]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-radv.c
d47a2fd3fd3cb5b74747becbc086edc090cdbf4f
[thirdparty/systemd.git] / src / network / networkd-radv.c
1 /***
2 This file is part of systemd.
3
4 Copyright (C) 2017 Intel Corporation. All rights reserved.
5
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18 ***/
19
20 #include <netinet/icmp6.h>
21 #include <arpa/inet.h>
22
23 #include "networkd-address.h"
24 #include "networkd-radv.h"
25 #include "sd-radv.h"
26
27 int radv_configure(Link *link) {
28 int r;
29 Prefix *p;
30
31 assert(link);
32 assert(link->network);
33
34 r = sd_radv_new(&link->radv);
35 if (r < 0)
36 return r;
37
38 r = sd_radv_attach_event(link->radv, NULL, 0);
39 if (r < 0)
40 return r;
41
42 r = sd_radv_set_mac(link->radv, &link->mac);
43 if (r < 0)
44 return r;
45
46 r = sd_radv_set_ifindex(link->radv, link->ifindex);
47 if (r < 0)
48 return r;
49
50 r = sd_radv_set_managed_information(link->radv, link->network->router_managed);
51 if (r < 0)
52 return r;
53
54 r = sd_radv_set_other_information(link->radv, link->network->router_other_information);
55 if (r < 0)
56 return r;
57
58 /* a value of 0xffffffff represents infinity, 0x0 means this host is
59 not a router */
60 r = sd_radv_set_router_lifetime(link->radv,
61 DIV_ROUND_UP(link->network->router_lifetime_usec, USEC_PER_SEC));
62 if (r < 0)
63 return r;
64
65 if (link->network->router_lifetime_usec > 0) {
66 r = sd_radv_set_preference(link->radv,
67 link->network->router_preference);
68 if (r < 0)
69 return r;
70 }
71
72 LIST_FOREACH(prefixes, p, link->network->static_prefixes) {
73 r = sd_radv_add_prefix(link->radv, p->radv_prefix);
74 if (r != -EEXIST && r < 0)
75 return r;
76 }
77
78 if (link->network->router_dns) {
79 r = sd_radv_set_rdnss(link->radv,
80 DIV_ROUND_UP(link->network->router_dns_lifetime_usec,
81 USEC_PER_SEC),
82 link->network->router_dns,
83 link->network->n_router_dns);
84 if (r < 0)
85 return r;
86 }
87
88 return 0;
89 }