aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/serverpacket.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-01-01 17:52:09 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-01-01 17:52:09 +0000
commit0416e3dde17ea9295635c52183b30fe3d7172333 (patch)
tree4eea1c401c74d6ec42f18c67090f73001103e0db /networking/udhcp/serverpacket.c
parentb2ec03813c34bc3de2ddf9a0974be4e5b31ec757 (diff)
downloadbusybox-w32-0416e3dde17ea9295635c52183b30fe3d7172333.tar.gz
busybox-w32-0416e3dde17ea9295635c52183b30fe3d7172333.tar.bz2
busybox-w32-0416e3dde17ea9295635c52183b30fe3d7172333.zip
udhcpd: disable opton to have absolute lease times in lease file
(that does not work with dumpleases) dumpleases: fix -a option. networking/udhcp/*: code shrink, more compact static leases struture, better comments, etc function old new delta find_free_or_expired_address - 147 +147 nobody_responds_to_arp - 84 +84 read_opt 781 830 +49 dumpleases_main 435 447 +12 send_ACK 229 232 +3 read_staticlease 90 93 +3 addStaticLease 60 61 +1 getIpByMac 46 43 -3 reservedIp 31 20 -11 keywords 304 288 -16 send_offer 428 403 -25 write_leases 225 193 -32 read_leases 184 143 -41 read_yn 64 - -64 find_address 191 - -191 ------------------------------------------------------------------------------ (add/remove: 2/2 grow/shrink: 5/6 up/down: 299/-383) Total: -84 bytes
Diffstat (limited to 'networking/udhcp/serverpacket.c')
-rw-r--r--networking/udhcp/serverpacket.c37
1 files changed, 16 insertions, 21 deletions
diff --git a/networking/udhcp/serverpacket.c b/networking/udhcp/serverpacket.c
index fca685dd1..afc0fb40d 100644
--- a/networking/udhcp/serverpacket.c
+++ b/networking/udhcp/serverpacket.c
@@ -102,48 +102,44 @@ static void add_bootp_options(struct dhcpMessage *packet)
102int FAST_FUNC send_offer(struct dhcpMessage *oldpacket) 102int FAST_FUNC send_offer(struct dhcpMessage *oldpacket)
103{ 103{
104 struct dhcpMessage packet; 104 struct dhcpMessage packet;
105 struct dhcpOfferedAddr *lease = NULL;
106 uint32_t req_align; 105 uint32_t req_align;
107 uint32_t lease_time_aligned = server_config.lease; 106 uint32_t lease_time_aligned = server_config.lease;
107 uint32_t static_lease_ip;
108 uint8_t *req, *lease_time; 108 uint8_t *req, *lease_time;
109 struct option_set *curr; 109 struct option_set *curr;
110 struct in_addr addr; 110 struct in_addr addr;
111 111
112 uint32_t static_lease_ip;
113
114 init_packet(&packet, oldpacket, DHCPOFFER); 112 init_packet(&packet, oldpacket, DHCPOFFER);
115 113
116 static_lease_ip = getIpByMac(server_config.static_leases, oldpacket->chaddr); 114 static_lease_ip = getIpByMac(server_config.static_leases, oldpacket->chaddr);
117 115
118 /* ADDME: if static, short circuit */ 116 /* ADDME: if static, short circuit */
119 if (!static_lease_ip) { 117 if (!static_lease_ip) {
120 /* the client is in our lease/offered table */ 118 struct dhcpOfferedAddr *lease;
119
121 lease = find_lease_by_chaddr(oldpacket->chaddr); 120 lease = find_lease_by_chaddr(oldpacket->chaddr);
121 /* the client is in our lease/offered table */
122 if (lease) { 122 if (lease) {
123 if (!lease_expired(lease)) 123 signed_leasetime_t tmp = lease->expires - time(NULL);
124 lease_time_aligned = lease->expires - time(0); 124 if (tmp >= 0)
125 lease_time_aligned = tmp;
125 packet.yiaddr = lease->yiaddr; 126 packet.yiaddr = lease->yiaddr;
126 /* Or the client has a requested ip */ 127 /* Or the client has requested an ip */
127 } else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP)) 128 } else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP)) != NULL
128 /* Don't look here (ugly hackish thing to do) */ 129 /* Don't look here (ugly hackish thing to do) */
129 && memcpy(&req_align, req, 4) 130 && (move_from_unaligned32(req_align, req), 1)
130 /* and the ip is in the lease range */ 131 /* and the ip is in the lease range */
131 && ntohl(req_align) >= server_config.start_ip 132 && ntohl(req_align) >= server_config.start_ip
132 && ntohl(req_align) <= server_config.end_ip 133 && ntohl(req_align) <= server_config.end_ip
133 && !static_lease_ip /* Check that its not a static lease */
134 /* and is not already taken/offered */ 134 /* and is not already taken/offered */
135 && (!(lease = find_lease_by_yiaddr(req_align)) 135 && (!(lease = find_lease_by_yiaddr(req_align))
136 /* or its taken, but expired */ /* ADDME: or maybe in here */ 136 /* or its taken, but expired */
137 || lease_expired(lease)) 137 || lease_expired(lease))
138 ) { 138 ) {
139 packet.yiaddr = req_align; /* FIXME: oh my, is there a host using this IP? */ 139 packet.yiaddr = req_align;
140 /* otherwise, find a free IP */ 140 /* otherwise, find a free IP */
141 } else { 141 } else {
142 /* Is it a static lease? (No, because find_address skips static lease) */ 142 packet.yiaddr = find_free_or_expired_address();
143 packet.yiaddr = find_address(0);
144 /* try for an expired lease */
145 if (!packet.yiaddr)
146 packet.yiaddr = find_address(1);
147 } 143 }
148 144
149 if (!packet.yiaddr) { 145 if (!packet.yiaddr) {
@@ -164,8 +160,7 @@ int FAST_FUNC send_offer(struct dhcpMessage *oldpacket)
164 160
165 /* Make sure we aren't just using the lease time from the previous offer */ 161 /* Make sure we aren't just using the lease time from the previous offer */
166 if (lease_time_aligned < server_config.min_lease) 162 if (lease_time_aligned < server_config.min_lease)
167 lease_time_aligned = server_config.lease; 163 lease_time_aligned = server_config.min_lease;
168 /* ADDME: end of short circuit */
169 } else { 164 } else {
170 /* It is a static lease... use it */ 165 /* It is a static lease... use it */
171 packet.yiaddr = static_lease_ip; 166 packet.yiaddr = static_lease_ip;
@@ -217,7 +212,7 @@ int FAST_FUNC send_ACK(struct dhcpMessage *oldpacket, uint32_t yiaddr)
217 if (lease_time_aligned > server_config.lease) 212 if (lease_time_aligned > server_config.lease)
218 lease_time_aligned = server_config.lease; 213 lease_time_aligned = server_config.lease;
219 else if (lease_time_aligned < server_config.min_lease) 214 else if (lease_time_aligned < server_config.min_lease)
220 lease_time_aligned = server_config.lease; 215 lease_time_aligned = server_config.min_lease;
221 } 216 }
222 217
223 add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_aligned)); 218 add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_aligned));