aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-01-25 19:27:08 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-01-25 19:27:08 +0000
commitca9635b19dc66f37c322a61d8fcba5c753a526af (patch)
tree19a5362ce20288bb6f7778cfadd7c263c8136aa7
parenta5549c961739fb0d354f3c41cb5fb0d64c8da4ec (diff)
downloadbusybox-w32-ca9635b19dc66f37c322a61d8fcba5c753a526af.tar.gz
busybox-w32-ca9635b19dc66f37c322a61d8fcba5c753a526af.tar.bz2
busybox-w32-ca9635b19dc66f37c322a61d8fcba5c753a526af.zip
udhcpc: fix wrong options in decline and release packets
(Jonas Danielsson <jonas.danielsson at axis.com>)
-rw-r--r--networking/udhcp/clientpacket.c24
-rw-r--r--networking/udhcp/dhcpc.c2
-rw-r--r--networking/udhcp/dhcpc.h2
3 files changed, 15 insertions, 13 deletions
diff --git a/networking/udhcp/clientpacket.c b/networking/udhcp/clientpacket.c
index b8190ba43..29d0d9a1d 100644
--- a/networking/udhcp/clientpacket.c
+++ b/networking/udhcp/clientpacket.c
@@ -48,14 +48,15 @@ static void init_packet(struct dhcpMessage *packet, char type)
48 add_option_string(packet->options, client_config.hostname); 48 add_option_string(packet->options, client_config.hostname);
49 if (client_config.fqdn) 49 if (client_config.fqdn)
50 add_option_string(packet->options, client_config.fqdn); 50 add_option_string(packet->options, client_config.fqdn);
51 add_option_string(packet->options, client_config.vendorclass); 51 if ((type != DHCPDECLINE) && (type != DHCPRELEASE))
52 add_option_string(packet->options, client_config.vendorclass);
52} 53}
53 54
54 55
55/* Add a parameter request list for stubborn DHCP servers. Pull the data 56/* Add a parameter request list for stubborn DHCP servers. Pull the data
56 * from the struct in options.c. Don't do bounds checking here because it 57 * from the struct in options.c. Don't do bounds checking here because it
57 * goes towards the head of the packet. */ 58 * goes towards the head of the packet. */
58static void add_requests(struct dhcpMessage *packet) 59static void add_param_req_option(struct dhcpMessage *packet)
59{ 60{
60 uint8_t c; 61 uint8_t c;
61 int end = end_option(packet->options); 62 int end = end_option(packet->options);
@@ -63,26 +64,28 @@ static void add_requests(struct dhcpMessage *packet)
63 64
64 packet->options[end + OPT_CODE] = DHCP_PARAM_REQ; 65 packet->options[end + OPT_CODE] = DHCP_PARAM_REQ;
65 for (i = 0; (c = dhcp_options[i].code) != 0; i++) { 66 for (i = 0; (c = dhcp_options[i].code) != 0; i++) {
66 if (dhcp_options[i].flags & OPTION_REQ 67 if ((dhcp_options[i].flags & OPTION_REQ)
67 || (client_config.opt_mask[c >> 3] & (1 << (c & 7))) 68 || (client_config.opt_mask[c >> 3] & (1 << (c & 7)))
68 ) { 69 ) {
69 packet->options[end + OPT_DATA + len++] = c; 70 packet->options[end + OPT_DATA + len] = c;
71 len++;
70 } 72 }
71 } 73 }
72 packet->options[end + OPT_LEN] = len; 74 packet->options[end + OPT_LEN] = len;
73 packet->options[end + OPT_DATA + len] = DHCP_END; 75 packet->options[end + OPT_DATA + len] = DHCP_END;
74
75} 76}
76 77
78
77#if ENABLE_FEATURE_UDHCPC_ARPING 79#if ENABLE_FEATURE_UDHCPC_ARPING
78/* Unicast a DHCP decline message */ 80/* Unicast a DHCP decline message */
79int send_decline(uint32_t xid, uint32_t server) 81int send_decline(uint32_t xid, uint32_t server, uint32_t requested)
80{ 82{
81 struct dhcpMessage packet; 83 struct dhcpMessage packet;
82 84
83 init_packet(&packet, DHCPDECLINE); 85 init_packet(&packet, DHCPDECLINE);
84 packet.xid = xid; 86 packet.xid = xid;
85 add_requests(&packet); 87 add_simple_option(packet.options, DHCP_REQUESTED_IP, requested);
88 add_simple_option(packet.options, DHCP_SERVER_ID, server);
86 89
87 bb_info_msg("Sending decline..."); 90 bb_info_msg("Sending decline...");
88 91
@@ -104,7 +107,7 @@ int send_discover(uint32_t xid, uint32_t requested)
104 /* Explicitly saying that we want RFC-compliant packets helps 107 /* Explicitly saying that we want RFC-compliant packets helps
105 * some buggy DHCP servers to NOT send bigger packets */ 108 * some buggy DHCP servers to NOT send bigger packets */
106 add_simple_option(packet.options, DHCP_MAX_SIZE, htons(576)); 109 add_simple_option(packet.options, DHCP_MAX_SIZE, htons(576));
107 add_requests(&packet); 110 add_param_req_option(&packet);
108 bb_info_msg("Sending discover..."); 111 bb_info_msg("Sending discover...");
109 return udhcp_send_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, 112 return udhcp_send_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
110 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); 113 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
@@ -123,7 +126,7 @@ int send_selecting(uint32_t xid, uint32_t server, uint32_t requested)
123 add_simple_option(packet.options, DHCP_REQUESTED_IP, requested); 126 add_simple_option(packet.options, DHCP_REQUESTED_IP, requested);
124 add_simple_option(packet.options, DHCP_SERVER_ID, server); 127 add_simple_option(packet.options, DHCP_SERVER_ID, server);
125 128
126 add_requests(&packet); 129 add_param_req_option(&packet);
127 addr.s_addr = requested; 130 addr.s_addr = requested;
128 bb_info_msg("Sending select for %s...", inet_ntoa(addr)); 131 bb_info_msg("Sending select for %s...", inet_ntoa(addr));
129 return udhcp_send_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, 132 return udhcp_send_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
@@ -140,7 +143,7 @@ int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr)
140 packet.xid = xid; 143 packet.xid = xid;
141 packet.ciaddr = ciaddr; 144 packet.ciaddr = ciaddr;
142 145
143 add_requests(&packet); 146 add_param_req_option(&packet);
144 bb_info_msg("Sending renew..."); 147 bb_info_msg("Sending renew...");
145 if (server) 148 if (server)
146 return udhcp_send_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); 149 return udhcp_send_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT);
@@ -159,7 +162,6 @@ int send_release(uint32_t server, uint32_t ciaddr)
159 packet.xid = random_xid(); 162 packet.xid = random_xid();
160 packet.ciaddr = ciaddr; 163 packet.ciaddr = ciaddr;
161 164
162 add_simple_option(packet.options, DHCP_REQUESTED_IP, ciaddr);
163 add_simple_option(packet.options, DHCP_SERVER_ID, server); 165 add_simple_option(packet.options, DHCP_SERVER_ID, server);
164 166
165 bb_info_msg("Sending release..."); 167 bb_info_msg("Sending release...");
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index d76a62c5a..e9b728ab5 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -523,7 +523,7 @@ int udhcpc_main(int argc, char **argv)
523 ) { 523 ) {
524 bb_info_msg("offered address is in use " 524 bb_info_msg("offered address is in use "
525 "(got ARP reply), declining"); 525 "(got ARP reply), declining");
526 send_decline(xid, server_addr); 526 send_decline(xid, server_addr, packet.yiaddr);
527 527
528 if (state != REQUESTING) 528 if (state != REQUESTING)
529 udhcp_run_script(NULL, "deconfig"); 529 udhcp_run_script(NULL, "deconfig");
diff --git a/networking/udhcp/dhcpc.h b/networking/udhcp/dhcpc.h
index e818896c9..bc05754ac 100644
--- a/networking/udhcp/dhcpc.h
+++ b/networking/udhcp/dhcpc.h
@@ -42,7 +42,7 @@ uint32_t random_xid(void);
42int send_discover(uint32_t xid, uint32_t requested); 42int send_discover(uint32_t xid, uint32_t requested);
43int send_selecting(uint32_t xid, uint32_t server, uint32_t requested); 43int send_selecting(uint32_t xid, uint32_t server, uint32_t requested);
44#if ENABLE_FEATURE_UDHCPC_ARPING 44#if ENABLE_FEATURE_UDHCPC_ARPING
45int send_decline(uint32_t xid, uint32_t server); 45int send_decline(uint32_t xid, uint32_t server, uint32_t requested);
46#endif 46#endif
47int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr); 47int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr);
48int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr); 48int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr);