[systemd-devel] [PATCH 24/24] networkd: Add initial DHCPv6 support
Patrik Flykt
patrik.flykt at linux.intel.com
Fri Jun 13 06:45:14 PDT 2014
Enable DHCPv6 support by creating a DHCPv6 boolean in the Network
section. Add necessary dhcp6 structures and initial function calls.
---
src/network/networkd-link.c | 75 ++++++++++++++++++++++++++++++++
src/network/networkd-network-gperf.gperf | 1 +
src/network/networkd.h | 3 ++
3 files changed, 79 insertions(+)
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 3653426..507e82d 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -120,6 +120,8 @@ static void link_free(Link *link) {
sd_ipv4ll_unref(link->ipv4ll);
+ sd_dhcp6_client_unref(link->dhcp6_client);
+
hashmap_remove(link->manager->links, &link->ifindex);
free(link->ifname);
@@ -231,6 +233,17 @@ static int link_stop_clients(Link *link) {
}
}
+ if (link->network->dhcp6) {
+ assert(link->dhcp6_client);
+
+ k = sd_dhcp6_client_stop(link->dhcp6_client);
+ if (k < 0) {
+ log_warning_link(link, "Could not stop DHCPv6 "
+ "client: %s", strerror(-r));
+ r = k;
+ }
+ }
+
return r;
}
@@ -1183,6 +1196,19 @@ static void ipv4ll_handler(sd_ipv4ll *ll, int event, void *userdata){
}
}
+static void dhcp6_handler(sd_dhcp6_client *client, 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;
+
+ log_debug_link(link, "DHCPv6 event %d", event);
+}
+
static int link_acquire_conf(Link *link) {
int r;
@@ -1217,6 +1243,19 @@ static int link_acquire_conf(Link *link) {
}
}
+ if (link->network->dhcp6) {
+ assert(link->dhcp6_client);
+
+ log_debug_link(link, "acquiring DHCPv6 lease");
+
+ r = sd_dhcp6_client_start(link->dhcp6_client);
+ if (r < 0) {
+ log_warning_link(link, "could not acquire DHCPv6 "
+ "lease");
+ return r;
+ }
+ }
+
return 0;
}
@@ -1667,6 +1706,30 @@ static int link_configure(Link *link) {
}
}
+ if (link->network->dhcp6) {
+ r = sd_dhcp6_client_new(&link->dhcp6_client);
+ if (r < 0)
+ return r;
+
+ r = sd_dhcp6_client_attach_event(link->dhcp6_client, NULL, 0);
+ if (r < 0)
+ return r;
+
+ r = sd_dhcp6_client_set_mac(link->dhcp6_client, &link->mac);
+ if (r < 0)
+ return r;
+
+ r = sd_dhcp6_client_set_index(link->dhcp6_client,
+ link->ifindex);
+ if (r < 0)
+ return r;
+
+ r = sd_dhcp6_client_set_callback(link->dhcp6_client,
+ dhcp6_handler, link);
+ if (r < 0)
+ return r;
+ }
+
if (link_has_carrier(link->flags, link->kernel_operstate)) {
r = link_acquire_conf(link);
if (r < 0)
@@ -1974,6 +2037,18 @@ int link_update(Link *link, sd_rtnl_message *m) {
return r;
}
}
+
+ if (link->dhcp6_client) {
+ r = sd_dhcp6_client_set_mac(link->dhcp6_client,
+ &link->mac);
+ if (r < 0) {
+ log_warning_link(link, "Could not "
+ "update MAC address "
+ "in DHCPv6 client: %s",
+ strerror(-r));
+ return r;
+ }
+ }
}
}
diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf
index 5038cb5..9e3993d 100644
--- a/src/network/networkd-network-gperf.gperf
+++ b/src/network/networkd-network-gperf.gperf
@@ -31,6 +31,7 @@ Network.VLAN, config_parse_netdev, 0,
Network.MACVLAN, config_parse_netdev, 0, offsetof(Network, macvlans)
Network.DHCP, config_parse_bool, 0, offsetof(Network, dhcp)
Network.IPv4LL, config_parse_bool, 0, offsetof(Network, ipv4ll)
+Network.DHCPv6, config_parse_bool, 0, offsetof(Network, dhcp6)
Network.Address, config_parse_address, 0, 0
Network.Gateway, config_parse_gateway, 0, 0
Network.DNS, config_parse_dns, 0, offsetof(Network, dns)
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 6f77c77..c943512 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -28,6 +28,7 @@
#include "sd-bus.h"
#include "sd-dhcp-client.h"
#include "sd-ipv4ll.h"
+#include "sd-dhcp6-client.h"
#include "udev.h"
#include "rtnl-util.h"
@@ -148,6 +149,7 @@ struct Network {
bool dhcp_domainname;
bool dhcp_critical;
bool ipv4ll;
+ bool dhcp6;
LIST_HEAD(Address, static_addresses);
LIST_HEAD(Route, static_routes);
@@ -256,6 +258,7 @@ struct Link {
char *lease_file;
uint16_t original_mtu;
sd_ipv4ll *ipv4ll;
+ sd_dhcp6_client *dhcp6_client;
};
struct Manager {
--
1.9.1
More information about the systemd-devel
mailing list