Commit Graph

706 Commits

Author SHA1 Message Date
Nicholas J. Kain
5cf572c2fd Merge dhcpmsg.[ch] into packet.[ch]. 2011-06-11 11:19:05 -04:00
Nicholas J. Kain
6191a07eb3 Move get_raw_packet() to packet.c and make get_packet() and get_raw_packet()
static functions.
2011-06-11 11:05:53 -04:00
Nicholas J. Kain
52306aa217 Remove some old and now misleading comments. 2011-06-11 10:59:00 -04:00
Nicholas J. Kain
13862b488c Cosmetic improvements for change_listen_mode(). Printed messages now
look better, and epoll_add() is not called before exit() in the failure
case.
2011-06-11 05:03:33 -04:00
Nicholas J. Kain
25ee07db95 Remove sleep() calls from raw packet receipt error handling. 2011-06-11 04:48:25 -04:00
Nicholas J. Kain
9cfcfefd4e Consolidate DHCP_MAGIC check for packet.cookie field.
Minor cosmetic cleanups for DHCP packet receipt handling.
2011-06-11 04:27:56 -04:00
Nicholas J. Kain
7c6b07ca75 Tweak the minimum dhcp packet size to at least include the magic cookie
field.  In practice, packets lacking any options at all are still invalid,
but they will fail later in the validation, so that is fine.
2011-06-11 04:09:05 -04:00
Nicholas J. Kain
6222d6ec0b Update documentation to suggest mode g+w for var/run in the suggested chroot
so that PID file creation for ndhc will not fail.
2011-06-10 14:07:03 -04:00
Nicholas J. Kain
109dfd74c6 Tolerate short DHCP messages that are less than DHCP_SIZE. The previous
check was overzealous and would drop valid packets.  Now the minimal
packet size that is tolerated is 32 bytes.

24 bytes would be enough for the client IP, but I very much doubt that any
server would leave out the non-optional fields of siaddr and giaddr as well as
chaddr. We already tolerate elided chaddr with a cut-off of 32 bytes, which is
dubious enough.
2011-06-10 14:04:50 -04:00
Nicholas J. Kain
bd49819f28 Fix a bug in safe_read() that would cause short reads on an async socket
to return failure rather than the number of characters read.
2011-06-10 13:53:05 -04:00
Nicholas J. Kain
387502255f Clean up logging prints in arp.c. 2011-06-02 10:48:58 -04:00
Nicholas J. Kain
927ed47b58 Print explicit warning messages when ARP packets fail in arp_validate(). 2011-06-02 10:41:34 -04:00
Nicholas J. Kain
8ede75738f When setting route, don't print an error if EEXIST is returned by the ioctl().
This 'error' merely means that the installed route already exists.
2011-05-31 11:55:26 -04:00
Nicholas J. Kain
bec1d30279 Add arpreply_clear() helper. 2011-05-31 11:24:40 -04:00
Nicholas J. Kain
96fee03a16 Use memcmp() rather than pointer type aliasing in handle_arp_response().
Cosmetic improvements to ARP code.
2011-05-31 11:14:50 -04:00
Nicholas J. Kain
96f640e36c More strictly validate ARP responses from remote servers. 2011-05-31 11:01:08 -04:00
Nicholas J. Kain
d72b24a2fe Theoretical correctness fix:
Handle EAGAIN and EWOULDBLOCK more gracefully when dealing with safe_read().
All occurrences of safe_read() should only be invoked on fds that have signaled
ready-to-read state via the epoll() mechanism, so this change should not
result in any observable difference, but it is best to be safe.

Additionally, a constant stack variable is converted to an equivalent
macro define for cleanliness.

Finally, print the error type encountered if reading data from an ARP response
fails with a read error.
2011-05-30 10:54:05 -04:00
Nicholas J. Kain
03f0e8719e Tidy up DESIGN. It was hopelessly out of date. 2011-05-01 21:05:39 -04:00
Nicholas J. Kain
59beb159d3 Place the ifchange socket in /var/state/ifchange within the chroot
jail and change configuration instructions as well.

Change default configuration instructions to specify setting root
of the chroot jail as owned by root.root.
2011-05-01 20:43:29 -04:00
Nicholas J. Kain
b3f9115689 Add a -V --verbose flag to enable the overly verbose list reciept logging.
Update interface flags only if it would provoke an actual change.
2011-04-30 07:30:07 -04:00
Nicholas J. Kain
e96dab80fe lseek() after ftruncate() just to be safe. 2011-04-25 01:08:03 -04:00
Nicholas J. Kain
da193ae35a Add support for writing lease files. 2011-04-19 16:37:43 -04:00
Nicholas J. Kain
c7ff945be8 Shrink a delay and whitespace fix. 2011-03-31 15:28:32 -04:00
Nicholas J. Kain
996983143e Only query gateway hwaddr when binding a new lease. Don't bother when just
renewing or rebinding a lease.
2011-03-31 15:05:05 -04:00
Nicholas J. Kain
a7db2c4bd2 Make arp code more robust and refactor it a bit.
Handle failure to create arp sockets more gracefully.
Add initial support for retransmitting arp requests if no reply is met after
a certain number of spurious packets.
2011-03-31 02:32:34 -04:00
Nicholas J. Kain
f4aa2058db Get rid of a very old blocking sleep that triggered after a DHCP NAK is
received.
2011-03-31 00:03:07 -04:00
Nicholas J. Kain
a6fa236700 Massive cosmetic patch: update or add copyright headers, untabify, and
change all unsigned char to uint8_t.
2011-03-30 23:59:22 -04:00
Nicholas J. Kain
147e2d0fd9 Untabify and headerize config.h. 2011-03-30 23:33:46 -04:00
Nicholas J. Kain
b5e5685d01 Fetch the gateway hardware address after receiving a router option in a DHCP
lease.

