38ad2399ed
Clean up the DHCP packet sending functions and make them more RFC-compliant. Rename cs->requestedIP to cs->clientAddr. Move the IFS_* defines into netlink.c. Cosmetic cleanups.
Nicholas J. Kain2011-07-01 11:37:13 -04:00
a68c8cb64c
Make the log prints less debug-like and more sysadmin-friendly.
Nicholas J. Kain2011-07-01 05:49:39 -04:00
e1262cd563
Cosmetic cleanup of create_udp_listen_socket() to eliminate invariant arguments.
Nicholas J. Kain2011-07-01 05:35:38 -04:00
9974cc2f51
Separate out dhcp packet validation into validate_dhcp_packet().
Nicholas J. Kain2011-07-01 05:33:12 -04:00
42f81ecd33
Make the DHCP BPF perform stricter checks. Now packets that have IP options are discarded, and the UDP length, IP length, and IP header size fields are validated for consistency.
Nicholas J. Kain2011-07-01 04:14:10 -04:00
7a2585d2bf
Keep track of whether the ARP BPF has been successfully installed. If it has, then don't perform redundant checks in ARP validation.
Nicholas J. Kain2011-07-01 03:01:29 -04:00
0e55bfd4fd
Optimize the ARP BPF bytecode to use fewer instructions.
Nicholas J. Kain2011-07-01 02:49:19 -04:00
927e2590a2
BPF's load instructions automatically convert the loaded argument from host to network byte order, thus BPF is endian independent.
Nicholas J. Kain2011-07-01 02:37:19 -04:00
9ddfab5085
Define a BPF for ARP-listening raw sockets that discriminates by ethernet frame protocol type field, ARP hardware type field, ARP protocol type field, ARP hardware address length field, and ARP protocol address length field.
Nicholas J. Kain2011-07-01 00:55:35 -04:00
3e3ecc816f
Define a BPF for DHCP-listening raw sockets that discriminates by IP version field, IP protocol number field, and UDP client and server port fields and passes the number of octets specified in the IP total length field.
Nicholas J. Kain2011-07-01 00:12:03 -04:00
f704abe50f
C99 designated initializers guarantee zero-init of unspecified members. Take advantage of that feature in ndhc.c when initializing the state and config structures.
Nicholas J. Kain2011-06-30 22:02:28 -04:00
1f514cbb50
Hide details of the listen mode implementation in packet.c.
Nicholas J. Kain2011-06-30 21:33:38 -04:00
6f2986803f
Fix a dumb error in delay_timeout(). Return value should be ms, not s.
Nicholas J. Kain2011-06-30 04:12:59 -04:00
e77190e2e9
Make frenew() less insane. It was most likely subtly buggy before depending on state.
Nicholas J. Kain2011-06-30 03:43:09 -04:00
3a81f1ea6c
Use an RFC2131-compliant exponential backoff delay.
Nicholas J. Kain2011-06-30 03:27:57 -04:00
339804856b
Make the renew and rebind timeouts more strictly rfc compliant, and also take into account the possiblity of renew times being ridiculously deferred such that the current time is within lease expiration time.
Nicholas J. Kain2011-06-30 02:48:58 -04:00
8fffc5721f
Calculate the renewTime timeout more accurately: take the delay in ARP checking into account.
Nicholas J. Kain2011-06-30 01:50:50 -04:00
d89e9f89c2
Rename ARP_GW_CHECK to BOUND_GW_CHECK and call anfrelease() rather than frelease() for this state.
Nicholas J. Kain2011-06-30 00:39:17 -04:00
76ecfffce2
Centralize DHCP timeout, packet reciept, and user-demanded action handling into state.[ch]. Remove timeout.c.
Nicholas J. Kain2011-06-29 23:47:31 -04:00
bef54a23fb
Rename perform_renew() and perform_release() to force_renew() and force_release().
Nicholas J. Kain2011-06-29 20:14:24 -04:00
3b5faebd6c
Fix a typo introduced when refactoring the raw socket code.
Nicholas J. Kain2011-06-29 19:17:32 -04:00
4c1c1715fe
Refactor the send and listen socket creation functions to share common code.
Nicholas J. Kain2011-06-28 23:56:12 -04:00
52fbeb46ad
Fix a problem where, when ndhc is waiting for an arp packet, an arp packet is received that is discarded by ndhc's basic checks and provokes a busy loop in the main program loop because epoll_wait() constantly sees data that is never drained from the socket buffer since arp_offset exceeds the maximum size of an ARP packet and would overflow the packet buffer.
Nicholas J. Kain2011-06-28 23:50:36 -04:00
d1f36cf75e
fsync() the leasefile after writing a new lease IP so that it's instantly updated to disk.
Nicholas J. Kain2011-06-28 13:47:36 -04:00
ac38a15c9f
Don't spam 'No lease, going to background.' messages after going into the background and trying to get a DHCP lease when the client has never had a lease in the current instance of the process.
Nicholas J. Kain2011-06-28 06:32:10 -04:00
55a397c2c9
Add the gentoo script for interfacing ndhc with the net configuration init scripts to version control.
Nicholas J. Kain2011-06-27 15:09:29 -04:00
27524d9d34
Use the new libc_random_u32() in ncmlib to replace random_xid().
Nicholas J. Kain2011-06-27 15:07:00 -04:00
55f24fd2a3
Make the various functions in options.c that take a pointer to an options buffer and length instead take a pointer to a struct dhcpmsg. This argument list choice implicitly gives safe length checks and is simpler.
Nicholas J. Kain2011-06-27 12:53:35 -04:00
63d9763345
Remove init_header() and clean up init_packet() and its callers.
Nicholas J. Kain2011-06-27 12:20:22 -04:00
1e2698b402
If a lease is negotiated, then expires after renewal attempts, don't time out and exit the daemon as would be desirable at startup. Just keep trying.
Nicholas J. Kain2011-06-26 18:21:40 -04:00
057211d5f5
Make IP and UDP checksum calculations for sending raw packets much less confusing. They are now calculated without mutating the underlying structures so that there is no longer any tricky operation order dependence.
Nicholas J. Kain2011-06-26 17:50:35 -04:00
864ad73b20
Remove pointless length-checking in get_raw_packet() that can never be triggered because safe_read() already protects against reads longer than a DHCP packet in length.
Nicholas J. Kain2011-06-26 17:25:00 -04:00
b70070e592
Define stateless functions to validate the checksum of an ip header and of a udp packet and use them in get_raw_packet().
Nicholas J. Kain2011-06-26 16:33:07 -04:00
7d0e05504f
Define a new IP checksum function that is resistant to undefined signed overflow when given ridiculously large data lengths. In practice, undefined behavior would never occur with the previous function since it would have required IP packets >128KiB bytes in length and the maximum length for an IP packet is 64KiB.
Nicholas J. Kain2011-06-26 10:21:02 -04:00
f43b656673
Make static in packet.c: checksum(), raw_packet(), and kernel_packet(). Rename raw_packet() to send_dhcp_raw() and strip of unnecessary arguments. Rename kernel_packet() to send_dhcp_cooked() and strip of unnecessary arguments. Remove the ugly bcast_raw_packet() wrapper hack.
Nicholas J. Kain2011-06-25 16:55:00 -04:00
5b3aee93ab
Tell the kernel not to attempt routing table lookups for sent DHCP traffic: - Use SO_DONTROUTE for dhcp listen and send sockets (both raw and udp).
Nicholas J. Kain2011-06-25 16:31:21 -04:00
c37d815754
Rewrite the ARP ping code to properly use modern interfaces. In detail:
Nicholas J. Kain2011-06-25 13:02:56 -04:00
7d206e45b6
Make raw listen sockets nonblocking. They should have been so all along. Minor constant correction: PF_PACKET -> AF_PACKET
Nicholas J. Kain2011-06-25 10:18:14 -04:00
19f7e6d11e
Silence excessively chatty messages from ARP handling. Random received packets that are discarded for simply not being targets for examination should not trigger prints.
Nicholas J. Kain2011-06-25 10:02:09 -04:00
13862b488c
Cosmetic improvements for change_listen_mode(). Printed messages now look better, and epoll_add() is not called before exit() in the failure case.
Nicholas J. Kain2011-06-11 05:03:33 -04:00
25ee07db95
Remove sleep() calls from raw packet receipt error handling.
Nicholas J. Kain2011-06-11 04:48:25 -04:00
9cfcfefd4e
Consolidate DHCP_MAGIC check for packet.cookie field. Minor cosmetic cleanups for DHCP packet receipt handling.
Nicholas J. Kain2011-06-11 04:27:56 -04:00
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.
Nicholas J. Kain2011-06-11 04:09:05 -04:00
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.
Nicholas J. Kain2011-06-10 14:07:03 -04:00
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.
Nicholas J. Kain2011-06-10 14:04:50 -04:00
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.
Nicholas J. Kain2011-06-10 13:53:05 -04:00
927ed47b58
Print explicit warning messages when ARP packets fail in arp_validate().
Nicholas J. Kain2011-06-02 10:41:34 -04:00
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.
Nicholas J. Kain2011-05-31 11:55:26 -04:00
96fee03a16
Use memcmp() rather than pointer type aliasing in handle_arp_response().
Nicholas J. Kain2011-05-31 11:14:50 -04:00
96f640e36c
More strictly validate ARP responses from remote servers.
Nicholas J. Kain2011-05-31 11:01:08 -04:00
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.
Nicholas J. Kain2011-05-30 10:54:05 -04:00
59beb159d3
Place the ifchange socket in /var/state/ifchange within the chroot jail and change configuration instructions as well.
Nicholas J. Kain2011-05-01 20:43:29 -04:00
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.
Nicholas J. Kain2011-04-30 07:30:07 -04:00
996983143e
Only query gateway hwaddr when binding a new lease. Don't bother when just renewing or rebinding a lease.
Nicholas J. Kain2011-03-31 15:05:05 -04:00
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.
Nicholas J. Kain2011-03-31 02:32:34 -04:00
f4aa2058db
Get rid of a very old blocking sleep that triggered after a DHCP NAK is received.
Nicholas J. Kain2011-03-31 00:03:07 -04:00
a6fa236700
Massive cosmetic patch: update or add copyright headers, untabify, and change all unsigned char to uint8_t.
Nicholas J. Kain2011-03-30 23:59:22 -04:00
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.
Nicholas J. Kain2011-03-30 20:13:48 -04:00
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.
Nicholas J. Kain2011-03-30 18:58:09 -04:00
18e6f8d2c6
Remove a unnecessary debug print from add_u32_option().
Nicholas J. Kain2011-03-30 16:41:29 -04:00
09613fd77a
Fold req_opts[] and list_opts[] into options[].type, and modify accessors accordingly.
Nicholas J. Kain2011-03-30 16:34:09 -04:00
5d7bcbb2d4
Change parameters for add_option_request_list(). Make all unsigned char into uint8_t in options.[ch].
Nicholas J. Kain2011-03-30 16:05:28 -04:00
ddf9daf8e4
Do more boundary and sanity checking when adding dhcp options. Simplify parameter list for ifchd_cmd().
Nicholas J. Kain2011-03-30 15:57:01 -04:00
0e62d46f8b
Explicitly track length in get_end_option_idx(). Rename get_options() to get_option_data() and end_options() to get_end_option_idx().
Nicholas J. Kain2011-03-30 12:04:38 -04:00
97978711de
Isolate the dhcp_option options[] array to options.c and provide abstract accessors for its data.
Nicholas J. Kain2011-03-30 11:36:27 -04:00
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.
Nicholas J. Kain2011-03-30 11:16:38 -04:00
97137ec3fc
Handle STRING options properly in fill_options and refactor a bit.
Nicholas J. Kain2011-03-30 10:39:11 -04:00
7c32f968c9
Perform length and type checking in ifchange.c:fill_options.c().
Nicholas J. Kain2011-03-30 10:13:34 -04:00
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.
Nicholas J. Kain2011-03-30 09:35:17 -04:00
f0865812d2
Kill unused function find_options() and unused struct option_set.
Nicholas J. Kain2011-03-30 08:21:06 -04:00
2719d12d3c
struct dhcp_option flags field is now exclusively for type, so rename it. Remove unused struct dhcp_option types.
Nicholas J. Kain2011-03-30 08:19:08 -04:00
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.
Nicholas J. Kain2011-03-30 08:02:25 -04:00