diff options
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/networkd-dhcp6.c | 146 | ||||
-rw-r--r-- | src/network/networkd-link.c | 16 | ||||
-rw-r--r-- | src/network/networkd-link.h | 7 | ||||
-rw-r--r-- | src/network/networkd-ndisc.c | 88 |
4 files changed, 111 insertions, 146 deletions
diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c index fb93e6606e..57c81cb646 100644 --- a/src/network/networkd-dhcp6.c +++ b/src/network/networkd-dhcp6.c @@ -25,7 +25,6 @@ #include "networkd-link.h" #include "network-internal.h" -#include "sd-icmp6-nd.h" #include "sd-dhcp6-client.h" static int dhcp6_lease_address_acquired(sd_dhcp6_client *client, Link *link); @@ -64,8 +63,7 @@ static int dhcp6_address_handler(sd_netlink *rtnl, sd_netlink_message *m, } static int dhcp6_address_change(Link *link, struct in6_addr *ip6_addr, - uint8_t prefixlen, uint32_t lifetime_preferred, - uint32_t lifetime_valid) { + uint32_t lifetime_preferred, uint32_t lifetime_valid) { int r; _cleanup_address_free_ Address *addr = NULL; @@ -77,14 +75,14 @@ static int dhcp6_address_change(Link *link, struct in6_addr *ip6_addr, memcpy(&addr->in_addr.in6, ip6_addr, sizeof(*ip6_addr)); addr->flags = IFA_F_NOPREFIXROUTE; - addr->prefixlen = prefixlen; + addr->prefixlen = 128; addr->cinfo.ifa_prefered = lifetime_preferred; addr->cinfo.ifa_valid = lifetime_valid; log_link_info(link, - "DHCPv6 address "SD_ICMP6_ND_ADDRESS_FORMAT_STR"/%d timeout preferred %d valid %d", - SD_ICMP6_ND_ADDRESS_FORMAT_VAL(addr->in_addr.in6), + "DHCPv6 address "SD_NDISC_ADDRESS_FORMAT_STR"/%d timeout preferred %d valid %d", + SD_NDISC_ADDRESS_FORMAT_VAL(addr->in_addr.in6), addr->prefixlen, lifetime_preferred, lifetime_valid); r = address_configure(addr, link, dhcp6_address_handler, true); @@ -99,7 +97,6 @@ static int dhcp6_lease_address_acquired(sd_dhcp6_client *client, Link *link) { sd_dhcp6_lease *lease; struct in6_addr ip6_addr; uint32_t lifetime_preferred, lifetime_valid; - uint8_t prefixlen; r = sd_dhcp6_client_get_lease(client, &lease); if (r < 0) @@ -111,18 +108,7 @@ static int dhcp6_lease_address_acquired(sd_dhcp6_client *client, Link *link) { &lifetime_preferred, &lifetime_valid) >= 0) { - r = sd_icmp6_ra_get_prefixlen(link->icmp6_router_discovery, - &ip6_addr, &prefixlen); - if (r < 0 && r != -EADDRNOTAVAIL) { - log_link_warning_errno(link, r, "Could not get prefix information: %m"); - return r; - } - - if (r == -EADDRNOTAVAIL) - prefixlen = 128; - - r = dhcp6_address_change(link, &ip6_addr, prefixlen, - lifetime_preferred, lifetime_valid); + r = dhcp6_address_change(link, &ip6_addr, lifetime_preferred, lifetime_valid); if (r < 0) return r; } @@ -179,34 +165,29 @@ static void dhcp6_handler(sd_dhcp6_client *client, int event, void *userdata) { link_check_ready(link); } -static int dhcp6_configure(Link *link, int event) { +int dhcp6_configure(Link *link, bool inf_req) { int r; bool information_request; assert_return(link, -EINVAL); - assert_return(IN_SET(event, SD_ICMP6_ND_EVENT_ROUTER_ADVERTISMENT_TIMEOUT, - SD_ICMP6_ND_EVENT_ROUTER_ADVERTISMENT_OTHER, - SD_ICMP6_ND_EVENT_ROUTER_ADVERTISMENT_MANAGED), -EINVAL); link->dhcp6_configured = false; if (link->dhcp6_client) { - r = sd_dhcp6_client_get_information_request(link->dhcp6_client, - &information_request); + r = sd_dhcp6_client_get_information_request(link->dhcp6_client, &information_request); if (r < 0) { log_link_warning_errno(link, r, "Could not get DHCPv6 Information request setting: %m"); goto error; } - if (information_request && event != SD_ICMP6_ND_EVENT_ROUTER_ADVERTISMENT_OTHER) { + if (information_request && !inf_req) { r = sd_dhcp6_client_stop(link->dhcp6_client); if (r < 0) { log_link_warning_errno(link, r, "Could not stop DHCPv6 while setting Managed mode: %m"); goto error; } - r = sd_dhcp6_client_set_information_request(link->dhcp6_client, - false); + r = sd_dhcp6_client_set_information_request(link->dhcp6_client, false); if (r < 0) { log_link_warning_errno(link, r, "Could not unset DHCPv6 Information request: %m"); goto error; @@ -249,9 +230,8 @@ static int dhcp6_configure(Link *link, int event) { if (r < 0) goto error; - if (event == SD_ICMP6_ND_EVENT_ROUTER_ADVERTISMENT_OTHER) { - r = sd_dhcp6_client_set_information_request(link->dhcp6_client, - true); + if (inf_req) { + r = sd_dhcp6_client_set_information_request(link->dhcp6_client, true); if (r < 0) goto error; } @@ -266,107 +246,3 @@ static int dhcp6_configure(Link *link, int event) { link->dhcp6_client = sd_dhcp6_client_unref(link->dhcp6_client); return r; } - -static int dhcp6_prefix_expired(Link *link) { - int r; - sd_dhcp6_lease *lease; - struct in6_addr *expired_prefix, ip6_addr; - uint8_t expired_prefixlen; - uint32_t lifetime_preferred, lifetime_valid; - - r = sd_icmp6_ra_get_expired_prefix(link->icmp6_router_discovery, - &expired_prefix, &expired_prefixlen); - if (r < 0) - return r; - - r = sd_dhcp6_client_get_lease(link->dhcp6_client, &lease); - if (r < 0) - return r; - - log_link_info(link, "IPv6 prefix "SD_ICMP6_ND_ADDRESS_FORMAT_STR"/%d expired", - SD_ICMP6_ND_ADDRESS_FORMAT_VAL(*expired_prefix), - expired_prefixlen); - - sd_dhcp6_lease_reset_address_iter(lease); - - while (sd_dhcp6_lease_get_address(lease, &ip6_addr, - &lifetime_preferred, - &lifetime_valid) >= 0) { - - r = sd_icmp6_prefix_match(expired_prefix, expired_prefixlen, - &ip6_addr); - if (r < 0) - continue; - - log_link_info(link, "IPv6 prefix length updated "SD_ICMP6_ND_ADDRESS_FORMAT_STR"/%d", SD_ICMP6_ND_ADDRESS_FORMAT_VAL(ip6_addr), 128); - - dhcp6_address_change(link, &ip6_addr, 128, lifetime_preferred, lifetime_valid); - } - - return 0; -} - -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 SD_ICMP6_ND_EVENT_ROUTER_ADVERTISMENT_NONE: - return; - - case SD_ICMP6_ND_EVENT_ROUTER_ADVERTISMENT_TIMEOUT: - case SD_ICMP6_ND_EVENT_ROUTER_ADVERTISMENT_OTHER: - case SD_ICMP6_ND_EVENT_ROUTER_ADVERTISMENT_MANAGED: - dhcp6_configure(link, event); - - break; - - case SD_ICMP6_ND_EVENT_ROUTER_ADVERTISMENT_PREFIX_EXPIRED: - if (!link->rtnl_extended_attrs) - dhcp6_prefix_expired(link); - - break; - - default: - if (event < 0) - log_link_warning_errno(link, event, "ICMPv6 error: %m"); - else - log_link_warning(link, "ICMPv6 unknown event: %d", event); - - break; - } - -} - -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; -} diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index ec4b082542..09f4bd7029 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -370,7 +370,7 @@ static void link_free(Link *link) { sd_ipv4ll_unref(link->ipv4ll); sd_dhcp6_client_unref(link->dhcp6_client); - sd_icmp6_nd_unref(link->icmp6_router_discovery); + sd_ndisc_unref(link->ndisc_router_discovery); if (link->manager) hashmap_remove(link->manager->links, INT_TO_PTR(link->ifindex)); @@ -481,16 +481,16 @@ static int link_stop_clients(Link *link) { r = log_link_warning_errno(link, r, "Could not stop IPv4 link-local: %m"); } - if(link->icmp6_router_discovery) { + if(link->ndisc_router_discovery) { if (link->dhcp6_client) { k = sd_dhcp6_client_stop(link->dhcp6_client); if (k < 0) r = log_link_warning_errno(link, r, "Could not stop DHCPv6 client: %m"); } - k = sd_icmp6_nd_stop(link->icmp6_router_discovery); + k = sd_ndisc_stop(link->ndisc_router_discovery); if (k < 0) - r = log_link_warning_errno(link, r, "Could not stop ICMPv6 router discovery: %m"); + r = log_link_warning_errno(link, r, "Could not stop IPv6 Router Discovery: %m"); } if (link->lldp) { @@ -1238,13 +1238,13 @@ static int link_acquire_conf(Link *link) { } if (link_dhcp6_enabled(link)) { - assert(link->icmp6_router_discovery); + assert(link->ndisc_router_discovery); log_link_debug(link, "Discovering IPv6 routers"); - r = sd_icmp6_router_solicitation_start(link->icmp6_router_discovery); + r = sd_ndisc_router_discovery_start(link->ndisc_router_discovery); if (r < 0) - return log_link_warning_errno(link, r, "Could not start IPv6 router discovery: %m"); + return log_link_warning_errno(link, r, "Could not start IPv6 Router Discovery: %m"); } if (link_lldp_enabled(link)) { @@ -2002,7 +2002,7 @@ static int link_configure(Link *link) { } if (link_dhcp6_enabled(link)) { - r = icmp6_configure(link); + r = ndisc_configure(link); if (r < 0) return r; } diff --git a/src/network/networkd-link.h b/src/network/networkd-link.h index af2ba11701..5c92df4ca8 100644 --- a/src/network/networkd-link.h +++ b/src/network/networkd-link.h @@ -26,7 +26,7 @@ #include "sd-dhcp-client.h" #include "sd-dhcp-server.h" #include "sd-ipv4ll.h" -#include "sd-icmp6-nd.h" +#include "sd-ndisc.h" #include "sd-dhcp6-client.h" #include "sd-lldp.h" @@ -104,7 +104,7 @@ struct Link { sd_dhcp_server *dhcp_server; - sd_icmp6_nd *icmp6_router_discovery; + sd_ndisc *ndisc_router_discovery; sd_dhcp6_client *dhcp6_client; bool rtnl_extended_attrs; @@ -145,7 +145,8 @@ int link_set_timezone(Link *link, const char *timezone); int ipv4ll_configure(Link *link); int dhcp4_configure(Link *link); -int icmp6_configure(Link *link); +int dhcp6_configure(Link *link, bool information_request); +int ndisc_configure(Link *link); bool link_lldp_enabled(Link *link); bool link_ipv4ll_enabled(Link *link); diff --git a/src/network/networkd-ndisc.c b/src/network/networkd-ndisc.c new file mode 100644 index 0000000000..637c29973e --- /dev/null +++ b/src/network/networkd-ndisc.c @@ -0,0 +1,88 @@ +/*-*- 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 "sd-ndisc.h" + +static void ndisc_router_handler(sd_ndisc *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 SD_NDISC_EVENT_ROUTER_ADVERTISMENT_NONE: + return; + + case SD_NDISC_EVENT_ROUTER_ADVERTISMENT_OTHER: + dhcp6_configure(link, true); + + break; + case SD_NDISC_EVENT_ROUTER_ADVERTISMENT_TIMEOUT: + case SD_NDISC_EVENT_ROUTER_ADVERTISMENT_MANAGED: + dhcp6_configure(link, false); + + break; + + default: + if (event < 0) + log_link_warning_errno(link, event, "IPv6 Neighbor Discover error: %m"); + else + log_link_warning(link, "IPv6 Neighbor Discovery unknown event: %d", event); + + break; + } +} + +int ndisc_configure(Link *link) { + int r; + + assert_return(link, -EINVAL); + + r = sd_ndisc_new(&link->ndisc_router_discovery); + if (r < 0) + return r; + + r = sd_ndisc_attach_event(link->ndisc_router_discovery, NULL, 0); + if (r < 0) + return r; + + r = sd_ndisc_set_mac(link->ndisc_router_discovery, &link->mac); + if (r < 0) + return r; + + r = sd_ndisc_set_index(link->ndisc_router_discovery, link->ifindex); + if (r < 0) + return r; + + r = sd_ndisc_set_callback(link->ndisc_router_discovery, + ndisc_router_handler, link); + + return r; +} |