source: drbl_ui/backup/test_busybox/busybox-1.7.2/busybox-1.7.1_udhcp.patch_v2 @ 148

Last change on this file since 148 was 20, checked in by chris, 17 years ago
File size: 12.9 KB
Line 
1diff -Naur busybox-1.7.1.org/applets/applets.c busybox-1.7.1/applets/applets.c
2--- busybox-1.7.1.org/applets/applets.c 2007-09-17 02:48:10.000000000 +0800
3+++ busybox-1.7.1/applets/applets.c 2007-10-09 10:12:34.000000000 +0800
4@@ -23,7 +23,7 @@
5 #warning Note that glibc is unsuitable for static linking anyway.
6 #warning If you still want to do it, remove -Wl,--gc-sections
7 #warning from top-level Makefile and remove this warning.
8-#error Aborting compilation.
9+
10 #endif
11 
12 
13diff -Naur busybox-1.7.1.org/include/usage.h busybox-1.7.1/include/usage.h
14--- busybox-1.7.1.org/include/usage.h 2007-09-03 19:48:46.000000000 +0800
15+++ busybox-1.7.1/include/usage.h 2007-10-09 10:12:34.000000000 +0800
16@@ -3653,7 +3653,7 @@
17 
18 #define udhcpc_trivial_usage \
19        "[-Cfbnqtv] [-c CID] [-V VCLS] [-H HOSTNAME] [-i INTERFACE]\n" \
20-       " [-p pidfile] [-r IP] [-s script]"
21+       " [-p pidfile] [-r IP] [-s script] [-P CLIENT_PORT]"
22 #define udhcpc_full_usage \
23        " -V,--vendorclass=CLASSID  Set vendor class identifier" \
24        "\n -i,--interface=INTERFACE  Interface to use (default: eth0)" \
25@@ -3671,14 +3671,16 @@
26        "\n -q,--quit Quit after obtaining lease" \
27        "\n -R,--release  Release IP on quit" \
28        "\n -v,--version  Display version" \
29+       "\n -P,--client-port CLIENT_PORT  Use CLIENT_PORT as DHCP Client port (default: 68)" \
30 
31 #define udhcpd_trivial_usage \
32-       "[-fS] [configfile]" \
33+       "[-fS] [-P SERVER_PORT] [configfile]" \
34 
35 #define udhcpd_full_usage \
36        "DHCP server" \
37        "\n -f  Stay in foreground" \
38-       "\n -S  Log to syslog too"
39+       "\n -S  Log to syslog too"  \
40+       "\n -P SERVER_PORT  Use SERVER_PORT as DHCP server port (default: 67)" \
41 
42 #define umount_trivial_usage \
43        "[flags] FILESYSTEM|DIRECTORY"
44diff -Naur busybox-1.7.1.org/Makefile busybox-1.7.1/Makefile
45--- busybox-1.7.1.org/Makefile  2007-09-17 02:50:24.000000000 +0800
46+++ busybox-1.7.1/Makefile  2007-10-09 10:12:34.000000000 +0800
47@@ -570,7 +570,7 @@
48 quiet_cmd_busybox__ ?= LINK    $@
49       cmd_busybox__ ?= $(srctree)/scripts/trylink $(CC) $(LDFLAGS) \
50       -o $@ -Wl,-Map -Wl,$@.map \
51-      -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
52+      -Wl,--warn-common -Wl,--sort-common  \
53       -Wl,--start-group $(busybox-all) -Wl,--end-group \
54       $(LDLIBS)
55 
56diff -Naur busybox-1.7.1.org/networking/udhcp/clientpacket.c busybox-1.7.1/networking/udhcp/clientpacket.c
57--- busybox-1.7.1.org/networking/udhcp/clientpacket.c 2007-09-03 19:48:26.000000000 +0800
58+++ busybox-1.7.1/networking/udhcp/clientpacket.c 2007-10-15 14:27:49.000000000 +0800
59@@ -74,6 +74,12 @@
60 int send_discover(uint32_t xid, uint32_t requested)
61 {
62  struct dhcpMessage packet;
63+ int    SRV_PORT, CLT_PORT;
64+
65+ SRV_PORT=(client_port == NULL)?SERVER_PORT:(atoi(client_port) - 1);
66+ CLT_PORT=(client_port == NULL)?CLIENT_PORT:atoi(client_port);
67+
68+ DEBUG("clientpacket.c: send_discover() - SRV_PORT= %d, CLT_PORT= %d\n", SRV_PORT, CLT_PORT);
69 
70  init_packet(&packet, DHCPDISCOVER);
71  packet.xid = xid;
72@@ -82,8 +88,7 @@
73 
74  add_requests(&packet);
75  bb_info_msg("Sending discover...");
76- return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
77-     SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
78+ return udhcp_raw_packet(&packet, INADDR_ANY, CLT_PORT, INADDR_BROADCAST, SRV_PORT, MAC_BCAST_ADDR, client_config.ifindex);
79 }
80 
81 
82@@ -92,6 +97,12 @@
83 {
84  struct dhcpMessage packet;
85  struct in_addr addr;
86+ int    SRV_PORT, CLT_PORT;
87+
88+ SRV_PORT=(client_port == NULL)?SERVER_PORT:(atoi(client_port) - 1);
89+ CLT_PORT=(client_port == NULL)?CLIENT_PORT:atoi(client_port);
90+
91+ DEBUG("clientpacket.c: send_selecting() - SRV_PORT= %d, CLT_PORT= %d\n", SRV_PORT, CLT_PORT);
92 
93  init_packet(&packet, DHCPREQUEST);
94  packet.xid = xid;
95@@ -102,8 +113,7 @@
96  add_requests(&packet);
97  addr.s_addr = requested;
98  bb_info_msg("Sending select for %s...", inet_ntoa(addr));
99- return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
100-       SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
101+ return udhcp_raw_packet(&packet, INADDR_ANY, CLT_PORT, INADDR_BROADCAST, SRV_PORT, MAC_BCAST_ADDR, client_config.ifindex);
102 }
103 
104 
105@@ -111,6 +121,12 @@
106 int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr)
107 {
108  struct dhcpMessage packet;
109+ int    SRV_PORT, CLT_PORT;
110+
111+ SRV_PORT=(client_port == NULL)?SERVER_PORT:(atoi(client_port) - 1);
112+ CLT_PORT=(client_port == NULL)?CLIENT_PORT:atoi(client_port);
113+
114+ DEBUG("clientpacket.c: send_renew() - SRV_PORT= %d, CLT_PORT= %d\n", SRV_PORT, CLT_PORT);
115 
116  init_packet(&packet, DHCPREQUEST);
117  packet.xid = xid;
118@@ -119,10 +135,10 @@
119  add_requests(&packet);
120  bb_info_msg("Sending renew...");
121  if (server)
122-   return udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT);
123+   return udhcp_kernel_packet(&packet, ciaddr, CLT_PORT, server, SRV_PORT);
124 
125- return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
126-       SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
127+ return udhcp_raw_packet(&packet, INADDR_ANY, CLT_PORT, INADDR_BROADCAST,
128+       SRV_PORT, MAC_BCAST_ADDR, client_config.ifindex);
129 }
130 
131 
132@@ -130,6 +146,12 @@
133 int send_release(uint32_t server, uint32_t ciaddr)
134 {
135  struct dhcpMessage packet;
136+ int    SRV_PORT, CLT_PORT;
137+
138+ SRV_PORT=(client_port == NULL)?SERVER_PORT:(atoi(client_port) - 1);
139+ CLT_PORT=(client_port == NULL)?CLIENT_PORT:atoi(client_port);
140+
141+ DEBUG("clientpacket.c: send_release() - SRV_PORT= %d, CLT_PORT= %d\n", SRV_PORT, CLT_PORT);
142 
143  init_packet(&packet, DHCPRELEASE);
144  packet.xid = random_xid();
145@@ -139,7 +161,7 @@
146  add_simple_option(packet.options, DHCP_SERVER_ID, server);
147 
148  bb_info_msg("Sending release...");
149- return udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT);
150+ return udhcp_kernel_packet(&packet, ciaddr, CLT_PORT, server, SRV_PORT);
151 }
152 
153 
154@@ -151,6 +173,8 @@
155  uint32_t source, dest;
156  uint16_t check;
157 
158+ int CLT_PORT = (client_port == NULL)?CLIENT_PORT:atoi(client_port);
159+
160  memset(&packet, 0, sizeof(struct udp_dhcp_packet));
161  bytes = read(fd, &packet, sizeof(struct udp_dhcp_packet));
162  if (bytes < 0) {
163@@ -175,7 +199,7 @@
164  /* Make sure its the right packet for us, and that it passes sanity checks */
165  if (packet.ip.protocol != IPPROTO_UDP || packet.ip.version != IPVERSION
166   || packet.ip.ihl != sizeof(packet.ip) >> 2
167-  || packet.udp.dest != htons(CLIENT_PORT)
168+  || packet.udp.dest != htons(CLT_PORT)
169   || bytes > (int) sizeof(struct udp_dhcp_packet)
170   || ntohs(packet.udp.len) != (uint16_t)(bytes - sizeof(packet.ip))
171  ) {
172diff -Naur busybox-1.7.1.org/networking/udhcp/dhcpc.c busybox-1.7.1/networking/udhcp/dhcpc.c
173--- busybox-1.7.1.org/networking/udhcp/dhcpc.c  2007-09-03 19:48:26.000000000 +0800
174+++ busybox-1.7.1/networking/udhcp/dhcpc.c  2007-10-09 10:12:34.000000000 +0800
175@@ -10,6 +10,7 @@
176 
177 #include <getopt.h>
178 #include <syslog.h>
179+#include <stdlib.h>  // for atoi()
180 
181 /* Override ENABLE_FEATURE_PIDFILE - ifupdown needs our pidfile to always exist */
182 #define WANT_PIDFILE 1
183@@ -179,6 +180,7 @@
184    OPT_t = 1 << 16,
185    OPT_v = 1 << 17,
186    OPT_S = 1 << 18,
187+   OPT_P = 1 << 19,
188  };
189 #if ENABLE_GETOPT_LONG
190  static const char udhcpc_longopts[] ALIGN1 =
191@@ -201,6 +203,7 @@
192    "version\0"       No_argument       "v"
193    "retries\0"       Required_argument "t"
194    "syslog\0"        No_argument       "S"
195+   "client-port\0"   Required_argument "P"
196    ;
197 #endif
198  /* Default options. */
199@@ -215,10 +218,10 @@
200 #if ENABLE_GETOPT_LONG
201  applet_long_options = udhcpc_longopts;
202 #endif
203- opt = getopt32(argv, "c:CV:fbH:h:F:i:np:qRr:s:T:t:vS",
204+ opt = getopt32(argv, "c:CV:fbH:h:F:i:np:qRr:s:T:t:vSP:",
205    &str_c, &str_V, &str_h, &str_h, &str_F,
206    &client_config.interface, &client_config.pidfile, &str_r,
207-   &client_config.script, &str_T, &str_t
208+   &client_config.script, &str_T, &str_t, &client_port
209    );
210 
211  if (opt & OPT_c)
212@@ -269,6 +272,14 @@
213    logmode |= LOGMODE_SYSLOG;
214  }
215 
216+ if (opt & OPT_P) {
217+   printf("Use %s as DHCP Client Port!\n",client_port);
218+ }
219+
220+ if (client_port == NULL) {
221+   printf("Use %d as DHCP Client Port!\n",CLIENT_PORT);
222+ }
223+
224  if (read_interface(client_config.interface, &client_config.ifindex,
225         NULL, client_config.arp))
226    return 1;
227@@ -310,10 +321,15 @@
228    tv.tv_usec = 0;
229 
230    if (listen_mode != LISTEN_NONE && sockfd < 0) {
231-     if (listen_mode == LISTEN_KERNEL)
232-       sockfd = listen_socket(/*INADDR_ANY,*/ CLIENT_PORT, client_config.interface);
233-     else
234+     if (listen_mode == LISTEN_KERNEL) {
235+       if (client_port == NULL) {
236+         sockfd = listen_socket(/*INADDR_ANY,*/ CLIENT_PORT, client_config.interface);
237+       } else {
238+         sockfd = listen_socket(/*INADDR_ANY,*/ atoi(client_port), client_config.interface);
239+       }
240+     } else {
241        sockfd = raw_socket(client_config.ifindex);
242+     }
243    }
244    max_fd = udhcp_sp_fd_set(&rfds, sockfd);
245 
246diff -Naur busybox-1.7.1.org/networking/udhcp/dhcpd.c busybox-1.7.1/networking/udhcp/dhcpd.c
247--- busybox-1.7.1.org/networking/udhcp/dhcpd.c  2007-09-03 19:48:26.000000000 +0800
248+++ busybox-1.7.1/networking/udhcp/dhcpd.c  2007-10-09 10:12:34.000000000 +0800
249@@ -11,6 +11,7 @@
250  */
251 
252 #include <syslog.h>
253+#include <stdlib.h>    // for atoi()
254 #include "common.h"
255 #include "dhcpd.h"
256 #include "options.h"
257@@ -20,7 +21,6 @@
258 struct dhcpOfferedAddr *leases;
259 struct server_config_t server_config;
260 
261-
262 int udhcpd_main(int argc, char **argv);
263 int udhcpd_main(int argc, char **argv)
264 {
265@@ -36,7 +36,7 @@
266  struct option_set *option;
267  struct dhcpOfferedAddr *lease, static_lease;
268 
269- opt = getopt32(argv, "fS");
270+ opt = getopt32(argv, "fSP:",&server_port);
271  argv += optind;
272 
273  if (!(opt & 1)) { /* no -f */
274@@ -49,6 +49,15 @@
275    logmode |= LOGMODE_SYSLOG;
276  }
277 
278+ if (opt & 4) { /* -P */
279+   printf("Use %s for DHCP Server Port!\n",server_port);
280+ }
281+
282+ if ( server_port == NULL)
283+ {
284+   printf("Use %d for DHCP Server Port!\n",SERVER_PORT);
285+ }
286+
287  /* Would rather not do read_config before daemonization -
288   * otherwise NOMMU machines will parse config twice */
289  read_config(argv[0] ? argv[0] : DHCPD_CONF_FILE);
290@@ -95,8 +104,10 @@
291  while (1) { /* loop until universe collapses */
292 
293    if (server_socket < 0) {
294-     server_socket = listen_socket(/*INADDR_ANY,*/ SERVER_PORT,
295-         server_config.interface);
296+     if ( server_port == NULL)
297+       server_socket = listen_socket(/*INADDR_ANY,*/ SERVER_PORT, server_config.interface);
298+     else
299+       server_socket = listen_socket(/*INADDR_ANY,*/ atoi(server_port), server_config.interface);
300    }
301 
302    max_sock = udhcp_sp_fd_set(&rfds, server_socket);
303diff -Naur busybox-1.7.1.org/networking/udhcp/options.c busybox-1.7.1/networking/udhcp/options.c
304--- busybox-1.7.1.org/networking/udhcp/options.c  2007-09-03 19:48:26.000000000 +0800
305+++ busybox-1.7.1/networking/udhcp/options.c  2007-10-09 10:12:34.000000000 +0800
306@@ -67,6 +67,8 @@
307  [OPTION_S32] =     4
308 };
309 
310+char *server_port = NULL;
311+char *client_port = NULL;
312 
313 /* get an option with bounds checking (warning, not aligned). */
314 uint8_t *get_option(struct dhcpMessage *packet, int code)
315diff -Naur busybox-1.7.1.org/networking/udhcp/options.h busybox-1.7.1/networking/udhcp/options.h
316--- busybox-1.7.1.org/networking/udhcp/options.h  2007-09-03 19:48:26.000000000 +0800
317+++ busybox-1.7.1/networking/udhcp/options.h  2007-10-09 10:12:34.000000000 +0800
318@@ -105,6 +105,8 @@
319 
320 extern const struct dhcp_option dhcp_options[];
321 extern const unsigned char option_lengths[];
322+extern char  *server_port;
323+extern char  *client_port;
324 
325 uint8_t *get_option(struct dhcpMessage *packet, int code);
326 int end_option(uint8_t *optionptr);
327diff -Naur busybox-1.7.1.org/networking/udhcp/serverpacket.c busybox-1.7.1/networking/udhcp/serverpacket.c
328--- busybox-1.7.1.org/networking/udhcp/serverpacket.c 2007-09-03 19:48:26.000000000 +0800
329+++ busybox-1.7.1/networking/udhcp/serverpacket.c 2007-10-15 14:50:07.000000000 +0800
330@@ -30,8 +30,13 @@
331 {
332  DEBUG("Forwarding packet to relay");
333 
334- return udhcp_kernel_packet(payload, server_config.server, SERVER_PORT,
335-     payload->giaddr, SERVER_PORT);
336+ if (server_port == NULL) {
337+   DEBUG("udhcp_kernel_packet(payload, server_config.server, %d, payload->giaddr, %d);",SERVER_PORT,SERVER_PORT);
338+   return udhcp_kernel_packet(payload, server_config.server, SERVER_PORT, payload->giaddr, SERVER_PORT);
339+ } else {
340+   DEBUG("udhcp_kernel_packet(payload, server_config.server, %d, payload->giaddr, %d);",atoi(server_port),atoi(server_port));
341+   return udhcp_kernel_packet(payload, server_config.server, atoi(server_port), payload->giaddr, atoi(server_port));
342+ }
343 }
344 
345 
346@@ -40,6 +45,12 @@
347 {
348  const uint8_t *chaddr;
349  uint32_t ciaddr;
350+ int      SRV_PORT=0, CLT_PORT=0;
351+
352+ SRV_PORT=(server_port == NULL)?SERVER_PORT:atoi(server_port);
353+ CLT_PORT=(server_port == NULL)?CLIENT_PORT:(atoi(server_port) + 1);
354+
355+ DEBUG("serverpacket.c: send_packet_to_client() - SRV_PORT=%d, CLT_PORT= %d",SRV_PORT, CLT_PORT);
356 
357  if (force_broadcast) {
358    DEBUG("broadcasting packet to client (NAK)");
359@@ -58,8 +69,8 @@
360    ciaddr = payload->yiaddr;
361    chaddr = payload->chaddr;
362  }
363- return udhcp_raw_packet(payload, server_config.server, SERVER_PORT,
364-     ciaddr, CLIENT_PORT, chaddr, server_config.ifindex);
365+ return udhcp_raw_packet(payload, server_config.server, SRV_PORT,
366+     ciaddr, CLT_PORT, chaddr, server_config.ifindex);
367 }
368 
369 
Note: See TracBrowser for help on using the repository browser.