aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-12-10 07:03:38 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-12-10 07:03:38 +0000
commit191836845e4551fe6191dc0d43b45a0232bff8be (patch)
treee6fd859b756304842334d0e0603856be2a5948e6
parent75aa615bef478622cd0695b95adcf182fbbc3d95 (diff)
downloadbusybox-w32-191836845e4551fe6191dc0d43b45a0232bff8be.tar.gz
busybox-w32-191836845e4551fe6191dc0d43b45a0232bff8be.tar.bz2
busybox-w32-191836845e4551fe6191dc0d43b45a0232bff8be.zip
udhcpc: support for -O <option>.
Two important notes: * nissrv and nisdomain are not requested by default anymore! * inconsistency between "XXXsvr" and "XXsrv" in option names resolved, all are "XXXsrv" now. function old new delta udhcpc_main 2494 2600 +106 packed_usage 23023 23067 +44 add_requests 91 119 +28 static.udhcpc_longopts 209 226 +17 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/0 up/down: 195/0) Total: 195 bytes
-rw-r--r--include/usage.h4
-rw-r--r--networking/udhcp/clientpacket.c11
-rw-r--r--networking/udhcp/dhcpc.c61
-rw-r--r--networking/udhcp/dhcpc.h1
-rw-r--r--networking/udhcp/options.c98
5 files changed, 97 insertions, 78 deletions
diff --git a/include/usage.h b/include/usage.h
index f6506b4f8..12d2cefd9 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -3840,7 +3840,7 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
3840 3840
3841#define udhcpc_trivial_usage \ 3841#define udhcpc_trivial_usage \
3842 "[-Cfbnqtv] [-c CID] [-V VCLS] [-H HOSTNAME] [-i INTERFACE]\n" \ 3842 "[-Cfbnqtv] [-c CID] [-V VCLS] [-H HOSTNAME] [-i INTERFACE]\n" \
3843 " [-p pidfile] [-r IP] [-s script]" 3843 " [-p pidfile] [-r IP] [-s script] [-O dhcp-option]..."
3844#define udhcpc_full_usage \ 3844#define udhcpc_full_usage \
3845 USE_GETOPT_LONG( \ 3845 USE_GETOPT_LONG( \
3846 " -V,--vendorclass=CLASSID Vendor class identifier" \ 3846 " -V,--vendorclass=CLASSID Vendor class identifier" \
@@ -3860,6 +3860,7 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
3860 "\n -n,--now Exit with failure if lease is not immediately obtained" \ 3860 "\n -n,--now Exit with failure if lease is not immediately obtained" \
3861 "\n -q,--quit Quit after obtaining lease" \ 3861 "\n -q,--quit Quit after obtaining lease" \
3862 "\n -R,--release Release IP on quit" \ 3862 "\n -R,--release Release IP on quit" \
3863 "\n -O,--request-option=OPT Request DHCP option OPT from server" \
3863 USE_FEATURE_UDHCPC_ARPING( \ 3864 USE_FEATURE_UDHCPC_ARPING( \
3864 "\n -a,--arping Use arping to validate offered address" \ 3865 "\n -a,--arping Use arping to validate offered address" \
3865 ) \ 3866 ) \
@@ -3882,6 +3883,7 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
3882 "\n -n Exit with failure if lease is not immediately obtained" \ 3883 "\n -n Exit with failure if lease is not immediately obtained" \
3883 "\n -q Quit after obtaining lease" \ 3884 "\n -q Quit after obtaining lease" \
3884 "\n -R Release IP on quit" \ 3885 "\n -R Release IP on quit" \
3886 "\n -O OPT Request DHCP option OPT from server" \
3885 USE_FEATURE_UDHCPC_ARPING( \ 3887 USE_FEATURE_UDHCPC_ARPING( \
3886 "\n -a Use arping to validate offered address" \ 3888 "\n -a Use arping to validate offered address" \
3887 ) \ 3889 ) \
diff --git a/networking/udhcp/clientpacket.c b/networking/udhcp/clientpacket.c
index 406fe340a..54f3f0e49 100644
--- a/networking/udhcp/clientpacket.c
+++ b/networking/udhcp/clientpacket.c
@@ -57,13 +57,18 @@ static void init_packet(struct dhcpMessage *packet, char type)
57 * goes towards the head of the packet. */ 57 * goes towards the head of the packet. */
58static void add_requests(struct dhcpMessage *packet) 58static void add_requests(struct dhcpMessage *packet)
59{ 59{
60 uint8_t c;
60 int end = end_option(packet->options); 61 int end = end_option(packet->options);
61 int i, len = 0; 62 int i, len = 0;
62 63
63 packet->options[end + OPT_CODE] = DHCP_PARAM_REQ; 64 packet->options[end + OPT_CODE] = DHCP_PARAM_REQ;
64 for (i = 0; dhcp_options[i].code; i++) 65 for (i = 0; (c = dhcp_options[i].code) != 0; i++) {
65 if (dhcp_options[i].flags & OPTION_REQ) 66 if (dhcp_options[i].flags & OPTION_REQ
66 packet->options[end + OPT_DATA + len++] = dhcp_options[i].code; 67 || (client_config.opt_mask[c >> 3] & (1 << (c & 7)))
68 ) {
69 packet->options[end + OPT_DATA + len++] = c;
70 }
71 }
67 packet->options[end + OPT_LEN] = len; 72 packet->options[end + OPT_LEN] = len;
68 packet->options[end + OPT_DATA + len] = DHCP_END; 73 packet->options[end + OPT_DATA + len] = DHCP_END;
69 74
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index d8077f7e8..69c35ca50 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -133,6 +133,7 @@ int udhcpc_main(int argc, char **argv)
133{ 133{
134 uint8_t *temp, *message; 134 uint8_t *temp, *message;
135 char *str_c, *str_V, *str_h, *str_F, *str_r, *str_T, *str_A, *str_t; 135 char *str_c, *str_V, *str_h, *str_F, *str_r, *str_T, *str_A, *str_t;
136 llist_t *list_O = NULL;
136#if ENABLE_FEATURE_UDHCPC_ARPING 137#if ENABLE_FEATURE_UDHCPC_ARPING
137 char *str_W; 138 char *str_W;
138#endif 139#endif
@@ -183,28 +184,29 @@ int udhcpc_main(int argc, char **argv)
183 }; 184 };
184#if ENABLE_GETOPT_LONG 185#if ENABLE_GETOPT_LONG
185 static const char udhcpc_longopts[] ALIGN1 = 186 static const char udhcpc_longopts[] ALIGN1 =
186 "clientid\0" Required_argument "c" 187 "clientid\0" Required_argument "c"
187 "clientid-none\0" No_argument "C" 188 "clientid-none\0" No_argument "C"
188 "vendorclass\0" Required_argument "V" 189 "vendorclass\0" Required_argument "V"
189 "foreground\0" No_argument "f" 190 "foreground\0" No_argument "f"
190 "background\0" No_argument "b" 191 "background\0" No_argument "b"
191 "hostname\0" Required_argument "H" 192 "hostname\0" Required_argument "H"
192 "fqdn\0" Required_argument "F" 193 "fqdn\0" Required_argument "F"
193 "interface\0" Required_argument "i" 194 "interface\0" Required_argument "i"
194 "now\0" No_argument "n" 195 "now\0" No_argument "n"
195 "pidfile\0" Required_argument "p" 196 "pidfile\0" Required_argument "p"
196 "quit\0" No_argument "q" 197 "quit\0" No_argument "q"
197 "release\0" No_argument "R" 198 "release\0" No_argument "R"
198 "request\0" Required_argument "r" 199 "request\0" Required_argument "r"
199 "script\0" Required_argument "s" 200 "script\0" Required_argument "s"
200 "timeout\0" Required_argument "T" 201 "timeout\0" Required_argument "T"
201 "version\0" No_argument "v" 202 "version\0" No_argument "v"
202 "retries\0" Required_argument "t" 203 "retries\0" Required_argument "t"
203 "tryagain\0" Required_argument "A" 204 "tryagain\0" Required_argument "A"
204 "syslog\0" No_argument "S" 205 "syslog\0" No_argument "S"
205#if ENABLE_FEATURE_UDHCPC_ARPING 206#if ENABLE_FEATURE_UDHCPC_ARPING
206 "arping\0" No_argument "a" 207 "arping\0" No_argument "a"
207#endif 208#endif
209 "request-option\0" Required_argument "O"
208 ; 210 ;
209#endif 211#endif
210 /* Default options. */ 212 /* Default options. */
@@ -212,16 +214,18 @@ int udhcpc_main(int argc, char **argv)
212 client_config.script = DEFAULT_SCRIPT; 214 client_config.script = DEFAULT_SCRIPT;
213 215
214 /* Parse command line */ 216 /* Parse command line */
215 opt_complementary = "c--C:C--c"; // mutually exclusive 217 opt_complementary = "c--C:C--c:O::"; // Cc: mutually exclusive; O: list
216#if ENABLE_GETOPT_LONG 218#if ENABLE_GETOPT_LONG
217 applet_long_options = udhcpc_longopts; 219 applet_long_options = udhcpc_longopts;
218#endif 220#endif
219 opt = getopt32(argv, "c:CV:fbH:h:F:i:np:qRr:s:T:t:vSA:" 221 opt = getopt32(argv, "c:CV:fbH:h:F:i:np:qRr:s:T:t:vSA:"
220 USE_FEATURE_UDHCPC_ARPING("aW:") 222 USE_FEATURE_UDHCPC_ARPING("aW:")
221 , &str_c, &str_V, &str_h, &str_h, &str_F, 223 "O:"
222 &client_config.interface, &client_config.pidfile, &str_r, 224 , &str_c, &str_V, &str_h, &str_h, &str_F
223 &client_config.script, &str_T, &str_t, &str_A 225 , &client_config.interface, &client_config.pidfile, &str_r
226 , &client_config.script, &str_T, &str_t, &str_A
224 USE_FEATURE_UDHCPC_ARPING(, &str_W) 227 USE_FEATURE_UDHCPC_ARPING(, &str_W)
228 , &list_O
225 ); 229 );
226 230
227 if (opt & OPT_c) 231 if (opt & OPT_c)
@@ -268,11 +272,18 @@ int udhcpc_main(int argc, char **argv)
268 puts("version "BB_VER); 272 puts("version "BB_VER);
269 return 0; 273 return 0;
270 } 274 }
271
272 if (opt & OPT_S) { 275 if (opt & OPT_S) {
273 openlog(applet_name, LOG_PID, LOG_LOCAL0); 276 openlog(applet_name, LOG_PID, LOG_LOCAL0);
274 logmode |= LOGMODE_SYSLOG; 277 logmode |= LOGMODE_SYSLOG;
275 } 278 }
279 while (list_O) {
280 int n = index_in_strings(dhcp_option_strings, list_O->data);
281 if (n < 0)
282 bb_error_msg_and_die("unknown option '%s'", list_O->data);
283 n = dhcp_options[n].code;
284 client_config.opt_mask[n >> 3] |= 1 << (n & 7);
285 list_O = list_O->link;
286 }
276 287
277 if (read_interface(client_config.interface, &client_config.ifindex, 288 if (read_interface(client_config.interface, &client_config.ifindex,
278 NULL, client_config.arp)) 289 NULL, client_config.arp))
diff --git a/networking/udhcp/dhcpc.h b/networking/udhcp/dhcpc.h
index c0172a84f..e818896c9 100644
--- a/networking/udhcp/dhcpc.h
+++ b/networking/udhcp/dhcpc.h
@@ -30,6 +30,7 @@ struct client_config_t {
30 uint8_t *fqdn; /* Optional fully qualified domain name to use */ 30 uint8_t *fqdn; /* Optional fully qualified domain name to use */
31 int ifindex; /* Index number of the interface to use */ 31 int ifindex; /* Index number of the interface to use */
32 uint8_t arp[6]; /* Our arp address */ 32 uint8_t arp[6]; /* Our arp address */
33 uint8_t opt_mask[256 / 8]; /* Bitmask of options to send (-O option) */
33}; 34};
34 35
35#define client_config (*(struct client_config_t*)&bb_common_bufsiz1) 36#define client_config (*(struct client_config_t*)&bb_common_bufsiz1)
diff --git a/networking/udhcp/options.c b/networking/udhcp/options.c
index c224f3670..12e566210 100644
--- a/networking/udhcp/options.c
+++ b/networking/udhcp/options.c
@@ -11,49 +11,49 @@
11 11
12/* Supported options are easily added here */ 12/* Supported options are easily added here */
13const struct dhcp_option dhcp_options[] = { 13const struct dhcp_option dhcp_options[] = {
14 /* flags code */ 14 /* flags code */
15 { OPTION_IP | OPTION_REQ, 0x01 }, /* DHCP_SUBNET */ 15 { OPTION_IP | OPTION_REQ, 0x01 }, /* DHCP_SUBNET */
16 { OPTION_S32, 0x02 }, /* DHCP_TIME_OFFSET */ 16 { OPTION_S32 , 0x02 }, /* DHCP_TIME_OFFSET */
17 { OPTION_IP | OPTION_LIST | OPTION_REQ, 0x03 }, /* DHCP_ROUTER */ 17 { OPTION_IP | OPTION_LIST | OPTION_REQ, 0x03 }, /* DHCP_ROUTER */
18 { OPTION_IP | OPTION_LIST, 0x04 }, /* DHCP_TIME_SERVER */ 18 { OPTION_IP | OPTION_LIST , 0x04 }, /* DHCP_TIME_SERVER */
19 { OPTION_IP | OPTION_LIST, 0x05 }, /* DHCP_NAME_SERVER */ 19 { OPTION_IP | OPTION_LIST , 0x05 }, /* DHCP_NAME_SERVER */
20 { OPTION_IP | OPTION_LIST | OPTION_REQ, 0x06 }, /* DHCP_DNS_SERVER */ 20 { OPTION_IP | OPTION_LIST | OPTION_REQ, 0x06 }, /* DHCP_DNS_SERVER */
21 { OPTION_IP | OPTION_LIST, 0x07 }, /* DHCP_LOG_SERVER */ 21 { OPTION_IP | OPTION_LIST , 0x07 }, /* DHCP_LOG_SERVER */
22 { OPTION_IP | OPTION_LIST, 0x08 }, /* DHCP_COOKIE_SERVER */ 22 { OPTION_IP | OPTION_LIST , 0x08 }, /* DHCP_COOKIE_SERVER */
23 { OPTION_IP | OPTION_LIST, 0x09 }, /* DHCP_LPR_SERVER */ 23 { OPTION_IP | OPTION_LIST , 0x09 }, /* DHCP_LPR_SERVER */
24 { OPTION_STRING | OPTION_REQ, 0x0c }, /* DHCP_HOST_NAME */ 24 { OPTION_STRING | OPTION_REQ, 0x0c }, /* DHCP_HOST_NAME */
25 { OPTION_U16, 0x0d }, /* DHCP_BOOT_SIZE */ 25 { OPTION_U16 , 0x0d }, /* DHCP_BOOT_SIZE */
26 { OPTION_STRING | OPTION_LIST | OPTION_REQ, 0x0f }, /* DHCP_DOMAIN_NAME */ 26 { OPTION_STRING | OPTION_LIST | OPTION_REQ, 0x0f }, /* DHCP_DOMAIN_NAME */
27 { OPTION_IP, 0x10 }, /* DHCP_SWAP_SERVER */ 27 { OPTION_IP , 0x10 }, /* DHCP_SWAP_SERVER */
28 { OPTION_STRING, 0x11 }, /* DHCP_ROOT_PATH */ 28 { OPTION_STRING , 0x11 }, /* DHCP_ROOT_PATH */
29 { OPTION_U8, 0x17 }, /* DHCP_IP_TTL */ 29 { OPTION_U8 , 0x17 }, /* DHCP_IP_TTL */
30 { OPTION_U16, 0x1a }, /* DHCP_MTU */ 30 { OPTION_U16 , 0x1a }, /* DHCP_MTU */
31 { OPTION_IP | OPTION_REQ, 0x1c }, /* DHCP_BROADCAST */ 31 { OPTION_IP | OPTION_REQ, 0x1c }, /* DHCP_BROADCAST */
32 { OPTION_STRING | OPTION_REQ, 0x28 }, /* DHCP_NTP_SERVER */ 32 { OPTION_STRING , 0x28 }, /* nisdomain */
33 { OPTION_IP | OPTION_LIST | OPTION_REQ, 0x29 }, /* DHCP_WINS_SERVER */ 33 { OPTION_IP | OPTION_LIST , 0x29 }, /* nissrv */
34 { OPTION_IP | OPTION_LIST | OPTION_REQ, 0x2a }, /* DHCP_REQUESTED_IP */ 34 { OPTION_IP | OPTION_LIST | OPTION_REQ, 0x2a }, /* DHCP_NTP_SERVER */
35 { OPTION_IP | OPTION_LIST, 0x2c }, /* DHCP_LEASE_TIME */ 35 { OPTION_IP | OPTION_LIST , 0x2c }, /* DHCP_WINS_SERVER */
36 { OPTION_IP, 0x32 }, /* DHCP_OPTION_OVER */ 36 { OPTION_IP , 0x32 }, /* DHCP_REQUESTED_IP */
37 { OPTION_U32, 0x33 }, /* DHCP_MESSAGE_TYPE */ 37 { OPTION_U32 , 0x33 }, /* DHCP_LEASE_TIME */
38 { OPTION_U8, 0x35 }, /* DHCP_SERVER_ID */ 38 { OPTION_U8 , 0x35 }, /* dhcptype */
39 { OPTION_IP, 0x36 }, /* DHCP_PARAM_REQ */ 39 { OPTION_IP , 0x36 }, /* DHCP_SERVER_ID */
40 { OPTION_STRING, 0x38 }, /* DHCP_MESSAGE */ 40 { OPTION_STRING , 0x38 }, /* DHCP_MESSAGE */
41 { OPTION_STRING, 0x3C }, /* DHCP_VENDOR */ 41 { OPTION_STRING , 0x3C }, /* DHCP_VENDOR */
42 { OPTION_STRING, 0x3D }, /* DHCP_CLIENT_ID */ 42 { OPTION_STRING , 0x3D }, /* DHCP_CLIENT_ID */
43 { OPTION_STRING, 0x42 }, /* "tftp" */ 43 { OPTION_STRING , 0x42 }, /* tftp */
44 { OPTION_STRING, 0x43 }, /* "bootfile" */ 44 { OPTION_STRING , 0x43 }, /* bootfile */
45 { OPTION_STRING, 0x4D }, /* "userclass" */ 45 { OPTION_STRING , 0x4D }, /* userclass */
46#if ENABLE_FEATURE_RFC3397 46#if ENABLE_FEATURE_RFC3397
47 { OPTION_STR1035 | OPTION_LIST | OPTION_REQ, 0x77 }, /* "search" */ 47 { OPTION_STR1035 | OPTION_LIST , 0x77 }, /* search */
48#endif 48#endif
49 /* MSIE's "Web Proxy Autodiscovery Protocol" support */ 49 /* MSIE's "Web Proxy Autodiscovery Protocol" support */
50 { OPTION_STRING, 0xfc }, /* "wpad" */ 50 { OPTION_STRING , 0xfc }, /* wpad */
51 51
52 /* Options below have no match in dhcp_option_strings[], 52 /* Options below have no match in dhcp_option_strings[],
53 * are not passed to dhcpc scripts, and cannot be specified 53 * are not passed to dhcpc scripts, and cannot be specified
54 * with "option XXX YYY" syntax in dhcpd config file. */ 54 * with "option XXX YYY" syntax in dhcpd config file. */
55 55
56 { OPTION_U16, 0x39 }, /* DHCP_MAX_SIZE */ 56 { OPTION_U16 , 0x39 }, /* DHCP_MAX_SIZE */
57 { } /* zeroed terminating entry */ 57 { } /* zeroed terminating entry */
58}; 58};
59 59
@@ -64,28 +64,28 @@ const char dhcp_option_strings[] ALIGN1 =
64 "subnet" "\0" /* DHCP_SUBNET */ 64 "subnet" "\0" /* DHCP_SUBNET */
65 "timezone" "\0" /* DHCP_TIME_OFFSET */ 65 "timezone" "\0" /* DHCP_TIME_OFFSET */
66 "router" "\0" /* DHCP_ROUTER */ 66 "router" "\0" /* DHCP_ROUTER */
67 "timesvr" "\0" /* DHCP_TIME_SERVER */ 67 "timesrv" "\0" /* DHCP_TIME_SERVER */
68 "namesvr" "\0" /* DHCP_NAME_SERVER */ 68 "namesrv" "\0" /* DHCP_NAME_SERVER */
69 "dns" "\0" /* DHCP_DNS_SERVER */ 69 "dns" "\0" /* DHCP_DNS_SERVER */
70 "logsvr" "\0" /* DHCP_LOG_SERVER */ 70 "logsrv" "\0" /* DHCP_LOG_SERVER */
71 "cookiesvr" "\0" /* DHCP_COOKIE_SERVER */ 71 "cookiesrv" "\0" /* DHCP_COOKIE_SERVER */
72 "lprsvr" "\0" /* DHCP_LPR_SERVER */ 72 "lprsrv" "\0" /* DHCP_LPR_SERVER */
73 "hostname" "\0" /* DHCP_HOST_NAME */ 73 "hostname" "\0" /* DHCP_HOST_NAME */
74 "bootsize" "\0" /* DHCP_BOOT_SIZE */ 74 "bootsize" "\0" /* DHCP_BOOT_SIZE */
75 "domain" "\0" /* DHCP_DOMAIN_NAME */ 75 "domain" "\0" /* DHCP_DOMAIN_NAME */
76 "swapsvr" "\0" /* DHCP_SWAP_SERVER */ 76 "swapsrv" "\0" /* DHCP_SWAP_SERVER */
77 "rootpath" "\0" /* DHCP_ROOT_PATH */ 77 "rootpath" "\0" /* DHCP_ROOT_PATH */
78 "ipttl" "\0" /* DHCP_IP_TTL */ 78 "ipttl" "\0" /* DHCP_IP_TTL */
79 "mtu" "\0" /* DHCP_MTU */ 79 "mtu" "\0" /* DHCP_MTU */
80 "broadcast" "\0" /* DHCP_BROADCAST */ 80 "broadcast" "\0" /* DHCP_BROADCAST */
81 "nisdomain" "\0" /* DHCP_NTP_SERVER */ 81 "nisdomain" "\0" /* */
82 "nissrv" "\0" /* DHCP_WINS_SERVER */ 82 "nissrv" "\0" /* */
83 "ntpsrv" "\0" /* DHCP_REQUESTED_IP */ 83 "ntpsrv" "\0" /* DHCP_NTP_SERVER */
84 "wins" "\0" /* DHCP_LEASE_TIME */ 84 "wins" "\0" /* DHCP_WINS_SERVER */
85 "requestip" "\0" /* DHCP_OPTION_OVER */ 85 "requestip" "\0" /* DHCP_REQUESTED_IP */
86 "lease" "\0" /* DHCP_MESSAGE_TYPE */ 86 "lease" "\0" /* DHCP_LEASE_TIME */
87 "dhcptype" "\0" /* DHCP_SERVER_ID */ 87 "dhcptype" "\0" /* */
88 "serverid" "\0" /* DHCP_PARAM_REQ */ 88 "serverid" "\0" /* DHCP_SERVER_ID */
89 "message" "\0" /* DHCP_MESSAGE */ 89 "message" "\0" /* DHCP_MESSAGE */
90 "vendorclass" "\0" /* DHCP_VENDOR */ 90 "vendorclass" "\0" /* DHCP_VENDOR */
91 "clientid" "\0" /* DHCP_CLIENT_ID */ 91 "clientid" "\0" /* DHCP_CLIENT_ID */