Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
74 lines (67 sloc) 2.91 KB
# -*- sh -*-
# This script splits a delegated IPv6 prefix obtained via DHCPv6 to
# other interfaces. It also requests a default route. It is tailored
# for the use with Orange France ISP.
handle_ipv6_pd() {
# Define the interfaces to which a delegated prefix will be assigned
local IA_PD_IFACES="<%= @interfaces.select { |name, options| options['v6'] }.keys.sort.join ' ' %>"
local reason
local offset=0
local iface
local address
case $reason in
BOUND6|EXPIRE6|REBIND6|REBOOT6|RENEW6)
logger -t "dhcpv6-pd" -p daemon.debug "DHCPv6 PD $reason"
if [ -n "$old_ip6_prefix" ] || [ -n "$new_ip6_prefix" ]; then
offset=0
for iface in $IA_PD_IFACES; do
# If old prefix differs from new one, flush it.
[ -n "$old_ip6_prefix" ] && [ "$old_ip6_prefix" != "$new_ip6_prefix" ] && {
logger -t "dhcpv6-pd" -p daemon.debug \
"old prefix $old_ip6_prefix expired, flushing $iface"
ip -6 addr flush dev "$iface" scope global || \
logger -t "dhcpv6-pd" -p daemon.err \
"failed to flush global IPv6 addresses from interface $iface"
}
# If new prefix, assign it.
[ -n "$new_ip6_prefix" ] && {
offset=$((offset + 1))
address=$(sipcalc --v6split=64 --split-verbose "$new_ip6_prefix" \
| grep '^Compressed' \
| awk "(NR == $offset)"' { print $NF }')1/64
logger -t "dhcpv6-pd" -p daemon.debug \
"from prefix $new_ip6_prefix, computed address $address (offset $offset)"
if ! ip -6 addr show dev "$iface" | grep -qwF "$address"; then
logger -t "dhcpv6-pd" -p daemon.info \
"adding new address $address to interface $iface"
ip -6 addr add "$address" dev "$iface" || \
logger -t "dhcpv6-pd" -p daemon.err \
"failed to add new address $address to interface $iface"
else
logger -t "dhcpv6-pd" -p daemon.debug \
"address $address already assigned to interface $iface"
fi
}
done
fi
# Handle default route
case $old_ip6_prefix,$new_ip6_prefix in
,) : ;;
*,)
logger -t "dhcpv6-pd" -p daemon.info "remove default route"
sysctl -qw net/ipv6/conf/$interface/accept_ra=0
ip -6 route del default proto ra || true
;;
*)
logger -t "dhcpv6-pd" -p daemon.info "request default route"
sysctl -qw net/ipv6/conf/$interface/accept_ra=2
rdisc6 $interface || \
logger -t "dhcpv6-pd" -p daemon.err "cannot request default route"
;;
esac
;;
esac
}
handle_ipv6_pd
unset handle_ipv6_pd
:
You can’t perform that action at this time.