diff options
Diffstat (limited to 'networking/udhcp/dhcpc.c')
-rw-r--r-- | networking/udhcp/dhcpc.c | 49 |
1 files changed, 24 insertions, 25 deletions
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) | |||
125 | static uint8_t* alloc_dhcp_option(int code, const char *str, int extra) | 125 | static 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; | |||
139 | int udhcpc_main(int argc UNUSED_PARAM, char **argv) | 138 | int 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 | ||