[pkg-dhcp-devel] Bug#635897: isc-dhcp-client-udeb: add IPv6 support to dhclient-script
Colin Watson
cjwatson at ubuntu.com
Fri Jul 29 13:09:24 UTC 2011
Package: isc-dhcp-client-udeb
Version: 4.1.1-P1-17
Severity: wishlist
Tags: patch
User: ubuntu-devel at lists.ubuntu.com
Usertags: origin-ubuntu ubuntu-patch oneiric
It would be helpful if the Linux udeb variant of dhclient-script
supported IPv6, since we're preparing to land IPv6 support in d-i quite
soon. Could you please review this patch for that, which mostly
consists of copying stuff over from dhclient-script.linux and stripping
it down in much the same way that the udeb variant was already stripped
down?
* Add DHCPv6 support to dhclient-script.linux.udeb.
diff --git a/debian/dhclient-script.linux.udeb b/debian/dhclient-script.linux.udeb
index 505b035..983176e 100644
--- a/debian/dhclient-script.linux.udeb
+++ b/debian/dhclient-script.linux.udeb
@@ -14,6 +14,7 @@ set -e
make_resolv_conf() {
local new_resolv_conf
+ # DHCPv4
if [ -n "$new_domain_name" ] || [ -n "$new_domain_name_servers" ]; then
new_resolv_conf=/etc/resolv.conf.dhclient-new
rm -f $new_resolv_conf
@@ -27,6 +28,20 @@ make_resolv_conf() {
done
mv $new_resolv_conf /etc/resolv.conf
+ # DHCPv6
+ elif [ -n "$new_dhcp6_domain_search" ] || [ -n "$new_dhcp6_name_servers" ]; then
+ new_resolv_conf=/etc/resolv.conf.dhclient-new
+ rm -f $new_resolv_conf
+
+ if [ -n "$new_dhcp6_domain_search" ]; then
+ echo "search $new_dhcp6_domain_search" >> $new_resolv_conf
+ fi
+
+ for nameserver in $new_dhcp6_name_servers; do
+ echo "nameserver $nameserver" >>$new_resolv_conf
+ done
+
+ mv $new_resolv_conf /etc/resolv.conf
fi
}
@@ -56,11 +71,14 @@ fi
# Execute the operation
case "$reason" in
+
+ ### DHCPv4 Handlers
+
MEDIUM|ARPCHECK|ARPSEND)
# Do nothing
;;
PREINIT)
- ip link set $interface up
+ ip link set dev $interface up
# We need to give the kernel some time to get the interface up.
sleep 1
@@ -72,26 +90,20 @@ case "$reason" in
if [ -n "$old_ip_address" ] &&
[ "$old_ip_address" != "$new_ip_address" ]; then
- # IP address changed. Bringing down the interface will delete all routes,
- # and clear the ARP cache.
- ip addr del $old_ip_address$old_mask $old_broadcast_arg dev $interface
- ip link set $interface down
- fi
-
- if [ -n "$new_interface_mtu" ]; then
- ip link set $interface mtu $new_interface_mtu || true
+ ip -4 addr flush dev $interface
fi
if [ -z "$old_ip_address" ] ||
[ "$old_ip_address" != "$new_ip_address" ] ||
[ "$reason" = "BOUND" ] || [ "$reason" = "REBOOT" ]; then
+ ip -4 addr add $new_ip_address$new_mask $new_broadcast_arg dev $interface
- ip link set $interface up
- ip addr flush dev $interface
- ip addr add $new_ip_address$new_mask $new_broadcast_arg dev $interface
+ if [ -n "$new_interface_mtu" ]; then
+ ip link set $interface mtu $new_interface_mtu || true
+ fi
for router in $new_routers; do
- ip route add default via $router
+ ip -4 route add default via $router dev $interface
done
fi
@@ -108,9 +120,7 @@ case "$reason" in
EXPIRE|FAIL|RELEASE|STOP)
if [ -n "$old_ip_address" ]; then
- # Shut down interface, which will delete routes and clear arp cache.
- ip addr flush dev $interface
- ip link set $interface down
+ ip -4 addr flush dev $interface
fi
;;
@@ -119,6 +129,46 @@ case "$reason" in
ip link set $interface down
;;
+
+ ### DHCPv6 Handlers
+ # TODO handle prefix change: ?based on ${old_ip6_prefix} and ${new_ip6_prefix}?
+
+ PREINIT6)
+ # ensure interface is up
+ ip link set $interface up
+
+ # flush any stale global permanent IPs from interface
+ ip -6 addr flush dev $interface scope global permanent
+
+ ;;
+
+ BOUND6|RENEW6|REBIND6)
+ if [ "$new_ip6_address" ] && [ "$new_ip6_prefixlen" ]; then
+ ip -6 addr add $new_ip6_address/$new_ip6_prefixlen \
+ dev $interface scope global
+ fi
+
+ make_resolv_conf
+
+ # Get the domain name into a file suitable for netcfg to read.
+ printf "${new_dhcp6_domain_search%% *}" > /tmp/domain_name
+
+ ;;
+
+ DEPREF6)
+ if [ "$new_ip6_prefixlen" ]; then
+ ip -6 addr change $cur_ip6_address/$cur_ip6_prefixlen \
+ dev $interface scope global preferred_lft 0
+ fi
+
+ ;;
+
+ EXPIRE6|RELEASE6|STOP6)
+ if [ "$old_ip6_address" ] && [ "$old_ip6_prefixlen" ]; then
+ ip -6 addr del $old_ip6_address/$old_ip6_prefixlen dev $interface
+ fi
+
+ ;;
esac
exit 0
Thanks,
--
Colin Watson [cjwatson at ubuntu.com]
More information about the pkg-dhcp-devel
mailing list