chiark / gitweb /
networkd-dhcp6: Move ICMPv6 and DHCPv6 configuration to new file
authorPatrik Flykt <patrik.flykt@linux.intel.com>
Wed, 10 Dec 2014 14:17:34 +0000 (16:17 +0200)
committerTom Gundersen <teg@jklm.no>
Wed, 10 Dec 2014 17:31:21 +0000 (18:31 +0100)
Handle all aspects of ICMPv6 and DHCPv6 in a file of its own as is done
with DHCPv4 and IPv4LL.

Makefile.am
src/network/networkd-dhcp6.c [new file with mode: 0644]
src/network/networkd-link.c
src/network/networkd-link.h

index 23210ff33edb09a03297c15caf6042bd297762da..6f02c742a98fc017708393b044b76d94f24646c7 100644 (file)
@@ -5247,6 +5247,7 @@ libsystemd_networkd_core_la_SOURCES = \
        src/network/networkd-link.c \
        src/network/networkd-ipv4ll.c \
        src/network/networkd-dhcp4.c \
        src/network/networkd-link.c \
        src/network/networkd-ipv4ll.c \
        src/network/networkd-dhcp4.c \
+       src/network/networkd-dhcp6.c \
        src/network/networkd-network.c \
        src/network/networkd-address.c \
        src/network/networkd-route.c \
        src/network/networkd-network.c \
        src/network/networkd-address.c \
        src/network/networkd-route.c \
diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c
new file mode 100644 (file)
index 0000000..bf8d78b
--- /dev/null
@@ -0,0 +1,165 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright (C) 2014 Intel Corporation. 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 <http://www.gnu.org/licenses/>.
+***/
+
+#include <netinet/ether.h>
+#include <linux/if.h>
+
+#include "networkd-link.h"
+#include "network-internal.h"
+
+#include "sd-icmp6-nd.h"
+#include "sd-dhcp6-client.h"
+
+static void dhcp6_handler(sd_dhcp6_client *client, int event, void *userdata) {
+        Link *link = userdata;
+
+        assert(link);
+        assert(link->network);
+        assert(link->manager);
+
+        if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
+                return;
+
+        switch(event) {
+        case DHCP6_EVENT_STOP:
+        case DHCP6_EVENT_RESEND_EXPIRE:
+        case DHCP6_EVENT_RETRANS_MAX:
+        case DHCP6_EVENT_IP_ACQUIRE:
+                log_link_debug(link, "DHCPv6 event %d", event);
+
+                break;
+
+        default:
+                if (event < 0)
+                        log_link_warning(link, "DHCPv6 error: %s",
+                                         strerror(-event));
+                else
+                        log_link_warning(link, "DHCPv6 unknown event: %d",
+                                         event);
+                return;
+        }
+}
+
+static int dhcp6_configure(Link *link) {
+        int r;
+
+        assert_return(link, -EINVAL);
+
+        if (link->dhcp6_client)
+                return 0;
+
+        r = sd_dhcp6_client_new(&link->dhcp6_client);
+        if (r < 0)
+                return r;
+
+        r = sd_dhcp6_client_attach_event(link->dhcp6_client, NULL, 0);
+        if (r < 0) {
+                link->dhcp6_client = sd_dhcp6_client_unref(link->dhcp6_client);
+                return r;
+        }
+
+        r = sd_dhcp6_client_set_mac(link->dhcp6_client,
+                                    (const uint8_t *) &link->mac,
+                                    sizeof (link->mac), ARPHRD_ETHER);
+        if (r < 0) {
+                link->dhcp6_client = sd_dhcp6_client_unref(link->dhcp6_client);
+                return r;
+        }
+
+        r = sd_dhcp6_client_set_index(link->dhcp6_client, link->ifindex);
+        if (r < 0) {
+                link->dhcp6_client = sd_dhcp6_client_unref(link->dhcp6_client);
+                return r;
+        }
+
+        r = sd_dhcp6_client_set_callback(link->dhcp6_client, dhcp6_handler,
+                                         link);
+        if (r < 0) {
+                link->dhcp6_client = sd_dhcp6_client_unref(link->dhcp6_client);
+                return r;
+        }
+
+        r = sd_dhcp6_client_start(link->dhcp6_client);
+        if (r < 0)
+                link->dhcp6_client = sd_dhcp6_client_unref(link->dhcp6_client);
+
+        return r;
+}
+
+static void icmp6_router_handler(sd_icmp6_nd *nd, int event, void *userdata) {
+        Link *link = userdata;
+
+        assert(link);
+        assert(link->network);
+        assert(link->manager);
+
+        if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
+                return;
+
+        switch(event) {
+        case ICMP6_EVENT_ROUTER_ADVERTISMENT_NONE:
+        case ICMP6_EVENT_ROUTER_ADVERTISMENT_OTHER:
+                return;
+
+        case ICMP6_EVENT_ROUTER_ADVERTISMENT_TIMEOUT:
+        case ICMP6_EVENT_ROUTER_ADVERTISMENT_MANAGED:
+                break;
+
+        default:
+                if (event < 0)
+                        log_link_warning(link, "ICMPv6 error: %s",
+                                         strerror(-event));
+                else
+                        log_link_warning(link, "ICMPv6 unknown event: %d",
+                                         event);
+
+                return;
+        }
+
+        dhcp6_configure(link);
+}
+
+int icmp6_configure(Link *link) {
+        int r;
+
+        assert_return(link, -EINVAL);
+
+        r = sd_icmp6_nd_new(&link->icmp6_router_discovery);
+        if (r < 0)
+                return r;
+
+        r = sd_icmp6_nd_attach_event(link->icmp6_router_discovery, NULL, 0);
+        if (r < 0)
+                return r;
+
+        r = sd_icmp6_nd_set_mac(link->icmp6_router_discovery, &link->mac);
+        if (r < 0)
+                return r;
+
+        r = sd_icmp6_nd_set_index(link->icmp6_router_discovery, link->ifindex);
+        if (r < 0)
+                return r;
+
+        r = sd_icmp6_nd_set_callback(link->icmp6_router_discovery,
+                                icmp6_router_handler, link);
+
+        return r;
+}
index 06e093a18516497f29ea05eb4a1490f2a68f6242..08f724e1279d5902f10f82cd1d7040d0da1885bc 100644 (file)
@@ -857,106 +857,6 @@ static int link_set_bridge(Link *link) {
         return r;
 }
 
         return r;
 }
 
