summaryrefslogtreecommitdiff
path: root/networking/udhcp/dhcpd.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/udhcp/dhcpd.c')
-rw-r--r--networking/udhcp/dhcpd.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index d6e90cd03..93e06b237 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -25,7 +25,6 @@
25#include "common.h" 25#include "common.h"
26#include "dhcpc.h" 26#include "dhcpc.h"
27#include "dhcpd.h" 27#include "dhcpd.h"
28#include "options.h"
29 28
30 29
31/* Send a packet to a specific mac address and ip address by creating our own ip packet */ 30/* Send a packet to a specific mac address and ip address by creating our own ip packet */
@@ -94,7 +93,7 @@ static void init_packet(struct dhcp_packet *packet, struct dhcp_packet *oldpacke
94 packet->flags = oldpacket->flags; 93 packet->flags = oldpacket->flags;
95 packet->gateway_nip = oldpacket->gateway_nip; 94 packet->gateway_nip = oldpacket->gateway_nip;
96 packet->ciaddr = oldpacket->ciaddr; 95 packet->ciaddr = oldpacket->ciaddr;
97 add_simple_option(packet->options, DHCP_SERVER_ID, server_config.server_nip); 96 udhcp_add_simple_option(packet->options, DHCP_SERVER_ID, server_config.server_nip);
98} 97}
99 98
100/* Fill options field, siaddr_nip, and sname and boot_file fields. 99/* Fill options field, siaddr_nip, and sname and boot_file fields.
@@ -106,7 +105,7 @@ static void add_server_options(struct dhcp_packet *packet)
106 105
107 while (curr) { 106 while (curr) {
108 if (curr->data[OPT_CODE] != DHCP_LEASE_TIME) 107 if (curr->data[OPT_CODE] != DHCP_LEASE_TIME)
109 add_option_string(packet->options, curr->data); 108 udhcp_add_option_string(packet->options, curr->data);
110 curr = curr->next; 109 curr = curr->next;
111 } 110 }
112 111
@@ -121,7 +120,7 @@ static void add_server_options(struct dhcp_packet *packet)
121static uint32_t select_lease_time(struct dhcp_packet *packet) 120static uint32_t select_lease_time(struct dhcp_packet *packet)
122{ 121{
123 uint32_t lease_time_sec = server_config.max_lease_sec; 122 uint32_t lease_time_sec = server_config.max_lease_sec;
124 uint8_t *lease_time_opt = get_option(packet, DHCP_LEASE_TIME); 123 uint8_t *lease_time_opt = udhcp_get_option(packet, DHCP_LEASE_TIME);
125 if (lease_time_opt) { 124 if (lease_time_opt) {
126 move_from_unaligned32(lease_time_sec, lease_time_opt); 125 move_from_unaligned32(lease_time_sec, lease_time_opt);
127 lease_time_sec = ntohl(lease_time_sec); 126 lease_time_sec = ntohl(lease_time_sec);
@@ -159,7 +158,7 @@ static void send_offer(struct dhcp_packet *oldpacket, uint32_t static_lease_nip,
159 packet.yiaddr = lease->lease_nip; 158 packet.yiaddr = lease->lease_nip;
160 } 159 }
161 /* Or: if client has requested an IP */ 160 /* Or: if client has requested an IP */
162 else if ((req_ip_opt = get_option(oldpacket, DHCP_REQUESTED_IP)) != NULL 161 else if ((req_ip_opt = udhcp_get_option(oldpacket, DHCP_REQUESTED_IP)) != NULL
163 /* (read IP) */ 162 /* (read IP) */
164 && (move_from_unaligned32(req_nip, req_ip_opt), 1) 163 && (move_from_unaligned32(req_nip, req_ip_opt), 1)
165 /* and the IP is in the lease range */ 164 /* and the IP is in the lease range */
@@ -182,7 +181,7 @@ static void send_offer(struct dhcp_packet *oldpacket, uint32_t static_lease_nip,
182 return; 181 return;
183 } 182 }
184 /* Reserve the IP for a short time hoping to get DHCPREQUEST soon */ 183 /* Reserve the IP for a short time hoping to get DHCPREQUEST soon */
185 p_host_name = (const char*) get_option(oldpacket, DHCP_HOST_NAME); 184 p_host_name = (const char*) udhcp_get_option(oldpacket, DHCP_HOST_NAME);
186 lease = add_lease(packet.chaddr, packet.yiaddr, 185 lease = add_lease(packet.chaddr, packet.yiaddr,
187 server_config.offer_time, 186 server_config.offer_time,
188 p_host_name, 187 p_host_name,
@@ -195,7 +194,7 @@ static void send_offer(struct dhcp_packet *oldpacket, uint32_t static_lease_nip,
195 } 194 }
196 195
197 lease_time_sec = select_lease_time(oldpacket); 196 lease_time_sec = select_lease_time(oldpacket);
198 add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_sec)); 197 udhcp_add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_sec));
199 add_server_options(&packet); 198 add_server_options(&packet);
200 199
201 addr.s_addr = packet.yiaddr; 200 addr.s_addr = packet.yiaddr;
@@ -225,7 +224,7 @@ static void send_ACK(struct dhcp_packet *oldpacket, uint32_t yiaddr)
225 packet.yiaddr = yiaddr; 224 packet.yiaddr = yiaddr;
226 225
227 lease_time_sec = select_lease_time(oldpacket); 226 lease_time_sec = select_lease_time(oldpacket);
228 add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_sec)); 227 udhcp_add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_sec));
229 228
230 add_server_options(&packet); 229 add_server_options(&packet);
231 230
@@ -233,7 +232,7 @@ static void send_ACK(struct dhcp_packet *oldpacket, uint32_t yiaddr)
233 bb_info_msg("Sending ACK to %s", inet_ntoa(addr)); 232 bb_info_msg("Sending ACK to %s", inet_ntoa(addr));
234 send_packet(&packet, /*force_bcast:*/ 0); 233 send_packet(&packet, /*force_bcast:*/ 0);
235 234
236 p_host_name = (const char*) get_option(oldpacket, DHCP_HOST_NAME); 235 p_host_name = (const char*) udhcp_get_option(oldpacket, DHCP_HOST_NAME);
237 add_lease(packet.chaddr, packet.yiaddr, 236 add_lease(packet.chaddr, packet.yiaddr,
238 lease_time_sec, 237 lease_time_sec,
239 p_host_name, 238 p_host_name,
@@ -422,7 +421,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
422 bb_error_msg("not a REQUEST, ignoring packet"); 421 bb_error_msg("not a REQUEST, ignoring packet");
423 continue; 422 continue;
424 } 423 }
425 state = get_option(&packet, DHCP_MESSAGE_TYPE); 424 state = udhcp_get_option(&packet, DHCP_MESSAGE_TYPE);
426 if (state == NULL || state[0] < DHCP_MINTYPE || state[0] > DHCP_MAXTYPE) { 425 if (state == NULL || state[0] < DHCP_MINTYPE || state[0] > DHCP_MAXTYPE) {
427 bb_error_msg("no or bad message type option, ignoring packet"); 426 bb_error_msg("no or bad message type option, ignoring packet");
428 continue; 427 continue;
@@ -441,7 +440,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
441 } 440 }
442 441
443 /* Get REQUESTED_IP and SERVER_ID if present */ 442 /* Get REQUESTED_IP and SERVER_ID if present */
444 server_id_opt = get_option(&packet, DHCP_SERVER_ID); 443 server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID);
445 if (server_id_opt) { 444 if (server_id_opt) {
446 uint32_t server_id_net; 445 uint32_t server_id_net;
447 move_from_unaligned32(server_id_net, server_id_opt); 446 move_from_unaligned32(server_id_net, server_id_opt);
@@ -451,7 +450,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
451 continue; 450 continue;
452 } 451 }
453 } 452 }
454 requested_opt = get_option(&packet, DHCP_REQUESTED_IP); 453 requested_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP);
455 if (requested_opt) { 454 if (requested_opt) {
456 move_from_unaligned32(requested_nip, requested_opt); 455 move_from_unaligned32(requested_nip, requested_opt);
457 } 456 }