aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/udhcp/clientpacket.c20
-rw-r--r--networking/udhcp/common.h35
-rw-r--r--networking/udhcp/dhcpc.c6
-rw-r--r--networking/udhcp/dhcpc.h2
-rw-r--r--networking/udhcp/dhcpd.c18
-rw-r--r--networking/udhcp/dhcpd.h37
-rw-r--r--networking/udhcp/dhcprelay.c8
-rw-r--r--networking/udhcp/dumpleases.c4
-rw-r--r--networking/udhcp/files.c4
-rw-r--r--networking/udhcp/leases.c24
-rw-r--r--networking/udhcp/options.c15
-rw-r--r--networking/udhcp/options.h2
-rw-r--r--networking/udhcp/packet.c20
-rw-r--r--networking/udhcp/script.c4
-rw-r--r--networking/udhcp/serverpacket.c30
15 files changed, 126 insertions, 103 deletions
diff --git a/networking/udhcp/clientpacket.c b/networking/udhcp/clientpacket.c
index 7d44697ec..21c1a7bd5 100644
--- a/networking/udhcp/clientpacket.c
+++ b/networking/udhcp/clientpacket.c
@@ -38,7 +38,7 @@ uint32_t FAST_FUNC random_xid(void)
38 38
39 39
40/* Initialize the packet with the proper defaults */ 40/* Initialize the packet with the proper defaults */
41static void init_packet(struct dhcpMessage *packet, char type) 41static void init_packet(struct dhcp_packet *packet, char type)
42{ 42{
43 udhcp_init_header(packet, type); 43 udhcp_init_header(packet, type);
44 memcpy(packet->chaddr, client_config.client_mac, 6); 44 memcpy(packet->chaddr, client_config.client_mac, 6);
@@ -56,7 +56,7 @@ static void init_packet(struct dhcpMessage *packet, char type)
56/* 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
57 * 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
58 * goes towards the head of the packet. */ 58 * goes towards the head of the packet. */
59static void add_param_req_option(struct dhcpMessage *packet) 59static void add_param_req_option(struct dhcp_packet *packet)
60{ 60{
61 uint8_t c; 61 uint8_t c;
62 int end = end_option(packet->options); 62 int end = end_option(packet->options);
@@ -96,7 +96,7 @@ static void add_param_req_option(struct dhcpMessage *packet)
96 * client reverts to using the IP broadcast address. 96 * client reverts to using the IP broadcast address.
97 */ 97 */
98 98
99static int raw_bcast_from_client_config_ifindex(struct dhcpMessage *packet) 99static int raw_bcast_from_client_config_ifindex(struct dhcp_packet *packet)
100{ 100{
101 return udhcp_send_raw_packet(packet, 101 return udhcp_send_raw_packet(packet,
102 /*src*/ INADDR_ANY, CLIENT_PORT, 102 /*src*/ INADDR_ANY, CLIENT_PORT,
@@ -109,7 +109,7 @@ static int raw_bcast_from_client_config_ifindex(struct dhcpMessage *packet)
109/* Broadcast a DHCP decline message */ 109/* Broadcast a DHCP decline message */
110int FAST_FUNC send_decline(uint32_t xid, uint32_t server, uint32_t requested) 110int FAST_FUNC send_decline(uint32_t xid, uint32_t server, uint32_t requested)
111{ 111{
112 struct dhcpMessage packet; 112 struct dhcp_packet packet;
113 113
114 init_packet(&packet, DHCPDECLINE); 114 init_packet(&packet, DHCPDECLINE);
115 packet.xid = xid; 115 packet.xid = xid;
@@ -126,7 +126,7 @@ int FAST_FUNC send_decline(uint32_t xid, uint32_t server, uint32_t requested)
126/* Broadcast a DHCP discover packet to the network, with an optionally requested IP */ 126/* Broadcast a DHCP discover packet to the network, with an optionally requested IP */
127int FAST_FUNC send_discover(uint32_t xid, uint32_t requested) 127int FAST_FUNC send_discover(uint32_t xid, uint32_t requested)
128{ 128{
129 struct dhcpMessage packet; 129 struct dhcp_packet packet;
130 130
131 init_packet(&packet, DHCPDISCOVER); 131 init_packet(&packet, DHCPDISCOVER);
132 packet.xid = xid; 132 packet.xid = xid;
@@ -150,7 +150,7 @@ int FAST_FUNC send_discover(uint32_t xid, uint32_t requested)
150 */ 150 */
151int FAST_FUNC send_select(uint32_t xid, uint32_t server, uint32_t requested) 151int FAST_FUNC send_select(uint32_t xid, uint32_t server, uint32_t requested)
152{ 152{
153 struct dhcpMessage packet; 153 struct dhcp_packet packet;
154 struct in_addr addr; 154 struct in_addr addr;
155 155
156 init_packet(&packet, DHCPREQUEST); 156 init_packet(&packet, DHCPREQUEST);
@@ -169,7 +169,7 @@ int FAST_FUNC send_select(uint32_t xid, uint32_t server, uint32_t requested)
169/* Unicasts or broadcasts a DHCP renew message */ 169/* Unicasts or broadcasts a DHCP renew message */
170int FAST_FUNC send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr) 170int FAST_FUNC send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr)
171{ 171{
172 struct dhcpMessage packet; 172 struct dhcp_packet packet;
173 173
174 init_packet(&packet, DHCPREQUEST); 174 init_packet(&packet, DHCPREQUEST);
175 packet.xid = xid; 175 packet.xid = xid;
@@ -189,7 +189,7 @@ int FAST_FUNC send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr)
189/* Unicasts a DHCP release message */ 189/* Unicasts a DHCP release message */
190int FAST_FUNC send_release(uint32_t server, uint32_t ciaddr) 190int FAST_FUNC send_release(uint32_t server, uint32_t ciaddr)
191{ 191{
192 struct dhcpMessage packet; 192 struct dhcp_packet packet;
193 193
194 init_packet(&packet, DHCPRELEASE); 194 init_packet(&packet, DHCPRELEASE);
195 packet.xid = random_xid(); 195 packet.xid = random_xid();
@@ -203,10 +203,10 @@ 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 */
206int FAST_FUNC udhcp_recv_raw_packet(struct dhcpMessage *dhcp_pkt, int fd) 206int FAST_FUNC udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
207{ 207{
208 int bytes; 208 int bytes;
209 struct udp_dhcp_packet packet; 209 struct ip_udp_dhcp_packet packet;
210 uint16_t check; 210 uint16_t check;
211 211
212 memset(&packet, 0, sizeof(packet)); 212 memset(&packet, 0, sizeof(packet));
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h
index 40b8df4df..a01597f68 100644
--- a/networking/udhcp/common.h
+++ b/networking/udhcp/common.h
@@ -23,8 +23,8 @@ extern const uint8_t MAC_BCAST_ADDR[6]; /* six all-ones */
23 23
24#define DHCP_OPTIONS_BUFSIZE 308 24#define DHCP_OPTIONS_BUFSIZE 308
25 25
26//TODO: rename to dhcp_packet; rename ciaddr/yiaddr/chaddr 26//TODO: rename ciaddr/yiaddr/chaddr
27struct dhcpMessage { 27struct dhcp_packet {
28 uint8_t op; /* 1 = BOOTREQUEST, 2 = BOOTREPLY */ 28 uint8_t op; /* 1 = BOOTREQUEST, 2 = BOOTREPLY */
29 uint8_t htype; /* hardware address type. 1 = 10mb ethernet */ 29 uint8_t htype; /* hardware address type. 1 = 10mb ethernet */
30 uint8_t hlen; /* hardware address length */ 30 uint8_t hlen; /* hardware address length */
@@ -45,39 +45,38 @@ struct dhcpMessage {
45 uint8_t options[DHCP_OPTIONS_BUFSIZE + CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS]; 45 uint8_t options[DHCP_OPTIONS_BUFSIZE + CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS];
46} PACKED; 46} PACKED;
47 47
48//TODO: rename to ip_udp_dhcp_packet? 48struct ip_udp_dhcp_packet {
49struct udp_dhcp_packet {
50 struct iphdr ip; 49 struct iphdr ip;
51 struct udphdr udp; 50 struct udphdr udp;
52 struct dhcpMessage data; 51 struct dhcp_packet data;
53} PACKED; 52} PACKED;
54 53
55/* Let's see whether compiler understood us right */ 54/* Let's see whether compiler understood us right */
56struct BUG_bad_sizeof_struct_udp_dhcp_packet { 55struct BUG_bad_sizeof_struct_ip_udp_dhcp_packet {
57 char BUG_bad_sizeof_struct_udp_dhcp_packet 56 char BUG_bad_sizeof_struct_ip_udp_dhcp_packet
58 [(sizeof(struct udp_dhcp_packet) != 576 + CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS) ? -1 : 1]; 57 [(sizeof(struct ip_udp_dhcp_packet) != 576 + CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS) ? -1 : 1];
59}; 58};
60 59
61uint16_t udhcp_checksum(void *addr, int count) FAST_FUNC; 60uint16_t udhcp_checksum(void *addr, int count) FAST_FUNC;
62 61
63void udhcp_init_header(struct dhcpMessage *packet, char type) FAST_FUNC; 62void udhcp_init_header(struct dhcp_packet *packet, char type) FAST_FUNC;
64 63
65/*int udhcp_recv_raw_packet(struct dhcpMessage *dhcp_pkt, int fd); - in dhcpc.h */ 64/*int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd); - in dhcpc.h */
66int udhcp_recv_kernel_packet(struct dhcpMessage *packet, int fd) FAST_FUNC; 65int udhcp_recv_kernel_packet(struct dhcp_packet *packet, int fd) FAST_FUNC;
67 66
68int udhcp_send_raw_packet(struct dhcpMessage *dhcp_pkt, 67int udhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt,
69 uint32_t source_ip, int source_port, 68 uint32_t source_ip, int source_port,
70 uint32_t dest_ip, int dest_port, const uint8_t *dest_arp, 69 uint32_t dest_ip, int dest_port, const uint8_t *dest_arp,
71 int ifindex) FAST_FUNC; 70 int ifindex) FAST_FUNC;
72 71
73int udhcp_send_kernel_packet(struct dhcpMessage *dhcp_pkt, 72int udhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt,
74 uint32_t source_ip, int source_port, 73 uint32_t source_ip, int source_port,
75 uint32_t dest_ip, int dest_port) FAST_FUNC; 74 uint32_t dest_ip, int dest_port) FAST_FUNC;
76 75
77 76
78/**/ 77/**/
79 78
80void udhcp_run_script(struct dhcpMessage *packet, const char *name) FAST_FUNC; 79void udhcp_run_script(struct dhcp_packet *packet, const char *name) FAST_FUNC;
81 80
82// Still need to clean these up... 81// Still need to clean these up...
83 82
@@ -104,16 +103,22 @@ int arpping(uint32_t test_ip,
104extern int dhcp_verbose; 103extern int dhcp_verbose;
105# define log1(...) do { if (dhcp_verbose >= 1) bb_info_msg(__VA_ARGS__); } while (0) 104# define log1(...) do { if (dhcp_verbose >= 1) bb_info_msg(__VA_ARGS__); } while (0)
106# if CONFIG_UDHCP_DEBUG >= 2 105# if CONFIG_UDHCP_DEBUG >= 2
107void udhcp_dump_packet(struct dhcpMessage *packet) FAST_FUNC; 106void udhcp_dump_packet(struct dhcp_packet *packet) FAST_FUNC;
108# define log2(...) do { if (dhcp_verbose >= 2) bb_info_msg(__VA_ARGS__); } while (0) 107# define log2(...) do { if (dhcp_verbose >= 2) bb_info_msg(__VA_ARGS__); } while (0)
109# else 108# else
110# define udhcp_dump_packet(...) ((void)0) 109# define udhcp_dump_packet(...) ((void)0)
111# define log2(...) ((void)0) 110# define log2(...) ((void)0)
112# endif 111# endif
112# if CONFIG_UDHCP_DEBUG >= 3
113# define log3(...) do { if (dhcp_verbose >= 3) bb_info_msg(__VA_ARGS__); } while (0)
114# else
115# define log3(...) ((void)0)
116# endif
113#else 117#else
114# define udhcp_dump_packet(...) ((void)0) 118# define udhcp_dump_packet(...) ((void)0)
115# define log1(...) ((void)0) 119# define log1(...) ((void)0)
116# define log2(...) ((void)0) 120# define log2(...) ((void)0)
121# define log3(...) ((void)0)
117#endif 122#endif
118 123
119POP_SAVED_FUNCTION_VISIBILITY 124POP_SAVED_FUNCTION_VISIBILITY
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index eed9d9a01..41bb0b09c 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -149,7 +149,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
149 int max_fd; 149 int max_fd;
150 int retval; 150 int retval;
151 struct timeval tv; 151 struct timeval tv;
152 struct dhcpMessage packet; 152 struct dhcp_packet packet;
153 fd_set rfds; 153 fd_set rfds;
154 154
155#if ENABLE_GETOPT_LONG 155#if ENABLE_GETOPT_LONG
@@ -498,7 +498,9 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
498 } 498 }
499 499
500 /* Ignore packets that aren't for us */ 500 /* Ignore packets that aren't for us */
501 if (memcmp(packet.chaddr, client_config.client_mac, 6)) { 501 if (packet.hlen != 6
502 || memcmp(packet.chaddr, client_config.client_mac, 6)
503 ) {
502//FIXME: need to also check that last 10 bytes are zero 504//FIXME: need to also check that last 10 bytes are zero
503 log1("chaddr does not match, ignoring packet"); // log2? 505 log1("chaddr does not match, ignoring packet"); // log2?
504 continue; 506 continue;
diff --git a/networking/udhcp/dhcpc.h b/networking/udhcp/dhcpc.h
index a7ed779a1..9bb1ac2af 100644
--- a/networking/udhcp/dhcpc.h
+++ b/networking/udhcp/dhcpc.h
@@ -43,7 +43,7 @@ int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr) FAST_FUNC;
43int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr) FAST_FUNC; 43int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr) FAST_FUNC;
44int send_release(uint32_t server, uint32_t ciaddr) FAST_FUNC; 44int send_release(uint32_t server, uint32_t ciaddr) FAST_FUNC;
45 45
46int udhcp_recv_raw_packet(struct dhcpMessage *dhcp_pkt, int fd) FAST_FUNC; 46int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd) FAST_FUNC;
47 47
48POP_SAVED_FUNCTION_VISIBILITY 48POP_SAVED_FUNCTION_VISIBILITY
49 49
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index cbc968401..348246341 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -18,7 +18,7 @@
18 18
19 19
20/* globals */ 20/* globals */
21struct dhcpOfferedAddr *leases; 21struct dyn_lease *leases;
22/* struct server_config_t server_config is in bb_common_bufsiz1 */ 22/* struct server_config_t server_config is in bb_common_bufsiz1 */
23 23
24 24
@@ -27,7 +27,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
27{ 27{
28 fd_set rfds; 28 fd_set rfds;
29 int server_socket = -1, retval, max_sock; 29 int server_socket = -1, retval, max_sock;
30 struct dhcpMessage packet; 30 struct dhcp_packet packet;
31 uint8_t *state, *server_id, *requested; 31 uint8_t *state, *server_id, *requested;
32 uint32_t server_id_aligned = server_id_aligned; /* for compiler */ 32 uint32_t server_id_aligned = server_id_aligned; /* for compiler */
33 uint32_t requested_aligned = requested_aligned; 33 uint32_t requested_aligned = requested_aligned;
@@ -36,7 +36,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
36 unsigned num_ips; 36 unsigned num_ips;
37 unsigned opt; 37 unsigned opt;
38 struct option_set *option; 38 struct option_set *option;
39 struct dhcpOfferedAddr *lease, static_lease; 39 struct dyn_lease *lease, static_lease;
40 IF_FEATURE_UDHCP_PORT(char *str_P;) 40 IF_FEATURE_UDHCP_PORT(char *str_P;)
41 41
42#if ENABLE_FEATURE_UDHCP_PORT 42#if ENABLE_FEATURE_UDHCP_PORT
@@ -170,6 +170,11 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
170 continue; 170 continue;
171 } 171 }
172 172
173 if (packet.hlen != 6) {
174 bb_error_msg("MAC length != 6, ignoring packet");
175 continue;
176 }
177
173 state = get_option(&packet, DHCP_MESSAGE_TYPE); 178 state = get_option(&packet, DHCP_MESSAGE_TYPE);
174 if (state == NULL) { 179 if (state == NULL) {
175 bb_error_msg("no message type option, ignoring packet"); 180 bb_error_msg("no message type option, ignoring packet");
@@ -181,7 +186,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
181 if (static_lease_ip) { 186 if (static_lease_ip) {
182 bb_info_msg("Found static lease: %x", static_lease_ip); 187 bb_info_msg("Found static lease: %x", static_lease_ip);
183 188
184 memcpy(&static_lease.lease_mac16, &packet.chaddr, 16); 189 memcpy(&static_lease.lease_mac, &packet.chaddr, 6);
185 static_lease.lease_nip = static_lease_ip; 190 static_lease.lease_nip = static_lease_ip;
186 static_lease.expires = 0; 191 static_lease.expires = 0;
187 192
@@ -212,7 +217,6 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
212 if (lease) { 217 if (lease) {
213 if (server_id) { 218 if (server_id) {
214 /* SELECTING State */ 219 /* SELECTING State */
215 log1("server_id = %08x", ntohl(server_id_aligned));
216 if (server_id_aligned == server_config.server_nip 220 if (server_id_aligned == server_config.server_nip
217 && requested 221 && requested
218 && requested_aligned == lease->lease_nip 222 && requested_aligned == lease->lease_nip
@@ -242,7 +246,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
242 if (lease) { 246 if (lease) {
243 if (lease_expired(lease)) { 247 if (lease_expired(lease)) {
244 /* probably best if we drop this lease */ 248 /* probably best if we drop this lease */
245 memset(lease->lease_mac16, 0, 16); 249 memset(lease->lease_mac, 0, sizeof(lease->lease_mac));
246 } else { 250 } else {
247 /* make some contention for this address */ 251 /* make some contention for this address */
248 send_NAK(&packet); 252 send_NAK(&packet);
@@ -264,7 +268,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
264 case DHCPDECLINE: 268 case DHCPDECLINE:
265 log1("Received DECLINE"); 269 log1("Received DECLINE");
266 if (lease) { 270 if (lease) {
267 memset(lease->lease_mac16, 0, 16); 271 memset(lease->lease_mac, 0, sizeof(lease->lease_mac));
268 lease->expires = time(NULL) + server_config.decline_time; 272 lease->expires = time(NULL) + server_config.decline_time;
269 } 273 }
270 break; 274 break;
diff --git a/networking/udhcp/dhcpd.h b/networking/udhcp/dhcpd.h
index 53cfad41f..7776708cf 100644
--- a/networking/udhcp/dhcpd.h
+++ b/networking/udhcp/dhcpd.h
@@ -79,30 +79,33 @@ struct server_config_t {
79typedef uint32_t leasetime_t; 79typedef uint32_t leasetime_t;
80typedef int32_t signed_leasetime_t; 80typedef int32_t signed_leasetime_t;
81 81
82//TODO: (1) rename to dyn_lease (that's what it is. we also have static_lease). 82struct dyn_lease {
83//(2) lease_mac16 may be shortened to lease_mac[6], since e.g. ARP probing uses
84//only 6 first bytes anyway. We can check received dhcp packets
85//that their "chaddr"s have only 6 first bytes != 0, and complain otherwise.
86struct dhcpOfferedAddr {
87 uint8_t lease_mac16[16];
88 /* "nip": IP in network order */ 83 /* "nip": IP in network order */
89 uint32_t lease_nip;
90 /* Unix time when lease expires. Kept in memory in host order. 84 /* Unix time when lease expires. Kept in memory in host order.
91 * When written to file, converted to network order 85 * When written to file, converted to network order
92 * and adjusted (current time subtracted) */ 86 * and adjusted (current time subtracted) */
93 leasetime_t expires; 87 leasetime_t expires;
94 uint8_t hostname[20]; /* (size is a multiply of 4) */ 88 uint32_t lease_nip;
89 /* We use lease_mac[6], since e.g. ARP probing uses
90 * only 6 first bytes anyway. We check received dhcp packets
91 * that their hlen == 6 and thus chaddr has only 6 significant bytes
92 * (dhcp packet has chaddr[16])
93 */
94 uint8_t lease_mac[6];
95 uint8_t hostname[20];
96 uint8_t pad[2];
97 /* total size is a multiply of 4 */
95}; 98};
96 99
97extern struct dhcpOfferedAddr *leases; 100extern struct dyn_lease *leases;
98 101
99struct dhcpOfferedAddr *add_lease( 102struct dyn_lease *add_lease(
100 const uint8_t *chaddr, uint32_t yiaddr, 103 const uint8_t *chaddr, uint32_t yiaddr,
101 leasetime_t leasetime, uint8_t *hostname 104 leasetime_t leasetime, uint8_t *hostname
102 ) FAST_FUNC; 105 ) FAST_FUNC;
103int lease_expired(struct dhcpOfferedAddr *lease) FAST_FUNC; 106int lease_expired(struct dyn_lease *lease) FAST_FUNC;
104struct dhcpOfferedAddr *find_lease_by_chaddr(const uint8_t *chaddr) FAST_FUNC; 107struct dyn_lease *find_lease_by_chaddr(const uint8_t *chaddr) FAST_FUNC;
105struct dhcpOfferedAddr *find_lease_by_yiaddr(uint32_t yiaddr) FAST_FUNC; 108struct dyn_lease *find_lease_by_yiaddr(uint32_t yiaddr) FAST_FUNC;
106uint32_t find_free_or_expired_address(const uint8_t *chaddr) FAST_FUNC; 109uint32_t find_free_or_expired_address(const uint8_t *chaddr) FAST_FUNC;
107 110
108 111
@@ -121,10 +124,10 @@ void print_static_leases(struct static_lease **st_lease_pp) FAST_FUNC;
121 124
122/*** serverpacket.h ***/ 125/*** serverpacket.h ***/
123 126
124int send_offer(struct dhcpMessage *oldpacket) FAST_FUNC; 127int send_offer(struct dhcp_packet *oldpacket) FAST_FUNC;
125int send_NAK(struct dhcpMessage *oldpacket) FAST_FUNC; 128int send_NAK(struct dhcp_packet *oldpacket) FAST_FUNC;
126int send_ACK(struct dhcpMessage *oldpacket, uint32_t yiaddr) FAST_FUNC; 129int send_ACK(struct dhcp_packet *oldpacket, uint32_t yiaddr) FAST_FUNC;
127int send_inform(struct dhcpMessage *oldpacket) FAST_FUNC; 130int send_inform(struct dhcp_packet *oldpacket) FAST_FUNC;
128 131
129 132
130/*** files.h ***/ 133/*** files.h ***/
diff --git a/networking/udhcp/dhcprelay.c b/networking/udhcp/dhcprelay.c
index 2fee49a41..a7e715ff9 100644
--- a/networking/udhcp/dhcprelay.c
+++ b/networking/udhcp/dhcprelay.c
@@ -97,7 +97,7 @@ static void xid_del(uint32_t xid)
97 * p - pointer to the dhcp packet 97 * p - pointer to the dhcp packet
98 * returns the message type on success, -1 otherwise 98 * returns the message type on success, -1 otherwise
99 */ 99 */
100static int get_dhcp_packet_type(struct dhcpMessage *p) 100static int get_dhcp_packet_type(struct dhcp_packet *p)
101{ 101{
102 uint8_t *op; 102 uint8_t *op;
103 103
@@ -175,7 +175,7 @@ static int init_sockets(char **client_ifaces, int num_clients,
175 * p - packet to send 175 * p - packet to send
176 * client - number of the client 176 * client - number of the client
177 */ 177 */
178static void pass_to_server(struct dhcpMessage *p, int packet_len, int client, int *fds, 178static void pass_to_server(struct dhcp_packet *p, int packet_len, int client, int *fds,
179 struct sockaddr_in *client_addr, struct sockaddr_in *server_addr) 179 struct sockaddr_in *client_addr, struct sockaddr_in *server_addr)
180{ 180{
181 int res, type; 181 int res, type;
@@ -206,7 +206,7 @@ static void pass_to_server(struct dhcpMessage *p, int packet_len, int client, in
206 * pass_to_client() - forwards dhcp packets from server to client 206 * pass_to_client() - forwards dhcp packets from server to client
207 * p - packet to send 207 * p - packet to send
208 */ 208 */
209static void pass_to_client(struct dhcpMessage *p, int packet_len, int *fds) 209static void pass_to_client(struct dhcp_packet *p, int packet_len, int *fds)
210{ 210{
211 int res, type; 211 int res, type;
212 struct xid_item *item; 212 struct xid_item *item;
@@ -240,7 +240,7 @@ static void pass_to_client(struct dhcpMessage *p, int packet_len, int *fds)
240int dhcprelay_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 240int dhcprelay_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
241int dhcprelay_main(int argc, char **argv) 241int dhcprelay_main(int argc, char **argv)
242{ 242{
243 struct dhcpMessage dhcp_msg; 243 struct dhcp_packet dhcp_msg;
244 struct sockaddr_in server_addr; 244 struct sockaddr_in server_addr;
245 struct sockaddr_in client_addr; 245 struct sockaddr_in client_addr;
246 fd_set rfds; 246 fd_set rfds;
diff --git a/networking/udhcp/dumpleases.c b/networking/udhcp/dumpleases.c
index 5b98aa5fe..d6176fb6b 100644
--- a/networking/udhcp/dumpleases.c
+++ b/networking/udhcp/dumpleases.c
@@ -25,7 +25,7 @@ int dumpleases_main(int argc UNUSED_PARAM, char **argv)
25 unsigned opt; 25 unsigned opt;
26 int64_t written_at, curr, expires_abs; 26 int64_t written_at, curr, expires_abs;
27 const char *file = LEASES_FILE; 27 const char *file = LEASES_FILE;
28 struct dhcpOfferedAddr lease; 28 struct dyn_lease lease;
29 struct in_addr addr; 29 struct in_addr addr;
30 30
31 enum { 31 enum {
@@ -61,7 +61,7 @@ int dumpleases_main(int argc UNUSED_PARAM, char **argv)
61 while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) { 61 while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) {
62 const char *fmt = ":%02x" + 1; 62 const char *fmt = ":%02x" + 1;
63 for (i = 0; i < 6; i++) { 63 for (i = 0; i < 6; i++) {
64 printf(fmt, lease.lease_mac16[i]); 64 printf(fmt, lease.lease_mac[i]);
65 fmt = ":%02x"; 65 fmt = ":%02x";
66 } 66 }
67 addr.s_addr = lease.lease_nip; 67 addr.s_addr = lease.lease_nip;
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c
index 9d5633b75..bddf3e141 100644
--- a/networking/udhcp/files.c
+++ b/networking/udhcp/files.c
@@ -390,7 +390,7 @@ void FAST_FUNC write_leases(void)
390 390
391void FAST_FUNC read_leases(const char *file) 391void FAST_FUNC read_leases(const char *file)
392{ 392{
393 struct dhcpOfferedAddr lease; 393 struct dyn_lease lease;
394 int64_t written_at, time_passed; 394 int64_t written_at, time_passed;
395 int fd; 395 int fd;
396#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1 396#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1
@@ -420,7 +420,7 @@ void FAST_FUNC read_leases(const char *file)
420 continue; 420 continue;
421 /* NB: add_lease takes "relative time", IOW, 421 /* NB: add_lease takes "relative time", IOW,
422 * lease duration, not lease deadline. */ 422 * lease duration, not lease deadline. */
423 if (!(add_lease(lease.lease_mac16, lease.lease_nip, expires, lease.hostname))) { 423 if (!(add_lease(lease.lease_mac, lease.lease_nip, expires, lease.hostname))) {
424 bb_error_msg("too many leases while loading %s", file); 424 bb_error_msg("too many leases while loading %s", file);
425 break; 425 break;
426 } 426 }
diff --git a/networking/udhcp/leases.c b/networking/udhcp/leases.c
index 06bc086ba..4039f4dfb 100644
--- a/networking/udhcp/leases.c
+++ b/networking/udhcp/leases.c
@@ -11,9 +11,9 @@
11 11
12 12
13/* Find the oldest expired lease, NULL if there are no expired leases */ 13/* Find the oldest expired lease, NULL if there are no expired leases */
14static struct dhcpOfferedAddr *oldest_expired_lease(void) 14static struct dyn_lease *oldest_expired_lease(void)
15{ 15{
16 struct dhcpOfferedAddr *oldest_lease = NULL; 16 struct dyn_lease *oldest_lease = NULL;
17 leasetime_t oldest_time = time(NULL); 17 leasetime_t oldest_time = time(NULL);
18 unsigned i; 18 unsigned i;
19 19
@@ -38,7 +38,7 @@ static void clear_lease(const uint8_t *chaddr, uint32_t yiaddr)
38 continue; 38 continue;
39 39
40 for (i = 0; i < server_config.max_leases; i++) { 40 for (i = 0; i < server_config.max_leases; i++) {
41 if ((j != 16 && memcmp(leases[i].lease_mac16, chaddr, 16) == 0) 41 if ((j != 16 && memcmp(leases[i].lease_mac, chaddr, 6) == 0)
42 || (yiaddr && leases[i].lease_nip == yiaddr) 42 || (yiaddr && leases[i].lease_nip == yiaddr)
43 ) { 43 ) {
44 memset(&leases[i], 0, sizeof(leases[i])); 44 memset(&leases[i], 0, sizeof(leases[i]));
@@ -48,11 +48,11 @@ static void clear_lease(const uint8_t *chaddr, uint32_t yiaddr)
48 48
49 49
50/* Add a lease into the table, clearing out any old ones */ 50/* Add a lease into the table, clearing out any old ones */
51struct dhcpOfferedAddr* FAST_FUNC add_lease( 51struct dyn_lease* FAST_FUNC add_lease(
52 const uint8_t *chaddr, uint32_t yiaddr, 52 const uint8_t *chaddr, uint32_t yiaddr,
53 leasetime_t leasetime, uint8_t *hostname) 53 leasetime_t leasetime, uint8_t *hostname)
54{ 54{
55 struct dhcpOfferedAddr *oldest; 55 struct dyn_lease *oldest;
56 uint8_t hostname_length; 56 uint8_t hostname_length;
57 57
58 /* clean out any old ones */ 58 /* clean out any old ones */
@@ -75,7 +75,7 @@ struct dhcpOfferedAddr* FAST_FUNC add_lease(
75 hostname++; 75 hostname++;
76 } 76 }
77 } 77 }
78 memcpy(oldest->lease_mac16, chaddr, 16); 78 memcpy(oldest->lease_mac, chaddr, 6);
79 oldest->lease_nip = yiaddr; 79 oldest->lease_nip = yiaddr;
80 oldest->expires = time(NULL) + leasetime; 80 oldest->expires = time(NULL) + leasetime;
81 } 81 }
@@ -85,19 +85,19 @@ struct dhcpOfferedAddr* FAST_FUNC add_lease(
85 85
86 86
87/* True if a lease has expired */ 87/* True if a lease has expired */
88int FAST_FUNC lease_expired(struct dhcpOfferedAddr *lease) 88int FAST_FUNC lease_expired(struct dyn_lease *lease)
89{ 89{
90 return (lease->expires < (leasetime_t) time(NULL)); 90 return (lease->expires < (leasetime_t) time(NULL));
91} 91}
92 92
93 93
94/* Find the first lease that matches chaddr, NULL if no match */ 94/* Find the first lease that matches chaddr, NULL if no match */
95struct dhcpOfferedAddr* FAST_FUNC find_lease_by_chaddr(const uint8_t *chaddr) 95struct dyn_lease* FAST_FUNC find_lease_by_chaddr(const uint8_t *chaddr)
96{ 96{
97 unsigned i; 97 unsigned i;
98 98
99 for (i = 0; i < server_config.max_leases; i++) 99 for (i = 0; i < server_config.max_leases; i++)
100 if (!memcmp(leases[i].lease_mac16, chaddr, 16)) 100 if (memcmp(leases[i].lease_mac, chaddr, 6) == 0)
101 return &(leases[i]); 101 return &(leases[i]);
102 102
103 return NULL; 103 return NULL;
@@ -105,7 +105,7 @@ struct dhcpOfferedAddr* FAST_FUNC find_lease_by_chaddr(const uint8_t *chaddr)
105 105
106 106
107/* Find the first lease that matches yiaddr, NULL is no match */ 107/* Find the first lease that matches yiaddr, NULL is no match */
108struct dhcpOfferedAddr* FAST_FUNC find_lease_by_yiaddr(uint32_t yiaddr) 108struct dyn_lease* FAST_FUNC find_lease_by_yiaddr(uint32_t yiaddr)
109{ 109{
110 unsigned i; 110 unsigned i;
111 111
@@ -146,12 +146,12 @@ static int nobody_responds_to_arp(uint32_t addr, const uint8_t *safe_mac)
146uint32_t FAST_FUNC find_free_or_expired_address(const uint8_t *chaddr) 146uint32_t FAST_FUNC find_free_or_expired_address(const uint8_t *chaddr)
147{ 147{
148 uint32_t addr; 148 uint32_t addr;
149 struct dhcpOfferedAddr *oldest_lease = NULL; 149 struct dyn_lease *oldest_lease = NULL;
150 150
151 addr = server_config.start_ip; /* addr is in host order here */ 151 addr = server_config.start_ip; /* addr is in host order here */
152 for (; addr <= server_config.end_ip; addr++) { 152 for (; addr <= server_config.end_ip; addr++) {
153 uint32_t net_addr; 153 uint32_t net_addr;
154 struct dhcpOfferedAddr *lease; 154 struct dyn_lease *lease;
155 155
156 /* ie, 192.168.55.0 */ 156 /* ie, 192.168.55.0 */
157 if ((addr & 0xff) == 0) 157 if ((addr & 0xff) == 0)
diff --git a/networking/udhcp/options.c b/networking/udhcp/options.c
index 7b80e6b28..b86b3135d 100644
--- a/networking/udhcp/options.c
+++ b/networking/udhcp/options.c
@@ -120,7 +120,7 @@ const uint8_t dhcp_option_lengths[] ALIGN1 = {
120 120
121 121
122/* get an option with bounds checking (warning, result is not aligned). */ 122/* get an option with bounds checking (warning, result is not aligned). */
123uint8_t* FAST_FUNC get_option(struct dhcpMessage *packet, int code) 123uint8_t* FAST_FUNC get_option(struct dhcp_packet *packet, int code)
124{ 124{
125 uint8_t *optionptr; 125 uint8_t *optionptr;
126 int len; 126 int len;
@@ -159,15 +159,21 @@ uint8_t* FAST_FUNC get_option(struct dhcpMessage *packet, int code)
159 rem = sizeof(packet->sname); 159 rem = sizeof(packet->sname);
160 continue; 160 continue;
161 } 161 }
162 return NULL; 162 break;
163 } 163 }
164 len = 2 + optionptr[OPT_LEN]; 164 len = 2 + optionptr[OPT_LEN];
165 rem -= len; 165 rem -= len;
166 if (rem < 0) 166 if (rem < 0)
167 continue; /* complain and return NULL */ 167 continue; /* complain and return NULL */
168 168
169 if (optionptr[OPT_CODE] == code) 169 if (optionptr[OPT_CODE] == code) {
170#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 2
171 char buf[256 * 2 + 2];
172 *bin2hex(buf, (void*) (optionptr + OPT_DATA), optionptr[OPT_LEN]) = '\0';
173 log2("Option 0x%02x found: %s", code, buf);
174#endif
170 return optionptr + OPT_DATA; 175 return optionptr + OPT_DATA;
176 }
171 177
172 if (optionptr[OPT_CODE] == DHCP_OPTION_OVERLOAD) { 178 if (optionptr[OPT_CODE] == DHCP_OPTION_OVERLOAD) {
173 overload |= optionptr[OPT_DATA]; 179 overload |= optionptr[OPT_DATA];
@@ -175,6 +181,9 @@ uint8_t* FAST_FUNC get_option(struct dhcpMessage *packet, int code)
175 } 181 }
176 optionptr += len; 182 optionptr += len;
177 } 183 }
184
185 /* log3 because udhcpc uses it a lot - very noisy */
186 log3("Option 0x%02x not found", code);
178 return NULL; 187 return NULL;
179} 188}
180 189
diff --git a/networking/udhcp/options.h b/networking/udhcp/options.h
index 23370da6e..8c80485be 100644
--- a/networking/udhcp/options.h
+++ b/networking/udhcp/options.h
@@ -100,7 +100,7 @@ extern const struct dhcp_option dhcp_options[];
100extern const char dhcp_option_strings[]; 100extern const char dhcp_option_strings[];
101extern const uint8_t dhcp_option_lengths[]; 101extern const uint8_t dhcp_option_lengths[];
102 102
103uint8_t *get_option(struct dhcpMessage *packet, int code) FAST_FUNC; 103uint8_t *get_option(struct dhcp_packet *packet, int code) FAST_FUNC;
104int end_option(uint8_t *optionptr) FAST_FUNC; 104int end_option(uint8_t *optionptr) FAST_FUNC;
105int add_option_string(uint8_t *optionptr, uint8_t *string) FAST_FUNC; 105int add_option_string(uint8_t *optionptr, uint8_t *string) FAST_FUNC;
106int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data) FAST_FUNC; 106int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data) FAST_FUNC;
diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c
index 2cd5f6176..911bd3b37 100644
--- a/networking/udhcp/packet.c
+++ b/networking/udhcp/packet.c
@@ -19,9 +19,9 @@
19#include "dhcpd.h" 19#include "dhcpd.h"
20#include "options.h" 20#include "options.h"
21 21
22void FAST_FUNC udhcp_init_header(struct dhcpMessage *packet, char type) 22void FAST_FUNC udhcp_init_header(struct dhcp_packet *packet, char type)
23{ 23{
24 memset(packet, 0, sizeof(struct dhcpMessage)); 24 memset(packet, 0, sizeof(struct dhcp_packet));
25 packet->op = BOOTREQUEST; /* if client to a server */ 25 packet->op = BOOTREQUEST; /* if client to a server */
26 switch (type) { 26 switch (type) {
27 case DHCPOFFER: 27 case DHCPOFFER:
@@ -37,7 +37,7 @@ void FAST_FUNC udhcp_init_header(struct dhcpMessage *packet, char type)
37} 37}
38 38
39#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1 39#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1
40void FAST_FUNC udhcp_dump_packet(struct dhcpMessage *packet) 40void FAST_FUNC udhcp_dump_packet(struct dhcp_packet *packet)
41{ 41{
42 char buf[sizeof(packet->chaddr)*2 + 1]; 42 char buf[sizeof(packet->chaddr)*2 + 1];
43 43
@@ -84,7 +84,7 @@ void FAST_FUNC udhcp_dump_packet(struct dhcpMessage *packet)
84#endif 84#endif
85 85
86/* Read a packet from socket fd, return -1 on read error, -2 on packet error */ 86/* Read a packet from socket fd, return -1 on read error, -2 on packet error */
87int FAST_FUNC udhcp_recv_kernel_packet(struct dhcpMessage *packet, int fd) 87int FAST_FUNC udhcp_recv_kernel_packet(struct dhcp_packet *packet, int fd)
88{ 88{
89 int bytes; 89 int bytes;
90 unsigned char *vendor; 90 unsigned char *vendor;
@@ -165,20 +165,20 @@ uint16_t FAST_FUNC udhcp_checksum(void *addr, int count)
165} 165}
166 166
167/* Construct a ip/udp header for a packet, send packet */ 167/* Construct a ip/udp header for a packet, send packet */
168int FAST_FUNC udhcp_send_raw_packet(struct dhcpMessage *dhcp_pkt, 168int FAST_FUNC udhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt,
169 uint32_t source_ip, int source_port, 169 uint32_t source_ip, int source_port,
170 uint32_t dest_ip, int dest_port, const uint8_t *dest_arp, 170 uint32_t dest_ip, int dest_port, const uint8_t *dest_arp,
171 int ifindex) 171 int ifindex)
172{ 172{
173 struct sockaddr_ll dest; 173 struct sockaddr_ll dest;
174 struct udp_dhcp_packet packet; 174 struct ip_udp_dhcp_packet packet;
175 int fd; 175 int fd;
176 int result = -1; 176 int result = -1;
177 const char *msg; 177 const char *msg;
178 178
179 enum { 179 enum {
180 IP_UPD_DHCP_SIZE = sizeof(struct udp_dhcp_packet) - CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS, 180 IP_UPD_DHCP_SIZE = sizeof(struct ip_udp_dhcp_packet) - CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS,
181 UPD_DHCP_SIZE = IP_UPD_DHCP_SIZE - offsetof(struct udp_dhcp_packet, udp), 181 UPD_DHCP_SIZE = IP_UPD_DHCP_SIZE - offsetof(struct ip_udp_dhcp_packet, udp),
182 }; 182 };
183 183
184 fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP)); 184 fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP));
@@ -236,7 +236,7 @@ int FAST_FUNC udhcp_send_raw_packet(struct dhcpMessage *dhcp_pkt,
236} 236}
237 237
238/* Let the kernel do all the work for packet generation */ 238/* Let the kernel do all the work for packet generation */
239int FAST_FUNC udhcp_send_kernel_packet(struct dhcpMessage *dhcp_pkt, 239int FAST_FUNC udhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt,
240 uint32_t source_ip, int source_port, 240 uint32_t source_ip, int source_port,
241 uint32_t dest_ip, int dest_port) 241 uint32_t dest_ip, int dest_port)
242{ 242{
@@ -246,7 +246,7 @@ int FAST_FUNC udhcp_send_kernel_packet(struct dhcpMessage *dhcp_pkt,
246 const char *msg; 246 const char *msg;
247 247
248 enum { 248 enum {
249 DHCP_SIZE = sizeof(struct dhcpMessage) - CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS, 249 DHCP_SIZE = sizeof(struct dhcp_packet) - CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS,
250 }; 250 };
251 251
252 fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); 252 fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c
index 22780d86a..794e3ca8d 100644
--- a/networking/udhcp/script.c
+++ b/networking/udhcp/script.c
@@ -129,7 +129,7 @@ static char *alloc_fill_opts(uint8_t *option, const struct dhcp_option *type_p,
129 129
130 130
131/* put all the parameters into an environment */ 131/* put all the parameters into an environment */
132static char **fill_envp(struct dhcpMessage *packet) 132static char **fill_envp(struct dhcp_packet *packet)
133{ 133{
134 int num_options = 0; 134 int num_options = 0;
135 int i; 135 int i;
@@ -210,7 +210,7 @@ static char **fill_envp(struct dhcpMessage *packet)
210 210
211 211
212/* Call a script with a par file and env vars */ 212/* Call a script with a par file and env vars */
213void FAST_FUNC udhcp_run_script(struct dhcpMessage *packet, const char *name) 213void FAST_FUNC udhcp_run_script(struct dhcp_packet *packet, const char *name)
214{ 214{
215 char **envp, **curr; 215 char **envp, **curr;
216 char *argv[3]; 216 char *argv[3];
diff --git a/networking/udhcp/serverpacket.c b/networking/udhcp/serverpacket.c
index 831165d8e..209d3c8f3 100644
--- a/networking/udhcp/serverpacket.c
+++ b/networking/udhcp/serverpacket.c
@@ -27,7 +27,7 @@
27 27
28 28
29/* send a packet to gateway_nip using the kernel ip stack */ 29/* send a packet to gateway_nip using the kernel ip stack */
30static int send_packet_to_relay(struct dhcpMessage *dhcp_pkt) 30static int send_packet_to_relay(struct dhcp_packet *dhcp_pkt)
31{ 31{
32 log1("Forwarding packet to relay"); 32 log1("Forwarding packet to relay");
33 33
@@ -38,7 +38,7 @@ static int send_packet_to_relay(struct dhcpMessage *dhcp_pkt)
38 38
39 39
40/* send a packet to a specific mac address and ip address by creating our own ip packet */ 40/* send a packet to a specific mac address and ip address by creating our own ip packet */
41static int send_packet_to_client(struct dhcpMessage *dhcp_pkt, int force_broadcast) 41static int send_packet_to_client(struct dhcp_packet *dhcp_pkt, int force_broadcast)
42{ 42{
43 const uint8_t *chaddr; 43 const uint8_t *chaddr;
44 uint32_t ciaddr; 44 uint32_t ciaddr;
@@ -76,7 +76,7 @@ static int send_packet_to_client(struct dhcpMessage *dhcp_pkt, int force_broadca
76 76
77 77
78/* send a dhcp packet, if force broadcast is set, the packet will be broadcast to the client */ 78/* send a dhcp packet, if force broadcast is set, the packet will be broadcast to the client */
79static int send_packet(struct dhcpMessage *dhcp_pkt, int force_broadcast) 79static int send_packet(struct dhcp_packet *dhcp_pkt, int force_broadcast)
80{ 80{
81 if (dhcp_pkt->gateway_nip) 81 if (dhcp_pkt->gateway_nip)
82 return send_packet_to_relay(dhcp_pkt); 82 return send_packet_to_relay(dhcp_pkt);
@@ -84,11 +84,11 @@ static int send_packet(struct dhcpMessage *dhcp_pkt, int force_broadcast)
84} 84}
85 85
86 86
87static void init_packet(struct dhcpMessage *packet, struct dhcpMessage *oldpacket, char type) 87static void init_packet(struct dhcp_packet *packet, struct dhcp_packet *oldpacket, char type)
88{ 88{
89 udhcp_init_header(packet, type); 89 udhcp_init_header(packet, type);
90 packet->xid = oldpacket->xid; 90 packet->xid = oldpacket->xid;
91 memcpy(packet->chaddr, oldpacket->chaddr, 16); 91 memcpy(packet->chaddr, oldpacket->chaddr, sizeof(oldpacket->chaddr));
92 packet->flags = oldpacket->flags; 92 packet->flags = oldpacket->flags;
93 packet->gateway_nip = oldpacket->gateway_nip; 93 packet->gateway_nip = oldpacket->gateway_nip;
94 packet->ciaddr = oldpacket->ciaddr; 94 packet->ciaddr = oldpacket->ciaddr;
@@ -97,7 +97,7 @@ static void init_packet(struct dhcpMessage *packet, struct dhcpMessage *oldpacke
97 97
98 98
99/* add in the bootp options */ 99/* add in the bootp options */
100static void add_bootp_options(struct dhcpMessage *packet) 100static void add_bootp_options(struct dhcp_packet *packet)
101{ 101{
102 packet->siaddr_nip = server_config.siaddr_nip; 102 packet->siaddr_nip = server_config.siaddr_nip;
103 if (server_config.sname) 103 if (server_config.sname)
@@ -108,9 +108,9 @@ static void add_bootp_options(struct dhcpMessage *packet)
108 108
109 109
110/* send a DHCP OFFER to a DHCP DISCOVER */ 110/* send a DHCP OFFER to a DHCP DISCOVER */
111int FAST_FUNC send_offer(struct dhcpMessage *oldpacket) 111int FAST_FUNC send_offer(struct dhcp_packet *oldpacket)
112{ 112{
113 struct dhcpMessage packet; 113 struct dhcp_packet packet;
114 uint32_t req_align; 114 uint32_t req_align;
115 uint32_t lease_time_aligned = server_config.lease; 115 uint32_t lease_time_aligned = server_config.lease;
116 uint32_t static_lease_ip; 116 uint32_t static_lease_ip;
@@ -124,7 +124,7 @@ int FAST_FUNC send_offer(struct dhcpMessage *oldpacket)
124 124
125 /* ADDME: if static, short circuit */ 125 /* ADDME: if static, short circuit */
126 if (!static_lease_ip) { 126 if (!static_lease_ip) {
127 struct dhcpOfferedAddr *lease; 127 struct dyn_lease *lease;
128 128
129 lease = find_lease_by_chaddr(oldpacket->chaddr); 129 lease = find_lease_by_chaddr(oldpacket->chaddr);
130 /* The client is in our lease/offered table */ 130 /* The client is in our lease/offered table */
@@ -195,9 +195,9 @@ int FAST_FUNC send_offer(struct dhcpMessage *oldpacket)
195} 195}
196 196
197 197
198int FAST_FUNC send_NAK(struct dhcpMessage *oldpacket) 198int FAST_FUNC send_NAK(struct dhcp_packet *oldpacket)
199{ 199{
200 struct dhcpMessage packet; 200 struct dhcp_packet packet;
201 201
202 init_packet(&packet, oldpacket, DHCPNAK); 202 init_packet(&packet, oldpacket, DHCPNAK);
203 203
@@ -206,9 +206,9 @@ int FAST_FUNC send_NAK(struct dhcpMessage *oldpacket)
206} 206}
207 207
208 208
209int FAST_FUNC send_ACK(struct dhcpMessage *oldpacket, uint32_t yiaddr) 209int FAST_FUNC send_ACK(struct dhcp_packet *oldpacket, uint32_t yiaddr)
210{ 210{
211 struct dhcpMessage packet; 211 struct dhcp_packet packet;
212 struct option_set *curr; 212 struct option_set *curr;
213 uint8_t *lease_time; 213 uint8_t *lease_time;
214 uint32_t lease_time_aligned = server_config.lease; 214 uint32_t lease_time_aligned = server_config.lease;
@@ -256,9 +256,9 @@ int FAST_FUNC send_ACK(struct dhcpMessage *oldpacket, uint32_t yiaddr)
256} 256}
257 257
258 258
259int FAST_FUNC send_inform(struct dhcpMessage *oldpacket) 259int FAST_FUNC send_inform(struct dhcp_packet *oldpacket)
260{ 260{
261 struct dhcpMessage packet; 261 struct dhcp_packet packet;
262 struct option_set *curr; 262 struct option_set *curr;
263 263
264 init_packet(&packet, oldpacket, DHCPACK); 264 init_packet(&packet, oldpacket, DHCPACK);