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/contrib/nm-compat.c | 2 +- src/contrib/nm-vpn-editor-plugin-call.h | 64 +- src/contrib/nm-vpn-plugin-utils.c | 20 +- src/contrib/nm-vpn-plugin-utils.h | 14 +- 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 +- src/libnm-base/nm-ethtool-base.c | 2 +- src/libnm-base/nm-priv-helper-utils.h | 6 +- src/libnm-client-aux-extern/nm-libnm-aux.c | 20 +- src/libnm-client-aux-extern/nm-libnm-aux.h | 14 +- .../tests/test-libnm-client-aux.c | 8 +- src/libnm-client-impl/libnm.ver | 5 + src/libnm-client-impl/nm-access-point.c | 26 +- src/libnm-client-impl/nm-active-connection.c | 14 +- src/libnm-client-impl/nm-checkpoint.c | 4 +- src/libnm-client-impl/nm-client.c | 854 +- src/libnm-client-impl/nm-dbus-helpers.c | 10 +- src/libnm-client-impl/nm-device-6lowpan.c | 2 +- src/libnm-client-impl/nm-device-adsl.c | 2 +- src/libnm-client-impl/nm-device-bond.c | 2 +- src/libnm-client-impl/nm-device-bridge.c | 2 +- src/libnm-client-impl/nm-device-bt.c | 10 +- src/libnm-client-impl/nm-device-ethernet.c | 12 +- src/libnm-client-impl/nm-device-generic.c | 2 +- src/libnm-client-impl/nm-device-infiniband.c | 4 +- src/libnm-client-impl/nm-device-ip-tunnel.c | 10 +- src/libnm-client-impl/nm-device-macsec.c | 4 +- src/libnm-client-impl/nm-device-macvlan.c | 6 +- src/libnm-client-impl/nm-device-modem.c | 24 +- src/libnm-client-impl/nm-device-olpc-mesh.c | 2 +- src/libnm-client-impl/nm-device-ovs-bridge.c | 2 +- src/libnm-client-impl/nm-device-ovs-port.c | 2 +- src/libnm-client-impl/nm-device-team.c | 2 +- src/libnm-client-impl/nm-device-tun.c | 6 +- src/libnm-client-impl/nm-device-veth.c | 2 +- src/libnm-client-impl/nm-device-vlan.c | 8 +- src/libnm-client-impl/nm-device-vrf.c | 2 +- src/libnm-client-impl/nm-device-vxlan.c | 6 +- src/libnm-client-impl/nm-device-wifi-p2p.c | 18 +- src/libnm-client-impl/nm-device-wifi.c | 34 +- src/libnm-client-impl/nm-device.c | 164 +- src/libnm-client-impl/nm-dhcp-config.c | 12 +- src/libnm-client-impl/nm-dns-manager.c | 8 +- src/libnm-client-impl/nm-dns-manager.h | 2 +- src/libnm-client-impl/nm-ip-config.c | 52 +- src/libnm-client-impl/nm-libnm-utils.c | 22 +- src/libnm-client-impl/nm-libnm-utils.h | 142 +- src/libnm-client-impl/nm-object.c | 16 +- src/libnm-client-impl/nm-property-infos-dbus.xml | 180 +- .../nm-property-infos-ifcfg-rh.xml | 392 +- .../nm-property-infos-keyfile.xml | 181 +- src/libnm-client-impl/nm-property-infos-nmcli.xml | 438 +- src/libnm-client-impl/nm-remote-connection.c | 64 +- src/libnm-client-impl/nm-secret-agent-old.c | 238 +- src/libnm-client-impl/nm-settings-docs-gir.xml | 1 + src/libnm-client-impl/nm-vpn-connection.c | 6 +- src/libnm-client-impl/nm-vpn-plugin-old.c | 90 +- src/libnm-client-impl/nm-vpn-service-plugin.c | 112 +- src/libnm-client-impl/nm-wifi-p2p-peer.c | 20 +- src/libnm-client-impl/tests/test-libnm.c | 28 +- src/libnm-client-impl/tests/test-nm-client.c | 255 +- .../tests/test-remote-settings-client.c | 44 +- src/libnm-client-impl/tests/test-secret-agent.c | 128 +- src/libnm-client-public/nm-access-point.h | 4 +- src/libnm-client-public/nm-active-connection.h | 20 +- src/libnm-client-public/nm-client.h | 174 +- src/libnm-client-public/nm-device-wifi-p2p.h | 10 +- src/libnm-client-public/nm-device-wifi.h | 18 +- src/libnm-client-public/nm-device.h | 64 +- src/libnm-client-public/nm-ip-config.h | 6 +- src/libnm-client-public/nm-remote-connection.h | 56 +- src/libnm-client-public/nm-secret-agent-old.h | 64 +- src/libnm-client-public/nm-vpn-connection.h | 2 +- src/libnm-client-public/nm-vpn-plugin-old.h | 16 +- src/libnm-client-public/nm-vpn-service-plugin.h | 20 +- src/libnm-client-test/nm-test-libnm-utils.h | 32 +- src/libnm-client-test/nm-test-utils-impl.c | 104 +- src/libnm-core-aux-extern/nm-libnm-core-aux.c | 20 +- src/libnm-core-aux-intern/nm-auth-subject.c | 6 +- src/libnm-core-aux-intern/nm-libnm-core-utils.c | 12 +- src/libnm-core-aux-intern/nm-libnm-core-utils.h | 12 +- src/libnm-core-impl/nm-connection-private.h | 20 +- src/libnm-core-impl/nm-connection.c | 180 +- src/libnm-core-impl/nm-crypto-gnutls.c | 24 +- src/libnm-core-impl/nm-crypto-impl.h | 24 +- src/libnm-core-impl/nm-crypto-nss.c | 44 +- src/libnm-core-impl/nm-crypto.c | 128 +- src/libnm-core-impl/nm-crypto.h | 44 +- src/libnm-core-impl/nm-dbus-utils.c | 30 +- src/libnm-core-impl/nm-keyfile-utils.c | 60 +- src/libnm-core-impl/nm-keyfile.c | 614 +- src/libnm-core-impl/nm-meta-setting-base-impl.c | 4 +- src/libnm-core-impl/nm-property-compare.c | 6 +- src/libnm-core-impl/nm-setting-6lowpan.c | 6 +- src/libnm-core-impl/nm-setting-8021x.c | 190 +- src/libnm-core-impl/nm-setting-adsl.c | 14 +- src/libnm-core-impl/nm-setting-bluetooth.c | 6 +- src/libnm-core-impl/nm-setting-bond-port.c | 6 +- src/libnm-core-impl/nm-setting-bond.c | 26 +- src/libnm-core-impl/nm-setting-bridge-port.c | 6 +- src/libnm-core-impl/nm-setting-bridge.c | 124 +- src/libnm-core-impl/nm-setting-cdma.c | 12 +- src/libnm-core-impl/nm-setting-connection.c | 95 +- src/libnm-core-impl/nm-setting-dcb.c | 16 +- src/libnm-core-impl/nm-setting-ethtool.c | 14 +- src/libnm-core-impl/nm-setting-gsm.c | 342 +- src/libnm-core-impl/nm-setting-hostname.c | 4 +- src/libnm-core-impl/nm-setting-infiniband.c | 180 +- src/libnm-core-impl/nm-setting-ip-config.c | 816 +- src/libnm-core-impl/nm-setting-ip-tunnel.c | 271 +- src/libnm-core-impl/nm-setting-ip4-config.c | 160 +- src/libnm-core-impl/nm-setting-ip6-config.c | 222 +- src/libnm-core-impl/nm-setting-macsec.c | 262 +- src/libnm-core-impl/nm-setting-macvlan.c | 116 +- src/libnm-core-impl/nm-setting-match.c | 12 +- src/libnm-core-impl/nm-setting-olpc-mesh.c | 6 +- src/libnm-core-impl/nm-setting-ovs-bridge.c | 104 +- src/libnm-core-impl/nm-setting-ovs-dpdk.c | 106 +- src/libnm-core-impl/nm-setting-ovs-external-ids.c | 46 +- src/libnm-core-impl/nm-setting-ovs-interface.c | 84 +- src/libnm-core-impl/nm-setting-ovs-patch.c | 72 +- src/libnm-core-impl/nm-setting-ovs-port.c | 12 +- src/libnm-core-impl/nm-setting-ppp.c | 4 +- src/libnm-core-impl/nm-setting-pppoe.c | 10 +- src/libnm-core-impl/nm-setting-private.h | 164 +- src/libnm-core-impl/nm-setting-proxy.c | 8 +- src/libnm-core-impl/nm-setting-serial.c | 4 +- src/libnm-core-impl/nm-setting-sriov.c | 144 +- src/libnm-core-impl/nm-setting-tc-config.c | 76 +- src/libnm-core-impl/nm-setting-team-port.c | 22 +- src/libnm-core-impl/nm-setting-team.c | 54 +- src/libnm-core-impl/nm-setting-tun.c | 8 +- src/libnm-core-impl/nm-setting-user.c | 34 +- src/libnm-core-impl/nm-setting-veth.c | 72 +- src/libnm-core-impl/nm-setting-vlan.c | 78 +- src/libnm-core-impl/nm-setting-vpn.c | 160 +- src/libnm-core-impl/nm-setting-vrf.c | 4 +- src/libnm-core-impl/nm-setting-vxlan.c | 397 +- src/libnm-core-impl/nm-setting-wifi-p2p.c | 6 +- src/libnm-core-impl/nm-setting-wimax.c | 90 +- src/libnm-core-impl/nm-setting-wired.c | 214 +- src/libnm-core-impl/nm-setting-wireguard.c | 394 +- src/libnm-core-impl/nm-setting-wireless-security.c | 485 +- src/libnm-core-impl/nm-setting-wireless.c | 335 +- src/libnm-core-impl/nm-setting-wpan.c | 6 +- src/libnm-core-impl/nm-setting.c | 701 +- src/libnm-core-impl/nm-simple-connection.c | 4 +- src/libnm-core-impl/nm-team-utils.c | 144 +- src/libnm-core-impl/nm-team-utils.h | 32 +- src/libnm-core-impl/nm-utils-private.h | 23 +- src/libnm-core-impl/nm-utils.c | 554 +- src/libnm-core-impl/nm-vpn-editor-plugin.c | 38 +- src/libnm-core-impl/nm-vpn-plugin-info.c | 60 +- src/libnm-core-impl/tests/test-compare.c | 8 +- src/libnm-core-impl/tests/test-crypto.c | 28 +- src/libnm-core-impl/tests/test-general.c | 814 +- src/libnm-core-impl/tests/test-keyfile.c | 130 +- src/libnm-core-impl/tests/test-secrets.c | 108 +- src/libnm-core-impl/tests/test-setting.c | 488 +- src/libnm-core-impl/tests/test-settings-defaults.c | 4 +- src/libnm-core-intern/nm-core-internal.h | 193 +- src/libnm-core-intern/nm-keyfile-internal.h | 12 +- src/libnm-core-intern/nm-keyfile-utils.h | 36 +- src/libnm-core-intern/nm-meta-setting-base-impl.h | 16 +- src/libnm-core-public/nm-connection.h | 72 +- src/libnm-core-public/nm-dbus-interface.h | 4 + src/libnm-core-public/nm-dbus-types.xml | 5 + src/libnm-core-public/nm-keyfile.h | 38 +- src/libnm-core-public/nm-setting-8021x.h | 82 +- src/libnm-core-public/nm-setting-adsl.h | 10 +- src/libnm-core-public/nm-setting-bluetooth.h | 2 +- src/libnm-core-public/nm-setting-bond.h | 6 +- src/libnm-core-public/nm-setting-cdma.h | 8 +- src/libnm-core-public/nm-setting-connection.h | 24 +- src/libnm-core-public/nm-setting-dcb.h | 2 +- src/libnm-core-public/nm-setting-infiniband.h | 2 +- src/libnm-core-public/nm-setting-ip-config.h | 40 +- src/libnm-core-public/nm-setting-match.h | 8 +- src/libnm-core-public/nm-setting-olpc-mesh.h | 4 +- src/libnm-core-public/nm-setting-ovs-dpdk.h | 3 + .../nm-setting-ovs-external-ids.h | 6 +- src/libnm-core-public/nm-setting-pppoe.h | 8 +- src/libnm-core-public/nm-setting-serial.h | 2 +- src/libnm-core-public/nm-setting-tc-config.h | 2 +- src/libnm-core-public/nm-setting-team.h | 16 +- src/libnm-core-public/nm-setting-vlan.h | 14 +- src/libnm-core-public/nm-setting-vpn.h | 2 +- src/libnm-core-public/nm-setting-wired.h | 14 +- src/libnm-core-public/nm-setting-wireguard.h | 14 +- .../nm-setting-wireless-security.h | 16 +- src/libnm-core-public/nm-setting-wireless.h | 6 +- src/libnm-core-public/nm-setting.h | 28 +- src/libnm-core-public/nm-utils.h | 44 +- src/libnm-core-public/nm-version-macros.h | 7 +- src/libnm-core-public/nm-version-macros.h.in | 3 +- src/libnm-core-public/nm-version.h | 14 + src/libnm-core-public/nm-vpn-editor-plugin.h | 30 +- src/libnm-core-public/nm-vpn-plugin-info.h | 2 +- src/libnm-glib-aux/nm-c-list.h | 2 +- src/libnm-glib-aux/nm-dbus-aux.c | 120 +- src/libnm-glib-aux/nm-dbus-aux.h | 92 +- src/libnm-glib-aux/nm-dedup-multi.c | 112 +- src/libnm-glib-aux/nm-dedup-multi.h | 78 +- src/libnm-glib-aux/nm-enum-utils.c | 18 +- src/libnm-glib-aux/nm-enum-utils.h | 10 +- src/libnm-glib-aux/nm-errno.c | 2 +- src/libnm-glib-aux/nm-glib.h | 12 +- src/libnm-glib-aux/nm-hash-utils.c | 42 +- src/libnm-glib-aux/nm-hash-utils.h | 14 +- src/libnm-glib-aux/nm-io-utils.c | 50 +- src/libnm-glib-aux/nm-io-utils.h | 26 +- src/libnm-glib-aux/nm-json-aux.c | 6 +- src/libnm-glib-aux/nm-json-aux.h | 2 +- src/libnm-glib-aux/nm-keyfile-aux.c | 32 +- src/libnm-glib-aux/nm-keyfile-aux.h | 10 +- src/libnm-glib-aux/nm-logging-base.c | 4 +- src/libnm-glib-aux/nm-macros-internal.h | 45 +- src/libnm-glib-aux/nm-random-utils.c | 6 +- src/libnm-glib-aux/nm-ref-string.c | 42 + src/libnm-glib-aux/nm-ref-string.h | 65 +- src/libnm-glib-aux/nm-secret-utils.h | 20 +- src/libnm-glib-aux/nm-shared-utils.c | 344 +- src/libnm-glib-aux/nm-shared-utils.h | 219 +- src/libnm-glib-aux/nm-str-buf.h | 2 +- src/libnm-glib-aux/nm-test-utils.h | 266 +- src/libnm-glib-aux/nm-uuid.c | 24 +- src/libnm-glib-aux/nm-uuid.h | 10 +- src/libnm-glib-aux/nm-value-type.h | 6 +- src/libnm-glib-aux/tests/test-json-aux.c | 2 +- src/libnm-glib-aux/tests/test-shared-general.c | 48 +- src/libnm-log-core/nm-logging.c | 28 +- src/libnm-platform/meson.build | 2 +- src/libnm-platform/nm-linux-platform.c | 895 +- src/libnm-platform/nm-netlink.c | 93 +- src/libnm-platform/nm-netlink.h | 44 +- src/libnm-platform/nm-platform-private.h | 2 +- src/libnm-platform/nm-platform-utils.c | 64 +- src/libnm-platform/nm-platform-utils.h | 8 +- src/libnm-platform/nm-platform.c | 523 +- src/libnm-platform/nm-platform.h | 344 +- src/libnm-platform/nmp-netns.c | 24 +- src/libnm-platform/nmp-object.c | 183 +- src/libnm-platform/nmp-object.h | 93 +- src/libnm-platform/nmp-route-manager.c | 839 ++ src/libnm-platform/nmp-route-manager.h | 79 + src/libnm-platform/nmp-rules-manager.c | 809 -- src/libnm-platform/nmp-rules-manager.h | 53 - src/libnm-platform/wifi/nm-wifi-utils-nl80211.c | 86 +- src/libnm-platform/wifi/nm-wifi-utils-private.h | 4 +- src/libnm-platform/wifi/nm-wifi-utils-wext.c | 14 +- src/libnm-platform/wifi/nm-wifi-utils.c | 4 +- src/libnm-platform/wifi/nm-wifi-utils.h | 4 +- src/libnm-platform/wpan/nm-wpan-utils.c | 22 +- src/libnm-std-aux/c-list-util.h | 2 +- src/libnm-systemd-core/meson.build | 2 - src/libnm-systemd-core/nm-sd-utils-dhcp.h | 2 +- src/libnm-systemd-core/nm-sd.h | 2 - .../src/libsystemd-network/arp-util.c | 34 +- .../src/libsystemd-network/arp-util.h | 4 +- .../src/libsystemd-network/dhcp-identifier.c | 6 +- .../src/libsystemd-network/dhcp-internal.h | 4 +- .../src/libsystemd-network/dhcp-lease-internal.h | 6 + .../src/libsystemd-network/dhcp-network.c | 66 +- .../src/libsystemd-network/dhcp-packet.c | 33 +- .../src/libsystemd-network/dhcp6-internal.h | 8 + .../src/libsystemd-network/dhcp6-lease-internal.h | 16 +- .../src/libsystemd-network/dhcp6-network.c | 4 + .../src/libsystemd-network/dhcp6-option.c | 189 +- .../src/libsystemd-network/dhcp6-protocol.h | 120 +- .../src/libsystemd-network/lldp-neighbor.c | 50 +- .../src/libsystemd-network/lldp-network.c | 21 +- .../src/libsystemd-network/network-common.h | 4 +- .../src/libsystemd-network/sd-dhcp-client.c | 61 +- .../src/libsystemd-network/sd-dhcp-lease.c | 96 +- .../src/libsystemd-network/sd-dhcp6-client.c | 316 +- .../src/libsystemd-network/sd-dhcp6-lease.c | 103 +- .../src/libsystemd-network/sd-ipv4acd.c | 616 -- .../src/libsystemd-network/sd-ipv4ll.c | 382 - .../src/libsystemd-network/sd-lldp-rx.c | 29 +- .../src/libsystemd/sd-event/event-source.h | 6 + .../src/libsystemd/sd-event/event-util.c | 24 + .../src/libsystemd/sd-event/event-util.h | 26 +- .../src/libsystemd/sd-event/sd-event.c | 204 +- .../src/libsystemd/sd-id128/id128-util.c | 2 +- .../src/libsystemd/sd-id128/sd-id128.c | 43 +- .../src/systemd/sd-dhcp-client.h | 117 +- src/libnm-systemd-core/src/systemd/sd-dhcp-lease.h | 7 + .../src/systemd/sd-dhcp6-client.h | 169 +- .../src/systemd/sd-dhcp6-lease.h | 4 + src/libnm-systemd-core/src/systemd/sd-event.h | 2 + src/libnm-systemd-core/src/systemd/sd-ipv4acd.h | 63 - src/libnm-systemd-core/src/systemd/sd-ipv4ll.h | 65 - src/libnm-systemd-core/src/systemd/sd-ndisc.h | 3 - .../sd-adapt-shared/filesystems.h | 3 + src/libnm-systemd-shared/sd-adapt-shared/hmac.h | 3 + .../sd-adapt-shared/missing_magic.h | 2 + .../sd-adapt-shared/netif-util.h | 3 + src/libnm-systemd-shared/src/basic/alloc-util.h | 51 +- src/libnm-systemd-shared/src/basic/cgroup-util.h | 28 + src/libnm-systemd-shared/src/basic/env-util.c | 22 +- src/libnm-systemd-shared/src/basic/errno-util.h | 38 +- src/libnm-systemd-shared/src/basic/escape.c | 6 +- src/libnm-systemd-shared/src/basic/escape.h | 2 +- .../src/basic/ether-addr-util.c | 216 +- .../src/basic/ether-addr-util.h | 56 +- src/libnm-systemd-shared/src/basic/fd-util.c | 261 +- src/libnm-systemd-shared/src/basic/fd-util.h | 15 +- src/libnm-systemd-shared/src/basic/fileio.c | 24 +- src/libnm-systemd-shared/src/basic/fileio.h | 5 +- src/libnm-systemd-shared/src/basic/format-util.h | 8 +- src/libnm-systemd-shared/src/basic/fs-util.c | 188 +- src/libnm-systemd-shared/src/basic/fs-util.h | 6 +- src/libnm-systemd-shared/src/basic/hostname-util.c | 3 +- src/libnm-systemd-shared/src/basic/hostname-util.h | 7 +- src/libnm-systemd-shared/src/basic/in-addr-util.c | 125 +- src/libnm-systemd-shared/src/basic/in-addr-util.h | 12 + src/libnm-systemd-shared/src/basic/inotify-util.c | 18 +- src/libnm-systemd-shared/src/basic/list.h | 11 +- src/libnm-systemd-shared/src/basic/log.h | 9 +- src/libnm-systemd-shared/src/basic/macro.h | 27 +- .../src/basic/missing_syscall.h | 66 +- src/libnm-systemd-shared/src/basic/parse-util.c | 6 +- src/libnm-systemd-shared/src/basic/path-util.c | 38 +- src/libnm-systemd-shared/src/basic/process-util.c | 156 +- src/libnm-systemd-shared/src/basic/process-util.h | 47 +- src/libnm-systemd-shared/src/basic/random-util.c | 18 +- src/libnm-systemd-shared/src/basic/signal-util.c | 20 +- src/libnm-systemd-shared/src/basic/socket-util.c | 60 +- src/libnm-systemd-shared/src/basic/socket-util.h | 5 + src/libnm-systemd-shared/src/basic/sort-util.h | 22 +- src/libnm-systemd-shared/src/basic/sparse-endian.h | 12 +- src/libnm-systemd-shared/src/basic/stat-util.c | 51 +- src/libnm-systemd-shared/src/basic/string-util.h | 4 + src/libnm-systemd-shared/src/basic/strv.c | 88 +- src/libnm-systemd-shared/src/basic/strv.h | 52 +- src/libnm-systemd-shared/src/basic/strxcpyx.c | 67 +- src/libnm-systemd-shared/src/basic/strxcpyx.h | 33 +- src/libnm-systemd-shared/src/basic/time-util.c | 12 +- src/libnm-systemd-shared/src/basic/tmpfile-util.c | 25 +- src/libnm-systemd-shared/src/basic/umask-util.h | 3 + src/libnm-systemd-shared/src/basic/utf8.c | 39 +- src/libnm-systemd-shared/src/basic/utf8.h | 2 + src/libnm-systemd-shared/src/basic/util.c | 66 - src/libnm-systemd-shared/src/basic/util.h | 46 +- .../src/fundamental/macro-fundamental.h | 72 +- .../src/fundamental/string-util-fundamental.c | 8 +- .../src/fundamental/string-util-fundamental.h | 4 +- src/libnm-systemd-shared/src/fundamental/type.h | 22 - .../src/fundamental/types-fundamental.h | 39 + src/libnm-systemd-shared/src/shared/dns-domain.c | 4 +- src/libnm-systemd-shared/src/shared/dns-domain.h | 4 + src/libnm-udev-aux/nm-udev-utils.c | 24 +- src/libnm-udev-aux/nm-udev-utils.h | 4 +- src/libnmc-base/nm-client-utils.c | 38 +- src/libnmc-base/nm-client-utils.h | 12 +- src/libnmc-base/nm-polkit-listener.c | 104 +- src/libnmc-base/nm-secret-agent-simple.c | 206 +- src/libnmc-base/nm-secret-agent-simple.h | 12 +- src/libnmc-base/nm-vpn-helpers.c | 94 +- src/libnmc-base/nm-vpn-helpers.h | 10 +- src/libnmc-base/qrcodegen.c | 2 +- src/libnmc-base/qrcodegen.h | 2 +- src/libnmc-setting/nm-meta-setting-access.c | 74 +- src/libnmc-setting/nm-meta-setting-access.h | 40 +- src/libnmc-setting/nm-meta-setting-base-impl.c | 4 +- src/libnmc-setting/nm-meta-setting-base-impl.h | 16 +- src/libnmc-setting/nm-meta-setting-desc.c | 598 +- src/libnmc-setting/nm-meta-setting-desc.h | 94 +- src/libnmc-setting/settings-docs-input.xml | 274 +- src/libnmc-setting/settings-docs.h | 3 + src/libnmc-setting/settings-docs.h.in | 3 + src/libnmc-setting/tests/test-libnmc-setting.c | 98 +- src/libnmt-newt/nmt-newt-button-box.c | 16 +- src/libnmt-newt/nmt-newt-button.c | 6 +- src/libnmt-newt/nmt-newt-checkbox.c | 10 +- src/libnmt-newt/nmt-newt-component.c | 8 +- src/libnmt-newt/nmt-newt-container.c | 8 +- src/libnmt-newt/nmt-newt-entry-numeric.c | 10 +- src/libnmt-newt/nmt-newt-entry.c | 16 +- src/libnmt-newt/nmt-newt-entry.h | 2 +- src/libnmt-newt/nmt-newt-form.c | 18 +- src/libnmt-newt/nmt-newt-grid.c | 32 +- src/libnmt-newt/nmt-newt-hacks.c | 10 +- src/libnmt-newt/nmt-newt-label.c | 6 +- src/libnmt-newt/nmt-newt-listbox.c | 12 +- src/libnmt-newt/nmt-newt-popup.c | 18 +- src/libnmt-newt/nmt-newt-section.c | 20 +- src/libnmt-newt/nmt-newt-stack.c | 8 +- src/libnmt-newt/nmt-newt-textbox.c | 14 +- src/libnmt-newt/nmt-newt-toggle-button.c | 12 +- src/libnmt-newt/nmt-newt-utils.c | 24 +- src/nm-cloud-setup/main.c | 122 +- src/nm-cloud-setup/nm-cloud-setup-utils.c | 54 +- src/nm-cloud-setup/nm-cloud-setup-utils.h | 28 +- src/nm-cloud-setup/nm-http-client.c | 104 +- src/nm-cloud-setup/nm-http-client.h | 30 +- src/nm-cloud-setup/nmcs-provider-aliyun.c | 48 +- src/nm-cloud-setup/nmcs-provider-azure.c | 78 +- src/nm-cloud-setup/nmcs-provider-ec2.c | 42 +- src/nm-cloud-setup/nmcs-provider-gcp.c | 64 +- src/nm-cloud-setup/nmcs-provider.c | 20 +- src/nm-cloud-setup/nmcs-provider.h | 16 +- .../tests/test-cloud-setup-general.c | 8 +- src/nm-dispatcher/nm-dispatcher-utils.c | 68 +- src/nm-dispatcher/nm-dispatcher-utils.h | 30 +- src/nm-dispatcher/nm-dispatcher.c | 82 +- src/nm-dispatcher/tests/test-dispatcher-envp.c | 146 +- src/nm-initrd-generator/nm-initrd-generator.c | 55 +- src/nm-initrd-generator/nm-initrd-generator.h | 7 +- src/nm-initrd-generator/nmi-cmdline-reader.c | 265 +- src/nm-initrd-generator/nmi-dt-reader.c | 46 +- src/nm-initrd-generator/nmi-ibft-reader.c | 52 +- .../tests/test-cmdline-reader.c | 471 +- src/nm-initrd-generator/tests/test-dt-reader.c | 20 +- src/nm-initrd-generator/tests/test-ibft-reader.c | 62 +- src/nm-online/nm-online.c | 8 +- src/nm-priv-helper/meson.build | 2 +- src/nm-priv-helper/nm-priv-helper.c | 42 +- src/nm-priv-helper/nm-priv-helper.conf | 8 +- .../org.freedesktop.nm-priv-helper.service.in | 5 - .../org.freedesktop.nm_priv_helper.service.in | 5 + src/nmcli/agent.c | 23 +- src/nmcli/common.c | 152 +- src/nmcli/common.h | 32 +- src/nmcli/connections.c | 1133 +-- src/nmcli/connections.h | 8 +- src/nmcli/devices.c | 524 +- src/nmcli/general.c | 93 +- src/nmcli/generate-docs-nm-settings-nmcli.c | 10 +- src/nmcli/generate-docs-nm-settings-nmcli.xml | 2 + src/nmcli/generate-docs-nm-settings-nmcli.xml.in | 2 + src/nmcli/nmcli.c | 26 +- src/nmcli/nmcli.h | 14 +- src/nmcli/polkit-agent.c | 2 +- src/nmcli/settings.c | 78 +- src/nmcli/settings.h | 18 +- src/nmcli/utils.c | 174 +- src/nmcli/utils.h | 54 +- src/nmtui/nm-editor-bindings.c | 200 +- src/nmtui/nm-editor-bindings.h | 68 +- src/nmtui/nm-editor-utils.c | 44 +- src/nmtui/nm-editor-utils.h | 2 +- src/nmtui/nmt-address-list.c | 20 +- src/nmtui/nmt-connect-connection-list.c | 86 +- src/nmtui/nmt-connect-connection-list.h | 18 +- src/nmtui/nmt-device-entry.c | 48 +- src/nmtui/nmt-device-entry.h | 4 +- src/nmtui/nmt-edit-connection-list.c | 42 +- src/nmtui/nmt-edit-connection-list.h | 2 +- src/nmtui/nmt-editor-grid.c | 50 +- src/nmtui/nmt-editor-grid.h | 6 +- src/nmtui/nmt-editor-page-device.c | 8 +- src/nmtui/nmt-editor-page.c | 2 +- src/nmtui/nmt-editor-section.c | 8 +- src/nmtui/nmt-editor-section.h | 2 +- src/nmtui/nmt-editor.c | 44 +- src/nmtui/nmt-ip-entry.c | 2 +- src/nmtui/nmt-mac-entry.c | 2 +- src/nmtui/nmt-mtu-entry.c | 8 +- src/nmtui/nmt-page-bond-port.c | 10 +- src/nmtui/nmt-page-bond.c | 58 +- src/nmtui/nmt-page-bridge-port.c | 10 +- src/nmtui/nmt-page-bridge.c | 14 +- src/nmtui/nmt-page-dsl.c | 16 +- src/nmtui/nmt-page-ethernet.c | 12 +- src/nmtui/nmt-page-infiniband.c | 12 +- src/nmtui/nmt-page-ip-tunnel.c | 18 +- src/nmtui/nmt-page-ip4.c | 18 +- src/nmtui/nmt-page-ip6.c | 18 +- src/nmtui/nmt-page-ppp.c | 32 +- src/nmtui/nmt-page-team-port.c | 18 +- src/nmtui/nmt-page-team.c | 26 +- src/nmtui/nmt-page-vlan.c | 12 +- src/nmtui/nmt-page-wifi.c | 44 +- src/nmtui/nmt-page-wireguard.c | 12 +- src/nmtui/nmt-password-dialog.c | 18 +- src/nmtui/nmt-password-dialog.h | 4 +- src/nmtui/nmt-password-fields.c | 12 +- src/nmtui/nmt-route-editor.c | 12 +- src/nmtui/nmt-route-entry.c | 10 +- src/nmtui/nmt-route-table.c | 32 +- src/nmtui/nmt-slave-list.c | 12 +- src/nmtui/nmt-slave-list.h | 2 +- src/nmtui/nmt-utils.c | 2 +- src/nmtui/nmt-widget-list.c | 8 +- src/nmtui/nmt-widget-list.h | 2 +- src/nmtui/nmt-wireguard-peer-editor.c | 22 +- src/nmtui/nmt-wireguard-peer-list.c | 34 +- src/nmtui/nmtui-connect.c | 64 +- src/nmtui/nmtui-edit.c | 48 +- src/nmtui/nmtui-edit.h | 6 +- src/nmtui/nmtui-hostname.c | 14 +- src/nmtui/nmtui.c | 26 +- .../test-client.check-on-disk/test_003.expected | 152 +- .../test-client.check-on-disk/test_004.expected | 132 +- 774 files changed, 43321 insertions(+), 50576 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 create mode 100644 src/libnm-platform/nmp-route-manager.c create mode 100644 src/libnm-platform/nmp-route-manager.h delete mode 100644 src/libnm-platform/nmp-rules-manager.c delete mode 100644 src/libnm-platform/nmp-rules-manager.h delete mode 100644 src/libnm-systemd-core/src/libsystemd-network/sd-ipv4acd.c delete mode 100644 src/libnm-systemd-core/src/libsystemd-network/sd-ipv4ll.c delete mode 100644 src/libnm-systemd-core/src/systemd/sd-ipv4acd.h delete mode 100644 src/libnm-systemd-core/src/systemd/sd-ipv4ll.h create mode 100644 src/libnm-systemd-shared/sd-adapt-shared/filesystems.h create mode 100644 src/libnm-systemd-shared/sd-adapt-shared/hmac.h create mode 100644 src/libnm-systemd-shared/sd-adapt-shared/netif-util.h delete mode 100644 src/libnm-systemd-shared/src/fundamental/type.h create mode 100644 src/libnm-systemd-shared/src/fundamental/types-fundamental.h delete mode 100644 src/nm-priv-helper/org.freedesktop.nm-priv-helper.service.in create mode 100644 src/nm-priv-helper/org.freedesktop.nm_priv_helper.service.in (limited to 'src') diff --git a/src/contrib/nm-compat.c b/src/contrib/nm-compat.c index f15c29c9..d322cb1f 100644 --- a/src/contrib/nm-compat.c +++ b/src/contrib/nm-compat.c @@ -22,7 +22,7 @@ _get_keys(NMSettingVpn *setting, gboolean is_secrets, guint *out_length) { guint len; const char **keys = NULL; - GPtrArray * a; + GPtrArray *a; nm_assert(NM_IS_SETTING_VPN(setting)); diff --git a/src/contrib/nm-vpn-editor-plugin-call.h b/src/contrib/nm-vpn-editor-plugin-call.h index be0a6772..713ddf08 100644 --- a/src/contrib/nm-vpn-editor-plugin-call.h +++ b/src/contrib/nm-vpn-editor-plugin-call.h @@ -33,21 +33,21 @@ typedef enum { /*< skip >*/ } NMVpnEditorPluginServiceFlags; struct _NMVpnEditorPluginVT { - gboolean (*fcn_get_service_info)(NMVpnEditorPlugin * plugin, - const char * service_type, - char ** out_short_name, - char ** out_pretty_name, - char ** out_description, + gboolean (*fcn_get_service_info)(NMVpnEditorPlugin *plugin, + const char *service_type, + char **out_short_name, + char **out_pretty_name, + char **out_description, NMVpnEditorPluginServiceFlags *out_flags); char **(*fcn_get_service_add_details)(NMVpnEditorPlugin *plugin, const char *service_name); gboolean (*fcn_get_service_add_detail)(NMVpnEditorPlugin *plugin, - const char * service_type, - const char * add_detail, - char ** out_pretty_name, - char ** out_description, - char ** out_add_detail_key, - char ** out_add_detail_val, - guint * out_flags); + const char *service_type, + const char *add_detail, + char **out_pretty_name, + char **out_description, + char **out_add_detail_key, + char **out_add_detail_val, + guint *out_flags); }; /***************************************************************************** @@ -58,17 +58,17 @@ struct _NMVpnEditorPluginVT { *****************************************************************************/ static inline gboolean -nm_vpn_editor_plugin_get_service_info(NMVpnEditorPlugin * plugin, - const char * service_type, - char ** out_short_name, - char ** out_pretty_name, - char ** out_description, +nm_vpn_editor_plugin_get_service_info(NMVpnEditorPlugin *plugin, + const char *service_type, + char **out_short_name, + char **out_pretty_name, + char **out_description, NMVpnEditorPluginServiceFlags *out_flags) { NMVpnEditorPluginVT vt; - gs_free char * short_name_local = NULL; - gs_free char * pretty_name_local = NULL; - gs_free char * description_local = NULL; + gs_free char *short_name_local = NULL; + gs_free char *pretty_name_local = NULL; + gs_free char *description_local = NULL; guint flags_local = 0; g_return_val_if_fail(NM_IS_VPN_EDITOR_PLUGIN(plugin), FALSE); @@ -94,7 +94,7 @@ static inline char ** nm_vpn_editor_plugin_get_service_add_details(NMVpnEditorPlugin *plugin, const char *service_name) { NMVpnEditorPluginVT vt; - char ** details = NULL; + char **details = NULL; g_return_val_if_fail(NM_IS_VPN_EDITOR_PLUGIN(plugin), NULL); g_return_val_if_fail(service_name, NULL); @@ -109,19 +109,19 @@ nm_vpn_editor_plugin_get_service_add_details(NMVpnEditorPlugin *plugin, const ch static inline gboolean nm_vpn_editor_plugin_get_service_add_detail(NMVpnEditorPlugin *plugin, - const char * service_type, - const char * add_detail, - char ** out_pretty_name, - char ** out_description, - char ** out_add_detail_key, - char ** out_add_detail_val, - guint * out_flags) + const char *service_type, + const char *add_detail, + char **out_pretty_name, + char **out_description, + char **out_add_detail_key, + char **out_add_detail_val, + guint *out_flags) { NMVpnEditorPluginVT vt; - gs_free char * pretty_name_local = NULL; - gs_free char * description_local = NULL; - gs_free char * add_detail_key_local = NULL; - gs_free char * add_detail_val_local = NULL; + gs_free char *pretty_name_local = NULL; + gs_free char *description_local = NULL; + gs_free char *add_detail_key_local = NULL; + gs_free char *add_detail_val_local = NULL; guint flags_local = 0; g_return_val_if_fail(NM_IS_VPN_EDITOR_PLUGIN(plugin), FALSE); diff --git a/src/contrib/nm-vpn-plugin-utils.c b/src/contrib/nm-vpn-plugin-utils.c index b10695b7..32af40cf 100644 --- a/src/contrib/nm-vpn-plugin-utils.c +++ b/src/contrib/nm-vpn-plugin-utils.c @@ -12,22 +12,22 @@ /*****************************************************************************/ NMVpnEditor * -nm_vpn_plugin_utils_load_editor(const char * module_name, - const char * factory_name, +nm_vpn_plugin_utils_load_editor(const char *module_name, + const char *factory_name, NMVpnPluginUtilsEditorFactory editor_factory, - NMVpnEditorPlugin * editor_plugin, - NMConnection * connection, + NMVpnEditorPlugin *editor_plugin, + NMConnection *connection, gpointer user_data, - GError ** error) + GError **error) { static struct { gpointer factory; - void * dl_module; - char * module_name; - char * factory_name; + void *dl_module; + char *module_name; + char *factory_name; } cached = {0}; - NMVpnEditor * editor; + NMVpnEditor *editor; gs_free char *module_path = NULL; gs_free char *dirname = NULL; Dl_info plugin_info; @@ -79,7 +79,7 @@ nm_vpn_plugin_utils_load_editor(const char * module_name, NULL); } else { gpointer factory; - void * dl_module; + void *dl_module; dl_module = dlopen(module_path, RTLD_LAZY | RTLD_LOCAL); if (!dl_module) { diff --git a/src/contrib/nm-vpn-plugin-utils.h b/src/contrib/nm-vpn-plugin-utils.h index 288143ef..b27b7513 100644 --- a/src/contrib/nm-vpn-plugin-utils.h +++ b/src/contrib/nm-vpn-plugin-utils.h @@ -10,16 +10,16 @@ typedef NMVpnEditor *(NMVpnPluginUtilsEditorFactory) (gpointer factory, NMVpnEditorPlugin *editor_plugin, - NMConnection * connection, + NMConnection *connection, gpointer user_data, - GError ** error); + GError **error); -NMVpnEditor *nm_vpn_plugin_utils_load_editor(const char * module_name, - const char * factory_name, +NMVpnEditor *nm_vpn_plugin_utils_load_editor(const char *module_name, + const char *factory_name, NMVpnPluginUtilsEditorFactory editor_factory, - NMVpnEditorPlugin * editor_plugin, - NMConnection * connection, + NMVpnEditorPlugin *editor_plugin, + NMConnection *connection, gpointer user_data, - GError ** error); + GError **error); #endif /* __NM_VPN_PLUGIN_UTILS_H__ */ 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); diff --git a/src/libnm-base/nm-ethtool-base.c b/src/libnm-base/nm-ethtool-base.c index c253ab94..99bbe68e 100644 --- a/src/libnm-base/nm-ethtool-base.c +++ b/src/libnm-base/nm-ethtool-base.c @@ -253,7 +253,7 @@ static int _by_name_cmp(gconstpointer a, gconstpointer b, gpointer user_data) { const guint8 *p_id = a; - const char * optname = b; + const char *optname = b; nm_assert(p_id && p_id >= _by_name && p_id <= &_by_name[_NM_ETHTOOL_ID_NUM]); nm_assert(*p_id < _NM_ETHTOOL_ID_NUM); diff --git a/src/libnm-base/nm-priv-helper-utils.h b/src/libnm-base/nm-priv-helper-utils.h index 22387cff..f866dd70 100644 --- a/src/libnm-base/nm-priv-helper-utils.h +++ b/src/libnm-base/nm-priv-helper-utils.h @@ -5,9 +5,9 @@ /*****************************************************************************/ -#define NM_PRIV_HELPER_DBUS_BUS_NAME "org.freedesktop.nm-priv-helper" -#define NM_PRIV_HELPER_DBUS_OBJECT_PATH "/org/freedesktop/nm-priv-helper" -#define NM_PRIV_HELPER_DBUS_IFACE_NAME "org.freedesktop.nm-priv-helper" +#define NM_PRIV_HELPER_DBUS_BUS_NAME "org.freedesktop.nm_priv_helper" +#define NM_PRIV_HELPER_DBUS_OBJECT_PATH "/org/freedesktop/nm_priv_helper" +#define NM_PRIV_HELPER_DBUS_IFACE_NAME "org.freedesktop.nm_priv_helper" /*****************************************************************************/ diff --git a/src/libnm-client-aux-extern/nm-libnm-aux.c b/src/libnm-client-aux-extern/nm-libnm-aux.c index 2d17241d..573eed1d 100644 --- a/src/libnm-client-aux-extern/nm-libnm-aux.c +++ b/src/libnm-client-aux-extern/nm-libnm-aux.c @@ -7,10 +7,10 @@ /*****************************************************************************/ NMClient * -nmc_client_new_async_valist(GCancellable * cancellable, +nmc_client_new_async_valist(GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data, - const char * first_property_name, + const char *first_property_name, va_list ap) { NMClient *nmc; @@ -25,10 +25,10 @@ nmc_client_new_async_valist(GCancellable * cancellable, } NMClient * -nmc_client_new_async(GCancellable * cancellable, +nmc_client_new_async(GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data, - const char * first_property_name, + const char *first_property_name, ...) { NMClient *nmc; @@ -44,8 +44,8 @@ nmc_client_new_async(GCancellable * cancellable, typedef struct { GMainLoop *main_loop; - NMClient * nmc; - GError * error; + NMClient *nmc; + GError *error; } ClientCreateData; static void @@ -82,12 +82,12 @@ _nmc_client_new_waitsync_cb(GObject *source_object, GAsyncResult *result, gpoint */ gboolean nmc_client_new_waitsync(GCancellable *cancellable, - NMClient ** out_nmc, - GError ** error, - const char * first_property_name, + NMClient **out_nmc, + GError **error, + const char *first_property_name, ...) { - gs_unref_object NMClient *nmc = NULL; + gs_unref_object NMClient *nmc = NULL; nm_auto_unref_gmainloop GMainLoop *main_loop = g_main_loop_new(g_main_context_get_thread_default(), FALSE); ClientCreateData data = { diff --git a/src/libnm-client-aux-extern/nm-libnm-aux.h b/src/libnm-client-aux-extern/nm-libnm-aux.h index c982eab7..44344fd0 100644 --- a/src/libnm-client-aux-extern/nm-libnm-aux.h +++ b/src/libnm-client-aux-extern/nm-libnm-aux.h @@ -3,22 +3,22 @@ #ifndef __NM_LIBNM_AUX_H__ #define __NM_LIBNM_AUX_H__ -NMClient *nmc_client_new_async_valist(GCancellable * cancellable, +NMClient *nmc_client_new_async_valist(GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data, - const char * first_property_name, + const char *first_property_name, va_list ap); -NMClient *nmc_client_new_async(GCancellable * cancellable, +NMClient *nmc_client_new_async(GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data, - const char * first_property_name, + const char *first_property_name, ...); gboolean nmc_client_new_waitsync(GCancellable *cancellable, - NMClient ** out_nmc, - GError ** error, - const char * first_property_name, + NMClient **out_nmc, + GError **error, + const char *first_property_name, ...); #endif /* __NM_LIBNM_AUX_H__ */ diff --git a/src/libnm-client-aux-extern/tests/test-libnm-client-aux.c b/src/libnm-client-aux-extern/tests/test-libnm-client-aux.c index c4db4d6a..f727b3d9 100644 --- a/src/libnm-client-aux-extern/tests/test-libnm-client-aux.c +++ b/src/libnm-client-aux-extern/tests/test-libnm-client-aux.c @@ -15,9 +15,9 @@ static NMTeamLinkWatcher * _team_link_watcher_from_string_impl(const char *str, gsize nextra, const char *const *vextra) { - NMTeamLinkWatcher *watcher; - gs_free char * str1_free = NULL; - gs_free_error GError *error = NULL; + NMTeamLinkWatcher *watcher; + gs_free char *str1_free = NULL; + gs_free_error GError *error = NULL; gsize i; g_assert(str); @@ -27,7 +27,7 @@ _team_link_watcher_from_string_impl(const char *str, gsize nextra, const char *c for (i = 0; i < 1 + nextra; i++) { nm_auto_unref_team_link_watcher NMTeamLinkWatcher *watcher1 = NULL; - const char * str1; + const char *str1; if (i == 0) { str1_free = nm_utils_team_link_watcher_to_string(watcher); diff --git a/src/libnm-client-impl/libnm.ver b/src/libnm-client-impl/libnm.ver index ce07a876..bb691ac2 100644 --- a/src/libnm-client-impl/libnm.ver +++ b/src/libnm-client-impl/libnm.ver @@ -1816,3 +1816,8 @@ global: nm_setting_connection_get_dns_over_tls; nm_setting_connection_dns_over_tls_get_type; } libnm_1_32_4; + +libnm_1_36_0 { +global: + nm_setting_ovs_dpdk_get_n_rxq; +} libnm_1_34_0; \ No newline at end of file diff --git a/src/libnm-client-impl/nm-access-point.c b/src/libnm-client-impl/nm-access-point.c index 3d12aa45..94b38f03 100644 --- a/src/libnm-client-impl/nm-access-point.c +++ b/src/libnm-client-impl/nm-access-point.c @@ -36,7 +36,7 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMAccessPoint, typedef struct { GBytes *ssid; - char * bssid; + char *bssid; guint32 flags; guint32 wpa_flags; guint32 rsn_flags; @@ -251,16 +251,16 @@ NM_BACKPORT_SYMBOL(libnm_1_0_6, int, nm_access_point_get_last_seen, (NMAccessPoi gboolean nm_access_point_connection_valid(NMAccessPoint *ap, NMConnection *connection) { - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; - const char * ctype, *ap_bssid; - GBytes * setting_ssid; - GBytes * ap_ssid; - const char * setting_bssid; - const char * setting_mode; + const char *ctype, *ap_bssid; + GBytes *setting_ssid; + GBytes *ap_ssid; + const char *setting_bssid; + const char *setting_mode; NM80211Mode ap_mode; - const char * setting_band; + const char *setting_band; guint32 ap_freq, setting_chan, ap_chan; g_return_val_if_fail(NM_IS_ACCESS_POINT(ap), FALSE); @@ -395,13 +395,13 @@ nm_access_point_filter_connections(NMAccessPoint *ap, const GPtrArray *connectio /*****************************************************************************/ static NMLDBusNotifyUpdatePropFlags -_notify_update_prop_hw_address(NMClient * client, - NMLDBusObject * dbobj, +_notify_update_prop_hw_address(NMClient *client, + NMLDBusObject *dbobj, const NMLDBusMetaIface *meta_iface, guint dbus_property_idx, - GVariant * value) + GVariant *value) { - NMAccessPoint * self = NM_ACCESS_POINT(dbobj->nmobj); + NMAccessPoint *self = NM_ACCESS_POINT(dbobj->nmobj); NMAccessPointPrivate *priv = NM_ACCESS_POINT_GET_PRIVATE(self); g_free(priv->bssid); diff --git a/src/libnm-client-impl/nm-active-connection.c b/src/libnm-client-impl/nm-active-connection.c index aa96219c..52e82b9f 100644 --- a/src/libnm-client-impl/nm-active-connection.c +++ b/src/libnm-client-impl/nm-active-connection.c @@ -62,10 +62,10 @@ enum { typedef struct _NMActiveConnectionPrivate { NMLDBusPropertyO property_o[_PROPERTY_O_IDX_NUM]; NMLDBusPropertyAO devices; - NMRefString * specific_object_path; - char * id; - char * uuid; - char * type; + NMRefString *specific_object_path; + char *id; + char *uuid; + char *type; guint32 state; guint32 state_flags; @@ -397,7 +397,7 @@ static void _notify_event_state_changed(NMClient *client, NMClientNotifyEventWithPtr *notify_event) { gs_unref_object NMActiveConnection *self = notify_event->user_data; - NMActiveConnectionPrivate * priv = NM_ACTIVE_CONNECTION_GET_PRIVATE(self); + NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE(self); /* we expose here the value cache in @priv. In practice, this is the same * value as we received from the signal. In the unexpected case where they @@ -408,7 +408,7 @@ _notify_event_state_changed(NMClient *client, NMClientNotifyEventWithPtr *notify void _nm_active_connection_state_changed_commit(NMActiveConnection *self, guint32 state, guint32 reason) { - NMClient * client; + NMClient *client; NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE(self); client = _nm_object_get_client(self); @@ -605,7 +605,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_connection_active = NML_DBUS_META static void nm_active_connection_class_init(NMActiveConnectionClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMObjectClass *nm_object_class = NM_OBJECT_CLASS(klass); g_type_class_add_private(klass, sizeof(NMActiveConnectionPrivate)); diff --git a/src/libnm-client-impl/nm-checkpoint.c b/src/libnm-client-impl/nm-checkpoint.c index c1f6b092..424d8e50 100644 --- a/src/libnm-client-impl/nm-checkpoint.c +++ b/src/libnm-client-impl/nm-checkpoint.c @@ -105,7 +105,7 @@ nm_checkpoint_init(NMCheckpoint *checkpoint) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMCheckpoint * checkpoint = NM_CHECKPOINT(object); + NMCheckpoint *checkpoint = NM_CHECKPOINT(object); NMCheckpointPrivate *priv = NM_CHECKPOINT_GET_PRIVATE(checkpoint); switch (prop_id) { @@ -145,7 +145,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_checkpoint = NML_DBUS_META_IFACE_ static void nm_checkpoint_class_init(NMCheckpointClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMObjectClass *nm_object_class = NM_OBJECT_CLASS(klass); object_class->get_property = get_property; diff --git a/src/libnm-client-impl/nm-client.c b/src/libnm-client-impl/nm-client.c index 0f9d8fe1..2cf12db5 100644 --- a/src/libnm-client-impl/nm-client.c +++ b/src/libnm-client-impl/nm-client.c @@ -71,7 +71,7 @@ _context_busy_watcher_attach_integration_source_cb(gpointer data, GObject *where void nm_context_busy_watcher_integrate_source(GMainContext *outer_context, GMainContext *inner_context, - GObject * context_busy_watcher) + GObject *context_busy_watcher) { GSource *source; @@ -141,7 +141,7 @@ typedef struct { CList iface_lst; union { const NMLDBusMetaIface *meta; - NMRefString * name; + NMRefString *name; } dbus_iface; CList changed_prop_lst_head; @@ -249,16 +249,16 @@ enum { }; typedef struct { - struct udev * udev; - GMainContext * main_context; - GMainContext * dbus_context; - GObject * context_busy_watcher; + struct udev *udev; + GMainContext *main_context; + GMainContext *dbus_context; + GObject *context_busy_watcher; GDBusConnection *dbus_connection; - NMLInitData * init_data; - GHashTable * dbus_objects; + NMLInitData *init_data; + GHashTable *dbus_objects; CList obj_changed_lst_head; - GCancellable * name_owner_get_cancellable; - GCancellable * get_managed_objects_cancellable; + GCancellable *name_owner_get_cancellable; + GCancellable *get_managed_objects_cancellable; CList queue_notify_lst_head; CList notify_event_lst_head; @@ -274,7 +274,7 @@ typedef struct { gsize log_call_counter; - guint8 * permissions; + guint8 *permissions; GCancellable *permissions_cancellable; char *name_owner; @@ -300,9 +300,9 @@ typedef struct { struct { NMLDBusPropertyO property_o[_PROPERTY_O_IDX_NM_NUM]; NMLDBusPropertyAO property_ao[_PROPERTY_AO_IDX_NM_NUM]; - char * connectivity_check_uri; - char * version; - guint32 * capabilities_arr; + char *connectivity_check_uri; + char *version; + guint32 *capabilities_arr; gsize capabilities_len; guint32 connectivity; guint32 state; @@ -319,14 +319,14 @@ typedef struct { struct { NMLDBusPropertyAO connections; - char * hostname; + char *hostname; bool can_modify; } settings; struct { GPtrArray *configuration; - char * mode; - char * rc_manager; + char *mode; + char *rc_manager; } dns_manager; } NMClientPrivate; @@ -363,11 +363,11 @@ G_DEFINE_TYPE_WITH_CODE(NMClient, static void _init_start_check_complete(NMClient *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); static void name_owner_get_call(NMClient *self); @@ -484,8 +484,8 @@ _nm_client_new_error_nm_not_cached(void) static void _nm_client_dbus_call_simple_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - GAsyncReadyCallback callback; - gpointer callback_user_data; + GAsyncReadyCallback callback; + gpointer callback_user_data; gs_unref_object GObject *context_busy_watcher = NULL; gpointer obfuscated_self_ptr; gpointer log_call_counter_ptr; @@ -506,21 +506,21 @@ _nm_client_dbus_call_simple_cb(GObject *source, GAsyncResult *result, gpointer u } void -_nm_client_dbus_call_simple(NMClient * self, - GCancellable * cancellable, - const char * object_path, - const char * interface_name, - const char * method_name, - GVariant * parameters, +_nm_client_dbus_call_simple(NMClient *self, + GCancellable *cancellable, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, const GVariantType *reply_type, GDBusCallFlags flags, int timeout_msec, GAsyncReadyCallback callback, gpointer user_data) { - NMClientPrivate * priv = NM_CLIENT_GET_PRIVATE(self); + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); nm_auto_pop_gmaincontext GMainContext *dbus_context = NULL; - gs_free char * log_str = NULL; + gs_free char *log_str = NULL; gsize log_call_counter; nm_assert(priv->name_owner); @@ -565,22 +565,22 @@ _nm_client_dbus_call_simple(NMClient * self, } void -_nm_client_dbus_call(NMClient * self, +_nm_client_dbus_call(NMClient *self, gpointer source_obj, gpointer source_tag, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback user_callback, gpointer user_callback_data, - const char * object_path, - const char * interface_name, - const char * method_name, - GVariant * parameters, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, const GVariantType *reply_type, GDBusCallFlags flags, int timeout_msec, GAsyncReadyCallback internal_callback) { - NMClientPrivate *priv; + NMClientPrivate *priv; gs_unref_object GTask *task = NULL; nm_assert(!source_obj || G_IS_OBJECT(source_obj)); @@ -622,19 +622,19 @@ _nm_client_dbus_call(NMClient * self, } GVariant * -_nm_client_dbus_call_sync(NMClient * self, - GCancellable * cancellable, - const char * object_path, - const char * interface_name, - const char * method_name, - GVariant * parameters, +_nm_client_dbus_call_sync(NMClient *self, + GCancellable *cancellable, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, const GVariantType *reply_type, GDBusCallFlags flags, int timeout_msec, gboolean strip_dbus_error, - GError ** error) + GError **error) { - NMClientPrivate *priv; + NMClientPrivate *priv; gs_unref_variant GVariant *ret = NULL; nm_assert(!cancellable || G_IS_CANCELLABLE(cancellable)); @@ -679,16 +679,16 @@ _nm_client_dbus_call_sync(NMClient * self, } gboolean -_nm_client_dbus_call_sync_void(NMClient * self, - GCancellable * cancellable, - const char * object_path, - const char * interface_name, - const char * method_name, - GVariant * parameters, +_nm_client_dbus_call_sync_void(NMClient *self, + GCancellable *cancellable, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, GDBusCallFlags flags, int timeout_msec, gboolean strip_dbus_error, - GError ** error) + GError **error) { gs_unref_variant GVariant *ret = NULL; @@ -707,15 +707,15 @@ _nm_client_dbus_call_sync_void(NMClient * self, } void -_nm_client_set_property_sync_legacy(NMClient * self, +_nm_client_set_property_sync_legacy(NMClient *self, const char *object_path, const char *interface_name, const char *property_name, const char *format_string, ...) { - NMClientPrivate *priv; - GVariant * val; + NMClientPrivate *priv; + GVariant *val; gs_unref_variant GVariant *ret = NULL; va_list ap; @@ -816,12 +816,12 @@ _nm_client_queue_notify_object(NMClient *self, gpointer nmobj, const GParamSpec /*****************************************************************************/ gpointer -_nm_client_notify_event_queue(NMClient * self, +_nm_client_notify_event_queue(NMClient *self, int priority, NMClientNotifyEventCb callback, gsize event_size) { - NMClientPrivate * priv = NM_CLIENT_GET_PRIVATE(self); + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); NMClientNotifyEvent *notify_event; nm_assert(callback); @@ -836,7 +836,7 @@ _nm_client_notify_event_queue(NMClient * self, } NMClientNotifyEventWithPtr * -_nm_client_notify_event_queue_with_ptr(NMClient * self, +_nm_client_notify_event_queue_with_ptr(NMClient *self, int priority, NMClientNotifyEventWithPtrCb callback, gpointer user_data) @@ -855,8 +855,8 @@ _nm_client_notify_event_queue_with_ptr(NMClient * self, typedef struct { NMClientNotifyEvent parent; - GObject * source; - NMObject * obj; + GObject *source; + NMObject *obj; guint signal_id; } NMClientNotifyEventObjAddedRemove; @@ -882,7 +882,7 @@ _nm_client_notify_event_queue_emit_obj_signal_cb(NMClient *self, gpointer notify void _nm_client_notify_event_queue_emit_obj_signal(NMClient *self, - GObject * source, + GObject *source, NMObject *nmobj, gboolean is_added /* or else removed */, int prio_offset, @@ -924,7 +924,7 @@ _nm_client_notify_event_cmp(const CList *a, const CList *b, const void *user_dat static void _nm_client_notify_event_emit_parts(NMClient *self, int max_priority /* included! */) { - NMClientPrivate * priv = NM_CLIENT_GET_PRIVATE(self); + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); NMClientNotifyEvent *notify_event; while (TRUE) { @@ -947,7 +947,7 @@ static void _nm_client_notify_event_emit(NMClient *self) { NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); - NMObjectBase * base; + NMObjectBase *base; _nm_client_notify_event_emit_parts(self, NM_CLIENT_NOTIFY_EVENT_PRIO_GPROP); @@ -1137,12 +1137,12 @@ nml_dbus_object_unref(NMLDBusObject *dbobj) static NMLDBusObjIfaceData * nml_dbus_object_iface_data_get(NMLDBusObject *dbobj, - const char * dbus_iface_name, + const char *dbus_iface_name, gboolean allow_create) { const NMLDBusMetaIface *meta_iface; - NMLDBusObjIfaceData * db_iface_data; - NMLDBusObjPropData * db_prop_data; + NMLDBusObjIfaceData *db_iface_data; + NMLDBusObjPropData *db_prop_data; guint count = 0; guint i; @@ -1245,8 +1245,8 @@ nml_dbus_obj_iface_data_destroy(NMLDBusObjIfaceData *db_iface_data) } gpointer -nml_dbus_object_get_property_location(NMLDBusObject * dbobj, - const NMLDBusMetaIface * meta_iface, +nml_dbus_object_get_property_location(NMLDBusObject *dbobj, + const NMLDBusMetaIface *meta_iface, const NMLDBusMetaProperty *meta_property) { char *target_c; @@ -1327,14 +1327,16 @@ nml_dbus_object_set_obj_state(NMLDBusObject *dbobj, NMLDBusObjState obj_state, N /*****************************************************************************/ static void -nml_dbus_object_obj_changed_link(NMClient * self, - NMLDBusObject * dbobj, +nml_dbus_object_obj_changed_link(NMClient *self, + NMLDBusObject *dbobj, NMLDBusObjChangedType changed_type) { nm_assert(NM_IS_CLIENT(self)); nm_assert(NML_IS_DBUS_OBJECT(dbobj)); nm_assert(changed_type != NML_DBUS_OBJ_CHANGED_TYPE_NONE); + /* Links @dbobj in the "obj_changed_lst", with the new "changed_type". */ + if (!NM_FLAGS_ALL((NMLDBusObjChangedType) dbobj->obj_changed_type, changed_type)) NML_NMCLIENT_LOG_T(self, "[%s]: changed-type 0x%02x linked", @@ -1365,13 +1367,19 @@ nml_dbus_object_obj_changed_link(NMClient * self, } static NMLDBusObjChangedType -nml_dbus_object_obj_changed_consume(NMClient * self, - NMLDBusObject * dbobj, +nml_dbus_object_obj_changed_consume(NMClient *self, + NMLDBusObject *dbobj, NMLDBusObjChangedType changed_type) { - NMClientPrivate * priv; + NMClientPrivate *priv; NMLDBusObjChangedType changed_type_res; + /* We have @dbobj which has some "obj_changed_type" set (consequently, + * it's linked in the "obj_changed_lst"). Here we consume the @changed_type, + * meaning, to clear those flags from "obj_change_type" (and return + * the flags that were cleared/present or NONE, if the current object + * doesn't have these changed-types. */ + nm_assert(NM_IS_CLIENT(self)); nm_assert(NML_IS_DBUS_OBJECT(dbobj)); nm_assert(changed_type != NML_DBUS_OBJ_CHANGED_TYPE_NONE); @@ -1383,6 +1391,8 @@ nml_dbus_object_obj_changed_consume(NMClient * self, dbobj->obj_changed_type &= ~changed_type; if (dbobj->obj_changed_type == NML_DBUS_OBJ_CHANGED_TYPE_NONE) { + /* No other "obj_change_type" left. Unlink the object from the + * "changed_type_list". */ c_list_unlink(&dbobj->obj_changed_lst); nm_assert(changed_type_res != NML_DBUS_OBJ_CHANGED_TYPE_NONE); NML_NMCLIENT_LOG_T(self, @@ -1394,6 +1404,9 @@ nml_dbus_object_obj_changed_consume(NMClient * self, priv = NM_CLIENT_GET_PRIVATE(self); + /* Actually, at this point, @dbobj is not linked in priv->obj_changed_lst_head, + * instead, it's linked on a temporary list. As we still have changes left after + * consuming "changed_type", we move it to priv->obj_changed_lst_head. */ nm_assert(!c_list_contains(&priv->obj_changed_lst_head, &dbobj->obj_changed_lst)); nm_c_list_move_tail(&priv->obj_changed_lst_head, &dbobj->obj_changed_lst); NML_NMCLIENT_LOG_T(self, @@ -1408,7 +1421,7 @@ static gboolean nml_dbus_object_obj_changed_any_linked(NMClient *self, NMLDBusObjChangedType changed_type) { NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); - NMLDBusObject * dbobj; + NMLDBusObject *dbobj; nm_assert(changed_type != NML_DBUS_OBJ_CHANGED_TYPE_NONE); @@ -1491,8 +1504,8 @@ static NMLDBusObject * _dbobjs_dbobj_create(NMClient *self, NMRefString *dbus_path_take) { nm_auto_ref_string NMRefString *dbus_path = g_steal_pointer(&dbus_path_take); - NMClientPrivate * priv = NM_CLIENT_GET_PRIVATE(self); - NMLDBusObject * dbobj; + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); + NMLDBusObject *dbobj; nm_assert(!_dbobjs_dbobj_get_r(self, dbus_path)); @@ -1506,7 +1519,7 @@ static NMLDBusObject * _dbobjs_dbobj_get_or_create(NMClient *self, NMRefString *dbus_path_take) { nm_auto_ref_string NMRefString *dbus_path = g_steal_pointer(&dbus_path_take); - NMLDBusObject * dbobj; + NMLDBusObject *dbobj; dbobj = _dbobjs_dbobj_get_r(self, dbus_path); if (dbobj) @@ -1550,8 +1563,8 @@ _dbobjs_get_nmobj_unpack_visible(NMClient *self, const char *dbus_path, GType gt /*****************************************************************************/ static gpointer -_dbobjs_obj_watcher_register_o(NMClient * self, - NMLDBusObject * dbobj, +_dbobjs_obj_watcher_register_o(NMClient *self, + NMLDBusObject *dbobj, NMLDBusObjWatchNotifyFcn notify_fcn, gsize struct_size) { @@ -1576,13 +1589,13 @@ _dbobjs_obj_watcher_register_o(NMClient * self, } static gpointer -_dbobjs_obj_watcher_register_r(NMClient * self, - NMRefString * dbus_path_take, +_dbobjs_obj_watcher_register_r(NMClient *self, + NMRefString *dbus_path_take, NMLDBusObjWatchNotifyFcn notify_fcn, gsize struct_size) { nm_auto_ref_string NMRefString *dbus_path = g_steal_pointer(&dbus_path_take); - NMLDBusObject * dbobj; + NMLDBusObject *dbobj; nm_assert(NM_IS_CLIENT(self)); nm_assert(notify_fcn); @@ -1597,7 +1610,7 @@ static void _dbobjs_obj_watcher_unregister(NMClient *self, gpointer obj_watcher_base) { NMLDBusObjWatcher *obj_watcher = obj_watcher_base; - NMLDBusObject * dbobj; + NMLDBusObject *dbobj; nm_assert(NM_IS_CLIENT(self)); nm_assert(obj_watcher); @@ -1654,7 +1667,7 @@ static void nml_dbus_property_o_notify_changed(NMLDBusPropertyO *pr_o, NMClient *self) { const NMLDBusPropertVTableO *vtable; - GObject * nmobj = NULL; + GObject *nmobj = NULL; gboolean is_ready = TRUE; gboolean changed_ready; GType gtype; @@ -1759,7 +1772,7 @@ nml_dbus_property_o_notify_changed_many(NMLDBusPropertyO *ptr, guint len, NMClie static void nml_dbus_property_o_notify_watch_cb(NMClient *self, gpointer obj_watcher) { - PropertyOData * pr_o_data = obj_watcher; + PropertyOData *pr_o_data = obj_watcher; NMLDBusPropertyO *pr_o = pr_o_data->pr_o; nm_assert(pr_o->obj_watcher == obj_watcher); @@ -1771,12 +1784,12 @@ nml_dbus_property_o_notify_watch_cb(NMClient *self, gpointer obj_watcher) } static NMLDBusNotifyUpdatePropFlags -nml_dbus_property_o_notify(NMClient * self, - NMLDBusPropertyO * pr_o, - NMLDBusObject * dbobj, +nml_dbus_property_o_notify(NMClient *self, + NMLDBusPropertyO *pr_o, + NMLDBusObject *dbobj, const NMLDBusMetaIface *meta_iface, guint dbus_property_idx, - GVariant * value) + GVariant *value) { const char *dbus_path = NULL; gboolean changed = FALSE; @@ -1837,6 +1850,7 @@ nml_dbus_property_o_clear(NMLDBusPropertyO *pr_o, NMClient *self) pr_o->meta_iface = NULL; pr_o->dbus_property_idx = 0; pr_o->is_ready = FALSE; + pr_o->nmobj = NULL; } void @@ -1850,9 +1864,9 @@ nml_dbus_property_o_clear_many(NMLDBusPropertyO *pr_o, guint len, NMClient *self typedef struct _NMLDBusPropertyAOData { NMLDBusObjWatcher obj_watcher; - NMLDBusPropertyAO * parent; + NMLDBusPropertyAO *parent; CList data_lst; - GObject * nmobj; + GObject *nmobj; struct _NMLDBusPropertyAOData *changed_next; bool is_ready : 1; bool is_notified : 1; @@ -1894,10 +1908,10 @@ _ASSERT_pr_ao(NMLDBusPropertyAO *pr_ao) static gboolean nml_dbus_property_ao_notify_changed_ao(PropertyAOData *pr_ao_data, - NMClient * self, + NMClient *self, gboolean is_added /* or else removed */) { - NMLDBusPropertyAO * pr_ao; + NMLDBusPropertyAO *pr_ao; const NMLDBusPropertVTableAO *vtable; if (!pr_ao_data->nmobj) @@ -1979,7 +1993,7 @@ nml_dbus_property_ao_notify_changed(NMLDBusPropertyAO *pr_ao, NMClient *self) while (pr_ao->changed_head) { const NMLDBusPropertVTableAO *vtable; - GObject * nmobj = NULL; + GObject *nmobj = NULL; gboolean is_ready = TRUE; GType gtype; @@ -2098,7 +2112,7 @@ nml_dbus_property_ao_notify_changed_many(NMLDBusPropertyAO *ptr, guint len, NMCl static void nml_dbus_property_ao_notify_watch_cb(NMClient *self, gpointer obj_watcher) { - PropertyAOData * pr_ao_data = obj_watcher; + PropertyAOData *pr_ao_data = obj_watcher; NMLDBusPropertyAO *pr_ao = pr_ao_data->parent; nm_assert(g_hash_table_lookup(pr_ao->hash, pr_ao_data) == pr_ao_data); @@ -2119,12 +2133,12 @@ nml_dbus_property_ao_notify_watch_cb(NMClient *self, gpointer obj_watcher) } NMLDBusNotifyUpdatePropFlags -nml_dbus_property_ao_notify(NMClient * self, - NMLDBusPropertyAO * pr_ao, - NMLDBusObject * dbobj, +nml_dbus_property_ao_notify(NMClient *self, + NMLDBusPropertyAO *pr_ao, + NMLDBusObject *dbobj, const NMLDBusMetaIface *meta_iface, guint dbus_property_idx, - GVariant * value) + GVariant *value) { CList stale_lst_head = C_LIST_INIT(stale_lst_head); PropertyAOData *pr_ao_data; @@ -2158,7 +2172,7 @@ nml_dbus_property_ao_notify(NMClient * self, if (value) { GVariantIter iter; - const char * path; + const char *path; g_variant_iter_init(&iter, value); while (g_variant_iter_next(&iter, "&o", &path)) { @@ -2344,23 +2358,23 @@ nml_dbus_property_ao_clear_many(NMLDBusPropertyAO *pr_ao, guint len, NMClient *s /*****************************************************************************/ NMLDBusNotifyUpdatePropFlags -_nml_dbus_notify_update_prop_ignore(NMClient * self, - NMLDBusObject * dbobj, +_nml_dbus_notify_update_prop_ignore(NMClient *self, + NMLDBusObject *dbobj, const NMLDBusMetaIface *meta_iface, guint dbus_property_idx, - GVariant * value) + GVariant *value) { return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NONE; } NMLDBusNotifyUpdatePropFlags -_nml_dbus_notify_update_prop_o(NMClient * self, - NMLDBusObject * dbobj, +_nml_dbus_notify_update_prop_o(NMClient *self, + NMLDBusObject *dbobj, const NMLDBusMetaIface *meta_iface, guint dbus_property_idx, - GVariant * value) + GVariant *value) { - const char * path = NULL; + const char *path = NULL; NMRefString **p_property; if (value) @@ -2381,17 +2395,17 @@ _nml_dbus_notify_update_prop_o(NMClient * self, /*****************************************************************************/ static void -_obj_handle_dbus_prop_changes(NMClient * self, - NMLDBusObject * dbobj, +_obj_handle_dbus_prop_changes(NMClient *self, + NMLDBusObject *dbobj, NMLDBusObjIfaceData *db_iface_data, guint dbus_property_idx, - GVariant * value) + GVariant *value) { - const NMLDBusMetaIface * meta_iface = db_iface_data->dbus_iface.meta; - const NMLDBusMetaProperty * meta_property = &meta_iface->dbus_properties[dbus_property_idx]; + const NMLDBusMetaIface *meta_iface = db_iface_data->dbus_iface.meta; + const NMLDBusMetaProperty *meta_property = &meta_iface->dbus_properties[dbus_property_idx]; gpointer p_property; - const char * dbus_type_s; - const GParamSpec * param_spec; + const char *dbus_type_s; + const GParamSpec *param_spec; NMLDBusNotifyUpdatePropFlags notify_update_prop_flags; nm_assert(G_IS_OBJECT(dbobj->nmobj)); @@ -2528,7 +2542,7 @@ _obj_handle_dbus_prop_changes(NMClient * self, { gconstpointer v; gsize l; - GBytes * b = NULL; + GBytes *b = NULL; if (value) { v = g_variant_get_fixed_array(value, &l, 1); @@ -2576,8 +2590,8 @@ notify: } static void -_obj_handle_dbus_iface_changes(NMClient * self, - NMLDBusObject * dbobj, +_obj_handle_dbus_iface_changes(NMClient *self, + NMLDBusObject *dbobj, NMLDBusObjIfaceData *db_iface_data) { NMLDBusObjPropData *db_prop_data; @@ -2648,9 +2662,9 @@ _obj_handle_dbus_iface_changes(NMClient * self, static void _obj_handle_dbus_changes(NMClient *self, NMLDBusObject *dbobj) { - NMClientPrivate * priv = NM_CLIENT_GET_PRIVATE(self); - NMLDBusObjIfaceData *db_iface_data; - NMLDBusObjIfaceData *db_iface_data_safe; + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); + NMLDBusObjIfaceData *db_iface_data; + NMLDBusObjIfaceData *db_iface_data_safe; gs_unref_object GObject *nmobj_unregistering = NULL; _ASSERT_dbobj(dbobj, self); @@ -2791,7 +2805,7 @@ static void _dbus_handle_obj_changed_nmobj(NMClient *self) { NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); - NMLDBusObject * dbobj; + NMLDBusObject *dbobj; CList obj_changed_tmp_lst_head = C_LIST_INIT(obj_changed_tmp_lst_head); nm_assert(!nml_dbus_object_obj_changed_any_linked(self, ~NML_DBUS_OBJ_CHANGED_TYPE_NMOBJ)); @@ -2852,7 +2866,7 @@ static void _dbus_handle_obj_changed_dbus(NMClient *self, const char *log_context) { NMClientPrivate *priv; - NMLDBusObject * dbobj; + NMLDBusObject *dbobj; CList obj_changed_tmp_lst_head = C_LIST_INIT(obj_changed_tmp_lst_head); priv = NM_CLIENT_GET_PRIVATE(self); @@ -2898,7 +2912,7 @@ _dbus_handle_obj_changed_dbus(NMClient *self, const char *log_context) static void _dbus_handle_changes_commit(NMClient *self, gboolean allow_init_start_check_complete) { - NMClientPrivate * priv = NM_CLIENT_GET_PRIVATE(self); + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); nm_auto_pop_gmaincontext GMainContext *dbus_context = NULL; _dbus_handle_obj_changed_nmobj(self); @@ -2914,7 +2928,7 @@ _dbus_handle_changes_commit(NMClient *self, gboolean allow_init_start_check_comp } static void -_dbus_handle_changes(NMClient * self, +_dbus_handle_changes(NMClient *self, const char *log_context, gboolean allow_init_start_check_complete) { @@ -2923,17 +2937,17 @@ _dbus_handle_changes(NMClient * self, } static gboolean -_dbus_handle_properties_changed(NMClient * self, - const char * log_context, - const char * object_path, - const char * interface_name, +_dbus_handle_properties_changed(NMClient *self, + const char *log_context, + const char *object_path, + const char *interface_name, gboolean allow_add_iface, - GVariant * changed_properties, + GVariant *changed_properties, NMLDBusObject **inout_dbobj) { - NMLDBusObject * dbobj = NULL; - NMLDBusObjIfaceData *db_iface_data = NULL; - nm_auto_ref_string NMRefString *dbus_path = NULL; + NMLDBusObject *dbobj = NULL; + NMLDBusObjIfaceData *db_iface_data = NULL; + nm_auto_ref_string NMRefString *dbus_path = NULL; nm_assert(!changed_properties || g_variant_is_of_type(changed_properties, G_VARIANT_TYPE("a{sv}"))); @@ -3000,14 +3014,14 @@ _dbus_handle_properties_changed(NMClient * self, interface_name); else if (changed_properties) { GVariantIter iter_prop; - const char * property_name; - GVariant * property_value_tmp; + const char *property_name; + GVariant *property_value_tmp; g_variant_iter_init(&iter_prop, changed_properties); while (g_variant_iter_next(&iter_prop, "{&sv}", &property_name, &property_value_tmp)) { _nm_unused gs_unref_variant GVariant *property_value = property_value_tmp; - const NMLDBusMetaProperty * meta_property; - NMLDBusObjPropData * db_propdata; + const NMLDBusMetaProperty *meta_property; + NMLDBusObjPropData *db_propdata; guint property_idx; meta_property = nml_dbus_meta_property_get(db_iface_data->dbus_iface.meta, @@ -3045,14 +3059,14 @@ _dbus_handle_properties_changed(NMClient * self, } static gboolean -_dbus_handle_interface_added(NMClient * self, +_dbus_handle_interface_added(NMClient *self, const char *log_context, const char *object_path, - GVariant * ifaces) + GVariant *ifaces) { gboolean changed = FALSE; - const char * interface_name; - GVariant * changed_properties; + const char *interface_name; + GVariant *changed_properties; GVariantIter iter_ifaces; NMLDBusObject *dbobj = NULL; @@ -3076,10 +3090,10 @@ _dbus_handle_interface_added(NMClient * self, } static gboolean -_dbus_handle_interface_removed(NMClient * self, - const char * log_context, - const char * object_path, - NMLDBusObject ** inout_dbobj, +_dbus_handle_interface_removed(NMClient *self, + const char *log_context, + const char *object_path, + NMLDBusObject **inout_dbobj, const char *const *removed_interfaces) { gboolean changed = FALSE; @@ -3103,7 +3117,7 @@ _dbus_handle_interface_removed(NMClient * self, for (i = 0; removed_interfaces[i]; i++) { NMLDBusObjIfaceData *db_iface_data; - const char * interface_name = removed_interfaces[i]; + const char *interface_name = removed_interfaces[i]; db_iface_data = nml_dbus_object_iface_data_get(dbobj, interface_name, FALSE); if (!db_iface_data) { @@ -3133,16 +3147,16 @@ _dbus_handle_interface_removed(NMClient * 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) { - NMClient * self = user_data; + NMClient *self = user_data; NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); - const char * log_context; + const char *log_context; gboolean changed; nm_assert(nm_streq0(interface_name, DBUS_INTERFACE_OBJECT_MANAGER)); @@ -3154,7 +3168,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; @@ -3169,7 +3183,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; @@ -3190,19 +3204,19 @@ out: 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) { - NMClient * self = user_data; - NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); - const char * interface_name; + NMClient *self = user_data; + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); + const char *interface_name; gs_unref_variant GVariant *changed_properties = NULL; - gs_free const char ** invalidated_properties = NULL; - const char * log_context = "properties-changed"; + gs_free const char **invalidated_properties = NULL; + const char *log_context = "properties-changed"; if (priv->get_managed_objects_cancellable) { /* we still wait for the initial GetManagedObjects(). Ignore the event. */ @@ -3239,12 +3253,12 @@ _dbus_properties_changed_cb(GDBusConnection *connection, static void _dbus_get_managed_objects_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - NMClient * self; - NMClientPrivate *priv; - gs_unref_variant GVariant *ret = NULL; - gs_unref_variant GVariant *managed_objects = NULL; - gs_free_error GError *error = NULL; - gs_unref_object GObject *context_busy_watcher = NULL; + NMClient *self; + NMClientPrivate *priv; + gs_unref_variant GVariant *ret = NULL; + gs_unref_variant GVariant *managed_objects = NULL; + gs_free_error GError *error = NULL; + gs_unref_object GObject *context_busy_watcher = NULL; nm_utils_user_data_unpack(user_data, &self, &context_busy_watcher); @@ -3273,8 +3287,8 @@ _dbus_get_managed_objects_cb(GObject *source, GAsyncResult *result, gpointer use if (managed_objects) { GVariantIter iter; - const char * object_path; - GVariant * ifaces_tmp; + const char *object_path; + GVariant *ifaces_tmp; g_variant_iter_init(&iter, managed_objects); while (g_variant_iter_next(&iter, "{&o@a{sa{sv}}}", &object_path, &ifaces_tmp)) { @@ -3294,12 +3308,12 @@ _dbus_get_managed_objects_cb(GObject *source, GAsyncResult *result, gpointer use static void _nm_client_get_settings_call_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - NMRemoteConnection *remote_connection; - NMClient * self; + NMRemoteConnection *remote_connection; + NMClient *self; gs_unref_variant GVariant *ret = NULL; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; gs_unref_variant GVariant *settings = NULL; - NMLDBusObject * dbobj; + NMLDBusObject *dbobj; ret = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), result, &error); if (!ret && nm_utils_error_is_cancelled(error)) @@ -3352,17 +3366,17 @@ _nm_client_get_settings_call(NMClient *self, NMLDBusObject *dbobj) static void _dbus_settings_updated_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) { - NMClient * self = user_data; + NMClient *self = user_data; NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); - const char * log_context = "settings-updated"; - NMLDBusObject * dbobj; + const char *log_context = "settings-updated"; + NMLDBusObject *dbobj; if (priv->get_managed_objects_cancellable) { /* we still wait for the initial GetManagedObjects(). Ignore the event. */ @@ -3391,17 +3405,17 @@ _dbus_settings_updated_cb(GDBusConnection *connection, static void _dbus_nm_connection_active_state_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) { - NMClient * self = user_data; + NMClient *self = user_data; NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); - const char * log_context = "active-connection-state-changed"; - NMLDBusObject * dbobj; + const char *log_context = "active-connection-state-changed"; + NMLDBusObject *dbobj; guint32 state; guint32 reason; @@ -3441,17 +3455,17 @@ _dbus_nm_connection_active_state_changed_cb(GDBusConnection *connection, static void _dbus_nm_vpn_connection_state_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) { - NMClient * self = user_data; + NMClient *self = user_data; NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); - const char * log_context = "vpn-connection-state-changed"; - NMLDBusObject * dbobj; + const char *log_context = "vpn-connection-state-changed"; + NMLDBusObject *dbobj; guint32 state; guint32 reason; @@ -3520,16 +3534,16 @@ _emit_permissions_changed(NMClient *self, const guint8 *old_permissions, const g static void _dbus_check_permissions_start_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - nm_auto_pop_gmaincontext GMainContext *dbus_context = NULL; - NMClient * self; - NMClientPrivate * priv; - gs_unref_variant GVariant *ret = NULL; - nm_auto_free_variant_iter GVariantIter *v_permissions = NULL; - gs_free guint8 *old_permissions = NULL; - gs_free_error GError *error = NULL; - const char * pkey; - const char * pvalue; - int i; + nm_auto_pop_gmaincontext GMainContext *dbus_context = NULL; + NMClient *self; + NMClientPrivate *priv; + gs_unref_variant GVariant *ret = NULL; + nm_auto_free_variant_iter GVariantIter *v_permissions = NULL; + gs_free guint8 *old_permissions = NULL; + gs_free_error GError *error = NULL; + const char *pkey; + const char *pvalue; + int i; ret = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), result, &error); if (!ret && nm_utils_error_is_cancelled(error)) @@ -3611,14 +3625,14 @@ _dbus_check_permissions_start(NMClient *self) static void _dbus_nm_check_permissions_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) { - NMClient * self = user_data; + NMClient *self = user_data; NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); if (!g_variant_is_of_type(parameters, G_VARIANT_TYPE("()"))) { @@ -3639,8 +3653,8 @@ _dbus_nm_check_permissions_cb(GDBusConnection *connection, static void _property_ao_notify_changed_connections_cb(NMLDBusPropertyAO *pr_ao, - NMClient * self, - NMObject * nmobj, + NMClient *self, + NMObject *nmobj, gboolean is_added /* or else removed */) { _nm_client_notify_event_queue_emit_obj_signal(self, @@ -3654,8 +3668,8 @@ _property_ao_notify_changed_connections_cb(NMLDBusPropertyAO *pr_ao, static void _property_ao_notify_changed_all_devices_cb(NMLDBusPropertyAO *pr_ao, - NMClient * self, - NMObject * nmobj, + NMClient *self, + NMObject *nmobj, gboolean is_added /* or else removed */) { _nm_client_notify_event_queue_emit_obj_signal(self, @@ -3669,8 +3683,8 @@ _property_ao_notify_changed_all_devices_cb(NMLDBusPropertyAO *pr_ao, static void _property_ao_notify_changed_devices_cb(NMLDBusPropertyAO *pr_ao, - NMClient * self, - NMObject * nmobj, + NMClient *self, + NMObject *nmobj, gboolean is_added /* or else removed */) { _nm_client_notify_event_queue_emit_obj_signal(self, @@ -3684,8 +3698,8 @@ _property_ao_notify_changed_devices_cb(NMLDBusPropertyAO *pr_ao, static void _property_ao_notify_changed_active_connections_cb(NMLDBusPropertyAO *pr_ao, - NMClient * self, - NMObject * nmobj, + NMClient *self, + NMObject *nmobj, gboolean is_added /* or else removed */) { _nm_client_notify_event_queue_emit_obj_signal(self, @@ -3701,10 +3715,10 @@ _property_ao_notify_changed_active_connections_cb(NMLDBusPropertyAO *pr_ao, typedef struct { NMLDBusObjWatcherWithPtr *obj_watcher; - const char * op_name; - NMLDBusObject * dbobj; - GTask * task; - GVariant * extra_results; + const char *op_name; + NMLDBusObject *dbobj; + GTask *task; + GVariant *extra_results; gpointer result; GType gtype; gulong cancellable_id; @@ -3801,8 +3815,8 @@ static void _request_wait_obj_watcher_cb(NMClient *self, gpointer obj_watcher_base) { NMLDBusObjWatcherWithPtr *obj_watcher = obj_watcher_base; - RequestWaitData * request_data = obj_watcher->user_data; - NMLDBusObject * dbobj; + RequestWaitData *request_data = obj_watcher->user_data; + NMLDBusObject *dbobj; dbobj = request_data->dbobj; @@ -3829,8 +3843,8 @@ static void _request_wait_cancelled_cb(GCancellable *cancellable, gpointer user_data) { RequestWaitData *request_data = user_data; - NMClient * self; - GError * error = NULL; + NMClient *self; + GError *error = NULL; nm_assert(cancellable == g_task_get_cancellable(request_data->task)); @@ -3848,17 +3862,17 @@ _request_wait_cancelled_cb(GCancellable *cancellable, gpointer user_data) } static void -_request_wait_start(GTask * task_take, +_request_wait_start(GTask *task_take, const char *op_name, GType gtype, const char *dbus_path, - GVariant * extra_results_take) + GVariant *extra_results_take) { - NMClient * self; + NMClient *self; gs_unref_object GTask *task = g_steal_pointer(&task_take); - RequestWaitData * request_data; - GCancellable * cancellable; - NMLDBusObject * dbobj; + RequestWaitData *request_data; + GCancellable *cancellable; + NMLDBusObject *dbobj; nm_assert(G_IS_TASK(task)); @@ -3922,11 +3936,11 @@ _request_wait_start(GTask * task_take, } static gpointer -_request_wait_finish(NMClient * client, +_request_wait_finish(NMClient *client, GAsyncResult *result, gpointer source_tag, - GVariant ** out_result, - GError ** error) + GVariant **out_result, + GError **error) { RequestWaitData *request_data = NULL; gpointer r; @@ -4501,7 +4515,7 @@ nm_client_set_logging(NMClient *client, const char *level, const char *domains, NMClientPermissionResult nm_client_get_permission_result(NMClient *client, NMClientPermission permission) { - NMClientPrivate * priv; + NMClientPrivate *priv; NMClientPermissionResult result = NM_CLIENT_PERMISSION_RESULT_UNKNOWN; g_return_val_if_fail(NM_IS_CLIENT(client), NM_CLIENT_PERMISSION_RESULT_UNKNOWN); @@ -4575,7 +4589,7 @@ nm_client_get_connectivity(NMClient *client) NMConnectivityState nm_client_check_connectivity(NMClient *client, GCancellable *cancellable, GError **error) { - NMClientPrivate *priv; + NMClientPrivate *priv; gs_unref_variant GVariant *ret = NULL; guint32 connectivity; @@ -4626,8 +4640,8 @@ nm_client_check_connectivity(NMClient *client, GCancellable *cancellable, GError * re-checking, and nm_client_check_connectivity(), which blocks. */ void -nm_client_check_connectivity_async(NMClient * client, - GCancellable * cancellable, +nm_client_check_connectivity_async(NMClient *client, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -4695,10 +4709,10 @@ nm_client_check_connectivity_finish(NMClient *client, GAsyncResult *result, GErr * Deprecated: 1.22: Use nm_client_save_hostname_async() or GDBusConnection. **/ gboolean -nm_client_save_hostname(NMClient * client, - const char * hostname, +nm_client_save_hostname(NMClient *client, + const char *hostname, GCancellable *cancellable, - GError ** error) + GError **error) { g_return_val_if_fail(NM_IS_CLIENT(client), FALSE); g_return_val_if_fail(!cancellable || G_IS_CANCELLABLE(cancellable), FALSE); @@ -4728,9 +4742,9 @@ nm_client_save_hostname(NMClient * client, * or cleared. **/ void -nm_client_save_hostname_async(NMClient * client, - const char * hostname, - GCancellable * cancellable, +nm_client_save_hostname_async(NMClient *client, + const char *hostname, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -4950,10 +4964,10 @@ nm_client_get_activating_connection(NMClient *client) static void activate_connection_cb(GObject *object, GAsyncResult *result, gpointer user_data) { - gs_unref_object GTask *task = user_data; - gs_unref_variant GVariant *ret = NULL; - const char * v_active_connection; - GError * error = NULL; + gs_unref_object GTask *task = user_data; + gs_unref_variant GVariant *ret = NULL; + const char *v_active_connection; + GError *error = NULL; ret = g_dbus_connection_call_finish(G_DBUS_CONNECTION(object), result, &error); if (!ret) { @@ -5006,11 +5020,11 @@ activate_connection_cb(GObject *object, GAsyncResult *result, gpointer user_data * track the activation to its completion. **/ void -nm_client_activate_connection_async(NMClient * client, - NMConnection * connection, - NMDevice * device, - const char * specific_object, - GCancellable * cancellable, +nm_client_activate_connection_async(NMClient *client, + NMConnection *connection, + NMDevice *device, + const char *specific_object, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -5076,17 +5090,17 @@ nm_client_activate_connection_finish(NMClient *client, GAsyncResult *result, GEr /*****************************************************************************/ static void -_add_and_activate_connection_done(GObject * object, +_add_and_activate_connection_done(GObject *object, GAsyncResult *result, gboolean use_add_and_activate_v2, - GTask * task_take) + GTask *task_take) { - _nm_unused gs_unref_object GTask *task = task_take; - gs_unref_variant GVariant *ret = NULL; - GError * error = NULL; - gs_unref_variant GVariant *v_result = NULL; - const char * v_active_connection; - const char * v_path; + _nm_unused gs_unref_object GTask *task = task_take; + gs_unref_variant GVariant *ret = NULL; + GError *error = NULL; + gs_unref_variant GVariant *v_result = NULL; + const char *v_active_connection; + const char *v_path; ret = g_dbus_connection_call_finish(G_DBUS_CONNECTION(object), result, &error); if (!ret) { @@ -5122,17 +5136,17 @@ _add_and_activate_connection_v2_cb(GObject *object, GAsyncResult *result, gpoint } static void -_add_and_activate_connection(NMClient * self, +_add_and_activate_connection(NMClient *self, gboolean is_v2, - NMConnection * partial, - NMDevice * device, - const char * specific_object, - GVariant * options, - GCancellable * cancellable, + NMConnection *partial, + NMDevice *device, + const char *specific_object, + GVariant *options, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { - GVariant * arg_connection = NULL; + GVariant *arg_connection = NULL; gboolean use_add_and_activate_v2 = FALSE; const char *arg_device = NULL; gpointer source_tag; @@ -5239,11 +5253,11 @@ _add_and_activate_connection(NMClient * self, * track the activation to its completion. **/ void -nm_client_add_and_activate_connection_async(NMClient * client, - NMConnection * partial, - NMDevice * device, - const char * specific_object, - GCancellable * cancellable, +nm_client_add_and_activate_connection_async(NMClient *client, + NMConnection *partial, + NMDevice *device, + const char *specific_object, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -5326,12 +5340,12 @@ nm_client_add_and_activate_connection_finish(NMClient *client, GAsyncResult *res * Since: 1.16 **/ void -nm_client_add_and_activate_connection2(NMClient * client, - NMConnection * partial, - NMDevice * device, - const char * specific_object, - GVariant * options, - GCancellable * cancellable, +nm_client_add_and_activate_connection2(NMClient *client, + NMConnection *partial, + NMDevice *device, + const char *specific_object, + GVariant *options, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -5351,7 +5365,7 @@ nm_client_add_and_activate_connection2(NMClient * client, * @client: an #NMClient * @result: the result passed to the #GAsyncReadyCallback * @error: location for a #GError, or %NULL - * @out_result: (allow-none) (transfer full): the output result + * @out_result: (allow-none) (transfer full) (out): the output result * of type "a{sv}" returned by D-Bus' AddAndActivate2 call. Currently, no * output is implemented yet. * @@ -5364,10 +5378,10 @@ nm_client_add_and_activate_connection2(NMClient * client, * failure, in which case @error will be set. **/ NMActiveConnection * -nm_client_add_and_activate_connection2_finish(NMClient * client, +nm_client_add_and_activate_connection2_finish(NMClient *client, GAsyncResult *result, - GVariant ** out_result, - GError ** error) + GVariant **out_result, + GError **error) { return NM_ACTIVE_CONNECTION(_request_wait_finish(client, result, @@ -5392,10 +5406,10 @@ nm_client_add_and_activate_connection2_finish(NMClient * client, * Deprecated: 1.22: Use nm_client_deactivate_connection_async() or GDBusConnection. **/ gboolean -nm_client_deactivate_connection(NMClient * client, +nm_client_deactivate_connection(NMClient *client, NMActiveConnection *active, - GCancellable * cancellable, - GError ** error) + GCancellable *cancellable, + GError **error) { const char *active_path; @@ -5428,9 +5442,9 @@ nm_client_deactivate_connection(NMClient * client, * Asynchronously deactivates an active #NMActiveConnection. **/ void -nm_client_deactivate_connection_async(NMClient * client, +nm_client_deactivate_connection_async(NMClient *client, NMActiveConnection *active, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -5591,16 +5605,16 @@ nm_client_get_connection_by_uuid(NMClient *client, const char *uuid) /*****************************************************************************/ static void -_add_connection_cb(GObject * source, +_add_connection_cb(GObject *source, GAsyncResult *result, gboolean with_extra_arg, gpointer user_data) { gs_unref_variant GVariant *ret = NULL; - gs_unref_object GTask *task = user_data; + gs_unref_object GTask *task = user_data; gs_unref_variant GVariant *v_result = NULL; - const char * v_path; - GError * error = NULL; + const char *v_path; + GError *error = NULL; ret = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), result, &error); if (!ret) { @@ -5636,13 +5650,13 @@ _add_connection_cb_with_extra_result(GObject *object, GAsyncResult *result, gpoi } static void -_add_connection_call(NMClient * self, +_add_connection_call(NMClient *self, gpointer source_tag, gboolean ignore_out_result, - GVariant * settings, + GVariant *settings, NMSettingsAddConnection2Flags flags, - GVariant * args, - GCancellable * cancellable, + GVariant *args, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -5736,10 +5750,10 @@ _add_connection_call(NMClient * self, * completion and/or normalization of connection properties. **/ void -nm_client_add_connection_async(NMClient * client, - NMConnection * connection, +nm_client_add_connection_async(NMClient *client, + NMConnection *connection, gboolean save_to_disk, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -5798,12 +5812,12 @@ nm_client_add_connection_finish(NMClient *client, GAsyncResult *result, GError * * Since: 1.20 **/ void -nm_client_add_connection2(NMClient * client, - GVariant * settings, +nm_client_add_connection2(NMClient *client, + GVariant *settings, NMSettingsAddConnection2Flags flags, - GVariant * args, + GVariant *args, gboolean ignore_out_result, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -5834,10 +5848,10 @@ nm_client_add_connection2(NMClient * client, * Since: 1.20 */ NMRemoteConnection * -nm_client_add_connection2_finish(NMClient * client, +nm_client_add_connection2_finish(NMClient *client, GAsyncResult *result, - GVariant ** out_result, - GError ** error) + GVariant **out_result, + GError **error) { return NM_REMOTE_CONNECTION( _request_wait_finish(client, result, nm_client_add_connection2, out_result, error)); @@ -5880,11 +5894,11 @@ nm_client_add_connection2_finish(NMClient * client, * Deprecated: 1.22: Use nm_client_load_connections_async() or GDBusConnection. **/ gboolean -nm_client_load_connections(NMClient * client, - char ** filenames, - char *** failures, +nm_client_load_connections(NMClient *client, + char **filenames, + char ***failures, GCancellable *cancellable, - GError ** error) + GError **error) { gs_unref_variant GVariant *ret = NULL; @@ -5926,9 +5940,9 @@ nm_client_load_connections(NMClient * client, * See nm_client_load_connections() for more details. **/ void -nm_client_load_connections_async(NMClient * client, - char ** filenames, - GCancellable * cancellable, +nm_client_load_connections_async(NMClient *client, + char **filenames, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -5967,10 +5981,10 @@ nm_client_load_connections_async(NMClient * client, * Note that even in the success case, you might have individual @failures. **/ gboolean -nm_client_load_connections_finish(NMClient * client, - char *** failures, +nm_client_load_connections_finish(NMClient *client, + char ***failures, GAsyncResult *result, - GError ** error) + GError **error) { gs_unref_variant GVariant *ret = NULL; @@ -6040,8 +6054,8 @@ nm_client_reload_connections(NMClient *client, GCancellable *cancellable, GError * in-memory state matches the on-disk state. **/ void -nm_client_reload_connections_async(NMClient * client, - GCancellable * cancellable, +nm_client_reload_connections_async(NMClient *client, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -6152,36 +6166,36 @@ nm_client_get_dns_configuration(NMClient *client) } static NMLDBusNotifyUpdatePropFlags -_notify_update_prop_dns_manager_configuration(NMClient * self, - NMLDBusObject * dbobj, +_notify_update_prop_dns_manager_configuration(NMClient *self, + NMLDBusObject *dbobj, const NMLDBusMetaIface *meta_iface, guint dbus_property_idx, - GVariant * value) + GVariant *value) { - NMClientPrivate * priv = NM_CLIENT_GET_PRIVATE(self); + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); gs_unref_ptrarray GPtrArray *configuration_old = NULL; gs_unref_ptrarray GPtrArray *configuration_new = NULL; nm_assert(G_OBJECT(self) == dbobj->nmobj); if (value) { - GVariant * entry_var_tmp; + GVariant *entry_var_tmp; GVariantIter iter; - GPtrArray * array; + GPtrArray *array; configuration_new = g_ptr_array_new_with_free_func((GDestroyNotify) nm_dns_entry_unref); g_variant_iter_init(&iter, value); while (g_variant_iter_next(&iter, "@a{sv}", &entry_var_tmp)) { - gs_unref_variant GVariant *entry_var = entry_var_tmp; + gs_unref_variant GVariant *entry_var = entry_var_tmp; nm_auto_free_variant_iter GVariantIter *iterp_nameservers = NULL; nm_auto_free_variant_iter GVariantIter *iterp_domains = NULL; - gs_free char ** nameservers = NULL; - gs_free char ** domains = NULL; + gs_free char **nameservers = NULL; + gs_free char **domains = NULL; gboolean vpn = FALSE; - NMDnsEntry * entry; - char * interface = NULL; - char * str; + NMDnsEntry *entry; + char *interface = NULL; + char *str; gint32 priority = 0; if (!g_variant_lookup(entry_var, "nameservers", "as", &iterp_nameservers) @@ -6256,11 +6270,11 @@ nm_client_get_capabilities(NMClient *client, gsize *length) } static NMLDBusNotifyUpdatePropFlags -_notify_update_prop_nm_capabilities(NMClient * self, - NMLDBusObject * dbobj, +_notify_update_prop_nm_capabilities(NMClient *self, + NMLDBusObject *dbobj, const NMLDBusMetaIface *meta_iface, guint dbus_property_idx, - GVariant * value) + GVariant *value) { NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); @@ -6310,10 +6324,10 @@ nm_client_get_checkpoints(NMClient *client) static void checkpoint_create_cb(GObject *object, GAsyncResult *result, gpointer user_data) { - gs_unref_object GTask *task = user_data; - gs_unref_variant GVariant *ret = NULL; - const char * v_checkpoint_path; - GError * error = NULL; + gs_unref_object GTask *task = user_data; + gs_unref_variant GVariant *ret = NULL; + const char *v_checkpoint_path; + GError *error = NULL; ret = g_dbus_connection_call_finish(G_DBUS_CONNECTION(object), result, &error); if (!ret) { @@ -6351,11 +6365,11 @@ checkpoint_create_cb(GObject *object, GAsyncResult *result, gpointer user_data) * Since: 1.12 **/ void -nm_client_checkpoint_create(NMClient * client, - const GPtrArray * devices, +nm_client_checkpoint_create(NMClient *client, + const GPtrArray *devices, guint32 rollback_timeout, NMCheckpointCreateFlags flags, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -6421,9 +6435,9 @@ nm_client_checkpoint_create_finish(NMClient *client, GAsyncResult *result, GErro * Since: 1.12 **/ void -nm_client_checkpoint_destroy(NMClient * client, - const char * checkpoint_path, - GCancellable * cancellable, +nm_client_checkpoint_destroy(NMClient *client, + const char *checkpoint_path, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -6481,9 +6495,9 @@ nm_client_checkpoint_destroy_finish(NMClient *client, GAsyncResult *result, GErr * Since: 1.12 **/ void -nm_client_checkpoint_rollback(NMClient * client, - const char * checkpoint_path, - GCancellable * cancellable, +nm_client_checkpoint_rollback(NMClient *client, + const char *checkpoint_path, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -6526,8 +6540,8 @@ nm_client_checkpoint_rollback_finish(NMClient *client, GAsyncResult *result, GEr gs_unref_variant GVariant *ret = NULL; gs_unref_variant GVariant *v_result = NULL; GVariantIter iter; - GHashTable * hash; - const char * path; + GHashTable *hash; + const char *path; guint32 r; g_return_val_if_fail(NM_IS_CLIENT(client), NULL); @@ -6564,10 +6578,10 @@ nm_client_checkpoint_rollback_finish(NMClient *client, GAsyncResult *result, GEr * Since: 1.12 **/ void -nm_client_checkpoint_adjust_rollback_timeout(NMClient * client, - const char * checkpoint_path, +nm_client_checkpoint_adjust_rollback_timeout(NMClient *client, + const char *checkpoint_path, guint32 add_timeout, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -6603,9 +6617,9 @@ nm_client_checkpoint_adjust_rollback_timeout(NMClient * client, * Since: 1.12 **/ gboolean -nm_client_checkpoint_adjust_rollback_timeout_finish(NMClient * client, +nm_client_checkpoint_adjust_rollback_timeout_finish(NMClient *client, GAsyncResult *result, - GError ** error) + GError **error) { g_return_val_if_fail(NM_IS_CLIENT(client), FALSE); g_return_val_if_fail( @@ -6632,9 +6646,9 @@ nm_client_checkpoint_adjust_rollback_timeout_finish(NMClient * client, * Since: 1.22 **/ void -nm_client_reload(NMClient * client, +nm_client_reload(NMClient *client, NMManagerReloadFlags flags, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -6709,14 +6723,14 @@ nm_client_reload_finish(NMClient *client, GAsyncResult *result, GError **error) * Since: 1.24 **/ void -nm_client_dbus_call(NMClient * client, - const char * object_path, - const char * interface_name, - const char * method_name, - GVariant * parameters, +nm_client_dbus_call(NMClient *client, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, const GVariantType *reply_type, int timeout_msec, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -6782,13 +6796,13 @@ nm_client_dbus_call_finish(NMClient *client, GAsyncResult *result, GError **erro * Since: 1.24 **/ void -nm_client_dbus_set_property(NMClient * client, - const char * object_path, - const char * interface_name, - const char * property_name, - GVariant * value, +nm_client_dbus_set_property(NMClient *client, + const char *object_path, + const char *interface_name, + const char *property_name, + GVariant *value, int timeout_msec, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -6839,7 +6853,7 @@ nm_client_dbus_set_property_finish(NMClient *client, GAsyncResult *result, GErro static void _init_fetch_all(NMClient *self) { - NMClientPrivate * priv = NM_CLIENT_GET_PRIVATE(self); + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); nm_auto_pop_gmaincontext GMainContext *dbus_context = NULL; dbus_context = nm_g_main_context_push_thread_default_if_necessary(priv->dbus_context); @@ -6936,8 +6950,8 @@ static void _init_release_all(NMClient *self) { NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); - CList ** dbus_objects_lst_heads; - NMLDBusObject * dbobj; + CList **dbus_objects_lst_heads; + NMLDBusObject *dbobj; int i; gboolean permissions_state_changed = FALSE; @@ -7008,10 +7022,10 @@ _init_release_all(NMClient *self) static void name_owner_changed(NMClient *self, const char *name_owner) { - NMClientPrivate * priv = NM_CLIENT_GET_PRIVATE(self); - gboolean changed; - gs_free char * old_name_owner_free = NULL; - const char * old_name_owner; + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); + gboolean changed; + gs_free char *old_name_owner_free = NULL; + const char *old_name_owner; nm_auto_pop_gmaincontext GMainContext *dbus_context = NULL; name_owner = nm_str_not_empty(name_owner); @@ -7087,16 +7101,16 @@ name_owner_changed(NMClient *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) { - NMClient * self = user_data; + NMClient *self = user_data; NMClientPrivate *priv; - const char * new_owner; + const char *new_owner; if (!g_variant_is_of_type(parameters, G_VARIANT_TYPE("(sss)"))) return; @@ -7113,12 +7127,12 @@ name_owner_changed_cb(GDBusConnection *connection, static void name_owner_get_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - NMClient * self; - NMClientPrivate *priv; - gs_unref_object GObject *context_busy_watcher = NULL; - gs_unref_variant GVariant *ret = NULL; - gs_free_error GError *error = NULL; - const char * name_owner = NULL; + NMClient *self; + NMClientPrivate *priv; + gs_unref_object GObject *context_busy_watcher = NULL; + gs_unref_variant GVariant *ret = NULL; + gs_free_error GError *error = NULL; + const char *name_owner = NULL; nm_utils_user_data_unpack(user_data, &self, &context_busy_watcher); @@ -7164,8 +7178,8 @@ name_owner_get_call(NMClient *self) static inline gboolean _nml_cleanup_context_busy_watcher_on_idle_cb(gpointer user_data) { - nm_auto_unref_gmaincontext GMainContext *context = NULL; - gs_unref_object GObject *context_busy_watcher = NULL; + nm_auto_unref_gmaincontext GMainContext *context = NULL; + gs_unref_object GObject *context_busy_watcher = NULL; nm_utils_user_data_unpack(user_data, &context, &context_busy_watcher); @@ -7178,7 +7192,7 @@ void nml_cleanup_context_busy_watcher_on_idle(GObject *context_busy_watcher_take, GMainContext *context) { gs_unref_object GObject *context_busy_watcher = g_steal_pointer(&context_busy_watcher_take); - GSource * cleanup_source; + GSource *cleanup_source; nm_assert(G_IS_OBJECT(context_busy_watcher)); nm_assert(context); @@ -7292,9 +7306,9 @@ _init_start_check_complete(NMClient *self) static void _init_start_cancelled_cb(GCancellable *cancellable, gpointer user_data) { - NMClient * self = user_data; + NMClient *self = user_data; NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); - GError * error; + GError *error; nm_assert(NM_IS_CLIENT(self)); nm_assert(priv->init_data); @@ -7315,7 +7329,7 @@ static gboolean _init_start_cancel_on_idle_cb(gpointer user_data) { NMClient *self = user_data; - GError * error; + GError *error; nm_utils_error_set_cancelled(&error, FALSE, NULL); _init_start_complete(self, error); @@ -7358,10 +7372,10 @@ _init_start_with_bus(NMClient *self) static void _init_start_bus_get_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - NMClient * self = user_data; + NMClient *self = user_data; NMClientPrivate *priv; GDBusConnection *dbus_connection; - GError * error = NULL; + GError *error = NULL; nm_assert(NM_IS_CLIENT(self)); @@ -7402,7 +7416,7 @@ _init_start(NMClient *self) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMClient * self = NM_CLIENT(object); + NMClient *self = NM_CLIENT(object); NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(object); switch (prop_id) { @@ -7487,7 +7501,7 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) case PROP_CAPABILITIES: { const guint32 *arr; - GArray * out; + GArray *out; gsize len; arr = nm_client_get_capabilities(self, &len); @@ -7536,7 +7550,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) { - NMClient * self = NM_CLIENT(object); + NMClient *self = NM_CLIENT(object); NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); gboolean b; guint v_uint; @@ -7618,11 +7632,11 @@ static gboolean init_sync(GInitable *initable, GCancellable *cancellable, GError **error) { gs_unref_object NMClient *self = NULL; - NMClientPrivate * priv; - GMainContext * dbus_context; - GError * local_error = NULL; - GMainLoop * main_loop; - GObject * parent_context_busy_watcher; + NMClientPrivate *priv; + GMainContext *dbus_context; + GError *local_error = NULL; + GMainLoop *main_loop; + GObject *parent_context_busy_watcher; g_return_val_if_fail(NM_IS_CLIENT(initable), FALSE); @@ -7702,16 +7716,16 @@ init_sync(GInitable *initable, GCancellable *cancellable, GError **error) /*****************************************************************************/ static void -init_async(GAsyncInitable * initable, +init_async(GAsyncInitable *initable, int io_priority, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { - NMClientPrivate * priv; - NMClient * self; + NMClientPrivate *priv; + NMClient *self; nm_auto_pop_gmaincontext GMainContext *context = NULL; - GTask * task; + GTask *task; g_return_if_fail(NM_IS_CLIENT(initable)); @@ -7863,7 +7877,7 @@ NMClient * nm_client_new_finish(GAsyncResult *result, GError **error) { gs_unref_object GObject *source_object = NULL; - GObject * object; + GObject *object; source_object = g_async_result_get_source_object(result); g_return_val_if_fail(source_object, NULL); @@ -7877,7 +7891,7 @@ nm_client_new_finish(GAsyncResult *result, GError **error) static void constructed(GObject *object) { - NMClient * self = NM_CLIENT(object); + NMClient *self = NM_CLIENT(object); NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); priv->main_context = g_main_context_ref_thread_default(); @@ -7890,7 +7904,7 @@ constructed(GObject *object) static void dispose(GObject *object) { - NMClient * self = NM_CLIENT(object); + NMClient *self = NM_CLIENT(object); NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self); nm_assert(!priv->init_data); diff --git a/src/libnm-client-impl/nm-dbus-helpers.c b/src/libnm-client-impl/nm-dbus-helpers.c index 3b5f9ff8..c413bf02 100644 --- a/src/libnm-client-impl/nm-dbus-helpers.c +++ b/src/libnm-client-impl/nm-dbus-helpers.c @@ -54,7 +54,7 @@ _nm_dbus_bind_properties(gpointer object, gpointer skeleton) static char * signal_name_from_method_name(const char *method_name) { - GString * signal_name; + GString *signal_name; const char *p; signal_name = g_string_new("handle"); @@ -68,8 +68,8 @@ signal_name_from_method_name(const char *method_name) } static void -_nm_dbus_method_meta_marshal(GClosure * closure, - GValue * return_value, +_nm_dbus_method_meta_marshal(GClosure *closure, + GValue *return_value, guint n_param_values, const GValue *param_values, gpointer invocation_hint, @@ -94,9 +94,9 @@ _nm_dbus_bind_methods(gpointer object, gpointer skeleton, ...) { va_list ap; const char *method_name; - char * signal_name; + char *signal_name; GCallback handler; - GClosure * closure; + GClosure *closure; va_start(ap, skeleton); while ((method_name = va_arg(ap, const char *)) && (handler = va_arg(ap, GCallback))) { diff --git a/src/libnm-client-impl/nm-device-6lowpan.c b/src/libnm-client-impl/nm-device-6lowpan.c index e03b4a00..39558f25 100644 --- a/src/libnm-client-impl/nm-device-6lowpan.c +++ b/src/libnm-client-impl/nm-device-6lowpan.c @@ -109,7 +109,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_lowpan = NML_DBUS_META_IFA static void nm_device_6lowpan_class_init(NMDevice6LowpanClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMObjectClass *nm_object_class = NM_OBJECT_CLASS(klass); object_class->get_property = get_property; diff --git a/src/libnm-client-impl/nm-device-adsl.c b/src/libnm-client-impl/nm-device-adsl.c index 65f87545..58366c8f 100644 --- a/src/libnm-client-impl/nm-device-adsl.c +++ b/src/libnm-client-impl/nm-device-adsl.c @@ -107,7 +107,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_adsl = NML_DBUS_META_IFACE static void nm_device_adsl_class_init(NMDeviceAdslClass *adsl_class) { - GObjectClass * object_class = G_OBJECT_CLASS(adsl_class); + GObjectClass *object_class = G_OBJECT_CLASS(adsl_class); NMDeviceClass *device_class = NM_DEVICE_CLASS(adsl_class); object_class->get_property = get_property; diff --git a/src/libnm-client-impl/nm-device-bond.c b/src/libnm-client-impl/nm-device-bond.c index add54639..e8b3e3eb 100644 --- a/src/libnm-client-impl/nm-device-bond.c +++ b/src/libnm-client-impl/nm-device-bond.c @@ -158,7 +158,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_bond = NML_DBUS_META_IFACE static void nm_device_bond_class_init(NMDeviceBondClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMObjectClass *nm_object_class = NM_OBJECT_CLASS(klass); NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); diff --git a/src/libnm-client-impl/nm-device-bridge.c b/src/libnm-client-impl/nm-device-bridge.c index fb0ad873..6d5d6f95 100644 --- a/src/libnm-client-impl/nm-device-bridge.c +++ b/src/libnm-client-impl/nm-device-bridge.c @@ -163,7 +163,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_bridge = NML_DBUS_META_IFA static void nm_device_bridge_class_init(NMDeviceBridgeClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMObjectClass *nm_object_class = NM_OBJECT_CLASS(klass); NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); diff --git a/src/libnm-client-impl/nm-device-bt.c b/src/libnm-client-impl/nm-device-bt.c index 074ada66..b006cec4 100644 --- a/src/libnm-client-impl/nm-device-bt.c +++ b/src/libnm-client-impl/nm-device-bt.c @@ -21,7 +21,7 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_NAME, PROP_BT_CAPABILITIES, ); typedef struct { - char * name; + char *name; guint32 bt_capabilities; } NMDeviceBtPrivate; @@ -96,7 +96,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); if (!s_bt) @@ -116,8 +116,8 @@ get_connection_bt_type(NMConnection *connection) static gboolean connection_compatible(NMDevice *device, NMConnection *connection, GError **error) { - NMSettingBluetooth * s_bt; - const char * hw_addr, *setting_addr; + NMSettingBluetooth *s_bt; + const char *hw_addr, *setting_addr; NMBluetoothCapabilities dev_caps; NMBluetoothCapabilities bt_type; @@ -235,7 +235,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_bluetooth = NML_DBUS_META_ static void nm_device_bt_class_init(NMDeviceBtClass *bt_class) { - GObjectClass * object_class = G_OBJECT_CLASS(bt_class); + GObjectClass *object_class = G_OBJECT_CLASS(bt_class); NMDeviceClass *device_class = NM_DEVICE_CLASS(bt_class); object_class->get_property = get_property; diff --git a/src/libnm-client-impl/nm-device-ethernet.c b/src/libnm-client-impl/nm-device-ethernet.c index b32decde..42b7262d 100644 --- a/src/libnm-client-impl/nm-device-ethernet.c +++ b/src/libnm-client-impl/nm-device-ethernet.c @@ -27,8 +27,8 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_PERM_HW_ADDRESS, PROP_S390_SUBCHANNELS, ); typedef struct _NMDeviceEthernetPrivate { - char ** s390_subchannels; - char * perm_hw_address; + char **s390_subchannels; + char *perm_hw_address; guint32 speed; bool carrier; } NMDeviceEthernetPrivate; @@ -132,7 +132,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; gsize num1, num2; gsize i, j; @@ -193,7 +193,7 @@ connection_compatible(NMDevice *device, NMConnection *connection, GError **error s_wired = nm_connection_get_setting_wired(connection); /* Wired setting optional for PPPoE */ if (s_wired) { - const char * perm_addr, *s_mac; + const char *perm_addr, *s_mac; gboolean try_mac = TRUE; const char *const *mac_blacklist; int i; @@ -292,7 +292,7 @@ finalize(GObject *object) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMDeviceEthernet * device = NM_DEVICE_ETHERNET(object); + NMDeviceEthernet *device = NM_DEVICE_ETHERNET(object); NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(device); switch (prop_id) { @@ -338,7 +338,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wired = NML_DBUS_META_IFAC static void nm_device_ethernet_class_init(NMDeviceEthernetClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); g_type_class_add_private(klass, sizeof(NMDeviceEthernetPrivate)); diff --git a/src/libnm-client-impl/nm-device-generic.c b/src/libnm-client-impl/nm-device-generic.c index 9dcc8c91..4a420003 100644 --- a/src/libnm-client-impl/nm-device-generic.c +++ b/src/libnm-client-impl/nm-device-generic.c @@ -147,7 +147,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_generic = NML_DBUS_META_IF static void nm_device_generic_class_init(NMDeviceGenericClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->get_property = get_property; diff --git a/src/libnm-client-impl/nm-device-infiniband.c b/src/libnm-client-impl/nm-device-infiniband.c index 7e4cc054..8bca721e 100644 --- a/src/libnm-client-impl/nm-device-infiniband.c +++ b/src/libnm-client-impl/nm-device-infiniband.c @@ -77,7 +77,7 @@ static gboolean connection_compatible(NMDevice *device, NMConnection *connection, GError **error) { NMSettingInfiniband *s_infiniband; - const char * hwaddr, *setting_hwaddr; + const char *hwaddr, *setting_hwaddr; if (!NM_DEVICE_CLASS(nm_device_infiniband_parent_class) ->connection_compatible(device, connection, error)) @@ -156,7 +156,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_infiniband = NML_DBUS_META static void nm_device_infiniband_class_init(NMDeviceInfinibandClass *ib_class) { - GObjectClass * object_class = G_OBJECT_CLASS(ib_class); + GObjectClass *object_class = G_OBJECT_CLASS(ib_class); NMDeviceClass *device_class = NM_DEVICE_CLASS(ib_class); object_class->get_property = get_property; diff --git a/src/libnm-client-impl/nm-device-ip-tunnel.c b/src/libnm-client-impl/nm-device-ip-tunnel.c index 14c72282..c34ad84b 100644 --- a/src/libnm-client-impl/nm-device-ip-tunnel.c +++ b/src/libnm-client-impl/nm-device-ip-tunnel.c @@ -30,10 +30,10 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_MODE, typedef struct { NMLDBusPropertyO parent; - char * local; - char * remote; - char * input_key; - char * output_key; + char *local; + char *remote; + char *input_key; + char *output_key; guint32 mode; guint32 flow_label; guint32 flags; @@ -383,7 +383,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_iptunnel = NML_DBUS_META_I static void nm_device_ip_tunnel_class_init(NMDeviceIPTunnelClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMObjectClass *nm_object_class = NM_OBJECT_CLASS(klass); NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); diff --git a/src/libnm-client-impl/nm-device-macsec.c b/src/libnm-client-impl/nm-device-macsec.c index faa5be7e..525d32d0 100644 --- a/src/libnm-client-impl/nm-device-macsec.c +++ b/src/libnm-client-impl/nm-device-macsec.c @@ -29,7 +29,7 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_PARENT, typedef struct { NMLDBusPropertyO parent; - char * validation; + char *validation; guint64 sci; guint64 cipher_suite; guint32 window; @@ -428,7 +428,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_macsec = NML_DBUS_META_IFA static void nm_device_macsec_class_init(NMDeviceMacsecClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMObjectClass *nm_object_class = NM_OBJECT_CLASS(klass); object_class->get_property = get_property; diff --git a/src/libnm-client-impl/nm-device-macvlan.c b/src/libnm-client-impl/nm-device-macvlan.c index ddb36bab..a8363c93 100644 --- a/src/libnm-client-impl/nm-device-macvlan.c +++ b/src/libnm-client-impl/nm-device-macvlan.c @@ -19,7 +19,7 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_PARENT, PROP_MODE, PROP_NO_PROMISC, PROP_ typedef struct { NMLDBusPropertyO parent; - char * mode; + char *mode; bool no_promisc; bool tap; } NMDeviceMacvlanPrivate; @@ -138,7 +138,7 @@ static gboolean connection_compatible(NMDevice *device, NMConnection *connection, GError **error) { NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE(device); - NMSettingMacvlan * s_macvlan; + NMSettingMacvlan *s_macvlan; if (!NM_DEVICE_CLASS(nm_device_macvlan_parent_class) ->connection_compatible(device, connection, error)) @@ -227,7 +227,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_macvlan = NML_DBUS_META_IF static void nm_device_macvlan_class_init(NMDeviceMacvlanClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMObjectClass *nm_object_class = NM_OBJECT_CLASS(klass); NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); diff --git a/src/libnm-client-impl/nm-device-modem.c b/src/libnm-client-impl/nm-device-modem.c index 57e09bc6..a1edfb04 100644 --- a/src/libnm-client-impl/nm-device-modem.c +++ b/src/libnm-client-impl/nm-device-modem.c @@ -23,9 +23,9 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_MODEM_CAPABILITIES, PROP_APN, ); typedef struct { - char * device_id; - char * operator_code; - char * apn; + char *device_id; + char *operator_code; + char *apn; guint32 modem_capabilities; guint32 current_capabilities; } NMDeviceModemPrivate; @@ -153,16 +153,18 @@ get_type_description(NMDevice *device) return NULL; } -#define MODEM_CAPS_3GPP(caps) \ - (caps & (NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS | NM_DEVICE_MODEM_CAPABILITY_LTE)) +#define MODEM_CAPS_3GPP(caps) \ + NM_FLAGS_ANY((caps), \ + (NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS | NM_DEVICE_MODEM_CAPABILITY_LTE \ + | NM_DEVICE_MODEM_CAPABILITY_5GNR)) -#define MODEM_CAPS_3GPP2(caps) (caps & (NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)) +#define MODEM_CAPS_3GPP2(caps) NM_FLAGS_ANY((caps), NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) static gboolean connection_compatible(NMDevice *device, NMConnection *connection, GError **error) { - NMSettingGsm * s_gsm; - NMSettingCdma * s_cdma; + NMSettingGsm *s_gsm; + NMSettingCdma *s_cdma; NMDeviceModemCapabilities current_caps; if (!NM_DEVICE_CLASS(nm_device_modem_parent_class) @@ -206,9 +208,9 @@ get_setting_type(NMDevice *device) NMDeviceModemCapabilities caps; caps = nm_device_modem_get_current_capabilities(NM_DEVICE_MODEM(device)); - if (caps & (NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS | NM_DEVICE_MODEM_CAPABILITY_LTE)) + if (MODEM_CAPS_3GPP(caps)) return NM_TYPE_SETTING_GSM; - else if (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) + else if (MODEM_CAPS_3GPP2(caps)) return NM_TYPE_SETTING_CDMA; else return G_TYPE_INVALID; @@ -282,7 +284,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_modem = NML_DBUS_META_IFAC static void nm_device_modem_class_init(NMDeviceModemClass *modem_class) { - GObjectClass * object_class = G_OBJECT_CLASS(modem_class); + GObjectClass *object_class = G_OBJECT_CLASS(modem_class); NMDeviceClass *device_class = NM_DEVICE_CLASS(modem_class); object_class->get_property = get_property; diff --git a/src/libnm-client-impl/nm-device-olpc-mesh.c b/src/libnm-client-impl/nm-device-olpc-mesh.c index 779990aa..26fceb3b 100644 --- a/src/libnm-client-impl/nm-device-olpc-mesh.c +++ b/src/libnm-client-impl/nm-device-olpc-mesh.c @@ -158,7 +158,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_olpcmesh = NML_DBUS_META_I static void nm_device_olpc_mesh_class_init(NMDeviceOlpcMeshClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMObjectClass *nm_object_class = NM_OBJECT_CLASS(klass); NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); diff --git a/src/libnm-client-impl/nm-device-ovs-bridge.c b/src/libnm-client-impl/nm-device-ovs-bridge.c index 465957c4..8c30fc3f 100644 --- a/src/libnm-client-impl/nm-device-ovs-bridge.c +++ b/src/libnm-client-impl/nm-device-ovs-bridge.c @@ -130,7 +130,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_ovsbridge = NML_DBUS_META_ static void nm_device_ovs_bridge_class_init(NMDeviceOvsBridgeClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->get_property = get_property; diff --git a/src/libnm-client-impl/nm-device-ovs-port.c b/src/libnm-client-impl/nm-device-ovs-port.c index 76ae7a58..9e20e5b8 100644 --- a/src/libnm-client-impl/nm-device-ovs-port.c +++ b/src/libnm-client-impl/nm-device-ovs-port.c @@ -130,7 +130,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_ovsport = NML_DBUS_META_IF static void nm_device_ovs_port_class_init(NMDeviceOvsPortClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); object_class->get_property = get_property; diff --git a/src/libnm-client-impl/nm-device-team.c b/src/libnm-client-impl/nm-device-team.c index 9f7fe768..0a42089a 100644 --- a/src/libnm-client-impl/nm-device-team.c +++ b/src/libnm-client-impl/nm-device-team.c @@ -192,7 +192,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_team = NML_DBUS_META_IFACE static void nm_device_team_class_init(NMDeviceTeamClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMObjectClass *nm_object_class = NM_OBJECT_CLASS(klass); NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); diff --git a/src/libnm-client-impl/nm-device-tun.c b/src/libnm-client-impl/nm-device-tun.c index 8b8ca0fe..353b4bdc 100644 --- a/src/libnm-client-impl/nm-device-tun.c +++ b/src/libnm-client-impl/nm-device-tun.c @@ -24,7 +24,7 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_MODE, PROP_MULTI_QUEUE, ); typedef struct { - char * mode; + char *mode; gint64 owner; gint64 group; bool no_pi; @@ -191,7 +191,7 @@ connection_compatible(NMDevice *device, NMConnection *connection, GError **error { NMDeviceTunPrivate *priv = NM_DEVICE_TUN_GET_PRIVATE(device); NMSettingTunMode mode; - NMSettingTun * s_tun; + NMSettingTun *s_tun; if (!NM_DEVICE_CLASS(nm_device_tun_parent_class) ->connection_compatible(device, connection, error)) @@ -294,7 +294,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_tun = NML_DBUS_META_IFACE_ static void nm_device_tun_class_init(NMDeviceTunClass *gre_class) { - GObjectClass * object_class = G_OBJECT_CLASS(gre_class); + GObjectClass *object_class = G_OBJECT_CLASS(gre_class); NMDeviceClass *device_class = NM_DEVICE_CLASS(gre_class); object_class->get_property = get_property; diff --git a/src/libnm-client-impl/nm-device-veth.c b/src/libnm-client-impl/nm-device-veth.c index f35f09b1..d9fc325b 100644 --- a/src/libnm-client-impl/nm-device-veth.c +++ b/src/libnm-client-impl/nm-device-veth.c @@ -95,7 +95,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_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); NMObjectClass *nm_object_class = NM_OBJECT_CLASS(klass); NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); diff --git a/src/libnm-client-impl/nm-device-vlan.c b/src/libnm-client-impl/nm-device-vlan.c index 4c2a435b..882fc171 100644 --- a/src/libnm-client-impl/nm-device-vlan.c +++ b/src/libnm-client-impl/nm-device-vlan.c @@ -105,10 +105,10 @@ nm_device_vlan_get_vlan_id(NMDeviceVlan *device) static gboolean connection_compatible(NMDevice *device, NMConnection *connection, GError **error) { - NMSettingVlan * s_vlan; + NMSettingVlan *s_vlan; NMSettingWired *s_wired; - const char * setting_hwaddr; - const char * hw_address; + const char *setting_hwaddr; + const char *hw_address; if (!NM_DEVICE_CLASS(nm_device_vlan_parent_class) ->connection_compatible(device, connection, error)) @@ -205,7 +205,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_vlan = NML_DBUS_META_IFACE static void nm_device_vlan_class_init(NMDeviceVlanClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMObjectClass *nm_object_class = NM_OBJECT_CLASS(klass); NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); diff --git a/src/libnm-client-impl/nm-device-vrf.c b/src/libnm-client-impl/nm-device-vrf.c index bbf37810..592785f9 100644 --- a/src/libnm-client-impl/nm-device-vrf.c +++ b/src/libnm-client-impl/nm-device-vrf.c @@ -115,7 +115,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_vrf = NML_DBUS_META_IFACE_ static void nm_device_vrf_class_init(NMDeviceVrfClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMObjectClass *nm_object_class = NM_OBJECT_CLASS(klass); NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); diff --git a/src/libnm-client-impl/nm-device-vxlan.c b/src/libnm-client-impl/nm-device-vxlan.c index 6fac3b71..d7bd9cbe 100644 --- a/src/libnm-client-impl/nm-device-vxlan.c +++ b/src/libnm-client-impl/nm-device-vxlan.c @@ -34,8 +34,8 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_CARRIER, typedef struct { NMLDBusPropertyO parent; - char * group; - char * local; + char *group; + char *local; guint32 id; guint32 limit; guint32 ageing; @@ -522,7 +522,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_vxlan = NML_DBUS_META_IFAC static void nm_device_vxlan_class_init(NMDeviceVxlanClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMObjectClass *nm_object_class = NM_OBJECT_CLASS(klass); NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); diff --git a/src/libnm-client-impl/nm-device-wifi-p2p.c b/src/libnm-client-impl/nm-device-wifi-p2p.c index 2daaf774..fb72f250 100644 --- a/src/libnm-client-impl/nm-device-wifi-p2p.c +++ b/src/libnm-client-impl/nm-device-wifi-p2p.c @@ -107,7 +107,7 @@ nm_device_wifi_p2p_get_peer_by_path(NMDeviceWifiP2P *device, const char *path) { const GPtrArray *peers; int i; - NMWifiP2PPeer * peer = NULL; + NMWifiP2PPeer *peer = NULL; g_return_val_if_fail(NM_IS_DEVICE_WIFI_P2P(device), NULL); g_return_val_if_fail(path != NULL, NULL); @@ -145,9 +145,9 @@ nm_device_wifi_p2p_get_peer_by_path(NMDeviceWifiP2P *device, const char *path) * Since: 1.16 **/ void -nm_device_wifi_p2p_start_find(NMDeviceWifiP2P * device, - GVariant * options, - GCancellable * cancellable, +nm_device_wifi_p2p_start_find(NMDeviceWifiP2P *device, + GVariant *options, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -207,8 +207,8 @@ nm_device_wifi_p2p_start_find_finish(NMDeviceWifiP2P *device, GAsyncResult *resu * Since: 1.16 **/ void -nm_device_wifi_p2p_stop_find(NMDeviceWifiP2P * device, - GCancellable * cancellable, +nm_device_wifi_p2p_stop_find(NMDeviceWifiP2P *device, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -286,8 +286,8 @@ get_type_description(NMDevice *device) static void _property_ao_notify_changed_peers_cb(NMLDBusPropertyAO *pr_ao, - NMClient * client, - NMObject * nmobj, + NMClient *client, + NMObject *nmobj, gboolean is_added /* or else removed */) { _nm_client_notify_event_queue_emit_obj_signal(client, @@ -342,7 +342,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wifip2p = NML_DBUS_META_IF static void nm_device_wifi_p2p_class_init(NMDeviceWifiP2PClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMObjectClass *nm_object_class = NM_OBJECT_CLASS(klass); NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); diff --git a/src/libnm-client-impl/nm-device-wifi.c b/src/libnm-client-impl/nm-device-wifi.c index cfbbea23..b062ea9e 100644 --- a/src/libnm-client-impl/nm-device-wifi.c +++ b/src/libnm-client-impl/nm-device-wifi.c @@ -33,7 +33,7 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_PERM_HW_ADDRESS, typedef struct { NMLDBusPropertyAO access_points; NMLDBusPropertyO active_access_point; - char * perm_hw_address; + char *perm_hw_address; gint64 last_scan; guint32 mode; guint32 bitrate; @@ -212,7 +212,7 @@ nm_device_wifi_get_access_point_by_path(NMDeviceWifi *device, const char *path) { const GPtrArray *aps; int i; - NMAccessPoint * ap = NULL; + NMAccessPoint *ap = NULL; g_return_val_if_fail(NM_IS_DEVICE_WIFI(device), NULL); g_return_val_if_fail(path != NULL, NULL); @@ -299,9 +299,9 @@ nm_device_wifi_request_scan(NMDeviceWifi *device, GCancellable *cancellable, GEr **/ gboolean nm_device_wifi_request_scan_options(NMDeviceWifi *device, - GVariant * options, + GVariant *options, GCancellable *cancellable, - GError ** error) + GError **error) { g_return_val_if_fail(NM_IS_DEVICE_WIFI(device), FALSE); g_return_val_if_fail(!options || g_variant_is_of_type(options, G_VARIANT_TYPE_VARDICT), FALSE); @@ -342,8 +342,8 @@ NM_BACKPORT_SYMBOL( * that for the scan to complete. **/ void -nm_device_wifi_request_scan_async(NMDeviceWifi * device, - GCancellable * cancellable, +nm_device_wifi_request_scan_async(NMDeviceWifi *device, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -371,9 +371,9 @@ nm_device_wifi_request_scan_async(NMDeviceWifi * device, * Since: 1.2 **/ void -nm_device_wifi_request_scan_options_async(NMDeviceWifi * device, - GVariant * options, - GCancellable * cancellable, +nm_device_wifi_request_scan_options_async(NMDeviceWifi *device, + GVariant *options, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -404,8 +404,8 @@ NM_BACKPORT_SYMBOL(libnm_1_0_6, void, nm_device_wifi_request_scan_options_async, (NMDeviceWifi * device, - GVariant * options, - GCancellable * cancellable, + GVariant *options, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data), (device, options, cancellable, callback, user_data)); @@ -453,11 +453,11 @@ has_proto(NMSettingWirelessSecurity *s_wsec, const char *proto) static gboolean connection_compatible(NMDevice *device, NMConnection *connection, GError **error) { - NMSettingWireless * s_wifi; + NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; - const char * hwaddr, *setting_hwaddr; + const char *hwaddr, *setting_hwaddr; NMDeviceWifiCapabilities wifi_caps; - const char * key_mgmt; + const char *key_mgmt; if (!NM_DEVICE_CLASS(nm_device_wifi_parent_class) ->connection_compatible(device, connection, error)) @@ -537,8 +537,8 @@ get_setting_type(NMDevice *device) static void _property_ao_notify_changed_access_points_cb(NMLDBusPropertyAO *pr_ao, - NMClient * client, - NMObject * nmobj, + NMClient *client, + NMObject *nmobj, gboolean is_added /* or else removed */) { _nm_client_notify_event_queue_emit_obj_signal(client, @@ -640,7 +640,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wireless = NML_DBUS_META_I static void nm_device_wifi_class_init(NMDeviceWifiClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMObjectClass *nm_object_class = NM_OBJECT_CLASS(klass); NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); diff --git a/src/libnm-client-impl/nm-device.c b/src/libnm-client-impl/nm-device.c index a680a05f..238e7c17 100644 --- a/src/libnm-client-impl/nm-device.c +++ b/src/libnm-client-impl/nm-device.c @@ -90,16 +90,16 @@ enum { typedef struct _NMDevicePrivate { NMLDBusPropertyO property_o[_PROPERTY_O_IDX_NUM]; NMLDBusPropertyAO property_ao[_PROPERTY_AO_IDX_NUM]; - GPtrArray * lldp_neighbors; - char * driver; - char * driver_version; - char * hw_address; - char * interface; - char * ip_interface; - char * firmware_version; - char * physical_port_id; - char * udi; - char * path; + GPtrArray *lldp_neighbors; + char *driver; + char *driver_version; + char *hw_address; + char *interface; + char *ip_interface; + char *firmware_version; + char *physical_port_id; + char *udi; + char *path; guint32 capabilities; guint32 device_type; guint32 ip4_connectivity; @@ -121,12 +121,12 @@ typedef struct _NMDevicePrivate { guint32 old_state; struct udev *udev; - char * type_description; - char * product; - char * vendor; - char * short_vendor; - char * description; - char * bus_name; + char *type_description; + char *product; + char *vendor; + char *short_vendor; + char *description; + char *bus_name; } NMDevicePrivate; @@ -168,7 +168,7 @@ static void _notify_event_state_changed(NMClient *client, NMClientNotifyEventWithPtr *notify_event) { gs_unref_object NMDevice *self = notify_event->user_data; - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); NML_NMCLIENT_LOG_T(client, "[%s] emit Device's StateChanged signal %u -> %u, reason: %u", @@ -186,13 +186,13 @@ _notify_event_state_changed(NMClient *client, NMClientNotifyEventWithPtr *notify } static NMLDBusNotifyUpdatePropFlags -_notify_update_prop_state_reason(NMClient * client, - NMLDBusObject * dbobj, +_notify_update_prop_state_reason(NMClient *client, + NMLDBusObject *dbobj, const NMLDBusMetaIface *meta_iface, guint dbus_property_idx, - GVariant * value) + GVariant *value) { - NMDevice * self = NM_DEVICE(dbobj->nmobj); + NMDevice *self = NM_DEVICE(dbobj->nmobj); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); guint32 new_state = NM_DEVICE_STATE_UNKNOWN; guint32 reason = NM_DEVICE_STATE_REASON_NONE; @@ -230,26 +230,26 @@ _notify_update_prop_state_reason(NMClient * client, } static NMLDBusNotifyUpdatePropFlags -_notify_update_prop_lldp_neighbors(NMClient * client, - NMLDBusObject * dbobj, +_notify_update_prop_lldp_neighbors(NMClient *client, + NMLDBusObject *dbobj, const NMLDBusMetaIface *meta_iface, guint dbus_property_idx, - GVariant * value) + GVariant *value) { - NMDevice * self = NM_DEVICE(dbobj->nmobj); - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - gs_unref_ptrarray GPtrArray *old = NULL; - gs_unref_ptrarray GPtrArray *new = NULL; - GVariantIter * attrs_iter; - GVariantIter iter; + NMDevice *self = NM_DEVICE(dbobj->nmobj); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + gs_unref_ptrarray GPtrArray *old = NULL; + gs_unref_ptrarray GPtrArray *new = NULL; + GVariantIter *attrs_iter; + GVariantIter iter; new = g_ptr_array_new_with_free_func((GDestroyNotify) nm_lldp_neighbor_unref); if (value) { g_variant_iter_init(&iter, value); while (g_variant_iter_next(&iter, "a{sv}", &attrs_iter)) { - GVariant * attr_variant; - const char * attr_name; + GVariant *attr_variant; + const char *attr_name; NMLldpNeighbor *neigh; /* Note that there is no public API to mutate a NMLldpNeighbor instance. @@ -477,7 +477,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 = NM_DEVICE(object); + NMDevice *self = NM_DEVICE(object); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); gboolean b; @@ -621,7 +621,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device = NML_DBUS_META_IFACE_INIT static void nm_device_class_init(NMDeviceClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMObjectClass *nm_object_class = NM_OBJECT_CLASS(klass); g_type_class_add_private(klass, sizeof(NMDevicePrivate)); @@ -1247,7 +1247,7 @@ const char * nm_device_get_type_description(NMDevice *device) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(device); - const char * desc, *typename; + const char *desc, *typename; /* BEWARE: this function should return the same value * as nm_device_get_type_description() in nm-core. */ @@ -1296,13 +1296,13 @@ nm_device_get_ports(NMDevice *device) } NMLDBusNotifyUpdatePropFlags -_nm_device_notify_update_prop_hw_address(NMClient * client, - NMLDBusObject * dbobj, +_nm_device_notify_update_prop_hw_address(NMClient *client, + NMLDBusObject *dbobj, const NMLDBusMetaIface *meta_iface, guint dbus_property_idx, - GVariant * value) + GVariant *value) { - NMDevice * self = NM_DEVICE(dbobj->nmobj); + NMDevice *self = NM_DEVICE(dbobj->nmobj); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); gboolean is_new = (meta_iface == &_nml_dbus_meta_iface_nm_device); gboolean changed = FALSE; @@ -1360,18 +1360,18 @@ nm_device_get_hw_address(NMDevice *device) } NMLDBusNotifyUpdatePropFlags -_nm_device_notify_update_prop_ports(NMClient * client, - NMLDBusObject * dbobj, +_nm_device_notify_update_prop_ports(NMClient *client, + NMLDBusObject *dbobj, const NMLDBusMetaIface *meta_iface, guint dbus_property_idx, - GVariant * value) + GVariant *value) { const NMLDBusMetaProperty *meta_property = &_nml_dbus_meta_iface_nm_device.dbus_properties[_NML_DEVICE_META_PROPERTY_INDEX_PORTS]; NMLDBusNotifyUpdatePropFlags notify_update_prop_flags; - NMDevice * self = NM_DEVICE(dbobj->nmobj); - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - NMDeviceClass * klass; + NMDevice *self = NM_DEVICE(dbobj->nmobj); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NMDeviceClass *klass; gboolean is_new = (meta_iface == &_nml_dbus_meta_iface_nm_device); nm_assert(nm_streq(meta_property->dbus_property_name, "Ports")); @@ -1851,10 +1851,10 @@ get_device_generic_type_name_with_iface(NMDevice *device) static const char * get_bus_name(NMDevice *device) { - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(device); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(device); struct udev_device *udevice; - const char * ifname; - const char * bus; + const char *ifname; + const char *bus; if (priv->bus_name) goto out; @@ -1893,17 +1893,17 @@ out: } static char * -_get_udev_property(NMDevice * device, +_get_udev_property(NMDevice *device, const char *enc_prop, /* ID_XXX_ENC */ const char *db_prop) /* ID_XXX_FROM_DATABASE */ { - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(device); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(device); struct udev_device *udev_device; struct udev_device *tmpdev; - const char * ifname; + const char *ifname; guint32 count = 0; - char * enc_value = NULL; - char * db_value = NULL; + char *enc_value = NULL; + char *db_value = NULL; if (!priv->udev) return NULL; @@ -1944,7 +1944,7 @@ _get_udev_property(NMDevice * device, } static char * -_get_udev_property_utf8safe(NMDevice * device, +_get_udev_property_utf8safe(NMDevice *device, const char *enc_prop, /* ID_XXX_ENC */ const char *db_prop) /* ID_XXX_FROM_DATABASE */ { @@ -2023,8 +2023,8 @@ static void ensure_description(NMDevice *device) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(device); - GParamSpec * name_prop; - gs_free char * short_product = NULL; + GParamSpec *name_prop; + gs_free char *short_product = NULL; priv->short_vendor = nm_str_realloc(nm_utils_fixup_vendor_string(nm_device_get_vendor(device))); @@ -2133,7 +2133,7 @@ find_duplicates(char **names, gboolean *duplicates, int num_devices) char ** nm_device_disambiguate_names(NMDevice **devices, int num_devices) { - char ** names; + char **names; gboolean *duplicates; int i; @@ -2162,7 +2162,7 @@ nm_device_disambiguate_names(NMDevice **devices, int num_devices) for (i = 0; i < num_devices; i++) { if (duplicates[i]) { const char *bus = get_bus_name(devices[i]); - char * name; + char *name; if (!bus) continue; @@ -2186,7 +2186,7 @@ nm_device_disambiguate_names(NMDevice **devices, int num_devices) for (i = 0; i < num_devices; i++) { if (duplicates[i]) { const char *vendor = get_short_vendor(devices[i]); - char * name; + char *name; if (!vendor) continue; @@ -2207,7 +2207,7 @@ nm_device_disambiguate_names(NMDevice **devices, int num_devices) for (i = 0; i < num_devices; i++) { if (duplicates[i] && NM_IS_DEVICE_BT(devices[i])) { const char *devname = nm_device_bt_get_name(NM_DEVICE_BT(devices[i])); - char * name; + char *name; if (!devname) continue; @@ -2382,12 +2382,12 @@ nm_device_is_software(NMDevice *device) * Deprecated: 1.22: Use nm_device_reapply_async() or GDBusConnection. **/ gboolean -nm_device_reapply(NMDevice * device, +nm_device_reapply(NMDevice *device, NMConnection *connection, guint64 version_id, guint32 flags, GCancellable *cancellable, - GError ** error) + GError **error) { GVariant *arg_connection = NULL; @@ -2434,11 +2434,11 @@ nm_device_reapply(NMDevice * device, * Since: 1.2 **/ void -nm_device_reapply_async(NMDevice * device, - NMConnection * connection, +nm_device_reapply_async(NMDevice *device, + NMConnection *connection, guint64 version_id, guint32 flags, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -2515,16 +2515,16 @@ nm_device_reapply_finish(NMDevice *device, GAsyncResult *result, GError **error) * Deprecated: 1.22: Use nm_device_get_applied_connection_async() or GDBusConnection. **/ NMConnection * -nm_device_get_applied_connection(NMDevice * device, +nm_device_get_applied_connection(NMDevice *device, guint32 flags, - guint64 * version_id, + guint64 *version_id, GCancellable *cancellable, - GError ** error) + GError **error) { gs_unref_variant GVariant *ret = NULL; gs_unref_variant GVariant *v_connection = NULL; guint64 v_version_id; - NMConnection * connection; + NMConnection *connection; g_return_val_if_fail(NM_IS_DEVICE(device), NULL); g_return_val_if_fail(!cancellable || G_IS_CANCELLABLE(cancellable), NULL); @@ -2569,9 +2569,9 @@ nm_device_get_applied_connection(NMDevice * device, * Since: 1.2 **/ void -nm_device_get_applied_connection_async(NMDevice * device, +nm_device_get_applied_connection_async(NMDevice *device, guint32 flags, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -2613,15 +2613,15 @@ nm_device_get_applied_connection_async(NMDevice * device, * Since: 1.2 **/ NMConnection * -nm_device_get_applied_connection_finish(NMDevice * device, +nm_device_get_applied_connection_finish(NMDevice *device, GAsyncResult *result, - guint64 * version_id, - GError ** error) + guint64 *version_id, + GError **error) { gs_unref_variant GVariant *ret = NULL; gs_unref_variant GVariant *v_connection = NULL; guint64 v_version_id; - NMConnection * connection; + NMConnection *connection; g_return_val_if_fail(NM_IS_DEVICE(device), NULL); g_return_val_if_fail(nm_g_task_is_valid(result, device, nm_device_get_applied_connection_async), @@ -2691,8 +2691,8 @@ nm_device_disconnect(NMDevice *device, GCancellable *cancellable, GError **error * manual network connection request. **/ void -nm_device_disconnect_async(NMDevice * device, - GCancellable * cancellable, +nm_device_disconnect_async(NMDevice *device, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -2778,8 +2778,8 @@ nm_device_delete(NMDevice *device, GCancellable *cancellable, GError **error) * be deleted. **/ void -nm_device_delete_async(NMDevice * device, - GCancellable * cancellable, +nm_device_delete_async(NMDevice *device, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -2848,7 +2848,7 @@ static gboolean connection_compatible(NMDevice *device, NMConnection *connection, GError **error) { const char *config_iface, *device_iface; - GError * local = NULL; + GError *local = NULL; if (!nm_connection_verify(connection, &local)) { g_set_error(error, @@ -3114,8 +3114,8 @@ nm_lldp_neighbor_get_attr_names(NMLldpNeighbor *neighbor) **/ gboolean nm_lldp_neighbor_get_attr_string_value(NMLldpNeighbor *neighbor, - const char * name, - const char ** out_value) + const char *name, + const char **out_value) { GVariant *variant; diff --git a/src/libnm-client-impl/nm-dhcp-config.c b/src/libnm-client-impl/nm-dhcp-config.c index c7f9a87a..1f908491 100644 --- a/src/libnm-client-impl/nm-dhcp-config.c +++ b/src/libnm-client-impl/nm-dhcp-config.c @@ -30,21 +30,21 @@ G_DEFINE_ABSTRACT_TYPE(NMDhcpConfig, nm_dhcp_config, NM_TYPE_OBJECT) /*****************************************************************************/ static NMLDBusNotifyUpdatePropFlags -_notify_update_prop_options(NMClient * client, - NMLDBusObject * dbobj, +_notify_update_prop_options(NMClient *client, + NMLDBusObject *dbobj, const NMLDBusMetaIface *meta_iface, guint dbus_property_idx, - GVariant * value) + GVariant *value) { - NMDhcpConfig * self = NM_DHCP_CONFIG(dbobj->nmobj); + NMDhcpConfig *self = NM_DHCP_CONFIG(dbobj->nmobj); NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE(self); g_hash_table_remove_all(priv->options); if (value) { GVariantIter iter; - const char * key; - GVariant * opt; + const char *key; + GVariant *opt; g_variant_iter_init(&iter, value); while (g_variant_iter_next(&iter, "{&sv}", &key, &opt)) { diff --git a/src/libnm-client-impl/nm-dns-manager.c b/src/libnm-client-impl/nm-dns-manager.c index f7c564ff..1fdcdd9b 100644 --- a/src/libnm-client-impl/nm-dns-manager.c +++ b/src/libnm-client-impl/nm-dns-manager.c @@ -23,9 +23,9 @@ G_DEFINE_BOXED_TYPE(NMDnsEntry, nm_dns_entry, nm_dns_entry_dup, nm_dns_entry_unr struct NMDnsEntry { guint refcount; - char * interface; - char ** nameservers; - char ** domains; + char *interface; + char **nameservers; + char **domains; int priority; gboolean vpn; }; @@ -38,7 +38,7 @@ struct NMDnsEntry { * Returns: (transfer full): the new #NMDnsEntry object, or %NULL on error **/ NMDnsEntry * -nm_dns_entry_new(const char * interface, +nm_dns_entry_new(const char *interface, const char *const *nameservers, const char *const *domains, int priority, diff --git a/src/libnm-client-impl/nm-dns-manager.h b/src/libnm-client-impl/nm-dns-manager.h index e6159e61..20a5286e 100644 --- a/src/libnm-client-impl/nm-dns-manager.h +++ b/src/libnm-client-impl/nm-dns-manager.h @@ -12,7 +12,7 @@ #include "nm-client.h" -NMDnsEntry *nm_dns_entry_new(const char * interface, +NMDnsEntry *nm_dns_entry_new(const char *interface, const char *const *nameservers, const char *const *domains, int priority, diff --git a/src/libnm-client-impl/nm-ip-config.c b/src/libnm-client-impl/nm-ip-config.c index 5666888c..2307ce2c 100644 --- a/src/libnm-client-impl/nm-ip-config.c +++ b/src/libnm-client-impl/nm-ip-config.c @@ -31,11 +31,11 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMIPConfig, typedef struct _NMIPConfigPrivate { GPtrArray *addresses; GPtrArray *routes; - char ** nameservers; - char ** domains; - char ** searches; - char ** wins_servers; - char * gateway; + char **nameservers; + char **domains; + char **searches; + char **wins_servers; + char *gateway; bool addresses_new_style : 1; bool routes_new_style : 1; @@ -51,14 +51,14 @@ G_DEFINE_ABSTRACT_TYPE(NMIPConfig, nm_ip_config, NM_TYPE_OBJECT) /*****************************************************************************/ static NMLDBusNotifyUpdatePropFlags -_notify_update_prop_addresses(NMClient * client, - NMLDBusObject * dbobj, +_notify_update_prop_addresses(NMClient *client, + NMLDBusObject *dbobj, const NMLDBusMetaIface *meta_iface, guint dbus_property_idx, - GVariant * value) + GVariant *value) { - NMIPConfig * self = NM_IP_CONFIG(dbobj->nmobj); - NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE(self); + NMIPConfig *self = NM_IP_CONFIG(dbobj->nmobj); + NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE(self); gs_unref_ptrarray GPtrArray *addresses_old = NULL; gs_unref_ptrarray GPtrArray *addresses_new = NULL; int addr_family = meta_iface == &_nml_dbus_meta_iface_nm_ip4config ? AF_INET : AF_INET6; @@ -91,14 +91,14 @@ _notify_update_prop_addresses(NMClient * client, } static NMLDBusNotifyUpdatePropFlags -_notify_update_prop_routes(NMClient * client, - NMLDBusObject * dbobj, +_notify_update_prop_routes(NMClient *client, + NMLDBusObject *dbobj, const NMLDBusMetaIface *meta_iface, guint dbus_property_idx, - GVariant * value) + GVariant *value) { - NMIPConfig * self = NM_IP_CONFIG(dbobj->nmobj); - NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE(self); + NMIPConfig *self = NM_IP_CONFIG(dbobj->nmobj); + NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE(self); gs_unref_ptrarray GPtrArray *routes_old = NULL; gs_unref_ptrarray GPtrArray *routes_new = NULL; int addr_family = meta_iface == &_nml_dbus_meta_iface_nm_ip4config ? AF_INET : AF_INET6; @@ -131,13 +131,13 @@ _notify_update_prop_routes(NMClient * client, } static NMLDBusNotifyUpdatePropFlags -_notify_update_prop_nameservers(NMClient * client, - NMLDBusObject * dbobj, +_notify_update_prop_nameservers(NMClient *client, + NMLDBusObject *dbobj, const NMLDBusMetaIface *meta_iface, guint dbus_property_idx, - GVariant * value) + GVariant *value) { - NMIPConfig * self = NM_IP_CONFIG(dbobj->nmobj); + NMIPConfig *self = NM_IP_CONFIG(dbobj->nmobj); NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE(self); gs_strfreev char **nameservers_new = NULL; gboolean new_style = TRUE; @@ -160,14 +160,14 @@ _notify_update_prop_nameservers(NMClient * client, else if (!new_style) nameservers_new = nm_utils_ip4_dns_from_variant(value); else { - GVariantIter iter; - GVariantIter * iter_v; + GVariantIter iter; + GVariantIter *iter_v; gs_unref_ptrarray GPtrArray *arr = NULL; g_variant_iter_init(&iter, value); while (g_variant_iter_next(&iter, "a{sv}", &iter_v)) { const char *key; - GVariant * val; + GVariant *val; while (g_variant_iter_next(iter_v, "{&sv}", &key, &val)) { if (nm_streq(key, "address")) { @@ -203,13 +203,13 @@ next: } static NMLDBusNotifyUpdatePropFlags -_notify_update_prop_wins_servers(NMClient * client, - NMLDBusObject * dbobj, +_notify_update_prop_wins_servers(NMClient *client, + NMLDBusObject *dbobj, const NMLDBusMetaIface *meta_iface, guint dbus_property_idx, - GVariant * value) + GVariant *value) { - NMIPConfig * self = NM_IP_CONFIG(dbobj->nmobj); + NMIPConfig *self = NM_IP_CONFIG(dbobj->nmobj); NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE(self); gs_strfreev char **wins_servers_new = NULL; gboolean new_style; diff --git a/src/libnm-client-impl/nm-libnm-utils.c b/src/libnm-client-impl/nm-libnm-utils.c index 4543eaa1..d3d429eb 100644 --- a/src/libnm-client-impl/nm-libnm-utils.c +++ b/src/libnm-client-impl/nm-libnm-utils.c @@ -42,9 +42,9 @@ void _nml_dbus_log(NMLDBusLogLevel level, gboolean use_stdout, const char *fmt, ...) { NMLDBusLogLevel configured_log_level; - gs_free char * msg = NULL; + gs_free char *msg = NULL; va_list args; - const char * prefix = ""; + const char *prefix = ""; gint64 ts; pid_t pid; @@ -116,7 +116,7 @@ char * nm_utils_wincaps_to_dash(const char *caps) { const char *p; - GString * str; + GString *str; str = g_string_new(NULL); p = caps; @@ -136,14 +136,14 @@ nm_utils_wincaps_to_dash(const char *caps) /*****************************************************************************/ static char * -_fixup_string(const char * desc, +_fixup_string(const char *desc, const char *const *ignored_phrases, const char *const *ignored_words, gboolean square_brackets_sensible) { - char * desc_full; + char *desc_full; gboolean in_paren = FALSE; - char * p, *q; + char *p, *q; int i; if (!desc || !desc[0]) @@ -727,7 +727,7 @@ static int _strcmp_common_prefix(gconstpointer a, gconstpointer b, gpointer user_data) { const NMLDBusMetaIface *iface = a; - const char * dbus_iface_name = b; + const char *dbus_iface_name = b; nm_assert(g_str_has_prefix(iface->dbus_iface_name, COMMON_PREFIX)); @@ -765,8 +765,8 @@ nml_dbus_meta_iface_get(const char *dbus_iface_name) const NMLDBusMetaProperty * nml_dbus_meta_property_get(const NMLDBusMetaIface *meta_iface, - const char * dbus_property_name, - guint * out_idx) + const char *dbus_property_name, + guint *out_idx) { gssize idx; @@ -788,7 +788,7 @@ nml_dbus_meta_property_get(const NMLDBusMetaIface *meta_iface, } void -_nml_dbus_meta_class_init_with_properties_impl(GObjectClass * object_class, +_nml_dbus_meta_class_init_with_properties_impl(GObjectClass *object_class, const NMLDBusMetaIface *const *meta_ifaces) { int i_iface; @@ -799,7 +799,7 @@ _nml_dbus_meta_class_init_with_properties_impl(GObjectClass * ob for (i_iface = 0; meta_ifaces[i_iface]; i_iface++) { const NMLDBusMetaIface *meta_iface = meta_ifaces[i_iface]; - guint8 * reverse_idx; + guint8 *reverse_idx; guint8 i; nm_assert(g_type_is_a(meta_iface->get_type_fcn(), G_OBJECT_CLASS_TYPE(object_class))); diff --git a/src/libnm-client-impl/nm-libnm-utils.h b/src/libnm-client-impl/nm-libnm-utils.h index 75e87064..db5f31ea 100644 --- a/src/libnm-client-impl/nm-libnm-utils.h +++ b/src/libnm-client-impl/nm-libnm-utils.h @@ -179,13 +179,13 @@ GQuark nm_context_busy_watcher_quark(void); void nm_context_busy_watcher_integrate_source(GMainContext *outer_context, GMainContext *inner_context, - GObject * context_busy_watcher); + GObject *context_busy_watcher); /*****************************************************************************/ typedef struct { GCancellable *cancellable; - GSource * cancel_on_idle_source; + GSource *cancel_on_idle_source; gulong cancelled_id; union { struct { @@ -193,7 +193,7 @@ typedef struct { } async; struct { GMainLoop *main_loop; - GError ** error_location; + GError **error_location; } sync; } data; bool is_sync : 1; @@ -206,7 +206,7 @@ NMLInitData *nml_init_data_new_async(GCancellable *cancellable, GTask *task_take void nml_init_data_return(NMLInitData *init_data, GError *error_take); -void nml_cleanup_context_busy_watcher_on_idle(GObject * context_busy_watcher_take, +void nml_cleanup_context_busy_watcher_on_idle(GObject *context_busy_watcher_take, GMainContext *context); /*****************************************************************************/ @@ -244,9 +244,9 @@ typedef struct { } NMLDBusPropertVTableO; struct _NMLDBusPropertyO { - NMLDBusObject * owner_dbobj; - NMLDBusObjWatcher * obj_watcher; - GObject * nmobj; + NMLDBusObject *owner_dbobj; + NMLDBusObjWatcher *obj_watcher; + GObject *nmobj; const NMLDBusMetaIface *meta_iface; guint dbus_property_idx; bool is_ready : 1; @@ -272,8 +272,8 @@ typedef struct { GType (*get_o_type_fcn)(void); void (*notify_changed_ao)(NMLDBusPropertyAO *pr_ao, - NMClient * self, - NMObject * nmobj, + NMClient *self, + NMObject *nmobj, gboolean is_added /* or else removed */); gboolean (*check_nmobj_visible_fcn)(GObject *nmobj); @@ -289,10 +289,10 @@ struct _NMLDBusPropertyAOData; struct _NMLDBusPropertyAO { CList data_lst_head; - GHashTable * hash; - NMLDBusObject * owner_dbobj; - const NMLDBusMetaIface * meta_iface; - GPtrArray * arr; + GHashTable *hash; + NMLDBusObject *owner_dbobj; + const NMLDBusMetaIface *meta_iface; + GPtrArray *arr; struct _NMLDBusPropertyAOData *changed_head; guint dbus_property_idx; guint n_not_ready; @@ -316,34 +316,34 @@ typedef enum { NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NOTIFY = 0x1, } NMLDBusNotifyUpdatePropFlags; -NMLDBusNotifyUpdatePropFlags _nml_dbus_notify_update_prop_ignore(NMClient * client, - NMLDBusObject * dbobj, +NMLDBusNotifyUpdatePropFlags _nml_dbus_notify_update_prop_ignore(NMClient *client, + NMLDBusObject *dbobj, const NMLDBusMetaIface *meta_iface, guint dbus_property_idx, GVariant *value); -NMLDBusNotifyUpdatePropFlags _nml_dbus_notify_update_prop_o(NMClient * client, - NMLDBusObject * dbobj, +NMLDBusNotifyUpdatePropFlags _nml_dbus_notify_update_prop_o(NMClient *client, + NMLDBusObject *dbobj, const NMLDBusMetaIface *meta_iface, guint dbus_property_idx, GVariant *value); -NMLDBusNotifyUpdatePropFlags nml_dbus_property_ao_notify(NMClient * self, - NMLDBusPropertyAO * pr_ao, - NMLDBusObject * dbobj, +NMLDBusNotifyUpdatePropFlags nml_dbus_property_ao_notify(NMClient *self, + NMLDBusPropertyAO *pr_ao, + NMLDBusObject *dbobj, const NMLDBusMetaIface *meta_iface, guint dbus_property_idx, - GVariant * value); + GVariant *value); typedef struct { - const char * dbus_property_name; + const char *dbus_property_name; const GVariantType *dbus_type; - NMLDBusNotifyUpdatePropFlags (*notify_update_prop)(NMClient * client, - NMLDBusObject * dbobj, + NMLDBusNotifyUpdatePropFlags (*notify_update_prop)(NMClient *client, + NMLDBusObject *dbobj, const NMLDBusMetaIface *meta_iface, guint dbus_property_idx, - GVariant * value); + GVariant *value); guint16 prop_struct_offset; @@ -352,7 +352,7 @@ typedef struct { bool obj_property_no_reverse_idx : 1; union { - const NMLDBusPropertVTableO * property_vtable_o; + const NMLDBusPropertVTableO *property_vtable_o; const NMLDBusPropertVTableAO *property_vtable_ao; } extra; @@ -475,9 +475,9 @@ struct _NMLDBusMetaIface { * assert (meta_iface->dbus_properties[d_idx].obj_properties_idx == o_idx) * if (and only if) two properties correspond. */ - const GParamSpec *const * obj_properties; + const GParamSpec *const *obj_properties; const NMLDBusMetaProperty *dbus_properties; - const guint8 * obj_properties_reverse_idx; + const guint8 *obj_properties_reverse_idx; guint8 n_dbus_properties; guint8 n_obj_properties; @@ -610,10 +610,10 @@ extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_wifip2ppeer; const NMLDBusMetaIface *nml_dbus_meta_iface_get(const char *dbus_iface_name); const NMLDBusMetaProperty *nml_dbus_meta_property_get(const NMLDBusMetaIface *meta_iface, - const char * dbus_property_name, - guint * out_idx); + const char *dbus_property_name, + guint *out_idx); -void _nml_dbus_meta_class_init_with_properties_impl(GObjectClass * object_class, +void _nml_dbus_meta_class_init_with_properties_impl(GObjectClass *object_class, const NMLDBusMetaIface *const *meta_iface); #define _nml_dbus_meta_class_init_with_properties(object_class, ...) \ _nml_dbus_meta_class_init_with_properties_impl( \ @@ -682,8 +682,8 @@ void nml_dbus_object_unref(NMLDBusObject *dbobj); NM_AUTO_DEFINE_FCN0(NMLDBusObject *, _nm_auto_unref_nml_dbusobj, nml_dbus_object_unref); #define nm_auto_unref_nml_dbusobj nm_auto(_nm_auto_unref_nml_dbusobj) -gpointer nml_dbus_object_get_property_location(NMLDBusObject * dbobj, - const NMLDBusMetaIface * meta_iface, +gpointer nml_dbus_object_get_property_location(NMLDBusObject *dbobj, + const NMLDBusMetaIface *meta_iface, const NMLDBusMetaProperty *meta_property); /*****************************************************************************/ @@ -713,7 +713,7 @@ struct _NMObject { typedef struct _NMObjectClassFieldInfo { const struct _NMObjectClassFieldInfo *parent; - NMObjectClass * klass; + NMObjectClass *klass; guint16 offset; guint16 num; } _NMObjectClassFieldInfo; @@ -926,14 +926,14 @@ struct _NMClientNotifyEvent { int priority; }; -gpointer _nm_client_notify_event_queue(NMClient * self, +gpointer _nm_client_notify_event_queue(NMClient *self, int priority, NMClientNotifyEventCb callback, gsize event_size); typedef struct _NMClientNotifyEventWithPtr NMClientNotifyEventWithPtr; -typedef void (*NMClientNotifyEventWithPtrCb)(NMClient * self, +typedef void (*NMClientNotifyEventWithPtrCb)(NMClient *self, NMClientNotifyEventWithPtr *notify_event); struct _NMClientNotifyEventWithPtr { @@ -942,13 +942,13 @@ struct _NMClientNotifyEventWithPtr { }; NMClientNotifyEventWithPtr * -_nm_client_notify_event_queue_with_ptr(NMClient * self, +_nm_client_notify_event_queue_with_ptr(NMClient *self, int priority, NMClientNotifyEventWithPtrCb callback, gpointer user_data); void _nm_client_notify_event_queue_emit_obj_signal(NMClient *self, - GObject * source, + GObject *source, NMObject *nmobj, gboolean is_added /* or else removed */, int prio_offset, @@ -959,57 +959,57 @@ void _nm_client_notify_event_queue_emit_obj_signal(NMClient *self, GError *_nm_client_new_error_nm_not_running(void); GError *_nm_client_new_error_nm_not_cached(void); -void _nm_client_dbus_call_simple(NMClient * self, - GCancellable * cancellable, - const char * object_path, - const char * interface_name, - const char * method_name, - GVariant * parameters, +void _nm_client_dbus_call_simple(NMClient *self, + GCancellable *cancellable, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, const GVariantType *reply_type, GDBusCallFlags flags, int timeout_msec, GAsyncReadyCallback callback, gpointer user_data); -void _nm_client_dbus_call(NMClient * self, +void _nm_client_dbus_call(NMClient *self, gpointer source_obj, gpointer source_tag, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback user_callback, gpointer user_callback_data, - const char * object_path, - const char * interface_name, - const char * method_name, - GVariant * parameters, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, const GVariantType *reply_type, GDBusCallFlags flags, int timeout_msec, GAsyncReadyCallback internal_callback); -GVariant *_nm_client_dbus_call_sync(NMClient * self, - GCancellable * cancellable, - const char * object_path, - const char * interface_name, - const char * method_name, - GVariant * parameters, +GVariant *_nm_client_dbus_call_sync(NMClient *self, + GCancellable *cancellable, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, const GVariantType *reply_type, GDBusCallFlags flags, int timeout_msec, gboolean strip_dbus_error, - GError ** error); - -gboolean _nm_client_dbus_call_sync_void(NMClient * self, - GCancellable * cancellable, - const char * object_path, - const char * interface_name, - const char * method_name, - GVariant * parameters, + GError **error); + +gboolean _nm_client_dbus_call_sync_void(NMClient *self, + GCancellable *cancellable, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, GDBusCallFlags flags, int timeout_msec, gboolean strip_dbus_error, - GError ** error); + GError **error); -void _nm_client_set_property_sync_legacy(NMClient * self, +void _nm_client_set_property_sync_legacy(NMClient *self, const char *object_path, const char *interface, const char *prop_name, @@ -1034,14 +1034,14 @@ void _nm_vpn_connection_state_changed_commit(NMVpnConnection *self, guint32 stat /*****************************************************************************/ NMLDBusNotifyUpdatePropFlags -_nm_device_notify_update_prop_hw_address(NMClient * client, - NMLDBusObject * dbobj, +_nm_device_notify_update_prop_hw_address(NMClient *client, + NMLDBusObject *dbobj, const NMLDBusMetaIface *meta_iface, guint dbus_property_idx, - GVariant * value); + GVariant *value); -NMLDBusNotifyUpdatePropFlags _nm_device_notify_update_prop_ports(NMClient * client, - NMLDBusObject * dbobj, +NMLDBusNotifyUpdatePropFlags _nm_device_notify_update_prop_ports(NMClient *client, + NMLDBusObject *dbobj, const NMLDBusMetaIface *meta_iface, guint dbus_property_idx, GVariant *value); diff --git a/src/libnm-client-impl/nm-object.c b/src/libnm-client-impl/nm-object.c index ae48853b..60b01ca8 100644 --- a/src/libnm-client-impl/nm-object.c +++ b/src/libnm-client-impl/nm-object.c @@ -24,7 +24,7 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_PATH, PROP_CLIENT, ); typedef struct _NMObjectPrivate { - NMClient * client; + NMClient *client; NMLDBusObject *dbobj; } NMObjectPrivate; @@ -117,7 +117,7 @@ nm_object_get_client(NMObject *object) static void clear_properties(NMObject *self, NMClient *client) { - NMObjectClass * klass = NM_OBJECT_GET_CLASS(self); + NMObjectClass *klass = NM_OBJECT_GET_CLASS(self); const _NMObjectClassFieldInfo *p; nm_assert(NM_IS_OBJECT(self)); @@ -141,8 +141,8 @@ clear_properties(NMObject *self, NMClient *client) static gboolean is_ready(NMObject *self) { - NMObjectClass * klass = NM_OBJECT_GET_CLASS(self); - NMClient * client = _nm_object_get_client(self); + NMObjectClass *klass = NM_OBJECT_GET_CLASS(self); + NMClient *client = _nm_object_get_client(self); const _NMObjectClassFieldInfo *p; guint16 i; @@ -172,8 +172,8 @@ is_ready(NMObject *self) static void obj_changed_notify(NMObject *self) { - NMObjectClass * klass = NM_OBJECT_GET_CLASS(self); - NMClient * client = _nm_object_get_client(self); + NMObjectClass *klass = NM_OBJECT_GET_CLASS(self); + NMClient *client = _nm_object_get_client(self); const _NMObjectClassFieldInfo *p; nm_assert(NM_IS_CLIENT(client)); @@ -245,7 +245,7 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) static void nm_object_init(NMObject *object) { - NMObject * self = NM_OBJECT(object); + NMObject *self = NM_OBJECT(object); NMObjectPrivate *priv; priv = G_TYPE_INSTANCE_GET_PRIVATE(self, NM_TYPE_OBJECT, NMObjectPrivate); @@ -262,7 +262,7 @@ nm_object_init(NMObject *object) static void dispose(GObject *object) { - NMObject * self = NM_OBJECT(object); + NMObject *self = NM_OBJECT(object); NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE(self); if (!self->obj_base.is_disposing) { diff --git a/src/libnm-client-impl/nm-property-infos-dbus.xml b/src/libnm-client-impl/nm-property-infos-dbus.xml index 009e1274..25c9c728 100644 --- a/src/libnm-client-impl/nm-property-infos-dbus.xml +++ b/src/libnm-client-impl/nm-property-infos-dbus.xml @@ -1,127 +1,53 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/libnm-client-impl/nm-property-infos-ifcfg-rh.xml b/src/libnm-client-impl/nm-property-infos-ifcfg-rh.xml index 15950eb8..91d04e13 100644 --- a/src/libnm-client-impl/nm-property-infos-ifcfg-rh.xml +++ b/src/libnm-client-impl/nm-property-infos-ifcfg-rh.xml @@ -1,339 +1,53 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/libnm-client-impl/nm-property-infos-keyfile.xml b/src/libnm-client-impl/nm-property-infos-keyfile.xml index 78a7fc0b..c6021c1c 100644 --- a/src/libnm-client-impl/nm-property-infos-keyfile.xml +++ b/src/libnm-client-impl/nm-property-infos-keyfile.xml @@ -1,128 +1,53 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/libnm-client-impl/nm-property-infos-nmcli.xml b/src/libnm-client-impl/nm-property-infos-nmcli.xml index a234f3ce..3d067745 100644 --- a/src/libnm-client-impl/nm-property-infos-nmcli.xml +++ b/src/libnm-client-impl/nm-property-infos-nmcli.xml @@ -1,80 +1,180 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + +A list of IPv4 destination addresses, prefix length, optional IPv4 +next hop addresses, optional route metric, optional attribute. The valid syntax is: +"ip[/prefix] [next-hop] [metric] [attribute=val]...[,ip[/prefix]...]". +For example "192.0.2.0/24 10.1.1.1 77, 198.51.100.0/24". + + +Various attributes are supported: + + +"cwnd" - an unsigned 32 bit integer. + + +"initcwnd" - an unsigned 32 bit integer. + + +"initrwnd" - an unsigned 32 bit integer. + + +"lock-cwnd" - a boolean value. + + +"lock-initcwnd" - a boolean value. + + +"lock-initrwnd" - a boolean value. + + +"lock-mtu" - a boolean value. + + +"lock-window" - a boolean value. + + +"mtu" - an unsigned 32 bit integer. + + +"onlink" - a boolean value. + + +"scope" - an unsigned 8 bit integer. IPv4 only. + + +"src" - an IPv4 address. + + +"table" - an unsigned 32 bit integer. The default depends on ipv4.route-table. + + +"tos" - an unsigned 8 bit integer. IPv4 only. + + +"type" - one of unicast, local, blackhole, +unavailable, prohibit. The default is unicast. + + +"window" - an unsigned 32 bit integer. + + + + +For details see also `man ip-route`. + + +A comma separated list of routing rules for policy routing. The format +is based on ip rule add syntax and mostly compatible. +One difference is that routing rules in NetworkManager always need a +fixed priority. + + +Example: priority 5 from 192.167.4.0/24 table 45 + + + +A list of IPv6 destination addresses, prefix length, optional IPv6 +next hop addresses, optional route metric, optional attribute. The valid syntax is: +"ip[/prefix] [next-hop] [metric] [attribute=val]...[,ip[/prefix]...]". + + +Various attributes are supported: + + +"cwnd" - an unsigned 32 bit integer. + + +"from" - an IPv6 address with optional prefix. IPv6 only. + + +"initcwnd" - an unsigned 32 bit integer. + + +"initrwnd" - an unsigned 32 bit integer. + + +"lock-cwnd" - a boolean value. + + +"lock-initcwnd" - a boolean value. + + +"lock-initrwnd" - a boolean value. + + +"lock-mtu" - a boolean value. + + +"lock-window" - a boolean value. + + +"mtu" - an unsigned 32 bit integer. + + +"onlink" - a boolean value. + + +"src" - an IPv6 address. + + +"table" - an unsigned 32 bit integer. The default depends on ipv6.route-table. + + +"type" - one of unicast, local, blackhole, +unavailable, prohibit. The default is unicast. + + +"window" - an unsigned 32 bit integer. + + + + +For details see also `man ip-route`. + + +A comma separated list of routing rules for policy routing. The format +is based on ip rule add syntax and mostly compatible. +One difference is that routing rules in NetworkManager always need a +fixed priority. + + +Example: priority 5 from 1:2:3::5/128 table 45 + + + + + + + + + + + + + + + + + Array of TC queueing disciplines. qdisc is a basic block in the Linux traffic control subsystem @@ -84,9 +184,7 @@ Each qdisc can be specified by the following attributes: - -handle HANDLE - +handle HANDLE specifies the qdisc handle. A qdisc, which potentially can have children, gets @@ -97,9 +195,7 @@ explicitly assign a handle to qdiscs expected to have children. - -parent HANDLE - +parent HANDLE specifies the handle of the parent qdisc the current qdisc must be @@ -108,9 +204,7 @@ attached to. - -root - +root specifies that the qdisc is attached to the root of device. @@ -118,9 +212,7 @@ specifies that the qdisc is attached to the root of device. - -KIND - +KIND this is the qdisc kind. NetworkManager currently supports the @@ -137,9 +229,7 @@ Parameters for 'fq_codel': - -limit U32 - +limit U32 the hard limit on the real queue size. When this limit is @@ -148,9 +238,7 @@ reached, incoming packets are dropped. Default is 10240 packets. - -memory_limit U32 - +memory_limit U32 sets a limit on the total number of bytes that can be queued in @@ -161,9 +249,7 @@ limit parameter and the memory limit will be enforced. Default is - -flows U32 - +flows U32 the number of flows into which the incoming packets are @@ -176,9 +262,7 @@ Default value is 1024. - -target U32 - +target U32 the acceptable minimum standing/persistent queue delay. This minimum @@ -188,9 +272,7 @@ experience. The unit of measurement is microsecond(us). Default value is 5ms. - -interval U32 - +interval U32 used to ensure that the measured minimum delay does not become too stale. @@ -202,9 +284,7 @@ react. Default value is 100ms. - -quantum U32 - +quantum U32 the number of bytes used as 'deficit' in the fair queuing @@ -214,9 +294,7 @@ Ethernet MTU plus the hardware header length of 14 bytes. - -ecn BOOL - +ecn BOOL can be used to mark packets instead of dropping them. ecn is turned @@ -225,9 +303,7 @@ on by default. - -ce_threshold U32 - +ce_threshold U32 sets a threshold above which all packets are marked with ECN @@ -243,9 +319,7 @@ Parameters for 'sfq': - -divisor U32 - +divisor U32 can be used to set a different hash table size, available @@ -256,9 +330,7 @@ value: 1024. - -limit U32 - +limit U32 Upper limit of the SFQ. Can be used to reduce the default @@ -267,9 +339,7 @@ length of 127 packets. - -depth U32 - +depth U32 Limit of packets per flow. Default to @@ -278,9 +348,7 @@ Limit of packets per flow. Default to - -perturb_period U32 - +perturb_period U32 Interval in seconds for queue algorithm perturbation. @@ -294,9 +362,7 @@ collisions. - -quantum U32 - +quantum U32 Amount of bytes a flow is allowed to dequeue during a @@ -307,9 +373,7 @@ minimum value. - -flows U32 - +flows U32 Default value is 127. @@ -322,9 +386,7 @@ Parameters for 'tbf': - -rate U64 - +rate U64 Bandwidth or rate. These parameters accept a floating @@ -336,9 +398,7 @@ device's speed. - -burst U32 - +burst U32 Also known as buffer or maxburst. Size of the bucket, in @@ -365,9 +425,7 @@ have to set this. Must be an integral power of 2. - -limit U32 - +limit U32 Limit is the number of bytes that can be queued waiting @@ -376,9 +434,7 @@ for tokens to become available. - -latency U32 - +latency U32 specifies the maximum amount of time a packet can @@ -388,11 +444,7 @@ the size of the bucket, the rate and possibly the peakrate - - - - - + Array of TC traffic filters. Traffic control can manage the packet content during classification by using filters. @@ -402,9 +454,7 @@ Each tfilters can be specified by the following attributes: - -handle HANDLE - +handle HANDLE specifies the tfilters handle. A filter is used by a classful qdisc to determine in which class @@ -414,9 +464,7 @@ see qdiscs handle for detailed information. - -parent HANDLE - +parent HANDLE specifies the handle of the parent qdisc the current qdisc must be @@ -425,9 +473,7 @@ attached to. - -root - +root specifies that the qdisc is attached to the root of device. @@ -435,9 +481,7 @@ specifies that the qdisc is attached to the root of device. - -KIND - +KIND this is the tfilters kind. NetworkManager currently supports @@ -453,9 +497,7 @@ Actions for 'mirred': - -egress bool - +egress bool Define whether the packet should exit from the interface. @@ -463,9 +505,7 @@ Define whether the packet should exit from the interface. - -ingress bool - +ingress bool Define whether the packet should come into the interface. @@ -473,9 +513,7 @@ Define whether the packet should come into the interface. - -mirror bool - +mirror bool Define whether the packet should be copied to the destination space. @@ -483,9 +521,7 @@ Define whether the packet should be copied to the destination space. - -redirect bool - +redirect bool Define whether the packet should be moved to the destination space. @@ -498,49 +534,27 @@ Action for 'simple': - -sdata char[32] - +sdata char[32] The actual string to print. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/libnm-client-impl/nm-remote-connection.c b/src/libnm-client-impl/nm-remote-connection.c index 8e36cf6d..efc4dbfb 100644 --- a/src/libnm-client-impl/nm-remote-connection.c +++ b/src/libnm-client-impl/nm-remote-connection.c @@ -36,7 +36,7 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMRemoteConnection, typedef struct { GCancellable *get_settings_cancellable; - char * filename; + char *filename; guint32 flags; bool unsaved; @@ -81,11 +81,11 @@ G_DEFINE_TYPE_WITH_CODE(NMRemoteConnection, * Since: 1.12 **/ void -nm_remote_connection_update2(NMRemoteConnection * connection, - GVariant * settings, +nm_remote_connection_update2(NMRemoteConnection *connection, + GVariant *settings, NMSettingsUpdate2Flags flags, - GVariant * args, - GCancellable * cancellable, + GVariant *args, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -128,11 +128,11 @@ nm_remote_connection_update2(NMRemoteConnection * connection, **/ GVariant * nm_remote_connection_update2_finish(NMRemoteConnection *connection, - GAsyncResult * result, - GError ** error) + GAsyncResult *result, + GError **error) { gs_unref_variant GVariant *ret = NULL; - GVariant * v_result; + GVariant *v_result; g_return_val_if_fail(NM_IS_REMOTE_CONNECTION(connection), NULL); g_return_val_if_fail(nm_g_task_is_valid(result, connection, nm_remote_connection_update2), @@ -167,8 +167,8 @@ nm_remote_connection_update2_finish(NMRemoteConnection *connection, gboolean nm_remote_connection_commit_changes(NMRemoteConnection *connection, gboolean save_to_disk, - GCancellable * cancellable, - GError ** error) + GCancellable *cancellable, + GError **error) { gs_unref_variant GVariant *ret = NULL; @@ -213,7 +213,7 @@ nm_remote_connection_commit_changes(NMRemoteConnection *connection, void nm_remote_connection_commit_changes_async(NMRemoteConnection *connection, gboolean save_to_disk, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -242,8 +242,8 @@ nm_remote_connection_commit_changes_async(NMRemoteConnection *connection, **/ gboolean nm_remote_connection_commit_changes_finish(NMRemoteConnection *connection, - GAsyncResult * result, - GError ** error) + GAsyncResult *result, + GError **error) { gs_unref_variant GVariant *v_result = NULL; @@ -296,7 +296,7 @@ nm_remote_connection_save(NMRemoteConnection *connection, GCancellable *cancella **/ void nm_remote_connection_save_async(NMRemoteConnection *connection, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -331,8 +331,8 @@ nm_remote_connection_save_async(NMRemoteConnection *connection, **/ gboolean nm_remote_connection_save_finish(NMRemoteConnection *connection, - GAsyncResult * result, - GError ** error) + GAsyncResult *result, + GError **error) { g_return_val_if_fail(NM_IS_REMOTE_CONNECTION(connection), FALSE); g_return_val_if_fail(nm_g_task_is_valid(result, connection, nm_remote_connection_save_async), @@ -357,8 +357,8 @@ nm_remote_connection_save_finish(NMRemoteConnection *connection, **/ gboolean nm_remote_connection_delete(NMRemoteConnection *connection, - GCancellable * cancellable, - GError ** error) + GCancellable *cancellable, + GError **error) { g_return_val_if_fail(NM_IS_REMOTE_CONNECTION(connection), FALSE); @@ -385,7 +385,7 @@ nm_remote_connection_delete(NMRemoteConnection *connection, **/ void nm_remote_connection_delete_async(NMRemoteConnection *connection, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -420,8 +420,8 @@ nm_remote_connection_delete_async(NMRemoteConnection *connection, **/ gboolean nm_remote_connection_delete_finish(NMRemoteConnection *connection, - GAsyncResult * result, - GError ** error) + GAsyncResult *result, + GError **error) { g_return_val_if_fail(NM_IS_REMOTE_CONNECTION(connection), FALSE); g_return_val_if_fail(nm_g_task_is_valid(result, connection, nm_remote_connection_delete_async), @@ -447,12 +447,12 @@ nm_remote_connection_delete_finish(NMRemoteConnection *connection, **/ GVariant * nm_remote_connection_get_secrets(NMRemoteConnection *connection, - const char * setting_name, - GCancellable * cancellable, - GError ** error) + const char *setting_name, + GCancellable *cancellable, + GError **error) { gs_unref_variant GVariant *ret = NULL; - GVariant * secrets; + GVariant *secrets; g_return_val_if_fail(NM_IS_REMOTE_CONNECTION(connection), NULL); g_return_val_if_fail(setting_name, NULL); @@ -489,8 +489,8 @@ nm_remote_connection_get_secrets(NMRemoteConnection *connection, **/ void nm_remote_connection_get_secrets_async(NMRemoteConnection *connection, - const char * setting_name, - GCancellable * cancellable, + const char *setting_name, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -527,11 +527,11 @@ nm_remote_connection_get_secrets_async(NMRemoteConnection *connection, **/ GVariant * nm_remote_connection_get_secrets_finish(NMRemoteConnection *connection, - GAsyncResult * result, - GError ** error) + GAsyncResult *result, + GError **error) { gs_unref_variant GVariant *ret = NULL; - GVariant * secrets; + GVariant *secrets; g_return_val_if_fail(NM_IS_REMOTE_CONNECTION(connection), NULL); g_return_val_if_fail( @@ -635,7 +635,7 @@ void _nm_remote_settings_get_settings_commit(NMRemoteConnection *self, GVariant *settings) { NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE(self); - GError * error = NULL; + GError *error = NULL; gboolean visible = FALSE; gboolean changed = FALSE; @@ -761,7 +761,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm_settings_connection = NML_DBUS_ME static void nm_remote_connection_class_init(NMRemoteConnectionClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMObjectClass *nm_object_class = NM_OBJECT_CLASS(klass); object_class->get_property = get_property; diff --git a/src/libnm-client-impl/nm-secret-agent-old.c b/src/libnm-client-impl/nm-secret-agent-old.c index 881dfd54..93475ed3 100644 --- a/src/libnm-client-impl/nm-secret-agent-old.c +++ b/src/libnm-client-impl/nm-secret-agent-old.c @@ -23,8 +23,8 @@ /*****************************************************************************/ typedef struct { - char * connection_path; - char * setting_name; + char *connection_path; + char *setting_name; GDBusMethodInvocation *context; CList gsi_lst; bool is_cancelling : 1; @@ -39,12 +39,12 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMSecretAgentOld, typedef struct { GDBusConnection *dbus_connection; - GMainContext * main_context; - GMainContext * dbus_context; - GObject * context_busy_watcher; - GCancellable * name_owner_cancellable; - GCancellable * registering_cancellable; - GSource * registering_retry_source; + GMainContext *main_context; + GMainContext *dbus_context; + GObject *context_busy_watcher; + GCancellable *name_owner_cancellable; + GCancellable *registering_cancellable; + GSource *registering_retry_source; NMLInitData *init_data; @@ -289,7 +289,7 @@ static void get_secret_info_complete_and_free_error(GetSecretsInfo *info, GQuark error_domain, int error_code, - const char * error_message) + const char *error_message) { g_dbus_method_invocation_return_error_literal(g_steal_pointer(&info->context), error_domain, @@ -312,16 +312,16 @@ _dbus_connection_call_cb(GObject *source, GAsyncResult *result, gpointer user_da } static void -_dbus_connection_call(NMSecretAgentOld * self, - const char * bus_name, - const char * object_path, - const char * interface_name, - const char * method_name, - GVariant * parameters, +_dbus_connection_call(NMSecretAgentOld *self, + const char *bus_name, + const char *object_path, + 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) { @@ -350,8 +350,8 @@ _dbus_connection_call(NMSecretAgentOld * self, static GetSecretsInfo * find_get_secrets_info(NMSecretAgentOldPrivate *priv, - const char * connection_path, - const char * setting_name) + const char *connection_path, + const char *setting_name) { GetSecretsInfo *info; @@ -385,15 +385,15 @@ _cancel_get_secret_request(NMSecretAgentOld *self, GetSecretsInfo *info, const c } static gboolean -verify_request(NMSecretAgentOld * self, +verify_request(NMSecretAgentOld *self, GDBusMethodInvocation *context, - GVariant * connection_dict, - const char * connection_path, - NMConnection ** out_connection, - GError ** error) + GVariant *connection_dict, + const char *connection_path, + NMConnection **out_connection, + GError **error) { gs_unref_object NMConnection *connection = NULL; - gs_free_error GError *local = NULL; + gs_free_error GError *local = NULL; if (!nm_dbus_path_not_empty(connection_path)) { g_set_error_literal(error, @@ -422,9 +422,9 @@ verify_request(NMSecretAgentOld * self, static void get_secrets_cb(NMSecretAgentOld *self, - NMConnection * connection, - GVariant * secrets, - GError * error, + NMConnection *connection, + GVariant *secrets, + GError *error, gpointer user_data) { GetSecretsInfo *info = user_data; @@ -446,15 +446,15 @@ get_secrets_cb(NMSecretAgentOld *self, static void impl_get_secrets(NMSecretAgentOld *self, GVariant *parameters, GDBusMethodInvocation *context) { - NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE(self); - GError * error = NULL; + NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE(self); + GError *error = NULL; gs_unref_object NMConnection *connection = NULL; - GetSecretsInfo * info; - gs_unref_variant GVariant *arg_connection = NULL; - const char * arg_connection_path; - const char * arg_setting_name; - gs_free const char ** arg_hints = NULL; - guint32 arg_flags; + GetSecretsInfo *info; + gs_unref_variant GVariant *arg_connection = NULL; + const char *arg_connection_path; + const char *arg_setting_name; + gs_free const char **arg_hints = NULL; + guint32 arg_flags; g_variant_get(parameters, "(@a{sa{sv}}&o&s^a&su)", @@ -494,14 +494,14 @@ impl_get_secrets(NMSecretAgentOld *self, GVariant *parameters, GDBusMethodInvoca } static void -impl_cancel_get_secrets(NMSecretAgentOld * self, - GVariant * parameters, +impl_cancel_get_secrets(NMSecretAgentOld *self, + GVariant *parameters, GDBusMethodInvocation *context) { NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE(self); - GetSecretsInfo * info; - const char * arg_connection_path; - const char * arg_setting_name; + GetSecretsInfo *info; + const char *arg_connection_path; + const char *arg_setting_name; g_variant_get(parameters, "(&o&s)", &arg_connection_path, &arg_setting_name); @@ -534,10 +534,10 @@ save_secrets_cb(NMSecretAgentOld *self, NMConnection *connection, GError *error, static void impl_save_secrets(NMSecretAgentOld *self, GVariant *parameters, GDBusMethodInvocation *context) { - gs_unref_object NMConnection *connection = NULL; - gs_unref_variant GVariant *arg_connection = NULL; - const char * arg_connection_path; - GError * error = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_variant GVariant *arg_connection = NULL; + const char *arg_connection_path; + GError *error = NULL; g_variant_get(parameters, "(@a{sa{sv}}&o)", &arg_connection, &arg_connection_path); @@ -557,8 +557,8 @@ impl_save_secrets(NMSecretAgentOld *self, GVariant *parameters, GDBusMethodInvoc static void delete_secrets_cb(NMSecretAgentOld *self, - NMConnection * connection, - GError * error, + NMConnection *connection, + GError *error, gpointer user_data) { GDBusMethodInvocation *context = user_data; @@ -572,10 +572,10 @@ delete_secrets_cb(NMSecretAgentOld *self, static void impl_delete_secrets(NMSecretAgentOld *self, GVariant *parameters, GDBusMethodInvocation *context) { - gs_unref_object NMConnection *connection = NULL; - gs_unref_variant GVariant *arg_connection = NULL; - const char * arg_connection_path; - GError * error = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_variant GVariant *arg_connection = NULL; + const char *arg_connection_path; + GError *error = NULL; g_variant_get(parameters, "(@a{sa{sv}}&o)", &arg_connection, &arg_connection_path); @@ -739,13 +739,13 @@ nm_secret_agent_old_register(NMSecretAgentOld *self, GCancellable *cancellable, static void _register_cancelled_cb(GObject *object, gpointer user_data) { - GTask * task0 = user_data; - gs_unref_object GTask * task = NULL; - NMSecretAgentOld * self = g_task_get_source_object(task0); - NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE(self); - gulong * p_cancelled_id; - NMCListElem * elem; - gs_free_error GError *error = NULL; + GTask *task0 = user_data; + gs_unref_object GTask *task = NULL; + NMSecretAgentOld *self = g_task_get_source_object(task0); + NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE(self); + gulong *p_cancelled_id; + NMCListElem *elem; + gs_free_error GError *error = NULL; elem = nm_c_list_elem_find_first(&priv->pending_tasks_register_lst_head, x, x == task0); @@ -786,8 +786,8 @@ _register_cancelled_cb(GObject *object, gpointer user_data) * you want to check and ensure that the agent is registered. **/ void -nm_secret_agent_old_register_async(NMSecretAgentOld * self, - GCancellable * cancellable, +nm_secret_agent_old_register_async(NMSecretAgentOld *self, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -906,8 +906,8 @@ nm_secret_agent_old_unregister(NMSecretAgentOld *self, GCancellable *cancellable * Deprecated: 1.24: Use nm_secret_agent_old_enable(). **/ void -nm_secret_agent_old_unregister_async(NMSecretAgentOld * self, - GCancellable * cancellable, +nm_secret_agent_old_unregister_async(NMSecretAgentOld *self, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -980,10 +980,10 @@ nm_secret_agent_old_unregister_finish(NMSecretAgentOld *self, GAsyncResult *resu * secrets from the user. */ void -nm_secret_agent_old_get_secrets(NMSecretAgentOld * self, - NMConnection * connection, - const char * setting_name, - const char ** hints, +nm_secret_agent_old_get_secrets(NMSecretAgentOld *self, + NMConnection *connection, + const char *setting_name, + const char **hints, NMSecretAgentGetSecretsFlags flags, NMSecretAgentOldGetSecretsFunc callback, gpointer user_data) @@ -1017,8 +1017,8 @@ nm_secret_agent_old_get_secrets(NMSecretAgentOld * self, * disk. */ void -nm_secret_agent_old_save_secrets(NMSecretAgentOld * self, - NMConnection * connection, +nm_secret_agent_old_save_secrets(NMSecretAgentOld *self, + NMConnection *connection, NMSecretAgentOldSaveSecretsFunc callback, gpointer user_data) { @@ -1044,8 +1044,8 @@ nm_secret_agent_old_save_secrets(NMSecretAgentOld * self, * @connection. */ void -nm_secret_agent_old_delete_secrets(NMSecretAgentOld * self, - NMConnection * connection, +nm_secret_agent_old_delete_secrets(NMSecretAgentOld *self, + NMConnection *connection, NMSecretAgentOldDeleteSecretsFunc callback, gpointer user_data) { @@ -1093,8 +1093,8 @@ validate_identifier(const char *identifier) static gboolean _register_retry_cb(gpointer user_data) { - NMSecretAgentOld * self = user_data; - NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE(self); + NMSecretAgentOld *self = user_data; + NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE(self); nm_auto_pop_gmaincontext GMainContext *dbus_context = NULL; dbus_context = nm_g_main_context_push_thread_default_if_necessary(priv->dbus_context); @@ -1107,10 +1107,10 @@ _register_retry_cb(gpointer user_data) static void _register_call_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - NMSecretAgentOld * self = user_data; - NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE(self); - gs_unref_variant GVariant *ret = NULL; - gs_free_error GError *error = NULL; + NMSecretAgentOld *self = user_data; + NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE(self); + gs_unref_variant GVariant *ret = NULL; + gs_free_error GError *error = NULL; ret = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), result, &error); @@ -1187,11 +1187,11 @@ _register_dbus_call(NMSecretAgentOld *self) static void _get_connection_unix_user_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - NMSecretAgentOld * self; - NMSecretAgentOldPrivate *priv; - gs_unref_variant GVariant *ret = NULL; - gs_free_error GError *error = NULL; - guint32 sender_uid = 0; + NMSecretAgentOld *self; + NMSecretAgentOldPrivate *priv; + gs_unref_variant GVariant *ret = NULL; + gs_free_error GError *error = NULL; + guint32 sender_uid = 0; ret = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), result, &error); if (nm_utils_error_is_cancelled(error)) @@ -1275,15 +1275,15 @@ _name_owner_changed(NMSecretAgentOld *self, const char *name_owner, gboolean is_ 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) { NMSecretAgentOld *self = user_data; - const char * new_owner; + const char *new_owner; if (!g_variant_is_of_type(parameters, G_VARIANT_TYPE("(sss)"))) return; @@ -1303,16 +1303,16 @@ _name_owner_get_cb(const char *name_owner, GError *error, gpointer user_data) /*****************************************************************************/ 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 *context, gpointer user_data) { - NMSecretAgentOld * self = user_data; + NMSecretAgentOld *self = user_data; NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE(self); nm_assert(nm_streq0(object_path, NM_DBUS_PATH_SECRET_AGENT)); @@ -1349,7 +1349,7 @@ static void _register_state_complete(NMSecretAgentOld *self) { NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE(self); - NMCListElem * elem; + NMCListElem *elem; gboolean any_tasks_to_complete = FALSE; if (!c_list_is_empty(&priv->pending_tasks_register_lst_head)) { @@ -1367,7 +1367,7 @@ _register_state_complete(NMSecretAgentOld *self) if (any_tasks_to_complete) { while ( (elem = c_list_first_entry(&priv->pending_tasks_register_lst_head, NMCListElem, lst))) { - gpointer data = nm_c_list_elem_free_steal(elem); + gpointer data = nm_c_list_elem_free_steal(elem); gs_unref_object GTask *task = NULL; if (data == &any_tasks_to_complete) { @@ -1525,8 +1525,8 @@ static void _register_state_change(NMSecretAgentOld *self) { _nm_unused gs_unref_object NMSecretAgentOld *self_keep_alive = g_object_ref(self); - NMSecretAgentOldPrivate * priv = NM_SECRET_AGENT_OLD_GET_PRIVATE(self); - nm_auto_pop_gmaincontext GMainContext *dbus_context = NULL; + NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE(self); + nm_auto_pop_gmaincontext GMainContext *dbus_context = NULL; if (priv->register_state_change_reenter == 0) { /* We are not yet initialized. Do nothing. */ @@ -1558,9 +1558,9 @@ again: static void _init_complete(NMSecretAgentOld *self, GError *error_take) { - NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE(self); - gs_free_error GError *error = g_steal_pointer(&error_take); - GError * error_cancelled = NULL; + NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE(self); + gs_free_error GError *error = g_steal_pointer(&error_take); + GError *error_cancelled = NULL; if (!priv->init_data) return; @@ -1582,10 +1582,10 @@ _init_complete(NMSecretAgentOld *self, GError *error_take) static void _init_register_object(NMSecretAgentOld *self) { - NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE(self); - gs_free_error GError *error = NULL; - GDBusInterfaceVTable interface_vtable = { - .method_call = _method_call, + NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE(self); + gs_free_error GError *error = NULL; + GDBusInterfaceVTable interface_vtable = { + .method_call = _method_call, }; if (g_cancellable_set_error_if_cancelled(priv->init_data->cancellable, &error)) { @@ -1613,9 +1613,9 @@ _init_register_object(NMSecretAgentOld *self) static void _init_got_bus(GObject *initable, GAsyncResult *result, gpointer user_data) { - NMSecretAgentOld * self = user_data; - NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE(self); - gs_free_error GError *error = NULL; + NMSecretAgentOld *self = user_data; + NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE(self); + gs_free_error GError *error = NULL; priv->dbus_connection = g_bus_get_finish(result, &error); if (!priv->dbus_connection) { @@ -1650,17 +1650,17 @@ _init_start(NMSecretAgentOld *self) } static void -init_async(GAsyncInitable * initable, +init_async(GAsyncInitable *initable, int io_priority, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { - NMSecretAgentOld * self; - NMSecretAgentOldClass * klass; - NMSecretAgentOldPrivate *priv; + NMSecretAgentOld *self; + NMSecretAgentOldClass *klass; + NMSecretAgentOldPrivate *priv; nm_auto_pop_gmaincontext GMainContext *dbus_context = NULL; - gs_unref_object GTask *task = NULL; + gs_unref_object GTask *task = NULL; g_return_if_fail(NM_IS_SECRET_AGENT_OLD(initable)); @@ -1705,10 +1705,10 @@ static gboolean init_sync(GInitable *initable, GCancellable *cancellable, GError **error) { gs_unref_object NMSecretAgentOld *self = NULL; - NMSecretAgentOldPrivate * priv; - NMSecretAgentOldClass * klass; - GMainLoop * main_loop; - GError * local_error = NULL; + NMSecretAgentOldPrivate *priv; + NMSecretAgentOldClass *klass; + GMainLoop *main_loop; + GError *local_error = NULL; g_return_val_if_fail(NM_IS_SECRET_AGENT_OLD(initable), FALSE); @@ -1789,7 +1789,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) { - NMSecretAgentOld * self = NM_SECRET_AGENT_OLD(object); + NMSecretAgentOld *self = NM_SECRET_AGENT_OLD(object); NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE(self); guint u; @@ -1855,7 +1855,7 @@ dispose(GObject *object) static void finalize(GObject *object) { - NMSecretAgentOld * self = NM_SECRET_AGENT_OLD(object); + NMSecretAgentOld *self = NM_SECRET_AGENT_OLD(object); NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE(self); _LOGT("finalizing"); diff --git a/src/libnm-client-impl/nm-settings-docs-gir.xml b/src/libnm-client-impl/nm-settings-docs-gir.xml index b916ee04..d8022132 100644 --- a/src/libnm-client-impl/nm-settings-docs-gir.xml +++ b/src/libnm-client-impl/nm-settings-docs-gir.xml @@ -304,6 +304,7 @@ + diff --git a/src/libnm-client-impl/nm-vpn-connection.c b/src/libnm-client-impl/nm-vpn-connection.c index fb061532..45699680 100644 --- a/src/libnm-client-impl/nm-vpn-connection.c +++ b/src/libnm-client-impl/nm-vpn-connection.c @@ -27,7 +27,7 @@ enum { static guint signals[LAST_SIGNAL] = {0}; typedef struct { - char * banner; + char *banner; guint32 vpn_state; guint32 reason; } NMVpnConnectionPrivate; @@ -89,7 +89,7 @@ static void _notify_event_state_changed(NMClient *client, NMClientNotifyEventWithPtr *notify_event) { gs_unref_object NMVpnConnection *self = notify_event->user_data; - NMVpnConnectionPrivate * priv = NM_VPN_CONNECTION_GET_PRIVATE(self); + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); /* we expose here the value cache in @priv. In practice, this is the same * value as we received from the signal. In the unexpected case where they @@ -104,7 +104,7 @@ _notify_event_state_changed(NMClient *client, NMClientNotifyEventWithPtr *notify void _nm_vpn_connection_state_changed_commit(NMVpnConnection *self, guint32 state, guint32 reason) { - NMClient * client; + NMClient *client; NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE(self); client = _nm_object_get_client(self); diff --git a/src/libnm-client-impl/nm-vpn-plugin-old.c b/src/libnm-client-impl/nm-vpn-plugin-old.c index f60bf19c..19ba2bb0 100644 --- a/src/libnm-client-impl/nm-vpn-plugin-old.c +++ b/src/libnm-client-impl/nm-vpn-plugin-old.c @@ -37,7 +37,7 @@ typedef struct { /* DBUS-y stuff */ GDBusConnection *connection; NMDBusVpnPlugin *dbus_vpn_plugin_old; - char * dbus_service_name; + char *dbus_service_name; /* Temporary stuff */ guint connect_timer; @@ -226,7 +226,7 @@ static gboolean connect_timer_expired(gpointer data) { NMVpnPluginOld *plugin = NM_VPN_PLUGIN_OLD(data); - GError * err = NULL; + GError *err = NULL; NM_VPN_PLUGIN_OLD_GET_PRIVATE(plugin)->connect_timer = 0; g_message("Connect timer expired, disconnecting."); @@ -330,11 +330,11 @@ void nm_vpn_plugin_old_set_ip4_config(NMVpnPluginOld *plugin, GVariant *ip4_config) { NMVpnPluginOldPrivate *priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE(plugin); - GVariant * combined_config; + GVariant *combined_config; GVariantBuilder builder; GVariantIter iter; - const char * key; - GVariant * value; + const char *key; + GVariant *value; g_return_if_fail(NM_IS_VPN_PLUGIN_OLD(plugin)); g_return_if_fail(ip4_config != NULL); @@ -415,17 +415,17 @@ connect_timer_start(NMVpnPluginOld *plugin) } static void -_connect_generic(NMVpnPluginOld * plugin, +_connect_generic(NMVpnPluginOld *plugin, GDBusMethodInvocation *context, - GVariant * properties, - GVariant * details) + GVariant *properties, + GVariant *details) { - NMVpnPluginOldPrivate *priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE(plugin); - NMVpnPluginOldClass * vpn_class = NM_VPN_PLUGIN_OLD_GET_CLASS(plugin); - gs_unref_object NMConnection *connection = NULL; - gboolean success = FALSE; - gs_free_error GError *error = NULL; - guint fail_stop_timeout = 0; + NMVpnPluginOldPrivate *priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE(plugin); + NMVpnPluginOldClass *vpn_class = NM_VPN_PLUGIN_OLD_GET_CLASS(plugin); + gs_unref_object NMConnection *connection = NULL; + gboolean success = FALSE; + gs_free_error GError *error = NULL; + guint fail_stop_timeout = 0; if (priv->state != NM_VPN_SERVICE_STATE_STOPPED && priv->state != NM_VPN_SERVICE_STATE_INIT) { g_dbus_method_invocation_return_error(context, @@ -488,19 +488,19 @@ _connect_generic(NMVpnPluginOld * plugin, } static void -impl_vpn_plugin_old_connect(NMVpnPluginOld * plugin, +impl_vpn_plugin_old_connect(NMVpnPluginOld *plugin, GDBusMethodInvocation *context, - GVariant * connection, + GVariant *connection, gpointer user_data) { _connect_generic(plugin, context, connection, NULL); } static void -impl_vpn_plugin_old_connect_interactive(NMVpnPluginOld * plugin, +impl_vpn_plugin_old_connect_interactive(NMVpnPluginOld *plugin, GDBusMethodInvocation *context, - GVariant * connection, - GVariant * details, + GVariant *connection, + GVariant *details, gpointer user_data) { _connect_generic(plugin, context, connection, details); @@ -509,15 +509,15 @@ impl_vpn_plugin_old_connect_interactive(NMVpnPluginOld * plugin, /*****************************************************************************/ static void -impl_vpn_plugin_old_need_secrets(NMVpnPluginOld * plugin, +impl_vpn_plugin_old_need_secrets(NMVpnPluginOld *plugin, GDBusMethodInvocation *context, - GVariant * properties, + GVariant *properties, gpointer user_data) { NMConnection *connection; - const char * setting_name; + const char *setting_name; gboolean needed; - GError * error = NULL; + GError *error = NULL; connection = _nm_simple_connection_new_from_dbus(properties, NM_SETTING_PARSE_FLAGS_BEST_EFFORT, &error); @@ -560,14 +560,14 @@ impl_vpn_plugin_old_need_secrets(NMVpnPluginOld * plugin, } static void -impl_vpn_plugin_old_new_secrets(NMVpnPluginOld * plugin, +impl_vpn_plugin_old_new_secrets(NMVpnPluginOld *plugin, GDBusMethodInvocation *context, - GVariant * properties, + GVariant *properties, gpointer user_data) { NMVpnPluginOldPrivate *priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE(plugin); - NMConnection * connection; - GError * error = NULL; + NMConnection *connection; + GError *error = NULL; gboolean success; if (priv->state != NM_VPN_SERVICE_STATE_STARTING) { @@ -693,8 +693,8 @@ nm_vpn_plugin_old_read_vpn_details(int fd, GHashTable **out_data, GHashTable **o * Deprecated: 1.2: Replaced by NMVpnServicePlugin. **/ gboolean -nm_vpn_plugin_old_get_secret_flags(GHashTable * data, - const char * secret_name, +nm_vpn_plugin_old_get_secret_flags(GHashTable *data, + const char *secret_name, NMSettingSecretFlags *out_flags) { return nm_vpn_service_plugin_get_secret_flags(data, secret_name, out_flags); @@ -703,7 +703,7 @@ nm_vpn_plugin_old_get_secret_flags(GHashTable * data, /*****************************************************************************/ static void -impl_vpn_plugin_old_disconnect(NMVpnPluginOld * plugin, +impl_vpn_plugin_old_disconnect(NMVpnPluginOld *plugin, GDBusMethodInvocation *context, gpointer user_data) { @@ -716,9 +716,9 @@ impl_vpn_plugin_old_disconnect(NMVpnPluginOld * plugin, } static void -impl_vpn_plugin_old_set_config(NMVpnPluginOld * plugin, +impl_vpn_plugin_old_set_config(NMVpnPluginOld *plugin, GDBusMethodInvocation *context, - GVariant * config, + GVariant *config, gpointer user_data) { nm_vpn_plugin_old_set_config(plugin, config); @@ -726,9 +726,9 @@ impl_vpn_plugin_old_set_config(NMVpnPluginOld * plugin, } static void -impl_vpn_plugin_old_set_ip4_config(NMVpnPluginOld * plugin, +impl_vpn_plugin_old_set_ip4_config(NMVpnPluginOld *plugin, GDBusMethodInvocation *context, - GVariant * config, + GVariant *config, gpointer user_data) { nm_vpn_plugin_old_set_ip4_config(plugin, config); @@ -736,9 +736,9 @@ impl_vpn_plugin_old_set_ip4_config(NMVpnPluginOld * plugin, } static void -impl_vpn_plugin_old_set_ip6_config(NMVpnPluginOld * plugin, +impl_vpn_plugin_old_set_ip6_config(NMVpnPluginOld *plugin, GDBusMethodInvocation *context, - GVariant * config, + GVariant *config, gpointer user_data) { nm_vpn_plugin_old_set_ip6_config(plugin, config); @@ -746,9 +746,9 @@ impl_vpn_plugin_old_set_ip6_config(NMVpnPluginOld * plugin, } static void -impl_vpn_plugin_old_set_failure(NMVpnPluginOld * plugin, +impl_vpn_plugin_old_set_failure(NMVpnPluginOld *plugin, GDBusMethodInvocation *context, - char * reason, + char *reason, gpointer user_data) { nm_vpn_plugin_old_failure(plugin, NM_VPN_PLUGIN_FAILURE_BAD_IP_CONFIG); @@ -803,11 +803,11 @@ nm_vpn_plugin_old_init(NMVpnPluginOld *plugin) static gboolean init_sync(GInitable *initable, GCancellable *cancellable, GError **error) { - NMVpnPluginOld * plugin = NM_VPN_PLUGIN_OLD(initable); + NMVpnPluginOld *plugin = NM_VPN_PLUGIN_OLD(initable); NMVpnPluginOldPrivate *priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE(plugin); - GDBusConnection * connection = NULL; - GDBusProxy * proxy; - GVariant * ret; + GDBusConnection *connection = NULL; + GDBusProxy *proxy; + GVariant *ret; gboolean success = FALSE; if (!priv->dbus_service_name) { @@ -931,10 +931,10 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) static void dispose(GObject *object) { - NMVpnPluginOld * plugin = NM_VPN_PLUGIN_OLD(object); + NMVpnPluginOld *plugin = NM_VPN_PLUGIN_OLD(object); NMVpnPluginOldPrivate *priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE(plugin); NMVpnServiceState state; - GError * err = NULL; + GError *err = NULL; nm_clear_g_source(&priv->fail_stop_id); nm_clear_g_source(&priv->quit_timer); @@ -956,7 +956,7 @@ dispose(GObject *object) static void finalize(GObject *object) { - NMVpnPluginOld * plugin = NM_VPN_PLUGIN_OLD(object); + NMVpnPluginOld *plugin = NM_VPN_PLUGIN_OLD(object); NMVpnPluginOldPrivate *priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE(plugin); nm_vpn_plugin_old_set_connection(plugin, NULL); diff --git a/src/libnm-client-impl/nm-vpn-service-plugin.c b/src/libnm-client-impl/nm-vpn-service-plugin.c index 18a85e91..2a217502 100644 --- a/src/libnm-client-impl/nm-vpn-service-plugin.c +++ b/src/libnm-client-impl/nm-vpn-service-plugin.c @@ -39,7 +39,7 @@ typedef struct { /* DBUS-y stuff */ GDBusConnection *connection; NMDBusVpnPlugin *dbus_vpn_service_plugin; - char * dbus_service_name; + char *dbus_service_name; gboolean dbus_watch_peer; /* Temporary stuff */ @@ -240,7 +240,7 @@ nm_vpn_service_plugin_shutdown(NMVpnServicePlugin *plugin) { NMVpnServicePluginPrivate *priv; NMVpnServiceState state; - GError * error = NULL; + GError *error = NULL; g_return_if_fail(NM_IS_VPN_SERVICE_PLUGIN(plugin)); @@ -271,7 +271,7 @@ static gboolean connect_timer_expired(gpointer data) { NMVpnServicePlugin *plugin = NM_VPN_SERVICE_PLUGIN(data); - GError * err = NULL; + GError *err = NULL; NM_VPN_SERVICE_PLUGIN_GET_PRIVATE(plugin)->connect_timer = 0; g_message("Connect timer expired, disconnecting."); @@ -368,11 +368,11 @@ void nm_vpn_service_plugin_set_ip4_config(NMVpnServicePlugin *plugin, GVariant *ip4_config) { NMVpnServicePluginPrivate *priv = NM_VPN_SERVICE_PLUGIN_GET_PRIVATE(plugin); - GVariant * combined_config; + GVariant *combined_config; GVariantBuilder builder; GVariantIter iter; - const char * key; - GVariant * value; + const char *key; + GVariant *value; g_return_if_fail(NM_IS_VPN_SERVICE_PLUGIN(plugin)); g_return_if_fail(ip4_config != NULL); @@ -454,11 +454,11 @@ connect_timer_start(NMVpnServicePlugin *plugin) static void peer_vanished(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) { nm_vpn_service_plugin_disconnect(NM_VPN_SERVICE_PLUGIN(user_data), NULL); @@ -478,16 +478,16 @@ watch_peer(NMVpnServicePlugin *plugin, GDBusMethodInvocation *context) } static void -_connect_generic(NMVpnServicePlugin * plugin, +_connect_generic(NMVpnServicePlugin *plugin, GDBusMethodInvocation *context, - GVariant * properties, - GVariant * details) + GVariant *properties, + GVariant *details) { NMVpnServicePluginPrivate *priv = NM_VPN_SERVICE_PLUGIN_GET_PRIVATE(plugin); - NMVpnServicePluginClass * vpn_class = NM_VPN_SERVICE_PLUGIN_GET_CLASS(plugin); - NMConnection * connection; + NMVpnServicePluginClass *vpn_class = NM_VPN_SERVICE_PLUGIN_GET_CLASS(plugin); + NMConnection *connection; gboolean success = FALSE; - GError * error = NULL; + GError *error = NULL; guint fail_stop_timeout = 0; if (priv->state != NM_VPN_SERVICE_STATE_STOPPED && priv->state != NM_VPN_SERVICE_STATE_INIT) { @@ -557,19 +557,19 @@ _connect_generic(NMVpnServicePlugin * plugin, } static void -impl_vpn_service_plugin_connect(NMVpnServicePlugin * plugin, +impl_vpn_service_plugin_connect(NMVpnServicePlugin *plugin, GDBusMethodInvocation *context, - GVariant * connection, + GVariant *connection, gpointer user_data) { _connect_generic(plugin, context, connection, NULL); } static void -impl_vpn_service_plugin_connect_interactive(NMVpnServicePlugin * plugin, +impl_vpn_service_plugin_connect_interactive(NMVpnServicePlugin *plugin, GDBusMethodInvocation *context, - GVariant * connection, - GVariant * details, + GVariant *connection, + GVariant *details, gpointer user_data) { _connect_generic(plugin, context, connection, details); @@ -578,15 +578,15 @@ impl_vpn_service_plugin_connect_interactive(NMVpnServicePlugin * plugin, /*****************************************************************************/ static void -impl_vpn_service_plugin_need_secrets(NMVpnServicePlugin * plugin, +impl_vpn_service_plugin_need_secrets(NMVpnServicePlugin *plugin, GDBusMethodInvocation *context, - GVariant * properties, + GVariant *properties, gpointer user_data) { NMConnection *connection; - const char * setting_name; + const char *setting_name; gboolean needed; - GError * error = NULL; + GError *error = NULL; connection = _nm_simple_connection_new_from_dbus(properties, NM_SETTING_PARSE_FLAGS_BEST_EFFORT, &error); @@ -629,14 +629,14 @@ impl_vpn_service_plugin_need_secrets(NMVpnServicePlugin * plugin, } static void -impl_vpn_service_plugin_new_secrets(NMVpnServicePlugin * plugin, +impl_vpn_service_plugin_new_secrets(NMVpnServicePlugin *plugin, GDBusMethodInvocation *context, - GVariant * properties, + GVariant *properties, gpointer user_data) { NMVpnServicePluginPrivate *priv = NM_VPN_SERVICE_PLUGIN_GET_PRIVATE(plugin); - NMConnection * connection; - GError * error = NULL; + NMConnection *connection; + GError *error = NULL; gboolean success; if (priv->state != NM_VPN_SERVICE_STATE_STARTING) { @@ -704,8 +704,8 @@ impl_vpn_service_plugin_new_secrets(NMVpnServicePlugin * plugin, */ void nm_vpn_service_plugin_secrets_required(NMVpnServicePlugin *plugin, - const char * message, - const char ** hints) + const char *message, + const char **hints) { NMVpnServicePluginPrivate *priv = NM_VPN_SERVICE_PLUGIN_GET_PRIVATE(plugin); @@ -803,12 +803,12 @@ nm_vpn_service_plugin_read_vpn_details(int fd, GHashTable **out_data, GHashTable gs_unref_hashtable GHashTable *data = NULL; gs_unref_hashtable GHashTable *secrets = NULL; gboolean success = FALSE; - GHashTable * hash = NULL; - nm_auto_free_gstring GString *key = NULL; - nm_auto_free_gstring GString *val = NULL; - nm_auto_free_gstring GString *line = NULL; - GString * str = NULL; - ReadFdBuf read_buf; + GHashTable *hash = NULL; + nm_auto_free_gstring GString *key = NULL; + nm_auto_free_gstring GString *val = NULL; + nm_auto_free_gstring GString *line = NULL; + GString *str = NULL; + ReadFdBuf read_buf; if (out_data) g_return_val_if_fail(*out_data == NULL, FALSE); @@ -920,12 +920,12 @@ next: * Since: 1.2 **/ gboolean -nm_vpn_service_plugin_get_secret_flags(GHashTable * data, - const char * secret_name, +nm_vpn_service_plugin_get_secret_flags(GHashTable *data, + const char *secret_name, NMSettingSecretFlags *out_flags) { - gs_free char * flag_name_free = NULL; - const char * s; + gs_free char *flag_name_free = NULL; + const char *s; gint64 t1; NMSettingSecretFlags t0; @@ -950,7 +950,7 @@ nm_vpn_service_plugin_get_secret_flags(GHashTable * data, /*****************************************************************************/ static void -impl_vpn_service_plugin_disconnect(NMVpnServicePlugin * plugin, +impl_vpn_service_plugin_disconnect(NMVpnServicePlugin *plugin, GDBusMethodInvocation *context, gpointer user_data) { @@ -963,9 +963,9 @@ impl_vpn_service_plugin_disconnect(NMVpnServicePlugin * plugin, } static void -impl_vpn_service_plugin_set_config(NMVpnServicePlugin * plugin, +impl_vpn_service_plugin_set_config(NMVpnServicePlugin *plugin, GDBusMethodInvocation *context, - GVariant * config, + GVariant *config, gpointer user_data) { nm_vpn_service_plugin_set_config(plugin, config); @@ -973,9 +973,9 @@ impl_vpn_service_plugin_set_config(NMVpnServicePlugin * plugin, } static void -impl_vpn_service_plugin_set_ip4_config(NMVpnServicePlugin * plugin, +impl_vpn_service_plugin_set_ip4_config(NMVpnServicePlugin *plugin, GDBusMethodInvocation *context, - GVariant * config, + GVariant *config, gpointer user_data) { nm_vpn_service_plugin_set_ip4_config(plugin, config); @@ -983,9 +983,9 @@ impl_vpn_service_plugin_set_ip4_config(NMVpnServicePlugin * plugin, } static void -impl_vpn_service_plugin_set_ip6_config(NMVpnServicePlugin * plugin, +impl_vpn_service_plugin_set_ip6_config(NMVpnServicePlugin *plugin, GDBusMethodInvocation *context, - GVariant * config, + GVariant *config, gpointer user_data) { nm_vpn_service_plugin_set_ip6_config(plugin, config); @@ -993,9 +993,9 @@ impl_vpn_service_plugin_set_ip6_config(NMVpnServicePlugin * plugin, } static void -impl_vpn_service_plugin_set_failure(NMVpnServicePlugin * plugin, +impl_vpn_service_plugin_set_failure(NMVpnServicePlugin *plugin, GDBusMethodInvocation *context, - char * reason, + char *reason, gpointer user_data) { nm_vpn_service_plugin_failure(plugin, NM_VPN_PLUGIN_FAILURE_BAD_IP_CONFIG); @@ -1050,11 +1050,11 @@ nm_vpn_service_plugin_init(NMVpnServicePlugin *plugin) static gboolean init_sync(GInitable *initable, GCancellable *cancellable, GError **error) { - NMVpnServicePlugin * plugin = NM_VPN_SERVICE_PLUGIN(initable); - NMVpnServicePluginPrivate *priv = NM_VPN_SERVICE_PLUGIN_GET_PRIVATE(plugin); + NMVpnServicePlugin *plugin = NM_VPN_SERVICE_PLUGIN(initable); + NMVpnServicePluginPrivate *priv = NM_VPN_SERVICE_PLUGIN_GET_PRIVATE(plugin); gs_unref_object GDBusConnection *connection = NULL; - gs_unref_object GDBusProxy *proxy = NULL; - GVariant * ret; + gs_unref_object GDBusProxy *proxy = NULL; + GVariant *ret; if (!priv->dbus_service_name) { g_set_error_literal(error, @@ -1186,7 +1186,7 @@ dispose(GObject *object) static void finalize(GObject *object) { - NMVpnServicePlugin * plugin = NM_VPN_SERVICE_PLUGIN(object); + NMVpnServicePlugin *plugin = NM_VPN_SERVICE_PLUGIN(object); NMVpnServicePluginPrivate *priv = NM_VPN_SERVICE_PLUGIN_GET_PRIVATE(plugin); nm_vpn_service_plugin_set_connection(plugin, NULL); diff --git a/src/libnm-client-impl/nm-wifi-p2p-peer.c b/src/libnm-client-impl/nm-wifi-p2p-peer.c index 1d6b7c95..54d1c5ed 100644 --- a/src/libnm-client-impl/nm-wifi-p2p-peer.c +++ b/src/libnm-client-impl/nm-wifi-p2p-peer.c @@ -29,12 +29,12 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_FLAGS, typedef struct { GBytes *wfd_ies; - char * name; - char * manufacturer; - char * model; - char * model_number; - char * serial; - char * hw_address; + char *name; + char *manufacturer; + char *model; + char *model_number; + char *serial; + char *hw_address; gint32 last_seen; guint32 flags; guint8 strength; @@ -261,10 +261,10 @@ gboolean nm_wifi_p2p_peer_connection_valid(NMWifiP2PPeer *peer, NMConnection *connection) { NMSettingConnection *s_con; - NMSettingWifiP2P * s_wifi_p2p; - const char * ctype; - const char * hw_address; - const char * setting_peer; + NMSettingWifiP2P *s_wifi_p2p; + const char *ctype; + const char *hw_address; + const char *setting_peer; s_wifi_p2p = (NMSettingWifiP2P *) nm_connection_get_setting(connection, NM_TYPE_SETTING_WIFI_P2P); diff --git a/src/libnm-client-impl/tests/test-libnm.c b/src/libnm-client-impl/tests/test-libnm.c index 29ffde97..0f600a4a 100644 --- a/src/libnm-client-impl/tests/test-libnm.c +++ b/src/libnm-client-impl/tests/test-libnm.c @@ -2280,18 +2280,18 @@ typedef struct { #define READ_VPN_DETAIL_DATA(...) ((ReadVpnDetailData[]){__VA_ARGS__}) static gboolean -_do_read_vpn_details_impl1(const char * file, +_do_read_vpn_details_impl1(const char *file, int line, int memfd, - char * mem, + char *mem, gsize len, const ReadVpnDetailData *expected_data, guint expected_data_len, const ReadVpnDetailData *expected_secrets, guint expected_secrets_len) { - gssize written; - off_t lseeked; + gssize written; + off_t lseeked; gs_unref_hashtable GHashTable *data = NULL; gs_unref_hashtable GHashTable *secrets = NULL; @@ -2312,11 +2312,11 @@ _do_read_vpn_details_impl1(const char * file, #define _assert_hash(hash, expected, expected_len) \ G_STMT_START \ { \ - GHashTable * _hash = (hash); \ + GHashTable *_hash = (hash); \ guint _expected_len = (expected_len); \ const ReadVpnDetailData *_expected = (expected); \ GHashTableIter _iter; \ - const char * _k, *_v; \ + const char *_k, *_v; \ guint _i; \ \ g_assert(_hash); \ @@ -2759,7 +2759,7 @@ test_types(void) for (i_type = 0; i_type < G_N_ELEMENTS(get_type_fcns); i_type++) { nm_auto_unref_gtypeclass GObjectClass *klass_unref = NULL; GType gtype = (get_type_fcns[i_type])(); - GObjectClass * klass; + GObjectClass *klass; g_assert(g_str_has_prefix(g_type_name(gtype), "NM")); @@ -2803,16 +2803,16 @@ test_types(void) static void test_nml_dbus_meta(void) { - const NMLDBusMetaIface * meta_iface; + const NMLDBusMetaIface *meta_iface; const NMLDBusMetaProperty *meta_property; guint prop_idx; gsize i, j; guint l, m; for (i = 0; i < G_N_ELEMENTS(_nml_dbus_meta_ifaces); i++) { - const NMLDBusMetaIface * mif = _nml_dbus_meta_ifaces[i]; + const NMLDBusMetaIface *mif = _nml_dbus_meta_ifaces[i]; nm_auto_unref_gtypeclass GObjectClass *klass_unref = NULL; - GObjectClass * klass; + GObjectClass *klass; GType gtype; #define COMMON_PREFIX "org.freedesktop.NetworkManager" @@ -3004,7 +3004,7 @@ test_nml_dbus_meta(void) check_dbus_properties: for (l = 0; l < mif->n_dbus_properties; l++) { const NMLDBusMetaProperty *mpr = &mif->dbus_properties[l]; - gs_free char * obj_property_name = NULL; + gs_free char *obj_property_name = NULL; const struct { const char *dbus_type; GType default_gtype; @@ -3218,7 +3218,7 @@ static void test_dbus_meta_types(void) { struct list_data { - const char * dbus_iface_name; + const char *dbus_iface_name; GType gtype; NMLDBusMetaInteracePrio interface_prio; } list[] = { @@ -3464,8 +3464,8 @@ test_nm_auth_permissions(void) for (i = 1; i < NM_CLIENT_PERMISSION_LAST; i++) { NMClientPermission a = nm_auth_permission_sorted[i - 1]; NMClientPermission b = nm_auth_permission_sorted[i]; - const char * s_a = nm_auth_permission_names_by_idx[a - 1]; - const char * s_b = nm_auth_permission_names_by_idx[b - 1]; + const char *s_a = nm_auth_permission_names_by_idx[a - 1]; + const char *s_b = nm_auth_permission_names_by_idx[b - 1]; g_assert_cmpstr(s_a, <, s_b); g_assert(a != b); diff --git a/src/libnm-client-impl/tests/test-nm-client.c b/src/libnm-client-impl/tests/test-nm-client.c index a3fc5847..a43e98cd 100644 --- a/src/libnm-client-impl/tests/test-nm-client.c +++ b/src/libnm-client-impl/tests/test-nm-client.c @@ -28,9 +28,9 @@ loop_quit(gpointer user_data) static void devices_notify_cb(NMClient *c, GParamSpec *pspec, gpointer user_data) { - gboolean * notified = user_data; + gboolean *notified = user_data; const GPtrArray *devices; - NMDevice * device; + NMDevice *device; devices = nm_client_get_devices(c); g_assert(devices); @@ -46,12 +46,12 @@ devices_notify_cb(NMClient *c, GParamSpec *pspec, gpointer user_data) static void test_device_added(void) { - nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL; - gs_unref_object NMClient *client = NULL; - const GPtrArray * devices; - NMDevice * device; - gboolean notified = FALSE; - GError * error = NULL; + nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL; + gs_unref_object NMClient *client = NULL; + const GPtrArray *devices; + NMDevice *device; + gboolean notified = FALSE; + GError *error = NULL; sinfo = nmtstc_service_init(); if (!nmtstc_service_available(sinfo)) @@ -113,9 +113,9 @@ device_sai_added_cb(NMClient *c, NMDevice *device, gpointer user_data) static void devices_sai_notify_cb(NMClient *c, GParamSpec *pspec, gpointer user_data) { - guint * result = user_data; + guint *result = user_data; const GPtrArray *devices; - NMDevice * device; + NMDevice *device; g_assert_cmpstr(pspec->name, ==, "devices"); @@ -134,11 +134,11 @@ devices_sai_notify_cb(NMClient *c, GParamSpec *pspec, gpointer user_data) static void test_device_added_signal_after_init(void) { - nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL; - gs_unref_object NMClient *client = NULL; - const GPtrArray * devices; - NMDevice * device; - guint result = 0; + nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL; + gs_unref_object NMClient *client = NULL; + const GPtrArray *devices; + NMDevice *device; + guint result = 0; sinfo = nmtstc_service_init(); if (!nmtstc_service_available(sinfo)) @@ -187,7 +187,7 @@ static const char *expected_bssid = "66:55:44:33:22:11"; typedef struct { GMainLoop *loop; gboolean found; - char * ap_path; + char *ap_path; gboolean signaled; gboolean notified; guint quit_id; @@ -229,7 +229,7 @@ static void wifi_ap_add_notify_cb(NMDeviceWifi *w, GParamSpec *pspec, WifiApInfo *info) { const GPtrArray *aps; - NMAccessPoint * ap; + NMAccessPoint *ap; aps = nm_device_wifi_get_access_points(w); g_assert(aps); @@ -269,13 +269,13 @@ wifi_ap_remove_notify_cb(NMDeviceWifi *w, GParamSpec *pspec, WifiApInfo *info) static void test_wifi_ap_added_removed(void) { - nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL; - gs_unref_object NMClient *client = NULL; - NMDeviceWifi * wifi; - WifiApInfo info = {gl.loop, FALSE, FALSE, 0, 0}; - GVariant * ret; - GError * error = NULL; - gs_free char * expected_path = NULL; + nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL; + gs_unref_object NMClient *client = NULL; + NMDeviceWifi *wifi; + WifiApInfo info = {gl.loop, FALSE, FALSE, 0, 0}; + GVariant *ret; + GError *error = NULL; + gs_free char *expected_path = NULL; sinfo = nmtstc_service_init(); if (!nmtstc_service_available(sinfo)) @@ -391,9 +391,9 @@ static void da_devices_notify_cb(NMClient *c, GParamSpec *pspec, DaInfo *info) { const GPtrArray *devices; - NMDevice * device; + NMDevice *device; guint i; - const char * iface; + const char *iface; devices = nm_client_get_devices(c); g_assert(devices); @@ -413,13 +413,13 @@ da_devices_notify_cb(NMClient *c, GParamSpec *pspec, DaInfo *info) static void test_devices_array(void) { - nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL; - gs_unref_object NMClient *client = NULL; - DaInfo info = {gl.loop}; - NMDevice * wlan0, *eth0, *eth1, *device; - const GPtrArray * devices; - GError * error = NULL; - GVariant * ret; + nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL; + gs_unref_object NMClient *client = NULL; + DaInfo info = {gl.loop}; + NMDevice *wlan0, *eth0, *eth1, *device; + const GPtrArray *devices; + GError *error = NULL; + GVariant *ret; sinfo = nmtstc_service_init(); if (!nmtstc_service_available(sinfo)) @@ -502,12 +502,12 @@ nm_running_changed(GObject *client, GParamSpec *pspec, gpointer user_data) static void test_client_nm_running(void) { - nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL; - gs_unref_object NMClient *client1 = NULL; - gs_unref_object NMClient *client2 = NULL; - guint quit_id; - int running_changed = 0; - GError * error = NULL; + nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL; + gs_unref_object NMClient *client1 = NULL; + gs_unref_object NMClient *client2 = NULL; + guint quit_id; + int running_changed = 0; + GError *error = NULL; client1 = nmtstc_client_new(TRUE); @@ -560,7 +560,7 @@ test_client_nm_running(void) } typedef struct { - GMainLoop * loop; + GMainLoop *loop; NMActiveConnection *ac; int remaining; @@ -572,8 +572,8 @@ typedef struct { static void assert_ac_and_device(NMClient *client) { - const GPtrArray * devices, *acs, *ac_devices; - NMDevice * device, *ac_device; + const GPtrArray *devices, *acs, *ac_devices; + NMDevice *device, *ac_device; NMActiveConnection *ac, *device_ac; acs = nm_client_get_active_connections(client); @@ -614,9 +614,9 @@ assert_ac_and_device(NMClient *client) static void add_and_activate_cb(GObject *object, GAsyncResult *result, gpointer user_data) { - NMClient * client = NM_CLIENT(object); + NMClient *client = NM_CLIENT(object); TestACInfo *info = user_data; - GError * error = NULL; + GError *error = NULL; info->ac = nm_client_add_and_activate_connection_finish(client, result, &error); g_assert_no_error(error); @@ -632,7 +632,7 @@ add_and_activate_cb(GObject *object, GAsyncResult *result, gpointer user_data) static void client_acs_changed_cb(GObject *client, GParamSpec *pspec, gpointer user_data) { - TestACInfo * info = user_data; + TestACInfo *info = user_data; const GPtrArray *acs; acs = nm_client_get_active_connections(NM_CLIENT(client)); @@ -659,11 +659,11 @@ device_ac_changed_cb(GObject *device, GParamSpec *pspec, gpointer user_data) static void test_active_connections(void) { - nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL; - gs_unref_object NMClient *client = NULL; - NMDevice * device; - NMConnection * conn; - TestACInfo info = {gl.loop, NULL, 0}; + nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL; + gs_unref_object NMClient *client = NULL; + NMDevice *device; + NMConnection *conn; + TestACInfo info = {gl.loop, NULL, 0}; sinfo = nmtstc_service_init(); if (!nmtstc_service_available(sinfo)) @@ -719,9 +719,9 @@ test_active_connections(void) static void client_devices_changed_cb(GObject *client, GParamSpec *pspec, gpointer user_data) { - TestACInfo * info = user_data; + TestACInfo *info = user_data; const GPtrArray *devices; - NMDevice * device; + NMDevice *device; devices = nm_client_get_devices(NM_CLIENT(client)); g_assert(devices != NULL); @@ -755,7 +755,7 @@ client_devices_changed_cb(GObject *client, GParamSpec *pspec, gpointer user_data } typedef struct { - GMainLoop * loop; + GMainLoop *loop; NMRemoteConnection *remote; } TestConnectionInfo; @@ -763,7 +763,7 @@ static void add_connection_cb(GObject *object, GAsyncResult *result, gpointer user_data) { TestConnectionInfo *info = user_data; - GError * error = NULL; + GError *error = NULL; info->remote = nm_client_add_connection_finish(NM_CLIENT(object), result, &error); g_assert_no_error(error); @@ -773,9 +773,9 @@ add_connection_cb(GObject *object, GAsyncResult *result, gpointer user_data) static void activate_cb(GObject *object, GAsyncResult *result, gpointer user_data) { - NMClient * client = NM_CLIENT(object); + NMClient *client = NM_CLIENT(object); TestACInfo *info = user_data; - GError * error = NULL; + GError *error = NULL; info->ac = nm_client_activate_connection_finish(client, result, &error); g_assert_no_error(error); @@ -788,16 +788,46 @@ activate_cb(GObject *object, GAsyncResult *result, gpointer user_data) g_main_loop_quit(info->loop); } +static void +_dev_eth0_1_state_changed_cb(NMDevice *device, + NMDeviceState new_state, + NMDeviceState old_state, + NMDeviceStateReason reason, + int *p_count_call) +{ + const GPtrArray *arr; + + g_assert(p_count_call); + g_assert_cmpint(*p_count_call, ==, 0); + + (*p_count_call)++; + + g_assert(NM_IS_DEVICE_VLAN(device)); + + g_assert_cmpint(old_state, >=, NM_DEVICE_STATE_PREPARE); + g_assert_cmpint(old_state, <=, NM_DEVICE_STATE_ACTIVATED); + g_assert_cmpint(new_state, ==, NM_DEVICE_STATE_UNKNOWN); + + arr = nm_device_get_available_connections(device); + g_assert(arr); + g_assert_cmpint(arr->len, ==, 0); + + g_assert(!nm_device_get_active_connection(device)); +} + static void test_activate_virtual(void) { - nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL; - gs_unref_object NMClient *client = NULL; - NMConnection * conn; - NMSettingConnection * s_con; - NMSettingVlan * s_vlan; - TestACInfo info = {gl.loop, NULL, 0}; - TestConnectionInfo conn_info = {gl.loop, NULL}; + nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL; + gs_unref_object NMClient *client = NULL; + NMConnection *conn; + NMSettingConnection *s_con; + NMSettingVlan *s_vlan; + TestACInfo info = {gl.loop, NULL, 0}; + TestConnectionInfo conn_info = {gl.loop, NULL}; + + if (nmtst_test_skip_slow()) + return; sinfo = nmtstc_service_init(); if (!nmtstc_service_available(sinfo)) @@ -847,23 +877,74 @@ test_activate_virtual(void) g_object_remove_weak_pointer(G_OBJECT(info.device), (gpointer *) &info.device); nm_clear_g_signal_handler(info.device, &info.ac_signal_id); } + + if (nmtst_get_rand_bool()) { + /* OK, enough for this run. Let's see whether we can tear down + * successfully at this point. */ + return; + } + + { + NMDevice *dev_eth0_1; + NMActiveConnection *ac; + const GPtrArray *arr; + gulong sig_id; + int call_count = 0; + gboolean take_ref = nmtst_get_rand_bool(); + + /* ensure we got all the necessary events in place. */ + nmtst_main_loop_run(gl.loop, 50); + + dev_eth0_1 = nm_client_get_device_by_iface(client, "eth0.1"); + g_assert(NM_IS_DEVICE_VLAN(dev_eth0_1)); + if (take_ref) + g_object_ref(dev_eth0_1); + + arr = nm_device_get_available_connections(dev_eth0_1); + g_assert(arr); + g_assert_cmpint(arr->len, ==, 1); + + ac = nm_device_get_active_connection(dev_eth0_1); + g_assert(NM_IS_ACTIVE_CONNECTION(ac)); + + sig_id = g_signal_connect(dev_eth0_1, + "state-changed", + G_CALLBACK(_dev_eth0_1_state_changed_cb), + &call_count); + + g_clear_object(&client); + + g_assert_cmpint(call_count, ==, 1); + + if (take_ref) { + arr = nm_device_get_available_connections(dev_eth0_1); + g_assert(arr); + g_assert_cmpint(arr->len, ==, 0); + + g_assert(!nm_device_get_active_connection(dev_eth0_1)); + + nm_clear_g_signal_handler(dev_eth0_1, &sig_id); + + g_object_unref(dev_eth0_1); + } + } } static void test_device_connection_compatibility(void) { - nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL; - gs_unref_object NMClient *client = NULL; - gs_unref_object NMConnection *conn = NULL; - NMDevice * device1; - NMDevice * device2; - NMSettingWired * s_wired; - GError * error = NULL; - const char * subchannels[] = {"0.0.8000", "0.0.8001", "0.0.8002", NULL}; - const char * subchannels_2[] = {"0.0.8000", "0.0.8001", NULL}; - const char * subchannels_x[] = {"0.0.8000", "0.0.8001", "0.0.800X", NULL}; - const char * hw_addr1 = "52:54:00:ab:db:23"; - const char * hw_addr2 = "52:54:00:ab:db:24"; + nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL; + gs_unref_object NMClient *client = NULL; + gs_unref_object NMConnection *conn = NULL; + NMDevice *device1; + NMDevice *device2; + NMSettingWired *s_wired; + GError *error = NULL; + const char *subchannels[] = {"0.0.8000", "0.0.8001", "0.0.8002", NULL}; + const char *subchannels_2[] = {"0.0.8000", "0.0.8001", NULL}; + const char *subchannels_x[] = {"0.0.8000", "0.0.8001", "0.0.800X", NULL}; + const char *hw_addr1 = "52:54:00:ab:db:23"; + const char *hw_addr2 = "52:54:00:ab:db:24"; sinfo = nmtstc_service_init(); if (!nmtstc_service_available(sinfo)) @@ -927,7 +1008,7 @@ static gboolean _test_connection_invalid_find_connections(gpointer element, gpointer needle, gpointer user_data) { NMRemoteConnection *con = NM_REMOTE_CONNECTION(element); - const char * path = needle; + const char *path = needle; g_assert(NM_IS_REMOTE_CONNECTION(con)); g_assert(path && *path); @@ -950,17 +1031,17 @@ test_connection_invalid(void) { NMTSTC_SERVICE_INFO_SETUP(my_sinfo); gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - gs_unref_object NMClient *client = NULL; - const GPtrArray * connections; - gs_free char * path0 = NULL; - gs_free char * path1 = NULL; - gs_free char * path2 = NULL; - gs_free char * path3 = NULL; - gs_free char * uuid2 = NULL; - gsize n_found; - gssize idx[4]; - gs_unref_variant GVariant *variant = NULL; + NMSettingConnection *s_con; + gs_unref_object NMClient *client = NULL; + const GPtrArray *connections; + gs_free char *path0 = NULL; + gs_free char *path1 = NULL; + gs_free char *path2 = NULL; + gs_free char *path3 = NULL; + gs_free char *uuid2 = NULL; + gsize n_found; + gssize idx[4]; + gs_unref_variant GVariant *variant = NULL; g_assert(g_main_loop_get_context(gl.loop) == (g_main_context_get_thread_default() ?: g_main_context_default())); diff --git a/src/libnm-client-impl/tests/test-remote-settings-client.c b/src/libnm-client-impl/tests/test-remote-settings-client.c index e5415f54..7e4872e9 100644 --- a/src/libnm-client-impl/tests/test-remote-settings-client.c +++ b/src/libnm-client-impl/tests/test-remote-settings-client.c @@ -13,9 +13,9 @@ #include "libnm-client-test/nm-test-libnm-utils.h" static struct { - NMTstcServiceInfo * sinfo; - NMClient * client; - GDBusConnection * bus; + NMTstcServiceInfo *sinfo; + NMClient *client; + GDBusConnection *bus; NMRemoteConnection *remote; } gl = {}; @@ -25,7 +25,7 @@ static void add_cb(GObject *s, GAsyncResult *result, gpointer user_data) { gboolean *done = user_data; - GError * error = NULL; + GError *error = NULL; gl.remote = nm_client_add_connection_finish(gl.client, result, &error); g_assert_no_error(error); @@ -72,7 +72,7 @@ test_add_connection(void) static void set_visible_cb(GObject *proxy, GAsyncResult *result, gpointer user_data) { - GError * error = NULL; + GError *error = NULL; GVariant *ret; ret = g_dbus_proxy_call_finish(G_DBUS_PROXY(proxy), result, &error); @@ -95,8 +95,8 @@ connection_removed_cb(NMClient *s, NMRemoteConnection *connection, gboolean *don } static void -invis_has_settings_cb(NMSetting * setting, - const char * key, +invis_has_settings_cb(NMSetting *setting, + const char *key, const GValue *value, GParamFlags flags, gpointer user_data) @@ -109,10 +109,10 @@ test_make_invisible(void) { const GPtrArray *conns; int i; - GDBusProxy * proxy; + GDBusProxy *proxy; gboolean visible_changed = FALSE, connection_removed = FALSE; gboolean has_settings = FALSE; - char * path; + char *path; if (!nmtstc_service_available(gl.sinfo)) return; @@ -193,9 +193,9 @@ test_make_visible(void) { const GPtrArray *conns; int i; - GDBusProxy * proxy; + GDBusProxy *proxy; gboolean found = FALSE; - char * path; + char *path; NMRemoteConnection *new = NULL; if (!nmtstc_service_available(gl.sinfo)) @@ -261,7 +261,7 @@ test_make_visible(void) static void deleted_cb(GObject *proxy, GAsyncResult *result, gpointer user_data) { - GError * error = NULL; + GError *error = NULL; GVariant *ret; ret = g_dbus_proxy_call_finish(G_DBUS_PROXY(proxy), result, &error); @@ -280,11 +280,11 @@ static void test_remove_connection(void) { NMRemoteConnection *connection; - const GPtrArray * conns; + const GPtrArray *conns; int i; - GDBusProxy * proxy; + GDBusProxy *proxy; gboolean done = FALSE; - char * path; + char *path; if (!nmtstc_service_available(gl.sinfo)) return; @@ -334,8 +334,8 @@ test_remove_connection(void) static void add_remove_cb(GObject *s, GAsyncResult *result, gpointer user_data) { - NMRemoteConnection *connection; - gboolean * done = user_data; + NMRemoteConnection *connection; + gboolean *done = user_data; gs_free_error GError *error = NULL; connection = nm_client_add_connection_finish(gl.client, result, &error); @@ -348,8 +348,8 @@ add_remove_cb(GObject *s, GAsyncResult *result, gpointer user_data) static void test_add_remove_connection(void) { - gs_unref_variant GVariant *ret = NULL; - GError * error = NULL; + gs_unref_variant GVariant *ret = NULL; + GError *error = NULL; gs_unref_object NMConnection *connection = NULL; gboolean done = FALSE; @@ -382,7 +382,7 @@ test_add_remove_connection(void) static void add_bad_cb(GObject *s, GAsyncResult *result, gpointer user_data) { - gboolean * done = user_data; + gboolean *done = user_data; gs_free_error GError *error = NULL; gl.remote = nm_client_add_connection_finish(gl.client, result, &error); @@ -418,7 +418,7 @@ test_add_bad_connection(void) static void save_hostname_cb(GObject *s, GAsyncResult *result, gpointer user_data) { - gboolean * done = user_data; + gboolean *done = user_data; gs_free_error GError *error = NULL; nm_client_save_hostname_finish(gl.client, result, &error); @@ -432,7 +432,7 @@ test_save_hostname(void) { gint64 until_ts; gboolean done = FALSE; - GError * error = NULL; + GError *error = NULL; if (!nmtstc_service_available(gl.sinfo)) return; diff --git a/src/libnm-client-impl/tests/test-secret-agent.c b/src/libnm-client-impl/tests/test-secret-agent.c index 8f758f3d..1fffb556 100644 --- a/src/libnm-client-impl/tests/test-secret-agent.c +++ b/src/libnm-client-impl/tests/test-secret-agent.c @@ -29,20 +29,20 @@ GType test_secret_agent_get_type(void); G_DEFINE_TYPE(TestSecretAgent, test_secret_agent, NM_TYPE_SECRET_AGENT_OLD) static void -test_secret_agent_get_secrets(NMSecretAgentOld * agent, - NMConnection * connection, - const char * connection_path, - const char * setting_name, - const char ** hints, +test_secret_agent_get_secrets(NMSecretAgentOld *agent, + NMConnection *connection, + const char *connection_path, + const char *setting_name, + const char **hints, NMSecretAgentGetSecretsFlags flags, NMSecretAgentOldGetSecretsFunc callback, gpointer callback_data) { NMSettingWirelessSecurity *s_wsec; - GVariant * secrets = NULL; + GVariant *secrets = NULL; GVariantBuilder secrets_builder, setting_builder; - char * secret = NULL; - GError * error = NULL; + char *secret = NULL; + GError *error = NULL; g_assert_cmpstr(setting_name, ==, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); @@ -91,16 +91,16 @@ done: static void test_secret_agent_cancel_get_secrets(NMSecretAgentOld *agent, - const char * connection_path, - const char * setting_name) + const char *connection_path, + const char *setting_name) { g_assert_not_reached(); } static void -test_secret_agent_save_secrets(NMSecretAgentOld * agent, - NMConnection * connection, - const char * connection_path, +test_secret_agent_save_secrets(NMSecretAgentOld *agent, + NMConnection *connection, + const char *connection_path, NMSecretAgentOldSaveSecretsFunc callback, gpointer callback_data) { @@ -108,9 +108,9 @@ test_secret_agent_save_secrets(NMSecretAgentOld * agent, } static void -test_secret_agent_delete_secrets(NMSecretAgentOld * agent, - NMConnection * connection, - const char * connection_path, +test_secret_agent_delete_secrets(NMSecretAgentOld *agent, + NMConnection *connection, + const char *connection_path, NMSecretAgentOldDeleteSecretsFunc callback, gpointer callback_data) { @@ -136,7 +136,7 @@ test_secret_agent_new(gboolean auto_register) static void test_secret_agent_class_init(TestSecretAgentClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSecretAgentOldClass *agent_class = NM_SECRET_AGENT_OLD_CLASS(klass); agent_class->get_secrets = test_secret_agent_get_secrets; @@ -163,14 +163,14 @@ test_secret_agent_class_init(TestSecretAgentClass *klass) typedef struct { NMTstcServiceInfo *sinfo; - NMClient * client; + NMClient *client; NMSecretAgentOld *agent; - NMDevice * device; - NMConnection * connection; + NMDevice *device; + NMConnection *connection; GMainLoop *loop; - GSource * timeout_source; + GSource *timeout_source; char *ifname; char *con_id; @@ -182,8 +182,8 @@ static void connection_added_cb(GObject *s, GAsyncResult *result, gpointer user_data) { TestSecretAgentData *sadata = user_data; - NMRemoteConnection * connection; - GError * error = NULL; + NMRemoteConnection *connection; + GError *error = NULL; connection = nm_client_add_connection_finish(sadata->client, result, &error); @@ -198,7 +198,7 @@ static void register_cb(GObject *object, GAsyncResult *result, gpointer user_data) { TestSecretAgentData *sadata = user_data; - GError * error = NULL; + GError *error = NULL; nm_secret_agent_old_register_finish(sadata->agent, result, &error); g_assert_no_error(error); @@ -212,14 +212,14 @@ register_cb(GObject *object, GAsyncResult *result, gpointer user_data) static void test_setup(TestSecretAgentData *sadata, gconstpointer test_data) { - static int static_counter = 0; - const int counter = static_counter++; - const char * create_agent = test_data; - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingWireless * s_wireless; - GBytes * ssid; - NMSetting * s_wsec; + static int static_counter = 0; + const int counter = static_counter++; + const char *create_agent = test_data; + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingWireless *s_wireless; + GBytes *ssid; + NMSetting *s_wsec; gs_free_error GError *error = NULL; sadata->sinfo = nmtstc_service_init(); @@ -296,8 +296,8 @@ test_setup(TestSecretAgentData *sadata, gconstpointer test_data) static void test_cleanup(TestSecretAgentData *sadata, gconstpointer test_data) { - GVariant * ret; - GError * error = NULL; + GVariant *ret; + GError *error = NULL; NMTstContextBusyWatcherData watcher_data = {}; g_assert(nm_g_main_context_is_thread_default(NULL)); @@ -358,8 +358,8 @@ test_cleanup(TestSecretAgentData *sadata, gconstpointer test_data) static void connection_activated_none_cb(GObject *c, GAsyncResult *result, gpointer user_data) { - TestSecretAgentData *sadata = user_data; - gs_free_error GError *error = NULL; + TestSecretAgentData *sadata = user_data; + gs_free_error GError *error = NULL; nm_client_activate_connection_finish(sadata->client, result, &error); g_assert_error(error, NM_AGENT_MANAGER_ERROR, NM_AGENT_MANAGER_ERROR_NO_SECRETS); @@ -387,10 +387,10 @@ test_secret_agent_none(TestSecretAgentData *sadata, gconstpointer test_data) static char * secrets_requested_no_secrets_cb(TestSecretAgent *agent, - NMConnection * connection, - const char * connection_path, - const char * setting_name, - const char * secret_name, + NMConnection *connection, + const char *connection_path, + const char *setting_name, + const char *secret_name, gpointer user_data) { TestSecretAgentData *sadata = user_data; @@ -404,9 +404,9 @@ secrets_requested_no_secrets_cb(TestSecretAgent *agent, static void connection_activated_no_secrets_cb(GObject *c, GAsyncResult *result, gpointer user_data) { - TestSecretAgentData *sadata = user_data; - gs_unref_object NMActiveConnection *ac = NULL; - gs_free_error GError *error = NULL; + TestSecretAgentData *sadata = user_data; + gs_unref_object NMActiveConnection *ac = NULL; + gs_free_error GError *error = NULL; ac = nm_client_activate_connection_finish(sadata->client, result, &error); g_assert_error(error, NM_AGENT_MANAGER_ERROR, NM_AGENT_MANAGER_ERROR_NO_SECRETS); @@ -441,9 +441,9 @@ test_secret_agent_no_secrets(TestSecretAgentData *sadata, gconstpointer test_dat static void connection_activated_cancel_cb(GObject *c, GAsyncResult *result, gpointer user_data) { - TestSecretAgentData *sadata = user_data; - gs_unref_object NMActiveConnection *ac = NULL; - gs_free_error GError *error = NULL; + TestSecretAgentData *sadata = user_data; + gs_unref_object NMActiveConnection *ac = NULL; + gs_free_error GError *error = NULL; ac = nm_client_activate_connection_finish(sadata->client, result, &error); g_assert_error(error, NM_AGENT_MANAGER_ERROR, NM_AGENT_MANAGER_ERROR_USER_CANCELED); @@ -452,10 +452,10 @@ connection_activated_cancel_cb(GObject *c, GAsyncResult *result, gpointer user_d static char * secrets_requested_cancel_cb(TestSecretAgent *agent, - NMConnection * connection, - const char * connection_path, - const char * setting_name, - const char * secret_name, + NMConnection *connection, + const char *connection_path, + const char *setting_name, + const char *secret_name, gpointer user_data) { TestSecretAgentData *sadata = user_data; @@ -495,8 +495,8 @@ static void connection_activated_good_cb(GObject *c, GAsyncResult *result, gpointer user_data) { TestSecretAgentData *sadata = user_data; - NMActiveConnection * ac; - GError * error = NULL; + NMActiveConnection *ac; + GError *error = NULL; ac = nm_client_activate_connection_finish(sadata->client, result, &error); g_assert_no_error(error); @@ -508,10 +508,10 @@ connection_activated_good_cb(GObject *c, GAsyncResult *result, gpointer user_dat static char * secrets_requested_good_cb(TestSecretAgent *agent, - NMConnection * connection, - const char * connection_path, - const char * setting_name, - const char * secret_name, + NMConnection *connection, + const char *connection_path, + const char *setting_name, + const char *secret_name, gpointer user_data) { TestSecretAgentData *sadata = user_data; @@ -550,8 +550,8 @@ test_secret_agent_good(TestSecretAgentData *sadata, gconstpointer test_data) static void async_init_cb(GObject *object, GAsyncResult *result, gpointer user_data) { - GMainLoop * loop = user_data; - gs_free_error GError *error = NULL; + GMainLoop *loop = user_data; + gs_free_error GError *error = NULL; gs_unref_object GObject *agent = NULL; agent = g_async_initable_new_finish(G_ASYNC_INITABLE(object), result, &error); @@ -564,9 +564,9 @@ async_init_cb(GObject *object, GAsyncResult *result, gpointer user_data) static void test_secret_agent_nm_not_running(void) { - gs_unref_object NMSecretAgentOld *agent = NULL; + gs_unref_object NMSecretAgentOld *agent = NULL; nm_auto_unref_gmainloop GMainLoop *loop = NULL; - GError * error = NULL; + GError *error = NULL; agent = g_initable_new(test_secret_agent_get_type(), NULL, @@ -626,12 +626,12 @@ registered_changed(GObject *object, GParamSpec *pspec, gpointer user_data) static void test_secret_agent_auto_register(void) { - NMTstcServiceInfo *sinfo; + NMTstcServiceInfo *sinfo; gs_unref_object NMSecretAgentOld *agent = NULL; - GError * error = NULL; + GError *error = NULL; AutoRegisterData auto_register_data = { - .step = 0, - .invoke_count = 0, + .step = 0, + .invoke_count = 0, }; gulong signal_id; NMTstContextBusyWatcherData watcher_data = {}; diff --git a/src/libnm-client-public/nm-access-point.h b/src/libnm-client-public/nm-access-point.h index 50a74296..9f9216bb 100644 --- a/src/libnm-client-public/nm-access-point.h +++ b/src/libnm-client-public/nm-access-point.h @@ -49,8 +49,8 @@ GType nm_access_point_get_type(void); NM80211ApFlags nm_access_point_get_flags(NMAccessPoint *ap); NM80211ApSecurityFlags nm_access_point_get_wpa_flags(NMAccessPoint *ap); NM80211ApSecurityFlags nm_access_point_get_rsn_flags(NMAccessPoint *ap); -GBytes * nm_access_point_get_ssid(NMAccessPoint *ap); -const char * nm_access_point_get_bssid(NMAccessPoint *ap); +GBytes *nm_access_point_get_ssid(NMAccessPoint *ap); +const char *nm_access_point_get_bssid(NMAccessPoint *ap); guint32 nm_access_point_get_frequency(NMAccessPoint *ap); NM80211Mode nm_access_point_get_mode(NMAccessPoint *ap); guint32 nm_access_point_get_max_bitrate(NMAccessPoint *ap); diff --git a/src/libnm-client-public/nm-active-connection.h b/src/libnm-client-public/nm-active-connection.h index 76ea107a..a65b4f20 100644 --- a/src/libnm-client-public/nm-active-connection.h +++ b/src/libnm-client-public/nm-active-connection.h @@ -51,23 +51,23 @@ typedef struct _NMActiveConnectionClass NMActiveConnectionClass; GType nm_active_connection_get_type(void); NMRemoteConnection *nm_active_connection_get_connection(NMActiveConnection *connection); -const char * nm_active_connection_get_id(NMActiveConnection *connection); -const char * nm_active_connection_get_uuid(NMActiveConnection *connection); -const char * nm_active_connection_get_connection_type(NMActiveConnection *connection); -const char * nm_active_connection_get_specific_object_path(NMActiveConnection *connection); -const GPtrArray * nm_active_connection_get_devices(NMActiveConnection *connection); +const char *nm_active_connection_get_id(NMActiveConnection *connection); +const char *nm_active_connection_get_uuid(NMActiveConnection *connection); +const char *nm_active_connection_get_connection_type(NMActiveConnection *connection); +const char *nm_active_connection_get_specific_object_path(NMActiveConnection *connection); +const GPtrArray *nm_active_connection_get_devices(NMActiveConnection *connection); NMActiveConnectionState nm_active_connection_get_state(NMActiveConnection *connection); NM_AVAILABLE_IN_1_10 NMActivationStateFlags nm_active_connection_get_state_flags(NMActiveConnection *connection); NM_AVAILABLE_IN_1_8 NMActiveConnectionStateReason nm_active_connection_get_state_reason(NMActiveConnection *connection); -NMDevice * nm_active_connection_get_master(NMActiveConnection *connection); +NMDevice *nm_active_connection_get_master(NMActiveConnection *connection); gboolean nm_active_connection_get_default(NMActiveConnection *connection); -NMIPConfig * nm_active_connection_get_ip4_config(NMActiveConnection *connection); -NMDhcpConfig * nm_active_connection_get_dhcp4_config(NMActiveConnection *connection); +NMIPConfig *nm_active_connection_get_ip4_config(NMActiveConnection *connection); +NMDhcpConfig *nm_active_connection_get_dhcp4_config(NMActiveConnection *connection); gboolean nm_active_connection_get_default6(NMActiveConnection *connection); -NMIPConfig * nm_active_connection_get_ip6_config(NMActiveConnection *connection); -NMDhcpConfig * nm_active_connection_get_dhcp6_config(NMActiveConnection *connection); +NMIPConfig *nm_active_connection_get_ip6_config(NMActiveConnection *connection); +NMDhcpConfig *nm_active_connection_get_dhcp6_config(NMActiveConnection *connection); gboolean nm_active_connection_get_vpn(NMActiveConnection *connection); G_END_DECLS diff --git a/src/libnm-client-public/nm-client.h b/src/libnm-client-public/nm-client.h index 02c8ee33..ac615b57 100644 --- a/src/libnm-client-public/nm-client.h +++ b/src/libnm-client-public/nm-client.h @@ -233,7 +233,7 @@ _NM_DEPRECATED_SYNC_METHOD gboolean nm_client_set_logging(NMClient *client, const char *level, const char *domains, GError **error); -NMClientPermissionResult nm_client_get_permission_result(NMClient * client, +NMClientPermissionResult nm_client_get_permission_result(NMClient *client, NMClientPermission permission); NM_AVAILABLE_IN_1_24 @@ -246,22 +246,22 @@ NM_DEPRECATED_IN_1_22 NMConnectivityState nm_client_check_connectivity(NMClient *client, GCancellable *cancellable, GError **error); -void nm_client_check_connectivity_async(NMClient * client, - GCancellable * cancellable, +void nm_client_check_connectivity_async(NMClient *client, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); NMConnectivityState nm_client_check_connectivity_finish(NMClient *client, GAsyncResult *result, GError **error); _NM_DEPRECATED_SYNC_METHOD -gboolean nm_client_save_hostname(NMClient * client, - const char * hostname, +gboolean nm_client_save_hostname(NMClient *client, + const char *hostname, GCancellable *cancellable, - GError ** error); + GError **error); -void nm_client_save_hostname_async(NMClient * client, - const char * hostname, - GCancellable * cancellable, +void nm_client_save_hostname_async(NMClient *client, + const char *hostname, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean nm_client_save_hostname_finish(NMClient *client, GAsyncResult *result, GError **error); @@ -271,8 +271,8 @@ gboolean nm_client_save_hostname_finish(NMClient *client, GAsyncResult *result, const GPtrArray *nm_client_get_devices(NMClient *client); NM_AVAILABLE_IN_1_2 const GPtrArray *nm_client_get_all_devices(NMClient *client); -NMDevice * nm_client_get_device_by_path(NMClient *client, const char *object_path); -NMDevice * nm_client_get_device_by_iface(NMClient *client, const char *iface); +NMDevice *nm_client_get_device_by_path(NMClient *client, const char *object_path); +NMDevice *nm_client_get_device_by_iface(NMClient *client, const char *iface); /* Active Connections */ @@ -281,51 +281,51 @@ const GPtrArray *nm_client_get_active_connections(NMClient *client); NMActiveConnection *nm_client_get_primary_connection(NMClient *client); NMActiveConnection *nm_client_get_activating_connection(NMClient *client); -void nm_client_activate_connection_async(NMClient * client, - NMConnection * connection, - NMDevice * device, - const char * specific_object, - GCancellable * cancellable, +void nm_client_activate_connection_async(NMClient *client, + NMConnection *connection, + NMDevice *device, + const char *specific_object, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); NMActiveConnection * nm_client_activate_connection_finish(NMClient *client, GAsyncResult *result, GError **error); -void nm_client_add_and_activate_connection_async(NMClient * client, - NMConnection * partial, - NMDevice * device, - const char * specific_object, - GCancellable * cancellable, +void nm_client_add_and_activate_connection_async(NMClient *client, + NMConnection *partial, + NMDevice *device, + const char *specific_object, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); -NMActiveConnection *nm_client_add_and_activate_connection_finish(NMClient * client, +NMActiveConnection *nm_client_add_and_activate_connection_finish(NMClient *client, GAsyncResult *result, - GError ** error); + GError **error); NM_AVAILABLE_IN_1_16 -void nm_client_add_and_activate_connection2(NMClient * client, - NMConnection * partial, - NMDevice * device, - const char * specific_object, - GVariant * options, - GCancellable * cancellable, +void nm_client_add_and_activate_connection2(NMClient *client, + NMConnection *partial, + NMDevice *device, + const char *specific_object, + GVariant *options, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); NM_AVAILABLE_IN_1_16 -NMActiveConnection *nm_client_add_and_activate_connection2_finish(NMClient * client, +NMActiveConnection *nm_client_add_and_activate_connection2_finish(NMClient *client, GAsyncResult *result, - GVariant ** out_result, - GError ** error); + GVariant **out_result, + GError **error); _NM_DEPRECATED_SYNC_METHOD -gboolean nm_client_deactivate_connection(NMClient * client, +gboolean nm_client_deactivate_connection(NMClient *client, NMActiveConnection *active, - GCancellable * cancellable, - GError ** error); + GCancellable *cancellable, + GError **error); -void nm_client_deactivate_connection_async(NMClient * client, +void nm_client_deactivate_connection_async(NMClient *client, NMActiveConnection *active, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean @@ -339,53 +339,53 @@ NMRemoteConnection *nm_client_get_connection_by_id(NMClient *client, const char NMRemoteConnection *nm_client_get_connection_by_path(NMClient *client, const char *path); NMRemoteConnection *nm_client_get_connection_by_uuid(NMClient *client, const char *uuid); -void nm_client_add_connection_async(NMClient * client, - NMConnection * connection, +void nm_client_add_connection_async(NMClient *client, + NMConnection *connection, gboolean save_to_disk, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); NMRemoteConnection * nm_client_add_connection_finish(NMClient *client, GAsyncResult *result, GError **error); NM_AVAILABLE_IN_1_20 -void nm_client_add_connection2(NMClient * client, - GVariant * settings, +void nm_client_add_connection2(NMClient *client, + GVariant *settings, NMSettingsAddConnection2Flags flags, - GVariant * args, + GVariant *args, gboolean ignore_out_result, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); NM_AVAILABLE_IN_1_20 -NMRemoteConnection *nm_client_add_connection2_finish(NMClient * client, +NMRemoteConnection *nm_client_add_connection2_finish(NMClient *client, GAsyncResult *result, - GVariant ** out_result, - GError ** error); + GVariant **out_result, + GError **error); _NM_DEPRECATED_SYNC_METHOD -gboolean nm_client_load_connections(NMClient * client, - char ** filenames, - char *** failures, +gboolean nm_client_load_connections(NMClient *client, + char **filenames, + char ***failures, GCancellable *cancellable, - GError ** error); + GError **error); -void nm_client_load_connections_async(NMClient * client, - char ** filenames, - GCancellable * cancellable, +void nm_client_load_connections_async(NMClient *client, + char **filenames, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); -gboolean nm_client_load_connections_finish(NMClient * client, - char *** failures, +gboolean nm_client_load_connections_finish(NMClient *client, + char ***failures, GAsyncResult *result, - GError ** error); + GError **error); _NM_DEPRECATED_SYNC_METHOD gboolean nm_client_reload_connections(NMClient *client, GCancellable *cancellable, GError **error); -void nm_client_reload_connections_async(NMClient * client, - GCancellable * cancellable, +void nm_client_reload_connections_async(NMClient *client, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean @@ -402,11 +402,11 @@ NM_AVAILABLE_IN_1_12 const GPtrArray *nm_client_get_checkpoints(NMClient *client); NM_AVAILABLE_IN_1_12 -void nm_client_checkpoint_create(NMClient * client, - const GPtrArray * devices, +void nm_client_checkpoint_create(NMClient *client, + const GPtrArray *devices, guint32 rollback_timeout, NMCheckpointCreateFlags flags, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); NM_AVAILABLE_IN_1_12 @@ -414,9 +414,9 @@ NMCheckpoint * nm_client_checkpoint_create_finish(NMClient *client, GAsyncResult *result, GError **error); NM_AVAILABLE_IN_1_12 -void nm_client_checkpoint_destroy(NMClient * client, - const char * checkpoint_path, - GCancellable * cancellable, +void nm_client_checkpoint_destroy(NMClient *client, + const char *checkpoint_path, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); NM_AVAILABLE_IN_1_12 @@ -424,9 +424,9 @@ gboolean nm_client_checkpoint_destroy_finish(NMClient *client, GAsyncResult *result, GError **error); NM_AVAILABLE_IN_1_12 -void nm_client_checkpoint_rollback(NMClient * client, - const char * checkpoint_path, - GCancellable * cancellable, +void nm_client_checkpoint_rollback(NMClient *client, + const char *checkpoint_path, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); NM_AVAILABLE_IN_1_12 @@ -434,22 +434,22 @@ GHashTable * nm_client_checkpoint_rollback_finish(NMClient *client, GAsyncResult *result, GError **error); NM_AVAILABLE_IN_1_12 -void nm_client_checkpoint_adjust_rollback_timeout(NMClient * client, - const char * checkpoint_path, +void nm_client_checkpoint_adjust_rollback_timeout(NMClient *client, + const char *checkpoint_path, guint32 add_timeout, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); NM_AVAILABLE_IN_1_12 -gboolean nm_client_checkpoint_adjust_rollback_timeout_finish(NMClient * client, +gboolean nm_client_checkpoint_adjust_rollback_timeout_finish(NMClient *client, GAsyncResult *result, - GError ** error); + GError **error); NM_AVAILABLE_IN_1_22 -void nm_client_reload(NMClient * client, +void nm_client_reload(NMClient *client, NMManagerReloadFlags flags, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); NM_AVAILABLE_IN_1_22 @@ -458,14 +458,14 @@ gboolean nm_client_reload_finish(NMClient *client, GAsyncResult *result, GError /*****************************************************************************/ NM_AVAILABLE_IN_1_24 -void nm_client_dbus_call(NMClient * client, - const char * object_path, - const char * interface_name, - const char * method_name, - GVariant * parameters, +void nm_client_dbus_call(NMClient *client, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, const GVariantType *reply_type, int timeout_msec, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); @@ -473,13 +473,13 @@ NM_AVAILABLE_IN_1_24 GVariant *nm_client_dbus_call_finish(NMClient *client, GAsyncResult *result, GError **error); NM_AVAILABLE_IN_1_24 -void nm_client_dbus_set_property(NMClient * client, - const char * object_path, - const char * interface_name, - const char * property_name, - GVariant * value, +void nm_client_dbus_set_property(NMClient *client, + const char *object_path, + const char *interface_name, + const char *property_name, + GVariant *value, int timeout_msec, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); diff --git a/src/libnm-client-public/nm-device-wifi-p2p.h b/src/libnm-client-public/nm-device-wifi-p2p.h index 3395ca29..cf68b496 100644 --- a/src/libnm-client-public/nm-device-wifi-p2p.h +++ b/src/libnm-client-public/nm-device-wifi-p2p.h @@ -50,9 +50,9 @@ NM_AVAILABLE_IN_1_16 const GPtrArray *nm_device_wifi_p2p_get_peers(NMDeviceWifiP2P *device); NM_AVAILABLE_IN_1_16 -void nm_device_wifi_p2p_start_find(NMDeviceWifiP2P * device, - GVariant * options, - GCancellable * cancellable, +void nm_device_wifi_p2p_start_find(NMDeviceWifiP2P *device, + GVariant *options, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); NM_AVAILABLE_IN_1_16 @@ -60,8 +60,8 @@ gboolean nm_device_wifi_p2p_start_find_finish(NMDeviceWifiP2P *device, GAsyncResult *result, GError **error); NM_AVAILABLE_IN_1_16 -void nm_device_wifi_p2p_stop_find(NMDeviceWifiP2P * device, - GCancellable * cancellable, +void nm_device_wifi_p2p_stop_find(NMDeviceWifiP2P *device, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); NM_AVAILABLE_IN_1_16 diff --git a/src/libnm-client-public/nm-device-wifi.h b/src/libnm-client-public/nm-device-wifi.h index 85062f51..1c767316 100644 --- a/src/libnm-client-public/nm-device-wifi.h +++ b/src/libnm-client-public/nm-device-wifi.h @@ -43,11 +43,11 @@ GType nm_device_wifi_get_type(void); NM_DEPRECATED_IN_1_24_FOR(nm_device_get_hw_address) const char *nm_device_wifi_get_hw_address(NMDeviceWifi *device); -const char * nm_device_wifi_get_permanent_hw_address(NMDeviceWifi *device); +const char *nm_device_wifi_get_permanent_hw_address(NMDeviceWifi *device); NM80211Mode nm_device_wifi_get_mode(NMDeviceWifi *device); guint32 nm_device_wifi_get_bitrate(NMDeviceWifi *device); NMDeviceWifiCapabilities nm_device_wifi_get_capabilities(NMDeviceWifi *device); -NMAccessPoint * nm_device_wifi_get_active_access_point(NMDeviceWifi *device); +NMAccessPoint *nm_device_wifi_get_active_access_point(NMDeviceWifi *device); NMAccessPoint *nm_device_wifi_get_access_point_by_path(NMDeviceWifi *device, const char *path); @@ -62,17 +62,17 @@ nm_device_wifi_request_scan(NMDeviceWifi *device, GCancellable *cancellable, GEr NM_AVAILABLE_IN_1_2 _NM_DEPRECATED_SYNC_METHOD gboolean nm_device_wifi_request_scan_options(NMDeviceWifi *device, - GVariant * options, + GVariant *options, GCancellable *cancellable, - GError ** error); -void nm_device_wifi_request_scan_async(NMDeviceWifi * device, - GCancellable * cancellable, + GError **error); +void nm_device_wifi_request_scan_async(NMDeviceWifi *device, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); NM_AVAILABLE_IN_1_2 -void nm_device_wifi_request_scan_options_async(NMDeviceWifi * device, - GVariant * options, - GCancellable * cancellable, +void nm_device_wifi_request_scan_options_async(NMDeviceWifi *device, + GVariant *options, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean diff --git a/src/libnm-client-public/nm-device.h b/src/libnm-client-public/nm-device.h index 23b1a805..9e9dbea6 100644 --- a/src/libnm-client-public/nm-device.h +++ b/src/libnm-client-public/nm-device.h @@ -128,17 +128,17 @@ typedef struct _NMLldpNeighbor NMLldpNeighbor; GType nm_device_get_type(void); -const char * nm_device_get_iface(NMDevice *device); -const char * nm_device_get_ip_iface(NMDevice *device); +const char *nm_device_get_iface(NMDevice *device); +const char *nm_device_get_ip_iface(NMDevice *device); NMDeviceType nm_device_get_device_type(NMDevice *device); -const char * nm_device_get_udi(NMDevice *device); +const char *nm_device_get_udi(NMDevice *device); NM_AVAILABLE_IN_1_26 -const char * nm_device_get_path(NMDevice *device); -const char * nm_device_get_driver(NMDevice *device); -const char * nm_device_get_driver_version(NMDevice *device); -const char * nm_device_get_firmware_version(NMDevice *device); -const char * nm_device_get_type_description(NMDevice *device); -const char * nm_device_get_hw_address(NMDevice *device); +const char *nm_device_get_path(NMDevice *device); +const char *nm_device_get_driver(NMDevice *device); +const char *nm_device_get_driver_version(NMDevice *device); +const char *nm_device_get_firmware_version(NMDevice *device); +const char *nm_device_get_type_description(NMDevice *device); +const char *nm_device_get_hw_address(NMDevice *device); NMDeviceCapabilities nm_device_get_capabilities(NMDevice *device); gboolean nm_device_get_managed(NMDevice *device); @@ -159,17 +159,17 @@ void nm_device_set_autoconnect(NMDevice *device, gboolean autoconnect); gboolean nm_device_get_firmware_missing(NMDevice *device); NM_AVAILABLE_IN_1_2 gboolean nm_device_get_nm_plugin_missing(NMDevice *device); -NMIPConfig * nm_device_get_ip4_config(NMDevice *device); +NMIPConfig *nm_device_get_ip4_config(NMDevice *device); NMDhcpConfig *nm_device_get_dhcp4_config(NMDevice *device); -NMIPConfig * nm_device_get_ip6_config(NMDevice *device); +NMIPConfig *nm_device_get_ip6_config(NMDevice *device); NMDhcpConfig *nm_device_get_dhcp6_config(NMDevice *device); NM_AVAILABLE_IN_1_16 NMConnectivityState nm_device_get_connectivity(NMDevice *device, int addr_family); NMDeviceState nm_device_get_state(NMDevice *device); NMDeviceStateReason nm_device_get_state_reason(NMDevice *device); NMActiveConnection *nm_device_get_active_connection(NMDevice *device); -const GPtrArray * nm_device_get_available_connections(NMDevice *device); -const char * nm_device_get_physical_port_id(NMDevice *device); +const GPtrArray *nm_device_get_available_connections(NMDevice *device); +const char *nm_device_get_physical_port_id(NMDevice *device); guint32 nm_device_get_mtu(NMDevice *device); NM_AVAILABLE_IN_1_2 gboolean nm_device_is_real(NMDevice *device); @@ -188,18 +188,18 @@ NMDeviceInterfaceFlags nm_device_get_interface_flags(NMDevice *device); char **nm_device_disambiguate_names(NMDevice **devices, int num_devices); NM_AVAILABLE_IN_1_2 _NM_DEPRECATED_SYNC_METHOD -gboolean nm_device_reapply(NMDevice * device, +gboolean nm_device_reapply(NMDevice *device, NMConnection *connection, guint64 version_id, guint32 flags, GCancellable *cancellable, - GError ** error); + GError **error); NM_AVAILABLE_IN_1_2 -void nm_device_reapply_async(NMDevice * device, - NMConnection * connection, +void nm_device_reapply_async(NMDevice *device, + NMConnection *connection, guint64 version_id, guint32 flags, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); NM_AVAILABLE_IN_1_2 @@ -207,35 +207,35 @@ gboolean nm_device_reapply_finish(NMDevice *device, GAsyncResult *result, GError NM_AVAILABLE_IN_1_2 _NM_DEPRECATED_SYNC_METHOD -NMConnection *nm_device_get_applied_connection(NMDevice * device, +NMConnection *nm_device_get_applied_connection(NMDevice *device, guint32 flags, - guint64 * version_id, + guint64 *version_id, GCancellable *cancellable, - GError ** error); + GError **error); NM_AVAILABLE_IN_1_2 -void nm_device_get_applied_connection_async(NMDevice * device, +void nm_device_get_applied_connection_async(NMDevice *device, guint32 flags, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); NM_AVAILABLE_IN_1_2 -NMConnection *nm_device_get_applied_connection_finish(NMDevice * device, +NMConnection *nm_device_get_applied_connection_finish(NMDevice *device, GAsyncResult *result, - guint64 * version_id, - GError ** error); + guint64 *version_id, + GError **error); _NM_DEPRECATED_SYNC_METHOD gboolean nm_device_disconnect(NMDevice *device, GCancellable *cancellable, GError **error); -void nm_device_disconnect_async(NMDevice * device, - GCancellable * cancellable, +void nm_device_disconnect_async(NMDevice *device, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean nm_device_disconnect_finish(NMDevice *device, GAsyncResult *result, GError **error); _NM_DEPRECATED_SYNC_METHOD gboolean nm_device_delete(NMDevice *device, GCancellable *cancellable, GError **error); -void nm_device_delete_async(NMDevice * device, - GCancellable * cancellable, +void nm_device_delete_async(NMDevice *device, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean nm_device_delete_finish(NMDevice *device, GAsyncResult *result, GError **error); @@ -264,8 +264,8 @@ NM_AVAILABLE_IN_1_2 NMLldpNeighbor *nm_lldp_neighbor_new(void); NM_AVAILABLE_IN_1_2 gboolean nm_lldp_neighbor_get_attr_string_value(NMLldpNeighbor *neighbor, - const char * name, - const char ** out_value); + const char *name, + const char **out_value); NM_AVAILABLE_IN_1_2 gboolean nm_lldp_neighbor_get_attr_uint_value(NMLldpNeighbor *neighbor, const char *name, guint *out_value); diff --git a/src/libnm-client-public/nm-ip-config.h b/src/libnm-client-public/nm-ip-config.h index a63dea67..99b1948d 100644 --- a/src/libnm-client-public/nm-ip-config.h +++ b/src/libnm-client-public/nm-ip-config.h @@ -41,9 +41,9 @@ typedef struct _NMIPConfigClass NMIPConfigClass; GType nm_ip_config_get_type(void); int nm_ip_config_get_family(NMIPConfig *config); -const char * nm_ip_config_get_gateway(NMIPConfig *config); -GPtrArray * nm_ip_config_get_addresses(NMIPConfig *config); -GPtrArray * nm_ip_config_get_routes(NMIPConfig *config); +const char *nm_ip_config_get_gateway(NMIPConfig *config); +GPtrArray *nm_ip_config_get_addresses(NMIPConfig *config); +GPtrArray *nm_ip_config_get_routes(NMIPConfig *config); const char *const *nm_ip_config_get_nameservers(NMIPConfig *config); const char *const *nm_ip_config_get_domains(NMIPConfig *config); const char *const *nm_ip_config_get_searches(NMIPConfig *config); diff --git a/src/libnm-client-public/nm-remote-connection.h b/src/libnm-client-public/nm-remote-connection.h index 06088e86..6104ecb8 100644 --- a/src/libnm-client-public/nm-remote-connection.h +++ b/src/libnm-client-public/nm-remote-connection.h @@ -42,73 +42,73 @@ typedef struct _NMRemoteConnectionClass NMRemoteConnectionClass; GType nm_remote_connection_get_type(void); NM_AVAILABLE_IN_1_12 -void nm_remote_connection_update2(NMRemoteConnection * connection, - GVariant * settings, +void nm_remote_connection_update2(NMRemoteConnection *connection, + GVariant *settings, NMSettingsUpdate2Flags flags, - GVariant * args, - GCancellable * cancellable, + GVariant *args, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); NM_AVAILABLE_IN_1_12 GVariant *nm_remote_connection_update2_finish(NMRemoteConnection *connection, - GAsyncResult * result, - GError ** error); + GAsyncResult *result, + GError **error); _NM_DEPRECATED_SYNC_METHOD gboolean nm_remote_connection_commit_changes(NMRemoteConnection *connection, gboolean save_to_disk, - GCancellable * cancellable, - GError ** error); + GCancellable *cancellable, + GError **error); void nm_remote_connection_commit_changes_async(NMRemoteConnection *connection, gboolean save_to_disk, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean nm_remote_connection_commit_changes_finish(NMRemoteConnection *connection, - GAsyncResult * result, - GError ** error); + GAsyncResult *result, + GError **error); _NM_DEPRECATED_SYNC_METHOD gboolean nm_remote_connection_save(NMRemoteConnection *connection, - GCancellable * cancellable, - GError ** error); + GCancellable *cancellable, + GError **error); void nm_remote_connection_save_async(NMRemoteConnection *connection, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean nm_remote_connection_save_finish(NMRemoteConnection *connection, - GAsyncResult * result, - GError ** error); + GAsyncResult *result, + GError **error); _NM_DEPRECATED_SYNC_METHOD gboolean nm_remote_connection_delete(NMRemoteConnection *connection, - GCancellable * cancellable, - GError ** error); + GCancellable *cancellable, + GError **error); void nm_remote_connection_delete_async(NMRemoteConnection *connection, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean nm_remote_connection_delete_finish(NMRemoteConnection *connection, - GAsyncResult * result, - GError ** error); + GAsyncResult *result, + GError **error); _NM_DEPRECATED_SYNC_METHOD GVariant *nm_remote_connection_get_secrets(NMRemoteConnection *connection, - const char * setting_name, - GCancellable * cancellable, - GError ** error); + const char *setting_name, + GCancellable *cancellable, + GError **error); void nm_remote_connection_get_secrets_async(NMRemoteConnection *connection, - const char * setting_name, - GCancellable * cancellable, + const char *setting_name, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GVariant *nm_remote_connection_get_secrets_finish(NMRemoteConnection *connection, - GAsyncResult * result, - GError ** error); + GAsyncResult *result, + GError **error); gboolean nm_remote_connection_get_unsaved(NMRemoteConnection *connection); diff --git a/src/libnm-client-public/nm-secret-agent-old.h b/src/libnm-client-public/nm-secret-agent-old.h index cc33c14a..b45b12bb 100644 --- a/src/libnm-client-public/nm-secret-agent-old.h +++ b/src/libnm-client-public/nm-secret-agent-old.h @@ -80,9 +80,9 @@ typedef struct { * */ typedef void (*NMSecretAgentOldGetSecretsFunc)(NMSecretAgentOld *agent, - NMConnection * connection, - GVariant * secrets, - GError * error, + NMConnection *connection, + GVariant *secrets, + GError *error, gpointer user_data); /** @@ -100,8 +100,8 @@ typedef void (*NMSecretAgentOldGetSecretsFunc)(NMSecretAgentOld *agent, * should be called. */ typedef void (*NMSecretAgentOldSaveSecretsFunc)(NMSecretAgentOld *agent, - NMConnection * connection, - GError * error, + NMConnection *connection, + GError *error, gpointer user_data); /** @@ -119,8 +119,8 @@ typedef void (*NMSecretAgentOldSaveSecretsFunc)(NMSecretAgentOld *agent, * should be called. */ typedef void (*NMSecretAgentOldDeleteSecretsFunc)(NMSecretAgentOld *agent, - NMConnection * connection, - GError * error, + NMConnection *connection, + GError *error, gpointer user_data); typedef struct { @@ -138,11 +138,11 @@ typedef struct { * error. Since 1.24, invoking the callback has no effect during cancellation * and may be omitted. */ - void (*get_secrets)(NMSecretAgentOld * self, - NMConnection * connection, - const char * connection_path, - const char * setting_name, - const char ** hints, + void (*get_secrets)(NMSecretAgentOld *self, + NMConnection *connection, + const char *connection_path, + const char *setting_name, + const char **hints, NMSecretAgentGetSecretsFlags flags, NMSecretAgentOldGetSecretsFunc callback, gpointer user_data); @@ -156,8 +156,8 @@ typedef struct { * the get_secrets callback will be ignored during cancellation and may be omitted. */ void (*cancel_get_secrets)(NMSecretAgentOld *self, - const char * connection_path, - const char * setting_name); + const char *connection_path, + const char *setting_name); /* Called when the subclass should save the secrets contained in the * connection to backing storage. Subclass must copy or reference any @@ -165,9 +165,9 @@ typedef struct { * arguments will freed (except for 'self', 'callback', and 'user_data' * of course). */ - void (*save_secrets)(NMSecretAgentOld * self, - NMConnection * connection, - const char * connection_path, + void (*save_secrets)(NMSecretAgentOld *self, + NMConnection *connection, + const char *connection_path, NMSecretAgentOldSaveSecretsFunc callback, gpointer user_data); @@ -177,9 +177,9 @@ typedef struct { * arguments will freed (except for 'self', 'callback', and 'user_data' * of course). */ - void (*delete_secrets)(NMSecretAgentOld * self, - NMConnection * connection, - const char * connection_path, + void (*delete_secrets)(NMSecretAgentOld *self, + NMConnection *connection, + const char *connection_path, NMSecretAgentOldDeleteSecretsFunc callback, gpointer user_data); @@ -208,8 +208,8 @@ gboolean nm_secret_agent_old_get_registered(NMSecretAgentOld *self); NM_AVAILABLE_IN_1_24 void nm_secret_agent_old_enable(NMSecretAgentOld *self, gboolean enable); -void nm_secret_agent_old_register_async(NMSecretAgentOld * self, - GCancellable * cancellable, +void nm_secret_agent_old_register_async(NMSecretAgentOld *self, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean @@ -229,8 +229,8 @@ gboolean nm_secret_agent_old_unregister(NMSecretAgentOld *self, GCancellable *cancellable, GError **error); NM_DEPRECATED_IN_1_24_FOR(nm_secret_agent_old_enable) -void nm_secret_agent_old_unregister_async(NMSecretAgentOld * self, - GCancellable * cancellable, +void nm_secret_agent_old_unregister_async(NMSecretAgentOld *self, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); @@ -240,21 +240,21 @@ nm_secret_agent_old_unregister_finish(NMSecretAgentOld *self, GAsyncResult *resu /*****************************************************************************/ -void nm_secret_agent_old_get_secrets(NMSecretAgentOld * self, - NMConnection * connection, - const char * setting_name, - const char ** hints, +void nm_secret_agent_old_get_secrets(NMSecretAgentOld *self, + NMConnection *connection, + const char *setting_name, + const char **hints, NMSecretAgentGetSecretsFlags flags, NMSecretAgentOldGetSecretsFunc callback, gpointer user_data); -void nm_secret_agent_old_save_secrets(NMSecretAgentOld * self, - NMConnection * connection, +void nm_secret_agent_old_save_secrets(NMSecretAgentOld *self, + NMConnection *connection, NMSecretAgentOldSaveSecretsFunc callback, gpointer user_data); -void nm_secret_agent_old_delete_secrets(NMSecretAgentOld * self, - NMConnection * connection, +void nm_secret_agent_old_delete_secrets(NMSecretAgentOld *self, + NMConnection *connection, NMSecretAgentOldDeleteSecretsFunc callback, gpointer user_data); diff --git a/src/libnm-client-public/nm-vpn-connection.h b/src/libnm-client-public/nm-vpn-connection.h index 1a20d0af..33ca139d 100644 --- a/src/libnm-client-public/nm-vpn-connection.h +++ b/src/libnm-client-public/nm-vpn-connection.h @@ -37,7 +37,7 @@ typedef struct _NMVpnConnectionClass NMVpnConnectionClass; GType nm_vpn_connection_get_type(void); NMVpnConnectionState nm_vpn_connection_get_vpn_state(NMVpnConnection *vpn); -const char * nm_vpn_connection_get_banner(NMVpnConnection *vpn); +const char *nm_vpn_connection_get_banner(NMVpnConnection *vpn); G_END_DECLS diff --git a/src/libnm-client-public/nm-vpn-plugin-old.h b/src/libnm-client-public/nm-vpn-plugin-old.h index 116b8b90..7704c153 100644 --- a/src/libnm-client-public/nm-vpn-plugin-old.h +++ b/src/libnm-client-public/nm-vpn-plugin-old.h @@ -66,9 +66,9 @@ typedef struct { NM_DEPRECATED_IN_1_2 gboolean (*need_secrets)(NMVpnPluginOld *plugin, - NMConnection * connection, - const char ** setting_name, - GError ** error); + NMConnection *connection, + const char **setting_name, + GError **error); NM_DEPRECATED_IN_1_2 gboolean (*disconnect)(NMVpnPluginOld *plugin, GError **err); @@ -78,9 +78,9 @@ typedef struct { NM_DEPRECATED_IN_1_2 gboolean (*connect_interactive)(NMVpnPluginOld *plugin, - NMConnection * connection, - GVariant * details, - GError ** error); + NMConnection *connection, + GVariant *details, + GError **error); /*< private >*/ NM_DEPRECATED_IN_1_2 @@ -126,8 +126,8 @@ gboolean nm_vpn_plugin_old_read_vpn_details(int fd, GHashTable **out_data, GHashTable **out_secrets); NM_DEPRECATED_IN_1_2 -gboolean nm_vpn_plugin_old_get_secret_flags(GHashTable * data, - const char * secret_name, +gboolean nm_vpn_plugin_old_get_secret_flags(GHashTable *data, + const char *secret_name, NMSettingSecretFlags *out_flags); G_END_DECLS diff --git a/src/libnm-client-public/nm-vpn-service-plugin.h b/src/libnm-client-public/nm-vpn-service-plugin.h index 916ea52a..81fb6730 100644 --- a/src/libnm-client-public/nm-vpn-service-plugin.h +++ b/src/libnm-client-public/nm-vpn-service-plugin.h @@ -73,9 +73,9 @@ typedef struct { NM_AVAILABLE_IN_1_2 gboolean (*need_secrets)(NMVpnServicePlugin *plugin, - NMConnection * connection, - const char ** setting_name, - GError ** error); + NMConnection *connection, + const char **setting_name, + GError **error); NM_AVAILABLE_IN_1_2 gboolean (*disconnect)(NMVpnServicePlugin *plugin, GError **err); @@ -85,9 +85,9 @@ typedef struct { NM_AVAILABLE_IN_1_2 gboolean (*connect_interactive)(NMVpnServicePlugin *plugin, - NMConnection * connection, - GVariant * details, - GError ** error); + NMConnection *connection, + GVariant *details, + GError **error); /*< private >*/ NM_AVAILABLE_IN_1_2 @@ -102,8 +102,8 @@ GDBusConnection *nm_vpn_service_plugin_get_connection(NMVpnServicePlugin *plugin NM_AVAILABLE_IN_1_2 void nm_vpn_service_plugin_secrets_required(NMVpnServicePlugin *plugin, - const char * message, - const char ** hints); + const char *message, + const char **hints); NM_AVAILABLE_IN_1_2 void nm_vpn_service_plugin_set_login_banner(NMVpnServicePlugin *plugin, const char *banner); @@ -133,8 +133,8 @@ gboolean nm_vpn_service_plugin_read_vpn_details(int fd, GHashTable **out_data, GHashTable **out_secrets); NM_AVAILABLE_IN_1_2 -gboolean nm_vpn_service_plugin_get_secret_flags(GHashTable * data, - const char * secret_name, +gboolean nm_vpn_service_plugin_get_secret_flags(GHashTable *data, + const char *secret_name, NMSettingSecretFlags *out_flags); G_END_DECLS diff --git a/src/libnm-client-test/nm-test-libnm-utils.h b/src/libnm-client-test/nm-test-libnm-utils.h index 4997ab33..2a4dae87 100644 --- a/src/libnm-client-test/nm-test-libnm-utils.h +++ b/src/libnm-client-test/nm-test-libnm-utils.h @@ -12,7 +12,7 @@ typedef struct { GDBusConnection *bus; - GDBusProxy * proxy; + GDBusProxy *proxy; GPid pid; int keepalive_fd; } NMTstcServiceInfo; @@ -39,34 +39,34 @@ _nmtstc_auto_service_cleanup(NMTstcServiceInfo **info) }) NMDevice *nmtstc_service_add_device(NMTstcServiceInfo *info, - NMClient * client, - const char * method, - const char * ifname); + NMClient *client, + const char *method, + const char *ifname); NMDevice *nmtstc_service_add_wired_device(NMTstcServiceInfo *sinfo, - NMClient * client, - const char * ifname, - const char * hwaddr, - const char ** subchannels); + NMClient *client, + const char *ifname, + const char *hwaddr, + const char **subchannels); void nmtstc_service_add_connection(NMTstcServiceInfo *sinfo, - NMConnection * connection, + NMConnection *connection, gboolean verify_connection, - char ** out_path); + char **out_path); void nmtstc_service_add_connection_variant(NMTstcServiceInfo *sinfo, - GVariant * connection, + GVariant *connection, gboolean verify_connection, - char ** out_path); + char **out_path); void nmtstc_service_update_connection(NMTstcServiceInfo *sinfo, - const char * path, - NMConnection * connection, + const char *path, + NMConnection *connection, gboolean verify_connection); void nmtstc_service_update_connection_variant(NMTstcServiceInfo *sinfo, - const char * path, - GVariant * connection, + const char *path, + GVariant *connection, gboolean verify_connection); gpointer nmtstc_context_object_new_valist(GType gtype, diff --git a/src/libnm-client-test/nm-test-utils-impl.c b/src/libnm-client-test/nm-test-utils-impl.c index 610232b0..ef98d9c2 100644 --- a/src/libnm-client-test/nm-test-utils-impl.c +++ b/src/libnm-client-test/nm-test-utils-impl.c @@ -42,7 +42,7 @@ name_exists(GDBusConnection *c, const char *name) } typedef struct { - GMainLoop * mainloop; + GMainLoop *mainloop; GDBusConnection *bus; int exit_code; bool exited : 1; @@ -92,8 +92,8 @@ NMTstcServiceInfo * nmtstc_service_init(void) { NMTstcServiceInfo *info; - const char * args[] = {TEST_NM_PYTHON, NMTSTC_NM_SERVICE, NULL}; - GError * error = NULL; + const char *args[] = {TEST_NM_PYTHON, NMTSTC_NM_SERVICE, NULL}; + GError *error = NULL; info = g_malloc0(sizeof(*info)); @@ -120,10 +120,10 @@ nmtstc_service_init(void) { nm_auto_unref_gsource GSource *timeout_source = NULL; nm_auto_unref_gsource GSource *child_source = NULL; - GMainContext * context = g_main_context_new(); + GMainContext *context = g_main_context_new(); ServiceInitWaitData data = { - .bus = info->bus, - .mainloop = g_main_loop_new(context, FALSE), + .bus = info->bus, + .mainloop = g_main_loop_new(context, FALSE), }; gboolean had_timeout; @@ -226,10 +226,10 @@ again_wait: } typedef struct { - GMainLoop * loop; + GMainLoop *loop; const char *ifname; const char *path; - NMDevice * device; + NMDevice *device; } AddDeviceInfo; static void @@ -249,11 +249,11 @@ device_added_cb(NMClient *client, NMDevice *device, gpointer user_data) } static GVariant * -call_add_wired_device(GDBusProxy * proxy, - const char * ifname, - const char * hwaddr, +call_add_wired_device(GDBusProxy *proxy, + const char *ifname, + const char *hwaddr, const char **subchannels, - GError ** error) + GError **error) { const char *empty[] = {NULL}; @@ -285,16 +285,16 @@ call_add_device(GDBusProxy *proxy, const char *method, const char *ifname, GErro static NMDevice * add_device_common(NMTstcServiceInfo *sinfo, - NMClient * client, - const char * method, - const char * ifname, - const char * hwaddr, - const char ** subchannels) + NMClient *client, + const char *method, + const char *ifname, + const char *hwaddr, + const char **subchannels) { - nm_auto_unref_gmainloop GMainLoop *loop = NULL; - gs_unref_variant GVariant *ret = NULL; - gs_free_error GError *error = NULL; - AddDeviceInfo info; + nm_auto_unref_gmainloop GMainLoop *loop = NULL; + gs_unref_variant GVariant *ret = NULL; + gs_free_error GError *error = NULL; + AddDeviceInfo info; g_assert(sinfo); g_assert(NM_IS_CLIENT(client)); @@ -334,28 +334,28 @@ add_device_common(NMTstcServiceInfo *sinfo, NMDevice * nmtstc_service_add_device(NMTstcServiceInfo *sinfo, - NMClient * client, - const char * method, - const char * ifname) + NMClient *client, + const char *method, + const char *ifname) { return add_device_common(sinfo, client, method, ifname, NULL, NULL); } NMDevice * nmtstc_service_add_wired_device(NMTstcServiceInfo *sinfo, - NMClient * client, - const char * ifname, - const char * hwaddr, - const char ** subchannels) + NMClient *client, + const char *ifname, + const char *hwaddr, + const char **subchannels) { return add_device_common(sinfo, client, "AddWiredDevice", ifname, hwaddr, subchannels); } void nmtstc_service_add_connection(NMTstcServiceInfo *sinfo, - NMConnection * connection, + NMConnection *connection, gboolean verify_connection, - char ** out_path) + char **out_path) { nmtstc_service_add_connection_variant( sinfo, @@ -366,12 +366,12 @@ nmtstc_service_add_connection(NMTstcServiceInfo *sinfo, void nmtstc_service_add_connection_variant(NMTstcServiceInfo *sinfo, - GVariant * connection, + GVariant *connection, gboolean verify_connection, - char ** out_path) + char **out_path) { GVariant *result; - GError * error = NULL; + GError *error = NULL; g_assert(sinfo); g_assert(G_IS_DBUS_PROXY(sinfo->proxy)); @@ -393,8 +393,8 @@ nmtstc_service_add_connection_variant(NMTstcServiceInfo *sinfo, void nmtstc_service_update_connection(NMTstcServiceInfo *sinfo, - const char * path, - NMConnection * connection, + const char *path, + NMConnection *connection, gboolean verify_connection) { if (!path) @@ -410,12 +410,12 @@ nmtstc_service_update_connection(NMTstcServiceInfo *sinfo, void nmtstc_service_update_connection_variant(NMTstcServiceInfo *sinfo, - const char * path, - GVariant * connection, + const char *path, + GVariant *connection, gboolean verify_connection) { GVariant *result; - GError * error = NULL; + GError *error = NULL; g_assert(sinfo); g_assert(G_IS_DBUS_PROXY(sinfo->proxy)); @@ -439,14 +439,14 @@ nmtstc_service_update_connection_variant(NMTstcServiceInfo *sinfo, typedef struct { GType gtype; GMainLoop *loop; - GObject * obj; + GObject *obj; bool call_nm_client_new_async : 1; } NMTstcObjNewData; static void _context_object_new_do_cb(GObject *source_object, GAsyncResult *res, gpointer user_data) { - NMTstcObjNewData *d = user_data; + NMTstcObjNewData *d = user_data; gs_free_error GError *error = NULL; g_assert(!d->obj); @@ -472,7 +472,7 @@ _context_object_new_do(GType gtype, va_list var_args) { gs_free_error GError *error = NULL; - GObject * obj; + GObject *obj; /* Create a GObject instance synchronously, and arbitrarily use either * the sync or async constructor. @@ -508,8 +508,8 @@ _context_object_new_do(GType gtype, } else { nm_auto_unref_gmainloop GMainLoop *loop = NULL; NMTstcObjNewData d = { - .gtype = gtype, - .loop = NULL, + .gtype = gtype, + .loop = NULL, }; gs_unref_object GObject *obj2 = NULL; @@ -545,8 +545,8 @@ typedef struct { GType gtype; const char *first_property_name; va_list var_args; - GMainLoop * loop; - GObject * obj; + GMainLoop *loop; + GObject *obj; bool sync; } NewSyncInsideDispatchedData; @@ -570,13 +570,13 @@ _context_object_new_inside_loop(GType gtype, const char *first_property_name, va_list var_args) { - GMainContext * context = g_main_context_get_thread_default(); - nm_auto_unref_gmainloop GMainLoop *loop = g_main_loop_new(context, FALSE); - NewSyncInsideDispatchedData d = { - .gtype = gtype, - .first_property_name = first_property_name, - .sync = sync, - .loop = loop, + GMainContext *context = g_main_context_get_thread_default(); + nm_auto_unref_gmainloop GMainLoop *loop = g_main_loop_new(context, FALSE); + NewSyncInsideDispatchedData d = { + .gtype = gtype, + .first_property_name = first_property_name, + .sync = sync, + .loop = loop, }; nm_auto_destroy_and_unref_gsource GSource *source = NULL; diff --git a/src/libnm-core-aux-extern/nm-libnm-core-aux.c b/src/libnm-core-aux-extern/nm-libnm-core-aux.c index e92c234f..dfc70e35 100644 --- a/src/libnm-core-aux-extern/nm-libnm-core-aux.c +++ b/src/libnm-core-aux-extern/nm-libnm-core-aux.c @@ -27,7 +27,7 @@ typedef struct { } ParseData; typedef struct { - const char * name; + const char *name; NMTeamLinkWatcherType watcher_type; KeyType key_type; union { @@ -65,8 +65,8 @@ _team_link_watcher_send_always(const NMTeamLinkWatcher *watcher) static const TeamLinkWatcherKeyInfo _team_link_watcher_key_infos[_NM_TEAM_LINK_WATCHER_KEY_NUM] = { #define _KEY_INFO(key_id, _name, _watcher_type, _key_type, ...) \ - [key_id] = {.name = ""_name \ - "", \ + [key_id] = {.name = ""_name \ + "", \ .watcher_type = (_watcher_type), \ .key_type = _key_type, \ ##__VA_ARGS__} @@ -189,7 +189,7 @@ char * nm_utils_team_link_watcher_to_string(const NMTeamLinkWatcher *watcher) { nm_auto_free_gstring GString *str = NULL; - const char * name; + const char *name; NMTeamLinkWatcherType watcher_type; NMTeamLinkWatcherKeyId key_id; @@ -205,7 +205,7 @@ nm_utils_team_link_watcher_to_string(const NMTeamLinkWatcher *watcher) for (key_id = 0; key_id < _NM_TEAM_LINK_WATCHER_KEY_NUM; key_id++) { const TeamLinkWatcherKeyInfo *info = &_team_link_watcher_key_infos[key_id]; - const char * vstr; + const char *vstr; int vint; bool vbool; @@ -257,12 +257,12 @@ nm_utils_team_link_watcher_to_string(const NMTeamLinkWatcher *watcher) NMTeamLinkWatcher * nm_utils_team_link_watcher_from_string(const char *str, GError **error) { - gs_free const char ** tokens = NULL; + gs_free const char **tokens = NULL; ParseData parse_data[_NM_TEAM_LINK_WATCHER_KEY_NUM] = {}; NMTeamLinkWatcherType watcher_type; NMTeamLinkWatcherKeyId key_id; gsize i_token; - NMTeamLinkWatcher * watcher; + NMTeamLinkWatcher *watcher; int errsv; g_return_val_if_fail(str, NULL); @@ -276,8 +276,8 @@ nm_utils_team_link_watcher_from_string(const char *str, GError **error) for (i_token = 0; tokens[i_token]; i_token++) { const TeamLinkWatcherKeyInfo *info; - const char * key = tokens[i_token]; - const char * val; + const char *key = tokens[i_token]; + const char *val; val = strchr(key, '='); if (!val) { @@ -413,7 +413,7 @@ nm_utils_team_link_watcher_from_string(const char *str, GError **error) #if NM_MORE_ASSERTS > 5 if (watcher) { - gs_free char * str2 = NULL; + gs_free char *str2 = NULL; nm_auto_unref_team_link_watcher NMTeamLinkWatcher *watcher2 = NULL; static _nm_thread_local int recursive; diff --git a/src/libnm-core-aux-intern/nm-auth-subject.c b/src/libnm-core-aux-intern/nm-auth-subject.c index 536b4e47..db499b88 100644 --- a/src/libnm-core-aux-intern/nm-auth-subject.c +++ b/src/libnm-core-aux-intern/nm-auth-subject.c @@ -34,7 +34,7 @@ typedef struct { gulong pid; gulong uid; guint64 start_time; - char * dbus_sender; + char *dbus_sender; } unix_process; struct { @@ -273,7 +273,7 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps NMAuthSubjectPrivate *priv = NM_AUTH_SUBJECT_GET_PRIVATE(object); NMAuthSubjectType subject_type; int i; - const char * str; + const char *str; gulong id; switch (prop_id) { @@ -348,7 +348,7 @@ nm_auth_subject_init(NMAuthSubject *self) static void constructed(GObject *object) { - NMAuthSubject * self = NM_AUTH_SUBJECT(object); + NMAuthSubject *self = NM_AUTH_SUBJECT(object); NMAuthSubjectPrivate *priv = NM_AUTH_SUBJECT_GET_PRIVATE(self); /* validate that the created instance. */ diff --git a/src/libnm-core-aux-intern/nm-libnm-core-utils.c b/src/libnm-core-aux-intern/nm-libnm-core-utils.c index e1688859..37518815 100644 --- a/src/libnm-core-aux-intern/nm-libnm-core-utils.c +++ b/src/libnm-core-aux-intern/nm-libnm-core-utils.c @@ -104,11 +104,11 @@ _nm_setting_bond_mode_to_string(int mode) gboolean nm_utils_vlan_priority_map_parse_str(NMVlanPriorityMap map_type, - const char * str, + const char *str, gboolean allow_wildcard_to, - guint32 * out_from, - guint32 * out_to, - gboolean * out_has_wildcard_to) + guint32 *out_from, + guint32 *out_to, + gboolean *out_has_wildcard_to) { const char *s2; gint64 v1, v2; @@ -216,7 +216,7 @@ _nm_auth_permission_from_string_cmp(gconstpointer a, gconstpointer b, gpointer u { const NMClientPermission *const p = a; const char *const needle = b; - const char * ss = nm_auth_permission_names_by_idx[*p - 1]; + const char *ss = nm_auth_permission_names_by_idx[*p - 1]; nm_assert(NM_STR_HAS_PREFIX(ss, AUTH_PERMISSION_PREFIX)); nm_assert(ss[NM_STRLEN(AUTH_PERMISSION_PREFIX)] != '\0'); @@ -281,7 +281,7 @@ nm_client_permission_result_to_string(NMClientPermissionResult permission) gboolean nm_utils_validate_dhcp4_vendor_class_id(const char *vci, GError **error) { - const char * bin; + const char *bin; gsize unescaped_len; gs_free char *to_free = NULL; diff --git a/src/libnm-core-aux-intern/nm-libnm-core-utils.h b/src/libnm-core-aux-intern/nm-libnm-core-utils.h index f90e3984..eb30c931 100644 --- a/src/libnm-core-aux-intern/nm-libnm-core-utils.h +++ b/src/libnm-core-aux-intern/nm-libnm-core-utils.h @@ -93,11 +93,11 @@ nm_utils_vlan_priority_map_get_max_prio(NMVlanPriorityMap map, gboolean from) } gboolean nm_utils_vlan_priority_map_parse_str(NMVlanPriorityMap map_type, - const char * str, + const char *str, gboolean allow_wildcard_to, - guint32 * out_from, - guint32 * out_to, - gboolean * out_has_wildcard_to); + guint32 *out_from, + guint32 *out_to, + gboolean *out_has_wildcard_to); /*****************************************************************************/ @@ -149,13 +149,13 @@ nm_setting_ip_config_get_addr_family(NMSettingIPConfig *s_ip) extern const char *const nm_auth_permission_names_by_idx[NM_CLIENT_PERMISSION_LAST]; extern const NMClientPermission nm_auth_permission_sorted[NM_CLIENT_PERMISSION_LAST]; -const char * nm_auth_permission_to_string(NMClientPermission permission); +const char *nm_auth_permission_to_string(NMClientPermission permission); NMClientPermission nm_auth_permission_from_string(const char *str); /*****************************************************************************/ NMClientPermissionResult nm_client_permission_result_from_string(const char *nm); -const char * nm_client_permission_result_to_string(NMClientPermissionResult permission); +const char *nm_client_permission_result_to_string(NMClientPermissionResult permission); gboolean nm_utils_validate_dhcp4_vendor_class_id(const char *vci, GError **error); diff --git a/src/libnm-core-impl/nm-connection-private.h b/src/libnm-core-impl/nm-connection-private.h index 27769ec1..08abb9a4 100644 --- a/src/libnm-core-impl/nm-connection-private.h +++ b/src/libnm-core-impl/nm-connection-private.h @@ -18,12 +18,12 @@ NMSetting *_nm_connection_find_base_type_setting(NMConnection *connection); const char *_nm_connection_detect_slave_type(NMConnection *connection, NMSetting **out_s_port); gboolean _nm_connection_detect_slave_type_full(NMSettingConnection *s_con, - NMConnection * connection, - const char ** out_slave_type, - const char ** out_normerr_slave_setting_type, - const char ** out_normerr_missing_slave_type, + NMConnection *connection, + const char **out_slave_type, + const char **out_normerr_slave_setting_type, + const char **out_normerr_missing_slave_type, const char **out_normerr_missing_slave_type_port, - GError ** error); + GError **error); const char *_nm_connection_detect_bluetooth_type(NMConnection *self); @@ -32,11 +32,11 @@ gboolean _nm_setting_connection_verify_secondaries(GArray *secondaries, GError * gboolean _nm_connection_verify_required_interface_name(NMConnection *connection, GError **error); int _nm_setting_ovs_interface_verify_interface_type(NMSettingOvsInterface *self, - const char * type, - NMConnection * connection, + const char *type, + NMConnection *connection, gboolean normalize, - gboolean * out_modified, - const char ** out_normalized_type, - GError ** error); + gboolean *out_modified, + const char **out_normalized_type, + GError **error); #endif /* __NM_CONNECTION_PRIVATE_H__ */ diff --git a/src/libnm-core-impl/nm-connection.c b/src/libnm-core-impl/nm-connection.c index dc85ea0c..a9b130a7 100644 --- a/src/libnm-core-impl/nm-connection.c +++ b/src/libnm-core-impl/nm-connection.c @@ -126,7 +126,7 @@ _nm_connection_get_private_from_qdata(NMConnection *connection) #define NM_CONNECTION_GET_PRIVATE(connection) \ ({ \ - NMConnection * _connection = (connection); \ + NMConnection *_connection = (connection); \ NMConnectionPrivate *_priv; \ \ if (G_LIKELY(NM_IS_SIMPLE_CONNECTION(_connection))) \ @@ -215,8 +215,8 @@ static void _nm_connection_add_setting(NMConnection *connection, NMSetting *setting) { const NMMetaSettingInfo *setting_info; - NMConnectionPrivate * priv; - NMSetting * s_old; + NMConnectionPrivate *priv; + NMSetting *s_old; nm_assert(NM_IS_CONNECTION(connection)); nm_assert(NM_IS_SETTING(setting)); @@ -264,8 +264,8 @@ nm_connection_add_setting(NMConnection *connection, NMSetting *setting) gboolean _nm_connection_remove_setting(NMConnection *connection, GType setting_type) { - NMConnectionPrivate * priv; - NMSetting * setting; + NMConnectionPrivate *priv; + NMSetting *setting; const NMMetaSettingInfo *setting_info; g_return_val_if_fail(NM_IS_CONNECTION(connection), FALSE); @@ -302,7 +302,7 @@ nm_connection_remove_setting(NMConnection *connection, GType setting_type) static gpointer _connection_get_setting(NMConnection *connection, GType setting_type) { - NMSetting * setting; + NMSetting *setting; const NMMetaSettingInfo *setting_info; nm_assert(NM_IS_CONNECTION(connection)); @@ -399,8 +399,8 @@ nm_connection_get_setting_by_name(NMConnection *connection, const char *name) gpointer /* (NMSetting *) */ _nm_connection_check_main_setting(NMConnection *connection, - const char * setting_name, - GError ** error) + const char *setting_name, + GError **error) { NMSetting *setting; @@ -498,16 +498,16 @@ _auto_settings(NMSetting ***p_settings) * are lost. **/ gboolean -_nm_connection_replace_settings(NMConnection * connection, - GVariant * new_settings, +_nm_connection_replace_settings(NMConnection *connection, + GVariant *new_settings, NMSettingParseFlags parse_flags, - GError ** error) + GError **error) { - NMSetting * settings[_NM_META_SETTING_TYPE_NUM] = {}; + NMSetting *settings[_NM_META_SETTING_TYPE_NUM] = {}; nm_auto(_auto_settings) NMSetting **settings_cleanup = settings; GVariantIter iter; - const char * setting_name; - GVariant * setting_dict; + const char *setting_name; + GVariant *setting_dict; gboolean changed; gboolean success; guint n_settings = 0; @@ -528,9 +528,9 @@ _nm_connection_replace_settings(NMConnection * connection, g_variant_iter_init(&iter, new_settings); while (g_variant_iter_next(&iter, "{&s@a{sv}}", &setting_name, &setting_dict)) { gs_unref_variant GVariant *setting_dict_free = NULL; - GError * local = NULL; - NMSetting * setting; - const NMMetaSettingInfo * setting_info; + GError *local = NULL; + NMSetting *setting; + const NMMetaSettingInfo *setting_info; setting_dict_free = setting_dict; @@ -748,11 +748,11 @@ nm_connection_compare(NMConnection *a, NMConnection *b, NMSettingCompareFlags fl } static gboolean -diff_one_connection(NMConnection * a, - NMConnection * b, +diff_one_connection(NMConnection *a, + NMConnection *b, NMSettingCompareFlags flags, gboolean invert_results, - GHashTable * diffs) + GHashTable *diffs) { NMConnectionPrivate *a_priv = NM_CONNECTION_GET_PRIVATE(a); NMConnectionPrivate *b_priv = b ? NM_CONNECTION_GET_PRIVATE(b) : NULL; @@ -763,7 +763,7 @@ diff_one_connection(NMConnection * a, NMSetting *a_setting = a_priv->settings[i]; if (a_setting) { - NMSetting * b_setting = b ? b_priv->settings[i] : NULL; + NMSetting *b_setting = b ? b_priv->settings[i] : NULL; const char *setting_name = nm_setting_get_name(a_setting); GHashTable *results; gboolean new_results = TRUE; @@ -803,10 +803,10 @@ diff_one_connection(NMConnection * a, * not **/ gboolean -nm_connection_diff(NMConnection * a, - NMConnection * b, +nm_connection_diff(NMConnection *a, + NMConnection *b, NMSettingCompareFlags flags, - GHashTable ** out_settings) + GHashTable **out_settings) { GHashTable *diffs; gboolean diff_found = FALSE; @@ -845,12 +845,12 @@ NMSetting * _nm_connection_find_base_type_setting(NMConnection *connection) { NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE(connection); - NMSetting * setting = NULL; + NMSetting *setting = NULL; NMSettingPriority setting_prio = NM_SETTING_PRIORITY_USER; int i; for (i = 0; i < (int) _NM_META_SETTING_TYPE_NUM; i++) { - NMSetting * s_iter = priv->settings[i]; + NMSetting *s_iter = priv->settings[i]; NMSettingPriority s_iter_prio; if (!s_iter) @@ -865,7 +865,7 @@ _nm_connection_find_base_type_setting(NMConnection *connection) continue; } else if (s_iter_prio == setting_prio) { NMSettingConnection *s_con = nm_connection_get_setting_connection(connection); - const char * type; + const char *type; if (s_con) { type = nm_setting_connection_get_connection_type(s_con); @@ -886,7 +886,7 @@ _normalize_connection_uuid(NMConnection *self) { NMSettingConnection *s_con = nm_connection_get_setting_connection(self); char uuid_normalized[37]; - const char * uuid; + const char *uuid; nm_assert(s_con); @@ -942,7 +942,7 @@ _nm_setting_connection_verify_secondaries(GArray *secondaries, GError **error) if (len > 1) { gs_free const char **strv_to_free = NULL; - const char ** strv2; + const char **strv2; strv2 = nm_strv_dup_shallow_maybe_a(20, strv, len, &strv_to_free); nm_strv_sort(strv2, len); @@ -979,8 +979,8 @@ static gboolean _normalize_connection_secondaries(NMConnection *self) { NMSettingConnection *s_con = nm_connection_get_setting_connection(self); - GArray * secondaries; - gs_strfreev char ** strv = NULL; + GArray *secondaries; + gs_strfreev char **strv = NULL; guint i; guint j; @@ -1017,8 +1017,8 @@ static gboolean _normalize_connection_type(NMConnection *self) { NMSettingConnection *s_con = nm_connection_get_setting_connection(self); - NMSetting * s_base = NULL; - const char * type; + NMSetting *s_base = NULL; + const char *type; type = nm_setting_connection_get_connection_type(s_con); @@ -1066,12 +1066,12 @@ const char * _nm_connection_detect_slave_type(NMConnection *connection, NMSetting **out_s_port) { NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE(connection); - const char * slave_type = NULL; - NMSetting * s_port = NULL; + const char *slave_type = NULL; + NMSetting *s_port = NULL; int i; static const struct { NMMetaSettingType meta_type; - const char * controller_type_name; + const char *controller_type_name; } infos[] = { {NM_META_SETTING_TYPE_BRIDGE_PORT, NM_SETTING_BRIDGE_SETTING_NAME}, {NM_META_SETTING_TYPE_BOND_PORT, NM_SETTING_BOND_SETTING_NAME}, @@ -1105,7 +1105,7 @@ static gboolean _normalize_connection_slave_type(NMConnection *self) { NMSettingConnection *s_con = nm_connection_get_setting_connection(self); - const char * slave_type, *port_type; + const char *slave_type, *port_type; if (!s_con) return FALSE; @@ -1177,7 +1177,7 @@ _normalize_ethernet_link_neg(NMConnection *self) static gboolean _supports_addr_family(NMConnection *self, int family) { - const char * connection_type = nm_connection_get_connection_type(self); + const char *connection_type = nm_connection_get_connection_type(self); NMSettingConnection *s_con; g_return_val_if_fail(connection_type, TRUE); @@ -1198,8 +1198,8 @@ static gboolean _normalize_ip_config(NMConnection *self, GHashTable *parameters) { NMSettingIPConfig *s_ip4, *s_ip6; - NMSettingProxy * s_proxy; - NMSetting * setting; + NMSettingProxy *s_proxy; + NMSetting *setting; gboolean changed = FALSE; guint num, i; @@ -1397,7 +1397,7 @@ _normalize_bond_options(NMConnection *self) { NMSettingBond *s_bond = nm_connection_get_setting_bond(self); gboolean changed = FALSE; - const char * name, *mode_str; + const char *name, *mode_str; NMBondMode mode; guint32 num, i; @@ -1425,8 +1425,8 @@ again: static gboolean _normalize_wireless_mac_address_randomization(NMConnection *self) { - NMSettingWireless * s_wifi = nm_connection_get_setting_wireless(self); - const char * cloned_mac_address; + NMSettingWireless *s_wifi = nm_connection_get_setting_wireless(self); + const char *cloned_mac_address; NMSettingMacRandomization mac_address_randomization; if (!s_wifi) @@ -1645,7 +1645,7 @@ static gboolean _normalize_required_settings(NMConnection *self) { NMSettingBluetooth *s_bt = nm_connection_get_setting_bluetooth(self); - NMSetting * s_bridge; + NMSetting *s_bridge; gboolean changed = FALSE; if (nm_connection_get_setting_vlan(self)) { @@ -1671,7 +1671,7 @@ static gboolean _normalize_invalid_slave_port_settings(NMConnection *self) { NMSettingConnection *s_con = nm_connection_get_setting_connection(self); - const char * slave_type; + const char *slave_type; gboolean changed = FALSE; slave_type = nm_setting_connection_get_slave_type(s_con); @@ -1725,10 +1725,10 @@ nm_connection_verify(NMConnection *connection, GError **error) NMSettingVerifyResult _nm_connection_verify(NMConnection *connection, GError **error) { - NMConnectionPrivate *priv; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSettingProxy * s_proxy; + NMConnectionPrivate *priv; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingProxy *s_proxy; gs_free_error GError *normalizable_error = NULL; NMSettingVerifyResult normalizable_error_type = NM_SETTING_VERIFY_SUCCESS; int i; @@ -1748,8 +1748,8 @@ _nm_connection_verify(NMConnection *connection, GError **error) } for (i = 0; i < (int) _NM_META_SETTING_TYPE_NUM; i++) { - NMSetting * setting = priv->settings[nm_meta_setting_types_by_priority[i]]; - GError * verify_error = NULL; + NMSetting *setting = priv->settings[nm_meta_setting_types_by_priority[i]]; + GError *verify_error = NULL; NMSettingVerifyResult verify_result; if (!setting) @@ -1909,9 +1909,9 @@ nm_connection_verify_secrets(NMConnection *connection, GError **error) static gboolean _connection_normalize(NMConnection *connection, - GHashTable * parameters, - gboolean * modified, - GError ** error) + GHashTable *parameters, + gboolean *modified, + GError **error) { NMSettingVerifyResult success; gboolean was_modified; @@ -2006,9 +2006,9 @@ _connection_normalize(NMConnection *connection, **/ gboolean nm_connection_normalize(NMConnection *connection, - GHashTable * parameters, - gboolean * modified, - GError ** error) + GHashTable *parameters, + gboolean *modified, + GError **error) { NMSettingVerifyResult success; gs_free_error GError *normalizable_error = NULL; @@ -2044,16 +2044,16 @@ nm_connection_normalize(NMConnection *connection, } gboolean -_nm_connection_ensure_normalized(NMConnection * connection, +_nm_connection_ensure_normalized(NMConnection *connection, gboolean allow_modify, - const char * expected_uuid, + const char *expected_uuid, gboolean coerce_uuid, NMConnection **out_connection_clone, - GError ** error) + GError **error) { gs_unref_object NMConnection *connection_clone = NULL; - gs_free_error GError *local = NULL; - NMSettingVerifyResult vresult; + gs_free_error GError *local = NULL; + NMSettingVerifyResult vresult; nm_assert(NM_IS_CONNECTION(connection)); nm_assert(!out_connection_clone || !*out_connection_clone); @@ -2122,7 +2122,7 @@ _nm_assert_connection_unchanging_changed_cb(NMConnection *connection, gpointer u static void _nm_assert_connection_unchanging_secrets_updated_cb(NMConnection *connection, - const char * setting_name, + const char *setting_name, gpointer user_data) { nm_assert_not_reached(); @@ -2187,16 +2187,16 @@ nm_assert_connection_unchanging(NMConnection *connection) **/ gboolean nm_connection_update_secrets(NMConnection *connection, - const char * setting_name, - GVariant * secrets, - GError ** error) + const char *setting_name, + GVariant *secrets, + GError **error) { - NMSetting * setting; + NMSetting *setting; gboolean success = TRUE; gboolean updated = FALSE; - GVariant * setting_dict = NULL; + GVariant *setting_dict = NULL; GVariantIter iter; - const char * key; + const char *key; gboolean full_connection; int success_detail; @@ -2320,7 +2320,7 @@ nm_connection_update_secrets(NMConnection *connection, const char * nm_connection_need_secrets(NMConnection *connection, GPtrArray **hints) { - NMSetting * setting_before = NULL; + NMSetting *setting_before = NULL; NMConnectionPrivate *priv; int i; @@ -2380,7 +2380,7 @@ nm_connection_clear_secrets(NMConnection *connection) * Clears and frees secrets determined by @func. **/ void -nm_connection_clear_secrets_with_flags(NMConnection * connection, +nm_connection_clear_secrets_with_flags(NMConnection *connection, NMSettingClearSecretsWithFlagsFn func, gpointer user_data) { @@ -2406,8 +2406,8 @@ nm_connection_clear_secrets_with_flags(NMConnection * connecti } static gboolean -_clear_secrets_by_secret_flags_cb(NMSetting * setting, - const char * secret, +_clear_secrets_by_secret_flags_cb(NMSetting *setting, + const char *secret, NMSettingSecretFlags flags, gpointer user_data) { @@ -2454,8 +2454,8 @@ _nm_connection_clear_secrets_by_secret_flags(NMConnection *self, NMSettingSecret /* Returns always a non-NULL, floating variant that must * be unrefed by the caller. */ GVariant * -_nm_connection_for_each_secret(NMConnection * self, - GVariant * secrets, +_nm_connection_for_each_secret(NMConnection *self, + GVariant *secrets, gboolean remove_non_secrets, _NMConnectionForEachSecretFunc callback, gpointer callback_data) @@ -2463,8 +2463,8 @@ _nm_connection_for_each_secret(NMConnection * self, GVariantBuilder secrets_builder; GVariantBuilder setting_builder; GVariantIter secrets_iter; - GVariantIter * setting_iter; - const char * setting_name; + GVariantIter *setting_iter; + const char *setting_name; /* This function, given a dict of dicts representing new secrets of * an NMConnection, walks through each toplevel dict (which represents a @@ -2486,9 +2486,9 @@ _nm_connection_for_each_secret(NMConnection * self, g_variant_builder_init(&secrets_builder, NM_VARIANT_TYPE_CONNECTION); while (g_variant_iter_next(&secrets_iter, "{&sa{sv}}", &setting_name, &setting_iter)) { _nm_unused nm_auto_free_variant_iter GVariantIter *setting_iter_free = setting_iter; - NMSetting * setting; - const char * secret_name; - GVariant * val; + NMSetting *setting; + const char *secret_name; + GVariant *val; setting = nm_connection_get_setting_by_name(self, setting_name); if (!setting) @@ -2532,16 +2532,16 @@ find_secret_for_each_func(NMSettingSecretFlags flags, gpointer user_data) } gboolean -_nm_connection_find_secret(NMConnection * self, - GVariant * secrets, +_nm_connection_find_secret(NMConnection *self, + GVariant *secrets, NMConnectionFindSecretFunc callback, gpointer callback_data) { gs_unref_variant GVariant *dummy = NULL; FindSecretData data = { - .find_func = callback, - .find_func_data = callback_data, - .found = FALSE, + .find_func = callback, + .find_func_data = callback_data, + .found = FALSE, }; dummy = _nm_connection_for_each_secret(self, secrets, FALSE, find_secret_for_each_func, &data); @@ -2600,7 +2600,7 @@ nm_connection_to_dbus(NMConnection *connection, NMConnectionSerializationFlags f } GVariant * -nm_connection_to_dbus_full(NMConnection * connection, +nm_connection_to_dbus_full(NMConnection *connection, NMConnectionSerializationFlags flags, const NMConnectionSerializationOptions *options) { @@ -2618,7 +2618,7 @@ nm_connection_to_dbus_full(NMConnection * connection, for (i = 0; i < (int) _NM_META_SETTING_TYPE_NUM; i++) { NMSetting *setting = priv->settings[nm_meta_setting_types_by_priority[i]]; - GVariant * setting_dict; + GVariant *setting_dict; if (!setting) continue; @@ -2702,7 +2702,7 @@ NMSetting ** nm_connection_get_settings(NMConnection *connection, guint *out_length) { NMConnectionPrivate *priv; - NMSetting ** arr; + NMSetting **arr; int len; int i; int j; @@ -2746,7 +2746,7 @@ nm_connection_get_settings(NMConnection *connection, guint *out_length) * calling the supplied user function for each property. **/ void -nm_connection_for_each_setting_value(NMConnection * connection, +nm_connection_for_each_setting_value(NMConnection *connection, NMSettingValueIterFn func, gpointer user_data) { @@ -2931,7 +2931,7 @@ nm_connection_get_interface_name(NMConnection *connection) NMConnectionMultiConnect _nm_connection_get_multi_connect(NMConnection *connection) { - NMSettingConnection * s_con; + NMSettingConnection *s_con; NMConnectionMultiConnect multi_connect; const NMConnectionMultiConnect DEFAULT = NM_CONNECTION_MULTI_CONNECT_SINGLE; diff --git a/src/libnm-core-impl/nm-crypto-gnutls.c b/src/libnm-core-impl/nm-crypto-gnutls.c index 88b123ad..d9e59136 100644 --- a/src/libnm-core-impl/nm-crypto-gnutls.c +++ b/src/libnm-core-impl/nm-crypto-gnutls.c @@ -68,14 +68,14 @@ _nm_crypto_init(GError **error) guint8 * _nmtst_crypto_decrypt(NMCryptoCipherType cipher, - const guint8 * data, + const guint8 *data, gsize data_len, - const guint8 * iv, + const guint8 *iv, gsize iv_len, - const guint8 * key, + const guint8 *key, gsize key_len, - gsize * out_len, - GError ** error) + gsize *out_len, + GError **error) { gnutls_cipher_hd_t ctx; gnutls_datum_t key_dt, iv_dt; @@ -168,14 +168,14 @@ _nmtst_crypto_decrypt(NMCryptoCipherType cipher, guint8 * _nmtst_crypto_encrypt(NMCryptoCipherType cipher, - const guint8 * data, + const guint8 *data, gsize data_len, - const guint8 * iv, + const guint8 *iv, gsize iv_len, - const guint8 * key, + const guint8 *key, gsize key_len, - gsize * out_len, - GError ** error) + gsize *out_len, + GError **error) { gnutls_cipher_hd_t ctx; gnutls_datum_t key_dt, iv_dt; @@ -350,8 +350,8 @@ gboolean _nm_crypto_verify_pkcs8(const guint8 *data, gsize data_len, gboolean is_encrypted, - const char * password, - GError ** error) + const char *password, + GError **error) { gnutls_x509_privkey_t p8; gnutls_datum_t dt; diff --git a/src/libnm-core-impl/nm-crypto-impl.h b/src/libnm-core-impl/nm-crypto-impl.h index 0fd8f194..61c3f7f8 100644 --- a/src/libnm-core-impl/nm-crypto-impl.h +++ b/src/libnm-core-impl/nm-crypto-impl.h @@ -21,29 +21,29 @@ _nm_crypto_verify_pkcs12(const guint8 *data, gsize data_len, const char *passwor gboolean _nm_crypto_verify_pkcs8(const guint8 *data, gsize data_len, gboolean is_encrypted, - const char * password, - GError ** error); + const char *password, + GError **error); /*****************************************************************************/ guint8 *_nmtst_crypto_encrypt(NMCryptoCipherType cipher, - const guint8 * data, + const guint8 *data, gsize data_len, - const guint8 * iv, + const guint8 *iv, gsize iv_len, - const guint8 * key, + const guint8 *key, gsize key_len, - gsize * out_len, - GError ** error); + gsize *out_len, + GError **error); guint8 *_nmtst_crypto_decrypt(NMCryptoCipherType cipher, - const guint8 * data, + const guint8 *data, gsize data_len, - const guint8 * iv, + const guint8 *iv, gsize iv_len, - const guint8 * key, + const guint8 *key, gsize key_len, - gsize * out_len, - GError ** error); + gsize *out_len, + GError **error); #endif /* __NM_CRYPTO_IMPL_H__ */ diff --git a/src/libnm-core-impl/nm-crypto-nss.c b/src/libnm-core-impl/nm-crypto-nss.c index e59a11b9..c27bf09e 100644 --- a/src/libnm-core-impl/nm-crypto-nss.c +++ b/src/libnm-core-impl/nm-crypto-nss.c @@ -28,7 +28,7 @@ NM_PRAGMA_WARNING_REENABLE static gboolean _get_cipher_info(NMCryptoCipherType cipher, CK_MECHANISM_TYPE *out_cipher_mech, - guint8 * out_real_iv_len) + guint8 *out_real_iv_len) { static const CK_MECHANISM_TYPE cipher_mechs[] = { [NM_CRYPTO_CIPHER_DES_EDE3_CBC] = CKM_DES3_CBC_PAD, @@ -87,21 +87,21 @@ _nm_crypto_init(GError **error) guint8 * _nmtst_crypto_decrypt(NMCryptoCipherType cipher, - const guint8 * data, + const guint8 *data, gsize data_len, - const guint8 * iv, + const guint8 *iv, gsize iv_len, - const guint8 * key, + const guint8 *key, gsize key_len, - gsize * out_len, - GError ** error) + gsize *out_len, + GError **error) { CK_MECHANISM_TYPE cipher_mech; - PK11SlotInfo * slot = NULL; + PK11SlotInfo *slot = NULL; SECItem key_item; - PK11SymKey * sym_key = NULL; - SECItem * sec_param = NULL; - PK11Context * ctx = NULL; + PK11SymKey *sym_key = NULL; + SECItem *sec_param = NULL; + PK11Context *ctx = NULL; nm_auto_clear_secret_ptr NMSecretPtr output = {0}; SECStatus s; gboolean success = FALSE; @@ -258,23 +258,23 @@ out: guint8 * _nmtst_crypto_encrypt(NMCryptoCipherType cipher, - const guint8 * data, + const guint8 *data, gsize data_len, - const guint8 * iv, + const guint8 *iv, gsize iv_len, - const guint8 * key, + const guint8 *key, gsize key_len, - gsize * out_len, - GError ** error) + gsize *out_len, + GError **error) { SECStatus ret; CK_MECHANISM_TYPE cipher_mech = CKM_DES3_CBC_PAD; - PK11SlotInfo * slot = NULL; + PK11SlotInfo *slot = NULL; SECItem key_item = {.data = (unsigned char *) key, .len = key_len}; SECItem iv_item = {.data = (unsigned char *) iv, .len = iv_len}; - PK11SymKey * sym_key = NULL; - SECItem * sec_param = NULL; - PK11Context * ctx = NULL; + PK11SymKey *sym_key = NULL; + SECItem *sec_param = NULL; + PK11Context *ctx = NULL; nm_auto_clear_secret_ptr NMSecretPtr padded_buf = {0}; nm_auto_clear_secret_ptr NMSecretPtr output = {0}; int encrypted_len = 0, i; @@ -409,7 +409,7 @@ _nm_crypto_verify_pkcs12(const guint8 *data, gsize data_len, const char *passwor { SEC_PKCS12DecoderContext *p12ctx = NULL; SECItem pw = {0}; - PK11SlotInfo * slot = NULL; + PK11SlotInfo *slot = NULL; SECStatus s; gboolean success = FALSE; @@ -513,8 +513,8 @@ gboolean _nm_crypto_verify_pkcs8(const guint8 *data, gsize data_len, gboolean is_encrypted, - const char * password, - GError ** error) + const char *password, + GError **error) { g_return_val_if_fail(data != NULL, FALSE); diff --git a/src/libnm-core-impl/nm-crypto.c b/src/libnm-core-impl/nm-crypto.c index ea17449f..78f793bd 100644 --- a/src/libnm-core-impl/nm-crypto.c +++ b/src/libnm-core-impl/nm-crypto.c @@ -44,9 +44,9 @@ static const NMCryptoCipherInfo cipher_infos[] = { #define _CI(_cipher, _name, _digest_len, _real_iv_len) \ - [(_cipher) -1] = {.cipher = _cipher, \ - .name = ""_name \ - "", \ + [(_cipher) -1] = {.cipher = _cipher, \ + .name = ""_name \ + "", \ .digest_len = _digest_len, \ .real_iv_len = _real_iv_len} _CI(NM_CRYPTO_CIPHER_DES_EDE3_CBC, "DES-EDE3-CBC", 24, 8), @@ -166,26 +166,26 @@ _extract_line(const guint8 **p, const guint8 *p_end) } static gboolean -parse_old_openssl_key_file(const guint8 * data, +parse_old_openssl_key_file(const guint8 *data, gsize data_len, - NMSecretPtr * out_parsed, - NMCryptoKeyType * out_key_type, + NMSecretPtr *out_parsed, + NMCryptoKeyType *out_key_type, NMCryptoCipherType *out_cipher, - char ** out_iv, - GError ** error) + char **out_iv, + GError **error) { gsize start = 0, end = 0; - nm_auto_free_secret char * str = NULL; - char * str_p; + nm_auto_free_secret char *str = NULL; + char *str_p; gsize str_len; int enc_tags = 0; NMCryptoKeyType key_type; nm_auto_clear_secret_ptr NMSecretPtr parsed = {0}; - nm_auto_free_secret char * iv = NULL; + nm_auto_free_secret char *iv = NULL; NMCryptoCipherType cipher = NM_CRYPTO_CIPHER_UNKNOWN; - const char * start_tag; - const char * end_tag; - const guint8 * data_start, *data_end; + const char *start_tag; + const char *end_tag; + const guint8 *data_start, *data_end; nm_assert(!out_parsed || (out_parsed->len == 0 && !out_parsed->bin)); nm_assert(!out_iv || !*out_iv); @@ -229,7 +229,7 @@ parse_old_openssl_key_file(const guint8 * data, while (data_start < data_end) { nm_auto_free_secret char *line = NULL; - char * p; + char *p; line = _extract_line(&data_start, data_end); if (!line) @@ -257,7 +257,7 @@ parse_old_openssl_key_file(const guint8 * data, } } else if (!strncmp(p, DEK_INFO_TAG, strlen(DEK_INFO_TAG))) { const NMCryptoCipherInfo *cipher_info; - char * comma; + char *comma; gsize p_len; if (enc_tags++ != 1 || str_p != str) { @@ -335,12 +335,12 @@ parse_old_openssl_key_file(const guint8 * data, static gboolean parse_pkcs8_key_file(const guint8 *data, gsize data_len, - NMSecretPtr * parsed, - gboolean * out_encrypted, - GError ** error) + NMSecretPtr *parsed, + gboolean *out_encrypted, + GError **error) { gsize start = 0, end = 0; - const char * start_tag = NULL, *end_tag = NULL; + const char *start_tag = NULL, *end_tag = NULL; gboolean encrypted = FALSE; nm_auto_free_secret char *der_base64 = NULL; @@ -396,8 +396,8 @@ parse_pkcs8_key_file(const guint8 *data, static gboolean parse_tpm2_wrapped_key_file(const guint8 *data, gsize data_len, - gboolean * out_encrypted, - GError ** error) + gboolean *out_encrypted, + GError **error) { gsize start = 0, end = 0; const char *start_tag = NULL, *end_tag = NULL; @@ -467,7 +467,7 @@ nm_crypto_read_file(const char *filename, GError **error) static guint8 * _nmtst_convert_iv(const char *src, gsize *out_len, GError **error) { - gsize i, num; + gsize i, num; gs_free guint8 *c = NULL; int c0, c1; @@ -508,13 +508,13 @@ _nmtst_convert_iv(const char *src, gsize *out_len, GError **error) guint8 * nmtst_crypto_make_des_aes_key(NMCryptoCipherType cipher, - const guint8 * salt, + const guint8 *salt, gsize salt_len, - const char * password, - gsize * out_len, - GError ** error) + const char *password, + gsize *out_len, + GError **error) { - guint8 * key; + guint8 *key; const NMCryptoCipherInfo *cipher_info; g_return_val_if_fail(salt != NULL, NULL); @@ -546,12 +546,12 @@ nmtst_crypto_make_des_aes_key(NMCryptoCipherType cipher, static gboolean _nmtst_decrypt_key(NMCryptoCipherType cipher, - const guint8 * data, + const guint8 *data, gsize data_len, - const char * iv, - const char * password, - NMSecretPtr * parsed, - GError ** error) + const char *iv, + const char *password, + NMSecretPtr *parsed, + GError **error) { nm_auto_clear_secret_ptr NMSecretPtr bin_iv = {0}; nm_auto_clear_secret_ptr NMSecretPtr key = {0}; @@ -599,15 +599,15 @@ _nmtst_decrypt_key(NMCryptoCipherType cipher, } GBytes * -nmtst_crypto_decrypt_openssl_private_key_data(const guint8 * data, +nmtst_crypto_decrypt_openssl_private_key_data(const guint8 *data, gsize data_len, - const char * password, + const char *password, NMCryptoKeyType *out_key_type, - GError ** error) + GError **error) { NMCryptoKeyType key_type = NM_CRYPTO_KEY_TYPE_UNKNOWN; nm_auto_clear_secret_ptr NMSecretPtr parsed = {0}; - nm_auto_free_secret char * iv = NULL; + nm_auto_free_secret char *iv = NULL; NMCryptoCipherType cipher = NM_CRYPTO_CIPHER_UNKNOWN; g_return_val_if_fail(data != NULL, NULL); @@ -651,10 +651,10 @@ nmtst_crypto_decrypt_openssl_private_key_data(const guint8 * data, } GBytes * -nmtst_crypto_decrypt_openssl_private_key(const char * file, - const char * password, +nmtst_crypto_decrypt_openssl_private_key(const char *file, + const char *password, NMCryptoKeyType *out_key_type, - GError ** error) + GError **error) { nm_auto_clear_secret_ptr NMSecretPtr contents = {0}; @@ -674,8 +674,8 @@ nmtst_crypto_decrypt_openssl_private_key(const char * file, static gboolean extract_pem_cert_data(const guint8 *contents, gsize contents_len, - NMSecretPtr * out_cert, - GError ** error) + NMSecretPtr *out_cert, + GError **error) { gsize start = 0; gsize end = 0; @@ -722,10 +722,10 @@ extract_pem_cert_data(const guint8 *contents, } gboolean -nm_crypto_load_and_verify_certificate(const char * file, +nm_crypto_load_and_verify_certificate(const char *file, NMCryptoFileFormat *out_file_format, - GBytes ** out_certificate, - GError ** error) + GBytes **out_certificate, + GError **error) { nm_auto_clear_secret_ptr NMSecretPtr contents = {0}; @@ -786,7 +786,7 @@ out: gboolean nm_crypto_is_pkcs12_data(const guint8 *data, gsize data_len, GError **error) { - GError * local = NULL; + GError *local = NULL; gboolean success; if (!data_len) { @@ -838,9 +838,9 @@ nm_crypto_is_pkcs12_file(const char *file, GError **error) NMCryptoFileFormat nm_crypto_verify_private_key_data(const guint8 *data, gsize data_len, - const char * password, - gboolean * out_is_encrypted, - GError ** error) + const char *password, + gboolean *out_is_encrypted, + GError **error) { NMCryptoFileFormat format = NM_CRYPTO_FILE_FORMAT_UNKNOWN; gboolean is_encrypted = FALSE; @@ -894,8 +894,8 @@ nm_crypto_verify_private_key_data(const guint8 *data, NMCryptoFileFormat nm_crypto_verify_private_key(const char *filename, const char *password, - gboolean * out_is_encrypted, - GError ** error) + gboolean *out_is_encrypted, + GError **error) { nm_auto_clear_secret_ptr NMSecretPtr contents = {0}; @@ -939,21 +939,21 @@ nm_crypto_randomize(void *buffer, gsize buffer_len, GError **error) GBytes * nmtst_crypto_rsa_key_encrypt(const guint8 *data, gsize len, - const char * in_password, - char ** out_password, - GError ** error) + const char *in_password, + char **out_password, + GError **error) { guint8 salt[8]; - nm_auto_clear_secret_ptr NMSecretPtr key = {0}; - nm_auto_clear_secret_ptr NMSecretPtr enc = {0}; - gs_unref_ptrarray GPtrArray *pem = NULL; - nm_auto_free_secret char * tmp_password = NULL; - nm_auto_free_secret char * enc_base64 = NULL; - gsize enc_base64_len; - const char * p; - gsize ret_len, ret_idx; - guint i; - NMSecretBuf * ret; + nm_auto_clear_secret_ptr NMSecretPtr key = {0}; + nm_auto_clear_secret_ptr NMSecretPtr enc = {0}; + gs_unref_ptrarray GPtrArray *pem = NULL; + nm_auto_free_secret char *tmp_password = NULL; + nm_auto_free_secret char *enc_base64 = NULL; + gsize enc_base64_len; + const char *p; + gsize ret_len, ret_idx; + guint i; + NMSecretBuf *ret; g_return_val_if_fail(data, NULL); g_return_val_if_fail(len > 0, NULL); diff --git a/src/libnm-core-impl/nm-crypto.h b/src/libnm-core-impl/nm-crypto.h index 855e4f9c..a740c43c 100644 --- a/src/libnm-core-impl/nm-crypto.h +++ b/src/libnm-core-impl/nm-crypto.h @@ -17,7 +17,7 @@ typedef enum { } NMCryptoCipherType; typedef struct { - const char * name; + const char *name; NMCryptoCipherType cipher; guint8 digest_len; guint8 real_iv_len; @@ -43,10 +43,10 @@ typedef enum { GBytes *nm_crypto_read_file(const char *filename, GError **error); -gboolean nm_crypto_load_and_verify_certificate(const char * file, +gboolean nm_crypto_load_and_verify_certificate(const char *file, NMCryptoFileFormat *out_file_format, - GBytes ** out_certificat, - GError ** error); + GBytes **out_certificat, + GError **error); gboolean nm_crypto_is_pkcs12_file(const char *file, GError **error); @@ -54,42 +54,42 @@ gboolean nm_crypto_is_pkcs12_data(const guint8 *data, gsize len, GError **error) NMCryptoFileFormat nm_crypto_verify_private_key_data(const guint8 *data, gsize data_len, - const char * password, - gboolean * out_is_encrypted, - GError ** error); + const char *password, + gboolean *out_is_encrypted, + GError **error); NMCryptoFileFormat nm_crypto_verify_private_key(const char *file, const char *password, - gboolean * out_is_encrypted, - GError ** error); + gboolean *out_is_encrypted, + GError **error); gboolean nm_crypto_randomize(void *buffer, gsize buffer_len, GError **error); /*****************************************************************************/ -GBytes *nmtst_crypto_decrypt_openssl_private_key_data(const guint8 * data, +GBytes *nmtst_crypto_decrypt_openssl_private_key_data(const guint8 *data, gsize data_len, - const char * password, + const char *password, NMCryptoKeyType *out_key_type, - GError ** error); + GError **error); -GBytes *nmtst_crypto_decrypt_openssl_private_key(const char * file, - const char * password, +GBytes *nmtst_crypto_decrypt_openssl_private_key(const char *file, + const char *password, NMCryptoKeyType *out_key_type, - GError ** error); + GError **error); GBytes *nmtst_crypto_rsa_key_encrypt(const guint8 *data, gsize len, - const char * in_password, - char ** out_password, - GError ** error); + const char *in_password, + char **out_password, + GError **error); guint8 *nmtst_crypto_make_des_aes_key(NMCryptoCipherType cipher, - const guint8 * salt, + const guint8 *salt, gsize salt_len, - const char * password, - gsize * out_len, - GError ** error); + const char *password, + gsize *out_len, + GError **error); /*****************************************************************************/ diff --git a/src/libnm-core-impl/nm-dbus-utils.c b/src/libnm-core-impl/nm-dbus-utils.c index a272f08c..c9443ff9 100644 --- a/src/libnm-core-impl/nm-dbus-utils.c +++ b/src/libnm-core-impl/nm-dbus-utils.c @@ -8,7 +8,7 @@ #include "libnm-core-intern/nm-core-internal.h" typedef struct { - char * signal_name; + char *signal_name; const GVariantType *signature; } NMDBusSignalData; @@ -22,17 +22,17 @@ dbus_signal_data_free(gpointer data, GClosure *closure) } static void -dbus_signal_meta_marshal(GClosure * closure, - GValue * return_value, +dbus_signal_meta_marshal(GClosure *closure, + GValue *return_value, guint n_param_values, const GValue *param_values, gpointer invocation_hint, gpointer marshal_data) { NMDBusSignalData *sd = marshal_data; - const char * signal_name; - GVariant * parameters, *param; - GValue * closure_params; + const char *signal_name; + GVariant *parameters, *param; + GValue *closure_params; gsize n_params, i; g_return_if_fail(n_param_values == 4); @@ -110,8 +110,8 @@ dbus_signal_meta_marshal(GClosure * closure, * g_signal_handlers_disconnect_by_data() will work correctly. */ gulong -_nm_dbus_signal_connect_data(GDBusProxy * proxy, - const char * signal_name, +_nm_dbus_signal_connect_data(GDBusProxy *proxy, + const char *signal_name, const GVariantType *signature, GCallback c_handler, gpointer data, @@ -119,7 +119,7 @@ _nm_dbus_signal_connect_data(GDBusProxy * proxy, GConnectFlags connect_flags) { NMDBusSignalData *sd; - GClosure * closure; + GClosure *closure; gboolean swapped = !!(connect_flags & G_CONNECT_SWAPPED); gboolean after = !!(connect_flags & G_CONNECT_AFTER); @@ -201,10 +201,10 @@ _nm_dbus_typecheck_response(GVariant *response, const GVariantType *reply_type, * return values. Free with g_variant_unref(). */ GVariant * -_nm_dbus_proxy_call_finish(GDBusProxy * proxy, - GAsyncResult * res, +_nm_dbus_proxy_call_finish(GDBusProxy *proxy, + GAsyncResult *res, const GVariantType *reply_type, - GError ** error) + GError **error) { GVariant *variant; @@ -215,10 +215,10 @@ _nm_dbus_proxy_call_finish(GDBusProxy * proxy, } GVariant * -_nm_dbus_connection_call_finish(GDBusConnection * dbus_connection, - GAsyncResult * result, +_nm_dbus_connection_call_finish(GDBusConnection *dbus_connection, + GAsyncResult *result, const GVariantType *reply_type, - GError ** error) + GError **error) { GVariant *variant; diff --git a/src/libnm-core-impl/nm-keyfile-utils.c b/src/libnm-core-impl/nm-keyfile-utils.c index f8c2f387..0e2e2d45 100644 --- a/src/libnm-core-impl/nm-keyfile-utils.c +++ b/src/libnm-core-impl/nm-keyfile-utils.c @@ -107,15 +107,15 @@ nm_keyfile_plugin_get_setting_name_for_alias(const char *alias) /*****************************************************************************/ char ** -nm_keyfile_plugin_kf_get_string_list(GKeyFile * kf, +nm_keyfile_plugin_kf_get_string_list(GKeyFile *kf, const char *group, const char *key, - gsize * out_length, - GError ** error) + gsize *out_length, + GError **error) { - char ** list; + char **list; const char *alias; - GError * local = NULL; + GError *local = NULL; gsize l; list = g_key_file_get_string_list(kf, group, key, &l, &local); @@ -135,16 +135,16 @@ nm_keyfile_plugin_kf_get_string_list(GKeyFile * kf, } guint * -nm_keyfile_plugin_kf_get_integer_list_uint(GKeyFile * key_file, +nm_keyfile_plugin_kf_get_integer_list_uint(GKeyFile *key_file, const char *group_name, const char *key, - gsize * out_length, - GError ** error) + gsize *out_length, + GError **error) { - GError * key_file_error = NULL; + GError *key_file_error = NULL; gs_strfreev char **values = NULL; - gs_free guint *int_values = NULL; - gsize i, num_ints; + gs_free guint *int_values = NULL; + gsize i, num_ints; NM_SET_OUT(out_length, 0); @@ -183,9 +183,9 @@ nm_keyfile_plugin_kf_get_integer_list_uint(GKeyFile * key_file, } void -nm_keyfile_plugin_kf_set_string_list(GKeyFile * kf, - const char * group, - const char * key, +nm_keyfile_plugin_kf_set_string_list(GKeyFile *kf, + const char *group, + const char *key, const char *const *list, gsize length) { @@ -196,9 +196,9 @@ nm_keyfile_plugin_kf_set_string_list(GKeyFile * kf, } void -nm_keyfile_plugin_kf_set_integer_list_uint(GKeyFile * kf, - const char * group, - const char * key, +nm_keyfile_plugin_kf_set_integer_list_uint(GKeyFile *kf, + const char *group, + const char *key, const guint *data, gsize length) { @@ -217,9 +217,9 @@ nm_keyfile_plugin_kf_set_integer_list_uint(GKeyFile * kf, } void -nm_keyfile_plugin_kf_set_integer_list_uint8(GKeyFile * kf, - const char * group, - const char * key, +nm_keyfile_plugin_kf_set_integer_list_uint8(GKeyFile *kf, + const char *group, + const char *key, const guint8 *data, gsize length) { @@ -242,7 +242,7 @@ nm_keyfile_plugin_kf_set_integer_list_uint8(GKeyFile * kf, { \ get_ctype val; \ const char *alias; \ - GError * local = NULL; \ + GError *local = NULL; \ \ val = key_file_get_fcn(kf, group, key, &local); \ if (nm_g_error_matches(local, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND)) { \ @@ -275,14 +275,14 @@ DEFINE_KF_WRAPPER_SET(nm_keyfile_plugin_kf_set_boolean, gboolean, g_key_file_set DEFINE_KF_WRAPPER_SET(nm_keyfile_plugin_kf_set_value, const char *, g_key_file_set_value); gint64 -nm_keyfile_plugin_kf_get_int64(GKeyFile * kf, +nm_keyfile_plugin_kf_get_int64(GKeyFile *kf, const char *group, const char *key, guint base, gint64 min, gint64 max, gint64 fallback, - GError ** error) + GError **error) { gs_free char *s = NULL; int errsv; @@ -311,9 +311,9 @@ nm_keyfile_plugin_kf_get_int64(GKeyFile * kf, char ** nm_keyfile_plugin_kf_get_keys(GKeyFile *kf, const char *group, gsize *out_length, GError **error) { - char ** keys; + char **keys; const char *alias; - GError * local = NULL; + GError *local = NULL; gsize l; keys = g_key_file_get_keys(kf, group, &l, &local); @@ -339,7 +339,7 @@ nm_keyfile_plugin_kf_has_key(GKeyFile *kf, const char *group, const char *key, G { gboolean has; const char *alias; - GError * local = NULL; + GError *local = NULL; has = g_key_file_has_key(kf, group, key, &local); if (nm_g_error_matches(local, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND)) { @@ -364,7 +364,7 @@ _nm_keyfile_copy(GKeyFile *dst, GKeyFile *src) groups = g_key_file_get_groups(src, NULL); for (g = 0; groups && groups[g]; g++) { - const char * group = groups[g]; + const char *group = groups[g]; gs_strfreev char **keys = NULL; keys = g_key_file_get_keys(src, group, NULL, NULL); @@ -372,7 +372,7 @@ _nm_keyfile_copy(GKeyFile *dst, GKeyFile *src) continue; for (k = 0; keys[k]; k++) { - const char * key = keys[k]; + const char *key = keys[k]; gs_free char *value = NULL; value = g_key_file_get_value(src, group, key, NULL); @@ -644,7 +644,7 @@ nm_keyfile_key_encode(const char *name, char **out_to_free) nm_assert(!*out_to_free || !nm_streq0(name, key)); { gs_free char *to_free2 = NULL; - const char * name2; + const char *name2; name2 = _keyfile_key_decode(key, &to_free2); /* name2, the result of encode()+decode() is identical to name. @@ -669,7 +669,7 @@ nm_keyfile_key_decode(const char *key, char **out_to_free) nm_assert(!*out_to_free || name == *out_to_free); { gs_free char *to_free2 = NULL; - const char * key2; + const char *key2; key2 = _keyfile_key_encode(name, &to_free2); /* key2, the result of decode+encode may not be identical diff --git a/src/libnm-core-impl/nm-keyfile.c b/src/libnm-core-impl/nm-keyfile.c index 1171ab03..4ff9b582 100644 --- a/src/libnm-core-impl/nm-keyfile.c +++ b/src/libnm-core-impl/nm-keyfile.c @@ -41,22 +41,22 @@ typedef struct _ParseInfoProperty ParseInfoProperty; typedef struct { - NMConnection * connection; - GKeyFile * keyfile; - const char * base_dir; + NMConnection *connection; + GKeyFile *keyfile; + const char *base_dir; NMKeyfileReadHandler read_handler; - void * user_data; - GError * error; - const char * group; - NMSetting * setting; + void *user_data; + GError *error; + const char *group; + NMSetting *setting; } KeyfileReaderInfo; typedef struct { - NMConnection * connection; - GKeyFile * keyfile; - GError * error; + NMConnection *connection; + GKeyFile *keyfile; + GError *error; NMKeyfileWriteHandler write_handler; - void * user_data; + void *user_data; } KeyfileWriterInfo; /*****************************************************************************/ @@ -64,11 +64,11 @@ typedef struct { static void _key_file_handler_data_init(NMKeyfileHandlerData *handler_data, NMKeyfileHandlerType handler_type, - const char * kf_group_name, - const char * kf_key, - NMSetting * cur_setting, - const char * cur_property, - GError ** p_error) + const char *kf_group_name, + const char *kf_key, + NMSetting *cur_setting, + const char *cur_property, + GError **p_error) { nm_assert(handler_data); nm_assert(p_error && !*p_error); @@ -84,9 +84,9 @@ _key_file_handler_data_init(NMKeyfileHandlerData *handler_data, static void _key_file_handler_data_init_read(NMKeyfileHandlerData *handler_data, NMKeyfileHandlerType handler_type, - KeyfileReaderInfo * info, - const char * kf_key, - const char * cur_property) + KeyfileReaderInfo *info, + const char *kf_key, + const char *cur_property) { _key_file_handler_data_init(handler_data, handler_type, @@ -100,11 +100,11 @@ _key_file_handler_data_init_read(NMKeyfileHandlerData *handler_data, static void _key_file_handler_data_init_write(NMKeyfileHandlerData *handler_data, NMKeyfileHandlerType handler_type, - KeyfileWriterInfo * info, - const char * kf_group, - const char * kf_key, - NMSetting * cur_setting, - const char * cur_property) + KeyfileWriterInfo *info, + const char *kf_group, + const char *kf_key, + NMSetting *cur_setting, + const char *cur_property) { _key_file_handler_data_init(handler_data, handler_type, @@ -115,11 +115,11 @@ _key_file_handler_data_init_write(NMKeyfileHandlerData *handler_data, &info->error); } -_nm_printf(5, 6) static void _handle_warn(KeyfileReaderInfo * info, - const char * kf_key, - const char * cur_property, +_nm_printf(5, 6) static void _handle_warn(KeyfileReaderInfo *info, + const char *kf_key, + const char *cur_property, NMKeyfileWarnSeverity severity, - const char * fmt, + const char *fmt, ...) { NMKeyfileHandlerData handler_data; @@ -178,8 +178,8 @@ _secret_flags_persist_secret(NMSettingSecretFlags flags) static void setting_alias_parser(KeyfileReaderInfo *info, NMSetting *setting, const char *key) { - const char * setting_name = nm_setting_get_name(setting); - const char * key_setting_name; + const char *setting_name = nm_setting_get_name(setting); + const char *key_setting_name; gs_free char *s = NULL; s = nm_keyfile_plugin_kf_get_string(info->keyfile, setting_name, key, NULL); @@ -193,10 +193,10 @@ setting_alias_parser(KeyfileReaderInfo *info, NMSetting *setting, const char *ke static void sriov_vfs_parser(KeyfileReaderInfo *info, NMSetting *setting, const char *key) { - const char * setting_name = nm_setting_get_name(setting); - gs_unref_ptrarray GPtrArray *vfs = NULL; - gs_strfreev char ** keys = NULL; - gsize n_keys = 0; + const char *setting_name = nm_setting_get_name(setting); + gs_unref_ptrarray GPtrArray *vfs = NULL; + gs_strfreev char **keys = NULL; + gsize n_keys = 0; int i; keys = nm_keyfile_plugin_kf_get_keys(info->keyfile, setting_name, &n_keys, NULL); @@ -207,8 +207,8 @@ sriov_vfs_parser(KeyfileReaderInfo *info, NMSetting *setting, const char *key) for (i = 0; i < n_keys; i++) { gs_free char *value = NULL; - NMSriovVF * vf; - const char * rest; + NMSriovVF *vf; + const char *rest; if (!g_str_has_prefix(keys[i], "vf.")) continue; @@ -232,9 +232,9 @@ static void read_array_of_uint(GKeyFile *file, NMSetting *setting, const char *key) { gs_unref_array GArray *array = NULL; - gs_free_error GError *error = NULL; - gs_free guint *tmp = NULL; - gsize length; + gs_free_error GError *error = NULL; + gs_free guint *tmp = NULL; + gsize length; tmp = nm_keyfile_plugin_kf_get_integer_list_uint(file, nm_setting_get_name(setting), @@ -251,11 +251,11 @@ read_array_of_uint(GKeyFile *file, NMSetting *setting, const char *key) static gboolean get_one_int(KeyfileReaderInfo *info, - const char * kf_key, - const char * property_name, - const char * str, + const char *kf_key, + const char *property_name, + const char *str, guint32 max_val, - guint32 * out) + guint32 *out) { gint64 tmp; @@ -292,14 +292,14 @@ get_one_int(KeyfileReaderInfo *info, static gpointer build_address(KeyfileReaderInfo *info, - const char * kf_key, - const char * property_name, + const char *kf_key, + const char *property_name, int family, - const char * address_str, + const char *address_str, guint32 plen) { NMIPAddress *addr; - GError * error = NULL; + GError *error = NULL; g_return_val_if_fail(address_str, NULL); @@ -320,18 +320,18 @@ build_address(KeyfileReaderInfo *info, static gpointer build_route(KeyfileReaderInfo *info, - const char * kf_key, - const char * property_name, + const char *kf_key, + const char *property_name, int family, - const char * dest_str, + const char *dest_str, guint32 plen, - const char * gateway_str, - const char * metric_str) + const char *gateway_str, + const char *metric_str) { NMIPRoute *route; guint32 u32; gint64 metric = -1; - GError * error = NULL; + GError *error = NULL; g_return_val_if_fail(dest_str, NULL); @@ -455,7 +455,7 @@ read_field(char **current, const char **out_err_str, const char *characters, con static void openconnect_fix_secret_flags(NMSetting *setting) { - NMSettingVpn * s_vpn; + NMSettingVpn *s_vpn; NMSettingSecretFlags flags; /* Huge hack. There were some openconnect changes that needed to happen @@ -518,22 +518,22 @@ openconnect_fix_secret_flags(NMSetting *setting) */ static gpointer read_one_ip_address_or_route(KeyfileReaderInfo *info, - const char * property_name, - const char * setting_name, - const char * kf_key, + const char *property_name, + const char *setting_name, + const char *kf_key, gboolean ipv6, gboolean route, - char ** out_gateway, - NMSetting * setting) + char **out_gateway, + NMSetting *setting) { guint plen; gpointer result; - const char * address_str; - const char * plen_str; - const char * gateway_str; - const char * metric_str; - const char * err_str = NULL; - char * current; + const char *address_str; + const char *plen_str; + const char *gateway_str; + const char *metric_str; + const char *err_str = NULL; + char *current; gs_free char *value = NULL; gs_free char *value_orig = NULL; @@ -680,17 +680,17 @@ read_one_ip_address_or_route(KeyfileReaderInfo *info, } static void -fill_route_attributes(GKeyFile * kf, - NMIPRoute * route, +fill_route_attributes(GKeyFile *kf, + NMIPRoute *route, const char *setting, const char *key, int family) { - gs_free char * value = NULL; - gs_unref_hashtable GHashTable *hash = NULL; + gs_free char *value = NULL; + gs_unref_hashtable GHashTable *hash = NULL; GHashTableIter iter; - char * name; - GVariant * variant; + char *name; + GVariant *variant; value = nm_keyfile_plugin_kf_get_string(kf, setting, key, NULL); if (!value || !value[0]) @@ -751,7 +751,7 @@ static gboolean _build_list_match_key_w_name_impl(const char *key, const char *base_name, gsize base_name_l, - gint32 * out_key_idx) + gint32 *out_key_idx) { gint64 v; @@ -798,14 +798,14 @@ _build_list_match_key_w_name_impl(const char *key, _build_list_match_key_w_name_impl(key, base_name, NM_STRLEN(base_name), out_key_idx) static BuildListData * -_build_list_create(GKeyFile * keyfile, - const char * group_name, +_build_list_create(GKeyFile *keyfile, + const char *group_name, BuildListType build_list_type, - gsize * out_build_list_len, - char *** out_keys_strv) + gsize *out_build_list_len, + char ***out_keys_strv) { - gs_strfreev char **keys = NULL; - gsize i_keys, n_keys; + gs_strfreev char **keys = NULL; + gsize i_keys, n_keys; gs_free BuildListData *build_list = NULL; gsize build_list_len = 0; @@ -878,14 +878,14 @@ _build_list_create(GKeyFile * keyfile, static void ip_address_or_route_parser(KeyfileReaderInfo *info, NMSetting *setting, const char *setting_key) { - const char * setting_name = nm_setting_get_name(setting); - gboolean is_ipv6 = nm_streq(setting_name, "ipv6"); - gboolean is_routes = nm_streq(setting_key, "routes"); - gs_free char * gateway = NULL; - gs_unref_ptrarray GPtrArray *list = NULL; - gs_strfreev char ** keys = NULL; - gs_free BuildListData *build_list = NULL; - gsize i_build_list, build_list_len = 0; + const char *setting_name = nm_setting_get_name(setting); + gboolean is_ipv6 = nm_streq(setting_name, "ipv6"); + gboolean is_routes = nm_streq(setting_key, "routes"); + gs_free char *gateway = NULL; + gs_unref_ptrarray GPtrArray *list = NULL; + gs_strfreev char **keys = NULL; + gs_free BuildListData *build_list = NULL; + gsize i_build_list, build_list_len = 0; build_list = _build_list_create(info->keyfile, setting_name, @@ -940,16 +940,16 @@ ip_address_or_route_parser(KeyfileReaderInfo *info, NMSetting *setting, const ch } static void -ip_routing_rule_parser_full(KeyfileReaderInfo * info, - const NMMetaSettingInfo * setting_info, +ip_routing_rule_parser_full(KeyfileReaderInfo *info, + const NMMetaSettingInfo *setting_info, const NMSettInfoProperty *property_info, - const ParseInfoProperty * pip, - NMSetting * setting) + const ParseInfoProperty *pip, + NMSetting *setting) { - const char * setting_name = nm_setting_get_name(setting); - gboolean is_ipv6 = nm_streq(setting_name, "ipv6"); - gs_strfreev char **keys = NULL; - gs_free BuildListData *build_list = NULL; + const char *setting_name = nm_setting_get_name(setting); + gboolean is_ipv6 = nm_streq(setting_name, "ipv6"); + gs_strfreev char **keys = NULL; + gs_free BuildListData *build_list = NULL; gsize i_build_list, build_list_len = 0; build_list = _build_list_create(info->keyfile, @@ -962,8 +962,8 @@ ip_routing_rule_parser_full(KeyfileReaderInfo * info, for (i_build_list = 0; i_build_list < build_list_len; i_build_list++) { nm_auto_unref_ip_routing_rule NMIPRoutingRule *rule = NULL; - gs_free char * value = NULL; - gs_free_error GError *local = NULL; + gs_free char *value = NULL; + gs_free_error GError *local = NULL; if (_build_list_data_is_shadowed(build_list, build_list_len, i_build_list)) continue; @@ -999,13 +999,13 @@ ip_routing_rule_parser_full(KeyfileReaderInfo * info, } static void -_parser_full_ovs_external_ids_data(KeyfileReaderInfo * info, - const NMMetaSettingInfo * setting_info, +_parser_full_ovs_external_ids_data(KeyfileReaderInfo *info, + const NMMetaSettingInfo *setting_info, const NMSettInfoProperty *property_info, - const ParseInfoProperty * pip, - NMSetting * setting) + const ParseInfoProperty *pip, + NMSetting *setting) { - const char * setting_name = NM_SETTING_OVS_EXTERNAL_IDS_SETTING_NAME; + const char *setting_name = NM_SETTING_OVS_EXTERNAL_IDS_SETTING_NAME; gs_strfreev char **keys = NULL; gsize n_keys; gsize i; @@ -1018,10 +1018,10 @@ _parser_full_ovs_external_ids_data(KeyfileReaderInfo * info, keys = nm_keyfile_plugin_kf_get_keys(info->keyfile, setting_name, &n_keys, NULL); for (i = 0; i < n_keys; i++) { - const char * key = keys[i]; + const char *key = keys[i]; gs_free char *name_to_free = NULL; gs_free char *value = NULL; - const char * name; + const char *name; if (!NM_STR_HAS_PREFIX(key, OVS_EXTERNAL_IDS_DATA_PREFIX)) continue; @@ -1089,8 +1089,8 @@ static void ip6_addr_gen_mode_parser(KeyfileReaderInfo *info, NMSetting *setting, const char *key) { NMSettingIP6ConfigAddrGenMode addr_gen_mode; - const char * setting_name = nm_setting_get_name(setting); - gs_free char * s = NULL; + const char *setting_name = nm_setting_get_name(setting); + gs_free char *s = NULL; s = nm_keyfile_plugin_kf_get_string(info->keyfile, setting_name, key, NULL); if (s) { @@ -1115,17 +1115,17 @@ ip6_addr_gen_mode_parser(KeyfileReaderInfo *info, NMSetting *setting, const char static void mac_address_parser(KeyfileReaderInfo *info, - NMSetting * setting, - const char * key, + NMSetting *setting, + const char *key, gsize addr_len, gboolean cloned_mac_addr) { - const char * setting_name = nm_setting_get_name(setting); - char addr_str[NM_UTILS_HWADDR_LEN_MAX * 3]; - guint8 addr_bin[NM_UTILS_HWADDR_LEN_MAX]; - gs_free char *tmp_string = NULL; - gs_free guint *int_list = NULL; - const char * mac_str; + const char *setting_name = nm_setting_get_name(setting); + char addr_str[NM_UTILS_HWADDR_LEN_MAX * 3]; + guint8 addr_bin[NM_UTILS_HWADDR_LEN_MAX]; + gs_free char *tmp_string = NULL; + gs_free guint *int_list = NULL; + const char *mac_str; gsize int_list_len; gsize i; @@ -1191,13 +1191,13 @@ mac_address_parser_INFINIBAND(KeyfileReaderInfo *info, NMSetting *setting, const static void read_hash_of_string(KeyfileReaderInfo *info, - GKeyFile * file, - NMSetting * setting, - const char * kf_group) + GKeyFile *file, + NMSetting *setting, + const char *kf_group) { gs_strfreev char **keys = NULL; const char *const *iter; - const char * setting_name = nm_setting_get_name(setting); + const char *setting_name = nm_setting_get_name(setting); gboolean is_vpn; gsize n_keys; @@ -1212,10 +1212,10 @@ read_hash_of_string(KeyfileReaderInfo *info, if ((is_vpn = NM_IS_SETTING_VPN(setting)) || NM_IS_SETTING_BOND(setting)) { for (iter = (const char *const *) keys; *iter; iter++) { - const char * kf_key = *iter; + const char *kf_key = *iter; gs_free char *to_free = NULL; gs_free char *value = NULL; - const char * name; + const char *name; value = nm_keyfile_plugin_kf_get_string(file, setting_name, kf_key, NULL); if (!value) @@ -1256,8 +1256,8 @@ read_hash_of_string(KeyfileReaderInfo *info, data = g_hash_table_new_full(nm_str_hash, g_str_equal, g_free, g_free); for (iter = (const char *const *) keys; *iter; iter++) { gs_free char *to_free = NULL; - char * value = NULL; - const char * name; + char *value = NULL; + const char *name; value = nm_keyfile_plugin_kf_get_string(file, setting_name, *iter, NULL); if (!value) @@ -1288,15 +1288,15 @@ unescape_semicolons(char *str) static GBytes * get_bytes(KeyfileReaderInfo *info, - const char * setting_name, - const char * key, + const char *setting_name, + const char *key, gboolean zero_terminate, gboolean unescape_semicolon) { nm_auto_free_secret char *tmp_string = NULL; gboolean may_be_int_list = TRUE; gsize length; - GBytes * result; + GBytes *result; /* New format: just a string * Old format: integer list; e.g. 11;25;38; @@ -1421,8 +1421,8 @@ get_bytes(KeyfileReaderInfo *info, static void ssid_parser(KeyfileReaderInfo *info, NMSetting *setting, const char *key) { - const char * setting_name = nm_setting_get_name(setting); - gs_unref_bytes GBytes *bytes = NULL; + const char *setting_name = nm_setting_get_name(setting); + gs_unref_bytes GBytes *bytes = NULL; bytes = get_bytes(info, setting_name, key, FALSE, TRUE); if (!bytes) { @@ -1435,8 +1435,8 @@ ssid_parser(KeyfileReaderInfo *info, NMSetting *setting, const char *key) static void password_raw_parser(KeyfileReaderInfo *info, NMSetting *setting, const char *key) { - const char * setting_name = nm_setting_get_name(setting); - gs_unref_bytes GBytes *bytes = NULL; + const char *setting_name = nm_setting_get_name(setting); + gs_unref_bytes GBytes *bytes = NULL; bytes = get_bytes(info, setting_name, key, FALSE, TRUE); if (!bytes) { @@ -1454,7 +1454,7 @@ static char * get_cert_path(const char *base_dir, const guint8 *cert_path, gsize cert_path_len) { const char *base; - char * p = NULL, *path, *tmp; + char *p = NULL, *path, *tmp; g_return_val_if_fail(base_dir != NULL, NULL); g_return_val_if_fail(cert_path != NULL, NULL); @@ -1489,13 +1489,13 @@ has_cert_ext(const char *path) } char * -nm_keyfile_detect_unqualified_path_scheme(const char * base_dir, +nm_keyfile_detect_unqualified_path_scheme(const char *base_dir, gconstpointer pdata, gsize data_len, gboolean consider_exists, - gboolean * out_exists) + gboolean *out_exists) { - const char * data = pdata; + const char *data = pdata; gboolean exists = FALSE; gsize validate_len; gsize path_len, pathuri_len; @@ -1573,11 +1573,11 @@ nm_keyfile_detect_unqualified_path_scheme(const char * base_dir, static void cert_parser(KeyfileReaderInfo *info, NMSetting *setting, const char *key) { - const char * setting_name = nm_setting_get_name(setting); - gs_unref_bytes GBytes *bytes = NULL; - const char * bin = NULL; - gsize bin_len = 0; - char * path; + const char *setting_name = nm_setting_get_name(setting); + gs_unref_bytes GBytes *bytes = NULL; + const char *bin = NULL; + gsize bin_len = 0; + char *path; gboolean path_exists; bytes = get_bytes(info, setting_name, key, TRUE, FALSE); @@ -1591,7 +1591,7 @@ cert_parser(KeyfileReaderInfo *info, NMSetting *setting, const char *key) } if (HAS_SCHEME_PREFIX(bin, bin_len, NM_KEYFILE_CERT_SCHEME_PREFIX_PATH)) { - const char * path2 = &bin[NM_STRLEN(NM_KEYFILE_CERT_SCHEME_PREFIX_PATH)]; + const char *path2 = &bin[NM_STRLEN(NM_KEYFILE_CERT_SCHEME_PREFIX_PATH)]; gs_free char *path2_free = NULL; if (nm_setting_802_1x_check_cert_scheme(bin, bin_len, NULL) @@ -1648,8 +1648,8 @@ cert_parser(KeyfileReaderInfo *info, NMSetting *setting, const char *key) } if (HAS_SCHEME_PREFIX(bin, bin_len, NM_KEYFILE_CERT_SCHEME_PREFIX_BLOB)) { - const char *cdata = bin + NM_STRLEN(NM_KEYFILE_CERT_SCHEME_PREFIX_BLOB); - gsize cdata_len = bin_len - NM_STRLEN(NM_KEYFILE_CERT_SCHEME_PREFIX_BLOB) - 1; + const char *cdata = bin + NM_STRLEN(NM_KEYFILE_CERT_SCHEME_PREFIX_BLOB); + gsize cdata_len = bin_len - NM_STRLEN(NM_KEYFILE_CERT_SCHEME_PREFIX_BLOB) - 1; gs_free guchar *bin_decoded = NULL; gsize bin_decoded_len = 0; gsize i; @@ -1801,10 +1801,10 @@ _parity_from_char(int ch) static void parity_parser(KeyfileReaderInfo *info, NMSetting *setting, const char *key) { - const char * setting_name = nm_setting_get_name(setting); - gs_free_error GError *err = NULL; + const char *setting_name = nm_setting_get_name(setting); + gs_free_error GError *err = NULL; int parity; - gs_free char * tmp_str = NULL; + gs_free char *tmp_str = NULL; gint64 i64; /* Keyfile traditionally stored this as the ASCII value for 'E', 'o', or 'n'. @@ -1869,9 +1869,9 @@ out_err: static void team_config_parser(KeyfileReaderInfo *info, NMSetting *setting, const char *key) { - const char * setting_name = nm_setting_get_name(setting); - gs_free char *conf = NULL; - gs_free_error GError *error = NULL; + const char *setting_name = nm_setting_get_name(setting); + gs_free char *conf = NULL; + gs_free_error GError *error = NULL; conf = nm_keyfile_plugin_kf_get_string(info->keyfile, setting_name, key, NULL); @@ -1892,11 +1892,11 @@ static void bridge_vlan_parser(KeyfileReaderInfo *info, NMSetting *setting, const char *key) { gs_unref_ptrarray GPtrArray *vlans = NULL; - gs_free char * value = NULL; - gs_free const char ** strv = NULL; - const char *const * iter; - GError * local = NULL; - NMBridgeVlan * vlan; + gs_free char *value = NULL; + gs_free const char **strv = NULL; + const char *const *iter; + GError *local = NULL; + NMBridgeVlan *vlan; value = nm_keyfile_plugin_kf_get_string(info->keyfile, nm_setting_get_name(setting), key, NULL); if (!value || !value[0]) @@ -1929,10 +1929,10 @@ bridge_vlan_parser(KeyfileReaderInfo *info, NMSetting *setting, const char *key) static void qdisc_parser(KeyfileReaderInfo *info, NMSetting *setting, const char *key) { - const char * setting_name = nm_setting_get_name(setting); - gs_unref_ptrarray GPtrArray *qdiscs = NULL; - gs_strfreev char ** keys = NULL; - gsize n_keys = 0; + const char *setting_name = nm_setting_get_name(setting); + gs_unref_ptrarray GPtrArray *qdiscs = NULL; + gs_strfreev char **keys = NULL; + gsize n_keys = 0; int i; keys = nm_keyfile_plugin_kf_get_keys(info->keyfile, setting_name, &n_keys, NULL); @@ -1942,11 +1942,11 @@ qdisc_parser(KeyfileReaderInfo *info, NMSetting *setting, const char *key) qdiscs = g_ptr_array_new_with_free_func((GDestroyNotify) nm_tc_qdisc_unref); for (i = 0; i < n_keys; i++) { - NMTCQdisc * qdisc; - const char * qdisc_parent; - gs_free char *qdisc_rest = NULL; - gs_free char *qdisc_str = NULL; - gs_free_error GError *err = NULL; + NMTCQdisc *qdisc; + const char *qdisc_parent; + gs_free char *qdisc_rest = NULL; + gs_free char *qdisc_str = NULL; + gs_free_error GError *err = NULL; if (!g_str_has_prefix(keys[i], "qdisc.")) continue; @@ -1979,10 +1979,10 @@ qdisc_parser(KeyfileReaderInfo *info, NMSetting *setting, const char *key) static void tfilter_parser(KeyfileReaderInfo *info, NMSetting *setting, const char *key) { - const char * setting_name = nm_setting_get_name(setting); - gs_unref_ptrarray GPtrArray *tfilters = NULL; - gs_strfreev char ** keys = NULL; - gsize n_keys = 0; + const char *setting_name = nm_setting_get_name(setting); + gs_unref_ptrarray GPtrArray *tfilters = NULL; + gs_strfreev char **keys = NULL; + gsize n_keys = 0; int i; keys = nm_keyfile_plugin_kf_get_keys(info->keyfile, setting_name, &n_keys, NULL); @@ -1992,11 +1992,11 @@ tfilter_parser(KeyfileReaderInfo *info, NMSetting *setting, const char *key) tfilters = g_ptr_array_new_with_free_func((GDestroyNotify) nm_tc_tfilter_unref); for (i = 0; i < n_keys; i++) { - NMTCTfilter * tfilter; - const char * tfilter_parent; - gs_free char *tfilter_rest = NULL; - gs_free char *tfilter_str = NULL; - gs_free_error GError *err = NULL; + NMTCTfilter *tfilter; + const char *tfilter_parent; + gs_free char *tfilter_rest = NULL; + gs_free char *tfilter_str = NULL; + gs_free_error GError *err = NULL; if (!g_str_has_prefix(keys[i], "tfilter.")) continue; @@ -2037,9 +2037,9 @@ tfilter_parser(KeyfileReaderInfo *info, NMSetting *setting, const char *key) */ static void setting_alias_writer(KeyfileWriterInfo *info, - NMSetting * setting, - const char * key, - const GValue * value) + NMSetting *setting, + const char *key, + const GValue *value) { const char *str, *alias; @@ -2060,7 +2060,7 @@ sriov_vfs_writer(KeyfileWriterInfo *info, NMSetting *setting, const char *key, c for (i = 0; i < vfs->len; i++) { const NMSriovVF *vf = vfs->pdata[i]; - gs_free char * kf_value = NULL; + gs_free char *kf_value = NULL; char kf_key[32]; kf_value = nm_utils_sriov_vf_to_str(vf, TRUE, NULL); @@ -2112,12 +2112,12 @@ dns_writer(KeyfileWriterInfo *info, NMSetting *setting, const char *key, const G static void ip6_addr_gen_mode_writer(KeyfileWriterInfo *info, - NMSetting * setting, - const char * key, - const GValue * value) + NMSetting *setting, + const char *key, + const GValue *value) { NMSettingIP6ConfigAddrGenMode addr_gen_mode; - gs_free char * str = NULL; + gs_free char *str = NULL; addr_gen_mode = (NMSettingIP6ConfigAddrGenMode) g_value_get_int(value); str = nm_utils_enum_to_str(nm_setting_ip6_config_addr_gen_mode_get_type(), addr_gen_mode); @@ -2125,9 +2125,9 @@ ip6_addr_gen_mode_writer(KeyfileWriterInfo *info, } static void -write_ip_values(GKeyFile * file, +write_ip_values(GKeyFile *file, const char *setting_name, - GPtrArray * array, + GPtrArray *array, const char *gateway, gboolean is_route) { @@ -2135,11 +2135,11 @@ write_ip_values(GKeyFile * file, nm_auto_str_buf NMStrBuf output = NM_STR_BUF_INIT(2 * INET_ADDRSTRLEN + 10, FALSE); int addr_family; guint i; - const char * addr; - const char * gw; + const char *addr; + const char *gw; guint32 plen; char key_name[64]; - char * key_name_idx; + char *key_name_idx; addr_family = nm_streq(setting_name, NM_SETTING_IP4_CONFIG_SETTING_NAME) ? AF_INET : AF_INET6; @@ -2211,7 +2211,7 @@ write_ip_values(GKeyFile * file, static void addr_writer(KeyfileWriterInfo *info, NMSetting *setting, const char *key, const GValue *value) { - GPtrArray * array; + GPtrArray *array; const char *setting_name = nm_setting_get_name(setting); const char *gateway = nm_setting_ip_config_get_gateway(NM_SETTING_IP_CONFIG(setting)); @@ -2223,7 +2223,7 @@ addr_writer(KeyfileWriterInfo *info, NMSetting *setting, const char *key, const static void route_writer(KeyfileWriterInfo *info, NMSetting *setting, const char *key, const GValue *value) { - GPtrArray * array; + GPtrArray *array; const char *setting_name = nm_setting_get_name(setting); array = (GPtrArray *) g_value_get_boxed(value); @@ -2233,9 +2233,9 @@ route_writer(KeyfileWriterInfo *info, NMSetting *setting, const char *key, const static void bridge_vlan_writer(KeyfileWriterInfo *info, - NMSetting * setting, - const char * key, - const GValue * value) + NMSetting *setting, + const char *key, + const GValue *value) { GPtrArray *vlans; @@ -2262,13 +2262,13 @@ bridge_vlan_writer(KeyfileWriterInfo *info, } static void -wired_s390_options_parser_full(KeyfileReaderInfo * info, - const NMMetaSettingInfo * setting_info, +wired_s390_options_parser_full(KeyfileReaderInfo *info, + const NMMetaSettingInfo *setting_info, const NMSettInfoProperty *property_info, - const ParseInfoProperty * pip, - NMSetting * setting) + const ParseInfoProperty *pip, + NMSetting *setting) { - NMSettingWired * s_wired = NM_SETTING_WIRED(setting); + NMSettingWired *s_wired = NM_SETTING_WIRED(setting); gs_strfreev char **keys = NULL; gsize n_keys; gsize i; @@ -2297,11 +2297,11 @@ wired_s390_options_parser_full(KeyfileReaderInfo * info, } static void -wired_s390_options_writer_full(KeyfileWriterInfo * info, - const NMMetaSettingInfo * setting_info, +wired_s390_options_writer_full(KeyfileWriterInfo *info, + const NMMetaSettingInfo *setting_info, const NMSettInfoProperty *property_info, - const ParseInfoProperty * pip, - NMSetting * setting) + const ParseInfoProperty *pip, + NMSetting *setting) { NMSettingWired *s_wired = NM_SETTING_WIRED(setting); guint i, n; @@ -2309,8 +2309,8 @@ wired_s390_options_writer_full(KeyfileWriterInfo * info, n = nm_setting_wired_get_num_s390_options(s_wired); for (i = 0; i < n; i++) { gs_free char *key_to_free = NULL; - const char * opt_key; - const char * opt_val; + const char *opt_key; + const char *opt_val; nm_setting_wired_get_s390_option(s_wired, i, &opt_key, &opt_val); nm_keyfile_plugin_kf_set_string(info->keyfile, @@ -2321,23 +2321,23 @@ wired_s390_options_writer_full(KeyfileWriterInfo * info, } static void -ip_routing_rule_writer_full(KeyfileWriterInfo * info, - const NMMetaSettingInfo * setting_info, +ip_routing_rule_writer_full(KeyfileWriterInfo *info, + const NMMetaSettingInfo *setting_info, const NMSettInfoProperty *property_info, - const ParseInfoProperty * pip, - NMSetting * setting) + const ParseInfoProperty *pip, + NMSetting *setting) { - const char * setting_name = nm_setting_get_name(setting); + const char *setting_name = nm_setting_get_name(setting); NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG(setting); guint i, j, n; char key_name_full[100] = "routing-rule"; - char * key_name_num = &key_name_full[NM_STRLEN("routing-rule")]; + char *key_name_num = &key_name_full[NM_STRLEN("routing-rule")]; n = nm_setting_ip_config_get_num_routing_rules(s_ip); j = 0; for (i = 0; i < n; i++) { NMIPRoutingRule *rule = nm_setting_ip_config_get_routing_rule(s_ip, i); - gs_free char * str = NULL; + gs_free char *str = NULL; str = nm_ip_routing_rule_to_string(rule, NM_IP_ROUTING_RULE_AS_STRING_FLAGS_NONE, NULL, NULL); @@ -2354,7 +2354,7 @@ qdisc_writer(KeyfileWriterInfo *info, NMSetting *setting, const char *key, const { nm_auto_free_gstring GString *key_name = NULL; nm_auto_free_gstring GString *value_str = NULL; - GPtrArray * array; + GPtrArray *array; guint i; array = g_value_get_boxed(value); @@ -2383,7 +2383,7 @@ tfilter_writer(KeyfileWriterInfo *info, NMSetting *setting, const char *key, con { nm_auto_free_gstring GString *key_name = NULL; nm_auto_free_gstring GString *value_str = NULL; - GPtrArray * array; + GPtrArray *array; guint i; array = g_value_get_boxed(value); @@ -2408,16 +2408,16 @@ tfilter_writer(KeyfileWriterInfo *info, NMSetting *setting, const char *key, con } static void -_writer_full_ovs_external_ids_data(KeyfileWriterInfo * info, - const NMMetaSettingInfo * setting_info, +_writer_full_ovs_external_ids_data(KeyfileWriterInfo *info, + const NMMetaSettingInfo *setting_info, const NMSettInfoProperty *property_info, - const ParseInfoProperty * pip, - NMSetting * setting) + const ParseInfoProperty *pip, + NMSetting *setting) { - GHashTable * hash; - NMUtilsNamedValue data_static[300u / sizeof(NMUtilsNamedValue)]; + GHashTable *hash; + NMUtilsNamedValue data_static[300u / sizeof(NMUtilsNamedValue)]; gs_free NMUtilsNamedValue *data_free = NULL; - const NMUtilsNamedValue * data; + const NMUtilsNamedValue *data; guint data_len; char full_key_static[NM_STRLEN(OVS_EXTERNAL_IDS_DATA_PREFIX) + 300u]; guint i; @@ -2436,13 +2436,13 @@ _writer_full_ovs_external_ids_data(KeyfileWriterInfo * info, memcpy(full_key_static, OVS_EXTERNAL_IDS_DATA_PREFIX, NM_STRLEN(OVS_EXTERNAL_IDS_DATA_PREFIX)); for (i = 0; i < data_len; i++) { - const char * key = data[i].name; - const char * val = data[i].value_str; + const char *key = data[i].name; + const char *val = data[i].value_str; gs_free char *escaped_key_to_free = NULL; - const char * escaped_key; + const char *escaped_key; gsize len; gs_free char *full_key_free = NULL; - char * full_key = full_key_static; + char *full_key = full_key_static; escaped_key = nm_keyfile_key_encode(key, &escaped_key_to_free); @@ -2464,8 +2464,8 @@ _writer_full_ovs_external_ids_data(KeyfileWriterInfo * info, static void write_hash_of_string(GKeyFile *file, NMSetting *setting, const char *key, const GValue *value) { - GHashTable * hash; - const char * group_name = nm_setting_get_name(setting); + GHashTable *hash; + const char *group_name = nm_setting_get_name(setting); gboolean vpn_secrets = FALSE; gs_free const char **keys = NULL; guint i, l; @@ -2486,7 +2486,7 @@ write_hash_of_string(GKeyFile *file, NMSetting *setting, const char *key, const keys = nm_strdict_get_keys(hash, TRUE, &l); for (i = 0; i < l; i++) { gs_free char *to_free = NULL; - const char * property, *data; + const char *property, *data; property = keys[i]; @@ -2514,10 +2514,10 @@ write_hash_of_string(GKeyFile *file, NMSetting *setting, const char *key, const static void ssid_writer(KeyfileWriterInfo *info, NMSetting *setting, const char *key, const GValue *value) { - GBytes * bytes; + GBytes *bytes; const guint8 *ssid_data; gsize ssid_len; - const char * setting_name = nm_setting_get_name(setting); + const char *setting_name = nm_setting_get_name(setting); gboolean new_format = TRUE; gsize semicolons = 0; gsize i; @@ -2576,12 +2576,12 @@ ssid_writer(KeyfileWriterInfo *info, NMSetting *setting, const char *key, const static void password_raw_writer(KeyfileWriterInfo *info, - NMSetting * setting, - const char * key, - const GValue * value) + NMSetting *setting, + const char *key, + const GValue *value) { - const char * setting_name = nm_setting_get_name(setting); - GBytes * array; + const char *setting_name = nm_setting_get_name(setting); + GBytes *array; gsize len; const guint8 *data; @@ -2599,10 +2599,10 @@ password_raw_writer(KeyfileWriterInfo *info, /*****************************************************************************/ static void -cert_writer_default(NMConnection * connection, - GKeyFile * file, - NMSetting8021x * setting, - const char * setting_name, +cert_writer_default(NMConnection *connection, + GKeyFile *file, + NMSetting8021x *setting, + const char *setting_name, const NMSetting8021xSchemeVtable *vtable) { NMSetting8021xCKScheme scheme; @@ -2612,7 +2612,7 @@ cert_writer_default(NMConnection * connection, gs_free char *path_free = NULL; gs_free char *base_dir = NULL; gs_free char *tmp = NULL; - const char * path; + const char *path; path = vtable->path_func(setting); g_assert(path); @@ -2643,7 +2643,7 @@ cert_writer_default(NMConnection * connection, nm_keyfile_plugin_kf_set_string(file, setting_name, vtable->setting_key, path); } else if (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB) { - GBytes * blob; + GBytes *blob; const guint8 *blob_data; gsize blob_len; gs_free char *blob_base64 = NULL; @@ -2677,7 +2677,7 @@ static void cert_writer(KeyfileWriterInfo *info, NMSetting *setting, const char *key, const GValue *value) { const NMSetting8021xSchemeVtable *vtable = NULL; - const char * setting_name; + const char *setting_name; guint i; for (i = 0; nm_setting_8021x_scheme_vtable[i].setting_key; i++) { @@ -2728,22 +2728,22 @@ struct _ParseInfoProperty { const char *property_name; union { void (*parser)(KeyfileReaderInfo *info, NMSetting *setting, const char *key); - void (*parser_full)(KeyfileReaderInfo * info, - const NMMetaSettingInfo * setting_info, + void (*parser_full)(KeyfileReaderInfo *info, + const NMMetaSettingInfo *setting_info, const NMSettInfoProperty *property_info, - const ParseInfoProperty * pip, - NMSetting * setting); + const ParseInfoProperty *pip, + NMSetting *setting); }; union { void (*writer)(KeyfileWriterInfo *info, - NMSetting * setting, - const char * key, - const GValue * value); - void (*writer_full)(KeyfileWriterInfo * info, - const NMMetaSettingInfo * setting_info, + NMSetting *setting, + const char *key, + const GValue *value); + void (*writer_full)(KeyfileWriterInfo *info, + const NMMetaSettingInfo *setting_info, const NMSettInfoProperty *property_info, - const ParseInfoProperty * pip, - NMSetting * setting); + const ParseInfoProperty *pip, + NMSetting *setting); }; bool parser_skip; bool parser_no_check_key : 1; @@ -3021,14 +3021,14 @@ static const ParseInfoSetting *const parse_infos[_NM_META_SETTING_TYPE_NUM] = { }; static void -_parse_info_find(NMSetting * setting, - const char * property_name, +_parse_info_find(NMSetting *setting, + const char *property_name, const NMMetaSettingInfo **out_setting_info, - const ParseInfoSetting ** out_parse_info_setting, + const ParseInfoSetting **out_parse_info_setting, const ParseInfoProperty **out_parse_info_property) { const NMMetaSettingInfo *setting_info; - const ParseInfoSetting * pis; + const ParseInfoSetting *pis; const ParseInfoProperty *pip; #if NM_MORE_ASSERTS > 10 @@ -3105,16 +3105,16 @@ _parse_info_find(NMSetting * setting, /*****************************************************************************/ static void -read_one_setting_value(KeyfileReaderInfo * info, - NMSetting * setting, +read_one_setting_value(KeyfileReaderInfo *info, + NMSetting *setting, const NMSettInfoProperty *property_info) { - GKeyFile * keyfile = info->keyfile; - gs_free_error GError * err = NULL; + GKeyFile *keyfile = info->keyfile; + gs_free_error GError *err = NULL; const NMMetaSettingInfo *setting_info; const ParseInfoProperty *pip; - gs_free char * tmp_str = NULL; - const char * key; + gs_free char *tmp_str = NULL; + const char *key; GType type; guint64 u64; gint64 i64; @@ -3255,11 +3255,11 @@ read_one_setting_value(KeyfileReaderInfo * info, } } else if (type == G_TYPE_BYTES) { nm_auto_unref_bytearray GByteArray *array = NULL; - gs_unref_bytes GBytes *bytes = NULL; - gs_free guint *tmp = NULL; - gsize length; - int i; - gboolean already_warned = FALSE; + gs_unref_bytes GBytes *bytes = NULL; + gs_free guint *tmp = NULL; + gsize length; + int i; + gboolean already_warned = FALSE; tmp = nm_keyfile_plugin_kf_get_integer_list_uint(keyfile, setting_info->setting_name, @@ -3347,9 +3347,9 @@ read_one_setting_value(KeyfileReaderInfo * info, static void _read_setting(KeyfileReaderInfo *info) { - const NMSettInfoSetting *sett_info; + const NMSettInfoSetting *sett_info; gs_unref_object NMSetting *setting = NULL; - const char * alias; + const char *alias; GType type; guint16 i; @@ -3386,10 +3386,10 @@ _read_setting(KeyfileReaderInfo *info) nm_strv_sort(keys, n_keys); for (k = 0; k < n_keys; k++) { - gs_free char *key = keys[k]; + gs_free char *key = keys[k]; gs_free_error GError *local = NULL; - const GVariantType * variant_type; - GVariant * variant; + const GVariantType *variant_type; + GVariant *variant; /* a GKeyFile can return duplicate keys, there is just no API to make sense * of them. Skip them. */ @@ -3477,16 +3477,16 @@ out: static void _read_setting_wireguard_peer(KeyfileReaderInfo *info) { - gs_unref_object NMSettingWireGuard *s_wg_new = NULL; - nm_auto_unref_wgpeer NMWireGuardPeer *peer = NULL; - gs_free_error GError *error = NULL; - NMSettingWireGuard * s_wg; - gs_free char * str = NULL; - const char * cstr = NULL; - const char * key; - gint64 i64; - gs_strfreev char ** sa = NULL; - gsize n_sa; + gs_unref_object NMSettingWireGuard *s_wg_new = NULL; + nm_auto_unref_wgpeer NMWireGuardPeer *peer = NULL; + gs_free_error GError *error = NULL; + NMSettingWireGuard *s_wg; + gs_free char *str = NULL; + const char *cstr = NULL; + const char *key; + gint64 i64; + gs_strfreev char **sa = NULL; + gsize n_sa; peer = nm_wireguard_peer_new(); @@ -3643,7 +3643,7 @@ _read_setting_vpn_secrets(KeyfileReaderInfo *info) { gs_strfreev char **keys = NULL; gsize i, n_keys; - NMSettingVpn * s_vpn; + NMSettingVpn *s_vpn; s_vpn = nm_connection_get_setting_vpn(info->connection); if (!s_vpn) { @@ -3689,7 +3689,7 @@ gboolean nm_keyfile_read_ensure_uuid(NMConnection *connection, const char *fallback_uuid_seed) { NMSettingConnection *s_con; - gs_free char * hashed_uuid = NULL; + gs_free char *hashed_uuid = NULL; g_return_val_if_fail(NM_IS_CONNECTION(connection), FALSE); g_return_val_if_fail(fallback_uuid_seed, FALSE); @@ -3724,16 +3724,16 @@ nm_keyfile_read_ensure_uuid(NMConnection *connection, const char *fallback_uuid_ * Since: 1.30 */ NMConnection * -nm_keyfile_read(GKeyFile * keyfile, - const char * base_dir, +nm_keyfile_read(GKeyFile *keyfile, + const char *base_dir, NMKeyfileHandlerFlags handler_flags, NMKeyfileReadHandler handler, - void * user_data, - GError ** error) + void *user_data, + GError **error) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - gs_strfreev char ** groups = NULL; + NMSettingConnection *s_con; + gs_strfreev char **groups = NULL; gsize n_groups; gsize i; gboolean vpn_secrets = FALSE; @@ -3814,13 +3814,13 @@ out_with_info_error: /*****************************************************************************/ static void -write_setting_value(KeyfileWriterInfo * info, - NMSetting * setting, +write_setting_value(KeyfileWriterInfo *info, + NMSetting *setting, const NMSettInfoProperty *property_info) { const NMMetaSettingInfo *setting_info; const ParseInfoProperty *pip; - const char * key; + const char *key; char numstr[64]; GValue value; GType type; @@ -3919,7 +3919,7 @@ write_setting_value(KeyfileWriterInfo * info, nm_sprintf_buf(numstr, "%d", (int) g_value_get_schar(&value)); nm_keyfile_plugin_kf_set_value(info->keyfile, setting_info->setting_name, key, numstr); } else if (type == G_TYPE_BYTES) { - GBytes * bytes; + GBytes *bytes; const guint8 *data; gsize len = 0; @@ -3968,13 +3968,13 @@ _write_setting_wireguard(NMSetting *setting, KeyfileWriterInfo *info) n_peers = nm_setting_wireguard_get_peers_len(s_wg); for (i_peer = 0; i_peer < n_peers; i_peer++) { - NMWireGuardPeer * peer = nm_setting_wireguard_get_peer(s_wg, i_peer); - const char * public_key; + NMWireGuardPeer *peer = nm_setting_wireguard_get_peer(s_wg, i_peer); + const char *public_key; char group[NM_STRLEN(NM_KEYFILE_GROUPPREFIX_WIREGUARD_PEER) + 200]; NMSettingSecretFlags secret_flags; gboolean any_key = FALSE; guint i_aip, n_aip; - const char * cstr; + const char *cstr; guint32 u32; public_key = nm_wireguard_peer_get_public_key(peer); @@ -4073,16 +4073,16 @@ _write_setting_wireguard(NMSetting *setting, KeyfileWriterInfo *info) * Since: 1.30 */ GKeyFile * -nm_keyfile_write(NMConnection * connection, +nm_keyfile_write(NMConnection *connection, NMKeyfileHandlerFlags handler_flags, NMKeyfileWriteHandler handler, - void * user_data, - GError ** error) + void *user_data, + GError **error) { nm_auto_unref_keyfile GKeyFile *keyfile = NULL; - GError * local = NULL; + GError *local = NULL; KeyfileWriterInfo info; - NMSetting ** settings; + NMSetting **settings; int i; guint16 j; @@ -4124,10 +4124,10 @@ nm_keyfile_write(NMConnection * connection, settings = _nm_connection_get_settings_arr(connection); for (i = 0; i < (int) _NM_META_SETTING_TYPE_NUM; i++) { - NMSetting * setting = settings[nm_meta_setting_types_by_priority[i]]; + NMSetting *setting = settings[nm_meta_setting_types_by_priority[i]]; const NMSettInfoSetting *sett_info; - const char * setting_name; - const char * setting_alias; + const char *setting_name; + const char *setting_alias; if (!setting) continue; @@ -4150,7 +4150,7 @@ nm_keyfile_write(NMConnection * connection, for (k = 0; k < n_keys; k++) { const char *key = keys[k]; - GVariant * v; + GVariant *v; v = g_hash_table_lookup(h, key); @@ -4305,7 +4305,7 @@ nm_keyfile_utils_create_filename(const char *name, gboolean with_extension) const char ESCAPE_CHAR = with_extension ? '_' : '*'; const char ESCAPE_CHAR2 = '_'; NMStrBuf str; - char * p; + char *p; gsize len; gsize i; @@ -4392,10 +4392,10 @@ nm_keyfile_handler_data_fail_with_error(NMKeyfileHandlerData *handler_data, GErr */ void nm_keyfile_handler_data_get_context(const NMKeyfileHandlerData *handler_data, - const char ** out_kf_group_name, - const char ** out_kf_key_name, - NMSetting ** out_cur_setting, - const char ** out_cur_property_name) + const char **out_kf_group_name, + const char **out_kf_key_name, + NMSetting **out_cur_setting, + const char **out_cur_property_name) { g_return_if_fail(handler_data); @@ -4435,8 +4435,8 @@ _nm_keyfile_handler_data_warn_get_message(const NMKeyfileHandlerData *handler_da */ void nm_keyfile_handler_data_warn_get(const NMKeyfileHandlerData *handler_data, - const char ** out_message, - NMKeyfileWarnSeverity * out_severity) + const char **out_message, + NMKeyfileWarnSeverity *out_severity) { g_return_if_fail(handler_data); g_return_if_fail(handler_data->type == NM_KEYFILE_HANDLER_TYPE_WARN); diff --git a/src/libnm-core-impl/nm-meta-setting-base-impl.c b/src/libnm-core-impl/nm-meta-setting-base-impl.c index 8c1ad10e..cd55779f 100644 --- a/src/libnm-core-impl/nm-meta-setting-base-impl.c +++ b/src/libnm-core-impl/nm-meta-setting-base-impl.c @@ -646,8 +646,8 @@ nm_meta_setting_infos_by_gtype(GType gtype) { #if _NM_META_SETTING_BASE_IMPL_LIBNM nm_auto_unref_gtypeclass GTypeClass *gtypeclass_unref = NULL; - GTypeClass * gtypeclass; - NMSettingClass * klass; + GTypeClass *gtypeclass; + NMSettingClass *klass; if (!g_type_is_a(gtype, NM_TYPE_SETTING)) goto out_none; diff --git a/src/libnm-core-impl/nm-property-compare.c b/src/libnm-core-impl/nm-property-compare.c index 4347d6d6..6273e90b 100644 --- a/src/libnm-core-impl/nm-property-compare.c +++ b/src/libnm-core-impl/nm-property-compare.c @@ -43,8 +43,8 @@ _nm_property_compare_vardict(GVariant *value1, GVariant *value2) { GVariantIter iter; int len1, len2; - const char * key; - GVariant * val1, *val2; + const char *key; + GVariant *val1, *val2; len1 = g_variant_n_children(value1); len2 = g_variant_n_children(value2); @@ -75,7 +75,7 @@ _nm_property_compare_strdict(GVariant *value1, GVariant *value2) { GVariantIter iter; int len1, len2; - const char * key, *val1, *val2; + const char *key, *val1, *val2; int ret; len1 = g_variant_n_children(value1); diff --git a/src/libnm-core-impl/nm-setting-6lowpan.c b/src/libnm-core-impl/nm-setting-6lowpan.c index 606fa824..765af69b 100644 --- a/src/libnm-core-impl/nm-setting-6lowpan.c +++ b/src/libnm-core-impl/nm-setting-6lowpan.c @@ -66,7 +66,7 @@ static gboolean verify(NMSetting *setting, NMConnection *connection, GError **error) { NMSetting6LowpanPrivate *priv = NM_SETTING_6LOWPAN_GET_PRIVATE(setting); - NMSettingConnection * s_con = NULL; + NMSettingConnection *s_con = NULL; if (connection) s_con = nm_connection_get_setting_connection(connection); @@ -150,9 +150,9 @@ nm_setting_6lowpan_new(void) static void nm_setting_6lowpan_class_init(NMSetting6LowpanClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSetting6LowpanPrivate)); diff --git a/src/libnm-core-impl/nm-setting-8021x.c b/src/libnm-core-impl/nm-setting-8021x.c index 103443ba..884f8830 100644 --- a/src/libnm-core-impl/nm-setting-8021x.c +++ b/src/libnm-core-impl/nm-setting-8021x.c @@ -72,7 +72,7 @@ typedef void (*EAPMethodNeedSecretsFunc)(NMSetting8021x *self, GPtrArray *secret typedef gboolean (*EAPMethodValidateFunc)(NMSetting8021x *self, gboolean phase2, GError **error); typedef struct { - const char * method; + const char *method; EAPMethodNeedSecretsFunc ns_func; EAPMethodValidateFunc v_func; } EAPMethodsTable; @@ -132,39 +132,39 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMSetting8021x, typedef struct { GSList *eap; /* GSList of strings */ - char * identity; - char * anonymous_identity; - char * pac_file; + char *identity; + char *anonymous_identity; + char *pac_file; GBytes *ca_cert; - char * ca_cert_password; - char * ca_path; - char * subject_match; + char *ca_cert_password; + char *ca_path; + char *subject_match; GSList *altsubject_matches; - char * domain_suffix_match; - char * domain_match; + char *domain_suffix_match; + char *domain_match; GBytes *client_cert; - char * client_cert_password; - char * phase1_peapver; - char * phase1_peaplabel; - char * phase1_fast_provisioning; - char * phase2_auth; - char * phase2_autheap; + char *client_cert_password; + char *phase1_peapver; + char *phase1_peaplabel; + char *phase1_fast_provisioning; + char *phase2_auth; + char *phase2_autheap; GBytes *phase2_ca_cert; - char * phase2_ca_cert_password; - char * phase2_ca_path; - char * phase2_subject_match; + char *phase2_ca_cert_password; + char *phase2_ca_path; + char *phase2_subject_match; GSList *phase2_altsubject_matches; - char * phase2_domain_suffix_match; - char * phase2_domain_match; + char *phase2_domain_suffix_match; + char *phase2_domain_match; GBytes *phase2_client_cert; - char * phase2_client_cert_password; - char * password; + char *phase2_client_cert_password; + char *password; GBytes *password_raw; - char * pin; + char *pin; GBytes *private_key; - char * private_key_password; + char *private_key_password; GBytes *phase2_private_key; - char * phase2_private_key_password; + char *phase2_private_key_password; guint ca_cert_password_flags; guint client_cert_password_flags; guint phase2_ca_cert_password_flags; @@ -221,7 +221,7 @@ G_DEFINE_TYPE(NMSetting8021x, nm_setting_802_1x, NM_TYPE_SETTING) NMSetting8021xCKScheme nm_setting_802_1x_check_cert_scheme(gconstpointer pdata, gsize length, GError **error) { - const char * data = pdata; + const char *data = pdata; NMSetting8021xCKScheme scheme; gsize prefix_length; @@ -309,7 +309,7 @@ _nm_setting_802_1x_cert_get_scheme(GBytes *bytes, GError **error) static gboolean _cert_verify_scheme(NMSetting8021xCKScheme scheme, GBytes *bytes, GError **error) { - GError * local = NULL; + GError *local = NULL; NMSetting8021xCKScheme scheme_detected; nm_assert(bytes); @@ -337,12 +337,12 @@ _cert_verify_scheme(NMSetting8021xCKScheme scheme, GBytes *bytes, GError **error GBytes * _nm_setting_802_1x_cert_value_to_bytes(NMSetting8021xCKScheme scheme, - const guint8 * val_bin, + const guint8 *val_bin, gssize val_len, - GError ** error) + GError **error) { gs_unref_bytes GBytes *bytes = NULL; - guint8 * mem; + guint8 *mem; gsize total_len; nm_assert(val_bin); @@ -411,7 +411,7 @@ _cert_get_path(GBytes *bytes) G_STMT_START \ { \ NMSetting8021x *const _setting = (setting); \ - GBytes * _cert; \ + GBytes *_cert; \ \ g_return_val_if_fail(NM_IS_SETTING_802_1X(_setting), NM_SETTING_802_1X_CK_SCHEME_UNKNOWN); \ \ @@ -425,7 +425,7 @@ _cert_get_path(GBytes *bytes) G_STMT_START \ { \ NMSetting8021x *const _setting = (setting); \ - GBytes * _cert; \ + GBytes *_cert; \ \ g_return_val_if_fail(NM_IS_SETTING_802_1X(_setting), NULL); \ \ @@ -441,7 +441,7 @@ _cert_get_path(GBytes *bytes) G_STMT_START \ { \ NMSetting8021x *const _setting = (setting); \ - GBytes * _cert; \ + GBytes *_cert; \ \ g_return_val_if_fail(NM_IS_SETTING_802_1X(_setting), NULL); \ \ @@ -457,7 +457,7 @@ _cert_get_path(GBytes *bytes) G_STMT_START \ { \ NMSetting8021x *const _setting = (setting); \ - GBytes * _cert; \ + GBytes *_cert; \ \ g_return_val_if_fail(NM_IS_SETTING_802_1X(_setting), NULL); \ \ @@ -470,20 +470,20 @@ _cert_get_path(GBytes *bytes) G_STMT_END static gboolean -_cert_impl_set(NMSetting8021x * setting, +_cert_impl_set(NMSetting8021x *setting, _PropertyEnums property, - const char * value, - const char * password, + const char *value, + const char *password, NMSetting8021xCKScheme scheme, NMSetting8021xCKFormat *out_format, - GError ** error) + GError **error) { NMSetting8021xPrivate *priv; NMCryptoFileFormat format = NM_CRYPTO_FILE_FORMAT_UNKNOWN; gs_unref_bytes GBytes *cert = NULL; - GBytes ** p_cert = NULL; - GBytes ** p_client_cert = NULL; - char ** p_password = NULL; + GBytes **p_cert = NULL; + GBytes **p_client_cert = NULL; + char **p_password = NULL; _PropertyEnums notify_cert = property; _PropertyEnums notify_password = PROP_0; _PropertyEnums notify_client_cert = PROP_0; @@ -630,7 +630,7 @@ static NMSetting8021xCKFormat _cert_impl_get_key_format_from_bytes(GBytes *private_key) { const char *path; - GError * error = NULL; + GError *error = NULL; if (!private_key) return NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; @@ -660,7 +660,7 @@ _cert_impl_get_key_format_from_bytes(GBytes *private_key) } #define _cert_impl_get_key_format(setting, private_key_field) \ ({ \ - NMSetting8021x * _setting = (setting); \ + NMSetting8021x *_setting = (setting); \ NMSetting8021xPrivate *_priv; \ \ g_return_val_if_fail(NM_IS_SETTING_802_1X(_setting), NM_SETTING_802_1X_CK_FORMAT_UNKNOWN); \ @@ -670,13 +670,13 @@ _cert_impl_get_key_format_from_bytes(GBytes *private_key) }) static gboolean -_cert_verify_property(GBytes * bytes, +_cert_verify_property(GBytes *bytes, const char *prop_name, const char *password, const char *password_prop_name, - GError ** error) + GError **error) { - GError * local = NULL; + GError *local = NULL; NMSetting8021xCKScheme scheme; if (!bytes) @@ -766,7 +766,7 @@ gboolean nm_setting_802_1x_add_eap_method(NMSetting8021x *setting, const char *eap) { NMSetting8021xPrivate *priv; - GSList * iter; + GSList *iter; g_return_val_if_fail(NM_IS_SETTING_802_1X(setting), FALSE); g_return_val_if_fail(eap != NULL, FALSE); @@ -793,7 +793,7 @@ void nm_setting_802_1x_remove_eap_method(NMSetting8021x *setting, guint32 i) { NMSetting8021xPrivate *priv; - GSList * elt; + GSList *elt; g_return_if_fail(NM_IS_SETTING_802_1X(setting)); @@ -819,7 +819,7 @@ gboolean nm_setting_802_1x_remove_eap_method_by_value(NMSetting8021x *setting, const char *eap) { NMSetting8021xPrivate *priv; - GSList * iter; + GSList *iter; g_return_val_if_fail(NM_IS_SETTING_802_1X(setting), FALSE); g_return_val_if_fail(eap != NULL, FALSE); @@ -1044,11 +1044,11 @@ nm_setting_802_1x_get_ca_cert_uri(NMSetting8021x *setting) * Returns: %TRUE if the operation succeeded, %FALSE if it was unsuccessful **/ gboolean -nm_setting_802_1x_set_ca_cert(NMSetting8021x * setting, - const char * value, +nm_setting_802_1x_set_ca_cert(NMSetting8021x *setting, + const char *value, NMSetting8021xCKScheme scheme, NMSetting8021xCKFormat *out_format, - GError ** error) + GError **error) { return _cert_impl_set(setting, PROP_CA_CERT, value, NULL, scheme, out_format, error); } @@ -1160,7 +1160,7 @@ gboolean nm_setting_802_1x_add_altsubject_match(NMSetting8021x *setting, const char *altsubject_match) { NMSetting8021xPrivate *priv; - GSList * iter; + GSList *iter; g_return_val_if_fail(NM_IS_SETTING_802_1X(setting), FALSE); g_return_val_if_fail(altsubject_match != NULL, FALSE); @@ -1187,7 +1187,7 @@ void nm_setting_802_1x_remove_altsubject_match(NMSetting8021x *setting, guint32 i) { NMSetting8021xPrivate *priv; - GSList * elt; + GSList *elt; g_return_if_fail(NM_IS_SETTING_802_1X(setting)); @@ -1212,10 +1212,10 @@ nm_setting_802_1x_remove_altsubject_match(NMSetting8021x *setting, guint32 i) **/ gboolean nm_setting_802_1x_remove_altsubject_match_by_value(NMSetting8021x *setting, - const char * altsubject_match) + const char *altsubject_match) { NMSetting8021xPrivate *priv; - GSList * iter; + GSList *iter; g_return_val_if_fail(NM_IS_SETTING_802_1X(setting), FALSE); g_return_val_if_fail(altsubject_match != NULL, FALSE); @@ -1377,11 +1377,11 @@ nm_setting_802_1x_get_client_cert_uri(NMSetting8021x *setting) * Returns: %TRUE if the operation succeeded, %FALSE if it was unsuccessful **/ gboolean -nm_setting_802_1x_set_client_cert(NMSetting8021x * setting, - const char * value, +nm_setting_802_1x_set_client_cert(NMSetting8021x *setting, + const char *value, NMSetting8021xCKScheme scheme, NMSetting8021xCKFormat *out_format, - GError ** error) + GError **error) { return _cert_impl_set(setting, PROP_CLIENT_CERT, value, NULL, scheme, out_format, error); } @@ -1635,11 +1635,11 @@ nm_setting_802_1x_get_phase2_ca_cert_uri(NMSetting8021x *setting) * Returns: %TRUE if the operation succeeded, %FALSE if it was unsuccessful **/ gboolean -nm_setting_802_1x_set_phase2_ca_cert(NMSetting8021x * setting, - const char * value, +nm_setting_802_1x_set_phase2_ca_cert(NMSetting8021x *setting, + const char *value, NMSetting8021xCKScheme scheme, NMSetting8021xCKFormat *out_format, - GError ** error) + GError **error) { return _cert_impl_set(setting, PROP_PHASE2_CA_CERT, value, NULL, scheme, out_format, error); } @@ -1782,10 +1782,10 @@ nm_setting_802_1x_get_phase2_altsubject_match(NMSetting8021x *setting, guint32 i **/ gboolean nm_setting_802_1x_add_phase2_altsubject_match(NMSetting8021x *setting, - const char * phase2_altsubject_match) + const char *phase2_altsubject_match) { NMSetting8021xPrivate *priv; - GSList * iter; + GSList *iter; g_return_val_if_fail(NM_IS_SETTING_802_1X(setting), FALSE); g_return_val_if_fail(phase2_altsubject_match != NULL, FALSE); @@ -1813,7 +1813,7 @@ void nm_setting_802_1x_remove_phase2_altsubject_match(NMSetting8021x *setting, guint32 i) { NMSetting8021xPrivate *priv; - GSList * elt; + GSList *elt; g_return_if_fail(NM_IS_SETTING_802_1X(setting)); @@ -1838,10 +1838,10 @@ nm_setting_802_1x_remove_phase2_altsubject_match(NMSetting8021x *setting, guint3 **/ gboolean nm_setting_802_1x_remove_phase2_altsubject_match_by_value(NMSetting8021x *setting, - const char * phase2_altsubject_match) + const char *phase2_altsubject_match) { NMSetting8021xPrivate *priv; - GSList * iter; + GSList *iter; g_return_val_if_fail(NM_IS_SETTING_802_1X(setting), FALSE); g_return_val_if_fail(phase2_altsubject_match != NULL, FALSE); @@ -1975,11 +1975,11 @@ nm_setting_802_1x_get_phase2_client_cert_uri(NMSetting8021x *setting) * Returns: %TRUE if the operation succeeded, %FALSE if it was unsuccessful **/ gboolean -nm_setting_802_1x_set_phase2_client_cert(NMSetting8021x * setting, - const char * value, +nm_setting_802_1x_set_phase2_client_cert(NMSetting8021x *setting, + const char *value, NMSetting8021xCKScheme scheme, NMSetting8021xCKFormat *out_format, - GError ** error) + GError **error) { return _cert_impl_set(setting, PROP_PHASE2_CLIENT_CERT, value, NULL, scheme, out_format, error); } @@ -2227,12 +2227,12 @@ nm_setting_802_1x_get_private_key_uri(NMSetting8021x *setting) * Returns: %TRUE if the operation succeeded, %FALSE if it was unsuccessful **/ gboolean -nm_setting_802_1x_set_private_key(NMSetting8021x * setting, - const char * value, - const char * password, +nm_setting_802_1x_set_private_key(NMSetting8021x *setting, + const char *value, + const char *password, NMSetting8021xCKScheme scheme, NMSetting8021xCKFormat *out_format, - GError ** error) + GError **error) { return _cert_impl_set(setting, PROP_PRIVATE_KEY, value, password, scheme, out_format, error); } @@ -2430,12 +2430,12 @@ nm_setting_802_1x_get_phase2_private_key_uri(NMSetting8021x *setting) * Returns: %TRUE if the operation succeeded, %FALSE if it was unsuccessful **/ gboolean -nm_setting_802_1x_set_phase2_private_key(NMSetting8021x * setting, - const char * value, - const char * password, +nm_setting_802_1x_set_phase2_private_key(NMSetting8021x *setting, + const char *value, + const char *password, NMSetting8021xCKScheme scheme, NMSetting8021xCKFormat *out_format, - GError ** error) + GError **error) { return _cert_impl_set(setting, PROP_PHASE2_PRIVATE_KEY, @@ -2504,7 +2504,7 @@ need_secrets_password(NMSetting8021x *self, GPtrArray *secrets, gboolean phase2) { NMSetting8021xPrivate *priv = NM_SETTING_802_1X_GET_PRIVATE(self); - if ((!priv->password || !strlen(priv->password)) + if (nm_str_is_empty(priv->password) && (!priv->password_raw || !g_bytes_get_size(priv->password_raw))) { g_ptr_array_add(secrets, NM_SETTING_802_1X_PASSWORD); g_ptr_array_add(secrets, NM_SETTING_802_1X_PASSWORD_RAW); @@ -2521,10 +2521,10 @@ need_secrets_sim(NMSetting8021x *self, GPtrArray *secrets, gboolean phase2) } static gboolean -need_private_key_password(GBytes * blob, +need_private_key_password(GBytes *blob, NMSetting8021xCKScheme scheme, - const char * path, - const char * password, + const char *path, + const char *password, NMSettingSecretFlags flags) { NMCryptoFileFormat format = NM_CRYPTO_FILE_FORMAT_UNKNOWN; @@ -2554,8 +2554,8 @@ need_secrets_tls(NMSetting8021x *self, GPtrArray *secrets, gboolean phase2) { NMSetting8021xPrivate *priv = NM_SETTING_802_1X_GET_PRIVATE(self); NMSetting8021xCKScheme scheme; - GBytes * blob = NULL; - const char * path = NULL; + GBytes *blob = NULL; + const char *path = NULL; if (phase2) { scheme = nm_setting_802_1x_get_phase2_private_key_scheme(self); @@ -2823,7 +2823,7 @@ static void need_secrets_phase2(NMSetting8021x *self, GPtrArray *secrets, gboolean phase2) { NMSetting8021xPrivate *priv = NM_SETTING_802_1X_GET_PRIVATE(self); - char * method = NULL; + char *method = NULL; int i; g_return_if_fail(phase2 == FALSE); @@ -2871,9 +2871,9 @@ static const EAPMethodsTable eap_methods_table[] = { static gboolean verify(NMSetting *setting, NMConnection *connection, GError **error) { - NMSetting8021x * self = NM_SETTING_802_1X(setting); + NMSetting8021x *self = NM_SETTING_802_1X(setting); NMSetting8021xPrivate *priv = NM_SETTING_802_1X_GET_PRIVATE(self); - const char * valid_eap[] = + const char *valid_eap[] = {"leap", "md5", "tls", "peap", "ttls", "sim", "fast", "pwd", "external", NULL}; GSList *iter; @@ -3057,10 +3057,10 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) static GPtrArray * need_secrets(NMSetting *setting) { - NMSetting8021x * self = NM_SETTING_802_1X(setting); + NMSetting8021x *self = NM_SETTING_802_1X(setting); NMSetting8021xPrivate *priv = NM_SETTING_802_1X_GET_PRIVATE(self); - GSList * iter; - GPtrArray * secrets; + GSList *iter; + GPtrArray *secrets; gboolean eap_method_found = FALSE; secrets = g_ptr_array_sized_new(4); @@ -3099,7 +3099,7 @@ need_secrets(NMSetting *setting) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMSetting8021x * setting = NM_SETTING_802_1X(object); + NMSetting8021x *setting = NM_SETTING_802_1X(object); NMSetting8021xPrivate *priv = NM_SETTING_802_1X_GET_PRIVATE(setting); switch (prop_id) { @@ -3121,7 +3121,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) { - NMSetting8021x * setting = NM_SETTING_802_1X(object); + NMSetting8021x *setting = NM_SETTING_802_1X(object); NMSetting8021xPrivate *priv = NM_SETTING_802_1X_GET_PRIVATE(setting); switch (prop_id) { @@ -3165,7 +3165,7 @@ nm_setting_802_1x_new(void) static void finalize(GObject *object) { - NMSetting8021x * self = NM_SETTING_802_1X(object); + NMSetting8021x *self = NM_SETTING_802_1X(object); NMSetting8021xPrivate *priv = NM_SETTING_802_1X_GET_PRIVATE(self); g_slist_free_full(priv->eap, g_free); @@ -3178,9 +3178,9 @@ finalize(GObject *object) static void nm_setting_802_1x_class_init(NMSetting8021xClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSetting8021xPrivate)); diff --git a/src/libnm-core-impl/nm-setting-adsl.c b/src/libnm-core-impl/nm-setting-adsl.c index 8e5dc8cf..88606b69 100644 --- a/src/libnm-core-impl/nm-setting-adsl.c +++ b/src/libnm-core-impl/nm-setting-adsl.c @@ -31,10 +31,10 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_USERNAME, PROP_VCI, ); typedef struct { - char * username; - char * password; - char * protocol; - char * encapsulation; + char *username; + char *password; + char *protocol; + char *encapsulation; guint password_flags; guint32 vpi; guint32 vci; @@ -228,7 +228,7 @@ static GPtrArray * need_secrets(NMSetting *setting) { NMSettingAdslPrivate *priv = NM_SETTING_ADSL_GET_PRIVATE(setting); - GPtrArray * secrets = NULL; + GPtrArray *secrets = NULL; if (priv->password && *priv->password) return NULL; @@ -263,9 +263,9 @@ nm_setting_adsl_new(void) static void nm_setting_adsl_class_init(NMSettingAdslClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingAdslPrivate)); diff --git a/src/libnm-core-impl/nm-setting-bluetooth.c b/src/libnm-core-impl/nm-setting-bluetooth.c index 53e4912f..f657ff13 100644 --- a/src/libnm-core-impl/nm-setting-bluetooth.c +++ b/src/libnm-core-impl/nm-setting-bluetooth.c @@ -100,7 +100,7 @@ static gboolean verify(NMSetting *setting, NMConnection *connection, GError **error) { NMSettingBluetoothPrivate *priv = NM_SETTING_BLUETOOTH_GET_PRIVATE(setting); - const char * type; + const char *type; gboolean missing_nap_bridge = FALSE; if (priv->bdaddr && !nm_utils_hwaddr_valid(priv->bdaddr, ETH_ALEN)) { @@ -250,9 +250,9 @@ nm_setting_bluetooth_new(void) static void nm_setting_bluetooth_class_init(NMSettingBluetoothClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingBluetoothPrivate)); diff --git a/src/libnm-core-impl/nm-setting-bond-port.c b/src/libnm-core-impl/nm-setting-bond-port.c index 4538e8b9..9b41a74f 100644 --- a/src/libnm-core-impl/nm-setting-bond-port.c +++ b/src/libnm-core-impl/nm-setting-bond-port.c @@ -72,7 +72,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) { if (connection) { NMSettingConnection *s_con; - const char * slave_type; + const char *slave_type; s_con = nm_connection_get_setting_connection(connection); if (!s_con) { @@ -127,9 +127,9 @@ nm_setting_bond_port_new(void) static void nm_setting_bond_port_class_init(NMSettingBondPortClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); object_class->get_property = _nm_setting_property_get_property_direct; object_class->set_property = _nm_setting_property_set_property_direct; diff --git a/src/libnm-core-impl/nm-setting-bond.c b/src/libnm-core-impl/nm-setting-bond.c index e81130cd..ae2fe051 100644 --- a/src/libnm-core-impl/nm-setting-bond.c +++ b/src/libnm-core-impl/nm-setting-bond.c @@ -34,7 +34,7 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMSettingBond, PROP_OPTIONS, ); typedef struct { - GHashTable * options; + GHashTable *options; NMUtilsNamedValue *options_idx_cache; } NMSettingBondPrivate; @@ -95,7 +95,7 @@ static const char *const valid_options_lst[] = { }; typedef struct { - const char * val; + const char *val; NMBondOptionType opt_type; guint min; guint max; @@ -449,8 +449,8 @@ _ensure_options_idx_cache(NMSettingBondPrivate *priv) gboolean nm_setting_bond_get_option(NMSettingBond *setting, guint32 idx, - const char ** out_name, - const char ** out_value) + const char **out_name, + const char **out_value) { NMSettingBondPrivate *priv; guint len; @@ -778,17 +778,17 @@ _nm_setting_bond_get_option_type(NMSettingBond *setting, const char *name) static gboolean verify(NMSetting *setting, NMConnection *connection, GError **error) { - NMSettingBond * self = NM_SETTING_BOND(setting); - NMSettingBondPrivate * priv = NM_SETTING_BOND_GET_PRIVATE(setting); + NMSettingBond *self = NM_SETTING_BOND(setting); + NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE(setting); int miimon; int arp_interval; int num_grat_arp; int num_unsol_na; int peer_notif_delay; - const char * mode_str; - const char * arp_ip_target = NULL; - const char * lacp_rate; - const char * primary; + const char *mode_str; + const char *arp_ip_target = NULL; + const char *lacp_rate; + const char *primary; NMBondMode bond_mode; guint i; const NMUtilsNamedValue *n; @@ -1062,7 +1062,7 @@ static gboolean options_equal_asym(NMSettingBond *s_bond, NMSettingBond *s_bond2, NMSettingCompareFlags flags) { GHashTableIter iter; - const char * key, *value; + const char *key, *value; g_hash_table_iter_init(&iter, NM_SETTING_BOND_GET_PRIVATE(s_bond)->options); while (g_hash_table_iter_next(&iter, (gpointer *) &key, (gpointer *) &value)) { @@ -1169,9 +1169,9 @@ finalize(GObject *object) static void nm_setting_bond_class_init(NMSettingBondClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingBondPrivate)); diff --git a/src/libnm-core-impl/nm-setting-bridge-port.c b/src/libnm-core-impl/nm-setting-bridge-port.c index 48ad74a1..b94a348e 100644 --- a/src/libnm-core-impl/nm-setting-bridge-port.c +++ b/src/libnm-core-impl/nm-setting-bridge-port.c @@ -318,7 +318,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) if (connection) { NMSettingConnection *s_con; - const char * slave_type; + const char *slave_type; s_con = nm_connection_get_setting_connection(connection); if (!s_con) { @@ -451,9 +451,9 @@ finalize(GObject *object) static void nm_setting_bridge_port_class_init(NMSettingBridgePortClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingBridgePortPrivate)); diff --git a/src/libnm-core-impl/nm-setting-bridge.c b/src/libnm-core-impl/nm-setting-bridge.c index 9045d619..41cd6632 100644 --- a/src/libnm-core-impl/nm-setting-bridge.c +++ b/src/libnm-core-impl/nm-setting-bridge.c @@ -57,10 +57,10 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMSettingBridge, typedef struct { GPtrArray *vlans; - char * mac_address; - char * multicast_router; - char * group_address; - char * vlan_protocol; + char *mac_address; + char *multicast_router; + char *group_address; + char *vlan_protocol; guint64 multicast_last_member_interval; guint64 multicast_membership_interval; guint64 multicast_querier_interval; @@ -465,12 +465,12 @@ nm_bridge_vlan_to_str(const NMBridgeVlan *vlan, GError **error) NMBridgeVlan * nm_bridge_vlan_from_str(const char *str, GError **error) { - NMBridgeVlan * vlan = NULL; + NMBridgeVlan *vlan = NULL; gs_free const char **tokens = NULL; guint i, vid_start, vid_end = 0; gboolean pvid = FALSE; gboolean untagged = FALSE; - char * c; + char *c; g_return_val_if_fail(str, NULL); g_return_val_if_fail(!error || !*error, NULL); @@ -868,7 +868,7 @@ gboolean nm_setting_bridge_remove_vlan_by_vid(NMSettingBridge *setting, guint16 vid_start, guint16 vid_end) { NMSettingBridgePrivate *priv; - NMBridgeVlan * vlan; + NMBridgeVlan *vlan; guint i; g_return_val_if_fail(NM_IS_SETTING_BRIDGE(setting), FALSE); @@ -1398,9 +1398,9 @@ finalize(GObject *object) static void nm_setting_bridge_class_init(NMSettingBridgeClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); object_class->get_property = get_property; object_class->set_property = set_property; @@ -1443,8 +1443,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) NM_SETTING_BRIDGE_MAC_ADDRESS, PROP_MAC_ADDRESS, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - mac_address, + NMSettingBridge, + _priv.mac_address, .direct_set_string_mac_address_len = ETH_ALEN); /** @@ -1465,8 +1465,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) PROP_STP, NM_BRIDGE_STP_DEF, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - stp); + NMSettingBridge, + _priv.stp); /** * NMSettingBridge:priority: @@ -1491,8 +1491,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) NM_BRIDGE_PRIORITY_MAX, NM_BRIDGE_PRIORITY_DEF, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - priority); + NMSettingBridge, + _priv.priority); /** * NMSettingBridge:forward-delay: @@ -1515,8 +1515,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) NM_BRIDGE_FORWARD_DELAY_MAX, NM_BRIDGE_FORWARD_DELAY_DEF, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - forward_delay); + NMSettingBridge, + _priv.forward_delay); /** * NMSettingBridge:hello-time: @@ -1539,8 +1539,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) NM_BRIDGE_HELLO_TIME_MAX, NM_BRIDGE_HELLO_TIME_DEF, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - hello_time); + NMSettingBridge, + _priv.hello_time); /** * NMSettingBridge:max-age: @@ -1563,8 +1563,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) NM_BRIDGE_MAX_AGE_MAX, NM_BRIDGE_MAX_AGE_DEF, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - max_age); + NMSettingBridge, + _priv.max_age); /** * NMSettingBridge:ageing-time: @@ -1587,8 +1587,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) NM_BRIDGE_AGEING_TIME_MAX, NM_BRIDGE_AGEING_TIME_DEF, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - ageing_time); + NMSettingBridge, + _priv.ageing_time); /** * NMSettingBridge:group-forward-mask: @@ -1610,8 +1610,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) 0xFFFF, 0, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - group_forward_mask); + NMSettingBridge, + _priv.group_forward_mask); /** * NMSettingBridge:multicast-snooping: @@ -1637,8 +1637,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) PROP_MULTICAST_SNOOPING, NM_BRIDGE_MULTICAST_SNOOPING_DEF, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - multicast_snooping); + NMSettingBridge, + _priv.multicast_snooping); /** * NMSettingBridge:vlan-filtering: @@ -1661,8 +1661,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) PROP_VLAN_FILTERING, FALSE, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - vlan_filtering); + NMSettingBridge, + _priv.vlan_filtering); /** * NMSettingBridge:vlan-default-pvid: @@ -1688,8 +1688,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) NM_BRIDGE_VLAN_VID_MAX, NM_BRIDGE_VLAN_DEFAULT_PVID_DEF, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - vlan_default_pvid); + NMSettingBridge, + _priv.vlan_default_pvid); /** * NMSettingBridge:vlans: (type GPtrArray(NMBridgeVlan)) @@ -1764,8 +1764,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) NM_SETTING_BRIDGE_GROUP_ADDRESS, PROP_GROUP_ADDRESS, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - group_address, + NMSettingBridge, + _priv.group_address, .direct_set_string_mac_address_len = ETH_ALEN); /** @@ -1792,8 +1792,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) NM_SETTING_BRIDGE_VLAN_PROTOCOL, PROP_VLAN_PROTOCOL, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - vlan_protocol); + NMSettingBridge, + _priv.vlan_protocol); /** * NMSettingBridge:vlan-stats-enabled: @@ -1815,8 +1815,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) PROP_VLAN_STATS_ENABLED, NM_BRIDGE_VLAN_STATS_ENABLED_DEF, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - vlan_stats_enabled); + NMSettingBridge, + _priv.vlan_stats_enabled); /** * NMSettingBridge:multicast-router: @@ -1843,8 +1843,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) NM_SETTING_BRIDGE_MULTICAST_ROUTER, PROP_MULTICAST_ROUTER, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - multicast_router); + NMSettingBridge, + _priv.multicast_router); /** * NMSettingBridge:multicast-query-use-ifaddr: @@ -1868,8 +1868,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) PROP_MULTICAST_QUERY_USE_IFADDR, NM_BRIDGE_MULTICAST_QUERY_USE_IFADDR_DEF, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - multicast_query_use_ifaddr); + NMSettingBridge, + _priv.multicast_query_use_ifaddr); /** * NMSettingBridge:multicast-querier: @@ -1892,8 +1892,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) PROP_MULTICAST_QUERIER, NM_BRIDGE_MULTICAST_QUERIER_DEF, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - multicast_querier); + NMSettingBridge, + _priv.multicast_querier); /** * NMSettingBridge:multicast-hash-max: @@ -1917,8 +1917,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) NM_BRIDGE_MULTICAST_HASH_MAX_MAX, NM_BRIDGE_MULTICAST_HASH_MAX_DEF, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - multicast_hash_max); + NMSettingBridge, + _priv.multicast_hash_max); /** * NMSettingBridge:multicast-last-member-count: @@ -1944,8 +1944,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) NM_BRIDGE_MULTICAST_LAST_MEMBER_COUNT_MAX, NM_BRIDGE_MULTICAST_LAST_MEMBER_COUNT_DEF, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - multicast_last_member_count); + NMSettingBridge, + _priv.multicast_last_member_count); /** * NMSettingBridge:multicast-last-member-interval: @@ -1970,8 +1970,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) NM_BRIDGE_MULTICAST_LAST_MEMBER_INTERVAL_MAX, NM_BRIDGE_MULTICAST_LAST_MEMBER_INTERVAL_DEF, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - multicast_last_member_interval); + NMSettingBridge, + _priv.multicast_last_member_interval); /** * NMSettingBridge:multicast-membership-interval: @@ -1997,8 +1997,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) NM_BRIDGE_MULTICAST_MEMBERSHIP_INTERVAL_MAX, NM_BRIDGE_MULTICAST_MEMBERSHIP_INTERVAL_DEF, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - multicast_membership_interval); + NMSettingBridge, + _priv.multicast_membership_interval); /** * NMSettingBridge:multicast-querier-interval: @@ -2023,8 +2023,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) NM_BRIDGE_MULTICAST_QUERIER_INTERVAL_MAX, NM_BRIDGE_MULTICAST_QUERIER_INTERVAL_DEF, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - multicast_querier_interval); + NMSettingBridge, + _priv.multicast_querier_interval); /** * NMSettingBridge:multicast-query-interval: @@ -2049,8 +2049,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) NM_BRIDGE_MULTICAST_QUERY_INTERVAL_MAX, NM_BRIDGE_MULTICAST_QUERY_INTERVAL_DEF, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - multicast_query_interval); + NMSettingBridge, + _priv.multicast_query_interval); /** * NMSettingBridge:multicast-query-response-interval: @@ -2075,8 +2075,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) NM_BRIDGE_MULTICAST_QUERY_RESPONSE_INTERVAL_MAX, NM_BRIDGE_MULTICAST_QUERY_RESPONSE_INTERVAL_DEF, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - multicast_query_response_interval); + NMSettingBridge, + _priv.multicast_query_response_interval); /** * NMSettingBridge:multicast-startup-query-count: @@ -2100,8 +2100,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) NM_BRIDGE_MULTICAST_STARTUP_QUERY_COUNT_MAX, NM_BRIDGE_MULTICAST_STARTUP_QUERY_COUNT_DEF, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - multicast_startup_query_count); + NMSettingBridge, + _priv.multicast_startup_query_count); /** * NMSettingBridge:multicast-startup-query-interval: @@ -2126,8 +2126,8 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) NM_BRIDGE_MULTICAST_STARTUP_QUERY_INTERVAL_MAX, NM_BRIDGE_MULTICAST_STARTUP_QUERY_INTERVAL_DEF, NM_SETTING_PARAM_INFERRABLE, - NMSettingBridgePrivate, - multicast_startup_query_interval); + NMSettingBridge, + _priv.multicast_startup_query_interval); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); @@ -2135,5 +2135,5 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) NM_META_SETTING_TYPE_BRIDGE, NULL, properties_override, - G_STRUCT_OFFSET(NMSettingBridge, _priv)); + 0); } diff --git a/src/libnm-core-impl/nm-setting-cdma.c b/src/libnm-core-impl/nm-setting-cdma.c index 214f3b91..46f29f96 100644 --- a/src/libnm-core-impl/nm-setting-cdma.c +++ b/src/libnm-core-impl/nm-setting-cdma.c @@ -29,9 +29,9 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_NUMBER, PROP_MTU, ); typedef struct { - char * number; - char * username; - char * password; + char *number; + char *username; + char *password; guint32 mtu; NMSettingSecretFlags password_flags; } NMSettingCdmaPrivate; @@ -177,7 +177,7 @@ static GPtrArray * need_secrets(NMSetting *setting) { NMSettingCdmaPrivate *priv = NM_SETTING_CDMA_GET_PRIVATE(setting); - GPtrArray * secrets = NULL; + GPtrArray *secrets = NULL; if (!nm_str_is_empty(priv->password)) return NULL; @@ -214,9 +214,9 @@ nm_setting_cdma_new(void) static void nm_setting_cdma_class_init(NMSettingCdmaClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingCdmaPrivate)); diff --git a/src/libnm-core-impl/nm-setting-connection.c b/src/libnm-core-impl/nm-setting-connection.c index 322250f8..73611004 100644 --- a/src/libnm-core-impl/nm-setting-connection.c +++ b/src/libnm-core-impl/nm-setting-connection.c @@ -39,7 +39,7 @@ typedef enum _nm_packed { typedef struct { PermType ptype; - char * item; + char *item; } Permission; NM_GOBJECT_PROPERTIES_DEFINE(NMSettingConnection, @@ -73,15 +73,15 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMSettingConnection, typedef struct { GArray *permissions; GArray *secondaries; - char * id; - char * uuid; - char * stable_id; - char * interface_name; - char * type; - char * master; - char * slave_type; - char * zone; - char * mud_url; + char *id; + char *uuid; + char *stable_id; + char *interface_name; + char *type; + char *master; + char *slave_type; + char *zone; + char *mud_url; guint64 timestamp; int autoconnect_slaves; int metered; @@ -322,12 +322,12 @@ nm_setting_connection_get_num_permissions(NMSettingConnection *setting) gboolean nm_setting_connection_get_permission(NMSettingConnection *setting, guint32 idx, - const char ** out_ptype, - const char ** out_pitem, - const char ** out_detail) + const char **out_ptype, + const char **out_pitem, + const char **out_detail) { NMSettingConnectionPrivate *priv; - Permission * permission; + Permission *permission; g_return_val_if_fail(NM_IS_SETTING_CONNECTION(setting), FALSE); @@ -408,9 +408,9 @@ nm_setting_connection_permissions_user_allowed(NMSettingConnection *setting, con */ gboolean nm_setting_connection_add_permission(NMSettingConnection *setting, - const char * ptype, - const char * pitem, - const char * detail) + const char *ptype, + const char *pitem, + const char *detail) { NMSettingConnectionPrivate *priv; guint i; @@ -487,9 +487,9 @@ nm_setting_connection_remove_permission(NMSettingConnection *setting, guint32 id */ gboolean nm_setting_connection_remove_permission_by_value(NMSettingConnection *setting, - const char * ptype, - const char * pitem, - const char * detail) + const char *ptype, + const char *pitem, + const char *detail) { NMSettingConnectionPrivate *priv; guint i; @@ -1009,20 +1009,20 @@ _set_error_missing_base_setting(GError **error, const char *type) gboolean _nm_connection_detect_slave_type_full(NMSettingConnection *s_con, - NMConnection * connection, - const char ** out_slave_type, - const char ** out_normerr_slave_setting_type, - const char ** out_normerr_missing_slave_type, - const char ** out_normerr_missing_slave_type_port, - GError ** error) + NMConnection *connection, + const char **out_slave_type, + const char **out_normerr_slave_setting_type, + const char **out_normerr_missing_slave_type, + const char **out_normerr_missing_slave_type_port, + GError **error) { NMSettingConnectionPrivate *priv = NM_SETTING_CONNECTION_GET_PRIVATE(s_con); gboolean is_slave; - const char * slave_setting_type; - const char * slave_type; - const char * normerr_slave_setting_type = NULL; - const char * normerr_missing_slave_type = NULL; - const char * normerr_missing_slave_type_port = NULL; + const char *slave_setting_type; + const char *slave_type; + const char *normerr_slave_setting_type = NULL; + const char *normerr_missing_slave_type = NULL; + const char *normerr_missing_slave_type_port = NULL; is_slave = FALSE; slave_setting_type = NULL; @@ -1094,14 +1094,14 @@ _nm_connection_detect_slave_type_full(NMSettingConnection *s_con, static gboolean verify(NMSetting *setting, NMConnection *connection, GError **error) { - NMSettingConnection * self = NM_SETTING_CONNECTION(setting); + NMSettingConnection *self = NM_SETTING_CONNECTION(setting); NMSettingConnectionPrivate *priv = NM_SETTING_CONNECTION_GET_PRIVATE(self); - NMSetting * normerr_base_type = NULL; - const char * type; - const char * slave_type; - const char * normerr_slave_setting_type = NULL; - const char * normerr_missing_slave_type = NULL; - const char * normerr_missing_slave_type_port = NULL; + NMSetting *normerr_base_type = NULL; + const char *type; + const char *slave_type; + const char *normerr_slave_setting_type = NULL; + const char *normerr_missing_slave_type = NULL; + const char *normerr_missing_slave_type_port = NULL; gboolean normerr_base_setting = FALSE; gboolean uuid_was_normalized = FALSE; @@ -1187,7 +1187,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) /* Make sure the corresponding 'type' item is present */ if (connection && !nm_connection_get_setting_by_name(connection, type)) { - NMSetting * s_base; + NMSetting *s_base; NMConnection *connection2; s_base = g_object_new(base_type, NULL); @@ -1206,7 +1206,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } if (priv->interface_name) { - GError * tmp_error = NULL; + GError *tmp_error = NULL; NMUtilsIfaceType iface_type; if (NM_IN_STRSET(type, @@ -1215,7 +1215,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) iface_type = NMU_IFACE_OVS; else if (nm_streq(type, NM_SETTING_OVS_INTERFACE_SETTING_NAME)) { NMSettingOvsInterface *s_ovs_iface = NULL; - const char * ovs_iface_type; + const char *ovs_iface_type; if (connection) s_ovs_iface = nm_connection_get_setting_ovs_interface(connection); @@ -1533,7 +1533,7 @@ after_interface_name: static const char * find_virtual_interface_name(GVariant *connection_dict, GVariant **variant_to_free) { - GVariant * setting_dict; + GVariant *setting_dict; const char *interface_name; nm_assert(variant_to_free && !*variant_to_free); @@ -1569,7 +1569,7 @@ find_virtual_interface_name(GVariant *connection_dict, GVariant **variant_to_fre static gboolean nm_setting_connection_no_interface_name(_NM_SETT_INFO_PROP_MISSING_FROM_DBUS_FCN_ARGS _nm_nil) { - const char * virtual_interface_name; + const char *virtual_interface_name; gs_unref_variant GVariant *variant_to_free = NULL; virtual_interface_name = find_virtual_interface_name(connection_dict, &variant_to_free); @@ -1615,7 +1615,7 @@ compare_fcn_timestamp(_NM_SETT_INFO_PROP_COMPARE_FCN_ARGS _nm_nil) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMSettingConnection * setting = NM_SETTING_CONNECTION(object); + NMSettingConnection *setting = NM_SETTING_CONNECTION(object); NMSettingConnectionPrivate *priv = NM_SETTING_CONNECTION_GET_PRIVATE(setting); switch (prop_id) { @@ -1717,9 +1717,9 @@ finalize(GObject *object) static void nm_setting_connection_class_init(NMSettingConnectionClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingConnectionPrivate)); @@ -1908,7 +1908,8 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) PROP_TYPE, NM_SETTING_PARAM_INFERRABLE, NMSettingConnectionPrivate, - type); + type, + .direct_string_is_refstr = TRUE); /** * NMSettingConnection:permissions: diff --git a/src/libnm-core-impl/nm-setting-dcb.c b/src/libnm-core-impl/nm-setting-dcb.c index a6f4a973..d6890891 100644 --- a/src/libnm-core-impl/nm-setting-dcb.c +++ b/src/libnm-core-impl/nm-setting-dcb.c @@ -48,7 +48,7 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMSettingDcb, PROP_PRIORITY_TRAFFIC_CLASS, ); typedef struct { - char * app_fcoe_mode; + char *app_fcoe_mode; guint pfc[8]; guint priority_group_id[8]; guint priority_group_bandwidth[8]; @@ -514,14 +514,14 @@ check_dcb_flags(NMSettingDcbFlags flags, const char *prop_name, GError **error) } static gboolean -check_uint_array(const guint * array, +check_uint_array(const guint *array, guint len, NMSettingDcbFlags flags, guint max, guint extra, gboolean sum_pct, - const char * prop_name, - GError ** error) + const char *prop_name, + GError **error) { guint i, sum = 0; @@ -714,7 +714,7 @@ G_STATIC_ASSERT(sizeof(guint) == sizeof(gboolean)); static void set_array_from_gvalue(const GValue *v, uint *a, size_t len) { - GArray * src = g_value_get_boxed(v); + GArray *src = g_value_get_boxed(v); const guint total_len = len * sizeof(a[0]); memset(a, 0, total_len); @@ -761,7 +761,7 @@ static const NMSettInfoPropertType nm_sett_info_propert_type_dcb_au = static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMSettingDcb * setting = NM_SETTING_DCB(object); + NMSettingDcb *setting = NM_SETTING_DCB(object); NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE(setting); switch (prop_id) { @@ -841,9 +841,9 @@ nm_setting_dcb_new(void) static void nm_setting_dcb_class_init(NMSettingDcbClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingDcbPrivate)); diff --git a/src/libnm-core-impl/nm-setting-ethtool.c b/src/libnm-core-impl/nm-setting-ethtool.c index 901dab48..49c0d780 100644 --- a/src/libnm-core-impl/nm-setting-ethtool.c +++ b/src/libnm-core-impl/nm-setting-ethtool.c @@ -212,14 +212,14 @@ nm_setting_ethtool_clear_features(NMSettingEthtool *setting) guint nm_setting_ethtool_init_features( NMSettingEthtool *setting, - NMOptionBool * requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */) + NMOptionBool *requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */) { - GHashTable * hash; + GHashTable *hash; GHashTableIter iter; guint i; guint n_req = 0; - const char * name; - GVariant * variant; + const char *name; + GVariant *variant; nm_assert(NM_IS_SETTING_ETHTOOL(setting)); nm_assert(requested); @@ -286,7 +286,7 @@ static gboolean verify(NMSetting *setting, NMConnection *connection, GError **error) { const char *const *optnames; - GVariant *const * variants; + GVariant *const *variants; guint len; guint i; NMTernary pause_autoneg = NM_TERNARY_DEFAULT; @@ -296,8 +296,8 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) len = _nm_setting_option_get_all(setting, &optnames, &variants); for (i = 0; i < len; i++) { - const char * optname = optnames[i]; - GVariant * variant = variants[i]; + const char *optname = optnames[i]; + GVariant *variant = variants[i]; const GVariantType *variant_type; NMEthtoolID ethtool_id; diff --git a/src/libnm-core-impl/nm-setting-gsm.c b/src/libnm-core-impl/nm-setting-gsm.c index 8b2749d9..15460ccc 100644 --- a/src/libnm-core-impl/nm-setting-gsm.c +++ b/src/libnm-core-impl/nm-setting-gsm.c @@ -39,20 +39,20 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_AUTO_CONFIG, PROP_MTU, ); typedef struct { - char * number; /* For dialing, duh */ - char * username; - char * password; - char * device_id; - char * sim_id; - char * sim_operator_id; - char * apn; /* NULL for dynamic */ - char * network_id; /* for manual registration or NULL for automatic */ - char * pin; - NMSettingSecretFlags password_flags; - NMSettingSecretFlags pin_flags; - guint32 mtu; - bool auto_config; - bool home_only; + char *number; + char *username; + char *password; + char *device_id; + char *sim_id; + char *sim_operator_id; + char *apn; + char *network_id; + char *pin; + guint password_flags; + guint pin_flags; + guint32 mtu; + bool auto_config; + bool home_only; } NMSettingGsmPrivate; /** @@ -463,7 +463,7 @@ static GPtrArray * need_secrets(NMSetting *setting) { NMSettingGsmPrivate *priv = NM_SETTING_GSM_GET_PRIVATE(setting); - GPtrArray * secrets = NULL; + GPtrArray *secrets = NULL; if (priv->password && *priv->password) return NULL; @@ -480,132 +480,6 @@ need_secrets(NMSetting *setting) /*****************************************************************************/ -static void -get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - NMSettingGsm *setting = NM_SETTING_GSM(object); - - switch (prop_id) { - case PROP_AUTO_CONFIG: - g_value_set_boolean(value, nm_setting_gsm_get_auto_config(setting)); - break; - case PROP_NUMBER: - g_value_set_string(value, nm_setting_gsm_get_number(setting)); - break; - case PROP_USERNAME: - g_value_set_string(value, nm_setting_gsm_get_username(setting)); - break; - case PROP_PASSWORD: - g_value_set_string(value, nm_setting_gsm_get_password(setting)); - break; - case PROP_PASSWORD_FLAGS: - g_value_set_flags(value, nm_setting_gsm_get_password_flags(setting)); - break; - case PROP_APN: - g_value_set_string(value, nm_setting_gsm_get_apn(setting)); - break; - case PROP_NETWORK_ID: - g_value_set_string(value, nm_setting_gsm_get_network_id(setting)); - break; - case PROP_PIN: - g_value_set_string(value, nm_setting_gsm_get_pin(setting)); - break; - case PROP_PIN_FLAGS: - g_value_set_flags(value, nm_setting_gsm_get_pin_flags(setting)); - break; - case PROP_HOME_ONLY: - g_value_set_boolean(value, nm_setting_gsm_get_home_only(setting)); - break; - case PROP_DEVICE_ID: - g_value_set_string(value, nm_setting_gsm_get_device_id(setting)); - break; - case PROP_SIM_ID: - g_value_set_string(value, nm_setting_gsm_get_sim_id(setting)); - break; - case PROP_SIM_OPERATOR_ID: - g_value_set_string(value, nm_setting_gsm_get_sim_operator_id(setting)); - break; - case PROP_MTU: - g_value_set_uint(value, nm_setting_gsm_get_mtu(setting)); - 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) -{ - NMSettingGsmPrivate *priv = NM_SETTING_GSM_GET_PRIVATE(object); - char * tmp; - - switch (prop_id) { - case PROP_AUTO_CONFIG: - priv->auto_config = g_value_get_boolean(value); - break; - case PROP_NUMBER: - g_free(priv->number); - priv->number = g_value_dup_string(value); - break; - case PROP_USERNAME: - g_free(priv->username); - priv->username = g_value_dup_string(value); - break; - case PROP_PASSWORD: - g_free(priv->password); - priv->password = g_value_dup_string(value); - break; - case PROP_PASSWORD_FLAGS: - priv->password_flags = g_value_get_flags(value); - break; - case PROP_APN: - g_free(priv->apn); - priv->apn = NULL; - tmp = g_value_dup_string(value); - if (tmp) - priv->apn = g_strstrip(tmp); - break; - case PROP_NETWORK_ID: - g_free(priv->network_id); - priv->network_id = NULL; - tmp = g_value_dup_string(value); - if (tmp) - priv->network_id = g_strstrip(tmp); - break; - case PROP_PIN: - g_free(priv->pin); - priv->pin = g_value_dup_string(value); - break; - case PROP_PIN_FLAGS: - priv->pin_flags = g_value_get_flags(value); - break; - case PROP_HOME_ONLY: - priv->home_only = g_value_get_boolean(value); - break; - case PROP_DEVICE_ID: - g_free(priv->device_id); - priv->device_id = g_value_dup_string(value); - break; - case PROP_SIM_ID: - g_free(priv->sim_id); - priv->sim_id = g_value_dup_string(value); - break; - case PROP_SIM_OPERATOR_ID: - g_free(priv->sim_operator_id); - priv->sim_operator_id = g_value_dup_string(value); - break; - case PROP_MTU: - priv->mtu = g_value_get_uint(value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } -} - -/*****************************************************************************/ - static void nm_setting_gsm_init(NMSettingGsm *setting) {} @@ -623,36 +497,17 @@ nm_setting_gsm_new(void) return g_object_new(NM_TYPE_SETTING_GSM, NULL); } -static void -finalize(GObject *object) -{ - NMSettingGsmPrivate *priv = NM_SETTING_GSM_GET_PRIVATE(object); - - g_free(priv->number); - g_free(priv->username); - g_free(priv->password); - g_free(priv->apn); - g_free(priv->network_id); - g_free(priv->pin); - g_free(priv->device_id); - g_free(priv->sim_id); - g_free(priv->sim_operator_id); - - G_OBJECT_CLASS(nm_setting_gsm_parent_class)->finalize(object); -} - static void nm_setting_gsm_class_init(NMSettingGsmClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingGsmPrivate)); - object_class->get_property = get_property; - object_class->set_property = set_property; - object_class->finalize = finalize; + object_class->get_property = _nm_setting_property_get_property_direct; + object_class->set_property = _nm_setting_property_set_property_direct; setting_class->verify = verify; setting_class->verify_secrets = verify_secrets; @@ -684,11 +539,13 @@ nm_setting_gsm_class_init(NMSettingGsmClass *klass) * * Deprecated: 1.16: User-provided values for this setting are no longer used. **/ - obj_properties[PROP_NUMBER] = g_param_spec_string(NM_SETTING_GSM_NUMBER, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_GSM_NUMBER, + PROP_NUMBER, + NM_SETTING_PARAM_NONE, + NMSettingGsmPrivate, + number); /** * NMSettingGsm:username: @@ -697,11 +554,13 @@ nm_setting_gsm_class_init(NMSettingGsmClass *klass) * providers do not require a username, or accept any username. But if a * username is required, it is specified here. **/ - obj_properties[PROP_USERNAME] = g_param_spec_string(NM_SETTING_GSM_USERNAME, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_GSM_USERNAME, + PROP_USERNAME, + NM_SETTING_PARAM_NONE, + NMSettingGsmPrivate, + username); /** * NMSettingGsm:password: @@ -710,26 +569,25 @@ nm_setting_gsm_class_init(NMSettingGsmClass *klass) * providers do not require a password, or accept any password. But if a * password is required, it is specified here. **/ - obj_properties[PROP_PASSWORD] = - g_param_spec_string(NM_SETTING_GSM_PASSWORD, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_GSM_PASSWORD, + PROP_PASSWORD, + NM_SETTING_PARAM_SECRET, + NMSettingGsmPrivate, + password); /** * NMSettingGsm:password-flags: * * Flags indicating how to handle the #NMSettingGsm:password property. **/ - obj_properties[PROP_PASSWORD_FLAGS] = - g_param_spec_flags(NM_SETTING_GSM_PASSWORD_FLAGS, - "", - "", - NM_TYPE_SETTING_SECRET_FLAGS, - NM_SETTING_SECRET_FLAG_NONE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - + _nm_setting_property_define_direct_secret_flags(properties_override, + obj_properties, + NM_SETTING_GSM_PASSWORD_FLAGS, + PROP_PASSWORD_FLAGS, + NMSettingGsmPrivate, + password_flags); /** * NMSettingGsm:apn: * @@ -741,11 +599,14 @@ nm_setting_gsm_class_init(NMSettingGsmClass *klass) * The APN may only be composed of the characters a-z, 0-9, ., and - per GSM * 03.60 Section 14.9. **/ - obj_properties[PROP_APN] = g_param_spec_string(NM_SETTING_GSM_APN, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_GSM_APN, + PROP_APN, + NM_SETTING_PARAM_NONE, + NMSettingGsmPrivate, + apn, + .direct_set_string_strip = TRUE); /** * NMSettingGsm:network-id: @@ -756,12 +617,14 @@ nm_setting_gsm_class_init(NMSettingGsmClass *klass) * This can be used to ensure that the device does not roam when direct * roaming control of the device is not otherwise possible. **/ - obj_properties[PROP_NETWORK_ID] = - g_param_spec_string(NM_SETTING_GSM_NETWORK_ID, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_GSM_NETWORK_ID, + PROP_NETWORK_ID, + NM_SETTING_PARAM_NONE, + NMSettingGsmPrivate, + network_id, + .direct_set_string_strip = TRUE); /** * NMSettingGsm:pin: @@ -770,24 +633,25 @@ nm_setting_gsm_class_init(NMSettingGsmClass *klass) * operations are requested. Specify the PIN here to allow operation of the * device. **/ - obj_properties[PROP_PIN] = - g_param_spec_string(NM_SETTING_GSM_PIN, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_GSM_PIN, + PROP_PIN, + NM_SETTING_PARAM_SECRET, + NMSettingGsmPrivate, + pin); /** * NMSettingGsm:pin-flags: * * Flags indicating how to handle the #NMSettingGsm:pin property. **/ - obj_properties[PROP_PIN_FLAGS] = g_param_spec_flags(NM_SETTING_GSM_PIN_FLAGS, - "", - "", - NM_TYPE_SETTING_SECRET_FLAGS, - NM_SETTING_SECRET_FLAG_NONE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_secret_flags(properties_override, + obj_properties, + NM_SETTING_GSM_PIN_FLAGS, + PROP_PIN_FLAGS, + NMSettingGsmPrivate, + pin_flags); /** * NMSettingGsm:home-only: @@ -813,12 +677,13 @@ nm_setting_gsm_class_init(NMSettingGsmClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_DEVICE_ID] = - g_param_spec_string(NM_SETTING_GSM_DEVICE_ID, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_GSM_DEVICE_ID, + PROP_DEVICE_ID, + NM_SETTING_PARAM_NONE, + NMSettingGsmPrivate, + device_id); /** * NMSettingGsm:sim-id: @@ -830,11 +695,13 @@ nm_setting_gsm_class_init(NMSettingGsmClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_SIM_ID] = g_param_spec_string(NM_SETTING_GSM_SIM_ID, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_GSM_SIM_ID, + PROP_SIM_ID, + NM_SETTING_PARAM_NONE, + NMSettingGsmPrivate, + sim_id); /** * NMSettingGsm:sim-operator-id: @@ -847,12 +714,13 @@ nm_setting_gsm_class_init(NMSettingGsmClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_SIM_OPERATOR_ID] = - g_param_spec_string(NM_SETTING_GSM_SIM_OPERATOR_ID, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_GSM_SIM_OPERATOR_ID, + PROP_SIM_OPERATOR_ID, + NM_SETTING_PARAM_NONE, + NMSettingGsmPrivate, + sim_operator_id); /** * NMSettingGsm:mtu: @@ -862,14 +730,16 @@ nm_setting_gsm_class_init(NMSettingGsmClass *klass) * * Since: 1.8 **/ - obj_properties[PROP_MTU] = g_param_spec_uint(NM_SETTING_GSM_MTU, - "", - "", - 0, - G_MAXUINT32, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE - | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_GSM_MTU, + PROP_MTU, + 0, + G_MAXUINT32, + 0, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingGsmPrivate, + mtu); /* Ignore incoming deprecated properties */ _nm_properties_override_dbus(properties_override, diff --git a/src/libnm-core-impl/nm-setting-hostname.c b/src/libnm-core-impl/nm-setting-hostname.c index d0a15684..276a75a8 100644 --- a/src/libnm-core-impl/nm-setting-hostname.c +++ b/src/libnm-core-impl/nm-setting-hostname.c @@ -145,9 +145,9 @@ nm_setting_hostname_new(void) static void nm_setting_hostname_class_init(NMSettingHostnameClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); object_class->get_property = _nm_setting_property_get_property_direct; object_class->set_property = _nm_setting_property_set_property_direct; diff --git a/src/libnm-core-impl/nm-setting-infiniband.c b/src/libnm-core-impl/nm-setting-infiniband.c index adbf3636..eb6c9536 100644 --- a/src/libnm-core-impl/nm-setting-infiniband.c +++ b/src/libnm-core-impl/nm-setting-infiniband.c @@ -32,11 +32,13 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_MAC_ADDRESS, PROP_PARENT, ); typedef struct { - char * mac_address; - char * transport_mode; - char * parent; - char * virtual_iface_name; - int p_key; + char *mac_address; + char *transport_mode; + char *parent; + char *virtual_iface_name; + gsize virtual_iface_name_parent_length; + gint32 virtual_iface_name_p_key; + gint32 p_key; guint32 mtu; } NMSettingInfinibandPrivate; @@ -156,20 +158,30 @@ const char * nm_setting_infiniband_get_virtual_interface_name(NMSettingInfiniband *setting) { NMSettingInfinibandPrivate *priv = NM_SETTING_INFINIBAND_GET_PRIVATE(setting); + gsize len; - if (priv->p_key == -1 || !priv->parent) + if (priv->p_key == -1 || !priv->parent) { + nm_clear_g_free(&priv->virtual_iface_name); return NULL; + } - if (!priv->virtual_iface_name) + len = strlen(priv->parent); + if (!priv->virtual_iface_name || priv->virtual_iface_name_p_key != priv->p_key + || priv->virtual_iface_name_parent_length != len + || memcmp(priv->parent, priv->virtual_iface_name, len) != 0) { + priv->virtual_iface_name_p_key = priv->p_key; + priv->virtual_iface_name_parent_length = len; + g_free(priv->virtual_iface_name); priv->virtual_iface_name = g_strdup_printf("%s.%04x", priv->parent, priv->p_key); + } - return NM_SETTING_INFINIBAND_GET_PRIVATE(setting)->virtual_iface_name; + return priv->virtual_iface_name; } static gboolean verify(NMSetting *setting, NMConnection *connection, GError **error) { - NMSettingConnection * s_con = NULL; + NMSettingConnection *s_con = NULL; NMSettingInfinibandPrivate *priv = NM_SETTING_INFINIBAND_GET_PRIVATE(setting); if (priv->mac_address && !nm_utils_hwaddr_valid(priv->mac_address, INFINIBAND_ALEN)) { @@ -237,10 +249,12 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) const char *interface_name = nm_setting_connection_get_interface_name(s_con); if (interface_name && priv->p_key != -1) { - if (!priv->virtual_iface_name) - priv->virtual_iface_name = g_strdup_printf("%s.%04x", priv->parent, priv->p_key); + const char *virtual_iface_name; - if (strcmp(interface_name, priv->virtual_iface_name) != 0) { + virtual_iface_name = + nm_setting_infiniband_get_virtual_interface_name(NM_SETTING_INFINIBAND(setting)); + + if (!nm_streq(interface_name, virtual_iface_name)) { /* We don't support renaming software infiniband devices. Later we might, but * for now just reject such connections. **/ @@ -249,7 +263,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) NM_CONNECTION_ERROR_INVALID_PROPERTY, _("interface name of software infiniband device must be '%s' or unset " "(instead it is '%s')"), - priv->virtual_iface_name, + virtual_iface_name, interface_name); g_prefix_error(error, "%s.%s: ", @@ -290,75 +304,9 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) /*****************************************************************************/ -static void -get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - NMSettingInfiniband *setting = NM_SETTING_INFINIBAND(object); - - switch (prop_id) { - case PROP_MAC_ADDRESS: - g_value_set_string(value, nm_setting_infiniband_get_mac_address(setting)); - break; - case PROP_MTU: - g_value_set_uint(value, nm_setting_infiniband_get_mtu(setting)); - break; - case PROP_TRANSPORT_MODE: - g_value_set_string(value, nm_setting_infiniband_get_transport_mode(setting)); - break; - case PROP_P_KEY: - g_value_set_int(value, nm_setting_infiniband_get_p_key(setting)); - break; - case PROP_PARENT: - g_value_set_string(value, nm_setting_infiniband_get_parent(setting)); - 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) -{ - NMSettingInfinibandPrivate *priv = NM_SETTING_INFINIBAND_GET_PRIVATE(object); - - switch (prop_id) { - case PROP_MAC_ADDRESS: - g_free(priv->mac_address); - priv->mac_address = - _nm_utils_hwaddr_canonical_or_invalid(g_value_get_string(value), INFINIBAND_ALEN); - break; - case PROP_MTU: - priv->mtu = g_value_get_uint(value); - break; - case PROP_TRANSPORT_MODE: - g_free(priv->transport_mode); - priv->transport_mode = g_value_dup_string(value); - break; - case PROP_P_KEY: - priv->p_key = g_value_get_int(value); - nm_clear_g_free(&priv->virtual_iface_name); - break; - case PROP_PARENT: - g_free(priv->parent); - priv->parent = g_value_dup_string(value); - nm_clear_g_free(&priv->virtual_iface_name); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } -} - -/*****************************************************************************/ - static void nm_setting_infiniband_init(NMSettingInfiniband *self) -{ - NMSettingInfinibandPrivate *priv = NM_SETTING_INFINIBAND_GET_PRIVATE(self); - - priv->p_key = -1; -} +{} /** * nm_setting_infiniband_new: @@ -378,8 +326,6 @@ finalize(GObject *object) { NMSettingInfinibandPrivate *priv = NM_SETTING_INFINIBAND_GET_PRIVATE(object); - g_free(priv->transport_mode); - g_free(priv->parent); g_free(priv->virtual_iface_name); G_OBJECT_CLASS(nm_setting_infiniband_parent_class)->finalize(object); @@ -388,14 +334,14 @@ finalize(GObject *object) static void nm_setting_infiniband_class_init(NMSettingInfinibandClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingInfinibandPrivate)); - object_class->get_property = get_property; - object_class->set_property = set_property; + object_class->get_property = _nm_setting_property_get_property_direct; + object_class->set_property = _nm_setting_property_set_property_direct; object_class->finalize = finalize; setting_class->verify = verify; @@ -447,14 +393,16 @@ nm_setting_infiniband_class_init(NMSettingInfinibandClass *klass) * description: MTU of the interface. * ---end--- */ - obj_properties[PROP_MTU] = g_param_spec_uint(NM_SETTING_INFINIBAND_MTU, - "", - "", - 0, - G_MAXUINT32, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE - | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_INFINIBAND_MTU, + PROP_MTU, + 0, + G_MAXUINT32, + 0, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingInfinibandPrivate, + mtu); /** * NMSettingInfiniband:transport-mode: @@ -470,12 +418,13 @@ nm_setting_infiniband_class_init(NMSettingInfinibandClass *klass) * "datagram" mode * ---end--- */ - obj_properties[PROP_TRANSPORT_MODE] = g_param_spec_string( - NM_SETTING_INFINIBAND_TRANSPORT_MODE, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_INFINIBAND_TRANSPORT_MODE, + PROP_TRANSPORT_MODE, + NM_SETTING_PARAM_INFERRABLE, + NMSettingInfinibandPrivate, + transport_mode); /** * NMSettingInfiniband:p-key: @@ -495,14 +444,16 @@ nm_setting_infiniband_class_init(NMSettingInfinibandClass *klass) * example: PKEY=yes PKEY_ID=2 PHYSDEV=mlx4_ib0 DEVICE=mlx4_ib0.8002 * ---end--- */ - obj_properties[PROP_P_KEY] = - g_param_spec_int(NM_SETTING_INFINIBAND_P_KEY, - "", - "", - -1, - 0xFFFF, - -1, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_int32(properties_override, + obj_properties, + NM_SETTING_INFINIBAND_P_KEY, + PROP_P_KEY, + -1, + 0xFFFF, + -1, + NM_SETTING_PARAM_INFERRABLE, + NMSettingInfinibandPrivate, + p_key); /** * NMSettingInfiniband:parent: @@ -520,12 +471,13 @@ nm_setting_infiniband_class_init(NMSettingInfinibandClass *klass) * example: PHYSDEV=ib0 * ---end--- */ - obj_properties[PROP_PARENT] = g_param_spec_string( - NM_SETTING_INFINIBAND_PARENT, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_INFINIBAND_PARENT, + PROP_PARENT, + NM_SETTING_PARAM_INFERRABLE, + NMSettingInfinibandPrivate, + parent); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-ip-config.c b/src/libnm-core-impl/nm-setting-ip-config.c index 33779ed9..52aa6515 100644 --- a/src/libnm-core-impl/nm-setting-ip-config.c +++ b/src/libnm-core-impl/nm-setting-ip-config.c @@ -54,56 +54,24 @@ const NMUtilsDNSOptionDesc _nm_utils_dns_option_descs[] = { {NULL, FALSE, FALSE}}; static char * -canonicalize_ip(int family, const char *ip, gboolean null_any) +canonicalize_ip_binary(int family, const NMIPAddr *ip, gboolean null_any) { - guint8 addr_bytes[sizeof(struct in6_addr)]; - char addr_str[NM_UTILS_INET_ADDRSTRLEN]; - int ret; - if (!ip) { if (null_any) return NULL; - if (family == AF_INET) + if (NM_IS_IPv4(family)) return g_strdup("0.0.0.0"); - if (family == AF_INET6) - return g_strdup("::"); - g_return_val_if_reached(NULL); + return g_strdup("::"); } - ret = inet_pton(family, ip, addr_bytes); - g_return_val_if_fail(ret == 1, NULL); - - if (null_any) { - if (!memcmp(addr_bytes, &in6addr_any, nm_utils_addr_family_to_size(family))) - return NULL; - } + if (null_any && nm_ip_addr_is_null(family, ip)) + return NULL; - return g_strdup(inet_ntop(family, addr_bytes, addr_str, sizeof(addr_str))); -} - -static char * -canonicalize_ip_binary(int family, gconstpointer ip, gboolean null_any) -{ - char string[NM_UTILS_INET_ADDRSTRLEN]; - - if (!ip) { - if (null_any) - return NULL; - if (family == AF_INET) - return g_strdup("0.0.0.0"); - if (family == AF_INET6) - return g_strdup("::"); - g_return_val_if_reached(NULL); - } - if (null_any) { - if (!memcmp(ip, &in6addr_any, nm_utils_addr_family_to_size(family))) - return NULL; - } - return g_strdup(inet_ntop(family, ip, string, sizeof(string))); + return nm_utils_inet_ntop_dup(family, ip); } static gboolean -valid_ip(int family, const char *ip, GError **error) +valid_ip(int family, const char *ip, NMIPAddr *addr, GError **error) { if (!ip) { g_set_error(error, @@ -112,7 +80,7 @@ valid_ip(int family, const char *ip, GError **error) family == AF_INET ? _("Missing IPv4 address") : _("Missing IPv6 address")); return FALSE; } - if (!nm_utils_ipaddr_is_valid(family, ip)) { + if (!nm_utils_parse_inaddr_bin(family, ip, NULL, addr)) { g_set_error(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED, @@ -120,8 +88,9 @@ valid_ip(int family, const char *ip, GError **error) : _("Invalid IPv6 address '%s'"), ip); return FALSE; - } else - return TRUE; + } + + return TRUE; } static gboolean @@ -169,9 +138,10 @@ G_DEFINE_BOXED_TYPE(NMIPAddress, nm_ip_address, nm_ip_address_dup, nm_ip_address struct NMIPAddress { guint refcount; - char *address; - int prefix, family; + gint8 family; + guint8 prefix; + char *address; GHashTable *attributes; }; @@ -191,21 +161,23 @@ NMIPAddress * nm_ip_address_new(int family, const char *addr, guint prefix, GError **error) { NMIPAddress *address; + NMIPAddr addr_bin; g_return_val_if_fail(family == AF_INET || family == AF_INET6, NULL); g_return_val_if_fail(addr != NULL, NULL); - if (!valid_ip(family, addr, error)) + if (!valid_ip(family, addr, &addr_bin, error)) return NULL; if (!valid_prefix(family, prefix, error)) return NULL; - address = g_slice_new0(NMIPAddress); - address->refcount = 1; - - address->family = family; - address->address = canonicalize_ip(family, addr, FALSE); - address->prefix = prefix; + address = g_slice_new(NMIPAddress); + *address = (NMIPAddress){ + .refcount = 1, + .family = family, + .address = canonicalize_ip_binary(family, &addr_bin, FALSE), + .prefix = prefix, + }; return address; } @@ -227,7 +199,6 @@ NMIPAddress * nm_ip_address_new_binary(int family, gconstpointer addr, guint prefix, GError **error) { NMIPAddress *address; - char string[NM_UTILS_INET_ADDRSTRLEN]; g_return_val_if_fail(family == AF_INET || family == AF_INET6, NULL); g_return_val_if_fail(addr != NULL, NULL); @@ -235,12 +206,13 @@ nm_ip_address_new_binary(int family, gconstpointer addr, guint prefix, GError ** if (!valid_prefix(family, prefix, error)) return NULL; - address = g_slice_new0(NMIPAddress); - address->refcount = 1; - - address->family = family; - address->address = g_strdup(inet_ntop(family, addr, string, sizeof(string))); - address->prefix = prefix; + address = g_slice_new(NMIPAddress); + *address = (NMIPAddress){ + .refcount = 1, + .family = family, + .address = nm_utils_inet_ntop_dup(family, addr), + .prefix = prefix, + }; return address; } @@ -276,9 +248,8 @@ nm_ip_address_unref(NMIPAddress *address) address->refcount--; if (address->refcount == 0) { g_free(address->address); - if (address->attributes) - g_hash_table_unref(address->attributes); - g_slice_free(NMIPAddress, address); + nm_g_hash_table_unref(address->attributes); + nm_g_slice_free(address); } } @@ -311,8 +282,8 @@ nm_ip_address_cmp_full(const NMIPAddress *a, const NMIPAddress *b, NMIPAddressCm if (NM_FLAGS_HAS(cmp_flags, NM_IP_ADDRESS_CMP_FLAGS_WITH_ATTRS)) { GHashTableIter iter; - const char * key; - GVariant * value, *value2; + const char *key; + GVariant *value, *value2; guint n; n = a->attributes ? g_hash_table_size(a->attributes) : 0u; @@ -382,8 +353,8 @@ nm_ip_address_dup(NMIPAddress *address) copy = nm_ip_address_new(address->family, address->address, address->prefix, NULL); if (address->attributes) { GHashTableIter iter; - const char * key; - GVariant * value; + const char *key; + GVariant *value; g_hash_table_iter_init(&iter, address->attributes); while (g_hash_table_iter_next(&iter, (gpointer *) &key, (gpointer *) &value)) @@ -441,12 +412,18 @@ nm_ip_address_get_address(NMIPAddress *address) void nm_ip_address_set_address(NMIPAddress *address, const char *addr) { + NMIPAddr addr_bin; + g_return_if_fail(address != NULL); - g_return_if_fail(addr != NULL); - g_return_if_fail(nm_utils_ipaddr_is_valid(address->family, addr)); + + if (!valid_ip(address->family, addr, &addr_bin, NULL)) { + g_return_if_fail(addr != NULL); + g_return_if_fail(nm_utils_ipaddr_is_valid(address->family, addr)); + nm_assert_not_reached(); + } g_free(address->address); - address->address = canonicalize_ip(address->family, addr, FALSE); + address->address = canonicalize_ip_binary(address->family, &addr_bin, FALSE); } /** @@ -479,13 +456,11 @@ nm_ip_address_get_address_binary(NMIPAddress *address, gpointer addr) void nm_ip_address_set_address_binary(NMIPAddress *address, gconstpointer addr) { - char string[NM_UTILS_INET_ADDRSTRLEN]; - g_return_if_fail(address != NULL); g_return_if_fail(addr != NULL); g_free(address->address); - address->address = g_strdup(inet_ntop(address->family, addr, string, sizeof(string))); + address->address = nm_utils_inet_ntop_dup(address->family, addr); } /** @@ -608,13 +583,14 @@ G_DEFINE_BOXED_TYPE(NMIPRoute, nm_ip_route, nm_ip_route_dup, nm_ip_route_unref) struct NMIPRoute { guint refcount; - int family; - char * dest; - guint prefix; - char * next_hop; - gint64 metric; + gint8 family; + guint8 prefix; + char *dest; + char *next_hop; GHashTable *attributes; + + gint64 metric; }; /** @@ -637,30 +613,33 @@ nm_ip_route_new(int family, guint prefix, const char *next_hop, gint64 metric, - GError ** error) + GError **error) { NMIPRoute *route; + NMIPAddr dest_bin; + NMIPAddr next_hop_bin; g_return_val_if_fail(family == AF_INET || family == AF_INET6, NULL); g_return_val_if_fail(dest, NULL); - if (!valid_ip(family, dest, error)) + if (!valid_ip(family, dest, &dest_bin, error)) return NULL; if (!valid_prefix(family, prefix, error)) return NULL; - if (next_hop && !valid_ip(family, next_hop, error)) + if (next_hop && !valid_ip(family, next_hop, &next_hop_bin, error)) return NULL; if (!valid_metric(metric, error)) return NULL; - route = g_slice_new0(NMIPRoute); - route->refcount = 1; - - route->family = family; - route->dest = canonicalize_ip(family, dest, FALSE); - route->prefix = prefix; - route->next_hop = canonicalize_ip(family, next_hop, TRUE); - route->metric = metric; + route = g_slice_new(NMIPRoute); + *route = (NMIPRoute){ + .refcount = 1, + .family = family, + .dest = canonicalize_ip_binary(family, &dest_bin, FALSE), + .prefix = prefix, + .next_hop = canonicalize_ip_binary(family, next_hop ? &next_hop_bin : NULL, TRUE), + .metric = metric, + }; return route; } @@ -686,7 +665,7 @@ nm_ip_route_new_binary(int family, guint prefix, gconstpointer next_hop, gint64 metric, - GError ** error) + GError **error) { NMIPRoute *route; @@ -698,14 +677,15 @@ nm_ip_route_new_binary(int family, if (!valid_metric(metric, error)) return NULL; - route = g_slice_new0(NMIPRoute); - route->refcount = 1; - - route->family = family; - route->dest = canonicalize_ip_binary(family, dest, FALSE); - route->prefix = prefix; - route->next_hop = canonicalize_ip_binary(family, next_hop, TRUE); - route->metric = metric; + route = g_slice_new0(NMIPRoute); + *route = (NMIPRoute){ + .refcount = 1, + .family = family, + .dest = canonicalize_ip_binary(family, dest, FALSE), + .prefix = prefix, + .next_hop = canonicalize_ip_binary(family, next_hop, TRUE), + .metric = metric, + }; return route; } @@ -742,9 +722,8 @@ nm_ip_route_unref(NMIPRoute *route) if (route->refcount == 0) { g_free(route->dest); g_free(route->next_hop); - if (route->attributes) - g_hash_table_unref(route->attributes); - g_slice_free(NMIPRoute, route); + nm_g_hash_table_unref(route->attributes); + nm_g_slice_free(route); } } @@ -783,8 +762,8 @@ nm_ip_route_equal_full(NMIPRoute *route, NMIPRoute *other, guint cmp_flags) return FALSE; if (cmp_flags == NM_IP_ROUTE_EQUAL_CMP_FLAGS_WITH_ATTRS) { GHashTableIter iter; - const char * key; - GVariant * value, *value2; + const char *key; + GVariant *value, *value2; guint n; n = route->attributes ? g_hash_table_size(route->attributes) : 0u; @@ -850,8 +829,8 @@ nm_ip_route_dup(NMIPRoute *route) NULL); if (route->attributes) { GHashTableIter iter; - const char * key; - GVariant * value; + const char *key; + GVariant *value; g_hash_table_iter_init(&iter, route->attributes); while (g_hash_table_iter_next(&iter, (gpointer *) &key, (gpointer *) &value)) @@ -909,11 +888,17 @@ nm_ip_route_get_dest(NMIPRoute *route) void nm_ip_route_set_dest(NMIPRoute *route, const char *dest) { + NMIPAddr dest_bin; + g_return_if_fail(route != NULL); - g_return_if_fail(nm_utils_ipaddr_is_valid(route->family, dest)); + + if (!valid_ip(route->family, dest, &dest_bin, NULL)) { + g_return_if_fail(nm_utils_ipaddr_is_valid(route->family, dest)); + nm_assert_not_reached(); + } g_free(route->dest); - route->dest = canonicalize_ip(route->family, dest, FALSE); + route->dest = canonicalize_ip_binary(route->family, &dest_bin, FALSE); } /** @@ -946,13 +931,11 @@ nm_ip_route_get_dest_binary(NMIPRoute *route, gpointer dest) void nm_ip_route_set_dest_binary(NMIPRoute *route, gconstpointer dest) { - char string[NM_UTILS_INET_ADDRSTRLEN]; - g_return_if_fail(route != NULL); g_return_if_fail(dest != NULL); g_free(route->dest); - route->dest = g_strdup(inet_ntop(route->family, dest, string, sizeof(string))); + route->dest = nm_utils_inet_ntop_dup(route->family, dest); } /** @@ -1020,11 +1003,17 @@ nm_ip_route_get_next_hop(NMIPRoute *route) void nm_ip_route_set_next_hop(NMIPRoute *route, const char *next_hop) { + NMIPAddr next_hop_bin; + g_return_if_fail(route != NULL); - g_return_if_fail(!next_hop || nm_utils_ipaddr_is_valid(route->family, next_hop)); + + if (next_hop && !valid_ip(route->family, next_hop, &next_hop_bin, NULL)) { + g_return_if_fail(!next_hop || nm_utils_ipaddr_is_valid(route->family, next_hop)); + nm_assert_not_reached(); + } g_free(route->next_hop); - route->next_hop = canonicalize_ip(route->family, next_hop, TRUE); + route->next_hop = canonicalize_ip_binary(route->family, next_hop ? &next_hop_bin : NULL, TRUE); } /** @@ -1214,8 +1203,8 @@ static const NMVariantAttributeSpec *const ip_route_attribute_spec[] = { .v6 = TRUE, ), NM_VARIANT_ATTRIBUTE_SPEC_DEFINE(NM_IP_ROUTE_ATTRIBUTE_FROM, G_VARIANT_TYPE_STRING, - .v6 = TRUE, - .str_type = 'p', ), + .v6 = TRUE, + .type_detail = 'p', ), NM_VARIANT_ATTRIBUTE_SPEC_DEFINE(NM_IP_ROUTE_ATTRIBUTE_INITCWND, G_VARIANT_TYPE_UINT32, .v4 = TRUE, @@ -1254,12 +1243,13 @@ static const NMVariantAttributeSpec *const ip_route_attribute_spec[] = { .v6 = TRUE, ), NM_VARIANT_ATTRIBUTE_SPEC_DEFINE(NM_IP_ROUTE_ATTRIBUTE_SCOPE, G_VARIANT_TYPE_BYTE, - .v4 = TRUE, ), + .v4 = TRUE, + .type_detail = 's'), NM_VARIANT_ATTRIBUTE_SPEC_DEFINE(NM_IP_ROUTE_ATTRIBUTE_SRC, G_VARIANT_TYPE_STRING, - .v4 = TRUE, - .v6 = TRUE, - .str_type = 'a', ), + .v4 = TRUE, + .v6 = TRUE, + .type_detail = 'a', ), NM_VARIANT_ATTRIBUTE_SPEC_DEFINE(NM_IP_ROUTE_ATTRIBUTE_TABLE, G_VARIANT_TYPE_UINT32, .v4 = TRUE, @@ -1267,9 +1257,9 @@ static const NMVariantAttributeSpec *const ip_route_attribute_spec[] = { NM_VARIANT_ATTRIBUTE_SPEC_DEFINE(NM_IP_ROUTE_ATTRIBUTE_TOS, G_VARIANT_TYPE_BYTE, .v4 = TRUE, ), NM_VARIANT_ATTRIBUTE_SPEC_DEFINE(NM_IP_ROUTE_ATTRIBUTE_TYPE, G_VARIANT_TYPE_STRING, - .v4 = TRUE, - .v6 = TRUE, - .str_type = 'T', ), + .v4 = TRUE, + .v6 = TRUE, + .type_detail = 'T', ), NM_VARIANT_ATTRIBUTE_SPEC_DEFINE(NM_IP_ROUTE_ATTRIBUTE_WINDOW, G_VARIANT_TYPE_UINT32, .v4 = TRUE, @@ -1290,34 +1280,26 @@ nm_ip_route_get_variant_attribute_spec(void) return ip_route_attribute_spec; } -/** - * nm_ip_route_attribute_validate: - * @name: the attribute name - * @value: the attribute value - * @family: IP address family of the route - * @known: (out): on return, whether the attribute name is a known one - * @error: (allow-none): return location for a #GError, or %NULL - * - * Validates a route attribute, i.e. checks that the attribute is a known one - * and the value is of the correct type and well-formed. - * - * Returns: %TRUE if the attribute is valid, %FALSE otherwise - * - * Since: 1.8 - */ -gboolean -nm_ip_route_attribute_validate(const char *name, - GVariant * value, - int family, - gboolean * known, - GError ** error) +typedef struct { + int type; + int scope; +} IPRouteAttrParseData; + +static gboolean +_ip_route_attribute_validate(const char *name, + GVariant *value, + int family, + IPRouteAttrParseData *parse_data, + gboolean *known, + GError **error) { const NMVariantAttributeSpec *spec; + const char *string; - g_return_val_if_fail(name, FALSE); - g_return_val_if_fail(value, FALSE); - g_return_val_if_fail(family == AF_INET || family == AF_INET6, FALSE); - g_return_val_if_fail(!error || !*error, FALSE); + nm_assert(name); + nm_assert(value); + nm_assert(family == AF_INET || family == AF_INET6); + nm_assert(!error || !*error); spec = _nm_variant_attribute_spec_find_binary_search(ip_route_attribute_spec, G_N_ELEMENTS(ip_route_attribute_spec) - 1, @@ -1351,80 +1333,132 @@ nm_ip_route_attribute_validate(const char *name, return FALSE; } - if (g_variant_type_equal(spec->type, G_VARIANT_TYPE_STRING)) { - const char *string = g_variant_get_string(value, NULL); - - switch (spec->str_type) { - case 'a': /* IP address */ - if (!nm_utils_ipaddr_is_valid(family, string)) { - g_set_error(error, - NM_CONNECTION_ERROR, - NM_CONNECTION_ERROR_FAILED, - family == AF_INET ? _("'%s' is not a valid IPv4 address") - : _("'%s' is not a valid IPv6 address"), - string); - return FALSE; - } - break; - case 'p': /* IP address + optional prefix */ - { - gs_free char *addr_free = NULL; - const char * addr = string; - const char * str; - - str = strchr(addr, '/'); - if (str) { - addr = nm_strndup_a(200, addr, str - addr, &addr_free); - str++; - if (_nm_utils_ascii_str_to_int64(str, 10, 0, family == AF_INET ? 32 : 128, -1) - < 0) { - g_set_error(error, - NM_CONNECTION_ERROR, - NM_CONNECTION_ERROR_FAILED, - _("invalid prefix %s"), - str); - return FALSE; - } - } - if (!nm_utils_ipaddr_is_valid(family, addr)) { + switch (spec->type_detail) { + case 'a': /* IP address */ + string = g_variant_get_string(value, NULL); + if (!nm_utils_ipaddr_is_valid(family, string)) { + g_set_error(error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_FAILED, + family == AF_INET ? _("'%s' is not a valid IPv4 address") + : _("'%s' is not a valid IPv6 address"), + string); + return FALSE; + } + break; + case 'p': /* IP address + optional prefix */ + { + gs_free char *addr_free = NULL; + const char *addr; + const char *str; + + string = g_variant_get_string(value, NULL); + addr = string; + + str = strchr(addr, '/'); + if (str) { + addr = nm_strndup_a(200, addr, str - addr, &addr_free); + str++; + if (_nm_utils_ascii_str_to_int64(str, 10, 0, family == AF_INET ? 32 : 128, -1) < 0) { g_set_error(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED, - family == AF_INET ? _("'%s' is not a valid IPv4 address") - : _("'%s' is not a valid IPv6 address"), - string); + _("invalid prefix %s"), + str); return FALSE; } - break; } - case 'T': /* route type. */ - if (!NM_IN_SET(nm_net_aux_rtnl_rtntype_a2n(string), RTN_UNICAST, RTN_LOCAL)) { - g_set_error(error, - NM_CONNECTION_ERROR, - NM_CONNECTION_ERROR_INVALID_PROPERTY, - _("%s is not a valid route type"), - string); - return FALSE; - } - break; - default: - break; + if (!nm_utils_ipaddr_is_valid(family, addr)) { + g_set_error(error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_FAILED, + family == AF_INET ? _("'%s' is not a valid IPv4 address") + : _("'%s' is not a valid IPv6 address"), + string); + return FALSE; } + break; + } + case 'T': /* route type. */ + { + int type; + + string = g_variant_get_string(value, NULL); + type = nm_net_aux_rtnl_rtntype_a2n(string); + if (!NM_IN_SET(type, + RTN_UNICAST, + RTN_LOCAL, + RTN_BLACKHOLE, + RTN_UNREACHABLE, + RTN_PROHIBIT)) { + g_set_error(error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("%s is not a valid route type"), + string); + return FALSE; + } + + if (parse_data) + parse_data->type = type; + break; + } + case 's': /* scope */ + if (parse_data) + parse_data->scope = g_variant_get_byte(value); + break; + case '\0': + break; + default: + nm_assert_not_reached(); + break; } return TRUE; } +/** + * nm_ip_route_attribute_validate: + * @name: the attribute name + * @value: the attribute value + * @family: IP address family of the route + * @known: (out): on return, whether the attribute name is a known one + * @error: (allow-none): return location for a #GError, or %NULL + * + * Validates a route attribute, i.e. checks that the attribute is a known one + * and the value is of the correct type and well-formed. + * + * Returns: %TRUE if the attribute is valid, %FALSE otherwise + * + * Since: 1.8 + */ +gboolean +nm_ip_route_attribute_validate(const char *name, + GVariant *value, + int family, + gboolean *known, + GError **error) +{ + g_return_val_if_fail(name, FALSE); + g_return_val_if_fail(value, FALSE); + g_return_val_if_fail(family == AF_INET || family == AF_INET6, FALSE); + g_return_val_if_fail(!error || !*error, FALSE); + + return _ip_route_attribute_validate(name, value, family, NULL, known, error); +} + gboolean _nm_ip_route_attribute_validate_all(const NMIPRoute *route, GError **error) { - NMUtilsNamedValue attrs_static[G_N_ELEMENTS(ip_route_attribute_spec)]; + NMUtilsNamedValue attrs_static[G_N_ELEMENTS(ip_route_attribute_spec)]; gs_free NMUtilsNamedValue *attrs_free = NULL; - const NMUtilsNamedValue * attrs; + const NMUtilsNamedValue *attrs; guint attrs_len; - GVariant * val; guint i; - guint8 u8; + IPRouteAttrParseData parse_data = { + .type = RTN_UNICAST, + .scope = -1, + }; g_return_val_if_fail(route, FALSE); g_return_val_if_fail(!error || !*error, FALSE); @@ -1437,34 +1471,38 @@ _nm_ip_route_attribute_validate_all(const NMIPRoute *route, GError **error) attrs_static, &attrs_free); for (i = 0; i < attrs_len; i++) { - const char *key = attrs[i].name; - GVariant * val2 = attrs[i].value_ptr; - - if (!nm_ip_route_attribute_validate(key, val2, route->family, NULL, error)) + if (!_ip_route_attribute_validate(attrs[i].name, + attrs[i].value_ptr, + route->family, + &parse_data, + NULL, + error)) return FALSE; } - if ((val = g_hash_table_lookup(route->attributes, NM_IP_ROUTE_ATTRIBUTE_TYPE))) { - int v_i; - - nm_assert(g_variant_is_of_type(val, G_VARIANT_TYPE_STRING)); - - v_i = nm_net_aux_rtnl_rtntype_a2n(g_variant_get_string(val, NULL)); - nm_assert(v_i >= 0); - - if (v_i == RTN_LOCAL && route->family == AF_INET - && (val = g_hash_table_lookup(route->attributes, NM_IP_ROUTE_ATTRIBUTE_SCOPE))) { - nm_assert(g_variant_is_of_type(val, G_VARIANT_TYPE_BYTE)); - u8 = g_variant_get_byte(val); - - if (!NM_IN_SET(u8, RT_SCOPE_HOST, RT_SCOPE_NOWHERE)) { - g_set_error(error, - NM_CONNECTION_ERROR, - NM_CONNECTION_ERROR_INVALID_PROPERTY, - _("route scope is invalid")); - return FALSE; - } + switch (parse_data.type) { + case RTN_LOCAL: + if (route->family == AF_INET && parse_data.scope >= 0 + && !NM_IN_SET(parse_data.scope, RT_SCOPE_HOST, RT_SCOPE_NOWHERE)) { + g_set_error(error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("route scope is invalid for local route")); + return FALSE; } + break; + case RTN_BLACKHOLE: + case RTN_UNREACHABLE: + case RTN_PROHIBIT: + if (route->next_hop) { + g_set_error(error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("a %s route cannot have a next-hop"), + nm_net_aux_rtnl_rtntype_n2a(parse_data.type)); + return FALSE; + } + break; } return TRUE; @@ -1475,10 +1513,10 @@ _nm_ip_route_attribute_validate_all(const NMIPRoute *route, GError **error) struct NMIPRoutingRule { NMIPAddr from_bin; NMIPAddr to_bin; - char * from_str; - char * to_str; - char * iifname; - char * oifname; + char *from_str; + char *to_str; + char *iifname; + char *oifname; guint ref_count; guint32 priority; guint32 table; @@ -1692,7 +1730,7 @@ nm_ip_routing_rule_unref(NMIPRoutingRule *self) g_free(self->iifname); g_free(self->oifname); - g_slice_free(NMIPRoutingRule, self); + nm_g_slice_free(self); } /** @@ -2254,7 +2292,7 @@ nm_ip_routing_rule_get_xifname_bin(const NMIPRoutingRule *self, char out_xifname[static 16 /* IFNAMSIZ */]) { gs_free gpointer bin_to_free = NULL; - const char * xifname; + const char *xifname; gconstpointer bin; gsize len; @@ -2448,8 +2486,8 @@ nm_ip_routing_rule_set_suppress_prefixlength(NMIPRoutingRule *self, gint32 suppr */ gboolean nm_ip_routing_rule_get_uid_range(const NMIPRoutingRule *self, - guint32 * out_range_start, - guint32 * out_range_end) + guint32 *out_range_start, + guint32 *out_range_end) { g_return_val_if_fail(NM_IS_IP_ROUTING_RULE(self, TRUE), -1); @@ -2590,7 +2628,7 @@ _rr_xport_range_parse(char *str, gint64 *out_start, guint16 *out_end) { guint16 start, end; gint64 i64; - char * s; + char *s; s = strchr(str, '-'); if (s) @@ -2823,7 +2861,7 @@ typedef enum { } RRDbusAttr; typedef struct { - const char * name; + const char *name; const GVariantType *dbus_type; } RRDbusData; @@ -2905,16 +2943,16 @@ _rr_variants_free(GVariant *(*p_variants)[]) NMIPRoutingRule * nm_ip_routing_rule_from_dbus(GVariant *variant, gboolean strict, GError **error) { - nm_auto(_rr_variants_free) GVariant *variants[_RR_DBUS_ATTR_NUM] = {}; - nm_auto_unref_ip_routing_rule NMIPRoutingRule *self = NULL; + nm_auto(_rr_variants_free) GVariant *variants[_RR_DBUS_ATTR_NUM] = {}; + nm_auto_unref_ip_routing_rule NMIPRoutingRule *self = NULL; RRDbusAttr attr; GVariantIter iter; - const char * iter_key; - GVariant * iter_val; + const char *iter_key; + GVariant *iter_val; int addr_family; int i; - GVariant * v_start; - GVariant * v_end; + GVariant *v_start; + GVariant *v_end; g_variant_iter_init(&iter, variant); @@ -3216,8 +3254,8 @@ nm_ip_routing_rule_to_dbus(const NMIPRoutingRule *self) static gboolean _rr_string_validate(gboolean for_from /* or else to-string */, NMIPRoutingRuleAsStringFlags to_string_flags, - GHashTable * extra_args, - GError ** error) + GHashTable *extra_args, + GError **error) { if (NM_FLAGS_ANY(to_string_flags, ~(NM_IP_ROUTING_RULE_AS_STRING_FLAGS_AF_INET @@ -3266,21 +3304,21 @@ _rr_string_addr_family_from_flags(NMIPRoutingRuleAsStringFlags to_string_flags) * Since: 1.18 */ NMIPRoutingRule * -nm_ip_routing_rule_from_string(const char * str, +nm_ip_routing_rule_from_string(const char *str, NMIPRoutingRuleAsStringFlags to_string_flags, - GHashTable * extra_args, - GError ** error) + GHashTable *extra_args, + GError **error) { nm_auto_unref_ip_routing_rule NMIPRoutingRule *self = NULL; - gs_free const char ** tokens = NULL; + gs_free const char **tokens = NULL; gsize i_token; gboolean any_words = FALSE; - char * word0 = NULL; - char * word1 = NULL; - char * word_from = NULL; - char * word_to = NULL; - char * word_iifname = NULL; - char * word_oifname = NULL; + char *word0 = NULL; + char *word1 = NULL; + char *word_from = NULL; + char *word_to = NULL; + char *word_iifname = NULL; + char *word_oifname = NULL; gint64 i64_priority = -1; gint64 i64_table = -1; gint64 i64_tos = -1; @@ -3302,7 +3340,7 @@ nm_ip_routing_rule_from_string(const char * str, NMIPAddr val_to = {}; int val_from_len = -1; int val_to_len = -1; - char * s; + char *s; g_return_val_if_fail(str, NULL); @@ -3688,7 +3726,7 @@ next_words_consumed: } static void -_rr_string_append_inet_addr(NMStrBuf * str, +_rr_string_append_inet_addr(NMStrBuf *str, gboolean is_from /* or else is-to */, gboolean required, int addr_family, @@ -3730,10 +3768,10 @@ _rr_string_append_inet_addr(NMStrBuf * str, * Since: 1.18 */ char * -nm_ip_routing_rule_to_string(const NMIPRoutingRule * self, +nm_ip_routing_rule_to_string(const NMIPRoutingRule *self, NMIPRoutingRuleAsStringFlags to_string_flags, - GHashTable * extra_args, - GError ** error) + GHashTable *extra_args, + GError **error) { int addr_family; NMStrBuf str; @@ -4000,25 +4038,31 @@ gboolean nm_setting_ip_config_add_dns(NMSettingIPConfig *setting, const char *dns) { NMSettingIPConfigPrivate *priv; - char * dns_canonical; + int addr_family; + NMIPAddr dns_bin; + char dns_canonical[NM_UTILS_INET_ADDRSTRLEN]; guint i; g_return_val_if_fail(NM_IS_SETTING_IP_CONFIG(setting), FALSE); - g_return_val_if_fail(dns != NULL, FALSE); - g_return_val_if_fail(nm_utils_ipaddr_is_valid(NM_SETTING_IP_CONFIG_GET_FAMILY(setting), dns), - FALSE); + + addr_family = NM_SETTING_IP_CONFIG_GET_FAMILY(setting); + + if (!valid_ip(addr_family, dns, &dns_bin, NULL)) { + g_return_val_if_fail(dns != NULL, FALSE); + g_return_val_if_fail(nm_utils_ipaddr_is_valid(addr_family, dns), FALSE); + nm_assert_not_reached(); + } priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(setting); - dns_canonical = canonicalize_ip(NM_SETTING_IP_CONFIG_GET_FAMILY(setting), dns, FALSE); + nm_utils_inet_ntop(addr_family, &dns_bin, dns_canonical); + for (i = 0; i < priv->dns->len; i++) { - if (!strcmp(dns_canonical, priv->dns->pdata[i])) { - g_free(dns_canonical); + if (nm_streq(dns_canonical, priv->dns->pdata[i])) return FALSE; - } } - g_ptr_array_add(priv->dns, dns_canonical); + g_ptr_array_add(priv->dns, g_strdup(dns_canonical)); _notify(setting, PROP_DNS); return TRUE; } @@ -4057,26 +4101,32 @@ gboolean nm_setting_ip_config_remove_dns_by_value(NMSettingIPConfig *setting, const char *dns) { NMSettingIPConfigPrivate *priv; - char * dns_canonical; + int addr_family; + NMIPAddr dns_bin; + char dns_canonical[NM_UTILS_INET_ADDRSTRLEN]; guint i; g_return_val_if_fail(NM_IS_SETTING_IP_CONFIG(setting), FALSE); - g_return_val_if_fail(dns != NULL, FALSE); - g_return_val_if_fail(nm_utils_ipaddr_is_valid(NM_SETTING_IP_CONFIG_GET_FAMILY(setting), dns), - FALSE); + + addr_family = NM_SETTING_IP_CONFIG_GET_FAMILY(setting); + + if (!valid_ip(addr_family, dns, &dns_bin, NULL)) { + g_return_val_if_fail(dns != NULL, FALSE); + g_return_val_if_fail(nm_utils_ipaddr_is_valid(addr_family, dns), FALSE); + nm_assert_not_reached(); + } priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(setting); - dns_canonical = canonicalize_ip(NM_SETTING_IP_CONFIG_GET_FAMILY(setting), dns, FALSE); + nm_utils_inet_ntop(addr_family, &dns_bin, dns_canonical); + for (i = 0; i < priv->dns->len; i++) { - if (!strcmp(dns_canonical, priv->dns->pdata[i])) { + if (nm_streq(dns_canonical, priv->dns->pdata[i])) { g_ptr_array_remove_index(priv->dns, i); _notify(setting, PROP_DNS); - g_free(dns_canonical); return TRUE; } } - g_free(dns_canonical); return FALSE; } @@ -4951,7 +5001,7 @@ nm_setting_ip_config_clear_routing_rules(NMSettingIPConfig *setting) static GVariant * _routing_rules_dbus_only_synth(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) { - NMSettingIPConfig * self = NM_SETTING_IP_CONFIG(setting); + NMSettingIPConfig *self = NM_SETTING_IP_CONFIG(setting); NMSettingIPConfigPrivate *priv; GVariantBuilder builder; gboolean any = FALSE; @@ -4983,7 +5033,7 @@ static gboolean _routing_rules_dbus_only_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) { GVariantIter iter_rules; - GVariant * rule_var; + GVariant *rule_var; guint i_rule; gboolean success = FALSE; gboolean rules_changed = FALSE; @@ -4994,9 +5044,9 @@ _routing_rules_dbus_only_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) i_rule = 0; while (g_variant_iter_next(&iter_rules, "@a{sv}", &rule_var)) { - _nm_unused gs_unref_variant GVariant *rule_var_unref = rule_var; - nm_auto_unref_ip_routing_rule NMIPRoutingRule *rule = NULL; - gs_free_error GError *local = NULL; + _nm_unused gs_unref_variant GVariant *rule_var_unref = rule_var; + nm_auto_unref_ip_routing_rule NMIPRoutingRule *rule = NULL; + gs_free_error GError *local = NULL; i_rule++; @@ -5322,7 +5372,7 @@ static gboolean verify_label(const char *label) { const char *p; - char * iface; + char *iface; p = strchr(label, ':'); if (!p) @@ -5390,7 +5440,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) /* Validate addresses */ for (i = 0; i < priv->addresses->len; i++) { NMIPAddress *addr = (NMIPAddress *) priv->addresses->pdata[i]; - GVariant * label; + GVariant *label; if (nm_ip_address_get_family(addr) != NM_SETTING_IP_CONFIG_GET_FAMILY(setting)) { g_set_error(error, @@ -5465,7 +5515,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) /* Validate routes */ for (i = 0; i < priv->routes->len; i++) { gs_free_error GError *local = NULL; - NMIPRoute * route = (NMIPRoute *) priv->routes->pdata[i]; + NMIPRoute *route = (NMIPRoute *) priv->routes->pdata[i]; if (nm_ip_route_get_family(route) != NM_SETTING_IP_CONFIG_GET_FAMILY(setting)) { g_set_error(error, @@ -5496,7 +5546,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) if (priv->routing_rules) { for (i = 0; i < priv->routing_rules->len; i++) { - NMIPRoutingRule *rule = priv->routing_rules->pdata[i]; + NMIPRoutingRule *rule = priv->routing_rules->pdata[i]; gs_free_error GError *local = NULL; if (_ip_routing_rule_get_addr_family(rule) @@ -5555,9 +5605,10 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) return FALSE; } - if (!_nm_utils_validate_dhcp_hostname_flags(priv->dhcp_hostname_flags, - NM_SETTING_IP_CONFIG_GET_FAMILY(setting), - error)) { + if (priv->dhcp_hostname_flags != (NMDhcpHostnameFlags) priv->dhcp_hostname_flags + || !_nm_utils_validate_dhcp_hostname_flags(priv->dhcp_hostname_flags, + NM_SETTING_IP_CONFIG_GET_FAMILY(setting), + error)) { g_prefix_error(error, "%s.%s: ", nm_setting_get_name(setting), @@ -5720,14 +5771,14 @@ duplicate_copy_properties(const NMSettInfoSetting *sett_info, NMSetting *src, NM static void enumerate_values(const NMSettInfoProperty *property_info, - NMSetting * setting, + NMSetting *setting, NMSettingValueIterFn func, gpointer user_data) { if (nm_streq(property_info->name, NM_SETTING_IP_CONFIG_ROUTING_RULES)) { - NMSettingIPConfigPrivate * priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(setting); + NMSettingIPConfigPrivate *priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(setting); nm_auto_unset_gvalue GValue value = G_VALUE_INIT; - GPtrArray * ptr = NULL; + GPtrArray *ptr = NULL; guint i; if (priv->routing_rules && priv->routing_rules->len > 0) { @@ -5788,7 +5839,8 @@ _nm_sett_info_property_override_create_array_ip_config(int addr_family) .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct, .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_direct_ip_config_gateway), .direct_offset = NM_STRUCT_OFFSET_ENSURE_TYPE(char *, NMSettingIPConfigPrivate, gateway), - .direct_set_string_ip_address_addr_family = addr_family); + .direct_set_string_ip_address_addr_family = addr_family + 1, + .direct_set_string_ip_address_addr_family_map_zero_to_null = TRUE); _nm_properties_override_gobj( properties_override, @@ -5824,6 +5876,20 @@ _nm_sett_info_property_override_create_array_ip_config(int addr_family) .direct_offset = NM_STRUCT_OFFSET_ENSURE_TYPE(bool, NMSettingIPConfigPrivate, ignore_auto_routes)); + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_ROUTE_TABLE], + &nm_sett_info_propert_type_direct_uint32, + .direct_offset = + NM_STRUCT_OFFSET_ENSURE_TYPE(guint32, NMSettingIPConfigPrivate, route_table)); + + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_ROUTE_METRIC], + &nm_sett_info_propert_type_direct_int64, + .direct_offset = + NM_STRUCT_OFFSET_ENSURE_TYPE(gint64, NMSettingIPConfigPrivate, route_metric)); + _nm_properties_override_gobj( properties_override, obj_properties[PROP_IGNORE_AUTO_DNS], @@ -5831,6 +5897,34 @@ _nm_sett_info_property_override_create_array_ip_config(int addr_family) .direct_offset = NM_STRUCT_OFFSET_ENSURE_TYPE(bool, NMSettingIPConfigPrivate, ignore_auto_dns)); + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_DNS_PRIORITY], + &nm_sett_info_propert_type_direct_int32, + .direct_offset = + NM_STRUCT_OFFSET_ENSURE_TYPE(gint32, NMSettingIPConfigPrivate, dns_priority)); + + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_DHCP_TIMEOUT], + &nm_sett_info_propert_type_direct_int32, + .direct_offset = + NM_STRUCT_OFFSET_ENSURE_TYPE(gint32, NMSettingIPConfigPrivate, dhcp_timeout)); + + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_REQUIRED_TIMEOUT], + &nm_sett_info_propert_type_direct_int32, + .direct_offset = + NM_STRUCT_OFFSET_ENSURE_TYPE(gint32, NMSettingIPConfigPrivate, required_timeout)); + + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_DAD_TIMEOUT], + &nm_sett_info_propert_type_direct_int32, + .direct_offset = + NM_STRUCT_OFFSET_ENSURE_TYPE(gint32, NMSettingIPConfigPrivate, dad_timeout)); + _nm_properties_override_gobj( properties_override, obj_properties[PROP_DHCP_SEND_HOSTNAME], @@ -5838,6 +5932,13 @@ _nm_sett_info_property_override_create_array_ip_config(int addr_family) .direct_offset = NM_STRUCT_OFFSET_ENSURE_TYPE(bool, NMSettingIPConfigPrivate, dhcp_send_hostname)); + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_DHCP_HOSTNAME_FLAGS], + &nm_sett_info_propert_type_direct_uint32, + .direct_offset = + NM_STRUCT_OFFSET_ENSURE_TYPE(guint32, NMSettingIPConfigPrivate, dhcp_hostname_flags)); + _nm_properties_override_gobj( properties_override, obj_properties[PROP_NEVER_DEFAULT], @@ -5859,13 +5960,10 @@ _nm_sett_info_property_override_create_array_ip_config(int addr_family) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMSettingIPConfig * setting = NM_SETTING_IP_CONFIG(object); + NMSettingIPConfig *setting = NM_SETTING_IP_CONFIG(object); NMSettingIPConfigPrivate *priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(setting); switch (prop_id) { - case PROP_METHOD: - g_value_set_string(value, nm_setting_ip_config_get_method(setting)); - break; case PROP_DNS: g_value_take_boxed(value, _nm_utils_ptrarray_to_strv(priv->dns)); break; @@ -5877,68 +5975,23 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) priv->dns_options ? _nm_utils_ptrarray_to_strv(priv->dns_options) : NULL); break; - case PROP_DNS_PRIORITY: - g_value_set_int(value, priv->dns_priority); - break; case PROP_ADDRESSES: g_value_take_boxed(value, _nm_utils_copy_array(priv->addresses, (NMUtilsCopyFunc) nm_ip_address_dup, (GDestroyNotify) nm_ip_address_unref)); break; - case PROP_GATEWAY: - g_value_set_string(value, nm_setting_ip_config_get_gateway(setting)); - break; case PROP_ROUTES: g_value_take_boxed(value, _nm_utils_copy_array(priv->routes, (NMUtilsCopyFunc) nm_ip_route_dup, (GDestroyNotify) nm_ip_route_unref)); break; - case PROP_ROUTE_METRIC: - g_value_set_int64(value, priv->route_metric); - break; - case PROP_ROUTE_TABLE: - g_value_set_uint(value, priv->route_table); - break; - case PROP_IGNORE_AUTO_ROUTES: - g_value_set_boolean(value, nm_setting_ip_config_get_ignore_auto_routes(setting)); - break; - case PROP_IGNORE_AUTO_DNS: - g_value_set_boolean(value, nm_setting_ip_config_get_ignore_auto_dns(setting)); - break; - case PROP_DHCP_HOSTNAME: - g_value_set_string(value, nm_setting_ip_config_get_dhcp_hostname(setting)); - break; - case PROP_DHCP_SEND_HOSTNAME: - g_value_set_boolean(value, nm_setting_ip_config_get_dhcp_send_hostname(setting)); - break; - case PROP_NEVER_DEFAULT: - g_value_set_boolean(value, priv->never_default); - break; - case PROP_MAY_FAIL: - g_value_set_boolean(value, priv->may_fail); - break; - case PROP_DAD_TIMEOUT: - g_value_set_int(value, nm_setting_ip_config_get_dad_timeout(setting)); - break; - case PROP_DHCP_TIMEOUT: - g_value_set_int(value, nm_setting_ip_config_get_dhcp_timeout(setting)); - break; - case PROP_REQUIRED_TIMEOUT: - g_value_set_int(value, nm_setting_ip_config_get_required_timeout(setting)); - break; - case PROP_DHCP_IAID: - g_value_set_string(value, nm_setting_ip_config_get_dhcp_iaid(setting)); - break; - case PROP_DHCP_HOSTNAME_FLAGS: - g_value_set_uint(value, nm_setting_ip_config_get_dhcp_hostname_flags(setting)); - break; case PROP_DHCP_REJECT_SERVERS: g_value_set_boxed(value, nm_strvarray_get_strv_non_empty(priv->dhcp_reject_servers, NULL)); break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + _nm_setting_property_get_property_direct(object, prop_id, value, pspec); break; } } @@ -5946,16 +5999,12 @@ 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) { - NMSettingIPConfig * setting = NM_SETTING_IP_CONFIG(object); + NMSettingIPConfig *setting = NM_SETTING_IP_CONFIG(object); NMSettingIPConfigPrivate *priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(setting); - char ** strv; + char **strv; guint i; switch (prop_id) { - case PROP_METHOD: - g_free(priv->method); - priv->method = g_value_dup_string(value); - break; case PROP_DNS: g_ptr_array_unref(priv->dns); priv->dns = nm_strv_to_ptrarray(g_value_get_boxed(value)); @@ -5983,73 +6032,23 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps } } break; - case PROP_DNS_PRIORITY: - priv->dns_priority = g_value_get_int(value); - break; case PROP_ADDRESSES: g_ptr_array_unref(priv->addresses); priv->addresses = _nm_utils_copy_array(g_value_get_boxed(value), (NMUtilsCopyFunc) nm_ip_address_dup, (GDestroyNotify) nm_ip_address_unref); break; - case PROP_GATEWAY: - g_free(priv->gateway); - priv->gateway = - _nm_utils_ipaddr_canonical_or_invalid(NM_SETTING_IP_CONFIG_GET_FAMILY(setting), - g_value_get_string(value)); - break; case PROP_ROUTES: g_ptr_array_unref(priv->routes); priv->routes = _nm_utils_copy_array(g_value_get_boxed(value), (NMUtilsCopyFunc) nm_ip_route_dup, (GDestroyNotify) nm_ip_route_unref); break; - case PROP_ROUTE_METRIC: - priv->route_metric = g_value_get_int64(value); - break; - case PROP_ROUTE_TABLE: - priv->route_table = g_value_get_uint(value); - break; - case PROP_IGNORE_AUTO_ROUTES: - priv->ignore_auto_routes = g_value_get_boolean(value); - break; - case PROP_IGNORE_AUTO_DNS: - priv->ignore_auto_dns = g_value_get_boolean(value); - break; - case PROP_DHCP_HOSTNAME: - g_free(priv->dhcp_hostname); - priv->dhcp_hostname = g_value_dup_string(value); - break; - case PROP_DHCP_SEND_HOSTNAME: - priv->dhcp_send_hostname = g_value_get_boolean(value); - break; - case PROP_NEVER_DEFAULT: - priv->never_default = g_value_get_boolean(value); - break; - case PROP_MAY_FAIL: - priv->may_fail = g_value_get_boolean(value); - break; - case PROP_DAD_TIMEOUT: - priv->dad_timeout = g_value_get_int(value); - break; - case PROP_DHCP_TIMEOUT: - priv->dhcp_timeout = g_value_get_int(value); - break; - case PROP_REQUIRED_TIMEOUT: - priv->required_timeout = g_value_get_int(value); - break; - case PROP_DHCP_IAID: - g_free(priv->dhcp_iaid); - priv->dhcp_iaid = g_value_dup_string(value); - break; - case PROP_DHCP_HOSTNAME_FLAGS: - priv->dhcp_hostname_flags = g_value_get_uint(value); - break; case PROP_DHCP_REJECT_SERVERS: nm_strvarray_set_strv(&priv->dhcp_reject_servers, g_value_get_boxed(value)); break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + _nm_setting_property_set_property_direct(object, prop_id, value, pspec); break; } } @@ -6061,13 +6060,10 @@ _nm_setting_ip_config_private_init(gpointer self, NMSettingIPConfigPrivate *priv { nm_assert(NM_IS_SETTING_IP_CONFIG(self)); - priv->dns = g_ptr_array_new_with_free_func(g_free); - priv->dns_search = g_ptr_array_new_with_free_func(g_free); - priv->addresses = g_ptr_array_new_with_free_func((GDestroyNotify) nm_ip_address_unref); - priv->routes = g_ptr_array_new_with_free_func((GDestroyNotify) nm_ip_route_unref); - priv->route_metric = -1; - priv->dad_timeout = -1; - priv->required_timeout = -1; + priv->dns = g_ptr_array_new_with_free_func(g_free); + priv->dns_search = g_ptr_array_new_with_free_func(g_free); + priv->addresses = g_ptr_array_new_with_free_func((GDestroyNotify) nm_ip_address_unref); + priv->routes = g_ptr_array_new_with_free_func((GDestroyNotify) nm_ip_route_unref); } static void @@ -6079,18 +6075,16 @@ nm_setting_ip_config_init(NMSettingIPConfig *setting) static void finalize(GObject *object) { - NMSettingIPConfig * self = NM_SETTING_IP_CONFIG(object); + NMSettingIPConfig *self = NM_SETTING_IP_CONFIG(object); NMSettingIPConfigPrivate *priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(self); g_ptr_array_unref(priv->dns); g_ptr_array_unref(priv->dns_search); - if (priv->dns_options) - g_ptr_array_unref(priv->dns_options); + nm_g_ptr_array_unref(priv->dns_options); g_ptr_array_unref(priv->addresses); g_ptr_array_unref(priv->routes); - if (priv->routing_rules) - g_ptr_array_unref(priv->routing_rules); - nm_clear_pointer(&priv->dhcp_reject_servers, g_array_unref); + nm_g_ptr_array_unref(priv->routing_rules); + nm_g_array_unref(priv->dhcp_reject_servers); G_OBJECT_CLASS(nm_setting_ip_config_parent_class)->finalize(object); } @@ -6098,7 +6092,7 @@ finalize(GObject *object) static void nm_setting_ip_config_class_init(NMSettingIPConfigClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); object_class->get_property = get_property; diff --git a/src/libnm-core-impl/nm-setting-ip-tunnel.c b/src/libnm-core-impl/nm-setting-ip-tunnel.c index 38f9047d..d42e97b9 100644 --- a/src/libnm-core-impl/nm-setting-ip-tunnel.c +++ b/src/libnm-core-impl/nm-setting-ip-tunnel.c @@ -32,19 +32,19 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_PARENT, PROP_FLAGS, ); typedef struct { - char * parent; - char * local; - char * remote; - char * input_key; - char * output_key; - guint ttl; - guint tos; - guint encapsulation_limit; - guint flow_label; - NMIPTunnelMode mode; - guint32 mtu; - guint32 flags; - bool path_mtu_discovery; + char *parent; + char *local; + char *remote; + char *input_key; + char *output_key; + guint32 ttl; + guint32 tos; + guint32 encapsulation_limit; + guint32 flow_label; + guint32 mode; + guint32 mtu; + guint32 flags; + bool path_mtu_discovery; } NMSettingIPTunnelPrivate; /** @@ -502,117 +502,6 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) /*****************************************************************************/ -static void -get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - NMSettingIPTunnel * setting = NM_SETTING_IP_TUNNEL(object); - NMSettingIPTunnelPrivate *priv = NM_SETTING_IP_TUNNEL_GET_PRIVATE(setting); - - switch (prop_id) { - case PROP_PARENT: - g_value_set_string(value, priv->parent); - break; - case PROP_MODE: - g_value_set_uint(value, priv->mode); - break; - case PROP_LOCAL: - g_value_set_string(value, priv->local); - break; - case PROP_REMOTE: - g_value_set_string(value, priv->remote); - break; - case PROP_TTL: - g_value_set_uint(value, priv->ttl); - break; - case PROP_TOS: - g_value_set_uint(value, priv->tos); - break; - case PROP_PATH_MTU_DISCOVERY: - g_value_set_boolean(value, priv->path_mtu_discovery); - break; - case PROP_INPUT_KEY: - g_value_set_string(value, priv->input_key); - break; - case PROP_OUTPUT_KEY: - g_value_set_string(value, priv->output_key); - break; - case PROP_ENCAPSULATION_LIMIT: - g_value_set_uint(value, priv->encapsulation_limit); - break; - case PROP_FLOW_LABEL: - g_value_set_uint(value, priv->flow_label); - break; - case PROP_MTU: - g_value_set_uint(value, priv->mtu); - break; - case PROP_FLAGS: - g_value_set_uint(value, priv->flags); - 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) -{ - NMSettingIPTunnel * setting = NM_SETTING_IP_TUNNEL(object); - NMSettingIPTunnelPrivate *priv = NM_SETTING_IP_TUNNEL_GET_PRIVATE(setting); - - switch (prop_id) { - case PROP_PARENT: - g_free(priv->parent); - priv->parent = g_value_dup_string(value); - break; - case PROP_MODE: - priv->mode = g_value_get_uint(value); - break; - case PROP_LOCAL: - g_free(priv->local); - priv->local = g_value_dup_string(value); - break; - case PROP_REMOTE: - g_free(priv->remote); - priv->remote = g_value_dup_string(value); - break; - case PROP_TTL: - priv->ttl = g_value_get_uint(value); - break; - case PROP_TOS: - priv->tos = g_value_get_uint(value); - break; - case PROP_PATH_MTU_DISCOVERY: - priv->path_mtu_discovery = g_value_get_boolean(value); - break; - case PROP_INPUT_KEY: - g_free(priv->input_key); - priv->input_key = g_value_dup_string(value); - break; - case PROP_OUTPUT_KEY: - g_free(priv->output_key); - priv->output_key = g_value_dup_string(value); - break; - case PROP_ENCAPSULATION_LIMIT: - priv->encapsulation_limit = g_value_get_uint(value); - break; - case PROP_FLOW_LABEL: - priv->flow_label = g_value_get_uint(value); - break; - case PROP_MTU: - priv->mtu = g_value_get_uint(value); - break; - case PROP_FLAGS: - priv->flags = g_value_get_uint(value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } -} - -/*****************************************************************************/ - static void nm_setting_ip_tunnel_init(NMSettingIPTunnel *self) {} @@ -635,14 +524,14 @@ nm_setting_ip_tunnel_new(void) static void nm_setting_ip_tunnel_class_init(NMSettingIPTunnelClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingIPTunnelPrivate)); - object_class->get_property = get_property; - object_class->set_property = set_property; + object_class->get_property = _nm_setting_property_get_property_direct; + object_class->set_property = _nm_setting_property_set_property_direct; setting_class->verify = verify; @@ -671,14 +560,16 @@ nm_setting_ip_tunnel_class_init(NMSettingIPTunnelClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_MODE] = - g_param_spec_uint(NM_SETTING_IP_TUNNEL_MODE, - "", - "", - 0, - G_MAXUINT, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_IP_TUNNEL_MODE, + PROP_MODE, + 0, + G_MAXUINT32, + NM_IP_TUNNEL_MODE_UNKNOWN, + NM_SETTING_PARAM_INFERRABLE, + NMSettingIPTunnelPrivate, + mode); /** * NMSettingIPTunnel:local: @@ -720,14 +611,16 @@ nm_setting_ip_tunnel_class_init(NMSettingIPTunnelClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_TTL] = - g_param_spec_uint(NM_SETTING_IP_TUNNEL_TTL, - "", - "", - 0, - 255, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_IP_TUNNEL_TTL, + PROP_TTL, + 0, + 255, + 0, + NM_SETTING_PARAM_INFERRABLE, + NMSettingIPTunnelPrivate, + ttl); /** * NMSettingIPTunnel:tos @@ -737,14 +630,16 @@ nm_setting_ip_tunnel_class_init(NMSettingIPTunnelClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_TOS] = - g_param_spec_uint(NM_SETTING_IP_TUNNEL_TOS, - "", - "", - 0, - 255, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_IP_TUNNEL_TOS, + PROP_TOS, + 0, + 255, + 0, + NM_SETTING_PARAM_INFERRABLE, + NMSettingIPTunnelPrivate, + tos); /** * NMSettingIPTunnel:path-mtu-discovery @@ -802,14 +697,16 @@ nm_setting_ip_tunnel_class_init(NMSettingIPTunnelClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_ENCAPSULATION_LIMIT] = - g_param_spec_uint(NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT, - "", - "", - 0, - 255, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT, + PROP_ENCAPSULATION_LIMIT, + 0, + 255, + 0, + NM_SETTING_PARAM_INFERRABLE, + NMSettingIPTunnelPrivate, + encapsulation_limit); /** * NMSettingIPTunnel:flow-label: @@ -819,14 +716,16 @@ nm_setting_ip_tunnel_class_init(NMSettingIPTunnelClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_FLOW_LABEL] = - g_param_spec_uint(NM_SETTING_IP_TUNNEL_FLOW_LABEL, - "", - "", - 0, - (1 << 20) - 1, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_IP_TUNNEL_FLOW_LABEL, + PROP_FLOW_LABEL, + 0, + (1 << 20) - 1, + 0, + NM_SETTING_PARAM_INFERRABLE, + NMSettingIPTunnelPrivate, + flow_label); /** * NMSettingIPTunnel:mtu: @@ -836,14 +735,16 @@ nm_setting_ip_tunnel_class_init(NMSettingIPTunnelClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_MTU] = g_param_spec_uint(NM_SETTING_IP_TUNNEL_MTU, - "", - "", - 0, - G_MAXUINT32, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE - | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_IP_TUNNEL_MTU, + PROP_MTU, + 0, + G_MAXUINT32, + 0, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingIPTunnelPrivate, + mtu); /** * NMSettingIPTunnel:flags: @@ -856,14 +757,16 @@ nm_setting_ip_tunnel_class_init(NMSettingIPTunnelClass *klass) * * Since: 1.12 **/ - obj_properties[PROP_FLAGS] = g_param_spec_uint(NM_SETTING_IP_TUNNEL_FLAGS, - "", - "", - 0, - G_MAXUINT32, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE - | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_IP_TUNNEL_FLAGS, + PROP_FLAGS, + 0, + G_MAXUINT32, + 0, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingIPTunnelPrivate, + flags); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-ip4-config.c b/src/libnm-core-impl/nm-setting-ip4-config.c index a7b3d68b..5b06739c 100644 --- a/src/libnm-core-impl/nm-setting-ip4-config.c +++ b/src/libnm-core-impl/nm-setting-ip4-config.c @@ -131,9 +131,9 @@ static gboolean verify(NMSetting *setting, NMConnection *connection, GError **error) { NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE(setting); - NMSettingIPConfig * s_ip = NM_SETTING_IP_CONFIG(setting); + NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG(setting); NMSettingVerifyResult ret; - const char * method; + const char *method; ret = NM_SETTING_CLASS(nm_setting_ip4_config_parent_class)->verify(setting, connection, error); if (ret != NM_SETTING_VERIFY_SUCCESS) @@ -344,7 +344,7 @@ static GVariant * ip4_addresses_get(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) { gs_unref_ptrarray GPtrArray *addrs = NULL; - const char * gateway; + const char *gateway; g_object_get(setting, NM_SETTING_IP_CONFIG_ADDRESSES, &addrs, NULL); gateway = nm_setting_ip_config_get_gateway(NM_SETTING_IP_CONFIG(setting)); @@ -355,8 +355,8 @@ static gboolean ip4_addresses_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) { GPtrArray *addrs; - GVariant * s_ip4; - char ** labels, *gateway = NULL; + GVariant *s_ip4; + char **labels, *gateway = NULL; int i; /* FIXME: properly handle errors */ @@ -397,8 +397,8 @@ ip4_address_labels_get(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) { NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG(setting); gboolean have_labels = FALSE; - GPtrArray * labels; - GVariant * ret; + GPtrArray *labels; + GVariant *ret; int num_addrs, i; if (!_nm_connection_serialize_non_secret(flags)) @@ -407,7 +407,7 @@ ip4_address_labels_get(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) num_addrs = nm_setting_ip_config_get_num_addresses(s_ip); for (i = 0; i < num_addrs; i++) { NMIPAddress *addr = nm_setting_ip_config_get_address(s_ip, i); - GVariant * label = nm_ip_address_get_attribute(addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL); + GVariant *label = nm_ip_address_get_attribute(addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL); if (label) { have_labels = TRUE; @@ -420,7 +420,7 @@ ip4_address_labels_get(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) labels = g_ptr_array_sized_new(num_addrs); for (i = 0; i < num_addrs; i++) { NMIPAddress *addr = nm_setting_ip_config_get_address(s_ip, i); - GVariant * label = nm_ip_address_get_attribute(addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL); + GVariant *label = nm_ip_address_get_attribute(addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL); g_ptr_array_add(labels, (char *) (label ? g_variant_get_string(label, NULL) : "")); } @@ -522,53 +522,6 @@ ip4_route_data_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) /*****************************************************************************/ -static void -get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - NMSettingIP4Config *s_ip4 = NM_SETTING_IP4_CONFIG(object); - - switch (prop_id) { - case PROP_DHCP_CLIENT_ID: - g_value_set_string(value, nm_setting_ip4_config_get_dhcp_client_id(s_ip4)); - break; - case PROP_DHCP_FQDN: - g_value_set_string(value, nm_setting_ip4_config_get_dhcp_fqdn(s_ip4)); - break; - case PROP_DHCP_VENDOR_CLASS_IDENTIFIER: - g_value_set_string(value, nm_setting_ip4_config_get_dhcp_vendor_class_identifier(s_ip4)); - 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) -{ - NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE(object); - - switch (prop_id) { - case PROP_DHCP_CLIENT_ID: - g_free(priv->dhcp_client_id); - priv->dhcp_client_id = g_value_dup_string(value); - break; - case PROP_DHCP_FQDN: - g_free(priv->dhcp_fqdn); - priv->dhcp_fqdn = g_value_dup_string(value); - break; - case PROP_DHCP_VENDOR_CLASS_IDENTIFIER: - g_free(priv->dhcp_vendor_class_identifier); - priv->dhcp_vendor_class_identifier = g_value_dup_string(value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } -} - -/*****************************************************************************/ - static void nm_setting_ip4_config_init(NMSettingIP4Config *setting) { @@ -593,15 +546,15 @@ nm_setting_ip4_config_new(void) static void nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); - NMSettingClass * setting_class = NM_SETTING_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); + NMSettingClass *setting_class = NM_SETTING_CLASS(klass); NMSettingIPConfigClass *setting_ip_config_class = NM_SETTING_IP_CONFIG_CLASS(klass); GArray *properties_override = _nm_sett_info_property_override_create_array_ip_config(AF_INET); g_type_class_add_private(klass, sizeof(NMSettingIP4ConfigPrivate)); - object_class->get_property = get_property; - object_class->set_property = set_property; + object_class->get_property = _nm_setting_property_get_property_direct; + object_class->set_property = _nm_setting_property_set_property_direct; setting_class->verify = verify; @@ -996,9 +949,73 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) * property: routes * format: a comma separated list of routes * description: A list of IPv4 destination addresses, prefix length, optional IPv4 - * next hop addresses, optional route metric, optional attribute. The valid syntax is: - * "ip[/prefix] [next-hop] [metric] [attribute=val]...[,ip[/prefix]...]". For example - * "192.0.2.0/24 10.1.1.1 77, 198.51.100.0/24". + * next hop addresses, optional route metric, optional attribute. The valid syntax is: + * "ip[/prefix] [next-hop] [metric] [attribute=val]...[,ip[/prefix]...]". For example + * "192.0.2.0/24 10.1.1.1 77, 198.51.100.0/24". + * description-docbook: + * + * A list of IPv4 destination addresses, prefix length, optional IPv4 + * next hop addresses, optional route metric, optional attribute. The valid syntax is: + * "ip[/prefix] [next-hop] [metric] [attribute=val]...[,ip[/prefix]...]". + * For example "192.0.2.0/24 10.1.1.1 77, 198.51.100.0/24". + * + * + * Various attributes are supported: + * + * + * "cwnd" - an unsigned 32 bit integer. + * + * + * "initcwnd" - an unsigned 32 bit integer. + * + * + * "initrwnd" - an unsigned 32 bit integer. + * + * + * "lock-cwnd" - a boolean value. + * + * + * "lock-initcwnd" - a boolean value. + * + * + * "lock-initrwnd" - a boolean value. + * + * + * "lock-mtu" - a boolean value. + * + * + * "lock-window" - a boolean value. + * + * + * "mtu" - an unsigned 32 bit integer. + * + * + * "onlink" - a boolean value. + * + * + * "scope" - an unsigned 8 bit integer. IPv4 only. + * + * + * "src" - an IPv4 address. + * + * + * "table" - an unsigned 32 bit integer. The default depends on ipv4.route-table. + * + * + * "tos" - an unsigned 8 bit integer. IPv4 only. + * + * + * "type" - one of unicast, local, blackhole, + * unavailable, prohibit. The default is unicast. + * + * + * "window" - an unsigned 32 bit integer. + * + * + * + * + * For details see also `man ip-route`. + * * ---end--- */ _nm_properties_override_gobj( @@ -1030,6 +1047,23 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) .compare_fcn = _nm_setting_property_compare_fcn_ignore, .from_dbus_fcn = ip4_route_data_set, )); + /* ---nmcli--- + * property: routing-rules + * format: a comma separated list of routing rules + * description: A comma separated list of routing rules for policy routing. + * description-docbook: + * + * A comma separated list of routing rules for policy routing. The format + * is based on ip rule add syntax and mostly compatible. + * One difference is that routing rules in NetworkManager always need a + * fixed priority. + * + * + * Example: priority 5 from 192.167.4.0/24 table 45 + * + * ---end--- + */ + g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); _nm_setting_class_commit(setting_class, diff --git a/src/libnm-core-impl/nm-setting-ip6-config.c b/src/libnm-core-impl/nm-setting-ip6-config.c index 87b9d958..f4623b28 100644 --- a/src/libnm-core-impl/nm-setting-ip6-config.c +++ b/src/libnm-core-impl/nm-setting-ip6-config.c @@ -48,11 +48,11 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_IP6_PRIVACY, typedef struct { NMSettingIPConfigPrivate parent; - char * token; - char * dhcp_duid; - NMSettingIP6ConfigPrivacy ip6_privacy; - NMSettingIP6ConfigAddrGenMode addr_gen_mode; - gint32 ra_timeout; + char *token; + char *dhcp_duid; + int ip6_privacy; + gint32 addr_gen_mode; + gint32 ra_timeout; } NMSettingIP6ConfigPrivate; /** @@ -175,9 +175,9 @@ static gboolean verify(NMSetting *setting, NMConnection *connection, GError **error) { NMSettingIP6ConfigPrivate *priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE(setting); - NMSettingIPConfig * s_ip = NM_SETTING_IP_CONFIG(setting); + NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG(setting); NMSettingVerifyResult ret; - const char * method; + const char *method; gboolean token_needs_normalization = FALSE; ret = NM_SETTING_CLASS(nm_setting_ip6_config_parent_class)->verify(setting, connection, error); @@ -385,7 +385,7 @@ static GVariant * ip6_addresses_get(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) { gs_unref_ptrarray GPtrArray *addrs = NULL; - const char * gateway; + const char *gateway; g_object_get(setting, NM_SETTING_IP_CONFIG_ADDRESSES, &addrs, NULL); gateway = nm_setting_ip_config_get_gateway(NM_SETTING_IP_CONFIG(setting)); @@ -396,7 +396,7 @@ static gboolean ip6_addresses_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) { GPtrArray *addrs; - char * gateway = NULL; + char *gateway = NULL; if (!_nm_setting_use_legacy_property(setting, connection_dict, "addresses", "address-data")) { *out_is_modified = FALSE; @@ -501,73 +501,12 @@ ip6_route_data_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) /*****************************************************************************/ -static void -get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - NMSettingIP6ConfigPrivate *priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE(object); - - switch (prop_id) { - case PROP_IP6_PRIVACY: - g_value_set_enum(value, priv->ip6_privacy); - break; - case PROP_ADDR_GEN_MODE: - g_value_set_int(value, priv->addr_gen_mode); - break; - case PROP_TOKEN: - g_value_set_string(value, priv->token); - break; - case PROP_DHCP_DUID: - g_value_set_string(value, priv->dhcp_duid); - break; - case PROP_RA_TIMEOUT: - g_value_set_int(value, priv->ra_timeout); - 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) -{ - NMSettingIP6ConfigPrivate *priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE(object); - - switch (prop_id) { - case PROP_IP6_PRIVACY: - priv->ip6_privacy = g_value_get_enum(value); - break; - case PROP_ADDR_GEN_MODE: - priv->addr_gen_mode = g_value_get_int(value); - break; - case PROP_TOKEN: - g_free(priv->token); - priv->token = g_value_dup_string(value); - break; - case PROP_DHCP_DUID: - g_free(priv->dhcp_duid); - priv->dhcp_duid = g_value_dup_string(value); - break; - case PROP_RA_TIMEOUT: - priv->ra_timeout = g_value_get_int(value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } -} - -/*****************************************************************************/ - static void nm_setting_ip6_config_init(NMSettingIP6Config *setting) { NMSettingIP6ConfigPrivate *priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE(setting); _nm_setting_ip_config_private_init(setting, &priv->parent); - - priv->ip6_privacy = NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN; - priv->addr_gen_mode = NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY; } /** @@ -586,15 +525,15 @@ nm_setting_ip6_config_new(void) static void nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); - NMSettingClass * setting_class = NM_SETTING_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); + NMSettingClass *setting_class = NM_SETTING_CLASS(klass); NMSettingIPConfigClass *setting_ip_config_class = NM_SETTING_IP_CONFIG_CLASS(klass); GArray *properties_override = _nm_sett_info_property_override_create_array_ip_config(AF_INET6); g_type_class_add_private(klass, sizeof(NMSettingIP6ConfigPrivate)); - object_class->get_property = get_property; - object_class->set_property = set_property; + object_class->get_property = _nm_setting_property_get_property_direct; + object_class->set_property = _nm_setting_property_set_property_direct; setting_class->verify = verify; @@ -803,13 +742,15 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) * example: IPV6_PRIVACY=rfc3041 IPV6_PRIVACY_PREFER_PUBLIC_IP=yes * ---end--- */ - obj_properties[PROP_IP6_PRIVACY] = - g_param_spec_enum(NM_SETTING_IP6_CONFIG_IP6_PRIVACY, - "", - "", - NM_TYPE_SETTING_IP6_CONFIG_PRIVACY, - NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_enum(properties_override, + obj_properties, + NM_SETTING_IP6_CONFIG_IP6_PRIVACY, + PROP_IP6_PRIVACY, + NM_TYPE_SETTING_IP6_CONFIG_PRIVACY, + NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN, + NM_SETTING_PARAM_NONE, + NMSettingIP6ConfigPrivate, + ip6_privacy); /** * NMSettingIP6Config:addr-gen-mode: @@ -852,14 +793,16 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) * example: IPV6_ADDR_GEN_MODE=stable-privacy * ---end--- */ - obj_properties[PROP_ADDR_GEN_MODE] = - g_param_spec_int(NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE, - "", - "", - G_MININT, - G_MAXINT, - NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_int32(properties_override, + obj_properties, + NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE, + PROP_ADDR_GEN_MODE, + G_MININT32, + G_MAXINT32, + NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY, + NM_SETTING_PARAM_NONE, + NMSettingIP6ConfigPrivate, + addr_gen_mode); /** * NMSettingIP6Config:token: @@ -902,15 +845,16 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) * example: IPV6_RA_TIMEOUT=10 * ---end--- */ - - obj_properties[PROP_RA_TIMEOUT] = g_param_spec_int( - NM_SETTING_IP6_CONFIG_RA_TIMEOUT, - "", - "", - 0, - G_MAXINT32, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_int32(properties_override, + obj_properties, + NM_SETTING_IP6_CONFIG_RA_TIMEOUT, + PROP_RA_TIMEOUT, + 0, + G_MAXINT32, + 0, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingIP6ConfigPrivate, + ra_timeout); /** * NMSettingIP6Config:dhcp-duid: @@ -1045,6 +989,71 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) * default metric for the device. * ---end--- */ + /* ---nmcli--- + * property: routes + * format: a comma separated list of routes + * description-docbook: + * + * A list of IPv6 destination addresses, prefix length, optional IPv6 + * next hop addresses, optional route metric, optional attribute. The valid syntax is: + * "ip[/prefix] [next-hop] [metric] [attribute=val]...[,ip[/prefix]...]". + * + * + * Various attributes are supported: + * + * + * "cwnd" - an unsigned 32 bit integer. + * + * + * "from" - an IPv6 address with optional prefix. IPv6 only. + * + * + * "initcwnd" - an unsigned 32 bit integer. + * + * + * "initrwnd" - an unsigned 32 bit integer. + * + * + * "lock-cwnd" - a boolean value. + * + * + * "lock-initcwnd" - a boolean value. + * + * + * "lock-initrwnd" - a boolean value. + * + * + * "lock-mtu" - a boolean value. + * + * + * "lock-window" - a boolean value. + * + * + * "mtu" - an unsigned 32 bit integer. + * + * + * "onlink" - a boolean value. + * + * + * "src" - an IPv6 address. + * + * + * "table" - an unsigned 32 bit integer. The default depends on ipv6.route-table. + * + * + * "type" - one of unicast, local, blackhole, + * unavailable, prohibit. The default is unicast. + * + * + * "window" - an unsigned 32 bit integer. + * + * + * + * + * For details see also `man ip-route`. + * + * ---end--- + */ _nm_properties_override_gobj( properties_override, g_object_class_find_property(G_OBJECT_CLASS(setting_class), NM_SETTING_IP_CONFIG_ROUTES), @@ -1074,6 +1083,23 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) .compare_fcn = _nm_setting_property_compare_fcn_ignore, .from_dbus_fcn = ip6_route_data_set, )); + /* ---nmcli--- + * property: routing-rules + * format: a comma separated list of routing rules + * description: A comma separated list of routing rules for policy routing. + * description-docbook: + * + * A comma separated list of routing rules for policy routing. The format + * is based on ip rule add syntax and mostly compatible. + * One difference is that routing rules in NetworkManager always need a + * fixed priority. + * + * + * Example: priority 5 from 1:2:3::5/128 table 45 + * + * ---end--- + */ + g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); _nm_setting_class_commit(setting_class, diff --git a/src/libnm-core-impl/nm-setting-macsec.c b/src/libnm-core-impl/nm-setting-macsec.c index 1a9e9bd8..85271214 100644 --- a/src/libnm-core-impl/nm-setting-macsec.c +++ b/src/libnm-core-impl/nm-setting-macsec.c @@ -38,15 +38,15 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_PARENT, PROP_SEND_SCI, ); typedef struct { - char * parent; - char * mka_cak; - char * mka_ckn; - int port; - NMSettingMacsecMode mode; - NMSettingSecretFlags mka_cak_flags; - NMSettingMacsecValidation validation; - bool encrypt; - bool send_sci; + char *parent; + char *mka_cak; + char *mka_ckn; + guint mka_cak_flags; + gint32 mode; + gint32 validation; + gint32 port; + bool encrypt; + bool send_sci; } NMSettingMacsecPrivate; /** @@ -84,6 +84,7 @@ const char * nm_setting_macsec_get_parent(NMSettingMacsec *setting) { g_return_val_if_fail(NM_IS_SETTING_MACSEC(setting), NULL); + return NM_SETTING_MACSEC_GET_PRIVATE(setting)->parent; } @@ -99,6 +100,7 @@ NMSettingMacsecMode nm_setting_macsec_get_mode(NMSettingMacsec *setting) { g_return_val_if_fail(NM_IS_SETTING_MACSEC(setting), NM_SETTING_MACSEC_MODE_PSK); + return NM_SETTING_MACSEC_GET_PRIVATE(setting)->mode; } @@ -129,6 +131,7 @@ const char * nm_setting_macsec_get_mka_cak(NMSettingMacsec *setting) { g_return_val_if_fail(NM_IS_SETTING_MACSEC(setting), NULL); + return NM_SETTING_MACSEC_GET_PRIVATE(setting)->mka_cak; } @@ -160,6 +163,7 @@ const char * nm_setting_macsec_get_mka_ckn(NMSettingMacsec *setting) { g_return_val_if_fail(NM_IS_SETTING_MACSEC(setting), NULL); + return NM_SETTING_MACSEC_GET_PRIVATE(setting)->mka_ckn; } @@ -175,6 +179,7 @@ int nm_setting_macsec_get_port(NMSettingMacsec *setting) { g_return_val_if_fail(NM_IS_SETTING_MACSEC(setting), 1); + return NM_SETTING_MACSEC_GET_PRIVATE(setting)->port; } @@ -190,6 +195,7 @@ NMSettingMacsecValidation nm_setting_macsec_get_validation(NMSettingMacsec *setting) { g_return_val_if_fail(NM_IS_SETTING_MACSEC(setting), NM_SETTING_MACSEC_VALIDATION_DISABLE); + return NM_SETTING_MACSEC_GET_PRIVATE(setting)->validation; } @@ -212,7 +218,7 @@ static GPtrArray * need_secrets(NMSetting *setting) { NMSettingMacsecPrivate *priv = NM_SETTING_MACSEC_GET_PRIVATE(setting); - GPtrArray * secrets = NULL; + GPtrArray *secrets = NULL; if (priv->mode == NM_SETTING_MACSEC_MODE_PSK) { if (!priv->mka_cak @@ -271,9 +277,9 @@ static gboolean verify(NMSetting *setting, NMConnection *connection, GError **error) { NMSettingMacsecPrivate *priv = NM_SETTING_MACSEC_GET_PRIVATE(setting); - NMSettingConnection * s_con = NULL; - NMSettingWired * s_wired = NULL; - NMSetting8021x * s_8021x = NULL; + NMSettingConnection *s_con = NULL; + NMSettingWired *s_wired = NULL; + NMSetting8021x *s_8021x = NULL; if (connection) { s_con = nm_connection_get_setting_connection(connection); @@ -374,15 +380,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) return FALSE; } - if (priv->port <= 0 || priv->port > 65534) { - g_set_error(error, - NM_CONNECTION_ERROR, - NM_CONNECTION_ERROR_MISSING_PROPERTY, - _("invalid port %d"), - priv->port); - g_prefix_error(error, "%s.%s: ", NM_SETTING_MACSEC_SETTING_NAME, NM_SETTING_MACSEC_PORT); - return FALSE; - } + nm_assert(priv->port >= 1 && priv->port <= 65534); if (priv->mode != NM_SETTING_MACSEC_MODE_PSK && (priv->mka_cak || priv->mka_ckn)) { g_set_error_literal(error, @@ -401,100 +399,9 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) /*****************************************************************************/ -static void -get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - NMSettingMacsec * setting = NM_SETTING_MACSEC(object); - NMSettingMacsecPrivate *priv = NM_SETTING_MACSEC_GET_PRIVATE(setting); - - switch (prop_id) { - case PROP_PARENT: - g_value_set_string(value, priv->parent); - break; - case PROP_MODE: - g_value_set_int(value, priv->mode); - break; - case PROP_ENCRYPT: - g_value_set_boolean(value, priv->encrypt); - break; - case PROP_MKA_CAK: - g_value_set_string(value, priv->mka_cak); - break; - case PROP_MKA_CAK_FLAGS: - g_value_set_flags(value, priv->mka_cak_flags); - break; - case PROP_MKA_CKN: - g_value_set_string(value, priv->mka_ckn); - break; - case PROP_PORT: - g_value_set_int(value, priv->port); - break; - case PROP_VALIDATION: - g_value_set_int(value, priv->validation); - break; - case PROP_SEND_SCI: - g_value_set_boolean(value, priv->send_sci); - 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) -{ - NMSettingMacsec * setting = NM_SETTING_MACSEC(object); - NMSettingMacsecPrivate *priv = NM_SETTING_MACSEC_GET_PRIVATE(setting); - - switch (prop_id) { - case PROP_PARENT: - g_free(priv->parent); - priv->parent = g_value_dup_string(value); - break; - case PROP_MODE: - priv->mode = g_value_get_int(value); - break; - case PROP_ENCRYPT: - priv->encrypt = g_value_get_boolean(value); - break; - case PROP_MKA_CAK: - nm_free_secret(priv->mka_cak); - priv->mka_cak = g_value_dup_string(value); - break; - case PROP_MKA_CAK_FLAGS: - priv->mka_cak_flags = g_value_get_flags(value); - break; - case PROP_MKA_CKN: - g_free(priv->mka_ckn); - priv->mka_ckn = g_value_dup_string(value); - break; - case PROP_PORT: - priv->port = g_value_get_int(value); - break; - case PROP_VALIDATION: - priv->validation = g_value_get_int(value); - break; - case PROP_SEND_SCI: - priv->send_sci = g_value_get_boolean(value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } -} - -/*****************************************************************************/ - static void nm_setting_macsec_init(NMSettingMacsec *self) -{ - NMSettingMacsecPrivate *priv = NM_SETTING_MACSEC_GET_PRIVATE(self); - - nm_assert(priv->mode == NM_SETTING_MACSEC_MODE_PSK); - priv->port = 1; - priv->validation = NM_SETTING_MACSEC_VALIDATION_STRICT; -} +{} /** * nm_setting_macsec_new: @@ -511,31 +418,17 @@ nm_setting_macsec_new(void) return g_object_new(NM_TYPE_SETTING_MACSEC, NULL); } -static void -finalize(GObject *object) -{ - NMSettingMacsec * setting = NM_SETTING_MACSEC(object); - NMSettingMacsecPrivate *priv = NM_SETTING_MACSEC_GET_PRIVATE(setting); - - g_free(priv->parent); - nm_free_secret(priv->mka_cak); - g_free(priv->mka_ckn); - - G_OBJECT_CLASS(nm_setting_macsec_parent_class)->finalize(object); -} - static void nm_setting_macsec_class_init(NMSettingMacsecClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingMacsecPrivate)); - object_class->get_property = get_property; - object_class->set_property = set_property; - object_class->finalize = finalize; + object_class->get_property = _nm_setting_property_get_property_direct; + object_class->set_property = _nm_setting_property_set_property_direct; setting_class->verify = verify; setting_class->need_secrets = need_secrets; @@ -550,12 +443,13 @@ nm_setting_macsec_class_init(NMSettingMacsecClass *klass) * * Since: 1.6 **/ - obj_properties[PROP_PARENT] = g_param_spec_string( - NM_SETTING_MACSEC_PARENT, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_MACSEC_PARENT, + PROP_PARENT, + NM_SETTING_PARAM_INFERRABLE, + NMSettingMacsecPrivate, + parent); /** * NMSettingMacsec:mode: @@ -565,14 +459,16 @@ nm_setting_macsec_class_init(NMSettingMacsecClass *klass) * * Since: 1.6 **/ - obj_properties[PROP_MODE] = - g_param_spec_int(NM_SETTING_MACSEC_MODE, - "", - "", - G_MININT, - G_MAXINT, - NM_SETTING_MACSEC_MODE_PSK, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_int32(properties_override, + obj_properties, + NM_SETTING_MACSEC_MODE, + PROP_MODE, + G_MININT32, + G_MAXINT32, + NM_SETTING_MACSEC_MODE_PSK, + NM_SETTING_PARAM_INFERRABLE, + NMSettingMacsecPrivate, + mode); /** * NMSettingMacsec:encrypt: @@ -598,12 +494,13 @@ nm_setting_macsec_class_init(NMSettingMacsecClass *klass) * * Since: 1.6 **/ - obj_properties[PROP_MKA_CAK] = - g_param_spec_string(NM_SETTING_MACSEC_MKA_CAK, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_MACSEC_MKA_CAK, + PROP_MKA_CAK, + NM_SETTING_PARAM_SECRET, + NMSettingMacsecPrivate, + mka_cak); /** * NMSettingMacsec:mka-cak-flags: @@ -613,13 +510,12 @@ nm_setting_macsec_class_init(NMSettingMacsecClass *klass) * * Since: 1.6 **/ - obj_properties[PROP_MKA_CAK_FLAGS] = - g_param_spec_flags(NM_SETTING_MACSEC_MKA_CAK_FLAGS, - "", - "", - NM_TYPE_SETTING_SECRET_FLAGS, - NM_SETTING_SECRET_FLAG_NONE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_secret_flags(properties_override, + obj_properties, + NM_SETTING_MACSEC_MKA_CAK_FLAGS, + PROP_MKA_CAK_FLAGS, + NMSettingMacsecPrivate, + mka_cak_flags); /** * NMSettingMacsec:mka-ckn: @@ -629,11 +525,13 @@ nm_setting_macsec_class_init(NMSettingMacsecClass *klass) * * Since: 1.6 **/ - obj_properties[PROP_MKA_CKN] = g_param_spec_string(NM_SETTING_MACSEC_MKA_CKN, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_MACSEC_MKA_CKN, + PROP_MKA_CKN, + NM_SETTING_PARAM_NONE, + NMSettingMacsecPrivate, + mka_ckn); /** * NMSettingMacsec:port: @@ -642,14 +540,16 @@ nm_setting_macsec_class_init(NMSettingMacsecClass *klass) * * Since: 1.6 **/ - obj_properties[PROP_PORT] = - g_param_spec_int(NM_SETTING_MACSEC_PORT, - "", - "", - 1, - 65534, - 1, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_int32(properties_override, + obj_properties, + NM_SETTING_MACSEC_PORT, + PROP_PORT, + 1, + 65534, + 1, + NM_SETTING_PARAM_INFERRABLE, + NMSettingMacsecPrivate, + port); /** * NMSettingMacsec:validation: @@ -658,14 +558,16 @@ nm_setting_macsec_class_init(NMSettingMacsecClass *klass) * * Since: 1.6 **/ - obj_properties[PROP_VALIDATION] = - g_param_spec_int(NM_SETTING_MACSEC_VALIDATION, - "", - "", - G_MININT, - G_MAXINT, - NM_SETTING_MACSEC_VALIDATION_STRICT, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_int32(properties_override, + obj_properties, + NM_SETTING_MACSEC_VALIDATION, + PROP_VALIDATION, + G_MININT32, + G_MAXINT32, + NM_SETTING_MACSEC_VALIDATION_STRICT, + NM_SETTING_PARAM_INFERRABLE, + NMSettingMacsecPrivate, + validation); /** * NMSettingMacsec:send-sci: diff --git a/src/libnm-core-impl/nm-setting-macvlan.c b/src/libnm-core-impl/nm-setting-macvlan.c index 32b30c2c..d26a8086 100644 --- a/src/libnm-core-impl/nm-setting-macvlan.c +++ b/src/libnm-core-impl/nm-setting-macvlan.c @@ -28,10 +28,10 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_PARENT, PROP_MODE, PROP_PROMISCUOUS, PROP_TAP, ); typedef struct { - char * parent; - NMSettingMacvlanMode mode; - bool promiscuous; - bool tap; + char *parent; + guint32 mode; + bool promiscuous; + bool tap; } NMSettingMacvlanPrivate; /** @@ -69,6 +69,7 @@ const char * nm_setting_macvlan_get_parent(NMSettingMacvlan *setting) { g_return_val_if_fail(NM_IS_SETTING_MACVLAN(setting), NULL); + return NM_SETTING_MACVLAN_GET_PRIVATE(setting)->parent; } @@ -84,6 +85,7 @@ NMSettingMacvlanMode nm_setting_macvlan_get_mode(NMSettingMacvlan *setting) { g_return_val_if_fail(NM_IS_SETTING_MACVLAN(setting), NM_SETTING_MACVLAN_MODE_UNKNOWN); + return NM_SETTING_MACVLAN_GET_PRIVATE(setting)->mode; } @@ -123,7 +125,7 @@ static gboolean verify(NMSetting *setting, NMConnection *connection, GError **error) { NMSettingMacvlanPrivate *priv = NM_SETTING_MACVLAN_GET_PRIVATE(setting); - NMSettingWired * s_wired; + NMSettingWired *s_wired; if (connection) s_wired = nm_connection_get_setting_wired(connection); @@ -179,59 +181,6 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) /*****************************************************************************/ -static void -get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - NMSettingMacvlan * setting = NM_SETTING_MACVLAN(object); - NMSettingMacvlanPrivate *priv = NM_SETTING_MACVLAN_GET_PRIVATE(setting); - - switch (prop_id) { - case PROP_PARENT: - g_value_set_string(value, priv->parent); - break; - case PROP_MODE: - g_value_set_uint(value, priv->mode); - break; - case PROP_PROMISCUOUS: - g_value_set_boolean(value, priv->promiscuous); - break; - case PROP_TAP: - g_value_set_boolean(value, priv->tap); - 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) -{ - NMSettingMacvlan * setting = NM_SETTING_MACVLAN(object); - NMSettingMacvlanPrivate *priv = NM_SETTING_MACVLAN_GET_PRIVATE(setting); - - switch (prop_id) { - case PROP_PARENT: - g_free(priv->parent); - priv->parent = g_value_dup_string(value); - break; - case PROP_MODE: - priv->mode = g_value_get_uint(value); - break; - case PROP_PROMISCUOUS: - priv->promiscuous = g_value_get_boolean(value); - break; - case PROP_TAP: - priv->tap = g_value_get_boolean(value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } -} - -/*****************************************************************************/ - static void nm_setting_macvlan_init(NMSettingMacvlan *self) {} @@ -251,29 +200,17 @@ nm_setting_macvlan_new(void) return g_object_new(NM_TYPE_SETTING_MACVLAN, NULL); } -static void -finalize(GObject *object) -{ - NMSettingMacvlan * setting = NM_SETTING_MACVLAN(object); - NMSettingMacvlanPrivate *priv = NM_SETTING_MACVLAN_GET_PRIVATE(setting); - - g_free(priv->parent); - - G_OBJECT_CLASS(nm_setting_macvlan_parent_class)->finalize(object); -} - static void nm_setting_macvlan_class_init(NMSettingMacvlanClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingMacvlanPrivate)); - object_class->get_property = get_property; - object_class->set_property = set_property; - object_class->finalize = finalize; + object_class->get_property = _nm_setting_property_get_property_direct; + object_class->set_property = _nm_setting_property_set_property_direct; setting_class->verify = verify; @@ -287,12 +224,13 @@ nm_setting_macvlan_class_init(NMSettingMacvlanClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_PARENT] = g_param_spec_string( - NM_SETTING_MACVLAN_PARENT, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_MACVLAN_PARENT, + PROP_PARENT, + NM_SETTING_PARAM_INFERRABLE, + NMSettingMacvlanPrivate, + parent); /** * NMSettingMacvlan:mode: @@ -302,14 +240,16 @@ nm_setting_macvlan_class_init(NMSettingMacvlanClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_MODE] = - g_param_spec_uint(NM_SETTING_MACVLAN_MODE, - "", - "", - 0, - G_MAXUINT, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_MACVLAN_MODE, + PROP_MODE, + 0, + G_MAXUINT32, + NM_SETTING_MACVLAN_MODE_UNKNOWN, + NM_SETTING_PARAM_INFERRABLE, + NMSettingMacvlanPrivate, + mode); /** * NMSettingMacvlan:promiscuous: diff --git a/src/libnm-core-impl/nm-setting-match.c b/src/libnm-core-impl/nm-setting-match.c index 20c6b798..0ddffee5 100644 --- a/src/libnm-core-impl/nm-setting-match.c +++ b/src/libnm-core-impl/nm-setting-match.c @@ -33,10 +33,10 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMSettingMatch, */ struct _NMSettingMatch { NMSetting parent; - GArray * interface_name; - GArray * kernel_command_line; - GArray * driver; - GArray * path; + GArray *interface_name; + GArray *kernel_command_line; + GArray *driver; + GArray *path; }; struct _NMSettingMatchClass { @@ -278,7 +278,7 @@ nm_setting_match_remove_kernel_command_line(NMSettingMatch *setting, guint idx) **/ gboolean nm_setting_match_remove_kernel_command_line_by_value(NMSettingMatch *setting, - const char * kernel_command_line) + const char *kernel_command_line) { g_return_val_if_fail(NM_IS_SETTING_MATCH(setting), FALSE); g_return_val_if_fail(kernel_command_line, FALSE); @@ -781,7 +781,7 @@ finalize(GObject *object) static void nm_setting_match_class_init(NMSettingMatchClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); object_class->get_property = get_property; diff --git a/src/libnm-core-impl/nm-setting-olpc-mesh.c b/src/libnm-core-impl/nm-setting-olpc-mesh.c index 0da1d5b4..fe6d3842 100644 --- a/src/libnm-core-impl/nm-setting-olpc-mesh.c +++ b/src/libnm-core-impl/nm-setting-olpc-mesh.c @@ -29,7 +29,7 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_SSID, PROP_CHANNEL, PROP_DHCP_ANYCAST_ADD typedef struct { GBytes *ssid; - char * dhcp_anycast_addr; + char *dhcp_anycast_addr; guint32 channel; } NMSettingOlpcMeshPrivate; @@ -167,9 +167,9 @@ nm_setting_olpc_mesh_new(void) static void nm_setting_olpc_mesh_class_init(NMSettingOlpcMeshClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingOlpcMeshPrivate)); diff --git a/src/libnm-core-impl/nm-setting-ovs-bridge.c b/src/libnm-core-impl/nm-setting-ovs-bridge.c index 711d5461..b15aab19 100644 --- a/src/libnm-core-impl/nm-setting-ovs-bridge.c +++ b/src/libnm-core-impl/nm-setting-ovs-bridge.c @@ -198,64 +198,6 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) /*****************************************************************************/ -static void -get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - NMSettingOvsBridge *self = NM_SETTING_OVS_BRIDGE(object); - - switch (prop_id) { - case PROP_FAIL_MODE: - g_value_set_string(value, self->fail_mode); - break; - case PROP_MCAST_SNOOPING_ENABLE: - g_value_set_boolean(value, self->mcast_snooping_enable); - break; - case PROP_RSTP_ENABLE: - g_value_set_boolean(value, self->rstp_enable); - break; - case PROP_STP_ENABLE: - g_value_set_boolean(value, self->stp_enable); - break; - case PROP_DATAPATH_TYPE: - g_value_set_string(value, self->datapath_type); - 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) -{ - NMSettingOvsBridge *self = NM_SETTING_OVS_BRIDGE(object); - - switch (prop_id) { - case PROP_FAIL_MODE: - g_free(self->fail_mode); - self->fail_mode = g_value_dup_string(value); - break; - case PROP_MCAST_SNOOPING_ENABLE: - self->mcast_snooping_enable = g_value_get_boolean(value); - break; - case PROP_RSTP_ENABLE: - self->rstp_enable = g_value_get_boolean(value); - break; - case PROP_STP_ENABLE: - self->stp_enable = g_value_get_boolean(value); - break; - case PROP_DATAPATH_TYPE: - g_free(self->datapath_type); - self->datapath_type = g_value_dup_string(value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } -} - -/*****************************************************************************/ - static void nm_setting_ovs_bridge_init(NMSettingOvsBridge *self) {} @@ -275,27 +217,15 @@ nm_setting_ovs_bridge_new(void) return g_object_new(NM_TYPE_SETTING_OVS_BRIDGE, NULL); } -static void -finalize(GObject *object) -{ - NMSettingOvsBridge *self = NM_SETTING_OVS_BRIDGE(object); - - g_free(self->fail_mode); - g_free(self->datapath_type); - - G_OBJECT_CLASS(nm_setting_ovs_bridge_parent_class)->finalize(object); -} - static void nm_setting_ovs_bridge_class_init(NMSettingOvsBridgeClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); - object_class->get_property = get_property; - object_class->set_property = set_property; - object_class->finalize = finalize; + object_class->get_property = _nm_setting_property_get_property_direct; + object_class->set_property = _nm_setting_property_set_property_direct; setting_class->verify = verify; @@ -306,12 +236,13 @@ nm_setting_ovs_bridge_class_init(NMSettingOvsBridgeClass *klass) * * Since: 1.10 **/ - obj_properties[PROP_FAIL_MODE] = g_param_spec_string( - NM_SETTING_OVS_BRIDGE_FAIL_MODE, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_OVS_BRIDGE_FAIL_MODE, + PROP_FAIL_MODE, + NM_SETTING_PARAM_INFERRABLE, + NMSettingOvsBridge, + fail_mode); /** * NMSettingOvsBridge:mcast-snooping-enable: @@ -368,12 +299,13 @@ nm_setting_ovs_bridge_class_init(NMSettingOvsBridgeClass *klass) * * Since: 1.20 **/ - obj_properties[PROP_DATAPATH_TYPE] = g_param_spec_string( - NM_SETTING_OVS_BRIDGE_DATAPATH_TYPE, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_OVS_BRIDGE_DATAPATH_TYPE, + PROP_DATAPATH_TYPE, + NM_SETTING_PARAM_INFERRABLE, + NMSettingOvsBridge, + datapath_type); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-ovs-dpdk.c b/src/libnm-core-impl/nm-setting-ovs-dpdk.c index 3107531b..e26f918b 100644 --- a/src/libnm-core-impl/nm-setting-ovs-dpdk.c +++ b/src/libnm-core-impl/nm-setting-ovs-dpdk.c @@ -10,6 +10,7 @@ #include "nm-connection-private.h" #include "nm-setting-connection.h" #include "nm-setting-private.h" +#include "nm-utils-private.h" /** * SECTION:nm-setting-ovs-dpdk @@ -21,7 +22,7 @@ /*****************************************************************************/ -NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_DEVARGS, ); +NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_DEVARGS, PROP_N_RXQ, ); /** * NMSettingOvsDpdk: @@ -31,7 +32,8 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_DEVARGS, ); struct _NMSettingOvsDpdk { NMSetting parent; - char *devargs; + char *devargs; + guint32 n_rxq; }; struct _NMSettingOvsDpdkClass { @@ -58,37 +60,20 @@ nm_setting_ovs_dpdk_get_devargs(NMSettingOvsDpdk *self) return self->devargs; } -/*****************************************************************************/ - -static void -get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +/** + * nm_setting_ovs_dpdk_get_n_rxq: + * @self: the #NMSettingOvsDpdk + * + * Returns: the #NMSettingOvsDpdk:n-rxq property of the setting + * + * Since: 1.36 + **/ +guint32 +nm_setting_ovs_dpdk_get_n_rxq(NMSettingOvsDpdk *self) { - NMSettingOvsDpdk *self = NM_SETTING_OVS_DPDK(object); - - switch (prop_id) { - case PROP_DEVARGS: - g_value_set_string(value, self->devargs); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } -} + g_return_val_if_fail(NM_IS_SETTING_OVS_DPDK(self), 0); -static void -set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) -{ - NMSettingOvsDpdk *self = NM_SETTING_OVS_DPDK(object); - - switch (prop_id) { - case PROP_DEVARGS: - g_free(self->devargs); - self->devargs = g_value_dup_string(value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } + return self->n_rxq; } /*****************************************************************************/ @@ -112,25 +97,15 @@ nm_setting_ovs_dpdk_new(void) return g_object_new(NM_TYPE_SETTING_OVS_DPDK, NULL); } -static void -finalize(GObject *object) -{ - NMSettingOvsDpdk *self = NM_SETTING_OVS_DPDK(object); - - g_free(self->devargs); - - G_OBJECT_CLASS(nm_setting_ovs_dpdk_parent_class)->finalize(object); -} - static void nm_setting_ovs_dpdk_class_init(NMSettingOvsDpdkClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); - NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); + NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GArray *properties_override = _nm_sett_info_property_override_create_array(); - object_class->set_property = set_property; - object_class->get_property = get_property; - object_class->finalize = finalize; + object_class->get_property = _nm_setting_property_get_property_direct; + object_class->set_property = _nm_setting_property_set_property_direct; /** * NMSettingOvsDpdk:devargs: @@ -139,14 +114,39 @@ nm_setting_ovs_dpdk_class_init(NMSettingOvsDpdkClass *klass) * * Since: 1.20 **/ - obj_properties[PROP_DEVARGS] = g_param_spec_string( - NM_SETTING_OVS_DPDK_DEVARGS, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_OVS_DPDK_DEVARGS, + PROP_DEVARGS, + NM_SETTING_PARAM_INFERRABLE, + NMSettingOvsDpdk, + devargs); + + /** + * NMSettingOvsDpdk:n-rxq: + * + * Open vSwitch DPDK number of rx queues. + * Defaults to zero which means to leave the parameter in OVS unspecified + * and effectively configures one queue. + * + * Since: 1.36 + **/ + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_OVS_DPDK_N_RXQ, + PROP_N_RXQ, + 0, + G_MAXUINT32, + 0, + NM_SETTING_PARAM_INFERRABLE, + NMSettingOvsDpdk, + n_rxq); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_OVS_DPDK, NULL, NULL, 0); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_OVS_DPDK, + NULL, + properties_override, + 0); } diff --git a/src/libnm-core-impl/nm-setting-ovs-external-ids.c b/src/libnm-core-impl/nm-setting-ovs-external-ids.c index ea4004f0..6b8d5d37 100644 --- a/src/libnm-core-impl/nm-setting-ovs-external-ids.c +++ b/src/libnm-core-impl/nm-setting-ovs-external-ids.c @@ -28,7 +28,7 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMSettingOvsExternalIDs, PROP_DATA, ); typedef struct { - GHashTable * data; + GHashTable *data; const char **data_keys; } NMSettingOvsExternalIDsPrivate; @@ -199,7 +199,7 @@ _nm_setting_ovs_external_ids_get_data(NMSettingOvsExternalIDs *self) const char *const * nm_setting_ovs_external_ids_get_data_keys(NMSettingOvsExternalIDs *setting, guint *out_len) { - NMSettingOvsExternalIDs * self = setting; + NMSettingOvsExternalIDs *self = setting; NMSettingOvsExternalIDsPrivate *priv; g_return_val_if_fail(NM_IS_SETTING_OVS_EXTERNAL_IDS(self), NULL); @@ -233,7 +233,7 @@ nm_setting_ovs_external_ids_get_data_keys(NMSettingOvsExternalIDs *setting, guin const char * nm_setting_ovs_external_ids_get_data(NMSettingOvsExternalIDs *setting, const char *key) { - NMSettingOvsExternalIDs * self = setting; + NMSettingOvsExternalIDs *self = setting; NMSettingOvsExternalIDsPrivate *priv; g_return_val_if_fail(NM_IS_SETTING_OVS_EXTERNAL_IDS(self), NULL); @@ -257,10 +257,10 @@ nm_setting_ovs_external_ids_get_data(NMSettingOvsExternalIDs *setting, const cha */ void nm_setting_ovs_external_ids_set_data(NMSettingOvsExternalIDs *setting, - const char * key, - const char * val) + const char *key, + const char *val) { - NMSettingOvsExternalIDs * self = setting; + NMSettingOvsExternalIDs *self = setting; NMSettingOvsExternalIDsPrivate *priv; g_return_if_fail(NM_IS_SETTING_OVS_EXTERNAL_IDS(self)); @@ -295,14 +295,14 @@ out_changed: static gboolean verify(NMSetting *setting, NMConnection *connection, GError **error) { - NMSettingOvsExternalIDs * self = NM_SETTING_OVS_EXTERNAL_IDS(setting); + NMSettingOvsExternalIDs *self = NM_SETTING_OVS_EXTERNAL_IDS(setting); NMSettingOvsExternalIDsPrivate *priv = NM_SETTING_OVS_EXTERNAL_IDS_GET_PRIVATE(self); if (priv->data) { gs_free_error GError *local = NULL; GHashTableIter iter; - const char * key; - const char * val; + const char *key; + const char *val; g_hash_table_iter_init(&iter, priv->data); while (g_hash_table_iter_next(&iter, (gpointer *) &key, (gpointer *) &val)) { @@ -346,8 +346,8 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) if (connection) { NMSettingConnection *s_con; - const char * type; - const char * slave_type; + const char *type; + const char *slave_type; type = nm_connection_get_connection_type(connection); if (!type) { @@ -408,12 +408,12 @@ compare_fcn_data(_NM_SETT_INFO_PROP_COMPARE_FCN_ARGS _nm_nil) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMSettingOvsExternalIDs * self = NM_SETTING_OVS_EXTERNAL_IDS(object); + NMSettingOvsExternalIDs *self = NM_SETTING_OVS_EXTERNAL_IDS(object); NMSettingOvsExternalIDsPrivate *priv = NM_SETTING_OVS_EXTERNAL_IDS_GET_PRIVATE(self); GHashTableIter iter; - GHashTable * data; - const char * key; - const char * val; + GHashTable *data; + const char *key; + const char *val; switch (prop_id) { case PROP_DATA: @@ -434,7 +434,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) { - NMSettingOvsExternalIDs * self = NM_SETTING_OVS_EXTERNAL_IDS(object); + NMSettingOvsExternalIDs *self = NM_SETTING_OVS_EXTERNAL_IDS(object); NMSettingOvsExternalIDsPrivate *priv = NM_SETTING_OVS_EXTERNAL_IDS_GET_PRIVATE(self); switch (prop_id) { @@ -442,9 +442,9 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps { gs_unref_hashtable GHashTable *old = NULL; GHashTableIter iter; - GHashTable * data; - const char * key; - const char * val; + GHashTable *data; + const char *key; + const char *val; nm_clear_g_free(&priv->data_keys); @@ -491,7 +491,7 @@ nm_setting_ovs_external_ids_new(void) static void finalize(GObject *object) { - NMSettingOvsExternalIDs * self = NM_SETTING_OVS_EXTERNAL_IDS(object); + NMSettingOvsExternalIDs *self = NM_SETTING_OVS_EXTERNAL_IDS(object); NMSettingOvsExternalIDsPrivate *priv = NM_SETTING_OVS_EXTERNAL_IDS_GET_PRIVATE(self); g_free(priv->data_keys); @@ -504,9 +504,9 @@ finalize(GObject *object) static void nm_setting_ovs_external_ids_class_init(NMSettingOvsExternalIDsClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); object_class->get_property = get_property; object_class->set_property = set_property; @@ -543,5 +543,5 @@ nm_setting_ovs_external_ids_class_init(NMSettingOvsExternalIDsClass *klass) NM_META_SETTING_TYPE_OVS_EXTERNAL_IDS, NULL, properties_override, - G_STRUCT_OFFSET(NMSettingOvsExternalIDs, _priv)); + 0); } diff --git a/src/libnm-core-impl/nm-setting-ovs-interface.c b/src/libnm-core-impl/nm-setting-ovs-interface.c index 58a01fcc..6554f520 100644 --- a/src/libnm-core-impl/nm-setting-ovs-interface.c +++ b/src/libnm-core-impl/nm-setting-ovs-interface.c @@ -62,12 +62,12 @@ nm_setting_ovs_interface_get_interface_type(NMSettingOvsInterface *self) int _nm_setting_ovs_interface_verify_interface_type(NMSettingOvsInterface *self, - const char * type, - NMConnection * connection, + const char *type, + NMConnection *connection, gboolean normalize, - gboolean * out_modified, - const char ** out_normalized_type, - GError ** error) + gboolean *out_modified, + const char **out_normalized_type, + GError **error) { const char *type_from_setting = NULL; const char *type_setting = NULL; @@ -276,7 +276,7 @@ static int verify(NMSetting *setting, NMConnection *connection, GError **error) { NMSettingOvsInterface *self = NM_SETTING_OVS_INTERFACE(setting); - NMSettingConnection * s_con = NULL; + NMSettingConnection *s_con = NULL; if (connection) { const char *slave_type; @@ -333,39 +333,6 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) /*****************************************************************************/ -static void -get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - NMSettingOvsInterface *self = NM_SETTING_OVS_INTERFACE(object); - - switch (prop_id) { - case PROP_TYPE: - g_value_set_string(value, self->type); - 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) -{ - NMSettingOvsInterface *self = NM_SETTING_OVS_INTERFACE(object); - - switch (prop_id) { - case PROP_TYPE: - g_free(self->type); - self->type = g_value_dup_string(value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } -} - -/*****************************************************************************/ - static void nm_setting_ovs_interface_init(NMSettingOvsInterface *self) {} @@ -385,25 +352,15 @@ nm_setting_ovs_interface_new(void) return g_object_new(NM_TYPE_SETTING_OVS_INTERFACE, NULL); } -static void -finalize(GObject *object) -{ - NMSettingOvsInterface *self = NM_SETTING_OVS_INTERFACE(object); - - g_free(self->type); - - G_OBJECT_CLASS(nm_setting_ovs_interface_parent_class)->finalize(object); -} - static void nm_setting_ovs_interface_class_init(NMSettingOvsInterfaceClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); - NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); + NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GArray *properties_override = _nm_sett_info_property_override_create_array(); - object_class->get_property = get_property; - object_class->set_property = set_property; - object_class->finalize = finalize; + object_class->get_property = _nm_setting_property_get_property_direct; + object_class->set_property = _nm_setting_property_set_property_direct; setting_class->verify = verify; @@ -414,14 +371,19 @@ nm_setting_ovs_interface_class_init(NMSettingOvsInterfaceClass *klass) * * Since: 1.10 **/ - obj_properties[PROP_TYPE] = g_param_spec_string(NM_SETTING_OVS_INTERFACE_TYPE, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE - | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_OVS_INTERFACE_TYPE, + PROP_TYPE, + NM_SETTING_PARAM_INFERRABLE, + NMSettingOvsInterface, + type); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_OVS_INTERFACE, NULL, NULL, 0); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_OVS_INTERFACE, + NULL, + properties_override, + 0); } diff --git a/src/libnm-core-impl/nm-setting-ovs-patch.c b/src/libnm-core-impl/nm-setting-ovs-patch.c index 578f5ee2..2781d435 100644 --- a/src/libnm-core-impl/nm-setting-ovs-patch.c +++ b/src/libnm-core-impl/nm-setting-ovs-patch.c @@ -93,39 +93,6 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) /*****************************************************************************/ -static void -get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - NMSettingOvsPatch *self = NM_SETTING_OVS_PATCH(object); - - switch (prop_id) { - case PROP_PEER: - g_value_set_string(value, self->peer); - 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) -{ - NMSettingOvsPatch *self = NM_SETTING_OVS_PATCH(object); - - switch (prop_id) { - case PROP_PEER: - g_free(self->peer); - self->peer = g_value_dup_string(value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } -} - -/*****************************************************************************/ - static void nm_setting_ovs_patch_init(NMSettingOvsPatch *self) {} @@ -145,25 +112,15 @@ nm_setting_ovs_patch_new(void) return g_object_new(NM_TYPE_SETTING_OVS_PATCH, NULL); } -static void -finalize(GObject *object) -{ - NMSettingOvsPatch *self = NM_SETTING_OVS_PATCH(object); - - g_free(self->peer); - - G_OBJECT_CLASS(nm_setting_ovs_patch_parent_class)->finalize(object); -} - static void nm_setting_ovs_patch_class_init(NMSettingOvsPatchClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); - NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); + NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GArray *properties_override = _nm_sett_info_property_override_create_array(); - object_class->set_property = set_property; - object_class->get_property = get_property; - object_class->finalize = finalize; + object_class->get_property = _nm_setting_property_get_property_direct; + object_class->set_property = _nm_setting_property_set_property_direct; setting_class->verify = verify; @@ -175,14 +132,19 @@ nm_setting_ovs_patch_class_init(NMSettingOvsPatchClass *klass) * * Since: 1.10 **/ - obj_properties[PROP_PEER] = g_param_spec_string(NM_SETTING_OVS_PATCH_PEER, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE - | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_OVS_PATCH_PEER, + PROP_PEER, + NM_SETTING_PARAM_INFERRABLE, + NMSettingOvsPatch, + peer); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_OVS_PATCH, NULL, NULL, 0); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_OVS_PATCH, + NULL, + properties_override, + 0); } diff --git a/src/libnm-core-impl/nm-setting-ovs-port.c b/src/libnm-core-impl/nm-setting-ovs-port.c index fc593268..ab9c0a11 100644 --- a/src/libnm-core-impl/nm-setting-ovs-port.c +++ b/src/libnm-core-impl/nm-setting-ovs-port.c @@ -36,9 +36,9 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_VLAN_MODE, struct _NMSettingOvsPort { NMSetting parent; - char * vlan_mode; - char * lacp; - char * bond_mode; + char *vlan_mode; + char *lacp; + char *bond_mode; guint32 tag; guint32 bond_updelay; guint32 bond_downdelay; @@ -160,7 +160,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) if (connection) { NMSettingConnection *s_con; - const char * slave_type; + const char *slave_type; s_con = nm_connection_get_setting_connection(connection); if (!s_con) { @@ -284,9 +284,9 @@ nm_setting_ovs_port_new(void) static void nm_setting_ovs_port_class_init(NMSettingOvsPortClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); object_class->get_property = _nm_setting_property_get_property_direct; object_class->set_property = _nm_setting_property_set_property_direct; diff --git a/src/libnm-core-impl/nm-setting-ppp.c b/src/libnm-core-impl/nm-setting-ppp.c index e4e4951e..a9d2b9a2 100644 --- a/src/libnm-core-impl/nm-setting-ppp.c +++ b/src/libnm-core-impl/nm-setting-ppp.c @@ -398,9 +398,9 @@ nm_setting_ppp_new(void) static void nm_setting_ppp_class_init(NMSettingPppClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingPppPrivate)); diff --git a/src/libnm-core-impl/nm-setting-pppoe.c b/src/libnm-core-impl/nm-setting-pppoe.c index 3ae547a2..c4a9a89c 100644 --- a/src/libnm-core-impl/nm-setting-pppoe.c +++ b/src/libnm-core-impl/nm-setting-pppoe.c @@ -135,8 +135,8 @@ nm_setting_pppoe_get_password_flags(NMSettingPppoe *setting) static gboolean verify(NMSetting *setting, NMConnection *connection, GError **error) { - NMSettingPppoePrivate *priv = NM_SETTING_PPPOE_GET_PRIVATE(setting); - gs_free_error GError *local_error = NULL; + NMSettingPppoePrivate *priv = NM_SETTING_PPPOE_GET_PRIVATE(setting); + gs_free_error GError *local_error = NULL; if (nm_str_is_empty(priv->username)) { if (!priv->username) { @@ -181,7 +181,7 @@ static GPtrArray * need_secrets(NMSetting *setting) { NMSettingPppoePrivate *priv = NM_SETTING_PPPOE_GET_PRIVATE(setting); - GPtrArray * secrets = NULL; + GPtrArray *secrets = NULL; if (priv->password) return NULL; @@ -216,9 +216,9 @@ nm_setting_pppoe_new(void) static void nm_setting_pppoe_class_init(NMSettingPppoeClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingPppoePrivate)); diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index 7faf5d1c..7483eaed 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -59,49 +59,49 @@ struct _NMSettingClass { int (*update_one_secret)(NMSetting *setting, const char *key, GVariant *value, GError **error); - gboolean (*get_secret_flags)(NMSetting * setting, - const char * secret_name, + gboolean (*get_secret_flags)(NMSetting *setting, + const char *secret_name, NMSettingSecretFlags *out_flags, - GError ** error); + GError **error); - gboolean (*set_secret_flags)(NMSetting * setting, - const char * secret_name, + gboolean (*set_secret_flags)(NMSetting *setting, + const char *secret_name, NMSettingSecretFlags flags, - GError ** error); + GError **error); gboolean (*clear_secrets)(const struct _NMSettInfoSetting *sett_info, - const NMSettInfoProperty * property_info, - NMSetting * setting, + const NMSettInfoProperty *property_info, + NMSetting *setting, NMSettingClearSecretsWithFlagsFn func, gpointer user_data); void (*padding_1)(void); void (*duplicate_copy_properties)(const struct _NMSettInfoSetting *sett_info, - NMSetting * src, - NMSetting * dst); + NMSetting *src, + NMSetting *dst); void (*enumerate_values)(const struct _NMSettInfoProperty *property_info, - NMSetting * setting, + NMSetting *setting, NMSettingValueIterFn func, gpointer user_data); gboolean (*aggregate)(NMSetting *setting, int type_i, gpointer arg); - void (*for_each_secret)(NMSetting * setting, - const char * secret_name, - GVariant * val, + void (*for_each_secret)(NMSetting *setting, + const char *secret_name, + GVariant *val, gboolean remove_non_secrets, _NMConnectionForEachSecretFunc callback, gpointer callback_data, - GVariantBuilder * setting_builder); + GVariantBuilder *setting_builder); - gboolean (*init_from_dbus)(NMSetting * setting, - GHashTable * keys, - GVariant * setting_dict, - GVariant * connection_dict, + gboolean (*init_from_dbus)(NMSetting *setting, + GHashTable *keys, + GVariant *setting_dict, + GVariant *connection_dict, guint /* NMSettingParseFlags */ parse_flags, - GError ** error); + GError **error); const struct _NMMetaSettingInfo *setting_info; }; @@ -134,18 +134,18 @@ typedef struct { GPtrArray *addresses; /* array of NMIPAddress */ GPtrArray *routes; /* array of NMIPRoute */ GPtrArray *routing_rules; - GArray * dhcp_reject_servers; - char * method; - char * gateway; - char * dhcp_hostname; - char * dhcp_iaid; + GArray *dhcp_reject_servers; + char *method; + char *gateway; + char *dhcp_hostname; + char *dhcp_iaid; gint64 route_metric; - guint dhcp_hostname_flags; - int dns_priority; - int dad_timeout; - int dhcp_timeout; - int required_timeout; + gint32 required_timeout; + gint32 dad_timeout; + gint32 dhcp_timeout; + gint32 dns_priority; guint32 route_table; + guint32 dhcp_hostname_flags; bool ignore_auto_routes; bool ignore_auto_dns; bool dhcp_send_hostname; @@ -226,7 +226,7 @@ typedef enum NMSettingUpdateSecretResult { NMSettingUpdateSecretResult _nm_setting_update_secrets(NMSetting *setting, GVariant *secrets, GError **error); -gboolean _nm_setting_clear_secrets(NMSetting * setting, +gboolean _nm_setting_clear_secrets(NMSetting *setting, NMSettingClearSecretsWithFlagsFn func, gpointer user_data); @@ -236,7 +236,7 @@ gboolean _nm_setting_clear_secrets(NMSetting * setting, /* The property of the #NMSetting should be considered during comparisons that * use the %NM_SETTING_COMPARE_FLAG_INFERRABLE flag. Properties that don't have - * this flag, are ignored when doing an infrerrable comparison. This flag should + * this flag, are ignored when doing an inferrable comparison. This flag should * be set on all properties that are read from the kernel or the system when a * connection is generated. eg, IP addresses/routes can be read from the * kernel, but the 'autoconnect' property cannot, so @@ -270,12 +270,10 @@ extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_interfac extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_i; extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_u; -extern const NMSettInfoPropertType nm_sett_info_propert_type_plain_i; -extern const NMSettInfoPropertType nm_sett_info_propert_type_plain_u; - extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_boolean; extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_int32; extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_uint32; +extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_int64; extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_uint64; extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_string; extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_bytes; @@ -289,16 +287,16 @@ _nm_setting_verify(NMSetting *setting, NMConnection *connection, GError **error) gboolean _nm_setting_verify_secret_string(const char *str, const char *setting_name, const char *property, - GError ** error); + GError **error); gboolean _nm_setting_aggregate(NMSetting *setting, NMConnectionAggregateType type, gpointer arg); gboolean _nm_setting_slave_type_is_valid(const char *slave_type, const char **out_port_type); -gboolean _nm_setting_compare_flags_check(const GParamSpec * param_spec, +gboolean _nm_setting_compare_flags_check(const GParamSpec *param_spec, NMSettingCompareFlags flags, - NMSetting * set_a, - NMSetting * set_b); + NMSetting *set_a, + NMSetting *set_b); NMTernary _nm_setting_property_compare_fcn_ignore(_NM_SETT_INFO_PROP_COMPARE_FCN_ARGS _nm_nil); @@ -306,15 +304,15 @@ NMTernary _nm_setting_property_compare_fcn_direct(_NM_SETT_INFO_PROP_COMPARE_FCN NMTernary _nm_setting_property_compare_fcn_default(_NM_SETT_INFO_PROP_COMPARE_FCN_ARGS _nm_nil); -void _nm_setting_property_get_property_direct(GObject * object, +void _nm_setting_property_get_property_direct(GObject *object, guint prop_id, - GValue * value, + GValue *value, GParamSpec *pspec); -void _nm_setting_property_set_property_direct(GObject * object, +void _nm_setting_property_set_property_direct(GObject *object, guint prop_id, const GValue *value, - GParamSpec * pspec); + GParamSpec *pspec); GVariant *_nm_setting_property_to_dbus_fcn_ignore(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil); @@ -337,26 +335,26 @@ gboolean _nm_setting_property_from_dbus_fcn_direct(_NM_SETT_INFO_PROP_FROM_DBUS_ gboolean _nm_setting_property_from_dbus_fcn_gprop(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil); -GVariant *_nm_setting_to_dbus(NMSetting * setting, - NMConnection * connection, +GVariant *_nm_setting_to_dbus(NMSetting *setting, + NMConnection *connection, NMConnectionSerializationFlags flags, const NMConnectionSerializationOptions *options); NMSetting *_nm_setting_new_from_dbus(GType setting_type, - GVariant * setting_dict, - GVariant * connection_dict, + GVariant *setting_dict, + GVariant *connection_dict, NMSettingParseFlags parse_flags, - GError ** error); + GError **error); gboolean _nm_setting_property_is_regular_secret(NMSetting *setting, const char *secret_name); -gboolean _nm_setting_property_is_regular_secret_flags(NMSetting * setting, +gboolean _nm_setting_property_is_regular_secret_flags(NMSetting *setting, const char *secret_flags_name); /*****************************************************************************/ const NMSettInfoProperty * _nm_sett_info_property_lookup_by_param_spec(const NMSettInfoSetting *sett_info, - const GParamSpec * param_spec); + const GParamSpec *param_spec); static inline GArray * _nm_sett_info_property_override_create_array_sized(guint reserved_size) @@ -375,10 +373,10 @@ _nm_sett_info_property_override_create_array(void) GArray *_nm_sett_info_property_override_create_array_ip_config(int addr_family); -void _nm_setting_class_commit(NMSettingClass * setting_class, +void _nm_setting_class_commit(NMSettingClass *setting_class, NMMetaSettingType meta_type, const NMSettInfoSettDetail *detail, - GArray * properties_override, + GArray *properties_override, gint16 private_offset); #define NM_SETT_INFO_SETT_GENDATA(...) \ @@ -464,7 +462,7 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p G_STMT_START \ { \ const gboolean _default_value = (default_value); \ - GParamSpec * _param_spec; \ + GParamSpec *_param_spec; \ \ G_STATIC_ASSERT( \ !NM_FLAGS_ANY((param_flags), \ @@ -585,6 +583,52 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p /*****************************************************************************/ +#define _nm_setting_property_define_direct_int64(properties_override, \ + obj_properties, \ + prop_name, \ + prop_id, \ + min_value, \ + max_value, \ + default_value, \ + param_flags, \ + private_struct_type, \ + private_struct_field, \ + ... /* extra NMSettInfoProperty fields */) \ + G_STMT_START \ + { \ + GParamSpec *_param_spec; \ + \ + G_STATIC_ASSERT( \ + !NM_FLAGS_ANY((param_flags), \ + ~(NM_SETTING_PARAM_FUZZY_IGNORE | NM_SETTING_PARAM_INFERRABLE))); \ + G_STATIC_ASSERT((min_value) >= G_MININT64); \ + G_STATIC_ASSERT((min_value) <= (default_value)); \ + G_STATIC_ASSERT((default_value) <= (max_value)); \ + G_STATIC_ASSERT((max_value) <= G_MAXINT64); \ + \ + _param_spec = \ + g_param_spec_int64("" prop_name "", \ + "", \ + "", \ + (min_value), \ + (max_value), \ + (default_value), \ + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | (param_flags)); \ + \ + (obj_properties)[(prop_id)] = _param_spec; \ + \ + _nm_properties_override_gobj( \ + (properties_override), \ + _param_spec, \ + &nm_sett_info_propert_type_direct_int64, \ + .direct_offset = \ + NM_STRUCT_OFFSET_ENSURE_TYPE(gint64, private_struct_type, private_struct_field), \ + __VA_ARGS__); \ + } \ + G_STMT_END + +/*****************************************************************************/ + #define _nm_setting_property_define_direct_uint64(properties_override, \ obj_properties, \ prop_name, \ @@ -641,12 +685,12 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p ... /* extra NMSettInfoProperty fields */) \ G_STMT_START \ { \ - GParamSpec * _param_spec; \ + GParamSpec *_param_spec; \ const NMSettInfoPropertType *_property_type = (property_type); \ \ G_STATIC_ASSERT(!NM_FLAGS_ANY((param_flags), \ ~(NM_SETTING_PARAM_SECRET | NM_SETTING_PARAM_FUZZY_IGNORE \ - | NM_SETTING_PARAM_INFERRABLE \ + | NM_SETTING_PARAM_INFERRABLE | NM_SETTING_PARAM_REQUIRED \ | NM_SETTING_PARAM_REAPPLY_IMMEDIATELY))); \ \ nm_assert(_property_type); \ @@ -890,16 +934,16 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p /*****************************************************************************/ -gboolean _nm_setting_use_legacy_property(NMSetting * setting, - GVariant * connection_dict, +gboolean _nm_setting_use_legacy_property(NMSetting *setting, + GVariant *connection_dict, const char *legacy_property, const char *new_property); GPtrArray *_nm_setting_need_secrets(NMSetting *setting); -gboolean _nm_setting_should_compare_secret_property(NMSetting * setting, - NMSetting * other, - const char * secret_name, +gboolean _nm_setting_should_compare_secret_property(NMSetting *setting, + NMSetting *other, + const char *secret_name, NMSettingCompareFlags flags); NMBridgeVlan *_nm_bridge_vlan_dup(const NMBridgeVlan *vlan); diff --git a/src/libnm-core-impl/nm-setting-proxy.c b/src/libnm-core-impl/nm-setting-proxy.c index 0425ec45..4b9a2970 100644 --- a/src/libnm-core-impl/nm-setting-proxy.c +++ b/src/libnm-core-impl/nm-setting-proxy.c @@ -29,8 +29,8 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_METHOD, PROP_BROWSER_ONLY, PROP_PAC_URL, PROP_PAC_SCRIPT, ); typedef struct { - char * pac_url; - char * pac_script; + char *pac_url; + char *pac_script; gint32 method; bool browser_only; } NMSettingProxyPrivate; @@ -229,9 +229,9 @@ nm_setting_proxy_new(void) static void nm_setting_proxy_class_init(NMSettingProxyClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingProxyPrivate)); diff --git a/src/libnm-core-impl/nm-setting-serial.c b/src/libnm-core-impl/nm-setting-serial.c index 3ebcf062..a8201876 100644 --- a/src/libnm-core-impl/nm-setting-serial.c +++ b/src/libnm-core-impl/nm-setting-serial.c @@ -222,9 +222,9 @@ nm_setting_serial_new(void) static void nm_setting_serial_class_init(NMSettingSerialClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingSerialPrivate)); diff --git a/src/libnm-core-impl/nm-setting-sriov.c b/src/libnm-core-impl/nm-setting-sriov.c index a024dba6..30dd8f54 100644 --- a/src/libnm-core-impl/nm-setting-sriov.c +++ b/src/libnm-core-impl/nm-setting-sriov.c @@ -30,8 +30,8 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMSettingSriov, PROP_TOTAL_VFS, PROP_VFS, PROP_AUTO struct _NMSettingSriov { NMSetting parent; GPtrArray *vfs; - guint total_vfs; - NMTernary autoprobe_drivers; + int autoprobe_drivers; + guint32 total_vfs; }; struct _NMSettingSriovClass { @@ -49,7 +49,7 @@ struct _NMSriovVF { guint index; GHashTable *attributes; GHashTable *vlans; - guint * vlan_ids; + guint *vlan_ids; }; typedef struct { @@ -163,9 +163,9 @@ gboolean nm_sriov_vf_equal(const NMSriovVF *vf, const NMSriovVF *other) { GHashTableIter iter; - const char * key; - GVariant * value, *value2; - VFVlan * vlan, *vlan2; + const char *key; + GVariant *value, *value2; + VFVlan *vlan, *vlan2; guint n_vlans; g_return_val_if_fail(vf, FALSE); @@ -239,11 +239,11 @@ vf_add_vlan(NMSriovVF *vf, guint vlan_id, guint qos, NMSriovVFVlanProtocol proto NMSriovVF * nm_sriov_vf_dup(const NMSriovVF *vf) { - NMSriovVF * copy; + NMSriovVF *copy; GHashTableIter iter; - const char * name; - GVariant * variant; - VFVlan * vlan; + const char *name; + GVariant *variant; + VFVlan *vlan; g_return_val_if_fail(vf, NULL); g_return_val_if_fail(vf->refcount > 0, NULL); @@ -350,13 +350,13 @@ nm_sriov_vf_get_attribute(const NMSriovVF *vf, const char *name) const NMVariantAttributeSpec *const _nm_sriov_vf_attribute_spec[] = { NM_VARIANT_ATTRIBUTE_SPEC_DEFINE(NM_SRIOV_VF_ATTRIBUTE_MAC, G_VARIANT_TYPE_STRING, - .str_type = 'm', ), + .type_detail = 'm', ), NM_VARIANT_ATTRIBUTE_SPEC_DEFINE(NM_SRIOV_VF_ATTRIBUTE_SPOOF_CHECK, G_VARIANT_TYPE_BOOLEAN, ), NM_VARIANT_ATTRIBUTE_SPEC_DEFINE(NM_SRIOV_VF_ATTRIBUTE_TRUST, G_VARIANT_TYPE_BOOLEAN, ), NM_VARIANT_ATTRIBUTE_SPEC_DEFINE(NM_SRIOV_VF_ATTRIBUTE_MIN_TX_RATE, G_VARIANT_TYPE_UINT32, ), NM_VARIANT_ATTRIBUTE_SPEC_DEFINE(NM_SRIOV_VF_ATTRIBUTE_MAX_TX_RATE, G_VARIANT_TYPE_UINT32, ), /* D-Bus only, synthetic attributes */ - NM_VARIANT_ATTRIBUTE_SPEC_DEFINE("vlans", G_VARIANT_TYPE_STRING, .str_type = 'd', ), + NM_VARIANT_ATTRIBUTE_SPEC_DEFINE("vlans", G_VARIANT_TYPE_STRING, .type_detail = 'd', ), NULL, }; @@ -378,7 +378,8 @@ gboolean nm_sriov_vf_attribute_validate(const char *name, GVariant *value, gboolean *known, GError **error) { const NMVariantAttributeSpec *const *iter; - const NMVariantAttributeSpec * spec = NULL; + const NMVariantAttributeSpec *spec = NULL; + const char *string; g_return_val_if_fail(name, FALSE); g_return_val_if_fail(value, FALSE); @@ -391,7 +392,7 @@ nm_sriov_vf_attribute_validate(const char *name, GVariant *value, gboolean *know } } - if (!spec || spec->str_type == 'd') { + if (!spec || spec->type_detail == 'd') { NM_SET_OUT(known, FALSE); g_set_error_literal(error, NM_CONNECTION_ERROR, @@ -411,24 +412,23 @@ nm_sriov_vf_attribute_validate(const char *name, GVariant *value, gboolean *know return FALSE; } - if (g_variant_type_equal(spec->type, G_VARIANT_TYPE_STRING)) { - const char *string; - - switch (spec->str_type) { - case 'm': /* MAC address */ - string = g_variant_get_string(value, NULL); - if (!nm_utils_hwaddr_valid(string, -1)) { - g_set_error(error, - NM_CONNECTION_ERROR, - NM_CONNECTION_ERROR_FAILED, - _("'%s' is not a valid MAC address"), - string); - return FALSE; - } - break; - default: - break; + switch (spec->type_detail) { + case 'm': /* MAC address */ + string = g_variant_get_string(value, NULL); + if (!nm_utils_hwaddr_valid(string, -1)) { + g_set_error(error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_FAILED, + _("'%s' is not a valid MAC address"), + string); + return FALSE; } + break; + case '\0': + break; + default: + nm_assert_not_reached(); + break; } return TRUE; @@ -438,9 +438,9 @@ gboolean _nm_sriov_vf_attribute_validate_all(const NMSriovVF *vf, GError **error) { GHashTableIter iter; - const char * name; - GVariant * variant; - GVariant * min, *max; + const char *name; + GVariant *variant; + GVariant *min, *max; g_return_val_if_fail(vf, FALSE); g_return_val_if_fail(vf->refcount > 0, FALSE); @@ -546,7 +546,7 @@ const guint * nm_sriov_vf_get_vlan_ids(const NMSriovVF *vf, guint *length) { GHashTableIter iter; - VFVlan * vlan; + VFVlan *vlan; guint num, i; g_return_val_if_fail(vf, NULL); @@ -888,10 +888,10 @@ vfs_to_dbus(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) if (vfs) { for (i = 0; i < vfs->len; i++) { gs_free const char **attr_names = NULL; - NMSriovVF * vf = vfs->pdata[i]; + NMSriovVF *vf = vfs->pdata[i]; GVariantBuilder vf_builder; - const guint * vlan_ids; - const char ** name; + const guint *vlan_ids; + const char **name; guint num_vlans = 0; g_variant_builder_init(&vf_builder, G_VARIANT_TYPE_VARDICT); @@ -954,20 +954,20 @@ vfs_to_dbus(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) static gboolean vfs_from_dbus(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) { - GPtrArray * vfs; + GPtrArray *vfs; GVariantIter vf_iter; - GVariant * vf_var; + GVariant *vf_var; g_return_val_if_fail(g_variant_is_of_type(value, G_VARIANT_TYPE("aa{sv}")), FALSE); vfs = g_ptr_array_new_with_free_func((GDestroyNotify) nm_sriov_vf_unref); g_variant_iter_init(&vf_iter, value); while (g_variant_iter_next(&vf_iter, "@a{sv}", &vf_var)) { - NMSriovVF * vf; + NMSriovVF *vf; guint32 index; GVariantIter attr_iter; - const char * attr_name; - GVariant * attr_var, *vlans_var; + const char *attr_name; + GVariant *attr_var, *vlans_var; if (!g_variant_lookup(vf_var, "index", "u", &index)) goto next; @@ -983,7 +983,7 @@ vfs_from_dbus(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) if (g_variant_lookup(vf_var, "vlans", "@aa{sv}", &vlans_var)) { GVariantIter vlan_iter; - GVariant * vlan_var; + GVariant *vlan_var; g_variant_iter_init(&vlan_iter, vlans_var); while (g_variant_iter_next(&vlan_iter, "@a{sv}", &vlan_var)) { @@ -1035,7 +1035,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) h = g_hash_table_new(nm_direct_hash, NULL); for (i = 0; i < self->vfs->len; i++) { - NMSriovVF * vf = self->vfs->pdata[i]; + NMSriovVF *vf = self->vfs->pdata[i]; gs_free_error GError *local = NULL; if (vf->index >= self->total_vfs) { @@ -1138,20 +1138,14 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) NMSettingSriov *self = NM_SETTING_SRIOV(object); switch (prop_id) { - case PROP_TOTAL_VFS: - g_value_set_uint(value, self->total_vfs); - break; case PROP_VFS: g_value_take_boxed(value, _nm_utils_copy_array(self->vfs, (NMUtilsCopyFunc) nm_sriov_vf_dup, (GDestroyNotify) nm_sriov_vf_unref)); break; - case PROP_AUTOPROBE_DRIVERS: - g_value_set_enum(value, self->autoprobe_drivers); - break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + _nm_setting_property_get_property_direct(object, prop_id, value, pspec); break; } } @@ -1162,20 +1156,14 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps NMSettingSriov *self = NM_SETTING_SRIOV(object); switch (prop_id) { - case PROP_TOTAL_VFS: - self->total_vfs = g_value_get_uint(value); - break; case PROP_VFS: g_ptr_array_unref(self->vfs); self->vfs = _nm_utils_copy_array(g_value_get_boxed(value), (NMUtilsCopyFunc) nm_sriov_vf_dup, (GDestroyNotify) nm_sriov_vf_unref); break; - case PROP_AUTOPROBE_DRIVERS: - self->autoprobe_drivers = g_value_get_enum(value); - break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + _nm_setting_property_set_property_direct(object, prop_id, value, pspec); break; } } @@ -1186,8 +1174,6 @@ static void nm_setting_sriov_init(NMSettingSriov *setting) { setting->vfs = g_ptr_array_new_with_free_func((GDestroyNotify) nm_sriov_vf_unref); - - setting->autoprobe_drivers = NM_TERNARY_DEFAULT; } /** @@ -1218,9 +1204,9 @@ finalize(GObject *object) static void nm_setting_sriov_class_init(NMSettingSriovClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); object_class->get_property = get_property; object_class->set_property = set_property; @@ -1248,14 +1234,16 @@ nm_setting_sriov_class_init(NMSettingSriovClass *klass) * example: SRIOV_TOTAL_VFS=16 * ---end--- */ - obj_properties[PROP_TOTAL_VFS] = g_param_spec_uint( - NM_SETTING_SRIOV_TOTAL_VFS, - "", - "", - 0, - G_MAXUINT32, - 0, - NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_SRIOV_TOTAL_VFS, + PROP_TOTAL_VFS, + 0, + G_MAXUINT32, + 0, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingSriov, + total_vfs); /** * NMSettingSriov:vfs: (type GPtrArray(NMSriovVF)) @@ -1335,13 +1323,13 @@ nm_setting_sriov_class_init(NMSettingSriovClass *klass) * example: SRIOV_AUTOPROBE_DRIVERS=0,1 * ---end--- */ - obj_properties[PROP_AUTOPROBE_DRIVERS] = g_param_spec_enum( - NM_SETTING_SRIOV_AUTOPROBE_DRIVERS, - "", - "", - NM_TYPE_TERNARY, - NM_TERNARY_DEFAULT, - NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_ternary_enum(properties_override, + obj_properties, + NM_SETTING_SRIOV_AUTOPROBE_DRIVERS, + PROP_AUTOPROBE_DRIVERS, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingSriov, + autoprobe_drivers); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-tc-config.c b/src/libnm-core-impl/nm-setting-tc-config.c index cd13709a..08a7f94d 100644 --- a/src/libnm-core-impl/nm-setting-tc-config.c +++ b/src/libnm-core-impl/nm-setting-tc-config.c @@ -24,7 +24,7 @@ G_DEFINE_BOXED_TYPE(NMTCQdisc, nm_tc_qdisc, nm_tc_qdisc_dup, nm_tc_qdisc_unref) struct NMTCQdisc { guint refcount; - char * kind; + char *kind; guint32 handle; guint32 parent; GHashTable *attributes; @@ -138,8 +138,8 @@ gboolean nm_tc_qdisc_equal(NMTCQdisc *qdisc, NMTCQdisc *other) { GHashTableIter iter; - const char * key; - GVariant * value, *value2; + const char *key; + GVariant *value, *value2; guint n; g_return_val_if_fail(qdisc != NULL, FALSE); @@ -172,9 +172,9 @@ nm_tc_qdisc_equal(NMTCQdisc *qdisc, NMTCQdisc *other) static guint _nm_tc_qdisc_hash(NMTCQdisc *qdisc) { - NMUtilsNamedValue attrs_static[30]; + NMUtilsNamedValue attrs_static[30]; gs_free NMUtilsNamedValue *attrs_free = NULL; - const NMUtilsNamedValue * attrs; + const NMUtilsNamedValue *attrs; NMHashState h; guint length; guint i; @@ -186,8 +186,8 @@ _nm_tc_qdisc_hash(NMTCQdisc *qdisc) nm_hash_update_vals(&h, qdisc->handle, qdisc->parent, length); nm_hash_update_str0(&h, qdisc->kind); for (i = 0; i < length; i++) { - const char * key = attrs[i].name; - GVariant * variant = attrs[i].value_ptr; + const char *key = attrs[i].name; + GVariant *variant = attrs[i].value_ptr; const GVariantType *vtype; vtype = g_variant_get_type(variant); @@ -224,8 +224,8 @@ nm_tc_qdisc_dup(NMTCQdisc *qdisc) if (qdisc->attributes) { GHashTableIter iter; - const char * key; - GVariant * value; + const char *key; + GVariant *value; g_hash_table_iter_init(&iter, qdisc->attributes); while (g_hash_table_iter_next(&iter, (gpointer *) &key, (gpointer *) &value)) @@ -495,8 +495,8 @@ gboolean nm_tc_action_equal(NMTCAction *action, NMTCAction *other) { GHashTableIter iter; - const char * key; - GVariant * value, *value2; + const char *key; + GVariant *value, *value2; guint n; g_return_val_if_fail(!action || action->refcount > 0, FALSE); @@ -549,8 +549,8 @@ nm_tc_action_dup(NMTCAction *action) if (action->attributes) { GHashTableIter iter; - const char * key; - GVariant * value; + const char *key; + GVariant *value; g_hash_table_iter_init(&iter, action->attributes); while (g_hash_table_iter_next(&iter, (gpointer *) &key, (gpointer *) &value)) @@ -667,7 +667,7 @@ G_DEFINE_BOXED_TYPE(NMTCTfilter, nm_tc_tfilter, nm_tc_tfilter_dup, nm_tc_tfilter struct NMTCTfilter { guint refcount; - char * kind; + char *kind; guint32 handle; guint32 parent; NMTCAction *action; @@ -806,7 +806,7 @@ _nm_tc_tfilter_hash(NMTCTfilter *tfilter) if (tfilter->action) { gs_free NMUtilsNamedValue *attrs_free = NULL; NMUtilsNamedValue attrs_static[30]; - const NMUtilsNamedValue * attrs; + const NMUtilsNamedValue *attrs; guint length; guint i; @@ -1370,10 +1370,10 @@ _qdiscs_to_variant(GPtrArray *qdiscs) if (qdiscs) { for (i = 0; i < qdiscs->len; i++) { - NMUtilsNamedValue attrs_static[30]; + NMUtilsNamedValue attrs_static[30]; gs_free NMUtilsNamedValue *attrs_free = NULL; - const NMUtilsNamedValue * attrs; - NMTCQdisc * qdisc = qdiscs->pdata[i]; + const NMUtilsNamedValue *attrs; + NMTCQdisc *qdisc = qdiscs->pdata[i]; guint length; GVariantBuilder qdisc_builder; guint y; @@ -1423,10 +1423,10 @@ _qdiscs_to_variant(GPtrArray *qdiscs) static GPtrArray * _qdiscs_from_variant(GVariant *value) { - GPtrArray * qdiscs; - GVariant * qdisc_var; + GPtrArray *qdiscs; + GVariant *qdisc_var; GVariantIter iter; - GError * error = NULL; + GError *error = NULL; g_return_val_if_fail(g_variant_is_of_type(value, G_VARIANT_TYPE("aa{sv}")), NULL); @@ -1434,12 +1434,12 @@ _qdiscs_from_variant(GVariant *value) qdiscs = g_ptr_array_new_with_free_func((GDestroyNotify) nm_tc_qdisc_unref); while (g_variant_iter_next(&iter, "@a{sv}", &qdisc_var)) { - const char * kind; + const char *kind; guint32 parent; - NMTCQdisc * qdisc; + NMTCQdisc *qdisc; GVariantIter qdisc_iter; - const char * key; - GVariant * attr_value; + const char *key; + GVariant *attr_value; if (!g_variant_lookup(qdisc_var, "kind", "&s", &kind) || !g_variant_lookup(qdisc_var, "parent", "u", &parent)) { @@ -1537,8 +1537,8 @@ _tfilters_to_variant(GPtrArray *tfilters) if (tfilters) { for (i = 0; i < tfilters->len; i++) { - NMTCTfilter * tfilter = tfilters->pdata[i]; - NMTCAction * action = nm_tc_tfilter_get_action(tfilter); + NMTCTfilter *tfilter = tfilters->pdata[i]; + NMTCAction *action = nm_tc_tfilter_get_action(tfilter); GVariantBuilder tfilter_builder; g_variant_builder_init(&tfilter_builder, G_VARIANT_TYPE("a{sv}")); @@ -1583,10 +1583,10 @@ _tfilters_to_variant(GPtrArray *tfilters) static GPtrArray * _tfilters_from_variant(GVariant *value) { - GPtrArray * tfilters; - GVariant * tfilter_var; + GPtrArray *tfilters; + GVariant *tfilter_var; GVariantIter iter; - GError * error = NULL; + GError *error = NULL; g_return_val_if_fail(g_variant_is_of_type(value, G_VARIANT_TYPE("aa{sv}")), NULL); @@ -1595,15 +1595,15 @@ _tfilters_from_variant(GVariant *value) while (g_variant_iter_next(&iter, "@a{sv}", &tfilter_var)) { NMTCTfilter *tfilter = NULL; - const char * kind; + const char *kind; guint32 handle; guint32 parent; - NMTCAction * action; - const char * action_kind = NULL; - char * action_key; + NMTCAction *action; + const char *action_kind = NULL; + char *action_key; GVariantIter action_iter; - GVariant * action_var = NULL; - GVariant * action_val; + GVariant *action_var = NULL; + GVariant *action_val; if (!g_variant_lookup(tfilter_var, "kind", "&s", &kind) || !g_variant_lookup(tfilter_var, "parent", "u", &parent)) { @@ -1767,9 +1767,9 @@ finalize(GObject *object) static void nm_setting_tc_config_class_init(NMSettingTCConfigClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); object_class->get_property = get_property; object_class->set_property = set_property; diff --git a/src/libnm-core-impl/nm-setting-team-port.c b/src/libnm-core-impl/nm-setting-team-port.c index 5e5f8910..816d85d9 100644 --- a/src/libnm-core-impl/nm-setting-team-port.c +++ b/src/libnm-core-impl/nm-setting-team-port.c @@ -313,7 +313,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) if (connection) { NMSettingConnection *s_con; - const char * slave_type; + const char *slave_type; s_con = nm_connection_get_setting_connection(connection); if (!s_con) { @@ -400,12 +400,12 @@ duplicate_copy_properties(const NMSettInfoSetting *sett_info, NMSetting *src, NM } static gboolean -init_from_dbus(NMSetting * setting, - GHashTable * keys, - GVariant * setting_dict, - GVariant * connection_dict, +init_from_dbus(NMSetting *setting, + GHashTable *keys, + GVariant *setting_dict, + GVariant *connection_dict, guint /* NMSettingParseFlags */ parse_flags, - GError ** error) + GError **error) { guint32 changed = 0; gboolean success; @@ -426,7 +426,7 @@ init_from_dbus(NMSetting * setting, static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMSettingTeamPort * setting = NM_SETTING_TEAM_PORT(object); + NMSettingTeamPort *setting = NM_SETTING_TEAM_PORT(object); NMSettingTeamPortPrivate *priv = NM_SETTING_TEAM_PORT_GET_PRIVATE(setting); switch (prop_id) { @@ -457,10 +457,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) { - NMSettingTeamPort * setting = NM_SETTING_TEAM_PORT(object); + NMSettingTeamPort *setting = NM_SETTING_TEAM_PORT(object); NMSettingTeamPortPrivate *priv = NM_SETTING_TEAM_PORT_GET_PRIVATE(setting); guint32 changed; - const GPtrArray * v_ptrarr; + const GPtrArray *v_ptrarr; switch (prop_id) { case NM_TEAM_ATTRIBUTE_CONFIG: @@ -528,9 +528,9 @@ finalize(GObject *object) static void nm_setting_team_port_class_init(NMSettingTeamPortClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingTeamPortPrivate)); diff --git a/src/libnm-core-impl/nm-setting-team.c b/src/libnm-core-impl/nm-setting-team.c index 1a11b043..3eeeb2c3 100644 --- a/src/libnm-core-impl/nm-setting-team.c +++ b/src/libnm-core-impl/nm-setting-team.c @@ -60,8 +60,8 @@ struct NMTeamLinkWatcher { int missed_max; } nsna_ping; struct { - const char * target_host; - const char * source_host; + const char *target_host; + const char *source_host; int init_wait; int interval; int missed_max; @@ -106,7 +106,7 @@ NMTeamLinkWatcher * nm_team_link_watcher_new_ethtool(int delay_up, int delay_down, GError **error) { NMTeamLinkWatcher *watcher; - const char * val_fail = NULL; + const char *val_fail = NULL; if (delay_up < 0 || !_NM_INT_LE_MAXINT32(delay_up)) val_fail = "delay-up"; @@ -156,11 +156,11 @@ nm_team_link_watcher_new_nsna_ping(int init_wait, int interval, int missed_max, const char *target_host, - GError ** error) + GError **error) { NMTeamLinkWatcher *watcher; - const char * val_fail = NULL; - char * str; + const char *val_fail = NULL; + char *str; gsize l_target_host; if (!target_host) { @@ -235,10 +235,10 @@ NMTeamLinkWatcher * nm_team_link_watcher_new_arp_ping(int init_wait, int interval, int missed_max, - const char * target_host, - const char * source_host, + const char *target_host, + const char *source_host, NMTeamLinkWatcherArpPingFlags flags, - GError ** error) + GError **error) { return nm_team_link_watcher_new_arp_ping2(init_wait, interval, @@ -274,14 +274,14 @@ nm_team_link_watcher_new_arp_ping2(int init_wait, int interval, int missed_max, int vlanid, - const char * target_host, - const char * source_host, + const char *target_host, + const char *source_host, NMTeamLinkWatcherArpPingFlags flags, - GError ** error) + GError **error) { NMTeamLinkWatcher *watcher; - const char * val_fail = NULL; - char * str; + const char *val_fail = NULL; + char *str; gsize l_target_host; gsize l_source_host; @@ -1016,7 +1016,7 @@ gboolean nm_setting_team_remove_runner_tx_hash_by_value(NMSettingTeam *setting, const char *txhash) { NMSettingTeamPrivate *priv = NM_SETTING_TEAM_GET_PRIVATE(setting); - const GPtrArray * arr; + const GPtrArray *arr; guint i; g_return_val_if_fail(NM_IS_SETTING_TEAM(setting), FALSE); @@ -1228,7 +1228,7 @@ nm_setting_team_remove_link_watcher(NMSettingTeam *setting, guint idx) * Since: 1.12 **/ gboolean -nm_setting_team_remove_link_watcher_by_value(NMSettingTeam * setting, +nm_setting_team_remove_link_watcher_by_value(NMSettingTeam *setting, NMTeamLinkWatcher *link_watcher) { g_return_val_if_fail(NM_IS_SETTING_TEAM(setting), FALSE); @@ -1325,12 +1325,12 @@ duplicate_copy_properties(const NMSettInfoSetting *sett_info, NMSetting *src, NM } static gboolean -init_from_dbus(NMSetting * setting, - GHashTable * keys, - GVariant * setting_dict, - GVariant * connection_dict, +init_from_dbus(NMSetting *setting, + GHashTable *keys, + GVariant *setting_dict, + GVariant *connection_dict, guint /* NMSettingParseFlags */ parse_flags, - GError ** error) + GError **error) { guint32 changed = 0; gboolean success; @@ -1353,9 +1353,9 @@ init_from_dbus(NMSetting * setting, static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMSettingTeam * setting = NM_SETTING_TEAM(object); + NMSettingTeam *setting = NM_SETTING_TEAM(object); NMSettingTeamPrivate *priv = NM_SETTING_TEAM_GET_PRIVATE(setting); - const GPtrArray * v_ptrarr; + const GPtrArray *v_ptrarr; switch (prop_id) { case NM_TEAM_ATTRIBUTE_CONFIG: @@ -1400,10 +1400,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) { - NMSettingTeam * setting = NM_SETTING_TEAM(object); + NMSettingTeam *setting = NM_SETTING_TEAM(object); NMSettingTeamPrivate *priv = NM_SETTING_TEAM_GET_PRIVATE(object); guint32 changed; - const GPtrArray * v_ptrarr; + const GPtrArray *v_ptrarr; switch (prop_id) { case NM_TEAM_ATTRIBUTE_CONFIG: @@ -1490,9 +1490,9 @@ finalize(GObject *object) static void nm_setting_team_class_init(NMSettingTeamClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingTeamPrivate)); diff --git a/src/libnm-core-impl/nm-setting-tun.c b/src/libnm-core-impl/nm-setting-tun.c index c2694847..ec095155 100644 --- a/src/libnm-core-impl/nm-setting-tun.c +++ b/src/libnm-core-impl/nm-setting-tun.c @@ -32,8 +32,8 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_MODE, PROP_MULTI_QUEUE, ); typedef struct { - char * owner; - char * group; + char *owner; + char *group; guint32 mode; bool pi; bool vnet_hdr; @@ -219,9 +219,9 @@ nm_setting_tun_new(void) static void nm_setting_tun_class_init(NMSettingTunClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingTunPrivate)); diff --git a/src/libnm-core-impl/nm-setting-user.c b/src/libnm-core-impl/nm-setting-user.c index 4068f337..0e95d38b 100644 --- a/src/libnm-core-impl/nm-setting-user.c +++ b/src/libnm-core-impl/nm-setting-user.c @@ -26,8 +26,8 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMSettingUser, PROP_DATA, ); typedef struct { - GHashTable * data; - GHashTable * data_invalid; + GHashTable *data; + GHashTable *data_invalid; const char **keys; } NMSettingUserPrivate; @@ -220,7 +220,7 @@ _create_data_hash(void) const char *const * nm_setting_user_get_keys(NMSettingUser *setting, guint *out_len) { - NMSettingUser * self = setting; + NMSettingUser *self = setting; NMSettingUserPrivate *priv; g_return_val_if_fail(NM_IS_SETTING_USER(self), NULL); @@ -276,7 +276,7 @@ nm_setting_user_get_data(NMSettingUser *setting, const char *key) gboolean nm_setting_user_set_data(NMSettingUser *setting, const char *key, const char *val, GError **error) { - NMSettingUser * self = setting; + NMSettingUser *self = setting; NMSettingUserPrivate *priv; gboolean changed = FALSE; @@ -340,12 +340,12 @@ out: static gboolean verify(NMSetting *setting, NMConnection *connection, GError **error) { - NMSettingUser * self = NM_SETTING_USER(setting); + NMSettingUser *self = NM_SETTING_USER(setting); NMSettingUserPrivate *priv = NM_SETTING_USER_GET_PRIVATE(self); if (priv->data_invalid) { - const char * key, *val; - GHashTableIter iter; + const char *key, *val; + GHashTableIter iter; gs_free_error GError *local = NULL; g_hash_table_iter_init(&iter, priv->data_invalid); @@ -411,11 +411,11 @@ compare_fcn_data(_NM_SETT_INFO_PROP_COMPARE_FCN_ARGS _nm_nil) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMSettingUser * self = NM_SETTING_USER(object); + NMSettingUser *self = NM_SETTING_USER(object); NMSettingUserPrivate *priv = NM_SETTING_USER_GET_PRIVATE(self); GHashTableIter iter; - GHashTable * data; - const char * key, *val; + GHashTable *data; + const char *key, *val; switch (prop_id) { case PROP_DATA: @@ -441,11 +441,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) { - NMSettingUser * self = NM_SETTING_USER(object); + NMSettingUser *self = NM_SETTING_USER(object); NMSettingUserPrivate *priv = NM_SETTING_USER_GET_PRIVATE(self); GHashTableIter iter; - GHashTable * data; - const char * key, *val; + GHashTable *data; + const char *key, *val; switch (prop_id) { case PROP_DATA: @@ -508,7 +508,7 @@ nm_setting_user_new(void) static void finalize(GObject *object) { - NMSettingUser * self = NM_SETTING_USER(object); + NMSettingUser *self = NM_SETTING_USER(object); NMSettingUserPrivate *priv = NM_SETTING_USER_GET_PRIVATE(self); g_free(priv->keys); @@ -523,9 +523,9 @@ finalize(GObject *object) static void nm_setting_user_class_init(NMSettingUserClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); object_class->get_property = get_property; object_class->set_property = set_property; @@ -576,5 +576,5 @@ nm_setting_user_class_init(NMSettingUserClass *klass) NM_META_SETTING_TYPE_USER, NULL, properties_override, - G_STRUCT_OFFSET(NMSettingUser, _priv)); + 0); } diff --git a/src/libnm-core-impl/nm-setting-veth.c b/src/libnm-core-impl/nm-setting-veth.c index 43d8da4f..40e3c961 100644 --- a/src/libnm-core-impl/nm-setting-veth.c +++ b/src/libnm-core-impl/nm-setting-veth.c @@ -63,6 +63,7 @@ const char * nm_setting_veth_get_peer(NMSettingVeth *setting) { g_return_val_if_fail(NM_IS_SETTING_VETH(setting), NULL); + return NM_SETTING_VETH_GET_PRIVATE(setting)->peer; } @@ -100,35 +101,6 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) /*****************************************************************************/ -static void -get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - NMSettingVeth * setting = NM_SETTING_VETH(object); - NMSettingVethPrivate *priv = NM_SETTING_VETH_GET_PRIVATE(setting); - - switch (prop_id) { - case PROP_PEER: - g_value_set_string(value, priv->peer); - break; - } -} - -static void -set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) -{ - NMSettingVeth * setting = NM_SETTING_VETH(object); - NMSettingVethPrivate *priv = NM_SETTING_VETH_GET_PRIVATE(setting); - - switch (prop_id) { - case PROP_PEER: - g_free(priv->peer); - priv->peer = g_value_dup_string(value); - break; - } -} - -/*****************************************************************************/ - static void nm_setting_veth_init(NMSettingVeth *setting) {} @@ -148,28 +120,15 @@ nm_setting_veth_new(void) return g_object_new(NM_TYPE_SETTING_VETH, NULL); } -static void -finalize(GObject *object) -{ - NMSettingVeth * setting = NM_SETTING_VETH(object); - NMSettingVethPrivate *priv = NM_SETTING_VETH_GET_PRIVATE(setting); - - g_free(priv->peer); - - G_OBJECT_CLASS(nm_setting_veth_parent_class)->finalize(object); -} - static void nm_setting_veth_class_init(NMSettingVethClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); - NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - - g_type_class_add_private(klass, sizeof(NMSettingVethPrivate)); + GObjectClass *object_class = G_OBJECT_CLASS(klass); + NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GArray *properties_override = _nm_sett_info_property_override_create_array(); - object_class->get_property = get_property; - object_class->set_property = set_property; - object_class->finalize = finalize; + object_class->get_property = _nm_setting_property_get_property_direct; + object_class->set_property = _nm_setting_property_set_property_direct; setting_class->verify = verify; @@ -181,14 +140,19 @@ nm_setting_veth_class_init(NMSettingVethClass *klass) * * Since: 1.30 **/ - obj_properties[PROP_PEER] = g_param_spec_string(NM_SETTING_VETH_PEER, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE - | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_VETH_PEER, + PROP_PEER, + NM_SETTING_PARAM_INFERRABLE, + NMSettingVeth, + _priv.peer); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_VETH, NULL, NULL, 0); + _nm_setting_class_commit(setting_class, + NM_META_SETTING_TYPE_VETH, + NULL, + properties_override, + 0); } diff --git a/src/libnm-core-impl/nm-setting-vlan.c b/src/libnm-core-impl/nm-setting-vlan.c index 1124953e..5f50acdd 100644 --- a/src/libnm-core-impl/nm-setting-vlan.c +++ b/src/libnm-core-impl/nm-setting-vlan.c @@ -36,7 +36,7 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMSettingVlan, typedef struct { GSList *ingress_priority_map; GSList *egress_priority_map; - char * parent; + char *parent; guint32 id; guint32 flags; } NMSettingVlanPrivate; @@ -77,6 +77,7 @@ const char * nm_setting_vlan_get_parent(NMSettingVlan *setting) { g_return_val_if_fail(NM_IS_SETTING_VLAN(setting), NULL); + return NM_SETTING_VLAN_GET_PRIVATE(setting)->parent; } @@ -197,7 +198,7 @@ set_map(NMSettingVlan *self, NMVlanPriorityMap map, GSList *list) static gboolean check_replace_duplicate_priority(GSList *list, guint32 from, guint32 to) { - GSList * iter; + GSList *iter; NMVlanQosMapping *p; for (iter = list; iter; iter = g_slist_next(iter)) { @@ -226,7 +227,7 @@ check_replace_duplicate_priority(GSList *list, guint32 from, guint32 to) gboolean nm_setting_vlan_add_priority_str(NMSettingVlan *setting, NMVlanPriorityMap map, const char *str) { - GSList * list = NULL; + GSList *list = NULL; NMVlanQosMapping *item = NULL; g_return_val_if_fail(NM_IS_SETTING_VLAN(setting), FALSE); @@ -287,14 +288,14 @@ nm_setting_vlan_get_num_priorities(NMSettingVlan *setting, NMVlanPriorityMap map * Returns: returns %TRUE if @idx is in range. Otherwise, %FALSE. **/ gboolean -nm_setting_vlan_get_priority(NMSettingVlan * setting, +nm_setting_vlan_get_priority(NMSettingVlan *setting, NMVlanPriorityMap map, guint32 idx, - guint32 * out_from, - guint32 * out_to) + guint32 *out_from, + guint32 *out_to) { NMVlanQosMapping *item; - GSList * list; + GSList *list; g_return_val_if_fail(NM_IS_SETTING_VLAN(setting), FALSE); g_return_val_if_fail(NM_IN_SET(map, NM_VLAN_INGRESS_MAP, NM_VLAN_EGRESS_MAP), FALSE); @@ -334,12 +335,12 @@ nm_setting_vlan_get_priority(NMSettingVlan * setting, * Returns: %TRUE. */ gboolean -nm_setting_vlan_add_priority(NMSettingVlan * setting, +nm_setting_vlan_add_priority(NMSettingVlan *setting, NMVlanPriorityMap map, guint32 from, guint32 to) { - GSList * list = NULL; + GSList *list = NULL; NMVlanQosMapping *item; g_return_val_if_fail(NM_IS_SETTING_VLAN(setting), FALSE); @@ -363,13 +364,13 @@ nm_setting_vlan_add_priority(NMSettingVlan * setting, } gboolean -_nm_setting_vlan_set_priorities(NMSettingVlan * setting, +_nm_setting_vlan_set_priorities(NMSettingVlan *setting, NMVlanPriorityMap map, const NMVlanQosMapping *qos_map, guint n_qos_map) { gboolean has_changes = FALSE; - GSList * map_prev, *map_new; + GSList *map_prev, *map_new; guint i; gint64 from_last; @@ -398,7 +399,7 @@ _nm_setting_vlan_set_priorities(NMSettingVlan * setting, from_last = G_MAXINT64; for (i = n_qos_map; i > 0;) { const NMVlanQosMapping *m = &qos_map[--i]; - NMVlanQosMapping * item; + NMVlanQosMapping *item; /* We require the array to be presorted. */ if (m->from >= from_last) @@ -418,12 +419,12 @@ _nm_setting_vlan_set_priorities(NMSettingVlan * setting, } void -_nm_setting_vlan_get_priorities(NMSettingVlan * setting, +_nm_setting_vlan_get_priorities(NMSettingVlan *setting, NMVlanPriorityMap map, NMVlanQosMapping **out_qos_map, - guint * out_n_qos_map) + guint *out_n_qos_map) { - GSList * list; + GSList *list; NMVlanQosMapping *qos_map = NULL; guint n_qos_map, i; @@ -470,13 +471,13 @@ nm_setting_vlan_remove_priority(NMSettingVlan *setting, NMVlanPriorityMap map, g } static gboolean -priority_map_remove_by_value(NMSettingVlan * setting, +priority_map_remove_by_value(NMSettingVlan *setting, NMVlanPriorityMap map, guint32 from, guint32 to, gboolean wildcard_to) { - GSList * list = NULL, *iter = NULL; + GSList *list = NULL, *iter = NULL; NMVlanQosMapping *item; nm_assert(NM_IS_SETTING_VLAN(setting)); @@ -512,7 +513,7 @@ priority_map_remove_by_value(NMSettingVlan * setting, * Returns: %TRUE if the priority mapping was found and removed; %FALSE if it was not. */ gboolean -nm_setting_vlan_remove_priority_by_value(NMSettingVlan * setting, +nm_setting_vlan_remove_priority_by_value(NMSettingVlan *setting, NMVlanPriorityMap map, guint32 from, guint32 to) @@ -536,9 +537,9 @@ nm_setting_vlan_remove_priority_by_value(NMSettingVlan * setting, * Returns: %TRUE if the priority mapping was found and removed; %FALSE if it was not. */ gboolean -nm_setting_vlan_remove_priority_str_by_value(NMSettingVlan * setting, +nm_setting_vlan_remove_priority_str_by_value(NMSettingVlan *setting, NMVlanPriorityMap map, - const char * str) + const char *str) { gboolean is_wildcard_to; guint32 from, to; @@ -578,8 +579,8 @@ static int verify(NMSetting *setting, NMConnection *connection, GError **error) { NMSettingVlanPrivate *priv = NM_SETTING_VLAN_GET_PRIVATE(setting); - NMSettingConnection * s_con; - NMSettingWired * s_wired; + NMSettingConnection *s_con; + NMSettingWired *s_wired; if (connection) { s_con = nm_connection_get_setting_connection(connection); @@ -712,7 +713,7 @@ priority_strv_to_maplist(NMVlanPriorityMap map, char **strv) static char ** priority_maplist_to_strv(GSList *list) { - GSList * iter; + GSList *iter; GPtrArray *strv; strv = g_ptr_array_new(); @@ -732,13 +733,10 @@ priority_maplist_to_strv(GSList *list) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMSettingVlan * setting = NM_SETTING_VLAN(object); + NMSettingVlan *setting = NM_SETTING_VLAN(object); NMSettingVlanPrivate *priv = NM_SETTING_VLAN_GET_PRIVATE(setting); switch (prop_id) { - case PROP_PARENT: - g_value_set_string(value, priv->parent); - break; case PROP_FLAGS: g_value_set_flags(value, priv->flags); break; @@ -757,14 +755,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) { - NMSettingVlan * setting = NM_SETTING_VLAN(object); + NMSettingVlan *setting = NM_SETTING_VLAN(object); NMSettingVlanPrivate *priv = NM_SETTING_VLAN_GET_PRIVATE(setting); switch (prop_id) { - case PROP_PARENT: - g_free(priv->parent); - priv->parent = g_value_dup_string(value); - break; case PROP_FLAGS: priv->flags = g_value_get_flags(value); break; @@ -810,10 +804,9 @@ nm_setting_vlan_new(void) static void finalize(GObject *object) { - NMSettingVlan * setting = NM_SETTING_VLAN(object); + NMSettingVlan *setting = NM_SETTING_VLAN(object); NMSettingVlanPrivate *priv = NM_SETTING_VLAN_GET_PRIVATE(setting); - g_free(priv->parent); g_slist_free_full(priv->ingress_priority_map, g_free); g_slist_free_full(priv->egress_priority_map, g_free); @@ -823,9 +816,9 @@ finalize(GObject *object) static void nm_setting_vlan_class_init(NMSettingVlanClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingVlanPrivate)); @@ -849,12 +842,13 @@ nm_setting_vlan_class_init(NMSettingVlanClass *klass) * description: Parent interface of the VLAN. * ---end--- */ - obj_properties[PROP_PARENT] = g_param_spec_string( - NM_SETTING_VLAN_PARENT, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_VLAN_PARENT, + PROP_PARENT, + NM_SETTING_PARAM_INFERRABLE, + NMSettingVlanPrivate, + parent); /** * NMSettingVlan:id: diff --git a/src/libnm-core-impl/nm-setting-vpn.c b/src/libnm-core-impl/nm-setting-vpn.c index a543051b..42f75fa2 100644 --- a/src/libnm-core-impl/nm-setting-vpn.c +++ b/src/libnm-core-impl/nm-setting-vpn.c @@ -65,7 +65,6 @@ typedef struct { */ GHashTable *secrets; - /* Timeout for the VPN service to establish the connection */ guint32 timeout; /* Whether the VPN stays up across link changes, until the user @@ -272,7 +271,7 @@ static void foreach_item_helper(NMSettingVpn *self, GHashTable **p_hash, NMVpnIterFunc func, gpointer user_data) { gs_unref_object NMSettingVpn *self_keep_alive = NULL; - gs_strfreev char ** keys = NULL; + gs_strfreev char **keys = NULL; guint i, len; nm_assert(NM_IS_SETTING_VPN(self)); @@ -457,10 +456,10 @@ nm_setting_vpn_foreach_secret(NMSettingVpn *setting, NMVpnIterFunc func, gpointe static gboolean aggregate(NMSetting *setting, int type_i, gpointer arg) { - NMSettingVpnPrivate * priv = NM_SETTING_VPN_GET_PRIVATE(setting); + NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE(setting); NMConnectionAggregateType type = type_i; NMSettingSecretFlags secret_flags; - const char * key_name; + const char *key_name; GHashTableIter iter; switch (type) { @@ -597,9 +596,9 @@ update_secret_string(NMSetting *setting, const char *key, const char *value, GEr static NMSettingUpdateSecretResult update_secret_dict(NMSetting *setting, GVariant *secrets, GError **error) { - NMSettingVpnPrivate * priv = NM_SETTING_VPN_GET_PRIVATE(setting); + NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE(setting); GVariantIter iter; - const char * name, *value; + const char *name, *value; NMSettingUpdateSecretResult result = NM_SETTING_UPDATE_SECRET_SUCCESS_UNCHANGED; g_return_val_if_fail(secrets != NULL, NM_SETTING_UPDATE_SECRET_ERROR); @@ -669,18 +668,18 @@ update_one_secret(NMSetting *setting, const char *key, GVariant *value, GError * } static void -for_each_secret(NMSetting * setting, - const char * secret_name, - GVariant * val, +for_each_secret(NMSetting *setting, + const char *secret_name, + GVariant *val, gboolean remove_non_secrets, _NMConnectionForEachSecretFunc callback, gpointer callback_data, - GVariantBuilder * setting_builder) + GVariantBuilder *setting_builder) { GVariantBuilder vpn_secrets_builder; GVariantIter vpn_secrets_iter; - const char * vpn_secret_name; - const char * secret; + const char *vpn_secret_name; + const char *secret; if (!nm_streq(secret_name, NM_SETTING_VPN_SECRETS)) { NM_SETTING_CLASS(nm_setting_vpn_parent_class) @@ -723,15 +722,15 @@ for_each_secret(NMSetting * setting, } static gboolean -get_secret_flags(NMSetting * setting, - const char * secret_name, +get_secret_flags(NMSetting *setting, + const char *secret_name, NMSettingSecretFlags *out_flags, - GError ** error) + GError **error) { NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE(setting); - gs_free char * flags_key_free = NULL; - const char * flags_key; - const char * flags_val; + gs_free char *flags_key_free = NULL; + const char *flags_key; + const char *flags_val; gint64 i64; nm_assert(secret_name); @@ -779,10 +778,10 @@ get_secret_flags(NMSetting * setting, } static gboolean -set_secret_flags(NMSetting * setting, - const char * secret_name, +set_secret_flags(NMSetting *setting, + const char *secret_name, NMSettingSecretFlags flags, - GError ** error) + GError **error) { nm_assert(secret_name); @@ -812,7 +811,7 @@ static NMTernary compare_property_secrets(NMSettingVpn *a, NMSettingVpn *b, NMSettingCompareFlags flags) { GHashTableIter iter; - const char * key, *val; + const char *key, *val; int run; if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_FUZZY)) @@ -824,8 +823,8 @@ compare_property_secrets(NMSettingVpn *a, NMSettingVpn *b, NMSettingCompareFlags return TRUE; for (run = 0; run < 2; run++) { - NMSettingVpn * current_a = (run == 0) ? a : b; - NMSettingVpn * current_b = (run == 0) ? b : a; + NMSettingVpn *current_a = (run == 0) ? a : b; + NMSettingVpn *current_b = (run == 0) ? b : a; NMSettingVpnPrivate *priv_a = NM_SETTING_VPN_GET_PRIVATE(current_a); if (!priv_a->secrets) @@ -857,15 +856,15 @@ compare_fcn_secrets(_NM_SETT_INFO_PROP_COMPARE_FCN_ARGS _nm_nil) } static gboolean -clear_secrets(const NMSettInfoSetting * sett_info, - const NMSettInfoProperty * property_info, - NMSetting * setting, +clear_secrets(const NMSettInfoSetting *sett_info, + const NMSettInfoProperty *property_info, + NMSetting *setting, NMSettingClearSecretsWithFlagsFn func, gpointer user_data) { NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE(setting); GHashTableIter iter; - const char * secret; + const char *secret; gboolean changed = TRUE; if (!property_info->param_spec @@ -903,12 +902,12 @@ clear_secrets(const NMSettInfoSetting * sett_info, static gboolean vpn_secrets_from_dbus(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) { - NMSettingVpn * self = NM_SETTING_VPN(setting); - NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE(self); + NMSettingVpn *self = NM_SETTING_VPN(setting); + NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE(self); gs_unref_hashtable GHashTable *hash_free = NULL; GVariantIter iter; - const char * key; - const char * val; + const char *key; + const char *val; hash_free = g_steal_pointer(&priv->secrets); @@ -943,7 +942,7 @@ vpn_secrets_to_dbus(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) keys = nm_strdict_get_keys(priv->secrets, TRUE, &len); for (i = 0; i < len; i++) { - const char * key = keys[i]; + const char *key = keys[i]; NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE; if (NM_FLAGS_ANY(flags, @@ -966,30 +965,18 @@ vpn_secrets_to_dbus(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMSettingVpn * setting = NM_SETTING_VPN(object); + NMSettingVpn *setting = NM_SETTING_VPN(object); NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE(setting); switch (prop_id) { - case PROP_SERVICE_TYPE: - g_value_set_string(value, nm_setting_vpn_get_service_type(setting)); - break; - case PROP_USER_NAME: - g_value_set_string(value, nm_setting_vpn_get_user_name(setting)); - break; - case PROP_PERSISTENT: - g_value_set_boolean(value, priv->persistent); - break; case PROP_DATA: g_value_take_boxed(value, _nm_utils_copy_strdict(priv->data)); break; case PROP_SECRETS: g_value_take_boxed(value, _nm_utils_copy_strdict(priv->secrets)); break; - case PROP_TIMEOUT: - g_value_set_uint(value, nm_setting_vpn_get_timeout(setting)); - break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + _nm_setting_property_get_property_direct(object, prop_id, value, pspec); break; } } @@ -1000,23 +987,12 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE(object); switch (prop_id) { - case PROP_SERVICE_TYPE: - g_free(priv->service_type); - priv->service_type = g_value_dup_string(value); - break; - case PROP_USER_NAME: - g_free(priv->user_name); - priv->user_name = g_value_dup_string(value); - break; - case PROP_PERSISTENT: - priv->persistent = g_value_get_boolean(value); - break; case PROP_DATA: case PROP_SECRETS: { gs_unref_hashtable GHashTable *hash_free = NULL; - GHashTable * src_hash = g_value_get_boxed(value); - GHashTable ** p_hash; + GHashTable *src_hash = g_value_get_boxed(value); + GHashTable **p_hash; const gboolean is_secrets = (prop_id == PROP_SECRETS); if (is_secrets) @@ -1028,8 +1004,8 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps if (src_hash && g_hash_table_size(src_hash) > 0) { GHashTableIter iter; - const char * key; - const char * val; + const char *key; + const char *val; g_hash_table_iter_init(&iter, src_hash); while (g_hash_table_iter_next(&iter, (gpointer *) &key, (gpointer *) &val)) { @@ -1046,11 +1022,8 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps } } } break; - case PROP_TIMEOUT: - priv->timeout = g_value_get_uint(value); - break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + _nm_setting_property_set_property_direct(object, prop_id, value, pspec); break; } } @@ -1079,12 +1052,8 @@ finalize(GObject *object) { NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE(object); - g_free(priv->service_type); - g_free(priv->user_name); - if (priv->data) - g_hash_table_unref(priv->data); - if (priv->secrets) - g_hash_table_unref(priv->secrets); + nm_g_hash_table_unref(priv->data); + nm_g_hash_table_unref(priv->secrets); G_OBJECT_CLASS(nm_setting_vpn_parent_class)->finalize(object); } @@ -1092,9 +1061,9 @@ finalize(GObject *object) static void nm_setting_vpn_class_init(NMSettingVpnClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingVpnPrivate)); @@ -1118,12 +1087,13 @@ nm_setting_vpn_class_init(NMSettingVpnClass *klass) * its network. i.e. org.freedesktop.NetworkManager.vpnc for the vpnc * plugin. **/ - obj_properties[PROP_SERVICE_TYPE] = - g_param_spec_string(NM_SETTING_VPN_SERVICE_TYPE, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_VPN_SERVICE_TYPE, + PROP_SERVICE_TYPE, + NM_SETTING_PARAM_NONE, + NMSettingVpnPrivate, + service_type); /** * NMSettingVpn:user-name: @@ -1135,12 +1105,13 @@ nm_setting_vpn_class_init(NMSettingVpnClass *klass) * will automatically supply the username of the user which requested the * VPN connection. **/ - obj_properties[PROP_USER_NAME] = - g_param_spec_string(NM_SETTING_VPN_USER_NAME, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_VPN_USER_NAME, + PROP_USER_NAME, + NM_SETTING_PARAM_NONE, + NMSettingVpnPrivate, + user_name); /** * NMSettingVpn:persistent: @@ -1221,13 +1192,16 @@ nm_setting_vpn_class_init(NMSettingVpnClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_TIMEOUT] = g_param_spec_uint(NM_SETTING_VPN_TIMEOUT, - "", - "", - 0, - G_MAXUINT32, - 0, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_VPN_TIMEOUT, + PROP_TIMEOUT, + 0, + G_MAXUINT32, + 0, + NM_SETTING_PARAM_NONE, + NMSettingVpnPrivate, + timeout); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-vrf.c b/src/libnm-core-impl/nm-setting-vrf.c index f998a7dd..4588149f 100644 --- a/src/libnm-core-impl/nm-setting-vrf.c +++ b/src/libnm-core-impl/nm-setting-vrf.c @@ -102,9 +102,9 @@ nm_setting_vrf_new(void) static void nm_setting_vrf_class_init(NMSettingVrfClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); object_class->get_property = _nm_setting_property_get_property_direct; object_class->set_property = _nm_setting_property_set_property_direct; diff --git a/src/libnm-core-impl/nm-setting-vxlan.c b/src/libnm-core-impl/nm-setting-vxlan.c index c2d23a7f..f617a073 100644 --- a/src/libnm-core-impl/nm-setting-vxlan.c +++ b/src/libnm-core-impl/nm-setting-vxlan.c @@ -42,22 +42,22 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_PARENT, PROP_L3_MISS, ); typedef struct { - char *parent; - char *local; - char *remote; - guint id; - guint source_port_min; - guint source_port_max; - guint destination_port; - guint tos; - guint ttl; - guint ageing; - guint limit; - bool proxy; - bool learning; - bool rsc; - bool l2_miss; - bool l3_miss; + char *parent; + char *local; + char *remote; + guint32 id; + guint32 source_port_min; + guint32 source_port_max; + guint32 destination_port; + guint32 tos; + guint32 ttl; + guint32 ageing; + guint32 limit; + bool proxy; + bool learning; + bool rsc; + bool l2_miss; + bool l3_miss; } NMSettingVxlanPrivate; /** @@ -95,6 +95,7 @@ const char * nm_setting_vxlan_get_parent(NMSettingVxlan *setting) { g_return_val_if_fail(NM_IS_SETTING_VXLAN(setting), NULL); + return NM_SETTING_VXLAN_GET_PRIVATE(setting)->parent; } @@ -110,6 +111,7 @@ guint nm_setting_vxlan_get_id(NMSettingVxlan *setting) { g_return_val_if_fail(NM_IS_SETTING_VXLAN(setting), 0); + return NM_SETTING_VXLAN_GET_PRIVATE(setting)->id; } @@ -125,6 +127,7 @@ const char * nm_setting_vxlan_get_local(NMSettingVxlan *setting) { g_return_val_if_fail(NM_IS_SETTING_VXLAN(setting), NULL); + return NM_SETTING_VXLAN_GET_PRIVATE(setting)->local; } @@ -140,6 +143,7 @@ const char * nm_setting_vxlan_get_remote(NMSettingVxlan *setting) { g_return_val_if_fail(NM_IS_SETTING_VXLAN(setting), NULL); + return NM_SETTING_VXLAN_GET_PRIVATE(setting)->remote; } @@ -155,6 +159,7 @@ guint nm_setting_vxlan_get_source_port_min(NMSettingVxlan *setting) { g_return_val_if_fail(NM_IS_SETTING_VXLAN(setting), 0); + return NM_SETTING_VXLAN_GET_PRIVATE(setting)->source_port_min; } @@ -170,6 +175,7 @@ guint nm_setting_vxlan_get_source_port_max(NMSettingVxlan *setting) { g_return_val_if_fail(NM_IS_SETTING_VXLAN(setting), 0); + return NM_SETTING_VXLAN_GET_PRIVATE(setting)->source_port_max; } @@ -185,6 +191,7 @@ guint nm_setting_vxlan_get_destination_port(NMSettingVxlan *setting) { g_return_val_if_fail(NM_IS_SETTING_VXLAN(setting), DST_PORT_DEFAULT); + return NM_SETTING_VXLAN_GET_PRIVATE(setting)->destination_port; } @@ -215,6 +222,7 @@ guint nm_setting_vxlan_get_ageing(NMSettingVxlan *setting) { g_return_val_if_fail(NM_IS_SETTING_VXLAN(setting), 0); + return NM_SETTING_VXLAN_GET_PRIVATE(setting)->ageing; } @@ -230,6 +238,7 @@ guint nm_setting_vxlan_get_limit(NMSettingVxlan *setting) { g_return_val_if_fail(NM_IS_SETTING_VXLAN(setting), 0); + return NM_SETTING_VXLAN_GET_PRIVATE(setting)->limit; } @@ -245,6 +254,7 @@ guint nm_setting_vxlan_get_tos(NMSettingVxlan *setting) { g_return_val_if_fail(NM_IS_SETTING_VXLAN(setting), 0); + return NM_SETTING_VXLAN_GET_PRIVATE(setting)->tos; } @@ -260,6 +270,7 @@ guint nm_setting_vxlan_get_ttl(NMSettingVxlan *setting) { g_return_val_if_fail(NM_IS_SETTING_VXLAN(setting), 0); + return NM_SETTING_VXLAN_GET_PRIVATE(setting)->ttl; } @@ -391,152 +402,9 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) /*****************************************************************************/ -static void -_addrstr_set(char **dst, const char *src) -{ - gs_free char *old = NULL; - - old = *dst; - if (!src) - *dst = NULL; - else if (!nm_utils_parse_inaddr(AF_UNSPEC, src, dst)) - *dst = g_strdup(src); -} -/*****************************************************************************/ - -static void -get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - NMSettingVxlan * setting = NM_SETTING_VXLAN(object); - NMSettingVxlanPrivate *priv = NM_SETTING_VXLAN_GET_PRIVATE(setting); - - switch (prop_id) { - case PROP_PARENT: - g_value_set_string(value, priv->parent); - break; - case PROP_ID: - g_value_set_uint(value, priv->id); - break; - case PROP_LOCAL: - g_value_set_string(value, priv->local); - break; - case PROP_REMOTE: - g_value_set_string(value, priv->remote); - break; - case PROP_SOURCE_PORT_MIN: - g_value_set_uint(value, priv->source_port_min); - break; - case PROP_SOURCE_PORT_MAX: - g_value_set_uint(value, priv->source_port_max); - break; - case PROP_DESTINATION_PORT: - g_value_set_uint(value, priv->destination_port); - break; - case PROP_TOS: - g_value_set_uint(value, priv->tos); - break; - case PROP_AGEING: - g_value_set_uint(value, priv->ageing); - break; - case PROP_LIMIT: - g_value_set_uint(value, priv->limit); - break; - case PROP_PROXY: - g_value_set_boolean(value, priv->proxy); - break; - case PROP_TTL: - g_value_set_uint(value, priv->ttl); - break; - case PROP_LEARNING: - g_value_set_boolean(value, priv->learning); - break; - case PROP_RSC: - g_value_set_boolean(value, priv->rsc); - break; - case PROP_L2_MISS: - g_value_set_boolean(value, priv->l2_miss); - break; - case PROP_L3_MISS: - g_value_set_boolean(value, priv->l3_miss); - 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) -{ - NMSettingVxlan * setting = NM_SETTING_VXLAN(object); - NMSettingVxlanPrivate *priv = NM_SETTING_VXLAN_GET_PRIVATE(setting); - - switch (prop_id) { - case PROP_PARENT: - g_free(priv->parent); - priv->parent = g_value_dup_string(value); - break; - case PROP_ID: - priv->id = g_value_get_uint(value); - break; - case PROP_LOCAL: - _addrstr_set(&priv->local, g_value_get_string(value)); - break; - case PROP_REMOTE: - _addrstr_set(&priv->remote, g_value_get_string(value)); - break; - case PROP_SOURCE_PORT_MIN: - priv->source_port_min = g_value_get_uint(value); - break; - case PROP_SOURCE_PORT_MAX: - priv->source_port_max = g_value_get_uint(value); - break; - case PROP_DESTINATION_PORT: - priv->destination_port = g_value_get_uint(value); - break; - case PROP_TOS: - priv->tos = g_value_get_uint(value); - break; - case PROP_AGEING: - priv->ageing = g_value_get_uint(value); - break; - case PROP_LIMIT: - priv->limit = g_value_get_uint(value); - break; - case PROP_PROXY: - priv->proxy = g_value_get_boolean(value); - break; - case PROP_TTL: - priv->ttl = g_value_get_uint(value); - break; - case PROP_LEARNING: - priv->learning = g_value_get_boolean(value); - break; - case PROP_RSC: - priv->rsc = g_value_get_boolean(value); - break; - case PROP_L2_MISS: - priv->l2_miss = g_value_get_boolean(value); - break; - case PROP_L3_MISS: - priv->l3_miss = g_value_get_boolean(value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } -} - -/*****************************************************************************/ - static void nm_setting_vxlan_init(NMSettingVxlan *self) -{ - NMSettingVxlanPrivate *priv = NM_SETTING_VXLAN_GET_PRIVATE(self); - - priv->destination_port = DST_PORT_DEFAULT; - priv->ageing = 300; -} +{} /** * nm_setting_vxlan_new: @@ -553,31 +421,17 @@ nm_setting_vxlan_new(void) return g_object_new(NM_TYPE_SETTING_VXLAN, NULL); } -static void -finalize(GObject *object) -{ - NMSettingVxlan * setting = NM_SETTING_VXLAN(object); - NMSettingVxlanPrivate *priv = NM_SETTING_VXLAN_GET_PRIVATE(setting); - - g_free(priv->parent); - g_free(priv->local); - g_free(priv->remote); - - G_OBJECT_CLASS(nm_setting_vxlan_parent_class)->finalize(object); -} - static void nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingVxlanPrivate)); - object_class->get_property = get_property; - object_class->set_property = set_property; - object_class->finalize = finalize; + object_class->get_property = _nm_setting_property_get_property_direct; + object_class->set_property = _nm_setting_property_set_property_direct; setting_class->verify = verify; @@ -588,12 +442,13 @@ nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_PARENT] = g_param_spec_string( - NM_SETTING_VXLAN_PARENT, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_VXLAN_PARENT, + PROP_PARENT, + NM_SETTING_PARAM_INFERRABLE, + NMSettingVxlanPrivate, + parent); /** * NMSettingVxlan:id: @@ -603,14 +458,16 @@ nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_ID] = - g_param_spec_uint(NM_SETTING_VXLAN_ID, - "", - "", - 0, - (1 << 24) - 1, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_VXLAN_ID, + PROP_ID, + 0, + (1 << 24) - 1, + 0, + NM_SETTING_PARAM_INFERRABLE, + NMSettingVxlanPrivate, + id); /** * NMSettingVxlan:local: @@ -619,12 +476,15 @@ nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_LOCAL] = g_param_spec_string(NM_SETTING_VXLAN_LOCAL, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE - | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_VXLAN_LOCAL, + PROP_LOCAL, + NM_SETTING_PARAM_INFERRABLE, + NMSettingVxlanPrivate, + local, + .direct_set_string_ip_address_addr_family = + AF_UNSPEC + 1); /** * NMSettingVxlan:remote: @@ -635,12 +495,15 @@ nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_REMOTE] = g_param_spec_string( - NM_SETTING_VXLAN_REMOTE, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_VXLAN_REMOTE, + PROP_REMOTE, + NM_SETTING_PARAM_INFERRABLE, + NMSettingVxlanPrivate, + remote, + .direct_set_string_ip_address_addr_family = + AF_UNSPEC + 1); /** * NMSettingVxlan:source-port-min: @@ -650,14 +513,16 @@ nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_SOURCE_PORT_MIN] = - g_param_spec_uint(NM_SETTING_VXLAN_SOURCE_PORT_MIN, - "", - "", - 0, - G_MAXUINT16, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_VXLAN_SOURCE_PORT_MIN, + PROP_SOURCE_PORT_MIN, + 0, + G_MAXUINT16, + 0, + NM_SETTING_PARAM_INFERRABLE, + NMSettingVxlanPrivate, + source_port_min); /** * NMSettingVxlan:source-port-max: @@ -667,14 +532,16 @@ nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_SOURCE_PORT_MAX] = - g_param_spec_uint(NM_SETTING_VXLAN_SOURCE_PORT_MAX, - "", - "", - 0, - G_MAXUINT16, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_VXLAN_SOURCE_PORT_MAX, + PROP_SOURCE_PORT_MAX, + 0, + G_MAXUINT16, + 0, + NM_SETTING_PARAM_INFERRABLE, + NMSettingVxlanPrivate, + source_port_max); /** * NMSettingVxlan:destination-port: @@ -684,14 +551,16 @@ nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_DESTINATION_PORT] = - g_param_spec_uint(NM_SETTING_VXLAN_DESTINATION_PORT, - "", - "", - 0, - G_MAXUINT16, - DST_PORT_DEFAULT, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_VXLAN_DESTINATION_PORT, + PROP_DESTINATION_PORT, + 0, + G_MAXUINT16, + DST_PORT_DEFAULT, + NM_SETTING_PARAM_INFERRABLE, + NMSettingVxlanPrivate, + destination_port); /** * NMSettingVxlan:ageing: @@ -700,14 +569,16 @@ nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_AGEING] = - g_param_spec_uint(NM_SETTING_VXLAN_AGEING, - "", - "", - 0, - G_MAXUINT32, - 300, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_VXLAN_AGEING, + PROP_AGEING, + 0, + G_MAXUINT32, + 300, + NM_SETTING_PARAM_INFERRABLE, + NMSettingVxlanPrivate, + ageing); /** * NMSettingVxlan:limit: @@ -717,14 +588,16 @@ nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_LIMIT] = - g_param_spec_uint(NM_SETTING_VXLAN_LIMIT, - "", - "", - 0, - G_MAXUINT32, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_VXLAN_LIMIT, + PROP_LIMIT, + 0, + G_MAXUINT32, + 0, + NM_SETTING_PARAM_INFERRABLE, + NMSettingVxlanPrivate, + limit); /** * NMSettingVxlan:tos: @@ -733,14 +606,16 @@ nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_TOS] = - g_param_spec_uint(NM_SETTING_VXLAN_TOS, - "", - "", - 0, - 255, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_VXLAN_TOS, + PROP_TOS, + 0, + 255, + 0, + NM_SETTING_PARAM_INFERRABLE, + NMSettingVxlanPrivate, + tos); /** * NMSettingVxlan:ttl: @@ -749,14 +624,16 @@ nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_TTL] = - g_param_spec_uint(NM_SETTING_VXLAN_TTL, - "", - "", - 0, - 255, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_VXLAN_TTL, + PROP_TTL, + 0, + 255, + 0, + NM_SETTING_PARAM_INFERRABLE, + NMSettingVxlanPrivate, + ttl); /** * NMSettingVxlan:proxy: diff --git a/src/libnm-core-impl/nm-setting-wifi-p2p.c b/src/libnm-core-impl/nm-setting-wifi-p2p.c index 06d450fc..e8ce4bdc 100644 --- a/src/libnm-core-impl/nm-setting-wifi-p2p.c +++ b/src/libnm-core-impl/nm-setting-wifi-p2p.c @@ -35,7 +35,7 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_PEER, PROP_WPS_METHOD, PROP_WFD_IES, ); typedef struct { - char * peer; + char *peer; GBytes *wfd_ies; guint32 wps_method; } NMSettingWifiP2PPrivate; @@ -170,9 +170,9 @@ nm_setting_wifi_p2p_new(void) static void nm_setting_wifi_p2p_class_init(NMSettingWifiP2PClass *setting_wifi_p2p_class) { - GObjectClass * object_class = G_OBJECT_CLASS(setting_wifi_p2p_class); + GObjectClass *object_class = G_OBJECT_CLASS(setting_wifi_p2p_class); NMSettingClass *setting_class = NM_SETTING_CLASS(setting_wifi_p2p_class); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); object_class->get_property = _nm_setting_property_get_property_direct; object_class->set_property = _nm_setting_property_set_property_direct; diff --git a/src/libnm-core-impl/nm-setting-wimax.c b/src/libnm-core-impl/nm-setting-wimax.c index f7fed08e..1e2b51c3 100644 --- a/src/libnm-core-impl/nm-setting-wimax.c +++ b/src/libnm-core-impl/nm-setting-wimax.c @@ -101,23 +101,12 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) { NMSettingWimaxPrivate *priv = NM_SETTING_WIMAX_GET_PRIVATE(setting); - if (!priv->network_name) { + if (nm_str_is_empty(priv->network_name)) { g_set_error_literal(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_MISSING_PROPERTY, - _("property is missing")); - g_prefix_error(error, - "%s.%s: ", - NM_SETTING_WIMAX_SETTING_NAME, - NM_SETTING_WIMAX_NETWORK_NAME); - return FALSE; - } - - if (!strlen(priv->network_name)) { - g_set_error_literal(error, - NM_CONNECTION_ERROR, - NM_CONNECTION_ERROR_INVALID_PROPERTY, - _("property is empty")); + !priv->network_name ? _("property is missing") + : _("property is empty")); g_prefix_error(error, "%s.%s: ", NM_SETTING_WIMAX_SETTING_NAME, @@ -142,47 +131,6 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) /*****************************************************************************/ -static void -get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - NMSettingWimax *setting = NM_SETTING_WIMAX(object); - - switch (prop_id) { - case PROP_NETWORK_NAME: - g_value_set_string(value, nm_setting_wimax_get_network_name(setting)); - break; - case PROP_MAC_ADDRESS: - g_value_set_string(value, nm_setting_wimax_get_mac_address(setting)); - 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) -{ - NMSettingWimaxPrivate *priv = NM_SETTING_WIMAX_GET_PRIVATE(object); - - switch (prop_id) { - case PROP_NETWORK_NAME: - g_free(priv->network_name); - priv->network_name = g_value_dup_string(value); - break; - case PROP_MAC_ADDRESS: - g_free(priv->mac_address); - priv->mac_address = - _nm_utils_hwaddr_canonical_or_invalid(g_value_get_string(value), ETH_ALEN); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } -} - -/*****************************************************************************/ - static void nm_setting_wimax_init(NMSettingWimax *setting) {} @@ -202,28 +150,17 @@ nm_setting_wimax_new(void) return g_object_new(NM_TYPE_SETTING_WIMAX, NULL); } -static void -finalize(GObject *object) -{ - NMSettingWimaxPrivate *priv = NM_SETTING_WIMAX_GET_PRIVATE(object); - - g_free(priv->network_name); - - G_OBJECT_CLASS(nm_setting_wimax_parent_class)->finalize(object); -} - static void nm_setting_wimax_class_init(NMSettingWimaxClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingWimaxPrivate)); - object_class->get_property = get_property; - object_class->set_property = set_property; - object_class->finalize = finalize; + object_class->get_property = _nm_setting_property_get_property_direct; + object_class->set_property = _nm_setting_property_set_property_direct; setting_class->verify = verify; @@ -235,12 +172,13 @@ nm_setting_wimax_class_init(NMSettingWimaxClass *klass) * * Deprecated: 1.2: WiMAX is no longer supported. **/ - obj_properties[PROP_NETWORK_NAME] = - g_param_spec_string(NM_SETTING_WIMAX_NETWORK_NAME, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_WIMAX_NETWORK_NAME, + PROP_NETWORK_NAME, + NM_SETTING_PARAM_NONE, + NMSettingWimaxPrivate, + network_name); /** * NMSettingWimax:mac-address: diff --git a/src/libnm-core-impl/nm-setting-wired.c b/src/libnm-core-impl/nm-setting-wired.c index 8c9bdcd4..830b2c73 100644 --- a/src/libnm-core-impl/nm-setting-wired.c +++ b/src/libnm-core-impl/nm-setting-wired.c @@ -53,20 +53,20 @@ typedef struct { guint len; guint n_alloc; } s390_options; - GArray * mac_address_blacklist; - char ** s390_subchannels; - char * port; - char * duplex; - char * device_mac_address; - char * cloned_mac_address; - char * generate_mac_address_mask; - char * s390_nettype; - char * wol_password; - NMSettingWiredWakeOnLan wol; - NMTernary accept_all_mac_addresses; - guint32 speed; - guint32 mtu; - bool auto_negotiate; + GArray *mac_address_blacklist; + char **s390_subchannels; + char *port; + char *duplex; + char *device_mac_address; + char *cloned_mac_address; + char *generate_mac_address_mask; + char *s390_nettype; + char *wol_password; + int accept_all_mac_addresses; + guint32 wake_on_lan; + guint32 speed; + guint32 mtu; + bool auto_negotiate; } NMSettingWiredPrivate; /** @@ -344,7 +344,7 @@ gboolean nm_setting_wired_add_mac_blacklist_item(NMSettingWired *setting, const char *mac) { NMSettingWiredPrivate *priv; - const char * candidate; + const char *candidate; int i; g_return_val_if_fail(NM_IS_SETTING_WIRED(setting), FALSE); @@ -401,7 +401,7 @@ gboolean nm_setting_wired_remove_mac_blacklist_item_by_value(NMSettingWired *setting, const char *mac) { NMSettingWiredPrivate *priv; - const char * candidate; + const char *candidate; int i; g_return_val_if_fail(NM_IS_SETTING_WIRED(setting), FALSE); @@ -526,8 +526,8 @@ nm_setting_wired_get_num_s390_options(NMSettingWired *setting) gboolean nm_setting_wired_get_s390_option(NMSettingWired *setting, guint32 idx, - const char ** out_key, - const char ** out_value) + const char **out_key, + const char **out_value) { NMSettingWiredPrivate *priv; @@ -731,7 +731,7 @@ nm_setting_wired_get_wake_on_lan(NMSettingWired *setting) { g_return_val_if_fail(NM_IS_SETTING_WIRED(setting), NM_SETTING_WIRED_WAKE_ON_LAN_NONE); - return NM_SETTING_WIRED_GET_PRIVATE(setting)->wol; + return NM_SETTING_WIRED_GET_PRIVATE(setting)->wake_on_lan; } /** @@ -773,7 +773,7 @@ static gboolean verify(NMSetting *setting, NMConnection *connection, GError **error) { NMSettingWiredPrivate *priv = NM_SETTING_WIRED_GET_PRIVATE(setting); - GError * local = NULL; + GError *local = NULL; guint i; if (!NM_IN_STRSET(priv->port, NULL, "tp", "aui", "bnc", "mii")) { @@ -919,8 +919,8 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) return FALSE; } - if (NM_FLAGS_ANY(priv->wol, NM_SETTING_WIRED_WAKE_ON_LAN_EXCLUSIVE_FLAGS) - && !nm_utils_is_power_of_two(priv->wol)) { + if (NM_FLAGS_ANY(priv->wake_on_lan, NM_SETTING_WIRED_WAKE_ON_LAN_EXCLUSIVE_FLAGS) + && !nm_utils_is_power_of_two(priv->wake_on_lan)) { g_set_error_literal(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, @@ -932,7 +932,8 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) return FALSE; } - if (priv->wol_password && !NM_FLAGS_HAS(priv->wol, NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC)) { + if (priv->wol_password + && !NM_FLAGS_HAS(priv->wake_on_lan, NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC)) { g_set_error_literal(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, @@ -996,45 +997,21 @@ clear_blacklist_item(char **item_p) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMSettingWired * setting = NM_SETTING_WIRED(object); + NMSettingWired *setting = NM_SETTING_WIRED(object); NMSettingWiredPrivate *priv = NM_SETTING_WIRED_GET_PRIVATE(setting); - GHashTable * hash; + GHashTable *hash; guint i; switch (prop_id) { - case PROP_PORT: - g_value_set_string(value, nm_setting_wired_get_port(setting)); - break; - case PROP_SPEED: - g_value_set_uint(value, nm_setting_wired_get_speed(setting)); - break; - case PROP_DUPLEX: - g_value_set_string(value, nm_setting_wired_get_duplex(setting)); - break; - case PROP_AUTO_NEGOTIATE: - g_value_set_boolean(value, nm_setting_wired_get_auto_negotiate(setting)); - break; - case PROP_MAC_ADDRESS: - g_value_set_string(value, nm_setting_wired_get_mac_address(setting)); - break; case PROP_CLONED_MAC_ADDRESS: g_value_set_string(value, nm_setting_wired_get_cloned_mac_address(setting)); break; - case PROP_GENERATE_MAC_ADDRESS_MASK: - g_value_set_string(value, nm_setting_wired_get_generate_mac_address_mask(setting)); - break; case PROP_MAC_ADDRESS_BLACKLIST: g_value_set_boxed(value, (char **) priv->mac_address_blacklist->data); break; - case PROP_MTU: - g_value_set_uint(value, nm_setting_wired_get_mtu(setting)); - break; case PROP_S390_SUBCHANNELS: g_value_set_boxed(value, priv->s390_subchannels); break; - case PROP_S390_NETTYPE: - g_value_set_string(value, nm_setting_wired_get_s390_nettype(setting)); - break; case PROP_S390_OPTIONS: hash = g_hash_table_new_full(nm_str_hash, g_str_equal, g_free, g_free); for (i = 0; i < priv->s390_options.len; i++) { @@ -1044,17 +1021,8 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) } g_value_take_boxed(value, hash); break; - case PROP_WAKE_ON_LAN: - g_value_set_uint(value, priv->wol); - break; - case PROP_WAKE_ON_LAN_PASSWORD: - g_value_set_string(value, priv->wol_password); - break; - case PROP_ACCEPT_ALL_MAC_ADDRESSES: - g_value_set_enum(value, priv->accept_all_mac_addresses); - break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + _nm_setting_property_get_property_direct(object, prop_id, value, pspec); break; } } @@ -1063,38 +1031,15 @@ static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { NMSettingWiredPrivate *priv = NM_SETTING_WIRED_GET_PRIVATE(object); - const char *const * blacklist; - const char * mac; + const char *const *blacklist; + const char *mac; switch (prop_id) { - case PROP_PORT: - g_free(priv->port); - priv->port = g_value_dup_string(value); - break; - case PROP_SPEED: - priv->speed = g_value_get_uint(value); - break; - case PROP_DUPLEX: - g_free(priv->duplex); - priv->duplex = g_value_dup_string(value); - break; - case PROP_AUTO_NEGOTIATE: - priv->auto_negotiate = g_value_get_boolean(value); - break; - case PROP_MAC_ADDRESS: - g_free(priv->device_mac_address); - priv->device_mac_address = - _nm_utils_hwaddr_canonical_or_invalid(g_value_get_string(value), ETH_ALEN); - break; case PROP_CLONED_MAC_ADDRESS: g_free(priv->cloned_mac_address); priv->cloned_mac_address = _nm_utils_hwaddr_canonical_or_invalid(g_value_get_string(value), ETH_ALEN); break; - case PROP_GENERATE_MAC_ADDRESS_MASK: - g_free(priv->generate_mac_address_mask); - priv->generate_mac_address_mask = g_value_dup_string(value); - break; case PROP_MAC_ADDRESS_BLACKLIST: blacklist = g_value_get_boxed(value); g_array_set_size(priv->mac_address_blacklist, 0); @@ -1107,18 +1052,11 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps } } break; - case PROP_MTU: - priv->mtu = g_value_get_uint(value); - break; case PROP_S390_SUBCHANNELS: if (priv->s390_subchannels) g_strfreev(priv->s390_subchannels); priv->s390_subchannels = g_value_dup_boxed(value); break; - case PROP_S390_NETTYPE: - g_free(priv->s390_nettype); - priv->s390_nettype = g_value_dup_string(value); - break; case PROP_S390_OPTIONS: { GHashTable *hash; @@ -1132,8 +1070,8 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps if (priv->s390_options.n_alloc > 0u) { gboolean invalid_content = FALSE; GHashTableIter iter; - const char * key; - const char * val; + const char *key; + const char *val; guint j; guint i; @@ -1181,18 +1119,8 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps g_return_if_fail(!invalid_content); } } break; - case PROP_WAKE_ON_LAN: - priv->wol = g_value_get_uint(value); - break; - case PROP_WAKE_ON_LAN_PASSWORD: - g_free(priv->wol_password); - priv->wol_password = g_value_dup_string(value); - break; - case PROP_ACCEPT_ALL_MAC_ADDRESSES: - priv->accept_all_mac_addresses = g_value_get_enum(value); - break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + _nm_setting_property_set_property_direct(object, prop_id, value, pspec); break; } } @@ -1207,9 +1135,6 @@ nm_setting_wired_init(NMSettingWired *setting) /* We use GArray rather than GPtrArray so it will automatically be NULL-terminated */ priv->mac_address_blacklist = g_array_new(TRUE, FALSE, sizeof(char *)); g_array_set_clear_func(priv->mac_address_blacklist, (GDestroyNotify) clear_blacklist_item); - - priv->wol = NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT; - priv->accept_all_mac_addresses = NM_TERNARY_DEFAULT; } /** @@ -1234,9 +1159,7 @@ finalize(GObject *object) g_free(priv->cloned_mac_address); g_array_unref(priv->mac_address_blacklist); - - if (priv->s390_subchannels) - g_strfreev(priv->s390_subchannels); + g_strfreev(priv->s390_subchannels); G_OBJECT_CLASS(nm_setting_wired_parent_class)->finalize(object); } @@ -1244,9 +1167,9 @@ finalize(GObject *object) static void nm_setting_wired_class_init(NMSettingWiredClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingWiredPrivate)); @@ -1302,13 +1225,16 @@ nm_setting_wired_class_init(NMSettingWiredClass *klass) * parameter in the ETHTOOL_OPTS variable. * ---end--- */ - obj_properties[PROP_SPEED] = g_param_spec_uint(NM_SETTING_WIRED_SPEED, - "", - "", - 0, - G_MAXUINT32, - 0, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_WIRED_SPEED, + PROP_SPEED, + 0, + G_MAXUINT32, + 0, + NM_SETTING_PARAM_NONE, + NMSettingWiredPrivate, + speed); /** * NMSettingWired:duplex: @@ -1566,14 +1492,16 @@ nm_setting_wired_class_init(NMSettingWiredClass *klass) * description: MTU of the interface. * ---end--- */ - obj_properties[PROP_MTU] = g_param_spec_uint(NM_SETTING_WIRED_MTU, - "", - "", - 0, - G_MAXUINT32, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE - | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_WIRED_MTU, + PROP_MTU, + 0, + G_MAXUINT32, + 0, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingWiredPrivate, + mtu); /** * NMSettingWired:s390-subchannels: @@ -1674,14 +1602,16 @@ nm_setting_wired_class_init(NMSettingWiredClass *klass) * in the ethtool manual page. * ---end--- */ - obj_properties[PROP_WAKE_ON_LAN] = - g_param_spec_uint(NM_SETTING_WIRED_WAKE_ON_LAN, - "", - "", - 0, - G_MAXUINT32, - NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_WIRED_WAKE_ON_LAN, + PROP_WAKE_ON_LAN, + 0, + G_MAXUINT32, + NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT, + NM_SETTING_PARAM_NONE, + NMSettingWiredPrivate, + wake_on_lan); /** * NMSettingWired:wake-on-lan-password: @@ -1724,13 +1654,13 @@ nm_setting_wired_class_init(NMSettingWiredClass *klass) * description: Enforce the interface to accept all the packets. * ---end--- */ - obj_properties[PROP_ACCEPT_ALL_MAC_ADDRESSES] = - g_param_spec_enum(NM_SETTING_WIRED_ACCEPT_ALL_MAC_ADDRESSES, - "", - "", - NM_TYPE_TERNARY, - NM_TERNARY_DEFAULT, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_ternary_enum(properties_override, + obj_properties, + NM_SETTING_WIRED_ACCEPT_ALL_MAC_ADDRESSES, + PROP_ACCEPT_ALL_MAC_ADDRESSES, + NM_SETTING_PARAM_NONE, + NMSettingWiredPrivate, + accept_all_mac_addresses); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-wireguard.c b/src/libnm-core-impl/nm-setting-wireguard.c index 27b81488..d713b6a5 100644 --- a/src/libnm-core-impl/nm-setting-wireguard.c +++ b/src/libnm-core-impl/nm-setting-wireguard.c @@ -46,10 +46,10 @@ G_DEFINE_BOXED_TYPE(NMWireGuardPeer, * Since: 1.16 */ struct _NMWireGuardPeer { - NMSockAddrEndpoint * endpoint; - char * public_key; - char * preshared_key; - GPtrArray * allowed_ips; + NMSockAddrEndpoint *endpoint; + char *public_key; + char *preshared_key; + GPtrArray *allowed_ips; guint refcount; NMSettingSecretFlags preshared_key_flags; guint16 persistent_keepalive; @@ -278,10 +278,10 @@ nm_wireguard_peer_get_public_key(const NMWireGuardPeer *self) */ gboolean nm_wireguard_peer_set_public_key(NMWireGuardPeer *self, - const char * public_key, + const char *public_key, gboolean accept_invalid) { - char * public_key_normalized = NULL; + char *public_key_normalized = NULL; gboolean is_valid; g_return_val_if_fail(NM_IS_WIREGUARD_PEER(self, FALSE), FALSE); @@ -365,10 +365,10 @@ nm_wireguard_peer_get_preshared_key(const NMWireGuardPeer *self) */ gboolean nm_wireguard_peer_set_preshared_key(NMWireGuardPeer *self, - const char * preshared_key, + const char *preshared_key, gboolean accept_invalid) { - char * preshared_key_normalized = NULL; + char *preshared_key_normalized = NULL; gboolean is_valid; g_return_val_if_fail(NM_IS_WIREGUARD_PEER(self, FALSE), FALSE); @@ -418,7 +418,7 @@ nm_wireguard_peer_get_preshared_key_flags(const NMWireGuardPeer *self) * Since: 1.16 */ void -nm_wireguard_peer_set_preshared_key_flags(NMWireGuardPeer * self, +nm_wireguard_peer_set_preshared_key_flags(NMWireGuardPeer *self, NMSettingSecretFlags preshared_key_flags) { g_return_if_fail(NM_IS_WIREGUARD_PEER(self, FALSE)); @@ -620,7 +620,7 @@ _peer_append_allowed_ip(NMWireGuardPeer *self, const char *allowed_ip, gboolean int addr_family; int prefix; NMIPAddr addrbin; - char * str; + char *str; gboolean is_valid = TRUE; nm_assert(NM_IS_WIREGUARD_PEER(self, FALSE)); @@ -677,7 +677,7 @@ _peer_append_allowed_ip(NMWireGuardPeer *self, const char *allowed_ip, gboolean */ gboolean nm_wireguard_peer_append_allowed_ip(NMWireGuardPeer *self, - const char * allowed_ip, + const char *allowed_ip, gboolean accept_invalid) { g_return_val_if_fail(NM_IS_WIREGUARD_PEER(self, FALSE), FALSE); @@ -733,7 +733,7 @@ gboolean nm_wireguard_peer_is_valid(const NMWireGuardPeer *self, gboolean check_non_secrets, gboolean check_secrets, - GError ** error) + GError **error) { guint i; @@ -876,7 +876,7 @@ nm_wireguard_peer_cmp(const NMWireGuardPeer *a, /*****************************************************************************/ typedef struct { - const char * public_key; + const char *public_key; NMWireGuardPeer *peer; guint idx; } PeerData; @@ -893,17 +893,17 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_FWMARK, PROP_PRIVATE_KEY_FLAGS, ); typedef struct { - char * private_key; - GPtrArray * peers_arr; - GHashTable * peers_hash; - NMSettingSecretFlags private_key_flags; - NMTernary ip4_auto_default_route; - NMTernary ip6_auto_default_route; - guint32 fwmark; - guint32 mtu; - guint16 listen_port; - bool peer_routes; - bool private_key_valid : 1; + char *private_key; + GPtrArray *peers_arr; + GHashTable *peers_hash; + guint private_key_flags; + int ip4_auto_default_route; + int ip6_auto_default_route; + guint32 fwmark; + guint32 mtu; + guint32 listen_port; + bool peer_routes; + bool private_key_valid : 1; } NMSettingWireGuardPrivate; /** @@ -941,7 +941,7 @@ G_DEFINE_TYPE(NMSettingWireGuard, nm_setting_wireguard, NM_TYPE_SETTING) #define peers_psk_get_secret_parse_a(secret_public_key, public_key_free) \ ({ \ const char *_secret_public_key = (secret_public_key); \ - char ** _public_key_free = (public_key_free); \ + char **_public_key_free = (public_key_free); \ const char *_public_key = NULL; \ \ nm_assert(_public_key_free && !*_public_key_free); \ @@ -1132,11 +1132,11 @@ _peers_get(NMSettingWireGuardPrivate *priv, guint idx) static PeerData * _peers_get_by_public_key(NMSettingWireGuardPrivate *priv, - const char * public_key, + const char *public_key, gboolean try_with_normalized_key) { gs_free char *public_key_normalized = NULL; - PeerData * pd; + PeerData *pd; again: nm_assert(priv); @@ -1233,11 +1233,11 @@ nm_setting_wireguard_get_peer(NMSettingWireGuard *self, guint idx) */ NMWireGuardPeer * nm_setting_wireguard_get_peer_by_public_key(NMSettingWireGuard *self, - const char * public_key, - guint * out_idx) + const char *public_key, + guint *out_idx) { NMSettingWireGuardPrivate *priv; - PeerData * pd; + PeerData *pd; g_return_val_if_fail(NM_IS_SETTING_WIREGUARD(self), NULL); g_return_val_if_fail(public_key, NULL); @@ -1255,12 +1255,12 @@ nm_setting_wireguard_get_peer_by_public_key(NMSettingWireGuard *self, static gboolean _peers_set(NMSettingWireGuardPrivate *priv, - NMWireGuardPeer * peer, + NMWireGuardPeer *peer, guint idx, gboolean check_same_key) { - PeerData * pd_same_key = NULL; - PeerData * pd_idx = NULL; + PeerData *pd_same_key = NULL; + PeerData *pd_idx = NULL; const char *public_key; nm_assert(idx <= priv->peers_arr->len); @@ -1462,7 +1462,7 @@ nm_setting_wireguard_clear_peers(NMSettingWireGuard *self) static GVariant * _peers_dbus_only_synth(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) { - NMSettingWireGuard * self = NM_SETTING_WIREGUARD(setting); + NMSettingWireGuard *self = NM_SETTING_WIREGUARD(setting); NMSettingWireGuardPrivate *priv; gboolean any_peers = FALSE; GVariantBuilder peers_builder; @@ -1518,7 +1518,7 @@ _peers_dbus_only_synth(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) if (_nm_connection_serialize_non_secret(flags) && peer->allowed_ips && peer->allowed_ips->len > 0) { - const char *const * strv = (const char *const *) peer->allowed_ips->pdata; + const char *const *strv = (const char *const *) peer->allowed_ips->pdata; gs_free const char **strv_fixed = NULL; for (i = 0; i < peer->allowed_ips->len; i++) { @@ -1561,7 +1561,7 @@ static gboolean _peers_dbus_only_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) { GVariantIter iter_peers; - GVariant * peer_var; + GVariant *peer_var; guint i_peer; gboolean success = FALSE; gboolean peers_changed = FALSE; @@ -1574,9 +1574,9 @@ _peers_dbus_only_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) while (g_variant_iter_next(&iter_peers, "@a{sv}", &peer_var)) { _nm_unused gs_unref_variant GVariant *peer_var_unref = peer_var; nm_auto_unref_wgpeer NMWireGuardPeer *peer = NULL; - const char * cstr; + const char *cstr; guint32 u32; - GVariant * var; + GVariant *var; i_peer++; @@ -1633,7 +1633,7 @@ _peers_dbus_only_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) if (g_variant_lookup(peer_var, NM_WIREGUARD_PEER_ATTR_ALLOWED_IPS, "@as", &var)) { _nm_unused gs_unref_variant GVariant *var_free = var; - gs_free const char ** allowed_ips = NULL; + gs_free const char **allowed_ips = NULL; gsize i, l; allowed_ips = g_variant_get_strv(var, &l); @@ -1688,7 +1688,7 @@ out: static gboolean verify(NMSetting *setting, NMConnection *connection, GError **error) { - NMSettingWireGuard * s_wg = NM_SETTING_WIREGUARD(setting); + NMSettingWireGuard *s_wg = NM_SETTING_WIREGUARD(setting); NMSettingWireGuardPrivate *priv = NM_SETTING_WIREGUARD_GET_PRIVATE(setting); guint i; @@ -1718,7 +1718,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) if (connection) { NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - const char * method; + const char *method; /* WireGuard is Layer 3 only. For the moment, we only support a restricted set of * IP methods. We may relax that later, once we fix the implementations so they @@ -1803,10 +1803,10 @@ static GPtrArray * need_secrets(NMSetting *setting) { NMSettingWireGuardPrivate *priv = NM_SETTING_WIREGUARD_GET_PRIVATE(setting); - GPtrArray * secrets = NULL; + GPtrArray *secrets = NULL; guint i; - if (!priv->private_key || !priv->private_key_valid) { + if (!priv->private_key_valid) { secrets = g_ptr_array_new_full(1, g_free); g_ptr_array_add(secrets, g_strdup(NM_SETTING_WIREGUARD_PRIVATE_KEY)); } @@ -1832,9 +1832,9 @@ need_secrets(NMSetting *setting) } static gboolean -clear_secrets(const NMSettInfoSetting * sett_info, - const NMSettInfoProperty * property_info, - NMSetting * setting, +clear_secrets(const NMSettInfoSetting *sett_info, + const NMSettInfoProperty *property_info, + NMSetting *setting, NMSettingClearSecretsWithFlagsFn func, gpointer user_data) { @@ -1852,7 +1852,7 @@ clear_secrets(const NMSettInfoSetting * sett_info, if (func) { gs_free char *name_free = NULL; - const char * name; + const char *name; if (j++ < 5) { /* we use alloca() inside a loop here, but it is guarded to happen at most @@ -1891,12 +1891,12 @@ clear_secrets(const NMSettInfoSetting * sett_info, static int update_one_secret(NMSetting *setting, const char *key, GVariant *value, GError **error) { - NMSettingWireGuard * self = NM_SETTING_WIREGUARD(setting); + NMSettingWireGuard *self = NM_SETTING_WIREGUARD(setting); NMSettingWireGuardPrivate *priv; gboolean has_changes = FALSE; gboolean has_error = FALSE; GVariantIter iter_peers; - GVariant * peer_var; + GVariant *peer_var; guint i_peer; if (!nm_streq(key, NM_SETTING_WIREGUARD_PEERS)) { @@ -1924,8 +1924,8 @@ update_one_secret(NMSetting *setting, const char *key, GVariant *value, GError * while (g_variant_iter_next(&iter_peers, "@a{sv}", &peer_var)) { _nm_unused gs_unref_variant GVariant *peer_var_unref = peer_var; nm_auto_unref_wgpeer NMWireGuardPeer *peer = NULL; - PeerData * pd; - const char * cstr; + PeerData *pd; + const char *cstr; i_peer++; @@ -2041,14 +2041,14 @@ duplicate_copy_properties(const NMSettInfoSetting *sett_info, NMSetting *src, NM static void enumerate_values(const NMSettInfoProperty *property_info, - NMSetting * setting, + NMSetting *setting, NMSettingValueIterFn func, gpointer user_data) { if (nm_streq(property_info->name, NM_SETTING_WIREGUARD_PEERS)) { - NMSettingWireGuardPrivate * priv = NM_SETTING_WIREGUARD_GET_PRIVATE(setting); + NMSettingWireGuardPrivate *priv = NM_SETTING_WIREGUARD_GET_PRIVATE(setting); nm_auto_unset_gvalue GValue value = G_VALUE_INIT; - GPtrArray * ptr = NULL; + GPtrArray *ptr = NULL; guint i; if (priv->peers_arr && priv->peers_arr->len > 0) { @@ -2115,16 +2115,16 @@ out_done: } static gboolean -get_secret_flags(NMSetting * setting, - const char * secret_name, +get_secret_flags(NMSetting *setting, + const char *secret_name, NMSettingSecretFlags *out_flags, - GError ** error) + GError **error) { if (NM_STR_HAS_PREFIX(secret_name, NM_SETTING_WIREGUARD_PEERS ".")) { NMSettingWireGuardPrivate *priv = NM_SETTING_WIREGUARD_GET_PRIVATE(setting); - gs_free char * public_key_free = NULL; - const char * public_key; - PeerData * pd; + gs_free char *public_key_free = NULL; + const char *public_key; + PeerData *pd; public_key = peers_psk_get_secret_parse_a(secret_name, &public_key_free); if (public_key && (pd = _peers_get_by_public_key(priv, public_key, FALSE))) { @@ -2138,17 +2138,17 @@ get_secret_flags(NMSetting * setting, } static gboolean -set_secret_flags(NMSetting * setting, - const char * secret_name, +set_secret_flags(NMSetting *setting, + const char *secret_name, NMSettingSecretFlags flags, - GError ** error) + GError **error) { if (NM_STR_HAS_PREFIX(secret_name, NM_SETTING_WIREGUARD_PEERS ".")) { - NMSettingWireGuard * self = NM_SETTING_WIREGUARD(setting); + NMSettingWireGuard *self = NM_SETTING_WIREGUARD(setting); NMSettingWireGuardPrivate *priv = NM_SETTING_WIREGUARD_GET_PRIVATE(self); - gs_free char * public_key_free = NULL; - const char * public_key; - PeerData * pd; + gs_free char *public_key_free = NULL; + const char *public_key; + PeerData *pd; public_key = peers_psk_get_secret_parse_a(secret_name, &public_key_free); if (public_key && (pd = _peers_get_by_public_key(priv, public_key, FALSE))) { @@ -2170,20 +2170,20 @@ set_secret_flags(NMSetting * setting, } static void -for_each_secret(NMSetting * setting, - const char * data_key, - GVariant * data_val, +for_each_secret(NMSetting *setting, + const char *data_key, + GVariant *data_val, gboolean remove_non_secrets, _NMConnectionForEachSecretFunc callback, gpointer callback_data, - GVariantBuilder * setting_builder) + GVariantBuilder *setting_builder) { - NMSettingWireGuard * s_wg; + NMSettingWireGuard *s_wg; NMSettingWireGuardPrivate *priv; GVariantBuilder peers_builder; - GVariantIter * peer_iter; + GVariantIter *peer_iter; GVariantIter data_iter; - const char * key; + const char *key; if (!nm_streq(data_key, NM_SETTING_WIREGUARD_PEERS)) { NM_SETTING_CLASS(nm_setting_wireguard_parent_class) @@ -2210,11 +2210,11 @@ for_each_secret(NMSetting * setting, g_variant_iter_init(&data_iter, data_val); while (g_variant_iter_next(&data_iter, "a{sv}", &peer_iter)) { _nm_unused nm_auto_free_variant_iter GVariantIter *peer_iter_free = peer_iter; - gs_unref_variant GVariant *preshared_key = NULL; - PeerData * pd = NULL; - NMSettingSecretFlags secret_flags; - GVariant * val; - GVariantBuilder peer_builder; + gs_unref_variant GVariant *preshared_key = NULL; + PeerData *pd = NULL; + NMSettingSecretFlags secret_flags; + GVariant *val; + GVariantBuilder peer_builder; g_variant_builder_init(&peer_builder, G_VARIANT_TYPE("a{sv}")); @@ -2258,89 +2258,35 @@ for_each_secret(NMSetting * setting, /*****************************************************************************/ -static void -get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +static gboolean +_set_string_fcn_public_key(const NMSettInfoSetting *sett_info, + const NMSettInfoProperty *property_info, + NMSetting *setting, + const char *str) { - NMSettingWireGuard * setting = NM_SETTING_WIREGUARD(object); - NMSettingWireGuardPrivate *priv = NM_SETTING_WIREGUARD_GET_PRIVATE(setting); - - switch (prop_id) { - case PROP_FWMARK: - g_value_set_uint(value, priv->fwmark); - break; - case PROP_IP4_AUTO_DEFAULT_ROUTE: - g_value_set_enum(value, priv->ip4_auto_default_route); - break; - case PROP_IP6_AUTO_DEFAULT_ROUTE: - g_value_set_enum(value, priv->ip6_auto_default_route); - break; - case PROP_LISTEN_PORT: - g_value_set_uint(value, priv->listen_port); - break; - case PROP_MTU: - g_value_set_uint(value, priv->mtu); - break; - case PROP_PEER_ROUTES: - g_value_set_boolean(value, priv->peer_routes); - break; - case PROP_PRIVATE_KEY: - g_value_set_string(value, priv->private_key); - break; - case PROP_PRIVATE_KEY_FLAGS: - g_value_set_flags(value, priv->private_key_flags); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; + NMSettingWireGuardPrivate *priv = NM_SETTING_WIREGUARD_GET_PRIVATE(setting); + gboolean valid; + char *new = NULL; + char *old; + + if (str) + valid = nm_utils_base64secret_normalize(str, NM_WIREGUARD_PUBLIC_KEY_LEN, &new); + else + valid = FALSE; + + if (nm_streq0(new ?: str, priv->private_key)) { + nm_assert(priv->private_key_valid == valid); + nm_free_secret(new); + return FALSE; } -} -static void -set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) -{ - NMSettingWireGuardPrivate *priv = NM_SETTING_WIREGUARD_GET_PRIVATE(object); - const char * str; + priv->private_key_valid = valid; - switch (prop_id) { - case PROP_FWMARK: - priv->fwmark = g_value_get_uint(value); - break; - case PROP_IP4_AUTO_DEFAULT_ROUTE: - priv->ip4_auto_default_route = g_value_get_enum(value); - break; - case PROP_IP6_AUTO_DEFAULT_ROUTE: - priv->ip6_auto_default_route = g_value_get_enum(value); - break; - case PROP_LISTEN_PORT: - priv->listen_port = g_value_get_uint(value); - break; - case PROP_MTU: - priv->mtu = g_value_get_uint(value); - break; - case PROP_PEER_ROUTES: - priv->peer_routes = g_value_get_boolean(value); - break; - case PROP_PRIVATE_KEY: - nm_clear_pointer(&priv->private_key, nm_free_secret); - str = g_value_get_string(value); - if (str) { - if (nm_utils_base64secret_normalize(str, - NM_WIREGUARD_PUBLIC_KEY_LEN, - &priv->private_key)) - priv->private_key_valid = TRUE; - else { - priv->private_key = g_strdup(str); - priv->private_key_valid = FALSE; - } - } - break; - case PROP_PRIVATE_KEY_FLAGS: - priv->private_key_flags = g_value_get_flags(value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } + old = priv->private_key; + priv->private_key = new ?: g_strdup(str); + nm_free_secret(old); + + return TRUE; } /*****************************************************************************/ @@ -2350,10 +2296,8 @@ nm_setting_wireguard_init(NMSettingWireGuard *setting) { NMSettingWireGuardPrivate *priv = NM_SETTING_WIREGUARD_GET_PRIVATE(setting); - priv->peers_arr = g_ptr_array_new(); - priv->peers_hash = g_hash_table_new(nm_pstr_hash, nm_pstr_equal); - priv->ip4_auto_default_route = NM_TERNARY_DEFAULT; - priv->ip6_auto_default_route = NM_TERNARY_DEFAULT; + priv->peers_arr = g_ptr_array_new(); + priv->peers_hash = g_hash_table_new(nm_pstr_hash, nm_pstr_equal); } /** @@ -2376,8 +2320,6 @@ finalize(GObject *object) { NMSettingWireGuardPrivate *priv = NM_SETTING_WIREGUARD_GET_PRIVATE(object); - nm_free_secret(priv->private_key); - _peers_clear(priv); g_ptr_array_unref(priv->peers_arr); g_hash_table_unref(priv->peers_hash); @@ -2388,12 +2330,12 @@ finalize(GObject *object) static void nm_setting_wireguard_class_init(NMSettingWireGuardClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); - object_class->get_property = get_property; - object_class->set_property = set_property; + object_class->get_property = _nm_setting_property_get_property_direct; + object_class->set_property = _nm_setting_property_set_property_direct; object_class->finalize = finalize; setting_class->verify = verify; @@ -2415,12 +2357,15 @@ nm_setting_wireguard_class_init(NMSettingWireGuardClass *klass) * * Since: 1.16 **/ - obj_properties[PROP_PRIVATE_KEY] = - g_param_spec_string(NM_SETTING_WIREGUARD_PRIVATE_KEY, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_WIREGUARD_PRIVATE_KEY, + PROP_PRIVATE_KEY, + NM_SETTING_PARAM_SECRET, + NMSettingWireGuard, + _priv.private_key, + .direct_hook.set_string_fcn = + _set_string_fcn_public_key); /** * NMSettingWireGuard:private-key-flags: @@ -2430,13 +2375,12 @@ nm_setting_wireguard_class_init(NMSettingWireGuardClass *klass) * * Since: 1.16 **/ - obj_properties[PROP_PRIVATE_KEY_FLAGS] = - g_param_spec_flags(NM_SETTING_WIREGUARD_PRIVATE_KEY_FLAGS, - "", - "", - NM_TYPE_SETTING_SECRET_FLAGS, - NM_SETTING_SECRET_FLAG_NONE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_secret_flags(properties_override, + obj_properties, + NM_SETTING_WIREGUARD_PRIVATE_KEY_FLAGS, + PROP_PRIVATE_KEY_FLAGS, + NMSettingWireGuard, + _priv.private_key_flags); /** * NMSettingWireGuard:fwmark: @@ -2449,14 +2393,16 @@ nm_setting_wireguard_class_init(NMSettingWireGuardClass *klass) * * Since: 1.16 **/ - obj_properties[PROP_FWMARK] = - g_param_spec_uint(NM_SETTING_WIREGUARD_FWMARK, - "", - "", - 0, - G_MAXUINT32, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_WIREGUARD_FWMARK, + PROP_FWMARK, + 0, + G_MAXUINT32, + 0, + NM_SETTING_PARAM_INFERRABLE, + NMSettingWireGuard, + _priv.fwmark); /** * NMSettingWireGuard:listen-port: @@ -2466,14 +2412,16 @@ nm_setting_wireguard_class_init(NMSettingWireGuardClass *klass) * * Since: 1.16 **/ - obj_properties[PROP_LISTEN_PORT] = - g_param_spec_uint(NM_SETTING_WIREGUARD_LISTEN_PORT, - "", - "", - 0, - 65535, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_WIREGUARD_LISTEN_PORT, + PROP_LISTEN_PORT, + 0, + 65535, + 0, + NM_SETTING_PARAM_INFERRABLE, + NMSettingWireGuard, + _priv.listen_port); /** * NMSettingWireGuard:peer-routes: @@ -2498,8 +2446,8 @@ nm_setting_wireguard_class_init(NMSettingWireGuardClass *klass) PROP_PEER_ROUTES, TRUE, NM_SETTING_PARAM_INFERRABLE, - NMSettingWireGuardPrivate, - peer_routes); + NMSettingWireGuard, + _priv.peer_routes); /** * NMSettingWireGuard:mtu: @@ -2513,14 +2461,16 @@ nm_setting_wireguard_class_init(NMSettingWireGuardClass *klass) * * Since: 1.16 **/ - obj_properties[PROP_MTU] = - g_param_spec_uint(NM_SETTING_WIREGUARD_MTU, - "", - "", - 0, - G_MAXUINT32, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_WIREGUARD_MTU, + PROP_MTU, + 0, + G_MAXUINT32, + 0, + NM_SETTING_PARAM_INFERRABLE, + NMSettingWireGuard, + _priv.mtu); /** * NMSettingWireGuard:ip4-auto-default-route: @@ -2542,13 +2492,13 @@ nm_setting_wireguard_class_init(NMSettingWireGuardClass *klass) * * Since: 1.20 **/ - obj_properties[PROP_IP4_AUTO_DEFAULT_ROUTE] = g_param_spec_enum( - NM_SETTING_WIREGUARD_IP4_AUTO_DEFAULT_ROUTE, - "", - "", - NM_TYPE_TERNARY, - NM_TERNARY_DEFAULT, - NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_ternary_enum(properties_override, + obj_properties, + NM_SETTING_WIREGUARD_IP4_AUTO_DEFAULT_ROUTE, + PROP_IP4_AUTO_DEFAULT_ROUTE, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingWireGuard, + _priv.ip4_auto_default_route); /** * NMSettingWireGuard:ip6-auto-default-route: @@ -2557,13 +2507,13 @@ nm_setting_wireguard_class_init(NMSettingWireGuardClass *klass) * * Since: 1.20 **/ - obj_properties[PROP_IP6_AUTO_DEFAULT_ROUTE] = g_param_spec_enum( - NM_SETTING_WIREGUARD_IP6_AUTO_DEFAULT_ROUTE, - "", - "", - NM_TYPE_TERNARY, - NM_TERNARY_DEFAULT, - NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_ternary_enum(properties_override, + obj_properties, + NM_SETTING_WIREGUARD_IP6_AUTO_DEFAULT_ROUTE, + PROP_IP6_AUTO_DEFAULT_ROUTE, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingWireGuard, + _priv.ip6_auto_default_route); /* ---dbus--- * property: peers @@ -2585,5 +2535,5 @@ nm_setting_wireguard_class_init(NMSettingWireGuardClass *klass) NM_META_SETTING_TYPE_WIREGUARD, NULL, properties_override, - G_STRUCT_OFFSET(NMSettingWireGuard, _priv)); + 0); } diff --git a/src/libnm-core-impl/nm-setting-wireless-security.c b/src/libnm-core-impl/nm-setting-wireless-security.c index 0bfc30c8..d9c5afb8 100644 --- a/src/libnm-core-impl/nm-setting-wireless-security.c +++ b/src/libnm-core-impl/nm-setting-wireless-security.c @@ -62,26 +62,26 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMSettingWirelessSecurity, PROP_FILS, ); typedef struct { - GSList * proto; /* GSList of strings */ - GSList * pairwise; /* GSList of strings */ - GSList * group; /* GSList of strings */ - char * key_mgmt; - char * auth_alg; - char * leap_username; - char * leap_password; - char * wep_key0; - char * wep_key1; - char * wep_key2; - char * wep_key3; - char * psk; - NMSettingSecretFlags leap_password_flags; - NMSettingSecretFlags wep_key_flags; - NMSettingSecretFlags psk_flags; - NMSettingWirelessSecurityPmf pmf; - NMWepKeyType wep_key_type; - NMSettingWirelessSecurityWpsMethod wps_method; - NMSettingWirelessSecurityFils fils; - guint32 wep_tx_keyidx; + GSList *proto; /* GSList of strings */ + GSList *pairwise; /* GSList of strings */ + GSList *group; /* GSList of strings */ + char *key_mgmt; + char *auth_alg; + char *leap_username; + char *leap_password; + char *wep_key0; + char *wep_key1; + char *wep_key2; + char *wep_key3; + char *psk; + guint leap_password_flags; + guint wep_key_flags; + guint psk_flags; + NMWepKeyType wep_key_type; + gint32 pmf; + gint32 fils; + guint32 wep_tx_keyidx; + guint32 wps_method; } NMSettingWirelessSecurityPrivate; /** @@ -177,7 +177,7 @@ gboolean nm_setting_wireless_security_add_proto(NMSettingWirelessSecurity *setting, const char *proto) { NMSettingWirelessSecurityPrivate *priv; - GSList * iter; + GSList *iter; g_return_val_if_fail(NM_IS_SETTING_WIRELESS_SECURITY(setting), FALSE); g_return_val_if_fail(proto != NULL, FALSE); @@ -204,7 +204,7 @@ void nm_setting_wireless_security_remove_proto(NMSettingWirelessSecurity *setting, guint32 i) { NMSettingWirelessSecurityPrivate *priv; - GSList * elt; + GSList *elt; g_return_if_fail(NM_IS_SETTING_WIRELESS_SECURITY(setting)); @@ -228,10 +228,10 @@ nm_setting_wireless_security_remove_proto(NMSettingWirelessSecurity *setting, gu **/ gboolean nm_setting_wireless_security_remove_proto_by_value(NMSettingWirelessSecurity *setting, - const char * proto) + const char *proto) { NMSettingWirelessSecurityPrivate *priv; - GSList * iter; + GSList *iter; g_return_val_if_fail(NM_IS_SETTING_WIRELESS_SECURITY(setting), FALSE); g_return_val_if_fail(proto != NULL, FALSE); @@ -321,7 +321,7 @@ gboolean nm_setting_wireless_security_add_pairwise(NMSettingWirelessSecurity *setting, const char *pairwise) { NMSettingWirelessSecurityPrivate *priv; - GSList * iter; + GSList *iter; g_return_val_if_fail(NM_IS_SETTING_WIRELESS_SECURITY(setting), FALSE); g_return_val_if_fail(pairwise != NULL, FALSE); @@ -349,7 +349,7 @@ void nm_setting_wireless_security_remove_pairwise(NMSettingWirelessSecurity *setting, guint32 i) { NMSettingWirelessSecurityPrivate *priv; - GSList * elt; + GSList *elt; g_return_if_fail(NM_IS_SETTING_WIRELESS_SECURITY(setting)); @@ -374,10 +374,10 @@ nm_setting_wireless_security_remove_pairwise(NMSettingWirelessSecurity *setting, **/ gboolean nm_setting_wireless_security_remove_pairwise_by_value(NMSettingWirelessSecurity *setting, - const char * pairwise) + const char *pairwise) { NMSettingWirelessSecurityPrivate *priv; - GSList * iter; + GSList *iter; g_return_val_if_fail(NM_IS_SETTING_WIRELESS_SECURITY(setting), FALSE); g_return_val_if_fail(pairwise != NULL, FALSE); @@ -468,7 +468,7 @@ gboolean nm_setting_wireless_security_add_group(NMSettingWirelessSecurity *setting, const char *group) { NMSettingWirelessSecurityPrivate *priv; - GSList * iter; + GSList *iter; g_return_val_if_fail(NM_IS_SETTING_WIRELESS_SECURITY(setting), FALSE); g_return_val_if_fail(group != NULL, FALSE); @@ -496,7 +496,7 @@ void nm_setting_wireless_security_remove_group(NMSettingWirelessSecurity *setting, guint32 i) { NMSettingWirelessSecurityPrivate *priv; - GSList * elt; + GSList *elt; g_return_if_fail(NM_IS_SETTING_WIRELESS_SECURITY(setting)); @@ -522,10 +522,10 @@ nm_setting_wireless_security_remove_group(NMSettingWirelessSecurity *setting, gu **/ gboolean nm_setting_wireless_security_remove_group_by_value(NMSettingWirelessSecurity *setting, - const char * group) + const char *group) { NMSettingWirelessSecurityPrivate *priv; - GSList * iter; + GSList *iter; g_return_val_if_fail(NM_IS_SETTING_WIRELESS_SECURITY(setting), FALSE); g_return_val_if_fail(group != NULL, FALSE); @@ -691,7 +691,7 @@ nm_setting_wireless_security_get_wep_key(NMSettingWirelessSecurity *setting, gui void nm_setting_wireless_security_set_wep_key(NMSettingWirelessSecurity *setting, guint32 idx, - const char * key) + const char *key) { NMSettingWirelessSecurityPrivate *priv; @@ -817,9 +817,9 @@ nm_setting_wireless_security_get_fils(NMSettingWirelessSecurity *setting) static GPtrArray * need_secrets(NMSetting *setting) { - NMSettingWirelessSecurity * self = NM_SETTING_WIRELESS_SECURITY(setting); + NMSettingWirelessSecurity *self = NM_SETTING_WIRELESS_SECURITY(setting); NMSettingWirelessSecurityPrivate *priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE(self); - GPtrArray * secrets; + GPtrArray *secrets; secrets = g_ptr_array_sized_new(4); @@ -895,16 +895,16 @@ no_secrets: static gboolean verify(NMSetting *setting, NMConnection *connection, GError **error) { - NMSettingWirelessSecurity * self = NM_SETTING_WIRELESS_SECURITY(setting); + NMSettingWirelessSecurity *self = NM_SETTING_WIRELESS_SECURITY(setting); NMSettingWirelessSecurityPrivate *priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE(self); - const char * valid_key_mgmt[] = + const char *valid_key_mgmt[] = {"none", "ieee8021x", "wpa-psk", "wpa-eap", "wpa-eap-suite-b-192", "sae", "owe", NULL}; - const char * valid_auth_algs[] = {"open", "shared", "leap", NULL}; - const char * valid_protos[] = {"wpa", "rsn", NULL}; - const char * valid_pairwise[] = {"tkip", "ccmp", NULL}; - const char * valid_groups[] = {"wep40", "wep104", "tkip", "ccmp", NULL}; + const char *valid_auth_algs[] = {"open", "shared", "leap", NULL}; + const char *valid_protos[] = {"wpa", "rsn", NULL}; + const char *valid_pairwise[] = {"tkip", "ccmp", NULL}; + const char *valid_groups[] = {"wep40", "wep104", "tkip", "ccmp", NULL}; NMSettingWireless *s_wifi; - const char * wifi_mode; + const char *wifi_mode; s_wifi = connection ? nm_connection_get_setting_wireless(connection) : NULL; wifi_mode = s_wifi ? nm_setting_wireless_get_mode(s_wifi) : NULL; @@ -993,7 +993,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } } - if (priv->leap_username && !strlen(priv->leap_username)) { + if (priv->leap_username && nm_str_is_empty(priv->leap_username)) { g_set_error_literal(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, @@ -1005,19 +1005,6 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) return FALSE; } - if (priv->wep_tx_keyidx > 3) { - g_set_error(error, - NM_CONNECTION_ERROR, - NM_CONNECTION_ERROR_INVALID_PROPERTY, - _("'%d' value is out of range <0-3>"), - priv->wep_tx_keyidx); - g_prefix_error(error, - "%s.%s: ", - NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, - NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX); - return FALSE; - } - if (priv->wep_key_type > NM_WEP_KEY_TYPE_LAST) { g_set_error_literal(error, NM_CONNECTION_ERROR, @@ -1161,10 +1148,10 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } static gboolean -_verify_wep_key(const char * wep_key, +_verify_wep_key(const char *wep_key, NMWepKeyType wep_key_type, - const char * property, - GError ** error) + const char *property, + GError **error) { if (wep_key && !nm_utils_wep_key_valid(wep_key, wep_key_type)) { g_set_error_literal(error, @@ -1180,7 +1167,7 @@ _verify_wep_key(const char * wep_key, static gboolean verify_secrets(NMSetting *setting, NMConnection *connection, GError **error) { - NMSettingWirelessSecurity * self = NM_SETTING_WIRELESS_SECURITY(setting); + NMSettingWirelessSecurity *self = NM_SETTING_WIRELESS_SECURITY(setting); NMSettingWirelessSecurityPrivate *priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE(self); /* LEAP */ @@ -1231,10 +1218,10 @@ verify_secrets(NMSetting *setting, NMConnection *connection, GError **error) } static gboolean -get_secret_flags(NMSetting * setting, - const char * secret_name, +get_secret_flags(NMSetting *setting, + const char *secret_name, NMSettingSecretFlags *out_flags, - GError ** error) + GError **error) { NMSettingSecretFlags flags; @@ -1260,10 +1247,10 @@ get_secret_flags(NMSetting * setting, } static gboolean -set_secret_flags(NMSetting * setting, - const char * secret_name, +set_secret_flags(NMSetting *setting, + const char *secret_name, NMSettingSecretFlags flags, - GError ** error) + GError **error) { if (NM_IN_STRSET(secret_name, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, @@ -1310,19 +1297,10 @@ wep_key_type_to_dbus(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMSettingWirelessSecurity * setting = NM_SETTING_WIRELESS_SECURITY(object); + NMSettingWirelessSecurity *setting = NM_SETTING_WIRELESS_SECURITY(object); NMSettingWirelessSecurityPrivate *priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE(setting); switch (prop_id) { - case PROP_KEY_MGMT: - g_value_set_string(value, priv->key_mgmt); - break; - case PROP_WEP_TX_KEYIDX: - g_value_set_uint(value, priv->wep_tx_keyidx); - break; - case PROP_AUTH_ALG: - g_value_set_string(value, priv->auth_alg); - break; case PROP_PROTO: g_value_take_boxed(value, _nm_utils_slist_to_strv(priv->proto, TRUE)); break; @@ -1332,50 +1310,11 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) case PROP_GROUP: g_value_take_boxed(value, _nm_utils_slist_to_strv(priv->group, TRUE)); break; - case PROP_PMF: - g_value_set_int(value, nm_setting_wireless_security_get_pmf(setting)); - break; - case PROP_LEAP_USERNAME: - g_value_set_string(value, priv->leap_username); - break; - case PROP_WEP_KEY0: - g_value_set_string(value, priv->wep_key0); - break; - case PROP_WEP_KEY1: - g_value_set_string(value, priv->wep_key1); - break; - case PROP_WEP_KEY2: - g_value_set_string(value, priv->wep_key2); - break; - case PROP_WEP_KEY3: - g_value_set_string(value, priv->wep_key3); - break; - case PROP_WEP_KEY_FLAGS: - g_value_set_flags(value, priv->wep_key_flags); - break; - case PROP_PSK: - g_value_set_string(value, priv->psk); - break; - case PROP_PSK_FLAGS: - g_value_set_flags(value, priv->psk_flags); - break; - case PROP_LEAP_PASSWORD: - g_value_set_string(value, priv->leap_password); - break; - case PROP_LEAP_PASSWORD_FLAGS: - g_value_set_flags(value, priv->leap_password_flags); - break; case PROP_WEP_KEY_TYPE: g_value_set_enum(value, priv->wep_key_type); break; - case PROP_WPS_METHOD: - g_value_set_uint(value, priv->wps_method); - break; - case PROP_FILS: - g_value_set_int(value, nm_setting_wireless_security_get_fils(setting)); - break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + _nm_setting_property_get_property_direct(object, prop_id, value, pspec); break; } } @@ -1383,24 +1322,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) { - NMSettingWirelessSecurity * setting = NM_SETTING_WIRELESS_SECURITY(object); + NMSettingWirelessSecurity *setting = NM_SETTING_WIRELESS_SECURITY(object); NMSettingWirelessSecurityPrivate *priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE(setting); - const char * str; switch (prop_id) { - case PROP_KEY_MGMT: - g_free(priv->key_mgmt); - str = g_value_get_string(value); - priv->key_mgmt = str ? g_ascii_strdown(str, -1) : NULL; - break; - case PROP_WEP_TX_KEYIDX: - priv->wep_tx_keyidx = g_value_get_uint(value); - break; - case PROP_AUTH_ALG: - g_free(priv->auth_alg); - str = g_value_get_string(value); - priv->auth_alg = str ? g_ascii_strdown(str, -1) : NULL; - break; case PROP_PROTO: g_slist_free_full(priv->proto, g_free); priv->proto = nm_strv_to_gslist(g_value_get_boxed(value), TRUE); @@ -1413,57 +1338,11 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps g_slist_free_full(priv->group, g_free); priv->group = nm_strv_to_gslist(g_value_get_boxed(value), TRUE); break; - case PROP_PMF: - priv->pmf = g_value_get_int(value); - break; - case PROP_LEAP_USERNAME: - g_free(priv->leap_username); - priv->leap_username = g_value_dup_string(value); - break; - case PROP_WEP_KEY0: - nm_free_secret(priv->wep_key0); - priv->wep_key0 = g_value_dup_string(value); - break; - case PROP_WEP_KEY1: - nm_free_secret(priv->wep_key1); - priv->wep_key1 = g_value_dup_string(value); - break; - case PROP_WEP_KEY2: - nm_free_secret(priv->wep_key2); - priv->wep_key2 = g_value_dup_string(value); - break; - case PROP_WEP_KEY3: - nm_free_secret(priv->wep_key3); - priv->wep_key3 = g_value_dup_string(value); - break; - case PROP_WEP_KEY_FLAGS: - priv->wep_key_flags = g_value_get_flags(value); - break; - case PROP_PSK: - nm_free_secret(priv->psk); - priv->psk = g_value_dup_string(value); - break; - case PROP_PSK_FLAGS: - priv->psk_flags = g_value_get_flags(value); - break; - case PROP_LEAP_PASSWORD: - nm_free_secret(priv->leap_password); - priv->leap_password = g_value_dup_string(value); - break; - case PROP_LEAP_PASSWORD_FLAGS: - priv->leap_password_flags = g_value_get_flags(value); - break; case PROP_WEP_KEY_TYPE: priv->wep_key_type = g_value_get_enum(value); break; - case PROP_WPS_METHOD: - priv->wps_method = g_value_get_uint(value); - break; - case PROP_FILS: - priv->fils = g_value_get_int(value); - break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + _nm_setting_property_set_property_direct(object, prop_id, value, pspec); break; } } @@ -1475,8 +1354,6 @@ nm_setting_wireless_security_init(NMSettingWirelessSecurity *self) { nm_assert(NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE(self)->wep_key_type == NM_WEP_KEY_TYPE_UNKNOWN); - nm_assert(NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE(self)->wps_method - == NM_SETTING_WIRELESS_SECURITY_WPS_METHOD_DEFAULT); } /** @@ -1495,19 +1372,9 @@ nm_setting_wireless_security_new(void) static void finalize(GObject *object) { - NMSettingWirelessSecurity * self = NM_SETTING_WIRELESS_SECURITY(object); + NMSettingWirelessSecurity *self = NM_SETTING_WIRELESS_SECURITY(object); NMSettingWirelessSecurityPrivate *priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE(self); - g_free(priv->key_mgmt); - g_free(priv->auth_alg); - g_free(priv->leap_username); - nm_free_secret(priv->wep_key0); - nm_free_secret(priv->wep_key1); - nm_free_secret(priv->wep_key2); - nm_free_secret(priv->wep_key3); - nm_free_secret(priv->psk); - nm_free_secret(priv->leap_password); - g_slist_free_full(priv->proto, g_free); g_slist_free_full(priv->pairwise, g_free); g_slist_free_full(priv->group, g_free); @@ -1518,9 +1385,9 @@ finalize(GObject *object) static void nm_setting_wireless_security_class_init(NMSettingWirelessSecurityClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingWirelessSecurityPrivate)); @@ -1552,12 +1419,14 @@ nm_setting_wireless_security_class_init(NMSettingWirelessSecurityClass *klass) * description: Key management method. * ---end--- */ - obj_properties[PROP_KEY_MGMT] = - g_param_spec_string(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_REQUIRED | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, + PROP_KEY_MGMT, + NM_SETTING_PARAM_REQUIRED, + NMSettingWirelessSecurityPrivate, + key_mgmt, + .direct_set_string_ascii_strdown = TRUE); /** * NMSettingWirelessSecurity:wep-tx-keyidx: @@ -1572,17 +1441,20 @@ nm_setting_wireless_security_class_init(NMSettingWirelessSecurityClass *klass) * variable: DEFAULTKEY * values: 1, 2, 3, 4 * default: 1 - * description: Index of active WEP key. + * description: Index of active WEP key. Note that in ifcfg format the index starts counting + * at 1, while NetworkManager API otherwise is zero based. * ---end--- */ - obj_properties[PROP_WEP_TX_KEYIDX] = - g_param_spec_uint(NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, - "", - "", - 0, - 3, - 0, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, + PROP_WEP_TX_KEYIDX, + 0, + 3, + 0, + NM_SETTING_PARAM_NONE, + NMSettingWirelessSecurityPrivate, + wep_tx_keyidx); /** * NMSettingWirelessSecurity:auth-alg: @@ -1600,11 +1472,14 @@ nm_setting_wireless_security_class_init(NMSettingWirelessSecurityClass *klass) * description: Authentication algorithm for WEP. * ---end--- */ - obj_properties[PROP_AUTH_ALG] = g_param_spec_string(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, + PROP_AUTH_ALG, + NM_SETTING_PARAM_NONE, + NMSettingWirelessSecurityPrivate, + auth_alg, + .direct_set_string_ascii_strdown = TRUE); /** * NMSettingWirelessSecurity:proto: @@ -1693,14 +1568,16 @@ nm_setting_wireless_security_class_init(NMSettingWirelessSecurityClass *klass) * example: PMF=required * ---end--- */ - obj_properties[PROP_PMF] = g_param_spec_int(NM_SETTING_WIRELESS_SECURITY_PMF, - "", - "", - G_MININT32, - G_MAXINT32, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE - | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_int32(properties_override, + obj_properties, + NM_SETTING_WIRELESS_SECURITY_PMF, + PROP_PMF, + G_MININT32, + G_MAXINT32, + 0, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingWirelessSecurityPrivate, + pmf); /** * NMSettingWirelessSecurity:leap-username: @@ -1714,12 +1591,13 @@ nm_setting_wireless_security_class_init(NMSettingWirelessSecurityClass *klass) * description: Login name for LEAP. * ---end--- */ - obj_properties[PROP_LEAP_USERNAME] = - g_param_spec_string(NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, + PROP_LEAP_USERNAME, + NM_SETTING_PARAM_NONE, + NMSettingWirelessSecurityPrivate, + leap_username); /** * NMSettingWirelessSecurity:wep-key0: @@ -1733,12 +1611,13 @@ nm_setting_wireless_security_class_init(NMSettingWirelessSecurityClass *klass) * description: The first WEP key (used in most networks). See also DEFAULTKEY for key index. * ---end--- */ - obj_properties[PROP_WEP_KEY0] = - g_param_spec_string(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, + PROP_WEP_KEY0, + NM_SETTING_PARAM_SECRET, + NMSettingWirelessSecurityPrivate, + wep_key0); /** * NMSettingWirelessSecurity:wep-key1: @@ -1752,12 +1631,13 @@ nm_setting_wireless_security_class_init(NMSettingWirelessSecurityClass *klass) * description: WEP key with index 1. See also DEFAULTKEY for key index. * ---end--- */ - obj_properties[PROP_WEP_KEY1] = - g_param_spec_string(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_WIRELESS_SECURITY_WEP_KEY1, + PROP_WEP_KEY1, + NM_SETTING_PARAM_SECRET, + NMSettingWirelessSecurityPrivate, + wep_key1); /** * NMSettingWirelessSecurity:wep-key2: @@ -1771,12 +1651,13 @@ nm_setting_wireless_security_class_init(NMSettingWirelessSecurityClass *klass) * description: WEP key with index 2. See also DEFAULTKEY for key index. * ---end--- */ - obj_properties[PROP_WEP_KEY2] = - g_param_spec_string(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_WIRELESS_SECURITY_WEP_KEY2, + PROP_WEP_KEY2, + NM_SETTING_PARAM_SECRET, + NMSettingWirelessSecurityPrivate, + wep_key2); /** * NMSettingWirelessSecurity:wep-key3: @@ -1790,12 +1671,13 @@ nm_setting_wireless_security_class_init(NMSettingWirelessSecurityClass *klass) * description: WEP key with index 3. See also DEFAULTKEY for key index. * ---end--- */ - obj_properties[PROP_WEP_KEY3] = - g_param_spec_string(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_WIRELESS_SECURITY_WEP_KEY3, + PROP_WEP_KEY3, + NM_SETTING_PARAM_SECRET, + NMSettingWirelessSecurityPrivate, + wep_key3); /** * NMSettingWirelessSecurity:wep-key-flags: @@ -1811,13 +1693,12 @@ nm_setting_wireless_security_class_init(NMSettingWirelessSecurityClass *klass) * description: Password flags for KEY, KEY_PASSPHRASE password. * ---end--- */ - obj_properties[PROP_WEP_KEY_FLAGS] = - g_param_spec_flags(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS, - "", - "", - NM_TYPE_SETTING_SECRET_FLAGS, - NM_SETTING_SECRET_FLAG_NONE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_secret_flags(properties_override, + obj_properties, + NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS, + PROP_WEP_KEY_FLAGS, + NMSettingWirelessSecurityPrivate, + wep_key_flags); /** * NMSettingWirelessSecurity:psk: @@ -1834,12 +1715,13 @@ nm_setting_wireless_security_class_init(NMSettingWirelessSecurityClass *klass) * description: Pre-Shared-Key for WPA networks. * ---end--- */ - obj_properties[PROP_PSK] = - g_param_spec_string(NM_SETTING_WIRELESS_SECURITY_PSK, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_WIRELESS_SECURITY_PSK, + PROP_PSK, + NM_SETTING_PARAM_SECRET, + NMSettingWirelessSecurityPrivate, + psk); /** * NMSettingWirelessSecurity:psk-flags: @@ -1855,12 +1737,12 @@ nm_setting_wireless_security_class_init(NMSettingWirelessSecurityClass *klass) * example: WPA_PSK_FLAGS=user * ---end--- */ - obj_properties[PROP_PSK_FLAGS] = g_param_spec_flags(NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS, - "", - "", - NM_TYPE_SETTING_SECRET_FLAGS, - NM_SETTING_SECRET_FLAG_NONE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_secret_flags(properties_override, + obj_properties, + NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS, + PROP_PSK_FLAGS, + NMSettingWirelessSecurityPrivate, + psk_flags); /** * NMSettingWirelessSecurity:leap-password: @@ -1875,12 +1757,13 @@ nm_setting_wireless_security_class_init(NMSettingWirelessSecurityClass *klass) * lookaside file, or it can be owned by a secret agent. * ---end--- */ - obj_properties[PROP_LEAP_PASSWORD] = - g_param_spec_string(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD, + PROP_LEAP_PASSWORD, + NM_SETTING_PARAM_SECRET, + NMSettingWirelessSecurityPrivate, + leap_password); /** * NMSettingWirelessSecurity:leap-password-flags: @@ -1895,13 +1778,13 @@ nm_setting_wireless_security_class_init(NMSettingWirelessSecurityClass *klass) * description: Password flags for IEEE_8021X_PASSWORD_FLAGS. * ---end--- */ - obj_properties[PROP_LEAP_PASSWORD_FLAGS] = - g_param_spec_flags(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS, - "", - "", - NM_TYPE_SETTING_SECRET_FLAGS, - NM_SETTING_SECRET_FLAG_NONE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_secret_flags( + properties_override, + obj_properties, + NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS, + PROP_LEAP_PASSWORD_FLAGS, + NMSettingWirelessSecurityPrivate, + leap_password_flags); /** * NMSettingWirelessSecurity:wep-key-type: @@ -1961,14 +1844,16 @@ nm_setting_wireless_security_class_init(NMSettingWirelessSecurityClass *klass) * example: WPS_METHOD=disabled, WPS_METHOD="pin pbc" * ---end--- */ - obj_properties[PROP_WPS_METHOD] = g_param_spec_uint( - NM_SETTING_WIRELESS_SECURITY_WPS_METHOD, - "", - "", - 0, - G_MAXUINT32, - NM_SETTING_WIRELESS_SECURITY_WPS_METHOD_DEFAULT, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_WIRELESS_SECURITY_WPS_METHOD, + PROP_WPS_METHOD, + 0, + G_MAXUINT32, + NM_SETTING_WIRELESS_SECURITY_WPS_METHOD_DEFAULT, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingWirelessSecurityPrivate, + wps_method); /** * NMSettingWirelessSecurity:fils: @@ -1992,14 +1877,16 @@ nm_setting_wireless_security_class_init(NMSettingWirelessSecurityClass *klass) * example: FILS=required * ---end--- */ - obj_properties[PROP_FILS] = g_param_spec_int(NM_SETTING_WIRELESS_SECURITY_FILS, - "", - "", - G_MININT32, - G_MAXINT32, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE - | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_int32(properties_override, + obj_properties, + NM_SETTING_WIRELESS_SECURITY_FILS, + PROP_FILS, + G_MININT32, + G_MAXINT32, + 0, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingWirelessSecurityPrivate, + fils); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-wireless.c b/src/libnm-core-impl/nm-setting-wireless.c index f5a4cb6a..8f57f69b 100644 --- a/src/libnm-core-impl/nm-setting-wireless.c +++ b/src/libnm-core-impl/nm-setting-wireless.c @@ -46,24 +46,24 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMSettingWireless, PROP_AP_ISOLATION, ); typedef struct { - GBytes * ssid; - GArray * mac_address_blacklist; - GPtrArray * seen_bssids; - char * mode; - char * band; - char * bssid; - char * device_mac_address; - char * cloned_mac_address; - char * generate_mac_address_mask; - NMSettingMacRandomization mac_address_randomization; - NMTernary ap_isolation; - guint32 channel; - guint32 rate; - guint32 tx_power; - guint32 mtu; - guint32 powersave; - guint32 wowl; - bool hidden; + GBytes *ssid; + GArray *mac_address_blacklist; + GPtrArray *seen_bssids; + char *mode; + char *band; + char *bssid; + char *device_mac_address; + char *cloned_mac_address; + char *generate_mac_address_mask; + int ap_isolation; + guint32 mac_address_randomization; + guint32 channel; + guint32 rate; + guint32 tx_power; + guint32 mtu; + guint32 powersave; + guint32 wake_on_wlan; + bool hidden; } NMSettingWirelessPrivate; /** @@ -127,7 +127,7 @@ match_cipher(const char *cipher, * security flags and mode, %FALSE if they are not. */ gboolean -nm_setting_wireless_ap_security_compatible(NMSettingWireless * s_wireless, +nm_setting_wireless_ap_security_compatible(NMSettingWireless *s_wireless, NMSettingWirelessSecurity *s_wireless_sec, NM80211ApFlags ap_flags, NM80211ApSecurityFlags ap_wpa, @@ -300,6 +300,16 @@ nm_setting_wireless_ap_security_compatible(NMSettingWireless * s_wireless return TRUE; } + /* WPA3 Enterprise Suite B 192 */ + if (!strcmp(key_mgmt, "wpa-eap-suite-b-192")) { + if (!(ap_rsn & NM_802_11_AP_SEC_KEY_MGMT_EAP_SUITE_B_192)) { + return FALSE; + } + + /* Since NetworkManager doesn't handle GCMP-256 directly, cipher check can be skipped */ + return TRUE; + } + return FALSE; } @@ -511,7 +521,7 @@ gboolean nm_setting_wireless_add_mac_blacklist_item(NMSettingWireless *setting, const char *mac) { NMSettingWirelessPrivate *priv; - const char * candidate; + const char *candidate; int i; g_return_val_if_fail(NM_IS_SETTING_WIRELESS(setting), FALSE); @@ -568,7 +578,7 @@ gboolean nm_setting_wireless_remove_mac_blacklist_item_by_value(NMSettingWireless *setting, const char *mac) { NMSettingWirelessPrivate *priv; - const char * candidate; + const char *candidate; int i; g_return_val_if_fail(NM_IS_SETTING_WIRELESS(setting), FALSE); @@ -678,7 +688,7 @@ gboolean nm_setting_wireless_add_seen_bssid(NMSettingWireless *setting, const char *bssid) { NMSettingWirelessPrivate *priv; - gs_free char * lower_bssid = NULL; + gs_free char *lower_bssid = NULL; g_return_val_if_fail(NM_IS_SETTING_WIRELESS(setting), FALSE); g_return_val_if_fail(bssid != NULL, FALSE); @@ -764,7 +774,7 @@ static gboolean _from_dbus_fcn_seen_bssids(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) { NMSettingWirelessPrivate *priv; - gs_free const char ** s = NULL; + gs_free const char **s = NULL; gsize len; gsize i; @@ -810,15 +820,15 @@ static gboolean verify(NMSetting *setting, NMConnection *connection, GError **error) { NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE(setting); - const char * valid_modes[] = {NM_SETTING_WIRELESS_MODE_INFRA, + const char *valid_modes[] = {NM_SETTING_WIRELESS_MODE_INFRA, NM_SETTING_WIRELESS_MODE_ADHOC, NM_SETTING_WIRELESS_MODE_AP, NM_SETTING_WIRELESS_MODE_MESH, NULL}; - const char * valid_bands[] = {"a", "bg", NULL}; + const char *valid_bands[] = {"a", "bg", NULL}; guint i; gsize length; - GError * local = NULL; + GError *local = NULL; if (!priv->ssid) { g_set_error_literal(error, @@ -1025,8 +1035,8 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) return FALSE; } - if (NM_FLAGS_ANY(priv->wowl, NM_SETTING_WIRELESS_WAKE_ON_WLAN_EXCLUSIVE_FLAGS)) { - if (!nm_utils_is_power_of_two(priv->wowl)) { + if (NM_FLAGS_ANY(priv->wake_on_wlan, NM_SETTING_WIRELESS_WAKE_ON_WLAN_EXCLUSIVE_FLAGS)) { + if (!nm_utils_is_power_of_two(priv->wake_on_wlan)) { g_set_error_literal(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, @@ -1037,7 +1047,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) NM_SETTING_WIRELESS_WAKE_ON_WLAN); return FALSE; } - } else if (NM_FLAGS_ANY(priv->wowl, ~NM_SETTING_WIRELESS_WAKE_ON_WLAN_ALL)) { + } else if (NM_FLAGS_ANY(priv->wake_on_wlan, ~NM_SETTING_WIRELESS_WAKE_ON_WLAN_ALL)) { g_set_error_literal(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, @@ -1138,7 +1148,7 @@ nm_setting_wireless_get_wake_on_wlan(NMSettingWireless *setting) { g_return_val_if_fail(NM_IS_SETTING_WIRELESS(setting), NM_SETTING_WIRELESS_WAKE_ON_WLAN_NONE); - return NM_SETTING_WIRELESS_GET_PRIVATE(setting)->wowl; + return NM_SETTING_WIRELESS_GET_PRIVATE(setting)->wake_on_wlan; } static void @@ -1152,37 +1162,16 @@ clear_blacklist_item(char **item_p) static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMSettingWireless * setting = NM_SETTING_WIRELESS(object); + NMSettingWireless *setting = NM_SETTING_WIRELESS(object); NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE(object); switch (prop_id) { - case PROP_MODE: - g_value_set_string(value, nm_setting_wireless_get_mode(setting)); - break; - case PROP_BAND: - g_value_set_string(value, nm_setting_wireless_get_band(setting)); - break; - case PROP_CHANNEL: - g_value_set_uint(value, nm_setting_wireless_get_channel(setting)); - break; - case PROP_RATE: - g_value_set_uint(value, nm_setting_wireless_get_rate(setting)); - break; - case PROP_TX_POWER: - g_value_set_uint(value, nm_setting_wireless_get_tx_power(setting)); - break; case PROP_CLONED_MAC_ADDRESS: g_value_set_string(value, nm_setting_wireless_get_cloned_mac_address(setting)); break; - case PROP_GENERATE_MAC_ADDRESS_MASK: - g_value_set_string(value, nm_setting_wireless_get_generate_mac_address_mask(setting)); - break; case PROP_MAC_ADDRESS_BLACKLIST: g_value_set_boxed(value, (char **) priv->mac_address_blacklist->data); break; - case PROP_MTU: - g_value_set_uint(value, nm_setting_wireless_get_mtu(setting)); - break; case PROP_SEEN_BSSIDS: g_value_take_boxed( value, @@ -1190,18 +1179,6 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) ? nm_strv_dup((char **) priv->seen_bssids->pdata, priv->seen_bssids->len, TRUE) : NULL); break; - case PROP_POWERSAVE: - g_value_set_uint(value, nm_setting_wireless_get_powersave(setting)); - break; - case PROP_MAC_ADDRESS_RANDOMIZATION: - g_value_set_uint(value, nm_setting_wireless_get_mac_address_randomization(setting)); - break; - case PROP_WAKE_ON_WLAN: - g_value_set_uint(value, nm_setting_wireless_get_wake_on_wlan(setting)); - break; - case PROP_AP_ISOLATION: - g_value_set_enum(value, priv->ap_isolation); - break; default: _nm_setting_property_get_property_direct(object, prop_id, value, pspec); break; @@ -1212,28 +1189,11 @@ static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE(object); - const char *const * blacklist; - const char * mac; + const char *const *blacklist; + const char *mac; gboolean bool_val; switch (prop_id) { - case PROP_MODE: - g_free(priv->mode); - priv->mode = g_value_dup_string(value); - break; - case PROP_BAND: - g_free(priv->band); - priv->band = g_value_dup_string(value); - break; - case PROP_CHANNEL: - priv->channel = g_value_get_uint(value); - break; - case PROP_RATE: - priv->rate = g_value_get_uint(value); - break; - case PROP_TX_POWER: - priv->tx_power = g_value_get_uint(value); - break; case PROP_CLONED_MAC_ADDRESS: bool_val = !!priv->cloned_mac_address; g_free(priv->cloned_mac_address); @@ -1248,10 +1208,6 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps } } break; - case PROP_GENERATE_MAC_ADDRESS_MASK: - g_free(priv->generate_mac_address_mask); - priv->generate_mac_address_mask = g_value_dup_string(value); - break; case PROP_MAC_ADDRESS_BLACKLIST: blacklist = g_value_get_boxed(value); g_array_set_size(priv->mac_address_blacklist, 0); @@ -1264,13 +1220,10 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps } } break; - case PROP_MTU: - priv->mtu = g_value_get_uint(value); - break; case PROP_SEEN_BSSIDS: { gs_unref_ptrarray GPtrArray *arr_old = NULL; - const char *const * strv; + const char *const *strv; arr_old = g_steal_pointer(&priv->seen_bssids); @@ -1285,18 +1238,6 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps } break; } - case PROP_POWERSAVE: - priv->powersave = g_value_get_uint(value); - break; - case PROP_MAC_ADDRESS_RANDOMIZATION: - priv->mac_address_randomization = g_value_get_uint(value); - break; - case PROP_WAKE_ON_WLAN: - priv->wowl = g_value_get_uint(value); - break; - case PROP_AP_ISOLATION: - priv->ap_isolation = g_value_get_enum(value); - break; default: _nm_setting_property_set_property_direct(object, prop_id, value, pspec); break; @@ -1313,9 +1254,6 @@ nm_setting_wireless_init(NMSettingWireless *setting) /* We use GArray rather than GPtrArray so it will automatically be NULL-terminated */ priv->mac_address_blacklist = g_array_new(TRUE, FALSE, sizeof(char *)); g_array_set_clear_func(priv->mac_address_blacklist, (GDestroyNotify) clear_blacklist_item); - - priv->wowl = NM_SETTING_WIRELESS_WAKE_ON_WLAN_DEFAULT; - priv->ap_isolation = NM_TERNARY_DEFAULT; } /** @@ -1336,13 +1274,9 @@ finalize(GObject *object) { NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE(object); - g_free(priv->mode); - g_free(priv->band); - g_free(priv->cloned_mac_address); - g_free(priv->generate_mac_address_mask); g_array_unref(priv->mac_address_blacklist); - nm_clear_pointer(&priv->seen_bssids, g_ptr_array_unref); + nm_g_ptr_array_unref(priv->seen_bssids); G_OBJECT_CLASS(nm_setting_wireless_parent_class)->finalize(object); } @@ -1350,9 +1284,9 @@ finalize(GObject *object) static void nm_setting_wireless_class_init(NMSettingWirelessClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingWirelessPrivate)); @@ -1401,11 +1335,13 @@ nm_setting_wireless_class_init(NMSettingWirelessClass *klass) * description: Wi-Fi network mode. * ---end--- */ - obj_properties[PROP_MODE] = g_param_spec_string(NM_SETTING_WIRELESS_MODE, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_WIRELESS_MODE, + PROP_MODE, + NM_SETTING_PARAM_NONE, + NMSettingWirelessPrivate, + mode); /** * NMSettingWireless:band: @@ -1426,11 +1362,13 @@ nm_setting_wireless_class_init(NMSettingWirelessClass *klass) * example: BAND=bg * ---end--- */ - obj_properties[PROP_BAND] = g_param_spec_string(NM_SETTING_WIRELESS_BAND, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_WIRELESS_BAND, + PROP_BAND, + NM_SETTING_PARAM_NONE, + NMSettingWirelessPrivate, + band); /** * NMSettingWireless:channel: @@ -1449,13 +1387,16 @@ nm_setting_wireless_class_init(NMSettingWirelessClass *klass) * example: CHANNEL=6 * ---end--- */ - obj_properties[PROP_CHANNEL] = g_param_spec_uint(NM_SETTING_WIRELESS_CHANNEL, - "", - "", - 0, - G_MAXUINT32, - 0, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_WIRELESS_CHANNEL, + PROP_CHANNEL, + 0, + G_MAXUINT32, + 0, + NM_SETTING_PARAM_NONE, + NMSettingWirelessPrivate, + channel); /** * NMSettingWireless:bssid: @@ -1495,14 +1436,16 @@ nm_setting_wireless_class_init(NMSettingWirelessClass *klass) * description: This property is not handled by ifcfg-rh plugin. * ---end--- */ - obj_properties[PROP_RATE] = g_param_spec_uint(NM_SETTING_WIRELESS_RATE, - "", - "", - 0, - G_MAXUINT32, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE - | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_WIRELESS_RATE, + PROP_RATE, + 0, + G_MAXUINT32, + 0, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingWirelessPrivate, + rate); /** * NMSettingWireless:tx-power: @@ -1517,14 +1460,16 @@ nm_setting_wireless_class_init(NMSettingWirelessClass *klass) * description: This property is not handled by ifcfg-rh plugin. * ---end--- */ - obj_properties[PROP_TX_POWER] = g_param_spec_uint( - NM_SETTING_WIRELESS_TX_POWER, - "", - "", - 0, - G_MAXUINT32, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_WIRELESS_TX_POWER, + PROP_TX_POWER, + 0, + G_MAXUINT32, + 0, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingWirelessPrivate, + tx_power); /** * NMSettingWireless:mac-address: @@ -1671,12 +1616,13 @@ nm_setting_wireless_class_init(NMSettingWirelessClass *klass) * cloned-mac-address. * ---end--- */ - obj_properties[PROP_GENERATE_MAC_ADDRESS_MASK] = g_param_spec_string( - NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK, + PROP_GENERATE_MAC_ADDRESS_MASK, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingWirelessPrivate, + generate_mac_address_mask); /** * NMSettingWireless:mac-address-blacklist: @@ -1747,14 +1693,16 @@ nm_setting_wireless_class_init(NMSettingWirelessClass *klass) * description: MTU of the wireless interface. * ---end--- */ - obj_properties[PROP_MTU] = g_param_spec_uint(NM_SETTING_WIRELESS_MTU, - "", - "", - 0, - G_MAXUINT32, - 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE - | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_WIRELESS_MTU, + PROP_MTU, + 0, + G_MAXUINT32, + 0, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingWirelessPrivate, + mtu); /** * NMSettingWireless:hidden: @@ -1808,13 +1756,16 @@ nm_setting_wireless_class_init(NMSettingWirelessClass *klass) * example: POWERSAVE=enable * ---end--- */ - obj_properties[PROP_POWERSAVE] = g_param_spec_uint(NM_SETTING_WIRELESS_POWERSAVE, - "", - "", - 0, - G_MAXUINT32, - NM_SETTING_WIRELESS_POWERSAVE_DEFAULT, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_WIRELESS_POWERSAVE, + PROP_POWERSAVE, + 0, + G_MAXUINT32, + NM_SETTING_WIRELESS_POWERSAVE_DEFAULT, + NM_SETTING_PARAM_NONE, + NMSettingWirelessPrivate, + powersave); /** * NMSettingWireless:mac-address-randomization: @@ -1837,14 +1788,16 @@ nm_setting_wireless_class_init(NMSettingWirelessClass *klass) * example: MAC_ADDRESS_RANDOMIZATION=always * ---end--- */ - obj_properties[PROP_MAC_ADDRESS_RANDOMIZATION] = - g_param_spec_uint(NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION, - "", - "", - 0, - G_MAXUINT32, - NM_SETTING_MAC_RANDOMIZATION_DEFAULT, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION, + PROP_MAC_ADDRESS_RANDOMIZATION, + 0, + G_MAXUINT32, + NM_SETTING_MAC_RANDOMIZATION_DEFAULT, + NM_SETTING_PARAM_NONE, + NMSettingWirelessPrivate, + mac_address_randomization); /* Compatibility for deprecated property */ /* ---ifcfg-rh--- @@ -1885,14 +1838,16 @@ nm_setting_wireless_class_init(NMSettingWirelessClass *klass) * * Since: 1.12 **/ - obj_properties[PROP_WAKE_ON_WLAN] = - g_param_spec_uint(NM_SETTING_WIRELESS_WAKE_ON_WLAN, - "", - "", - 0, - G_MAXUINT32, - NM_SETTING_WIRELESS_WAKE_ON_WLAN_DEFAULT, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_uint32(properties_override, + obj_properties, + NM_SETTING_WIRELESS_WAKE_ON_WLAN, + PROP_WAKE_ON_WLAN, + 0, + G_MAXUINT32, + NM_SETTING_WIRELESS_WAKE_ON_WLAN_DEFAULT, + NM_SETTING_PARAM_NONE, + NMSettingWirelessPrivate, + wake_on_wlan); /** * NMSettingWireless:ap-isolation @@ -1924,13 +1879,13 @@ nm_setting_wireless_class_init(NMSettingWirelessClass *klass) * description: Whether AP isolation is enabled * ---end--- */ - obj_properties[PROP_AP_ISOLATION] = g_param_spec_enum( - NM_SETTING_WIRELESS_AP_ISOLATION, - "", - "", - NM_TYPE_TERNARY, - NM_TERNARY_DEFAULT, - NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_direct_ternary_enum(properties_override, + obj_properties, + NM_SETTING_WIRELESS_AP_ISOLATION, + PROP_AP_ISOLATION, + NM_SETTING_PARAM_FUZZY_IGNORE, + NMSettingWirelessPrivate, + ap_isolation); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-wpan.c b/src/libnm-core-impl/nm-setting-wpan.c index 78cdc036..9e25dd16 100644 --- a/src/libnm-core-impl/nm-setting-wpan.c +++ b/src/libnm-core-impl/nm-setting-wpan.c @@ -42,7 +42,7 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_MAC_ADDRESS, PROP_CHANNEL, ); typedef struct { - char * mac_address; + char *mac_address; guint32 pan_id; guint32 short_address; gint32 page; @@ -222,9 +222,9 @@ nm_setting_wpan_new(void) static void nm_setting_wpan_class_init(NMSettingWpanClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSettingClass *setting_class = NM_SETTING_CLASS(klass); - GArray * properties_override = _nm_sett_info_property_override_create_array(); + GArray *properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(setting_class, sizeof(NMSettingWpanPrivate)); diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index 9ef9e96c..be88effb 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -8,11 +8,13 @@ #include "nm-setting.h" -#include "nm-setting-private.h" -#include "nm-utils.h" #include "libnm-core-intern/nm-core-internal.h" -#include "nm-utils-private.h" +#include "libnm-glib-aux/nm-ref-string.h" +#include "libnm-glib-aux/nm-secret-utils.h" #include "nm-property-compare.h" +#include "nm-setting-private.h" +#include "nm-utils-private.h" +#include "nm-utils.h" /** * SECTION:nm-setting @@ -29,13 +31,13 @@ /*****************************************************************************/ typedef struct { - GHashTable * hash; + GHashTable *hash; const char **names; - GVariant ** values; + GVariant **values; } GenData; typedef struct { - const char * name; + const char *name; GType type; NMSettingPriority priority; } SettingInfo; @@ -55,8 +57,8 @@ G_DEFINE_ABSTRACT_TYPE(NMSetting, nm_setting, G_TYPE_OBJECT) static GenData *_gendata_hash(NMSetting *setting, gboolean create_if_necessary); static gboolean set_property_from_dbus(const NMSettInfoProperty *property_info, - GVariant * src_value, - GValue * dst_value); + GVariant *src_value, + GValue *dst_value); /*****************************************************************************/ @@ -148,7 +150,7 @@ _nm_setting_slave_type_is_valid(const char *slave_type, const char **out_port_ty static const NMSettInfoProperty * _nm_sett_info_property_find_in_array(const NMSettInfoProperty *properties, guint len, - const char * name) + const char *name) { guint i; @@ -234,7 +236,7 @@ _property_infos_sort_cmp_setting_connection(gconstpointer p_a, static const NMSettInfoProperty *const * _property_infos_sort(const NMSettInfoProperty *property_infos, guint16 property_infos_len, - NMSettingClass * setting_class) + NMSettingClass *setting_class) { const NMSettInfoProperty **arr; guint16 i; @@ -280,14 +282,14 @@ _property_lookup_by_param_spec_sort(gconstpointer p_a, gconstpointer p_b, gpoint } void -_nm_setting_class_commit(NMSettingClass * setting_class, +_nm_setting_class_commit(NMSettingClass *setting_class, NMMetaSettingType meta_type, const NMSettInfoSettDetail *detail, - GArray * properties_override, + GArray *properties_override, gint16 private_offset) { - NMSettInfoSetting *sett_info; - gs_free GParamSpec ** property_specs = NULL; + NMSettInfoSetting *sett_info; + gs_free GParamSpec **property_specs = NULL; guint n_property_specs; NMSettInfoPropertLookupByParamSpec *lookup_by_iter; guint override_len; @@ -350,7 +352,7 @@ _nm_setting_class_commit(NMSettingClass * setting_class, #endif for (i = 0; i < n_property_specs; i++) { - const char * name = property_specs[i]->name; + const char *name = property_specs[i]->name; NMSettInfoProperty *p; if (_nm_sett_info_property_find_in_array((NMSettInfoProperty *) properties_override->data, @@ -375,55 +377,27 @@ _nm_setting_class_commit(NMSettingClass * setting_class, nm_assert(p->param_spec); vtype = p->param_spec->value_type; - if (vtype == G_TYPE_INT) - p->property_type = &nm_sett_info_propert_type_plain_i; - else if (vtype == G_TYPE_UINT) - p->property_type = &nm_sett_info_propert_type_plain_u; - else if (vtype == G_TYPE_INT64) - p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( - G_VARIANT_TYPE_INT64, - .compare_fcn = _nm_setting_property_compare_fcn_default, - .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, - .from_dbus_is_full = TRUE); - else if (vtype == G_TYPE_STRING) { - nm_assert(nm_streq(p->name, NM_SETTING_NAME) - == (!NM_FLAGS_HAS(p->param_spec->flags, G_PARAM_WRITABLE))); - if (!NM_FLAGS_HAS(p->param_spec->flags, G_PARAM_WRITABLE)) - p->property_type = &nm_sett_info_propert_type_setting_name; - else { - p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( - G_VARIANT_TYPE_STRING, - .compare_fcn = _nm_setting_property_compare_fcn_default, - .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, - .from_dbus_is_full = TRUE); - } - } else if (vtype == G_TYPE_DOUBLE) - p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( - G_VARIANT_TYPE_DOUBLE, - .compare_fcn = _nm_setting_property_compare_fcn_default, - .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, - .from_dbus_is_full = TRUE); - else if (vtype == G_TYPE_STRV) + + if (vtype == G_TYPE_STRING) { + /* The "name" property is a bit special because it's defined in the + * parent class NMSetting. We set the property_type here, because + * it's more convenient (albeit a bit ugly). + * + * FIXME: let _nm_sett_info_property_override_create_array() always add + * the handling of the name property.*/ + nm_assert(nm_streq(p->name, NM_SETTING_NAME)); + nm_assert(!NM_FLAGS_HAS(p->param_spec->flags, G_PARAM_WRITABLE)); + p->property_type = &nm_sett_info_propert_type_setting_name; + goto has_property_type; + } + + if (vtype == G_TYPE_STRV) p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( G_VARIANT_TYPE_STRING_ARRAY, .compare_fcn = _nm_setting_property_compare_fcn_default, .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, .from_dbus_is_full = TRUE); - else if (g_type_is_a(vtype, G_TYPE_ENUM)) { - p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( - G_VARIANT_TYPE_INT32, - .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_ENUM, - .compare_fcn = _nm_setting_property_compare_fcn_default, - .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, - .from_dbus_is_full = TRUE); - } else if (g_type_is_a(vtype, G_TYPE_FLAGS)) { - p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( - G_VARIANT_TYPE_UINT32, - .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_FLAGS, - .compare_fcn = _nm_setting_property_compare_fcn_default, - .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, - .from_dbus_is_full = TRUE); - } else + else nm_assert_not_reached(); has_property_type: @@ -493,7 +467,7 @@ has_property_type: const NMSettInfoProperty * _nm_sett_info_setting_get_property_info(const NMSettInfoSetting *sett_info, - const char * property_name) + const char *property_name) { const NMSettInfoProperty *property_info; gssize idx; @@ -539,7 +513,7 @@ _nm_setting_class_get_sett_info(NMSettingClass *setting_class) const NMSettInfoProperty * _nm_sett_info_property_lookup_by_param_spec(const NMSettInfoSetting *sett_info, - const GParamSpec * param_spec) + const GParamSpec *param_spec) { NMSettInfoPropertLookupByParamSpec needle; int imin; @@ -610,8 +584,8 @@ _nm_setting_emit_property_changed(NMSetting *setting) /*****************************************************************************/ gboolean -_nm_setting_use_legacy_property(NMSetting * setting, - GVariant * connection_dict, +_nm_setting_use_legacy_property(NMSetting *setting, + GVariant *connection_dict, const char *legacy_property, const char *new_property) { @@ -656,33 +630,74 @@ _nm_setting_use_legacy_property(NMSetting * setting, /*****************************************************************************/ static gboolean -_property_direct_set_string(const NMSettInfoProperty *property_info, char **dst, const char *src) +_property_direct_set_string(const NMSettInfoSetting *sett_info, + const NMSettInfoProperty *property_info, + NMSetting *setting, + const char *src) { - if (property_info->direct_set_string_ascii_strdown) - return nm_strdup_reset_take(dst, src ? g_ascii_strdown(src, -1) : NULL); + char **dst; + char *s; + + nm_assert(property_info->property_type->direct_type == NM_VALUE_TYPE_STRING); + nm_assert(((!!property_info->direct_set_string_ascii_strdown) + + (!!property_info->direct_set_string_strip) + + (!!property_info->direct_string_is_refstr) + + (property_info->direct_set_string_mac_address_len > 0) + + (property_info->direct_set_string_ip_address_addr_family != 0)) + <= (property_info->direct_hook.set_string_fcn ? 0 : 1)); + + if (property_info->direct_hook.set_string_fcn) { + return property_info->direct_hook.set_string_fcn(sett_info, property_info, setting, src); + } + + dst = _nm_setting_get_private_field(setting, sett_info, property_info); + + if (property_info->direct_string_is_refstr) { + nm_assert(property_info->param_spec); + nm_assert(!NM_FLAGS_HAS(property_info->param_spec->flags, NM_SETTING_PARAM_SECRET)); + return nm_ref_string_reset_str_upcast((const char **) dst, src); + } + + if (property_info->direct_set_string_ascii_strdown) { + s = src ? g_ascii_strdown(src, -1) : NULL; + goto out_take; + } + if (property_info->direct_set_string_strip) { + s = nm_strstrip_dup(src); + goto out_take; + } if (property_info->direct_set_string_mac_address_len > 0) { - return nm_strdup_reset_take(dst, - _nm_utils_hwaddr_canonical_or_invalid( - src, - property_info->direct_set_string_mac_address_len)); + s = _nm_utils_hwaddr_canonical_or_invalid(src, + property_info->direct_set_string_mac_address_len); + goto out_take; } if (property_info->direct_set_string_ip_address_addr_family != 0) { - return nm_strdup_reset_take(dst, - _nm_utils_ipaddr_canonical_or_invalid( - property_info->direct_set_string_ip_address_addr_family, - src)); - } + s = _nm_utils_ipaddr_canonical_or_invalid( + property_info->direct_set_string_ip_address_addr_family - 1, + src, + property_info->direct_set_string_ip_address_addr_family_map_zero_to_null); + goto out_take; + } else + nm_assert(!property_info->direct_set_string_ip_address_addr_family_map_zero_to_null); + + if (NM_FLAGS_HAS(property_info->param_spec->flags, NM_SETTING_PARAM_SECRET)) + return nm_strdup_reset_secret(dst, src); + return nm_strdup_reset(dst, src); + +out_take: + nm_assert(!NM_FLAGS_HAS(property_info->param_spec->flags, NM_SETTING_PARAM_SECRET)); + return nm_strdup_reset_take(dst, s); } void -_nm_setting_property_get_property_direct(GObject * object, +_nm_setting_property_get_property_direct(GObject *object, guint prop_id, - GValue * value, + GValue *value, GParamSpec *pspec) { - NMSetting * setting = NM_SETTING(object); - const NMSettInfoSetting * sett_info; + NMSetting *setting = NM_SETTING(object); + const NMSettInfoSetting *sett_info; const NMSettInfoProperty *property_info; sett_info = _nm_setting_class_get_sett_info(NM_SETTING_GET_CLASS(setting)); @@ -697,56 +712,56 @@ _nm_setting_property_get_property_direct(GObject * object, switch (property_info->property_type->direct_type) { case NM_VALUE_TYPE_BOOL: { - const bool *p_val = - _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + const bool *p_val = _nm_setting_get_private_field(setting, sett_info, property_info); g_value_set_boolean(value, *p_val); return; } case NM_VALUE_TYPE_INT32: { - const gint32 *p_val = - _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + const gint32 *p_val = _nm_setting_get_private_field(setting, sett_info, property_info); g_value_set_int(value, *p_val); return; } case NM_VALUE_TYPE_UINT32: { - const guint32 *p_val = - _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + const guint32 *p_val = _nm_setting_get_private_field(setting, sett_info, property_info); g_value_set_uint(value, *p_val); return; } + case NM_VALUE_TYPE_INT64: + { + const gint64 *p_val = _nm_setting_get_private_field(setting, sett_info, property_info); + + g_value_set_int64(value, *p_val); + return; + } case NM_VALUE_TYPE_UINT64: { - const guint64 *p_val = - _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + const guint64 *p_val = _nm_setting_get_private_field(setting, sett_info, property_info); g_value_set_uint64(value, *p_val); return; } case NM_VALUE_TYPE_ENUM: { - const int *p_val = - _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + const int *p_val = _nm_setting_get_private_field(setting, sett_info, property_info); g_value_set_enum(value, *p_val); return; } case NM_VALUE_TYPE_FLAGS: { - const guint *p_val = - _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + const guint *p_val = _nm_setting_get_private_field(setting, sett_info, property_info); g_value_set_flags(value, *p_val); return; } case NM_VALUE_TYPE_STRING: { - const char *const *p_val = - _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + const char *const *p_val = _nm_setting_get_private_field(setting, sett_info, property_info); g_value_set_string(value, *p_val); return; @@ -754,7 +769,7 @@ _nm_setting_property_get_property_direct(GObject * object, case NM_VALUE_TYPE_BYTES: { const GBytes *const *p_val = - _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + _nm_setting_get_private_field(setting, sett_info, property_info); g_value_set_boxed(value, *p_val); return; @@ -770,13 +785,13 @@ out_fail: } void -_nm_setting_property_set_property_direct(GObject * object, +_nm_setting_property_set_property_direct(GObject *object, guint prop_id, const GValue *value, - GParamSpec * pspec) + GParamSpec *pspec) { - NMSetting * setting = NM_SETTING(object); - const NMSettInfoSetting * sett_info; + NMSetting *setting = NM_SETTING(object); + const NMSettInfoSetting *sett_info; const NMSettInfoProperty *property_info; sett_info = _nm_setting_class_get_sett_info(NM_SETTING_GET_CLASS(setting)); @@ -791,7 +806,7 @@ _nm_setting_property_set_property_direct(GObject * object, switch (property_info->property_type->direct_type) { case NM_VALUE_TYPE_BOOL: { - bool * p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + bool *p_val = _nm_setting_get_private_field(setting, sett_info, property_info); gboolean v; v = g_value_get_boolean(value); @@ -802,7 +817,7 @@ _nm_setting_property_set_property_direct(GObject * object, } case NM_VALUE_TYPE_INT32: { - gint32 *p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + gint32 *p_val = _nm_setting_get_private_field(setting, sett_info, property_info); int v; v = g_value_get_int(value); @@ -817,7 +832,7 @@ _nm_setting_property_set_property_direct(GObject * object, } case NM_VALUE_TYPE_UINT32: { - guint32 *p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + guint32 *p_val = _nm_setting_get_private_field(setting, sett_info, property_info); guint v; v = g_value_get_uint(value); @@ -830,9 +845,20 @@ _nm_setting_property_set_property_direct(GObject * object, nm_assert(*p_val == v); goto out_notify; } + case NM_VALUE_TYPE_INT64: + { + gint64 *p_val = _nm_setting_get_private_field(setting, sett_info, property_info); + gint64 v; + + v = g_value_get_int64(value); + if (*p_val == v) + return; + *p_val = v; + goto out_notify; + } case NM_VALUE_TYPE_UINT64: { - guint64 *p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + guint64 *p_val = _nm_setting_get_private_field(setting, sett_info, property_info); guint64 v; v = g_value_get_uint64(value); @@ -843,7 +869,7 @@ _nm_setting_property_set_property_direct(GObject * object, } case NM_VALUE_TYPE_ENUM: { - int *p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + int *p_val = _nm_setting_get_private_field(setting, sett_info, property_info); int v; v = g_value_get_enum(value); @@ -854,7 +880,7 @@ _nm_setting_property_set_property_direct(GObject * object, } case NM_VALUE_TYPE_FLAGS: { - guint *p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + guint *p_val = _nm_setting_get_private_field(setting, sett_info, property_info); guint v; v = g_value_get_flags(value); @@ -864,16 +890,16 @@ _nm_setting_property_set_property_direct(GObject * object, goto out_notify; } case NM_VALUE_TYPE_STRING: - if (!_property_direct_set_string( - property_info, - _nm_setting_get_private(setting, sett_info, property_info->direct_offset), - g_value_get_string(value))) + if (!_property_direct_set_string(sett_info, + property_info, + setting, + g_value_get_string(value))) return; goto out_notify; case NM_VALUE_TYPE_BYTES: { - GBytes **p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset); - GBytes * v; + GBytes **p_val = _nm_setting_get_private_field(setting, sett_info, property_info); + GBytes *v; _nm_unused gs_unref_bytes GBytes *old = NULL; v = g_value_get_boxed(value); @@ -923,7 +949,7 @@ _init_direct(NMSetting *setting) break; case NM_VALUE_TYPE_BOOL: { - bool *p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + bool *p_val = _nm_setting_get_private_field(setting, sett_info, property_info); gboolean def_val; def_val = NM_G_PARAM_SPEC_GET_DEFAULT_BOOLEAN(property_info->param_spec); @@ -933,9 +959,8 @@ _init_direct(NMSetting *setting) } case NM_VALUE_TYPE_INT32: { - gint32 *p_val = - _nm_setting_get_private(setting, sett_info, property_info->direct_offset); - int def_val; + gint32 *p_val = _nm_setting_get_private_field(setting, sett_info, property_info); + int def_val; def_val = NM_G_PARAM_SPEC_GET_DEFAULT_INT(property_info->param_spec); nm_assert(*p_val == 0); @@ -944,20 +969,28 @@ _init_direct(NMSetting *setting) } case NM_VALUE_TYPE_UINT32: { - guint32 *p_val = - _nm_setting_get_private(setting, sett_info, property_info->direct_offset); - guint def_val; + guint32 *p_val = _nm_setting_get_private_field(setting, sett_info, property_info); + guint def_val; def_val = NM_G_PARAM_SPEC_GET_DEFAULT_UINT(property_info->param_spec); nm_assert(*p_val == 0); *p_val = def_val; break; } + case NM_VALUE_TYPE_INT64: + { + gint64 *p_val = _nm_setting_get_private_field(setting, sett_info, property_info); + gint64 def_val; + + def_val = NM_G_PARAM_SPEC_GET_DEFAULT_INT64(property_info->param_spec); + nm_assert(*p_val == 0); + *p_val = def_val; + break; + } case NM_VALUE_TYPE_UINT64: { - guint64 *p_val = - _nm_setting_get_private(setting, sett_info, property_info->direct_offset); - guint64 def_val; + guint64 *p_val = _nm_setting_get_private_field(setting, sett_info, property_info); + guint64 def_val; def_val = NM_G_PARAM_SPEC_GET_DEFAULT_UINT64(property_info->param_spec); nm_assert(*p_val == 0); @@ -966,7 +999,7 @@ _init_direct(NMSetting *setting) } case NM_VALUE_TYPE_ENUM: { - int *p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + int *p_val = _nm_setting_get_private_field(setting, sett_info, property_info); int def_val; def_val = NM_G_PARAM_SPEC_GET_DEFAULT_ENUM(property_info->param_spec); @@ -976,9 +1009,8 @@ _init_direct(NMSetting *setting) } case NM_VALUE_TYPE_FLAGS: { - guint *p_val = - _nm_setting_get_private(setting, sett_info, property_info->direct_offset); - guint def_val; + guint *p_val = _nm_setting_get_private_field(setting, sett_info, property_info); + guint def_val; def_val = NM_G_PARAM_SPEC_GET_DEFAULT_FLAGS(property_info->param_spec); nm_assert(*p_val == 0); @@ -987,14 +1019,12 @@ _init_direct(NMSetting *setting) } case NM_VALUE_TYPE_STRING: nm_assert(!NM_G_PARAM_SPEC_GET_DEFAULT_STRING(property_info->param_spec)); - nm_assert(!( - *((const char *const *) - _nm_setting_get_private(setting, sett_info, property_info->direct_offset)))); + nm_assert(!(*((const char *const *) + _nm_setting_get_private_field(setting, sett_info, property_info)))); break; case NM_VALUE_TYPE_BYTES: - nm_assert(!( - *((const GBytes *const *) - _nm_setting_get_private(setting, sett_info, property_info->direct_offset)))); + nm_assert(!(*((const GBytes *const *) + _nm_setting_get_private_field(setting, sett_info, property_info)))); break; default: nm_assert_not_reached(); @@ -1027,22 +1057,26 @@ _finalize_direct(NMSetting *setting) case NM_VALUE_TYPE_BOOL: case NM_VALUE_TYPE_INT32: case NM_VALUE_TYPE_UINT32: + case NM_VALUE_TYPE_INT64: case NM_VALUE_TYPE_UINT64: case NM_VALUE_TYPE_ENUM: case NM_VALUE_TYPE_FLAGS: break; case NM_VALUE_TYPE_STRING: { - char **p_val = - _nm_setting_get_private(setting, sett_info, property_info->direct_offset); - - nm_clear_g_free(p_val); + char **p_val = _nm_setting_get_private_field(setting, sett_info, property_info); + + if (property_info->direct_string_is_refstr) + nm_clear_pointer(p_val, nm_ref_string_unref_upcast); + else if (NM_FLAGS_HAS(property_info->param_spec->flags, NM_SETTING_PARAM_SECRET)) + nm_clear_pointer(p_val, nm_free_secret); + else + nm_clear_g_free(p_val); break; } case NM_VALUE_TYPE_BYTES: { - GBytes **p_val = - _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + GBytes **p_val = _nm_setting_get_private_field(setting, sett_info, property_info); nm_clear_pointer(p_val, g_bytes_unref); break; @@ -1064,7 +1098,7 @@ _nm_setting_property_to_dbus_fcn_direct(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_ { gboolean val; - val = *((bool *) _nm_setting_get_private(setting, sett_info, property_info->direct_offset)); + val = *((bool *) _nm_setting_get_private_field(setting, sett_info, property_info)); if (!property_info->to_dbus_including_default && val == NM_G_PARAM_SPEC_GET_DEFAULT_BOOLEAN(property_info->param_spec)) return NULL; @@ -1074,8 +1108,7 @@ _nm_setting_property_to_dbus_fcn_direct(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_ { gint32 val; - val = - *((gint32 *) _nm_setting_get_private(setting, sett_info, property_info->direct_offset)); + val = *((gint32 *) _nm_setting_get_private_field(setting, sett_info, property_info)); if (!property_info->to_dbus_including_default && val == NM_G_PARAM_SPEC_GET_DEFAULT_INT(property_info->param_spec)) return NULL; @@ -1085,19 +1118,27 @@ _nm_setting_property_to_dbus_fcn_direct(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_ { guint32 val; - val = *( - (guint32 *) _nm_setting_get_private(setting, sett_info, property_info->direct_offset)); + val = *((guint32 *) _nm_setting_get_private_field(setting, sett_info, property_info)); if (!property_info->to_dbus_including_default && val == NM_G_PARAM_SPEC_GET_DEFAULT_UINT(property_info->param_spec)) return NULL; return g_variant_new_uint32(val); } + case NM_VALUE_TYPE_INT64: + { + gint64 val; + + val = *((gint64 *) _nm_setting_get_private_field(setting, sett_info, property_info)); + if (!property_info->to_dbus_including_default + && val == NM_G_PARAM_SPEC_GET_DEFAULT_INT64(property_info->param_spec)) + return NULL; + return g_variant_new_int64(val); + } case NM_VALUE_TYPE_UINT64: { guint64 val; - val = *( - (guint64 *) _nm_setting_get_private(setting, sett_info, property_info->direct_offset)); + val = *((guint64 *) _nm_setting_get_private_field(setting, sett_info, property_info)); if (!property_info->to_dbus_including_default && val == NM_G_PARAM_SPEC_GET_DEFAULT_UINT64(property_info->param_spec)) return NULL; @@ -1107,7 +1148,7 @@ _nm_setting_property_to_dbus_fcn_direct(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_ { int val; - val = *((int *) _nm_setting_get_private(setting, sett_info, property_info->direct_offset)); + val = *((int *) _nm_setting_get_private_field(setting, sett_info, property_info)); if (!property_info->to_dbus_including_default && val == NM_G_PARAM_SPEC_GET_DEFAULT_ENUM(property_info->param_spec)) return NULL; @@ -1117,8 +1158,7 @@ _nm_setting_property_to_dbus_fcn_direct(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_ { guint val; - val = - *((guint *) _nm_setting_get_private(setting, sett_info, property_info->direct_offset)); + val = *((guint *) _nm_setting_get_private_field(setting, sett_info, property_info)); if (!property_info->to_dbus_including_default && val == NM_G_PARAM_SPEC_GET_DEFAULT_FLAGS(property_info->param_spec)) return NULL; @@ -1136,9 +1176,8 @@ _nm_setting_property_to_dbus_fcn_direct(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_ nm_assert(!NM_G_PARAM_SPEC_GET_DEFAULT_STRING(property_info->param_spec)); nm_assert(!property_info->to_dbus_including_default); - val = *((const char *const *) _nm_setting_get_private(setting, - sett_info, - property_info->direct_offset)); + val = *( + (const char *const *) _nm_setting_get_private_field(setting, sett_info, property_info)); if (!val) return NULL; if (!val[0]) @@ -1153,9 +1192,9 @@ _nm_setting_property_to_dbus_fcn_direct(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_ * (but it could have). */ nm_assert(!property_info->to_dbus_including_default); - val = *((const GBytes *const *) _nm_setting_get_private(setting, - sett_info, - property_info->direct_offset)); + val = *((const GBytes *const *) _nm_setting_get_private_field(setting, + sett_info, + property_info)); if (!val) return NULL; return nm_g_bytes_to_variant_ay(val); @@ -1175,9 +1214,7 @@ _nm_setting_property_to_dbus_fcn_direct_mac_address(_NM_SETT_INFO_PROP_TO_DBUS_F nm_assert(!NM_G_PARAM_SPEC_GET_DEFAULT_STRING(property_info->param_spec)); nm_assert(!property_info->to_dbus_including_default); - val = *((const char *const *) _nm_setting_get_private(setting, - sett_info, - property_info->direct_offset)); + val = *((const char *const *) _nm_setting_get_private_field(setting, sett_info, property_info)); return nm_utils_hwaddr_to_dbus(val); } @@ -1209,10 +1246,6 @@ _nm_setting_property_to_dbus_fcn_gprop(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_n switch (property_info->property_type->typdata_to_dbus.gprop_type) { case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_DEFAULT: return g_dbus_gvalue_to_gvariant(&prop_value, property_info->property_type->dbus_type); - case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_ENUM: - return nm_g_variant_maybe_singleton_i(g_value_get_enum(&prop_value)); - case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_FLAGS: - return g_variant_new_uint32(g_value_get_flags(&prop_value)); case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_GARRAY_UINT: G_STATIC_ASSERT_EXPR(sizeof(guint) == sizeof(guint32)); nm_assert(G_VALUE_HOLDS(&prop_value, G_TYPE_ARRAY)); @@ -1249,9 +1282,8 @@ _nm_setting_property_from_dbus_fcn_direct_mac_address(_NM_SETT_INFO_PROP_FROM_DB array = g_variant_get_fixed_array(value, &length, 1); - if (nm_strdup_reset_take( - _nm_setting_get_private(setting, sett_info, property_info->direct_offset), - length > 0 ? nm_utils_hwaddr_ntoa(array, length) : NULL)) { + if (nm_strdup_reset_take(_nm_setting_get_private_field(setting, sett_info, property_info), + length > 0 ? nm_utils_hwaddr_ntoa(array, length) : NULL)) { g_object_notify_by_pspec(G_OBJECT(setting), property_info->param_spec); } else *out_is_modified = FALSE; @@ -1271,7 +1303,7 @@ _nm_setting_property_from_dbus_fcn_direct(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS ({ \ const NMSettInfoProperty const *_property_info = (property_info); \ const GType _gtype = (gtype); \ - GVariant * _value = (value); \ + GVariant *_value = (value); \ gboolean _success = FALSE; \ \ nm_assert(_property_info->param_spec->value_type == _gtype); \ @@ -1292,7 +1324,7 @@ _nm_setting_property_from_dbus_fcn_direct(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS switch (property_info->property_type->direct_type) { case NM_VALUE_TYPE_BOOL: { - bool * p_val; + bool *p_val; gboolean v; if (g_variant_is_of_type(value, G_VARIANT_TYPE_BOOLEAN)) @@ -1307,7 +1339,7 @@ _nm_setting_property_from_dbus_fcn_direct(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS v = !!v; } - p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + p_val = _nm_setting_get_private_field(setting, sett_info, property_info); if (*p_val == v) goto out_unchanged; *p_val = v; @@ -1316,7 +1348,7 @@ _nm_setting_property_from_dbus_fcn_direct(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS case NM_VALUE_TYPE_INT32: { const GParamSpecInt *param_spec; - gint32 * p_val; + gint32 *p_val; int v; if (g_variant_is_of_type(value, G_VARIANT_TYPE_INT32)) { @@ -1331,7 +1363,7 @@ _nm_setting_property_from_dbus_fcn_direct(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS goto out_error_wrong_dbus_type; } - p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + p_val = _nm_setting_get_private_field(setting, sett_info, property_info); if (*p_val == v) goto out_unchanged; @@ -1344,7 +1376,7 @@ _nm_setting_property_from_dbus_fcn_direct(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS case NM_VALUE_TYPE_UINT32: { const GParamSpecUInt *param_spec; - guint32 * p_val; + guint32 *p_val; guint v; if (g_variant_is_of_type(value, G_VARIANT_TYPE_UINT32)) { @@ -1359,7 +1391,7 @@ _nm_setting_property_from_dbus_fcn_direct(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS goto out_error_wrong_dbus_type; } - p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + p_val = _nm_setting_get_private_field(setting, sett_info, property_info); if (*p_val == v) goto out_unchanged; @@ -1369,10 +1401,37 @@ _nm_setting_property_from_dbus_fcn_direct(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS *p_val = v; goto out_notify; } + case NM_VALUE_TYPE_INT64: + { + const GParamSpecInt64 *param_spec; + gint64 *p_val; + gint64 v; + + if (g_variant_is_of_type(value, G_VARIANT_TYPE_INT64)) + v = g_variant_get_int64(value); + else { + if (!_variant_get_value_transform(property_info, + value, + G_TYPE_INT64, + g_value_get_int64, + &v)) + goto out_error_wrong_dbus_type; + } + + p_val = _nm_setting_get_private_field(setting, sett_info, property_info); + if (*p_val == v) + goto out_unchanged; + + param_spec = NM_G_PARAM_SPEC_CAST_INT64(property_info->param_spec); + if (v < param_spec->minimum || v > param_spec->maximum) + goto out_error_param_spec_validation; + *p_val = v; + goto out_notify; + } case NM_VALUE_TYPE_UINT64: { const GParamSpecUInt64 *param_spec; - guint64 * p_val; + guint64 *p_val; guint64 v; if (g_variant_is_of_type(value, G_VARIANT_TYPE_UINT64)) @@ -1386,7 +1445,7 @@ _nm_setting_property_from_dbus_fcn_direct(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS goto out_error_wrong_dbus_type; } - p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + p_val = _nm_setting_get_private_field(setting, sett_info, property_info); if (*p_val == v) goto out_unchanged; @@ -1399,7 +1458,7 @@ _nm_setting_property_from_dbus_fcn_direct(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS case NM_VALUE_TYPE_ENUM: { const GParamSpecEnum *param_spec; - int * p_val; + int *p_val; int v; param_spec = NM_G_PARAM_SPEC_CAST_ENUM(property_info->param_spec); @@ -1416,7 +1475,7 @@ _nm_setting_property_from_dbus_fcn_direct(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS goto out_error_wrong_dbus_type; } - p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + p_val = _nm_setting_get_private_field(setting, sett_info, property_info); if (*p_val == v) goto out_unchanged; @@ -1428,7 +1487,7 @@ _nm_setting_property_from_dbus_fcn_direct(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS case NM_VALUE_TYPE_FLAGS: { const GParamSpecFlags *param_spec; - guint * p_val; + guint *p_val; guint v; param_spec = NM_G_PARAM_SPEC_CAST_FLAGS(property_info->param_spec); @@ -1445,7 +1504,7 @@ _nm_setting_property_from_dbus_fcn_direct(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS goto out_error_wrong_dbus_type; } - p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + p_val = _nm_setting_get_private_field(setting, sett_info, property_info); if (*p_val == v) goto out_unchanged; @@ -1457,8 +1516,8 @@ _nm_setting_property_from_dbus_fcn_direct(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS case NM_VALUE_TYPE_STRING: { gs_free char *v_free = NULL; - char ** p_val; - const char * v; + const char *v; + gboolean changed; if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) { v = g_variant_get_string(value, NULL); @@ -1472,23 +1531,26 @@ _nm_setting_property_from_dbus_fcn_direct(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS v = v_free; } - p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset); - if (!_property_direct_set_string(property_info, p_val, v)) - goto out_unchanged; + changed = _property_direct_set_string(sett_info, property_info, setting, v); + + if (NM_FLAGS_HAS(property_info->param_spec->flags, NM_SETTING_PARAM_SECRET)) + nm_clear_pointer(&v_free, nm_free_secret); + if (!changed) + goto out_unchanged; goto out_notify; } case NM_VALUE_TYPE_BYTES: { gs_unref_bytes GBytes *v = NULL; - GBytes ** p_val; + GBytes **p_val; if (!g_variant_is_of_type(value, G_VARIANT_TYPE_BYTESTRING)) goto out_error_wrong_dbus_type; v = nm_g_bytes_new_from_variant_ay(value); - p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset); + p_val = _nm_setting_get_private_field(setting, sett_info, property_info); if (nm_g_bytes_equal0(*p_val, v)) goto out_unchanged; @@ -1542,7 +1604,7 @@ gboolean _nm_setting_property_from_dbus_fcn_gprop(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) { nm_auto_unset_gvalue GValue object_value = G_VALUE_INIT; - gs_free_error GError *local = NULL; + gs_free_error GError *local = NULL; nm_assert(property_info->param_spec); @@ -1586,10 +1648,10 @@ _nm_setting_property_from_dbus_fcn_gprop(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _ } static GVariant * -property_to_dbus(const NMSettInfoSetting * sett_info, - const NMSettInfoProperty * property_info, - NMConnection * connection, - NMSetting * setting, +property_to_dbus(const NMSettInfoSetting *sett_info, + const NMSettInfoProperty *property_info, + NMConnection *connection, + NMSetting *setting, NMConnectionSerializationFlags flags, const NMConnectionSerializationOptions *options, gboolean ignore_flags) @@ -1646,8 +1708,8 @@ property_to_dbus(const NMSettInfoSetting * sett_info, static gboolean set_property_from_dbus(const NMSettInfoProperty *property_info, - GVariant * src_value, - GValue * dst_value) + GVariant *src_value, + GValue *dst_value) { nm_assert(property_info->param_spec); nm_assert(property_info->property_type->dbus_type); @@ -1687,18 +1749,18 @@ set_property_from_dbus(const NMSettInfoProperty *property_info, * properties **/ GVariant * -_nm_setting_to_dbus(NMSetting * setting, - NMConnection * connection, +_nm_setting_to_dbus(NMSetting *setting, + NMConnection *connection, NMConnectionSerializationFlags flags, const NMConnectionSerializationOptions *options) { - NMSettingPrivate * priv; + NMSettingPrivate *priv; GVariantBuilder builder; const NMSettInfoSetting *sett_info; guint n_properties; guint i; guint16 j; - const char *const * gendata_keys; + const char *const *gendata_keys; g_return_val_if_fail(NM_IS_SETTING(setting), NULL); @@ -1716,8 +1778,8 @@ _nm_setting_to_dbus(NMSetting * setting, sett_info = _nm_setting_class_get_sett_info(NM_SETTING_GET_CLASS(setting)); for (j = 0; j < sett_info->property_infos_len; j++) { - const NMSettInfoProperty *property_info = &sett_info->property_infos[j]; - gs_unref_variant GVariant *dbus_value = NULL; + const NMSettInfoProperty *property_info = &sett_info->property_infos[j]; + gs_unref_variant GVariant *dbus_value = NULL; dbus_value = property_to_dbus(sett_info, property_info, connection, setting, flags, options, FALSE); @@ -1751,14 +1813,14 @@ _nm_setting_to_dbus(NMSetting * setting, **/ NMSetting * _nm_setting_new_from_dbus(GType setting_type, - GVariant * setting_dict, - GVariant * connection_dict, + GVariant *setting_dict, + GVariant *connection_dict, NMSettingParseFlags parse_flags, - GError ** error) + GError **error) { - gs_unref_ptrarray GPtrArray *keys_keep_variant = NULL; - gs_unref_object NMSetting *setting = NULL; - gs_unref_hashtable GHashTable *keys = NULL; + gs_unref_ptrarray GPtrArray *keys_keep_variant = NULL; + gs_unref_object NMSetting *setting = NULL; + gs_unref_hashtable GHashTable *keys = NULL; g_return_val_if_fail(G_TYPE_IS_INSTANTIATABLE(setting_type), NULL); g_return_val_if_fail(g_variant_is_of_type(setting_dict, NM_VARIANT_TYPE_SETTING), NULL); @@ -1783,8 +1845,8 @@ _nm_setting_new_from_dbus(GType setting_type, if (NM_FLAGS_HAS(parse_flags, NM_SETTING_PARSE_FLAGS_STRICT)) { GVariantIter iter; - GVariant * entry, *entry_key; - const char * key; + GVariant *entry, *entry_key; + const char *key; keys_keep_variant = g_ptr_array_new_with_free_func((GDestroyNotify) g_variant_unref); keys = g_hash_table_new(nm_str_hash, g_str_equal); @@ -1813,7 +1875,7 @@ _nm_setting_new_from_dbus(GType setting_type, if (NM_FLAGS_HAS(parse_flags, NM_SETTING_PARSE_FLAGS_STRICT) && g_hash_table_size(keys) > 0) { GHashTableIter iter; - const char * key; + const char *key; g_hash_table_iter_init(&iter, keys); if (g_hash_table_iter_next(&iter, (gpointer *) &key, NULL)) { @@ -1830,14 +1892,14 @@ _nm_setting_new_from_dbus(GType setting_type, } static gboolean -_property_set_from_dbus(const NMSettInfoSetting * sett_info, +_property_set_from_dbus(const NMSettInfoSetting *sett_info, const NMSettInfoProperty *property_info, - NMSetting * setting, - GVariant * connection_dict, - GVariant * value, + NMSetting *setting, + GVariant *connection_dict, + GVariant *value, NMSettingParseFlags parse_flags, - gboolean * out_is_modified, - GError ** error) + gboolean *out_is_modified, + GError **error) { gs_free_error GError *local = NULL; NMTernary is_modified = NM_TERNARY_DEFAULT; @@ -1904,12 +1966,12 @@ _property_set_from_dbus(const NMSettInfoSetting * sett_info, } static gboolean -init_from_dbus(NMSetting * setting, - GHashTable * keys, - GVariant * setting_dict, - GVariant * connection_dict, +init_from_dbus(NMSetting *setting, + GHashTable *keys, + GVariant *setting_dict, + GVariant *connection_dict, guint /* NMSettingParseFlags */ parse_flags, - GError ** error) + GError **error) { const NMSettInfoSetting *sett_info; guint16 i; @@ -1922,10 +1984,10 @@ init_from_dbus(NMSetting * setting, sett_info = _nm_setting_class_get_sett_info(NM_SETTING_GET_CLASS(setting)); if (sett_info->detail.gendata_info) { - GHashTable * hash; + GHashTable *hash; GVariantIter iter; - char * key; - GVariant * val; + char *key; + GVariant *val; hash = _gendata_hash(setting, TRUE)->hash; @@ -1952,9 +2014,9 @@ init_from_dbus(NMSetting * setting, } for (i = 0; i < sett_info->property_infos_len; i++) { - const NMSettInfoProperty *property_info = &sett_info->property_infos[i]; - gs_unref_variant GVariant *value = NULL; - gs_free_error GError *local = NULL; + const NMSettInfoProperty *property_info = &sett_info->property_infos[i]; + gs_unref_variant GVariant *value = NULL; + gs_free_error GError *local = NULL; if (property_info->property_type == &nm_sett_info_propert_type_setting_name) continue; @@ -2034,7 +2096,7 @@ nm_setting_get_dbus_property_type(NMSetting *setting, const char *property_name) gboolean _nm_setting_get_property(NMSetting *setting, const char *property_name, GValue *value) { - const NMSettInfoSetting * sett_info; + const NMSettInfoSetting *sett_info; const NMSettInfoProperty *property_info; g_return_val_if_fail(NM_IS_SETTING(setting), FALSE); @@ -2045,7 +2107,7 @@ _nm_setting_get_property(NMSetting *setting, const char *property_name, GValue * if (sett_info->detail.gendata_info) { GVariant *variant; - GenData * gendata = _gendata_hash(setting, FALSE); + GenData *gendata = _gendata_hash(setting, FALSE); variant = gendata ? g_hash_table_lookup(gendata->hash, property_name) : NULL; @@ -2096,9 +2158,9 @@ duplicate_copy_properties(const NMSettInfoSetting *sett_info, NMSetting *src, NM if (gendata && g_hash_table_size(gendata->hash) > 0) { GHashTableIter iter; - GHashTable * h = _gendata_hash(dst, TRUE)->hash; - const char * key; - GVariant * val; + GHashTable *h = _gendata_hash(dst, TRUE)->hash; + const char *key; + GVariant *val; g_hash_table_iter_init(&iter, gendata->hash); while (g_hash_table_iter_next(&iter, (gpointer *) &key, (gpointer *) &val)) { @@ -2146,8 +2208,8 @@ NMSetting * nm_setting_duplicate(NMSetting *setting) { const NMSettInfoSetting *sett_info; - NMSettingClass * klass; - NMSetting * dst; + NMSettingClass *klass; + NMSetting *dst; g_return_val_if_fail(NM_IS_SETTING(setting), NULL); @@ -2256,7 +2318,7 @@ gboolean _nm_setting_verify_secret_string(const char *str, const char *setting_name, const char *property, - GError ** error) + GError **error) { if (str && !*str) { g_set_error_literal(error, @@ -2270,9 +2332,9 @@ _nm_setting_verify_secret_string(const char *str, } gboolean -_nm_setting_should_compare_secret_property(NMSetting * setting, - NMSetting * other, - const char * secret_name, +_nm_setting_should_compare_secret_property(NMSetting *setting, + NMSetting *other, + const char *secret_name, NMSettingCompareFlags flags) { NMSettingSecretFlags a_secret_flags = NM_SETTING_SECRET_FLAG_NONE; @@ -2328,10 +2390,10 @@ _nm_setting_should_compare_secret_property(NMSetting * setting, /*****************************************************************************/ gboolean -_nm_setting_compare_flags_check(const GParamSpec * param_spec, +_nm_setting_compare_flags_check(const GParamSpec *param_spec, NMSettingCompareFlags flags, - NMSetting * set_a, - NMSetting * set_b) + NMSetting *set_a, + NMSetting *set_b) { if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_FUZZY) && NM_FLAGS_ANY(param_spec->flags, NM_SETTING_PARAM_FUZZY_IGNORE | NM_SETTING_PARAM_SECRET)) @@ -2381,8 +2443,8 @@ _nm_setting_property_compare_fcn_direct(_NM_SETT_INFO_PROP_COMPARE_FCN_ARGS _nm_ if (!set_b) return TRUE; - p_a = _nm_setting_get_private(set_a, sett_info, property_info->direct_offset); - p_b = _nm_setting_get_private(set_b, sett_info, property_info->direct_offset); + p_a = _nm_setting_get_private_field(set_a, sett_info, property_info); + p_b = _nm_setting_get_private_field(set_b, sett_info, property_info); switch (property_info->property_type->direct_type) { case NM_VALUE_TYPE_BOOL: @@ -2391,6 +2453,8 @@ _nm_setting_property_compare_fcn_direct(_NM_SETT_INFO_PROP_COMPARE_FCN_ARGS _nm_ return *((const gint32 *) p_a) == *((const gint32 *) p_b); case NM_VALUE_TYPE_UINT32: return *((const guint32 *) p_a) == *((const guint32 *) p_b); + case NM_VALUE_TYPE_INT64: + return *((const gint64 *) p_a) == *((const gint64 *) p_b); case NM_VALUE_TYPE_UINT64: return *((const guint64 *) p_a) == *((const guint64 *) p_b); case NM_VALUE_TYPE_ENUM: @@ -2443,12 +2507,12 @@ _nm_setting_property_compare_fcn_default(_NM_SETT_INFO_PROP_COMPARE_FCN_ARGS _nm } static NMTernary -_compare_property(const NMSettInfoSetting * sett_info, +_compare_property(const NMSettInfoSetting *sett_info, const NMSettInfoProperty *property_info, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, + NMConnection *con_a, + NMSetting *set_a, + NMConnection *con_b, + NMSetting *set_b, NMSettingCompareFlags flags) { NMTernary compare_result; @@ -2500,10 +2564,10 @@ nm_setting_compare(NMSetting *a, NMSetting *b, NMSettingCompareFlags flags) } gboolean -_nm_setting_compare(NMConnection * con_a, - NMSetting * a, - NMConnection * con_b, - NMSetting * b, +_nm_setting_compare(NMConnection *con_a, + NMSetting *a, + NMConnection *con_b, + NMSetting *b, NMSettingCompareFlags flags) { const NMSettInfoSetting *sett_info; @@ -2579,23 +2643,23 @@ _setting_diff_add_result(GHashTable *results, const char *prop_name, NMSettingDi * Returns: %TRUE if the settings contain the same values, %FALSE if they do not **/ gboolean -nm_setting_diff(NMSetting * a, - NMSetting * b, +nm_setting_diff(NMSetting *a, + NMSetting *b, NMSettingCompareFlags flags, gboolean invert_results, - GHashTable ** results) + GHashTable **results) { return _nm_setting_diff(NULL, a, NULL, b, flags, invert_results, results); } gboolean -_nm_setting_diff(NMConnection * con_a, - NMSetting * a, - NMConnection * con_b, - NMSetting * b, +_nm_setting_diff(NMConnection *con_a, + NMSetting *a, + NMConnection *con_b, + NMSetting *b, NMSettingCompareFlags flags, gboolean invert_results, - GHashTable ** results) + GHashTable **results) { const NMSettInfoSetting *sett_info; NMSettingDiffResult a_result = NM_SETTING_DIFF_RESULT_IN_A; @@ -2650,11 +2714,11 @@ _nm_setting_diff(NMConnection * con_a, sett_info = _nm_setting_class_get_sett_info(NM_SETTING_GET_CLASS(a)); if (sett_info->detail.gendata_info) { - const char * key; - GVariant * val, *val2; + const char *key; + GVariant *val, *val2; GHashTableIter iter; - GenData * a_gendata = _gendata_hash(a, FALSE); - GenData * b_gendata = b ? _gendata_hash(b, FALSE) : NULL; + GenData *a_gendata = _gendata_hash(a, FALSE); + GenData *b_gendata = b ? _gendata_hash(b, FALSE) : NULL; if (!a_gendata || !b_gendata) { if (a_gendata || b_gendata) { @@ -2692,7 +2756,7 @@ _nm_setting_diff(NMConnection * con_a, NMSettingDiffResult r = NM_SETTING_DIFF_RESULT_UNKNOWN; const NMSettInfoProperty *property_info = &sett_info->property_infos[i]; NMTernary compare_result; - GParamSpec * prop_spec; + GParamSpec *prop_spec; compare_result = _compare_property(sett_info, property_info, con_a, a, con_b, b, flags); if (compare_result == NM_TERNARY_DEFAULT) @@ -2809,7 +2873,7 @@ _nm_setting_diff(NMConnection * con_a, static void enumerate_values(const NMSettInfoProperty *property_info, - NMSetting * setting, + NMSetting *setting, NMSettingValueIterFn func, gpointer user_data) { @@ -2859,7 +2923,7 @@ nm_setting_enumerate_values(NMSetting *setting, NMSettingValueIterFn func, gpoin n_properties = _nm_setting_option_get_all(setting, &names, NULL); if (n_properties > 0) { gs_strfreev char **keys = g_strdupv((char **) names); - GHashTable * h = _gendata_hash(setting, FALSE)->hash; + GHashTable *h = _gendata_hash(setting, FALSE)->hash; for (i = 0; i < n_properties; i++) { GValue value = G_VALUE_INIT; @@ -2894,7 +2958,7 @@ static gboolean aggregate(NMSetting *setting, int type_i, gpointer arg) { NMConnectionAggregateType type = type_i; - const NMSettInfoSetting * sett_info; + const NMSettInfoSetting *sett_info; guint16 i; nm_assert(NM_IN_SET(type, @@ -2903,8 +2967,8 @@ aggregate(NMSetting *setting, int type_i, gpointer arg) sett_info = _nm_setting_class_get_sett_info(NM_SETTING_GET_CLASS(setting)); for (i = 0; i < sett_info->property_infos_len; i++) { - const NMSettInfoProperty * property_info = &sett_info->property_infos[i]; - GParamSpec * prop_spec = property_info->param_spec; + const NMSettInfoProperty *property_info = &sett_info->property_infos[i]; + GParamSpec *prop_spec = property_info->param_spec; nm_auto_unset_gvalue GValue value = G_VALUE_INIT; NMSettingSecretFlags secret_flags; @@ -2969,14 +3033,14 @@ _nm_setting_aggregate(NMSetting *setting, NMConnectionAggregateType type, gpoint } static gboolean -clear_secrets(const NMSettInfoSetting * sett_info, - const NMSettInfoProperty * property_info, - NMSetting * setting, +clear_secrets(const NMSettInfoSetting *sett_info, + const NMSettInfoProperty *property_info, + NMSetting *setting, NMSettingClearSecretsWithFlagsFn func, gpointer user_data) { NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE; - GParamSpec * param_spec = property_info->param_spec; + GParamSpec *param_spec = property_info->param_spec; if (!param_spec) return FALSE; @@ -3019,13 +3083,13 @@ clear_secrets(const NMSettInfoSetting * sett_info, * Returns: %TRUE if the setting changed at all **/ gboolean -_nm_setting_clear_secrets(NMSetting * setting, +_nm_setting_clear_secrets(NMSetting *setting, NMSettingClearSecretsWithFlagsFn func, gpointer user_data) { const NMSettInfoSetting *sett_info; gboolean changed = FALSE; - NMSettingClass * klass; + NMSettingClass *klass; guint16 i; g_return_val_if_fail(NM_IS_SETTING(setting), FALSE); @@ -3073,7 +3137,7 @@ _nm_setting_need_secrets(NMSetting *setting) static int update_one_secret(NMSetting *setting, const char *key, GVariant *value, GError **error) { - const NMSettInfoSetting * sett_info; + const NMSettInfoSetting *sett_info; const NMSettInfoProperty *property_info; gboolean is_modified; @@ -3125,9 +3189,9 @@ NMSettingUpdateSecretResult _nm_setting_update_secrets(NMSetting *setting, GVariant *secrets, GError **error) { GVariantIter iter; - const char * secret_key; - GVariant * secret_value; - GError * tmp_error = NULL; + const char *secret_key; + GVariant *secret_value; + GError *tmp_error = NULL; NMSettingUpdateSecretResult result = NM_SETTING_UPDATE_SECRET_SUCCESS_UNCHANGED; g_return_val_if_fail(NM_IS_SETTING(setting), NM_SETTING_UPDATE_SECRET_ERROR); @@ -3161,13 +3225,13 @@ _nm_setting_update_secrets(NMSetting *setting, GVariant *secrets, GError **error } static void -for_each_secret(NMSetting * setting, - const char * secret_name, - GVariant * val, +for_each_secret(NMSetting *setting, + const char *secret_name, + GVariant *val, gboolean remove_non_secrets, _NMConnectionForEachSecretFunc callback, gpointer callback_data, - GVariantBuilder * setting_builder) + GVariantBuilder *setting_builder) { NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE; @@ -3219,13 +3283,13 @@ _nm_setting_property_is_regular_secret_flags(NMSetting *setting, const char *sec } static gboolean -get_secret_flags(NMSetting * setting, - const char * secret_name, +get_secret_flags(NMSetting *setting, + const char *secret_name, NMSettingSecretFlags *out_flags, - GError ** error) + GError **error) { - gs_free char * secret_flags_name_free = NULL; - const char * secret_flags_name; + gs_free char *secret_flags_name_free = NULL; + const char *secret_flags_name; NMSettingSecretFlags flags; if (!_nm_setting_property_is_regular_secret(setting, secret_name)) { @@ -3257,10 +3321,10 @@ get_secret_flags(NMSetting * setting, * this setting, and if that property is secret), %FALSE if not **/ gboolean -nm_setting_get_secret_flags(NMSetting * setting, - const char * secret_name, +nm_setting_get_secret_flags(NMSetting *setting, + const char *secret_name, NMSettingSecretFlags *out_flags, - GError ** error) + GError **error) { g_return_val_if_fail(NM_IS_SETTING(setting), FALSE); g_return_val_if_fail(secret_name != NULL, FALSE); @@ -3269,13 +3333,13 @@ nm_setting_get_secret_flags(NMSetting * setting, } static gboolean -set_secret_flags(NMSetting * setting, - const char * secret_name, +set_secret_flags(NMSetting *setting, + const char *secret_name, NMSettingSecretFlags flags, - GError ** error) + GError **error) { gs_free char *secret_flags_name_free = NULL; - const char * secret_flags_name; + const char *secret_flags_name; if (!_nm_setting_property_is_regular_secret(setting, secret_name)) { _set_error_secret_property_not_found(error, setting, secret_name); @@ -3309,10 +3373,10 @@ set_secret_flags(NMSetting * setting, * this setting, and if that property is secret), %FALSE if not **/ gboolean -nm_setting_set_secret_flags(NMSetting * setting, - const char * secret_name, +nm_setting_set_secret_flags(NMSetting *setting, + const char *secret_name, NMSettingSecretFlags flags, - GError ** error) + GError **error) { g_return_val_if_fail(NM_IS_SETTING(setting), FALSE); g_return_val_if_fail(secret_name != NULL, FALSE); @@ -3337,9 +3401,9 @@ nm_setting_set_secret_flags(NMSetting * setting, char * nm_setting_to_string(NMSetting *setting) { - GString * string; + GString *string; gs_unref_variant GVariant *variant = NULL; - GVariant * child; + GVariant *child; GVariantIter iter; string = g_string_new(nm_setting_get_name(setting)); @@ -3349,9 +3413,9 @@ nm_setting_to_string(NMSetting *setting) g_variant_iter_init(&iter, variant); while ((child = g_variant_iter_next_value(&iter))) { - gs_free char * name = NULL; - gs_free char * value_str = NULL; - gs_unref_variant GVariant *value = NULL; + gs_free char *name = NULL; + gs_free char *value_str = NULL; + gs_unref_variant GVariant *value = NULL; g_variant_get(child, "{sv}", &name, &value); value_str = g_variant_print(value, FALSE); @@ -3405,18 +3469,6 @@ const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_u = /* No functions set. This property type is to silently ignore the value on D-Bus. */ .compare_fcn = _nm_setting_property_compare_fcn_ignore); -const NMSettInfoPropertType nm_sett_info_propert_type_plain_i = - NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(G_VARIANT_TYPE_INT32, - .compare_fcn = _nm_setting_property_compare_fcn_default, - .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, - .from_dbus_is_full = TRUE); - -const NMSettInfoPropertType nm_sett_info_propert_type_plain_u = - NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(G_VARIANT_TYPE_UINT32, - .compare_fcn = _nm_setting_property_compare_fcn_default, - .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, - .from_dbus_is_full = TRUE); - const NMSettInfoPropertType nm_sett_info_propert_type_direct_boolean = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_BOOLEAN, .direct_type = NM_VALUE_TYPE_BOOL, @@ -3444,6 +3496,15 @@ const NMSettInfoPropertType nm_sett_info_propert_type_direct_uint32 = .from_dbus_is_full = TRUE, .from_dbus_direct_allow_transform = TRUE); +const NMSettInfoPropertType nm_sett_info_propert_type_direct_int64 = + NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_INT64, + .direct_type = NM_VALUE_TYPE_INT64, + .compare_fcn = _nm_setting_property_compare_fcn_direct, + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_direct, + .from_dbus_is_full = TRUE, + .from_dbus_direct_allow_transform = TRUE); + const NMSettInfoPropertType nm_sett_info_propert_type_direct_uint64 = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_UINT64, .direct_type = NM_VALUE_TYPE_UINT64, @@ -3568,11 +3629,11 @@ out: } guint -_nm_setting_option_get_all(NMSetting * setting, +_nm_setting_option_get_all(NMSetting *setting, const char *const **out_names, - GVariant *const ** out_values) + GVariant *const **out_values) { - GenData * gendata; + GenData *gendata; GHashTable *hash; guint i, len; @@ -3668,9 +3729,9 @@ _nm_setting_option_clear(NMSetting *setting, const char *optname) void nm_setting_option_clear_by_name(NMSetting *setting, NMUtilsPredicateStr predicate) { - GHashTable * hash; + GHashTable *hash; GHashTableIter iter; - const char * name; + const char *name; gboolean changed = FALSE; g_return_if_fail(NM_IS_SETTING(setting)); @@ -3790,7 +3851,7 @@ nm_setting_option_get_uint32(NMSetting *setting, const char *opt_name, guint32 * void nm_setting_option_set(NMSetting *setting, const char *opt_name, GVariant *variant) { - GVariant * old_variant; + GVariant *old_variant; gboolean changed_name; gboolean changed_value; GHashTable *hash; @@ -3850,7 +3911,7 @@ nm_setting_option_set(NMSetting *setting, const char *opt_name, GVariant *varian void nm_setting_option_set_boolean(NMSetting *setting, const char *opt_name, gboolean value) { - GVariant * old_variant; + GVariant *old_variant; gboolean changed_name; gboolean changed_value; GHashTable *hash; @@ -3887,7 +3948,7 @@ nm_setting_option_set_boolean(NMSetting *setting, const char *opt_name, gboolean void nm_setting_option_set_uint32(NMSetting *setting, const char *opt_name, guint32 value) { - GVariant * old_variant; + GVariant *old_variant; gboolean changed_name; gboolean changed_value; GHashTable *hash; @@ -3936,7 +3997,7 @@ nm_setting_init(NMSetting *setting) static void constructed(GObject *object) { - NMSetting * self = NM_SETTING(object); + NMSetting *self = NM_SETTING(object); NMSettingClass *klass = NM_SETTING_GET_CLASS(self); /* we don't support that NMSetting subclasses override constructed. @@ -3962,7 +4023,7 @@ constructed(GObject *object) static void finalize(GObject *object) { - NMSetting * self = NM_SETTING(object); + NMSetting *self = NM_SETTING(object); NMSettingPrivate *priv = NM_SETTING_GET_PRIVATE(self); if (priv->gendata) { diff --git a/src/libnm-core-impl/nm-simple-connection.c b/src/libnm-core-impl/nm-simple-connection.c index f16d9d59..6252dc2c 100644 --- a/src/libnm-core-impl/nm-simple-connection.c +++ b/src/libnm-core-impl/nm-simple-connection.c @@ -139,7 +139,7 @@ NMConnection * nm_simple_connection_new_clone(NMConnection *connection) { NMConnection *clone; - const char * path; + const char *path; g_return_val_if_fail(NM_IS_CONNECTION(connection), NULL); @@ -164,8 +164,6 @@ dispose(GObject *object) (gpointer) &_nm_assert_connection_unchanging_user_data); #endif - nm_connection_clear_secrets(connection); - _nm_connection_private_clear(_GET_PRIVATE(connection)); G_OBJECT_CLASS(nm_simple_connection_parent_class)->dispose(object); diff --git a/src/libnm-core-impl/nm-team-utils.c b/src/libnm-core-impl/nm-team-utils.c index f67c08be..2f62f6c6 100644 --- a/src/libnm-core-impl/nm-team-utils.c +++ b/src/libnm-core-impl/nm-team-utils.c @@ -133,7 +133,7 @@ static const RunnerCompatElem _runner_compat_lst[] = { typedef struct { const char *const *js_keys; - const char * property_name; + const char *property_name; NMValueTypUnion default_val; union { struct { @@ -377,8 +377,8 @@ typedef enum { LINK_WATCHER_ATTRIBUTE_VLANID, LINK_WATCHER_ATTRIBUTE_SEND_ALWAYS typedef struct { - const char * js_key; - const char * dbus_name; + const char *js_key; + const char *dbus_name; NMValueTypUnion default_val; LinkWatcherAttribute link_watcher_attr; NMValueType value_type; @@ -389,9 +389,9 @@ static const LinkWatcherAttrData link_watcher_attr_datas[] = { [_link_watcher_attr] = {.link_watcher_attr = (_link_watcher_attr), \ .value_type = (_value_type), \ .js_key = (""_js_key \ - ""), \ + ""), \ .dbus_name = (""_dbus_name \ - ""), \ + ""), \ __VA_ARGS__} _INIT(LINK_WATCHER_ATTRIBUTE_NAME, "name", "name", NM_VALUE_TYPE_STRING, ), _INIT(LINK_WATCHER_ATTRIBUTE_DELAY_UP, "delay_up", "delay-up", NM_VALUE_TYPE_INT, ), @@ -547,9 +547,9 @@ _team_attr_data_copy(const TeamAttrData *attr_data, gpointer dst, gconstpointer src) { - GPtrArray * v_ptrarray_dst; + GPtrArray *v_ptrarray_dst; const GPtrArray *v_ptrarray_src; - GPtrArray * dst_array; + GPtrArray *dst_array; guint i, len; if (attr_data->value_type != NM_VALUE_TYPE_UNSPEC) @@ -595,7 +595,7 @@ _team_attr_data_copy(const TeamAttrData *attr_data, static void _team_attr_data_to_json(const TeamAttrData *attr_data, gboolean is_port, - GString * gstr, + GString *gstr, gconstpointer p_field) { guint i; @@ -677,7 +677,7 @@ _team_setting_has_field(const NMTeamSetting *self, const TeamAttrData *attr_data } static gboolean -_team_setting_has_fields_any_v(const NMTeamSetting * self, +_team_setting_has_fields_any_v(const NMTeamSetting *self, const NMTeamAttribute *team_attrs, gsize n_team_attrs) { @@ -698,7 +698,7 @@ _team_setting_has_fields_any_v(const NMTeamSetting * self, NM_NARG(__VA_ARGS__)) static void -_team_setting_has_field_set(NMTeamSetting * self, +_team_setting_has_field_set(NMTeamSetting *self, const TeamAttrData *attr_data, SetFieldModeEnum set_field_mode) { @@ -745,7 +745,7 @@ _team_setting_get_field(const NMTeamSetting *self, const TeamAttrData *attr_data } static guint32 -_team_setting_attribute_changed(NMTeamSetting * self, +_team_setting_attribute_changed(NMTeamSetting *self, const TeamAttrData *attr_data, gboolean changed, SetFieldModeEnum set_field_mode, @@ -785,7 +785,7 @@ _team_setting_attribute_changed(NMTeamSetting * self, } static guint32 -_team_setting_attribute_changed_attr(NMTeamSetting * self, +_team_setting_attribute_changed_attr(NMTeamSetting *self, NMTeamAttribute team_attr, gboolean changed, SetFieldModeEnum set_field_mode, @@ -800,9 +800,9 @@ _team_setting_attribute_changed_attr(NMTeamSetting * self, static gboolean _team_setting_field_to_json(const NMTeamSetting *self, - GString * gstr, + GString *gstr, gboolean prepend_delimiter, - const TeamAttrData * attr_data) + const TeamAttrData *attr_data) { if (!_team_setting_has_field(self, attr_data)) return FALSE; @@ -817,8 +817,8 @@ _team_setting_field_to_json(const NMTeamSetting *self, } static gboolean -_team_setting_fields_to_json_maybe(const NMTeamSetting * self, - GString * gstr, +_team_setting_fields_to_json_maybe(const NMTeamSetting *self, + GString *gstr, gboolean prepend_delimiter, const NMTeamAttribute *team_attrs_lst, gsize team_attrs_lst_len) @@ -839,9 +839,9 @@ _team_setting_fields_to_json_maybe(const NMTeamSetting * self, } static guint32 -_team_setting_set(NMTeamSetting * self, +_team_setting_set(NMTeamSetting *self, gboolean modify, - const bool * has_lst, + const bool *has_lst, const NMValueTypUnion *val_lst) { guint32 changed_flags = 0; @@ -914,7 +914,7 @@ _nm_team_setting_value_get(const NMTeamSetting *self, } static guint32 -_team_setting_value_set(NMTeamSetting * self, +_team_setting_value_set(NMTeamSetting *self, const TeamAttrData *attr_data, gconstpointer val, SetFieldModeEnum set_field_mode, @@ -936,7 +936,7 @@ _team_setting_value_set(NMTeamSetting * self, } guint32 -nm_team_setting_value_reset(NMTeamSetting * self, +nm_team_setting_value_reset(NMTeamSetting *self, NMTeamAttribute team_attr, gboolean to_default /* or else unset */) { @@ -954,7 +954,7 @@ nm_team_setting_value_reset(NMTeamSetting * self, } guint32 -_nm_team_setting_value_set(NMTeamSetting * self, +_nm_team_setting_value_set(NMTeamSetting *self, NMTeamAttribute team_attr, NMValueType value_type, gconstpointer val) @@ -998,7 +998,7 @@ out: } guint32 -nm_team_setting_value_link_watchers_remove_by_value(NMTeamSetting * self, +nm_team_setting_value_link_watchers_remove_by_value(NMTeamSetting *self, const NMTeamLinkWatcher *link_watcher) { guint i; @@ -1026,7 +1026,7 @@ nm_team_setting_value_link_watchers_remove(NMTeamSetting *self, guint idx) } static guint32 -_team_setting_value_link_watchers_set_list(NMTeamSetting * self, +_team_setting_value_link_watchers_set_list(NMTeamSetting *self, const NMTeamLinkWatcher *const *arr, guint len, SetFieldModeEnum set_field_mode, @@ -1074,7 +1074,7 @@ out: } guint32 -nm_team_setting_value_link_watchers_set_list(NMTeamSetting * self, +nm_team_setting_value_link_watchers_set_list(NMTeamSetting *self, const NMTeamLinkWatcher *const *arr, guint len) { @@ -1125,7 +1125,7 @@ nm_team_setting_value_master_runner_tx_hash_remove(NMTeamSetting *self, guint id } static guint32 -_team_setting_value_master_runner_tx_hash_set_list(NMTeamSetting * self, +_team_setting_value_master_runner_tx_hash_set_list(NMTeamSetting *self, const char *const *arr, guint len, SetFieldModeEnum set_field_mode, @@ -1167,7 +1167,7 @@ out: } guint32 -nm_team_setting_value_master_runner_tx_hash_set_list(NMTeamSetting * self, +nm_team_setting_value_master_runner_tx_hash_set_list(NMTeamSetting *self, const char *const *arr, guint len) { @@ -1214,7 +1214,7 @@ static void _link_watcher_unpack(const NMTeamLinkWatcher *link_watcher, NMValueTypUnioMaybe args[static G_N_ELEMENTS(link_watcher_attr_datas)]) { - const char * v_name = nm_team_link_watcher_get_name(link_watcher); + const char *v_name = nm_team_link_watcher_get_name(link_watcher); NMTeamLinkWatcherArpPingFlags v_arp_ping_flags; memset(args, 0, sizeof(args[0]) * G_N_ELEMENTS(link_watcher_attr_datas)); @@ -1305,22 +1305,22 @@ _link_watcher_to_json(const NMTeamLinkWatcher *link_watcher, GString *gstr) } static NMTeamLinkWatcher * -_link_watcher_from_json(const NMJsonVt * vt, +_link_watcher_from_json(const NMJsonVt *vt, const nm_json_t *root_js_obj, - gboolean * out_unrecognized_content) + gboolean *out_unrecognized_content) { NMValueTypUnioMaybe args[G_N_ELEMENTS(link_watcher_attr_datas)] = {}; - const char * j_key; - nm_json_t * j_val; - const char * v_name; - NMTeamLinkWatcher * result = NULL; + const char *j_key; + nm_json_t *j_val; + const char *v_name; + NMTeamLinkWatcher *result = NULL; if (!nm_json_is_object(root_js_obj)) goto fail; nm_json_object_foreach (vt, (nm_json_t *) root_js_obj, j_key, j_val) { const LinkWatcherAttrData *attr_data = NULL; - NMValueTypUnioMaybe * parse_result; + NMValueTypUnioMaybe *parse_result; if (j_key) { int i; @@ -1434,7 +1434,7 @@ _link_watcher_to_variant(const NMTeamLinkWatcher *link_watcher) for (i = 0; i < (int) G_N_ELEMENTS(link_watcher_attr_datas); i++) { const NMValueTypUnioMaybe *p_val = &args[i]; const LinkWatcherAttrData *attr_data = &link_watcher_attr_datas[i]; - GVariant * v; + GVariant *v; if (!p_val->has) continue; @@ -1459,7 +1459,7 @@ _link_watcher_to_variant(const NMTeamLinkWatcher *link_watcher) #define _LINK_WATCHER_ATTR_VARGET(variants, link_watcher_attribute, _value_type, c_type, _cmd) \ ({ \ GVariant *const *_variants = (variants); \ - GVariant * _cc; \ + GVariant *_cc; \ \ nm_assert(link_watcher_attr_datas[(link_watcher_attribute)].value_type == (_value_type)); \ \ @@ -1502,9 +1502,9 @@ _link_watcher_from_variant(GVariant *watcher_var, gboolean strict_parsing, GErro GVariant *variants[G_N_ELEMENTS(link_watcher_attr_datas)] = { NULL, }; - const char * v_key; - GVariant * v_val; - const char * v_name; + const char *v_key; + GVariant *v_val; + const char *v_name; GVariantIter iter; g_return_val_if_fail(g_variant_is_of_type(watcher_var, G_VARIANT_TYPE("a{sv}")), NULL); @@ -1512,8 +1512,8 @@ _link_watcher_from_variant(GVariant *watcher_var, gboolean strict_parsing, GErro g_variant_iter_init(&iter, watcher_var); while (g_variant_iter_next(&iter, "{&sv}", &v_key, &v_val)) { _nm_unused gs_unref_variant GVariant *v_val_free = v_val; - const LinkWatcherAttrData * attr_data = NULL; - const GVariantType * variant_type; + const LinkWatcherAttrData *attr_data = NULL; + const GVariantType *variant_type; int i; for (i = 0; i < (int) G_N_ELEMENTS(link_watcher_attr_datas); i++) { @@ -1704,7 +1704,7 @@ _nm_utils_team_link_watchers_from_variant(GVariant *value, gboolean strict_parsi { gs_unref_ptrarray GPtrArray *link_watchers = NULL; GVariantIter iter; - GVariant * watcher_var; + GVariant *watcher_var; g_return_val_if_fail(g_variant_is_of_type(value, G_VARIANT_TYPE("aa{sv}")), NULL); @@ -1713,7 +1713,7 @@ _nm_utils_team_link_watchers_from_variant(GVariant *value, gboolean strict_parsi g_variant_iter_init(&iter, value); while (g_variant_iter_next(&iter, "@a{sv}", &watcher_var)) { _nm_unused gs_unref_variant GVariant *watcher_var_free = watcher_var; - NMTeamLinkWatcher * watcher; + NMTeamLinkWatcher *watcher; watcher = _link_watcher_from_variant(watcher_var, strict_parsing, error); if (error && *error) @@ -1942,18 +1942,18 @@ _attr_data_find_by_json_key(gboolean is_port, const char *const *keys, guint8 n_ static void _js_parse_locate_keys(const NMJsonVt *vt, - NMTeamSetting * self, - nm_json_t * root_js_obj, - nm_json_t * found_keys[static _NM_TEAM_ATTRIBUTE_NUM], - gboolean * out_unrecognized_content) + NMTeamSetting *self, + nm_json_t *root_js_obj, + nm_json_t *found_keys[static _NM_TEAM_ATTRIBUTE_NUM], + gboolean *out_unrecognized_content) { const char *keys[3]; const char *cur_key1; const char *cur_key2; const char *cur_key3; - nm_json_t * cur_val1; - nm_json_t * cur_val2; - nm_json_t * cur_val3; + nm_json_t *cur_val1; + nm_json_t *cur_val2; + nm_json_t *cur_val3; nm_assert(vt); @@ -2007,12 +2007,12 @@ _js_parse_locate_keys(const NMJsonVt *vt, static void _js_parse_unpack(const NMJsonVt *vt, gboolean is_port, - nm_json_t * found_keys[static _NM_TEAM_ATTRIBUTE_NUM], + nm_json_t *found_keys[static _NM_TEAM_ATTRIBUTE_NUM], bool out_has_lst[static _NM_TEAM_ATTRIBUTE_NUM], NMValueTypUnion out_val_lst[static _NM_TEAM_ATTRIBUTE_NUM], - gboolean * out_unrecognized_content, - GPtrArray ** out_ptr_array_link_watchers_free, - GPtrArray ** out_ptr_array_master_runner_tx_hash_free) + gboolean *out_unrecognized_content, + GPtrArray **out_ptr_array_link_watchers_free, + GPtrArray **out_ptr_array_master_runner_tx_hash_free) { const TeamAttrData *attr_data; @@ -2023,7 +2023,7 @@ _js_parse_unpack(const NMJsonVt *vt, attr_data++) { NMValueTypUnion *p_out_val; gboolean valid = FALSE; - nm_json_t * arg_js_obj; + nm_json_t *arg_js_obj; if (!_team_attr_data_is_relevant(attr_data, is_port)) continue; @@ -2039,7 +2039,7 @@ _js_parse_unpack(const NMJsonVt *vt, if (attr_data->value_type != NM_VALUE_TYPE_UNSPEC) valid = nm_value_type_from_json(vt, attr_data->value_type, arg_js_obj, p_out_val); else if (attr_data->team_attr == NM_TEAM_ATTRIBUTE_LINK_WATCHERS) { - GPtrArray * link_watchers = NULL; + GPtrArray *link_watchers = NULL; NMTeamLinkWatcher *link_watcher; nm_assert(out_ptr_array_link_watchers_free && !*out_ptr_array_link_watchers_free); @@ -2151,7 +2151,7 @@ nm_team_setting_config_set(NMTeamSetting *self, const char *js_str) FALSE, }; NMValueTypUnion val_lst[_NM_TEAM_ATTRIBUTE_NUM]; - nm_json_t * found_keys[_NM_TEAM_ATTRIBUTE_NUM] = { + nm_json_t *found_keys[_NM_TEAM_ATTRIBUTE_NUM] = { NULL, }; gs_unref_ptrarray GPtrArray *ptr_array_master_runner_tx_hash_free = NULL; @@ -2199,9 +2199,9 @@ _team_setting_prefix_error_plain(gboolean is_port, const char *property_name, GE static void _team_setting_prefix_error(const NMTeamSetting *self, - const char * prop_name_master, - const char * prop_name_port, - GError ** error) + const char *prop_name_master, + const char *prop_name_port, + GError **error) { _team_setting_ASSERT(self); nm_assert(self->d.is_port ? (!!prop_name_port) : (!!prop_name_master)); @@ -2501,29 +2501,29 @@ _variants_list_team_unref_auto(GVariant *(*p_variants)[]) } gboolean -nm_team_setting_reset_from_dbus(NMTeamSetting * self, - GVariant * setting_dict, - GHashTable * keys, - guint32 * out_changed, +nm_team_setting_reset_from_dbus(NMTeamSetting *self, + GVariant *setting_dict, + GHashTable *keys, + guint32 *out_changed, guint /* NMSettingParseFlags */ parse_flags, - GError ** error) + GError **error) { nm_auto(_variants_list_team_unref_auto) GVariant *variants[_NM_TEAM_ATTRIBUTE_NUM] = { NULL, }; gs_unref_ptrarray GPtrArray *v_link_watchers = NULL; - const TeamAttrData * attr_data; + const TeamAttrData *attr_data; GVariantIter iter; - const char * v_key; - GVariant * v_val; - const NMJsonVt * vt; + const char *v_key; + GVariant *v_val; + const NMJsonVt *vt; *out_changed = 0; g_variant_iter_init(&iter, setting_dict); while (g_variant_iter_next(&iter, "{&sv}", &v_key, &v_val)) { _nm_unused gs_unref_variant GVariant *v_val_free = v_val; - const GVariantType * variant_type = NULL; + const GVariantType *variant_type = NULL; attr_data = _team_attr_data_find_for_property_name(self->d.is_port, v_key); if (!attr_data) { @@ -2678,7 +2678,7 @@ nm_team_setting_reset_from_dbus(NMTeamSetting * self, /*****************************************************************************/ gboolean -nm_team_setting_maybe_changed(NMSetting * source, +nm_team_setting_maybe_changed(NMSetting *source, const GParamSpec *const *obj_properties, guint32 changed_flags) { @@ -2727,7 +2727,7 @@ _nm_setting_get_team_setting(struct _NMSetting *setting) GVariant * _nm_team_settings_property_to_dbus(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) { - NMTeamSetting * self = _nm_setting_get_team_setting(setting); + NMTeamSetting *self = _nm_setting_get_team_setting(setting); const TeamAttrData *attr_data = _team_attr_data_get(self->d.is_port, property_info->param_spec->param_id); diff --git a/src/libnm-core-impl/nm-team-utils.h b/src/libnm-core-impl/nm-team-utils.h index d888e191..06fa6cc8 100644 --- a/src/libnm-core-impl/nm-team-utils.h +++ b/src/libnm-core-impl/nm-team-utils.h @@ -87,10 +87,10 @@ struct _NMTeamSettingData { union { struct { const GPtrArray *runner_tx_hash; - const char * runner; - const char * runner_hwaddr_policy; - const char * runner_tx_balancer; - const char * runner_agg_select_policy; + const char *runner; + const char *runner_hwaddr_policy; + const char *runner_tx_balancer; + const char *runner_agg_select_policy; gint32 notify_peers_count; gint32 notify_peers_interval; gint32 mcast_rejoin_count; @@ -169,11 +169,11 @@ nm_team_setting_value_get_string(const NMTeamSetting *self, NMTeamAttribute team /*****************************************************************************/ -guint32 nm_team_setting_value_reset(NMTeamSetting * self, +guint32 nm_team_setting_value_reset(NMTeamSetting *self, NMTeamAttribute team_attr, gboolean to_default /* or else unset */); -guint32 _nm_team_setting_value_set(NMTeamSetting * self, +guint32 _nm_team_setting_value_set(NMTeamSetting *self, NMTeamAttribute team_attr, NMValueType value_type, gconstpointer val); @@ -200,16 +200,16 @@ nm_team_setting_value_set_string(NMTeamSetting *self, NMTeamAttribute team_attr, /*****************************************************************************/ -guint32 nm_team_setting_value_link_watchers_add(NMTeamSetting * self, +guint32 nm_team_setting_value_link_watchers_add(NMTeamSetting *self, const struct NMTeamLinkWatcher *link_watcher); guint32 nm_team_setting_value_link_watchers_remove(NMTeamSetting *self, guint idx); guint32 -nm_team_setting_value_link_watchers_remove_by_value(NMTeamSetting * self, +nm_team_setting_value_link_watchers_remove_by_value(NMTeamSetting *self, const struct NMTeamLinkWatcher *link_watcher); -guint32 nm_team_setting_value_link_watchers_set_list(NMTeamSetting * self, +guint32 nm_team_setting_value_link_watchers_set_list(NMTeamSetting *self, const struct NMTeamLinkWatcher *const *arr, guint len); @@ -219,7 +219,7 @@ guint32 nm_team_setting_value_master_runner_tx_hash_add(NMTeamSetting *self, con guint32 nm_team_setting_value_master_runner_tx_hash_remove(NMTeamSetting *self, guint idx); -guint32 nm_team_setting_value_master_runner_tx_hash_set_list(NMTeamSetting * self, +guint32 nm_team_setting_value_master_runner_tx_hash_set_list(NMTeamSetting *self, const char *const *arr, guint len); @@ -235,12 +235,12 @@ int nm_team_setting_cmp(const NMTeamSetting *self_a, guint32 nm_team_setting_reset(NMTeamSetting *self, const NMTeamSetting *src); -gboolean nm_team_setting_reset_from_dbus(NMTeamSetting * self, - GVariant * setting_dict, - GHashTable * keys, - guint32 * out_changed, +gboolean nm_team_setting_reset_from_dbus(NMTeamSetting *self, + GVariant *setting_dict, + GHashTable *keys, + guint32 *out_changed, guint /* NMSettingParseFlags */ parse_flags, - GError ** error); + GError **error); /*****************************************************************************/ @@ -250,7 +250,7 @@ GVariant *_nm_utils_team_link_watchers_to_variant(const GPtrArray *link_watchers /*****************************************************************************/ -gboolean nm_team_setting_maybe_changed(struct _NMSetting * source, +gboolean nm_team_setting_maybe_changed(struct _NMSetting *source, const GParamSpec *const *obj_properties, guint32 changed); diff --git a/src/libnm-core-impl/nm-utils-private.h b/src/libnm-core-impl/nm-utils-private.h index 679fd6b4..1a6f29ef 100644 --- a/src/libnm-core-impl/nm-utils-private.h +++ b/src/libnm-core-impl/nm-utils-private.h @@ -19,16 +19,16 @@ gboolean _nm_utils_string_slist_validate(GSList *list, const char **valid_values); gboolean _nm_utils_secret_flags_validate(NMSettingSecretFlags secret_flags, - const char * setting_name, - const char * property_name, + const char *setting_name, + const char *property_name, NMSettingSecretFlags disallowed_flags, - GError ** error); + GError **error); gboolean _nm_utils_wps_method_validate(NMSettingWirelessSecurityWpsMethod wps_method, - const char * setting_name, - const char * property_name, + const char *setting_name, + const char *property_name, gboolean wps_required, - GError ** error); + GError **error); /* D-Bus transform funcs */ @@ -44,15 +44,16 @@ void _nm_utils_bytes_from_dbus(GVariant *dbus_value, GValue *prop_value); char *_nm_utils_hwaddr_canonical_or_invalid(const char *mac, gssize length); -char *_nm_utils_ipaddr_canonical_or_invalid(int addr_family, const char *ip); +char * +_nm_utils_ipaddr_canonical_or_invalid(int addr_family, const char *ip, gboolean map_zero_to_null); gboolean _nm_utils_hwaddr_link_local_valid(const char *mac); gboolean _nm_sriov_vf_parse_vlans(NMSriovVF *vf, const char *str, GError **error); -gboolean _nm_utils_bridge_vlan_verify_list(GPtrArray * vlans, +gboolean _nm_utils_bridge_vlan_verify_list(GPtrArray *vlans, gboolean check_normalizable, - GError ** error, + GError **error, const char *setting, const char *property); @@ -66,4 +67,8 @@ void _nm_team_settings_property_from_dbus_link_watchers( GVariant *_nm_utils_ip4_dns_to_variant(const char *const *dns, gssize len); GVariant *_nm_utils_ip6_dns_to_variant(const char *const *dns, gssize len); +const char *const *nmtst_system_encodings_for_lang(const char *lang); +const char *const *nmtst_system_encodings_get_default(void); +const char *const *nmtst_system_encodings_get(void); + #endif diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c index ccdd4b92..55b01c15 100644 --- a/src/libnm-core-impl/nm-utils.c +++ b/src/libnm-core-impl/nm-utils.c @@ -79,7 +79,7 @@ NM_IS_SOCK_ADDR_ENDPOINT(const NMSockAddrEndpoint *self) static const char * _parse_endpoint(char *str, guint16 *out_port) { - char * s; + char *s; const char *s_port; gint16 port; @@ -147,8 +147,8 @@ nm_sock_addr_endpoint_new(const char *endpoint) gsize l_endpoint; gsize l_host = 0; gsize i; - gs_free char * host_clone = NULL; - const char * host; + gs_free char *host_clone = NULL; + const char *host; guint16 port; g_return_val_if_fail(endpoint, NULL); @@ -294,7 +294,7 @@ nm_sock_addr_endpoint_get_fixed_sockaddr(NMSockAddrEndpoint *self, gpointer sock { gs_free char *tmp_str = NULL; - const char * host_part; + const char *host_part; host_part = nm_strndup_a(200, self->host, s - self->host, &tmp_str); if (nm_utils_parse_inaddr_bin(AF_INET6, host_part, &addr_family, &addrbin)) @@ -328,169 +328,181 @@ good: /*****************************************************************************/ -struct IsoLangToEncodings { - const char * lang; - const char *const *encodings; -}; +typedef const char *const StrvArray4Type[4]; -#define LANG_ENCODINGS(l, ...) \ - { \ - .lang = l, .encodings = NM_MAKE_STRV(__VA_ARGS__), \ +#define LL(l, ...) \ + { \ + .name = l, .value = {__VA_ARGS__, NULL}, \ } /* 5-letter language codes */ -static const struct IsoLangToEncodings isoLangEntries5[] = { - /* Simplified Chinese */ - LANG_ENCODINGS("zh_cn", "euc-cn", "gb2312", "gb18030"), /* PRC */ - LANG_ENCODINGS("zh_sg", "euc-cn", "gb2312", "gb18030"), /* Singapore */ - - /* Traditional Chinese */ - LANG_ENCODINGS("zh_tw", "big5", "euc-tw"), /* Taiwan */ - LANG_ENCODINGS("zh_hk", "big5", "euc-tw", "big5-hkcs"), /* Hong Kong */ - LANG_ENCODINGS("zh_mo", "big5", "euc-tw"), /* Macau */ - - LANG_ENCODINGS(NULL, NULL)}; +static _NM_UTILS_STRING_TABLE_LOOKUP_DEFINE( + _iso_lang_entries_5_lookup, + StrvArray4Type, + const char *const *, + { nm_assert(name); }, + { return NULL; }, + , + LL("zh_cn", "euc-cn", "gb2312", "gb18030"), /* Simplified Chinese, PRC */ + LL("zh_hk", "big5", "euc-tw", "big5-hkcs"), /* Traditional Chinese, Hong Kong */ + LL("zh_mo", "big5", "euc-tw"), /* Traditional Chinese, Macau */ + LL("zh_sg", "euc-cn", "gb2312", "gb18030"), /* Simplified Chinese, Singapore */ + LL("zh_tw", "big5", "euc-tw"), /* Traditional Chinese, Taiwan */ +); /* 2-letter language codes; we don't care about the other 3 in this table */ -static const struct IsoLangToEncodings isoLangEntries2[] = { - /* Japanese */ - LANG_ENCODINGS("ja", "euc-jp", "shift_jis", "iso-2022-jp"), - - /* Korean */ - LANG_ENCODINGS("ko", "euc-kr", "iso-2022-kr", "johab"), - - /* Thai */ - LANG_ENCODINGS("th", "iso-8859-11", "windows-874"), - - /* Central European */ - LANG_ENCODINGS("hu", "iso-8859-2", "windows-1250"), /* Hungarian */ - LANG_ENCODINGS("cs", "iso-8859-2", "windows-1250"), /* Czech */ - LANG_ENCODINGS("hr", "iso-8859-2", "windows-1250"), /* Croatian */ - LANG_ENCODINGS("pl", "iso-8859-2", "windows-1250"), /* Polish */ - LANG_ENCODINGS("ro", "iso-8859-2", "windows-1250"), /* Romanian */ - LANG_ENCODINGS("sk", "iso-8859-2", "windows-1250"), /* Slovakian */ - LANG_ENCODINGS("sl", "iso-8859-2", "windows-1250"), /* Slovenian */ - LANG_ENCODINGS("sh", "iso-8859-2", "windows-1250"), /* Serbo-Croatian */ - - /* Cyrillic */ - LANG_ENCODINGS("ru", "koi8-r", "windows-1251", "iso-8859-5"), /* Russian */ - LANG_ENCODINGS("be", "koi8-r", "windows-1251", "iso-8859-5"), /* Belorussian */ - LANG_ENCODINGS("bg", "windows-1251", "koi8-r", "iso-8859-5"), /* Bulgarian */ - LANG_ENCODINGS("mk", "koi8-r", "windows-1251", "iso-8859-5"), /* Macedonian */ - LANG_ENCODINGS("sr", "koi8-r", "windows-1251", "iso-8859-5"), /* Serbian */ - LANG_ENCODINGS("uk", "koi8-u", "koi8-r", "windows-1251"), /* Ukrainian */ - - /* Arabic */ - LANG_ENCODINGS("ar", "iso-8859-6", "windows-1256"), - - /* Baltic */ - LANG_ENCODINGS("et", "iso-8859-4", "windows-1257"), /* Estonian */ - LANG_ENCODINGS("lt", "iso-8859-4", "windows-1257"), /* Lithuanian */ - LANG_ENCODINGS("lv", "iso-8859-4", "windows-1257"), /* Latvian */ - - /* Greek */ - LANG_ENCODINGS("el", "iso-8859-7", "windows-1253"), - - /* Hebrew */ - LANG_ENCODINGS("he", "iso-8859-8", "windows-1255"), - LANG_ENCODINGS("iw", "iso-8859-8", "windows-1255"), - - /* Turkish */ - LANG_ENCODINGS("tr", "iso-8859-9", "windows-1254"), - - /* Table end */ - LANG_ENCODINGS(NULL, NULL)}; - -static GHashTable *langToEncodings5 = NULL; -static GHashTable *langToEncodings2 = NULL; +static _NM_UTILS_STRING_TABLE_LOOKUP_DEFINE( + _iso_lang_entries_2_lookup, + StrvArray4Type, + const char *const *, + { nm_assert(name); }, + { return NULL; }, + , + LL("ar", "iso-8859-6", "windows-1256"), /* Arabic */ + LL("be", "koi8-r", "windows-1251", "iso-8859-5"), /* Cyrillic, Belorussian */ + LL("bg", "windows-1251", "koi8-r", "iso-8859-5"), /* Cyrillic, Bulgarian */ + LL("cs", "iso-8859-2", "windows-1250"), /* Central European, Czech */ + LL("el", "iso-8859-7", "windows-1253"), /* Greek */ + LL("et", "iso-8859-4", "windows-1257"), /* Baltic, Estonian */ + LL("he", "iso-8859-8", "windows-1255"), /* Hebrew */ + LL("hr", "iso-8859-2", "windows-1250"), /* Central European, Croatian */ + LL("hu", "iso-8859-2", "windows-1250"), /* Central European, Hungarian */ + LL("iw", "iso-8859-8", "windows-1255"), /* Hebrew */ + LL("ja", "euc-jp", "shift_jis", "iso-2022-jp"), /* Japanese */ + LL("ko", "euc-kr", "iso-2022-kr", "johab"), /* Korean */ + LL("lt", "iso-8859-4", "windows-1257"), /* Baltic, Lithuanian */ + LL("lv", "iso-8859-4", "windows-1257"), /* Baltic, Latvian */ + LL("mk", "koi8-r", "windows-1251", "iso-8859-5"), /* Cyrillic, Macedonian */ + LL("pl", "iso-8859-2", "windows-1250"), /* Central European, Polish */ + LL("ro", "iso-8859-2", "windows-1250"), /* Central European, Romanian */ + LL("ru", "koi8-r", "windows-1251", "iso-8859-5"), /* Cyrillic, Russian */ + LL("sh", "iso-8859-2", "windows-1250"), /* Central European, Serbo-Croatian */ + LL("sk", "iso-8859-2", "windows-1250"), /* Central European, Slovakian */ + LL("sl", "iso-8859-2", "windows-1250"), /* Central European, Slovenian */ + LL("sr", "koi8-r", "windows-1251", "iso-8859-5"), /* Cyrillic, Serbian */ + LL("th", "iso-8859-11", "windows-874"), /* Thai */ + LL("tr", "iso-8859-9", "windows-1254"), /* Turkish */ + LL("uk", "koi8-u", "koi8-r", "windows-1251"), /* Cyrillic, Ukrainian */ +); -static void -init_lang_to_encodings_hash(void) +static const char *const * +_system_encodings_for_lang(const char *lang) { - struct IsoLangToEncodings *enc; + char tmp_lang[3]; + const char *const *e; - if (G_UNLIKELY(langToEncodings5 == NULL)) { - /* Five-letter codes */ - enc = (struct IsoLangToEncodings *) &isoLangEntries5[0]; - langToEncodings5 = g_hash_table_new(nm_str_hash, g_str_equal); - while (enc->lang) { - g_hash_table_insert(langToEncodings5, (gpointer) enc->lang, (gpointer) enc->encodings); - enc++; - } + nm_assert(lang); + + if (lang[0] == '\0' || lang[1] == '\0') { + /* need at least two characters. */ + nm_assert(!_iso_lang_entries_5_lookup(lang)); + nm_assert(!_iso_lang_entries_2_lookup(lang)); + return NULL; } - if (G_UNLIKELY(langToEncodings2 == NULL)) { - /* Two-letter codes */ - enc = (struct IsoLangToEncodings *) &isoLangEntries2[0]; - langToEncodings2 = g_hash_table_new(nm_str_hash, g_str_equal); - while (enc->lang) { - g_hash_table_insert(langToEncodings2, (gpointer) enc->lang, (gpointer) enc->encodings); - enc++; - } + if (lang[2] != '\0') { + nm_assert(!_iso_lang_entries_2_lookup(lang)); + + if (lang[3] != '\0' && lang[4] != '\0' && lang[5] == '\0') { + /* lang is 5 characters long. Try it. */ + if ((e = _iso_lang_entries_5_lookup(lang))) + return e; + } else + nm_assert(!_iso_lang_entries_5_lookup(lang)); + + /* extract the first 2 characters and ignore the rest. */ + tmp_lang[0] = lang[0]; + tmp_lang[1] = lang[1]; + tmp_lang[2] = '\0'; + lang = tmp_lang; } + + if ((e = _iso_lang_entries_2_lookup(lang))) + return e; + + return NULL; } -static gboolean -get_encodings_for_lang(const char *lang, const char *const **encodings) +const char *const * +nmtst_system_encodings_for_lang(const char *lang) +{ + return _system_encodings_for_lang(lang); +} + +static const char *const * +_system_encodings_get_default(void) { - gs_free char *tmp_lang = NULL; + static gsize init_once = 0; + static const char *default_encodings[4]; - g_return_val_if_fail(lang, FALSE); - g_return_val_if_fail(encodings, FALSE); + if (g_once_init_enter(&init_once)) { + const char *e_default = NULL; + int i; - init_lang_to_encodings_hash(); + g_get_charset(&e_default); - if ((*encodings = g_hash_table_lookup(langToEncodings5, lang))) - return TRUE; + i = 0; + if (e_default) + default_encodings[i++] = e_default; + if (!nm_streq0(e_default, "iso-8859-1")) + default_encodings[i++] = "iso-8859-1"; + if (!nm_streq0(e_default, "windows-1251")) + default_encodings[i++] = "windows-1251"; + default_encodings[i++] = NULL; + nm_assert(i <= G_N_ELEMENTS(default_encodings)); - /* Truncate tmp_lang to length of 2 */ - if (strlen(lang) > 2) { - tmp_lang = g_strdup(lang); - tmp_lang[2] = '\0'; - if ((*encodings = g_hash_table_lookup(langToEncodings2, tmp_lang))) - return TRUE; + g_once_init_leave(&init_once, 1); } - return FALSE; + return default_encodings; +} + +const char *const * +nmtst_system_encodings_get_default(void) +{ + return _system_encodings_get_default(); } static const char *const * -get_system_encodings(void) +_system_encodings_get(void) { - static const char *const *cached_encodings; - static char * default_encodings[4]; - const char *const * encodings = NULL; - char * lang; + static const char *const *cached = NULL; + const char *const *e; - if (cached_encodings) - return cached_encodings; +again: + if (!(e = g_atomic_pointer_get(&cached))) { + const char *lang; - /* Use environment variables as encoding hint */ - lang = getenv("LC_ALL"); - if (!lang) - lang = getenv("LC_CTYPE"); - if (!lang) - lang = getenv("LANG"); - if (lang) { - char *dot; + /* Use environment variables as encoding hint */ + lang = getenv("LC_ALL") ?: getenv("LC_CTYPE") ?: getenv("LANG"); - lang = g_ascii_strdown(lang, -1); - if ((dot = strchr(lang, '.'))) - *dot = '\0'; + if (lang) { + gs_free char *lang_down = NULL; + char *dot; - get_encodings_for_lang(lang, &encodings); - g_free(lang); - } - if (!encodings) { - g_get_charset((const char **) &default_encodings[0]); - default_encodings[1] = "iso-8859-1"; - default_encodings[2] = "windows-1251"; - default_encodings[3] = NULL; - encodings = (const char *const *) default_encodings; + lang_down = g_ascii_strdown(lang, -1); + if ((dot = strchr(lang_down, '.'))) + *dot = '\0'; + e = _system_encodings_for_lang(lang_down); + } + + if (!e) + e = _system_encodings_get_default(); + + /* in any case, @e is now a static buffer, that we may cache. */ + nm_assert(e); + + if (!g_atomic_pointer_compare_and_exchange(&cached, NULL, e)) + goto again; } - cached_encodings = encodings; - return cached_encodings; + return e; +} + +const char *const * +nmtst_system_encodings_get(void) +{ + return _system_encodings_get(); } /*****************************************************************************/ @@ -560,14 +572,14 @@ nm_utils_ssid_to_utf8(const guint8 *ssid, gsize len) { const char *const *encodings; const char *const *e; - char * converted = NULL; + char *converted = NULL; g_return_val_if_fail(ssid != NULL, NULL); if (g_utf8_validate((const char *) ssid, len, NULL)) return g_strndup((const char *) ssid, len); - encodings = get_system_encodings(); + encodings = _system_encodings_get(); for (e = encodings; *e; e++) { converted = g_convert((const char *) ssid, len, "UTF-8", *e, NULL, NULL, NULL); @@ -652,7 +664,7 @@ nm_utils_escape_ssid(const guint8 *ssid, gsize len) { static char escaped[NM_IW_ESSID_MAX_SIZE * 2 + 1]; const guint8 *s = ssid; - char * d = escaped; + char *d = escaped; if (nm_utils_is_empty_ssid(ssid, len)) { memcpy(escaped, "", sizeof("")); @@ -746,9 +758,9 @@ _nm_utils_string_slist_validate(GSList *list, const char **valid_values) GSList * _nm_utils_hash_values_to_slist(GHashTable *hash) { - GSList * list = NULL; + GSList *list = NULL; GHashTableIter iter; - void * value; + void *value; g_return_val_if_fail(hash, NULL); @@ -763,8 +775,8 @@ void _nm_utils_strdict_from_dbus(_NM_SETT_INFO_PROP_FROM_DBUS_GPROP_FCN_ARGS _nm_nil) { GVariantIter iter; - const char * key, *value; - GHashTable * hash; + const char *key, *value; + GHashTable *hash; hash = g_hash_table_new_full(nm_str_hash, g_str_equal, g_free, g_free); g_variant_iter_init(&iter, from); @@ -786,7 +798,7 @@ const NMSettInfoPropertType nm_sett_info_propert_type_strdict = GHashTable * _nm_utils_copy_strdict(GHashTable *strdict) { - GHashTable * copy; + GHashTable *copy; GHashTableIter iter; gpointer key, value; @@ -861,7 +873,7 @@ char ** _nm_utils_slist_to_strv(const GSList *slist, gboolean deep_copy) { const GSList *iter; - char ** strv; + char **strv; guint len, i; if (!slist) @@ -1328,7 +1340,7 @@ nm_utils_ip4_dns_from_variant(GVariant *value) { const guint32 *array; gsize length; - char ** dns; + char **dns; gsize i; g_return_val_if_fail(g_variant_is_of_type(value, G_VARIANT_TYPE("au")), NULL); @@ -1409,9 +1421,9 @@ nm_utils_ip4_addresses_to_variant(GPtrArray *addresses, const char *gateway) GPtrArray * nm_utils_ip4_addresses_from_variant(GVariant *value, char **out_gateway) { - GPtrArray * addresses; + GPtrArray *addresses; GVariantIter iter; - GVariant * addr_var; + GVariant *addr_var; g_return_val_if_fail(g_variant_is_of_type(value, G_VARIANT_TYPE("aau")), NULL); @@ -1424,8 +1436,8 @@ nm_utils_ip4_addresses_from_variant(GVariant *value, char **out_gateway) while (g_variant_iter_next(&iter, "@au", &addr_var)) { const guint32 *addr_array; gsize length; - NMIPAddress * addr; - GError * error = NULL; + NMIPAddress *addr; + GError *error = NULL; addr_array = g_variant_get_fixed_array(addr_var, &length, sizeof(guint32)); if (length < 3) { @@ -1506,8 +1518,8 @@ GPtrArray * nm_utils_ip4_routes_from_variant(GVariant *value) { GVariantIter iter; - GVariant * route_var; - GPtrArray * routes; + GVariant *route_var; + GPtrArray *routes; g_return_val_if_fail(g_variant_is_of_type(value, G_VARIANT_TYPE("aau")), NULL); @@ -1517,8 +1529,8 @@ nm_utils_ip4_routes_from_variant(GVariant *value) while (g_variant_iter_next(&iter, "@au", &route_var)) { const guint32 *route_array; gsize length; - NMIPRoute * route; - GError * error = NULL; + NMIPRoute *route; + GError *error = NULL; route_array = g_variant_get_fixed_array(route_var, &length, sizeof(guint32)); if (length < 4) { @@ -1647,8 +1659,8 @@ char ** nm_utils_ip6_dns_from_variant(GVariant *value) { GVariantIter iter; - GVariant * ip_var; - char ** dns; + GVariant *ip_var; + char **dns; gsize i; g_return_val_if_fail(g_variant_is_of_type(value, G_VARIANT_TYPE("aay")), NULL); @@ -1695,7 +1707,7 @@ nm_utils_ip6_addresses_to_variant(GPtrArray *addresses, const char *gateway) if (addresses) { for (i = 0; i < addresses->len; i++) { - NMIPAddress * addr = addresses->pdata[i]; + NMIPAddress *addr = addresses->pdata[i]; struct in6_addr address_bin; struct in6_addr gateway_bin_data; const struct in6_addr *gateway_bin; @@ -1741,9 +1753,9 @@ GPtrArray * nm_utils_ip6_addresses_from_variant(GVariant *value, char **out_gateway) { GVariantIter iter; - GVariant * addr_var, *gateway_var; + GVariant *addr_var, *gateway_var; guint32 prefix; - GPtrArray * addresses; + GPtrArray *addresses; g_return_val_if_fail(g_variant_is_of_type(value, G_VARIANT_TYPE("a(ayuay)")), NULL); @@ -1754,10 +1766,10 @@ nm_utils_ip6_addresses_from_variant(GVariant *value, char **out_gateway) addresses = g_ptr_array_new_with_free_func((GDestroyNotify) nm_ip_address_unref); while (g_variant_iter_next(&iter, "(@ayu@ay)", &addr_var, &prefix, &gateway_var)) { - NMIPAddress * addr; + NMIPAddress *addr; const struct in6_addr *addr_bytes, *gateway_bytes; gsize addr_len, gateway_len; - GError * error = NULL; + GError *error = NULL; if (!g_variant_is_of_type(addr_var, G_VARIANT_TYPE_BYTESTRING) || !g_variant_is_of_type(gateway_var, G_VARIANT_TYPE_BYTESTRING)) { @@ -1820,7 +1832,7 @@ nm_utils_ip6_routes_to_variant(GPtrArray *routes) if (routes) { for (i = 0; i < routes->len; i++) { - NMIPRoute * route = routes->pdata[i]; + NMIPRoute *route = routes->pdata[i]; struct in6_addr dest_bytes; struct in6_addr next_hop_bytes; guint32 metric; @@ -1860,9 +1872,9 @@ nm_utils_ip6_routes_to_variant(GPtrArray *routes) GPtrArray * nm_utils_ip6_routes_from_variant(GVariant *value) { - GPtrArray * routes; + GPtrArray *routes; GVariantIter iter; - GVariant * dest_var, *next_hop_var; + GVariant *dest_var, *next_hop_var; const struct in6_addr *dest, *next_hop; gsize dest_len, next_hop_len; guint32 prefix, metric; @@ -1874,7 +1886,7 @@ nm_utils_ip6_routes_from_variant(GVariant *value) g_variant_iter_init(&iter, value); while (g_variant_iter_next(&iter, "(@ayu@ayu)", &dest_var, &prefix, &next_hop_var, &metric)) { NMIPRoute *route; - GError * error = NULL; + GError *error = NULL; if (!g_variant_is_of_type(dest_var, G_VARIANT_TYPE_BYTESTRING) || !g_variant_is_of_type(next_hop_var, G_VARIANT_TYPE_BYTESTRING)) { @@ -1939,7 +1951,7 @@ nm_utils_ip_addresses_to_variant(GPtrArray *addresses) if (addresses) { for (i = 0; i < addresses->len; i++) { - NMIPAddress * addr = addresses->pdata[i]; + NMIPAddress *addr = addresses->pdata[i]; GVariantBuilder addr_builder; gs_free const char **names = NULL; guint j, len; @@ -1985,15 +1997,15 @@ nm_utils_ip_addresses_to_variant(GPtrArray *addresses) GPtrArray * nm_utils_ip_addresses_from_variant(GVariant *value, int family) { - GPtrArray * addresses; + GPtrArray *addresses; GVariantIter iter, attrs_iter; - GVariant * addr_var; - const char * ip; + GVariant *addr_var; + const char *ip; guint32 prefix; - const char * attr_name; - GVariant * attr_val; + const char *attr_name; + GVariant *attr_val; NMIPAddress *addr; - GError * error = NULL; + GError *error = NULL; g_return_val_if_fail(g_variant_is_of_type(value, G_VARIANT_TYPE("aa{sv}")), NULL); @@ -2051,7 +2063,7 @@ nm_utils_ip_routes_to_variant(GPtrArray *routes) if (routes) { for (i = 0; i < routes->len; i++) { - NMIPRoute * route = routes->pdata[i]; + NMIPRoute *route = routes->pdata[i]; GVariantBuilder route_builder; gs_free const char **names = NULL; guint j, len; @@ -2110,16 +2122,16 @@ nm_utils_ip_routes_to_variant(GPtrArray *routes) GPtrArray * nm_utils_ip_routes_from_variant(GVariant *value, int family) { - GPtrArray * routes; + GPtrArray *routes; GVariantIter iter, attrs_iter; - GVariant * route_var; - const char * dest, *next_hop; + GVariant *route_var; + const char *dest, *next_hop; guint32 prefix, metric32; gint64 metric; - const char * attr_name; - GVariant * attr_val; - NMIPRoute * route; - GError * error = NULL; + const char *attr_name; + GVariant *attr_val; + NMIPRoute *route; + GError *error = NULL; g_return_val_if_fail(g_variant_is_of_type(value, G_VARIANT_TYPE("aa{sv}")), NULL); @@ -2297,7 +2309,7 @@ static const NMVariantAttributeSpec *const tc_qdisc_fq_codel_spec[] = { }; typedef struct { - const char * kind; + const char *kind; const NMVariantAttributeSpec *const *attrs; } NMQdiscAttributeSpec; @@ -2323,7 +2335,7 @@ void _nm_utils_string_append_tc_qdisc_rest(GString *string, NMTCQdisc *qdisc) { guint32 handle = nm_tc_qdisc_get_handle(qdisc); - const char * kind = nm_tc_qdisc_get_kind(qdisc); + const char *kind = nm_tc_qdisc_get_kind(qdisc); gs_free char *str = NULL; if (handle != TC_H_UNSPEC && !NM_IN_STRSET(kind, "ingress", "clsact")) { @@ -2368,14 +2380,14 @@ nm_utils_tc_qdisc_to_str(NMTCQdisc *qdisc, GError **error) static gboolean _tc_read_common_opts(const char *str, - guint32 * handle, - guint32 * parent, - char ** kind, - char ** rest, - GError ** error) + guint32 *handle, + guint32 *parent, + char **kind, + char **rest, + GError **error) { gs_unref_hashtable GHashTable *ht = NULL; - GVariant * variant; + GVariant *variant; ht = nm_utils_parse_variant_attributes(str, ' ', ' ', FALSE, tc_object_attribute_spec, error); if (!ht) @@ -2456,11 +2468,11 @@ _tc_read_common_opts(const char *str, NMTCQdisc * nm_utils_tc_qdisc_from_str(const char *str, GError **error) { - guint32 handle = TC_H_UNSPEC; - guint32 parent = TC_H_UNSPEC; - gs_free char * kind = NULL; - gs_free char * rest = NULL; - NMTCQdisc * qdisc = NULL; + guint32 handle = TC_H_UNSPEC; + guint32 parent = TC_H_UNSPEC; + gs_free char *kind = NULL; + gs_free char *rest = NULL; + NMTCQdisc *qdisc = NULL; gs_unref_hashtable GHashTable *options = NULL; GHashTableIter iter; gpointer key, value; @@ -2541,8 +2553,8 @@ static const NMVariantAttributeSpec *const tc_action_attribute_spec[] = { static gboolean _string_append_tc_action(GString *string, NMTCAction *action, GError **error) { - const char * kind = nm_tc_action_get_kind(action); - gs_free char * str = NULL; + const char *kind = nm_tc_action_get_kind(action); + gs_free char *str = NULL; const NMVariantAttributeSpec *const *attrs; if (nm_streq(kind, "simple")) @@ -2605,12 +2617,12 @@ nm_utils_tc_action_to_str(NMTCAction *action, GError **error) NMTCAction * nm_utils_tc_action_from_str(const char *str, GError **error) { - const char * kind = NULL; - const char * rest = NULL; - nm_auto_unref_tc_action NMTCAction *action = NULL; - gs_unref_hashtable GHashTable *ht = NULL; - gs_unref_hashtable GHashTable * options = NULL; - GVariant * variant; + const char *kind = NULL; + const char *rest = NULL; + nm_auto_unref_tc_action NMTCAction *action = NULL; + gs_unref_hashtable GHashTable *ht = NULL; + gs_unref_hashtable GHashTable *options = NULL; + GVariant *variant; const NMVariantAttributeSpec *const *attrs; nm_assert(str); @@ -2753,15 +2765,15 @@ static const NMVariantAttributeSpec *const tc_tfilter_attribute_spec[] = { NMTCTfilter * nm_utils_tc_tfilter_from_str(const char *str, GError **error) { - guint32 handle = TC_H_UNSPEC; - guint32 parent = TC_H_UNSPEC; - gs_free char * kind = NULL; - gs_free char * rest = NULL; + guint32 handle = TC_H_UNSPEC; + guint32 parent = TC_H_UNSPEC; + gs_free char *kind = NULL; + gs_free char *rest = NULL; nm_auto_unref_tc_action NMTCAction *action = NULL; - const char * extra_opts = NULL; - NMTCTfilter * tfilter = NULL; - gs_unref_hashtable GHashTable *ht = NULL; - GVariant * variant; + const char *extra_opts = NULL; + NMTCTfilter *tfilter = NULL; + gs_unref_hashtable GHashTable *ht = NULL; + GVariant *variant; nm_assert(str); nm_assert(!error || !*error); @@ -2826,11 +2838,11 @@ char * nm_utils_sriov_vf_to_str(const NMSriovVF *vf, gboolean omit_index, GError **error) { gs_free NMUtilsNamedValue *values = NULL; - gs_free const char ** names = NULL; - const guint * vlan_ids; + gs_free const char **names = NULL; + const guint *vlan_ids; guint num_vlans, num_attrs; guint i; - GString * str; + GString *str; str = g_string_new(""); if (!omit_index) @@ -2987,7 +2999,7 @@ NMSriovVF * nm_utils_sriov_vf_from_str(const char *str, GError **error) { gs_free char *index_free = NULL; - const char * detail; + const char *detail; g_return_val_if_fail(str, NULL); g_return_val_if_fail(!error || !*error, NULL); @@ -3008,13 +3020,13 @@ NMSriovVF * _nm_utils_sriov_vf_from_strparts(const char *index, const char *detail, gboolean ignore_unknown, - GError ** error) + GError **error) { - NMSriovVF * vf; - guint32 n_index; - GHashTableIter iter; - char * key; - GVariant * variant; + NMSriovVF *vf; + guint32 n_index; + GHashTableIter iter; + char *key; + GVariant *variant; gs_unref_hashtable GHashTable *ht = NULL; n_index = _nm_utils_ascii_str_to_int64(index, 10, 0, G_MAXUINT32, 0); @@ -3102,7 +3114,7 @@ file_has_extension(const char *filename, const char *extensions[]) gboolean nm_utils_file_is_certificate(const char *filename) { - const char * extensions[] = {".der", ".pem", ".crt", ".cer", NULL}; + const char *extensions[] = {".der", ".pem", ".crt", ".cer", NULL}; NMCryptoFileFormat file_format; g_return_val_if_fail(filename != NULL, FALSE); @@ -3160,12 +3172,12 @@ nm_utils_file_is_pkcs12(const char *filename) /*****************************************************************************/ gboolean -_nm_utils_check_file(const char * filename, +_nm_utils_check_file(const char *filename, gint64 check_owner, NMUtilsCheckFilePredicate check_file, gpointer user_data, - struct stat * out_st, - GError ** error) + struct stat *out_st, + GError **error) { struct stat st_backup; @@ -3232,11 +3244,11 @@ _nm_utils_check_file(const char * filename, } gboolean -_nm_utils_check_module_file(const char * name, +_nm_utils_check_module_file(const char *name, int check_owner, NMUtilsCheckFilePredicate check_file, gpointer user_data, - GError ** error) + GError **error) { if (!g_path_is_absolute(name)) { g_set_error(error, @@ -3310,13 +3322,13 @@ _nm_utils_check_module_file(const char * name, * invocations of the function might overwrite it. */ const char * -nm_utils_file_search_in_paths(const char * progname, - const char * try_first, - const char *const * paths, +nm_utils_file_search_in_paths(const char *progname, + const char *try_first, + const char *const *paths, GFileTest file_test_flags, NMUtilsFileSearchInPathsPredicate predicate, gpointer user_data, - GError ** error) + GError **error) { g_return_val_if_fail(!error || !*error, NULL); g_return_val_if_fail(progname && progname[0] && !strchr(progname, '/'), NULL); @@ -3899,19 +3911,19 @@ _nm_utils_hwaddr_canonical_or_invalid(const char *mac, gssize length) } char * -_nm_utils_ipaddr_canonical_or_invalid(int addr_family, const char *ip) +_nm_utils_ipaddr_canonical_or_invalid(int addr_family, const char *ip, gboolean map_zero_to_null) { NMIPAddr addr_bin; - nm_assert_addr_family(addr_family); + nm_assert_addr_family_or_unspec(addr_family); if (!ip) return NULL; - if (!nm_utils_parse_inaddr_bin(addr_family, ip, NULL, &addr_bin)) + if (!nm_utils_parse_inaddr_bin(addr_family, ip, &addr_family, &addr_bin)) return g_strdup(ip); - if (nm_ip_addr_is_null(addr_family, &addr_bin)) + if (map_zero_to_null && nm_ip_addr_is_null(addr_family, &addr_bin)) return NULL; return nm_utils_inet_ntop_dup(addr_family, &addr_bin); @@ -4078,7 +4090,7 @@ _nm_utils_hwaddr_cloned_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) { gsize length; const guint8 *array; - char * str; + char *str; nm_assert(nm_streq0(property_info->name, "cloned-mac-address")); @@ -4174,10 +4186,10 @@ const NMSettInfoPropertType nm_sett_info_propert_type_assigned_mac_address = * For new settings, they shall validate the secret-flags strictly. */ gboolean _nm_utils_secret_flags_validate(NMSettingSecretFlags secret_flags, - const char * setting_name, - const char * property_name, + const char *setting_name, + const char *property_name, NMSettingSecretFlags disallowed_flags, - GError ** error) + GError **error) { if (secret_flags == NM_SETTING_SECRET_FLAG_NONE) return TRUE; @@ -4226,10 +4238,10 @@ _nm_utils_secret_flags_validate(NMSettingSecretFlags secret_flags, gboolean _nm_utils_wps_method_validate(NMSettingWirelessSecurityWpsMethod wps_method, - const char * setting_name, - const char * property_name, + const char *setting_name, + const char *property_name, gboolean wps_required, - GError ** error) + GError **error) { if (wps_method > NM_SETTING_WIRELESS_SECURITY_WPS_METHOD_PIN) { g_set_error_literal(error, @@ -4283,15 +4295,15 @@ _split_word(char *s) } gboolean -_nm_utils_generate_mac_address_mask_parse(const char * value, - struct ether_addr * out_mask, +_nm_utils_generate_mac_address_mask_parse(const char *value, + struct ether_addr *out_mask, struct ether_addr **out_ouis, - gsize * out_ouis_len, - GError ** error) + gsize *out_ouis_len, + GError **error) { - gs_free char * s_free = NULL; - char * s, *s_next; - struct ether_addr mask; + gs_free char *s_free = NULL; + char *s, *s_next; + struct ether_addr mask; gs_unref_array GArray *ouis = NULL; g_return_val_if_fail(!error || !*error, FALSE); @@ -4694,7 +4706,7 @@ guint _nm_utils_strstrdictkey_hash(gconstpointer a) { const NMUtilsStrStrDictKey *k = a; - const char * p; + const char *p; NMHashState h; nm_hash_init(&h, 76642997u); @@ -4777,7 +4789,7 @@ _nm_utils_strstrdictkey_create(const char *v1, const char *v2) } static gboolean -validate_dns_option(const char * name, +validate_dns_option(const char *name, gboolean numeric, gboolean ipv6, const NMUtilsDNSOptionDesc *option_descs) @@ -4813,16 +4825,16 @@ validate_dns_option(const char * name, * %FALSE otherwise */ gboolean -_nm_utils_dns_option_validate(const char * option, - char ** out_name, - long * out_value, +_nm_utils_dns_option_validate(const char *option, + char **out_name, + long *out_value, gboolean ipv6, const NMUtilsDNSOptionDesc *option_descs) { gs_free char *option0_free = NULL; - const char * option0; - const char * option1; - const char * delim; + const char *option0; + const char *option1; + const char *delim; long option1_num; g_return_val_if_fail(option != NULL, FALSE); @@ -5013,7 +5025,7 @@ gboolean nm_utils_is_json_object(const char *str, GError **error) { nm_auto_decref_json nm_json_t *json = NULL; - const NMJsonVt * vt; + const NMJsonVt *vt; nm_json_error_t jerror; g_return_val_if_fail(!error || !*error, FALSE); @@ -5097,7 +5109,7 @@ _nmtst_variant_attribute_spec_assert_sorted(const NMVariantAttributeSpec *const const NMVariantAttributeSpec * _nm_variant_attribute_spec_find_binary_search(const NMVariantAttributeSpec *const *array, gsize len, - const char * name) + const char *name) { gssize idx; @@ -5132,16 +5144,16 @@ _nm_variant_attribute_spec_find_binary_search(const NMVariantAttributeSpec *cons * Since: 1.8 */ GHashTable * -nm_utils_parse_variant_attributes(const char * string, +nm_utils_parse_variant_attributes(const char *string, char attr_separator, char key_value_separator, gboolean ignore_unknown, const NMVariantAttributeSpec *const *spec, - GError ** error) + GError **error) { - gs_unref_hashtable GHashTable * ht = NULL; - const char * ptr = string, *start = NULL, *sep; - GVariant * variant; + gs_unref_hashtable GHashTable *ht = NULL; + const char *ptr = string, *start = NULL, *sep; + GVariant *variant; const NMVariantAttributeSpec *const *s; g_return_val_if_fail(string, NULL); @@ -5460,11 +5472,11 @@ nm_utils_base64secret_decode(const char *base64_key, gsize required_key_len, gui gboolean nm_utils_base64secret_normalize(const char *base64_key, gsize required_key_len, - char ** out_base64_key_norm) + char **out_base64_key_norm) { gs_free guint8 *buf_free = NULL; guint8 buf_static[200]; - guint8 * buf; + guint8 *buf; if (required_key_len > sizeof(buf_static)) { buf_free = g_new(guint8, required_key_len); @@ -5488,7 +5500,7 @@ _nm_utils_bridge_vlans_to_dbus(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) gs_unref_ptrarray GPtrArray *vlans = NULL; GVariantBuilder builder; guint i; - const char * property_name = property_info->name; + const char *property_name = property_info->name; nm_assert(property_name); @@ -5497,7 +5509,7 @@ _nm_utils_bridge_vlans_to_dbus(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) if (vlans) { for (i = 0; i < vlans->len; i++) { - NMBridgeVlan * vlan = vlans->pdata[i]; + NMBridgeVlan *vlan = vlans->pdata[i]; GVariantBuilder vlan_builder; guint16 vid_start, vid_end; @@ -5529,7 +5541,7 @@ _nm_utils_bridge_vlans_from_dbus(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) { gs_unref_ptrarray GPtrArray *vlans = NULL; GVariantIter vlan_iter; - GVariant * vlan_var; + GVariant *vlan_var; g_return_val_if_fail(g_variant_is_of_type(value, G_VARIANT_TYPE("aa{sv}")), FALSE); @@ -5537,7 +5549,7 @@ _nm_utils_bridge_vlans_from_dbus(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) g_variant_iter_init(&vlan_iter, value); while (g_variant_iter_next(&vlan_iter, "@a{sv}", &vlan_var)) { _nm_unused gs_unref_variant GVariant *var_unref = vlan_var; - NMBridgeVlan * vlan; + NMBridgeVlan *vlan; guint16 vid_start, vid_end; gboolean pvid = FALSE, untagged = FALSE; @@ -5587,13 +5599,13 @@ _nm_utils_bridge_compare_vlans(GPtrArray *vlans_a, GPtrArray *vlans_b) } gboolean -_nm_utils_bridge_vlan_verify_list(GPtrArray * vlans, +_nm_utils_bridge_vlan_verify_list(GPtrArray *vlans, gboolean check_normalizable, - GError ** error, + GError **error, const char *setting, const char *property) { - guint i; + guint i; gs_unref_hashtable GHashTable *h = NULL; gboolean pvid_found = FALSE; diff --git a/src/libnm-core-impl/nm-vpn-editor-plugin.c b/src/libnm-core-impl/nm-vpn-editor-plugin.c index 468ddcea..225f25ef 100644 --- a/src/libnm-core-impl/nm-vpn-editor-plugin.c +++ b/src/libnm-core-impl/nm-vpn-editor-plugin.c @@ -141,7 +141,7 @@ void nm_vpn_editor_plugin_set_plugin_info(NMVpnEditorPlugin *plugin, NMVpnPluginInfo *plugin_info) { NMVpnEditorPluginInterface *interface; - NMVpnEditorPluginPrivate * priv; + NMVpnEditorPluginPrivate *priv; g_return_if_fail(NM_IS_VPN_EDITOR_PLUGIN(plugin)); @@ -192,7 +192,7 @@ nm_vpn_editor_plugin_set_plugin_info(NMVpnEditorPlugin *plugin, NMVpnPluginInfo gsize nm_vpn_editor_plugin_get_vt(NMVpnEditorPlugin *plugin, NMVpnEditorPluginVT *vt, gsize vt_size) { - const NMVpnEditorPluginVT * p_vt = NULL; + const NMVpnEditorPluginVT *p_vt = NULL; gsize p_vt_size = 0; NMVpnEditorPluginInterface *interface; @@ -218,23 +218,23 @@ nm_vpn_editor_plugin_get_vt(NMVpnEditorPlugin *plugin, NMVpnEditorPluginVT *vt, /*****************************************************************************/ static NMVpnEditorPlugin * -_nm_vpn_editor_plugin_load(const char * plugin_name, +_nm_vpn_editor_plugin_load(const char *plugin_name, gboolean do_file_checks, - const char * check_service, + const char *check_service, int check_owner, NMUtilsCheckFilePredicate check_file, gpointer user_data, - GError ** error) + GError **error) { - void * dl_module = NULL; - gboolean loaded_before; - NMVpnEditorPluginFactory factory = NULL; + void *dl_module = NULL; + gboolean loaded_before; + NMVpnEditorPluginFactory factory = NULL; gs_unref_object NMVpnEditorPlugin *editor_plugin = NULL; - gs_free char * plugin_filename_free = NULL; - const char * plugin_filename; - gs_free_error GError *factory_error = NULL; - gs_free char * plug_name = NULL; - gs_free char * plug_service = NULL; + gs_free char *plugin_filename_free = NULL; + const char *plugin_filename; + gs_free_error GError *factory_error = NULL; + gs_free char *plug_name = NULL; + gs_free char *plug_service = NULL; g_return_val_if_fail(plugin_name && *plugin_name, NULL); @@ -385,12 +385,12 @@ _nm_vpn_editor_plugin_load(const char * plugin_name, * Since: 1.2 */ NMVpnEditorPlugin * -nm_vpn_editor_plugin_load_from_file(const char * plugin_name, - const char * check_service, +nm_vpn_editor_plugin_load_from_file(const char *plugin_name, + const char *check_service, int check_owner, NMUtilsCheckFilePredicate check_file, gpointer user_data, - GError ** error) + GError **error) { return _nm_vpn_editor_plugin_load(plugin_name, TRUE, @@ -484,9 +484,9 @@ nm_vpn_editor_plugin_import(NMVpnEditorPlugin *plugin, const char *path, GError gboolean nm_vpn_editor_plugin_export(NMVpnEditorPlugin *plugin, - const char * path, - NMConnection * connection, - GError ** error) + const char *path, + NMConnection *connection, + GError **error) { g_return_val_if_fail(NM_IS_VPN_EDITOR_PLUGIN(plugin), FALSE); diff --git a/src/libnm-core-impl/nm-vpn-plugin-info.c b/src/libnm-core-impl/nm-vpn-plugin-info.c index 2ffb7774..473063fb 100644 --- a/src/libnm-core-impl/nm-vpn-plugin-info.c +++ b/src/libnm-core-impl/nm-vpn-plugin-info.c @@ -25,11 +25,11 @@ enum { }; typedef struct { - char * filename; - char * name; - char * service; - char * auth_dialog; - char ** aliases; + char *filename; + char *name; + char *service; + char *auth_dialog; + char **aliases; GKeyFile *keyfile; /* It is convenient for nm_vpn_plugin_info_lookup_property() to return a const char *, @@ -96,14 +96,14 @@ nm_vpn_plugin_info_validate_filename(const char *filename) } static gboolean -nm_vpn_plugin_info_check_file_full(const char * filename, +nm_vpn_plugin_info_check_file_full(const char *filename, gboolean check_absolute, gboolean do_validate_filename, gint64 check_owner, NMUtilsCheckFilePredicate check_file, gpointer user_data, - struct stat * out_st, - GError ** error) + struct stat *out_st, + GError **error) { if (!filename || !*filename) { g_set_error(error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_FAILED, _("missing filename")); @@ -153,13 +153,13 @@ nm_vpn_plugin_info_check_file_full(const char * filename, * Since: 1.2 */ gboolean -_nm_vpn_plugin_info_check_file(const char * filename, +_nm_vpn_plugin_info_check_file(const char *filename, gboolean check_absolute, gboolean do_validate_filename, gint64 check_owner, NMUtilsCheckFilePredicate check_file, gpointer user_data, - GError ** error) + GError **error) { return nm_vpn_plugin_info_check_file_full(filename, check_absolute, @@ -244,16 +244,16 @@ _nm_vpn_plugin_info_get_default_dir_user() * Returns: (transfer full) (element-type NMVpnPluginInfo): list of loaded plugin infos. */ GSList * -_nm_vpn_plugin_info_list_load_dir(const char * dirname, +_nm_vpn_plugin_info_list_load_dir(const char *dirname, gboolean do_validate_filename, gint64 check_owner, NMUtilsCheckFilePredicate check_file, gpointer user_data) { - GDir * dir; + GDir *dir; const char *fn; - GArray * array; - GSList * res = NULL; + GArray *array; + GSList *res = NULL; guint i; g_return_val_if_fail(dirname, NULL); @@ -316,8 +316,8 @@ nm_vpn_plugin_info_list_load() { int i; gint64 uid; - GSList * list = NULL; - GSList * infos, *info; + GSList *list = NULL; + GSList *infos, *info; const char *const dir[] = { /* We load plugins from NM_VPN_PLUGIN_DIR *and* DEFAULT_DIR*, with * preference to the former. @@ -370,7 +370,7 @@ NMVpnPluginInfo * nm_vpn_plugin_info_new_search_file(const char *name, const char *service) { NMVpnPluginInfo *info; - GSList * infos; + GSList *infos; if (!name && !service) g_return_val_if_reached(NULL); @@ -402,7 +402,7 @@ _check_no_conflict(NMVpnPluginInfo *i1, NMVpnPluginInfo *i2, GError **error) for (i = 0; i < G_N_ELEMENTS(check_list); i++) { gs_free NMUtilsStrStrDictKey *k = NULL; - const char * s1, *s2; + const char *s1, *s2; k = _nm_utils_strstrdictkey_create(check_list[i].group, check_list[i].key); s1 = g_hash_table_lookup(priv1->keys, k); @@ -440,7 +440,7 @@ _check_no_conflict(NMVpnPluginInfo *i1, NMVpnPluginInfo *i2, GError **error) gboolean nm_vpn_plugin_info_list_add(GSList **list, NMVpnPluginInfo *plugin_info, GError **error) { - GSList * iter; + GSList *iter; const char *name; g_return_val_if_fail(list, FALSE); @@ -619,7 +619,7 @@ char * nm_vpn_plugin_info_list_find_service_type(GSList *list, const char *name) { NMVpnPluginInfo *info; - char * n; + char *n; if (!name) g_return_val_if_reached(NULL); @@ -685,12 +685,12 @@ _service_type_get_default_abbreviation(const char *service_type) * Since: 1.4 */ char ** -nm_vpn_plugin_info_list_get_service_types(GSList * list, +nm_vpn_plugin_info_list_get_service_types(GSList *list, gboolean only_existing, gboolean with_abbreviations) { - GSList * iter; - GPtrArray * l; + GSList *iter; + GPtrArray *l; guint i, j; const char *n; @@ -953,7 +953,7 @@ nm_vpn_plugin_info_get_aliases(NMVpnPluginInfo *self) const char * nm_vpn_plugin_info_lookup_property(NMVpnPluginInfo *self, const char *group, const char *key) { - NMVpnPluginInfoPrivate *priv; + NMVpnPluginInfoPrivate *priv; gs_free NMUtilsStrStrDictKey *k = NULL; g_return_val_if_fail(NM_IS_VPN_PLUGIN_INFO(self), NULL); @@ -997,7 +997,7 @@ void nm_vpn_plugin_info_set_editor_plugin(NMVpnPluginInfo *self, NMVpnEditorPlugin *plugin) { NMVpnPluginInfoPrivate *priv; - NMVpnEditorPlugin * old; + NMVpnEditorPlugin *old; g_return_if_fail(NM_IS_VPN_PLUGIN_INFO(self)); g_return_if_fail(!plugin || G_IS_OBJECT(plugin)); @@ -1033,7 +1033,7 @@ NMVpnEditorPlugin * nm_vpn_plugin_info_load_editor_plugin(NMVpnPluginInfo *self, GError **error) { NMVpnPluginInfoPrivate *priv; - const char * plugin_filename; + const char *plugin_filename; g_return_val_if_fail(NM_IS_VPN_PLUGIN_INFO(self), NULL); @@ -1121,9 +1121,9 @@ nm_vpn_plugin_info_init(NMVpnPluginInfo *plugin) static gboolean init_sync(GInitable *initable, GCancellable *cancellable, GError **error) { - NMVpnPluginInfo * self = NM_VPN_PLUGIN_INFO(initable); + NMVpnPluginInfo *self = NM_VPN_PLUGIN_INFO(initable); NMVpnPluginInfoPrivate *priv = NM_VPN_PLUGIN_INFO_GET_PRIVATE(self); - gs_strfreev char ** groups = NULL; + gs_strfreev char **groups = NULL; guint i, j; if (!priv->keyfile) { @@ -1258,7 +1258,7 @@ nm_vpn_plugin_info_new_with_data(const char *filename, GKeyFile *keyfile, GError static void dispose(GObject *object) { - NMVpnPluginInfo * self = NM_VPN_PLUGIN_INFO(object); + NMVpnPluginInfo *self = NM_VPN_PLUGIN_INFO(object); NMVpnPluginInfoPrivate *priv = NM_VPN_PLUGIN_INFO_GET_PRIVATE(self); g_clear_object(&priv->editor_plugin); @@ -1269,7 +1269,7 @@ dispose(GObject *object) static void finalize(GObject *object) { - NMVpnPluginInfo * self = NM_VPN_PLUGIN_INFO(object); + NMVpnPluginInfo *self = NM_VPN_PLUGIN_INFO(object); NMVpnPluginInfoPrivate *priv = NM_VPN_PLUGIN_INFO_GET_PRIVATE(self); g_free(priv->name); diff --git a/src/libnm-core-impl/tests/test-compare.c b/src/libnm-core-impl/tests/test-compare.c index 3716399a..77d2e17b 100644 --- a/src/libnm-core-impl/tests/test-compare.c +++ b/src/libnm-core-impl/tests/test-compare.c @@ -37,7 +37,7 @@ compare_ints(void) static void compare_strings(void) { - GVariant * value1, *value2; + GVariant *value1, *value2; const char *str1 = "hello"; const char *str2 = "world"; @@ -58,7 +58,7 @@ compare_strings(void) static void compare_strv(void) { - GVariant * value1, *value2; + GVariant *value1, *value2; const char *const strv1[] = {"foo", "bar", "baz", NULL}; const char *const strv2[] = {"foo", "bar", "bar", NULL}; const char *const strv3[] = {"foo", "bar", NULL}; @@ -123,7 +123,7 @@ compare_arrays(void) static void compare_str_hash(void) { - GVariant * value1, *value2; + GVariant *value1, *value2; GVariantBuilder builder; g_variant_builder_init(&builder, G_VARIANT_TYPE("a{ss}")); @@ -165,7 +165,7 @@ compare_str_hash(void) static void compare_ip6_addresses(void) { - GVariant * value1, *value2; + GVariant *value1, *value2; struct in6_addr addr1; struct in6_addr addr2; struct in6_addr addr3; diff --git a/src/libnm-core-impl/tests/test-crypto.c b/src/libnm-core-impl/tests/test-crypto.c index 1c072f71..6a6e7fbc 100644 --- a/src/libnm-core-impl/tests/test-crypto.c +++ b/src/libnm-core-impl/tests/test-crypto.c @@ -80,10 +80,10 @@ out: static void test_cert(gconstpointer test_data) { - gs_free char * path = NULL; + gs_free char *path = NULL; gs_unref_bytes GBytes *cert = NULL; NMCryptoFileFormat format = NM_CRYPTO_FILE_FORMAT_UNKNOWN; - GError * error = NULL; + GError *error = NULL; gboolean success; path = g_build_filename(TEST_CERT_DIR, (const char *) test_data, NULL); @@ -101,10 +101,10 @@ test_load_private_key(const char *path, const char *decrypted_path, int expected_error) { - NMCryptoKeyType key_type = NM_CRYPTO_KEY_TYPE_UNKNOWN; - gboolean is_encrypted = FALSE; - gs_unref_bytes GBytes *array = NULL; - GError * error = NULL; + NMCryptoKeyType key_type = NM_CRYPTO_KEY_TYPE_UNKNOWN; + gboolean is_encrypted = FALSE; + gs_unref_bytes GBytes *array = NULL; + GError *error = NULL; g_assert(nm_utils_file_is_private_key(path, &is_encrypted)); g_assert(is_encrypted); @@ -144,7 +144,7 @@ test_load_pkcs12(const char *path, const char *password, int expected_error) { NMCryptoFileFormat format = NM_CRYPTO_FILE_FORMAT_UNKNOWN; gboolean is_encrypted = FALSE; - GError * error = NULL; + GError *error = NULL; g_assert(nm_utils_file_is_private_key(path, NULL)); @@ -165,7 +165,7 @@ test_load_pkcs12_no_password(const char *path) { NMCryptoFileFormat format = NM_CRYPTO_FILE_FORMAT_UNKNOWN; gboolean is_encrypted = FALSE; - GError * error = NULL; + GError *error = NULL; g_assert(nm_utils_file_is_private_key(path, NULL)); @@ -180,7 +180,7 @@ static void test_is_pkcs12(const char *path, gboolean expect_fail) { gboolean is_pkcs12; - GError * error = NULL; + GError *error = NULL; is_pkcs12 = nm_crypto_is_pkcs12_file(path, &error); @@ -199,7 +199,7 @@ test_load_pkcs8(const char *path, const char *password, int expected_error) { NMCryptoFileFormat format = NM_CRYPTO_FILE_FORMAT_UNKNOWN; gboolean is_encrypted = FALSE; - GError * error = NULL; + GError *error = NULL; g_assert(nm_utils_file_is_private_key(path, NULL)); @@ -218,11 +218,11 @@ test_load_pkcs8(const char *path, const char *password, int expected_error) static void test_encrypt_private_key(const char *path, const char *password) { - NMCryptoKeyType key_type = NM_CRYPTO_KEY_TYPE_UNKNOWN; + NMCryptoKeyType key_type = NM_CRYPTO_KEY_TYPE_UNKNOWN; gs_unref_bytes GBytes *array = NULL; gs_unref_bytes GBytes *encrypted = NULL; gs_unref_bytes GBytes *re_decrypted = NULL; - GError * error = NULL; + GError *error = NULL; array = nmtst_crypto_decrypt_openssl_private_key(path, password, &key_type, &error); nmtst_assert_success(array, error); @@ -281,7 +281,7 @@ test_key_decrypted(gconstpointer test_data) { const char *file = (const char *) test_data; gboolean is_encrypted = FALSE; - char * path; + char *path; path = g_build_filename(TEST_CERT_DIR, file, NULL); @@ -404,7 +404,7 @@ NMTST_DEFINE(); int main(int argc, char **argv) { - GError * error = NULL; + GError *error = NULL; gboolean success; int ret; diff --git a/src/libnm-core-impl/tests/test-general.c b/src/libnm-core-impl/tests/test-general.c index 5c831cb7..d0f85a9f 100644 --- a/src/libnm-core-impl/tests/test-general.c +++ b/src/libnm-core-impl/tests/test-general.c @@ -13,12 +13,13 @@ #include #include -#include "libnm-std-aux/c-list-util.h" -#include "libnm-glib-aux/nm-uuid.h" +#include "libnm-base/nm-base.h" #include "libnm-glib-aux/nm-enum-utils.h" -#include "libnm-glib-aux/nm-str-buf.h" #include "libnm-glib-aux/nm-json-aux.h" -#include "libnm-base/nm-base.h" +#include "libnm-glib-aux/nm-ref-string.h" +#include "libnm-glib-aux/nm-str-buf.h" +#include "libnm-glib-aux/nm-uuid.h" +#include "libnm-std-aux/c-list-util.h" #include "libnm-systemd-shared/nm-sd-utils-shared.h" #include "nm-utils.h" @@ -110,8 +111,8 @@ static void test_wired_wake_on_lan_enum(void) { nm_auto_unref_gtypeclass GFlagsClass *flags_class = NULL; - gs_unref_hashtable GHashTable *vals = g_hash_table_new(nm_direct_hash, NULL); - guint i; + gs_unref_hashtable GHashTable *vals = g_hash_table_new(nm_direct_hash, NULL); + guint i; G_STATIC_ASSERT_EXPR(sizeof(NMSettingWiredWakeOnLan) == sizeof(_NMSettingWiredWakeOnLan)); G_STATIC_ASSERT_EXPR(sizeof(NMSettingWiredWakeOnLan) < sizeof(gint64)); @@ -161,8 +162,8 @@ static void test_wireless_wake_on_wlan_enum(void) { nm_auto_unref_gtypeclass GFlagsClass *flags_class = NULL; - gs_unref_hashtable GHashTable *vals = g_hash_table_new(nm_direct_hash, NULL); - guint i; + gs_unref_hashtable GHashTable *vals = g_hash_table_new(nm_direct_hash, NULL); + guint i; G_STATIC_ASSERT_EXPR(sizeof(NMSettingWirelessWakeOnWLan) == sizeof(_NMSettingWirelessWakeOnWLan)); @@ -215,8 +216,8 @@ static void test_device_wifi_capabilities(void) { nm_auto_unref_gtypeclass GFlagsClass *flags_class = NULL; - gs_unref_hashtable GHashTable *vals = g_hash_table_new(nm_direct_hash, NULL); - guint i; + gs_unref_hashtable GHashTable *vals = g_hash_table_new(nm_direct_hash, NULL); + guint i; G_STATIC_ASSERT_EXPR(sizeof(NMDeviceWifiCapabilities) == sizeof(_NMDeviceWifiCapabilities)); G_STATIC_ASSERT_EXPR(sizeof(NMDeviceWifiCapabilities) < sizeof(gint64)); @@ -268,8 +269,8 @@ static void test_80211_mode(void) { nm_auto_unref_gtypeclass GEnumClass *enum_class = NULL; - gs_unref_hashtable GHashTable *vals = g_hash_table_new(nm_direct_hash, NULL); - guint i; + gs_unref_hashtable GHashTable *vals = g_hash_table_new(nm_direct_hash, NULL); + guint i; G_STATIC_ASSERT_EXPR(sizeof(NM80211Mode) == sizeof(_NM80211Mode)); G_STATIC_ASSERT_EXPR(sizeof(NM80211Mode) < sizeof(gint64)); @@ -312,8 +313,8 @@ static void test_vlan_flags(void) { nm_auto_unref_gtypeclass GFlagsClass *flags_class = NULL; - gs_unref_hashtable GHashTable *vals = g_hash_table_new(nm_direct_hash, NULL); - guint i; + gs_unref_hashtable GHashTable *vals = g_hash_table_new(nm_direct_hash, NULL); + guint i; G_STATIC_ASSERT_EXPR(sizeof(NMVlanFlags) == sizeof(_NMVlanFlags)); G_STATIC_ASSERT_EXPR(sizeof(NMVlanFlags) < sizeof(gint64)); @@ -543,9 +544,9 @@ test_nm_g_slice_free_fcn(void) static void _do_test_nm_strsplit_set_f_one(NMUtilsStrsplitSetFlags flags, - const char * str, + const char *str, gsize words_len, - const char *const * exp_words) + const char *const *exp_words) { #define DELIMITERS " \n" #define DELIMITERS_C ' ', '\n' @@ -554,7 +555,7 @@ _do_test_nm_strsplit_set_f_one(NMUtilsStrsplitSetFlags flags, gsize i, j, k; const gboolean f_allow_escaping = NM_FLAGS_HAS(flags, NM_STRSPLIT_SET_FLAGS_ALLOW_ESCAPING); const gboolean f_preserve_empty = NM_FLAGS_HAS(flags, NM_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY); - const char * s1; + const char *s1; gsize initial_offset; gs_strfreev char **words_g = NULL; @@ -750,9 +751,9 @@ _do_test_nm_strsplit_set_f_one(NMUtilsStrsplitSetFlags flags, static void _do_test_nm_strsplit_set_f(NMUtilsStrsplitSetFlags flags, - const char * str, + const char *str, gsize words_len, - const char *const * exp_words) + const char *const *exp_words) { _do_test_nm_strsplit_set_f_one(flags, str, words_len, exp_words); @@ -784,9 +785,9 @@ _do_test_nm_strsplit_set_f(NMUtilsStrsplitSetFlags flags, static void _do_test_nm_strsplit_set_simple(NMUtilsStrsplitSetFlags flags, - const char * str, + const char *str, gsize words_len, - const char *const * exp_words) + const char *const *exp_words) { gs_free const char **tokens = NULL; gsize n_tokens; @@ -1108,7 +1109,7 @@ _escaped_tokens_split(char *str, const char **out_key, const char **out_val) } static void -_escaped_tokens_combine(GString * combined, +_escaped_tokens_combine(GString *combined, const char *key, const char *val, gboolean strict, @@ -1139,9 +1140,9 @@ _escaped_tokens_combine(GString * combined, } static void -_escaped_tokens_check_one_impl(const char * expected_key, - const char * expected_val, - const char * expected_combination, +_escaped_tokens_check_one_impl(const char *expected_key, + const char *expected_val, + const char *expected_combination, const char *const *other, gsize n_other) { @@ -1158,11 +1159,11 @@ _escaped_tokens_check_one_impl(const char * expected_key, for (i = 0; i < n_other + 2u; i++) { nm_auto_free_gstring GString *str0 = NULL; - gs_free const char ** strv_split = NULL; - gs_free char * strv_split0 = NULL; - const char * comb; - const char * key; - const char * val; + gs_free const char **strv_split = NULL; + gs_free char *strv_split0 = NULL; + const char *comb; + const char *key; + const char *val; if (i == 0) comb = expected_combination; @@ -1208,10 +1209,10 @@ test_nm_utils_escaped_tokens(void) int i_run; for (i_run = 0; i_run < 1000; i_run++) { - const guint num_options = nmtst_get_rand_word_length(NULL); - gs_unref_ptrarray GPtrArray *options = g_ptr_array_new_with_free_func(g_free); - nm_auto_free_gstring GString *combined = g_string_new(NULL); - gs_free const char ** strv_split = NULL; + const guint num_options = nmtst_get_rand_word_length(NULL); + gs_unref_ptrarray GPtrArray *options = g_ptr_array_new_with_free_func(g_free); + nm_auto_free_gstring GString *combined = g_string_new(NULL); + gs_free const char **strv_split = NULL; guint i_option; guint i; @@ -1244,8 +1245,8 @@ test_nm_utils_escaped_tokens(void) /* ensure that we can split and parse the options without difference. */ strv_split = nm_utils_escaped_tokens_options_split_list(combined->str); for (i_option = 0; i_option < num_options; i_option++) { - const char * expected_key = options->pdata[2u * i_option + 0u]; - const char * expected_val = options->pdata[2u * i_option + 1u]; + const char *expected_key = options->pdata[2u * i_option + 0u]; + const char *expected_val = options->pdata[2u * i_option + 1u]; gs_free char *s_split = i_option < NM_PTRARRAY_LEN(strv_split) ? g_strdup(strv_split[i_option]) : NULL; const char *key = NULL; @@ -1301,7 +1302,7 @@ test_nm_utils_escaped_tokens(void) */ for (i = 0; i < 1u + 2u * i_option; i++) { gs_free char *str = NULL; - const char * cstr; + const char *cstr; if (i == 0) cstr = combined->str; @@ -1359,7 +1360,7 @@ _do_test_c_list_sort(CListSort *elements, guint n_list, gboolean headless) CList head, *iter, *iter_prev, *lst; guint i; const CListSort *el_prev; - CListSort * el; + CListSort *el; c_list_init(&head); for (i = 0; i < n_list; i++) { @@ -1409,8 +1410,8 @@ _do_test_c_list_sort(CListSort *elements, guint n_list, gboolean headless) static void test_c_list_sort(void) { - const guint N_ELEMENTS = 10000; - guint n_list, repeat; + const guint N_ELEMENTS = 10000; + guint n_list, repeat; gs_free CListSort *elements = NULL; { @@ -1545,11 +1546,11 @@ _dedup_idx_assert(const NMDedupMultiIdxType *idx_type) static void _dedup_idx_obj_id_hash_update(const NMDedupMultiIdxType *idx_type, - const NMDedupMultiObj * obj, - NMHashState * h) + const NMDedupMultiObj *obj, + NMHashState *h) { const DedupIdxType *t; - const DedupObj * o; + const DedupObj *o; t = _dedup_idx_assert(idx_type); o = _dedup_obj_assert(obj); @@ -1560,12 +1561,12 @@ _dedup_idx_obj_id_hash_update(const NMDedupMultiIdxType *idx_type, static gboolean _dedup_idx_obj_id_equal(const NMDedupMultiIdxType *idx_type, - const NMDedupMultiObj * obj_a, - const NMDedupMultiObj * obj_b) + const NMDedupMultiObj *obj_a, + const NMDedupMultiObj *obj_b) { const DedupIdxType *t; - const DedupObj * o_a; - const DedupObj * o_b; + const DedupObj *o_a; + const DedupObj *o_b; t = _dedup_idx_assert(idx_type); o_a = _dedup_obj_assert(obj_a); @@ -1577,11 +1578,11 @@ _dedup_idx_obj_id_equal(const NMDedupMultiIdxType *idx_type, static void _dedup_idx_obj_partition_hash_update(const NMDedupMultiIdxType *idx_type, - const NMDedupMultiObj * obj, - NMHashState * h) + const NMDedupMultiObj *obj, + NMHashState *h) { const DedupIdxType *t; - const DedupObj * o; + const DedupObj *o; t = _dedup_idx_assert(idx_type); o = _dedup_obj_assert(obj); @@ -1591,12 +1592,12 @@ _dedup_idx_obj_partition_hash_update(const NMDedupMultiIdxType *idx_type, static gboolean _dedup_idx_obj_partition_equal(const NMDedupMultiIdxType *idx_type, - const NMDedupMultiObj * obj_a, - const NMDedupMultiObj * obj_b) + const NMDedupMultiObj *obj_a, + const NMDedupMultiObj *obj_b) { const DedupIdxType *t; - const DedupObj * o_a; - const DedupObj * o_b; + const DedupObj *o_a; + const DedupObj *o_b; t = _dedup_idx_assert(idx_type); o_a = _dedup_obj_assert(obj_a); @@ -1622,9 +1623,9 @@ DEDUP_IDX_TYPE_INIT(DedupIdxType *idx_type, guint partition_size, guint val_mod) } static gboolean -_dedup_idx_add(NMDedupMultiIndex * idx, - const DedupIdxType * idx_type, - const DedupObj * obj, +_dedup_idx_add(NMDedupMultiIndex *idx, + const DedupIdxType *idx_type, + const DedupObj *obj, NMDedupMultiIdxMode mode, const NMDedupMultiEntry **out_entry) { @@ -1675,7 +1676,7 @@ _dedup_entry_get_idx_type(const NMDedupMultiEntry *entry) static void _dedup_entry_assert_all(const NMDedupMultiEntry *entry, gssize expected_idx, - const DedupObj *const * expected_obj) + const DedupObj *const *expected_obj) { gsize n, i; CList *iter; @@ -1698,8 +1699,8 @@ _dedup_entry_assert_all(const NMDedupMultiEntry *entry, i = 0; c_list_for_each (iter, &entry->head->lst_entries_head) { const NMDedupMultiEntry *entry_current = c_list_entry(iter, NMDedupMultiEntry, lst_entries); - const DedupObj * obj_current; - const DedupIdxType * idx_type = _dedup_entry_get_idx_type(entry_current); + const DedupObj *obj_current; + const DedupIdxType *idx_type = _dedup_entry_get_idx_type(entry_current); obj_current = _dedup_entry_assert(entry_current); g_assert(obj_current); @@ -1719,10 +1720,10 @@ _dedup_entry_assert_all(const NMDedupMultiEntry *entry, static void test_dedup_multi(void) { - NMDedupMultiIndex * idx; + NMDedupMultiIndex *idx; DedupIdxType IDX_20_3_a_stack; const DedupIdxType *const IDX_20_3_a = DEDUP_IDX_TYPE_INIT(&IDX_20_3_a_stack, 20, 3); - const NMDedupMultiEntry * entry1; + const NMDedupMultiEntry *entry1; idx = nm_dedup_multi_index_new(); @@ -1800,7 +1801,7 @@ static void test_setting_vpn_items(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingVpn * s_vpn; + NMSettingVpn *s_vpn; connection = nmtst_create_minimal_connection("vpn-items", NULL, NM_SETTING_VPN_SETTING_NAME, NULL); @@ -1919,17 +1920,17 @@ test_setting_vpn_items(void) static void test_setting_vpn_update_secrets(void) { - NMConnection * connection; - NMSettingVpn * s_vpn; + NMConnection *connection; + NMSettingVpn *s_vpn; GVariantBuilder settings_builder, vpn_builder, secrets_builder; - GVariant * settings; + GVariant *settings; gboolean success; - GError * error = NULL; - const char * tmp; - const char * key1 = "foobar"; - const char * key2 = "blahblah"; - const char * val1 = "value1"; - const char * val2 = "value2"; + GError *error = NULL; + const char *tmp; + const char *key1 = "foobar"; + const char *key2 = "blahblah"; + const char *val1 = "value1"; + const char *val2 = "value2"; connection = nm_simple_connection_new(); s_vpn = (NMSettingVpn *) nm_setting_vpn_new(); @@ -1970,7 +1971,7 @@ test_setting_vpn_update_secrets(void) #define TO_DEL_NUM 50 typedef struct { NMSettingVpn *s_vpn; - char * to_del[TO_DEL_NUM]; + char *to_del[TO_DEL_NUM]; guint called; } IterInfo; @@ -1998,7 +1999,7 @@ test_setting_vpn_modify_during_foreach(void) { NMSettingVpn *s_vpn; IterInfo info; - char * key, *val; + char *key, *val; int i, u = 0; s_vpn = (NMSettingVpn *) nm_setting_vpn_new(); @@ -2040,13 +2041,13 @@ static void test_setting_ip4_config_labels(void) { NMSettingIPConfig *s_ip4; - NMIPAddress * addr; - GVariant * label; - GPtrArray * addrs; - char ** labels; - NMConnection * conn; - GVariant * dict, *dict2, *setting_dict, *value; - GError * error = NULL; + NMIPAddress *addr; + GVariant *label; + GPtrArray *addrs; + char **labels; + NMConnection *conn; + GVariant *dict, *dict2, *setting_dict, *value; + GError *error = NULL; s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); g_object_set(G_OBJECT(s_ip4), @@ -2242,11 +2243,11 @@ static void test_setting_ip4_config_address_data(void) { NMSettingIPConfig *s_ip4; - NMIPAddress * addr; - GPtrArray * addrs; - NMConnection * conn; - GVariant * dict, *setting_dict, *value; - GError * error = NULL; + NMIPAddress *addr; + GPtrArray *addrs; + NMConnection *conn; + GVariant *dict, *setting_dict, *value; + GError *error = NULL; s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); g_object_set(G_OBJECT(s_ip4), @@ -2412,7 +2413,7 @@ static void test_setting_gsm_apn_spaces(void) { gs_unref_object NMSettingGsm *s_gsm = NULL; - const char * tmp; + const char *tmp; s_gsm = (NMSettingGsm *) nm_setting_gsm_new(); g_assert(s_gsm); @@ -2558,7 +2559,7 @@ static void test_setting_to_dbus_all(void) { NMSettingWirelessSecurity *s_wsec; - GVariant * dict; + GVariant *dict; s_wsec = make_test_wsec_setting("setting-to-dbus-all"); @@ -2578,7 +2579,7 @@ static void test_setting_to_dbus_no_secrets(void) { NMSettingWirelessSecurity *s_wsec; - GVariant * dict; + GVariant *dict; s_wsec = make_test_wsec_setting("setting-to-dbus-no-secrets"); @@ -2603,7 +2604,7 @@ static void test_setting_to_dbus_only_secrets(void) { NMSettingWirelessSecurity *s_wsec; - GVariant * dict; + GVariant *dict; s_wsec = make_test_wsec_setting("setting-to-dbus-only-secrets"); @@ -2625,9 +2626,9 @@ test_setting_to_dbus_only_secrets(void) static void test_setting_to_dbus_transform(void) { - NMSetting * s_wired; - GVariant * dict, *val; - const char * test_mac_address = "11:22:33:44:55:66"; + NMSetting *s_wired; + GVariant *dict, *val; + const char *test_mac_address = "11:22:33:44:55:66"; const guint8 *dbus_mac_address; guint8 cmp_mac_address[ETH_ALEN]; gsize len; @@ -2660,7 +2661,7 @@ static void test_setting_to_dbus_enum(void) { NMSetting *s_ip6, *s_wsec, *s_serial; - GVariant * dict, *val; + GVariant *dict, *val; /* enum */ s_ip6 = nm_setting_ip6_config_new(); @@ -2730,9 +2731,9 @@ test_setting_to_dbus_enum(void) static void test_connection_to_dbus_setting_name(void) { - NMConnection * connection; + NMConnection *connection; NMSettingWirelessSecurity *s_wsec; - GVariant * dict; + GVariant *dict; connection = nm_simple_connection_new(); s_wsec = make_test_wsec_setting("connection-to-dbus-setting-name"); @@ -2781,11 +2782,11 @@ test_connection_to_dbus_setting_name(void) static void test_connection_to_dbus_deprecated_props(void) { - NMConnection * connection; - NMSetting * s_wireless; - GBytes * ssid; + NMConnection *connection; + NMSetting *s_wireless; + GBytes *ssid; NMSettingWirelessSecurity *s_wsec; - GVariant * dict, *wireless_dict, *sec_val; + GVariant *dict, *wireless_dict, *sec_val; connection = nmtst_create_minimal_connection("test-connection-to-dbus-deprecated-props", NULL, @@ -2839,7 +2840,7 @@ static void test_setting_new_from_dbus(void) { NMSettingWirelessSecurity *s_wsec; - GVariant * dict; + GVariant *dict; s_wsec = make_test_wsec_setting("setting-new-from-dbus"); dict = _nm_setting_to_dbus(NM_SETTING(s_wsec), NULL, NM_CONNECTION_SERIALIZE_ALL, NULL); @@ -2863,12 +2864,12 @@ test_setting_new_from_dbus(void) static void test_setting_new_from_dbus_transform(void) { - NMSetting * s_wired; - GVariant * dict; + NMSetting *s_wired; + GVariant *dict; GVariantBuilder builder; - const char * test_mac_address = "11:22:33:44:55:66"; + const char *test_mac_address = "11:22:33:44:55:66"; guint8 dbus_mac_address[ETH_ALEN]; - GError * error = NULL; + GError *error = NULL; nm_utils_hwaddr_aton(test_mac_address, dbus_mac_address, ETH_ALEN); @@ -2898,12 +2899,12 @@ test_setting_new_from_dbus_transform(void) static void test_setting_new_from_dbus_enum(void) { - NMSettingIP6Config * s_ip6; + NMSettingIP6Config *s_ip6; NMSettingWirelessSecurity *s_wsec; - NMSettingSerial * s_serial; - GVariant * dict; + NMSettingSerial *s_serial; + GVariant *dict; GVariantBuilder builder; - GError * error = NULL; + GError *error = NULL; /* enum */ g_variant_builder_init(&builder, NM_VARIANT_TYPE_SETTING); @@ -2977,12 +2978,12 @@ test_setting_new_from_dbus_enum(void) static void test_setting_new_from_dbus_bad(void) { - NMSetting * setting; + NMSetting *setting; NMConnection *conn; - GBytes * ssid; - GPtrArray * addrs; - GVariant * orig_dict, *dict; - GError * error = NULL; + GBytes *ssid; + GPtrArray *addrs; + GVariant *orig_dict, *dict; + GError *error = NULL; /* We want to test: * - ordinary scalar properties @@ -3166,8 +3167,8 @@ static NMConnection * new_test_connection(void) { NMConnection *connection; - NMSetting * setting; - char * uuid; + NMSetting *setting; + char *uuid; guint64 timestamp = time(NULL); connection = nm_simple_connection_new(); @@ -3204,7 +3205,7 @@ new_test_connection(void) } static GVariant * -new_connection_dict(char ** out_uuid, +new_connection_dict(char **out_uuid, const char **out_expected_id, const char **out_expected_ip6_method) { @@ -3264,14 +3265,14 @@ new_connection_dict(char ** out_uuid, static void test_connection_replace_settings(void) { - NMConnection * connection; - GVariant * new_settings; - GError * error = NULL; + NMConnection *connection; + GVariant *new_settings; + GError *error = NULL; gboolean success; NMSettingConnection *s_con; - NMSettingIPConfig * s_ip6; - char * uuid = NULL; - const char * expected_id = NULL, *expected_method = NULL; + NMSettingIPConfig *s_ip6; + char *uuid = NULL; + const char *expected_id = NULL, *expected_method = NULL; connection = new_test_connection(); @@ -3303,12 +3304,12 @@ test_connection_replace_settings(void) static void test_connection_replace_settings_from_connection(void) { - NMConnection * connection, *replacement; + NMConnection *connection, *replacement; NMSettingConnection *s_con; - NMSetting * setting; - GBytes * ssid; - char * uuid = NULL; - const char * expected_id = "Awesome connection"; + NMSetting *setting; + GBytes *ssid; + char *uuid = NULL; + const char *expected_id = "Awesome connection"; connection = new_test_connection(); g_assert(connection); @@ -3365,10 +3366,10 @@ test_connection_replace_settings_from_connection(void) static void test_connection_replace_settings_bad(void) { - NMConnection * connection, *new_connection; - GVariant * new_settings; + NMConnection *connection, *new_connection; + GVariant *new_settings; GVariantBuilder builder, setting_builder; - GError * error = NULL; + GError *error = NULL; gboolean success; NMSettingConnection *s_con; @@ -3426,13 +3427,13 @@ test_connection_replace_settings_bad(void) static void test_connection_new_from_dbus(void) { - NMConnection * connection; - GVariant * new_settings; - GError * error = NULL; + NMConnection *connection; + GVariant *new_settings; + GError *error = NULL; NMSettingConnection *s_con; - NMSettingIPConfig * s_ip6; - char * uuid = NULL; - const char * expected_id = NULL, *expected_method = NULL; + NMSettingIPConfig *s_ip6; + char *uuid = NULL; + const char *expected_id = NULL, *expected_method = NULL; new_settings = new_connection_dict(&uuid, &expected_id, &expected_method); g_assert(new_settings); @@ -3484,8 +3485,8 @@ test_setting_connection_permissions_helpers(void) NMSettingConnection *s_con; gboolean success; char buf[9] = {0x61, 0x62, 0x63, 0xff, 0xfe, 0xfd, 0x23, 0x01, 0x00}; - char ** perms; - const char * expected_perm = "user:" TEST_UNAME ":"; + char **perms; + const char *expected_perm = "user:" TEST_UNAME ":"; s_con = NM_SETTING_CONNECTION(nm_setting_connection_new()); @@ -3552,13 +3553,13 @@ test_setting_connection_permissions_helpers(void) static void add_permission_property(NMSettingConnection *s_con, - const char * ptype, - const char * pitem, + const char *ptype, + const char *pitem, int pitem_len, - const char * detail) + const char *detail) { GString *str; - char * perms[2]; + char *perms[2]; str = g_string_sized_new(50); if (ptype) @@ -3598,12 +3599,12 @@ test_setting_connection_permissions_property(void) { \ NMSettingConnection *_s_con = (s_con); \ guint _idx = (idx); \ - const char * _ptype; \ - const char * _pitem; \ - const char * _detail; \ - const char ** _p_ptype = nmtst_get_rand_bool() ? &_ptype : NULL; \ - const char ** _p_pitem = nmtst_get_rand_bool() ? &_pitem : NULL; \ - const char ** _p_detail = nmtst_get_rand_bool() ? &_detail : NULL; \ + const char *_ptype; \ + const char *_pitem; \ + const char *_detail; \ + const char **_p_ptype = nmtst_get_rand_bool() ? &_ptype : NULL; \ + const char **_p_pitem = nmtst_get_rand_bool() ? &_pitem : NULL; \ + const char **_p_detail = nmtst_get_rand_bool() ? &_detail : NULL; \ \ g_assert_cmpint(_idx, <, nm_setting_connection_get_num_permissions(_s_con)); \ g_assert( \ @@ -3690,7 +3691,7 @@ test_connection_compare_same(void) static void test_connection_compare_key_only_in_a(void) { - NMConnection * a, *b; + NMConnection *a, *b; NMSettingConnection *s_con; a = new_test_connection(); @@ -3720,7 +3721,7 @@ test_connection_compare_setting_only_in_a(void) static void test_connection_compare_key_only_in_b(void) { - NMConnection * a, *b; + NMConnection *a, *b; NMSettingConnection *s_con; a = new_test_connection(); @@ -3792,8 +3793,8 @@ ensure_diffs(GHashTable *diffs, const DiffSetting *check, gsize n_check) static void test_connection_diff_a_only(void) { - NMConnection * connection; - GHashTable * out_diffs = NULL; + NMConnection *connection; + GHashTable *out_diffs = NULL; gboolean same; const DiffSetting settings[] = { {NM_SETTING_CONNECTION_SETTING_NAME, @@ -3892,7 +3893,7 @@ static void test_connection_diff_same(void) { NMConnection *a, *b; - GHashTable * out_diffs = NULL; + GHashTable *out_diffs = NULL; gboolean same; a = new_test_connection(); @@ -3908,8 +3909,8 @@ test_connection_diff_same(void) static void test_connection_diff_different(void) { - NMConnection * a, *b; - GHashTable * out_diffs = NULL; + NMConnection *a, *b; + GHashTable *out_diffs = NULL; NMSettingIPConfig *s_ip4; gboolean same; const DiffSetting settings[] = { @@ -3945,9 +3946,9 @@ test_connection_diff_different(void) static void test_connection_diff_no_secrets(void) { - NMConnection * a, *b; - GHashTable * out_diffs = NULL; - NMSetting * s_pppoe; + NMConnection *a, *b; + GHashTable *out_diffs = NULL; + NMSetting *s_pppoe; gboolean same; const DiffSetting settings[] = { {NM_SETTING_PPPOE_SETTING_NAME, @@ -3990,13 +3991,13 @@ test_connection_diff_no_secrets(void) static void test_connection_diff_inferrable(void) { - NMConnection * a, *b; - GHashTable * out_diffs = NULL; + NMConnection *a, *b; + GHashTable *out_diffs = NULL; gboolean same; NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - char * uuid; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + char *uuid; const DiffSetting settings[] = { {NM_SETTING_CONNECTION_SETTING_NAME, { @@ -4053,7 +4054,7 @@ static void add_generic_settings(NMConnection *connection, const char *ctype) { NMSetting *setting; - char * uuid; + char *uuid; uuid = nm_utils_uuid_generate(); @@ -4083,11 +4084,11 @@ static void test_connection_good_base_types(void) { NMConnection *connection; - NMSetting * setting; + NMSetting *setting; gboolean success; - GError * error = NULL; - GBytes * ssid; - const char * bdaddr = "11:22:33:44:55:66"; + GError *error = NULL; + GBytes *ssid; + const char *bdaddr = "11:22:33:44:55:66"; /* Try a basic wired connection */ connection = nm_simple_connection_new(); @@ -4193,9 +4194,9 @@ static void test_connection_bad_base_types(void) { NMConnection *connection; - NMSetting * setting; + NMSetting *setting; gboolean success; - GError * error = NULL; + GError *error = NULL; /* Test various non-base connection types to make sure they are rejected; * using a fake 'wired' connection so the rest of it verifies @@ -4303,8 +4304,8 @@ test_setting_compare_addresses(void) { gs_unref_object NMSetting *s1 = NULL, *s2 = NULL; gboolean success; - NMIPAddress * a; - GHashTable * result = NULL; + NMIPAddress *a; + GHashTable *result = NULL; s1 = nm_setting_ip4_config_new(); s2 = nm_setting_ip4_config_new(); @@ -4335,8 +4336,8 @@ test_setting_compare_routes(void) { gs_unref_object NMSetting *s1 = NULL, *s2 = NULL; gboolean success; - NMIPRoute * r; - GHashTable * result = NULL; + NMIPRoute *r; + GHashTable *result = NULL; s1 = nm_setting_ip4_config_new(); s2 = nm_setting_ip4_config_new(); @@ -4367,7 +4368,7 @@ test_setting_compare_wired_cloned_mac_address(void) { gs_unref_object NMSetting *old = NULL, *new = NULL; gboolean success; - gs_free char * str1 = NULL; + gs_free char *str1 = NULL; old = nm_setting_wired_new(); g_object_set(old, NM_SETTING_WIRED_CLONED_MAC_ADDRESS, "stable", NULL); @@ -4411,7 +4412,7 @@ test_setting_compare_wireless_cloned_mac_address(void) { gs_unref_object NMSetting *old = NULL, *new = NULL; gboolean success; - gs_free char * str1 = NULL; + gs_free char *str1 = NULL; old = nm_setting_wireless_new(); g_object_set(old, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, "stable", NULL); @@ -4501,8 +4502,8 @@ test_data_compare_secrets_new(NMSettingSecretFlags secret_flags, } static void -_test_compare_secrets_check_diff(NMSetting * a, - NMSetting * b, +_test_compare_secrets_check_diff(NMSetting *a, + NMSetting *b, NMSettingCompareFlags flags, gboolean exp_same_psk, gboolean exp_same_psk_flags) @@ -4617,11 +4618,11 @@ _test_compare_secrets_check_diff(NMSetting * a, static void test_setting_compare_secrets(gconstpointer test_data) { - const TestDataCompareSecrets *data = test_data; - gs_unref_object NMConnection *conn_old = NULL; - gs_unref_object NMConnection *conn_new = NULL; - gs_unref_object NMSetting *old = NULL; - gs_unref_object NMSetting *new = NULL; + const TestDataCompareSecrets *data = test_data; + gs_unref_object NMConnection *conn_old = NULL; + gs_unref_object NMConnection *conn_new = NULL; + gs_unref_object NMSetting *old = NULL; + gs_unref_object NMSetting *new = NULL; /* Make sure that a connection with transient/unsaved secrets compares * successfully to the same connection without those secrets. @@ -4700,8 +4701,8 @@ static void test_setting_compare_vpn_secrets(gconstpointer test_data) { const TestDataCompareSecrets *data = test_data; - gs_unref_object NMSetting *old = NULL, *new = NULL; - gboolean success; + gs_unref_object NMSetting *old = NULL, *new = NULL; + gboolean success; /* Make sure that a connection with transient/unsaved secrets compares * successfully to the same connection without those secrets. @@ -4773,15 +4774,15 @@ test_hwaddr_aton_malformed(void) static void test_hwaddr_equal(void) { - const char * string = "00:1a:2b:03:44:05"; - const char * upper_string = "00:1A:2B:03:44:05"; - const char * bad_string = "0:1a:2b:3:44:5"; + const char *string = "00:1a:2b:03:44:05"; + const char *upper_string = "00:1A:2B:03:44:05"; + const char *bad_string = "0:1a:2b:3:44:5"; const guint8 binary[ETH_ALEN] = {0x00, 0x1A, 0x2B, 0x03, 0x44, 0x05}; - const char * other_string = "1a:2b:03:44:05:00"; + const char *other_string = "1a:2b:03:44:05:00"; const guint8 other_binary[ETH_ALEN] = {0x1A, 0x2B, 0x03, 0x44, 0x05, 0x00}; - const char * long_string = "00:1a:2b:03:44:05:06:07"; + const char *long_string = "00:1a:2b:03:44:05:06:07"; const guint8 long_binary[8] = {0x00, 0x1A, 0x2B, 0x03, 0x44, 0x05, 0x06, 0x07}; - const char * null_string = "00:00:00:00:00:00"; + const char *null_string = "00:00:00:00:00:00"; const guint8 null_binary[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; g_assert(nm_utils_hwaddr_matches(string, -1, string, -1)); @@ -4860,7 +4861,7 @@ test_hwaddr_canonical(void) const char *short_string = "0:1a:2b:3:44:5"; const char *hyphen_string = "00-1a-2b-03-44-05"; const char *invalid_string = "00:1A:2B"; - char * canonical; + char *canonical; canonical = nm_utils_hwaddr_canonical(string, ETH_ALEN); g_assert_cmpstr(canonical, ==, string); @@ -5032,10 +5033,10 @@ test_connection_changed_signal(void) static void test_setting_connection_changed_signal(void) { - NMConnection * connection; + NMConnection *connection; gboolean changed = FALSE; NMSettingConnection *s_con; - gs_free char * uuid = NULL; + gs_free char *uuid = NULL; connection = nm_simple_connection_new(); g_signal_connect(connection, @@ -5069,7 +5070,7 @@ test_setting_connection_changed_signal(void) static void test_setting_bond_changed_signal(void) { - NMConnection * connection; + NMConnection *connection; gboolean changed = FALSE; NMSettingBond *s_bond; @@ -5092,12 +5093,12 @@ test_setting_bond_changed_signal(void) static void test_setting_ip4_changed_signal(void) { - NMConnection * connection; + NMConnection *connection; gboolean changed = FALSE; NMSettingIPConfig *s_ip4; - NMIPAddress * addr; - NMIPRoute * route; - GError * error = NULL; + NMIPAddress *addr; + NMIPRoute *route; + GError *error = NULL; connection = nm_simple_connection_new(); g_signal_connect(connection, @@ -5168,12 +5169,12 @@ test_setting_ip4_changed_signal(void) static void test_setting_ip6_changed_signal(void) { - NMConnection * connection; + NMConnection *connection; gboolean changed = FALSE; NMSettingIPConfig *s_ip6; - NMIPAddress * addr; - NMIPRoute * route; - GError * error = NULL; + NMIPAddress *addr; + NMIPRoute *route; + GError *error = NULL; connection = nm_simple_connection_new(); g_signal_connect(connection, @@ -5238,7 +5239,7 @@ test_setting_ip6_changed_signal(void) static void test_setting_vlan_changed_signal(void) { - NMConnection * connection; + NMConnection *connection; gboolean changed = FALSE; NMSettingVlan *s_vlan; @@ -5300,7 +5301,7 @@ test_setting_vpn_changed_signal(void) static void test_setting_wired_changed_signal(void) { - NMConnection * connection; + NMConnection *connection; gboolean changed = FALSE; NMSettingWired *s_wired; @@ -5323,7 +5324,7 @@ test_setting_wired_changed_signal(void) static void test_setting_wireless_changed_signal(void) { - NMConnection * connection; + NMConnection *connection; gboolean changed = FALSE; NMSettingWireless *s_wifi; @@ -5344,7 +5345,7 @@ test_setting_wireless_changed_signal(void) static void test_setting_wireless_security_changed_signal(void) { - NMConnection * connection; + NMConnection *connection; gboolean changed = FALSE; NMSettingWirelessSecurity *s_wsec; @@ -5411,7 +5412,7 @@ test_setting_wireless_security_changed_signal(void) static void test_setting_802_1x_changed_signal(void) { - NMConnection * connection; + NMConnection *connection; gboolean changed = FALSE; NMSetting8021x *s_8021x; @@ -5505,13 +5506,13 @@ test_connection_normalize_uuid(void) static void test_connection_normalize_virtual_iface_name(void) { - NMConnection * con = NULL; + NMConnection *con = NULL; NMSettingConnection *s_con; - NMSettingVlan * s_vlan; - GVariant * connection_dict, *setting_dict, *var; - GError * error = NULL; - const char * IFACE_NAME = "iface"; - const char * IFACE_VIRT = "iface-X"; + NMSettingVlan *s_vlan; + GVariant *connection_dict, *setting_dict, *var; + GError *error = NULL; + const char *IFACE_NAME = "iface"; + const char *IFACE_VIRT = "iface-X"; con = nmtst_create_minimal_connection("test1", "22001632-bbb4-4616-b277-363dce3dfb5b", @@ -5605,11 +5606,11 @@ _test_connection_normalize_type_normalizable_setting( const char *type, void (*prepare_normalizable_fcn)(NMConnection *con)) { - NMSettingConnection *s_con; - NMSetting * s_base; - GType base_type; + NMSettingConnection *s_con; + NMSetting *s_base; + GType base_type; gs_unref_object NMConnection *con = NULL; - gs_free char * id = g_strdup_printf("%s[%s]", G_STRFUNC, type); + gs_free char *id = g_strdup_printf("%s[%s]", G_STRFUNC, type); base_type = nm_setting_lookup_type(type); g_assert(base_type != G_TYPE_INVALID); @@ -5640,10 +5641,10 @@ _test_connection_normalize_type_normalizable_setting( static void _test_connection_normalize_type_unnormalizable_setting(const char *type) { - NMSettingConnection *s_con; - GType base_type; + NMSettingConnection *s_con; + GType base_type; gs_unref_object NMConnection *con = NULL; - gs_free char * id = g_strdup_printf("%s[%s]", G_STRFUNC, type); + gs_free char *id = g_strdup_printf("%s[%s]", G_STRFUNC, type); base_type = nm_setting_lookup_type(type); g_assert(base_type != G_TYPE_INVALID); @@ -5666,11 +5667,11 @@ static void _test_connection_normalize_type_normalizable_type(const char *type, NMSetting *(*add_setting_fcn)(NMConnection *con)) { - NMSettingConnection *s_con; - NMSetting * s_base; - GType base_type; + NMSettingConnection *s_con; + NMSetting *s_base; + GType base_type; gs_unref_object NMConnection *con = NULL; - gs_free char * id = g_strdup_printf("%s[%s]", G_STRFUNC, type); + gs_free char *id = g_strdup_printf("%s[%s]", G_STRFUNC, type); base_type = nm_setting_lookup_type(type); g_assert(base_type != G_TYPE_INVALID); @@ -5738,7 +5739,7 @@ _add_setting_fcn_bluetooth(NMConnection *con) static NMSetting * _add_setting_fcn_bond(NMConnection *con) { - NMSetting * setting; + NMSetting *setting; NMSettingConnection *s_con; setting = g_object_new(NM_TYPE_SETTING_BOND, NULL); @@ -5755,7 +5756,7 @@ _add_setting_fcn_bond(NMConnection *con) static NMSetting * _add_setting_fcn_bridge(NMConnection *con) { - NMSetting * setting; + NMSetting *setting; NMSettingConnection *s_con; setting = g_object_new(NM_TYPE_SETTING_BRIDGE, NULL); @@ -5797,9 +5798,9 @@ _add_setting_fcn_infiniband(NMConnection *con) static NMSetting * _add_setting_fcn_olpc_mesh(NMConnection *con) { - NMSetting * setting; + NMSetting *setting; const char *ssid_data = "ssid-test"; - GBytes * ssid; + GBytes *ssid; ssid = g_bytes_new(ssid_data, strlen(ssid_data)); setting = g_object_new(NM_TYPE_SETTING_OLPC_MESH, @@ -5817,7 +5818,7 @@ _add_setting_fcn_olpc_mesh(NMConnection *con) static NMSetting * _add_setting_fcn_team(NMConnection *con) { - NMSetting * setting; + NMSetting *setting; NMSettingConnection *s_con; setting = g_object_new(NM_TYPE_SETTING_TEAM, NULL); @@ -5871,9 +5872,9 @@ _add_setting_fcn_wimax(NMConnection *con) static NMSetting * _add_setting_fcn_wireless(NMConnection *con) { - NMSetting * setting; + NMSetting *setting; const char *ssid_data = "ssid-test"; - GBytes * ssid; + GBytes *ssid; ssid = g_bytes_new(ssid_data, strlen(ssid_data)); setting = g_object_new(NM_TYPE_SETTING_WIRELESS, NM_SETTING_WIRELESS_SSID, ssid, NULL); @@ -5939,7 +5940,7 @@ static void test_connection_normalize_slave_type_1(void) { gs_unref_object NMConnection *con = NULL; - NMSettingConnection * s_con; + NMSettingConnection *s_con; con = nmtst_create_minimal_connection("test_connection_normalize_slave_type_1", "cc4cd5df-45dc-483e-b291-6b76c2338ecb", @@ -5975,7 +5976,7 @@ static void test_connection_normalize_slave_type_2(void) { gs_unref_object NMConnection *con = NULL; - NMSettingConnection * s_con; + NMSettingConnection *s_con; con = nmtst_create_minimal_connection("test_connection_normalize_slave_type_2", "40bea008-ca72-439a-946b-e65f827656f9", @@ -6013,7 +6014,7 @@ static void test_connection_normalize_infiniband_mtu(void) { gs_unref_object NMConnection *con = NULL; - NMSettingInfiniband * s_infini; + NMSettingInfiniband *s_infini; guint mtu_regular = nmtst_rand_select(2044, 2045, 65520); con = nmtst_create_minimal_connection("test_connection_normalize_infiniband_mtu", @@ -6073,9 +6074,9 @@ static void test_connection_normalize_gateway_never_default(void) { gs_unref_object NMConnection *con = NULL; - NMSettingIPConfig * s_ip4, *s_ip6; - NMIPAddress * addr; - gs_free_error GError *error = NULL; + NMSettingIPConfig *s_ip4, *s_ip6; + NMIPAddress *addr; + gs_free_error GError *error = NULL; con = nmtst_create_minimal_connection("test1", NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); nmtst_assert_connection_verifies_and_normalizable(con); @@ -6124,7 +6125,7 @@ static void test_connection_normalize_may_fail(void) { gs_unref_object NMConnection *con = NULL; - NMSettingIPConfig * s_ip4, *s_ip6; + NMSettingIPConfig *s_ip4, *s_ip6; con = nmtst_create_minimal_connection("test2", NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); nmtst_assert_connection_verifies_and_normalizable(con); @@ -6166,9 +6167,9 @@ static void test_connection_normalize_shared_addresses(void) { gs_unref_object NMConnection *con = NULL; - NMSettingIPConfig * s_ip4, *s_ip6; - NMIPAddress * addr; - gs_free_error GError *error = NULL; + NMSettingIPConfig *s_ip4, *s_ip6; + NMIPAddress *addr; + gs_free_error GError *error = NULL; con = nmtst_create_minimal_connection("test1", NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); nmtst_assert_connection_verifies_and_normalizable(con); @@ -6217,10 +6218,10 @@ test_connection_normalize_shared_addresses(void) static void test_connection_normalize_ovs_interface_type_system(gconstpointer test_data) { - const guint TEST_CASE = GPOINTER_TO_UINT(test_data); - gs_unref_object NMConnection *con = NULL; - NMSettingConnection * s_con; - NMSettingOvsInterface * s_ovs_if; + const guint TEST_CASE = GPOINTER_TO_UINT(test_data); + gs_unref_object NMConnection *con = NULL; + NMSettingConnection *s_con; + NMSettingOvsInterface *s_ovs_if; con = nmtst_create_minimal_connection("test_connection_normalize_ovs_interface_type_system", NULL, @@ -6370,13 +6371,13 @@ test_connection_normalize_ovs_interface_type_system(gconstpointer test_data) static void test_connection_normalize_ovs_interface_type_ovs_interface(gconstpointer test_data) { - const guint TEST_CASE = GPOINTER_TO_UINT(test_data); - gs_unref_object NMConnection *con = NULL; - NMSettingConnection * s_con; - NMSettingOvsInterface * s_ovs_if; - NMSettingOvsPatch * s_ovs_patch; - NMSettingIP4Config * s_ip4; - NMSettingIP6Config * s_ip6; + const guint TEST_CASE = GPOINTER_TO_UINT(test_data); + gs_unref_object NMConnection *con = NULL; + NMSettingConnection *s_con; + NMSettingOvsInterface *s_ovs_if; + NMSettingOvsPatch *s_ovs_patch; + NMSettingIP4Config *s_ip4; + NMSettingIP6Config *s_ip6; con = nmtst_create_minimal_connection( "test_connection_normalize_ovs_interface_type_ovs_interface", @@ -6602,16 +6603,16 @@ test_connection_normalize_ovs_interface_type_ovs_interface(gconstpointer test_da static void test_setting_ip4_gateway(void) { - NMConnection * conn; + NMConnection *conn; NMSettingIPConfig *s_ip4; - NMIPAddress * addr; - GVariant * conn_dict, *ip4_dict, *value; + NMIPAddress *addr; + GVariant *conn_dict, *ip4_dict, *value; GVariantIter iter; - GVariant * addr_var; + GVariant *addr_var; guint32 addr_vals_0[] = {htonl(0xc0a8010a), 0x00000018, htonl(0x00000000)}; guint32 addr_vals_1[] = {htonl(0xc0a8010b), 0x00000018, htonl(0xc0a80101)}; GVariantBuilder addrs_builder; - GError * error = NULL; + GError *error = NULL; nmtst_assert_ip4_address(addr_vals_0[0], "192.168.1.10"); @@ -6713,12 +6714,12 @@ test_setting_ip4_gateway(void) static void test_setting_ip6_gateway(void) { - NMConnection * conn; + NMConnection *conn; NMSettingIPConfig *s_ip6; - NMIPAddress * addr; - GVariant * conn_dict, *ip6_dict, *value; + NMIPAddress *addr; + GVariant *conn_dict, *ip6_dict, *value; GVariantIter iter; - GVariant * gateway_var; + GVariant *gateway_var; GVariantBuilder addrs_builder; guint8 addr_bytes_0[] = {0xab, 0xcd, @@ -6768,7 +6769,7 @@ test_setting_ip6_gateway(void) 0x00, 0x00, 0x01}; - GError * error = NULL; + GError *error = NULL; /* When serializing on the daemon side, ipv6.gateway is copied to the first * entry of ipv6.addresses @@ -6872,7 +6873,7 @@ test_setting_ip6_gateway(void) } typedef struct { - const char * str; + const char *str; const guint8 expected[20]; const guint expected_len; } HexItem; @@ -6881,10 +6882,10 @@ static void test_setting_compare_default_strv(void) { gs_unref_object NMConnection *c1 = NULL, *c2 = NULL; - char ** strv; - NMSettingIPConfig * s_ip2, *s_ip1; + char **strv; + NMSettingIPConfig *s_ip2, *s_ip1; gboolean compare; - GHashTable * out_settings = NULL; + GHashTable *out_settings = NULL; c1 = nmtst_create_minimal_connection("test_compare_default_strv", NULL, @@ -6951,8 +6952,8 @@ static void _sock_addr_endpoint(const char *endpoint, const char *host, gint32 port) { nm_auto_unref_sockaddrendpoint NMSockAddrEndpoint *ep = NULL; - const char * s_endpoint; - const char * s_host; + const char *s_endpoint; + const char *s_host; gint32 s_port; SockAddrUnion sockaddr = {}; @@ -6993,8 +6994,8 @@ static void _sock_addr_endpoint_fixed(const char *endpoint, const char *host, guint16 port, guint scope_id) { nm_auto_unref_sockaddrendpoint NMSockAddrEndpoint *ep = NULL; - const char * s_endpoint; - const char * s_host; + const char *s_endpoint; + const char *s_host; gint32 s_port; int addr_family; NMIPAddr addrbin; @@ -7130,8 +7131,8 @@ _do_strquote(const char *str, gsize buf_len, const char *expected) { char canary = (char) nmtst_get_rand_uint32(); gs_free char *buf_full = g_malloc(buf_len + 2); - char * buf = &buf_full[1]; - const char * b; + char *buf = &buf_full[1]; + const char *b; buf[-1] = canary; buf[buf_len] = canary; @@ -7932,8 +7933,8 @@ test_nm_utils_ascii_str_to_int64_do(const char *str, int exp_errno, gint64 exp_val) { - const char * sign = ""; - const char * val; + const char *sign = ""; + const char *val; static const char *whitespaces[] = { "", " ", @@ -7972,7 +7973,7 @@ test_nm_utils_ascii_str_to_int64_do(const char *str, for (ws_post = whitespaces; *ws_post; ws_post++) { for (null = nulls; *null; null++) { for (i = 0;; i++) { - char * s; + char *s; const char *str_base = ""; if (base == 16) { @@ -8145,8 +8146,8 @@ test_nm_utils_strstrdictkey(void) .v1 = _v1, .v2 = _v2, .v_static = _nm_utils_strstrdictkey_static(_v1, _v2), \ } const struct { - const char * v1; - const char * v2; + const char *v1; + const char *v2; NMUtilsStrStrDictKey *v_static; } * val1, *val2, values[] = { @@ -8210,11 +8211,11 @@ test_nm_ptrarray_len(void) #define _PTRARRAY_LEN0(T) \ G_STMT_START \ { \ - T ** vnull = NULL; \ - T *const * vnull1 = NULL; \ + T **vnull = NULL; \ + T *const *vnull1 = NULL; \ T *const *const vnull2 = NULL; \ - T * v0[] = {NULL}; \ - T *const * v01 = v0; \ + T *v0[] = {NULL}; \ + T *const *v01 = v0; \ T *const *const v02 = v0; \ T **const v03 = v0; \ \ @@ -8241,13 +8242,13 @@ test_nm_ptrarray_len(void) { \ T x[5] = {0}; \ \ - T * v1[] = {&x[0], NULL}; \ - T *const * v11 = v1; \ + T *v1[] = {&x[0], NULL}; \ + T *const *v11 = v1; \ T *const *const v12 = v1; \ T **const v13 = v1; \ \ - T * v2[] = {&x[0], &x[1], NULL}; \ - T *const * v21 = v2; \ + T *v2[] = {&x[0], &x[1], NULL}; \ + T *const *v21 = v2; \ T *const *const v22 = v2; \ T **const v23 = v2; \ \ @@ -8273,14 +8274,14 @@ test_nm_ptrarray_len(void) /*****************************************************************************/ static void -test_nm_utils_dns_option_validate_do(char * option, +test_nm_utils_dns_option_validate_do(char *option, gboolean ipv6, const NMUtilsDNSOptionDesc *descs, gboolean exp_result, - char * exp_name, + char *exp_name, gboolean exp_value) { - char * name; + char *name; long value = 0; gboolean result; @@ -8556,7 +8557,7 @@ test_nm_utils_is_power_of_two(void) { guint64 xyes, xno; int i, j; - GRand * rand = nmtst_get_rand(); + GRand *rand = nmtst_get_rand(); int numbits; g_assert(!nm_utils_is_power_of_two(0)); @@ -8636,8 +8637,8 @@ _test_find_binary_search_cmp(gconstpointer a, gconstpointer b, gpointer dummy) static void _test_find_binary_search_do(const int *array, gsize len) { - gsize i; - gssize idx, idx2, idx_first, idx_last; + gsize i; + gssize idx, idx2, idx_first, idx_last; gs_free gconstpointer *parray = g_new(gconstpointer, len); const int NEEDLE = 0; gconstpointer pneedle = GINT_TO_POINTER(NEEDLE); @@ -8884,7 +8885,7 @@ test_nm_utils_ptrarray_find_binary_search_with_duplicates(void) static void _test_nm_utils_enum_to_str_do_full(GType type, int flags, - const char * exp_str, + const char *exp_str, const NMUtilsEnumValueInfo *value_infos) { gs_free char *str = NULL; @@ -8914,10 +8915,10 @@ _test_nm_utils_enum_to_str_do_full(GType type, static void _test_nm_utils_enum_from_str_do_full(GType type, - const char * str, + const char *str, gboolean exp_result, int exp_flags, - const char * exp_err_token, + const char *exp_err_token, const NMUtilsEnumValueInfo *value_infos) { int flags; @@ -8962,7 +8963,7 @@ static void _test_nm_utils_enum_get_values_do(GType type, int from, int to, const char *exp_str) { gs_free const char **strv = NULL; - gs_free char * str = NULL; + gs_free char *str = NULL; g_assert(exp_str); @@ -9132,9 +9133,9 @@ static void _do_test_utils_str_utf8safe_unescape(const char *str, const char *expected, gsize expected_len) { gsize l; - const char * s; + const char *s; gs_free gpointer buf_free_1 = NULL; - gs_free char * str_free_1 = NULL; + gs_free char *str_free_1 = NULL; s = nm_utils_buf_utf8safe_unescape(str, NM_UTILS_STR_UTF8_SAFE_FLAG_NONE, &l, &buf_free_1); g_assert_cmpint(expected_len, ==, l); @@ -9174,14 +9175,14 @@ _do_test_utils_str_utf8safe_unescape(const char *str, const char *expected, gsiz _do_test_utils_str_utf8safe_unescape("" str "", expected, NM_STRLEN(expected)) static void -_do_test_utils_str_utf8safe(const char * str, +_do_test_utils_str_utf8safe(const char *str, gsize str_len, - const char * expected, + const char *expected, NMUtilsStrUtf8SafeFlags flags) { - const char * str_safe; - const char * buf_safe; - const char * s; + const char *str_safe; + const char *buf_safe; + const char *s; gs_free char *str_free_1 = NULL; gs_free char *str_free_2 = NULL; gs_free char *str_free_3 = NULL; @@ -9623,8 +9624,8 @@ static void test_route_attributes_parse(void) { GHashTable *ht; - GError * error = NULL; - GVariant * variant; + GError *error = NULL; + GVariant *variant; ht = nm_utils_parse_variant_attributes("mtu=1400 src=1.2.3.4 cwnd=14", ' ', @@ -9689,7 +9690,7 @@ static void test_route_attributes_format(void) { gs_unref_hashtable GHashTable *ht = NULL; - char * str; + char *str; ht = g_hash_table_new_full(nm_str_hash, g_str_equal, NULL, (GDestroyNotify) g_variant_unref); @@ -9918,9 +9919,9 @@ test_ethtool_offload(void) /*****************************************************************************/ typedef struct { - GMainLoop * loop1; + GMainLoop *loop1; GMainContext *c2; - GSource * extra_sources[2]; + GSource *extra_sources[2]; bool got_signal[5]; int fd_2; } IntegData; @@ -9971,7 +9972,7 @@ static gboolean _test_integrate_cb_idle_2(gpointer user_data) { IntegData *d = user_data; - GSource * extra_source; + GSource *extra_source; g_assert(d->got_signal[1]); g_assert(d->got_signal[2]); @@ -9995,7 +9996,7 @@ static gboolean _test_integrate_cb_idle_1(gpointer user_data) { IntegData *d = user_data; - GSource * extra_source; + GSource *extra_source; g_assert(d->got_signal[2]); g_assert(!d->extra_sources[0]); @@ -10032,9 +10033,9 @@ _test_integrate_maincontext_cb_idle1(gpointer user_data) static void test_integrate_maincontext(gconstpointer test_data) { - const guint TEST_IDX = GPOINTER_TO_UINT(test_data); - GMainContext * c1 = g_main_context_default(); - nm_auto_unref_gmaincontext GMainContext *c2 = g_main_context_new(); + const guint TEST_IDX = GPOINTER_TO_UINT(test_data); + GMainContext *c1 = g_main_context_default(); + nm_auto_unref_gmaincontext GMainContext *c2 = g_main_context_new(); nm_auto_destroy_and_unref_gsource GSource *integ_source = NULL; integ_source = nm_utils_g_main_context_create_integrate_source(c2); @@ -10056,11 +10057,11 @@ test_integrate_maincontext(gconstpointer test_data) nm_auto_destroy_and_unref_gsource GSource *timeout_source_1 = NULL; nm_auto_destroy_and_unref_gsource GSource *idle_source_1 = NULL; nm_auto_destroy_and_unref_gsource GSource *fd_source_1 = NULL; - nm_auto_unref_gmainloop GMainLoop *loop1 = NULL; - nm_auto_close int fd_1 = -1; - nm_auto_close int fd_2 = -1; - IntegData d; - int i; + nm_auto_unref_gmainloop GMainLoop *loop1 = NULL; + nm_auto_close int fd_1 = -1; + nm_auto_close int fd_2 = -1; + IntegData d; + int i; main_timeout_source = g_timeout_source_new(3000); g_source_set_callback(main_timeout_source, nmtst_g_source_assert_not_called, NULL, NULL); @@ -10134,14 +10135,14 @@ test_nm_ip_addr_zero(void) static void test_connection_ovs_ifname(gconstpointer test_data) { - const guint TEST_CASE = GPOINTER_TO_UINT(test_data); + const guint TEST_CASE = GPOINTER_TO_UINT(test_data); gs_unref_object NMConnection *con = NULL; - NMSettingConnection * s_con = NULL; - NMSettingOvsBridge * s_ovs_bridge = NULL; - NMSettingOvsPort * s_ovs_port = NULL; - NMSettingOvsInterface * s_ovs_iface = NULL; - NMSettingOvsPatch * s_ovs_patch = NULL; - const char * ovs_iface_type = NULL; + NMSettingConnection *s_con = NULL; + NMSettingOvsBridge *s_ovs_bridge = NULL; + NMSettingOvsPort *s_ovs_port = NULL; + NMSettingOvsInterface *s_ovs_iface = NULL; + NMSettingOvsPatch *s_ovs_patch = NULL; + const char *ovs_iface_type = NULL; switch (TEST_CASE) { case 1: @@ -10345,10 +10346,10 @@ static char * _strsplit_quoted_join_strv_rand(const char *const *strv) { NMStrBuf strbuf = NM_STR_BUF_INIT(nmtst_get_rand_uint32() % 200, nmtst_get_rand_bool()); - char * result; + char *result; gsize l; gsize l2; - gsize * p_l2 = nmtst_get_rand_bool() ? &l2 : NULL; + gsize *p_l2 = nmtst_get_rand_bool() ? &l2 : NULL; gsize i; g_assert(strv); @@ -10419,14 +10420,14 @@ next_maybe_quote: } static void -_strsplit_quoted_assert_strv(const char * topic, - const char * str, +_strsplit_quoted_assert_strv(const char *topic, + const char *str, const char *const *strv1, const char *const *strv2) { nm_auto_str_buf NMStrBuf s1 = {}; nm_auto_str_buf NMStrBuf s2 = {}; - gs_free char * str_escaped = NULL; + gs_free char *str_escaped = NULL; int i; g_assert(str); @@ -10504,7 +10505,7 @@ test_strsplit_quoted(void) for (i_run = 0; i_run < 1000; i_run++) { gs_strfreev char **strv = NULL; - gs_free char * str = NULL; + gs_free char *str = NULL; /* create random strv array and join them carefully so that splitting * them will yield the original value. */ @@ -10530,7 +10531,7 @@ test_nm_property_variant_to_gvalue(void) #define _test_variant_to_gvalue_bad(variant, gtype) \ G_STMT_START \ { \ - gs_unref_variant GVariant * _variant = (variant); \ + gs_unref_variant GVariant *_variant = (variant); \ GType _gtype = (gtype); \ nm_auto_unset_gvalue GValue _gvalue = G_VALUE_INIT; \ \ @@ -10542,10 +10543,10 @@ test_nm_property_variant_to_gvalue(void) #define _test_variant_to_gvalue(variant, gtype, check) \ G_STMT_START \ { \ - gs_unref_variant GVariant * _variant = (variant); \ + gs_unref_variant GVariant *_variant = (variant); \ GType _gtype = (gtype); \ nm_auto_unset_gvalue GValue _gvalue = G_VALUE_INIT; \ - _nm_unused GValue *const gg = &_gvalue; \ + _nm_unused GValue *const gg = &_gvalue; \ \ g_value_init(&_gvalue, _gtype); \ g_assert_cmpint(_nm_property_variant_to_gvalue(_variant, &_gvalue), ==, TRUE); \ @@ -10666,6 +10667,146 @@ test_vpn_connection_state_reason(void) /*****************************************************************************/ +static void +test_system_encodings(void) +{ + const int N_RUN = 10000; + int i_run; + + g_assert(nmtst_system_encodings_for_lang("") == NULL); + g_assert(nmtst_system_encodings_for_lang("zh") == NULL); + g_assert(nmtst_system_encodings_for_lang("zh_cx") == NULL); + +#define LL(lang, ...) \ + G_STMT_START \ + { \ + const char *const _lang = "" lang ""; \ + \ + nmtst_assert_strv(nmtst_system_encodings_for_lang(_lang), __VA_ARGS__); \ + \ + if (strlen(_lang) == 2) { \ + gs_free char *_lang2 = g_strdup_printf("%s%s", _lang, "x"); \ + \ + nmtst_assert_strv(nmtst_system_encodings_for_lang(_lang2), __VA_ARGS__); \ + } \ + } \ + G_STMT_END + + LL("zh_cn", "euc-cn", "gb2312", "gb18030"); + LL("zh_hk", "big5", "euc-tw", "big5-hkcs"); + LL("zh_mo", "big5", "euc-tw"); + LL("zh_sg", "euc-cn", "gb2312", "gb18030"); + LL("zh_tw", "big5", "euc-tw"); + + LL("ar", "iso-8859-6", "windows-1256"); + LL("be", "koi8-r", "windows-1251", "iso-8859-5"); + LL("bg", "windows-1251", "koi8-r", "iso-8859-5"); + LL("cs", "iso-8859-2", "windows-1250"); + LL("el", "iso-8859-7", "windows-1253"); + LL("et", "iso-8859-4", "windows-1257"); + LL("he", "iso-8859-8", "windows-1255"); + LL("hr", "iso-8859-2", "windows-1250"); + LL("hu", "iso-8859-2", "windows-1250"); + LL("iw", "iso-8859-8", "windows-1255"); + LL("ja", "euc-jp", "shift_jis", "iso-2022-jp"); + LL("ko", "euc-kr", "iso-2022-kr", "johab"); + LL("lt", "iso-8859-4", "windows-1257"); + LL("lv", "iso-8859-4", "windows-1257"); + LL("mk", "koi8-r", "windows-1251", "iso-8859-5"); + LL("pl", "iso-8859-2", "windows-1250"); + LL("ro", "iso-8859-2", "windows-1250"); + LL("ru", "koi8-r", "windows-1251", "iso-8859-5"); + LL("sh", "iso-8859-2", "windows-1250"); + LL("sk", "iso-8859-2", "windows-1250"); + LL("sl", "iso-8859-2", "windows-1250"); + LL("sr", "koi8-r", "windows-1251", "iso-8859-5"); + LL("th", "iso-8859-11", "windows-874"); + LL("tr", "iso-8859-9", "windows-1254"); + LL("uk", "koi8-u", "koi8-r", "windows-1251"); + + g_assert(nmtst_system_encodings_get_default()); + g_assert(nmtst_system_encodings_get()); + + for (i_run = 0; i_run < N_RUN; i_run++) { + char buf[7]; + int n_buf; + int i_buf; + const char *const *e; + + if (i_run < N_RUN / 3) + n_buf = 2; + else if (i_run < 2 * N_RUN / 3) + n_buf = 5; + else + n_buf = nmtst_get_rand_uint32() % G_N_ELEMENTS(buf); + + for (i_buf = 0; i_buf < n_buf; i_buf++) { + do { + buf[i_buf] = (char) nmtst_get_rand_uint32(); + } while (buf[i_buf] == '\0'); + } + g_assert(i_buf < G_N_ELEMENTS(buf)); + buf[i_buf] = '\0'; + + g_assert_cmpint(n_buf, <, G_N_ELEMENTS(buf)); + g_assert_cmpint(strlen(buf), ==, n_buf); + + e = nmtst_system_encodings_for_lang(buf); + if (e) + g_assert_cmpint(n_buf, >=, 2); + } +} + +/*****************************************************************************/ + +static void +test_direct_string_is_refstr(void) +{ + gs_unref_object NMSetting *s1 = NULL; + gs_unref_object NMSetting *s2 = NULL; + const char *TEST_STR = "adfdsff"; + NMRefString *rstr0; + NMRefString *rstr = NULL; + + g_assert(!nmtst_ref_string_find(TEST_STR)); + + s1 = nm_setting_connection_new(); + g_object_set(s1, + NM_SETTING_CONNECTION_ID, + "uuidtest", + NM_SETTING_CONNECTION_UUID, + nm_uuid_generate_random_str_a(), + NM_SETTING_CONNECTION_TYPE, + TEST_STR, + NULL); + + rstr0 = nmtst_ref_string_find(TEST_STR); + g_assert(rstr0); + + if (nmtst_get_rand_bool()) { + rstr = nm_ref_string_new(TEST_STR); + g_assert(rstr); + g_assert(rstr == rstr0); + g_assert(rstr->str + == nm_setting_connection_get_connection_type((NMSettingConnection *) s1)); + } + + s2 = nm_setting_duplicate(s1); + g_assert(rstr0->str == nm_setting_connection_get_connection_type((NMSettingConnection *) s2)); + + g_clear_object(&s1); + if (nmtst_get_rand_bool()) + g_clear_object(&s2); + else { + g_object_set(s2, NM_SETTING_CONNECTION_TYPE, nmtst_get_rand_bool() ? "hallo" : NULL, NULL); + } + nm_ref_string_unref(rstr); + + g_assert(!nmtst_ref_string_find(TEST_STR)); +} + +/*****************************************************************************/ + NMTST_DEFINE(); int @@ -11008,5 +11149,8 @@ main(int argc, char **argv) g_test_add_func("/core/general/test_vpn_connection_state_reason", test_vpn_connection_state_reason); + g_test_add_func("/core/general/test_system_encodings", test_system_encodings); + g_test_add_func("/core/general/test_direct_string_is_refstr", test_direct_string_is_refstr); + return g_test_run(); } diff --git a/src/libnm-core-impl/tests/test-keyfile.c b/src/libnm-core-impl/tests/test-keyfile.c index db193379..9bd13ffc 100644 --- a/src/libnm-core-impl/tests/test-keyfile.c +++ b/src/libnm-core-impl/tests/test-keyfile.c @@ -26,15 +26,15 @@ /*****************************************************************************/ static void -do_test_encode_key_full(GKeyFile * kf, +do_test_encode_key_full(GKeyFile *kf, const char *name, const char *key, const char *key_decode_encode) { gs_free char *to_free1 = NULL; gs_free char *to_free2 = NULL; - const char * key2; - const char * name2; + const char *key2; + const char *name2; g_assert(key); @@ -105,7 +105,7 @@ test_encode_key(void) G_STMT_START \ { \ NMConnection **_con = (con); \ - GKeyFile ** _keyfile = (keyfile); \ + GKeyFile **_keyfile = (keyfile); \ \ g_clear_object(_con); \ nm_clear_pointer(_keyfile, g_key_file_unref); \ @@ -129,7 +129,7 @@ _assert_gbytes(GBytes *bytes, gconstpointer data, gssize len) static GKeyFile * _keyfile_load_from_data(const char *str) { - GError * error = NULL; + GError *error = NULL; gboolean success; GKeyFile *keyfile; @@ -146,7 +146,7 @@ _keyfile_load_from_data(const char *str) static GKeyFile * _nm_keyfile_write(NMConnection *connection, NMKeyfileWriteHandler handler, void *user_data) { - GError * error = NULL; + GError *error = NULL; GKeyFile *kf; g_assert(NM_IS_CONNECTION(connection)); @@ -158,13 +158,13 @@ _nm_keyfile_write(NMConnection *connection, NMKeyfileWriteHandler handler, void } static NMConnection * -_nm_keyfile_read(GKeyFile * keyfile, - const char * keyfile_name, +_nm_keyfile_read(GKeyFile *keyfile, + const char *keyfile_name, NMKeyfileReadHandler read_handler, - void * read_data, + void *read_data, gboolean needs_normalization) { - GError * error = NULL; + GError *error = NULL; NMConnection *con; gs_free char *filename = NULL; gs_free char *base_dir = NULL; @@ -208,18 +208,18 @@ _nm_keyfile_read(GKeyFile * keyfile, } static void -_keyfile_convert(NMConnection ** con, - GKeyFile ** keyfile, - const char * keyfile_name, +_keyfile_convert(NMConnection **con, + GKeyFile **keyfile, + const char *keyfile_name, NMKeyfileReadHandler read_handler, - void * read_data, + void *read_data, NMKeyfileWriteHandler write_handler, - void * write_data, + void *write_data, gboolean needs_normalization) { - NMConnection * c0; - GKeyFile * k0; - gs_unref_object NMConnection *c0_k1_c2 = NULL, *k0_c1 = NULL, *k0_c1_k2_c3 = NULL; + NMConnection *c0; + GKeyFile *k0; + gs_unref_object NMConnection *c0_k1_c2 = NULL, *k0_c1 = NULL, *k0_c1_k2_c3 = NULL; nm_auto_unref_keyfile GKeyFile *k0_c1_k2 = NULL, *c0_k1 = NULL, *c0_k1_c2_k3 = NULL; /* convert from @con to @keyfile and check that we can make @@ -263,7 +263,7 @@ _keyfile_convert(NMConnection ** con, nmtst_assert_resolve_relative_path_equals(p1, p2); if (strcmp(p1, p2) != 0) { - gs_free char * puri = NULL; + gs_free char *puri = NULL; gs_unref_bytes GBytes *pfile = NULL; g_assert(p1[0] != '/' && p2[0] == '/'); @@ -310,14 +310,14 @@ _keyfile_convert(NMConnection ** con, /*****************************************************************************/ static void -_test_8021x_cert_check(NMConnection * con, +_test_8021x_cert_check(NMConnection *con, NMSetting8021xCKScheme expected_scheme, - const void * value, + const void *value, gssize val_len) { - GKeyFile * keyfile = NULL; + GKeyFile *keyfile = NULL; NMSetting8021x *s_8021x; - gs_free char * kval = NULL; + gs_free char *kval = NULL; _keyfile_convert(&con, &keyfile, "/_test_8021x_cert_check/foo", NULL, NULL, NULL, NULL, FALSE); @@ -335,7 +335,7 @@ _test_8021x_cert_check(NMConnection * con, g_assert(kval); g_assert_cmpstr(kval, ==, value); } else if (expected_scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB) { - GBytes * blob = nm_setting_802_1x_get_ca_cert_blob(s_8021x); + GBytes *blob = nm_setting_802_1x_get_ca_cert_blob(s_8021x); gs_free char *file_blob = NULL; if (val_len == -1) { @@ -363,7 +363,7 @@ _test_8021x_cert_check(NMConnection * con, static void _test_8021x_cert_check_blob_full(NMConnection *con, const void *data, gsize len) { - GBytes * bytes; + GBytes *bytes; NMSetting8021x *s_8021x = nm_connection_get_setting_802_1x(con); bytes = g_bytes_new(data, len); @@ -380,10 +380,10 @@ _test_8021x_cert_check_blob_full(NMConnection *con, const void *data, gsize len) static void _test_8021x_cert_from_files(const char *cert, const char *key) { - NMSetting8021x *s_8021x; + NMSetting8021x *s_8021x; gs_unref_object NMConnection *con = nmtst_create_minimal_connection("test-cert", NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); - GError * error = NULL; + GError *error = NULL; gboolean success; NMSetting8021xCKScheme scheme = NM_SETTING_802_1X_CK_SCHEME_PATH; gs_free char *full_TEST_WIRED_TLS_CA_CERT = nmtst_file_resolve_relative_path(cert, NULL); @@ -456,9 +456,9 @@ test_8021x_cert_tpm2key(void) static void test_8021x_cert_read(void) { - GKeyFile * keyfile = NULL; - gs_unref_object NMConnection *con = NULL; - NMSetting8021x * s_8021x; + GKeyFile *keyfile = NULL; + gs_unref_object NMConnection *con = NULL; + NMSetting8021x *s_8021x; con = nmtst_create_connection_from_keyfile("[connection]\n" "type=ethernet", @@ -649,9 +649,9 @@ test_8021x_cert_read(void) static void test_team_conf_read_valid(void) { - GKeyFile * keyfile = NULL; - gs_unref_object NMConnection *con = NULL; - NMSettingTeam * s_team; + GKeyFile *keyfile = NULL; + gs_unref_object NMConnection *con = NULL; + NMSettingTeam *s_team; con = nmtst_create_connection_from_keyfile("[connection]\n" "type=team\n" @@ -671,9 +671,9 @@ test_team_conf_read_valid(void) static void test_team_conf_read_invalid(void) { - GKeyFile * keyfile = NULL; - gs_unref_object NMConnection *con = NULL; - NMSettingTeam * s_team; + GKeyFile *keyfile = NULL; + gs_unref_object NMConnection *con = NULL; + NMSettingTeam *s_team; if (!nm_json_vt()) { g_test_skip("team test requires JSON validation"); @@ -701,8 +701,8 @@ static void test_user_1(void) { nm_auto_unref_keyfile GKeyFile *keyfile = NULL; - gs_unref_object NMConnection *con = NULL; - NMSettingUser * s_user; + gs_unref_object NMConnection *con = NULL; + NMSettingUser *s_user; con = nmtst_create_connection_from_keyfile("[connection]\n" "id=t\n" @@ -728,7 +728,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); \ @@ -771,8 +771,8 @@ static void test_vpn_1(void) { nm_auto_unref_keyfile GKeyFile *keyfile = NULL; - gs_unref_object NMConnection *con = NULL; - NMSettingVpn * s_vpn; + gs_unref_object NMConnection *con = NULL; + NMSettingVpn *s_vpn; con = nmtst_create_connection_from_keyfile("[connection]\n" "id=t\n" @@ -797,19 +797,19 @@ static void test_bridge_vlans(void) { nm_auto_unref_keyfile GKeyFile *keyfile = NULL; - gs_unref_object NMConnection *con = NULL; - NMSettingBridge * s_bridge; - NMBridgeVlan * vlan; - guint16 vid, vid_end; + gs_unref_object NMConnection *con = NULL; + NMSettingBridge *s_bridge; + NMBridgeVlan *vlan; + guint16 vid, vid_end; con = nmtst_create_connection_from_keyfile("[connection]\n" - "id=t\n" - "type=bridge\n" - "interface-name=br4\n" - "\n" - "[bridge]\n" - "vlans=900 , 1 pvid untagged, 100-123 untagged\n" - "", + "id=t\n" + "type=bridge\n" + "interface-name=br4\n" + "\n" + "[bridge]\n" + "vlans=900 , 1 pvid untagged, 100-123 untagged\n" + "", "/test_bridge_port/vlans"); s_bridge = NM_SETTING_BRIDGE(nm_connection_get_setting(con, NM_TYPE_SETTING_BRIDGE)); g_assert(s_bridge); @@ -846,21 +846,21 @@ static void test_bridge_port_vlans(void) { nm_auto_unref_keyfile GKeyFile *keyfile = NULL; - gs_unref_object NMConnection *con = NULL; - NMSettingBridgePort * s_port; - NMBridgeVlan * vlan; - guint16 vid_start, vid_end; + gs_unref_object NMConnection *con = NULL; + NMSettingBridgePort *s_port; + NMBridgeVlan *vlan; + guint16 vid_start, vid_end; con = nmtst_create_connection_from_keyfile("[connection]\n" - "id=t\n" - "type=dummy\n" - "interface-name=dummy1\n" - "master=br0\n" - "slave-type=bridge\n" - "\n" - "[bridge-port]\n" - "vlans=4094 pvid , 10-20 untagged\n" - "", + "id=t\n" + "type=dummy\n" + "interface-name=dummy1\n" + "master=br0\n" + "slave-type=bridge\n" + "\n" + "[bridge-port]\n" + "vlans=4094 pvid , 10-20 untagged\n" + "", "/test_bridge_port/vlans"); s_port = NM_SETTING_BRIDGE_PORT(nm_connection_get_setting(con, NM_TYPE_SETTING_BRIDGE_PORT)); g_assert(s_port); diff --git a/src/libnm-core-impl/tests/test-secrets.c b/src/libnm-core-impl/tests/test-secrets.c index 41dcc4b3..2fa3f105 100644 --- a/src/libnm-core-impl/tests/test-secrets.c +++ b/src/libnm-core-impl/tests/test-secrets.c @@ -46,14 +46,14 @@ _assert_hints_has(GPtrArray *hints, const char *item) static NMConnection * make_tls_connection(const char *detail, NMSetting8021xCKScheme scheme) { - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - NMSetting8021x * s_8021x; - NMSettingWired * s_wired; - NMSettingIP4Config * s_ip4; - char * uuid; + NMSetting8021x *s_8021x; + NMSettingWired *s_wired; + NMSettingIP4Config *s_ip4; + char *uuid; gboolean success; - GError * error = NULL; + GError *error = NULL; connection = nm_simple_connection_new(); @@ -129,8 +129,8 @@ static void test_need_tls_secrets_path(void) { NMConnection *connection; - const char * setting_name; - GPtrArray * hints = NULL; + const char *setting_name; + GPtrArray *hints = NULL; connection = make_tls_connection("need-tls-secrets-path-key", NM_SETTING_802_1X_CK_SCHEME_PATH); @@ -155,8 +155,8 @@ static void test_need_tls_secrets_blob(void) { NMConnection *connection; - const char * setting_name; - GPtrArray * hints = NULL; + const char *setting_name; + GPtrArray *hints = NULL; connection = make_tls_connection("need-tls-secrets-blob-key", NM_SETTING_802_1X_CK_SCHEME_BLOB); @@ -180,14 +180,14 @@ test_need_tls_secrets_blob(void) static NMConnection * make_tls_phase2_connection(const char *detail, NMSetting8021xCKScheme scheme) { - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - NMSetting8021x * s_8021x; - NMSettingWired * s_wired; - NMSettingIP4Config * s_ip4; - char * uuid; + NMSetting8021x *s_8021x; + NMSettingWired *s_wired; + NMSettingIP4Config *s_ip4; + char *uuid; gboolean success; - GError * error = NULL; + GError *error = NULL; connection = nm_simple_connection_new(); @@ -264,8 +264,8 @@ static void test_need_tls_phase2_secrets_path(void) { NMConnection *connection; - const char * setting_name; - GPtrArray * hints = NULL; + const char *setting_name; + GPtrArray *hints = NULL; connection = make_tls_phase2_connection("need-tls-phase2-secrets-path-key", NM_SETTING_802_1X_CK_SCHEME_PATH); @@ -291,8 +291,8 @@ static void test_need_tls_phase2_secrets_blob(void) { NMConnection *connection; - const char * setting_name; - GPtrArray * hints = NULL; + const char *setting_name; + GPtrArray *hints = NULL; connection = make_tls_phase2_connection("need-tls-phase2-secrets-blob-key", NM_SETTING_802_1X_CK_SCHEME_BLOB); @@ -317,13 +317,13 @@ test_need_tls_phase2_secrets_blob(void) static NMConnection * wifi_connection_new(void) { - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; unsigned char tmpssid[] = {0x31, 0x33, 0x33, 0x37}; - char * uuid; - GBytes * ssid; + char *uuid; + GBytes *ssid; connection = nm_simple_connection_new(); g_assert(connection); @@ -386,13 +386,13 @@ build_wep_secrets(const char *wepkey) static void test_update_secrets_wifi_single_setting(void) { - NMConnection * connection; + NMConnection *connection; NMSettingWirelessSecurity *s_wsec; - GVariant * secrets; - GError * error = NULL; + GVariant *secrets; + GError *error = NULL; gboolean success; - const char * wepkey = "11111111111111111111111111"; - const char * tmp; + const char *wepkey = "11111111111111111111111111"; + const char *tmp; /* Test update with a hashed setting of 802-11-wireless secrets */ @@ -420,14 +420,14 @@ test_update_secrets_wifi_single_setting(void) static void test_update_secrets_wifi_full_hash(void) { - NMConnection * connection; + NMConnection *connection; NMSettingWirelessSecurity *s_wsec; GVariantBuilder builder; - GVariant * all; - GError * error = NULL; + GVariant *all; + GError *error = NULL; gboolean success; - const char * wepkey = "11111111111111111111111111"; - const char * tmp; + const char *wepkey = "11111111111111111111111111"; + const char *tmp; /* Test update with a hashed connection containing only 802-11-wireless * setting and secrets. @@ -464,10 +464,10 @@ static void test_update_secrets_wifi_bad_setting_name(void) { NMConnection *connection; - GVariant * secrets; - GError * error = NULL; + GVariant *secrets; + GError *error = NULL; gboolean success; - const char * wepkey = "11111111111111111111111111"; + const char *wepkey = "11111111111111111111111111"; /* Test that passing an invalid setting name to * nm_connection_update_secrets() fails with the correct error. @@ -489,12 +489,12 @@ test_update_secrets_wifi_bad_setting_name(void) static void test_update_secrets_whole_connection(void) { - NMConnection * connection; + NMConnection *connection; NMSettingWirelessSecurity *s_wsec; - GVariant * secrets; - GError * error = NULL; + GVariant *secrets; + GError *error = NULL; gboolean success; - const char * wepkey = "11111111111111111111111111"; + const char *wepkey = "11111111111111111111111111"; /* Test calling nm_connection_update_secrets() with an entire hashed * connection including non-secrets. @@ -527,8 +527,8 @@ static void test_update_secrets_whole_connection_empty_hash(void) { gs_unref_object NMConnection *connection = NULL; - GVariant * secrets; - GError * error = NULL; + GVariant *secrets; + GError *error = NULL; gboolean success; /* Test that updating secrets with an empty connection hash returns success */ @@ -550,15 +550,15 @@ test_update_secrets_whole_connection_empty_hash(void) static void test_update_secrets_whole_connection_bad_setting(void) { - NMConnection * connection; + NMConnection *connection; NMSettingWirelessSecurity *s_wsec; - GVariant * secrets, *copy, *setting_hash; - const char * setting_name; + GVariant *secrets, *copy, *setting_hash; + const char *setting_name; GVariantBuilder conn_builder; GVariantIter conn_iter; - GError * error = NULL; + GError *error = NULL; gboolean success; - const char * wepkey = "11111111111111111111111111"; + const char *wepkey = "11111111111111111111111111"; /* Test that sending a hashed connection containing an invalid setting * name fails with the right error. @@ -601,8 +601,8 @@ static void test_update_secrets_whole_connection_empty_base_setting(void) { NMConnection *connection; - GVariant * secrets, *setting; - GError * error = NULL; + GVariant *secrets, *setting; + GError *error = NULL; gboolean success; /* Test that a hashed connection which does not have any hashed secrets @@ -632,10 +632,10 @@ static void test_update_secrets_null_setting_name_with_setting_hash(void) { NMConnection *connection; - GVariant * secrets; - GError * error = NULL; + GVariant *secrets; + GError *error = NULL; gboolean success; - const char * wepkey = "11111111111111111111111111"; + const char *wepkey = "11111111111111111111111111"; /* Ensure that a NULL setting name and only a hashed setting fails */ diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 7444f2c1..d6ac37b4 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -48,8 +48,8 @@ _connection_new_from_dbus_strict(GVariant *dict, gboolean normalize) gs_unref_object NMConnection *con_n_0 = NULL; gs_unref_object NMConnection *con_n_s = NULL; gs_unref_object NMConnection *con_n_e = NULL; - gs_free_error GError *error = NULL; - guint i; + gs_free_error GError *error = NULL; + guint i; g_assert(g_variant_is_of_type(dict, NM_VARIANT_TYPE_CONNECTION)); @@ -128,7 +128,7 @@ test_nm_meta_setting_types_by_priority(void) for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { const NMMetaSettingType meta_type = nm_meta_setting_types_by_priority[i]; const NMMetaSettingInfo *setting_info; - NMSetting * setting; + NMSetting *setting; g_assert(_NM_INT_NOT_NEGATIVE(meta_type)); g_assert(meta_type < _NM_META_SETTING_TYPE_NUM); @@ -203,7 +203,7 @@ compare_blob_data(const char *test, const char *key_path, GBytes *key) { gs_free char *contents = NULL; gsize len = 0; - GError * error = NULL; + GError *error = NULL; gboolean success; g_assert(key && g_bytes_get_size(key) > 0); @@ -237,13 +237,13 @@ check_scheme_path(GBytes *value, const char *path) static void test_private_key_import(const char *path, const char *password, NMSetting8021xCKScheme scheme) { - NMSetting8021x * s_8021x; + NMSetting8021x *s_8021x; gboolean success; NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; NMSetting8021xCKFormat tmp_fmt; - GError * error = NULL; - GBytes * tmp_key = NULL, *client_cert = NULL; - const char * pw; + GError *error = NULL; + GBytes *tmp_key = NULL, *client_cert = NULL; + const char *pw; s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); g_assert(s_8021x); @@ -293,7 +293,7 @@ static void _do_test_connection_uuid(NMConnection *con, const char *uuid, const char *expected_uuid) { NMSettingConnection *s_con; - gs_free char * uuid_old = NULL; + gs_free char *uuid_old = NULL; gboolean success; gboolean is_normalized; char uuid_normalized[37]; @@ -407,17 +407,17 @@ test_connection_uuid(void) /*****************************************************************************/ static void -test_phase2_private_key_import(const char * path, - const char * password, +test_phase2_private_key_import(const char *path, + const char *password, NMSetting8021xCKScheme scheme) { - NMSetting8021x * s_8021x; + NMSetting8021x *s_8021x; gboolean success; NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; NMSetting8021xCKFormat tmp_fmt; - GError * error = NULL; - GBytes * tmp_key = NULL, *client_cert = NULL; - const char * pw; + GError *error = NULL; + GBytes *tmp_key = NULL, *client_cert = NULL; + const char *pw; s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); g_assert(s_8021x); @@ -465,11 +465,11 @@ test_phase2_private_key_import(const char * path, static void test_wrong_password_keeps_data(const char *path, const char *password) { - NMSetting8021x * s_8021x; + NMSetting8021x *s_8021x; gboolean success; NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; - GError * error = NULL; - const char * pw; + GError *error = NULL; + const char *pw; s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); g_assert(s_8021x); @@ -506,11 +506,11 @@ test_wrong_password_keeps_data(const char *path, const char *password) static void test_clear_private_key(const char *path, const char *password) { - NMSetting8021x * s_8021x; + NMSetting8021x *s_8021x; gboolean success; NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; - GError * error = NULL; - const char * pw; + GError *error = NULL; + const char *pw; s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); g_assert(s_8021x); @@ -547,11 +547,11 @@ test_clear_private_key(const char *path, const char *password) static void test_wrong_phase2_password_keeps_data(const char *path, const char *password) { - NMSetting8021x * s_8021x; + NMSetting8021x *s_8021x; gboolean success; NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; - GError * error = NULL; - const char * pw; + GError *error = NULL; + const char *pw; s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); g_assert(s_8021x); @@ -588,11 +588,11 @@ test_wrong_phase2_password_keeps_data(const char *path, const char *password) static void test_clear_phase2_private_key(const char *path, const char *password) { - NMSetting8021x * s_8021x; + NMSetting8021x *s_8021x; gboolean success; NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; - GError * error = NULL; - const char * pw; + GError *error = NULL; + const char *pw; s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); g_assert(s_8021x); @@ -683,8 +683,8 @@ static void _test_verify_options(gboolean expected_result, const char *const *options) { gs_unref_object NMConnection *con = NULL; - NMSettingBond * s_bond; - const char *const * option; + NMSettingBond *s_bond; + const char *const *option; g_assert(NM_PTRARRAY_LEN(options) % 2 == 0); @@ -777,7 +777,7 @@ static void test_bond_compare_options(gboolean exp_res, const char **opts1, const char **opts2) { gs_unref_object NMSettingBond *s_bond1 = NULL, *s_bond2 = NULL; - const char ** p; + const char **p; s_bond1 = (NMSettingBond *) nm_setting_bond_new(); g_assert(s_bond1); @@ -830,10 +830,10 @@ static void test_bond_normalize_options(const char **opts1, const char **opts2) { gs_unref_object NMConnection *con = NULL; - NMSettingBond * s_bond; - GError * error = NULL; + NMSettingBond *s_bond; + GError *error = NULL; gboolean success; - const char ** p; + const char **p; int num = 0; create_bond_connection(&con, &s_bond); @@ -880,7 +880,7 @@ static void test_dummy_normalize(void) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; + NMSettingConnection *s_con; connection = nm_simple_connection_new(); s_con = NM_SETTING_CONNECTION(nm_setting_connection_new()); @@ -911,7 +911,7 @@ static void test_dcb_flags_valid(void) { gs_unref_object NMSettingDcb *s_dcb = NULL; - GError * error = NULL; + GError *error = NULL; gboolean success; guint i; @@ -969,7 +969,7 @@ static void test_dcb_flags_invalid(void) { gs_unref_object NMSettingDcb *s_dcb = NULL; - GError * error = NULL; + GError *error = NULL; gboolean success; s_dcb = (NMSettingDcb *) nm_setting_dcb_new(); @@ -1039,7 +1039,7 @@ static void test_dcb_app_priorities(void) { gs_unref_object NMSettingDcb *s_dcb = NULL; - GError * error = NULL; + GError *error = NULL; gboolean success; s_dcb = (NMSettingDcb *) nm_setting_dcb_new(); @@ -1107,7 +1107,7 @@ static void test_dcb_priorities_valid(void) { gs_unref_object NMSettingDcb *s_dcb = NULL; - GError * error = NULL; + GError *error = NULL; gboolean success; guint i; @@ -1166,7 +1166,7 @@ static void test_dcb_bandwidth_sums(void) { gs_unref_object NMSettingDcb *s_dcb = NULL; - GError * error = NULL; + GError *error = NULL; gboolean success; s_dcb = (NMSettingDcb *) nm_setting_dcb_new(); @@ -1225,17 +1225,17 @@ _test_team_config_sync(const char *team_config, int notify_peers_interval, int mcast_rejoin_count, int mcast_rejoin_interval, - char * runner, - char * runner_hwaddr_policy, /* activebackup */ - GPtrArray * runner_tx_hash, /* lacp, loadbalance */ - char * runner_tx_balancer, /* lacp, loadbalance */ + char *runner, + char *runner_hwaddr_policy, /* activebackup */ + GPtrArray *runner_tx_hash, /* lacp, loadbalance */ + char *runner_tx_balancer, /* lacp, loadbalance */ int runner_tx_balancer_interval, /* lacp, loadbalance */ gboolean runner_active, /* lacp */ gboolean runner_fast_rate, /* lacp */ int runner_sys_prio, /* lacp */ int runner_min_ports, /* lacp */ - char * runner_agg_select_policy, /* lacp */ - GPtrArray * link_watchers) + char *runner_agg_select_policy, /* lacp */ + GPtrArray *link_watchers) { gs_unref_object NMSettingTeam *s_team = NULL; guint i, j; @@ -1634,7 +1634,7 @@ _test_team_port_config_sync(const char *team_port_config, gboolean sticky, int lacp_prio, int lacp_key, - GPtrArray * link_watchers) + GPtrArray *link_watchers) { gs_unref_object NMSettingTeamPort *s_team_port = NULL; guint i, j; @@ -1812,8 +1812,8 @@ test_team_setting(void) G_VARIANT_TYPE_VARDICT, "{'config': <'{\"link_watch\": {\"name\": \"ethtool\"}}'>, 'interface-name': <'nm-team'>, " "'link-watchers': <[{'name': <'ethtool'>}]>}"); - gs_free_error GError *error = NULL; - gs_unref_object NMSetting * setting = NULL; + gs_free_error GError *error = NULL; + gs_unref_object NMSetting *setting = NULL; nm_auto_unref_team_link_watcher NMTeamLinkWatcher *watcher1 = nm_team_link_watcher_new_nsna_ping(1, 3, 4, "bbb", NULL); nm_auto_unref_team_link_watcher NMTeamLinkWatcher *watcher2 = @@ -1939,16 +1939,16 @@ _setting_ethtool_get_feature(NMSettingEthtool *s_ethtool, const char *opt_name) static void test_ethtool_features(void) { - gs_unref_object NMConnection *con = NULL; - gs_unref_object NMConnection *con2 = NULL; - gs_unref_object NMConnection *con3 = NULL; - gs_unref_variant GVariant *variant = NULL; - gs_free_error GError *error = NULL; + gs_unref_object NMConnection *con = NULL; + gs_unref_object NMConnection *con2 = NULL; + gs_unref_object NMConnection *con3 = NULL; + gs_unref_variant GVariant *variant = NULL; + gs_free_error GError *error = NULL; nm_auto_unref_keyfile GKeyFile *keyfile = NULL; - NMSettingConnection * s_con; - NMSettingEthtool * s_ethtool; - NMSettingEthtool * s_ethtool2; - NMSettingEthtool * s_ethtool3; + NMSettingConnection *s_con; + NMSettingEthtool *s_ethtool; + NMSettingEthtool *s_ethtool2; + NMSettingEthtool *s_ethtool3; con = nmtst_create_minimal_connection("ethtool-1", NULL, NM_SETTING_WIRED_SETTING_NAME, &s_con); s_ethtool = NM_SETTING_ETHTOOL(nm_setting_ethtool_new()); @@ -2024,16 +2024,16 @@ test_ethtool_features(void) static void test_ethtool_coalesce(void) { - gs_unref_object NMConnection *con = NULL; - gs_unref_object NMConnection *con2 = NULL; - gs_unref_object NMConnection *con3 = NULL; - gs_unref_variant GVariant *variant = NULL; - gs_free_error GError *error = NULL; + gs_unref_object NMConnection *con = NULL; + gs_unref_object NMConnection *con2 = NULL; + gs_unref_object NMConnection *con3 = NULL; + gs_unref_variant GVariant *variant = NULL; + gs_free_error GError *error = NULL; nm_auto_unref_keyfile GKeyFile *keyfile = NULL; - NMSettingConnection * s_con; - NMSettingEthtool * s_ethtool; - NMSettingEthtool * s_ethtool2; - NMSettingEthtool * s_ethtool3; + NMSettingConnection *s_con; + NMSettingEthtool *s_ethtool; + NMSettingEthtool *s_ethtool2; + NMSettingEthtool *s_ethtool3; guint32 u32; con = nmtst_create_minimal_connection("ethtool-coalesce", @@ -2120,16 +2120,16 @@ test_ethtool_coalesce(void) static void test_ethtool_ring(void) { - gs_unref_object NMConnection *con = NULL; - gs_unref_object NMConnection *con2 = NULL; - gs_unref_object NMConnection *con3 = NULL; - gs_unref_variant GVariant *variant = NULL; - gs_free_error GError *error = NULL; + gs_unref_object NMConnection *con = NULL; + gs_unref_object NMConnection *con2 = NULL; + gs_unref_object NMConnection *con3 = NULL; + gs_unref_variant GVariant *variant = NULL; + gs_free_error GError *error = NULL; nm_auto_unref_keyfile GKeyFile *keyfile = NULL; - NMSettingConnection * s_con; - NMSettingEthtool * s_ethtool; - NMSettingEthtool * s_ethtool2; - NMSettingEthtool * s_ethtool3; + NMSettingConnection *s_con; + NMSettingEthtool *s_ethtool; + NMSettingEthtool *s_ethtool2; + NMSettingEthtool *s_ethtool3; guint32 out_value; con = nmtst_create_minimal_connection("ethtool-ring", @@ -2214,16 +2214,16 @@ test_ethtool_ring(void) static void test_ethtool_pause(void) { - gs_unref_object NMConnection *con = NULL; - gs_unref_object NMConnection *con2 = NULL; - gs_unref_object NMConnection *con3 = NULL; - gs_unref_variant GVariant *variant = NULL; - gs_free_error GError *error = NULL; + gs_unref_object NMConnection *con = NULL; + gs_unref_object NMConnection *con2 = NULL; + gs_unref_object NMConnection *con3 = NULL; + gs_unref_variant GVariant *variant = NULL; + gs_free_error GError *error = NULL; nm_auto_unref_keyfile GKeyFile *keyfile = NULL; - NMSettingConnection * s_con; - NMSettingEthtool * s_ethtool; - NMSettingEthtool * s_ethtool2; - NMSettingEthtool * s_ethtool3; + NMSettingConnection *s_con; + NMSettingEthtool *s_ethtool; + NMSettingEthtool *s_ethtool2; + NMSettingEthtool *s_ethtool3; gboolean out_value; con = nmtst_create_minimal_connection("ethtool-pause", @@ -2311,8 +2311,8 @@ static void test_sriov_vf(void) { NMSriovVF *vf1, *vf2; - GError * error = NULL; - char * str; + GError *error = NULL; + char *str; vf1 = nm_sriov_vf_new(1); nm_sriov_vf_set_attribute(vf1, @@ -2369,10 +2369,10 @@ test_sriov_vf_dup(void) static void test_sriov_vf_vlan(void) { - NMSriovVF * vf; - const guint * vlan_ids; + NMSriovVF *vf; + const guint *vlan_ids; guint num; - GError * error = NULL; + GError *error = NULL; gs_free char *str = NULL; vf = nm_sriov_vf_new(19); @@ -2430,10 +2430,10 @@ static void test_sriov_setting(void) { gs_unref_object NMConnection *con = NULL; - NMSettingConnection * s_con; - NMSettingSriov * s_sriov = NULL; - NMSriovVF * vf1, *vf2, *vf3; - GError * error = NULL; + NMSettingConnection *s_con; + NMSettingSriov *s_sriov = NULL; + NMSriovVF *vf1, *vf2, *vf3; + GError *error = NULL; gboolean success; con = nm_simple_connection_new(); @@ -2491,7 +2491,7 @@ typedef struct { static void _test_sriov_parse_vlan_one(const char *string, gboolean exp_res, VlanData *data, guint data_length) { - NMSriovVF * vf; + NMSriovVF *vf; gboolean res; guint i, num_vlans; const guint *vlan_ids; @@ -2550,9 +2550,9 @@ static void test_bridge_vlans(void) { NMBridgeVlan *v1, *v2; - GError * error = NULL; + GError *error = NULL; guint16 vid_start, vid_end; - char * str; + char *str; v1 = nm_bridge_vlan_from_str("1 foobar", &error); nmtst_assert_no_success(v1, error); @@ -2641,8 +2641,8 @@ static void _test_verify_options_bridge(gboolean expected_result, const char *const *options) { gs_unref_object NMConnection *con = NULL; - NMSettingBridge * s_bridge; - const char *const * option; + NMSettingBridge *s_bridge; + const char *const *option; g_assert(NM_PTRARRAY_LEN(options) % 2 == 0); @@ -2729,9 +2729,9 @@ static void test_tc_config_qdisc(void) { NMTCQdisc *qdisc1, *qdisc2; - char * str; - GError * error = NULL; - GVariant * variant; + char *str; + GError *error = NULL; + GVariant *variant; qdisc1 = nm_tc_qdisc_new("fq_codel", TC_H_ROOT, &error); nmtst_assert_success(qdisc1, error); @@ -2844,8 +2844,8 @@ static void test_tc_config_action(void) { NMTCAction *action1, *action2; - char * str; - GError * error = NULL; + char *str; + GError *error = NULL; action1 = nm_tc_action_new("drop", &error); nmtst_assert_success(action1, error); @@ -2897,10 +2897,10 @@ test_tc_config_action(void) static void test_tc_config_tfilter_matchall_sdata(void) { - NMTCAction * action1; + NMTCAction *action1; NMTCTfilter *tfilter1, *tfilter2; - char * str; - GError * error = NULL; + char *str; + GError *error = NULL; tfilter1 = nm_tc_tfilter_new("matchall", TC_H_MAKE(0x1234u << 16, 0x0000u), &error); nmtst_assert_success(tfilter1, error); @@ -2948,12 +2948,12 @@ test_tc_config_tfilter_matchall_sdata(void) static void test_tc_config_tfilter_matchall_mirred(void) { - NMTCAction * action; - NMTCTfilter * tfilter1; - GError * error = NULL; + NMTCAction *action; + NMTCTfilter *tfilter1; + GError *error = NULL; gs_strfreev char **attr_names = NULL; - gs_free char * str; - GVariant * variant; + gs_free char *str = NULL; + GVariant *variant; tfilter1 = nm_utils_tc_tfilter_from_str("parent ffff: matchall action mirred ingress mirror dev eth0", @@ -2995,8 +2995,8 @@ static void test_tc_config_setting_valid(void) { gs_unref_object NMSettingTCConfig *s_tc = NULL; - NMTCQdisc * qdisc1, *qdisc2; - GError * error = NULL; + NMTCQdisc *qdisc1, *qdisc2; + GError *error = NULL; s_tc = (NMSettingTCConfig *) nm_setting_tc_config_new(); @@ -3028,12 +3028,12 @@ test_tc_config_setting_duplicates(void) { gs_unref_ptrarray GPtrArray *qdiscs = NULL; gs_unref_ptrarray GPtrArray *tfilters = NULL; - NMSettingConnection * s_con; - NMConnection * con; - NMSetting * s_tc; - NMTCQdisc * qdisc; - NMTCTfilter * tfilter; - GError * error = NULL; + NMSettingConnection *s_con; + NMConnection *con; + NMSetting *s_tc; + NMTCQdisc *qdisc; + NMTCTfilter *tfilter; + GError *error = NULL; con = nmtst_create_minimal_connection("dummy", NULL, NM_SETTING_DUMMY_SETTING_NAME, &s_con); g_object_set(s_con, NM_SETTING_CONNECTION_INTERFACE_NAME, "dummy1", NULL); @@ -3088,12 +3088,12 @@ static void test_tc_config_dbus(void) { NMConnection *connection1, *connection2; - NMSetting * s_tc; - NMTCQdisc * qdisc1, *qdisc2; - NMTCTfilter * tfilter1, *tfilter2; - NMTCAction * action; - GVariant * dbus, *tc_dbus, *var1, *var2; - GError * error = NULL; + NMSetting *s_tc; + NMTCQdisc *qdisc1, *qdisc2; + NMTCTfilter *tfilter1, *tfilter2; + NMTCAction *action; + GVariant *dbus, *tc_dbus, *var1, *var2; + GError *error = NULL; gboolean success; connection1 = @@ -3183,13 +3183,13 @@ test_tc_config_dbus(void) static void _rndt_wired_add_s390_options(NMSettingWired *s_wired, char **out_keyfile_entries) { - gsize n_opts; - gsize i, j; - const char *const * option_names; - gs_free const char **opt_keys = NULL; - gs_strfreev char ** opt_vals = NULL; - gs_free bool * opt_found = NULL; - GString * keyfile_entries; + gsize n_opts; + gsize i, j; + const char *const *option_names; + gs_free const char **opt_keys = NULL; + gs_strfreev char **opt_vals = NULL; + gs_free bool *opt_found = NULL; + GString *keyfile_entries; nm_auto_free_gstring GString *str_tmp = NULL; option_names = nm_setting_wired_get_valid_s390_options(nmtst_get_rand_bool() ? NULL : s_wired); @@ -3288,9 +3288,9 @@ _rndt_wg_peers_create(void) NMWireGuardPeer *peer; guint8 public_key_buf[NM_WIREGUARD_PUBLIC_KEY_LEN]; guint8 preshared_key_buf[NM_WIREGUARD_SYMMETRIC_KEY_LEN]; - gs_free char * public_key = NULL; - gs_free char * preshared_key = NULL; - gs_free char * s_endpoint = NULL; + gs_free char *public_key = NULL; + gs_free char *preshared_key = NULL; + gs_free char *s_endpoint = NULL; guint i_aip, n_aip; /* we don't bother to create a valid curve25519 public key. Of course, libnm cannot @@ -3358,11 +3358,11 @@ _rndt_wg_peers_to_keyfile(GPtrArray *wg_peers, gboolean strict, char **out_str) nm_gstring_prepare(&gstr); for (i = 0; i < wg_peers->len; i++) { const NMWireGuardPeer *peer = wg_peers->pdata[i]; - gs_free char * s_endpoint = NULL; - gs_free char * s_preshared_key = NULL; - gs_free char * s_preshared_key_flags = NULL; - gs_free char * s_persistent_keepalive = NULL; - gs_free char * s_allowed_ips = NULL; + gs_free char *s_endpoint = NULL; + gs_free char *s_preshared_key = NULL; + gs_free char *s_preshared_key_flags = NULL; + gs_free char *s_persistent_keepalive = NULL; + gs_free char *s_allowed_ips = NULL; if (nm_wireguard_peer_get_endpoint(peer)) s_endpoint = g_strdup_printf("endpoint=%s\n", nm_wireguard_peer_get_endpoint(peer)); @@ -3421,7 +3421,7 @@ _rndt_wg_peers_to_keyfile(GPtrArray *wg_peers, gboolean strict, char **out_str) static void _rndt_wg_peers_assert_equal(NMSettingWireGuard *s_wg, - GPtrArray * peers, + GPtrArray *peers, gboolean consider_persistent_secrets, gboolean consider_all_secrets, gboolean expect_no_secrets) @@ -3476,8 +3476,8 @@ _rndt_wg_peers_fix_secrets(NMSettingWireGuard *s_wg, GPtrArray *peers) g_assert_cmpint(peers->len, ==, nm_setting_wireguard_get_peers_len(s_wg)); for (i = 0; i < peers->len; i++) { - const NMWireGuardPeer *a = peers->pdata[i]; - const NMWireGuardPeer *b = nm_setting_wireguard_get_peer(s_wg, i); + const NMWireGuardPeer *a = peers->pdata[i]; + const NMWireGuardPeer *b = nm_setting_wireguard_get_peer(s_wg, i); nm_auto_unref_wgpeer NMWireGuardPeer *b_clone = NULL; g_assert(a); @@ -3538,23 +3538,23 @@ test_roundtrip_conversion(gconstpointer test_data) nmtst_rand_select(NM_SETTING_SECRET_FLAG_NONE, NM_SETTING_SECRET_FLAG_NOT_SAVED, NM_SETTING_SECRET_FLAG_AGENT_OWNED); - const guint WG_LISTEN_PORT = nmtst_rand_select(0u, nmtst_get_rand_uint32() % 0x10000); - const guint WG_FWMARK = nmtst_rand_select(0u, nmtst_get_rand_uint32()); - gs_unref_ptrarray GPtrArray *kf_data_arr = g_ptr_array_new_with_free_func(g_free); - gs_unref_ptrarray GPtrArray * wg_peers = NULL; + const guint WG_LISTEN_PORT = nmtst_rand_select(0u, nmtst_get_rand_uint32() % 0x10000); + const guint WG_FWMARK = nmtst_rand_select(0u, nmtst_get_rand_uint32()); + gs_unref_ptrarray GPtrArray *kf_data_arr = g_ptr_array_new_with_free_func(g_free); + gs_unref_ptrarray GPtrArray *wg_peers = NULL; const NMConnectionSerializationFlags dbus_serialization_flags[] = { NM_CONNECTION_SERIALIZE_ALL, NM_CONNECTION_SERIALIZE_WITH_NON_SECRET, NM_CONNECTION_SERIALIZE_WITH_SECRETS, }; - guint dbus_serialization_flags_idx; - gs_unref_object NMConnection *con = NULL; - gs_free_error GError *error = NULL; - gs_free char * tmp_str = NULL; - guint kf_data_idx; - NMSettingConnection * s_con = NULL; - NMSettingWired * s_eth = NULL; - NMSettingWireGuard * s_wg = NULL; + guint dbus_serialization_flags_idx; + gs_unref_object NMConnection *con = NULL; + gs_free_error GError *error = NULL; + gs_free char *tmp_str = NULL; + guint kf_data_idx; + NMSettingConnection *s_con = NULL; + NMSettingWired *s_eth = NULL; + NMSettingWireGuard *s_wg = NULL; union { struct { NMSettingIPConfig *s_6; @@ -3849,8 +3849,8 @@ test_roundtrip_conversion(gconstpointer test_data) /* check that reading any of kf_data_arr yields the same result that we expect. */ for (kf_data_idx = 0; kf_data_idx < kf_data_arr->len; kf_data_idx++) { gs_unref_object NMConnection *con2 = NULL; - NMSettingWireGuard * s_wg2 = NULL; - NMSettingWired * s_eth2 = NULL; + NMSettingWireGuard *s_wg2 = NULL; + NMSettingWired *s_eth2 = NULL; con2 = nmtst_create_connection_from_keyfile(kf_data_arr->pdata[kf_data_idx], "/no/where/file.nmconnection"); @@ -3918,9 +3918,9 @@ test_roundtrip_conversion(gconstpointer test_data) dbus_serialization_flags_idx++) { NMConnectionSerializationFlags flag = dbus_serialization_flags[dbus_serialization_flags_idx]; - gs_unref_variant GVariant *con_var = NULL; - gs_unref_object NMConnection *con2 = NULL; - NMSettingWireGuard * s_wg2 = NULL; + gs_unref_variant GVariant *con_var = NULL; + gs_unref_object NMConnection *con2 = NULL; + NMSettingWireGuard *s_wg2 = NULL; con_var = nm_connection_to_dbus(con, flag); g_assert(g_variant_is_of_type(con_var, NM_VARIANT_TYPE_CONNECTION)); @@ -3963,12 +3963,12 @@ test_roundtrip_conversion(gconstpointer test_data) static NMIPRoutingRule * _rr_from_str_get_impl(const char *str, const char *const *aliases) { - nm_auto_unref_ip_routing_rule NMIPRoutingRule *rr = NULL; - gs_free_error GError * error = NULL; - gboolean vbool; - int addr_family; - int i; - NMIPRoutingRuleAsStringFlags to_string_flags; + nm_auto_unref_ip_routing_rule NMIPRoutingRule *rr = NULL; + gs_free_error GError *error = NULL; + gboolean vbool; + int addr_family; + int i; + NMIPRoutingRuleAsStringFlags to_string_flags; rr = nm_ip_routing_rule_from_string(str, NM_IP_ROUTING_RULE_AS_STRING_FLAGS_VALIDATE, @@ -3985,10 +3985,10 @@ _rr_from_str_get_impl(const char *str, const char *const *aliases) to_string_flags = NM_IP_ROUTING_RULE_AS_STRING_FLAGS_AF_INET6; for (i = 0; TRUE; i++) { - nm_auto_unref_ip_routing_rule NMIPRoutingRule *rr2 = NULL; - gs_free char * str1 = NULL; - gs_unref_variant GVariant *variant1 = NULL; - const char * cstr1; + nm_auto_unref_ip_routing_rule NMIPRoutingRule *rr2 = NULL; + gs_free char *str1 = NULL; + gs_unref_variant GVariant *variant1 = NULL; + const char *cstr1; switch (i) { case 0: @@ -4084,7 +4084,7 @@ test_routing_rule(gconstpointer test_data) nm_auto_unref_ip_routing_rule NMIPRoutingRule *rr1 = NULL; gboolean success; char ifname_buf[16]; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; _rr_from_str("priority 5 from 0.0.0.0 table 1", " from 0.0.0.0 priority 5 lookup 1 "); _rr_from_str("priority 5 from 0.0.0.0/0 table 4"); @@ -4190,7 +4190,7 @@ test_parse_tc_handle(void) G_STMT_START \ { \ gs_free_error GError *_error = NULL; \ - GError ** _perror = nmtst_get_rand_bool() ? &_error : NULL; \ + GError **_perror = nmtst_get_rand_bool() ? &_error : NULL; \ guint32 _v; \ const guint32 _v_exp = (exp); \ \ @@ -4247,12 +4247,12 @@ test_parse_tc_handle(void) static void test_empty_setting(void) { - gs_unref_object NMConnection *con = NULL; - gs_unref_object NMConnection *con2 = NULL; - NMSettingBluetooth * s_bt; - NMSettingGsm * s_gsm; - nm_auto_unref_keyfile GKeyFile *kf = NULL; - gs_free_error GError *error = NULL; + gs_unref_object NMConnection *con = NULL; + gs_unref_object NMConnection *con2 = NULL; + NMSettingBluetooth *s_bt; + NMSettingGsm *s_gsm; + nm_auto_unref_keyfile GKeyFile *kf = NULL; + gs_free_error GError *error = NULL; con = nmtst_create_minimal_connection("bt-empty-gsm", "dca3192a-f2dc-48eb-b806-d0ff788f122c", @@ -4307,7 +4307,7 @@ _PROP_IDX_OWNER(GHashTable *h_property_types, const NMSettInfoPropertType *prope const NMSettInfoSetting *sett_info_settings = nmtst_sett_info_settings(); const NMSettInfoSetting *sis; const NMMetaSettingInfo *msi; - GArray * arr; + GArray *arr; guint idx; NMMetaSettingType meta_type; guint prop_idx; @@ -4341,8 +4341,8 @@ _PROP_IDX_OWNER(GHashTable *h_property_types, const NMSettInfoPropertType *prope static void test_setting_metadata(void) { - const NMSettInfoSetting *sett_info_settings = nmtst_sett_info_settings(); - NMMetaSettingType meta_type; + const NMSettInfoSetting *sett_info_settings = nmtst_sett_info_settings(); + NMMetaSettingType meta_type; gs_unref_hashtable GHashTable *h_property_types = NULL; G_STATIC_ASSERT(_NM_META_SETTING_TYPE_NUM == NM_META_SETTING_TYPE_UNKNOWN); @@ -4351,7 +4351,7 @@ test_setting_metadata(void) g_hash_table_new_full(nm_direct_hash, NULL, NULL, (GDestroyNotify) g_array_unref); for (meta_type = 0; meta_type < _NM_META_SETTING_TYPE_NUM; meta_type++) { - const NMMetaSettingInfo *msi = &nm_meta_setting_infos[meta_type]; + const NMMetaSettingInfo *msi = &nm_meta_setting_infos[meta_type]; nm_auto_unref_gtypeclass NMSettingClass *klass = NULL; GType gtype; @@ -4382,17 +4382,17 @@ test_setting_metadata(void) g_assert(sett_info_settings); for (meta_type = 0; meta_type < _NM_META_SETTING_TYPE_NUM; meta_type++) { - const NMSettInfoSetting *sis = &sett_info_settings[meta_type]; - const NMMetaSettingInfo *msi = &nm_meta_setting_infos[meta_type]; + const NMSettInfoSetting *sis = &sett_info_settings[meta_type]; + const NMMetaSettingInfo *msi = &nm_meta_setting_infos[meta_type]; gs_unref_hashtable GHashTable *h_properties = NULL; GType gtype; - gs_unref_object NMSetting *setting = NULL; - guint prop_idx; - gs_free GParamSpec **property_specs = NULL; - guint n_property_specs; - guint n_param_spec; - guint i; - guint j; + gs_unref_object NMSetting *setting = NULL; + guint prop_idx; + gs_free GParamSpec **property_specs = NULL; + guint n_property_specs; + guint n_param_spec; + guint i; + guint j; g_assert(sis); @@ -4427,9 +4427,11 @@ test_setting_metadata(void) for (prop_idx = 0; prop_idx < sis->property_infos_len; prop_idx++) { const NMSettInfoProperty *sip = &sis->property_infos[prop_idx]; - GArray * property_types_data; + GArray *property_types_data; guint prop_idx_val; gboolean can_set_including_default = FALSE; + gboolean can_have_direct_hook = FALSE; + int n_special_options; g_assert(sip->name); @@ -4489,6 +4491,22 @@ test_setting_metadata(void) g_assert_cmpint(pspec->maximum, <=, (guint64) G_MAXUINT32); + can_set_including_default = TRUE; + } else if (sip->property_type->direct_type == NM_VALUE_TYPE_INT64) { + const GParamSpecInt64 *pspec; + + g_assert(sip->property_type == &nm_sett_info_propert_type_direct_int64); + g_assert(g_variant_type_equal(sip->property_type->dbus_type, "x")); + g_assert(sip->property_type->to_dbus_fcn + == _nm_setting_property_to_dbus_fcn_direct); + g_assert(sip->param_spec); + g_assert(sip->param_spec->value_type == G_TYPE_INT64); + + pspec = NM_G_PARAM_SPEC_CAST_INT64(sip->param_spec); + g_assert_cmpint(pspec->minimum, <=, pspec->maximum); + g_assert_cmpint(pspec->default_value, >=, pspec->minimum); + g_assert_cmpint(pspec->default_value, <=, pspec->maximum); + can_set_including_default = TRUE; } else if (sip->property_type->direct_type == NM_VALUE_TYPE_UINT64) { const GParamSpecUInt64 *pspec; @@ -4555,6 +4573,7 @@ test_setting_metadata(void) g_assert(g_variant_type_equal(sip->property_type->dbus_type, "s")); g_assert(sip->property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_direct); + can_have_direct_hook = TRUE; } g_assert(sip->param_spec); g_assert(sip->param_spec->value_type == G_TYPE_STRING); @@ -4569,6 +4588,13 @@ test_setting_metadata(void) if (sip->direct_set_string_ascii_strdown) g_assert(sip->property_type->direct_type == NM_VALUE_TYPE_STRING); + if (sip->direct_set_string_strip) + g_assert(sip->property_type->direct_type == NM_VALUE_TYPE_STRING); + if (sip->direct_string_is_refstr) { + g_assert(sip->property_type->direct_type == NM_VALUE_TYPE_STRING); + g_assert(sip->param_spec); + g_assert(!NM_FLAGS_HAS(sip->param_spec->flags, NM_SETTING_PARAM_SECRET)); + } if (sip->direct_set_string_mac_address_len != 0) { g_assert(NM_IN_SET(sip->property_type, @@ -4577,10 +4603,38 @@ test_setting_metadata(void) g_assert(sip->property_type->direct_type == NM_VALUE_TYPE_STRING); } - g_assert(((sip->direct_set_string_mac_address_len != 0) - + (!!sip->direct_set_string_ascii_strdown) - + (sip->direct_set_string_ip_address_addr_family != 0)) - <= 1); + if (!can_have_direct_hook) + g_assert(!sip->direct_hook.set_string_fcn); + + n_special_options = (sip->direct_set_string_mac_address_len != 0) + + (!!sip->direct_set_string_strip) + + (!!sip->direct_set_string_ascii_strdown) + + (sip->direct_set_string_ip_address_addr_family != 0) + + (!!sip->direct_string_is_refstr); + + G_STATIC_ASSERT_EXPR(AF_UNSPEC + 1 != 0); + g_assert(NM_IN_SET((int) sip->direct_set_string_ip_address_addr_family, + 0, + AF_UNSPEC + 1, + AF_INET + 1, + AF_INET6 + 1)); + + if (sip->direct_set_string_ip_address_addr_family == 0) + g_assert(!sip->direct_set_string_ip_address_addr_family_map_zero_to_null); + + /* currently, we have no cases where special options are mixed. There is no problem to support + * that, but as it's not needed, don't do it for now. */ + g_assert_cmpint(n_special_options, <=, 1); + + if (n_special_options > 0) { + /* currently, special options are only relevant for string properties. */ + g_assert(sip->property_type->direct_type == NM_VALUE_TYPE_STRING); + } + + if (sip->param_spec && NM_FLAGS_HAS(sip->param_spec->flags, NM_SETTING_PARAM_SECRET)) { + /* Currently, special options are not supported for secrets. */ + g_assert_cmpint(n_special_options, ==, 0); + } if (!sip->property_type->to_dbus_fcn) { /* it's allowed to have no to_dbus_fcn(), to ignore a property. But such @@ -4589,12 +4643,6 @@ test_setting_metadata(void) } else if (sip->property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_gprop) { g_assert(sip->param_spec); switch (sip->property_type->typdata_to_dbus.gprop_type) { - case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_ENUM: - g_assert(g_type_is_a(sip->param_spec->value_type, G_TYPE_ENUM)); - goto check_done; - case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_FLAGS: - g_assert(g_type_is_a(sip->param_spec->value_type, G_TYPE_FLAGS)); - goto check_done; case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_GARRAY_UINT: g_assert(sip->param_spec->value_type == G_TYPE_ARRAY); goto check_done; @@ -4709,9 +4757,10 @@ check_done:; NULL); g_assert(!NM_G_PARAM_SPEC_GET_DEFAULT_STRING(sip->param_spec)); - if (nm_streq(sip->name, NM_SETTING_NAME)) + if (nm_streq(sip->name, NM_SETTING_NAME)) { g_assert_cmpstr(g_value_get_string(&val), ==, msi->setting_name); - else + g_assert(sip->property_type == &nm_sett_info_propert_type_setting_name); + } else g_assert_cmpstr(g_value_get_string(&val), ==, NULL); } @@ -4856,23 +4905,6 @@ check_done:; != 0) continue; - if ((pt == &nm_sett_info_propert_type_plain_i - && pt_2 == &nm_sett_info_propert_type_deprecated_ignore_i) - || (pt_2 == &nm_sett_info_propert_type_plain_i - && pt == &nm_sett_info_propert_type_deprecated_ignore_i) - || (pt == &nm_sett_info_propert_type_plain_u - && pt_2 == &nm_sett_info_propert_type_deprecated_ignore_u) - || (pt_2 == &nm_sett_info_propert_type_plain_u - && pt == &nm_sett_info_propert_type_deprecated_ignore_u)) { - /* These are known to be duplicated. This is the case for - * "gsm.network-type" and plain properties like "802-11-wireless-security.fils" ("i" D-Bus type) - * "gsm.allowed-bands" and plain properties like "802-11-olpc-mesh.channel" ("u" D-Bus type) - * While the content/behaviour of the property types are identical, their purpose - * is different. So allow them. - */ - continue; - } - /* the property-types with same content should all be shared. Here we have two that * are the same content, but different instances. Bug. */ g_error("The identical property type for D-Bus type \"%s\" is used by: %s and %s. " @@ -4892,7 +4924,7 @@ static void test_setting_connection_secondaries_verify(void) { gs_unref_object NMConnection *con = NULL; - NMSettingConnection * s_con; + NMSettingConnection *s_con; guint i_run; guint i_word; @@ -4900,7 +4932,7 @@ test_setting_connection_secondaries_verify(void) nmtst_connection_normalize(con); for (i_run = 0; i_run < 100; i_run++) { - guint word_len = nmtst_get_rand_word_length(NULL); + guint word_len = nmtst_get_rand_word_length(NULL); gs_unref_ptrarray GPtrArray *arr = NULL; gs_unref_ptrarray GPtrArray *arr_norm = NULL; gboolean was_normalized; @@ -4930,10 +4962,10 @@ test_setting_connection_secondaries_verify(void) G_STMT_START \ { \ NMSettingConnection *const _s_con = (s_con); \ - const char *const * _expected = (expected); \ - GArray * _secondaries; \ + const char *const *_expected = (expected); \ + GArray *_secondaries; \ const guint _expected_len = NM_PTRARRAY_LEN(_expected); \ - gs_strfreev char ** _sec_strv = NULL; \ + gs_strfreev char **_sec_strv = NULL; \ guint _i; \ \ g_assert(_expected); \ @@ -5011,8 +5043,8 @@ static void test_6lowpan_1(void) { gs_unref_object NMConnection *con = NULL; - NMSetting6Lowpan * s_6low; - gs_free char * value = NULL; + NMSetting6Lowpan *s_6low; + gs_free char *value = NULL; con = nmtst_create_minimal_connection("test-sec", NULL, NM_SETTING_6LOWPAN_SETTING_NAME, NULL); diff --git a/src/libnm-core-impl/tests/test-settings-defaults.c b/src/libnm-core-impl/tests/test-settings-defaults.c index b9db7107..ade28c53 100644 --- a/src/libnm-core-impl/tests/test-settings-defaults.c +++ b/src/libnm-core-impl/tests/test-settings-defaults.c @@ -27,7 +27,7 @@ test_defaults(GType type, const char *name) { GParamSpec **property_specs; guint n_property_specs; - GObject * setting; + GObject *setting; int i; setting = g_object_new(type, NULL); @@ -39,7 +39,7 @@ test_defaults(GType type, const char *name) GParamSpec *prop_spec = property_specs[i]; GValue value = G_VALUE_INIT; GValue defvalue = G_VALUE_INIT; - char * actual, *expected; + char *actual, *expected; gboolean ok = FALSE; /* Ignore non-fundamental types since they won't really have diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index 93d75e44..d9634b04 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -199,14 +199,14 @@ typedef enum { /*< skip >*/ NM_SETTING_PARSE_FLAGS_ALL = ((_NM_SETTING_PARSE_FLAGS_LAST - 1) << 1) - 1, } NMSettingParseFlags; -gboolean _nm_connection_replace_settings(NMConnection * connection, - GVariant * new_settings, +gboolean _nm_connection_replace_settings(NMConnection *connection, + GVariant *new_settings, NMSettingParseFlags parse_flags, - GError ** error); + GError **error); gpointer _nm_connection_check_main_setting(NMConnection *connection, - const char * setting_name, - GError ** error); + const char *setting_name, + GError **error); typedef struct { struct { @@ -221,7 +221,7 @@ typedef struct { gboolean nm_connection_serialization_options_equal(const NMConnectionSerializationOptions *a, const NMConnectionSerializationOptions *b); -GVariant *nm_connection_to_dbus_full(NMConnection * connection, +GVariant *nm_connection_to_dbus_full(NMConnection *connection, NMConnectionSerializationFlags flags, const NMConnectionSerializationOptions *options); @@ -262,12 +262,12 @@ typedef enum { NMSettingVerifyResult _nm_connection_verify(NMConnection *connection, GError **error); -gboolean _nm_connection_ensure_normalized(NMConnection * connection, +gboolean _nm_connection_ensure_normalized(NMConnection *connection, gboolean allow_modify, - const char * expected_uuid, + const char *expected_uuid, gboolean coerce_uuid, NMConnection **out_connection_clone, - GError ** error); + GError **error); gboolean _nm_connection_remove_setting(NMConnection *connection, GType setting_type); @@ -280,9 +280,9 @@ nm_assert_connection_unchanging(NMConnection *connection) {} #endif -NMConnection *_nm_simple_connection_new_from_dbus(GVariant * dict, +NMConnection *_nm_simple_connection_new_from_dbus(GVariant *dict, NMSettingParseFlags parse_flags, - GError ** error); + GError **error); NMSettingPriority _nm_setting_get_setting_priority(NMSetting *setting); @@ -294,9 +294,9 @@ GHashTable *_nm_setting_option_hash(NMSetting *setting, gboolean create_if_neces void _nm_setting_option_notify(NMSetting *setting, gboolean keys_changed); -guint _nm_setting_option_get_all(NMSetting * setting, +guint _nm_setting_option_get_all(NMSetting *setting, const char *const **out_names, - GVariant *const ** out_values); + GVariant *const **out_values); gboolean _nm_setting_option_clear(NMSetting *setting, const char *optname); @@ -304,7 +304,7 @@ gboolean _nm_setting_option_clear(NMSetting *setting, const char *optname); guint nm_setting_ethtool_init_features( NMSettingEthtool *setting, - NMOptionBool * requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */); + NMOptionBool *requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */); /*****************************************************************************/ @@ -335,7 +335,7 @@ GHashTable *_nm_ip_route_get_attributes(NMIPRoute *route); NMSriovVF *_nm_utils_sriov_vf_from_strparts(const char *index, const char *detail, gboolean ignore_unknown, - GError ** error); + GError **error); gboolean _nm_sriov_vf_attribute_validate_all(const NMSriovVF *vf, GError **error); GPtrArray * @@ -343,23 +343,23 @@ _nm_utils_copy_array(const GPtrArray *array, NMUtilsCopyFunc copy_func, GDestroy GPtrArray *_nm_utils_copy_object_array(const GPtrArray *array); GSList *nm_strv_to_gslist(char **strv, gboolean deep_copy); -char ** _nm_utils_slist_to_strv(const GSList *slist, gboolean deep_copy); +char **_nm_utils_slist_to_strv(const GSList *slist, gboolean deep_copy); GPtrArray *nm_strv_to_ptrarray(char **strv); -char ** _nm_utils_ptrarray_to_strv(const GPtrArray *ptrarray); +char **_nm_utils_ptrarray_to_strv(const GPtrArray *ptrarray); -gboolean _nm_utils_check_file(const char * filename, +gboolean _nm_utils_check_file(const char *filename, gint64 check_owner, NMUtilsCheckFilePredicate check_file, gpointer user_data, - struct stat * out_st, - GError ** error); + struct stat *out_st, + GError **error); -gboolean _nm_utils_check_module_file(const char * name, +gboolean _nm_utils_check_module_file(const char *name, int check_owner, NMUtilsCheckFilePredicate check_file, gpointer user_data, - GError ** error); + GError **error); /*****************************************************************************/ @@ -370,8 +370,8 @@ extern gboolean _nm_utils_is_manager_process; gboolean _nm_dbus_typecheck_response(GVariant *response, const GVariantType *reply_type, GError **error); -gulong _nm_dbus_signal_connect_data(GDBusProxy * proxy, - const char * signal_name, +gulong _nm_dbus_signal_connect_data(GDBusProxy *proxy, + const char *signal_name, const GVariantType *signature, GCallback c_handler, gpointer data, @@ -380,15 +380,15 @@ gulong _nm_dbus_signal_connect_data(GDBusProxy * proxy, #define _nm_dbus_signal_connect(proxy, name, signature, handler, data) \ _nm_dbus_signal_connect_data(proxy, name, signature, handler, data, NULL, (GConnectFlags) 0) -GVariant *_nm_dbus_proxy_call_finish(GDBusProxy * proxy, - GAsyncResult * res, +GVariant *_nm_dbus_proxy_call_finish(GDBusProxy *proxy, + GAsyncResult *res, const GVariantType *reply_type, - GError ** error); + GError **error); -GVariant *_nm_dbus_connection_call_finish(GDBusConnection * dbus_connection, - GAsyncResult * result, +GVariant *_nm_dbus_connection_call_finish(GDBusConnection *dbus_connection, + GAsyncResult *result, const GVariantType *reply_type, - GError ** error); + GError **error); gboolean _nm_dbus_error_has_name(GError *error, const char *dbus_error_name); @@ -398,19 +398,19 @@ char *_nm_utils_ssid_to_utf8(GBytes *ssid); /*****************************************************************************/ -gboolean _nm_vpn_plugin_info_check_file(const char * filename, +gboolean _nm_vpn_plugin_info_check_file(const char *filename, gboolean check_absolute, gboolean do_validate_filename, gint64 check_owner, NMUtilsCheckFilePredicate check_file, gpointer user_data, - GError ** error); + GError **error); const char *_nm_vpn_plugin_info_get_default_dir_etc(void); const char *_nm_vpn_plugin_info_get_default_dir_lib(void); const char *_nm_vpn_plugin_info_get_default_dir_user(void); -GSList *_nm_vpn_plugin_info_list_load_dir(const char * dirname, +GSList *_nm_vpn_plugin_info_list_load_dir(const char *dirname, gboolean do_validate_filename, gint64 check_owner, NMUtilsCheckFilePredicate check_file, @@ -430,9 +430,9 @@ typedef struct { extern const NMUtilsDNSOptionDesc _nm_utils_dns_option_descs[]; -gboolean _nm_utils_dns_option_validate(const char * option, - char ** out_name, - long * out_value, +gboolean _nm_utils_dns_option_validate(const char *option, + char **out_name, + long *out_value, gboolean ipv6, const NMUtilsDNSOptionDesc *option_descs); gssize _nm_utils_dns_option_find_idx(GPtrArray *array, const char *option); @@ -450,24 +450,24 @@ NMUtilsStrStrDictKey *_nm_utils_strstrdictkey_create(const char *v1, const char /*****************************************************************************/ -gboolean _nm_setting_vlan_set_priorities(NMSettingVlan * setting, +gboolean _nm_setting_vlan_set_priorities(NMSettingVlan *setting, NMVlanPriorityMap map, const NMVlanQosMapping *qos_map, guint n_qos_map); -void _nm_setting_vlan_get_priorities(NMSettingVlan * setting, +void _nm_setting_vlan_get_priorities(NMSettingVlan *setting, NMVlanPriorityMap map, NMVlanQosMapping **out_qos_map, - guint * out_n_qos_map); + guint *out_n_qos_map); /*****************************************************************************/ struct ether_addr; -gboolean _nm_utils_generate_mac_address_mask_parse(const char * value, - struct ether_addr * out_mask, +gboolean _nm_utils_generate_mac_address_mask_parse(const char *value, + struct ether_addr *out_mask, struct ether_addr **out_ouis, - gsize * out_ouis_len, - GError ** error); + gsize *out_ouis_len, + GError **error); /*****************************************************************************/ @@ -645,7 +645,7 @@ gboolean nm_ip_routing_rule_get_xifname_bin(const NMIPRoutingRule *self, #define NM_IP_ROUTING_RULE_ATTR_UID_RANGE_END "uid-range-end" NMIPRoutingRule *nm_ip_routing_rule_from_dbus(GVariant *variant, gboolean strict, GError **error); -GVariant * nm_ip_routing_rule_to_dbus(const NMIPRoutingRule *self); +GVariant *nm_ip_routing_rule_to_dbus(const NMIPRoutingRule *self); /*****************************************************************************/ @@ -660,8 +660,6 @@ const NMSettInfoSetting *nmtst_sett_info_settings(void); typedef enum _nm_packed { NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_DEFAULT = 0, - NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_ENUM, - NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_FLAGS, NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_GARRAY_UINT, NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_STRDICT, } NMSettingPropertyToDBusFcnGPropType; @@ -748,8 +746,37 @@ struct _NMSettInfoProperty { GParamSpec *param_spec; + /* We want that our properties follow a small number of "default" types + * and behaviors. For example, we have int32 and string properties, but + * most properties of a certain type should behave in a similar way. + * + * That common behavior is realized via the property_type, which defines + * general behaviors for the property. + * + * Note that we still will need some property-specific additional tweaks. + * Of course, the name and param_spec are per-property. But below there are + * also flags and hooks, that can augment the behavior in the property_type. + * For example, the property_type in general might be of type string, but + * then we might want for some properties that the setter will strip + * whitespace. That is for example express with the flag direct_set_string_strip, + * which now is per-property-info, and no longer per-property-type. + * + * The distinction between those two is fixed. At the most extreme, we could + * move all fields from property_type to NMSettInfoProperty or we could move + * behavioral tweaks into the classes themselves. It's chosen this way so + * that we still have sensible common behaviors (string type), but minor + * tweaks are per property-info (and don't require a separate property-type). */ const NMSettInfoPropertType *property_type; + union { + /* Optional hook for direct string properties, this gets called when setting the string. + * Return whether the value changed. */ + gboolean (*set_string_fcn)(const NMSettInfoSetting *sett_info, + const NMSettInfoProperty *property_info, + NMSetting *setting, + const char *src); + } direct_hook; + /* This only has meaning for direct properties (property_type->direct_type != NM_VALUE_TYPE_UNSPEC). * In that case, this is the offset where _nm_setting_get_private() can find * the direct location. */ @@ -759,16 +786,30 @@ struct _NMSettInfoProperty { * normalize the string via g_ascii_strdown(). */ bool direct_set_string_ascii_strdown : 1; + /* If TRUE, this is a NM_VALUE_TYPE_STRING direct property, and the setter will + * normalize the string via g_strstrip(). */ + bool direct_set_string_strip : 1; + /* If non-zero, this is a NM_VALUE_TYPE_STRING direct property. Actually, it is * a _nm_setting_property_define_direct_mac_address(), and the setter will * call _nm_utils_hwaddr_canonical_or_invalid() on the string, with the specified * MAC address length. */ guint8 direct_set_string_mac_address_len : 5; - /* If non-zero, this is the addr-family (AF_INET/AF_INET6) for normalizing an IP - * address. */ + /* If non-zero, this is the addr-family (AF_UNSPEC/AF_INET/AF_INET6) for normalizing an IP + * address with _nm_utils_ipaddr_canonical_or_invalid(). + * Note that AF_UNSPEC is zero, so to differentiate between zero and AF_UNSPEC + * this value is actually the address family + 1. So either zero or AF_UNSPEC+1, AF_INET+1, + * or AF_INET6+1. */ guint8 direct_set_string_ip_address_addr_family : 5; + /* Only makes sense together with direct_set_string_ip_address_addr_family. This flag + * is passed to _nm_utils_ipaddr_canonical_or_invalid(). */ + bool direct_set_string_ip_address_addr_family_map_zero_to_null : 1; + + /* Whether the string property is implemented as a (downcast) NMRefString. */ + bool direct_string_is_refstr : 1; + /* Usually, properties that are set to the default value for the GParamSpec * are not serialized to GVariant (and NULL is returned by to_dbus_data(). * Set this flag to force always converting the property even if the value @@ -787,8 +828,8 @@ typedef struct { typedef struct { const GVariantType *(*get_variant_type)(const struct _NMSettInfoSetting *sett_info, - const char * name, - GError ** error); + const char *name, + GError **error); } NMSettInfoSettGendata; typedef struct { @@ -848,6 +889,20 @@ _nm_setting_get_private(NMSetting *self, const NMSettInfoSetting *sett_info, gui return ((((char *) ((gpointer) self)) + sett_info->private_offset) + offset); } +static inline gpointer +_nm_setting_get_private_field(NMSetting *self, + const NMSettInfoSetting *sett_info, + const NMSettInfoProperty *prop_info) +{ + nm_assert(sett_info); + nm_assert(prop_info); + nm_assert(prop_info->property_type); + nm_assert(prop_info->property_type->direct_type > NM_VALUE_TYPE_UNSPEC); + nm_assert(sett_info->private_offset != 0 || prop_info->direct_offset != 0); + + return _nm_setting_get_private(self, sett_info, prop_info->direct_offset); +} + static inline const NMSettInfoProperty * _nm_sett_info_property_info_get_sorted(const NMSettInfoSetting *sett_info, guint16 idx) { @@ -861,7 +916,7 @@ _nm_sett_info_property_info_get_sorted(const NMSettInfoSetting *sett_info, guint const NMSettInfoProperty * _nm_sett_info_setting_get_property_info(const NMSettInfoSetting *sett_info, - const char * property_name); + const char *property_name); const NMSettInfoSetting *_nm_setting_class_get_sett_info(NMSettingClass *setting_class); @@ -874,26 +929,26 @@ _nm_setting_class_get_property_info(NMSettingClass *setting_class, const char *p /*****************************************************************************/ -gboolean _nm_setting_compare(NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, +gboolean _nm_setting_compare(NMConnection *con_a, + NMSetting *set_a, + NMConnection *con_b, + NMSetting *set_b, NMSettingCompareFlags flags); -gboolean _nm_setting_diff(NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, +gboolean _nm_setting_diff(NMConnection *con_a, + NMSetting *set_a, + NMConnection *con_b, + NMSetting *set_b, NMSettingCompareFlags flags, gboolean invert_results, - GHashTable ** results); + GHashTable **results); NMSetting8021xCKScheme _nm_setting_802_1x_cert_get_scheme(GBytes *bytes, GError **error); GBytes *_nm_setting_802_1x_cert_value_to_bytes(NMSetting8021xCKScheme scheme, - const guint8 * val_bin, + const guint8 *val_bin, gssize val_len, - GError ** error); + GError **error); /*****************************************************************************/ @@ -936,19 +991,19 @@ _nm_connection_serialize_secrets(NMConnectionSerializationFlags flags, return FALSE; } -void _nm_connection_clear_secrets_by_secret_flags(NMConnection * self, +void _nm_connection_clear_secrets_by_secret_flags(NMConnection *self, NMSettingSecretFlags filter_flags); -GVariant *_nm_connection_for_each_secret(NMConnection * self, - GVariant * secrets, +GVariant *_nm_connection_for_each_secret(NMConnection *self, + GVariant *secrets, gboolean remove_non_secrets, _NMConnectionForEachSecretFunc callback, gpointer callback_data); typedef gboolean (*NMConnectionFindSecretFunc)(NMSettingSecretFlags flags, gpointer user_data); -gboolean _nm_connection_find_secret(NMConnection * self, - GVariant * secrets, +gboolean _nm_connection_find_secret(NMConnection *self, + GVariant *secrets, NMConnectionFindSecretFunc callback, gpointer callback_data); @@ -956,7 +1011,7 @@ gboolean _nm_connection_find_secret(NMConnection * self, gboolean nm_utils_base64secret_normalize(const char *base64_key, gsize required_key_len, - char ** out_base64_key_norm); + char **out_base64_key_norm); /*****************************************************************************/ @@ -977,7 +1032,7 @@ gboolean _nmtst_variant_attribute_spec_assert_sorted(const NMVariantAttributeSpe const NMVariantAttributeSpec * _nm_variant_attribute_spec_find_binary_search(const NMVariantAttributeSpec *const *array, gsize len, - const char * name); + const char *name); /*****************************************************************************/ diff --git a/src/libnm-core-intern/nm-keyfile-internal.h b/src/libnm-core-intern/nm-keyfile-internal.h index d3fd77d2..ecbcedb2 100644 --- a/src/libnm-core-intern/nm-keyfile-internal.h +++ b/src/libnm-core-intern/nm-keyfile-internal.h @@ -26,11 +26,11 @@ #define NM_KEYFILE_CERT_SCHEME_PREFIX_PKCS11 "pkcs11:" #define NM_KEYFILE_CERT_SCHEME_PREFIX_BLOB "data:;base64," -char *nm_keyfile_detect_unqualified_path_scheme(const char * base_dir, +char *nm_keyfile_detect_unqualified_path_scheme(const char *base_dir, gconstpointer pdata, gsize data_len, gboolean consider_exists, - gboolean * out_exists); + gboolean *out_exists); gboolean nm_keyfile_read_ensure_id(NMConnection *connection, const char *fallback_id); @@ -46,8 +46,8 @@ gboolean nm_keyfile_read_ensure_uuid(NMConnection *connection, const char *fallb */ typedef struct { NMKeyfileWarnSeverity severity; - char * message; - const char * fmt; + char *message; + const char *fmt; va_list ap; } NMKeyfileHandlerDataWarn; @@ -69,7 +69,7 @@ struct _NMKeyfileHandlerData { const char *kf_group_name; const char *kf_key; - NMSetting * cur_setting; + NMSetting *cur_setting; const char *cur_property; union { @@ -86,7 +86,7 @@ const char *_nm_keyfile_handler_data_warn_get_message(const NMKeyfileHandlerData char * nm_keyfile_plugin_kf_get_string(GKeyFile *kf, const char *group, const char *key, GError **error); -void nm_keyfile_plugin_kf_set_string(GKeyFile * kf, +void nm_keyfile_plugin_kf_set_string(GKeyFile *kf, const char *group, const char *key, const char *value); diff --git a/src/libnm-core-intern/nm-keyfile-utils.h b/src/libnm-core-intern/nm-keyfile-utils.h index 4dde7029..45741646 100644 --- a/src/libnm-core-intern/nm-keyfile-utils.h +++ b/src/libnm-core-intern/nm-keyfile-utils.h @@ -31,16 +31,16 @@ const char *nm_keyfile_plugin_get_setting_name_for_alias(const char *alias); /*****************************************************************************/ -guint *nm_keyfile_plugin_kf_get_integer_list_uint(GKeyFile * kf, +guint *nm_keyfile_plugin_kf_get_integer_list_uint(GKeyFile *kf, const char *group, const char *key, - gsize * out_length, - GError ** error); -char **nm_keyfile_plugin_kf_get_string_list(GKeyFile * kf, + gsize *out_length, + GError **error); +char **nm_keyfile_plugin_kf_get_string_list(GKeyFile *kf, const char *group, const char *key, - gsize * out_length, - GError ** error); + gsize *out_length, + GError **error); char * nm_keyfile_plugin_kf_get_string(GKeyFile *kf, const char *group, const char *key, GError **error); gboolean @@ -48,23 +48,23 @@ nm_keyfile_plugin_kf_get_boolean(GKeyFile *kf, const char *group, const char *ke char * nm_keyfile_plugin_kf_get_value(GKeyFile *kf, const char *group, const char *key, GError **error); -void nm_keyfile_plugin_kf_set_integer_list_uint8(GKeyFile * kf, - const char * group, - const char * key, +void nm_keyfile_plugin_kf_set_integer_list_uint8(GKeyFile *kf, + const char *group, + const char *key, const guint8 *list, gsize length); -void nm_keyfile_plugin_kf_set_integer_list_uint(GKeyFile * kf, - const char * group, - const char * key, +void nm_keyfile_plugin_kf_set_integer_list_uint(GKeyFile *kf, + const char *group, + const char *key, const guint *list, gsize length); -void nm_keyfile_plugin_kf_set_string_list(GKeyFile * kf, - const char * group, - const char * key, +void nm_keyfile_plugin_kf_set_string_list(GKeyFile *kf, + const char *group, + const char *key, const char *const *list, gsize length); -void nm_keyfile_plugin_kf_set_string(GKeyFile * kf, +void nm_keyfile_plugin_kf_set_string(GKeyFile *kf, const char *group, const char *key, const char *value); @@ -73,14 +73,14 @@ nm_keyfile_plugin_kf_set_boolean(GKeyFile *kf, const char *group, const char *ke void nm_keyfile_plugin_kf_set_value(GKeyFile *kf, const char *group, const char *key, const char *value); -gint64 nm_keyfile_plugin_kf_get_int64(GKeyFile * kf, +gint64 nm_keyfile_plugin_kf_get_int64(GKeyFile *kf, const char *group, const char *key, guint base, gint64 min, gint64 max, gint64 fallback, - GError ** error); + GError **error); char ** nm_keyfile_plugin_kf_get_keys(GKeyFile *kf, const char *group, gsize *out_length, GError **error); diff --git a/src/libnm-core-intern/nm-meta-setting-base-impl.h b/src/libnm-core-intern/nm-meta-setting-base-impl.h index eba1fb96..ea4f85ff 100644 --- a/src/libnm-core-intern/nm-meta-setting-base-impl.h +++ b/src/libnm-core-intern/nm-meta-setting-base-impl.h @@ -73,18 +73,18 @@ typedef struct { const char *(*uri_func)(NMSetting8021x *setting); const char *(*passwd_func)(NMSetting8021x *setting); NMSettingSecretFlags (*pwflag_func)(NMSetting8021x *setting); - gboolean (*set_cert_func)(NMSetting8021x * setting, - const char * value, + gboolean (*set_cert_func)(NMSetting8021x *setting, + const char *value, NMSetting8021xCKScheme scheme, NMSetting8021xCKFormat *out_format, - GError ** error); - gboolean (*set_private_key_func)(NMSetting8021x * setting, - const char * value, - const char * password, + GError **error); + gboolean (*set_private_key_func)(NMSetting8021x *setting, + const char *value, + const char *password, NMSetting8021xCKScheme scheme, NMSetting8021xCKFormat *out_format, - GError ** error); - const char * file_suffix; + GError **error); + const char *file_suffix; NMSetting8021xSchemeType scheme_type; bool is_secret : 1; } NMSetting8021xSchemeVtable; diff --git a/src/libnm-core-public/nm-connection.h b/src/libnm-core-public/nm-connection.h index fb54ce88..081f115e 100644 --- a/src/libnm-core-public/nm-connection.h +++ b/src/libnm-core-public/nm-connection.h @@ -145,31 +145,31 @@ void nm_connection_clear_settings(NMConnection *connection); gboolean nm_connection_compare(NMConnection *a, NMConnection *b, NMSettingCompareFlags flags); -gboolean nm_connection_diff(NMConnection * a, - NMConnection * b, +gboolean nm_connection_diff(NMConnection *a, + NMConnection *b, NMSettingCompareFlags flags, - GHashTable ** out_settings); + GHashTable **out_settings); gboolean nm_connection_verify(NMConnection *connection, GError **error); NM_AVAILABLE_IN_1_2 gboolean nm_connection_verify_secrets(NMConnection *connection, GError **error); gboolean nm_connection_normalize(NMConnection *connection, - GHashTable * parameters, - gboolean * modified, - GError ** error); + GHashTable *parameters, + gboolean *modified, + GError **error); const char *nm_connection_need_secrets(NMConnection *connection, GPtrArray **hints); void nm_connection_clear_secrets(NMConnection *connection); -void nm_connection_clear_secrets_with_flags(NMConnection * connection, +void nm_connection_clear_secrets_with_flags(NMConnection *connection, NMSettingClearSecretsWithFlagsFn func, gpointer user_data); gboolean nm_connection_update_secrets(NMConnection *connection, - const char * setting_name, - GVariant * secrets, - GError ** error); + const char *setting_name, + GVariant *secrets, + GError **error); void nm_connection_set_path(NMConnection *connection, const char *path); @@ -179,7 +179,7 @@ const char *nm_connection_get_interface_name(NMConnection *connection); gboolean nm_connection_is_type(NMConnection *connection, const char *type); -void nm_connection_for_each_setting_value(NMConnection * connection, +void nm_connection_for_each_setting_value(NMConnection *connection, NMSettingValueIterFn func, gpointer user_data); @@ -194,22 +194,22 @@ const char *nm_connection_get_id(NMConnection *connection); const char *nm_connection_get_connection_type(NMConnection *connection); gboolean nm_connection_is_virtual(NMConnection *connection); -char * nm_connection_get_virtual_device_description(NMConnection *connection); - -NMSetting8021x * nm_connection_get_setting_802_1x(NMConnection *connection); -NMSettingBluetooth * nm_connection_get_setting_bluetooth(NMConnection *connection); -NMSettingBond * nm_connection_get_setting_bond(NMConnection *connection); -NMSettingTeam * nm_connection_get_setting_team(NMConnection *connection); -NMSettingTeamPort * nm_connection_get_setting_team_port(NMConnection *connection); -NMSettingBridge * nm_connection_get_setting_bridge(NMConnection *connection); +char *nm_connection_get_virtual_device_description(NMConnection *connection); + +NMSetting8021x *nm_connection_get_setting_802_1x(NMConnection *connection); +NMSettingBluetooth *nm_connection_get_setting_bluetooth(NMConnection *connection); +NMSettingBond *nm_connection_get_setting_bond(NMConnection *connection); +NMSettingTeam *nm_connection_get_setting_team(NMConnection *connection); +NMSettingTeamPort *nm_connection_get_setting_team_port(NMConnection *connection); +NMSettingBridge *nm_connection_get_setting_bridge(NMConnection *connection); NMSettingBridgePort *nm_connection_get_setting_bridge_port(NMConnection *connection); -NMSettingCdma * nm_connection_get_setting_cdma(NMConnection *connection); +NMSettingCdma *nm_connection_get_setting_cdma(NMConnection *connection); NMSettingConnection *nm_connection_get_setting_connection(NMConnection *connection); -NMSettingDcb * nm_connection_get_setting_dcb(NMConnection *connection); +NMSettingDcb *nm_connection_get_setting_dcb(NMConnection *connection); NM_AVAILABLE_IN_1_8 -NMSettingDummy * nm_connection_get_setting_dummy(NMConnection *connection); -NMSettingGeneric * nm_connection_get_setting_generic(NMConnection *connection); -NMSettingGsm * nm_connection_get_setting_gsm(NMConnection *connection); +NMSettingDummy *nm_connection_get_setting_dummy(NMConnection *connection); +NMSettingGeneric *nm_connection_get_setting_generic(NMConnection *connection); +NMSettingGsm *nm_connection_get_setting_gsm(NMConnection *connection); NMSettingInfiniband *nm_connection_get_setting_infiniband(NMConnection *connection); NM_AVAILABLE_IN_1_2 NMSettingIPTunnel *nm_connection_get_setting_ip_tunnel(NMConnection *connection); @@ -218,31 +218,31 @@ NMSettingIPConfig *nm_connection_get_setting_ip6_config(NMConnection *connection NM_AVAILABLE_IN_1_6 NMSettingMacsec *nm_connection_get_setting_macsec(NMConnection *connection); NM_AVAILABLE_IN_1_2 -NMSettingMacvlan * nm_connection_get_setting_macvlan(NMConnection *connection); +NMSettingMacvlan *nm_connection_get_setting_macvlan(NMConnection *connection); NMSettingOlpcMesh *nm_connection_get_setting_olpc_mesh(NMConnection *connection); NM_AVAILABLE_IN_1_10 NMSettingOvsBridge *nm_connection_get_setting_ovs_bridge(NMConnection *connection); NM_AVAILABLE_IN_1_10 NMSettingOvsInterface *nm_connection_get_setting_ovs_interface(NMConnection *connection); -NMSettingOvsPatch * nm_connection_get_setting_ovs_patch(NMConnection *connection); +NMSettingOvsPatch *nm_connection_get_setting_ovs_patch(NMConnection *connection); NM_AVAILABLE_IN_1_10 NMSettingOvsPort *nm_connection_get_setting_ovs_port(NMConnection *connection); -NMSettingPpp * nm_connection_get_setting_ppp(NMConnection *connection); -NMSettingPppoe * nm_connection_get_setting_pppoe(NMConnection *connection); +NMSettingPpp *nm_connection_get_setting_ppp(NMConnection *connection); +NMSettingPppoe *nm_connection_get_setting_pppoe(NMConnection *connection); NM_AVAILABLE_IN_1_6 -NMSettingProxy * nm_connection_get_setting_proxy(NMConnection *connection); +NMSettingProxy *nm_connection_get_setting_proxy(NMConnection *connection); NMSettingSerial *nm_connection_get_setting_serial(NMConnection *connection); NM_AVAILABLE_IN_1_12 NMSettingTCConfig *nm_connection_get_setting_tc_config(NMConnection *connection); NM_AVAILABLE_IN_1_2 -NMSettingTun * nm_connection_get_setting_tun(NMConnection *connection); -NMSettingVpn * nm_connection_get_setting_vpn(NMConnection *connection); -NMSettingWimax * nm_connection_get_setting_wimax(NMConnection *connection); -NMSettingAdsl * nm_connection_get_setting_adsl(NMConnection *connection); -NMSettingWired * nm_connection_get_setting_wired(NMConnection *connection); -NMSettingWireless * nm_connection_get_setting_wireless(NMConnection *connection); +NMSettingTun *nm_connection_get_setting_tun(NMConnection *connection); +NMSettingVpn *nm_connection_get_setting_vpn(NMConnection *connection); +NMSettingWimax *nm_connection_get_setting_wimax(NMConnection *connection); +NMSettingAdsl *nm_connection_get_setting_adsl(NMConnection *connection); +NMSettingWired *nm_connection_get_setting_wired(NMConnection *connection); +NMSettingWireless *nm_connection_get_setting_wireless(NMConnection *connection); NMSettingWirelessSecurity *nm_connection_get_setting_wireless_security(NMConnection *connection); -NMSettingVlan * nm_connection_get_setting_vlan(NMConnection *connection); +NMSettingVlan *nm_connection_get_setting_vlan(NMConnection *connection); NM_AVAILABLE_IN_1_2 NMSettingVxlan *nm_connection_get_setting_vxlan(NMConnection *connection); diff --git a/src/libnm-core-public/nm-dbus-interface.h b/src/libnm-core-public/nm-dbus-interface.h index 7fd228ca..fe2a6c09 100644 --- a/src/libnm-core-public/nm-dbus-interface.h +++ b/src/libnm-core-public/nm-dbus-interface.h @@ -428,6 +428,7 @@ typedef enum { /*< flags >*/ * @NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS: modem supports at least one of GSM, * GPRS, EDGE, UMTS, HSDPA, HSUPA, or HSPA+ packet switched data capability * @NM_DEVICE_MODEM_CAPABILITY_LTE: modem has LTE data capability + * @NM_DEVICE_MODEM_CAPABILITY_5GNR: modem has 5GNR data capability (Since: 1.36) * * #NMDeviceModemCapabilities values indicate the generic radio access * technology families a modem device supports. For more information on the @@ -440,7 +441,10 @@ typedef enum { /*< flags >*/ NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO = 0x00000002, NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS = 0x00000004, NM_DEVICE_MODEM_CAPABILITY_LTE = 0x00000008, + NM_DEVICE_MODEM_CAPABILITY_5GNR = 0x00000040, } NMDeviceModemCapabilities; +/* Note: the numeric values of NMDeviceModemCapabilities must be identical to the values + * in MMModemCapability. See the G_STATIC_ASSERT() in nm-modem-broadband.c's get_capabilities(). */ /** * NMWimaxNspNetworkType: diff --git a/src/libnm-core-public/nm-dbus-types.xml b/src/libnm-core-public/nm-dbus-types.xml index c4b59b45..fa5b175b 100644 --- a/src/libnm-core-public/nm-dbus-types.xml +++ b/src/libnm-core-public/nm-dbus-types.xml @@ -722,6 +722,11 @@ = 0x00000008 modem has LTE data capability + + NM_DEVICE_MODEM_CAPABILITY_5GNR + = 0x00000040 + modem has 5GNR data capability (Since: 1.36) + diff --git a/src/libnm-core-public/nm-keyfile.h b/src/libnm-core-public/nm-keyfile.h index e298aae8..8f8b1f1b 100644 --- a/src/libnm-core-public/nm-keyfile.h +++ b/src/libnm-core-public/nm-keyfile.h @@ -71,19 +71,19 @@ typedef struct _NMKeyfileHandlerData NMKeyfileHandlerData; * * Since: 1.30 */ -typedef gboolean (*NMKeyfileReadHandler)(GKeyFile * keyfile, - NMConnection * connection, +typedef gboolean (*NMKeyfileReadHandler)(GKeyFile *keyfile, + NMConnection *connection, NMKeyfileHandlerType handler_type, NMKeyfileHandlerData *handler_data, - void * user_data); + void *user_data); NM_AVAILABLE_IN_1_30 -NMConnection *nm_keyfile_read(GKeyFile * keyfile, - const char * base_dir, +NMConnection *nm_keyfile_read(GKeyFile *keyfile, + const char *base_dir, NMKeyfileHandlerFlags handler_flags, NMKeyfileReadHandler handler, - void * user_data, - GError ** error); + void *user_data, + GError **error); /** * NMKeyfileWriteHandler: @@ -112,18 +112,18 @@ NMConnection *nm_keyfile_read(GKeyFile * keyfile, * * Since: 1.30 */ -typedef gboolean (*NMKeyfileWriteHandler)(NMConnection * connection, - GKeyFile * keyfile, +typedef gboolean (*NMKeyfileWriteHandler)(NMConnection *connection, + GKeyFile *keyfile, NMKeyfileHandlerType handler_type, NMKeyfileHandlerData *handler_data, - void * user_data); + void *user_data); NM_AVAILABLE_IN_1_30 -GKeyFile *nm_keyfile_write(NMConnection * connection, +GKeyFile *nm_keyfile_write(NMConnection *connection, NMKeyfileHandlerFlags handler_flags, NMKeyfileWriteHandler handler, - void * user_data, - GError ** error); + void *user_data, + GError **error); /*****************************************************************************/ @@ -132,10 +132,10 @@ void nm_keyfile_handler_data_fail_with_error(NMKeyfileHandlerData *handler_data, NM_AVAILABLE_IN_1_30 void nm_keyfile_handler_data_get_context(const NMKeyfileHandlerData *handler_data, - const char ** out_kf_group_name, - const char ** out_kf_key_name, - NMSetting ** out_cur_setting, - const char ** out_cur_property_name); + const char **out_kf_group_name, + const char **out_kf_key_name, + NMSetting **out_cur_setting, + const char **out_cur_property_name); /** * NMKeyfileWarnSeverity: @@ -157,8 +157,8 @@ typedef enum { NM_AVAILABLE_IN_1_30 void nm_keyfile_handler_data_warn_get(const NMKeyfileHandlerData *handler_data, - const char ** out_message, - NMKeyfileWarnSeverity * out_severity); + const char **out_message, + NMKeyfileWarnSeverity *out_severity); G_END_DECLS diff --git a/src/libnm-core-public/nm-setting-8021x.h b/src/libnm-core-public/nm-setting-8021x.h index f9ebdd1c..2bd089da 100644 --- a/src/libnm-core-public/nm-setting-8021x.h +++ b/src/libnm-core-public/nm-setting-8021x.h @@ -192,15 +192,15 @@ const char *nm_setting_802_1x_get_ca_path(NMSetting8021x *setting); const char *nm_setting_802_1x_get_phase2_ca_path(NMSetting8021x *setting); NMSetting8021xCKScheme nm_setting_802_1x_get_ca_cert_scheme(NMSetting8021x *setting); -GBytes * nm_setting_802_1x_get_ca_cert_blob(NMSetting8021x *setting); -const char * nm_setting_802_1x_get_ca_cert_path(NMSetting8021x *setting); +GBytes *nm_setting_802_1x_get_ca_cert_blob(NMSetting8021x *setting); +const char *nm_setting_802_1x_get_ca_cert_path(NMSetting8021x *setting); NM_AVAILABLE_IN_1_6 const char *nm_setting_802_1x_get_ca_cert_uri(NMSetting8021x *setting); -gboolean nm_setting_802_1x_set_ca_cert(NMSetting8021x * setting, - const char * value, +gboolean nm_setting_802_1x_set_ca_cert(NMSetting8021x *setting, + const char *value, NMSetting8021xCKScheme scheme, NMSetting8021xCKFormat *out_format, - GError ** error); + GError **error); NM_AVAILABLE_IN_1_8 const char *nm_setting_802_1x_get_ca_cert_password(NMSetting8021x *setting); @@ -212,10 +212,10 @@ const char *nm_setting_802_1x_get_subject_match(NMSetting8021x *setting); guint32 nm_setting_802_1x_get_num_altsubject_matches(NMSetting8021x *setting); const char *nm_setting_802_1x_get_altsubject_match(NMSetting8021x *setting, guint32 i); gboolean nm_setting_802_1x_add_altsubject_match(NMSetting8021x *setting, - const char * altsubject_match); + const char *altsubject_match); void nm_setting_802_1x_remove_altsubject_match(NMSetting8021x *setting, guint32 i); gboolean nm_setting_802_1x_remove_altsubject_match_by_value(NMSetting8021x *setting, - const char * altsubject_match); + const char *altsubject_match); void nm_setting_802_1x_clear_altsubject_matches(NMSetting8021x *setting); NM_AVAILABLE_IN_1_2 const char *nm_setting_802_1x_get_domain_suffix_match(NMSetting8021x *setting); @@ -224,15 +224,15 @@ NM_AVAILABLE_IN_1_24 const char *nm_setting_802_1x_get_domain_match(NMSetting8021x *setting); NMSetting8021xCKScheme nm_setting_802_1x_get_client_cert_scheme(NMSetting8021x *setting); -GBytes * nm_setting_802_1x_get_client_cert_blob(NMSetting8021x *setting); -const char * nm_setting_802_1x_get_client_cert_path(NMSetting8021x *setting); +GBytes *nm_setting_802_1x_get_client_cert_blob(NMSetting8021x *setting); +const char *nm_setting_802_1x_get_client_cert_path(NMSetting8021x *setting); NM_AVAILABLE_IN_1_6 const char *nm_setting_802_1x_get_client_cert_uri(NMSetting8021x *setting); -gboolean nm_setting_802_1x_set_client_cert(NMSetting8021x * setting, - const char * value, +gboolean nm_setting_802_1x_set_client_cert(NMSetting8021x *setting, + const char *value, NMSetting8021xCKScheme scheme, NMSetting8021xCKFormat *out_format, - GError ** error); + GError **error); NM_AVAILABLE_IN_1_8 const char *nm_setting_802_1x_get_client_cert_password(NMSetting8021x *setting); @@ -250,15 +250,15 @@ const char *nm_setting_802_1x_get_phase2_auth(NMSetting8021x *setting); const char *nm_setting_802_1x_get_phase2_autheap(NMSetting8021x *setting); NMSetting8021xCKScheme nm_setting_802_1x_get_phase2_ca_cert_scheme(NMSetting8021x *setting); -GBytes * nm_setting_802_1x_get_phase2_ca_cert_blob(NMSetting8021x *setting); -const char * nm_setting_802_1x_get_phase2_ca_cert_path(NMSetting8021x *setting); +GBytes *nm_setting_802_1x_get_phase2_ca_cert_blob(NMSetting8021x *setting); +const char *nm_setting_802_1x_get_phase2_ca_cert_path(NMSetting8021x *setting); NM_AVAILABLE_IN_1_6 const char *nm_setting_802_1x_get_phase2_ca_cert_uri(NMSetting8021x *setting); -gboolean nm_setting_802_1x_set_phase2_ca_cert(NMSetting8021x * setting, - const char * value, +gboolean nm_setting_802_1x_set_phase2_ca_cert(NMSetting8021x *setting, + const char *value, NMSetting8021xCKScheme scheme, NMSetting8021xCKFormat *out_format, - GError ** error); + GError **error); NM_AVAILABLE_IN_1_8 const char *nm_setting_802_1x_get_phase2_ca_cert_password(NMSetting8021x *setting); @@ -270,11 +270,11 @@ const char *nm_setting_802_1x_get_phase2_subject_match(NMSetting8021x *setting); guint32 nm_setting_802_1x_get_num_phase2_altsubject_matches(NMSetting8021x *setting); const char *nm_setting_802_1x_get_phase2_altsubject_match(NMSetting8021x *setting, guint32 i); gboolean nm_setting_802_1x_add_phase2_altsubject_match(NMSetting8021x *setting, - const char * phase2_altsubject_match); + const char *phase2_altsubject_match); void nm_setting_802_1x_remove_phase2_altsubject_match(NMSetting8021x *setting, guint32 i); gboolean nm_setting_802_1x_remove_phase2_altsubject_match_by_value(NMSetting8021x *setting, - const char * phase2_altsubject_match); + const char *phase2_altsubject_match); void nm_setting_802_1x_clear_phase2_altsubject_matches(NMSetting8021x *setting); NM_AVAILABLE_IN_1_2 const char *nm_setting_802_1x_get_phase2_domain_suffix_match(NMSetting8021x *setting); @@ -283,15 +283,15 @@ NM_AVAILABLE_IN_1_24 const char *nm_setting_802_1x_get_phase2_domain_match(NMSetting8021x *setting); NMSetting8021xCKScheme nm_setting_802_1x_get_phase2_client_cert_scheme(NMSetting8021x *setting); -GBytes * nm_setting_802_1x_get_phase2_client_cert_blob(NMSetting8021x *setting); -const char * nm_setting_802_1x_get_phase2_client_cert_path(NMSetting8021x *setting); +GBytes *nm_setting_802_1x_get_phase2_client_cert_blob(NMSetting8021x *setting); +const char *nm_setting_802_1x_get_phase2_client_cert_path(NMSetting8021x *setting); NM_AVAILABLE_IN_1_6 const char *nm_setting_802_1x_get_phase2_client_cert_uri(NMSetting8021x *setting); -gboolean nm_setting_802_1x_set_phase2_client_cert(NMSetting8021x * setting, - const char * value, +gboolean nm_setting_802_1x_set_phase2_client_cert(NMSetting8021x *setting, + const char *value, NMSetting8021xCKScheme scheme, NMSetting8021xCKFormat *out_format, - GError ** error); + GError **error); NM_AVAILABLE_IN_1_8 const char *nm_setting_802_1x_get_phase2_client_cert_password(NMSetting8021x *setting); @@ -299,41 +299,41 @@ NM_AVAILABLE_IN_1_8 NMSettingSecretFlags nm_setting_802_1x_get_phase2_client_cert_password_flags(NMSetting8021x *setting); -const char * nm_setting_802_1x_get_password(NMSetting8021x *setting); +const char *nm_setting_802_1x_get_password(NMSetting8021x *setting); NMSettingSecretFlags nm_setting_802_1x_get_password_flags(NMSetting8021x *setting); -GBytes * nm_setting_802_1x_get_password_raw(NMSetting8021x *setting); +GBytes *nm_setting_802_1x_get_password_raw(NMSetting8021x *setting); NMSettingSecretFlags nm_setting_802_1x_get_password_raw_flags(NMSetting8021x *setting); -const char * nm_setting_802_1x_get_pin(NMSetting8021x *setting); +const char *nm_setting_802_1x_get_pin(NMSetting8021x *setting); NMSettingSecretFlags nm_setting_802_1x_get_pin_flags(NMSetting8021x *setting); NMSetting8021xCKScheme nm_setting_802_1x_get_private_key_scheme(NMSetting8021x *setting); -GBytes * nm_setting_802_1x_get_private_key_blob(NMSetting8021x *setting); -const char * nm_setting_802_1x_get_private_key_path(NMSetting8021x *setting); +GBytes *nm_setting_802_1x_get_private_key_blob(NMSetting8021x *setting); +const char *nm_setting_802_1x_get_private_key_path(NMSetting8021x *setting); NM_AVAILABLE_IN_1_6 -const char * nm_setting_802_1x_get_private_key_uri(NMSetting8021x *setting); -gboolean nm_setting_802_1x_set_private_key(NMSetting8021x * setting, - const char * value, - const char * password, +const char *nm_setting_802_1x_get_private_key_uri(NMSetting8021x *setting); +gboolean nm_setting_802_1x_set_private_key(NMSetting8021x *setting, + const char *value, + const char *password, NMSetting8021xCKScheme scheme, NMSetting8021xCKFormat *out_format, - GError ** error); -const char * nm_setting_802_1x_get_private_key_password(NMSetting8021x *setting); + GError **error); +const char *nm_setting_802_1x_get_private_key_password(NMSetting8021x *setting); NMSettingSecretFlags nm_setting_802_1x_get_private_key_password_flags(NMSetting8021x *setting); NMSetting8021xCKFormat nm_setting_802_1x_get_private_key_format(NMSetting8021x *setting); NMSetting8021xCKScheme nm_setting_802_1x_get_phase2_private_key_scheme(NMSetting8021x *setting); -GBytes * nm_setting_802_1x_get_phase2_private_key_blob(NMSetting8021x *setting); -const char * nm_setting_802_1x_get_phase2_private_key_path(NMSetting8021x *setting); +GBytes *nm_setting_802_1x_get_phase2_private_key_blob(NMSetting8021x *setting); +const char *nm_setting_802_1x_get_phase2_private_key_path(NMSetting8021x *setting); NM_AVAILABLE_IN_1_6 const char *nm_setting_802_1x_get_phase2_private_key_uri(NMSetting8021x *setting); -gboolean nm_setting_802_1x_set_phase2_private_key(NMSetting8021x * setting, - const char * value, - const char * password, +gboolean nm_setting_802_1x_set_phase2_private_key(NMSetting8021x *setting, + const char *value, + const char *password, NMSetting8021xCKScheme scheme, NMSetting8021xCKFormat *out_format, - GError ** error); + GError **error); const char *nm_setting_802_1x_get_phase2_private_key_password(NMSetting8021x *setting); NMSettingSecretFlags nm_setting_802_1x_get_phase2_private_key_password_flags(NMSetting8021x *setting); diff --git a/src/libnm-core-public/nm-setting-adsl.h b/src/libnm-core-public/nm-setting-adsl.h index 8c584fed..1c8c56a5 100644 --- a/src/libnm-core-public/nm-setting-adsl.h +++ b/src/libnm-core-public/nm-setting-adsl.h @@ -45,11 +45,11 @@ typedef struct _NMSettingAdslClass NMSettingAdslClass; GType nm_setting_adsl_get_type(void); -NMSetting * nm_setting_adsl_new(void); -const char * nm_setting_adsl_get_username(NMSettingAdsl *setting); -const char * nm_setting_adsl_get_password(NMSettingAdsl *setting); -const char * nm_setting_adsl_get_protocol(NMSettingAdsl *setting); -const char * nm_setting_adsl_get_encapsulation(NMSettingAdsl *setting); +NMSetting *nm_setting_adsl_new(void); +const char *nm_setting_adsl_get_username(NMSettingAdsl *setting); +const char *nm_setting_adsl_get_password(NMSettingAdsl *setting); +const char *nm_setting_adsl_get_protocol(NMSettingAdsl *setting); +const char *nm_setting_adsl_get_encapsulation(NMSettingAdsl *setting); guint32 nm_setting_adsl_get_vpi(NMSettingAdsl *setting); guint32 nm_setting_adsl_get_vci(NMSettingAdsl *setting); NMSettingSecretFlags nm_setting_adsl_get_password_flags(NMSettingAdsl *setting); diff --git a/src/libnm-core-public/nm-setting-bluetooth.h b/src/libnm-core-public/nm-setting-bluetooth.h index 6388430a..613005c9 100644 --- a/src/libnm-core-public/nm-setting-bluetooth.h +++ b/src/libnm-core-public/nm-setting-bluetooth.h @@ -59,7 +59,7 @@ typedef struct _NMSettingBluetoothClass NMSettingBluetoothClass; GType nm_setting_bluetooth_get_type(void); -NMSetting * nm_setting_bluetooth_new(void); +NMSetting *nm_setting_bluetooth_new(void); const char *nm_setting_bluetooth_get_bdaddr(NMSettingBluetooth *setting); const char *nm_setting_bluetooth_get_connection_type(NMSettingBluetooth *setting); diff --git a/src/libnm-core-public/nm-setting-bond.h b/src/libnm-core-public/nm-setting-bond.h index e819b4e1..ed44abbf 100644 --- a/src/libnm-core-public/nm-setting-bond.h +++ b/src/libnm-core-public/nm-setting-bond.h @@ -62,12 +62,12 @@ typedef struct _NMSettingBondClass NMSettingBondClass; GType nm_setting_bond_get_type(void); -NMSetting * nm_setting_bond_new(void); +NMSetting *nm_setting_bond_new(void); guint32 nm_setting_bond_get_num_options(NMSettingBond *setting); gboolean nm_setting_bond_get_option(NMSettingBond *setting, guint32 idx, - const char ** out_name, - const char ** out_value); + const char **out_name, + const char **out_value); const char *nm_setting_bond_get_option_by_name(NMSettingBond *setting, const char *name); gboolean nm_setting_bond_add_option(NMSettingBond *setting, const char *name, const char *value); gboolean nm_setting_bond_remove_option(NMSettingBond *setting, const char *name); diff --git a/src/libnm-core-public/nm-setting-cdma.h b/src/libnm-core-public/nm-setting-cdma.h index 1378f170..9b2e5ed7 100644 --- a/src/libnm-core-public/nm-setting-cdma.h +++ b/src/libnm-core-public/nm-setting-cdma.h @@ -37,10 +37,10 @@ typedef struct _NMSettingCdmaClass NMSettingCdmaClass; GType nm_setting_cdma_get_type(void); -NMSetting * nm_setting_cdma_new(void); -const char * nm_setting_cdma_get_number(NMSettingCdma *setting); -const char * nm_setting_cdma_get_username(NMSettingCdma *setting); -const char * nm_setting_cdma_get_password(NMSettingCdma *setting); +NMSetting *nm_setting_cdma_new(void); +const char *nm_setting_cdma_get_number(NMSettingCdma *setting); +const char *nm_setting_cdma_get_username(NMSettingCdma *setting); +const char *nm_setting_cdma_get_password(NMSettingCdma *setting); NMSettingSecretFlags nm_setting_cdma_get_password_flags(NMSettingCdma *setting); NM_AVAILABLE_IN_1_8 diff --git a/src/libnm-core-public/nm-setting-connection.h b/src/libnm-core-public/nm-setting-connection.h index 54fc7929..83b5fd34 100644 --- a/src/libnm-core-public/nm-setting-connection.h +++ b/src/libnm-core-public/nm-setting-connection.h @@ -150,7 +150,7 @@ typedef struct _NMSettingConnectionClass NMSettingConnectionClass; GType nm_setting_connection_get_type(void); -NMSetting * nm_setting_connection_new(void); +NMSetting *nm_setting_connection_new(void); const char *nm_setting_connection_get_id(NMSettingConnection *setting); const char *nm_setting_connection_get_uuid(NMSettingConnection *setting); NM_AVAILABLE_IN_1_4 @@ -169,21 +169,21 @@ gboolean nm_setting_connection_get_read_only(NMSettingConnection guint32 nm_setting_connection_get_num_permissions(NMSettingConnection *setting); gboolean nm_setting_connection_get_permission(NMSettingConnection *setting, guint32 idx, - const char ** out_ptype, - const char ** out_pitem, - const char ** out_detail); + const char **out_ptype, + const char **out_pitem, + const char **out_detail); const char *nm_setting_connection_get_zone(NMSettingConnection *setting); gboolean nm_setting_connection_permissions_user_allowed(NMSettingConnection *setting, - const char * uname); + const char *uname); gboolean nm_setting_connection_add_permission(NMSettingConnection *setting, - const char * ptype, - const char * pitem, - const char * detail); + const char *ptype, + const char *pitem, + const char *detail); void nm_setting_connection_remove_permission(NMSettingConnection *setting, guint32 idx); gboolean nm_setting_connection_remove_permission_by_value(NMSettingConnection *setting, - const char * ptype, - const char * pitem, - const char * detail); + const char *ptype, + const char *pitem, + const char *detail); const char *nm_setting_connection_get_master(NMSettingConnection *setting); gboolean nm_setting_connection_is_slave_type(NMSettingConnection *setting, const char *type); @@ -197,7 +197,7 @@ const char *nm_setting_connection_get_secondary(NMSettingConnection *setting, gu gboolean nm_setting_connection_add_secondary(NMSettingConnection *setting, const char *sec_uuid); void nm_setting_connection_remove_secondary(NMSettingConnection *setting, guint32 idx); gboolean nm_setting_connection_remove_secondary_by_value(NMSettingConnection *setting, - const char * sec_uuid); + const char *sec_uuid); guint32 nm_setting_connection_get_gateway_ping_timeout(NMSettingConnection *setting); NM_AVAILABLE_IN_1_2 diff --git a/src/libnm-core-public/nm-setting-dcb.h b/src/libnm-core-public/nm-setting-dcb.h index 53786213..ba702bd7 100644 --- a/src/libnm-core-public/nm-setting-dcb.h +++ b/src/libnm-core-public/nm-setting-dcb.h @@ -85,7 +85,7 @@ NMSetting *nm_setting_dcb_new(void); NMSettingDcbFlags nm_setting_dcb_get_app_fcoe_flags(NMSettingDcb *setting); int nm_setting_dcb_get_app_fcoe_priority(NMSettingDcb *setting); -const char * nm_setting_dcb_get_app_fcoe_mode(NMSettingDcb *setting); +const char *nm_setting_dcb_get_app_fcoe_mode(NMSettingDcb *setting); NMSettingDcbFlags nm_setting_dcb_get_app_iscsi_flags(NMSettingDcb *setting); int nm_setting_dcb_get_app_iscsi_priority(NMSettingDcb *setting); diff --git a/src/libnm-core-public/nm-setting-infiniband.h b/src/libnm-core-public/nm-setting-infiniband.h index 44f30839..313b2087 100644 --- a/src/libnm-core-public/nm-setting-infiniband.h +++ b/src/libnm-core-public/nm-setting-infiniband.h @@ -38,7 +38,7 @@ typedef struct _NMSettingInfinibandClass NMSettingInfinibandClass; GType nm_setting_infiniband_get_type(void); -NMSetting * nm_setting_infiniband_new(void); +NMSetting *nm_setting_infiniband_new(void); const char *nm_setting_infiniband_get_mac_address(NMSettingInfiniband *setting); guint32 nm_setting_infiniband_get_mtu(NMSettingInfiniband *setting); const char *nm_setting_infiniband_get_transport_mode(NMSettingInfiniband *setting); diff --git a/src/libnm-core-public/nm-setting-ip-config.h b/src/libnm-core-public/nm-setting-ip-config.h index 126c4c11..6a19bdb3 100644 --- a/src/libnm-core-public/nm-setting-ip-config.h +++ b/src/libnm-core-public/nm-setting-ip-config.h @@ -61,7 +61,7 @@ void nm_ip_address_set_address_binary(NMIPAddress *address, gconstpointer guint nm_ip_address_get_prefix(NMIPAddress *address); void nm_ip_address_set_prefix(NMIPAddress *address, guint prefix); -char ** nm_ip_address_get_attribute_names(NMIPAddress *address); +char **nm_ip_address_get_attribute_names(NMIPAddress *address); GVariant *nm_ip_address_get_attribute(NMIPAddress *address, const char *name); void nm_ip_address_set_attribute(NMIPAddress *address, const char *name, GVariant *value); @@ -74,13 +74,13 @@ NMIPRoute *nm_ip_route_new(int family, guint prefix, const char *next_hop, gint64 metric, - GError ** error); + GError **error); NMIPRoute *nm_ip_route_new_binary(int family, gconstpointer dest, guint prefix, gconstpointer next_hop, gint64 metric, - GError ** error); + GError **error); void nm_ip_route_ref(NMIPRoute *route); void nm_ip_route_unref(NMIPRoute *route); @@ -111,17 +111,17 @@ void nm_ip_route_set_next_hop_binary(NMIPRoute *route, gconstpointer next gint64 nm_ip_route_get_metric(NMIPRoute *route); void nm_ip_route_set_metric(NMIPRoute *route, gint64 metric); -char ** nm_ip_route_get_attribute_names(NMIPRoute *route); +char **nm_ip_route_get_attribute_names(NMIPRoute *route); GVariant *nm_ip_route_get_attribute(NMIPRoute *route, const char *name); void nm_ip_route_set_attribute(NMIPRoute *route, const char *name, GVariant *value); NM_AVAILABLE_IN_1_8 const NMVariantAttributeSpec *const *nm_ip_route_get_variant_attribute_spec(void); NM_AVAILABLE_IN_1_8 gboolean nm_ip_route_attribute_validate(const char *name, - GVariant * value, + GVariant *value, int family, - gboolean * known, - GError ** error); + gboolean *known, + GError **error); #define NM_IP_ROUTE_ATTRIBUTE_CWND "cwnd" #define NM_IP_ROUTE_ATTRIBUTE_FROM "from" @@ -250,8 +250,8 @@ void nm_ip_routing_rule_set_suppress_prefixlength(NMIPRoutingRule *self, NM_AVAILABLE_IN_1_34 gboolean nm_ip_routing_rule_get_uid_range(const NMIPRoutingRule *self, - guint32 * out_range_start, - guint32 * out_range_end); + guint32 *out_range_start, + guint32 *out_range_end); NM_AVAILABLE_IN_1_34 void nm_ip_routing_rule_set_uid_range(NMIPRoutingRule *self, guint32 uid_range_start, @@ -286,16 +286,16 @@ typedef enum { /*< flags >*/ } NMIPRoutingRuleAsStringFlags; NM_AVAILABLE_IN_1_18 -NMIPRoutingRule *nm_ip_routing_rule_from_string(const char * str, +NMIPRoutingRule *nm_ip_routing_rule_from_string(const char *str, NMIPRoutingRuleAsStringFlags to_string_flags, - GHashTable * extra_args, - GError ** error); + GHashTable *extra_args, + GError **error); NM_AVAILABLE_IN_1_18 -char *nm_ip_routing_rule_to_string(const NMIPRoutingRule * self, +char *nm_ip_routing_rule_to_string(const NMIPRoutingRule *self, NMIPRoutingRuleAsStringFlags to_string_flags, - GHashTable * extra_args, - GError ** error); + GHashTable *extra_args, + GError **error); /*****************************************************************************/ @@ -413,7 +413,7 @@ const char *nm_setting_ip_config_get_dns_search(NMSettingIPConfig *setting, int gboolean nm_setting_ip_config_add_dns_search(NMSettingIPConfig *setting, const char *dns_search); void nm_setting_ip_config_remove_dns_search(NMSettingIPConfig *setting, int idx); gboolean nm_setting_ip_config_remove_dns_search_by_value(NMSettingIPConfig *setting, - const char * dns_search); + const char *dns_search); void nm_setting_ip_config_clear_dns_searches(NMSettingIPConfig *setting); guint nm_setting_ip_config_get_num_dns_options(NMSettingIPConfig *setting); @@ -422,7 +422,7 @@ const char *nm_setting_ip_config_get_dns_option(NMSettingIPConfig *setting, guin gboolean nm_setting_ip_config_add_dns_option(NMSettingIPConfig *setting, const char *dns_option); void nm_setting_ip_config_remove_dns_option(NMSettingIPConfig *setting, int idx); gboolean nm_setting_ip_config_remove_dns_option_by_value(NMSettingIPConfig *setting, - const char * dns_option); + const char *dns_option); void nm_setting_ip_config_clear_dns_options(NMSettingIPConfig *setting, gboolean is_set); NM_AVAILABLE_IN_1_4 @@ -433,7 +433,7 @@ NMIPAddress *nm_setting_ip_config_get_address(NMSettingIPConfig *setting, int id gboolean nm_setting_ip_config_add_address(NMSettingIPConfig *setting, NMIPAddress *address); void nm_setting_ip_config_remove_address(NMSettingIPConfig *setting, int idx); gboolean nm_setting_ip_config_remove_address_by_value(NMSettingIPConfig *setting, - NMIPAddress * address); + NMIPAddress *address); void nm_setting_ip_config_clear_addresses(NMSettingIPConfig *setting); const char *nm_setting_ip_config_get_gateway(NMSettingIPConfig *setting); @@ -456,7 +456,7 @@ NM_AVAILABLE_IN_1_18 NMIPRoutingRule *nm_setting_ip_config_get_routing_rule(NMSettingIPConfig *setting, guint idx); NM_AVAILABLE_IN_1_18 void nm_setting_ip_config_add_routing_rule(NMSettingIPConfig *setting, - NMIPRoutingRule * routing_rule); + NMIPRoutingRule *routing_rule); NM_AVAILABLE_IN_1_18 void nm_setting_ip_config_remove_routing_rule(NMSettingIPConfig *setting, guint idx); NM_AVAILABLE_IN_1_18 @@ -484,7 +484,7 @@ NMDhcpHostnameFlags nm_setting_ip_config_get_dhcp_hostname_flags(NMSettingIPConf NM_AVAILABLE_IN_1_28 const char *const *nm_setting_ip_config_get_dhcp_reject_servers(NMSettingIPConfig *setting, - guint * out_len); + guint *out_len); NM_AVAILABLE_IN_1_28 void nm_setting_ip_config_add_dhcp_reject_server(NMSettingIPConfig *setting, const char *server); NM_AVAILABLE_IN_1_28 diff --git a/src/libnm-core-public/nm-setting-match.h b/src/libnm-core-public/nm-setting-match.h index a4e283e2..6f3666b5 100644 --- a/src/libnm-core-public/nm-setting-match.h +++ b/src/libnm-core-public/nm-setting-match.h @@ -46,7 +46,7 @@ NM_AVAILABLE_IN_1_14 void nm_setting_match_remove_interface_name(NMSettingMatch *setting, int idx); NM_AVAILABLE_IN_1_14 gboolean nm_setting_match_remove_interface_name_by_value(NMSettingMatch *setting, - const char * interface_name); + const char *interface_name); NM_AVAILABLE_IN_1_14 void nm_setting_match_add_interface_name(NMSettingMatch *setting, const char *interface_name); NM_AVAILABLE_IN_1_14 @@ -62,15 +62,15 @@ NM_AVAILABLE_IN_1_26 void nm_setting_match_remove_kernel_command_line(NMSettingMatch *setting, guint idx); NM_AVAILABLE_IN_1_26 gboolean nm_setting_match_remove_kernel_command_line_by_value(NMSettingMatch *setting, - const char * kernel_command_line); + const char *kernel_command_line); NM_AVAILABLE_IN_1_26 void nm_setting_match_add_kernel_command_line(NMSettingMatch *setting, - const char * kernel_command_line); + const char *kernel_command_line); NM_AVAILABLE_IN_1_26 void nm_setting_match_clear_kernel_command_lines(NMSettingMatch *setting); NM_AVAILABLE_IN_1_26 const char *const *nm_setting_match_get_kernel_command_lines(NMSettingMatch *setting, - guint * length); + guint *length); NM_AVAILABLE_IN_1_26 guint nm_setting_match_get_num_drivers(NMSettingMatch *setting); diff --git a/src/libnm-core-public/nm-setting-olpc-mesh.h b/src/libnm-core-public/nm-setting-olpc-mesh.h index c9903f75..b055adbb 100644 --- a/src/libnm-core-public/nm-setting-olpc-mesh.h +++ b/src/libnm-core-public/nm-setting-olpc-mesh.h @@ -37,8 +37,8 @@ typedef struct _NMSettingOlpcMeshClass NMSettingOlpcMeshClass; GType nm_setting_olpc_mesh_get_type(void); -NMSetting * nm_setting_olpc_mesh_new(void); -GBytes * nm_setting_olpc_mesh_get_ssid(NMSettingOlpcMesh *setting); +NMSetting *nm_setting_olpc_mesh_new(void); +GBytes *nm_setting_olpc_mesh_get_ssid(NMSettingOlpcMesh *setting); guint32 nm_setting_olpc_mesh_get_channel(NMSettingOlpcMesh *setting); const char *nm_setting_olpc_mesh_get_dhcp_anycast_address(NMSettingOlpcMesh *setting); diff --git a/src/libnm-core-public/nm-setting-ovs-dpdk.h b/src/libnm-core-public/nm-setting-ovs-dpdk.h index 5d96aef4..2e2d11b9 100644 --- a/src/libnm-core-public/nm-setting-ovs-dpdk.h +++ b/src/libnm-core-public/nm-setting-ovs-dpdk.h @@ -28,6 +28,7 @@ G_BEGIN_DECLS #define NM_SETTING_OVS_DPDK_SETTING_NAME "ovs-dpdk" #define NM_SETTING_OVS_DPDK_DEVARGS "devargs" +#define NM_SETTING_OVS_DPDK_N_RXQ "n-rxq" typedef struct _NMSettingOvsDpdkClass NMSettingOvsDpdkClass; @@ -38,6 +39,8 @@ NMSetting *nm_setting_ovs_dpdk_new(void); NM_AVAILABLE_IN_1_20 const char *nm_setting_ovs_dpdk_get_devargs(NMSettingOvsDpdk *self); +NM_AVAILABLE_IN_1_36 +guint32 nm_setting_ovs_dpdk_get_n_rxq(NMSettingOvsDpdk *self); G_END_DECLS diff --git a/src/libnm-core-public/nm-setting-ovs-external-ids.h b/src/libnm-core-public/nm-setting-ovs-external-ids.h index 3ae991a1..03cb299e 100644 --- a/src/libnm-core-public/nm-setting-ovs-external-ids.h +++ b/src/libnm-core-public/nm-setting-ovs-external-ids.h @@ -46,15 +46,15 @@ NMSetting *nm_setting_ovs_external_ids_new(void); NM_AVAILABLE_IN_1_30 const char *const *nm_setting_ovs_external_ids_get_data_keys(NMSettingOvsExternalIDs *setting, - guint * out_len); + guint *out_len); NM_AVAILABLE_IN_1_30 const char *nm_setting_ovs_external_ids_get_data(NMSettingOvsExternalIDs *setting, const char *key); NM_AVAILABLE_IN_1_30 void nm_setting_ovs_external_ids_set_data(NMSettingOvsExternalIDs *setting, - const char * key, - const char * val); + const char *key, + const char *val); /*****************************************************************************/ diff --git a/src/libnm-core-public/nm-setting-pppoe.h b/src/libnm-core-public/nm-setting-pppoe.h index 5abf9c9f..b94046d4 100644 --- a/src/libnm-core-public/nm-setting-pppoe.h +++ b/src/libnm-core-public/nm-setting-pppoe.h @@ -39,10 +39,10 @@ GType nm_setting_pppoe_get_type(void); NMSetting *nm_setting_pppoe_new(void); NM_AVAILABLE_IN_1_10 -const char * nm_setting_pppoe_get_parent(NMSettingPppoe *setting); -const char * nm_setting_pppoe_get_service(NMSettingPppoe *setting); -const char * nm_setting_pppoe_get_username(NMSettingPppoe *setting); -const char * nm_setting_pppoe_get_password(NMSettingPppoe *setting); +const char *nm_setting_pppoe_get_parent(NMSettingPppoe *setting); +const char *nm_setting_pppoe_get_service(NMSettingPppoe *setting); +const char *nm_setting_pppoe_get_username(NMSettingPppoe *setting); +const char *nm_setting_pppoe_get_password(NMSettingPppoe *setting); NMSettingSecretFlags nm_setting_pppoe_get_password_flags(NMSettingPppoe *setting); G_END_DECLS diff --git a/src/libnm-core-public/nm-setting-serial.h b/src/libnm-core-public/nm-setting-serial.h index 4f8ead82..82a97cb4 100644 --- a/src/libnm-core-public/nm-setting-serial.h +++ b/src/libnm-core-public/nm-setting-serial.h @@ -51,7 +51,7 @@ typedef struct _NMSettingSerialClass NMSettingSerialClass; GType nm_setting_serial_get_type(void); -NMSetting * nm_setting_serial_new(void); +NMSetting *nm_setting_serial_new(void); guint nm_setting_serial_get_baud(NMSettingSerial *setting); guint nm_setting_serial_get_bits(NMSettingSerial *setting); NMSettingSerialParity nm_setting_serial_get_parity(NMSettingSerial *setting); diff --git a/src/libnm-core-public/nm-setting-tc-config.h b/src/libnm-core-public/nm-setting-tc-config.h index 7e8a44b5..abd61683 100644 --- a/src/libnm-core-public/nm-setting-tc-config.h +++ b/src/libnm-core-public/nm-setting-tc-config.h @@ -153,7 +153,7 @@ NM_AVAILABLE_IN_1_12 void nm_setting_tc_config_remove_tfilter(NMSettingTCConfig *setting, guint idx); NM_AVAILABLE_IN_1_12 gboolean nm_setting_tc_config_remove_tfilter_by_value(NMSettingTCConfig *setting, - NMTCTfilter * tfilter); + NMTCTfilter *tfilter); NM_AVAILABLE_IN_1_12 void nm_setting_tc_config_clear_tfilters(NMSettingTCConfig *setting); diff --git a/src/libnm-core-public/nm-setting-team.h b/src/libnm-core-public/nm-setting-team.h index 82174152..339830d3 100644 --- a/src/libnm-core-public/nm-setting-team.h +++ b/src/libnm-core-public/nm-setting-team.h @@ -48,24 +48,24 @@ NMTeamLinkWatcher *nm_team_link_watcher_new_nsna_ping(int init_wait, int interval, int missed_max, const char *target_host, - GError ** error); + GError **error); NM_AVAILABLE_IN_1_12 NMTeamLinkWatcher *nm_team_link_watcher_new_arp_ping(int init_wait, int interval, int missed_max, - const char * target_host, - const char * source_host, + const char *target_host, + const char *source_host, NMTeamLinkWatcherArpPingFlags flags, - GError ** error); + GError **error); NM_AVAILABLE_IN_1_16 NMTeamLinkWatcher *nm_team_link_watcher_new_arp_ping2(int init_wait, int interval, int missed_max, int vlanid, - const char * target_host, - const char * source_host, + const char *target_host, + const char *source_host, NMTeamLinkWatcherArpPingFlags flags, - GError ** error); + GError **error); NM_AVAILABLE_IN_1_12 void nm_team_link_watcher_ref(NMTeamLinkWatcher *watcher); NM_AVAILABLE_IN_1_12 @@ -203,7 +203,7 @@ gboolean nm_setting_team_add_link_watcher(NMSettingTeam *setting, NMTeamLinkWatc NM_AVAILABLE_IN_1_12 void nm_setting_team_remove_link_watcher(NMSettingTeam *setting, guint idx); NM_AVAILABLE_IN_1_12 -gboolean nm_setting_team_remove_link_watcher_by_value(NMSettingTeam * setting, +gboolean nm_setting_team_remove_link_watcher_by_value(NMSettingTeam *setting, NMTeamLinkWatcher *link_watcher); NM_AVAILABLE_IN_1_12 void nm_setting_team_clear_link_watchers(NMSettingTeam *setting); diff --git a/src/libnm-core-public/nm-setting-vlan.h b/src/libnm-core-public/nm-setting-vlan.h index 09a407db..10a95da0 100644 --- a/src/libnm-core-public/nm-setting-vlan.h +++ b/src/libnm-core-public/nm-setting-vlan.h @@ -89,27 +89,27 @@ guint32 nm_setting_vlan_get_flags(NMSettingVlan *setting); gint32 nm_setting_vlan_get_num_priorities(NMSettingVlan *setting, NMVlanPriorityMap map); -gboolean nm_setting_vlan_get_priority(NMSettingVlan * setting, +gboolean nm_setting_vlan_get_priority(NMSettingVlan *setting, NMVlanPriorityMap map, guint32 idx, - guint32 * out_from, - guint32 * out_to); + guint32 *out_from, + guint32 *out_to); -gboolean nm_setting_vlan_add_priority(NMSettingVlan * setting, +gboolean nm_setting_vlan_add_priority(NMSettingVlan *setting, NMVlanPriorityMap map, guint32 from, guint32 to); void nm_setting_vlan_remove_priority(NMSettingVlan *setting, NMVlanPriorityMap map, guint32 idx); -gboolean nm_setting_vlan_remove_priority_by_value(NMSettingVlan * setting, +gboolean nm_setting_vlan_remove_priority_by_value(NMSettingVlan *setting, NMVlanPriorityMap map, guint32 from, guint32 to); -gboolean nm_setting_vlan_remove_priority_str_by_value(NMSettingVlan * setting, +gboolean nm_setting_vlan_remove_priority_str_by_value(NMSettingVlan *setting, NMVlanPriorityMap map, - const char * str); + const char *str); void nm_setting_vlan_clear_priorities(NMSettingVlan *setting, NMVlanPriorityMap map); diff --git a/src/libnm-core-public/nm-setting-vpn.h b/src/libnm-core-public/nm-setting-vpn.h index 9fbb791b..151a293a 100644 --- a/src/libnm-core-public/nm-setting-vpn.h +++ b/src/libnm-core-public/nm-setting-vpn.h @@ -46,7 +46,7 @@ typedef void (*NMVpnIterFunc)(const char *key, const char *value, gpointer user_ GType nm_setting_vpn_get_type(void); -NMSetting * nm_setting_vpn_new(void); +NMSetting *nm_setting_vpn_new(void); const char *nm_setting_vpn_get_service_type(NMSettingVpn *setting); const char *nm_setting_vpn_get_user_name(NMSettingVpn *setting); gboolean nm_setting_vpn_get_persistent(NMSettingVpn *setting); diff --git a/src/libnm-core-public/nm-setting-wired.h b/src/libnm-core-public/nm-setting-wired.h index 54c8f9c0..ebe0d00a 100644 --- a/src/libnm-core-public/nm-setting-wired.h +++ b/src/libnm-core-public/nm-setting-wired.h @@ -85,7 +85,7 @@ typedef struct _NMSettingWiredClass NMSettingWiredClass; GType nm_setting_wired_get_type(void); -NMSetting * nm_setting_wired_new(void); +NMSetting *nm_setting_wired_new(void); const char *nm_setting_wired_get_port(NMSettingWired *setting); guint32 nm_setting_wired_get_speed(NMSettingWired *setting); const char *nm_setting_wired_get_duplex(NMSettingWired *setting); @@ -101,23 +101,23 @@ const char *nm_setting_wired_get_generate_mac_address_mask(NMSettingWired *setti const char *const *nm_setting_wired_get_mac_address_blacklist(NMSettingWired *setting); guint32 nm_setting_wired_get_num_mac_blacklist_items(NMSettingWired *setting); -const char * nm_setting_wired_get_mac_blacklist_item(NMSettingWired *setting, guint32 idx); +const char *nm_setting_wired_get_mac_blacklist_item(NMSettingWired *setting, guint32 idx); gboolean nm_setting_wired_add_mac_blacklist_item(NMSettingWired *setting, const char *mac); void nm_setting_wired_remove_mac_blacklist_item(NMSettingWired *setting, guint32 idx); gboolean nm_setting_wired_remove_mac_blacklist_item_by_value(NMSettingWired *setting, - const char * mac); + const char *mac); void nm_setting_wired_clear_mac_blacklist_items(NMSettingWired *setting); guint32 nm_setting_wired_get_mtu(NMSettingWired *setting); const char *const *nm_setting_wired_get_s390_subchannels(NMSettingWired *setting); -const char * nm_setting_wired_get_s390_nettype(NMSettingWired *setting); +const char *nm_setting_wired_get_s390_nettype(NMSettingWired *setting); guint32 nm_setting_wired_get_num_s390_options(NMSettingWired *setting); gboolean nm_setting_wired_get_s390_option(NMSettingWired *setting, guint32 idx, - const char ** out_key, - const char ** out_value); + const char **out_key, + const char **out_value); const char *nm_setting_wired_get_s390_option_by_key(NMSettingWired *setting, const char *key); gboolean nm_setting_wired_add_s390_option(NMSettingWired *setting, const char *key, const char *value); @@ -125,7 +125,7 @@ gboolean nm_setting_wired_remove_s390_option(NMSettingWired *setting, const const char **nm_setting_wired_get_valid_s390_options(NMSettingWired *setting); NMSettingWiredWakeOnLan nm_setting_wired_get_wake_on_lan(NMSettingWired *setting); -const char * nm_setting_wired_get_wake_on_lan_password(NMSettingWired *setting); +const char *nm_setting_wired_get_wake_on_lan_password(NMSettingWired *setting); G_END_DECLS diff --git a/src/libnm-core-public/nm-setting-wireguard.h b/src/libnm-core-public/nm-setting-wireguard.h index cb475d27..7e62e2ed 100644 --- a/src/libnm-core-public/nm-setting-wireguard.h +++ b/src/libnm-core-public/nm-setting-wireguard.h @@ -47,20 +47,20 @@ NM_AVAILABLE_IN_1_16 const char *nm_wireguard_peer_get_public_key(const NMWireGuardPeer *self); NM_AVAILABLE_IN_1_16 gboolean nm_wireguard_peer_set_public_key(NMWireGuardPeer *self, - const char * public_key, + const char *public_key, gboolean accept_invalid); NM_AVAILABLE_IN_1_16 const char *nm_wireguard_peer_get_preshared_key(const NMWireGuardPeer *self); NM_AVAILABLE_IN_1_16 gboolean nm_wireguard_peer_set_preshared_key(NMWireGuardPeer *self, - const char * preshared_key, + const char *preshared_key, gboolean accept_invalid); NM_AVAILABLE_IN_1_16 NMSettingSecretFlags nm_wireguard_peer_get_preshared_key_flags(const NMWireGuardPeer *self); NM_AVAILABLE_IN_1_16 -void nm_wireguard_peer_set_preshared_key_flags(NMWireGuardPeer * self, +void nm_wireguard_peer_set_preshared_key_flags(NMWireGuardPeer *self, NMSettingSecretFlags preshared_key_flags); NM_AVAILABLE_IN_1_16 @@ -84,7 +84,7 @@ NM_AVAILABLE_IN_1_16 void nm_wireguard_peer_clear_allowed_ips(NMWireGuardPeer *self); NM_AVAILABLE_IN_1_16 gboolean nm_wireguard_peer_append_allowed_ip(NMWireGuardPeer *self, - const char * allowed_ip, + const char *allowed_ip, gboolean accept_invalid); NM_AVAILABLE_IN_1_16 gboolean nm_wireguard_peer_remove_allowed_ip(NMWireGuardPeer *self, guint idx); @@ -93,7 +93,7 @@ NM_AVAILABLE_IN_1_16 gboolean nm_wireguard_peer_is_valid(const NMWireGuardPeer *self, gboolean check_non_secrets, gboolean check_secrets, - GError ** error); + GError **error); NM_AVAILABLE_IN_1_16 int nm_wireguard_peer_cmp(const NMWireGuardPeer *a, @@ -168,8 +168,8 @@ NMWireGuardPeer *nm_setting_wireguard_get_peer(NMSettingWireGuard *self, guint i NM_AVAILABLE_IN_1_16 NMWireGuardPeer *nm_setting_wireguard_get_peer_by_public_key(NMSettingWireGuard *self, - const char * public_key, - guint * out_idx); + const char *public_key, + guint *out_idx); NM_AVAILABLE_IN_1_16 void nm_setting_wireguard_set_peer(NMSettingWireGuard *self, NMWireGuardPeer *peer, guint idx); diff --git a/src/libnm-core-public/nm-setting-wireless-security.h b/src/libnm-core-public/nm-setting-wireless-security.h index 9686e7d5..c9aec27d 100644 --- a/src/libnm-core-public/nm-setting-wireless-security.h +++ b/src/libnm-core-public/nm-setting-wireless-security.h @@ -163,36 +163,36 @@ const char *nm_setting_wireless_security_get_key_mgmt(NMSettingWirelessSecurity guint32 nm_setting_wireless_security_get_num_protos(NMSettingWirelessSecurity *setting); const char *nm_setting_wireless_security_get_proto(NMSettingWirelessSecurity *setting, guint32 i); gboolean nm_setting_wireless_security_add_proto(NMSettingWirelessSecurity *setting, - const char * proto); + const char *proto); void nm_setting_wireless_security_remove_proto(NMSettingWirelessSecurity *setting, guint32 i); gboolean nm_setting_wireless_security_remove_proto_by_value(NMSettingWirelessSecurity *setting, - const char * proto); + const char *proto); void nm_setting_wireless_security_clear_protos(NMSettingWirelessSecurity *setting); guint32 nm_setting_wireless_security_get_num_pairwise(NMSettingWirelessSecurity *setting); const char *nm_setting_wireless_security_get_pairwise(NMSettingWirelessSecurity *setting, guint32 i); gboolean nm_setting_wireless_security_add_pairwise(NMSettingWirelessSecurity *setting, - const char * pairwise); + const char *pairwise); void nm_setting_wireless_security_remove_pairwise(NMSettingWirelessSecurity *setting, guint32 i); gboolean nm_setting_wireless_security_remove_pairwise_by_value(NMSettingWirelessSecurity *setting, - const char * pairwise); + const char *pairwise); void nm_setting_wireless_security_clear_pairwise(NMSettingWirelessSecurity *setting); guint32 nm_setting_wireless_security_get_num_groups(NMSettingWirelessSecurity *setting); const char *nm_setting_wireless_security_get_group(NMSettingWirelessSecurity *setting, guint32 i); gboolean nm_setting_wireless_security_add_group(NMSettingWirelessSecurity *setting, - const char * group); + const char *group); void nm_setting_wireless_security_remove_group(NMSettingWirelessSecurity *setting, guint32 i); gboolean nm_setting_wireless_security_remove_group_by_value(NMSettingWirelessSecurity *setting, - const char * group); + const char *group); void nm_setting_wireless_security_clear_groups(NMSettingWirelessSecurity *setting); NM_AVAILABLE_IN_1_10 NMSettingWirelessSecurityPmf nm_setting_wireless_security_get_pmf(NMSettingWirelessSecurity *setting); -const char * nm_setting_wireless_security_get_psk(NMSettingWirelessSecurity *setting); +const char *nm_setting_wireless_security_get_psk(NMSettingWirelessSecurity *setting); NMSettingSecretFlags nm_setting_wireless_security_get_psk_flags(NMSettingWirelessSecurity *setting); const char *nm_setting_wireless_security_get_leap_username(NMSettingWirelessSecurity *setting); @@ -204,7 +204,7 @@ const char *nm_setting_wireless_security_get_wep_key(NMSettingWirelessSecurity * guint32 idx); void nm_setting_wireless_security_set_wep_key(NMSettingWirelessSecurity *setting, guint32 idx, - const char * key); + const char *key); guint32 nm_setting_wireless_security_get_wep_tx_keyidx(NMSettingWirelessSecurity *setting); const char *nm_setting_wireless_security_get_auth_alg(NMSettingWirelessSecurity *setting); diff --git a/src/libnm-core-public/nm-setting-wireless.h b/src/libnm-core-public/nm-setting-wireless.h index 4451785f..0d4872fb 100644 --- a/src/libnm-core-public/nm-setting-wireless.h +++ b/src/libnm-core-public/nm-setting-wireless.h @@ -148,7 +148,7 @@ GType nm_setting_wireless_get_type(void); NMSetting *nm_setting_wireless_new(void); -GBytes * nm_setting_wireless_get_ssid(NMSettingWireless *setting); +GBytes *nm_setting_wireless_get_ssid(NMSettingWireless *setting); const char *nm_setting_wireless_get_mode(NMSettingWireless *setting); const char *nm_setting_wireless_get_band(NMSettingWireless *setting); guint32 nm_setting_wireless_get_channel(NMSettingWireless *setting); @@ -167,7 +167,7 @@ const char *nm_setting_wireless_get_mac_blacklist_item(NMSettingWireless *settin gboolean nm_setting_wireless_add_mac_blacklist_item(NMSettingWireless *setting, const char *mac); void nm_setting_wireless_remove_mac_blacklist_item(NMSettingWireless *setting, guint32 idx); gboolean nm_setting_wireless_remove_mac_blacklist_item_by_value(NMSettingWireless *setting, - const char * mac); + const char *mac); void nm_setting_wireless_clear_mac_blacklist_items(NMSettingWireless *setting); guint32 nm_setting_wireless_get_mtu(NMSettingWireless *setting); @@ -184,7 +184,7 @@ gboolean nm_setting_wireless_add_seen_bssid(NMSettingWireless *setting, const ch guint32 nm_setting_wireless_get_num_seen_bssids(NMSettingWireless *setting); const char *nm_setting_wireless_get_seen_bssid(NMSettingWireless *setting, guint32 i); -gboolean nm_setting_wireless_ap_security_compatible(NMSettingWireless * s_wireless, +gboolean nm_setting_wireless_ap_security_compatible(NMSettingWireless *s_wireless, NMSettingWirelessSecurity *s_wireless_sec, NM80211ApFlags ap_flags, NM80211ApSecurityFlags ap_wpa, diff --git a/src/libnm-core-public/nm-setting.h b/src/libnm-core-public/nm-setting.h index ea2525dc..ddf648bc 100644 --- a/src/libnm-core-public/nm-setting.h +++ b/src/libnm-core-public/nm-setting.h @@ -138,8 +138,8 @@ typedef enum { * * Returns: %TRUE to clear the secret, %FALSE to not clear the secret */ -typedef gboolean (*NMSettingClearSecretsWithFlagsFn)(NMSetting * setting, - const char * secret, +typedef gboolean (*NMSettingClearSecretsWithFlagsFn)(NMSetting *setting, + const char *secret, NMSettingSecretFlags flags, gpointer user_data); @@ -156,8 +156,8 @@ struct _NMSettInfoProperty; * @flags: The property's flags, like %NM_SETTING_PARAM_SECRET * @user_data: User data passed to nm_setting_enumerate_values() */ -typedef void (*NMSettingValueIterFn)(NMSetting * setting, - const char * key, +typedef void (*NMSettingValueIterFn)(NMSetting *setting, + const char *key, const GValue *value, GParamFlags flags, gpointer user_data); @@ -202,11 +202,11 @@ typedef enum { NM_SETTING_DIFF_RESULT_IN_B_DEFAULT = 0x00000008, } NMSettingDiffResult; -gboolean nm_setting_diff(NMSetting * a, - NMSetting * b, +gboolean nm_setting_diff(NMSetting *a, + NMSetting *b, NMSettingCompareFlags flags, gboolean invert_results, - GHashTable ** results); + GHashTable **results); void nm_setting_enumerate_values(NMSetting *setting, NMSettingValueIterFn func, gpointer user_data); @@ -214,15 +214,15 @@ char *nm_setting_to_string(NMSetting *setting); /*****************************************************************************/ -gboolean nm_setting_get_secret_flags(NMSetting * setting, - const char * secret_name, +gboolean nm_setting_get_secret_flags(NMSetting *setting, + const char *secret_name, NMSettingSecretFlags *out_flags, - GError ** error); + GError **error); -gboolean nm_setting_set_secret_flags(NMSetting * setting, - const char * secret_name, +gboolean nm_setting_set_secret_flags(NMSetting *setting, + const char *secret_name, NMSettingSecretFlags flags, - GError ** error); + GError **error); /*****************************************************************************/ @@ -253,7 +253,7 @@ void nm_setting_option_clear_by_name(NMSetting *setting, NMUtilsPredicateStr pre /*****************************************************************************/ -const GVariantType *nm_setting_get_dbus_property_type(NMSetting * setting, +const GVariantType *nm_setting_get_dbus_property_type(NMSetting *setting, const char *property_name); /*****************************************************************************/ diff --git a/src/libnm-core-public/nm-utils.h b/src/libnm-core-public/nm-utils.h index 5100b678..0a7c7a81 100644 --- a/src/libnm-core-public/nm-utils.h +++ b/src/libnm-core-public/nm-utils.h @@ -31,7 +31,7 @@ gboolean nm_utils_same_ssid(const guint8 *ssid1, const guint8 *ssid2, gsize len2, gboolean ignore_trailing_null); -char * nm_utils_ssid_to_utf8(const guint8 *ssid, gsize len); +char *nm_utils_ssid_to_utf8(const guint8 *ssid, gsize len); /** * NMUtilsSecurityType: @@ -86,27 +86,27 @@ gboolean nm_utils_wpa_psk_valid(const char *psk); NM_AVAILABLE_IN_1_6 gboolean nm_utils_is_json_object(const char *str, GError **error); -GVariant * nm_utils_ip4_dns_to_variant(char **dns); -char ** nm_utils_ip4_dns_from_variant(GVariant *value); -GVariant * nm_utils_ip4_addresses_to_variant(GPtrArray *addresses, const char *gateway); +GVariant *nm_utils_ip4_dns_to_variant(char **dns); +char **nm_utils_ip4_dns_from_variant(GVariant *value); +GVariant *nm_utils_ip4_addresses_to_variant(GPtrArray *addresses, const char *gateway); GPtrArray *nm_utils_ip4_addresses_from_variant(GVariant *value, char **out_gateway); -GVariant * nm_utils_ip4_routes_to_variant(GPtrArray *routes); +GVariant *nm_utils_ip4_routes_to_variant(GPtrArray *routes); GPtrArray *nm_utils_ip4_routes_from_variant(GVariant *value); guint32 nm_utils_ip4_netmask_to_prefix(guint32 netmask); guint32 nm_utils_ip4_prefix_to_netmask(guint32 prefix); guint32 nm_utils_ip4_get_default_prefix(guint32 ip); -GVariant * nm_utils_ip6_dns_to_variant(char **dns); -char ** nm_utils_ip6_dns_from_variant(GVariant *value); -GVariant * nm_utils_ip6_addresses_to_variant(GPtrArray *addresses, const char *gateway); +GVariant *nm_utils_ip6_dns_to_variant(char **dns); +char **nm_utils_ip6_dns_from_variant(GVariant *value); +GVariant *nm_utils_ip6_addresses_to_variant(GPtrArray *addresses, const char *gateway); GPtrArray *nm_utils_ip6_addresses_from_variant(GVariant *value, char **out_gateway); -GVariant * nm_utils_ip6_routes_to_variant(GPtrArray *routes); +GVariant *nm_utils_ip6_routes_to_variant(GPtrArray *routes); GPtrArray *nm_utils_ip6_routes_from_variant(GVariant *value); -GVariant * nm_utils_ip_addresses_to_variant(GPtrArray *addresses); +GVariant *nm_utils_ip_addresses_to_variant(GPtrArray *addresses); GPtrArray *nm_utils_ip_addresses_from_variant(GVariant *value, int family); -GVariant * nm_utils_ip_routes_to_variant(GPtrArray *routes); +GVariant *nm_utils_ip_routes_to_variant(GPtrArray *routes); GPtrArray *nm_utils_ip_routes_from_variant(GVariant *value, int family); char *nm_utils_uuid_generate(void); @@ -119,18 +119,18 @@ typedef gboolean (*NMUtilsFileSearchInPathsPredicate)(const char *filename, gpoi struct stat; -typedef gboolean (*NMUtilsCheckFilePredicate)(const char * filename, +typedef gboolean (*NMUtilsCheckFilePredicate)(const char *filename, const struct stat *stat, gpointer user_data, - GError ** error); + GError **error); -const char *nm_utils_file_search_in_paths(const char * progname, - const char * try_first, - const char *const * paths, +const char *nm_utils_file_search_in_paths(const char *progname, + const char *try_first, + const char *const *paths, GFileTest file_test_flags, NMUtilsFileSearchInPathsPredicate predicate, gpointer user_data, - GError ** error); + GError **error); guint32 nm_utils_wifi_freq_to_channel(guint32 freq); guint32 nm_utils_wifi_channel_to_freq(guint32 channel, const char *band); @@ -153,18 +153,18 @@ const char *nm_utils_wifi_strength_bars(guint8 strength); gsize nm_utils_hwaddr_len(int type) G_GNUC_PURE; -char * nm_utils_hwaddr_ntoa(gconstpointer addr, gsize length); +char *nm_utils_hwaddr_ntoa(gconstpointer addr, gsize length); GByteArray *nm_utils_hwaddr_atoba(const char *asc, gsize length); -guint8 * nm_utils_hwaddr_aton(const char *asc, gpointer buffer, gsize length); +guint8 *nm_utils_hwaddr_aton(const char *asc, gpointer buffer, gsize length); gboolean nm_utils_hwaddr_valid(const char *asc, gssize length); -char * nm_utils_hwaddr_canonical(const char *asc, gssize length); +char *nm_utils_hwaddr_canonical(const char *asc, gssize length); gboolean nm_utils_hwaddr_matches(gconstpointer hwaddr1, gssize hwaddr1_len, gconstpointer hwaddr2, gssize hwaddr2_len); -char * nm_utils_bin2hexstr(gconstpointer src, gsize len, int final_len); +char *nm_utils_bin2hexstr(gconstpointer src, gsize len, int final_len); GBytes *nm_utils_hexstr2bin(const char *hex); NM_DEPRECATED_IN_1_6_FOR(nm_utils_is_valid_iface_name) @@ -214,7 +214,7 @@ GHashTable *nm_utils_parse_variant_attributes(const char *string, char key_value_separator, gboolean ignore_unknown, const NMVariantAttributeSpec *const *spec, - GError ** error); + GError **error); NM_AVAILABLE_IN_1_8 char *nm_utils_format_variant_attributes(GHashTable *attributes, diff --git a/src/libnm-core-public/nm-version-macros.h b/src/libnm-core-public/nm-version-macros.h index 3063f2f4..f0936734 100644 --- a/src/libnm-core-public/nm-version-macros.h +++ b/src/libnm-core-public/nm-version-macros.h @@ -22,7 +22,7 @@ * Evaluates to the minor version number of NetworkManager which this source * is compiled against. */ -#define NM_MINOR_VERSION (34) +#define NM_MINOR_VERSION (35) /** * NM_MICRO_VERSION: @@ -30,7 +30,7 @@ * Evaluates to the micro version number of NetworkManager which this source * compiled against. */ -#define NM_MICRO_VERSION (0) +#define NM_MICRO_VERSION (91) /** * NM_CHECK_VERSION: @@ -69,13 +69,14 @@ #define NM_VERSION_1_30 (NM_ENCODE_VERSION (1, 30, 0)) #define NM_VERSION_1_32 (NM_ENCODE_VERSION (1, 32, 0)) #define NM_VERSION_1_34 (NM_ENCODE_VERSION (1, 34, 0)) +#define NM_VERSION_1_36 (NM_ENCODE_VERSION (1, 36, 0)) /* For releases, NM_API_VERSION is equal to NM_VERSION. * * For development builds, NM_API_VERSION is the next * stable API after NM_VERSION. When you run a development * version, you are already using the future API, even if - * it is not yet release. Hence, the currently used API + * it is not yet released. Hence, the currently used API * version is the future one. */ #define NM_API_VERSION \ (((NM_MINOR_VERSION % 2) == 1) \ diff --git a/src/libnm-core-public/nm-version-macros.h.in b/src/libnm-core-public/nm-version-macros.h.in index 8ec83436..76dd4240 100644 --- a/src/libnm-core-public/nm-version-macros.h.in +++ b/src/libnm-core-public/nm-version-macros.h.in @@ -69,13 +69,14 @@ #define NM_VERSION_1_30 (NM_ENCODE_VERSION (1, 30, 0)) #define NM_VERSION_1_32 (NM_ENCODE_VERSION (1, 32, 0)) #define NM_VERSION_1_34 (NM_ENCODE_VERSION (1, 34, 0)) +#define NM_VERSION_1_36 (NM_ENCODE_VERSION (1, 36, 0)) /* For releases, NM_API_VERSION is equal to NM_VERSION. * * For development builds, NM_API_VERSION is the next * stable API after NM_VERSION. When you run a development * version, you are already using the future API, even if - * it is not yet release. Hence, the currently used API + * it is not yet released. Hence, the currently used API * version is the future one. */ #define NM_API_VERSION \ (((NM_MINOR_VERSION % 2) == 1) \ diff --git a/src/libnm-core-public/nm-version.h b/src/libnm-core-public/nm-version.h index f0f09fa8..d6f58924 100644 --- a/src/libnm-core-public/nm-version.h +++ b/src/libnm-core-public/nm-version.h @@ -299,6 +299,20 @@ #define NM_AVAILABLE_IN_1_34 #endif +#if NM_VERSION_MIN_REQUIRED >= NM_VERSION_1_36 +#define NM_DEPRECATED_IN_1_36 G_DEPRECATED +#define NM_DEPRECATED_IN_1_36_FOR(f) G_DEPRECATED_FOR(f) +#else +#define NM_DEPRECATED_IN_1_36 +#define NM_DEPRECATED_IN_1_36_FOR(f) +#endif + +#if NM_VERSION_MAX_ALLOWED < NM_VERSION_1_36 +#define NM_AVAILABLE_IN_1_36 G_UNAVAILABLE(1, 36) +#else +#define NM_AVAILABLE_IN_1_36 +#endif + /* * Synchronous API for calling D-Bus in libnm is deprecated. See * https://developer.gnome.org/libnm/stable/usage.html#sync-api diff --git a/src/libnm-core-public/nm-vpn-editor-plugin.h b/src/libnm-core-public/nm-vpn-editor-plugin.h index e25c358e..4e632244 100644 --- a/src/libnm-core-public/nm-vpn-editor-plugin.h +++ b/src/libnm-core-public/nm-vpn-editor-plugin.h @@ -103,9 +103,9 @@ typedef struct { NMConnection *(*import_from_file)(NMVpnEditorPlugin *plugin, const char *path, GError **error); gboolean (*export_to_file)(NMVpnEditorPlugin *plugin, - const char * path, - NMConnection * connection, - GError ** error); + const char *path, + NMConnection *connection, + GError **error); char *(*get_suggested_filename)(NMVpnEditorPlugin *plugin, NMConnection *connection); @@ -117,8 +117,8 @@ typedef struct { GType nm_vpn_editor_plugin_get_type(void); NMVpnEditor *nm_vpn_editor_plugin_get_editor(NMVpnEditorPlugin *plugin, - NMConnection * connection, - GError ** error); + NMConnection *connection, + GError **error); NMVpnEditorPluginCapability nm_vpn_editor_plugin_get_capabilities(NMVpnEditorPlugin *plugin); @@ -126,22 +126,22 @@ NM_AVAILABLE_IN_1_4 gsize nm_vpn_editor_plugin_get_vt(NMVpnEditorPlugin *plugin, NMVpnEditorPluginVT *vt, gsize vt_size); -NMConnection * - nm_vpn_editor_plugin_import(NMVpnEditorPlugin *plugin, const char *path, GError **error); +NMConnection * +nm_vpn_editor_plugin_import(NMVpnEditorPlugin *plugin, const char *path, GError **error); gboolean nm_vpn_editor_plugin_export(NMVpnEditorPlugin *plugin, - const char * path, - NMConnection * connection, - GError ** error); -char * nm_vpn_editor_plugin_get_suggested_filename(NMVpnEditorPlugin *plugin, - NMConnection * connection); + const char *path, + NMConnection *connection, + GError **error); +char *nm_vpn_editor_plugin_get_suggested_filename(NMVpnEditorPlugin *plugin, + NMConnection *connection); NM_AVAILABLE_IN_1_2 -NMVpnEditorPlugin *nm_vpn_editor_plugin_load_from_file(const char * plugin_name, - const char * check_service, +NMVpnEditorPlugin *nm_vpn_editor_plugin_load_from_file(const char *plugin_name, + const char *check_service, int check_owner, NMUtilsCheckFilePredicate check_file, gpointer user_data, - GError ** error); + GError **error); NM_AVAILABLE_IN_1_4 NMVpnEditorPlugin * diff --git a/src/libnm-core-public/nm-vpn-plugin-info.h b/src/libnm-core-public/nm-vpn-plugin-info.h index 1e9870c8..aa319a57 100644 --- a/src/libnm-core-public/nm-vpn-plugin-info.h +++ b/src/libnm-core-public/nm-vpn-plugin-info.h @@ -89,7 +89,7 @@ NMVpnPluginInfo *nm_vpn_plugin_info_list_find_by_service(GSList *list, const cha NM_AVAILABLE_IN_1_4 char *nm_vpn_plugin_info_list_find_service_type(GSList *list, const char *name); NM_AVAILABLE_IN_1_4 -char **nm_vpn_plugin_info_list_get_service_types(GSList * list, +char **nm_vpn_plugin_info_list_get_service_types(GSList *list, gboolean only_existing, gboolean with_abbreviations); diff --git a/src/libnm-glib-aux/nm-c-list.h b/src/libnm-glib-aux/nm-c-list.h index 6dd3ac72..d89a9223 100644 --- a/src/libnm-glib-aux/nm-c-list.h +++ b/src/libnm-glib-aux/nm-c-list.h @@ -169,7 +169,7 @@ nm_c_list_move_after(CList *lst, CList *elem) G_STMT_START \ { \ CList *const _lst = (lst); \ - type * _elem; \ + type *_elem; \ \ while ((_elem = c_list_first_entry(_lst, type, member))) { \ destroy_fcn(_elem); \ diff --git a/src/libnm-glib-aux/nm-dbus-aux.c b/src/libnm-glib-aux/nm-dbus-aux.c index 454bd2d8..0f43ba8e 100644 --- a/src/libnm-glib-aux/nm-dbus-aux.c +++ b/src/libnm-glib-aux/nm-dbus-aux.c @@ -12,9 +12,9 @@ static void _nm_dbus_connection_call_get_name_owner_cb(GObject *source, GAsyncResult *res, gpointer user_data) { - gs_unref_variant GVariant *ret = NULL; - gs_free_error GError * error = NULL; - const char * owner = NULL; + gs_unref_variant GVariant *ret = NULL; + gs_free_error GError *error = NULL; + const char *owner = NULL; gpointer orig_user_data; NMDBusConnectionCallGetNameOwnerCb callback; @@ -28,10 +28,10 @@ _nm_dbus_connection_call_get_name_owner_cb(GObject *source, GAsyncResult *res, g } void -nm_dbus_connection_call_get_name_owner(GDBusConnection * dbus_connection, - const char * service_name, +nm_dbus_connection_call_get_name_owner(GDBusConnection *dbus_connection, + const char *service_name, int timeout_msec, - GCancellable * cancellable, + GCancellable *cancellable, NMDBusConnectionCallGetNameOwnerCb callback, gpointer user_data) { @@ -56,8 +56,8 @@ nm_dbus_connection_call_get_name_owner(GDBusConnection * dbus_c static void _nm_dbus_connection_call_default_cb(GObject *source, GAsyncResult *res, gpointer user_data) { - gs_unref_variant GVariant *ret = NULL; - gs_free_error GError * error = NULL; + gs_unref_variant GVariant *ret = NULL; + gs_free_error GError *error = NULL; gpointer orig_user_data; NMDBusConnectionCallDefaultCb callback; @@ -71,12 +71,12 @@ _nm_dbus_connection_call_default_cb(GObject *source, GAsyncResult *res, gpointer } void -nm_dbus_connection_call_get_all(GDBusConnection * dbus_connection, - const char * bus_name, - const char * object_path, - const char * interface_name, +nm_dbus_connection_call_get_all(GDBusConnection *dbus_connection, + const char *bus_name, + const char *object_path, + const char *interface_name, int timeout_msec, - GCancellable * cancellable, + GCancellable *cancellable, NMDBusConnectionCallDefaultCb callback, gpointer user_data) { @@ -97,14 +97,14 @@ nm_dbus_connection_call_get_all(GDBusConnection * dbus_connection, } void -nm_dbus_connection_call_set(GDBusConnection * dbus_connection, - const char * bus_name, - const char * object_path, - const char * interface_name, - const char * property_name, - GVariant * value, +nm_dbus_connection_call_set(GDBusConnection *dbus_connection, + const char *bus_name, + const char *object_path, + const char *interface_name, + const char *property_name, + GVariant *value, int timeout_msec, - GCancellable * cancellable, + GCancellable *cancellable, NMDBusConnectionCallDefaultCb callback, gpointer user_data) { @@ -125,13 +125,13 @@ nm_dbus_connection_call_set(GDBusConnection * dbus_connection, /*****************************************************************************/ static void -_nm_dbus_connection_call_get_managed_objects_cb(GObject * source, +_nm_dbus_connection_call_get_managed_objects_cb(GObject *source, GAsyncResult *res, gpointer user_data) { - gs_unref_variant GVariant *ret = NULL; - gs_unref_variant GVariant *arg = NULL; - gs_free_error GError * error = NULL; + gs_unref_variant GVariant *ret = NULL; + gs_unref_variant GVariant *arg = NULL; + gs_free_error GError *error = NULL; gpointer orig_user_data; NMDBusConnectionCallDefaultCb callback; @@ -150,12 +150,12 @@ _nm_dbus_connection_call_get_managed_objects_cb(GObject * source, } void -nm_dbus_connection_call_get_managed_objects(GDBusConnection * dbus_connection, - const char * bus_name, - const char * object_path, +nm_dbus_connection_call_get_managed_objects(GDBusConnection *dbus_connection, + const char *bus_name, + const char *object_path, GDBusCallFlags flags, int timeout_msec, - GCancellable * cancellable, + GCancellable *cancellable, NMDBusConnectionCallDefaultCb callback, gpointer user_data) { @@ -178,15 +178,15 @@ nm_dbus_connection_call_get_managed_objects(GDBusConnection * dbus_c /*****************************************************************************/ static void -_call_finish_cb(GObject * source, +_call_finish_cb(GObject *source, GAsyncResult *result, gpointer user_data, gboolean return_void, gboolean strip_dbus_error) { - gs_unref_object GTask *task = user_data; + gs_unref_object GTask *task = user_data; gs_unref_variant GVariant *ret = NULL; - GError * error = NULL; + GError *error = NULL; nm_assert(G_IS_DBUS_CONNECTION(source)); nm_assert(G_IS_TASK(user_data)); @@ -230,7 +230,7 @@ nm_dbus_connection_call_finish_void_cb(GObject *source, GAsyncResult *result, gp * is that on error this will first call g_dbus_error_strip_remote_error() on the error. */ void -nm_dbus_connection_call_finish_void_strip_dbus_error_cb(GObject * source, +nm_dbus_connection_call_finish_void_strip_dbus_error_cb(GObject *source, GAsyncResult *result, gpointer user_data) { @@ -259,7 +259,7 @@ nm_dbus_connection_call_finish_variant_cb(GObject *source, GAsyncResult *result, * is that on error this will first call g_dbus_error_strip_remote_error() on the error. */ void -nm_dbus_connection_call_finish_variant_strip_dbus_error_cb(GObject * source, +nm_dbus_connection_call_finish_variant_strip_dbus_error_cb(GObject *source, GAsyncResult *result, gpointer user_data) { @@ -269,12 +269,12 @@ nm_dbus_connection_call_finish_variant_strip_dbus_error_cb(GObject * source, /*****************************************************************************/ typedef struct { - char * bus_name; - char * object_path; - char * interface_name; - char * method_name; - GVariant * parameters; - GDBusConnection * connection; + char *bus_name; + char *object_path; + char *interface_name; + char *method_name; + GVariant *parameters; + GDBusConnection *connection; const GVariantType *reply_type; int timeout_msec; } CallAsyncInfo; @@ -295,8 +295,8 @@ static void call_cb(GObject *source, GAsyncResult *result, gpointer user_data) { gs_unref_object GTask *task = user_data; - GError * error = NULL; - GVariant * ret; + GError *error = NULL; + GVariant *ret; ret = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), result, &error); if (!ret) { @@ -311,9 +311,9 @@ static void call_bus_get_cb(GObject *source, GAsyncResult *result, gpointer user_data) { gs_unref_object GTask *task = user_data; - GCancellable * cancellable; - CallAsyncInfo * info; - GError * error = NULL; + GCancellable *cancellable; + CallAsyncInfo *info; + GError *error = NULL; info = g_task_get_task_data(task); info->connection = g_bus_get_finish(result, &error); @@ -340,18 +340,18 @@ call_bus_get_cb(GObject *source, GAsyncResult *result, gpointer user_data) void nm_dbus_call(GBusType bus_type, - const char * bus_name, - const char * object_path, - const char * interface_name, - const char * method_name, - GVariant * parameters, + const char *bus_name, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, const GVariantType *reply_type, - GCancellable * cancellable, + GCancellable *cancellable, int timeout_msec, GAsyncReadyCallback callback, gpointer user_data) { - GTask * task; + GTask *task; CallAsyncInfo *info; info = g_new(CallAsyncInfo, 1); @@ -385,7 +385,7 @@ gboolean _nm_dbus_error_is(GError *error, ...) { gs_free char *dbus_error = NULL; - const char * name; + const char *name; va_list ap; dbus_error = g_dbus_error_get_remote_error(error); @@ -408,7 +408,7 @@ _nm_dbus_error_is(GError *error, ...) typedef struct { GDBusConnection **p_dbus_connection; - GError ** p_error; + GError **p_error; } BusGetData; static void @@ -433,12 +433,12 @@ _bus_get_cb(GObject *source, GAsyncResult *result, gpointer user_data) GDBusConnection * nm_g_bus_get_blocking(GCancellable *cancellable, GError **error) { - gs_free_error GError *local_error = NULL; + gs_free_error GError *local_error = NULL; gs_unref_object GDBusConnection *dbus_connection = NULL; - GMainContext * main_context = g_main_context_get_thread_default(); + GMainContext *main_context = g_main_context_get_thread_default(); BusGetData data = { - .p_dbus_connection = &dbus_connection, - .p_error = &local_error, + .p_dbus_connection = &dbus_connection, + .p_error = &local_error, }; g_bus_get(G_BUS_TYPE_SYSTEM, cancellable, _bus_get_cb, &data); @@ -471,9 +471,9 @@ nm_dbus_connection_call_blocking_callback(GObject *source, GAsyncResult *res, gp GVariant * nm_dbus_connection_call_blocking(NMDBusConnectionCallBlockingData *data, GError **error) { - GMainContext *main_context = g_main_context_get_thread_default(); - gs_free_error GError *local_error = NULL; - gs_unref_variant GVariant *result = NULL; + GMainContext *main_context = g_main_context_get_thread_default(); + gs_free_error GError *local_error = NULL; + gs_unref_variant GVariant *result = NULL; nm_assert(data); diff --git a/src/libnm-glib-aux/nm-dbus-aux.h b/src/libnm-glib-aux/nm-dbus-aux.h index 420a0c55..dfba61b0 100644 --- a/src/libnm-glib-aux/nm-dbus-aux.h +++ b/src/libnm-glib-aux/nm-dbus-aux.h @@ -30,10 +30,10 @@ typedef void (*NMDBusConnectionCallDefaultCb)(GVariant *result, GError *error, g /*****************************************************************************/ static inline void -nm_dbus_connection_call_start_service_by_name(GDBusConnection * dbus_connection, - const char * name, +nm_dbus_connection_call_start_service_by_name(GDBusConnection *dbus_connection, + const char *name, int timeout_msec, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -54,8 +54,8 @@ nm_dbus_connection_call_start_service_by_name(GDBusConnection * dbus_connectio /*****************************************************************************/ static inline guint -nm_dbus_connection_signal_subscribe_name_owner_changed(GDBusConnection * dbus_connection, - const char * service_name, +nm_dbus_connection_signal_subscribe_name_owner_changed(GDBusConnection *dbus_connection, + const char *service_name, GDBusSignalCallback callback, gpointer user_data, GDestroyNotify user_data_free_func) @@ -74,22 +74,22 @@ nm_dbus_connection_signal_subscribe_name_owner_changed(GDBusConnection * dbus_ } typedef void (*NMDBusConnectionCallGetNameOwnerCb)(const char *name_owner, - GError * error, + GError *error, gpointer user_data); -void nm_dbus_connection_call_get_name_owner(GDBusConnection * dbus_connection, - const char * service_name, +void nm_dbus_connection_call_get_name_owner(GDBusConnection *dbus_connection, + const char *service_name, int timeout_msec, - GCancellable * cancellable, + GCancellable *cancellable, NMDBusConnectionCallGetNameOwnerCb callback, gpointer user_data); static inline void -nm_dbus_connection_call_request_name(GDBusConnection * dbus_connection, - const char * name, +nm_dbus_connection_call_request_name(GDBusConnection *dbus_connection, + const char *name, guint32 flags, int timeout_msec, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -108,10 +108,10 @@ nm_dbus_connection_call_request_name(GDBusConnection * dbus_connection, } static inline guint -nm_dbus_connection_signal_subscribe_properties_changed(GDBusConnection * dbus_connection, - const char * bus_name, - const char * object_path, - const char * interface_name, +nm_dbus_connection_signal_subscribe_properties_changed(GDBusConnection *dbus_connection, + const char *bus_name, + const char *object_path, + const char *interface_name, GDBusSignalCallback callback, gpointer user_data, GDestroyNotify user_data_free_func) @@ -138,33 +138,33 @@ nm_dbus_connection_signal_subscribe_properties_changed(GDBusConnection * dbus_ user_data_free_func); } -void nm_dbus_connection_call_get_all(GDBusConnection * dbus_connection, - const char * bus_name, - const char * object_path, - const char * interface_name, +void nm_dbus_connection_call_get_all(GDBusConnection *dbus_connection, + const char *bus_name, + const char *object_path, + const char *interface_name, int timeout_msec, - GCancellable * cancellable, + GCancellable *cancellable, NMDBusConnectionCallDefaultCb callback, gpointer user_data); -void nm_dbus_connection_call_set(GDBusConnection * dbus_connection, - const char * bus_name, - const char * object_path, - const char * interface_name, - const char * property_name, - GVariant * value, +void nm_dbus_connection_call_set(GDBusConnection *dbus_connection, + const char *bus_name, + const char *object_path, + const char *interface_name, + const char *property_name, + GVariant *value, int timeout_msec, - GCancellable * cancellable, + GCancellable *cancellable, NMDBusConnectionCallDefaultCb callback, gpointer user_data); /*****************************************************************************/ static inline guint -nm_dbus_connection_signal_subscribe_object_manager(GDBusConnection * dbus_connection, - const char * service_name, - const char * object_path, - const char * signal_name, +nm_dbus_connection_signal_subscribe_object_manager(GDBusConnection *dbus_connection, + const char *service_name, + const char *object_path, + const char *signal_name, GDBusSignalCallback callback, gpointer user_data, GDestroyNotify user_data_free_func) @@ -181,12 +181,12 @@ nm_dbus_connection_signal_subscribe_object_manager(GDBusConnection * dbus_conn user_data_free_func); } -void nm_dbus_connection_call_get_managed_objects(GDBusConnection * dbus_connection, - const char * bus_name, - const char * object_path, +void nm_dbus_connection_call_get_managed_objects(GDBusConnection *dbus_connection, + const char *bus_name, + const char *object_path, GDBusCallFlags flags, int timeout_msec, - GCancellable * cancellable, + GCancellable *cancellable, NMDBusConnectionCallDefaultCb callback, gpointer user_data); @@ -195,28 +195,28 @@ void nm_dbus_connection_call_get_managed_objects(GDBusConnection * d void nm_dbus_connection_call_finish_void_cb(GObject *source, GAsyncResult *result, gpointer user_data); -void nm_dbus_connection_call_finish_void_strip_dbus_error_cb(GObject * source, +void nm_dbus_connection_call_finish_void_strip_dbus_error_cb(GObject *source, GAsyncResult *result, gpointer user_data); -void nm_dbus_connection_call_finish_variant_cb(GObject * source, +void nm_dbus_connection_call_finish_variant_cb(GObject *source, GAsyncResult *result, gpointer user_data); -void nm_dbus_connection_call_finish_variant_strip_dbus_error_cb(GObject * source, +void nm_dbus_connection_call_finish_variant_strip_dbus_error_cb(GObject *source, GAsyncResult *result, gpointer user_data); /*****************************************************************************/ void nm_dbus_call(GBusType bus_type, - const char * bus_name, - const char * object_path, - const char * interface_name, - const char * method_name, - GVariant * parameters, + const char *bus_name, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, const GVariantType *reply_type, - GCancellable * cancellable, + GCancellable *cancellable, int timeout_msec, GAsyncReadyCallback callback, gpointer user_data); @@ -244,7 +244,7 @@ GDBusConnection *nm_g_bus_get_blocking(GCancellable *cancellable, GError **error typedef struct { GVariant *result; - GError * error; + GError *error; } NMDBusConnectionCallBlockingData; void diff --git a/src/libnm-glib-aux/nm-dedup-multi.c b/src/libnm-glib-aux/nm-dedup-multi.c index f77bb3cd..7d451d0d 100644 --- a/src/libnm-glib-aux/nm-dedup-multi.c +++ b/src/libnm-glib-aux/nm-dedup-multi.c @@ -21,7 +21,7 @@ typedef struct { * always non-NULL. * */ CList lst_entries_sentinel; - const NMDedupMultiObj * obj; + const NMDedupMultiObj *obj; const NMDedupMultiIdxType *idx_type; bool lookup_head; } LookupEntry; @@ -65,9 +65,9 @@ nm_dedup_multi_idx_type_init(NMDedupMultiIdxType *idx_type, const NMDedupMultiId /*****************************************************************************/ static NMDedupMultiEntry * -_entry_lookup_obj(const NMDedupMultiIndex * self, +_entry_lookup_obj(const NMDedupMultiIndex *self, const NMDedupMultiIdxType *idx_type, - const NMDedupMultiObj * obj) + const NMDedupMultiObj *obj) { const LookupEntry stack_entry = { .obj = obj, @@ -80,15 +80,15 @@ _entry_lookup_obj(const NMDedupMultiIndex * self, } static NMDedupMultiHeadEntry * -_entry_lookup_head(const NMDedupMultiIndex * self, +_entry_lookup_head(const NMDedupMultiIndex *self, const NMDedupMultiIdxType *idx_type, - const NMDedupMultiObj * obj) + const NMDedupMultiObj *obj) { NMDedupMultiHeadEntry *head_entry; const LookupEntry stack_entry = { - .obj = obj, - .idx_type = idx_type, - .lookup_head = TRUE, + .obj = obj, + .idx_type = idx_type, + .lookup_head = TRUE, }; ASSERT_idx_type(idx_type); @@ -108,13 +108,13 @@ _entry_lookup_head(const NMDedupMultiIndex * self, } static void -_entry_unpack(const NMDedupMultiEntry * entry, +_entry_unpack(const NMDedupMultiEntry *entry, const NMDedupMultiIdxType **out_idx_type, - const NMDedupMultiObj ** out_obj, - gboolean * out_lookup_head) + const NMDedupMultiObj **out_obj, + gboolean *out_lookup_head) { const NMDedupMultiHeadEntry *head_entry; - const LookupEntry * lookup_entry; + const LookupEntry *lookup_entry; nm_assert(entry); @@ -162,7 +162,7 @@ static guint _dict_idx_entries_hash(const NMDedupMultiEntry *entry) { const NMDedupMultiIdxType *idx_type; - const NMDedupMultiObj * obj; + const NMDedupMultiObj *obj; gboolean lookup_head; NMHashState h; @@ -185,7 +185,7 @@ static gboolean _dict_idx_entries_equal(const NMDedupMultiEntry *entry_a, const NMDedupMultiEntry *entry_b) { const NMDedupMultiIdxType *idx_type_a, *idx_type_b; - const NMDedupMultiObj * obj_a, *obj_b; + const NMDedupMultiObj *obj_a, *obj_b; gboolean lookup_head_a, lookup_head_b; _entry_unpack(entry_a, &idx_type_a, &obj_a, &lookup_head_a); @@ -203,15 +203,15 @@ _dict_idx_entries_equal(const NMDedupMultiEntry *entry_a, const NMDedupMultiEntr /*****************************************************************************/ static gboolean -_add(NMDedupMultiIndex * self, - NMDedupMultiIdxType * idx_type, - const NMDedupMultiObj * obj, - NMDedupMultiEntry * entry, +_add(NMDedupMultiIndex *self, + NMDedupMultiIdxType *idx_type, + const NMDedupMultiObj *obj, + NMDedupMultiEntry *entry, NMDedupMultiIdxMode mode, - const NMDedupMultiEntry * entry_order, - NMDedupMultiHeadEntry * head_existing, + const NMDedupMultiEntry *entry_order, + NMDedupMultiHeadEntry *head_existing, const NMDedupMultiEntry **out_entry, - const NMDedupMultiObj ** out_obj_old) + const NMDedupMultiObj **out_obj_old) { NMDedupMultiHeadEntry *head_entry; const NMDedupMultiObj *obj_new, *obj_old; @@ -365,11 +365,11 @@ _add(NMDedupMultiIndex * self, } gboolean -nm_dedup_multi_index_add(NMDedupMultiIndex * self, - NMDedupMultiIdxType * idx_type, +nm_dedup_multi_index_add(NMDedupMultiIndex *self, + NMDedupMultiIdxType *idx_type, /*const NMDedupMultiObj * */ gconstpointer obj, NMDedupMultiIdxMode mode, - const NMDedupMultiEntry ** out_entry, + const NMDedupMultiEntry **out_entry, /* const NMDedupMultiObj ** */ gpointer out_obj_old) { NMDedupMultiEntry *entry; @@ -423,14 +423,14 @@ nm_dedup_multi_index_add(NMDedupMultiIndex * self, * Return: %TRUE if anything changed, %FALSE if nothing changed. */ gboolean -nm_dedup_multi_index_add_full(NMDedupMultiIndex * self, - NMDedupMultiIdxType * idx_type, +nm_dedup_multi_index_add_full(NMDedupMultiIndex *self, + NMDedupMultiIdxType *idx_type, /*const NMDedupMultiObj * */ gconstpointer obj, NMDedupMultiIdxMode mode, - const NMDedupMultiEntry * entry_order, - const NMDedupMultiEntry * entry_existing, - const NMDedupMultiHeadEntry * head_existing, - const NMDedupMultiEntry ** out_entry, + const NMDedupMultiEntry *entry_order, + const NMDedupMultiEntry *entry_existing, + const NMDedupMultiHeadEntry *head_existing, + const NMDedupMultiEntry **out_entry, /* const NMDedupMultiObj ** */ gpointer out_obj_old) { NMDedupMultiEntry *entry; @@ -472,7 +472,7 @@ _remove_entry(NMDedupMultiIndex *self, NMDedupMultiEntry *entry, gboolean *out_h { const NMDedupMultiObj *obj; NMDedupMultiHeadEntry *head_entry; - NMDedupMultiIdxType * idx_type; + NMDedupMultiIdxType *idx_type; nm_assert(self); nm_assert(entry); @@ -519,14 +519,14 @@ _remove_entry(NMDedupMultiIndex *self, NMDedupMultiEntry *entry, gboolean *out_h } static guint -_remove_head(NMDedupMultiIndex * self, +_remove_head(NMDedupMultiIndex *self, NMDedupMultiHeadEntry *head_entry, gboolean remove_all /* otherwise just dirty ones */, gboolean mark_survivors_dirty) { guint n; gboolean head_entry_removed; - CList * iter_entry, *iter_entry_safe; + CList *iter_entry, *iter_entry_safe; nm_assert(self); nm_assert(head_entry); @@ -552,7 +552,7 @@ _remove_head(NMDedupMultiIndex * self, } static guint -_remove_idx_entry(NMDedupMultiIndex * self, +_remove_idx_entry(NMDedupMultiIndex *self, NMDedupMultiIdxType *idx_type, gboolean remove_all /* otherwise just dirty ones */, gboolean mark_survivors_dirty) @@ -588,8 +588,8 @@ nm_dedup_multi_index_remove_entry(NMDedupMultiIndex *self, gconstpointer entry) } guint -nm_dedup_multi_index_remove_obj(NMDedupMultiIndex * self, - NMDedupMultiIdxType * idx_type, +nm_dedup_multi_index_remove_obj(NMDedupMultiIndex *self, + NMDedupMultiIdxType *idx_type, /*const NMDedupMultiObj * */ gconstpointer obj, /*const NMDedupMultiObj ** */ gconstpointer *out_obj) { @@ -611,8 +611,8 @@ nm_dedup_multi_index_remove_obj(NMDedupMultiIndex * sel } guint -nm_dedup_multi_index_remove_head(NMDedupMultiIndex * self, - NMDedupMultiIdxType * idx_type, +nm_dedup_multi_index_remove_head(NMDedupMultiIndex *self, + NMDedupMultiIdxType *idx_type, /*const NMDedupMultiObj * */ gconstpointer obj) { const NMDedupMultiHeadEntry *entry; @@ -643,8 +643,8 @@ nm_dedup_multi_index_remove_idx(NMDedupMultiIndex *self, NMDedupMultiIdxType *id * Returns: the cache entry or %NULL if the entry wasn't found. */ const NMDedupMultiEntry * -nm_dedup_multi_index_lookup_obj(const NMDedupMultiIndex * self, - const NMDedupMultiIdxType * idx_type, +nm_dedup_multi_index_lookup_obj(const NMDedupMultiIndex *self, + const NMDedupMultiIdxType *idx_type, /*const NMDedupMultiObj * */ gconstpointer obj) { g_return_val_if_fail(self, FALSE); @@ -669,8 +669,8 @@ nm_dedup_multi_index_lookup_obj(const NMDedupMultiIndex * self, * Returns: the cache entry or %NULL if the entry wasn't found. */ const NMDedupMultiHeadEntry * -nm_dedup_multi_index_lookup_head(const NMDedupMultiIndex * self, - const NMDedupMultiIdxType * idx_type, +nm_dedup_multi_index_lookup_head(const NMDedupMultiIndex *self, + const NMDedupMultiIdxType *idx_type, /*const NMDedupMultiObj * */ gconstpointer obj) { g_return_val_if_fail(self, FALSE); @@ -682,12 +682,12 @@ nm_dedup_multi_index_lookup_head(const NMDedupMultiIndex * self /*****************************************************************************/ void -nm_dedup_multi_index_dirty_set_head(NMDedupMultiIndex * self, - const NMDedupMultiIdxType * idx_type, +nm_dedup_multi_index_dirty_set_head(NMDedupMultiIndex *self, + const NMDedupMultiIdxType *idx_type, /*const NMDedupMultiObj * */ gconstpointer obj) { NMDedupMultiHeadEntry *head_entry; - CList * iter_entry; + CList *iter_entry; g_return_if_fail(self); g_return_if_fail(idx_type); @@ -740,7 +740,7 @@ nm_dedup_multi_index_dirty_set_idx(NMDedupMultiIndex *self, const NMDedupMultiId * Returns: number of deleted entries. */ guint -nm_dedup_multi_index_dirty_remove_idx(NMDedupMultiIndex * self, +nm_dedup_multi_index_dirty_remove_idx(NMDedupMultiIndex *self, NMDedupMultiIdxType *idx_type, gboolean mark_survivors_dirty) { @@ -770,7 +770,7 @@ _dict_idx_objs_equal(const NMDedupMultiObj *obj_a, const NMDedupMultiObj *obj_b) } void -nm_dedup_multi_index_obj_release(NMDedupMultiIndex * self, +nm_dedup_multi_index_obj_release(NMDedupMultiIndex *self, /* const NMDedupMultiObj * */ gconstpointer obj) { nm_assert(self); @@ -784,7 +784,7 @@ nm_dedup_multi_index_obj_release(NMDedupMultiIndex * sel } gconstpointer -nm_dedup_multi_index_obj_find(NMDedupMultiIndex * self, +nm_dedup_multi_index_obj_find(NMDedupMultiIndex *self, /* const NMDedupMultiObj * */ gconstpointer obj) { g_return_val_if_fail(self, NULL); @@ -794,7 +794,7 @@ nm_dedup_multi_index_obj_find(NMDedupMultiIndex * self, } gconstpointer -nm_dedup_multi_index_obj_intern(NMDedupMultiIndex * self, +nm_dedup_multi_index_obj_intern(NMDedupMultiIndex *self, /* const NMDedupMultiObj * */ gconstpointer obj) { const NMDedupMultiObj *obj_new = obj; @@ -885,13 +885,13 @@ nm_dedup_multi_obj_clone(const NMDedupMultiObj *obj) } gconstpointer * -nm_dedup_multi_objs_to_array_head(const NMDedupMultiHeadEntry * head_entry, +nm_dedup_multi_objs_to_array_head(const NMDedupMultiHeadEntry *head_entry, NMDedupMultiFcnSelectPredicate predicate, gpointer user_data, - guint * out_len) + guint *out_len) { gconstpointer *result; - CList * iter; + CList *iter; guint i; if (!head_entry) { @@ -923,12 +923,12 @@ nm_dedup_multi_objs_to_array_head(const NMDedupMultiHeadEntry * head_entry, } GPtrArray * -nm_dedup_multi_objs_to_ptr_array_head(const NMDedupMultiHeadEntry * head_entry, +nm_dedup_multi_objs_to_ptr_array_head(const NMDedupMultiHeadEntry *head_entry, NMDedupMultiFcnSelectPredicate predicate, gpointer user_data) { GPtrArray *result; - CList * iter; + CList *iter; if (!head_entry) return NULL; @@ -1028,8 +1028,8 @@ nm_dedup_multi_index_unref(NMDedupMultiIndex *self) { GHashTableIter iter; const NMDedupMultiIdxType *idx_type; - NMDedupMultiEntry * entry; - const NMDedupMultiObj * obj; + NMDedupMultiEntry *entry; + const NMDedupMultiObj *obj; g_return_val_if_fail(self, NULL); g_return_val_if_fail(self->ref_count > 0, NULL); diff --git a/src/libnm-glib-aux/nm-dedup-multi.h b/src/libnm-glib-aux/nm-dedup-multi.h index fb1cb863..0fa47422 100644 --- a/src/libnm-glib-aux/nm-dedup-multi.h +++ b/src/libnm-glib-aux/nm-dedup-multi.h @@ -83,14 +83,14 @@ void nm_dedup_multi_obj_unref(const NMDedupMultiObj *obj); const NMDedupMultiObj *nm_dedup_multi_obj_clone(const NMDedupMultiObj *obj); gboolean nm_dedup_multi_obj_needs_clone(const NMDedupMultiObj *obj); -gconstpointer nm_dedup_multi_index_obj_intern(NMDedupMultiIndex * self, +gconstpointer nm_dedup_multi_index_obj_intern(NMDedupMultiIndex *self, /* const NMDedupMultiObj * */ gconstpointer obj); -void nm_dedup_multi_index_obj_release(NMDedupMultiIndex * self, +void nm_dedup_multi_index_obj_release(NMDedupMultiIndex *self, /* const NMDedupMultiObj * */ gconstpointer obj); /* const NMDedupMultiObj * */ gconstpointer -nm_dedup_multi_index_obj_find(NMDedupMultiIndex * self, +nm_dedup_multi_index_obj_find(NMDedupMultiIndex *self, /* const NMDedupMultiObj * */ gconstpointer obj); /*****************************************************************************/ @@ -132,18 +132,18 @@ struct _NMDedupMultiIdxType { guint len; }; -void nm_dedup_multi_idx_type_init(NMDedupMultiIdxType * idx_type, +void nm_dedup_multi_idx_type_init(NMDedupMultiIdxType *idx_type, const NMDedupMultiIdxTypeClass *klass); struct _NMDedupMultiIdxTypeClass { NMObjBaseClass parent; void (*idx_obj_id_hash_update)(const NMDedupMultiIdxType *idx_type, - const NMDedupMultiObj * obj, - struct _NMHashState * h); + const NMDedupMultiObj *obj, + struct _NMHashState *h); 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); /* an NMDedupMultiIdxTypeClass which implements partitioning of the * tracked objects, must implement the idx_obj_partition*() functions. @@ -153,17 +153,17 @@ struct _NMDedupMultiIdxTypeClass { * routes that don't have a valid ifindex. If the idx-type says that the * object is not partitionable, it is never added to the NMDedupMultiIndex. */ gboolean (*idx_obj_partitionable)(const NMDedupMultiIdxType *idx_type, - const NMDedupMultiObj * obj); + const NMDedupMultiObj *obj); void (*idx_obj_partition_hash_update)(const NMDedupMultiIdxType *idx_type, - const NMDedupMultiObj * obj, - struct _NMHashState * h); + const NMDedupMultiObj *obj, + struct _NMHashState *h); gboolean (*idx_obj_partition_equal)(const NMDedupMultiIdxType *idx_type, - const NMDedupMultiObj * obj_a, - const NMDedupMultiObj * obj_b); + const NMDedupMultiObj *obj_a, + const NMDedupMultiObj *obj_b); }; static inline gboolean -nm_dedup_multi_idx_type_id_equal(const NMDedupMultiIdxType * idx_type, +nm_dedup_multi_idx_type_id_equal(const NMDedupMultiIdxType *idx_type, /* const NMDedupMultiObj * */ gconstpointer obj_a, /* const NMDedupMultiObj * */ gconstpointer obj_b) { @@ -172,7 +172,7 @@ nm_dedup_multi_idx_type_id_equal(const NMDedupMultiIdxType * idx } static inline gboolean -nm_dedup_multi_idx_type_partition_equal(const NMDedupMultiIdxType * idx_type, +nm_dedup_multi_idx_type_partition_equal(const NMDedupMultiIdxType *idx_type, /* const NMDedupMultiObj * */ gconstpointer obj_a, /* const NMDedupMultiObj * */ gconstpointer obj_b) { @@ -255,54 +255,54 @@ _nm_auto_unref_dedup_multi_index(NMDedupMultiIndex **v) #define NM_DEDUP_MULTI_ENTRY_MISSING ((const NMDedupMultiEntry *) GUINT_TO_POINTER(1)) #define NM_DEDUP_MULTI_HEAD_ENTRY_MISSING ((const NMDedupMultiHeadEntry *) GUINT_TO_POINTER(1)) -gboolean nm_dedup_multi_index_add_full(NMDedupMultiIndex * self, - NMDedupMultiIdxType * idx_type, +gboolean nm_dedup_multi_index_add_full(NMDedupMultiIndex *self, + NMDedupMultiIdxType *idx_type, /*const NMDedupMultiObj * */ gconstpointer obj, NMDedupMultiIdxMode mode, - const NMDedupMultiEntry * entry_order, - const NMDedupMultiEntry * entry_existing, - const NMDedupMultiHeadEntry * head_existing, - const NMDedupMultiEntry ** out_entry, + const NMDedupMultiEntry *entry_order, + const NMDedupMultiEntry *entry_existing, + const NMDedupMultiHeadEntry *head_existing, + const NMDedupMultiEntry **out_entry, /* const NMDedupMultiObj ** */ gpointer out_obj_old); -gboolean nm_dedup_multi_index_add(NMDedupMultiIndex * self, - NMDedupMultiIdxType * idx_type, +gboolean nm_dedup_multi_index_add(NMDedupMultiIndex *self, + NMDedupMultiIdxType *idx_type, /*const NMDedupMultiObj * */ gconstpointer obj, NMDedupMultiIdxMode mode, - const NMDedupMultiEntry ** out_entry, + const NMDedupMultiEntry **out_entry, /* const NMDedupMultiObj ** */ gpointer out_obj_old); const NMDedupMultiEntry * -nm_dedup_multi_index_lookup_obj(const NMDedupMultiIndex * self, - const NMDedupMultiIdxType * idx_type, +nm_dedup_multi_index_lookup_obj(const NMDedupMultiIndex *self, + const NMDedupMultiIdxType *idx_type, /*const NMDedupMultiObj * */ gconstpointer obj); const NMDedupMultiHeadEntry * -nm_dedup_multi_index_lookup_head(const NMDedupMultiIndex * self, - const NMDedupMultiIdxType * idx_type, +nm_dedup_multi_index_lookup_head(const NMDedupMultiIndex *self, + const NMDedupMultiIdxType *idx_type, /*const NMDedupMultiObj * */ gconstpointer obj); guint nm_dedup_multi_index_remove_entry(NMDedupMultiIndex *self, gconstpointer entry); -guint nm_dedup_multi_index_remove_obj(NMDedupMultiIndex * self, - NMDedupMultiIdxType * idx_type, +guint nm_dedup_multi_index_remove_obj(NMDedupMultiIndex *self, + NMDedupMultiIdxType *idx_type, /*const NMDedupMultiObj * */ gconstpointer obj, /*const NMDedupMultiObj ** */ gconstpointer *out_obj); -guint nm_dedup_multi_index_remove_head(NMDedupMultiIndex * self, - NMDedupMultiIdxType * idx_type, +guint nm_dedup_multi_index_remove_head(NMDedupMultiIndex *self, + NMDedupMultiIdxType *idx_type, /*const NMDedupMultiObj * */ gconstpointer obj); guint nm_dedup_multi_index_remove_idx(NMDedupMultiIndex *self, NMDedupMultiIdxType *idx_type); -void nm_dedup_multi_index_dirty_set_head(NMDedupMultiIndex * self, - const NMDedupMultiIdxType * idx_type, +void nm_dedup_multi_index_dirty_set_head(NMDedupMultiIndex *self, + const NMDedupMultiIdxType *idx_type, /*const NMDedupMultiObj * */ gconstpointer obj); -void nm_dedup_multi_index_dirty_set_idx(NMDedupMultiIndex * self, +void nm_dedup_multi_index_dirty_set_idx(NMDedupMultiIndex *self, const NMDedupMultiIdxType *idx_type); -guint nm_dedup_multi_index_dirty_remove_idx(NMDedupMultiIndex * self, +guint nm_dedup_multi_index_dirty_remove_idx(NMDedupMultiIndex *self, NMDedupMultiIdxType *idx_type, gboolean mark_survivors_dirty); @@ -395,11 +395,11 @@ nm_dedup_multi_iter_prev(NMDedupMultiIter *iter) typedef gboolean (*NMDedupMultiFcnSelectPredicate)(/* const NMDedupMultiObj * */ gconstpointer obj, gpointer user_data); -gconstpointer *nm_dedup_multi_objs_to_array_head(const NMDedupMultiHeadEntry * head_entry, +gconstpointer *nm_dedup_multi_objs_to_array_head(const NMDedupMultiHeadEntry *head_entry, NMDedupMultiFcnSelectPredicate predicate, gpointer user_data, - guint * out_len); -GPtrArray * nm_dedup_multi_objs_to_ptr_array_head(const NMDedupMultiHeadEntry * head_entry, + guint *out_len); +GPtrArray *nm_dedup_multi_objs_to_ptr_array_head(const NMDedupMultiHeadEntry *head_entry, NMDedupMultiFcnSelectPredicate predicate, gpointer user_data); diff --git a/src/libnm-glib-aux/nm-enum-utils.c b/src/libnm-glib-aux/nm-enum-utils.c index f97cdfcb..3b9b7e8d 100644 --- a/src/libnm-glib-aux/nm-enum-utils.c +++ b/src/libnm-glib-aux/nm-enum-utils.c @@ -17,7 +17,7 @@ _ASSERT_enum_values_info(GType type, const NMUtilsEnumValueInfo *value_infos) { #if NM_MORE_ASSERTS > 5 nm_auto_unref_gtypeclass GTypeClass *klass = NULL; - gs_unref_hashtable GHashTable *ht = NULL; + gs_unref_hashtable GHashTable *ht = NULL; klass = g_type_class_ref(type); @@ -109,7 +109,7 @@ _enum_is_valid_flags_nick(const char *str) char * _nm_utils_enum_to_str_full(GType type, int value, - const char * flags_separator, + const char *flags_separator, const NMUtilsEnumValueInfo *value_infos) { nm_auto_unref_gtypeclass GTypeClass *klass = NULL; @@ -199,18 +199,18 @@ _find_value_info(const NMUtilsEnumValueInfo *value_infos, const char *needle) gboolean _nm_utils_enum_from_str_full(GType type, - const char * str, - int * out_value, - char ** err_token, + const char *str, + int *out_value, + char **err_token, const NMUtilsEnumValueInfo *value_infos) { nm_auto_unref_gtypeclass GTypeClass *klass = NULL; gboolean ret = FALSE; int value = 0; - gs_free char * str_clone = NULL; - char * s; + gs_free char *str_clone = NULL; + char *s; gint64 v64; - const NMUtilsEnumValueInfo * nick; + const NMUtilsEnumValueInfo *nick; g_return_val_if_fail(str, FALSE); @@ -317,7 +317,7 @@ const char ** _nm_utils_enum_get_values(GType type, int from, int to) { GTypeClass *klass; - GPtrArray * array; + GPtrArray *array; int i; char sbuf[64]; diff --git a/src/libnm-glib-aux/nm-enum-utils.h b/src/libnm-glib-aux/nm-enum-utils.h index 89be54e7..6478cadf 100644 --- a/src/libnm-glib-aux/nm-enum-utils.h +++ b/src/libnm-glib-aux/nm-enum-utils.h @@ -15,14 +15,14 @@ typedef struct _NMUtilsEnumValueInfo { int value; } NMUtilsEnumValueInfo; -char * _nm_utils_enum_to_str_full(GType type, +char *_nm_utils_enum_to_str_full(GType type, int value, - const char * sep, + const char *sep, const NMUtilsEnumValueInfo *value_infos); gboolean _nm_utils_enum_from_str_full(GType type, - const char * str, - int * out_value, - char ** err_token, + const char *str, + int *out_value, + char **err_token, const NMUtilsEnumValueInfo *value_infos); const char **_nm_utils_enum_get_values(GType type, int from, int to); diff --git a/src/libnm-glib-aux/nm-errno.c b/src/libnm-glib-aux/nm-errno.c index 0426a21d..14d93d64 100644 --- a/src/libnm-glib-aux/nm-errno.c +++ b/src/libnm-glib-aux/nm-errno.c @@ -156,7 +156,7 @@ const char * nm_strerror_native(int errsv) { static _nm_thread_local char *buf_static = NULL; - char * buf; + char *buf; buf = buf_static; if (G_UNLIKELY(!buf)) { diff --git a/src/libnm-glib-aux/nm-glib.h b/src/libnm-glib-aux/nm-glib.h index 49470d92..4ab9cbbd 100644 --- a/src/libnm-glib-aux/nm-glib.h +++ b/src/libnm-glib-aux/nm-glib.h @@ -195,7 +195,7 @@ __nmtst_g_test_skip(const char *msg) /* g_test_add_data_func_full() is only available since glib 2.34. Add a compatibility wrapper. */ static inline void -__g_test_add_data_func_full(const char * testpath, +__g_test_add_data_func_full(const char *testpath, gpointer test_data, GTestDataFunc test_func, GDestroyNotify data_free_func) @@ -311,7 +311,7 @@ _nm_g_ptr_array_insert(GPtrArray *array, int index_, gpointer data) static inline gboolean _g_key_file_save_to_file(GKeyFile *key_file, const char *filename, GError **error) { - char * contents; + char *contents; gboolean success; gsize length; @@ -484,7 +484,7 @@ _nm_g_variant_new_take_string(char *string) #if !GLIB_CHECK_VERSION(2, 38, 0) _nm_printf(1, 2) static inline GVariant *_nm_g_variant_new_printf(const char *format_string, ...) { - char * string; + char *string; va_list ap; g_return_val_if_fail(format_string, NULL); @@ -650,10 +650,10 @@ _g_atomic_pointer_compare_and_exchange(void **atomic, void *oldval, void *newval #if !GLIB_CHECK_VERSION(2, 58, 0) static inline gboolean -g_hash_table_steal_extended(GHashTable * hash_table, +g_hash_table_steal_extended(GHashTable *hash_table, gconstpointer lookup_key, - gpointer * stolen_key, - gpointer * stolen_value) + gpointer *stolen_key, + gpointer *stolen_value) { g_assert(stolen_key); g_assert(stolen_value); diff --git a/src/libnm-glib-aux/nm-hash-utils.c b/src/libnm-glib-aux/nm-hash-utils.c index a6949ebd..68b33998 100644 --- a/src/libnm-glib-aux/nm-hash-utils.c +++ b/src/libnm-glib-aux/nm-hash-utils.c @@ -138,12 +138,6 @@ nm_hash_str(const char *str) return nm_hash_complete(&h); } -guint -nm_str_hash(gconstpointer str) -{ - return nm_hash_str(str); -} - guint nm_hash_ptr(gconstpointer ptr) { @@ -156,12 +150,6 @@ nm_hash_ptr(gconstpointer ptr) return nm_hash_complete(&h); } -guint -nm_direct_hash(gconstpointer ptr) -{ - return nm_hash_ptr(ptr); -} - /*****************************************************************************/ guint @@ -257,7 +245,7 @@ nm_ppdirect_equal(gconstpointer a, gconstpointer b) guint nm_g_bytes_hash(gconstpointer p) { - GBytes * ptr = (GBytes *) p; + GBytes *ptr = (GBytes *) p; gconstpointer arr; gsize len; @@ -284,3 +272,31 @@ nm_pg_bytes_equal(gconstpointer a, gconstpointer b) return g_bytes_equal(*ptr_a, *ptr_b); } + +/*****************************************************************************/ + +guint64 +nm_hash_obfuscate_ptr(guint static_seed, gconstpointer val) +{ + NMHashState h; + + if (NM_MORE_ASSERTS > 0) { + static int obfuscate_static = -1; + int obfuscate; + +again: + obfuscate = g_atomic_int_get(&obfuscate_static); + if (G_UNLIKELY(obfuscate == -1)) { + obfuscate = _nm_utils_ascii_str_to_int64(g_getenv("NM_OBFUSCATE_PTR"), 10, 0, 1, 1); + if (!g_atomic_int_compare_and_exchange(&obfuscate_static, -1, obfuscate)) + goto again; + } + + if (!obfuscate) + return (uintptr_t) val; + } + + nm_hash_init(&h, static_seed); + nm_hash_update_val(&h, val); + return nm_hash_complete_u64(&h); +} diff --git a/src/libnm-glib-aux/nm-hash-utils.h b/src/libnm-glib-aux/nm-hash-utils.h index d7de2de4..b7ee4dd1 100644 --- a/src/libnm-glib-aux/nm-hash-utils.h +++ b/src/libnm-glib-aux/nm-hash-utils.h @@ -201,10 +201,10 @@ nm_hash_update_str(NMHashState *state, const char *str) #endif guint nm_hash_ptr(gconstpointer ptr); -guint nm_direct_hash(gconstpointer str); +#define nm_direct_hash nm_hash_ptr guint nm_hash_str(const char *str); -guint nm_str_hash(gconstpointer str); +#define nm_str_hash ((guint(*)(gconstpointer str)) nm_hash_str) #define nm_hash_val(static_seed, val) \ ({ \ @@ -284,15 +284,7 @@ gboolean nm_pg_bytes_equal(gconstpointer a, gconstpointer b); * * Note that there is a chance that two different pointer values hash to the same obfuscated * value. So beware of that when reviewing logs. However, such a collision is very unlikely. */ -static inline guint64 -nm_hash_obfuscate_ptr(guint static_seed, gconstpointer val) -{ - NMHashState h; - - nm_hash_init(&h, static_seed); - nm_hash_update_val(&h, val); - return nm_hash_complete_u64(&h); -} +guint64 nm_hash_obfuscate_ptr(guint static_seed, gconstpointer val); /* if you want to log obfuscated pointer for a certain context (like, NMPRuleManager * logging user-tags), then you are advised to use nm_hash_obfuscate_ptr() with your diff --git a/src/libnm-glib-aux/nm-io-utils.c b/src/libnm-glib-aux/nm-io-utils.c index 85a81f69..503f044f 100644 --- a/src/libnm-glib-aux/nm-io-utils.c +++ b/src/libnm-glib-aux/nm-io-utils.c @@ -20,9 +20,9 @@ /*****************************************************************************/ -_nm_printf(4, 5) static int _get_contents_error(GError ** error, +_nm_printf(4, 5) static int _get_contents_error(GError **error, int errsv, - int * out_errsv, + int *out_errsv, const char *format, ...) { @@ -94,14 +94,14 @@ nm_utils_fd_get_contents(int fd, gboolean close_fd, gsize max_length, NMUtilsFileGetContentsFlags flags, - char ** contents, - gsize * length, - int * out_errsv, - GError ** error) + char **contents, + gsize *length, + int *out_errsv, + GError **error) { nm_auto_close int fd_keeper = close_fd ? fd : -1; struct stat stat_buf; - gs_free char * str = NULL; + gs_free char *str = NULL; const bool do_bzero_mem = NM_FLAGS_HAS(flags, NM_UTILS_FILE_GET_CONTENTS_FLAG_SECRET); int errsv; @@ -288,13 +288,13 @@ nm_utils_fd_get_contents(int fd, */ gboolean nm_utils_file_get_contents(int dirfd, - const char * filename, + const char *filename, gsize max_length, NMUtilsFileGetContentsFlags flags, - char ** contents, - gsize * length, - int * out_errsv, - GError ** error) + char **contents, + gsize *length, + int *out_errsv, + GError **error) { int fd; @@ -338,13 +338,13 @@ nm_utils_file_get_contents(int dirfd, * and last modification times. */ gboolean -nm_utils_file_set_contents(const char * filename, - const char * contents, +nm_utils_file_set_contents(const char *filename, + const char *contents, gssize length, mode_t mode, const struct timespec *times, - int * out_errsv, - GError ** error) + int *out_errsv, + GError **error) { gs_free char *tmp_name = NULL; struct stat statbuf; @@ -498,7 +498,7 @@ nm_utils_fd_read(int fd, NMStrBuf *out_string) typedef struct { GSubprocess *subprocess; - GSource * timeout_source; + GSource *timeout_source; } SubprocessTerminateData; static void @@ -527,7 +527,7 @@ void nm_g_subprocess_terminate_in_background(GSubprocess *subprocess, int timeout_msec_before_kill) { SubprocessTerminateData *term_data; - GMainContext * main_context; + GMainContext *main_context; nm_assert(timeout_msec_before_kill > 0); @@ -573,9 +573,9 @@ char ** nm_utils_find_mkstemp_files(const char *dirname, const char *filename) { static const char letters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - DIR * dir; - struct dirent * entry; - GPtrArray * arr = NULL; + DIR *dir; + struct dirent *entry; + GPtrArray *arr = NULL; gsize l; /* We write files with g_file_set_contents() and nm_utils_file_set_contents(). @@ -685,12 +685,12 @@ nm_sd_notify(const char *state) struct sockaddr_un sockaddr; struct iovec iovec; struct msghdr msghdr = { - .msg_iov = &iovec, - .msg_iovlen = 1, - .msg_name = &sockaddr, + .msg_iov = &iovec, + .msg_iovlen = 1, + .msg_name = &sockaddr, }; nm_auto_close int fd = -1; - const char * e; + const char *e; int r; if (!state) diff --git a/src/libnm-glib-aux/nm-io-utils.h b/src/libnm-glib-aux/nm-io-utils.h index 479d0e51..a8503986 100644 --- a/src/libnm-glib-aux/nm-io-utils.h +++ b/src/libnm-glib-aux/nm-io-utils.h @@ -26,27 +26,27 @@ gboolean nm_utils_fd_get_contents(int fd, gboolean close_fd, gsize max_length, NMUtilsFileGetContentsFlags flags, - char ** contents, - gsize * length, - int * out_errsv, - GError ** error); + char **contents, + gsize *length, + int *out_errsv, + GError **error); gboolean nm_utils_file_get_contents(int dirfd, - const char * filename, + const char *filename, gsize max_length, NMUtilsFileGetContentsFlags flags, - char ** contents, - gsize * length, - int * out_errsv, - GError ** error); + char **contents, + gsize *length, + int *out_errsv, + GError **error); -gboolean nm_utils_file_set_contents(const char * filename, - const char * contents, +gboolean nm_utils_file_set_contents(const char *filename, + const char *contents, gssize length, mode_t mode, const struct timespec *times, - int * out_errsv, - GError ** error); + int *out_errsv, + GError **error); struct _NMStrBuf; diff --git a/src/libnm-glib-aux/nm-json-aux.c b/src/libnm-glib-aux/nm-json-aux.c index 0a3b25f8..6216d93c 100644 --- a/src/libnm-glib-aux/nm-json-aux.c +++ b/src/libnm-glib-aux/nm-json-aux.c @@ -155,15 +155,15 @@ nm_json_gstr_append_obj_name(GString *gstr, const char *key, char start_containe typedef struct { NMJsonVt vt; - void * dl_handle; + void *dl_handle; } NMJsonVtInternal; static NMJsonVtInternal * _nm_json_vt_internal_load(void) { NMJsonVtInternal *v; - const char * soname; - void * handle; + const char *soname; + void *handle; v = g_new0(NMJsonVtInternal, 1); diff --git a/src/libnm-glib-aux/nm-json-aux.h b/src/libnm-glib-aux/nm-json-aux.h index 088d67a9..275ed770 100644 --- a/src/libnm-glib-aux/nm-json-aux.h +++ b/src/libnm-glib-aux/nm-json-aux.h @@ -399,7 +399,7 @@ nm_value_type_to_json(NMValueType value_type, GString *gstr, gconstpointer p_fie } static inline gboolean -nm_value_type_from_json(const NMJsonVt * vt, +nm_value_type_from_json(const NMJsonVt *vt, NMValueType value_type, const nm_json_t *elem, gpointer out_val) diff --git a/src/libnm-glib-aux/nm-keyfile-aux.c b/src/libnm-glib-aux/nm-keyfile-aux.c index 9cda1cf7..1cae28b4 100644 --- a/src/libnm-glib-aux/nm-keyfile-aux.c +++ b/src/libnm-glib-aux/nm-keyfile-aux.c @@ -19,8 +19,8 @@ struct _NMKeyFileDB { NMKeyFileDBLogFcn log_fcn; NMKeyFileDBGotDirtyFcn got_dirty_fcn; gpointer user_data; - const char * group_name; - GKeyFile * kf; + const char *group_name; + GKeyFile *kf; guint ref_count; bool is_started : 1; @@ -77,8 +77,8 @@ _key_file_new(void) /*****************************************************************************/ NMKeyFileDB * -nm_key_file_db_new(const char * filename, - const char * group_name, +nm_key_file_db_new(const char *filename, + const char *group_name, NMKeyFileDBLogFcn log_fcn, NMKeyFileDBGotDirtyFcn got_dirty_fcn, gpointer user_data) @@ -175,8 +175,8 @@ nm_key_file_db_destroy(NMKeyFileDB *self) void nm_key_file_db_start(NMKeyFileDB *self) { - gs_free char *contents = NULL; - gsize contents_len; + gs_free char *contents = NULL; + gsize contents_len; gs_free_error GError *error = NULL; g_return_if_fail(_IS_KEY_FILE_DB(self, FALSE, FALSE)); @@ -309,7 +309,7 @@ nm_key_file_db_set_value(NMKeyFileDB *self, const char *key, const char *value) if (!self->dirty && !got_dirty) { gs_free_error GError *error = NULL; - gs_free char * new_value = NULL; + gs_free char *new_value = NULL; new_value = g_key_file_get_value(self->kf, self->group_name, key, &error); if (error || !new_value || !nm_streq0(old_value, new_value)) @@ -321,8 +321,8 @@ nm_key_file_db_set_value(NMKeyFileDB *self, const char *key, const char *value) } void -nm_key_file_db_set_string_list(NMKeyFileDB * self, - const char * key, +nm_key_file_db_set_string_list(NMKeyFileDB *self, + const char *key, const char *const *value, gssize len) { @@ -352,7 +352,7 @@ nm_key_file_db_set_string_list(NMKeyFileDB * self, if (!self->dirty && !got_dirty) { gs_free_error GError *error = NULL; - gs_free char * new_value = NULL; + gs_free char *new_value = NULL; new_value = g_key_file_get_value(self->kf, self->group_name, key, &error); if (error || !new_value || !nm_streq0(old_value, new_value)) @@ -388,8 +388,8 @@ nm_key_file_db_to_file(NMKeyFileDB *self, gboolean force) void nm_key_file_db_prune_tmp_files(NMKeyFileDB *self) { - gs_free char * n_file = NULL; - gs_free char * n_dir = NULL; + gs_free char *n_file = NULL; + gs_free char *n_dir = NULL; gs_strfreev char **tmpfiles = NULL; gsize i; @@ -401,7 +401,7 @@ nm_key_file_db_prune_tmp_files(NMKeyFileDB *self) return; for (i = 0; tmpfiles[i]; i++) { - const char * tmpfile = tmpfiles[i]; + const char *tmpfile = tmpfiles[i]; gs_free char *full_file = NULL; int r; @@ -430,10 +430,10 @@ nm_key_file_db_prune(NMKeyFileDB *self, gboolean (*predicate)(const char *key, gpointer user_data), gpointer user_data) { - gs_strfreev char ** keys = NULL; + gs_strfreev char **keys = NULL; nm_auto_unref_keyfile GKeyFile *kf_to_free = NULL; - GKeyFile * kf_src = NULL; - GKeyFile * kf_dst = NULL; + GKeyFile *kf_src = NULL; + GKeyFile *kf_dst = NULL; guint k; g_return_if_fail(_IS_KEY_FILE_DB(self, TRUE, FALSE)); diff --git a/src/libnm-glib-aux/nm-keyfile-aux.h b/src/libnm-glib-aux/nm-keyfile-aux.h index e756c57a..7ada4029 100644 --- a/src/libnm-glib-aux/nm-keyfile-aux.h +++ b/src/libnm-glib-aux/nm-keyfile-aux.h @@ -13,13 +13,13 @@ typedef struct _NMKeyFileDB NMKeyFileDB; typedef void (*NMKeyFileDBLogFcn)(NMKeyFileDB *self, int syslog_level, gpointer user_data, - const char * fmt, + const char *fmt, ...) G_GNUC_PRINTF(4, 5); typedef void (*NMKeyFileDBGotDirtyFcn)(NMKeyFileDB *self, gpointer user_data); -NMKeyFileDB *nm_key_file_db_new(const char * filename, - const char * group, +NMKeyFileDB *nm_key_file_db_new(const char *filename, + const char *group, NMKeyFileDBLogFcn log_fcn, NMKeyFileDBGotDirtyFcn got_dirty_fcn, gpointer user_data); @@ -43,8 +43,8 @@ void nm_key_file_db_remove_key(NMKeyFileDB *self, const char *key); void nm_key_file_db_set_value(NMKeyFileDB *self, const char *key, const char *value); -void nm_key_file_db_set_string_list(NMKeyFileDB * self, - const char * key, +void nm_key_file_db_set_string_list(NMKeyFileDB *self, + const char *key, const char *const *value, gssize len); diff --git a/src/libnm-glib-aux/nm-logging-base.c b/src/libnm-glib-aux/nm-logging-base.c index cc19ef15..5195cbb7 100644 --- a/src/libnm-glib-aux/nm-logging-base.c +++ b/src/libnm-glib-aux/nm-logging-base.c @@ -104,8 +104,8 @@ _nm_log_simple_printf(NMLogLevel level, const char *fmt, ...) { gs_free char *msg_heap = NULL; char msg_stack[700]; - const char * msg; - const char * level_str; + const char *msg; + const char *level_str; gint64 ts; ts = nm_utils_clock_gettime_nsec(CLOCK_BOOTTIME); diff --git a/src/libnm-glib-aux/nm-macros-internal.h b/src/libnm-glib-aux/nm-macros-internal.h index e7ee7f38..14c16020 100644 --- a/src/libnm-glib-aux/nm-macros-internal.h +++ b/src/libnm-glib-aux/nm-macros-internal.h @@ -137,7 +137,7 @@ static inline void _nm_auto_freev(gpointer ptr) { gpointer **p = ptr; - gpointer * _ptr; + gpointer *_ptr; if (*p) { for (_ptr = *p; *_ptr; _ptr++) @@ -552,12 +552,12 @@ nm_str_realloc(char *str) #define NM_GOBJECT_PROPERTIES_DEFINE_NOTIFY(suffix, obj_type) \ static inline void _nm_gobject_notify_together_impl##suffix( \ - obj_type * obj, \ + obj_type *obj, \ guint n, \ const _PropertyEnums##suffix *props) \ { \ GObject *const gobj = (GObject *) obj; \ - GParamSpec * pspec_first = NULL; \ + GParamSpec *pspec_first = NULL; \ gboolean frozen = FALSE; \ \ nm_assert(G_IS_OBJECT(obj)); \ @@ -565,7 +565,7 @@ nm_str_realloc(char *str) \ while (n-- > 0) { \ const _PropertyEnums##suffix prop = *props++; \ - GParamSpec * pspec; \ + GParamSpec *pspec; \ \ if (prop == PROP_0##suffix) \ continue; \ @@ -1040,7 +1040,7 @@ nm_g_variant_equal(GVariant *a, GVariant *b) #define nm_str_skip_leading_spaces(str) \ ({ \ - typeof(*(str)) * _str_sls = (str); \ + typeof(*(str)) *_str_sls = (str); \ _nm_unused const char *const _str_type_check = _str_sls; \ \ if (_str_sls) { \ @@ -1057,6 +1057,27 @@ nm_strstrip(char *str) return str ? g_strstrip(str) : NULL; } +static inline char * +nm_strstrip_dup(const char *str) +{ + gsize l; + char *s; + + if (!str) + return NULL; + + str = nm_str_skip_leading_spaces(str); + l = strlen(str); + + while (l > 0 && g_ascii_isspace(str[l - 1])) + l--; + + s = g_new(char, l + 1); + memcpy(s, str, l); + s[l] = '\0'; + return s; +} + static inline const char * nm_strstrip_avoid_copy(const char *str, char **str_free) { @@ -1085,7 +1106,7 @@ nm_strstrip_avoid_copy(const char *str, char **str_free) #define nm_strstrip_avoid_copy_a(alloca_maxlen, str, out_str_free) \ ({ \ const char *_str_ssac = (str); \ - char ** _out_str_free_ssac = (out_str_free); \ + char **_out_str_free_ssac = (out_str_free); \ \ G_STATIC_ASSERT_EXPR((alloca_maxlen) > 0); \ \ @@ -1315,7 +1336,7 @@ _nm_strndup_a_step(char *s, const char *str, gsize len) const char *const _str_snd = (str); \ const gsize _len_snd = (len); \ char **const _out_str_free_snd = (out_str_free); \ - char * _s_snd; \ + char *_s_snd; \ \ G_STATIC_ASSERT_EXPR((alloca_maxlen) <= 300); \ \ @@ -1423,7 +1444,7 @@ nm_decode_version(guint version, guint *major, guint *minor, guint *micro) (_str ? ({ \ const gsize _trunc_at = (trunc_at); \ const gsize _strlen_trunc = NM_MIN(strlen(_str), _trunc_at); \ - char * _buf; \ + char *_buf; \ \ G_STATIC_ASSERT_EXPR((trunc_at) <= 300); \ \ @@ -1456,7 +1477,7 @@ nm_decode_version(guint version, guint *major, guint *minor, guint *micro) char *const _sbuf_stack = (sbuf_stack); \ char **const _out_sbuf_heap = (out_sbuf_heap); \ gsize *const _out_len = (out_len); \ - const char * _msg; \ + const char *_msg; \ va_list _va_args; \ int _l; \ \ @@ -1470,7 +1491,7 @@ nm_decode_version(guint version, guint *major, guint *minor, guint *micro) \ if ((gsize) _l >= sizeof(sbuf_stack)) { \ const gsize _l2 = ((gsize) _l) + 1u; \ - char * _sbuf_heap; \ + char *_sbuf_heap; \ \ /* Don't use g_strdup_vprintf() here either, because that also needs * to first determine the length (which is commonly does by printing @@ -1503,7 +1524,7 @@ nm_decode_version(guint version, guint *major, guint *minor, guint *micro) * must not be larger than 300 bytes, as this gets stack allocated. */ #define nm_sprintf_buf_unsafe_a(bufsize, format, ...) \ ({ \ - char * _buf; \ + char *_buf; \ int _buf_len; \ typeof(bufsize) _bufsize = (bufsize); \ \ @@ -1531,7 +1552,7 @@ nm_decode_version(guint version, guint *major, guint *minor, guint *micro) const char *const _name = (name); \ char **const _p_val_to_free = (p_val_to_free); \ const gsize _name_len = strlen(_name); \ - char * _buf2; \ + char *_buf2; \ \ nm_assert(_p_val_to_free && !*_p_val_to_free); \ if (NM_STRLEN(format) <= 290 && _name_len < (gsize) (290 - NM_STRLEN(format))) \ diff --git a/src/libnm-glib-aux/nm-random-utils.c b/src/libnm-glib-aux/nm-random-utils.c index 2f42f3f6..3a8ba64f 100644 --- a/src/libnm-glib-aux/nm-random-utils.c +++ b/src/libnm-glib-aux/nm-random-utils.c @@ -80,7 +80,7 @@ _bad_random_init_seed(BadRandSeed *seed) { const guint8 *p_at_random; int seed_idx; - GRand * rand; + GRand *rand; /* g_rand_new() reads /dev/urandom, but we already noticed that * /dev/urandom fails to give us good randomness (which is why @@ -148,7 +148,7 @@ _bad_random_bytes(guint8 *buf, gsize n) { static BadRandState gl_state; - static GRand * gl_rand; + static GRand *gl_rand; static GMutex gl_mutex; NM_G_MUTEX_LOCKED(&gl_mutex); @@ -224,7 +224,7 @@ nm_utils_random_bytes(void *p, size_t n) int fd; int r; gboolean has_high_quality = TRUE; - guint8 * buf = p; + guint8 *buf = p; g_return_val_if_fail(p, FALSE); g_return_val_if_fail(n > 0, FALSE); diff --git a/src/libnm-glib-aux/nm-ref-string.c b/src/libnm-glib-aux/nm-ref-string.c index 93e97c79..fec5d60e 100644 --- a/src/libnm-glib-aux/nm-ref-string.c +++ b/src/libnm-glib-aux/nm-ref-string.c @@ -172,6 +172,48 @@ nm_ref_string_new_len(const char *cstr, gsize len) return rstr; } +/** + * nmtst_ref_string_find_len: + * @cstr: the string to find. + * @len: length of @cstr. + * + * Returns: (transfer none): %NULL, if the string is currently + * not interned. Otherwise a reference to the interned string. + * Beware: this does not return ownership of the reference, + * it is thus not thread safe. Only use this from unit tests + * when you know that your thread holds a reference to the string + * to keep it alive. Otherwise, this might be a dangling pointer. + */ +NMRefString * +nmtst_ref_string_find_len(const char *cstr, gsize len) +{ + NMRefString *rstr = NULL; + + /* @len cannot be close to G_MAXSIZE. For one, that would mean our call + * to malloc() below overflows. Also, we use G_MAXSIZE as special length + * to indicate using _priv_lookup. */ + nm_assert(len < G_MAXSIZE - G_STRUCT_OFFSET(NMRefString, str) - 1u); + + G_LOCK(gl_lock); + + if (G_LIKELY(gl_hash)) { + NMRefString rr_lookup = { + .len = G_MAXSIZE, + ._priv_lookup = + { + .l_len = len, + .l_str = cstr, + }, + }; + + rstr = g_hash_table_lookup(gl_hash, &rr_lookup); + } + + G_UNLOCK(gl_lock); + + return rstr; +} + void _nm_ref_string_unref_slow_path(NMRefString *rstr) { diff --git a/src/libnm-glib-aux/nm-ref-string.h b/src/libnm-glib-aux/nm-ref-string.h index 6950d1b9..3363bce0 100644 --- a/src/libnm-glib-aux/nm-ref-string.h +++ b/src/libnm-glib-aux/nm-ref-string.h @@ -46,6 +46,19 @@ nm_ref_string_new(const char *cstr) /*****************************************************************************/ +NMRefString *nmtst_ref_string_find_len(const char *cstr, gsize len); + +static inline NMRefString * +nmtst_ref_string_find(const char *cstr) +{ + /* WARNING: only use for testing. See nmtst_ref_string_find_len() why. */ + if (!cstr) + return FALSE; + return nmtst_ref_string_find_len(cstr, strlen(cstr)); +} + +/*****************************************************************************/ + static inline NMRefString * nm_ref_string_ref(NMRefString *rstr) { @@ -118,11 +131,14 @@ static inline gboolean nm_ref_string_equal_str(NMRefString *rstr, const char *str) { if (!str) - return (!!rstr); + return !rstr; if (!rstr) return FALSE; + /* We don't use streq() here, because an NMRefString might have embedded NUL characters + * (as the length is tracked separately). The NUL terminated C string @str must not + * compare equal to such a @rstr, thus we first explicitly check strlen(). */ return rstr->len == strlen(str) && (rstr->str == str || memcmp(rstr->str, str, rstr->len) == 0); } @@ -164,24 +180,63 @@ nm_ref_string_unref_upcast(const char *str) nm_ref_string_unref(NM_REF_STRING_UPCAST(str)); } +/** + * nm_ref_string_reset_str_upcast: + * @ptr: the destination pointer that gets updated. + * @str: the new string to be set. + * + * @ptr is a location (destination pointer) of an "upcast" NMRefString. + * That is, it holds either %NULL or some ((NMRefString *) rstr)->str. + * In other words, @ptr holds an NMRefString which you could get via + * NM_REF_STRING_UPCAST(*ptr). + * This function resets @ptr to point to a NMRefString equal to @str. + * + * Returns: %TRUE if the pointer changed and %FALSE if the value was + * already set to a string equal to @str. + */ +static inline gboolean +nm_ref_string_reset_str_upcast(const char **ptr, const char *str) +{ + NMRefString *rstr; + gsize l; + + nm_assert(ptr); + + if (!str) + return nm_clear_pointer(ptr, nm_ref_string_unref_upcast); + + rstr = NM_REF_STRING_UPCAST(*ptr); + + l = strlen(str); + + if (rstr && rstr->len == l && (rstr->str == str || memcmp(rstr->str, str, l) == 0)) + return FALSE; + + *ptr = nm_ref_string_new_len(str, l)->str; + nm_ref_string_unref(rstr); + return TRUE; +} + static inline gboolean nm_ref_string_reset_str(NMRefString **ptr, const char *str) { - nm_auto_ref_string NMRefString *rstr = NULL; - gsize l; + NMRefString *rstr; + gsize l; nm_assert(ptr); if (!str) return nm_clear_pointer(ptr, nm_ref_string_unref); + rstr = *ptr; + l = strlen(str); - if ((*ptr) && (*ptr)->len == l && ((*ptr)->str == str || memcmp((*ptr)->str, str, l) == 0)) + if (rstr && rstr->len == l && (rstr->str == str || memcmp(rstr->str, str, l) == 0)) return FALSE; - rstr = *ptr; *ptr = nm_ref_string_new_len(str, l); + nm_ref_string_unref(rstr); return TRUE; } diff --git a/src/libnm-glib-aux/nm-secret-utils.h b/src/libnm-glib-aux/nm-secret-utils.h index ac279635..513dbca5 100644 --- a/src/libnm-glib-aux/nm-secret-utils.h +++ b/src/libnm-glib-aux/nm-secret-utils.h @@ -20,6 +20,22 @@ char *nm_secret_strchomp(char *secret); void nm_free_secret(char *secret); +static inline gboolean +nm_strdup_reset_secret(char **dst, const char *src) +{ + char *old; + + nm_assert(dst); + + if (nm_streq0(*dst, src)) + return FALSE; + old = *dst; + *dst = src ? g_strdup(src) : NULL; + if (old) + nm_free_secret(old); + return TRUE; +} + NM_AUTO_DEFINE_FCN0(char *, _nm_auto_free_secret, nm_free_secret); /** * nm_auto_free_secret: @@ -46,8 +62,8 @@ typedef struct { /* the data pointer. This pointer must be allocated with malloc (at least * when used with nm_secret_ptr_clear()). */ union { - char * str; - void * ptr; + char *str; + void *ptr; guint8 *bin; }; } NMSecretPtr; diff --git a/src/libnm-glib-aux/nm-shared-utils.c b/src/libnm-glib-aux/nm-shared-utils.c index 9d1a1bf1..6e6fed12 100644 --- a/src/libnm-glib-aux/nm-shared-utils.c +++ b/src/libnm-glib-aux/nm-shared-utils.c @@ -54,7 +54,7 @@ nm_ip_addr_set_from_untrusted(int addr_family, gpointer dst, gconstpointer src, gsize src_len, - int * out_addr_family) + int *out_addr_family) { nm_assert(dst); @@ -177,7 +177,7 @@ nm_utils_ipv6_addr_set_interface_identifier(struct in6_addr *addr, const NMUtils * the interface identifier. */ void -nm_utils_ipv6_interface_identifier_get_from_addr(NMUtilsIPv6IfaceId * iid, +nm_utils_ipv6_interface_identifier_get_from_addr(NMUtilsIPv6IfaceId *iid, const struct in6_addr *addr) { memcpy(iid, addr->s6_addr + 8, 8); @@ -245,40 +245,58 @@ nm_utils_gettid(void) * The main-thread is determined by remembering the thread-id * of when the function was called the first time. * - * When forking, the thread-id is again reset upon first call. */ + * When forking, the thread-id is again reset upon first call. + * + * Note that this is only used for asserting, to check that we don't + * call the function on the wrong thread. As it's difficult to correctly + * cache the tid/pid, we might get this wrong during fork. That is not + * a problem, because we err on the side of pretending all is good. */ gboolean _nm_assert_on_main_thread(void) { - G_LOCK_DEFINE_STATIC(lock); - static pid_t seen_tid; - static pid_t seen_pid; - pid_t tid; - pid_t pid; - gboolean success = FALSE; + static GMutex lock; + static int seen_tid; + pid_t tid; + int t; + gboolean success = FALSE; tid = nm_utils_gettid(); nm_assert(tid != 0); + nm_assert(({ + const int tt = tid; - G_LOCK(lock); + tt == tid; + })); - if (G_LIKELY(tid == seen_tid)) { + t = g_atomic_int_get(&seen_tid); + if (G_LIKELY(t == tid)) { /* we don't care about false positives (when the process forked, and the thread-id * is accidentally re-used) . It's for assertions only. */ + return TRUE; + } + + g_mutex_lock(&lock); + + t = g_atomic_int_get(&seen_tid); + if (G_UNLIKELY(t == tid)) success = TRUE; - } else { + else { + static pid_t seen_pid; + pid_t pid; + pid = getpid(); nm_assert(pid != 0); - if (seen_tid == 0 || seen_pid != pid) { + if (t == 0 || seen_pid != pid) { /* either this is the first time we call the function, or the process - * forked. In both cases, remember the thread-id. */ - seen_tid = tid; + * forked. In both cases, update the thread-id. */ + g_atomic_int_set(&seen_tid, tid); seen_pid = pid; success = TRUE; } } - G_UNLOCK(lock); + g_mutex_unlock(&lock); return success; } @@ -377,7 +395,7 @@ nm_strbuf_append_str(char **buf, gsize *len, const char *str) void nm_strbuf_append(char **buf, gsize *len, const char *format, ...) { - char * p = *buf; + char *p = *buf; va_list args; int retval; @@ -480,7 +498,7 @@ GBytes * nm_g_bytes_get_empty(void) { static GBytes *bytes = NULL; - GBytes * b; + GBytes *b; again: b = g_atomic_pointer_get(&bytes); @@ -566,7 +584,7 @@ nm_g_bytes_to_variant_ay(const GBytes *bytes) #define _variant_singleton_get(create_variant) \ ({ \ static GVariant *_singleton = NULL; \ - GVariant * _v; \ + GVariant *_v; \ \ while (TRUE) { \ _v = g_atomic_pointer_get(&_singleton); \ @@ -629,7 +647,7 @@ _variant_singleton_get_array_init(GVariant **p_singleton, const char *variant_ty #define _variant_singleton_get_array(variant_type) \ ({ \ static GVariant *_singleton = NULL; \ - GVariant * _v; \ + GVariant *_v; \ \ _v = g_atomic_pointer_get(&_singleton); \ if (G_UNLIKELY(!_v)) { \ @@ -708,10 +726,10 @@ nm_g_variant_maybe_singleton_i(gint32 value) GHashTable * nm_strdict_clone(GHashTable *src) { - GHashTable * dst; + GHashTable *dst; GHashTableIter iter; - const char * key; - const char * val; + const char *key; + const char *val; if (!src) return NULL; @@ -732,7 +750,7 @@ nm_strdict_to_variant_ass(GHashTable *strdict) { gs_free NMUtilsNamedValue *values_free = NULL; NMUtilsNamedValue values_prepared[20]; - const NMUtilsNamedValue * values; + const NMUtilsNamedValue *values; GVariantBuilder builder; guint i; guint n; @@ -753,7 +771,7 @@ nm_strdict_to_variant_asv(GHashTable *strdict) { gs_free NMUtilsNamedValue *values_free = NULL; NMUtilsNamedValue values_prepared[20]; - const NMUtilsNamedValue * values; + const NMUtilsNamedValue *values; GVariantBuilder builder; guint i; guint n; @@ -873,7 +891,7 @@ const char * nm_utils_flags2str(const NMUtilsFlags2StrDesc *descs, gsize n_descs, unsigned flags, - char * buf, + char *buf, gsize len) { gsize i; @@ -986,10 +1004,10 @@ nm_utils_ip_is_site_local(int addr_family, const void *address) static gboolean _parse_legacy_addr4(const char *text, in_addr_t *out_addr, GError **error) { - gs_free char * s_free = NULL; + gs_free char *s_free = NULL; struct in_addr a1; guint8 bin[sizeof(a1)]; - char * s; + char *s; int i; if (inet_aton(text, &a1) != 1) { @@ -1024,7 +1042,7 @@ _parse_legacy_addr4(const char *text, in_addr_t *out_addr, GError **error) s = nm_memdup_maybe_a(300, text, strlen(text) + 1, &s_free); for (i = 0; i < G_N_ELEMENTS(bin); i++) { - char * current_token = s; + char *current_token = s; gint32 v; s = strchr(s, '.'); @@ -1088,7 +1106,7 @@ gboolean nm_utils_parse_inaddr_bin_full(int addr_family, gboolean accept_legacy, const char *text, - int * out_addr_family, + int *out_addr_family, gpointer out_addr) { NMIPAddr addrbin; @@ -1160,14 +1178,14 @@ nm_utils_parse_inaddr(int addr_family, const char *text, char **out_addr) gboolean nm_utils_parse_inaddr_prefix_bin(int addr_family, const char *text, - int * out_addr_family, + int *out_addr_family, gpointer out_addr, - int * out_prefix) + int *out_prefix) { gs_free char *addrstr_free = NULL; int prefix = -1; - const char * slash; - const char * addrstr; + const char *slash; + const char *addrstr; NMIPAddr addrbin; g_return_val_if_fail(text, FALSE); @@ -1218,9 +1236,9 @@ nm_utils_parse_inaddr_prefix(int addr_family, const char *text, char **out_addr, gboolean nm_utils_parse_next_line(const char **inout_ptr, - gsize * inout_len, + gsize *inout_len, const char **out_line, - gsize * out_line_len) + gsize *out_line_len) { gboolean eol_is_carriage_return; const char *line_start; @@ -1843,12 +1861,12 @@ _char_lookup_has_all(const CharLookupTable *lookup, const char *candidates) const char ** nm_strsplit_set_full(const char *str, const char *delimiters, NMUtilsStrsplitSetFlags flags) { - const char ** ptr; + const char **ptr; gsize num_tokens; gsize i_token; gsize str_len_p1; - const char * c_str; - char * s; + const char *c_str; + char *s; CharLookupTable ch_lookup; const gboolean f_escaped = NM_FLAGS_HAS(flags, NM_STRSPLIT_SET_FLAGS_ESCAPED); const gboolean f_allow_escaping = @@ -1884,7 +1902,7 @@ nm_strsplit_set_full(const char *str, const char *delimiters, NMUtilsStrsplitSet ({ \ const char *const _str_start = (str_start); \ const char *const _str_cur = (str_cur); \ - const char * _str_i = (_str_cur); \ + const char *_str_i = (_str_cur); \ \ while (_str_i > _str_start && _str_i[-1] == '\\') \ _str_i--; \ @@ -2030,16 +2048,16 @@ done2: /*****************************************************************************/ const char * -nm_utils_escaped_tokens_escape_full(const char * str, - const char * delimiters, - const char * delimiters_as_needed, +nm_utils_escaped_tokens_escape_full(const char *str, + const char *delimiters, + const char *delimiters_as_needed, NMUtilsEscapedTokensEscapeFlags flags, - char ** out_to_free) + char **out_to_free) { CharLookupTable ch_lookup; CharLookupTable ch_lookup_as_needed; gboolean has_ch_lookup_as_needed = FALSE; - char * ret; + char *ret; gsize str_len; gsize alloc_len; gsize n_escapes; @@ -2268,7 +2286,7 @@ char ** nm_utils_strsplit_quoted(const char *str) { gs_unref_ptrarray GPtrArray *arr = NULL; - gs_free char * str_out = NULL; + gs_free char *str_out = NULL; CharLookupTable ch_lookup; nm_assert(str); @@ -2520,7 +2538,7 @@ nm_strv_cleanup(char **strv, gboolean strip_whitespace, gboolean skip_empty, gbo /*****************************************************************************/ GPtrArray * -_nm_g_ptr_array_copy(GPtrArray * array, +_nm_g_ptr_array_copy(GPtrArray *array, GCopyFunc func, gpointer user_data, GDestroyNotify element_free_func) @@ -2624,14 +2642,14 @@ nm_utils_error_is_notfound(GError *error) * Returns: whether the value was successfully set. */ gboolean -nm_g_object_set_property(GObject * object, - const char * property_name, +nm_g_object_set_property(GObject *object, + const char *property_name, const GValue *value, - GError ** error) + GError **error) { - GParamSpec * pspec; + GParamSpec *pspec; nm_auto_unset_gvalue GValue tmp_value = G_VALUE_INIT; - GObjectClass * klass; + GObjectClass *klass; g_return_val_if_fail(G_IS_OBJECT(object), FALSE); g_return_val_if_fail(property_name != NULL, FALSE); @@ -2725,46 +2743,46 @@ nm_g_object_set_property(GObject * object, G_STMT_END gboolean -nm_g_object_set_property_string(GObject * object, +nm_g_object_set_property_string(GObject *object, const char *property_name, const char *value, - GError ** error) + GError **error) { _set_property(object, property_name, G_TYPE_STRING, g_value_set_string, value, error); } gboolean -nm_g_object_set_property_string_static(GObject * object, +nm_g_object_set_property_string_static(GObject *object, const char *property_name, const char *value, - GError ** error) + GError **error) { _set_property(object, property_name, G_TYPE_STRING, g_value_set_static_string, value, error); } gboolean -nm_g_object_set_property_string_take(GObject * object, +nm_g_object_set_property_string_take(GObject *object, const char *property_name, - char * value, - GError ** error) + char *value, + GError **error) { _set_property(object, property_name, G_TYPE_STRING, g_value_take_string, value, error); } gboolean -nm_g_object_set_property_boolean(GObject * object, +nm_g_object_set_property_boolean(GObject *object, const char *property_name, gboolean value, - GError ** error) + GError **error) { _set_property(object, property_name, G_TYPE_BOOLEAN, g_value_set_boolean, !!value, error); } gboolean -nm_g_object_set_property_char(GObject * object, +nm_g_object_set_property_char(GObject *object, const char *property_name, gint8 value, - GError ** error) + GError **error) { /* glib says about G_TYPE_CHAR: * @@ -2775,10 +2793,10 @@ nm_g_object_set_property_char(GObject * object, } gboolean -nm_g_object_set_property_uchar(GObject * object, +nm_g_object_set_property_uchar(GObject *object, const char *property_name, guint8 value, - GError ** error) + GError **error) { _set_property(object, property_name, G_TYPE_UCHAR, g_value_set_uchar, value, error); } @@ -2790,38 +2808,38 @@ nm_g_object_set_property_int(GObject *object, const char *property_name, int val } gboolean -nm_g_object_set_property_int64(GObject * object, +nm_g_object_set_property_int64(GObject *object, const char *property_name, gint64 value, - GError ** error) + GError **error) { _set_property(object, property_name, G_TYPE_INT64, g_value_set_int64, value, error); } gboolean -nm_g_object_set_property_uint(GObject * object, +nm_g_object_set_property_uint(GObject *object, const char *property_name, guint value, - GError ** error) + GError **error) { _set_property(object, property_name, G_TYPE_UINT, g_value_set_uint, value, error); } gboolean -nm_g_object_set_property_uint64(GObject * object, +nm_g_object_set_property_uint64(GObject *object, const char *property_name, guint64 value, - GError ** error) + GError **error) { _set_property(object, property_name, G_TYPE_UINT64, g_value_set_uint64, value, error); } gboolean -nm_g_object_set_property_flags(GObject * object, +nm_g_object_set_property_flags(GObject *object, const char *property_name, GType gtype, guint value, - GError ** error) + GError **error) { nm_assert(({ nm_auto_unref_gtypeclass GTypeClass *gtypeclass = g_type_class_ref(gtype); @@ -2831,11 +2849,11 @@ nm_g_object_set_property_flags(GObject * object, } gboolean -nm_g_object_set_property_enum(GObject * object, +nm_g_object_set_property_enum(GObject *object, const char *property_name, GType gtype, int value, - GError ** error) + GError **error) { nm_assert(({ nm_auto_unref_gtypeclass GTypeClass *gtypeclass = g_type_class_ref(gtype); @@ -2873,7 +2891,7 @@ GType nm_g_type_find_implementing_class_for_property(GType gtype, const char *pname) { nm_auto_unref_gtypeclass GObjectClass *klass = NULL; - GParamSpec * pspec; + GParamSpec *pspec; g_return_val_if_fail(pname, G_TYPE_INVALID); @@ -2949,10 +2967,10 @@ _str_buf_append_c_escape_octal(NMStrBuf *strbuf, char ch) * containing the unescaped string and returned. */ gconstpointer -nm_utils_buf_utf8safe_unescape(const char * str, +nm_utils_buf_utf8safe_unescape(const char *str, NMUtilsStrUtf8SafeFlags flags, - gsize * out_len, - gpointer * to_free) + gsize *out_len, + gpointer *to_free) { gboolean strip_spaces = NM_FLAGS_HAS(flags, NM_UTILS_STR_UTF8_SAFE_UNESCAPE_STRIP_SPACES); NMStrBuf strbuf; @@ -3114,11 +3132,11 @@ const char * nm_utils_buf_utf8safe_escape(gconstpointer buf, gssize buflen, NMUtilsStrUtf8SafeFlags flags, - char ** to_free) + char **to_free) { const char *const str = buf; - const char * p = NULL; - const char * s; + const char *p = NULL; + const char *s; gboolean nul_terminated = FALSE; NMStrBuf strbuf; @@ -3209,7 +3227,7 @@ char * nm_utils_buf_utf8safe_escape_cp(gconstpointer buf, gssize buflen, NMUtilsStrUtf8SafeFlags flags) { const char *s_const; - char * s; + char *s; s_const = nm_utils_buf_utf8safe_escape(buf, buflen, flags, &s); nm_assert(!s || s == s_const); @@ -3419,11 +3437,11 @@ nm_utils_named_value_clear_with_g_free(NMUtilsNamedValue *val) G_STATIC_ASSERT(G_STRUCT_OFFSET(NMUtilsNamedValue, name) == 0); NMUtilsNamedValue * -nm_utils_named_values_from_strdict_full(GHashTable * hash, - guint * out_len, +nm_utils_named_values_from_strdict_full(GHashTable *hash, + guint *out_len, GCompareDataFunc compare_func, gpointer user_data, - NMUtilsNamedValue * provided_buffer, + NMUtilsNamedValue *provided_buffer, guint provided_buffer_len, NMUtilsNamedValue **out_allocated_buffer) { @@ -3466,7 +3484,7 @@ nm_utils_named_values_from_strdict_full(GHashTable * hash, gssize nm_utils_named_value_list_find(const NMUtilsNamedValue *arr, gsize len, - const char * name, + const char *name, gboolean sorted) { gsize i; @@ -3556,10 +3574,10 @@ nm_utils_named_value_list_sort(NMUtilsNamedValue *arr, /*****************************************************************************/ gpointer * -nm_utils_hash_keys_to_array(GHashTable * hash, +nm_utils_hash_keys_to_array(GHashTable *hash, GCompareDataFunc compare_func, gpointer user_data, - guint * out_len) + guint *out_len) { guint len; gpointer *keys; @@ -3580,14 +3598,14 @@ nm_utils_hash_keys_to_array(GHashTable * hash, } gpointer * -nm_utils_hash_values_to_array(GHashTable * hash, +nm_utils_hash_values_to_array(GHashTable *hash, GCompareDataFunc compare_func, gpointer user_data, - guint * out_len) + guint *out_len) { GHashTableIter iter; gpointer value; - gpointer * arr; + gpointer *arr; guint i, len; if (!hash || (len = g_hash_table_size(hash)) == 0u) { @@ -3669,8 +3687,8 @@ nm_utils_hashtable_equal(const GHashTable *a, } static gboolean -_utils_hashtable_equal(GHashTable * hash_a, - GHashTable * hash_b, +_utils_hashtable_equal(GHashTable *hash_a, + GHashTable *hash_b, GCompareDataFunc cmp_values, gpointer user_data) { @@ -3768,8 +3786,8 @@ static int _hashtable_cmp_func(gconstpointer a, gconstpointer b, gpointer user_data) { const HashTableUserData *d = user_data; - const HashTableCmpData * d_a = *((const HashTableCmpData *const *) a); - const HashTableCmpData * d_b = *((const HashTableCmpData *const *) b); + const HashTableCmpData *d_a = *((const HashTableCmpData *const *) a); + const HashTableCmpData *d_b = *((const HashTableCmpData *const *) b); NM_CMP_RETURN(d->cmp_keys(d_a, d_b, d->user_data)); return 0; @@ -3805,11 +3823,11 @@ nm_utils_hashtable_cmp(const GHashTable *a, GCompareDataFunc cmp_values, gpointer user_data) { - GHashTable *hash_a = (GHashTable *) a; - GHashTable *hash_b = (GHashTable *) b; + GHashTable *hash_a = (GHashTable *) a; + GHashTable *hash_b = (GHashTable *) b; gs_free HashTableCmpData *cmp_array_free = NULL; - HashTableCmpData * cmp_array_a; - HashTableCmpData * cmp_array_b; + HashTableCmpData *cmp_array_a; + HashTableCmpData *cmp_array_b; GHashTableIter h; gpointer i_key; gpointer i_val; @@ -4011,12 +4029,12 @@ _nm_strv_dup_packed(const char *const *strv, gssize len) { gs_free gsize *str_len_free = NULL; - gsize * str_len; - const char ** result; + gsize *str_len; + const char **result; gsize mem_len; gsize pre_len; gsize len2; - char * sbuf; + char *sbuf; gsize i; nm_assert(len >= -1); @@ -4113,7 +4131,7 @@ nm_utils_ptrarray_find_first(gconstpointer *list, gssize len, gconstpointer need /*****************************************************************************/ gboolean -nm_utils_ptrarray_is_sorted(gconstpointer * list, +nm_utils_ptrarray_is_sorted(gconstpointer *list, gsize len, gboolean require_strict, GCompareDataFunc cmpfcn, @@ -4135,7 +4153,7 @@ nm_utils_ptrarray_is_sorted(gconstpointer * list, } gssize -nm_utils_ptrarray_find_binary_search(gconstpointer * list, +nm_utils_ptrarray_find_binary_search(gconstpointer *list, gsize len, gconstpointer needle, GCompareDataFunc cmpfcn, @@ -4172,13 +4190,13 @@ nm_utils_ptrarray_find_binary_search(gconstpointer * list, } gssize -nm_utils_ptrarray_find_binary_search_range(gconstpointer * list, +nm_utils_ptrarray_find_binary_search_range(gconstpointer *list, gsize len, gconstpointer needle, GCompareDataFunc cmpfcn, gpointer user_data, - gssize * out_idx_first, - gssize * out_idx_last) + gssize *out_idx_first, + gssize *out_idx_last) { gssize imin, imax, imid, i2min, i2max, i2mid; int cmp; @@ -4336,10 +4354,10 @@ nm_utils_get_start_time_for_pid(pid_t pid, char *out_state, pid_t *out_ppid) { guint64 start_time; char filename[256]; - gs_free char * contents = NULL; + gs_free char *contents = NULL; size_t length; gs_free const char **tokens = NULL; - char * p; + char *p; char state = ' '; gint64 ppid = 0; @@ -4593,8 +4611,8 @@ _nm_utils_user_data_unpack(NMUtilsUserData *user_data, int nargs, ...) typedef struct { gpointer callback_user_data; - GCancellable * cancellable; - GSource * source; + GCancellable *cancellable; + GSource *source; NMUtilsInvokeOnIdleCallback callback; gulong cancelled_id; } InvokeOnIdleData; @@ -4639,12 +4657,12 @@ _nm_utils_invoke_on_idle_cb_cancelled(GCancellable *cancellable, InvokeOnIdleDat static void _nm_utils_invoke_on_idle_start(gboolean use_timeout, guint timeout_msec, - GCancellable * cancellable, + GCancellable *cancellable, NMUtilsInvokeOnIdleCallback callback, gpointer callback_user_data) { InvokeOnIdleData *data; - GSource * source; + GSource *source; g_return_if_fail(callback); @@ -4688,7 +4706,7 @@ _nm_utils_invoke_on_idle_start(gboolean use_timeout, } void -nm_utils_invoke_on_idle(GCancellable * cancellable, +nm_utils_invoke_on_idle(GCancellable *cancellable, NMUtilsInvokeOnIdleCallback callback, gpointer callback_user_data) { @@ -4697,7 +4715,7 @@ nm_utils_invoke_on_idle(GCancellable * cancellable, void nm_utils_invoke_on_timeout(guint timeout_msec, - GCancellable * cancellable, + GCancellable *cancellable, NMUtilsInvokeOnIdleCallback callback, gpointer callback_user_data) { @@ -4787,11 +4805,11 @@ nm_utils_bin2hexstr_full(gconstpointer addr, gsize length, char delimiter, gboolean upper_case, - char * out) + char *out) { const guint8 *in = addr; - const char * LOOKUP = upper_case ? "0123456789ABCDEF" : "0123456789abcdef"; - char * out0; + const char *LOOKUP = upper_case ? "0123456789ABCDEF" : "0123456789abcdef"; + char *out0; if (out) out0 = out; @@ -4829,12 +4847,12 @@ nm_utils_hexstr2bin_full(const char *hexstr, gboolean hexdigit_pairs_required, const char *delimiter_candidates, gsize required_len, - guint8 * buffer, + guint8 *buffer, gsize buffer_len, - gsize * out_len) + gsize *out_len) { const char *in = hexstr; - guint8 * out = buffer; + guint8 *out = buffer; gboolean delimiter_has = TRUE; guint8 delimiter = '\0'; gsize len; @@ -4918,7 +4936,7 @@ nm_utils_hexstr2bin_alloc(const char *hexstr, gboolean delimiter_required, const char *delimiter_candidates, gsize required_len, - gsize * out_len) + gsize *out_len) { guint8 *buffer; gsize buffer_len, len; @@ -4968,16 +4986,16 @@ fail: GVariant * nm_utils_gvariant_vardict_filter(GVariant *src, gboolean (*filter_fcn)(const char *key, - GVariant * val, - char ** out_key, - GVariant ** out_val, + GVariant *val, + char **out_key, + GVariant **out_val, gpointer user_data), gpointer user_data) { GVariantIter iter; GVariantBuilder builder; - const char * key; - GVariant * val; + const char *key; + GVariant *val; g_return_val_if_fail(src && g_variant_is_of_type(src, G_VARIANT_TYPE_VARDICT), NULL); g_return_val_if_fail(filter_fcn, NULL); @@ -4987,8 +5005,8 @@ nm_utils_gvariant_vardict_filter(GVariant *src, g_variant_iter_init(&iter, src); while (g_variant_iter_next(&iter, "{&sv}", &key, &val)) { _nm_unused gs_unref_variant GVariant *val_free = val; - gs_free char * key2 = NULL; - gs_unref_variant GVariant *val2 = NULL; + gs_free char *key2 = NULL; + gs_unref_variant GVariant *val2 = NULL; if (filter_fcn(key, val, &key2, &val2, user_data)) { g_variant_builder_add(&builder, "{sv}", key2 ?: key, val2 ?: val); @@ -5000,9 +5018,9 @@ nm_utils_gvariant_vardict_filter(GVariant *src, static gboolean _gvariant_vardict_filter_drop_one(const char *key, - GVariant * val, - char ** out_key, - GVariant ** out_val, + GVariant *val, + char **out_key, + GVariant **out_val, gpointer user_data) { return !nm_streq(key, user_data); @@ -5231,8 +5249,8 @@ typedef struct { typedef struct { GSource source; GMainContext *context; - GHashTable * fds; - GPollFD * fds_arr; + GHashTable *fds; + GPollFD *fds_arr; guint fds_len; int max_priority; bool acquired : 1; @@ -5272,16 +5290,16 @@ _ctx_integ_source_reacquire(CtxIntegSource *ctx_src) static gboolean _ctx_integ_source_prepare(GSource *source, int *out_timeout) { - CtxIntegSource *ctx_src = ((CtxIntegSource *) source); - int max_priority; - int timeout = -1; - gboolean any_ready; - GHashTableIter h_iter; - PollData * poll_data; - gboolean fds_changed; - GPollFD new_fds_stack[300u / sizeof(GPollFD)]; + CtxIntegSource *ctx_src = ((CtxIntegSource *) source); + int max_priority; + int timeout = -1; + gboolean any_ready; + GHashTableIter h_iter; + PollData *poll_data; + gboolean fds_changed; + GPollFD new_fds_stack[300u / sizeof(GPollFD)]; gs_free GPollFD *new_fds_heap = NULL; - GPollFD * new_fds; + GPollFD *new_fds; guint new_fds_len; guint new_fds_alloc; guint i; @@ -5455,7 +5473,7 @@ _ctx_integ_source_check(GSource *source) CtxIntegSource *ctx_src = ((CtxIntegSource *) source); GHashTableIter h_iter; gboolean some_ready; - PollData * poll_data; + PollData *poll_data; nm_assert(ctx_src->context); @@ -5511,7 +5529,7 @@ _ctx_integ_source_finalize(GSource *source) { CtxIntegSource *ctx_src = ((CtxIntegSource *) source); GHashTableIter h_iter; - PollData * poll_data; + PollData *poll_data; g_return_if_fail(ctx_src->context); @@ -5890,17 +5908,17 @@ attribute_escape(const char *src, char c1, char c2) } void -_nm_utils_format_variant_attributes_full(GString * str, - const NMUtilsNamedValue * values, +_nm_utils_format_variant_attributes_full(GString *str, + const NMUtilsNamedValue *values, guint num_values, const NMVariantAttributeSpec *const *spec, char attr_separator, char key_value_separator) { const NMVariantAttributeSpec *const *s; - const char * name, *value; - GVariant * variant; - char * escaped; + const char *name, *value; + GVariant *variant; + char *escaped; char buf[64]; char sep = 0; guint i; @@ -5960,15 +5978,15 @@ _nm_utils_format_variant_attributes_full(GString * st } char * -_nm_utils_format_variant_attributes(GHashTable * attributes, +_nm_utils_format_variant_attributes(GHashTable *attributes, const NMVariantAttributeSpec *const *spec, char attr_separator, char key_value_separator) { gs_free NMUtilsNamedValue *values_free = NULL; NMUtilsNamedValue values_prepared[20]; - const NMUtilsNamedValue * values; - GString * str = NULL; + const NMUtilsNamedValue *values; + GString *str = NULL; guint len; g_return_val_if_fail(attr_separator, NULL); @@ -6078,7 +6096,7 @@ nm_utils_uid_to_name(uid_t uid) gs_free char *buf_heap = NULL; char buf_stack[4096]; gsize bufsize; - char * buf; + char *buf; bufsize = sizeof(buf_stack); buf = buf_stack; @@ -6112,7 +6130,7 @@ nm_utils_name_to_uid(const char *name, uid_t *out_uid) gs_free char *buf_heap = NULL; char buf_stack[4096]; gsize bufsize; - char * buf; + char *buf; if (!name) return nm_assert_unreachable_val(FALSE); @@ -6210,7 +6228,7 @@ char * _nm_utils_ssid_to_string_arr(const guint8 *ssid, gsize len) { gs_free char *s_copy = NULL; - const char * s_cnst; + const char *s_cnst; if (len == 0) return g_strdup("(empty)"); @@ -6286,7 +6304,7 @@ nm_utils_ip4_address_clear_host_address(in_addr_t addr, guint8 plen) * @dst and @src to the same destination or set @src NULL. */ const struct in6_addr * -nm_utils_ip6_address_clear_host_address(struct in6_addr * dst, +nm_utils_ip6_address_clear_host_address(struct in6_addr *dst, const struct in6_addr *src, guint8 plen) { @@ -6475,10 +6493,10 @@ nm_crypto_md5_hash(const guint8 *salt, gsize salt_len, const guint8 *password, gsize password_len, - guint8 * buffer, + guint8 *buffer, gsize buflen) { - nm_auto_free_checksum GChecksum * ctx = NULL; + nm_auto_free_checksum GChecksum *ctx = NULL; nm_auto_clear_static_secret_ptr const NMSecretPtr digest = NM_SECRET_PTR_STATIC(NM_UTILS_CHECKSUM_LENGTH_MD5); gsize bufidx = 0; @@ -6569,7 +6587,7 @@ static pthread_key_t _tls_reg_key; static void _tls_reg_destroy(gpointer data) { - CList * lst_head = data; + CList *lst_head = data; TlsRegData *entry; if (!lst_head) @@ -6612,8 +6630,8 @@ nm_utils_thread_local_register_destroy(gpointer tls_data, GDestroyNotify destroy { NM_AUTO_PROTECT_ERRNO(errsv); static pthread_once_t key_once = PTHREAD_ONCE_INIT; - CList * lst_head; - TlsRegData * entry; + CList *lst_head; + TlsRegData *entry; nm_assert(destroy_notify); diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h index 8dd53dcf..54550f27 100644 --- a/src/libnm-glib-aux/nm-shared-utils.h +++ b/src/libnm-glib-aux/nm-shared-utils.h @@ -36,12 +36,7 @@ pid_t nm_utils_gettid(void); gboolean _nm_assert_on_main_thread(void); #if NM_MORE_ASSERTS > 5 -#define NM_ASSERT_ON_MAIN_THREAD() \ - G_STMT_START \ - { \ - nm_assert(_nm_assert_on_main_thread()); \ - } \ - G_STMT_END +#define NM_ASSERT_ON_MAIN_THREAD() nm_assert(_nm_assert_on_main_thread()) #else #define NM_ASSERT_ON_MAIN_THREAD() \ G_STMT_START \ @@ -90,7 +85,7 @@ G_STATIC_ASSERT(sizeof(int) == sizeof(gint32)); #define _NM_INT_LE_MAXINT32(value) \ ({ \ _nm_unused typeof(value) _value = (value); \ - _nm_unused const int * _p_value = &_value; \ + _nm_unused const int *_p_value = &_value; \ \ TRUE; \ }) @@ -248,10 +243,9 @@ extern const NMIPAddr nm_ip_addr_zero; static inline int nm_ip_addr_cmp(int addr_family, gconstpointer a, gconstpointer b) { - nm_assert(a); - nm_assert(b); - - return memcmp(a, b, nm_utils_addr_family_to_size(addr_family)); + NM_CMP_SELF(a, b); + NM_CMP_DIRECT_MEMCMP(a, b, nm_utils_addr_family_to_size(addr_family)); + return 0; } static inline gboolean @@ -313,7 +307,7 @@ gboolean nm_ip_addr_set_from_untrusted(int addr_family, gpointer dst, gconstpointer src, gsize src_len, - int * out_addr_family); + int *out_addr_family); gboolean nm_ip_addr_set_from_variant(int addr_family, gpointer dst, GVariant *variant, int *out_addr_family); @@ -375,20 +369,20 @@ typedef struct _NMUtilsIPv6IfaceId { } \ } -void nm_utils_ipv6_addr_set_interface_identifier(struct in6_addr * addr, +void nm_utils_ipv6_addr_set_interface_identifier(struct in6_addr *addr, const NMUtilsIPv6IfaceId *iid); -void nm_utils_ipv6_interface_identifier_get_from_addr(NMUtilsIPv6IfaceId * iid, +void nm_utils_ipv6_interface_identifier_get_from_addr(NMUtilsIPv6IfaceId *iid, const struct in6_addr *addr); gboolean nm_utils_ipv6_interface_identifier_get_from_token(NMUtilsIPv6IfaceId *iid, - const char * token); + const char *token); const char *nm_utils_inet6_interface_identifier_to_token(const NMUtilsIPv6IfaceId *iid, char buf[static INET6_ADDRSTRLEN]); gboolean nm_utils_get_ipv6_interface_identifier(NMLinkType link_type, - const guint8 * hwaddr, + const guint8 *hwaddr, guint len, guint dev_id, NMUtilsIPv6IfaceId *out_iid); @@ -398,7 +392,7 @@ gboolean nm_utils_get_ipv6_interface_identifier(NMLinkType link_type, gconstpointer nm_utils_ipx_address_clear_host_address(int family, gpointer dst, gconstpointer src, guint8 plen); in_addr_t nm_utils_ip4_address_clear_host_address(in_addr_t addr, guint8 plen); -const struct in6_addr *nm_utils_ip6_address_clear_host_address(struct in6_addr * dst, +const struct in6_addr *nm_utils_ip6_address_clear_host_address(struct in6_addr *dst, const struct in6_addr *src, guint8 plen); @@ -623,9 +617,9 @@ GVariant *nm_strdict_to_variant_asv(GHashTable *strdict); GVariant *nm_utils_gvariant_vardict_filter(GVariant *src, gboolean (*filter_fcn)(const char *key, - GVariant * val, - char ** out_key, - GVariant ** out_val, + GVariant *val, + char **out_key, + GVariant **out_val, gpointer user_data), gpointer user_data); @@ -751,7 +745,7 @@ gboolean nm_strv_has_duplicate(const char *const *list, gssize len, gboolean is_ const char **nm_strv_cleanup_const(const char **strv, gboolean skip_empty, gboolean skip_repeated); -char **nm_strv_cleanup(char ** strv, +char **nm_strv_cleanup(char **strv, gboolean strip_whitespace, gboolean skip_empty, gboolean skip_repeated); @@ -824,7 +818,7 @@ const char *nm_utils_escaped_tokens_escape_full(const char *str, const char *delimiters, const char *delimiters_as_needed, NMUtilsEscapedTokensEscapeFlags flags, - char ** out_to_free); + char **out_to_free); static inline const char * nm_utils_escaped_tokens_escape(const char *str, const char *delimiters, char **out_to_free) @@ -859,7 +853,7 @@ nm_utils_escaped_tokens_escape_unnecessary(const char *str, const char *delimite { gs_free char *str_to_free = NULL; - const char * str0; + const char *str0; str0 = nm_utils_escaped_tokens_escape(str, delimiters, &str_to_free); nm_assert(str0 == str); @@ -873,7 +867,7 @@ nm_utils_escaped_tokens_escape_unnecessary(const char *str, const char *delimite static inline void nm_utils_escaped_tokens_escape_gstr_assert(const char *str, const char *delimiters, - GString * gstring) + GString *gstring) { g_string_append(gstring, nm_utils_escaped_tokens_escape_unnecessary(str, delimiters)); } @@ -987,7 +981,7 @@ guint32 _nm_utils_ip4_get_default_prefix(in_addr_t ip); gconstpointer nm_utils_ipx_address_clear_host_address(int family, gpointer dst, gconstpointer src, guint8 plen); in_addr_t nm_utils_ip4_address_clear_host_address(in_addr_t addr, guint8 plen); -const struct in6_addr *nm_utils_ip6_address_clear_host_address(struct in6_addr * dst, +const struct in6_addr *nm_utils_ip6_address_clear_host_address(struct in6_addr *dst, const struct in6_addr *src, guint8 plen); int nm_utils_ip6_address_same_prefix_cmp(const struct in6_addr *addr_a, @@ -1001,12 +995,12 @@ gboolean nm_utils_ip_is_site_local(int addr_family, const void *address); gboolean nm_utils_parse_inaddr_bin_full(int addr_family, gboolean accept_legacy, const char *text, - int * out_addr_family, + int *out_addr_family, gpointer out_addr); static inline gboolean nm_utils_parse_inaddr_bin(int addr_family, const char *text, - int * out_addr_family, + int *out_addr_family, gpointer out_addr) { return nm_utils_parse_inaddr_bin_full(addr_family, FALSE, text, out_addr_family, out_addr); @@ -1016,17 +1010,17 @@ gboolean nm_utils_parse_inaddr(int addr_family, const char *text, char **out_add gboolean nm_utils_parse_inaddr_prefix_bin(int addr_family, const char *text, - int * out_addr_family, + int *out_addr_family, gpointer out_addr, - int * out_prefix); + int *out_prefix); gboolean nm_utils_parse_inaddr_prefix(int addr_family, const char *text, char **out_addr, int *out_prefix); gboolean nm_utils_parse_next_line(const char **inout_ptr, - gsize * inout_len, + gsize *inout_len, const char **out_line, - gsize * out_line_len); + gsize *out_line_len); gint64 nm_g_ascii_strtoll(const char *nptr, char **endptr, guint base); @@ -1083,7 +1077,7 @@ typedef struct { const char *nm_utils_flags2str(const NMUtilsFlags2StrDesc *descs, gsize n_descs, unsigned flags, - char * buf, + char *buf, gsize len); /*****************************************************************************/ @@ -1373,70 +1367,70 @@ nm_utils_error_set_literal(GError **error, int error_code, const char *literal) /*****************************************************************************/ -gboolean nm_g_object_set_property(GObject * object, - const char * property_name, +gboolean nm_g_object_set_property(GObject *object, + const char *property_name, const GValue *value, - GError ** error); + GError **error); -gboolean nm_g_object_set_property_string(GObject * object, +gboolean nm_g_object_set_property_string(GObject *object, const char *property_name, const char *value, - GError ** error); + GError **error); -gboolean nm_g_object_set_property_string_static(GObject * object, +gboolean nm_g_object_set_property_string_static(GObject *object, const char *property_name, const char *value, - GError ** error); + GError **error); -gboolean nm_g_object_set_property_string_take(GObject * object, +gboolean nm_g_object_set_property_string_take(GObject *object, const char *property_name, - char * value, - GError ** error); + char *value, + GError **error); -gboolean nm_g_object_set_property_boolean(GObject * object, +gboolean nm_g_object_set_property_boolean(GObject *object, const char *property_name, gboolean value, - GError ** error); + GError **error); -gboolean nm_g_object_set_property_char(GObject * object, +gboolean nm_g_object_set_property_char(GObject *object, const char *property_name, gint8 value, - GError ** error); + GError **error); -gboolean nm_g_object_set_property_uchar(GObject * object, +gboolean nm_g_object_set_property_uchar(GObject *object, const char *property_name, guint8 value, - GError ** error); + GError **error); gboolean nm_g_object_set_property_int(GObject *object, const char *property_name, int value, GError **error); -gboolean nm_g_object_set_property_int64(GObject * object, +gboolean nm_g_object_set_property_int64(GObject *object, const char *property_name, gint64 value, - GError ** error); + GError **error); -gboolean nm_g_object_set_property_uint(GObject * object, +gboolean nm_g_object_set_property_uint(GObject *object, const char *property_name, guint value, - GError ** error); + GError **error); -gboolean nm_g_object_set_property_uint64(GObject * object, +gboolean nm_g_object_set_property_uint64(GObject *object, const char *property_name, guint64 value, - GError ** error); + GError **error); -gboolean nm_g_object_set_property_flags(GObject * object, +gboolean nm_g_object_set_property_flags(GObject *object, const char *property_name, GType gtype, guint value, - GError ** error); + GError **error); -gboolean nm_g_object_set_property_enum(GObject * object, +gboolean nm_g_object_set_property_enum(GObject *object, const char *property_name, GType gtype, int value, - GError ** error); + GError **error); GParamSpec *nm_g_object_class_find_property_from_gtype(GType gtype, const char *property_name); @@ -1464,6 +1458,8 @@ GParamSpec *nm_g_object_class_find_property_from_gtype(GType gtype, const char * _NM_G_PARAM_SPEC_CAST(param_spec, G_TYPE_INT, GParamSpecInt) #define NM_G_PARAM_SPEC_CAST_UINT(param_spec) \ _NM_G_PARAM_SPEC_CAST(param_spec, G_TYPE_UINT, GParamSpecUInt) +#define NM_G_PARAM_SPEC_CAST_INT64(param_spec) \ + _NM_G_PARAM_SPEC_CAST(param_spec, G_TYPE_INT64, GParamSpecInt64) #define NM_G_PARAM_SPEC_CAST_UINT64(param_spec) \ _NM_G_PARAM_SPEC_CAST(param_spec, G_TYPE_UINT64, GParamSpecUInt64) #define NM_G_PARAM_SPEC_CAST_ENUM(param_spec) \ @@ -1479,6 +1475,8 @@ GParamSpec *nm_g_object_class_find_property_from_gtype(GType gtype, const char * (NM_G_PARAM_SPEC_CAST_INT(NM_ENSURE_NOT_NULL(param_spec))->default_value) #define NM_G_PARAM_SPEC_GET_DEFAULT_UINT(param_spec) \ (NM_G_PARAM_SPEC_CAST_UINT(NM_ENSURE_NOT_NULL(param_spec))->default_value) +#define NM_G_PARAM_SPEC_GET_DEFAULT_INT64(param_spec) \ + (NM_G_PARAM_SPEC_CAST_INT64(NM_ENSURE_NOT_NULL(param_spec))->default_value) #define NM_G_PARAM_SPEC_GET_DEFAULT_UINT64(param_spec) \ (NM_G_PARAM_SPEC_CAST_UINT64(NM_ENSURE_NOT_NULL(param_spec))->default_value) #define NM_G_PARAM_SPEC_GET_DEFAULT_ENUM(param_spec) \ @@ -1526,15 +1524,15 @@ typedef enum { const char *nm_utils_buf_utf8safe_escape(gconstpointer buf, gssize buflen, NMUtilsStrUtf8SafeFlags flags, - char ** to_free); + char **to_free); char * nm_utils_buf_utf8safe_escape_cp(gconstpointer buf, gssize buflen, NMUtilsStrUtf8SafeFlags flags); const char * nm_utils_buf_utf8safe_escape_bytes(GBytes *bytes, NMUtilsStrUtf8SafeFlags flags, char **to_free); -gconstpointer nm_utils_buf_utf8safe_unescape(const char * str, +gconstpointer nm_utils_buf_utf8safe_unescape(const char *str, NMUtilsStrUtf8SafeFlags flags, - gsize * out_len, - gpointer * to_free); + gsize *out_len, + gpointer *to_free); const char * nm_utils_str_utf8safe_escape(const char *str, NMUtilsStrUtf8SafeFlags flags, char **to_free); @@ -1634,8 +1632,8 @@ nm_g_variant_builder_add_sv(GVariantBuilder *builder, const char *key, GVariant static inline void nm_g_variant_builder_add_sv_bytearray(GVariantBuilder *builder, - const char * key, - const guint8 * arr, + const char *key, + const guint8 *arr, gsize len) { g_variant_builder_add(builder, "{sv}", key, nm_g_variant_new_ay(arr, len)); @@ -1660,15 +1658,16 @@ nm_g_source_destroy_and_unref(GSource *source) * will destroy the user-data of the callback right away (and not only * during the last g_source_unref()). * - * It also means, that if the user data itself has the reference to the - * source, then this will lead to crash: + * This means for example, if the user data itself has the reference to the + * source, then the following would lead to a crash: * * g_source_destroy(user_data->my_source); * // ups, user_data was destroyed (if source was attached). * g_source_unref(user_data->my_source); * - * nm_g_source_destroy_and_unref() and nm_clear_g_source_inst() does not - * suffer from this problem. */ + * nm_g_source_destroy_and_unref(user_data->my_source) and nm_clear_g_source_inst(&user_data->my_source) + * does not have this problem (of course, afterwards, user_data would be a dangling + * pointer). */ g_source_destroy(source); g_source_unref(source); } @@ -1960,12 +1959,12 @@ typedef struct { typedef struct { union { NMUtilsNamedEntry named_entry; - const char * name; - char * name_mutable; + const char *name; + char *name_mutable; }; union { const char *value_str; - char * value_str_mutable; + char *value_str_mutable; gpointer value_ptr; }; } NMUtilsNamedValue; @@ -1976,11 +1975,11 @@ typedef struct { } NMUtilsNamedValue * -nm_utils_named_values_from_strdict_full(GHashTable * hash, - guint * out_len, +nm_utils_named_values_from_strdict_full(GHashTable *hash, + guint *out_len, GCompareDataFunc compare_func, gpointer user_data, - NMUtilsNamedValue * provided_buffer, + NMUtilsNamedValue *provided_buffer, guint provided_buffer_len, NMUtilsNamedValue **out_allocated_buffer); @@ -1995,7 +1994,7 @@ nm_utils_named_values_from_strdict_full(GHashTable * hash, gssize nm_utils_named_value_list_find(const NMUtilsNamedValue *arr, gsize len, - const char * name, + const char *name, gboolean sorted); gboolean nm_utils_named_value_list_is_sorted(const NMUtilsNamedValue *arr, @@ -2013,15 +2012,15 @@ void nm_utils_named_value_clear_with_g_free(NMUtilsNamedValue *val); /*****************************************************************************/ -gpointer *nm_utils_hash_keys_to_array(GHashTable * hash, +gpointer *nm_utils_hash_keys_to_array(GHashTable *hash, GCompareDataFunc compare_func, gpointer user_data, - guint * out_len); + guint *out_len); -gpointer *nm_utils_hash_values_to_array(GHashTable * hash, +gpointer *nm_utils_hash_values_to_array(GHashTable *hash, GCompareDataFunc compare_func, gpointer user_data, - guint * out_len); + guint *out_len); static inline const char ** nm_strdict_get_keys(const GHashTable *hash, gboolean sorted, guint *out_length) @@ -2078,7 +2077,7 @@ const char **_nm_strv_dup_packed(const char *const *strv, gssize len); ({ \ const char *const *const _strv = NM_CAST_STRV_CC(strv); \ const gssize _len = (len); \ - const char ** _result = NULL; \ + const char **_result = NULL; \ const char ***const _to_free = (to_free); \ \ G_STATIC_ASSERT_EXPR((alloca_maxlen) <= 500u / sizeof(const char *)); \ @@ -2177,7 +2176,7 @@ nm_g_ptr_array_unref(GPtrArray *arr) #define nm_g_ptr_array_set(pdst, val) \ ({ \ GPtrArray **_pdst = (pdst); \ - GPtrArray * _val = (val); \ + GPtrArray *_val = (val); \ gboolean _changed = FALSE; \ \ nm_assert(_pdst); \ @@ -2194,7 +2193,7 @@ nm_g_ptr_array_unref(GPtrArray *arr) #define nm_g_ptr_array_set_take(pdst, val) \ ({ \ GPtrArray **_pdst = (pdst); \ - GPtrArray * _val = (val); \ + GPtrArray *_val = (val); \ gboolean _changed = FALSE; \ \ nm_assert(_pdst); \ @@ -2222,7 +2221,7 @@ nm_g_ptr_array_pdata(const GPtrArray *arr) return arr ? arr->pdata : NULL; } -GPtrArray *_nm_g_ptr_array_copy(GPtrArray * array, +GPtrArray *_nm_g_ptr_array_copy(GPtrArray *array, GCopyFunc func, gpointer user_data, GDestroyNotify element_free_func); @@ -2298,25 +2297,25 @@ nm_g_hash_table_remove(GHashTable *hash, gconstpointer key) /*****************************************************************************/ -gboolean nm_utils_ptrarray_is_sorted(gconstpointer * list, +gboolean nm_utils_ptrarray_is_sorted(gconstpointer *list, gsize len, gboolean require_strict, GCompareDataFunc cmpfcn, gpointer user_data); -gssize nm_utils_ptrarray_find_binary_search(gconstpointer * list, +gssize nm_utils_ptrarray_find_binary_search(gconstpointer *list, gsize len, gconstpointer needle, GCompareDataFunc cmpfcn, gpointer user_data); -gssize nm_utils_ptrarray_find_binary_search_range(gconstpointer * list, +gssize nm_utils_ptrarray_find_binary_search_range(gconstpointer *list, gsize len, gconstpointer needle, GCompareDataFunc cmpfcn, gpointer user_data, - gssize * out_idx_first, - gssize * out_idx_last); + gssize *out_idx_first, + gssize *out_idx_last); #define nm_strv_find_binary_search(strv, len, needle) \ ({ \ @@ -2546,12 +2545,12 @@ void _nm_utils_user_data_unpack(NMUtilsUserData *user_data, int nargs, ...); typedef void (*NMUtilsInvokeOnIdleCallback)(gpointer user_data, GCancellable *cancellable); -void nm_utils_invoke_on_idle(GCancellable * cancellable, +void nm_utils_invoke_on_idle(GCancellable *cancellable, NMUtilsInvokeOnIdleCallback callback, gpointer callback_user_data); void nm_utils_invoke_on_timeout(guint timeout_msec, - GCancellable * cancellable, + GCancellable *cancellable, NMUtilsInvokeOnIdleCallback callback, gpointer callback_user_data); @@ -2707,15 +2706,15 @@ char *nm_utils_bin2hexstr_full(gconstpointer addr, gsize length, char delimiter, gboolean upper_case, - char * out); + char *out); #define nm_utils_bin2hexstr_a(addr, length, delimiter, upper_case, str_to_free) \ ({ \ gconstpointer _addr = (addr); \ gsize _length = (length); \ char _delimiter = (delimiter); \ - char ** _str_to_free = (str_to_free); \ - char * _s; \ + char **_str_to_free = (str_to_free); \ + char *_s; \ gsize _s_len; \ \ nm_assert(_str_to_free); \ @@ -2748,9 +2747,9 @@ guint8 *nm_utils_hexstr2bin_full(const char *hexstr, gboolean hexdigit_pairs_required, const char *delimiter_candidates, gsize required_len, - guint8 * buffer, + guint8 *buffer, gsize buffer_len, - gsize * out_len); + gsize *out_len); #define nm_utils_hexstr2bin_buf(hexstr, \ allow_0x_prefix, \ @@ -2772,7 +2771,7 @@ guint8 *nm_utils_hexstr2bin_alloc(const char *hexstr, gboolean delimiter_required, const char *delimiter_candidates, gsize required_len, - gsize * out_len); + gsize *out_len); /** * _nm_utils_hwaddr_aton: @@ -2834,7 +2833,7 @@ static inline const char * _nm_utils_hwaddr_ntoa(gconstpointer addr, gsize addr_len, gboolean upper_case, - char * buf, + char *buf, gsize buf_len) { g_return_val_if_fail(addr, NULL); @@ -2952,7 +2951,7 @@ _nm_utils_hwaddr_ntoa(gconstpointer addr, static inline GTask * nm_g_task_new(gpointer source_object, - GCancellable * cancellable, + GCancellable *cancellable, gpointer source_tag, GAsyncReadyCallback callback, gpointer callback_data) @@ -3143,25 +3142,31 @@ nm_strvarray_remove_first(GArray *strv, const char *needle) /*****************************************************************************/ struct _NMVariantAttributeSpec { - char * name; + char *name; const GVariantType *type; bool v4 : 1; bool v6 : 1; bool no_value : 1; bool consumes_rest : 1; - char str_type; + + /* This indicates a non-standard parsing behavior. What this is, + * depends on the actual validation and how to handle it. + * + * Note that the entire NMVariantAttributeSpec is internal API, + * so we can change behavior and adjust it as it fits. */ + char type_detail; }; typedef struct _NMVariantAttributeSpec NMVariantAttributeSpec; -void _nm_utils_format_variant_attributes_full(GString * str, - const NMUtilsNamedValue * values, +void _nm_utils_format_variant_attributes_full(GString *str, + const NMUtilsNamedValue *values, guint num_values, const NMVariantAttributeSpec *const *spec, char attr_separator, char key_value_separator); -char *_nm_utils_format_variant_attributes(GHashTable * attributes, +char *_nm_utils_format_variant_attributes(GHashTable *attributes, const NMVariantAttributeSpec *const *spec, char attr_separator, char key_value_separator); @@ -3172,7 +3177,7 @@ gboolean nm_utils_is_localhost(const char *name); gboolean nm_utils_is_specific_hostname(const char *name); -char * nm_utils_uid_to_name(uid_t uid); +char *nm_utils_uid_to_name(uid_t uid); gboolean nm_utils_name_to_uid(const char *name, uid_t *out_uid); /*****************************************************************************/ @@ -3183,8 +3188,8 @@ double nm_utils_exp10(gint16 e); gboolean _nm_utils_is_empty_ssid_arr(const guint8 *ssid, gsize len); gboolean _nm_utils_is_empty_ssid_gbytes(GBytes *ssid); -char * _nm_utils_ssid_to_string_arr(const guint8 *ssid, gsize len); -char * _nm_utils_ssid_to_string_gbytes(GBytes *ssid); +char *_nm_utils_ssid_to_string_arr(const guint8 *ssid, gsize len); +char *_nm_utils_ssid_to_string_gbytes(GBytes *ssid); /*****************************************************************************/ @@ -3207,7 +3212,7 @@ void nm_crypto_md5_hash(const guint8 *salt, gsize salt_len, const guint8 *password, gsize password_len, - guint8 * buffer, + guint8 *buffer, gsize buflen); /*****************************************************************************/ diff --git a/src/libnm-glib-aux/nm-str-buf.h b/src/libnm-glib-aux/nm-str-buf.h index 7a7f580c..47d1f055 100644 --- a/src/libnm-glib-aux/nm-str-buf.h +++ b/src/libnm-glib-aux/nm-str-buf.h @@ -348,7 +348,7 @@ nm_utils_escaped_tokens_escape_strbuf(const char *str, const char *delimiters, N static inline void nm_utils_escaped_tokens_escape_strbuf_assert(const char *str, const char *delimiters, - NMStrBuf * strbuf) + NMStrBuf *strbuf) { nm_str_buf_append(strbuf, nm_utils_escaped_tokens_escape_unnecessary(str, delimiters)); } diff --git a/src/libnm-glib-aux/nm-test-utils.h b/src/libnm-glib-aux/nm-test-utils.h index 253aaf0e..caf43d5f 100644 --- a/src/libnm-glib-aux/nm-test-utils.h +++ b/src/libnm-glib-aux/nm-test-utils.h @@ -104,7 +104,7 @@ #define nmtst_assert_error(error, expect_error_domain, expect_error_code, expect_error_pattern) \ G_STMT_START \ { \ - GError * _error = (error); \ + GError *_error = (error); \ GQuark _expect_error_domain = (expect_error_domain); \ const char *_expect_error_pattern = (expect_error_pattern); \ \ @@ -182,6 +182,23 @@ } \ G_STMT_END +#define nmtst_assert_strv(strv, ...) \ + G_STMT_START \ + { \ + const char *const *const _strv = (strv); \ + const char *const _exp[] = {__VA_ARGS__, NULL}; \ + const gsize _n = G_N_ELEMENTS(_exp) - 1; \ + gsize _i; \ + \ + g_assert(_n == NM_NARG(__VA_ARGS__)); \ + g_assert(_strv); \ + for (_i = 0; _i < _n; _i++) { \ + g_assert(_exp[_i]); \ + g_assert_cmpstr(_strv[_i], ==, _exp[_i]); \ + } \ + } \ + G_STMT_END + /*****************************************************************************/ /* Our nm-error error numbers use negative values to signal failure. @@ -204,16 +221,16 @@ /*****************************************************************************/ struct __nmtst_internal { - GRand * rand0; + GRand *rand0; guint32 rand_seed; - GRand * rand; + GRand *rand; gboolean is_debug; gboolean assert_logging; gboolean no_expect_message; gboolean test_quick; gboolean test_tap_log; - char * sudo_cmd; - char ** orig_argv; + char *sudo_cmd; + char **orig_argv; }; extern struct __nmtst_internal __nmtst_internal; @@ -255,7 +272,7 @@ static inline char ** nmtst_str_split(char *str, const char *delimiters) { const char *d; - GArray * result = g_array_sized_new(TRUE, FALSE, sizeof(char *), 3); + GArray *result = g_array_sized_new(TRUE, FALSE, sizeof(char *), 3); g_assert(str); g_assert(delimiters && !strchr(delimiters, '\\')); @@ -312,35 +329,35 @@ nmtst_free(void) } static inline void -_nmtst_log_handler(const char * log_domain, +_nmtst_log_handler(const char *log_domain, GLogLevelFlags log_level, - const char * message, + const char *message, gpointer user_data) { g_print("%s\n", message); } static inline void -__nmtst_init(int * argc, - char *** argv, +__nmtst_init(int *argc, + char ***argv, gboolean assert_logging, const char *log_level, const char *log_domains, - gboolean * out_set_logging) -{ - const char * nmtst_debug; - gboolean is_debug = FALSE; - char * c_log_level = NULL, *c_log_domains = NULL; - char * sudo_cmd = NULL; - GArray * debug_messages = g_array_new(TRUE, FALSE, sizeof(char *)); - int i; - gboolean no_expect_message = FALSE; - gboolean _out_set_logging; - gboolean test_quick = FALSE; - gboolean test_quick_set = FALSE; - gboolean test_quick_argv = FALSE; - gs_unref_ptrarray GPtrArray *p_tests = NULL; - gs_unref_ptrarray GPtrArray *s_tests = NULL; + gboolean *out_set_logging) +{ + const char *nmtst_debug; + gboolean is_debug = FALSE; + char *c_log_level = NULL, *c_log_domains = NULL; + char *sudo_cmd = NULL; + GArray *debug_messages = g_array_new(TRUE, FALSE, sizeof(char *)); + int i; + gboolean no_expect_message = FALSE; + gboolean _out_set_logging; + gboolean test_quick = FALSE; + gboolean test_quick_set = FALSE; + gboolean test_quick_argv = FALSE; + gs_unref_ptrarray GPtrArray *p_tests = NULL; + gs_unref_ptrarray GPtrArray *s_tests = NULL; if (!out_set_logging) out_set_logging = &_out_set_logging; @@ -471,10 +488,10 @@ __nmtst_init(int * argc, /* g_test_init() sets g_log_set_always_fatal() for G_LOG_LEVEL_WARNING * and G_LOG_LEVEL_CRITICAL. So, beware that the test will fail if you * have any WARN or ERR log messages -- unless you g_test_expect_message(). */ - GPtrArray * arg_array = g_ptr_array_new(); + GPtrArray *arg_array = g_ptr_array_new(); gs_free char **arg_array_c = NULL; int arg_array_n, j; - static char ** s_tests_x, **p_tests_x; + static char **s_tests_x, **p_tests_x; if (*argc) { for (i = 0; i < *argc; i++) @@ -628,7 +645,7 @@ __nmtst_init(int * argc, * add "/bin" and "/sbin" to $PATH for all tests. */ { static char *path_new; - const char * path_old; + const char *path_old; g_assert(!path_new); @@ -692,6 +709,17 @@ nmtst_test_quick(void) return __nmtst_internal.test_quick; } +static inline gboolean +nmtst_test_skip_slow(void) +{ + if (!nmtst_test_quick()) + return FALSE; + + g_print("Skipping test: don't run long running test %s (NMTST_DEBUG=slow)\n", g_get_prgname()); + g_test_skip("Skip long running test"); + return TRUE; +} + #if GLIB_CHECK_VERSION(2, 34, 0) #undef g_test_expect_message #define g_test_expect_message(...) \ @@ -747,10 +775,10 @@ typedef void (*NmtstTestHandler)(const NmtstTestData *test_data); struct _NmtstTestData { union { const char *testpath; - char * _testpath; + char *_testpath; }; gsize n_args; - gpointer * args; + gpointer *args; NmtstTestHandler _func_setup; GTestDataFunc _func_test; NmtstTestHandler _func_teardown; @@ -804,7 +832,7 @@ _nmtst_test_run(gconstpointer data) } static inline void -_nmtst_add_test_func_full(const char * testpath, +_nmtst_add_test_func_full(const char *testpath, GTestDataFunc func_test, NmtstTestHandler func_setup, NmtstTestHandler func_teardown, @@ -874,7 +902,7 @@ nmtst_get_rand(void) g_rand_set_seed(__nmtst_internal.rand, seed); } else { /* NMTST_SEED_RAND is set. Use it as a seed. */ - char * s; + char *s; gint64 i; i = g_ascii_strtoll(str, &s, 0); @@ -1067,7 +1095,7 @@ nmtst_stable_rand(guint64 seed, gpointer buf, gsize len) { const guint64 C = 1442695040888963407llu; const guint64 A = 6364136223846793005llu; - guint8 * b; + guint8 *b; union { guint8 a[sizeof(guint64)]; guint64 n; @@ -1203,7 +1231,7 @@ static inline gboolean nmtst_main_loop_run(GMainLoop *loop, guint timeout_msec) { nm_auto_unref_gsource GSource *source = NULL; - GMainLoop * loopx = loop; + GMainLoop *loopx = loop; if (timeout_msec > 0) { source = g_timeout_source_new(timeout_msec); @@ -1244,7 +1272,7 @@ _nmtst_main_loop_quit_on_notify(GObject *object, GParamSpec *pspec, gpointer use ({ \ nm_auto_destroy_and_unref_gsource GSource *_source_timeout = NULL; \ nm_auto_destroy_and_unref_gsource GSource *_source_poll = NULL; \ - GMainContext * _context = (context); \ + GMainContext *_context = (context); \ gboolean _had_timeout = FALSE; \ typeof(timeout_msec) _timeout_msec0 = (timeout_msec); \ typeof(poll_msec) _poll_msec0 = (poll_msec); \ @@ -1319,7 +1347,7 @@ nmtst_main_context_assert_no_dispatch(GMainContext *context, guint timeout_msec) typedef struct { GMainLoop *_main_loop; union { - GSList * _list; + GSList *_list; const void *const is_waiting; }; } NMTstContextBusyWatcherData; @@ -1328,7 +1356,7 @@ static inline void _nmtst_context_busy_watcher_add_cb(gpointer data, GObject *where_the_object_was) { NMTstContextBusyWatcherData *watcher_data = data; - GSList * l; + GSList *l; g_assert(watcher_data); @@ -1389,7 +1417,7 @@ nmtst_get_sudo_cmd(void) static inline void nmtst_reexec_sudo(void) { - char * str; + char *str; char **argv; int i; int errsv; @@ -1426,7 +1454,7 @@ nmtst_find_all_indexes(gpointer *elements, gsize n_needles, gboolean (*equal_fcn)(gpointer element, gpointer needle, gpointer user_data), gpointer user_data, - gssize * out_idx) + gssize *out_idx) { gsize i, j, k; gsize found = 0; @@ -1489,13 +1517,13 @@ __define_nmtst_static(01, 1024) __define_nmtst_static(02, 1024) __define_nmtst_s #if defined(__NM_UTILS_H__) || defined(NM_UTILS_H) #define NMTST_UUID_INIT(uuid) \ - gs_free char * _nmtst_hidden_##uuid = nm_utils_uuid_generate(); \ + gs_free char *_nmtst_hidden_##uuid = nm_utils_uuid_generate(); \ const char *const uuid = _nmtst_hidden_##uuid static inline const char *nmtst_uuid_generate(void) { static _nm_thread_local char u[37]; - gs_free char * m = NULL; + gs_free char *m = NULL; m = nm_utils_uuid_generate(); g_assert(m && strlen(m) == sizeof(u) - 1); @@ -1609,10 +1637,10 @@ _nmtst_assert_ip4_address(const char *file, int line, in_addr_t addr, const char _nmtst_assert_ip4_address(__FILE__, __LINE__, addr, str_expected) static inline void -_nmtst_assert_ip6_address(const char * file, +_nmtst_assert_ip6_address(const char *file, int line, const struct in6_addr *addr, - const char * str_expected) + const char *str_expected) { struct in6_addr any = in6addr_any; @@ -1650,20 +1678,20 @@ _nmtst_assert_ip6_address(const char * file, ##__VA_ARGS__, \ NULL) static inline int __nmtst_spawn_sync(const char *working_directory, - char ** standard_out, - char ** standard_err, + char **standard_out, + char **standard_err, int assert_exit_status, ...) G_GNUC_NULL_TERMINATED; static inline int __nmtst_spawn_sync(const char *working_directory, - char ** standard_out, - char ** standard_err, + char **standard_out, + char **standard_err, int assert_exit_status, ...) { int exit_status = 0; - GError * error = NULL; - char * arg; + GError *error = NULL; + char *arg; va_list va_args; GPtrArray *argv = g_ptr_array_new(); gboolean success; @@ -1724,9 +1752,9 @@ nmtst_file_resolve_relative_path(const char *rel, const char *cwd) static inline char * nmtst_file_get_contents(const char *filename) { - GError * error = NULL; + GError *error = NULL; gboolean success; - char * contents = NULL; + char *contents = NULL; gsize len; success = g_file_get_contents(filename, &contents, &len, &error); @@ -1738,7 +1766,7 @@ nmtst_file_get_contents(const char *filename) #define nmtst_file_set_contents_size(filename, content, size) \ G_STMT_START \ { \ - GError * _error = NULL; \ + GError *_error = NULL; \ gboolean _success; \ const char *_content = (content); \ gssize _size = (size); \ @@ -1924,9 +1952,9 @@ nmtst_setting_ip_config_add_address(NMSettingIPConfig *s_ip, const char *address static inline void nmtst_setting_ip_config_add_route(NMSettingIPConfig *s_ip, - const char * dest, + const char *dest, guint prefix, - const char * next_hop, + const char *next_hop, gint64 metric) { NMIPRoute *route; @@ -2030,15 +2058,15 @@ nmtst_clone_connection(NMConnection *connection) } static inline NMConnection * -nmtst_create_minimal_connection(const char * id, - const char * uuid, - const char * type, +nmtst_create_minimal_connection(const char *id, + const char *uuid, + const char *type, NMSettingConnection **out_s_con) { - NMConnection * con; - NMSetting * s_base = NULL; + NMConnection *con; + NMSetting *s_base = NULL; NMSettingConnection *s_con; - gs_free char * uuid_free = NULL; + gs_free char *uuid_free = NULL; g_assert(id); @@ -2095,7 +2123,7 @@ nmtst_create_minimal_connection(const char * id, static inline gboolean _nmtst_connection_normalize_v(NMConnection *connection, va_list args) { - GError * error = NULL; + GError *error = NULL; gboolean success; gboolean was_modified = FALSE; GHashTable *parameters = NULL; @@ -2156,10 +2184,10 @@ nmtst_assert_connection_equals(NMConnection *a, NMConnection *b, gboolean normalize_b) { - gboolean compare; + gboolean compare; gs_unref_object NMConnection *a2 = NULL; gs_unref_object NMConnection *b2 = NULL; - GHashTable * out_settings = NULL; + GHashTable *out_settings = NULL; g_assert(NM_IS_CONNECTION(a)); g_assert(NM_IS_CONNECTION(b)); @@ -2171,8 +2199,8 @@ nmtst_assert_connection_equals(NMConnection *a, compare = nm_connection_diff(a, b, NM_SETTING_COMPARE_FLAG_EXACT, &out_settings); if (!compare || out_settings) { - const char * name, *pname; - GHashTable * setting; + const char *name, *pname; + GHashTable *setting; GHashTableIter iter, iter2; __NMTST_LOG(g_message, ">>> ASSERTION nmtst_assert_connection_equals() fails"); @@ -2190,7 +2218,7 @@ nmtst_assert_connection_equals(NMConnection *a, #ifdef __NM_KEYFILE_INTERNAL_H__ { nm_auto_unref_keyfile GKeyFile *kf_a = NULL, *kf_b = NULL; - gs_free char * str_a = NULL, *str_b = NULL; + gs_free char *str_a = NULL, *str_b = NULL; kf_a = nm_keyfile_write(a, NM_KEYFILE_HANDLER_FLAGS_NONE, NULL, NULL, NULL); kf_b = nm_keyfile_write(b, NM_KEYFILE_HANDLER_FLAGS_NONE, NULL, NULL, NULL); @@ -2222,7 +2250,7 @@ static inline void nmtst_assert_connection_verifies(NMConnection *con) { /* assert that the connection does verify, it might be normaliziable or not */ - GError * error = NULL; + GError *error = NULL; gboolean success; g_assert(NM_IS_CONNECTION(con)); @@ -2236,10 +2264,10 @@ static inline void nmtst_assert_connection_verifies_without_normalization(NMConnection *con) { /* assert that the connection verifies and does not need any normalization */ - GError * error = NULL; - gboolean success; - gboolean was_modified = FALSE; - gs_unref_object NMConnection *clone = NULL; + GError *error = NULL; + gboolean success; + gboolean was_modified = FALSE; + gs_unref_object NMConnection *clone = NULL; clone = nmtst_clone_connection(con); @@ -2256,10 +2284,10 @@ static inline void nmtst_assert_connection_verifies_and_normalizable(NMConnection *con) { /* assert that the connection does verify, but normalization still modifies it */ - GError * error = NULL; - gboolean success; - gboolean was_modified = FALSE; - gs_unref_object NMConnection *clone = NULL; + GError *error = NULL; + gboolean success; + gboolean was_modified = FALSE; + gs_unref_object NMConnection *clone = NULL; clone = nmtst_clone_connection(con); @@ -2280,10 +2308,10 @@ nmtst_assert_connection_verifies_after_normalization(NMConnection *con, int expect_error_code) { /* assert that the connection does not verify, but normalization does fix it */ - GError * error = NULL; - gboolean success; - gboolean was_modified = FALSE; - gs_unref_object NMConnection *clone = NULL; + GError *error = NULL; + gboolean success; + gboolean was_modified = FALSE; + gs_unref_object NMConnection *clone = NULL; clone = nmtst_clone_connection(con); @@ -2308,10 +2336,10 @@ nmtst_assert_connection_unnormalizable(NMConnection *con, { /* assert that the connection does not verify, and it cannot be fixed by normalization */ - GError * error = NULL; - gboolean success; - gboolean was_modified = FALSE; - gs_unref_object NMConnection *clone = NULL; + GError *error = NULL; + gboolean success; + gboolean was_modified = FALSE; + gs_unref_object NMConnection *clone = NULL; clone = nmtst_clone_connection(con); @@ -2333,7 +2361,7 @@ nmtst_assert_setting_verifies(NMSetting *setting) { /* assert that the setting verifies without an error */ - GError * error = NULL; + GError *error = NULL; gboolean success; g_assert(NM_IS_SETTING(setting)); @@ -2351,12 +2379,12 @@ _nmtst_assert_connection_has_settings(NMConnection *connection, gboolean has_at_most, ...) { - gs_unref_hashtable GHashTable *names = NULL; - gs_free NMSetting **settings = NULL; - va_list ap; - const char * name; - guint i, len; - gs_unref_ptrarray GPtrArray *names_arr = NULL; + gs_unref_hashtable GHashTable *names = NULL; + gs_free NMSetting **settings = NULL; + va_list ap; + const char *name; + guint i, len; + gs_unref_ptrarray GPtrArray *names_arr = NULL; g_assert(NM_IS_CONNECTION(connection)); @@ -2382,9 +2410,9 @@ _nmtst_assert_connection_has_settings(NMConnection *connection, } } if (g_hash_table_size(names) > 0 && has_at_least) { - gs_free char * expected_str = g_strjoinv(" ", (char **) names_arr->pdata); + gs_free char *expected_str = g_strjoinv(" ", (char **) names_arr->pdata); gs_free const char **settings_names = NULL; - gs_free char * has_str = NULL; + gs_free char *has_str = NULL; settings_names = g_new0(const char *, len + 1); for (i = 0; i < len; i++) @@ -2413,7 +2441,7 @@ nmtst_assert_setting_verify_fails(NMSetting *setting, { /* assert that the setting verification fails */ - GError * error = NULL; + GError *error = NULL; gboolean success; g_assert(NM_IS_SETTING(setting)); @@ -2452,7 +2480,7 @@ nmtst_assert_setting_is_equal(gconstpointer /* const NMSetting * */ a, static inline NMSetting * nmtst_assert_setting_dbus_new(GType gtype, GVariant *variant) { - NMSetting * setting; + NMSetting *setting; gs_free_error GError *error = NULL; g_assert(g_type_is_a(gtype, NM_TYPE_SETTING)); @@ -2484,8 +2512,8 @@ nmtst_assert_setting_dbus_roundtrip(gconstpointer /* const NMSetting * */ settin static inline void nmtst_assert_hwaddr_equals(gconstpointer hwaddr1, gssize hwaddr1_len, - const char * expected, - const char * file, + const char *expected, + const char *file, int line) { guint8 buf2[NM_UTILS_HWADDR_LEN_MAX]; @@ -2531,11 +2559,11 @@ static inline NMConnection * nmtst_create_connection_from_keyfile(const char *keyfile_str, const char *full_filename) { nm_auto_unref_keyfile GKeyFile *keyfile = NULL; - gs_free_error GError *error = NULL; - gboolean success; - NMConnection * con; - gs_free char * filename = g_path_get_basename(full_filename); - gs_free char * base_dir = g_path_get_dirname(full_filename); + gs_free_error GError *error = NULL; + gboolean success; + NMConnection *con; + gs_free char *filename = g_path_get_basename(full_filename); + gs_free char *base_dir = g_path_get_dirname(full_filename); g_assert(keyfile_str); g_assert(full_filename && full_filename[0] == '/'); @@ -2568,8 +2596,8 @@ _nmtst_variant_new_vardict(int dummy, ...) { GVariantBuilder builder; va_list ap; - const char * name; - GVariant * variant; + const char *name; + GVariant *variant; g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT); @@ -2608,7 +2636,7 @@ _nmtst_variant_new_vardict(int dummy, ...) G_STMT_START \ { \ gsize _l; \ - GVariant * _variant = (variant); \ + GVariant *_variant = (variant); \ const char *_str = (str); \ \ nmtst_assert_variant_is_of_type(_variant, G_VARIANT_TYPE_STRING); \ @@ -2625,8 +2653,8 @@ _nmtst_variant_new_vardict(int dummy, ...) if (memcmp(_ptr2, _ptr, _len) != 0) { \ gs_free char *_x1 = NULL; \ gs_free char *_x2 = NULL; \ - const char * _xx1; \ - const char * _xx2; \ + const char *_xx1; \ + const char *_xx2; \ \ _xx1 = nm_utils_buf_utf8safe_escape(_ptr, \ _len, \ @@ -2650,7 +2678,7 @@ _nmtst_variant_new_vardict(int dummy, ...) #define nmtst_assert_variant_bytestring(variant, ptr, len) \ G_STMT_START \ { \ - GVariant * _variant = (variant); \ + GVariant *_variant = (variant); \ gconstpointer _ptr = (ptr); \ gconstpointer _ptr2; \ gsize _len = (len); \ @@ -2677,8 +2705,8 @@ typedef enum { { \ GVariantIter __connection_iter, *__setting_iter; \ GVariantBuilder __connection_builder, __setting_builder; \ - const char * __cur_setting_name, *__cur_property_name; \ - GVariant * __property_val; \ + const char *__cur_setting_name, *__cur_property_name; \ + GVariant *__property_val; \ NmtstVariantEditorPhase __phase; \ \ g_variant_builder_init(&__connection_builder, NM_VARIANT_TYPE_CONNECTION); \ @@ -2790,7 +2818,7 @@ static inline GVariant * nmtst_variant_from_string(const GVariantType *variant_type, const char *variant_str) { GVariant *variant; - GError * error = NULL; + GError *error = NULL; g_assert(variant_type); g_assert(variant_str); @@ -2805,13 +2833,13 @@ nmtst_variant_from_string(const GVariantType *variant_type, const char *variant_ static inline void nmtst_keyfile_assert_data(GKeyFile *kf, const char *data, gssize data_len) { - nm_auto_unref_keyfile GKeyFile *kf2 = NULL; - gs_free_error GError *error = NULL; - gs_free char * d1 = NULL; - gs_free char * d2 = NULL; - gboolean success; - gsize d1_len; - gsize d2_len; + nm_auto_unref_keyfile GKeyFile *kf2 = NULL; + gs_free_error GError *error = NULL; + gs_free char *d1 = NULL; + gs_free char *d2 = NULL; + gboolean success; + gsize d1_len; + gsize d2_len; g_assert(kf); g_assert(data || data_len == 0); @@ -2843,7 +2871,7 @@ nmtst_keyfile_assert_data(GKeyFile *kf, const char *data, gssize data_len) static inline gssize nmtst_keyfile_get_num_keys(GKeyFile *keyfile, const char *group_name) { - gs_strfreev char **keys = NULL; + gs_strfreev char **keys = NULL; gs_free_error GError *error = NULL; gsize l = 0; @@ -2871,7 +2899,7 @@ nmtst_ip_address_new(int addr_family, const char *str) { NMIPAddr addr; int plen; - GError * error = NULL; + GError *error = NULL; NMIPAddress *a; if (!nm_utils_parse_inaddr_prefix_bin(addr_family, str, &addr_family, &addr, &plen)) diff --git a/src/libnm-glib-aux/nm-uuid.c b/src/libnm-glib-aux/nm-uuid.c index e7f67c70..19b09667 100644 --- a/src/libnm-glib-aux/nm-uuid.c +++ b/src/libnm-glib-aux/nm-uuid.c @@ -45,7 +45,7 @@ gboolean nm_uuid_parse_full(const char *str, NMUuid *out_uuid, gboolean *out_is_normalized) { NMUuid uuid; - guint8 * p; + guint8 *p; int i; gboolean is_normalized = TRUE; @@ -194,8 +194,8 @@ nm_uuid_is_valid_nmlegacy(const char *str) gboolean nm_uuid_is_valid_nm(const char *str, - gboolean * out_normalized, - char * out_normalized_str /* [static 37] */) + gboolean *out_normalized, + char *out_normalized_str /* [static 37] */) { NMUuid uuid; gboolean is_normalized; @@ -310,8 +310,8 @@ nm_uuid_generate_random_str(char buf[static 37]) * Returns: the input @uuid. This function cannot fail. **/ NMUuid * -nm_uuid_generate_from_string(NMUuid * uuid, - const char * s, +nm_uuid_generate_from_string(NMUuid *uuid, + const char *s, gssize slen, NMUuidType uuid_type, const NMUuid *type_args) @@ -382,14 +382,20 @@ nm_uuid_generate_from_string(NMUuid * uuid, * object's #NMSettingConnection:id: property **/ char * -nm_uuid_generate_from_string_str(const char * s, +nm_uuid_generate_from_string_str(const char *s, gssize slen, NMUuidType uuid_type, const NMUuid *type_args) { - NMUuid uuid; + NMUuid uuid; + const NMUuid *u; + + u = nm_uuid_generate_from_string(&uuid, s, slen, uuid_type, type_args); + + if (G_UNLIKELY(!u)) + return nm_assert_unreachable_val(NULL); + nm_assert(u == &uuid); - nm_uuid_generate_from_string(&uuid, s, slen, uuid_type, type_args); return nm_uuid_unparse(&uuid, g_new(char, 37)); } @@ -415,7 +421,7 @@ nm_uuid_generate_from_strings(const char *string1, ...) { nm_auto_str_buf NMStrBuf str = NM_STR_BUF_INIT(NM_UTILS_GET_NEXT_REALLOC_SIZE_104, FALSE); va_list args; - const char * s; + const char *s; nm_str_buf_append_len(&str, string1, strlen(string1) + 1u); diff --git a/src/libnm-glib-aux/nm-uuid.h b/src/libnm-glib-aux/nm-uuid.h index 504ec789..15b03a2d 100644 --- a/src/libnm-glib-aux/nm-uuid.h +++ b/src/libnm-glib-aux/nm-uuid.h @@ -76,8 +76,8 @@ nm_uuid_is_normalized(const char *str) gboolean nm_uuid_is_valid_nmlegacy(const char *str); gboolean nm_uuid_is_valid_nm(const char *str, - gboolean * out_normalized, - char * out_normalized_str /* [static 37] */); + gboolean *out_normalized, + char *out_normalized_str /* [static 37] */); /*****************************************************************************/ @@ -109,13 +109,13 @@ typedef enum { NM_UUID_TYPE_VERSION5 = 5, } NMUuidType; -NMUuid *nm_uuid_generate_from_string(NMUuid * uuid, - const char * s, +NMUuid *nm_uuid_generate_from_string(NMUuid *uuid, + const char *s, gssize slen, NMUuidType uuid_type, const NMUuid *type_args); -char *nm_uuid_generate_from_string_str(const char * s, +char *nm_uuid_generate_from_string_str(const char *s, gssize slen, NMUuidType uuid_type, const NMUuid *type_args); diff --git a/src/libnm-glib-aux/nm-value-type.h b/src/libnm-glib-aux/nm-value-type.h index 0addeec6..d774e120 100644 --- a/src/libnm-glib-aux/nm-value-type.h +++ b/src/libnm-glib-aux/nm-value-type.h @@ -44,7 +44,7 @@ typedef union { /* for convenience, also let the union contain other pointer types. These are * for NM_VALUE_TYPE_UNSPEC. */ - gconstpointer * v_ptr; + gconstpointer *v_ptr; const GPtrArray *v_ptrarray; } NMValueTypUnion; @@ -181,7 +181,7 @@ nm_value_type_copy(NMValueType value_type, gpointer dst, gconstpointer src) static inline void nm_value_type_get_from_variant(NMValueType value_type, gpointer dst, - GVariant * variant, + GVariant *variant, gboolean clone) { switch (value_type) { @@ -230,7 +230,7 @@ nm_value_type_get_from_variant(NMValueType value_type, static inline GVariant * nm_value_type_to_variant(NMValueType value_type, gconstpointer src) { - const char * v_string; + const char *v_string; const GBytes *v_bytes; switch (value_type) { diff --git a/src/libnm-glib-aux/tests/test-json-aux.c b/src/libnm-glib-aux/tests/test-json-aux.c index 5f33f4fe..32462a29 100644 --- a/src/libnm-glib-aux/tests/test-json-aux.c +++ b/src/libnm-glib-aux/tests/test-json-aux.c @@ -13,7 +13,7 @@ static void test_jansson(void) { - const NMJsonVt * vt; + const NMJsonVt *vt; nm_auto_decref_json nm_json_t *js1 = NULL; nm_auto_decref_json nm_json_t *js2 = NULL; diff --git a/src/libnm-glib-aux/tests/test-shared-general.c b/src/libnm-glib-aux/tests/test-shared-general.c index 9674f228..ecba02e0 100644 --- a/src/libnm-glib-aux/tests/test-shared-general.c +++ b/src/libnm-glib-aux/tests/test-shared-general.c @@ -35,7 +35,7 @@ test_nm_static_assert(void) { int v1[NM_STATIC_ASSERT_EXPR_1(1)]; typeof(NM_STATIC_ASSERT_EXPR_1(1)) v_int; - int * p_int; + int *p_int; G_STATIC_ASSERT(sizeof(v1) == sizeof(int)); G_STATIC_ASSERT(NM_STATIC_ASSERT_EXPR_1(1) == 1); @@ -218,7 +218,7 @@ test_nm_strndup_a(void) { gs_free char *dup_free = NULL; - const char * dup; + const char *dup; l = strlen(input) + 1; dup = nm_strndup_a(10, input, l - 1, &dup_free); @@ -231,7 +231,7 @@ test_nm_strndup_a(void) { gs_free char *dup_free = NULL; - const char * dup; + const char *dup; l = nmtst_get_rand_uint32() % 23; dup = nm_strndup_a(10, input, l, &dup_free); @@ -321,10 +321,10 @@ test_unaligned(void) /*****************************************************************************/ static void -_strv_cmp_fuzz_input(const char *const * in, +_strv_cmp_fuzz_input(const char *const *in, gssize l, - const char *** out_strv_free_shallow, - char *** out_strv_free_deep, + const char ***out_strv_free_shallow, + char ***out_strv_free_deep, const char *const **out_s1, const char *const **out_s2) { @@ -402,12 +402,12 @@ test_strv_cmp(void) { \ gssize _l1 = (l1); \ gssize _l2 = (l2); \ - const char *const * _a1; \ - const char *const * _a2; \ - const char *const * _a1x; \ - const char *const * _a2x; \ - char ** _a1_free_deep = NULL; \ - char ** _a2_free_deep = NULL; \ + const char *const *_a1; \ + const char *const *_a2; \ + const char *const *_a1x; \ + const char *const *_a2x; \ + char **_a1_free_deep = NULL; \ + char **_a2_free_deep = NULL; \ gs_free const char **_a1_free_shallow = NULL; \ gs_free const char **_a2_free_shallow = NULL; \ int _c1, _c2; \ @@ -468,8 +468,8 @@ _do_strstrip_avoid_copy(const char *str) gs_free char *str2 = g_strdup(str); gs_free char *str3 = NULL; gs_free char *str4 = NULL; - const char * s3; - const char * s4; + const char *s3; + const char *s4; if (str1) g_strstrip(str1); @@ -528,11 +528,11 @@ test_nm_utils_bin2hexstr(void) gboolean upper_case = nmtst_get_rand_bool(); gboolean hexdigit_pairs_mangled; gsize expected_strlen; - char * str_hex; + char *str_hex; gsize required_len; gboolean outlen_set; gsize outlen; - guint8 * bin2; + guint8 *bin2; guint i, j; nmtst_rand_buf(NULL, buf, len); @@ -647,15 +647,22 @@ static void test_nm_ref_string(void) { nm_auto_ref_string NMRefString *s1 = NULL; - NMRefString * s2; + NMRefString *s2; g_assert(NULL == NM_REF_STRING_UPCAST(NULL)); + g_assert(nm_ref_string_equal_str(NULL, NULL)); + g_assert(!nm_ref_string_equal_str(NULL, "")); + g_assert(!nm_ref_string_equal_str(NULL, "a")); s1 = nm_ref_string_new("hallo"); g_assert(s1); g_assert_cmpstr(s1->str, ==, "hallo"); g_assert_cmpint(s1->len, ==, strlen("hallo")); g_assert(s1 == NM_REF_STRING_UPCAST(s1->str)); + g_assert(nm_ref_string_equal_str(s1, "hallo")); + g_assert(!nm_ref_string_equal_str(s1, "hallox")); + g_assert(!nm_ref_string_equal_str(s1, "hall")); + g_assert(!nm_ref_string_equal_str(s1, NULL)); s2 = nm_ref_string_new("hallo"); g_assert(s2 == s1); @@ -672,6 +679,7 @@ test_nm_ref_string(void) g_assert_cmpint(s2->len, ==, NM_STRLEN(STR_WITH_NUL)); g_assert_cmpint(s2->len, >, strlen(s2->str)); g_assert_cmpmem(s2->str, s2->len, STR_WITH_NUL, NM_STRLEN(STR_WITH_NUL)); + g_assert(!nm_ref_string_equal_str(s2, "hallo")); g_assert(s2->str[s2->len] == '\0'); nm_ref_string_unref(s2); } @@ -909,8 +917,8 @@ test_nm_str_buf(void) guint i_run; for (i_run = 0; TRUE; i_run++) { - nm_auto_str_buf NMStrBuf strbuf = {}; - nm_auto_free_gstring GString *gstr = NULL; + nm_auto_str_buf NMStrBuf strbuf = {}; + nm_auto_free_gstring GString *gstr = NULL; int i, j, k; int c; @@ -1102,7 +1110,7 @@ test_strv_dup_packed(void) for (i_run = 0; i_run < 500; i_run++) { const int strv_len = nmtst_get_rand_word_length(NULL); gs_free const char **strv_cpy = NULL; - const char *const * strv_src; + const char *const *strv_src; int i, j; g_ptr_array_set_size(src, 0); diff --git a/src/libnm-log-core/nm-logging.c b/src/libnm-log-core/nm-logging.c index 6d2c085e..f464ef29 100644 --- a/src/libnm-log-core/nm-logging.c +++ b/src/libnm-log-core/nm-logging.c @@ -257,7 +257,7 @@ match_log_level(const char *level, NMLogLevel *out_level, GError **error) gboolean nm_logging_setup(const char *level, const char *domains, char **bad_domains, GError **error) { - GString * unrecognized = NULL; + GString *unrecognized = NULL; NMLogDomain cur_log_state[_LOGL_N_REAL]; NMLogDomain new_log_state[_LOGL_N_REAL]; NMLogLevel cur_log_level; @@ -266,7 +266,7 @@ nm_logging_setup(const char *level, const char *domains, char **bad_domains, GEr gsize i_d; int i; gboolean had_platform_debug; - gs_free char * domains_free = NULL; + gs_free char *domains_free = NULL; NM_ASSERT_ON_MAIN_THREAD(); @@ -298,8 +298,8 @@ nm_logging_setup(const char *level, const char *domains, char **bad_domains, GEr domains_v = nm_strsplit_set(domains, ", "); for (i_d = 0; domains_v && domains_v[i_d]; i_d++) { - const char * s = domains_v[i_d]; - const char * p; + const char *s = domains_v[i_d]; + const char *p; const LogDesc *diter; NMLogLevel domain_log_level; NMLogDomain bits; @@ -517,7 +517,7 @@ again: static gsize once = 0; const LogDesc *diter; gsize buf_l; - char * buf_p; + char *buf_p; if (!g_once_init_enter(&once)) goto again; @@ -603,12 +603,12 @@ _iovec_set_string(struct iovec *iov, const char *str) #define _iovec_set_string_literal(iov, str) _iovec_set((iov), "" str "", NM_STRLEN(str)) _nm_printf(3, 4) static void _iovec_set_format(struct iovec *iov, - char ** iov_free, - const char * format, + char **iov_free, + const char *format, ...) { va_list ap; - char * str; + char *str; va_start(ap, format); str = g_strdup_vprintf(format, ap); @@ -663,14 +663,14 @@ _nm_log_impl(const char *file, ...) { char msg_stack[400]; - gs_free char * msg_heap = NULL; - const char * msg; + gs_free char *msg_heap = NULL; + const char *msg; GTimeVal tv; int errsv; const NMLogDomain *cur_log_state; NMLogDomain cur_log_state_copy[_LOGL_N_REAL]; Global g_copy; - const Global * g; + const Global *g; if (G_UNLIKELY(mt_require_locking)) { G_LOCK(log); @@ -722,9 +722,9 @@ _nm_log_impl(const char *file, { gint64 now, boottime; struct iovec iov_data[15]; - struct iovec * iov = iov_data; - char * iov_free_data[5]; - char ** iov_free = iov_free_data; + struct iovec *iov = iov_data; + char *iov_free_data[5]; + char **iov_free = iov_free_data; const LogDesc *diter; NMLogDomain dom_all; char s_log_domains_buf[NM_STRLEN("NM_LOG_DOMAINS=") + sizeof(_all_logging_domains_to_str)]; diff --git a/src/libnm-platform/meson.build b/src/libnm-platform/meson.build index 3e4f41a9..d0a7c6c2 100644 --- a/src/libnm-platform/meson.build +++ b/src/libnm-platform/meson.build @@ -9,7 +9,7 @@ libnm_platform = static_library( 'nm-platform.c', 'nmp-netns.c', 'nmp-object.c', - 'nmp-rules-manager.c', + 'nmp-route-manager.c', 'wifi/nm-wifi-utils-nl80211.c', 'wifi/nm-wifi-utils.c', 'wpan/nm-wpan-utils.c', diff --git a/src/libnm-platform/nm-linux-platform.c b/src/libnm-platform/nm-linux-platform.c index 78df53e7..93935b98 100644 --- a/src/libnm-platform/nm-linux-platform.c +++ b/src/libnm-platform/nm-linux-platform.c @@ -402,11 +402,11 @@ typedef struct { guint32 seq_number; WaitForNlResponseResult seq_result; DelayedActionWaitForNlResponseType response_type; - gint64 timeout_abs_ns; - WaitForNlResponseResult * out_seq_result; - char ** out_errmsg; + gint64 timeout_abs_nsec; + WaitForNlResponseResult *out_seq_result; + char **out_errmsg; union { - int * out_refresh_all_in_progress; + int *out_refresh_all_in_progress; NMPObject **out_route_get; gpointer out_data; } response; @@ -446,11 +446,22 @@ typedef struct { GPtrArray *list_master_connected; GPtrArray *list_refresh_link; - GArray * list_wait_for_nl_response; + GArray *list_wait_for_nl_response; int is_handling; } delayed_action; + /* This is the receive buffer for netlink messages. This buffer should be large + * enough for any rtnetlink message. When too small, nl_recv() would notice the + * truncation and lose the message. In that case, we reallocate a larger buffer. + * + * We keep the receive buffer around for the entire lifetime of the platform instance. + * Usually we only have one platform instance per netns, so we don't waste too much. */ + struct { + unsigned char *buf; + gsize len; + } netlink_recv_buf; + } NMLinuxPlatformPrivate; struct _NMLinuxPlatform { @@ -493,7 +504,7 @@ NM_LINUX_PLATFORM_FROM_PRIVATE(NMLinuxPlatformPrivate *priv) G_STMT_START \ { \ 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)) { \ @@ -554,7 +565,7 @@ delayed_action_schedule(NMPlatform *platform, DelayedActionType action_type, gpo static gboolean delayed_action_handle_all(NMPlatform *platform, gboolean read_netlink); static void do_request_link_no_delayed_actions(NMPlatform *platform, int ifindex, const char *name); static void do_request_all_no_delayed_actions(NMPlatform *platform, DelayedActionType action_type); -static void cache_on_change(NMPlatform * platform, +static void cache_on_change(NMPlatform *platform, NMPCacheOpsType cache_op, const NMPObject *obj_old, const NMPObject *obj_new); @@ -576,8 +587,8 @@ wait_for_nl_response_to_nmerr(WaitForNlResponseResult seq_result) static const char * wait_for_nl_response_to_string(WaitForNlResponseResult seq_result, - const char * errmsg, - char * buf, + const char *errmsg, + char *buf, gsize buf_size) { char *buf0 = buf; @@ -993,9 +1004,9 @@ _addrtime_get_lifetimes(guint32 timestamp, /*****************************************************************************/ static const NMPObject * -_lookup_cached_link(const NMPCache * cache, +_lookup_cached_link(const NMPCache *cache, int ifindex, - gboolean * completed_from_cache, + gboolean *completed_from_cache, const NMPObject **link_cached) { const NMPObject *obj; @@ -1019,7 +1030,7 @@ static char * _linktype_read_devtype(int dirfd) { gs_free char *contents = NULL; - char * cont, *end; + char *cont, *end; nm_assert(dirfd >= 0); @@ -1046,16 +1057,16 @@ _linktype_read_devtype(int dirfd) } static NMLinkType -_linktype_get_type(NMPlatform * platform, - const NMPCache * cache, - const char * kind, +_linktype_get_type(NMPlatform *platform, + const NMPCache *cache, + const char *kind, int ifindex, - const char * ifname, + const char *ifname, unsigned flags, unsigned arptype, - gboolean * completed_from_cache, + gboolean *completed_from_cache, const NMPObject **link_cached, - const char ** out_kind) + const char **out_kind) { NMLinkType link_type; @@ -1138,7 +1149,7 @@ _linktype_get_type(NMPlatform * platform, { nm_auto_close int dirfd = -1; - gs_free char * devtype = NULL; + gs_free char *devtype = NULL; char ifname_verified[IFNAMSIZ]; dirfd = nmp_utils_sysctl_open_netdir(ifindex, ifname, ifname_verified); @@ -1242,12 +1253,12 @@ _nl_addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data, int al /* Copied and heavily modified from libnl3's inet6_parse_protinfo(). */ static gboolean -_parse_af_inet6(NMPlatform * platform, - struct nlattr * attr, +_parse_af_inet6(NMPlatform *platform, + struct nlattr *attr, NMUtilsIPv6IfaceId *out_token, - gboolean * out_token_valid, - guint8 * out_addr_gen_mode_inv, - gboolean * out_addr_gen_mode_valid) + gboolean *out_token_valid, + guint8 *out_addr_gen_mode_inv, + gboolean *out_addr_gen_mode_valid) { static const struct nla_policy policy[] = { [IFLA_INET6_FLAGS] = {.type = NLA_U32}, @@ -1258,7 +1269,7 @@ _parse_af_inet6(NMPlatform * platform, [IFLA_INET6_TOKEN] = {.minlen = sizeof(struct in6_addr)}, [IFLA_INET6_ADDR_GEN_MODE] = {.type = NLA_U8}, }; - struct nlattr * tb[G_N_ELEMENTS(policy)]; + struct nlattr *tb[G_N_ELEMENTS(policy)]; struct in6_addr i6_token; gboolean token_valid = FALSE; gboolean addr_gen_mode_valid = FALSE; @@ -1331,8 +1342,8 @@ _parse_lnk_bridge(const char *kind, struct nlattr *info_data) [IFLA_BR_MCAST_STARTUP_QUERY_INTVL] = {.type = NLA_U64}, }; NMPlatformLnkBridge *props; - struct nlattr * tb[G_N_ELEMENTS(policy)]; - NMPObject * obj; + struct nlattr *tb[G_N_ELEMENTS(policy)]; + NMPObject *obj; if (!info_data || !nm_streq0(kind, "bridge")) return NULL; @@ -1420,8 +1431,8 @@ _parse_lnk_gre(const char *kind, struct nlattr *info_data) [IFLA_GRE_TOS] = {.type = NLA_U8}, [IFLA_GRE_PMTUDISC] = {.type = NLA_U8}, }; - struct nlattr * tb[G_N_ELEMENTS(policy)]; - NMPObject * obj; + struct nlattr *tb[G_N_ELEMENTS(policy)]; + NMPObject *obj; NMPlatformLnkGre *props; gboolean is_tap; @@ -1480,10 +1491,10 @@ _parse_lnk_infiniband(const char *kind, struct nlattr *info_data) [IFLA_IPOIB_MODE] = {.type = NLA_U16}, [IFLA_IPOIB_UMCAST] = {.type = NLA_U16}, }; - struct nlattr * tb[G_N_ELEMENTS(policy)]; + struct nlattr *tb[G_N_ELEMENTS(policy)]; NMPlatformLnkInfiniband *info; - NMPObject * obj; - const char * mode; + NMPObject *obj; + const char *mode; if (!info_data || !nm_streq0(kind, "ipoib")) return NULL; @@ -1529,8 +1540,8 @@ _parse_lnk_ip6tnl(const char *kind, struct nlattr *info_data) [IFLA_IPTUN_PROTO] = {.type = NLA_U8}, [IFLA_IPTUN_FLAGS] = {.type = NLA_U32}, }; - struct nlattr * tb[G_N_ELEMENTS(policy)]; - NMPObject * obj; + struct nlattr *tb[G_N_ELEMENTS(policy)]; + NMPObject *obj; NMPlatformLnkIp6Tnl *props; guint32 flowinfo; @@ -1582,8 +1593,8 @@ _parse_lnk_ip6gre(const char *kind, struct nlattr *info_data) [IFLA_GRE_FLOWINFO] = {.type = NLA_U32}, [IFLA_GRE_FLAGS] = {.type = NLA_U32}, }; - struct nlattr * tb[G_N_ELEMENTS(policy)]; - NMPObject * obj; + struct nlattr *tb[G_N_ELEMENTS(policy)]; + NMPObject *obj; NMPlatformLnkIp6Tnl *props; guint32 flowinfo; gboolean is_tap; @@ -1648,8 +1659,8 @@ _parse_lnk_ipip(const char *kind, struct nlattr *info_data) [IFLA_IPTUN_TOS] = {.type = NLA_U8}, [IFLA_IPTUN_PMTUDISC] = {.type = NLA_U8}, }; - struct nlattr * tb[G_N_ELEMENTS(policy)]; - NMPObject * obj; + struct nlattr *tb[G_N_ELEMENTS(policy)]; + NMPObject *obj; NMPlatformLnkIpIp *props; if (!info_data || !nm_streq0(kind, "ipip")) @@ -1681,8 +1692,8 @@ _parse_lnk_macvlan(const char *kind, struct nlattr *info_data) [IFLA_MACVLAN_FLAGS] = {.type = NLA_U16}, }; NMPlatformLnkMacvlan *props; - struct nlattr * tb[G_N_ELEMENTS(policy)]; - NMPObject * obj; + struct nlattr *tb[G_N_ELEMENTS(policy)]; + NMPObject *obj; gboolean tap; if (!info_data || !kind) @@ -1732,8 +1743,8 @@ _parse_lnk_macsec(const char *kind, struct nlattr *info_data) [IFLA_MACSEC_REPLAY_PROTECT] = {.type = NLA_U8}, [IFLA_MACSEC_VALIDATION] = {.type = NLA_U8}, }; - struct nlattr * tb[G_N_ELEMENTS(policy)]; - NMPObject * obj; + struct nlattr *tb[G_N_ELEMENTS(policy)]; + NMPObject *obj; NMPlatformLnkMacsec *props; if (!info_data || !nm_streq0(kind, "macsec")) @@ -1800,8 +1811,8 @@ _parse_lnk_sit(const char *kind, struct nlattr *info_data) [IFLA_IPTUN_FLAGS] = {.type = NLA_U16}, [IFLA_IPTUN_PROTO] = {.type = NLA_U8}, }; - struct nlattr * tb[G_N_ELEMENTS(policy)]; - NMPObject * obj; + struct nlattr *tb[G_N_ELEMENTS(policy)]; + NMPObject *obj; NMPlatformLnkSit *props; if (!info_data || !nm_streq0(kind, "sit")) @@ -1841,8 +1852,8 @@ _parse_lnk_tun(const char *kind, struct nlattr *info_data) [IFLA_TUN_NUM_QUEUES] = {.type = NLA_U32}, [IFLA_TUN_NUM_DISABLED_QUEUES] = {.type = NLA_U32}, }; - struct nlattr * tb[G_N_ELEMENTS(policy)]; - NMPObject * obj; + struct nlattr *tb[G_N_ELEMENTS(policy)]; + NMPObject *obj; NMPlatformLnkTun *props; if (!info_data || !nm_streq0(kind, "tun")) @@ -1878,12 +1889,12 @@ _parse_lnk_tun(const char *kind, struct nlattr *info_data) /*****************************************************************************/ static gboolean -_vlan_qos_mapping_from_nla(struct nlattr * nlattr, +_vlan_qos_mapping_from_nla(struct nlattr *nlattr, const NMVlanQosMapping **out_map, - guint * out_n_map) + guint *out_n_map) { - struct nlattr * nla; - int remaining; + struct nlattr *nla; + int remaining; gs_unref_ptrarray GPtrArray *array = NULL; G_STATIC_ASSERT(sizeof(NMVlanQosMapping) == sizeof(struct ifla_vlan_qos_mapping)); @@ -1950,9 +1961,9 @@ _parse_lnk_vlan(const char *kind, struct nlattr *info_data) [IFLA_VLAN_EGRESS_QOS] = {.type = NLA_NESTED}, [IFLA_VLAN_PROTOCOL] = {.type = NLA_U16}, }; - struct nlattr *tb[G_N_ELEMENTS(policy)]; + struct nlattr *tb[G_N_ELEMENTS(policy)]; nm_auto_nmpobj NMPObject *obj = NULL; - NMPObject * obj_result; + NMPObject *obj_result; if (!info_data || !nm_streq0(kind, "vlan")) return NULL; @@ -2050,8 +2061,8 @@ _parse_lnk_vxlan(const char *kind, struct nlattr *info_data) [IFLA_VXLAN_PORT] = {.type = NLA_U16}, }; NMPlatformLnkVxlan *props; - struct nlattr * tb[G_N_ELEMENTS(policy)]; - NMPObject * obj; + struct nlattr *tb[G_N_ELEMENTS(policy)]; + NMPObject *obj; if (!info_data || !nm_streq0(kind, "vxlan")) return NULL; @@ -2117,8 +2128,8 @@ _parse_lnk_vrf(const char *kind, struct nlattr *info_data) [IFLA_VRF_TABLE] = {.type = NLA_U32}, }; NMPlatformLnkVrf *props; - struct nlattr * tb[G_N_ELEMENTS(policy)]; - NMPObject * obj; + struct nlattr *tb[G_N_ELEMENTS(policy)]; + NMPObject *obj; if (!info_data || !nm_streq0(kind, "vrf")) return NULL; @@ -2199,7 +2210,7 @@ _wireguard_update_from_peers_nla(CList *peers, GArray **p_allowed_ips, struct nl [WGPEER_A_TX_BYTES] = {.type = NLA_U64}, [WGPEER_A_ALLOWEDIPS] = {.type = NLA_NESTED}, }; - struct nlattr * tb[G_N_ELEMENTS(policy)]; + struct nlattr *tb[G_N_ELEMENTS(policy)]; WireGuardPeerConstruct *peer_c; if (nla_parse_nested_arr(tb, peer_attr, policy) < 0) @@ -2259,7 +2270,7 @@ _wireguard_update_from_peers_nla(CList *peers, GArray **p_allowed_ips, struct nl if (tb[WGPEER_A_ALLOWEDIPS]) { struct nlattr *attr; int rem; - GArray * allowed_ips = *p_allowed_ips; + GArray *allowed_ips = *p_allowed_ips; nla_for_each_nested (attr, tb[WGPEER_A_ALLOWEDIPS], rem) { if (!allowed_ips) { @@ -2290,7 +2301,7 @@ typedef struct { const int ifindex; NMPObject *obj; CList peers; - GArray * allowed_ips; + GArray *allowed_ips; } WireGuardParseData; static int @@ -2306,7 +2317,7 @@ _wireguard_get_device_cb(struct nl_msg *msg, void *arg) [WGDEVICE_A_FWMARK] = {.type = NLA_U32}, [WGDEVICE_A_PEERS] = {.type = NLA_NESTED}, }; - struct nlattr * tb[G_N_ELEMENTS(policy)]; + struct nlattr *tb[G_N_ELEMENTS(policy)]; WireGuardParseData *parse_data = arg; if (genlmsg_parse_arr(nlmsg_hdr(msg), 0, tb, policy) < 0) @@ -2327,7 +2338,7 @@ _wireguard_get_device_cb(struct nl_msg *msg, void *arg) /* we already have an object instance. This means the netlink message * is a continuation, only providing more WGDEVICE_A_PEERS data below. */ } else { - NMPObject * obj; + NMPObject *obj; NMPlatformLnkWireGuard *props; obj = nmp_object_new(NMP_OBJECT_TYPE_LNK_WIREGUARD, NULL); @@ -2370,18 +2381,18 @@ _wireguard_get_device_cb(struct nl_msg *msg, void *arg) } static const NMPObject * -_wireguard_read_info(NMPlatform * platform /* used only as logging context */, +_wireguard_read_info(NMPlatform *platform /* used only as logging context */, struct nl_sock *genl, int wireguard_family_id, int ifindex) { nm_auto_nlmsg struct nl_msg *msg = NULL; - NMPObject * obj = NULL; - WireGuardPeerConstruct * peer_c; - WireGuardPeerConstruct * peer_c_safe; - gs_unref_array GArray *allowed_ips = NULL; - WireGuardParseData parse_data = { - .ifindex = ifindex, + NMPObject *obj = NULL; + WireGuardPeerConstruct *peer_c; + WireGuardPeerConstruct *peer_c_safe; + gs_unref_array GArray *allowed_ips = NULL; + WireGuardParseData parse_data = { + .ifindex = ifindex, }; guint i; @@ -2522,13 +2533,13 @@ _wireguard_get_family_id(NMPlatform *platform, int ifindex_try) static const NMPObject * _wireguard_refresh_link(NMPlatform *platform, int wireguard_family_id, int ifindex) { - NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE(platform); + NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE(platform); nm_auto_nmpobj const NMPObject *obj_old = NULL; nm_auto_nmpobj const NMPObject *obj_new = NULL; nm_auto_nmpobj const NMPObject *lnk_new = NULL; NMPCacheOpsType cache_op; - const NMPObject * plink = NULL; - nm_auto_nmpobj NMPObject *obj = NULL; + const NMPObject *plink = NULL; + nm_auto_nmpobj NMPObject *obj = NULL; nm_assert(wireguard_family_id >= 0); nm_assert(ifindex > 0); @@ -2587,25 +2598,25 @@ _wireguard_refresh_link(NMPlatform *platform, int wireguard_family_id, int ifind } static int -_wireguard_create_change_nlmsgs(NMPlatform * platform, +_wireguard_create_change_nlmsgs(NMPlatform *platform, int ifindex, int wireguard_family_id, - const NMPlatformLnkWireGuard * lnk_wireguard, - const NMPWireGuardPeer * peers, + const NMPlatformLnkWireGuard *lnk_wireguard, + const NMPWireGuardPeer *peers, const NMPlatformWireGuardChangePeerFlags *peer_flags, guint peers_len, NMPlatformWireGuardChangeFlags change_flags, - GPtrArray ** out_msgs) + GPtrArray **out_msgs) { - gs_unref_ptrarray GPtrArray * msgs = NULL; - nm_auto_nlmsg struct nl_msg * msg = NULL; + gs_unref_ptrarray GPtrArray *msgs = NULL; + nm_auto_nlmsg struct nl_msg *msg = NULL; const guint IDX_NIL = G_MAXUINT; guint idx_peer_curr; guint idx_allowed_ips_curr; - struct nlattr * nest_peers; - struct nlattr * nest_curr_peer; - struct nlattr * nest_allowed_ips; - struct nlattr * nest_curr_allowed_ip; + struct nlattr *nest_peers; + struct nlattr *nest_curr_peer; + struct nlattr *nest_allowed_ips; + struct nlattr *nest_curr_allowed_ip; NMPlatformWireGuardChangePeerFlags p_flags = NM_PLATFORM_WIREGUARD_CHANGE_PEER_FLAG_DEFAULT; #define _nla_nest_end(msg, nest_start) \ @@ -2821,15 +2832,15 @@ nla_put_failure: } static int -link_wireguard_change(NMPlatform * platform, +link_wireguard_change(NMPlatform *platform, int ifindex, - const NMPlatformLnkWireGuard * lnk_wireguard, - const NMPWireGuardPeer * peers, + const NMPlatformLnkWireGuard *lnk_wireguard, + const NMPWireGuardPeer *peers, const NMPlatformWireGuardChangePeerFlags *peer_flags, guint peers_len, NMPlatformWireGuardChangeFlags change_flags) { - NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE(platform); + NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE(platform); gs_unref_ptrarray GPtrArray *msgs = NULL; int wireguard_family_id; guint i; @@ -2897,8 +2908,8 @@ _nmp_link_address_set(NMPLinkAddress *dst, const struct nlattr *nla) /* Copied and heavily modified from libnl3's link_msg_parser(). */ static NMPObject * -_new_from_nl_link(NMPlatform * platform, - const NMPCache * cache, +_new_from_nl_link(NMPlatform *platform, + const NMPCache *cache, struct nlmsghdr *nlh, gboolean id_only) { @@ -2930,15 +2941,15 @@ _new_from_nl_link(NMPlatform * platform, [IFLA_LINK_NETNSID] = {}, [IFLA_PERM_ADDRESS] = {.type = NLA_UNSPEC}, }; - const struct ifinfomsg *ifi; - struct nlattr * tb[G_N_ELEMENTS(policy)]; - struct nlattr * nl_info_data = NULL; - const char * nl_info_kind = NULL; + const struct ifinfomsg *ifi; + struct nlattr *tb[G_N_ELEMENTS(policy)]; + struct nlattr *nl_info_data = NULL; + const char *nl_info_kind = NULL; nm_auto_nmpobj NMPObject *obj = NULL; gboolean completed_from_cache_val = FALSE; - gboolean * completed_from_cache = cache ? &completed_from_cache_val : NULL; - const NMPObject * link_cached = NULL; - const NMPObject * lnk_data = NULL; + gboolean *completed_from_cache = cache ? &completed_from_cache_val : NULL; + const NMPObject *link_cached = NULL; + const NMPObject *lnk_data = NULL; gboolean address_complete_from_cache = TRUE; gboolean perm_address_complete_from_cache = TRUE; gboolean broadcast_complete_from_cache = TRUE; @@ -3210,7 +3221,7 @@ _new_from_nl_link(NMPlatform * platform, if (obj->link.type == NM_LINK_TYPE_WIREGUARD) { const NMPObject *lnk_data_new = NULL; - struct nl_sock * genl = NM_LINUX_PLATFORM_GET_PRIVATE(platform)->genl; + struct nl_sock *genl = NM_LINUX_PLATFORM_GET_PRIVATE(platform)->genl; /* The WireGuard kernel module does not yet send link update * notifications, so we don't actually update the cache. For @@ -3255,9 +3266,9 @@ _new_from_nl_addr(struct nlmsghdr *nlh, gboolean id_only) [IFA_CACHEINFO] = {.minlen = nm_offsetofend(struct ifa_cacheinfo, tstamp)}, [IFA_FLAGS] = {}, }; - struct nlattr * tb[G_N_ELEMENTS(policy)]; - const struct ifaddrmsg *ifa; - gboolean is_v4; + struct nlattr *tb[G_N_ELEMENTS(policy)]; + const struct ifaddrmsg *ifa; + gboolean IS_IPv4; nm_auto_nmpobj NMPObject *obj = NULL; int addr_len; guint32 lifetime, preferred, timestamp; @@ -3267,29 +3278,31 @@ _new_from_nl_addr(struct nlmsghdr *nlh, gboolean id_only) ifa = nlmsg_data(nlh); - if (!NM_IN_SET(ifa->ifa_family, AF_INET, AF_INET6)) + if (ifa->ifa_family == AF_INET) + IS_IPv4 = TRUE; + else if (ifa->ifa_family == AF_INET6) + IS_IPv4 = FALSE; + else return NULL; - is_v4 = ifa->ifa_family == AF_INET; - if (nlmsg_parse_arr(nlh, sizeof(*ifa), tb, policy) < 0) return NULL; - addr_len = is_v4 ? sizeof(in_addr_t) : sizeof(struct in6_addr); + addr_len = IS_IPv4 ? sizeof(in_addr_t) : sizeof(struct in6_addr); - if (ifa->ifa_prefixlen > (is_v4 ? 32 : 128)) + if (ifa->ifa_prefixlen > (IS_IPv4 ? 32 : 128)) return NULL; /*****************************************************************/ - obj = nmp_object_new(is_v4 ? NMP_OBJECT_TYPE_IP4_ADDRESS : NMP_OBJECT_TYPE_IP6_ADDRESS, NULL); + obj = nmp_object_new(IS_IPv4 ? NMP_OBJECT_TYPE_IP4_ADDRESS : NMP_OBJECT_TYPE_IP6_ADDRESS, NULL); obj->ip_address.ifindex = ifa->ifa_index; obj->ip_address.plen = ifa->ifa_prefixlen; _check_addr_or_return_null(tb, IFA_ADDRESS, addr_len); _check_addr_or_return_null(tb, IFA_LOCAL, addr_len); - if (is_v4) { + if (IS_IPv4) { /* For IPv4, kernel omits IFA_LOCAL/IFA_ADDRESS if (and only if) they * are effectively 0.0.0.0 (all-zero). */ if (tb[IFA_LOCAL]) @@ -3325,7 +3338,7 @@ _new_from_nl_addr(struct nlmsghdr *nlh, gboolean id_only) obj->ip_address.n_ifa_flags = tb[IFA_FLAGS] ? nla_get_u32(tb[IFA_FLAGS]) : ifa->ifa_flags; - if (is_v4) { + if (IS_IPv4) { if (tb[IFA_LABEL]) { char label[IFNAMSIZ]; @@ -3374,9 +3387,9 @@ _new_from_nl_route(struct nlmsghdr *nlh, gboolean id_only) [RTA_METRICS] = {.type = NLA_NESTED}, [RTA_MULTIPATH] = {.type = NLA_NESTED}, }; - const struct rtmsg *rtm; - struct nlattr * tb[G_N_ELEMENTS(policy)]; - gboolean is_v4; + const struct rtmsg *rtm; + struct nlattr *tb[G_N_ELEMENTS(policy)]; + gboolean IS_IPv4; nm_auto_nmpobj NMPObject *obj = NULL; int addr_len; struct { @@ -3403,10 +3416,19 @@ _new_from_nl_route(struct nlmsghdr *nlh, gboolean id_only) * only handle ~supported~ routes. *****************************************************************/ - if (!NM_IN_SET(rtm->rtm_family, AF_INET, AF_INET6)) + if (rtm->rtm_family == AF_INET) + IS_IPv4 = TRUE; + else if (rtm->rtm_family == AF_INET6) + IS_IPv4 = FALSE; + else return NULL; - if (!NM_IN_SET(rtm->rtm_type, RTN_UNICAST, RTN_LOCAL)) + if (!NM_IN_SET(rtm->rtm_type, + RTN_UNICAST, + RTN_LOCAL, + RTN_BLACKHOLE, + RTN_UNREACHABLE, + RTN_PROHIBIT)) return NULL; if (nlmsg_parse_arr(nlh, sizeof(struct rtmsg), tb, policy) < 0) @@ -3414,10 +3436,9 @@ _new_from_nl_route(struct nlmsghdr *nlh, gboolean id_only) /*****************************************************************/ - is_v4 = rtm->rtm_family == AF_INET; - addr_len = is_v4 ? sizeof(in_addr_t) : sizeof(struct in6_addr); + addr_len = IS_IPv4 ? sizeof(in_addr_t) : sizeof(struct in6_addr); - if (rtm->rtm_dst_len > (is_v4 ? 32 : 128)) + if (rtm->rtm_dst_len > (IS_IPv4 ? 32 : 128)) return NULL; /***************************************************************** @@ -3481,16 +3502,45 @@ rta_multipath_done:; /* If no nexthops have been provided via RTA_MULTIPATH * we add it as regular nexthop to maintain backwards * compatibility */ - nh.ifindex = ifindex; - nh.gateway = gateway; + nh.ifindex = ifindex; + nh.gateway = gateway; + nh.is_present = TRUE; } else { /* Kernel supports new style nexthop configuration, * verify that it is a duplicate and ignore old-style nexthop. */ if (nh.ifindex != ifindex || memcmp(&nh.gateway, &gateway, addr_len) != 0) return NULL; } - } else if (!nh.is_present) - return NULL; + } + + if (nm_platform_route_type_is_nodev(rtm->rtm_type)) { + /* These routes are special. They don't have an device/ifindex. + * + * Well, actually, for IPv6 kernel will always say that the device is + * 1 (lo). Of course it does!! */ + if (nh.is_present) { + if (IS_IPv4) { + if (nh.ifindex != 0 || nh.gateway.addr4 != 0) { + /* we only accept kernel to notify about the ifindex/gateway, if it + * is zero. This is only to be a bit forgiving, but we really don't + * know how to handle such routes that have an ifindex. */ + return NULL; + } + } else { + if (!NM_IN_SET(nh.ifindex, 0, 1) || !IN6_IS_ADDR_UNSPECIFIED(&nh.gateway.addr6)) { + /* We allow an ifindex of 1 (will be normalized to zero). Otherwise, + * we don't expect a device/next hop. */ + return NULL; + } + nh.ifindex = 0; + } + } + } else { + if (!nh.is_present) { + /* a "normal" route needs a device. This is not the route we are looking for. */ + return NULL; + } + } /*****************************************************************/ @@ -3528,9 +3578,8 @@ rta_multipath_done:; /*****************************************************************/ - obj = nmp_object_new(is_v4 ? NMP_OBJECT_TYPE_IP4_ROUTE : NMP_OBJECT_TYPE_IP6_ROUTE, NULL); + obj = nmp_object_new(IS_IPv4 ? NMP_OBJECT_TYPE_IP4_ROUTE : NMP_OBJECT_TYPE_IP6_ROUTE, NULL); - obj->ip_route.is_external = TRUE; obj->ip_route.type_coerced = nm_platform_route_type_coerce(rtm->rtm_type); obj->ip_route.table_coerced = nm_platform_route_table_coerce( tb[RTA_TABLE] ? nla_get_u32(tb[RTA_TABLE]) : (guint32) rtm->rtm_table); @@ -3545,22 +3594,22 @@ rta_multipath_done:; if (tb[RTA_PRIORITY]) obj->ip_route.metric = nla_get_u32(tb[RTA_PRIORITY]); - if (is_v4) + if (IS_IPv4) obj->ip4_route.gateway = nh.gateway.addr4; else obj->ip6_route.gateway = nh.gateway.addr6; - if (is_v4) + if (IS_IPv4) obj->ip4_route.scope_inv = nm_platform_route_scope_inv(rtm->rtm_scope); if (_check_addr_or_return_null(tb, RTA_PREFSRC, addr_len)) { - if (is_v4) + if (IS_IPv4) memcpy(&obj->ip4_route.pref_src, nla_data(tb[RTA_PREFSRC]), addr_len); else memcpy(&obj->ip6_route.pref_src, nla_data(tb[RTA_PREFSRC]), addr_len); } - if (is_v4) + if (IS_IPv4) obj->ip4_route.tos = rtm->rtm_tos; else { if (tb[RTA_SRC]) { @@ -3582,7 +3631,7 @@ rta_multipath_done:; obj->ip_route.lock_initrwnd = NM_FLAGS_HAS(lock, 1 << RTAX_INITRWND); obj->ip_route.lock_mtu = NM_FLAGS_HAS(lock, 1 << RTAX_MTU); - if (!is_v4) { + if (!IS_IPv4) { if (tb[RTA_PREF]) obj->ip6_route.rt_pref = nla_get_u8(tb[RTA_PREF]); } @@ -3682,12 +3731,12 @@ _new_from_nl_routing_rule(struct nlmsghdr *nlh, gboolean id_only) .maxlen = sizeof(NMFibRulePortRange), }, }; - struct nlattr * tb[G_N_ELEMENTS(policy)]; + struct nlattr *tb[G_N_ELEMENTS(policy)]; const struct fib_rule_hdr *frh; - NMPlatformRoutingRule * props; - nm_auto_nmpobj NMPObject *obj = NULL; - int addr_family; - guint8 addr_size; + NMPlatformRoutingRule *props; + nm_auto_nmpobj NMPObject *obj = NULL; + int addr_family; + guint8 addr_size; if (nlmsg_parse_arr(nlh, sizeof(*frh), tb, policy) < 0) return NULL; @@ -3876,8 +3925,8 @@ _new_from_nl_qdisc(NMPlatform *platform, struct nlmsghdr *nlh, gboolean id_only) [TCA_KIND] = {.type = NLA_STRING}, [TCA_OPTIONS] = {.type = NLA_NESTED}, }; - struct nlattr * tb[G_N_ELEMENTS(policy)]; - const struct tcmsg *tcm; + struct nlattr *tb[G_N_ELEMENTS(policy)]; + const struct tcmsg *tcm; nm_auto_nmpobj NMPObject *obj = NULL; if (!nm_platform_get_cache_tc(platform)) @@ -3926,7 +3975,7 @@ _new_from_nl_qdisc(NMPlatform *platform, struct nlmsghdr *nlh, gboolean id_only) [TCA_TBF_PARMS] = {.minlen = sizeof(struct tc_tbf_qopt)}, [TCA_TBF_RATE64] = {.type = NLA_U64}, }; - struct nlattr * tbf_tb[G_N_ELEMENTS(tbf_policy)]; + struct nlattr *tbf_tb[G_N_ELEMENTS(tbf_policy)]; struct tc_tbf_qopt opt; if (nla_parse_nested_arr(tbf_tb, tb[TCA_OPTIONS], tbf_policy) < 0) @@ -3988,8 +4037,8 @@ _new_from_nl_tfilter(NMPlatform *platform, struct nlmsghdr *nlh, gboolean id_onl static const struct nla_policy policy[] = { [TCA_KIND] = {.type = NLA_STRING}, }; - struct nlattr * tb[G_N_ELEMENTS(policy)]; - NMPObject * obj = NULL; + struct nlattr *tb[G_N_ELEMENTS(policy)]; + NMPObject *obj = NULL; const struct tcmsg *tcm; if (!nm_platform_get_cache_tc(platform)) @@ -4028,9 +4077,9 @@ _new_from_nl_tfilter(NMPlatform *platform, struct nlmsghdr *nlh, gboolean id_onl * Returns: %NULL or a newly created NMPObject instance. **/ static NMPObject * -nmp_object_new_from_nl(NMPlatform * platform, +nmp_object_new_from_nl(NMPlatform *platform, const NMPCache *cache, - struct nl_msg * msg, + struct nl_msg *msg, gboolean id_only) { struct nlmsghdr *msghdr; @@ -4113,7 +4162,7 @@ _nl_msg_new_link_set_linkinfo(struct nl_msg *msg, NMLinkType link_type, gconstpo { struct nlattr *info; struct nlattr *data = NULL; - const char * kind; + const char *kind; nm_assert(msg); @@ -4242,9 +4291,9 @@ _nl_msg_new_link_set_linkinfo(struct nl_msg *msg, NMLinkType link_type, gconstpo } case NM_LINK_TYPE_VETH: { - const char * veth_peer = extra_data; + const char *veth_peer = extra_data; const struct ifinfomsg ifi = {}; - struct nlattr * info_peer; + struct nlattr *info_peer; nm_assert(veth_peer); @@ -4438,7 +4487,7 @@ nla_put_failure: } static gboolean -_nl_msg_new_link_set_linkinfo_vlan(struct nl_msg * msg, +_nl_msg_new_link_set_linkinfo_vlan(struct nl_msg *msg, int vlan_id, guint32 flags_mask, guint32 flags_set, @@ -4559,10 +4608,10 @@ _nl_msg_new_link_full(int nlmsg_type, { nm_auto_nlmsg struct nl_msg *msg = NULL; const struct ifinfomsg ifi = { - .ifi_family = family, - .ifi_change = flags_mask, - .ifi_flags = flags_set, - .ifi_index = ifindex, + .ifi_family = family, + .ifi_change = flags_mask, + .ifi_flags = flags_set, + .ifi_index = ifindex, }; nm_assert(NM_IN_SET(nlmsg_type, RTM_DELLINK, RTM_NEWLINK, RTM_GETLINK, RTM_SETLINK)); @@ -4601,14 +4650,14 @@ _nl_msg_new_address(int nlmsg_type, guint32 lifetime, guint32 preferred, in_addr_t ip4_broadcast_address, - const char * label) + const char *label) { nm_auto_nlmsg struct nl_msg *msg = NULL; struct ifaddrmsg am = { - .ifa_family = family, - .ifa_index = ifindex, - .ifa_prefixlen = plen, - .ifa_flags = flags, + .ifa_family = family, + .ifa_index = ifindex, + .ifa_prefixlen = plen, + .ifa_flags = flags, }; gsize addr_len; @@ -4680,27 +4729,48 @@ ip_route_get_lock_flag(const NMPlatformIPRoute *route) | (((guint32) route->lock_mtu) << RTAX_MTU); } +static gboolean +ip_route_ignored_protocol(const NMPlatformIPRoute *route) +{ + guint8 prot; + + nm_assert(route); + nm_assert(route->rt_source >= NM_IP_CONFIG_SOURCE_RTPROT_UNSPEC + && route->rt_source <= _NM_IP_CONFIG_SOURCE_RTPROT_LAST); + + prot = route->rt_source - 1; + + nm_assert(nmp_utils_ip_config_source_from_rtprot(prot) == route->rt_source); + + /* We ignore all routes outside a certain subest of rtm_protocol. NetworkManager + * itself wouldn't configure those, so they are always configured by somebody + * external. We thus ignore them to avoid the overhead that processing them brings. + * For example, the BGP daemon "bird" might configure a huge number of RTPROT_BIRD routes. */ + + return prot > RTPROT_STATIC && !NM_IN_SET(prot, RTPROT_DHCP, RTPROT_RA); +} + /* Copied and modified from libnl3's build_route_msg() and rtnl_route_build_msg(). */ static struct nl_msg * _nl_msg_new_route(int nlmsg_type, guint16 nlmsgflags, const NMPObject *obj) { - nm_auto_nlmsg struct nl_msg *msg = NULL; - const NMPClass * klass = NMP_OBJECT_GET_CLASS(obj); - gboolean is_v4 = klass->addr_family == AF_INET; - const guint32 lock = ip_route_get_lock_flag(NMP_OBJECT_CAST_IP_ROUTE(obj)); + nm_auto_nlmsg struct nl_msg *msg = NULL; + const NMPClass *klass = NMP_OBJECT_GET_CLASS(obj); + const gboolean IS_IPv4 = NM_IS_IPv4(klass->addr_family); + const guint32 lock = ip_route_get_lock_flag(NMP_OBJECT_CAST_IP_ROUTE(obj)); const guint32 table = nm_platform_route_table_uncoerce(NMP_OBJECT_CAST_IP_ROUTE(obj)->table_coerced, TRUE); const struct rtmsg rtmsg = { .rtm_family = klass->addr_family, - .rtm_tos = is_v4 ? obj->ip4_route.tos : 0, + .rtm_tos = IS_IPv4 ? obj->ip4_route.tos : 0, .rtm_table = table <= 0xFF ? table : RT_TABLE_UNSPEC, .rtm_protocol = nmp_utils_ip_config_source_coerce_to_rtprot(obj->ip_route.rt_source), .rtm_scope = - is_v4 ? nm_platform_route_scope_inv(obj->ip4_route.scope_inv) : RT_SCOPE_NOWHERE, + IS_IPv4 ? nm_platform_route_scope_inv(obj->ip4_route.scope_inv) : RT_SCOPE_NOWHERE, .rtm_type = nm_platform_route_type_uncoerce(NMP_OBJECT_CAST_IP_ROUTE(obj)->type_coerced), .rtm_flags = obj->ip_route.r_rtm_flags & ((unsigned) (RTNH_F_ONLINK)), .rtm_dst_len = obj->ip_route.plen, - .rtm_src_len = is_v4 ? 0 : NMP_OBJECT_CAST_IP6_ROUTE(obj)->src_plen, + .rtm_src_len = IS_IPv4 ? 0 : NMP_OBJECT_CAST_IP6_ROUTE(obj)->src_plen, }; gsize addr_len; @@ -4714,28 +4784,28 @@ _nl_msg_new_route(int nlmsg_type, guint16 nlmsgflags, const NMPObject *obj) if (nlmsg_append_struct(msg, &rtmsg) < 0) goto nla_put_failure; - addr_len = is_v4 ? sizeof(in_addr_t) : sizeof(struct in6_addr); + addr_len = IS_IPv4 ? sizeof(in_addr_t) : sizeof(struct in6_addr); NLA_PUT(msg, RTA_DST, addr_len, - is_v4 ? (gconstpointer) &obj->ip4_route.network - : (gconstpointer) &obj->ip6_route.network); + IS_IPv4 ? (gconstpointer) &obj->ip4_route.network + : (gconstpointer) &obj->ip6_route.network); - if (!is_v4) { + if (!IS_IPv4) { if (!IN6_IS_ADDR_UNSPECIFIED(&NMP_OBJECT_CAST_IP6_ROUTE(obj)->src)) NLA_PUT(msg, RTA_SRC, addr_len, &obj->ip6_route.src); } NLA_PUT_U32(msg, RTA_PRIORITY, - is_v4 ? nm_platform_ip4_route_get_effective_metric(&obj->ip4_route) - : nm_platform_ip6_route_get_effective_metric(&obj->ip6_route)); + IS_IPv4 ? nm_platform_ip4_route_get_effective_metric(&obj->ip4_route) + : nm_platform_ip6_route_get_effective_metric(&obj->ip6_route)); if (table > 0xFF) NLA_PUT_U32(msg, RTA_TABLE, table); - if (is_v4) { + if (IS_IPv4) { if (NMP_OBJECT_CAST_IP4_ROUTE(obj)->pref_src) NLA_PUT(msg, RTA_PREFSRC, addr_len, &obj->ip4_route.pref_src); } else { @@ -4770,7 +4840,7 @@ _nl_msg_new_route(int nlmsg_type, guint16 nlmsgflags, const NMPObject *obj) } /* We currently don't have need for multi-hop routes... */ - if (is_v4) { + if (IS_IPv4) { NLA_PUT(msg, RTA_GATEWAY, addr_len, &obj->ip4_route.gateway); } else { if (!IN6_IS_ADDR_UNSPECIFIED(&obj->ip6_route.gateway)) @@ -4778,7 +4848,7 @@ _nl_msg_new_route(int nlmsg_type, guint16 nlmsgflags, const NMPObject *obj) } NLA_PUT_U32(msg, RTA_OIF, obj->ip_route.ifindex); - if (!is_v4 && obj->ip6_route.rt_pref != NM_ICMPV6_ROUTER_PREF_MEDIUM) + if (!IS_IPv4 && obj->ip6_route.rt_pref != NM_ICMPV6_ROUTER_PREF_MEDIUM) NLA_PUT_U8(msg, RTA_PREF, obj->ip6_route.rt_pref); return g_steal_pointer(&msg); @@ -4904,13 +4974,13 @@ static struct nl_msg * _nl_msg_new_qdisc(int nlmsg_type, int nlmsg_flags, const NMPlatformQdisc *qdisc) { nm_auto_nlmsg struct nl_msg *msg = NULL; - struct nlattr * tc_options; + struct nlattr *tc_options; const struct tcmsg tcm = { - .tcm_family = qdisc->addr_family, - .tcm_ifindex = qdisc->ifindex, - .tcm_handle = qdisc->handle, - .tcm_parent = qdisc->parent, - .tcm_info = qdisc->info, + .tcm_family = qdisc->addr_family, + .tcm_ifindex = qdisc->ifindex, + .tcm_handle = qdisc->handle, + .tcm_parent = qdisc->parent, + .tcm_info = qdisc->info, }; msg = nlmsg_alloc_simple(nlmsg_type, nlmsg_flags | NMP_NLM_FLAG_F_ECHO); @@ -4991,14 +5061,14 @@ static struct nl_msg * _nl_msg_new_tfilter(int nlmsg_type, int nlmsg_flags, const NMPlatformTfilter *tfilter) { nm_auto_nlmsg struct nl_msg *msg = NULL; - struct nlattr * tc_options; - struct nlattr * act_tab; + struct nlattr *tc_options; + struct nlattr *act_tab; const struct tcmsg tcm = { - .tcm_family = tfilter->addr_family, - .tcm_ifindex = tfilter->ifindex, - .tcm_handle = tfilter->handle, - .tcm_parent = tfilter->parent, - .tcm_info = tfilter->info, + .tcm_family = tfilter->addr_family, + .tcm_ifindex = tfilter->ifindex, + .tcm_handle = tfilter->handle, + .tcm_parent = tfilter->parent, + .tcm_info = tfilter->info, }; msg = nlmsg_alloc_simple(nlmsg_type, nlmsg_flags | NMP_NLM_FLAG_F_ECHO); @@ -5016,8 +5086,8 @@ _nl_msg_new_tfilter(int nlmsg_type, int nlmsg_flags, const NMPlatformTfilter *tf if (tfilter->action.kind) { const NMPlatformAction *action = &tfilter->action; - struct nlattr * prio; - struct nlattr * act_options; + struct nlattr *prio; + struct nlattr *act_options; if (!(prio = nla_nest_start(msg, 1 /* priority */))) goto nla_put_failure; @@ -5121,7 +5191,7 @@ _log_dbg_sysctl_set_impl(NMPlatform *platform, const char *path, const char *value) { - GError * error = NULL; + GError *error = NULL; gs_free char *contents = NULL; gs_free char *value_escaped = g_strescape(value, NULL); @@ -5175,7 +5245,7 @@ sysctl_set_internal(NMPlatform *platform, int fd, tries; gssize nwrote; gssize len; - char * actual; + char *actual; gs_free char *actual_free = NULL; int errsv; @@ -5314,12 +5384,12 @@ sysctl_set(NMPlatform *platform, const char *pathid, int dirfd, const char *path } typedef struct { - NMPlatform * platform; - char * pathid; + NMPlatform *platform; + char *pathid; int dirfd; - char * path; - char ** values; - GCancellable * cancellable; + char *path; + char **values; + GCancellable *cancellable; NMPlatformAsyncCallback callback; gpointer callback_data; } SysctlAsyncInfo; @@ -5340,11 +5410,11 @@ sysctl_async_info_free(SysctlAsyncInfo *info) static void sysctl_async_cb(GObject *object, GAsyncResult *res, gpointer user_data) { - NMPlatform * platform; - GTask * task = G_TASK(res); - SysctlAsyncInfo *info; + NMPlatform *platform; + GTask *task = G_TASK(res); + SysctlAsyncInfo *info; gs_free_error GError *error = NULL; - gs_free char * values_str = NULL; + gs_free char *values_str = NULL; info = g_task_get_task_data(task); @@ -5360,15 +5430,15 @@ sysctl_async_cb(GObject *object, GAsyncResult *res, gpointer user_data) } static void -sysctl_async_thread_fn(GTask * task, +sysctl_async_thread_fn(GTask *task, gpointer source_object, gpointer task_data, GCancellable *cancellable) { nm_auto_pop_netns NMPNetns *netns = NULL; - SysctlAsyncInfo * info = task_data; - GError * error = NULL; - char ** value; + SysctlAsyncInfo *info = task_data; + GError *error = NULL; + char **value; if (g_task_return_error_if_cancelled(task)) return; @@ -5403,11 +5473,11 @@ sysctl_async_thread_fn(GTask * task, static void sysctl_set_async_return_idle(gpointer user_data, GCancellable *cancellable) { - gs_unref_object NMPlatform *platform = NULL; - gs_free_error GError *cancelled_error = NULL; - gs_free_error GError * error = NULL; - NMPlatformAsyncCallback callback; - gpointer callback_data; + gs_unref_object NMPlatform *platform = NULL; + gs_free_error GError *cancelled_error = NULL; + gs_free_error GError *error = NULL; + NMPlatformAsyncCallback callback; + gpointer callback_data; nm_utils_user_data_unpack(user_data, &platform, &callback, &callback_data, &error); g_cancellable_set_error_if_cancelled(cancellable, &cancelled_error); @@ -5415,20 +5485,20 @@ sysctl_set_async_return_idle(gpointer user_data, GCancellable *cancellable) } static void -sysctl_set_async(NMPlatform * platform, - const char * pathid, +sysctl_set_async(NMPlatform *platform, + const char *pathid, int dirfd, - const char * path, - const char *const * values, + const char *path, + const char *const *values, NMPlatformAsyncCallback callback, gpointer data, - GCancellable * cancellable) + GCancellable *cancellable) { SysctlAsyncInfo *info; - GTask * task; + GTask *task; int dirfd_dup, errsv; gpointer packed; - GError * error = NULL; + GError *error = NULL; g_return_if_fail(platform); g_return_if_fail(path); @@ -5501,7 +5571,7 @@ _nm_logging_clear_platform_logging_cache(void) typedef struct { const char *path; CList lst; - char * value; + char *value; char path_data[]; } SysctlCacheEntry; @@ -5539,7 +5609,7 @@ _log_dbg_sysctl_get_impl(NMPlatform *platform, const char *pathid, const char *c **/ NM_G_MUTEX_LOCKED(&sysctl_clear_cache_lock); NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE(platform); - SysctlCacheEntry * entry = NULL; + SysctlCacheEntry *entry = NULL; if (!priv->sysctl_get_prev_values) { c_list_link_tail(&sysctl_clear_cache_lst_head, &priv->sysctl_clear_cache_lst); @@ -5567,7 +5637,7 @@ _log_dbg_sysctl_get_impl(NMPlatform *platform, const char *pathid, const char *c nm_c_list_move_front(&priv->sysctl_list, &entry->lst); } else { - gs_free char * contents_escaped = g_strescape(contents, NULL); + gs_free char *contents_escaped = g_strescape(contents, NULL); SysctlCacheEntry *old; size_t len; @@ -5602,8 +5672,8 @@ static char * sysctl_get(NMPlatform *platform, const char *pathid, int dirfd, const char *path) { nm_auto_pop_netns NMPNetns *netns = NULL; - GError * error = NULL; - gs_free char * contents = NULL; + GError *error = NULL; + gs_free char *contents = NULL; ASSERT_SYSCTL_ARGS(pathid, dirfd, path); @@ -5813,10 +5883,10 @@ static NM_UTILS_LOOKUP_STR_DEFINE( static const char * delayed_action_to_string_full(DelayedActionType action_type, gpointer user_data, - char * buf, + char *buf, gsize buf_size) { - char * buf0 = buf; + char *buf0 = buf; const DelayedActionWaitForNlResponseData *data; nm_strbuf_append_str(&buf, &buf_size, delayed_action_to_string(action_type)); @@ -5831,7 +5901,7 @@ delayed_action_to_string_full(DelayedActionType action_type, data = user_data; if (data) { - gint64 timeout = data->timeout_abs_ns - nm_utils_get_monotonic_timestamp_nsec(); + gint64 timeout = data->timeout_abs_nsec - nm_utils_get_monotonic_timestamp_nsec(); char b[255]; nm_strbuf_append( @@ -5889,11 +5959,11 @@ delayed_action_refresh_all_in_progress(NMPlatform *platform, DelayedActionType a } static void -delayed_action_wait_for_nl_response_complete(NMPlatform * platform, +delayed_action_wait_for_nl_response_complete(NMPlatform *platform, guint idx, WaitForNlResponseResult seq_result) { - NMLinuxPlatformPrivate * priv = NM_LINUX_PLATFORM_GET_PRIVATE(platform); + NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE(platform); DelayedActionWaitForNlResponseData *data; nm_assert(NM_FLAGS_HAS(priv->delayed_action.flags, DELAYED_ACTION_TYPE_WAIT_FOR_NL_RESPONSE)); @@ -5932,17 +6002,17 @@ delayed_action_wait_for_nl_response_complete(NMPlatform * platform, } static void -delayed_action_wait_for_nl_response_complete_check(NMPlatform * platform, +delayed_action_wait_for_nl_response_complete_check(NMPlatform *platform, WaitForNlResponseResult force_result, - guint32 * out_next_seq_number, - gint64 * out_next_timeout_abs_ns, - gint64 * p_now_ns) + guint32 *out_next_seq_number, + gint64 *out_next_timeout_abs_ns, + gint64 *p_now_nsec) { NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE(platform); guint i; guint32 next_seq_number = 0; gint64 next_timeout_abs_ns = 0; - gint64 now_ns = 0; + gint64 now_nsec = 0; for (i = 0; i < priv->delayed_action.list_wait_for_nl_response->len;) { const DelayedActionWaitForNlResponseData *data = @@ -5952,10 +6022,10 @@ delayed_action_wait_for_nl_response_complete_check(NMPlatform * platf if (data->seq_result) delayed_action_wait_for_nl_response_complete(platform, i, data->seq_result); - else if (p_now_ns - && ((now_ns ?: (now_ns = nm_utils_get_monotonic_timestamp_nsec())) - >= data->timeout_abs_ns)) { - /* the caller can optionally check for timeout by providing a p_now_ns argument. */ + else if (p_now_nsec + && ((now_nsec ?: (now_nsec = nm_utils_get_monotonic_timestamp_nsec())) + >= data->timeout_abs_nsec)) { + /* the caller can optionally check for timeout by providing a p_now_nsec argument. */ delayed_action_wait_for_nl_response_complete( platform, i, @@ -5963,9 +6033,9 @@ delayed_action_wait_for_nl_response_complete_check(NMPlatform * platf } else if (force_result != WAIT_FOR_NL_RESPONSE_RESULT_UNKNOWN) delayed_action_wait_for_nl_response_complete(platform, i, force_result); else { - if (next_seq_number == 0 || next_timeout_abs_ns > data->timeout_abs_ns) { + if (next_seq_number == 0 || next_timeout_abs_ns > data->timeout_abs_nsec) { next_seq_number = data->seq_number; - next_timeout_abs_ns = data->timeout_abs_ns; + next_timeout_abs_ns = data->timeout_abs_nsec; } i++; } @@ -5979,11 +6049,11 @@ delayed_action_wait_for_nl_response_complete_check(NMPlatform * platf NM_SET_OUT(out_next_seq_number, next_seq_number); NM_SET_OUT(out_next_timeout_abs_ns, next_timeout_abs_ns); - NM_SET_OUT(p_now_ns, now_ns); + NM_SET_OUT(p_now_nsec, now_nsec); } static void -delayed_action_wait_for_nl_response_complete_all(NMPlatform * platform, +delayed_action_wait_for_nl_response_complete_all(NMPlatform *platform, WaitForNlResponseResult fallback_result) { delayed_action_wait_for_nl_response_complete_check(platform, fallback_result, NULL, NULL, NULL); @@ -6080,8 +6150,8 @@ delayed_action_handle_one(NMPlatform *platform) priv->delayed_action.flags &= ~DELAYED_ACTION_TYPE_REFRESH_ALL; if (_LOGt_ENABLED()) { - FOR_EACH_DELAYED_ACTION(iflags, flags) - _LOGt_delayed_action(iflags, NULL, "handle"); + FOR_EACH_DELAYED_ACTION (iflags, flags) + _LOGt_delayed_action(iflags, NULL, "handle"); } delayed_action_handle_REFRESH_ALL(platform, flags); @@ -6177,22 +6247,22 @@ delayed_action_schedule(NMPlatform *platform, DelayedActionType action_type, gpo priv->delayed_action.flags |= action_type; if (_LOGt_ENABLED()) { - FOR_EACH_DELAYED_ACTION(iflags, action_type) - _LOGt_delayed_action(iflags, user_data, "schedule"); + FOR_EACH_DELAYED_ACTION (iflags, action_type) + _LOGt_delayed_action(iflags, user_data, "schedule"); } } static void -delayed_action_schedule_WAIT_FOR_NL_RESPONSE(NMPlatform * platform, +delayed_action_schedule_WAIT_FOR_NL_RESPONSE(NMPlatform *platform, guint32 seq_number, - WaitForNlResponseResult * out_seq_result, - char ** out_errmsg, + WaitForNlResponseResult *out_seq_result, + char **out_errmsg, DelayedActionWaitForNlResponseType response_type, gpointer response_out_data) { DelayedActionWaitForNlResponseData data = { .seq_number = seq_number, - .timeout_abs_ns = + .timeout_abs_nsec = nm_utils_get_monotonic_timestamp_nsec() + (200 * (NM_UTILS_NSEC_PER_SEC / 1000)), .out_seq_result = out_seq_result, .out_errmsg = out_errmsg, @@ -6211,7 +6281,7 @@ cache_prune_one_type(NMPlatform *platform, const NMPLookup *lookup) NMDedupMultiIter iter; const NMPObject *obj; NMPCacheOpsType cache_op; - NMPCache * cache = nm_platform_get_cache(platform); + NMPCache *cache = nm_platform_get_cache(platform); nm_dedup_multi_iter_init(&iter, nmp_cache_lookup(cache, lookup)); while (nm_dedup_multi_iter_next(&iter)) { @@ -6260,7 +6330,7 @@ cache_prune_all(NMPlatform *platform) } static void -cache_on_change(NMPlatform * platform, +cache_on_change(NMPlatform *platform, NMPCacheOpsType cache_op, const NMPObject *obj_old, const NMPObject *obj_new) @@ -6268,7 +6338,7 @@ cache_on_change(NMPlatform * platform, const NMPClass *klass; char str_buf[sizeof(_nm_utils_to_string_buffer)]; char str_buf2[sizeof(_nm_utils_to_string_buffer)]; - NMPCache * cache = nm_platform_get_cache(platform); + NMPCache *cache = nm_platform_get_cache(platform); ASSERT_nmp_cache_ops(cache, cache_op, obj_old, obj_new); nm_assert(cache_op != NMP_CACHE_OPS_UNCHANGED); @@ -6531,10 +6601,10 @@ _nlh_seq_next_get(NMLinuxPlatformPrivate *priv) * Returns: 0 on success or a negative errno. */ static int -_nl_send_nlmsghdr(NMPlatform * platform, - struct nlmsghdr * nlhdr, - WaitForNlResponseResult * out_seq_result, - char ** out_errmsg, +_nl_send_nlmsghdr(NMPlatform *platform, + struct nlmsghdr *nlhdr, + WaitForNlResponseResult *out_seq_result, + char **out_errmsg, DelayedActionWaitForNlResponseType response_type, gpointer response_out_data) { @@ -6598,15 +6668,15 @@ again: * Returns: 0 on success, or a negative libnl3 error code (beware, it's not an errno). */ static int -_nl_send_nlmsg(NMPlatform * platform, - struct nl_msg * nlmsg, - WaitForNlResponseResult * out_seq_result, - char ** out_errmsg, +_nl_send_nlmsg(NMPlatform *platform, + struct nl_msg *nlmsg, + WaitForNlResponseResult *out_seq_result, + char **out_errmsg, DelayedActionWaitForNlResponseType response_type, gpointer response_out_data) { NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE(platform); - struct nlmsghdr * nlhdr; + struct nlmsghdr *nlhdr; guint32 seq; int nle; @@ -6632,7 +6702,7 @@ _nl_send_nlmsg(NMPlatform * platform, static void do_request_link_no_delayed_actions(NMPlatform *platform, int ifindex, const char *name) { - NMLinuxPlatformPrivate * priv = NM_LINUX_PLATFORM_GET_PRIVATE(platform); + NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE(platform); nm_auto_nlmsg struct nl_msg *nlmsg = NULL; int nle; @@ -6680,7 +6750,7 @@ static struct nl_msg * _nl_msg_new_dump(NMPObjectType obj_type, int preferred_addr_family) { nm_auto_nlmsg struct nl_msg *nlmsg = NULL; - const NMPClass * klass; + const NMPClass *klass; klass = nmp_class_from_type(obj_type); @@ -6753,8 +6823,7 @@ do_request_all_no_delayed_actions(NMPlatform *platform, DelayedActionType action action_type_prune &= ~DELAYED_ACTION_TYPE_REFRESH_ALL_ROUTING_RULES_ALL; } - FOR_EACH_DELAYED_ACTION(iflags, action_type_prune) - { + FOR_EACH_DELAYED_ACTION (iflags, action_type_prune) { RefreshAllType refresh_all_type = delayed_action_type_to_refresh_all_type(iflags); NMPLookup lookup; @@ -6763,12 +6832,11 @@ do_request_all_no_delayed_actions(NMPlatform *platform, DelayedActionType action nmp_cache_dirty_set_all_main(nm_platform_get_cache(platform), &lookup); } - FOR_EACH_DELAYED_ACTION(iflags, action_type) - { + FOR_EACH_DELAYED_ACTION (iflags, action_type) { RefreshAllType refresh_all_type = delayed_action_type_to_refresh_all_type(iflags); const RefreshAllInfo *refresh_all_info = refresh_all_type_get_info(refresh_all_type); nm_auto_nlmsg struct nl_msg *nlmsg = NULL; - int * out_refresh_all_in_progress; + int *out_refresh_all_in_progress; out_refresh_all_in_progress = &priv->delayed_action.refresh_all_in_progress[refresh_all_type]; @@ -6826,7 +6894,7 @@ do_request_one_type_by_needle_object(NMPlatform *platform, const NMPObject *obj_ static void event_seq_check_refresh_all(NMPlatform *platform, guint32 seq_number) { - NMLinuxPlatformPrivate * priv = NM_LINUX_PLATFORM_GET_PRIVATE(platform); + NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE(platform); DelayedActionWaitForNlResponseData *data; guint i; @@ -6855,12 +6923,12 @@ event_seq_check_refresh_all(NMPlatform *platform, guint32 seq_number) } static void -event_seq_check(NMPlatform * platform, +event_seq_check(NMPlatform *platform, guint32 seq_number, WaitForNlResponseResult seq_result, - const char * msg) + const char *msg) { - NMLinuxPlatformPrivate * priv = NM_LINUX_PLATFORM_GET_PRIVATE(platform); + NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE(platform); DelayedActionWaitForNlResponseData *data; guint i; @@ -6901,14 +6969,14 @@ event_seq_check(NMPlatform * platform, static void event_valid_msg(NMPlatform *platform, struct nl_msg *msg, gboolean handle_events) { - NMLinuxPlatformPrivate *priv; + NMLinuxPlatformPrivate *priv; nm_auto_nmpobj NMPObject *obj = NULL; NMPCacheOpsType cache_op; - struct nlmsghdr * msghdr; + struct nlmsghdr *msghdr; char buf_nlmsghdr[400]; gboolean is_del = FALSE; gboolean is_dump = FALSE; - NMPCache * cache = nm_platform_get_cache(platform); + NMPCache *cache = nm_platform_get_cache(platform); msghdr = nlmsg_hdr(msg); @@ -7010,6 +7078,17 @@ event_valid_msg(NMPlatform *platform, struct nl_msg *msg, gboolean handle_events } } + if (ip_route_ignored_protocol(NMP_OBJECT_CAST_IP_ROUTE(obj))) { + /* We ignore certain rtm_protocol, because NetworkManager would only ever + * configure certain protocols. Other routes were not added by NetworkManager + * and we don't need to track them in the platform cache. + * + * This is to help with the performance overhead of a huge number of + * routes, for example with the bird BGP software, that adds routes + * with RTPROT_BIRD protocol. */ + return; + } + cache_op = nmp_cache_update_netlink_route(cache, obj, is_dump, @@ -7085,18 +7164,18 @@ event_valid_msg(NMPlatform *platform, struct nl_msg *msg, gboolean handle_events /*****************************************************************************/ static int -do_add_link_with_lookup(NMPlatform * platform, +do_add_link_with_lookup(NMPlatform *platform, NMLinkType link_type, - const char * name, - struct nl_msg * nlmsg, + const char *name, + struct nl_msg *nlmsg, const NMPlatformLink **out_link) { - const NMPObject * obj = NULL; + const NMPObject *obj = NULL; WaitForNlResponseResult seq_result = WAIT_FOR_NL_RESPONSE_RESULT_UNKNOWN; - gs_free char * errmsg = NULL; + gs_free char *errmsg = NULL; int nle; char s_buf[256]; - NMPCache * cache = nm_platform_get_cache(platform); + NMPCache *cache = nm_platform_get_cache(platform); event_handler_read_netlink(platform, FALSE); @@ -7135,13 +7214,13 @@ do_add_link_with_lookup(NMPlatform * platform, } static int -do_add_addrroute(NMPlatform * platform, +do_add_addrroute(NMPlatform *platform, const NMPObject *obj_id, - struct nl_msg * nlmsg, + struct nl_msg *nlmsg, gboolean suppress_netlink_failure) { WaitForNlResponseResult seq_result = WAIT_FOR_NL_RESPONSE_RESULT_UNKNOWN; - gs_free char * errmsg = NULL; + gs_free char *errmsg = NULL; int nle; char s_buf[256]; @@ -7200,11 +7279,11 @@ static gboolean do_delete_object(NMPlatform *platform, const NMPObject *obj_id, struct nl_msg *nlmsg) { WaitForNlResponseResult seq_result = WAIT_FOR_NL_RESPONSE_RESULT_UNKNOWN; - gs_free char * errmsg = NULL; + gs_free char *errmsg = NULL; int nle; char s_buf[256]; gboolean success; - const char * log_detail = ""; + const char *log_detail = ""; event_handler_read_netlink(platform, FALSE); @@ -7270,23 +7349,23 @@ do_delete_object(NMPlatform *platform, const NMPObject *obj_id, struct nl_msg *n } static int -do_change_link(NMPlatform * platform, +do_change_link(NMPlatform *platform, ChangeLinkType change_link_type, int ifindex, - struct nl_msg * nlmsg, + struct nl_msg *nlmsg, const ChangeLinkData *data) { nm_auto_pop_netns NMPNetns *netns = NULL; int nle; WaitForNlResponseResult seq_result = WAIT_FOR_NL_RESPONSE_RESULT_UNKNOWN; - gs_free char * errmsg = NULL; + gs_free char *errmsg = NULL; char s_buf[256]; int result = 0; NMLogLevel log_level = LOGL_DEBUG; - const char * log_result = "failure"; - const char * log_detail = ""; - gs_free char * log_detail_free = NULL; - const NMPObject * obj_cache; + const char *log_result = "failure"; + const char *log_detail = ""; + gs_free char *log_detail_free = NULL; + const NMPObject *obj_cache; if (!nm_platform_netns_push(platform, &netns)) { log_level = LOGL_ERR; @@ -7368,11 +7447,11 @@ out: } 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, @@ -7418,7 +7497,7 @@ link_delete(NMPlatform *platform, int ifindex) { nm_auto_nlmsg struct nl_msg *nlmsg = NULL; NMPObject obj_id; - const NMPObject * obj; + const NMPObject *obj; obj = nmp_cache_lookup_link(nm_platform_get_cache(platform), ifindex); if (!obj || !obj->_link.netlink.is_in_netlink) @@ -7527,7 +7606,7 @@ static gboolean link_supports_vlans(NMPlatform *platform, int ifindex) { nm_auto_pop_netns NMPNetns *netns = NULL; - const NMPObject * obj; + const NMPObject *obj; obj = nm_platform_link_get_obj(platform, ifindex, TRUE); @@ -7569,10 +7648,10 @@ link_set_address(NMPlatform *platform, int ifindex, gconstpointer address, size_ { nm_auto_nlmsg struct nl_msg *nlmsg = NULL; const ChangeLinkData d = { - .set_address = + .set_address = { - .address = address, - .length = length, + .address = address, + .length = length, }, }; @@ -7643,11 +7722,11 @@ nla_put_failure: static void sriov_idle_cb(gpointer user_data, GCancellable *cancellable) { - gs_unref_object NMPlatform *platform = NULL; - gs_free_error GError *cancelled_error = NULL; - gs_free_error GError * error = NULL; - NMPlatformAsyncCallback callback; - gpointer callback_data; + gs_unref_object NMPlatform *platform = NULL; + gs_free_error GError *cancelled_error = NULL; + gs_free_error GError *error = NULL; + NMPlatformAsyncCallback callback; + gpointer callback_data; g_cancellable_set_error_if_cancelled(cancellable, &cancelled_error); nm_utils_user_data_unpack(user_data, &platform, &error, &callback, &callback_data); @@ -7655,24 +7734,24 @@ sriov_idle_cb(gpointer user_data, GCancellable *cancellable) } static void -link_set_sriov_params_async(NMPlatform * platform, +link_set_sriov_params_async(NMPlatform *platform, int ifindex, guint num_vfs, NMOptionBool autoprobe, NMPlatformAsyncCallback callback, gpointer data, - GCancellable * cancellable) + GCancellable *cancellable) { nm_auto_pop_netns NMPNetns *netns = NULL; - gs_free_error GError *error = NULL; - nm_auto_close int dirfd = -1; - int current_autoprobe; - guint i, total; - gint64 current_num; - char ifname[IFNAMSIZ]; - gpointer packed; - const char * values[3]; - char buf[64]; + gs_free_error GError *error = NULL; + nm_auto_close int dirfd = -1; + int current_autoprobe; + guint i, total; + gint64 current_num; + char ifname[IFNAMSIZ]; + gpointer packed; + const char *values[3]; + char buf[64]; g_return_if_fail(callback || !data); g_return_if_fail(cancellable); @@ -7781,7 +7860,7 @@ static gboolean link_set_sriov_vfs(NMPlatform *platform, int ifindex, const NMPlatformVF *const *vfs) { nm_auto_nlmsg struct nl_msg *nlmsg = NULL; - struct nlattr * list, *info, *vlan_list; + struct nlattr *list, *info, *vlan_list; guint i; nlmsg = _nl_msg_new_link(RTM_NEWLINK, 0, ifindex, NULL); @@ -7868,13 +7947,13 @@ nla_put_failure: } static gboolean -link_set_bridge_vlans(NMPlatform * platform, +link_set_bridge_vlans(NMPlatform *platform, int ifindex, gboolean on_master, const NMPlatformBridgeVlan *const *vlans) { nm_auto_nlmsg struct nl_msg *nlmsg = NULL; - struct nlattr * list; + struct nlattr *list; struct bridge_vlan_info vinfo = {}; guint i; @@ -7959,13 +8038,13 @@ link_get_dev_id(NMPlatform *platform, int ifindex) } static gboolean -link_tun_add(NMPlatform * platform, - const char * name, +link_tun_add(NMPlatform *platform, + const char *name, const NMPlatformLnkTun *props, - const NMPlatformLink ** out_link, - int * out_fd) + const NMPlatformLink **out_link, + int *out_fd) { - const NMPObject * obj; + const NMPObject *obj; struct ifreq ifr = {}; nm_auto_close int fd = -1; @@ -8023,8 +8102,8 @@ _vlan_change_vlan_qos_mapping_create(gboolean is_ingress_map, guint current_n_map, const NMVlanQosMapping *set_map, guint set_n_map, - NMVlanQosMapping ** out_map, - guint * out_n_map) + NMVlanQosMapping **out_map, + guint *out_n_map) { NMVlanQosMapping *map; guint i, j, len; @@ -8087,7 +8166,7 @@ _vlan_change_vlan_qos_mapping_create(gboolean is_ingress_map, } static gboolean -link_vlan_change(NMPlatform * platform, +link_vlan_change(NMPlatform *platform, int ifindex, _NMVlanFlags flags_mask, _NMVlanFlags flags_set, @@ -8098,13 +8177,13 @@ link_vlan_change(NMPlatform * platform, const NMVlanQosMapping *egress_map, gsize n_egress_map) { - const NMPObject * obj_cache; + const NMPObject *obj_cache; nm_auto_nlmsg struct nl_msg *nlmsg = NULL; - const NMPObjectLnkVlan * lnk; + const NMPObjectLnkVlan *lnk; guint new_n_ingress_map = 0; guint new_n_egress_map = 0; - gs_free NMVlanQosMapping *new_ingress_map = NULL; - gs_free NMVlanQosMapping *new_egress_map = NULL; + gs_free NMVlanQosMapping *new_ingress_map = NULL; + gs_free NMVlanQosMapping *new_egress_map = NULL; obj_cache = nmp_cache_lookup_link(nm_platform_get_cache(platform), ifindex); if (!obj_cache || !obj_cache->_link.netlink.is_in_netlink) { @@ -8175,7 +8254,7 @@ link_release(NMPlatform *platform, int master, int slave) /*****************************************************************************/ static gboolean -_infiniband_partition_action(NMPlatform * platform, +_infiniband_partition_action(NMPlatform *platform, InfinibandAction action, int parent, int p_key, @@ -8183,7 +8262,7 @@ _infiniband_partition_action(NMPlatform * platform, { nm_auto_close int dirfd = -1; char ifname_parent[IFNAMSIZ]; - const NMPObject * obj; + const NMPObject *obj; char id[20]; char name[IFNAMSIZ]; gboolean success; @@ -8234,7 +8313,7 @@ _infiniband_partition_action(NMPlatform * platform, } static gboolean -infiniband_partition_add(NMPlatform * platform, +infiniband_partition_add(NMPlatform *platform, int parent, int p_key, const NMPlatformLink **out_link) @@ -8274,7 +8353,7 @@ get_ext_data(NMPlatform *platform, int ifindex) #define WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, retval) \ nm_auto_pop_netns NMPNetns *netns = NULL; \ - NMWifiUtils * wifi_data; \ + NMWifiUtils *wifi_data; \ if (!nm_platform_netns_push(platform, &netns)) \ return retval; \ wifi_data = NM_WIFI_UTILS(get_ext_data(platform, ifindex)); \ @@ -8298,11 +8377,11 @@ wifi_get_frequency(NMPlatform *platform, int ifindex) } static gboolean -wifi_get_station(NMPlatform * platform, +wifi_get_station(NMPlatform *platform, int ifindex, NMEtherAddr *out_bssid, - int * out_quality, - guint32 * out_rate) + int *out_quality, + guint32 *out_rate) { WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, FALSE); return nm_wifi_utils_get_station(wifi_data, out_bssid, out_quality, out_rate); @@ -8365,7 +8444,7 @@ link_can_assume(NMPlatform *platform, int ifindex) NMPLookup lookup; const NMPObject *link, *o; NMDedupMultiIter iter; - NMPCache * cache = nm_platform_get_cache(platform); + NMPCache *cache = nm_platform_get_cache(platform); if (ifindex <= 0) return FALSE; @@ -8488,9 +8567,9 @@ link_get_wake_on_lan(NMPlatform *platform, int ifindex) 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) { nm_auto_pop_netns NMPNetns *netns = NULL; NMPUtilsEthtoolDriverInfo driver_info; @@ -8543,7 +8622,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, @@ -8632,7 +8711,7 @@ ip6_address_delete(NMPlatform *platform, int ifindex, struct in6_addr addr, guin /*****************************************************************************/ static int -ip_route_add(NMPlatform * platform, +ip_route_add(NMPlatform *platform, NMPNlmFlags flags, int addr_family, const NMPlatformIPRoute *route) @@ -8659,7 +8738,7 @@ static gboolean object_delete(NMPlatform *platform, const NMPObject *obj) { nm_auto_nmpobj const NMPObject *obj_keep_alive = NULL; - nm_auto_nlmsg struct nl_msg * nlmsg = NULL; + nm_auto_nlmsg struct nl_msg *nlmsg = NULL; if (!NMP_OBJECT_IS_STACKINIT(obj)) obj_keep_alive = nmp_object_ref(obj); @@ -8690,17 +8769,17 @@ object_delete(NMPlatform *platform, const NMPObject *obj) /*****************************************************************************/ static int -ip_route_get(NMPlatform * platform, +ip_route_get(NMPlatform *platform, int addr_family, gconstpointer address, int oif_ifindex, - NMPObject ** out_route) + NMPObject **out_route) { - const gboolean is_v4 = (addr_family == AF_INET); - const int addr_len = is_v4 ? 4 : 16; - int try_count = 0; - WaitForNlResponseResult seq_result; - int nle; + const gboolean IS_IPv4 = NM_IS_IPv4(addr_family); + const int addr_len = IS_IPv4 ? 4 : 16; + int try_count = 0; + WaitForNlResponseResult seq_result; + int nle; nm_auto_nmpobj NMPObject *route = NULL; nm_assert(NM_IS_LINUX_PLATFORM(platform)); @@ -8718,7 +8797,7 @@ ip_route_get(NMPlatform * platform, .n.nlmsg_type = RTM_GETROUTE, .r.rtm_family = addr_family, .r.rtm_tos = 0, - .r.rtm_dst_len = is_v4 ? 32 : 128, + .r.rtm_dst_len = IS_IPv4 ? 32 : 128, .r.rtm_flags = 0x1000 /* RTM_F_LOOKUP_TABLE */, }; @@ -8778,7 +8857,7 @@ routing_rule_add(NMPlatform *platform, NMPNlmFlags flags, const NMPlatformRoutin { WaitForNlResponseResult seq_result = WAIT_FOR_NL_RESPONSE_RESULT_UNKNOWN; nm_auto_nlmsg struct nl_msg *msg = NULL; - gs_free char * errmsg = NULL; + gs_free char *errmsg = NULL; char s_buf[256]; int nle; @@ -8818,7 +8897,7 @@ static int qdisc_add(NMPlatform *platform, NMPNlmFlags flags, const NMPlatformQdisc *qdisc) { WaitForNlResponseResult seq_result = WAIT_FOR_NL_RESPONSE_RESULT_UNKNOWN; - gs_free char * errmsg = NULL; + gs_free char *errmsg = NULL; int nle; char s_buf[256]; nm_auto_nlmsg struct nl_msg *msg = NULL; @@ -8860,14 +8939,14 @@ static int tc_delete(NMPlatform *platform, int nlmsgtype, int ifindex, guint32 parent, gboolean log_error) { WaitForNlResponseResult seq_result = WAIT_FOR_NL_RESPONSE_RESULT_UNKNOWN; - gs_free char * errmsg = NULL; + gs_free char *errmsg = NULL; int nle; char s_buf[256]; - const char * log_tag; + const char *log_tag; nm_auto_nlmsg struct nl_msg *msg = NULL; const struct tcmsg tcm = { - .tcm_ifindex = ifindex, - .tcm_parent = parent, + .tcm_ifindex = ifindex, + .tcm_parent = parent, }; switch (nlmsgtype) { @@ -8934,7 +9013,7 @@ static int tfilter_add(NMPlatform *platform, NMPNlmFlags flags, const NMPlatformTfilter *tfilter) { WaitForNlResponseResult seq_result = WAIT_FOR_NL_RESPONSE_RESULT_UNKNOWN; - gs_free char * errmsg = NULL; + gs_free char *errmsg = NULL; int nle; char s_buf[256]; nm_auto_nlmsg struct nl_msg *msg = NULL; @@ -8992,39 +9071,44 @@ event_handler(int fd, GIOCondition io_condition, gpointer user_data) static int event_handler_recvmsgs(NMPlatform *platform, gboolean handle_events) { - NMLinuxPlatformPrivate * priv = NM_LINUX_PLATFORM_GET_PRIVATE(platform); - struct nl_sock * sk = priv->nlh; - int n; - int err = 0; - gboolean multipart = 0; - gboolean interrupted = FALSE; - struct nlmsghdr * hdr; - WaitForNlResponseResult seq_result; - struct sockaddr_nl nla = {0}; - struct ucred creds; - gboolean creds_has; - nm_auto_free unsigned char *buf = NULL; + NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE(platform); + struct nl_sock *sk = priv->nlh; + int n; + int err = 0; + gboolean multipart = 0; + gboolean interrupted = FALSE; + struct nlmsghdr *hdr; + WaitForNlResponseResult seq_result; + struct sockaddr_nl nla; + struct ucred creds; + gboolean creds_has; + unsigned char *buf; continue_reading: - nm_clear_pointer(&buf, free); - n = nl_recv(sk, &nla, &buf, &creds, &creds_has); + buf = NULL; + + n = nl_recv(sk, + priv->netlink_recv_buf.buf, + priv->netlink_recv_buf.len, + &nla, + &buf, + &creds, + &creds_has); + + nm_assert((n <= 0 && !buf) + || (n > 0 && n <= priv->netlink_recv_buf.len && buf == priv->netlink_recv_buf.buf)); if (n <= 0) { if (n == -NME_NL_MSG_TRUNC) { - int buf_size; - /* the message receive buffer was too small. We lost one message, which * is unfortunate. Try to double the buffer size for the next time. */ - buf_size = nl_socket_get_msg_buf_size(sk); - if (buf_size < 512 * 1024) { - buf_size *= 2; - _LOGT("netlink: recvmsg: increase message buffer size for recvmsg() to %d bytes", - buf_size); - if (nl_socket_set_msg_buf_size(sk, buf_size) < 0) - nm_assert_not_reached(); - if (!handle_events) - goto continue_reading; - } + priv->netlink_recv_buf.len *= 2; + priv->netlink_recv_buf.buf = + g_realloc(priv->netlink_recv_buf.buf, priv->netlink_recv_buf.len); + _LOGT("netlink: recvmsg: increase message buffer size for recvmsg() to %zu bytes", + priv->netlink_recv_buf.len); + if (!handle_events) + goto continue_reading; } return n; @@ -9037,7 +9121,7 @@ continue_reading: gboolean process_valid_msg = FALSE; guint32 seq_number; char buf_nlmsghdr[400]; - const char * extack_msg = NULL; + const char *extack_msg = NULL; msg = nlmsg_alloc_convert(hdr); @@ -9195,15 +9279,15 @@ static gboolean event_handler_read_netlink(NMPlatform *platform, gboolean wait_for_acks) { nm_auto_pop_netns NMPNetns *netns = NULL; - NMLinuxPlatformPrivate * priv = NM_LINUX_PLATFORM_GET_PRIVATE(platform); + NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE(platform); int r; struct pollfd pfd; gboolean any = FALSE; int timeout_msec; struct { guint32 seq_number; - gint64 timeout_abs_ns; - gint64 now_ns; + gint64 timeout_abs_nsec; + gint64 now_nsec; } next; if (!nm_platform_netns_push(platform, &netns)) { @@ -9275,25 +9359,33 @@ after_read: delayed_action_wait_for_nl_response_complete_check(platform, WAIT_FOR_NL_RESPONSE_RESULT_UNKNOWN, &next.seq_number, - &next.timeout_abs_ns, - &next.now_ns); + &next.timeout_abs_nsec, + &next.now_nsec); if (!wait_for_acks || !NM_FLAGS_HAS(priv->delayed_action.flags, DELAYED_ACTION_TYPE_WAIT_FOR_NL_RESPONSE)) return any; nm_assert(next.seq_number); - nm_assert(next.now_ns > 0); - nm_assert(next.timeout_abs_ns > next.now_ns); + nm_assert(next.now_nsec > 0); + nm_assert(next.timeout_abs_nsec > next.now_nsec); + nm_assert(next.timeout_abs_nsec - next.now_nsec <= 200 * (NM_UTILS_NSEC_PER_SEC / 1000)); - _LOGT("netlink: read: wait for ACK for sequence number %u...", next.seq_number); + timeout_msec = + NM_CLAMP((next.timeout_abs_nsec - next.now_nsec) / (NM_UTILS_NSEC_PER_SEC / 1000), + 1, + 1000); - timeout_msec = (next.timeout_abs_ns - next.now_ns) / (NM_UTILS_NSEC_PER_SEC / 1000); + _LOGT("netlink: read: wait for ACK for sequence number %u... (%d msec)", + next.seq_number, + timeout_msec); memset(&pfd, 0, sizeof(pfd)); pfd.fd = nl_socket_get_fd(priv->nlh); pfd.events = POLLIN; - r = poll(&pfd, 1, MAX(1, timeout_msec)); + r = poll(&pfd, 1, timeout_msec); + + _LOGT("netlink: read: poll done (r=%d)", r); if (r == 0) { /* timeout and there is nothing to read. */ @@ -9412,11 +9504,11 @@ static void handle_udev_event(NMUdevClient *udev_client, struct udev_device *udevice, gpointer user_data) { nm_auto_pop_netns NMPNetns *netns = NULL; - NMPlatform * platform = NM_PLATFORM(user_data); - const char * subsys; - const char * ifindex; + NMPlatform *platform = NM_PLATFORM(user_data); + const char *subsys; + const char *ifindex; guint64 seqnum; - const char * action; + const char *action; action = udev_device_get_action(udevice); g_return_if_fail(action); @@ -9449,6 +9541,9 @@ nm_linux_platform_init(NMLinuxPlatform *self) { NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE(self); + priv->netlink_recv_buf.len = 32 * 1024; + priv->netlink_recv_buf.buf = g_malloc(priv->netlink_recv_buf.len); + c_list_init(&priv->sysctl_clear_cache_lst); c_list_init(&priv->sysctl_list); @@ -9461,7 +9556,7 @@ nm_linux_platform_init(NMLinuxPlatform *self) static void constructed(GObject *_object) { - NMPlatform * platform = NM_PLATFORM(_object); + NMPlatform *platform = NM_PLATFORM(_object); NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE(platform); int nle; int fd; @@ -9517,10 +9612,10 @@ constructed(GObject *_object) _LOGD("could not enable extended acks on netlink socket"); /* explicitly set the msg buffer size and disable MSG_PEEK. - * If we later encounter NME_NL_MSG_TRUNC, we will adjust the buffer size. */ + * We use our own receive buffer priv->netlink_recv_buf. + * If we encounter NME_NL_MSG_TRUNC, we will increase the buffer + * and resync (as we would have lost the message without NL_MSG_PEEK). */ nl_socket_disable_msg_peek(priv->nlh); - nle = nl_socket_set_msg_buf_size(priv->nlh, 32 * 1024); - g_assert(!nle); nle = nl_socket_add_memberships(priv->nlh, RTNLGRP_IPV4_IFADDR, @@ -9571,7 +9666,7 @@ constructed(GObject *_object) /* Set up udev monitoring */ if (priv->udev_client) { - struct udev_enumerate * enumerator; + struct udev_enumerate *enumerator; struct udev_list_entry *devices, *l; /* And read initial device list */ @@ -9643,7 +9738,7 @@ nm_linux_platform_new(gboolean log_with_ptr, gboolean netns_support, gboolean ca static void dispose(GObject *object) { - NMPlatform * platform = NM_PLATFORM(object); + NMPlatform *platform = NM_PLATFORM(object); NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE(platform); _LOGD("dispose"); @@ -9688,12 +9783,14 @@ finalize(GObject *object) priv->udev_client = nm_udev_client_destroy(priv->udev_client); G_OBJECT_CLASS(nm_linux_platform_parent_class)->finalize(object); + + g_free(priv->netlink_recv_buf.buf); } static void nm_linux_platform_class_init(NMLinuxPlatformClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMPlatformClass *platform_class = NM_PLATFORM_CLASS(klass); object_class->constructed = constructed; diff --git a/src/libnm-platform/nm-netlink.c b/src/libnm-platform/nm-netlink.c index 56cde50c..697ae591 100644 --- a/src/libnm-platform/nm-netlink.c +++ b/src/libnm-platform/nm-netlink.c @@ -32,7 +32,7 @@ struct nl_msg { struct sockaddr_nl nm_src; struct sockaddr_nl nm_dst; struct ucred nm_creds; - struct nlmsghdr * nm_nlh; + struct nlmsghdr *nm_nlh; size_t nm_size; bool nm_creds_has : 1; }; @@ -245,7 +245,7 @@ nlmsg_hdr(struct nl_msg *n) void * nlmsg_reserve(struct nl_msg *n, size_t len, int pad) { - char * buf = (char *) n->nm_nlh; + char *buf = (char *) n->nm_nlh; size_t nlmsg_len = n->nm_nlh->nlmsg_len; size_t tlen; @@ -386,9 +386,9 @@ nlmsg_append(struct nl_msg *n, const void *data, size_t len, int pad) /*****************************************************************************/ int -nlmsg_parse(struct nlmsghdr * nlh, +nlmsg_parse(struct nlmsghdr *nlh, int hdrlen, - struct nlattr * tb[], + struct nlattr *tb[], int maxtype, const struct nla_policy *policy) { @@ -639,9 +639,9 @@ validate_nla(const struct nlattr *nla, int maxtype, const struct nla_policy *pol } int -nla_parse(struct nlattr * tb[], +nla_parse(struct nlattr *tb[], int maxtype, - struct nlattr * head, + struct nlattr *head, int len, const struct nla_policy *policy) { @@ -718,7 +718,7 @@ genlmsg_put(struct nl_msg *msg, uint8_t cmd, uint8_t version) { - struct nlmsghdr * nlh; + struct nlmsghdr *nlh; struct genlmsghdr hdr = { .cmd = cmd, .version = version, @@ -794,9 +794,9 @@ genlmsg_valid_hdr(struct nlmsghdr *nlh, int hdrlen) } int -genlmsg_parse(struct nlmsghdr * nlh, +genlmsg_parse(struct nlmsghdr *nlh, int hdrlen, - struct nlattr * tb[], + struct nlattr *tb[], int maxtype, const struct nla_policy *policy) { @@ -825,9 +825,9 @@ _genl_parse_getfamily(struct nl_msg *msg, void *arg) [CTRL_ATTR_OPS] = {.type = NLA_NESTED}, [CTRL_ATTR_MCAST_GROUPS] = {.type = NLA_NESTED}, }; - struct nlattr * tb[G_N_ELEMENTS(ctrl_policy)]; + struct nlattr *tb[G_N_ELEMENTS(ctrl_policy)]; struct nlmsghdr *nlh = nlmsg_hdr(msg); - gint32 * response_data = arg; + gint32 *response_data = arg; if (genlmsg_parse_arr(nlh, 0, tb, ctrl_policy) < 0) return NL_SKIP; @@ -845,8 +845,8 @@ genl_ctrl_resolve(struct nl_sock *sk, const char *name) int nmerr; gint32 response_data = -1; const struct nl_cb cb = { - .valid_cb = _genl_parse_getfamily, - .valid_arg = &response_data, + .valid_cb = _genl_parse_getfamily, + .valid_arg = &response_data, }; msg = nlmsg_alloc(); @@ -1170,13 +1170,13 @@ nl_recvmsgs(struct nl_sock *sk, const struct nl_cb *cb) { int n, nmerr = 0, multipart = 0, interrupted = 0, nrecv = 0; gs_free unsigned char *buf = NULL; - struct nlmsghdr * hdr; - struct sockaddr_nl nla = {0}; + struct nlmsghdr *hdr; + struct sockaddr_nl nla; struct ucred creds; gboolean creds_has; continue_reading: - n = nl_recv(sk, &nla, &buf, &creds, &creds_has); + n = nl_recv(sk, NULL, 0, &nla, &buf, &creds, &creds_has); if (n <= 0) return n; @@ -1327,12 +1327,12 @@ int nl_send_iovec(struct nl_sock *sk, struct nl_msg *msg, struct iovec *iov, unsigned iovlen) { struct sockaddr_nl *dst; - struct ucred * creds; + struct ucred *creds; struct msghdr hdr = { - .msg_name = (void *) &sk->s_peer, - .msg_namelen = sizeof(struct sockaddr_nl), - .msg_iov = iov, - .msg_iovlen = iovlen, + .msg_name = (void *) &sk->s_peer, + .msg_namelen = sizeof(struct sockaddr_nl), + .msg_iov = iov, + .msg_iovlen = iovlen, }; char buf[CMSG_SPACE(sizeof(struct ucred))]; @@ -1401,12 +1401,41 @@ nl_send_auto(struct nl_sock *sk, struct nl_msg *msg) return nl_send(sk, msg); } +/** + * nl_recv(): + * @sk: the netlink socket + * @buf0: NULL or a receive buffer of length @buf0_len + * @buf0_len: the length of the optional receive buffer. + * @nla: (out): the source address on success. + * @buf: (out): pointer to the result buffer on success. This is + * either @buf0 or an allocated buffer that gets returned. + * @out_creds: (out) (allow-none): optional out buffer for the credentials + * on success. + * @out_creds_has: (out) (allow-none): result indicating whether + * @out_creds was filled. + * + * If @buf0_len is zero, the function will g_malloc() a new receive buffer of size + * nl_socket_get_msg_buf_size(). If @buf0_len is larger than zero, then @buf0 + * is used as receive buffer. That is also the buffer returned by @buf. + * + * If NL_MSG_PEEK is not enabled and the receive buffer is too small, then + * the message was lost and -NME_NL_MSG_TRUNC gets returned. + * If NL_MSG_PEEK is enabled, then we first peek. If the buffer is too small, + * we g_malloc() a new buffer. In any case, we proceed to receive the buffer. + * NL_MSG_PEEK is great because it means no messages are lost. But it's bad, + * because we always need two syscalls on every receive. + * + * Returns: a negative error code or the length of the received message in + * @buf. + */ int -nl_recv(struct nl_sock * sk, +nl_recv(struct nl_sock *sk, + unsigned char *buf0, + size_t buf0_len, struct sockaddr_nl *nla, - unsigned char ** buf, - struct ucred * out_creds, - gboolean * out_creds_has) + unsigned char **buf, + struct ucred *out_creds, + gboolean *out_creds_has) { /* We really expect msg_contol_buf to be large enough and MSG_CTRUNC not * happening. We nm_assert() against that. However, in release builds @@ -1443,8 +1472,13 @@ nl_recv(struct nl_sock * sk, || (!(sk->s_flags & NL_MSG_PEEK_EXPLICIT) && sk->s_bufsize == 0)) flags |= MSG_PEEK | MSG_TRUNC; - iov.iov_len = sk->s_bufsize ?: (((size_t) nm_utils_getpagesize()) * 4u); - iov.iov_base = g_malloc(iov.iov_len); + if (buf0_len > 0) { + iov.iov_len = buf0_len; + iov.iov_base = buf0; + } else { + iov.iov_len = sk->s_bufsize ?: (((size_t) nm_utils_getpagesize()) * 4u); + iov.iov_base = g_malloc(iov.iov_len); + } if (out_creds && (sk->s_flags & NL_SOCK_PASSCRED)) { msg.msg_controllen = sizeof(msg_contol_buf); @@ -1482,7 +1516,7 @@ retry: /* Provided buffer is not long enough, enlarge it * to size of n (which should be total length of the message) * and try again. */ - iov.iov_base = g_realloc(iov.iov_base, n); + iov.iov_base = g_realloc(iov.iov_base != buf0 ? iov.iov_base : NULL, n); iov.iov_len = n; flags = 0; goto retry; @@ -1517,7 +1551,8 @@ retry: abort: if (retval <= 0) { - g_free(iov.iov_base); + if (iov.iov_base != buf0) + g_free(iov.iov_base); return retval; } diff --git a/src/libnm-platform/nm-netlink.h b/src/libnm-platform/nm-netlink.h index 00d817cd..bb1e41ee 100644 --- a/src/libnm-platform/nm-netlink.h +++ b/src/libnm-platform/nm-netlink.h @@ -328,9 +328,9 @@ void nla_nest_cancel(struct nl_msg *msg, const struct nlattr *attr); struct nlattr *nla_nest_start(struct nl_msg *msg, int attrtype); int nla_nest_end(struct nl_msg *msg, struct nlattr *start); -int nla_parse(struct nlattr * tb[], +int nla_parse(struct nlattr *tb[], int maxtype, - struct nlattr * head, + struct nlattr *head, int len, const struct nla_policy *policy); @@ -342,9 +342,9 @@ int nla_parse(struct nlattr * tb[], }) static inline int -nla_parse_nested(struct nlattr * tb[], +nla_parse_nested(struct nlattr *tb[], int maxtype, - struct nlattr * nla, + struct nlattr *nla, const struct nla_policy *policy) { return nla_parse(tb, maxtype, nla_data(nla), nla_len(nla), policy); @@ -468,9 +468,9 @@ nlmsg_find_attr(struct nlmsghdr *nlh, int hdrlen, int attrtype) return nla_find(nlmsg_attrdata(nlh, hdrlen), nlmsg_attrlen(nlh, hdrlen), attrtype); } -int nlmsg_parse(struct nlmsghdr * nlh, +int nlmsg_parse(struct nlmsghdr *nlh, int hdrlen, - struct nlattr * tb[], + struct nlattr *tb[], int maxtype, const struct nla_policy *policy); @@ -517,11 +517,13 @@ int nl_socket_add_memberships(struct nl_sock *sk, int group, ...); int nl_connect(struct nl_sock *sk, int protocol); -int nl_recv(struct nl_sock * sk, +int nl_recv(struct nl_sock *sk, + unsigned char *buf0, + size_t buf0_len, struct sockaddr_nl *nla, - unsigned char ** buf, - struct ucred * out_creds, - gboolean * out_creds_has); + unsigned char **buf, + struct ucred *out_creds, + gboolean *out_creds_has); int nl_send(struct nl_sock *sk, struct nl_msg *msg); @@ -544,16 +546,16 @@ typedef int (*nl_recvmsg_err_cb_t)(struct sockaddr_nl *nla, struct nlmsgerr *nle struct nl_cb { nl_recvmsg_msg_cb_t valid_cb; - void * valid_arg; + void *valid_arg; nl_recvmsg_msg_cb_t finish_cb; - void * finish_arg; + void *finish_arg; nl_recvmsg_msg_cb_t ack_cb; - void * ack_arg; + void *ack_arg; nl_recvmsg_err_cb_t err_cb; - void * err_arg; + void *err_arg; }; int nl_sendmsg(struct nl_sock *sk, struct nl_msg *msg, struct msghdr *hdr); @@ -570,7 +572,7 @@ int nl_socket_set_ext_ack(struct nl_sock *sk, gboolean enable); /*****************************************************************************/ -void * genlmsg_put(struct nl_msg *msg, +void *genlmsg_put(struct nl_msg *msg, uint32_t port, uint32_t seq, int family, @@ -578,18 +580,18 @@ void * genlmsg_put(struct nl_msg *msg, int flags, uint8_t cmd, uint8_t version); -void * genlmsg_data(const struct genlmsghdr *gnlh); -void * genlmsg_user_hdr(const struct genlmsghdr *gnlh); +void *genlmsg_data(const struct genlmsghdr *gnlh); +void *genlmsg_user_hdr(const struct genlmsghdr *gnlh); struct genlmsghdr *genlmsg_hdr(struct nlmsghdr *nlh); -void * genlmsg_user_data(const struct genlmsghdr *gnlh, const int hdrlen); -struct nlattr * genlmsg_attrdata(const struct genlmsghdr *gnlh, int hdrlen); +void *genlmsg_user_data(const struct genlmsghdr *gnlh, const int hdrlen); +struct nlattr *genlmsg_attrdata(const struct genlmsghdr *gnlh, int hdrlen); int genlmsg_len(const struct genlmsghdr *gnlh); int genlmsg_attrlen(const struct genlmsghdr *gnlh, int hdrlen); int genlmsg_valid_hdr(struct nlmsghdr *nlh, int hdrlen); -int genlmsg_parse(struct nlmsghdr * nlh, +int genlmsg_parse(struct nlmsghdr *nlh, int hdrlen, - struct nlattr * tb[], + struct nlattr *tb[], int maxtype, const struct nla_policy *policy); diff --git a/src/libnm-platform/nm-platform-private.h b/src/libnm-platform/nm-platform-private.h index cf805689..7537bb0b 100644 --- a/src/libnm-platform/nm-platform-private.h +++ b/src/libnm-platform/nm-platform-private.h @@ -21,7 +21,7 @@ NMPCache *nm_platform_get_cache(NMPlatform *self); } \ G_STMT_END -void nm_platform_cache_update_emit_signal(NMPlatform * platform, +void nm_platform_cache_update_emit_signal(NMPlatform *platform, NMPCacheOpsType cache_op, const NMPObject *obj_old, const NMPObject *obj_new); diff --git a/src/libnm-platform/nm-platform-utils.c b/src/libnm-platform/nm-platform-utils.c index f0522736..9ad030df 100644 --- a/src/libnm-platform/nm-platform-utils.c +++ b/src/libnm-platform/nm-platform-utils.c @@ -91,16 +91,16 @@ typedef enum { } IoctlCallDataType; static int -_ioctl_call(const char * log_ioctl_type, - const char * log_subtype, +_ioctl_call(const char *log_ioctl_type, + const char *log_subtype, unsigned long int ioctl_request, int ifindex, - int * inout_fd, - char * inout_ifname, + int *inout_fd, + char *inout_ifname, IoctlCallDataType edata_type, gpointer edata, gsize edata_size, - struct ifreq * out_ifreq) + struct ifreq *out_ifreq) { nm_auto_close int fd_close = -1; int fd; @@ -109,7 +109,7 @@ _ioctl_call(const char * log_ioctl_type, gs_free gpointer edata_backup_free = NULL; guint try_count; char known_ifnames[2][IFNAMSIZ]; - const char * failure_reason = NULL; + const char *failure_reason = NULL; struct ifreq ifr; nm_assert(ifindex > 0); @@ -365,7 +365,7 @@ ethtool_get_stringset(SocketHandle *shandle, int stringset_id) .info.reserved = 0, .info.sset_mask = (1ULL << stringset_id), }; - const guint32 * pdata; + const guint32 *pdata; gs_free struct ethtool_gstrings *gstrings = NULL; gsize gstrings_len; guint32 i, len; @@ -574,7 +574,7 @@ _ASSERT_ethtool_feature_infos(void) static NMEthtoolFeatureStates * ethtool_get_features(SocketHandle *shandle) { - gs_free NMEthtoolFeatureStates * states = NULL; + gs_free NMEthtoolFeatureStates *states = NULL; gs_free struct ethtool_gstrings *ss_features = NULL; _ASSERT_ethtool_feature_infos(); @@ -584,11 +584,11 @@ ethtool_get_features(SocketHandle *shandle) return NULL; if (ss_features->len > 0) { - gs_free struct ethtool_gfeatures * gfeatures_free = NULL; - struct ethtool_gfeatures * gfeatures; + gs_free struct ethtool_gfeatures *gfeatures_free = NULL; + struct ethtool_gfeatures *gfeatures; gsize gfeatures_len; guint idx; - const NMEthtoolFeatureState * states_list0 = NULL; + const NMEthtoolFeatureState *states_list0 = NULL; const NMEthtoolFeatureState *const *states_plist0 = NULL; guint states_plist_n = 0; @@ -606,7 +606,7 @@ ethtool_get_features(SocketHandle *shandle) for (idx_kernel_name = 0; idx_kernel_name < info->n_kernel_names; idx_kernel_name++) { NMEthtoolFeatureState *kstate; - const char * kernel_name = info->kernel_names[idx_kernel_name]; + const char *kernel_name = info->kernel_names[idx_kernel_name]; int i_feature; guint i_block; guint32 i_flag; @@ -667,7 +667,7 @@ NMEthtoolFeatureStates * nmp_utils_ethtool_get_features(int ifindex) { nm_auto_socket_handle SocketHandle shandle = SOCKET_HANDLE_INIT(ifindex); - NMEthtoolFeatureStates * features; + NMEthtoolFeatureStates *features; g_return_val_if_fail(ifindex > 0, 0); @@ -689,10 +689,10 @@ nmp_utils_ethtool_get_features(int ifindex) } static const char * -_ethtool_feature_state_to_string(char * buf, +_ethtool_feature_state_to_string(char *buf, gsize buf_size, const NMEthtoolFeatureState *s, - const char * prefix) + const char *prefix) { int l; @@ -718,8 +718,8 @@ nmp_utils_ethtool_set_features( gboolean do_set /* or reset */) { nm_auto_socket_handle SocketHandle shandle = SOCKET_HANDLE_INIT(ifindex); - gs_free struct ethtool_sfeatures * sfeatures_free = NULL; - struct ethtool_sfeatures * sfeatures; + gs_free struct ethtool_sfeatures *sfeatures_free = NULL; + struct ethtool_sfeatures *sfeatures; gsize sfeatures_len; int r; guint i, j; @@ -1215,8 +1215,8 @@ gboolean nmp_utils_ethtool_supports_vlans(int ifindex) { nm_auto_socket_handle SocketHandle shandle = SOCKET_HANDLE_INIT(ifindex); - gs_free struct ethtool_gfeatures * features_free = NULL; - struct ethtool_gfeatures * features; + gs_free struct ethtool_gfeatures *features_free = NULL; + struct ethtool_gfeatures *features; gsize features_len; int idx, block, bit, size; @@ -1250,8 +1250,8 @@ nmp_utils_ethtool_get_peer_ifindex(int ifindex) { nm_auto_socket_handle SocketHandle shandle = SOCKET_HANDLE_INIT(ifindex); gsize stats_len; - gs_free struct ethtool_stats * stats_free = NULL; - struct ethtool_stats * stats; + gs_free struct ethtool_stats *stats_free = NULL; + struct ethtool_stats *stats; int peer_ifindex_stat; g_return_val_if_fail(ifindex > 0, 0); @@ -1289,8 +1289,8 @@ nmp_utils_ethtool_get_wake_on_lan(int ifindex) gboolean nmp_utils_ethtool_get_link_settings(int ifindex, - gboolean * out_autoneg, - guint32 * out_speed, + gboolean *out_autoneg, + guint32 *out_speed, NMPlatformLinkDuplexType *out_duplex) { struct ethtool_cmd edata = { @@ -1474,7 +1474,7 @@ const guint32 _nmp_link_mode_all_advertised_modes[] = { }; static NMOptionBool -set_link_settings_new(SocketHandle * shandle, +set_link_settings_new(SocketHandle *shandle, gboolean autoneg, guint32 speed, NMPlatformLinkDuplexType duplex) @@ -1512,8 +1512,8 @@ set_link_settings_new(SocketHandle * shandle, { const guint32 *v_map_supported = &edata->link_mode_masks[0]; - guint32 * v_map_advertising = &edata->link_mode_masks[nwords]; - guint32 * v_map_lp_advertising = &edata->link_mode_masks[2 * nwords]; + guint32 *v_map_advertising = &edata->link_mode_masks[nwords]; + guint32 *v_map_lp_advertising = &edata->link_mode_masks[2 * nwords]; memcpy(v_map_advertising, v_map_supported, sizeof(guint32) * nwords); (void) v_map_lp_advertising; @@ -1574,7 +1574,7 @@ nmp_utils_ethtool_set_link_settings(int ifindex, { nm_auto_socket_handle SocketHandle shandle = SOCKET_HANDLE_INIT(ifindex); struct ethtool_cmd edata = { - .cmd = ETHTOOL_GSET, + .cmd = ETHTOOL_GSET, }; NMOptionBool ret; @@ -1651,7 +1651,7 @@ set_autoneg: gboolean nmp_utils_ethtool_set_wake_on_lan(int ifindex, _NMSettingWiredWakeOnLan wol, - const char * wol_password) + const char *wol_password) { struct ethtool_wolinfo wol_info = { .cmd = ETHTOOL_SWOL, @@ -1706,7 +1706,7 @@ nmp_utils_mii_supports_carrier_detect(int ifindex) nm_auto_socket_handle SocketHandle shandle = SOCKET_HANDLE_INIT(ifindex); int r; struct ifreq ifr; - struct mii_ioctl_data * mii; + struct mii_ioctl_data *mii; g_return_val_if_fail(ifindex > 0, FALSE); @@ -1757,7 +1757,7 @@ const char * nmp_utils_udev_get_driver(struct udev_device *udevice) { struct udev_device *parent = NULL, *grandparent = NULL; - const char * driver, *subsys; + const char *driver, *subsys; driver = udev_device_get_driver(udevice); if (driver) @@ -2194,10 +2194,10 @@ nmp_utils_modprobe(GError **error, gboolean suppress_error_logging, const char * { gs_unref_ptrarray GPtrArray *argv = NULL; int exit_status; - gs_free char * _log_str = NULL; + gs_free char *_log_str = NULL; #define ARGV_TO_STR(argv) \ (_log_str ? _log_str : (_log_str = g_strjoinv(" ", (char **) argv->pdata))) - GError * local = NULL; + GError *local = NULL; va_list ap; NMLogLevel llevel = suppress_error_logging ? LOGL_DEBUG : LOGL_ERR; gs_free char *std_out = NULL, *std_err = NULL; diff --git a/src/libnm-platform/nm-platform-utils.h b/src/libnm-platform/nm-platform-utils.h index 5511e8af..a9ccebb3 100644 --- a/src/libnm-platform/nm-platform-utils.h +++ b/src/libnm-platform/nm-platform-utils.h @@ -18,7 +18,7 @@ int nmp_utils_ethtool_get_peer_ifindex(int ifindex); gboolean nmp_utils_ethtool_get_wake_on_lan(int ifindex); gboolean nmp_utils_ethtool_set_wake_on_lan(int ifindex, _NMSettingWiredWakeOnLan wol, - const char * wol_password); + const char *wol_password); const char *nm_platform_link_duplex_type_to_string(NMPlatformLinkDuplexType duplex); @@ -26,8 +26,8 @@ extern const guint8 _nmp_link_mode_all_advertised_modes_bits[79]; extern const guint32 _nmp_link_mode_all_advertised_modes[3]; gboolean nmp_utils_ethtool_get_link_settings(int ifindex, - gboolean * out_autoneg, - guint32 * out_speed, + gboolean *out_autoneg, + guint32 *out_speed, NMPlatformLinkDuplexType *out_duplex); gboolean nmp_utils_ethtool_set_link_settings(int ifindex, gboolean autoneg, @@ -77,7 +77,7 @@ int nmp_utils_if_nametoindex(const char *ifname); int nmp_utils_sysctl_open_netdir(int ifindex, const char *ifname_guess, char *out_ifname); -char * nmp_utils_new_vlan_name(const char *parent_iface, guint32 vlan_id); +char *nmp_utils_new_vlan_name(const char *parent_iface, guint32 vlan_id); const char *nmp_utils_new_infiniband_name(char *name, const char *parent_name, int p_key); guint32 diff --git a/src/libnm-platform/nm-platform.c b/src/libnm-platform/nm-platform.c index 5d4ec037..b95cd95e 100644 --- a/src/libnm-platform/nm-platform.c +++ b/src/libnm-platform/nm-platform.c @@ -115,9 +115,9 @@ nmp_link_address_get_as_bytes(const NMPLinkAddress *addr) #define NMLOG_COMMON(level, name, ...) \ char __prefix[32]; \ - const char * __p_prefix = _NMLOG_PREFIX_NAME; \ + const char *__p_prefix = _NMLOG_PREFIX_NAME; \ const NMPlatform *const __self = (self); \ - const char * __name = name; \ + const char *__name = name; \ \ if (__self && NM_PLATFORM_GET_PRIVATE(__self)->log_with_ptr) { \ g_snprintf(__prefix, sizeof(__prefix), "%s[%p]", _NMLOG_PREFIX_NAME, __self); \ @@ -187,9 +187,9 @@ typedef struct _NMPlatformPrivate { guint ip4_dev_route_blacklist_check_id; guint ip4_dev_route_blacklist_gc_timeout_id; - GHashTable * ip4_dev_route_blacklist_hash; + GHashTable *ip4_dev_route_blacklist_hash; NMDedupMultiIndex *multi_idx; - NMPCache * cache; + NMPCache *cache; } NMPlatformPrivate; G_DEFINE_TYPE(NMPlatform, nm_platform, G_TYPE_OBJECT) @@ -255,7 +255,7 @@ _nm_platform_signal_id_get(NMPlatformSignalIdType signal_type) #define _CHECK_SELF_NETNS(self, klass, netns, err_val) \ nm_auto_pop_netns NMPNetns *netns = NULL; \ - NMPlatformClass * klass; \ + NMPlatformClass *klass; \ do { \ g_return_val_if_fail(NM_IS_PLATFORM(self), err_val); \ klass = NM_PLATFORM_GET_CLASS(self); \ @@ -531,14 +531,14 @@ nm_platform_sysctl_set(NMPlatform *self, * independently of how /proc/sys/kernel/sysctl_writes_strict is configured. */ void -nm_platform_sysctl_set_async(NMPlatform * self, - const char * pathid, +nm_platform_sysctl_set_async(NMPlatform *self, + const char *pathid, int dirfd, - const char * path, - const char *const * values, + const char *path, + const char *const *values, NMPlatformAsyncCallback callback, gpointer data, - GCancellable * cancellable) + GCancellable *cancellable) { _CHECK_SELF_VOID(self, klass); @@ -717,7 +717,7 @@ nm_platform_sysctl_get_int_checked(NMPlatform *self, gint64 max, gint64 fallback) { - char * value = NULL; + char *value = NULL; gint32 ret; int errsv; @@ -821,7 +821,7 @@ int nm_platform_sysctl_ip_conf_get_rp_filter_ipv4(NMPlatform *self, const char *ifname, gboolean consider_all, - gboolean * out_due_to_all) + gboolean *out_due_to_all) { int val, val_all; @@ -899,11 +899,11 @@ _link_get_all_presort(gconstpointer p_a, gconstpointer p_b, gpointer sort_by_nam GPtrArray * nm_platform_link_get_all(NMPlatform *self, gboolean sort_by_name) { - gs_unref_ptrarray GPtrArray *links = NULL; - GPtrArray * result; - guint i, nresult; + gs_unref_ptrarray GPtrArray *links = NULL; + GPtrArray *result; + guint i, nresult; gs_unref_hashtable GHashTable *unseen = NULL; - const NMPlatformLink * item; + const NMPlatformLink *item; NMPLookup lookup; _CHECK_SELF(self, klass, NULL); @@ -1077,7 +1077,7 @@ struct _nm_platform_link_get_by_address_data { }; static gboolean -_nm_platform_link_get_by_address_match_link(const NMPObject * obj, +_nm_platform_link_get_by_address_match_link(const NMPObject *obj, struct _nm_platform_link_get_by_address_data *d) { return obj->link.l_address.len == d->len && !memcmp(obj->link.l_address.data, d->data, d->len); @@ -1093,12 +1093,12 @@ _nm_platform_link_get_by_address_match_link(const NMPObject * * address. **/ const NMPlatformLink * -nm_platform_link_get_by_address(NMPlatform * self, +nm_platform_link_get_by_address(NMPlatform *self, NMLinkType link_type, gconstpointer address, size_t length) { - const NMPObject * obj; + const NMPObject *obj; struct _nm_platform_link_get_by_address_data d = { .data = address, .len = length, @@ -1125,8 +1125,8 @@ nm_platform_link_get_by_address(NMPlatform * self, } static int -_link_add_check_existing(NMPlatform * self, - const char * name, +_link_add_check_existing(NMPlatform *self, + const char *name, NMLinkType type, const NMPlatformLink **out_link) { @@ -1174,11 +1174,11 @@ _link_add_check_existing(NMPlatform * self, * Returns: the negative nm-error on failure. */ int -nm_platform_link_add(NMPlatform * self, +nm_platform_link_add(NMPlatform *self, 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, @@ -1439,13 +1439,13 @@ nm_platform_link_get_type_name(NMPlatform *self, int ifindex) } gboolean -nm_platform_link_get_udev_property(NMPlatform * self, +nm_platform_link_get_udev_property(NMPlatform *self, int ifindex, - const char * name, + const char *name, const char **out_value) { struct udev_device *udevice = NULL; - const char * uproperty; + const char *uproperty; udevice = nm_platform_link_get_udev_device(self, ifindex); if (!udevice) @@ -1717,7 +1717,7 @@ nm_platform_link_get_address(NMPlatform *self, int ifindex, size_t *length) * address. */ gboolean -nm_platform_link_get_permanent_address_ethtool(NMPlatform * self, +nm_platform_link_get_permanent_address_ethtool(NMPlatform *self, int ifindex, NMPLinkAddress *out_address) { @@ -1735,9 +1735,9 @@ nm_platform_link_get_permanent_address_ethtool(NMPlatform * self, } gboolean -nm_platform_link_get_permanent_address(NMPlatform * self, +nm_platform_link_get_permanent_address(NMPlatform *self, const NMPlatformLink *plink, - NMPLinkAddress * out_address) + NMPLinkAddress *out_address) { _CHECK_SELF(self, klass, FALSE); nm_assert(out_address); @@ -1804,13 +1804,13 @@ nm_platform_link_supports_sriov(NMPlatform *self, int ifindex) * always invoked, and asynchronously. */ void -nm_platform_link_set_sriov_params_async(NMPlatform * self, +nm_platform_link_set_sriov_params_async(NMPlatform *self, int ifindex, guint num_vfs, NMOptionBool autoprobe, NMPlatformAsyncCallback callback, gpointer callback_data, - GCancellable * cancellable) + GCancellable *cancellable) { _CHECK_SELF_VOID(self, klass); @@ -1845,7 +1845,7 @@ nm_platform_link_set_sriov_vfs(NMPlatform *self, int ifindex, const NMPlatformVF } gboolean -nm_platform_link_set_bridge_vlans(NMPlatform * self, +nm_platform_link_set_bridge_vlans(NMPlatform *self, int ifindex, gboolean on_master, const NMPlatformBridgeVlan *const *vlans) @@ -2038,9 +2038,9 @@ nm_platform_link_get_wake_on_lan(NMPlatform *self, int ifindex) gboolean nm_platform_link_get_driver_info(NMPlatform *self, 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) { _CHECK_SELF(self, klass, FALSE); @@ -2149,7 +2149,7 @@ nm_platform_link_can_assume(NMPlatform *self, int ifindex) * (but don't modify it). */ const NMPObject * -nm_platform_link_get_lnk(NMPlatform * self, +nm_platform_link_get_lnk(NMPlatform *self, int ifindex, NMLinkType link_type, const NMPlatformLink **out_link) @@ -2308,10 +2308,10 @@ static NM_UTILS_FLAGS2STR_DEFINE( NM_UTILS_FLAGS2STR(NM_PLATFORM_WIREGUARD_CHANGE_PEER_FLAG_REPLACE_ALLOWEDIPS, "remove-aips"), ); int -nm_platform_link_wireguard_change(NMPlatform * self, +nm_platform_link_wireguard_change(NMPlatform *self, int ifindex, - const NMPlatformLnkWireGuard * lnk_wireguard, - const NMPWireGuardPeer * peers, + const NMPlatformLnkWireGuard *lnk_wireguard, + const NMPWireGuardPeer *peers, const NMPlatformWireGuardChangePeerFlags *peer_flags, guint peers_len, NMPlatformWireGuardChangeFlags change_flags) @@ -2391,11 +2391,11 @@ nm_platform_link_wireguard_change(NMPlatform * self * Create a TUN or TAP interface. */ int -nm_platform_link_tun_add(NMPlatform * self, - const char * name, +nm_platform_link_tun_add(NMPlatform *self, + const char *name, const NMPlatformLnkTun *props, - const NMPlatformLink ** out_link, - int * out_fd) + const NMPlatformLink **out_link, + int *out_fd) { char b[255]; int r; @@ -2466,7 +2466,7 @@ link_set_option(NMPlatform *self, { nm_auto_close int dirfd = -1; char ifname_verified[IFNAMSIZ]; - const char * path; + const char *path; if (!category || !option) return FALSE; @@ -2487,7 +2487,7 @@ link_get_option(NMPlatform *self, int ifindex, const char *category, const char { nm_auto_close int dirfd = -1; char ifname_verified[IFNAMSIZ]; - const char * path; + const char *path; if (!category || !option) return NULL; @@ -2588,7 +2588,7 @@ nm_platform_sysctl_slave_get_option(NMPlatform *self, int ifindex, const char *o /*****************************************************************************/ gboolean -nm_platform_link_vlan_change(NMPlatform * self, +nm_platform_link_vlan_change(NMPlatform *self, int ifindex, _NMVlanFlags flags_mask, _NMVlanFlags flags_set, @@ -2680,7 +2680,7 @@ nm_platform_link_vlan_set_egress_map(NMPlatform *self, int ifindex, int from, in } static int -_infiniband_add_add_or_delete(NMPlatform * self, +_infiniband_add_add_or_delete(NMPlatform *self, int ifindex, int p_key, gboolean add, @@ -2727,7 +2727,7 @@ _infiniband_add_add_or_delete(NMPlatform * self, } int -nm_platform_link_infiniband_add(NMPlatform * self, +nm_platform_link_infiniband_add(NMPlatform *self, int parent, int p_key, const NMPlatformLink **out_link) @@ -2742,18 +2742,18 @@ nm_platform_link_infiniband_delete(NMPlatform *self, int parent, int p_key) } gboolean -nm_platform_link_infiniband_get_properties(NMPlatform * self, +nm_platform_link_infiniband_get_properties(NMPlatform *self, int ifindex, - int * out_parent, - int * out_p_key, + int *out_parent, + int *out_p_key, const char **out_mode) { nm_auto_close int dirfd = -1; char ifname_verified[IFNAMSIZ]; const NMPlatformLnkInfiniband *plnk; - const NMPlatformLink * plink; - char * contents; - const char * mode; + const NMPlatformLink *plink; + char *contents; + const char *mode; int p_key = 0; _CHECK_SELF(self, klass, FALSE); @@ -2968,11 +2968,11 @@ nm_platform_wifi_get_frequency(NMPlatform *self, int ifindex) } gboolean -nm_platform_wifi_get_station(NMPlatform * self, +nm_platform_wifi_get_station(NMPlatform *self, int ifindex, NMEtherAddr *out_bssid, - int * out_quality, - guint32 * out_rate) + int *out_quality, + guint32 *out_rate) { _CHECK_SELF(self, klass, FALSE); @@ -3143,11 +3143,12 @@ nm_platform_wpan_set_channel(NMPlatform *self, int ifindex, guint8 page, guint8 static const char * _to_string_dev(NMPlatform *self, int ifindex, char *buf, size_t size) { - g_assert(buf && size >= TO_STRING_DEV_BUF_SIZE); + nm_assert(buf); + nm_assert(size >= TO_STRING_DEV_BUF_SIZE); if (ifindex) { const char *name = ifindex > 0 && self ? nm_platform_link_get_name(self, ifindex) : NULL; - char * buf2; + char *buf2; strcpy(buf, " dev "); buf2 = buf + 5; @@ -3188,10 +3189,10 @@ _to_string_ifa_flags(guint32 ifa_flags, char *buf, gsize size) /*****************************************************************************/ gboolean -nm_platform_ethtool_set_wake_on_lan(NMPlatform * self, +nm_platform_ethtool_set_wake_on_lan(NMPlatform *self, int ifindex, _NMSettingWiredWakeOnLan wol, - const char * wol_password) + const char *wol_password) { _CHECK_SELF_NETNS(self, klass, netns, FALSE); @@ -3201,7 +3202,7 @@ nm_platform_ethtool_set_wake_on_lan(NMPlatform * self, } gboolean -nm_platform_ethtool_set_link_settings(NMPlatform * self, +nm_platform_ethtool_set_link_settings(NMPlatform *self, int ifindex, gboolean autoneg, guint32 speed, @@ -3215,10 +3216,10 @@ nm_platform_ethtool_set_link_settings(NMPlatform * self, } gboolean -nm_platform_ethtool_get_link_settings(NMPlatform * self, +nm_platform_ethtool_get_link_settings(NMPlatform *self, int ifindex, - gboolean * out_autoneg, - guint32 * out_speed, + gboolean *out_autoneg, + guint32 *out_speed, NMPlatformLinkDuplexType *out_duplex) { _CHECK_SELF_NETNS(self, klass, netns, FALSE); @@ -3242,7 +3243,7 @@ nm_platform_ethtool_get_link_features(NMPlatform *self, int ifindex) gboolean nm_platform_ethtool_set_features( - NMPlatform * self, + NMPlatform *self, int ifindex, const NMEthtoolFeatureStates *features, const NMOptionBool *requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */, @@ -3256,7 +3257,7 @@ nm_platform_ethtool_set_features( } gboolean -nm_platform_ethtool_get_link_coalesce(NMPlatform * self, +nm_platform_ethtool_get_link_coalesce(NMPlatform *self, int ifindex, NMEthtoolCoalesceState *coalesce) { @@ -3269,7 +3270,7 @@ nm_platform_ethtool_get_link_coalesce(NMPlatform * self, } gboolean -nm_platform_ethtool_set_coalesce(NMPlatform * self, +nm_platform_ethtool_set_coalesce(NMPlatform *self, int ifindex, const NMEthtoolCoalesceState *coalesce) { @@ -3380,8 +3381,8 @@ nm_platform_lookup_predicate_routes_main_skip_rtprot_kernel(const NMPObject *obj * Returns: the result of the lookup. */ GPtrArray * -nm_platform_lookup_clone(NMPlatform * self, - const NMPLookup * lookup, +nm_platform_lookup_clone(NMPlatform *self, + const NMPLookup *lookup, NMPObjectPredicateFunc predicate, gpointer user_data) { @@ -3511,7 +3512,7 @@ nm_platform_ip4_address_add(NMPlatform *self, } gboolean -nm_platform_ip6_address_add(NMPlatform * self, +nm_platform_ip6_address_add(NMPlatform *self, int ifindex, struct in6_addr address, guint8 plen, @@ -3630,7 +3631,7 @@ nm_platform_ip6_address_get(NMPlatform *self, int ifindex, const struct in6_addr static gboolean _addr_array_clean_expired(int addr_family, int ifindex, - GPtrArray * array, + GPtrArray *array, guint32 now, GHashTable **idx) { @@ -3748,7 +3749,7 @@ ip4_addr_subnets_build_index(const GPtrArray *addresses, for (i = 0; i < addresses->len; i++) { const NMPlatformIP4Address *address; gpointer p_address; - GPtrArray * addr_list; + GPtrArray *addr_list; guint32 net; int position; gpointer p; @@ -3805,16 +3806,16 @@ ip4_addr_subnets_build_index(const GPtrArray *addresses, * Returns: %TRUE if the address is secondary, %FALSE otherwise */ static gboolean -ip4_addr_subnets_is_secondary(const NMPObject * address, - GHashTable * subnets, - const GPtrArray * addresses, +ip4_addr_subnets_is_secondary(const NMPObject *address, + GHashTable *subnets, + const GPtrArray *addresses, const GPtrArray **out_addr_list) { const NMPlatformIP4Address *a; - const GPtrArray * addr_list; + const GPtrArray *addr_list; gconstpointer p; guint32 net; - const NMPObject ** o; + const NMPObject **o; a = NMP_OBJECT_CAST_IP4_ADDRESS(address); @@ -3902,14 +3903,14 @@ gboolean nm_platform_ip_address_sync(NMPlatform *self, int addr_family, int ifindex, - GPtrArray * known_addresses, - GPtrArray * addresses_prune) + GPtrArray *known_addresses, + GPtrArray *addresses_prune) { - const gint32 now = nm_utils_get_monotonic_timestamp_sec(); - const int IS_IPv4 = NM_IS_IPv4(addr_family); + const gint32 now = nm_utils_get_monotonic_timestamp_sec(); + const int IS_IPv4 = NM_IS_IPv4(addr_family); gs_unref_hashtable GHashTable *known_addresses_idx = NULL; - GPtrArray * plat_addresses; - GHashTable * known_subnets = NULL; + GPtrArray *plat_addresses; + GHashTable *known_subnets = NULL; guint i_plat; guint i_know; guint i; @@ -3947,9 +3948,9 @@ nm_platform_ip_address_sync(NMPlatform *self, plat_subnets = ip4_addr_subnets_build_index(plat_addresses, TRUE, TRUE); for (i = 0; i < plat_addresses->len; i++) { - const NMPObject * plat_obj; + const NMPObject *plat_obj; const NMPlatformIP4Address *plat_address; - const GPtrArray * addr_list; + const GPtrArray *addr_list; plat_obj = plat_addresses->pdata[i]; if (!plat_obj) { @@ -4044,8 +4045,8 @@ nm_platform_ip_address_sync(NMPlatform *self, * * Note that we mark handled addresses by setting it to %NULL in @plat_addresses array. */ for (i_plat = 0; i_plat < plat_addresses->len; i_plat++) { - const NMPObject * plat_obj = plat_addresses->pdata[i_plat]; - const NMPObject * know_obj; + const NMPObject *plat_obj = plat_addresses->pdata[i_plat]; + const NMPObject *know_obj; const NMPlatformIP6Address *plat_addr = NMP_OBJECT_CAST_IP6_ADDRESS(plat_obj); if (known_addresses_idx) { @@ -4141,7 +4142,7 @@ next_plat:; */ for (i_know = 0; i_know < known_addresses->len; i_know++) { const NMPlatformIPXAddress *known_address; - const NMPObject * o; + const NMPObject *o; guint32 lifetime; guint32 preferred; @@ -4211,7 +4212,7 @@ nm_platform_ip_address_flush(NMPlatform *self, int addr_family, int ifindex) static gboolean _err_inval_due_to_ipv6_tentative_pref_src(NMPlatform *self, const NMPObject *obj) { - const NMPlatformIP6Route * r; + const NMPlatformIP6Route *r; const NMPlatformIP6Address *a; nm_assert(NM_IS_PLATFORM(self)); @@ -4253,8 +4254,8 @@ nm_platform_ip_address_get_prune_list(NMPlatform *self, const int IS_IPv4 = NM_IS_IPv4(addr_family); const NMDedupMultiHeadEntry *head_entry; NMPLookup lookup; - GPtrArray * result; - CList * iter; + GPtrArray *result; + CList *iter; nmp_lookup_init_object(&lookup, NMP_OBJECT_TYPE_IP_ADDRESS(NM_IS_IPv4(addr_family)), ifindex); @@ -4285,20 +4286,20 @@ nm_platform_ip_address_get_prune_list(NMPlatform *self, } GPtrArray * -nm_platform_ip_route_get_prune_list(NMPlatform * self, +nm_platform_ip_route_get_prune_list(NMPlatform *self, int addr_family, int ifindex, NMIPRouteTableSyncMode route_table_sync) { NMPLookup lookup; - GPtrArray * routes_prune; + GPtrArray *routes_prune; const NMDedupMultiHeadEntry *head_entry; - CList * iter; + CList *iter; NMPlatformIP4Route rt_local4; NMPlatformIP6Route rt_local6; NMPlatformIP6Route rt_mcast6; - const NMPlatformLink * pllink; - const NMPlatformLnkVrf * lnk_vrf; + const NMPlatformLink *pllink; + const NMPlatformLnkVrf *lnk_vrf; guint32 local_table; nm_assert(NM_IS_PLATFORM(self)); @@ -4326,7 +4327,7 @@ nm_platform_ip_route_get_prune_list(NMPlatform * self, routes_prune = g_ptr_array_new_full(head_entry->len, (GDestroyNotify) nm_dedup_multi_obj_unref); c_list_for_each (iter, &head_entry->lst_entries_head) { - const NMPObject * obj = c_list_entry(iter, NMDedupMultiEntry, lst_entries)->obj; + const NMPObject *obj = c_list_entry(iter, NMDedupMultiEntry, lst_entries)->obj; const NMPlatformIPXRoute *rt = NMP_OBJECT_CAST_IPX_ROUTE(obj); switch (route_table_sync) { @@ -4493,15 +4494,15 @@ gboolean nm_platform_ip_route_sync(NMPlatform *self, int addr_family, int ifindex, - GPtrArray * routes, - GPtrArray * routes_prune, + GPtrArray *routes, + GPtrArray *routes_prune, GPtrArray **out_temporary_not_available) { - const int IS_IPv4 = NM_IS_IPv4(addr_family); - const NMPlatformVTableRoute *vt; + const int IS_IPv4 = NM_IS_IPv4(addr_family); + const NMPlatformVTableRoute *vt; gs_unref_hashtable GHashTable *routes_idx = NULL; - const NMPObject * conf_o; - const NMDedupMultiEntry * plat_entry; + const NMPObject *conf_o; + const NMDedupMultiEntry *plat_entry; guint i; int i_type; gboolean success = TRUE; @@ -4520,12 +4521,6 @@ nm_platform_ip_route_sync(NMPlatform *self, conf_o = routes->pdata[i]; - if (NMP_OBJECT_CAST_IP_ROUTE(conf_o)->is_external) { - /* This route is added externally. We don't have our own agenda to - * add it, so skip. */ - continue; - } - /* User space cannot add IPv6 routes with metric 0. However, kernel can, and we might track such * routes in @route as they are present external. As we already skipped external routes above, * we don't expect a user's choice to add such a route (it won't work anyway). */ @@ -4721,24 +4716,6 @@ sync_route_add: } if (routes_prune) { - if (routes) { - for (i = 0; i < routes->len; i++) { - conf_o = routes->pdata[i]; - - if (NMP_OBJECT_CAST_IP_ROUTE(conf_o)->is_external) { - /* this is only to catch the case where an external route is - * both in @routes and @routes_prune list. In that case, - * @routes should win and we should not remove the address. */ - if (!routes_idx) { - routes_idx = g_hash_table_new((GHashFunc) nmp_object_id_hash, - (GEqualFunc) nmp_object_id_equal); - } - g_hash_table_add(routes_idx, (gpointer) conf_o); - continue; - } - } - } - for (i = 0; i < routes_prune->len; i++) { const NMPObject *prune_o; @@ -4958,11 +4935,11 @@ nm_platform_object_delete(NMPlatform *self, const NMPObject *obj) /*****************************************************************************/ int -nm_platform_ip_route_get(NMPlatform * self, +nm_platform_ip_route_get(NMPlatform *self, int addr_family, gconstpointer address /* in_addr_t or struct in6_addr */, int oif_ifindex, - NMPObject ** out_route) + NMPObject **out_route) { nm_auto_nmpobj NMPObject *route = NULL; int result; @@ -5027,11 +5004,11 @@ _ip4_dev_route_blacklist_timeout_ms_marked(gint64 timeout_msec) static gboolean _ip4_dev_route_blacklist_check_cb(gpointer user_data) { - NMPlatform * self = user_data; + NMPlatform *self = user_data; NMPlatformPrivate *priv = NM_PLATFORM_GET_PRIVATE(self); GHashTableIter iter; - const NMPObject * p_obj; - gint64 * p_timeout_ms; + const NMPObject *p_obj; + gint64 *p_timeout_ms; gint64 now_ms; priv->ip4_dev_route_blacklist_check_id = 0; @@ -5081,8 +5058,8 @@ static void _ip4_dev_route_blacklist_notify_route(NMPlatform *self, const NMPObject *obj) { NMPlatformPrivate *priv; - const NMPObject * p_obj; - gint64 * p_timeout_ms; + const NMPObject *p_obj; + gint64 *p_timeout_ms; gint64 now_ms; nm_assert(NM_IS_PLATFORM(self)); @@ -5120,11 +5097,11 @@ _ip4_dev_route_blacklist_notify_route(NMPlatform *self, const NMPObject *obj) static gboolean _ip4_dev_route_blacklist_gc_timeout_handle(gpointer user_data) { - NMPlatform * self = user_data; + NMPlatform *self = user_data; NMPlatformPrivate *priv = NM_PLATFORM_GET_PRIVATE(self); GHashTableIter iter; - const NMPObject * p_obj; - gint64 * p_timeout_ms; + const NMPObject *p_obj; + gint64 *p_timeout_ms; gint64 now_ms; nm_assert(priv->ip4_dev_route_blacklist_gc_timeout_id); @@ -5193,15 +5170,15 @@ _ip4_dev_route_blacklist_schedule(NMPlatform *self) void nm_platform_ip4_dev_route_blacklist_set(NMPlatform *self, int ifindex, - GPtrArray * ip4_dev_route_blacklist) + GPtrArray *ip4_dev_route_blacklist) { NMPlatformPrivate *priv; GHashTableIter iter; - const NMPObject * p_obj; + const NMPObject *p_obj; guint i; gint64 timeout_msec; gint64 timeout_msec_val; - gint64 * p_timeout_ms; + gint64 *p_timeout_ms; gboolean needs_check = FALSE; nm_assert(NM_IS_PLATFORM(self)); @@ -5275,7 +5252,7 @@ nm_platform_ip4_dev_route_blacklist_set(NMPlatform *self, /*****************************************************************************/ int -nm_platform_routing_rule_add(NMPlatform * self, +nm_platform_routing_rule_add(NMPlatform *self, NMPNlmFlags flags, const NMPlatformRoutingRule *routing_rule) { @@ -5355,8 +5332,8 @@ nm_platform_tfilter_delete(NMPlatform *self, int ifindex, guint32 parent, gboole gboolean nm_platform_tc_sync(NMPlatform *self, int ifindex, - GPtrArray * known_qdiscs, - GPtrArray * known_tfilters) + GPtrArray *known_qdiscs, + GPtrArray *known_tfilters) { guint i; gboolean success = TRUE; @@ -5397,10 +5374,10 @@ nm_platform_tc_sync(NMPlatform *self, /*****************************************************************************/ const char * -nm_platform_vlan_qos_mapping_to_string(const char * name, +nm_platform_vlan_qos_mapping_to_string(const char *name, const NMVlanQosMapping *map, gsize n_map, - char * buf, + char *buf, gsize len) { gsize i; @@ -5448,7 +5425,7 @@ _lifetime_summary_to_string(gint32 now, guint32 timestamp, guint32 preferred, guint32 lifetime, - char * buf, + char *buf, size_t buf_size) { g_snprintf(buf, @@ -5478,7 +5455,7 @@ nm_platform_link_to_string(const NMPlatformLink *link, char *buf, gsize len) char parent[20]; char str_flags[1 + NM_PLATFORM_LINK_FLAGS2STR_MAX_LEN + 1]; char str_highlighted_flags[50]; - char * s; + char *s; gsize l; char str_addrmode[30]; char str_address[_NM_UTILS_HWADDR_LEN_MAX * 3]; @@ -6109,7 +6086,7 @@ nm_platform_lnk_vxlan_to_string(const NMPlatformLnkVxlan *lnk, char *buf, gsize const char * nm_platform_wireguard_peer_to_string(const NMPWireGuardPeer *peer, char *buf, gsize len) { - char * buf0 = buf; + char *buf0 = buf; gs_free char *public_key_b64 = NULL; char s_sockaddr[NM_UTILS_INET_ADDRSTRLEN + 100]; char s_endpoint[20 + sizeof(s_sockaddr)]; @@ -6214,7 +6191,7 @@ nm_platform_ip4_address_to_string(const NMPlatformIP4Address *address, char *buf char str_dev[TO_STRING_DEV_BUF_SIZE]; char str_label[32]; char str_lft[30], str_pref[30], str_time[50], s_source[50]; - char * str_peer = NULL; + char *str_peer = NULL; const char *str_lft_p, *str_pref_p, *str_time_p; gint32 now = nm_utils_get_monotonic_timestamp_sec(); in_addr_t broadcast_address; @@ -6273,9 +6250,9 @@ nm_platform_ip4_address_to_string(const NMPlatformIP4Address *address, char *buf "%s" /* flags */ "%s" /* label */ " src %s" - "%s" /* external */ "%s" /* a_acd_not_ready */ "%s" /* a_assume_config_once */ + "%s" /* a_force_commit */ "", s_address, address->plen, @@ -6293,9 +6270,9 @@ nm_platform_ip4_address_to_string(const NMPlatformIP4Address *address, char *buf _to_string_ifa_flags(address->n_ifa_flags, s_flags, sizeof(s_flags)), str_label, nmp_utils_ip_config_source_to_string(address->addr_source, s_source, sizeof(s_source)), - address->external ? " ext" : "", address->a_acd_not_ready ? " ip4acd-not-ready" : "", - address->a_assume_config_once ? " assume-config-once" : ""); + address->a_assume_config_once ? " assume-config-once" : "", + address->a_force_commit ? " force-commit" : ""); g_free(str_peer); return buf; } @@ -6374,7 +6351,7 @@ nm_platform_ip6_address_to_string(const NMPlatformIP6Address *address, char *buf char s_peer[INET6_ADDRSTRLEN]; char str_lft[30], str_pref[30], str_time[50], s_source[50]; char str_dev[TO_STRING_DEV_BUF_SIZE]; - char * str_peer = NULL; + char *str_peer = NULL; const char *str_lft_p, *str_pref_p, *str_time_p; gint32 now = nm_utils_get_monotonic_timestamp_sec(); @@ -6415,8 +6392,8 @@ nm_platform_ip6_address_to_string(const NMPlatformIP6Address *address, char *buf buf, len, "%s/%d lft %s pref %s%s%s%s%s src %s" - "%s" /* external */ "%s" /* a_assume_config_once */ + "%s" /* a_force_commit */ "", s_address, address->plen, @@ -6427,8 +6404,8 @@ nm_platform_ip6_address_to_string(const NMPlatformIP6Address *address, char *buf str_dev, _to_string_ifa_flags(address->n_ifa_flags, s_flags, sizeof(s_flags)), nmp_utils_ip_config_source_to_string(address->addr_source, s_source, sizeof(s_source)), - address->external ? " external" : "", - address->a_assume_config_once ? " assume-config-once" : ""); + address->a_assume_config_once ? " assume-config-once" : "", + address->a_force_commit ? " force-commit" : ""); g_free(str_peer); return buf; } @@ -6482,12 +6459,19 @@ _rtm_flags_to_string_full(char *buf, gsize buf_size, unsigned rtm_flags) const char * nm_platform_ip4_route_to_string(const NMPlatformIP4Route *route, char *buf, gsize len) { - char s_network[INET_ADDRSTRLEN], s_gateway[INET_ADDRSTRLEN]; + char s_network[INET_ADDRSTRLEN]; + char s_gateway[INET_ADDRSTRLEN]; char s_pref_src[INET_ADDRSTRLEN]; char str_dev[TO_STRING_DEV_BUF_SIZE]; char str_table[30]; - char str_scope[30], s_source[50]; - char str_tos[32], str_window[32], str_cwnd[32], str_initcwnd[32], str_initrwnd[32], str_mtu[32]; + char str_scope[30]; + char s_source[50]; + char str_tos[32]; + char str_window[32]; + char str_cwnd[32]; + char str_initcwnd[32]; + char str_initrwnd[32]; + char str_mtu[32]; char str_rtm_flags[_RTM_FLAGS_TO_STRING_MAXLEN]; char str_type[30]; char str_metric[30]; @@ -6496,7 +6480,11 @@ nm_platform_ip4_route_to_string(const NMPlatformIP4Route *route, char *buf, gsiz return buf; inet_ntop(AF_INET, &route->network, s_network, sizeof(s_network)); - inet_ntop(AF_INET, &route->gateway, s_gateway, sizeof(s_gateway)); + + if (route->gateway == 0) + s_gateway[0] = '\0'; + else + inet_ntop(AF_INET, &route->gateway, s_gateway, sizeof(s_gateway)); _to_string_dev(NULL, route->ifindex, str_dev, sizeof(str_dev)); @@ -6506,21 +6494,22 @@ nm_platform_ip4_route_to_string(const NMPlatformIP4Route *route, char *buf, gsiz "type %s " /* type */ "%s" /* table */ "%s/%d" - " via %s" + "%s%s" /* gateway */ "%s" " metric %s" - " mss %" G_GUINT32_FORMAT " rt-src %s" /* protocol */ - "%s" /* rtm_flags */ - "%s%s" /* scope */ - "%s%s" /* pref-src */ - "%s" /* tos */ - "%s" /* window */ - "%s" /* cwnd */ - "%s" /* initcwnd */ - "%s" /* initrwnd */ - "%s" /* mtu */ - "%s" /* is_external */ - "%s" /* r_assume_config_once */ + " mss %" G_GUINT32_FORMAT /* mss */ + " rt-src %s" /* protocol */ + "%s" /* rtm_flags */ + "%s%s" /* scope */ + "%s%s" /* pref-src */ + "%s" /* tos */ + "%s" /* window */ + "%s" /* cwnd */ + "%s" /* initcwnd */ + "%s" /* initrwnd */ + "%s" /* mtu */ + "%s" /* r_assume_config_once */ + "%s" /* r_force_commit */ "", nm_net_aux_rtnl_rtntype_n2a_maybe_buf(nm_platform_route_type_uncoerce(route->type_coerced), str_type), @@ -6533,6 +6522,7 @@ nm_platform_ip4_route_to_string(const NMPlatformIP4Route *route, char *buf, gsiz : ""), s_network, route->plen, + s_gateway[0] ? " via " : "", s_gateway, str_dev, route->metric_any @@ -6577,8 +6567,8 @@ nm_platform_ip4_route_to_string(const NMPlatformIP4Route *route, char *buf, gsiz route->lock_mtu ? "lock " : "", route->mtu) : "", - route->is_external ? " is-external" : "", - route->r_assume_config_once ? " assume-config-once" : ""); + route->r_assume_config_once ? " assume-config-once" : "", + route->r_force_commit ? " force-commit" : ""); return buf; } @@ -6620,7 +6610,11 @@ nm_platform_ip6_route_to_string(const NMPlatformIP6Route *route, char *buf, gsiz return buf; inet_ntop(AF_INET6, &route->network, s_network, sizeof(s_network)); - inet_ntop(AF_INET6, &route->gateway, s_gateway, sizeof(s_gateway)); + + if (IN6_IS_ADDR_UNSPECIFIED(&route->gateway)) + s_gateway[0] = '\0'; + else + inet_ntop(AF_INET6, &route->gateway, s_gateway, sizeof(s_gateway)); if (IN6_IS_ADDR_UNSPECIFIED(&route->pref_src)) s_pref_src[0] = 0; @@ -6635,21 +6629,22 @@ nm_platform_ip6_route_to_string(const NMPlatformIP6Route *route, char *buf, gsiz "type %s " /* type */ "%s" /* table */ "%s/%d" - " via %s" + "%s%s" /* gateway */ "%s" " metric %s" - " mss %" G_GUINT32_FORMAT " rt-src %s" /* protocol */ - "%s" /* source */ - "%s" /* rtm_flags */ - "%s%s" /* pref-src */ - "%s" /* window */ - "%s" /* cwnd */ - "%s" /* initcwnd */ - "%s" /* initrwnd */ - "%s" /* mtu */ - "%s" /* pref */ - "%s" /* is_external */ - "%s" /* r_assume_config_once */ + " mss %" G_GUINT32_FORMAT /* mss */ + " rt-src %s" /* protocol */ + "%s" /* source */ + "%s" /* rtm_flags */ + "%s%s" /* pref-src */ + "%s" /* window */ + "%s" /* cwnd */ + "%s" /* initcwnd */ + "%s" /* initrwnd */ + "%s" /* mtu */ + "%s" /* pref */ + "%s" /* r_assume_config_once */ + "%s" /* r_force_commit */ "", nm_net_aux_rtnl_rtntype_n2a_maybe_buf(nm_platform_route_type_uncoerce(route->type_coerced), str_type), @@ -6662,6 +6657,7 @@ nm_platform_ip6_route_to_string(const NMPlatformIP6Route *route, char *buf, gsiz : ""), s_network, route->plen, + s_gateway[0] ? " via " : "", s_gateway, str_dev, route->metric_any @@ -6710,15 +6706,15 @@ nm_platform_ip6_route_to_string(const NMPlatformIP6Route *route, char *buf, gsiz " pref %s", nm_icmpv6_router_pref_to_string(route->rt_pref, str_pref2, sizeof(str_pref2))) : "", - route->is_external ? " is-external" : "", - route->r_assume_config_once ? " assume-config-once" : ""); + route->r_assume_config_once ? " assume-config-once" : "", + route->r_force_commit ? " force-commit" : ""); return buf; } static void -_routing_rule_addr_to_string(char ** buf, - gsize * len, +_routing_rule_addr_to_string(char **buf, + gsize *len, int addr_family, const NMIPAddr *addr, guint8 plen, @@ -6752,10 +6748,10 @@ _routing_rule_addr_to_string(char ** buf, } static void -_routing_rule_port_range_to_string(char ** buf, - gsize * len, +_routing_rule_port_range_to_string(char **buf, + gsize *len, const NMFibRulePortRange *port_range, - const char * name) + const char *name) { if (port_range->start == 0 && port_range->end == 0) nm_strbuf_append_str(buf, len, ""); @@ -7179,11 +7175,11 @@ nm_platform_tfilter_cmp(const NMPlatformTfilter *a, const NMPlatformTfilter *b) const char * nm_platform_vf_to_string(const NMPlatformVF *vf, char *buf, gsize len) { - char str_mac[128], mac[128]; - char str_spoof_check[64]; - char str_trust[64]; - char str_min_tx_rate[64]; - char str_max_tx_rate[64]; + char str_mac[128], mac[128]; + char str_spoof_check[64]; + char str_trust[64]; + char str_min_tx_rate[64]; + char str_max_tx_rate[64]; nm_auto_free_gstring GString *gstr_vlans = NULL; guint i; @@ -7845,10 +7841,10 @@ nm_platform_ip4_address_hash_update(const NMPlatformIP4Address *obj, NMHashState obj->address, obj->peer_address, NM_HASH_COMBINE_BOOLS(guint8, - obj->external, obj->use_ip4_broadcast_address, obj->a_acd_not_ready, - obj->a_assume_config_once)); + obj->a_assume_config_once, + obj->a_force_commit)); nm_hash_update_strarr(h, obj->label); } @@ -7869,26 +7865,27 @@ nm_platform_ip4_address_cmp(const NMPlatformIP4Address *a, const NMPlatformIP4Ad NM_CMP_FIELD(a, b, preferred); NM_CMP_FIELD(a, b, n_ifa_flags); NM_CMP_FIELD_STR(a, b, label); - NM_CMP_FIELD_UNSAFE(a, b, external); NM_CMP_FIELD_UNSAFE(a, b, a_acd_not_ready); NM_CMP_FIELD_UNSAFE(a, b, a_assume_config_once); + NM_CMP_FIELD_UNSAFE(a, b, a_force_commit); return 0; } void nm_platform_ip6_address_hash_update(const NMPlatformIP6Address *obj, NMHashState *h) { - nm_hash_update_vals(h, - obj->ifindex, - obj->addr_source, - obj->timestamp, - obj->lifetime, - obj->preferred, - obj->n_ifa_flags, - obj->plen, - obj->address, - obj->peer_address, - NM_HASH_COMBINE_BOOLS(guint8, obj->external, obj->a_assume_config_once)); + nm_hash_update_vals( + h, + obj->ifindex, + obj->addr_source, + obj->timestamp, + obj->lifetime, + obj->preferred, + obj->n_ifa_flags, + obj->plen, + obj->address, + obj->peer_address, + NM_HASH_COMBINE_BOOLS(guint8, obj->a_assume_config_once, obj->a_force_commit)); } int @@ -7908,15 +7905,15 @@ nm_platform_ip6_address_cmp(const NMPlatformIP6Address *a, const NMPlatformIP6Ad NM_CMP_FIELD(a, b, lifetime); NM_CMP_FIELD(a, b, preferred); NM_CMP_FIELD(a, b, n_ifa_flags); - NM_CMP_FIELD_UNSAFE(a, b, external); NM_CMP_FIELD_UNSAFE(a, b, a_assume_config_once); + NM_CMP_FIELD_UNSAFE(a, b, a_force_commit); return 0; } void nm_platform_ip4_route_hash_update(const NMPlatformIP4Route *obj, NMPlatformIPRouteCmpType cmp_type, - NMHashState * h) + NMHashState *h) { switch (cmp_type) { case NM_PLATFORM_IP_ROUTE_CMP_TYPE_WEAK_ID: @@ -8018,8 +8015,8 @@ nm_platform_ip4_route_hash_update(const NMPlatformIP4Route *obj, obj->lock_initcwnd, obj->lock_initrwnd, obj->lock_mtu, - obj->is_external, - obj->r_assume_config_once)); + obj->r_assume_config_once, + obj->r_force_commit)); break; } } @@ -8110,8 +8107,8 @@ nm_platform_ip4_route_cmp(const NMPlatformIP4Route *a, NM_CMP_FIELD(a, b, initrwnd); NM_CMP_FIELD(a, b, mtu); if (cmp_type == NM_PLATFORM_IP_ROUTE_CMP_TYPE_FULL) { - NM_CMP_FIELD_UNSAFE(a, b, is_external); NM_CMP_FIELD_UNSAFE(a, b, r_assume_config_once); + NM_CMP_FIELD_UNSAFE(a, b, r_force_commit); } break; } @@ -8121,7 +8118,7 @@ nm_platform_ip4_route_cmp(const NMPlatformIP4Route *a, void nm_platform_ip6_route_hash_update(const NMPlatformIP6Route *obj, NMPlatformIPRouteCmpType cmp_type, - NMHashState * h) + NMHashState *h) { struct in6_addr a1, a2; @@ -8205,8 +8202,8 @@ nm_platform_ip6_route_hash_update(const NMPlatformIP6Route *obj, obj->lock_initcwnd, obj->lock_initrwnd, obj->lock_mtu, - obj->is_external, - obj->r_assume_config_once), + obj->r_assume_config_once, + obj->r_force_commit), obj->window, obj->cwnd, obj->initcwnd, @@ -8290,8 +8287,8 @@ nm_platform_ip6_route_cmp(const NMPlatformIP6Route *a, else NM_CMP_FIELD(a, b, rt_pref); if (cmp_type == NM_PLATFORM_IP_ROUTE_CMP_TYPE_FULL) { - NM_CMP_FIELD_UNSAFE(a, b, is_external); NM_CMP_FIELD_UNSAFE(a, b, r_assume_config_once); + NM_CMP_FIELD_UNSAFE(a, b, r_force_commit); } break; } @@ -8308,7 +8305,7 @@ nm_platform_ip6_route_cmp(const NMPlatformIP6Route *a, void nm_platform_routing_rule_hash_update(const NMPlatformRoutingRule *obj, NMPlatformRoutingRuleCmpType cmp_type, - NMHashState * h) + NMHashState *h) { gboolean cmp_full = TRUE; gsize addr_size; @@ -8551,9 +8548,9 @@ nm_platform_ip4_address_addr_to_hash(NMPlatform *self, int ifindex) { const NMDedupMultiHeadEntry *head_entry; NMDedupMultiIter iter; - const NMPObject * obj; + const NMPObject *obj; NMPLookup lookup; - GHashTable * hash; + GHashTable *hash; g_return_val_if_fail(NM_IS_PLATFORM(self), NULL); g_return_val_if_fail(ifindex > 0, NULL); @@ -8583,7 +8580,8 @@ nm_platform_ip4_address_generate_device_route(const NMPlatformIP4Address *addr, int ifindex, guint32 route_table, guint32 route_metric, - NMPlatformIP4Route * dst) + gboolean force_commit, + NMPlatformIP4Route *dst) { in_addr_t network_4; @@ -8614,14 +8612,15 @@ nm_platform_ip4_address_generate_device_route(const NMPlatformIP4Address *addr, } *dst = (NMPlatformIP4Route){ - .ifindex = ifindex, - .rt_source = NM_IP_CONFIG_SOURCE_KERNEL, - .network = network_4, - .plen = addr->plen, - .pref_src = addr->address, - .table_coerced = nm_platform_route_table_coerce(route_table), - .metric = route_metric, - .scope_inv = nm_platform_route_scope_inv(NM_RT_SCOPE_LINK), + .ifindex = ifindex, + .rt_source = NM_IP_CONFIG_SOURCE_KERNEL, + .network = network_4, + .plen = addr->plen, + .pref_src = addr->address, + .table_coerced = nm_platform_route_table_coerce(route_table), + .metric = route_metric, + .scope_inv = nm_platform_route_scope_inv(NM_RT_SCOPE_LINK), + .r_force_commit = force_commit, }; nm_platform_ip_route_normalize(AF_INET, (NMPlatformIPRoute *) dst); @@ -8645,10 +8644,10 @@ nm_platform_signal_change_type_to_string(NMPlatformSignalChangeType change_type) } static void -log_link(NMPlatform * self, +log_link(NMPlatform *self, NMPObjectType obj_type, int ifindex, - NMPlatformLink * device, + NMPlatformLink *device, NMPlatformSignalChangeType change_type, gpointer user_data) { @@ -8658,10 +8657,10 @@ log_link(NMPlatform * self, } static void -log_ip4_address(NMPlatform * self, +log_ip4_address(NMPlatform *self, NMPObjectType obj_type, int ifindex, - NMPlatformIP4Address * address, + NMPlatformIP4Address *address, NMPlatformSignalChangeType change_type, gpointer user_data) { @@ -8671,10 +8670,10 @@ log_ip4_address(NMPlatform * self, } static void -log_ip6_address(NMPlatform * self, +log_ip6_address(NMPlatform *self, NMPObjectType obj_type, int ifindex, - NMPlatformIP6Address * address, + NMPlatformIP6Address *address, NMPlatformSignalChangeType change_type, gpointer user_data) { @@ -8684,10 +8683,10 @@ log_ip6_address(NMPlatform * self, } static void -log_ip4_route(NMPlatform * self, +log_ip4_route(NMPlatform *self, NMPObjectType obj_type, int ifindex, - NMPlatformIP4Route * route, + NMPlatformIP4Route *route, NMPlatformSignalChangeType change_type, gpointer user_data) { @@ -8697,10 +8696,10 @@ log_ip4_route(NMPlatform * self, } static void -log_ip6_route(NMPlatform * self, +log_ip6_route(NMPlatform *self, NMPObjectType obj_type, int ifindex, - NMPlatformIP6Route * route, + NMPlatformIP6Route *route, NMPlatformSignalChangeType change_type, gpointer user_data) { @@ -8710,10 +8709,10 @@ log_ip6_route(NMPlatform * self, } static void -log_routing_rule(NMPlatform * self, +log_routing_rule(NMPlatform *self, NMPObjectType obj_type, int ifindex, - NMPlatformRoutingRule * routing_rule, + NMPlatformRoutingRule *routing_rule, NMPlatformSignalChangeType change_type, gpointer user_data) { @@ -8724,10 +8723,10 @@ log_routing_rule(NMPlatform * self, } static void -log_qdisc(NMPlatform * self, +log_qdisc(NMPlatform *self, NMPObjectType obj_type, int ifindex, - NMPlatformQdisc * qdisc, + NMPlatformQdisc *qdisc, NMPlatformSignalChangeType change_type, gpointer user_data) { @@ -8737,10 +8736,10 @@ log_qdisc(NMPlatform * self, } static void -log_tfilter(NMPlatform * self, +log_tfilter(NMPlatform *self, NMPObjectType obj_type, int ifindex, - NMPlatformTfilter * tfilter, + NMPlatformTfilter *tfilter, NMPlatformSignalChangeType change_type, gpointer user_data) { @@ -8752,7 +8751,7 @@ log_tfilter(NMPlatform * self, /*****************************************************************************/ void -nm_platform_cache_update_emit_signal(NMPlatform * self, +nm_platform_cache_update_emit_signal(NMPlatform *self, NMPCacheOpsType cache_op, const NMPObject *obj_old, const NMPObject *obj_new) @@ -8760,7 +8759,7 @@ nm_platform_cache_update_emit_signal(NMPlatform * self, gboolean visible_new; gboolean visible_old; const NMPObject *o; - const NMPClass * klass; + const NMPClass *klass; int ifindex; nm_assert(NM_IN_SET((NMPlatformSignalChangeType) cache_op, @@ -8875,7 +8874,7 @@ const _NMPlatformVTableRouteUnion nm_platform_vtable_route = { const NMPlatformIPXRoute *b, NMPlatformIPRouteCmpType cmp_type)) nm_platform_ip4_route_cmp, .route_to_string = (const char *(*) (const NMPlatformIPXRoute *route, - char * buf, + char *buf, gsize len)) nm_platform_ip4_route_to_string, }, .v6 = @@ -8888,7 +8887,7 @@ const _NMPlatformVTableRouteUnion nm_platform_vtable_route = { const NMPlatformIPXRoute *b, NMPlatformIPRouteCmpType cmp_type)) nm_platform_ip6_route_cmp, .route_to_string = (const char *(*) (const NMPlatformIPXRoute *route, - char * buf, + char *buf, gsize len)) nm_platform_ip6_route_to_string, }, }; @@ -8898,7 +8897,7 @@ const _NMPlatformVTableRouteUnion nm_platform_vtable_route = { static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - NMPlatform * self = NM_PLATFORM(object); + NMPlatform *self = NM_PLATFORM(object); NMPlatformPrivate *priv = NM_PLATFORM_GET_PRIVATE(self); switch (prop_id) { @@ -8939,8 +8938,8 @@ nm_platform_init(NMPlatform *self) static GObject * constructor(GType type, guint n_construct_params, GObjectConstructParam *construct_params) { - GObject * object; - NMPlatform * self; + GObject *object; + NMPlatform *self; NMPlatformPrivate *priv; object = G_OBJECT_CLASS(nm_platform_parent_class) @@ -8958,7 +8957,7 @@ constructor(GType type, guint n_construct_params, GObjectConstructParam *constru static void finalize(GObject *object) { - NMPlatform * self = NM_PLATFORM(object); + NMPlatform *self = NM_PLATFORM(object); NMPlatformPrivate *priv = NM_PLATFORM_GET_PRIVATE(self); nm_clear_g_source(&priv->ip4_dev_route_blacklist_check_id); diff --git a/src/libnm-platform/nm-platform.h b/src/libnm-platform/nm-platform.h index 7101b48c..6f5cd524 100644 --- a/src/libnm-platform/nm-platform.h +++ b/src/libnm-platform/nm-platform.h @@ -155,7 +155,7 @@ G_STATIC_ASSERT(_nm_alignof(NMEtherAddr) == 1); G_STATIC_ASSERT(_nm_alignof(NMPLinkAddress) == 1); gconstpointer nmp_link_address_get(const NMPLinkAddress *addr, size_t *length); -GBytes * nmp_link_address_get_as_bytes(const NMPLinkAddress *addr); +GBytes *nmp_link_address_get_as_bytes(const NMPLinkAddress *addr); typedef enum { @@ -318,16 +318,14 @@ typedef enum { * IFA_FLAGS attribute. */ \ guint32 n_ifa_flags; \ \ - /* FIXME(l3cfg): the external marker won't be necessary anymore, because we only - * merge addresses we care about, and ignore (don't remove) external addresses. */ \ - bool external : 1; \ - \ bool use_ip4_broadcast_address : 1; \ \ - /* Whether the address is should be configured once during assume. This is a meta flag - * that is not honored by NMPlatform (netlink code). Instead, it can be used by the upper - * layers which use NMPlatformIPAddress to track addresses that should be configured. */ \ + /* Meta flags not honored by NMPlatform (netlink code). Instead, they can be + * used by the upper layers which use NMPlatformIPRoute to track addresses that + * should be configured. */ \ + /* Whether the address is should be configured once during assume. */ \ bool a_assume_config_once : 1; \ + bool a_force_commit : 1; \ \ guint8 plen; \ ; @@ -471,18 +469,13 @@ typedef union { * the "table_coerced" field is ignored (unlike for the metric). */ \ bool table_any : 1; \ \ - /* This route is tracked as external route, that is not a route that NetworkManager - * actively wants to add, but a route that was added externally. In some cases, such - * a route should be ignored. - * - * Note that unlike most other fields here, this flag only exists inside NetworkManager - * and is not reflected on netlink. */ \ - bool is_external : 1; \ - \ - /* Whether the route is should be configured once during assume. This is a meta flag - * that is not honored by NMPlatform (netlink code). Instead, it can be used by the upper - * layers which use NMPlatformIPRoute to track routes that should be configured. */ \ + /* Meta flags not honored by NMPlatform (netlink code). Instead, they can be + * used by the upper layers which use NMPlatformIPRoute to track routes that + * should be configured. */ \ + /* Whether the route is should be configured once during assume. */ \ bool r_assume_config_once : 1; \ + /* Whether the route should be committed even if it was removed externally. */ \ + bool r_force_commit : 1; \ \ /* rtnh_flags * @@ -1078,7 +1071,7 @@ struct _NMPlatformPrivate; struct _NMPlatform { GObject parent; - NMPNetns * _netns; + NMPNetns *_netns; struct _NMPlatformPrivate *_priv; }; @@ -1090,24 +1083,24 @@ typedef struct { int dirfd, const char *path, const char *value); - void (*sysctl_set_async)(NMPlatform * self, - const char * pathid, + void (*sysctl_set_async)(NMPlatform *self, + const char *pathid, int dirfd, - const char * path, - const char *const * values, + const char *path, + const char *const *values, NMPlatformAsyncCallback callback, gpointer data, - GCancellable * cancellable); + GCancellable *cancellable); char *(*sysctl_get)(NMPlatform *self, const char *pathid, int dirfd, const char *path); void (*refresh_all)(NMPlatform *self, NMPObjectType obj_type); void (*process_events)(NMPlatform *self); - int (*link_add)(NMPlatform * self, + int (*link_add)(NMPlatform *self, 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, @@ -1123,21 +1116,21 @@ typedef struct { int (*link_set_inet6_addr_gen_mode)(NMPlatform *self, int ifindex, guint8 enabled); gboolean (*link_set_token)(NMPlatform *self, int ifindex, const NMUtilsIPv6IfaceId *iid); - gboolean (*link_get_permanent_address_ethtool)(NMPlatform * self, + gboolean (*link_get_permanent_address_ethtool)(NMPlatform *self, int ifindex, NMPLinkAddress *out_address); int (*link_set_address)(NMPlatform *self, int ifindex, gconstpointer address, size_t length); int (*link_set_mtu)(NMPlatform *self, int ifindex, guint32 mtu); gboolean (*link_set_name)(NMPlatform *self, int ifindex, const char *name); - void (*link_set_sriov_params_async)(NMPlatform * self, + void (*link_set_sriov_params_async)(NMPlatform *self, int ifindex, guint num_vfs, NMOptionBool autoprobe, NMPlatformAsyncCallback callback, gpointer callback_data, - GCancellable * cancellable); + GCancellable *cancellable); gboolean (*link_set_sriov_vfs)(NMPlatform *self, int ifindex, const NMPlatformVF *const *vfs); - gboolean (*link_set_bridge_vlans)(NMPlatform * self, + gboolean (*link_set_bridge_vlans)(NMPlatform *self, int ifindex, gboolean on_master, const NMPlatformBridgeVlan *const *vlans); @@ -1147,9 +1140,9 @@ typedef struct { gboolean (*link_get_wake_on_lan)(NMPlatform *self, int ifindex); gboolean (*link_get_driver_info)(NMPlatform *self, 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); gboolean (*link_supports_carrier_detect)(NMPlatform *self, int ifindex); gboolean (*link_supports_vlans)(NMPlatform *self, int ifindex); @@ -1160,15 +1153,15 @@ typedef struct { gboolean (*link_can_assume)(NMPlatform *self, int ifindex); - int (*link_wireguard_change)(NMPlatform * self, + int (*link_wireguard_change)(NMPlatform *self, int ifindex, - const NMPlatformLnkWireGuard * lnk_wireguard, - const struct _NMPWireGuardPeer * peers, + const NMPlatformLnkWireGuard *lnk_wireguard, + const struct _NMPWireGuardPeer *peers, const NMPlatformWireGuardChangePeerFlags *peer_flags, guint peers_len, NMPlatformWireGuardChangeFlags change_flags); - gboolean (*link_vlan_change)(NMPlatform * self, + gboolean (*link_vlan_change)(NMPlatform *self, int ifindex, _NMVlanFlags flags_mask, _NMVlanFlags flags_set, @@ -1178,26 +1171,26 @@ typedef struct { gboolean egress_reset_all, const NMVlanQosMapping *egress_map, gsize n_egress_map); - gboolean (*link_tun_add)(NMPlatform * self, - const char * name, + gboolean (*link_tun_add)(NMPlatform *self, + const char *name, const NMPlatformLnkTun *props, - const NMPlatformLink ** out_link, - int * out_fd); + const NMPlatformLink **out_link, + int *out_fd); - gboolean (*infiniband_partition_add)(NMPlatform * self, + gboolean (*infiniband_partition_add)(NMPlatform *self, int parent, int p_key, const NMPlatformLink **out_link); gboolean (*infiniband_partition_delete)(NMPlatform *self, int parent, int p_key); - gboolean (*wifi_get_capabilities)(NMPlatform * self, + gboolean (*wifi_get_capabilities)(NMPlatform *self, int ifindex, _NMDeviceWifiCapabilities *caps); - gboolean (*wifi_get_station)(NMPlatform * self, + gboolean (*wifi_get_station)(NMPlatform *self, int ifindex, NMEtherAddr *out_bssid, - int * out_quality, - guint32 * out_rate); + int *out_quality, + guint32 *out_rate); gboolean (*wifi_get_bssid)(NMPlatform *self, int ifindex, guint8 *bssid); guint32 (*wifi_get_frequency)(NMPlatform *self, int ifindex); int (*wifi_get_quality)(NMPlatform *self, int ifindex); @@ -1208,7 +1201,7 @@ typedef struct { guint32 (*wifi_find_frequency)(NMPlatform *self, int ifindex, const guint32 *freqs); void (*wifi_indicate_addressing_running)(NMPlatform *self, int ifindex, gboolean running); _NMSettingWirelessWakeOnWLan (*wifi_get_wake_on_wlan)(NMPlatform *self, int ifindex); - gboolean (*wifi_set_wake_on_wlan)(NMPlatform * self, + gboolean (*wifi_set_wake_on_wlan)(NMPlatform *self, int ifindex, _NMSettingWirelessWakeOnWLan wowl); @@ -1234,7 +1227,7 @@ typedef struct { guint32 preferred_lft, guint32 flags, const char *label); - gboolean (*ip6_address_add)(NMPlatform * self, + gboolean (*ip6_address_add)(NMPlatform *self, int ifindex, struct in6_addr address, guint8 plen, @@ -1247,22 +1240,22 @@ typedef struct { in_addr_t address, guint8 plen, in_addr_t peer_address); - gboolean (*ip6_address_delete)(NMPlatform * self, + gboolean (*ip6_address_delete)(NMPlatform *self, int ifindex, struct in6_addr address, guint8 plen); - int (*ip_route_add)(NMPlatform * self, + int (*ip_route_add)(NMPlatform *self, NMPNlmFlags flags, int addr_family, const NMPlatformIPRoute *route); - int (*ip_route_get)(NMPlatform * self, + int (*ip_route_get)(NMPlatform *self, int addr_family, gconstpointer address, int oif_ifindex, - NMPObject ** out_route); + NMPObject **out_route); - int (*routing_rule_add)(NMPlatform * self, + int (*routing_rule_add)(NMPlatform *self, NMPNlmFlags flags, const NMPlatformRoutingRule *routing_rule); @@ -1415,6 +1408,12 @@ _nm_platform_link_get_inet6_addr_gen_mode(const NMPlatformLink *pllink) return _nm_platform_uint8_inv(pllink->inet6_addr_gen_mode_inv); } +static inline gboolean +nm_platform_route_type_is_nodev(guint8 type) +{ + return NM_IN_SET(type, 6 /* RTN_BLACKHOLE */, 7 /* RTN_UNREACHABLE */, 8 /* RTN_PROHIBIT */); +} + /** * nm_platform_route_type_coerce: * @table: the route type, in its original value. @@ -1484,15 +1483,15 @@ gboolean nm_platform_sysctl_set(NMPlatform *self, int dirfd, const char *path, const char *value); -void nm_platform_sysctl_set_async(NMPlatform * self, - const char * pathid, +void nm_platform_sysctl_set_async(NMPlatform *self, + const char *pathid, int dirfd, - const char * path, - const char *const * values, + const char *path, + const char *const *values, NMPlatformAsyncCallback callback, gpointer data, - GCancellable * cancellable); -char * nm_platform_sysctl_get(NMPlatform *self, const char *pathid, int dirfd, const char *path); + GCancellable *cancellable); +char *nm_platform_sysctl_get(NMPlatform *self, const char *pathid, int dirfd, const char *path); gint32 nm_platform_sysctl_get_int32(NMPlatform *self, const char *pathid, int dirfd, @@ -1544,7 +1543,7 @@ gboolean nm_platform_sysctl_ip_neigh_set_ipv6_retrans_time(NMPlatform *self, int nm_platform_sysctl_ip_conf_get_rp_filter_ipv4(NMPlatform *platform, const char *iface, gboolean consider_all, - gboolean * out_due_to_all); + gboolean *out_due_to_all); const char *nm_platform_if_indextoname(NMPlatform *self, int ifindex, @@ -1554,27 +1553,27 @@ int nm_platform_if_nametoindex(NMPlatform *self, const char *ifname); const NMPObject *nm_platform_link_get_obj(NMPlatform *self, int ifindex, gboolean visible_only); const NMPlatformLink *nm_platform_link_get(NMPlatform *self, int ifindex); const NMPlatformLink *nm_platform_link_get_by_ifname(NMPlatform *self, const char *ifname); -const NMPlatformLink *nm_platform_link_get_by_address(NMPlatform * self, +const NMPlatformLink *nm_platform_link_get_by_address(NMPlatform *self, NMLinkType link_type, gconstpointer address, size_t length); GPtrArray *nm_platform_link_get_all(NMPlatform *self, gboolean sort_by_name); -int nm_platform_link_add(NMPlatform * self, +int nm_platform_link_add(NMPlatform *self, 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); static inline int -nm_platform_link_veth_add(NMPlatform * self, - const char * name, - const char * peer, +nm_platform_link_veth_add(NMPlatform *self, + const char *name, + const char *peer, const NMPlatformLink **out_link) { return nm_platform_link_add(self, NM_LINK_TYPE_VETH, name, 0, NULL, 0, 0, peer, out_link); @@ -1587,13 +1586,13 @@ nm_platform_link_dummy_add(NMPlatform *self, const char *name, const NMPlatformL } static inline int -nm_platform_link_bridge_add(NMPlatform * self, - const char * name, - const void * address, +nm_platform_link_bridge_add(NMPlatform *self, + const char *name, + const void *address, size_t address_len, guint32 mtu, const NMPlatformLnkBridge *props, - const NMPlatformLink ** out_link) + const NMPlatformLink **out_link) { return nm_platform_link_add(self, NM_LINK_TYPE_BRIDGE, @@ -1625,12 +1624,12 @@ nm_platform_link_wireguard_add(NMPlatform *self, const char *name, const NMPlatf } static inline int -nm_platform_link_gre_add(NMPlatform * self, - const char * name, - const void * address, +nm_platform_link_gre_add(NMPlatform *self, + const char *name, + const void *address, size_t address_len, const NMPlatformLnkGre *props, - const NMPlatformLink ** out_link) + const NMPlatformLink **out_link) { g_return_val_if_fail(props, -NME_BUG); @@ -1646,17 +1645,17 @@ nm_platform_link_gre_add(NMPlatform * self, } static inline int -nm_platform_link_sit_add(NMPlatform * self, - const char * name, +nm_platform_link_sit_add(NMPlatform *self, + const char *name, const NMPlatformLnkSit *props, - const NMPlatformLink ** out_link) + const NMPlatformLink **out_link) { return nm_platform_link_add(self, NM_LINK_TYPE_SIT, name, 0, NULL, 0, 0, props, out_link); } static inline int -nm_platform_link_vlan_add(NMPlatform * self, - const char * name, +nm_platform_link_vlan_add(NMPlatform *self, + const char *name, int parent, int vlanid, guint32 vlanflags, @@ -1680,26 +1679,26 @@ nm_platform_link_vlan_add(NMPlatform * self, } static inline int -nm_platform_link_vrf_add(NMPlatform * self, - const char * name, +nm_platform_link_vrf_add(NMPlatform *self, + const char *name, const NMPlatformLnkVrf *props, - const NMPlatformLink ** out_link) + const NMPlatformLink **out_link) { return nm_platform_link_add(self, NM_LINK_TYPE_VRF, name, 0, NULL, 0, 0, props, out_link); } static inline int -nm_platform_link_vxlan_add(NMPlatform * self, - const char * name, +nm_platform_link_vxlan_add(NMPlatform *self, + const char *name, const NMPlatformLnkVxlan *props, - const NMPlatformLink ** out_link) + const NMPlatformLink **out_link) { return nm_platform_link_add(self, NM_LINK_TYPE_VXLAN, name, 0, NULL, 0, 0, props, out_link); } static inline int -nm_platform_link_6lowpan_add(NMPlatform * self, - const char * name, +nm_platform_link_6lowpan_add(NMPlatform *self, + const char *name, int parent, const NMPlatformLink **out_link) { @@ -1715,10 +1714,10 @@ nm_platform_link_6lowpan_add(NMPlatform * self, } static inline int -nm_platform_link_ip6tnl_add(NMPlatform * self, - const char * name, +nm_platform_link_ip6tnl_add(NMPlatform *self, + const char *name, const NMPlatformLnkIp6Tnl *props, - const NMPlatformLink ** out_link) + const NMPlatformLink **out_link) { g_return_val_if_fail(props, -NME_BUG); g_return_val_if_fail(!props->is_gre, -NME_BUG); @@ -1727,12 +1726,12 @@ nm_platform_link_ip6tnl_add(NMPlatform * self, } static inline int -nm_platform_link_ip6gre_add(NMPlatform * self, - const char * name, - const void * address, +nm_platform_link_ip6gre_add(NMPlatform *self, + const char *name, + const void *address, size_t address_len, const NMPlatformLnkIp6Tnl *props, - const NMPlatformLink ** out_link) + const NMPlatformLink **out_link) { g_return_val_if_fail(props, -NME_BUG); g_return_val_if_fail(props->is_gre, -NME_BUG); @@ -1749,10 +1748,10 @@ nm_platform_link_ip6gre_add(NMPlatform * self, } static inline int -nm_platform_link_ipip_add(NMPlatform * self, - const char * name, +nm_platform_link_ipip_add(NMPlatform *self, + const char *name, const NMPlatformLnkIpIp *props, - const NMPlatformLink ** out_link) + const NMPlatformLink **out_link) { g_return_val_if_fail(props, -NME_BUG); @@ -1760,11 +1759,11 @@ nm_platform_link_ipip_add(NMPlatform * self, } static inline int -nm_platform_link_macsec_add(NMPlatform * self, - const char * name, +nm_platform_link_macsec_add(NMPlatform *self, + const char *name, int parent, const NMPlatformLnkMacsec *props, - const NMPlatformLink ** out_link) + const NMPlatformLink **out_link) { g_return_val_if_fail(props, -NME_BUG); g_return_val_if_fail(parent > 0, -NME_BUG); @@ -1781,11 +1780,11 @@ nm_platform_link_macsec_add(NMPlatform * self, } static inline int -nm_platform_link_macvlan_add(NMPlatform * self, - const char * name, +nm_platform_link_macvlan_add(NMPlatform *self, + const char *name, int parent, const NMPlatformLnkMacvlan *props, - const NMPlatformLink ** out_link) + const NMPlatformLink **out_link) { g_return_val_if_fail(props, -NME_BUG); g_return_val_if_fail(parent > 0, -NME_BUG); @@ -1807,7 +1806,7 @@ gboolean nm_platform_link_set_netns(NMPlatform *self, int ifindex, int netns_fd) struct _NMDedupMultiHeadEntry; struct _NMPLookup; -const struct _NMDedupMultiHeadEntry *nm_platform_lookup(NMPlatform * self, +const struct _NMDedupMultiHeadEntry *nm_platform_lookup(NMPlatform *self, const struct _NMPLookup *lookup); #define nm_platform_iter_obj_for_each(iter, self, lookup, obj) \ @@ -1818,7 +1817,7 @@ gboolean nm_platform_lookup_predicate_routes_main(const NMPObject *obj, gpointer gboolean nm_platform_lookup_predicate_routes_main_skip_rtprot_kernel(const NMPObject *obj, gpointer user_data); -GPtrArray *nm_platform_lookup_clone(NMPlatform * self, +GPtrArray *nm_platform_lookup_clone(NMPlatform *self, const struct _NMPLookup *lookup, NMPObjectPredicateFunc predicate, gpointer user_data); @@ -1874,9 +1873,9 @@ nm_platform_link_change_flags(NMPlatform *self, int ifindex, unsigned value, gbo return nm_platform_link_change_flags_full(self, ifindex, value, set ? value : 0u); } -gboolean nm_platform_link_get_udev_property(NMPlatform * self, +gboolean nm_platform_link_get_udev_property(NMPlatform *self, int ifindex, - const char * name, + const char *name, const char **out_value); const char *nm_platform_link_get_udi(NMPlatform *self, int ifindex); const char *nm_platform_link_get_path(NMPlatform *self, int ifindex); @@ -1887,39 +1886,39 @@ int nm_platform_link_set_inet6_addr_gen_mode(NMPlatform *self, int ifindex, guin gboolean nm_platform_link_set_ipv6_token(NMPlatform *self, int ifindex, const NMUtilsIPv6IfaceId *iid); -gboolean nm_platform_link_get_permanent_address_ethtool(NMPlatform * self, +gboolean nm_platform_link_get_permanent_address_ethtool(NMPlatform *self, int ifindex, NMPLinkAddress *out_address); -gboolean nm_platform_link_get_permanent_address(NMPlatform * self, +gboolean nm_platform_link_get_permanent_address(NMPlatform *self, const NMPlatformLink *plink, - NMPLinkAddress * out_address); + NMPLinkAddress *out_address); int nm_platform_link_set_address(NMPlatform *self, int ifindex, const void *address, size_t length); int nm_platform_link_set_mtu(NMPlatform *self, int ifindex, guint32 mtu); gboolean nm_platform_link_set_name(NMPlatform *self, int ifindex, const char *name); -void nm_platform_link_set_sriov_params_async(NMPlatform * self, +void nm_platform_link_set_sriov_params_async(NMPlatform *self, int ifindex, guint num_vfs, NMOptionBool autoprobe, NMPlatformAsyncCallback callback, gpointer callback_data, - GCancellable * cancellable); + GCancellable *cancellable); gboolean nm_platform_link_set_sriov_vfs(NMPlatform *self, int ifindex, const NMPlatformVF *const *vfs); -gboolean nm_platform_link_set_bridge_vlans(NMPlatform * self, +gboolean nm_platform_link_set_bridge_vlans(NMPlatform *self, int ifindex, gboolean on_master, const NMPlatformBridgeVlan *const *vlans); -char * nm_platform_link_get_physical_port_id(NMPlatform *self, int ifindex); +char *nm_platform_link_get_physical_port_id(NMPlatform *self, int ifindex); guint nm_platform_link_get_dev_id(NMPlatform *self, int ifindex); gboolean nm_platform_link_get_wake_on_lan(NMPlatform *self, int ifindex); gboolean nm_platform_link_get_driver_info(NMPlatform *self, 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); gboolean nm_platform_link_supports_carrier_detect(NMPlatform *self, int ifindex); gboolean nm_platform_link_supports_vlans(NMPlatform *self, int ifindex); @@ -1932,14 +1931,14 @@ gboolean nm_platform_sysctl_master_set_option(NMPlatform *self, int ifindex, const char *option, const char *value); -char * nm_platform_sysctl_master_get_option(NMPlatform *self, int ifindex, const char *option); +char *nm_platform_sysctl_master_get_option(NMPlatform *self, int ifindex, const char *option); gboolean nm_platform_sysctl_slave_set_option(NMPlatform *self, int ifindex, const char *option, const char *value); -char * nm_platform_sysctl_slave_get_option(NMPlatform *self, int ifindex, const char *option); +char *nm_platform_sysctl_slave_get_option(NMPlatform *self, int ifindex, const char *option); -const NMPObject *nm_platform_link_get_lnk(NMPlatform * self, +const NMPObject *nm_platform_link_get_lnk(NMPlatform *self, int ifindex, NMLinkType link_type, const NMPlatformLink **out_link); @@ -1982,7 +1981,7 @@ nm_platform_link_get_lnk_wireguard(NMPlatform *self, int ifindex, const NMPlatfo gboolean nm_platform_link_vlan_set_ingress_map(NMPlatform *self, int ifindex, int from, int to); gboolean nm_platform_link_vlan_set_egress_map(NMPlatform *self, int ifindex, int from, int to); -gboolean nm_platform_link_vlan_change(NMPlatform * self, +gboolean nm_platform_link_vlan_change(NMPlatform *self, int ifindex, _NMVlanFlags flags_mask, _NMVlanFlags flags_set, @@ -1993,30 +1992,30 @@ gboolean nm_platform_link_vlan_change(NMPlatform * self, const NMVlanQosMapping *egress_map, gsize n_egress_map); -int nm_platform_link_infiniband_add(NMPlatform * self, +int nm_platform_link_infiniband_add(NMPlatform *self, int parent, int p_key, const NMPlatformLink **out_link); int nm_platform_link_infiniband_delete(NMPlatform *self, int parent, int p_key); -gboolean nm_platform_link_infiniband_get_properties(NMPlatform * self, +gboolean nm_platform_link_infiniband_get_properties(NMPlatform *self, int ifindex, - int * parent, - int * p_key, + int *parent, + int *p_key, const char **mode); gboolean nm_platform_link_veth_get_properties(NMPlatform *self, int ifindex, int *out_peer_ifindex); -gboolean nm_platform_link_tun_get_properties(NMPlatform * self, +gboolean nm_platform_link_tun_get_properties(NMPlatform *self, int ifindex, NMPlatformLnkTun *out_properties); gboolean nm_platform_wifi_get_capabilities(NMPlatform *self, int ifindex, _NMDeviceWifiCapabilities *caps); guint32 nm_platform_wifi_get_frequency(NMPlatform *self, int ifindex); -gboolean nm_platform_wifi_get_station(NMPlatform * self, +gboolean nm_platform_wifi_get_station(NMPlatform *self, int ifindex, NMEtherAddr *out_bssid, - int * out_quality, - guint32 * out_rate); + int *out_quality, + guint32 *out_rate); _NM80211Mode nm_platform_wifi_get_mode(NMPlatform *self, int ifindex); void nm_platform_wifi_set_mode(NMPlatform *self, int ifindex, _NM80211Mode mode); void nm_platform_wifi_set_powersave(NMPlatform *self, int ifindex, guint32 powersave); @@ -2045,24 +2044,24 @@ const NMPlatformIP4Address *nm_platform_ip4_address_get(NMPlatform *self, guint8 plen, in_addr_t peer_address); -int nm_platform_link_sit_add(NMPlatform * self, - const char * name, +int nm_platform_link_sit_add(NMPlatform *self, + const char *name, const NMPlatformLnkSit *props, - const NMPlatformLink ** out_link); -int nm_platform_link_tun_add(NMPlatform * self, - const char * name, + const NMPlatformLink **out_link); +int nm_platform_link_tun_add(NMPlatform *self, + const char *name, const NMPlatformLnkTun *props, - const NMPlatformLink ** out_link, - int * out_fd); + const NMPlatformLink **out_link, + int *out_fd); gboolean nm_platform_link_6lowpan_get_properties(NMPlatform *self, int ifindex, int *out_parent); int nm_platform_link_wireguard_add(NMPlatform *self, const char *name, const NMPlatformLink **out_link); -int nm_platform_link_wireguard_change(NMPlatform * self, +int nm_platform_link_wireguard_change(NMPlatform *self, int ifindex, - const NMPlatformLnkWireGuard * lnk_wireguard, - const struct _NMPWireGuardPeer * peers, + const NMPlatformLnkWireGuard *lnk_wireguard, + const struct _NMPWireGuardPeer *peers, const NMPlatformWireGuardChangePeerFlags *peer_flags, guint peers_len, NMPlatformWireGuardChangeFlags change_flags); @@ -2082,7 +2081,7 @@ gboolean nm_platform_ip4_address_add(NMPlatform *self, guint32 preferred_lft, guint32 flags, const char *label); -gboolean nm_platform_ip6_address_add(NMPlatform * self, +gboolean nm_platform_ip6_address_add(NMPlatform *self, int ifindex, struct in6_addr address, guint8 plen, @@ -2101,8 +2100,8 @@ nm_platform_ip6_address_delete(NMPlatform *self, int ifindex, struct in6_addr ad gboolean nm_platform_ip_address_sync(NMPlatform *self, int addr_family, int ifindex, - GPtrArray * known_addresses, - GPtrArray * addresses_prune); + GPtrArray *known_addresses, + GPtrArray *addresses_prune); GPtrArray *nm_platform_ip_address_get_prune_list(NMPlatform *self, int addr_family, @@ -2113,7 +2112,7 @@ static inline gboolean _nm_platform_ip_address_sync(NMPlatform *self, int addr_family, int ifindex, - GPtrArray * known_addresses, + GPtrArray *known_addresses, gboolean full_sync) { gs_unref_ptrarray GPtrArray *addresses_prune = NULL; @@ -2135,7 +2134,7 @@ nm_platform_ip4_address_sync(NMPlatform *self, int ifindex, GPtrArray *known_add static inline gboolean nm_platform_ip6_address_sync(NMPlatform *self, int ifindex, - GPtrArray * known_addresses, + GPtrArray *known_addresses, gboolean full_sync) { return _nm_platform_ip_address_sync(self, AF_INET6, ifindex, known_addresses, full_sync); @@ -2188,7 +2187,9 @@ static inline gconstpointer nm_platform_ip_route_get_gateway(int addr_family, const NMPlatformIPRoute *route) { nm_assert_addr_family(addr_family); - nm_assert(route); + + if (!route) + return NULL; if (NM_IS_IPv4(addr_family)) return &((NMPlatformIP4Route *) route)->gateway; @@ -2199,7 +2200,7 @@ int nm_platform_ip_route_add(NMPlatform *self, NMPNlmFlags flags, const NMPObjec int nm_platform_ip4_route_add(NMPlatform *self, NMPNlmFlags flags, const NMPlatformIP4Route *route); int nm_platform_ip6_route_add(NMPlatform *self, NMPNlmFlags flags, const NMPlatformIP6Route *route); -GPtrArray *nm_platform_ip_route_get_prune_list(NMPlatform * self, +GPtrArray *nm_platform_ip_route_get_prune_list(NMPlatform *self, int addr_family, int ifindex, NMIPRouteTableSyncMode route_table_sync); @@ -2207,19 +2208,19 @@ GPtrArray *nm_platform_ip_route_get_prune_list(NMPlatform * self, gboolean nm_platform_ip_route_sync(NMPlatform *self, int addr_family, int ifindex, - GPtrArray * routes, - GPtrArray * routes_prune, + GPtrArray *routes, + GPtrArray *routes_prune, GPtrArray **out_temporary_not_available); gboolean nm_platform_ip_route_flush(NMPlatform *self, int addr_family, int ifindex); -int nm_platform_ip_route_get(NMPlatform * self, +int nm_platform_ip_route_get(NMPlatform *self, int addr_family, gconstpointer address, int oif_ifindex, - NMPObject ** out_route); + NMPObject **out_route); -int nm_platform_routing_rule_add(NMPlatform * self, +int nm_platform_routing_rule_add(NMPlatform *self, NMPNlmFlags flags, const NMPlatformRoutingRule *routing_rule); @@ -2229,8 +2230,8 @@ int nm_platform_tfilter_add(NMPlatform *self, NMPNlmFlags flags, const NMPlatfor int nm_platform_tfilter_delete(NMPlatform *self, int ifindex, guint32 parent, gboolean log_error); gboolean nm_platform_tc_sync(NMPlatform *self, int ifindex, - GPtrArray * known_qdiscs, - GPtrArray * known_tfilters); + GPtrArray *known_qdiscs, + GPtrArray *known_tfilters); const char *nm_platform_link_to_string(const NMPlatformLink *link, char *buf, gsize len); const char *nm_platform_lnk_bridge_to_string(const NMPlatformLnkBridge *lnk, char *buf, gsize len); @@ -2263,10 +2264,10 @@ const char *nm_platform_vf_to_string(const NMPlatformVF *vf, char *buf, gsize le const char * nm_platform_bridge_vlan_to_string(const NMPlatformBridgeVlan *vlan, char *buf, gsize len); -const char *nm_platform_vlan_qos_mapping_to_string(const char * name, +const char *nm_platform_vlan_qos_mapping_to_string(const char *name, const NMVlanQosMapping *map, gsize n_map, - char * buf, + char *buf, gsize len); const char * @@ -2339,13 +2340,13 @@ void nm_platform_ip4_address_hash_update(const NMPlatformIP4Address *obj, NMHash void nm_platform_ip6_address_hash_update(const NMPlatformIP6Address *obj, NMHashState *h); void nm_platform_ip4_route_hash_update(const NMPlatformIP4Route *obj, NMPlatformIPRouteCmpType cmp_type, - NMHashState * h); + NMHashState *h); void nm_platform_ip6_route_hash_update(const NMPlatformIP6Route *obj, NMPlatformIPRouteCmpType cmp_type, - NMHashState * h); + NMHashState *h); void nm_platform_routing_rule_hash_update(const NMPlatformRoutingRule *obj, NMPlatformRoutingRuleCmpType cmp_type, - NMHashState * h); + NMHashState *h); void nm_platform_lnk_bridge_hash_update(const NMPlatformLnkBridge *obj, NMHashState *h); void nm_platform_lnk_gre_hash_update(const NMPlatformLnkGre *obj, NMHashState *h); void nm_platform_lnk_infiniband_hash_update(const NMPlatformLnkInfiniband *obj, NMHashState *h); @@ -2372,34 +2373,34 @@ const char *nm_platform_route_scope2str(int scope, char *buf, gsize len); int nm_platform_ip_address_cmp_expiry(const NMPlatformIPAddress *a, const NMPlatformIPAddress *b); -gboolean nm_platform_ethtool_set_wake_on_lan(NMPlatform * self, +gboolean nm_platform_ethtool_set_wake_on_lan(NMPlatform *self, int ifindex, _NMSettingWiredWakeOnLan wol, - const char * wol_password); -gboolean nm_platform_ethtool_set_link_settings(NMPlatform * self, + const char *wol_password); +gboolean nm_platform_ethtool_set_link_settings(NMPlatform *self, int ifindex, gboolean autoneg, guint32 speed, NMPlatformLinkDuplexType duplex); -gboolean nm_platform_ethtool_get_link_settings(NMPlatform * self, +gboolean nm_platform_ethtool_get_link_settings(NMPlatform *self, int ifindex, - gboolean * out_autoneg, - guint32 * out_speed, + gboolean *out_autoneg, + guint32 *out_speed, NMPlatformLinkDuplexType *out_duplex); NMEthtoolFeatureStates *nm_platform_ethtool_get_link_features(NMPlatform *self, int ifindex); gboolean nm_platform_ethtool_set_features( - NMPlatform * self, + NMPlatform *self, int ifindex, const NMEthtoolFeatureStates *features, const NMOptionBool *requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */, gboolean do_set /* or reset */); -gboolean nm_platform_ethtool_get_link_coalesce(NMPlatform * self, +gboolean nm_platform_ethtool_get_link_coalesce(NMPlatform *self, int ifindex, NMEthtoolCoalesceState *coalesce); -gboolean nm_platform_ethtool_set_coalesce(NMPlatform * self, +gboolean nm_platform_ethtool_set_coalesce(NMPlatform *self, int ifindex, const NMEthtoolCoalesceState *coalesce); @@ -2416,7 +2417,7 @@ nm_platform_ethtool_set_pause(NMPlatform *self, int ifindex, const NMEthtoolPaus void nm_platform_ip4_dev_route_blacklist_set(NMPlatform *self, int ifindex, - GPtrArray * ip4_dev_route_blacklist); + GPtrArray *ip4_dev_route_blacklist); struct _NMDedupMultiIndex *nm_platform_get_multi_idx(NMPlatform *self); @@ -2426,6 +2427,7 @@ NMPlatformIP4Route *nm_platform_ip4_address_generate_device_route(const NMPlatfo int ifindex, guint32 route_table, guint32 route_metric, + gboolean force_commit, NMPlatformIP4Route *dst); /*****************************************************************************/ diff --git a/src/libnm-platform/nmp-netns.c b/src/libnm-platform/nmp-netns.c index d06c3e11..2563e8f6 100644 --- a/src/libnm-platform/nmp-netns.c +++ b/src/libnm-platform/nmp-netns.c @@ -147,8 +147,8 @@ static GArray * _netns_stack_get_impl(void) { gs_unref_object NMPNetns *netns = NULL; - gs_free_error GError *error = NULL; - GArray * s; + gs_free_error GError *error = NULL; + GArray *s; s = g_array_new(FALSE, FALSE, sizeof(NetnsInfo)); g_array_set_clear_func(s, _netns_stack_clear_cb); @@ -444,7 +444,7 @@ nmp_netns_get_fd_mnt(NMPNetns *self) static gboolean _nmp_netns_push_type(NMPNetns *self, int ns_types) { - GArray * netns_stack = _netns_stack_get(); + GArray *netns_stack = _netns_stack_get(); NetnsInfo *info; char sbuf[100]; @@ -493,10 +493,10 @@ nmp_netns_push_type(NMPNetns *self, int ns_types) NMPNetns * nmp_netns_new(void) { - GArray * netns_stack = _netns_stack_get(); - NMPNetns * self; + GArray *netns_stack = _netns_stack_get(); + NMPNetns *self; int errsv; - GError * error = NULL; + GError *error = NULL; unsigned long mountflags = 0; if (!_stack_peek(netns_stack)) { @@ -553,7 +553,7 @@ err_out: gboolean nmp_netns_pop(NMPNetns *self) { - GArray * netns_stack = _netns_stack_get(); + GArray *netns_stack = _netns_stack_get(); NetnsInfo *info; int ns_types; @@ -608,9 +608,9 @@ nmp_netns_is_initial(void) gboolean nmp_netns_bind_to_path(NMPNetns *self, const char *filename, int *out_fd) { - gs_free char * dirname = NULL; - int errsv; - int fd; + gs_free char *dirname = NULL; + int errsv; + int fd; nm_auto_pop_netns NMPNetns *netns_pop = NULL; g_return_val_if_fail(NMP_IS_NETNS(self), FALSE); @@ -690,7 +690,7 @@ nmp_netns_bind_to_path_destroy(NMPNetns *self, const char *filename) static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - NMPNetns * self = NMP_NETNS(object); + NMPNetns *self = NMP_NETNS(object); NMPNetnsPrivate *priv = NMP_NETNS_GET_PRIVATE(self); switch (prop_id) { @@ -717,7 +717,7 @@ nmp_netns_init(NMPNetns *self) static void dispose(GObject *object) { - NMPNetns * self = NMP_NETNS(object); + NMPNetns *self = NMP_NETNS(object); NMPNetnsPrivate *priv = NMP_NETNS_GET_PRIVATE(self); nm_close(priv->fd_net); diff --git a/src/libnm-platform/nmp-object.c b/src/libnm-platform/nmp-object.c index 559fd8d6..d518e6e5 100644 --- a/src/libnm-platform/nmp-object.c +++ b/src/libnm-platform/nmp-object.c @@ -279,8 +279,8 @@ static const NMDedupMultiIdxTypeClass _dedup_multi_idx_type_class; static void _idx_obj_id_hash_update(const NMDedupMultiIdxType *idx_type, - const NMDedupMultiObj * obj, - NMHashState * h) + const NMDedupMultiObj *obj, + NMHashState *h) { const NMPObject *o = (NMPObject *) obj; @@ -292,8 +292,8 @@ _idx_obj_id_hash_update(const NMDedupMultiIdxType *idx_type, 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) { const NMPObject *o_a = (NMPObject *) obj_a; const NMPObject *o_b = (NMPObject *) obj_b; @@ -307,9 +307,9 @@ _idx_obj_id_equal(const NMDedupMultiIdxType *idx_type, static guint _idx_obj_part(const DedupMultiIdxType *idx_type, - const NMPObject * obj_a, - const NMPObject * obj_b, - NMHashState * h) + const NMPObject *obj_a, + const NMPObject *obj_b, + NMHashState *h) { NMPObjectType obj_type; @@ -386,7 +386,11 @@ _idx_obj_part(const DedupMultiIdxType *idx_type, nm_hash_update_val(h, obj_a); return 0; } - nm_assert(NMP_OBJECT_CAST_OBJ_WITH_IFINDEX(obj_a)->ifindex > 0); + nm_assert(NMP_OBJECT_CAST_OBJ_WITH_IFINDEX(obj_a)->ifindex > 0 + || (NMP_OBJECT_CAST_OBJ_WITH_IFINDEX(obj_a)->ifindex == 0 + && NM_IN_SET(NMP_OBJECT_GET_TYPE(obj_a), + NMP_OBJECT_TYPE_IP4_ROUTE, + NMP_OBJECT_TYPE_IP6_ROUTE))); if (obj_b) { return NMP_OBJECT_GET_TYPE(obj_a) == NMP_OBJECT_GET_TYPE(obj_b) && NMP_OBJECT_CAST_OBJ_WITH_IFINDEX(obj_a)->ifindex @@ -401,14 +405,14 @@ _idx_obj_part(const DedupMultiIdxType *idx_type, case NMP_CACHE_ID_TYPE_ROUTES_BY_WEAK_ID: obj_type = NMP_OBJECT_GET_TYPE(obj_a); if (!NM_IN_SET(obj_type, NMP_OBJECT_TYPE_IP4_ROUTE, NMP_OBJECT_TYPE_IP6_ROUTE) - || NMP_OBJECT_CAST_IP_ROUTE(obj_a)->ifindex <= 0) { + || NMP_OBJECT_CAST_IP_ROUTE(obj_a)->ifindex < 0) { if (h) nm_hash_update_val(h, obj_a); return 0; } if (obj_b) { return obj_type == NMP_OBJECT_GET_TYPE(obj_b) - && NMP_OBJECT_CAST_IP_ROUTE(obj_b)->ifindex > 0 + && NMP_OBJECT_CAST_IP_ROUTE(obj_b)->ifindex >= 0 && (obj_type == NMP_OBJECT_TYPE_IP4_ROUTE ? (nm_platform_ip4_route_cmp(&obj_a->ip4_route, &obj_b->ip4_route, @@ -466,16 +470,16 @@ _idx_obj_partitionable(const NMDedupMultiIdxType *idx_type, const NMDedupMultiOb static void _idx_obj_partition_hash_update(const NMDedupMultiIdxType *idx_type, - const NMDedupMultiObj * obj, - NMHashState * h) + const NMDedupMultiObj *obj, + NMHashState *h) { _idx_obj_part((DedupMultiIdxType *) idx_type, (NMPObject *) obj, NULL, h); } static gboolean _idx_obj_partition_equal(const NMDedupMultiIdxType *idx_type, - const NMDedupMultiObj * obj_a, - const NMDedupMultiObj * obj_b) + const NMDedupMultiObj *obj_a, + const NMDedupMultiObj *obj_b) { return _idx_obj_part((DedupMultiIdxType *) idx_type, (NMPObject *) obj_a, @@ -528,8 +532,8 @@ _vlan_xgress_qos_mappings_cmp(guint n_map, } static void -_vlan_xgress_qos_mappings_cpy(guint * dst_n_map, - NMVlanQosMapping ** dst_map, +_vlan_xgress_qos_mappings_cpy(guint *dst_n_map, + NMVlanQosMapping **dst_map, guint src_n_map, const NMVlanQosMapping *src_map) { @@ -655,7 +659,7 @@ _nmp_object_fixup_link_udev_fields(NMPObject **obj_new, NMPObject *obj_orig, gbo { const char *driver = NULL; gboolean initialized = FALSE; - NMPObject * obj; + NMPObject *obj; nm_assert(obj_orig || *obj_new); nm_assert(obj_new); @@ -695,8 +699,8 @@ _nmp_object_fixup_link_udev_fields(NMPObject **obj_new, NMPObject *obj_orig, gbo } static void -_nmp_object_fixup_link_master_connected(NMPObject ** obj_new, - NMPObject * obj_orig, +_nmp_object_fixup_link_master_connected(NMPObject **obj_new, + NMPObject *obj_orig, const NMPCache *cache) { NMPObject *obj; @@ -775,7 +779,7 @@ NMPObject * nmp_object_new(NMPObjectType obj_type, gconstpointer plobj) { const NMPClass *klass = nmp_class_from_type(obj_type); - NMPObject * obj; + NMPObject *obj; obj = _nmp_object_new_from_class(klass); if (plobj) @@ -891,9 +895,9 @@ nmp_object_stackinit_id_ip6_address(NMPObject *obj, int ifindex, const struct in /*****************************************************************************/ const char * -nmp_object_to_string(const NMPObject * obj, +nmp_object_to_string(const NMPObject *obj, NMPObjectToStringMode to_string_mode, - char * buf, + char *buf, gsize buf_size) { const NMPClass *klass; @@ -937,13 +941,13 @@ nmp_object_to_string(const NMPObject * obj, } static const char * -_vt_cmd_obj_to_string_link(const NMPObject * obj, +_vt_cmd_obj_to_string_link(const NMPObject *obj, NMPObjectToStringMode to_string_mode, - char * buf, + char *buf, gsize buf_size) { const NMPClass *klass = NMP_OBJECT_GET_CLASS(obj); - char * b = buf; + char *b = buf; switch (to_string_mode) { case NMP_OBJECT_TO_STRING_ID: @@ -982,14 +986,14 @@ _vt_cmd_obj_to_string_link(const NMPObject * obj, } static const char * -_vt_cmd_obj_to_string_lnk_vlan(const NMPObject * obj, +_vt_cmd_obj_to_string_lnk_vlan(const NMPObject *obj, NMPObjectToStringMode to_string_mode, - char * buf, + char *buf, gsize buf_size) { const NMPClass *klass; char buf2[sizeof(_nm_utils_to_string_buffer)]; - char * b; + char *b; gsize l; klass = NMP_OBJECT_GET_CLASS(obj); @@ -1046,14 +1050,14 @@ _vt_cmd_obj_to_string_lnk_vlan(const NMPObject * obj, } static const char * -_vt_cmd_obj_to_string_lnk_wireguard(const NMPObject * obj, +_vt_cmd_obj_to_string_lnk_wireguard(const NMPObject *obj, NMPObjectToStringMode to_string_mode, - char * buf, + char *buf, gsize buf_size) { const NMPClass *klass; char buf2[sizeof(_nm_utils_to_string_buffer)]; - char * b; + char *b; guint i; klass = NMP_OBJECT_GET_CLASS(obj); @@ -1100,7 +1104,7 @@ _vt_cmd_obj_to_string_lnk_wireguard(const NMPObject * obj, #define _vt_cmd_plobj_to_string_id(type, plat_type, ...) \ static const char *_vt_cmd_plobj_to_string_id_##type(const NMPlatformObject *_obj, \ - char * buf, \ + char *buf, \ gsize buf_len) \ { \ plat_type *const obj = (plat_type *) _obj; \ @@ -1740,8 +1744,7 @@ _vt_cmd_obj_is_alive_ipx_route(const NMPObject *obj) * Instead we create a dead object, and nmp_cache_update_netlink() * will remove the old version of the update. **/ - return NMP_OBJECT_CAST_IP_ROUTE(obj)->ifindex > 0 - && !NM_FLAGS_HAS(obj->ip_route.r_rtm_flags, RTM_F_CLONED); + return !NM_FLAGS_HAS(NMP_OBJECT_CAST_IP_ROUTE(obj)->r_rtm_flags, RTM_F_CLONED); } static gboolean @@ -1825,7 +1828,7 @@ static const guint8 _supported_cache_ids_routing_rules[] = { static void _vt_dedup_obj_destroy(NMDedupMultiObj *obj) { - NMPObject * o = (NMPObject *) obj; + NMPObject *o = (NMPObject *) obj; const NMPClass *klass; nm_assert(o->parent._ref_count == 0); @@ -1907,7 +1910,7 @@ nmp_cache_link_connected_for_slave(int ifindex_master, const NMPObject *slave) * Returns: %TRUE, if @master->link.connected should be flipped/toggled. **/ gboolean -nmp_cache_link_connected_needs_toggle(const NMPCache * cache, +nmp_cache_link_connected_needs_toggle(const NMPCache *cache, const NMPObject *master, const NMPObject *potential_slave, const NMPObject *ignore_slave) @@ -1972,7 +1975,7 @@ nmp_cache_link_connected_needs_toggle(const NMPCache * cache, * The connected flag of that master should be toggled. */ const NMPObject * -nmp_cache_link_connected_needs_toggle_by_ifindex(const NMPCache * cache, +nmp_cache_link_connected_needs_toggle_by_ifindex(const NMPCache *cache, int master_ifindex, const NMPObject *potential_slave, const NMPObject *ignore_slave) @@ -1990,7 +1993,7 @@ nmp_cache_link_connected_needs_toggle_by_ifindex(const NMPCache * cache, /*****************************************************************************/ static const NMDedupMultiEntry * -_lookup_entry_with_idx_type(const NMPCache * cache, +_lookup_entry_with_idx_type(const NMPCache *cache, NMPCacheIdType cache_id_type, const NMPObject *obj) { @@ -2014,7 +2017,7 @@ _lookup_entry(const NMPCache *cache, const NMPObject *obj) } const NMDedupMultiEntry * -nmp_cache_lookup_entry_with_idx_type(const NMPCache * cache, +nmp_cache_lookup_entry_with_idx_type(const NMPCache *cache, NMPCacheIdType cache_id_type, const NMPObject *obj) { @@ -2063,7 +2066,7 @@ nmp_cache_lookup_link(const NMPCache *cache, int ifindex) /*****************************************************************************/ const NMDedupMultiHeadEntry * -nmp_cache_lookup_all(const NMPCache * cache, +nmp_cache_lookup_all(const NMPCache *cache, NMPCacheIdType cache_id_type, const NMPObject *select_obj) { @@ -2143,7 +2146,15 @@ nmp_lookup_init_object(NMPLookup *lookup, NMPObjectType obj_type, int ifindex) NMP_OBJECT_TYPE_QDISC, NMP_OBJECT_TYPE_TFILTER)); - if (ifindex <= 0) { + if (G_UNLIKELY( + (ifindex < 0) + || (ifindex == 0 + && !NM_IN_SET(obj_type, NMP_OBJECT_TYPE_IP4_ROUTE, NMP_OBJECT_TYPE_IP6_ROUTE)))) { + /* This function used to have a fallback that meant to lookup all objects, if + * ifindex is non-positive. As routes can have a zero ifindex, that fallback is + * confusing and no longer supported. Only have this code, to catch accidental bugs + * after the API change. */ + nm_assert_not_reached(); return nmp_lookup_init_obj_type(lookup, obj_type); } @@ -2220,7 +2231,7 @@ nmp_lookup_init_ip4_route_by_weak_id(NMPLookup *lookup, } const NMPLookup * -nmp_lookup_init_ip6_route_by_weak_id(NMPLookup * lookup, +nmp_lookup_init_ip6_route_by_weak_id(NMPLookup *lookup, const struct in6_addr *network, guint plen, guint32 metric, @@ -2269,10 +2280,10 @@ nmp_cache_lookup_to_array(const NMDedupMultiHeadEntry *head_entry, NMPObjectType obj_type, gboolean visible_only) { - const NMPClass * klass = nmp_class_from_type(obj_type); + const NMPClass *klass = nmp_class_from_type(obj_type); NMDedupMultiIter iter; const NMPObject *o; - GArray * array; + GArray *array; g_return_val_if_fail(klass, NULL); @@ -2289,19 +2300,19 @@ nmp_cache_lookup_to_array(const NMDedupMultiHeadEntry *head_entry, /*****************************************************************************/ const NMPObject * -nmp_cache_lookup_link_full(const NMPCache * cache, +nmp_cache_lookup_link_full(const NMPCache *cache, int ifindex, - const char * ifname, + const char *ifname, gboolean visible_only, NMLinkType link_type, NMPObjectMatchFn match_fn, gpointer user_data) { NMPObject obj_needle; - const NMPObject * obj; + const NMPObject *obj; NMDedupMultiIter iter; const NMDedupMultiHeadEntry *head_entry; - const NMPlatformLink * link = NULL; + const NMPlatformLink *link = NULL; NMPLookup lookup; if (ifindex > 0) { @@ -2369,8 +2380,8 @@ _obj_get_add_mode(const NMPObject *obj) static void _idxcache_update_order_for_dump(NMPCache *cache, const NMDedupMultiEntry *entry) { - const NMPClass * klass; - const guint8 * i_idx_type; + const NMPClass *klass; + const guint8 *i_idx_type; const NMDedupMultiEntry *entry2; nm_dedup_multi_entry_reorder(entry, NULL, TRUE); @@ -2396,7 +2407,7 @@ _idxcache_update_order_for_dump(NMPCache *cache, const NMDedupMultiEntry *entry) } static void -_idxcache_update_other_cache_ids(NMPCache * cache, +_idxcache_update_other_cache_ids(NMPCache *cache, NMPCacheIdType cache_id_type, const NMPObject *obj_old, const NMPObject *obj_new, @@ -2405,7 +2416,7 @@ _idxcache_update_other_cache_ids(NMPCache * cache, const NMDedupMultiEntry *entry_new; const NMDedupMultiEntry *entry_old; const NMDedupMultiEntry *entry_order; - NMDedupMultiIdxType * idx_type; + NMDedupMultiIdxType *idx_type; nm_assert(obj_new || obj_old); nm_assert(!obj_new || NMP_OBJECT_GET_TYPE(obj_new) != NMP_OBJECT_TYPE_UNKNOWN); @@ -2474,15 +2485,15 @@ _idxcache_update_other_cache_ids(NMPCache * cache, } static void -_idxcache_update(NMPCache * cache, - const NMDedupMultiEntry * entry_old, - NMPObject * obj_new, +_idxcache_update(NMPCache *cache, + const NMDedupMultiEntry *entry_old, + NMPObject *obj_new, gboolean is_dump, const NMDedupMultiEntry **out_entry_new) { - const NMPClass * klass; - const guint8 * i_idx_type; - NMDedupMultiIdxType * idx_type_o = _idx_type_get(cache, NMP_CACHE_ID_TYPE_OBJECT_TYPE); + const NMPClass *klass; + const guint8 *i_idx_type; + NMDedupMultiIdxType *idx_type_o = _idx_type_get(cache, NMP_CACHE_ID_TYPE_OBJECT_TYPE); const NMDedupMultiEntry *entry_new = NULL; nm_auto_nmpobj const NMPObject *obj_old = NULL; @@ -2559,14 +2570,14 @@ _idxcache_update(NMPCache * cache, } NMPCacheOpsType -nmp_cache_remove(NMPCache * cache, - const NMPObject * obj_needle, +nmp_cache_remove(NMPCache *cache, + const NMPObject *obj_needle, gboolean equals_by_ptr, gboolean only_dirty, const NMPObject **out_obj_old) { const NMDedupMultiEntry *entry_old; - const NMPObject * obj_old; + const NMPObject *obj_old; entry_old = _lookup_entry(cache, obj_needle); @@ -2593,14 +2604,14 @@ nmp_cache_remove(NMPCache * cache, } NMPCacheOpsType -nmp_cache_remove_netlink(NMPCache * cache, - const NMPObject * obj_needle, +nmp_cache_remove_netlink(NMPCache *cache, + const NMPObject *obj_needle, const NMPObject **out_obj_old, const NMPObject **out_obj_new) { - const NMDedupMultiEntry *entry_old; - const NMDedupMultiEntry *entry_new = NULL; - const NMPObject * obj_old; + const NMDedupMultiEntry *entry_old; + const NMDedupMultiEntry *entry_new = NULL; + const NMPObject *obj_old; nm_auto_nmpobj NMPObject *obj_new = NULL; entry_old = _lookup_entry(cache, obj_needle); @@ -2679,15 +2690,15 @@ nmp_cache_remove_netlink(NMPCache * cache, * and @out_obj_new will be set accordingly. **/ NMPCacheOpsType -nmp_cache_update_netlink(NMPCache * cache, - NMPObject * obj_hand_over, +nmp_cache_update_netlink(NMPCache *cache, + NMPObject *obj_hand_over, gboolean is_dump, const NMPObject **out_obj_old, const NMPObject **out_obj_new) { const NMDedupMultiEntry *entry_old; const NMDedupMultiEntry *entry_new; - const NMPObject * obj_old; + const NMPObject *obj_old; gboolean is_alive; nm_assert(cache); @@ -2789,20 +2800,20 @@ nmp_cache_update_netlink(NMPCache * cache, } NMPCacheOpsType -nmp_cache_update_netlink_route(NMPCache * cache, - NMPObject * obj_hand_over, +nmp_cache_update_netlink_route(NMPCache *cache, + NMPObject *obj_hand_over, gboolean is_dump, guint16 nlmsgflags, const NMPObject **out_obj_old, const NMPObject **out_obj_new, const NMPObject **out_obj_replace, - gboolean * out_resync_required) + gboolean *out_resync_required) { NMDedupMultiIter iter; - const NMDedupMultiEntry * entry_old; - const NMDedupMultiEntry * entry_new; - const NMDedupMultiEntry * entry_cur; - const NMDedupMultiEntry * entry_replace; + const NMDedupMultiEntry *entry_old; + const NMDedupMultiEntry *entry_new; + const NMDedupMultiEntry *entry_cur; + const NMDedupMultiEntry *entry_replace; const NMDedupMultiHeadEntry *head_entry; gboolean is_alive; NMPCacheOpsType ops_type = NMP_CACHE_OPS_UNCHANGED; @@ -2937,16 +2948,16 @@ out: } NMPCacheOpsType -nmp_cache_update_link_udev(NMPCache * cache, +nmp_cache_update_link_udev(NMPCache *cache, int ifindex, struct udev_device *udevice, - const NMPObject ** out_obj_old, - const NMPObject ** out_obj_new) + const NMPObject **out_obj_old, + const NMPObject **out_obj_new) { - const NMPObject *obj_old; + const NMPObject *obj_old; nm_auto_nmpobj NMPObject *obj_new = NULL; - const NMDedupMultiEntry * entry_old; - const NMDedupMultiEntry * entry_new; + const NMDedupMultiEntry *entry_old; + const NMDedupMultiEntry *entry_new; entry_old = nmp_cache_lookup_entry_link(cache, ifindex); @@ -2997,14 +3008,14 @@ nmp_cache_update_link_udev(NMPCache * cache, } NMPCacheOpsType -nmp_cache_update_link_master_connected(NMPCache * cache, +nmp_cache_update_link_master_connected(NMPCache *cache, int ifindex, const NMPObject **out_obj_old, const NMPObject **out_obj_new) { - const NMDedupMultiEntry *entry_old; - const NMDedupMultiEntry *entry_new = NULL; - const NMPObject * obj_old; + const NMDedupMultiEntry *entry_old; + const NMDedupMultiEntry *entry_new = NULL; + const NMPObject *obj_old; nm_auto_nmpobj NMPObject *obj_new = NULL; entry_old = nmp_cache_lookup_entry_link(cache, ifindex); diff --git a/src/libnm-platform/nmp-object.h b/src/libnm-platform/nmp-object.h index bf140d78..784dcc2d 100644 --- a/src/libnm-platform/nmp-object.h +++ b/src/libnm-platform/nmp-object.h @@ -170,9 +170,9 @@ typedef enum { typedef struct { NMDedupMultiObjClass parent; - const char * obj_type_name; - const char * signal_type; - const guint8 * supported_cache_ids; + const char *obj_type_name; + const char *signal_type; + const guint8 *supported_cache_ids; int sizeof_data; int sizeof_public; int addr_family; @@ -189,9 +189,9 @@ typedef struct { void (*cmd_obj_dispose)(NMPObject *obj); gboolean (*cmd_obj_is_alive)(const NMPObject *obj); gboolean (*cmd_obj_is_visible)(const NMPObject *obj); - const char *(*cmd_obj_to_string)(const NMPObject * obj, + const char *(*cmd_obj_to_string)(const NMPObject *obj, NMPObjectToStringMode to_string_mode, - char * buf, + char *buf, gsize buf_size); /* functions that operate on NMPlatformObject */ @@ -302,7 +302,7 @@ typedef struct { typedef struct { NMPlatformLnkWireGuard _public; - const NMPWireGuardPeer * peers; + const NMPWireGuardPeer *peers; const NMPWireGuardAllowedIP *_allowed_ips_buf; guint peers_len; guint _allowed_ips_buf_len; @@ -662,7 +662,7 @@ nmp_object_ref_set_up_cast(gpointer pp, gconstpointer obj) { gboolean _changed = FALSE; const NMPObject *p; - gconstpointer * pp2 = pp; + gconstpointer *pp2 = pp; nm_assert(!pp2 || !*pp2 || NMP_OBJECT_IS_VALID(NMP_OBJECT_UP_CAST(*pp2))); nm_assert(!obj || NMP_OBJECT_IS_VALID(NMP_OBJECT_UP_CAST(obj))); @@ -699,9 +699,9 @@ const NMPObject *nmp_object_stackinit_id_ip4_address(NMPObject *obj, const NMPObject * nmp_object_stackinit_id_ip6_address(NMPObject *obj, int ifindex, const struct in6_addr *address); -const char *nmp_object_to_string(const NMPObject * obj, +const char *nmp_object_to_string(const NMPObject *obj, NMPObjectToStringMode to_string_mode, - char * buf, + char *buf, gsize buf_size); void nmp_object_hash_update(const NMPObject *obj, NMHashState *h); @@ -758,7 +758,7 @@ _nm_auto_nmpobj_cleanup(gpointer p) typedef struct _NMPCache NMPCache; -typedef void (*NMPCachePreHook)(NMPCache * cache, +typedef void (*NMPCachePreHook)(NMPCache *cache, const NMPObject *old, const NMPObject *new, NMPCacheOpsType ops_type, @@ -766,12 +766,12 @@ typedef void (*NMPCachePreHook)(NMPCache * cache, typedef gboolean (*NMPObjectMatchFn)(const NMPObject *obj, gpointer user_data); const NMDedupMultiEntry *nmp_cache_lookup_entry(const NMPCache *cache, const NMPObject *obj); -const NMDedupMultiEntry *nmp_cache_lookup_entry_with_idx_type(const NMPCache * cache, +const NMDedupMultiEntry *nmp_cache_lookup_entry_with_idx_type(const NMPCache *cache, NMPCacheIdType cache_id_type, const NMPObject *obj); const NMDedupMultiEntry *nmp_cache_lookup_entry_link(const NMPCache *cache, int ifindex); -const NMPObject * nmp_cache_lookup_obj(const NMPCache *cache, const NMPObject *obj); -const NMPObject * nmp_cache_lookup_link(const NMPCache *cache, int ifindex); +const NMPObject *nmp_cache_lookup_obj(const NMPCache *cache, const NMPObject *obj); +const NMPObject *nmp_cache_lookup_link(const NMPCache *cache, int ifindex); typedef struct _NMPLookup NMPLookup; @@ -780,7 +780,7 @@ struct _NMPLookup { NMPObject selector_obj; }; -const NMDedupMultiHeadEntry *nmp_cache_lookup_all(const NMPCache * cache, +const NMDedupMultiHeadEntry *nmp_cache_lookup_all(const NMPCache *cache, NMPCacheIdType cache_id_type, const NMPObject *select_obj); @@ -800,7 +800,7 @@ const NMPLookup *nmp_lookup_init_ip4_route_by_weak_id(NMPLookup *lookup, guint plen, guint32 metric, guint8 tos); -const NMPLookup *nmp_lookup_init_ip6_route_by_weak_id(NMPLookup * lookup, +const NMPLookup *nmp_lookup_init_ip6_route_by_weak_id(NMPLookup *lookup, const struct in6_addr *network, guint plen, guint32 metric, @@ -858,20 +858,20 @@ nmp_cache_iter_next_link(NMDedupMultiIter *iter, const NMPlatformLink **out_obj) #define nmp_cache_iter_for_each_link(iter, head, obj) \ for (nm_dedup_multi_iter_init((iter), (head)); nmp_cache_iter_next_link((iter), (obj));) -const NMPObject *nmp_cache_lookup_link_full(const NMPCache * cache, +const NMPObject *nmp_cache_lookup_link_full(const NMPCache *cache, int ifindex, - const char * ifname, + const char *ifname, gboolean visible_only, NMLinkType link_type, NMPObjectMatchFn match_fn, gpointer user_data); gboolean nmp_cache_link_connected_for_slave(int ifindex_master, const NMPObject *slave); -gboolean nmp_cache_link_connected_needs_toggle(const NMPCache * cache, +gboolean nmp_cache_link_connected_needs_toggle(const NMPCache *cache, const NMPObject *master, const NMPObject *potential_slave, const NMPObject *ignore_slave); -const NMPObject *nmp_cache_link_connected_needs_toggle_by_ifindex(const NMPCache * cache, +const NMPObject *nmp_cache_link_connected_needs_toggle_by_ifindex(const NMPCache *cache, int master_ifindex, const NMPObject *potential_slave, const NMPObject *ignore_slave); @@ -880,42 +880,42 @@ gboolean nmp_cache_use_udev_get(const NMPCache *cache); void nmtst_assert_nmp_cache_is_consistent(const NMPCache *cache); -NMPCacheOpsType nmp_cache_remove(NMPCache * cache, - const NMPObject * obj_needle, +NMPCacheOpsType nmp_cache_remove(NMPCache *cache, + const NMPObject *obj_needle, gboolean equals_by_ptr, gboolean only_dirty, const NMPObject **out_obj_old); -NMPCacheOpsType nmp_cache_remove_netlink(NMPCache * cache, - const NMPObject * obj_needle, +NMPCacheOpsType nmp_cache_remove_netlink(NMPCache *cache, + const NMPObject *obj_needle, const NMPObject **out_obj_old, const NMPObject **out_obj_new); -NMPCacheOpsType nmp_cache_update_netlink(NMPCache * cache, - NMPObject * obj_hand_over, +NMPCacheOpsType nmp_cache_update_netlink(NMPCache *cache, + NMPObject *obj_hand_over, gboolean is_dump, const NMPObject **out_obj_old, const NMPObject **out_obj_new); -NMPCacheOpsType nmp_cache_update_netlink_route(NMPCache * cache, - NMPObject * obj_hand_over, +NMPCacheOpsType nmp_cache_update_netlink_route(NMPCache *cache, + NMPObject *obj_hand_over, gboolean is_dump, guint16 nlmsgflags, const NMPObject **out_obj_old, const NMPObject **out_obj_new, const NMPObject **out_obj_replace, - gboolean * out_resync_required); -NMPCacheOpsType nmp_cache_update_link_udev(NMPCache * cache, + gboolean *out_resync_required); +NMPCacheOpsType nmp_cache_update_link_udev(NMPCache *cache, int ifindex, struct udev_device *udevice, - const NMPObject ** out_obj_old, - const NMPObject ** out_obj_new); -NMPCacheOpsType nmp_cache_update_link_master_connected(NMPCache * cache, + const NMPObject **out_obj_old, + const NMPObject **out_obj_new); +NMPCacheOpsType nmp_cache_update_link_master_connected(NMPCache *cache, int ifindex, const NMPObject **out_obj_old, const NMPObject **out_obj_new); static inline const NMDedupMultiEntry * -nmp_cache_reresolve_main_entry(NMPCache * cache, +nmp_cache_reresolve_main_entry(NMPCache *cache, const NMDedupMultiEntry *entry, - const NMPLookup * lookup) + const NMPLookup *lookup) { const NMDedupMultiEntry *main_entry; @@ -944,7 +944,7 @@ NMPCache *nmp_cache_new(NMDedupMultiIndex *multi_idx, gboolean use_udev); void nmp_cache_free(NMPCache *cache); static inline void -ASSERT_nmp_cache_ops(const NMPCache * cache, +ASSERT_nmp_cache_ops(const NMPCache *cache, NMPCacheOpsType ops_type, const NMPObject *obj_old, const NMPObject *obj_new) @@ -1024,7 +1024,7 @@ nm_platform_lookup_object(NMPlatform *platform, NMPObjectType obj_type, int ifin } static inline GPtrArray * -nm_platform_lookup_object_clone(NMPlatform * platform, +nm_platform_lookup_object_clone(NMPlatform *platform, NMPObjectType obj_type, int ifindex, NMPObjectPredicateFunc predicate, @@ -1046,7 +1046,7 @@ nm_platform_lookup_route_default(NMPlatform *platform, NMPObjectType obj_type) } static inline GPtrArray * -nm_platform_lookup_route_default_clone(NMPlatform * platform, +nm_platform_lookup_route_default_clone(NMPlatform *platform, NMPObjectType obj_type, NMPObjectPredicateFunc predicate, gpointer user_data) @@ -1071,7 +1071,7 @@ nm_platform_lookup_ip4_route_by_weak_id(NMPlatform *platform, } static inline const NMDedupMultiHeadEntry * -nm_platform_lookup_ip6_route_by_weak_id(NMPlatform * platform, +nm_platform_lookup_ip6_route_by_weak_id(NMPlatform *platform, const struct in6_addr *network, guint plen, guint32 metric, @@ -1085,7 +1085,7 @@ nm_platform_lookup_ip6_route_by_weak_id(NMPlatform * platform, } static inline const NMDedupMultiHeadEntry * -nm_platform_lookup_object_by_addr_family(NMPlatform * platform, +nm_platform_lookup_object_by_addr_family(NMPlatform *platform, NMPObjectType obj_type, int addr_family) { @@ -1112,6 +1112,21 @@ nmp_object_get_assume_config_once(const NMPObject *obj) } } +static inline gboolean +nmp_object_get_force_commit(const NMPObject *obj) +{ + switch (NMP_OBJECT_GET_TYPE(obj)) { + case NMP_OBJECT_TYPE_IP4_ADDRESS: + case NMP_OBJECT_TYPE_IP6_ADDRESS: + return NMP_OBJECT_CAST_IP_ADDRESS(obj)->a_force_commit; + case NMP_OBJECT_TYPE_IP4_ROUTE: + case NMP_OBJECT_TYPE_IP6_ROUTE: + return NMP_OBJECT_CAST_IP_ROUTE(obj)->r_force_commit; + default: + return nm_assert_unreachable_val(FALSE); + } +} + static inline const char * nmp_object_link_get_ifname(const NMPObject *obj) { diff --git a/src/libnm-platform/nmp-route-manager.c b/src/libnm-platform/nmp-route-manager.c new file mode 100644 index 00000000..c31c9806 --- /dev/null +++ b/src/libnm-platform/nmp-route-manager.c @@ -0,0 +1,839 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include "libnm-glib-aux/nm-default-glib-i18n-lib.h" + +#include "nmp-route-manager.h" + +#include +#include + +#include "libnm-log-core/nm-logging.h" +#include "libnm-std-aux/c-list-util.h" +#include "nmp-object.h" + +/*****************************************************************************/ + +struct _NMPRouteManager { + NMPlatform *platform; + GHashTable *by_obj; + GHashTable *by_user_tag; + GHashTable *by_data; + CList by_obj_lst_heads[3]; + guint ref_count; +}; + +/*****************************************************************************/ + +#define _NMLOG_DOMAIN LOGD_PLATFORM +#define _NMLOG_PREFIX_NAME "route-manager" + +#define _NMLOG(level, ...) __NMLOG_DEFAULT(level, LOGD_PLATFORM, _NMLOG_PREFIX_NAME, __VA_ARGS__) + +/*****************************************************************************/ + +static gboolean +NMP_IS_ROUTE_MANAGER(gpointer self) +{ + return self && ((NMPRouteManager *) self)->ref_count > 0 + && NM_IS_PLATFORM(((NMPRouteManager *) self)->platform); +} + +/*****************************************************************************/ + +typedef struct { + const NMPObject *obj; + gconstpointer user_tag; + CList obj_lst; + CList user_tag_lst; + + /* track_priority_val zero is special: those are weakly tracked rules. + * That means: NetworkManager will restore them only if it removed them earlier. + * But it will not remove or add them otherwise. + * + * Otherwise, the track_priority_val goes together with track_priority_present. + * In case of one rule being tracked multiple times (with different priorities), + * the one with higher priority wins. See _track_obj_data_get_best_data(). + * Then, the winning present state either enforces that the rule is present + * or absent. + * + * If a rules is not tracked at all, it is ignored by NetworkManager. Assuming + * that it was added externally by the user. But unlike weakly tracked rules, + * NM will *not* restore such rules if NetworkManager themself removed them. */ + guint32 track_priority_val; + bool track_priority_present : 1; + + bool dirty : 1; +} TrackData; + +typedef enum { + CONFIG_STATE_NONE = 0, + CONFIG_STATE_ADDED_BY_US = 1, + CONFIG_STATE_REMOVED_BY_US = 2, + + /* ConfigState encodes whether the rule was touched by us at all (CONFIG_STATE_NONE). + * + * Maybe we would only need to track whether we touched the rule at all. But we + * track it more in detail what we did: did we add it (CONFIG_STATE_ADDED_BY_US) + * or did we remove it (CONFIG_STATE_REMOVED_BY_US)? + * Finally, we need CONFIG_STATE_OWNED_BY_US, which means that we didn't actively + * add/remove it, but whenever we are about to undo the add/remove, we need to do it. + * In that sense, CONFIG_STATE_OWNED_BY_US is really just a flag that we unconditionally + * force the state next time when necessary. */ + CONFIG_STATE_OWNED_BY_US = 3, +} ConfigState; + +typedef struct { + const NMPObject *obj; + CList obj_lst_head; + + CList by_obj_lst; + + /* indicates whether we configured/removed the rule (during sync()). We need that, so + * if the rule gets untracked, that we know to remove/restore it. + * + * This makes NMPRouteManager stateful (beyond the configuration that indicates + * which rules are tracked). + * After a restart, NetworkManager would no longer remember which rules were added + * by us. + * + * That is partially fixed by NetworkManager taking over the rules that it + * actively configures (see %NMP_ROUTE_MANAGER_EXTERN_WEAKLY_TRACKED_USER_TAG). */ + ConfigState config_state; +} TrackObjData; + +typedef struct { + gconstpointer user_tag; + CList user_tag_lst_head; +} TrackUserTagData; + +/*****************************************************************************/ + +static void _track_data_untrack(NMPRouteManager *self, + TrackData *track_data, + gboolean remove_user_tag_data, + gboolean make_owned_by_us); + +/*****************************************************************************/ + +static CList * +_by_obj_lst_head(NMPRouteManager *self, NMPObjectType obj_type) +{ + G_STATIC_ASSERT(G_N_ELEMENTS(self->by_obj_lst_heads) == 3); + + switch (obj_type) { + case NMP_OBJECT_TYPE_IP4_ROUTE: + return &self->by_obj_lst_heads[0]; + case NMP_OBJECT_TYPE_IP6_ROUTE: + return &self->by_obj_lst_heads[1]; + case NMP_OBJECT_TYPE_ROUTING_RULE: + return &self->by_obj_lst_heads[2]; + default: + return nm_assert_unreachable_val(NULL); + } +} + +/*****************************************************************************/ + +static void +_track_data_assert(const TrackData *track_data, gboolean linked) +{ + nm_assert(track_data); + nm_assert(NM_IN_SET(NMP_OBJECT_GET_TYPE(track_data->obj), + NMP_OBJECT_TYPE_IP4_ROUTE, + NMP_OBJECT_TYPE_IP6_ROUTE, + NMP_OBJECT_TYPE_ROUTING_RULE)); + nm_assert(nmp_object_is_visible(track_data->obj)); + nm_assert(track_data->user_tag); + nm_assert(!linked || !c_list_is_empty(&track_data->obj_lst)); + nm_assert(!linked || !c_list_is_empty(&track_data->user_tag_lst)); +} + +static guint +_track_data_hash(gconstpointer data) +{ + const TrackData *track_data = data; + NMHashState h; + + _track_data_assert(track_data, FALSE); + + nm_hash_init(&h, 269297543u); + nmp_object_id_hash_update(track_data->obj, &h); + nm_hash_update_val(&h, track_data->user_tag); + return nm_hash_complete(&h); +} + +static gboolean +_track_data_equal(gconstpointer data_a, gconstpointer data_b) +{ + const TrackData *track_data_a = data_a; + const TrackData *track_data_b = data_b; + + _track_data_assert(track_data_a, FALSE); + _track_data_assert(track_data_b, FALSE); + + return track_data_a->user_tag == track_data_b->user_tag + && nmp_object_id_equal(track_data_a->obj, track_data_b->obj); +} + +static void +_track_data_destroy(gpointer data) +{ + TrackData *track_data = data; + + _track_data_assert(track_data, FALSE); + + c_list_unlink_stale(&track_data->obj_lst); + c_list_unlink_stale(&track_data->user_tag_lst); + nmp_object_unref(track_data->obj); + nm_g_slice_free(track_data); +} + +static const TrackData * +_track_obj_data_get_best_data(TrackObjData *obj_data) +{ + TrackData *track_data; + const TrackData *td_best = NULL; + + c_list_for_each_entry (track_data, &obj_data->obj_lst_head, obj_lst) { + _track_data_assert(track_data, TRUE); + + if (td_best) { + if (td_best->track_priority_val > track_data->track_priority_val) + continue; + if (td_best->track_priority_val == track_data->track_priority_val) { + if (td_best->track_priority_present || !track_data->track_priority_present) { + /* if the priorities are identical, then "present" wins over + * "!present" (absent). */ + continue; + } + } + } + + td_best = track_data; + } + + return td_best; +} + +static guint +_track_obj_data_hash(gconstpointer data) +{ + const TrackObjData *obj_data = data; + + return nmp_object_id_hash(obj_data->obj); +} + +static gboolean +_track_obj_data_equal(gconstpointer data_a, gconstpointer data_b) +{ + const TrackObjData *obj_data_a = data_a; + const TrackObjData *obj_data_b = data_b; + + return nmp_object_id_equal(obj_data_a->obj, obj_data_b->obj); +} + +static void +_track_obj_data_destroy(gpointer data) +{ + TrackObjData *obj_data = data; + + c_list_unlink_stale(&obj_data->obj_lst_head); + c_list_unlink_stale(&obj_data->by_obj_lst); + nmp_object_unref(obj_data->obj); + nm_g_slice_free(obj_data); +} + +static void +_track_user_tag_data_destroy(gpointer data) +{ + TrackUserTagData *user_tag_data = data; + + c_list_unlink_stale(&user_tag_data->user_tag_lst_head); + nm_g_slice_free(user_tag_data); +} + +static TrackData * +_track_data_lookup(GHashTable *by_data, const NMPObject *obj, gconstpointer user_tag) +{ + TrackData track_data_needle = { + .obj = obj, + .user_tag = user_tag, + }; + + return g_hash_table_lookup(by_data, &track_data_needle); +} + +/*****************************************************************************/ + +/** + * nmp_route_manager_track: + * @self: the #NMPRouteManager instance + * @obj_type: the NMPObjectType of @obj that we are tracking. + * @obj: the NMPlatformObject (of type NMPObjectType) to track. Usually + * a #NMPlatformRoutingRule, #NMPlatformIP4Route or #NMPlatformIP6Route + * pointer. + * @track_priority: the priority for tracking the rule. Note that + * negative values indicate a forced absence of the rule. Priorities + * are compared with their absolute values (with higher absolute + * value being more important). For example, if you track the same + * rule twice, once with priority -5 and +10, then the rule is + * present (because the positive number is more important). + * The special value 0 indicates weakly-tracked rules. + * @user_tag: the tag associated with tracking this rule. The same tag + * must be used to untrack the rule later. + * @user_tag_untrack: if not %NULL, at the same time untrack this user-tag + * for the same rule. Note that this is different from a plain nmp_route_manager_untrack_rule(), + * because it enforces ownership of the now tracked rule. On the other hand, + * a plain nmp_route_manager_untrack_rule() merely forgets about the tracking. + * The purpose here is to set this to %NMP_ROUTE_MANAGER_EXTERN_WEAKLY_TRACKED_USER_TAG. + * + * Returns: %TRUE, if something changed. + */ +gboolean +nmp_route_manager_track(NMPRouteManager *self, + NMPObjectType obj_type, + gconstpointer obj, + gint32 track_priority, + gconstpointer user_tag, + gconstpointer user_tag_untrack) +{ + NMPObject obj_stack; + const NMPObject *p_obj_stack; + TrackData *track_data; + TrackObjData *obj_data; + TrackUserTagData *user_tag_data; + gboolean changed = FALSE; + gboolean changed_untrack = FALSE; + guint32 track_priority_val; + gboolean track_priority_present; + + g_return_val_if_fail(NMP_IS_ROUTE_MANAGER(self), FALSE); + g_return_val_if_fail(obj, FALSE); + g_return_val_if_fail(user_tag, FALSE); + + /* The route must not be tied to an interface. We can only handle here + * blackhole/unreachable/prohibit route types. */ + g_return_val_if_fail( + obj_type == NMP_OBJECT_TYPE_ROUTING_RULE + || (NM_IN_SET(obj_type, NMP_OBJECT_TYPE_IP4_ROUTE, NMP_OBJECT_TYPE_IP6_ROUTE) + && ((const NMPlatformIPRoute *) obj)->ifindex == 0), + FALSE); + + nm_assert(track_priority != G_MININT32); + + p_obj_stack = nmp_object_stackinit(&obj_stack, obj_type, obj); + + nm_assert(nmp_object_is_visible(p_obj_stack)); + + if (track_priority >= 0) { + track_priority_val = track_priority; + track_priority_present = TRUE; + } else { + track_priority_val = -track_priority; + track_priority_present = FALSE; + } + + track_data = _track_data_lookup(self->by_data, p_obj_stack, user_tag); + + if (!track_data) { + track_data = g_slice_new(TrackData); + *track_data = (TrackData){ + .obj = nm_dedup_multi_index_obj_intern(nm_platform_get_multi_idx(self->platform), + p_obj_stack), + .user_tag = user_tag, + .track_priority_val = track_priority_val, + .track_priority_present = track_priority_present, + .dirty = FALSE, + }; + g_hash_table_add(self->by_data, track_data); + + obj_data = g_hash_table_lookup(self->by_obj, &track_data->obj); + if (!obj_data) { + obj_data = g_slice_new(TrackObjData); + *obj_data = (TrackObjData){ + .obj = nmp_object_ref(track_data->obj), + .obj_lst_head = C_LIST_INIT(obj_data->obj_lst_head), + .config_state = CONFIG_STATE_NONE, + }; + g_hash_table_add(self->by_obj, obj_data); + c_list_link_tail(_by_obj_lst_head(self, obj_type), &obj_data->by_obj_lst); + } + c_list_link_tail(&obj_data->obj_lst_head, &track_data->obj_lst); + + user_tag_data = g_hash_table_lookup(self->by_user_tag, &track_data->user_tag); + if (!user_tag_data) { + user_tag_data = g_slice_new(TrackUserTagData); + *user_tag_data = (TrackUserTagData){ + .user_tag = user_tag, + .user_tag_lst_head = C_LIST_INIT(user_tag_data->user_tag_lst_head), + }; + g_hash_table_add(self->by_user_tag, user_tag_data); + } + c_list_link_tail(&user_tag_data->user_tag_lst_head, &track_data->user_tag_lst); + changed = TRUE; + } else { + track_data->dirty = FALSE; + if (track_data->track_priority_val != track_priority_val + || track_data->track_priority_present != track_priority_present) { + track_data->track_priority_val = track_priority_val; + track_data->track_priority_present = track_priority_present; + changed = TRUE; + } + } + + if (user_tag_untrack) { + if (user_tag != user_tag_untrack) { + TrackData *track_data_untrack; + + track_data_untrack = _track_data_lookup(self->by_data, p_obj_stack, user_tag_untrack); + if (track_data_untrack) { + _track_data_untrack(self, track_data_untrack, FALSE, TRUE); + changed_untrack = TRUE; + } + } else + nm_assert_not_reached(); + } + + _track_data_assert(track_data, TRUE); + + if (changed) { + _LOGD("track [" NM_HASH_OBFUSCATE_PTR_FMT ",%s%u] %s \"%s\"", + NM_HASH_OBFUSCATE_PTR(track_data->user_tag), + (track_data->track_priority_val == 0 + ? "" + : (track_data->track_priority_present ? "+" : "-")), + (guint) track_data->track_priority_val, + NMP_OBJECT_GET_CLASS(track_data->obj)->obj_type_name, + nmp_object_to_string(track_data->obj, NMP_OBJECT_TO_STRING_PUBLIC, NULL, 0)); + } + + return changed || changed_untrack; +} + +static void +_track_data_untrack(NMPRouteManager *self, + TrackData *track_data, + gboolean remove_user_tag_data, + gboolean make_owned_by_us) +{ + TrackObjData *obj_data; + + nm_assert(NMP_IS_ROUTE_MANAGER(self)); + _track_data_assert(track_data, TRUE); + nm_assert(self->by_data); + nm_assert(g_hash_table_lookup(self->by_data, track_data) == track_data); + + _LOGD("untrack [" NM_HASH_OBFUSCATE_PTR_FMT "] %s \"%s\"", + NM_HASH_OBFUSCATE_PTR(track_data->user_tag), + NMP_OBJECT_GET_CLASS(track_data->obj)->obj_type_name, + nmp_object_to_string(track_data->obj, NMP_OBJECT_TO_STRING_PUBLIC, NULL, 0)); + +#if NM_MORE_ASSERTS + { + TrackUserTagData *user_tag_data; + + user_tag_data = g_hash_table_lookup(self->by_user_tag, &track_data->user_tag); + nm_assert(user_tag_data); + nm_assert(c_list_contains(&user_tag_data->user_tag_lst_head, &track_data->user_tag_lst)); + } +#endif + + nm_assert(!c_list_is_empty(&track_data->user_tag_lst)); + + obj_data = g_hash_table_lookup(self->by_obj, &track_data->obj); + nm_assert(obj_data); + nm_assert(c_list_contains(&obj_data->obj_lst_head, &track_data->obj_lst)); + nm_assert(obj_data == g_hash_table_lookup(self->by_obj, &track_data->obj)); + + if (make_owned_by_us) { + if (obj_data->config_state == CONFIG_STATE_NONE) { + /* we need to mark this entry that it requires a touch on the next + * sync. */ + obj_data->config_state = CONFIG_STATE_OWNED_BY_US; + } + } else if (remove_user_tag_data && c_list_length_is(&track_data->user_tag_lst, 1)) + g_hash_table_remove(self->by_user_tag, &track_data->user_tag); + + /* if obj_data is marked to be "added_by_us" or "removed_by_us", we need to keep this entry + * around for the next sync -- so that we can undo what we did earlier. */ + if (obj_data->config_state == CONFIG_STATE_NONE && c_list_length_is(&track_data->obj_lst, 1)) + g_hash_table_remove(self->by_obj, &track_data->obj); + + g_hash_table_remove(self->by_data, track_data); +} + +gboolean +nmp_route_manager_untrack(NMPRouteManager *self, + NMPObjectType obj_type, + gconstpointer obj, + gconstpointer user_tag) +{ + NMPObject obj_stack; + const NMPObject *p_obj_stack; + TrackData *track_data; + gboolean changed = FALSE; + + g_return_val_if_fail(NMP_IS_ROUTE_MANAGER(self), FALSE); + nm_assert(NM_IN_SET(obj_type, + NMP_OBJECT_TYPE_IP4_ROUTE, + NMP_OBJECT_TYPE_IP6_ROUTE, + NMP_OBJECT_TYPE_ROUTING_RULE)); + g_return_val_if_fail(obj, FALSE); + g_return_val_if_fail(user_tag, FALSE); + + p_obj_stack = nmp_object_stackinit(&obj_stack, obj_type, obj); + + nm_assert(nmp_object_is_visible(p_obj_stack)); + + track_data = _track_data_lookup(self->by_data, p_obj_stack, user_tag); + if (track_data) { + _track_data_untrack(self, track_data, TRUE, FALSE); + changed = TRUE; + } + + return changed; +} + +void +nmp_route_manager_set_dirty(NMPRouteManager *self, gconstpointer user_tag) +{ + TrackData *track_data; + TrackUserTagData *user_tag_data; + + g_return_if_fail(NMP_IS_ROUTE_MANAGER(self)); + g_return_if_fail(user_tag); + + user_tag_data = g_hash_table_lookup(self->by_user_tag, &user_tag); + if (!user_tag_data) + return; + + c_list_for_each_entry (track_data, &user_tag_data->user_tag_lst_head, user_tag_lst) + track_data->dirty = TRUE; +} + +gboolean +nmp_route_manager_untrack_all(NMPRouteManager *self, + gconstpointer user_tag, + gboolean all /* or only dirty */, + gboolean make_survivors_dirty) +{ + TrackData *track_data; + TrackData *track_data_safe; + TrackUserTagData *user_tag_data; + gboolean changed = FALSE; + + g_return_val_if_fail(NMP_IS_ROUTE_MANAGER(self), FALSE); + g_return_val_if_fail(user_tag, FALSE); + + user_tag_data = g_hash_table_lookup(self->by_user_tag, &user_tag); + if (!user_tag_data) + return FALSE; + + c_list_for_each_entry_safe (track_data, + track_data_safe, + &user_tag_data->user_tag_lst_head, + user_tag_lst) { + if (all || track_data->dirty) { + _track_data_untrack(self, track_data, FALSE, FALSE); + changed = TRUE; + continue; + } + if (make_survivors_dirty) + track_data->dirty = TRUE; + } + if (c_list_is_empty(&user_tag_data->user_tag_lst_head)) + g_hash_table_remove(self->by_user_tag, user_tag_data); + + return changed; +} + +/*****************************************************************************/ + +void +nmp_route_manager_sync(NMPRouteManager *self, NMPObjectType obj_type, gboolean keep_deleted) +{ + const NMDedupMultiHeadEntry *pl_head_entry; + NMDedupMultiIter pl_iter; + const NMPObject *plobj; + gs_unref_ptrarray GPtrArray *objs_to_delete = NULL; + TrackObjData *obj_data; + TrackObjData *obj_data_safe; + CList *by_obj_lst_head; + guint i; + const TrackData *td_best; + + g_return_if_fail(NMP_IS_ROUTE_MANAGER(self)); + g_return_if_fail(NM_IN_SET(obj_type, + NMP_OBJECT_TYPE_IP4_ROUTE, + NMP_OBJECT_TYPE_IP6_ROUTE, + NMP_OBJECT_TYPE_ROUTING_RULE)); + + _LOGD("sync %s%s", + nmp_class_from_type(obj_type)->obj_type_name, + keep_deleted ? " (don't remove any)" : ""); + + if (obj_type == NMP_OBJECT_TYPE_ROUTING_RULE) + pl_head_entry = nm_platform_lookup_obj_type(self->platform, obj_type); + else + pl_head_entry = nm_platform_lookup_object(self->platform, obj_type, 0); + + if (pl_head_entry) { + nmp_cache_iter_for_each (&pl_iter, pl_head_entry, &plobj) { + obj_data = g_hash_table_lookup(self->by_obj, &plobj); + + if (!obj_data) { + /* this obj is not tracked. It was externally added, hence we + * ignore it. */ + continue; + } + + td_best = _track_obj_data_get_best_data(obj_data); + if (td_best) { + if (td_best->track_priority_present) { + if (obj_data->config_state == CONFIG_STATE_OWNED_BY_US) + obj_data->config_state = CONFIG_STATE_ADDED_BY_US; + continue; + } + if (td_best->track_priority_val == 0) { + if (!NM_IN_SET(obj_data->config_state, + CONFIG_STATE_ADDED_BY_US, + CONFIG_STATE_OWNED_BY_US)) { + obj_data->config_state = CONFIG_STATE_NONE; + continue; + } + obj_data->config_state = CONFIG_STATE_NONE; + } + } + + if (keep_deleted) { + _LOGD("forget/leak object added by us: %s \"%s\"", + NMP_OBJECT_GET_CLASS(plobj)->obj_type_name, + nmp_object_to_string(plobj, NMP_OBJECT_TO_STRING_PUBLIC, NULL, 0)); + continue; + } + + if (!objs_to_delete) + objs_to_delete = g_ptr_array_new_with_free_func((GDestroyNotify) nmp_object_unref); + + g_ptr_array_add(objs_to_delete, (gpointer) nmp_object_ref(plobj)); + + obj_data->config_state = CONFIG_STATE_REMOVED_BY_US; + } + } + + if (objs_to_delete) { + for (i = 0; i < objs_to_delete->len; i++) + nm_platform_object_delete(self->platform, objs_to_delete->pdata[i]); + } + + by_obj_lst_head = _by_obj_lst_head(self, obj_type); + + c_list_for_each_entry_safe (obj_data, obj_data_safe, by_obj_lst_head, by_obj_lst) { + nm_assert(NMP_OBJECT_GET_TYPE(obj_data->obj) == obj_type); + + td_best = _track_obj_data_get_best_data(obj_data); + + if (!td_best) { + g_hash_table_remove(self->by_obj, obj_data); + continue; + } + + if (!td_best->track_priority_present) { + if (obj_data->config_state == CONFIG_STATE_OWNED_BY_US) + obj_data->config_state = CONFIG_STATE_REMOVED_BY_US; + continue; + } + if (td_best->track_priority_val == 0) { + if (!NM_IN_SET(obj_data->config_state, + CONFIG_STATE_REMOVED_BY_US, + CONFIG_STATE_OWNED_BY_US)) { + obj_data->config_state = CONFIG_STATE_NONE; + continue; + } + obj_data->config_state = CONFIG_STATE_NONE; + } + + plobj = + nm_platform_lookup_obj(self->platform, NMP_CACHE_ID_TYPE_OBJECT_TYPE, obj_data->obj); + if (plobj) + continue; + + obj_data->config_state = CONFIG_STATE_ADDED_BY_US; + + if (obj_type == NMP_OBJECT_TYPE_ROUTING_RULE) { + nm_platform_routing_rule_add(self->platform, + NMP_NLM_FLAG_ADD, + NMP_OBJECT_CAST_ROUTING_RULE(obj_data->obj)); + } else + nm_platform_ip_route_add(self->platform, NMP_NLM_FLAG_APPEND, obj_data->obj); + } +} + +/*****************************************************************************/ + +void +nmp_route_manager_track_rule_from_platform(NMPRouteManager *self, + NMPlatform *platform, + int addr_family, + gint32 tracking_priority, + gconstpointer user_tag) +{ + NMPLookup lookup; + const NMDedupMultiHeadEntry *head_entry; + NMDedupMultiIter iter; + const NMPObject *o; + + g_return_if_fail(NMP_IS_ROUTE_MANAGER(self)); + + if (!platform) + platform = self->platform; + else + g_return_if_fail(NM_IS_PLATFORM(platform)); + + nm_assert(NM_IN_SET(addr_family, AF_UNSPEC, AF_INET, AF_INET6)); + + nmp_lookup_init_obj_type(&lookup, NMP_OBJECT_TYPE_ROUTING_RULE); + head_entry = nm_platform_lookup(platform, &lookup); + nmp_cache_iter_for_each (&iter, head_entry, &o) { + const NMPlatformRoutingRule *rr = NMP_OBJECT_CAST_ROUTING_RULE(o); + + if (addr_family != AF_UNSPEC && rr->addr_family != addr_family) + continue; + + nmp_route_manager_track_rule(self, rr, tracking_priority, user_tag, NULL); + } +} + +/*****************************************************************************/ + +void +nmp_route_manager_track_rule_default(NMPRouteManager *self, + int addr_family, + gint32 track_priority, + gconstpointer user_tag) +{ + g_return_if_fail(NMP_IS_ROUTE_MANAGER(self)); + + nm_assert(NM_IN_SET(addr_family, AF_UNSPEC, AF_INET, AF_INET6)); + + /* track the default rules. See also `man ip-rule`. */ + + if (NM_IN_SET(addr_family, AF_UNSPEC, AF_INET)) { + nmp_route_manager_track_rule(self, + &((NMPlatformRoutingRule){ + .addr_family = AF_INET, + .priority = 0, + .table = RT_TABLE_LOCAL, + .action = FR_ACT_TO_TBL, + .protocol = RTPROT_KERNEL, + }), + track_priority, + user_tag, + NULL); + nmp_route_manager_track_rule(self, + &((NMPlatformRoutingRule){ + .addr_family = AF_INET, + .priority = 32766, + .table = RT_TABLE_MAIN, + .action = FR_ACT_TO_TBL, + .protocol = RTPROT_KERNEL, + }), + track_priority, + user_tag, + NULL); + nmp_route_manager_track_rule(self, + &((NMPlatformRoutingRule){ + .addr_family = AF_INET, + .priority = 32767, + .table = RT_TABLE_DEFAULT, + .action = FR_ACT_TO_TBL, + .protocol = RTPROT_KERNEL, + }), + track_priority, + user_tag, + NULL); + } + if (NM_IN_SET(addr_family, AF_UNSPEC, AF_INET6)) { + nmp_route_manager_track_rule(self, + &((NMPlatformRoutingRule){ + .addr_family = AF_INET6, + .priority = 0, + .table = RT_TABLE_LOCAL, + .action = FR_ACT_TO_TBL, + .protocol = RTPROT_KERNEL, + }), + track_priority, + user_tag, + NULL); + nmp_route_manager_track_rule(self, + &((NMPlatformRoutingRule){ + .addr_family = AF_INET6, + .priority = 32766, + .table = RT_TABLE_MAIN, + .action = FR_ACT_TO_TBL, + .protocol = RTPROT_KERNEL, + }), + track_priority, + user_tag, + NULL); + } +} + +/*****************************************************************************/ + +NMPRouteManager * +nmp_route_manager_new(NMPlatform *platform) +{ + NMPRouteManager *self; + + g_return_val_if_fail(NM_IS_PLATFORM(platform), NULL); + + G_STATIC_ASSERT_EXPR(G_STRUCT_OFFSET(TrackUserTagData, user_tag) == 0); + + self = g_slice_new(NMPRouteManager); + *self = (NMPRouteManager){ + .ref_count = 1, + .platform = g_object_ref(platform), + .by_data = + g_hash_table_new_full(_track_data_hash, _track_data_equal, NULL, _track_data_destroy), + .by_obj = g_hash_table_new_full(_track_obj_data_hash, + _track_obj_data_equal, + NULL, + _track_obj_data_destroy), + .by_user_tag = g_hash_table_new_full(nm_pdirect_hash, + nm_pdirect_equal, + NULL, + _track_user_tag_data_destroy), + .by_obj_lst_heads[0] = C_LIST_INIT(self->by_obj_lst_heads[0]), + .by_obj_lst_heads[1] = C_LIST_INIT(self->by_obj_lst_heads[1]), + .by_obj_lst_heads[2] = C_LIST_INIT(self->by_obj_lst_heads[2]), + }; + return self; +} + +NMPRouteManager * +nmp_route_manager_ref(NMPRouteManager *self) +{ + g_return_val_if_fail(NMP_IS_ROUTE_MANAGER(self), NULL); + + self->ref_count++; + return self; +} + +void +nmp_route_manager_unref(NMPRouteManager *self) +{ + g_return_if_fail(NMP_IS_ROUTE_MANAGER(self)); + + if (--self->ref_count > 0) + return; + + g_hash_table_destroy(self->by_user_tag); + g_hash_table_destroy(self->by_obj); + g_hash_table_destroy(self->by_data); + nm_assert(c_list_is_empty(&self->by_obj_lst_heads[0])); + nm_assert(c_list_is_empty(&self->by_obj_lst_heads[1])); + nm_assert(c_list_is_empty(&self->by_obj_lst_heads[2])); + g_object_unref(self->platform); + nm_g_slice_free(self); +} diff --git a/src/libnm-platform/nmp-route-manager.h b/src/libnm-platform/nmp-route-manager.h new file mode 100644 index 00000000..97ec3840 --- /dev/null +++ b/src/libnm-platform/nmp-route-manager.h @@ -0,0 +1,79 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#ifndef __NMP_ROUTE_MANAGER_H__ +#define __NMP_ROUTE_MANAGER_H__ + +#include "nm-platform.h" + +/*****************************************************************************/ + +#define NMP_ROUTE_MANAGER_EXTERN_WEAKLY_TRACKED_USER_TAG ((const void *) nmp_route_manager_new) + +typedef struct _NMPRouteManager NMPRouteManager; + +NMPRouteManager *nmp_route_manager_new(NMPlatform *platform); + +NMPRouteManager *nmp_route_manager_ref(NMPRouteManager *self); +void nmp_route_manager_unref(NMPRouteManager *self); + +#define nm_auto_unref_route_manager nm_auto(_nmp_route_manager_unref) +NM_AUTO_DEFINE_FCN0(NMPRouteManager *, _nmp_route_manager_unref, nmp_route_manager_unref); + +gboolean nmp_route_manager_track(NMPRouteManager *self, + NMPObjectType obj_type, + gconstpointer obj, + gint32 track_priority, + gconstpointer user_tag, + gconstpointer user_tag_untrack); + +static inline gboolean +nmp_route_manager_track_rule(NMPRouteManager *self, + const NMPlatformRoutingRule *routing_rule, + gint32 track_priority, + gconstpointer user_tag, + gconstpointer user_tag_untrack) +{ + return nmp_route_manager_track(self, + NMP_OBJECT_TYPE_ROUTING_RULE, + routing_rule, + track_priority, + user_tag, + user_tag_untrack); +} + +void nmp_route_manager_track_rule_default(NMPRouteManager *self, + int addr_family, + gint32 track_priority, + gconstpointer user_tag); + +void nmp_route_manager_track_rule_from_platform(NMPRouteManager *self, + NMPlatform *platform, + int addr_family, + gint32 tracking_priority, + gconstpointer user_tag); + +gboolean nmp_route_manager_untrack(NMPRouteManager *self, + NMPObjectType obj_type, + gconstpointer obj, + gconstpointer user_tag); + +static inline gboolean +nmp_route_manager_untrack_rule(NMPRouteManager *self, + const NMPlatformRoutingRule *routing_rule, + gconstpointer user_tag) +{ + return nmp_route_manager_untrack(self, NMP_OBJECT_TYPE_ROUTING_RULE, routing_rule, user_tag); +} + +void nmp_route_manager_set_dirty(NMPRouteManager *self, gconstpointer user_tag); + +gboolean nmp_route_manager_untrack_all(NMPRouteManager *self, + gconstpointer user_tag, + gboolean all /* or only dirty */, + gboolean make_survivors_dirty); + +void nmp_route_manager_sync(NMPRouteManager *self, NMPObjectType obj_type, gboolean keep_deleted); + +/*****************************************************************************/ + +#endif /* __NMP_ROUTE_MANAGER_H__ */ diff --git a/src/libnm-platform/nmp-rules-manager.c b/src/libnm-platform/nmp-rules-manager.c deleted file mode 100644 index 636c90b2..00000000 --- a/src/libnm-platform/nmp-rules-manager.c +++ /dev/null @@ -1,809 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ - -#include "libnm-glib-aux/nm-default-glib-i18n-lib.h" - -#include "nmp-rules-manager.h" - -#include -#include - -#include "libnm-log-core/nm-logging.h" -#include "libnm-std-aux/c-list-util.h" -#include "nmp-object.h" - -/*****************************************************************************/ - -struct _NMPRulesManager { - NMPlatform *platform; - GHashTable *by_obj; - GHashTable *by_user_tag; - GHashTable *by_data; - guint ref_count; -}; - -/*****************************************************************************/ - -static void _rules_init(NMPRulesManager *self); - -/*****************************************************************************/ - -#define _NMLOG_DOMAIN LOGD_PLATFORM -#define _NMLOG_PREFIX_NAME "rules-manager" - -#define _NMLOG(level, ...) \ - G_STMT_START \ - { \ - const NMLogLevel __level = (level); \ - \ - if (nm_logging_enabled(__level, _NMLOG_DOMAIN)) { \ - _nm_log(__level, \ - _NMLOG_DOMAIN, \ - 0, \ - NULL, \ - NULL, \ - "%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ - _NMLOG_PREFIX_NAME _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ - } \ - } \ - G_STMT_END - -/*****************************************************************************/ - -static gboolean -NMP_IS_RULES_MANAGER(gpointer self) -{ - return self && ((NMPRulesManager *) self)->ref_count > 0 - && NM_IS_PLATFORM(((NMPRulesManager *) self)->platform); -} - -#define _USER_TAG_LOG(user_tag) nm_hash_obfuscate_ptr(1240261787u, (user_tag)) - -/*****************************************************************************/ - -typedef struct { - const NMPObject *obj; - gconstpointer user_tag; - CList obj_lst; - CList user_tag_lst; - - /* track_priority_val zero is special: those are weakly tracked rules. - * That means: NetworkManager will restore them only if it removed them earlier. - * But it will not remove or add them otherwise. - * - * Otherwise, the track_priority_val goes together with track_priority_present. - * In case of one rule being tracked multiple times (with different priorities), - * the one with higher priority wins. See _rules_obj_get_best_data(). - * Then, the winning present state either enforces that the rule is present - * or absent. - * - * If a rules is not tracked at all, it is ignored by NetworkManager. Assuming - * that it was added externally by the user. But unlike weakly tracked rules, - * NM will *not* restore such rules if NetworkManager themself removed them. */ - guint32 track_priority_val; - bool track_priority_present : 1; - - bool dirty : 1; -} RulesData; - -typedef enum { - CONFIG_STATE_NONE = 0, - CONFIG_STATE_ADDED_BY_US = 1, - CONFIG_STATE_REMOVED_BY_US = 2, - - /* ConfigState encodes whether the rule was touched by us at all (CONFIG_STATE_NONE). - * - * Maybe we would only need to track whether we touched the rule at all. But we - * track it more in detail what we did: did we add it (CONFIG_STATE_ADDED_BY_US) - * or did we remove it (CONFIG_STATE_REMOVED_BY_US)? - * Finally, we need CONFIG_STATE_OWNED_BY_US, which means that we didn't actively - * add/remove it, but whenever we are about to undo the add/remove, we need to do it. - * In that sense, CONFIG_STATE_OWNED_BY_US is really just a flag that we unconditionally - * force the state next time when necessary. */ - CONFIG_STATE_OWNED_BY_US = 3, -} ConfigState; - -typedef struct { - const NMPObject *obj; - CList obj_lst_head; - - /* indicates whether we configured/removed the rule (during sync()). We need that, so - * if the rule gets untracked, that we know to remove/restore it. - * - * This makes NMPRulesManager stateful (beyond the configuration that indicates - * which rules are tracked). - * After a restart, NetworkManager would no longer remember which rules were added - * by us. - * - * That is partially fixed by NetworkManager taking over the rules that it - * actively configures (see %NMP_RULES_MANAGER_EXTERN_WEAKLY_TRACKED_USER_TAG). */ - ConfigState config_state; -} RulesObjData; - -typedef struct { - gconstpointer user_tag; - CList user_tag_lst_head; -} RulesUserTagData; - -/*****************************************************************************/ - -static void _rules_data_untrack(NMPRulesManager *self, - RulesData * rules_data, - gboolean remove_user_tag_data, - gboolean make_owned_by_us); - -/*****************************************************************************/ - -static void -_rules_data_assert(const RulesData *rules_data, gboolean linked) -{ - nm_assert(rules_data); - nm_assert(NMP_OBJECT_GET_TYPE(rules_data->obj) == NMP_OBJECT_TYPE_ROUTING_RULE); - nm_assert(nmp_object_is_visible(rules_data->obj)); - nm_assert(rules_data->user_tag); - nm_assert(!linked || !c_list_is_empty(&rules_data->obj_lst)); - nm_assert(!linked || !c_list_is_empty(&rules_data->user_tag_lst)); -} - -static guint -_rules_data_hash(gconstpointer data) -{ - const RulesData *rules_data = data; - NMHashState h; - - _rules_data_assert(rules_data, FALSE); - - nm_hash_init(&h, 269297543u); - nm_platform_routing_rule_hash_update(NMP_OBJECT_CAST_ROUTING_RULE(rules_data->obj), - NM_PLATFORM_ROUTING_RULE_CMP_TYPE_ID, - &h); - nm_hash_update_val(&h, rules_data->user_tag); - return nm_hash_complete(&h); -} - -static gboolean -_rules_data_equal(gconstpointer data_a, gconstpointer data_b) -{ - const RulesData *rules_data_a = data_a; - const RulesData *rules_data_b = data_b; - - _rules_data_assert(rules_data_a, FALSE); - _rules_data_assert(rules_data_b, FALSE); - - return rules_data_a->user_tag == rules_data_b->user_tag - && (nm_platform_routing_rule_cmp(NMP_OBJECT_CAST_ROUTING_RULE(rules_data_a->obj), - NMP_OBJECT_CAST_ROUTING_RULE(rules_data_b->obj), - NM_PLATFORM_ROUTING_RULE_CMP_TYPE_ID) - == 0); -} - -static void -_rules_data_destroy(gpointer data) -{ - RulesData *rules_data = data; - - _rules_data_assert(rules_data, FALSE); - - c_list_unlink_stale(&rules_data->obj_lst); - c_list_unlink_stale(&rules_data->user_tag_lst); - nmp_object_unref(rules_data->obj); - g_slice_free(RulesData, rules_data); -} - -static const RulesData * -_rules_obj_get_best_data(RulesObjData *obj_data) -{ - RulesData * rules_data; - const RulesData *rd_best = NULL; - - c_list_for_each_entry (rules_data, &obj_data->obj_lst_head, obj_lst) { - _rules_data_assert(rules_data, TRUE); - - if (rd_best) { - if (rd_best->track_priority_val > rules_data->track_priority_val) - continue; - if (rd_best->track_priority_val == rules_data->track_priority_val) { - if (rd_best->track_priority_present || !rules_data->track_priority_present) { - /* if the priorities are identical, then "present" wins over - * "!present" (absent). */ - continue; - } - } - } - - rd_best = rules_data; - } - - return rd_best; -} - -static guint -_rules_obj_hash(gconstpointer data) -{ - const RulesObjData *obj_data = data; - NMHashState h; - - nm_hash_init(&h, 432817559u); - nm_platform_routing_rule_hash_update(NMP_OBJECT_CAST_ROUTING_RULE(obj_data->obj), - NM_PLATFORM_ROUTING_RULE_CMP_TYPE_ID, - &h); - return nm_hash_complete(&h); -} - -static gboolean -_rules_obj_equal(gconstpointer data_a, gconstpointer data_b) -{ - const RulesObjData *obj_data_a = data_a; - const RulesObjData *obj_data_b = data_b; - - return (nm_platform_routing_rule_cmp(NMP_OBJECT_CAST_ROUTING_RULE(obj_data_a->obj), - NMP_OBJECT_CAST_ROUTING_RULE(obj_data_b->obj), - NM_PLATFORM_ROUTING_RULE_CMP_TYPE_ID) - == 0); -} - -static void -_rules_obj_destroy(gpointer data) -{ - RulesObjData *obj_data = data; - - c_list_unlink_stale(&obj_data->obj_lst_head); - nmp_object_unref(obj_data->obj); - g_slice_free(RulesObjData, obj_data); -} - -static guint -_rules_user_tag_hash(gconstpointer data) -{ - const RulesUserTagData *user_tag_data = data; - - return nm_hash_val(644693447u, user_tag_data->user_tag); -} - -static gboolean -_rules_user_tag_equal(gconstpointer data_a, gconstpointer data_b) -{ - const RulesUserTagData *user_tag_data_a = data_a; - const RulesUserTagData *user_tag_data_b = data_b; - - return user_tag_data_a->user_tag == user_tag_data_b->user_tag; -} - -static void -_rules_user_tag_destroy(gpointer data) -{ - RulesUserTagData *user_tag_data = data; - - c_list_unlink_stale(&user_tag_data->user_tag_lst_head); - g_slice_free(RulesUserTagData, user_tag_data); -} - -static RulesData * -_rules_data_lookup(GHashTable *by_data, const NMPObject *obj, gconstpointer user_tag) -{ - RulesData rules_data_needle = { - .obj = obj, - .user_tag = user_tag, - }; - - return g_hash_table_lookup(by_data, &rules_data_needle); -} - -/** - * nmp_rules_manager_track: - * @self: the #NMPRulesManager instance - * @routing_rule: the #NMPlatformRoutingRule to track or untrack - * @track_priority: the priority for tracking the rule. Note that - * negative values indicate a forced absence of the rule. Priorities - * are compared with their absolute values (with higher absolute - * value being more important). For example, if you track the same - * rule twice, once with priority -5 and +10, then the rule is - * present (because the positive number is more important). - * The special value 0 indicates weakly-tracked rules. - * @user_tag: the tag associated with tracking this rule. The same tag - * must be used to untrack the rule later. - * @user_tag_untrack: if not %NULL, at the same time untrack this user-tag - * for the same rule. Note that this is different from a plain nmp_rules_manager_untrack(), - * because it enforces ownership of the now tracked rule. On the other hand, - * a plain nmp_rules_manager_untrack() merely forgets about the tracking. - * The purpose here is to set this to %NMP_RULES_MANAGER_EXTERN_WEAKLY_TRACKED_USER_TAG. - */ -void -nmp_rules_manager_track(NMPRulesManager * self, - const NMPlatformRoutingRule *routing_rule, - gint32 track_priority, - gconstpointer user_tag, - gconstpointer user_tag_untrack) -{ - NMPObject obj_stack; - const NMPObject * p_obj_stack; - RulesData * rules_data; - RulesObjData * obj_data; - RulesUserTagData *user_tag_data; - gboolean changed = FALSE; - guint32 track_priority_val; - gboolean track_priority_present; - - g_return_if_fail(NMP_IS_RULES_MANAGER(self)); - g_return_if_fail(routing_rule); - g_return_if_fail(user_tag); - nm_assert(track_priority != G_MININT32); - - _rules_init(self); - - p_obj_stack = nmp_object_stackinit(&obj_stack, NMP_OBJECT_TYPE_ROUTING_RULE, routing_rule); - - nm_assert(nmp_object_is_visible(p_obj_stack)); - - if (track_priority >= 0) { - track_priority_val = track_priority; - track_priority_present = TRUE; - } else { - track_priority_val = -track_priority; - track_priority_present = FALSE; - } - - rules_data = _rules_data_lookup(self->by_data, p_obj_stack, user_tag); - - if (!rules_data) { - rules_data = g_slice_new(RulesData); - *rules_data = (RulesData){ - .obj = nm_dedup_multi_index_obj_intern(nm_platform_get_multi_idx(self->platform), - p_obj_stack), - .user_tag = user_tag, - .track_priority_val = track_priority_val, - .track_priority_present = track_priority_present, - .dirty = FALSE, - }; - g_hash_table_add(self->by_data, rules_data); - - obj_data = g_hash_table_lookup(self->by_obj, &rules_data->obj); - if (!obj_data) { - obj_data = g_slice_new(RulesObjData); - *obj_data = (RulesObjData){ - .obj = nmp_object_ref(rules_data->obj), - .obj_lst_head = C_LIST_INIT(obj_data->obj_lst_head), - .config_state = CONFIG_STATE_NONE, - }; - g_hash_table_add(self->by_obj, obj_data); - } - c_list_link_tail(&obj_data->obj_lst_head, &rules_data->obj_lst); - - user_tag_data = g_hash_table_lookup(self->by_user_tag, &rules_data->user_tag); - if (!user_tag_data) { - user_tag_data = g_slice_new(RulesUserTagData); - *user_tag_data = (RulesUserTagData){ - .user_tag = user_tag, - .user_tag_lst_head = C_LIST_INIT(user_tag_data->user_tag_lst_head), - }; - g_hash_table_add(self->by_user_tag, user_tag_data); - } - c_list_link_tail(&user_tag_data->user_tag_lst_head, &rules_data->user_tag_lst); - changed = TRUE; - } else { - rules_data->dirty = FALSE; - if (rules_data->track_priority_val != track_priority_val - || rules_data->track_priority_present != track_priority_present) { - rules_data->track_priority_val = track_priority_val; - rules_data->track_priority_present = track_priority_present; - changed = TRUE; - } - } - - if (user_tag_untrack) { - if (user_tag != user_tag_untrack) { - RulesData *rules_data_untrack; - - rules_data_untrack = _rules_data_lookup(self->by_data, p_obj_stack, user_tag_untrack); - if (rules_data_untrack) - _rules_data_untrack(self, rules_data_untrack, FALSE, TRUE); - } else - nm_assert_not_reached(); - } - - _rules_data_assert(rules_data, TRUE); - - if (changed) { - _LOGD("routing-rule: track [" NM_HASH_OBFUSCATE_PTR_FMT ",%s%u] \"%s\")", - _USER_TAG_LOG(rules_data->user_tag), - (rules_data->track_priority_val == 0 - ? "" - : (rules_data->track_priority_present ? "+" : "-")), - (guint) rules_data->track_priority_val, - nmp_object_to_string(rules_data->obj, NMP_OBJECT_TO_STRING_PUBLIC, NULL, 0)); - } -} - -static void -_rules_data_untrack(NMPRulesManager *self, - RulesData * rules_data, - gboolean remove_user_tag_data, - gboolean make_owned_by_us) -{ - RulesObjData *obj_data; - - nm_assert(NMP_IS_RULES_MANAGER(self)); - _rules_data_assert(rules_data, TRUE); - nm_assert(self->by_data); - nm_assert(g_hash_table_lookup(self->by_data, rules_data) == rules_data); - - _LOGD("routing-rule: untrack [" NM_HASH_OBFUSCATE_PTR_FMT "] \"%s\"", - _USER_TAG_LOG(rules_data->user_tag), - nmp_object_to_string(rules_data->obj, NMP_OBJECT_TO_STRING_PUBLIC, NULL, 0)); - -#if NM_MORE_ASSERTS - { - RulesUserTagData *user_tag_data; - - user_tag_data = g_hash_table_lookup(self->by_user_tag, &rules_data->user_tag); - nm_assert(user_tag_data); - nm_assert(c_list_contains(&user_tag_data->user_tag_lst_head, &rules_data->user_tag_lst)); - } -#endif - - nm_assert(!c_list_is_empty(&rules_data->user_tag_lst)); - - obj_data = g_hash_table_lookup(self->by_obj, &rules_data->obj); - nm_assert(obj_data); - nm_assert(c_list_contains(&obj_data->obj_lst_head, &rules_data->obj_lst)); - nm_assert(obj_data == g_hash_table_lookup(self->by_obj, &rules_data->obj)); - - if (make_owned_by_us) { - if (obj_data->config_state == CONFIG_STATE_NONE) { - /* we need to mark this entry that it requires a touch on the next - * sync. */ - obj_data->config_state = CONFIG_STATE_OWNED_BY_US; - } - } else if (remove_user_tag_data && c_list_length_is(&rules_data->user_tag_lst, 1)) - g_hash_table_remove(self->by_user_tag, &rules_data->user_tag); - - /* if obj_data is marked to be "added_by_us" or "removed_by_us", we need to keep this entry - * around for the next sync -- so that we can undo what we did earlier. */ - if (obj_data->config_state == CONFIG_STATE_NONE && c_list_length_is(&rules_data->obj_lst, 1)) - g_hash_table_remove(self->by_obj, &rules_data->obj); - - g_hash_table_remove(self->by_data, rules_data); -} - -void -nmp_rules_manager_untrack(NMPRulesManager * self, - const NMPlatformRoutingRule *routing_rule, - gconstpointer user_tag) -{ - NMPObject obj_stack; - const NMPObject *p_obj_stack; - RulesData * rules_data; - - g_return_if_fail(NMP_IS_RULES_MANAGER(self)); - g_return_if_fail(routing_rule); - g_return_if_fail(user_tag); - - _rules_init(self); - - p_obj_stack = nmp_object_stackinit(&obj_stack, NMP_OBJECT_TYPE_ROUTING_RULE, routing_rule); - - nm_assert(nmp_object_is_visible(p_obj_stack)); - - rules_data = _rules_data_lookup(self->by_data, p_obj_stack, user_tag); - if (rules_data) - _rules_data_untrack(self, rules_data, TRUE, FALSE); -} - -void -nmp_rules_manager_set_dirty(NMPRulesManager *self, gconstpointer user_tag) -{ - RulesData * rules_data; - RulesUserTagData *user_tag_data; - - g_return_if_fail(NMP_IS_RULES_MANAGER(self)); - g_return_if_fail(user_tag); - - if (!self->by_data) - return; - - user_tag_data = g_hash_table_lookup(self->by_user_tag, &user_tag); - if (!user_tag_data) - return; - - c_list_for_each_entry (rules_data, &user_tag_data->user_tag_lst_head, user_tag_lst) - rules_data->dirty = TRUE; -} - -void -nmp_rules_manager_untrack_all(NMPRulesManager *self, - gconstpointer user_tag, - gboolean all /* or only dirty */) -{ - RulesData * rules_data; - RulesData * rules_data_safe; - RulesUserTagData *user_tag_data; - - g_return_if_fail(NMP_IS_RULES_MANAGER(self)); - g_return_if_fail(user_tag); - - if (!self->by_data) - return; - - user_tag_data = g_hash_table_lookup(self->by_user_tag, &user_tag); - if (!user_tag_data) - return; - - c_list_for_each_entry_safe (rules_data, - rules_data_safe, - &user_tag_data->user_tag_lst_head, - user_tag_lst) { - if (all || rules_data->dirty) - _rules_data_untrack(self, rules_data, FALSE, FALSE); - } - if (c_list_is_empty(&user_tag_data->user_tag_lst_head)) - g_hash_table_remove(self->by_user_tag, user_tag_data); -} - -void -nmp_rules_manager_sync(NMPRulesManager *self, gboolean keep_deleted_rules) -{ - const NMDedupMultiHeadEntry *pl_head_entry; - NMDedupMultiIter pl_iter; - const NMPObject * plobj; - gs_unref_ptrarray GPtrArray *rules_to_delete = NULL; - RulesObjData * obj_data; - GHashTableIter h_iter; - guint i; - const RulesData * rd_best; - - g_return_if_fail(NMP_IS_RULES_MANAGER(self)); - - if (!self->by_data) - return; - - _LOGD("sync%s", keep_deleted_rules ? " (don't remove any rules)" : ""); - - pl_head_entry = nm_platform_lookup_obj_type(self->platform, NMP_OBJECT_TYPE_ROUTING_RULE); - if (pl_head_entry) { - nmp_cache_iter_for_each (&pl_iter, pl_head_entry, &plobj) { - obj_data = g_hash_table_lookup(self->by_obj, &plobj); - - if (!obj_data) { - /* this rule is not tracked. It was externally added, hence we - * ignore it. */ - continue; - } - - rd_best = _rules_obj_get_best_data(obj_data); - if (rd_best) { - if (rd_best->track_priority_present) { - if (obj_data->config_state == CONFIG_STATE_OWNED_BY_US) - obj_data->config_state = CONFIG_STATE_ADDED_BY_US; - continue; - } - if (rd_best->track_priority_val == 0) { - if (!NM_IN_SET(obj_data->config_state, - CONFIG_STATE_ADDED_BY_US, - CONFIG_STATE_OWNED_BY_US)) { - obj_data->config_state = CONFIG_STATE_NONE; - continue; - } - obj_data->config_state = CONFIG_STATE_NONE; - } - } - - if (keep_deleted_rules) { - _LOGD("forget/leak rule added by us: %s", - nmp_object_to_string(plobj, NMP_OBJECT_TO_STRING_PUBLIC, NULL, 0)); - continue; - } - - if (!rules_to_delete) - rules_to_delete = g_ptr_array_new_with_free_func((GDestroyNotify) nmp_object_unref); - - g_ptr_array_add(rules_to_delete, (gpointer) nmp_object_ref(plobj)); - - obj_data->config_state = CONFIG_STATE_REMOVED_BY_US; - } - } - - if (rules_to_delete) { - for (i = 0; i < rules_to_delete->len; i++) - nm_platform_object_delete(self->platform, rules_to_delete->pdata[i]); - } - - g_hash_table_iter_init(&h_iter, self->by_obj); - while (g_hash_table_iter_next(&h_iter, (gpointer *) &obj_data, NULL)) { - rd_best = _rules_obj_get_best_data(obj_data); - - if (!rd_best) { - g_hash_table_iter_remove(&h_iter); - continue; - } - - if (!rd_best->track_priority_present) { - if (obj_data->config_state == CONFIG_STATE_OWNED_BY_US) - obj_data->config_state = CONFIG_STATE_REMOVED_BY_US; - continue; - } - if (rd_best->track_priority_val == 0) { - if (!NM_IN_SET(obj_data->config_state, - CONFIG_STATE_REMOVED_BY_US, - CONFIG_STATE_OWNED_BY_US)) { - obj_data->config_state = CONFIG_STATE_NONE; - continue; - } - obj_data->config_state = CONFIG_STATE_NONE; - } - - plobj = - nm_platform_lookup_obj(self->platform, NMP_CACHE_ID_TYPE_OBJECT_TYPE, obj_data->obj); - if (plobj) - continue; - - obj_data->config_state = CONFIG_STATE_ADDED_BY_US; - nm_platform_routing_rule_add(self->platform, - NMP_NLM_FLAG_ADD, - NMP_OBJECT_CAST_ROUTING_RULE(obj_data->obj)); - } -} - -void -nmp_rules_manager_track_from_platform(NMPRulesManager *self, - NMPlatform * platform, - int addr_family, - gint32 tracking_priority, - gconstpointer user_tag) -{ - NMPLookup lookup; - const NMDedupMultiHeadEntry *head_entry; - NMDedupMultiIter iter; - const NMPObject * o; - - g_return_if_fail(NMP_IS_RULES_MANAGER(self)); - - if (!platform) - platform = self->platform; - else - g_return_if_fail(NM_IS_PLATFORM(platform)); - - nm_assert(NM_IN_SET(addr_family, AF_UNSPEC, AF_INET, AF_INET6)); - - nmp_lookup_init_obj_type(&lookup, NMP_OBJECT_TYPE_ROUTING_RULE); - head_entry = nm_platform_lookup(platform, &lookup); - nmp_cache_iter_for_each (&iter, head_entry, &o) { - const NMPlatformRoutingRule *rr = NMP_OBJECT_CAST_ROUTING_RULE(o); - - if (addr_family != AF_UNSPEC && rr->addr_family != addr_family) - continue; - - nmp_rules_manager_track(self, rr, tracking_priority, user_tag, NULL); - } -} - -/*****************************************************************************/ - -void -nmp_rules_manager_track_default(NMPRulesManager *self, - int addr_family, - gint32 track_priority, - gconstpointer user_tag) -{ - g_return_if_fail(NMP_IS_RULES_MANAGER(self)); - - nm_assert(NM_IN_SET(addr_family, AF_UNSPEC, AF_INET, AF_INET6)); - - /* track the default rules. See also `man ip-rule`. */ - - if (NM_IN_SET(addr_family, AF_UNSPEC, AF_INET)) { - nmp_rules_manager_track(self, - &((NMPlatformRoutingRule){ - .addr_family = AF_INET, - .priority = 0, - .table = RT_TABLE_LOCAL, - .action = FR_ACT_TO_TBL, - .protocol = RTPROT_KERNEL, - }), - track_priority, - user_tag, - NULL); - nmp_rules_manager_track(self, - &((NMPlatformRoutingRule){ - .addr_family = AF_INET, - .priority = 32766, - .table = RT_TABLE_MAIN, - .action = FR_ACT_TO_TBL, - .protocol = RTPROT_KERNEL, - }), - track_priority, - user_tag, - NULL); - nmp_rules_manager_track(self, - &((NMPlatformRoutingRule){ - .addr_family = AF_INET, - .priority = 32767, - .table = RT_TABLE_DEFAULT, - .action = FR_ACT_TO_TBL, - .protocol = RTPROT_KERNEL, - }), - track_priority, - user_tag, - NULL); - } - if (NM_IN_SET(addr_family, AF_UNSPEC, AF_INET6)) { - nmp_rules_manager_track(self, - &((NMPlatformRoutingRule){ - .addr_family = AF_INET6, - .priority = 0, - .table = RT_TABLE_LOCAL, - .action = FR_ACT_TO_TBL, - .protocol = RTPROT_KERNEL, - }), - track_priority, - user_tag, - NULL); - nmp_rules_manager_track(self, - &((NMPlatformRoutingRule){ - .addr_family = AF_INET6, - .priority = 32766, - .table = RT_TABLE_MAIN, - .action = FR_ACT_TO_TBL, - .protocol = RTPROT_KERNEL, - }), - track_priority, - user_tag, - NULL); - } -} - -static void -_rules_init(NMPRulesManager *self) -{ - if (self->by_data) - return; - - self->by_data = - g_hash_table_new_full(_rules_data_hash, _rules_data_equal, NULL, _rules_data_destroy); - self->by_obj = - g_hash_table_new_full(_rules_obj_hash, _rules_obj_equal, NULL, _rules_obj_destroy); - self->by_user_tag = g_hash_table_new_full(_rules_user_tag_hash, - _rules_user_tag_equal, - NULL, - _rules_user_tag_destroy); -} - -/*****************************************************************************/ - -NMPRulesManager * -nmp_rules_manager_new(NMPlatform *platform) -{ - NMPRulesManager *self; - - g_return_val_if_fail(NM_IS_PLATFORM(platform), NULL); - - self = g_slice_new(NMPRulesManager); - *self = (NMPRulesManager){ - .ref_count = 1, - .platform = g_object_ref(platform), - }; - return self; -} - -void -nmp_rules_manager_ref(NMPRulesManager *self) -{ - g_return_if_fail(NMP_IS_RULES_MANAGER(self)); - - self->ref_count++; -} - -void -nmp_rules_manager_unref(NMPRulesManager *self) -{ - g_return_if_fail(NMP_IS_RULES_MANAGER(self)); - - if (--self->ref_count > 0) - return; - - if (self->by_data) { - g_hash_table_destroy(self->by_user_tag); - g_hash_table_destroy(self->by_obj); - g_hash_table_destroy(self->by_data); - } - g_object_unref(self->platform); - g_slice_free(NMPRulesManager, self); -} diff --git a/src/libnm-platform/nmp-rules-manager.h b/src/libnm-platform/nmp-rules-manager.h deleted file mode 100644 index 69cf9075..00000000 --- a/src/libnm-platform/nmp-rules-manager.h +++ /dev/null @@ -1,53 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ - -#ifndef __NMP_RULES_MANAGER_H__ -#define __NMP_RULES_MANAGER_H__ - -#include "nm-platform.h" - -/*****************************************************************************/ - -#define NMP_RULES_MANAGER_EXTERN_WEAKLY_TRACKED_USER_TAG ((const void *) nmp_rules_manager_new) - -typedef struct _NMPRulesManager NMPRulesManager; - -NMPRulesManager *nmp_rules_manager_new(NMPlatform *platform); - -void nmp_rules_manager_ref(NMPRulesManager *self); -void nmp_rules_manager_unref(NMPRulesManager *self); - -#define nm_auto_unref_rules_manager nm_auto(_nmp_rules_manager_unref) -NM_AUTO_DEFINE_FCN0(NMPRulesManager *, _nmp_rules_manager_unref, nmp_rules_manager_unref); - -void nmp_rules_manager_track(NMPRulesManager * self, - const NMPlatformRoutingRule *routing_rule, - gint32 track_priority, - gconstpointer user_tag, - gconstpointer user_tag_untrack); - -void nmp_rules_manager_track_default(NMPRulesManager *self, - int addr_family, - gint32 track_priority, - gconstpointer user_tag); - -void nmp_rules_manager_track_from_platform(NMPRulesManager *self, - NMPlatform * platform, - int addr_family, - gint32 tracking_priority, - gconstpointer user_tag); - -void nmp_rules_manager_untrack(NMPRulesManager * self, - const NMPlatformRoutingRule *routing_rule, - gconstpointer user_tag); - -void nmp_rules_manager_set_dirty(NMPRulesManager *self, gconstpointer user_tag); - -void nmp_rules_manager_untrack_all(NMPRulesManager *self, - gconstpointer user_tag, - gboolean all /* or only dirty */); - -void nmp_rules_manager_sync(NMPRulesManager *self, gboolean keep_deleted_rules); - -/*****************************************************************************/ - -#endif /* __NMP_RULES_MANAGER_H__ */ diff --git a/src/libnm-platform/wifi/nm-wifi-utils-nl80211.c b/src/libnm-platform/wifi/nm-wifi-utils-nl80211.c index 148657ea..2fa46e38 100644 --- a/src/libnm-platform/wifi/nm-wifi-utils-nl80211.c +++ b/src/libnm-platform/wifi/nm-wifi-utils-nl80211.c @@ -43,7 +43,7 @@ typedef struct { NMWifiUtils parent; struct nl_sock *nl_sock; - guint32 * freqs; + guint32 *freqs; int id; int num_freqs; int phy; @@ -104,21 +104,21 @@ nl80211_alloc_msg(NMWifiUtilsNl80211 *self, guint32 cmd, guint32 flags) static int nl80211_send_and_recv(NMWifiUtilsNl80211 *self, - struct nl_msg * msg, + struct nl_msg *msg, int (*valid_handler)(struct nl_msg *, void *), void *valid_data) { int err; int done = 0; const struct nl_cb cb = { - .err_cb = error_handler, - .err_arg = &done, - .finish_cb = finish_handler, - .finish_arg = &done, - .ack_cb = ack_handler, - .ack_arg = &done, - .valid_cb = valid_handler, - .valid_arg = valid_data, + .err_cb = error_handler, + .err_arg = &done, + .finish_cb = finish_handler, + .finish_arg = &done, + .ack_cb = ack_handler, + .ack_arg = &done, + .valid_cb = valid_handler, + .valid_arg = valid_data, }; g_return_val_if_fail(msg != NULL, -ENOMEM); @@ -169,8 +169,8 @@ static int nl80211_iface_info_handler(struct nl_msg *msg, void *arg) { struct nl80211_iface_info *info = arg; - struct genlmsghdr * gnlh = nlmsg_data(nlmsg_hdr(msg)); - struct nlattr * tb[NL80211_ATTR_MAX + 1]; + struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); + struct nlattr *tb[NL80211_ATTR_MAX + 1]; if (nla_parse_arr(tb, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL) < 0) return NL_SKIP; @@ -202,7 +202,7 @@ nl80211_iface_info_handler(struct nl_msg *msg, void *arg) static _NM80211Mode wifi_nl80211_get_mode(NMWifiUtils *data) { - NMWifiUtilsNl80211 * self = (NMWifiUtilsNl80211 *) data; + NMWifiUtilsNl80211 *self = (NMWifiUtilsNl80211 *) data; struct nl80211_iface_info iface_info = { .mode = _NM_802_11_MODE_UNKNOWN, }; @@ -219,7 +219,7 @@ wifi_nl80211_get_mode(NMWifiUtils *data) static gboolean wifi_nl80211_set_mode(NMWifiUtils *data, const _NM80211Mode mode) { - NMWifiUtilsNl80211 * self = (NMWifiUtilsNl80211 *) data; + NMWifiUtilsNl80211 *self = (NMWifiUtilsNl80211 *) data; nm_auto_nlmsg struct nl_msg *msg = NULL; int err; @@ -252,7 +252,7 @@ nla_put_failure: static gboolean wifi_nl80211_set_powersave(NMWifiUtils *data, guint32 powersave) { - NMWifiUtilsNl80211 * self = (NMWifiUtilsNl80211 *) data; + NMWifiUtilsNl80211 *self = (NMWifiUtilsNl80211 *) data; nm_auto_nlmsg struct nl_msg *msg = NULL; int err; @@ -271,9 +271,9 @@ static int nl80211_get_wake_on_wlan_handler(struct nl_msg *msg, void *arg) { _NMSettingWirelessWakeOnWLan *wowl = arg; - struct nlattr * attrs[NL80211_ATTR_MAX + 1]; - struct nlattr * trig[NUM_NL80211_WOWLAN_TRIG]; - struct genlmsghdr * gnlh = nlmsg_data(nlmsg_hdr(msg)); + struct nlattr *attrs[NL80211_ATTR_MAX + 1]; + struct nlattr *trig[NUM_NL80211_WOWLAN_TRIG]; + struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); nla_parse_arr(attrs, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL); @@ -309,7 +309,7 @@ nl80211_get_wake_on_wlan_handler(struct nl_msg *msg, void *arg) static _NMSettingWirelessWakeOnWLan wifi_nl80211_get_wake_on_wlan(NMWifiUtils *data) { - NMWifiUtilsNl80211 * self = (NMWifiUtilsNl80211 *) data; + NMWifiUtilsNl80211 *self = (NMWifiUtilsNl80211 *) data; _NMSettingWirelessWakeOnWLan wowl = _NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE; nm_auto_nlmsg struct nl_msg *msg = NULL; @@ -323,9 +323,9 @@ wifi_nl80211_get_wake_on_wlan(NMWifiUtils *data) static gboolean wifi_nl80211_set_wake_on_wlan(NMWifiUtils *data, _NMSettingWirelessWakeOnWLan wowl) { - NMWifiUtilsNl80211 * self = (NMWifiUtilsNl80211 *) data; + NMWifiUtilsNl80211 *self = (NMWifiUtilsNl80211 *) data; nm_auto_nlmsg struct nl_msg *msg = NULL; - struct nlattr * triggers; + struct nlattr *triggers; int err; if (wowl == _NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE) @@ -365,7 +365,7 @@ nla_put_failure: static guint32 wifi_nl80211_get_freq(NMWifiUtils *data) { - NMWifiUtilsNl80211 * self = (NMWifiUtilsNl80211 *) data; + NMWifiUtilsNl80211 *self = (NMWifiUtilsNl80211 *) data; struct nl80211_iface_info iface_info = {}; nm_auto_nlmsg struct nl_msg *msg = NULL; @@ -441,11 +441,11 @@ nl80211_station_dump_handler(struct nl_msg *msg, void *arg) [NL80211_RATE_INFO_40_MHZ_WIDTH] = {.type = NLA_FLAG}, [NL80211_RATE_INFO_SHORT_GI] = {.type = NLA_FLAG}, }; - struct nlattr * rinfo[G_N_ELEMENTS(rate_policy)]; - struct nlattr * sinfo[G_N_ELEMENTS(stats_policy)]; + struct nlattr *rinfo[G_N_ELEMENTS(rate_policy)]; + struct nlattr *sinfo[G_N_ELEMENTS(stats_policy)]; struct nl80211_station_info *info = arg; - struct nlattr * tb[NL80211_ATTR_MAX + 1]; - struct genlmsghdr * gnlh = nlmsg_data(nlmsg_hdr(msg)); + struct nlattr *tb[NL80211_ATTR_MAX + 1]; + struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); if (nla_parse_arr(tb, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL) < 0) return NL_SKIP; @@ -495,10 +495,10 @@ nl80211_station_dump_handler(struct nl_msg *msg, void *arg) static gboolean wifi_nl80211_get_station(NMWifiUtils *data, NMEtherAddr *out_bssid, - int * out_quality, - guint32 * out_rate) + int *out_quality, + guint32 *out_rate) { - NMWifiUtilsNl80211 * self = (NMWifiUtilsNl80211 *) data; + NMWifiUtilsNl80211 *self = (NMWifiUtilsNl80211 *) data; nm_auto_nlmsg struct nl_msg *msg = NULL; struct nl80211_station_info sta_info = {}; @@ -525,7 +525,7 @@ wifi_nl80211_get_station(NMWifiUtils *data, static gboolean wifi_nl80211_indicate_addressing_running(NMWifiUtils *data, gboolean running) { - NMWifiUtilsNl80211 * self = (NMWifiUtilsNl80211 *) data; + NMWifiUtilsNl80211 *self = (NMWifiUtilsNl80211 *) data; nm_auto_nlmsg struct nl_msg *msg = NULL; int err; @@ -552,7 +552,7 @@ nla_put_failure: struct nl80211_device_info { NMWifiUtilsNl80211 *self; int phy; - guint32 * freqs; + guint32 *freqs; int num_freqs; guint32 freq; guint32 caps; @@ -587,14 +587,14 @@ nl80211_wiphy_info_handler(struct nl_msg *msg, void *arg) [NL80211_FREQUENCY_ATTR_RADAR] = {.type = NLA_FLAG}, [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = {.type = NLA_U32}, }; - struct nlattr * tb[NL80211_ATTR_MAX + 1]; - struct genlmsghdr * gnlh = nlmsg_data(nlmsg_hdr(msg)); + struct nlattr *tb[NL80211_ATTR_MAX + 1]; + struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); struct nl80211_device_info *info = arg; - NMWifiUtilsNl80211 * self = info->self; - struct nlattr * tb_band[NL80211_BAND_ATTR_MAX + 1]; - struct nlattr * tb_freq[G_N_ELEMENTS(freq_policy)]; - struct nlattr * nl_band; - struct nlattr * nl_freq; + NMWifiUtilsNl80211 *self = info->self; + struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1]; + struct nlattr *tb_freq[G_N_ELEMENTS(freq_policy)]; + struct nlattr *nl_band; + struct nlattr *nl_freq; int rem_freq; int rem_band; int freq_idx; @@ -761,7 +761,7 @@ nl80211_wiphy_info_handler(struct nl_msg *msg, void *arg) static guint32 wifi_nl80211_get_mesh_channel(NMWifiUtils *data) { - NMWifiUtilsNl80211 * self = (NMWifiUtilsNl80211 *) data; + NMWifiUtilsNl80211 *self = (NMWifiUtilsNl80211 *) data; nm_auto_nlmsg struct nl_msg *msg = NULL; struct nl80211_device_info device_info = {.self = self}; int i; @@ -783,7 +783,7 @@ wifi_nl80211_get_mesh_channel(NMWifiUtils *data) static gboolean wifi_nl80211_set_mesh_channel(NMWifiUtils *data, guint32 channel) { - NMWifiUtilsNl80211 * self = (NMWifiUtilsNl80211 *) data; + NMWifiUtilsNl80211 *self = (NMWifiUtilsNl80211 *) data; nm_auto_nlmsg struct nl_msg *msg = NULL; int err; @@ -802,7 +802,7 @@ nla_put_failure: static gboolean wifi_nl80211_set_mesh_ssid(NMWifiUtils *data, const guint8 *ssid, gsize len) { - NMWifiUtilsNl80211 * self = (NMWifiUtilsNl80211 *) data; + NMWifiUtilsNl80211 *self = (NMWifiUtilsNl80211 *) data; nm_auto_nlmsg struct nl_msg *msg = NULL; int err; @@ -822,7 +822,7 @@ nm_wifi_utils_nl80211_init(NMWifiUtilsNl80211 *self) static void nm_wifi_utils_nl80211_class_init(NMWifiUtilsNl80211Class *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMWifiUtilsClass *wifi_utils_class = NM_WIFI_UTILS_CLASS(klass); object_class->dispose = dispose; @@ -845,7 +845,7 @@ NMWifiUtils * nm_wifi_utils_nl80211_new(int ifindex, struct nl_sock *genl) { gs_unref_object NMWifiUtilsNl80211 *self = NULL; - nm_auto_nlmsg struct nl_msg * msg = NULL; + nm_auto_nlmsg struct nl_msg *msg = NULL; struct nl80211_device_info device_info = {}; if (!genl) diff --git a/src/libnm-platform/wifi/nm-wifi-utils-private.h b/src/libnm-platform/wifi/nm-wifi-utils-private.h index bc1e75ec..7461b65e 100644 --- a/src/libnm-platform/wifi/nm-wifi-utils-private.h +++ b/src/libnm-platform/wifi/nm-wifi-utils-private.h @@ -39,8 +39,8 @@ typedef struct { */ gboolean (*get_station)(NMWifiUtils *data, NMEtherAddr *out_bssid, - int * out_quality, - guint32 * out_rate); + int *out_quality, + guint32 *out_rate); /* OLPC Mesh-only functions */ diff --git a/src/libnm-platform/wifi/nm-wifi-utils-wext.c b/src/libnm-platform/wifi/nm-wifi-utils-wext.c index 6fb37c49..2d4112bc 100644 --- a/src/libnm-platform/wifi/nm-wifi-utils-wext.c +++ b/src/libnm-platform/wifi/nm-wifi-utils-wext.c @@ -427,7 +427,7 @@ wext_qual_to_percent(const struct iw_quality *qual, const struct iw_quality *max static int wifi_wext_get_qual(NMWifiUtils *data) { - NMWifiUtilsWext * wext = (NMWifiUtilsWext *) data; + NMWifiUtilsWext *wext = (NMWifiUtilsWext *) data; struct iwreq wrq; struct iw_statistics stats; char ifname[IFNAMSIZ]; @@ -455,8 +455,8 @@ wifi_wext_get_qual(NMWifiUtils *data) static gboolean wifi_wext_get_station(NMWifiUtils *data, NMEtherAddr *out_bssid, - int * out_quality, - guint32 * out_rate) + int *out_quality, + guint32 *out_rate) { NMEtherAddr local_addr; @@ -588,9 +588,9 @@ wext_can_scan_ifname(NMWifiUtilsWext *wext, const char *ifname) static gboolean wext_get_range_ifname(NMWifiUtilsWext *wext, - const char * ifname, + const char *ifname, struct iw_range *range, - guint32 * response_len) + guint32 *response_len) { int i = 26; gboolean success = FALSE; @@ -698,7 +698,7 @@ nm_wifi_utils_wext_init(NMWifiUtilsWext *self) static void nm_wifi_utils_wext_class_init(NMWifiUtilsWextClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMWifiUtilsClass *wifi_utils_class = NM_WIFI_UTILS_CLASS(klass); object_class->dispose = dispose; @@ -717,7 +717,7 @@ nm_wifi_utils_wext_class_init(NMWifiUtilsWextClass *klass) NMWifiUtils * nm_wifi_utils_wext_new(int ifindex, gboolean check_scan) { - NMWifiUtilsWext * wext; + NMWifiUtilsWext *wext; struct iw_range range; guint32 response_len = 0; struct iw_range_with_scan_capa *scan_capa_range; diff --git a/src/libnm-platform/wifi/nm-wifi-utils.c b/src/libnm-platform/wifi/nm-wifi-utils.c index 0b5f8d71..8bdd65c2 100644 --- a/src/libnm-platform/wifi/nm-wifi-utils.c +++ b/src/libnm-platform/wifi/nm-wifi-utils.c @@ -132,8 +132,8 @@ nm_wifi_utils_find_freq(NMWifiUtils *data, const guint32 *freqs) gboolean nm_wifi_utils_get_station(NMWifiUtils *data, NMEtherAddr *out_bssid, - int * out_quality, - guint32 * out_rate) + int *out_quality, + guint32 *out_rate) { g_return_val_if_fail(data != NULL, FALSE); diff --git a/src/libnm-platform/wifi/nm-wifi-utils.h b/src/libnm-platform/wifi/nm-wifi-utils.h index 157522ee..be33b90c 100644 --- a/src/libnm-platform/wifi/nm-wifi-utils.h +++ b/src/libnm-platform/wifi/nm-wifi-utils.h @@ -51,8 +51,8 @@ guint32 nm_wifi_utils_find_freq(NMWifiUtils *data, const guint32 *freqs); */ gboolean nm_wifi_utils_get_station(NMWifiUtils *data, NMEtherAddr *out_bssid, - int * out_quality, - guint32 * out_rate); + int *out_quality, + guint32 *out_rate); /* Tells the driver DHCP or SLAAC is running */ gboolean nm_wifi_utils_indicate_addressing_running(NMWifiUtils *data, gboolean running); diff --git a/src/libnm-platform/wpan/nm-wpan-utils.c b/src/libnm-platform/wpan/nm-wpan-utils.c index 082cc3e7..d9bbd0f0 100644 --- a/src/libnm-platform/wpan/nm-wpan-utils.c +++ b/src/libnm-platform/wpan/nm-wpan-utils.c @@ -95,7 +95,7 @@ nl802154_alloc_msg(NMWpanUtils *self, guint32 cmd, guint32 flags) } static int -nl802154_send_and_recv(NMWpanUtils * self, +nl802154_send_and_recv(NMWpanUtils *self, struct nl_msg *msg, int (*valid_handler)(struct nl_msg *, void *), void *valid_data) @@ -103,14 +103,14 @@ nl802154_send_and_recv(NMWpanUtils * self, int err; int done = 0; const struct nl_cb cb = { - .err_cb = error_handler, - .err_arg = &done, - .finish_cb = finish_handler, - .finish_arg = &done, - .ack_cb = ack_handler, - .ack_arg = &done, - .valid_cb = valid_handler, - .valid_arg = valid_data, + .err_cb = error_handler, + .err_arg = &done, + .finish_cb = finish_handler, + .finish_arg = &done, + .ack_cb = ack_handler, + .ack_arg = &done, + .valid_cb = valid_handler, + .valid_arg = valid_data, }; g_return_val_if_fail(msg != NULL, -ENOMEM); @@ -149,9 +149,9 @@ nl802154_get_interface_handler(struct nl_msg *msg, void *arg) [NL802154_ATTR_PAN_ID] = {.type = NLA_U16}, [NL802154_ATTR_SHORT_ADDR] = {.type = NLA_U16}, }; - struct nlattr * tb[G_N_ELEMENTS(nl802154_policy)]; + struct nlattr *tb[G_N_ELEMENTS(nl802154_policy)]; struct nl802154_interface *info = arg; - struct genlmsghdr * gnlh = nlmsg_data(nlmsg_hdr(msg)); + struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); if (nla_parse_arr(tb, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), nl802154_policy) < 0) return NL_SKIP; diff --git a/src/libnm-std-aux/c-list-util.h b/src/libnm-std-aux/c-list-util.h index 9d86d663..dbfef0f8 100644 --- a/src/libnm-std-aux/c-list-util.h +++ b/src/libnm-std-aux/c-list-util.h @@ -31,7 +31,7 @@ static inline int c_list_length_is(const CList *list, unsigned long check_len) { unsigned long n = 0; - const CList * iter; + const CList *iter; c_list_for_each (iter, list) { ++n; diff --git a/src/libnm-systemd-core/meson.build b/src/libnm-systemd-core/meson.build index fb472a76..1fa94486 100644 --- a/src/libnm-systemd-core/meson.build +++ b/src/libnm-systemd-core/meson.build @@ -18,8 +18,6 @@ libnm_systemd_core = static_library( 'src/libsystemd-network/sd-dhcp-lease.c', 'src/libsystemd-network/sd-dhcp6-client.c', 'src/libsystemd-network/sd-dhcp6-lease.c', - 'src/libsystemd-network/sd-ipv4acd.c', - 'src/libsystemd-network/sd-ipv4ll.c', 'src/libsystemd-network/sd-lldp-rx.c', 'src/libsystemd/sd-event/event-util.c', 'src/libsystemd/sd-event/sd-event.c', diff --git a/src/libnm-systemd-core/nm-sd-utils-dhcp.h b/src/libnm-systemd-core/nm-sd-utils-dhcp.h index 5d126d5b..6487a90d 100644 --- a/src/libnm-systemd-core/nm-sd-utils-dhcp.h +++ b/src/libnm-systemd-core/nm-sd-utils-dhcp.h @@ -11,7 +11,7 @@ typedef struct { uint8_t code; uint8_t data_len; - void * data; + void *data; } nm_sd_dhcp_option; int nm_sd_dhcp_lease_get_private_options(sd_dhcp_lease *lease, nm_sd_dhcp_option **out_options); diff --git a/src/libnm-systemd-core/nm-sd.h b/src/libnm-systemd-core/nm-sd.h index 0ec2f16e..421f5372 100644 --- a/src/libnm-systemd-core/nm-sd.h +++ b/src/libnm-systemd-core/nm-sd.h @@ -8,9 +8,7 @@ #include "src/systemd/sd-dhcp-client.h" #include "src/systemd/sd-dhcp6-client.h" -#include "src/systemd/sd-ipv4ll.h" #include "src/systemd/sd-lldp-rx.h" -#include "src/systemd/sd-lldp.h" /*****************************************************************************/ diff --git a/src/libnm-systemd-core/src/libsystemd-network/arp-util.c b/src/libnm-systemd-core/src/libsystemd-network/arp-util.c index 46c4a8cb..c8a73111 100644 --- a/src/libnm-systemd-core/src/libsystemd-network/arp-util.c +++ b/src/libnm-systemd-core/src/libsystemd-network/arp-util.c @@ -16,7 +16,7 @@ #include "unaligned.h" #include "util.h" -int arp_update_filter(int fd, const struct in_addr *a, const struct ether_addr *eth_mac) { +int arp_update_filter(int fd, const struct in_addr *a, const struct ether_addr *mac) { struct sock_filter filter[] = { BPF_STMT(BPF_LD + BPF_W + BPF_LEN, 0), /* A <- packet length */ BPF_JUMP(BPF_JMP + BPF_JGE + BPF_K, sizeof(struct ether_arp), 1, 0), /* packet >= arp packet ? */ @@ -38,30 +38,21 @@ int arp_update_filter(int fd, const struct in_addr *a, const struct ether_addr * BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ARPOP_REPLY, 1, 0), /* protocol == reply ? */ BPF_STMT(BPF_RET + BPF_K, 0), /* ignore */ /* Sender Hardware Address must be different from our own */ - BPF_STMT(BPF_LD + BPF_IMM, unaligned_read_be32(ð_mac->ether_addr_octet[0])),/* A <- 4 bytes of client's MAC */ - BPF_STMT(BPF_MISC + BPF_TAX, 0), /* X <- A */ + BPF_STMT(BPF_LDX + BPF_IMM, unaligned_read_be32(&mac->ether_addr_octet[0])), /* X <- 4 bytes of client's MAC */ BPF_STMT(BPF_LD + BPF_W + BPF_ABS, offsetof(struct ether_arp, arp_sha)), /* A <- 4 bytes of SHA */ - BPF_STMT(BPF_ALU + BPF_XOR + BPF_X, 0), /* A xor X */ - BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 0, 0, 6), /* A == 0 ? */ - BPF_STMT(BPF_LD + BPF_IMM, unaligned_read_be16(ð_mac->ether_addr_octet[4])),/* A <- remainder of client's MAC */ - BPF_STMT(BPF_MISC + BPF_TAX, 0), /* X <- A */ + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_X, 0, 0, 4), /* A == X ? */ + BPF_STMT(BPF_LDX + BPF_IMM, unaligned_read_be16(&mac->ether_addr_octet[4])), /* X <- remainder of client's MAC */ BPF_STMT(BPF_LD + BPF_H + BPF_ABS, offsetof(struct ether_arp, arp_sha) + 4), /* A <- remainder of SHA */ - BPF_STMT(BPF_ALU + BPF_XOR + BPF_X, 0), /* A xor X */ - BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 0, 0, 1), /* A == 0 ? */ + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_X, 0, 0, 1), /* A == X ? */ BPF_STMT(BPF_RET + BPF_K, 0), /* ignore */ /* Sender Protocol Address or Target Protocol Address must be equal to the one we care about */ - BPF_STMT(BPF_LD + BPF_IMM, htobe32(a->s_addr)), /* A <- clients IP */ - BPF_STMT(BPF_MISC + BPF_TAX, 0), /* X <- A */ + BPF_STMT(BPF_LDX + BPF_IMM, htobe32(a->s_addr)), /* X <- clients IP */ BPF_STMT(BPF_LD + BPF_W + BPF_ABS, offsetof(struct ether_arp, arp_spa)), /* A <- SPA */ - BPF_STMT(BPF_ALU + BPF_XOR + BPF_X, 0), /* X xor A */ - BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 0, 0, 1), /* A == 0 ? */ - BPF_STMT(BPF_RET + BPF_K, 65535), /* return all */ - BPF_STMT(BPF_LD + BPF_IMM, htobe32(a->s_addr)), /* A <- clients IP */ - BPF_STMT(BPF_MISC + BPF_TAX, 0), /* X <- A */ + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_X, 0, 0, 1), /* A == X ? */ + BPF_STMT(BPF_RET + BPF_K, UINT32_MAX), /* accept */ BPF_STMT(BPF_LD + BPF_W + BPF_ABS, offsetof(struct ether_arp, arp_tpa)), /* A <- TPA */ - BPF_STMT(BPF_ALU + BPF_XOR + BPF_X, 0), /* X xor A */ - BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 0, 0, 1), /* A == 0 ? */ - BPF_STMT(BPF_RET + BPF_K, 65535), /* return all */ + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_X, 0, 0, 1), /* A == 0 ? */ + BPF_STMT(BPF_RET + BPF_K, UINT32_MAX), /* accept */ BPF_STMT(BPF_RET + BPF_K, 0), /* ignore */ }; struct sock_fprog fprog = { @@ -77,7 +68,7 @@ int arp_update_filter(int fd, const struct in_addr *a, const struct ether_addr * return 0; } -int arp_network_bind_raw_socket(int ifindex, const struct in_addr *a, const struct ether_addr *eth_mac) { +int arp_network_bind_raw_socket(int ifindex, const struct in_addr *a, const struct ether_addr *mac) { union sockaddr_union link = { .ll.sll_family = AF_PACKET, .ll.sll_protocol = htobe16(ETH_P_ARP), @@ -89,12 +80,13 @@ int arp_network_bind_raw_socket(int ifindex, const struct in_addr *a, const stru int r; assert(ifindex > 0); + assert(mac); s = socket(AF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0); if (s < 0) return -errno; - r = arp_update_filter(s, a, eth_mac); + r = arp_update_filter(s, a, mac); if (r < 0) return r; diff --git a/src/libnm-systemd-core/src/libsystemd-network/arp-util.h b/src/libnm-systemd-core/src/libsystemd-network/arp-util.h index e8615a15..b66a81bf 100644 --- a/src/libnm-systemd-core/src/libsystemd-network/arp-util.h +++ b/src/libnm-systemd-core/src/libsystemd-network/arp-util.h @@ -11,8 +11,8 @@ #include "socket-util.h" #include "sparse-endian.h" -int arp_update_filter(int fd, const struct in_addr *a, const struct ether_addr *eth_mac); -int arp_network_bind_raw_socket(int ifindex, const struct in_addr *a, const struct ether_addr *eth_mac); +int arp_update_filter(int fd, const struct in_addr *a, const struct ether_addr *mac); +int arp_network_bind_raw_socket(int ifindex, const struct in_addr *a, const struct ether_addr *mac); int arp_send_packet( int fd, diff --git a/src/libnm-systemd-core/src/libsystemd-network/dhcp-identifier.c b/src/libnm-systemd-core/src/libsystemd-network/dhcp-identifier.c index bd47ff41..74aa19de 100644 --- a/src/libnm-systemd-core/src/libsystemd-network/dhcp-identifier.c +++ b/src/libnm-systemd-core/src/libsystemd-network/dhcp-identifier.c @@ -11,7 +11,7 @@ #include "dhcp-identifier.h" #include "dhcp6-protocol.h" -#include "network-util.h" +#include "netif-util.h" #include "siphash24.h" #include "sparse-endian.h" #include "stat-util.h" @@ -200,7 +200,7 @@ int dhcp_identifier_set_iaid( /* device is under renaming */ return -EBUSY; - name = net_get_name_persistent(device); + name = net_get_persistent_name(device); } if (name) @@ -214,7 +214,7 @@ int dhcp_identifier_set_iaid( if (legacy_unstable_byteorder) /* for historical reasons (a bug), the bits were swapped and thus * the result was endianness dependent. Preserve that behavior. */ - id32 = __bswap_32(id32); + id32 = bswap_32(id32); else /* the fixed behavior returns a stable byte order. Since LE is expected * to be more common, swap the bytes on LE to give the same as legacy diff --git a/src/libnm-systemd-core/src/libsystemd-network/dhcp-internal.h b/src/libnm-systemd-core/src/libsystemd-network/dhcp-internal.h index 6538f05b..466d8e4b 100644 --- a/src/libnm-systemd-core/src/libsystemd-network/dhcp-internal.h +++ b/src/libnm-systemd-core/src/libsystemd-network/dhcp-internal.h @@ -53,8 +53,8 @@ typedef int (*dhcp_option_callback_t)(uint8_t code, uint8_t len, int dhcp_option_parse(DHCPMessage *message, size_t len, dhcp_option_callback_t cb, void *userdata, char **error_message); int dhcp_message_init(DHCPMessage *message, uint8_t op, uint32_t xid, - uint8_t type, uint16_t arp_type, size_t optlen, - size_t *optoffset); + uint8_t type, uint16_t arp_type, uint8_t hlen, const uint8_t *chaddr, + size_t optlen, size_t *optoffset); uint16_t dhcp_packet_checksum(uint8_t *buf, size_t len); diff --git a/src/libnm-systemd-core/src/libsystemd-network/dhcp-lease-internal.h b/src/libnm-systemd-core/src/libsystemd-network/dhcp-lease-internal.h index 35a74dd7..992ac9f3 100644 --- a/src/libnm-systemd-core/src/libsystemd-network/dhcp-lease-internal.h +++ b/src/libnm-systemd-core/src/libsystemd-network/dhcp-lease-internal.h @@ -70,6 +70,12 @@ struct sd_dhcp_lease { char *timezone; + uint8_t sixrd_ipv4masklen; + uint8_t sixrd_prefixlen; + struct in6_addr sixrd_prefix; + struct in_addr *sixrd_br_addresses; + size_t sixrd_n_br_addresses; + LIST_HEAD(struct sd_dhcp_raw_option, private_options); }; diff --git a/src/libnm-systemd-core/src/libsystemd-network/dhcp-network.c b/src/libnm-systemd-core/src/libsystemd-network/dhcp-network.c index bbfdeb0f..1c5f3427 100644 --- a/src/libnm-systemd-core/src/libsystemd-network/dhcp-network.c +++ b/src/libnm-systemd-core/src/libsystemd-network/dhcp-network.c @@ -60,24 +60,20 @@ static int _bind_raw_socket(int ifindex, union sockaddr_union *link, /* We only support MAC address length to be either 0 or 6 (ETH_ALEN). Optionally * compare chaddr for ETH_ALEN bytes. */ - BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ETH_ALEN, 0, 12), /* A (the MAC address length) == ETH_ALEN ? */ - BPF_STMT(BPF_LD + BPF_IMM, unaligned_read_be32(ð_mac->ether_addr_octet[0])), /* A <- 4 bytes of client's MAC */ - BPF_STMT(BPF_MISC + BPF_TAX, 0), /* X <- A */ + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ETH_ALEN, 0, 8), /* A (the MAC address length) == ETH_ALEN ? */ + BPF_STMT(BPF_LDX + BPF_IMM, unaligned_read_be32(ð_mac->ether_addr_octet[0])), /* X <- 4 bytes of client's MAC */ BPF_STMT(BPF_LD + BPF_W + BPF_ABS, offsetof(DHCPPacket, dhcp.chaddr)), /* A <- 4 bytes of MAC from dhcp.chaddr */ - BPF_STMT(BPF_ALU + BPF_XOR + BPF_X, 0), /* A xor X */ - BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 0, 1, 0), /* A == 0 ? */ + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_X, 0, 1, 0), /* A == X ? */ BPF_STMT(BPF_RET + BPF_K, 0), /* ignore */ - BPF_STMT(BPF_LD + BPF_IMM, unaligned_read_be16(ð_mac->ether_addr_octet[4])), /* A <- remainder of client's MAC */ - BPF_STMT(BPF_MISC + BPF_TAX, 0), /* X <- A */ + BPF_STMT(BPF_LDX + BPF_IMM, unaligned_read_be16(ð_mac->ether_addr_octet[4])), /* X <- remainder of client's MAC */ BPF_STMT(BPF_LD + BPF_H + BPF_ABS, offsetof(DHCPPacket, dhcp.chaddr) + 4), /* A <- remainder of MAC from dhcp.chaddr */ - BPF_STMT(BPF_ALU + BPF_XOR + BPF_X, 0), /* A xor X */ - BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 0, 1, 0), /* A == 0 ? */ + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_X, 0, 1, 0), /* A == X ? */ BPF_STMT(BPF_RET + BPF_K, 0), /* ignore */ BPF_STMT(BPF_LD + BPF_W + BPF_ABS, offsetof(DHCPPacket, dhcp.magic)), /* A <- DHCP magic cookie */ BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, DHCP_MAGIC_COOKIE, 1, 0), /* cookie == DHCP magic cookie ? */ BPF_STMT(BPF_RET + BPF_K, 0), /* ignore */ - BPF_STMT(BPF_RET + BPF_K, 65535), /* return all */ + BPF_STMT(BPF_RET + BPF_K, UINT32_MAX), /* accept */ }; struct sock_fprog fprog = { .len = ELEMENTSOF(filter), @@ -117,10 +113,17 @@ static int _bind_raw_socket(int ifindex, union sockaddr_union *link, return TAKE_FD(s); } -int dhcp_network_bind_raw_socket(int ifindex, union sockaddr_union *link, uint32_t xid, - const uint8_t *mac_addr, size_t mac_addr_len, - const uint8_t *bcast_addr, size_t bcast_addr_len, - uint16_t arp_type, uint16_t port) { +int dhcp_network_bind_raw_socket( + int ifindex, + union sockaddr_union *link, + uint32_t xid, + const uint8_t *mac_addr, + size_t mac_addr_len, + const uint8_t *bcast_addr, + size_t bcast_addr_len, + uint16_t arp_type, + uint16_t port) { + static const uint8_t eth_bcast[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; /* Default broadcast address for IPoIB */ static const uint8_t ib_bcast[] = { @@ -174,7 +177,6 @@ int dhcp_network_bind_udp_socket(int ifindex, be32_t address, uint16_t port, int r = setsockopt_int(s, IPPROTO_IP, IP_TOS, ip_service_type); else r = setsockopt_int(s, IPPROTO_IP, IP_TOS, IPTOS_CLASS_CS6); - if (r < 0) return r; @@ -206,43 +208,49 @@ int dhcp_network_bind_udp_socket(int ifindex, be32_t address, uint16_t port, int return r; } - r = bind(s, &src.sa, sizeof(src.in)); - if (r < 0) + if (bind(s, &src.sa, sizeof(src.in)) < 0) return -errno; return TAKE_FD(s); } -int dhcp_network_send_raw_socket(int s, const union sockaddr_union *link, - const void *packet, size_t len) { - int r; +int dhcp_network_send_raw_socket( + int s, + const union sockaddr_union *link, + const void *packet, + size_t len) { + + /* Do not add assert(s >= 0) here, as this is called in fuzz-dhcp-server, and in that case this + * function should fail with negative errno. */ assert(link); assert(packet); - assert(len); + assert(len > 0); - r = sendto(s, packet, len, 0, &link->sa, SOCKADDR_LL_LEN(link->ll)); - if (r < 0) + if (sendto(s, packet, len, 0, &link->sa, SOCKADDR_LL_LEN(link->ll)) < 0) return -errno; return 0; } -int dhcp_network_send_udp_socket(int s, be32_t address, uint16_t port, - const void *packet, size_t len) { +int dhcp_network_send_udp_socket( + int s, + be32_t address, + uint16_t port, + const void *packet, + size_t len) { + union sockaddr_union dest = { .in.sin_family = AF_INET, .in.sin_port = htobe16(port), .in.sin_addr.s_addr = address, }; - int r; assert(s >= 0); assert(packet); - assert(len); + assert(len > 0); - r = sendto(s, packet, len, 0, &dest.sa, sizeof(dest.in)); - if (r < 0) + if (sendto(s, packet, len, 0, &dest.sa, sizeof(dest.in)) < 0) return -errno; return 0; diff --git a/src/libnm-systemd-core/src/libsystemd-network/dhcp-packet.c b/src/libnm-systemd-core/src/libsystemd-network/dhcp-packet.c index eeadd562..25a69a61 100644 --- a/src/libnm-systemd-core/src/libsystemd-network/dhcp-packet.c +++ b/src/libnm-systemd-core/src/libsystemd-network/dhcp-packet.c @@ -12,21 +12,44 @@ #include "dhcp-internal.h" #include "dhcp-protocol.h" +#include "memory-util.h" #define DHCP_CLIENT_MIN_OPTIONS_SIZE 312 -int dhcp_message_init(DHCPMessage *message, uint8_t op, uint32_t xid, - uint8_t type, uint16_t arp_type, size_t optlen, - size_t *optoffset) { +int dhcp_message_init( + DHCPMessage *message, + uint8_t op, + uint32_t xid, + uint8_t type, + uint16_t arp_type, + uint8_t hlen, + const uint8_t *chaddr, + size_t optlen, + size_t *optoffset) { + size_t offset = 0; int r; assert(IN_SET(op, BOOTREQUEST, BOOTREPLY)); - assert(IN_SET(arp_type, ARPHRD_ETHER, ARPHRD_INFINIBAND)); + assert(chaddr || hlen == 0); message->op = op; message->htype = arp_type; - message->hlen = (arp_type == ARPHRD_ETHER) ? ETHER_ADDR_LEN : 0; + + /* RFC2131 section 4.1.1: + The client MUST include its hardware address in the ’chaddr’ field, if + necessary for delivery of DHCP reply messages. + + RFC 4390 section 2.1: + A DHCP client, when working over an IPoIB interface, MUST follow the + following rules: + "htype" (hardware address type) MUST be 32 [ARPPARAM]. + "hlen" (hardware address length) MUST be 0. + "chaddr" (client hardware address) field MUST be zeroed. + */ + message->hlen = (arp_type == ARPHRD_INFINIBAND) ? 0 : hlen; + memcpy_safe(message->chaddr, chaddr, message->hlen); + message->xid = htobe32(xid); message->magic = htobe32(DHCP_MAGIC_COOKIE); diff --git a/src/libnm-systemd-core/src/libsystemd-network/dhcp6-internal.h b/src/libnm-systemd-core/src/libsystemd-network/dhcp6-internal.h index 4eb56aa8..f9434098 100644 --- a/src/libnm-systemd-core/src/libsystemd-network/dhcp6-internal.h +++ b/src/libnm-systemd-core/src/libsystemd-network/dhcp6-internal.h @@ -11,6 +11,7 @@ #include "sd-event.h" #include "sd-dhcp6-client.h" +#include "dhcp6-protocol.h" #include "hashmap.h" #include "list.h" #include "macro.h" @@ -93,6 +94,7 @@ typedef struct DHCP6IA { typedef struct sd_dhcp6_client sd_dhcp6_client; +bool dhcp6_option_can_request(uint16_t option); int dhcp6_option_append(uint8_t **buf, size_t *buflen, uint16_t code, size_t optlen, const void *optval); int dhcp6_option_append_ia(uint8_t **buf, size_t *buflen, const DHCP6IA *ia); @@ -129,6 +131,12 @@ int dhcp6_network_bind_udp_socket(int ifindex, struct in6_addr *address); int dhcp6_network_send_udp_socket(int s, struct in6_addr *address, const void *packet, size_t len); +int client_parse_message( + sd_dhcp6_client *client, + DHCP6Message *message, + size_t len, + sd_dhcp6_lease *lease); + const char *dhcp6_message_type_to_string(int s) _const_; int dhcp6_message_type_from_string(const char *s) _pure_; const char *dhcp6_message_status_to_string(int s) _const_; diff --git a/src/libnm-systemd-core/src/libsystemd-network/dhcp6-lease-internal.h b/src/libnm-systemd-core/src/libsystemd-network/dhcp6-lease-internal.h index 8801497b..8ae2ecd6 100644 --- a/src/libnm-systemd-core/src/libsystemd-network/dhcp6-lease-internal.h +++ b/src/libnm-systemd-core/src/libsystemd-network/dhcp6-lease-internal.h @@ -14,10 +14,14 @@ struct sd_dhcp6_lease { unsigned n_ref; + uint8_t *clientid; + size_t clientid_len; uint8_t *serverid; size_t serverid_len; uint8_t preference; bool rapid_commit; + triple_timestamp timestamp; + struct in6_addr server_address; DHCP6IA ia; DHCP6IA pd; @@ -39,21 +43,19 @@ struct sd_dhcp6_lease { int dhcp6_lease_ia_rebind_expire(const DHCP6IA *ia, uint32_t *expire); DHCP6IA *dhcp6_lease_free_ia(DHCP6IA *ia); -int dhcp6_lease_set_serverid(sd_dhcp6_lease *lease, const uint8_t *id, - size_t len); -int dhcp6_lease_get_serverid(sd_dhcp6_lease *lease, uint8_t **id, size_t *len); +int dhcp6_lease_set_clientid(sd_dhcp6_lease *lease, const uint8_t *id, size_t len); +int dhcp6_lease_get_clientid(sd_dhcp6_lease *lease, uint8_t **ret_id, size_t *ret_len); +int dhcp6_lease_set_serverid(sd_dhcp6_lease *lease, const uint8_t *id, size_t len); +int dhcp6_lease_get_serverid(sd_dhcp6_lease *lease, uint8_t **ret_id, size_t *ret_len); int dhcp6_lease_set_preference(sd_dhcp6_lease *lease, uint8_t preference); int dhcp6_lease_get_preference(sd_dhcp6_lease *lease, uint8_t *preference); int dhcp6_lease_set_rapid_commit(sd_dhcp6_lease *lease); int dhcp6_lease_get_rapid_commit(sd_dhcp6_lease *lease, bool *rapid_commit); -int dhcp6_lease_get_iaid(sd_dhcp6_lease *lease, be32_t *iaid); -int dhcp6_lease_get_pd_iaid(sd_dhcp6_lease *lease, be32_t *iaid); - int dhcp6_lease_add_dns(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen); int dhcp6_lease_add_domains(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen); int dhcp6_lease_add_ntp(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen); -int dhcp6_lease_add_sntp(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen) ; +int dhcp6_lease_add_sntp(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen); int dhcp6_lease_set_fqdn(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen); int dhcp6_lease_new(sd_dhcp6_lease **ret); diff --git a/src/libnm-systemd-core/src/libsystemd-network/dhcp6-network.c b/src/libnm-systemd-core/src/libsystemd-network/dhcp6-network.c index b6816de4..beace4c7 100644 --- a/src/libnm-systemd-core/src/libsystemd-network/dhcp6-network.c +++ b/src/libnm-systemd-core/src/libsystemd-network/dhcp6-network.c @@ -49,6 +49,10 @@ int dhcp6_network_bind_udp_socket(int ifindex, struct in6_addr *local_address) { if (r < 0) return r; + r = setsockopt_int(s, SOL_SOCKET, SO_TIMESTAMP, true); + if (r < 0) + return r; + r = bind(s, &src.sa, sizeof(src.in6)); if (r < 0) return -errno; diff --git a/src/libnm-systemd-core/src/libsystemd-network/dhcp6-option.c b/src/libnm-systemd-core/src/libsystemd-network/dhcp6-option.c index 4249f90d..237771e6 100644 --- a/src/libnm-systemd-core/src/libsystemd-network/dhcp6-option.c +++ b/src/libnm-systemd-core/src/libsystemd-network/dhcp6-option.c @@ -26,6 +26,193 @@ #define DHCP6_OPTION_IA_PD_LEN (sizeof(struct ia_pd)) #define DHCP6_OPTION_IA_TA_LEN (sizeof(struct ia_ta)) +bool dhcp6_option_can_request(uint16_t option) { + /* See Client ORO field in + * https://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xhtml#dhcpv6-parameters-2 */ + + switch (option) { + case SD_DHCP6_OPTION_CLIENTID: + case SD_DHCP6_OPTION_SERVERID: + case SD_DHCP6_OPTION_IA_NA: + case SD_DHCP6_OPTION_IA_TA: + case SD_DHCP6_OPTION_IAADDR: + case SD_DHCP6_OPTION_ORO: + case SD_DHCP6_OPTION_PREFERENCE: + case SD_DHCP6_OPTION_ELAPSED_TIME: + case SD_DHCP6_OPTION_RELAY_MSG: + case SD_DHCP6_OPTION_AUTH: + case SD_DHCP6_OPTION_UNICAST: + case SD_DHCP6_OPTION_STATUS_CODE: + case SD_DHCP6_OPTION_RAPID_COMMIT: + case SD_DHCP6_OPTION_USER_CLASS: + case SD_DHCP6_OPTION_VENDOR_CLASS: + return false; + case SD_DHCP6_OPTION_VENDOR_OPTS: + return true; + case SD_DHCP6_OPTION_INTERFACE_ID: + case SD_DHCP6_OPTION_RECONF_MSG: + case SD_DHCP6_OPTION_RECONF_ACCEPT: + return false; + case SD_DHCP6_OPTION_SIP_SERVER_DOMAIN_NAME: + case SD_DHCP6_OPTION_SIP_SERVER_ADDRESS: + case SD_DHCP6_OPTION_DNS_SERVERS: + case SD_DHCP6_OPTION_DOMAIN_LIST: + return true; + case SD_DHCP6_OPTION_IA_PD: + case SD_DHCP6_OPTION_IA_PD_PREFIX: + return false; + case SD_DHCP6_OPTION_NIS_SERVERS: + case SD_DHCP6_OPTION_NISP_SERVERS: + case SD_DHCP6_OPTION_NIS_DOMAIN_NAME: + case SD_DHCP6_OPTION_NISP_DOMAIN_NAME: + case SD_DHCP6_OPTION_SNTP_SERVERS: + case SD_DHCP6_OPTION_INFORMATION_REFRESH_TIME: + case SD_DHCP6_OPTION_BCMCS_SERVER_D: + case SD_DHCP6_OPTION_BCMCS_SERVER_A: + case SD_DHCP6_OPTION_GEOCONF_CIVIC: + return true; + case SD_DHCP6_OPTION_REMOTE_ID: + case SD_DHCP6_OPTION_SUBSCRIBER_ID: + return false; + case SD_DHCP6_OPTION_CLIENT_FQDN: + case SD_DHCP6_OPTION_PANA_AGENT: + case SD_DHCP6_OPTION_NEW_POSIX_TIMEZONE: + case SD_DHCP6_OPTION_NEW_TZDB_TIMEZONE: + return true; + case SD_DHCP6_OPTION_ERO: + case SD_DHCP6_OPTION_LQ_QUERY: + case SD_DHCP6_OPTION_CLIENT_DATA: + case SD_DHCP6_OPTION_CLT_TIME: + case SD_DHCP6_OPTION_LQ_RELAY_DATA: + case SD_DHCP6_OPTION_LQ_CLIENT_LINK: + return false; + case SD_DHCP6_OPTION_MIP6_HNIDF: + case SD_DHCP6_OPTION_MIP6_VDINF: + case SD_DHCP6_OPTION_V6_LOST: + case SD_DHCP6_OPTION_CAPWAP_AC_V6: + return true; + case SD_DHCP6_OPTION_RELAY_ID: + return false; + case SD_DHCP6_OPTION_IPV6_ADDRESS_MOS: + case SD_DHCP6_OPTION_IPV6_FQDN_MOS: + case SD_DHCP6_OPTION_NTP_SERVER: + case SD_DHCP6_OPTION_V6_ACCESS_DOMAIN: + case SD_DHCP6_OPTION_SIP_UA_CS_LIST: + case SD_DHCP6_OPTION_BOOTFILE_URL: + case SD_DHCP6_OPTION_BOOTFILE_PARAM: + return true; + case SD_DHCP6_OPTION_CLIENT_ARCH_TYPE: + return false; + case SD_DHCP6_OPTION_NII: + case SD_DHCP6_OPTION_GEOLOCATION: + case SD_DHCP6_OPTION_AFTR_NAME: + case SD_DHCP6_OPTION_ERP_LOCAL_DOMAIN_NAME: + return true; + case SD_DHCP6_OPTION_RSOO: + return false; + case SD_DHCP6_OPTION_PD_EXCLUDE: + return true; + case SD_DHCP6_OPTION_VSS: + return false; + case SD_DHCP6_OPTION_MIP6_IDINF: + case SD_DHCP6_OPTION_MIP6_UDINF: + case SD_DHCP6_OPTION_MIP6_HNP: + case SD_DHCP6_OPTION_MIP6_HAA: + case SD_DHCP6_OPTION_MIP6_HAF: + case SD_DHCP6_OPTION_RDNSS_SELECTION: + case SD_DHCP6_OPTION_KRB_PRINCIPAL_NAME: + case SD_DHCP6_OPTION_KRB_REALM_NAME: + case SD_DHCP6_OPTION_KRB_DEFAULT_REALM_NAME: + case SD_DHCP6_OPTION_KRB_KDC: + return true; + case SD_DHCP6_OPTION_CLIENT_LINKLAYER_ADDR: + case SD_DHCP6_OPTION_LINK_ADDRESS: + case SD_DHCP6_OPTION_RADIUS: + return false; + case SD_DHCP6_OPTION_SOL_MAX_RT: + case SD_DHCP6_OPTION_INF_MAX_RT: + case SD_DHCP6_OPTION_ADDRSEL: + case SD_DHCP6_OPTION_ADDRSEL_TABLE: + case SD_DHCP6_OPTION_V6_PCP_SERVER: + return true; + case SD_DHCP6_OPTION_DHCPV4_MSG: + return false; + case SD_DHCP6_OPTION_DHCP4_O_DHCP6_SERVER: + return true; + case SD_DHCP6_OPTION_S46_RULE: + return false; + case SD_DHCP6_OPTION_S46_BR: + return true; + case SD_DHCP6_OPTION_S46_DMR: + case SD_DHCP6_OPTION_S46_V4V6BIND: + case SD_DHCP6_OPTION_S46_PORTPARAMS: + return false; + case SD_DHCP6_OPTION_S46_CONT_MAPE: + case SD_DHCP6_OPTION_S46_CONT_MAPT: + case SD_DHCP6_OPTION_S46_CONT_LW: + case SD_DHCP6_OPTION_4RD: + case SD_DHCP6_OPTION_4RD_MAP_RULE: + case SD_DHCP6_OPTION_4RD_NON_MAP_RULE: + return true; + case SD_DHCP6_OPTION_LQ_BASE_TIME: + case SD_DHCP6_OPTION_LQ_START_TIME: + case SD_DHCP6_OPTION_LQ_END_TIME: + return false; + case SD_DHCP6_OPTION_CAPTIVE_PORTAL: + case SD_DHCP6_OPTION_MPL_PARAMETERS: + return true; + case SD_DHCP6_OPTION_ANI_ATT: + case SD_DHCP6_OPTION_ANI_NETWORK_NAME: + case SD_DHCP6_OPTION_ANI_AP_NAME: + case SD_DHCP6_OPTION_ANI_AP_BSSID: + case SD_DHCP6_OPTION_ANI_OPERATOR_ID: + case SD_DHCP6_OPTION_ANI_OPERATOR_REALM: + return false; + case SD_DHCP6_OPTION_S46_PRIORITY: + return true; + case SD_DHCP6_OPTION_MUD_URL_V6: + return false; + case SD_DHCP6_OPTION_V6_PREFIX64: + return true; + case SD_DHCP6_OPTION_F_BINDING_STATUS: + case SD_DHCP6_OPTION_F_CONNECT_FLAGS: + case SD_DHCP6_OPTION_F_DNS_REMOVAL_INFO: + case SD_DHCP6_OPTION_F_DNS_HOST_NAME: + case SD_DHCP6_OPTION_F_DNS_ZONE_NAME: + case SD_DHCP6_OPTION_F_DNS_FLAGS: + case SD_DHCP6_OPTION_F_EXPIRATION_TIME: + case SD_DHCP6_OPTION_F_MAX_UNACKED_BNDUPD: + case SD_DHCP6_OPTION_F_MCLT: + case SD_DHCP6_OPTION_F_PARTNER_LIFETIME: + case SD_DHCP6_OPTION_F_PARTNER_LIFETIME_SENT: + case SD_DHCP6_OPTION_F_PARTNER_DOWN_TIME: + case SD_DHCP6_OPTION_F_PARTNER_RAW_CLT_TIME: + case SD_DHCP6_OPTION_F_PROTOCOL_VERSION: + case SD_DHCP6_OPTION_F_KEEPALIVE_TIME: + case SD_DHCP6_OPTION_F_RECONFIGURE_DATA: + case SD_DHCP6_OPTION_F_RELATIONSHIP_NAME: + case SD_DHCP6_OPTION_F_SERVER_FLAGS: + case SD_DHCP6_OPTION_F_SERVER_STATE: + case SD_DHCP6_OPTION_F_START_TIME_OF_STATE: + case SD_DHCP6_OPTION_F_STATE_EXPIRATION_TIME: + case SD_DHCP6_OPTION_RELAY_PORT: + return false; + case SD_DHCP6_OPTION_V6_SZTP_REDIRECT: + case SD_DHCP6_OPTION_S46_BIND_IPV6_PREFIX: + return true; + case SD_DHCP6_OPTION_IA_LL: + case SD_DHCP6_OPTION_LLADDR: + case SD_DHCP6_OPTION_SLAP_QUAD: + return false; + case SD_DHCP6_OPTION_V6_DOTS_RI: + case SD_DHCP6_OPTION_V6_DOTS_ADDRESS: + case SD_DHCP6_OPTION_IPV6_ADDRESS_ANDSF: + return true; + default: + return false; + } +} + static int option_append_hdr(uint8_t **buf, size_t *buflen, uint16_t optcode, size_t optlen) { DHCP6Option *option; @@ -275,7 +462,7 @@ int dhcp6_option_append_fqdn(uint8_t **buf, size_t *buflen, const char *fqdn) { if (dns_name_is_single_label(fqdn)) r--; - r = dhcp6_option_append(buf, buflen, SD_DHCP6_OPTION_FQDN, 1 + r, buffer); + r = dhcp6_option_append(buf, buflen, SD_DHCP6_OPTION_CLIENT_FQDN, 1 + r, buffer); return r; } diff --git a/src/libnm-systemd-core/src/libsystemd-network/dhcp6-protocol.h b/src/libnm-systemd-core/src/libsystemd-network/dhcp6-protocol.h index c7003638..5d2af439 100644 --- a/src/libnm-systemd-core/src/libsystemd-network/dhcp6-protocol.h +++ b/src/libnm-systemd-core/src/libsystemd-network/dhcp6-protocol.h @@ -5,6 +5,7 @@ Copyright © 2014 Intel Corporation. All rights reserved. ***/ +#include #include #include @@ -36,57 +37,83 @@ enum { DHCP6_PORT_CLIENT = 546, }; -#define DHCP6_INF_TIMEOUT 1 * USEC_PER_SEC -#define DHCP6_INF_MAX_RT 120 * USEC_PER_SEC -#define DHCP6_SOL_MAX_DELAY 1 * USEC_PER_SEC -#define DHCP6_SOL_TIMEOUT 1 * USEC_PER_SEC -#define DHCP6_SOL_MAX_RT 120 * USEC_PER_SEC -#define DHCP6_REQ_TIMEOUT 1 * USEC_PER_SEC -#define DHCP6_REQ_MAX_RT 120 * USEC_PER_SEC +#define DHCP6_INF_TIMEOUT (1 * USEC_PER_SEC) +#define DHCP6_INF_MAX_RT (120 * USEC_PER_SEC) +#define DHCP6_SOL_MAX_DELAY (1 * USEC_PER_SEC) +#define DHCP6_SOL_TIMEOUT (1 * USEC_PER_SEC) +#define DHCP6_SOL_MAX_RT (120 * USEC_PER_SEC) +#define DHCP6_REQ_TIMEOUT (1 * USEC_PER_SEC) +#define DHCP6_REQ_MAX_RT (120 * USEC_PER_SEC) #define DHCP6_REQ_MAX_RC 10 -#define DHCP6_REN_TIMEOUT 10 * USEC_PER_SEC -#define DHCP6_REN_MAX_RT 600 * USEC_PER_SEC -#define DHCP6_REB_TIMEOUT 10 * USEC_PER_SEC -#define DHCP6_REB_MAX_RT 600 * USEC_PER_SEC +#define DHCP6_REN_TIMEOUT (10 * USEC_PER_SEC) +#define DHCP6_REN_MAX_RT (600 * USEC_PER_SEC) +#define DHCP6_REB_TIMEOUT (10 * USEC_PER_SEC) +#define DHCP6_REB_MAX_RT (600 * USEC_PER_SEC) -enum DHCP6State { - DHCP6_STATE_STOPPED = 0, - DHCP6_STATE_INFORMATION_REQUEST = 1, - DHCP6_STATE_SOLICITATION = 2, - DHCP6_STATE_REQUEST = 3, - DHCP6_STATE_BOUND = 4, - DHCP6_STATE_RENEW = 5, - DHCP6_STATE_REBIND = 6, -}; +typedef enum DHCP6State { + DHCP6_STATE_STOPPED, + DHCP6_STATE_INFORMATION_REQUEST, + DHCP6_STATE_SOLICITATION, + DHCP6_STATE_REQUEST, + DHCP6_STATE_BOUND, + DHCP6_STATE_RENEW, + DHCP6_STATE_REBIND, + _DHCP6_STATE_MAX, + _DHCP6_STATE_INVALID = -EINVAL, +} DHCP6State; -enum { - DHCP6_SOLICIT = 1, - DHCP6_ADVERTISE = 2, - DHCP6_REQUEST = 3, - DHCP6_CONFIRM = 4, - DHCP6_RENEW = 5, - DHCP6_REBIND = 6, - DHCP6_REPLY = 7, - DHCP6_RELEASE = 8, - DHCP6_DECLINE = 9, - DHCP6_RECONFIGURE = 10, - DHCP6_INFORMATION_REQUEST = 11, - DHCP6_RELAY_FORW = 12, - DHCP6_RELAY_REPL = 13, - _DHCP6_MESSAGE_MAX = 14, -}; +/* https://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xhtml#dhcpv6-parameters-1 */ +typedef enum DHCP6MessageType { + DHCP6_MESSAGE_SOLICIT = 1, /* RFC 8415 */ + DHCP6_MESSAGE_ADVERTISE = 2, /* RFC 8415 */ + DHCP6_MESSAGE_REQUEST = 3, /* RFC 8415 */ + DHCP6_MESSAGE_CONFIRM = 4, /* RFC 8415 */ + DHCP6_MESSAGE_RENEW = 5, /* RFC 8415 */ + DHCP6_MESSAGE_REBIND = 6, /* RFC 8415 */ + DHCP6_MESSAGE_REPLY = 7, /* RFC 8415 */ + DHCP6_MESSAGE_RELEASE = 8, /* RFC 8415 */ + DHCP6_MESSAGE_DECLINE = 9, /* RFC 8415 */ + DHCP6_MESSAGE_RECONFIGURE = 10, /* RFC 8415 */ + DHCP6_MESSAGE_INFORMATION_REQUEST = 11, /* RFC 8415 */ + DHCP6_MESSAGE_RELAY_FORWARD = 12, /* RFC 8415 */ + DHCP6_MESSAGE_RELAY_REPLY = 13, /* RFC 8415 */ + DHCP6_MESSAGE_LEASE_QUERY = 14, /* RFC 5007 */ + DHCP6_MESSAGE_LEASE_QUERY_REPLY = 15, /* RFC 5007 */ + DHCP6_MESSAGE_LEASE_QUERY_DONE = 16, /* RFC 5460 */ + DHCP6_MESSAGE_LEASE_QUERY_DATA = 17, /* RFC 5460 */ + DHCP6_MESSAGE_RECONFIGURE_REQUEST = 18, /* RFC 6977 */ + DHCP6_MESSAGE_RECONFIGURE_REPLY = 19, /* RFC 6977 */ + DHCP6_MESSAGE_DHCPV4_QUERY = 20, /* RFC 7341 */ + DHCP6_MESSAGE_DHCPV4_RESPONSE = 21, /* RFC 7341 */ + DHCP6_MESSAGE_ACTIVE_LEASE_QUERY = 22, /* RFC 7653 */ + DHCP6_MESSAGE_START_TLS = 23, /* RFC 7653 */ + DHCP6_MESSAGE_BINDING_UPDATE = 24, /* RFC 8156 */ + DHCP6_MESSAGE_BINDING_REPLY = 25, /* RFC 8156 */ + DHCP6_MESSAGE_POOL_REQUEST = 26, /* RFC 8156 */ + DHCP6_MESSAGE_POOL_RESPONSE = 27, /* RFC 8156 */ + DHCP6_MESSAGE_UPDATE_REQUEST = 28, /* RFC 8156 */ + DHCP6_MESSAGE_UPDATE_REQUEST_ALL = 29, /* RFC 8156 */ + DHCP6_MESSAGE_UPDATE_DONE = 30, /* RFC 8156 */ + DHCP6_MESSAGE_CONNECT = 31, /* RFC 8156 */ + DHCP6_MESSAGE_CONNECT_REPLY = 32, /* RFC 8156 */ + DHCP6_MESSAGE_DISCONNECT = 33, /* RFC 8156 */ + DHCP6_MESSAGE_STATE = 34, /* RFC 8156 */ + DHCP6_MESSAGE_CONTACT = 35, /* RFC 8156 */ + _DHCP6_MESSAGE_TYPE_MAX, + _DHCP6_MESSAGE_TYPE_INVALID = -EINVAL, +} DHCP6MessageType; -enum { +typedef enum DHCP6NTPSubOption { DHCP6_NTP_SUBOPTION_SRV_ADDR = 1, DHCP6_NTP_SUBOPTION_MC_ADDR = 2, DHCP6_NTP_SUBOPTION_SRV_FQDN = 3, -}; +} DHCP6NTPSubOption; /* * RFC 8415, RFC 5007 and RFC 7653 status codes: * https://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xhtml#dhcpv6-parameters-5 */ -enum { +typedef enum DHCP6Status { DHCP6_STATUS_SUCCESS = 0, DHCP6_STATUS_UNSPEC_FAIL = 1, DHCP6_STATUS_NO_ADDRS_AVAIL = 2, @@ -110,11 +137,12 @@ enum { DHCP6_STATUS_SERVER_SHUTTING_DOWN = 20, DHCP6_STATUS_DNS_UPDATE_NOT_SUPPORTED = 21, DHCP6_STATUS_EXCESSIVE_TIME_SKEW = 22, - _DHCP6_STATUS_MAX = 23, -}; + _DHCP6_STATUS_MAX, + _DHCP6_STATUS_INVALID = -EINVAL, +} DHCP6Status; -enum { - DHCP6_FQDN_FLAG_S = (1 << 0), - DHCP6_FQDN_FLAG_O = (1 << 1), - DHCP6_FQDN_FLAG_N = (1 << 2), -}; +typedef enum DHCP6FQDNFlag { + DHCP6_FQDN_FLAG_S = 1 << 0, + DHCP6_FQDN_FLAG_O = 1 << 1, + DHCP6_FQDN_FLAG_N = 1 << 2, +} DHCP6FQDNFlag; diff --git a/src/libnm-systemd-core/src/libsystemd-network/lldp-neighbor.c b/src/libnm-systemd-core/src/libsystemd-network/lldp-neighbor.c index 3d6d7e42..b4d7c327 100644 --- a/src/libnm-systemd-core/src/libsystemd-network/lldp-neighbor.c +++ b/src/libnm-systemd-core/src/libsystemd-network/lldp-neighbor.c @@ -47,7 +47,7 @@ int lldp_neighbor_prioq_compare_func(const void *a, const void *b) { return CMP(x->until, y->until); } -_public_ sd_lldp_neighbor *sd_lldp_neighbor_ref(sd_lldp_neighbor *n) { +sd_lldp_neighbor *sd_lldp_neighbor_ref(sd_lldp_neighbor *n) { if (!n) return NULL; @@ -72,7 +72,7 @@ static sd_lldp_neighbor *lldp_neighbor_free(sd_lldp_neighbor *n) { return mfree(n); } -_public_ sd_lldp_neighbor *sd_lldp_neighbor_unref(sd_lldp_neighbor *n) { +sd_lldp_neighbor *sd_lldp_neighbor_unref(sd_lldp_neighbor *n) { /* Drops one reference from the neighbor. Note that the object is not freed unless it is already unlinked from * the sd_lldp object. */ @@ -360,7 +360,7 @@ bool lldp_neighbor_equal(const sd_lldp_neighbor *a, const sd_lldp_neighbor *b) { return memcmp(LLDP_NEIGHBOR_RAW(a), LLDP_NEIGHBOR_RAW(b), a->raw_size) == 0; } -_public_ int sd_lldp_neighbor_get_source_address(sd_lldp_neighbor *n, struct ether_addr* address) { +int sd_lldp_neighbor_get_source_address(sd_lldp_neighbor *n, struct ether_addr* address) { assert_return(n, -EINVAL); assert_return(address, -EINVAL); @@ -368,7 +368,7 @@ _public_ int sd_lldp_neighbor_get_source_address(sd_lldp_neighbor *n, struct eth return 0; } -_public_ int sd_lldp_neighbor_get_destination_address(sd_lldp_neighbor *n, struct ether_addr* address) { +int sd_lldp_neighbor_get_destination_address(sd_lldp_neighbor *n, struct ether_addr* address) { assert_return(n, -EINVAL); assert_return(address, -EINVAL); @@ -376,7 +376,7 @@ _public_ int sd_lldp_neighbor_get_destination_address(sd_lldp_neighbor *n, struc return 0; } -_public_ int sd_lldp_neighbor_get_raw(sd_lldp_neighbor *n, const void **ret, size_t *size) { +int sd_lldp_neighbor_get_raw(sd_lldp_neighbor *n, const void **ret, size_t *size) { assert_return(n, -EINVAL); assert_return(ret, -EINVAL); assert_return(size, -EINVAL); @@ -387,7 +387,7 @@ _public_ int sd_lldp_neighbor_get_raw(sd_lldp_neighbor *n, const void **ret, siz return 0; } -_public_ int sd_lldp_neighbor_get_chassis_id(sd_lldp_neighbor *n, uint8_t *type, const void **ret, size_t *size) { +int sd_lldp_neighbor_get_chassis_id(sd_lldp_neighbor *n, uint8_t *type, const void **ret, size_t *size) { assert_return(n, -EINVAL); assert_return(type, -EINVAL); assert_return(ret, -EINVAL); @@ -440,7 +440,7 @@ static int format_network_address(const void *data, size_t sz, char **ret) { return 1; } -_public_ int sd_lldp_neighbor_get_chassis_id_as_string(sd_lldp_neighbor *n, const char **ret) { +int sd_lldp_neighbor_get_chassis_id_as_string(sd_lldp_neighbor *n, const char **ret) { char *k; int r; @@ -496,7 +496,7 @@ done: return 0; } -_public_ int sd_lldp_neighbor_get_port_id(sd_lldp_neighbor *n, uint8_t *type, const void **ret, size_t *size) { +int sd_lldp_neighbor_get_port_id(sd_lldp_neighbor *n, uint8_t *type, const void **ret, size_t *size) { assert_return(n, -EINVAL); assert_return(type, -EINVAL); assert_return(ret, -EINVAL); @@ -511,7 +511,7 @@ _public_ int sd_lldp_neighbor_get_port_id(sd_lldp_neighbor *n, uint8_t *type, co return 0; } -_public_ int sd_lldp_neighbor_get_port_id_as_string(sd_lldp_neighbor *n, const char **ret) { +int sd_lldp_neighbor_get_port_id_as_string(sd_lldp_neighbor *n, const char **ret) { char *k; int r; @@ -566,7 +566,7 @@ done: return 0; } -_public_ int sd_lldp_neighbor_get_ttl(sd_lldp_neighbor *n, uint16_t *ret_sec) { +int sd_lldp_neighbor_get_ttl(sd_lldp_neighbor *n, uint16_t *ret_sec) { assert_return(n, -EINVAL); assert_return(ret_sec, -EINVAL); @@ -574,7 +574,7 @@ _public_ int sd_lldp_neighbor_get_ttl(sd_lldp_neighbor *n, uint16_t *ret_sec) { return 0; } -_public_ int sd_lldp_neighbor_get_system_name(sd_lldp_neighbor *n, const char **ret) { +int sd_lldp_neighbor_get_system_name(sd_lldp_neighbor *n, const char **ret) { assert_return(n, -EINVAL); assert_return(ret, -EINVAL); @@ -585,7 +585,7 @@ _public_ int sd_lldp_neighbor_get_system_name(sd_lldp_neighbor *n, const char ** return 0; } -_public_ int sd_lldp_neighbor_get_system_description(sd_lldp_neighbor *n, const char **ret) { +int sd_lldp_neighbor_get_system_description(sd_lldp_neighbor *n, const char **ret) { assert_return(n, -EINVAL); assert_return(ret, -EINVAL); @@ -596,7 +596,7 @@ _public_ int sd_lldp_neighbor_get_system_description(sd_lldp_neighbor *n, const return 0; } -_public_ int sd_lldp_neighbor_get_port_description(sd_lldp_neighbor *n, const char **ret) { +int sd_lldp_neighbor_get_port_description(sd_lldp_neighbor *n, const char **ret) { assert_return(n, -EINVAL); assert_return(ret, -EINVAL); @@ -607,7 +607,7 @@ _public_ int sd_lldp_neighbor_get_port_description(sd_lldp_neighbor *n, const ch return 0; } -_public_ int sd_lldp_neighbor_get_mud_url(sd_lldp_neighbor *n, const char **ret) { +int sd_lldp_neighbor_get_mud_url(sd_lldp_neighbor *n, const char **ret) { assert_return(n, -EINVAL); assert_return(ret, -EINVAL); @@ -618,7 +618,7 @@ _public_ int sd_lldp_neighbor_get_mud_url(sd_lldp_neighbor *n, const char **ret) return 0; } -_public_ int sd_lldp_neighbor_get_system_capabilities(sd_lldp_neighbor *n, uint16_t *ret) { +int sd_lldp_neighbor_get_system_capabilities(sd_lldp_neighbor *n, uint16_t *ret) { assert_return(n, -EINVAL); assert_return(ret, -EINVAL); @@ -629,7 +629,7 @@ _public_ int sd_lldp_neighbor_get_system_capabilities(sd_lldp_neighbor *n, uint1 return 0; } -_public_ int sd_lldp_neighbor_get_enabled_capabilities(sd_lldp_neighbor *n, uint16_t *ret) { +int sd_lldp_neighbor_get_enabled_capabilities(sd_lldp_neighbor *n, uint16_t *ret) { assert_return(n, -EINVAL); assert_return(ret, -EINVAL); @@ -640,7 +640,7 @@ _public_ int sd_lldp_neighbor_get_enabled_capabilities(sd_lldp_neighbor *n, uint return 0; } -_public_ int sd_lldp_neighbor_from_raw(sd_lldp_neighbor **ret, const void *raw, size_t raw_size) { +int sd_lldp_neighbor_from_raw(sd_lldp_neighbor **ret, const void *raw, size_t raw_size) { _cleanup_(sd_lldp_neighbor_unrefp) sd_lldp_neighbor *n = NULL; int r; @@ -661,7 +661,7 @@ _public_ int sd_lldp_neighbor_from_raw(sd_lldp_neighbor **ret, const void *raw, return r; } -_public_ int sd_lldp_neighbor_tlv_rewind(sd_lldp_neighbor *n) { +int sd_lldp_neighbor_tlv_rewind(sd_lldp_neighbor *n) { assert_return(n, -EINVAL); assert(n->raw_size >= sizeof(struct ether_header)); @@ -670,7 +670,7 @@ _public_ int sd_lldp_neighbor_tlv_rewind(sd_lldp_neighbor *n) { return n->rindex < n->raw_size; } -_public_ int sd_lldp_neighbor_tlv_next(sd_lldp_neighbor *n) { +int sd_lldp_neighbor_tlv_next(sd_lldp_neighbor *n) { size_t length; assert_return(n, -EINVAL); @@ -689,7 +689,7 @@ _public_ int sd_lldp_neighbor_tlv_next(sd_lldp_neighbor *n) { return n->rindex < n->raw_size; } -_public_ int sd_lldp_neighbor_tlv_get_type(sd_lldp_neighbor *n, uint8_t *type) { +int sd_lldp_neighbor_tlv_get_type(sd_lldp_neighbor *n, uint8_t *type) { assert_return(n, -EINVAL); assert_return(type, -EINVAL); @@ -703,7 +703,7 @@ _public_ int sd_lldp_neighbor_tlv_get_type(sd_lldp_neighbor *n, uint8_t *type) { return 0; } -_public_ int sd_lldp_neighbor_tlv_is_type(sd_lldp_neighbor *n, uint8_t type) { +int sd_lldp_neighbor_tlv_is_type(sd_lldp_neighbor *n, uint8_t type) { uint8_t k; int r; @@ -716,7 +716,7 @@ _public_ int sd_lldp_neighbor_tlv_is_type(sd_lldp_neighbor *n, uint8_t type) { return type == k; } -_public_ int sd_lldp_neighbor_tlv_get_oui(sd_lldp_neighbor *n, uint8_t oui[_SD_ARRAY_STATIC 3], uint8_t *subtype) { +int sd_lldp_neighbor_tlv_get_oui(sd_lldp_neighbor *n, uint8_t oui[_SD_ARRAY_STATIC 3], uint8_t *subtype) { const uint8_t *d; size_t length; int r; @@ -745,7 +745,7 @@ _public_ int sd_lldp_neighbor_tlv_get_oui(sd_lldp_neighbor *n, uint8_t oui[_SD_A return 0; } -_public_ int sd_lldp_neighbor_tlv_is_oui(sd_lldp_neighbor *n, const uint8_t oui[_SD_ARRAY_STATIC 3], uint8_t subtype) { +int sd_lldp_neighbor_tlv_is_oui(sd_lldp_neighbor *n, const uint8_t oui[_SD_ARRAY_STATIC 3], uint8_t subtype) { uint8_t k[3], st; int r; @@ -758,7 +758,7 @@ _public_ int sd_lldp_neighbor_tlv_is_oui(sd_lldp_neighbor *n, const uint8_t oui[ return memcmp(k, oui, 3) == 0 && st == subtype; } -_public_ int sd_lldp_neighbor_tlv_get_raw(sd_lldp_neighbor *n, const void **ret, size_t *size) { +int sd_lldp_neighbor_tlv_get_raw(sd_lldp_neighbor *n, const void **ret, size_t *size) { size_t length; assert_return(n, -EINVAL); @@ -780,7 +780,7 @@ _public_ int sd_lldp_neighbor_tlv_get_raw(sd_lldp_neighbor *n, const void **ret, return 0; } -_public_ int sd_lldp_neighbor_get_timestamp(sd_lldp_neighbor *n, clockid_t clock, uint64_t *ret) { +int sd_lldp_neighbor_get_timestamp(sd_lldp_neighbor *n, clockid_t clock, uint64_t *ret) { assert_return(n, -EINVAL); assert_return(TRIPLE_TIMESTAMP_HAS_CLOCK(clock), -EOPNOTSUPP); assert_return(clock_supported(clock), -EOPNOTSUPP); diff --git a/src/libnm-systemd-core/src/libsystemd-network/lldp-network.c b/src/libnm-systemd-core/src/libsystemd-network/lldp-network.c index 34a4f3f0..00eb9703 100644 --- a/src/libnm-systemd-core/src/libsystemd-network/lldp-network.c +++ b/src/libnm-systemd-core/src/libsystemd-network/lldp-network.c @@ -11,7 +11,6 @@ #include "socket-util.h" int lldp_network_bind_raw_socket(int ifindex) { - static const struct sock_filter filter[] = { BPF_STMT(BPF_LD + BPF_W + BPF_ABS, offsetof(struct ethhdr, h_dest)), /* A <- 4 bytes of destination MAC */ BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 0x0180c200, 1, 0), /* A != 01:80:c2:00 */ @@ -26,26 +25,21 @@ int lldp_network_bind_raw_socket(int ifindex) { BPF_STMT(BPF_RET + BPF_K, 0), /* drop packet */ BPF_STMT(BPF_RET + BPF_K, UINT32_MAX), /* accept packet */ }; - static const struct sock_fprog fprog = { .len = ELEMENTSOF(filter), .filter = (struct sock_filter*) filter, }; - struct packet_mreq mreq = { .mr_ifindex = ifindex, .mr_type = PACKET_MR_MULTICAST, .mr_alen = ETH_ALEN, .mr_address = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x00 } }; - union sockaddr_union saddrll = { .ll.sll_family = AF_PACKET, .ll.sll_ifindex = ifindex, }; - _cleanup_close_ int fd = -1; - int r; assert(ifindex > 0); @@ -54,29 +48,24 @@ int lldp_network_bind_raw_socket(int ifindex) { if (fd < 0) return -errno; - r = setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &fprog, sizeof(fprog)); - if (r < 0) + if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &fprog, sizeof(fprog)) < 0) return -errno; /* customer bridge */ - r = setsockopt(fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); - if (r < 0) + if (setsockopt(fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) return -errno; /* non TPMR bridge */ mreq.mr_address[ETH_ALEN - 1] = 0x03; - r = setsockopt(fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); - if (r < 0) + if (setsockopt(fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) return -errno; /* nearest bridge */ mreq.mr_address[ETH_ALEN - 1] = 0x0E; - r = setsockopt(fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); - if (r < 0) + if (setsockopt(fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) return -errno; - r = bind(fd, &saddrll.sa, sizeof(saddrll.ll)); - if (r < 0) + if (bind(fd, &saddrll.sa, sizeof(saddrll.ll)) < 0) return -errno; return TAKE_FD(fd); diff --git a/src/libnm-systemd-core/src/libsystemd-network/network-common.h b/src/libnm-systemd-core/src/libsystemd-network/network-common.h index d43b76d4..2b0e3b56 100644 --- a/src/libnm-systemd-core/src/libsystemd-network/network-common.h +++ b/src/libnm-systemd-core/src/libsystemd-network/network-common.h @@ -8,8 +8,10 @@ int _e = (error); \ if (DEBUG_LOGGING) { \ const char *_n = NULL; \ + type *_v = (val); \ \ - (void) type##_get_ifname(val, &_n); \ + if (_v) \ + (void) type##_get_ifname(_v, &_n); \ log_interface_full_errno_zerook( \ _n, LOG_DEBUG, _e, prefix fmt, \ ##__VA_ARGS__); \ diff --git a/src/libnm-systemd-core/src/libsystemd-network/sd-dhcp-client.c b/src/libnm-systemd-core/src/libsystemd-network/sd-dhcp-client.c index cb984b6e..1600f806 100644 --- a/src/libnm-systemd-core/src/libsystemd-network/sd-dhcp-client.c +++ b/src/libnm-systemd-core/src/libsystemd-network/sd-dhcp-client.c @@ -837,7 +837,8 @@ static int client_message_init( return -ENOMEM; r = dhcp_message_init(&packet->dhcp, BOOTREQUEST, client->xid, type, - client->arp_type, optlen, &optoffset); + client->arp_type, client->mac_addr_len, client->mac_addr, + optlen, &optoffset); if (r < 0) return r; @@ -853,7 +854,7 @@ static int client_message_init( secs = ((time_now - client->start_time) / USEC_PER_SEC) ? : 1; packet->dhcp.secs = htobe16(secs); - /* RFC2132 section 4.1 + /* RFC2131 section 4.1 A client that cannot receive unicast IP datagrams until its protocol software has been configured with an IP address SHOULD set the BROADCAST bit in the 'flags' field to 1 in any DHCPDISCOVER or @@ -867,15 +868,6 @@ static int client_message_init( if (client->request_broadcast || client->arp_type != ARPHRD_ETHER) packet->dhcp.flags = htobe16(0x8000); - /* RFC2132 section 4.1.1: - The client MUST include its hardware address in the ’chaddr’ field, if - necessary for delivery of DHCP reply messages. Non-Ethernet - interfaces will leave 'chaddr' empty and use the client identifier - instead (eg, RFC 4390 section 2.1). - */ - if (client->arp_type == ARPHRD_ETHER) - memcpy(&packet->dhcp.chaddr, &client->mac_addr, ETH_ALEN); - /* If no client identifier exists, construct an RFC 4361-compliant one */ if (client->client_id_len == 0) { size_t duid_len; @@ -1935,13 +1927,13 @@ static int client_receive_message_udp( assert(client); buflen = next_datagram_size_fd(fd); - if (buflen == -ENETDOWN) - /* the link is down. Don't return an error or the I/O event - source will be disconnected and we won't be able to receive - packets again when the link comes back. */ + if (buflen < 0) { + if (ERRNO_IS_TRANSIENT(buflen) || ERRNO_IS_DISCONNECT(buflen)) + return 0; + + log_dhcp_client_errno(client, buflen, "Failed to determine datagram size to read, ignoring: %m"); return 0; - if (buflen < 0) - return buflen; + } message = malloc0(buflen); if (!message) @@ -1949,12 +1941,11 @@ static int client_receive_message_udp( len = recv(fd, message, buflen, 0); if (len < 0) { - /* see comment above for why we shouldn't error out on ENETDOWN. */ - if (IN_SET(errno, EAGAIN, EINTR, ENETDOWN)) + if (ERRNO_IS_TRANSIENT(errno) || ERRNO_IS_DISCONNECT(errno)) return 0; - return log_dhcp_client_errno(client, errno, - "Could not receive message from UDP socket: %m"); + log_dhcp_client_errno(client, errno, "Could not receive message from UDP socket, ignoring: %m"); + return 0; } if ((size_t) len < sizeof(DHCPMessage)) { log_dhcp_client(client, "Too small to be a DHCP message: ignoring"); @@ -2000,7 +1991,9 @@ static int client_receive_message_udp( return 0; } - return client_handle_message(client, message, len); + log_dhcp_client(client, "Received message from UDP socket, processing."); + (void) client_handle_message(client, message, len); + return 0; } static int client_receive_message_raw( @@ -2028,10 +2021,13 @@ static int client_receive_message_raw( assert(client); buflen = next_datagram_size_fd(fd); - if (buflen == -ENETDOWN) + if (buflen < 0) { + if (ERRNO_IS_TRANSIENT(buflen) || ERRNO_IS_DISCONNECT(buflen)) + return 0; + + log_dhcp_client_errno(client, buflen, "Failed to determine datagram size to read, ignoring: %m"); return 0; - if (buflen < 0) - return buflen; + } packet = malloc0(buflen); if (!packet) @@ -2040,12 +2036,13 @@ static int client_receive_message_raw( iov = IOVEC_MAKE(packet, buflen); len = recvmsg_safe(fd, &msg, 0); - if (IN_SET(len, -EAGAIN, -EINTR, -ENETDOWN)) - return 0; - if (len < 0) - return log_dhcp_client_errno(client, len, - "Could not receive message from raw socket: %m"); + if (len < 0) { + if (ERRNO_IS_TRANSIENT(len) || ERRNO_IS_DISCONNECT(len)) + return 0; + log_dhcp_client_errno(client, len, "Could not receive message from raw socket, ignoring: %m"); + return 0; + } if ((size_t) len < sizeof(DHCPPacket)) return 0; @@ -2061,7 +2058,9 @@ static int client_receive_message_raw( len -= DHCP_IP_UDP_SIZE; - return client_handle_message(client, &packet->dhcp, len); + log_dhcp_client(client, "Received message from RAW socket, processing."); + (void) client_handle_message(client, &packet->dhcp, len); + return 0; } int sd_dhcp_client_send_renew(sd_dhcp_client *client) { diff --git a/src/libnm-systemd-core/src/libsystemd-network/sd-dhcp-lease.c b/src/libnm-systemd-core/src/libsystemd-network/sd-dhcp-lease.c index 4cd9295c..7a250534 100644 --- a/src/libnm-systemd-core/src/libsystemd-network/sd-dhcp-lease.c +++ b/src/libnm-systemd-core/src/libsystemd-network/sd-dhcp-lease.c @@ -107,12 +107,13 @@ int sd_dhcp_lease_get_servers( assert_return(lease, -EINVAL); assert_return(what >= 0, -EINVAL); assert_return(what < _SD_DHCP_LEASE_SERVER_TYPE_MAX, -EINVAL); - assert_return(addr, -EINVAL); if (lease->servers[what].size <= 0) return -ENODATA; - *addr = lease->servers[what].addr; + if (addr) + *addr = lease->servers[what].addr; + return (int) lease->servers[what].size; } @@ -252,6 +253,33 @@ int sd_dhcp_lease_get_search_domains(sd_dhcp_lease *lease, char ***domains) { return -ENODATA; } +int sd_dhcp_lease_get_6rd( + sd_dhcp_lease *lease, + uint8_t *ret_ipv4masklen, + uint8_t *ret_prefixlen, + struct in6_addr *ret_prefix, + const struct in_addr **ret_br_addresses, + size_t *ret_n_br_addresses) { + + assert_return(lease, -EINVAL); + + if (lease->sixrd_n_br_addresses <= 0) + return -ENODATA; + + if (ret_ipv4masklen) + *ret_ipv4masklen = lease->sixrd_ipv4masklen; + if (ret_prefixlen) + *ret_prefixlen = lease->sixrd_prefixlen; + if (ret_prefix) + *ret_prefix = lease->sixrd_prefix; + if (ret_br_addresses) + *ret_br_addresses = lease->sixrd_br_addresses; + if (ret_n_br_addresses) + *ret_n_br_addresses = lease->sixrd_n_br_addresses; + + return 0; +} + int sd_dhcp_lease_get_vendor_specific(sd_dhcp_lease *lease, const void **data, size_t *data_len) { assert_return(lease, -EINVAL); assert_return(data, -EINVAL); @@ -290,6 +318,7 @@ static sd_dhcp_lease *dhcp_lease_free(sd_dhcp_lease *lease) { free(lease->client_id); free(lease->vendor_specific); strv_free(lease->search_domains); + free(lease->sixrd_br_addresses); return mfree(lease); } @@ -535,6 +564,61 @@ static int lease_parse_classless_routes( return 0; } +static int lease_parse_6rd(sd_dhcp_lease *lease, const uint8_t *option, size_t len) { + uint8_t ipv4masklen, prefixlen; + struct in6_addr prefix; + _cleanup_free_ struct in_addr *br_addresses = NULL; + size_t n_br_addresses; + + assert(lease); + assert(option); + + /* See RFC 5969 Section 7.1.1 */ + + if (lease->sixrd_n_br_addresses > 0) + /* Multiple 6rd option?? */ + return -EINVAL; + + /* option-length: The length of the DHCP option in octets (22 octets with one BR IPv4 address). */ + if (len < 2 + sizeof(struct in6_addr) + sizeof(struct in_addr) || + (len - 2 - sizeof(struct in6_addr)) % sizeof(struct in_addr) != 0) + return -EINVAL; + + /* IPv4MaskLen: The number of high-order bits that are identical across all CE IPv4 addresses + * within a given 6rd domain. This may be any value between 0 and 32. Any value + * greater than 32 is invalid. */ + ipv4masklen = option[0]; + if (ipv4masklen > 32) + return -EINVAL; + + /* 6rdPrefixLen: The IPv6 prefix length of the SP's 6rd IPv6 prefix in number of bits. For the + * purpose of bounds checking by DHCP option processing, the sum of + * (32 - IPv4MaskLen) + 6rdPrefixLen MUST be less than or equal to 128. */ + prefixlen = option[1]; + if (32 - ipv4masklen + prefixlen > 128) + return -EINVAL; + + /* 6rdPrefix: The service provider's 6rd IPv6 prefix represented as a 16-octet IPv6 address. + * The bits in the prefix after the 6rdPrefixlen number of bits are reserved and + * MUST be initialized to zero by the sender and ignored by the receiver. */ + memcpy(&prefix, option + 2, sizeof(struct in6_addr)); + (void) in6_addr_mask(&prefix, prefixlen); + + /* 6rdBRIPv4Address: One or more IPv4 addresses of the 6rd Border Relay(s) for a given 6rd domain. */ + n_br_addresses = (len - 2 - sizeof(struct in6_addr)) / sizeof(struct in_addr); + br_addresses = newdup(struct in_addr, option + 2 + sizeof(struct in6_addr), n_br_addresses); + if (!br_addresses) + return -ENOMEM; + + lease->sixrd_ipv4masklen = ipv4masklen; + lease->sixrd_prefixlen = prefixlen; + lease->sixrd_prefix = prefix; + lease->sixrd_br_addresses = TAKE_PTR(br_addresses); + lease->sixrd_n_br_addresses = n_br_addresses; + + return 0; +} + int dhcp_lease_parse_options(uint8_t code, uint8_t len, const void *option, void *userdata) { sd_dhcp_lease *lease = userdata; int r; @@ -693,7 +777,7 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const void *option, void } if (!timezone_is_valid(tz, LOG_DEBUG)) { - log_debug_errno(r, "Timezone is not valid, ignoring: %m"); + log_debug("Timezone is not valid, ignoring."); return 0; } @@ -720,6 +804,12 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const void *option, void lease->vendor_specific_len = len; break; + case SD_DHCP_OPTION_6RD: + r = lease_parse_6rd(lease, option, len); + if (r < 0) + log_debug_errno(r, "Failed to parse 6rd option, ignoring: %m"); + break; + case SD_DHCP_OPTION_PRIVATE_BASE ... SD_DHCP_OPTION_PRIVATE_LAST: r = dhcp_lease_insert_private_option(lease, code, option, len); if (r < 0) diff --git a/src/libnm-systemd-core/src/libsystemd-network/sd-dhcp6-client.c b/src/libnm-systemd-core/src/libsystemd-network/sd-dhcp6-client.c index 5398bdff..0c2206ff 100644 --- a/src/libnm-systemd-core/src/libsystemd-network/sd-dhcp6-client.c +++ b/src/libnm-systemd-core/src/libsystemd-network/sd-dhcp6-client.c @@ -27,6 +27,7 @@ #include "hexdecoct.h" #include "hostname-util.h" #include "in-addr-util.h" +#include "io-util.h" #include "network-common.h" #include "random-util.h" #include "socket-util.h" @@ -41,16 +42,16 @@ #define IRT_MINIMUM (600 * USEC_PER_SEC) /* what to request from the server, addresses (IA_NA) and/or prefixes (IA_PD) */ -enum { - DHCP6_REQUEST_IA_NA = 1, - DHCP6_REQUEST_IA_TA = 2, /* currently not used */ - DHCP6_REQUEST_IA_PD = 4, -}; +typedef enum DHCP6RequestIA { + DHCP6_REQUEST_IA_NA = 1 << 0, + DHCP6_REQUEST_IA_TA = 1 << 1, /* currently not used */ + DHCP6_REQUEST_IA_PD = 1 << 2, +} DHCP6RequestIA; struct sd_dhcp6_client { unsigned n_ref; - enum DHCP6State state; + DHCP6State state; sd_event *event; int event_priority; int ifindex; @@ -64,7 +65,7 @@ struct sd_dhcp6_client { DHCP6IA ia_pd; sd_event_source *timeout_t1; sd_event_source *timeout_t2; - unsigned request; + DHCP6RequestIA request_ia; be32_t transaction_id; usec_t transaction_start; struct sd_dhcp6_lease *lease; @@ -102,20 +103,42 @@ static const uint16_t default_req_opts[] = { SD_DHCP6_OPTION_SNTP_SERVERS, }; -const char * dhcp6_message_type_table[_DHCP6_MESSAGE_MAX] = { - [DHCP6_SOLICIT] = "SOLICIT", - [DHCP6_ADVERTISE] = "ADVERTISE", - [DHCP6_REQUEST] = "REQUEST", - [DHCP6_CONFIRM] = "CONFIRM", - [DHCP6_RENEW] = "RENEW", - [DHCP6_REBIND] = "REBIND", - [DHCP6_REPLY] = "REPLY", - [DHCP6_RELEASE] = "RELEASE", - [DHCP6_DECLINE] = "DECLINE", - [DHCP6_RECONFIGURE] = "RECONFIGURE", - [DHCP6_INFORMATION_REQUEST] = "INFORMATION-REQUEST", - [DHCP6_RELAY_FORW] = "RELAY-FORW", - [DHCP6_RELAY_REPL] = "RELAY-REPL", +const char * dhcp6_message_type_table[_DHCP6_MESSAGE_TYPE_MAX] = { + [DHCP6_MESSAGE_SOLICIT] = "Solicit", + [DHCP6_MESSAGE_ADVERTISE] = "Advertise", + [DHCP6_MESSAGE_REQUEST] = "Request", + [DHCP6_MESSAGE_CONFIRM] = "Confirm", + [DHCP6_MESSAGE_RENEW] = "Renew", + [DHCP6_MESSAGE_REBIND] = "Rebind", + [DHCP6_MESSAGE_REPLY] = "Reply", + [DHCP6_MESSAGE_RELEASE] = "Release", + [DHCP6_MESSAGE_DECLINE] = "Decline", + [DHCP6_MESSAGE_RECONFIGURE] = "Reconfigure", + [DHCP6_MESSAGE_INFORMATION_REQUEST] = "Information Request", + [DHCP6_MESSAGE_RELAY_FORWARD] = "Relay Forward", + [DHCP6_MESSAGE_RELAY_REPLY] = "Relay Reply", + [DHCP6_MESSAGE_LEASE_QUERY] = "Lease Query", + [DHCP6_MESSAGE_LEASE_QUERY_REPLY] = "Lease Query Reply", + [DHCP6_MESSAGE_LEASE_QUERY_DONE] = "Lease Query Done", + [DHCP6_MESSAGE_LEASE_QUERY_DATA] = "Lease Query Data", + [DHCP6_MESSAGE_RECONFIGURE_REQUEST] = "Reconfigure Request", + [DHCP6_MESSAGE_RECONFIGURE_REPLY] = "Reconfigure Reply", + [DHCP6_MESSAGE_DHCPV4_QUERY] = "DHCPv4 Query", + [DHCP6_MESSAGE_DHCPV4_RESPONSE] = "DHCPv4 Response", + [DHCP6_MESSAGE_ACTIVE_LEASE_QUERY] = "Active Lease Query", + [DHCP6_MESSAGE_START_TLS] = "Start TLS", + [DHCP6_MESSAGE_BINDING_UPDATE] = "Binding Update", + [DHCP6_MESSAGE_BINDING_REPLY] = "Binding Reply", + [DHCP6_MESSAGE_POOL_REQUEST] = "Pool Request", + [DHCP6_MESSAGE_POOL_RESPONSE] = "Pool Response", + [DHCP6_MESSAGE_UPDATE_REQUEST] = "Update Request", + [DHCP6_MESSAGE_UPDATE_REQUEST_ALL] = "Update Request All", + [DHCP6_MESSAGE_UPDATE_DONE] = "Update Done", + [DHCP6_MESSAGE_CONNECT] = "Connect", + [DHCP6_MESSAGE_CONNECT_REPLY] = "Connect Reply", + [DHCP6_MESSAGE_DISCONNECT] = "Disconnect", + [DHCP6_MESSAGE_STATE] = "State", + [DHCP6_MESSAGE_CONTACT] = "Contact", }; DEFINE_STRING_TABLE_LOOKUP(dhcp6_message_type, int); @@ -151,7 +174,7 @@ DEFINE_STRING_TABLE_LOOKUP(dhcp6_message_status, int); #define DHCP6_CLIENT_DONT_DESTROY(client) \ _cleanup_(sd_dhcp6_client_unrefp) _unused_ sd_dhcp6_client *_dont_destroy_##client = sd_dhcp6_client_ref(client) -static int client_start(sd_dhcp6_client *client, enum DHCP6State state); +static int client_start(sd_dhcp6_client *client, DHCP6State state); int sd_dhcp6_client_set_callback( sd_dhcp6_client *client, @@ -234,10 +257,6 @@ int sd_dhcp6_client_set_mac( return 0; } - if (client->mac_addr_len == addr_len && - memcmp(&client->mac_addr, addr, addr_len) == 0) - return 0; - memcpy(&client->mac_addr, addr, addr_len); client->mac_addr_len = addr_len; client->arp_type = arp_type; @@ -475,7 +494,7 @@ int sd_dhcp6_client_set_request_option(sd_dhcp6_client *client, uint16_t option) assert_return(client, -EINVAL); assert_return(client->state == DHCP6_STATE_STOPPED, -EBUSY); - if (option <= 0 || option >= UINT8_MAX) + if (!dhcp6_option_can_request(option)) return -EINVAL; for (t = 0; t < client->req_opts_len; t++) @@ -548,7 +567,7 @@ int sd_dhcp6_client_get_prefix_delegation(sd_dhcp6_client *client, int *delegati assert_return(client, -EINVAL); assert_return(delegation, -EINVAL); - *delegation = FLAGS_SET(client->request, DHCP6_REQUEST_IA_PD); + *delegation = FLAGS_SET(client->request_ia, DHCP6_REQUEST_IA_PD); return 0; } @@ -556,7 +575,7 @@ int sd_dhcp6_client_get_prefix_delegation(sd_dhcp6_client *client, int *delegati int sd_dhcp6_client_set_prefix_delegation(sd_dhcp6_client *client, int delegation) { assert_return(client, -EINVAL); - SET_FLAG(client->request, DHCP6_REQUEST_IA_PD, delegation); + SET_FLAG(client->request_ia, DHCP6_REQUEST_IA_PD, delegation); return 0; } @@ -565,7 +584,7 @@ int sd_dhcp6_client_get_address_request(sd_dhcp6_client *client, int *request) { assert_return(client, -EINVAL); assert_return(request, -EINVAL); - *request = FLAGS_SET(client->request, DHCP6_REQUEST_IA_NA); + *request = FLAGS_SET(client->request_ia, DHCP6_REQUEST_IA_NA); return 0; } @@ -573,7 +592,7 @@ int sd_dhcp6_client_get_address_request(sd_dhcp6_client *client, int *request) { int sd_dhcp6_client_set_address_request(sd_dhcp6_client *client, int request) { assert_return(client, -EINVAL); - SET_FLAG(client->request, DHCP6_REQUEST_IA_NA, request); + SET_FLAG(client->request_ia, DHCP6_REQUEST_IA_NA, request); return 0; } @@ -678,11 +697,11 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) { switch(client->state) { case DHCP6_STATE_INFORMATION_REQUEST: - message->type = DHCP6_INFORMATION_REQUEST; + message->type = DHCP6_MESSAGE_INFORMATION_REQUEST; if (client->mudurl) { r = dhcp6_option_append(&opt, &optlen, - SD_DHCP6_OPTION_MUD_URL, strlen(client->mudurl), + SD_DHCP6_OPTION_MUD_URL_V6, strlen(client->mudurl), client->mudurl); if (r < 0) return r; @@ -691,14 +710,14 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) { break; case DHCP6_STATE_SOLICITATION: - message->type = DHCP6_SOLICIT; + message->type = DHCP6_MESSAGE_SOLICIT; r = dhcp6_option_append(&opt, &optlen, SD_DHCP6_OPTION_RAPID_COMMIT, 0, NULL); if (r < 0) return r; - if (FLAGS_SET(client->request, DHCP6_REQUEST_IA_NA)) { + if (FLAGS_SET(client->request_ia, DHCP6_REQUEST_IA_NA)) { r = dhcp6_option_append_ia(&opt, &optlen, &client->ia_na); if (r < 0) @@ -713,7 +732,7 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) { if (client->mudurl) { r = dhcp6_option_append(&opt, &optlen, - SD_DHCP6_OPTION_MUD_URL, strlen(client->mudurl), + SD_DHCP6_OPTION_MUD_URL_V6, strlen(client->mudurl), client->mudurl); if (r < 0) return r; @@ -738,7 +757,7 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) { return r; } - if (FLAGS_SET(client->request, DHCP6_REQUEST_IA_PD)) { + if (FLAGS_SET(client->request_ia, DHCP6_REQUEST_IA_PD)) { r = dhcp6_option_append_pd(&opt, &optlen, &client->ia_pd, &client->hint_pd_prefix); if (r < 0) return r; @@ -750,9 +769,9 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) { case DHCP6_STATE_RENEW: if (client->state == DHCP6_STATE_REQUEST) - message->type = DHCP6_REQUEST; + message->type = DHCP6_MESSAGE_REQUEST; else - message->type = DHCP6_RENEW; + message->type = DHCP6_MESSAGE_RENEW; r = dhcp6_option_append(&opt, &optlen, SD_DHCP6_OPTION_SERVERID, client->lease->serverid_len, @@ -760,7 +779,7 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) { if (r < 0) return r; - if (FLAGS_SET(client->request, DHCP6_REQUEST_IA_NA) && client->lease->ia.addresses) { + if (FLAGS_SET(client->request_ia, DHCP6_REQUEST_IA_NA) && client->lease->ia.addresses) { r = dhcp6_option_append_ia(&opt, &optlen, &client->lease->ia); if (r < 0) @@ -775,7 +794,7 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) { if (client->mudurl) { r = dhcp6_option_append(&opt, &optlen, - SD_DHCP6_OPTION_MUD_URL, strlen(client->mudurl), + SD_DHCP6_OPTION_MUD_URL_V6, strlen(client->mudurl), client->mudurl); if (r < 0) return r; @@ -799,7 +818,7 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) { return r; } - if (FLAGS_SET(client->request, DHCP6_REQUEST_IA_PD) && client->lease->pd.addresses) { + if (FLAGS_SET(client->request_ia, DHCP6_REQUEST_IA_PD) && client->lease->pd.addresses) { r = dhcp6_option_append_pd(&opt, &optlen, &client->lease->pd, NULL); if (r < 0) return r; @@ -808,9 +827,9 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) { break; case DHCP6_STATE_REBIND: - message->type = DHCP6_REBIND; + message->type = DHCP6_MESSAGE_REBIND; - if (FLAGS_SET(client->request, DHCP6_REQUEST_IA_NA)) { + if (FLAGS_SET(client->request_ia, DHCP6_REQUEST_IA_NA)) { r = dhcp6_option_append_ia(&opt, &optlen, &client->lease->ia); if (r < 0) return r; @@ -824,7 +843,7 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) { if (client->mudurl) { r = dhcp6_option_append(&opt, &optlen, - SD_DHCP6_OPTION_MUD_URL, strlen(client->mudurl), + SD_DHCP6_OPTION_MUD_URL_V6, strlen(client->mudurl), client->mudurl); if (r < 0) return r; @@ -848,7 +867,7 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) { return r; } - if (FLAGS_SET(client->request, DHCP6_REQUEST_IA_PD)) { + if (FLAGS_SET(client->request_ia, DHCP6_REQUEST_IA_PD) && client->lease->pd.addresses) { r = dhcp6_option_append_pd(&opt, &optlen, &client->lease->pd, NULL); if (r < 0) return r; @@ -859,6 +878,8 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) { case DHCP6_STATE_STOPPED: case DHCP6_STATE_BOUND: return -EINVAL; + default: + assert_not_reached(); } r = dhcp6_option_append(&opt, &optlen, SD_DHCP6_OPTION_ORO, @@ -873,14 +894,12 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) { if (r < 0) return r; - elapsed_usec = time_now - client->transaction_start; - if (elapsed_usec < 0xffff * USEC_PER_MSEC * 10) - elapsed_time = htobe16(elapsed_usec / USEC_PER_MSEC / 10); - else - elapsed_time = 0xffff; - - r = dhcp6_option_append(&opt, &optlen, SD_DHCP6_OPTION_ELAPSED_TIME, - sizeof(elapsed_time), &elapsed_time); + /* RFC 8415 Section 21.9. + * A client MUST include an Elapsed Time option in messages to indicate how long the client has + * been trying to complete a DHCP message exchange. */ + elapsed_usec = MIN(usec_sub_unsigned(time_now, client->transaction_start) / USEC_PER_MSEC / 10, (usec_t) UINT16_MAX); + elapsed_time = htobe16(elapsed_usec); + r = dhcp6_option_append(&opt, &optlen, SD_DHCP6_OPTION_ELAPSED_TIME, sizeof(elapsed_time), &elapsed_time); if (r < 0) return r; @@ -936,7 +955,7 @@ static int client_timeout_t1(sd_event_source *s, uint64_t usec, void *userdata) static int client_timeout_resend_expire(sd_event_source *s, uint64_t usec, void *userdata) { sd_dhcp6_client *client = userdata; DHCP6_CLIENT_DONT_DESTROY(client); - enum DHCP6State state; + DHCP6State state; assert(s); assert(client); @@ -980,7 +999,7 @@ static int client_timeout_resend(sd_event_source *s, uint64_t usec, void *userda case DHCP6_STATE_SOLICITATION: - if (client->retransmit_count && client->lease) { + if (client->retransmit_count > 0 && client->lease) { client_start(client, DHCP6_STATE_REQUEST); return 0; } @@ -1027,6 +1046,8 @@ static int client_timeout_resend(sd_event_source *s, uint64_t usec, void *userda case DHCP6_STATE_STOPPED: case DHCP6_STATE_BOUND: return 0; + default: + assert_not_reached(); } if (max_retransmit_count > 0 && @@ -1051,8 +1072,8 @@ static int client_timeout_resend(sd_event_source *s, uint64_t usec, void *userda client->retransmit_time += init_retransmit_time / 10; } else { - if (max_retransmit_time > 0 && - client->retransmit_time > max_retransmit_time / 2) + assert(max_retransmit_time > 0); + if (client->retransmit_time > max_retransmit_time / 2) client->retransmit_time = client_timeout_compute_random(max_retransmit_time); else client->retransmit_time += client_timeout_compute_random(client->retransmit_time); @@ -1113,7 +1134,7 @@ static int client_ensure_iaid(sd_dhcp6_client *client) { return 0; } -static int client_parse_message( +int client_parse_message( sd_dhcp6_client *client, DHCP6Message *message, size_t len, @@ -1121,7 +1142,6 @@ static int client_parse_message( uint32_t lt_t1 = UINT32_MAX, lt_t2 = UINT32_MAX; usec_t irt = IRT_DEFAULT; - bool clientid = false; int r; assert(client); @@ -1141,23 +1161,19 @@ static int client_parse_message( switch (optcode) { case SD_DHCP6_OPTION_CLIENTID: - if (clientid) - return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "%s contains multiple clientids", + if (dhcp6_lease_get_clientid(lease, NULL, NULL) >= 0) + return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "%s contains multiple client IDs", dhcp6_message_type_to_string(message->type)); - if (optlen != client->duid_len || - memcmp(&client->duid, optval, optlen) != 0) - return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "%s DUID does not match", - dhcp6_message_type_to_string(message->type)); - - clientid = true; + r = dhcp6_lease_set_clientid(lease, optval, optlen); + if (r < 0) + return r; break; case SD_DHCP6_OPTION_SERVERID: - r = dhcp6_lease_get_serverid(lease, NULL, NULL); - if (r >= 0) - return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "%s contains multiple serverids", + if (dhcp6_lease_get_serverid(lease, NULL, NULL) >= 0) + return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "%s contains multiple server IDs", dhcp6_message_type_to_string(message->type)); r = dhcp6_lease_set_serverid(lease, optval, optlen); @@ -1255,35 +1271,35 @@ static int client_parse_message( case SD_DHCP6_OPTION_DNS_SERVERS: r = dhcp6_lease_add_dns(lease, optval, optlen); if (r < 0) - return r; + log_dhcp6_client_errno(client, r, "Failed to parse DNS server option, ignoring: %m"); break; case SD_DHCP6_OPTION_DOMAIN_LIST: r = dhcp6_lease_add_domains(lease, optval, optlen); if (r < 0) - return r; + log_dhcp6_client_errno(client, r, "Failed to parse domain list option, ignoring: %m"); break; case SD_DHCP6_OPTION_NTP_SERVER: r = dhcp6_lease_add_ntp(lease, optval, optlen); if (r < 0) - return r; + log_dhcp6_client_errno(client, r, "Failed to parse NTP server option, ignoring: %m"); break; case SD_DHCP6_OPTION_SNTP_SERVERS: r = dhcp6_lease_add_sntp(lease, optval, optlen); if (r < 0) - return r; + log_dhcp6_client_errno(client, r, "Failed to parse SNTP server option, ignoring: %m"); break; - case SD_DHCP6_OPTION_FQDN: + case SD_DHCP6_OPTION_CLIENT_FQDN: r = dhcp6_lease_set_fqdn(lease, optval, optlen); if (r < 0) - return r; + log_dhcp6_client_errno(client, r, "Failed to parse FQDN option, ignoring: %m"); break; @@ -1296,8 +1312,15 @@ static int client_parse_message( } } - if (!clientid) - return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "%s has incomplete options", + uint8_t *clientid; + size_t clientid_len; + if (dhcp6_lease_get_clientid(lease, &clientid, &clientid_len) < 0) + return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "%s message does not contain client ID. Ignoring.", + dhcp6_message_type_to_string(message->type)); + + if (clientid_len != client->duid_len || + memcmp(clientid, &client->duid, clientid_len) != 0) + return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "The client ID in %s message does not match. Ignoring.", dhcp6_message_type_to_string(message->type)); if (client->state != DHCP6_STATE_INFORMATION_REQUEST) { @@ -1325,21 +1348,32 @@ static int client_parse_message( return 0; } -static int client_receive_reply(sd_dhcp6_client *client, DHCP6Message *reply, size_t len) { +static int client_receive_reply( + sd_dhcp6_client *client, + DHCP6Message *reply, + size_t len, + const triple_timestamp *t, + const struct in6_addr *server_address) { + _cleanup_(sd_dhcp6_lease_unrefp) sd_dhcp6_lease *lease = NULL; bool rapid_commit; int r; assert(client); assert(reply); + assert(t); - if (reply->type != DHCP6_REPLY) + if (reply->type != DHCP6_MESSAGE_REPLY) return 0; r = dhcp6_lease_new(&lease); if (r < 0) return -ENOMEM; + lease->timestamp = *t; + if (server_address) + lease->server_address = *server_address; + r = client_parse_message(client, reply, len, lease); if (r < 0) return r; @@ -1359,18 +1393,32 @@ static int client_receive_reply(sd_dhcp6_client *client, DHCP6Message *reply, si return DHCP6_STATE_BOUND; } -static int client_receive_advertise(sd_dhcp6_client *client, DHCP6Message *advertise, size_t len) { +static int client_receive_advertise( + sd_dhcp6_client *client, + DHCP6Message *advertise, + size_t len, + const triple_timestamp *t, + const struct in6_addr *server_address) { + _cleanup_(sd_dhcp6_lease_unrefp) sd_dhcp6_lease *lease = NULL; uint8_t pref_advertise = 0, pref_lease = 0; int r; - if (advertise->type != DHCP6_ADVERTISE) + assert(client); + assert(advertise); + assert(t); + + if (advertise->type != DHCP6_MESSAGE_ADVERTISE) return 0; r = dhcp6_lease_new(&lease); if (r < 0) return r; + lease->timestamp = *t; + if (server_address) + lease->server_address = *server_address; + r = client_parse_message(client, advertise, len, lease); if (r < 0) return r; @@ -1401,7 +1449,22 @@ static int client_receive_message( sd_dhcp6_client *client = userdata; DHCP6_CLIENT_DONT_DESTROY(client); + /* This needs to be initialized with zero. See #20741. */ + CMSG_BUFFER_TYPE(CMSG_SPACE_TIMEVAL) control = {}; + struct iovec iov; + union sockaddr_union sa = {}; + struct msghdr msg = { + .msg_name = &sa.sa, + .msg_namelen = sizeof(sa), + .msg_iov = &iov, + .msg_iovlen = 1, + .msg_control = &control, + .msg_controllen = sizeof(control), + }; + struct cmsghdr *cmsg; + triple_timestamp t = {}; _cleanup_free_ DHCP6Message *message = NULL; + struct in6_addr *server_address = NULL; ssize_t buflen, len; int r = 0; @@ -1410,52 +1473,59 @@ static int client_receive_message( assert(client->event); buflen = next_datagram_size_fd(fd); - if (buflen == -ENETDOWN) - /* the link is down. Don't return an error or the I/O event - source will be disconnected and we won't be able to receive - packets again when the link comes back. */ + if (buflen < 0) { + if (ERRNO_IS_TRANSIENT(buflen) || ERRNO_IS_DISCONNECT(buflen)) + return 0; + + log_dhcp6_client_errno(client, buflen, "Failed to determine datagram size to read, ignoring: %m"); return 0; - if (buflen < 0) - return buflen; + } message = malloc(buflen); if (!message) return -ENOMEM; - len = recv(fd, message, buflen, 0); + iov = IOVEC_MAKE(message, buflen); + + len = recvmsg_safe(fd, &msg, MSG_DONTWAIT); if (len < 0) { - /* see comment above for why we shouldn't error out on ENETDOWN. */ - if (IN_SET(errno, EAGAIN, EINTR, ENETDOWN)) + if (ERRNO_IS_TRANSIENT(len) || ERRNO_IS_DISCONNECT(len)) return 0; - return log_dhcp6_client_errno(client, errno, "Could not receive message from UDP socket: %m"); - + log_dhcp6_client_errno(client, len, "Could not receive message from UDP socket, ignoring: %m"); + return 0; } if ((size_t) len < sizeof(DHCP6Message)) { log_dhcp6_client(client, "Too small to be DHCP6 message: ignoring"); return 0; } - switch(message->type) { - case DHCP6_SOLICIT: - case DHCP6_REQUEST: - case DHCP6_CONFIRM: - case DHCP6_RENEW: - case DHCP6_REBIND: - case DHCP6_RELEASE: - case DHCP6_DECLINE: - case DHCP6_INFORMATION_REQUEST: - case DHCP6_RELAY_FORW: - case DHCP6_RELAY_REPL: - return 0; + /* msg_namelen == 0 happens when running the test-suite over a socketpair */ + if (msg.msg_namelen > 0) { + if (msg.msg_namelen != sizeof(struct sockaddr_in6) || sa.in6.sin6_family != AF_INET6) { + log_dhcp6_client(client, "Received message from invalid source, ignoring."); + return 0; + } - case DHCP6_ADVERTISE: - case DHCP6_REPLY: - case DHCP6_RECONFIGURE: - break; + server_address = &sa.in6.sin6_addr; + } - default: - log_dhcp6_client(client, "Unknown message type %d", message->type); + CMSG_FOREACH(cmsg, &msg) { + if (cmsg->cmsg_level == SOL_SOCKET && + cmsg->cmsg_type == SO_TIMESTAMP && + cmsg->cmsg_len == CMSG_LEN(sizeof(struct timeval))) + triple_timestamp_from_realtime(&t, timeval_load((struct timeval*) CMSG_DATA(cmsg))); + } + + if (!triple_timestamp_is_set(&t)) + triple_timestamp_get(&t); + + if (!IN_SET(message->type, DHCP6_MESSAGE_ADVERTISE, DHCP6_MESSAGE_REPLY, DHCP6_MESSAGE_RECONFIGURE)) { + const char *type_str = dhcp6_message_type_to_string(message->type); + if (type_str) + log_dhcp6_client(client, "Received unexpected %s message, ignoring.", type_str); + else + log_dhcp6_client(client, "Received unsupported message type %u, ignoring.", message->type); return 0; } @@ -1464,7 +1534,7 @@ static int client_receive_message( switch (client->state) { case DHCP6_STATE_INFORMATION_REQUEST: - r = client_receive_reply(client, message, len); + r = client_receive_reply(client, message, len, &t, server_address); if (r < 0) { log_dhcp6_client_errno(client, r, "Failed to process received reply message, ignoring: %m"); return 0; @@ -1477,7 +1547,7 @@ static int client_receive_message( break; case DHCP6_STATE_SOLICITATION: - r = client_receive_advertise(client, message, len); + r = client_receive_advertise(client, message, len, &t, server_address); if (r < 0) { log_dhcp6_client_errno(client, r, "Failed to process received advertise message, ignoring: %m"); return 0; @@ -1493,7 +1563,7 @@ static int client_receive_message( case DHCP6_STATE_RENEW: case DHCP6_STATE_REBIND: - r = client_receive_reply(client, message, len); + r = client_receive_reply(client, message, len, &t, server_address); if (r < 0) { log_dhcp6_client_errno(client, r, "Failed to process received reply message, ignoring: %m"); return 0; @@ -1517,6 +1587,8 @@ static int client_receive_message( case DHCP6_STATE_STOPPED: return 0; + default: + assert_not_reached(); } log_dhcp6_client(client, "Recv %s", @@ -1530,14 +1602,14 @@ static int client_get_lifetime(sd_dhcp6_client *client, uint32_t *lifetime_t1, assert_return(client, -EINVAL); assert_return(client->lease, -EINVAL); - if (FLAGS_SET(client->request, DHCP6_REQUEST_IA_NA) && client->lease->ia.addresses) { + if (FLAGS_SET(client->request_ia, DHCP6_REQUEST_IA_NA) && client->lease->ia.addresses) { *lifetime_t1 = be32toh(client->lease->ia.ia_na.lifetime_t1); *lifetime_t2 = be32toh(client->lease->ia.ia_na.lifetime_t2); return 0; } - if (FLAGS_SET(client->request, DHCP6_REQUEST_IA_PD) && client->lease->pd.addresses) { + if (FLAGS_SET(client->request_ia, DHCP6_REQUEST_IA_PD) && client->lease->pd.addresses) { *lifetime_t1 = be32toh(client->lease->pd.ia_pd.lifetime_t1); *lifetime_t2 = be32toh(client->lease->pd.ia_pd.lifetime_t2); @@ -1547,7 +1619,7 @@ static int client_get_lifetime(sd_dhcp6_client *client, uint32_t *lifetime_t1, return -ENOMSG; } -static int client_start(sd_dhcp6_client *client, enum DHCP6State state) { +static int client_start(sd_dhcp6_client *client, DHCP6State state) { int r; usec_t timeout, time_now; uint32_t lifetime_t1, lifetime_t2; @@ -1647,6 +1719,8 @@ static int client_start(sd_dhcp6_client *client, enum DHCP6State state) { client->state = state; return 0; + default: + assert_not_reached(); } client->transaction_id = random_u32() & htobe32(0x00ffffff); @@ -1685,7 +1759,7 @@ int sd_dhcp6_client_is_running(sd_dhcp6_client *client) { } int sd_dhcp6_client_start(sd_dhcp6_client *client) { - enum DHCP6State state = DHCP6_STATE_SOLICITATION; + DHCP6State state = DHCP6_STATE_SOLICITATION; int r; assert_return(client, -EINVAL); @@ -1696,7 +1770,7 @@ int sd_dhcp6_client_start(sd_dhcp6_client *client) { if (client->state != DHCP6_STATE_STOPPED) return -EBUSY; - if (!client->information_request && !client->request) + if (!client->information_request && client->request_ia == 0) return -EINVAL; r = client_reset(client); @@ -1824,7 +1898,7 @@ int sd_dhcp6_client_new(sd_dhcp6_client **ret) { .ia_na.type = SD_DHCP6_OPTION_IA_NA, .ia_pd.type = SD_DHCP6_OPTION_IA_PD, .ifindex = -1, - .request = DHCP6_REQUEST_IA_NA, + .request_ia = DHCP6_REQUEST_IA_NA | DHCP6_REQUEST_IA_PD, .fd = -1, .req_opts_len = ELEMENTSOF(default_req_opts), .hint_pd_prefix.iapdprefix.lifetime_preferred = (be32_t) -1, diff --git a/src/libnm-systemd-core/src/libsystemd-network/sd-dhcp6-lease.c b/src/libnm-systemd-core/src/libsystemd-network/sd-dhcp6-lease.c index 85649d92..b46a2e33 100644 --- a/src/libnm-systemd-core/src/libsystemd-network/sd-dhcp6-lease.c +++ b/src/libnm-systemd-core/src/libsystemd-network/sd-dhcp6-lease.c @@ -13,6 +13,27 @@ #include "strv.h" #include "util.h" +int sd_dhcp6_lease_get_timestamp(sd_dhcp6_lease *lease, clockid_t clock, uint64_t *ret) { + assert_return(lease, -EINVAL); + assert_return(TRIPLE_TIMESTAMP_HAS_CLOCK(clock), -EOPNOTSUPP); + assert_return(clock_supported(clock), -EOPNOTSUPP); + assert_return(ret, -EINVAL); + + if (!triple_timestamp_is_set(&lease->timestamp)) + return -ENODATA; + + *ret = triple_timestamp_by_clock(&lease->timestamp, clock); + return 0; +} + +int sd_dhcp6_lease_get_server_address(sd_dhcp6_lease *lease, struct in6_addr *ret) { + assert_return(lease, -EINVAL); + assert_return(ret, -EINVAL); + + *ret = lease->server_address; + return 0; +} + int dhcp6_lease_ia_rebind_expire(const DHCP6IA *ia, uint32_t *expire) { DHCP6Address *addr; uint32_t valid = 0, t; @@ -52,12 +73,43 @@ DHCP6IA *dhcp6_lease_free_ia(DHCP6IA *ia) { return NULL; } -int dhcp6_lease_set_serverid(sd_dhcp6_lease *lease, const uint8_t *id, - size_t len) { +int dhcp6_lease_set_clientid(sd_dhcp6_lease *lease, const uint8_t *id, size_t len) { + uint8_t *clientid; + + assert_return(lease, -EINVAL); + assert_return(id, -EINVAL); + assert_return(len > 0, -EINVAL); + + clientid = memdup(id, len); + if (!clientid) + return -ENOMEM; + + free_and_replace(lease->clientid, clientid); + lease->clientid_len = len; + + return 0; +} + +int dhcp6_lease_get_clientid(sd_dhcp6_lease *lease, uint8_t **ret_id, size_t *ret_len) { + assert_return(lease, -EINVAL); + + if (!lease->clientid) + return -ENODATA; + + if (ret_id) + *ret_id = lease->clientid; + if (ret_len) + *ret_len = lease->clientid_len; + + return 0; +} + +int dhcp6_lease_set_serverid(sd_dhcp6_lease *lease, const uint8_t *id, size_t len) { uint8_t *serverid; assert_return(lease, -EINVAL); assert_return(id, -EINVAL); + assert_return(len > 0, -EINVAL); serverid = memdup(id, len); if (!serverid) @@ -69,16 +121,16 @@ int dhcp6_lease_set_serverid(sd_dhcp6_lease *lease, const uint8_t *id, return 0; } -int dhcp6_lease_get_serverid(sd_dhcp6_lease *lease, uint8_t **id, size_t *len) { +int dhcp6_lease_get_serverid(sd_dhcp6_lease *lease, uint8_t **ret_id, size_t *ret_len) { assert_return(lease, -EINVAL); if (!lease->serverid) - return -ENOMSG; + return -ENODATA; - if (id) - *id = lease->serverid; - if (len) - *len = lease->serverid_len; + if (ret_id) + *ret_id = lease->serverid; + if (ret_len) + *ret_len = lease->serverid_len; return 0; } @@ -119,24 +171,6 @@ int dhcp6_lease_get_rapid_commit(sd_dhcp6_lease *lease, bool *rapid_commit) { return 0; } -int dhcp6_lease_get_iaid(sd_dhcp6_lease *lease, be32_t *iaid) { - assert_return(lease, -EINVAL); - assert_return(iaid, -EINVAL); - - *iaid = lease->ia.ia_na.id; - - return 0; -} - -int dhcp6_lease_get_pd_iaid(sd_dhcp6_lease *lease, be32_t *iaid) { - assert_return(lease, -EINVAL); - assert_return(iaid, -EINVAL); - - *iaid = lease->pd.ia_pd.id; - - return 0; -} - int sd_dhcp6_lease_get_address(sd_dhcp6_lease *lease, struct in6_addr *addr, uint32_t *lifetime_preferred, uint32_t *lifetime_valid) { @@ -207,12 +241,13 @@ int dhcp6_lease_add_dns(sd_dhcp6_lease *lease, const uint8_t *optval, size_t opt int sd_dhcp6_lease_get_dns(sd_dhcp6_lease *lease, const struct in6_addr **ret) { assert_return(lease, -EINVAL); - assert_return(ret, -EINVAL); if (!lease->dns) return -ENOENT; - *ret = lease->dns; + if (ret) + *ret = lease->dns; + return lease->dns_count; } @@ -305,16 +340,17 @@ int dhcp6_lease_add_sntp(sd_dhcp6_lease *lease, const uint8_t *optval, size_t op int sd_dhcp6_lease_get_ntp_addrs(sd_dhcp6_lease *lease, const struct in6_addr **ret) { assert_return(lease, -EINVAL); - assert_return(ret, -EINVAL); if (lease->ntp) { - *ret = lease->ntp; + if (ret) + *ret = lease->ntp; return lease->ntp_count; } if (lease->sntp && !lease->ntp_fqdn) { /* Fallback to the deprecated SNTP option. */ - *ret = lease->sntp; + if (ret) + *ret = lease->sntp; return lease->sntp_count; } @@ -323,12 +359,12 @@ int sd_dhcp6_lease_get_ntp_addrs(sd_dhcp6_lease *lease, const struct in6_addr ** int sd_dhcp6_lease_get_ntp_fqdn(sd_dhcp6_lease *lease, char ***ret) { assert_return(lease, -EINVAL); - assert_return(ret, -EINVAL); if (!lease->ntp_fqdn) return -ENOENT; - *ret = lease->ntp_fqdn; + if (ret) + *ret = lease->ntp_fqdn; return strv_length(lease->ntp_fqdn); } @@ -366,6 +402,7 @@ static sd_dhcp6_lease *dhcp6_lease_free(sd_dhcp6_lease *lease) { if (!lease) return NULL; + free(lease->clientid); free(lease->serverid); dhcp6_lease_free_ia(&lease->ia); dhcp6_lease_free_ia(&lease->pd); diff --git a/src/libnm-systemd-core/src/libsystemd-network/sd-ipv4acd.c b/src/libnm-systemd-core/src/libsystemd-network/sd-ipv4acd.c deleted file mode 100644 index f0612ed5..00000000 --- a/src/libnm-systemd-core/src/libsystemd-network/sd-ipv4acd.c +++ /dev/null @@ -1,616 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/*** - Copyright © 2014 Axis Communications AB. All rights reserved. -***/ - -#include "nm-sd-adapt-core.h" - -#include -#include -#include -#include -#include - -#include "sd-ipv4acd.h" - -#include "alloc-util.h" -#include "arp-util.h" -#include "ether-addr-util.h" -#include "event-util.h" -#include "fd-util.h" -#include "in-addr-util.h" -#include "memory-util.h" -#include "network-common.h" -#include "random-util.h" -#include "siphash24.h" -#include "string-table.h" -#include "string-util.h" -#include "time-util.h" - -/* Constants from the RFC */ -#define PROBE_WAIT_USEC (1U * USEC_PER_SEC) -#define PROBE_NUM 3U -#define PROBE_MIN_USEC (1U * USEC_PER_SEC) -#define PROBE_MAX_USEC (2U * USEC_PER_SEC) -#define ANNOUNCE_WAIT_USEC (2U * USEC_PER_SEC) -#define ANNOUNCE_NUM 2U -#define ANNOUNCE_INTERVAL_USEC (2U * USEC_PER_SEC) -#define MAX_CONFLICTS 10U -#define RATE_LIMIT_INTERVAL_USEC (60U * USEC_PER_SEC) -#define DEFEND_INTERVAL_USEC (10U * USEC_PER_SEC) - -typedef enum IPv4ACDState { - IPV4ACD_STATE_INIT, - IPV4ACD_STATE_STARTED, - IPV4ACD_STATE_WAITING_PROBE, - IPV4ACD_STATE_PROBING, - IPV4ACD_STATE_WAITING_ANNOUNCE, - IPV4ACD_STATE_ANNOUNCING, - IPV4ACD_STATE_RUNNING, - _IPV4ACD_STATE_MAX, - _IPV4ACD_STATE_INVALID = -EINVAL, -} IPv4ACDState; - -struct sd_ipv4acd { - unsigned n_ref; - - IPv4ACDState state; - int ifindex; - int fd; - - char *ifname; - unsigned n_iteration; - unsigned n_conflict; - - sd_event_source *receive_message_event_source; - sd_event_source *timer_event_source; - - usec_t defend_window; - struct in_addr address; - - /* External */ - struct ether_addr mac_addr; - - sd_event *event; - int event_priority; - sd_ipv4acd_callback_t callback; - void *userdata; - sd_ipv4acd_check_mac_callback_t check_mac_callback; - void *check_mac_userdata; -}; - -#define log_ipv4acd_errno(acd, error, fmt, ...) \ - log_interface_prefix_full_errno( \ - "IPv4ACD: ", \ - sd_ipv4acd, acd, \ - error, fmt, ##__VA_ARGS__) -#define log_ipv4acd(acd, fmt, ...) \ - log_interface_prefix_full_errno_zerook( \ - "IPv4ACD: ", \ - sd_ipv4acd, acd, \ - 0, fmt, ##__VA_ARGS__) - -static const char * const ipv4acd_state_table[_IPV4ACD_STATE_MAX] = { - [IPV4ACD_STATE_INIT] = "init", - [IPV4ACD_STATE_STARTED] = "started", - [IPV4ACD_STATE_WAITING_PROBE] = "waiting-probe", - [IPV4ACD_STATE_PROBING] = "probing", - [IPV4ACD_STATE_WAITING_ANNOUNCE] = "waiting-announce", - [IPV4ACD_STATE_ANNOUNCING] = "announcing", - [IPV4ACD_STATE_RUNNING] = "running", -}; - -DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(ipv4acd_state, IPv4ACDState); - -static void ipv4acd_set_state(sd_ipv4acd *acd, IPv4ACDState st, bool reset_counter) { - assert(acd); - assert(st < _IPV4ACD_STATE_MAX); - - if (st != acd->state) - log_ipv4acd(acd, "%s -> %s", ipv4acd_state_to_string(acd->state), ipv4acd_state_to_string(st)); - - if (st == acd->state && !reset_counter) - acd->n_iteration++; - else { - acd->state = st; - acd->n_iteration = 0; - } -} - -static void ipv4acd_reset(sd_ipv4acd *acd) { - assert(acd); - - (void) event_source_disable(acd->timer_event_source); - acd->receive_message_event_source = sd_event_source_disable_unref(acd->receive_message_event_source); - - acd->fd = safe_close(acd->fd); - - ipv4acd_set_state(acd, IPV4ACD_STATE_INIT, true); -} - -static sd_ipv4acd *ipv4acd_free(sd_ipv4acd *acd) { - assert(acd); - - ipv4acd_reset(acd); - sd_event_source_unref(acd->timer_event_source); - sd_ipv4acd_detach_event(acd); - free(acd->ifname); - return mfree(acd); -} - -DEFINE_TRIVIAL_REF_UNREF_FUNC(sd_ipv4acd, sd_ipv4acd, ipv4acd_free); - -int sd_ipv4acd_new(sd_ipv4acd **ret) { - _cleanup_(sd_ipv4acd_unrefp) sd_ipv4acd *acd = NULL; - - assert_return(ret, -EINVAL); - - acd = new(sd_ipv4acd, 1); - if (!acd) - return -ENOMEM; - - *acd = (sd_ipv4acd) { - .n_ref = 1, - .state = IPV4ACD_STATE_INIT, - .ifindex = -1, - .fd = -1, - }; - - *ret = TAKE_PTR(acd); - - return 0; -} - -static void ipv4acd_client_notify(sd_ipv4acd *acd, int event) { - assert(acd); - - if (!acd->callback) - return; - - acd->callback(acd, event, acd->userdata); -} - -int sd_ipv4acd_stop(sd_ipv4acd *acd) { - IPv4ACDState old_state; - - if (!acd) - return 0; - - old_state = acd->state; - - ipv4acd_reset(acd); - - if (old_state == IPV4ACD_STATE_INIT) - return 0; - - log_ipv4acd(acd, "STOPPED"); - - ipv4acd_client_notify(acd, SD_IPV4ACD_EVENT_STOP); - - return 0; -} - -static int ipv4acd_on_timeout(sd_event_source *s, uint64_t usec, void *userdata); - -static int ipv4acd_set_next_wakeup(sd_ipv4acd *acd, usec_t usec, usec_t random_usec) { - usec_t next_timeout, time_now; - - assert(acd); - - next_timeout = usec; - - if (random_usec > 0) - next_timeout += (usec_t) random_u64() % random_usec; - - assert_se(sd_event_now(acd->event, clock_boottime_or_monotonic(), &time_now) >= 0); - - return event_reset_time(acd->event, &acd->timer_event_source, - clock_boottime_or_monotonic(), - time_now + next_timeout, 0, - ipv4acd_on_timeout, acd, - acd->event_priority, "ipv4acd-timer", true); -} - -static int ipv4acd_on_timeout(sd_event_source *s, uint64_t usec, void *userdata) { - sd_ipv4acd *acd = userdata; - int r = 0; - - assert(acd); - - switch (acd->state) { - - case IPV4ACD_STATE_STARTED: - acd->defend_window = 0; - - ipv4acd_set_state(acd, IPV4ACD_STATE_WAITING_PROBE, true); - - if (acd->n_conflict >= MAX_CONFLICTS) { - log_ipv4acd(acd, "Max conflicts reached, delaying by %s", - FORMAT_TIMESPAN(RATE_LIMIT_INTERVAL_USEC, 0)); - r = ipv4acd_set_next_wakeup(acd, RATE_LIMIT_INTERVAL_USEC, PROBE_WAIT_USEC); - } else - r = ipv4acd_set_next_wakeup(acd, 0, PROBE_WAIT_USEC); - if (r < 0) - goto fail; - - break; - - case IPV4ACD_STATE_WAITING_PROBE: - case IPV4ACD_STATE_PROBING: - /* Send a probe */ - r = arp_send_probe(acd->fd, acd->ifindex, &acd->address, &acd->mac_addr); - if (r < 0) { - log_ipv4acd_errno(acd, r, "Failed to send ARP probe: %m"); - goto fail; - } - - log_ipv4acd(acd, "Probing "IPV4_ADDRESS_FMT_STR, IPV4_ADDRESS_FMT_VAL(acd->address)); - - if (acd->n_iteration < PROBE_NUM - 2) { - ipv4acd_set_state(acd, IPV4ACD_STATE_PROBING, false); - - r = ipv4acd_set_next_wakeup(acd, PROBE_MIN_USEC, (PROBE_MAX_USEC-PROBE_MIN_USEC)); - if (r < 0) - goto fail; - } else { - ipv4acd_set_state(acd, IPV4ACD_STATE_WAITING_ANNOUNCE, true); - - r = ipv4acd_set_next_wakeup(acd, ANNOUNCE_WAIT_USEC, 0); - if (r < 0) - goto fail; - } - - break; - - case IPV4ACD_STATE_ANNOUNCING: - if (acd->n_iteration >= ANNOUNCE_NUM - 1) { - ipv4acd_set_state(acd, IPV4ACD_STATE_RUNNING, false); - break; - } - - _fallthrough_; - case IPV4ACD_STATE_WAITING_ANNOUNCE: - /* Send announcement packet */ - r = arp_send_announcement(acd->fd, acd->ifindex, &acd->address, &acd->mac_addr); - if (r < 0) { - log_ipv4acd_errno(acd, r, "Failed to send ARP announcement: %m"); - goto fail; - } - - log_ipv4acd(acd, "Announcing "IPV4_ADDRESS_FMT_STR, IPV4_ADDRESS_FMT_VAL(acd->address)); - - ipv4acd_set_state(acd, IPV4ACD_STATE_ANNOUNCING, false); - - r = ipv4acd_set_next_wakeup(acd, ANNOUNCE_INTERVAL_USEC, 0); - if (r < 0) - goto fail; - - if (acd->n_iteration == 0) { - acd->n_conflict = 0; - ipv4acd_client_notify(acd, SD_IPV4ACD_EVENT_BIND); - } - - break; - - default: - assert_not_reached(); - } - - return 0; - -fail: - sd_ipv4acd_stop(acd); - return 0; -} - -static bool ipv4acd_arp_conflict(sd_ipv4acd *acd, const struct ether_arp *arp, bool announced) { - assert(acd); - assert(arp); - - /* RFC 5227 section 2.1.1. - * "the host receives any ARP packet (Request *or* Reply) on the interface where the probe is - * being performed, where the packet's 'sender IP address' is the address being probed for, - * then the host MUST treat this address as being in use by some other host" */ - if (memcmp(arp->arp_spa, &acd->address, sizeof(struct in_addr)) == 0) - return true; - - if (announced) - /* the TPA matched instead of SPA, this is not a conflict */ - return false; - - /* "any ARP Probe where the packet's 'target IP address' is the address being probed for, and - * the packet's 'sender hardware address' is not the hardware address of any of the host's - * interfaces, then the host SHOULD similarly treat this as an address conflict" */ - if (arp->ea_hdr.ar_op != htobe16(ARPOP_REQUEST)) - return false; /* not ARP Request, ignoring. */ - if (memeqzero(arp->arp_spa, sizeof(struct in_addr)) == 0) - return false; /* not ARP Probe, ignoring. */ - if (memcmp(arp->arp_tpa, &acd->address, sizeof(struct in_addr)) != 0) - return false; /* target IP address does not match, BPF code is broken? */ - - if (acd->check_mac_callback && - acd->check_mac_callback(acd, (const struct ether_addr*) arp->arp_sha, acd->check_mac_userdata) > 0) - /* sender hardware is one of the host's interfaces, ignoring. */ - return true; - - return true; /* conflict! */ -} - -static void ipv4acd_on_conflict(sd_ipv4acd *acd) { - assert(acd); - - acd->n_conflict++; - - log_ipv4acd(acd, "Conflict on "IPV4_ADDRESS_FMT_STR" (%u)", IPV4_ADDRESS_FMT_VAL(acd->address), acd->n_conflict); - - ipv4acd_reset(acd); - ipv4acd_client_notify(acd, SD_IPV4ACD_EVENT_CONFLICT); -} - -static int ipv4acd_on_packet( - sd_event_source *s, - int fd, - uint32_t revents, - void *userdata) { - - sd_ipv4acd *acd = userdata; - struct ether_arp packet; - ssize_t n; - int r; - - assert(s); - assert(acd); - assert(fd >= 0); - - n = recv(fd, &packet, sizeof(struct ether_arp), 0); - if (n < 0) { - if (IN_SET(errno, EAGAIN, EINTR)) - return 0; - - log_ipv4acd_errno(acd, errno, "Failed to read ARP packet: %m"); - goto fail; - } - if ((size_t) n != sizeof(struct ether_arp)) { - log_ipv4acd(acd, "Ignoring too short ARP packet."); - return 0; - } - - switch (acd->state) { - - case IPV4ACD_STATE_ANNOUNCING: - case IPV4ACD_STATE_RUNNING: - - if (ipv4acd_arp_conflict(acd, &packet, true)) { - usec_t ts; - - assert_se(sd_event_now(acd->event, clock_boottime_or_monotonic(), &ts) >= 0); - - /* Defend address */ - if (ts > acd->defend_window) { - acd->defend_window = ts + DEFEND_INTERVAL_USEC; - r = arp_send_announcement(acd->fd, acd->ifindex, &acd->address, &acd->mac_addr); - if (r < 0) { - log_ipv4acd_errno(acd, r, "Failed to send ARP announcement: %m"); - goto fail; - } - - log_ipv4acd(acd, "Defending "IPV4_ADDRESS_FMT_STR, IPV4_ADDRESS_FMT_VAL(acd->address)); - - } else - ipv4acd_on_conflict(acd); - } - break; - - case IPV4ACD_STATE_WAITING_PROBE: - case IPV4ACD_STATE_PROBING: - case IPV4ACD_STATE_WAITING_ANNOUNCE: - if (ipv4acd_arp_conflict(acd, &packet, false)) - ipv4acd_on_conflict(acd); - break; - - default: - assert_not_reached(); - } - - return 0; - -fail: - sd_ipv4acd_stop(acd); - return 0; -} - -int sd_ipv4acd_set_ifindex(sd_ipv4acd *acd, int ifindex) { - assert_return(acd, -EINVAL); - assert_return(ifindex > 0, -EINVAL); - assert_return(acd->state == IPV4ACD_STATE_INIT, -EBUSY); - - acd->ifindex = ifindex; - - return 0; -} - -int sd_ipv4acd_get_ifindex(sd_ipv4acd *acd) { - if (!acd) - return -EINVAL; - - return acd->ifindex; -} - -int sd_ipv4acd_set_ifname(sd_ipv4acd *acd, const char *ifname) { - assert_return(acd, -EINVAL); - assert_return(ifname, -EINVAL); - - if (!ifname_valid_full(ifname, IFNAME_VALID_ALTERNATIVE)) - return -EINVAL; - - return free_and_strdup(&acd->ifname, ifname); -} - -int sd_ipv4acd_get_ifname(sd_ipv4acd *acd, const char **ret) { - int r; - - assert_return(acd, -EINVAL); - - r = get_ifname(acd->ifindex, &acd->ifname); - if (r < 0) - return r; - - if (ret) - *ret = acd->ifname; - - return 0; -} - -int sd_ipv4acd_set_mac(sd_ipv4acd *acd, const struct ether_addr *addr) { - int r; - - assert_return(acd, -EINVAL); - assert_return(addr, -EINVAL); - assert_return(!ether_addr_is_null(addr), -EINVAL); - - acd->mac_addr = *addr; - - if (!sd_ipv4acd_is_running(acd)) - return 0; - - assert(acd->fd >= 0); - r = arp_update_filter(acd->fd, &acd->address, &acd->mac_addr); - if (r < 0) { - ipv4acd_reset(acd); - return r; - } - - return 0; -} - -int sd_ipv4acd_detach_event(sd_ipv4acd *acd) { - assert_return(acd, -EINVAL); - - acd->event = sd_event_unref(acd->event); - - return 0; -} - -int sd_ipv4acd_attach_event(sd_ipv4acd *acd, sd_event *event, int64_t priority) { - int r; - - assert_return(acd, -EINVAL); - assert_return(!acd->event, -EBUSY); - - if (event) - acd->event = sd_event_ref(event); - else { - r = sd_event_default(&acd->event); - if (r < 0) - return r; - } - - acd->event_priority = priority; - - return 0; -} - -int sd_ipv4acd_set_callback(sd_ipv4acd *acd, sd_ipv4acd_callback_t cb, void *userdata) { - assert_return(acd, -EINVAL); - - acd->callback = cb; - acd->userdata = userdata; - - return 0; -} - -int sd_ipv4acd_set_check_mac_callback(sd_ipv4acd *acd, sd_ipv4acd_check_mac_callback_t cb, void *userdata) { - assert_return(acd, -EINVAL); - - acd->check_mac_callback = cb; - acd->check_mac_userdata = userdata; - return 0; -} - -int sd_ipv4acd_set_address(sd_ipv4acd *acd, const struct in_addr *address) { - int r; - - assert_return(acd, -EINVAL); - assert_return(address, -EINVAL); - assert_return(in4_addr_is_set(address), -EINVAL); - - if (in4_addr_equal(&acd->address, address)) - return 0; - - acd->address = *address; - - if (!sd_ipv4acd_is_running(acd)) - return 0; - - assert(acd->fd >= 0); - r = arp_update_filter(acd->fd, &acd->address, &acd->mac_addr); - if (r < 0) - goto fail; - - r = ipv4acd_set_next_wakeup(acd, 0, 0); - if (r < 0) - goto fail; - - ipv4acd_set_state(acd, IPV4ACD_STATE_STARTED, true); - return 0; - -fail: - ipv4acd_reset(acd); - return r; -} - -int sd_ipv4acd_get_address(sd_ipv4acd *acd, struct in_addr *address) { - assert_return(acd, -EINVAL); - assert_return(address, -EINVAL); - - *address = acd->address; - - return 0; -} - -int sd_ipv4acd_is_running(sd_ipv4acd *acd) { - assert_return(acd, false); - - return acd->state != IPV4ACD_STATE_INIT; -} - -int sd_ipv4acd_start(sd_ipv4acd *acd, bool reset_conflicts) { - int r; - - assert_return(acd, -EINVAL); - assert_return(acd->event, -EINVAL); - assert_return(acd->ifindex > 0, -EINVAL); - assert_return(in4_addr_is_set(&acd->address), -EINVAL); - assert_return(!ether_addr_is_null(&acd->mac_addr), -EINVAL); - assert_return(acd->state == IPV4ACD_STATE_INIT, -EBUSY); - - r = arp_network_bind_raw_socket(acd->ifindex, &acd->address, &acd->mac_addr); - if (r < 0) - return r; - - CLOSE_AND_REPLACE(acd->fd, r); - - if (reset_conflicts) - acd->n_conflict = 0; - - r = sd_event_add_io(acd->event, &acd->receive_message_event_source, acd->fd, EPOLLIN, ipv4acd_on_packet, acd); - if (r < 0) - goto fail; - - r = sd_event_source_set_priority(acd->receive_message_event_source, acd->event_priority); - if (r < 0) - goto fail; - - (void) sd_event_source_set_description(acd->receive_message_event_source, "ipv4acd-receive-message"); - - r = ipv4acd_set_next_wakeup(acd, 0, 0); - if (r < 0) - goto fail; - - ipv4acd_set_state(acd, IPV4ACD_STATE_STARTED, true); - return 0; - -fail: - ipv4acd_reset(acd); - return r; -} diff --git a/src/libnm-systemd-core/src/libsystemd-network/sd-ipv4ll.c b/src/libnm-systemd-core/src/libsystemd-network/sd-ipv4ll.c deleted file mode 100644 index 4a500dfc..00000000 --- a/src/libnm-systemd-core/src/libsystemd-network/sd-ipv4ll.c +++ /dev/null @@ -1,382 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/*** - Copyright © 2014 Axis Communications AB. All rights reserved. -***/ - -#include "nm-sd-adapt-core.h" - -#include -#include -#include -#include - -#include "sd-id128.h" -#include "sd-ipv4acd.h" -#include "sd-ipv4ll.h" - -#include "alloc-util.h" -#include "ether-addr-util.h" -#include "in-addr-util.h" -#include "network-common.h" -#include "random-util.h" -#include "siphash24.h" -#include "sparse-endian.h" -#include "string-util.h" -#include "util.h" - -#define IPV4LL_NETWORK UINT32_C(0xA9FE0000) -#define IPV4LL_NETMASK UINT32_C(0xFFFF0000) - -#define IPV4LL_DONT_DESTROY(ll) \ - _cleanup_(sd_ipv4ll_unrefp) _unused_ sd_ipv4ll *_dont_destroy_##ll = sd_ipv4ll_ref(ll) - -struct sd_ipv4ll { - unsigned n_ref; - - sd_ipv4acd *acd; - - be32_t address; /* the address pushed to ACD */ - struct ether_addr mac; - - struct { - le64_t value; - le64_t generation; - } seed; - bool seed_set; - - /* External */ - be32_t claimed_address; - - sd_ipv4ll_callback_t callback; - void *userdata; - - sd_ipv4ll_check_mac_callback_t check_mac_callback; - void *check_mac_userdata; -}; - -#define log_ipv4ll_errno(ll, error, fmt, ...) \ - log_interface_prefix_full_errno( \ - "IPv4LL: ", \ - sd_ipv4ll, ll, \ - error, fmt, ##__VA_ARGS__) -#define log_ipv4ll(ll, fmt, ...) \ - log_interface_prefix_full_errno_zerook( \ - "IPv4LL: ", \ - sd_ipv4ll, ll, \ - 0, fmt, ##__VA_ARGS__) - -static void ipv4ll_on_acd(sd_ipv4acd *acd, int event, void *userdata); -static int ipv4ll_check_mac(sd_ipv4acd *acd, const struct ether_addr *mac, void *userdata); - -static sd_ipv4ll *ipv4ll_free(sd_ipv4ll *ll) { - assert(ll); - - sd_ipv4acd_unref(ll->acd); - return mfree(ll); -} - -DEFINE_TRIVIAL_REF_UNREF_FUNC(sd_ipv4ll, sd_ipv4ll, ipv4ll_free); - -int sd_ipv4ll_new(sd_ipv4ll **ret) { - _cleanup_(sd_ipv4ll_unrefp) sd_ipv4ll *ll = NULL; - int r; - - assert_return(ret, -EINVAL); - - ll = new0(sd_ipv4ll, 1); - if (!ll) - return -ENOMEM; - - ll->n_ref = 1; - - r = sd_ipv4acd_new(&ll->acd); - if (r < 0) - return r; - - r = sd_ipv4acd_set_callback(ll->acd, ipv4ll_on_acd, ll); - if (r < 0) - return r; - - r = sd_ipv4acd_set_check_mac_callback(ll->acd, ipv4ll_check_mac, ll); - if (r < 0) - return r; - - *ret = TAKE_PTR(ll); - - return 0; -} - -int sd_ipv4ll_stop(sd_ipv4ll *ll) { - if (!ll) - return 0; - - return sd_ipv4acd_stop(ll->acd); -} - -int sd_ipv4ll_set_ifindex(sd_ipv4ll *ll, int ifindex) { - assert_return(ll, -EINVAL); - assert_return(ifindex > 0, -EINVAL); - assert_return(sd_ipv4ll_is_running(ll) == 0, -EBUSY); - - return sd_ipv4acd_set_ifindex(ll->acd, ifindex); -} - -int sd_ipv4ll_get_ifindex(sd_ipv4ll *ll) { - if (!ll) - return -EINVAL; - - return sd_ipv4acd_get_ifindex(ll->acd); -} - -int sd_ipv4ll_set_ifname(sd_ipv4ll *ll, const char *ifname) { - assert_return(ll, -EINVAL); - assert_return(ifname, -EINVAL); - - return sd_ipv4acd_set_ifname(ll->acd, ifname); -} - -int sd_ipv4ll_get_ifname(sd_ipv4ll *ll, const char **ret) { - assert_return(ll, -EINVAL); - - return sd_ipv4acd_get_ifname(ll->acd, ret); -} - -int sd_ipv4ll_set_mac(sd_ipv4ll *ll, const struct ether_addr *addr) { - int r; - - assert_return(ll, -EINVAL); - assert_return(addr, -EINVAL); - assert_return(!ether_addr_is_null(addr), -EINVAL); - - r = sd_ipv4acd_set_mac(ll->acd, addr); - if (r < 0) - return r; - - ll->mac = *addr; - return 0; -} - -int sd_ipv4ll_detach_event(sd_ipv4ll *ll) { - assert_return(ll, -EINVAL); - - return sd_ipv4acd_detach_event(ll->acd); -} - -int sd_ipv4ll_attach_event(sd_ipv4ll *ll, sd_event *event, int64_t priority) { - assert_return(ll, -EINVAL); - - return sd_ipv4acd_attach_event(ll->acd, event, priority); -} - -int sd_ipv4ll_set_callback(sd_ipv4ll *ll, sd_ipv4ll_callback_t cb, void *userdata) { - assert_return(ll, -EINVAL); - - ll->callback = cb; - ll->userdata = userdata; - - return 0; -} - -int sd_ipv4ll_set_check_mac_callback(sd_ipv4ll *ll, sd_ipv4ll_check_mac_callback_t cb, void *userdata) { - assert_return(ll, -EINVAL); - - ll->check_mac_callback = cb; - ll->check_mac_userdata = userdata; - - return 0; -} - -int sd_ipv4ll_get_address(sd_ipv4ll *ll, struct in_addr *address) { - assert_return(ll, -EINVAL); - assert_return(address, -EINVAL); - - if (ll->claimed_address == 0) - return -ENOENT; - - address->s_addr = ll->claimed_address; - - return 0; -} - -int sd_ipv4ll_set_address_seed(sd_ipv4ll *ll, uint64_t seed) { - assert_return(ll, -EINVAL); - assert_return(sd_ipv4ll_is_running(ll) == 0, -EBUSY); - - ll->seed.value = htole64(seed); - ll->seed_set = true; - - return 0; -} - -int sd_ipv4ll_is_running(sd_ipv4ll *ll) { - assert_return(ll, false); - - return sd_ipv4acd_is_running(ll->acd); -} - -static bool ipv4ll_address_is_valid(const struct in_addr *address) { - assert(address); - - if (!in4_addr_is_link_local(address)) - return false; - - return !IN_SET(be32toh(address->s_addr) & 0x0000FF00U, 0x0000U, 0xFF00U); -} - -int sd_ipv4ll_set_address(sd_ipv4ll *ll, const struct in_addr *address) { - int r; - - assert_return(ll, -EINVAL); - assert_return(address, -EINVAL); - assert_return(ipv4ll_address_is_valid(address), -EINVAL); - - r = sd_ipv4acd_set_address(ll->acd, address); - if (r < 0) - return r; - - ll->address = address->s_addr; - - return 0; -} - -#define PICK_HASH_KEY SD_ID128_MAKE(15,ac,82,a6,d6,3f,49,78,98,77,5d,0c,69,02,94,0b) - -static int ipv4ll_pick_address(sd_ipv4ll *ll) { - _cleanup_free_ char *address = NULL; - be32_t addr; - - assert(ll); - - do { - uint64_t h; - - h = siphash24(&ll->seed, sizeof(ll->seed), PICK_HASH_KEY.bytes); - - /* Increase the generation counter by one */ - ll->seed.generation = htole64(le64toh(ll->seed.generation) + 1); - - addr = htobe32((h & UINT32_C(0x0000FFFF)) | IPV4LL_NETWORK); - } while (addr == ll->address || - IN_SET(be32toh(addr) & 0x0000FF00U, 0x0000U, 0xFF00U)); - - (void) in_addr_to_string(AF_INET, &(union in_addr_union) { .in.s_addr = addr }, &address); - log_ipv4ll(ll, "Picked new IP address %s.", strna(address)); - - return sd_ipv4ll_set_address(ll, &(struct in_addr) { addr }); -} - -#define MAC_HASH_KEY SD_ID128_MAKE(df,04,22,98,3f,ad,14,52,f9,87,2e,d1,9c,70,e2,f2) - -static int ipv4ll_start_internal(sd_ipv4ll *ll, bool reset_generation) { - int r; - bool picked_address = false; - - assert_return(ll, -EINVAL); - assert_return(!ether_addr_is_null(&ll->mac), -EINVAL); - - /* If no random seed is set, generate some from the MAC address */ - if (!ll->seed_set) - ll->seed.value = htole64(siphash24(ll->mac.ether_addr_octet, ETH_ALEN, MAC_HASH_KEY.bytes)); - - if (reset_generation) - ll->seed.generation = 0; - - if (ll->address == 0) { - r = ipv4ll_pick_address(ll); - if (r < 0) - return r; - - picked_address = true; - } - - r = sd_ipv4acd_start(ll->acd, reset_generation); - if (r < 0) { - - /* We couldn't start? If so, let's forget the picked address again, the user might make a change and - * retry, and we want the new data to take effect when picking an address. */ - if (picked_address) - ll->address = 0; - - return r; - } - - return 1; -} - -int sd_ipv4ll_start(sd_ipv4ll *ll) { - assert_return(ll, -EINVAL); - - if (sd_ipv4ll_is_running(ll)) - return 0; - - return ipv4ll_start_internal(ll, true); -} - -int sd_ipv4ll_restart(sd_ipv4ll *ll) { - ll->address = 0; - - return ipv4ll_start_internal(ll, false); -} - -static void ipv4ll_client_notify(sd_ipv4ll *ll, int event) { - assert(ll); - - if (ll->callback) - ll->callback(ll, event, ll->userdata); -} - -void ipv4ll_on_acd(sd_ipv4acd *acd, int event, void *userdata) { - sd_ipv4ll *ll = userdata; - IPV4LL_DONT_DESTROY(ll); - int r; - - assert(acd); - assert(ll); - - switch (event) { - - case SD_IPV4ACD_EVENT_STOP: - ipv4ll_client_notify(ll, SD_IPV4LL_EVENT_STOP); - ll->claimed_address = 0; - break; - - case SD_IPV4ACD_EVENT_BIND: - ll->claimed_address = ll->address; - ipv4ll_client_notify(ll, SD_IPV4LL_EVENT_BIND); - break; - - case SD_IPV4ACD_EVENT_CONFLICT: - /* if an address was already bound we must call up to the - user to handle this, otherwise we just try again */ - if (ll->claimed_address != 0) { - ipv4ll_client_notify(ll, SD_IPV4LL_EVENT_CONFLICT); - - ll->claimed_address = 0; - } else { - r = sd_ipv4ll_restart(ll); - if (r < 0) - goto error; - } - - break; - - default: - assert_not_reached(); - } - - return; - -error: - ipv4ll_client_notify(ll, SD_IPV4LL_EVENT_STOP); -} - -static int ipv4ll_check_mac(sd_ipv4acd *acd, const struct ether_addr *mac, void *userdata) { - sd_ipv4ll *ll = userdata; - - assert(ll); - - if (ll->check_mac_callback) - return ll->check_mac_callback(ll, mac, ll->check_mac_userdata); - - return 0; -} diff --git a/src/libnm-systemd-core/src/libsystemd-network/sd-lldp-rx.c b/src/libnm-systemd-core/src/libsystemd-network/sd-lldp-rx.c index 9da2b149..f50e9c8d 100644 --- a/src/libnm-systemd-core/src/libsystemd-network/sd-lldp-rx.c +++ b/src/libnm-systemd-core/src/libsystemd-network/sd-lldp-rx.c @@ -202,6 +202,9 @@ static int lldp_rx_receive_datagram(sd_event_source *s, int fd, uint32_t revents space = next_datagram_size_fd(fd); if (space < 0) { + if (ERRNO_IS_TRANSIENT(space) || ERRNO_IS_DISCONNECT(space)) + return 0; + log_lldp_rx_errno(lldp_rx, space, "Failed to determine datagram size to read, ignoring: %m"); return 0; } @@ -214,7 +217,7 @@ static int lldp_rx_receive_datagram(sd_event_source *s, int fd, uint32_t revents length = recv(fd, LLDP_NEIGHBOR_RAW(n), n->raw_size, MSG_DONTWAIT); if (length < 0) { - if (IN_SET(errno, EAGAIN, EINTR)) + if (ERRNO_IS_TRANSIENT(errno) || ERRNO_IS_DISCONNECT(errno)) return 0; log_lldp_rx_errno(lldp_rx, errno, "Failed to read LLDP datagram, ignoring: %m"); @@ -251,7 +254,7 @@ int sd_lldp_rx_is_running(sd_lldp_rx *lldp_rx) { return lldp_rx->fd >= 0; } -_public_ int sd_lldp_rx_start(sd_lldp_rx *lldp_rx) { +int sd_lldp_rx_start(sd_lldp_rx *lldp_rx) { int r; assert_return(lldp_rx, -EINVAL); @@ -285,7 +288,7 @@ fail: return r; } -_public_ int sd_lldp_rx_stop(sd_lldp_rx *lldp_rx) { +int sd_lldp_rx_stop(sd_lldp_rx *lldp_rx) { if (!sd_lldp_rx_is_running(lldp_rx)) return 0; @@ -297,7 +300,7 @@ _public_ int sd_lldp_rx_stop(sd_lldp_rx *lldp_rx) { return 1; } -_public_ int sd_lldp_rx_attach_event(sd_lldp_rx *lldp_rx, sd_event *event, int64_t priority) { +int sd_lldp_rx_attach_event(sd_lldp_rx *lldp_rx, sd_event *event, int64_t priority) { int r; assert_return(lldp_rx, -EINVAL); @@ -317,7 +320,7 @@ _public_ int sd_lldp_rx_attach_event(sd_lldp_rx *lldp_rx, sd_event *event, int64 return 0; } -_public_ int sd_lldp_rx_detach_event(sd_lldp_rx *lldp_rx) { +int sd_lldp_rx_detach_event(sd_lldp_rx *lldp_rx) { assert_return(lldp_rx, -EINVAL); assert_return(!sd_lldp_rx_is_running(lldp_rx), -EBUSY); @@ -327,13 +330,13 @@ _public_ int sd_lldp_rx_detach_event(sd_lldp_rx *lldp_rx) { return 0; } -_public_ sd_event* sd_lldp_rx_get_event(sd_lldp_rx *lldp_rx) { +sd_event* sd_lldp_rx_get_event(sd_lldp_rx *lldp_rx) { assert_return(lldp_rx, NULL); return lldp_rx->event; } -_public_ int sd_lldp_rx_set_callback(sd_lldp_rx *lldp_rx, sd_lldp_rx_callback_t cb, void *userdata) { +int sd_lldp_rx_set_callback(sd_lldp_rx *lldp_rx, sd_lldp_rx_callback_t cb, void *userdata) { assert_return(lldp_rx, -EINVAL); lldp_rx->callback = cb; @@ -342,7 +345,7 @@ _public_ int sd_lldp_rx_set_callback(sd_lldp_rx *lldp_rx, sd_lldp_rx_callback_t return 0; } -_public_ int sd_lldp_rx_set_ifindex(sd_lldp_rx *lldp_rx, int ifindex) { +int sd_lldp_rx_set_ifindex(sd_lldp_rx *lldp_rx, int ifindex) { assert_return(lldp_rx, -EINVAL); assert_return(ifindex > 0, -EINVAL); assert_return(!sd_lldp_rx_is_running(lldp_rx), -EBUSY); @@ -394,7 +397,7 @@ static sd_lldp_rx *lldp_rx_free(sd_lldp_rx *lldp_rx) { DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_lldp_rx, sd_lldp_rx, lldp_rx_free); -_public_ int sd_lldp_rx_new(sd_lldp_rx **ret) { +int sd_lldp_rx_new(sd_lldp_rx **ret) { _cleanup_(sd_lldp_rx_unrefp) sd_lldp_rx *lldp_rx = NULL; assert_return(ret, -EINVAL); @@ -462,7 +465,7 @@ static inline int neighbor_compare_func(sd_lldp_neighbor * const *a, sd_lldp_nei return lldp_neighbor_id_compare_func(&(*a)->id, &(*b)->id); } -_public_ int sd_lldp_rx_get_neighbors(sd_lldp_rx *lldp_rx, sd_lldp_neighbor ***ret) { +int sd_lldp_rx_get_neighbors(sd_lldp_rx *lldp_rx, sd_lldp_neighbor ***ret) { _cleanup_free_ sd_lldp_neighbor **l = NULL; sd_lldp_neighbor *n; int k = 0; @@ -491,7 +494,7 @@ _public_ int sd_lldp_rx_get_neighbors(sd_lldp_rx *lldp_rx, sd_lldp_neighbor ***r return k; } -_public_ int sd_lldp_rx_set_neighbors_max(sd_lldp_rx *lldp_rx, uint64_t m) { +int sd_lldp_rx_set_neighbors_max(sd_lldp_rx *lldp_rx, uint64_t m) { assert_return(lldp_rx, -EINVAL); assert_return(m > 0, -EINVAL); @@ -501,7 +504,7 @@ _public_ int sd_lldp_rx_set_neighbors_max(sd_lldp_rx *lldp_rx, uint64_t m) { return 0; } -_public_ int sd_lldp_rx_match_capabilities(sd_lldp_rx *lldp_rx, uint16_t mask) { +int sd_lldp_rx_match_capabilities(sd_lldp_rx *lldp_rx, uint16_t mask) { assert_return(lldp_rx, -EINVAL); assert_return(mask != 0, -EINVAL); @@ -510,7 +513,7 @@ _public_ int sd_lldp_rx_match_capabilities(sd_lldp_rx *lldp_rx, uint16_t mask) { return 0; } -_public_ int sd_lldp_rx_set_filter_address(sd_lldp_rx *lldp_rx, const struct ether_addr *addr) { +int sd_lldp_rx_set_filter_address(sd_lldp_rx *lldp_rx, const struct ether_addr *addr) { assert_return(lldp_rx, -EINVAL); /* In order to deal nicely with bridges that send back our own packets, allow one address to be filtered, so diff --git a/src/libnm-systemd-core/src/libsystemd/sd-event/event-source.h b/src/libnm-systemd-core/src/libsystemd/sd-event/event-source.h index 08b409fe..74cbc269 100644 --- a/src/libnm-systemd-core/src/libsystemd/sd-event/event-source.h +++ b/src/libnm-systemd-core/src/libsystemd/sd-event/event-source.h @@ -71,6 +71,7 @@ struct sd_event_source { uint64_t prepare_iteration; sd_event_destroy_t destroy_callback; + sd_event_handler_t ratelimit_expire_callback; LIST_FIELDS(sd_event_source, sources); @@ -214,6 +215,11 @@ struct inotify_data { * the events locally if they can't be coalesced). */ unsigned n_pending; + /* If this counter is non-zero, don't GC the inotify data object even if not used to watch any inode + * anymore. This is useful to pin the object for a bit longer, after the last event source needing it + * is gone. */ + unsigned n_busy; + /* A linked list of all inotify objects with data already read, that still need processing. We keep this list * to make it efficient to figure out what inotify objects to process data on next. */ LIST_FIELDS(struct inotify_data, buffered); diff --git a/src/libnm-systemd-core/src/libsystemd/sd-event/event-util.c b/src/libnm-systemd-core/src/libsystemd/sd-event/event-util.c index 7cc55be1..13e16f9b 100644 --- a/src/libnm-systemd-core/src/libsystemd/sd-event/event-util.c +++ b/src/libnm-systemd-core/src/libsystemd/sd-event/event-util.c @@ -86,6 +86,30 @@ int event_reset_time( return created; } +int event_reset_time_relative( + sd_event *e, + sd_event_source **s, + clockid_t clock, + uint64_t usec, + uint64_t accuracy, + sd_event_time_handler_t callback, + void *userdata, + int64_t priority, + const char *description, + bool force_reset) { + + usec_t usec_now; + int r; + + assert(e); + + r = sd_event_now(e, clock, &usec_now); + if (r < 0) + return log_debug_errno(r, "sd-event: Failed to get the current time: %m"); + + return event_reset_time(e, s, clock, usec_add(usec_now, usec), accuracy, callback, userdata, priority, description, force_reset); +} + int event_source_disable(sd_event_source *s) { if (!s) return 0; diff --git a/src/libnm-systemd-core/src/libsystemd/sd-event/event-util.h b/src/libnm-systemd-core/src/libsystemd/sd-event/event-util.h index c8f97bc8..64a41992 100644 --- a/src/libnm-systemd-core/src/libsystemd/sd-event/event-util.h +++ b/src/libnm-systemd-core/src/libsystemd/sd-event/event-util.h @@ -5,9 +5,27 @@ #include "sd-event.h" -int event_reset_time(sd_event *e, sd_event_source **s, - clockid_t clock, uint64_t usec, uint64_t accuracy, - sd_event_time_handler_t callback, void *userdata, - int64_t priority, const char *description, bool force_reset); +int event_reset_time( + sd_event *e, + sd_event_source **s, + clockid_t clock, + uint64_t usec, + uint64_t accuracy, + sd_event_time_handler_t callback, + void *userdata, + int64_t priority, + const char *description, + bool force_reset); +int event_reset_time_relative( + sd_event *e, + sd_event_source **s, + clockid_t clock, + uint64_t usec, + uint64_t accuracy, + sd_event_time_handler_t callback, + void *userdata, + int64_t priority, + const char *description, + bool force_reset); int event_source_disable(sd_event_source *s); int event_source_is_enabled(sd_event_source *s); diff --git a/src/libnm-systemd-core/src/libsystemd/sd-event/sd-event.c b/src/libnm-systemd-core/src/libsystemd/sd-event/sd-event.c index 0acbdd54..e87d900c 100644 --- a/src/libnm-systemd-core/src/libsystemd/sd-event/sd-event.c +++ b/src/libnm-systemd-core/src/libsystemd/sd-event/sd-event.c @@ -1824,6 +1824,29 @@ static void event_free_inode_data( free(d); } +static void event_gc_inotify_data( + sd_event *e, + struct inotify_data *d) { + + assert(e); + + /* GCs the inotify data object if we don't need it anymore. That's the case if we don't want to watch + * any inode with it anymore, which in turn happens if no event source of this priority is interested + * in any inode any longer. That said, we maintain an extra busy counter: if non-zero we'll delay GC + * (under the expectation that the GC is called again once the counter is decremented). */ + + if (!d) + return; + + if (!hashmap_isempty(d->inodes)) + return; + + if (d->n_busy > 0) + return; + + event_free_inotify_data(e, d); +} + static void event_gc_inode_data( sd_event *e, struct inode_data *d) { @@ -1841,8 +1864,7 @@ static void event_gc_inode_data( inotify_data = d->inotify_data; event_free_inode_data(e, d); - if (inotify_data && hashmap_isempty(inotify_data->inodes)) - event_free_inotify_data(e, inotify_data); + event_gc_inotify_data(e, inotify_data); } static int event_make_inode_data( @@ -1971,24 +1993,25 @@ static int inotify_exit_callback(sd_event_source *s, const struct inotify_event return sd_event_exit(sd_event_source_get_event(s), PTR_TO_INT(userdata)); } -_public_ int sd_event_add_inotify( +static int event_add_inotify_fd_internal( sd_event *e, sd_event_source **ret, - const char *path, + int fd, + bool donate, uint32_t mask, sd_event_inotify_handler_t callback, void *userdata) { + _cleanup_close_ int donated_fd = donate ? fd : -1; + _cleanup_(source_freep) sd_event_source *s = NULL; struct inotify_data *inotify_data = NULL; struct inode_data *inode_data = NULL; - _cleanup_close_ int fd = -1; - _cleanup_(source_freep) sd_event_source *s = NULL; struct stat st; int r; assert_return(e, -EINVAL); assert_return(e = event_resolve(e), -ENOPKG); - assert_return(path, -EINVAL); + assert_return(fd >= 0, -EBADF); assert_return(e->state != SD_EVENT_FINISHED, -ESTALE); assert_return(!event_pid_changed(e), -ECHILD); @@ -2001,12 +2024,6 @@ _public_ int sd_event_add_inotify( if (mask & IN_MASK_ADD) return -EINVAL; - fd = open(path, O_PATH|O_CLOEXEC| - (mask & IN_ONLYDIR ? O_DIRECTORY : 0)| - (mask & IN_DONT_FOLLOW ? O_NOFOLLOW : 0)); - if (fd < 0) - return -errno; - if (fstat(fd, &st) < 0) return -errno; @@ -2026,14 +2043,24 @@ _public_ int sd_event_add_inotify( r = event_make_inode_data(e, inotify_data, st.st_dev, st.st_ino, &inode_data); if (r < 0) { - event_free_inotify_data(e, inotify_data); + event_gc_inotify_data(e, inotify_data); return r; } /* Keep the O_PATH fd around until the first iteration of the loop, so that we can still change the priority of * the event source, until then, for which we need the original inode. */ if (inode_data->fd < 0) { - inode_data->fd = TAKE_FD(fd); + if (donated_fd >= 0) + inode_data->fd = TAKE_FD(donated_fd); + else { + inode_data->fd = fcntl(fd, F_DUPFD_CLOEXEC, 3); + if (inode_data->fd < 0) { + r = -errno; + event_gc_inode_data(e, inode_data); + return r; + } + } + LIST_PREPEND(to_close, e->inode_data_to_close, inode_data); } @@ -2046,8 +2073,6 @@ _public_ int sd_event_add_inotify( if (r < 0) return r; - (void) sd_event_source_set_description(s, path); - if (ret) *ret = s; TAKE_PTR(s); @@ -2055,6 +2080,48 @@ _public_ int sd_event_add_inotify( return 0; } +_public_ int sd_event_add_inotify_fd( + sd_event *e, + sd_event_source **ret, + int fd, + uint32_t mask, + sd_event_inotify_handler_t callback, + void *userdata) { + + return event_add_inotify_fd_internal(e, ret, fd, /* donate= */ false, mask, callback, userdata); +} + +_public_ int sd_event_add_inotify( + sd_event *e, + sd_event_source **ret, + const char *path, + uint32_t mask, + sd_event_inotify_handler_t callback, + void *userdata) { + + sd_event_source *s = NULL; /* avoid false maybe-uninitialized warning */ + int fd, r; + + assert_return(path, -EINVAL); + + fd = open(path, O_PATH|O_CLOEXEC| + (mask & IN_ONLYDIR ? O_DIRECTORY : 0)| + (mask & IN_DONT_FOLLOW ? O_NOFOLLOW : 0)); + if (fd < 0) + return -errno; + + r = event_add_inotify_fd_internal(e, &s, fd, /* donate= */ true, mask, callback, userdata); + if (r < 0) + return r; + + (void) sd_event_source_set_description(s, path); + + if (ret) + *ret = s; + + return r; +} + static sd_event_source* event_source_free(sd_event_source *s) { if (!s) return NULL; @@ -2845,7 +2912,7 @@ fail: return r; } -static int event_source_leave_ratelimit(sd_event_source *s) { +static int event_source_leave_ratelimit(sd_event_source *s, bool run_callback) { int r; assert(s); @@ -2877,6 +2944,30 @@ static int event_source_leave_ratelimit(sd_event_source *s) { ratelimit_reset(&s->rate_limit); log_debug("Event source %p (%s) left rate limit state.", s, strna(s->description)); + + if (run_callback && s->ratelimit_expire_callback) { + s->dispatching = true; + r = s->ratelimit_expire_callback(s, s->userdata); + s->dispatching = false; + + if (r < 0) { + log_debug_errno(r, "Ratelimit expiry callback of event source %s (type %s) returned error, %s: %m", + strna(s->description), + event_source_type_to_string(s->type), + s->exit_on_failure ? "exiting" : "disabling"); + + if (s->exit_on_failure) + (void) sd_event_exit(s->event, r); + } + + if (s->n_ref == 0) + source_free(s); + else if (r < 0) + assert_se(sd_event_source_set_enabled(s, SD_EVENT_OFF) >= 0); + + return 1; + } + return 0; fail: @@ -3055,7 +3146,7 @@ static int flush_timer(sd_event *e, int fd, uint32_t events, usec_t *next) { ss = read(fd, &x, sizeof(x)); if (ss < 0) { - if (IN_SET(errno, EAGAIN, EINTR)) + if (ERRNO_IS_TRANSIENT(errno)) return 0; return -errno; @@ -3076,6 +3167,7 @@ static int process_timer( struct clock_data *d) { sd_event_source *s; + bool callback_invoked = false; int r; assert(e); @@ -3093,9 +3185,11 @@ static int process_timer( * again. */ assert(s->ratelimited); - r = event_source_leave_ratelimit(s); + r = event_source_leave_ratelimit(s, /* run_callback */ true); if (r < 0) return r; + else if (r == 1) + callback_invoked = true; continue; } @@ -3110,7 +3204,7 @@ static int process_timer( event_source_time_prioq_reshuffle(s); } - return 0; + return callback_invoked; } static int process_child(sd_event *e, int64_t threshold, int64_t *ret_min_priority) { @@ -3258,7 +3352,7 @@ static int process_signal(sd_event *e, struct signal_data *d, uint32_t events, i n = read(d->fd, &si, sizeof(si)); if (n < 0) { - if (IN_SET(errno, EAGAIN, EINTR)) + if (ERRNO_IS_TRANSIENT(errno)) return 0; return -errno; @@ -3312,7 +3406,7 @@ static int event_inotify_data_read(sd_event *e, struct inotify_data *d, uint32_t n = read(d->fd, &d->buffer, sizeof(d->buffer)); if (n < 0) { - if (IN_SET(errno, EAGAIN, EINTR)) + if (ERRNO_IS_TRANSIENT(errno)) return 0; return -errno; @@ -3560,13 +3654,23 @@ static int source_dispatch(sd_event_source *s) { sz = offsetof(struct inotify_event, name) + d->buffer.ev.len; assert(d->buffer_filled >= sz); + /* If the inotify callback destroys the event source then this likely means we don't need to + * watch the inode anymore, and thus also won't need the inotify object anymore. But if we'd + * free it immediately, then we couldn't drop the event from the inotify event queue without + * memory corruption anymore, as below. Hence, let's not free it immediately, but mark it + * "busy" with a counter (which will ensure it's not GC'ed away prematurely). Let's then + * explicitly GC it after we are done dropping the inotify event from the buffer. */ + d->n_busy++; r = s->inotify.callback(s, &d->buffer.ev, s->userdata); + d->n_busy--; - /* When no event is pending anymore on this inotify object, then let's drop the event from the - * buffer. */ + /* When no event is pending anymore on this inotify object, then let's drop the event from + * the inotify event queue buffer. */ if (d->n_pending == 0) event_inotify_data_drop(e, d, sz); + /* Now we don't want to access 'd' anymore, it's OK to GC now. */ + event_gc_inotify_data(e, d); break; } @@ -3591,7 +3695,7 @@ static int source_dispatch(sd_event_source *s) { if (s->n_ref == 0) source_free(s); else if (r < 0) - sd_event_source_set_enabled(s, SD_EVENT_OFF); + assert_se(sd_event_source_set_enabled(s, SD_EVENT_OFF) >= 0); return 1; } @@ -3632,7 +3736,7 @@ static int event_prepare(sd_event *e) { if (s->n_ref == 0) source_free(s); else if (r < 0) - sd_event_source_set_enabled(s, SD_EVENT_OFF); + assert_se(sd_event_source_set_enabled(s, SD_EVENT_OFF) >= 0); } return 0; @@ -3693,10 +3797,7 @@ static int arm_watchdog(sd_event *e) { if (its.it_value.tv_sec == 0 && its.it_value.tv_nsec == 0) its.it_value.tv_nsec = 1; - if (timerfd_settime(e->watchdog_fd, TFD_TIMER_ABSTIME, &its, NULL) < 0) - return -errno; - - return 0; + return RET_NERRNO(timerfd_settime(e->watchdog_fd, TFD_TIMER_ABSTIME, &its, NULL)); } static int process_watchdog(sd_event *e) { @@ -3806,7 +3907,7 @@ static int epoll_wait_usec( int maxevents, usec_t timeout) { - int r, msec; + int msec; #if 0 static bool epoll_pwait2_absent = false; @@ -3846,14 +3947,7 @@ static int epoll_wait_usec( msec = (int) k; } - r = epoll_wait(fd, - events, - maxevents, - msec); - if (r < 0) - return -errno; - - return r; + return RET_NERRNO(epoll_wait(fd, events, maxevents, msec)); } static int process_epoll(sd_event *e, usec_t timeout, int64_t threshold, int64_t *ret_min_priority) { @@ -4024,15 +4118,15 @@ _public_ int sd_event_wait(sd_event *e, uint64_t timeout) { if (r < 0) goto finish; - r = process_timer(e, e->timestamp.realtime, &e->realtime); + r = process_inotify(e); if (r < 0) goto finish; - r = process_timer(e, e->timestamp.boottime, &e->boottime); + r = process_timer(e, e->timestamp.realtime, &e->realtime); if (r < 0) goto finish; - r = process_timer(e, e->timestamp.monotonic, &e->monotonic); + r = process_timer(e, e->timestamp.boottime, &e->boottime); if (r < 0) goto finish; @@ -4044,9 +4138,20 @@ _public_ int sd_event_wait(sd_event *e, uint64_t timeout) { if (r < 0) goto finish; - r = process_inotify(e); + r = process_timer(e, e->timestamp.monotonic, &e->monotonic); if (r < 0) goto finish; + else if (r == 1) { + /* Ratelimit expiry callback was called. Let's postpone processing pending sources and + * put loop in the initial state in order to evaluate (in the next iteration) also sources + * there were potentially re-enabled by the callback. + * + * Wondering why we treat only this invocation of process_timer() differently? Once event + * source is ratelimited we essentially transform it into CLOCK_MONOTONIC timer hence + * ratelimit expiry callback is never called for any other timer type. */ + r = 0; + goto finish; + } if (event_next_pending(e)) { e->state = SD_EVENT_PENDING; @@ -4117,7 +4222,7 @@ _public_ int sd_event_run(sd_event *e, uint64_t timeout) { this_run = now(CLOCK_MONOTONIC); - l = u64log2(this_run - e->last_run_usec); + l = log2u64(this_run - e->last_run_usec); assert(l < ELEMENTSOF(e->delays)); e->delays[l]++; @@ -4416,7 +4521,7 @@ _public_ int sd_event_source_set_ratelimit(sd_event_source *s, uint64_t interval /* When ratelimiting is configured we'll always reset the rate limit state first and start fresh, * non-ratelimited. */ - r = event_source_leave_ratelimit(s); + r = event_source_leave_ratelimit(s, /* run_callback */ false); if (r < 0) return r; @@ -4424,6 +4529,13 @@ _public_ int sd_event_source_set_ratelimit(sd_event_source *s, uint64_t interval return 0; } +_public_ int sd_event_source_set_ratelimit_expire_callback(sd_event_source *s, sd_event_handler_t callback) { + assert_return(s, -EINVAL); + + s->ratelimit_expire_callback = callback; + return 0; +} + _public_ int sd_event_source_get_ratelimit(sd_event_source *s, uint64_t *ret_interval, unsigned *ret_burst) { assert_return(s, -EINVAL); diff --git a/src/libnm-systemd-core/src/libsystemd/sd-id128/id128-util.c b/src/libnm-systemd-core/src/libsystemd/sd-id128/id128-util.c index d80145a8..9ec2abc8 100644 --- a/src/libnm-systemd-core/src/libsystemd/sd-id128/id128-util.c +++ b/src/libnm-systemd-core/src/libsystemd/sd-id128/id128-util.c @@ -224,7 +224,7 @@ int id128_get_product(sd_id128_t *ret) { r = id128_read("/sys/class/dmi/id/product_uuid", ID128_UUID, &uuid); if (r == -ENOENT) - r = id128_read("/sys/firmware/devicetree/base/vm,uuid", ID128_UUID, &uuid); + r = id128_read("/proc/device-tree/vm,uuid", ID128_UUID, &uuid); if (r < 0) return r; diff --git a/src/libnm-systemd-core/src/libsystemd/sd-id128/sd-id128.c b/src/libnm-systemd-core/src/libsystemd/sd-id128/sd-id128.c index 0860f493..c3ed3bbb 100644 --- a/src/libnm-systemd-core/src/libsystemd/sd-id128/sd-id128.c +++ b/src/libnm-systemd-core/src/libsystemd/sd-id128/sd-id128.c @@ -6,21 +6,14 @@ #include #include -#if HAVE_OPENSSL -#include -#include -#endif - #include "sd-id128.h" #include "alloc-util.h" #include "fd-util.h" #include "hexdecoct.h" +#include "hmac.h" #include "id128-util.h" #include "io-util.h" -#if !HAVE_OPENSSL -#include "khash.h" -#endif #include "macro.h" #include "missing_syscall.h" #include "random-util.h" @@ -283,43 +276,15 @@ _public_ int sd_id128_randomize(sd_id128_t *ret) { } static int get_app_specific(sd_id128_t base, sd_id128_t app_id, sd_id128_t *ret) { + uint8_t hmac[SHA256_DIGEST_SIZE]; sd_id128_t result; assert(ret); -#if HAVE_OPENSSL - /* We prefer doing this in-process, since we this means we are not dependent on kernel configuration, - * and this also works in locked down container environments. But some distros don't like OpenSSL's - * license and its (in-) compatibility with GPL2, hence also support khash */ - uint8_t md[256/8]; - if (!HMAC(EVP_sha256(), - &base, sizeof(base), - (const unsigned char*) &app_id, sizeof(app_id), - md, NULL)) - return -ENOTRECOVERABLE; + hmac_sha256(&base, sizeof(base), &app_id, sizeof(app_id), hmac); /* Take only the first half. */ - memcpy(&result, md, MIN(sizeof(md), sizeof(result))); -#else - _cleanup_(khash_unrefp) khash *h = NULL; - const void *p; - int r; - - r = khash_new_with_key(&h, "hmac(sha256)", &base, sizeof(base)); - if (r < 0) - return r; - - r = khash_put(h, &app_id, sizeof(app_id)); - if (r < 0) - return r; - - r = khash_digest_data(h, &p); - if (r < 0) - return r; - - /* We chop off the trailing 16 bytes */ - memcpy(&result, p, MIN(khash_get_size(h), sizeof(result))); -#endif + memcpy(&result, hmac, MIN(sizeof(hmac), sizeof(result))); *ret = id128_make_v4_uuid(result); return 0; diff --git a/src/libnm-systemd-core/src/systemd/sd-dhcp-client.h b/src/libnm-systemd-core/src/systemd/sd-dhcp-client.h index 23979b12..4af4b45f 100644 --- a/src/libnm-systemd-core/src/systemd/sd-dhcp-client.h +++ b/src/libnm-systemd-core/src/systemd/sd-dhcp-client.h @@ -45,65 +45,66 @@ enum { }; enum { - SD_DHCP_OPTION_PAD = 0, - SD_DHCP_OPTION_SUBNET_MASK = 1, - SD_DHCP_OPTION_TIME_OFFSET = 2, - SD_DHCP_OPTION_ROUTER = 3, - SD_DHCP_OPTION_DOMAIN_NAME_SERVER = 6, - SD_DHCP_OPTION_LPR_SERVER = 9, - SD_DHCP_OPTION_HOST_NAME = 12, - SD_DHCP_OPTION_BOOT_FILE_SIZE = 13, - SD_DHCP_OPTION_DOMAIN_NAME = 15, - SD_DHCP_OPTION_ROOT_PATH = 17, - SD_DHCP_OPTION_ENABLE_IP_FORWARDING = 19, - SD_DHCP_OPTION_ENABLE_IP_FORWARDING_NL = 20, - SD_DHCP_OPTION_POLICY_FILTER = 21, - SD_DHCP_OPTION_INTERFACE_MDR = 22, - SD_DHCP_OPTION_INTERFACE_TTL = 23, - SD_DHCP_OPTION_INTERFACE_MTU_AGING_TIMEOUT = 24, - SD_DHCP_OPTION_INTERFACE_MTU = 26, - SD_DHCP_OPTION_BROADCAST = 28, - /* Windows 10 option to send when Anonymize=true */ - SD_DHCP_OPTION_ROUTER_DISCOVER = 31, - SD_DHCP_OPTION_STATIC_ROUTE = 33, - SD_DHCP_OPTION_NTP_SERVER = 42, - SD_DHCP_OPTION_VENDOR_SPECIFIC = 43, - /* Windows 10 option to send when Anonymize=true */ - SD_DHCP_OPTION_NETBIOS_NAMESERVER = 44, - /* Windows 10 option to send when Anonymize=true */ - SD_DHCP_OPTION_NETBIOS_NODETYPE = 46, - /* Windows 10 option to send when Anonymize=true */ - SD_DHCP_OPTION_NETBIOS_SCOPE = 47, - SD_DHCP_OPTION_REQUESTED_IP_ADDRESS = 50, - SD_DHCP_OPTION_IP_ADDRESS_LEASE_TIME = 51, - SD_DHCP_OPTION_OVERLOAD = 52, - SD_DHCP_OPTION_MESSAGE_TYPE = 53, - SD_DHCP_OPTION_SERVER_IDENTIFIER = 54, - SD_DHCP_OPTION_PARAMETER_REQUEST_LIST = 55, - SD_DHCP_OPTION_ERROR_MESSAGE = 56, - SD_DHCP_OPTION_MAXIMUM_MESSAGE_SIZE = 57, - SD_DHCP_OPTION_RENEWAL_T1_TIME = 58, - SD_DHCP_OPTION_REBINDING_T2_TIME = 59, - SD_DHCP_OPTION_VENDOR_CLASS_IDENTIFIER = 60, - SD_DHCP_OPTION_CLIENT_IDENTIFIER = 61, - SD_DHCP_OPTION_SMTP_SERVER = 69, - SD_DHCP_OPTION_POP3_SERVER = 70, - SD_DHCP_OPTION_USER_CLASS = 77, - SD_DHCP_OPTION_FQDN = 81, - SD_DHCP_OPTION_RELAY_AGENT_INFORMATION = 82, - SD_DHCP_OPTION_NEW_POSIX_TIMEZONE = 100, - SD_DHCP_OPTION_NEW_TZDB_TIMEZONE = 101, - SD_DHCP_OPTION_DOMAIN_SEARCH_LIST = 119, - SD_DHCP_OPTION_SIP_SERVER = 120, - SD_DHCP_OPTION_CLASSLESS_STATIC_ROUTE = 121, - SD_DHCP_OPTION_MUD_URL = 161, - SD_DHCP_OPTION_PRIVATE_BASE = 224, - /* Windows 10 option to send when Anonymize=true */ + SD_DHCP_OPTION_PAD = 0, + SD_DHCP_OPTION_SUBNET_MASK = 1, + SD_DHCP_OPTION_TIME_OFFSET = 2, + SD_DHCP_OPTION_ROUTER = 3, + SD_DHCP_OPTION_DOMAIN_NAME_SERVER = 6, + SD_DHCP_OPTION_LPR_SERVER = 9, + SD_DHCP_OPTION_HOST_NAME = 12, + SD_DHCP_OPTION_BOOT_FILE_SIZE = 13, + SD_DHCP_OPTION_DOMAIN_NAME = 15, + SD_DHCP_OPTION_ROOT_PATH = 17, + SD_DHCP_OPTION_ENABLE_IP_FORWARDING = 19, + SD_DHCP_OPTION_ENABLE_IP_FORWARDING_NL = 20, + SD_DHCP_OPTION_POLICY_FILTER = 21, + SD_DHCP_OPTION_INTERFACE_MDR = 22, + SD_DHCP_OPTION_INTERFACE_TTL = 23, + SD_DHCP_OPTION_INTERFACE_MTU_AGING_TIMEOUT = 24, + SD_DHCP_OPTION_INTERFACE_MTU = 26, + SD_DHCP_OPTION_BROADCAST = 28, + /* Windows 10 option to send when Anonymize=true */ + SD_DHCP_OPTION_ROUTER_DISCOVER = 31, + SD_DHCP_OPTION_STATIC_ROUTE = 33, + SD_DHCP_OPTION_NTP_SERVER = 42, + SD_DHCP_OPTION_VENDOR_SPECIFIC = 43, + /* Windows 10 option to send when Anonymize=true */ + SD_DHCP_OPTION_NETBIOS_NAMESERVER = 44, + /* Windows 10 option to send when Anonymize=true */ + SD_DHCP_OPTION_NETBIOS_NODETYPE = 46, + /* Windows 10 option to send when Anonymize=true */ + SD_DHCP_OPTION_NETBIOS_SCOPE = 47, + SD_DHCP_OPTION_REQUESTED_IP_ADDRESS = 50, + SD_DHCP_OPTION_IP_ADDRESS_LEASE_TIME = 51, + SD_DHCP_OPTION_OVERLOAD = 52, + SD_DHCP_OPTION_MESSAGE_TYPE = 53, + SD_DHCP_OPTION_SERVER_IDENTIFIER = 54, + SD_DHCP_OPTION_PARAMETER_REQUEST_LIST = 55, + SD_DHCP_OPTION_ERROR_MESSAGE = 56, + SD_DHCP_OPTION_MAXIMUM_MESSAGE_SIZE = 57, + SD_DHCP_OPTION_RENEWAL_T1_TIME = 58, + SD_DHCP_OPTION_REBINDING_T2_TIME = 59, + SD_DHCP_OPTION_VENDOR_CLASS_IDENTIFIER = 60, + SD_DHCP_OPTION_CLIENT_IDENTIFIER = 61, + SD_DHCP_OPTION_SMTP_SERVER = 69, + SD_DHCP_OPTION_POP3_SERVER = 70, + SD_DHCP_OPTION_USER_CLASS = 77, + SD_DHCP_OPTION_FQDN = 81, + SD_DHCP_OPTION_RELAY_AGENT_INFORMATION = 82, + SD_DHCP_OPTION_NEW_POSIX_TIMEZONE = 100, + SD_DHCP_OPTION_NEW_TZDB_TIMEZONE = 101, + SD_DHCP_OPTION_DOMAIN_SEARCH_LIST = 119, + SD_DHCP_OPTION_SIP_SERVER = 120, + SD_DHCP_OPTION_CLASSLESS_STATIC_ROUTE = 121, + SD_DHCP_OPTION_MUD_URL = 161, + SD_DHCP_OPTION_6RD = 212, + SD_DHCP_OPTION_PRIVATE_BASE = 224, + /* Windows 10 option to send when Anonymize=true */ SD_DHCP_OPTION_PRIVATE_CLASSLESS_STATIC_ROUTE = 249, - /* Windows 10 option to send when Anonymize=true */ - SD_DHCP_OPTION_PRIVATE_PROXY_AUTODISCOVERY = 252, - SD_DHCP_OPTION_PRIVATE_LAST = 254, - SD_DHCP_OPTION_END = 255, + /* Windows 10 option to send when Anonymize=true */ + SD_DHCP_OPTION_PRIVATE_PROXY_AUTODISCOVERY = 252, + SD_DHCP_OPTION_PRIVATE_LAST = 254, + SD_DHCP_OPTION_END = 255, }; /* Suboptions for SD_DHCP_OPTION_RELAY_AGENT_INFORMATION option */ diff --git a/src/libnm-systemd-core/src/systemd/sd-dhcp-lease.h b/src/libnm-systemd-core/src/systemd/sd-dhcp-lease.h index 5abf9a40..478bbfd7 100644 --- a/src/libnm-systemd-core/src/systemd/sd-dhcp-lease.h +++ b/src/libnm-systemd-core/src/systemd/sd-dhcp-lease.h @@ -71,6 +71,13 @@ int sd_dhcp_lease_get_routes(sd_dhcp_lease *lease, sd_dhcp_route ***routes); int sd_dhcp_lease_get_vendor_specific(sd_dhcp_lease *lease, const void **data, size_t *data_len); int sd_dhcp_lease_get_client_id(sd_dhcp_lease *lease, const void **client_id, size_t *client_id_len); int sd_dhcp_lease_get_timezone(sd_dhcp_lease *lease, const char **timezone); +int sd_dhcp_lease_get_6rd( + sd_dhcp_lease *lease, + uint8_t *ret_ipv4masklen, + uint8_t *ret_prefixlen, + struct in6_addr *ret_prefix, + const struct in_addr **ret_br_addresses, + size_t *ret_n_br_addresses); int sd_dhcp_route_get_destination(sd_dhcp_route *route, struct in_addr *destination); int sd_dhcp_route_get_destination_prefix_length(sd_dhcp_route *route, uint8_t *length); diff --git a/src/libnm-systemd-core/src/systemd/sd-dhcp6-client.h b/src/libnm-systemd-core/src/systemd/sd-dhcp6-client.h index f3889782..0e23c84e 100644 --- a/src/libnm-systemd-core/src/systemd/sd-dhcp6-client.h +++ b/src/libnm-systemd-core/src/systemd/sd-dhcp6-client.h @@ -39,44 +39,151 @@ enum { SD_DHCP6_CLIENT_EVENT_INFORMATION_REQUEST = 13, }; +/* https://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xhtml#dhcpv6-parameters-2 */ enum { - SD_DHCP6_OPTION_CLIENTID = 1, - SD_DHCP6_OPTION_SERVERID = 2, - SD_DHCP6_OPTION_IA_NA = 3, - SD_DHCP6_OPTION_IA_TA = 4, - SD_DHCP6_OPTION_IAADDR = 5, - SD_DHCP6_OPTION_ORO = 6, - SD_DHCP6_OPTION_PREFERENCE = 7, - SD_DHCP6_OPTION_ELAPSED_TIME = 8, - SD_DHCP6_OPTION_RELAY_MSG = 9, + SD_DHCP6_OPTION_CLIENTID = 1, /* RFC 8415 */ + SD_DHCP6_OPTION_SERVERID = 2, /* RFC 8415 */ + SD_DHCP6_OPTION_IA_NA = 3, /* RFC 8415 */ + SD_DHCP6_OPTION_IA_TA = 4, /* RFC 8415 */ + SD_DHCP6_OPTION_IAADDR = 5, /* RFC 8415 */ + SD_DHCP6_OPTION_ORO = 6, /* RFC 8415 */ + SD_DHCP6_OPTION_PREFERENCE = 7, /* RFC 8415 */ + SD_DHCP6_OPTION_ELAPSED_TIME = 8, /* RFC 8415 */ + SD_DHCP6_OPTION_RELAY_MSG = 9, /* RFC 8415 */ /* option code 10 is unassigned */ - SD_DHCP6_OPTION_AUTH = 11, - SD_DHCP6_OPTION_UNICAST = 12, - SD_DHCP6_OPTION_STATUS_CODE = 13, - SD_DHCP6_OPTION_RAPID_COMMIT = 14, - SD_DHCP6_OPTION_USER_CLASS = 15, - SD_DHCP6_OPTION_VENDOR_CLASS = 16, - SD_DHCP6_OPTION_VENDOR_OPTS = 17, - SD_DHCP6_OPTION_INTERFACE_ID = 18, - SD_DHCP6_OPTION_RECONF_MSG = 19, - SD_DHCP6_OPTION_RECONF_ACCEPT = 20, - + SD_DHCP6_OPTION_AUTH = 11, /* RFC 8415 */ + SD_DHCP6_OPTION_UNICAST = 12, /* RFC 8415 */ + SD_DHCP6_OPTION_STATUS_CODE = 13, /* RFC 8415 */ + SD_DHCP6_OPTION_RAPID_COMMIT = 14, /* RFC 8415 */ + SD_DHCP6_OPTION_USER_CLASS = 15, /* RFC 8415 */ + SD_DHCP6_OPTION_VENDOR_CLASS = 16, /* RFC 8415 */ + SD_DHCP6_OPTION_VENDOR_OPTS = 17, /* RFC 8415 */ + SD_DHCP6_OPTION_INTERFACE_ID = 18, /* RFC 8415 */ + SD_DHCP6_OPTION_RECONF_MSG = 19, /* RFC 8415 */ + SD_DHCP6_OPTION_RECONF_ACCEPT = 20, /* RFC 8415 */ + SD_DHCP6_OPTION_SIP_SERVER_DOMAIN_NAME = 21, /* RFC 3319 */ + SD_DHCP6_OPTION_SIP_SERVER_ADDRESS = 22, /* RFC 3319 */ SD_DHCP6_OPTION_DNS_SERVERS = 23, /* RFC 3646 */ SD_DHCP6_OPTION_DOMAIN_LIST = 24, /* RFC 3646 */ - SD_DHCP6_OPTION_IA_PD = 25, /* RFC 3633, prefix delegation */ - SD_DHCP6_OPTION_IA_PD_PREFIX = 26, /* RFC 3633, prefix delegation */ - + SD_DHCP6_OPTION_IA_PD = 25, /* RFC 3633, RFC 8415 */ + SD_DHCP6_OPTION_IA_PD_PREFIX = 26, /* RFC 3633, RFC 8415 */ + SD_DHCP6_OPTION_NIS_SERVERS = 27, /* RFC 3898 */ + SD_DHCP6_OPTION_NISP_SERVERS = 28, /* RFC 3898 */ + SD_DHCP6_OPTION_NIS_DOMAIN_NAME = 29, /* RFC 3898 */ + SD_DHCP6_OPTION_NISP_DOMAIN_NAME = 30, /* RFC 3898 */ SD_DHCP6_OPTION_SNTP_SERVERS = 31, /* RFC 4075, deprecated */ - SD_DHCP6_OPTION_INFORMATION_REFRESH_TIME = 32, /* RFC 8415, sec. 21.23 */ - + SD_DHCP6_OPTION_INFORMATION_REFRESH_TIME = 32, /* RFC 4242, 8415, sec. 21.23 */ + SD_DHCP6_OPTION_BCMCS_SERVER_D = 33, /* RFC 4280 */ + SD_DHCP6_OPTION_BCMCS_SERVER_A = 34, /* RFC 4280 */ /* option code 35 is unassigned */ - - SD_DHCP6_OPTION_FQDN = 39, /* RFC 4704 */ - + SD_DHCP6_OPTION_GEOCONF_CIVIC = 36, /* RFC 4776 */ + SD_DHCP6_OPTION_REMOTE_ID = 37, /* RFC 4649 */ + SD_DHCP6_OPTION_SUBSCRIBER_ID = 38, /* RFC 4580 */ + SD_DHCP6_OPTION_CLIENT_FQDN = 39, /* RFC 4704 */ + SD_DHCP6_OPTION_PANA_AGENT = 40, /* RFC 5192 */ + SD_DHCP6_OPTION_NEW_POSIX_TIMEZONE = 41, /* RFC 4833 */ + SD_DHCP6_OPTION_NEW_TZDB_TIMEZONE = 42, /* RFC 4833 */ + SD_DHCP6_OPTION_ERO = 43, /* RFC 4994 */ + SD_DHCP6_OPTION_LQ_QUERY = 44, /* RFC 5007 */ + SD_DHCP6_OPTION_CLIENT_DATA = 45, /* RFC 5007 */ + SD_DHCP6_OPTION_CLT_TIME = 46, /* RFC 5007 */ + SD_DHCP6_OPTION_LQ_RELAY_DATA = 47, /* RFC 5007 */ + SD_DHCP6_OPTION_LQ_CLIENT_LINK = 48, /* RFC 5007 */ + SD_DHCP6_OPTION_MIP6_HNIDF = 49, /* RFC 6610 */ + SD_DHCP6_OPTION_MIP6_VDINF = 50, /* RFC 6610 */ + SD_DHCP6_OPTION_V6_LOST = 51, /* RFC 5223 */ + SD_DHCP6_OPTION_CAPWAP_AC_V6 = 52, /* RFC 5417 */ + SD_DHCP6_OPTION_RELAY_ID = 53, /* RFC 5460 */ + SD_DHCP6_OPTION_IPV6_ADDRESS_MOS = 54, /* RFC 5678 */ + SD_DHCP6_OPTION_IPV6_FQDN_MOS = 55, /* RFC 5678 */ SD_DHCP6_OPTION_NTP_SERVER = 56, /* RFC 5908 */ - SD_DHCP6_OPTION_MUD_URL = 112, /* RFC 8250 */ - - /* option codes 89-142 are unassigned */ + SD_DHCP6_OPTION_V6_ACCESS_DOMAIN = 57, /* RFC 5986 */ + SD_DHCP6_OPTION_SIP_UA_CS_LIST = 58, /* RFC 6011 */ + SD_DHCP6_OPTION_BOOTFILE_URL = 59, /* RFC 5970 */ + SD_DHCP6_OPTION_BOOTFILE_PARAM = 60, /* RFC 5970 */ + SD_DHCP6_OPTION_CLIENT_ARCH_TYPE = 61, /* RFC 5970 */ + SD_DHCP6_OPTION_NII = 62, /* RFC 5970 */ + SD_DHCP6_OPTION_GEOLOCATION = 63, /* RFC 6225 */ + SD_DHCP6_OPTION_AFTR_NAME = 64, /* RFC 6334 */ + SD_DHCP6_OPTION_ERP_LOCAL_DOMAIN_NAME = 65, /* RFC 6440 */ + SD_DHCP6_OPTION_RSOO = 66, /* RFC 6422 */ + SD_DHCP6_OPTION_PD_EXCLUDE = 67, /* RFC 6603 */ + SD_DHCP6_OPTION_VSS = 68, /* RFC 6607 */ + SD_DHCP6_OPTION_MIP6_IDINF = 69, /* RFC 6610 */ + SD_DHCP6_OPTION_MIP6_UDINF = 70, /* RFC 6610 */ + SD_DHCP6_OPTION_MIP6_HNP = 71, /* RFC 6610 */ + SD_DHCP6_OPTION_MIP6_HAA = 72, /* RFC 6610 */ + SD_DHCP6_OPTION_MIP6_HAF = 73, /* RFC 6610 */ + SD_DHCP6_OPTION_RDNSS_SELECTION = 74, /* RFC 6731 */ + SD_DHCP6_OPTION_KRB_PRINCIPAL_NAME = 75, /* RFC 6784 */ + SD_DHCP6_OPTION_KRB_REALM_NAME = 76, /* RFC 6784 */ + SD_DHCP6_OPTION_KRB_DEFAULT_REALM_NAME = 77, /* RFC 6784 */ + SD_DHCP6_OPTION_KRB_KDC = 78, /* RFC 6784 */ + SD_DHCP6_OPTION_CLIENT_LINKLAYER_ADDR = 79, /* RFC 6939 */ + SD_DHCP6_OPTION_LINK_ADDRESS = 80, /* RFC 6977 */ + SD_DHCP6_OPTION_RADIUS = 81, /* RFC 7037 */ + SD_DHCP6_OPTION_SOL_MAX_RT = 82, /* RFC 7083, RFC 8415 */ + SD_DHCP6_OPTION_INF_MAX_RT = 83, /* RFC 7083, RFC 8415 */ + SD_DHCP6_OPTION_ADDRSEL = 84, /* RFC 7078 */ + SD_DHCP6_OPTION_ADDRSEL_TABLE = 85, /* RFC 7078 */ + SD_DHCP6_OPTION_V6_PCP_SERVER = 86, /* RFC 7291 */ + SD_DHCP6_OPTION_DHCPV4_MSG = 87, /* RFC 7341 */ + SD_DHCP6_OPTION_DHCP4_O_DHCP6_SERVER = 88, /* RFC 7341 */ + SD_DHCP6_OPTION_S46_RULE = 89, /* RFC 7598 */ + SD_DHCP6_OPTION_S46_BR = 90, /* RFC 7598, RFC 8539 */ + SD_DHCP6_OPTION_S46_DMR = 91, /* RFC 7598 */ + SD_DHCP6_OPTION_S46_V4V6BIND = 92, /* RFC 7598 */ + SD_DHCP6_OPTION_S46_PORTPARAMS = 93, /* RFC 7598 */ + SD_DHCP6_OPTION_S46_CONT_MAPE = 94, /* RFC 7598 */ + SD_DHCP6_OPTION_S46_CONT_MAPT = 95, /* RFC 7598 */ + SD_DHCP6_OPTION_S46_CONT_LW = 96, /* RFC 7598 */ + SD_DHCP6_OPTION_4RD = 97, /* RFC 7600 */ + SD_DHCP6_OPTION_4RD_MAP_RULE = 98, /* RFC 7600 */ + SD_DHCP6_OPTION_4RD_NON_MAP_RULE = 99, /* RFC 7600 */ + SD_DHCP6_OPTION_LQ_BASE_TIME = 100, /* RFC 7653 */ + SD_DHCP6_OPTION_LQ_START_TIME = 101, /* RFC 7653 */ + SD_DHCP6_OPTION_LQ_END_TIME = 102, /* RFC 7653 */ + SD_DHCP6_OPTION_CAPTIVE_PORTAL = 103, /* RFC 8910 */ + SD_DHCP6_OPTION_MPL_PARAMETERS = 104, /* RFC 7774 */ + SD_DHCP6_OPTION_ANI_ATT = 105, /* RFC 7839 */ + SD_DHCP6_OPTION_ANI_NETWORK_NAME = 106, /* RFC 7839 */ + SD_DHCP6_OPTION_ANI_AP_NAME = 107, /* RFC 7839 */ + SD_DHCP6_OPTION_ANI_AP_BSSID = 108, /* RFC 7839 */ + SD_DHCP6_OPTION_ANI_OPERATOR_ID = 109, /* RFC 7839 */ + SD_DHCP6_OPTION_ANI_OPERATOR_REALM = 110, /* RFC 7839 */ + SD_DHCP6_OPTION_S46_PRIORITY = 111, /* RFC 8026 */ + SD_DHCP6_OPTION_MUD_URL_V6 = 112, /* RFC 8520 */ + SD_DHCP6_OPTION_V6_PREFIX64 = 113, /* RFC 8115 */ + SD_DHCP6_OPTION_F_BINDING_STATUS = 114, /* RFC 8156 */ + SD_DHCP6_OPTION_F_CONNECT_FLAGS = 115, /* RFC 8156 */ + SD_DHCP6_OPTION_F_DNS_REMOVAL_INFO = 116, /* RFC 8156 */ + SD_DHCP6_OPTION_F_DNS_HOST_NAME = 117, /* RFC 8156 */ + SD_DHCP6_OPTION_F_DNS_ZONE_NAME = 118, /* RFC 8156 */ + SD_DHCP6_OPTION_F_DNS_FLAGS = 119, /* RFC 8156 */ + SD_DHCP6_OPTION_F_EXPIRATION_TIME = 120, /* RFC 8156 */ + SD_DHCP6_OPTION_F_MAX_UNACKED_BNDUPD = 121, /* RFC 8156 */ + SD_DHCP6_OPTION_F_MCLT = 122, /* RFC 8156 */ + SD_DHCP6_OPTION_F_PARTNER_LIFETIME = 123, /* RFC 8156 */ + SD_DHCP6_OPTION_F_PARTNER_LIFETIME_SENT = 124, /* RFC 8156 */ + SD_DHCP6_OPTION_F_PARTNER_DOWN_TIME = 125, /* RFC 8156 */ + SD_DHCP6_OPTION_F_PARTNER_RAW_CLT_TIME = 126, /* RFC 8156 */ + SD_DHCP6_OPTION_F_PROTOCOL_VERSION = 127, /* RFC 8156 */ + SD_DHCP6_OPTION_F_KEEPALIVE_TIME = 128, /* RFC 8156 */ + SD_DHCP6_OPTION_F_RECONFIGURE_DATA = 129, /* RFC 8156 */ + SD_DHCP6_OPTION_F_RELATIONSHIP_NAME = 130, /* RFC 8156 */ + SD_DHCP6_OPTION_F_SERVER_FLAGS = 131, /* RFC 8156 */ + SD_DHCP6_OPTION_F_SERVER_STATE = 132, /* RFC 8156 */ + SD_DHCP6_OPTION_F_START_TIME_OF_STATE = 133, /* RFC 8156 */ + SD_DHCP6_OPTION_F_STATE_EXPIRATION_TIME = 134, /* RFC 8156 */ + SD_DHCP6_OPTION_RELAY_PORT = 135, /* RFC 8357 */ + SD_DHCP6_OPTION_V6_SZTP_REDIRECT = 136, /* RFC 8572 */ + SD_DHCP6_OPTION_S46_BIND_IPV6_PREFIX = 137, /* RFC 8539 */ + SD_DHCP6_OPTION_IA_LL = 138, /* RFC 8947 */ + SD_DHCP6_OPTION_LLADDR = 139, /* RFC 8947 */ + SD_DHCP6_OPTION_SLAP_QUAD = 140, /* RFC 8948 */ + SD_DHCP6_OPTION_V6_DOTS_RI = 141, /* RFC 8973 */ + SD_DHCP6_OPTION_V6_DOTS_ADDRESS = 142, /* RFC 8973 */ + SD_DHCP6_OPTION_IPV6_ADDRESS_ANDSF = 143, /* RFC 6153 */ /* option codes 144-65535 are unassigned */ }; diff --git a/src/libnm-systemd-core/src/systemd/sd-dhcp6-lease.h b/src/libnm-systemd-core/src/systemd/sd-dhcp6-lease.h index a10901e5..472276de 100644 --- a/src/libnm-systemd-core/src/systemd/sd-dhcp6-lease.h +++ b/src/libnm-systemd-core/src/systemd/sd-dhcp6-lease.h @@ -21,6 +21,7 @@ #include #include +#include #include "_sd-common.h" @@ -28,6 +29,9 @@ _SD_BEGIN_DECLARATIONS; typedef struct sd_dhcp6_lease sd_dhcp6_lease; +int sd_dhcp6_lease_get_timestamp(sd_dhcp6_lease *lease, clockid_t clock, uint64_t *ret); +int sd_dhcp6_lease_get_server_address(sd_dhcp6_lease *lease, struct in6_addr *ret); + void sd_dhcp6_lease_reset_address_iter(sd_dhcp6_lease *lease); int sd_dhcp6_lease_get_address(sd_dhcp6_lease *lease, struct in6_addr *addr, diff --git a/src/libnm-systemd-core/src/systemd/sd-event.h b/src/libnm-systemd-core/src/systemd/sd-event.h index 2ae2a0da..63984eef 100644 --- a/src/libnm-systemd-core/src/systemd/sd-event.h +++ b/src/libnm-systemd-core/src/systemd/sd-event.h @@ -93,6 +93,7 @@ int sd_event_add_signal(sd_event *e, sd_event_source **s, int sig, sd_event_sign int sd_event_add_child(sd_event *e, sd_event_source **s, pid_t pid, int options, sd_event_child_handler_t callback, void *userdata); int sd_event_add_child_pidfd(sd_event *e, sd_event_source **s, int pidfd, int options, sd_event_child_handler_t callback, void *userdata); int sd_event_add_inotify(sd_event *e, sd_event_source **s, const char *path, uint32_t mask, sd_event_inotify_handler_t callback, void *userdata); +int sd_event_add_inotify_fd(sd_event *e, sd_event_source **s, int fd, uint32_t mask, sd_event_inotify_handler_t callback, void *userdata); int sd_event_add_defer(sd_event *e, sd_event_source **s, sd_event_handler_t callback, void *userdata); int sd_event_add_post(sd_event *e, sd_event_source **s, sd_event_handler_t callback, void *userdata); int sd_event_add_exit(sd_event *e, sd_event_source **s, sd_event_handler_t callback, void *userdata); @@ -165,6 +166,7 @@ int sd_event_source_set_exit_on_failure(sd_event_source *s, int b); int sd_event_source_set_ratelimit(sd_event_source *s, uint64_t interval_usec, unsigned burst); int sd_event_source_get_ratelimit(sd_event_source *s, uint64_t *ret_interval_usec, unsigned *ret_burst); int sd_event_source_is_ratelimited(sd_event_source *s); +int sd_event_source_set_ratelimit_expire_callback(sd_event_source *s, sd_event_handler_t callback); /* Define helpers so that __attribute__((cleanup(sd_event_unrefp))) and similar may be used. */ _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_event, sd_event_unref); diff --git a/src/libnm-systemd-core/src/systemd/sd-ipv4acd.h b/src/libnm-systemd-core/src/systemd/sd-ipv4acd.h deleted file mode 100644 index 90d3f0a0..00000000 --- a/src/libnm-systemd-core/src/systemd/sd-ipv4acd.h +++ /dev/null @@ -1,63 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -#ifndef foosdipv4acdfoo -#define foosdipv4acdfoo - -/*** - Copyright © 2014 Axis Communications AB. All rights reserved. - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see . -***/ - -#include -#include -#include - -#include "sd-event.h" - -#include "_sd-common.h" - -_SD_BEGIN_DECLARATIONS; - -enum { - SD_IPV4ACD_EVENT_STOP = 0, - SD_IPV4ACD_EVENT_BIND = 1, - SD_IPV4ACD_EVENT_CONFLICT = 2, -}; - -typedef struct sd_ipv4acd sd_ipv4acd; -typedef void (*sd_ipv4acd_callback_t)(sd_ipv4acd *acd, int event, void *userdata); -typedef int (*sd_ipv4acd_check_mac_callback_t)(sd_ipv4acd *acd, const struct ether_addr *mac, void *userdata); - -int sd_ipv4acd_detach_event(sd_ipv4acd *acd); -int sd_ipv4acd_attach_event(sd_ipv4acd *acd, sd_event *event, int64_t priority); -int sd_ipv4acd_get_address(sd_ipv4acd *acd, struct in_addr *address); -int sd_ipv4acd_set_callback(sd_ipv4acd *acd, sd_ipv4acd_callback_t cb, void *userdata); -int sd_ipv4acd_set_check_mac_callback(sd_ipv4acd *acd, sd_ipv4acd_check_mac_callback_t cb, void *userdata); -int sd_ipv4acd_set_mac(sd_ipv4acd *acd, const struct ether_addr *addr); -int sd_ipv4acd_set_ifindex(sd_ipv4acd *acd, int interface_index); -int sd_ipv4acd_get_ifindex(sd_ipv4acd *acd); -int sd_ipv4acd_set_ifname(sd_ipv4acd *acd, const char *interface_name); -int sd_ipv4acd_get_ifname(sd_ipv4acd *acd, const char **ret); -int sd_ipv4acd_set_address(sd_ipv4acd *acd, const struct in_addr *address); -int sd_ipv4acd_is_running(sd_ipv4acd *acd); -int sd_ipv4acd_start(sd_ipv4acd *acd, bool reset_conflicts); -int sd_ipv4acd_stop(sd_ipv4acd *acd); -sd_ipv4acd *sd_ipv4acd_ref(sd_ipv4acd *acd); -sd_ipv4acd *sd_ipv4acd_unref(sd_ipv4acd *acd); -int sd_ipv4acd_new(sd_ipv4acd **ret); - -_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_ipv4acd, sd_ipv4acd_unref); - -_SD_END_DECLARATIONS; - -#endif diff --git a/src/libnm-systemd-core/src/systemd/sd-ipv4ll.h b/src/libnm-systemd-core/src/systemd/sd-ipv4ll.h deleted file mode 100644 index ed014b53..00000000 --- a/src/libnm-systemd-core/src/systemd/sd-ipv4ll.h +++ /dev/null @@ -1,65 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -#ifndef foosdipv4llfoo -#define foosdipv4llfoo - -/*** - Copyright © 2014 Axis Communications AB. All rights reserved. - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see . -***/ - -#include -#include - -#include "sd-event.h" - -#include "_sd-common.h" - -_SD_BEGIN_DECLARATIONS; - -enum { - SD_IPV4LL_EVENT_STOP = 0, - SD_IPV4LL_EVENT_BIND = 1, - SD_IPV4LL_EVENT_CONFLICT = 2, -}; - -typedef struct sd_ipv4ll sd_ipv4ll; -typedef void (*sd_ipv4ll_callback_t)(sd_ipv4ll *ll, int event, void *userdata); -typedef int (*sd_ipv4ll_check_mac_callback_t)(sd_ipv4ll *ll, const struct ether_addr *mac, void *userdata); - -int sd_ipv4ll_detach_event(sd_ipv4ll *ll); -int sd_ipv4ll_attach_event(sd_ipv4ll *ll, sd_event *event, int64_t priority); -int sd_ipv4ll_get_address(sd_ipv4ll *ll, struct in_addr *address); -int sd_ipv4ll_set_callback(sd_ipv4ll *ll, sd_ipv4ll_callback_t cb, void *userdata); -int sd_ipv4ll_set_check_mac_callback(sd_ipv4ll *ll, sd_ipv4ll_check_mac_callback_t cb, void *userdata); -int sd_ipv4ll_set_mac(sd_ipv4ll *ll, const struct ether_addr *addr); -int sd_ipv4ll_set_ifindex(sd_ipv4ll *ll, int interface_index); -int sd_ipv4ll_get_ifindex(sd_ipv4ll *ll); -int sd_ipv4ll_set_ifname(sd_ipv4ll *ll, const char *interface_name); -int sd_ipv4ll_get_ifname(sd_ipv4ll *ll, const char **ret); -int sd_ipv4ll_set_address(sd_ipv4ll *ll, const struct in_addr *address); -int sd_ipv4ll_set_address_seed(sd_ipv4ll *ll, uint64_t seed); -int sd_ipv4ll_is_running(sd_ipv4ll *ll); -int sd_ipv4ll_restart(sd_ipv4ll *ll); -int sd_ipv4ll_start(sd_ipv4ll *ll); -int sd_ipv4ll_stop(sd_ipv4ll *ll); -sd_ipv4ll *sd_ipv4ll_ref(sd_ipv4ll *ll); -sd_ipv4ll *sd_ipv4ll_unref(sd_ipv4ll *ll); -int sd_ipv4ll_new(sd_ipv4ll **ret); - -_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_ipv4ll, sd_ipv4ll_unref); - -_SD_END_DECLARATIONS; - -#endif diff --git a/src/libnm-systemd-core/src/systemd/sd-ndisc.h b/src/libnm-systemd-core/src/systemd/sd-ndisc.h index f45b2ad6..ab9ff55d 100644 --- a/src/libnm-systemd-core/src/systemd/sd-ndisc.h +++ b/src/libnm-systemd-core/src/systemd/sd-ndisc.h @@ -82,9 +82,6 @@ int sd_ndisc_set_ifname(sd_ndisc *nd, const char *interface_name); int sd_ndisc_get_ifname(sd_ndisc *nd, const char **ret); int sd_ndisc_set_mac(sd_ndisc *nd, const struct ether_addr *mac_addr); -int sd_ndisc_get_mtu(sd_ndisc *nd, uint32_t *ret); -int sd_ndisc_get_hop_limit(sd_ndisc *nd, uint8_t *ret); - int sd_ndisc_router_from_raw(sd_ndisc_router **ret, const void *raw, size_t raw_size); sd_ndisc_router *sd_ndisc_router_ref(sd_ndisc_router *rt); sd_ndisc_router *sd_ndisc_router_unref(sd_ndisc_router *rt); diff --git a/src/libnm-systemd-shared/sd-adapt-shared/filesystems.h b/src/libnm-systemd-shared/sd-adapt-shared/filesystems.h new file mode 100644 index 00000000..637892c2 --- /dev/null +++ b/src/libnm-systemd-shared/sd-adapt-shared/filesystems.h @@ -0,0 +1,3 @@ +#pragma once + +/* dummy header */ diff --git a/src/libnm-systemd-shared/sd-adapt-shared/hmac.h b/src/libnm-systemd-shared/sd-adapt-shared/hmac.h new file mode 100644 index 00000000..637892c2 --- /dev/null +++ b/src/libnm-systemd-shared/sd-adapt-shared/hmac.h @@ -0,0 +1,3 @@ +#pragma once + +/* dummy header */ diff --git a/src/libnm-systemd-shared/sd-adapt-shared/missing_magic.h b/src/libnm-systemd-shared/sd-adapt-shared/missing_magic.h index 637892c2..a5dce206 100644 --- a/src/libnm-systemd-shared/sd-adapt-shared/missing_magic.h +++ b/src/libnm-systemd-shared/sd-adapt-shared/missing_magic.h @@ -1,3 +1,5 @@ #pragma once /* dummy header */ + +#include diff --git a/src/libnm-systemd-shared/sd-adapt-shared/netif-util.h b/src/libnm-systemd-shared/sd-adapt-shared/netif-util.h new file mode 100644 index 00000000..637892c2 --- /dev/null +++ b/src/libnm-systemd-shared/sd-adapt-shared/netif-util.h @@ -0,0 +1,3 @@ +#pragma once + +/* dummy header */ diff --git a/src/libnm-systemd-shared/src/basic/alloc-util.h b/src/libnm-systemd-shared/src/basic/alloc-util.h index e587fe79..65d51756 100644 --- a/src/libnm-systemd-shared/src/basic/alloc-util.h +++ b/src/libnm-systemd-shared/src/basic/alloc-util.h @@ -22,20 +22,25 @@ typedef void (*free_func_t)(void *p); #define new0(t, n) ((t*) calloc((n) ?: 1, sizeof(t))) +#define alloca_safe(n) \ + ({ \ + size_t _nn_ = n; \ + assert(_nn_ <= ALLOCA_MAX); \ + alloca(_nn_ == 0 ? 1 : _nn_); \ + }) \ + #define newa(t, n) \ ({ \ size_t _n_ = n; \ assert(!size_multiply_overflow(sizeof(t), _n_)); \ - assert(sizeof(t)*_n_ <= ALLOCA_MAX); \ - (t*) alloca((sizeof(t)*_n_) ?: 1); \ + (t*) alloca_safe(sizeof(t)*_n_); \ }) #define newa0(t, n) \ ({ \ size_t _n_ = n; \ assert(!size_multiply_overflow(sizeof(t), _n_)); \ - assert(sizeof(t)*_n_ <= ALLOCA_MAX); \ - (t*) alloca0((sizeof(t)*_n_) ?: 1); \ + (t*) alloca0((sizeof(t)*_n_)); \ }) #define newdup(t, p, n) ((t*) memdup_multiply(p, sizeof(t), (n))) @@ -44,12 +49,6 @@ typedef void (*free_func_t)(void *p); #define malloc0(n) (calloc(1, (n) ?: 1)) -#define mfree(memory) \ - ({ \ - free(memory); \ - (typeof(memory)) NULL; \ - }) - #define free_and_replace(a, b) \ ({ \ typeof(a)* _a = &(a); \ @@ -67,8 +66,7 @@ void* memdup_suffix0(const void *p, size_t l); /* We can't use _alloc_() here, s ({ \ void *_q_; \ size_t _l_ = l; \ - assert(_l_ <= ALLOCA_MAX); \ - _q_ = alloca(_l_ ?: 1); \ + _q_ = alloca_safe(_l_); \ memcpy_safe(_q_, p, _l_); \ }) @@ -76,8 +74,7 @@ void* memdup_suffix0(const void *p, size_t l); /* We can't use _alloc_() here, s ({ \ void *_q_; \ size_t _l_ = l; \ - assert(_l_ <= ALLOCA_MAX); \ - _q_ = alloca(_l_ + 1); \ + _q_ = alloca_safe(_l_ + 1); \ ((uint8_t*) _q_)[_l_] = 0; \ memcpy_safe(_q_, p, _l_); \ }) @@ -144,9 +141,8 @@ void* greedy_realloc0(void **p, size_t need, size_t size); ({ \ char *_new_; \ size_t _len_ = n; \ - assert(_len_ <= ALLOCA_MAX); \ - _new_ = alloca(_len_ ?: 1); \ - (void *) memset(_new_, 0, _len_); \ + _new_ = alloca_safe(_len_); \ + memset(_new_, 0, _len_); \ }) /* It's not clear what alignment glibc/gcc alloca() guarantee, hence provide a guaranteed safe version */ @@ -155,8 +151,7 @@ void* greedy_realloc0(void **p, size_t need, size_t size); void *_ptr_; \ size_t _mask_ = (align) - 1; \ size_t _size_ = size; \ - assert(_size_ <= ALLOCA_MAX); \ - _ptr_ = alloca((_size_ + _mask_) ?: 1); \ + _ptr_ = alloca_safe(_size_ + _mask_); \ (void*)(((uintptr_t)_ptr_ + _mask_) & ~_mask_); \ }) @@ -165,7 +160,7 @@ void* greedy_realloc0(void **p, size_t need, size_t size); void *_new_; \ size_t _xsize_ = (size); \ _new_ = alloca_align(_xsize_, (align)); \ - (void*)memset(_new_, 0, _xsize_); \ + memset(_new_, 0, _xsize_); \ }) #if HAS_FEATURE_MEMORY_SANITIZER @@ -193,3 +188,19 @@ void* greedy_realloc0(void **p, size_t need, size_t size); __builtin_types_compatible_p(typeof(x), typeof(&*(x))), \ MALLOC_SIZEOF_SAFE(x)/sizeof((x)[0]), \ VOID_0)) + + +/* These are like strdupa()/strndupa(), but honour ALLOCA_MAX */ +#define strdupa_safe(s) \ + ({ \ + const char *_t = (s); \ + (char*) memdupa_suffix0(_t, strlen(_t)); \ + }) + +#define strndupa_safe(s, n) \ + ({ \ + const char *_t = (s); \ + (char*) memdupa_suffix0(_t, strnlen(_t, (n))); \ + }) + +#include "memory-util.h" diff --git a/src/libnm-systemd-shared/src/basic/cgroup-util.h b/src/libnm-systemd-shared/src/basic/cgroup-util.h index 90ccd2c0..461c01b3 100644 --- a/src/libnm-systemd-shared/src/basic/cgroup-util.h +++ b/src/libnm-systemd-shared/src/basic/cgroup-util.h @@ -2,6 +2,7 @@ #pragma once #include +#include #include #include #include @@ -33,6 +34,9 @@ typedef enum CGroupController { CGROUP_CONTROLLER_BPF_FOREIGN, CGROUP_CONTROLLER_BPF_SOCKET_BIND, CGROUP_CONTROLLER_BPF_RESTRICT_NETWORK_INTERFACES, + /* The BPF hook implementing RestrictFileSystems= is not defined here. + * It's applied as late as possible in exec_child() so we don't block + * our own unit setup code. */ _CGROUP_CONTROLLER_MAX, _CGROUP_CONTROLLER_INVALID = -EINVAL, @@ -123,6 +127,20 @@ static inline bool CGROUP_CPU_SHARES_IS_OK(uint64_t x) { (x >= CGROUP_CPU_SHARES_MIN && x <= CGROUP_CPU_SHARES_MAX); } +/* Special values for the special {blkio,io}.bfq.weight attribute */ +#define CGROUP_BFQ_WEIGHT_INVALID UINT64_MAX +#define CGROUP_BFQ_WEIGHT_MIN UINT64_C(1) +#define CGROUP_BFQ_WEIGHT_MAX UINT64_C(1000) +#define CGROUP_BFQ_WEIGHT_DEFAULT UINT64_C(100) + +/* Convert the normal io.weight value to io.bfq.weight */ +static inline uint64_t BFQ_WEIGHT(uint64_t io_weight) { + return + io_weight <= CGROUP_WEIGHT_DEFAULT ? + CGROUP_BFQ_WEIGHT_DEFAULT - (CGROUP_WEIGHT_DEFAULT - io_weight) * (CGROUP_BFQ_WEIGHT_DEFAULT - CGROUP_BFQ_WEIGHT_MIN) / (CGROUP_WEIGHT_DEFAULT - CGROUP_WEIGHT_MIN) : + CGROUP_BFQ_WEIGHT_DEFAULT + (io_weight - CGROUP_WEIGHT_DEFAULT) * (CGROUP_BFQ_WEIGHT_MAX - CGROUP_BFQ_WEIGHT_DEFAULT) / (CGROUP_WEIGHT_MAX - CGROUP_WEIGHT_DEFAULT); +} + /* Special values for the blkio.weight attribute */ #define CGROUP_BLKIO_WEIGHT_INVALID UINT64_MAX #define CGROUP_BLKIO_WEIGHT_MIN UINT64_C(10) @@ -236,6 +254,7 @@ int cg_is_empty_recursive(const char *controller, const char *path); int cg_get_root_path(char **path); +int cg_path_get_cgroupid(const char *path, uint64_t *ret); int cg_path_get_session(const char *path, char **session); int cg_path_get_owner_uid(const char *path, uid_t *uid); int cg_path_get_unit(const char *path, char **unit); @@ -311,3 +330,12 @@ typedef enum ManagedOOMPreference { const char* managed_oom_preference_to_string(ManagedOOMPreference a) _const_; ManagedOOMPreference managed_oom_preference_from_string(const char *s) _pure_; + +/* The structure to pass to name_to_handle_at() on cgroupfs2 */ +typedef union { + struct file_handle file_handle; + uint8_t space[offsetof(struct file_handle, f_handle) + sizeof(uint64_t)]; +} cg_file_handle; + +#define CG_FILE_HANDLE_INIT { .file_handle.handle_bytes = sizeof(uint64_t) } +#define CG_FILE_HANDLE_CGROUPID(fh) (*(uint64_t*) (fh).file_handle.f_handle) diff --git a/src/libnm-systemd-shared/src/basic/env-util.c b/src/libnm-systemd-shared/src/basic/env-util.c index 431862f6..f47ddefe 100644 --- a/src/libnm-systemd-shared/src/basic/env-util.c +++ b/src/libnm-systemd-shared/src/basic/env-util.c @@ -10,6 +10,7 @@ #include "alloc-util.h" #include "env-util.h" +#include "errno-util.h" #include "escape.h" #include "extract-word.h" #include "macro.h" @@ -397,7 +398,7 @@ int strv_env_replace_consume(char ***l, char *p) { return -EINVAL; } - name = strndupa(p, t - p); + name = strndupa_safe(p, t - p); STRV_FOREACH(f, *l) if (env_entry_has_name(*f, name)) { @@ -484,7 +485,7 @@ char *strv_env_get_n(char **l, const char *name, size_t k, unsigned flags) { if (flags & REPLACE_ENV_USE_ENVIRONMENT) { const char *t; - t = strndupa(name, k); + t = strndupa_safe(name, k); return getenv(t); }; @@ -791,15 +792,12 @@ int getenv_bool_secure(const char *p) { #if 0 /* NM_IGNORED */ int set_unset_env(const char *name, const char *value, bool overwrite) { - int r; + assert(name); if (value) - r = setenv(name, value, overwrite); - else - r = unsetenv(name); - if (r < 0) - return -errno; - return 0; + return RET_NERRNO(setenv(name, value, overwrite)); + + return RET_NERRNO(unsetenv(name)); } int putenv_dup(const char *assignment, bool override) { @@ -809,12 +807,10 @@ int putenv_dup(const char *assignment, bool override) { if (!e) return -EINVAL; - n = strndupa(assignment, e - assignment); + n = strndupa_safe(assignment, e - assignment); /* This is like putenv(), but uses setenv() so that our memory doesn't become part of environ[]. */ - if (setenv(n, e + 1, override) < 0) - return -errno; - return 0; + return RET_NERRNO(setenv(n, e + 1, override)); } int setenv_systemd_exec_pid(bool update_only) { diff --git a/src/libnm-systemd-shared/src/basic/errno-util.h b/src/libnm-systemd-shared/src/basic/errno-util.h index 3f2d0af5..09abf0b7 100644 --- a/src/libnm-systemd-shared/src/basic/errno-util.h +++ b/src/libnm-systemd-shared/src/basic/errno-util.h @@ -13,7 +13,7 @@ static inline void _reset_errno_(int *saved_errno) { errno = *saved_errno; } -#define PROTECT_ERRNO \ +#define PROTECT_ERRNO \ _cleanup_(_reset_errno_) _unused_ int _saved_errno_ = errno #define UNPROTECT_ERRNO \ @@ -31,6 +31,29 @@ static inline int negative_errno(void) { return -errno; } +static inline int RET_NERRNO(int ret) { + + /* Helper to wrap system calls in to make them return negative errno errors. This brings system call + * error handling in sync with how we usually handle errors in our own code, i.e. with immediate + * returning of negative errno. Usage is like this: + * + * … + * r = RET_NERRNO(unlink(t)); + * … + * + * or + * + * … + * fd = RET_NERRNO(open("/etc/fstab", O_RDONLY|O_CLOEXEC)); + * … + */ + + if (ret < 0) + return negative_errno(); + + return ret; +} + static inline const char *strerror_safe(int error) { /* 'safe' here does NOT mean thread safety. */ return strerror(abs(error)); /* lgtm [cpp/potentially-dangerous-function] */ @@ -47,6 +70,13 @@ static inline int errno_or_else(int fallback) { return -abs(fallback); } +/* For send()/recv() or read()/write(). */ +static inline bool ERRNO_IS_TRANSIENT(int r) { + return IN_SET(abs(r), + EAGAIN, + EINTR); +} + /* Hint #1: ENETUNREACH happens if we try to connect to "non-existing" special IP addresses, such as ::5. * * Hint #2: The kernel sends e.g., EHOSTUNREACH or ENONET to userspace in some ICMP error cases. See the @@ -77,10 +107,8 @@ static inline bool ERRNO_IS_DISCONNECT(int r) { * the accept(2) man page. */ static inline bool ERRNO_IS_ACCEPT_AGAIN(int r) { return ERRNO_IS_DISCONNECT(r) || - IN_SET(abs(r), - EAGAIN, - EINTR, - EOPNOTSUPP); + ERRNO_IS_TRANSIENT(r) || + abs(r) == EOPNOTSUPP; } /* Resource exhaustion, could be our fault or general system trouble */ diff --git a/src/libnm-systemd-shared/src/basic/escape.c b/src/libnm-systemd-shared/src/basic/escape.c index 93288563..4dfb9a16 100644 --- a/src/libnm-systemd-shared/src/basic/escape.c +++ b/src/libnm-systemd-shared/src/basic/escape.c @@ -547,7 +547,7 @@ char* shell_maybe_quote(const char *s, ShellEscapeFlags flags) { return str_realloc(buf); } -char* quote_command_line(char **argv) { +char* quote_command_line(char **argv, ShellEscapeFlags flags) { _cleanup_free_ char *result = NULL; assert(argv); @@ -556,7 +556,7 @@ char* quote_command_line(char **argv) { STRV_FOREACH(a, argv) { _cleanup_free_ char *t = NULL; - t = shell_maybe_quote(*a, SHELL_ESCAPE_EMPTY); + t = shell_maybe_quote(*a, flags); if (!t) return NULL; @@ -564,6 +564,6 @@ char* quote_command_line(char **argv) { return NULL; } - return TAKE_PTR(result); + return str_realloc(TAKE_PTR(result)); } #endif /* NM_IGNORED */ diff --git a/src/libnm-systemd-shared/src/basic/escape.h b/src/libnm-systemd-shared/src/basic/escape.h index d490510d..318da6f2 100644 --- a/src/libnm-systemd-shared/src/basic/escape.h +++ b/src/libnm-systemd-shared/src/basic/escape.h @@ -69,4 +69,4 @@ char* escape_non_printable_full(const char *str, size_t console_width, XEscapeFl char* shell_escape(const char *s, const char *bad); char* shell_maybe_quote(const char *s, ShellEscapeFlags flags); -char* quote_command_line(char **argv); +char* quote_command_line(char **argv, ShellEscapeFlags flags); diff --git a/src/libnm-systemd-shared/src/basic/ether-addr-util.c b/src/libnm-systemd-shared/src/basic/ether-addr-util.c index c73dcff1..4504b6be 100644 --- a/src/libnm-systemd-shared/src/basic/ether-addr-util.c +++ b/src/libnm-systemd-shared/src/basic/ether-addr-util.c @@ -9,20 +9,29 @@ #include #include "ether-addr-util.h" +#include "hexdecoct.h" #include "macro.h" #include "string-util.h" -char* hw_addr_to_string(const struct hw_addr_data *addr, char buffer[HW_ADDR_TO_STRING_MAX]) { +char *hw_addr_to_string_full( + const struct hw_addr_data *addr, + HardwareAddressToStringFlags flags, + char buffer[static HW_ADDR_TO_STRING_MAX]) { + assert(addr); assert(buffer); assert(addr->length <= HW_ADDR_MAX_SIZE); - for (size_t i = 0; i < addr->length; i++) { - sprintf(&buffer[3*i], "%02"PRIx8, addr->bytes[i]); - if (i < addr->length - 1) - buffer[3*i + 2] = ':'; + for (size_t i = 0, j = 0; i < addr->length; i++) { + buffer[j++] = hexchar(addr->bytes[i] >> 4); + buffer[j++] = hexchar(addr->bytes[i] & 0x0f); + if (!FLAGS_SET(flags, HW_ADDR_TO_STRING_NO_COLON)) + buffer[j++] = ':'; } + buffer[addr->length == 0 || FLAGS_SET(flags, HW_ADDR_TO_STRING_NO_COLON) ? + addr->length * 2 : + addr->length * 3 - 1] = '\0'; return buffer; } @@ -39,7 +48,7 @@ int hw_addr_compare(const struct hw_addr_data *a, const struct hw_addr_data *b) return memcmp(a->bytes, b->bytes, a->length); } -static void hw_addr_hash_func(const struct hw_addr_data *p, struct siphash *state) { +void hw_addr_hash_func(const struct hw_addr_data *p, struct siphash *state) { assert(p); assert(state); @@ -48,6 +57,7 @@ static void hw_addr_hash_func(const struct hw_addr_data *p, struct siphash *stat } DEFINE_HASH_OPS(hw_addr_hash_ops, struct hw_addr_data, hw_addr_hash_func, hw_addr_compare); +DEFINE_HASH_OPS_WITH_KEY_DESTRUCTOR(hw_addr_hash_ops_free, struct hw_addr_data, hw_addr_hash_func, hw_addr_compare, free); char* ether_addr_to_string(const struct ether_addr *addr, char buffer[ETHER_ADDR_TO_STRING_MAX]) { assert(addr); @@ -93,75 +103,163 @@ static void ether_addr_hash_func(const struct ether_addr *p, struct siphash *sta } DEFINE_HASH_OPS(ether_addr_hash_ops, struct ether_addr, ether_addr_hash_func, ether_addr_compare); +DEFINE_HASH_OPS_WITH_KEY_DESTRUCTOR(ether_addr_hash_ops_free, struct ether_addr, ether_addr_hash_func, ether_addr_compare, free); -int ether_addr_from_string(const char *s, struct ether_addr *ret) { - size_t pos = 0, n, field; - char sep = '\0'; - const char *hex = HEXDIGITS, *hexoff; - size_t x; - bool touched; - -#define parse_fields(v) \ - for (field = 0; field < ELEMENTSOF(v); field++) { \ - touched = false; \ - for (n = 0; n < (2 * sizeof(v[0])); n++) { \ - if (s[pos] == '\0') \ - break; \ - hexoff = strchr(hex, s[pos]); \ - if (!hexoff) \ - break; \ - assert(hexoff >= hex); \ - x = hexoff - hex; \ - if (x >= 16) \ - x -= 6; /* A-F */ \ - assert(x < 16); \ - touched = true; \ - v[field] <<= 4; \ - v[field] += x; \ - pos++; \ - } \ - if (!touched) \ - return -EINVAL; \ - if (field < (ELEMENTSOF(v)-1)) { \ - if (s[pos] != sep) \ - return -EINVAL; \ - else \ - pos++; \ - } \ - } +static int parse_hw_addr_one_field(const char **s, char sep, size_t len, uint8_t *buf) { + const char *hex = HEXDIGITS, *p; + uint16_t data = 0; + bool cont; assert(s); - assert(ret); + assert(*s); + assert(IN_SET(len, 1, 2)); + assert(buf); - s += strspn(s, WHITESPACE); - sep = s[strspn(s, hex)]; + p = *s; - if (sep == '.') { - uint16_t shorts[3] = { 0 }; + for (size_t i = 0; i < len * 2; i++) { + const char *hexoff; + size_t x; - parse_fields(shorts); + if (*p == '\0' || *p == sep) { + if (i == 0) + return -EINVAL; + break; + } - if (s[pos] != '\0') + hexoff = strchr(hex, *p); + if (!hexoff) return -EINVAL; - for (n = 0; n < ELEMENTSOF(shorts); n++) { - ret->ether_addr_octet[2*n] = ((shorts[n] & (uint16_t)0xff00) >> 8); - ret->ether_addr_octet[2*n + 1] = (shorts[n] & (uint16_t)0x00ff); + assert(hexoff >= hex); + x = hexoff - hex; + if (x >= 16) + x -= 6; /* A-F */ + + assert(x < 16); + data <<= 4; + data += x; + + p++; + } + + if (*p != '\0' && *p != sep) + return -EINVAL; + + switch (len) { + case 1: + buf[0] = data; + break; + case 2: + buf[0] = (data & 0xff00) >> 8; + buf[1] = data & 0xff; + break; + default: + assert_not_reached(); + } + + cont = *p == sep; + *s = p + cont; + return cont; +} + +int parse_hw_addr_full(const char *s, size_t expected_len, struct hw_addr_data *ret) { + size_t field_size, max_len, len = 0; + uint8_t bytes[HW_ADDR_MAX_SIZE]; + char sep; + int r; + + assert(s); + assert(expected_len <= HW_ADDR_MAX_SIZE || expected_len == SIZE_MAX); + assert(ret); + + /* This accepts the following formats: + * + * Dot separated 2 bytes format: xxyy.zzaa.bbcc + * Colon separated 1 bytes format: xx:yy:zz:aa:bb:cc + * Hyphen separated 1 bytes format: xx-yy-zz-aa-bb-cc + * + * Moreover, if expected_len == 0, 4, or 16, this also accepts: + * + * IPv4 format: used by IPv4 tunnel, e.g. ipgre + * IPv6 format: used by IPv6 tunnel, e.g. ip6gre + * + * The expected_len argument controls the length of acceptable addresses: + * + * 0: accepts 4 (AF_INET), 16 (AF_INET6), 6 (ETH_ALEN), or 20 (INFINIBAND_ALEN). + * SIZE_MAX: accepts arbitrary length, but at least one separator must be included. + * Otherwise: accepts addresses with matching length. + */ + + if (IN_SET(expected_len, 0, sizeof(struct in_addr), sizeof(struct in6_addr))) { + union in_addr_union a; + int family; + + if (expected_len == 0) + r = in_addr_from_string_auto(s, &family, &a); + else { + family = expected_len == sizeof(struct in_addr) ? AF_INET : AF_INET6; + r = in_addr_from_string(family, s, &a); + } + if (r >= 0) { + ret->length = FAMILY_ADDRESS_SIZE(family); + memcpy(ret->bytes, a.bytes, ret->length); + return 0; } + } - } else if (IN_SET(sep, ':', '-')) { - struct ether_addr out = ETHER_ADDR_NULL; + max_len = + expected_len == 0 ? INFINIBAND_ALEN : + expected_len == SIZE_MAX ? HW_ADDR_MAX_SIZE : expected_len; + sep = s[strspn(s, HEXDIGITS)]; - parse_fields(out.ether_addr_octet); + if (sep == '.') + field_size = 2; + else if (IN_SET(sep, ':', '-')) + field_size = 1; + else + return -EINVAL; - if (s[pos] != '\0') - return -EINVAL; + if (max_len % field_size != 0) + return -EINVAL; - for (n = 0; n < ELEMENTSOF(out.ether_addr_octet); n++) - ret->ether_addr_octet[n] = out.ether_addr_octet[n]; + for (size_t i = 0; i < max_len / field_size; i++) { + r = parse_hw_addr_one_field(&s, sep, field_size, bytes + i * field_size); + if (r < 0) + return r; + if (r == 0) { + len = (i + 1) * field_size; + break; + } + } - } else + if (len == 0) return -EINVAL; + if (expected_len == 0) { + if (!IN_SET(len, 4, 16, ETH_ALEN, INFINIBAND_ALEN)) + return -EINVAL; + } else if (expected_len != SIZE_MAX) { + if (len != expected_len) + return -EINVAL; + } + + ret->length = len; + memcpy(ret->bytes, bytes, ret->length); + return 0; +} + +int parse_ether_addr(const char *s, struct ether_addr *ret) { + struct hw_addr_data a; + int r; + + assert(s); + assert(ret); + + r = parse_hw_addr_full(s, ETH_ALEN, &a); + if (r < 0) + return r; + + *ret = a.ether; return 0; } diff --git a/src/libnm-systemd-shared/src/basic/ether-addr-util.h b/src/libnm-systemd-shared/src/basic/ether-addr-util.h index 794fc55b..32f45fe8 100644 --- a/src/libnm-systemd-shared/src/basic/ether-addr-util.h +++ b/src/libnm-systemd-shared/src/basic/ether-addr-util.h @@ -6,6 +6,9 @@ #include #include "hash-funcs.h" +#include "in-addr-util.h" +#include "macro.h" +#include "memory-util.h" /* This is MAX_ADDR_LEN as defined in linux/netdevice.h, but net/if_arp.h * defines a macro of the same name with a much lower size. */ @@ -16,29 +19,51 @@ struct hw_addr_data { union { struct ether_addr ether; uint8_t infiniband[INFINIBAND_ALEN]; + struct in_addr in; + struct in6_addr in6; uint8_t bytes[HW_ADDR_MAX_SIZE]; }; }; +int parse_hw_addr_full(const char *s, size_t expected_len, struct hw_addr_data *ret); +static inline int parse_hw_addr(const char *s, struct hw_addr_data *ret) { + return parse_hw_addr_full(s, 0, ret); +} +int parse_ether_addr(const char *s, struct ether_addr *ret); + +typedef enum HardwareAddressToStringFlags { + HW_ADDR_TO_STRING_NO_COLON = 1 << 0, +} HardwareAddressToStringFlags; + #define HW_ADDR_TO_STRING_MAX (3*HW_ADDR_MAX_SIZE) -char* hw_addr_to_string(const struct hw_addr_data *addr, char buffer[HW_ADDR_TO_STRING_MAX]); +char *hw_addr_to_string_full( + const struct hw_addr_data *addr, + HardwareAddressToStringFlags flags, + char buffer[static HW_ADDR_TO_STRING_MAX]); +static inline char *hw_addr_to_string(const struct hw_addr_data *addr, char buffer[static HW_ADDR_TO_STRING_MAX]) { + return hw_addr_to_string_full(addr, 0, buffer); +} /* Note: the lifetime of the compound literal is the immediately surrounding block, * see C11 §6.5.2.5, and * https://stackoverflow.com/questions/34880638/compound-literal-lifetime-and-if-blocks */ -#define HW_ADDR_TO_STR(hw_addr) hw_addr_to_string((hw_addr), (char[HW_ADDR_TO_STRING_MAX]){}) +#define HW_ADDR_TO_STR_FULL(hw_addr, flags) hw_addr_to_string_full((hw_addr), flags, (char[HW_ADDR_TO_STRING_MAX]){}) +#define HW_ADDR_TO_STR(hw_addr) HW_ADDR_TO_STR_FULL(hw_addr, 0) #define HW_ADDR_NULL ((const struct hw_addr_data){}) +void hw_addr_hash_func(const struct hw_addr_data *p, struct siphash *state); int hw_addr_compare(const struct hw_addr_data *a, const struct hw_addr_data *b); static inline bool hw_addr_equal(const struct hw_addr_data *a, const struct hw_addr_data *b) { return hw_addr_compare(a, b) == 0; } static inline bool hw_addr_is_null(const struct hw_addr_data *addr) { - return hw_addr_equal(addr, &HW_ADDR_NULL); + assert(addr); + return addr->length == 0 || memeqzero(addr->bytes, addr->length); } extern const struct hash_ops hw_addr_hash_ops; +extern const struct hash_ops hw_addr_hash_ops_free; #define ETHER_ADDR_FORMAT_STR "%02X%02X%02X%02X%02X%02X" #define ETHER_ADDR_FORMAT_VAL(x) (x).ether_addr_octet[0], (x).ether_addr_octet[1], (x).ether_addr_octet[2], (x).ether_addr_octet[3], (x).ether_addr_octet[4], (x).ether_addr_octet[5] @@ -60,6 +85,29 @@ static inline bool ether_addr_is_null(const struct ether_addr *addr) { return ether_addr_equal(addr, ÐER_ADDR_NULL); } -int ether_addr_from_string(const char *s, struct ether_addr *ret); +static inline bool ether_addr_is_broadcast(const struct ether_addr *addr) { + assert(addr); + return memeqbyte(0xff, addr->ether_addr_octet, ETH_ALEN); +} + +static inline bool ether_addr_is_multicast(const struct ether_addr *addr) { + assert(addr); + return FLAGS_SET(addr->ether_addr_octet[0], 0x01); +} + +static inline bool ether_addr_is_unicast(const struct ether_addr *addr) { + return !ether_addr_is_multicast(addr); +} + +static inline bool ether_addr_is_local(const struct ether_addr *addr) { + /* Determine if the Ethernet address is locally-assigned one (IEEE 802) */ + assert(addr); + return FLAGS_SET(addr->ether_addr_octet[0], 0x02); +} + +static inline bool ether_addr_is_global(const struct ether_addr *addr) { + return !ether_addr_is_local(addr); +} extern const struct hash_ops ether_addr_hash_ops; +extern const struct hash_ops ether_addr_hash_ops_free; diff --git a/src/libnm-systemd-shared/src/basic/fd-util.c b/src/libnm-systemd-shared/src/basic/fd-util.c index ee2a4caf..c3df68de 100644 --- a/src/libnm-systemd-shared/src/basic/fd-util.c +++ b/src/libnm-systemd-shared/src/basic/fd-util.c @@ -154,10 +154,7 @@ int fd_nonblock(int fd, bool nonblock) { if (nflags == flags) return 0; - if (fcntl(fd, F_SETFL, nflags) < 0) - return -errno; - - return 0; + return RET_NERRNO(fcntl(fd, F_SETFL, nflags)); } int fd_cloexec(int fd, bool cloexec) { @@ -173,10 +170,7 @@ int fd_cloexec(int fd, bool cloexec) { if (nflags == flags) return 0; - if (fcntl(fd, F_SETFD, nflags) < 0) - return -errno; - - return 0; + return RET_NERRNO(fcntl(fd, F_SETFD, nflags)); } #if 0 /* NM_IGNORED */ @@ -190,7 +184,7 @@ _pure_ static bool fd_in_set(int fd, const int fdset[], size_t n_fdset) { return false; } -static int get_max_fd(void) { +int get_max_fd(void) { struct rlimit rl; rlim_t m; @@ -211,37 +205,147 @@ static int get_max_fd(void) { return (int) (m - 1); } -int close_all_fds_full(int except[], size_t n_except, bool allow_alloc) { - static bool have_close_range = true; /* Assume we live in the future */ +static int close_all_fds_frugal(const int except[], size_t n_except) { + int max_fd, r = 0; + + assert(n_except == 0 || except); + + /* This is the inner fallback core of close_all_fds(). This never calls malloc() or opendir() or so + * and hence is safe to be called in signal handler context. Most users should call close_all_fds(), + * but when we assume we are called from signal handler context, then use this simpler call + * instead. */ + + max_fd = get_max_fd(); + if (max_fd < 0) + return max_fd; + + /* Refuse to do the loop over more too many elements. It's better to fail immediately than to + * spin the CPU for a long time. */ + if (max_fd > MAX_FD_LOOP_LIMIT) + return log_debug_errno(SYNTHETIC_ERRNO(EPERM), + "Refusing to loop over %d potential fds.", + max_fd); + + for (int fd = 3; fd >= 0; fd = fd < max_fd ? fd + 1 : -1) { + int q; + + if (fd_in_set(fd, except, n_except)) + continue; + + q = close_nointr(fd); + if (q < 0 && q != -EBADF && r >= 0) + r = q; + } + + return r; +} + +static bool have_close_range = true; /* Assume we live in the future */ + +static int close_all_fds_special_case(const int except[], size_t n_except) { + assert(n_except == 0 || except); + + /* Handles a few common special cases separately, since they are common and can be optimized really + * nicely, since we won't need sorting for them. Returns > 0 if the special casing worked, 0 + * otherwise. */ + + if (!have_close_range) + return 0; + + switch (n_except) { + + case 0: + /* Close everything. Yay! */ + + if (close_range(3, -1, 0) >= 0) + return 1; + + if (ERRNO_IS_NOT_SUPPORTED(errno) || ERRNO_IS_PRIVILEGE(errno)) { + have_close_range = false; + return 0; + } + + return -errno; + + case 1: + /* Close all but exactly one, then we don't need no sorting. This is a pretty common + * case, hence let's handle it specially. */ + + if ((except[0] <= 3 || close_range(3, except[0]-1, 0) >= 0) && + (except[0] >= INT_MAX || close_range(MAX(3, except[0]+1), -1, 0) >= 0)) + return 1; + + if (ERRNO_IS_NOT_SUPPORTED(errno) || ERRNO_IS_PRIVILEGE(errno)) { + have_close_range = false; + return 0; + } + + return -errno; + + default: + return 0; + } +} + +int close_all_fds_without_malloc(const int except[], size_t n_except) { + int r; + + assert(n_except == 0 || except); + + r = close_all_fds_special_case(except, n_except); + if (r < 0) + return r; + if (r > 0) /* special case worked! */ + return 0; + + return close_all_fds_frugal(except, n_except); +} + +int close_all_fds(const int except[], size_t n_except) { _cleanup_closedir_ DIR *d = NULL; int r = 0; assert(n_except == 0 || except); + r = close_all_fds_special_case(except, n_except); + if (r < 0) + return r; + if (r > 0) /* special case worked! */ + return 0; + if (have_close_range) { + _cleanup_free_ int *sorted_malloc = NULL; + size_t n_sorted; + int *sorted; + /* In the best case we have close_range() to close all fds between a start and an end fd, * which we can use on the "inverted" exception array, i.e. all intervals between all * adjacent pairs from the sorted exception array. This changes loop complexity from O(n) * where n is number of open fds to O(m⋅log(m)) where m is the number of fds to keep * open. Given that we assume n ≫ m that's preferable to us. */ - if (n_except == 0) { - /* Close everything. Yay! */ + assert(n_except < SIZE_MAX); + n_sorted = n_except + 1; - if (close_range(3, -1, 0) >= 0) - return 0; + if (n_sorted > 64) /* Use heap for large numbers of fds, stack otherwise */ + sorted = sorted_malloc = new(int, n_sorted); + else + sorted = newa(int, n_sorted); - if (ERRNO_IS_NOT_SUPPORTED(errno) || ERRNO_IS_PRIVILEGE(errno)) - have_close_range = false; - else - return -errno; + if (sorted) { + memcpy(sorted, except, n_except * sizeof(int)); - } else { - typesafe_qsort(except, n_except, cmp_int); + /* Let's add fd 2 to the list of fds, to simplify the loop below, as this + * allows us to cover the head of the array the same way as the body */ + sorted[n_sorted-1] = 2; - for (size_t i = 0; i < n_except; i++) { - int start = i == 0 ? 2 : MAX(except[i-1], 2); /* The first three fds shall always remain open */ - int end = MAX(except[i], 2); + typesafe_qsort(sorted, n_sorted, cmp_int); + + for (size_t i = 0; i < n_sorted-1; i++) { + int start, end; + + start = MAX(sorted[i], 2); /* The first three fds shall always remain open */ + end = MAX(sorted[i+1], 2); assert(end >= start); @@ -250,83 +354,58 @@ int close_all_fds_full(int except[], size_t n_except, bool allow_alloc) { /* Close everything between the start and end fds (both of which shall stay open) */ if (close_range(start + 1, end - 1, 0) < 0) { - if (ERRNO_IS_NOT_SUPPORTED(errno) || ERRNO_IS_PRIVILEGE(errno)) - have_close_range = false; - else + if (!ERRNO_IS_NOT_SUPPORTED(errno) && !ERRNO_IS_PRIVILEGE(errno)) return -errno; - goto opendir_fallback; + + have_close_range = false; + break; } } - /* The loop succeeded. Let's now close everything beyond the end */ + if (have_close_range) { + /* The loop succeeded. Let's now close everything beyond the end */ - if (except[n_except-1] >= INT_MAX) /* Don't let the addition below overflow */ - return 0; + if (sorted[n_sorted-1] >= INT_MAX) /* Dont let the addition below overflow */ + return 0; - int start = MAX(except[n_except-1], 2); + if (close_range(sorted[n_sorted-1] + 1, -1, 0) >= 0) + return 0; - if (close_range(start + 1, -1, 0) >= 0) - return 0; + if (!ERRNO_IS_NOT_SUPPORTED(errno) && !ERRNO_IS_PRIVILEGE(errno)) + return -errno; - if (ERRNO_IS_NOT_SUPPORTED(errno) || ERRNO_IS_PRIVILEGE(errno)) have_close_range = false; - else - return -errno; + } } - } - - /* Fallback for when close_range() is not supported */ - opendir_fallback: - d = allow_alloc ? opendir("/proc/self/fd") : NULL; - if (d) { - struct dirent *de; - - FOREACH_DIRENT(de, d, return -errno) { - int fd = -1, q; - - if (safe_atoi(de->d_name, &fd) < 0) - /* Let's better ignore this, just in case */ - continue; - if (fd < 3) - continue; - - if (fd == dirfd(d)) - continue; + /* Fallback on OOM or if close_range() is not supported */ + } - if (fd_in_set(fd, except, n_except)) - continue; + d = opendir("/proc/self/fd"); + if (!d) + return close_all_fds_frugal(except, n_except); /* ultimate fallback if /proc/ is not available */ - q = close_nointr(fd); - if (q < 0 && q != -EBADF && r >= 0) /* Valgrind has its own FD and doesn't want to have it closed */ - r = q; - } + FOREACH_DIRENT(de, d, return -errno) { + int fd = -1, q; - return r; - } - - /* Fallback for when /proc isn't available (for example in chroots) or when we cannot allocate by - * brute-forcing through the file descriptor table. */ + if (!IN_SET(de->d_type, DT_LNK, DT_UNKNOWN)) + continue; - int max_fd = get_max_fd(); - if (max_fd < 0) - return max_fd; + if (safe_atoi(de->d_name, &fd) < 0) + /* Let's better ignore this, just in case */ + continue; - /* Refuse to do the loop over more too many elements. It's better to fail immediately than to - * spin the CPU for a long time. */ - if (max_fd > MAX_FD_LOOP_LIMIT) - return log_debug_errno(SYNTHETIC_ERRNO(EPERM), - "/proc/self/fd is inaccessible. Refusing to loop over %d potential fds.", - max_fd); + if (fd < 3) + continue; - for (int fd = 3; fd >= 0; fd = fd < max_fd ? fd + 1 : -1) { - int q; + if (fd == dirfd(d)) + continue; if (fd_in_set(fd, except, n_except)) continue; q = close_nointr(fd); - if (q < 0 && q != -EBADF && r >= 0) + if (q < 0 && q != -EBADF && r >= 0) /* Valgrind has its own FD and doesn't want to have it closed */ r = q; } @@ -652,7 +731,7 @@ finish: } int fd_reopen(int fd, int flags) { - int new_fd; + int new_fd, r; /* Reopens the specified fd with new flags. This is useful for convert an O_PATH fd into a regular one, or to * turn O_RDWR fds into O_RDONLY fds. @@ -661,15 +740,28 @@ int fd_reopen(int fd, int flags) { * * This implicitly resets the file read index to 0. */ + if (FLAGS_SET(flags, O_DIRECTORY)) { + /* If we shall reopen the fd as directory we can just go via "." and thus bypass the whole + * magic /proc/ directory, and make ourselves independent of that being mounted. */ + new_fd = openat(fd, ".", flags); + if (new_fd < 0) + return -errno; + + return new_fd; + } + new_fd = open(FORMAT_PROC_FD_PATH(fd), flags); if (new_fd < 0) { if (errno != ENOENT) return -errno; - if (proc_mounted() == 0) + r = proc_mounted(); + if (r == 0) return -ENOSYS; /* if we have no /proc/, the concept is not implementable */ - return -ENOENT; + return r > 0 ? -EBADF : -ENOENT; /* If /proc/ is definitely around then this means the fd is + * not valid, otherwise let's propagate the original + * error */ } return new_fd; @@ -710,9 +802,6 @@ int btrfs_defrag_fd(int fd) { if (r < 0) return r; - if (ioctl(fd, BTRFS_IOC_DEFRAG, NULL) < 0) - return -errno; - - return 0; + return RET_NERRNO(ioctl(fd, BTRFS_IOC_DEFRAG, NULL)); } #endif /* NM_IGNORED */ diff --git a/src/libnm-systemd-shared/src/basic/fd-util.h b/src/libnm-systemd-shared/src/basic/fd-util.h index 2382d52d..f5cfcb4e 100644 --- a/src/libnm-systemd-shared/src/basic/fd-util.h +++ b/src/libnm-systemd-shared/src/basic/fd-util.h @@ -57,10 +57,10 @@ DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(DIR*, closedir, NULL); int fd_nonblock(int fd, bool nonblock); int fd_cloexec(int fd, bool cloexec); -int close_all_fds_full(int except[], size_t n_except, bool allow_alloc); -static inline int close_all_fds(int except[], size_t n_except) { - return close_all_fds_full(except, n_except, true); -} +int get_max_fd(void); + +int close_all_fds(const int except[], size_t n_except); +int close_all_fds_without_malloc(const int except[], size_t n_except); int same_fd(int a, int b); @@ -91,9 +91,10 @@ static inline int make_null_stdio(void) { /* Like TAKE_PTR() but for file descriptors, resetting them to -1 */ #define TAKE_FD(fd) \ ({ \ - int _fd_ = (fd); \ - (fd) = -1; \ - _fd_; \ + int *_fd_ = &(fd); \ + int _ret_ = *_fd_; \ + *_fd_ = -1; \ + _ret_; \ }) /* Like free_and_replace(), but for file descriptors */ diff --git a/src/libnm-systemd-shared/src/basic/fileio.c b/src/libnm-systemd-shared/src/basic/fileio.c index 322638a2..c66bc67b 100644 --- a/src/libnm-systemd-shared/src/basic/fileio.c +++ b/src/libnm-systemd-shared/src/basic/fileio.c @@ -169,7 +169,7 @@ int write_string_stream_ts( * it won't be equal to the new value. */ if (read_virtual_file_fd(fd, strlen(line)+1, &t, NULL) > 0 && streq_skip_trailing_chars(line, t, NEWLINE)) { - log_debug("No change in value '%s', supressing write", line); + log_debug("No change in value '%s', suppressing write", line); return 0; } @@ -551,12 +551,25 @@ int read_virtual_file_fd(int fd, size_t max_size, char **ret_contents, size_t *r return !truncated; } -int read_virtual_file(const char *filename, size_t max_size, char **ret_contents, size_t *ret_size) { +int read_virtual_file_at( + int dir_fd, + const char *filename, + size_t max_size, + char **ret_contents, + size_t *ret_size) { + _cleanup_close_ int fd = -1; - assert(filename); + assert(dir_fd >= 0 || dir_fd == AT_FDCWD); - fd = open(filename, O_RDONLY | O_NOCTTY | O_CLOEXEC); + if (!filename) { + if (dir_fd == AT_FDCWD) + return -EBADF; + + return read_virtual_file_fd(dir_fd, max_size, ret_contents, ret_size); + } + + fd = openat(dir_fd, filename, O_RDONLY | O_NOCTTY | O_CLOEXEC); if (fd < 0) return -errno; @@ -934,6 +947,9 @@ DIR *xopendirat(int fd, const char *name, int flags) { assert(!(flags & O_CREAT)); + if (fd == AT_FDCWD && flags == 0) + return opendir(name); + nfd = openat(fd, name, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|flags, 0); if (nfd < 0) return NULL; diff --git a/src/libnm-systemd-shared/src/basic/fileio.h b/src/libnm-systemd-shared/src/basic/fileio.h index 899def94..cea3dd89 100644 --- a/src/libnm-systemd-shared/src/basic/fileio.h +++ b/src/libnm-systemd-shared/src/basic/fileio.h @@ -69,7 +69,10 @@ static inline int read_full_file(const char *filename, char **ret_contents, size } int read_virtual_file_fd(int fd, size_t max_size, char **ret_contents, size_t *ret_size); -int read_virtual_file(const char *filename, size_t max_size, char **ret_contents, size_t *ret_size); +int read_virtual_file_at(int dir_fd, const char *filename, size_t max_size, char **ret_contents, size_t *ret_size); +static inline int read_virtual_file(const char *filename, size_t max_size, char **ret_contents, size_t *ret_size) { + return read_virtual_file_at(AT_FDCWD, filename, max_size, ret_contents, ret_size); +} static inline int read_full_virtual_file(const char *filename, char **ret_contents, size_t *ret_size) { return read_virtual_file(filename, SIZE_MAX, ret_contents, ret_size); } diff --git a/src/libnm-systemd-shared/src/basic/format-util.h b/src/libnm-systemd-shared/src/basic/format-util.h index 7dd422b9..7db8b61d 100644 --- a/src/libnm-systemd-shared/src/basic/format-util.h +++ b/src/libnm-systemd-shared/src/basic/format-util.h @@ -26,11 +26,15 @@ assert_cc(sizeof(gid_t) == sizeof(uint32_t)); # error Unknown time_t size #endif -#if defined __x86_64__ && defined __ILP32__ +#if 0 /* NM_IGNORED */ +#if SIZEOF_TIMEX_MEMBER == 8 # define PRI_TIMEX PRIi64 -#else +#elif SIZEOF_TIMEX_MEMBER == 4 # define PRI_TIMEX "li" +#else +# error Unknown timex member size #endif +#endif /* NM_IGNORED */ #if SIZEOF_RLIM_T == 8 # define RLIM_FMT "%" PRIu64 diff --git a/src/libnm-systemd-shared/src/basic/fs-util.c b/src/libnm-systemd-shared/src/basic/fs-util.c index 3f309868..b524a6fd 100644 --- a/src/libnm-systemd-shared/src/basic/fs-util.c +++ b/src/libnm-systemd-shared/src/basic/fs-util.c @@ -14,6 +14,7 @@ #include "fd-util.h" #include "fileio.h" #include "fs-util.h" +#include "hostname-util.h" #include "log.h" #include "macro.h" #include "missing_fcntl.h" @@ -31,18 +32,13 @@ #include "strv.h" #include "time-util.h" #include "tmpfile-util.h" +#include "umask-util.h" #include "user-util.h" #include "util.h" int unlink_noerrno(const char *path) { PROTECT_ERRNO; - int r; - - r = unlink(path); - if (r < 0) - return -errno; - - return 0; + return RET_NERRNO(unlink(path)); } #if 0 /* NM_IGNORED */ @@ -59,7 +55,7 @@ int rmdir_parents(const char *path, const char *stop) { if (!path_is_safe(stop)) return -EINVAL; - p = strdupa(path); + p = strdupa_safe(path); for (;;) { char *slash = NULL; @@ -99,8 +95,8 @@ int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char * want — though not atomic (i.e. for a short period both the new and the old filename will exist). */ if (linkat(olddirfd, oldpath, newdirfd, newpath, 0) >= 0) { - if (unlinkat(olddirfd, oldpath, 0) < 0) { - r = -errno; /* Backup errno before the following unlinkat() alters it */ + r = RET_NERRNO(unlinkat(olddirfd, oldpath, 0)); + if (r < 0) { (void) unlinkat(newdirfd, newpath, 0); return r; } @@ -119,10 +115,7 @@ int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char if (errno != ENOENT) return -errno; - if (renameat(olddirfd, oldpath, newdirfd, newpath) < 0) - return -errno; - - return 0; + return RET_NERRNO(renameat(olddirfd, oldpath, newdirfd, newpath)); } #endif /* NM_IGNORED */ @@ -290,14 +283,9 @@ int fchmod_and_chown_with_fallback(int fd, const char *path, mode_t mode, uid_t } int fchmod_umask(int fd, mode_t m) { - mode_t u; - int r; - - u = umask(0777); - r = fchmod(fd, m & (~u)) < 0 ? -errno : 0; - umask(u); + _cleanup_umask_ mode_t u = umask(0777); - return r; + return RET_NERRNO(fchmod(fd, m & (~u))); } int fchmod_opath(int fd, mode_t m) { @@ -550,7 +538,6 @@ int mkfifoat_atomic(int dirfd, const char *path, mode_t mode) { int get_files_in_directory(const char *path, char ***list) { _cleanup_strv_free_ char **l = NULL; _cleanup_closedir_ DIR *d = NULL; - struct dirent *de; size_t n = 0; assert(path); @@ -830,7 +817,7 @@ int unlinkat_deallocate(int fd, const char *name, UnlinkDeallocateFlags flags) { int open_parent(const char *path, int flags, mode_t mode) { _cleanup_free_ char *parent = NULL; - int fd, r; + int r; r = path_extract_directory(path, &parent); if (r < 0) @@ -844,11 +831,7 @@ int open_parent(const char *path, int flags, mode_t mode) { else if (!FLAGS_SET(flags, O_TMPFILE)) flags |= O_DIRECTORY|O_RDONLY; - fd = open(parent, flags, mode); - if (fd < 0) - return -errno; - - return fd; + return RET_NERRNO(open(parent, flags, mode)); } #endif /* NM_IGNORED */ @@ -962,3 +945,152 @@ int posix_fallocate_loop(int fd, uint64_t offset, uint64_t size) { return -EINTR; } + +int parse_cifs_service( + const char *s, + char **ret_host, + char **ret_service, + char **ret_path) { + + _cleanup_free_ char *h = NULL, *ss = NULL, *x = NULL; + const char *p, *e, *d; + char delimiter; + + /* Parses a CIFS service in form of //host/service/path… and splitting it in three parts. The last + * part is optional, in which case NULL is returned there. To maximize compatibility syntax with + * backslashes instead of slashes is accepted too. */ + + if (!s) + return -EINVAL; + + p = startswith(s, "//"); + if (!p) { + p = startswith(s, "\\\\"); + if (!p) + return -EINVAL; + } + + delimiter = s[0]; + e = strchr(p, delimiter); + if (!e) + return -EINVAL; + + h = strndup(p, e - p); + if (!h) + return -ENOMEM; + + if (!hostname_is_valid(h, 0)) + return -EINVAL; + + e++; + + d = strchrnul(e, delimiter); + + ss = strndup(e, d - e); + if (!ss) + return -ENOMEM; + + if (!filename_is_valid(ss)) + return -EINVAL; + + if (!isempty(d)) { + x = strdup(skip_leading_chars(d, CHAR_TO_STR(delimiter))); + if (!x) + return -EINVAL; + + /* Make sure to convert Windows-style "\" → Unix-style / */ + for (char *i = x; *i; i++) + if (*i == delimiter) + *i = '/'; + + if (!path_is_valid(x)) + return -EINVAL; + + path_simplify(x); + if (!path_is_normalized(x)) + return -EINVAL; + } + + if (ret_host) + *ret_host = TAKE_PTR(h); + if (ret_service) + *ret_service = TAKE_PTR(ss); + if (ret_path) + *ret_path = TAKE_PTR(x); + + return 0; +} + +int open_mkdir_at(int dirfd, const char *path, int flags, mode_t mode) { + _cleanup_close_ int fd = -1, parent_fd = -1; + _cleanup_free_ char *fname = NULL; + bool made; + int r; + + /* Creates a directory with mkdirat() and then opens it, in the "most atomic" fashion we can + * do. Guarantees that the returned fd refers to a directory. If O_EXCL is specified will fail if the + * dir already exists. Otherwise will open an existing dir, but only if it is one. */ + + if (flags & ~(O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_EXCL|O_NOATIME|O_NOFOLLOW|O_PATH)) + return -EINVAL; + if ((flags & O_ACCMODE) != O_RDONLY) + return -EINVAL; + + /* Note that O_DIRECTORY|O_NOFOLLOW is implied, but we allow specifying it anyway. The following + * flags actually make sense to specify: O_CLOEXEC, O_EXCL, O_NOATIME, O_PATH */ + + if (isempty(path)) + return -EINVAL; + + if (!filename_is_valid(path)) { + _cleanup_free_ char *parent = NULL; + + /* If this is not a valid filename, it's a path. Let's open the parent directory then, so + * that we can pin it, and operate below it. */ + + r = path_extract_directory(path, &parent); + if (r < 0) + return r; + + r = path_extract_filename(path, &fname); + if (r < 0) + return r; + + parent_fd = openat(dirfd, parent, O_PATH|O_DIRECTORY|O_CLOEXEC); + if (parent_fd < 0) + return -errno; + + dirfd = parent_fd; + path = fname; + } + + r = RET_NERRNO(mkdirat(dirfd, path, mode)); + if (r == -EEXIST) { + if (FLAGS_SET(flags, O_EXCL)) + return -EEXIST; + + made = false; + } else if (r < 0) + return r; + else + made = true; + + fd = RET_NERRNO(openat(dirfd, path, (flags & ~O_EXCL)|O_DIRECTORY|O_NOFOLLOW)); + if (fd < 0) { + if (fd == -ENOENT) /* We got ENOENT? then someone else immediately removed it after we + * created it. In that case let's return immediately without unlinking + * anything, because there simply isn't anything to unlink anymore. */ + return -ENOENT; + if (fd == -ELOOP) /* is a symlink? exists already → created by someone else, don't unlink */ + return -EEXIST; + if (fd == -ENOTDIR) /* not a directory? exists already → created by someone else, don't unlink */ + return -EEXIST; + + if (made) + (void) unlinkat(dirfd, path, AT_REMOVEDIR); + + return fd; + } + + return TAKE_FD(fd); +} diff --git a/src/libnm-systemd-shared/src/basic/fs-util.h b/src/libnm-systemd-shared/src/basic/fs-util.h index f8a7657a..0bbb3f62 100644 --- a/src/libnm-systemd-shared/src/basic/fs-util.h +++ b/src/libnm-systemd-shared/src/basic/fs-util.h @@ -47,7 +47,7 @@ int fd_warn_permissions(const char *path, int fd); int stat_warn_permissions(const char *path, const struct stat *st); #define laccess(path, mode) \ - (faccessat(AT_FDCWD, (path), (mode), AT_SYMLINK_NOFOLLOW) < 0 ? -errno : 0) + RET_NERRNO(faccessat(AT_FDCWD, (path), (mode), AT_SYMLINK_NOFOLLOW)) int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gid, mode_t mode); int touch(const char *path); @@ -106,3 +106,7 @@ static inline int conservative_rename(const char *oldpath, const char *newpath) } int posix_fallocate_loop(int fd, uint64_t offset, uint64_t size); + +int parse_cifs_service(const char *s, char **ret_host, char **ret_service, char **ret_path); + +int open_mkdir_at(int dirfd, const char *path, int flags, mode_t mode); diff --git a/src/libnm-systemd-shared/src/basic/hostname-util.c b/src/libnm-systemd-shared/src/basic/hostname-util.c index 3063cc7c..1d1c2f51 100644 --- a/src/libnm-systemd-shared/src/basic/hostname-util.c +++ b/src/libnm-systemd-shared/src/basic/hostname-util.c @@ -49,8 +49,7 @@ int gethostname_full(GetHostnameFlags flags, char **ret) { assert_se(uname(&u) >= 0); s = u.nodename; - if (isempty(s) || - (!FLAGS_SET(flags, GET_HOSTNAME_ALLOW_NONE) && streq(s, "(none)")) || + if (isempty(s) || streq(s, "(none)") || (!FLAGS_SET(flags, GET_HOSTNAME_ALLOW_LOCALHOST) && is_localhost(s)) || (FLAGS_SET(flags, GET_HOSTNAME_SHORT) && s[0] == '.')) { if (!FLAGS_SET(flags, GET_HOSTNAME_FALLBACK_DEFAULT)) diff --git a/src/libnm-systemd-shared/src/basic/hostname-util.h b/src/libnm-systemd-shared/src/basic/hostname-util.h index 0d1574db..d435bed5 100644 --- a/src/libnm-systemd-shared/src/basic/hostname-util.h +++ b/src/libnm-systemd-shared/src/basic/hostname-util.h @@ -9,10 +9,9 @@ #include "strv.h" typedef enum GetHostnameFlags { - GET_HOSTNAME_ALLOW_NONE = 1 << 0, /* accepts "(none)". */ - GET_HOSTNAME_ALLOW_LOCALHOST = 1 << 1, /* accepts "localhost" or friends. */ - GET_HOSTNAME_FALLBACK_DEFAULT = 1 << 2, /* use default hostname if no hostname is set. */ - GET_HOSTNAME_SHORT = 1 << 3, /* kills the FQDN part if present. */ + GET_HOSTNAME_ALLOW_LOCALHOST = 1 << 0, /* accepts "localhost" or friends. */ + GET_HOSTNAME_FALLBACK_DEFAULT = 1 << 1, /* use default hostname if no hostname is set. */ + GET_HOSTNAME_SHORT = 1 << 2, /* kills the FQDN part if present. */ } GetHostnameFlags; int gethostname_full(GetHostnameFlags flags, char **ret); diff --git a/src/libnm-systemd-shared/src/basic/in-addr-util.c b/src/libnm-systemd-shared/src/basic/in-addr-util.c index bd4dd8fc..1bf0764d 100644 --- a/src/libnm-systemd-shared/src/basic/in-addr-util.c +++ b/src/libnm-systemd-shared/src/basic/in-addr-util.c @@ -629,65 +629,120 @@ int in4_addr_default_subnet_mask(const struct in_addr *addr, struct in_addr *mas return 0; } -#if 0 /* NM_IGNORED */ -int in_addr_mask(int family, union in_addr_union *addr, unsigned char prefixlen) { +int in4_addr_mask(struct in_addr *addr, unsigned char prefixlen) { + struct in_addr mask; + assert(addr); - if (family == AF_INET) { - struct in_addr mask; + if (!in4_addr_prefixlen_to_netmask(&mask, prefixlen)) + return -EINVAL; - if (!in4_addr_prefixlen_to_netmask(&mask, prefixlen)) - return -EINVAL; + addr->s_addr &= mask.s_addr; + return 0; +} - addr->in.s_addr &= mask.s_addr; - return 0; - } +int in6_addr_mask(struct in6_addr *addr, unsigned char prefixlen) { + unsigned i; - if (family == AF_INET6) { - unsigned i; + for (i = 0; i < 16; i++) { + uint8_t mask; - for (i = 0; i < 16; i++) { - uint8_t mask; + if (prefixlen >= 8) { + mask = 0xFF; + prefixlen -= 8; + } else if (prefixlen > 0) { + mask = 0xFF << (8 - prefixlen); + prefixlen = 0; + } else { + assert(prefixlen == 0); + mask = 0; + } - if (prefixlen >= 8) { - mask = 0xFF; - prefixlen -= 8; - } else { - mask = 0xFF << (8 - prefixlen); - prefixlen = 0; - } + addr->s6_addr[i] &= mask; + } - addr->in6.s6_addr[i] &= mask; - } + return 0; +} - return 0; +#if 0 /* NM_IGNORED */ +int in_addr_mask(int family, union in_addr_union *addr, unsigned char prefixlen) { + assert(addr); + + switch (family) { + case AF_INET: + return in4_addr_mask(&addr->in, prefixlen); + case AF_INET6: + return in6_addr_mask(&addr->in6, prefixlen); + default: + return -EAFNOSUPPORT; } +} - return -EAFNOSUPPORT; +int in4_addr_prefix_covers( + const struct in_addr *prefix, + unsigned char prefixlen, + const struct in_addr *address) { + + struct in_addr masked_prefix, masked_address; + int r; + + assert(prefix); + assert(address); + + masked_prefix = *prefix; + r = in4_addr_mask(&masked_prefix, prefixlen); + if (r < 0) + return r; + + masked_address = *address; + r = in4_addr_mask(&masked_address, prefixlen); + if (r < 0) + return r; + + return in4_addr_equal(&masked_prefix, &masked_address); } -int in_addr_prefix_covers(int family, - const union in_addr_union *prefix, - unsigned char prefixlen, - const union in_addr_union *address) { +int in6_addr_prefix_covers( + const struct in6_addr *prefix, + unsigned char prefixlen, + const struct in6_addr *address) { - union in_addr_union masked_prefix, masked_address; + struct in6_addr masked_prefix, masked_address; int r; assert(prefix); assert(address); masked_prefix = *prefix; - r = in_addr_mask(family, &masked_prefix, prefixlen); + r = in6_addr_mask(&masked_prefix, prefixlen); if (r < 0) return r; masked_address = *address; - r = in_addr_mask(family, &masked_address, prefixlen); + r = in6_addr_mask(&masked_address, prefixlen); if (r < 0) return r; - return in_addr_equal(family, &masked_prefix, &masked_address); + return in6_addr_equal(&masked_prefix, &masked_address); +} + +int in_addr_prefix_covers( + int family, + const union in_addr_union *prefix, + unsigned char prefixlen, + const union in_addr_union *address) { + + assert(prefix); + assert(address); + + switch (family) { + case AF_INET: + return in4_addr_prefix_covers(&prefix->in, prefixlen, &address->in); + case AF_INET6: + return in6_addr_prefix_covers(&prefix->in6, prefixlen, &address->in6); + default: + return -EAFNOSUPPORT; + } } int in_addr_parse_prefixlen(int family, const char *p, unsigned char *ret) { @@ -855,4 +910,10 @@ int in6_addr_compare_func(const struct in6_addr *a, const struct in6_addr *b) { } DEFINE_HASH_OPS(in6_addr_hash_ops, struct in6_addr, in6_addr_hash_func, in6_addr_compare_func); +DEFINE_HASH_OPS_WITH_KEY_DESTRUCTOR( + in6_addr_hash_ops_free, + struct in6_addr, + in6_addr_hash_func, + in6_addr_compare_func, + free); #endif /* NM_IGNORED */ diff --git a/src/libnm-systemd-shared/src/basic/in-addr-util.h b/src/libnm-systemd-shared/src/basic/in-addr-util.h index c74b0d51..0178391e 100644 --- a/src/libnm-systemd-shared/src/basic/in-addr-util.h +++ b/src/libnm-systemd-shared/src/basic/in-addr-util.h @@ -89,7 +89,11 @@ unsigned char in4_addr_netmask_to_prefixlen(const struct in_addr *addr); struct in_addr* in4_addr_prefixlen_to_netmask(struct in_addr *addr, unsigned char prefixlen); int in4_addr_default_prefixlen(const struct in_addr *addr, unsigned char *prefixlen); int in4_addr_default_subnet_mask(const struct in_addr *addr, struct in_addr *mask); +int in4_addr_mask(struct in_addr *addr, unsigned char prefixlen); +int in6_addr_mask(struct in6_addr *addr, unsigned char prefixlen); int in_addr_mask(int family, union in_addr_union *addr, unsigned char prefixlen); +int in4_addr_prefix_covers(const struct in_addr *prefix, unsigned char prefixlen, const struct in_addr *address); +int in6_addr_prefix_covers(const struct in6_addr *prefix, unsigned char prefixlen, const struct in6_addr *address); int in_addr_prefix_covers(int family, const union in_addr_union *prefix, unsigned char prefixlen, const union in_addr_union *address); int in_addr_parse_prefixlen(int family, const char *p, unsigned char *ret); int in_addr_prefix_from_string(const char *p, int family, union in_addr_union *ret_prefix, unsigned char *ret_prefixlen); @@ -110,6 +114,13 @@ static inline size_t FAMILY_ADDRESS_SIZE(int family) { return family == AF_INET6 ? 16 : 4; } +#define FAMILY_ADDRESS_SIZE_SAFE(f) \ + ({ \ + int _f = (f); \ + _f == AF_INET ? sizeof(struct in_addr) : \ + _f == AF_INET6 ? sizeof(struct in6_addr) : 0; \ + }) + /* Workaround for clang, explicitly specify the maximum-size element here. * See also oss-fuzz#11344. */ #define IN_ADDR_NULL ((union in_addr_union) { .in6 = {} }) @@ -119,6 +130,7 @@ int in6_addr_compare_func(const struct in6_addr *a, const struct in6_addr *b); extern const struct hash_ops in_addr_data_hash_ops; extern const struct hash_ops in6_addr_hash_ops; +extern const struct hash_ops in6_addr_hash_ops_free; #define IPV4_ADDRESS_FMT_STR "%u.%u.%u.%u" #define IPV4_ADDRESS_FMT_VAL(address) \ diff --git a/src/libnm-systemd-shared/src/basic/inotify-util.c b/src/libnm-systemd-shared/src/basic/inotify-util.c index cc2a92ad..59e03e62 100644 --- a/src/libnm-systemd-shared/src/basic/inotify-util.c +++ b/src/libnm-systemd-shared/src/basic/inotify-util.c @@ -4,14 +4,26 @@ #include "fd-util.h" #include "inotify-util.h" +#include "stat-util.h" int inotify_add_watch_fd(int fd, int what, uint32_t mask) { - int wd; + int wd, r; /* This is like inotify_add_watch(), except that the file to watch is not referenced by a path, but by an fd */ wd = inotify_add_watch(fd, FORMAT_PROC_FD_PATH(what), mask); - if (wd < 0) - return -errno; + if (wd < 0) { + if (errno != ENOENT) + return -errno; + + /* Didn't work with ENOENT? If so, then either /proc/ isn't mounted, or the fd is bad */ + r = proc_mounted(); + if (r == 0) + return -ENOSYS; + if (r > 0) + return -EBADF; + + return -ENOENT; /* OK, no clue, let's propagate the original error */ + } return wd; } diff --git a/src/libnm-systemd-shared/src/basic/list.h b/src/libnm-systemd-shared/src/basic/list.h index e488fff9..f827e721 100644 --- a/src/libnm-systemd-shared/src/basic/list.h +++ b/src/libnm-systemd-shared/src/basic/list.h @@ -134,7 +134,7 @@ } while (false) #define LIST_JUST_US(name,item) \ - (!(item)->name##_prev && !(item)->name##_next) \ + (!(item)->name##_prev && !(item)->name##_next) #define LIST_FOREACH(name,i,head) \ for ((i) = (head); (i); (i) = (i)->name##_next) @@ -181,3 +181,12 @@ } \ (b) = NULL; \ } while (false) + +#define LIST_POP(name, a) \ + ({ \ + typeof(a)* _a = &(a); \ + typeof(a) _p = *_a; \ + if (_p) \ + LIST_REMOVE(name, *_a, _p); \ + _p; \ + }) diff --git a/src/libnm-systemd-shared/src/basic/log.h b/src/libnm-systemd-shared/src/basic/log.h index b11eac21..88d278fd 100644 --- a/src/libnm-systemd-shared/src/basic/log.h +++ b/src/libnm-systemd-shared/src/basic/log.h @@ -27,10 +27,14 @@ typedef enum LogTarget{ _LOG_TARGET_INVALID = -EINVAL, } LogTarget; -/* Note to readers: << and >> have lower precedence than & and | */ +/* This log level disables logging completely. It can only be passed to log_set_max_level() and cannot be + * used a regular log level. */ +#define LOG_NULL (LOG_EMERG - 1) + +/* Note to readers: << and >> have lower precedence (are evaluated earlier) than & and | */ #define SYNTHETIC_ERRNO(num) (1 << 30 | (num)) #define IS_SYNTHETIC_ERRNO(val) ((val) >> 30 & 1) -#define ERRNO_VALUE(val) (abs(val) & 255) +#define ERRNO_VALUE(val) (abs(val) & ~(1 << 30)) /* The callback function to be invoked when syntax warnings are seen * in the unit files. */ @@ -90,6 +94,7 @@ int log_open(void); void log_close(void); void log_forget_fds(void); +void log_parse_environment_variables(void); void log_parse_environment(void); #if 0 /* NM_IGNORED */ diff --git a/src/libnm-systemd-shared/src/basic/macro.h b/src/libnm-systemd-shared/src/basic/macro.h index 33d28332..79437775 100644 --- a/src/libnm-systemd-shared/src/basic/macro.h +++ b/src/libnm-systemd-shared/src/basic/macro.h @@ -25,7 +25,7 @@ #define _public_ __attribute__((__visibility__("default"))) #define _hidden_ __attribute__((__visibility__("hidden"))) #define _weakref_(x) __attribute__((__weakref__(#x))) -#define _alignas_(x) __attribute__((__aligned__(__alignof(x)))) +#define _alignas_(x) __attribute__((__aligned__(__alignof__(x)))) #define _alignptr_ __attribute__((__aligned__(sizeof(void*)))) #define _warn_unused_result_ __attribute__((__warn_unused_result__)) @@ -154,24 +154,6 @@ #define ALIGN4_PTR(p) ((void*) ALIGN4((unsigned long) (p))) #define ALIGN8_PTR(p) ((void*) ALIGN8((unsigned long) (p))) -static inline size_t ALIGN_TO(size_t l, size_t ali) { - /* Check that alignment is exponent of 2 */ -#if SIZE_MAX == UINT_MAX - assert(__builtin_popcount(ali) == 1); -#elif SIZE_MAX == ULONG_MAX - assert(__builtin_popcountl(ali) == 1); -#elif SIZE_MAX == ULLONG_MAX - assert(__builtin_popcountll(ali) == 1); -#else -#error "Unexpected size_t" -#endif - - if (l > SIZE_MAX - (ali - 1)) - return SIZE_MAX; /* indicate overflow */ - - return ((l + ali - 1) & ~(ali - 1)); -} - #define ALIGN_TO_PTR(p, ali) ((void*) ALIGN_TO((unsigned long) (p), (ali))) /* align to next higher power-of-2 (except for: 0 => 0, overflow => 0) */ @@ -355,13 +337,6 @@ static inline int __coverity_check_and_return__(int condition) { ans; \ }) -#define UPDATE_FLAG(orig, flag, b) \ - ((b) ? ((orig) | (flag)) : ((orig) & ~(flag))) -#define SET_FLAG(v, flag, b) \ - (v) = UPDATE_FLAG(v, flag, b) -#define FLAGS_SET(v, flags) \ - ((~(v) & (flags)) == 0) - #define SWAP_TWO(x, y) do { \ typeof(x) _t = (x); \ (x) = (y); \ diff --git a/src/libnm-systemd-shared/src/basic/missing_syscall.h b/src/libnm-systemd-shared/src/basic/missing_syscall.h index aeb994f0..41c83ec5 100644 --- a/src/libnm-systemd-shared/src/basic/missing_syscall.h +++ b/src/libnm-systemd-shared/src/basic/missing_syscall.h @@ -20,6 +20,7 @@ #include #endif +#include "macro.h" #include "missing_keyctl.h" #include "missing_stat.h" #include "missing_syscall_def.h" @@ -79,7 +80,8 @@ static inline int missing_memfd_create(const char *name, unsigned int flags) { /* ======================================================================= */ #if !HAVE_GETRANDOM -static inline int missing_getrandom(void *buffer, size_t count, unsigned flags) { +/* glibc says getrandom() returns ssize_t */ +static inline ssize_t missing_getrandom(void *buffer, size_t count, unsigned flags) { # ifdef __NR_getrandom return syscall(__NR_getrandom, buffer, count, flags); # else @@ -466,8 +468,52 @@ struct mount_attr { struct mount_attr; #endif +#ifndef MOUNT_ATTR_RDONLY +#define MOUNT_ATTR_RDONLY 0x00000001 /* Mount read-only */ +#endif + +#ifndef MOUNT_ATTR_NOSUID +#define MOUNT_ATTR_NOSUID 0x00000002 /* Ignore suid and sgid bits */ +#endif + +#ifndef MOUNT_ATTR_NODEV +#define MOUNT_ATTR_NODEV 0x00000004 /* Disallow access to device special files */ +#endif + +#ifndef MOUNT_ATTR_NOEXEC +#define MOUNT_ATTR_NOEXEC 0x00000008 /* Disallow program execution */ +#endif + +#ifndef MOUNT_ATTR__ATIME +#define MOUNT_ATTR__ATIME 0x00000070 /* Setting on how atime should be updated */ +#endif + +#ifndef MOUNT_ATTR_RELATIME +#define MOUNT_ATTR_RELATIME 0x00000000 /* - Update atime relative to mtime/ctime. */ +#endif + +#ifndef MOUNT_ATTR_NOATIME +#define MOUNT_ATTR_NOATIME 0x00000010 /* - Do not update access times. */ +#endif + +#ifndef MOUNT_ATTR_STRICTATIME +#define MOUNT_ATTR_STRICTATIME 0x00000020 /* - Always perform atime updates */ +#endif + +#ifndef MOUNT_ATTR_NODIRATIME +#define MOUNT_ATTR_NODIRATIME 0x00000080 /* Do not update directory access times */ +#endif + #ifndef MOUNT_ATTR_IDMAP -#define MOUNT_ATTR_IDMAP 0x00100000 +#define MOUNT_ATTR_IDMAP 0x00100000 /* Idmap mount to @userns_fd in struct mount_attr. */ +#endif + +#ifndef MOUNT_ATTR_NOSYMFOLLOW +#define MOUNT_ATTR_NOSYMFOLLOW 0x00200000 /* Do not follow symlinks */ +#endif + +#ifndef MOUNT_ATTR_SIZE_VER0 +#define MOUNT_ATTR_SIZE_VER0 32 /* sizeof first published struct */ #endif #ifndef AT_RECURSIVE @@ -545,4 +591,20 @@ static inline int missing_move_mount( # define move_mount missing_move_mount #endif + +/* ======================================================================= */ + +#if !HAVE_GETDENTS64 + +static inline ssize_t missing_getdents64(int fd, void *buffer, size_t length) { +# if defined __NR_getdents64 && __NR_getdents64 >= 0 + return syscall(__NR_getdents64, fd, buffer, length); +# else + errno = ENOSYS; + return -1; +# endif +} + +# define getdents64 missing_getdents64 +#endif #endif /* NM_IGNORED */ diff --git a/src/libnm-systemd-shared/src/basic/parse-util.c b/src/libnm-systemd-shared/src/basic/parse-util.c index f81bf1da..4ba2657c 100644 --- a/src/libnm-systemd-shared/src/basic/parse-util.c +++ b/src/libnm-systemd-shared/src/basic/parse-util.c @@ -651,7 +651,7 @@ int parse_ip_port(const char *s, uint16_t *ret) { uint16_t l; int r; - r = safe_atou16(s, &l); + r = safe_atou16_full(s, SAFE_ATO_REFUSE_LEADING_WHITESPACE, &l); if (r < 0) return r; @@ -711,7 +711,7 @@ int parse_dev(const char *s, dev_t *ret) { if (s[n] != ':') return -EINVAL; - major = strndupa(s, n); + major = strndupa_safe(s, n); r = safe_atou(major, &x); if (r < 0) return r; @@ -772,7 +772,7 @@ int parse_loadavg_fixed_point(const char *s, loadavg_t *ret) { if (!d) return -EINVAL; - i_str = strndupa(s, d - s); + i_str = strndupa_safe(s, d - s); f_str = d + 1; r = safe_atolu_full(i_str, 10, &i); diff --git a/src/libnm-systemd-shared/src/basic/path-util.c b/src/libnm-systemd-shared/src/basic/path-util.c index 92c55048..f391848f 100644 --- a/src/libnm-systemd-shared/src/basic/path-util.c +++ b/src/libnm-systemd-shared/src/basic/path-util.c @@ -1246,8 +1246,6 @@ char *file_in_same_dir(const char *path, const char *filename) { } bool hidden_or_backup_file(const char *filename) { - const char *p; - assert(filename); if (filename[0] == '.' || @@ -1257,24 +1255,25 @@ bool hidden_or_backup_file(const char *filename) { endswith(filename, "~")) return true; - p = strrchr(filename, '.'); - if (!p) + const char *dot = strrchr(filename, '.'); + if (!dot) return false; - /* Please, let's not add more entries to the list below. If external projects think it's a good idea to come up - * with always new suffixes and that everybody else should just adjust to that, then it really should be on - * them. Hence, in future, let's not add any more entries. Instead, let's ask those packages to instead adopt - * one of the generic suffixes/prefixes for hidden files or backups, possibly augmented with an additional - * string. Specifically: there's now: + /* Please, let's not add more entries to the list below. If external projects think it's a good idea + * to come up with always new suffixes and that everybody else should just adjust to that, then it + * really should be on them. Hence, in future, let's not add any more entries. Instead, let's ask + * those packages to instead adopt one of the generic suffixes/prefixes for hidden files or backups, + * possibly augmented with an additional string. Specifically: there's now: * * The generic suffixes "~" and ".bak" for backup files * The generic prefix "." for hidden files * - * Thus, if a new package manager "foopkg" wants its own set of ".foopkg-new", ".foopkg-old", ".foopkg-dist" - * or so registered, let's refuse that and ask them to use ".foopkg.new", ".foopkg.old" or ".foopkg~" instead. + * Thus, if a new package manager "foopkg" wants its own set of ".foopkg-new", ".foopkg-old", + * ".foopkg-dist" or so registered, let's refuse that and ask them to use ".foopkg.new", + * ".foopkg.old" or ".foopkg~" instead. */ - return STR_IN_SET(p + 1, + return STR_IN_SET(dot + 1, "rpmnew", "rpmsave", "rpmorig", @@ -1296,15 +1295,16 @@ bool hidden_or_backup_file(const char *filename) { bool is_device_path(const char *path) { - /* Returns true on paths that likely refer to a device, either by path in sysfs or to something in /dev */ + /* Returns true for paths that likely refer to a device, either by path in sysfs or to something in + * /dev. */ return PATH_STARTSWITH_SET(path, "/dev/", "/sys/"); } bool valid_device_node_path(const char *path) { - /* Some superficial checks whether the specified path is a valid device node path, all without looking at the - * actual device node. */ + /* Some superficial checks whether the specified path is a valid device node path, all without + * looking at the actual device node. */ if (!PATH_STARTSWITH_SET(path, "/dev/", "/run/systemd/inaccessible/")) return false; @@ -1318,8 +1318,8 @@ bool valid_device_node_path(const char *path) { bool valid_device_allow_pattern(const char *path) { assert(path); - /* Like valid_device_node_path(), but also allows full-subsystem expressions, like DeviceAllow= and DeviceDeny= - * accept it */ + /* Like valid_device_node_path(), but also allows full-subsystem expressions like those accepted by + * DeviceAllow= and DeviceDeny=. */ if (STARTSWITH_SET(path, "block-", "char-")) return true; @@ -1412,8 +1412,8 @@ bool dot_or_dot_dot(const char *path) { #if 0 /* NM_IGNORED */ bool empty_or_root(const char *path) { - /* For operations relative to some root directory, returns true if the specified root directory is redundant, - * i.e. either / or NULL or the empty string or any equivalent. */ + /* For operations relative to some root directory, returns true if the specified root directory is + * redundant, i.e. either / or NULL or the empty string or any equivalent. */ if (isempty(path)) return true; diff --git a/src/libnm-systemd-shared/src/basic/process-util.c b/src/libnm-systemd-shared/src/basic/process-util.c index 96d0912c..70564bd3 100644 --- a/src/libnm-systemd-shared/src/basic/process-util.c +++ b/src/libnm-systemd-shared/src/basic/process-util.c @@ -187,13 +187,13 @@ static int get_process_cmdline_nulstr( return r; } -int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags, char **line) { +int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags, char **ret) { _cleanup_free_ char *t = NULL; size_t k; char *ans; - assert(line); assert(pid >= 0); + assert(ret); /* Retrieve and format a commandline. See above for discussion of retrieval options. * @@ -220,25 +220,23 @@ int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags assert(!(flags & PROCESS_CMDLINE_USE_LOCALE)); _cleanup_strv_free_ char **args = NULL; + char **p; args = strv_parse_nulstr(t, k); if (!args) return -ENOMEM; - for (size_t i = 0; args[i]; i++) { - char *e; - - e = shell_maybe_quote(args[i], shflags); - if (!e) - return -ENOMEM; + /* Drop trailing empty strings. See issue #21186. */ + STRV_FOREACH_BACKWARDS(p, args) { + if (!isempty(*p)) + break; - free_and_replace(args[i], e); + *p = mfree(*p); } - ans = strv_join(args, " "); + ans = quote_command_line(args, shflags); if (!ans) return -ENOMEM; - } else { /* Arguments are separated by NULs. Let's replace those with spaces. */ for (size_t i = 0; i < k - 1; i++) @@ -257,7 +255,7 @@ int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags ans = str_realloc(ans); } - *line = ans; + *ret = ans; return 0; } @@ -464,29 +462,29 @@ int is_kernel_thread(pid_t pid) { return !!(flags & PF_KTHREAD); } -int get_process_capeff(pid_t pid, char **capeff) { +int get_process_capeff(pid_t pid, char **ret) { const char *p; int r; - assert(capeff); assert(pid >= 0); + assert(ret); p = procfs_file_alloca(pid, "status"); - r = get_proc_field(p, "CapEff", WHITESPACE, capeff); + r = get_proc_field(p, "CapEff", WHITESPACE, ret); if (r == -ENOENT) return -ESRCH; return r; } -static int get_process_link_contents(const char *proc_file, char **name) { +static int get_process_link_contents(const char *proc_file, char **ret) { int r; assert(proc_file); - assert(name); + assert(ret); - r = readlink_malloc(proc_file, name); + r = readlink_malloc(proc_file, ret); if (r == -ENOENT) return -ESRCH; if (r < 0) @@ -495,32 +493,33 @@ static int get_process_link_contents(const char *proc_file, char **name) { return 0; } -int get_process_exe(pid_t pid, char **name) { +int get_process_exe(pid_t pid, char **ret) { const char *p; char *d; int r; assert(pid >= 0); + assert(ret); p = procfs_file_alloca(pid, "exe"); - r = get_process_link_contents(p, name); + r = get_process_link_contents(p, ret); if (r < 0) return r; - d = endswith(*name, " (deleted)"); + d = endswith(*ret, " (deleted)"); if (d) *d = '\0'; return 0; } -static int get_process_id(pid_t pid, const char *field, uid_t *uid) { +static int get_process_id(pid_t pid, const char *field, uid_t *ret) { _cleanup_fclose_ FILE *f = NULL; const char *p; int r; assert(field); - assert(uid); + assert(ret); if (pid < 0) return -EINVAL; @@ -550,60 +549,62 @@ static int get_process_id(pid_t pid, const char *field, uid_t *uid) { l[strcspn(l, WHITESPACE)] = 0; - return parse_uid(l, uid); + return parse_uid(l, ret); } } return -EIO; } -int get_process_uid(pid_t pid, uid_t *uid) { +int get_process_uid(pid_t pid, uid_t *ret) { if (pid == 0 || pid == getpid_cached()) { - *uid = getuid(); + *ret = getuid(); return 0; } - return get_process_id(pid, "Uid:", uid); + return get_process_id(pid, "Uid:", ret); } -int get_process_gid(pid_t pid, gid_t *gid) { +int get_process_gid(pid_t pid, gid_t *ret) { if (pid == 0 || pid == getpid_cached()) { - *gid = getgid(); + *ret = getgid(); return 0; } assert_cc(sizeof(uid_t) == sizeof(gid_t)); - return get_process_id(pid, "Gid:", gid); + return get_process_id(pid, "Gid:", ret); } -int get_process_cwd(pid_t pid, char **cwd) { +int get_process_cwd(pid_t pid, char **ret) { const char *p; assert(pid >= 0); + assert(ret); if (pid == 0 || pid == getpid_cached()) - return safe_getcwd(cwd); + return safe_getcwd(ret); p = procfs_file_alloca(pid, "cwd"); - return get_process_link_contents(p, cwd); + return get_process_link_contents(p, ret); } -int get_process_root(pid_t pid, char **root) { +int get_process_root(pid_t pid, char **ret) { const char *p; assert(pid >= 0); + assert(ret); p = procfs_file_alloca(pid, "root"); - return get_process_link_contents(p, root); + return get_process_link_contents(p, ret); } #define ENVIRONMENT_BLOCK_MAX (5U*1024U*1024U) -int get_process_environ(pid_t pid, char **env) { +int get_process_environ(pid_t pid, char **ret) { _cleanup_fclose_ FILE *f = NULL; _cleanup_free_ char *outcome = NULL; size_t sz = 0; @@ -611,7 +612,7 @@ int get_process_environ(pid_t pid, char **env) { int r; assert(pid >= 0); - assert(env); + assert(ret); p = procfs_file_alloca(pid, "environ"); @@ -643,7 +644,7 @@ int get_process_environ(pid_t pid, char **env) { } outcome[sz] = '\0'; - *env = TAKE_PTR(outcome); + *ret = TAKE_PTR(outcome); return 0; } @@ -702,13 +703,13 @@ int get_process_ppid(pid_t pid, pid_t *ret) { return 0; } -int get_process_umask(pid_t pid, mode_t *umask) { +int get_process_umask(pid_t pid, mode_t *ret) { _cleanup_free_ char *m = NULL; const char *p; int r; - assert(umask); assert(pid >= 0); + assert(ret); p = procfs_file_alloca(pid, "status"); @@ -716,7 +717,7 @@ int get_process_umask(pid_t pid, mode_t *umask) { if (r == -ENOENT) return -ESRCH; - return parse_mode(m, umask); + return parse_mode(m, ret); } int wait_for_terminate(pid_t pid, siginfo_t *status) { @@ -830,7 +831,7 @@ int wait_for_terminate_with_timeout(pid_t pid, usec_t timeout) { if (n >= until) break; - r = sigtimedwait(&mask, NULL, timespec_store(&ts, until - n)) < 0 ? -errno : 0; + r = RET_NERRNO(sigtimedwait(&mask, NULL, timespec_store(&ts, until - n))); /* Assuming we woke due to the child exiting. */ if (waitid(P_PID, pid, &status, WEXITED|WNOHANG) == 0) { if (status.si_pid == pid) { @@ -863,8 +864,8 @@ int wait_for_terminate_with_timeout(pid_t pid, usec_t timeout) { void sigkill_wait(pid_t pid) { assert(pid > 1); - if (kill(pid, SIGKILL) >= 0) - (void) wait_for_terminate(pid, NULL); + (void) kill(pid, SIGKILL); + (void) wait_for_terminate(pid, NULL); } void sigkill_waitp(pid_t *pid) { @@ -881,14 +882,14 @@ void sigkill_waitp(pid_t *pid) { void sigterm_wait(pid_t pid) { assert(pid > 1); - if (kill_and_sigcont(pid, SIGTERM) >= 0) - (void) wait_for_terminate(pid, NULL); + (void) kill_and_sigcont(pid, SIGTERM); + (void) wait_for_terminate(pid, NULL); } int kill_and_sigcont(pid_t pid, int sig) { int r; - r = kill(pid, sig) < 0 ? -errno : 0; + r = RET_NERRNO(kill(pid, sig)); /* If this worked, also send SIGCONT, unless we already just sent a SIGCONT, or SIGKILL was sent which isn't * affected by a process being suspended anyway. */ @@ -1064,8 +1065,8 @@ unsigned long personality_from_string(const char *p) { if (architecture == native_architecture()) return PER_LINUX; -#ifdef SECONDARY_ARCHITECTURE - if (architecture == SECONDARY_ARCHITECTURE) +#ifdef ARCHITECTURE_SECONDARY + if (architecture == ARCHITECTURE_SECONDARY) return PER_LINUX32; #endif @@ -1077,9 +1078,9 @@ const char* personality_to_string(unsigned long p) { if (p == PER_LINUX) architecture = native_architecture(); -#ifdef SECONDARY_ARCHITECTURE +#ifdef ARCHITECTURE_SECONDARY else if (p == PER_LINUX32) - architecture = SECONDARY_ARCHITECTURE; + architecture = ARCHITECTURE_SECONDARY; #endif if (architecture < 0) @@ -1150,23 +1151,6 @@ int pid_compare_func(const pid_t *a, const pid_t *b) { /* Suitable for usage in qsort() */ return CMP(*a, *b); } - -int ioprio_parse_priority(const char *s, int *ret) { - int i, r; - - assert(s); - assert(ret); - - r = safe_atoi(s, &i); - if (r < 0) - return r; - - if (!ioprio_priority_is_valid(i)) - return -EINVAL; - - *ret = i; - return 0; -} #endif /* NM_IGNORED */ /* The cached PID, possible values: @@ -1256,7 +1240,7 @@ static void restore_sigsetp(sigset_t **ssp) { int safe_fork_full( const char *name, - int except_fds[], + const int except_fds[], size_t n_except_fds, ForkFlags flags, pid_t *ret_pid) { @@ -1451,7 +1435,7 @@ int safe_fork_full( int namespace_fork( const char *outer_name, const char *inner_name, - int except_fds[], + const int except_fds[], size_t n_except_fds, ForkFlags flags, int pidns_fd, @@ -1467,8 +1451,7 @@ int namespace_fork( * process. This ensures that we are fully a member of the destination namespace, with pidns an all, so that * /proc/self/fd works correctly. */ - r = safe_fork_full(outer_name, except_fds, n_except_fds, - (flags|FORK_DEATHSIG) & ~(FORK_REOPEN_LOG|FORK_NEW_MOUNTNS|FORK_MOUNTNS_SLAVE), ret_pid); + r = safe_fork_full(outer_name, except_fds, n_except_fds, (flags|FORK_DEATHSIG) & ~(FORK_REOPEN_LOG|FORK_NEW_MOUNTNS|FORK_MOUNTNS_SLAVE), ret_pid); if (r < 0) return r; if (r == 0) { @@ -1513,7 +1496,7 @@ int set_oom_score_adjust(int value) { } int get_oom_score_adjust(int *ret) { - _cleanup_free_ char *t; + _cleanup_free_ char *t = NULL; int r, a; r = read_virtual_file("/proc/self/oom_score_adj", SIZE_MAX, &t, NULL); @@ -1628,14 +1611,27 @@ bool invoked_as(char *argv[], const char *token) { return strstr(last_path_component(argv[0]), token); } -static const char *const ioprio_class_table[] = { - [IOPRIO_CLASS_NONE] = "none", - [IOPRIO_CLASS_RT] = "realtime", - [IOPRIO_CLASS_BE] = "best-effort", - [IOPRIO_CLASS_IDLE] = "idle", -}; +_noreturn_ void freeze(void) { + log_close(); + + /* Make sure nobody waits for us (i.e. on one of our sockets) anymore. Note that we use + * close_all_fds_without_malloc() instead of plain close_all_fds() here, since we want this function + * to be compatible with being called from signal handlers. */ + (void) close_all_fds_without_malloc(NULL, 0); + + /* Let's not freeze right away, but keep reaping zombies. */ + for (;;) { + siginfo_t si = {}; + + if (waitid(P_ALL, 0, &si, WEXITED) < 0 && errno != EINTR) + break; + } + + /* waitid() failed with an unexpected error, things are really borked. Freeze now! */ + for (;;) + pause(); +} -DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(ioprio_class, int, IOPRIO_N_CLASSES); static const char *const sigchld_code_table[] = { [CLD_EXITED] = "exited", diff --git a/src/libnm-systemd-shared/src/basic/process-util.h b/src/libnm-systemd-shared/src/basic/process-util.h index bc16d328..a957cab2 100644 --- a/src/libnm-systemd-shared/src/basic/process-util.h +++ b/src/libnm-systemd-shared/src/basic/process-util.h @@ -14,7 +14,6 @@ #include "alloc-util.h" #include "format-util.h" #include "macro.h" -#include "missing_ioprio.h" #include "time-util.h" #define procfs_file_alloca(pid, field) \ @@ -39,17 +38,17 @@ typedef enum ProcessCmdlineFlags { PROCESS_CMDLINE_QUOTE_POSIX = 1 << 3, } ProcessCmdlineFlags; -int get_process_comm(pid_t pid, char **name); -int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags, char **line); -int get_process_exe(pid_t pid, char **name); -int get_process_uid(pid_t pid, uid_t *uid); -int get_process_gid(pid_t pid, gid_t *gid); -int get_process_capeff(pid_t pid, char **capeff); -int get_process_cwd(pid_t pid, char **cwd); -int get_process_root(pid_t pid, char **root); -int get_process_environ(pid_t pid, char **environ); -int get_process_ppid(pid_t pid, pid_t *ppid); -int get_process_umask(pid_t pid, mode_t *umask); +int get_process_comm(pid_t pid, char **ret); +int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags, char **ret); +int get_process_exe(pid_t pid, char **ret); +int get_process_uid(pid_t pid, uid_t *ret); +int get_process_gid(pid_t pid, gid_t *ret); +int get_process_capeff(pid_t pid, char **ret); +int get_process_cwd(pid_t pid, char **ret); +int get_process_root(pid_t pid, char **ret); +int get_process_environ(pid_t pid, char **ret); +int get_process_ppid(pid_t pid, pid_t *ret); +int get_process_umask(pid_t pid, mode_t *ret); int wait_for_terminate(pid_t pid, siginfo_t *status); @@ -97,9 +96,6 @@ const char *personality_to_string(unsigned long); int safe_personality(unsigned long p); int opinionated_personality(unsigned long *ret); -int ioprio_class_to_string_alloc(int i, char **s); -int ioprio_class_from_string(const char *s); - const char *sigchld_code_to_string(int i) _const_; int sigchld_code_from_string(const char *s) _pure_; @@ -131,21 +127,11 @@ static inline bool sched_priority_is_valid(int i) { return i >= 0 && i <= sched_get_priority_max(SCHED_RR); } -static inline bool ioprio_class_is_valid(int i) { - return IN_SET(i, IOPRIO_CLASS_NONE, IOPRIO_CLASS_RT, IOPRIO_CLASS_BE, IOPRIO_CLASS_IDLE); -} - -static inline bool ioprio_priority_is_valid(int i) { - return i >= 0 && i < IOPRIO_BE_NR; -} - static inline bool pid_is_valid(pid_t p) { return p > 0; } #endif /* NM_IGNORED */ -int ioprio_parse_priority(const char *s, int *ret); - pid_t getpid_cached(void); void reset_cached_pid(void); @@ -168,13 +154,13 @@ typedef enum ForkFlags { FORK_NEW_USERNS = 1 << 13, /* Run child in its own user namespace */ } ForkFlags; -int safe_fork_full(const char *name, int except_fds[], size_t n_except_fds, ForkFlags flags, pid_t *ret_pid); +int safe_fork_full(const char *name, const int except_fds[], size_t n_except_fds, ForkFlags flags, pid_t *ret_pid); static inline int safe_fork(const char *name, ForkFlags flags, pid_t *ret_pid) { return safe_fork_full(name, NULL, 0, flags, ret_pid); } -int namespace_fork(const char *outer_name, const char *inner_name, int except_fds[], size_t n_except_fds, ForkFlags flags, int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int root_fd, pid_t *ret_pid); +int namespace_fork(const char *outer_name, const char *inner_name, const int except_fds[], size_t n_except_fds, ForkFlags flags, int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int root_fd, pid_t *ret_pid); int set_oom_score_adjust(int value); int get_oom_score_adjust(int *ret); @@ -194,8 +180,9 @@ assert_cc(TASKS_MAX <= (unsigned long) PID_T_MAX); /* Like TAKE_PTR() but for child PIDs, resetting them to 0 */ #define TAKE_PID(pid) \ ({ \ - pid_t _pid_ = (pid); \ - (pid) = 0; \ + pid_t *_ppid_ = &(pid); \ + pid_t _pid_ = *_ppid_; \ + *_ppid_ = 0; \ _pid_; \ }) @@ -204,3 +191,5 @@ int pidfd_get_pid(int fd, pid_t *ret); int setpriority_closest(int priority); bool invoked_as(char *argv[], const char *token); + +_noreturn_ void freeze(void); diff --git a/src/libnm-systemd-shared/src/basic/random-util.c b/src/libnm-systemd-shared/src/basic/random-util.c index 063784dc..9832f8ef 100644 --- a/src/libnm-systemd-shared/src/basic/random-util.c +++ b/src/libnm-systemd-shared/src/basic/random-util.c @@ -163,7 +163,6 @@ int genuine_random_bytes(void *p, size_t n, RandomFlags flags) { static int have_syscall = -1; _cleanup_close_ int fd = -1; bool got_some = false; - int r; /* Gathers some high-quality randomness from the kernel (or potentially mid-quality randomness from * the CPU if the RANDOM_ALLOW_RDRAND flag is set). This call won't block, unless the RANDOM_BLOCK @@ -222,25 +221,26 @@ int genuine_random_bytes(void *p, size_t n, RandomFlags flags) { if (have_syscall != 0 && !HAS_FEATURE_MEMORY_SANITIZER) { for (;;) { + ssize_t l; #if !HAVE_GETRANDOM /* NetworkManager Note: systemd calls the syscall directly in this case. Don't add that workaround. * If you don't compile against a libc that provides getrandom(), you don't get it. */ - r = -1; + l = -1; errno = ENOSYS; #else - r = getrandom(p, n, + l = getrandom(p, n, (FLAGS_SET(flags, RANDOM_BLOCK) ? 0 : GRND_NONBLOCK) | (FLAGS_SET(flags, RANDOM_ALLOW_INSECURE) ? GRND_INSECURE : 0)); #endif - if (r > 0) { + if (l > 0) { have_syscall = true; - if ((size_t) r == n) + if ((size_t) l == n) return 0; /* Yay, success! */ - assert((size_t) r < n); - p = (uint8_t*) p + r; - n -= r; + assert((size_t) l < n); + p = (uint8_t*) p + l; + n -= l; if (FLAGS_SET(flags, RANDOM_EXTEND_WITH_PSEUDO)) { /* Fill in the remaining bytes using pseudo-random values */ @@ -257,7 +257,7 @@ int genuine_random_bytes(void *p, size_t n, RandomFlags flags) { /* Fill in the rest with /dev/urandom */ break; - } else if (r == 0) { + } else if (l == 0) { have_syscall = true; return -EIO; diff --git a/src/libnm-systemd-shared/src/basic/signal-util.c b/src/libnm-systemd-shared/src/basic/signal-util.c index f96eb4d4..6d8c9920 100644 --- a/src/libnm-systemd-shared/src/basic/signal-util.c +++ b/src/libnm-systemd-shared/src/basic/signal-util.c @@ -5,6 +5,7 @@ #include #include +#include "errno-util.h" #include "macro.h" #include "parse-util.h" #include "signal-util.h" @@ -42,10 +43,7 @@ int reset_signal_mask(void) { if (sigemptyset(&ss) < 0) return -errno; - if (sigprocmask(SIG_SETMASK, &ss, NULL) < 0) - return -errno; - - return 0; + return RET_NERRNO(sigprocmask(SIG_SETMASK, &ss, NULL)); } int sigaction_many_internal(const struct sigaction *sa, ...) { @@ -122,7 +120,7 @@ int sigprocmask_many(int how, sigset_t *old, ...) { return 0; } -static const char *const __signal_table[] = { +static const char *const static_signal_table[] = { [SIGHUP] = "HUP", [SIGINT] = "INT", [SIGQUIT] = "QUIT", @@ -158,13 +156,13 @@ static const char *const __signal_table[] = { [SIGSYS] = "SYS" }; -DEFINE_PRIVATE_STRING_TABLE_LOOKUP(__signal, int); +DEFINE_PRIVATE_STRING_TABLE_LOOKUP(static_signal, int); const char *signal_to_string(int signo) { static thread_local char buf[STRLEN("RTMIN+") + DECIMAL_STR_MAX(int)]; const char *name; - name = __signal_to_string(signo); + name = static_signal_to_string(signo); if (name) return name; @@ -193,7 +191,7 @@ int signal_from_string(const char *s) { s += 3; /* Check that the input is a signal name. */ - signo = __signal_from_string(s); + signo = static_signal_from_string(s); if (signo > 0) return signo; @@ -250,11 +248,7 @@ int signal_is_blocked(int sig) { if (r != 0) return -r; - r = sigismember(&ss, sig); - if (r < 0) - return -errno; - - return r; + return RET_NERRNO(sigismember(&ss, sig)); } int pop_pending_signal_internal(int sig, ...) { diff --git a/src/libnm-systemd-shared/src/basic/socket-util.c b/src/libnm-systemd-shared/src/basic/socket-util.c index 49a4df44..6478fdee 100644 --- a/src/libnm-systemd-shared/src/basic/socket-util.c +++ b/src/libnm-systemd-shared/src/basic/socket-util.c @@ -405,6 +405,41 @@ const union in_addr_union *sockaddr_in_addr(const struct sockaddr *_sa) { } } +int sockaddr_set_in_addr( + union sockaddr_union *u, + int family, + const union in_addr_union *a, + uint16_t port) { + + assert(u); + assert(a); + + switch (family) { + + case AF_INET: + u->in = (struct sockaddr_in) { + .sin_family = AF_INET, + .sin_addr = a->in, + .sin_port = htobe16(port), + }; + + return 0; + + case AF_INET6: + u->in6 = (struct sockaddr_in6) { + .sin6_family = AF_INET6, + .sin6_addr = a->in6, + .sin6_port = htobe16(port), + }; + + return 0; + + default: + return -EAFNOSUPPORT; + + } +} + int sockaddr_pretty( const struct sockaddr *_sa, socklen_t salen, @@ -556,7 +591,7 @@ int getpeername_pretty(int fd, bool include_port, char **ret) { return -errno; if (sa.sa.sa_family == AF_UNIX) { - struct ucred ucred = {}; + struct ucred ucred = UCRED_INVALID; /* UNIX connection sockets are anonymous, so let's use * PID/UID as pretty credentials instead */ @@ -1238,10 +1273,7 @@ int socket_bind_to_ifname(int fd, const char *ifname) { /* Call with NULL to drop binding */ - if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, ifname, strlen_ptr(ifname)) < 0) - return -errno; - - return 0; + return RET_NERRNO(setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, ifname, strlen_ptr(ifname))); } int socket_bind_to_ifindex(int fd, int ifindex) { @@ -1250,13 +1282,9 @@ int socket_bind_to_ifindex(int fd, int ifindex) { assert(fd >= 0); - if (ifindex <= 0) { + if (ifindex <= 0) /* Drop binding */ - if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, NULL, 0) < 0) - return -errno; - - return 0; - } + return RET_NERRNO(setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, NULL, 0)); r = setsockopt_int(fd, SOL_SOCKET, SO_BINDTOIFINDEX, ifindex); if (r != -ENOPROTOOPT) @@ -1345,16 +1373,10 @@ int socket_set_unicast_if(int fd, int af, int ifi) { switch (af) { case AF_INET: - if (setsockopt(fd, IPPROTO_IP, IP_UNICAST_IF, &ifindex_be, sizeof(ifindex_be)) < 0) - return -errno; - - return 0; + return RET_NERRNO(setsockopt(fd, IPPROTO_IP, IP_UNICAST_IF, &ifindex_be, sizeof(ifindex_be))); case AF_INET6: - if (setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_IF, &ifindex_be, sizeof(ifindex_be)) < 0) - return -errno; - - return 0; + return RET_NERRNO(setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_IF, &ifindex_be, sizeof(ifindex_be))); default: return -EAFNOSUPPORT; diff --git a/src/libnm-systemd-shared/src/basic/socket-util.h b/src/libnm-systemd-shared/src/basic/socket-util.h index 4caa27c8..ddea5350 100644 --- a/src/libnm-systemd-shared/src/basic/socket-util.h +++ b/src/libnm-systemd-shared/src/basic/socket-util.h @@ -15,6 +15,7 @@ #include #include "errno-util.h" +#include "in-addr-util.h" #include "macro.h" #include "missing_network.h" #include "missing_socket.h" @@ -108,6 +109,7 @@ bool socket_ipv6_is_enabled(void); int sockaddr_port(const struct sockaddr *_sa, unsigned *port); const union in_addr_union *sockaddr_in_addr(const struct sockaddr *sa); +int sockaddr_set_in_addr(union sockaddr_union *u, int family, const union in_addr_union *a, uint16_t port); int sockaddr_pretty(const struct sockaddr *_sa, socklen_t salen, bool translate_ipv6, bool include_port, char **ret); int getpeername_pretty(int fd, bool include_port, char **ret); @@ -331,3 +333,6 @@ static inline int socket_set_recvfragsize(int fd, int af, bool b) { #endif /* NM_IGNORED */ int socket_get_mtu(int fd, int af, size_t *ret); + +/* an initializer for struct ucred that initialized all fields to the invalid value appropriate for each */ +#define UCRED_INVALID { .pid = 0, .uid = UID_INVALID, .gid = GID_INVALID } diff --git a/src/libnm-systemd-shared/src/basic/sort-util.h b/src/libnm-systemd-shared/src/basic/sort-util.h index a8984fc1..28c06c40 100644 --- a/src/libnm-systemd-shared/src/basic/sort-util.h +++ b/src/libnm-systemd-shared/src/basic/sort-util.h @@ -5,14 +5,20 @@ #include "macro.h" +/* This is the same as glibc's internal __compar_d_fn_t type. glibc exports a public comparison_fn_t, for the + * external type __compar_fn_t, but doesn't do anything similar for __compar_d_fn_t. Let's hence do that + * ourselves, picking a name that is obvious, but likely enough to not clash with glibc's choice of naming if + * they should ever add one. */ +typedef int (*comparison_userdata_fn_t)(const void *, const void *, void *); + void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size, - __compar_d_fn_t compar, void *arg); + comparison_userdata_fn_t compar, void *arg); #define typesafe_bsearch_r(k, b, n, func, userdata) \ ({ \ const typeof(b[0]) *_k = k; \ int (*_func_)(const typeof(b[0])*, const typeof(b[0])*, typeof(userdata)) = func; \ - xbsearch_r((const void*) _k, (b), (n), sizeof((b)[0]), (__compar_d_fn_t) _func_, userdata); \ + xbsearch_r((const void*) _k, (b), (n), sizeof((b)[0]), (comparison_userdata_fn_t) _func_, userdata); \ }) /** @@ -20,7 +26,7 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size, * that only if nmemb > 0. */ static inline void* bsearch_safe(const void *key, const void *base, - size_t nmemb, size_t size, __compar_fn_t compar) { + size_t nmemb, size_t size, comparison_fn_t compar) { if (nmemb <= 0) return NULL; @@ -32,14 +38,14 @@ static inline void* bsearch_safe(const void *key, const void *base, ({ \ const typeof(b[0]) *_k = k; \ int (*_func_)(const typeof(b[0])*, const typeof(b[0])*) = func; \ - bsearch_safe((const void*) _k, (b), (n), sizeof((b)[0]), (__compar_fn_t) _func_); \ + bsearch_safe((const void*) _k, (b), (n), sizeof((b)[0]), (comparison_fn_t) _func_); \ }) /** * Normal qsort requires base to be nonnull. Here were require * that only if nmemb > 0. */ -static inline void _qsort_safe(void *base, size_t nmemb, size_t size, __compar_fn_t compar) { +static inline void _qsort_safe(void *base, size_t nmemb, size_t size, comparison_fn_t compar) { if (nmemb <= 1) return; @@ -52,11 +58,11 @@ static inline void _qsort_safe(void *base, size_t nmemb, size_t size, __compar_f #define typesafe_qsort(p, n, func) \ ({ \ int (*_func_)(const typeof(p[0])*, const typeof(p[0])*) = func; \ - _qsort_safe((p), (n), sizeof((p)[0]), (__compar_fn_t) _func_); \ + _qsort_safe((p), (n), sizeof((p)[0]), (comparison_fn_t) _func_); \ }) #if 0 /* NM_IGNORED */ -static inline void qsort_r_safe(void *base, size_t nmemb, size_t size, __compar_d_fn_t compar, void *userdata) { +static inline void qsort_r_safe(void *base, size_t nmemb, size_t size, comparison_userdata_fn_t compar, void *userdata) { if (nmemb <= 1) return; @@ -67,7 +73,7 @@ static inline void qsort_r_safe(void *base, size_t nmemb, size_t size, __compar_ #define typesafe_qsort_r(p, n, func, userdata) \ ({ \ int (*_func_)(const typeof(p[0])*, const typeof(p[0])*, typeof(userdata)) = func; \ - qsort_r_safe((p), (n), sizeof((p)[0]), (__compar_d_fn_t) _func_, userdata); \ + qsort_r_safe((p), (n), sizeof((p)[0]), (comparison_userdata_fn_t) _func_, userdata); \ }) #endif /* NM_IGNORED */ diff --git a/src/libnm-systemd-shared/src/basic/sparse-endian.h b/src/libnm-systemd-shared/src/basic/sparse-endian.h index 9583dda9..c795d3da 100644 --- a/src/libnm-systemd-shared/src/basic/sparse-endian.h +++ b/src/libnm-systemd-shared/src/basic/sparse-endian.h @@ -55,9 +55,9 @@ typedef uint64_t __sd_bitwise be64_t; #undef le64toh #if __BYTE_ORDER == __LITTLE_ENDIAN -#define bswap_16_on_le(x) __bswap_16(x) -#define bswap_32_on_le(x) __bswap_32(x) -#define bswap_64_on_le(x) __bswap_64(x) +#define bswap_16_on_le(x) bswap_16(x) +#define bswap_32_on_le(x) bswap_32(x) +#define bswap_64_on_le(x) bswap_64(x) #define bswap_16_on_be(x) (x) #define bswap_32_on_be(x) (x) #define bswap_64_on_be(x) (x) @@ -65,9 +65,9 @@ typedef uint64_t __sd_bitwise be64_t; #define bswap_16_on_le(x) (x) #define bswap_32_on_le(x) (x) #define bswap_64_on_le(x) (x) -#define bswap_16_on_be(x) __bswap_16(x) -#define bswap_32_on_be(x) __bswap_32(x) -#define bswap_64_on_be(x) __bswap_64(x) +#define bswap_16_on_be(x) bswap_16(x) +#define bswap_32_on_be(x) bswap_32(x) +#define bswap_64_on_be(x) bswap_64(x) #endif static inline le16_t htole16(uint16_t value) { return (le16_t __sd_force) bswap_16_on_be(value); } diff --git a/src/libnm-systemd-shared/src/basic/stat-util.c b/src/libnm-systemd-shared/src/basic/stat-util.c index 133828bc..8126ce08 100644 --- a/src/libnm-systemd-shared/src/basic/stat-util.c +++ b/src/libnm-systemd-shared/src/basic/stat-util.c @@ -15,10 +15,13 @@ #include "errno-util.h" #include "fd-util.h" #include "fileio.h" +#include "filesystems.h" +#include "fs-util.h" #include "macro.h" #include "missing_fs.h" #include "missing_magic.h" #include "missing_syscall.h" +#include "nulstr-util.h" #include "parse-util.h" #include "stat-util.h" #include "string-util.h" @@ -75,27 +78,41 @@ int is_device_node(const char *path) { int dir_is_empty_at(int dir_fd, const char *path) { _cleanup_close_ int fd = -1; - _cleanup_closedir_ DIR *d = NULL; + /* Allocate space for at least 3 full dirents, since every dir has at least two entries ("." + + * ".."), and only once we have seen if there's a third we know whether the dir is empty or not. */ + DEFINE_DIRENT_BUFFER(buffer, 3); struct dirent *de; + ssize_t n; if (path) { + assert(dir_fd >= 0 || dir_fd == AT_FDCWD); + fd = openat(dir_fd, path, O_RDONLY|O_DIRECTORY|O_CLOEXEC); if (fd < 0) return -errno; + } else if (dir_fd == AT_FDCWD) { + fd = open(".", O_RDONLY|O_DIRECTORY|O_CLOEXEC); + if (fd < 0) + return -errno; } else { - /* Note that DUPing is not enough, as the internal pointer - * would still be shared and moved by FOREACH_DIRENT. */ - fd = fd_reopen(dir_fd, O_CLOEXEC); + /* Note that DUPing is not enough, as the internal pointer would still be shared and moved + * getedents64(). */ + assert(dir_fd >= 0); + + fd = fd_reopen(dir_fd, O_RDONLY|O_DIRECTORY|O_CLOEXEC); if (fd < 0) return fd; } - d = take_fdopendir(&fd); - if (!d) + n = getdents64(fd, &buffer, sizeof(buffer)); + if (n < 0) return -errno; - FOREACH_DIRENT(de, d, return -errno) - return 0; + msan_unpoison(&buffer, n); + + FOREACH_DIRENT_IN_BUFFER(de, &buffer.de, n) + if (!dot_or_dot_dot(de->d_name)) + return 0; return 1; } @@ -178,7 +195,6 @@ int files_same(const char *filea, const char *fileb, int flags) { a.st_ino == b.st_ino; } -#if 0 /* NM_IGNORED */ bool is_fs_type(const struct statfs *s, statfs_f_type_t magic_value) { assert(s); assert_cc(sizeof(statfs_f_type_t) >= sizeof(s->f_type)); @@ -186,6 +202,7 @@ bool is_fs_type(const struct statfs *s, statfs_f_type_t magic_value) { return F_TYPE_EQUAL(s->f_type, magic_value); } +#if 0 /* NM_IGNORED */ int fd_is_fs_type(int fd, statfs_f_type_t magic_value) { struct statfs s; @@ -194,6 +211,7 @@ int fd_is_fs_type(int fd, statfs_f_type_t magic_value) { return is_fs_type(&s, magic_value); } +#endif /* NM_IGNORE */ int path_is_fs_type(const char *path, statfs_f_type_t magic_value) { struct statfs s; @@ -204,20 +222,13 @@ int path_is_fs_type(const char *path, statfs_f_type_t magic_value) { return is_fs_type(&s, magic_value); } +#if 0 /* NM_IGNORE */ bool is_temporary_fs(const struct statfs *s) { - return is_fs_type(s, TMPFS_MAGIC) || - is_fs_type(s, RAMFS_MAGIC); + return fs_in_group(s, FILESYSTEM_SET_TEMPORARY); } bool is_network_fs(const struct statfs *s) { - return is_fs_type(s, CIFS_MAGIC_NUMBER) || - is_fs_type(s, CODA_SUPER_MAGIC) || - is_fs_type(s, NCP_SUPER_MAGIC) || - is_fs_type(s, NFS_SUPER_MAGIC) || - is_fs_type(s, SMB_SUPER_MAGIC) || - is_fs_type(s, V9FS_MAGIC) || - is_fs_type(s, AFS_SUPER_MAGIC) || - is_fs_type(s, OCFS2_SUPER_MAGIC); + return fs_in_group(s, FILESYSTEM_SET_NETWORK); } int fd_is_temporary_fs(int fd) { @@ -395,6 +406,7 @@ int device_path_parse_major_minor(const char *path, mode_t *ret_mode, dev_t *ret return 0; } +#endif /* NM_IGNORED */ int proc_mounted(void) { int r; @@ -408,6 +420,7 @@ int proc_mounted(void) { return r; } +#if 0 /* NM_IGNORED */ bool stat_inode_unmodified(const struct stat *a, const struct stat *b) { /* Returns if the specified stat structures reference the same, unmodified inode. This check tries to diff --git a/src/libnm-systemd-shared/src/basic/string-util.h b/src/libnm-systemd-shared/src/basic/string-util.h index 775d694c..a1d88fbb 100644 --- a/src/libnm-systemd-shared/src/basic/string-util.h +++ b/src/libnm-systemd-shared/src/basic/string-util.h @@ -60,6 +60,10 @@ static inline const char *empty_to_null(const char *p) { return isempty(p) ? NULL : p; } +static inline const char *empty_to_na(const char *p) { + return isempty(p) ? "n/a" : p; +} + static inline const char *empty_to_dash(const char *str) { return isempty(str) ? "-" : str; } diff --git a/src/libnm-systemd-shared/src/basic/strv.c b/src/libnm-systemd-shared/src/basic/strv.c index 1d840923..3e0faf95 100644 --- a/src/libnm-systemd-shared/src/basic/strv.c +++ b/src/libnm-systemd-shared/src/basic/strv.c @@ -18,7 +18,7 @@ #include "string-util.h" #include "strv.h" -char *strv_find(char * const *l, const char *name) { +char* strv_find(char * const *l, const char *name) { char * const *i; assert(name); @@ -30,7 +30,7 @@ char *strv_find(char * const *l, const char *name) { return NULL; } -char *strv_find_case(char * const *l, const char *name) { +char* strv_find_case(char * const *l, const char *name) { char * const *i; assert(name); @@ -42,7 +42,7 @@ char *strv_find_case(char * const *l, const char *name) { return NULL; } -char *strv_find_prefix(char * const *l, const char *name) { +char* strv_find_prefix(char * const *l, const char *name) { char * const *i; assert(name); @@ -54,7 +54,7 @@ char *strv_find_prefix(char * const *l, const char *name) { return NULL; } -char *strv_find_startswith(char * const *l, const char *name) { +char* strv_find_startswith(char * const *l, const char *name) { char * const *i, *e; assert(name); @@ -71,19 +71,17 @@ char *strv_find_startswith(char * const *l, const char *name) { return NULL; } -char **strv_free(char **l) { - char **k; - +char** strv_free(char **l) { if (!l) return NULL; - for (k = l; *k; k++) + for (char **k = l; *k; k++) free(*k); return mfree(l); } -char **strv_free_erase(char **l) { +char** strv_free_erase(char **l) { char **i; STRV_FOREACH(i, l) @@ -92,7 +90,7 @@ char **strv_free_erase(char **l) { return mfree(l); } -char **strv_copy(char * const *l) { +char** strv_copy(char * const *l) { char **r, **k; k = r = new(char*, strv_length(l) + 1); @@ -124,7 +122,7 @@ size_t strv_length(char * const *l) { return n; } -char **strv_new_ap(const char *x, va_list ap) { +char** strv_new_ap(const char *x, va_list ap) { _cleanup_strv_free_ char **a = NULL; size_t n = 0, i = 0; va_list aq; @@ -163,7 +161,7 @@ char **strv_new_ap(const char *x, va_list ap) { return TAKE_PTR(a); } -char **strv_new_internal(const char *x, ...) { +char** strv_new_internal(const char *x, ...) { char **r; va_list ap; @@ -176,7 +174,7 @@ char **strv_new_internal(const char *x, ...) { int strv_extend_strv(char ***a, char * const *b, bool filter_duplicates) { char * const *s, **t; - size_t p, q, i = 0, j; + size_t p, q, i = 0; assert(a); @@ -197,7 +195,6 @@ int strv_extend_strv(char ***a, char * const *b, bool filter_duplicates) { *a = t; STRV_FOREACH(s, b) { - if (filter_duplicates && strv_contains(t, *s)) continue; @@ -214,7 +211,7 @@ int strv_extend_strv(char ***a, char * const *b, bool filter_duplicates) { return (int) i; rollback: - for (j = 0; j < i; j++) + for (size_t j = 0; j < i; j++) free(t[p + j]); t[p] = NULL; @@ -289,7 +286,6 @@ int strv_split_full(char ***t, const char *s, const char *separators, ExtractFla return -ENOMEM; l[n++] = TAKE_PTR(word); - l[n] = NULL; } @@ -376,7 +372,7 @@ int strv_split_colon_pairs(char ***t, const char *s) { } #endif /* NM_IGNORED */ -char *strv_join_full(char * const *l, const char *separator, const char *prefix, bool unescape_separators) { +char* strv_join_full(char * const *l, const char *separator, const char *prefix, bool unescape_separators) { char * const *s; char *r, *e; size_t n, k, m; @@ -483,7 +479,7 @@ int strv_push_pair(char ***l, char *a, char *b) { int strv_insert(char ***l, size_t position, char *value) { char **c; - size_t n, m, i; + size_t n, m; if (!value) return 0; @@ -500,18 +496,14 @@ int strv_insert(char ***l, size_t position, char *value) { if (!c) return -ENOMEM; - for (i = 0; i < position; i++) + for (size_t i = 0; i < position; i++) c[i] = (*l)[i]; c[position] = value; - for (i = position; i < n; i++) + for (size_t i = position; i < n; i++) c[i+1] = (*l)[i]; - c[n+1] = NULL; - free(*l); - *l = c; - - return 0; + return free_and_replace(*l, c); } int strv_consume(char ***l, char *value) { @@ -608,7 +600,7 @@ int strv_extend_front(char ***l, const char *value) { return 0; } -char **strv_uniq(char **l) { +char** strv_uniq(char **l) { char **i; /* Drops duplicate entries. The first identical string will be @@ -630,7 +622,7 @@ bool strv_is_uniq(char * const *l) { return true; } -char **strv_remove(char **l, const char *s) { +char** strv_remove(char **l, const char *s) { char **f, **t; if (!l) @@ -651,7 +643,7 @@ char **strv_remove(char **l, const char *s) { return l; } -char **strv_parse_nulstr(const char *s, size_t l) { +char** strv_parse_nulstr(const char *s, size_t l) { /* l is the length of the input data, which will be split at NULs into * elements of the resulting strv. Hence, the number of items in the resulting strv * will be equal to one plus the number of NUL bytes in the l bytes starting at s, @@ -663,7 +655,6 @@ char **strv_parse_nulstr(const char *s, size_t l) { * empty strings in s. */ - const char *p; size_t c = 0, i = 0; char **v; @@ -672,7 +663,7 @@ char **strv_parse_nulstr(const char *s, size_t l) { if (l <= 0) return new0(char*, 1); - for (p = s; p < s + l; p++) + for (const char *p = s; p < s + l; p++) if (*p == 0) c++; @@ -683,8 +674,7 @@ char **strv_parse_nulstr(const char *s, size_t l) { if (!v) return NULL; - p = s; - while (p < s + l) { + for (const char *p = s; p < s + l; ) { const char *e; e = memchr(p, 0, s + l - p); @@ -709,7 +699,7 @@ char **strv_parse_nulstr(const char *s, size_t l) { } #if 0 /* NM_IGNORED */ -char **strv_split_nulstr(const char *s) { +char** strv_split_nulstr(const char *s) { const char *i; char **r = NULL; @@ -786,7 +776,7 @@ static int str_compare(char * const *a, char * const *b) { return strcmp(*a, *b); } -char **strv_sort(char **l) { +char** strv_sort(char **l) { typesafe_qsort(l, strv_length(l), str_compare); return l; } @@ -836,21 +826,21 @@ int strv_extendf(char ***l, const char *format, ...) { return strv_consume(l, x); } -char **strv_reverse(char **l) { - size_t n, i; +char** strv_reverse(char **l) { + size_t n; n = strv_length(l); if (n <= 1) return l; - for (i = 0; i < n / 2; i++) + for (size_t i = 0; i < n / 2; i++) SWAP_TWO(l[i], l[n-1-i]); return l; } #if 0 /* NM_IGNORED */ -char **strv_shell_escape(char **l, const char *bad) { +char** strv_shell_escape(char **l, const char *bad) { char **s; /* Escapes every character in every string in l that is in bad, @@ -882,19 +872,7 @@ bool strv_fnmatch_full(char* const* patterns, const char *s, int flags, size_t * return false; } -char ***strv_free_free(char ***l) { - char ***i; - - if (!l) - return NULL; - - for (i = l; *i; i++) - strv_free(*i); - - return mfree(l); -} - -char **strv_skip(char **l, size_t n) { +char** strv_skip(char **l, size_t n) { while (n > 0) { if (strv_isempty(l)) @@ -907,7 +885,7 @@ char **strv_skip(char **l, size_t n) { } int strv_extend_n(char ***l, const char *value, size_t n) { - size_t i, j, k; + size_t i, k; char **nl; assert(l); @@ -934,15 +912,15 @@ int strv_extend_n(char ***l, const char *value, size_t n) { if (!nl[i]) goto rollback; } - nl[i] = NULL; + return 0; rollback: - for (j = k; j < i; j++) + for (size_t j = k; j < i; j++) free(nl[j]); - nl[k] = NULL; + return -ENOMEM; } diff --git a/src/libnm-systemd-shared/src/basic/strv.h b/src/libnm-systemd-shared/src/basic/strv.h index a56ef941..092d40c8 100644 --- a/src/libnm-systemd-shared/src/basic/strv.h +++ b/src/libnm-systemd-shared/src/basic/strv.h @@ -13,23 +13,23 @@ #include "macro.h" #include "string-util.h" -char *strv_find(char * const *l, const char *name) _pure_; -char *strv_find_case(char * const *l, const char *name) _pure_; -char *strv_find_prefix(char * const *l, const char *name) _pure_; -char *strv_find_startswith(char * const *l, const char *name) _pure_; +char* strv_find(char * const *l, const char *name) _pure_; +char* strv_find_case(char * const *l, const char *name) _pure_; +char* strv_find_prefix(char * const *l, const char *name) _pure_; +char* strv_find_startswith(char * const *l, const char *name) _pure_; #define strv_contains(l, s) (!!strv_find((l), (s))) #define strv_contains_case(l, s) (!!strv_find_case((l), (s))) -char **strv_free(char **l); +char** strv_free(char **l); DEFINE_TRIVIAL_CLEANUP_FUNC(char**, strv_free); #define _cleanup_strv_free_ _cleanup_(strv_freep) -char **strv_free_erase(char **l); +char** strv_free_erase(char **l); DEFINE_TRIVIAL_CLEANUP_FUNC(char**, strv_free_erase); #define _cleanup_strv_free_erase_ _cleanup_(strv_free_erasep) -char **strv_copy(char * const *l); +char** strv_copy(char * const *l); size_t strv_length(char * const *l) _pure_; int strv_extend_strv(char ***a, char * const *b, bool filter_duplicates); @@ -50,8 +50,8 @@ int strv_consume(char ***l, char *value); int strv_consume_pair(char ***l, char *a, char *b); int strv_consume_prepend(char ***l, char *value); -char **strv_remove(char **l, const char *s); -char **strv_uniq(char **l); +char** strv_remove(char **l, const char *s); +char** strv_uniq(char **l); bool strv_is_uniq(char * const *l); int strv_compare(char * const *a, char * const *b); @@ -59,8 +59,8 @@ static inline bool strv_equal(char * const *a, char * const *b) { return strv_compare(a, b) == 0; } -char **strv_new_internal(const char *x, ...) _sentinel_; -char **strv_new_ap(const char *x, va_list ap); +char** strv_new_internal(const char *x, ...) _sentinel_; +char** strv_new_ap(const char *x, va_list ap); #define strv_new(...) strv_new_internal(__VA_ARGS__, NULL) #define STRV_IGNORE ((const char *) POINTER_MAX) @@ -74,7 +74,7 @@ static inline bool strv_isempty(char * const *l) { } int strv_split_full(char ***t, const char *s, const char *separators, ExtractFlags flags); -static inline char **strv_split(const char *s, const char *separators) { +static inline char** strv_split(const char *s, const char *separators) { char **ret; if (strv_split_full(&ret, s, separators, 0) < 0) @@ -87,7 +87,7 @@ int strv_split_and_extend_full(char ***t, const char *s, const char *separators, #define strv_split_and_extend(t, s, sep, dup) strv_split_and_extend_full(t, s, sep, dup, 0) int strv_split_newlines_full(char ***ret, const char *s, ExtractFlags flags); -static inline char **strv_split_newlines(const char *s) { +static inline char** strv_split_newlines(const char *s) { char **ret; if (strv_split_newlines_full(&ret, s, 0) < 0) @@ -101,13 +101,13 @@ static inline char **strv_split_newlines(const char *s) { * string in the vector is an empty string. */ int strv_split_colon_pairs(char ***t, const char *s); -char *strv_join_full(char * const *l, const char *separator, const char *prefix, bool escape_separtor); +char* strv_join_full(char * const *l, const char *separator, const char *prefix, bool escape_separtor); static inline char *strv_join(char * const *l, const char *separator) { return strv_join_full(l, separator, NULL, false); } -char **strv_parse_nulstr(const char *s, size_t l); -char **strv_split_nulstr(const char *s); +char** strv_parse_nulstr(const char *s, size_t l); +char** strv_split_nulstr(const char *s); int strv_make_nulstr(char * const *l, char **p, size_t *n); static inline int strv_from_nulstr(char ***a, const char *nulstr) { @@ -136,7 +136,7 @@ bool strv_overlap(char * const *a, char * const *b) _pure_; #define STRV_FOREACH_PAIR(x, y, l) \ for ((x) = (l), (y) = (x) ? (x+1) : NULL; (x) && *(x) && *(y); (x) += 2, (y) = (x + 1)) -char **strv_sort(char **l); +char** strv_sort(char **l); void strv_print(char * const *l); #define strv_from_stdarg_alloca(first) \ @@ -206,13 +206,16 @@ void strv_print(char * const *l); _found; \ }) -#define FOREACH_STRING(x, y, ...) \ - for (char **_l = STRV_MAKE(({ x = y; }), ##__VA_ARGS__); \ +#define _FOREACH_STRING(uniq, x, y, ...) \ + for (char **UNIQ_T(l, uniq) = STRV_MAKE(({ x = y; }), ##__VA_ARGS__); \ x; \ - x = *(++_l)) + x = *(++UNIQ_T(l, uniq))) -char **strv_reverse(char **l); -char **strv_shell_escape(char **l, const char *bad); +#define FOREACH_STRING(x, y, ...) \ + _FOREACH_STRING(UNIQ, x, y, ##__VA_ARGS__) + +char** strv_reverse(char **l); +char** strv_shell_escape(char **l, const char *bad); bool strv_fnmatch_full(char* const* patterns, const char *s, int flags, size_t *matched_pos); static inline bool strv_fnmatch(char* const* patterns, const char *s) { @@ -225,10 +228,7 @@ static inline bool strv_fnmatch_or_empty(char* const* patterns, const char *s, i strv_fnmatch_full(patterns, s, flags, NULL); } -char ***strv_free_free(char ***l); -DEFINE_TRIVIAL_CLEANUP_FUNC(char***, strv_free_free); - -char **strv_skip(char **l, size_t n); +char** strv_skip(char **l, size_t n); int strv_extend_n(char ***l, const char *value, size_t n); diff --git a/src/libnm-systemd-shared/src/basic/strxcpyx.c b/src/libnm-systemd-shared/src/basic/strxcpyx.c index 39aebb88..2788dd82 100644 --- a/src/libnm-systemd-shared/src/basic/strxcpyx.c +++ b/src/libnm-systemd-shared/src/basic/strxcpyx.c @@ -17,57 +17,73 @@ #include #include +#include "string-util.h" #include "strxcpyx.h" -size_t strnpcpy(char **dest, size_t size, const char *src, size_t len) { +size_t strnpcpy_full(char **dest, size_t size, const char *src, size_t len, bool *ret_truncated) { + bool truncated = false; + assert(dest); assert(src); - if (size == 0) + if (size == 0) { + if (ret_truncated) + *ret_truncated = len > 0; return 0; + } if (len >= size) { if (size > 1) *dest = mempcpy(*dest, src, size-1); size = 0; + truncated = true; } else if (len > 0) { *dest = mempcpy(*dest, src, len); size -= len; } + if (ret_truncated) + *ret_truncated = truncated; + *dest[0] = '\0'; return size; } -size_t strpcpy(char **dest, size_t size, const char *src) { +size_t strpcpy_full(char **dest, size_t size, const char *src, bool *ret_truncated) { assert(dest); assert(src); - return strnpcpy(dest, size, src, strlen(src)); + return strnpcpy_full(dest, size, src, strlen(src), ret_truncated); } -size_t strpcpyf(char **dest, size_t size, const char *src, ...) { +size_t strpcpyf_full(char **dest, size_t size, bool *ret_truncated, const char *src, ...) { + bool truncated = false; va_list va; int i; assert(dest); assert(src); - if (size == 0) - return 0; - va_start(va, src); i = vsnprintf(*dest, size, src, va); - if (i < (int)size) { + va_end(va); + + if (i < (int) size) { *dest += i; size -= i; - } else + } else { size = 0; - va_end(va); + truncated = i > 0; + } + + if (ret_truncated) + *ret_truncated = truncated; + return size; } -size_t strpcpyl(char **dest, size_t size, const char *src, ...) { +size_t strpcpyl_full(char **dest, size_t size, bool *ret_truncated, const char *src, ...) { + bool truncated = false; va_list va; assert(dest); @@ -75,31 +91,38 @@ size_t strpcpyl(char **dest, size_t size, const char *src, ...) { va_start(va, src); do { - size = strpcpy(dest, size, src); + bool t; + + size = strpcpy_full(dest, size, src, &t); + truncated = truncated || t; src = va_arg(va, char *); } while (src); va_end(va); + + if (ret_truncated) + *ret_truncated = truncated; return size; } -size_t strnscpy(char *dest, size_t size, const char *src, size_t len) { +size_t strnscpy_full(char *dest, size_t size, const char *src, size_t len, bool *ret_truncated) { char *s; assert(dest); assert(src); s = dest; - return strnpcpy(&s, size, src, len); + return strnpcpy_full(&s, size, src, len, ret_truncated); } -size_t strscpy(char *dest, size_t size, const char *src) { +size_t strscpy_full(char *dest, size_t size, const char *src, bool *ret_truncated) { assert(dest); assert(src); - return strnscpy(dest, size, src, strlen(src)); + return strnscpy_full(dest, size, src, strlen(src), ret_truncated); } -size_t strscpyl(char *dest, size_t size, const char *src, ...) { +size_t strscpyl_full(char *dest, size_t size, bool *ret_truncated, const char *src, ...) { + bool truncated = false; va_list va; char *s; @@ -109,10 +132,16 @@ size_t strscpyl(char *dest, size_t size, const char *src, ...) { va_start(va, src); s = dest; do { - size = strpcpy(&s, size, src); + bool t; + + size = strpcpy_full(&s, size, src, &t); + truncated = truncated || t; src = va_arg(va, char *); } while (src); va_end(va); + if (ret_truncated) + *ret_truncated = truncated; + return size; } diff --git a/src/libnm-systemd-shared/src/basic/strxcpyx.h b/src/libnm-systemd-shared/src/basic/strxcpyx.h index cdef492d..4a648ed0 100644 --- a/src/libnm-systemd-shared/src/basic/strxcpyx.h +++ b/src/libnm-systemd-shared/src/basic/strxcpyx.h @@ -1,14 +1,33 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include #include #include "macro.h" -size_t strnpcpy(char **dest, size_t size, const char *src, size_t len); -size_t strpcpy(char **dest, size_t size, const char *src); -size_t strpcpyf(char **dest, size_t size, const char *src, ...) _printf_(3, 4); -size_t strpcpyl(char **dest, size_t size, const char *src, ...) _sentinel_; -size_t strnscpy(char *dest, size_t size, const char *src, size_t len); -size_t strscpy(char *dest, size_t size, const char *src); -size_t strscpyl(char *dest, size_t size, const char *src, ...) _sentinel_; +size_t strnpcpy_full(char **dest, size_t size, const char *src, size_t len, bool *ret_truncated); +static inline size_t strnpcpy(char **dest, size_t size, const char *src, size_t len) { + return strnpcpy_full(dest, size, src, len, NULL); +} +size_t strpcpy_full(char **dest, size_t size, const char *src, bool *ret_truncated); +static inline size_t strpcpy(char **dest, size_t size, const char *src) { + return strpcpy_full(dest, size, src, NULL); +} +size_t strpcpyf_full(char **dest, size_t size, bool *ret_truncated, const char *src, ...) _printf_(4, 5); +#define strpcpyf(dest, size, src, ...) \ + strpcpyf_full((dest), (size), NULL, (src), ##__VA_ARGS__) +size_t strpcpyl_full(char **dest, size_t size, bool *ret_truncated, const char *src, ...) _sentinel_; +#define strpcpyl(dest, size, src, ...) \ + strpcpyl_full((dest), (size), NULL, (src), ##__VA_ARGS__) +size_t strnscpy_full(char *dest, size_t size, const char *src, size_t len, bool *ret_truncated); +static inline size_t strnscpy(char *dest, size_t size, const char *src, size_t len) { + return strnscpy_full(dest, size, src, len, NULL); +} +size_t strscpy_full(char *dest, size_t size, const char *src, bool *ret_truncated); +static inline size_t strscpy(char *dest, size_t size, const char *src) { + return strscpy_full(dest, size, src, NULL); +} +size_t strscpyl_full(char *dest, size_t size, bool *ret_truncated, const char *src, ...) _sentinel_; +#define strscpyl(dest, size, src, ...) \ + strscpyl_full(dest, size, NULL, src, ##__VA_ARGS__) diff --git a/src/libnm-systemd-shared/src/basic/time-util.c b/src/libnm-systemd-shared/src/basic/time-util.c index 21e7b24a..d7ea2b38 100644 --- a/src/libnm-systemd-shared/src/basic/time-util.c +++ b/src/libnm-systemd-shared/src/basic/time-util.c @@ -271,7 +271,6 @@ struct timespec *timespec_store_nsec(struct timespec *ts, nsec_t n) { return ts; } -#if 0 /* NM_IGNORED */ usec_t timeval_load(const struct timeval *tv) { assert(tv); @@ -286,6 +285,7 @@ usec_t timeval_load(const struct timeval *tv) { (usec_t) tv->tv_usec; } +#if 0 /* NM_IGNORED */ struct timeval *timeval_store(struct timeval *tv, usec_t u) { assert(tv); @@ -676,7 +676,7 @@ static int parse_timestamp_impl(const char *t, usec_t *usec, bool with_tz) { goto finish; } else if ((k = endswith(t, " ago"))) { - t = strndupa(t, k - t); + t = strndupa_safe(t, k - t); r = parse_sec(t, &minus); if (r < 0) @@ -685,7 +685,7 @@ static int parse_timestamp_impl(const char *t, usec_t *usec, bool with_tz) { goto finish; } else if ((k = endswith(t, " left"))) { - t = strndupa(t, k - t); + t = strndupa_safe(t, k - t); r = parse_sec(t, &plus); if (r < 0) @@ -697,7 +697,7 @@ static int parse_timestamp_impl(const char *t, usec_t *usec, bool with_tz) { /* See if the timestamp is suffixed with UTC */ utc = endswith_no_case(t, " UTC"); if (utc) - t = strndupa(t, utc - t); + t = strndupa_safe(t, utc - t); else { const char *e = NULL; int j; @@ -728,7 +728,7 @@ static int parse_timestamp_impl(const char *t, usec_t *usec, bool with_tz) { if (IN_SET(j, 0, 1)) { /* Found one of the two timezones specified. */ - t = strndupa(t, e - t - 1); + t = strndupa_safe(t, e - t - 1); dst = j; tzn = tzname[j]; } @@ -929,7 +929,7 @@ int parse_timestamp(const char *t, usec_t *usec) { /* Cut off the timezone if we don't need it. */ if (with_tz) - t = strndupa(t, last_space - t); + t = strndupa_safe(t, last_space - t); shared->return_value = parse_timestamp_impl(t, &shared->usec, with_tz); diff --git a/src/libnm-systemd-shared/src/basic/tmpfile-util.c b/src/libnm-systemd-shared/src/basic/tmpfile-util.c index 8a6404d3..dc5a49e2 100644 --- a/src/libnm-systemd-shared/src/basic/tmpfile-util.c +++ b/src/libnm-systemd-shared/src/basic/tmpfile-util.c @@ -67,16 +67,9 @@ int fopen_temporary(const char *path, FILE **ret_f, char **ret_temp_path) { /* This is much like mkostemp() but is subject to umask(). */ int mkostemp_safe(char *pattern) { - int fd = -1; /* avoid false maybe-uninitialized warning */ - assert(pattern); - - RUN_WITH_UMASK(0077) - fd = mkostemp(pattern, O_CLOEXEC); - if (fd < 0) - return -errno; - - return fd; + BLOCK_WITH_UMASK(0077); + return RET_NERRNO(mkostemp(pattern, O_CLOEXEC)); } #if 0 /* NM_IGNORED */ @@ -288,8 +281,6 @@ int open_tmpfile_linkable(const char *target, int flags, char **ret_path) { } int link_tmpfile(int fd, const char *path, const char *target) { - int r; - assert(fd >= 0); assert(target); @@ -300,16 +291,10 @@ int link_tmpfile(int fd, const char *path, const char *target) { * Note that in both cases we will not replace existing files. This is because linkat() does not support this * operation currently (renameat2() does), and there is no nice way to emulate this. */ - if (path) { - r = rename_noreplace(AT_FDCWD, path, AT_FDCWD, target); - if (r < 0) - return r; - } else { - if (linkat(AT_FDCWD, FORMAT_PROC_FD_PATH(fd), AT_FDCWD, target, AT_SYMLINK_FOLLOW) < 0) - return -errno; - } + if (path) + return rename_noreplace(AT_FDCWD, path, AT_FDCWD, target); - return 0; + return RET_NERRNO(linkat(AT_FDCWD, FORMAT_PROC_FD_PATH(fd), AT_FDCWD, target, AT_SYMLINK_FOLLOW)); } int mkdtemp_malloc(const char *template, char **ret) { diff --git a/src/libnm-systemd-shared/src/basic/umask-util.h b/src/libnm-systemd-shared/src/basic/umask-util.h index bd7c2bdb..90d18f70 100644 --- a/src/libnm-systemd-shared/src/basic/umask-util.h +++ b/src/libnm-systemd-shared/src/basic/umask-util.h @@ -24,3 +24,6 @@ assert_cc((S_IFMT & 0777) == 0); for (_cleanup_umask_ mode_t _saved_umask_ = umask(mask) | S_IFMT; \ FLAGS_SET(_saved_umask_, S_IFMT); \ _saved_umask_ &= 0777) + +#define BLOCK_WITH_UMASK(mask) \ + _unused_ _cleanup_umask_ mode_t _saved_umask_ = umask(mask); diff --git a/src/libnm-systemd-shared/src/basic/utf8.c b/src/libnm-systemd-shared/src/basic/utf8.c index dfa010e8..c8e39fe4 100644 --- a/src/libnm-systemd-shared/src/basic/utf8.c +++ b/src/libnm-systemd-shared/src/basic/utf8.c @@ -126,11 +126,9 @@ int utf8_encoded_to_unichar(const char *str, char32_t *ret_unichar) { } bool utf8_is_printable_newline(const char* str, size_t length, bool allow_newline) { - const char *p; - assert(str); - for (p = str; length > 0;) { + for (const char *p = str; length > 0;) { int encoded_len, r; char32_t val; @@ -293,14 +291,12 @@ char *utf8_escape_non_printable_full(const char *str, size_t console_width, bool #endif /* NM_IGNORED */ char *ascii_is_valid(const char *str) { - const char *p; - /* Check whether the string consists of valid ASCII bytes, * i.e values between 0 and 127, inclusive. */ assert(str); - for (p = str; *p; p++) + for (const char *p = str; *p; p++) if ((unsigned char) *p >= 128) return NULL; @@ -322,6 +318,37 @@ char *ascii_is_valid_n(const char *str, size_t len) { } #endif /* NM_IGNORED */ +int utf8_to_ascii(const char *str, char replacement_char, char **ret) { + /* Convert to a string that has only ASCII chars, replacing anything that is not ASCII + * by replacement_char. */ + + _cleanup_free_ char *ans = new(char, strlen(str) + 1); + if (!ans) + return -ENOMEM; + + char *q = ans; + + for (const char *p = str; *p; q++) { + int l; + + l = utf8_encoded_valid_unichar(p, SIZE_MAX); + if (l < 0) /* Non-UTF-8, let's not even try to propagate the garbage */ + return l; + + if (l == 1) + *q = *p; + else + /* non-ASCII, we need to replace it */ + *q = replacement_char; + + p += l; + } + *q = '\0'; + + *ret = TAKE_PTR(ans); + return 0; +} + /** * utf8_encode_unichar() - Encode single UCS-4 character as UTF-8 * @out_utf8: output buffer of at least 4 bytes or NULL diff --git a/src/libnm-systemd-shared/src/basic/utf8.h b/src/libnm-systemd-shared/src/basic/utf8.h index b0e969f6..4a06dd62 100644 --- a/src/libnm-systemd-shared/src/basic/utf8.h +++ b/src/libnm-systemd-shared/src/basic/utf8.h @@ -21,6 +21,8 @@ static inline char *utf8_is_valid(const char *s) { char *ascii_is_valid(const char *s) _pure_; char *ascii_is_valid_n(const char *str, size_t len); +int utf8_to_ascii(const char *str, char replacement_char, char **ret); + bool utf8_is_printable_newline(const char* str, size_t length, bool allow_newline) _pure_; #define utf8_is_printable(str, length) utf8_is_printable_newline(str, length, true) diff --git a/src/libnm-systemd-shared/src/basic/util.c b/src/libnm-systemd-shared/src/basic/util.c index ed328466..3425d0f0 100644 --- a/src/libnm-systemd-shared/src/basic/util.c +++ b/src/libnm-systemd-shared/src/basic/util.c @@ -8,7 +8,6 @@ #include "alloc-util.h" #include "build.h" -#include "dirent-util.h" #include "env-file.h" #include "env-util.h" #include "fd-util.h" @@ -118,71 +117,6 @@ void in_initrd_force(bool value) { saved_in_initrd = value; } -int on_ac_power(void) { - bool found_offline = false, found_online = false; - _cleanup_closedir_ DIR *d = NULL; - struct dirent *de; - - d = opendir("/sys/class/power_supply"); - if (!d) - return errno == ENOENT ? true : -errno; - - FOREACH_DIRENT(de, d, return -errno) { - _cleanup_close_ int fd = -1, device = -1; - char contents[6]; - ssize_t n; - - device = openat(dirfd(d), de->d_name, O_DIRECTORY|O_RDONLY|O_CLOEXEC|O_NOCTTY); - if (device < 0) { - if (IN_SET(errno, ENOENT, ENOTDIR)) - continue; - - return -errno; - } - - fd = openat(device, "type", O_RDONLY|O_CLOEXEC|O_NOCTTY); - if (fd < 0) { - if (errno == ENOENT) - continue; - - return -errno; - } - - n = read(fd, contents, sizeof(contents)); - if (n < 0) - return -errno; - - if (n != 6 || memcmp(contents, "Mains\n", 6)) - continue; - - safe_close(fd); - fd = openat(device, "online", O_RDONLY|O_CLOEXEC|O_NOCTTY); - if (fd < 0) { - if (errno == ENOENT) - continue; - - return -errno; - } - - n = read(fd, contents, sizeof(contents)); - if (n < 0) - return -errno; - - if (n != 2 || contents[1] != '\n') - return -EIO; - - if (contents[0] == '1') { - found_online = true; - break; - } else if (contents[0] == '0') - found_offline = true; - else - return -EIO; - } - - return found_online || !found_offline; -} - int container_get_leader(const char *machine, pid_t *pid) { _cleanup_free_ char *s = NULL, *class = NULL; const char *p; diff --git a/src/libnm-systemd-shared/src/basic/util.h b/src/libnm-systemd-shared/src/basic/util.h index b6c51c03..dd1cb4f3 100644 --- a/src/libnm-systemd-shared/src/basic/util.h +++ b/src/libnm-systemd-shared/src/basic/util.h @@ -20,13 +20,24 @@ int prot_from_flags(int flags) _const_; bool in_initrd(void); void in_initrd_force(bool value); -int on_ac_power(void); - -static inline unsigned u64log2(uint64_t n) { +/* Note: log2(0) == log2(1) == 0 here and below. */ + +#define CONST_LOG2ULL(x) ((x) > 1 ? (unsigned) __builtin_clzll(x) ^ 63U : 0) +#define NONCONST_LOG2ULL(x) ({ \ + unsigned long long _x = (x); \ + _x > 1 ? (unsigned) __builtin_clzll(_x) ^ 63U : 0; \ + }) +#if 0 /* NM_IGNORED */ +#define LOG2ULL(x) __builtin_choose_expr(__builtin_constant_p(x), CONST_LOG2ULL(x), NONCONST_LOG2ULL(x)) +#else /* NM_IGNORED */ +#define LOG2ULL(x) NONCONST_LOG2ULL(x) +#endif /* NM_IGNORED */ + +static inline unsigned log2u64(uint64_t x) { #if __SIZEOF_LONG_LONG__ == 8 - return (n > 1) ? (unsigned) __builtin_clzll(n) ^ 63U : 0; + return LOG2ULL(x); #else -#error "Wut?" +# error "Wut?" #endif } @@ -34,26 +45,31 @@ static inline unsigned u32ctz(uint32_t n) { #if __SIZEOF_INT__ == 4 return n != 0 ? __builtin_ctz(n) : 32; #else -#error "Wut?" +# error "Wut?" #endif } -static inline unsigned log2i(int x) { - assert(x > 0); +#define CONST_LOG2U(x) ((x) > 1 ? __SIZEOF_INT__ * 8 - __builtin_clz(x) - 1 : 0) +#define NONCONST_LOG2U(x) ({ \ + unsigned _x = (x); \ + _x > 1 ? __SIZEOF_INT__ * 8 - __builtin_clz(_x) - 1 : 0; \ + }) +#if 0 /* NM_IGNORED */ +#define LOG2U(x) __builtin_choose_expr(__builtin_constant_p(x), CONST_LOG2U(x), NONCONST_LOG2U(x)) +#else /* NM_IGNORED */ +#define LOG2U(x) NONCONST_LOG2U(x) +#endif /* NM_IGNORED */ - return __SIZEOF_INT__ * 8 - __builtin_clz(x) - 1; +static inline unsigned log2i(int x) { + return LOG2U(x); } static inline unsigned log2u(unsigned x) { - assert(x > 0); - - return sizeof(unsigned) * 8 - __builtin_clz(x) - 1; + return LOG2U(x); } static inline unsigned log2u_round_up(unsigned x) { - assert(x > 0); - - if (x == 1) + if (x <= 1) return 0; return log2u(x - 1) + 1; diff --git a/src/libnm-systemd-shared/src/fundamental/macro-fundamental.h b/src/libnm-systemd-shared/src/fundamental/macro-fundamental.h index 20d8dabf..d597c743 100644 --- a/src/libnm-systemd-shared/src/fundamental/macro-fundamental.h +++ b/src/libnm-systemd-shared/src/fundamental/macro-fundamental.h @@ -5,13 +5,15 @@ #include #endif -#include "type.h" +#include +#include "types-fundamental.h" #define _align_(x) __attribute__((__aligned__(x))) #define _const_ __attribute__((__const__)) #define _pure_ __attribute__((__pure__)) #define _section_(x) __attribute__((__section__(x))) #define _packed_ __attribute__((__packed__)) +#define _retain_ __attribute__((__retain__)) #define _used_ __attribute__((__used__)) #define _unused_ __attribute__((__unused__)) #define _cleanup_(x) __attribute__((__cleanup__(x))) @@ -59,8 +61,19 @@ #define assert(expr) ({ _likely_(expr) ? VOID_0 : efi_assert(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__); }) #define assert_not_reached() efi_assert("Code should not be reached", __FILE__, __LINE__, __PRETTY_FUNCTION__) #endif + + #define memcpy(a, b, c) CopyMem((a), (b), (c)) + #define free(a) FreePool(a) #endif +/* This passes the argument through after (if asserts are enabled) checking that it is not null. */ +#define ASSERT_PTR(expr) \ + ({ \ + typeof(expr) _expr_ = (expr); \ + assert(_expr_); \ + _expr_; \ + }) + #if defined(static_assert) #define assert_cc(expr) \ static_assert(expr, #expr) @@ -81,8 +94,8 @@ #define ONCE __ONCE(UNIQ_T(_once_, UNIQ)) #define __ONCE(o) \ ({ \ - static bool (o) = false; \ - __sync_bool_compare_and_swap(&(o), false, true); \ + static sd_bool (o) = sd_false; \ + __sync_bool_compare_and_swap(&(o), sd_false, sd_true); \ }) #undef MAX @@ -232,7 +245,7 @@ #define IN_SET(x, ...) \ ({ \ - sd_bool _found = false; \ + sd_bool _found = sd_false; \ /* If the build breaks in the line below, you need to extend the case macros. (We use "long double" as \ * type for the array, in the hope that checkers such as ubsan don't complain that the initializers for \ * the array are not representable by the base type. Ideally we'd use typeof(x) as base type, but that \ @@ -241,7 +254,7 @@ assert_cc(ELEMENTSOF(__assert_in_set) <= 20); \ switch(x) { \ FOR_EACH_MAKE_CASE(__VA_ARGS__) \ - _found = true; \ + _found = sd_true; \ break; \ default: \ break; \ @@ -253,8 +266,9 @@ * resets it to NULL. See: https://doc.rust-lang.org/std/option/enum.Option.html#method.take */ #define TAKE_PTR(ptr) \ ({ \ - typeof(ptr) _ptr_ = (ptr); \ - (ptr) = NULL; \ + typeof(ptr) *_pptr_ = &(ptr); \ + typeof(ptr) _ptr_ = *_pptr_; \ + *_pptr_ = NULL; \ _ptr_; \ }) @@ -264,3 +278,47 @@ * @x: a string literal. */ #define STRLEN(x) (sizeof(""x"") - sizeof(typeof(x[0]))) + +#define mfree(memory) \ + ({ \ + free(memory); \ + (typeof(memory)) NULL; \ + }) + +static inline size_t ALIGN_TO(size_t l, size_t ali) { + /* sd-boot uses UINTN for size_t, let's make sure SIZE_MAX is correct. */ + assert_cc(SIZE_MAX == ~(size_t)0); + + /* Check that alignment is exponent of 2 */ +#if SIZE_MAX == UINT_MAX + assert(__builtin_popcount(ali) == 1); +#elif SIZE_MAX == ULONG_MAX + assert(__builtin_popcountl(ali) == 1); +#elif SIZE_MAX == ULLONG_MAX + assert(__builtin_popcountll(ali) == 1); +#else + #error "Unexpected size_t" +#endif + + if (l > SIZE_MAX - (ali - 1)) + return SIZE_MAX; /* indicate overflow */ + + return ((l + ali - 1) & ~(ali - 1)); +} + +/* Same as ALIGN_TO but callable in constant contexts. */ +#define CONST_ALIGN_TO(l, ali) \ + __builtin_choose_expr( \ + __builtin_constant_p(l) && \ + __builtin_constant_p(ali) && \ + __builtin_popcountll(ali) == 1 && /* is power of 2? */ \ + (l <= SIZE_MAX - (ali - 1)), /* overflow? */ \ + ((l) + (ali) - 1) & ~((ali) - 1), \ + VOID_0) + +#define UPDATE_FLAG(orig, flag, b) \ + ((b) ? ((orig) | (flag)) : ((orig) & ~(flag))) +#define SET_FLAG(v, flag, b) \ + (v) = UPDATE_FLAG(v, flag, b) +#define FLAGS_SET(v, flags) \ + ((~(v) & (flags)) == 0) diff --git a/src/libnm-systemd-shared/src/fundamental/string-util-fundamental.c b/src/libnm-systemd-shared/src/fundamental/string-util-fundamental.c index f1703926..73569765 100644 --- a/src/libnm-systemd-shared/src/fundamental/string-util-fundamental.c +++ b/src/libnm-systemd-shared/src/fundamental/string-util-fundamental.c @@ -10,7 +10,7 @@ #include "string-util-fundamental.h" sd_char *startswith(const sd_char *s, const sd_char *prefix) { - sd_size_t l; + size_t l; assert(s); assert(prefix); @@ -24,7 +24,7 @@ sd_char *startswith(const sd_char *s, const sd_char *prefix) { #ifndef SD_BOOT sd_char *startswith_no_case(const sd_char *s, const sd_char *prefix) { - sd_size_t l; + size_t l; assert(s); assert(prefix); @@ -38,7 +38,7 @@ sd_char *startswith_no_case(const sd_char *s, const sd_char *prefix) { #endif sd_char* endswith(const sd_char *s, const sd_char *postfix) { - sd_size_t sl, pl; + size_t sl, pl; assert(s); assert(postfix); @@ -59,7 +59,7 @@ sd_char* endswith(const sd_char *s, const sd_char *postfix) { } sd_char* endswith_no_case(const sd_char *s, const sd_char *postfix) { - sd_size_t sl, pl; + size_t sl, pl; assert(s); assert(postfix); diff --git a/src/libnm-systemd-shared/src/fundamental/string-util-fundamental.h b/src/libnm-systemd-shared/src/fundamental/string-util-fundamental.h index 7455c054..dc0c1202 100644 --- a/src/libnm-systemd-shared/src/fundamental/string-util-fundamental.h +++ b/src/libnm-systemd-shared/src/fundamental/string-util-fundamental.h @@ -68,10 +68,10 @@ static inline const sd_char *yes_no(sd_bool b) { sd_int strverscmp_improved(const sd_char *a, const sd_char *b); /* Like startswith(), but operates on arbitrary memory blocks */ -static inline void *memory_startswith(const void *p, sd_size_t sz, const sd_char *token) { +static inline void *memory_startswith(const void *p, size_t sz, const sd_char *token) { assert(token); - sd_size_t n = strlen(token) * sizeof(sd_char); + size_t n = strlen(token) * sizeof(sd_char); if (sz < n) return NULL; diff --git a/src/libnm-systemd-shared/src/fundamental/type.h b/src/libnm-systemd-shared/src/fundamental/type.h deleted file mode 100644 index f645d2de..00000000 --- a/src/libnm-systemd-shared/src/fundamental/type.h +++ /dev/null @@ -1,22 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -#pragma once - -#ifdef SD_BOOT -#include - -typedef BOOLEAN sd_bool; -typedef CHAR16 sd_char; -typedef INTN sd_int; -typedef UINTN sd_size_t; - -#define true TRUE -#define false FALSE -#else -#include -#include - -typedef bool sd_bool; -typedef char sd_char; -typedef int sd_int; -typedef size_t sd_size_t; -#endif diff --git a/src/libnm-systemd-shared/src/fundamental/types-fundamental.h b/src/libnm-systemd-shared/src/fundamental/types-fundamental.h new file mode 100644 index 00000000..5977e40c --- /dev/null +++ b/src/libnm-systemd-shared/src/fundamental/types-fundamental.h @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +/* This defines a number of basic types that are one thing in userspace and another in the UEFI environment, + * but mostly the same in concept and behaviour. + * + * Note: if the definition of these types/values has slightly different semantics in userspace and in the + * UEFI environment then please prefix its name with "sd_" to make clear these types have special semantics, + * and *we* defined them. Otherwise, if the types are effectively 100% identical in behaviour in userspace + * and UEFI environment you can omit the prefix. (Examples: sd_char is 8 bit in userspace and 16 bit in UEFI + * space hence it should have the sd_ prefix; but size_t in userspace and UINTN in UEFI environment are 100% + * defined the same way ultimately, hence it's OK to just define size_t as alias to UINTN in UEFI + * environment, so that size_t can be used everywhere, without any "sd_" prefix.) + * + * Note: we generally prefer the userspace names of types and concepts. i.e. if in doubt please name types + * after the userspace vocabulary, and let's keep UEFI vocabulary specific to the UEFI build environment. */ + +#ifdef SD_BOOT +#include + +typedef BOOLEAN sd_bool; +typedef CHAR16 sd_char; +typedef INTN sd_int; +typedef UINTN size_t; + +#define sd_true TRUE +#define sd_false FALSE +#else +#include +#include + +typedef bool sd_bool; +typedef char sd_char; +typedef int sd_int; + +#define sd_true true +#define sd_false false + +#endif diff --git a/src/libnm-systemd-shared/src/shared/dns-domain.c b/src/libnm-systemd-shared/src/shared/dns-domain.c index 473f6a02..b82a9a1c 100644 --- a/src/libnm-systemd-shared/src/shared/dns-domain.c +++ b/src/libnm-systemd-shared/src/shared/dns-domain.c @@ -687,7 +687,7 @@ int dns_name_change_suffix(const char *name, const char *old_suffix, const char } /* Found it! Now generate the new name */ - prefix = strndupa(name, saved_before - name); + prefix = strndupa_safe(name, saved_before - name); r = dns_name_concat(prefix, new_suffix, 0, ret); if (r < 0) @@ -1037,7 +1037,7 @@ static bool dns_service_name_label_is_valid(const char *label, size_t n) { if (memchr(label, 0, n)) return false; - s = strndupa(label, n); + s = strndupa_safe(label, n); return dns_service_name_is_valid(s); } diff --git a/src/libnm-systemd-shared/src/shared/dns-domain.h b/src/libnm-systemd-shared/src/shared/dns-domain.h index d0195c58..c237f761 100644 --- a/src/libnm-systemd-shared/src/shared/dns-domain.h +++ b/src/libnm-systemd-shared/src/shared/dns-domain.h @@ -62,6 +62,10 @@ static inline int dns_name_is_valid_ldh(const char *s) { return 1; } +static inline bool dns_name_is_empty(const char *s) { + return isempty(s) || streq(s, "."); +} + void dns_name_hash_func(const char *s, struct siphash *state); int dns_name_compare_func(const char *a, const char *b); extern const struct hash_ops dns_name_hash_ops; diff --git a/src/libnm-udev-aux/nm-udev-utils.c b/src/libnm-udev-aux/nm-udev-utils.c index ef1cf26b..744d03ce 100644 --- a/src/libnm-udev-aux/nm-udev-utils.c +++ b/src/libnm-udev-aux/nm-udev-utils.c @@ -10,9 +10,9 @@ #include struct _NMPUdevClient { - char ** subsystems; - GSource * watch_source; - struct udev * udev; + char **subsystems; + GSource *watch_source; + struct udev *udev; struct udev_monitor *monitor; NMUdevClientEvent event_handler; gpointer event_user_data; @@ -36,8 +36,8 @@ const char * nm_udev_utils_property_decode(const char *uproperty, char **to_free) { const char *p; - char * unescaped = NULL; - char * n = NULL; + char *unescaped = NULL; + char *n = NULL; if (!uproperty) { *to_free = NULL; @@ -87,10 +87,10 @@ nm_udev_utils_property_decode_cp(const char *uproperty) /*****************************************************************************/ static void -_subsystem_split(const char * subsystem_full, +_subsystem_split(const char *subsystem_full, const char **out_subsystem, const char **out_devtype, - char ** to_free) + char **to_free) { char *tmp, *s; @@ -124,8 +124,8 @@ nm_udev_utils_enumerate(struct udev *uclient, const char *const *subsystems) if (subsystems) { for (n = 0; subsystems[n]; n++) { - const char * subsystem; - const char * devtype; + const char *subsystem; + const char *devtype; gs_free char *to_free = NULL; _subsystem_split(subsystems[n], &subsystem, &devtype, &to_free); @@ -161,7 +161,7 @@ nm_udev_client_enumerate_new(NMUdevClient *self) static gboolean monitor_event(int fd, GIOCondition condition, gpointer user_data) { - NMUdevClient * self = user_data; + NMUdevClient *self = user_data; struct udev_device *udevice; if (!self->monitor) @@ -217,8 +217,8 @@ nm_udev_client_new(const char *const *subsystems, /* install subsystem filters to only wake up for certain events */ for (n = 0; self->subsystems[n]; n++) { gs_free char *to_free = NULL; - const char * subsystem; - const char * devtype; + const char *subsystem; + const char *devtype; _subsystem_split(self->subsystems[n], &subsystem, &devtype, &to_free); udev_monitor_filter_add_match_subsystem_devtype(self->monitor, subsystem, devtype); diff --git a/src/libnm-udev-aux/nm-udev-utils.h b/src/libnm-udev-aux/nm-udev-utils.h index 191f9a89..1c04fc58 100644 --- a/src/libnm-udev-aux/nm-udev-utils.h +++ b/src/libnm-udev-aux/nm-udev-utils.h @@ -12,11 +12,11 @@ struct udev_enumerate; gboolean nm_udev_utils_property_as_boolean(const char *uproperty); const char *nm_udev_utils_property_decode(const char *uproperty, char **to_free); -char * nm_udev_utils_property_decode_cp(const char *uproperty); +char *nm_udev_utils_property_decode_cp(const char *uproperty); typedef struct _NMPUdevClient NMUdevClient; -typedef void (*NMUdevClientEvent)(NMUdevClient * udev_client, +typedef void (*NMUdevClientEvent)(NMUdevClient *udev_client, struct udev_device *udevice, gpointer event_user_data); diff --git a/src/libnmc-base/nm-client-utils.c b/src/libnmc-base/nm-client-utils.c index 49234d97..01b3df32 100644 --- a/src/libnmc-base/nm-client-utils.c +++ b/src/libnmc-base/nm-client-utils.c @@ -55,14 +55,14 @@ nmc_objects_sort_by_path(const NMObject *const *objs, gssize len) * If required, the resulting number is checked to be in the range. */ static gboolean -nmc_string_to_uint_base(const char * str, +nmc_string_to_uint_base(const char *str, int base, gboolean range_check, unsigned long int min, unsigned long int max, unsigned long int *value) { - char * end; + char *end; unsigned long int tmp; if (!str || !str[0]) @@ -79,7 +79,7 @@ nmc_string_to_uint_base(const char * str, } gboolean -nmc_string_to_uint(const char * str, +nmc_string_to_uint(const char *str, gboolean range_check, unsigned long int min, unsigned long int max, @@ -130,10 +130,10 @@ nmc_string_to_bool(const char *str, gboolean *val_bool, GError **error) } gboolean -nmc_string_to_ternary_full(const char * str, +nmc_string_to_ternary_full(const char *str, NMCStringToTernaryFlags flags, - NMTernary * val, - GError ** error) + NMTernary *val, + GError **error) { gs_free char *str_to_free = NULL; int i; @@ -194,7 +194,7 @@ _nmc_string_is_valid(const char *input, const char *const *allowed, GError **err { const char *const *p; size_t input_ln, p_len; - const char * partial_match = NULL; + const char *partial_match = NULL; gboolean ambiguous = FALSE; g_return_val_if_fail(!error || !*error, NULL); @@ -324,7 +324,7 @@ nmc_device_state_to_string_with_external(NMDevice *device) { NMActiveConnection *ac; NMDeviceState state; - const char * s; + const char *s; state = nm_device_get_state(device); @@ -501,8 +501,8 @@ NM_UTILS_LOOKUP_STR_DEFINE( NMActiveConnectionState nmc_activation_get_effective_state(NMActiveConnection *active, - NMDevice * device, - const char ** reason) + NMDevice *device, + const char **reason) { NMActiveConnectionState ac_state; NMActiveConnectionStateReason ac_reason; @@ -569,7 +569,7 @@ can_show_utf8(void) { static gboolean can_show_utf8_set = FALSE; static gboolean can_show_utf8 = TRUE; - char * locale_str; + char *locale_str; if (G_LIKELY(can_show_utf8_set)) return can_show_utf8; @@ -763,12 +763,12 @@ nmc_utils_read_passwd_file(const char *passwd_file, gssize *out_error_line, GErr } GHashTable * -nmc_utils_parse_passwd_file(char * contents /* will be modified */, - gssize * out_error_line, +nmc_utils_parse_passwd_file(char *contents /* will be modified */, + gssize *out_error_line, GError **error) { gs_unref_hashtable GHashTable *pwds_hash = NULL; - const char * contents_str; + const char *contents_str; gsize contents_line; pwds_hash = @@ -781,11 +781,11 @@ nmc_utils_parse_passwd_file(char * contents /* will be modified */, while (contents_str[0]) { nm_auto_free_secret char *l_hash_key = NULL; nm_auto_free_secret char *l_hash_val = NULL; - const char * l_content_line; - const char * l_setting; - const char * l_prop; - const char * l_val; - const char * s; + const char *l_content_line; + const char *l_setting; + const char *l_prop; + const char *l_val; + const char *s; gsize l_hash_val_len; /* consume first line. As line delimiters we accept "\r\n", "\n", and "\r". */ diff --git a/src/libnmc-base/nm-client-utils.h b/src/libnmc-base/nm-client-utils.h index 1fc18aca..7d6ec707 100644 --- a/src/libnmc-base/nm-client-utils.h +++ b/src/libnmc-base/nm-client-utils.h @@ -17,7 +17,7 @@ const char *_nmc_string_is_valid(const char *input, const char *const *allowed, #define nmc_string_is_valid(input, allowed, error) \ _nmc_string_is_valid((input), NM_CAST_STRV_CC(allowed), (error)) -gboolean nmc_string_to_uint(const char * str, +gboolean nmc_string_to_uint(const char *str, gboolean range_check, unsigned long int min, unsigned long int max, @@ -29,10 +29,10 @@ typedef enum { NMC_STRING_TO_TERNARY_FLAGS_IGNORE_FOR_DEFAULT = (1LL << 0), } NMCStringToTernaryFlags; -gboolean nmc_string_to_ternary_full(const char * str, +gboolean nmc_string_to_ternary_full(const char *str, NMCStringToTernaryFlags flags, - NMTernary * val, - GError ** error); + NMTernary *val, + GError **error); static inline gboolean nmc_string_to_ternary(const char *str, NMTernary *val, GError **error) @@ -53,8 +53,8 @@ const char *nmc_device_reason_to_string(NMDeviceStateReason reason); const char *nmc_device_metered_to_string(NMMetered value); NMActiveConnectionState nmc_activation_get_effective_state(NMActiveConnection *active, - NMDevice * device, - const char ** reason); + NMDevice *device, + const char **reason); const char *nmc_wifi_strength_bars(guint8 strength); diff --git a/src/libnmc-base/nm-polkit-listener.c b/src/libnmc-base/nm-polkit-listener.c index 29c25b4e..39a06bc6 100644 --- a/src/libnmc-base/nm-polkit-listener.c +++ b/src/libnmc-base/nm-polkit-listener.c @@ -59,9 +59,9 @@ static guint signals[LAST_SIGNAL] = {0}; struct _NMPolkitListener { GObject parent; GDBusConnection *dbus_connection; - char * name_owner; - GCancellable * cancellable; - GMainContext * main_context; + char *name_owner; + GCancellable *cancellable; + GMainContext *main_context; CList request_lst_head; guint pk_auth_agent_reg_id; guint name_owner_changed_id; @@ -79,14 +79,14 @@ G_DEFINE_TYPE(NMPolkitListener, nm_polkit_listener, G_TYPE_OBJECT); typedef struct { CList request_lst; - NMPolkitListener * listener; - GSource * child_stdout_watch_source; - GSource * child_stdin_watch_source; + NMPolkitListener *listener; + GSource *child_stdout_watch_source; + GSource *child_stdin_watch_source; GDBusMethodInvocation *dbus_invocation; - char * action_id; - char * message; - char * username; - char * cookie; + char *action_id; + char *message; + char *username; + char *cookie; NMStrBuf in_buffer; NMStrBuf out_buffer; gsize out_buffer_offset; @@ -163,11 +163,11 @@ static char * choose_identity(GVariant *identities) { GVariantIter identity_iter; - GVariant * details_tmp; - const char * kind; + GVariant *details_tmp; + const char *kind; gs_free char *username_first = NULL; gs_free char *username_root = NULL; - const char * user; + const char *user; /* Choose identity. First try current user, then root, and else * take the first one we find. */ @@ -221,10 +221,10 @@ choose_identity(GVariant *identities) static void agent_register_cb(GObject *source_object, GAsyncResult *res, gpointer user_data) { - NMPolkitListener *listener = NM_POLKIT_LISTENER(user_data); - GDBusConnection * dbus_connection = G_DBUS_CONNECTION(source_object); - gs_free_error GError *error = NULL; - gs_unref_variant GVariant *ret = NULL; + NMPolkitListener *listener = NM_POLKIT_LISTENER(user_data); + GDBusConnection *dbus_connection = G_DBUS_CONNECTION(source_object); + gs_free_error GError *error = NULL; + gs_unref_variant GVariant *ret = NULL; ret = g_dbus_connection_call_finish(dbus_connection, res, &error); @@ -242,9 +242,9 @@ agent_register_cb(GObject *source_object, GAsyncResult *res, gpointer user_data) static void agent_register(NMPolkitListener *self, const char *session_id) { - const char * locale = NULL; + const char *locale = NULL; gs_unref_object NMAuthSubject *subject = NULL; - GVariant * subject_variant = NULL; + GVariant *subject_variant = NULL; locale = g_getenv("LANG"); if (locale == NULL) { @@ -277,7 +277,7 @@ static void agent_unregister(NMPolkitListener *self) { gs_unref_object NMAuthSubject *subject = NULL; - GVariant * subject_variant = NULL; + GVariant *subject_variant = NULL; subject = nm_auth_subject_new_unix_process_self(); subject_variant = nm_auth_subject_unix_to_polkit_gvariant(subject); @@ -299,14 +299,14 @@ agent_unregister(NMPolkitListener *self) static void retrieve_session_id_cb(GObject *source_object, GAsyncResult *res, gpointer user_data) { - NMPolkitListener * listener = NM_POLKIT_LISTENER(user_data); - char * session_id; - guint32 session_uid; - nm_auto_free_variant_iter GVariantIter *iter = NULL; - gs_unref_variant GVariant *ret = NULL; - gs_free_error GError *error = NULL; - gs_free char * err_str = NULL; - uid_t uid = getuid(); + NMPolkitListener *listener = NM_POLKIT_LISTENER(user_data); + char *session_id; + guint32 session_uid; + nm_auto_free_variant_iter GVariantIter *iter = NULL; + gs_unref_variant GVariant *ret = NULL; + gs_free_error GError *error = NULL; + gs_free char *err_str = NULL; + uid_t uid = getuid(); ret = g_dbus_connection_call_finish(listener->dbus_connection, res, &error); @@ -437,7 +437,7 @@ io_watch_have_data(int fd, GIOCondition condition, gpointer user_data) } while (TRUE) { - char * line_terminator; + char *line_terminator; const char *line; line = nm_str_buf_get_str(&request->in_buffer); @@ -568,12 +568,12 @@ get_request(NMPolkitListener *listener, const char *cookie) } static AuthRequest * -create_request(NMPolkitListener * listener, +create_request(NMPolkitListener *listener, GDBusMethodInvocation *invocation, - const char * action_id, - const char * message, - char * username_take, - const char * cookie) + const char *action_id, + const char *message, + char *username_take, + const char *cookie) { AuthRequest *request; @@ -596,20 +596,20 @@ create_request(NMPolkitListener * listener, } static void -dbus_method_call_cb(GDBusConnection * connection, - const char * sender, - const char * object_path, - const char * interface_name, - const char * method_name, - GVariant * parameters, +dbus_method_call_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) { - NMPolkitListener *listener = NM_POLKIT_LISTENER(user_data); - const char * action_id; - const char * message; - const char * cookie; - AuthRequest * request; + NMPolkitListener *listener = NM_POLKIT_LISTENER(user_data); + const char *action_id; + const char *message; + const char *cookie; + AuthRequest *request; gs_unref_variant GVariant *identities_gvariant = NULL; if (nm_streq(method_name, "BeginAuthentication")) { @@ -724,15 +724,15 @@ name_owner_changed(NMPolkitListener *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) { NMPolkitListener *self = user_data; - const char * new_owner; + const char *new_owner; if (!g_variant_is_of_type(parameters, G_VARIANT_TYPE("(sss)"))) { return; @@ -829,7 +829,7 @@ static void dispose(GObject *object) { NMPolkitListener *self = NM_POLKIT_LISTENER(object); - AuthRequest * request; + AuthRequest *request; nm_clear_g_cancellable(&self->cancellable); diff --git a/src/libnmc-base/nm-secret-agent-simple.c b/src/libnmc-base/nm-secret-agent-simple.c index a3d5062d..5651a15b 100644 --- a/src/libnmc-base/nm-secret-agent-simple.c +++ b/src/libnmc-base/nm-secret-agent-simple.c @@ -34,12 +34,12 @@ typedef struct { NMSecretAgentSimple *self; - NMConnection * connection; - const char * setting_name; - char ** hints; + NMConnection *connection; + const char *setting_name; + char **hints; NMSecretAgentOldGetSecretsFunc callback; gpointer callback_data; - GCancellable * cancellable; + GCancellable *cancellable; NMSecretAgentGetSecretsFlags flags; } RequestData; @@ -54,7 +54,7 @@ static guint signals[LAST_SIGNAL] = {0}; typedef struct { GHashTable *requests; - char * path; + char *path; gboolean enabled; } NMSecretAgentSimplePrivate; @@ -88,12 +88,12 @@ _request_data_free(gpointer data) } static void -_request_data_complete(RequestData * request, - GVariant * secrets, - GError * error, +_request_data_complete(RequestData *request, + GVariant *secrets, + GError *error, GHashTableIter *iter_to_remove) { - NMSecretAgentSimple * self = request->self; + NMSecretAgentSimple *self = request->self; NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE(self); nm_assert((secrets != NULL) != (error != NULL)); @@ -124,8 +124,8 @@ _request_data_complete(RequestData * request, typedef struct { NMSecretAgentSimpleSecret base; - NMSetting * setting; - char * property; + NMSetting *setting; + char *property; } SecretReal; static void @@ -145,11 +145,11 @@ _secret_real_free(NMSecretAgentSimpleSecret *secret) static NMSecretAgentSimpleSecret * _secret_real_new_plain(NMSecretAgentSecretType secret_type, - const char * pretty_name, - NMSetting * setting, - const char * property) + const char *pretty_name, + NMSetting *setting, + const char *property) { - SecretReal * real; + SecretReal *real; gs_free char *value = NULL; nm_assert(property); @@ -178,7 +178,7 @@ _secret_real_new_plain(NMSecretAgentSecretType secret_type, static NMSecretAgentSimpleSecret * _secret_real_new_vpn_secret(const char *pretty_name, - NMSetting * setting, + NMSetting *setting, const char *property, const char *vpn_type) { @@ -208,8 +208,8 @@ _secret_real_new_vpn_secret(const char *pretty_name, static NMSecretAgentSimpleSecret * _secret_real_new_wireguard_peer_psk(NMSettingWireGuard *s_wg, - const char * public_key, - const char * preshared_key) + const char *public_key, + const char *preshared_key) { SecretReal *real; @@ -238,8 +238,8 @@ _secret_real_new_wireguard_peer_psk(NMSettingWireGuard *s_wg, static gboolean add_8021x_secrets(RequestData *request, GPtrArray *secrets) { - NMSetting8021x * s_8021x = nm_connection_get_setting_802_1x(request->connection); - const char * eap_method; + NMSetting8021x *s_8021x = nm_connection_get_setting_802_1x(request->connection); + const char *eap_method; NMSecretAgentSimpleSecret *secret; /* If hints are given, then always ask for what the hints require */ @@ -301,7 +301,7 @@ add_wireless_secrets(RequestData *request, GPtrArray *secrets) { NMSettingWirelessSecurity *s_wsec = nm_connection_get_setting_wireless_security(request->connection); - const char * key_mgmt = nm_setting_wireless_security_get_key_mgmt(s_wsec); + const char *key_mgmt = nm_setting_wireless_security_get_key_mgmt(s_wsec); NMSecretAgentSimpleSecret *secret; if (!key_mgmt || nm_streq(key_mgmt, "owe")) @@ -350,7 +350,7 @@ add_wireless_secrets(RequestData *request, GPtrArray *secrets) static gboolean add_pppoe_secrets(RequestData *request, GPtrArray *secrets) { - NMSettingPppoe * s_pppoe = nm_connection_get_setting_pppoe(request->connection); + NMSettingPppoe *s_pppoe = nm_connection_get_setting_pppoe(request->connection); NMSecretAgentSimpleSecret *secret; secret = _secret_real_new_plain(NM_SECRET_AGENT_SECRET_TYPE_PROPERTY, @@ -375,7 +375,7 @@ static NMSettingSecretFlags get_vpn_secret_flags(NMSettingVpn *s_vpn, const char *secret_name) { NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE; - GHashTable * vpn_data; + GHashTable *vpn_data; g_object_get(s_vpn, NM_SETTING_VPN_DATA, &vpn_data, NULL); nm_vpn_service_plugin_get_secret_flags(vpn_data, secret_name, &flags); @@ -385,10 +385,10 @@ get_vpn_secret_flags(NMSettingVpn *s_vpn, const char *secret_name) } static void -add_vpn_secret_helper(GPtrArray * secrets, +add_vpn_secret_helper(GPtrArray *secrets, NMSettingVpn *s_vpn, - const char * name, - const char * ui_name) + const char *name, + const char *ui_name) { NMSecretAgentSimpleSecret *secret; NMSettingSecretFlags flags; @@ -421,10 +421,10 @@ add_vpn_secret_helper(GPtrArray * secrets, static gboolean add_vpn_secrets(RequestData *request, GPtrArray *secrets, char **msg) { - NMSettingVpn * s_vpn = nm_connection_get_setting_vpn(request->connection); + NMSettingVpn *s_vpn = nm_connection_get_setting_vpn(request->connection); const NmcVpnPasswordName *p; - const char * vpn_msg = NULL; - char ** iter; + const char *vpn_msg = NULL; + char **iter; /* If hints are given, then always ask for what the hints require */ if (request->hints) { @@ -451,7 +451,7 @@ add_vpn_secrets(RequestData *request, GPtrArray *secrets, char **msg) static gboolean add_wireguard_secrets(RequestData *request, GPtrArray *secrets, char **msg, GError **error) { - NMSettingWireGuard * s_wg; + NMSettingWireGuard *s_wg; NMSecretAgentSimpleSecret *secret; guint i; @@ -479,8 +479,8 @@ add_wireguard_secrets(RequestData *request, GPtrArray *secrets, char **msg, GErr if (request->hints) { for (i = 0; request->hints[i]; i++) { NMWireGuardPeer *peer; - const char * name = request->hints[i]; - gs_free char * public_key = NULL; + const char *name = request->hints[i]; + gs_free char *public_key = NULL; if (nm_streq(name, NM_SETTING_WIREGUARD_PRIVATE_KEY)) continue; @@ -516,13 +516,13 @@ add_wireguard_secrets(RequestData *request, GPtrArray *secrets, char **msg, GErr typedef struct { GPid auth_dialog_pid; - GString * auth_dialog_response; - RequestData * request; - GPtrArray * secrets; - GCancellable * cancellable; + GString *auth_dialog_response; + RequestData *request; + GPtrArray *secrets; + GCancellable *cancellable; gulong cancellable_id; guint child_watch_id; - GInputStream * input_stream; + GInputStream *input_stream; GOutputStream *output_stream; char read_buf[5]; } AuthDialogData; @@ -544,16 +544,16 @@ _auth_dialog_data_free(AuthDialogData *data) static void _auth_dialog_exited(GPid pid, int status, gpointer user_data) { - AuthDialogData * data = user_data; - RequestData * request = data->request; - GPtrArray * secrets = data->secrets; - NMSettingVpn * s_vpn = nm_connection_get_setting_vpn(request->connection); + AuthDialogData *data = user_data; + RequestData *request = data->request; + GPtrArray *secrets = data->secrets; + NMSettingVpn *s_vpn = nm_connection_get_setting_vpn(request->connection); nm_auto_unref_keyfile GKeyFile *keyfile = NULL; - gs_strfreev char ** groups = NULL; - gs_free char * title = NULL; - gs_free char * message = NULL; + gs_strfreev char **groups = NULL; + gs_free char *title = NULL; + gs_free char *message = NULL; int i; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; data->child_watch_id = 0; @@ -646,9 +646,9 @@ _request_cancelled(GObject *object, gpointer user_data) static void _auth_dialog_read_done(GObject *source_object, GAsyncResult *res, gpointer user_data) { - GInputStream * auth_dialog_out = G_INPUT_STREAM(source_object); - AuthDialogData *data = user_data; - gssize read_size; + GInputStream *auth_dialog_out = G_INPUT_STREAM(source_object); + AuthDialogData *data = user_data; + gssize read_size; gs_free_error GError *error = NULL; read_size = g_input_stream_read_finish(auth_dialog_out, res, &error); @@ -684,7 +684,7 @@ _auth_dialog_read_done(GObject *source_object, GAsyncResult *res, gpointer user_ static void _auth_dialog_write_done(GObject *source_object, GAsyncResult *res, gpointer user_data) { - GOutputStream *auth_dialog_out = G_OUTPUT_STREAM(source_object); + GOutputStream *auth_dialog_out = G_OUTPUT_STREAM(source_object); _nm_unused gs_free char *auth_dialog_request_free = user_data; /* We don't care about write errors. If there are any problems, the @@ -732,20 +732,20 @@ _add_secret_to_string(const char *key, const char *value, gpointer user_data) static gboolean try_spawn_vpn_auth_helper(RequestData *request, GPtrArray *secrets) { - NMSettingVpn * s_vpn = nm_connection_get_setting_vpn(request->connection); + NMSettingVpn *s_vpn = nm_connection_get_setting_vpn(request->connection); gs_unref_ptrarray GPtrArray *auth_dialog_argv = NULL; - NMVpnPluginInfo * plugin_info; - const char * s; + NMVpnPluginInfo *plugin_info; + const char *s; GPid auth_dialog_pid; int auth_dialog_in_fd; int auth_dialog_out_fd; - GOutputStream * auth_dialog_in; - GInputStream * auth_dialog_out; - GError * error = NULL; - GString * auth_dialog_request; - gs_free char * auth_dialog_request_str = NULL; + GOutputStream *auth_dialog_in; + GInputStream *auth_dialog_out; + GError *error = NULL; + GString *auth_dialog_request; + gs_free char *auth_dialog_request_str = NULL; gsize auth_dialog_request_len; - AuthDialogData * data; + AuthDialogData *data; int i; plugin_info = nm_vpn_plugin_info_list_find_by_service(nm_vpn_get_plugin_infos(), @@ -845,11 +845,11 @@ static void request_secrets_from_ui(RequestData *request) { gs_unref_ptrarray GPtrArray *secrets = NULL; - gs_free_error GError * error = NULL; - NMSecretAgentSimplePrivate *priv; - NMSecretAgentSimpleSecret * secret; - const char * title; - gs_free char * msg = NULL; + gs_free_error GError *error = NULL; + NMSecretAgentSimplePrivate *priv; + NMSecretAgentSimpleSecret *secret; + const char *title; + gs_free char *msg = NULL; priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE(request->self); g_return_if_fail(priv->enabled); @@ -869,8 +869,8 @@ request_secrets_from_ui(RequestData *request) if (nm_connection_is_type(request->connection, NM_SETTING_WIRELESS_SETTING_NAME)) { NMSettingWireless *s_wireless; - GBytes * ssid; - gs_free char * ssid_utf8 = NULL; + GBytes *ssid; + gs_free char *ssid_utf8 = NULL; s_wireless = nm_connection_get_setting_wireless(request->connection); ssid = nm_setting_wireless_get_ssid(s_wireless); @@ -1022,21 +1022,21 @@ out_fail_error: } static void -get_secrets(NMSecretAgentOld * agent, - NMConnection * connection, - const char * connection_path, - const char * setting_name, - const char ** hints, +get_secrets(NMSecretAgentOld *agent, + NMConnection *connection, + const char *connection_path, + const char *setting_name, + const char **hints, NMSecretAgentGetSecretsFlags flags, NMSecretAgentOldGetSecretsFunc callback, gpointer callback_data) { - NMSecretAgentSimple * self = NM_SECRET_AGENT_SIMPLE(agent); + NMSecretAgentSimple *self = NM_SECRET_AGENT_SIMPLE(agent); NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE(self); - RequestData * request; - gs_free_error GError *error = NULL; - gs_free char * request_id = NULL; - const char * request_id_setting_name; + RequestData *request; + gs_free_error GError *error = NULL; + gs_free char *request_id = NULL; + const char *request_id_setting_name; request_id = g_strdup_printf("%s/%s", connection_path, setting_name); @@ -1097,14 +1097,14 @@ get_secrets(NMSecretAgentOld * agent, */ void nm_secret_agent_simple_response(NMSecretAgentSimple *self, - const char * request_id, - GPtrArray * secrets) + const char *request_id, + GPtrArray *secrets) { NMSecretAgentSimplePrivate *priv; - RequestData * request; - gs_unref_variant GVariant *secrets_dict = NULL; - gs_free_error GError *error = NULL; - int i; + RequestData *request; + gs_unref_variant GVariant *secrets_dict = NULL; + gs_free_error GError *error = NULL; + int i; g_return_if_fail(NM_IS_SECRET_AGENT_SIMPLE(self)); @@ -1117,9 +1117,9 @@ nm_secret_agent_simple_response(NMSecretAgentSimple *self, GVariantBuilder vpn_secrets_builder; GVariantBuilder wg_secrets_builder; GVariantBuilder wg_peer_builder; - GHashTable * settings; + GHashTable *settings; GHashTableIter iter; - const char * name; + const char *name; gboolean has_vpn = FALSE; gboolean has_wg = FALSE; @@ -1207,11 +1207,11 @@ nm_secret_agent_simple_response(NMSecretAgentSimple *self, static void cancel_get_secrets(NMSecretAgentOld *agent, const char *connection_path, const char *setting_name) { - NMSecretAgentSimple * self = NM_SECRET_AGENT_SIMPLE(agent); - NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE(self); - gs_free_error GError *error = NULL; - gs_free char * request_id = NULL; - RequestData * request; + NMSecretAgentSimple *self = NM_SECRET_AGENT_SIMPLE(agent); + NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE(self); + gs_free_error GError *error = NULL; + gs_free char *request_id = NULL; + RequestData *request; request_id = g_strdup_printf("%s/%s", connection_path, setting_name); request = g_hash_table_lookup(priv->requests, &request_id); @@ -1229,9 +1229,9 @@ cancel_get_secrets(NMSecretAgentOld *agent, const char *connection_path, const c } static void -save_secrets(NMSecretAgentOld * agent, - NMConnection * connection, - const char * connection_path, +save_secrets(NMSecretAgentOld *agent, + NMConnection *connection, + const char *connection_path, NMSecretAgentOldSaveSecretsFunc callback, gpointer callback_data) { @@ -1240,9 +1240,9 @@ save_secrets(NMSecretAgentOld * agent, } static void -delete_secrets(NMSecretAgentOld * agent, - NMConnection * connection, - const char * connection_path, +delete_secrets(NMSecretAgentOld *agent, + NMConnection *connection, + const char *connection_path, NMSecretAgentOldDeleteSecretsFunc callback, gpointer callback_data) { @@ -1263,10 +1263,10 @@ delete_secrets(NMSecretAgentOld * agent, void nm_secret_agent_simple_enable(NMSecretAgentSimple *self, const char *path) { - NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE(self); - gs_free RequestData **requests = NULL; - gsize i; - gs_free char * path_full = NULL; + NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE(self); + gs_free RequestData **requests = NULL; + gsize i; + gs_free char *path_full = NULL; /* The path is only used to match a request_id with the current * connection. Since the request_id is "${CONNECTION_PATH}/${SETTING}", @@ -1326,10 +1326,10 @@ nm_secret_agent_simple_new(const char *name) static void dispose(GObject *object) { - NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE(object); - gs_free_error GError *error = NULL; - GHashTableIter iter; - RequestData * request; + NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE(object); + gs_free_error GError *error = NULL; + GHashTableIter iter; + RequestData *request; g_hash_table_iter_init(&iter, priv->requests); while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &request)) { @@ -1356,7 +1356,7 @@ finalize(GObject *object) void nm_secret_agent_simple_class_init(NMSecretAgentSimpleClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); NMSecretAgentOldClass *agent_class = NM_SECRET_AGENT_OLD_CLASS(klass); object_class->dispose = dispose; diff --git a/src/libnmc-base/nm-secret-agent-simple.h b/src/libnmc-base/nm-secret-agent-simple.h index 878f9c75..7193f7e5 100644 --- a/src/libnmc-base/nm-secret-agent-simple.h +++ b/src/libnmc-base/nm-secret-agent-simple.h @@ -17,10 +17,10 @@ typedef enum { typedef struct { NMSecretAgentSecretType secret_type; - const char * pretty_name; - const char * entry_id; - char * value; - const char * vpn_type; + const char *pretty_name; + const char *entry_id; + char *value; + const char *vpn_type; bool is_secret : 1; bool no_prompt_entry_id : 1; } NMSecretAgentSimpleSecret; @@ -53,8 +53,8 @@ GType nm_secret_agent_simple_get_type(void); NMSecretAgentSimple *nm_secret_agent_simple_new(const char *name); void nm_secret_agent_simple_response(NMSecretAgentSimple *self, - const char * request_id, - GPtrArray * secrets); + const char *request_id, + GPtrArray *secrets); void nm_secret_agent_simple_enable(NMSecretAgentSimple *self, const char *path); diff --git a/src/libnmc-base/nm-vpn-helpers.c b/src/libnmc-base/nm-vpn-helpers.c index 99a69276..e2c0c394 100644 --- a/src/libnmc-base/nm-vpn-helpers.c +++ b/src/libnmc-base/nm-vpn-helpers.c @@ -25,8 +25,8 @@ NMVpnEditorPlugin * nm_vpn_get_editor_plugin(const char *service_type, GError **error) { - NMVpnEditorPlugin *plugin = NULL; - NMVpnPluginInfo * plugin_info; + NMVpnEditorPlugin *plugin = NULL; + NMVpnPluginInfo *plugin_info; gs_free_error GError *local = NULL; g_return_val_if_fail(service_type, NULL); @@ -95,8 +95,8 @@ nm_vpn_get_plugin_infos(void) gboolean nm_vpn_supports_ipv6(NMConnection *connection) { - NMSettingVpn * s_vpn; - const char * service_type; + NMSettingVpn *s_vpn; + const char *service_type; NMVpnEditorPlugin *plugin; guint32 capabilities; @@ -188,16 +188,16 @@ _extract_variable_value(char *line, const char *tag, char **value) gboolean nm_vpn_openconnect_authenticate_helper(const char *host, - char ** cookie, - char ** gateway, - char ** gwcert, - int * status, - GError ** error) + char **cookie, + char **gateway, + char **gwcert, + int *status, + GError **error) { - gs_free char * output = NULL; + gs_free char *output = NULL; gs_free const char **output_v = NULL; - const char *const * iter; - const char * path; + const char *const *iter; + const char *path; const char *const DEFAULT_PATHS[] = { "/sbin/", "/usr/sbin/", @@ -249,14 +249,14 @@ nm_vpn_openconnect_authenticate_helper(const char *host, } static gboolean -_wg_complete_peer(GPtrArray ** p_peers, +_wg_complete_peer(GPtrArray **p_peers, NMWireGuardPeer *peer_take, gsize peer_start_line_nr, - const char * filename, - GError ** error) + const char *filename, + GError **error) { - nm_auto_unref_wgpeer NMWireGuardPeer *peer = peer_take; - gs_free_error GError *local = NULL; + nm_auto_unref_wgpeer NMWireGuardPeer *peer = peer_take; + gs_free_error GError *local = NULL; if (!peer) return TRUE; @@ -330,37 +330,37 @@ nm_vpn_wireguard_import(const char *filename, GError **error) { nm_auto_clear_secret_ptr NMSecretPtr file_content = NM_SECRET_PTR_INIT(); char ifname[IFNAMSIZ]; - gs_free char * uuid = NULL; + gs_free char *uuid = NULL; gboolean ifname_valid = FALSE; - const char * cstr; - char * line_remainder; - gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSettingWireGuard * s_wg; - gs_free_error GError *local = NULL; + const char *cstr; + char *line_remainder; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingWireGuard *s_wg; + gs_free_error GError *local = NULL; enum { LINE_CONTEXT_INIT, LINE_CONTEXT_INTERFACE, LINE_CONTEXT_PEER, } line_context; - gsize line_nr; - gsize current_peer_start_line_nr = 0; - nm_auto_unref_wgpeer NMWireGuardPeer *current_peer = NULL; - gs_unref_ptrarray GPtrArray *data_dns_search = NULL; - gs_unref_ptrarray GPtrArray *data_dns_v4 = NULL; - gs_unref_ptrarray GPtrArray *data_dns_v6 = NULL; - gs_unref_ptrarray GPtrArray *data_addr_v4 = NULL; - gs_unref_ptrarray GPtrArray *data_addr_v6 = NULL; - gs_unref_ptrarray GPtrArray *data_peers = NULL; - const char * data_private_key = NULL; - gint64 data_table; - guint data_listen_port = 0; - guint data_fwmark = 0; - guint data_mtu = 0; - int is_v4; - guint i; + gsize line_nr; + gsize current_peer_start_line_nr = 0; + nm_auto_unref_wgpeer NMWireGuardPeer *current_peer = NULL; + gs_unref_ptrarray GPtrArray *data_dns_search = NULL; + gs_unref_ptrarray GPtrArray *data_dns_v4 = NULL; + gs_unref_ptrarray GPtrArray *data_dns_v6 = NULL; + gs_unref_ptrarray GPtrArray *data_addr_v4 = NULL; + gs_unref_ptrarray GPtrArray *data_addr_v6 = NULL; + gs_unref_ptrarray GPtrArray *data_peers = NULL; + const char *data_private_key = NULL; + gint64 data_table; + guint data_listen_port = 0; + guint data_fwmark = 0; + guint data_mtu = 0; + int is_v4; + guint i; g_return_val_if_fail(filename, NULL); g_return_val_if_fail(!error || !*error, NULL); @@ -420,8 +420,8 @@ nm_vpn_wireguard_import(const char *filename, GError **error) line_nr = 0; while (line_remainder[0] != '\0') { const char *matched_key = NULL; - char * value = NULL; - char * line; + char *value = NULL; + char *line; char ch; gint64 i64; @@ -742,9 +742,9 @@ fail_invalid_secret: const char *method_manual = is_v4 ? NM_SETTING_IP4_CONFIG_METHOD_MANUAL : NM_SETTING_IP6_CONFIG_METHOD_MANUAL; NMSettingIPConfig *s_ip = is_v4 ? s_ip4 : s_ip6; - GPtrArray * data_dns = is_v4 ? data_dns_v4 : data_dns_v6; - GPtrArray * data_addr = is_v4 ? data_addr_v4 : data_addr_v6; - GPtrArray * data_dns_search2 = data_dns_search; + GPtrArray *data_dns = is_v4 ? data_dns_v4 : data_dns_v6; + GPtrArray *data_addr = is_v4 ? data_addr_v4 : data_addr_v6; + GPtrArray *data_dns_search2 = data_dns_search; if (!data_addr) { /* When specifying "DNS", we also require an "Address" for the same address diff --git a/src/libnmc-base/nm-vpn-helpers.h b/src/libnmc-base/nm-vpn-helpers.h index 1cf06743..678ce1e2 100644 --- a/src/libnmc-base/nm-vpn-helpers.h +++ b/src/libnmc-base/nm-vpn-helpers.h @@ -20,11 +20,11 @@ gboolean nm_vpn_supports_ipv6(NMConnection *connection); const NmcVpnPasswordName *nm_vpn_get_secret_names(const char *service_type); gboolean nm_vpn_openconnect_authenticate_helper(const char *host, - char ** cookie, - char ** gateway, - char ** gwcert, - int * status, - GError ** error); + char **cookie, + char **gateway, + char **gwcert, + int *status, + GError **error); NMConnection *nm_vpn_wireguard_import(const char *filename, GError **error); diff --git a/src/libnmc-base/qrcodegen.c b/src/libnmc-base/qrcodegen.c index 0aacdb01..b86ca587 100644 --- a/src/libnmc-base/qrcodegen.c +++ b/src/libnmc-base/qrcodegen.c @@ -133,7 +133,7 @@ static const int PENALTY_N4 = 10; // Public function - see documentation comment in header file. bool -qrcodegen_encodeText(const char * text, +qrcodegen_encodeText(const char *text, uint8_t tempBuffer[], uint8_t qrcode[], enum qrcodegen_Ecc ecl, diff --git a/src/libnmc-base/qrcodegen.h b/src/libnmc-base/qrcodegen.h index b91ae49a..46d986a3 100644 --- a/src/libnmc-base/qrcodegen.h +++ b/src/libnmc-base/qrcodegen.h @@ -158,7 +158,7 @@ struct qrcodegen_Segment { * - Please consult the QR Code specification for information on * data capacities per version, ECC level, and text encoding mode. */ -bool qrcodegen_encodeText(const char * text, +bool qrcodegen_encodeText(const char *text, uint8_t tempBuffer[], uint8_t qrcode[], enum qrcodegen_Ecc ecl, diff --git a/src/libnmc-setting/nm-meta-setting-access.c b/src/libnmc-setting/nm-meta-setting-access.c index cd4cbdd5..7f679ae5 100644 --- a/src/libnmc-setting/nm-meta-setting-access.c +++ b/src/libnmc-setting/nm-meta-setting-access.c @@ -72,7 +72,7 @@ nm_meta_setting_info_editor_find_by_setting(NMSetting *setting) const NMMetaPropertyInfo * nm_meta_setting_info_editor_get_property_info(const NMMetaSettingInfoEditor *setting_info, - const char * property_name) + const char *property_name) { guint i; @@ -109,7 +109,7 @@ const NMMetaPropertyInfo * nm_meta_property_info_find_by_name(const char *setting_name, const char *property_name) { const NMMetaSettingInfoEditor *setting_info; - const NMMetaPropertyInfo * property_info; + const NMMetaPropertyInfo *property_info; setting_info = nm_meta_setting_info_editor_find_by_name(setting_name, FALSE); if (!setting_info) @@ -128,7 +128,7 @@ const NMMetaPropertyInfo * nm_meta_property_info_find_by_setting(NMSetting *setting, const char *property_name) { const NMMetaSettingInfoEditor *setting_info; - const NMMetaPropertyInfo * property_info; + const NMMetaPropertyInfo *property_info; setting_info = nm_meta_setting_info_editor_find_by_setting(setting); if (!setting_info) @@ -193,8 +193,8 @@ nm_meta_abstract_info_get_name(const NMMetaAbstractInfo *abstract_info, gboolean const NMMetaAbstractInfo *const * nm_meta_abstract_info_get_nested(const NMMetaAbstractInfo *abstract_info, - guint * out_len, - gpointer * nested_to_free) + guint *out_len, + gpointer *nested_to_free) { const NMMetaAbstractInfo *const *nested; guint l = 0; @@ -219,16 +219,16 @@ nm_meta_abstract_info_get_nested(const NMMetaAbstractInfo *abstract_info, } gconstpointer -nm_meta_abstract_info_get(const NMMetaAbstractInfo * abstract_info, - const NMMetaEnvironment * environment, +nm_meta_abstract_info_get(const NMMetaAbstractInfo *abstract_info, + const NMMetaEnvironment *environment, gpointer environment_user_data, gpointer target, gpointer target_data, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, - gboolean * out_is_default, - gpointer * out_to_free) + gboolean *out_is_default, + gpointer *out_to_free) { nm_assert(abstract_info); nm_assert(abstract_info->meta_type); @@ -254,13 +254,13 @@ nm_meta_abstract_info_get(const NMMetaAbstractInfo * abstract_info, } const char *const * -nm_meta_abstract_info_complete(const NMMetaAbstractInfo * abstract_info, - const NMMetaEnvironment * environment, +nm_meta_abstract_info_complete(const NMMetaAbstractInfo *abstract_info, + const NMMetaEnvironment *environment, gpointer environment_user_data, const NMMetaOperationContext *operation_context, - const char * text, - gboolean * out_complete_filename, - char *** out_to_free) + const char *text, + gboolean *out_complete_filename, + char ***out_to_free) { const char *const *values; gsize i, j, text_len; @@ -319,7 +319,7 @@ nm_meta_abstract_info_complete(const NMMetaAbstractInfo * abstract_info, return (const char *const *) v; } else { const char *const *v = values; - char ** r; + char **r; for (i = 0, j = 0; v[i]; i++) { if (strncmp(v[i], text, text_len) != 0) @@ -347,7 +347,7 @@ nm_meta_abstract_info_complete(const NMMetaAbstractInfo * abstract_info, char * nm_meta_abstract_info_get_nested_names_str(const NMMetaAbstractInfo *abstract_info, - const char * name_prefix) + const char *name_prefix) { gs_free gpointer nested_to_free = NULL; const NMMetaAbstractInfo *const *nested; @@ -364,7 +364,7 @@ nm_meta_abstract_info_get_nested_names_str(const NMMetaAbstractInfo *abstract_in char * nm_meta_abstract_infos_get_names_str(const NMMetaAbstractInfo *const *fields_array, - const char * name_prefix) + const char *name_prefix) { GString *str; guint i; @@ -417,7 +417,7 @@ _output_selection_pack(const NMMetaAbstractInfo *const *fields_array, GArray *ar memcpy(pdata, str->str, str->len); for (i = 0; i < len; i++) { const OutputSelectionItem *a = &g_array_index(array, OutputSelectionItem, i); - NMMetaSelectionItem * p = (NMMetaSelectionItem *) &result->items[i]; + NMMetaSelectionItem *p = (NMMetaSelectionItem *) &result->items[i]; p->info = fields_array[a->idx]; p->idx = a->idx; @@ -433,19 +433,19 @@ _output_selection_pack(const NMMetaAbstractInfo *const *fields_array, GArray *ar static gboolean _output_selection_select_one(const NMMetaAbstractInfo *const *fields_array, - const char * fields_prefix, - const char * fields_str, + const char *fields_prefix, + const char *fields_str, gboolean validate_nested, - GArray ** p_array, - GString ** p_str, - GError ** error) + GArray **p_array, + GString **p_str, + GError **error) { guint i, j; - const char * i_name; - const char * right; + const char *i_name; + const char *right; gboolean found = FALSE; const NMMetaAbstractInfo *fields_array_failure = NULL; - gs_free char * fields_str_clone = NULL; + gs_free char *fields_str_clone = NULL; nm_assert(fields_str); nm_assert(p_array); @@ -465,7 +465,7 @@ _output_selection_select_one(const NMMetaAbstractInfo *const *fields_array, goto not_found; for (i = 0; fields_array[i]; i++) { - const NMMetaAbstractInfo * fi = fields_array[i]; + const NMMetaAbstractInfo *fi = fields_array[i]; const NMMetaAbstractInfo *const *nested; gs_free gpointer nested_to_free = NULL; @@ -536,7 +536,7 @@ not_found: } { - GString * str; + GString *str; OutputSelectionItem s = { .idx = i, }; @@ -588,14 +588,14 @@ nm_meta_selection_create_all(const NMMetaAbstractInfo *const *fields_array) NMMetaSelectionResultList * nm_meta_selection_create_parse_one( const NMMetaAbstractInfo *const *fields_array, - const char * fields_prefix, + const char *fields_prefix, const char * fields_str, /* one field selector (contains no commas) and is already stripped of spaces. */ gboolean validate_nested, GError **error) { - gs_unref_array GArray *array = NULL; - nm_auto_free_gstring GString *str = NULL; + gs_unref_array GArray *array = NULL; + nm_auto_free_gstring GString *str = NULL; g_return_val_if_fail(!error || !*error, NULL); nm_assert(fields_str && !strchr(fields_str, ',')); @@ -614,15 +614,15 @@ nm_meta_selection_create_parse_one( NMMetaSelectionResultList * nm_meta_selection_create_parse_list( const NMMetaAbstractInfo *const *fields_array, - const char * fields_str, /* a comma separated list of selectors */ + const char *fields_str, /* a comma separated list of selectors */ gboolean validate_nested, - GError ** error) + GError **error) { - gs_unref_array GArray *array = NULL; + gs_unref_array GArray *array = NULL; nm_auto_free_gstring GString *str = NULL; - gs_free char * fields_str_clone = NULL; - char * fields_str_cur; - char * fields_str_next; + gs_free char *fields_str_clone = NULL; + char *fields_str_cur; + char *fields_str_next; g_return_val_if_fail(!error || !*error, NULL); diff --git a/src/libnmc-setting/nm-meta-setting-access.h b/src/libnmc-setting/nm-meta-setting-access.h index 81aa3b6f..9b00eb0a 100644 --- a/src/libnmc-setting/nm-meta-setting-access.h +++ b/src/libnmc-setting/nm-meta-setting-access.h @@ -20,10 +20,10 @@ const NMMetaSettingInfoEditor *nm_meta_setting_info_editor_find_by_setting(NMSet const NMMetaPropertyInfo * nm_meta_setting_info_editor_get_property_info(const NMMetaSettingInfoEditor *setting_info, - const char * property_name); + const char *property_name); const NMMetaPropertyInfo *nm_meta_property_info_find_by_name(const char *setting_name, const char *property_name); -const NMMetaPropertyInfo *nm_meta_property_info_find_by_setting(NMSetting * setting, +const NMMetaPropertyInfo *nm_meta_property_info_find_by_setting(NMSetting *setting, const char *property_name); gboolean nm_meta_setting_info_editor_has_secrets(const NMMetaSettingInfoEditor *setting_info); @@ -39,41 +39,41 @@ const char *nm_meta_abstract_info_get_name(const NMMetaAbstractInfo *abstract_in const NMMetaAbstractInfo *const * nm_meta_abstract_info_get_nested(const NMMetaAbstractInfo *abstract_info, - guint * out_len, - gpointer * nested_to_free); + guint *out_len, + gpointer *nested_to_free); -gconstpointer nm_meta_abstract_info_get(const NMMetaAbstractInfo * abstract_info, - const NMMetaEnvironment * environment, +gconstpointer nm_meta_abstract_info_get(const NMMetaAbstractInfo *abstract_info, + const NMMetaEnvironment *environment, gpointer environment_user_data, gpointer target, gpointer target_data, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, - gboolean * out_is_default, - gpointer * out_to_free); + gboolean *out_is_default, + gpointer *out_to_free); const char *const *nm_meta_abstract_info_complete(const NMMetaAbstractInfo *abstract_info, - const NMMetaEnvironment * environment, + const NMMetaEnvironment *environment, gpointer environment_user_data, const NMMetaOperationContext *operation_context, - const char * text, + const char *text, gboolean *out_complete_filename, - char *** out_to_free); + char ***out_to_free); /*****************************************************************************/ char *nm_meta_abstract_info_get_nested_names_str(const NMMetaAbstractInfo *abstract_info, - const char * name_prefix); + const char *name_prefix); char *nm_meta_abstract_infos_get_names_str(const NMMetaAbstractInfo *const *fields_array, - const char * name_prefix); + const char *name_prefix); /*****************************************************************************/ typedef struct { const NMMetaAbstractInfo *info; - const char * self_selection; - const char * sub_selection; + const char *self_selection; + const char *sub_selection; guint idx; } NMMetaSelectionItem; @@ -86,14 +86,14 @@ NMMetaSelectionResultList * nm_meta_selection_create_all(const NMMetaAbstractInfo *const *fields_array); NMMetaSelectionResultList * nm_meta_selection_create_parse_one(const NMMetaAbstractInfo *const *fields_array, - const char * fields_prefix, - const char * fields_str, + const char *fields_prefix, + const char *fields_str, gboolean validate_nested, - GError ** error); + GError **error); NMMetaSelectionResultList * nm_meta_selection_create_parse_list(const NMMetaAbstractInfo *const *fields_array, - const char * fields_str, + const char *fields_str, gboolean validate_nested, - GError ** error); + GError **error); #endif /* _NM_META_SETTING_ACCESS_H__ */ diff --git a/src/libnmc-setting/nm-meta-setting-base-impl.c b/src/libnmc-setting/nm-meta-setting-base-impl.c index 8c1ad10e..cd55779f 100644 --- a/src/libnmc-setting/nm-meta-setting-base-impl.c +++ b/src/libnmc-setting/nm-meta-setting-base-impl.c @@ -646,8 +646,8 @@ nm_meta_setting_infos_by_gtype(GType gtype) { #if _NM_META_SETTING_BASE_IMPL_LIBNM nm_auto_unref_gtypeclass GTypeClass *gtypeclass_unref = NULL; - GTypeClass * gtypeclass; - NMSettingClass * klass; + GTypeClass *gtypeclass; + NMSettingClass *klass; if (!g_type_is_a(gtype, NM_TYPE_SETTING)) goto out_none; diff --git a/src/libnmc-setting/nm-meta-setting-base-impl.h b/src/libnmc-setting/nm-meta-setting-base-impl.h index eba1fb96..ea4f85ff 100644 --- a/src/libnmc-setting/nm-meta-setting-base-impl.h +++ b/src/libnmc-setting/nm-meta-setting-base-impl.h @@ -73,18 +73,18 @@ typedef struct { const char *(*uri_func)(NMSetting8021x *setting); const char *(*passwd_func)(NMSetting8021x *setting); NMSettingSecretFlags (*pwflag_func)(NMSetting8021x *setting); - gboolean (*set_cert_func)(NMSetting8021x * setting, - const char * value, + gboolean (*set_cert_func)(NMSetting8021x *setting, + const char *value, NMSetting8021xCKScheme scheme, NMSetting8021xCKFormat *out_format, - GError ** error); - gboolean (*set_private_key_func)(NMSetting8021x * setting, - const char * value, - const char * password, + GError **error); + gboolean (*set_private_key_func)(NMSetting8021x *setting, + const char *value, + const char *password, NMSetting8021xCKScheme scheme, NMSetting8021xCKFormat *out_format, - GError ** error); - const char * file_suffix; + GError **error); + const char *file_suffix; NMSetting8021xSchemeType scheme_type; bool is_secret : 1; } NMSetting8021xSchemeVtable; diff --git a/src/libnmc-setting/nm-meta-setting-desc.c b/src/libnmc-setting/nm-meta-setting-desc.c index 5bb2b451..4a6f3882 100644 --- a/src/libnmc-setting/nm-meta-setting-desc.c +++ b/src/libnmc-setting/nm-meta-setting-desc.c @@ -49,7 +49,7 @@ _gtype_property_get_gtype(GType gtype, const char *property_name) /* given @gtype, a type for a GObject, lookup the property @property_name * and return its value_type. */ if (G_TYPE_IS_CLASSED(gtype)) { - GParamSpec * param_spec; + GParamSpec *param_spec; nm_auto_unref_gtypeclass GTypeClass *gtypeclass = g_type_class_ref(gtype); if (G_IS_OBJECT_CLASS(gtypeclass)) { @@ -88,12 +88,12 @@ _int64_cmp_desc(gconstpointer a, gconstpointer b, gpointer user_data) static gint64 * _value_str_as_index_list(const char *value, gsize *out_len) { - gs_free char *str_clone_free = NULL; - gboolean str_cloned = FALSE; - char * str; - gsize i, j; - gsize n_alloc; - gsize len; + gs_free char *str_clone_free = NULL; + gboolean str_cloned = FALSE; + char *str; + gsize i, j; + gsize n_alloc; + gsize len; gs_free gint64 *arr = NULL; *out_len = 0; @@ -244,10 +244,10 @@ _parse_ip_address(int family, const char *address, GError **error) { gs_free char *ip_str = NULL; const int MAX_PREFIX = (family == AF_INET) ? 32 : 128; - NMIPAddress * addr; - char * plen; + NMIPAddress *addr; + char *plen; int prefix; - GError * local = NULL; + GError *local = NULL; g_return_val_if_fail(address, NULL); g_return_val_if_fail(!error || !*error, NULL); @@ -285,19 +285,19 @@ _parse_ip_address(int family, const char *address, GError **error) static NMIPRoute * _parse_ip_route(int family, const char *str, GError **error) { - const int MAX_PREFIX = (family == AF_INET) ? 32 : 128; - const char * next_hop = NULL; - int prefix; - NMIPRoute * route = NULL; - GError * local = NULL; - gint64 metric = -1; - guint i; - gs_free const char **routev = NULL; - gs_free char * str_clean_free = NULL; - const char * str_clean; - gs_free char * dest_clone = NULL; - const char * dest; - const char * plen; + const int MAX_PREFIX = (family == AF_INET) ? 32 : 128; + const char *next_hop = NULL; + int prefix; + NMIPRoute *route = NULL; + GError *local = NULL; + gint64 metric = -1; + guint i; + gs_free const char **routev = NULL; + gs_free char *str_clean_free = NULL; + const char *str_clean; + gs_free char *dest_clone = NULL; + const char *dest; + const char *plen; gs_unref_hashtable GHashTable *attrs = NULL; #define ROUTE_SYNTAX \ _("The valid syntax is: 'ip[/prefix] [next-hop] [metric] [attribute=val]... [,ip[/prefix] " \ @@ -357,9 +357,9 @@ _parse_ip_route(int family, const char *str, GError **error) } metric = tmp64; } else if (strchr(routev[i], '=')) { - GHashTableIter iter; - char * iter_key; - GVariant * iter_value; + GHashTableIter iter; + char *iter_key; + GVariant *iter_value; gs_unref_hashtable GHashTable *tmp_attrs = NULL; tmp_attrs = nm_utils_parse_variant_attributes(routev[i], @@ -409,8 +409,8 @@ _parse_ip_route(int family, const char *str, GError **error) if (attrs) { GHashTableIter iter; - char * name; - GVariant * variant; + char *name; + GVariant *variant; g_hash_table_iter_init(&iter, attrs); while (g_hash_table_iter_next(&iter, (gpointer *) &name, (gpointer *) &variant)) @@ -445,7 +445,7 @@ nmc_proxy_check_script(const char *script, char **out_script, GError **error) _PAC_SCRIPT_TYPE_FILE, _PAC_SCRIPT_TYPE_JSON, } desired_type = _PAC_SCRIPT_TYPE_GUESS; - const char * filename = NULL; + const char *filename = NULL; size_t c_len = 0; gs_free char *script_clone = NULL; @@ -588,7 +588,7 @@ static void _env_warn_fcn(const NMMetaEnvironment *environment, gpointer environment_user_data, NMMetaEnvWarnLevel warn_level, - const char * fmt_l10n, + const char *fmt_l10n, ...) { va_list ap; @@ -636,7 +636,7 @@ static gboolean _set_fcn_optionlist(ARGS_SET_FCN); static gboolean _SET_FCN_DO_RESET_DEFAULT(const NMMetaPropertyInfo *property_info, NMMetaAccessorModifier modifier, - const char * value) + const char *value) { nm_assert(property_info); nm_assert(!property_info->property_type->set_supports_remove); @@ -649,7 +649,7 @@ _SET_FCN_DO_RESET_DEFAULT(const NMMetaPropertyInfo *property_info, static gboolean _SET_FCN_DO_RESET_DEFAULT_WITH_SUPPORTS_REMOVE(const NMMetaPropertyInfo *property_info, NMMetaAccessorModifier modifier, - const char * value) + const char *value) { nm_assert(property_info); nm_assert(property_info->property_type->set_supports_remove); @@ -724,9 +724,9 @@ static gboolean _gobject_property_is_default(NMSetting *setting, const char *prop_name) { nm_auto_unset_gvalue GValue v = G_VALUE_INIT; - GParamSpec * pspec; - GHashTable * ht; - char ** strv; + GParamSpec *pspec; + GHashTable *ht; + char **strv; pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(setting)), prop_name); if (!G_IS_PARAM_SPEC(pspec)) @@ -750,7 +750,7 @@ static gboolean _gobject_property_reset(NMSetting *setting, const char *prop_name, gboolean reset_default) { nm_auto_unset_gvalue GValue v = G_VALUE_INIT; - GParamSpec * pspec; + GParamSpec *pspec; pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(setting)), prop_name); if (!G_IS_PARAM_SPEC(pspec)) @@ -772,8 +772,8 @@ _gobject_property_reset_default(NMSetting *setting, const char *prop_name) static const char * _coerce_str_emptyunset(NMMetaAccessorGetType get_type, gboolean is_default, - const char * cstr, - char ** out_str) + const char *cstr, + char **out_str) { nm_assert(out_str && !*out_str); nm_assert((!is_default && cstr && cstr[0] != '\0') || NM_IN_STRSET(cstr, NULL, "")); @@ -803,7 +803,7 @@ _coerce_str_emptyunset(NMMetaAccessorGetType get_type, #define RETURN_STR_EMPTYUNSET(get_type, is_default, cstr) \ G_STMT_START \ { \ - char * _str = NULL; \ + char *_str = NULL; \ const char *_cstr; \ \ _cstr = _coerce_str_emptyunset((get_type), (is_default), (cstr), &_str); \ @@ -824,13 +824,13 @@ _is_default(const NMMetaPropertyInfo *property_info, NMSetting *setting) static gconstpointer _get_fcn_gobject_impl(const NMMetaPropertyInfo *property_info, - NMSetting * setting, + NMSetting *setting, NMMetaAccessorGetType get_type, gboolean handle_emptyunset, - gboolean * out_is_default, - gpointer * out_to_free) + gboolean *out_is_default, + gpointer *out_to_free) { - const char * cstr; + const char *cstr; GType gtype_prop; nm_auto_unset_gvalue GValue val = G_VALUE_INIT; gboolean is_default; @@ -910,9 +910,9 @@ _get_fcn_gobject_impl(const NMMetaPropertyInfo *property_info, } if (gtype_prop == G_TYPE_HASH_TABLE) { - GHashTable * strdict; + GHashTable *strdict; gs_free const char **keys = NULL; - GString * str; + GString *str; gsize i; nm_assert(property_info->setting_info @@ -927,8 +927,8 @@ _get_fcn_gobject_impl(const NMMetaPropertyInfo *property_info, str = g_string_new(NULL); for (i = 0; keys[i]; i++) { - const char * key = keys[i]; - const char * v = g_hash_table_lookup(strdict, key); + const char *key = keys[i]; + const char *v = g_hash_table_lookup(strdict, key); gs_free char *escaped_key = NULL; gs_free char *escaped_val = NULL; @@ -945,7 +945,8 @@ _get_fcn_gobject_impl(const NMMetaPropertyInfo *property_info, return NULL; } -static gconstpointer _get_fcn_gobject(ARGS_GET_FCN) +static gconstpointer +_get_fcn_gobject(ARGS_GET_FCN) { return _get_fcn_gobject_impl(property_info, setting, @@ -955,15 +956,16 @@ static gconstpointer _get_fcn_gobject(ARGS_GET_FCN) out_to_free); } -static gconstpointer _get_fcn_gobject_int(ARGS_GET_FCN) +static gconstpointer +_get_fcn_gobject_int(ARGS_GET_FCN) { - GParamSpec * pspec; + GParamSpec *pspec; nm_auto_unset_gvalue GValue gval = G_VALUE_INIT; gboolean is_uint64 = FALSE; NMMetaSignUnsignInt64 v; guint base = 10; const NMMetaUtilsIntValueInfo *value_infos; - char * return_str; + char *return_str; RETURN_UNSUPPORTED_GET_TYPE(); @@ -1034,7 +1036,8 @@ static gconstpointer _get_fcn_gobject_int(ARGS_GET_FCN) RETURN_STR_TO_FREE(return_str); } -static gconstpointer _get_fcn_gobject_mtu(ARGS_GET_FCN) +static gconstpointer +_get_fcn_gobject_mtu(ARGS_GET_FCN) { guint32 mtu; @@ -1058,7 +1061,8 @@ static gconstpointer _get_fcn_gobject_mtu(ARGS_GET_FCN) RETURN_STR_TO_FREE(g_strdup_printf("%u", (unsigned) mtu)); } -static gconstpointer _get_fcn_gobject_secret_flags(ARGS_GET_FCN) +static gconstpointer +_get_fcn_gobject_secret_flags(ARGS_GET_FCN) { guint v; GValue val = G_VALUE_INIT; @@ -1072,12 +1076,13 @@ static gconstpointer _get_fcn_gobject_secret_flags(ARGS_GET_FCN) RETURN_STR_TO_FREE(secret_flags_to_string(v, get_type)); } -static gconstpointer _get_fcn_gobject_enum(ARGS_GET_FCN) +static gconstpointer +_get_fcn_gobject_enum(ARGS_GET_FCN) { - GType gtype = 0; + GType gtype = 0; nm_auto_unref_gtypeclass GTypeClass *gtype_class = NULL; nm_auto_unref_gtypeclass GTypeClass *gtype_prop_class = NULL; - const struct _NMUtilsEnumValueInfo * value_infos = NULL; + const struct _NMUtilsEnumValueInfo *value_infos = NULL; gboolean has_gtype = FALSE; nm_auto_unset_gvalue GValue gval = G_VALUE_INIT; gint64 v; @@ -1086,9 +1091,9 @@ static gconstpointer _get_fcn_gobject_enum(ARGS_GET_FCN) gboolean format_numeric_hex_unknown = FALSE; gboolean format_text = FALSE; gboolean format_text_l10n = FALSE; - gs_free char * s = NULL; + gs_free char *s = NULL; char s_numeric[64]; - GParamSpec * pspec; + GParamSpec *pspec; RETURN_UNSUPPORTED_GET_TYPE(); @@ -1221,7 +1226,8 @@ static gconstpointer _get_fcn_gobject_enum(ARGS_GET_FCN) /*****************************************************************************/ -static gboolean _set_fcn_gobject_string(ARGS_SET_FCN) +static gboolean +_set_fcn_gobject_string(ARGS_SET_FCN) { gs_free char *to_free = NULL; @@ -1264,10 +1270,10 @@ static gboolean _set_fcn_gobject_string(ARGS_SET_FCN) static gboolean _set_fcn_gobject_bool_impl(const NMMetaPropertyInfo *property_info, - NMSetting * setting, + NMSetting *setting, NMMetaAccessorModifier modifier, - const char * value, - GError ** error) + const char *value, + GError **error) { gboolean val_bool; @@ -1281,12 +1287,14 @@ _set_fcn_gobject_bool_impl(const NMMetaPropertyInfo *property_info, return TRUE; } -static gboolean _set_fcn_gobject_bool(ARGS_SET_FCN) +static gboolean +_set_fcn_gobject_bool(ARGS_SET_FCN) { return _set_fcn_gobject_bool_impl(property_info, setting, modifier, value, error); } -static gboolean _set_fcn_gobject_ternary(ARGS_SET_FCN) +static gboolean +_set_fcn_gobject_ternary(ARGS_SET_FCN) { NMTernary val; @@ -1303,10 +1311,11 @@ static gboolean _set_fcn_gobject_ternary(ARGS_SET_FCN) return TRUE; } -static gboolean _set_fcn_gobject_int(ARGS_SET_FCN) +static gboolean +_set_fcn_gobject_int(ARGS_SET_FCN) { int errsv; - const GParamSpec * pspec; + const GParamSpec *pspec; nm_auto_unset_gvalue GValue gval = G_VALUE_INIT; gboolean is_uint64; NMMetaSignUnsignInt64 v; @@ -1330,7 +1339,7 @@ static gboolean _set_fcn_gobject_int(ARGS_SET_FCN) if (value && (value_infos = property_info->property_typ_data->subtype.gobject_int.value_infos)) { gs_free char *vv_free = NULL; - const char * vv; + const char *vv; vv = nm_strstrip_avoid_copy_a(300, value, &vv_free); for (; value_infos->nick; value_infos++) { @@ -1454,10 +1463,11 @@ have_value_from_nick: return TRUE; } -static gboolean _set_fcn_gobject_mtu(ARGS_SET_FCN) +static gboolean +_set_fcn_gobject_mtu(ARGS_SET_FCN) { nm_auto_unset_gvalue GValue gval = G_VALUE_INIT; - const GParamSpec * pspec; + const GParamSpec *pspec; gint64 v; if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) @@ -1496,7 +1506,8 @@ static gboolean _set_fcn_gobject_mtu(ARGS_SET_FCN) #define IEEE802154_ADDR_LEN 8 #endif -static gboolean _set_fcn_gobject_mac(ARGS_SET_FCN) +static gboolean +_set_fcn_gobject_mac(ARGS_SET_FCN) { NMMetaPropertyTypeMacMode mode; gboolean valid; @@ -1528,12 +1539,13 @@ static gboolean _set_fcn_gobject_mac(ARGS_SET_FCN) return TRUE; } -static gboolean _set_fcn_gobject_enum(ARGS_SET_FCN) +static gboolean +_set_fcn_gobject_enum(ARGS_SET_FCN) { - GType gtype = 0; - GType gtype_prop; - gboolean has_gtype = FALSE; - nm_auto_unset_gvalue GValue gval = G_VALUE_INIT; + GType gtype = 0; + GType gtype_prop; + gboolean has_gtype = FALSE; + nm_auto_unset_gvalue GValue gval = G_VALUE_INIT; nm_auto_unref_gtypeclass GTypeClass *gtype_prop_class = NULL; nm_auto_unref_gtypeclass GTypeClass *gtype_class = NULL; gboolean is_flags; @@ -1619,7 +1631,7 @@ static gboolean _set_fcn_gobject_enum(ARGS_SET_FCN) fail: if (error) { gs_free const char **valid_all = NULL; - gs_free const char * valid_str = NULL; + gs_free const char *valid_str = NULL; gboolean has_minmax = FALSE; int min = G_MININT; int max = G_MAXINT; @@ -1661,14 +1673,15 @@ fail: /*****************************************************************************/ -static const char *const *_values_fcn_gobject_enum(ARGS_VALUES_FCN) +static const char *const * +_values_fcn_gobject_enum(ARGS_VALUES_FCN) { GType gtype = 0; gboolean has_gtype = FALSE; gboolean has_minmax = FALSE; int min = G_MININT; int max = G_MAXINT; - char ** v; + char **v; if (property_info->property_typ_data) { if (property_info->property_typ_data->subtype.gobject_enum.min @@ -1707,7 +1720,8 @@ static const char *const *_values_fcn_gobject_enum(ARGS_VALUES_FCN) /*****************************************************************************/ -static const char *const *_complete_fcn_gobject_bool(ARGS_COMPLETE_FCN) +static const char *const * +_complete_fcn_gobject_bool(ARGS_COMPLETE_FCN) { static const char *const v[] = { "true", @@ -1726,7 +1740,8 @@ static const char *const *_complete_fcn_gobject_bool(ARGS_COMPLETE_FCN) return v; } -static const char *const *_complete_fcn_gobject_ternary(ARGS_COMPLETE_FCN) +static const char *const * +_complete_fcn_gobject_ternary(ARGS_COMPLETE_FCN) { static const char *const v[] = { "on", @@ -1748,12 +1763,13 @@ static const char *const *_complete_fcn_gobject_ternary(ARGS_COMPLETE_FCN) return v; } -static const char *const *_complete_fcn_gobject_devices(ARGS_COMPLETE_FCN) +static const char *const * +_complete_fcn_gobject_devices(ARGS_COMPLETE_FCN) { NMDevice *const *devices = NULL; guint i, j; guint len = 0; - char ** ifnames; + char **ifnames; if (environment && environment->get_nm_devices) { devices = environment->get_nm_devices(environment, environment_user_data, &len); @@ -1860,9 +1876,9 @@ secret_flags_to_string(guint32 flags, NMMetaAccessorGetType get_type) static const char * _multilist_do_validate(const NMMetaPropertyInfo *property_info, - NMSetting * setting, - const char * item, - GError ** error) + NMSetting *setting, + const char *item, + GError **error) { if (property_info->property_typ_data->values_static) { nm_assert(!property_info->property_typ_data->subtype.multilist.validate_fcn); @@ -1882,7 +1898,8 @@ _multilist_do_validate(const NMMetaPropertyInfo *property_info, return item; } -static gconstpointer _get_fcn_multilist(ARGS_GET_FCN) +static gconstpointer +_get_fcn_multilist(ARGS_GET_FCN) { return _get_fcn_gobject_impl( property_info, @@ -1895,7 +1912,7 @@ static gconstpointer _get_fcn_multilist(ARGS_GET_FCN) static gboolean _multilist_clear_property(const NMMetaPropertyInfo *property_info, - NMSetting * setting, + NMSetting *setting, gboolean is_set /* or else set default */) { if (property_info->property_typ_data->subtype.multilist.clear_emptyunset_fcn) { @@ -1909,7 +1926,8 @@ _multilist_clear_property(const NMMetaPropertyInfo *property_info, return _gobject_property_reset(setting, property_info->property_name, FALSE); } -static gboolean _set_fcn_multilist(ARGS_SET_FCN) +static gboolean +_set_fcn_multilist(ARGS_SET_FCN) { gs_free const char **strv = NULL; gsize i, j, nstrv; @@ -2000,7 +2018,8 @@ static gboolean _set_fcn_multilist(ARGS_SET_FCN) return TRUE; } -static gboolean _set_fcn_optionlist(ARGS_SET_FCN) +static gboolean +_set_fcn_optionlist(ARGS_SET_FCN) { gs_free const char **strv = NULL; gs_free const char **strv_val = NULL; @@ -2112,7 +2131,7 @@ validate_flags(NMSetting *setting, const char *prop, guint val, GError **error) if (g_param_value_validate(pspec, &value)) { GParamSpecFlags *pspec_flags = (GParamSpecFlags *) pspec; - gs_free char * flag_values = NULL; + gs_free char *flag_values = NULL; flag_values = flag_values_to_string(pspec_flags->flags_class->values, pspec_flags->flags_class->n_values); @@ -2129,7 +2148,8 @@ validate_flags(NMSetting *setting, const char *prop, guint val, GError **error) return success; } -static gboolean _set_fcn_gobject_flags(ARGS_SET_FCN) +static gboolean +_set_fcn_gobject_flags(ARGS_SET_FCN) { unsigned long val_int; @@ -2149,7 +2169,8 @@ static gboolean _set_fcn_gobject_flags(ARGS_SET_FCN) return TRUE; } -static gboolean _set_fcn_gobject_ssid(ARGS_SET_FCN) +static gboolean +_set_fcn_gobject_ssid(ARGS_SET_FCN) { gs_unref_bytes GBytes *ssid = NULL; @@ -2166,7 +2187,8 @@ static gboolean _set_fcn_gobject_ssid(ARGS_SET_FCN) return TRUE; } -static gboolean _set_fcn_gobject_ifname(ARGS_SET_FCN) +static gboolean +_set_fcn_gobject_ifname(ARGS_SET_FCN) { if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) return _gobject_property_reset_default(setting, property_info->property_name); @@ -2175,7 +2197,8 @@ static gboolean _set_fcn_gobject_ifname(ARGS_SET_FCN) return TRUE; } -static gboolean _set_fcn_vpn_service_type(ARGS_SET_FCN) +static gboolean +_set_fcn_vpn_service_type(ARGS_SET_FCN) { gs_free char *service_name = NULL; @@ -2187,7 +2210,8 @@ static gboolean _set_fcn_vpn_service_type(ARGS_SET_FCN) return TRUE; } -static const char *const *_complete_fcn_vpn_service_type(ARGS_COMPLETE_FCN) +static const char *const * +_complete_fcn_vpn_service_type(ARGS_COMPLETE_FCN) { gsize i, j; char **values; @@ -2240,14 +2264,15 @@ _multilist_validate_fcn_is_ipv4_addr_or_subnet(const char *value, GError **error return value; } -static gboolean _set_fcn_gobject_bytes(ARGS_SET_FCN) +static gboolean +_set_fcn_gobject_bytes(ARGS_SET_FCN) { - gs_free char * val_strip_free = NULL; - gs_free const char **strv = NULL; - const char * val_strip; - const char ** iter; + gs_free char *val_strip_free = NULL; + gs_free const char **strv = NULL; + const char *val_strip; + const char **iter; gs_unref_bytes GBytes *bytes = NULL; - GByteArray * array; + GByteArray *array; if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) return _gobject_property_reset_default(setting, property_info->property_name); @@ -2294,11 +2319,12 @@ done: /*****************************************************************************/ -static gconstpointer _get_fcn_cert_8021x(ARGS_GET_FCN) +static gconstpointer +_get_fcn_cert_8021x(ARGS_GET_FCN) { - NMSetting8021x * s_8021X = NM_SETTING_802_1X(setting); + NMSetting8021x *s_8021X = NM_SETTING_802_1X(setting); const NMSetting8021xSchemeVtable *vtable; - char * str = NULL; + char *str = NULL; RETURN_UNSUPPORTED_GET_TYPE(); @@ -2325,9 +2351,10 @@ static gconstpointer _get_fcn_cert_8021x(ARGS_GET_FCN) RETURN_STR_TO_FREE(str); } -static gboolean _set_fcn_cert_8021x(ARGS_SET_FCN) +static gboolean +_set_fcn_cert_8021x(ARGS_SET_FCN) { - gs_free char * value_to_free = NULL; + gs_free char *value_to_free = NULL; NMSetting8021xCKScheme scheme = NM_SETTING_802_1X_CK_SCHEME_PATH; const NMSetting8021xSchemeVtable *vtable; @@ -2352,9 +2379,9 @@ static gboolean _set_fcn_cert_8021x(ARGS_SET_FCN) if (vtable->is_secret) { nm_auto_free_secret char *password_free = NULL; - gs_free const char ** strv = NULL; - const char * password; - const char * path; + gs_free const char **strv = NULL; + const char *password; + const char *path; gsize len; strv = nm_utils_escaped_tokens_split(value, NM_ASCII_SPACES); @@ -2383,7 +2410,8 @@ static gboolean _set_fcn_cert_8021x(ARGS_SET_FCN) } } -static const char *const *_complete_fcn_cert_8021x(ARGS_COMPLETE_FCN) +static const char *const * +_complete_fcn_cert_8021x(ARGS_COMPLETE_FCN) { const NMSetting8021xSchemeVtable *vtable; @@ -2403,10 +2431,11 @@ static const char *const *_complete_fcn_cert_8021x(ARGS_COMPLETE_FCN) return NULL; } -static gconstpointer _get_fcn_bond_options(ARGS_GET_FCN) +static gconstpointer +_get_fcn_bond_options(ARGS_GET_FCN) { NMSettingBond *s_bond = NM_SETTING_BOND(setting); - GString * str; + GString *str; guint32 i, len; RETURN_UNSUPPORTED_GET_TYPE(); @@ -2414,10 +2443,10 @@ static gconstpointer _get_fcn_bond_options(ARGS_GET_FCN) str = g_string_new(NULL); len = nm_setting_bond_get_num_options(s_bond); for (i = 0; i < len; i++) { - const char * key; - const char * val; + const char *key; + const char *val; gs_free char *val_tmp = NULL; - char * p; + char *p; gs_free char *escaped_key = NULL; gs_free char *escaped_val = NULL; @@ -2444,15 +2473,15 @@ static gconstpointer _get_fcn_bond_options(ARGS_GET_FCN) } gboolean -_nm_meta_setting_bond_add_option(NMSetting * setting, +_nm_meta_setting_bond_add_option(NMSetting *setting, const char *name, const char *value, - GError ** error) + GError **error) { NMSettingBond *s_bond = NM_SETTING_BOND(setting); - gs_free char * tmp_value = NULL; - const char * val2; - char * p; + gs_free char *tmp_value = NULL; + const char *val2; + char *p; if (!value || !value[0]) { /* This call only fails if name is currently not tracked. It's not an @@ -2513,11 +2542,12 @@ _nm_meta_setting_bond_add_option(NMSetting * setting, return TRUE; } -static const char *_describe_fcn_bond_options(ARGS_DESCRIBE_FCN) +static const char * +_describe_fcn_bond_options(ARGS_DESCRIBE_FCN) { gs_free char *options_str = NULL; - const char ** valid_options; - char * s; + const char **valid_options; + char *s; valid_options = nm_setting_bond_get_valid_options(NULL); options_str = g_strjoinv(", ", (char **) valid_options); @@ -2538,17 +2568,19 @@ static const char *_describe_fcn_bond_options(ARGS_DESCRIBE_FCN) return (*out_to_free = s); } -static const char *const *_values_fcn_bond_options(ARGS_VALUES_FCN) +static const char *const * +_values_fcn_bond_options(ARGS_VALUES_FCN) { return nm_setting_bond_get_valid_options(NULL); } -static gconstpointer _get_fcn_connection_permissions(ARGS_GET_FCN) +static gconstpointer +_get_fcn_connection_permissions(ARGS_GET_FCN) { NMSettingConnection *s_con = NM_SETTING_CONNECTION(setting); - GString * perm = NULL; - const char * perm_item; - const char * perm_type; + GString *perm = NULL; + const char *perm_item; + const char *perm_type; guint i, n; RETURN_UNSUPPORTED_GET_TYPE(); @@ -2575,7 +2607,8 @@ static gconstpointer _get_fcn_connection_permissions(ARGS_GET_FCN) return NULL; } -static gboolean _set_fcn_connection_type(ARGS_SET_FCN) +static gboolean +_set_fcn_connection_type(ARGS_SET_FCN) { gs_free char *uuid = NULL; @@ -2603,10 +2636,11 @@ static gboolean _set_fcn_connection_type(ARGS_SET_FCN) return TRUE; } -static const char *const *_complete_fcn_connection_type(ARGS_COMPLETE_FCN) +static const char *const * +_complete_fcn_connection_type(ARGS_COMPLETE_FCN) { guint i, j; - char ** result; + char **result; gsize text_len; const char *slave_types[] = {"bond-slave", "bridge-slave", "team-slave"}; @@ -2617,7 +2651,7 @@ static const char *const *_complete_fcn_connection_type(ARGS_COMPLETE_FCN) for (i = 0, j = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { const NMMetaSettingInfoEditor *setting_info = &nm_meta_setting_infos_editor[i]; GType gtype = setting_info->general->get_setting_gtype(); - const char * v; + const char *v; if (_nm_setting_type_get_base_type_priority(gtype) == NM_SETTING_PRIORITY_INVALID) { nm_assert(!setting_info->valid_parts); @@ -2662,9 +2696,9 @@ _sanitize_connection_permission_user(const char *perm) } static const char * -_multilist_validate2_fcn_connection_permissions(NMSetting * setting, +_multilist_validate2_fcn_connection_permissions(NMSetting *setting, const char *item, - GError ** error) + GError **error) { if (!_sanitize_connection_permission_user(item)) { nm_utils_error_set(error, @@ -2703,14 +2737,15 @@ _multilist_remove_by_value_fcn_connection_permissions(NMSetting *setting, const return TRUE; } -static const char *const *_complete_fcn_connection_master(ARGS_COMPLETE_FCN) +static const char *const * +_complete_fcn_connection_master(ARGS_COMPLETE_FCN) { NMRemoteConnection *const *connections = NULL; guint len = 0; guint i, j; - char ** result; - NMSettingConnection * s_con; - const char * expected_type = NULL; + char **result; + NMSettingConnection *s_con; + const char *expected_type = NULL; gsize text_len; if (environment && environment->get_nm_connections) { @@ -2776,10 +2811,11 @@ _multilist_validate2_fcn_uuid(NMSetting *setting, const char *item, GError **err return item; } -static gconstpointer _get_fcn_connection_metered(ARGS_GET_FCN) +static gconstpointer +_get_fcn_connection_metered(ARGS_GET_FCN) { NMSettingConnection *s_conn = NM_SETTING_CONNECTION(setting); - const char * s; + const char *s; RETURN_UNSUPPORTED_GET_TYPE(); @@ -2802,7 +2838,8 @@ static gconstpointer _get_fcn_connection_metered(ARGS_GET_FCN) return s; } -static gboolean _set_fcn_connection_metered(ARGS_SET_FCN) +static gboolean +_set_fcn_connection_metered(ARGS_SET_FCN) { NMMetered metered; NMTernary ts_val; @@ -2859,10 +2896,11 @@ dcb_flags_to_string(NMSettingDcbFlags flags) return g_string_free(flag_str, FALSE); } -static gconstpointer _get_fcn_dcb(ARGS_GET_FCN) +static gconstpointer +_get_fcn_dcb(ARGS_GET_FCN) { NMSettingDcb *s_dcb = NM_SETTING_DCB(setting); - GString * str; + GString *str; guint i; RETURN_UNSUPPORTED_GET_TYPE(); @@ -2884,7 +2922,8 @@ static gconstpointer _get_fcn_dcb(ARGS_GET_FCN) #define DCB_ALL_FLAGS \ (NM_SETTING_DCB_FLAG_ENABLE | NM_SETTING_DCB_FLAG_ADVERTISE | NM_SETTING_DCB_FLAG_WILLING) -static gconstpointer _get_fcn_dcb_flags(ARGS_GET_FCN) +static gconstpointer +_get_fcn_dcb_flags(ARGS_GET_FCN) { nm_auto_unset_gvalue GValue val = G_VALUE_INIT; guint v; @@ -2898,7 +2937,8 @@ static gconstpointer _get_fcn_dcb_flags(ARGS_GET_FCN) RETURN_STR_TO_FREE(dcb_flags_to_string(v)); } -static gboolean _set_fcn_dcb_flags(ARGS_SET_FCN) +static gboolean +_set_fcn_dcb_flags(ARGS_SET_FCN) { NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE; long int t; @@ -2912,7 +2952,7 @@ static gboolean _set_fcn_dcb_flags(ARGS_SET_FCN) flags = (guint) t; else { gs_free const char **strv = NULL; - const char *const * iter; + const char *const *iter; /* Check for individual flag numbers */ strv = nm_strsplit_set(value, " \t,"); @@ -2950,10 +2990,10 @@ dcb_parse_uint_array(const char *val, guint max, guint other, guint out_array[static 8], - GError ** error) + GError **error) { gs_free const char **items = NULL; - const char *const * iter; + const char *const *iter; gsize i; items = nm_strsplit_set_with_empty(val, ","); @@ -2997,9 +3037,9 @@ dcb_parse_uint_array(const char *val, static void dcb_check_feature_enabled(const NMMetaEnvironment *environment, - gpointer * environment_user_data, - NMSettingDcb * s_dcb, - const char * flags_prop) + gpointer *environment_user_data, + NMSettingDcb *s_dcb, + const char *flags_prop) { NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE; @@ -3013,7 +3053,8 @@ dcb_check_feature_enabled(const NMMetaEnvironment *environment, } } -static gboolean _set_fcn_dcb(ARGS_SET_FCN) +static gboolean +_set_fcn_dcb(ARGS_SET_FCN) { guint i = 0; guint nums[8] = { @@ -3054,10 +3095,11 @@ static gboolean _set_fcn_dcb(ARGS_SET_FCN) return TRUE; } -static gconstpointer _get_fcn_dcb_bool(ARGS_GET_FCN) +static gconstpointer +_get_fcn_dcb_bool(ARGS_GET_FCN) { NMSettingDcb *s_dcb = NM_SETTING_DCB(setting); - GString * str; + GString *str; guint i; RETURN_UNSUPPORTED_GET_TYPE(); @@ -3076,7 +3118,8 @@ static gconstpointer _get_fcn_dcb_bool(ARGS_GET_FCN) RETURN_STR_TO_FREE(g_string_free(str, FALSE)); } -static gboolean _set_fcn_dcb_bool(ARGS_SET_FCN) +static gboolean +_set_fcn_dcb_bool(ARGS_SET_FCN) { guint i = 0; guint nums[8] = { @@ -3105,7 +3148,8 @@ static gboolean _set_fcn_dcb_bool(ARGS_SET_FCN) return TRUE; } -static gboolean _set_fcn_gsm_auto_config(ARGS_SET_FCN) +static gboolean +_set_fcn_gsm_auto_config(ARGS_SET_FCN) { if (!_set_fcn_gobject_bool_impl(property_info, setting, modifier, value, error)) return FALSE; @@ -3127,7 +3171,8 @@ static gboolean _set_fcn_gsm_auto_config(ARGS_SET_FCN) return TRUE; } -static gboolean _set_fcn_gsm_sim_operator_id(ARGS_SET_FCN) +static gboolean +_set_fcn_gsm_sim_operator_id(ARGS_SET_FCN) { const char *p = value; @@ -3152,7 +3197,8 @@ static gboolean _set_fcn_gsm_sim_operator_id(ARGS_SET_FCN) return TRUE; } -static gboolean _set_fcn_infiniband_p_key(ARGS_SET_FCN) +static gboolean +_set_fcn_infiniband_p_key(ARGS_SET_FCN) { gint64 p_key; @@ -3173,7 +3219,8 @@ static gboolean _set_fcn_infiniband_p_key(ARGS_SET_FCN) return TRUE; } -static gconstpointer _get_fcn_infiniband_p_key(ARGS_GET_FCN) +static gconstpointer +_get_fcn_infiniband_p_key(ARGS_GET_FCN) { NMSettingInfiniband *s_infiniband = NM_SETTING_INFINIBAND(setting); int p_key; @@ -3192,7 +3239,8 @@ static gconstpointer _get_fcn_infiniband_p_key(ARGS_GET_FCN) RETURN_STR_TO_FREE(g_strdup_printf("0x%04x", p_key)); } -static gconstpointer _get_fcn_objlist(ARGS_GET_FCN) +static gconstpointer +_get_fcn_objlist(ARGS_GET_FCN) { GString *str = NULL; guint num; @@ -3247,9 +3295,9 @@ static gconstpointer _get_fcn_objlist(ARGS_GET_FCN) static void _objlist_obj_to_str_fcn_ip_config_addresses(NMMetaAccessorGetType get_type, - NMSetting * setting, + NMSetting *setting, guint idx, - GString * str) + GString *str) { NMIPAddress *obj; @@ -3262,14 +3310,14 @@ _objlist_obj_to_str_fcn_ip_config_addresses(NMMetaAccessorGetType get_type, static void _objlist_obj_to_str_fcn_ip_config_routes(NMMetaAccessorGetType get_type, - NMSetting * setting, + NMSetting *setting, guint idx, - GString * str) + GString *str) { - NMIPRoute * route; - gs_free char * attr_str = NULL; - gs_strfreev char **attr_names = NULL; - gs_unref_hashtable GHashTable *hash = g_hash_table_new(nm_str_hash, g_str_equal); + NMIPRoute *route; + gs_free char *attr_str = NULL; + gs_strfreev char **attr_names = NULL; + gs_unref_hashtable GHashTable *hash = g_hash_table_new(nm_str_hash, g_str_equal); int j; route = nm_setting_ip_config_get_route(NM_SETTING_IP_CONFIG(setting), idx); @@ -3314,7 +3362,8 @@ _objlist_obj_to_str_fcn_ip_config_routes(NMMetaAccessorGetType get_type, } } -static gboolean _set_fcn_ip_config_method(ARGS_SET_FCN) +static gboolean +_set_fcn_ip_config_method(ARGS_SET_FCN) { if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value)) return _gobject_property_reset_default(setting, property_info->property_name); @@ -3367,7 +3416,8 @@ _multilist_add_fcn_ip_config_dns_options(NMSetting *setting, const char *item) return TRUE; } -static gboolean _set_fcn_objlist(ARGS_SET_FCN) +static gboolean +_set_fcn_objlist(ARGS_SET_FCN) { gs_free const char **strv = NULL; gsize i, nstrv; @@ -3439,10 +3489,10 @@ static gboolean _set_fcn_objlist(ARGS_SET_FCN) } static gboolean -_objlist_set_fcn_ip_config_addresses(NMSetting * setting, +_objlist_set_fcn_ip_config_addresses(NMSetting *setting, gboolean do_add, const char *value, - GError ** error) + GError **error) { int addr_family = nm_setting_ip_config_get_addr_family(NM_SETTING_IP_CONFIG(setting)); nm_auto_unref_ip_address NMIPAddress *addr = NULL; @@ -3457,7 +3507,8 @@ _objlist_set_fcn_ip_config_addresses(NMSetting * setting, return TRUE; } -static gboolean _set_fcn_ip_config_gateway(ARGS_SET_FCN) +static gboolean +_set_fcn_ip_config_gateway(ARGS_SET_FCN) { gs_free char *value_to_free = NULL; int addr_family = nm_setting_ip_config_get_addr_family(NM_SETTING_IP_CONFIG(setting)); @@ -3489,10 +3540,10 @@ static gboolean _set_fcn_ip_config_gateway(ARGS_SET_FCN) } static gboolean -_objlist_set_fcn_ip_config_routes(NMSetting * setting, +_objlist_set_fcn_ip_config_routes(NMSetting *setting, gboolean do_add, const char *value, - GError ** error) + GError **error) { int addr_family = nm_setting_ip_config_get_addr_family(NM_SETTING_IP_CONFIG(setting)); nm_auto_unref_ip_route NMIPRoute *route = NULL; @@ -3515,12 +3566,12 @@ _is_default_func_ip_config_dns_options(NMSetting *setting) static void _objlist_obj_to_str_fcn_ip_config_routing_rules(NMMetaAccessorGetType get_type, - NMSetting * setting, + NMSetting *setting, guint idx, - GString * str) + GString *str) { NMIPRoutingRule *rule; - gs_free char * s = NULL; + gs_free char *s = NULL; rule = nm_setting_ip_config_get_routing_rule(NM_SETTING_IP_CONFIG(setting), idx); s = nm_ip_routing_rule_to_string(rule, NM_IP_ROUTING_RULE_AS_STRING_FLAGS_NONE, NULL, NULL); @@ -3529,12 +3580,12 @@ _objlist_obj_to_str_fcn_ip_config_routing_rules(NMMetaAccessorGetType get_type, } static gboolean -_objlist_set_fcn_ip_config_routing_rules(NMSetting * setting, +_objlist_set_fcn_ip_config_routing_rules(NMSetting *setting, gboolean do_add, const char *str, - GError ** error) + GError **error) { - NMSettingIPConfig * s_ip = NM_SETTING_IP_CONFIG(setting); + NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG(setting); nm_auto_unref_ip_routing_rule NMIPRoutingRule *rule = NULL; guint i, n; @@ -3581,7 +3632,7 @@ _multilist_get_num_fcn_ip_config_dhcp_reject_servers(NMSettingIPConfig *setting) static gboolean _multilist_remove_by_value_fcn_ip_config_dhcp_reject_servers(NMSettingIPConfig *setting, - const char * item) + const char *item) { const char *const *strv; guint num; @@ -3594,11 +3645,12 @@ _multilist_remove_by_value_fcn_ip_config_dhcp_reject_servers(NMSettingIPConfig * return TRUE; } -static gconstpointer _get_fcn_olpc_mesh_ssid(ARGS_GET_FCN) +static gconstpointer +_get_fcn_olpc_mesh_ssid(ARGS_GET_FCN) { NMSettingOlpcMesh *s_olpc_mesh = NM_SETTING_OLPC_MESH(setting); - GBytes * ssid; - char * ssid_str = NULL; + GBytes *ssid; + char *ssid_str = NULL; RETURN_UNSUPPORTED_GET_TYPE(); @@ -3611,7 +3663,8 @@ static gconstpointer _get_fcn_olpc_mesh_ssid(ARGS_GET_FCN) RETURN_STR_TO_FREE(ssid_str); } -static gboolean _set_fcn_olpc_mesh_channel(ARGS_SET_FCN) +static gboolean +_set_fcn_olpc_mesh_channel(ARGS_SET_FCN) { unsigned long chan_int; @@ -3638,12 +3691,12 @@ _validate_fcn_proxy_pac_script(const char *value, char **out_to_free, GError **e static void _objlist_obj_to_str_fcn_sriov_vfs(NMMetaAccessorGetType get_type, - NMSetting * setting, + NMSetting *setting, guint idx, - GString * str) + GString *str) { gs_free char *s = NULL; - NMSriovVF * vf; + NMSriovVF *vf; vf = nm_setting_sriov_get_vf(NM_SETTING_SRIOV(setting), idx); s = nm_utils_sriov_vf_to_str(vf, FALSE, NULL); @@ -3653,12 +3706,12 @@ _objlist_obj_to_str_fcn_sriov_vfs(NMMetaAccessorGetType get_type, static void _objlist_obj_to_str_fcn_tc_config_qdiscs(NMMetaAccessorGetType get_type, - NMSetting * setting, + NMSetting *setting, guint idx, - GString * str) + GString *str) { gs_free char *s = NULL; - NMTCQdisc * qdisc; + NMTCQdisc *qdisc; qdisc = nm_setting_tc_config_get_qdisc(NM_SETTING_TC_CONFIG(setting), idx); s = nm_utils_tc_qdisc_to_str(qdisc, NULL); @@ -3668,9 +3721,9 @@ _objlist_obj_to_str_fcn_tc_config_qdiscs(NMMetaAccessorGetType get_type, static void _objlist_obj_to_str_fcn_bridge_vlans(NMMetaAccessorGetType get_type, - NMSetting * setting, + NMSetting *setting, guint idx, - GString * str) + GString *str) { gs_free char *s = NULL; NMBridgeVlan *vlan; @@ -3688,8 +3741,8 @@ _objlist_obj_to_str_fcn_bridge_vlans(NMMetaAccessorGetType get_type, static gboolean _objlist_set_fcn_sriov_vfs(NMSetting *setting, gboolean do_add, const char *value, GError **error) { - nm_auto_unref_sriov_vf NMSriovVF *vf = NULL; - gs_free_error GError *local = NULL; + nm_auto_unref_sriov_vf NMSriovVF *vf = NULL; + gs_free_error GError *local = NULL; vf = nm_utils_sriov_vf_from_str(value, &local); if (!vf) { @@ -3709,13 +3762,13 @@ _objlist_set_fcn_sriov_vfs(NMSetting *setting, gboolean do_add, const char *valu } static gboolean -_objlist_set_fcn_tc_config_qdiscs(NMSetting * setting, +_objlist_set_fcn_tc_config_qdiscs(NMSetting *setting, gboolean do_add, const char *value, - GError ** error) + GError **error) { nm_auto_unref_tc_qdisc NMTCQdisc *tc_qdisc = NULL; - gs_free_error GError *local = NULL; + gs_free_error GError *local = NULL; tc_qdisc = nm_utils_tc_qdisc_from_str(value, &local); if (!tc_qdisc) { @@ -3735,14 +3788,14 @@ _objlist_set_fcn_tc_config_qdiscs(NMSetting * setting, } static gboolean -_objlist_set_fcn_bridge_vlans(NMSetting * setting, +_objlist_set_fcn_bridge_vlans(NMSetting *setting, gboolean do_add, const char *value, - GError ** error) + GError **error) { - nm_auto_unref_bridge_vlan NMBridgeVlan *vlan = NULL; - gs_free_error GError *local = NULL; - guint16 vid_start, vid_end; + nm_auto_unref_bridge_vlan NMBridgeVlan *vlan = NULL; + gs_free_error GError *local = NULL; + guint16 vid_start, vid_end; vlan = nm_bridge_vlan_from_str(value, &local); if (!vlan) { @@ -3777,11 +3830,11 @@ _objlist_set_fcn_bridge_vlans(NMSetting * setting, static void _objlist_obj_to_str_fcn_tc_config_tfilters(NMMetaAccessorGetType get_type, - NMSetting * setting, + NMSetting *setting, guint idx, - GString * str) + GString *str) { - NMTCTfilter * tfilter; + NMTCTfilter *tfilter; gs_free char *s = NULL; tfilter = nm_setting_tc_config_get_tfilter(NM_SETTING_TC_CONFIG(setting), idx); @@ -3791,12 +3844,12 @@ _objlist_obj_to_str_fcn_tc_config_tfilters(NMMetaAccessorGetType get_type, } static gboolean -_objlist_set_fcn_tc_config_tfilters(NMSetting * setting, +_objlist_set_fcn_tc_config_tfilters(NMSetting *setting, gboolean do_add, const char *value, - GError ** error) + GError **error) { - gs_free_error GError * local = NULL; + gs_free_error GError *local = NULL; nm_auto_unref_tc_tfilter NMTCTfilter *tc_tfilter = NULL; tc_tfilter = nm_utils_tc_tfilter_from_str(value, &local); @@ -3828,12 +3881,12 @@ _validate_fcn_team_config(const char *value, char **out_to_free, GError **error) static void _objlist_obj_to_str_fcn_team_link_watchers(NMMetaAccessorGetType get_type, - NMSetting * setting, + NMSetting *setting, guint idx, - GString * str) + GString *str) { NMTeamLinkWatcher *watcher; - gs_free char * s = NULL; + gs_free char *s = NULL; if (NM_IS_SETTING_TEAM(setting)) watcher = nm_setting_team_get_link_watcher(NM_SETTING_TEAM(setting), idx); @@ -3846,10 +3899,10 @@ _objlist_obj_to_str_fcn_team_link_watchers(NMMetaAccessorGetType get_type, } static gboolean -_objlist_set_fcn_team_link_watchers(NMSetting * setting, +_objlist_set_fcn_team_link_watchers(NMSetting *setting, gboolean do_add, const char *value, - GError ** error) + GError **error) { nm_auto_unref_team_link_watcher NMTeamLinkWatcher *watcher = NULL; @@ -3871,7 +3924,8 @@ _objlist_set_fcn_team_link_watchers(NMSetting * setting, return TRUE; } -static gconstpointer _get_fcn_vlan_flags(ARGS_GET_FCN) +static gconstpointer +_get_fcn_vlan_flags(ARGS_GET_FCN) { NMSettingVlan *s_vlan = NM_SETTING_VLAN(setting); guint32 flags; @@ -3898,11 +3952,12 @@ _vlan_priority_map_type_from_property_info(const NMMetaPropertyInfo *property_in : NM_VLAN_EGRESS_MAP; } -static gconstpointer _get_fcn_vlan_xgress_priority_map(ARGS_GET_FCN) +static gconstpointer +_get_fcn_vlan_xgress_priority_map(ARGS_GET_FCN) { NMVlanPriorityMap map_type = _vlan_priority_map_type_from_property_info(property_info); - NMSettingVlan * s_vlan = NM_SETTING_VLAN(setting); - GString * str = NULL; + NMSettingVlan *s_vlan = NM_SETTING_VLAN(setting); + GString *str = NULL; gint32 i, num; RETURN_UNSUPPORTED_GET_TYPE(); @@ -3927,7 +3982,8 @@ static gconstpointer _get_fcn_vlan_xgress_priority_map(ARGS_GET_FCN) RETURN_STR_TO_FREE(g_string_free(str, FALSE)); } -static gboolean _set_fcn_vlan_xgress_priority_map(ARGS_SET_FCN) +static gboolean +_set_fcn_vlan_xgress_priority_map(ARGS_SET_FCN) { NMVlanPriorityMap map_type = _vlan_priority_map_type_from_property_info(property_info); gs_free const char **prio_map = NULL; @@ -3970,7 +4026,7 @@ static gboolean _set_fcn_vlan_xgress_priority_map(ARGS_SET_FCN) static void _vpn_options_callback(const char *key, const char *val, gpointer user_data) { - GString * str = user_data; + GString *str = user_data; gs_free char *escaped_key = NULL; gs_free char *escaped_val = NULL; @@ -3982,10 +4038,11 @@ _vpn_options_callback(const char *key, const char *val, gpointer user_data) g_string_append(str, nm_utils_escaped_tokens_options_escape_val(val, &escaped_val)); } -static gconstpointer _get_fcn_vpn_options(ARGS_GET_FCN) +static gconstpointer +_get_fcn_vpn_options(ARGS_GET_FCN) { NMSettingVpn *s_vpn = NM_SETTING_VPN(setting); - GString * str; + GString *str; RETURN_UNSUPPORTED_GET_TYPE(); @@ -3999,10 +4056,10 @@ static gconstpointer _get_fcn_vpn_options(ARGS_GET_FCN) } static gboolean -_optionlist_set_fcn_vpn_data(NMSetting * setting, +_optionlist_set_fcn_vpn_data(NMSetting *setting, const char *option, const char *value, - GError ** error) + GError **error) { if (value) nm_setting_vpn_add_data_item(NM_SETTING_VPN(setting), option, value); @@ -4012,10 +4069,10 @@ _optionlist_set_fcn_vpn_data(NMSetting * setting, } static gboolean -_optionlist_set_fcn_vpn_secrets(NMSetting * setting, +_optionlist_set_fcn_vpn_secrets(NMSetting *setting, const char *option, const char *value, - GError ** error) + GError **error) { if (value) nm_setting_vpn_add_secret(NM_SETTING_VPN(setting), option, value); @@ -4024,7 +4081,8 @@ _optionlist_set_fcn_vpn_secrets(NMSetting * setting, return TRUE; } -static gboolean _set_fcn_wired_s390_subchannels(ARGS_SET_FCN) +static gboolean +_set_fcn_wired_s390_subchannels(ARGS_SET_FCN) { gs_free const char **strv = NULL; gsize len; @@ -4044,10 +4102,10 @@ static gboolean _set_fcn_wired_s390_subchannels(ARGS_SET_FCN) } static gboolean -_optionlist_set_fcn_wired_s390_options(NMSetting * setting, +_optionlist_set_fcn_wired_s390_options(NMSetting *setting, const char *name, const char *value, - GError ** error) + GError **error) { if (value) nm_setting_wired_add_s390_option(NM_SETTING_WIRED(setting), name, value); @@ -4056,16 +4114,18 @@ _optionlist_set_fcn_wired_s390_options(NMSetting * setting, return TRUE; } -static const char *const *_values_fcn_wired_s390_options(ARGS_VALUES_FCN) +static const char *const * +_values_fcn_wired_s390_options(ARGS_VALUES_FCN) { return nm_setting_wired_get_valid_s390_options(NULL); } -static const char *_describe_fcn_wired_s390_options(ARGS_DESCRIBE_FCN) +static const char * +_describe_fcn_wired_s390_options(ARGS_DESCRIBE_FCN) { gs_free char *options_str = NULL; - const char ** valid_options; - char * s; + const char **valid_options; + char *s; valid_options = nm_setting_wired_get_valid_s390_options(NULL); @@ -4078,11 +4138,12 @@ static const char *_describe_fcn_wired_s390_options(ARGS_DESCRIBE_FCN) return (*out_to_free = s); } -static gconstpointer _get_fcn_wireless_ssid(ARGS_GET_FCN) +static gconstpointer +_get_fcn_wireless_ssid(ARGS_GET_FCN) { NMSettingWireless *s_wireless = NM_SETTING_WIRELESS(setting); - GBytes * ssid; - char * ssid_str = NULL; + GBytes *ssid; + char *ssid_str = NULL; RETURN_UNSUPPORTED_GET_TYPE(); @@ -4095,7 +4156,8 @@ static gconstpointer _get_fcn_wireless_ssid(ARGS_GET_FCN) RETURN_STR_TO_FREE(ssid_str); } -static gboolean _set_fcn_wireless_channel(ARGS_SET_FCN) +static gboolean +_set_fcn_wireless_channel(ARGS_SET_FCN) { unsigned long chan_int; @@ -4133,10 +4195,11 @@ _multilist_validate2_fcn_mac_addr(NMSetting *setting, const char *item, GError * return item; } -static gconstpointer _get_fcn_wireless_security_wep_key(ARGS_GET_FCN) +static gconstpointer +_get_fcn_wireless_security_wep_key(ARGS_GET_FCN) { NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY(setting); - char * key; + char *key; guint index; RETURN_UNSUPPORTED_GET_TYPE(); @@ -4152,7 +4215,8 @@ static gconstpointer _get_fcn_wireless_security_wep_key(ARGS_GET_FCN) RETURN_STR_TO_FREE(key); } -static gboolean _set_fcn_wireless_wep_key(ARGS_SET_FCN) +static gboolean +_set_fcn_wireless_wep_key(ARGS_SET_FCN) { NMWepKeyType guessed_type = NM_WEP_KEY_TYPE_UNKNOWN; NMWepKeyType type; @@ -4221,9 +4285,9 @@ static gboolean _set_fcn_wireless_wep_key(ARGS_SET_FCN) static void _gobject_enum_pre_set_notify_fcn_wireless_security_wep_key_type( const NMMetaPropertyInfo *property_info, - const NMMetaEnvironment * environment, + const NMMetaEnvironment *environment, gpointer environment_user_data, - NMSetting * setting, + NMSetting *setting, int value) { guint i; @@ -4255,7 +4319,8 @@ _gobject_enum_pre_set_notify_fcn_wireless_security_wep_key_type( /*****************************************************************************/ -static gconstpointer _get_fcn_ethtool(ARGS_GET_FCN) +static gconstpointer +_get_fcn_ethtool(ARGS_GET_FCN) { NMEthtoolID ethtool_id = property_info->property_typ_data->subtype.ethtool.ethtool_id; const char *s; @@ -4286,7 +4351,8 @@ static gconstpointer _get_fcn_ethtool(ARGS_GET_FCN) return s; } -static gboolean _set_fcn_ethtool(ARGS_SET_FCN) +static gboolean +_set_fcn_ethtool(ARGS_SET_FCN) { NMEthtoolID ethtool_id = property_info->property_typ_data->subtype.ethtool.ethtool_id; gint64 i64; @@ -4336,7 +4402,8 @@ do_unset: return TRUE; } -static const char *const *_complete_fcn_ethtool(ARGS_COMPLETE_FCN) +static const char *const * +_complete_fcn_ethtool(ARGS_COMPLETE_FCN) { static const char *const v[] = { "true", @@ -6618,7 +6685,10 @@ static const NMMetaPropertyInfo *const property_infos_OVS_BRIDGE[] = { static const NMMetaPropertyInfo *const property_infos_OVS_DPDK[] = { PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_DPDK_DEVARGS, .property_type = &_pt_gobject_string, - ), + ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_OVS_DPDK_N_RXQ, + .property_type = &_pt_gobject_int, + ), NULL }; @@ -8596,16 +8666,16 @@ _meta_type_property_info_get_name(const NMMetaAbstractInfo *abstract_info, gbool } static gconstpointer -_meta_type_setting_info_editor_get_fcn(const NMMetaAbstractInfo * abstract_info, - const NMMetaEnvironment * environment, +_meta_type_setting_info_editor_get_fcn(const NMMetaAbstractInfo *abstract_info, + const NMMetaEnvironment *environment, gpointer environment_user_data, gpointer target, gpointer target_data, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, - gboolean * out_is_default, - gpointer * out_to_free) + gboolean *out_is_default, + gpointer *out_to_free) { const NMMetaSettingInfoEditor *info = (const NMMetaSettingInfoEditor *) abstract_info; @@ -8622,16 +8692,16 @@ _meta_type_setting_info_editor_get_fcn(const NMMetaAbstractInfo * abstract_info, } static gconstpointer -_meta_type_property_info_get_fcn(const NMMetaAbstractInfo * abstract_info, - const NMMetaEnvironment * environment, +_meta_type_property_info_get_fcn(const NMMetaAbstractInfo *abstract_info, + const NMMetaEnvironment *environment, gpointer environment_user_data, gpointer target, gpointer target_data, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, - gboolean * out_is_default, - gpointer * out_to_free) + gboolean *out_is_default, + gpointer *out_to_free) { const NMMetaPropertyInfo *info = (const NMMetaPropertyInfo *) abstract_info; gboolean is_default_local = FALSE; @@ -8671,8 +8741,8 @@ _meta_type_property_info_get_fcn(const NMMetaAbstractInfo * abstract_info, static const NMMetaAbstractInfo *const * _meta_type_setting_info_editor_get_nested(const NMMetaAbstractInfo *abstract_info, - guint * out_len, - gpointer * out_to_free) + guint *out_len, + gpointer *out_to_free) { const NMMetaSettingInfoEditor *info; @@ -8684,21 +8754,21 @@ _meta_type_setting_info_editor_get_nested(const NMMetaAbstractInfo *abstract_inf static const NMMetaAbstractInfo *const * _meta_type_property_info_get_nested(const NMMetaAbstractInfo *abstract_info, - guint * out_len, - gpointer * out_to_free) + guint *out_len, + gpointer *out_to_free) { NM_SET_OUT(out_len, 0); return NULL; } static const char *const * -_meta_type_property_info_complete_fcn(const NMMetaAbstractInfo * abstract_info, - const NMMetaEnvironment * environment, +_meta_type_property_info_complete_fcn(const NMMetaAbstractInfo *abstract_info, + const NMMetaEnvironment *environment, gpointer environment_user_data, const NMMetaOperationContext *operation_context, - const char * text, - gboolean * out_complete_filename, - char *** out_to_free) + const char *text, + gboolean *out_complete_filename, + char ***out_to_free) { const NMMetaPropertyInfo *info = (const NMMetaPropertyInfo *) abstract_info; diff --git a/src/libnmc-setting/nm-meta-setting-desc.h b/src/libnmc-setting/nm-meta-setting-desc.h index 29416dcb..91905253 100644 --- a/src/libnmc-setting/nm-meta-setting-desc.h +++ b/src/libnmc-setting/nm-meta-setting-desc.h @@ -203,32 +203,32 @@ struct _NMMetaPropertyType { /* should return a translated string */ const char *(*describe_fcn)(const NMMetaPropertyInfo *property_info, char **out_to_free); - gconstpointer (*get_fcn)(const NMMetaPropertyInfo * property_info, - const NMMetaEnvironment * environment, + gconstpointer (*get_fcn)(const NMMetaPropertyInfo *property_info, + const NMMetaEnvironment *environment, gpointer environment_user_data, - NMSetting * setting, + NMSetting *setting, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, - gboolean * out_is_default, - gpointer * out_to_free); + gboolean *out_is_default, + gpointer *out_to_free); gboolean (*set_fcn)(const NMMetaPropertyInfo *property_info, - const NMMetaEnvironment * environment, + const NMMetaEnvironment *environment, gpointer environment_user_data, - NMSetting * setting, + NMSetting *setting, NMMetaAccessorModifier modifier, - const char * value, - GError ** error); + const char *value, + GError **error); const char *const *(*values_fcn)(const NMMetaPropertyInfo *property_info, char ***out_to_free); - const char *const *(*complete_fcn)(const NMMetaPropertyInfo * property_info, - const NMMetaEnvironment * environment, + const char *const *(*complete_fcn)(const NMMetaPropertyInfo *property_info, + const NMMetaEnvironment *environment, gpointer environment_user_data, const NMMetaOperationContext *operation_context, - const char * text, - gboolean * out_complete_filename, - char *** out_to_free); + const char *text, + gboolean *out_complete_filename, + char ***out_to_free); /* Whether set_fcn() supports the '-' modifier. That is, whether the property * is a list type. */ @@ -243,7 +243,7 @@ typedef union { } NMMetaSignUnsignInt64; typedef struct { - const char * nick; + const char *nick; NMMetaSignUnsignInt64 value; } NMMetaUtilsIntValueInfo; @@ -256,9 +256,9 @@ struct _NMMetaPropertyTypData { const struct _NMUtilsEnumValueInfo *value_infos_get; /* nicks for get function */ const struct _NMUtilsEnumValueInfo *value_infos; /* nicks for set function */ void (*pre_set_notify)(const NMMetaPropertyInfo *property_info, - const NMMetaEnvironment * environment, + const NMMetaEnvironment *environment, gpointer environment_user_data, - NMSetting * setting, + NMSetting *setting, int value); } gobject_enum; struct { @@ -299,13 +299,13 @@ struct _NMMetaPropertyTypData { struct { guint (*get_num_fcn)(NMSetting *setting); void (*obj_to_str_fcn)(NMMetaAccessorGetType get_type, - NMSetting * setting, + NMSetting *setting, guint idx, - GString * str); - gboolean (*set_fcn)(NMSetting * setting, + GString *str); + gboolean (*set_fcn)(NMSetting *setting, gboolean do_add /* or else remove. */, const char *value, - GError ** error); + GError **error); void (*clear_all_fcn)(NMSetting *setting); void (*remove_by_idx_fcn_u)(NMSetting *setting, guint idx); void (*remove_by_idx_fcn_s)(NMSetting *setting, int idx); @@ -313,10 +313,10 @@ struct _NMMetaPropertyTypData { bool strsplit_plain : 1; } objlist; struct { - gboolean (*set_fcn)(NMSetting * setting, + gboolean (*set_fcn)(NMSetting *setting, const char *option, const char *value, - GError ** error); + GError **error); bool no_empty_value : 1; } optionlist; struct { @@ -345,7 +345,7 @@ struct _NMMetaPropertyTypData { } ethtool; } subtype; gboolean (*is_default_fcn)(NMSetting *setting); - const char *const * values_static; + const char *const *values_static; const NMMetaPropertyTypDataNested *nested; NMMetaPropertyTypFlags typ_flags; }; @@ -396,7 +396,7 @@ struct _NMMetaPropertyInfo { /* a non-translated but translatable static description (marked with N_()). */ const char *describe_message; - const NMMetaPropertyType * property_type; + const NMMetaPropertyType *property_type; const NMMetaPropertyTypData *property_typ_data; }; @@ -410,9 +410,9 @@ struct _NMMetaSettingInfoEditor { NMObjBaseInst parent; const NMMetaType *meta_type; }; - const NMMetaSettingInfo * general; - const char * alias; - const char * pretty_name; + const NMMetaSettingInfo *general; + const char *alias; + const char *pretty_name; const NMMetaPropertyInfo *const *properties; guint properties_num; @@ -429,34 +429,34 @@ struct _NMMetaSettingInfoEditor { const NMMetaSettingValidPartItem *const *valid_parts; void (*setting_init_fcn)(const NMMetaSettingInfoEditor *setting_info, - NMSetting * setting, + NMSetting *setting, NMMetaAccessorSettingInitType init_type); }; struct _NMMetaType { NMObjBaseClass parent; - const char * type_name; + const char *type_name; const char *(*get_name)(const NMMetaAbstractInfo *abstract_info, gboolean for_header); const NMMetaAbstractInfo *const *(*get_nested)(const NMMetaAbstractInfo *abstract_info, - guint * out_len, - gpointer * out_to_free); - gconstpointer (*get_fcn)(const NMMetaAbstractInfo * info, - const NMMetaEnvironment * environment, + guint *out_len, + gpointer *out_to_free); + gconstpointer (*get_fcn)(const NMMetaAbstractInfo *info, + const NMMetaEnvironment *environment, gpointer environment_user_data, gpointer target, gpointer target_data, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, - gboolean * out_is_default, - gpointer * out_to_free); - const char *const *(*complete_fcn)(const NMMetaAbstractInfo * info, - const NMMetaEnvironment * environment, + gboolean *out_is_default, + gpointer *out_to_free); + const char *const *(*complete_fcn)(const NMMetaAbstractInfo *info, + const NMMetaEnvironment *environment, gpointer environment_user_data, const NMMetaOperationContext *operation_context, - const char * text, - gboolean * out_complete_filename, - char *** out_to_free); + const char *text, + gboolean *out_complete_filename, + char ***out_to_free); }; struct _NMMetaAbstractInfo { @@ -474,7 +474,7 @@ extern const NMMetaSettingInfoEditor nm_meta_setting_infos_editor[_NM_META_SETTI extern const NMMetaSettingValidPartItem *const nm_meta_setting_info_valid_parts_default[]; const NMMetaSettingValidPartItem *const * -nm_meta_setting_info_valid_parts_for_slave_type(const char * slave_type, +nm_meta_setting_info_valid_parts_for_slave_type(const char *slave_type, const char **out_slave_name); /*****************************************************************************/ @@ -499,11 +499,11 @@ struct _NMMetaEnvironment { struct _NMDevice *const *(*get_nm_devices)(const NMMetaEnvironment *environment, gpointer environment_user_data, - guint * out_len); + guint *out_len); struct _NMRemoteConnection *const *(*get_nm_connections)(const NMMetaEnvironment *environment, gpointer environment_user_data, - guint * out_len); + guint *out_len); }; /*****************************************************************************/ @@ -516,7 +516,7 @@ extern const NMMetaType nm_meta_type_nested_property_info; struct _NMMetaNestedPropertyInfo { union { - const NMMetaType * meta_type; + const NMMetaType *meta_type; NMMetaPropertyInfo base; }; const NMMetaPropertyInfo *parent_info; @@ -531,10 +531,10 @@ extern const NMMetaPropertyTypDataNested nm_meta_property_typ_data_bond; /*****************************************************************************/ -gboolean _nm_meta_setting_bond_add_option(NMSetting * setting, +gboolean _nm_meta_setting_bond_add_option(NMSetting *setting, const char *name, const char *value, - GError ** error); + GError **error); /*****************************************************************************/ diff --git a/src/libnmc-setting/settings-docs-input.xml b/src/libnmc-setting/settings-docs-input.xml index 3555f302..37ad35ba 100644 --- a/src/libnmc-setting/settings-docs-input.xml +++ b/src/libnmc-setting/settings-docs-input.xml @@ -1,4 +1,144 @@ - + + +A list of IPv4 destination addresses, prefix length, optional IPv4 +next hop addresses, optional route metric, optional attribute. The valid syntax is: +"ip[/prefix] [next-hop] [metric] [attribute=val]...[,ip[/prefix]...]". +For example "192.0.2.0/24 10.1.1.1 77, 198.51.100.0/24". + + +Various attributes are supported: + + +"cwnd" - an unsigned 32 bit integer. + + +"initcwnd" - an unsigned 32 bit integer. + + +"initrwnd" - an unsigned 32 bit integer. + + +"lock-cwnd" - a boolean value. + + +"lock-initcwnd" - a boolean value. + + +"lock-initrwnd" - a boolean value. + + +"lock-mtu" - a boolean value. + + +"lock-window" - a boolean value. + + +"mtu" - an unsigned 32 bit integer. + + +"onlink" - a boolean value. + + +"scope" - an unsigned 8 bit integer. IPv4 only. + + +"src" - an IPv4 address. + + +"table" - an unsigned 32 bit integer. The default depends on ipv4.route-table. + + +"tos" - an unsigned 8 bit integer. IPv4 only. + + +"type" - one of unicast, local, blackhole, +unavailable, prohibit. The default is unicast. + + +"window" - an unsigned 32 bit integer. + + + + +For details see also `man ip-route`. + + +A comma separated list of routing rules for policy routing. The format +is based on ip rule add syntax and mostly compatible. +One difference is that routing rules in NetworkManager always need a +fixed priority. + + +Example: priority 5 from 192.167.4.0/24 table 45 + + +A list of IPv6 destination addresses, prefix length, optional IPv6 +next hop addresses, optional route metric, optional attribute. The valid syntax is: +"ip[/prefix] [next-hop] [metric] [attribute=val]...[,ip[/prefix]...]". + + +Various attributes are supported: + + +"cwnd" - an unsigned 32 bit integer. + + +"from" - an IPv6 address with optional prefix. IPv6 only. + + +"initcwnd" - an unsigned 32 bit integer. + + +"initrwnd" - an unsigned 32 bit integer. + + +"lock-cwnd" - a boolean value. + + +"lock-initcwnd" - a boolean value. + + +"lock-initrwnd" - a boolean value. + + +"lock-mtu" - a boolean value. + + +"lock-window" - a boolean value. + + +"mtu" - an unsigned 32 bit integer. + + +"onlink" - a boolean value. + + +"src" - an IPv6 address. + + +"table" - an unsigned 32 bit integer. The default depends on ipv6.route-table. + + +"type" - one of unicast, local, blackhole, +unavailable, prohibit. The default is unicast. + + +"window" - an unsigned 32 bit integer. + + + + +For details see also `man ip-route`. + + +A comma separated list of routing rules for policy routing. The format +is based on ip rule add syntax and mostly compatible. +One difference is that routing rules in NetworkManager always need a +fixed priority. + + +Example: priority 5 from 1:2:3::5/128 table 45 + Array of TC queueing disciplines. qdisc is a basic block in the Linux traffic control subsystem @@ -8,9 +148,7 @@ Each qdisc can be specified by the following attributes: - -handle HANDLE - +handle HANDLE specifies the qdisc handle. A qdisc, which potentially can have children, gets @@ -21,9 +159,7 @@ explicitly assign a handle to qdiscs expected to have children. - -parent HANDLE - +parent HANDLE specifies the handle of the parent qdisc the current qdisc must be @@ -32,9 +168,7 @@ attached to. - -root - +root specifies that the qdisc is attached to the root of device. @@ -42,9 +176,7 @@ specifies that the qdisc is attached to the root of device. - -KIND - +KIND this is the qdisc kind. NetworkManager currently supports the @@ -61,9 +193,7 @@ Parameters for 'fq_codel': - -limit U32 - +limit U32 the hard limit on the real queue size. When this limit is @@ -72,9 +202,7 @@ reached, incoming packets are dropped. Default is 10240 packets. - -memory_limit U32 - +memory_limit U32 sets a limit on the total number of bytes that can be queued in @@ -85,9 +213,7 @@ limit parameter and the memory limit will be enforced. Default is - -flows U32 - +flows U32 the number of flows into which the incoming packets are @@ -100,9 +226,7 @@ Default value is 1024. - -target U32 - +target U32 the acceptable minimum standing/persistent queue delay. This minimum @@ -112,9 +236,7 @@ experience. The unit of measurement is microsecond(us). Default value is 5ms. - -interval U32 - +interval U32 used to ensure that the measured minimum delay does not become too stale. @@ -126,9 +248,7 @@ react. Default value is 100ms. - -quantum U32 - +quantum U32 the number of bytes used as 'deficit' in the fair queuing @@ -138,9 +258,7 @@ Ethernet MTU plus the hardware header length of 14 bytes. - -ecn BOOL - +ecn BOOL can be used to mark packets instead of dropping them. ecn is turned @@ -149,9 +267,7 @@ on by default. - -ce_threshold U32 - +ce_threshold U32 sets a threshold above which all packets are marked with ECN @@ -167,9 +283,7 @@ Parameters for 'sfq': - -divisor U32 - +divisor U32 can be used to set a different hash table size, available @@ -180,9 +294,7 @@ value: 1024. - -limit U32 - +limit U32 Upper limit of the SFQ. Can be used to reduce the default @@ -191,9 +303,7 @@ length of 127 packets. - -depth U32 - +depth U32 Limit of packets per flow. Default to @@ -202,9 +312,7 @@ Limit of packets per flow. Default to - -perturb_period U32 - +perturb_period U32 Interval in seconds for queue algorithm perturbation. @@ -218,9 +326,7 @@ collisions. - -quantum U32 - +quantum U32 Amount of bytes a flow is allowed to dequeue during a @@ -231,9 +337,7 @@ minimum value. - -flows U32 - +flows U32 Default value is 127. @@ -246,9 +350,7 @@ Parameters for 'tbf': - -rate U64 - +rate U64 Bandwidth or rate. These parameters accept a floating @@ -260,9 +362,7 @@ device's speed. - -burst U32 - +burst U32 Also known as buffer or maxburst. Size of the bucket, in @@ -289,9 +389,7 @@ have to set this. Must be an integral power of 2. - -limit U32 - +limit U32 Limit is the number of bytes that can be queued waiting @@ -300,9 +398,7 @@ for tokens to become available. - -latency U32 - +latency U32 specifies the maximum amount of time a packet can @@ -312,9 +408,7 @@ the size of the bucket, the rate and possibly the peakrate - - - + Array of TC traffic filters. Traffic control can manage the packet content during classification by using filters. @@ -324,9 +418,7 @@ Each tfilters can be specified by the following attributes: - -handle HANDLE - +handle HANDLE specifies the tfilters handle. A filter is used by a classful qdisc to determine in which class @@ -336,9 +428,7 @@ see qdiscs handle for detailed information. - -parent HANDLE - +parent HANDLE specifies the handle of the parent qdisc the current qdisc must be @@ -347,9 +437,7 @@ attached to. - -root - +root specifies that the qdisc is attached to the root of device. @@ -357,9 +445,7 @@ specifies that the qdisc is attached to the root of device. - -KIND - +KIND this is the tfilters kind. NetworkManager currently supports @@ -375,9 +461,7 @@ Actions for 'mirred': - -egress bool - +egress bool Define whether the packet should exit from the interface. @@ -385,9 +469,7 @@ Define whether the packet should exit from the interface. - -ingress bool - +ingress bool Define whether the packet should come into the interface. @@ -395,9 +477,7 @@ Define whether the packet should come into the interface. - -mirror bool - +mirror bool Define whether the packet should be copied to the destination space. @@ -405,9 +485,7 @@ Define whether the packet should be copied to the destination space. - -redirect bool - +redirect bool Define whether the packet should be moved to the destination space. @@ -420,15 +498,11 @@ Action for 'simple': - -sdata char[32] - +sdata char[32] The actual string to print. - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/libnmc-setting/settings-docs.h b/src/libnmc-setting/settings-docs.h index 06346b1e..5ba6302d 100644 --- a/src/libnmc-setting/settings-docs.h +++ b/src/libnmc-setting/settings-docs.h @@ -253,6 +253,7 @@ #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ROUTE_METRIC N_("The default metric for routes that don't explicitly specify a metric. The default value -1 means that the metric is chosen automatically based on the device type. The metric applies to dynamic routes, manual (static) routes that don't have an explicit metric setting, address prefix routes, and the default route. Note that for IPv6, the kernel accepts zero (0) but coerces it to 1024 (user default). Hence, setting this property to zero effectively mean setting it to 1024. For IPv4, zero is a regular value for the metric.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ROUTE_TABLE N_("Enable policy routing (source routing) and set the routing table used when adding routes. This affects all routes, including device-routes, IPv4LL, DHCP, SLAAC, default-routes and static routes. But note that static routes can individually overwrite the setting by explicitly specifying a non-zero routing table. If the table setting is left at zero, it is eligible to be overwritten via global configuration. If the property is zero even after applying the global configuration value, policy routing is disabled for the address family of this connection. Policy routing disabled means that NetworkManager will add all routes to the main table (except static routes that explicitly configure a different table). Additionally, NetworkManager will not delete any extraneous routes from tables except the main table. This is to preserve backward compatibility for users who manage routing tables outside of NetworkManager.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ROUTES N_("A list of IPv4 destination addresses, prefix length, optional IPv4 next hop addresses, optional route metric, optional attribute. The valid syntax is: \"ip[/prefix] [next-hop] [metric] [attribute=val]...[,ip[/prefix]...]\". For example \"192.0.2.0/24 10.1.1.1 77, 198.51.100.0/24\".") +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ROUTING_RULES N_("A comma separated list of routing rules for policy routing.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE N_("Configure method for creating the address for use with RFC4862 IPv6 Stateless Address Autoconfiguration. The permitted values are: NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64 (0) or NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY (1). If the property is set to EUI64, the addresses will be generated using the interface tokens derived from hardware address. This makes the host part of the address to stay constant, making it possible to track host's presence when it changes networks. The address changes when the interface hardware is replaced. The value of stable-privacy enables use of cryptographically secure hash of a secret host-specific key along with the connection's stable-id and the network address as specified by RFC7217. This makes it impossible to use the address track host's presence, and makes the address stable when the network interface hardware is replaced. On D-Bus, the absence of an addr-gen-mode setting equals enabling stable-privacy. For keyfile plugin, the absence of the setting on disk means EUI64 so that the property doesn't change on upgrade from older versions. Note that this setting is distinct from the Privacy Extensions as configured by \"ip6-privacy\" property and it does not affect the temporary addresses configured with this option.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ADDRESSES N_("A list of IPv6 addresses and their prefix length. Multiple addresses can be separated by comma. For example \"2001:db8:85a3::8a2e:370:7334/64, 2001:db8:85a3::5/64\". The addresses are listed in increasing priority, meaning the last address will be the primary address.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DAD_TIMEOUT N_("Timeout in milliseconds used to check for the presence of duplicate IP addresses on the network. If an address conflict is detected, the activation will fail. A zero value means that no duplicate address detection is performed, -1 means the default value (either configuration ipvx.dad-timeout override or zero). A value greater than zero is a timeout in milliseconds. The property is currently implemented only for IPv4.") @@ -279,6 +280,7 @@ #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ROUTE_METRIC N_("The default metric for routes that don't explicitly specify a metric. The default value -1 means that the metric is chosen automatically based on the device type. The metric applies to dynamic routes, manual (static) routes that don't have an explicit metric setting, address prefix routes, and the default route. Note that for IPv6, the kernel accepts zero (0) but coerces it to 1024 (user default). Hence, setting this property to zero effectively mean setting it to 1024. For IPv4, zero is a regular value for the metric.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ROUTE_TABLE N_("Enable policy routing (source routing) and set the routing table used when adding routes. This affects all routes, including device-routes, IPv4LL, DHCP, SLAAC, default-routes and static routes. But note that static routes can individually overwrite the setting by explicitly specifying a non-zero routing table. If the table setting is left at zero, it is eligible to be overwritten via global configuration. If the property is zero even after applying the global configuration value, policy routing is disabled for the address family of this connection. Policy routing disabled means that NetworkManager will add all routes to the main table (except static routes that explicitly configure a different table). Additionally, NetworkManager will not delete any extraneous routes from tables except the main table. This is to preserve backward compatibility for users who manage routing tables outside of NetworkManager.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ROUTES N_("Array of IP routes.") +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ROUTING_RULES N_("A comma separated list of routing rules for policy routing.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_TOKEN N_("Configure the token for draft-chown-6man-tokenised-ipv6-identifiers-02 IPv6 tokenized interface identifiers. Useful with eui64 addr-gen-mode.") #define DESCRIBE_DOC_NM_SETTING_MACSEC_ENCRYPT N_("Whether the transmitted traffic must be encrypted.") #define DESCRIBE_DOC_NM_SETTING_MACSEC_MKA_CAK N_("The pre-shared CAK (Connectivity Association Key) for MACsec Key Agreement.") @@ -303,6 +305,7 @@ #define DESCRIBE_DOC_NM_SETTING_OVS_BRIDGE_RSTP_ENABLE N_("Enable or disable RSTP.") #define DESCRIBE_DOC_NM_SETTING_OVS_BRIDGE_STP_ENABLE N_("Enable or disable STP.") #define DESCRIBE_DOC_NM_SETTING_OVS_DPDK_DEVARGS N_("Open vSwitch DPDK device arguments.") +#define DESCRIBE_DOC_NM_SETTING_OVS_DPDK_N_RXQ N_("Open vSwitch DPDK number of rx queues. Defaults to zero which means to leave the parameter in OVS unspecified and effectively configures one queue.") #define DESCRIBE_DOC_NM_SETTING_OVS_EXTERNAL_IDS_DATA N_("A dictionary of key/value pairs with exernal-ids for OVS.") #define DESCRIBE_DOC_NM_SETTING_OVS_INTERFACE_TYPE N_("The interface type. Either \"internal\", \"system\", \"patch\", \"dpdk\", or empty.") #define DESCRIBE_DOC_NM_SETTING_OVS_PATCH_PEER N_("Specifies the name of the interface for the other side of the patch. The patch on the other side must also set this interface as peer.") diff --git a/src/libnmc-setting/settings-docs.h.in b/src/libnmc-setting/settings-docs.h.in index 06346b1e..5ba6302d 100644 --- a/src/libnmc-setting/settings-docs.h.in +++ b/src/libnmc-setting/settings-docs.h.in @@ -253,6 +253,7 @@ #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ROUTE_METRIC N_("The default metric for routes that don't explicitly specify a metric. The default value -1 means that the metric is chosen automatically based on the device type. The metric applies to dynamic routes, manual (static) routes that don't have an explicit metric setting, address prefix routes, and the default route. Note that for IPv6, the kernel accepts zero (0) but coerces it to 1024 (user default). Hence, setting this property to zero effectively mean setting it to 1024. For IPv4, zero is a regular value for the metric.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ROUTE_TABLE N_("Enable policy routing (source routing) and set the routing table used when adding routes. This affects all routes, including device-routes, IPv4LL, DHCP, SLAAC, default-routes and static routes. But note that static routes can individually overwrite the setting by explicitly specifying a non-zero routing table. If the table setting is left at zero, it is eligible to be overwritten via global configuration. If the property is zero even after applying the global configuration value, policy routing is disabled for the address family of this connection. Policy routing disabled means that NetworkManager will add all routes to the main table (except static routes that explicitly configure a different table). Additionally, NetworkManager will not delete any extraneous routes from tables except the main table. This is to preserve backward compatibility for users who manage routing tables outside of NetworkManager.") #define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ROUTES N_("A list of IPv4 destination addresses, prefix length, optional IPv4 next hop addresses, optional route metric, optional attribute. The valid syntax is: \"ip[/prefix] [next-hop] [metric] [attribute=val]...[,ip[/prefix]...]\". For example \"192.0.2.0/24 10.1.1.1 77, 198.51.100.0/24\".") +#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_ROUTING_RULES N_("A comma separated list of routing rules for policy routing.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE N_("Configure method for creating the address for use with RFC4862 IPv6 Stateless Address Autoconfiguration. The permitted values are: NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64 (0) or NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY (1). If the property is set to EUI64, the addresses will be generated using the interface tokens derived from hardware address. This makes the host part of the address to stay constant, making it possible to track host's presence when it changes networks. The address changes when the interface hardware is replaced. The value of stable-privacy enables use of cryptographically secure hash of a secret host-specific key along with the connection's stable-id and the network address as specified by RFC7217. This makes it impossible to use the address track host's presence, and makes the address stable when the network interface hardware is replaced. On D-Bus, the absence of an addr-gen-mode setting equals enabling stable-privacy. For keyfile plugin, the absence of the setting on disk means EUI64 so that the property doesn't change on upgrade from older versions. Note that this setting is distinct from the Privacy Extensions as configured by \"ip6-privacy\" property and it does not affect the temporary addresses configured with this option.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ADDRESSES N_("A list of IPv6 addresses and their prefix length. Multiple addresses can be separated by comma. For example \"2001:db8:85a3::8a2e:370:7334/64, 2001:db8:85a3::5/64\". The addresses are listed in increasing priority, meaning the last address will be the primary address.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DAD_TIMEOUT N_("Timeout in milliseconds used to check for the presence of duplicate IP addresses on the network. If an address conflict is detected, the activation will fail. A zero value means that no duplicate address detection is performed, -1 means the default value (either configuration ipvx.dad-timeout override or zero). A value greater than zero is a timeout in milliseconds. The property is currently implemented only for IPv4.") @@ -279,6 +280,7 @@ #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ROUTE_METRIC N_("The default metric for routes that don't explicitly specify a metric. The default value -1 means that the metric is chosen automatically based on the device type. The metric applies to dynamic routes, manual (static) routes that don't have an explicit metric setting, address prefix routes, and the default route. Note that for IPv6, the kernel accepts zero (0) but coerces it to 1024 (user default). Hence, setting this property to zero effectively mean setting it to 1024. For IPv4, zero is a regular value for the metric.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ROUTE_TABLE N_("Enable policy routing (source routing) and set the routing table used when adding routes. This affects all routes, including device-routes, IPv4LL, DHCP, SLAAC, default-routes and static routes. But note that static routes can individually overwrite the setting by explicitly specifying a non-zero routing table. If the table setting is left at zero, it is eligible to be overwritten via global configuration. If the property is zero even after applying the global configuration value, policy routing is disabled for the address family of this connection. Policy routing disabled means that NetworkManager will add all routes to the main table (except static routes that explicitly configure a different table). Additionally, NetworkManager will not delete any extraneous routes from tables except the main table. This is to preserve backward compatibility for users who manage routing tables outside of NetworkManager.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ROUTES N_("Array of IP routes.") +#define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_ROUTING_RULES N_("A comma separated list of routing rules for policy routing.") #define DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_TOKEN N_("Configure the token for draft-chown-6man-tokenised-ipv6-identifiers-02 IPv6 tokenized interface identifiers. Useful with eui64 addr-gen-mode.") #define DESCRIBE_DOC_NM_SETTING_MACSEC_ENCRYPT N_("Whether the transmitted traffic must be encrypted.") #define DESCRIBE_DOC_NM_SETTING_MACSEC_MKA_CAK N_("The pre-shared CAK (Connectivity Association Key) for MACsec Key Agreement.") @@ -303,6 +305,7 @@ #define DESCRIBE_DOC_NM_SETTING_OVS_BRIDGE_RSTP_ENABLE N_("Enable or disable RSTP.") #define DESCRIBE_DOC_NM_SETTING_OVS_BRIDGE_STP_ENABLE N_("Enable or disable STP.") #define DESCRIBE_DOC_NM_SETTING_OVS_DPDK_DEVARGS N_("Open vSwitch DPDK device arguments.") +#define DESCRIBE_DOC_NM_SETTING_OVS_DPDK_N_RXQ N_("Open vSwitch DPDK number of rx queues. Defaults to zero which means to leave the parameter in OVS unspecified and effectively configures one queue.") #define DESCRIBE_DOC_NM_SETTING_OVS_EXTERNAL_IDS_DATA N_("A dictionary of key/value pairs with exernal-ids for OVS.") #define DESCRIBE_DOC_NM_SETTING_OVS_INTERFACE_TYPE N_("The interface type. Either \"internal\", \"system\", \"patch\", \"dpdk\", or empty.") #define DESCRIBE_DOC_NM_SETTING_OVS_PATCH_PEER N_("Specifies the name of the interface for the other side of the patch. The patch on the other side must also set this interface as peer.") diff --git a/src/libnmc-setting/tests/test-libnmc-setting.c b/src/libnmc-setting/tests/test-libnmc-setting.c index fe196ad0..d34bf028 100644 --- a/src/libnmc-setting/tests/test-libnmc-setting.c +++ b/src/libnmc-setting/tests/test-libnmc-setting.c @@ -106,7 +106,7 @@ test_client_meta_check(void) g_assert((!!info->valid_parts) == is_base_type); if (info->valid_parts) { - gsize i, l; + gsize i, l; gs_unref_hashtable GHashTable *dup = g_hash_table_new(nm_direct_hash, NULL); l = NM_PTRARRAY_LEN(info->valid_parts); @@ -161,12 +161,12 @@ test_client_meta_check(void) static void test_client_import_wireguard_test0(void) { - gs_unref_object NMConnection *connection; - NMSettingWireGuard * s_wg; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMWireGuardPeer * peer; - gs_free_error GError *error = NULL; + gs_unref_object NMConnection *connection = NULL; + NMSettingWireGuard *s_wg; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMWireGuardPeer *peer; + gs_free_error GError *error = NULL; connection = nm_vpn_wireguard_import(NM_BUILD_SRCDIR "/src/libnmc-setting/tests/wg-test0.conf", &error); @@ -271,48 +271,48 @@ test_client_import_wireguard_missing(void) /*****************************************************************************/ -#define _do_test_parse_passwd_file(contents, success, exp_error_line, ...) \ - G_STMT_START \ - { \ - static const NMUtilsNamedValue _values[] = {__VA_ARGS__}; \ - gs_free char * _contents = g_strndup(contents, NM_STRLEN(contents)); \ - gs_unref_hashtable GHashTable *_secrets = NULL; \ - gs_free_error GError *_local = NULL; \ - gssize _error_line; \ - GError ** _p_local = nmtst_get_rand_bool() ? &_local : NULL; \ - gssize * _p_error_line = nmtst_get_rand_bool() ? &_error_line : NULL; \ - gboolean _success = !!(success); \ - gssize _exp_error_line = (exp_error_line); \ - int _i; \ - \ - g_assert(_success || (G_N_ELEMENTS(_values) == 0)); \ - \ - _secrets = nmc_utils_parse_passwd_file(_contents, _p_error_line, _p_local); \ - \ - g_assert(_success == (!!_secrets)); \ - if (!_success) { \ - if (_p_error_line) \ - g_assert_cmpint(_exp_error_line, ==, *_p_error_line); \ - if (_p_local) \ - g_assert(_local); \ - } else { \ - if (_p_error_line) \ - g_assert_cmpint(-1, ==, *_p_error_line); \ - g_assert(!_local); \ - \ - for (_i = 0; _i < (int) G_N_ELEMENTS(_values); _i++) { \ - const NMUtilsNamedValue *_n = &_values[_i]; \ - const char * _v; \ - \ - _v = g_hash_table_lookup(_secrets, _n->name); \ - if (!_v) \ - g_error("cannot find key \"%s\"", _n->name); \ - g_assert_cmpstr(_v, ==, _n->value_str); \ - } \ - \ - g_assert_cmpint(g_hash_table_size(_secrets), ==, G_N_ELEMENTS(_values)); \ - } \ - } \ +#define _do_test_parse_passwd_file(contents, success, exp_error_line, ...) \ + G_STMT_START \ + { \ + static const NMUtilsNamedValue _values[] = {__VA_ARGS__}; \ + gs_free char *_contents = g_strndup(contents, NM_STRLEN(contents)); \ + gs_unref_hashtable GHashTable *_secrets = NULL; \ + gs_free_error GError *_local = NULL; \ + gssize _error_line; \ + GError **_p_local = nmtst_get_rand_bool() ? &_local : NULL; \ + gssize *_p_error_line = nmtst_get_rand_bool() ? &_error_line : NULL; \ + gboolean _success = !!(success); \ + gssize _exp_error_line = (exp_error_line); \ + int _i; \ + \ + g_assert(_success || (G_N_ELEMENTS(_values) == 0)); \ + \ + _secrets = nmc_utils_parse_passwd_file(_contents, _p_error_line, _p_local); \ + \ + g_assert(_success == (!!_secrets)); \ + if (!_success) { \ + if (_p_error_line) \ + g_assert_cmpint(_exp_error_line, ==, *_p_error_line); \ + if (_p_local) \ + g_assert(_local); \ + } else { \ + if (_p_error_line) \ + g_assert_cmpint(-1, ==, *_p_error_line); \ + g_assert(!_local); \ + \ + for (_i = 0; _i < (int) G_N_ELEMENTS(_values); _i++) { \ + const NMUtilsNamedValue *_n = &_values[_i]; \ + const char *_v; \ + \ + _v = g_hash_table_lookup(_secrets, _n->name); \ + if (!_v) \ + g_error("cannot find key \"%s\"", _n->name); \ + g_assert_cmpstr(_v, ==, _n->value_str); \ + } \ + \ + g_assert_cmpint(g_hash_table_size(_secrets), ==, G_N_ELEMENTS(_values)); \ + } \ + } \ G_STMT_END #define _do_test_parse_passwd_file_bad(contents, exp_error_line) \ diff --git a/src/libnmt-newt/nmt-newt-button-box.c b/src/libnmt-newt/nmt-newt-button-box.c index d86a154c..f3c8b27e 100644 --- a/src/libnmt-newt/nmt-newt-button-box.c +++ b/src/libnmt-newt/nmt-newt-button-box.c @@ -29,7 +29,7 @@ G_DEFINE_TYPE(NmtNewtButtonBox, nmt_newt_button_box, NMT_TYPE_NEWT_CONTAINER) typedef struct { NmtNewtButtonBoxOrientation orientation; - GPtrArray * start_buttons, *end_buttons; + GPtrArray *start_buttons, *end_buttons; } NmtNewtButtonBoxPrivate; enum { @@ -193,7 +193,7 @@ static newtComponent * nmt_newt_button_box_get_components(NmtNewtWidget *widget) { NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE(widget); - GPtrArray * cos; + GPtrArray *cos; cos = g_ptr_array_new(); add_buttons(priv->start_buttons, cos); @@ -231,7 +231,7 @@ size_request_buttons(NmtNewtButtonBox *bbox, GPtrArray *buttons, int *width, int static void nmt_newt_button_box_size_request(NmtNewtWidget *widget, int *width, int *height) { - NmtNewtButtonBox * bbox = NMT_NEWT_BUTTON_BOX(widget); + NmtNewtButtonBox *bbox = NMT_NEWT_BUTTON_BOX(widget); NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE(widget); *width = *height = 0; @@ -248,7 +248,7 @@ static void nmt_newt_button_box_size_allocate(NmtNewtWidget *widget, int x, int y, int width, int height) { NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE(widget); - NmtNewtWidget * child; + NmtNewtWidget *child; int child_x, child_y, child_width, child_height; int i; @@ -295,10 +295,10 @@ nmt_newt_button_box_size_allocate(NmtNewtWidget *widget, int x, int y, int width } static void -nmt_newt_button_box_set_property(GObject * object, +nmt_newt_button_box_set_property(GObject *object, guint prop_id, const GValue *value, - GParamSpec * pspec) + GParamSpec *pspec) { NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE(object); @@ -330,8 +330,8 @@ nmt_newt_button_box_get_property(GObject *object, guint prop_id, GValue *value, static void nmt_newt_button_box_class_init(NmtNewtButtonBoxClass *bbox_class) { - GObjectClass * object_class = G_OBJECT_CLASS(bbox_class); - NmtNewtWidgetClass * widget_class = NMT_NEWT_WIDGET_CLASS(bbox_class); + GObjectClass *object_class = G_OBJECT_CLASS(bbox_class); + NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS(bbox_class); NmtNewtContainerClass *container_class = NMT_NEWT_CONTAINER_CLASS(bbox_class); g_type_class_add_private(bbox_class, sizeof(NmtNewtButtonBoxPrivate)); diff --git a/src/libnmt-newt/nmt-newt-button.c b/src/libnmt-newt/nmt-newt-button.c index 974d05bd..b21ae537 100644 --- a/src/libnmt-newt/nmt-newt-button.c +++ b/src/libnmt-newt/nmt-newt-button.c @@ -108,7 +108,7 @@ nmt_newt_button_build_component(NmtNewtComponent *component, gboolean sensitive) { NmtNewtButtonPrivate *priv = NMT_NEWT_BUTTON_GET_PRIVATE(component); newtComponent co; - gs_free char * label_lc = NULL; + gs_free char *label_lc = NULL; if (sensitive) { label_lc = nmt_newt_locale_from_utf8(priv->label); @@ -183,9 +183,9 @@ nmt_newt_button_get_property(GObject *object, guint prop_id, GValue *value, GPar static void nmt_newt_button_class_init(NmtNewtButtonClass *button_class) { - GObjectClass * object_class = G_OBJECT_CLASS(button_class); + GObjectClass *object_class = G_OBJECT_CLASS(button_class); NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS(button_class); - NmtNewtWidgetClass * widget_class = NMT_NEWT_WIDGET_CLASS(button_class); + NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS(button_class); g_type_class_add_private(button_class, sizeof(NmtNewtButtonPrivate)); diff --git a/src/libnmt-newt/nmt-newt-checkbox.c b/src/libnmt-newt/nmt-newt-checkbox.c index cf825e08..26e7ebf0 100644 --- a/src/libnmt-newt/nmt-newt-checkbox.c +++ b/src/libnmt-newt/nmt-newt-checkbox.c @@ -21,7 +21,7 @@ G_DEFINE_TYPE(NmtNewtCheckbox, nmt_newt_checkbox, NMT_TYPE_NEWT_COMPONENT) (G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_NEWT_CHECKBOX, NmtNewtCheckboxPrivate)) typedef struct { - char * label_lc; + char *label_lc; gboolean active; } NmtNewtCheckboxPrivate; @@ -139,12 +139,12 @@ nmt_newt_checkbox_build_component(NmtNewtComponent *component, gboolean sensitiv } static void -nmt_newt_checkbox_set_property(GObject * object, +nmt_newt_checkbox_set_property(GObject *object, guint prop_id, const GValue *value, - GParamSpec * pspec) + GParamSpec *pspec) { - NmtNewtCheckbox * checkbox = NMT_NEWT_CHECKBOX(object); + NmtNewtCheckbox *checkbox = NMT_NEWT_CHECKBOX(object); NmtNewtCheckboxPrivate *priv = NMT_NEWT_CHECKBOX_GET_PRIVATE(object); switch (prop_id) { @@ -182,7 +182,7 @@ nmt_newt_checkbox_get_property(GObject *object, guint prop_id, GValue *value, GP static void nmt_newt_checkbox_class_init(NmtNewtCheckboxClass *checkbox_class) { - GObjectClass * object_class = G_OBJECT_CLASS(checkbox_class); + GObjectClass *object_class = G_OBJECT_CLASS(checkbox_class); NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS(checkbox_class); g_type_class_add_private(checkbox_class, sizeof(NmtNewtCheckboxPrivate)); diff --git a/src/libnmt-newt/nmt-newt-component.c b/src/libnmt-newt/nmt-newt-component.c index 8d7a9005..d3cb12c6 100644 --- a/src/libnmt-newt/nmt-newt-component.c +++ b/src/libnmt-newt/nmt-newt-component.c @@ -89,7 +89,7 @@ static newtComponent * nmt_newt_component_get_components(NmtNewtWidget *widget) { NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE(widget); - newtComponent * cos; + newtComponent *cos; priv->own_component = FALSE; cos = g_new0(newtComponent, 2); @@ -209,10 +209,10 @@ nmt_newt_component_set_sensitive(NmtNewtComponent *component, gboolean sensitive } static void -nmt_newt_component_set_property(GObject * object, +nmt_newt_component_set_property(GObject *object, guint prop_id, const GValue *value, - GParamSpec * pspec) + GParamSpec *pspec) { NmtNewtComponent *component = NMT_NEWT_COMPONENT(object); @@ -247,7 +247,7 @@ nmt_newt_component_get_property(GObject *object, guint prop_id, GValue *value, G static void nmt_newt_component_class_init(NmtNewtComponentClass *component_class) { - GObjectClass * object_class = G_OBJECT_CLASS(component_class); + GObjectClass *object_class = G_OBJECT_CLASS(component_class); NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS(component_class); g_type_class_add_private(component_class, sizeof(NmtNewtComponentPrivate)); diff --git a/src/libnmt-newt/nmt-newt-container.c b/src/libnmt-newt/nmt-newt-container.c index 4cc8db24..65e0a644 100644 --- a/src/libnmt-newt/nmt-newt-container.c +++ b/src/libnmt-newt/nmt-newt-container.c @@ -42,7 +42,7 @@ nmt_newt_container_init(NmtNewtContainer *container) static void nmt_newt_container_finalize(GObject *object) { - NmtNewtContainer * container = NMT_NEWT_CONTAINER(object); + NmtNewtContainer *container = NMT_NEWT_CONTAINER(object); NmtNewtContainerPrivate *priv = NMT_NEWT_CONTAINER_GET_PRIVATE(object); while (priv->children->len) @@ -178,7 +178,7 @@ static NmtNewtWidget * nmt_newt_container_find_component(NmtNewtWidget *widget, newtComponent co) { NmtNewtContainerPrivate *priv = NMT_NEWT_CONTAINER_GET_PRIVATE(widget); - NmtNewtWidget * found, *child; + NmtNewtWidget *found, *child; int i; for (i = 0; i < priv->children->len; i++) { @@ -204,7 +204,7 @@ GSList * nmt_newt_container_get_children(NmtNewtContainer *container) { NmtNewtContainerPrivate *priv = NMT_NEWT_CONTAINER_GET_PRIVATE(container); - GSList * ret; + GSList *ret; int i; for (i = 0, ret = NULL; i < priv->children->len; i++) @@ -215,7 +215,7 @@ nmt_newt_container_get_children(NmtNewtContainer *container) static void nmt_newt_container_class_init(NmtNewtContainerClass *container_class) { - GObjectClass * object_class = G_OBJECT_CLASS(container_class); + GObjectClass *object_class = G_OBJECT_CLASS(container_class); NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS(container_class); g_type_class_add_private(container_class, sizeof(NmtNewtContainerPrivate)); diff --git a/src/libnmt-newt/nmt-newt-entry-numeric.c b/src/libnmt-newt/nmt-newt-entry-numeric.c index 7e8edd6c..829eac11 100644 --- a/src/libnmt-newt/nmt-newt-entry-numeric.c +++ b/src/libnmt-newt/nmt-newt-entry-numeric.c @@ -84,7 +84,7 @@ nmt_newt_entry_numeric_new_full(int width, gint64 min, gint64 max, gboolean opti static gboolean newt_entry_numeric_filter(NmtNewtEntry *entry, - const char * text, + const char *text, int ch, int position, gpointer user_data) @@ -136,10 +136,10 @@ nmt_newt_entry_numeric_constructed(GObject *object) } static void -nmt_newt_entry_numeric_set_property(GObject * object, +nmt_newt_entry_numeric_set_property(GObject *object, guint prop_id, const GValue *value, - GParamSpec * pspec) + GParamSpec *pspec) { NmtNewtEntryNumericPrivate *priv = NMT_NEWT_ENTRY_NUMERIC_GET_PRIVATE(object); @@ -160,9 +160,9 @@ nmt_newt_entry_numeric_set_property(GObject * object, } static void -nmt_newt_entry_numeric_get_property(GObject * object, +nmt_newt_entry_numeric_get_property(GObject *object, guint prop_id, - GValue * value, + GValue *value, GParamSpec *pspec) { NmtNewtEntryNumericPrivate *priv = NMT_NEWT_ENTRY_NUMERIC_GET_PRIVATE(object); diff --git a/src/libnmt-newt/nmt-newt-entry.c b/src/libnmt-newt/nmt-newt-entry.c index 76a96df2..3b0a21be 100644 --- a/src/libnmt-newt/nmt-newt-entry.c +++ b/src/libnmt-newt/nmt-newt-entry.c @@ -28,7 +28,7 @@ G_DEFINE_TYPE(NmtNewtEntry, nmt_newt_entry, NMT_TYPE_NEWT_COMPONENT) typedef struct { int width; NmtNewtEntryFlags flags; - char * text; + char *text; int last_cursor_pos; guint idle_update; @@ -150,7 +150,7 @@ nmt_newt_entry_check_valid(NmtNewtEntry *entry) * will not be considered #NmtNewtWidget:valid. */ void -nmt_newt_entry_set_validator(NmtNewtEntry * entry, +nmt_newt_entry_set_validator(NmtNewtEntry *entry, NmtNewtEntryValidator validator, gpointer user_data) { @@ -296,7 +296,7 @@ idle_update_entry(gpointer entry) { NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE(entry); newtComponent co = nmt_newt_component_get_component(entry); - char * text; + char *text; priv->idle_update = 0; if (!co) @@ -351,7 +351,7 @@ nmt_newt_entry_build_component(NmtNewtComponent *component, gboolean sensitive) { NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE(component); newtComponent co; - char * text_lc; + char *text_lc; int flags; flags = convert_flags(priv->flags); @@ -385,7 +385,7 @@ nmt_newt_entry_activated(NmtNewtWidget *widget) static void nmt_newt_entry_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - NmtNewtEntry * entry = NMT_NEWT_ENTRY(object); + NmtNewtEntry *entry = NMT_NEWT_ENTRY(object); NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE(entry); switch (prop_id) { @@ -415,7 +415,7 @@ nmt_newt_entry_set_property(GObject *object, guint prop_id, const GValue *value, static void nmt_newt_entry_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NmtNewtEntry * entry = NMT_NEWT_ENTRY(object); + NmtNewtEntry *entry = NMT_NEWT_ENTRY(object); NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE(entry); switch (prop_id) { @@ -440,8 +440,8 @@ nmt_newt_entry_get_property(GObject *object, guint prop_id, GValue *value, GPara static void nmt_newt_entry_class_init(NmtNewtEntryClass *entry_class) { - GObjectClass * object_class = G_OBJECT_CLASS(entry_class); - NmtNewtWidgetClass * widget_class = NMT_NEWT_WIDGET_CLASS(entry_class); + GObjectClass *object_class = G_OBJECT_CLASS(entry_class); + NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS(entry_class); NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS(entry_class); g_type_class_add_private(entry_class, sizeof(NmtNewtEntryPrivate)); diff --git a/src/libnmt-newt/nmt-newt-entry.h b/src/libnmt-newt/nmt-newt-entry.h index da1a9aee..81221812 100644 --- a/src/libnmt-newt/nmt-newt-entry.h +++ b/src/libnmt-newt/nmt-newt-entry.h @@ -41,7 +41,7 @@ typedef enum { NmtNewtWidget *nmt_newt_entry_new(int width, NmtNewtEntryFlags flags); void nmt_newt_entry_set_filter(NmtNewtEntry *entry, NmtNewtEntryFilter filter, gpointer user_data); -void nmt_newt_entry_set_validator(NmtNewtEntry * entry, +void nmt_newt_entry_set_validator(NmtNewtEntry *entry, NmtNewtEntryValidator validator, gpointer user_data); diff --git a/src/libnmt-newt/nmt-newt-form.c b/src/libnmt-newt/nmt-newt-form.c index 825f7cfe..7d28c80e 100644 --- a/src/libnmt-newt/nmt-newt-form.c +++ b/src/libnmt-newt/nmt-newt-form.c @@ -34,7 +34,7 @@ typedef struct { guint padding; gboolean fixed_x, fixed_y; gboolean fixed_width, fixed_height; - char * title_lc; + char *title_lc; gboolean dirty, escape_exits; NmtNewtWidget *focus; @@ -137,7 +137,7 @@ nmt_newt_form_needs_rebuild(NmtNewtWidget *widget) static void nmt_newt_form_remove(NmtNewtContainer *container, NmtNewtWidget *widget) { - NmtNewtFormPrivate * priv = NMT_NEWT_FORM_GET_PRIVATE(container); + NmtNewtFormPrivate *priv = NMT_NEWT_FORM_GET_PRIVATE(container); NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS(nmt_newt_form_parent_class); g_return_if_fail(widget == priv->content); @@ -156,7 +156,7 @@ nmt_newt_form_remove(NmtNewtContainer *container, NmtNewtWidget *widget) void nmt_newt_form_set_content(NmtNewtForm *form, NmtNewtWidget *content) { - NmtNewtFormPrivate * priv = NMT_NEWT_FORM_GET_PRIVATE(form); + NmtNewtFormPrivate *priv = NMT_NEWT_FORM_GET_PRIVATE(form); NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS(nmt_newt_form_parent_class); if (priv->content) @@ -173,7 +173,7 @@ nmt_newt_form_build(NmtNewtForm *form) { NmtNewtFormPrivate *priv = NMT_NEWT_FORM_GET_PRIVATE(form); int screen_height, screen_width, form_height, form_width; - newtComponent * cos; + newtComponent *cos; int i; priv->dirty = FALSE; @@ -260,8 +260,8 @@ nmt_newt_form_destroy(NmtNewtForm *form) static void nmt_newt_form_iterate(NmtNewtForm *form) { - NmtNewtFormPrivate * priv = NMT_NEWT_FORM_GET_PRIVATE(form); - NmtNewtWidget * focus; + NmtNewtFormPrivate *priv = NMT_NEWT_FORM_GET_PRIVATE(form); + NmtNewtWidget *focus; struct newtExitStruct es; if (priv->dirty) { @@ -301,7 +301,7 @@ nmt_newt_form_iterate(NmtNewtForm *form) * nmt_newt_form_keypress_callback() iterates the top-most form, so it can * process the keypress. */ -static GSList * form_stack; +static GSList *form_stack; static GSource *keypress_source; static gboolean @@ -552,9 +552,9 @@ nmt_newt_form_get_property(GObject *object, guint prop_id, GValue *value, GParam static void nmt_newt_form_class_init(NmtNewtFormClass *form_class) { - GObjectClass * object_class = G_OBJECT_CLASS(form_class); + GObjectClass *object_class = G_OBJECT_CLASS(form_class); NmtNewtContainerClass *container_class = NMT_NEWT_CONTAINER_CLASS(form_class); - NmtNewtWidgetClass * widget_class = NMT_NEWT_WIDGET_CLASS(form_class); + NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS(form_class); g_type_class_add_private(form_class, sizeof(NmtNewtFormPrivate)); diff --git a/src/libnmt-newt/nmt-newt-grid.c b/src/libnmt-newt/nmt-newt-grid.c index a68a496b..1078723d 100644 --- a/src/libnmt-newt/nmt-newt-grid.c +++ b/src/libnmt-newt/nmt-newt-grid.c @@ -37,16 +37,16 @@ G_DEFINE_TYPE(NmtNewtGrid, nmt_newt_grid, NMT_TYPE_NEWT_CONTAINER) (G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_NEWT_GRID, NmtNewtGridPrivate)) typedef struct { - NmtNewtWidget * widget; + NmtNewtWidget *widget; int x, y; NmtNewtGridFlags flags; int req_height, req_width; } NmtNewtGridChild; typedef struct { - GArray * children; + GArray *children; int max_x, max_y; - int * row_heights, *col_widths; + int *row_heights, *col_widths; gboolean *expand_rows, *expand_cols; int n_expand_rows, n_expand_cols; int req_height, req_width; @@ -103,9 +103,9 @@ static newtComponent * nmt_newt_grid_get_components(NmtNewtWidget *widget) { NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE(widget); - NmtNewtGridChild * children; - GPtrArray * cos; - newtComponent * child_cos; + NmtNewtGridChild *children; + GPtrArray *cos; + newtComponent *child_cos; int i, c; g_array_sort(priv->children, child_sort_func); @@ -130,9 +130,9 @@ nmt_newt_grid_get_components(NmtNewtWidget *widget) static void nmt_newt_grid_size_request(NmtNewtWidget *widget, int *width, int *height) { - NmtNewtGrid * grid = NMT_NEWT_GRID(widget); + NmtNewtGrid *grid = NMT_NEWT_GRID(widget); NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE(grid); - NmtNewtGridChild * children = (NmtNewtGridChild *) priv->children->data; + NmtNewtGridChild *children = (NmtNewtGridChild *) priv->children->data; int row, col, i; g_free(priv->row_heights); @@ -190,7 +190,7 @@ static void nmt_newt_grid_size_allocate(NmtNewtWidget *widget, int x, int y, int width, int height) { NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE(widget); - NmtNewtGridChild * children = (NmtNewtGridChild *) priv->children->data, *child; + NmtNewtGridChild *children = (NmtNewtGridChild *) priv->children->data, *child; int i, row, col; int child_x, child_y, child_width, child_height; int extra, extra_all, extra_some; @@ -268,7 +268,7 @@ static void nmt_newt_grid_find_size(NmtNewtGrid *grid) { NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE(grid); - NmtNewtGridChild * children = (NmtNewtGridChild *) priv->children->data; + NmtNewtGridChild *children = (NmtNewtGridChild *) priv->children->data; int i; priv->max_x = priv->max_y = 0; @@ -315,7 +315,7 @@ static int find_child(NmtNewtGrid *grid, NmtNewtWidget *widget) { NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE(grid); - NmtNewtGridChild * children = (NmtNewtGridChild *) priv->children->data; + NmtNewtGridChild *children = (NmtNewtGridChild *) priv->children->data; int i; for (i = 0; i < priv->children->len; i++) { @@ -329,7 +329,7 @@ find_child(NmtNewtGrid *grid, NmtNewtWidget *widget) static void nmt_newt_grid_remove(NmtNewtContainer *container, NmtNewtWidget *widget) { - NmtNewtGrid * grid = NMT_NEWT_GRID(container); + NmtNewtGrid *grid = NMT_NEWT_GRID(container); NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE(grid); int i; @@ -355,7 +355,7 @@ void nmt_newt_grid_move(NmtNewtGrid *grid, NmtNewtWidget *widget, int x, int y) { NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE(grid); - NmtNewtGridChild * children = (NmtNewtGridChild *) priv->children->data; + NmtNewtGridChild *children = (NmtNewtGridChild *) priv->children->data; int i; i = find_child(grid, widget); @@ -411,7 +411,7 @@ void nmt_newt_grid_set_flags(NmtNewtGrid *grid, NmtNewtWidget *widget, NmtNewtGridFlags flags) { NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE(grid); - NmtNewtGridChild * children = (NmtNewtGridChild *) priv->children->data; + NmtNewtGridChild *children = (NmtNewtGridChild *) priv->children->data; int i; i = find_child(grid, widget); @@ -422,8 +422,8 @@ nmt_newt_grid_set_flags(NmtNewtGrid *grid, NmtNewtWidget *widget, NmtNewtGridFla static void nmt_newt_grid_class_init(NmtNewtGridClass *grid_class) { - GObjectClass * object_class = G_OBJECT_CLASS(grid_class); - NmtNewtWidgetClass * widget_class = NMT_NEWT_WIDGET_CLASS(grid_class); + GObjectClass *object_class = G_OBJECT_CLASS(grid_class); + NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS(grid_class); NmtNewtContainerClass *container_class = NMT_NEWT_CONTAINER_CLASS(grid_class); g_type_class_add_private(grid_class, sizeof(NmtNewtGridPrivate)); diff --git a/src/libnmt-newt/nmt-newt-hacks.c b/src/libnmt-newt/nmt-newt-hacks.c index 40114a29..a4539ed5 100644 --- a/src/libnmt-newt/nmt-newt-hacks.c +++ b/src/libnmt-newt/nmt-newt-hacks.c @@ -25,10 +25,10 @@ struct newtComponent_0_52_15_struct_hack { struct componentOps *ops; newtCallback callback; - void * callbackData; + void *callbackData; newtCallback destroyCallback; - void * destroyCallbackData; + void *destroyCallbackData; void *data; }; @@ -57,7 +57,7 @@ newtComponentGetPosition(newtComponent component, int *left, int *top) #ifndef HAVE_NEWTENTRYGETCURSORPOSITION struct newtEntry_0_52_15_struct_hack { int flags; - char * buf; + char *buf; const char **resultPtr; int bufAlloced; int bufUsed; @@ -69,7 +69,7 @@ int newtEntryGetCursorPosition(newtComponent component) { struct newtComponent_0_52_15_struct_hack *co_hack = (void *) component; - struct newtEntry_0_52_15_struct_hack * entry_hack = co_hack->data; + struct newtEntry_0_52_15_struct_hack *entry_hack = co_hack->data; return entry_hack->cursorPosition; } @@ -78,7 +78,7 @@ void newtEntrySetCursorPosition(newtComponent component, int position) { struct newtComponent_0_52_15_struct_hack *co_hack = (void *) component; - struct newtEntry_0_52_15_struct_hack * entry_hack = co_hack->data; + struct newtEntry_0_52_15_struct_hack *entry_hack = co_hack->data; entry_hack->cursorPosition = position; } diff --git a/src/libnmt-newt/nmt-newt-label.c b/src/libnmt-newt/nmt-newt-label.c index 32c7809d..f823b9b2 100644 --- a/src/libnmt-newt/nmt-newt-label.c +++ b/src/libnmt-newt/nmt-newt-label.c @@ -24,7 +24,7 @@ G_DEFINE_TYPE(NmtNewtLabel, nmt_newt_label, NMT_TYPE_NEWT_COMPONENT) (G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_NEWT_LABEL, NmtNewtLabelPrivate)) typedef struct { - char * text; + char *text; NmtNewtLabelStyle style; gboolean highlight; } NmtNewtLabelPrivate; @@ -193,7 +193,7 @@ nmt_newt_label_build_component(NmtNewtComponent *component, gboolean sensitive) { NmtNewtLabelPrivate *priv = NMT_NEWT_LABEL_GET_PRIVATE(component); newtComponent co; - char * text_lc; + char *text_lc; text_lc = nmt_newt_locale_from_utf8(priv->text); co = newtLabel(-1, -1, text_lc); @@ -252,7 +252,7 @@ nmt_newt_label_get_property(GObject *object, guint prop_id, GValue *value, GPara static void nmt_newt_label_class_init(NmtNewtLabelClass *label_class) { - GObjectClass * object_class = G_OBJECT_CLASS(label_class); + GObjectClass *object_class = G_OBJECT_CLASS(label_class); NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS(label_class); g_type_class_add_private(label_class, sizeof(NmtNewtLabelPrivate)); diff --git a/src/libnmt-newt/nmt-newt-listbox.c b/src/libnmt-newt/nmt-newt-listbox.c index cfe23647..96e04c15 100644 --- a/src/libnmt-newt/nmt-newt-listbox.c +++ b/src/libnmt-newt/nmt-newt-listbox.c @@ -307,7 +307,7 @@ update_active_internal(NmtNewtListbox *listbox, int new_active) static void selection_changed_callback(newtComponent co, void *user_data) { - NmtNewtListbox * listbox = user_data; + NmtNewtListbox *listbox = user_data; NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE(listbox); int new_active; @@ -369,12 +369,12 @@ nmt_newt_listbox_activated(NmtNewtWidget *widget) } static void -nmt_newt_listbox_set_property(GObject * object, +nmt_newt_listbox_set_property(GObject *object, guint prop_id, const GValue *value, - GParamSpec * pspec) + GParamSpec *pspec) { - NmtNewtListbox * listbox = NMT_NEWT_LISTBOX(object); + NmtNewtListbox *listbox = NMT_NEWT_LISTBOX(object); NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE(object); switch (prop_id) { @@ -430,8 +430,8 @@ nmt_newt_listbox_get_property(GObject *object, guint prop_id, GValue *value, GPa static void nmt_newt_listbox_class_init(NmtNewtListboxClass *listbox_class) { - GObjectClass * object_class = G_OBJECT_CLASS(listbox_class); - NmtNewtWidgetClass * widget_class = NMT_NEWT_WIDGET_CLASS(listbox_class); + GObjectClass *object_class = G_OBJECT_CLASS(listbox_class); + NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS(listbox_class); NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS(listbox_class); g_type_class_add_private(listbox_class, sizeof(NmtNewtListboxPrivate)); diff --git a/src/libnmt-newt/nmt-newt-popup.c b/src/libnmt-newt/nmt-newt-popup.c index 1822c9d9..c62951ca 100644 --- a/src/libnmt-newt/nmt-newt-popup.c +++ b/src/libnmt-newt/nmt-newt-popup.c @@ -59,7 +59,7 @@ enum { NmtNewtWidget * nmt_newt_popup_new(NmtNewtPopupEntry *entries) { - NmtNewtWidget * widget; + NmtNewtWidget *widget; NmtNewtPopupPrivate *priv; int i; @@ -107,7 +107,7 @@ static newtComponent nmt_newt_popup_build_component(NmtNewtComponent *component, gboolean sensitive) { NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE(component); - NmtNewtPopupEntry * entries = (NmtNewtPopupEntry *) priv->entries->data; + NmtNewtPopupEntry *entries = (NmtNewtPopupEntry *) priv->entries->data; nmt_newt_button_set_label(NMT_NEWT_BUTTON(component), entries[priv->active].label); return NMT_NEWT_COMPONENT_CLASS(nmt_newt_popup_parent_class) @@ -118,9 +118,9 @@ static void nmt_newt_popup_activated(NmtNewtWidget *widget) { NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE(widget); - NmtNewtPopupEntry * entries = (NmtNewtPopupEntry *) priv->entries->data; - NmtNewtForm * form; - NmtNewtWidget * listbox, *ret; + NmtNewtPopupEntry *entries = (NmtNewtPopupEntry *) priv->entries->data; + NmtNewtForm *form; + NmtNewtWidget *listbox, *ret; int button_x, button_y; int window_x, window_y; int list_w, list_h; @@ -234,7 +234,7 @@ const char * nmt_newt_popup_get_active_id(NmtNewtPopup *popup) { NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE(popup); - NmtNewtPopupEntry * entries = (NmtNewtPopupEntry *) priv->entries->data; + NmtNewtPopupEntry *entries = (NmtNewtPopupEntry *) priv->entries->data; return entries[priv->active].id; } @@ -250,7 +250,7 @@ void nmt_newt_popup_set_active_id(NmtNewtPopup *popup, const char *active_id) { NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE(popup); - NmtNewtPopupEntry * entries = (NmtNewtPopupEntry *) priv->entries->data; + NmtNewtPopupEntry *entries = (NmtNewtPopupEntry *) priv->entries->data; int i; for (i = 0; i < priv->entries->len; i++) { @@ -300,8 +300,8 @@ nmt_newt_popup_get_property(GObject *object, guint prop_id, GValue *value, GPara static void nmt_newt_popup_class_init(NmtNewtPopupClass *popup_class) { - GObjectClass * object_class = G_OBJECT_CLASS(popup_class); - NmtNewtWidgetClass * widget_class = NMT_NEWT_WIDGET_CLASS(popup_class); + GObjectClass *object_class = G_OBJECT_CLASS(popup_class); + NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS(popup_class); NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS(popup_class); g_type_class_add_private(popup_class, sizeof(NmtNewtPopupPrivate)); diff --git a/src/libnmt-newt/nmt-newt-section.c b/src/libnmt-newt/nmt-newt-section.c index fa73ea4a..eb551273 100644 --- a/src/libnmt-newt/nmt-newt-section.c +++ b/src/libnmt-newt/nmt-newt-section.c @@ -47,7 +47,7 @@ typedef struct { NmtNewtWidget *border_open_label; NmtNewtWidget *border_closed_label; NmtNewtWidget *border_end_label; - GPtrArray * border_line_labels; + GPtrArray *border_line_labels; gboolean open; } NmtNewtSectionPrivate; @@ -124,7 +124,7 @@ nmt_newt_section_set_header(NmtNewtSection *section, NmtNewtWidget *header) { NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE(section); NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS(nmt_newt_section_parent_class); - NmtNewtContainer * container = NMT_NEWT_CONTAINER(section); + NmtNewtContainer *container = NMT_NEWT_CONTAINER(section); if (priv->header) parent_class->remove(container, priv->header); @@ -160,7 +160,7 @@ nmt_newt_section_set_body(NmtNewtSection *section, NmtNewtWidget *body) { NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE(section); NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS(nmt_newt_section_parent_class); - NmtNewtContainer * container = NMT_NEWT_CONTAINER(section); + NmtNewtContainer *container = NMT_NEWT_CONTAINER(section); if (priv->body) parent_class->remove(container, priv->body); @@ -187,7 +187,7 @@ nmt_newt_section_get_body(NmtNewtSection *section) static void nmt_newt_section_remove(NmtNewtContainer *container, NmtNewtWidget *widget) { - NmtNewtSection * section = NMT_NEWT_SECTION(container); + NmtNewtSection *section = NMT_NEWT_SECTION(container); NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE(section); NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS(nmt_newt_section_parent_class); @@ -205,8 +205,8 @@ static newtComponent * nmt_newt_section_get_components(NmtNewtWidget *widget) { NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE(widget); - newtComponent * child_cos; - GPtrArray * cos; + newtComponent *child_cos; + GPtrArray *cos; int i; g_return_val_if_fail(priv->header != NULL && priv->body != NULL, NULL); @@ -316,10 +316,10 @@ nmt_newt_section_size_allocate(NmtNewtWidget *widget, int x, int y, int width, i } static void -nmt_newt_section_set_property(GObject * object, +nmt_newt_section_set_property(GObject *object, guint prop_id, const GValue *value, - GParamSpec * pspec) + GParamSpec *pspec) { NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE(object); @@ -359,8 +359,8 @@ nmt_newt_section_get_property(GObject *object, guint prop_id, GValue *value, GPa static void nmt_newt_section_class_init(NmtNewtSectionClass *section_class) { - GObjectClass * object_class = G_OBJECT_CLASS(section_class); - NmtNewtWidgetClass * widget_class = NMT_NEWT_WIDGET_CLASS(section_class); + GObjectClass *object_class = G_OBJECT_CLASS(section_class); + NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS(section_class); NmtNewtContainerClass *container_class = NMT_NEWT_CONTAINER_CLASS(section_class); g_type_class_add_private(section_class, sizeof(NmtNewtSectionPrivate)); diff --git a/src/libnmt-newt/nmt-newt-stack.c b/src/libnmt-newt/nmt-newt-stack.c index e0fdb3b9..bb05e51b 100644 --- a/src/libnmt-newt/nmt-newt-stack.c +++ b/src/libnmt-newt/nmt-newt-stack.c @@ -87,7 +87,7 @@ nmt_newt_stack_get_components(NmtNewtWidget *widget) static void nmt_newt_stack_size_request(NmtNewtWidget *widget, int *width, int *height) { - NmtNewtStack * stack = NMT_NEWT_STACK(widget); + NmtNewtStack *stack = NMT_NEWT_STACK(widget); NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE(stack); int i, child_width, child_height; @@ -142,7 +142,7 @@ nmt_newt_stack_add(NmtNewtStack *stack, const char *id, NmtNewtWidget *widget) static void nmt_newt_stack_remove(NmtNewtContainer *container, NmtNewtWidget *widget) { - NmtNewtStack * stack = NMT_NEWT_STACK(container); + NmtNewtStack *stack = NMT_NEWT_STACK(container); NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE(stack); int i; @@ -293,8 +293,8 @@ nmt_newt_stack_get_property(GObject *object, guint prop_id, GValue *value, GPara static void nmt_newt_stack_class_init(NmtNewtStackClass *stack_class) { - GObjectClass * object_class = G_OBJECT_CLASS(stack_class); - NmtNewtWidgetClass * widget_class = NMT_NEWT_WIDGET_CLASS(stack_class); + GObjectClass *object_class = G_OBJECT_CLASS(stack_class); + NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS(stack_class); NmtNewtContainerClass *container_class = NMT_NEWT_CONTAINER_CLASS(stack_class); g_type_class_add_private(stack_class, sizeof(NmtNewtStackPrivate)); diff --git a/src/libnmt-newt/nmt-newt-textbox.c b/src/libnmt-newt/nmt-newt-textbox.c index 128e539b..24aae9f9 100644 --- a/src/libnmt-newt/nmt-newt-textbox.c +++ b/src/libnmt-newt/nmt-newt-textbox.c @@ -76,7 +76,7 @@ void nmt_newt_textbox_set_text(NmtNewtTextbox *textbox, const char *text) { NmtNewtTextboxPrivate *priv = NMT_NEWT_TEXTBOX_GET_PRIVATE(textbox); - char ** lines; + char **lines; int i, width; if (!text) @@ -151,8 +151,8 @@ nmt_newt_textbox_build_component(NmtNewtComponent *component, gboolean sensitive { NmtNewtTextboxPrivate *priv = NMT_NEWT_TEXTBOX_GET_PRIVATE(component); newtComponent co; - const char * text; - char * text_lc; + const char *text; + char *text_lc; text = priv->text; if (!*text) @@ -176,12 +176,12 @@ nmt_newt_textbox_build_component(NmtNewtComponent *component, gboolean sensitive } static void -nmt_newt_textbox_set_property(GObject * object, +nmt_newt_textbox_set_property(GObject *object, guint prop_id, const GValue *value, - GParamSpec * pspec) + GParamSpec *pspec) { - NmtNewtTextbox * textbox = NMT_NEWT_TEXTBOX(object); + NmtNewtTextbox *textbox = NMT_NEWT_TEXTBOX(object); NmtNewtTextboxPrivate *priv = NMT_NEWT_TEXTBOX_GET_PRIVATE(textbox); switch (prop_id) { @@ -224,7 +224,7 @@ nmt_newt_textbox_get_property(GObject *object, guint prop_id, GValue *value, GPa static void nmt_newt_textbox_class_init(NmtNewtTextboxClass *textbox_class) { - GObjectClass * object_class = G_OBJECT_CLASS(textbox_class); + GObjectClass *object_class = G_OBJECT_CLASS(textbox_class); NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS(textbox_class); g_type_class_add_private(textbox_class, sizeof(NmtNewtTextboxPrivate)); diff --git a/src/libnmt-newt/nmt-newt-toggle-button.c b/src/libnmt-newt/nmt-newt-toggle-button.c index c48931e5..069dff84 100644 --- a/src/libnmt-newt/nmt-newt-toggle-button.c +++ b/src/libnmt-newt/nmt-newt-toggle-button.c @@ -20,7 +20,7 @@ G_DEFINE_TYPE(NmtNewtToggleButton, nmt_newt_toggle_button, NMT_TYPE_NEWT_BUTTON) (G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_NEWT_TOGGLE_BUTTON, NmtNewtToggleButtonPrivate)) typedef struct { - char * on_label, *off_label; + char *on_label, *off_label; gboolean active; } NmtNewtToggleButtonPrivate; @@ -115,10 +115,10 @@ nmt_newt_toggle_button_activated(NmtNewtWidget *widget) } static void -nmt_newt_toggle_button_set_property(GObject * object, +nmt_newt_toggle_button_set_property(GObject *object, guint prop_id, const GValue *value, - GParamSpec * pspec) + GParamSpec *pspec) { NmtNewtToggleButtonPrivate *priv = NMT_NEWT_TOGGLE_BUTTON_GET_PRIVATE(object); @@ -146,9 +146,9 @@ nmt_newt_toggle_button_set_property(GObject * object, } static void -nmt_newt_toggle_button_get_property(GObject * object, +nmt_newt_toggle_button_get_property(GObject *object, guint prop_id, - GValue * value, + GValue *value, GParamSpec *pspec) { NmtNewtToggleButtonPrivate *priv = NMT_NEWT_TOGGLE_BUTTON_GET_PRIVATE(object); @@ -172,7 +172,7 @@ nmt_newt_toggle_button_get_property(GObject * object, static void nmt_newt_toggle_button_class_init(NmtNewtToggleButtonClass *button_class) { - GObjectClass * object_class = G_OBJECT_CLASS(button_class); + GObjectClass *object_class = G_OBJECT_CLASS(button_class); NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS(button_class); g_type_class_add_private(button_class, sizeof(NmtNewtToggleButtonPrivate)); diff --git a/src/libnmt-newt/nmt-newt-utils.c b/src/libnmt-newt/nmt-newt-utils.c index 99bde747..14825fab 100644 --- a/src/libnmt-newt/nmt-newt-utils.c +++ b/src/libnmt-newt/nmt-newt-utils.c @@ -19,13 +19,13 @@ #include "libnm-glib-aux/nm-io-utils.h" static void -nmt_newt_dialog_g_log_handler(const char * log_domain, +nmt_newt_dialog_g_log_handler(const char *log_domain, GLogLevelFlags log_level, - const char * message, + const char *message, gpointer user_data) { - const char * level_name; - char * full_message; + const char *level_name; + char *full_message; int screen_width, screen_height; newtComponent text, ok, form; newtGrid grid; @@ -85,9 +85,9 @@ nmt_newt_dialog_g_log_handler(const char * log_domain, } static void -nmt_newt_basic_g_log_handler(const char * log_domain, +nmt_newt_basic_g_log_handler(const char *log_domain, GLogLevelFlags log_level, - const char * message, + const char *message, gpointer user_data) { newtSuspend(); @@ -133,7 +133,7 @@ nmt_newt_parse_colors(const char *s, bool is_newt) const char *name; const char *fg; const char *bg; - char * parsed_s; + char *parsed_s; parsed_s = (char *) lines[i]; name = parsed_s; @@ -178,7 +178,7 @@ nmt_newt_parse_colors(const char *s, bool is_newt) static void nmt_newt_init_colors(gboolean is_newt) { - const char * colors; + const char *colors; gs_free char *file_content = NULL; colors = getenv(is_newt ? "NEWT_COLORS" : "NMT_NEWT_COLORS"); @@ -257,7 +257,7 @@ void nmt_newt_message_dialog(const char *message, ...) { va_list ap; - char * msg, *msg_lc, *ok_lc; + char *msg, *msg_lc, *ok_lc; va_start(ap, message); msg = g_strdup_vprintf(message, ap); @@ -288,7 +288,7 @@ int nmt_newt_choice_dialog(const char *button1, const char *button2, const char *message, ...) { va_list ap; - char * msg, *msg_lc, *button1_lc, *button2_lc; + char *msg, *msg_lc, *button1_lc, *button2_lc; int choice; va_start(ap, message); @@ -402,10 +402,10 @@ char * nmt_newt_edit_string(const char *data) { gssize len, nwrote; - char * filename, *argv[3]; + char *filename, *argv[3]; GError *error = NULL; int fd, status; - char * new_data = NULL; + char *new_data = NULL; fd = g_file_open_tmp("XXXXXX.json", &filename, &error); if (fd == -1) { diff --git a/src/nm-cloud-setup/main.c b/src/nm-cloud-setup/main.c index 916f41da..f6acadca 100644 --- a/src/nm-cloud-setup/main.c +++ b/src/nm-cloud-setup/main.c @@ -16,7 +16,7 @@ /*****************************************************************************/ typedef struct { - GMainLoop * main_loop; + GMainLoop *main_loop; GCancellable *cancellable; NMCSProvider *provider_result; guint detect_count; @@ -26,9 +26,9 @@ static void _provider_detect_cb(GObject *source, GAsyncResult *result, gpointer user_data) { gs_unref_object NMCSProvider *provider = NMCS_PROVIDER(source); - gs_free_error GError *error = NULL; - ProviderDetectData * dd; - gboolean success; + gs_free_error GError *error = NULL; + ProviderDetectData *dd; + gboolean success; success = nmcs_provider_detect_finish(provider, result, &error); @@ -75,14 +75,14 @@ _provider_detect_sigterm_cb(GCancellable *source, gpointer user_data) static NMCSProvider * _provider_detect(GCancellable *sigterm_cancellable) { - nm_auto_unref_gmainloop GMainLoop *main_loop = g_main_loop_new(NULL, FALSE); - gs_unref_object GCancellable *cancellable = g_cancellable_new(); - gs_unref_object NMHttpClient *http_client = NULL; - ProviderDetectData dd = { - .cancellable = cancellable, - .main_loop = main_loop, - .detect_count = 0, - .provider_result = NULL, + nm_auto_unref_gmainloop GMainLoop *main_loop = g_main_loop_new(NULL, FALSE); + gs_unref_object GCancellable *cancellable = g_cancellable_new(); + gs_unref_object NMHttpClient *http_client = NULL; + ProviderDetectData dd = { + .cancellable = cancellable, + .main_loop = main_loop, + .detect_count = 0, + .provider_result = NULL, }; const GType gtypes[] = { NMCS_TYPE_PROVIDER_EC2, @@ -127,17 +127,17 @@ static char ** _nmc_get_hwaddrs(NMClient *nmc) { gs_unref_ptrarray GPtrArray *hwaddrs = NULL; - const GPtrArray * devices; - char ** hwaddrs_v; - gs_free char * str = NULL; + const GPtrArray *devices; + char **hwaddrs_v; + gs_free char *str = NULL; guint i; devices = nm_client_get_devices(nmc); for (i = 0; i < devices->len; i++) { - NMDevice * device = devices->pdata[i]; + NMDevice *device = devices->pdata[i]; const char *hwaddr; - char * s; + char *s; if (!NM_IS_DEVICE_ETHERNET(device)) continue; @@ -180,8 +180,8 @@ _nmc_get_device_by_hwaddr(NMClient *nmc, const char *hwaddr) devices = nm_client_get_devices(nmc); for (i = 0; i < devices->len; i++) { - NMDevice * device = devices->pdata[i]; - const char * hwaddr_dev; + NMDevice *device = devices->pdata[i]; + const char *hwaddr_dev; gs_free char *s = NULL; if (!NM_IS_DEVICE_ETHERNET(device)) @@ -202,16 +202,16 @@ _nmc_get_device_by_hwaddr(NMClient *nmc, const char *hwaddr) /*****************************************************************************/ typedef struct { - GMainLoop * main_loop; + GMainLoop *main_loop; NMCSProviderGetConfigResult *result; } GetConfigData; static void _get_config_cb(GObject *source, GAsyncResult *res, gpointer user_data) { - GetConfigData * data = user_data; + GetConfigData *data = user_data; nm_auto_free_nmcs_provider_get_config_result NMCSProviderGetConfigResult *result = NULL; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; result = nmcs_provider_get_config_finish(NMCS_PROVIDER(source), res, &error); @@ -230,7 +230,7 @@ _get_config(GCancellable *sigterm_cancellable, NMCSProvider *provider, NMClient { nm_auto_unref_gmainloop GMainLoop *main_loop = g_main_loop_new(NULL, FALSE); GetConfigData data = { - .main_loop = main_loop, + .main_loop = main_loop, }; gs_strfreev char **hwaddrs = NULL; @@ -254,7 +254,7 @@ static gboolean _nmc_skip_connection(NMConnection *connection) { NMSettingUser *s_user; - const char * v; + const char *v; s_user = NM_SETTING_USER(nm_connection_get_setting(connection, NM_TYPE_SETTING_USER)); if (!s_user) @@ -269,24 +269,24 @@ _nmc_skip_connection(NMConnection *connection) } static gboolean -_nmc_mangle_connection(NMDevice * device, - NMConnection * connection, - const NMCSProviderGetConfigResult * result, +_nmc_mangle_connection(NMDevice *device, + NMConnection *connection, + const NMCSProviderGetConfigResult *result, const NMCSProviderGetConfigIfaceData *config_data, - gboolean * out_skipped_single_addr, - gboolean * out_changed) + gboolean *out_skipped_single_addr, + gboolean *out_changed) { - NMSettingIPConfig * s_ip; - NMActiveConnection *ac; - NMConnection * remote_connection; - NMSettingIPConfig * remote_s_ip = NULL; - gsize i; - gboolean addrs_changed = FALSE; - gboolean rules_changed = FALSE; - gboolean routes_changed = FALSE; - gs_unref_ptrarray GPtrArray *addrs_new = NULL; - gs_unref_ptrarray GPtrArray *rules_new = NULL; - gs_unref_ptrarray GPtrArray *routes_new = NULL; + NMSettingIPConfig *s_ip; + NMActiveConnection *ac; + NMConnection *remote_connection; + NMSettingIPConfig *remote_s_ip = NULL; + gsize i; + gboolean addrs_changed = FALSE; + gboolean rules_changed = FALSE; + gboolean routes_changed = FALSE; + gs_unref_ptrarray GPtrArray *addrs_new = NULL; + gs_unref_ptrarray GPtrArray *rules_new = NULL; + gs_unref_ptrarray GPtrArray *routes_new = NULL; NM_SET_OUT(out_skipped_single_addr, FALSE); NM_SET_OUT(out_changed, FALSE); @@ -339,8 +339,8 @@ _nmc_mangle_connection(NMDevice * device, } else if (config_data->has_ipv4s && config_data->has_cidr) { gs_unref_hashtable GHashTable *unique_subnets = g_hash_table_new(nm_direct_hash, g_direct_equal); - NMIPAddress * addr_entry; - NMIPRoute * route_entry; + NMIPAddress *addr_entry; + NMIPRoute *route_entry; NMIPRoutingRule *rule_entry; in_addr_t gateway; char sbuf[NM_UTILS_INET_ADDRSTRLEN]; @@ -435,22 +435,22 @@ _nmc_mangle_connection(NMDevice * device, /*****************************************************************************/ static gboolean -_config_one(GCancellable * sigterm_cancellable, - NMClient * nmc, +_config_one(GCancellable *sigterm_cancellable, + NMClient *nmc, const NMCSProviderGetConfigResult *result, guint idx) { - const NMCSProviderGetConfigIfaceData *config_data = result->iface_datas_arr[idx]; - const char * hwaddr = config_data->hwaddr; - gs_unref_object NMDevice *device = NULL; - gs_unref_object NMConnection *applied_connection = NULL; - guint64 applied_version_id; - gs_free_error GError *error = NULL; - gboolean changed; - gboolean skipped_single_addr; - gboolean version_id_changed; - guint try_count; - gboolean any_changes = FALSE; + const NMCSProviderGetConfigIfaceData *config_data = result->iface_datas_arr[idx]; + const char *hwaddr = config_data->hwaddr; + gs_unref_object NMDevice *device = NULL; + gs_unref_object NMConnection *applied_connection = NULL; + guint64 applied_version_id; + gs_free_error GError *error = NULL; + gboolean changed; + gboolean skipped_single_addr; + gboolean version_id_changed; + guint try_count; + gboolean any_changes = FALSE; g_main_context_iteration(NULL, FALSE); @@ -572,8 +572,8 @@ try_again: } static gboolean -_config_all(GCancellable * sigterm_cancellable, - NMClient * nmc, +_config_all(GCancellable *sigterm_cancellable, + NMClient *nmc, const NMCSProviderGetConfigResult *result) { gboolean any_changes = FALSE; @@ -607,12 +607,12 @@ sigterm_handler(gpointer user_data) int main(int argc, const char *const *argv) { - gs_unref_object GCancellable * sigterm_cancellable = NULL; + gs_unref_object GCancellable *sigterm_cancellable = NULL; nm_auto_destroy_and_unref_gsource GSource *sigterm_source = NULL; - gs_unref_object NMCSProvider *provider = NULL; - gs_unref_object NMClient * nmc = NULL; + gs_unref_object NMCSProvider *provider = NULL; + gs_unref_object NMClient *nmc = NULL; nm_auto_free_nmcs_provider_get_config_result NMCSProviderGetConfigResult *result = NULL; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; _nm_logging_enabled_init(g_getenv(NMCS_ENV_VARIABLE("NM_CLOUD_SETUP_LOG"))); diff --git a/src/nm-cloud-setup/nm-cloud-setup-utils.c b/src/nm-cloud-setup/nm-cloud-setup-utils.c index 206461e4..bf705549 100644 --- a/src/nm-cloud-setup/nm-cloud-setup-utils.c +++ b/src/nm-cloud-setup/nm-cloud-setup-utils.c @@ -113,7 +113,7 @@ _wait_for_objects_iterate_until_done_idle_cb(gpointer user_data) gboolean nmcs_wait_for_objects_iterate_until_done(GMainContext *context, int timeout_msec) { - nm_auto_unref_gmainloop GMainLoop *loop = g_main_loop_new(context, FALSE); + nm_auto_unref_gmainloop GMainLoop *loop = g_main_loop_new(context, FALSE); nm_auto_destroy_and_unref_gsource GSource *timeout_source = NULL; WaitForObjectsData data; gboolean has_more_objects; @@ -167,11 +167,11 @@ nmcs_wait_for_objects_iterate_until_done(GMainContext *context, int timeout_msec /*****************************************************************************/ typedef struct { - GTask * task; - GSource * source_timeout; - GSource * source_next_poll; - GMainContext * context; - GCancellable * internal_cancellable; + GTask *task; + GSource *source_timeout; + GSource *source_next_poll; + GMainContext *context; + GCancellable *internal_cancellable; NMCSUtilsPollProbeStartFcn probe_start_fcn; NMCSUtilsPollProbeFinishFcn probe_finish_fcn; gpointer probe_user_data; @@ -220,7 +220,7 @@ static gboolean _poll_start_cb(gpointer user_data); static void _poll_done_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - PollTaskData * poll_task_data = user_data; + PollTaskData *poll_task_data = user_data; _nm_unused gs_unref_object GTask *task = poll_task_data->task; /* balance ref from _poll_start_cb() */ gs_free_error GError *error = NULL; @@ -291,7 +291,7 @@ static void _poll_cancelled_cb(GObject *object, gpointer user_data) { PollTaskData *poll_task_data = user_data; - GError * error = NULL; + GError *error = NULL; nm_clear_g_signal_handler(g_task_get_cancellable(poll_task_data->task), &poll_task_data->cancellable_id); @@ -330,7 +330,7 @@ nmcs_utils_poll(int poll_timeout_ms, NMCSUtilsPollProbeStartFcn probe_start_fcn, NMCSUtilsPollProbeFinishFcn probe_finish_fcn, gpointer probe_user_data, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -400,7 +400,7 @@ nmcs_utils_poll(int poll_timeout_ms, gboolean nmcs_utils_poll_finish(GAsyncResult *result, gpointer *probe_user_data, GError **error) { - GTask * task; + GTask *task; PollTaskData *poll_task_data; g_return_val_if_fail(nm_g_task_is_valid(result, NULL, nmcs_utils_poll), FALSE); @@ -422,7 +422,7 @@ char * nmcs_utils_hwaddr_normalize(const char *hwaddr, gssize len) { gs_free char *hwaddr_clone = NULL; - char * hw; + char *hw; guint8 buf[ETH_ALEN]; gsize l; @@ -474,11 +474,11 @@ gboolean nmcs_utils_ipaddr_normalize_bin(int addr_family, const char *addr, gssize len, - int * out_addr_family, + int *out_addr_family, gpointer out_addr_bin) { gs_free char *addr_clone = NULL; - char * ad; + char *ad; gsize l; nm_assert(len >= -1); @@ -620,7 +620,7 @@ nmcs_utils_uri_complete_interned(const char *uri) gboolean nmcs_setting_ip_replace_ipv4_addresses(NMSettingIPConfig *s_ip, - NMIPAddress ** entries_arr, + NMIPAddress **entries_arr, guint entries_len) { gboolean any_changes = FALSE; @@ -667,7 +667,7 @@ nmcs_setting_ip_replace_ipv4_addresses(NMSettingIPConfig *s_ip, gboolean nmcs_setting_ip_replace_ipv4_routes(NMSettingIPConfig *s_ip, - NMIPRoute ** entries_arr, + NMIPRoute **entries_arr, guint entries_len) { gboolean any_changes = FALSE; @@ -713,7 +713,7 @@ nmcs_setting_ip_replace_ipv4_routes(NMSettingIPConfig *s_ip, gboolean nmcs_setting_ip_replace_ipv4_rules(NMSettingIPConfig *s_ip, - NMIPRoutingRule ** entries_arr, + NMIPRoutingRule **entries_arr, guint entries_len) { gboolean any_changes = FALSE; @@ -758,9 +758,9 @@ nmcs_setting_ip_replace_ipv4_rules(NMSettingIPConfig *s_ip, /*****************************************************************************/ typedef struct { - GMainLoop * main_loop; + GMainLoop *main_loop; NMConnection *connection; - GError * error; + GError *error; guint64 version_id; } DeviceGetAppliedConnectionData; @@ -777,14 +777,14 @@ _nmcs_device_get_applied_connection_cb(GObject *source, GAsyncResult *result, gp } NMConnection * -nmcs_device_get_applied_connection(NMDevice * device, +nmcs_device_get_applied_connection(NMDevice *device, GCancellable *cancellable, - guint64 * version_id, - GError ** error) + guint64 *version_id, + GError **error) { nm_auto_unref_gmainloop GMainLoop *main_loop = g_main_loop_new(NULL, FALSE); DeviceGetAppliedConnectionData data = { - .main_loop = main_loop, + .main_loop = main_loop, }; nm_device_get_applied_connection_async(device, @@ -805,7 +805,7 @@ nmcs_device_get_applied_connection(NMDevice * device, typedef struct { GMainLoop *main_loop; - GError * error; + GError *error; } DeviceReapplyData; static void @@ -818,16 +818,16 @@ _nmcs_device_reapply_cb(GObject *source, GAsyncResult *result, gpointer user_dat } gboolean -nmcs_device_reapply(NMDevice * device, +nmcs_device_reapply(NMDevice *device, GCancellable *sigterm_cancellable, NMConnection *connection, guint64 version_id, - gboolean * out_version_id_changed, - GError ** error) + gboolean *out_version_id_changed, + GError **error) { nm_auto_unref_gmainloop GMainLoop *main_loop = g_main_loop_new(NULL, FALSE); DeviceReapplyData data = { - .main_loop = main_loop, + .main_loop = main_loop, }; nm_device_reapply_async(device, diff --git a/src/nm-cloud-setup/nm-cloud-setup-utils.h b/src/nm-cloud-setup/nm-cloud-setup-utils.h index e1502b95..4131abfe 100644 --- a/src/nm-cloud-setup/nm-cloud-setup-utils.h +++ b/src/nm-cloud-setup/nm-cloud-setup-utils.h @@ -40,15 +40,15 @@ gboolean nmcs_wait_for_objects_iterate_until_done(GMainContext *context, int tim /*****************************************************************************/ -typedef void (*NMCSUtilsPollProbeStartFcn)(GCancellable * cancellable, +typedef void (*NMCSUtilsPollProbeStartFcn)(GCancellable *cancellable, gpointer probe_user_data, GAsyncReadyCallback callback, gpointer user_data); -typedef gboolean (*NMCSUtilsPollProbeFinishFcn)(GObject * source, +typedef gboolean (*NMCSUtilsPollProbeFinishFcn)(GObject *source, GAsyncResult *result, gpointer probe_user_data, - GError ** error); + GError **error); void nmcs_utils_poll(int poll_timeout_ms, int ratelimit_timeout_ms, @@ -56,7 +56,7 @@ void nmcs_utils_poll(int poll_timeout_ms, NMCSUtilsPollProbeStartFcn probe_start_fcn, NMCSUtilsPollProbeFinishFcn probe_finish_fcn, gpointer probe_user_data, - GCancellable * cancellable, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); @@ -81,7 +81,7 @@ nmcs_utils_hwaddr_normalize_gbytes(GBytes *hwaddr) gboolean nmcs_utils_ipaddr_normalize_bin(int addr_family, const char *addr, gssize len, - int * out_addr_family, + int *out_addr_family, gpointer out_addr_bin); char *nmcs_utils_ipaddr_normalize(int addr_family, const char *addr, gssize len); @@ -114,29 +114,29 @@ const char *nmcs_utils_uri_complete_interned(const char *uri); /*****************************************************************************/ gboolean nmcs_setting_ip_replace_ipv4_addresses(NMSettingIPConfig *s_ip, - NMIPAddress ** entries_arr, + NMIPAddress **entries_arr, guint entries_len); gboolean nmcs_setting_ip_replace_ipv4_routes(NMSettingIPConfig *s_ip, - NMIPRoute ** entries_arr, + NMIPRoute **entries_arr, guint entries_len); gboolean nmcs_setting_ip_replace_ipv4_rules(NMSettingIPConfig *s_ip, - NMIPRoutingRule ** entries_arr, + NMIPRoutingRule **entries_arr, guint entries_len); /*****************************************************************************/ -NMConnection *nmcs_device_get_applied_connection(NMDevice * device, +NMConnection *nmcs_device_get_applied_connection(NMDevice *device, GCancellable *cancellable, - guint64 * version_id, - GError ** error); + guint64 *version_id, + GError **error); -gboolean nmcs_device_reapply(NMDevice * device, +gboolean nmcs_device_reapply(NMDevice *device, GCancellable *sigterm_cancellable, NMConnection *connection, guint64 version_id, - gboolean * out_version_id_changed, - GError ** error); + gboolean *out_version_id_changed, + GError **error); #endif /* __NM_CLOUD_SETUP_UTILS_H__ */ diff --git a/src/nm-cloud-setup/nm-http-client.c b/src/nm-cloud-setup/nm-http-client.c index 618ab1be..2f71cefa 100644 --- a/src/nm-cloud-setup/nm-http-client.c +++ b/src/nm-cloud-setup/nm-http-client.c @@ -15,9 +15,9 @@ typedef struct { GMainContext *context; - CURLM * mhandle; - GSource * mhandle_source_timeout; - GHashTable * source_sockets_hashtable; + CURLM *mhandle; + GSource *mhandle_source_timeout; + GHashTable *source_sockets_hashtable; } NMHttpClientPrivate; struct _NMHttpClient { @@ -113,11 +113,11 @@ _get_result_free(gpointer data) } typedef struct { - GTask * task; - GSource * timeout_source; + GTask *task; + GSource *timeout_source; CURLcode ehandle_result; - CURL * ehandle; - char * url; + CURL *ehandle; + char *url; NMStrBuf recv_data; struct curl_slist *headers; gssize max_data; @@ -128,7 +128,7 @@ static void _ehandle_free_ehandle(EHandleData *edata) { if (edata->ehandle) { - NMHttpClient * self = g_task_get_source_object(edata->task); + NMHttpClient *self = g_task_get_source_object(edata->task); NMHttpClientPrivate *priv = NM_HTTP_CLIENT_GET_PRIVATE(self); curl_multi_remove_handle(priv->mhandle, edata->ehandle); @@ -154,7 +154,7 @@ _ehandle_free(EHandleData *edata) static void _ehandle_complete(EHandleData *edata, GError *error_take) { - GetResult * get_result; + GetResult *get_result; gs_free char *str_tmp_1 = NULL; long response_code = -1; @@ -249,7 +249,7 @@ static void _get_cancelled_cb(GObject *object, gpointer user_data) { EHandleData *edata = user_data; - GError * error = NULL; + GError *error = NULL; nm_clear_g_signal_handler(g_task_get_cancellable(edata->task), &edata->cancellable_id); nm_utils_error_set_cancelled(&error, FALSE, NULL); @@ -257,17 +257,17 @@ _get_cancelled_cb(GObject *object, gpointer user_data) } void -nm_http_client_get(NMHttpClient * self, - const char * url, +nm_http_client_get(NMHttpClient *self, + const char *url, int timeout_msec, gssize max_data, - const char *const * http_headers, - GCancellable * cancellable, + const char *const *http_headers, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { NMHttpClientPrivate *priv; - EHandleData * edata; + EHandleData *edata; guint i; g_return_if_fail(NM_IS_HTTP_CLIENT(self)); @@ -363,9 +363,9 @@ nm_http_client_get(NMHttpClient * self, gboolean nm_http_client_get_finish(NMHttpClient *self, GAsyncResult *result, - long * out_response_code, - GBytes ** out_response_data, - GError ** error) + long *out_response_code, + GBytes **out_response_data, + GError **error) { GetResult *get_result; @@ -394,12 +394,12 @@ nm_http_client_get_finish(NMHttpClient *self, /*****************************************************************************/ typedef struct { - GTask * task; - char * uri; - const char *const * http_headers; + GTask *task; + char *uri; + const char *const *http_headers; NMHttpClientPollGetCheckFcn check_fcn; gpointer check_user_data; - GBytes * response_data; + GBytes *response_data; gsize request_max_data; long response_code; int request_timeout_ms; @@ -419,7 +419,7 @@ _poll_get_data_free(gpointer data) } static void -_poll_get_probe_start_fcn(GCancellable * cancellable, +_poll_get_probe_start_fcn(GCancellable *cancellable, gpointer probe_user_data, GAsyncReadyCallback callback, gpointer user_data) @@ -440,16 +440,16 @@ _poll_get_probe_start_fcn(GCancellable * cancellable, } static gboolean -_poll_get_probe_finish_fcn(GObject * source, +_poll_get_probe_finish_fcn(GObject *source, GAsyncResult *result, gpointer probe_user_data, - GError ** error) + GError **error) { - PollGetData * poll_get_data = probe_user_data; + PollGetData *poll_get_data = probe_user_data; _nm_unused gs_unref_object GTask *task = poll_get_data->task; /* balance ref from _poll_get_probe_start_fcn() */ - gboolean success; - gs_free_error GError *local_error = NULL; + gboolean success; + gs_free_error GError *local_error = NULL; gs_unref_bytes GBytes *response_data = NULL; long response_code = -1; @@ -496,8 +496,8 @@ _poll_get_probe_finish_fcn(GObject * source, static void _poll_get_done_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - PollGetData * poll_get_data = user_data; - gs_free_error GError *error = NULL; + PollGetData *poll_get_data = user_data; + gs_free_error GError *error = NULL; gboolean success; success = nmcs_utils_poll_finish(result, NULL, &error); @@ -513,21 +513,21 @@ _poll_get_done_cb(GObject *source, GAsyncResult *result, gpointer user_data) } void -nm_http_client_poll_get(NMHttpClient * self, - const char * uri, +nm_http_client_poll_get(NMHttpClient *self, + const char *uri, int request_timeout_ms, gssize request_max_data, int poll_timeout_ms, int ratelimit_timeout_ms, - const char *const * http_headers, - GCancellable * cancellable, + const char *const *http_headers, + GCancellable *cancellable, NMHttpClientPollGetCheckFcn check_fcn, gpointer check_user_data, GAsyncReadyCallback callback, gpointer user_data) { nm_auto_pop_gmaincontext GMainContext *context = NULL; - PollGetData * poll_get_data; + PollGetData *poll_get_data; g_return_if_fail(NM_IS_HTTP_CLIENT(self)); g_return_if_fail(uri && uri[0]); @@ -570,13 +570,13 @@ nm_http_client_poll_get(NMHttpClient * self, gboolean nm_http_client_poll_get_finish(NMHttpClient *self, GAsyncResult *result, - long * out_response_code, - GBytes ** out_response_data, - GError ** error) + long *out_response_code, + GBytes **out_response_data, + GError **error) { - PollGetData * poll_get_data; - GTask * task; - gboolean success; + PollGetData *poll_get_data; + GTask *task; + gboolean success; gs_free_error GError *local_error = NULL; g_return_val_if_fail(NM_HTTP_CLIENT(self), FALSE); @@ -608,8 +608,8 @@ static void _mhandle_action(NMHttpClient *self, int sockfd, int ev_bitmask) { NMHttpClientPrivate *priv = NM_HTTP_CLIENT_GET_PRIVATE(self); - EHandleData * edata; - CURLMsg * msg; + EHandleData *edata; + CURLMsg *msg; CURLcode eret; int m_left; CURLMcode ret; @@ -652,14 +652,14 @@ _mhandle_socket_cb(int fd, GIOCondition condition, gpointer user_data) } static int -_mhandle_socketfunction_cb(CURL * e_handle, +_mhandle_socketfunction_cb(CURL *e_handle, curl_socket_t fd, int what, - void * user_data, - void * socketp) + void *user_data, + void *socketp) { - GSource * source_socket; - NMHttpClient * self = user_data; + GSource *source_socket; + NMHttpClient *self = user_data; NMHttpClientPrivate *priv = NM_HTTP_CLIENT_GET_PRIVATE(self); (void) _NM_ENSURE_TYPE(int, fd); @@ -704,7 +704,7 @@ _mhandle_timeout_cb(gpointer user_data) static int _mhandle_timerfunction_cb(CURLM *multi, long timeout_msec, void *user_data) { - NMHttpClient * self = user_data; + NMHttpClient *self = user_data; NMHttpClientPrivate *priv = NM_HTTP_CLIENT_GET_PRIVATE(self); nm_clear_pointer(&priv->mhandle_source_timeout, nm_g_source_destroy_and_unref); @@ -737,7 +737,7 @@ nm_http_client_init(NMHttpClient *self) static void constructed(GObject *object) { - NMHttpClient * self = NM_HTTP_CLIENT(object); + NMHttpClient *self = NM_HTTP_CLIENT(object); NMHttpClientPrivate *priv = NM_HTTP_CLIENT_GET_PRIVATE(self); priv->context = g_main_context_ref_thread_default(); @@ -764,7 +764,7 @@ nm_http_client_new(void) static void dispose(GObject *object) { - NMHttpClient * self = NM_HTTP_CLIENT(object); + NMHttpClient *self = NM_HTTP_CLIENT(object); NMHttpClientPrivate *priv = NM_HTTP_CLIENT_GET_PRIVATE(self); nm_clear_pointer(&priv->mhandle, curl_multi_cleanup); @@ -778,7 +778,7 @@ dispose(GObject *object) static void finalize(GObject *object) { - NMHttpClient * self = NM_HTTP_CLIENT(object); + NMHttpClient *self = NM_HTTP_CLIENT(object); NMHttpClientPrivate *priv = NM_HTTP_CLIENT_GET_PRIVATE(self); G_OBJECT_CLASS(nm_http_client_parent_class)->finalize(object); diff --git a/src/nm-cloud-setup/nm-http-client.h b/src/nm-cloud-setup/nm-http-client.h index 862b7338..0a7052ae 100644 --- a/src/nm-cloud-setup/nm-http-client.h +++ b/src/nm-cloud-setup/nm-http-client.h @@ -27,34 +27,34 @@ GMainContext *nm_http_client_get_main_context(NMHttpClient *self); /*****************************************************************************/ -void nm_http_client_get(NMHttpClient * self, - const char * uri, +void nm_http_client_get(NMHttpClient *self, + const char *uri, int timeout_msec, gssize max_data, - const char *const * http_headers, - GCancellable * cancellable, + const char *const *http_headers, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean nm_http_client_get_finish(NMHttpClient *self, GAsyncResult *result, - long * out_response_code, - GBytes ** out_response_data, - GError ** error); + long *out_response_code, + GBytes **out_response_data, + GError **error); typedef gboolean (*NMHttpClientPollGetCheckFcn)(long response_code, - GBytes * response_data, + GBytes *response_data, gpointer check_user_data, GError **error); -void nm_http_client_poll_get(NMHttpClient * self, - const char * uri, +void nm_http_client_poll_get(NMHttpClient *self, + const char *uri, int request_timeout_ms, gssize request_max_data, int poll_timeout_ms, int ratelimit_timeout_ms, - const char *const * http_headers, - GCancellable * cancellable, + const char *const *http_headers, + GCancellable *cancellable, NMHttpClientPollGetCheckFcn check_fcn, gpointer check_user_data, GAsyncReadyCallback callback, @@ -62,9 +62,9 @@ void nm_http_client_poll_get(NMHttpClient * self, gboolean nm_http_client_poll_get_finish(NMHttpClient *self, GAsyncResult *result, - long * out_response_code, - GBytes ** out_response_data, - GError ** error); + long *out_response_code, + GBytes **out_response_data, + GError **error); /*****************************************************************************/ diff --git a/src/nm-cloud-setup/nmcs-provider-aliyun.c b/src/nm-cloud-setup/nmcs-provider-aliyun.c index 7073318c..31c9830d 100644 --- a/src/nm-cloud-setup/nmcs-provider-aliyun.c +++ b/src/nm-cloud-setup/nmcs-provider-aliyun.c @@ -22,7 +22,7 @@ static const char * _aliyun_base(void) { static const char *base_cached = NULL; - const char * base; + const char *base; again: base = g_atomic_pointer_get(&base_cached); @@ -73,9 +73,9 @@ filter_chars(char *str, const char *chars) static void _detect_get_meta_data_done_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - gs_unref_object GTask *task = user_data; - gs_free_error GError *get_error = NULL; - gs_free_error GError *error = NULL; + gs_unref_object GTask *task = user_data; + gs_free_error GError *get_error = NULL; + gs_free_error GError *error = NULL; nm_http_client_poll_get_finish(NM_HTTP_CLIENT(source), result, NULL, NULL, &get_error); @@ -128,20 +128,20 @@ typedef enum { } GetConfigFetchDoneType; static void -_get_config_fetch_done_cb(NMHttpClient * http_client, - GAsyncResult * result, +_get_config_fetch_done_cb(NMHttpClient *http_client, + GAsyncResult *result, gpointer user_data, GetConfigFetchDoneType fetch_type) { - NMCSProviderGetConfigTaskData *get_config_data; - gs_unref_bytes GBytes *response = NULL; - gs_free_error GError * error = NULL; + NMCSProviderGetConfigTaskData *get_config_data; + gs_unref_bytes GBytes *response = NULL; + gs_free_error GError *error = NULL; NMCSProviderGetConfigIfaceData *config_iface_data; in_addr_t tmp_addr; int tmp_prefix; in_addr_t netmask_bin; in_addr_t gateway_bin; - gs_free const char ** s_addrs = NULL; + gs_free const char **s_addrs = NULL; gsize i; gsize len; @@ -263,11 +263,11 @@ _get_config_metadata_ready_cb(GObject *source, GAsyncResult *result, gpointer us { NMCSProviderGetConfigTaskData *get_config_data; gs_unref_hashtable GHashTable *response_parsed = NULL; - gs_free_error GError *error = NULL; - GetConfigMetadataMac *v_mac_data; - const char * v_hwaddr; - GHashTableIter h_iter; - NMHttpClient * http_client; + gs_free_error GError *error = NULL; + GetConfigMetadataMac *v_mac_data; + const char *v_hwaddr; + GHashTableIter h_iter; + NMHttpClient *http_client; nm_http_client_poll_get_finish(NM_HTTP_CLIENT(source), result, NULL, NULL, &error); @@ -293,10 +293,10 @@ _get_config_metadata_ready_cb(GObject *source, GAsyncResult *result, gpointer us g_hash_table_iter_init(&h_iter, response_parsed); while (g_hash_table_iter_next(&h_iter, (gpointer *) &v_hwaddr, (gpointer *) &v_mac_data)) { NMCSProviderGetConfigIfaceData *config_iface_data; - gs_free char * uri1 = NULL; - gs_free char * uri2 = NULL; - gs_free char * uri3 = NULL; - gs_free char * uri4 = NULL; + gs_free char *uri1 = NULL; + gs_free char *uri2 = NULL; + gs_free char *uri3 = NULL; + gs_free char *uri4 = NULL; config_iface_data = g_hash_table_lookup(get_config_data->result_dict, v_hwaddr); @@ -397,19 +397,19 @@ _get_config_metadata_ready_cb(GObject *source, GAsyncResult *result, gpointer us static gboolean _get_config_metadata_ready_check(long response_code, - GBytes * response, + GBytes *response, gpointer check_user_data, GError **error) { NMCSProviderGetConfigTaskData *get_config_data = check_user_data; gs_unref_hashtable GHashTable *response_parsed = NULL; - const guint8 * r_data; - const char * cur_line; + const guint8 *r_data; + const char *cur_line; gsize r_len; gsize cur_line_len; GHashTableIter h_iter; gboolean has_all; - const char * c_hwaddr; + const char *c_hwaddr; gssize iface_idx_counter = 0; if (response_code != 200 || !response) { @@ -423,7 +423,7 @@ _get_config_metadata_ready_check(long response_code, while (nm_utils_parse_next_line((const char **) &r_data, &r_len, &cur_line, &cur_line_len)) { GetConfigMetadataMac *mac_data; - char * hwaddr; + char *hwaddr; if (cur_line_len == 0) continue; diff --git a/src/nm-cloud-setup/nmcs-provider-azure.c b/src/nm-cloud-setup/nmcs-provider-azure.c index b3f0c68b..06f23ea7 100644 --- a/src/nm-cloud-setup/nmcs-provider-azure.c +++ b/src/nm-cloud-setup/nmcs-provider-azure.c @@ -38,9 +38,9 @@ G_DEFINE_TYPE(NMCSProviderAzure, nmcs_provider_azure, NMCS_TYPE_PROVIDER); static void _detect_get_meta_data_done_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - gs_unref_object GTask *task = user_data; - gs_free_error GError *get_error = NULL; - gs_free_error GError *error = NULL; + gs_unref_object GTask *task = user_data; + gs_free_error GError *get_error = NULL; + gs_free_error GError *error = NULL; nm_http_client_poll_get_finish(NM_HTTP_CLIENT(source), result, NULL, NULL, &get_error); @@ -92,7 +92,7 @@ typedef enum { } GetConfigFetchType; typedef struct { - NMCSProviderGetConfigTaskData * get_config_data; + NMCSProviderGetConfigTaskData *get_config_data; NMCSProviderGetConfigIfaceData *iface_get_config; gssize intern_iface_idx; gssize extern_iface_idx; @@ -106,20 +106,20 @@ _azure_iface_data_destroy(AzureIfaceData *iface_data) } static void -_get_config_fetch_done_cb(NMHttpClient * http_client, - GAsyncResult * result, - AzureIfaceData * iface_data, +_get_config_fetch_done_cb(NMHttpClient *http_client, + GAsyncResult *result, + AzureIfaceData *iface_data, GetConfigFetchType fetch_type) { - NMCSProviderGetConfigTaskData * get_config_data; + NMCSProviderGetConfigTaskData *get_config_data; NMCSProviderGetConfigIfaceData *iface_get_config; - gs_unref_bytes GBytes *response = NULL; - gs_free_error GError *error = NULL; - const char * resp_str = NULL; - gsize resp_len; - char tmp_addr_str[NM_UTILS_INET_ADDRSTRLEN]; - in_addr_t tmp_addr; - int tmp_prefix = -1; + gs_unref_bytes GBytes *response = NULL; + gs_free_error GError *error = NULL; + const char *resp_str = NULL; + gsize resp_len; + char tmp_addr_str[NM_UTILS_INET_ADDRSTRLEN]; + in_addr_t tmp_addr; + int tmp_prefix = -1; nm_http_client_poll_get_finish(http_client, result, NULL, &response, &error); @@ -196,7 +196,7 @@ out_done: } static void -_get_config_fetch_done_cb_ipv4_ipaddress_x_privateipaddress(GObject * source, +_get_config_fetch_done_cb_ipv4_ipaddress_x_privateipaddress(GObject *source, GAsyncResult *result, gpointer user_data) { @@ -207,7 +207,7 @@ _get_config_fetch_done_cb_ipv4_ipaddress_x_privateipaddress(GObject * source } static void -_get_config_fetch_done_cb_ipv4_subnet_0_address(GObject * source, +_get_config_fetch_done_cb_ipv4_subnet_0_address(GObject *source, GAsyncResult *result, gpointer user_data) { @@ -218,7 +218,7 @@ _get_config_fetch_done_cb_ipv4_subnet_0_address(GObject * source, } static void -_get_config_fetch_done_cb_ipv4_subnet_0_prefix(GObject * source, +_get_config_fetch_done_cb_ipv4_subnet_0_prefix(GObject *source, GAsyncResult *result, gpointer user_data) { @@ -231,13 +231,13 @@ _get_config_fetch_done_cb_ipv4_subnet_0_prefix(GObject * source, static void _get_config_ips_prefix_list_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - gs_unref_bytes GBytes *response = NULL; - AzureIfaceData * iface_data = user_data; - gs_free_error GError * error = NULL; - const char * response_str = NULL; + gs_unref_bytes GBytes *response = NULL; + AzureIfaceData *iface_data = user_data; + gs_free_error GError *error = NULL; + const char *response_str = NULL; gsize response_len; NMCSProviderGetConfigTaskData *get_config_data; - const char * line; + const char *line; gsize line_len; char iface_idx_str[30]; @@ -350,12 +350,12 @@ static void _get_config_iface_cb(GObject *source, GAsyncResult *result, gpointer user_data) { NMCSProviderGetConfigTaskData *get_config_data; - gs_unref_bytes GBytes *response = NULL; - AzureIfaceData * iface_data = user_data; - gs_free char * v_hwaddr = NULL; - gs_free_error GError *error = NULL; - gs_free const char * uri = NULL; - char buf[100]; + gs_unref_bytes GBytes *response = NULL; + AzureIfaceData *iface_data = user_data; + gs_free char *v_hwaddr = NULL; + gs_free_error GError *error = NULL; + gs_free const char *uri = NULL; + char buf[100]; nm_http_client_poll_get_finish(NM_HTTP_CLIENT(source), result, NULL, &response, &error); @@ -433,15 +433,15 @@ static void _get_net_ifaces_list_cb(GObject *source, GAsyncResult *result, gpointer user_data) { NMCSProviderGetConfigTaskData *get_config_data; - gs_unref_ptrarray GPtrArray *ifaces_arr = NULL; - gs_unref_bytes GBytes *response = NULL; - gs_free_error GError *error = NULL; - const char * response_str; - gsize response_len; - const char * line; - gsize line_len; - guint i; - gssize extern_iface_idx_cnt = 0; + gs_unref_ptrarray GPtrArray *ifaces_arr = NULL; + gs_unref_bytes GBytes *response = NULL; + gs_free_error GError *error = NULL; + const char *response_str; + gsize response_len; + const char *line; + gsize line_len; + guint i; + gssize extern_iface_idx_cnt = 0; nm_http_client_poll_get_finish(NM_HTTP_CLIENT(source), result, NULL, &response, &error); @@ -500,7 +500,7 @@ _get_net_ifaces_list_cb(GObject *source, GAsyncResult *result, gpointer user_dat } for (i = 0; i < ifaces_arr->len; ++i) { - AzureIfaceData * iface_data = ifaces_arr->pdata[i]; + AzureIfaceData *iface_data = ifaces_arr->pdata[i]; gs_free const char *uri = NULL; char buf[100]; diff --git a/src/nm-cloud-setup/nmcs-provider-ec2.c b/src/nm-cloud-setup/nmcs-provider-ec2.c index 96b08807..ee4e2a95 100644 --- a/src/nm-cloud-setup/nmcs-provider-ec2.c +++ b/src/nm-cloud-setup/nmcs-provider-ec2.c @@ -20,7 +20,7 @@ static const char * _ec2_base(void) { static const char *base_cached = NULL; - const char * base; + const char *base; again: base = g_atomic_pointer_get(&base_cached); @@ -58,7 +58,7 @@ G_DEFINE_TYPE(NMCSProviderEC2, nmcs_provider_ec2, NMCS_TYPE_PROVIDER); static gboolean _detect_get_meta_data_check_cb(long response_code, - GBytes * response, + GBytes *response, gpointer check_user_data, GError **error) { @@ -68,9 +68,9 @@ _detect_get_meta_data_check_cb(long response_code, static void _detect_get_meta_data_done_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - gs_unref_object GTask *task = user_data; - gs_free_error GError *get_error = NULL; - gs_free_error GError *error = NULL; + gs_unref_object GTask *task = user_data; + gs_free_error GError *get_error = NULL; + gs_free_error GError *error = NULL; nm_http_client_poll_get_finish(NM_HTTP_CLIENT(source), result, NULL, NULL, &get_error); @@ -121,9 +121,9 @@ _get_config_fetch_done_cb(NMHttpClient *http_client, gpointer user_data, gboolean is_local_ipv4) { - NMCSProviderGetConfigTaskData *get_config_data; - gs_unref_bytes GBytes *response = NULL; - gs_free_error GError * error = NULL; + NMCSProviderGetConfigTaskData *get_config_data; + gs_unref_bytes GBytes *response = NULL; + gs_free_error GError *error = NULL; NMCSProviderGetConfigIfaceData *config_iface_data; in_addr_t tmp_addr; int tmp_prefix; @@ -178,7 +178,7 @@ out: } static void -_get_config_fetch_done_cb_subnet_ipv4_cidr_block(GObject * source, +_get_config_fetch_done_cb_subnet_ipv4_cidr_block(GObject *source, GAsyncResult *result, gpointer user_data) { @@ -201,11 +201,11 @@ _get_config_metadata_ready_cb(GObject *source, GAsyncResult *result, gpointer us { NMCSProviderGetConfigTaskData *get_config_data; gs_unref_hashtable GHashTable *response_parsed = NULL; - gs_free_error GError *error = NULL; - GetConfigMetadataMac *v_mac_data; - const char * v_hwaddr; - GHashTableIter h_iter; - NMHttpClient * http_client; + gs_free_error GError *error = NULL; + GetConfigMetadataMac *v_mac_data; + const char *v_hwaddr; + GHashTableIter h_iter; + NMHttpClient *http_client; nm_http_client_poll_get_finish(NM_HTTP_CLIENT(source), result, NULL, NULL, &error); @@ -231,8 +231,8 @@ _get_config_metadata_ready_cb(GObject *source, GAsyncResult *result, gpointer us g_hash_table_iter_init(&h_iter, response_parsed); while (g_hash_table_iter_next(&h_iter, (gpointer *) &v_hwaddr, (gpointer *) &v_mac_data)) { NMCSProviderGetConfigIfaceData *config_iface_data; - gs_free char * uri1 = NULL; - gs_free char * uri2 = NULL; + gs_free char *uri1 = NULL; + gs_free char *uri2 = NULL; config_iface_data = g_hash_table_lookup(get_config_data->result_dict, v_hwaddr); @@ -298,19 +298,19 @@ _get_config_metadata_ready_cb(GObject *source, GAsyncResult *result, gpointer us static gboolean _get_config_metadata_ready_check(long response_code, - GBytes * response, + GBytes *response, gpointer check_user_data, GError **error) { NMCSProviderGetConfigTaskData *get_config_data = check_user_data; gs_unref_hashtable GHashTable *response_parsed = NULL; - const guint8 * r_data; - const char * cur_line; + const guint8 *r_data; + const char *cur_line; gsize r_len; gsize cur_line_len; GHashTableIter h_iter; gboolean has_all; - const char * c_hwaddr; + const char *c_hwaddr; gssize iface_idx_counter = 0; if (response_code != 200 || !response) { @@ -324,7 +324,7 @@ _get_config_metadata_ready_check(long response_code, while (nm_utils_parse_next_line((const char **) &r_data, &r_len, &cur_line, &cur_line_len)) { GetConfigMetadataMac *mac_data; - char * hwaddr; + char *hwaddr; if (cur_line_len == 0) continue; diff --git a/src/nm-cloud-setup/nmcs-provider-gcp.c b/src/nm-cloud-setup/nmcs-provider-gcp.c index 60425ad9..0df2bdd6 100644 --- a/src/nm-cloud-setup/nmcs-provider-gcp.c +++ b/src/nm-cloud-setup/nmcs-provider-gcp.c @@ -41,9 +41,9 @@ G_DEFINE_TYPE(NMCSProviderGCP, nmcs_provider_gcp, NMCS_TYPE_PROVIDER); static void _detect_get_meta_data_done_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - gs_unref_object GTask *task = user_data; - gs_free_error GError *get_error = NULL; - gs_free_error GError *error = NULL; + gs_unref_object GTask *task = user_data; + gs_free_error GError *get_error = NULL; + gs_free_error GError *error = NULL; nm_http_client_poll_get_finish(NM_HTTP_CLIENT(source), result, NULL, NULL, &get_error); @@ -89,7 +89,7 @@ detect(NMCSProvider *provider, GTask *task) /*****************************************************************************/ typedef struct { - NMCSProviderGetConfigTaskData * get_config_data; + NMCSProviderGetConfigTaskData *get_config_data; NMCSProviderGetConfigIfaceData *iface_get_config; gssize intern_iface_idx; gssize extern_iface_idx; @@ -105,14 +105,14 @@ _gcp_iface_data_destroy(GCPIfaceData *iface_data) static void _get_config_fip_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - NMCSProviderGetConfigTaskData * get_config_data; + NMCSProviderGetConfigTaskData *get_config_data; NMCSProviderGetConfigIfaceData *iface_get_config; - gs_unref_bytes GBytes *response = NULL; - GCPIfaceData * iface_data = user_data; - gs_free_error GError *error = NULL; - gs_free char * ipaddr = NULL; - NMIPRoute ** routes_arr; - NMIPRoute * route_new; + gs_unref_bytes GBytes *response = NULL; + GCPIfaceData *iface_data = user_data; + gs_free_error GError *error = NULL; + gs_free char *ipaddr = NULL; + NMIPRoute **routes_arr; + NMIPRoute *route_new; nm_http_client_poll_get_finish(NM_HTTP_CLIENT(source), result, NULL, &response, &error); @@ -161,15 +161,15 @@ static void _get_config_ips_list_cb(GObject *source, GAsyncResult *result, gpointer user_data) { NMCSProviderGetConfigTaskData *get_config_data; - gs_unref_ptrarray GPtrArray *uri_arr = NULL; - gs_unref_bytes GBytes *response = NULL; - GCPIfaceData * iface_data = user_data; - gs_free_error GError *error = NULL; - const char * response_str = NULL; - gsize response_len; - const char * line; - gsize line_len; - guint i; + gs_unref_ptrarray GPtrArray *uri_arr = NULL; + gs_unref_bytes GBytes *response = NULL; + GCPIfaceData *iface_data = user_data; + gs_free_error GError *error = NULL; + const char *response_str = NULL; + gsize response_len; + const char *line; + gsize line_len; + guint i; nm_http_client_poll_get_finish(NM_HTTP_CLIENT(source), result, NULL, &response, &error); @@ -217,7 +217,7 @@ _get_config_ips_list_cb(GObject *source, GAsyncResult *result, gpointer user_dat iface_data->iface_get_config->iproutes_arr = g_new(NMIPRoute *, iface_data->n_fips_pending); for (i = 0; i < uri_arr->len; ++i) { - const char * str = uri_arr->pdata[i]; + const char *str = uri_arr->pdata[i]; gs_free const char *uri = NULL; nm_http_client_poll_get(NM_HTTP_CLIENT(source), @@ -243,11 +243,11 @@ out_error: static void _get_config_iface_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - gs_unref_bytes GBytes *response = NULL; - GCPIfaceData * iface_data = user_data; - gs_free_error GError * error = NULL; - gs_free char * v_hwaddr = NULL; - gs_free const char * uri = NULL; + gs_unref_bytes GBytes *response = NULL; + GCPIfaceData *iface_data = user_data; + gs_free_error GError *error = NULL; + gs_free char *v_hwaddr = NULL; + gs_free const char *uri = NULL; char sbuf[100]; NMCSProviderGetConfigTaskData *get_config_data; gboolean is_requested; @@ -330,13 +330,13 @@ out_done: static void _get_net_ifaces_list_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - gs_unref_ptrarray GPtrArray *ifaces_arr = NULL; - gs_unref_bytes GBytes *response = NULL; - gs_free_error GError * error = NULL; + gs_unref_ptrarray GPtrArray *ifaces_arr = NULL; + gs_unref_bytes GBytes *response = NULL; + gs_free_error GError *error = NULL; NMCSProviderGetConfigTaskData *get_config_data; - const char * response_str; + const char *response_str; gsize response_len; - const char * line; + const char *line; gsize line_len; guint i; gssize extern_iface_idx_cnt = 0; @@ -397,7 +397,7 @@ _get_net_ifaces_list_cb(GObject *source, GAsyncResult *result, gpointer user_dat } for (i = 0; i < ifaces_arr->len; ++i) { - GCPIfaceData * data = ifaces_arr->pdata[i]; + GCPIfaceData *data = ifaces_arr->pdata[i]; gs_free const char *uri = NULL; char sbuf[100]; diff --git a/src/nm-cloud-setup/nmcs-provider.c b/src/nm-cloud-setup/nmcs-provider.c index 138e78d4..f14a3d02 100644 --- a/src/nm-cloud-setup/nmcs-provider.c +++ b/src/nm-cloud-setup/nmcs-provider.c @@ -68,11 +68,11 @@ static NMCSProviderGetConfigResult * nmcs_provider_get_config_result_new(GHashTable *iface_datas) { const NMCSProviderGetConfigIfaceData *iface_data; - NMCSProviderGetConfigResult * result; + NMCSProviderGetConfigResult *result; GHashTableIter h_iter; guint num_valid_ifaces = 0; guint num_ipv4s = 0; - GPtrArray * ptrarr; + GPtrArray *ptrarr; guint n_iface_datas; n_iface_datas = g_hash_table_size(iface_datas); @@ -137,13 +137,13 @@ nmcs_provider_get_config_result_free(NMCSProviderGetConfigResult *result) /*****************************************************************************/ void -nmcs_provider_detect(NMCSProvider * self, - GCancellable * cancellable, +nmcs_provider_detect(NMCSProvider *self, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { gs_unref_object GTask *task = NULL; - const char * env; + const char *env; g_return_if_fail(NMCS_IS_PROVIDER(self)); g_return_if_fail(!cancellable || G_IS_CANCELLABLE(cancellable)); @@ -251,7 +251,7 @@ _get_config_task_maybe_return(NMCSProviderGetConfigTaskData *get_config_data, GE void _nmcs_provider_get_config_task_maybe_return(NMCSProviderGetConfigTaskData *get_config_data, - GError * error_take) + GError *error_take) { nm_assert(!error_take || !nm_utils_error_is_cancelled(error_take)); _get_config_task_maybe_return(get_config_data, error_take); @@ -264,10 +264,10 @@ _get_config_cancelled_cb(GObject *object, gpointer user_data) } void -nmcs_provider_get_config(NMCSProvider * self, +nmcs_provider_get_config(NMCSProvider *self, gboolean any, - const char *const * hwaddrs, - GCancellable * cancellable, + const char *const *hwaddrs, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { @@ -351,7 +351,7 @@ nmcs_provider_init(NMCSProvider *self) static void dispose(GObject *object) { - NMCSProvider * self = NMCS_PROVIDER(object); + NMCSProvider *self = NMCS_PROVIDER(object); NMCSProviderPrivate *priv = NMCS_PROVIDER_GET_PRIVATE(self); g_clear_object(&priv->http_client); diff --git a/src/nm-cloud-setup/nmcs-provider.h b/src/nm-cloud-setup/nmcs-provider.h index 36632059..bce41dcb 100644 --- a/src/nm-cloud-setup/nmcs-provider.h +++ b/src/nm-cloud-setup/nmcs-provider.h @@ -125,8 +125,8 @@ typedef struct { typedef struct { GObjectClass parent; - const char * _name; - const char * _env_provider_enabled; + const char *_name; + const char *_env_provider_enabled; void (*detect)(NMCSProvider *self, GTask *task); @@ -145,8 +145,8 @@ GMainContext *nmcs_provider_get_main_context(NMCSProvider *provider); /*****************************************************************************/ -void nmcs_provider_detect(NMCSProvider * provider, - GCancellable * cancellable, +void nmcs_provider_detect(NMCSProvider *provider, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); @@ -155,12 +155,12 @@ gboolean nmcs_provider_detect_finish(NMCSProvider *provider, GAsyncResult *resul /*****************************************************************************/ void _nmcs_provider_get_config_task_maybe_return(NMCSProviderGetConfigTaskData *get_config_data, - GError * error_take); + GError *error_take); -void nmcs_provider_get_config(NMCSProvider * provider, +void nmcs_provider_get_config(NMCSProvider *provider, gboolean any, - const char *const * hwaddrs, - GCancellable * cancellable, + const char *const *hwaddrs, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); diff --git a/src/nm-cloud-setup/tests/test-cloud-setup-general.c b/src/nm-cloud-setup/tests/test-cloud-setup-general.c index 82df4e17..c8635009 100644 --- a/src/nm-cloud-setup/tests/test-cloud-setup-general.c +++ b/src/nm-cloud-setup/tests/test-cloud-setup-general.c @@ -41,10 +41,10 @@ static void _test_ri4a(const char *const *addrs_before, const char *const *addrs_new) { gs_unref_object NMSettingIPConfig *s_ip = NULL; - gs_unref_ptrarray GPtrArray *arr = NULL; - const gsize n = NM_PTRARRAY_LEN(addrs_new); - gboolean changed; - gsize i; + gs_unref_ptrarray GPtrArray *arr = NULL; + const gsize n = NM_PTRARRAY_LEN(addrs_new); + gboolean changed; + gsize i; s_ip = _ri4a_new_s_ip(addrs_before); arr = _ri4a_new_arr(addrs_new); diff --git a/src/nm-dispatcher/nm-dispatcher-utils.c b/src/nm-dispatcher/nm-dispatcher-utils.c index f754a3fa..74ea4e40 100644 --- a/src/nm-dispatcher/nm-dispatcher-utils.c +++ b/src/nm-dispatcher/nm-dispatcher-utils.c @@ -131,7 +131,7 @@ static void _items_add_printf(GPtrArray *items, const char *fmt, ...) { va_list ap; - char * line; + char *line; nm_assert(items); nm_assert(fmt); @@ -225,8 +225,8 @@ construct_ip_items(GPtrArray *items, int addr_family, GVariant *ip_config, const : G_VARIANT_TYPE("a(ayuay)")); if (val) { gs_unref_ptrarray GPtrArray *addresses = NULL; - gs_free char * gateway_free = NULL; - const char * gateway; + gs_free char *gateway_free = NULL; + const char *gateway; if (addr_family == AF_INET) addresses = nm_utils_ip4_addresses_from_variant(val, &gateway_free); @@ -346,12 +346,12 @@ construct_ip_items(GPtrArray *items, int addr_family, GVariant *ip_config, const static void construct_device_dhcp_items(GPtrArray *items, int addr_family, GVariant *dhcp_config) { - GVariantIter iter; - const char * key; - GVariant * val; - char four_or_six; - gboolean found_unknown_245 = FALSE; - gs_unref_variant GVariant *private_245_val = NULL; + GVariantIter iter; + const char *key; + GVariant *val; + char four_or_six; + gboolean found_unknown_245 = FALSE; + gs_unref_variant GVariant *private_245_val = NULL; if (!dhcp_config) return; @@ -415,34 +415,34 @@ construct_device_dhcp_items(GPtrArray *items, int addr_family, GVariant *dhcp_co /*****************************************************************************/ char ** -nm_dispatcher_utils_construct_envp(const char * action, - GVariant * connection_dict, - GVariant * connection_props, - GVariant * device_props, - GVariant * device_proxy_props, - GVariant * device_ip4_props, - GVariant * device_ip6_props, - GVariant * device_dhcp4_props, - GVariant * device_dhcp6_props, - const char * connectivity_state, - const char * vpn_ip_iface, - GVariant * vpn_proxy_props, - GVariant * vpn_ip4_props, - GVariant * vpn_ip6_props, - char ** out_iface, +nm_dispatcher_utils_construct_envp(const char *action, + GVariant *connection_dict, + GVariant *connection_props, + GVariant *device_props, + GVariant *device_proxy_props, + GVariant *device_ip4_props, + GVariant *device_ip6_props, + GVariant *device_dhcp4_props, + GVariant *device_dhcp6_props, + const char *connectivity_state, + const char *vpn_ip_iface, + GVariant *vpn_proxy_props, + GVariant *vpn_ip4_props, + GVariant *vpn_ip6_props, + char **out_iface, const char **out_error_message) { - const char * iface = NULL; - const char * ip_iface = NULL; - const char * uuid = NULL; - const char * id = NULL; - const char * path = NULL; - const char * filename = NULL; - gboolean external; - NMDeviceState dev_state = NM_DEVICE_STATE_UNKNOWN; - GVariant * variant; + const char *iface = NULL; + const char *ip_iface = NULL; + const char *uuid = NULL; + const char *id = NULL; + const char *path = NULL; + const char *filename = NULL; + gboolean external; + NMDeviceState dev_state = NM_DEVICE_STATE_UNKNOWN; + GVariant *variant; gs_unref_ptrarray GPtrArray *items = NULL; - const char * error_message_backup; + const char *error_message_backup; if (!out_error_message) out_error_message = &error_message_backup; diff --git a/src/nm-dispatcher/nm-dispatcher-utils.h b/src/nm-dispatcher/nm-dispatcher-utils.h index cb40d146..b9e9b2c1 100644 --- a/src/nm-dispatcher/nm-dispatcher-utils.h +++ b/src/nm-dispatcher/nm-dispatcher-utils.h @@ -6,21 +6,21 @@ #ifndef __NETWORKMANAGER_DISPATCHER_UTILS_H__ #define __NETWORKMANAGER_DISPATCHER_UTILS_H__ -char **nm_dispatcher_utils_construct_envp(const char * action, - GVariant * connection_dict, - GVariant * connection_props, - GVariant * device_props, - GVariant * device_proxy_props, - GVariant * device_ip4_props, - GVariant * device_ip6_props, - GVariant * device_dhcp4_props, - GVariant * device_dhcp6_props, - const char * connectivity_state, - const char * vpn_ip_iface, - GVariant * vpn_proxy_props, - GVariant * vpn_ip4_props, - GVariant * vpn_ip6_props, - char ** out_iface, +char **nm_dispatcher_utils_construct_envp(const char *action, + GVariant *connection_dict, + GVariant *connection_props, + GVariant *device_props, + GVariant *device_proxy_props, + GVariant *device_ip4_props, + GVariant *device_ip6_props, + GVariant *device_dhcp4_props, + GVariant *device_dhcp6_props, + const char *connectivity_state, + const char *vpn_ip_iface, + GVariant *vpn_proxy_props, + GVariant *vpn_ip4_props, + GVariant *vpn_ip6_props, + char **out_iface, const char **out_error_message); #endif /* __NETWORKMANAGER_DISPATCHER_UTILS_H__ */ diff --git a/src/nm-dispatcher/nm-dispatcher.c b/src/nm-dispatcher/nm-dispatcher.c index b29f5aca..aeecaa9b 100644 --- a/src/nm-dispatcher/nm-dispatcher.c +++ b/src/nm-dispatcher/nm-dispatcher.c @@ -35,7 +35,7 @@ typedef struct Request Request; typedef struct { GDBusConnection *dbus_connection; - GCancellable * quit_cancellable; + GCancellable *quit_cancellable; bool log_verbose; bool log_stdout; @@ -50,7 +50,7 @@ typedef struct { gboolean persist; Request *current_request; - GQueue * requests_waiting; + GQueue *requests_waiting; int num_requests_pending; bool exit_with_failure; @@ -67,23 +67,23 @@ GlobalData gl; typedef struct { Request *request; - char * script; + char *script; GPid pid; DispatchResult result; - char * error; + char *error; gboolean wait; gboolean dispatched; - GSource * watch_source; - GSource * timeout_source; + GSource *watch_source; + GSource *timeout_source; } ScriptInfo; struct Request { guint request_id; GDBusMethodInvocation *context; - char * action; - char * iface; - char ** envp; + char *action; + char *iface; + char **envp; gboolean debug; GPtrArray *scripts; /* list of ScriptInfo */ @@ -293,7 +293,7 @@ static void complete_request(Request *request) { GVariantBuilder results; - GVariant * ret; + GVariant *ret; guint i; nm_assert(request); @@ -397,7 +397,7 @@ complete_script(ScriptInfo *script) static void script_watch_cb(GPid pid, int status, gpointer user_data) { - ScriptInfo * script = user_data; + ScriptInfo *script = user_data; gs_free char *status_desc = NULL; g_assert(pid == script->pid); @@ -518,8 +518,8 @@ static gboolean script_dispatch(ScriptInfo *script) { gs_free_error GError *error = NULL; - char * argv[4]; - Request * request = script->request; + char *argv[4]; + Request *request = script->request; if (script->dispatched) return FALSE; @@ -596,10 +596,10 @@ _compare_basenames(gconstpointer a, gconstpointer b) static void _find_scripts(Request *request, GHashTable *scripts, const char *base, const char *subdir) { - const char * filename; + const char *filename; gs_free char *dirname = NULL; - GError * error = NULL; - GDir * dir; + GError *error = NULL; + GDir *dir; dirname = g_build_filename(base, "dispatcher.d", subdir, NULL); @@ -628,11 +628,11 @@ static GSList * find_scripts(Request *request) { gs_unref_hashtable GHashTable *scripts = NULL; - GSList * script_list = NULL; + GSList *script_list = NULL; GHashTableIter iter; - const char * subdir; - char * path; - char * filename; + const char *subdir; + char *path; + char *filename; if (NM_IN_STRSET(request->action, NMD_ACTION_PRE_UP, NMD_ACTION_VPN_PRE_UP)) subdir = "pre-up.d"; @@ -649,7 +649,7 @@ find_scripts(Request *request) g_hash_table_iter_init(&iter, scripts); while (g_hash_table_iter_next(&iter, (gpointer *) &filename, (gpointer *) &path)) { gs_free char *link_target = NULL; - const char * err_msg = NULL; + const char *err_msg = NULL; struct stat st; int err; @@ -681,7 +681,7 @@ script_must_wait(const char *path) link = g_file_read_link(path, NULL); if (link) { - gs_free char * dir = NULL; + gs_free char *dir = NULL; nm_auto_free char *real = NULL; if (!g_path_is_absolute(link)) { @@ -706,7 +706,7 @@ script_must_wait(const char *path) static void _handle_action(GDBusMethodInvocation *invocation, GVariant *parameters) { - const char * action; + const char *action; gs_unref_variant GVariant *connection = NULL; gs_unref_variant GVariant *connection_properties = NULL; gs_unref_variant GVariant *device_properties = NULL; @@ -715,18 +715,18 @@ _handle_action(GDBusMethodInvocation *invocation, GVariant *parameters) gs_unref_variant GVariant *device_ip6_config = NULL; gs_unref_variant GVariant *device_dhcp4_config = NULL; gs_unref_variant GVariant *device_dhcp6_config = NULL; - const char * connectivity_state; - const char * vpn_ip_iface; + const char *connectivity_state; + const char *vpn_ip_iface; gs_unref_variant GVariant *vpn_proxy_properties = NULL; gs_unref_variant GVariant *vpn_ip4_config = NULL; gs_unref_variant GVariant *vpn_ip6_config = NULL; gboolean debug; - GSList * sorted_scripts = NULL; - GSList * iter; - Request * request; - char ** p; + GSList *sorted_scripts = NULL; + GSList *iter; + Request *request; + char **p; guint i, num_nowait = 0; - const char * error_message = NULL; + const char *error_message = NULL; g_variant_get(parameters, "(" @@ -872,7 +872,7 @@ _handle_ping(GDBusMethodInvocation *invocation, GVariant *parameters) { gs_free char *msg = NULL; gint64 running_msec; - const char * arg_s; + const char *arg_s; g_variant_get(parameters, "(&s)", &arg_s); @@ -888,12 +888,12 @@ _handle_ping(GDBusMethodInvocation *invocation, GVariant *parameters) } static void -_bus_method_call(GDBusConnection * connection, - const char * sender, - const char * object_path, - const char * interface_name, - const char * method_name, - GVariant * parameters, +_bus_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) { @@ -955,9 +955,9 @@ _bus_register_service(void) static const GDBusInterfaceVTable interface_vtable = { .method_call = _bus_method_call, }; - gs_free_error GError * error = NULL; + gs_free_error GError *error = NULL; NMDBusConnectionCallBlockingData data = { - .result = NULL, + .result = NULL, }; gs_unref_variant GVariant *ret = NULL; guint32 ret_val; @@ -1185,8 +1185,8 @@ int main(int argc, char **argv) { gs_free_error GError *error = NULL; - GSource * source_term = NULL; - GSource * source_int = NULL; + GSource *source_term = NULL; + GSource *source_int = NULL; signal(SIGPIPE, SIG_IGN); source_term = diff --git a/src/nm-dispatcher/tests/test-dispatcher-envp.c b/src/nm-dispatcher/tests/test-dispatcher-envp.c index 8a24c426..f53bb1c1 100644 --- a/src/nm-dispatcher/tests/test-dispatcher-envp.c +++ b/src/nm-dispatcher/tests/test-dispatcher-envp.c @@ -24,7 +24,7 @@ _print_env(const char *const *denv, GHashTable *expected_env) { const char *const *iter; GHashTableIter k; - const char * key; + const char *key; g_print("\n******* Generated environment:\n"); for (iter = denv; iter && *iter; iter++) @@ -37,22 +37,22 @@ _print_env(const char *const *denv, GHashTable *expected_env) } static gboolean -parse_main(GKeyFile * kf, +parse_main(GKeyFile *kf, const char *filename, - GVariant ** out_con_dict, - GVariant ** out_con_props, - char ** out_expected_iface, - char ** out_action, - char ** out_connectivity_state, - char ** out_vpn_ip_iface, - GError ** error) + GVariant **out_con_dict, + GVariant **out_con_props, + char **out_expected_iface, + char **out_action, + char **out_connectivity_state, + char **out_vpn_ip_iface, + GError **error) { - nm_auto_clear_variant_builder GVariantBuilder props = {}; - gs_free char * uuid = NULL; - gs_free char * id = NULL; - gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - const char * s; + nm_auto_clear_variant_builder GVariantBuilder props = {}; + gs_free char *uuid = NULL; + gs_free char *id = NULL; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection *s_con; + const char *s; *out_expected_iface = g_key_file_get_string(kf, "main", "expected-iface", NULL); @@ -108,7 +108,7 @@ static gboolean parse_device(GKeyFile *kf, GVariant **out_device_props, GError **error) { nm_auto_clear_variant_builder GVariantBuilder props = {}; - gs_free char * tmp = NULL; + gs_free char *tmp = NULL; int i; g_variant_builder_init(&props, G_VARIANT_TYPE("a{sv}")); @@ -145,13 +145,13 @@ parse_device(GKeyFile *kf, GVariant **out_device_props, GError **error) } static gboolean -add_uint_array(GKeyFile * kf, +add_uint_array(GKeyFile *kf, GVariantBuilder *props, - const char * section, - const char * key, - GError ** error) + const char *section, + const char *key, + GError **error) { - gs_free char * tmp = NULL; + gs_free char *tmp = NULL; gs_free const char **split = NULL; gsize i; @@ -193,7 +193,7 @@ static gboolean parse_proxy(GKeyFile *kf, GVariant **out_props, const char *section, GError **error) { nm_auto_clear_variant_builder GVariantBuilder props = {}; - gs_free char * tmp = NULL; + gs_free char *tmp = NULL; g_variant_builder_init(&props, G_VARIANT_TYPE("a{sv}")); @@ -216,9 +216,9 @@ static gboolean parse_ip4(GKeyFile *kf, GVariant **out_props, const char *section, GError **error) { nm_auto_clear_variant_builder GVariantBuilder props = {}; - gs_free char * tmp = NULL; - gs_free const char ** split = NULL; - const char ** iter; + gs_free char *tmp = NULL; + gs_free const char **split = NULL; + const char **iter; g_variant_builder_init(&props, G_VARIANT_TYPE("a{sv}")); @@ -250,14 +250,14 @@ parse_ip4(GKeyFile *kf, GVariant **out_props, const char *section, GError **erro split = nm_strsplit_set_with_empty(tmp, ","); if (split) { gs_unref_ptrarray GPtrArray *addresses = NULL; - const char * gateway = NULL; + const char *gateway = NULL; addresses = g_ptr_array_new_with_free_func((GDestroyNotify) nm_ip_address_unref); for (iter = split; *iter; iter++) { - const char * s = *iter; + const char *s = *iter; NMIPAddress *addr; - const char * ip; - const char * prefix; + const char *ip; + const char *prefix; g_strstrip((char *) s); if (s[0] == '\0') @@ -298,7 +298,7 @@ parse_ip4(GKeyFile *kf, GVariant **out_props, const char *section, GError **erro routes = g_ptr_array_new_with_free_func((GDestroyNotify) nm_ip_route_unref); for (iter = split; *iter; iter++) { const char *s = *iter; - NMIPRoute * route; + NMIPRoute *route; const char *dest; const char *prefix; const char *next_hop; @@ -344,8 +344,8 @@ static gboolean parse_dhcp(GKeyFile *kf, const char *group_name, GVariant **out_props, GError **error) { nm_auto_clear_variant_builder GVariantBuilder props = {}; - gs_strfreev char ** keys = NULL; - char ** iter; + gs_strfreev char **keys = NULL; + char **iter; keys = g_key_file_get_keys(kf, group_name, NULL, error); if (!keys) @@ -366,28 +366,28 @@ parse_dhcp(GKeyFile *kf, const char *group_name, GVariant **out_props, GError ** } static gboolean -get_dispatcher_file(const char * file, - GVariant ** out_con_dict, - GVariant ** out_con_props, - GVariant ** out_device_props, - GVariant ** out_device_proxy_props, - GVariant ** out_device_ip4_props, - GVariant ** out_device_ip6_props, - GVariant ** out_device_dhcp4_props, - GVariant ** out_device_dhcp6_props, - char ** out_connectivity_state, - char ** out_vpn_ip_iface, - GVariant ** out_vpn_proxy_props, - GVariant ** out_vpn_ip4_props, - GVariant ** out_vpn_ip6_props, - char ** out_expected_iface, - char ** out_action, +get_dispatcher_file(const char *file, + GVariant **out_con_dict, + GVariant **out_con_props, + GVariant **out_device_props, + GVariant **out_device_proxy_props, + GVariant **out_device_ip4_props, + GVariant **out_device_ip6_props, + GVariant **out_device_dhcp4_props, + GVariant **out_device_dhcp6_props, + char **out_connectivity_state, + char **out_vpn_ip_iface, + GVariant **out_vpn_proxy_props, + GVariant **out_vpn_ip4_props, + GVariant **out_vpn_ip6_props, + char **out_expected_iface, + char **out_action, GHashTable **out_env, - GError ** error) + GError **error) { nm_auto_unref_keyfile GKeyFile *kf = NULL; - gs_strfreev char ** keys = NULL; - char ** iter; + gs_strfreev char **keys = NULL; + char **iter; g_assert(!error || !*error); g_assert(out_con_dict && !*out_con_dict); @@ -465,29 +465,29 @@ get_dispatcher_file(const char * file, static void test_generic(const char *file, const char *override_vpn_ip_iface) { - gs_unref_variant GVariant *con_dict = NULL; - gs_unref_variant GVariant *con_props = NULL; - gs_unref_variant GVariant *device_props = NULL; - gs_unref_variant GVariant *device_proxy_props = NULL; - gs_unref_variant GVariant *device_ip4_props = NULL; - gs_unref_variant GVariant *device_ip6_props = NULL; - gs_unref_variant GVariant *device_dhcp4_props = NULL; - gs_unref_variant GVariant *device_dhcp6_props = NULL; - gs_free char * connectivity_change = NULL; - gs_free char * vpn_ip_iface = NULL; - gs_unref_variant GVariant *vpn_proxy_props = NULL; - gs_unref_variant GVariant *vpn_ip4_props = NULL; - gs_unref_variant GVariant *vpn_ip6_props = NULL; - gs_free char * expected_iface = NULL; - gs_free char * action = NULL; - gs_free char * out_iface = NULL; - const char * error_message = NULL; - gs_unref_hashtable GHashTable *expected_env = NULL; - GError * error = NULL; + gs_unref_variant GVariant *con_dict = NULL; + gs_unref_variant GVariant *con_props = NULL; + gs_unref_variant GVariant *device_props = NULL; + gs_unref_variant GVariant *device_proxy_props = NULL; + gs_unref_variant GVariant *device_ip4_props = NULL; + gs_unref_variant GVariant *device_ip6_props = NULL; + gs_unref_variant GVariant *device_dhcp4_props = NULL; + gs_unref_variant GVariant *device_dhcp6_props = NULL; + gs_free char *connectivity_change = NULL; + gs_free char *vpn_ip_iface = NULL; + gs_unref_variant GVariant *vpn_proxy_props = NULL; + gs_unref_variant GVariant *vpn_ip4_props = NULL; + gs_unref_variant GVariant *vpn_ip6_props = NULL; + gs_free char *expected_iface = NULL; + gs_free char *action = NULL; + gs_free char *out_iface = NULL; + const char *error_message = NULL; + gs_unref_hashtable GHashTable *expected_env = NULL; + GError *error = NULL; gboolean success; - gs_free char * filename = NULL; - gs_strfreev char ** denv = NULL; - char ** iter; + gs_free char *filename = NULL; + gs_strfreev char **denv = NULL; + char **iter; filename = g_build_filename(TEST_DIR, file, NULL); success = get_dispatcher_file(filename, diff --git a/src/nm-initrd-generator/nm-initrd-generator.c b/src/nm-initrd-generator/nm-initrd-generator.c index b78808b2..981cb14b 100644 --- a/src/nm-initrd-generator/nm-initrd-generator.c +++ b/src/nm-initrd-generator/nm-initrd-generator.c @@ -28,14 +28,14 @@ static void output_conn(gpointer key, gpointer value, gpointer user_data) { - const char * basename = key; - NMConnection * connection = value; - char * connections_dir = user_data; - nm_auto_unref_keyfile GKeyFile *file = NULL; - gs_free char * data = NULL; - gs_free_error GError *error = NULL; - gsize len; - NMSetting * setting; + const char *basename = key; + NMConnection *connection = value; + char *connections_dir = user_data; + nm_auto_unref_keyfile GKeyFile *file = NULL; + gs_free char *data = NULL; + gs_free_error GError *error = NULL; + gsize len; + NMSetting *setting; setting = nm_setting_user_new(); nm_connection_add_setting(connection, setting); @@ -79,14 +79,15 @@ err_out: int main(int argc, char *argv[]) { - GHashTable * connections; - gs_free char * connections_dir = NULL; - gs_free char * initrd_dir = NULL; - gs_free char * sysfs_dir = NULL; - gs_free char * run_config_dir = NULL; - gboolean dump_to_stdout = FALSE; - gs_strfreev char **remaining = NULL; - GOptionEntry option_entries[] = { + GHashTable *connections; + gs_free char *connections_dir = NULL; + gs_free char *etc_connections_dir = NULL; + gs_free char *initrd_dir = NULL; + gs_free char *sysfs_dir = NULL; + gs_free char *run_config_dir = NULL; + gboolean dump_to_stdout = FALSE; + gs_strfreev char **remaining = NULL; + GOptionEntry option_entries[] = { {"connections-dir", 'c', 0, @@ -94,6 +95,13 @@ main(int argc, char *argv[]) &connections_dir, "Output connection directory", NM_KEYFILE_PATH_NAME_RUN}, + {"persistent-connections-dir", + 'p', + 0, + G_OPTION_ARG_FILENAME, + &etc_connections_dir, + "Persistent connection directory", + NM_KEYFILE_PATH_NAME_ETC_DEFAULT}, {"initrd-data-dir", 'i', 0, @@ -125,10 +133,10 @@ main(int argc, char *argv[]) {G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &remaining, NULL, NULL}, {NULL}}; nm_auto_free_option_context GOptionContext *option_context = NULL; - gs_free_error GError *error = NULL; - gs_free char * hostname = NULL; - int errsv; - gint64 carrier_timeout_sec = 0; + gs_free_error GError *error = NULL; + gs_free char *hostname = NULL; + int errsv; + gint64 carrier_timeout_sec = 0; option_context = g_option_context_new( "-- [ip=...] [rd.route=...] [bridge=...] [bond=...] [team=...] [vlan=...] " @@ -153,6 +161,8 @@ main(int argc, char *argv[]) return 0; } + if (!etc_connections_dir) + etc_connections_dir = g_strdup(NM_KEYFILE_PATH_NAME_ETC_DEFAULT); if (!connections_dir) connections_dir = g_strdup(NM_KEYFILE_PATH_NAME_RUN); if (!sysfs_dir) @@ -162,7 +172,8 @@ main(int argc, char *argv[]) if (!run_config_dir) run_config_dir = g_strdup(DEFAULT_RUN_CONFIG_DIR); - connections = nmi_cmdline_reader_parse(sysfs_dir, + connections = nmi_cmdline_reader_parse(etc_connections_dir, + sysfs_dir, (const char *const *) remaining, &hostname, &carrier_timeout_sec); @@ -207,7 +218,7 @@ main(int argc, char *argv[]) } if (carrier_timeout_sec != 0) { nm_auto_unref_keyfile GKeyFile *keyfile = NULL; - gs_free char * filename = NULL; + gs_free char *filename = NULL; keyfile = g_key_file_new(); g_key_file_set_list_separator(keyfile, NM_CONFIG_KEYFILE_LIST_SEPARATOR); diff --git a/src/nm-initrd-generator/nm-initrd-generator.h b/src/nm-initrd-generator/nm-initrd-generator.h index 2ec52a01..4f33ac65 100644 --- a/src/nm-initrd-generator/nm-initrd-generator.h +++ b/src/nm-initrd-generator/nm-initrd-generator.h @@ -38,9 +38,10 @@ nmi_ibft_update_connection_from_nic(NMConnection *connection, GHashTable *nic, G NMConnection *nmi_dt_reader_parse(const char *sysfs_dir); -GHashTable *nmi_cmdline_reader_parse(const char * sysfs_dir, +GHashTable *nmi_cmdline_reader_parse(const char *etc_connections_dir, + const char *sysfs_dir, const char *const *argv, - char ** hostname, - gint64 * carrier_timeout_sec); + char **hostname, + gint64 *carrier_timeout_sec); #endif /* __NM_INITRD_GENERATOR_H__ */ diff --git a/src/nm-initrd-generator/nmi-cmdline-reader.c b/src/nm-initrd-generator/nmi-cmdline-reader.c index 8fafb08f..412c7510 100644 --- a/src/nm-initrd-generator/nmi-cmdline-reader.c +++ b/src/nm-initrd-generator/nmi-cmdline-reader.c @@ -27,18 +27,19 @@ /*****************************************************************************/ typedef struct { - GHashTable * hash; - GPtrArray * array; - GPtrArray * vlan_parents; - GHashTable * explicit_ip_connections; + GHashTable *hash; + GPtrArray *array; + GPtrArray *vlan_parents; + GHashTable *explicit_ip_connections; NMConnection *bootdev_connection; /* connection for bootdev=$ifname */ NMConnection *default_connection; /* connection not bound to any ifname */ - char * hostname; + char *hostname; + GHashTable *znet_ifnames; /* Parameters to be set for all connections */ gboolean ignore_auto_dns; int dhcp_timeout; - char * dhcp4_vci; + char *dhcp4_vci; gint64 carrier_timeout_sec; } Reader; @@ -55,6 +56,7 @@ reader_new(void) g_hash_table_new_full(nm_direct_hash, NULL, g_object_unref, NULL), .vlan_parents = g_ptr_array_new_with_free_func(g_free), .array = g_ptr_array_new(), + .znet_ifnames = g_hash_table_new_full(nm_str_hash, g_str_equal, g_free, g_free), }; return reader; @@ -70,6 +72,7 @@ reader_destroy(Reader *reader, gboolean free_hash) g_hash_table_unref(reader->explicit_ip_connections); hash = g_steal_pointer(&reader->hash); nm_clear_g_free(&reader->hostname); + g_hash_table_unref(reader->znet_ifnames); nm_clear_g_free(&reader->dhcp4_vci); nm_g_slice_free(reader); if (!free_hash) @@ -91,16 +94,16 @@ reader_add_connection(Reader *reader, const char *name, NMConnection *connection /* Returns a new connection owned by the reader */ static NMConnection * -reader_create_connection(Reader * reader, - const char * basename, - const char * id, - const char * ifname, - const char * mac, - const char * type_name, +reader_create_connection(Reader *reader, + const char *basename, + const char *id, + const char *ifname, + const char *mac, + const char *type_name, NMConnectionMultiConnect multi_connect) { NMConnection *connection; - NMSetting * setting; + NMSetting *setting; connection = reader_add_connection(reader, basename, nm_simple_connection_new()); @@ -195,14 +198,14 @@ reader_get_default_connection(Reader *reader) } static NMConnection * -reader_get_connection(Reader * reader, +reader_get_connection(Reader *reader, const char *iface_spec, const char *type_name, gboolean create_if_missing) { NMConnection *connection = NULL; - NMSetting * setting; - const char * ifname = NULL; + NMSetting *setting; + const char *ifname = NULL; gs_free char *mac = NULL; if (iface_spec) { @@ -216,7 +219,7 @@ reader_get_connection(Reader * reader, } if (!ifname && !mac) { - NMConnection * candidate; + NMConnection *candidate; NMSettingConnection *s_con; guint i; @@ -314,14 +317,14 @@ get_word(char **argument, const char separator) static void connection_set(NMConnection *connection, - const char * setting_name, - const char * property, - const char * value) + const char *setting_name, + const char *property, + const char *value) { - NMSetting * setting; - GType setting_type; + NMSetting *setting; + GType setting_type; nm_auto_unref_gtypeclass GObjectClass *object_class = NULL; - GParamSpec * spec; + GParamSpec *spec; setting_type = nm_setting_lookup_type(setting_name); object_class = g_type_class_ref(setting_type); @@ -355,20 +358,20 @@ static void reader_read_all_connections_from_fw(Reader *reader, const char *sysfs_dir) { gs_unref_hashtable GHashTable *ibft = NULL; - NMConnection * dt_connection; - const char * mac; - GHashTable * nic; - const char * index; - GError * error = NULL; + NMConnection *dt_connection; + const char *mac; + GHashTable *nic; + const char *index; + GError *error = NULL; guint i, length; - gs_free const char ** keys = NULL; + gs_free const char **keys = NULL; ibft = nmi_ibft_read(sysfs_dir); keys = nm_strdict_get_keys(ibft, TRUE, &length); for (i = 0; i < length; i++) { gs_unref_object NMConnection *connection = NULL; - gs_free char * name = NULL; + gs_free char *name = NULL; mac = keys[i]; nic = g_hash_table_lookup(ibft, mac); @@ -426,7 +429,7 @@ _parse_ip_method(const char *kind) "auto", "ibft", }; - gs_free char * kind_to_free = NULL; + gs_free char *kind_to_free = NULL; gs_free const char **strv = NULL; gsize i; @@ -512,26 +515,26 @@ _parse_ip_method(const char *kind) static void reader_parse_ip(Reader *reader, const char *sysfs_dir, char *argument) { - NMConnection * connection; - NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4 = NULL, *s_ip6 = NULL; + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4 = NULL, *s_ip6 = NULL; gs_unref_hashtable GHashTable *ibft = NULL; - const char * tmp; - const char * tmp2; - const char * tmp3; - const char * kind; - const char * client_ip = NULL; - const char * peer = NULL; - const char * gateway_ip = NULL; - const char * netmask = NULL; - const char * client_hostname = NULL; - const char * iface_spec = NULL; - const char * mtu = NULL; - const char * macaddr = NULL; + const char *tmp; + const char *tmp2; + const char *tmp3; + const char *kind; + const char *client_ip = NULL; + const char *peer = NULL; + const char *gateway_ip = NULL; + const char *netmask = NULL; + const char *client_hostname = NULL; + const char *iface_spec = NULL; + const char *mtu = NULL; + const char *macaddr = NULL; int client_ip_family = AF_UNSPEC; int client_ip_prefix = -1; gboolean clear_ip4_required_timeout = TRUE; - const char * dns[2] = { + const char *dns[2] = { NULL, NULL, }; @@ -770,11 +773,11 @@ reader_parse_ip(Reader *reader, const char *sysfs_dir, char *argument) } } else if (nm_streq(kind, "ibft")) { NMSettingWired *s_wired; - const char * mac = NULL; - const char * ifname; - gs_free char * mac_free = NULL; - gs_free char * address_path = NULL; - GHashTable * nic = NULL; + const char *mac = NULL; + const char *ifname; + gs_free char *mac_free = NULL; + gs_free char *address_path = NULL; + GHashTable *nic = NULL; if ((s_wired = nm_connection_get_setting_wired(connection)) && (mac = nm_setting_wired_get_mac_address(s_wired))) { @@ -857,14 +860,14 @@ reader_parse_ip(Reader *reader, const char *sysfs_dir, char *argument) static void reader_parse_master(Reader *reader, char *argument, const char *type_name, const char *default_name) { - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - gs_free char * master_to_free = NULL; - const char * master; - char * slaves; - const char * slave; - char * opts; - const char * mtu = NULL; + gs_free char *master_to_free = NULL; + const char *master; + char *slaves; + const char *slave; + char *opts; + const char *mtu = NULL; master = get_word(&argument, ':'); if (!master) @@ -886,8 +889,8 @@ reader_parse_master(Reader *reader, char *argument, const char *type_name, const opts = get_word(&argument, ':'); while (opts && *opts) { gs_free_error GError *error = NULL; - char * opt; - const char * opt_name; + char *opt; + const char *opt_name; opt = get_word(&opts, ','); opt_name = get_word(&opt, '='); @@ -934,17 +937,17 @@ reader_add_routes(Reader *reader, GPtrArray *array) guint i; for (i = 0; i < array->len; i++) { - NMConnection * connection = NULL; - const char * net; - const char * gateway; - const char * interface; - int family = AF_UNSPEC; - NMIPAddr net_addr = {}; - NMIPAddr gateway_addr = {}; - int net_prefix = -1; - NMIPRoute * route; - NMSettingIPConfig *s_ip; - char * argument; + NMConnection *connection = NULL; + const char *net; + const char *gateway; + const char *interface; + int family = AF_UNSPEC; + NMIPAddr net_addr = {}; + NMIPAddr gateway_addr = {}; + int net_prefix = -1; + NMIPRoute *route; + NMSettingIPConfig *s_ip; + char *argument; gs_free_error GError *error = NULL; argument = array->pdata[i]; @@ -1010,11 +1013,11 @@ reader_add_routes(Reader *reader, GPtrArray *array) static void reader_parse_vlan(Reader *reader, char *argument) { - NMConnection * connection; + NMConnection *connection; NMSettingVlan *s_vlan; - const char * vlan; - const char * phy; - const char * vlanid; + const char *vlan; + const char *phy; + const char *vlanid; vlan = get_word(&argument, ':'); phy = get_word(&argument, ':'); @@ -1044,11 +1047,11 @@ reader_parse_vlan(Reader *reader, char *argument) static void reader_parse_ib_pkey(Reader *reader, char *argument) { - NMConnection * connection; + NMConnection *connection; NMSettingInfiniband *s_ib; - char * ifname; - gs_free char * parent = NULL; - char * pkey; + char *ifname; + gs_free char *parent = NULL; + char *pkey; gint64 pkey_int; /* At the moment we only support ib.pkey=.; @@ -1091,19 +1094,36 @@ reader_parse_ib_pkey(Reader *reader, char *argument) _LOGW(LOGD_CORE, "Ignoring extra: '%s' for ib.pkey=", argument); } +static void +reader_parse_znet_ifname(Reader *reader, char *argument) +{ + char *ifname; + + ifname = get_word(&argument, ':'); + if (!ifname) { + _LOGW(LOGD_CORE, "rd.znet_ifname= without argument"); + return; + } + + if (!g_hash_table_replace(reader->znet_ifnames, g_strdup(argument), g_strdup(ifname))) { + _LOGW(LOGD_CORE, "duplicate rd.znet_ifname for ifname=%s", ifname); + } +} + static void reader_parse_rd_znet(Reader *reader, char *argument, gboolean net_ifnames) { - const char * nettype; - const char * subchannels[4] = {0, 0, 0, 0}; - const char * tmp; - gs_free char * ifname = NULL; - const char * prefix; - NMConnection * connection; + const char *nettype; + const char *subchannels[4] = {0, 0, 0, 0}; + const char *tmp; + gs_free char *ifname = NULL; + gs_free char *str_subchannels = NULL; + const char *prefix; + NMConnection *connection; NMSettingWired *s_wired; static int count_ctc = 0; static int count_eth = 0; - int index; + int index = -1; nettype = get_word(&argument, ','); subchannels[0] = get_word(&argument, ','); @@ -1131,7 +1151,13 @@ reader_parse_rd_znet(Reader *reader, char *argument, gboolean net_ifnames) } } - if (net_ifnames == TRUE) { + str_subchannels = g_strjoinv(",", (char **) subchannels); + ifname = g_hash_table_lookup(reader->znet_ifnames, str_subchannels); + + if (ifname) { + ifname = g_strdup(ifname); + g_hash_table_remove(reader->znet_ifnames, str_subchannels); + } else if (net_ifnames == TRUE) { const char *bus_id; size_t bus_id_len; size_t bus_id_start; @@ -1144,6 +1170,7 @@ reader_parse_rd_znet(Reader *reader, char *argument, gboolean net_ifnames) ifname = g_strdup_printf("%sc%s", prefix, bus_id); } else { + nm_assert(index > -1); ifname = g_strdup_printf("%s%d", prefix, index); } @@ -1160,7 +1187,7 @@ reader_parse_rd_znet(Reader *reader, char *argument, gboolean net_ifnames) while ((tmp = get_word(&argument, ',')) != NULL) { const char *key; - char * val; + char *val; val = strchr(tmp, '='); if (!val) { @@ -1184,11 +1211,11 @@ reader_parse_rd_znet(Reader *reader, char *argument, gboolean net_ifnames) static void reader_parse_ethtool(Reader *reader, char *argument) { - NMConnection * connection; + NMConnection *connection; NMSettingWired *s_wired; - const char * autoneg_str; - const char * speed_str; - const char * interface; + const char *autoneg_str; + const char *speed_str; + const char *interface; int autoneg; guint speed; @@ -1251,11 +1278,11 @@ _normalize_conn(gpointer key, gpointer value, gpointer user_data) static void reader_add_nameservers(Reader *reader, GPtrArray *nameservers) { - NMConnection * connection; + NMConnection *connection; NMSettingIPConfig *s_ip; GHashTableIter iter; int addr_family; - const char * ns; + const char *ns; guint i; for (i = 0; i < nameservers->len; i++) { @@ -1316,21 +1343,22 @@ connection_set_needed_cb(gpointer key, gpointer value, gpointer user_data) } GHashTable * -nmi_cmdline_reader_parse(const char * sysfs_dir, +nmi_cmdline_reader_parse(const char *etc_connections_dir, + const char *sysfs_dir, const char *const *argv, - char ** hostname, - gint64 * carrier_timeout_sec) + char **hostname, + gint64 *carrier_timeout_sec) { - Reader * reader; - const char * tag; - gboolean ignore_bootif = FALSE; - gboolean neednet = FALSE; - gs_free char * bootif_val = NULL; - gs_free char * bootdev = NULL; - gboolean net_ifnames = TRUE; - gs_unref_ptrarray GPtrArray *nameservers = NULL; - gs_unref_ptrarray GPtrArray *routes = NULL; - gs_unref_ptrarray GPtrArray *znets = NULL; + Reader *reader; + const char *tag; + gboolean ignore_bootif = FALSE; + gboolean neednet = FALSE; + gs_free char *bootif_val = NULL; + gs_free char *bootdev = NULL; + gboolean net_ifnames = TRUE; + gs_unref_ptrarray GPtrArray *nameservers = NULL; + gs_unref_ptrarray GPtrArray *routes = NULL; + gs_unref_ptrarray GPtrArray *znets = NULL; int i; guint64 dhcp_timeout = 90; guint64 dhcp_num_tries = 1; @@ -1339,7 +1367,7 @@ nmi_cmdline_reader_parse(const char * sysfs_dir, for (i = 0; argv[i]; i++) { gs_free char *argument_clone = NULL; - char * argument; + char *argument; argument_clone = g_strdup(argv[i]); argument = argument_clone; @@ -1375,8 +1403,8 @@ nmi_cmdline_reader_parse(const char * sysfs_dir, for (i = 0; argv[i]; i++) { gs_free char *argument_clone = NULL; - char * argument; - char * word; + char *argument; + char *word; argument_clone = g_strdup(argv[i]); argument = argument_clone; @@ -1422,6 +1450,8 @@ nmi_cmdline_reader_parse(const char * sysfs_dir, if (!znets) znets = g_ptr_array_new_with_free_func(g_free); g_ptr_array_add(znets, g_strdup(argument)); + } else if (nm_streq(tag, "rd.znet_ifname")) { + reader_parse_znet_ifname(reader, argument); } else if (g_ascii_strcasecmp(tag, "BOOTIF") == 0) { nm_clear_g_free(&bootif_val); bootif_val = g_strdup(argument); @@ -1430,7 +1460,7 @@ nmi_cmdline_reader_parse(const char * sysfs_dir, } for (i = 0; i < reader->vlan_parents->len; i++) { - NMConnection * connection; + NMConnection *connection; NMSettingIPConfig *s_ip; /* Disable IP configuration for parent connections of VLANs, @@ -1459,9 +1489,9 @@ nmi_cmdline_reader_parse(const char * sysfs_dir, if (ignore_bootif) nm_clear_g_free(&bootif_val); if (bootif_val) { - NMConnection * connection; + NMConnection *connection; NMSettingWired *s_wired; - const char * bootif = bootif_val; + const char *bootif = bootif_val; char prefix[4]; if (!nm_utils_hwaddr_valid(bootif, ETH_ALEN)) { @@ -1512,7 +1542,8 @@ nmi_cmdline_reader_parse(const char * sysfs_dir, } if (neednet) { - if (g_hash_table_size(reader->hash) == 0) { + if (!(etc_connections_dir && g_file_test(etc_connections_dir, G_FILE_TEST_IS_DIR)) + && g_hash_table_size(reader->hash) == 0) { /* Make sure there's some connection. */ reader_get_default_connection(reader); } @@ -1531,6 +1562,10 @@ nmi_cmdline_reader_parse(const char * sysfs_dir, reader_parse_rd_znet(reader, znets->pdata[i], net_ifnames); } + if (g_hash_table_size(reader->znet_ifnames)) { + _LOGW(LOGD_CORE, "Mismatch between rd.znet_ifname and rd.znet"); + } + g_hash_table_foreach(reader->hash, _normalize_conn, NULL); NM_SET_OUT(hostname, g_steal_pointer(&reader->hostname)); diff --git a/src/nm-initrd-generator/nmi-dt-reader.c b/src/nm-initrd-generator/nmi-dt-reader.c index 99c149dc..8bd591a8 100644 --- a/src/nm-initrd-generator/nmi-dt-reader.c +++ b/src/nm-initrd-generator/nmi-dt-reader.c @@ -28,11 +28,11 @@ static gboolean dt_get_property(const char *base, const char *dev, const char *prop, - char ** contents, - size_t * length) + char **contents, + size_t *length) { - gs_free char *filename = g_build_filename(base, dev, prop, NULL); - gs_free_error GError *error = NULL; + gs_free char *filename = g_build_filename(base, dev, prop, NULL); + gs_free_error GError *error = NULL; if (!g_file_test(filename, G_FILE_TEST_EXISTS)) return FALSE; @@ -106,31 +106,31 @@ str_addr(const char *str, int *family) NMConnection * nmi_dt_reader_parse(const char *sysfs_dir) { - gs_unref_object NMConnection *connection = NULL; - gs_free char * base = NULL; - gs_free char * bootpath = NULL; - gs_strfreev char ** tokens = NULL; - char * path = NULL; - gboolean bootp = FALSE; - const char * s_ipaddr = NULL; - const char * s_netmask = NULL; - const char * s_gateway = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_free char *base = NULL; + gs_free char *bootpath = NULL; + gs_strfreev char **tokens = NULL; + char *path = NULL; + gboolean bootp = FALSE; + const char *s_ipaddr = NULL; + const char *s_netmask = NULL; + const char *s_gateway = NULL; nm_auto_unref_ip_address NMIPAddress *ipaddr = NULL; nm_auto_unref_ip_address NMIPAddress *gateway = NULL; - const char * duplex = NULL; - gs_free char * hwaddr = NULL; - gs_free char * local_hwaddr = NULL; - gs_free char * hostname = NULL; + const char *duplex = NULL; + gs_free char *hwaddr = NULL; + gs_free char *local_hwaddr = NULL; + gs_free char *hostname = NULL; guint32 speed = 0; int prefix = -1; - NMSettingIPConfig * s_ip = NULL; - NMSetting * s_ip4 = NULL; - NMSetting * s_ip6 = NULL; - NMSetting * s_wired = NULL; + NMSettingIPConfig *s_ip = NULL; + NMSetting *s_ip4 = NULL; + NMSetting *s_ip6 = NULL; + NMSetting *s_wired = NULL; int family = AF_UNSPEC; int i = 0; - char * c; - gs_free_error GError *error = NULL; + char *c; + gs_free_error GError *error = NULL; base = g_build_filename(sysfs_dir, "firmware", "devicetree", "base", NULL); diff --git a/src/nm-initrd-generator/nmi-ibft-reader.c b/src/nm-initrd-generator/nmi-ibft-reader.c index b3db3f01..196bb141 100644 --- a/src/nm-initrd-generator/nmi-ibft-reader.c +++ b/src/nm-initrd-generator/nmi-ibft-reader.c @@ -36,12 +36,12 @@ static GHashTable * load_one_nic(const char *sysfs_dir, const char *dir_name) { - gs_free char *nic_path = g_build_filename(sysfs_dir, dir_name, NULL); - GDir * nic_dir; - const char * entry_name; - char * content; + gs_free char *nic_path = g_build_filename(sysfs_dir, dir_name, NULL); + GDir *nic_dir; + const char *entry_name; + char *content; gs_free_error GError *error = NULL; - GHashTable * nic; + GHashTable *nic; g_return_val_if_fail(sysfs_dir != NULL, FALSE); @@ -77,11 +77,11 @@ load_one_nic(const char *sysfs_dir, const char *dir_name) GHashTable * nmi_ibft_read(const char *sysfs_dir) { - gs_free char *ibft_path = NULL; - GDir * ibft_dir; - const char * dir_name; - GHashTable * ibft, *nic; - char * mac; + gs_free char *ibft_path = NULL; + GDir *ibft_dir; + const char *dir_name; + GHashTable *ibft, *nic; + char *mac; gs_free_error GError *error = NULL; g_return_val_if_fail(sysfs_dir != NULL, FALSE); @@ -133,14 +133,14 @@ ip_setting_add_from_block(GHashTable *nic, NMConnection *connection, GError **er NMSettingIPConfig *s_ip = NULL; NMSettingIPConfig *s_ip4 = NULL; NMSettingIPConfig *s_ip6 = NULL; - NMIPAddress * addr; - const char * s_ipaddr = NULL; - const char * s_prefix = NULL; - const char * s_gateway = NULL; - const char * s_dns1 = NULL; - const char * s_dns2 = NULL; - const char * s_origin = NULL; - const char * method = NULL; + NMIPAddress *addr; + const char *s_ipaddr = NULL; + const char *s_prefix = NULL; + const char *s_gateway = NULL; + const char *s_dns1 = NULL; + const char *s_dns2 = NULL; + const char *s_origin = NULL; + const char *method = NULL; int family; gint64 prefix; @@ -276,14 +276,14 @@ ip_setting_add_from_block(GHashTable *nic, NMConnection *connection, GError **er } static gboolean -connection_setting_add(GHashTable * nic, +connection_setting_add(GHashTable *nic, NMConnection *connection, - const char * type, - const char * prefix, - GError ** error) + const char *type, + const char *prefix, + GError **error) { - NMSetting * s_con; - char * id, *uuid; + NMSetting *s_con; + char *id, *uuid; const char *s_index, *s_hwaddr, *s_ipaddr, *s_vlanid; s_index = (const char *) g_hash_table_lookup(nic, "index"); @@ -359,7 +359,7 @@ is_ibft_vlan_device(GHashTable *nic) static gboolean vlan_setting_add_from_block(GHashTable *nic, NMConnection *connection, GError **error) { - NMSetting * s_vlan = NULL; + NMSetting *s_vlan = NULL; const char *vlan_id_str = NULL; gint64 vlan_id = -1; @@ -397,7 +397,7 @@ vlan_setting_add_from_block(GHashTable *nic, NMConnection *connection, GError ** static gboolean wired_setting_add_from_block(GHashTable *nic, NMConnection *connection, GError **error) { - NMSetting * s_wired = NULL; + NMSetting *s_wired = NULL; const char *hwaddr = NULL; g_assert(nic); diff --git a/src/nm-initrd-generator/tests/test-cmdline-reader.c b/src/nm-initrd-generator/tests/test-cmdline-reader.c index 2cb1b2f4..d7b7b3cb 100644 --- a/src/nm-initrd-generator/tests/test-cmdline-reader.c +++ b/src/nm-initrd-generator/tests/test-cmdline-reader.c @@ -27,9 +27,10 @@ const char *const *const _ARGV = (ARGV); \ char **const _out_hostname = (out_hostname); \ gint64 *const _out_carrier_timeout_sec = (out_carrier_timeout_sec); \ - GHashTable * _connections; \ + GHashTable *_connections; \ \ - _connections = nmi_cmdline_reader_parse(TEST_INITRD_DIR "/sysfs", \ + _connections = nmi_cmdline_reader_parse(NULL, \ + TEST_INITRD_DIR "/sysfs", \ _ARGV, \ _out_hostname, \ _out_carrier_timeout_sec); \ @@ -41,7 +42,7 @@ #define _parse_cons(ARGV) \ ({ \ - GHashTable * _con_connections; \ + GHashTable *_con_connections; \ gs_free char *_con_hostname = NULL; \ gint64 _con_carrier_timeout_sec = 0; \ \ @@ -57,7 +58,7 @@ #define _parse_con(ARGV, connection_name) \ ({ \ gs_unref_hashtable GHashTable *_1_connections = NULL; \ - NMConnection * _1_connection; \ + NMConnection *_1_connection; \ const char *const _1_connection_name = (connection_name); \ \ g_assert(_1_connection_name); \ @@ -89,12 +90,12 @@ static void test_auto(void) { - const char *const *ARGV = NM_MAKE_STRV("ip=auto"); + const char *const *ARGV = NM_MAKE_STRV("ip=auto"); 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 = _parse_con(ARGV, "default_connection"); @@ -140,13 +141,13 @@ static void test_dhcp_with_hostname(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("ip=::::host1::dhcp,dhcp6"); - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - gs_free char * hostname = NULL; + const char *const *ARGV = NM_MAKE_STRV("ip=::::host1::dhcp,dhcp6"); + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + gs_free char *hostname = NULL; gint64 carrier_timeout_sec = 0; connections = _parse(ARGV, &hostname, &carrier_timeout_sec); @@ -198,10 +199,10 @@ test_dhcp_with_mtu(void) for (i = 0; i < G_N_ELEMENTS(ARGV); i++) { 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 = _parse_con(ARGV[i], "default_connection"); @@ -259,9 +260,9 @@ test_dhcp_timeout(void) for (i = 0; i < G_N_ELEMENTS(data); i++) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = _parse_con(data[i].cmdline, "default_connection"); @@ -300,12 +301,12 @@ test_dhcp_timeout(void) static void test_if_auto_with_mtu(void) { - const char *const *ARGV = NM_MAKE_STRV("ip=eth0:dhcp,dhcp6:1666", "="); + const char *const *ARGV = NM_MAKE_STRV("ip=eth0:dhcp,dhcp6:1666", "="); 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 = _parse_con(ARGV, "eth0"); @@ -340,10 +341,10 @@ test_if_auto_with_mtu(void) static void test_if_dhcp6(void) { - const char *const *ARGV = NM_MAKE_STRV("ip=eth1:dhcp6"); + const char *const *ARGV = NM_MAKE_STRV("ip=eth1:dhcp6"); gs_unref_object NMConnection *connection = NULL; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = _parse_con(ARGV, "eth1"); @@ -365,11 +366,11 @@ test_if_dhcp6(void) static void test_if_auto_with_mtu_and_mac(void) { - const char *const *ARGV = NM_MAKE_STRV("ip=eth2:auto6:2048:00:53:ef:12:34:56"); + const char *const *ARGV = NM_MAKE_STRV("ip=eth2:auto6:2048:00:53:ef:12:34:56"); gs_unref_object NMConnection *connection = NULL; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = _parse_con(ARGV, "eth2"); @@ -397,16 +398,16 @@ static void test_if_ip4_manual(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("ip=192.0.2.2::192.0.2.1:255.255.255.0:" - "hostname0.example.com:eth3:none:192.0.2.53", + const char *const *ARGV = NM_MAKE_STRV("ip=192.0.2.2::192.0.2.1:255.255.255.0:" + "hostname0.example.com:eth3:none:192.0.2.53", "ip=203.0.113.2::203.0.113.1:26:" - "hostname1.example.com:eth4"); - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMIPAddress * ip_addr; - gs_free char * hostname = NULL; + "hostname1.example.com:eth4"); + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMIPAddress *ip_addr; + gs_free char *hostname = NULL; gint64 carrier_timeout_sec = 0; connections = _parse(ARGV, &hostname, &carrier_timeout_sec); @@ -477,12 +478,12 @@ test_if_ip4_manual(void) static void test_if_ip4_manual_no_dev(void) { - const char *const * ARGV = NM_MAKE_STRV("ip=192.0.2.2::192.0.2.1:24:::", "=foo"); - NMConnection * connection; + const char *const *ARGV = NM_MAKE_STRV("ip=192.0.2.2::192.0.2.1:24:::", "=foo"); + NMConnection *connection; NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMIPAddress * ip_addr; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMIPAddress *ip_addr; connection = _parse_con(ARGV, "default_connection"); g_assert_cmpstr(nm_connection_get_id(connection), ==, "Wired Connection"); @@ -518,12 +519,12 @@ static void test_if_ip6_manual(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("ip=[2001:0db8::02]/64::[2001:0db8::01]::" - "hostname0.example.com:eth4::[2001:0db8::53]"); - NMConnection * connection; - NMSettingIPConfig * s_ip6; - NMIPAddress * ip_addr; - gs_free char * hostname = NULL; + const char *const *ARGV = NM_MAKE_STRV("ip=[2001:0db8::02]/64::[2001:0db8::01]::" + "hostname0.example.com:eth4::[2001:0db8::53]"); + NMConnection *connection; + NMSettingIPConfig *s_ip6; + NMIPAddress *ip_addr; + gs_free char *hostname = NULL; gint64 carrier_timeout_sec = 0; connections = _parse(ARGV, &hostname, &carrier_timeout_sec); @@ -557,13 +558,13 @@ static void test_if_off(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("ip=off", + const char *const *ARGV = NM_MAKE_STRV("ip=off", "ip=ens3:off", "ip=10.0.0.8:::::ens4:off", "ip=[2001:DB8::8]:::::ens5:off"); - NMConnection * connection; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMConnection *connection; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; struct { const char name[32]; const char ipv4_method[32]; @@ -599,13 +600,13 @@ static void test_if_mac_ifname(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("ip=[2001:0db8::42]/64::[2001:0db8::01]::" - "hostname0:00-11-22-33-44-55::[2001:0db8::53]"); - NMConnection * connection; - NMSettingIPConfig * s_ip6; - NMSettingWired * s_wired; - NMIPAddress * ip_addr; - gs_free char * hostname = NULL; + const char *const *ARGV = NM_MAKE_STRV("ip=[2001:0db8::42]/64::[2001:0db8::01]::" + "hostname0:00-11-22-33-44-55::[2001:0db8::53]"); + NMConnection *connection; + NMSettingIPConfig *s_ip6; + NMSettingWired *s_wired; + NMIPAddress *ip_addr; + gs_free char *hostname = NULL; gint64 carrier_timeout_sec = 0; connections = _parse(ARGV, &hostname, &carrier_timeout_sec); @@ -646,11 +647,11 @@ test_multiple_merge(void) const char *const *ARGV = NM_MAKE_STRV("ip=192.0.2.2/16:::::eth0", "ip=[2001:db8::2]:::56::eth0"); gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMIPAddress * ip_addr; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMIPAddress *ip_addr; connection = _parse_con(ARGV, "eth0"); @@ -699,10 +700,10 @@ test_multiple_bootdev(void) "ip=eth5:link6", "bootdev=eth4"); - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 3); @@ -745,9 +746,9 @@ static void test_bootdev(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("vlan=vlan2:ens5", "bootdev=ens3"); - NMConnection * connection; - NMSettingConnection * s_con; + const char *const *ARGV = NM_MAKE_STRV("vlan=vlan2:ens5", "bootdev=ens3"); + NMConnection *connection; + NMSettingConnection *s_con; connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 3); @@ -793,7 +794,7 @@ static void test_some_more(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("bootdev=eth1", + const char *const *ARGV = NM_MAKE_STRV("bootdev=eth1", "hail", "nameserver=[2001:DB8:3::53]", "satan", @@ -802,12 +803,12 @@ test_some_more(void) "doom", "rd.peerdns=0", "rd.route=[2001:DB8:3::/48]:[2001:DB8:2::1]:ens10"); - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMIPRoute * ip_route; + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMIPRoute *ip_route; connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 2); @@ -883,17 +884,17 @@ static void test_bond(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("rd.route=192.0.2.53::bong0", + const char *const *ARGV = NM_MAKE_STRV("rd.route=192.0.2.53::bong0", "bond=bong0:eth0,eth1:mode=balance-rr:9000", "nameserver=203.0.113.53"); - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSettingBond * s_bond; - NMSettingWired * s_wired; - NMIPRoute * ip_route; - const char * master_uuid; + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingBond *s_bond; + NMSettingWired *s_wired; + NMIPRoute *ip_route; + const char *master_uuid; connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 3); @@ -976,18 +977,18 @@ static void test_bond_ip(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = + const char *const *ARGV = NM_MAKE_STRV("bond=bond0:eth0,eth1", "ip=192.168.1.1::192.168.1.254:24::bond0:none:1480:01:02:03:04:05:06", "nameserver=4.8.15.16"); - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSettingWired * s_wired; - NMSettingBond * s_bond; - NMIPAddress * ip_addr; - const char * master_uuid; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingWired *s_wired; + NMSettingBond *s_bond; + NMIPAddress *ip_addr; + const char *master_uuid; connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 3); @@ -1073,13 +1074,13 @@ static void test_bond_default(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("bond"); - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSettingBond * s_bond; - const char * master_uuid; + const char *const *ARGV = NM_MAKE_STRV("bond"); + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingBond *s_bond; + const char *master_uuid; connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 2); @@ -1136,16 +1137,16 @@ static void test_bridge(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("bridge=bridge0:eth0,eth1", + const char *const *ARGV = NM_MAKE_STRV("bridge=bridge0:eth0,eth1", "rd.route=192.0.2.53::bridge0", "rd.net.timeout.dhcp=10"); - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSettingBridge * s_bridge; - NMIPRoute * ip_route; - const char * master_uuid; + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingBridge *s_bridge; + NMIPRoute *ip_route; + const char *master_uuid; connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 3); @@ -1232,13 +1233,13 @@ static void test_bridge_default(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("bridge"); - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSettingBridge * s_bridge; - const char * master_uuid; + const char *const *ARGV = NM_MAKE_STRV("bridge"); + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingBridge *s_bridge; + const char *master_uuid; connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 2); @@ -1295,16 +1296,16 @@ static void test_bridge_ip(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = + const char *const *ARGV = NM_MAKE_STRV("ip=bridge123:auto:1280:00:11:22:33:CA:fe", "bridge=bridge123:eth0,eth1,eth2,eth3,eth4,eth5,eth6,eth7,eth8,eth9"); - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSettingWired * s_wired; - NMSettingBridge * s_bridge; - const char * master_uuid; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingWired *s_wired; + NMSettingBridge *s_bridge; + const char *master_uuid; guint i; connections = _parse_cons(ARGV); @@ -1364,13 +1365,13 @@ static void test_team(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("team=team0:eth0,eth1", "ip=team0:dhcp6"); - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSettingTeam * s_team; - const char * master_uuid; + const char *const *ARGV = NM_MAKE_STRV("team=team0:eth0,eth1", "ip=team0:dhcp6"); + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingTeam *s_team; + const char *master_uuid; connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 3); @@ -1448,10 +1449,10 @@ test_vlan(void) for (i = 0; i < G_N_ELEMENTS(ARGV); i++) { gs_unref_hashtable GHashTable *connections = NULL; - NMConnection * connection; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSettingVlan * s_vlan; + NMConnection *connection; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingVlan *s_vlan; connections = _parse_cons(ARGV[i]); g_assert_cmpint(g_hash_table_size(connections), ==, 2); @@ -1513,10 +1514,10 @@ test_vlan_with_dhcp_on_parent(void) for (i = 0; i < G_N_ELEMENTS(ARGV); i++) { gs_unref_hashtable GHashTable *connections = NULL; - NMConnection * connection; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSettingVlan * s_vlan; + NMConnection *connection; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingVlan *s_vlan; connections = _parse_cons(ARGV[i]); g_assert_cmpint(g_hash_table_size(connections), ==, 2); @@ -1585,10 +1586,10 @@ test_vlan_over_bond(void) for (i = 0; i < G_N_ELEMENTS(ARGV); i++) { gs_unref_hashtable GHashTable *connections = NULL; - NMConnection * connection; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMSettingVlan * s_vlan; + NMConnection *connection; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingVlan *s_vlan; connections = _parse_cons(ARGV[i]); g_assert_cmpint(g_hash_table_size(connections), ==, 4); @@ -1649,8 +1650,8 @@ test_vlan_over_bond(void) static void test_ibft_ip_dev(void) { - const char *const * ARGV = NM_MAKE_STRV("ip=eth0:ibft"); - NMSettingConnection *s_con; + const char *const *ARGV = NM_MAKE_STRV("ip=eth0:ibft"); + NMSettingConnection *s_con; gs_unref_object NMConnection *connection = NULL; connection = _parse_con(ARGV, "eth0"); @@ -1666,8 +1667,8 @@ test_ibft_ip_dev(void) static void test_ibft_ip_dev_mac(void) { - const char *const * ARGV = NM_MAKE_STRV("ip=00-53-06-66-ab-01:ibft"); - NMSettingConnection *s_con; + const char *const *ARGV = NM_MAKE_STRV("ip=00-53-06-66-ab-01:ibft"); + NMSettingConnection *s_con; gs_unref_object NMConnection *connection = NULL; connection = _parse_con(ARGV, "00:53:06:66:AB:01"); @@ -1684,7 +1685,7 @@ static void _test_ibft_ip(const char *const *ARGV) { gs_unref_hashtable GHashTable *connections = NULL; - NMConnection * connection; + NMConnection *connection; connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 2); @@ -1721,7 +1722,7 @@ static void test_ignore_extra(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("blabla", "extra", "lalala"); + const char *const *ARGV = NM_MAKE_STRV("blabla", "extra", "lalala"); connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 0); @@ -1736,10 +1737,10 @@ test_rd_znet(void) "ip=slc600:dhcp", "rd.znet=qeth,0.0.0800,0.0.0801,0.0.0802,layer2=0,portno=1", "rd.znet=ctc,0.0.0600,0.0.0601,layer2=0,portno=0"); - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWired * s_wired; - const char *const * v_subchannels; + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + const char *const *v_subchannels; const NMUtilsNamedValue s390_options[] = { {.name = "layer2", .value_str = "0"}, {.name = "portno", .value_str = "1"}, @@ -1778,9 +1779,9 @@ test_rd_znet(void) for (i_s390_options_keys = 0; i_s390_options_keys < G_N_ELEMENTS(s390_options); i_s390_options_keys++) { const NMUtilsNamedValue *s390_option = &s390_options[i_s390_options_keys]; - const char * k; - const char * v; - const char * v2; + const char *k; + const char *v; + const char *v2; g_assert(s390_option->name); g_assert(s390_option->value_str); @@ -1830,9 +1831,9 @@ test_rd_znet_legacy(void) "rd.znet=ctc,0.0.0600,0.0.0601,layer2=0,portno=0", "ip=ctc0:dhcp", "net.ifnames=0"); - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - gs_free char * hostname = NULL; + gs_free char *hostname = NULL; gint64 carrier_timeout_sec = 0; connections = _parse(ARGV, &hostname, &carrier_timeout_sec); @@ -1896,14 +1897,83 @@ test_rd_znet_malformed(void) } } +static void +test_rd_znet_ifnames(void) +{ + gs_unref_hashtable GHashTable *connections = NULL; + const char *const *const ARGV = + NM_MAKE_STRV("rd.znet_ifname=zeth1:0.0.0600,0.0.0601", + "rd.znet=qeth,0.0.0800,0.0.0801,0.0.0802,layer2=0,portno=1,foo", + "rd.znet=ctc,0.0.0600,0.0.0601", + "rd.znet_ifname=zeth0:0.0.0800,0.0.0801,0.0.0802", + "ip=zeth0:dhcp", + "ip=zeth1:dhcp"); + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + gs_free char *hostname = NULL; + gint64 carrier_timeout_sec = 0; + const char *const *v_subchannels; + + connections = _parse(ARGV, &hostname, &carrier_timeout_sec); + g_assert_cmpint(g_hash_table_size(connections), ==, 2); + + connection = g_hash_table_lookup(connections, "zeth0"); + g_assert(NM_IS_CONNECTION(connection)); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(NM_IS_SETTING_CONNECTION(s_con)); + g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), + ==, + NM_SETTING_WIRED_SETTING_NAME); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "zeth0"); + g_assert_cmpstr(nm_setting_connection_get_interface_name(s_con), ==, "zeth0"); + + s_wired = nm_connection_get_setting_wired(connection); + g_assert_cmpstr(nm_setting_wired_get_s390_nettype(s_wired), ==, "qeth"); + g_assert(s_wired); + + v_subchannels = nm_setting_wired_get_s390_subchannels(s_wired); + g_assert(v_subchannels); + g_assert_cmpstr(v_subchannels[0], ==, "0.0.0800"); + g_assert_cmpstr(v_subchannels[1], ==, "0.0.0801"); + g_assert_cmpstr(v_subchannels[2], ==, "0.0.0802"); + g_assert_cmpstr(v_subchannels[3], ==, NULL); + + nmtst_assert_connection_verifies_without_normalization(connection); + + connection = g_hash_table_lookup(connections, "zeth1"); + g_assert(NM_IS_CONNECTION(connection)); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(NM_IS_SETTING_CONNECTION(s_con)); + g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), + ==, + NM_SETTING_WIRED_SETTING_NAME); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "zeth1"); + g_assert_cmpstr(nm_setting_connection_get_interface_name(s_con), ==, "zeth1"); + + s_wired = nm_connection_get_setting_wired(connection); + g_assert_cmpstr(nm_setting_wired_get_s390_nettype(s_wired), ==, "ctc"); + g_assert(s_wired); + + v_subchannels = nm_setting_wired_get_s390_subchannels(s_wired); + g_assert(v_subchannels); + g_assert_cmpstr(v_subchannels[0], ==, "0.0.0600"); + g_assert_cmpstr(v_subchannels[1], ==, "0.0.0601"); + g_assert_cmpstr(v_subchannels[2], ==, NULL); + + nmtst_assert_connection_verifies_without_normalization(connection); +} + static void test_bootif_ip(void) { - const char *const *ARGV = NM_MAKE_STRV("BOOTIF=00:53:AB:cd:02:03", "ip=dhcp"); + const char *const *ARGV = NM_MAKE_STRV("BOOTIF=00:53:AB:cd:02:03", "ip=dhcp"); gs_unref_object NMConnection *connection = NULL; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = _parse_con(ARGV, "default_connection"); @@ -1928,11 +1998,11 @@ test_bootif_ip(void) static void test_neednet_no_args(void) { - const char *const *ARGV = NM_MAKE_STRV("rd.neednet"); + const char *const *ARGV = NM_MAKE_STRV("rd.neednet"); gs_unref_object NMConnection *connection = NULL; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = _parse_con(ARGV, "default_connection"); @@ -1960,12 +2030,12 @@ static void test_neednet_args(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("rd.neednet", + const char *const *ARGV = NM_MAKE_STRV("rd.neednet", "ip=eno1:dhcp", "ip=172.25.1.100::172.25.1.1:24::eno2", "bridge=br0:eno3"); - NMConnection * connection; - NMSettingConnection * s_con; + NMConnection *connection; + NMSettingConnection *s_con; connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 4); @@ -2008,11 +2078,11 @@ test_neednet_args(void) static void test_bootif_no_ip(void) { - const char *const *ARGV = NM_MAKE_STRV("BOOTIF=00:53:AB:cd:02:03"); + const char *const *ARGV = NM_MAKE_STRV("BOOTIF=00:53:AB:cd:02:03"); gs_unref_object NMConnection *connection = NULL; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connection = _parse_con(ARGV, "default_connection"); @@ -2043,10 +2113,10 @@ test_bootif_hwtype(void) for (i = 0; i < G_N_ELEMENTS(ARGV); i++) { gs_unref_hashtable GHashTable *connections = NULL; - NMConnection * connection; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMConnection *connection; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connections = _parse_cons(ARGV[i]); g_assert_cmpint(g_hash_table_size(connections), ==, 2); @@ -2108,16 +2178,16 @@ static void test_nameserver(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = + const char *const *ARGV = NM_MAKE_STRV("nameserver=1.1.1.1", "ip=eth0:dhcp", "ip=eth1:auto6", "ip=10.11.12.13::10.11.12.1:24:foo.example.com:eth2:none", "nameserver=1.0.0.1", "nameserver=[2606:4700:4700::1111]"); - NMConnection * connection; + NMConnection *connection; NMSettingIPConfig *s_ip; - gs_free char * hostname = NULL; + gs_free char *hostname = NULL; gint64 carrier_timeout_sec = 0; connections = _parse(ARGV, &hostname, &carrier_timeout_sec); @@ -2165,10 +2235,10 @@ test_bootif_off(void) static void test_dhcp_vendor_class_id(void) { - const char *const *ARGV; + const char *const *ARGV; gs_unref_object NMConnection *connection = NULL; - NMSettingIP4Config * s_ip4; - gs_free char * vci_long = NULL; + NMSettingIP4Config *s_ip4; + gs_free char *vci_long = NULL; char vci_arg_long[512] = {0}; ARGV = NM_MAKE_STRV("rd.net.dhcp.vendor-class=testvci", "ip=eno1:dhcp"); @@ -2196,9 +2266,9 @@ test_dhcp_vendor_class_id(void) static void test_infiniband_iface(void) { - const char *const *ARGV = NM_MAKE_STRV("ip=ib1:dhcp"); + const char *const *ARGV = NM_MAKE_STRV("ip=ib1:dhcp"); gs_unref_object NMConnection *connection = NULL; - NMSettingInfiniband * s_ib; + NMSettingInfiniband *s_ib; connection = _parse_con(ARGV, "ib1"); @@ -2215,7 +2285,7 @@ test_infiniband_mac(void) const char *const *ARGV = NM_MAKE_STRV("ip=00-11-22-33-44-55-66-77-88-99-aa-bb-cc-dd-ee-ff-00-11-22-33:dhcp"); gs_unref_object NMConnection *connection = NULL; - NMSettingInfiniband * s_ib; + NMSettingInfiniband *s_ib; connection = _parse_con(ARGV, "00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33"); @@ -2233,12 +2303,12 @@ test_infiniband_mac(void) static void test_infiniband_pkey(void) { - const char *const *const ARGV = NM_MAKE_STRV("ib.pkey=ib0.8004", "ip=ib0.8004:dhcp"); + const char *const *const ARGV = NM_MAKE_STRV("ib.pkey=ib0.8004", "ip=ib0.8004:dhcp"); gs_unref_hashtable GHashTable *connections = NULL; - NMConnection * connection; - NMSettingInfiniband * s_ib; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; + NMConnection *connection; + NMSettingInfiniband *s_ib; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; connections = _parse_cons(ARGV); g_assert_cmpint(g_hash_table_size(connections), ==, 1); @@ -2268,8 +2338,8 @@ static void test_carrier_timeout(void) { gs_unref_hashtable GHashTable *connections = NULL; - const char *const * ARGV = NM_MAKE_STRV("rd.net.timeout.carrier=20"); - gs_free char * hostname = NULL; + const char *const *ARGV = NM_MAKE_STRV("rd.net.timeout.carrier=20"); + gs_free char *hostname = NULL; gint64 carrier_timeout_sec = 0; connections = _parse(ARGV, &hostname, &carrier_timeout_sec); @@ -2295,7 +2365,7 @@ test_carrier_timeout(void) G_STMT_START \ { \ gs_unref_object NMConnection *_connection = NULL; \ - NMSettingWired * _s_wired; \ + NMSettingWired *_s_wired; \ typeof(speed) _speed = speed; \ \ _connection = _parse_con(strv, "eth0"); \ @@ -2482,6 +2552,7 @@ main(int argc, char **argv) g_test_add_func("/initrd/cmdline/rd_znet/legacy", test_rd_znet_legacy); g_test_add_func("/initrd/cmdline/rd_znet/no_ip", test_rd_znet_no_ip); g_test_add_func("/initrd/cmdline/rd_znet/empty", test_rd_znet_malformed); + g_test_add_func("/initrd/cmdline/rd_znet/ifnames", test_rd_znet_ifnames); g_test_add_func("/initrd/cmdline/bootif/ip", test_bootif_ip); g_test_add_func("/initrd/cmdline/bootif/no_ip", test_bootif_no_ip); g_test_add_func("/initrd/cmdline/bootif/hwtype", test_bootif_hwtype); diff --git a/src/nm-initrd-generator/tests/test-dt-reader.c b/src/nm-initrd-generator/tests/test-dt-reader.c index c1c28e06..e194646d 100644 --- a/src/nm-initrd-generator/tests/test-dt-reader.c +++ b/src/nm-initrd-generator/tests/test-dt-reader.c @@ -25,12 +25,12 @@ static void test_read_dt_ofw(void) { - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - const char * mac_address; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + const char *mac_address; connection = nmi_dt_reader_parse(TEST_INITRD_DIR "/sysfs-dt"); g_assert(connection); @@ -69,12 +69,12 @@ test_read_dt_ofw(void) static void test_read_dt_slof(void) { - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - NMIPAddress * ip4_addr; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMIPAddress *ip4_addr; connection = nmi_dt_reader_parse(TEST_INITRD_DIR "/sysfs-dt-tftp"); g_assert(connection); diff --git a/src/nm-initrd-generator/tests/test-ibft-reader.c b/src/nm-initrd-generator/tests/test-ibft-reader.c index 0d437519..55925a9a 100644 --- a/src/nm-initrd-generator/tests/test-ibft-reader.c +++ b/src/nm-initrd-generator/tests/test-ibft-reader.c @@ -25,10 +25,10 @@ static NMConnection * read_connection(const char *sysfs_dir, const char *expected_mac, GError **error) { - NMConnection * connection = NULL; - gs_unref_hashtable GHashTable *ibft = NULL; - gs_free char * mac = NULL; - GHashTable * nic = NULL; + NMConnection *connection = NULL; + gs_unref_hashtable GHashTable *ibft = NULL; + gs_free char *mac = NULL; + GHashTable *nic = NULL; ibft = nmi_ibft_read(sysfs_dir); @@ -48,14 +48,14 @@ read_connection(const char *sysfs_dir, const char *expected_mac, GError **error) static void test_read_ibft_dhcp(void) { - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - GError * error = NULL; - const char * mac_address; - const char * expected_mac_address = "00:33:21:98:b9:f1"; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + GError *error = NULL; + const char *mac_address; + const char *expected_mac_address = "00:33:21:98:b9:f1"; connection = read_connection(TEST_INITRD_DIR "/sysfs-dhcp", expected_mac_address, &error); g_assert_no_error(error); @@ -96,15 +96,15 @@ test_read_ibft_dhcp(void) static void test_read_ibft_static(void) { - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingIPConfig * s_ip4; - NMSettingIPConfig * s_ip6; - GError * error = NULL; - const char * mac_address; - const char * expected_mac_address = "00:33:21:98:b9:f0"; - NMIPAddress * ip4_addr; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + GError *error = NULL; + const char *mac_address; + const char *expected_mac_address = "00:33:21:98:b9:f0"; + NMIPAddress *ip4_addr; connection = read_connection(TEST_INITRD_DIR "/sysfs-static", expected_mac_address, &error); g_assert_no_error(error); @@ -159,9 +159,9 @@ test_read_ibft_static(void) static void test_read_ibft_bad_address(gconstpointer user_data) { - const char * sysfs_dir = user_data; + const char *sysfs_dir = user_data; NMConnection *connection; - GError * error = NULL; + GError *error = NULL; g_assert(g_file_test(sysfs_dir, G_FILE_TEST_EXISTS)); @@ -174,15 +174,15 @@ test_read_ibft_bad_address(gconstpointer user_data) static void test_read_ibft_vlan(void) { - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - NMSettingWired * s_wired; - NMSettingVlan * s_vlan; - NMSettingIPConfig * s_ip4; - const char * mac_address; - const char * expected_mac_address = "00:33:21:98:b9:f0"; - NMIPAddress * ip4_addr; - GError * error = NULL; + NMSettingWired *s_wired; + NMSettingVlan *s_vlan; + NMSettingIPConfig *s_ip4; + const char *mac_address; + const char *expected_mac_address = "00:33:21:98:b9:f0"; + NMIPAddress *ip4_addr; + GError *error = NULL; connection = read_connection(TEST_INITRD_DIR "/sysfs-vlan", expected_mac_address, &error); g_assert_no_error(error); @@ -231,10 +231,10 @@ test_read_ibft_vlan(void) static void test_read_ibft(void) { - NMConnection * connection; + NMConnection *connection; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - GError * error = NULL; + GError *error = NULL; /* This test doesn't actually test too much (apart from the presence of * IPv6 that is not covered by other tests), but the test fixture is a good diff --git a/src/nm-online/nm-online.c b/src/nm-online/nm-online.c index 6c807a60..340c2d19 100644 --- a/src/nm-online/nm-online.c +++ b/src/nm-online/nm-online.c @@ -34,8 +34,8 @@ #define EXIT_FAILURE_UNSPECIFIED 43 typedef struct { - GMainLoop * loop; - NMClient * client; + GMainLoop *loop; + NMClient *client; GCancellable *client_new_cancellable; guint client_new_timeout_id; guint handle_timeout_id; @@ -139,7 +139,7 @@ client_properties_changed(GObject *object, GParamSpec *pspec, gpointer user_data static gboolean handle_timeout(gpointer user_data) { - OnlineData * data = user_data; + OnlineData *data = user_data; const gint64 now = _now_ms(); gint64 remaining_ms = data->end_timestamp_ms - now; const gint64 elapsed_ms = now - data->start_timestamp_ms; @@ -194,7 +194,7 @@ got_client_timeout(gpointer user_data) static void got_client(GObject *source_object, GAsyncResult *res, gpointer user_data) { - OnlineData * data = user_data; + OnlineData *data = user_data; gs_free_error GError *error = NULL; nm_assert(NM_IS_CLIENT(source_object)); diff --git a/src/nm-priv-helper/meson.build b/src/nm-priv-helper/meson.build index e9f8a7c3..6141e0e2 100644 --- a/src/nm-priv-helper/meson.build +++ b/src/nm-priv-helper/meson.build @@ -1,7 +1,7 @@ # SPDX-License-Identifier: LGPL-2.1-or-later configure_file( - input: 'org.freedesktop.nm-priv-helper.service.in', + input: 'org.freedesktop.nm_priv_helper.service.in', output: '@BASENAME@', install_dir: dbus_system_bus_services_dir, configuration: data_conf, diff --git a/src/nm-priv-helper/nm-priv-helper.c b/src/nm-priv-helper/nm-priv-helper.c index 76ca0cab..ec064bca 100644 --- a/src/nm-priv-helper/nm-priv-helper.c +++ b/src/nm-priv-helper/nm-priv-helper.c @@ -38,7 +38,7 @@ typedef struct { struct _GlobalData { GDBusConnection *dbus_connection; - GCancellable * quit_cancellable; + GCancellable *quit_cancellable; GSource *source_sigterm; @@ -112,9 +112,9 @@ _handle_ping(GlobalData *gl, GDBusMethodInvocation *invocation, const char *arg) static void _handle_get_fd(GlobalData *gl, GDBusMethodInvocation *invocation, guint32 fd_type) { - nm_auto_close int fd = -1; + nm_auto_close int fd = -1; gs_unref_object GUnixFDList *fd_list = NULL; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; if (fd_type != (NMPrivHelperGetFDType) fd_type) fd_type = NM_PRIV_HELPER_GET_FD_TYPE_NONE; @@ -151,7 +151,7 @@ _signal_callback_term(gpointer user_data) static GDBusConnection * _bus_get(GCancellable *cancellable, int *out_exit_code) { - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; gs_unref_object GDBusConnection *dbus_connection = NULL; dbus_connection = nm_g_bus_get_blocking(cancellable, &error); @@ -178,11 +178,11 @@ _bus_get(GCancellable *cancellable, int *out_exit_code) 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) { GlobalData *gl = user_data; @@ -207,7 +207,7 @@ _name_owner_changed_cb(GDBusConnection *connection, typedef struct { GlobalData *gl; - char ** p_name_owner; + char **p_name_owner; gboolean is_cancelled; } BusFindNMNameOwnerData; @@ -226,7 +226,7 @@ _bus_find_nm_nameowner(GlobalData *gl) { BusFindNMNameOwnerData data; guint name_owner_changed_id; - gs_free char * name_owner = NULL; + gs_free char *name_owner = NULL; name_owner_changed_id = nm_dbus_connection_signal_subscribe_name_owner_changed(gl->dbus_connection, @@ -262,12 +262,12 @@ _bus_find_nm_nameowner(GlobalData *gl) /*****************************************************************************/ static void -_bus_method_call(GDBusConnection * connection, - const char * sender, - const char * object_path, - const char * interface_name, - const char * method_name, - GVariant * parameters, +_bus_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) { @@ -351,9 +351,9 @@ _bus_register_service(GlobalData *gl) static const GDBusInterfaceVTable interface_vtable = { .method_call = _bus_method_call, }; - gs_free_error GError * error = NULL; + gs_free_error GError *error = NULL; NMDBusConnectionCallBlockingData data = { - .result = NULL, + .result = NULL, }; gs_unref_variant GVariant *ret = NULL; guint32 ret_val; @@ -455,7 +455,7 @@ static gboolean _pending_job_register_object_release_on_idle_cb(gpointer data) { PendingJobData *idle_data = data; - GlobalData * gl = idle_data->gl; + GlobalData *gl = idle_data->gl; c_list_unlink_stale(&idle_data->pending_jobs_lst); nm_g_slice_free(idle_data); @@ -498,7 +498,7 @@ static void _bus_release_name_cb(GObject *source, GAsyncResult *result, gpointer user_data) { _nm_unused gs_unref_object GObject *keep_alive_object = NULL; - GlobalData * gl; + GlobalData *gl; nm_utils_user_data_unpack(user_data, &gl, &keep_alive_object); diff --git a/src/nm-priv-helper/nm-priv-helper.conf b/src/nm-priv-helper/nm-priv-helper.conf index c56b2007..c0d04617 100644 --- a/src/nm-priv-helper/nm-priv-helper.conf +++ b/src/nm-priv-helper/nm-priv-helper.conf @@ -3,11 +3,11 @@ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> - - + + - - + + diff --git a/src/nm-priv-helper/org.freedesktop.nm-priv-helper.service.in b/src/nm-priv-helper/org.freedesktop.nm-priv-helper.service.in deleted file mode 100644 index 0ca30669..00000000 --- a/src/nm-priv-helper/org.freedesktop.nm-priv-helper.service.in +++ /dev/null @@ -1,5 +0,0 @@ -[D-BUS Service] -Name=org.freedesktop.nm-priv-helper -Exec=@libexecdir@/nm-priv-helper -User=root -SystemdService=dbus-org.freedesktop.nm-priv-helper.service diff --git a/src/nm-priv-helper/org.freedesktop.nm_priv_helper.service.in b/src/nm-priv-helper/org.freedesktop.nm_priv_helper.service.in new file mode 100644 index 00000000..9e86a635 --- /dev/null +++ b/src/nm-priv-helper/org.freedesktop.nm_priv_helper.service.in @@ -0,0 +1,5 @@ +[D-BUS Service] +Name=org.freedesktop.nm_priv_helper +Exec=@libexecdir@/nm-priv-helper +User=root +SystemdService=nm-priv-helper.service diff --git a/src/nmcli/agent.c b/src/nmcli/agent.c index bdbd6e45..6d0fcfb5 100644 --- a/src/nmcli/agent.c +++ b/src/nmcli/agent.c @@ -56,7 +56,8 @@ usage_agent_all(void) static char *pre_input_deftext; -static int set_deftext(_NMC_RL_STARTUPHOOK_ARGS) +static int +set_deftext(_NMC_RL_STARTUPHOOK_ARGS) { if (pre_input_deftext && rl_startup_hook) { rl_insert_text(pre_input_deftext); @@ -68,16 +69,16 @@ static int set_deftext(_NMC_RL_STARTUPHOOK_ARGS) static gboolean get_secrets_from_user(const NmcConfig *nmc_config, - const char * request_id, - const char * title, - const char * msg, - GPtrArray * secrets) + const char *request_id, + const char *title, + const char *msg, + GPtrArray *secrets) { int i; for (i = 0; i < secrets->len; i++) { NMSecretAgentSimpleSecret *secret = secrets->pdata[i]; - char * pwd = NULL; + char *pwd = NULL; /* Ask user for the password */ if (msg) @@ -103,13 +104,13 @@ get_secrets_from_user(const NmcConfig *nmc_config, static void secrets_requested(NMSecretAgentSimple *agent, - const char * request_id, - const char * title, - const char * msg, - GPtrArray * secrets, + const char *request_id, + const char *title, + const char *msg, + GPtrArray *secrets, gpointer user_data) { - NmCli * nmc = user_data; + NmCli *nmc = user_data; gboolean success; if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) diff --git a/src/nmcli/common.c b/src/nmcli/common.c index d9a981c3..26398c84 100644 --- a/src/nmcli/common.c +++ b/src/nmcli/common.c @@ -30,8 +30,8 @@ static char ** _ip_config_get_routes(NMIPConfig *cfg) { gs_unref_hashtable GHashTable *hash = NULL; - GPtrArray * ptr_array; - char ** arr; + GPtrArray *ptr_array; + char **arr; guint i; ptr_array = nm_ip_config_get_routes(cfg); @@ -43,12 +43,12 @@ _ip_config_get_routes(NMIPConfig *cfg) arr = g_new(char *, ptr_array->len + 1); for (i = 0; i < ptr_array->len; i++) { - NMIPRoute * route = g_ptr_array_index(ptr_array, i); + NMIPRoute *route = g_ptr_array_index(ptr_array, i); gs_strfreev char **names = NULL; gsize j; - GString * str; + GString *str; guint64 metric; - gs_free char * attributes = NULL; + gs_free char *attributes = NULL; str = g_string_new(NULL); g_string_append_printf( @@ -92,14 +92,15 @@ _ip_config_get_routes(NMIPConfig *cfg) /*****************************************************************************/ -static gconstpointer _metagen_ip4_config_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) +static gconstpointer +_metagen_ip4_config_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) { - NMIPConfig * cfg4 = target; - GPtrArray * ptr_array; - char ** arr; + NMIPConfig *cfg4 = target; + GPtrArray *ptr_array; + char **arr; const char *const *arrc; guint i = 0; - const char * str; + const char *str; nm_assert(info->info_type < _NMC_GENERIC_INFO_TYPE_IP4_CONFIG_NUM); @@ -185,14 +186,15 @@ const NmcMetaGenericInfo *const metagen_ip4_config[_NMC_GENERIC_INFO_TYPE_IP4_CO /*****************************************************************************/ -static gconstpointer _metagen_ip6_config_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) +static gconstpointer +_metagen_ip6_config_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) { - NMIPConfig * cfg6 = target; - GPtrArray * ptr_array; - char ** arr; + NMIPConfig *cfg6 = target; + GPtrArray *ptr_array; + char **arr; const char *const *arrc; guint i = 0; - const char * str; + const char *str; nm_assert(info->info_type < _NMC_GENERIC_INFO_TYPE_IP6_CONFIG_NUM); @@ -272,18 +274,19 @@ const NmcMetaGenericInfo *const metagen_ip6_config[_NMC_GENERIC_INFO_TYPE_IP6_CO /*****************************************************************************/ -static gconstpointer _metagen_dhcp_config_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) +static gconstpointer +_metagen_dhcp_config_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) { NMDhcpConfig *dhcp = target; guint i; - char ** arr = NULL; + char **arr = NULL; NMC_HANDLE_COLOR(NM_META_COLOR_NONE); switch (info->info_type) { case NMC_GENERIC_INFO_TYPE_DHCP_CONFIG_OPTION: { - GHashTable * table; + GHashTable *table; gs_free char **arr2 = NULL; guint n; @@ -333,13 +336,13 @@ const NmcMetaGenericInfo *const metagen_dhcp_config[_NMC_GENERIC_INFO_TYPE_DHCP_ /*****************************************************************************/ gboolean -print_ip_config(NMIPConfig * cfg, +print_ip_config(NMIPConfig *cfg, int addr_family, const NmcConfig *nmc_config, - const char * one_field) + const char *one_field) { gs_free_error GError *error = NULL; - gs_free char * field_str = NULL; + gs_free char *field_str = NULL; if (!cfg) return FALSE; @@ -364,13 +367,13 @@ print_ip_config(NMIPConfig * cfg, } gboolean -print_dhcp_config(NMDhcpConfig * dhcp, +print_dhcp_config(NMDhcpConfig *dhcp, int addr_family, const NmcConfig *nmc_config, - const char * one_field) + const char *one_field) { gs_free_error GError *error = NULL; - gs_free char * field_str = NULL; + gs_free char *field_str = NULL; if (!dhcp) return FALSE; @@ -416,16 +419,16 @@ print_dhcp_config(NMDhcpConfig * dhcp, */ NMConnection * nmc_find_connection(const GPtrArray *connections, - const char * filter_type, - const char * filter_val, - GPtrArray ** out_result, + const char *filter_type, + const char *filter_val, + GPtrArray **out_result, gboolean complete) { - NMConnection * best_candidate_uuid = NULL; - NMConnection * best_candidate = NULL; - gs_unref_ptrarray GPtrArray *result_allocated = NULL; - GPtrArray * result = out_result ? *out_result : NULL; - const guint result_inital_len = result ? result->len : 0u; + NMConnection *best_candidate_uuid = NULL; + NMConnection *best_candidate = NULL; + gs_unref_ptrarray GPtrArray *result_allocated = NULL; + GPtrArray *result = out_result ? *out_result : NULL; + const guint result_inital_len = result ? result->len : 0u; guint i, j; nm_assert(connections); @@ -434,8 +437,8 @@ nmc_find_connection(const GPtrArray *connections, for (i = 0; i < connections->len; i++) { gboolean match_by_uuid = FALSE; NMConnection *connection; - const char * v; - const char * v_num; + const char *v; + const char *v_num; connection = NM_CONNECTION(connections->pdata[i]); @@ -517,21 +520,21 @@ found: NMActiveConnection * nmc_find_active_connection(const GPtrArray *active_cons, - const char * filter_type, - const char * filter_val, - GPtrArray ** out_result, + const char *filter_type, + const char *filter_val, + GPtrArray **out_result, gboolean complete) { guint i, j; NMActiveConnection *best_candidate = NULL; - GPtrArray * result = out_result ? *out_result : NULL; + GPtrArray *result = out_result ? *out_result : NULL; nm_assert(filter_val); for (i = 0; i < active_cons->len; i++) { NMRemoteConnection *con; NMActiveConnection *candidate = g_ptr_array_index(active_cons, i); - const char * v, *v_num; + const char *v, *v_num; con = nm_active_connection_get_connection(candidate); @@ -606,9 +609,9 @@ found: static gboolean vpn_openconnect_get_secrets(NMConnection *connection, GPtrArray *secrets) { - GError * error = NULL; + GError *error = NULL; NMSettingVpn *s_vpn; - const char * gw, *port; + const char *gw, *port; gs_free char *cookie = NULL; gs_free char *gateway = NULL; gs_free char *gwcert = NULL; @@ -679,13 +682,13 @@ vpn_openconnect_get_secrets(NMConnection *connection, GPtrArray *secrets) static gboolean get_secrets_from_user(const NmcConfig *nmc_config, - const char * request_id, - const char * title, - const char * msg, - NMConnection * connection, + const char *request_id, + const char *title, + const char *msg, + NMConnection *connection, gboolean ask, - GHashTable * pwds_hash, - GPtrArray * secrets) + GHashTable *pwds_hash, + GPtrArray *secrets) { int i; @@ -695,7 +698,7 @@ get_secrets_from_user(const NmcConfig *nmc_config, for (i = 0; i < secrets->len; i++) { NMSecretAgentSimpleSecret *secret = secrets->pdata[i]; - char * pwd = NULL; + char *pwd = NULL; /* First try to find the password in provided passwords file, * then ask user. */ @@ -764,15 +767,15 @@ get_secrets_from_user(const NmcConfig *nmc_config, */ void nmc_secrets_requested(NMSecretAgentSimple *agent, - const char * request_id, - const char * title, - const char * msg, - GPtrArray * secrets, + const char *request_id, + const char *title, + const char *msg, + GPtrArray *secrets, gpointer user_data) { - NmCli * nmc = (NmCli *) user_data; - NMConnection * connection = NULL; - char * path, *p; + NmCli *nmc = (NmCli *) user_data; + NMConnection *connection = NULL; + char *path, *p; gboolean success = FALSE; const GPtrArray *connections; @@ -814,8 +817,8 @@ char * nmc_unique_connection_name(const GPtrArray *connections, const char *try_name) { NMConnection *connection; - const char * name; - char * new_name; + const char *name; + char *new_name; unsigned num = 1; int i = 0; @@ -837,7 +840,7 @@ nmc_unique_connection_name(const GPtrArray *connections, const char *try_name) /* readline state variables */ static gboolean nmcli_in_readline = FALSE; static gboolean rl_got_line; -static char * rl_string; +static char *rl_string; /** * nmc_cleanup_readline: @@ -978,7 +981,7 @@ nmc_secret_redisplay(void) { int save_point = rl_point; int save_end = rl_end; - char * save_line_buffer = rl_line_buffer; + char *save_line_buffer = rl_line_buffer; const char *subst = nmc_password_subst_char(); int subst_len = strlen(subst); int i; @@ -1009,7 +1012,7 @@ nmc_readline_echo(const NmcConfig *nmc_config, gboolean echo_on, const char *pro { va_list args; gs_free char *prompt = NULL; - char * str; + char *str; #if HAVE_READLINE_HISTORY nm_auto_free HISTORY_STATE *saved_history = NULL; HISTORY_STATE passwd_history = { @@ -1129,8 +1132,8 @@ nmc_rl_gen_func_ifnames(const char *text, int state) { int i; const GPtrArray *devices; - const char ** ifnames; - char * ret; + const char **ifnames; + char *ret; devices = nm_client_get_devices(nm_cli_global_readline->client); if (devices->len == 0) @@ -1138,7 +1141,7 @@ nmc_rl_gen_func_ifnames(const char *text, int state) ifnames = g_new(const char *, devices->len + 1); for (i = 0; i < devices->len; i++) { - NMDevice * dev = g_ptr_array_index(devices, i); + NMDevice *dev = g_ptr_array_index(devices, i); const char *ifname = nm_device_get_iface(dev); ifnames[i] = ifname; } @@ -1152,7 +1155,8 @@ nmc_rl_gen_func_ifnames(const char *text, int state) char *nmc_rl_pre_input_deftext; -int nmc_rl_set_deftext(_NMC_RL_STARTUPHOOK_ARGS) +int +nmc_rl_set_deftext(_NMC_RL_STARTUPHOOK_ARGS) { if (nmc_rl_pre_input_deftext && rl_startup_hook) { rl_insert_text(nmc_rl_pre_input_deftext); @@ -1186,7 +1190,7 @@ nmc_parse_lldp_capabilities(guint value) "s-vlan-component", "tpmr"}; gboolean first = TRUE; - GString * str; + GString *str; int i; if (!value) @@ -1217,8 +1221,8 @@ nmc_parse_lldp_capabilities(guint value) static void command_done(GObject *object, GAsyncResult *res, gpointer user_data) { - GTask * task = G_TASK(res); - NmCli * nmc = user_data; + GTask *task = G_TASK(res); + NmCli *nmc = user_data; gs_free_error GError *error = NULL; if (!g_task_propagate_boolean(task, &error)) { @@ -1233,8 +1237,8 @@ command_done(GObject *object, GAsyncResult *res, gpointer user_data) typedef struct { const NMCCommand *cmd; int argc; - char ** argv; - GTask * task; + char **argv; + GTask *task; } CmdCall; static void @@ -1243,10 +1247,10 @@ call_cmd(NmCli *nmc, GTask *task, const NMCCommand *cmd, int argc, const char *c static void got_client(GObject *source_object, GAsyncResult *res, gpointer user_data) { - gs_unref_object GTask *task = NULL; - gs_free_error GError *error = NULL; - CmdCall * call = user_data; - NmCli * nmc; + gs_unref_object GTask *task = NULL; + gs_free_error GError *error = NULL; + CmdCall *call = user_data; + NmCli *nmc; nm_assert(NM_IS_CLIENT(source_object)); @@ -1343,7 +1347,7 @@ nmc_complete_help(const char *prefix) void nmc_do_cmd(NmCli *nmc, const NMCCommand cmds[], const char *cmd, int argc, const char *const *argv) { - const NMCCommand *c; + const NMCCommand *c; gs_unref_object GTask *task = NULL; task = nm_g_task_new(NULL, NULL, nmc_do_cmd, command_done, nmc); diff --git a/src/nmcli/common.h b/src/nmcli/common.h index 908dad06..1572c534 100644 --- a/src/nmcli/common.h +++ b/src/nmcli/common.h @@ -9,33 +9,33 @@ #include "nmcli.h" #include "libnmc-base/nm-secret-agent-simple.h" -gboolean print_ip_config(NMIPConfig * cfg, +gboolean print_ip_config(NMIPConfig *cfg, int addr_family, const NmcConfig *nmc_config, - const char * one_field); + const char *one_field); -gboolean print_dhcp_config(NMDhcpConfig * dhcp, +gboolean print_dhcp_config(NMDhcpConfig *dhcp, int addr_family, const NmcConfig *nmc_config, - const char * one_field); + const char *one_field); NMConnection *nmc_find_connection(const GPtrArray *connections, - const char * filter_type, - const char * filter_val, - GPtrArray ** out_result, + const char *filter_type, + const char *filter_val, + GPtrArray **out_result, gboolean complete); NMActiveConnection *nmc_find_active_connection(const GPtrArray *active_cons, - const char * filter_type, - const char * filter_val, - GPtrArray ** out_result, + const char *filter_type, + const char *filter_val, + GPtrArray **out_result, gboolean complete); void nmc_secrets_requested(NMSecretAgentSimple *agent, - const char * request_id, - const char * title, - const char * msg, - GPtrArray * secrets, + const char *request_id, + const char *title, + const char *msg, + GPtrArray *secrets, gpointer user_data); char *nmc_unique_connection_name(const GPtrArray *connections, const char *try_name); @@ -45,8 +45,8 @@ char *nmc_readline(const NmcConfig *nmc_config, const char *prompt_fmt, ...) G_G char *nmc_readline_echo(const NmcConfig *nmc_config, gboolean echo_on, const char *prompt_fmt, ...) G_GNUC_PRINTF(3, 4); NmcCompEntryFunc nmc_rl_compentry_func_wrap(const char *const *values); -char * nmc_rl_gen_func_basic(const char *text, int state, const char *const *words); -char * nmc_rl_gen_func_ifnames(const char *text, int state); +char *nmc_rl_gen_func_basic(const char *text, int state, const char *const *words); +char *nmc_rl_gen_func_ifnames(const char *text, int state); gboolean nmc_get_in_readline(void); void nmc_set_in_readline(gboolean in_readline); diff --git a/src/nmcli/connections.c b/src/nmcli/connections.c index 5edd33f0..5a66b82f 100644 --- a/src/nmcli/connections.c +++ b/src/nmcli/connections.c @@ -45,13 +45,13 @@ typedef char *(*CompEntryFunc)(const char *, int); typedef struct _OptionInfo { const NMMetaSettingInfoEditor *setting_info; - const char * property; - const char * option; - gboolean (*check_and_set)(NmCli * nmc, - NMConnection * connection, + const char *property; + const char *option; + gboolean (*check_and_set)(NmCli *nmc, + NMConnection *connection, const struct _OptionInfo *option, - const char * value, - GError ** error); + const char *value, + GError **error); CompEntryFunc generator_func; } OptionInfo; @@ -100,9 +100,9 @@ static NM_UTILS_LOOKUP_STR_DEFINE( typedef struct { NmCli *nmc; - char * orig_id; - char * orig_uuid; - char * new_id; + char *orig_id; + char *orig_uuid; + char *new_id; } AddConnectionInfo; static AddConnectionInfo * @@ -189,10 +189,10 @@ active_connection_get_state_ord(NMActiveConnection *active) int nmc_active_connection_cmp(NMActiveConnection *ac_a, NMActiveConnection *ac_b) { - NMSettingIPConfig * s_ip; + NMSettingIPConfig *s_ip; NMRemoteConnection *conn; - NMIPConfig * da_ip; - NMIPConfig * db_ip; + NMIPConfig *da_ip; + NMIPConfig *db_ip; int da_num_addrs; int db_num_addrs; int cmp = 0; @@ -254,7 +254,7 @@ nmc_active_connection_cmp(NMActiveConnection *ac_a, NMActiveConnection *ac_b) static char * get_ac_device_string(NMActiveConnection *active) { - GString * dev_str; + GString *dev_str; const GPtrArray *devices; guint i; @@ -265,7 +265,7 @@ get_ac_device_string(NMActiveConnection *active) dev_str = g_string_new(NULL); devices = nm_active_connection_get_devices(active); for (i = 0; i < devices->len; i++) { - NMDevice * device = g_ptr_array_index(devices, i); + NMDevice *device = g_ptr_array_index(devices, i); const char *dev_iface = nm_device_get_iface(device); if (dev_iface) { @@ -288,7 +288,7 @@ static const char * get_vpn_connection_type(NMConnection *connection) { NMSettingVpn *s_vpn; - const char * type, *p; + const char *type, *p; s_vpn = nm_connection_get_setting_vpn(connection); if (!s_vpn) @@ -387,9 +387,9 @@ get_vpn_data_item(NMConnection *connection, enum VpnDataItem vpn_data_item) /*****************************************************************************/ typedef struct { - NMConnection * connection; + NMConnection *connection; NMActiveConnection *primary_active; - GPtrArray * all_active; + GPtrArray *all_active; bool show_active_fields; } MetagenConShowRowData; @@ -422,7 +422,7 @@ _metagen_con_show_row_data_new_for_active_connection(NMRemoteConnection *connect static void _metagen_con_show_row_data_add_active_connection(MetagenConShowRowData *row_data, - NMActiveConnection * active) + NMActiveConnection *active) { if (!row_data->primary_active) { row_data->primary_active = g_object_ref(active); @@ -477,7 +477,7 @@ static const char * _con_show_fcn_get_id(NMConnection *c, NMActiveConnection *ac) { NMSettingConnection *s_con = NULL; - const char * s; + const char *s; if (c) s_con = nm_connection_get_setting_connection(c); @@ -499,7 +499,7 @@ static const char * _con_show_fcn_get_type(NMConnection *c, NMActiveConnection *ac, NMMetaAccessorGetType get_type) { NMSettingConnection *s_con = NULL; - const char * s; + const char *s; if (c) s_con = nm_connection_get_setting_connection(c); @@ -513,14 +513,15 @@ _con_show_fcn_get_type(NMConnection *c, NMActiveConnection *ac, NMMetaAccessorGe return connection_type_to_display(s, get_type); } -static gconstpointer _metagen_con_show_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) +static gconstpointer +_metagen_con_show_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) { const MetagenConShowRowData *row_data = target; - NMConnection * c = row_data->connection; - NMActiveConnection * ac = row_data->primary_active; - NMSettingConnection * s_con = NULL; - const char * s; - char * s_mut; + NMConnection *c = row_data->connection; + NMActiveConnection *ac = row_data->primary_active; + NMSettingConnection *s_con = NULL; + const char *s; + char *s_mut; NMC_HANDLE_COLOR(nmc_active_connection_state_to_color(ac)); @@ -654,14 +655,15 @@ const NmcMetaGenericInfo *const metagen_con_show[_NMC_GENERIC_INFO_TYPE_CON_SHOW /*****************************************************************************/ -static gconstpointer _metagen_con_active_general_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) +static gconstpointer +_metagen_con_active_general_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) { - NMActiveConnection * ac = target; - NMConnection * c; + NMActiveConnection *ac = target; + NMConnection *c; NMSettingConnection *s_con = NULL; - NMDevice * dev; + NMDevice *dev; guint i; - const char * s; + const char *s; NMC_HANDLE_COLOR(NM_META_COLOR_NONE); @@ -680,14 +682,14 @@ static gconstpointer _metagen_con_active_general_get_fcn(NMC_META_GENERIC_INFO_G case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEVICES: case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_IP_IFACE: { - GString * str = NULL; + GString *str = NULL; const GPtrArray *devices; s = NULL; devices = nm_active_connection_get_devices(ac); if (devices) { for (i = 0; i < devices->len; i++) { - NMDevice * device = g_ptr_array_index(devices, i); + NMDevice *device = g_ptr_array_index(devices, i); const char *iface; if (info->info_type == NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEVICES) { @@ -767,15 +769,16 @@ const NmcMetaGenericInfo /*****************************************************************************/ -static gconstpointer _metagen_con_active_vpn_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) +static gconstpointer +_metagen_con_active_vpn_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) { - NMActiveConnection * ac = target; - NMConnection * c; - NMSettingVpn * s_vpn = NULL; + NMActiveConnection *ac = target; + NMConnection *c; + NMSettingVpn *s_vpn = NULL; NMVpnConnectionState vpn_state; guint i; - const char * s; - char ** arr = NULL; + const char *s; + char **arr = NULL; nm_assert(NM_IS_VPN_CONNECTION(ac)); @@ -909,12 +912,12 @@ static guint progress_id = 0; /* ID of event source for displaying progress */ /* for readline TAB completion in editor */ typedef struct { - NmCli * nmc; - char * con_type; + NmCli *nmc; + char *con_type; NMConnection *connection; - NMSetting * setting; - const char * property; - char ** words; + NMSetting *setting; + const char *property; + char **words; } TabCompletionInfo; static TabCompletionInfo nmc_tab_completion; @@ -1291,12 +1294,12 @@ get_ac_for_connection_cmp(gconstpointer pa, gconstpointer pb) static NMActiveConnection * get_ac_for_connection(const GPtrArray *active_cons, - NMConnection * connection, - GPtrArray ** out_result) + NMConnection *connection, + GPtrArray **out_result) { guint i; NMActiveConnection *best_candidate = NULL; - GPtrArray * result = out_result ? *out_result : NULL; + GPtrArray *result = out_result ? *out_result : NULL; for (i = 0; i < active_cons->len; i++) { NMActiveConnection *candidate = g_ptr_array_index(active_cons, i); @@ -1323,16 +1326,16 @@ get_ac_for_connection(const GPtrArray *active_cons, } typedef struct { - GMainLoop * loop; + GMainLoop *loop; NMConnection *local; - const char * setting_name; + const char *setting_name; } GetSecretsData; static void got_secrets(GObject *source_object, GAsyncResult *res, gpointer user_data) { - NMRemoteConnection *remote = NM_REMOTE_CONNECTION(source_object); - GetSecretsData * data = user_data; + NMRemoteConnection *remote = NM_REMOTE_CONNECTION(source_object); + GetSecretsData *data = user_data; gs_unref_variant GVariant *secrets = NULL; secrets = nm_remote_connection_get_secrets_finish(remote, res, NULL); @@ -1384,13 +1387,13 @@ update_secrets_in_connection(NMRemoteConnection *remote, NMConnection *local) static gboolean nmc_connection_profile_details(NMConnection *connection, NmCli *nmc) { - GError * error = NULL; - GArray * print_settings_array; - GPtrArray * prop_array = NULL; + GError *error = NULL; + GArray *print_settings_array; + GPtrArray *prop_array = NULL; guint i; - char * fields_str; - char * fields_all = NMC_FIELDS_SETTINGS_NAMES_ALL; - char * fields_common = NMC_FIELDS_SETTINGS_NAMES_ALL; + char *fields_str; + char *fields_all = NMC_FIELDS_SETTINGS_NAMES_ALL; + char *fields_common = NMC_FIELDS_SETTINGS_NAMES_ALL; const char *base_hdr = _("Connection profile details"); gboolean was_output = FALSE; @@ -1417,9 +1420,9 @@ nmc_connection_profile_details(NMConnection *connection, NmCli *nmc) /* Main header */ { - gs_free char *header_name = NULL; - gs_free NmcOutputField *row = NULL; - gs_unref_array GArray *out_indices = NULL; + gs_free char *header_name = NULL; + gs_free NmcOutputField *row = NULL; + gs_unref_array GArray *out_indices = NULL; header_name = construct_header_name(base_hdr, nm_connection_get_id(connection)); out_indices = parse_output_fields( @@ -1444,7 +1447,7 @@ nmc_connection_profile_details(NMConnection *connection, NmCli *nmc) /* Loop through the required settings and print them. */ for (i = 0; i < print_settings_array->len; i++) { - NMSetting * setting; + NMSetting *setting; int section_idx = g_array_index(print_settings_array, int, i); const char *prop_name = (const char *) g_ptr_array_index(prop_array, i); @@ -1496,12 +1499,12 @@ nmc_active_connection_state_to_color(NMActiveConnection *ac) static gboolean nmc_active_connection_details(NMActiveConnection *acon, NmCli *nmc) { - GError * error = NULL; - GArray * print_groups; - GPtrArray * group_fields = NULL; + GError *error = NULL; + GArray *print_groups; + GPtrArray *group_fields = NULL; int i; const char *fields_str = NULL; - const char *base_hdr = _("Activate connection details"); + const char *base_hdr = _("Active connection details"); gboolean was_output = FALSE; if (!nmc->required_fields || g_ascii_strcasecmp(nmc->required_fields, "common") == 0) { @@ -1527,9 +1530,9 @@ nmc_active_connection_details(NMActiveConnection *acon, NmCli *nmc) /* Main header */ { - gs_free char *header_name = NULL; - gs_free NmcOutputField *row = NULL; - gs_unref_array GArray *out_indices = NULL; + gs_free char *header_name = NULL; + gs_free NmcOutputField *row = NULL; + gs_unref_array GArray *out_indices = NULL; header_name = construct_header_name(base_hdr, nm_active_connection_get_uuid(acon)); out_indices = parse_output_fields( @@ -1648,12 +1651,12 @@ nmc_active_connection_details(NMActiveConnection *acon, NmCli *nmc) static gboolean split_required_fields_for_con_show(const char *input, - char ** profile_flds, - char ** active_flds, - GError ** error) + char **profile_flds, + char **active_flds, + GError **error) { - gs_free const char **fields = NULL; - const char *const * iter; + gs_free const char **fields = NULL; + const char *const *iter; nm_auto_free_gstring GString *str1 = NULL; nm_auto_free_gstring GString *str2 = NULL; gboolean group_profile = FALSE; @@ -1671,8 +1674,8 @@ split_required_fields_for_con_show(const char *input, fields = nm_strsplit_set_with_empty(input, ","); for (iter = fields; iter && *iter; iter++) { - char * s_mutable = (char *) (*iter); - char * dot; + char *s_mutable = (char *) (*iter); + char *dot; gboolean is_all; gboolean is_common; gboolean found; @@ -1789,7 +1792,7 @@ typedef enum { } NmcSortOrder; typedef struct { - NmCli * nmc; + NmCli *nmc; const GArray *order; gboolean show_active_fields; } ConShowSortInfo; @@ -1797,15 +1800,15 @@ typedef struct { static int con_show_get_items_cmp(gconstpointer pa, gconstpointer pb, gpointer user_data) { - const ConShowSortInfo * sort_info = user_data; + const ConShowSortInfo *sort_info = user_data; const MetagenConShowRowData *row_data_a = *((const MetagenConShowRowData *const *) pa); const MetagenConShowRowData *row_data_b = *((const MetagenConShowRowData *const *) pb); - NMConnection * c_a = row_data_a->connection; - NMConnection * c_b = row_data_b->connection; - NMActiveConnection * ac_a = row_data_a->primary_active; - NMActiveConnection * ac_b = row_data_b->primary_active; - NMActiveConnection * ac_a_effective = sort_info->show_active_fields ? ac_a : NULL; - NMActiveConnection * ac_b_effective = sort_info->show_active_fields ? ac_b : NULL; + NMConnection *c_a = row_data_a->connection; + NMConnection *c_b = row_data_b->connection; + NMActiveConnection *ac_a = row_data_a->primary_active; + NMActiveConnection *ac_b = row_data_b->primary_active; + NMActiveConnection *ac_a_effective = sort_info->show_active_fields ? ac_a : NULL; + NMActiveConnection *ac_b_effective = sort_info->show_active_fields ? ac_b : NULL; /* first sort active-connections which are invisible, i.e. that have no connection */ if (!c_a && c_b) @@ -1815,7 +1818,7 @@ con_show_get_items_cmp(gconstpointer pa, gconstpointer pb, gpointer user_data) /* we have two connections... */ if (c_a && c_b && c_a != c_b) { - const NmcSortOrder * order_arr; + const NmcSortOrder *order_arr; guint i, order_len; NMMetaAccessorGetType get_type = nmc_print_output_to_accessor_get_type(sort_info->nmc->nmc_config.print_output); @@ -1892,15 +1895,15 @@ con_show_get_items(NmCli *nmc, gboolean active_only, gboolean show_active_fields { gs_unref_hashtable GHashTable *row_hash = NULL; GHashTableIter hiter; - GPtrArray * result; - const GPtrArray * arr; - NMRemoteConnection * c; - MetagenConShowRowData * row_data; + GPtrArray *result; + const GPtrArray *arr; + NMRemoteConnection *c; + MetagenConShowRowData *row_data; guint i; const ConShowSortInfo sort_info = { - .nmc = nmc, - .order = order, - .show_active_fields = show_active_fields, + .nmc = nmc, + .order = order, + .show_active_fields = show_active_fields, }; row_hash = g_hash_table_new(nm_direct_hash, NULL); @@ -2003,9 +2006,9 @@ static GArray * parse_preferred_connection_order(const char *order, GError **error) { gs_free const char **strv = NULL; - const char *const * iter; - const char * str; - GArray * order_arr; + const char *const *iter; + const char *str; + GArray *order_arr; NmcSortOrder val; gboolean inverse, unique; guint i; @@ -2057,17 +2060,17 @@ parse_preferred_connection_order(const char *order, GError **error) } static NMConnection * -get_connection(NmCli * nmc, - int * argc, +get_connection(NmCli *nmc, + int *argc, const char *const **argv, - const char ** out_selector, - const char ** out_value, - GPtrArray ** out_result, - GError ** error) + const char **out_selector, + const char **out_value, + GPtrArray **out_result, + GError **error) { const GPtrArray *connections; - NMConnection * connection = NULL; - const char * selector = NULL; + NMConnection *connection = NULL; + const char *selector = NULL; NM_SET_OUT(out_selector, NULL); NM_SET_OUT(out_value, NULL); @@ -2121,11 +2124,11 @@ get_connection(NmCli * nmc, static void do_connections_show(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - gs_free_error GError *err = NULL; - gs_free char * profile_flds = NULL; - gs_free char * active_flds = NULL; - gboolean active_only = FALSE; - gs_unref_array GArray *order = NULL; + gs_free_error GError *err = NULL; + gs_free char *profile_flds = NULL; + gs_free char *active_flds = NULL; + gboolean active_only = FALSE; + gs_unref_array GArray *order = NULL; guint i; int option; @@ -2153,8 +2156,8 @@ do_connections_show(const NMCCommand *cmd, NmCli *nmc, int argc, const char *con } if (argc == 0) { - const char * fields_str = NULL; - gs_unref_ptrarray GPtrArray *items = NULL; + const char *fields_str = NULL; + gs_unref_ptrarray GPtrArray *items = NULL; gs_free NMMetaSelectionResultList *selection = NULL; gboolean show_active_fields = TRUE; @@ -2242,14 +2245,14 @@ do_connections_show(const NMCCommand *cmd, NmCli *nmc, int argc, const char *con } while (argc > 0) { - const GPtrArray *connections; - gboolean res; - NMConnection * con; - gs_unref_object NMActiveConnection *explicit_acon = NULL; - const char * selector = NULL; - gs_unref_ptrarray GPtrArray *found_cons = NULL; - gboolean explicit_acon_handled = FALSE; - guint i_found_cons; + const GPtrArray *connections; + gboolean res; + NMConnection *con; + gs_unref_object NMActiveConnection *explicit_acon = NULL; + const char *selector = NULL; + gs_unref_ptrarray GPtrArray *found_cons = NULL; + gboolean explicit_acon_handled = FALSE; + guint i_found_cons; if (argc == 1 && nmc->complete) nmc_complete_strings(*argv, "id", "uuid", "path", "filename", "apath"); @@ -2396,9 +2399,9 @@ static NMActiveConnection * get_default_active_connection(NmCli *nmc, NMDevice **device) { NMActiveConnection *default_ac = NULL; - NMDevice * non_default_device = NULL; + NMDevice *non_default_device = NULL; NMActiveConnection *non_default_ac = NULL; - const GPtrArray * connections; + const GPtrArray *connections; guint i; g_return_val_if_fail(nmc, NULL); @@ -2408,7 +2411,7 @@ get_default_active_connection(NmCli *nmc, NMDevice **device) connections = nm_client_get_active_connections(nmc->client); for (i = 0; i < connections->len; i++) { NMActiveConnection *candidate = g_ptr_array_index(connections, i); - const GPtrArray * devices; + const GPtrArray *devices; devices = nm_active_connection_get_devices(candidate); if (!devices->len) @@ -2447,17 +2450,17 @@ get_default_active_connection(NmCli *nmc, NMDevice **device) * RETURNS: TRUE when a device is found, FALSE otherwise. */ static gboolean -find_device_for_connection(NmCli * nmc, +find_device_for_connection(NmCli *nmc, NMConnection *connection, - const char * iface, - const char * ap, - const char * nsp, - NMDevice ** device, - const char ** spec_object, - GError ** error) + const char *iface, + const char *ap, + const char *nsp, + NMDevice **device, + const char **spec_object, + GError **error) { NMSettingConnection *s_con; - const char * con_type; + const char *con_type; guint i, j; g_return_val_if_fail(nmc, FALSE); @@ -2495,7 +2498,7 @@ find_device_for_connection(NmCli * nmc, } } else { /* Other connections */ - NMDevice * found_device = NULL; + NMDevice *found_device = NULL; const GPtrArray *devices = nm_client_get_devices(nmc->client); gboolean found_device_with_name = FALSE; @@ -2524,14 +2527,14 @@ find_device_for_connection(NmCli * nmc, found_device = dev; if (ap && nm_streq(con_type, NM_SETTING_WIRELESS_SETTING_NAME) && NM_IS_DEVICE_WIFI(dev)) { - gs_free char * bssid_up = g_ascii_strup(ap, -1); + gs_free char *bssid_up = g_ascii_strup(ap, -1); const GPtrArray *aps = nm_device_wifi_get_access_points(NM_DEVICE_WIFI(dev)); found_device = NULL; /* Mark as not found; set to the device again later, only if AP matches */ for (j = 0; j < aps->len; j++) { NMAccessPoint *candidate_ap = g_ptr_array_index(aps, j); - const char * candidate_bssid = nm_access_point_get_bssid(candidate_ap); + const char *candidate_bssid = nm_access_point_get_bssid(candidate_ap); if (nm_streq0(bssid_up, candidate_bssid)) { found_device = dev; @@ -2575,17 +2578,17 @@ find_device_for_connection(NmCli * nmc, } typedef struct { - NmCli * nmc; - NMDevice * device; + NmCli *nmc; + NMDevice *device; NMActiveConnection *active; } ActivateConnectionInfo; static void active_connection_hint(GString *return_text, NMActiveConnection *active, NMDevice *device) { - NMRemoteConnection * connection; + NMRemoteConnection *connection; nm_auto_free_gstring GString *hint = NULL; - const GPtrArray * devices; + const GPtrArray *devices; guint i; if (!active) @@ -2623,8 +2626,8 @@ static void check_activated(ActivateConnectionInfo *info) { NMActiveConnectionState ac_state; - NmCli * nmc = info->nmc; - const char * reason = NULL; + NmCli *nmc = info->nmc; + const char *reason = NULL; ac_state = nmc_activation_get_effective_state(info->active, info->device, &reason); switch (ac_state) { @@ -2668,10 +2671,10 @@ device_state_cb(NMDevice *device, GParamSpec *pspec, ActivateConnectionInfo *inf } static void -active_connection_state_cb(NMActiveConnection * active, +active_connection_state_cb(NMActiveConnection *active, NMActiveConnectionState state, NMActiveConnectionStateReason reason, - ActivateConnectionInfo * info) + ActivateConnectionInfo *info) { check_activated(info); } @@ -2707,11 +2710,11 @@ progress_cb(gpointer user_data) static gboolean progress_active_connection_cb(gpointer user_data) { - NMActiveConnection * active = user_data; - const char * str; - NMDevice * device; + NMActiveConnection *active = user_data; + const char *str; + NMDevice *device; NMActiveConnectionState ac_state; - const GPtrArray * ac_devs; + const GPtrArray *ac_devs; ac_state = nm_active_connection_get_state(active); @@ -2755,12 +2758,12 @@ static void activate_connection_cb(GObject *client, GAsyncResult *result, gpointer user_data) { ActivateConnectionInfo *info = (ActivateConnectionInfo *) user_data; - NmCli * nmc = info->nmc; - NMDevice * device = info->device; - NMActiveConnection * active; + NmCli *nmc = info->nmc; + NMDevice *device = info->device; + NMActiveConnection *active; NMActiveConnectionState state; - const GPtrArray * ac_devs; - GError * error = NULL; + const GPtrArray *ac_devs; + GError *error = NULL; info->active = active = nm_client_activate_connection_finish(NM_CLIENT(client), result, &error); @@ -2820,19 +2823,19 @@ activate_connection_cb(GObject *client, GAsyncResult *result, gpointer user_data } static gboolean -nmc_activate_connection(NmCli * nmc, - NMConnection * connection, - const char * ifname, - const char * ap, - const char * nsp, - const char * pwds, +nmc_activate_connection(NmCli *nmc, + NMConnection *connection, + const char *ifname, + const char *ap, + const char *nsp, + const char *pwds, GAsyncReadyCallback callback, - GError ** error) + GError **error) { ActivateConnectionInfo *info; GHashTable *pwds_hash; - NMDevice * device = NULL; + NMDevice *device = NULL; const char *spec_object = NULL; gboolean device_found; @@ -2930,16 +2933,16 @@ nmc_activate_connection(NmCli * nmc, static void do_connection_up(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - NMConnection *connection = NULL; - const char * ifname = NULL; - const char * ap = NULL; - const char * nsp = NULL; - const char * pwds = NULL; - gs_free_error GError *error = NULL; - gs_strfreev char ** arg_arr = NULL; + NMConnection *connection = NULL; + const char *ifname = NULL; + const char *ap = NULL; + const char *nsp = NULL; + const char *pwds = NULL; + gs_free_error GError *error = NULL; + gs_strfreev char **arg_arr = NULL; int arg_num; - const char *const ** argv_ptr; - int * argc_ptr; + const char *const **argv_ptr; + int *argc_ptr; /* * Set default timeout for connection activation. @@ -3058,7 +3061,7 @@ typedef struct { NmCli *nmc; /* a list of object that is relevant for the callback. The object * type differs, and depends on the type of callback. */ - GPtrArray * obj_list; + GPtrArray *obj_list; guint timeout_id; GCancellable *cancellable; } ConnectionCbInfo; @@ -3067,8 +3070,8 @@ static void connection_removed_cb(NMClient *client, NMConnection *connection, ConnectionCbInfo *info); static void down_active_connection_state_cb(NMActiveConnection *active, - GParamSpec * pspec, - ConnectionCbInfo * info); + GParamSpec *pspec, + ConnectionCbInfo *info); static void connection_cb_info_obj_list_destroy(ConnectionCbInfo *info, gpointer obj) @@ -3165,8 +3168,8 @@ connection_removed_cb(NMClient *client, NMConnection *connection, ConnectionCbIn static void down_active_connection_state_cb(NMActiveConnection *active, - GParamSpec * pspec, - ConnectionCbInfo * info) + GParamSpec *pspec, + ConnectionCbInfo *info) { if (nm_active_connection_get_state(active) < NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) return; @@ -3194,13 +3197,13 @@ connection_op_timeout_cb(gpointer user_data) static void do_connection_down(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - NMActiveConnection *active; - ConnectionCbInfo * info = NULL; - const GPtrArray * active_cons; - gs_strfreev char ** arg_arr = NULL; - const char *const * arg_ptr; - int arg_num; - guint i; + NMActiveConnection *active; + ConnectionCbInfo *info = NULL; + const GPtrArray *active_cons; + gs_strfreev char **arg_arr = NULL; + const char *const *arg_ptr; + int arg_num; + guint i; gs_unref_ptrarray GPtrArray *found_active_cons = NULL; if (nmc->timeout == -1) @@ -3351,7 +3354,7 @@ get_valid_options_string(const NMMetaSettingValidPartItem *const *array, const NMMetaSettingValidPartItem *const *array_slv) { const NMMetaSettingValidPartItem *const *iter = array; - GString * str; + GString *str; int i; str = g_string_sized_new(150); @@ -3422,8 +3425,8 @@ get_valid_settings_array(const char *con_type) } static char * -_construct_property_name(const char * setting_name, - const char * property_name, +_construct_property_name(const char *setting_name, + const char *property_name, NMMetaAccessorModifier modifier) { return g_strdup_printf("%s%s.%s\n", @@ -3452,12 +3455,12 @@ static char * get_valid_properties_string(const NMMetaSettingValidPartItem *const *array, const NMMetaSettingValidPartItem *const *array_slv, NMMetaAccessorModifier modifier, - const char * prefix, - const char * postfix) + const char *prefix, + const char *postfix) { const NMMetaSettingValidPartItem *const *iter = array; - const char * prop_name = NULL; - GString * str; + const char *prop_name = NULL; + GString *str; guint i, j; gboolean full_match = FALSE; @@ -3493,7 +3496,7 @@ get_valid_properties_string(const NMMetaSettingValidPartItem *const *array, /* Search the array with the arguments of the current property */ for (j = 0; j < setting_info->properties_num; j++) { gs_free char *ss1 = NULL; - const char * arg_name; + const char *arg_name; arg_name = setting_info->properties[j]->property_name; @@ -3526,16 +3529,16 @@ get_valid_properties_string(const NMMetaSettingValidPartItem *const *array, * The returned string must not be freed. */ static const char * -check_valid_name(const char * val, +check_valid_name(const char *val, const NMMetaSettingValidPartItem *const *array, const NMMetaSettingValidPartItem *const *array_slv, - GError ** error) + GError **error) { const NMMetaSettingValidPartItem *const *iter; - gs_unref_ptrarray GPtrArray *tmp_arr = NULL; - const char * str; - GError * tmp_err = NULL; - int i; + gs_unref_ptrarray GPtrArray *tmp_arr = NULL; + const char *str; + GError *tmp_err = NULL; + int i; g_return_val_if_fail(array, NULL); @@ -3590,11 +3593,11 @@ check_valid_name(const char * val, static const char * check_valid_name_toplevel(const char *val, const char **slave_type, GError **error) { - gs_unref_ptrarray GPtrArray * tmp_arr = NULL; + gs_unref_ptrarray GPtrArray *tmp_arr = NULL; const NMMetaSettingInfoEditor *setting_info; - gs_free_error GError *tmp_err = NULL; - const char * str; - int i; + gs_free_error GError *tmp_err = NULL; + const char *str; + int i; NM_SET_OUT(slave_type, NULL); @@ -3649,11 +3652,11 @@ check_valid_name_toplevel(const char *val, const char **slave_type, GError **err static gboolean is_setting_mandatory(NMConnection *connection, NMSetting *setting) { - NMSettingConnection * s_con; - const char * c_type; + NMSettingConnection *s_con; + const char *c_type; const NMMetaSettingValidPartItem *const *item; - const char * name; - const char * s_type; + const char *name; + const char *s_type; guint i; s_con = nm_connection_get_setting_connection(connection); @@ -3716,17 +3719,17 @@ _strip_master_prefix(const char *master, const char *(**func)(NMConnection *) ) */ static const char * normalized_master_for_slave(const GPtrArray *connections, - const char * master, - const char * type, - const char ** out_type) + const char *master, + const char *type, + const char **out_type) { - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - const char * con_type = NULL, *id, *uuid, *ifname; + const char *con_type = NULL, *id, *uuid, *ifname; guint i; - const char * found_by_id = NULL; - const char * out_type_by_id = NULL; - const char * out_master = NULL; + const char *found_by_id = NULL; + const char *out_type_by_id = NULL; + const char *out_master = NULL; const char *(*func)(NMConnection *) = NULL; if (!master) @@ -3806,10 +3809,10 @@ prompt_yes_no(gboolean default_yes, char *delim) } static NMSetting * -is_setting_valid(NMConnection * connection, +is_setting_valid(NMConnection *connection, const NMMetaSettingValidPartItem *const *valid_settings_main, const NMMetaSettingValidPartItem *const *valid_settings_slave, - const char * setting) + const char *setting) { const char *setting_name; @@ -3823,7 +3826,7 @@ static char * is_property_valid(NMSetting *setting, const char *property, GError **error) { gs_strfreev char **valid_props = NULL; - const char * prop_name; + const char *prop_name; valid_props = nmc_setting_get_valid_properties(setting); prop_name = nmc_string_is_valid(property, (const char **) valid_props, error); @@ -3876,7 +3879,7 @@ set_default_interface_name(NmCli *nmc, NMSettingConnection *s_con) if (default_name) { const GPtrArray *connections; - gs_free char * ifname = NULL; + gs_free char *ifname = NULL; connections = nm_client_get_connections(nmc->client); ifname = unique_master_iface_ifname(connections, default_name); @@ -3932,10 +3935,10 @@ _meta_property_needs_bond_hack(const NMMetaPropertyInfo *property_info) static char ** _meta_abstract_complete(const NMMetaAbstractInfo *abstract_info, const char *text) { - const char *const * values; - char ** values_to_free = NULL; + const char *const *values; + char **values_to_free = NULL; const NMMetaOperationContext ctx = { - .connection = nmc_tab_completion.connection, + .connection = nmc_tab_completion.connection, }; values = nm_meta_abstract_info_complete(abstract_info, @@ -3961,14 +3964,14 @@ _meta_abstract_generator(const char *text, int state) } static void -_meta_abstract_get(const NMMetaAbstractInfo * abstract_info, +_meta_abstract_get(const NMMetaAbstractInfo *abstract_info, const NMMetaSettingInfoEditor **out_setting_info, - const char ** out_setting_name, - const char ** out_property_name, - const char ** out_option, - NMMetaPropertyInfFlags * out_inf_flags, - const char ** out_prompt, - const char ** out_def_hint) + const char **out_setting_name, + const char **out_property_name, + const char **out_option, + NMMetaPropertyInfFlags *out_inf_flags, + const char **out_prompt, + const char **out_def_hint) { const NMMetaPropertyInfo *info = (const NMMetaPropertyInfo *) abstract_info; @@ -4031,7 +4034,7 @@ enable_options(const char *setting_name, const char *property, const char *const static void disable_options(const char *setting_name, const char *property) { - const NMMetaPropertyInfo * property_infos_local[2]; + const NMMetaPropertyInfo *property_infos_local[2]; const NMMetaPropertyInfo *const *property_infos; guint p; @@ -4119,17 +4122,17 @@ reset_options(void) } static gboolean -set_property(NMClient * client, - NMConnection * connection, - const char * setting_name, - const char * property, - const char * value, +set_property(NMClient *client, + NMConnection *connection, + const char *setting_name, + const char *property, + const char *value, NMMetaAccessorModifier modifier, - GError ** error) + GError **error) { - gs_free char *property_name = NULL; - gs_free_error GError *local = NULL; - NMSetting * setting; + gs_free char *property_name = NULL; + gs_free_error GError *local = NULL; + NMSetting *setting; nm_assert(setting_name && setting_name[0]); nm_assert(NM_IN_SET(modifier, @@ -4182,15 +4185,15 @@ set_property(NMClient * client, } static gboolean -set_option(NmCli * nmc, - NMConnection * connection, +set_option(NmCli *nmc, + NMConnection *connection, const NMMetaAbstractInfo *abstract_info, - const char * value, - GError ** error) + const char *value, + GError **error) { - const char * setting_name, *property_name, *option_name; + const char *setting_name, *property_name, *option_name; NMMetaPropertyInfFlags inf_flags; - const OptionInfo * option; + const OptionInfo *option; option = _meta_abstract_get_option_info(abstract_info); @@ -4227,12 +4230,12 @@ set_option(NmCli * nmc, * and slave type. */ static gboolean -con_settings(NMConnection * connection, +con_settings(NMConnection *connection, const NMMetaSettingValidPartItem *const **type_settings, const NMMetaSettingValidPartItem *const **slv_settings, - GError ** error) + GError **error) { - const char * con_type; + const char *con_type; NMSettingConnection *s_con; g_return_val_if_fail(type_settings, FALSE); @@ -4332,17 +4335,17 @@ gen_func_bond_lacp_rate(const char *text, int state) /*****************************************************************************/ static gboolean -set_connection_type(NmCli * nmc, - NMConnection * con, +set_connection_type(NmCli *nmc, + NMConnection *con, const OptionInfo *option, - const char * value, - GError ** error) + const char *value, + GError **error) { const NMMetaSettingValidPartItem *const *type_settings; const NMMetaSettingValidPartItem *const *slv_settings; - GError * local = NULL; - const char * master[] = {"master", NULL}; - const char * slave_type = NULL; + GError *local = NULL; + const char *master[] = {"master", NULL}; + const char *slave_type = NULL; value = check_valid_name_toplevel(value, &slave_type, &local); if (!value) { @@ -4396,11 +4399,11 @@ set_connection_type(NmCli * nmc, } static gboolean -set_connection_iface(NmCli * nmc, - NMConnection * con, +set_connection_iface(NmCli *nmc, + NMConnection *con, const OptionInfo *option, - const char * value, - GError ** error) + const char *value, + GError **error) { if (value) { /* Special value of '*' means no specific interface name */ @@ -4418,15 +4421,15 @@ set_connection_iface(NmCli * nmc, } static gboolean -set_connection_master(NmCli * nmc, - NMConnection * con, +set_connection_master(NmCli *nmc, + NMConnection *con, const OptionInfo *option, - const char * value, - GError ** error) + const char *value, + GError **error) { - const GPtrArray * connections; + const GPtrArray *connections; NMSettingConnection *s_con; - const char * slave_type; + const char *slave_type; s_con = nm_connection_get_setting_connection(con); g_return_val_if_fail(s_con, FALSE); @@ -4463,16 +4466,16 @@ set_connection_master(NmCli * nmc, } static gboolean -set_bond_option(NmCli * nmc, - NMConnection * con, +set_bond_option(NmCli *nmc, + NMConnection *con, const OptionInfo *option, - const char * value, - GError ** error) + const char *value, + GError **error) { NMSettingBond *s_bond; gboolean success; - gs_free char * name = NULL; - char * p; + gs_free char *name = NULL; + char *p; s_bond = nm_connection_get_setting_bond(con); g_return_val_if_fail(s_bond, FALSE); @@ -4507,16 +4510,16 @@ set_bond_option(NmCli * nmc, } static gboolean -set_bond_monitoring_mode(NmCli * nmc, - NMConnection * con, +set_bond_monitoring_mode(NmCli *nmc, + NMConnection *con, const OptionInfo *option, - const char * value, - GError ** error) + const char *value, + GError **error) { NMSettingBond *s_bond; - gs_free char * monitor_mode = NULL; - const char * miimon_opts[] = {"miimon", "downdelay", "updelay", NULL}; - const char * arp_opts[] = {"arp-interval", "arp-ip-target", NULL}; + gs_free char *monitor_mode = NULL; + const char *miimon_opts[] = {"miimon", "downdelay", "updelay", NULL}; + const char *arp_opts[] = {"arp-interval", "arp-ip-target", NULL}; s_bond = nm_connection_get_setting_bond(con); g_return_val_if_fail(s_bond, FALSE); @@ -4547,11 +4550,11 @@ set_bond_monitoring_mode(NmCli * nmc, } static gboolean -set_bluetooth_type(NmCli * nmc, - NMConnection * con, +set_bluetooth_type(NmCli *nmc, + NMConnection *con, const OptionInfo *option, - const char * value, - GError ** error) + const char *value, + GError **error) { NMSetting *setting; @@ -4595,11 +4598,11 @@ set_bluetooth_type(NmCli * nmc, } static gboolean -set_ip4_address(NmCli * nmc, - NMConnection * con, +set_ip4_address(NmCli *nmc, + NMConnection *con, const OptionInfo *option, - const char * value, - GError ** error) + const char *value, + GError **error) { NMSettingIPConfig *s_ip4; @@ -4622,11 +4625,11 @@ set_ip4_address(NmCli * nmc, } static gboolean -set_ip6_address(NmCli * nmc, - NMConnection * con, +set_ip6_address(NmCli *nmc, + NMConnection *con, const OptionInfo *option, - const char * value, - GError ** error) + const char *value, + GError **error) { NMSettingIPConfig *s_ip6; @@ -4703,9 +4706,9 @@ _meta_abstract_get_option_info(const NMMetaAbstractInfo *abstract_info) OPTION_INFO(IP6_CONFIG, NM_SETTING_IP_CONFIG_ADDRESSES, "ip6", set_ip6_address, NULL), {0}, }; - const char * property_name, *option; + const char *property_name, *option; const NMMetaSettingInfoEditor *setting_info; - const OptionInfo * candidate; + const OptionInfo *candidate; _meta_abstract_get(abstract_info, &setting_info, @@ -4728,7 +4731,7 @@ _meta_abstract_get_option_info(const NMMetaAbstractInfo *abstract_info) static gboolean option_relevant(NMConnection *connection, const NMMetaAbstractInfo *abstract_info) { - const char * setting_name; + const char *setting_name; NMMetaPropertyInfFlags inf_flags; _meta_abstract_get(abstract_info, NULL, &setting_name, NULL, NULL, &inf_flags, NULL, NULL); @@ -4746,18 +4749,18 @@ option_relevant(NMConnection *connection, const NMMetaAbstractInfo *abstract_inf /*****************************************************************************/ static void -complete_property_name(NmCli * nmc, - NMConnection * connection, +complete_property_name(NmCli *nmc, + NMConnection *connection, NMMetaAccessorModifier modifier, - const char * prefix, - const char * postfix) + const char *prefix, + const char *postfix) { - NMSettingConnection * s_con; + NMSettingConnection *s_con; const NMMetaSettingValidPartItem *const *valid_settings_main; const NMMetaSettingValidPartItem *const *valid_settings_slave; - const char * connection_type = NULL; - const char * slave_type = NULL; - gs_free char * word_list = NULL; + const char *connection_type = NULL; + const char *slave_type = NULL; + gs_free char *word_list = NULL; NMMetaSettingType s; connection_type = nm_connection_get_connection_type(connection); @@ -4831,17 +4834,17 @@ run_rl_generator(rl_compentry_func_t *generator_func, const char *prefix) } static gboolean -complete_option(NmCli * nmc, +complete_option(NmCli *nmc, const NMMetaAbstractInfo *abstract_info, - const char * prefix, - NMConnection * context_connection) + const char *prefix, + NMConnection *context_connection) { - const OptionInfo * candidate; - const char *const * values; - gs_strfreev char ** values_to_free = NULL; + const OptionInfo *candidate; + const char *const *values; + gs_strfreev char **values_to_free = NULL; gboolean complete_filename = FALSE; const NMMetaOperationContext ctx = { - .connection = context_connection, + .connection = context_connection, }; values = nm_meta_abstract_info_complete(abstract_info, @@ -4873,7 +4876,7 @@ complete_option(NmCli * nmc, static void complete_existing_setting(NmCli *nmc, NMConnection *connection, const char *prefix) { - gs_free NMSetting ** settings = NULL; + gs_free NMSetting **settings = NULL; const NMMetaSettingInfoEditor *editor; guint i; @@ -4892,10 +4895,10 @@ complete_existing_setting(NmCli *nmc, NMConnection *connection, const char *pref } static void -complete_property(NmCli * nmc, - const char * setting_name, - const char * property, - const char * prefix, +complete_property(NmCli *nmc, + const char *setting_name, + const char *property, + const char *prefix, NMConnection *connection) { const NMMetaPropertyInfo *property_info; @@ -4928,11 +4931,11 @@ connection_remove_setting(NMConnection *connection, NMSetting *setting, GError * } static gboolean -get_value(const char ** value, - int * argc, +get_value(const char **value, + int *argc, const char *const **argv, - const char * option, - GError ** error) + const char *option, + GError **error) { if (!**argv) { g_set_error(error, @@ -4955,12 +4958,12 @@ get_value(const char ** value, } gboolean -nmc_process_connection_properties(NmCli * nmc, - NMConnection * connection, - int * argc, +nmc_process_connection_properties(NmCli *nmc, + NMConnection *connection, + int *argc, const char *const **argv, gboolean allow_setting_removal, - GError ** error) + GError **error) { /* First check if we have a slave-type, as this would mean we will not * have ip properties but possibly others, slave-type specific. @@ -4970,13 +4973,13 @@ nmc_process_connection_properties(NmCli * nmc, const NMMetaSettingValidPartItem *const *type_settings; const NMMetaSettingValidPartItem *const *slv_settings; NMMetaAccessorModifier modifier; - const char * option_orig; - const char * option; - const char * value = NULL; - const char * tmp; - const NMMetaAbstractInfo * chosen = NULL; - const char * chosen_setting_name = NULL; - const char * chosen_option = NULL; + const char *option_orig; + const char *option; + const char *value = NULL; + const char *tmp; + const NMMetaAbstractInfo *chosen = NULL; + const char *chosen_setting_name = NULL; + const char *chosen_option = NULL; NMMetaSettingType s; if (!con_settings(connection, &type_settings, &slv_settings, error)) @@ -5016,7 +5019,7 @@ nmc_process_connection_properties(NmCli * nmc, if (allow_setting_removal && modifier == NM_META_ACCESSOR_MODIFIER_SET && nm_streq(option, "remove")) { - NMSetting * ss; + NMSetting *ss; const char *setting_name; (*argc)--; @@ -5060,9 +5063,9 @@ nmc_process_connection_properties(NmCli * nmc, if ((tmp = strchr(option, '.'))) { gs_free char *option_sett = g_strndup(option, tmp - option); - const char * option_prop = &tmp[1]; - const char * option_sett_expanded; - GError * local = NULL; + const char *option_prop = &tmp[1]; + const char *option_sett_expanded; + GError *local = NULL; /* This seems like a . (such as "connection.id" or "bond.mode"), * optionally prefixed with "+| or "-". */ @@ -5208,10 +5211,10 @@ static void add_connection_cb(GObject *client, GAsyncResult *result, gpointer user_data) { nm_auto_free_add_connection_info AddConnectionInfo *info = user_data; - NmCli * nmc = info->nmc; - NMRemoteConnection * connection; - GError * error = NULL; - const GPtrArray * connections; + NmCli *nmc = info->nmc; + NMRemoteConnection *connection; + GError *error = NULL; + const GPtrArray *connections; guint i, found; connection = nm_client_add_connection2_finish(NM_CLIENT(client), result, NULL, &error); @@ -5266,8 +5269,8 @@ add_connection_cb(GObject *client, GAsyncResult *result, gpointer user_data) } static void -add_connection(NMClient * client, - NMConnection * connection, +add_connection(NMClient *client, + NMConnection *connection, gboolean temporary, GAsyncReadyCallback callback, gpointer user_data) @@ -5311,10 +5314,10 @@ static char ** nmcli_con_add_tab_completion(const char *text, int start, int end) { NMMetaSettingType s; - char ** match_array = NULL; - rl_compentry_func_t * generator_func = NULL; - gs_free char * no = g_strdup_printf("[%s]: ", _("no")); - gs_free char * yes = g_strdup_printf("[%s]: ", _("yes")); + char **match_array = NULL; + rl_compentry_func_t *generator_func = NULL; + gs_free char *no = g_strdup_printf("[%s]: ", _("no")); + gs_free char *yes = g_strdup_printf("[%s]: ", _("yes")); const NMMetaAbstractInfo *info; /* Disable readline's default filename completion */ @@ -5379,11 +5382,11 @@ next: static void ask_option(NmCli *nmc, NMConnection *connection, const NMMetaAbstractInfo *abstract_info) { - char * value; - GError * error = NULL; - gs_free char * prompt = NULL; + char *value; + GError *error = NULL; + gs_free char *prompt = NULL; gboolean multi; - const char * opt_prompt, *opt_def_hint; + const char *opt_prompt, *opt_def_hint; NMMetaPropertyInfFlags inf_flags; _meta_abstract_get(abstract_info, @@ -5420,8 +5423,8 @@ again: static NMMetaSettingType connection_get_base_meta_setting_type(NMConnection *connection) { - const char * connection_type; - NMSetting * base_setting; + const char *connection_type; + NMSetting *base_setting; const NMMetaSettingInfoEditor *editor; connection_type = nm_connection_get_connection_type(connection); @@ -5438,7 +5441,7 @@ static void questionnaire_mandatory_ask_setting(NmCli *nmc, NMConnection *connection, NMMetaSettingType type) { const NMMetaSettingInfoEditor *editor; - const NMMetaPropertyInfo * property_info; + const NMMetaPropertyInfo *property_info; guint p; editor = &nm_meta_setting_infos_editor[type]; @@ -5516,7 +5519,7 @@ want_provide_opt_args(const NmcConfig *nmc_config, const char *type, guint num) static gboolean questionnaire_one_optional(NmCli *nmc, NMConnection *connection) { - NMMetaSettingType base; + NMMetaSettingType base; gs_unref_ptrarray GPtrArray *infos = NULL; guint i, j; gboolean already_confirmed = FALSE; @@ -5600,11 +5603,11 @@ static void do_connection_add(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - gs_free_error GError *error = NULL; - gboolean save_bool = TRUE; - gboolean seen_dash_dash = FALSE; - NMMetaSettingType s; + NMSettingConnection *s_con; + gs_free_error GError *error = NULL; + gboolean save_bool = TRUE; + gboolean seen_dash_dash = FALSE; + NMMetaSettingType s; next_arg(nmc, &argc, &argv, NULL); @@ -5679,8 +5682,8 @@ read_properties: /* If only bother when there's a type, which is not guaranteed at this point. * Otherwise, the validation will fail anyway. */ if (type) { - gs_free char * try_name = NULL; - gs_free char * default_name = NULL; + gs_free char *try_name = NULL; + gs_free char *default_name = NULL; const GPtrArray *connections; connections = nm_client_get_connections(nmc->client); @@ -5769,10 +5772,10 @@ static void uuid_display_hook(char **array, int len, int max_len) { const GPtrArray *connections; - NMConnection * con; + NMConnection *con; int i, max = 0; - char * tmp; - const char * id; + char *tmp; + const char *id; for (i = 1; i <= len; i++) { connections = nm_client_get_connections(nmc_tab_completion.nmc->client); con = nmc_find_connection(connections, "uuid", array[i], NULL, FALSE); @@ -5842,12 +5845,12 @@ static char * gen_cmd_print0(const char *text, int state) { static char **words = NULL; - char * ret = NULL; + char *ret = NULL; if (!state) { - GVariant * settings; + GVariant *settings; GVariantIter iter; - const char * setting_name; + const char *setting_name; int i = 0; settings = nm_connection_to_dbus(nmc_tab_completion.connection, @@ -5888,9 +5891,9 @@ gen_cmd_save(const char *text, int state) static rl_compentry_func_t * gen_connection_types(const char *text) { - gs_free char ** values = NULL; + gs_free char **values = NULL; const NMMetaSettingInfoEditor *editor; - GPtrArray * array; + GPtrArray *array; int i; array = g_ptr_array_new(); @@ -5918,10 +5921,10 @@ static char * gen_setting_names(const char *text, int state) { static int list_idx, len, is_slv; - const char * s_name, *a_name; + const char *s_name, *a_name; const NMMetaSettingValidPartItem *const *valid_settings_arr; - NMSettingConnection * s_con; - const char * s_type = NULL; + NMSettingConnection *s_con; + const char *s_type = NULL; if (!state) { list_idx = 0; @@ -5982,16 +5985,16 @@ gen_setting_names(const char *text, int state) static char * gen_property_names(const char *text, int state) { - NMSetting * setting = NULL; - char ** valid_props = NULL; - char * ret = NULL; - const char * line = rl_line_buffer; - const char * setting_name; - char ** strv = NULL; + NMSetting *setting = NULL; + char **valid_props = NULL; + char *ret = NULL; + const char *line = rl_line_buffer; + const char *setting_name; + char **strv = NULL; const NMMetaSettingValidPartItem *const *valid_settings_main; const NMMetaSettingValidPartItem *const *valid_settings_slave; - const char * p1; - const char * slv_type; + const char *p1; + const char *slv_type; /* Try to get the setting from 'line' - setting_name.property */ p1 = strchr(line, '.'); @@ -6046,8 +6049,8 @@ gen_compat_devices(const char *text, int state) { guint i, j = 0; const GPtrArray *devices; - const char ** compatible_devices; - char * ret; + const char **compatible_devices; + char *ret; devices = nm_client_get_devices(nmc_tab_completion.nmc->client); if (devices->len == 0) @@ -6055,9 +6058,9 @@ gen_compat_devices(const char *text, int state) compatible_devices = g_new(const char *, devices->len + 1); for (i = 0; i < devices->len; i++) { - NMDevice * dev = g_ptr_array_index(devices, i); + NMDevice *dev = g_ptr_array_index(devices, i); const char *ifname = nm_device_get_iface(dev); - NMDevice * device = NULL; + NMDevice *device = NULL; const char *spec_object = NULL; if (find_device_for_connection(nmc_tab_completion.nmc, @@ -6091,7 +6094,7 @@ _create_vpn_array(const GPtrArray *connections, gboolean uuid) array = g_new(const char *, connections->len + 1); for (c = 0; c < connections->len; c++) { NMConnection *connection = NM_CONNECTION(connections->pdata[c]); - const char * type = nm_connection_get_connection_type(connection); + const char *type = nm_connection_get_connection_type(connection); if (nm_streq0(type, NM_SETTING_VPN_SETTING_NAME)) array[idx++] = @@ -6105,8 +6108,8 @@ static char * gen_vpn_uuids(const char *text, int state) { const GPtrArray *connections; - const char ** uuids; - char * ret; + const char **uuids; + char *ret; connections = nm_client_get_connections(nm_cli_global_readline->client); if (connections->len < 1) @@ -6122,8 +6125,8 @@ static char * gen_vpn_ids(const char *text, int state) { const GPtrArray *connections; - const char ** ids; - char * ret; + const char **ids; + char *ret; connections = nm_client_get_connections(nm_cli_global_readline->client); if (connections->len < 1) @@ -6171,7 +6174,7 @@ get_gen_func_cmd_nmcli(const char *str) static gboolean should_complete_cmd(const char *line, int end, const char *cmd, int *cw_num, char **prev_word) { - char * tmp; + char *tmp; const char *word1, *word2, *word3; size_t n1, n2, n3, n4, n5, n6; gboolean word1_done, word2_done, word3_done; @@ -6305,17 +6308,17 @@ static void get_setting_and_property(const char *prompt, const char *line, NMSetting **setting_out, - char ** property_out) + char **property_out) { const NMMetaSettingValidPartItem *const *valid_settings_main; const NMMetaSettingValidPartItem *const *valid_settings_slave; - gs_unref_object NMSetting *setting = NULL; - gs_free char * property = NULL; - NMSettingConnection * s_con; - gs_free char * sett = NULL; - gs_free char * prop = NULL; - const char * s_type = NULL; - const char * setting_name; + gs_unref_object NMSetting *setting = NULL; + gs_free char *property = NULL; + NMSettingConnection *s_con; + gs_free char *sett = NULL; + gs_free char *prop = NULL; + const char *s_type = NULL; + const char *setting_name; extract_setting_and_property(prompt, line, &sett, &prop); @@ -6345,11 +6348,11 @@ get_setting_and_property(const char *prompt, } static gboolean -_get_and_check_property(const char * prompt, - const char * line, +_get_and_check_property(const char *prompt, + const char *line, const char **array, const char **array_multi, - gboolean * multi) + gboolean *multi) { gs_free char *prop = NULL; gboolean found = FALSE; @@ -6398,8 +6401,8 @@ static const char *const * get_allowed_property_values(char ***out_to_free) { gs_unref_object NMSetting *setting = NULL; - gs_free char * property = NULL; - const char *const * avals = NULL; + gs_free char *property = NULL; + const char *const *avals = NULL; get_setting_and_property(rl_prompt, rl_line_buffer, &setting, &property); if (setting && property) @@ -6444,7 +6447,7 @@ static gboolean should_complete_boolean(const char *prompt, const char *line) { gs_unref_object NMSetting *setting = NULL; - gs_free char * property = NULL; + gs_free char *property = NULL; get_setting_and_property(prompt, line, &setting, &property); return setting && property && _setting_property_is_boolean(setting, property); @@ -6477,10 +6480,10 @@ static char ** nmcli_editor_tab_completion(const char *text, int start, int end) { rl_compentry_func_t *generator_func = NULL; - const char * line = rl_line_buffer; - gs_free char * prompt_tmp = NULL; - gs_free char * word = NULL; - char ** match_array = NULL; + const char *line = rl_line_buffer; + gs_free char *prompt_tmp = NULL; + gs_free char *word = NULL; + char **match_array = NULL; size_t n1; int num; @@ -6615,11 +6618,11 @@ static void load_history_cmds(const char *uuid) { GKeyFile *kf; - char * filename; - char ** keys; - char * line; + char *filename; + char **keys; + char *line; size_t i; - GError * err = NULL; + GError *err = NULL; filename = g_build_filename(g_get_home_dir(), NMCLI_EDITOR_HISTORY, NULL); kf = g_key_file_new(); @@ -6645,13 +6648,13 @@ load_history_cmds(const char *uuid) static void save_history_cmds(const char *uuid) { - nm_auto_unref_keyfile GKeyFile *kf = NULL; - gs_free_error GError *error = NULL; - gs_free char * filename = NULL; - gs_free char * data = NULL; - HIST_ENTRY ** hist; - gsize len; - gsize i; + nm_auto_unref_keyfile GKeyFile *kf = NULL; + gs_free_error GError *error = NULL; + gs_free char *filename = NULL; + gs_free char *data = NULL; + HIST_ENTRY **hist; + gsize len; + gsize i; hist = history_list(); if (!hist) @@ -6723,13 +6726,14 @@ typedef enum { NMC_EDITOR_MAIN_CMD_HELP, NMC_EDITOR_MAIN_CMD_NMCLI, NMC_EDITOR_MAIN_CMD_QUIT, + NMC_EDITOR_MAIN_CMD_ADD, } NmcEditorMainCmd; static void _split_cmd(const char *cmd, char **out_arg0, const char **out_argr) { gs_free char *arg0 = NULL; - const char * argr = NULL; + const char *argr = NULL; gsize l; NM_SET_OUT(out_arg0, NULL); @@ -6760,8 +6764,8 @@ static NmcEditorMainCmd parse_editor_main_cmd(const char *cmd, char **cmd_arg) { NmcEditorMainCmd editor_cmd = NMC_EDITOR_MAIN_CMD_UNKNOWN; - gs_free char * cmd_arg0 = NULL; - const char * cmd_argr; + gs_free char *cmd_arg0 = NULL; + const char *cmd_argr; _split_cmd(cmd, &cmd_arg0, &cmd_argr); if (!cmd_arg0) @@ -6773,6 +6777,8 @@ parse_editor_main_cmd(const char *cmd, char **cmd_arg) editor_cmd = NMC_EDITOR_MAIN_CMD_REMOVE; else if (matches(cmd_arg0, "set")) editor_cmd = NMC_EDITOR_MAIN_CMD_SET; + else if (matches(cmd_arg0, "add")) + editor_cmd = NMC_EDITOR_MAIN_CMD_ADD; else if (matches(cmd_arg0, "describe")) editor_cmd = NMC_EDITOR_MAIN_CMD_DESCRIBE; else if (matches(cmd_arg0, "print")) @@ -6854,6 +6860,11 @@ editor_main_help(const char *command) "This command sets property value.\n\n" "Example: nmcli> set con.id My connection\n")); break; + case NMC_EDITOR_MAIN_CMD_ADD: + g_print(_("add [. ] :: add property value\n\n" + "This command appends property value.\n\n" + "Example: nmcli> add ipv4.addresses 192.168.1.1/24\n")); + break; case NMC_EDITOR_MAIN_CMD_DESCRIBE: g_print(_("describe [.] :: describe property\n\n" "Shows property description. You can consult nm-settings(5) " @@ -6951,8 +6962,8 @@ static NmcEditorSubCmd parse_editor_sub_cmd(const char *cmd, char **cmd_arg) { NmcEditorSubCmd editor_cmd = NMC_EDITOR_SUB_CMD_UNKNOWN; - gs_free char * cmd_arg0 = NULL; - const char * cmd_argr; + gs_free char *cmd_arg0 = NULL; + const char *cmd_argr; _split_cmd(cmd, &cmd_arg0, &cmd_argr); if (!cmd_arg0) @@ -7074,14 +7085,14 @@ editor_sub_usage(const char *command) /*****************************************************************************/ typedef struct { - NMDevice * device; + NMDevice *device; NMActiveConnection *ac; guint monitor_id; - NmCli * nmc; + NmCli *nmc; } MonitorACInfo; static gboolean nmc_editor_cb_called; -static GError * nmc_editor_error; +static GError *nmc_editor_error; static MonitorACInfo *nmc_editor_monitor_ac; static void @@ -7107,7 +7118,7 @@ static void add_connection_editor_cb(GObject *client, GAsyncResult *result, gpointer user_data) { gs_unref_object NMRemoteConnection *connection = NULL; - gs_free_error GError *error = NULL; + gs_free_error GError *error = NULL; connection = nm_client_add_connection2_finish(NM_CLIENT(client), result, NULL, &error); set_info_and_signal_editor_thread(error, NULL); @@ -7126,9 +7137,9 @@ update_connection_editor_cb(GObject *connection, GAsyncResult *result, gpointer static gboolean progress_activation_editor_cb(gpointer user_data) { - MonitorACInfo * info = (MonitorACInfo *) user_data; - NMDevice * device = info->device; - NMActiveConnection * ac = info->ac; + MonitorACInfo *info = (MonitorACInfo *) user_data; + NMDevice *device = info->device; + NMActiveConnection *ac = info->ac; NMActiveConnectionState ac_state; NMDeviceState dev_state; @@ -7174,11 +7185,11 @@ static void activate_connection_editor_cb(GObject *client, GAsyncResult *result, gpointer user_data) { ActivateConnectionInfo *info = (ActivateConnectionInfo *) user_data; - NMDevice * device = info->device; - const GPtrArray * ac_devs; - MonitorACInfo * monitor_ac_info = NULL; - NMActiveConnection * active; - GError * error = NULL; + NMDevice *device = info->device; + const GPtrArray *ac_devs; + MonitorACInfo *monitor_ac_info = NULL; + NMActiveConnection *active; + GError *error = NULL; active = nm_client_activate_connection_finish(NM_CLIENT(client), result, &error); @@ -7237,7 +7248,7 @@ static void editor_show_status_line(NMConnection *connection, gboolean dirty, gboolean temp) { NMSettingConnection *s_con; - const char * con_type, *con_id, *con_uuid; + const char *con_type, *con_id, *con_uuid; s_con = nm_connection_get_setting_connection(connection); g_assert(s_con); @@ -7296,17 +7307,17 @@ confirm_quit(const NmcConfig *nmc_config) * Return: TRUE - continue; FALSE - should quit */ static gboolean -property_edit_submenu(NmCli * nmc, - NMConnection * connection, +property_edit_submenu(NmCli *nmc, + NMConnection *connection, NMRemoteConnection **rem_con, - GWeakRef * rem_con_weak, - NMSetting * curr_setting, - const char * prop_name) + GWeakRef *rem_con_weak, + NMSetting *curr_setting, + const char *prop_name) { NmcEditorSubCmd cmdsub; gboolean set_result; - GError * tmp_err = NULL; - gs_free char * prompt = NULL; + GError *tmp_err = NULL; + gs_free char *prompt = NULL; gboolean temp_changes; /* Set global variable for use in TAB completion */ @@ -7467,8 +7478,8 @@ static void split_editor_main_cmd_args(const char *str, char **setting, char **property, char **value) { gs_free char *cmd_arg0 = NULL; - const char * cmd_argr; - const char * s; + const char *cmd_argr; + const char *s; NM_SET_OUT(setting, NULL); NM_SET_OUT(property, NULL); @@ -7489,12 +7500,12 @@ split_editor_main_cmd_args(const char *str, char **setting, char **property, cha } static NMSetting * -create_setting_by_name(const char * name, +create_setting_by_name(const char *name, const NMMetaSettingValidPartItem *const *valid_settings_main, const NMMetaSettingValidPartItem *const *valid_settings_slave) { const char *setting_name; - NMSetting * setting = NULL; + NMSetting *setting = NULL; /* Get a valid setting name */ setting_name = check_valid_name(name, valid_settings_main, valid_settings_slave, NULL); @@ -7508,15 +7519,15 @@ create_setting_by_name(const char * name, } static const char * -ask_check_setting(const NmcConfig * nmc_config, - const char * arg, +ask_check_setting(const NmcConfig *nmc_config, + const char *arg, const NMMetaSettingValidPartItem *const *valid_settings_main, const NMMetaSettingValidPartItem *const *valid_settings_slave, - const char * valid_settings_str) + const char *valid_settings_str) { gs_free char *setting_name_user = NULL; - const char * setting_name; - GError * err = NULL; + const char *setting_name; + GError *err = NULL; if (!arg) { g_print(_("Available settings: %s\n"), valid_settings_str); @@ -7538,13 +7549,13 @@ ask_check_setting(const NmcConfig * nmc_config, static const char * ask_check_property(const NmcConfig *nmc_config, - const char * arg, - const char ** valid_props, - const char * valid_props_str) + const char *arg, + const char **valid_props, + const char *valid_props_str) { gs_free_error GError *tmp_err = NULL; - gs_free char * prop_name_user = NULL; - const char * prop_name; + gs_free char *prop_name_user = NULL; + const char *prop_name; if (!arg) { g_print(_("Available properties: %s\n"), valid_props_str); @@ -7609,16 +7620,16 @@ confirm_connection_saving(const NmcConfig *nmc_config, NMConnection *local, NMCo typedef struct { guint level; - char * main_prompt; + char *main_prompt; NMSetting *curr_setting; - char ** valid_props; - char * valid_props_str; + char **valid_props; + char *valid_props_str; } NmcEditorMenuContext; static void -menu_switch_to_level0(const NmcConfig * nmc_config, +menu_switch_to_level0(const NmcConfig *nmc_config, NmcEditorMenuContext *menu_ctx, - const char * prompt) + const char *prompt) { menu_ctx->level = 0; g_free(menu_ctx->main_prompt); @@ -7631,10 +7642,10 @@ menu_switch_to_level0(const NmcConfig * nmc_config, } static void -menu_switch_to_level1(const NmcConfig * nmc_config, +menu_switch_to_level1(const NmcConfig *nmc_config, NmcEditorMenuContext *menu_ctx, - NMSetting * setting, - const char * setting_name) + NMSetting *setting, + const char *setting_name) { menu_ctx->level = 1; g_free(menu_ctx->main_prompt); @@ -7660,19 +7671,19 @@ editor_save_timeout(gpointer user_data) static gboolean editor_menu_main(NmCli *nmc, NMConnection *connection, const char *connection_type) { - gs_unref_object NMRemoteConnection * rem_con = NULL; - NMSettingConnection * s_con; - NMRemoteConnection * con_tmp; + gs_unref_object NMRemoteConnection *rem_con = NULL; + NMSettingConnection *s_con; + NMRemoteConnection *con_tmp; GWeakRef weak = {{NULL}}; gboolean removed; NmcEditorMainCmd cmd; gboolean cmd_loop = TRUE; const NMMetaSettingValidPartItem *const *valid_settings_main; const NMMetaSettingValidPartItem *const *valid_settings_slave; - gs_free char * valid_settings_str = NULL; - const char * s_type = NULL; + gs_free char *valid_settings_str = NULL; + const char *s_type = NULL; gboolean temp_changes; - GError * err1 = NULL; + GError *err1 = NULL; NmcEditorMenuContext menu_ctx = {0}; s_con = nm_connection_get_setting_connection(connection); @@ -7724,15 +7735,16 @@ editor_menu_main(NmCli *nmc, NMConnection *connection, const char *connection_ty split_editor_main_cmd_args(cmd_arg, &cmd_arg_s, &cmd_arg_p, &cmd_arg_v); switch (cmd) { + case NMC_EDITOR_MAIN_CMD_ADD: case NMC_EDITOR_MAIN_CMD_SET: /* Set property value */ if (!cmd_arg) { if (menu_ctx.level == 1) { gs_strfreev char **avals_to_free = NULL; - gs_free char * prop_val_user = NULL; - const char * prop_name; + gs_free char *prop_val_user = NULL; + const char *prop_name; const char *const *avals; - GError * tmp_err = NULL; + GError *tmp_err = NULL; prop_name = ask_check_property(&nmc->nmc_config, cmd_arg, @@ -7769,10 +7781,10 @@ editor_menu_main(NmCli *nmc, NMConnection *connection, const char *connection_ty g_print(_("use 'goto ' first, or 'set .'\n")); } } else { - gs_free char * prop_name = NULL; + gs_free char *prop_name = NULL; gs_unref_object NMSetting *ss_created = NULL; - NMSetting * ss = NULL; - GError * tmp_err = NULL; + NMSetting *ss = NULL; + GError *tmp_err = NULL; if (cmd_arg_s) { /* setting provided as "setting.property" */ @@ -7847,7 +7859,7 @@ editor_menu_main(NmCli *nmc, NMConnection *connection, const char *connection_ty if (menu_ctx.level == 0 || cmd_arg_s) { /* in top level - no setting selected yet */ const char *setting_name; - NMSetting * setting; + NMSetting *setting; const char *user_arg = cmd_arg_s ?: cmd_arg_p; setting_name = ask_check_setting(&nmc->nmc_config, @@ -7920,7 +7932,7 @@ editor_menu_main(NmCli *nmc, NMConnection *connection, const char *connection_ty /* Remove setting from connection, or delete value of a property */ if (!cmd_arg) { if (menu_ctx.level == 1) { - GError * tmp_err = NULL; + GError *tmp_err = NULL; const char *prop_name; prop_name = ask_check_property(&nmc->nmc_config, @@ -7946,7 +7958,7 @@ editor_menu_main(NmCli *nmc, NMConnection *connection, const char *connection_ty } else { NMSetting *ss = NULL; gboolean descr_all; - char * user_s; + char *user_s; /* cmd_arg_s != NULL means argument is "setting.property" */ descr_all = !cmd_arg_s && !menu_ctx.curr_setting; @@ -7985,16 +7997,17 @@ editor_menu_main(NmCli *nmc, NMConnection *connection, const char *connection_ty nmc_tab_completion.setting = NULL; /* for TAB completion */ } } else { - gs_free char *prop_name = NULL; - gs_free_error GError *tmp_err = NULL; + gs_free char *prop_name = NULL; + gs_free_error GError *tmp_err = NULL; prop_name = is_property_valid(ss, cmd_arg_p, &tmp_err); if (prop_name) { if (!nmc_setting_set_property(nmc->client, ss, prop_name, - NM_META_ACCESSOR_MODIFIER_SET, - NULL, + cmd_arg_v ? NM_META_ACCESSOR_MODIFIER_DEL + : NM_META_ACCESSOR_MODIFIER_SET, + cmd_arg_v ? cmd_arg_v : NULL, &tmp_err)) { g_print(_("Error: failed to remove value of '%s': %s\n"), prop_name, @@ -8051,9 +8064,9 @@ editor_menu_main(NmCli *nmc, NMConnection *connection, const char *connection_ty } } else { gs_unref_object NMSetting *ss_free = NULL; - NMSetting * ss = NULL; + NMSetting *ss = NULL; gboolean descr_all; - char * user_s; + char *user_s; /* cmd_arg_s != NULL means argument is "setting.property" */ descr_all = !cmd_arg_s && !menu_ctx.curr_setting; @@ -8086,7 +8099,7 @@ editor_menu_main(NmCli *nmc, NMConnection *connection, const char *connection_ty print_setting_description(ss); } else { gs_free_error GError *tmp_err = NULL; - gs_free char * prop_name = NULL; + gs_free char *prop_name = NULL; prop_name = is_property_valid(ss, cmd_arg_p, &tmp_err); if (prop_name) { @@ -8120,7 +8133,7 @@ editor_menu_main(NmCli *nmc, NMConnection *connection, const char *connection_ty else { NMSetting *ss = NULL; gboolean whole_setting; - char * user_s; + char *user_s; /* cmd_arg_s != NULL means argument is "setting.property" */ whole_setting = !cmd_arg_s && !menu_ctx.curr_setting; @@ -8150,7 +8163,7 @@ editor_menu_main(NmCli *nmc, NMConnection *connection, const char *connection_ty editor_show_setting(ss, nmc); } else { gs_free char *prop_name = NULL; - GError * err = NULL; + GError *err = NULL; prop_name = is_property_valid(ss, cmd_arg_p, &err); if (prop_name) { @@ -8220,8 +8233,8 @@ editor_menu_main(NmCli *nmc, NMConnection *connection, const char *connection_ty case NMC_EDITOR_MAIN_CMD_SAVE: /* Save the connection */ if (nm_connection_verify(connection, &err1)) { - gboolean temporary = FALSE; - gboolean connection_changed; + gboolean temporary = FALSE; + gboolean connection_changed; nm_auto_unref_gsource GSource *source = NULL; gboolean timeout = FALSE; gulong handler_id = 0; @@ -8338,7 +8351,7 @@ editor_menu_main(NmCli *nmc, NMConnection *connection, const char *connection_ty case NMC_EDITOR_MAIN_CMD_ACTIVATE: { - GError * tmp_err = NULL; + GError *tmp_err = NULL; const char *ifname = cmd_arg_p; const char *ap_nsp = cmd_arg_v; @@ -8421,7 +8434,7 @@ editor_menu_main(NmCli *nmc, NMConnection *connection, const char *connection_ty case NMC_EDITOR_MAIN_CMD_NMCLI: if (cmd_arg_p && matches(cmd_arg_p, "status-line")) { - GError * tmp_err = NULL; + GError *tmp_err = NULL; gboolean bb; if (!nmc_string_to_bool(cmd_arg_v ? g_strstrip(cmd_arg_v) : "", &bb, &tmp_err)) { g_print(_("Error: status-line: %s\n"), tmp_err->message); @@ -8429,7 +8442,7 @@ editor_menu_main(NmCli *nmc, NMConnection *connection, const char *connection_ty } else nmc->editor_status_line = bb; } else if (cmd_arg_p && matches(cmd_arg_p, "save-confirmation")) { - GError * tmp_err = NULL; + GError *tmp_err = NULL; gboolean bb; if (!nmc_string_to_bool(cmd_arg_v ? g_strstrip(cmd_arg_v) : "", &bb, &tmp_err)) { g_print(_("Error: save-confirmation: %s\n"), tmp_err->message); @@ -8437,7 +8450,7 @@ editor_menu_main(NmCli *nmc, NMConnection *connection, const char *connection_ty } else nmc->editor_save_confirmation = bb; } else if (cmd_arg_p && matches(cmd_arg_p, "show-secrets")) { - GError * tmp_err = NULL; + GError *tmp_err = NULL; gboolean bb; if (!nmc_string_to_bool(cmd_arg_v ? g_strstrip(cmd_arg_v) : "", &bb, &tmp_err)) { g_print(_("Error: show-secrets: %s\n"), tmp_err->message); @@ -8508,9 +8521,9 @@ get_ethernet_device_name(NmCli *nmc) static void editor_init_new_connection(NmCli *nmc, NMConnection *connection, const char *slave_type) { - NMSetting * setting, *base_setting; + NMSetting *setting, *base_setting; NMSettingConnection *s_con; - const char * con_type; + const char *con_type; s_con = nm_connection_get_setting_connection(connection); g_assert(s_con); @@ -8579,9 +8592,9 @@ editor_init_new_connection(NmCli *nmc, NMConnection *connection, const char *sla static void editor_init_existing_connection(NMConnection *connection) { - NMSettingIPConfig * s_ip4, *s_ip6; - NMSettingProxy * s_proxy; - NMSettingWireless * s_wireless; + NMSettingIPConfig *s_ip4, *s_ip6; + NMSettingProxy *s_proxy; + NMSettingWireless *s_wireless; NMSettingConnection *s_con; /* FIXME: this approach of connecting handlers to do something is fundamentally @@ -8623,21 +8636,21 @@ nmc_complete_connection_type(const char *prefix) static void do_connection_edit(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - const GPtrArray *connections; + const GPtrArray *connections; gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - const char * connection_type; - const char * type = NULL; - const char * con_name = NULL; - const char * con = NULL; - const char * con_id = NULL; - const char * con_uuid = NULL; - const char * con_path = NULL; - const char * con_filename = NULL; - const char * selector = NULL; - gs_free_error GError *error = NULL; - GError * err1 = NULL; - nmc_arg_t exp_args[] = {{"type", TRUE, &type, FALSE}, + NMSettingConnection *s_con; + const char *connection_type; + const char *type = NULL; + const char *con_name = NULL; + const char *con = NULL; + const char *con_id = NULL; + const char *con_uuid = NULL; + const char *con_path = NULL; + const char *con_filename = NULL; + const char *selector = NULL; + gs_free_error GError *error = NULL; + GError *err1 = NULL; + nmc_arg_t exp_args[] = {{"type", TRUE, &type, FALSE}, {"con-name", TRUE, &con_name, FALSE}, {"id", TRUE, &con_id, FALSE}, {"uuid", TRUE, &con_uuid, FALSE}, @@ -8731,7 +8744,7 @@ do_connection_edit(const NMCCommand *cmd, NmCli *nmc, int argc, const char *cons editor_init_existing_connection(connection); } else { - const char * slave_type = NULL; + const char *slave_type = NULL; gs_free char *uuid = NULL; gs_free char *default_name = NULL; gs_free char *tmp_str = NULL; @@ -8825,7 +8838,7 @@ do_connection_edit(const NMCCommand *cmd, NmCli *nmc, int argc, const char *cons static void modify_connection_cb(GObject *connection, GAsyncResult *result, gpointer user_data) { - NmCli * nmc = user_data; + NmCli *nmc = user_data; gs_free_error GError *error = NULL; if (!nm_remote_connection_commit_changes_finish(NM_REMOTE_CONNECTION(connection), @@ -8849,10 +8862,10 @@ modify_connection_cb(GObject *connection, GAsyncResult *result, gpointer user_da static void do_connection_modify(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - NMConnection * connection = NULL; - NMRemoteConnection *rc = NULL; - gs_free_error GError *error = NULL; - gboolean temporary = FALSE; + NMConnection *connection = NULL; + NMRemoteConnection *rc = NULL; + gs_free_error GError *error = NULL; + gboolean temporary = FALSE; if (next_arg(nmc, &argc, &argv, "--temporary", NULL) > 0) { temporary = TRUE; @@ -8891,10 +8904,10 @@ do_connection_modify(const NMCCommand *cmd, NmCli *nmc, int argc, const char *co static void clone_connection_cb(GObject *client, GAsyncResult *result, gpointer user_data) { - nm_auto_free_add_connection_info AddConnectionInfo *info = user_data; - NmCli * nmc = info->nmc; - gs_unref_object NMRemoteConnection *connection = NULL; - gs_free_error GError *error = NULL; + nm_auto_free_add_connection_info AddConnectionInfo *info = user_data; + NmCli *nmc = info->nmc; + gs_unref_object NMRemoteConnection *connection = NULL; + gs_free_error GError *error = NULL; connection = nm_client_add_connection2_finish(NM_CLIENT(client), result, NULL, &error); if (error) { @@ -8917,17 +8930,17 @@ clone_connection_cb(GObject *client, GAsyncResult *result, gpointer user_data) static void do_connection_clone(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - NMConnection * connection = NULL; + NMConnection *connection = NULL; gs_unref_object NMConnection *new_connection = NULL; - const char * new_name; - gs_free char * new_name_free = NULL; - gs_free char * uuid = NULL; + const char *new_name; + gs_free char *new_name_free = NULL; + gs_free char *uuid = NULL; gboolean temporary = FALSE; - gs_strfreev char ** arg_arr = NULL; + gs_strfreev char **arg_arr = NULL; int arg_num; - const char *const ** argv_ptr; - int * argc_ptr; - GError * error = NULL; + const char *const **argv_ptr; + int *argc_ptr; + GError *error = NULL; if (next_arg(nmc, &argc, &argv, "--temporary", NULL) > 0) { temporary = TRUE; @@ -8999,7 +9012,7 @@ static void delete_cb(GObject *con, GAsyncResult *result, gpointer user_data) { ConnectionCbInfo *info = (ConnectionCbInfo *) user_data; - GError * error = NULL; + GError *error = NULL; if (!nm_remote_connection_delete_finish(NM_REMOTE_CONNECTION(con), result, &error)) { if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) @@ -9018,15 +9031,15 @@ delete_cb(GObject *con, GAsyncResult *result, gpointer user_data) static void do_connection_delete(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - NMConnection * connection; - ConnectionCbInfo * info = NULL; - gs_strfreev char ** arg_arr = NULL; - const char *const * arg_ptr; - guint i; - int arg_num; + NMConnection *connection; + ConnectionCbInfo *info = NULL; + gs_strfreev char **arg_arr = NULL; + const char *const *arg_ptr; + guint i; + int arg_num; nm_auto_free_gstring GString *invalid_cons = NULL; - gs_unref_ptrarray GPtrArray *found_cons = NULL; - GError * error = NULL; + gs_unref_ptrarray GPtrArray *found_cons = NULL; + GError *error = NULL; if (nmc->timeout == -1) nmc->timeout = 10; @@ -9168,10 +9181,10 @@ connection_removed(NMClient *client, NMRemoteConnection *con, NmCli *nmc) static void do_connection_monitor(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - GError * error = NULL; - guint i; + GError *error = NULL; + guint i; gs_unref_ptrarray GPtrArray *found_cons = NULL; - const GPtrArray * connections = NULL; + const GPtrArray *connections = NULL; next_arg(nmc, &argc, &argv, NULL); if (argc == 0) { @@ -9222,9 +9235,9 @@ do_connection_monitor(const NMCCommand *cmd, NmCli *nmc, int argc, const char *c static void connection_reload_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - NmCli * nmc = user_data; - gs_free_error GError *error = NULL; - gs_unref_variant GVariant *ret = NULL; + NmCli *nmc = user_data; + gs_free_error GError *error = NULL; + gs_unref_variant GVariant *ret = NULL; ret = nm_dbus_call_finish(result, &error); if (error) { @@ -9261,10 +9274,10 @@ do_connection_reload(const NMCCommand *cmd, NmCli *nmc, int argc, const char *co static void do_connection_load(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - GError * error = NULL; + GError *error = NULL; gs_strfreev char **filenames = NULL; gs_strfreev char **failures = NULL; - gs_free char * current_dir = NULL; + gs_free char *current_dir = NULL; int i; next_arg(nmc, &argc, &argv, NULL); @@ -9318,13 +9331,13 @@ do_connection_load(const NMCCommand *cmd, NmCli *nmc, int argc, const char *cons static void do_connection_import(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - gs_free_error GError *error = NULL; - const char * type = NULL, *filename = NULL; - gs_free char * type_ask = NULL; - gs_free char * filename_ask = NULL; - gs_unref_object NMConnection *connection = NULL; - NMVpnEditorPlugin * plugin; - gs_free char * service_type = NULL; + gs_free_error GError *error = NULL; + const char *type = NULL, *filename = NULL; + gs_free char *type_ask = NULL; + gs_free char *filename_ask = NULL; + gs_unref_object NMConnection *connection = NULL; + NMVpnEditorPlugin *plugin; + gs_free char *service_type = NULL; gboolean temporary = FALSE; /* Check --temporary */ @@ -9457,18 +9470,18 @@ do_connection_import(const NMCCommand *cmd, NmCli *nmc, int argc, const char *co static void do_connection_export(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - NMConnection * connection = NULL; - const char * out_name = NULL; - gs_free char * out_name_ask = NULL; - const char * path = NULL; - const char * type = NULL; - NMVpnEditorPlugin *plugin; + NMConnection *connection = NULL; + const char *out_name = NULL; + gs_free char *out_name_ask = NULL; + const char *path = NULL; + const char *type = NULL; + NMVpnEditorPlugin *plugin; gs_free_error GError *error = NULL; char tmpfile[] = "/tmp/nmcli-export-temp-XXXXXX"; - gs_strfreev char ** arg_arr = NULL; + gs_strfreev char **arg_arr = NULL; int arg_num; - const char *const ** argv_ptr; - int * argc_ptr; + const char *const **argv_ptr; + int *argc_ptr; next_arg(nmc, &argc, &argv, NULL); argv_ptr = &argv; @@ -9577,8 +9590,8 @@ gen_func_connection_names(const char *text, int state) { guint i; const GPtrArray *connections; - const char ** connection_names; - char * ret; + const char **connection_names; + char *ret; connections = nm_client_get_connections(nm_cli_global_readline->client); if (connections->len == 0) @@ -9600,8 +9613,8 @@ gen_func_active_connection_names(const char *text, int state) { guint i; const GPtrArray *acs; - const char ** connections; - char * ret; + const char **connections; + char *ret; if (!nm_cli_global_readline->client) return NULL; @@ -9624,8 +9637,8 @@ gen_func_active_connection_names(const char *text, int state) static char ** nmcli_con_tab_completion(const char *text, int start, int end) { - char ** match_array = NULL; - rl_compentry_func_t * generator_func = NULL; + char **match_array = NULL; + rl_compentry_func_t *generator_func = NULL; const NMMetaAbstractInfo *info; /* Disable readline's default filename completion */ diff --git a/src/nmcli/connections.h b/src/nmcli/connections.h index 74c1fe00..782c4eaf 100644 --- a/src/nmcli/connections.h +++ b/src/nmcli/connections.h @@ -10,12 +10,12 @@ void monitor_connections(NmCli *nmc); -gboolean nmc_process_connection_properties(NmCli * nmc, - NMConnection * connection, - int * argc, +gboolean nmc_process_connection_properties(NmCli *nmc, + NMConnection *connection, + int *argc, const char *const **argv, gboolean allow_remove_setting, - GError ** error); + GError **error); NMMetaColor nmc_active_connection_state_to_color(NMActiveConnection *ac); diff --git a/src/nmcli/devices.c b/src/nmcli/devices.c index d2e472a0..e23ef681 100644 --- a/src/nmcli/devices.c +++ b/src/nmcli/devices.c @@ -93,9 +93,10 @@ wifi_signal_to_color(guint8 strength) /*****************************************************************************/ -static gconstpointer _metagen_device_status_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) +static gconstpointer +_metagen_device_status_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) { - NMDevice * d = target; + NMDevice *d = target; NMActiveConnection *ac; NMC_HANDLE_COLOR(nmc_device_state_to_color(d)); @@ -152,13 +153,14 @@ const NmcMetaGenericInfo /*****************************************************************************/ -static gconstpointer _metagen_device_detail_general_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) +static gconstpointer +_metagen_device_detail_general_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) { - NMDevice * d = target; + NMDevice *d = target; NMActiveConnection *ac; NMDeviceStateReason state_reason; NMConnectivityState connectivity; - const char * s; + const char *s; NMC_HANDLE_COLOR(NM_META_COLOR_NONE); @@ -317,7 +319,7 @@ static NMRemoteConnection ** _device_get_available_connections(NMDevice *d, guint *out_len) { NMRemoteConnection **avail_cons; - const GPtrArray * avail_cons_arr; + const GPtrArray *avail_cons_arr; avail_cons_arr = nm_device_get_available_connections(d); if (!avail_cons_arr || avail_cons_arr->len == 0) { @@ -333,15 +335,16 @@ _device_get_available_connections(NMDevice *d, guint *out_len) return avail_cons; } -static gconstpointer _metagen_device_detail_connections_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) +static gconstpointer +_metagen_device_detail_connections_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) { - NMDevice *d = target; + NMDevice *d = target; gs_free NMRemoteConnection **avail_cons = NULL; guint avail_cons_len; guint i; guint j; - char ** arr = NULL; - GString * str; + char **arr = NULL; + GString *str; gboolean had_prefix; gboolean has_prefix; @@ -360,8 +363,8 @@ static gconstpointer _metagen_device_detail_connections_get_fcn(NMC_META_GENERIC j = 0; for (i = 0; i < avail_cons_len; i++) { NMRemoteConnection *ac = avail_cons[i]; - const char * ac_id = nm_connection_get_id(NM_CONNECTION(ac)); - const char * ac_uuid = nm_connection_get_uuid(NM_CONNECTION(ac)); + const char *ac_id = nm_connection_get_id(NM_CONNECTION(ac)); + const char *ac_uuid = nm_connection_get_uuid(NM_CONNECTION(ac)); if (!ac_id || !ac_uuid) { const char *ac_path = nm_connection_get_path(NM_CONNECTION(ac)); @@ -390,7 +393,7 @@ static gconstpointer _metagen_device_detail_connections_get_fcn(NMC_META_GENERIC had_prefix = FALSE; for (i = 0; i < avail_cons_len; i++) { NMRemoteConnection *ac = avail_cons[i]; - const char * p = nm_connection_get_path(NM_CONNECTION(ac)); + const char *p = nm_connection_get_path(NM_CONNECTION(ac)); if (!p) continue; @@ -447,9 +450,10 @@ const NmcMetaGenericInfo *const /*****************************************************************************/ -static gconstpointer _metagen_device_detail_capabilities_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) +static gconstpointer +_metagen_device_detail_capabilities_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) { - NMDevice * d = target; + NMDevice *d = target; NMDeviceCapabilities caps; guint32 speed; @@ -511,7 +515,7 @@ const NmcMetaGenericInfo /*****************************************************************************/ static gconstpointer - _metagen_device_detail_wired_properties_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) +_metagen_device_detail_wired_properties_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) { NMDevice *d = target; @@ -552,9 +556,9 @@ const NmcMetaGenericInfo *const /*****************************************************************************/ static gconstpointer - _metagen_device_detail_wifi_properties_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) +_metagen_device_detail_wifi_properties_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) { - NMDevice * d = target; + NMDevice *d = target; NMDeviceWifiCapabilities wcaps; NMC_HANDLE_COLOR(NM_META_COLOR_NONE); @@ -649,9 +653,9 @@ const NmcMetaGenericInfo *const /*****************************************************************************/ static gconstpointer - _metagen_device_detail_interface_flags_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) +_metagen_device_detail_interface_flags_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) { - NMDevice * d = target; + NMDevice *d = target; NMDeviceInterfaceFlags flags; NMC_HANDLE_COLOR(NM_META_COLOR_NONE); @@ -1049,8 +1053,8 @@ quit(void) static int compare_devices(const void *a, const void *b) { - NMDevice * da = *(NMDevice **) a; - NMDevice * db = *(NMDevice **) b; + NMDevice *da = *(NMDevice **) a; + NMDevice *db = *(NMDevice **) b; NMActiveConnection *da_ac = nm_device_get_active_connection(da); NMActiveConnection *db_ac = nm_device_get_active_connection(db); @@ -1067,7 +1071,7 @@ NMDevice ** nmc_get_devices_sorted(NMClient *client) { const GPtrArray *devs; - NMDevice ** sorted; + NMDevice **sorted; devs = nm_client_get_devices(client); @@ -1111,9 +1115,9 @@ get_device_list(NmCli *nmc, int argc, const char *const *argv) int arg_num = argc; gs_strfreev char **arg_arr = NULL; const char *const *arg_ptr = argv; - NMDevice ** devices; - GSList * queue = NULL; - NMDevice * device; + NMDevice **devices; + GSList *queue = NULL; + NMDevice *device; int i; if (argc == 0) { @@ -1171,8 +1175,8 @@ static NMDevice * get_device(NmCli *nmc, int *argc, const char *const **argv, GError **error) { gs_free NMDevice **devices = NULL; - gs_free char * ifname_ask = NULL; - const char * ifname = NULL; + gs_free char *ifname_ask = NULL; + const char *ifname = NULL; int i; if (*argc == 0) { @@ -1245,39 +1249,39 @@ sort_access_points(const GPtrArray *aps) } typedef struct { - NmCli * nmc; + NmCli *nmc; int index; guint32 output_flags; const char *active_bssid; const char *device; - GPtrArray * output_data; + GPtrArray *output_data; } APInfo; static void fill_output_access_point(gpointer data, gpointer user_data) { - NMAccessPoint * ap = NM_ACCESS_POINT(data); - APInfo * info = (APInfo *) user_data; - NmcOutputField * arr; + NMAccessPoint *ap = NM_ACCESS_POINT(data); + APInfo *info = (APInfo *) user_data; + NmcOutputField *arr; gboolean active = FALSE; NM80211ApFlags flags; NM80211ApSecurityFlags wpa_flags, rsn_flags; guint32 freq, bitrate; guint8 strength; - GBytes * ssid; - const char * bssid; + GBytes *ssid; + const char *bssid; NM80211Mode mode; - char * channel_str; - char * freq_str; - char * ssid_str = NULL; - char * ssid_hex_str = NULL; - char * bitrate_str; - char * strength_str; - char * wpa_flags_str; - char * rsn_flags_str; - GString * security_str; - char * ap_name; - const char * sig_bars; + char *channel_str; + char *freq_str; + char *ssid_str = NULL; + char *ssid_hex_str = NULL; + char *bitrate_str; + char *strength_str; + char *wpa_flags_str; + char *rsn_flags_str; + GString *security_str; + char *ap_name; + const char *sig_bars; NMMetaColor color; if (info->active_bssid) { @@ -1413,16 +1417,16 @@ construct_header_name(const char *base, const char *spec) } static gboolean -print_bond_bridge_info(NMDevice * device, - NmCli * nmc, +print_bond_bridge_info(NMDevice *device, + NmCli *nmc, const char *group_prefix, const char *one_field) { - const GPtrArray * slaves = NULL; - GString * slaves_str; + const GPtrArray *slaves = NULL; + GString *slaves_str; int idx; const NMMetaAbstractInfo *const *tmpl; - NmcOutputField * arr; + NmcOutputField *arr; NMC_OUTPUT_DATA_DEFINE_SCOPED(out); if (NM_IS_DEVICE_BOND(device)) @@ -1434,7 +1438,7 @@ print_bond_bridge_info(NMDevice * device, slaves_str = g_string_new(NULL); for (idx = 0; slaves && idx < slaves->len; idx++) { - NMDevice * slave = g_ptr_array_index(slaves, idx); + NMDevice *slave = g_ptr_array_index(slaves, idx); const char *iface = nm_device_get_iface(slave); if (iface) { @@ -1483,11 +1487,11 @@ sanitize_team_config(const char *config) static gboolean print_team_info(NMDevice *device, NmCli *nmc, const char *group_prefix, const char *one_field) { - const GPtrArray * slaves = NULL; - GString * slaves_str; + const GPtrArray *slaves = NULL; + GString *slaves_str; int idx; const NMMetaAbstractInfo *const *tmpl; - NmcOutputField * arr; + NmcOutputField *arr; NMC_OUTPUT_DATA_DEFINE_SCOPED(out); if (NM_IS_DEVICE_TEAM(device)) @@ -1497,7 +1501,7 @@ print_team_info(NMDevice *device, NmCli *nmc, const char *group_prefix, const ch slaves_str = g_string_new(NULL); for (idx = 0; slaves && idx < slaves->len; idx++) { - NMDevice * slave = g_ptr_array_index(slaves, idx); + NMDevice *slave = g_ptr_array_index(slaves, idx); const char *iface = nm_device_get_iface(slave); if (iface) { @@ -1528,18 +1532,18 @@ print_team_info(NMDevice *device, NmCli *nmc, const char *group_prefix, const ch static gboolean show_device_info(NMDevice *device, NmCli *nmc) { - GError * error = NULL; + GError *error = NULL; NMDeviceState state = NM_DEVICE_STATE_UNKNOWN; - GArray * sections_array; + GArray *sections_array; int k; - const char * fields_str = NULL; + const char *fields_str = NULL; const NMMetaAbstractInfo *const *tmpl; - NmcOutputField * arr; + NmcOutputField *arr; gboolean was_output = FALSE; - NMIPConfig * cfg4, *cfg6; - NMDhcpConfig * dhcp4, *dhcp6; - const char * base_hdr = _("Device details"); - GPtrArray * fields_in_section = NULL; + NMIPConfig *cfg4, *cfg6; + NMDhcpConfig *dhcp4, *dhcp6; + const char *base_hdr = _("Device details"); + GPtrArray *fields_in_section = NULL; if (!nmc->required_fields || g_ascii_strcasecmp(nmc->required_fields, "common") == 0) fields_str = NMC_FIELDS_DEV_SHOW_SECTIONS_COMMON; @@ -1562,9 +1566,9 @@ show_device_info(NMDevice *device, NmCli *nmc) } { - gs_unref_array GArray *out_indices = NULL; - gs_free char * header_name = NULL; - gs_free NmcOutputField *row = NULL; + gs_unref_array GArray *out_indices = NULL; + gs_free char *header_name = NULL; + gs_free NmcOutputField *row = NULL; int i; /* Main header (pretty only) */ @@ -1676,7 +1680,7 @@ show_device_info(NMDevice *device, NmCli *nmc) /* Wireless specific information */ if ((NM_IS_DEVICE_WIFI(device))) { NMAccessPoint *active_ap = NULL; - const char * active_bssid = NULL; + const char *active_bssid = NULL; /* section AP */ if (!g_ascii_strcasecmp(nmc_fields_dev_show_sections[section_idx]->name, @@ -1701,12 +1705,12 @@ show_device_info(NMDevice *device, NmCli *nmc) { gs_unref_ptrarray GPtrArray *aps = NULL; APInfo info = { - .nmc = nmc, - .index = 1, - .output_flags = NMC_OF_FLAG_SECTION_PREFIX, - .active_bssid = active_bssid, - .device = nm_device_get_iface(device), - .output_data = out.output_data, + .nmc = nmc, + .index = 1, + .output_flags = NMC_OF_FLAG_SECTION_PREFIX, + .active_bssid = active_bssid, + .device = nm_device_get_iface(device), + .output_data = out.output_data, }; aps = sort_access_points( @@ -1908,9 +1912,9 @@ nmc_device_state_to_color(NMDevice *device) static void do_devices_status(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - GError *error = NULL; + GError *error = NULL; gs_free NMDevice **devices = NULL; - const char * fields_str = NULL; + const char *fields_str = NULL; next_arg(nmc, &argc, &argv, NULL); @@ -2020,17 +2024,17 @@ progress_cb(gpointer user_data) } typedef struct { - NmCli * nmc; - NMDevice * device; + NmCli *nmc; + NMDevice *device; NMActiveConnection *active; - char * specific_object; + char *specific_object; bool hotspot : 1; bool create : 1; } AddAndActivateInfo; static AddAndActivateInfo * -add_and_activate_info_new(NmCli * nmc, - NMDevice * device, +add_and_activate_info_new(NmCli *nmc, + NMDevice *device, gboolean hotspot, gboolean create, const char *specific_object) @@ -2103,10 +2107,10 @@ connected_state_cb(AddAndActivateInfo *info) static void add_and_activate_cb(GObject *client, GAsyncResult *result, gpointer user_data) { - nm_auto_free_add_and_activate_info AddAndActivateInfo *info = user_data; - NmCli * nmc = info->nmc; - gs_unref_object NMActiveConnection *active = NULL; - gs_free_error GError *error = NULL; + nm_auto_free_add_and_activate_info AddAndActivateInfo *info = user_data; + NmCli *nmc = info->nmc; + gs_unref_object NMActiveConnection *active = NULL; + gs_free_error GError *error = NULL; if (info->create) active = nm_client_add_and_activate_connection_finish(NM_CLIENT(client), result, &error); @@ -2151,7 +2155,7 @@ add_and_activate_cb(GObject *client, GAsyncResult *result, gpointer user_data) static void create_connect_connection_for_device(AddAndActivateInfo *info) { - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; /* Create new connection and tie it to the device */ @@ -2172,10 +2176,10 @@ create_connect_connection_for_device(AddAndActivateInfo *info) static void connect_device_cb(GObject *client, GAsyncResult *result, gpointer user_data) { - nm_auto_free_add_and_activate_info AddAndActivateInfo *info = user_data; - NmCli * nmc = info->nmc; - gs_unref_object NMActiveConnection *active = NULL; - GError * error = NULL; + nm_auto_free_add_and_activate_info AddAndActivateInfo *info = user_data; + NmCli *nmc = info->nmc; + gs_unref_object NMActiveConnection *active = NULL; + GError *error = NULL; active = nm_client_activate_connection_finish(NM_CLIENT(client), result, &error); @@ -2220,8 +2224,8 @@ connect_device_cb(GObject *client, GAsyncResult *result, gpointer user_data) static void do_device_connect(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - NMDevice * device = NULL; - AddAndActivateInfo *info; + NMDevice *device = NULL; + AddAndActivateInfo *info; gs_free_error GError *error = NULL; /* Set default timeout for connect operation. */ @@ -2277,8 +2281,8 @@ do_device_connect(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const } typedef struct { - NmCli * nmc; - GSList * queue; + NmCli *nmc; + GSList *queue; guint timeout_id; gboolean cmd_disconnect; GCancellable *cancellable; @@ -2367,10 +2371,10 @@ device_cb_info_finish(DeviceCbInfo *info, NMDevice *device) static void reapply_device_cb(GObject *object, GAsyncResult *result, gpointer user_data) { - NMDevice * device = NM_DEVICE(object); + NMDevice *device = NM_DEVICE(object); DeviceCbInfo *info = (DeviceCbInfo *) user_data; - NmCli * nmc = info->nmc; - GError * error = NULL; + NmCli *nmc = info->nmc; + GError *error = NULL; if (!nm_device_reapply_finish(device, result, &error)) { g_string_printf(nmc->return_text, @@ -2393,8 +2397,8 @@ reapply_device_cb(GObject *object, GAsyncResult *result, gpointer user_data) static void do_device_reapply(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - NMDevice * device; - DeviceCbInfo *info = NULL; + NMDevice *device; + DeviceCbInfo *info = NULL; gs_free_error GError *error = NULL; /* Set default timeout for reapply operation. */ @@ -2447,10 +2451,10 @@ NM_AUTO_DEFINE_FCN_VOID0(ModifyInfo *, _auto_free_modify_info, modify_info_free) static void modify_reapply_cb(GObject *object, GAsyncResult *result, gpointer user_data) { - NMDevice * device = NM_DEVICE(object); + NMDevice *device = NM_DEVICE(object); nm_auto(_auto_free_modify_info) ModifyInfo *info = user_data; - NmCli * nmc = info->nmc; - GError * error = NULL; + NmCli *nmc = info->nmc; + GError *error = NULL; if (!nm_device_reapply_finish(device, result, &error)) { g_string_printf(nmc->return_text, @@ -2473,14 +2477,14 @@ modify_reapply_cb(GObject *object, GAsyncResult *result, gpointer user_data) static void modify_get_applied_cb(GObject *object, GAsyncResult *result, gpointer user_data) { - NMDevice * device = NM_DEVICE(object); + NMDevice *device = NM_DEVICE(object); nm_auto(_auto_free_modify_info) ModifyInfo *info = user_data; - NmCli * nmc = info->nmc; - gs_free_error GError *error = NULL; - NMConnection * connection; - guint64 version_id; - int argc; - const char *const * argv; + NmCli *nmc = info->nmc; + gs_free_error GError *error = NULL; + NMConnection *connection; + guint64 version_id; + int argc; + const char *const *argv; connection = nm_device_get_applied_connection_finish(device, result, &version_id, &error); if (!connection) { @@ -2521,8 +2525,8 @@ modify_get_applied_cb(GObject *object, GAsyncResult *result, gpointer user_data) static void do_device_modify(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - NMDevice * device = NULL; - ModifyInfo * info; + NMDevice *device = NULL; + ModifyInfo *info; gs_free_error GError *error = NULL; next_arg(nmc, &argc, &argv, NULL); @@ -2552,11 +2556,11 @@ do_device_modify(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const static void disconnect_device_cb(GObject *object, GAsyncResult *result, gpointer user_data) { - NMDevice * device = NM_DEVICE(object); + NMDevice *device = NM_DEVICE(object); DeviceCbInfo *info = (DeviceCbInfo *) user_data; - NmCli * nmc; + NmCli *nmc; NMDeviceState state; - GError * error = NULL; + GError *error = NULL; if (!nm_device_disconnect_finish(device, result, &error)) { if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) @@ -2588,9 +2592,9 @@ disconnect_device_cb(GObject *object, GAsyncResult *result, gpointer user_data) static void do_devices_disconnect(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - NMDevice * device; + NMDevice *device; DeviceCbInfo *info = NULL; - GSList * queue, *iter; + GSList *queue, *iter; /* Set default timeout for disconnect operation. */ if (nmc->timeout == -1) @@ -2633,10 +2637,10 @@ out: static void delete_device_cb(GObject *object, GAsyncResult *result, gpointer user_data) { - NMDevice * device = NM_DEVICE(object); + NMDevice *device = NM_DEVICE(object); DeviceCbInfo *info = (DeviceCbInfo *) user_data; - NmCli * nmc = info->nmc; - GError * error = NULL; + NmCli *nmc = info->nmc; + GError *error = NULL; if (!nm_device_delete_finish(device, result, &error)) { g_string_printf(nmc->return_text, _("Error: not all devices deleted.")); @@ -2656,9 +2660,9 @@ delete_device_cb(GObject *object, GAsyncResult *result, gpointer user_data) static void do_devices_delete(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - NMDevice * device; + NMDevice *device; DeviceCbInfo *info = NULL; - GSList * queue, *iter; + GSList *queue, *iter; /* Set default timeout for delete operation. */ if (nmc->timeout == -1) @@ -2814,7 +2818,7 @@ static void device_ac(NMDevice *device, GParamSpec *pspec, NmCli *nmc) { NMActiveConnection *ac = nm_device_get_active_connection(device); - const char * id = ac ? nm_active_connection_get_id(ac) : NULL; + const char *id = ac ? nm_active_connection_get_id(ac) : NULL; if (!id) return; @@ -2928,7 +2932,7 @@ static NMAccessPoint * find_ap_on_device(NMDevice *device, const char *bssid, const char *ssid, gboolean complete) { const GPtrArray *aps; - NMAccessPoint * ap = NULL; + NMAccessPoint *ap = NULL; int i; g_return_val_if_fail(NM_IS_DEVICE_WIFI(device), NULL); @@ -2954,7 +2958,7 @@ find_ap_on_device(NMDevice *device, const char *bssid, const char *ssid, gboolea if (ssid) { /* Parameter is SSID */ GBytes *candidate_ssid; - char * ssid_tmp; + char *ssid_tmp; candidate_ssid = nm_access_point_get_ssid(candidate_ap); if (!candidate_ssid) @@ -2987,8 +2991,8 @@ find_ap_on_device(NMDevice *device, const char *bssid, const char *ssid, gboolea static void show_access_point_info(NMDeviceWifi *wifi, NmCli *nmc, NmcOutputData *out) { - NMAccessPoint * active_ap = NULL; - const char * active_bssid = NULL; + NMAccessPoint *active_ap = NULL; + const char *active_bssid = NULL; NmcOutputField *arr; if (nm_device_get_state(NM_DEVICE(wifi)) == NM_DEVICE_STATE_ACTIVATED) { @@ -3003,12 +3007,12 @@ show_access_point_info(NMDeviceWifi *wifi, NmCli *nmc, NmcOutputData *out) { gs_unref_ptrarray GPtrArray *aps = NULL; APInfo info = { - .nmc = nmc, - .index = 1, - .output_flags = 0, - .active_bssid = active_bssid, - .device = nm_device_get_iface(NM_DEVICE(wifi)), - .output_data = out->output_data, + .nmc = nmc, + .index = 1, + .output_flags = 0, + .active_bssid = active_bssid, + .device = nm_device_get_iface(NM_DEVICE(wifi)), + .output_data = out->output_data, }; aps = sort_access_points(nm_device_wifi_get_access_points(wifi)); @@ -3019,21 +3023,21 @@ show_access_point_info(NMDeviceWifi *wifi, NmCli *nmc, NmcOutputData *out) } static void -wifi_print_aps(NMDeviceWifi * wifi, - NmCli * nmc, - GArray * _out_indices, +wifi_print_aps(NMDeviceWifi *wifi, + NmCli *nmc, + GArray *_out_indices, const NMMetaAbstractInfo *const *tmpl, - const char * bssid_user, - gboolean * bssid_found) + const char *bssid_user, + gboolean *bssid_found) { - NMAccessPoint * ap = NULL; + NMAccessPoint *ap = NULL; const GPtrArray *aps; - APInfo * info; + APInfo *info; guint i; - NmcOutputField * arr; - const char * base_hdr = _("Wi-Fi scan list"); + NmcOutputField *arr; + const char *base_hdr = _("Wi-Fi scan list"); NMC_OUTPUT_DATA_DEFINE_SCOPED(out); - gs_free char * header_name = NULL; + gs_free char *header_name = NULL; static gboolean empty_line = FALSE; if (empty_line) @@ -3097,17 +3101,17 @@ _device_wifi_get_last_scan(NMDeviceWifi *wifi) } typedef struct { - NmCli * nmc; - NMDevice ** devices; + NmCli *nmc; + NMDevice **devices; const NMMetaAbstractInfo *const *tmpl; - char * bssid_user; - GArray * out_indices; + char *bssid_user; + GArray *out_indices; gint64 rescan_cutoff_msec; guint pending; } ScanInfo; typedef struct { - ScanInfo * scan_info; + ScanInfo *scan_info; NMDeviceWifi *wifi; gulong last_scan_id; guint timeout_id; @@ -3118,7 +3122,7 @@ static void wifi_list_finish(WifiListData *wifi_list_data, gboolean force_finished) { ScanInfo *scan_info = wifi_list_data->scan_info; - NmCli * nmc = scan_info->nmc; + NmCli *nmc = scan_info->nmc; gboolean bssid_found = FALSE; guint i; @@ -3189,9 +3193,9 @@ wifi_list_rescan_retry_cb(gpointer user_data, GCancellable *cancellable) static void wifi_list_rescan_cb(GObject *source_object, GAsyncResult *res, gpointer user_data) { - NMDeviceWifi *wifi = NM_DEVICE_WIFI(source_object); + NMDeviceWifi *wifi = NM_DEVICE_WIFI(source_object); gs_free_error GError *error = NULL; - WifiListData * wifi_list_data; + WifiListData *wifi_list_data; gboolean force_finished; gboolean done; @@ -3248,7 +3252,7 @@ wifi_list_scan_timeout(gpointer user_data) } static void -complete_aps(NMDevice ** devices, +complete_aps(NMDevice **devices, const char *ifname, const char *bssid_prefix, const char *ssid_prefix) @@ -3272,21 +3276,21 @@ nmc_complete_bssid(NMClient *client, const char *ifname, const char *bssid_prefi static void do_device_wifi_list(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - GError * error = NULL; - NMDevice * device = NULL; - const char *ifname = NULL; - const char *bssid_user = NULL; - const char *rescan = NULL; - gs_free NMDevice ** devices = NULL; - const char * fields_str = NULL; + GError *error = NULL; + NMDevice *device = NULL; + const char *ifname = NULL; + const char *bssid_user = NULL; + const char *rescan = NULL; + gs_free NMDevice **devices = NULL; + const char *fields_str = NULL; const NMMetaAbstractInfo *const *tmpl; - gs_unref_array GArray *out_indices = NULL; - int option; - gint64 rescan_cutoff_msec; - ScanInfo * scan_info = NULL; - gboolean ifname_handled; - NMDevice * ifname_handled_candidate; - guint i, j; + gs_unref_array GArray *out_indices = NULL; + int option; + gint64 rescan_cutoff_msec; + ScanInfo *scan_info = NULL; + gboolean ifname_handled; + NMDevice *ifname_handled_candidate; + guint i, j; devices = nmc_get_devices_sorted(nmc->client); @@ -3488,11 +3492,11 @@ do_device_wifi_list(const NMCCommand *cmd, NmCli *nmc, int argc, const char *con static void activate_update2_cb(GObject *source_object, GAsyncResult *res, gpointer user_data) { - NMRemoteConnection *remote_con = NM_REMOTE_CONNECTION(source_object); - AddAndActivateInfo *info = user_data; - NmCli * nmc = info->nmc; - gs_unref_variant GVariant *ret = NULL; - GError * error = NULL; + NMRemoteConnection *remote_con = NM_REMOTE_CONNECTION(source_object); + AddAndActivateInfo *info = user_data; + NmCli *nmc = info->nmc; + gs_unref_variant GVariant *ret = NULL; + GError *error = NULL; ret = nm_remote_connection_update2_finish(remote_con, res, &error); @@ -3515,11 +3519,11 @@ activate_update2_cb(GObject *source_object, GAsyncResult *res, gpointer user_dat } static void -save_and_activate_connection(NmCli * nmc, - NMDevice * device, +save_and_activate_connection(NmCli *nmc, + NMDevice *device, NMConnection *connection, gboolean hotspot, - const char * specific_object) + const char *specific_object) { AddAndActivateInfo *info; @@ -3551,29 +3555,29 @@ save_and_activate_connection(NmCli * nmc, static void do_device_wifi_connect(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - NMDevice * device = NULL; - NMAccessPoint * ap = NULL; - NM80211ApFlags ap_flags; - NM80211ApSecurityFlags ap_wpa_flags; - NM80211ApSecurityFlags ap_rsn_flags; + NMDevice *device = NULL; + NMAccessPoint *ap = NULL; + NM80211ApFlags ap_flags; + NM80211ApSecurityFlags ap_wpa_flags; + NM80211ApSecurityFlags ap_rsn_flags; gs_unref_object NMConnection *connection = NULL; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; - const char * param_user = NULL; - const char * ifname = NULL; - const char * bssid = NULL; - const char * password = NULL; - const char * con_name = NULL; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + const char *param_user = NULL; + const char *ifname = NULL; + const char *bssid = NULL; + const char *password = NULL; + const char *con_name = NULL; gboolean private = FALSE; - gboolean hidden = FALSE; - gboolean wep_passphrase = FALSE; - GByteArray *bssid1_arr = NULL; - GByteArray *bssid2_arr = NULL; + gboolean hidden = FALSE; + gboolean wep_passphrase = FALSE; + GByteArray *bssid1_arr = NULL; + GByteArray *bssid2_arr = NULL; gs_free NMDevice **devices = NULL; int devices_idx; - char * ssid_ask = NULL; - char * passwd_ask = NULL; - const GPtrArray * avail_cons; + char *ssid_ask = NULL; + char *passwd_ask = NULL; + const GPtrArray *avail_cons; gboolean name_match = FALSE; int i; @@ -3781,8 +3785,8 @@ do_device_wifi_connect(const NMCCommand *cmd, NmCli *nmc, int argc, const char * /* For hidden SSID first scan it so that NM learns about the AP */ if (hidden) { GVariantBuilder builder, array_builder; - GVariant * options; - GError * scan_err = NULL; + GVariant *options; + GError *scan_err = NULL; g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT); g_variant_builder_init(&array_builder, G_VARIANT_TYPE("aay")); @@ -3840,7 +3844,7 @@ do_device_wifi_connect(const NMCCommand *cmd, NmCli *nmc, int argc, const char * avail_cons = nm_device_get_available_connections(device); for (i = 0; i < avail_cons->len; i++) { NMConnection *avail_con = g_ptr_array_index(avail_cons, i); - const char * id = nm_connection_get_id(NM_CONNECTION(avail_con)); + const char *id = nm_connection_get_id(NM_CONNECTION(avail_con)); if (con_name) { if (!id || strcmp(id, con_name)) @@ -3929,7 +3933,7 @@ do_device_wifi_connect(const NMCCommand *cmd, NmCli *nmc, int argc, const char * || (ap_rsn_flags != NM_802_11_AP_SEC_NONE && !NM_FLAGS_ANY(ap_rsn_flags, NM_802_11_AP_SEC_KEY_MGMT_OWE | NM_802_11_AP_SEC_KEY_MGMT_OWE_TM))) { - const char * con_password = NULL; + const char *con_password = NULL; NMSettingWirelessSecurity *s_wsec = NULL; if (connection) { @@ -4006,7 +4010,7 @@ static GBytes * generate_ssid_for_hotspot(void) { GBytes *ssid_bytes; - char * ssid = NULL; + char *ssid = NULL; ssid = g_strdup_printf("Hotspot-%s", g_get_host_name()); if (strlen(ssid) > 32) @@ -4059,11 +4063,11 @@ generate_wep_key(char *key, size_t len) static gboolean set_wireless_security_for_hotspot(NMSettingWirelessSecurity *s_wsec, - const char * wifi_mode, + const char *wifi_mode, NMDeviceWifiCapabilities caps, - const char * password, + const char *password, gboolean show_password, - GError ** error) + GError **error) { char generated_key[11]; const char *key; @@ -4135,15 +4139,15 @@ set_wireless_security_for_hotspot(NMSettingWirelessSecurity *s_wsec, } static NMConnection * -find_hotspot_conn(NMDevice * device, +find_hotspot_conn(NMDevice *device, const GPtrArray *connections, - const char * con_name, - GBytes * ssid_bytes, - const char * wifi_mode, - const char * band, + const char *con_name, + GBytes *ssid_bytes, + const char *wifi_mode, + const char *band, gint64 channel_int) { - NMConnection * connection; + NMConnection *connection; NMSettingWireless *s_wifi; int i; @@ -4177,19 +4181,19 @@ find_hotspot_conn(NMDevice * device, static NMConnection * create_hotspot_conn(const GPtrArray *connections, - const char * con_name, - GBytes * ssid_bytes, - const char * wifi_mode, - const char * band, + const char *con_name, + GBytes *ssid_bytes, + const char *wifi_mode, + const char *band, gint64 channel_int) { - char * default_name = NULL; - NMConnection * connection; - NMSettingConnection * s_con; - NMSettingWireless * s_wifi; + char *default_name = NULL; + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; - NMSettingIPConfig * s_ip4, *s_ip6; - NMSettingProxy * s_proxy; + NMSettingIPConfig *s_ip4, *s_ip6; + NMSettingProxy *s_proxy; connection = nm_simple_connection_new(); s_con = (NMSettingConnection *) nm_setting_connection_new(); @@ -4244,22 +4248,22 @@ create_hotspot_conn(const GPtrArray *connections, static void do_device_wifi_hotspot(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - const char * ifname = NULL; - const char * con_name = NULL; - gs_unref_bytes GBytes *ssid_bytes = NULL; - const char * wifi_mode; - const char * band = NULL; - const char * channel = NULL; - gint64 channel_int = -1; - const char * password = NULL; - gboolean show_password = FALSE; - NMDevice * device = NULL; - gs_free NMDevice ** devices = NULL; - NMDeviceWifiCapabilities caps; + const char *ifname = NULL; + const char *con_name = NULL; + gs_unref_bytes GBytes *ssid_bytes = NULL; + const char *wifi_mode; + const char *band = NULL; + const char *channel = NULL; + gint64 channel_int = -1; + const char *password = NULL; + gboolean show_password = FALSE; + NMDevice *device = NULL; + gs_free NMDevice **devices = NULL; + NMDeviceWifiCapabilities caps; gs_unref_object NMConnection *connection = NULL; - const GPtrArray * connections; - NMSettingWirelessSecurity * s_wsec; - GError * error = NULL; + const GPtrArray *connections; + NMSettingWirelessSecurity *s_wsec; + GError *error = NULL; /* Set default timeout waiting for operation completion. */ if (nmc->timeout == -1) @@ -4459,7 +4463,7 @@ do_device_wifi_hotspot(const NMCCommand *cmd, NmCli *nmc, int argc, const char * static void request_rescan_cb(GObject *object, GAsyncResult *result, gpointer user_data) { - NmCli * nmc = (NmCli *) user_data; + NmCli *nmc = (NmCli *) user_data; GError *error = NULL; nm_device_wifi_request_scan_finish(NM_DEVICE_WIFI(object), result, &error); @@ -4474,13 +4478,13 @@ request_rescan_cb(GObject *object, GAsyncResult *result, gpointer user_data) static void do_device_wifi_rescan(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - NMDevice * device; - const char * ifname = NULL; - gs_unref_ptrarray GPtrArray *ssids = NULL; - gs_free NMDevice **devices = NULL; - GVariantBuilder builder, array_builder; - GVariant * options; - int i; + NMDevice *device; + const char *ifname = NULL; + gs_unref_ptrarray GPtrArray *ssids = NULL; + gs_free NMDevice **devices = NULL; + GVariantBuilder builder, array_builder; + GVariant *options; + int i; ssids = g_ptr_array_new(); devices = nmc_get_devices_sorted(nmc->client); @@ -4599,13 +4603,13 @@ string_append_mecard(GString *string, const char *tag, const char *text) static void print_wifi_connection(const NmcConfig *nmc_config, NMConnection *connection) { - NMSettingWireless * s_wireless; - NMSettingWirelessSecurity *s_wsec; - const char * key_mgmt = NULL; - const char * psk = NULL; - const char * type = NULL; - GBytes * ssid_bytes; - gs_free char * ssid = NULL; + NMSettingWireless *s_wireless; + NMSettingWirelessSecurity *s_wsec; + const char *key_mgmt = NULL; + const char *psk = NULL; + const char *type = NULL; + GBytes *ssid_bytes; + gs_free char *ssid = NULL; nm_auto_free_gstring GString *string = NULL; s_wireless = nm_connection_get_setting_wireless(connection); @@ -4661,9 +4665,9 @@ print_wifi_connection(const NmcConfig *nmc_config, NMConnection *connection) static gboolean wifi_show_device(const NmcConfig *nmc_config, NMDevice *device, GError **error) { - NMActiveConnection *active_conn; + NMActiveConnection *active_conn; gs_unref_object NMConnection *connection = NULL; - gs_unref_variant GVariant *secrets = NULL; + gs_unref_variant GVariant *secrets = NULL; if (!NM_IS_DEVICE_WIFI(device)) { g_set_error(error, @@ -4708,10 +4712,10 @@ wifi_show_device(const NmcConfig *nmc_config, NMDevice *device, GError **error) static void do_device_wifi_show_password(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - const char *ifname = NULL; - gs_free NMDevice **devices = NULL; - gs_free_error GError *error = NULL; - gboolean found = FALSE; + const char *ifname = NULL; + gs_free NMDevice **devices = NULL; + gs_free_error GError *error = NULL; + gboolean found = FALSE; int i; devices = nmc_get_devices_sorted(nmc->client); @@ -4795,9 +4799,9 @@ static int show_device_lldp_list(NMDevice *device, NmCli *nmc, const char *fields_str, int *counter) { const NMMetaAbstractInfo *const *tmpl; - NmcOutputField * arr; - GPtrArray * neighbors; - const char * str; + NmcOutputField *arr; + GPtrArray *neighbors; + const char *str; int i; NMC_OUTPUT_DATA_DEFINE_SCOPED(out); gs_free char *header_name = NULL; @@ -4894,10 +4898,10 @@ show_device_lldp_list(NMDevice *device, NmCli *nmc, const char *fields_str, int static void do_device_lldp_list(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - NMDevice * device = NULL; - gs_free_error GError *error = NULL; - const char * fields_str = NULL; - int counter = 0; + NMDevice *device = NULL; + gs_free_error GError *error = NULL; + const char *fields_str = NULL; + int counter = 0; gs_unref_array GArray *out_indices = NULL; next_arg(nmc, &argc, &argv, NULL); @@ -4996,7 +5000,7 @@ is_single_word(const char *line) static char ** nmcli_device_tab_completion(const char *text, int start, int end) { - char ** match_array = NULL; + char **match_array = NULL; rl_compentry_func_t *generator_func = NULL; /* Disable readline's default filename completion */ diff --git a/src/nmcli/general.c b/src/nmcli/general.c index d87df17a..65437e79 100644 --- a/src/nmcli/general.c +++ b/src/nmcli/general.c @@ -108,10 +108,11 @@ static NM_UTILS_LOOKUP_DEFINE( static const NmcMetaGenericInfo *const metagen_general_status[]; -static gconstpointer _metagen_general_status_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) +static gconstpointer +_metagen_general_status_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) { - NmCli * nmc = target; - const char * value; + NmCli *nmc = target; + const char *value; gboolean v_bool; NMState state; NMConnectivityState connectivity; @@ -209,12 +210,13 @@ static const NmcMetaGenericInfo /*****************************************************************************/ -static gconstpointer _metagen_general_permissions_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) +static gconstpointer +_metagen_general_permissions_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) { NMClientPermission perm = GPOINTER_TO_UINT(target); - NmCli * nmc = environment_user_data; + NmCli *nmc = environment_user_data; NMClientPermissionResult perm_result; - const char * s; + const char *s; switch (info->info_type) { case NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_PERMISSION: @@ -252,9 +254,10 @@ typedef struct { char **domains; } GetGeneralLoggingData; -static gconstpointer _metagen_general_logging_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) +static gconstpointer +_metagen_general_logging_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) { - NmCli * nmc = environment_user_data; + NmCli *nmc = environment_user_data; GetGeneralLoggingData *d = target; nm_assert(info->info_type < _NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_NUM); @@ -466,9 +469,9 @@ static gboolean show_nm_status(NmCli *nmc, const char *pretty_header_name, const char *print_flds) { gs_free_error GError *error = NULL; - const char * fields_str; - const char * fields_all = print_flds ?: NMC_FIELDS_NM_STATUS_ALL; - const char * fields_common = print_flds ?: NMC_FIELDS_NM_STATUS_COMMON; + const char *fields_str; + const char *fields_all = print_flds ?: NMC_FIELDS_NM_STATUS_ALL; + const char *fields_common = print_flds ?: NMC_FIELDS_NM_STATUS_COMMON; if (!nmc->required_fields || g_ascii_strcasecmp(nmc->required_fields, "common") == 0) fields_str = fields_common; @@ -519,9 +522,9 @@ timeout_cb(gpointer user_data) static void print_permissions(void *user_data) { - NmCli * nmc = user_data; + NmCli *nmc = user_data; gs_free_error GError *error = NULL; - const char * fields_str = NULL; + const char *fields_str = NULL; gpointer permissions[G_N_ELEMENTS(nm_auth_permission_sorted) + 1]; gboolean is_running; int i; @@ -603,9 +606,9 @@ show_nm_permissions(NmCli *nmc) static void reload_cb(GObject *source, GAsyncResult *result, gpointer user_data) { - NmCli * nmc = user_data; - gs_free_error GError *error = NULL; - gs_unref_variant GVariant *ret = NULL; + NmCli *nmc = user_data; + gs_free_error GError *error = NULL; + gs_unref_variant GVariant *ret = NULL; ret = nm_dbus_call_finish(result, &error); if (error) { @@ -622,8 +625,8 @@ static void do_general_reload(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { gs_free const char **values = NULL; - gs_free char * err_token = NULL; - gs_free char * joined = NULL; + gs_free char *err_token = NULL; + gs_free char *joined = NULL; int flags = 0; next_arg(nmc, &argc, &argv, NULL); @@ -694,13 +697,13 @@ do_general_permissions(const NMCCommand *cmd, NmCli *nmc, int argc, const char * static void show_general_logging(NmCli *nmc) { - gs_free char *level_cache = NULL; - gs_free char *domains_cache = NULL; - gs_free_error GError *error = NULL; - const char * fields_str = NULL; - GetGeneralLoggingData d = { - .level = &level_cache, - .domains = &domains_cache, + gs_free char *level_cache = NULL; + gs_free char *domains_cache = NULL; + gs_free_error GError *error = NULL; + const char *fields_str = NULL; + GetGeneralLoggingData d = { + .level = &level_cache, + .domains = &domains_cache, }; if (!nmc->required_fields || g_ascii_strcasecmp(nmc->required_fields, "common") == 0) { @@ -742,9 +745,9 @@ nmc_complete_strings_nocase(const char *prefix, ...) static void _set_logging_cb(GObject *object, GAsyncResult *result, gpointer user_data) { - NmCli * nmc = user_data; - gs_unref_variant GVariant *res = NULL; - gs_free_error GError *error = NULL; + NmCli *nmc = user_data; + gs_unref_variant GVariant *res = NULL; + gs_free_error GError *error = NULL; res = nm_client_dbus_call_finish(NM_CLIENT(object), result, &error); if (!res) { @@ -878,7 +881,7 @@ do_general_logging(const NMCCommand *cmd, NmCli *nmc, int argc, const char *cons static void save_hostname_cb(GObject *object, GAsyncResult *result, gpointer user_data) { - NmCli * nmc = user_data; + NmCli *nmc = user_data; gs_free_error GError *error = NULL; nm_client_save_hostname_finish(NM_CLIENT(object), result, &error); @@ -984,9 +987,9 @@ nmc_switch_parse_on_off(NmCli *nmc, const char *arg1, const char *arg2, gboolean static void _do_networking_on_off_cb(GObject *object, GAsyncResult *result, gpointer user_data) { - NmCli * nmc = user_data; - gs_unref_variant GVariant *ret = NULL; - gs_free_error GError *error = NULL; + NmCli *nmc = user_data; + gs_unref_variant GVariant *ret = NULL; + gs_free_error GError *error = NULL; ret = nm_client_dbus_call_finish(NM_CLIENT(object), result, &error); if (!ret) { @@ -1119,7 +1122,7 @@ do_radio_all(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *arg static void _do_radio_wifi_cb(GObject *object, GAsyncResult *result, gpointer user_data) { - NmCli * nmc = user_data; + NmCli *nmc = user_data; gs_free_error GError *error = NULL; if (!nm_client_dbus_set_property_finish(NM_CLIENT(object), result, &error)) { @@ -1214,7 +1217,7 @@ static void networkmanager_running(NMClient *client, GParamSpec *param, NmCli *nmc) { gboolean running; - char * str; + char *str; running = nm_client_get_nm_running(client); str = nmc_colorize(&nmc->nmc_config, @@ -1237,7 +1240,7 @@ static void client_primary_connection(NMClient *client, GParamSpec *param, NmCli *nmc) { NMActiveConnection *primary; - const char * id; + const char *id; primary = nm_client_get_primary_connection(client); if (primary) { @@ -1255,7 +1258,7 @@ static void client_connectivity(NMClient *client, GParamSpec *param, NmCli *nmc) { NMConnectivityState connectivity; - char * str; + char *str; g_object_get(client, NM_CLIENT_CONNECTIVITY, &connectivity, NULL); str = nmc_colorize(&nmc->nmc_config, @@ -1270,7 +1273,7 @@ static void client_state(NMClient *client, GParamSpec *param, NmCli *nmc) { NMState state; - char * str; + char *str; g_object_get(client, NM_CLIENT_STATE, &state, NULL); str = nmc_colorize(&nmc->nmc_config, @@ -1284,8 +1287,8 @@ client_state(NMClient *client, GParamSpec *param, NmCli *nmc) static void device_overview(NmCli *nmc, NMDevice *device) { - GString * outbuf = g_string_sized_new(80); - char * tmp; + GString *outbuf = g_string_sized_new(80); + char *tmp; const GPtrArray *activatable; activatable = nm_device_get_available_connections(device); @@ -1392,8 +1395,8 @@ device_overview(NmCli *nmc, NMDevice *device) static void ac_overview(NmCli *nmc, NMActiveConnection *ac) { - GString * outbuf = g_string_sized_new(80); - NMIPConfig * ip; + GString *outbuf = g_string_sized_new(80); + NMIPConfig *ip; nm_auto_str_buf NMStrBuf str = NM_STR_BUF_INIT(NM_UTILS_GET_NEXT_REALLOC_SIZE_104, FALSE); if (nm_active_connection_get_master(ac)) { @@ -1463,12 +1466,12 @@ ac_overview(NmCli *nmc, NMActiveConnection *ac) void nmc_command_func_overview(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - NMDevice ** devices; - const GPtrArray * p; + NMDevice **devices; + const GPtrArray *p; NMActiveConnection *ac; NMMetaColor color; - NMDnsEntry * dns; - char * tmp; + NMDnsEntry *dns; + char *tmp; int i; next_arg(nmc, &argc, &argv, NULL); diff --git a/src/nmcli/generate-docs-nm-settings-nmcli.c b/src/nmcli/generate-docs-nm-settings-nmcli.c index cd1bb670..196e4d35 100644 --- a/src/nmcli/generate-docs-nm-settings-nmcli.c +++ b/src/nmcli/generate-docs-nm-settings-nmcli.c @@ -34,8 +34,8 @@ main(int argc, char *argv[]) for (i_sett_infos = 0; i_sett_infos < G_N_ELEMENTS(nm_meta_setting_infos_editor); i_sett_infos++) { const NMMetaSettingInfoEditor *sett_info = &nm_meta_setting_infos_editor[i_sett_infos]; - gs_free char * tmp_s1 = NULL; - gs_free char * tmp_s2 = NULL; + gs_free char *tmp_s1 = NULL; + gs_free char *tmp_s2 = NULL; g_print("%sgeneral->setting_name)); @@ -47,9 +47,9 @@ main(int argc, char *argv[]) for (i_property = 0; i_property < sett_info->properties_num; i_property++) { const NMMetaPropertyInfo *prop_info = sett_info->properties[i_property]; - gs_free char * tmp2 = NULL; - gs_free char * tmp3 = NULL; - gs_free char * tmp4 = NULL; + gs_free char *tmp2 = NULL; + gs_free char *tmp3 = NULL; + gs_free char *tmp4 = NULL; g_print("%sproperty_name)); diff --git a/src/nmcli/generate-docs-nm-settings-nmcli.xml b/src/nmcli/generate-docs-nm-settings-nmcli.xml index 02fd8800..1d329305 100644 --- a/src/nmcli/generate-docs-nm-settings-nmcli.xml +++ b/src/nmcli/generate-docs-nm-settings-nmcli.xml @@ -818,6 +818,8 @@ + diff --git a/src/nmcli/generate-docs-nm-settings-nmcli.xml.in b/src/nmcli/generate-docs-nm-settings-nmcli.xml.in index 02fd8800..1d329305 100644 --- a/src/nmcli/generate-docs-nm-settings-nmcli.xml.in +++ b/src/nmcli/generate-docs-nm-settings-nmcli.xml.in @@ -818,6 +818,8 @@ + diff --git a/src/nmcli/nmcli.c b/src/nmcli/nmcli.c index b2b2cd81..fae40584 100644 --- a/src/nmcli/nmcli.c +++ b/src/nmcli/nmcli.c @@ -118,7 +118,7 @@ typedef struct { } ArgsInfo; /* --- Global variables --- */ -GMainLoop * loop = NULL; +GMainLoop *loop = NULL; struct termios termios_orig; NM_CACHED_QUARK_FCN("nmcli-error-quark", nmcli_error_quark); @@ -150,10 +150,10 @@ static void complete_one(gpointer key, gpointer value, gpointer user_data) { const char **option_with_value = user_data; - const char * option = option_with_value[0]; - const char * prefix = option_with_value[1]; - const char * name = key; - const char * last; + const char *option = option_with_value[0]; + const char *prefix = option_with_value[1]; + const char *name = key; + const char *last; last = strrchr(prefix, ','); if (last) @@ -272,9 +272,9 @@ static gboolean matches_arg(NmCli *nmc, int *argc, const char *const **argv, const char *pattern, char **arg) { gs_free char *opt_free = NULL; - const char * opt = (*argv)[0]; + const char *opt = (*argv)[0]; gs_free char *arg_tmp = NULL; - const char * s; + const char *s; nm_assert(opt); nm_assert(opt[0] == '-'); @@ -377,7 +377,7 @@ check_colors_check_palette_one_file(const char *base_dir, const char *name, cons for (i = 0; i < G_N_ELEMENTS(extensions); i++) { gs_free char *filename = NULL; - char * contents; + char *contents; filename = check_colors_construct_filename(base_dir, name, term, extensions[i]); if (g_file_get_contents(filename, &contents, NULL, NULL)) @@ -470,9 +470,9 @@ check_colors_check_palette(const char *base_dir_1, static gboolean check_colors(NmcColorOption color_option, char **out_palette_str) { - const char * base_dir_1, *base_dir_2; + const char *base_dir_1, *base_dir_2; const char *const NAME = "nmcli"; - const char * term; + const char *term; *out_palette_str = NULL; @@ -681,8 +681,8 @@ parse_color_scheme(char *palette_buffer, NmcColorPalette *out_palette, GError ** static void set_colors(NmcColorOption color_option, - bool * out_use_colors, - char ** out_palette_buffer, + bool *out_use_colors, + char **out_palette_buffer, NmcColorPalette *out_palette) { gs_free char *palette_str = NULL; @@ -730,7 +730,7 @@ process_command_line(NmCli *nmc, int argc, char **argv_orig) {NULL, nmc_command_func_overview, usage, TRUE, TRUE}, }; NmcColorOption colors = NMC_USE_COLOR_AUTO; - const char * base; + const char *base; const char *const *argv; base = strrchr(argv_orig[0], '/'); diff --git a/src/nmcli/nmcli.h b/src/nmcli/nmcli.h index f1303378..157aae99 100644 --- a/src/nmcli/nmcli.h +++ b/src/nmcli/nmcli.h @@ -85,7 +85,7 @@ typedef struct _NmcMetaGenericInfo NmcMetaGenericInfo; struct _NmcOutputField { const NMMetaAbstractInfo *info; int width; /* Width in screen columns */ - void * value; /* Value of current field - char* or char** (NULL-terminated array) */ + void *value; /* Value of current field - char* or char** (NULL-terminated array) */ gboolean value_is_array; /* Whether value is char** instead of char* */ gboolean free_value; /* Whether to free the value */ NmcOfFlags flags; /* Flags - whether and how to print values/field names/headers */ @@ -118,14 +118,14 @@ typedef struct _NmCli { NMClient *client; /* Pointer to NMClient of libnm */ NMCResultCode return_value; /* Return code of nmcli */ - GString * return_text; /* Reason text */ + GString *return_text; /* Reason text */ NmcPagerData pager_data; int timeout; /* Operation timeout */ - NMSecretAgentSimple * secret_agent; /* Secret agent */ - GHashTable * pwds_hash; /* Hash table with passwords in passwd-file */ + NMSecretAgentSimple *secret_agent; /* Secret agent */ + GHashTable *pwds_hash; /* Hash table with passwords in passwd-file */ struct _NMPolkitListener *pk_listener; /* polkit agent listener */ int should_wait; /* Semaphore indicating whether nmcli should not end or not yet */ @@ -135,7 +135,7 @@ typedef struct _NmCli { const NmcConfig nmc_config; NmcConfig nmc_config_mutable; }; - char * required_fields; /* Required fields in output: '--fields' option */ + char *required_fields; /* Required fields in output: '--fields' option */ gboolean ask; /* Ask for missing parameters: option '--ask' */ gboolean complete; /* Autocomplete the command line */ gboolean editor_status_line; /* Whether to display status line in connection editor */ @@ -163,9 +163,9 @@ void nm_cli_spawn_pager(const NmcConfig *nmc_config, NmcPagerData *pager_data); void nmc_empty_output_fields(NmcOutputData *output_data); #define NMC_OUTPUT_DATA_DEFINE_SCOPED(out) \ - gs_unref_array GArray * out##_indices = NULL; \ + gs_unref_array GArray *out##_indices = NULL; \ nm_auto(nmc_empty_output_fields) NmcOutputData out = { \ - .output_data = g_ptr_array_new_full(20, g_free), \ + .output_data = g_ptr_array_new_full(20, g_free), \ } /*****************************************************************************/ diff --git a/src/nmcli/polkit-agent.c b/src/nmcli/polkit-agent.c index 7776d7e7..41567023 100644 --- a/src/nmcli/polkit-agent.c +++ b/src/nmcli/polkit-agent.c @@ -43,7 +43,7 @@ gboolean nmc_polkit_agent_init(NmCli *nmc, gboolean for_session, GError **error) { NMPolkitListener *listener; - GDBusConnection * dbus_connection = NULL; + GDBusConnection *dbus_connection = NULL; g_return_val_if_fail(error == NULL || *error == NULL, FALSE); diff --git a/src/nmcli/settings.c b/src/nmcli/settings.c index f4966400..c80d0c7c 100644 --- a/src/nmcli/settings.c +++ b/src/nmcli/settings.c @@ -24,8 +24,8 @@ static gboolean get_answer(const char *prop, const char *value) { - char * tmp_str; - char * question; + char *tmp_str; + char *question; gboolean answer = FALSE; if (value) @@ -226,7 +226,7 @@ proxy_method_changed_cb(GObject *object, GParamSpec *pspec, gpointer user_data) static void wireless_band_channel_changed_cb(GObject *object, GParamSpec *pspec, gpointer user_data) { - const char * value = NULL, *mode; + const char *value = NULL, *mode; char str[16]; NMSettingWireless *s_wireless = NM_SETTING_WIRELESS(object); @@ -257,9 +257,9 @@ static void connection_master_changed_cb(GObject *object, GParamSpec *pspec, gpointer user_data) { NMSettingConnection *s_con = NM_SETTING_CONNECTION(object); - NMConnection * connection = NM_CONNECTION(user_data); - NMSetting * s_ipv4, *s_ipv6; - const char * value, *tmp_str; + NMConnection *connection = NM_CONNECTION(user_data); + NMSetting *s_ipv4, *s_ipv6; + const char *value, *tmp_str; value = nm_setting_connection_get_master(s_con); if (value) { @@ -350,16 +350,16 @@ nmc_setting_connection_connect_handlers(NMSettingConnection *setting, NMConnecti /*****************************************************************************/ static gboolean -_set_fcn_precheck_connection_secondaries(NMClient * client, +_set_fcn_precheck_connection_secondaries(NMClient *client, const char *value, - char ** value_coerced, - GError ** error) + char **value_coerced, + GError **error) { - const GPtrArray * connections; - NMConnection * con; + const GPtrArray *connections; + NMConnection *con; gs_free const char **strv0 = NULL; - gs_strfreev char ** strv = NULL; - char ** iter; + gs_strfreev char **strv = NULL; + char **iter; gboolean modified = FALSE; strv0 = nm_strsplit_set(value, " \t,"); @@ -419,7 +419,7 @@ _env_warn_fcn_handle( fmt_l10n, /* the untranslated format string, but it is marked for translation using N_(). */ va_list ap) { - NmCli * nmc = environment_user_data; + NmCli *nmc = environment_user_data; gs_free char *m = NULL; if (nmc->complete) @@ -443,9 +443,9 @@ _env_warn_fcn_handle( static NMDevice *const * _env_get_nm_devices(const NMMetaEnvironment *environment, gpointer environment_user_data, - guint * out_len) + guint *out_len) { - NmCli * nmc = environment_user_data; + NmCli *nmc = environment_user_data; const GPtrArray *devices; nm_assert(nmc); @@ -467,9 +467,9 @@ _env_get_nm_devices(const NMMetaEnvironment *environment, static NMRemoteConnection *const * _env_get_nm_connections(const NMMetaEnvironment *environment, gpointer environment_user_data, - guint * out_len) + guint *out_len) { - NmCli * nmc = environment_user_data; + NmCli *nmc = environment_user_data; const GPtrArray *values; nm_assert(nmc); @@ -497,11 +497,11 @@ const NMMetaEnvironment *const nmc_meta_environment = &((NMMetaEnvironment){ }); static char * -get_property_val(NMSetting * setting, - const char * prop, +get_property_val(NMSetting *setting, + const char *prop, NMMetaAccessorGetType get_type, gboolean show_secrets, - GError ** error) + GError **error) { const NMMetaPropertyInfo *property_info; @@ -514,8 +514,8 @@ get_property_val(NMSetting * setting, if ((property_info = nm_meta_property_info_find_by_setting(setting, prop))) { if (property_info->property_type->get_fcn) { NMMetaAccessorGetOutFlags out_flags = NM_META_ACCESSOR_GET_OUT_FLAGS_NONE; - char * to_free = NULL; - const char * value; + char *to_free = NULL; + const char *value; value = property_info->property_type->get_fcn( property_info, @@ -560,15 +560,15 @@ nmc_setting_get_property_parsable(NMSetting *setting, const char *prop, GError * } gboolean -nmc_setting_set_property(NMClient * client, - NMSetting * setting, - const char * prop, +nmc_setting_set_property(NMClient *client, + NMSetting *setting, + const char *prop, NMMetaAccessorModifier modifier, - const char * value, - GError ** error) + const char *value, + GError **error) { const NMMetaPropertyInfo *property_info; - gs_free char * value_to_free = NULL; + gs_free char *value_to_free = NULL; gboolean success; g_return_val_if_fail(NM_IS_SETTING(setting), FALSE); @@ -639,7 +639,7 @@ char ** nmc_setting_get_valid_properties(NMSetting *setting) { const NMMetaSettingInfoEditor *setting_info; - char ** valid_props; + char **valid_props; guint i, num; setting_info = nm_meta_setting_info_editor_find_by_setting(setting); @@ -686,14 +686,14 @@ nmc_setting_get_property_allowed_values(NMSetting *setting, const char *prop, ch char * nmc_setting_get_property_desc(NMSetting *setting, const char *prop) { - gs_free char * desc_to_free = NULL; - const char * setting_desc = NULL; - const char * setting_desc_title = ""; - const char * nmcli_desc = NULL; - const char * nmcli_desc_title = ""; - const char * nmcli_nl = ""; + gs_free char *desc_to_free = NULL; + const char *setting_desc = NULL; + const char *setting_desc_title = ""; + const char *nmcli_desc = NULL; + const char *nmcli_desc_title = ""; + const char *nmcli_nl = ""; const NMMetaPropertyInfo *property_info; - const char * desc = NULL; + const char *desc = NULL; g_return_val_if_fail(NM_IS_SETTING(setting), FALSE); @@ -732,8 +732,8 @@ gboolean setting_details(const NmcConfig *nmc_config, NMSetting *setting, const char *one_prop) { const NMMetaSettingInfoEditor *setting_info; - gs_free_error GError *error = NULL; - gs_free char * fields_str = NULL; + gs_free_error GError *error = NULL; + gs_free char *fields_str = NULL; g_return_val_if_fail(NM_IS_SETTING(setting), FALSE); diff --git a/src/nmcli/settings.h b/src/nmcli/settings.h index 2dbe7607..9cbf13c4 100644 --- a/src/nmcli/settings.h +++ b/src/nmcli/settings.h @@ -17,20 +17,20 @@ void nmc_setting_ip6_connect_handlers(NMSettingIPConfig *setting); void nmc_setting_proxy_connect_handlers(NMSettingProxy *setting); void nmc_setting_wireless_connect_handlers(NMSettingWireless *setting); void nmc_setting_connection_connect_handlers(NMSettingConnection *setting, - NMConnection * connection); + NMConnection *connection); char **nmc_setting_get_valid_properties(NMSetting *setting); -char * nmc_setting_get_property_desc(NMSetting *setting, const char *prop); +char *nmc_setting_get_property_desc(NMSetting *setting, const char *prop); const char *const * nmc_setting_get_property_allowed_values(NMSetting *setting, const char *prop, char ***out_to_free); -char * nmc_setting_get_property(NMSetting *setting, const char *prop, GError **error); -char * nmc_setting_get_property_parsable(NMSetting *setting, const char *prop, GError **error); -gboolean nmc_setting_set_property(NMClient * client, - NMSetting * setting, - const char * prop, +char *nmc_setting_get_property(NMSetting *setting, const char *prop, GError **error); +char *nmc_setting_get_property_parsable(NMSetting *setting, const char *prop, GError **error); +gboolean nmc_setting_set_property(NMClient *client, + NMSetting *setting, + const char *prop, NMMetaAccessorModifier modifier, - const char * val, - GError ** error); + const char *val, + GError **error); gboolean setting_details(const NmcConfig *nmc_config, NMSetting *setting, const char *one_prop); diff --git a/src/nmcli/utils.c b/src/nmcli/utils.c index 85768c19..7645a08c 100644 --- a/src/nmcli/utils.c +++ b/src/nmcli/utils.c @@ -40,8 +40,8 @@ _meta_type_nmc_generic_info_get_name(const NMMetaAbstractInfo *abstract_info, gb static const NMMetaAbstractInfo *const * _meta_type_nmc_generic_info_get_nested(const NMMetaAbstractInfo *abstract_info, - guint * out_len, - gpointer * out_to_free) + guint *out_len, + gpointer *out_to_free) { const NmcMetaGenericInfo *info; @@ -52,16 +52,16 @@ _meta_type_nmc_generic_info_get_nested(const NMMetaAbstractInfo *abstract_info, } static gconstpointer -_meta_type_nmc_generic_info_get_fcn(const NMMetaAbstractInfo * abstract_info, - const NMMetaEnvironment * environment, +_meta_type_nmc_generic_info_get_fcn(const NMMetaAbstractInfo *abstract_info, + const NMMetaEnvironment *environment, gpointer environment_user_data, gpointer target, gpointer target_data, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, NMMetaAccessorGetOutFlags *out_flags, - gboolean * out_is_default, - gpointer * out_to_free) + gboolean *out_is_default, + gpointer *out_to_free) { const NmcMetaGenericInfo *info = (const NmcMetaGenericInfo *) abstract_info; @@ -244,11 +244,11 @@ nmc_arg_is_option(const char *str, const char *opt_name) * Returns: TRUE on success, FALSE on an error and sets 'error' */ gboolean -nmc_parse_args(nmc_arg_t * arg_arr, +nmc_parse_args(nmc_arg_t *arg_arr, gboolean last, - int * argc, + int *argc, const char *const **argv, - GError ** error) + GError **error) { nmc_arg_t *p; gboolean found; @@ -376,7 +376,7 @@ nmc_colorize(const NmcConfig *nmc_config, NMMetaColor color, const char *fmt, .. { va_list args; gs_free char *str = NULL; - const char * ansi_seq = NULL; + const char *ansi_seq = NULL; va_start(args, fmt); str = g_strdup_vprintf(fmt, args); @@ -423,7 +423,7 @@ void nmc_filter_out_colors_inplace(char *str) { const char *p1; - char * p2; + char *p2; gboolean copy_char = TRUE; if (!str) @@ -463,7 +463,7 @@ nmc_filter_out_colors(const char *str) char * nmc_get_user_input(const char *ask_str) { - char * line = NULL; + char *line = NULL; size_t line_ln = 0; ssize_t num; @@ -489,11 +489,11 @@ int nmc_string_to_arg_array(const char *line, const char *delim, gboolean unquote, - char *** argv, - int * argc) + char ***argv, + int *argc) { gs_free const char **arr0 = NULL; - char ** arr; + char **arr; arr0 = nm_strsplit_set(line ?: "", delim ?: " \t"); if (!arr0) @@ -503,7 +503,7 @@ nmc_string_to_arg_array(const char *line, if (unquote) { int i = 0; - char * s; + char *s; size_t l; const char *quotes = "\"'"; @@ -658,17 +658,17 @@ typedef struct _PrintDataCol { } PrintDataCol; static gboolean -_output_selection_append(GArray * cols, +_output_selection_append(GArray *cols, guint parent_idx, const NMMetaSelectionItem *selection_item, - GPtrArray * gfree_keeper, - GError ** error) + GPtrArray *gfree_keeper, + GError **error) { gs_free gpointer nested_to_free = NULL; guint col_idx; guint i; const NMMetaAbstractInfo *const *nested; - NMMetaSelectionResultList * selection; + NMMetaSelectionResultList *selection; col_idx = cols->len; @@ -787,16 +787,16 @@ _output_selection_complete(GArray *cols) */ static gboolean _output_selection_parse(const NMMetaAbstractInfo *const *fields, - const char * fields_str, - PrintDataCol ** out_cols_data, - guint * out_cols_len, - GPtrArray ** out_gfree_keeper, - GError ** error) + const char *fields_str, + PrintDataCol **out_cols_data, + guint *out_cols_len, + GPtrArray **out_gfree_keeper, + GError **error) { - NMMetaSelectionResultList *selection; + NMMetaSelectionResultList *selection; gs_unref_ptrarray GPtrArray *gfree_keeper = NULL; - gs_unref_array GArray *cols = NULL; - guint i; + gs_unref_array GArray *cols = NULL; + guint i; selection = nm_meta_selection_create_parse_list(fields, fields_str, FALSE, error); if (!selection) @@ -853,15 +853,15 @@ _output_selection_parse(const NMMetaAbstractInfo *const *fields, * Caller is responsible for freeing the array. */ GArray * -parse_output_fields(const char * fields_str, +parse_output_fields(const char *fields_str, const NMMetaAbstractInfo *const *fields_array, gboolean parse_groups, - GPtrArray ** out_group_fields, - GError ** error) + GPtrArray **out_group_fields, + GError **error) { gs_free NMMetaSelectionResultList *selection = NULL; - GArray * array; - GPtrArray * group_fields = NULL; + GArray *array; + GPtrArray *group_fields = NULL; guint i; g_return_val_if_fail(!error || !*error, NULL); @@ -926,7 +926,7 @@ nmc_empty_output_fields(NmcOutputData *output_data) typedef struct { guint col_idx; const PrintDataCol *col; - const char * title; + const char *title; bool title_to_free : 1; /* whether the column should be printed. If not %TRUE, @@ -946,7 +946,7 @@ typedef struct { const PrintDataHeaderCell *header_cell; NMMetaColor color; union { - const char * plain; + const char *plain; const char *const *strv; } text; PrintDataCellFormatType text_format : 3; @@ -993,16 +993,16 @@ _print_data_cell_clear(gpointer cell_p) } static void -_print_fill(const NmcConfig * nmc_config, - gpointer const * targets, +_print_fill(const NmcConfig *nmc_config, + gpointer const *targets, gpointer targets_data, const PrintDataCol *cols, guint cols_len, - GArray ** out_header_row, - GArray ** out_cells) + GArray **out_header_row, + GArray **out_cells) { - GArray * cells; - GArray * header_row; + GArray *cells; + GArray *header_row; guint i_row, i_col; guint targets_len; NMMetaAccessorGetType text_get_type; @@ -1012,8 +1012,8 @@ _print_fill(const NmcConfig * nmc_config, g_array_set_clear_func(header_row, _print_data_header_cell_clear); for (i_col = 0; i_col < cols_len; i_col++) { - const PrintDataCol * col; - PrintDataHeaderCell * header_cell; + const PrintDataCol *col; + PrintDataHeaderCell *header_cell; guint col_idx; const NMMetaAbstractInfo *info; @@ -1064,9 +1064,9 @@ _print_fill(const NmcConfig * nmc_config, PrintDataCell *cells_line = &g_array_index(cells, PrintDataCell, i_row * header_row->len); for (i_col = 0; i_col < header_row->len; i_col++) { - char * to_free = NULL; - PrintDataCell * cell = &cells_line[i_col]; - PrintDataHeaderCell * header_cell; + char *to_free = NULL; + PrintDataCell *cell = &cells_line[i_col]; + PrintDataHeaderCell *header_cell; const NMMetaAbstractInfo *info; NMMetaAccessorGetOutFlags text_out_flags, color_out_flags; gconstpointer value; @@ -1155,7 +1155,7 @@ _print_fill(const NmcConfig * nmc_config, const PrintDataCell *cells_line = &g_array_index(cells, PrintDataCell, i_row * header_row->len); const PrintDataCell *cell = &cells_line[i_col]; - const char *const * i_strv; + const char *const *i_strv; switch (cell->text_format) { case PRINT_DATA_CELL_FORMAT_TYPE_PLAIN: @@ -1185,7 +1185,7 @@ static gboolean _print_skip_column(const NmcConfig *nmc_config, const PrintDataHeaderCell *header_cell) { const NMMetaSelectionItem *selection_item; - const NMMetaAbstractInfo * info; + const NMMetaAbstractInfo *info; selection_item = header_cell->col->selection_item; info = selection_item->info; @@ -1217,16 +1217,16 @@ _print_skip_column(const NmcConfig *nmc_config, const PrintDataHeaderCell *heade } static void -_print_do(const NmcConfig * nmc_config, - const char * header_name_no_l10n, +_print_do(const NmcConfig *nmc_config, + const char *header_name_no_l10n, guint col_len, guint row_len, const PrintDataHeaderCell *header_row, - const PrintDataCell * cells) + const PrintDataCell *cells) { - int width1, width2; - int table_width = 0; - guint i_row, i_col; + int width1, width2; + int table_width = 0; + guint i_row, i_col; nm_auto_free_gstring GString *str = NULL; g_assert(col_len); @@ -1235,7 +1235,7 @@ _print_do(const NmcConfig * nmc_config, if (nmc_config->print_output == NMC_PRINT_PRETTY && header_name_no_l10n) { gs_free char *line = NULL; int header_width; - const char * header_name = _(header_name_no_l10n); + const char *header_name = _(header_name_no_l10n); header_width = nmc_string_screen_width(header_name, NULL) + 4; @@ -1261,7 +1261,7 @@ _print_do(const NmcConfig * nmc_config, && !nmc_config->multiline_output) { for (i_col = 0; i_col < col_len; i_col++) { const PrintDataHeaderCell *header_cell = &header_row[i_col]; - const char * title; + const char *title; if (_print_skip_column(nmc_config, header_cell)) continue; @@ -1297,7 +1297,7 @@ _print_do(const NmcConfig * nmc_config, for (i_col = 0; i_col < col_len; i_col++) { const PrintDataCell *cell = ¤t_line[i_col]; - const char *const * lines = NULL; + const char *const *lines = NULL; guint i_lines, lines_len; if (_print_skip_column(nmc_config, cell->header_cell)) @@ -1318,7 +1318,7 @@ _print_do(const NmcConfig * nmc_config, for (i_lines = 0; i_lines < lines_len; i_lines++) { gs_free char *text_to_free = NULL; - const char * text; + const char *text; text = colorize_string(nmc_config, cell->color, lines[i_lines], &text_to_free); if (nmc_config->multiline_output) { @@ -1385,19 +1385,19 @@ _print_do(const NmcConfig * nmc_config, } gboolean -nmc_print(const NmcConfig * nmc_config, - gpointer const * targets, +nmc_print(const NmcConfig *nmc_config, + gpointer const *targets, gpointer targets_data, - const char * header_name_no_l10n, + const char *header_name_no_l10n, const NMMetaAbstractInfo *const *fields, - const char * fields_str, - GError ** error) + const char *fields_str, + GError **error) { gs_unref_ptrarray GPtrArray *gfree_keeper = NULL; - gs_free PrintDataCol *cols_data = NULL; - guint cols_len; - gs_unref_array GArray *header_row = NULL; - gs_unref_array GArray *cells = NULL; + gs_free PrintDataCol *cols_data = NULL; + guint cols_len; + gs_unref_array GArray *header_row = NULL; + gs_unref_array GArray *cells = NULL; if (!_output_selection_parse(fields, fields_str, &cols_data, &cols_len, &gfree_keeper, error)) return FALSE; @@ -1528,15 +1528,15 @@ nmc_terminal_spawn_pager(const NmcConfig *nmc_config) /*****************************************************************************/ static const char * -get_value_to_print(const NmcConfig * nmc_config, +get_value_to_print(const NmcConfig *nmc_config, const NmcOutputField *field, gboolean field_name, - const char * not_set_str, - char ** out_to_free) + const char *not_set_str, + char **out_to_free) { gboolean is_array = field->value_is_array; - const char * value; - const char * out; + const char *value; + const char *out; gs_free char *free_value = NULL; nm_assert(out_to_free && !*out_to_free); @@ -1569,18 +1569,18 @@ get_value_to_print(const NmcConfig * nmc_config, * of 'field_values' array. */ void -print_required_fields(const NmcConfig * nmc_config, - NmcPagerData * pager_data, +print_required_fields(const NmcConfig *nmc_config, + NmcPagerData *pager_data, NmcOfFlags of_flags, - const GArray * indices, - const char * header_name, + const GArray *indices, + const char *header_name, int indent, const NmcOutputField *field_values) { nm_auto_free_gstring GString *str = NULL; int width1, width2; int table_width = 0; - const char * not_set_str; + const char *not_set_str; int i; gboolean main_header_add = of_flags & NMC_OF_FLAG_MAIN_HEADER_ADD; gboolean main_header_only = of_flags & NMC_OF_FLAG_MAIN_HEADER_ONLY; @@ -1635,7 +1635,7 @@ print_required_fields(const NmcConfig * nmc_config, if (is_array) { gs_free char *val_to_free = NULL; - const char ** p, *val, *print_val; + const char **p, *val, *print_val; int j; /* value is a null-terminated string array */ @@ -1664,9 +1664,9 @@ print_required_fields(const NmcConfig * nmc_config, } else { gs_free char *val_to_free = NULL; gs_free char *tmp = NULL; - const char * hdr_name = (const char *) field_values[0].value; - const char * val = (const char *) field_values[idx].value; - const char * print_val; + const char *hdr_name = (const char *) field_values[0].value; + const char *val = (const char *) field_values[idx].value; + const char *print_val; /* value is a string */ @@ -1703,7 +1703,7 @@ print_required_fields(const NmcConfig * nmc_config, for (i = 0; i < indices->len; i++) { gs_free char *val_to_free = NULL; int idx; - const char * value; + const char *value; idx = g_array_index(indices, int, i); @@ -1782,7 +1782,7 @@ print_data_prepare_width(GPtrArray *output_data) for (j = 0; j < output_data->len; j++) { gboolean field_names; gs_free char *val_to_free = NULL; - const char * value; + const char *value; row = g_ptr_array_index(output_data, j); field_names = row[0].flags & NMC_OF_FLAG_FIELD_NAMES; @@ -1798,10 +1798,10 @@ print_data_prepare_width(GPtrArray *output_data) } void -print_data(const NmcConfig * nmc_config, - NmcPagerData * pager_data, - const GArray * indices, - const char * header_name, +print_data(const NmcConfig *nmc_config, + NmcPagerData *pager_data, + const GArray *indices, + const char *header_name, int indent, const NmcOutputData *out) { diff --git a/src/nmcli/utils.h b/src/nmcli/utils.h index aadaab67..c6ead55b 100644 --- a/src/nmcli/utils.h +++ b/src/nmcli/utils.h @@ -11,7 +11,7 @@ /* === Types === */ typedef struct { - const char * name; + const char *name; gboolean has_value; const char **value; gboolean mandatory; @@ -22,16 +22,16 @@ typedef struct { int next_arg(NmCli *nmc, int *argc, const char *const **argv, ...); gboolean nmc_arg_is_help(const char *arg); gboolean nmc_arg_is_option(const char *arg, const char *opt_name); -gboolean nmc_parse_args(nmc_arg_t * arg_arr, +gboolean nmc_parse_args(nmc_arg_t *arg_arr, gboolean last, - int * argc, + int *argc, const char *const **argv, - GError ** error); -char * ssid_to_hex(const char *str, gsize len); + GError **error); +char *ssid_to_hex(const char *str, gsize len); void nmc_terminal_erase_line(void); void nmc_terminal_show_progress(const char *str); pid_t nmc_terminal_spawn_pager(const NmcConfig *nmc_config); -char * nmc_colorize(const NmcConfig *nmc_config, NMMetaColor color, const char *fmt, ...) +char *nmc_colorize(const NmcConfig *nmc_config, NMMetaColor color, const char *fmt, ...) _nm_printf(3, 4); void nmc_filter_out_colors_inplace(char *str); char *nmc_filter_out_colors(const char *str); @@ -39,8 +39,8 @@ char *nmc_get_user_input(const char *ask_str); int nmc_string_to_arg_array(const char *line, const char *delim, gboolean unquote, - char *** argv, - int * argc); + char ***argv, + int *argc); char *nmc_util_strv_for_display(const char *const *strv, gboolean brackets); int nmc_string_screen_width(const char *start, const char *end); void set_val_str(NmcOutputField fields_array[], guint32 index, char *value); @@ -50,25 +50,25 @@ void set_val_arrc(NmcOutputField fields_array[], guint32 index, const char **va void set_val_color_all(NmcOutputField fields_array[], NMMetaColor color); void nmc_free_output_field_values(NmcOutputField fields_array[]); -GArray * parse_output_fields(const char * fields_str, +GArray *parse_output_fields(const char *fields_str, const NMMetaAbstractInfo *const *fields_array, gboolean parse_groups, - GPtrArray ** group_fields, - GError ** error); + GPtrArray **group_fields, + GError **error); NmcOutputField *nmc_dup_fields_array(const NMMetaAbstractInfo *const *fields, NmcOfFlags flags); void nmc_empty_output_fields(NmcOutputData *output_data); -void print_required_fields(const NmcConfig * nmc_config, - NmcPagerData * pager_data, +void print_required_fields(const NmcConfig *nmc_config, + NmcPagerData *pager_data, NmcOfFlags of_flags, - const GArray * indices, - const char * header_name, + const GArray *indices, + const char *header_name, int indent, const NmcOutputField *field_values); void print_data_prepare_width(GPtrArray *output_data); -void print_data(const NmcConfig * nmc_config, - NmcPagerData * pager_data, - const GArray * indices, - const char * header_name, +void print_data(const NmcConfig *nmc_config, + NmcPagerData *pager_data, + const GArray *indices, + const char *header_name, int indent, const NmcOutputData *out); @@ -251,8 +251,8 @@ struct _NmcMetaGenericInfo { const NMMetaType *meta_type; }; NmcGenericInfoType info_type; - const char * name; - const char * name_header; + const char *name; + const char *name_header; const NmcMetaGenericInfo *const *nested; #define NMC_META_GENERIC_INFO_GET_FCN_ARGS \ @@ -327,7 +327,7 @@ typedef enum { static inline char * nmc_meta_generic_get_enum_with_detail(NmcMetaGenericGetEnumType get_enum_type, gint64 enum_val, - const char * str_val, + const char *str_val, NMMetaAccessorGetType get_type) { if (!NM_IN_SET(get_type, NM_META_ACCESSOR_GET_TYPE_PRETTY, NM_META_ACCESSOR_GET_TYPE_PARSABLE)) @@ -359,13 +359,13 @@ nmc_meta_generic_get_enum_with_detail(NmcMetaGenericGetEnumType get_enum_type, /*****************************************************************************/ -gboolean nmc_print(const NmcConfig * nmc_config, - gpointer const * targets, +gboolean nmc_print(const NmcConfig *nmc_config, + gpointer const *targets, gpointer targets_data, - const char * header_name_no_l10n, + const char *header_name_no_l10n, const NMMetaAbstractInfo *const *fields, - const char * fields_str, - GError ** error); + const char *fields_str, + GError **error); /*****************************************************************************/ diff --git a/src/nmtui/nm-editor-bindings.c b/src/nmtui/nm-editor-bindings.c index 59474fba..22ffdfd5 100644 --- a/src/nmtui/nm-editor-bindings.c +++ b/src/nmtui/nm-editor-bindings.c @@ -55,16 +55,16 @@ nm_editor_bindings_init(void) } static gboolean -ip_addresses_with_prefix_to_strv(GBinding * binding, +ip_addresses_with_prefix_to_strv(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { - GPtrArray * addrs; + GPtrArray *addrs; NMIPAddress *addr; - const char * addrstr; + const char *addrstr; guint32 prefix; - char ** strings; + char **strings; int i; addrs = g_value_get_boxed(source_value); @@ -86,16 +86,16 @@ ip_addresses_with_prefix_to_strv(GBinding * binding, } static gboolean -ip_addresses_with_prefix_from_strv(GBinding * binding, +ip_addresses_with_prefix_from_strv(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { int addr_family = GPOINTER_TO_INT(user_data); - char ** strings; - GPtrArray * addrs; + char **strings; + GPtrArray *addrs; NMIPAddress *addr; - char * addrstr; + char *addrstr; int prefix; int i; @@ -165,9 +165,9 @@ ip_addresses_with_prefix_from_strv(GBinding * binding, void nm_editor_bind_ip_addresses_with_prefix_to_strv(int addr_family, gpointer source, - const char * source_property, + const char *source_property, gpointer target, - const char * target_property, + const char *target_property, GBindingFlags flags) { g_object_bind_property_full(source, @@ -182,9 +182,9 @@ nm_editor_bind_ip_addresses_with_prefix_to_strv(int addr_family, } static gboolean -ip_addresses_check_and_copy(GBinding * binding, +ip_addresses_check_and_copy(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { int addr_family = GPOINTER_TO_INT(user_data); @@ -220,9 +220,9 @@ ip_addresses_check_and_copy(GBinding * binding, void nm_editor_bind_ip_addresses_to_strv(int addr_family, gpointer source, - const char * source_property, + const char *source_property, gpointer target, - const char * target_property, + const char *target_property, GBindingFlags flags) { g_object_bind_property_full(source, @@ -237,9 +237,9 @@ nm_editor_bind_ip_addresses_to_strv(int addr_family, } static gboolean -ip_gateway_to_string(GBinding * binding, +ip_gateway_to_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { g_value_set_string(target_value, g_value_get_string(source_value)); @@ -247,9 +247,9 @@ ip_gateway_to_string(GBinding * binding, } static gboolean -ip_gateway_from_string(GBinding * binding, +ip_gateway_from_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { int addr_family = GPOINTER_TO_INT(user_data); @@ -264,9 +264,9 @@ ip_gateway_from_string(GBinding * binding, } static gboolean -ip_addresses_to_gateway(GBinding * binding, +ip_addresses_to_gateway(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { GPtrArray *addrs; @@ -280,9 +280,9 @@ ip_addresses_to_gateway(GBinding * binding, } static gboolean -ip_addresses_to_sensitivity(GBinding * binding, +ip_addresses_to_sensitivity(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { GPtrArray *addrs; @@ -319,8 +319,8 @@ void nm_editor_bind_ip_gateway_to_string(int addr_family, NMSettingIPConfig *source, gpointer target, - const char * target_property, - const char * target_sensitive_property, + const char *target_property, + const char *target_sensitive_property, GBindingFlags flags) { g_object_bind_property_full(source, @@ -353,14 +353,14 @@ nm_editor_bind_ip_gateway_to_string(int addr_family, } static gboolean -ip_route_transform_to_dest_string(GBinding * binding, +ip_route_transform_to_dest_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { - NMIPRoute * route; + NMIPRoute *route; const char *addrstr; - char * string; + char *string; route = g_value_get_boxed(source_value); if (route) @@ -377,12 +377,12 @@ ip_route_transform_to_dest_string(GBinding * binding, } static gboolean -ip_route_transform_to_next_hop_string(GBinding * binding, +ip_route_transform_to_next_hop_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { - NMIPRoute * route; + NMIPRoute *route; const char *addrstr; route = g_value_get_boxed(source_value); @@ -398,13 +398,13 @@ ip_route_transform_to_next_hop_string(GBinding * binding, } static gboolean -ip_route_transform_to_metric_string(GBinding * binding, +ip_route_transform_to_metric_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { NMIPRoute *route; - char * string; + char *string; route = g_value_get_boxed(source_value); if (route && nm_ip_route_get_dest(route) && nm_ip_route_get_metric(route) != -1) { @@ -416,15 +416,15 @@ ip_route_transform_to_metric_string(GBinding * binding, } static gboolean -ip_route_transform_from_dest_string(GBinding * binding, +ip_route_transform_from_dest_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { int addr_family = GPOINTER_TO_INT(user_data); - NMIPRoute * route; + NMIPRoute *route; const char *text; - char * addrstr; + char *addrstr; int prefix; text = g_value_get_string(source_value); @@ -461,13 +461,13 @@ ip_route_transform_from_dest_string(GBinding * binding, } static gboolean -ip_route_transform_from_next_hop_string(GBinding * binding, +ip_route_transform_from_next_hop_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { int addr_family = GPOINTER_TO_INT(user_data); - NMIPRoute * route; + NMIPRoute *route; const char *text; text = g_value_get_string(source_value); @@ -490,12 +490,12 @@ ip_route_transform_from_next_hop_string(GBinding * binding, } static gboolean -ip_route_transform_from_metric_string(GBinding * binding, +ip_route_transform_from_metric_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { - NMIPRoute * route; + NMIPRoute *route; const char *text; gint64 metric; @@ -538,13 +538,13 @@ ip_route_transform_from_metric_string(GBinding * binding, void nm_editor_bind_ip_route_to_strings(int addr_family, gpointer source, - const char * source_property, + const char *source_property, gpointer dest_target, - const char * dest_target_property, + const char *dest_target_property, gpointer next_hop_target, - const char * next_hop_target_property, + const char *next_hop_target_property, gpointer metric_target, - const char * metric_target_property, + const char *metric_target_property, GBindingFlags flags) { g_object_bind_property_full(source, @@ -577,13 +577,13 @@ nm_editor_bind_ip_route_to_strings(int addr_family, } gboolean -peer_transform_to_public_key_string(GBinding * binding, +peer_transform_to_public_key_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { NMWireGuardPeer *peer; - char * string; + char *string; peer = g_value_get_boxed(source_value); if (peer && nm_wireguard_peer_get_public_key(peer)) { @@ -595,13 +595,13 @@ peer_transform_to_public_key_string(GBinding * binding, } gboolean -peer_transform_to_allowed_ips_string(GBinding * binding, +peer_transform_to_allowed_ips_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { NMWireGuardPeer *peer; - GString * string = NULL; + GString *string = NULL; guint i, len; peer = g_value_get_boxed(source_value); @@ -623,13 +623,13 @@ peer_transform_to_allowed_ips_string(GBinding * binding, } gboolean -peer_transform_to_endpoint_string(GBinding * binding, +peer_transform_to_endpoint_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { NMWireGuardPeer *peer; - char * string; + char *string; peer = g_value_get_boxed(source_value); if (peer && nm_wireguard_peer_get_endpoint(peer)) { @@ -641,13 +641,13 @@ peer_transform_to_endpoint_string(GBinding * binding, } gboolean -peer_transform_to_preshared_key_string(GBinding * binding, +peer_transform_to_preshared_key_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { NMWireGuardPeer *peer; - char * string; + char *string; peer = g_value_get_boxed(source_value); if (peer && nm_wireguard_peer_get_preshared_key(peer)) { @@ -659,13 +659,13 @@ peer_transform_to_preshared_key_string(GBinding * binding, } gboolean -peer_transform_to_persistent_keepalive_string(GBinding * binding, +peer_transform_to_persistent_keepalive_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { NMWireGuardPeer *peer; - char * string; + char *string; peer = g_value_get_boxed(source_value); if (peer && nm_wireguard_peer_get_persistent_keepalive(peer)) { @@ -677,13 +677,13 @@ peer_transform_to_persistent_keepalive_string(GBinding * binding, } gboolean -peer_transform_from_public_key_string(GBinding * binding, +peer_transform_from_public_key_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { NMWireGuardPeer *peer; - const char * text; + const char *text; text = g_value_get_string(source_value); @@ -700,14 +700,14 @@ peer_transform_from_public_key_string(GBinding * binding, } gboolean -peer_transform_from_allowed_ips_string(GBinding * binding, +peer_transform_from_allowed_ips_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { NMWireGuardPeer *peer; - const char * text; - char ** strv; + const char *text; + char **strv; guint i; text = g_value_get_string(source_value); @@ -730,13 +730,13 @@ peer_transform_from_allowed_ips_string(GBinding * binding, } gboolean -peer_transform_from_endpoint_string(GBinding * binding, +peer_transform_from_endpoint_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { NMWireGuardPeer *peer; - const char * text; + const char *text; text = g_value_get_string(source_value); @@ -753,13 +753,13 @@ peer_transform_from_endpoint_string(GBinding * binding, } gboolean -peer_transform_from_preshared_key_string(GBinding * binding, +peer_transform_from_preshared_key_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { NMWireGuardPeer *peer; - const char * text; + const char *text; text = g_value_get_string(source_value); @@ -777,13 +777,13 @@ peer_transform_from_preshared_key_string(GBinding * binding, } gboolean -peer_transform_from_persistent_keepalive_string(GBinding * binding, +peer_transform_from_persistent_keepalive_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { NMWireGuardPeer *peer; - const char * text; + const char *text; text = g_value_get_string(source_value); @@ -801,12 +801,12 @@ peer_transform_from_persistent_keepalive_string(GBinding * binding, /* Wireless security method binding */ typedef struct { - NMConnection * connection; + NMConnection *connection; NMSettingWirelessSecurity *s_wsec; gboolean s_wsec_in_use; GObject *target; - char * target_property; + char *target_property; gboolean updating; } NMEditorWirelessSecurityMethodBinding; @@ -873,7 +873,7 @@ static void wireless_connection_changed(NMConnection *connection, gpointer user_data) { NMEditorWirelessSecurityMethodBinding *binding = user_data; - NMSettingWirelessSecurity * s_wsec; + NMSettingWirelessSecurity *s_wsec; if (binding->updating) return; @@ -890,7 +890,7 @@ static void wireless_security_target_changed(GObject *object, GParamSpec *pspec, gpointer user_data) { NMEditorWirelessSecurityMethodBinding *binding = user_data; - char * method; + char *method; if (binding->updating) return; @@ -1029,14 +1029,14 @@ wireless_security_target_destroyed(gpointer user_data, GObject *ex_target) * changes. */ void -nm_editor_bind_wireless_security_method(NMConnection * connection, +nm_editor_bind_wireless_security_method(NMConnection *connection, NMSettingWirelessSecurity *s_wsec, gpointer target, - const char * target_property, + const char *target_property, GBindingFlags flags) { NMEditorWirelessSecurityMethodBinding *binding; - char * notify; + char *notify; binding = g_slice_new0(NMEditorWirelessSecurityMethodBinding); @@ -1078,8 +1078,8 @@ nm_editor_bind_wireless_security_method(NMConnection * connection, typedef struct { NMSettingWirelessSecurity *s_wsec; - GObject * entry, *key_selector; - char * entry_property, *key_selector_property; + GObject *entry, *key_selector; + char *entry_property, *key_selector_property; gboolean updating; } NMEditorWepKeyBinding; @@ -1088,7 +1088,7 @@ static void wep_key_setting_changed(GObject *object, GParamSpec *pspec, gpointer user_data) { NMEditorWepKeyBinding *binding = user_data; - const char * key; + const char *key; int index; if (binding->updating) @@ -1107,7 +1107,7 @@ static void wep_key_ui_changed(GObject *object, GParamSpec *pspec, gpointer user_data) { NMEditorWepKeyBinding *binding = user_data; - char * key; + char *key; int index; if (binding->updating) @@ -1180,13 +1180,13 @@ wep_key_target_destroyed(gpointer user_data, GObject *ex_target) void nm_editor_bind_wireless_security_wep_key(NMSettingWirelessSecurity *s_wsec, gpointer entry, - const char * entry_property, + const char *entry_property, gpointer key_selector, - const char * key_selector_property, + const char *key_selector_property, GBindingFlags flags) { NMEditorWepKeyBinding *binding; - char * notify; + char *notify; binding = g_slice_new0(NMEditorWepKeyBinding); binding->s_wsec = g_object_ref(s_wsec); @@ -1237,7 +1237,7 @@ nm_editor_bind_wireless_security_wep_key(NMSettingWirelessSecurity *s_wsec, /* VLAN binding */ typedef struct { - NMSettingVlan * s_vlan; + NMSettingVlan *s_vlan; NMSettingConnection *s_con; char *last_ifname_parent; @@ -1250,7 +1250,7 @@ static gboolean parse_interface_name(const char *ifname, char **parent_ifname, int *id) { const char *ifname_end; - char * end; + char *end; if (!ifname || !*ifname) return FALSE; @@ -1280,8 +1280,8 @@ static void vlan_settings_changed(GObject *object, GParamSpec *pspec, gpointer user_data) { NMEditorVlanWidgetBinding *binding = user_data; - const char * ifname, *parent; - char * ifname_parent; + const char *ifname, *parent; + char *ifname_parent; int ifname_id, id; if (binding->updating) @@ -1341,7 +1341,7 @@ void nm_editor_bind_vlan_name(NMSettingVlan *s_vlan, NMSettingConnection *s_con) { NMEditorVlanWidgetBinding *binding; - const char * ifname; + const char *ifname; binding = g_slice_new0(NMEditorVlanWidgetBinding); binding->s_vlan = s_vlan; diff --git a/src/nmtui/nm-editor-bindings.h b/src/nmtui/nm-editor-bindings.h index a9bf51ed..ef2f36f2 100644 --- a/src/nmtui/nm-editor-bindings.h +++ b/src/nmtui/nm-editor-bindings.h @@ -10,97 +10,97 @@ void nm_editor_bindings_init(void); void nm_editor_bind_ip_addresses_with_prefix_to_strv(int family, gpointer source, - const char * source_property, + const char *source_property, gpointer target, - const char * target_property, + const char *target_property, GBindingFlags flags); void nm_editor_bind_ip_addresses_to_strv(int family, gpointer source, - const char * source_property, + const char *source_property, gpointer target, - const char * target_property, + const char *target_property, GBindingFlags flags); void nm_editor_bind_ip_gateway_to_string(int family, NMSettingIPConfig *source, gpointer target, - const char * target_property, - const char * target_sensitive_property, + const char *target_property, + const char *target_sensitive_property, GBindingFlags flags); void nm_editor_bind_ip_route_to_strings(int family, gpointer source, - const char * source_property, + const char *source_property, gpointer dest_target, - const char * dest_target_property, + const char *dest_target_property, gpointer next_hop_target, - const char * next_hop_target_property, + const char *next_hop_target_property, gpointer metric_target, - const char * metric_target_property, + const char *metric_target_property, GBindingFlags flags); -void nm_editor_bind_wireless_security_method(NMConnection * connection, +void nm_editor_bind_wireless_security_method(NMConnection *connection, NMSettingWirelessSecurity *s_wsec, gpointer target, - const char * target_property, + const char *target_property, GBindingFlags flags); void nm_editor_bind_wireless_security_wep_key(NMSettingWirelessSecurity *s_wsec, gpointer entry, - const char * entry_property, + const char *entry_property, gpointer key_selector, - const char * key_selector_property, + const char *key_selector_property, GBindingFlags flags); void nm_editor_bind_vlan_name(NMSettingVlan *s_vlan, NMSettingConnection *s_con); -gboolean peer_transform_to_public_key_string(GBinding * binding, +gboolean peer_transform_to_public_key_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data); -gboolean peer_transform_to_allowed_ips_string(GBinding * binding, +gboolean peer_transform_to_allowed_ips_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data); -gboolean peer_transform_to_endpoint_string(GBinding * binding, +gboolean peer_transform_to_endpoint_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data); -gboolean peer_transform_to_preshared_key_string(GBinding * binding, +gboolean peer_transform_to_preshared_key_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data); -gboolean peer_transform_to_persistent_keepalive_string(GBinding * binding, +gboolean peer_transform_to_persistent_keepalive_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data); -gboolean peer_transform_from_public_key_string(GBinding * binding, +gboolean peer_transform_from_public_key_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data); -gboolean peer_transform_from_allowed_ips_string(GBinding * binding, +gboolean peer_transform_from_allowed_ips_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data); -gboolean peer_transform_from_endpoint_string(GBinding * binding, +gboolean peer_transform_from_endpoint_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data); -gboolean peer_transform_from_preshared_key_string(GBinding * binding, +gboolean peer_transform_from_preshared_key_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data); -gboolean peer_transform_from_persistent_keepalive_string(GBinding * binding, +gboolean peer_transform_from_persistent_keepalive_string(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data); #endif /* NM_EDITOR_BINDINGS_H */ diff --git a/src/nmtui/nm-editor-utils.c b/src/nmtui/nm-editor-utils.c index 2b6acbbe..a3ee7a75 100644 --- a/src/nmtui/nm-editor-utils.c +++ b/src/nmtui/nm-editor-utils.c @@ -49,9 +49,9 @@ wifi_connection_setup_func(NMConnection *connection, NMSettingConnection *s_con, static void bond_connection_setup_func(NMConnection *connection, NMSettingConnection *s_con, NMSetting *s_hw) { - NMSettingBond * s_bond = NM_SETTING_BOND(s_hw); + NMSettingBond *s_bond = NM_SETTING_BOND(s_hw); guint i; - const char * value; + const char *value; static const char *const options[] = { NM_SETTING_BOND_OPTION_MODE, NM_SETTING_BOND_OPTION_MIIMON, @@ -67,9 +67,9 @@ bond_connection_setup_func(NMConnection *connection, NMSettingConnection *s_con, } static void -wireguard_connection_setup_func(NMConnection * connection, +wireguard_connection_setup_func(NMConnection *connection, NMSettingConnection *s_con, - NMSetting * s_hw) + NMSetting *s_hw) { NMSettingIPConfig *s_ip; @@ -82,14 +82,14 @@ wireguard_connection_setup_func(NMConnection * connection, nm_connection_add_setting(connection, (NMSetting *) s_ip); } -typedef void (*NMEditorNewConnectionSetupFunc)(NMConnection * connection, +typedef void (*NMEditorNewConnectionSetupFunc)(NMConnection *connection, NMSettingConnection *s_con, - NMSetting * s_hw); + NMSetting *s_hw); typedef struct { NMEditorConnectionTypeData data; - const char * id_format; + const char *id_format; NMEditorNewConnectionSetupFunc connection_setup_func; gboolean no_autoconnect; } NMEditorConnectionTypeDataReal; @@ -127,8 +127,8 @@ sort_types(gconstpointer a, gconstpointer b) NMEditorConnectionTypeData ** nm_editor_utils_get_connection_type_list(void) { - GPtrArray * array; - NMEditorConnectionTypeDataReal * item; + GPtrArray *array; + NMEditorConnectionTypeDataReal *item; static NMEditorConnectionTypeData **list; #if 0 GHashTable *vpn_plugins_hash; @@ -291,8 +291,8 @@ static char * get_available_connection_name(const char *format, NMClient *client) { const GPtrArray *conns; - GSList * names = NULL, *iter; - char * cname = NULL; + GSList *names = NULL, *iter; + char *cname = NULL; int i = 0; nm_assert(_assert_format_int(format)); @@ -308,7 +308,7 @@ get_available_connection_name(const char *format, NMClient *client) /* Find the next available unique connection name */ for (i = 1; !cname && i < 10000; i++) { - char * temp; + char *temp; gboolean found = FALSE; NM_PRAGMA_WARNING_DISABLE("-Wformat-nonliteral") @@ -334,11 +334,11 @@ static char * get_available_iface_name(const char *try_name, NMClient *client) { const GPtrArray *connections; - NMConnection * connection; - char * new_name; + NMConnection *connection; + char *new_name; unsigned num = 1; int i = 0; - const char * ifname = NULL; + const char *ifname = NULL; connections = nm_client_get_connections(client); @@ -374,14 +374,14 @@ get_available_iface_name(const char *try_name, NMClient *client) NMConnection * nm_editor_utils_create_connection(GType type, NMConnection *master, NMClient *client) { - NMEditorConnectionTypeData ** types; + NMEditorConnectionTypeData **types; NMEditorConnectionTypeDataReal *type_data = NULL; - const char * master_setting_type = NULL, *master_uuid = NULL; + const char *master_setting_type = NULL, *master_uuid = NULL; GType master_type = G_TYPE_INVALID, slave_setting_type = G_TYPE_INVALID; - NMConnection * connection; + NMConnection *connection; NMSettingConnection *s_con; - NMSetting * s_hw, *s_slave; - char * uuid, *id, *ifname; + NMSetting *s_hw, *s_slave; + char *uuid, *id, *ifname; int i; if (master) { @@ -469,8 +469,8 @@ nm_editor_utils_create_connection(GType type, NMConnection *master, NMClient *cl NMEditorConnectionTypeData * nm_editor_utils_get_connection_type_data(NMConnection *conn) { - NMSettingConnection * s_con; - const char * conn_type; + NMSettingConnection *s_con; + const char *conn_type; GType conn_gtype; NMEditorConnectionTypeData **types; int i; diff --git a/src/nmtui/nm-editor-utils.h b/src/nmtui/nm-editor-utils.h index 5b624f93..decbc271 100644 --- a/src/nmtui/nm-editor-utils.h +++ b/src/nmtui/nm-editor-utils.h @@ -15,7 +15,7 @@ typedef struct { } NMEditorConnectionTypeData; NMEditorConnectionTypeData **nm_editor_utils_get_connection_type_list(void); -NMEditorConnectionTypeData * nm_editor_utils_get_connection_type_data(NMConnection *conn); +NMEditorConnectionTypeData *nm_editor_utils_get_connection_type_data(NMConnection *conn); NMConnection *nm_editor_utils_create_connection(GType type, NMConnection *master, NMClient *client); diff --git a/src/nmtui/nmt-address-list.c b/src/nmtui/nmt-address-list.c index 265457d6..1678f33f 100644 --- a/src/nmtui/nmt-address-list.c +++ b/src/nmtui/nmt-address-list.c @@ -32,7 +32,7 @@ G_DEFINE_TYPE(NmtAddressList, nmt_address_list, NMT_TYPE_WIDGET_LIST) typedef struct { NmtAddressListType list_type; - char ** strings; + char **strings; } NmtAddressListPrivate; enum { @@ -73,9 +73,9 @@ nmt_address_list_init(NmtAddressList *list) {} static gboolean -strings_transform_to_entry(GBinding * binding, +strings_transform_to_entry(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { int n = GPOINTER_TO_INT(user_data); @@ -90,12 +90,12 @@ strings_transform_to_entry(GBinding * binding, } static gboolean -strings_transform_from_entry(GBinding * binding, +strings_transform_from_entry(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { - NmtAddressList * list = NMT_ADDRESS_LIST(g_binding_get_source(binding)); + NmtAddressList *list = NMT_ADDRESS_LIST(g_binding_get_source(binding)); NmtAddressListPrivate *priv = NMT_ADDRESS_LIST_GET_PRIVATE(list); int n = GPOINTER_TO_INT(user_data); @@ -119,7 +119,7 @@ static NmtNewtWidget * nmt_address_list_create_widget(NmtWidgetList *list, int num) { NmtAddressListPrivate *priv = NMT_ADDRESS_LIST_GET_PRIVATE(list); - NmtNewtWidget * entry; + NmtNewtWidget *entry; if (priv->list_type == NMT_ADDRESS_LIST_IP4_WITH_PREFIX) entry = nmt_ip_entry_new(25, AF_INET, TRUE, FALSE); @@ -178,10 +178,10 @@ nmt_address_list_remove_clicked(NmtWidgetList *list, int num) } static void -nmt_address_list_set_property(GObject * object, +nmt_address_list_set_property(GObject *object, guint prop_id, const GValue *value, - GParamSpec * pspec) + GParamSpec *pspec) { NmtAddressListPrivate *priv = NMT_ADDRESS_LIST_GET_PRIVATE(object); @@ -223,7 +223,7 @@ nmt_address_list_get_property(GObject *object, guint prop_id, GValue *value, GPa static void nmt_address_list_class_init(NmtAddressListClass *list_class) { - GObjectClass * object_class = G_OBJECT_CLASS(list_class); + GObjectClass *object_class = G_OBJECT_CLASS(list_class); NmtWidgetListClass *widget_list_class = NMT_WIDGET_LIST_CLASS(list_class); g_type_class_add_private(list_class, sizeof(NmtAddressListPrivate)); diff --git a/src/nmtui/nmt-connect-connection-list.c b/src/nmtui/nmt-connect-connection-list.c index 486e1400..535cf8fd 100644 --- a/src/nmtui/nmt-connect-connection-list.c +++ b/src/nmtui/nmt-connect-connection-list.c @@ -27,7 +27,7 @@ G_DEFINE_TYPE(NmtConnectConnectionList, nmt_connect_connection_list, NMT_TYPE_NE NmtConnectConnectionListPrivate)) typedef struct { - char * name; + char *name; NMDevice *device; int sort_order; @@ -37,11 +37,11 @@ typedef struct { typedef struct { const char *name; - char * ssid; + char *ssid; - NMConnection * conn; - NMAccessPoint * ap; - NMDevice * device; + NMConnection *conn; + NMAccessPoint *ap; + NMDevice *device; NMActiveConnection *active; } NmtConnectConnection; @@ -124,7 +124,7 @@ static int get_sort_order_for_connection(NMConnection *conn) { NMSettingConnection *s_con; - const char * type; + const char *type; int i; s_con = nm_connection_get_setting_connection(conn); @@ -178,7 +178,7 @@ add_connections_for_device(NmtConnectDevice *nmtdev, const GPtrArray *connection int i; for (i = 0; i < connections->len; i++) { - NMConnection * conn = connections->pdata[i]; + NMConnection *conn = connections->pdata[i]; NMSettingConnection *s_con; s_con = nm_connection_get_setting_connection(conn); @@ -201,7 +201,7 @@ static char * hash_ap(NMAccessPoint *ap) { unsigned char input[66]; - GBytes * ssid; + GBytes *ssid; NM80211Mode mode; guint32 flags; guint32 wpa_flags; @@ -246,12 +246,12 @@ static void add_connections_for_aps(NmtConnectDevice *nmtdev, const GPtrArray *connections) { NmtConnectConnection *nmtconn; - NMConnection * conn; - NMAccessPoint * ap; - const GPtrArray * aps; - GHashTable * seen_ssids; - GBytes * ssid; - char * ap_hash; + NMConnection *conn; + NMAccessPoint *ap; + const GPtrArray *aps; + GHashTable *seen_ssids; + GBytes *ssid; + char *ap_hash; int i, c; aps = nm_device_wifi_get_access_points(NM_DEVICE_WIFI(nmtdev->device)); @@ -301,13 +301,13 @@ add_connections_for_aps(NmtConnectDevice *nmtdev, const GPtrArray *connections) } static GSList * -append_nmt_devices_for_devices(GSList * nmt_devices, +append_nmt_devices_for_devices(GSList *nmt_devices, const GPtrArray *devices, - char ** names, + char **names, const GPtrArray *connections) { NmtConnectDevice *nmtdev; - NMDevice * device; + NMDevice *device; int i, sort_order; for (i = 0; i < devices->len; i++) { @@ -337,11 +337,11 @@ append_nmt_devices_for_devices(GSList * nmt_devices, static GSList * append_nmt_devices_for_virtual_devices(GSList *nmt_devices, const GPtrArray *connections) { - NmtConnectDevice * nmtdev = NULL; + NmtConnectDevice *nmtdev = NULL; int i; - GHashTable * devices_by_name; - char * name; - NMConnection * conn; + GHashTable *devices_by_name; + char *name; + NMConnection *conn; NmtConnectConnection *nmtconn; int sort_order; @@ -381,9 +381,9 @@ append_nmt_devices_for_virtual_devices(GSList *nmt_devices, const GPtrArray *con static GSList * append_nmt_devices_for_vpns(GSList *nmt_devices, const GPtrArray *connections) { - NmtConnectDevice * nmtdev; + NmtConnectDevice *nmtdev; int i; - NMConnection * conn; + NMConnection *conn; NmtConnectConnection *nmtconn; nmtdev = g_slice_new0(NmtConnectDevice); @@ -444,14 +444,14 @@ static void nmt_connect_connection_list_rebuild(NmtConnectConnectionList *list) { NmtConnectConnectionListPrivate *priv = NMT_CONNECT_CONNECTION_LIST_GET_PRIVATE(list); - NmtNewtListbox * listbox = NMT_NEWT_LISTBOX(list); - const GPtrArray * devices, *acs, *connections; + NmtNewtListbox *listbox = NMT_NEWT_LISTBOX(list); + const GPtrArray *devices, *acs, *connections; int max_width; - char ** names, *row, active_col; - const char * strength_col; - GSList * nmt_devices, *diter, *citer; - NmtConnectDevice * nmtdev; - NmtConnectConnection * nmtconn; + char **names, *row, active_col; + const char *strength_col; + GSList *nmt_devices, *diter, *citer; + NmtConnectDevice *nmtdev; + NmtConnectConnection *nmtconn; g_slist_free_full(priv->nmt_devices, (GDestroyNotify) nmt_connect_device_free); priv->nmt_devices = NULL; @@ -599,17 +599,17 @@ nmt_connect_connection_list_class_init(NmtConnectConnectionListClass *list_class */ gboolean nmt_connect_connection_list_get_connection(NmtConnectConnectionList *list, - const char * identifier, - NMConnection ** connection, - NMDevice ** device, - NMObject ** specific_object, - NMActiveConnection ** active) + const char *identifier, + NMConnection **connection, + NMDevice **device, + NMObject **specific_object, + NMActiveConnection **active) { NmtConnectConnectionListPrivate *priv = NMT_CONNECT_CONNECTION_LIST_GET_PRIVATE(list); - GSList * diter, *citer; - NmtConnectDevice * nmtdev; - NmtConnectConnection * nmtconn = NULL; - NMConnection * conn = NULL; + GSList *diter, *citer; + NmtConnectDevice *nmtdev; + NmtConnectConnection *nmtconn = NULL; + NMConnection *conn = NULL; g_return_val_if_fail(identifier, FALSE); @@ -669,10 +669,10 @@ found: */ gboolean nmt_connect_connection_list_get_selection(NmtConnectConnectionList *list, - NMConnection ** connection, - NMDevice ** device, - NMObject ** specific_object, - NMActiveConnection ** active) + NMConnection **connection, + NMDevice **device, + NMObject **specific_object, + NMActiveConnection **active) { NmtConnectConnection *nmtconn; diff --git a/src/nmtui/nmt-connect-connection-list.h b/src/nmtui/nmt-connect-connection-list.h index 15a319b1..1eea4d04 100644 --- a/src/nmtui/nmt-connect-connection-list.h +++ b/src/nmtui/nmt-connect-connection-list.h @@ -39,15 +39,15 @@ GType nmt_connect_connection_list_get_type(void); NmtNewtWidget *nmt_connect_connection_list_new(void); gboolean nmt_connect_connection_list_get_connection(NmtConnectConnectionList *list, - const char * identifier, - NMConnection ** connection, - NMDevice ** device, - NMObject ** specific_object, - NMActiveConnection ** active); + const char *identifier, + NMConnection **connection, + NMDevice **device, + NMObject **specific_object, + NMActiveConnection **active); gboolean nmt_connect_connection_list_get_selection(NmtConnectConnectionList *list, - NMConnection ** connection, - NMDevice ** device, - NMObject ** specific_object, - NMActiveConnection ** active); + NMConnection **connection, + NMDevice **device, + NMObject **specific_object, + NMActiveConnection **active); #endif /* NMT_CONNECT_CONNECTION_LIST_H */ diff --git a/src/nmtui/nmt-device-entry.c b/src/nmtui/nmt-device-entry.c index e831f4e4..7f312bd1 100644 --- a/src/nmtui/nmt-device-entry.c +++ b/src/nmtui/nmt-device-entry.c @@ -44,8 +44,8 @@ typedef struct { char *interface_name; char *mac_address; - char * label; - NmtNewtEntry * entry; + char *label; + NmtNewtEntry *entry; NmtNewtWidget *button; gboolean updating; @@ -91,13 +91,13 @@ nmt_device_entry_new(const char *label, int width, GType hardware_type) static gboolean device_entry_parse(NmtDeviceEntry *deventry, - const char * text, - char ** interface_name, - char ** mac_address) + const char *text, + char **interface_name, + char **mac_address) { NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE(deventry); guint8 buf[NM_UTILS_HWADDR_LEN_MAX]; - char ** words; + char **words; int len; *interface_name = *mac_address = NULL; @@ -151,7 +151,7 @@ static gboolean device_entry_validate(NmtNewtEntry *entry, const char *text, gpointer user_data) { NmtDeviceEntry *deventry = user_data; - char * ifname, *mac; + char *ifname, *mac; if (!device_entry_parse(deventry, text, &ifname, &mac)) return FALSE; @@ -165,8 +165,8 @@ static NMDevice * find_device_by_interface_name(NmtDeviceEntry *deventry, const char *interface_name) { NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE(deventry); - const GPtrArray * devices; - NMDevice * device = NULL; + const GPtrArray *devices; + NMDevice *device = NULL; int i; devices = nm_client_get_devices(nm_client); @@ -192,14 +192,14 @@ static NMDevice * find_device_by_mac_address(NmtDeviceEntry *deventry, const char *mac_address) { NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE(deventry); - const GPtrArray * devices; - NMDevice * device = NULL; + const GPtrArray *devices; + NMDevice *device = NULL; int i; devices = nm_client_get_devices(nm_client); for (i = 0; i < devices->len && !device; i++) { NMDevice *candidate = devices->pdata[i]; - char * hwaddr; + char *hwaddr; if (priv->hardware_type != G_TYPE_NONE && !G_TYPE_CHECK_INSTANCE_TYPE(candidate, priv->hardware_type)) @@ -222,9 +222,9 @@ static void update_entry(NmtDeviceEntry *deventry) { NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE(deventry); - const char * ifname; - char * mac, *text; - NMDevice * ifname_device, *mac_device; + const char *ifname; + char *mac, *text; + NMDevice *ifname_device, *mac_device; if (priv->interface_name) { ifname = priv->interface_name; @@ -314,8 +314,8 @@ static void entry_text_changed(GObject *object, GParamSpec *pspec, gpointer deventry) { NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE(deventry); - const char * text; - char * ifname, *mac; + const char *text; + char *ifname, *mac; if (priv->updating) return; @@ -335,7 +335,7 @@ static void nmt_device_entry_init(NmtDeviceEntry *deventry) { NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE(deventry); - NmtNewtWidget * entry; + NmtNewtWidget *entry; priv->hardware_type = G_TYPE_NONE; @@ -401,7 +401,7 @@ nmt_device_entry_finalize(GObject *object) * accepted by the filter will be allowed. */ void -nmt_device_entry_set_device_filter(NmtDeviceEntry * deventry, +nmt_device_entry_set_device_filter(NmtDeviceEntry *deventry, NmtDeviceEntryDeviceFilter filter, gpointer user_data) { @@ -412,15 +412,15 @@ nmt_device_entry_set_device_filter(NmtDeviceEntry * deventry, } static void -nmt_device_entry_set_property(GObject * object, +nmt_device_entry_set_property(GObject *object, guint prop_id, const GValue *value, - GParamSpec * pspec) + GParamSpec *pspec) { - NmtDeviceEntry * deventry = NMT_DEVICE_ENTRY(object); + NmtDeviceEntry *deventry = NMT_DEVICE_ENTRY(object); NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE(deventry); - const char * interface_name; - const char * mac_address; + const char *interface_name; + const char *mac_address; switch (prop_id) { case PROP_LABEL: diff --git a/src/nmtui/nmt-device-entry.h b/src/nmtui/nmt-device-entry.h index 13f82bc8..f66c3d8d 100644 --- a/src/nmtui/nmt-device-entry.h +++ b/src/nmtui/nmt-device-entry.h @@ -33,9 +33,9 @@ GType nmt_device_entry_get_type(void); NmtNewtWidget *nmt_device_entry_new(const char *label, int width, GType hardware_type); typedef gboolean (*NmtDeviceEntryDeviceFilter)(NmtDeviceEntry *deventry, - NMDevice * device, + NMDevice *device, gpointer user_data); -void nmt_device_entry_set_device_filter(NmtDeviceEntry * deventry, +void nmt_device_entry_set_device_filter(NmtDeviceEntry *deventry, NmtDeviceEntryDeviceFilter filter, gpointer user_data); diff --git a/src/nmtui/nmt-edit-connection-list.c b/src/nmtui/nmt-edit-connection-list.c index 9b31e06f..aec669c8 100644 --- a/src/nmtui/nmt-edit-connection-list.c +++ b/src/nmtui/nmt-edit-connection-list.c @@ -32,7 +32,7 @@ typedef struct { NmtEditConnectionListFilter connection_filter; gpointer connection_filter_data; - NmtNewtListbox * listbox; + NmtNewtListbox *listbox; NmtNewtButtonBox *buttons; NmtNewtWidget *add; @@ -73,8 +73,8 @@ static void nmt_edit_connection_list_init(NmtEditConnectionList *list) { NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(list); - NmtNewtWidget * listbox, *buttons; - NmtNewtGrid * grid = NMT_NEWT_GRID(list); + NmtNewtWidget *listbox, *buttons; + NmtNewtGrid *grid = NMT_NEWT_GRID(list); listbox = g_object_new(NMT_TYPE_NEWT_LISTBOX, "flags", @@ -135,8 +135,8 @@ static void free_connections(NmtEditConnectionList *list) { NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(list); - NMConnection * conn; - GSList * iter; + NMConnection *conn; + GSList *iter; for (iter = priv->connections; iter; iter = iter->next) { conn = iter->data; @@ -152,11 +152,11 @@ static void nmt_edit_connection_list_rebuild(NmtEditConnectionList *list) { NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(list); - const GPtrArray * connections; - GSList * iter; + const GPtrArray *connections; + GSList *iter; gboolean did_header = FALSE, did_vpn = FALSE; - NMEditorConnectionTypeData ** types; - NMConnection * conn, *selected_conn; + NMEditorConnectionTypeData **types; + NMConnection *conn, *selected_conn; int i, row, selected_row; selected_row = nmt_newt_listbox_get_active(priv->listbox); @@ -213,7 +213,7 @@ nmt_edit_connection_list_rebuild(NmtEditConnectionList *list) for (iter = priv->connections; iter; iter = iter->next) { NMSetting *setting; - char * indented; + char *indented; conn = iter->data; setting = nm_connection_get_setting(conn, types[i]->setting_type); @@ -254,7 +254,7 @@ rebuild_on_connections_changed(GObject *object, GParamSpec *pspec, gpointer list static void nmt_edit_connection_list_constructed(GObject *object) { - NmtEditConnectionList * list = NMT_EDIT_CONNECTION_LIST(object); + NmtEditConnectionList *list = NMT_EDIT_CONNECTION_LIST(object); NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(list); if (priv->extra) @@ -280,7 +280,7 @@ static void edit_clicked(NmtNewtButton *button, gpointer list) { NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(list); - NMConnection * connection; + NMConnection *connection; connection = nmt_newt_listbox_get_active_key(priv->listbox); g_return_if_fail(connection != NULL); @@ -292,7 +292,7 @@ static void delete_clicked(NmtNewtButton *button, gpointer list) { NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(list); - NMRemoteConnection * connection; + NMRemoteConnection *connection; connection = nmt_newt_listbox_get_active_key(priv->listbox); g_return_if_fail(connection != NULL); @@ -318,8 +318,8 @@ void nmt_edit_connection_list_recommit(NmtEditConnectionList *list) { NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(list); - NMConnection * conn; - GSList * iter; + NMConnection *conn; + GSList *iter; for (iter = priv->connections; iter; iter = iter->next) { conn = iter->data; @@ -346,10 +346,10 @@ nmt_edit_connection_list_finalize(GObject *object) } static void -nmt_edit_connection_list_set_property(GObject * object, +nmt_edit_connection_list_set_property(GObject *object, guint prop_id, const GValue *value, - GParamSpec * pspec) + GParamSpec *pspec) { NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(object); @@ -375,14 +375,14 @@ nmt_edit_connection_list_set_property(GObject * object, } static void -nmt_edit_connection_list_get_property(GObject * object, +nmt_edit_connection_list_get_property(GObject *object, guint prop_id, - GValue * value, + GValue *value, GParamSpec *pspec) { NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(object); - GPtrArray * connections; - GSList * iter; + GPtrArray *connections; + GSList *iter; switch (prop_id) { case PROP_GROUPED: diff --git a/src/nmtui/nmt-edit-connection-list.h b/src/nmtui/nmt-edit-connection-list.h index 824f767a..a5375be4 100644 --- a/src/nmtui/nmt-edit-connection-list.h +++ b/src/nmtui/nmt-edit-connection-list.h @@ -37,7 +37,7 @@ typedef struct { GType nmt_edit_connection_list_get_type(void); typedef gboolean (*NmtEditConnectionListFilter)(NmtEditConnectionList *list, - NMConnection * connection, + NMConnection *connection, gpointer user_data); void nmt_edit_connection_list_recommit(NmtEditConnectionList *list); diff --git a/src/nmtui/nmt-editor-grid.c b/src/nmtui/nmt-editor-grid.c index 8c79e8d9..bb257805 100644 --- a/src/nmtui/nmt-editor-grid.c +++ b/src/nmtui/nmt-editor-grid.c @@ -35,14 +35,14 @@ G_DEFINE_TYPE(NmtEditorGrid, nmt_editor_grid, NMT_TYPE_NEWT_CONTAINER) typedef struct { GArray *rows; - int * row_heights; + int *row_heights; int indent; } NmtEditorGridPrivate; typedef struct { - NmtNewtWidget * label; - NmtNewtWidget * widget; - NmtNewtWidget * extra; + NmtNewtWidget *label; + NmtNewtWidget *widget; + NmtNewtWidget *extra; NmtEditorGridRowFlags flags; } NmtEditorGridRow; @@ -102,13 +102,13 @@ nmt_editor_grid_finalize(GObject *object) */ void nmt_editor_grid_append(NmtEditorGrid *grid, - const char * label, + const char *label, NmtNewtWidget *widget, NmtNewtWidget *extra) { - NmtEditorGridPrivate * priv = NMT_EDITOR_GRID_GET_PRIVATE(grid); + NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE(grid); NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS(nmt_editor_grid_parent_class); - NmtNewtContainer * container = NMT_NEWT_CONTAINER(grid); + NmtNewtContainer *container = NMT_NEWT_CONTAINER(grid); NmtEditorGridRow row; g_return_if_fail(label != NULL || widget != NULL); @@ -147,7 +147,7 @@ static int nmt_editor_grid_find_widget(NmtEditorGrid *grid, NmtNewtWidget *widget) { NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE(grid); - NmtEditorGridRow * rows = (NmtEditorGridRow *) priv->rows->data; + NmtEditorGridRow *rows = (NmtEditorGridRow *) priv->rows->data; int i; for (i = 0; i < priv->rows->len; i++) { @@ -177,12 +177,12 @@ nmt_editor_grid_find_widget(NmtEditorGrid *grid, NmtNewtWidget *widget) * Sets flags to adjust the layout of @widget's row in @grid. */ void -nmt_editor_grid_set_row_flags(NmtEditorGrid * grid, - NmtNewtWidget * widget, +nmt_editor_grid_set_row_flags(NmtEditorGrid *grid, + NmtNewtWidget *widget, NmtEditorGridRowFlags flags) { NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE(grid); - NmtEditorGridRow * rows = (NmtEditorGridRow *) priv->rows->data; + NmtEditorGridRow *rows = (NmtEditorGridRow *) priv->rows->data; int i; i = nmt_editor_grid_find_widget(grid, widget); @@ -193,10 +193,10 @@ nmt_editor_grid_set_row_flags(NmtEditorGrid * grid, static void nmt_editor_grid_remove(NmtNewtContainer *container, NmtNewtWidget *widget) { - NmtEditorGrid * grid = NMT_EDITOR_GRID(container); - NmtEditorGridPrivate * priv = NMT_EDITOR_GRID_GET_PRIVATE(grid); + NmtEditorGrid *grid = NMT_EDITOR_GRID(container); + NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE(grid); NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS(nmt_editor_grid_parent_class); - NmtEditorGridRow * rows = (NmtEditorGridRow *) priv->rows->data; + NmtEditorGridRow *rows = (NmtEditorGridRow *) priv->rows->data; int i; i = nmt_editor_grid_find_widget(grid, widget); @@ -219,9 +219,9 @@ static newtComponent * nmt_editor_grid_get_components(NmtNewtWidget *widget) { NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE(widget); - NmtEditorGridRow * rows = (NmtEditorGridRow *) priv->rows->data; - newtComponent * child_cos; - GPtrArray * cos; + NmtEditorGridRow *rows = (NmtEditorGridRow *) priv->rows->data; + newtComponent *child_cos; + GPtrArray *cos; int i, c; cos = g_ptr_array_new(); @@ -257,7 +257,7 @@ nmt_editor_grid_get_components(NmtNewtWidget *widget) static NmtEditorGridFormState * get_form_state(NmtNewtWidget *widget) { - NmtNewtForm * form = nmt_newt_widget_get_form(widget); + NmtNewtForm *form = nmt_newt_widget_get_form(widget); NmtEditorGridFormState *state; if (!form) @@ -276,7 +276,7 @@ static void nmt_editor_grid_realize(NmtNewtWidget *widget) { NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE(widget); - NmtNewtWidget * parent; + NmtNewtWidget *parent; NMT_NEWT_WIDGET_CLASS(nmt_editor_grid_parent_class)->realize(widget); @@ -307,8 +307,8 @@ nmt_editor_grid_unrealize(NmtNewtWidget *widget) static void nmt_editor_grid_size_request(NmtNewtWidget *widget, int *width, int *height) { - NmtEditorGridPrivate * priv = NMT_EDITOR_GRID_GET_PRIVATE(widget); - NmtEditorGridRow * rows = (NmtEditorGridRow *) priv->rows->data; + NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE(widget); + NmtEditorGridRow *rows = (NmtEditorGridRow *) priv->rows->data; NmtEditorGridFormState *state = get_form_state(widget); gboolean add_padding = FALSE; int i; @@ -355,8 +355,8 @@ nmt_editor_grid_size_request(NmtNewtWidget *widget, int *width, int *height) static void nmt_editor_grid_size_allocate(NmtNewtWidget *widget, int x, int y, int width, int height) { - NmtEditorGridPrivate * priv = NMT_EDITOR_GRID_GET_PRIVATE(widget); - NmtEditorGridRow * rows = (NmtEditorGridRow *) priv->rows->data; + NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE(widget); + NmtEditorGridRow *rows = (NmtEditorGridRow *) priv->rows->data; NmtEditorGridFormState *state = get_form_state(widget); int col0_width, col1_width, col2_width; int i, row; @@ -422,8 +422,8 @@ nmt_editor_grid_size_allocate(NmtNewtWidget *widget, int x, int y, int width, in static void nmt_editor_grid_class_init(NmtEditorGridClass *grid_class) { - GObjectClass * object_class = G_OBJECT_CLASS(grid_class); - NmtNewtWidgetClass * widget_class = NMT_NEWT_WIDGET_CLASS(grid_class); + GObjectClass *object_class = G_OBJECT_CLASS(grid_class); + NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS(grid_class); NmtNewtContainerClass *container_class = NMT_NEWT_CONTAINER_CLASS(grid_class); g_type_class_add_private(grid_class, sizeof(NmtEditorGridPrivate)); diff --git a/src/nmtui/nmt-editor-grid.h b/src/nmtui/nmt-editor-grid.h index 39a86067..3a917536 100644 --- a/src/nmtui/nmt-editor-grid.h +++ b/src/nmtui/nmt-editor-grid.h @@ -38,11 +38,11 @@ typedef enum { NmtNewtWidget *nmt_editor_grid_new(void); void nmt_editor_grid_append(NmtEditorGrid *grid, - const char * label, + const char *label, NmtNewtWidget *widget, NmtNewtWidget *extra); -void nmt_editor_grid_set_row_flags(NmtEditorGrid * grid, - NmtNewtWidget * widget, +void nmt_editor_grid_set_row_flags(NmtEditorGrid *grid, + NmtNewtWidget *widget, NmtEditorGridRowFlags flags); #endif /* NMT_EDITOR_GRID_H */ diff --git a/src/nmtui/nmt-editor-page-device.c b/src/nmtui/nmt-editor-page-device.c index 950f4db1..57503f47 100644 --- a/src/nmtui/nmt-editor-page-device.c +++ b/src/nmtui/nmt-editor-page-device.c @@ -60,10 +60,10 @@ nmt_editor_page_device_get_device_entry(NmtEditorPageDevice *page) } static void -nmt_editor_page_device_set_property(GObject * object, +nmt_editor_page_device_set_property(GObject *object, guint prop_id, const GValue *value, - GParamSpec * pspec) + GParamSpec *pspec) { NmtEditorPageDevicePrivate *priv = NMT_EDITOR_PAGE_DEVICE_GET_PRIVATE(object); @@ -78,9 +78,9 @@ nmt_editor_page_device_set_property(GObject * object, } static void -nmt_editor_page_device_get_property(GObject * object, +nmt_editor_page_device_get_property(GObject *object, guint prop_id, - GValue * value, + GValue *value, GParamSpec *pspec) { NmtEditorPageDevicePrivate *priv = NMT_EDITOR_PAGE_DEVICE_GET_PRIVATE(object); diff --git a/src/nmtui/nmt-editor-page.c b/src/nmtui/nmt-editor-page.c index 6d90d71e..d94b1f0f 100644 --- a/src/nmtui/nmt-editor-page.c +++ b/src/nmtui/nmt-editor-page.c @@ -22,7 +22,7 @@ G_DEFINE_ABSTRACT_TYPE(NmtEditorPage, nmt_editor_page, G_TYPE_OBJECT) typedef struct { NMConnection *connection; - GSList * sections; + GSList *sections; } NmtEditorPagePrivate; diff --git a/src/nmtui/nmt-editor-section.c b/src/nmtui/nmt-editor-section.c index 3fbfe7a3..462d1f89 100644 --- a/src/nmtui/nmt-editor-section.c +++ b/src/nmtui/nmt-editor-section.c @@ -22,7 +22,7 @@ G_DEFINE_TYPE(NmtEditorSection, nmt_editor_section, NMT_TYPE_NEWT_SECTION) typedef struct { NmtEditorGrid *header, *body; - char * title; + char *title; NmtNewtWidget *header_widget; NmtNewtWidget *toggle; @@ -156,12 +156,12 @@ nmt_editor_section_get_title(NmtEditorSection *section) } static void -nmt_editor_section_set_property(GObject * object, +nmt_editor_section_set_property(GObject *object, guint prop_id, const GValue *value, - GParamSpec * pspec) + GParamSpec *pspec) { - NmtEditorSection * section = NMT_EDITOR_SECTION(object); + NmtEditorSection *section = NMT_EDITOR_SECTION(object); NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE(section); switch (prop_id) { diff --git a/src/nmtui/nmt-editor-section.h b/src/nmtui/nmt-editor-section.h index b7baf821..43e6852b 100644 --- a/src/nmtui/nmt-editor-section.h +++ b/src/nmtui/nmt-editor-section.h @@ -35,7 +35,7 @@ GType nmt_editor_section_get_type(void); NmtEditorSection * nmt_editor_section_new(const char *title, NmtNewtWidget *header_widget, gboolean show_by_default); -const char * nmt_editor_section_get_title(NmtEditorSection *section); +const char *nmt_editor_section_get_title(NmtEditorSection *section); NmtNewtWidget *nmt_editor_section_get_header_widget(NmtEditorSection *section); NmtEditorGrid *nmt_editor_section_get_body(NmtEditorSection *section); diff --git a/src/nmtui/nmt-editor.c b/src/nmtui/nmt-editor.c index 94e9b7a8..8e6a760c 100644 --- a/src/nmtui/nmt-editor.c +++ b/src/nmtui/nmt-editor.c @@ -55,7 +55,7 @@ typedef struct { NMEditorConnectionTypeData *type_data; - GSList * pages; + GSList *pages; NmtNewtWidget *ok, *cancel; gboolean running; } NmtEditorPrivate; @@ -128,7 +128,7 @@ static void connection_added(GObject *client, GAsyncResult *result, gpointer op) { NMRemoteConnection *connection; - GError * error = NULL; + GError *error = NULL; connection = nm_client_add_connection_finish(NM_CLIENT(client), result, &error); nmt_sync_op_complete_boolean(op, error == NULL, error); @@ -147,10 +147,10 @@ page_saved(gpointer data, gpointer user_data) static void save_connection_and_exit(NmtNewtButton *button, gpointer user_data) { - NmtEditor * editor = user_data; + NmtEditor *editor = user_data; NmtEditorPrivate *priv = NMT_EDITOR_GET_PRIVATE(editor); NmtSyncOp op; - GError * error = NULL; + GError *error = NULL; nm_connection_replace_settings_from_connection(priv->orig_connection, priv->edit_connection); @@ -195,7 +195,7 @@ static void got_secrets(GObject *object, GAsyncResult *result, gpointer op) { GVariant *secrets; - GError * error = NULL; + GError *error = NULL; secrets = nm_remote_connection_get_secrets_finish(NM_REMOTE_CONNECTION(object), result, &error); if (secrets) @@ -208,9 +208,9 @@ static NMConnection * build_edit_connection(NMConnection *orig_connection) { NMConnection *edit_connection; - GVariant * settings, *secrets; + GVariant *settings, *secrets; GVariantIter iter; - const char * setting_name; + const char *setting_name; NmtSyncOp op; edit_connection = nm_simple_connection_new_clone(orig_connection); @@ -243,9 +243,9 @@ build_edit_connection(NMConnection *orig_connection) } static gboolean -permissions_transform_to_allusers(GBinding * binding, +permissions_transform_to_allusers(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { char **perms = g_value_get_boxed(source_value); @@ -255,13 +255,13 @@ permissions_transform_to_allusers(GBinding * binding, } static gboolean -permissions_transform_from_allusers(GBinding * binding, +permissions_transform_from_allusers(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { gboolean allusers = g_value_get_boolean(source_value); - char ** perms = NULL; + char **perms = NULL; if (!allusers) { perms = g_new(char *, 2); @@ -277,8 +277,8 @@ static NmtNewtWidget * add_sections_for_page(NmtEditor *editor, NmtEditorGrid *grid, NmtEditorPage *page) { NmtEditorPrivate *priv = NMT_EDITOR_GET_PRIVATE(editor); - NmtNewtWidget * first_section = NULL; - const GSList * sections, *iter; + NmtNewtWidget *first_section = NULL; + const GSList *sections, *iter; g_return_val_if_fail(NMT_IS_EDITOR_PAGE(page), NULL); @@ -297,16 +297,16 @@ add_sections_for_page(NmtEditor *editor, NmtEditorGrid *grid, NmtEditorPage *pag static void nmt_editor_constructed(GObject *object) { - NmtEditor * editor = NMT_EDITOR(object); - NmtEditorPrivate * priv = NMT_EDITOR_GET_PRIVATE(editor); + NmtEditor *editor = NMT_EDITOR(object); + NmtEditorPrivate *priv = NMT_EDITOR_GET_PRIVATE(editor); NMSettingConnection *s_con; - NmtNewtWidget * vbox, *widget, *buttons; - NmtEditorGrid * grid; - const char * deventry_label; - NmtDeviceEntry * deventry; + NmtNewtWidget *vbox, *widget, *buttons; + NmtEditorGrid *grid; + const char *deventry_label; + NmtDeviceEntry *deventry; GType hardware_type; - const char * slave_type; - NmtEditorPage * page; + const char *slave_type; + NmtEditorPage *page; if (G_OBJECT_CLASS(nmt_editor_parent_class)->constructed) G_OBJECT_CLASS(nmt_editor_parent_class)->constructed(object); diff --git a/src/nmtui/nmt-ip-entry.c b/src/nmtui/nmt-ip-entry.c index b801eec4..9bd0f12d 100644 --- a/src/nmtui/nmt-ip-entry.c +++ b/src/nmtui/nmt-ip-entry.c @@ -76,7 +76,7 @@ static gboolean ip_entry_filter(NmtNewtEntry *entry, const char *text, int ch, int position, gpointer user_data) { NmtIPEntryPrivate *priv = NMT_IP_ENTRY_GET_PRIVATE(entry); - const char * slash; + const char *slash; gboolean inaddr; if (g_ascii_isdigit(ch)) diff --git a/src/nmtui/nmt-mac-entry.c b/src/nmtui/nmt-mac-entry.c index 3f71f4c9..11ceecf9 100644 --- a/src/nmtui/nmt-mac-entry.c +++ b/src/nmtui/nmt-mac-entry.c @@ -85,7 +85,7 @@ static gboolean mac_validator(NmtNewtEntry *entry, const char *text, gpointer user_data) { NmtMacEntryPrivate *priv = NMT_MAC_ENTRY_GET_PRIVATE(entry); - const char * p; + const char *p; if (!*text) return TRUE; diff --git a/src/nmtui/nmt-mtu-entry.c b/src/nmtui/nmt-mtu-entry.c index eab25a23..664ee88f 100644 --- a/src/nmtui/nmt-mtu-entry.c +++ b/src/nmtui/nmt-mtu-entry.c @@ -75,9 +75,9 @@ mtu_validator(NmtNewtEntry *entry, const char *text, gpointer user_data) } static gboolean -mtu_transform_to_text(GBinding * binding, +mtu_transform_to_text(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { int mtu = g_value_get_int(source_value); @@ -93,8 +93,8 @@ static void nmt_mtu_entry_init(NmtMtuEntry *entry) { NmtMtuEntryPrivate *priv = NMT_MTU_ENTRY_GET_PRIVATE(entry); - NmtNewtGrid * grid = NMT_NEWT_GRID(entry); - NmtNewtWidget * real_entry, *label; + NmtNewtGrid *grid = NMT_NEWT_GRID(entry); + NmtNewtWidget *real_entry, *label; real_entry = nmt_newt_entry_numeric_new(10, 0, 65535); priv->entry = NMT_NEWT_ENTRY(real_entry); diff --git a/src/nmtui/nmt-page-bond-port.c b/src/nmtui/nmt-page-bond-port.c index 156553c2..bed8a0f6 100644 --- a/src/nmtui/nmt-page-bond-port.c +++ b/src/nmtui/nmt-page-bond-port.c @@ -29,12 +29,12 @@ nmt_page_bond_port_new(NMConnection *conn) static void nmt_page_bond_port_constructed(GObject *object) { - NmtPageBondPort * bond = NMT_PAGE_BOND_PORT(object); - NmtEditorSection * section; - NmtEditorGrid * grid; + NmtPageBondPort *bond = NMT_PAGE_BOND_PORT(object); + NmtEditorSection *section; + NmtEditorGrid *grid; NMSettingBondPort *s_port; - NmtNewtWidget * widget; - NMConnection * conn; + NmtNewtWidget *widget; + NMConnection *conn; conn = nmt_editor_page_get_connection(NMT_EDITOR_PAGE(bond)); s_port = _nm_connection_ensure_setting(conn, NM_TYPE_SETTING_BOND_PORT); diff --git a/src/nmtui/nmt-page-bond.c b/src/nmtui/nmt-page-bond.c index aea7949e..edcf681e 100644 --- a/src/nmtui/nmt-page-bond.c +++ b/src/nmtui/nmt-page-bond.c @@ -41,13 +41,13 @@ typedef struct { /* Note: when adding new options to the UI also ensure they are * initialized in bond_connection_setup_func() */ - NmtNewtPopup * mode; - NmtNewtEntry * primary; - NmtNewtPopup * monitoring; - NmtNewtEntry * miimon; - NmtNewtEntry * updelay; - NmtNewtEntry * downdelay; - NmtNewtEntry * arp_interval; + NmtNewtPopup *mode; + NmtNewtEntry *primary; + NmtNewtPopup *monitoring; + NmtNewtEntry *miimon; + NmtNewtEntry *updelay; + NmtNewtEntry *downdelay; + NmtNewtEntry *arp_interval; NmtAddressList *arp_ip_target; NmtPageBondMonitoringMode monitoring_mode; @@ -96,11 +96,11 @@ static NmtNewtPopupEntry bond_monitoring[] = {{N_("MII (recommended)"), "mii"}, static void bond_options_changed(GObject *object, GParamSpec *pspec, gpointer user_data) { - NMSettingBond * s_bond = NM_SETTING_BOND(object); - NmtPageBond * bond = NMT_PAGE_BOND(user_data); - NmtPageBondPrivate * priv = NMT_PAGE_BOND_GET_PRIVATE(bond); + NMSettingBond *s_bond = NM_SETTING_BOND(object); + NmtPageBond *bond = NMT_PAGE_BOND(user_data); + NmtPageBondPrivate *priv = NMT_PAGE_BOND_GET_PRIVATE(bond); gs_free const char **ips = NULL; - const char * val; + const char *val; gboolean visible_mii; NMBondMode mode; @@ -161,9 +161,9 @@ bond_options_changed(GObject *object, GParamSpec *pspec, gpointer user_data) static void slaves_changed(GObject *object, GParamSpec *pspec, gpointer user_data) { - NmtPageBond * bond = NMT_PAGE_BOND(user_data); + NmtPageBond *bond = NMT_PAGE_BOND(user_data); NmtPageBondPrivate *priv = NMT_PAGE_BOND_GET_PRIVATE(bond); - GPtrArray * slaves; + GPtrArray *slaves; g_object_get(object, "connections", &slaves, NULL); if (slaves->len == 0) { @@ -207,9 +207,9 @@ _bond_add_option(NMSettingBond *s_bond, const char *option, const char *value) #define WIDGET_CHANGED_FUNC(widget, func, option, dflt) \ static void widget##_widget_changed(GObject *object, GParamSpec *pspec, gpointer user_data) \ { \ - NmtPageBond * bond = NMT_PAGE_BOND(user_data); \ + NmtPageBond *bond = NMT_PAGE_BOND(user_data); \ NmtPageBondPrivate *priv = NMT_PAGE_BOND_GET_PRIVATE(bond); \ - const char * v; \ + const char *v; \ \ if (priv->updating) \ return; \ @@ -229,9 +229,9 @@ WIDGET_CHANGED_FUNC(arp_interval, nmt_newt_entry_get_text, NM_SETTING_BOND_OPTIO static void mode_widget_changed(GObject *object, GParamSpec *pspec, gpointer user_data) { - NmtPageBond * bond = NMT_PAGE_BOND(user_data); + NmtPageBond *bond = NMT_PAGE_BOND(user_data); NmtPageBondPrivate *priv = NMT_PAGE_BOND_GET_PRIVATE(bond); - const char * mode; + const char *mode; if (priv->updating) return; @@ -261,7 +261,7 @@ mode_widget_changed(GObject *object, GParamSpec *pspec, gpointer user_data) static void monitoring_widget_changed(GObject *object, GParamSpec *pspec, gpointer user_data) { - NmtPageBond * bond = NMT_PAGE_BOND(user_data); + NmtPageBond *bond = NMT_PAGE_BOND(user_data); NmtPageBondPrivate *priv = NMT_PAGE_BOND_GET_PRIVATE(bond); gboolean visible_mii; @@ -290,9 +290,9 @@ monitoring_widget_changed(GObject *object, GParamSpec *pspec, gpointer user_data static void arp_ip_target_widget_changed(GObject *object, GParamSpec *pspec, gpointer user_data) { - NmtPageBond * bond = NMT_PAGE_BOND(user_data); + NmtPageBond *bond = NMT_PAGE_BOND(user_data); NmtPageBondPrivate *priv = NMT_PAGE_BOND_GET_PRIVATE(bond); - char ** ips, *target; + char **ips, *target; if (priv->updating) return; @@ -311,7 +311,7 @@ arp_ip_target_widget_changed(GObject *object, GParamSpec *pspec, gpointer user_d static gboolean bond_connection_type_filter(GType connection_type, gpointer user_data) { - NmtPageBond * bond = user_data; + NmtPageBond *bond = user_data; NmtPageBondPrivate *priv = NMT_PAGE_BOND_GET_PRIVATE(bond); if (priv->slave_type != NM_TYPE_SETTING_WIRED && connection_type == NM_TYPE_SETTING_INFINIBAND) @@ -325,14 +325,14 @@ bond_connection_type_filter(GType connection_type, gpointer user_data) static void nmt_page_bond_constructed(GObject *object) { - NmtPageBond * bond = NMT_PAGE_BOND(object); + NmtPageBond *bond = NMT_PAGE_BOND(object); NmtPageBondPrivate *priv = NMT_PAGE_BOND_GET_PRIVATE(bond); - NmtEditorSection * section; - NmtEditorGrid * grid; - NMSettingWired * s_wired; - NMSettingBond * s_bond; - NmtNewtWidget * widget, *label; - NMConnection * conn; + NmtEditorSection *section; + NmtEditorGrid *grid; + NMSettingWired *s_wired; + NMSettingBond *s_bond; + NmtNewtWidget *widget, *label; + NMConnection *conn; conn = nmt_editor_page_get_connection(NMT_EDITOR_PAGE(bond)); s_bond = _nm_connection_ensure_setting(conn, NM_TYPE_SETTING_BOND); @@ -426,7 +426,7 @@ nmt_page_bond_saved(NmtEditorPage *editor_page) static void nmt_page_bond_class_init(NmtPageBondClass *bond_class) { - GObjectClass * object_class = G_OBJECT_CLASS(bond_class); + GObjectClass *object_class = G_OBJECT_CLASS(bond_class); NmtEditorPageClass *editor_page_class = NMT_EDITOR_PAGE_CLASS(bond_class); g_type_class_add_private(bond_class, sizeof(NmtPageBondPrivate)); diff --git a/src/nmtui/nmt-page-bridge-port.c b/src/nmtui/nmt-page-bridge-port.c index f6c18d7c..e39d15e2 100644 --- a/src/nmtui/nmt-page-bridge-port.c +++ b/src/nmtui/nmt-page-bridge-port.c @@ -29,12 +29,12 @@ nmt_page_bridge_port_init(NmtPageBridgePort *bridge) static void nmt_page_bridge_port_constructed(GObject *object) { - NmtPageBridgePort * bridge = NMT_PAGE_BRIDGE_PORT(object); - NmtEditorSection * section; - NmtEditorGrid * grid; + NmtPageBridgePort *bridge = NMT_PAGE_BRIDGE_PORT(object); + NmtEditorSection *section; + NmtEditorGrid *grid; NMSettingBridgePort *s_port; - NmtNewtWidget * widget; - NMConnection * conn; + NmtNewtWidget *widget; + NMConnection *conn; conn = nmt_editor_page_get_connection(NMT_EDITOR_PAGE(bridge)); s_port = _nm_connection_ensure_setting(conn, NM_TYPE_SETTING_BRIDGE_PORT); diff --git a/src/nmtui/nmt-page-bridge.c b/src/nmtui/nmt-page-bridge.c index 684b17bd..bc32e2a2 100644 --- a/src/nmtui/nmt-page-bridge.c +++ b/src/nmtui/nmt-page-bridge.c @@ -45,13 +45,13 @@ bridge_connection_type_filter(GType connection_type, gpointer user_data) static void nmt_page_bridge_constructed(GObject *object) { - NmtPageBridge * bridge = NMT_PAGE_BRIDGE(object); + NmtPageBridge *bridge = NMT_PAGE_BRIDGE(object); NmtPageBridgePrivate *priv = NMT_PAGE_BRIDGE_GET_PRIVATE(bridge); - NmtEditorSection * section; - NmtEditorGrid * grid; - NMSettingBridge * s_bridge; - NmtNewtWidget * widget, *label, *stp; - NMConnection * conn; + NmtEditorSection *section; + NmtEditorGrid *grid; + NMSettingBridge *s_bridge; + NmtNewtWidget *widget, *label, *stp; + NMConnection *conn; conn = nmt_editor_page_get_connection(NMT_EDITOR_PAGE(bridge)); s_bridge = _nm_connection_ensure_setting(conn, NM_TYPE_SETTING_BRIDGE); @@ -171,7 +171,7 @@ nmt_page_bridge_saved(NmtEditorPage *editor_page) static void nmt_page_bridge_class_init(NmtPageBridgeClass *bridge_class) { - GObjectClass * object_class = G_OBJECT_CLASS(bridge_class); + GObjectClass *object_class = G_OBJECT_CLASS(bridge_class); NmtEditorPageClass *editor_page_class = NMT_EDITOR_PAGE_CLASS(bridge_class); object_class->constructed = nmt_page_bridge_constructed; diff --git a/src/nmtui/nmt-page-dsl.c b/src/nmtui/nmt-page-dsl.c index a0d8cdf4..5fa756cc 100644 --- a/src/nmtui/nmt-page-dsl.c +++ b/src/nmtui/nmt-page-dsl.c @@ -41,8 +41,8 @@ static NmtEditorSection * build_dsl_section(NmtPageDsl *dsl, NMSettingPppoe *s_pppoe) { NmtEditorSection *section; - NmtEditorGrid * grid; - NmtNewtWidget * widget; + NmtEditorGrid *grid; + NmtNewtWidget *widget; section = nmt_editor_section_new(_("DSL"), NULL, TRUE); grid = nmt_editor_section_get_body(section); @@ -77,12 +77,12 @@ build_dsl_section(NmtPageDsl *dsl, NMSettingPppoe *s_pppoe) static void nmt_page_dsl_constructed(GObject *object) { - NmtPageDsl * dsl = NMT_PAGE_DSL(object); + NmtPageDsl *dsl = NMT_PAGE_DSL(object); NmtPageDslPrivate *priv = NMT_PAGE_DSL_GET_PRIVATE(dsl); - NMConnection * conn; - NMSettingPppoe * s_pppoe; - NmtEditorSection * section; - const GSList * sections, *iter; + NMConnection *conn; + NMSettingPppoe *s_pppoe; + NmtEditorSection *section; + const GSList *sections, *iter; conn = nmt_editor_page_get_connection(NMT_EDITOR_PAGE(dsl)); s_pppoe = _nm_connection_ensure_setting(conn, NM_TYPE_SETTING_PPPOE); @@ -108,7 +108,7 @@ nmt_page_dsl_constructed(GObject *object) static void nmt_page_dsl_finalize(GObject *object) { - NmtPageDsl * dsl = NMT_PAGE_DSL(object); + NmtPageDsl *dsl = NMT_PAGE_DSL(object); NmtPageDslPrivate *priv = NMT_PAGE_DSL_GET_PRIVATE(dsl); g_clear_object(&priv->ethernet_page); diff --git a/src/nmtui/nmt-page-ethernet.c b/src/nmtui/nmt-page-ethernet.c index addbd3f3..89026d0f 100644 --- a/src/nmtui/nmt-page-ethernet.c +++ b/src/nmtui/nmt-page-ethernet.c @@ -34,13 +34,13 @@ nmt_page_ethernet_init(NmtPageEthernet *ethernet) static void nmt_page_ethernet_constructed(GObject *object) { - NmtPageEthernet * ethernet = NMT_PAGE_ETHERNET(object); - NmtDeviceEntry * deventry; + NmtPageEthernet *ethernet = NMT_PAGE_ETHERNET(object); + NmtDeviceEntry *deventry; NmtEditorSection *section; - NmtEditorGrid * grid; - NMSettingWired * s_wired; - NmtNewtWidget * widget; - NMConnection * conn; + NmtEditorGrid *grid; + NMSettingWired *s_wired; + NmtNewtWidget *widget; + NMConnection *conn; conn = nmt_editor_page_get_connection(NMT_EDITOR_PAGE(ethernet)); s_wired = _nm_connection_ensure_setting(conn, NM_TYPE_SETTING_WIRED); diff --git a/src/nmtui/nmt-page-infiniband.c b/src/nmtui/nmt-page-infiniband.c index 1216208f..b292c751 100644 --- a/src/nmtui/nmt-page-infiniband.c +++ b/src/nmtui/nmt-page-infiniband.c @@ -39,13 +39,13 @@ static NmtNewtPopupEntry transport_mode[] = {{N_("Datagram"), "datagram"}, static void nmt_page_infiniband_constructed(GObject *object) { - NmtPageInfiniband * infiniband = NMT_PAGE_INFINIBAND(object); - NmtDeviceEntry * deventry; - NmtEditorSection * section; - NmtEditorGrid * grid; + NmtPageInfiniband *infiniband = NMT_PAGE_INFINIBAND(object); + NmtDeviceEntry *deventry; + NmtEditorSection *section; + NmtEditorGrid *grid; NMSettingInfiniband *s_ib; - NmtNewtWidget * widget; - NMConnection * conn; + NmtNewtWidget *widget; + NMConnection *conn; conn = nmt_editor_page_get_connection(NMT_EDITOR_PAGE(infiniband)); s_ib = _nm_connection_ensure_setting(conn, NM_TYPE_SETTING_INFINIBAND); diff --git a/src/nmtui/nmt-page-ip-tunnel.c b/src/nmtui/nmt-page-ip-tunnel.c index 96864919..c74037b6 100644 --- a/src/nmtui/nmt-page-ip-tunnel.c +++ b/src/nmtui/nmt-page-ip-tunnel.c @@ -43,8 +43,8 @@ nmt_page_ip_tunnel_init(NmtPageIPTunnel *ip_tunnel) static void mode_changed(GObject *object, GParamSpec *pspec, gpointer user_data) { - NMSettingIPTunnel * s_ip_tunnel = NM_SETTING_IP_TUNNEL(object); - NmtPageIPTunnel * ip_tunnel = NMT_PAGE_IP_TUNNEL(user_data); + NMSettingIPTunnel *s_ip_tunnel = NM_SETTING_IP_TUNNEL(object); + NmtPageIPTunnel *ip_tunnel = NMT_PAGE_IP_TUNNEL(user_data); NmtPageIPTunnelPrivate *priv = NMT_PAGE_IP_TUNNEL_GET_PRIVATE(ip_tunnel); NMIPTunnelMode mode; gboolean enable_keys; @@ -93,14 +93,14 @@ add_offset(GBinding *binding, const GValue *from_value, GValue *to_value, gpoint static void nmt_page_ip_tunnel_constructed(GObject *object) { - NmtPageIPTunnel * ip_tunnel = NMT_PAGE_IP_TUNNEL(object); + NmtPageIPTunnel *ip_tunnel = NMT_PAGE_IP_TUNNEL(object); NmtPageIPTunnelPrivate *priv = NMT_PAGE_IP_TUNNEL_GET_PRIVATE(ip_tunnel); - NmtEditorSection * section; - NmtEditorGrid * grid; - NMSettingIPTunnel * s_ip_tunnel; - NmtNewtWidget * widget, *parent; - NMConnection * conn; - GClosure * s2w, *w2s; + NmtEditorSection *section; + NmtEditorGrid *grid; + NMSettingIPTunnel *s_ip_tunnel; + NmtNewtWidget *widget, *parent; + NMConnection *conn; + GClosure *s2w, *w2s; conn = nmt_editor_page_get_connection(NMT_EDITOR_PAGE(ip_tunnel)); s_ip_tunnel = _nm_connection_ensure_setting(conn, NM_TYPE_SETTING_IP_TUNNEL); diff --git a/src/nmtui/nmt-page-ip4.c b/src/nmtui/nmt-page-ip4.c index a7e4bdae..4d01b356 100644 --- a/src/nmtui/nmt-page-ip4.c +++ b/src/nmtui/nmt-page-ip4.c @@ -44,7 +44,7 @@ nmt_page_ip4_init(NmtPageIP4 *ip4) static void edit_routes(NmtNewtButton *button, gpointer user_data) { - NMSetting * s_ip4 = user_data; + NMSetting *s_ip4 = user_data; NmtNewtForm *form; form = nmt_route_editor_new(s_ip4); @@ -53,13 +53,13 @@ edit_routes(NmtNewtButton *button, gpointer user_data) } static gboolean -ip4_routes_transform_to_description(GBinding * binding, +ip4_routes_transform_to_description(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { GPtrArray *routes; - char * text; + char *text; routes = g_value_get_boxed(source_value); if (!routes || !routes->len) @@ -77,13 +77,13 @@ ip4_routes_transform_to_description(GBinding * binding, static void nmt_page_ip4_constructed(GObject *object) { - NmtPageIP4 * ip4 = NMT_PAGE_IP4(object); + NmtPageIP4 *ip4 = NMT_PAGE_IP4(object); gboolean show_by_default; - NmtEditorSection * section; - NmtEditorGrid * grid; + NmtEditorSection *section; + NmtEditorGrid *grid; NMSettingIPConfig *s_ip4; - NmtNewtWidget * widget, *button; - NMConnection * conn; + NmtNewtWidget *widget, *button; + NMConnection *conn; conn = nmt_editor_page_get_connection(NMT_EDITOR_PAGE(ip4)); s_ip4 = _nm_connection_ensure_setting(conn, NM_TYPE_SETTING_IP4_CONFIG); diff --git a/src/nmtui/nmt-page-ip6.c b/src/nmtui/nmt-page-ip6.c index 0d4de65a..7e7a48c5 100644 --- a/src/nmtui/nmt-page-ip6.c +++ b/src/nmtui/nmt-page-ip6.c @@ -45,7 +45,7 @@ nmt_page_ip6_init(NmtPageIP6 *ip6) static void edit_routes(NmtNewtButton *button, gpointer user_data) { - NMSetting * s_ip6 = user_data; + NMSetting *s_ip6 = user_data; NmtNewtForm *form; form = nmt_route_editor_new(s_ip6); @@ -54,13 +54,13 @@ edit_routes(NmtNewtButton *button, gpointer user_data) } static gboolean -ip6_routes_transform_to_description(GBinding * binding, +ip6_routes_transform_to_description(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { GPtrArray *routes; - char * text; + char *text; routes = g_value_get_boxed(source_value); if (!routes || !routes->len) @@ -78,13 +78,13 @@ ip6_routes_transform_to_description(GBinding * binding, static void nmt_page_ip6_constructed(GObject *object) { - NmtPageIP6 * ip6 = NMT_PAGE_IP6(object); + NmtPageIP6 *ip6 = NMT_PAGE_IP6(object); gboolean show_by_default; - NmtEditorSection * section; - NmtEditorGrid * grid; + NmtEditorSection *section; + NmtEditorGrid *grid; NMSettingIPConfig *s_ip6; - NmtNewtWidget * widget, *button; - NMConnection * conn; + NmtNewtWidget *widget, *button; + NMConnection *conn; conn = nmt_editor_page_get_connection(NMT_EDITOR_PAGE(ip6)); s_ip6 = _nm_connection_ensure_setting(conn, NM_TYPE_SETTING_IP6_CONFIG); diff --git a/src/nmtui/nmt-page-ppp.c b/src/nmtui/nmt-page-ppp.c index ffa1a8b2..6f844fd6 100644 --- a/src/nmtui/nmt-page-ppp.c +++ b/src/nmtui/nmt-page-ppp.c @@ -37,9 +37,9 @@ nmt_page_ppp_init(NmtPagePpp *ppp) {} static gboolean -transform_lcp_echo_properties_to_checkbox(GBinding * binding, +transform_lcp_echo_properties_to_checkbox(GBinding *binding, const GValue *from_value, - GValue * to_value, + GValue *to_value, gpointer user_data) { NMSettingPpp *s_ppp = NM_SETTING_PPP(g_binding_get_source(binding)); @@ -54,12 +54,12 @@ transform_lcp_echo_properties_to_checkbox(GBinding * binding, } static gboolean -transform_checkbox_to_lcp_echo_interval(GBinding * binding, +transform_checkbox_to_lcp_echo_interval(GBinding *binding, const GValue *from_value, - GValue * to_value, + GValue *to_value, gpointer user_data) { - NmtPagePpp * ppp = user_data; + NmtPagePpp *ppp = user_data; NmtPagePppPrivate *priv = NMT_PAGE_PPP_GET_PRIVATE(ppp); if (g_value_get_boolean(from_value)) @@ -71,12 +71,12 @@ transform_checkbox_to_lcp_echo_interval(GBinding * binding, } static gboolean -transform_checkbox_to_lcp_echo_failure(GBinding * binding, +transform_checkbox_to_lcp_echo_failure(GBinding *binding, const GValue *from_value, - GValue * to_value, + GValue *to_value, gpointer user_data) { - NmtPagePpp * ppp = user_data; + NmtPagePpp *ppp = user_data; NmtPagePppPrivate *priv = NMT_PAGE_PPP_GET_PRIVATE(ppp); if (g_value_get_boolean(from_value)) @@ -90,15 +90,15 @@ transform_checkbox_to_lcp_echo_failure(GBinding * binding, static void nmt_page_ppp_constructed(GObject *object) { - NmtPagePpp * ppp = NMT_PAGE_PPP(object); + NmtPagePpp *ppp = NMT_PAGE_PPP(object); NmtPagePppPrivate *priv = NMT_PAGE_PPP_GET_PRIVATE(ppp); - NmtEditorSection * section; - NmtEditorGrid * grid; - NMSettingPpp * s_ppp; - NmtNewtWidget * widget, *use_mppe; - NmtNewtGrid * auth_grid, *mppe_grid; - NmtNewtSection * auth_section, *mppe_section; - NMConnection * conn; + NmtEditorSection *section; + NmtEditorGrid *grid; + NMSettingPpp *s_ppp; + NmtNewtWidget *widget, *use_mppe; + NmtNewtGrid *auth_grid, *mppe_grid; + NmtNewtSection *auth_section, *mppe_section; + NMConnection *conn; conn = nmt_editor_page_get_connection(NMT_EDITOR_PAGE(ppp)); s_ppp = nm_connection_get_setting_ppp(conn); diff --git a/src/nmtui/nmt-page-team-port.c b/src/nmtui/nmt-page-team-port.c index c1f3cbc6..af401fa6 100644 --- a/src/nmtui/nmt-page-team-port.c +++ b/src/nmtui/nmt-page-team-port.c @@ -37,10 +37,10 @@ nmt_page_team_port_init(NmtPageTeamPort *team) static void edit_clicked(NmtNewtButton *button, gpointer user_data) { - NmtPageTeamPort * team = user_data; + NmtPageTeamPort *team = user_data; NmtPageTeamPortPrivate *priv = NMT_PAGE_TEAM_PORT_GET_PRIVATE(team); - const char * config; - char * new_config; + const char *config; + char *new_config; config = nm_setting_team_port_get_config(priv->s_port); if (!config) @@ -57,13 +57,13 @@ edit_clicked(NmtNewtButton *button, gpointer user_data) static void nmt_page_team_port_constructed(GObject *object) { - NmtPageTeamPort * team = NMT_PAGE_TEAM_PORT(object); + NmtPageTeamPort *team = NMT_PAGE_TEAM_PORT(object); NmtPageTeamPortPrivate *priv = NMT_PAGE_TEAM_PORT_GET_PRIVATE(team); - NmtEditorSection * section; - NmtNewtGrid * grid; - NMSettingTeamPort * s_port; - NmtNewtWidget * widget; - NMConnection * conn; + NmtEditorSection *section; + NmtNewtGrid *grid; + NMSettingTeamPort *s_port; + NmtNewtWidget *widget; + NMConnection *conn; conn = nmt_editor_page_get_connection(NMT_EDITOR_PAGE(team)); s_port = _nm_connection_ensure_setting(conn, NM_TYPE_SETTING_TEAM_PORT); diff --git a/src/nmtui/nmt-page-team.c b/src/nmtui/nmt-page-team.c index d61c06c5..1a554aad 100644 --- a/src/nmtui/nmt-page-team.c +++ b/src/nmtui/nmt-page-team.c @@ -45,9 +45,9 @@ nmt_page_team_init(NmtPageTeam *team) static void slaves_changed(GObject *object, GParamSpec *pspec, gpointer user_data) { - NmtPageTeam * team = NMT_PAGE_TEAM(user_data); + NmtPageTeam *team = NMT_PAGE_TEAM(user_data); NmtPageTeamPrivate *priv = NMT_PAGE_TEAM_GET_PRIVATE(team); - GPtrArray * slaves; + GPtrArray *slaves; g_object_get(object, "connections", &slaves, NULL); if (slaves->len == 0) { @@ -65,7 +65,7 @@ slaves_changed(GObject *object, GParamSpec *pspec, gpointer user_data) static gboolean team_connection_type_filter(GType connection_type, gpointer user_data) { - NmtPageTeam * team = user_data; + NmtPageTeam *team = user_data; NmtPageTeamPrivate *priv = NMT_PAGE_TEAM_GET_PRIVATE(team); if (priv->slave_type != NM_TYPE_SETTING_WIRED) { @@ -84,10 +84,10 @@ team_connection_type_filter(GType connection_type, gpointer user_data) static void edit_clicked(NmtNewtButton *button, gpointer user_data) { - NmtPageTeam * team = user_data; + NmtPageTeam *team = user_data; NmtPageTeamPrivate *priv = NMT_PAGE_TEAM_GET_PRIVATE(team); - const char * config; - char * new_config; + const char *config; + char *new_config; config = nm_setting_team_get_config(priv->s_team); if (!config) @@ -104,13 +104,13 @@ edit_clicked(NmtNewtButton *button, gpointer user_data) static void nmt_page_team_constructed(GObject *object) { - NmtPageTeam * team = NMT_PAGE_TEAM(object); + NmtPageTeam *team = NMT_PAGE_TEAM(object); NmtPageTeamPrivate *priv = NMT_PAGE_TEAM_GET_PRIVATE(team); - NmtEditorSection * section; - NmtNewtGrid * grid; - NMSettingTeam * s_team; - NmtNewtWidget * widget; - NMConnection * conn; + NmtEditorSection *section; + NmtNewtGrid *grid; + NMSettingTeam *s_team; + NmtNewtWidget *widget; + NMConnection *conn; conn = nmt_editor_page_get_connection(NMT_EDITOR_PAGE(team)); s_team = _nm_connection_ensure_setting(conn, NM_TYPE_SETTING_TEAM); @@ -162,7 +162,7 @@ nmt_page_team_saved(NmtEditorPage *editor_page) static void nmt_page_team_class_init(NmtPageTeamClass *team_class) { - GObjectClass * object_class = G_OBJECT_CLASS(team_class); + GObjectClass *object_class = G_OBJECT_CLASS(team_class); NmtEditorPageClass *editor_page_class = NMT_EDITOR_PAGE_CLASS(team_class); g_type_class_add_private(team_class, sizeof(NmtPageTeamPrivate)); diff --git a/src/nmtui/nmt-page-vlan.c b/src/nmtui/nmt-page-vlan.c index 5baf9756..1956d3d6 100644 --- a/src/nmtui/nmt-page-vlan.c +++ b/src/nmtui/nmt-page-vlan.c @@ -42,13 +42,13 @@ vlan_device_filter(NmtDeviceEntry *deventry, NMDevice *device, gpointer user_dat static void nmt_page_vlan_constructed(GObject *object) { - NmtPageVlan * vlan = NMT_PAGE_VLAN(object); + NmtPageVlan *vlan = NMT_PAGE_VLAN(object); NmtEditorSection *section; - NmtEditorGrid * grid; - NMSettingWired * s_wired; - NMSettingVlan * s_vlan; - NmtNewtWidget * widget, *parent, *id_entry; - NMConnection * conn; + NmtEditorGrid *grid; + NMSettingWired *s_wired; + NMSettingVlan *s_vlan; + NmtNewtWidget *widget, *parent, *id_entry; + NMConnection *conn; conn = nmt_editor_page_get_connection(NMT_EDITOR_PAGE(vlan)); s_vlan = _nm_connection_ensure_setting(conn, NM_TYPE_SETTING_VLAN); diff --git a/src/nmtui/nmt-page-wifi.c b/src/nmtui/nmt-page-wifi.c index 1a476b02..60960e64 100644 --- a/src/nmtui/nmt-page-wifi.c +++ b/src/nmtui/nmt-page-wifi.c @@ -80,9 +80,9 @@ static NmtNewtPopupEntry wep_auth[] = {{N_("Open System"), "open"}, {NULL, NULL}}; static gboolean -mode_transform_to_band_visibility(GBinding * binding, +mode_transform_to_band_visibility(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { if (!g_strcmp0(g_value_get_string(source_value), NM_SETTING_WIRELESS_MODE_INFRA)) @@ -93,9 +93,9 @@ mode_transform_to_band_visibility(GBinding * binding, } static gboolean -band_transform_to_channel_visibility(GBinding * binding, +band_transform_to_channel_visibility(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { g_value_set_boolean(target_value, g_value_get_string(source_value) != NULL); @@ -103,13 +103,13 @@ band_transform_to_channel_visibility(GBinding * binding, } static gboolean -ssid_transform_to_entry(GBinding * binding, +ssid_transform_to_entry(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { GBytes *ssid; - char * utf8; + char *utf8; ssid = g_value_get_boxed(source_value); if (ssid) @@ -121,15 +121,15 @@ ssid_transform_to_entry(GBinding * binding, } static gboolean -ssid_transform_from_entry(GBinding * binding, +ssid_transform_from_entry(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { NMSettingWireless *s_wireless = user_data; - const char * text; - GBytes * old_ssid, *ssid; - char * utf8; + const char *text; + GBytes *old_ssid, *ssid; + char *utf8; text = g_value_get_string(source_value); @@ -153,17 +153,17 @@ ssid_transform_from_entry(GBinding * binding, static void nmt_page_wifi_constructed(GObject *object) { - NmtPageWifiPrivate * priv = NMT_PAGE_WIFI_GET_PRIVATE(object); - NmtPageWifi * wifi = NMT_PAGE_WIFI(object); - NmtDeviceEntry * deventry; - NmtEditorSection * section; - NmtEditorGrid * grid; - NMSettingWireless * s_wireless; + NmtPageWifiPrivate *priv = NMT_PAGE_WIFI_GET_PRIVATE(object); + NmtPageWifi *wifi = NMT_PAGE_WIFI(object); + NmtDeviceEntry *deventry; + NmtEditorSection *section; + NmtEditorGrid *grid; + NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wsec; - NmtNewtWidget * widget, *hbox, *subgrid; - NmtNewtWidget * mode, *band, *security, *entry; - NmtNewtStack * stack; - NMConnection * conn; + NmtNewtWidget *widget, *hbox, *subgrid; + NmtNewtWidget *mode, *band, *security, *entry; + NmtNewtStack *stack; + NMConnection *conn; conn = nmt_editor_page_get_connection(NMT_EDITOR_PAGE(wifi)); s_wireless = _nm_connection_ensure_setting(conn, NM_TYPE_SETTING_WIRELESS); diff --git a/src/nmtui/nmt-page-wireguard.c b/src/nmtui/nmt-page-wireguard.c index 30a984e0..77e327b8 100644 --- a/src/nmtui/nmt-page-wireguard.c +++ b/src/nmtui/nmt-page-wireguard.c @@ -43,13 +43,13 @@ nmt_page_wireguard_init(NmtPageWireGuard *wireguard) static void nmt_page_wireguard_constructed(GObject *object) { - NmtPageWireGuard * wireguard = NMT_PAGE_WIREGUARD(object); + NmtPageWireGuard *wireguard = NMT_PAGE_WIREGUARD(object); NmtPageWireGuardPrivate *priv = NMT_PAGE_WIREGUARD_GET_PRIVATE(wireguard); - NmtEditorSection * section; - NmtEditorGrid * grid; - NMSettingWireGuard * s_wireguard; - NmtNewtWidget * widget; - NMConnection * conn; + NmtEditorSection *section; + NmtEditorGrid *grid; + NMSettingWireGuard *s_wireguard; + NmtNewtWidget *widget; + NMConnection *conn; conn = nmt_editor_page_get_connection(NMT_EDITOR_PAGE(wireguard)); s_wireguard = _nm_connection_ensure_setting(conn, NM_TYPE_SETTING_WIREGUARD); diff --git a/src/nmtui/nmt-password-dialog.c b/src/nmtui/nmt-password-dialog.c index 99b9b3f7..6189997f 100644 --- a/src/nmtui/nmt-password-dialog.c +++ b/src/nmtui/nmt-password-dialog.c @@ -23,8 +23,8 @@ G_DEFINE_TYPE(NmtPasswordDialog, nmt_password_dialog, NMT_TYPE_NEWT_FORM) (G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_PASSWORD_DIALOG, NmtPasswordDialogPrivate)) typedef struct { - char * request_id; - char * prompt; + char *request_id; + char *prompt; GPtrArray *secrets; GPtrArray *entries; @@ -60,7 +60,7 @@ NmtNewtForm * nmt_password_dialog_new(const char *request_id, const char *title, const char *prompt, - GPtrArray * secrets) + GPtrArray *secrets) { return g_object_new(NMT_TYPE_PASSWORD_DIALOG, "request-id", @@ -111,11 +111,11 @@ maybe_save_input_and_exit(NmtNewtWidget *widget, gpointer dialog) static void nmt_password_dialog_constructed(GObject *object) { - NmtPasswordDialog * dialog = NMT_PASSWORD_DIALOG(object); + NmtPasswordDialog *dialog = NMT_PASSWORD_DIALOG(object); NmtPasswordDialogPrivate *priv = NMT_PASSWORD_DIALOG_GET_PRIVATE(dialog); - NmtNewtWidget * widget; - NmtNewtGrid * grid, *secret_grid; - NmtNewtButtonBox * bbox; + NmtNewtWidget *widget; + NmtNewtGrid *grid, *secret_grid; + NmtNewtButtonBox *bbox; int i; widget = nmt_newt_grid_new(); @@ -187,10 +187,10 @@ nmt_password_dialog_finalize(GObject *object) } static void -nmt_password_dialog_set_property(GObject * object, +nmt_password_dialog_set_property(GObject *object, guint prop_id, const GValue *value, - GParamSpec * pspec) + GParamSpec *pspec) { NmtPasswordDialogPrivate *priv = NMT_PASSWORD_DIALOG_GET_PRIVATE(object); diff --git a/src/nmtui/nmt-password-dialog.h b/src/nmtui/nmt-password-dialog.h index 77e8f292..4c60e33d 100644 --- a/src/nmtui/nmt-password-dialog.h +++ b/src/nmtui/nmt-password-dialog.h @@ -34,11 +34,11 @@ GType nmt_password_dialog_get_type(void); NmtNewtForm *nmt_password_dialog_new(const char *request_id, const char *title, const char *prompt, - GPtrArray * secrets); + GPtrArray *secrets); gboolean nmt_password_dialog_succeeded(NmtPasswordDialog *dialog); const char *nmt_password_dialog_get_request_id(NmtPasswordDialog *dialog); -GPtrArray * nmt_password_dialog_get_secrets(NmtPasswordDialog *dialog); +GPtrArray *nmt_password_dialog_get_secrets(NmtPasswordDialog *dialog); #endif /* NMT_PASSWORD_DIALOG_H */ diff --git a/src/nmtui/nmt-password-fields.c b/src/nmtui/nmt-password-fields.c index 45073c7e..09573c72 100644 --- a/src/nmtui/nmt-password-fields.c +++ b/src/nmtui/nmt-password-fields.c @@ -24,7 +24,7 @@ G_DEFINE_TYPE(NmtPasswordFields, nmt_password_fields, NMT_TYPE_NEWT_GRID) typedef struct { NmtPasswordFieldsExtras extras; - NmtNewtEntry * entry; + NmtNewtEntry *entry; NmtNewtCheckbox *always_ask; NmtNewtCheckbox *show_password; @@ -113,7 +113,7 @@ static void nmt_password_fields_constructed(GObject *object) { NmtPasswordFieldsPrivate *priv = NMT_PASSWORD_FIELDS_GET_PRIVATE(object); - NmtNewtGrid * grid = NMT_NEWT_GRID(object); + NmtNewtGrid *grid = NMT_NEWT_GRID(object); nmt_newt_grid_add(grid, NMT_NEWT_WIDGET(priv->entry), 0, 0); @@ -169,12 +169,12 @@ nmt_password_fields_finalize(GObject *object) } static void -nmt_password_fields_set_property(GObject * object, +nmt_password_fields_set_property(GObject *object, guint prop_id, const GValue *value, - GParamSpec * pspec) + GParamSpec *pspec) { - NmtPasswordFields * fields = NMT_PASSWORD_FIELDS(object); + NmtPasswordFields *fields = NMT_PASSWORD_FIELDS(object); NmtPasswordFieldsPrivate *priv = NMT_PASSWORD_FIELDS_GET_PRIVATE(fields); switch (prop_id) { @@ -205,7 +205,7 @@ nmt_password_fields_set_property(GObject * object, static void nmt_password_fields_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NmtPasswordFields * entry = NMT_PASSWORD_FIELDS(object); + NmtPasswordFields *entry = NMT_PASSWORD_FIELDS(object); NmtPasswordFieldsPrivate *priv = NMT_PASSWORD_FIELDS_GET_PRIVATE(entry); switch (prop_id) { diff --git a/src/nmtui/nmt-route-editor.c b/src/nmtui/nmt-route-editor.c index ffccf38d..52272310 100644 --- a/src/nmtui/nmt-route-editor.c +++ b/src/nmtui/nmt-route-editor.c @@ -56,9 +56,9 @@ nmt_route_editor_init(NmtRouteEditor *entry) static void save_routes_and_exit(NmtNewtButton *button, gpointer user_data) { - NmtRouteEditor * editor = user_data; + NmtRouteEditor *editor = user_data; NmtRouteEditorPrivate *priv = NMT_ROUTE_EDITOR_GET_PRIVATE(editor); - GPtrArray * routes; + GPtrArray *routes; g_object_get(priv->edit_setting, NM_SETTING_IP_CONFIG_ROUTES, &routes, NULL); g_object_set(priv->orig_setting, NM_SETTING_IP_CONFIG_ROUTES, routes, NULL); @@ -70,9 +70,9 @@ save_routes_and_exit(NmtNewtButton *button, gpointer user_data) static void nmt_route_editor_constructed(GObject *object) { - NmtRouteEditor * editor = NMT_ROUTE_EDITOR(object); + NmtRouteEditor *editor = NMT_ROUTE_EDITOR(object); NmtRouteEditorPrivate *priv = NMT_ROUTE_EDITOR_GET_PRIVATE(editor); - NmtNewtWidget * vbox, *routes, *buttons, *ok, *cancel; + NmtNewtWidget *vbox, *routes, *buttons, *ok, *cancel; if (G_OBJECT_CLASS(nmt_route_editor_parent_class)->constructed) G_OBJECT_CLASS(nmt_route_editor_parent_class)->constructed(object); @@ -123,10 +123,10 @@ nmt_route_editor_finalize(GObject *object) } static void -nmt_route_editor_set_property(GObject * object, +nmt_route_editor_set_property(GObject *object, guint prop_id, const GValue *value, - GParamSpec * pspec) + GParamSpec *pspec) { NmtRouteEditorPrivate *priv = NMT_ROUTE_EDITOR_GET_PRIVATE(object); diff --git a/src/nmtui/nmt-route-entry.c b/src/nmtui/nmt-route-entry.c index 5cd150b0..e186fff2 100644 --- a/src/nmtui/nmt-route-entry.c +++ b/src/nmtui/nmt-route-entry.c @@ -75,9 +75,9 @@ nmt_route_entry_init(NmtRouteEntry *entry) {} static gboolean -entry_validity_transform_to_warning_label(GBinding * binding, +entry_validity_transform_to_warning_label(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { if (g_value_get_boolean(source_value)) @@ -109,8 +109,8 @@ static void nmt_route_entry_constructed(GObject *object) { NmtRouteEntryPrivate *priv = NMT_ROUTE_ENTRY_GET_PRIVATE(object); - NmtNewtGrid * grid = NMT_NEWT_GRID(object); - NmtNewtWidget * warning_label; + NmtNewtGrid *grid = NMT_NEWT_GRID(object); + NmtNewtWidget *warning_label; priv->dest = nmt_ip_entry_new(priv->ip_entry_width, priv->family, TRUE, FALSE); priv->next_hop = nmt_ip_entry_new(priv->ip_entry_width, priv->family, FALSE, TRUE); @@ -213,7 +213,7 @@ nmt_route_entry_get_property(GObject *object, guint prop_id, GValue *value, GPar static void nmt_route_entry_class_init(NmtRouteEntryClass *entry_class) { - GObjectClass * object_class = G_OBJECT_CLASS(entry_class); + GObjectClass *object_class = G_OBJECT_CLASS(entry_class); NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS(entry_class); g_type_class_add_private(entry_class, sizeof(NmtRouteEntryPrivate)); diff --git a/src/nmtui/nmt-route-table.c b/src/nmtui/nmt-route-table.c index fcb14e6a..4dc28d7c 100644 --- a/src/nmtui/nmt-route-table.c +++ b/src/nmtui/nmt-route-table.c @@ -32,7 +32,7 @@ typedef struct { int ip_entry_width; int metric_entry_width; - GPtrArray * routes; + GPtrArray *routes; NmtNewtWidget *list; } NmtRouteTablePrivate; @@ -59,15 +59,15 @@ nmt_route_table_new(int family) } static gboolean -route_list_transform_to_route(GBinding * binding, +route_list_transform_to_route(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { - NmtRouteTable * table = NMT_ROUTE_TABLE(g_binding_get_source(binding)); + NmtRouteTable *table = NMT_ROUTE_TABLE(g_binding_get_source(binding)); NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE(table); int n = GPOINTER_TO_INT(user_data); - NMIPRoute * route; + NMIPRoute *route; if (n >= priv->routes->len) return FALSE; @@ -78,16 +78,16 @@ route_list_transform_to_route(GBinding * binding, } static gboolean -route_list_transform_from_route(GBinding * binding, +route_list_transform_from_route(GBinding *binding, const GValue *source_value, - GValue * target_value, + GValue *target_value, gpointer user_data) { - NmtRouteTable * table = NMT_ROUTE_TABLE(g_binding_get_source(binding)); + NmtRouteTable *table = NMT_ROUTE_TABLE(g_binding_get_source(binding)); NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE(table); int n = GPOINTER_TO_INT(user_data); - GPtrArray * routes; - NMIPRoute * route; + GPtrArray *routes; + NMIPRoute *route; if (n >= priv->routes->len) return FALSE; @@ -108,7 +108,7 @@ static NmtNewtWidget * create_route_entry(NmtWidgetList *list, int num, gpointer table) { NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE(table); - NmtNewtWidget * entry; + NmtNewtWidget *entry; entry = nmt_route_entry_new(priv->family, priv->ip_entry_width, priv->metric_entry_width); @@ -128,7 +128,7 @@ static void add_route(NmtWidgetList *list, gpointer table) { NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE(table); - NMIPRoute * route; + NMIPRoute *route; if (priv->family == AF_INET) route = nm_ip_route_new(AF_INET, "0.0.0.0", 32, NULL, -1, NULL); @@ -157,10 +157,10 @@ static void nmt_route_table_init(NmtRouteTable *table) { NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE(table); - NmtNewtWidget * header, *empty; - NmtNewtWidget * dest_prefix_label, *next_hop_label, *metric_label; + NmtNewtWidget *header, *empty; + NmtNewtWidget *dest_prefix_label, *next_hop_label, *metric_label; int dest_prefix_width, next_hop_width, metric_width; - char * text; + char *text; priv->routes = g_ptr_array_new_with_free_func((GDestroyNotify) nm_ip_route_unref); @@ -219,7 +219,7 @@ static void nmt_route_table_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE(object); - GPtrArray * array; + GPtrArray *array; int i; switch (prop_id) { diff --git a/src/nmtui/nmt-slave-list.c b/src/nmtui/nmt-slave-list.c index a6ce554d..b3ba8dc4 100644 --- a/src/nmtui/nmt-slave-list.c +++ b/src/nmtui/nmt-slave-list.c @@ -22,7 +22,7 @@ G_DEFINE_TYPE(NmtSlaveList, nmt_slave_list, NMT_TYPE_EDIT_CONNECTION_LIST) typedef struct { NMConnection *master; - const char * master_type, *master_uuid; + const char *master_type, *master_uuid; NmtAddConnectionTypeFilter type_filter; gpointer type_filter_data; @@ -38,7 +38,7 @@ enum { }; static gboolean nmt_slave_list_connection_filter(NmtEditConnectionList *list, - NMConnection * connection, + NMConnection *connection, gpointer user_data); /** @@ -59,7 +59,7 @@ static gboolean nmt_slave_list_connection_filter(NmtEditConnectionList *list, * Returns: a new #NmtSlaveList. */ NmtNewtWidget * -nmt_slave_list_new(NMConnection * master, +nmt_slave_list_new(NMConnection *master, NmtAddConnectionTypeFilter type_filter, gpointer type_filter_data) { @@ -93,12 +93,12 @@ nmt_slave_list_finalize(GObject *object) static gboolean nmt_slave_list_connection_filter(NmtEditConnectionList *list, - NMConnection * connection, + NMConnection *connection, gpointer user_data) { NmtSlaveListPrivate *priv = NMT_SLAVE_LIST_GET_PRIVATE(list); NMSettingConnection *s_con; - const char * master, *master_ifname, *slave_type; + const char *master, *master_ifname, *slave_type; s_con = nm_connection_get_setting_connection(connection); g_return_val_if_fail(s_con != NULL, FALSE); @@ -193,7 +193,7 @@ nmt_slave_list_get_property(GObject *object, guint prop_id, GValue *value, GPara static void nmt_slave_list_class_init(NmtSlaveListClass *list_class) { - GObjectClass * object_class = G_OBJECT_CLASS(list_class); + GObjectClass *object_class = G_OBJECT_CLASS(list_class); NmtEditConnectionListClass *connection_list_class = NMT_EDIT_CONNECTION_LIST_CLASS(list_class); g_type_class_add_private(list_class, sizeof(NmtSlaveListPrivate)); diff --git a/src/nmtui/nmt-slave-list.h b/src/nmtui/nmt-slave-list.h index f220fc12..ab7de7b7 100644 --- a/src/nmtui/nmt-slave-list.h +++ b/src/nmtui/nmt-slave-list.h @@ -30,7 +30,7 @@ typedef struct { GType nmt_slave_list_get_type(void); -NmtNewtWidget *nmt_slave_list_new(NMConnection * master, +NmtNewtWidget *nmt_slave_list_new(NMConnection *master, NmtAddConnectionTypeFilter type_filter, gpointer type_filter_data); diff --git a/src/nmtui/nmt-utils.c b/src/nmtui/nmt-utils.c index bac763f6..84d9e9bb 100644 --- a/src/nmtui/nmt-utils.c +++ b/src/nmtui/nmt-utils.c @@ -42,7 +42,7 @@ typedef struct { gpointer result; - GError * error; + GError *error; gpointer complete; } NmtSyncOpReal; diff --git a/src/nmtui/nmt-widget-list.c b/src/nmtui/nmt-widget-list.c index cd0c6c3c..18d4d16e 100644 --- a/src/nmtui/nmt-widget-list.c +++ b/src/nmtui/nmt-widget-list.c @@ -45,7 +45,7 @@ typedef struct { GPtrArray *remove_buttons; NmtNewtWidget *add_button; - GBinding * add_sensitivity; + GBinding *add_sensitivity; } NmtWidgetListPrivate; enum { @@ -106,7 +106,7 @@ NmtNewtWidget * nmt_widget_list_new(NmtWidgetListCallback create_callback, gpointer user_data, GDestroyNotify destroy_notify, - NmtNewtWidget * empty_widget) + NmtNewtWidget *empty_widget) { return g_object_new(NMT_TYPE_WIDGET_LIST, "create-callback", @@ -166,9 +166,9 @@ static void ensure_widgets(NmtWidgetList *list) { NmtWidgetListPrivate *priv = NMT_WIDGET_LIST_GET_PRIVATE(list); - NmtNewtWidget * widget, *button, *focus; + NmtNewtWidget *widget, *button, *focus; gboolean was_empty; - NmtNewtForm * form; + NmtNewtForm *form; int i; was_empty = priv->widgets->len == 0; diff --git a/src/nmtui/nmt-widget-list.h b/src/nmtui/nmt-widget-list.h index 1825c884..f6ed8c4d 100644 --- a/src/nmtui/nmt-widget-list.h +++ b/src/nmtui/nmt-widget-list.h @@ -42,7 +42,7 @@ typedef NmtNewtWidget *(*NmtWidgetListCallback)(NmtWidgetList *list, int n, gpoi NmtNewtWidget *nmt_widget_list_new(NmtWidgetListCallback create_callback, gpointer user_data, GDestroyNotify destroy_notify, - NmtNewtWidget * empty_widget); + NmtNewtWidget *empty_widget); int nmt_widget_list_get_length(NmtWidgetList *list); void nmt_widget_list_set_length(NmtWidgetList *list, int length); diff --git a/src/nmtui/nmt-wireguard-peer-editor.c b/src/nmtui/nmt-wireguard-peer-editor.c index 810bdf69..a78cfdf0 100644 --- a/src/nmtui/nmt-wireguard-peer-editor.c +++ b/src/nmtui/nmt-wireguard-peer-editor.c @@ -28,8 +28,8 @@ G_DEFINE_TYPE(NmtWireguardPeerEditor, nmt_wireguard_peer_editor, NMT_TYPE_NEWT_F typedef struct { NMSettingWireGuard *orig_setting; NMSettingWireGuard *edit_setting; - NMWireGuardPeer * peer; - NmtNewtEntry * private_key; + NMWireGuardPeer *peer; + NmtNewtEntry *private_key; } NmtWireguardPeerEditorPrivate; enum { @@ -55,7 +55,7 @@ nmt_wireguard_peer_editor_init(NmtWireguardPeerEditor *peer) static void save_peer_and_exit(NmtNewtButton *button, gpointer user_data) { - NmtWireguardPeerEditor * editor = user_data; + NmtWireguardPeerEditor *editor = user_data; NmtWireguardPeerEditorPrivate *priv = NMT_WIREGUARD_PEER_EDITOR_GET_PRIVATE(editor); nm_setting_wireguard_append_peer(priv->orig_setting, priv->peer); @@ -67,10 +67,10 @@ static void nmt_wireguard_peer_editor_constructed(GObject *object) { NmtWireguardPeerEditor *peer = NMT_WIREGUARD_PEER_EDITOR(object); - NmtEditorSection * section; - NmtEditorGrid * grid; - NmtNewtWidget * widget, *label; - NmtNewtWidget * buttons, *ok, *cancel; + NmtEditorSection *section; + NmtEditorGrid *grid; + NmtNewtWidget *widget, *label; + NmtNewtWidget *buttons, *ok, *cancel; if (G_OBJECT_CLASS(nmt_wireguard_peer_editor_parent_class)->constructed) G_OBJECT_CLASS(nmt_wireguard_peer_editor_parent_class)->constructed(object); @@ -161,10 +161,10 @@ nmt_wireguard_peer_editor_constructed(GObject *object) } static void -nmt_wireguard_peer_editor_set_property(GObject * object, +nmt_wireguard_peer_editor_set_property(GObject *object, guint prop_id, const GValue *value, - GParamSpec * pspec) + GParamSpec *pspec) { NmtWireguardPeerEditorPrivate *priv = NMT_WIREGUARD_PEER_EDITOR_GET_PRIVATE(object); @@ -184,9 +184,9 @@ nmt_wireguard_peer_editor_set_property(GObject * object, } static void -nmt_wireguard_peer_editor_get_property(GObject * object, +nmt_wireguard_peer_editor_get_property(GObject *object, guint prop_id, - GValue * value, + GValue *value, GParamSpec *pspec) { NmtWireguardPeerEditorPrivate *priv = NMT_WIREGUARD_PEER_EDITOR_GET_PRIVATE(object); diff --git a/src/nmtui/nmt-wireguard-peer-list.c b/src/nmtui/nmt-wireguard-peer-list.c index 03f3ef9a..3ac8a88c 100644 --- a/src/nmtui/nmt-wireguard-peer-list.c +++ b/src/nmtui/nmt-wireguard-peer-list.c @@ -24,9 +24,9 @@ G_DEFINE_TYPE(NmtWireguardPeerList, nmt_wireguard_peer_list, NMT_TYPE_NEWT_GRID) typedef struct { NMSettingWireGuard *setting; - GSList * peers; + GSList *peers; - NmtNewtListbox * listbox; + NmtNewtListbox *listbox; NmtNewtButtonBox *buttons; NmtNewtWidget *add; @@ -98,8 +98,8 @@ static void nmt_wireguard_peer_list_init(NmtWireguardPeerList *list) { NmtWireguardPeerListPrivate *priv = NMT_WIREGUARD_PEER_LIST_GET_PRIVATE(list); - NmtNewtWidget * listbox, *buttons; - NmtNewtGrid * grid = NMT_NEWT_GRID(list); + NmtNewtWidget *listbox, *buttons; + NmtNewtGrid *grid = NMT_NEWT_GRID(list); listbox = g_object_new(NMT_TYPE_NEWT_LISTBOX, "flags", @@ -166,8 +166,8 @@ static void nmt_wireguard_peer_list_add_peer(NmtWireguardPeerList *list) { NmtWireguardPeerListPrivate *priv = NMT_WIREGUARD_PEER_LIST_GET_PRIVATE(list); - NMWireGuardPeer * peer = nm_wireguard_peer_new(); - NmtNewtForm * editor; + NMWireGuardPeer *peer = nm_wireguard_peer_new(); + NmtNewtForm *editor; editor = nmt_wireguard_peer_editor_new(priv->setting, peer); @@ -183,8 +183,8 @@ static void nmt_wireguard_peer_list_edit_peer(NmtWireguardPeerList *list) { NmtWireguardPeerListPrivate *priv = NMT_WIREGUARD_PEER_LIST_GET_PRIVATE(list); - NMWireGuardPeer * orig_peer, *edit_peer; - NmtNewtForm * editor; + NMWireGuardPeer *orig_peer, *edit_peer; + NmtNewtForm *editor; int selected_row; selected_row = nmt_newt_listbox_get_active(priv->listbox); @@ -216,10 +216,10 @@ nmt_wireguard_peer_list_remove_peer(NmtWireguardPeerList *list) } static void -nmt_wireguard_peer_list_set_property(GObject * object, +nmt_wireguard_peer_list_set_property(GObject *object, guint prop_id, const GValue *value, - GParamSpec * pspec) + GParamSpec *pspec) { NmtWireguardPeerListPrivate *priv = NMT_WIREGUARD_PEER_LIST_GET_PRIVATE(object); @@ -237,14 +237,14 @@ nmt_wireguard_peer_list_set_property(GObject * object, } static void -nmt_wireguard_peer_list_get_property(GObject * object, +nmt_wireguard_peer_list_get_property(GObject *object, guint prop_id, - GValue * value, + GValue *value, GParamSpec *pspec) { NmtWireguardPeerListPrivate *priv = NMT_WIREGUARD_PEER_LIST_GET_PRIVATE(object); - GPtrArray * peers; - GSList * iter; + GPtrArray *peers; + GSList *iter; switch (prop_id) { case PROP_SETTING: @@ -269,10 +269,10 @@ static void nmt_wireguard_peer_list_rebuild(NmtWireguardPeerList *list) { NmtWireguardPeerListPrivate *priv = NMT_WIREGUARD_PEER_LIST_GET_PRIVATE(list); - GSList * iter; - NMWireGuardPeer * peer, *selected_peer; + GSList *iter; + NMWireGuardPeer *peer, *selected_peer; int i, row, selected_row, num; - NMSettingWireGuard * setting = priv->setting; + NMSettingWireGuard *setting = priv->setting; selected_row = nmt_newt_listbox_get_active(priv->listbox); selected_peer = nmt_newt_listbox_get_active_key(priv->listbox); diff --git a/src/nmtui/nmtui-connect.c b/src/nmtui/nmtui-connect.c index 4aa91acb..fb456653 100644 --- a/src/nmtui/nmtui-connect.c +++ b/src/nmtui/nmtui-connect.c @@ -33,11 +33,11 @@ static gboolean openconnect_authenticate(NMConnection *connection, char **cookie, char **gateway, char **gwcert) { - GError * error = NULL; + GError *error = NULL; NMSettingVpn *s_vpn; gboolean ret; int status = 0; - const char * gw, *port; + const char *gw, *port; nmt_newt_message_dialog( _("openconnect will be run to authenticate.\nIt will return to nmtui when completed.")); @@ -80,13 +80,13 @@ openconnect_authenticate(NMConnection *connection, char **cookie, char **gateway static void secrets_requested(NMSecretAgentSimple *agent, - const char * request_id, - const char * title, - const char * msg, - GPtrArray * secrets, + const char *request_id, + const char *title, + const char *msg, + GPtrArray *secrets, gpointer user_data) { - NmtNewtForm * form; + NmtNewtForm *form; NMConnection *connection = NM_CONNECTION(user_data); int i; @@ -138,16 +138,16 @@ secrets_requested(NMSecretAgentSimple *agent, } typedef struct { - NMDevice * device; + NMDevice *device; NMActiveConnection *active; - NmtSyncOp * op; + NmtSyncOp *op; } ActivateConnectionInfo; static void connect_cancelled(NmtNewtForm *form, gpointer user_data) { ActivateConnectionInfo *info = user_data; - GError * error = NULL; + GError *error = NULL; error = g_error_new_literal(G_IO_ERROR, G_IO_ERROR_CANCELLED, "Cancelled"); nmt_sync_op_complete_boolean(info->op, FALSE, error); @@ -158,8 +158,8 @@ static void check_activated(ActivateConnectionInfo *info) { NMActiveConnectionState ac_state; - const char * reason = NULL; - gs_free_error GError *error = NULL; + const char *reason = NULL; + gs_free_error GError *error = NULL; ac_state = nmc_activation_get_effective_state(info->active, info->device, &reason); if (!NM_IN_SET(ac_state, @@ -193,9 +193,9 @@ activate_device_state_changed(GObject *object, GParamSpec *pspec, gpointer user_ static void activate_callback(GObject *client, GAsyncResult *result, gpointer user_data) { - NmtSyncOp * op = user_data; + NmtSyncOp *op = user_data; NMActiveConnection *ac; - GError * error = NULL; + GError *error = NULL; ac = nm_client_activate_connection_finish(NM_CLIENT(client), result, &error); if (error) @@ -207,9 +207,9 @@ activate_callback(GObject *client, GAsyncResult *result, gpointer user_data) static void add_and_activate_callback(GObject *client, GAsyncResult *result, gpointer user_data) { - NmtSyncOp * op = user_data; + NmtSyncOp *op = user_data; NMActiveConnection *ac; - GError * error = NULL; + GError *error = NULL; ac = nm_client_add_and_activate_connection_finish(NM_CLIENT(client), result, &error); if (error) @@ -232,13 +232,13 @@ deactivate_connection(NMActiveConnection *ac) static void activate_connection(NMConnection *connection, NMDevice *device, NMObject *specific_object) { - NmtNewtForm * form; + NmtNewtForm *form; gs_unref_object NMSecretAgentSimple *agent = NULL; - NmtNewtWidget * label; + NmtNewtWidget *label; NmtSyncOp op; - const char * specific_object_path; - NMActiveConnection * ac; - GError * error = NULL; + const char *specific_object_path; + NMActiveConnection *ac; + GError *error = NULL; ActivateConnectionInfo info = {}; form = g_object_new(NMT_TYPE_NEWT_FORM, "escape-exits", TRUE, NULL); @@ -351,10 +351,10 @@ static void listbox_activated(NmtNewtListbox *listbox, gpointer user_data) { NmtConnectConnectionList *list = NMT_CONNECT_CONNECTION_LIST(listbox); - NMConnection * connection; - NMDevice * device; - NMObject * specific_object; - NMActiveConnection * ac; + NMConnection *connection; + NMDevice *device; + NMObject *specific_object; + NMActiveConnection *ac; if (!nmt_connect_connection_list_get_selection(list, &connection, @@ -379,9 +379,9 @@ static void listbox_active_changed(GObject *object, GParamSpec *pspec, gpointer button) { NmtConnectConnectionList *list = NMT_CONNECT_CONNECTION_LIST(object); - static const char * activate, *deactivate; + static const char *activate, *deactivate; static int deactivate_padding, activate_padding; - NMActiveConnection * ac; + NMActiveConnection *ac; gboolean has_selection; if (G_UNLIKELY(activate == NULL)) { @@ -412,7 +412,7 @@ static NmtNewtForm * nmt_connect_connection_list(gboolean is_top) { int screen_width, screen_height; - NmtNewtForm * form; + NmtNewtForm *form; NmtNewtWidget *list, *activate, *quit, *bbox, *grid; newtGetScreenSize(&screen_width, &screen_height); @@ -455,10 +455,10 @@ nmt_connect_connection_list(gboolean is_top) static NmtNewtForm * nmt_connect_connection(const char *identifier) { - NmtNewtWidget * list; - NMConnection * connection; - NMDevice * device; - NMObject * specific_object; + NmtNewtWidget *list; + NMConnection *connection; + NMDevice *device; + NMObject *specific_object; NMActiveConnection *ac; list = nmt_connect_connection_list_new(); diff --git a/src/nmtui/nmtui-edit.c b/src/nmtui/nmtui-edit.c index 534643a7..ec80a203 100644 --- a/src/nmtui/nmtui-edit.c +++ b/src/nmtui/nmtui-edit.c @@ -45,13 +45,13 @@ list_remove_connection(NmtEditConnectionList *list, NMRemoteConnection *connecti static gboolean edit_connection_list_filter(NmtEditConnectionList *list, - NMConnection * connection, + NMConnection *connection, gpointer user_data) { NMSettingConnection *s_con; - const char * master, *slave_type; - const char * uuid, *ifname; - const GPtrArray * conns; + const char *master, *slave_type; + const char *uuid, *ifname; + const GPtrArray *conns; int i; gboolean found_master = FALSE; @@ -86,7 +86,7 @@ static NmtNewtForm * nmt_edit_main_connection_list(gboolean is_top) { int screen_width, screen_height; - NmtNewtForm * form; + NmtNewtForm *form; NmtNewtWidget *quit, *list; newtGetScreenSize(&screen_width, &screen_height); @@ -137,9 +137,9 @@ typedef struct { NmtNewtTextbox *textbox; NmtNewtListbox *listbox; - char * primary_text; - char * secondary_text; - NMConnection * master; + char *primary_text; + char *secondary_text; + NMConnection *master; NmtAddConnectionTypeFilter type_filter; gpointer type_filter_data; @@ -181,8 +181,8 @@ static void nmt_add_connection_init(NmtAddConnection *form) { NmtAddConnectionPrivate *priv = NMT_ADD_CONNECTION_GET_PRIVATE(form); - NmtNewtWidget * textbox, *listbox, *button; - NmtNewtGrid * grid, *buttons; + NmtNewtWidget *textbox, *listbox, *button; + NmtNewtGrid *grid, *buttons; grid = NMT_NEWT_GRID(nmt_newt_grid_new()); @@ -222,9 +222,9 @@ nmt_add_connection_init(NmtAddConnection *form) static void nmt_add_connection_constructed(GObject *object) { - NmtAddConnectionPrivate * priv = NMT_ADD_CONNECTION_GET_PRIVATE(object); + NmtAddConnectionPrivate *priv = NMT_ADD_CONNECTION_GET_PRIVATE(object); NMEditorConnectionTypeData **types; - char * text; + char *text; int i, num_types; if (priv->secondary_text) { @@ -275,10 +275,10 @@ nmt_add_connection_finalize(GObject *object) } static void -nmt_add_connection_set_property(GObject * object, +nmt_add_connection_set_property(GObject *object, guint prop_id, const GValue *value, - GParamSpec * pspec) + GParamSpec *pspec) { NmtAddConnectionPrivate *priv = NMT_ADD_CONNECTION_GET_PRIVATE(object); @@ -334,7 +334,7 @@ nmt_add_connection_get_property(GObject *object, guint prop_id, GValue *value, G static void nmt_add_connection_class_init(NmtAddConnectionClass *add_class) { - GObjectClass * object_class = G_OBJECT_CLASS(add_class); + GObjectClass *object_class = G_OBJECT_CLASS(add_class); NmtNewtFormClass *form_class = NMT_NEWT_FORM_CLASS(add_class); g_type_class_add_private(add_class, sizeof(NmtAddConnectionPrivate)); @@ -404,9 +404,9 @@ nmt_add_connection(void) } void -nmt_add_connection_full(const char * primary_text, - const char * secondary_text, - NMConnection * master, +nmt_add_connection_full(const char *primary_text, + const char *secondary_text, + NMConnection *master, NmtAddConnectionTypeFilter type_filter, gpointer type_filter_data) { @@ -453,7 +453,7 @@ static void connection_deleted_callback(GObject *connection, GAsyncResult *result, gpointer user_data) { ConnectionDeleteData *data = user_data; - GError * error = NULL; + GError *error = NULL; if (!nm_remote_connection_delete_finish(data->connection, result, &error)) { nmt_newt_message_dialog(_("Unable to delete connection: %s"), error->message); @@ -481,7 +481,7 @@ static void remove_one_connection(NMRemoteConnection *connection) { ConnectionDeleteData data; - GError * error = NULL; + GError *error = NULL; data.got_callback = data.got_signal = FALSE; nmt_sync_op_init(&data.op); @@ -506,12 +506,12 @@ remove_one_connection(NMRemoteConnection *connection) void nmt_remove_connection(NMRemoteConnection *connection) { - const GPtrArray * all_conns; - GSList * slaves, *iter; + const GPtrArray *all_conns; + GSList *slaves, *iter; int i; - NMRemoteConnection * slave; + NMRemoteConnection *slave; NMSettingConnection *s_con; - const char * uuid, *iface, *master; + const char *uuid, *iface, *master; int choice; choice = nmt_newt_choice_dialog(_("Cancel"), diff --git a/src/nmtui/nmtui-edit.h b/src/nmtui/nmtui-edit.h index 99e370b4..e8685602 100644 --- a/src/nmtui/nmtui-edit.h +++ b/src/nmtui/nmtui-edit.h @@ -13,9 +13,9 @@ typedef gboolean (*NmtAddConnectionTypeFilter)(GType connection_type, gpointer u NmtNewtForm *nmtui_edit(gboolean is_top, int argc, char **argv); void nmt_add_connection(void); -void nmt_add_connection_full(const char * primary_text, - const char * secondary_text, - NMConnection * master, +void nmt_add_connection_full(const char *primary_text, + const char *secondary_text, + NMConnection *master, NmtAddConnectionTypeFilter type_filter, gpointer type_filter_data); diff --git a/src/nmtui/nmtui-hostname.c b/src/nmtui/nmtui-hostname.c index 2f252428..65af73cc 100644 --- a/src/nmtui/nmtui-hostname.c +++ b/src/nmtui/nmtui-hostname.c @@ -21,12 +21,12 @@ static char * nmtui_hostname_run_dialog(void) { - NmtNewtForm * form; - NmtNewtWidget * widget, *ok, *cancel; - NmtNewtGrid * grid; - NmtNewtEntry * entry; + NmtNewtForm *form; + NmtNewtWidget *widget, *ok, *cancel; + NmtNewtGrid *grid; + NmtNewtEntry *entry; NmtNewtButtonBox *bbox; - char * hostname, *ret = NULL; + char *hostname, *ret = NULL; form = g_object_new(NMT_TYPE_NEWT_FORM, "title", _("Set Hostname"), "escape-exits", TRUE, NULL); @@ -79,9 +79,9 @@ NmtNewtForm * nmtui_hostname(gboolean is_top, int argc, char **argv) { const char *hostname; - char * tmp = NULL; + char *tmp = NULL; NmtSyncOp op; - GError * error = NULL; + GError *error = NULL; if (argc == 2) hostname = argv[1]; diff --git a/src/nmtui/nmtui.c b/src/nmtui/nmtui.c index 897e0911..c99d1641 100644 --- a/src/nmtui/nmtui.c +++ b/src/nmtui/nmtui.c @@ -27,14 +27,14 @@ #include "nmtui-connect.h" #include "nmtui-hostname.h" -NMClient * nm_client; +NMClient *nm_client; static GMainLoop *loop; typedef NmtNewtForm *(*NmtuiSubprogram)(gboolean is_top, int argc, char **argv); static const struct { - const char * name, *shortcut, *arg; - const char * display_name; + const char *name, *shortcut, *arg; + const char *display_name; NmtuiSubprogram func; } subprograms[] = { {"edit", "nmtui-edit", N_("connection"), N_("Edit a connection"), nmtui_edit}, @@ -57,7 +57,7 @@ quit_func(int argc, char **argv) static void main_list_activated(NmtNewtWidget *widget, NmtNewtListbox *listbox) { - NmtNewtForm * form; + NmtNewtForm *form; NmtuiSubprogram sub; sub = nmt_newt_listbox_get_active_key(listbox); @@ -73,10 +73,10 @@ main_list_activated(NmtNewtWidget *widget, NmtNewtListbox *listbox) static NmtNewtForm * nmtui_main(gboolean is_top, int argc, char **argv) { - NmtNewtForm * form; - NmtNewtWidget * widget, *ok; - NmtNewtGrid * grid; - NmtNewtListbox * listbox; + NmtNewtForm *form; + NmtNewtWidget *widget, *ok; + NmtNewtGrid *grid; + NmtNewtListbox *listbox; NmtNewtButtonBox *bbox; int i; @@ -162,7 +162,7 @@ usage(void) typedef struct { NmtuiSubprogram subprogram; int argc; - char ** argv; + char **argv; } NmtuiStartupData; static void @@ -175,7 +175,7 @@ static gboolean idle_run_subprogram(gpointer user_data) { NmtuiStartupData *data = user_data; - NmtNewtForm * form; + NmtNewtForm *form; form = data->subprogram(TRUE, data->argc, data->argv); if (form) { @@ -210,10 +210,10 @@ GOptionEntry entries[] = {{"sleep", int main(int argc, char **argv) { - GOptionContext * opts; - GError * error = NULL; + GOptionContext *opts; + GError *error = NULL; NmtuiStartupData startup_data; - const char * prgname; + const char *prgname; int i; setlocale(LC_ALL, ""); diff --git a/src/tests/client/test-client.check-on-disk/test_003.expected b/src/tests/client/test-client.check-on-disk/test_003.expected index beb58fe4..5ba040ef 100644 --- a/src/tests/client/test-client.check-on-disk/test_003.expected +++ b/src/tests/client/test-client.check-on-disk/test_003.expected @@ -4430,12 +4430,12 @@ UUID-con-gsm3-REPLACED-REPLACED-REPL gsm UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet <<< -size: 7193 +size: 7191 location: src/tests/client/test-client.py:test_003()/102 cmd: $NMCLI --pretty con s ethernet lang: C returncode: 0 -stdout: 7050 bytes +stdout: 7048 bytes >>> =============================================================================== Connection profile details (ethernet) @@ -4542,7 +4542,7 @@ proxy.pac-url: -- proxy.pac-script: -- ------------------------------------------------------------------------------- =============================================================================== - Activate connection details (UUID-ethernet-REPLACED-REPLACED-REPL) + Active connection details (UUID-ethernet-REPLACED-REPLACED-REPL) =============================================================================== GENERAL.NAME: ethernet GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL @@ -4560,7 +4560,7 @@ GENERAL.MASTER-PATH: -- ------------------------------------------------------------------------------- =============================================================================== - Activate connection details (UUID-ethernet-REPLACED-REPLACED-REPL) + Active connection details (UUID-ethernet-REPLACED-REPLACED-REPL) =============================================================================== GENERAL.NAME: ethernet GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL @@ -4726,12 +4726,12 @@ GENERAL.MASTER-PATH: -- ------------------------------------------------------------------------------- <<< -size: 6210 +size: 6209 location: src/tests/client/test-client.py:test_003()/104 cmd: $NMCLI --pretty c s /org/freedesktop/NetworkManager/ActiveConnection/1 lang: C returncode: 0 -stdout: 6027 bytes +stdout: 6026 bytes >>> =============================================================================== Connection profile details (ethernet) @@ -4838,7 +4838,7 @@ proxy.pac-url: -- proxy.pac-script: -- ------------------------------------------------------------------------------- =============================================================================== - Activate connection details (UUID-ethernet-REPLACED-REPLACED-REPL) + Active connection details (UUID-ethernet-REPLACED-REPLACED-REPL) =============================================================================== GENERAL.NAME: ethernet GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL @@ -5236,12 +5236,12 @@ UUID-con-gsm3-REPLACED-REPLACED-REPL gsm UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet <<< -size: 7205 +size: 7203 location: src/tests/client/test-client.py:test_003()/112 cmd: $NMCLI --pretty --color yes con s ethernet lang: C returncode: 0 -stdout: 7050 bytes +stdout: 7048 bytes >>> =============================================================================== Connection profile details (ethernet) @@ -5348,7 +5348,7 @@ proxy.pac-url: -- proxy.pac-script: -- ------------------------------------------------------------------------------- =============================================================================== - Activate connection details (UUID-ethernet-REPLACED-REPLACED-REPL) + Active connection details (UUID-ethernet-REPLACED-REPLACED-REPL) =============================================================================== GENERAL.NAME: ethernet GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL @@ -5366,7 +5366,7 @@ GENERAL.MASTER-PATH: -- ------------------------------------------------------------------------------- =============================================================================== - Activate connection details (UUID-ethernet-REPLACED-REPLACED-REPL) + Active connection details (UUID-ethernet-REPLACED-REPLACED-REPL) =============================================================================== GENERAL.NAME: ethernet GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL @@ -5532,12 +5532,12 @@ GENERAL.MASTER-PATH: -- ------------------------------------------------------------------------------- <<< -size: 6222 +size: 6221 location: src/tests/client/test-client.py:test_003()/114 cmd: $NMCLI --pretty --color yes c s /org/freedesktop/NetworkManager/ActiveConnection/1 lang: C returncode: 0 -stdout: 6027 bytes +stdout: 6026 bytes >>> =============================================================================== Connection profile details (ethernet) @@ -5644,7 +5644,7 @@ proxy.pac-url: -- proxy.pac-script: -- ------------------------------------------------------------------------------- =============================================================================== - Activate connection details (UUID-ethernet-REPLACED-REPLACED-REPL) + Active connection details (UUID-ethernet-REPLACED-REPLACED-REPL) =============================================================================== GENERAL.NAME: ethernet GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL @@ -7958,12 +7958,12 @@ UUID-con-gsm3-REPLACED-REPLACED-REPL gsm UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet <<< -size: 6473 +size: 6461 location: src/tests/client/test-client.py:test_003()/162 cmd: $NMCLI --mode tabular --pretty con s ethernet lang: C returncode: 0 -stdout: 6315 bytes +stdout: 6303 bytes >>> ========================================= Connection profile details (ethernet) @@ -7988,17 +7988,17 @@ name method browser-only pac-url pac-script -------------------------------------------------- proxy none no -- -- -====================================================================== - Activate connection details (UUID-ethernet-REPLACED-REPLACED-REPL) -====================================================================== +==================================================================== + Active connection details (UUID-ethernet-REPLACED-REPLACED-REPL) +==================================================================== GROUP NAME UUID DEVICES IP-IFACE STATE DEFAULT DEFAULT6 SPEC-OBJECT VPN DBUS-PATH CON-PATH ZONE MASTER-PATH ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GENERAL ethernet UUID-ethernet-REPLACED-REPLACED-REPL eth1 eth1 activated no no -- no /org/freedesktop/NetworkManager/ActiveConnection/2 /org/freedesktop/NetworkManager/Settings/Connection/6 -- -- -====================================================================== - Activate connection details (UUID-ethernet-REPLACED-REPLACED-REPL) -====================================================================== +==================================================================== + Active connection details (UUID-ethernet-REPLACED-REPLACED-REPL) +==================================================================== GROUP NAME UUID DEVICES IP-IFACE STATE DEFAULT DEFAULT6 SPEC-OBJECT VPN DBUS-PATH CON-PATH ZONE MASTER-PATH ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GENERAL ethernet UUID-ethernet-REPLACED-REPLACED-REPL eth0 eth0 deactivating no no -- no /org/freedesktop/NetworkManager/ActiveConnection/1 /org/freedesktop/NetworkManager/Settings/Connection/6 -- -- @@ -8052,12 +8052,12 @@ GENERAL ethernet UUID-ethernet-REPLACED-REPLACED-REPL eth0 eth0 deza <<< -size: 5549 +size: 5543 location: src/tests/client/test-client.py:test_003()/164 cmd: $NMCLI --mode tabular --pretty c s /org/freedesktop/NetworkManager/ActiveConnection/1 lang: C returncode: 0 -stdout: 5351 bytes +stdout: 5345 bytes >>> ========================================= Connection profile details (ethernet) @@ -8082,9 +8082,9 @@ name method browser-only pac-url pac-script -------------------------------------------------- proxy none no -- -- -====================================================================== - Activate connection details (UUID-ethernet-REPLACED-REPLACED-REPL) -====================================================================== +==================================================================== + Active connection details (UUID-ethernet-REPLACED-REPLACED-REPL) +==================================================================== GROUP NAME UUID DEVICES IP-IFACE STATE DEFAULT DEFAULT6 SPEC-OBJECT VPN DBUS-PATH CON-PATH ZONE MASTER-PATH ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GENERAL ethernet UUID-ethernet-REPLACED-REPLACED-REPL eth0 eth0 deactivating no no -- no /org/freedesktop/NetworkManager/ActiveConnection/1 /org/freedesktop/NetworkManager/Settings/Connection/6 -- -- @@ -8306,12 +8306,12 @@ UUID-con-gsm3-REPLACED-REPLACED-REPL gsm UUID-con-xx1-REPLACED-REPLACED-REPLA ethernet <<< -size: 6485 +size: 6473 location: src/tests/client/test-client.py:test_003()/172 cmd: $NMCLI --mode tabular --pretty --color yes con s ethernet lang: C returncode: 0 -stdout: 6315 bytes +stdout: 6303 bytes >>> ========================================= Connection profile details (ethernet) @@ -8336,17 +8336,17 @@ name method browser-only pac-url pac-script -------------------------------------------------- proxy none no -- -- -====================================================================== - Activate connection details (UUID-ethernet-REPLACED-REPLACED-REPL) -====================================================================== +==================================================================== + Active connection details (UUID-ethernet-REPLACED-REPLACED-REPL) +==================================================================== GROUP NAME UUID DEVICES IP-IFACE STATE DEFAULT DEFAULT6 SPEC-OBJECT VPN DBUS-PATH CON-PATH ZONE MASTER-PATH ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GENERAL ethernet UUID-ethernet-REPLACED-REPLACED-REPL eth1 eth1 activated no no -- no /org/freedesktop/NetworkManager/ActiveConnection/2 /org/freedesktop/NetworkManager/Settings/Connection/6 -- -- -====================================================================== - Activate connection details (UUID-ethernet-REPLACED-REPLACED-REPL) -====================================================================== +==================================================================== + Active connection details (UUID-ethernet-REPLACED-REPLACED-REPL) +==================================================================== GROUP NAME UUID DEVICES IP-IFACE STATE DEFAULT DEFAULT6 SPEC-OBJECT VPN DBUS-PATH CON-PATH ZONE MASTER-PATH ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GENERAL ethernet UUID-ethernet-REPLACED-REPLACED-REPL eth0 eth0 deactivating no no -- no /org/freedesktop/NetworkManager/ActiveConnection/1 /org/freedesktop/NetworkManager/Settings/Connection/6 -- -- @@ -8400,12 +8400,12 @@ GENERAL ethernet UUID-ethernet-REPLACED-REPLACED-REPL eth0 eth0 deza <<< -size: 5561 +size: 5555 location: src/tests/client/test-client.py:test_003()/174 cmd: $NMCLI --mode tabular --pretty --color yes c s /org/freedesktop/NetworkManager/ActiveConnection/1 lang: C returncode: 0 -stdout: 5351 bytes +stdout: 5345 bytes >>> ========================================= Connection profile details (ethernet) @@ -8430,9 +8430,9 @@ name method browser-only pac-url pac-script -------------------------------------------------- proxy none no -- -- -====================================================================== - Activate connection details (UUID-ethernet-REPLACED-REPLACED-REPL) -====================================================================== +==================================================================== + Active connection details (UUID-ethernet-REPLACED-REPLACED-REPL) +==================================================================== GROUP NAME UUID DEVICES IP-IFACE STATE DEFAULT DEFAULT6 SPEC-OBJECT VPN DBUS-PATH CON-PATH ZONE MASTER-PATH ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GENERAL ethernet UUID-ethernet-REPLACED-REPLACED-REPL eth0 eth0 deactivating no no -- no /org/freedesktop/NetworkManager/ActiveConnection/1 /org/freedesktop/NetworkManager/Settings/Connection/6 -- -- @@ -11032,12 +11032,12 @@ TYPE: ethernet ------------------------------------------------------------------------------- <<< -size: 7210 +size: 7208 location: src/tests/client/test-client.py:test_003()/222 cmd: $NMCLI --mode multiline --pretty con s ethernet lang: C returncode: 0 -stdout: 7050 bytes +stdout: 7048 bytes >>> =============================================================================== Connection profile details (ethernet) @@ -11144,7 +11144,7 @@ proxy.pac-url: -- proxy.pac-script: -- ------------------------------------------------------------------------------- =============================================================================== - Activate connection details (UUID-ethernet-REPLACED-REPLACED-REPL) + Active connection details (UUID-ethernet-REPLACED-REPLACED-REPL) =============================================================================== GENERAL.NAME: ethernet GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL @@ -11162,7 +11162,7 @@ GENERAL.MASTER-PATH: -- ------------------------------------------------------------------------------- =============================================================================== - Activate connection details (UUID-ethernet-REPLACED-REPLACED-REPL) + Active connection details (UUID-ethernet-REPLACED-REPLACED-REPL) =============================================================================== GENERAL.NAME: ethernet GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL @@ -11328,12 +11328,12 @@ GENERAL.MASTER-PATH: -- ------------------------------------------------------------------------------- <<< -size: 6227 +size: 6226 location: src/tests/client/test-client.py:test_003()/224 cmd: $NMCLI --mode multiline --pretty c s /org/freedesktop/NetworkManager/ActiveConnection/1 lang: C returncode: 0 -stdout: 6027 bytes +stdout: 6026 bytes >>> =============================================================================== Connection profile details (ethernet) @@ -11440,7 +11440,7 @@ proxy.pac-url: -- proxy.pac-script: -- ------------------------------------------------------------------------------- =============================================================================== - Activate connection details (UUID-ethernet-REPLACED-REPLACED-REPL) + Active connection details (UUID-ethernet-REPLACED-REPLACED-REPL) =============================================================================== GENERAL.NAME: ethernet GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL @@ -12064,12 +12064,12 @@ TYPE: ethernet ------------------------------------------------------------------------------- <<< -size: 7222 +size: 7220 location: src/tests/client/test-client.py:test_003()/232 cmd: $NMCLI --mode multiline --pretty --color yes con s ethernet lang: C returncode: 0 -stdout: 7050 bytes +stdout: 7048 bytes >>> =============================================================================== Connection profile details (ethernet) @@ -12176,7 +12176,7 @@ proxy.pac-url: -- proxy.pac-script: -- ------------------------------------------------------------------------------- =============================================================================== - Activate connection details (UUID-ethernet-REPLACED-REPLACED-REPL) + Active connection details (UUID-ethernet-REPLACED-REPLACED-REPL) =============================================================================== GENERAL.NAME: ethernet GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL @@ -12194,7 +12194,7 @@ GENERAL.MASTER-PATH: -- ------------------------------------------------------------------------------- =============================================================================== - Activate connection details (UUID-ethernet-REPLACED-REPLACED-REPL) + Active connection details (UUID-ethernet-REPLACED-REPLACED-REPL) =============================================================================== GENERAL.NAME: ethernet GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL @@ -12360,12 +12360,12 @@ GENERAL.MASTER-PATH: -- ------------------------------------------------------------------------------- <<< -size: 6239 +size: 6238 location: src/tests/client/test-client.py:test_003()/234 cmd: $NMCLI --mode multiline --pretty --color yes c s /org/freedesktop/NetworkManager/ActiveConnection/1 lang: C returncode: 0 -stdout: 6027 bytes +stdout: 6026 bytes >>> =============================================================================== Connection profile details (ethernet) @@ -12472,7 +12472,7 @@ proxy.pac-url: -- proxy.pac-script: -- ------------------------------------------------------------------------------- =============================================================================== - Activate connection details (UUID-ethernet-REPLACED-REPLACED-REPL) + Active connection details (UUID-ethernet-REPLACED-REPLACED-REPL) =============================================================================== GENERAL.NAME: ethernet GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL @@ -15260,18 +15260,18 @@ stderr: 58 bytes Błąd: ethernet — nie ma takiego profilu połączenia. <<< -size: 1421 +size: 1420 location: src/tests/client/test-client.py:test_003()/284 cmd: $NMCLI --pretty c s /org/freedesktop/NetworkManager/ActiveConnection/1 lang: C returncode: 0 -stdout: 1238 bytes +stdout: 1237 bytes >>> =============================================================================== Connection profile details =============================================================================== =============================================================================== - Activate connection details (UUID-ethernet-REPLACED-REPLACED-REPL) + Active connection details (UUID-ethernet-REPLACED-REPLACED-REPL) =============================================================================== GENERAL.NAME: ethernet GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL @@ -15586,18 +15586,18 @@ stderr: 58 bytes Błąd: ethernet — nie ma takiego profilu połączenia. <<< -size: 1433 +size: 1432 location: src/tests/client/test-client.py:test_003()/294 cmd: $NMCLI --pretty --color yes c s /org/freedesktop/NetworkManager/ActiveConnection/1 lang: C returncode: 0 -stdout: 1238 bytes +stdout: 1237 bytes >>> =============================================================================== Connection profile details =============================================================================== =============================================================================== - Activate connection details (UUID-ethernet-REPLACED-REPLACED-REPL) + Active connection details (UUID-ethernet-REPLACED-REPLACED-REPL) =============================================================================== GENERAL.NAME: ethernet GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL @@ -16804,19 +16804,19 @@ stderr: 58 bytes Błąd: ethernet — nie ma takiego profilu połączenia. <<< -size: 1261 +size: 1255 location: src/tests/client/test-client.py:test_003()/344 cmd: $NMCLI --mode tabular --pretty c s /org/freedesktop/NetworkManager/ActiveConnection/1 lang: C returncode: 0 -stdout: 1063 bytes +stdout: 1057 bytes >>> ============================== Connection profile details ============================== -====================================================================== - Activate connection details (UUID-ethernet-REPLACED-REPLACED-REPL) -====================================================================== +==================================================================== + Active connection details (UUID-ethernet-REPLACED-REPLACED-REPL) +==================================================================== GROUP NAME UUID DEVICES IP-IFACE STATE DEFAULT DEFAULT6 SPEC-OBJECT VPN DBUS-PATH CON-PATH ZONE MASTER-PATH ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GENERAL ethernet UUID-ethernet-REPLACED-REPLACED-REPL eth0 eth0 deactivating no no -- no /org/freedesktop/NetworkManager/ActiveConnection/1 /org/freedesktop/NetworkManager/Settings/Connection/6 -- -- @@ -17036,19 +17036,19 @@ stderr: 58 bytes Błąd: ethernet — nie ma takiego profilu połączenia. <<< -size: 1273 +size: 1267 location: src/tests/client/test-client.py:test_003()/354 cmd: $NMCLI --mode tabular --pretty --color yes c s /org/freedesktop/NetworkManager/ActiveConnection/1 lang: C returncode: 0 -stdout: 1063 bytes +stdout: 1057 bytes >>> ============================== Connection profile details ============================== -====================================================================== - Activate connection details (UUID-ethernet-REPLACED-REPLACED-REPL) -====================================================================== +==================================================================== + Active connection details (UUID-ethernet-REPLACED-REPLACED-REPL) +==================================================================== GROUP NAME UUID DEVICES IP-IFACE STATE DEFAULT DEFAULT6 SPEC-OBJECT VPN DBUS-PATH CON-PATH ZONE MASTER-PATH ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GENERAL ethernet UUID-ethernet-REPLACED-REPLACED-REPL eth0 eth0 deactivating no no -- no /org/freedesktop/NetworkManager/ActiveConnection/1 /org/freedesktop/NetworkManager/Settings/Connection/6 -- -- @@ -18710,18 +18710,18 @@ stderr: 58 bytes Błąd: ethernet — nie ma takiego profilu połączenia. <<< -size: 1438 +size: 1437 location: src/tests/client/test-client.py:test_003()/404 cmd: $NMCLI --mode multiline --pretty c s /org/freedesktop/NetworkManager/ActiveConnection/1 lang: C returncode: 0 -stdout: 1238 bytes +stdout: 1237 bytes >>> =============================================================================== Connection profile details =============================================================================== =============================================================================== - Activate connection details (UUID-ethernet-REPLACED-REPLACED-REPL) + Active connection details (UUID-ethernet-REPLACED-REPLACED-REPL) =============================================================================== GENERAL.NAME: ethernet GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL @@ -19258,18 +19258,18 @@ stderr: 58 bytes Błąd: ethernet — nie ma takiego profilu połączenia. <<< -size: 1450 +size: 1449 location: src/tests/client/test-client.py:test_003()/414 cmd: $NMCLI --mode multiline --pretty --color yes c s /org/freedesktop/NetworkManager/ActiveConnection/1 lang: C returncode: 0 -stdout: 1238 bytes +stdout: 1237 bytes >>> =============================================================================== Connection profile details =============================================================================== =============================================================================== - Activate connection details (UUID-ethernet-REPLACED-REPLACED-REPL) + Active connection details (UUID-ethernet-REPLACED-REPLACED-REPL) =============================================================================== GENERAL.NAME: ethernet GENERAL.UUID: UUID-ethernet-REPLACED-REPLACED-REPL diff --git a/src/tests/client/test-client.check-on-disk/test_004.expected b/src/tests/client/test-client.check-on-disk/test_004.expected index 25d4f424..ca8af006 100644 --- a/src/tests/client/test-client.check-on-disk/test_004.expected +++ b/src/tests/client/test-client.check-on-disk/test_004.expected @@ -7398,12 +7398,12 @@ connection.type: 802-11-wireless connection.interface-name: -- <<< -size: 6335 +size: 6334 location: src/tests/client/test-client.py:test_004()/125 cmd: $NMCLI --pretty con s con-vpn-1 lang: C returncode: 0 -stdout: 6191 bytes +stdout: 6190 bytes >>> =============================================================================== Connection profile details (con-vpn-1) @@ -7501,7 +7501,7 @@ proxy.pac-url: -- proxy.pac-script: -- ------------------------------------------------------------------------------- =============================================================================== - Activate connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) + Active connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) =============================================================================== GENERAL.NAME: con-vpn-1 GENERAL.UUID: UUID-con-vpn-1-REPLACED-REPLACED-REP @@ -7658,12 +7658,12 @@ VPN.CFG[3]: key3 = val3 ------------------------------------------------------------------------------- <<< -size: 6335 +size: 6334 location: src/tests/client/test-client.py:test_004()/127 cmd: $NMCLI --pretty con s con-vpn-1 lang: C returncode: 0 -stdout: 6191 bytes +stdout: 6190 bytes >>> =============================================================================== Connection profile details (con-vpn-1) @@ -7761,7 +7761,7 @@ proxy.pac-url: -- proxy.pac-script: -- ------------------------------------------------------------------------------- =============================================================================== - Activate connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) + Active connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) =============================================================================== GENERAL.NAME: con-vpn-1 GENERAL.UUID: UUID-con-vpn-1-REPLACED-REPLACED-REP @@ -8164,15 +8164,15 @@ vpn.timeout: 0 ------------------------------------------------------------------------------- <<< -size: 1181 +size: 1180 location: src/tests/client/test-client.py:test_004()/133 cmd: $NMCLI --pretty -f GENERAL con s con-vpn-1 lang: C returncode: 0 -stdout: 1026 bytes +stdout: 1025 bytes >>> =============================================================================== - Activate connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) + Active connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) =============================================================================== GENERAL.NAME: con-vpn-1 GENERAL.UUID: UUID-con-vpn-1-REPLACED-REPLACED-REP @@ -11324,12 +11324,12 @@ connection.interface-name: -- ------------------------------------------------------------------------------- <<< -size: 6347 +size: 6346 location: src/tests/client/test-client.py:test_004()/175 cmd: $NMCLI --pretty --color yes con s con-vpn-1 lang: C returncode: 0 -stdout: 6191 bytes +stdout: 6190 bytes >>> =============================================================================== Connection profile details (con-vpn-1) @@ -11427,7 +11427,7 @@ proxy.pac-url: -- proxy.pac-script: -- ------------------------------------------------------------------------------- =============================================================================== - Activate connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) + Active connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) =============================================================================== GENERAL.NAME: con-vpn-1 GENERAL.UUID: UUID-con-vpn-1-REPLACED-REPLACED-REP @@ -11584,12 +11584,12 @@ VPN.CFG[3]: key3 = val3 ------------------------------------------------------------------------------- <<< -size: 6347 +size: 6346 location: src/tests/client/test-client.py:test_004()/177 cmd: $NMCLI --pretty --color yes con s con-vpn-1 lang: C returncode: 0 -stdout: 6191 bytes +stdout: 6190 bytes >>> =============================================================================== Connection profile details (con-vpn-1) @@ -11687,7 +11687,7 @@ proxy.pac-url: -- proxy.pac-script: -- ------------------------------------------------------------------------------- =============================================================================== - Activate connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) + Active connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) =============================================================================== GENERAL.NAME: con-vpn-1 GENERAL.UUID: UUID-con-vpn-1-REPLACED-REPLACED-REP @@ -12090,15 +12090,15 @@ vpn.timeout: 0 ------------------------------------------------------------------------------- <<< -size: 1193 +size: 1192 location: src/tests/client/test-client.py:test_004()/183 cmd: $NMCLI --pretty --color yes -f GENERAL con s con-vpn-1 lang: C returncode: 0 -stdout: 1026 bytes +stdout: 1025 bytes >>> =============================================================================== - Activate connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) + Active connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) =============================================================================== GENERAL.NAME: con-vpn-1 GENERAL.UUID: UUID-con-vpn-1-REPLACED-REPLACED-REP @@ -25006,12 +25006,12 @@ interface-name <<< -size: 5499 +size: 5493 location: src/tests/client/test-client.py:test_004()/425 cmd: $NMCLI --mode tabular --pretty con s con-vpn-1 lang: C returncode: 0 -stdout: 5340 bytes +stdout: 5334 bytes >>> ========================================== Connection profile details (con-vpn-1) @@ -25036,9 +25036,9 @@ name method browser-only pac-url pac-script -------------------------------------------------- proxy none no -- -- -====================================================================== - Activate connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) -====================================================================== +==================================================================== + Active connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) +==================================================================== GROUP NAME UUID DEVICES IP-IFACE STATE DEFAULT DEFAULT6 SPEC-OBJECT VPN DBUS-PATH CON-PATH ZONE MASTER-PATH ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GENERAL con-vpn-1 UUID-con-vpn-1-REPLACED-REPLACED-REP wlan0 wlan0 activated no no -- yes /org/freedesktop/NetworkManager/ActiveConnection/2 /org/freedesktop/NetworkManager/Settings/Connection/3 -- -- @@ -25090,12 +25090,12 @@ NAME TYPE USERNAME GATEWAY BANNER VPN-STATE VPN openvpn -- -- *** VPN connection con-vpn-1 *** 5 — Połączono z VPN key1 = val1 | key2 = val2 | key3 = val3 <<< -size: 5499 +size: 5493 location: src/tests/client/test-client.py:test_004()/427 cmd: $NMCLI --mode tabular --pretty con s con-vpn-1 lang: C returncode: 0 -stdout: 5340 bytes +stdout: 5334 bytes >>> ========================================== Connection profile details (con-vpn-1) @@ -25120,9 +25120,9 @@ name method browser-only pac-url pac-script -------------------------------------------------- proxy none no -- -- -====================================================================== - Activate connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) -====================================================================== +==================================================================== + Active connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) +==================================================================== GROUP NAME UUID DEVICES IP-IFACE STATE DEFAULT DEFAULT6 SPEC-OBJECT VPN DBUS-PATH CON-PATH ZONE MASTER-PATH ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GENERAL con-vpn-1 UUID-con-vpn-1-REPLACED-REPLACED-REP wlan0 wlan0 activated no no -- yes /org/freedesktop/NetworkManager/ActiveConnection/2 /org/freedesktop/NetworkManager/Settings/Connection/3 -- -- @@ -25268,16 +25268,16 @@ name service-type user-name data vpn org.freedesktop.NetworkManager.openvpn -- key1 = val1, key2 = val2, key3 = val3 nie 0 <<< -size: 1134 +size: 1128 location: src/tests/client/test-client.py:test_004()/433 cmd: $NMCLI --mode tabular --pretty -f GENERAL con s con-vpn-1 lang: C returncode: 0 -stdout: 965 bytes +stdout: 959 bytes >>> -====================================================================== - Activate connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) -====================================================================== +==================================================================== + Active connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) +==================================================================== GROUP NAME UUID DEVICES IP-IFACE STATE DEFAULT DEFAULT6 SPEC-OBJECT VPN DBUS-PATH CON-PATH ZONE MASTER-PATH ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GENERAL con-vpn-1 UUID-con-vpn-1-REPLACED-REPLACED-REP wlan0 wlan0 activated no no -- yes /org/freedesktop/NetworkManager/ActiveConnection/2 /org/freedesktop/NetworkManager/Settings/Connection/3 -- -- @@ -27314,12 +27314,12 @@ interface-name <<< -size: 5511 +size: 5505 location: src/tests/client/test-client.py:test_004()/475 cmd: $NMCLI --mode tabular --pretty --color yes con s con-vpn-1 lang: C returncode: 0 -stdout: 5340 bytes +stdout: 5334 bytes >>> ========================================== Connection profile details (con-vpn-1) @@ -27344,9 +27344,9 @@ name method browser-only pac-url pac-script -------------------------------------------------- proxy none no -- -- -====================================================================== - Activate connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) -====================================================================== +==================================================================== + Active connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) +==================================================================== GROUP NAME UUID DEVICES IP-IFACE STATE DEFAULT DEFAULT6 SPEC-OBJECT VPN DBUS-PATH CON-PATH ZONE MASTER-PATH ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GENERAL con-vpn-1 UUID-con-vpn-1-REPLACED-REPLACED-REP wlan0 wlan0 activated no no -- yes /org/freedesktop/NetworkManager/ActiveConnection/2 /org/freedesktop/NetworkManager/Settings/Connection/3 -- -- @@ -27398,12 +27398,12 @@ NAME TYPE USERNAME GATEWAY BANNER VPN-STATE VPN openvpn -- -- *** VPN connection con-vpn-1 *** 5 — Połączono z VPN key1 = val1 | key2 = val2 | key3 = val3 <<< -size: 5511 +size: 5505 location: src/tests/client/test-client.py:test_004()/477 cmd: $NMCLI --mode tabular --pretty --color yes con s con-vpn-1 lang: C returncode: 0 -stdout: 5340 bytes +stdout: 5334 bytes >>> ========================================== Connection profile details (con-vpn-1) @@ -27428,9 +27428,9 @@ name method browser-only pac-url pac-script -------------------------------------------------- proxy none no -- -- -====================================================================== - Activate connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) -====================================================================== +==================================================================== + Active connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) +==================================================================== GROUP NAME UUID DEVICES IP-IFACE STATE DEFAULT DEFAULT6 SPEC-OBJECT VPN DBUS-PATH CON-PATH ZONE MASTER-PATH ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GENERAL con-vpn-1 UUID-con-vpn-1-REPLACED-REPLACED-REP wlan0 wlan0 activated no no -- yes /org/freedesktop/NetworkManager/ActiveConnection/2 /org/freedesktop/NetworkManager/Settings/Connection/3 -- -- @@ -27576,16 +27576,16 @@ name service-type user-name data vpn org.freedesktop.NetworkManager.openvpn -- key1 = val1, key2 = val2, key3 = val3 nie 0 <<< -size: 1146 +size: 1140 location: src/tests/client/test-client.py:test_004()/483 cmd: $NMCLI --mode tabular --pretty --color yes -f GENERAL con s con-vpn-1 lang: C returncode: 0 -stdout: 965 bytes +stdout: 959 bytes >>> -====================================================================== - Activate connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) -====================================================================== +==================================================================== + Active connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) +==================================================================== GROUP NAME UUID DEVICES IP-IFACE STATE DEFAULT DEFAULT6 SPEC-OBJECT VPN DBUS-PATH CON-PATH ZONE MASTER-PATH ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GENERAL con-vpn-1 UUID-con-vpn-1-REPLACED-REPLACED-REP wlan0 wlan0 activated no no -- yes /org/freedesktop/NetworkManager/ActiveConnection/2 /org/freedesktop/NetworkManager/Settings/Connection/3 -- -- @@ -39006,12 +39006,12 @@ connection.type: 802-11-wireless connection.interface-name: -- <<< -size: 6352 +size: 6351 location: src/tests/client/test-client.py:test_004()/725 cmd: $NMCLI --mode multiline --pretty con s con-vpn-1 lang: C returncode: 0 -stdout: 6191 bytes +stdout: 6190 bytes >>> =============================================================================== Connection profile details (con-vpn-1) @@ -39109,7 +39109,7 @@ proxy.pac-url: -- proxy.pac-script: -- ------------------------------------------------------------------------------- =============================================================================== - Activate connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) + Active connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) =============================================================================== GENERAL.NAME: con-vpn-1 GENERAL.UUID: UUID-con-vpn-1-REPLACED-REPLACED-REP @@ -39266,12 +39266,12 @@ VPN.CFG[3]: key3 = val3 ------------------------------------------------------------------------------- <<< -size: 6352 +size: 6351 location: src/tests/client/test-client.py:test_004()/727 cmd: $NMCLI --mode multiline --pretty con s con-vpn-1 lang: C returncode: 0 -stdout: 6191 bytes +stdout: 6190 bytes >>> =============================================================================== Connection profile details (con-vpn-1) @@ -39369,7 +39369,7 @@ proxy.pac-url: -- proxy.pac-script: -- ------------------------------------------------------------------------------- =============================================================================== - Activate connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) + Active connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) =============================================================================== GENERAL.NAME: con-vpn-1 GENERAL.UUID: UUID-con-vpn-1-REPLACED-REPLACED-REP @@ -39772,15 +39772,15 @@ vpn.timeout: 0 ------------------------------------------------------------------------------- <<< -size: 1198 +size: 1197 location: src/tests/client/test-client.py:test_004()/733 cmd: $NMCLI --mode multiline --pretty -f GENERAL con s con-vpn-1 lang: C returncode: 0 -stdout: 1026 bytes +stdout: 1025 bytes >>> =============================================================================== - Activate connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) + Active connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) =============================================================================== GENERAL.NAME: con-vpn-1 GENERAL.UUID: UUID-con-vpn-1-REPLACED-REPLACED-REP @@ -43462,12 +43462,12 @@ connection.interface-name: -- ------------------------------------------------------------------------------- <<< -size: 6364 +size: 6363 location: src/tests/client/test-client.py:test_004()/775 cmd: $NMCLI --mode multiline --pretty --color yes con s con-vpn-1 lang: C returncode: 0 -stdout: 6191 bytes +stdout: 6190 bytes >>> =============================================================================== Connection profile details (con-vpn-1) @@ -43565,7 +43565,7 @@ proxy.pac-url: -- proxy.pac-script: -- ------------------------------------------------------------------------------- =============================================================================== - Activate connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) + Active connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) =============================================================================== GENERAL.NAME: con-vpn-1 GENERAL.UUID: UUID-con-vpn-1-REPLACED-REPLACED-REP @@ -43722,12 +43722,12 @@ VPN.CFG[3]: key3 = val3 ------------------------------------------------------------------------------- <<< -size: 6364 +size: 6363 location: src/tests/client/test-client.py:test_004()/777 cmd: $NMCLI --mode multiline --pretty --color yes con s con-vpn-1 lang: C returncode: 0 -stdout: 6191 bytes +stdout: 6190 bytes >>> =============================================================================== Connection profile details (con-vpn-1) @@ -43825,7 +43825,7 @@ proxy.pac-url: -- proxy.pac-script: -- ------------------------------------------------------------------------------- =============================================================================== - Activate connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) + Active connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) =============================================================================== GENERAL.NAME: con-vpn-1 GENERAL.UUID: UUID-con-vpn-1-REPLACED-REPLACED-REP @@ -44228,15 +44228,15 @@ vpn.timeout: 0 ------------------------------------------------------------------------------- <<< -size: 1210 +size: 1209 location: src/tests/client/test-client.py:test_004()/783 cmd: $NMCLI --mode multiline --pretty --color yes -f GENERAL con s con-vpn-1 lang: C returncode: 0 -stdout: 1026 bytes +stdout: 1025 bytes >>> =============================================================================== - Activate connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) + Active connection details (UUID-con-vpn-1-REPLACED-REPLACED-REP) =============================================================================== GENERAL.NAME: con-vpn-1 GENERAL.UUID: UUID-con-vpn-1-REPLACED-REPLACED-REP -- cgit 1.3.0-6-gf8a5