diff options
Diffstat (limited to 'networking/udhcp/clientpacket.c')
-rw-r--r-- | networking/udhcp/clientpacket.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/networking/udhcp/clientpacket.c b/networking/udhcp/clientpacket.c index 068f947cc..7d44697ec 100644 --- a/networking/udhcp/clientpacket.c +++ b/networking/udhcp/clientpacket.c | |||
@@ -203,7 +203,7 @@ int FAST_FUNC send_release(uint32_t server, uint32_t ciaddr) | |||
203 | 203 | ||
204 | 204 | ||
205 | /* Returns -1 on errors that are fatal for the socket, -2 for those that aren't */ | 205 | /* Returns -1 on errors that are fatal for the socket, -2 for those that aren't */ |
206 | int FAST_FUNC udhcp_recv_raw_packet(struct dhcpMessage *payload, int fd) | 206 | int FAST_FUNC udhcp_recv_raw_packet(struct dhcpMessage *dhcp_pkt, int fd) |
207 | { | 207 | { |
208 | int bytes; | 208 | int bytes; |
209 | struct udp_dhcp_packet packet; | 209 | struct udp_dhcp_packet packet; |
@@ -212,19 +212,19 @@ int FAST_FUNC udhcp_recv_raw_packet(struct dhcpMessage *payload, int fd) | |||
212 | memset(&packet, 0, sizeof(packet)); | 212 | memset(&packet, 0, sizeof(packet)); |
213 | bytes = safe_read(fd, &packet, sizeof(packet)); | 213 | bytes = safe_read(fd, &packet, sizeof(packet)); |
214 | if (bytes < 0) { | 214 | if (bytes < 0) { |
215 | DEBUG("Cannot read on raw listening socket - ignoring"); | 215 | log1("Packet read error, ignoring"); |
216 | /* NB: possible down interface, etc. Caller should pause. */ | 216 | /* NB: possible down interface, etc. Caller should pause. */ |
217 | return bytes; /* returns -1 */ | 217 | return bytes; /* returns -1 */ |
218 | } | 218 | } |
219 | 219 | ||
220 | if (bytes < (int) (sizeof(packet.ip) + sizeof(packet.udp))) { | 220 | if (bytes < (int) (sizeof(packet.ip) + sizeof(packet.udp))) { |
221 | DEBUG("Packet is too short, ignoring"); | 221 | log1("Packet is too short, ignoring"); |
222 | return -2; | 222 | return -2; |
223 | } | 223 | } |
224 | 224 | ||
225 | if (bytes < ntohs(packet.ip.tot_len)) { | 225 | if (bytes < ntohs(packet.ip.tot_len)) { |
226 | /* packet is bigger than sizeof(packet), we did partial read */ | 226 | /* packet is bigger than sizeof(packet), we did partial read */ |
227 | DEBUG("Oversized packet, ignoring"); | 227 | log1("Oversized packet, ignoring"); |
228 | return -2; | 228 | return -2; |
229 | } | 229 | } |
230 | 230 | ||
@@ -238,7 +238,7 @@ int FAST_FUNC udhcp_recv_raw_packet(struct dhcpMessage *payload, int fd) | |||
238 | /* || bytes > (int) sizeof(packet) - can't happen */ | 238 | /* || bytes > (int) sizeof(packet) - can't happen */ |
239 | || ntohs(packet.udp.len) != (uint16_t)(bytes - sizeof(packet.ip)) | 239 | || ntohs(packet.udp.len) != (uint16_t)(bytes - sizeof(packet.ip)) |
240 | ) { | 240 | ) { |
241 | DEBUG("Unrelated/bogus packet"); | 241 | log1("Unrelated/bogus packet, ignoring"); |
242 | return -2; | 242 | return -2; |
243 | } | 243 | } |
244 | 244 | ||
@@ -246,7 +246,7 @@ int FAST_FUNC udhcp_recv_raw_packet(struct dhcpMessage *payload, int fd) | |||
246 | check = packet.ip.check; | 246 | check = packet.ip.check; |
247 | packet.ip.check = 0; | 247 | packet.ip.check = 0; |
248 | if (check != udhcp_checksum(&packet.ip, sizeof(packet.ip))) { | 248 | if (check != udhcp_checksum(&packet.ip, sizeof(packet.ip))) { |
249 | DEBUG("Bad IP header checksum, ignoring"); | 249 | log1("Bad IP header checksum, ignoring"); |
250 | return -2; | 250 | return -2; |
251 | } | 251 | } |
252 | 252 | ||
@@ -257,16 +257,17 @@ int FAST_FUNC udhcp_recv_raw_packet(struct dhcpMessage *payload, int fd) | |||
257 | check = packet.udp.check; | 257 | check = packet.udp.check; |
258 | packet.udp.check = 0; | 258 | packet.udp.check = 0; |
259 | if (check && check != udhcp_checksum(&packet, bytes)) { | 259 | if (check && check != udhcp_checksum(&packet, bytes)) { |
260 | bb_error_msg("packet with bad UDP checksum received, ignoring"); | 260 | log1("Packet with bad UDP checksum received, ignoring"); |
261 | return -2; | 261 | return -2; |
262 | } | 262 | } |
263 | 263 | ||
264 | memcpy(payload, &packet.data, bytes - (sizeof(packet.ip) + sizeof(packet.udp))); | 264 | memcpy(dhcp_pkt, &packet.data, bytes - (sizeof(packet.ip) + sizeof(packet.udp))); |
265 | 265 | ||
266 | if (payload->cookie != htonl(DHCP_MAGIC)) { | 266 | if (dhcp_pkt->cookie != htonl(DHCP_MAGIC)) { |
267 | bb_error_msg("received bogus message (bad magic), ignoring"); | 267 | bb_info_msg("Packet with bad magic, ignoring"); |
268 | return -2; | 268 | return -2; |
269 | } | 269 | } |
270 | DEBUG("Got valid DHCP packet"); | 270 | log1("Got valid DHCP packet"); |
271 | udhcp_dump_packet(dhcp_pkt); | ||
271 | return bytes - (sizeof(packet.ip) + sizeof(packet.udp)); | 272 | return bytes - (sizeof(packet.ip) + sizeof(packet.udp)); |
272 | } | 273 | } |