diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-04 13:12:16 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-04 13:12:16 +0000 |
commit | d55fe3e595eb0aad60484d273e251cfee4ef8aa5 (patch) | |
tree | 1b9ff57d70411902db36582da8dbaded99485eeb | |
parent | e8ef7ec7de0cd9906b42a94eddb800ed1229a614 (diff) | |
download | busybox-w32-d55fe3e595eb0aad60484d273e251cfee4ef8aa5.tar.gz busybox-w32-d55fe3e595eb0aad60484d273e251cfee4ef8aa5.tar.bz2 busybox-w32-d55fe3e595eb0aad60484d273e251cfee4ef8aa5.zip |
udhcp: optional support for non-standard DHCP ports (+300 bytes when selected)
-rw-r--r-- | include/usage.h | 15 | ||||
-rw-r--r-- | networking/udhcp/Config.in | 7 | ||||
-rw-r--r-- | networking/udhcp/clientsocket.c | 14 | ||||
-rw-r--r-- | networking/udhcp/common.h | 3 | ||||
-rw-r--r-- | networking/udhcp/dhcpc.c | 17 | ||||
-rw-r--r-- | networking/udhcp/dhcpc.h | 10 | ||||
-rw-r--r-- | networking/udhcp/dhcpd.c | 16 | ||||
-rw-r--r-- | networking/udhcp/dhcpd.h | 9 | ||||
-rw-r--r-- | networking/udhcp/dhcprelay.c | 1 | ||||
-rw-r--r-- | networking/udhcp/serverpacket.c | 1 |
10 files changed, 79 insertions, 14 deletions
diff --git a/include/usage.h b/include/usage.h index 989ed9134..fb88e9bcd 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -3892,7 +3892,7 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when | |||
3892 | 3892 | ||
3893 | #define udhcpc_trivial_usage \ | 3893 | #define udhcpc_trivial_usage \ |
3894 | "[-Cfbnqtv] [-c CID] [-V VCLS] [-H HOSTNAME] [-i INTERFACE]\n" \ | 3894 | "[-Cfbnqtv] [-c CID] [-V VCLS] [-H HOSTNAME] [-i INTERFACE]\n" \ |
3895 | " [-p pidfile] [-r IP] [-s script] [-O dhcp-option]..." | 3895 | " [-p pidfile] [-r IP] [-s script] [-O dhcp-option]..." USE_FEATURE_UDHCP_PORT(" [-P N]") |
3896 | #define udhcpc_full_usage \ | 3896 | #define udhcpc_full_usage \ |
3897 | USE_GETOPT_LONG( \ | 3897 | USE_GETOPT_LONG( \ |
3898 | " -V,--vendorclass=CLASSID Vendor class identifier" \ | 3898 | " -V,--vendorclass=CLASSID Vendor class identifier" \ |
@@ -3913,6 +3913,9 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when | |||
3913 | "\n -q,--quit Quit after obtaining lease" \ | 3913 | "\n -q,--quit Quit after obtaining lease" \ |
3914 | "\n -R,--release Release IP on quit" \ | 3914 | "\n -R,--release Release IP on quit" \ |
3915 | "\n -O,--request-option=OPT Request DHCP option OPT from server" \ | 3915 | "\n -O,--request-option=OPT Request DHCP option OPT from server" \ |
3916 | USE_FEATURE_UDHCP_PORT( \ | ||
3917 | "\n -P,--client-port N Use port N instead of default 68" \ | ||
3918 | ) \ | ||
3916 | USE_FEATURE_UDHCPC_ARPING( \ | 3919 | USE_FEATURE_UDHCPC_ARPING( \ |
3917 | "\n -a,--arping Use arping to validate offered address" \ | 3920 | "\n -a,--arping Use arping to validate offered address" \ |
3918 | ) \ | 3921 | ) \ |
@@ -3936,18 +3939,24 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when | |||
3936 | "\n -q Quit after obtaining lease" \ | 3939 | "\n -q Quit after obtaining lease" \ |
3937 | "\n -R Release IP on quit" \ | 3940 | "\n -R Release IP on quit" \ |
3938 | "\n -O OPT Request DHCP option OPT from server" \ | 3941 | "\n -O OPT Request DHCP option OPT from server" \ |
3942 | USE_FEATURE_UDHCP_PORT( \ | ||
3943 | "\n -P N Use port N instead of default 68" \ | ||
3944 | ) \ | ||
3939 | USE_FEATURE_UDHCPC_ARPING( \ | 3945 | USE_FEATURE_UDHCPC_ARPING( \ |
3940 | "\n -a Use arping to validate offered address" \ | 3946 | "\n -a Use arping to validate offered address" \ |
3941 | ) \ | 3947 | ) \ |
3942 | ) | 3948 | ) |
3943 | 3949 | ||
3944 | #define udhcpd_trivial_usage \ | 3950 | #define udhcpd_trivial_usage \ |
3945 | "[-fS] [configfile]" \ | 3951 | "[-fS]" USE_FEATURE_UDHCP_PORT(" [-P N]") " [configfile]" \ |
3946 | 3952 | ||
3947 | #define udhcpd_full_usage \ | 3953 | #define udhcpd_full_usage \ |
3948 | "DHCP server" \ | 3954 | "DHCP server" \ |
3949 | "\n -f Run in foreground" \ | 3955 | "\n -f Run in foreground" \ |
3950 | "\n -S Log to syslog too" | 3956 | "\n -S Log to syslog too" \ |
3957 | USE_FEATURE_UDHCP_PORT( \ | ||
3958 | "\n -P N Use port N instead of default 67" \ | ||
3959 | ) | ||
3951 | 3960 | ||
3952 | #define umount_trivial_usage \ | 3961 | #define umount_trivial_usage \ |
3953 | "[flags] FILESYSTEM|DIRECTORY" | 3962 | "[flags] FILESYSTEM|DIRECTORY" |
diff --git a/networking/udhcp/Config.in b/networking/udhcp/Config.in index 26cc8f501..ff0e4e2ae 100644 --- a/networking/udhcp/Config.in +++ b/networking/udhcp/Config.in | |||
@@ -63,6 +63,13 @@ config FEATURE_UDHCPC_ARPING | |||
63 | is really available. The client will DHCPDECLINE the offer if the | 63 | is really available. The client will DHCPDECLINE the offer if the |
64 | address is in use, and restart the discover process. | 64 | address is in use, and restart the discover process. |
65 | 65 | ||
66 | config FEATURE_UDHCP_PORT | ||
67 | bool "Enable '-P port' option for udhcpd and udhcpc" | ||
68 | default n | ||
69 | depends on APP_UDHCPD || APP_UDHCPC | ||
70 | help | ||
71 | At the cost of ~300 bytes, enables -P port option. | ||
72 | This feature is typically not needed. | ||
66 | 73 | ||
67 | config FEATURE_UDHCP_DEBUG | 74 | config FEATURE_UDHCP_DEBUG |
68 | bool "Compile udhcp with noisy debugging messages" | 75 | bool "Compile udhcp with noisy debugging messages" |
diff --git a/networking/udhcp/clientsocket.c b/networking/udhcp/clientsocket.c index 954db5319..b5534f83e 100644 --- a/networking/udhcp/clientsocket.c +++ b/networking/udhcp/clientsocket.c | |||
@@ -33,8 +33,8 @@ | |||
33 | #include <linux/filter.h> | 33 | #include <linux/filter.h> |
34 | 34 | ||
35 | #include "common.h" | 35 | #include "common.h" |
36 | 36 | #include "dhcpd.h" | |
37 | #define SERVER_AND_CLIENT_PORTS ((SERVER_PORT << 16) + CLIENT_PORT) | 37 | #include "dhcpc.h" |
38 | 38 | ||
39 | int raw_socket(int ifindex) | 39 | int raw_socket(int ifindex) |
40 | { | 40 | { |
@@ -62,6 +62,7 @@ int raw_socket(int ifindex) | |||
62 | * | 62 | * |
63 | * TODO: make conditional? | 63 | * TODO: make conditional? |
64 | */ | 64 | */ |
65 | #define SERVER_AND_CLIENT_PORTS ((67 << 16) + 68) | ||
65 | static const struct sock_filter filter_instr[] = { | 66 | static const struct sock_filter filter_instr[] = { |
66 | /* check for udp */ | 67 | /* check for udp */ |
67 | BPF_STMT(BPF_LD|BPF_B|BPF_ABS, 9), | 68 | BPF_STMT(BPF_LD|BPF_B|BPF_ABS, 9), |
@@ -89,10 +90,13 @@ int raw_socket(int ifindex) | |||
89 | fd = xsocket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP)); | 90 | fd = xsocket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP)); |
90 | DEBUG("got raw socket fd %d", fd); | 91 | DEBUG("got raw socket fd %d", fd); |
91 | 92 | ||
92 | /* Ignoring error (kernel may lack support for this) */ | 93 | if (SERVER_PORT == 67 && CLIENT_PORT == 68) { |
93 | if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter_prog, | 94 | /* Use only if standard ports are in use */ |
95 | /* Ignoring error (kernel may lack support for this) */ | ||
96 | if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter_prog, | ||
94 | sizeof(filter_prog)) >= 0) | 97 | sizeof(filter_prog)) >= 0) |
95 | DEBUG("attached filter to raw socket fd %d", fd); | 98 | DEBUG("attached filter to raw socket fd %d", fd); |
99 | } | ||
96 | 100 | ||
97 | sock.sll_family = AF_PACKET; | 101 | sock.sll_family = AF_PACKET; |
98 | sock.sll_protocol = htons(ETH_P_IP); | 102 | sock.sll_protocol = htons(ETH_P_IP); |
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h index b1d629b18..9b26678c1 100644 --- a/networking/udhcp/common.h +++ b/networking/udhcp/common.h | |||
@@ -14,9 +14,6 @@ | |||
14 | 14 | ||
15 | #define DEFAULT_SCRIPT "/usr/share/udhcpc/default.script" | 15 | #define DEFAULT_SCRIPT "/usr/share/udhcpc/default.script" |
16 | 16 | ||
17 | #define SERVER_PORT 67 | ||
18 | #define CLIENT_PORT 68 | ||
19 | |||
20 | extern const uint8_t MAC_BCAST_ADDR[6]; /* six all-ones */ | 17 | extern const uint8_t MAC_BCAST_ADDR[6]; /* six all-ones */ |
21 | 18 | ||
22 | /*** packet.h ***/ | 19 | /*** packet.h ***/ |
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index f54bc08f1..7fca184ab 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 | USE_FEATURE_UDHCP_PORT(char *str_P;) | ||
136 | llist_t *list_O = NULL; | 137 | llist_t *list_O = NULL; |
137 | #if ENABLE_FEATURE_UDHCPC_ARPING | 138 | #if ENABLE_FEATURE_UDHCPC_ARPING |
138 | char *str_W; | 139 | char *str_W; |
@@ -181,6 +182,7 @@ int udhcpc_main(int argc, char **argv) | |||
181 | OPT_a = 1 << 20, | 182 | OPT_a = 1 << 20, |
182 | OPT_W = 1 << 21, | 183 | OPT_W = 1 << 21, |
183 | #endif | 184 | #endif |
185 | OPT_P = 1 << 22, | ||
184 | }; | 186 | }; |
185 | #if ENABLE_GETOPT_LONG | 187 | #if ENABLE_GETOPT_LONG |
186 | static const char udhcpc_longopts[] ALIGN1 = | 188 | static const char udhcpc_longopts[] ALIGN1 = |
@@ -207,9 +209,16 @@ int udhcpc_main(int argc, char **argv) | |||
207 | "arping\0" No_argument "a" | 209 | "arping\0" No_argument "a" |
208 | #endif | 210 | #endif |
209 | "request-option\0" Required_argument "O" | 211 | "request-option\0" Required_argument "O" |
212 | #if ENABLE_FEATURE_UDHCP_PORT | ||
213 | "client-port\0" Required_argument "P" | ||
214 | #endif | ||
210 | ; | 215 | ; |
211 | #endif | 216 | #endif |
212 | /* Default options. */ | 217 | /* Default options. */ |
218 | #if ENABLE_FEATURE_UDHCP_PORT | ||
219 | SERVER_PORT = 67; | ||
220 | CLIENT_PORT = 68; | ||
221 | #endif | ||
213 | client_config.interface = "eth0"; | 222 | client_config.interface = "eth0"; |
214 | client_config.script = DEFAULT_SCRIPT; | 223 | client_config.script = DEFAULT_SCRIPT; |
215 | 224 | ||
@@ -220,11 +229,13 @@ int udhcpc_main(int argc, char **argv) | |||
220 | #endif | 229 | #endif |
221 | opt = getopt32(argv, "c:CV:fbH:h:F:i:np:qRr:s:T:t:vSA:" | 230 | opt = getopt32(argv, "c:CV:fbH:h:F:i:np:qRr:s:T:t:vSA:" |
222 | USE_FEATURE_UDHCPC_ARPING("aW:") | 231 | USE_FEATURE_UDHCPC_ARPING("aW:") |
232 | USE_FEATURE_UDHCP_PORT("P:") | ||
223 | "O:" | 233 | "O:" |
224 | , &str_c, &str_V, &str_h, &str_h, &str_F | 234 | , &str_c, &str_V, &str_h, &str_h, &str_F |
225 | , &client_config.interface, &client_config.pidfile, &str_r | 235 | , &client_config.interface, &client_config.pidfile, &str_r |
226 | , &client_config.script, &str_T, &str_t, &str_A | 236 | , &client_config.script, &str_T, &str_t, &str_A |
227 | USE_FEATURE_UDHCPC_ARPING(, &str_W) | 237 | USE_FEATURE_UDHCPC_ARPING(, &str_W) |
238 | USE_FEATURE_UDHCP_PORT(, &str_P) | ||
228 | , &list_O | 239 | , &list_O |
229 | ); | 240 | ); |
230 | 241 | ||
@@ -276,6 +287,12 @@ int udhcpc_main(int argc, char **argv) | |||
276 | openlog(applet_name, LOG_PID, LOG_LOCAL0); | 287 | openlog(applet_name, LOG_PID, LOG_LOCAL0); |
277 | logmode |= LOGMODE_SYSLOG; | 288 | logmode |= LOGMODE_SYSLOG; |
278 | } | 289 | } |
290 | #if ENABLE_FEATURE_UDHCP_PORT | ||
291 | if (opt & OPT_P) { | ||
292 | CLIENT_PORT = xatou16(str_P); | ||
293 | SERVER_PORT = CLIENT_PORT - 1; | ||
294 | } | ||
295 | #endif | ||
279 | while (list_O) { | 296 | while (list_O) { |
280 | int n = index_in_strings(dhcp_option_strings, list_O->data); | 297 | int n = index_in_strings(dhcp_option_strings, list_O->data); |
281 | if (n < 0) | 298 | if (n < 0) |
diff --git a/networking/udhcp/dhcpc.h b/networking/udhcp/dhcpc.h index bc05754ac..4b8f3ec98 100644 --- a/networking/udhcp/dhcpc.h +++ b/networking/udhcp/dhcpc.h | |||
@@ -29,11 +29,19 @@ struct client_config_t { | |||
29 | uint8_t *hostname; /* Optional hostname to use */ | 29 | uint8_t *hostname; /* Optional hostname to use */ |
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 | uint16_t port; | ||
32 | uint8_t arp[6]; /* Our arp address */ | 33 | uint8_t arp[6]; /* Our arp address */ |
33 | uint8_t opt_mask[256 / 8]; /* Bitmask of options to send (-O option) */ | 34 | uint8_t opt_mask[256 / 8]; /* Bitmask of options to send (-O option) */ |
34 | }; | 35 | }; |
35 | 36 | ||
36 | #define client_config (*(struct client_config_t*)&bb_common_bufsiz1) | 37 | /* server_config sits in 1st half of bb_common_bufsiz1 */ |
38 | #define client_config (*(struct client_config_t*)(&bb_common_bufsiz1[COMMON_BUFSIZE/2])) | ||
39 | |||
40 | #if ENABLE_FEATURE_UDHCP_PORT | ||
41 | #define CLIENT_PORT (client_config.port) | ||
42 | #else | ||
43 | #define CLIENT_PORT 68 | ||
44 | #endif | ||
37 | 45 | ||
38 | 46 | ||
39 | /*** clientpacket.h ***/ | 47 | /*** clientpacket.h ***/ |
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index 45f445b48..eb7323da7 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c | |||
@@ -12,6 +12,7 @@ | |||
12 | 12 | ||
13 | #include <syslog.h> | 13 | #include <syslog.h> |
14 | #include "common.h" | 14 | #include "common.h" |
15 | #include "dhcpc.h" | ||
15 | #include "dhcpd.h" | 16 | #include "dhcpd.h" |
16 | #include "options.h" | 17 | #include "options.h" |
17 | 18 | ||
@@ -35,8 +36,14 @@ int udhcpd_main(int argc, char **argv) | |||
35 | unsigned opt; | 36 | unsigned opt; |
36 | struct option_set *option; | 37 | struct option_set *option; |
37 | struct dhcpOfferedAddr *lease, static_lease; | 38 | struct dhcpOfferedAddr *lease, static_lease; |
39 | USE_FEATURE_UDHCP_PORT(char *str_P;) | ||
38 | 40 | ||
39 | opt = getopt32(argv, "fS"); | 41 | #if ENABLE_FEATURE_UDHCP_PORT |
42 | SERVER_PORT = 67; | ||
43 | CLIENT_PORT = 68; | ||
44 | #endif | ||
45 | |||
46 | opt = getopt32(argv, "fS" USE_FEATURE_UDHCP_PORT("P:", &str_P)); | ||
40 | argv += optind; | 47 | argv += optind; |
41 | 48 | ||
42 | if (!(opt & 1)) { /* no -f */ | 49 | if (!(opt & 1)) { /* no -f */ |
@@ -48,7 +55,12 @@ int udhcpd_main(int argc, char **argv) | |||
48 | openlog(applet_name, LOG_PID, LOG_LOCAL0); | 55 | openlog(applet_name, LOG_PID, LOG_LOCAL0); |
49 | logmode |= LOGMODE_SYSLOG; | 56 | logmode |= LOGMODE_SYSLOG; |
50 | } | 57 | } |
51 | 58 | #if ENABLE_FEATURE_UDHCP_PORT | |
59 | if (opt & 4) { /* -P */ | ||
60 | SERVER_PORT = xatou16(str_P); | ||
61 | CLIENT_PORT = SERVER_PORT + 1; | ||
62 | } | ||
63 | #endif | ||
52 | /* Would rather not do read_config before daemonization - | 64 | /* Would rather not do read_config before daemonization - |
53 | * otherwise NOMMU machines will parse config twice */ | 65 | * otherwise NOMMU machines will parse config twice */ |
54 | read_config(argv[0] ? argv[0] : DHCPD_CONF_FILE); | 66 | read_config(argv[0] ? argv[0] : DHCPD_CONF_FILE); |
diff --git a/networking/udhcp/dhcpd.h b/networking/udhcp/dhcpd.h index 216b7ab64..fe45ca312 100644 --- a/networking/udhcp/dhcpd.h +++ b/networking/udhcp/dhcpd.h | |||
@@ -1,5 +1,6 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* dhcpd.h */ | 2 | /* dhcpd.h */ |
3 | |||
3 | #ifndef _DHCPD_H | 4 | #ifndef _DHCPD_H |
4 | #define _DHCPD_H | 5 | #define _DHCPD_H |
5 | 6 | ||
@@ -27,6 +28,7 @@ struct static_lease { | |||
27 | 28 | ||
28 | struct server_config_t { | 29 | struct server_config_t { |
29 | uint32_t server; /* Our IP, in network order */ | 30 | uint32_t server; /* Our IP, in network order */ |
31 | uint16_t port; | ||
30 | /* start,end are in host order: we need to compare start <= ip <= end */ | 32 | /* start,end are in host order: we need to compare start <= ip <= end */ |
31 | uint32_t start_ip; /* Start address of leases, in host order */ | 33 | uint32_t start_ip; /* Start address of leases, in host order */ |
32 | uint32_t end_ip; /* End of leases, in host order */ | 34 | uint32_t end_ip; /* End of leases, in host order */ |
@@ -55,6 +57,13 @@ struct server_config_t { | |||
55 | }; | 57 | }; |
56 | 58 | ||
57 | #define server_config (*(struct server_config_t*)&bb_common_bufsiz1) | 59 | #define server_config (*(struct server_config_t*)&bb_common_bufsiz1) |
60 | /* client_config sits in 2nd half of bb_common_bufsiz1 */ | ||
61 | |||
62 | #if ENABLE_FEATURE_UDHCP_PORT | ||
63 | #define SERVER_PORT (server_config.port) | ||
64 | #else | ||
65 | #define SERVER_PORT 67 | ||
66 | #endif | ||
58 | 67 | ||
59 | extern struct dhcpOfferedAddr *leases; | 68 | extern struct dhcpOfferedAddr *leases; |
60 | 69 | ||
diff --git a/networking/udhcp/dhcprelay.c b/networking/udhcp/dhcprelay.c index c243cc16c..def1bc297 100644 --- a/networking/udhcp/dhcprelay.c +++ b/networking/udhcp/dhcprelay.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include "options.h" | 14 | #include "options.h" |
15 | 15 | ||
16 | /* constants */ | 16 | /* constants */ |
17 | #define SERVER_PORT 67 | ||
17 | #define SELECT_TIMEOUT 5 /* select timeout in sec. */ | 18 | #define SELECT_TIMEOUT 5 /* select timeout in sec. */ |
18 | #define MAX_LIFETIME 2*60 /* lifetime of an xid entry in sec. */ | 19 | #define MAX_LIFETIME 2*60 /* lifetime of an xid entry in sec. */ |
19 | 20 | ||
diff --git a/networking/udhcp/serverpacket.c b/networking/udhcp/serverpacket.c index 764b9a8f6..1dc7233f2 100644 --- a/networking/udhcp/serverpacket.c +++ b/networking/udhcp/serverpacket.c | |||
@@ -21,6 +21,7 @@ | |||
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include "common.h" | 23 | #include "common.h" |
24 | #include "dhcpc.h" | ||
24 | #include "dhcpd.h" | 25 | #include "dhcpd.h" |
25 | #include "options.h" | 26 | #include "options.h" |
26 | 27 | ||