From 9d6a2e6f0ff62dd716bb47e35d3ae062e316f953 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Thu, 9 Apr 2015 15:23:50 +0200 Subject: [PATCH 1/7] systemd: ensure every file includes 'nm-sd-adapt.h' first --- src/systemd/src/libsystemd-network/ipv4ll-internal.h | 2 ++ src/systemd/src/libsystemd-network/ipv4ll-network.c | 2 ++ src/systemd/src/libsystemd-network/ipv4ll-packet.c | 3 +++ src/systemd/src/libsystemd-network/sd-ipv4ll.c | 2 ++ src/systemd/src/systemd/sd-ipv4ll.h | 2 ++ 5 files changed, 11 insertions(+) diff --git a/src/systemd/src/libsystemd-network/ipv4ll-internal.h b/src/systemd/src/libsystemd-network/ipv4ll-internal.h index ae0ce43985..3a0668fab4 100644 --- a/src/systemd/src/libsystemd-network/ipv4ll-internal.h +++ b/src/systemd/src/libsystemd-network/ipv4ll-internal.h @@ -21,6 +21,8 @@ along with systemd; If not, see . ***/ +#include "nm-sd-adapt.h" + #include #include "sparse-endian.h" diff --git a/src/systemd/src/libsystemd-network/ipv4ll-network.c b/src/systemd/src/libsystemd-network/ipv4ll-network.c index 93ffed408f..de1e9ddfd4 100644 --- a/src/systemd/src/libsystemd-network/ipv4ll-network.c +++ b/src/systemd/src/libsystemd-network/ipv4ll-network.c @@ -17,6 +17,8 @@ along with systemd; If not, see . ***/ +#include "nm-sd-adapt.h" + #include #include "util.h" diff --git a/src/systemd/src/libsystemd-network/ipv4ll-packet.c b/src/systemd/src/libsystemd-network/ipv4ll-packet.c index 2b6c73ab4b..5e89a119b0 100644 --- a/src/systemd/src/libsystemd-network/ipv4ll-packet.c +++ b/src/systemd/src/libsystemd-network/ipv4ll-packet.c @@ -16,6 +16,9 @@ You should have received a copy of the GNU Lesser General Public License along with systemd; If not, see . ***/ + +#include "nm-sd-adapt.h" + #include #include "util.h" diff --git a/src/systemd/src/libsystemd-network/sd-ipv4ll.c b/src/systemd/src/libsystemd-network/sd-ipv4ll.c index 02f2f9e0a9..ccd6bdf0b0 100644 --- a/src/systemd/src/libsystemd-network/sd-ipv4ll.c +++ b/src/systemd/src/libsystemd-network/sd-ipv4ll.c @@ -17,6 +17,8 @@ along with systemd; If not, see . ***/ +#include "nm-sd-adapt.h" + #include #include #include diff --git a/src/systemd/src/systemd/sd-ipv4ll.h b/src/systemd/src/systemd/sd-ipv4ll.h index d017158154..10725a1184 100644 --- a/src/systemd/src/systemd/sd-ipv4ll.h +++ b/src/systemd/src/systemd/sd-ipv4ll.h @@ -22,6 +22,8 @@ along with systemd; If not, see . ***/ +#include "nm-sd-adapt.h" + #include #include #include From 7a7f280ef3dd567b8d3004e1990f04cf113662b8 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 8 Apr 2015 14:00:11 +0200 Subject: [PATCH 2/7] device/trivial: rename 'aipd' and 'autoip4' to 'ipv4ll' --- src/devices/nm-device.c | 82 ++++++++++++++++++++--------------------- src/devices/nm-device.h | 6 +-- src/nm-manager.c | 2 +- 3 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index a10ff18469..32c0b07b0b 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -279,10 +279,10 @@ typedef struct { /* Firewall */ NMFirewallPendingCall fw_call; - /* avahi-autoipd stuff */ - GPid aipd_pid; - guint aipd_watch; - guint aipd_timeout; + /* IPv4LL stuff */ + GPid ipv4ll_pid; + guint ipv4ll_watch; + guint ipv4ll_timeout; /* IP6 configuration info */ NMIP6Config * ip6_config; @@ -2696,39 +2696,39 @@ nm_device_activate_schedule_stage2_device_config (NMDevice *self) } /*********************************************/ -/* avahi-autoipd stuff */ +/* IPv4LL stuff */ static void -aipd_timeout_remove (NMDevice *self) +ipv4ll_timeout_remove (NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - if (priv->aipd_timeout) { - g_source_remove (priv->aipd_timeout); - priv->aipd_timeout = 0; + if (priv->ipv4ll_timeout) { + g_source_remove (priv->ipv4ll_timeout); + priv->ipv4ll_timeout = 0; } } static void -aipd_cleanup (NMDevice *self) +ipv4ll_cleanup (NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - if (priv->aipd_watch) { - g_source_remove (priv->aipd_watch); - priv->aipd_watch = 0; + if (priv->ipv4ll_watch) { + g_source_remove (priv->ipv4ll_watch); + priv->ipv4ll_watch = 0; } - if (priv->aipd_pid > 0) { - nm_utils_kill_child_sync (priv->aipd_pid, SIGKILL, LOGD_AUTOIP4, "avahi-autoipd", NULL, 0, 0); - priv->aipd_pid = -1; + if (priv->ipv4ll_pid > 0) { + nm_utils_kill_child_sync (priv->ipv4ll_pid, SIGKILL, LOGD_AUTOIP4, "avahi-autoipd", NULL, 0, 0); + priv->ipv4ll_pid = -1; } - aipd_timeout_remove (self); + ipv4ll_timeout_remove (self); } static NMIP4Config * -aipd_get_ip4_config (NMDevice *self, guint32 lla) +ipv4ll_get_ip4_config (NMDevice *self, guint32 lla) { NMIP4Config *config = NULL; NMPlatformIP4Address address; @@ -2758,9 +2758,9 @@ aipd_get_ip4_config (NMDevice *self, guint32 lla) #define IPV4LL_NETMASK (htonl (0xFFFF0000L)) void -nm_device_handle_autoip4_event (NMDevice *self, - const char *event, - const char *address) +nm_device_handle_ipv4ll_event (NMDevice *self, + const char *event, + const char *address) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMConnection *connection = NULL; @@ -2796,15 +2796,15 @@ nm_device_handle_autoip4_event (NMDevice *self, return; } - config = aipd_get_ip4_config (self, lla); + config = ipv4ll_get_ip4_config (self, lla); if (config == NULL) { - _LOGE (LOGD_AUTOIP4, "failed to get autoip config"); + _LOGE (LOGD_AUTOIP4, "failed to get IPv4LL config"); nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); return; } if (priv->ip4_state == IP_CONF) { - aipd_timeout_remove (self); + ipv4ll_timeout_remove (self); nm_device_activate_schedule_ip4_config_result (self, config); } else if (priv->ip4_state == IP_DONE) { if (!ip4_config_merge_and_apply (self, config, TRUE, &reason)) { @@ -2816,7 +2816,7 @@ nm_device_handle_autoip4_event (NMDevice *self, g_object_unref (config); } else { - _LOGW (LOGD_AUTOIP4, "autoip address %s no longer valid because '%s'.", address, event); + _LOGW (LOGD_AUTOIP4, "IPv4LL address %s no longer valid because '%s'.", address, event); /* The address is gone; terminate the connection or fail activation */ nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_IP_CONFIG_EXPIRED); @@ -2824,15 +2824,15 @@ nm_device_handle_autoip4_event (NMDevice *self, } static void -aipd_watch_cb (GPid pid, gint status, gpointer user_data) +ipv4ll_watch_cb (GPid pid, gint status, gpointer user_data) { NMDevice *self = NM_DEVICE (user_data); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMDeviceState state; - if (!priv->aipd_watch) + if (!priv->ipv4ll_watch) return; - priv->aipd_watch = 0; + priv->ipv4ll_watch = 0; if (WIFEXITED (status)) _LOGD (LOGD_AUTOIP4, "avahi-autoipd exited with error code %d", WEXITSTATUS (status)); @@ -2843,7 +2843,7 @@ aipd_watch_cb (GPid pid, gint status, gpointer user_data) else _LOGW (LOGD_AUTOIP4, "avahi-autoipd died from an unknown cause"); - aipd_cleanup (self); + ipv4ll_cleanup (self); state = nm_device_get_state (self); if (nm_device_is_activating (self) || (state == NM_DEVICE_STATE_ACTIVATED)) @@ -2851,15 +2851,15 @@ aipd_watch_cb (GPid pid, gint status, gpointer user_data) } static gboolean -aipd_timeout_cb (gpointer user_data) +ipv4ll_timeout_cb (gpointer user_data) { NMDevice *self = NM_DEVICE (user_data); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - if (priv->aipd_timeout) { + if (priv->ipv4ll_timeout) { _LOGI (LOGD_AUTOIP4, "avahi-autoipd timed out."); - priv->aipd_timeout = 0; - aipd_cleanup (self); + priv->ipv4ll_timeout = 0; + ipv4ll_cleanup (self); if (priv->ip4_state == IP_CONF) nm_device_activate_schedule_ip4_config_timeout (self); @@ -2872,7 +2872,7 @@ aipd_timeout_cb (gpointer user_data) const char *nm_device_autoipd_helper_path = LIBEXECDIR "/nm-avahi-autoipd.action"; static NMActStageReturn -aipd_start (NMDevice *self, NMDeviceStateReason *reason) +ipv4ll_start (NMDevice *self, NMDeviceStateReason *reason) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); const char *argv[6]; @@ -2881,7 +2881,7 @@ aipd_start (NMDevice *self, NMDeviceStateReason *reason) int i = 0; GError *error = NULL; - aipd_cleanup (self); + ipv4ll_cleanup (self); /* Find avahi-autoipd */ aipd_binary = nm_utils_find_helper ("avahi-autoipd", NULL, NULL); @@ -2907,13 +2907,13 @@ aipd_start (NMDevice *self, NMDeviceStateReason *reason) g_free (cmdline); if (!g_spawn_async ("/", (char **) argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, - nm_utils_setpgid, NULL, &(priv->aipd_pid), &error)) { + nm_utils_setpgid, NULL, &(priv->ipv4ll_pid), &error)) { _LOGW (LOGD_DEVICE | LOGD_AUTOIP4, "Activation: Stage 3 of 5 (IP Configure Start) failed" " to start avahi-autoipd: %s", error && error->message ? error->message : "(unknown)"); g_clear_error (&error); - aipd_cleanup (self); + ipv4ll_cleanup (self); return NM_ACT_STAGE_RETURN_FAILURE; } @@ -2922,10 +2922,10 @@ aipd_start (NMDevice *self, NMDeviceStateReason *reason) " avahi-autoipd..."); /* Monitor the child process so we know when it dies */ - priv->aipd_watch = g_child_watch_add (priv->aipd_pid, aipd_watch_cb, self); + priv->ipv4ll_watch = g_child_watch_add (priv->ipv4ll_pid, ipv4ll_watch_cb, self); /* Start a timeout to bound the address attempt */ - priv->aipd_timeout = g_timeout_add_seconds (20, aipd_timeout_cb, self); + priv->ipv4ll_timeout = g_timeout_add_seconds (20, ipv4ll_timeout_cb, self); return NM_ACT_STAGE_RETURN_POSTPONE; } @@ -3574,7 +3574,7 @@ act_stage3_ip4_config_start (NMDevice *self, if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0) ret = dhcp4_start (self, connection, reason); else if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL) == 0) - ret = aipd_start (self, reason); + ret = ipv4ll_start (self, reason); else if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0) { /* Use only IPv4 config from the connection data */ *out_config = nm_ip4_config_new (nm_device_get_ip_ifindex (self)); @@ -7518,7 +7518,7 @@ _cleanup_ip_pre (NMDevice *self, gboolean deconfigure) linklocal6_cleanup (self); addrconf6_cleanup (self); dnsmasq_cleanup (self); - aipd_cleanup (self); + ipv4ll_cleanup (self); } static void diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 218faa4fa1..1485b81960 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -394,9 +394,9 @@ gboolean nm_device_has_capability (NMDevice *self, NMDeviceCapabilities caps); gboolean nm_device_get_autoconnect (NMDevice *device); -void nm_device_handle_autoip4_event (NMDevice *self, - const char *event, - const char *address); +void nm_device_handle_ipv4ll_event (NMDevice *self, + const char *event, + const char *address); void nm_device_state_changed (NMDevice *device, NMDeviceState state, diff --git a/src/nm-manager.c b/src/nm-manager.c index 848ccd26bf..f9ccdb6334 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -850,7 +850,7 @@ aipd_handle_event (GDBusProxy *proxy, NMDevice *candidate = NM_DEVICE (iter->data); if (!strcmp (nm_device_get_iface (candidate), iface)) { - nm_device_handle_autoip4_event (candidate, event, address); + nm_device_handle_ipv4ll_event (candidate, event, address); handled = TRUE; break; } From 33d4232c3d66d865052493443c4315bfc62005eb Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 20 Apr 2015 22:13:41 +0200 Subject: [PATCH 3/7] device/trivial: move nm_device_check_ip_failed() Move nm_device_check_ip_failed() upwards as it will be used by IPv4LL code. --- src/devices/nm-device.c | 72 ++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 32c0b07b0b..826c417f42 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -2695,6 +2695,42 @@ nm_device_activate_schedule_stage2_device_config (NMDevice *self) _LOGD (LOGD_DEVICE, "Activation: Stage 2 of 5 (Device Configure) scheduled..."); } +/* + * nm_device_check_ip_failed + * + * Progress the device to appropriate state if both IPv4 and IPv6 failed + */ +static void +nm_device_check_ip_failed (NMDevice *self, gboolean may_fail) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); + NMDeviceState state; + + if ( priv->ip4_state != IP_FAIL + || priv->ip6_state != IP_FAIL) + return; + + if (nm_device_uses_assumed_connection (self)) { + /* We have assumed configuration, but couldn't + * redo it. No problem, move to check state. */ + priv->ip4_state = priv->ip6_state = IP_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; + } + + nm_device_state_changed (self, + state, + NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); +} + /*********************************************/ /* IPv4LL stuff */ @@ -4906,42 +4942,6 @@ nm_device_activate_stage3_ip6_start (NMDevice *self) return TRUE; } -/* - * nm_device_check_ip_failed - * - * Progress the device to appropriate state if both IPv4 and IPv6 failed - */ -static void -nm_device_check_ip_failed (NMDevice *self, gboolean may_fail) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - NMDeviceState state; - - if ( priv->ip4_state != IP_FAIL - || priv->ip6_state != IP_FAIL) - return; - - if (nm_device_uses_assumed_connection (self)) { - /* We have assumed configuration, but couldn't - * redo it. No problem, move to check state. */ - priv->ip4_state = priv->ip6_state = IP_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; - } - - nm_device_state_changed (self, - state, - NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); -} - /* * nm_device_activate_stage3_ip_config_start * From c6302f32273200ddba486069ef329e175e6b45e1 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Tue, 21 Apr 2015 08:51:55 +0200 Subject: [PATCH 4/7] device: fix device state transition after IPv4LL failure Don't terminate the entire connection if IPv4LL configuration fails but instead call nm_device_check_ip_failed() to check the result of IPv6 as well. --- src/devices/nm-device.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 826c417f42..7145044599 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -2801,7 +2801,6 @@ nm_device_handle_ipv4ll_event (NMDevice *self, NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMConnection *connection = NULL; const char *method; - NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE; g_return_if_fail (event != NULL); @@ -2822,20 +2821,23 @@ nm_device_handle_ipv4ll_event (NMDevice *self, if (inet_pton (AF_INET, address, &lla) <= 0) { _LOGE (LOGD_AUTOIP4, "invalid address %s received from avahi-autoipd.", address); - nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_AUTOIP_ERROR); + priv->ip4_state = IP_FAIL; + nm_device_check_ip_failed (self, FALSE); return; } if ((lla & IPV4LL_NETMASK) != IPV4LL_NETWORK) { _LOGE (LOGD_AUTOIP4, "invalid address %s received from avahi-autoipd (not link-local).", address); - nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_AUTOIP_ERROR); + priv->ip4_state = IP_FAIL; + nm_device_check_ip_failed (self, FALSE); return; } config = ipv4ll_get_ip4_config (self, lla); if (config == NULL) { _LOGE (LOGD_AUTOIP4, "failed to get IPv4LL config"); - nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); + priv->ip4_state = IP_FAIL; + nm_device_check_ip_failed (self, FALSE); return; } @@ -2843,9 +2845,10 @@ nm_device_handle_ipv4ll_event (NMDevice *self, ipv4ll_timeout_remove (self); nm_device_activate_schedule_ip4_config_result (self, config); } else if (priv->ip4_state == IP_DONE) { - if (!ip4_config_merge_and_apply (self, config, TRUE, &reason)) { + if (!ip4_config_merge_and_apply (self, config, TRUE, NULL)) { _LOGE (LOGD_AUTOIP4, "failed to update IP4 config for autoip change."); - nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, reason); + priv->ip4_state = IP_FAIL; + nm_device_check_ip_failed (self, FALSE); } } else g_assert_not_reached (); @@ -2853,9 +2856,8 @@ nm_device_handle_ipv4ll_event (NMDevice *self, g_object_unref (config); } else { _LOGW (LOGD_AUTOIP4, "IPv4LL address %s no longer valid because '%s'.", address, event); - - /* The address is gone; terminate the connection or fail activation */ - nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_IP_CONFIG_EXPIRED); + priv->ip4_state = IP_FAIL; + nm_device_check_ip_failed (self, FALSE); } } From c029502912f854568d0dbe0f79a9d491101af876 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 20 Apr 2015 18:13:41 +0200 Subject: [PATCH 5/7] ipv4ll: use internal implementation --- man/NetworkManager.conf.xml.in | 2 +- src/Makefile.am | 5 + src/devices/nm-device.c | 170 +++++++++++++----------------- src/devices/nm-device.h | 7 -- src/dhcp-manager/nm-dhcp-dhcpcd.c | 2 +- src/main.c | 1 - src/nm-manager.c | 57 ---------- 7 files changed, 78 insertions(+), 166 deletions(-) diff --git a/man/NetworkManager.conf.xml.in b/man/NetworkManager.conf.xml.in index 7807b1bf9d..054f84202b 100644 --- a/man/NetworkManager.conf.xml.in +++ b/man/NetworkManager.conf.xml.in @@ -401,7 +401,7 @@ unmanaged-devices=mac:00:22:68:1c:59:b1;mac:00:1E:65:30:D1:C4;interface-name:eth WIFI_SCAN : Wi-Fi scanning operations IP4 : IPv4-related operations IP6 : IPv6-related operations - AUTOIP4 : AutoIP (avahi) operations + AUTOIP4 : AutoIP operations DNS : Domain Name System related operations VPN : Virtual Private Network connections and operations SHARING : Connection sharing diff --git a/src/Makefile.am b/src/Makefile.am index 0008351de3..caf688083c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -81,6 +81,10 @@ libsystemd_nm_la_SOURCES = \ systemd/src/libsystemd-network/dhcp6-protocol.h \ systemd/src/libsystemd-network/dhcp-lease-internal.h \ systemd/src/libsystemd-network/sd-dhcp6-client.c \ + systemd/src/libsystemd-network/ipv4ll-internal.h \ + systemd/src/libsystemd-network/sd-ipv4ll.c \ + systemd/src/libsystemd-network/ipv4ll-packet.c \ + systemd/src/libsystemd-network/ipv4ll-network.c \ systemd/src/shared/async.h \ systemd/src/shared/time-util.h \ systemd/src/shared/siphash24.h \ @@ -112,6 +116,7 @@ libsystemd_nm_la_SOURCES = \ systemd/src/systemd/sd-dhcp6-client.h \ systemd/src/systemd/sd-event.h \ systemd/src/systemd/_sd-common.h \ + systemd/src/systemd/sd-ipv4ll.h \ systemd/nm-sd-adapt.h \ systemd/nm-sd-adapt.c diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 7145044599..f764f013d3 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -68,6 +68,7 @@ #include "nm-core-internal.h" #include "nm-default-route-manager.h" #include "nm-route-manager.h" +#include "sd-ipv4ll.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF (NMDevice); @@ -280,9 +281,8 @@ typedef struct { NMFirewallPendingCall fw_call; /* IPv4LL stuff */ - GPid ipv4ll_pid; - guint ipv4ll_watch; - guint ipv4ll_timeout; + sd_ipv4ll * ipv4ll; + guint ipv4ll_timeout; /* IP6 configuration info */ NMIP6Config * ip6_config; @@ -2750,14 +2750,10 @@ ipv4ll_cleanup (NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - if (priv->ipv4ll_watch) { - g_source_remove (priv->ipv4ll_watch); - priv->ipv4ll_watch = 0; - } - - if (priv->ipv4ll_pid > 0) { - nm_utils_kill_child_sync (priv->ipv4ll_pid, SIGKILL, LOGD_AUTOIP4, "avahi-autoipd", NULL, 0, 0); - priv->ipv4ll_pid = -1; + if (priv->ipv4ll) { + sd_ipv4ll_set_callback (priv->ipv4ll, NULL, NULL); + sd_ipv4ll_stop (priv->ipv4ll); + priv->ipv4ll = sd_ipv4ll_unref (priv->ipv4ll); } ipv4ll_timeout_remove (self); @@ -2793,16 +2789,16 @@ ipv4ll_get_ip4_config (NMDevice *self, guint32 lla) #define IPV4LL_NETWORK (htonl (0xA9FE0000L)) #define IPV4LL_NETMASK (htonl (0xFFFF0000L)) -void -nm_device_handle_ipv4ll_event (NMDevice *self, - const char *event, - const char *address) +static void +nm_device_handle_ipv4ll_event (sd_ipv4ll *ll, int event, void *data) { + NMDevice *self = data; NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMConnection *connection = NULL; const char *method; - - g_return_if_fail (event != NULL); + struct in_addr address; + NMIP4Config *config; + int r; if (priv->act_request == NULL) return; @@ -2815,25 +2811,24 @@ nm_device_handle_ipv4ll_event (NMDevice *self, if (g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL) != 0) return; - if (strcmp (event, "BIND") == 0) { - guint32 lla; - NMIP4Config *config; - - if (inet_pton (AF_INET, address, &lla) <= 0) { - _LOGE (LOGD_AUTOIP4, "invalid address %s received from avahi-autoipd.", address); + switch (event) { + case 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); priv->ip4_state = IP_FAIL; nm_device_check_ip_failed (self, FALSE); return; } - if ((lla & IPV4LL_NETMASK) != IPV4LL_NETWORK) { - _LOGE (LOGD_AUTOIP4, "invalid address %s received from avahi-autoipd (not link-local).", address); + if ((address.s_addr & IPV4LL_NETMASK) != IPV4LL_NETWORK) { + _LOGE (LOGD_AUTOIP4, "invalid address %08x received (not link-local).", address.s_addr); priv->ip4_state = IP_FAIL; nm_device_check_ip_failed (self, FALSE); return; } - config = ipv4ll_get_ip4_config (self, lla); + config = ipv4ll_get_ip4_config (self, address.s_addr); if (config == NULL) { _LOGE (LOGD_AUTOIP4, "failed to get IPv4LL config"); priv->ip4_state = IP_FAIL; @@ -2854,40 +2849,14 @@ nm_device_handle_ipv4ll_event (NMDevice *self, g_assert_not_reached (); g_object_unref (config); - } else { - _LOGW (LOGD_AUTOIP4, "IPv4LL address %s no longer valid because '%s'.", address, event); + break; + default: + _LOGW (LOGD_AUTOIP4, "IPv4LL address no longer valid after event %d.", event); priv->ip4_state = IP_FAIL; nm_device_check_ip_failed (self, FALSE); } } -static void -ipv4ll_watch_cb (GPid pid, gint status, gpointer user_data) -{ - NMDevice *self = NM_DEVICE (user_data); - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - NMDeviceState state; - - if (!priv->ipv4ll_watch) - return; - priv->ipv4ll_watch = 0; - - if (WIFEXITED (status)) - _LOGD (LOGD_AUTOIP4, "avahi-autoipd exited with error code %d", WEXITSTATUS (status)); - else if (WIFSTOPPED (status)) - _LOGW (LOGD_AUTOIP4, "avahi-autoipd stopped unexpectedly with signal %d", WSTOPSIG (status)); - else if (WIFSIGNALED (status)) - _LOGW (LOGD_AUTOIP4, "avahi-autoipd died with signal %d", WTERMSIG (status)); - else - _LOGW (LOGD_AUTOIP4, "avahi-autoipd died from an unknown cause"); - - ipv4ll_cleanup (self); - - state = nm_device_get_state (self); - if (nm_device_is_activating (self) || (state == NM_DEVICE_STATE_ACTIVATED)) - nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_AUTOIP_FAILED); -} - static gboolean ipv4ll_timeout_cb (gpointer user_data) { @@ -2895,7 +2864,7 @@ ipv4ll_timeout_cb (gpointer user_data) NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); if (priv->ipv4ll_timeout) { - _LOGI (LOGD_AUTOIP4, "avahi-autoipd timed out."); + _LOGI (LOGD_AUTOIP4, "IPv4LL configuration timed out."); priv->ipv4ll_timeout = 0; ipv4ll_cleanup (self); @@ -2906,66 +2875,69 @@ ipv4ll_timeout_cb (gpointer user_data) return FALSE; } -/* default to installed helper, but can be modified for testing */ -const char *nm_device_autoipd_helper_path = LIBEXECDIR "/nm-avahi-autoipd.action"; - static NMActStageReturn ipv4ll_start (NMDevice *self, NMDeviceStateReason *reason) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - const char *argv[6]; - char *cmdline; - const char *aipd_binary; - int i = 0; - GError *error = NULL; + const struct ether_addr *addr; + int ifindex, r; + size_t addr_len; ipv4ll_cleanup (self); - /* Find avahi-autoipd */ - aipd_binary = nm_utils_find_helper ("avahi-autoipd", NULL, NULL); - if (!aipd_binary) { - _LOGW (LOGD_DEVICE | LOGD_AUTOIP4, - "Activation: Stage 3 of 5 (IP Configure Start) failed" - " to start avahi-autoipd: not found"); - *reason = NM_DEVICE_STATE_REASON_AUTOIP_START_FAILED; - return NM_ACT_STAGE_RETURN_FAILURE; + r = sd_ipv4ll_new (&priv->ipv4ll); + if (r < 0) { + _LOGE (LOGD_AUTOIP4, "IPv4LL: new() failed with error %d", r); + goto fail; } - argv[i++] = aipd_binary; - argv[i++] = "--script"; - argv[i++] = nm_device_autoipd_helper_path; - - if (nm_logging_enabled (LOGL_DEBUG, LOGD_AUTOIP4)) - argv[i++] = "--debug"; - argv[i++] = nm_device_get_ip_iface (self); - argv[i++] = NULL; - - cmdline = g_strjoinv (" ", (char **) argv); - _LOGD (LOGD_AUTOIP4, "running: %s", cmdline); - g_free (cmdline); - - if (!g_spawn_async ("/", (char **) argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, - nm_utils_setpgid, NULL, &(priv->ipv4ll_pid), &error)) { - _LOGW (LOGD_DEVICE | LOGD_AUTOIP4, - "Activation: Stage 3 of 5 (IP Configure Start) failed" - " to start avahi-autoipd: %s", - error && error->message ? error->message : "(unknown)"); - g_clear_error (&error); - ipv4ll_cleanup (self); - 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); + goto fail; } - _LOGD (LOGD_DEVICE | LOGD_AUTOIP4, - "Activation: Stage 3 of 5 (IP Configure Start) started" - " avahi-autoipd..."); + ifindex = nm_device_get_ip_ifindex (self); + addr = nm_platform_link_get_address (NM_PLATFORM_GET, ifindex, &addr_len); + if (!addr || addr_len != ETH_ALEN) { + _LOGE (LOGD_AUTOIP4, "IPv4LL: can't retrieve hardware address"); + goto fail; + } - /* Monitor the child process so we know when it dies */ - priv->ipv4ll_watch = g_child_watch_add (priv->ipv4ll_pid, ipv4ll_watch_cb, self); + r = sd_ipv4ll_set_mac (priv->ipv4ll, addr); + if (r < 0) { + _LOGE (LOGD_AUTOIP4, "IPv4LL: set_mac() failed with error %d", r); + goto fail; + } + + r = sd_ipv4ll_set_index (priv->ipv4ll, ifindex); + if (r < 0) { + _LOGE (LOGD_AUTOIP4, "IPv4LL: set_index() failed with error %d", r); + goto fail; + } + + 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); + goto fail; + } + + r = sd_ipv4ll_start (priv->ipv4ll); + if (r < 0) { + _LOGE (LOGD_AUTOIP4, "IPv4LL: start() failed with error %d", r); + goto fail; + } + + _LOGI (LOGD_DEVICE | LOGD_AUTOIP4, + "Activation: Stage 3 of 5 (IP Configure Start) IPv4LL started"); /* 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; +fail: + *reason = NM_DEVICE_STATE_REASON_AUTOIP_START_FAILED; + return NM_ACT_STAGE_RETURN_FAILURE; } /*********************************************/ diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 1485b81960..ad79376f47 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -394,10 +394,6 @@ gboolean nm_device_has_capability (NMDevice *self, NMDeviceCapabilities caps); gboolean nm_device_get_autoconnect (NMDevice *device); -void nm_device_handle_ipv4ll_event (NMDevice *self, - const char *event, - const char *address); - void nm_device_state_changed (NMDevice *device, NMDeviceState state, NMDeviceStateReason reason); @@ -442,7 +438,4 @@ void nm_device_spawn_iface_helper (NMDevice *self); G_END_DECLS -/* For testing only */ -extern const char* nm_device_autoipd_helper_path; - #endif /* NM_DEVICE_H */ diff --git a/src/dhcp-manager/nm-dhcp-dhcpcd.c b/src/dhcp-manager/nm-dhcp-dhcpcd.c index 86aba4dac1..bea89dc981 100644 --- a/src/dhcp-manager/nm-dhcp-dhcpcd.c +++ b/src/dhcp-manager/nm-dhcp-dhcpcd.c @@ -95,7 +95,7 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last g_ptr_array_add (argv, (gpointer) "-K"); /* Disable built-in carrier detection */ - g_ptr_array_add (argv, (gpointer) "-L"); /* Disable built-in IPv4LL since we use avahi-autoipd */ + g_ptr_array_add (argv, (gpointer) "-L"); /* Disable built-in IPv4LL */ /* --noarp. Don't request or claim the address by ARP; this also disables IPv4LL. */ g_ptr_array_add (argv, (gpointer) "-A"); diff --git a/src/main.c b/src/main.c index a5851dc558..49f0cd1d33 100644 --- a/src/main.c +++ b/src/main.c @@ -323,7 +323,6 @@ main (int argc, char *argv[]) /* don't free these strings, we need them for the entire * process lifetime */ nm_dhcp_helper_path = g_strdup_printf ("%s/src/dhcp-manager/nm-dhcp-helper", path); - nm_device_autoipd_helper_path = g_strdup_printf ("%s/callouts/nm-avahi-autoipd.action", path); g_free (path); } diff --git a/src/nm-manager.c b/src/nm-manager.c index f9ccdb6334..4a7c1f9aa2 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -59,9 +59,6 @@ #include "nm-core-internal.h" #include "nm-config.h" -#define NM_AUTOIP_DBUS_SERVICE "org.freedesktop.nm_avahi_autoipd" -#define NM_AUTOIP_DBUS_IFACE "org.freedesktop.nm_avahi_autoipd" - static gboolean impl_manager_get_devices (NMManager *manager, GPtrArray **devices, GError **err); @@ -183,7 +180,6 @@ typedef struct { NMVpnManager *vpn_manager; - GDBusProxy *aipd_proxy; NMSleepMonitor *sleep_monitor; GSList *auth_chains; @@ -826,40 +822,6 @@ device_removed_cb (NMDevice *device, gpointer user_data) remove_device (NM_MANAGER (user_data), device, FALSE, TRUE); } -static void -aipd_handle_event (GDBusProxy *proxy, - const char *event, - const char *iface, - const char *address, - gpointer user_data) -{ - NMManager *manager = NM_MANAGER (user_data); - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); - GSList *iter; - gboolean handled = FALSE; - - if ( (strcmp (event, "BIND") != 0) - && (strcmp (event, "CONFLICT") != 0) - && (strcmp (event, "UNBIND") != 0) - && (strcmp (event, "STOP") != 0)) { - nm_log_warn (LOGD_AUTOIP4, "unknown event '%s' received from avahi-autoipd", event); - return; - } - - for (iter = priv->devices; iter; iter = g_slist_next (iter)) { - NMDevice *candidate = NM_DEVICE (iter->data); - - if (!strcmp (nm_device_get_iface (candidate), iface)) { - nm_device_handle_ipv4ll_event (candidate, event, address); - handled = TRUE; - break; - } - } - - if (!handled) - nm_log_warn (LOGD_AUTOIP4, "(%s): unhandled avahi-autoipd event", iface); -} - NMState nm_manager_get_state (NMManager *manager) { @@ -4594,7 +4556,6 @@ nm_manager_init (NMManager *manager) NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); guint i; GFile *file; - GError *error = NULL; /* Initialize rfkill structures and states */ memset (priv->radio_states, 0, sizeof (priv->radio_states)); @@ -4635,23 +4596,6 @@ nm_manager_init (NMManager *manager) priv->vpn_manager = g_object_ref (nm_vpn_manager_get ()); - /* avahi-autoipd stuff */ - priv->aipd_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, - NULL, - NM_AUTOIP_DBUS_SERVICE, - "/", - NM_AUTOIP_DBUS_IFACE, - NULL, &error); - if (priv->aipd_proxy) { - _nm_dbus_signal_connect (priv->aipd_proxy, "Event", G_VARIANT_TYPE ("(sss)"), - G_CALLBACK (aipd_handle_event), manager); - } else { - nm_log_warn (LOGD_AUTOIP4, "could not initialize avahi-autoipd D-Bus proxy: %s", - error->message); - g_clear_error (&error); - } - /* sleep/wake handling */ priv->sleep_monitor = g_object_ref (nm_sleep_monitor_get ()); g_signal_connect (priv->sleep_monitor, NM_SLEEP_MONITOR_SLEEPING, @@ -4878,7 +4822,6 @@ dispose (GObject *object) priv->dbus_mgr = NULL; } - g_clear_object (&priv->aipd_proxy); if (priv->sleep_monitor) { g_signal_handlers_disconnect_by_func (priv->sleep_monitor, sleeping_cb, manager); g_signal_handlers_disconnect_by_func (priv->sleep_monitor, resuming_cb, manager); From 3376952ef94c4cd230efdba87e18c6dffdc267c5 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Thu, 2 Apr 2015 11:52:00 +0200 Subject: [PATCH 6/7] callouts: avahi-autoipd-action is no more --- callouts/Makefile.am | 14 +--- callouts/nm-avahi-autoipd-action.c | 126 ----------------------------- callouts/nm-avahi-autoipd.conf | 13 --- 3 files changed, 2 insertions(+), 151 deletions(-) delete mode 100644 callouts/nm-avahi-autoipd-action.c delete mode 100644 callouts/nm-avahi-autoipd.conf diff --git a/callouts/Makefile.am b/callouts/Makefile.am index cc38e01a82..7bc7273032 100644 --- a/callouts/Makefile.am +++ b/callouts/Makefile.am @@ -22,20 +22,10 @@ noinst_LTLIBRARIES = \ dbusservicedir = $(DBUS_SYS_DIR) dbusservice_DATA = \ - nm-dispatcher.conf \ - nm-avahi-autoipd.conf + nm-dispatcher.conf libexec_PROGRAMS = \ - nm-dispatcher \ - nm-avahi-autoipd.action - - -nm_avahi_autoipd_action_SOURCES = \ - nm-avahi-autoipd-action.c - -nm_avahi_autoipd_action_LDADD = \ - $(DBUS_LIBS) \ - $(GLIB_LIBS) + nm-dispatcher nm_dispatcher_SOURCES = \ diff --git a/callouts/nm-avahi-autoipd-action.c b/callouts/nm-avahi-autoipd-action.c deleted file mode 100644 index b28dae5d21..0000000000 --- a/callouts/nm-avahi-autoipd-action.c +++ /dev/null @@ -1,126 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager -- Network link manager - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Copyright 2008, 2014 Red Hat, Inc. - */ - -#include "config.h" - -#include -#include - -#include - -#define NM_AVAHI_AUTOIPD_DBUS_SERVICE "org.freedesktop.nm_avahi_autoipd" -#define NM_AVAHI_AUTOIPD_DBUS_INTERFACE "org.freedesktop.nm_avahi_autoipd" - -static void -on_name_acquired (GDBusConnection *connection, - const gchar *name, - gpointer loop) -{ - g_main_loop_quit (loop); -} - -static void -on_name_lost (GDBusConnection *connection, - const gchar *name, - gpointer user_data) -{ - g_printerr ("Error: Could not acquire the NM autoipd service."); - exit (1); -} - -int -main (int argc, char *argv[]) -{ - GDBusConnection *connection; - char *event, *iface, *address; - GMainLoop *loop; - GError *error = NULL; - -#if !GLIB_CHECK_VERSION (2, 35, 0) - g_type_init (); -#endif - - if (argc != 4) { - g_printerr ("Error: expected 3 arguments (event, interface, address).\n"); - exit (1); - } - - event = argv[1]; - iface = argv[2]; - address = argv[3] ? argv[3] : ""; - - if (!event || !iface || !strlen (event) || !strlen (iface)) { - g_printerr ("Error: unexpected arguments received from avahi-autoipd.\n"); - exit (1); - } - - /* Get a connection to the system bus */ - connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); - if (error) { - char *remote_error = g_dbus_error_get_remote_error (error); - - g_dbus_error_strip_remote_error (error); - g_printerr ("Error: could not get the system bus. Make sure " - "the message bus daemon is running! Message: (%s) %s\n", - remote_error, error->message); - g_free (remote_error); - g_error_free (error); - return 1; - } - - /* Acquire the bus name */ - loop = g_main_loop_new (NULL, FALSE); - g_bus_own_name_on_connection (connection, - NM_AVAHI_AUTOIPD_DBUS_SERVICE, - 0, - on_name_acquired, - on_name_lost, - loop, NULL); - g_main_loop_run (loop); - g_main_loop_unref (loop); - - /* Send the signal */ - if (!g_dbus_connection_emit_signal (connection, - NULL, - "/", - NM_AVAHI_AUTOIPD_DBUS_INTERFACE, - "Event", - g_variant_new ("(sss)", - event, - iface, - address), - &error)) { - g_dbus_error_strip_remote_error (error); - g_printerr ("Error: Could not send autoipd Event signal: %s\n", error->message); - g_error_free (error); - return 1; - } - - if (!g_dbus_connection_flush_sync (connection, NULL, &error)) { - g_dbus_error_strip_remote_error (error); - g_printerr ("Error: Could not flush D-Bus connection: %s\n", error->message); - g_error_free (error); - return 1; - } - - g_object_unref (connection); - return 0; -} - diff --git a/callouts/nm-avahi-autoipd.conf b/callouts/nm-avahi-autoipd.conf deleted file mode 100644 index 485ab42929..0000000000 --- a/callouts/nm-avahi-autoipd.conf +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - From db923366b21d5eb6c86e15d25cc060fd00ab6535 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Fri, 3 Apr 2015 09:22:41 +0200 Subject: [PATCH 7/7] contrib/rpm: remove avahi-autoipd dependency and files --- contrib/fedora/rpm/NetworkManager.spec | 3 --- 1 file changed, 3 deletions(-) diff --git a/contrib/fedora/rpm/NetworkManager.spec b/contrib/fedora/rpm/NetworkManager.spec index a488ca3648..2937b26b41 100644 --- a/contrib/fedora/rpm/NetworkManager.spec +++ b/contrib/fedora/rpm/NetworkManager.spec @@ -107,7 +107,6 @@ Requires: dhclient >= 12:4.1.0 Requires: libnl3 >= %{libnl3_version} Requires: %{name}-libnm%{?_isa} = %{epoch}:%{version}-%{release} Requires: ppp = %{ppp_version} -Requires: avahi-autoipd Requires: dnsmasq Requires: udev Requires: iptables @@ -519,7 +518,6 @@ fi %defattr(-,root,root,0755) %doc COPYING NEWS AUTHORS README CONTRIBUTING TODO %{_sysconfdir}/dbus-1/system.d/org.freedesktop.NetworkManager.conf -%{_sysconfdir}/dbus-1/system.d/nm-avahi-autoipd.conf %{_sysconfdir}/dbus-1/system.d/nm-dispatcher.conf %{_sysconfdir}/dbus-1/system.d/nm-ifcfg-rh.conf %{_sbindir}/%{name} @@ -536,7 +534,6 @@ fi %config(noreplace) %{_sysconfdir}/%{name}/NetworkManager.conf %{_bindir}/nm-online %{_libexecdir}/nm-dhcp-helper -%{_libexecdir}/nm-avahi-autoipd.action %{_libexecdir}/nm-dispatcher %{_libexecdir}/nm-iface-helper %dir %{_libdir}/NetworkManager