From abe4b3c1770b4f03cad23a3af663f4ba8b3576f0 Mon Sep 17 00:00:00 2001 From: Fedor Date: Tue, 23 Feb 2010 21:33:45 -0500 Subject: [PATCH] Busybox udhcpc: support for options 0x21, 0x79, 0xF9 (from 1.15 trunk, and from wl500g.googlecode.com project) --- .../src/router/busybox/networking/udhcp/options.c | 12 +++++- .../src/router/busybox/networking/udhcp/options.h | 10 +++-- .../src/router/busybox/networking/udhcp/script.c | 45 ++++++++++++++++++++++ 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/release/src/router/busybox/networking/udhcp/options.c b/release/src/router/busybox/networking/udhcp/options.c index 143a1fd1ca..179fd55a63 100644 --- a/release/src/router/busybox/networking/udhcp/options.c +++ b/release/src/router/busybox/networking/udhcp/options.c @@ -31,6 +31,7 @@ const struct dhcp_option dhcp_options[] = { { OPTION_U8 , 0x17 }, /* DHCP_IP_TTL */ { OPTION_U16 , 0x1a }, /* DHCP_MTU */ { OPTION_IP | OPTION_REQ, 0x1c }, /* DHCP_BROADCAST */ + { OPTION_IP | OPTION_LIST | OPTION_REQ, 0x21 }, /* routes */ { OPTION_STRING , 0x28 }, /* nisdomain */ { OPTION_IP | OPTION_LIST , 0x29 }, /* nissrv */ { OPTION_IP | OPTION_LIST | OPTION_REQ, 0x2a }, /* DHCP_NTP_SERVER */ @@ -48,6 +49,8 @@ const struct dhcp_option dhcp_options[] = { #if ENABLE_FEATURE_UDHCP_RFC3397 { OPTION_STR1035 | OPTION_LIST , 0x77 }, /* search */ #endif + { OPTION_STATIC_ROUTES , 0x79 }, /* DHCP_STATIC_ROUTES */ + { OPTION_U8 | OPTION_LIST | OPTION_REQ, 0xF9 }, /* msroutes */ /* MSIE's "Web Proxy Autodiscovery Protocol" support */ { OPTION_STRING , 0xfc }, /* wpad */ @@ -80,6 +83,7 @@ const char dhcp_option_strings[] ALIGN1 = "ipttl" "\0" /* DHCP_IP_TTL */ "mtu" "\0" /* DHCP_MTU */ "broadcast" "\0" /* DHCP_BROADCAST */ + "routes" "\0" /* */ "nisdomain" "\0" /* */ "nissrv" "\0" /* */ "ntpsrv" "\0" /* DHCP_NTP_SERVER */ @@ -97,6 +101,8 @@ const char dhcp_option_strings[] ALIGN1 = #if ENABLE_FEATURE_UDHCP_RFC3397 "search" "\0" #endif + "staticroutes" "\0" /* DHCP_STATIC_ROUTES */ + "msroutes" "\0" /* MSIE's "Web Proxy Autodiscovery Protocol" support */ "wpad" "\0" ; @@ -115,7 +121,9 @@ const uint8_t dhcp_option_lengths[] ALIGN1 = { [OPTION_U16] = 2, [OPTION_S16] = 2, [OPTION_U32] = 4, - [OPTION_S32] = 4 + [OPTION_S32] = 4, + /* Just like OPTION_STRING, we use minimum length here */ + [OPTION_STATIC_ROUTES] = 5, }; @@ -159,7 +167,7 @@ uint8_t* FAST_FUNC get_option(struct dhcpMessage *packet, int code) rem = sizeof(packet->sname); continue; } - return NULL; + break; } len = 2 + optionptr[OPT_LEN]; rem -= len; diff --git a/release/src/router/busybox/networking/udhcp/options.h b/release/src/router/busybox/networking/udhcp/options.h index 23370da6e4..3311d17660 100644 --- a/release/src/router/busybox/networking/udhcp/options.h +++ b/release/src/router/busybox/networking/udhcp/options.h @@ -19,11 +19,14 @@ enum { OPTION_U16, OPTION_S16, OPTION_U32, - OPTION_S32 + OPTION_S32, + OPTION_STATIC_ROUTES, }; -#define OPTION_REQ 0x10 /* have the client request this option */ -#define OPTION_LIST 0x20 /* There can be a list of 1 or more of these */ +/* Client requests this option by default */ +#define OPTION_REQ 0x10 +/* There can be a list of 1 or more of these */ +#define OPTION_LIST 0x20 /*****************************************************************/ /* Do not modify below here unless you know what you are doing!! */ @@ -66,6 +69,7 @@ enum { #define DHCP_VENDOR 0x3c #define DHCP_CLIENT_ID 0x3d #define DHCP_FQDN 0x51 +#define DHCP_STATIC_ROUTES 0x79 #define DHCP_END 0xFF /* Offsets in option byte sequence */ #define OPT_CODE 0 diff --git a/release/src/router/busybox/networking/udhcp/script.c b/release/src/router/busybox/networking/udhcp/script.c index 3029b13670..338ba08100 100644 --- a/release/src/router/busybox/networking/udhcp/script.c +++ b/release/src/router/busybox/networking/udhcp/script.c @@ -17,6 +17,7 @@ static const uint8_t max_option_length[] = { [OPTION_IP] = sizeof("255.255.255.255 "), [OPTION_IP_PAIR] = sizeof("255.255.255.255 ") * 2, + [OPTION_STATIC_ROUTES]= sizeof("255.255.255.255/32 255.255.255.255 "), [OPTION_STRING] = 1, #if ENABLE_FEATURE_UDHCP_RFC3397 [OPTION_STR1035] = 1, @@ -109,6 +110,50 @@ static char *alloc_fill_opts(uint8_t *option, const struct dhcp_option *type_p, memcpy(dest, option, len); dest[len] = '\0'; return ret; /* Short circuit this case */ + case OPTION_STATIC_ROUTES: { + /* Option binary format: + * mask [one byte, 0..32] + * ip [big endian, 0..4 bytes depending on mask] + * router [big endian, 4 bytes] + * may be repeated + * + * We convert it to a string "IP/MASK ROUTER IP2/MASK2 ROUTER2" + */ + const char *pfx = ""; + + while(len >= 1 + 4) { /* mask + 0-byte ip + router */ + uint32_t nip; + uint8_t *p; + unsigned mask; + int bytes; + + mask = *option++; + if (mask > 32) + break; + len--; + + nip=0; + p = (void*) &nip; + bytes = (mask+7) / 8; /* 0 -> 0, 1..8 -> 1, 9..16 -> 2 etc */ + while (--bytes >= 0) { + *p++ = *option++; + len--; + } + if (len < 4) + break; + + /* print ip/mask */ + dest += sprintip(dest, pfx, (void*) &nip); + pfx = " "; + dest += sprintf(dest, "/%u ", mask); + /* print router */ + dest += sprintip(dest, "", option); + option += 4; + len -= 4; + } + + return ret; + } #if ENABLE_FEATURE_UDHCP_RFC3397 case OPTION_STR1035: /* unpack option into dest; use ret for prefix (i.e., "optname=") */ -- 2.11.4.GIT