aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-03-20 18:06:23 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-03-20 18:06:23 +0100
commit87fa216e1e388c537cda2cff126eea816a4135ac (patch)
treebfbf5781bd9b33525029c162d59902ac438ea2a4 /networking
parent0f62c4d065bc7fa9d3de52a8482bf48ecfd18ecf (diff)
downloadbusybox-w32-87fa216e1e388c537cda2cff126eea816a4135ac.tar.gz
busybox-w32-87fa216e1e388c537cda2cff126eea816a4135ac.tar.bz2
busybox-w32-87fa216e1e388c537cda2cff126eea816a4135ac.zip
udhcpc: make it possible to disable vendor id; improve help text
function old new delta init_packet 135 139 +4 packed_usage 26789 26786 -3 alloc_dhcp_option 67 63 -4 udhcpc_main 2467 2447 -20 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/3 up/down: 4/-27) Total: -23 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking')
-rw-r--r--networking/udhcp/clientpacket.c6
-rw-r--r--networking/udhcp/dhcpc.c49
-rw-r--r--networking/udhcp/options.c1
-rw-r--r--networking/udhcp/options.h12
4 files changed, 36 insertions, 32 deletions
diff --git a/networking/udhcp/clientpacket.c b/networking/udhcp/clientpacket.c
index f091d8067..a255d6e84 100644
--- a/networking/udhcp/clientpacket.c
+++ b/networking/udhcp/clientpacket.c
@@ -47,8 +47,12 @@ static void init_packet(struct dhcp_packet *packet, char type)
47 add_option_string(packet->options, client_config.hostname); 47 add_option_string(packet->options, client_config.hostname);
48 if (client_config.fqdn) 48 if (client_config.fqdn)
49 add_option_string(packet->options, client_config.fqdn); 49 add_option_string(packet->options, client_config.fqdn);
50 if ((type != DHCPDECLINE) && (type != DHCPRELEASE)) 50 if (type != DHCPDECLINE
51 && type != DHCPRELEASE
52 && client_config.vendorclass
53 ) {
51 add_option_string(packet->options, client_config.vendorclass); 54 add_option_string(packet->options, client_config.vendorclass);
55 }
52} 56}
53 57
54 58
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 9a2fe35e4..3e2cd1217 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -125,8 +125,7 @@ static void client_background(void)
125static uint8_t* alloc_dhcp_option(int code, const char *str, int extra) 125static uint8_t* alloc_dhcp_option(int code, const char *str, int extra)
126{ 126{
127 uint8_t *storage; 127 uint8_t *storage;
128 int len = strlen(str); 128 int len = strnlen(str, 255);
129 if (len > 255) len = 255;
130 storage = xzalloc(len + extra + OPT_DATA); 129 storage = xzalloc(len + extra + OPT_DATA);
131 storage[OPT_CODE] = code; 130 storage[OPT_CODE] = code;
132 storage[OPT_LEN] = len + extra; 131 storage[OPT_LEN] = len + extra;
@@ -139,7 +138,7 @@ int udhcpc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
139int udhcpc_main(int argc UNUSED_PARAM, char **argv) 138int udhcpc_main(int argc UNUSED_PARAM, char **argv)
140{ 139{
141 uint8_t *temp, *message; 140 uint8_t *temp, *message;
142 char *str_c, *str_V, *str_h, *str_F, *str_r; 141 const char *str_c, *str_V, *str_h, *str_F, *str_r;
143 IF_FEATURE_UDHCP_PORT(char *str_P;) 142 IF_FEATURE_UDHCP_PORT(char *str_P;)
144 llist_t *list_O = NULL; 143 llist_t *list_O = NULL;
145 int tryagain_timeout = 20; 144 int tryagain_timeout = 20;
@@ -222,6 +221,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
222 IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;) 221 IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;)
223 client_config.interface = "eth0"; 222 client_config.interface = "eth0";
224 client_config.script = DEFAULT_SCRIPT; 223 client_config.script = DEFAULT_SCRIPT;
224 str_V = "udhcp "BB_VER;
225 225
226 /* Parse command line */ 226 /* Parse command line */
227 /* Cc: mutually exclusive; O: list; -T,-t,-A take numeric param */ 227 /* Cc: mutually exclusive; O: list; -T,-t,-A take numeric param */
@@ -246,23 +246,22 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
246 , &dhcp_verbose 246 , &dhcp_verbose
247#endif 247#endif
248 ); 248 );
249 if (opt & OPT_c)
250 client_config.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, str_c, 0);
251 if (opt & OPT_V)
252 client_config.vendorclass = alloc_dhcp_option(DHCP_VENDOR, str_V, 0);
253 if (opt & (OPT_h|OPT_H)) 249 if (opt & (OPT_h|OPT_H))
254 client_config.hostname = alloc_dhcp_option(DHCP_HOST_NAME, str_h, 0); 250 client_config.hostname = alloc_dhcp_option(DHCP_HOST_NAME, str_h, 0);
255 if (opt & OPT_F) { 251 if (opt & OPT_F) {
252 /* FQDN option format: [0x51][len][flags][0][0]<fqdn> */
256 client_config.fqdn = alloc_dhcp_option(DHCP_FQDN, str_F, 3); 253 client_config.fqdn = alloc_dhcp_option(DHCP_FQDN, str_F, 3);
257 /* Flags: 0000NEOS 254 /* Flag bits: 0000NEOS
258 S: 1 => Client requests Server to update A RR in DNS as well as PTR 255 * S: 1 = Client requests server to update A RR in DNS as well as PTR
259 O: 1 => Server indicates to client that DNS has been updated regardless 256 * O: 1 = Server indicates to client that DNS has been updated regardless
260 E: 1 => Name data is DNS format, i.e. <4>host<6>domain<3>com<0> not "host.domain.com" 257 * E: 1 = Name is in DNS format, i.e. <4>host<6>domain<3>com<0>,
261 N: 1 => Client requests Server to not update DNS 258 * not "host.domain.com". Format 0 is obsolete.
262 */ 259 * N: 1 = Client requests server to not update DNS (S must be 0 then)
260 * Two [0] bytes which follow are deprecated and must be 0.
261 */
263 client_config.fqdn[OPT_DATA + 0] = 0x1; 262 client_config.fqdn[OPT_DATA + 0] = 0x1;
264 /* client_config.fqdn[OPT_DATA + 1] = 0; - redundant */ 263 /*client_config.fqdn[OPT_DATA + 1] = 0; - xzalloc did it */
265 /* client_config.fqdn[OPT_DATA + 2] = 0; - redundant */ 264 /*client_config.fqdn[OPT_DATA + 2] = 0; */
266 } 265 }
267 if (opt & OPT_r) 266 if (opt & OPT_r)
268 requested_ip = inet_addr(str_r); 267 requested_ip = inet_addr(str_r);
@@ -291,6 +290,16 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
291 return 1; 290 return 1;
292 } 291 }
293 292
293 if (opt & OPT_c) {
294 client_config.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, str_c, 0);
295 } else if (!(opt & OPT_C)) {
296 /* not set and not suppressed, set the default client ID */
297 client_config.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, "", 7);
298 client_config.clientid[OPT_DATA] = 1; /* type: ethernet */
299 memcpy(client_config.clientid + OPT_DATA+1, client_config.client_mac, 6);
300 }
301 if (str_V[0] != '\0')
302 client_config.vendorclass = alloc_dhcp_option(DHCP_VENDOR, str_V, 0);
294#if !BB_MMU 303#if !BB_MMU
295 /* on NOMMU reexec (i.e., background) early */ 304 /* on NOMMU reexec (i.e., background) early */
296 if (!(opt & OPT_f)) { 305 if (!(opt & OPT_f)) {
@@ -314,16 +323,6 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
314 /* Goes to stdout (unless NOMMU) and possibly syslog */ 323 /* Goes to stdout (unless NOMMU) and possibly syslog */
315 bb_info_msg("%s (v"BB_VER") started", applet_name); 324 bb_info_msg("%s (v"BB_VER") started", applet_name);
316 325
317 /* If not set, and not suppressed, set up the default client ID */
318 if (!client_config.clientid && !(opt & OPT_C)) {
319 client_config.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, "", 7);
320 client_config.clientid[OPT_DATA] = 1;
321 memcpy(client_config.clientid + OPT_DATA+1, client_config.client_mac, 6);
322 }
323
324 if (!client_config.vendorclass)
325 client_config.vendorclass = alloc_dhcp_option(DHCP_VENDOR, "udhcp "BB_VER, 0);
326
327 /* Set up the signal pipe */ 326 /* Set up the signal pipe */
328 udhcp_sp_setup(); 327 udhcp_sp_setup();
329 328
diff --git a/networking/udhcp/options.c b/networking/udhcp/options.c
index c2a230527..09d31c69b 100644
--- a/networking/udhcp/options.c
+++ b/networking/udhcp/options.c
@@ -13,6 +13,7 @@
13 13
14/* Supported options are easily added here. 14/* Supported options are easily added here.
15 * See RFC2132 for more options. 15 * See RFC2132 for more options.
16 * OPTION_REQ: these options are requested by udhcpc (unless -o).
16 */ 17 */
17const struct dhcp_option dhcp_options[] = { 18const struct dhcp_option dhcp_options[] = {
18 /* flags code */ 19 /* flags code */
diff --git a/networking/udhcp/options.h b/networking/udhcp/options.h
index 2d9c15f8a..75087fa35 100644
--- a/networking/udhcp/options.h
+++ b/networking/udhcp/options.h
@@ -46,9 +46,9 @@ enum {
46#define DHCP_LOG_SERVER 0x07 46#define DHCP_LOG_SERVER 0x07
47//#define DHCP_COOKIE_SERVER 0x08 /* "quote of the day" server */ 47//#define DHCP_COOKIE_SERVER 0x08 /* "quote of the day" server */
48#define DHCP_LPR_SERVER 0x09 48#define DHCP_LPR_SERVER 0x09
49#define DHCP_HOST_NAME 0x0c 49#define DHCP_HOST_NAME 0x0c /* either client informs server or server gives name to client */
50#define DHCP_BOOT_SIZE 0x0d 50#define DHCP_BOOT_SIZE 0x0d
51#define DHCP_DOMAIN_NAME 0x0f 51#define DHCP_DOMAIN_NAME 0x0f /* server gives domain suffix */
52#define DHCP_SWAP_SERVER 0x10 52#define DHCP_SWAP_SERVER 0x10
53#define DHCP_ROOT_PATH 0x11 53#define DHCP_ROOT_PATH 0x11
54#define DHCP_IP_TTL 0x17 54#define DHCP_IP_TTL 0x17
@@ -61,14 +61,14 @@ enum {
61#define DHCP_OPTION_OVERLOAD 0x34 61#define DHCP_OPTION_OVERLOAD 0x34
62#define DHCP_MESSAGE_TYPE 0x35 62#define DHCP_MESSAGE_TYPE 0x35
63#define DHCP_SERVER_ID 0x36 /* by default server's IP */ 63#define DHCP_SERVER_ID 0x36 /* by default server's IP */
64#define DHCP_PARAM_REQ 0x37 64#define DHCP_PARAM_REQ 0x37 /* list of options client wants */
65#define DHCP_MESSAGE 0x38 /* error message when sending NAK etc */ 65#define DHCP_MESSAGE 0x38 /* error message when sending NAK etc */
66#define DHCP_MAX_SIZE 0x39 66#define DHCP_MAX_SIZE 0x39
67//#define DHCP_T1 0x3a 67//#define DHCP_T1 0x3a
68//#define DHCP_T2 0x3b 68//#define DHCP_T2 0x3b
69#define DHCP_VENDOR 0x3c /* client's vendor */ 69#define DHCP_VENDOR 0x3c /* client's vendor (a string) */
70#define DHCP_CLIENT_ID 0x3d /* by default client's MAC addr */ 70#define DHCP_CLIENT_ID 0x3d /* by default client's MAC addr, but may be arbitrarily long */
71#define DHCP_FQDN 0x51 71#define DHCP_FQDN 0x51 /* client asks to update DNS to map its FQDN to its new IP */
72#define DHCP_STATIC_ROUTES 0x79 72#define DHCP_STATIC_ROUTES 0x79
73#define DHCP_END 0xFF 73#define DHCP_END 0xFF
74/* Offsets in option byte sequence */ 74/* Offsets in option byte sequence */