-static void dhcp6_handler(sd_dhcp6_client *client, int event, void *userdata) {
-        Link *link = userdata;
-
-        assert(link);
-        assert(link->network);
-        assert(link->manager);
-
-        if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
-                return;
-
-        switch(event) {
-        case DHCP6_EVENT_STOP:
-        case DHCP6_EVENT_RESEND_EXPIRE:
-        case DHCP6_EVENT_RETRANS_MAX:
-        case DHCP6_EVENT_IP_ACQUIRE:
-                log_link_debug(link, "DHCPv6 event %d", event);
-
-                break;
-
-        default:
-                if (event < 0)
-                        log_link_warning(link, "DHCPv6 error: %s",
-                                         strerror(-event));
-                else
-                        log_link_warning(link, "DHCPv6 unknown event: %d",
-                                         event);
-                return;
-        }
-}
-
-static void icmp6_router_handler(sd_icmp6_nd *nd, int event, void *userdata) {
-        Link *link = userdata;
-        int r;
-
-        assert(link);
-        assert(link->network);
-        assert(link->manager);
-
-        if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
-                return;
-
-        switch(event) {
-        case ICMP6_EVENT_ROUTER_ADVERTISMENT_NONE:
-        case ICMP6_EVENT_ROUTER_ADVERTISMENT_OTHER:
-                return;
-
-        case ICMP6_EVENT_ROUTER_ADVERTISMENT_TIMEOUT:
-        case ICMP6_EVENT_ROUTER_ADVERTISMENT_MANAGED:
-                break;
-
-        default:
-                if (event < 0)
-                        log_link_warning(link, "ICMPv6 error: %s",
-                                         strerror(-event));
-                else
-                        log_link_warning(link, "ICMPv6 unknown event: %d",
-                                         event);
-
-                return;
-        }
-
-        if (link->dhcp6_client)
-                return;
-
-        r = sd_dhcp6_client_new(&link->dhcp6_client);
-        if (r < 0)
-                return;
-
-        r = sd_dhcp6_client_attach_event(link->dhcp6_client, NULL, 0);
-        if (r < 0) {
-                link->dhcp6_client = sd_dhcp6_client_unref(link->dhcp6_client);
-                return;
-        }
-
-        r = sd_dhcp6_client_set_mac(link->dhcp6_client,
-                                    (const uint8_t *) &link->mac,
-                                    sizeof (link->mac), ARPHRD_ETHER);
-        if (r < 0) {
-                link->dhcp6_client = sd_dhcp6_client_unref(link->dhcp6_client);
-                return;
-        }
-
-        r = sd_dhcp6_client_set_index(link->dhcp6_client, link->ifindex);
-        if (r < 0) {
-                link->dhcp6_client = sd_dhcp6_client_unref(link->dhcp6_client);
-                return;
-        }
-
-        r = sd_dhcp6_client_set_callback(link->dhcp6_client, dhcp6_handler,
-                                         link);
-        if (r < 0) {
-                link->dhcp6_client = sd_dhcp6_client_unref(link->dhcp6_client);
-                return;
-        }
-
-        r = sd_dhcp6_client_start(link->dhcp6_client);
-        if (r < 0)
-                link->dhcp6_client = sd_dhcp6_client_unref(link->dhcp6_client);
-}
-
 static int link_acquire_conf(Link *link) {
         int r;
 
 static int link_acquire_conf(Link *link) {
         int r;
 
@@ -1270,27 +1170,7 @@ static int link_configure(Link *link) {
         }
 
         if (link_dhcp6_enabled(link)) {
         }
 
         if (link_dhcp6_enabled(link)) {
-                r = sd_icmp6_nd_new(&link->icmp6_router_discovery);
-                if (r < 0)
-                        return r;
-
-                r = sd_icmp6_nd_attach_event(link->icmp6_router_discovery,
-                                             NULL, 0);
-                if (r < 0)
-                        return r;
-
-                r = sd_icmp6_nd_set_mac(link->icmp6_router_discovery,
-                                        &link->mac);
-                if (r < 0)
-                        return r;
-
-                r = sd_icmp6_nd_set_index(link->icmp6_router_discovery,
-                                          link->ifindex);
-                if (r < 0)
-                        return r;
-
-                r = sd_icmp6_nd_set_callback(link->icmp6_router_discovery,
-                                             icmp6_router_handler, link);
+                r = icmp6_configure(link);
                 if (r < 0)
                         return r;
         }
                 if (r < 0)
                         return r;
         }
index 31688c3ba34a5e4424ab49a98ffcead07ac70478..05c34eef197124ea6a9ae41d473027c1c9f0b9d4 100644 (file)
@@ -119,6 +119,7 @@ int link_set_hostname(Link *link, const char *hostname);
 
 int ipv4ll_configure(Link *link);
 int dhcp4_configure(Link *link);
 
 int ipv4ll_configure(Link *link);
 int dhcp4_configure(Link *link);
+int icmp6_configure(Link *link);
 
 const char* link_state_to_string(LinkState s) _const_;
 LinkState link_state_from_string(const char *s) _pure_;
 
 const char* link_state_to_string(LinkState s) _const_;
 LinkState link_state_from_string(const char *s) _pure_;