From: Patrik Flykt Date: Fri, 12 May 2017 13:48:32 +0000 (+0300) Subject: networkd-radv: Helper function for Router Advertisement initialization X-Git-Tag: v234~191^2~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=091214b636e1eb88acf3a5c980b5b66feb647de6;p=thirdparty%2Fsystemd.git networkd-radv: Helper function for Router Advertisement initialization Add a helper function for configuring Router Advertisement on a specific network link. Add the prefixes that are going to be advertised. --- diff --git a/Makefile.am b/Makefile.am index 29fa71df0df..ad79ccde76e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5860,6 +5860,8 @@ libnetworkd_core_la_SOURCES = \ src/network/networkd-dhcp4.c \ src/network/networkd-dhcp6.c \ src/network/networkd-ndisc.h \ + src/network/networkd-radv.c \ + src/network/networkd-radv.h \ src/network/networkd-ndisc.c \ src/network/networkd-network.h \ src/network/networkd-network.c \ diff --git a/src/network/networkd-link.h b/src/network/networkd-link.h index 4e53298cb49..6479f4a2e54 100644 --- a/src/network/networkd-link.h +++ b/src/network/networkd-link.h @@ -118,6 +118,8 @@ typedef struct Link { Set *ndisc_rdnss; Set *ndisc_dnssl; + sd_radv *radv; + sd_dhcp6_client *dhcp6_client; bool rtnl_extended_attrs; diff --git a/src/network/networkd-radv.c b/src/network/networkd-radv.c new file mode 100644 index 00000000000..e5be145146a --- /dev/null +++ b/src/network/networkd-radv.c @@ -0,0 +1,77 @@ +/*** + This file is part of systemd. + + Copyright (C) 2017 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 . +***/ + +#include +#include + +#include "networkd-address.h" +#include "networkd-radv.h" +#include "sd-radv.h" + +int radv_configure(Link *link) { + int r; + Prefix *p; + + assert(link); + assert(link->network); + + r = sd_radv_new(&link->radv); + if (r < 0) + return r; + + r = sd_radv_attach_event(link->radv, NULL, 0); + if (r < 0) + return r; + + r = sd_radv_set_mac(link->radv, &link->mac); + if (r < 0) + return r; + + r = sd_radv_set_ifindex(link->radv, link->ifindex); + if (r < 0) + return r; + + r = sd_radv_set_managed_information(link->radv, link->network->router_managed); + if (r < 0) + return r; + + r = sd_radv_set_other_information(link->radv, link->network->router_other_information); + if (r < 0) + return r; + + r = sd_radv_set_router_lifetime(link->radv, + link->network->router_lifetime_usec); + if (r < 0) + return r; + + if (link->network->router_lifetime_usec > 0) { + r = sd_radv_set_preference(link->radv, + link->network->router_preference); + if (r < 0) + return r; + } + + LIST_FOREACH(prefixes, p, link->network->static_prefixes) { + r = sd_radv_add_prefix(link->radv, p->radv_prefix); + if (r != -EEXIST && r < 0) + return r; + } + + return 0; +} diff --git a/src/network/networkd-radv.h b/src/network/networkd-radv.h new file mode 100644 index 00000000000..a186b111a1e --- /dev/null +++ b/src/network/networkd-radv.h @@ -0,0 +1,24 @@ +#pragma once + +/*** + This file is part of systemd. + + Copyright 2017 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 . +***/ + +#include "networkd-link.h" + +int radv_configure(Link *link);