aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-07-03 18:14:03 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-07-03 18:14:03 +0200
commit97ef65483a40f8622aaa73408dc0909f01ebd118 (patch)
treee5ea5c626bedf51c271c480eedbea0b827b1f5ed
parent7895b91743702497efc179a4fe30808e49c67977 (diff)
downloadbusybox-w32-97ef65483a40f8622aaa73408dc0909f01ebd118.tar.gz
busybox-w32-97ef65483a40f8622aaa73408dc0909f01ebd118.tar.bz2
busybox-w32-97ef65483a40f8622aaa73408dc0909f01ebd118.zip
udhcpc: support option 0x79 (static routes) (part of bug 341)
function old new delta xmalloc_optname_optval - 583 +583 dhcp_option_strings 258 266 +8 dhcp_options 70 72 +2 len_of_option_as_string 11 12 +1 dhcp_option_lengths 11 12 +1 udhcp_run_script 1187 669 -518 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 4/1 up/down: 595/-518) Total: 77 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/udhcp/options.c4
-rw-r--r--networking/udhcp/options.h2
-rw-r--r--networking/udhcp/script.c47
3 files changed, 52 insertions, 1 deletions
diff --git a/networking/udhcp/options.c b/networking/udhcp/options.c
index 76d6e3737..ddb894432 100644
--- a/networking/udhcp/options.c
+++ b/networking/udhcp/options.c
@@ -48,6 +48,7 @@ const struct dhcp_option dhcp_options[] = {
48#if ENABLE_FEATURE_UDHCP_RFC3397 48#if ENABLE_FEATURE_UDHCP_RFC3397
49 { OPTION_STR1035 | OPTION_LIST , 0x77 }, /* search */ 49 { OPTION_STR1035 | OPTION_LIST , 0x77 }, /* search */
50#endif 50#endif
51 { OPTION_STATIC_ROUTES , 0x79 }, /* DHCP_STATIC_ROUTES */
51 /* MSIE's "Web Proxy Autodiscovery Protocol" support */ 52 /* MSIE's "Web Proxy Autodiscovery Protocol" support */
52 { OPTION_STRING , 0xfc }, /* wpad */ 53 { OPTION_STRING , 0xfc }, /* wpad */
53 54
@@ -97,6 +98,7 @@ const char dhcp_option_strings[] ALIGN1 =
97#if ENABLE_FEATURE_UDHCP_RFC3397 98#if ENABLE_FEATURE_UDHCP_RFC3397
98 "search" "\0" 99 "search" "\0"
99#endif 100#endif
101 "staticroutes" "\0" /* DHCP_STATIC_ROUTES */
100 /* MSIE's "Web Proxy Autodiscovery Protocol" support */ 102 /* MSIE's "Web Proxy Autodiscovery Protocol" support */
101 "wpad" "\0" 103 "wpad" "\0"
102 ; 104 ;
@@ -116,6 +118,8 @@ const uint8_t dhcp_option_lengths[] ALIGN1 = {
116 [OPTION_S16] = 2, 118 [OPTION_S16] = 2,
117 [OPTION_U32] = 4, 119 [OPTION_U32] = 4,
118 [OPTION_S32] = 4, 120 [OPTION_S32] = 4,
121 /* Just like OPTION_STRING, we use minimum length here */
122 [OPTION_STATIC_ROUTES] = 5,
119}; 123};
120 124
121 125
diff --git a/networking/udhcp/options.h b/networking/udhcp/options.h
index 9e624318f..aeed36907 100644
--- a/networking/udhcp/options.h
+++ b/networking/udhcp/options.h
@@ -20,6 +20,7 @@ enum {
20 OPTION_S16, 20 OPTION_S16,
21 OPTION_U32, 21 OPTION_U32,
22 OPTION_S32, 22 OPTION_S32,
23 OPTION_STATIC_ROUTES,
23}; 24};
24 25
25/* Client requests this option by default */ 26/* Client requests this option by default */
@@ -68,6 +69,7 @@ enum {
68#define DHCP_VENDOR 0x3c 69#define DHCP_VENDOR 0x3c
69#define DHCP_CLIENT_ID 0x3d 70#define DHCP_CLIENT_ID 0x3d
70#define DHCP_FQDN 0x51 71#define DHCP_FQDN 0x51
72#define DHCP_STATIC_ROUTES 0x79
71#define DHCP_END 0xFF 73#define DHCP_END 0xFF
72/* Offsets in option byte sequence */ 74/* Offsets in option byte sequence */
73#define OPT_CODE 0 75#define OPT_CODE 0
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c
index 94dabf4d1..f315008a3 100644
--- a/networking/udhcp/script.c
+++ b/networking/udhcp/script.c
@@ -17,6 +17,7 @@
17static const uint8_t len_of_option_as_string[] = { 17static const uint8_t len_of_option_as_string[] = {
18 [OPTION_IP] = sizeof("255.255.255.255 "), 18 [OPTION_IP] = sizeof("255.255.255.255 "),
19 [OPTION_IP_PAIR] = sizeof("255.255.255.255 ") * 2, 19 [OPTION_IP_PAIR] = sizeof("255.255.255.255 ") * 2,
20 [OPTION_STATIC_ROUTES]= sizeof("255.255.255.255/32 255.255.255.255 "),
20 [OPTION_STRING] = 1, 21 [OPTION_STRING] = 1,
21#if ENABLE_FEATURE_UDHCP_RFC3397 22#if ENABLE_FEATURE_UDHCP_RFC3397
22 [OPTION_STR1035] = 1, 23 [OPTION_STR1035] = 1,
@@ -51,7 +52,7 @@ static int mton(uint32_t mask)
51 52
52 53
53/* Create "opt_name=opt_value" string */ 54/* Create "opt_name=opt_value" string */
54static char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_option *type_p, const char *opt_name) 55static NOINLINE char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_option *type_p, const char *opt_name)
55{ 56{
56 unsigned upper_length; 57 unsigned upper_length;
57 int len, type, optlen; 58 int len, type, optlen;
@@ -106,6 +107,50 @@ static char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_option *t
106 memcpy(dest, option, len); 107 memcpy(dest, option, len);
107 dest[len] = '\0'; 108 dest[len] = '\0';
108 return ret; /* Short circuit this case */ 109 return ret; /* Short circuit this case */
110 case OPTION_STATIC_ROUTES: {
111 /* Option binary format:
112 * mask [one byte, 0..32]
113 * ip [big endian, 0..4 bytes depending on mask]
114 * router [big endian, 4 bytes]
115 * may be repeated
116 *
117 * We convert it to a string "IP/MASK ROUTER IP2/MASK2 ROUTER2"
118 */
119 const char *pfx = "";
120
121 while (len >= 1 + 4) { /* mask + 0-byte ip + router */
122 uint32_t nip;
123 uint8_t *p;
124 unsigned mask;
125 int bytes;
126
127 mask = *option++;
128 if (mask > 32)
129 break;
130 len--;
131
132 nip = 0;
133 p = (void*) &nip;
134 bytes = (mask + 7) / 8; /* 0 -> 0, 1..8 -> 1, 9..16 -> 2 etc */
135 while (--bytes >= 0) {
136 *p++ = *option++;
137 len--;
138 }
139 if (len < 4)
140 break;
141
142 /* print ip/mask */
143 dest += sprint_nip(dest, pfx, (void*) &nip);
144 pfx = " ";
145 dest += sprintf(dest, "/%u ", mask);
146 /* print router */
147 dest += sprint_nip(dest, "", option);
148 option += 4;
149 len -= 4;
150 }
151
152 return ret;
153 }
109#if ENABLE_FEATURE_UDHCP_RFC3397 154#if ENABLE_FEATURE_UDHCP_RFC3397
110 case OPTION_STR1035: 155 case OPTION_STR1035:
111 /* unpack option into dest; use ret for prefix (i.e., "optname=") */ 156 /* unpack option into dest; use ret for prefix (i.e., "optname=") */