[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#632915: ifupdown: DHCPv6 support



Package: ifupdown
Version: 0.7~alpha5.1
Severity: wishlist
Tags: patch
User: ubuntu-devel@lists.ubuntu.com
Usertags: origin-ubuntu ubuntu-patch oneiric

The following patch adds DHCPv6 support to ifupdown, both stateless
(addressing information provided by RAs) and stateful (addressing
information provided by DHCP).

My main interest here is in supplying enough basic support that I can
cause my IPv6 netcfg branch (based on Matt Palmer's work from a few
months ago) to write out configuration in this or similar form; of
course this relies on ifupdown 0.7 reaching unstable fairly soon.  I
don't pretend to be a professional IPv6 network administrator, and so
I'm CCing debian-ipv6 here for comments.  Hopefully most of them will be
of the form "this could do with some extra options to meet my needs"
rather than "this needs to be put together completely differently and
incompatibly to meet my needs", but if comments of the latter form are
going to arrive then it would be best for them to do so now rather than
later.

With this patch, stateless DHCPv6 works like this, extending the
existing 'auto' method introduced in ifupdown 0.7~alpha3 (stateless
DHCPv6 is similar enough to SLAAC that it didn't seem to make sense to
add an entirely new method):

  iface eth0 inet6 auto
          dhcp 1

Stateful DHCPv6 works like this:

  iface eth0 inet6 dhcp

I guess the most obvious flaw in this is that it takes no account of the
AdvOtherConfigFlag (stateless DHCPv6) and AdvManagedFlag (stateful
DHCPv6) flags in radvd.  That said, I note that even though
radvd.conf(5) refers to RFC4862 to describe those flags, they were
dropped in RFC4862 relative to RFC2462.  Perhaps debian-ipv6 folks can
help here: in production, are people relying on these flags
automatically modifying client behaviour, or is it OK for us to have
different /etc/network/interfaces stanzas for the different modes?  Put
another way, are we painting ourselves into a corner by taking this
approach?  In future we could conceivably just have 'auto' do everything
if that seems to be better, but the code for that would have been quite
a bit more complicated than the following patch.

I was initially going to support wide-dhcpv6-client as well as
isc-dhcp-client, but it was rather harder to integrate into ifupdown,
since doing stateful DHCPv6 there requires writing out custom
configuration files rather than just passing the right command line
options.  isc-dhcp-client is Priority: important, so this ought to be
good enough for most people.

Please review - comments welcome.

  * Add initial DHCPv6 support.

diff -r dfec9e41d751 ifupdown.nw
--- a/ifupdown.nw	Sat Jun 11 11:50:55 2011 +0300
+++ b/ifupdown.nw	Wed Jul 06 23:15:57 2011 +0100
@@ -2975,6 +2975,30 @@
 varvalue = get_var(command, nextpercent - command, ifd);
 @ 
 
+We also define an exported [[var_true()]] function to allow methods to
+have lines of code that are conditional on the value of a variable.
+
+<<exported symbols>>=
+int var_true(char *id, interface_defn *ifd);
+@
+
+<<execute functions>>=
+int var_true(char *id, interface_defn *ifd) {
+	char *varvalue;
+
+	varvalue = get_var(id, strlen(id), ifd);
+	if (varvalue) {
+		if (strcmp(varvalue, "1") == 0 ||
+		    strcasecmp(varvalue, "true") == 0 ||
+		    strcasecmp(varvalue, "yes") == 0)
+			return 1;
+		else
+			return 0;
+	} else
+		return 0;
+}
+@
+
 \subsection{Mapping Scripts}
 
 Doing a mapping is moderately complicated, since we need to pass a
@@ -4381,15 +4405,21 @@
     IPv6 addresses. Using this method on its own doesn't mean that RDNSS options
     will be applied, too. To make this happen, *rdnssd* daemon must be installed,
     properly configured and running.
+    If stateless DHCPv6 support is turned on, then additional network
+    configuration parameters such as DNS and NTP servers will be retrieved
+    from a DHCP server.
 
   options
     privext int            -- Privacy extensions (RFC3041) (0=off, 1=assign, 2=prefer)
+    dhcp int               -- Use stateless DHCPv6 (0=off, 1=on)
   up
     modprobe -q net-pf-10 > /dev/null 2>&1 || true # ignore failure.
     [[sysctl net.ipv6.conf.%iface%.use_tempaddr=%privext%]]
     sysctl net.ipv6.conf.%iface%.accept_ra=1
     sysctl net.ipv6.conf.%iface%.autoconf=1
     ip link set dev %iface% up
+    dhclient -6 -S -pf /var/run/dhclient6.%iface%.pid -lf /var/lib/dhcp/dhclient6.%iface%.leases %iface% \
+        if (var_true("dhcp", ifd) && execable("/sbin/dhclient"))
   down
     ip -6 addr flush dev %iface% scope global
     ip link set dev %iface% down
@@ -4448,6 +4478,30 @@
 
   down
 
+method dhcp
+  description
+    This method may be used to obtain network interface configuration via
+    stateful DHCPv6 with dhclient.  In stateful DHCPv6, the DHCP server is
+    responsible for assigning addresses to clients.
+
+  options
+    hwaddress address      -- Hardware address
+
+  conversion
+    hwaddress cleanup_hwaddress_for_iproute
+
+  up
+    modprobe -q net-pf-10 > /dev/null 2>&1 || true # ignore failure.
+    [[ip link set dev %iface% address %hwaddress%]]
+    sysctl net.ipv6.conf.%iface%.accept_ra=0
+    dhclient -6 -pf /var/run/dhclient6.%iface%.pid -lf /var/lib/dhcp/dhclient6.%iface%.leases %iface% \
+        if (execable("/sbin/dhclient"))
+
+  down
+    dhclient -6 -r -pf /var/run/dhclient6.%iface%.pid -lf /var/lib/dhcp/dhclient6.%iface%.leases %iface% \
+        if (execable("/sbin/dhclient"))
+    ip link set dev %iface% down
+
 method v4tunnel
   description
     This method may be used to setup an IPv6-over-IPv4 tunnel. It requires

Thanks,

-- 
Colin Watson                                       [cjwatson@ubuntu.com]



Reply to: