diff options
Diffstat (limited to 'networking/udhcp/clientpacket.c')
-rw-r--r-- | networking/udhcp/clientpacket.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/networking/udhcp/clientpacket.c b/networking/udhcp/clientpacket.c index 82975700c..f7e7d442c 100644 --- a/networking/udhcp/clientpacket.c +++ b/networking/udhcp/clientpacket.c | |||
@@ -44,7 +44,8 @@ unsigned long random_xid(void) | |||
44 | 44 | ||
45 | fd = open("/dev/urandom", 0); | 45 | fd = open("/dev/urandom", 0); |
46 | if (fd < 0 || read(fd, &seed, sizeof(seed)) < 0) { | 46 | if (fd < 0 || read(fd, &seed, sizeof(seed)) < 0) { |
47 | LOG(LOG_WARNING, "Could not load seed from /dev/urandom: %m"); | 47 | bb_info_msg("Could not load seed " |
48 | "from /dev/urandom: %s", strerror(errno)); | ||
48 | seed = time(0); | 49 | seed = time(0); |
49 | } | 50 | } |
50 | if (fd >= 0) close(fd); | 51 | if (fd >= 0) close(fd); |
@@ -97,7 +98,7 @@ int send_discover(unsigned long xid, unsigned long requested) | |||
97 | add_simple_option(packet.options, DHCP_REQUESTED_IP, requested); | 98 | add_simple_option(packet.options, DHCP_REQUESTED_IP, requested); |
98 | 99 | ||
99 | add_requests(&packet); | 100 | add_requests(&packet); |
100 | LOG(LOG_DEBUG, "Sending discover..."); | 101 | bb_info_msg("Sending discover..."); |
101 | return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, | 102 | return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, |
102 | SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); | 103 | SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); |
103 | } | 104 | } |
@@ -117,7 +118,7 @@ int send_selecting(unsigned long xid, unsigned long server, unsigned long reques | |||
117 | 118 | ||
118 | add_requests(&packet); | 119 | add_requests(&packet); |
119 | addr.s_addr = requested; | 120 | addr.s_addr = requested; |
120 | LOG(LOG_DEBUG, "Sending select for %s...", inet_ntoa(addr)); | 121 | bb_info_msg("Sending select for %s...", inet_ntoa(addr)); |
121 | return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, | 122 | return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, |
122 | SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); | 123 | SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); |
123 | } | 124 | } |
@@ -134,7 +135,7 @@ int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr) | |||
134 | packet.ciaddr = ciaddr; | 135 | packet.ciaddr = ciaddr; |
135 | 136 | ||
136 | add_requests(&packet); | 137 | add_requests(&packet); |
137 | LOG(LOG_DEBUG, "Sending renew..."); | 138 | bb_info_msg("Sending renew..."); |
138 | if (server) | 139 | if (server) |
139 | ret = udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); | 140 | ret = udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); |
140 | else ret = udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, | 141 | else ret = udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, |
@@ -155,7 +156,7 @@ int send_release(unsigned long server, unsigned long ciaddr) | |||
155 | add_simple_option(packet.options, DHCP_REQUESTED_IP, ciaddr); | 156 | add_simple_option(packet.options, DHCP_REQUESTED_IP, ciaddr); |
156 | add_simple_option(packet.options, DHCP_SERVER_ID, server); | 157 | add_simple_option(packet.options, DHCP_SERVER_ID, server); |
157 | 158 | ||
158 | LOG(LOG_DEBUG, "Sending release..."); | 159 | bb_info_msg("Sending release..."); |
159 | return udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); | 160 | return udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); |
160 | } | 161 | } |
161 | 162 | ||
@@ -171,18 +172,18 @@ int get_raw_packet(struct dhcpMessage *payload, int fd) | |||
171 | memset(&packet, 0, sizeof(struct udp_dhcp_packet)); | 172 | memset(&packet, 0, sizeof(struct udp_dhcp_packet)); |
172 | bytes = read(fd, &packet, sizeof(struct udp_dhcp_packet)); | 173 | bytes = read(fd, &packet, sizeof(struct udp_dhcp_packet)); |
173 | if (bytes < 0) { | 174 | if (bytes < 0) { |
174 | DEBUG(LOG_INFO, "couldn't read on raw listening socket -- ignoring"); | 175 | DEBUG("Couldn't read on raw listening socket - ignoring"); |
175 | usleep(500000); /* possible down interface, looping condition */ | 176 | usleep(500000); /* possible down interface, looping condition */ |
176 | return -1; | 177 | return -1; |
177 | } | 178 | } |
178 | 179 | ||
179 | if (bytes < (int) (sizeof(struct iphdr) + sizeof(struct udphdr))) { | 180 | if (bytes < (int) (sizeof(struct iphdr) + sizeof(struct udphdr))) { |
180 | DEBUG(LOG_INFO, "message too short, ignoring"); | 181 | DEBUG("Message too short, ignoring"); |
181 | return -2; | 182 | return -2; |
182 | } | 183 | } |
183 | 184 | ||
184 | if (bytes < ntohs(packet.ip.tot_len)) { | 185 | if (bytes < ntohs(packet.ip.tot_len)) { |
185 | DEBUG(LOG_INFO, "Truncated packet"); | 186 | DEBUG("Truncated packet"); |
186 | return -2; | 187 | return -2; |
187 | } | 188 | } |
188 | 189 | ||
@@ -194,7 +195,7 @@ int get_raw_packet(struct dhcpMessage *payload, int fd) | |||
194 | packet.ip.ihl != sizeof(packet.ip) >> 2 || packet.udp.dest != htons(CLIENT_PORT) || | 195 | packet.ip.ihl != sizeof(packet.ip) >> 2 || packet.udp.dest != htons(CLIENT_PORT) || |
195 | bytes > (int) sizeof(struct udp_dhcp_packet) || | 196 | bytes > (int) sizeof(struct udp_dhcp_packet) || |
196 | ntohs(packet.udp.len) != (uint16_t) (bytes - sizeof(packet.ip))) { | 197 | ntohs(packet.udp.len) != (uint16_t) (bytes - sizeof(packet.ip))) { |
197 | DEBUG(LOG_INFO, "unrelated/bogus packet"); | 198 | DEBUG("Unrelated/bogus packet"); |
198 | return -2; | 199 | return -2; |
199 | } | 200 | } |
200 | 201 | ||
@@ -202,7 +203,7 @@ int get_raw_packet(struct dhcpMessage *payload, int fd) | |||
202 | check = packet.ip.check; | 203 | check = packet.ip.check; |
203 | packet.ip.check = 0; | 204 | packet.ip.check = 0; |
204 | if (check != udhcp_checksum(&(packet.ip), sizeof(packet.ip))) { | 205 | if (check != udhcp_checksum(&(packet.ip), sizeof(packet.ip))) { |
205 | DEBUG(LOG_INFO, "bad IP header checksum, ignoring"); | 206 | DEBUG("bad IP header checksum, ignoring"); |
206 | return -1; | 207 | return -1; |
207 | } | 208 | } |
208 | 209 | ||
@@ -218,17 +219,17 @@ int get_raw_packet(struct dhcpMessage *payload, int fd) | |||
218 | packet.ip.daddr = dest; | 219 | packet.ip.daddr = dest; |
219 | packet.ip.tot_len = packet.udp.len; /* cheat on the psuedo-header */ | 220 | packet.ip.tot_len = packet.udp.len; /* cheat on the psuedo-header */ |
220 | if (check && check != udhcp_checksum(&packet, bytes)) { | 221 | if (check && check != udhcp_checksum(&packet, bytes)) { |
221 | DEBUG(LOG_ERR, "packet with bad UDP checksum received, ignoring"); | 222 | bb_error_msg("Packet with bad UDP checksum received, ignoring"); |
222 | return -2; | 223 | return -2; |
223 | } | 224 | } |
224 | 225 | ||
225 | memcpy(payload, &(packet.data), bytes - (sizeof(packet.ip) + sizeof(packet.udp))); | 226 | memcpy(payload, &(packet.data), bytes - (sizeof(packet.ip) + sizeof(packet.udp))); |
226 | 227 | ||
227 | if (ntohl(payload->cookie) != DHCP_MAGIC) { | 228 | if (ntohl(payload->cookie) != DHCP_MAGIC) { |
228 | LOG(LOG_ERR, "received bogus message (bad magic) -- ignoring"); | 229 | bb_error_msg("Received bogus message (bad magic) - ignoring"); |
229 | return -2; | 230 | return -2; |
230 | } | 231 | } |
231 | DEBUG(LOG_INFO, "oooooh!!! got some!"); | 232 | DEBUG("oooooh!!! got some!"); |
232 | return bytes - (sizeof(packet.ip) + sizeof(packet.udp)); | 233 | return bytes - (sizeof(packet.ip) + sizeof(packet.udp)); |
233 | 234 | ||
234 | } | 235 | } |