]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-ndisc.c
Merge pull request #1821 from darkcircle/ko-catalog-translation
[thirdparty/systemd.git] / src / network / networkd-ndisc.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4 This file is part of systemd.
5
6 Copyright (C) 2014 Intel Corporation. All rights reserved.
7
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.
12
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.
17
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/>.
20 ***/
21
22 #include <netinet/ether.h>
23 #include <linux/if.h>
24
25 #include "sd-ndisc.h"
26
27 #include "networkd-link.h"
28
29 static void ndisc_router_handler(sd_ndisc *nd, int event, void *userdata) {
30 Link *link = userdata;
31
32 assert(link);
33 assert(link->network);
34 assert(link->manager);
35
36 if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
37 return;
38
39 switch(event) {
40 case SD_NDISC_EVENT_ROUTER_ADVERTISMENT_NONE:
41 return;
42
43 case SD_NDISC_EVENT_ROUTER_ADVERTISMENT_OTHER:
44 dhcp6_configure(link, true);
45
46 break;
47 case SD_NDISC_EVENT_ROUTER_ADVERTISMENT_TIMEOUT:
48 case SD_NDISC_EVENT_ROUTER_ADVERTISMENT_MANAGED:
49 dhcp6_configure(link, false);
50
51 break;
52
53 default:
54 if (event < 0)
55 log_link_warning_errno(link, event, "IPv6 Neighbor Discover error: %m");
56 else
57 log_link_warning(link, "IPv6 Neighbor Discovery unknown event: %d", event);
58
59 break;
60 }
61 }
62
63 int ndisc_configure(Link *link) {
64 int r;
65
66 assert_return(link, -EINVAL);
67
68 r = sd_ndisc_new(&link->ndisc_router_discovery);
69 if (r < 0)
70 return r;
71
72 r = sd_ndisc_attach_event(link->ndisc_router_discovery, NULL, 0);
73 if (r < 0)
74 return r;
75
76 r = sd_ndisc_set_mac(link->ndisc_router_discovery, &link->mac);
77 if (r < 0)
78 return r;
79
80 r = sd_ndisc_set_index(link->ndisc_router_discovery, link->ifindex);
81 if (r < 0)
82 return r;
83
84 r = sd_ndisc_set_callback(link->ndisc_router_discovery,
85 ndisc_router_handler, link);
86
87 return r;
88 }