source: MondoRescue/branches/stable/mindi-busybox/networking/udhcp/serverpacket.c

Last change on this file was 1770, checked in by Bruno Cornec, 16 years ago
  • Better output for mindi-busybox revision
  • Remove dummy file created on NFS - report from Arnaud Tiger <arnaud.tiger_at_hp.com>
  • strace useful for debug
  • fix new versions for pb (2.0.0 for mindi and 1.7.2 for mindi-busybox)
  • fix build process for mindi-busybox + options used in that version (dd for label-partitions-as-necessary)
  • fix typo in label-partitions-as-necessary which doesn't seem to work
  • Update to busybox 1.7.2
  • perl is now required at restore time to support uuid swap partitions (and will be used for many other thigs

in the future for sure)

  • next mindi version will be 2.0.0 due to all the changes made in it (udev may break working distros)
  • small optimization in mindi on keyboard handling (one single find instead of multiple)
  • better interaction for USB device when launching mindi manually
  • attempt to automatically guess block disk size for ramdisk
  • fix typos in bkphw
  • Fix the remaining problem with UUID support for swap partitions
  • Updates mondoarchive man page for USB support
  • Adds preliminary Hardware support to mindi (Proliant SSSTK)
  • Tries to add udev support also for rhel4
  • Fix UUID support which was still broken.
  • Be conservative in test for the start-nfs script
  • Update config file for mindi-busybox for 1.7.2 migration
  • Try to run around a busybox bug (1.2.2 pb on inexistant links)
  • Add build content for mindi-busybox in pb
  • Remove distributions content for mindi-busybox
  • Fix a warning on inexistant raidtab
  • Solve problem on tmpfs in restore init (Problem of inexistant symlink and busybox)
  • Create MONDO_CACHE and use it everywhere + creation at start
  • Really never try to eject a USB device
  • Fix a issue with &> usage (replaced with 1> and 2>)
  • Adds magic file to depllist in order to have file working + ldd which helps for debugging issues
  • tty modes correct to avoid sh error messages
  • Use ext3 normally and not ext2 instead
  • USB device should be corrected after reading (take 1st part)
  • Adds a mount_USB_here function derived from mount_CDROM_here
  • usb detection place before /dev detection in device name at restore time
  • Fix when restoring from USB: media is asked in interactive mode
  • Adds USB support for mondorestore
  • mount_cdrom => mount_media
  • elilo.efi is now searched throughout /boot/efi and not in a fixed place as there is no standard
  • untar-and-softlink => untar (+ interface change)
  • suppress useless softlinks creation/removal in boot process
  • avoids udevd messages on groups
  • Increase # of disks to 99 as in mindi at restore time (should be a conf file parameter)
  • skip existing big file creation
  • seems to work correctly for USB mindi boot
  • Adds group and tty link to udev conf
  • Always load usb-torage (even 2.6) to initiate USB bus discovery
  • Better printing of messages
  • Attempt to fix a bug in supporting OpenSusE 10.3 kernel for initramfs (mindi may now use multiple regex for kernel initrd detection)
  • Links were not correctly done as non relative for modules in mindi
  • exclusion of modules denied now works
  • Also create modules in their ordinary place, so that classical modprobe works + copy modules.dep
  • Fix bugs for DENY_MODS handling
  • Add device /dev/console for udev
  • ide-generic should now really be excluded
  • Fix a bug in major number for tty
  • If udev then adds modprobe/insmod to rootfs
  • tty0 is also cretaed with udev
  • ide-generic put rather in DENY_MODS
  • udevd remove from deplist s handled in mindi directly
  • better default for mindi when using --usb
  • Handles dynamically linked busybox (in case we want to use it soon ;-)
  • Adds fixed devices to create for udev
  • ide-generic should not be part of the initrd when using libata v2
  • support a dynamically linked udev (case on Ubuntu 7.10 and Mandriva 2008.0 so should be quite generic) This will give incitation to move to dyn. linked binaries in the initrd which will help for other tasks (ia6 4)
  • Improvement in udev support (do not use cl options not available in busybox)
  • Udev in mindi
    • auto creation of the right links at boot time with udev-links.conf(from Mandriva 2008.0)
    • rework startup of udev as current makes kernel crash (from Mandriva 2008.0)
    • add support for 64 bits udev
  • Try to render MyInsmod silent at boot time
  • Adds udev support (mandatory for newest distributions to avoid remapping of devices in a different way as on the original system)
  • We also need vaft format support for USB boot
  • Adds libusual support (Ubuntu 7.10 needs it for USB)
  • Improve Ubuntu/Debian keyboard detection and support
  • pbinit adapted to new pb (0.8.10). Filtering of docs done in it
  • Suppress some mondo warnings and errors on USB again
  • Tries to fix lack of files in deb mindi package
  • Verify should now work for USB devices
  • More log/mesages improvement for USB support
  • - Supress g_erase_tmpdir_and_scratchdir
  • Improve some log messages for USB support
  • Try to improve install in mindi to avoid issues with isolinux.cfg not installed vene if in the pkg :-(
  • Improve mindi-busybox build
  • In conformity with pb 0.8.9
  • Add support for Ubuntu 7.10 in build process
  • Add USB Key button to Menu UI (CD streamer removed)
  • Attempt to fix error messages on tmp/scratch files at the end by removing those dir at the latest possible.
  • Fix a bug linked to the size of the -E param which could be used (Arnaud Tiger/René Ribaud).
  • Integrate ~/.pbrc content into mondorescue.pb (required project-builder >= 0.8.7)
  • Put mondorescue in conformity with new pb filtering rules
  • Add USB support at restore time (no test done yet). New start-usb script PB varibale added where useful
  • Unmounting USB device before removal of temporary scratchdir
  • Stil refining USB copy back to mondo (one command was not executed)
  • No need to have the image subdor in the csratchdir when USB.
  • umount the USB partition before attempting to use it
  • Remove useless copy from mindi to mondo at end of USB handling

(risky merge, we are raising the limits of 2 diverging branches. The status of stable is not completely sure as such. Will need lots of tests, but it's not yet done :-()
(merge -r1692:1769 $SVN_M/branches/2.2.5)

File size: 7.6 KB
Line 
1/* vi: set sw=4 ts=4: */
2/* serverpacket.c
3 *
4 * Construct and send DHCP server packets
5 *
6 * Russ Dill <Russ.Dill@asu.edu> July 2001
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include "common.h"
24#include "dhcpd.h"
25#include "options.h"
26
27
28/* send a packet to giaddr using the kernel ip stack */
29static int send_packet_to_relay(struct dhcpMessage *payload)
30{
31 DEBUG("Forwarding packet to relay");
32
33 return udhcp_kernel_packet(payload, server_config.server, SERVER_PORT,
34 payload->giaddr, SERVER_PORT);
35}
36
37
38/* send a packet to a specific arp address and ip address by creating our own ip packet */
39static int send_packet_to_client(struct dhcpMessage *payload, int force_broadcast)
40{
41 const uint8_t *chaddr;
42 uint32_t ciaddr;
43
44 if (force_broadcast) {
45 DEBUG("broadcasting packet to client (NAK)");
46 ciaddr = INADDR_BROADCAST;
47 chaddr = MAC_BCAST_ADDR;
48 } else if (payload->ciaddr) {
49 DEBUG("unicasting packet to client ciaddr");
50 ciaddr = payload->ciaddr;
51 chaddr = payload->chaddr;
52 } else if (ntohs(payload->flags) & BROADCAST_FLAG) {
53 DEBUG("broadcasting packet to client (requested)");
54 ciaddr = INADDR_BROADCAST;
55 chaddr = MAC_BCAST_ADDR;
56 } else {
57 DEBUG("unicasting packet to client yiaddr");
58 ciaddr = payload->yiaddr;
59 chaddr = payload->chaddr;
60 }
61 return udhcp_raw_packet(payload, server_config.server, SERVER_PORT,
62 ciaddr, CLIENT_PORT, chaddr, server_config.ifindex);
63}
64
65
66/* send a dhcp packet, if force broadcast is set, the packet will be broadcast to the client */
67static int send_packet(struct dhcpMessage *payload, int force_broadcast)
68{
69 int ret;
70
71 if (payload->giaddr)
72 ret = send_packet_to_relay(payload);
73 else ret = send_packet_to_client(payload, force_broadcast);
74 return ret;
75}
76
77
78static void init_packet(struct dhcpMessage *packet, struct dhcpMessage *oldpacket, char type)
79{
80 udhcp_init_header(packet, type);
81 packet->xid = oldpacket->xid;
82 memcpy(packet->chaddr, oldpacket->chaddr, 16);
83 packet->flags = oldpacket->flags;
84 packet->giaddr = oldpacket->giaddr;
85 packet->ciaddr = oldpacket->ciaddr;
86 add_simple_option(packet->options, DHCP_SERVER_ID, server_config.server);
87}
88
89
90/* add in the bootp options */
91static void add_bootp_options(struct dhcpMessage *packet)
92{
93 packet->siaddr = server_config.siaddr;
94 if (server_config.sname)
95 strncpy((char*)packet->sname, server_config.sname, sizeof(packet->sname) - 1);
96 if (server_config.boot_file)
97 strncpy((char*)packet->file, server_config.boot_file, sizeof(packet->file) - 1);
98}
99
100
101/* send a DHCP OFFER to a DHCP DISCOVER */
102int sendOffer(struct dhcpMessage *oldpacket)
103{
104 struct dhcpMessage packet;
105 struct dhcpOfferedAddr *lease = NULL;
106 uint32_t req_align, lease_time_align = server_config.lease;
107 uint8_t *req, *lease_time;
108 struct option_set *curr;
109 struct in_addr addr;
110
111 uint32_t static_lease_ip;
112
113 init_packet(&packet, oldpacket, DHCPOFFER);
114
115 static_lease_ip = getIpByMac(server_config.static_leases, oldpacket->chaddr);
116
117 /* ADDME: if static, short circuit */
118 if (!static_lease_ip) {
119 /* the client is in our lease/offered table */
120 lease = find_lease_by_chaddr(oldpacket->chaddr);
121 if (lease) {
122 if (!lease_expired(lease))
123 lease_time_align = lease->expires - time(0);
124 packet.yiaddr = lease->yiaddr;
125 /* Or the client has a requested ip */
126 } else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP))
127 /* Don't look here (ugly hackish thing to do) */
128 && memcpy(&req_align, req, 4)
129 /* and the ip is in the lease range */
130 && ntohl(req_align) >= server_config.start_ip
131 && ntohl(req_align) <= server_config.end_ip
132 && !static_lease_ip /* Check that its not a static lease */
133 /* and is not already taken/offered */
134 && (!(lease = find_lease_by_yiaddr(req_align))
135 /* or its taken, but expired */ /* ADDME: or maybe in here */
136 || lease_expired(lease))
137 ) {
138 packet.yiaddr = req_align; /* FIXME: oh my, is there a host using this IP? */
139 /* otherwise, find a free IP */
140 } else {
141 /* Is it a static lease? (No, because find_address skips static lease) */
142 packet.yiaddr = find_address(0);
143 /* try for an expired lease */
144 if (!packet.yiaddr)
145 packet.yiaddr = find_address(1);
146 }
147
148 if (!packet.yiaddr) {
149 bb_error_msg("no IP addresses to give - OFFER abandoned");
150 return -1;
151 }
152 if (!add_lease(packet.chaddr, packet.yiaddr, server_config.offer_time)) {
153 bb_error_msg("lease pool is full - OFFER abandoned");
154 return -1;
155 }
156 lease_time = get_option(oldpacket, DHCP_LEASE_TIME);
157 if (lease_time) {
158 memcpy(&lease_time_align, lease_time, 4);
159 lease_time_align = ntohl(lease_time_align);
160 if (lease_time_align > server_config.lease)
161 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)
166 lease_time_align = server_config.lease;
167 /* ADDME: end of short circuit */
168 } else {
169 /* It is a static lease... use it */
170 packet.yiaddr = static_lease_ip;
171 }
172
173 add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_align));
174
175 curr = server_config.options;
176 while (curr) {
177 if (curr->data[OPT_CODE] != DHCP_LEASE_TIME)
178 add_option_string(packet.options, curr->data);
179 curr = curr->next;
180 }
181
182 add_bootp_options(&packet);
183
184 addr.s_addr = packet.yiaddr;
185 bb_info_msg("Sending OFFER of %s", inet_ntoa(addr));
186 return send_packet(&packet, 0);
187}
188
189
190int sendNAK(struct dhcpMessage *oldpacket)
191{
192 struct dhcpMessage packet;
193
194 init_packet(&packet, oldpacket, DHCPNAK);
195
196 DEBUG("Sending NAK");
197 return send_packet(&packet, 1);
198}
199
200
201int sendACK(struct dhcpMessage *oldpacket, uint32_t yiaddr)
202{
203 struct dhcpMessage packet;
204 struct option_set *curr;
205 uint8_t *lease_time;
206 uint32_t lease_time_align = server_config.lease;
207 struct in_addr addr;
208
209 init_packet(&packet, oldpacket, DHCPACK);
210 packet.yiaddr = yiaddr;
211
212 lease_time = get_option(oldpacket, DHCP_LEASE_TIME);
213 if (lease_time) {
214 memcpy(&lease_time_align, lease_time, 4);
215 lease_time_align = ntohl(lease_time_align);
216 if (lease_time_align > server_config.lease)
217 lease_time_align = server_config.lease;
218 else if (lease_time_align < server_config.min_lease)
219 lease_time_align = server_config.lease;
220 }
221
222 add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_align));
223
224 curr = server_config.options;
225 while (curr) {
226 if (curr->data[OPT_CODE] != DHCP_LEASE_TIME)
227 add_option_string(packet.options, curr->data);
228 curr = curr->next;
229 }
230
231 add_bootp_options(&packet);
232
233 addr.s_addr = packet.yiaddr;
234 bb_info_msg("Sending ACK to %s", inet_ntoa(addr));
235
236 if (send_packet(&packet, 0) < 0)
237 return -1;
238
239 add_lease(packet.chaddr, packet.yiaddr, lease_time_align);
240 if (ENABLE_FEATURE_UDHCPD_WRITE_LEASES_EARLY) {
241 /* rewrite the file with leases at every new acceptance */
242 write_leases();
243 }
244
245 return 0;
246}
247
248
249int send_inform(struct dhcpMessage *oldpacket)
250{
251 struct dhcpMessage packet;
252 struct option_set *curr;
253
254 init_packet(&packet, oldpacket, DHCPACK);
255
256 curr = server_config.options;
257 while (curr) {
258 if (curr->data[OPT_CODE] != DHCP_LEASE_TIME)
259 add_option_string(packet.options, curr->data);
260 curr = curr->next;
261 }
262
263 add_bootp_options(&packet);
264
265 return send_packet(&packet, 0);
266}
Note: See TracBrowser for help on using the repository browser.