1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright (C) 2014 Intel Corporation. All rights reserved.
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include <netinet/ether.h>
25 #include "networkd-link.h"
26 #include "network-internal.h"
28 #include "sd-icmp6-nd.h"
29 #include "sd-dhcp6-client.h"
31 static void dhcp6_handler(sd_dhcp6_client *client, int event, void *userdata) {
32 Link *link = userdata;
35 assert(link->network);
36 assert(link->manager);
38 if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
42 case DHCP6_EVENT_STOP:
43 case DHCP6_EVENT_RESEND_EXPIRE:
44 case DHCP6_EVENT_RETRANS_MAX:
45 case DHCP6_EVENT_IP_ACQUIRE:
46 log_link_debug(link, "DHCPv6 event %d", event);
52 log_link_warning(link, "DHCPv6 error: %s",
55 log_link_warning(link, "DHCPv6 unknown event: %d",
61 static int dhcp6_configure(Link *link) {
64 assert_return(link, -EINVAL);
66 if (link->dhcp6_client)
69 r = sd_dhcp6_client_new(&link->dhcp6_client);
73 r = sd_dhcp6_client_attach_event(link->dhcp6_client, NULL, 0);
75 link->dhcp6_client = sd_dhcp6_client_unref(link->dhcp6_client);
79 r = sd_dhcp6_client_set_mac(link->dhcp6_client,
80 (const uint8_t *) &link->mac,
81 sizeof (link->mac), ARPHRD_ETHER);
83 link->dhcp6_client = sd_dhcp6_client_unref(link->dhcp6_client);
87 r = sd_dhcp6_client_set_index(link->dhcp6_client, link->ifindex);
89 link->dhcp6_client = sd_dhcp6_client_unref(link->dhcp6_client);
93 r = sd_dhcp6_client_set_callback(link->dhcp6_client, dhcp6_handler,
96 link->dhcp6_client = sd_dhcp6_client_unref(link->dhcp6_client);
100 r = sd_dhcp6_client_start(link->dhcp6_client);
102 link->dhcp6_client = sd_dhcp6_client_unref(link->dhcp6_client);
107 static void icmp6_router_handler(sd_icmp6_nd *nd, int event, void *userdata) {
108 Link *link = userdata;
111 assert(link->network);
112 assert(link->manager);
114 if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
118 case ICMP6_EVENT_ROUTER_ADVERTISMENT_NONE:
119 case ICMP6_EVENT_ROUTER_ADVERTISMENT_OTHER:
122 case ICMP6_EVENT_ROUTER_ADVERTISMENT_TIMEOUT:
123 case ICMP6_EVENT_ROUTER_ADVERTISMENT_MANAGED:
128 log_link_warning(link, "ICMPv6 error: %s",
131 log_link_warning(link, "ICMPv6 unknown event: %d",
137 dhcp6_configure(link);
140 int icmp6_configure(Link *link) {
143 assert_return(link, -EINVAL);
145 r = sd_icmp6_nd_new(&link->icmp6_router_discovery);
149 r = sd_icmp6_nd_attach_event(link->icmp6_router_discovery, NULL, 0);
153 r = sd_icmp6_nd_set_mac(link->icmp6_router_discovery, &link->mac);
157 r = sd_icmp6_nd_set_index(link->icmp6_router_discovery, link->ifindex);
161 r = sd_icmp6_nd_set_callback(link->icmp6_router_discovery,
162 icmp6_router_handler, link);