aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/clientpacket.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/udhcp/clientpacket.c')
-rw-r--r--networking/udhcp/clientpacket.c36
1 files changed, 15 insertions, 21 deletions
diff --git a/networking/udhcp/clientpacket.c b/networking/udhcp/clientpacket.c
index 54f3f0e49..03473109f 100644
--- a/networking/udhcp/clientpacket.c
+++ b/networking/udhcp/clientpacket.c
@@ -86,7 +86,7 @@ int send_decline(uint32_t xid, uint32_t server)
86 86
87 bb_info_msg("Sending decline..."); 87 bb_info_msg("Sending decline...");
88 88
89 return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, 89 return udhcp_send_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
90 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); 90 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
91} 91}
92#endif 92#endif
@@ -106,7 +106,7 @@ int send_discover(uint32_t xid, uint32_t requested)
106 add_simple_option(packet.options, DHCP_MAX_SIZE, htons(576)); 106 add_simple_option(packet.options, DHCP_MAX_SIZE, htons(576));
107 add_requests(&packet); 107 add_requests(&packet);
108 bb_info_msg("Sending discover..."); 108 bb_info_msg("Sending discover...");
109 return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, 109 return udhcp_send_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
110 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); 110 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
111} 111}
112 112
@@ -126,7 +126,7 @@ int send_selecting(uint32_t xid, uint32_t server, uint32_t requested)
126 add_requests(&packet); 126 add_requests(&packet);
127 addr.s_addr = requested; 127 addr.s_addr = requested;
128 bb_info_msg("Sending select for %s...", inet_ntoa(addr)); 128 bb_info_msg("Sending select for %s...", inet_ntoa(addr));
129 return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, 129 return udhcp_send_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
130 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); 130 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
131} 131}
132 132
@@ -143,9 +143,9 @@ int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr)
143 add_requests(&packet); 143 add_requests(&packet);
144 bb_info_msg("Sending renew..."); 144 bb_info_msg("Sending renew...");
145 if (server) 145 if (server)
146 return udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); 146 return udhcp_send_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT);
147 147
148 return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, 148 return udhcp_send_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
149 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); 149 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
150} 150}
151 151
@@ -163,7 +163,7 @@ int send_release(uint32_t server, uint32_t ciaddr)
163 add_simple_option(packet.options, DHCP_SERVER_ID, server); 163 add_simple_option(packet.options, DHCP_SERVER_ID, server);
164 164
165 bb_info_msg("Sending release..."); 165 bb_info_msg("Sending release...");
166 return udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); 166 return udhcp_send_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT);
167} 167}
168 168
169 169
@@ -172,7 +172,6 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
172{ 172{
173 int bytes; 173 int bytes;
174 struct udp_dhcp_packet packet; 174 struct udp_dhcp_packet packet;
175 uint32_t source, dest;
176 uint16_t check; 175 uint16_t check;
177 176
178 memset(&packet, 0, sizeof(struct udp_dhcp_packet)); 177 memset(&packet, 0, sizeof(struct udp_dhcp_packet));
@@ -207,36 +206,31 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
207 return -2; 206 return -2;
208 } 207 }
209 208
210 /* check IP checksum */ 209 /* verify IP checksum */
211 check = packet.ip.check; 210 check = packet.ip.check;
212 packet.ip.check = 0; 211 packet.ip.check = 0;
213 if (check != udhcp_checksum(&(packet.ip), sizeof(packet.ip))) { 212 if (check != udhcp_checksum(&packet.ip, sizeof(packet.ip))) {
214 DEBUG("bad IP header checksum, ignoring"); 213 DEBUG("Bad IP header checksum, ignoring");
215 return -1; 214 return -1;
216 } 215 }
217 216
218 /* verify the UDP checksum by replacing the header with a pseudo header */ 217 /* verify UDP checksum. IP header has to be modified for this */
219 source = packet.ip.saddr; 218 memset(&packet.ip, 0, offsetof(struct iphdr, protocol));
220 dest = packet.ip.daddr; 219 /* fields which are not memset: protocol, check, saddr, daddr */
220 packet.ip.tot_len = packet.udp.len; /* yes, this is needed */
221 check = packet.udp.check; 221 check = packet.udp.check;
222 packet.udp.check = 0; 222 packet.udp.check = 0;
223 memset(&packet.ip, 0, sizeof(packet.ip));
224
225 packet.ip.protocol = IPPROTO_UDP;
226 packet.ip.saddr = source;
227 packet.ip.daddr = dest;
228 packet.ip.tot_len = packet.udp.len; /* cheat on the psuedo-header */
229 if (check && check != udhcp_checksum(&packet, bytes)) { 223 if (check && check != udhcp_checksum(&packet, bytes)) {
230 bb_error_msg("packet with bad UDP checksum received, ignoring"); 224 bb_error_msg("packet with bad UDP checksum received, ignoring");
231 return -2; 225 return -2;
232 } 226 }
233 227
234 memcpy(payload, &(packet.data), bytes - (sizeof(packet.ip) + sizeof(packet.udp))); 228 memcpy(payload, &packet.data, bytes - (sizeof(packet.ip) + sizeof(packet.udp)));
235 229
236 if (payload->cookie != htonl(DHCP_MAGIC)) { 230 if (payload->cookie != htonl(DHCP_MAGIC)) {
237 bb_error_msg("received bogus message (bad magic) - ignoring"); 231 bb_error_msg("received bogus message (bad magic) - ignoring");
238 return -2; 232 return -2;
239 } 233 }
240 DEBUG("oooooh!!! got some!"); 234 DEBUG("Got valid DHCP packet");
241 return bytes - (sizeof(packet.ip) + sizeof(packet.udp)); 235 return bytes - (sizeof(packet.ip) + sizeof(packet.udp));
242} 236}