aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-03-20 03:49:27 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-03-20 03:49:27 +0100
commita953987e778e1a89d9371df99b243e7b57b22a07 (patch)
tree011bae27383dcc3ccf07106e754d40e6db742bbc
parent8a7c166ab9ad35eef8c90d6b0b3a25b8a9fbacd2 (diff)
downloadbusybox-w32-a953987e778e1a89d9371df99b243e7b57b22a07.tar.gz
busybox-w32-a953987e778e1a89d9371df99b243e7b57b22a07.tar.bz2
busybox-w32-a953987e778e1a89d9371df99b243e7b57b22a07.zip
udhcpd: remove redundant code in send_offer()
static_lease_nip and lease pointer are canculated in the caller, no need to calculate them again. lease_time_sec calculation is also redundant: it is assigned to later, w/o being used in between. function old new delta udhcpd_main 1956 1925 -31 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/udhcp/dhcpd.c27
1 files changed, 9 insertions, 18 deletions
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index 26fb3045f..d7887d914 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -120,12 +120,11 @@ static uint32_t select_lease_time(struct dhcp_packet *packet)
120} 120}
121 121
122/* send a DHCP OFFER to a DHCP DISCOVER */ 122/* send a DHCP OFFER to a DHCP DISCOVER */
123static int send_offer(struct dhcp_packet *oldpacket) 123static int send_offer(struct dhcp_packet *oldpacket, uint32_t static_lease_nip, struct dyn_lease *lease)
124{ 124{
125 struct dhcp_packet packet; 125 struct dhcp_packet packet;
126 uint32_t req_nip; 126 uint32_t req_nip;
127 uint32_t lease_time_sec = server_config.max_lease_sec; 127 uint32_t lease_time_sec = server_config.max_lease_sec;
128 uint32_t static_lease_ip;
129 uint8_t *req_ip_opt; 128 uint8_t *req_ip_opt;
130 const char *p_host_name; 129 const char *p_host_name;
131 struct option_set *curr; 130 struct option_set *curr;
@@ -133,18 +132,10 @@ static int send_offer(struct dhcp_packet *oldpacket)
133 132
134 init_packet(&packet, oldpacket, DHCPOFFER); 133 init_packet(&packet, oldpacket, DHCPOFFER);
135 134
136 static_lease_ip = get_static_nip_by_mac(server_config.static_leases, oldpacket->chaddr);
137
138 /* ADDME: if static, short circuit */ 135 /* ADDME: if static, short circuit */
139 if (!static_lease_ip) { 136 if (!static_lease_nip) {
140 struct dyn_lease *lease;
141
142 lease = find_lease_by_mac(oldpacket->chaddr);
143 /* The client is in our lease/offered table */ 137 /* The client is in our lease/offered table */
144 if (lease) { 138 if (lease) {
145 signed_leasetime_t tmp = lease->expires - time(NULL);
146 if (tmp >= 0)
147 lease_time_sec = tmp;
148 packet.yiaddr = lease->lease_nip; 139 packet.yiaddr = lease->lease_nip;
149 } 140 }
150 /* Or the client has requested an IP */ 141 /* Or the client has requested an IP */
@@ -183,7 +174,7 @@ static int send_offer(struct dhcp_packet *oldpacket)
183 lease_time_sec = select_lease_time(oldpacket); 174 lease_time_sec = select_lease_time(oldpacket);
184 } else { 175 } else {
185 /* It is a static lease... use it */ 176 /* It is a static lease... use it */
186 packet.yiaddr = static_lease_ip; 177 packet.yiaddr = static_lease_nip;
187 } 178 }
188 179
189 add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_sec)); 180 add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_sec));
@@ -288,7 +279,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
288 int server_socket = -1, retval, max_sock; 279 int server_socket = -1, retval, max_sock;
289 struct dhcp_packet packet; 280 struct dhcp_packet packet;
290 uint8_t *state; 281 uint8_t *state;
291 uint32_t static_lease_ip; 282 uint32_t static_lease_nip;
292 unsigned timeout_end; 283 unsigned timeout_end;
293 unsigned num_ips; 284 unsigned num_ips;
294 unsigned opt; 285 unsigned opt;
@@ -439,12 +430,12 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
439 } 430 }
440 431
441 /* Look for a static lease */ 432 /* Look for a static lease */
442 static_lease_ip = get_static_nip_by_mac(server_config.static_leases, &packet.chaddr); 433 static_lease_nip = get_static_nip_by_mac(server_config.static_leases, &packet.chaddr);
443 if (static_lease_ip) { 434 if (static_lease_nip) {
444 bb_info_msg("Found static lease: %x", static_lease_ip); 435 bb_info_msg("Found static lease: %x", static_lease_nip);
445 436
446 memcpy(&fake_lease.lease_mac, &packet.chaddr, 6); 437 memcpy(&fake_lease.lease_mac, &packet.chaddr, 6);
447 fake_lease.lease_nip = static_lease_ip; 438 fake_lease.lease_nip = static_lease_nip;
448 fake_lease.expires = 0; 439 fake_lease.expires = 0;
449 440
450 lease = &fake_lease; 441 lease = &fake_lease;
@@ -456,7 +447,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
456 case DHCPDISCOVER: 447 case DHCPDISCOVER:
457 log1("Received DISCOVER"); 448 log1("Received DISCOVER");
458 449
459 if (send_offer(&packet) < 0) { 450 if (send_offer(&packet, static_lease_nip, lease) < 0) {
460 bb_error_msg("send OFFER failed"); 451 bb_error_msg("send OFFER failed");
461 } 452 }
462 break; 453 break;