Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- commit a854cbdaa7d01d07fc07e2601826b927a6422f94
- Author: Paul Donovan <paul@donovansbrain.co.uk>
- Date: Sat Dec 11 13:53:50 2010 +1100
- dhcpv6, rc, nvram: Add DHCPv6 with Prefix Delegation support.
- This configures dhcp6c properly, including a small alteration to the radvd.conf file that gets generated. An ipv6_service value of 'native-pd' enables this functionality, and ipv6_prefix_length should be given a valid value (like 60). Port 546 UDP incoming must be open in ip6tables to allow in order to receive responses from the DHCPv6 server.
- diff --git a/release/src/router/Makefile b/release/src/router/Makefile
- index 57e5cb4..2246a43 100644
- --- a/release/src/router/Makefile
- +++ b/release/src/router/Makefile
- @@ -804,6 +804,8 @@ dhcpv6: dhcpv6/stamp-h1
- dhcpv6-install: dhcpv6
- install -D dhcpv6/dhcp6c $(INSTALLDIR)/dhcpv6/usr/sbin/dhcp6c
- $(STRIP) $(INSTALLDIR)/dhcpv6/usr/sbin/dhcp6c
- + install -D dhcpv6/dhcp6c-state $(INSTALLDIR)/dhcpv6/usr/sbin/dhcp6c-state
- + install -D dhcpv6/dhcp6c-ifup $(INSTALLDIR)/dhcpv6/usr/sbin/dhcp6c-ifup
- dhcpv6-clean:
- -@$(MAKE) -C dhcpv6 clean
- diff --git a/release/src/router/dhcpv6/dhcp6c-ifup b/release/src/router/dhcpv6/dhcp6c-ifup
- new file mode 100755
- index 0000000..b60723e
- --- /dev/null
- +++ b/release/src/router/dhcpv6/dhcp6c-ifup
- @@ -0,0 +1,3 @@
- +#!/bin/sh
- +sleep 5
- +killall -s SIGHUP radvd
- diff --git a/release/src/router/dhcpv6/dhcp6c-state b/release/src/router/dhcpv6/dhcp6c-state
- new file mode 100755
- index 0000000..1657e54
- --- /dev/null
- +++ b/release/src/router/dhcpv6/dhcp6c-state
- @@ -0,0 +1,13 @@
- +#!/bin/sh
- +CONF="/etc/resolv.dnsmasq"
- +if [ -n "$new_domain_name_servers" ]; then
- + sed -i "/^#BEGIN--dhcp6c/,/^#END--dhcp6c/d" $CONF
- + echo '#BEGIN--dhcp6c' >> $CONF
- + for nameserver in $new_domain_name_servers; do
- + echo nameserver $nameserver >> $CONF
- + done
- + echo '#END--dhcp6c' >> $CONF
- +fi
- +
- +nohup /usr/sbin/dhcp6c-ifup 2>&1 &
- +
- diff --git a/release/src/router/nvram/defaults.c b/release/src/router/nvram/defaults.c
- index 96067fc..33b1962 100644
- --- a/release/src/router/nvram/defaults.c
- +++ b/release/src/router/nvram/defaults.c
- @@ -127,9 +127,9 @@ const defaults_t defaults[] = {
- #ifdef TCONFIG_IPV6
- // IPv6 parameters
- - { "ipv6_service", "" }, // [''|native|sit|other]
- + { "ipv6_service", "" }, // [''|native|native-pd|sit|other]
- { "ipv6_prefix", "" }, // The global-scope IPv6 prefix to route/advertise
- - { "ipv6_prefix_length", "64" }, // The bit length of the prefix. Currently mostly ignored: for radvd, /64 is always assumed.
- + { "ipv6_prefix_length", "64" }, // The bit length of the prefix. Used by dhcp6c. For radvd, /64 is always assumed.
- { "ipv6_rtr_addr", "" }, // defaults to $ipv6_prefix::1
- { "ipv6_tun_v4end" "0.0.0.0" }, // Foreign IPv4 endpoint of SIT tunnel
- { "ipv6_ifname" "" }, // The interface facing the rest of the IPv6 world
- diff --git a/release/src/router/rc/rc.h b/release/src/router/rc/rc.h
- index 76c03a1..61f2689 100644
- --- a/release/src/router/rc/rc.h
- +++ b/release/src/router/rc/rc.h
- @@ -193,6 +193,10 @@ extern void stop_hotplug2(void);
- #ifdef TCONFIG_IPV6
- extern void start_ipv6_sit_tunnel(void);
- extern void stop_ipv6_sit_tunnel(void);
- +extern void start_radvd(void);
- +extern void stop_radvd(void);
- +extern void start_dhcpv6(void);
- +extern void stop_dhcpv6(void);
- #endif
- // !!TB - USB Support
- diff --git a/release/src/router/rc/services.c b/release/src/router/rc/services.c
- index 097b148..a2879c7 100644
- --- a/release/src/router/rc/services.c
- +++ b/release/src/router/rc/services.c
- @@ -459,8 +459,14 @@ void stop_ipv6_sit_tunnel(void)
- void start_radvd(void)
- {
- FILE *f;
- + char *p;
- +
- + p = nvram_safe_get("ipv6_prefix");
- + if (nvram_match("ipv6_service", "native-pd")) {
- + p = "::";
- + }
- - if (nvram_invmatch("ipv6_prefix", "")) {
- + if (*p != '\0') {
- // Create radvd.conf
- if ((f = fopen("/etc/radvd.conf", "w")) == NULL) return;
- fprintf(f,
- @@ -477,7 +483,7 @@ void start_radvd(void)
- "\t\tAdvRouterAddr off;\n"
- "\t};\n"
- "};\n",
- - nvram_safe_get("lan_ifname"), nvram_safe_get("ipv6_prefix"));
- + nvram_safe_get("lan_ifname"), p);
- fclose(f);
- // Start radvd
- @@ -490,6 +496,55 @@ void stop_radvd(void)
- killall_tk("radvd");
- }
- +void start_dhcpv6(void)
- +{
- + FILE *f;
- + char *p;
- +
- + // Check if turned on
- + if (nvram_match("ipv6_service", "native-pd")) {
- + p = nvram_safe_get("ipv6_prefix_length");
- +
- + if (*p) {
- + int prefix_len = atoi(p);
- +
- + // Create dhcp6c.conf
- + if ((f = fopen("/etc/dhcp6c.conf", "w")) == NULL) return;
- + fprintf(f,
- + "interface %s {\n"
- + "\tsend ia-pd 0;\n"
- + "\tsend rapid-commit;\n"
- + "\trequest domain-name-servers;\n"
- + "\tscript \"/usr/sbin/dhcp6c-state\";\n"
- + "};\n"
- + "id-assoc pd 0 {\n"
- + "\tprefix-interface %s {\n"
- + "\t\tsla-id 0;\n"
- + "\t\tsla-len %d;\n"
- + "\t};\n"
- + "\tprefix-interface %s {\n"
- + "\t\tsla-id 1;\n"
- + "\t\tsla-len %d;\n"
- + "\t};\n"
- + "};\n",
- + nvram_safe_get("wan_iface"),
- + "lo",
- + 64 - prefix_len,
- + nvram_safe_get("lan_ifname"),
- + 64 - prefix_len);
- + fclose(f);
- +
- + eval("dhcp6c", "-D", nvram_safe_get("wan_iface"));
- + }
- + }
- +}
- +
- +void stop_dhcpv6(void)
- +{
- + killall_tk("dhcp6c");
- +}
- +
- +
- void start_ipv6(void)
- {
- char *p;
- @@ -514,6 +569,7 @@ void stop_ipv6(void)
- {
- stop_ipv6_sit_tunnel();
- stop_radvd();
- + stop_dhcpv6();
- eval("ip", "-6", "addr", "flush", "scope", "global");
- }
- @@ -1799,6 +1855,16 @@ TOP:
- }
- goto CLEAR;
- }
- +
- + if (strcmp(service, "dhcp6c") == 0) {
- + if (action & A_STOP) {
- + stop_dhcpv6();
- + }
- + if (action & A_START) {
- + start_dhcpv6();
- + }
- + goto CLEAR;
- + }
- #endif
- if (strcmp(service, "admin") == 0) {
- diff --git a/release/src/router/rc/wan.c b/release/src/router/rc/wan.c
- index b27afad..a0e3af0 100644
- --- a/release/src/router/rc/wan.c
- +++ b/release/src/router/rc/wan.c
- @@ -357,7 +357,7 @@ void start_pppoe(int num)
- }
- #ifdef TCONFIG_IPV6
- - if (nvram_match("ipv6_service", "native")) {
- + if (nvram_match("ipv6_service", "native") || nvram_match("ipv6_service", "native-pd")) {
- *arg++ = "-6"; // enables IPv6CP
- }
- #endif
- @@ -897,6 +897,17 @@ void start_wan_done(char *wan_ifname)
- if (nvram_match("ipv6_service", "native")) {
- eval("ip", "route", "add", "::/0", "dev", nvram_safe_get("wan_iface"));
- }
- + else if (nvram_match("ipv6_service", "native-pd")) {
- + eval("ip", "route", "add", "::/0", "dev", nvram_safe_get("wan_iface"));
- + stop_dhcpv6();
- + stop_radvd();
- + /* note: starting radvd here is really too early because we won't have
- + received a prefix and so it will disable advertisements,
- + but the SIGHUP sent from dhcp6c-state will restart them.
- + */
- + start_radvd();
- + start_dhcpv6();
- + }
- else if (nvram_match("ipv6_service", "sit")) {
- stop_ipv6_sit_tunnel();
- start_ipv6_sit_tunnel();
- @@ -943,6 +954,7 @@ void stop_wan(void)
- #ifdef TCONFIG_IPV6
- stop_ipv6_sit_tunnel();
- + stop_dhcpv6();
- #endif
- /* Kill any WAN client daemons or callbacks */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement