Advertisement
Guest User

TomatoUSB patch to add DHCPv6 Prefix Delegation support

a guest
Dec 10th, 2010
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 7.07 KB | None | 0 0
  1. commit a854cbdaa7d01d07fc07e2601826b927a6422f94
  2. Author: Paul Donovan <paul@donovansbrain.co.uk>
  3. Date:   Sat Dec 11 13:53:50 2010 +1100
  4.  
  5.     dhcpv6, rc, nvram: Add DHCPv6 with Prefix Delegation support.
  6.    
  7.     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.
  8.  
  9. diff --git a/release/src/router/Makefile b/release/src/router/Makefile
  10. index 57e5cb4..2246a43 100644
  11. --- a/release/src/router/Makefile
  12. +++ b/release/src/router/Makefile
  13. @@ -804,6 +804,8 @@ dhcpv6: dhcpv6/stamp-h1
  14.  dhcpv6-install: dhcpv6
  15.     install -D dhcpv6/dhcp6c $(INSTALLDIR)/dhcpv6/usr/sbin/dhcp6c
  16.     $(STRIP) $(INSTALLDIR)/dhcpv6/usr/sbin/dhcp6c
  17. +   install -D dhcpv6/dhcp6c-state $(INSTALLDIR)/dhcpv6/usr/sbin/dhcp6c-state
  18. +   install -D dhcpv6/dhcp6c-ifup $(INSTALLDIR)/dhcpv6/usr/sbin/dhcp6c-ifup
  19.  
  20.  dhcpv6-clean:
  21.     -@$(MAKE) -C dhcpv6 clean
  22. diff --git a/release/src/router/dhcpv6/dhcp6c-ifup b/release/src/router/dhcpv6/dhcp6c-ifup
  23. new file mode 100755
  24. index 0000000..b60723e
  25. --- /dev/null
  26. +++ b/release/src/router/dhcpv6/dhcp6c-ifup
  27. @@ -0,0 +1,3 @@
  28. +#!/bin/sh
  29. +sleep 5
  30. +killall -s SIGHUP radvd
  31. diff --git a/release/src/router/dhcpv6/dhcp6c-state b/release/src/router/dhcpv6/dhcp6c-state
  32. new file mode 100755
  33. index 0000000..1657e54
  34. --- /dev/null
  35. +++ b/release/src/router/dhcpv6/dhcp6c-state
  36. @@ -0,0 +1,13 @@
  37. +#!/bin/sh
  38. +CONF="/etc/resolv.dnsmasq"
  39. +if [ -n "$new_domain_name_servers" ]; then
  40. +  sed -i "/^#BEGIN--dhcp6c/,/^#END--dhcp6c/d" $CONF
  41. +  echo '#BEGIN--dhcp6c' >> $CONF
  42. +  for nameserver in $new_domain_name_servers; do
  43. +    echo nameserver $nameserver >> $CONF
  44. +  done
  45. +  echo '#END--dhcp6c' >> $CONF
  46. +fi
  47. +
  48. +nohup /usr/sbin/dhcp6c-ifup 2>&1 &
  49. +
  50. diff --git a/release/src/router/nvram/defaults.c b/release/src/router/nvram/defaults.c
  51. index 96067fc..33b1962 100644
  52. --- a/release/src/router/nvram/defaults.c
  53. +++ b/release/src/router/nvram/defaults.c
  54. @@ -127,9 +127,9 @@ const defaults_t defaults[] = {
  55.  
  56.  #ifdef TCONFIG_IPV6
  57.     // IPv6 parameters
  58. -   { "ipv6_service",       ""              },  // [''|native|sit|other]
  59. +   { "ipv6_service",       ""              },  // [''|native|native-pd|sit|other]
  60.     { "ipv6_prefix",        ""              },  // The global-scope IPv6 prefix to route/advertise
  61. -   { "ipv6_prefix_length", "64"            },  // The bit length of the prefix. Currently mostly ignored: for radvd, /64 is always assumed.
  62. +   { "ipv6_prefix_length", "64"            },  // The bit length of the prefix. Used by dhcp6c. For radvd, /64 is always assumed.
  63.     { "ipv6_rtr_addr",      ""              },  // defaults to $ipv6_prefix::1
  64.     { "ipv6_tun_v4end"      "0.0.0.0"       },  // Foreign IPv4 endpoint of SIT tunnel
  65.     { "ipv6_ifname"         ""              },  // The interface facing the rest of the IPv6 world
  66. diff --git a/release/src/router/rc/rc.h b/release/src/router/rc/rc.h
  67. index 76c03a1..61f2689 100644
  68. --- a/release/src/router/rc/rc.h
  69. +++ b/release/src/router/rc/rc.h
  70. @@ -193,6 +193,10 @@ extern void stop_hotplug2(void);
  71.  #ifdef TCONFIG_IPV6
  72.  extern void start_ipv6_sit_tunnel(void);
  73.  extern void stop_ipv6_sit_tunnel(void);
  74. +extern void start_radvd(void);
  75. +extern void stop_radvd(void);
  76. +extern void start_dhcpv6(void);
  77. +extern void stop_dhcpv6(void);
  78.  #endif
  79.  
  80.  // !!TB - USB Support
  81. diff --git a/release/src/router/rc/services.c b/release/src/router/rc/services.c
  82. index 097b148..a2879c7 100644
  83. --- a/release/src/router/rc/services.c
  84. +++ b/release/src/router/rc/services.c
  85. @@ -459,8 +459,14 @@ void stop_ipv6_sit_tunnel(void)
  86.  void start_radvd(void)
  87.  {
  88.     FILE *f;
  89. +   char *p;
  90. +
  91. +   p = nvram_safe_get("ipv6_prefix");
  92. +   if (nvram_match("ipv6_service", "native-pd")) {
  93. +       p = "::";  
  94. +   }
  95.  
  96. -   if (nvram_invmatch("ipv6_prefix", "")) {
  97. +   if (*p != '\0') {
  98.         // Create radvd.conf
  99.         if ((f = fopen("/etc/radvd.conf", "w")) == NULL) return;
  100.         fprintf(f,
  101. @@ -477,7 +483,7 @@ void start_radvd(void)
  102.             "\t\tAdvRouterAddr off;\n"
  103.             "\t};\n"
  104.             "};\n",
  105. -           nvram_safe_get("lan_ifname"), nvram_safe_get("ipv6_prefix"));
  106. +           nvram_safe_get("lan_ifname"), p);
  107.         fclose(f);
  108.  
  109.         // Start radvd
  110. @@ -490,6 +496,55 @@ void stop_radvd(void)
  111.     killall_tk("radvd");
  112.  }
  113.  
  114. +void start_dhcpv6(void)
  115. +{
  116. +   FILE *f;
  117. +   char *p;
  118. +
  119. +   // Check if turned on
  120. +   if (nvram_match("ipv6_service", "native-pd")) {
  121. +       p = nvram_safe_get("ipv6_prefix_length");
  122. +  
  123. +       if (*p) {
  124. +           int prefix_len = atoi(p);
  125. +  
  126. +           // Create dhcp6c.conf
  127. +           if ((f = fopen("/etc/dhcp6c.conf", "w")) == NULL) return;
  128. +           fprintf(f,
  129. +               "interface %s {\n"
  130. +               "\tsend ia-pd 0;\n"
  131. +               "\tsend rapid-commit;\n"
  132. +               "\trequest domain-name-servers;\n"
  133. +               "\tscript \"/usr/sbin/dhcp6c-state\";\n"
  134. +               "};\n"
  135. +               "id-assoc pd 0 {\n"
  136. +               "\tprefix-interface %s {\n"
  137. +               "\t\tsla-id 0;\n"
  138. +               "\t\tsla-len %d;\n"
  139. +               "\t};\n"
  140. +               "\tprefix-interface %s {\n"
  141. +               "\t\tsla-id 1;\n"
  142. +               "\t\tsla-len %d;\n"
  143. +               "\t};\n"
  144. +               "};\n",
  145. +               nvram_safe_get("wan_iface"),
  146. +               "lo",
  147. +               64 - prefix_len,
  148. +               nvram_safe_get("lan_ifname"),
  149. +               64 - prefix_len);
  150. +           fclose(f);
  151. +  
  152. +           eval("dhcp6c", "-D", nvram_safe_get("wan_iface"));
  153. +       }
  154. +   }  
  155. +}
  156. +
  157. +void stop_dhcpv6(void)
  158. +{
  159. +   killall_tk("dhcp6c");
  160. +}
  161. +
  162. +
  163.  void start_ipv6(void)
  164.  {
  165.     char *p;
  166. @@ -514,6 +569,7 @@ void stop_ipv6(void)
  167.  {
  168.     stop_ipv6_sit_tunnel();
  169.     stop_radvd();
  170. +   stop_dhcpv6();
  171.     eval("ip", "-6", "addr", "flush", "scope", "global");
  172.  }
  173.  
  174. @@ -1799,6 +1855,16 @@ TOP:
  175.         }
  176.         goto CLEAR;
  177.     }
  178. +
  179. +   if (strcmp(service, "dhcp6c") == 0) {
  180. +       if (action & A_STOP) {
  181. +           stop_dhcpv6();
  182. +       }
  183. +       if (action & A_START) {
  184. +           start_dhcpv6();
  185. +       }
  186. +       goto CLEAR;
  187. +   }
  188.  #endif
  189.    
  190.     if (strcmp(service, "admin") == 0) {
  191. diff --git a/release/src/router/rc/wan.c b/release/src/router/rc/wan.c
  192. index b27afad..a0e3af0 100644
  193. --- a/release/src/router/rc/wan.c
  194. +++ b/release/src/router/rc/wan.c
  195. @@ -357,7 +357,7 @@ void start_pppoe(int num)
  196.     }
  197.  
  198.  #ifdef TCONFIG_IPV6
  199. -   if (nvram_match("ipv6_service", "native")) {
  200. +   if (nvram_match("ipv6_service", "native") || nvram_match("ipv6_service", "native-pd")) {
  201.         *arg++ = "-6";      // enables IPv6CP
  202.     }
  203.  #endif
  204. @@ -897,6 +897,17 @@ void start_wan_done(char *wan_ifname)
  205.         if (nvram_match("ipv6_service", "native")) {
  206.             eval("ip", "route", "add", "::/0", "dev", nvram_safe_get("wan_iface"));
  207.         }
  208. +       else if (nvram_match("ipv6_service", "native-pd")) {
  209. +           eval("ip", "route", "add", "::/0", "dev", nvram_safe_get("wan_iface"));
  210. +           stop_dhcpv6();
  211. +           stop_radvd();
  212. +           /* note: starting radvd here is really too early because we won't have
  213. +              received a prefix and so it will disable advertisements,
  214. +              but the SIGHUP sent from dhcp6c-state will restart them.
  215. +           */
  216. +           start_radvd();
  217. +           start_dhcpv6();
  218. +       }
  219.         else if (nvram_match("ipv6_service", "sit")) {
  220.             stop_ipv6_sit_tunnel();
  221.             start_ipv6_sit_tunnel();
  222. @@ -943,6 +954,7 @@ void stop_wan(void)
  223.  
  224.  #ifdef TCONFIG_IPV6
  225.     stop_ipv6_sit_tunnel();
  226. +   stop_dhcpv6();
  227.  #endif
  228.  
  229.     /* Kill any WAN client daemons or callbacks */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement