#!/usr/bin/bash
if [ -z "$IFNAME" ] || [ "$LINKNAME" != "my_provider_linkname_blahblahblah" ]
then
true
exit
fi
lan_iface="br-lan"
modprobe ip6_tables
modprobe ip6table_filter
ip6tables -P FORWARD DROP && sysctl net.ipv6.conf.default.forwarding=1 && sysctl net.ipv6.conf.all.forwarding=1
if ! ip6tables -t mangle -C FORWARD -i "$lan_iface" -o "$IFNAME" -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
then
ip6tables -t mangle -A FORWARD -i "$lan_iface" -o "$IFNAME" -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
fi
if ! ip6tables -C FORWARD -i "$lan_iface" -o "$IFNAME" -j ACCEPT
then
ip6tables -A FORWARD -i "$lan_iface" -o "$IFNAME" -j ACCEPT
fi
if ! ip6tables -C FORWARD -i "$IFNAME" -o "$lan_iface" -j ACCEPT
then
ip6tables -A FORWARD -i "$IFNAME" -o "$lan_iface" -j ACCEPT
fi
cat >/var/run/custom-internet-dhcpcd.conf <<__END__
ipv6only
noipv6rs
ia_pd 1
__END__
cat >/var/run/custom-internet-dhcpcd-hooks <<__END__
#!/usr/bin/bash
if [ "\$reason" == "REBIND6" ] && [ "\$new_dhcp6_prefix" == "\$old_dhcp6_prefix" ]
then
true
exit
fi
if [ "\$reason" == "BOUND6" ] || [ "\$reason" == "REBIND6" ] || [ "\$reason" == "STOP6" ]
then
if [ -f /var/run/custom-internet-radvd.conf ]
then
rm /var/run/custom-internet-radvd.conf
fi
if [ -f /var/run/custom-internet-radvd.pid ]
then
radvd_pid="\$(cat /var/run/custom-internet-radvd.pid)"
rm /var/run/custom-internet-radvd.pid
kill "\$radvd_pid"
fi
if [ -f /var/run/custom-internet-dhcpcd-addr.data ]
then
ip -6 addr del "\$(cat /var/run/custom-internet-dhcpcd-addr.data)" dev $lan_iface
rm /var/run/custom-internet-dhcpcd-addr.data
fi
fi
if [ "\$reason" == "BOUND6" ] || [ "\$reason" == "REBIND6" ]
then
new_dhcp6_addr="\${new_dhcp6_prefix/%::\\/64/::1/64}"
if [ "\$new_dhcp6_addr" != "\$new_dhcp6_prefix" ]
then
echo "\$new_dhcp6_addr" >/var/run/custom-internet-dhcpcd-addr.data
ip -6 addr add "\$new_dhcp6_addr" dev $lan_iface
cat >/var/run/custom-internet-radvd.conf <<__INNER_END__
interface $lan_iface {
AdvSendAdvert on;
MaxRtrAdvInterval 10; # hack for broken mobile wifi-devices (normal default is 600)
AdvDefaultLifetime 1800; # hack for broken mobile wifi-devices (normal default is MaxRtrAdvInterval*3)
# see http://code.google.com/p/android/issues/detail?id=32662
prefix \$new_dhcp6_prefix
{
};
RDNSS 2001:4860:4860::8888 2001:4860:4860::8844
{
};
};
__INNER_END__
radvd -C /var/run/custom-internet-radvd.conf -p /var/run/custom-internet-radvd.pid
fi
fi
true
__END__
chmod +x /var/run/custom-internet-dhcpcd-hooks
dhcpcd -B -f /var/run/custom-internet-dhcpcd.conf -c /var/run/custom-internet-dhcpcd-hooks "$IFNAME" &
true