Be more aggressive about closing old arp file descriptors.

Check the ARP headers to make sure that received ARP packets are addressed to
our machine.  Whatever bug may have existed before doesn't exist on modern
Linux kernels, if it ever did.

Use the stored gateway hardware address to validate a restored link in the
DS_ARP_GW_CHECK state.

If an ARP message is received while we are in a state that does not expect
ARP messages, close the ARP socket and log a message.
2011-03-30 23:17:27 -04:00
Nicholas J. Kain
e1eb41e1c0 Remove a debugging print. 2011-03-30 20:21:44 -04:00
Nicholas J. Kain
03717e1593 If physical link state changes to UP and a lease is bound, check to see if
the currently assigned gateway/router still replies to ARP queries.  If so,
keep the lease.  If not, get a new lease.

Save the IP address of the current gateway/router.
Remove an outdated check for a buggy compiler.
Fix a typo in the previous commit that caused timeouts to be 1000x faster than
they should be.
2011-03-30 20:13:48 -04:00
Nicholas J. Kain
de23d2241d Improve timeout backoff. It's a capped linear backoff. RFC specifies
capped randomized exponential, but I don't feel like incurring the cost
when the cap is so low.
Add comments for the dhcpMessage structure members.
2011-03-30 18:58:09 -04:00
Nicholas J. Kain
18e6f8d2c6 Remove a unnecessary debug print from add_u32_option(). 2011-03-30 16:41:29 -04:00
Nicholas J. Kain
953443f688 Untabify and headerize ifchange.[ch]. 2011-03-30 16:38:53 -04:00
Nicholas J. Kain
6265a0e973 Untabify options.[ch]. 2011-03-30 16:35:23 -04:00
Nicholas J. Kain
09613fd77a Fold req_opts[] and list_opts[] into options[].type, and modify accessors
accordingly.
2011-03-30 16:34:09 -04:00
Nicholas J. Kain
5d7bcbb2d4 Change parameters for add_option_request_list().
Make all unsigned char into uint8_t in options.[ch].
2011-03-30 16:05:28 -04:00
Nicholas J. Kain
ddf9daf8e4 Do more boundary and sanity checking when adding dhcp options.
Simplify parameter list for ifchd_cmd().
2011-03-30 15:57:01 -04:00
Nicholas J. Kain
0e62d46f8b Explicitly track length in get_end_option_idx().
Rename get_options() to get_option_data() and end_options() to
get_end_option_idx().
2011-03-30 12:04:38 -04:00
Nicholas J. Kain
97978711de Isolate the dhcp_option options[] array to options.c and provide abstract
accessors for its data.
2011-03-30 11:36:27 -04:00
Nicholas J. Kain
16460699fc Use inet_ntop() in ifchange.c rather than a homebrew function.
Get rid of a lousy hack in ifchange.c that translated the output of ifchd_cmd()
by changing every '=' to a ':'.  ifchd_cmd() is not called anywhere else, so
just make ifchd_cmd() generate the proper output.
Make buffer size accounting stricter.
2011-03-30 11:16:38 -04:00
Nicholas J. Kain
97137ec3fc Handle STRING options properly in fill_options and refactor a bit. 2011-03-30 10:39:11 -04:00
Nicholas J. Kain
7c32f968c9 Perform length and type checking in ifchange.c:fill_options.c(). 2011-03-30 10:13:34 -04:00
Nicholas J. Kain
1437f520ca Rewrite get_option(): new version fixes at least one bug, and is much easier
to understand and verify as correct.  It also returns the length of the
extracted option.
2011-03-30 09:35:17 -04:00
Nicholas J. Kain
f0865812d2 Kill unused function find_options() and unused struct option_set. 2011-03-30 08:21:06 -04:00
Nicholas J. Kain
2719d12d3c struct dhcp_option flags field is now exclusively for type, so rename it.
Remove unused struct dhcp_option types.
2011-03-30 08:19:08 -04:00
Nicholas J. Kain
f28c0c7445 OPTION_LIST is unused, remove it. 2011-03-30 08:12:56 -04:00
Nicholas J. Kain
d4171420a1 Fix sending DHCP_MAX_SIZE option.
Move DHCP_PARAM_REQ message types out of the options[] structure.
Make ipchange.c:translation_option() less insane.
2011-03-30 08:02:25 -04:00
Nicholas J. Kain
811cc67e16 Move add_requests() from dhcpmsg.c to options.c. Fixes a layering violation.
Document an ugly-as-hell code bit in ifchange.c.
Add some debugging messages for the netlink response code.
Clean headers a bit more.
2011-03-30 07:26:42 -04:00
Nicholas J. Kain
3c85228aaf Add new code for creating DHCP option data, and use it in ndhc.c. 2011-03-30 07:05:00 -04:00