aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/usage.h12
-rw-r--r--networking/ifupdown.c5
-rw-r--r--networking/udhcp/clientpacket.c15
-rw-r--r--networking/udhcp/dhcpc.c6
-rw-r--r--networking/udhcp/dhcpc.h1
-rw-r--r--networking/udhcp/files.c6
6 files changed, 30 insertions, 15 deletions
diff --git a/include/usage.h b/include/usage.h
index 3be317bff..529a228ec 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -4116,7 +4116,7 @@
4116 "Adjust filesystem options on ext[23] filesystems" 4116 "Adjust filesystem options on ext[23] filesystems"
4117 4117
4118#define udhcpc_trivial_usage \ 4118#define udhcpc_trivial_usage \
4119 "[-Cfbnqtv] [-c CID] [-V VCLS] [-H HOSTNAME] [-i INTERFACE]\n" \ 4119 "[-Cfbnqtvo] [-c CID] [-V VCLS] [-H HOSTNAME] [-i INTERFACE]\n" \
4120 " [-p pidfile] [-r IP] [-s script] [-O dhcp-option]..." USE_FEATURE_UDHCP_PORT(" [-P N]") 4120 " [-p pidfile] [-r IP] [-s script] [-O dhcp-option]..." USE_FEATURE_UDHCP_PORT(" [-P N]")
4121#define udhcpc_full_usage \ 4121#define udhcpc_full_usage \
4122 USE_GETOPT_LONG( \ 4122 USE_GETOPT_LONG( \
@@ -4127,17 +4127,18 @@
4127 "\n -C,--clientid-none Suppress default client identifier" \ 4127 "\n -C,--clientid-none Suppress default client identifier" \
4128 "\n -p,--pidfile=file Create pidfile" \ 4128 "\n -p,--pidfile=file Create pidfile" \
4129 "\n -r,--request=IP IP address to request" \ 4129 "\n -r,--request=IP IP address to request" \
4130 "\n -s,--script=file Run file at dhcp events (default /usr/share/udhcpc/default.script)" \ 4130 "\n -s,--script=file Run file at DHCP events (default "CONFIG_DHCPC_DEFAULT_SCRIPT")" \
4131 "\n -t,--retries=N Send up to N request packets" \ 4131 "\n -t,--retries=N Send up to N request packets" \
4132 "\n -T,--timeout=N Try to get a lease for N seconds (default 3)" \ 4132 "\n -T,--timeout=N Try to get a lease for N seconds (default 3)" \
4133 "\n -A,--tryagain=N Wait N seconds (default 20) after failure" \ 4133 "\n -A,--tryagain=N Wait N seconds (default 20) after failure" \
4134 "\n -O,--request-option=OPT Request DHCP option OPT (cumulative)" \
4135 "\n -o,--no-default-options Do not request any options (unless -O is also given)" \
4134 "\n -f,--foreground Run in foreground" \ 4136 "\n -f,--foreground Run in foreground" \
4135 "\n -b,--background Background if lease is not immediately obtained" \ 4137 "\n -b,--background Background if lease is not immediately obtained" \
4136 "\n -S,--syslog Log to syslog too" \ 4138 "\n -S,--syslog Log to syslog too" \
4137 "\n -n,--now Exit with failure if lease is not immediately obtained" \ 4139 "\n -n,--now Exit with failure if lease is not immediately obtained" \
4138 "\n -q,--quit Quit after obtaining lease" \ 4140 "\n -q,--quit Quit after obtaining lease" \
4139 "\n -R,--release Release IP on quit" \ 4141 "\n -R,--release Release IP on quit" \
4140 "\n -O,--request-option=OPT Request DHCP option OPT from server" \
4141 USE_FEATURE_UDHCP_PORT( \ 4142 USE_FEATURE_UDHCP_PORT( \
4142 "\n -P,--client-port N Use port N instead of default 68" \ 4143 "\n -P,--client-port N Use port N instead of default 68" \
4143 ) \ 4144 ) \
@@ -4153,17 +4154,18 @@
4153 "\n -C Suppress default client identifier" \ 4154 "\n -C Suppress default client identifier" \
4154 "\n -p file Create pidfile" \ 4155 "\n -p file Create pidfile" \
4155 "\n -r IP IP address to request" \ 4156 "\n -r IP IP address to request" \
4156 "\n -s file Run file at dhcp events (default /usr/share/udhcpc/default.script)" \ 4157 "\n -s file Run file at DHCP events (default "CONFIG_DHCPC_DEFAULT_SCRIPT")" \
4157 "\n -t N Send up to N request packets" \ 4158 "\n -t N Send up to N request packets" \
4158 "\n -T N Try to get a lease for N seconds (default 3)" \ 4159 "\n -T N Try to get a lease for N seconds (default 3)" \
4159 "\n -A N Wait N seconds (default 20) after failure" \ 4160 "\n -A N Wait N seconds (default 20) after failure" \
4161 "\n -O OPT Request DHCP option OPT (cumulative)" \
4162 "\n -o Do not request any options (unless -O is also given)" \
4160 "\n -f Run in foreground" \ 4163 "\n -f Run in foreground" \
4161 "\n -b Background if lease is not immediately obtained" \ 4164 "\n -b Background if lease is not immediately obtained" \
4162 "\n -S Log to syslog too" \ 4165 "\n -S Log to syslog too" \
4163 "\n -n Exit with failure if lease is not immediately obtained" \ 4166 "\n -n Exit with failure if lease is not immediately obtained" \
4164 "\n -q Quit after obtaining lease" \ 4167 "\n -q Quit after obtaining lease" \
4165 "\n -R Release IP on quit" \ 4168 "\n -R Release IP on quit" \
4166 "\n -O OPT Request DHCP option OPT from server" \
4167 USE_FEATURE_UDHCP_PORT( \ 4169 USE_FEATURE_UDHCP_PORT( \
4168 "\n -P N Use port N instead of default 68" \ 4170 "\n -P N Use port N instead of default 68" \
4169 ) \ 4171 ) \
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index 7c31448e8..50b96261b 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -476,7 +476,8 @@ static const struct dhcp_client_t ext_dhcp_clients[] = {
476 "pump -i %iface% -k", 476 "pump -i %iface% -k",
477 }, 477 },
478 { "udhcpc", 478 { "udhcpc",
479 "udhcpc -R -n -p /var/run/udhcpc.%iface%.pid -i %iface%[[ -H %hostname%]][[ -c %clientid%]][[ -s %script%]][[ -t %retries%]]", 479 "udhcpc -R -n -p /var/run/udhcpc.%iface%.pid -i %iface%[[ -H %hostname%]][[ -c %clientid%]]"
480 "[[ -s %script%]][[ %udhcpc_opts%]]",
480 "kill `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", 481 "kill `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null",
481 }, 482 },
482}; 483};
@@ -507,7 +508,7 @@ static int dhcp_up(struct interface_defn_t *ifd, execfn *exec)
507 return 0; 508 return 0;
508#endif 509#endif
509 return execute("udhcpc -R -n -p /var/run/udhcpc.%iface%.pid " 510 return execute("udhcpc -R -n -p /var/run/udhcpc.%iface%.pid "
510 "-i %iface%[[ -H %hostname%]][[ -c %clientid%]][[ -s %script%]][[ -t %retries%]]", 511 "-i %iface%[[ -H %hostname%]][[ -c %clientid%]][[ -s %script%]][[ %udhcpc_opts%]]",
511 ifd, exec); 512 ifd, exec);
512} 513}
513#else 514#else
diff --git a/networking/udhcp/clientpacket.c b/networking/udhcp/clientpacket.c
index 29d0d9a1d..f826c1b94 100644
--- a/networking/udhcp/clientpacket.c
+++ b/networking/udhcp/clientpacket.c
@@ -62,17 +62,20 @@ static void add_param_req_option(struct dhcpMessage *packet)
62 int end = end_option(packet->options); 62 int end = end_option(packet->options);
63 int i, len = 0; 63 int i, len = 0;
64 64
65 packet->options[end + OPT_CODE] = DHCP_PARAM_REQ;
66 for (i = 0; (c = dhcp_options[i].code) != 0; i++) { 65 for (i = 0; (c = dhcp_options[i].code) != 0; i++) {
67 if ((dhcp_options[i].flags & OPTION_REQ) 66 if (((dhcp_options[i].flags & OPTION_REQ)
67 && !client_config.no_default_options)
68 || (client_config.opt_mask[c >> 3] & (1 << (c & 7))) 68 || (client_config.opt_mask[c >> 3] & (1 << (c & 7)))
69 ) { 69 ) {
70 packet->options[end + OPT_DATA + len] = c; 70 packet->options[end + OPT_DATA + len] = c;
71 len++; 71 len++;
72 } 72 }
73 } 73 }
74 packet->options[end + OPT_LEN] = len; 74 if (len) {
75 packet->options[end + OPT_DATA + len] = DHCP_END; 75 packet->options[end + OPT_CODE] = DHCP_PARAM_REQ;
76 packet->options[end + OPT_LEN] = len;
77 packet->options[end + OPT_DATA + len] = DHCP_END;
78 }
76} 79}
77 80
78 81
@@ -107,7 +110,9 @@ int send_discover(uint32_t xid, uint32_t requested)
107 /* Explicitly saying that we want RFC-compliant packets helps 110 /* Explicitly saying that we want RFC-compliant packets helps
108 * some buggy DHCP servers to NOT send bigger packets */ 111 * some buggy DHCP servers to NOT send bigger packets */
109 add_simple_option(packet.options, DHCP_MAX_SIZE, htons(576)); 112 add_simple_option(packet.options, DHCP_MAX_SIZE, htons(576));
113
110 add_param_req_option(&packet); 114 add_param_req_option(&packet);
115
111 bb_info_msg("Sending discover..."); 116 bb_info_msg("Sending discover...");
112 return udhcp_send_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, 117 return udhcp_send_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
113 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); 118 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
@@ -125,8 +130,8 @@ int send_selecting(uint32_t xid, uint32_t server, uint32_t requested)
125 130
126 add_simple_option(packet.options, DHCP_REQUESTED_IP, requested); 131 add_simple_option(packet.options, DHCP_REQUESTED_IP, requested);
127 add_simple_option(packet.options, DHCP_SERVER_ID, server); 132 add_simple_option(packet.options, DHCP_SERVER_ID, server);
128
129 add_param_req_option(&packet); 133 add_param_req_option(&packet);
134
130 addr.s_addr = requested; 135 addr.s_addr = requested;
131 bb_info_msg("Sending select for %s...", inet_ntoa(addr)); 136 bb_info_msg("Sending select for %s...", inet_ntoa(addr));
132 return udhcp_send_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, 137 return udhcp_send_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index bc0676152..fb328cb03 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -182,6 +182,7 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv)
182 OPT_W = 1 << 21, 182 OPT_W = 1 << 21,
183#endif 183#endif
184 OPT_P = 1 << 22, 184 OPT_P = 1 << 22,
185 OPT_o = 1 << 23,
185 }; 186 };
186#if ENABLE_GETOPT_LONG 187#if ENABLE_GETOPT_LONG
187 static const char udhcpc_longopts[] ALIGN1 = 188 static const char udhcpc_longopts[] ALIGN1 =
@@ -211,6 +212,7 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv)
211#if ENABLE_FEATURE_UDHCP_PORT 212#if ENABLE_FEATURE_UDHCP_PORT
212 "client-port\0" Required_argument "P" 213 "client-port\0" Required_argument "P"
213#endif 214#endif
215 "no-default-options\0" No_argument "o"
214 ; 216 ;
215#endif 217#endif
216 /* Default options. */ 218 /* Default options. */
@@ -230,7 +232,7 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv)
230 opt = getopt32(argv, "c:CV:fbH:h:F:i:np:qRr:s:T:t:vSA:" 232 opt = getopt32(argv, "c:CV:fbH:h:F:i:np:qRr:s:T:t:vSA:"
231 USE_FEATURE_UDHCPC_ARPING("aW:") 233 USE_FEATURE_UDHCPC_ARPING("aW:")
232 USE_FEATURE_UDHCP_PORT("P:") 234 USE_FEATURE_UDHCP_PORT("P:")
233 "O:" 235 "O:o"
234 , &str_c, &str_V, &str_h, &str_h, &str_F 236 , &str_c, &str_V, &str_h, &str_h, &str_F
235 , &client_config.interface, &client_config.pidfile, &str_r 237 , &client_config.interface, &client_config.pidfile, &str_r
236 , &client_config.script 238 , &client_config.script
@@ -291,6 +293,8 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv)
291 SERVER_PORT = CLIENT_PORT - 1; 293 SERVER_PORT = CLIENT_PORT - 1;
292 } 294 }
293#endif 295#endif
296 if (opt & OPT_o)
297 client_config.no_default_options = 1;
294 while (list_O) { 298 while (list_O) {
295 int n = index_in_strings(dhcp_option_strings, list_O->data); 299 int n = index_in_strings(dhcp_option_strings, list_O->data);
296 if (n < 0) 300 if (n < 0)
diff --git a/networking/udhcp/dhcpc.h b/networking/udhcp/dhcpc.h
index d0fde7302..c8acd4982 100644
--- a/networking/udhcp/dhcpc.h
+++ b/networking/udhcp/dhcpc.h
@@ -21,6 +21,7 @@ struct client_config_t {
21 char release_on_quit; /* Perform release on quit */ 21 char release_on_quit; /* Perform release on quit */
22 char abort_if_no_lease; /* Abort if no lease */ 22 char abort_if_no_lease; /* Abort if no lease */
23 char background_if_no_lease; /* Fork to background if no lease */ 23 char background_if_no_lease; /* Fork to background if no lease */
24 char no_default_options; /* Do not include default optins in request */
24 const char *interface; /* The name of the interface to use */ 25 const char *interface; /* The name of the interface to use */
25 char *pidfile; /* Optionally store the process ID */ 26 char *pidfile; /* Optionally store the process ID */
26 const char *script; /* User script to run at dhcp events */ 27 const char *script; /* User script to run at dhcp events */
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c
index 6a93bd0e2..043a95bb0 100644
--- a/networking/udhcp/files.c
+++ b/networking/udhcp/files.c
@@ -396,6 +396,7 @@ void write_leases(void)
396 close(fp); 396 close(fp);
397 397
398 if (server_config.notify_file) { 398 if (server_config.notify_file) {
399// TODO: vfork-based child creation
399 char *cmd = xasprintf("%s %s", server_config.notify_file, server_config.lease_file); 400 char *cmd = xasprintf("%s %s", server_config.notify_file, server_config.lease_file);
400 system(cmd); 401 system(cmd);
401 free(cmd); 402 free(cmd);
@@ -406,7 +407,7 @@ void write_leases(void)
406void read_leases(const char *file) 407void read_leases(const char *file)
407{ 408{
408 int fp; 409 int fp;
409 unsigned int i = 0; 410 unsigned i;
410 struct dhcpOfferedAddr lease; 411 struct dhcpOfferedAddr lease;
411 412
412 fp = open_or_warn(file, O_RDONLY); 413 fp = open_or_warn(file, O_RDONLY);
@@ -414,6 +415,7 @@ void read_leases(const char *file)
414 return; 415 return;
415 } 416 }
416 417
418 i = 0;
417 while (i < server_config.max_leases 419 while (i < server_config.max_leases
418 && full_read(fp, &lease, sizeof(lease)) == sizeof(lease) 420 && full_read(fp, &lease, sizeof(lease)) == sizeof(lease)
419 ) { 421 ) {
@@ -422,7 +424,7 @@ void read_leases(const char *file)
422 if (y >= server_config.start_ip && y <= server_config.end_ip) { 424 if (y >= server_config.start_ip && y <= server_config.end_ip) {
423 lease.expires = ntohl(lease.expires); 425 lease.expires = ntohl(lease.expires);
424 if (!server_config.remaining) 426 if (!server_config.remaining)
425 lease.expires -= time(0); 427 lease.expires -= time(NULL);
426 if (!(add_lease(lease.chaddr, lease.yiaddr, lease.expires))) { 428 if (!(add_lease(lease.chaddr, lease.yiaddr, lease.expires))) {
427 bb_error_msg("too many leases while loading %s", file); 429 bb_error_msg("too many leases while loading %s", file);
428 break; 430 break;