diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-18 19:51:32 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-18 19:51:32 +0000 |
commit | 5a3395bc01cd4b11309595a6ecdaf32f8279f378 (patch) | |
tree | 1e63aa591a05e9ec75aefdcd639ca4188e583648 /networking/udhcp/serverpacket.c | |
parent | abfc4cf6d8b9c59724aceb70df5081a1368fdb62 (diff) | |
download | busybox-w32-5a3395bc01cd4b11309595a6ecdaf32f8279f378.tar.gz busybox-w32-5a3395bc01cd4b11309595a6ecdaf32f8279f378.tar.bz2 busybox-w32-5a3395bc01cd4b11309595a6ecdaf32f8279f378.zip |
udhcp: fix indentation and style.
Eliminate (group) a lot of smallish *.h files
Remove lots of unneeded #includes
Diffstat (limited to 'networking/udhcp/serverpacket.c')
-rw-r--r-- | networking/udhcp/serverpacket.c | 111 |
1 files changed, 48 insertions, 63 deletions
diff --git a/networking/udhcp/serverpacket.c b/networking/udhcp/serverpacket.c index b5cfcf405..8889fda86 100644 --- a/networking/udhcp/serverpacket.c +++ b/networking/udhcp/serverpacket.c | |||
@@ -20,17 +20,10 @@ | |||
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <sys/socket.h> | ||
24 | #include <netinet/in.h> | ||
25 | #include <arpa/inet.h> | ||
26 | #include <string.h> | ||
27 | #include <time.h> | ||
28 | |||
29 | #include "common.h" | 23 | #include "common.h" |
30 | #include "serverpacket.h" | ||
31 | #include "dhcpd.h" | 24 | #include "dhcpd.h" |
32 | #include "options.h" | 25 | #include "options.h" |
33 | #include "static_leases.h" | 26 | |
34 | 27 | ||
35 | /* send a packet to giaddr using the kernel ip stack */ | 28 | /* send a packet to giaddr using the kernel ip stack */ |
36 | static int send_packet_to_relay(struct dhcpMessage *payload) | 29 | static int send_packet_to_relay(struct dhcpMessage *payload) |
@@ -122,65 +115,57 @@ int sendOffer(struct dhcpMessage *oldpacket) | |||
122 | static_lease_ip = getIpByMac(server_config.static_leases, oldpacket->chaddr); | 115 | static_lease_ip = getIpByMac(server_config.static_leases, oldpacket->chaddr); |
123 | 116 | ||
124 | /* ADDME: if static, short circuit */ | 117 | /* ADDME: if static, short circuit */ |
125 | if(!static_lease_ip) | 118 | if (!static_lease_ip) { |
126 | { | 119 | /* the client is in our lease/offered table */ |
127 | /* the client is in our lease/offered table */ | 120 | lease = find_lease_by_chaddr(oldpacket->chaddr); |
128 | if ((lease = find_lease_by_chaddr(oldpacket->chaddr))) { | 121 | if (lease) { |
129 | if (!lease_expired(lease)) | 122 | if (!lease_expired(lease)) |
130 | lease_time_align = lease->expires - time(0); | 123 | lease_time_align = lease->expires - time(0); |
131 | packet.yiaddr = lease->yiaddr; | 124 | packet.yiaddr = lease->yiaddr; |
132 | 125 | ||
133 | /* Or the client has a requested ip */ | 126 | /* Or the client has a requested ip */ |
134 | } else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP)) && | 127 | } else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP)) |
135 | 128 | /* Don't look here (ugly hackish thing to do) */ | |
136 | /* Don't look here (ugly hackish thing to do) */ | 129 | && memcpy(&req_align, req, 4) |
137 | memcpy(&req_align, req, 4) && | 130 | /* and the ip is in the lease range */ |
138 | 131 | && ntohl(req_align) >= ntohl(server_config.start) | |
139 | /* and the ip is in the lease range */ | 132 | && ntohl(req_align) <= ntohl(server_config.end) |
140 | ntohl(req_align) >= ntohl(server_config.start) && | 133 | && !static_lease_ip /* Check that its not a static lease */ |
141 | ntohl(req_align) <= ntohl(server_config.end) && | ||
142 | |||
143 | !static_lease_ip && /* Check that its not a static lease */ | ||
144 | /* and is not already taken/offered */ | 134 | /* and is not already taken/offered */ |
145 | ((!(lease = find_lease_by_yiaddr(req_align)) || | 135 | && (!(lease = find_lease_by_yiaddr(req_align)) |
146 | 136 | /* or its taken, but expired */ /* ADDME: or maybe in here */ | |
147 | /* or its taken, but expired */ /* ADDME: or maybe in here */ | 137 | || lease_expired(lease)) |
148 | lease_expired(lease)))) { | 138 | ) { |
149 | packet.yiaddr = req_align; /* FIXME: oh my, is there a host using this IP? */ | 139 | packet.yiaddr = req_align; /* FIXME: oh my, is there a host using this IP? */ |
150 | |||
151 | /* otherwise, find a free IP */ | 140 | /* otherwise, find a free IP */ |
152 | } else { | 141 | } else { |
153 | /* Is it a static lease? (No, because find_address skips static lease) */ | 142 | /* Is it a static lease? (No, because find_address skips static lease) */ |
154 | packet.yiaddr = find_address(0); | 143 | packet.yiaddr = find_address(0); |
155 | 144 | /* try for an expired lease */ | |
156 | /* try for an expired lease */ | 145 | if (!packet.yiaddr) packet.yiaddr = find_address(1); |
157 | if (!packet.yiaddr) packet.yiaddr = find_address(1); | 146 | } |
158 | } | 147 | |
159 | 148 | if (!packet.yiaddr) { | |
160 | if(!packet.yiaddr) { | 149 | bb_error_msg("no IP addresses to give - OFFER abandoned"); |
161 | bb_error_msg("no IP addresses to give - OFFER abandoned"); | 150 | return -1; |
162 | return -1; | 151 | } |
163 | } | 152 | if (!add_lease(packet.chaddr, packet.yiaddr, server_config.offer_time)) { |
164 | 153 | bb_error_msg("lease pool is full - OFFER abandoned"); | |
165 | if (!add_lease(packet.chaddr, packet.yiaddr, server_config.offer_time)) { | 154 | return -1; |
166 | bb_error_msg("lease pool is full - OFFER abandoned"); | 155 | } |
167 | return -1; | 156 | lease_time = get_option(oldpacket, DHCP_LEASE_TIME); |
168 | } | 157 | if (lease_time) { |
169 | 158 | memcpy(&lease_time_align, lease_time, 4); | |
170 | if ((lease_time = get_option(oldpacket, DHCP_LEASE_TIME))) { | 159 | lease_time_align = ntohl(lease_time_align); |
171 | memcpy(&lease_time_align, lease_time, 4); | 160 | if (lease_time_align > server_config.lease) |
172 | lease_time_align = ntohl(lease_time_align); | 161 | lease_time_align = server_config.lease; |
173 | if (lease_time_align > server_config.lease) | 162 | } |
163 | |||
164 | /* Make sure we aren't just using the lease time from the previous offer */ | ||
165 | if (lease_time_align < server_config.min_lease) | ||
174 | lease_time_align = server_config.lease; | 166 | lease_time_align = server_config.lease; |
175 | } | 167 | /* ADDME: end of short circuit */ |
176 | 168 | } else { | |
177 | /* Make sure we aren't just using the lease time from the previous offer */ | ||
178 | if (lease_time_align < server_config.min_lease) | ||
179 | lease_time_align = server_config.lease; | ||
180 | } | ||
181 | /* ADDME: end of short circuit */ | ||
182 | else | ||
183 | { | ||
184 | /* It is a static lease... use it */ | 169 | /* It is a static lease... use it */ |
185 | packet.yiaddr = static_lease_ip; | 170 | packet.yiaddr = static_lease_ip; |
186 | } | 171 | } |