38ad2399edClean 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. Kain
2011-07-01 11:37:13 -04:00
a68c8cb64cMake the log prints less debug-like and more sysadmin-friendly.
Nicholas J. Kain
2011-07-01 05:49:39 -04:00
e1262cd563Cosmetic cleanup of create_udp_listen_socket() to eliminate invariant arguments.
Nicholas J. Kain
2011-07-01 05:35:38 -04:00
9974cc2f51Separate out dhcp packet validation into validate_dhcp_packet().
Nicholas J. Kain
2011-07-01 05:33:12 -04:00
09b5c08b5bCosmetic cleanups in packet.c.
Nicholas J. Kain
2011-07-01 04:38:38 -04:00
42f81ecd33Make 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. Kain
2011-07-01 04:14:10 -04:00
7a2585d2bfKeep track of whether the ARP BPF has been successfully installed. If it has, then don't perform redundant checks in ARP validation.
Nicholas J. Kain
2011-07-01 03:01:29 -04:00
0e55bfd4fdOptimize the ARP BPF bytecode to use fewer instructions.
Nicholas J. Kain
2011-07-01 02:49:19 -04:00
927e2590a2BPF's load instructions automatically convert the loaded argument from host to network byte order, thus BPF is endian independent.
Nicholas J. Kain
2011-07-01 02:37:19 -04:00
9ddfab5085Define 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. Kain
2011-07-01 00:55:35 -04:00
3e3ecc816fDefine 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. Kain
2011-07-01 00:12:03 -04:00
f704abe50fC99 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. Kain
2011-06-30 22:02:28 -04:00
1f514cbb50Hide details of the listen mode implementation in packet.c.
Nicholas J. Kain
2011-06-30 21:33:38 -04:00
5c2398857dCosmetic cleanups to packet.c.
Nicholas J. Kain
2011-06-30 20:48:09 -04:00
6f2986803fFix a dumb error in delay_timeout(). Return value should be ms, not s.
Nicholas J. Kain
2011-06-30 04:12:59 -04:00
e77190e2e9Make frenew() less insane. It was most likely subtly buggy before depending on state.
Nicholas J. Kain
2011-06-30 03:43:09 -04:00
3a81f1ea6cUse an RFC2131-compliant exponential backoff delay.
Nicholas J. Kain
2011-06-30 03:27:57 -04:00
339804856bMake 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. Kain
2011-06-30 02:48:58 -04:00
8fffc5721fCalculate the renewTime timeout more accurately: take the delay in ARP checking into account.
Nicholas J. Kain
2011-06-30 01:50:50 -04:00
d89e9f89c2Rename ARP_GW_CHECK to BOUND_GW_CHECK and call anfrelease() rather than frelease() for this state.
Nicholas J. Kain
2011-06-30 00:39:17 -04:00
3f6aafe809Remove the DS_RENEW_REQUESTED state.
Nicholas J. Kain
2011-06-30 00:19:59 -04:00
d6fcb35903Fold renew_requested_timeout() into requesting_timeout().
Nicholas J. Kain
2011-06-30 00:11:43 -04:00
6ea5ac0d5dDon't special case DS_ARP_CHECK in nfrelease().
Nicholas J. Kain
2011-06-30 00:01:02 -04:00
76ecfffce2Centralize DHCP timeout, packet reciept, and user-demanded action handling into state.[ch]. Remove timeout.c.
Nicholas J. Kain
2011-06-29 23:47:31 -04:00
bef54a23fbRename perform_renew() and perform_release() to force_renew() and force_release().
Nicholas J. Kain
2011-06-29 20:14:24 -04:00
de47d3b4d6Add better comments to timeout.c.
Nicholas J. Kain
2011-06-29 20:08:32 -04:00
3b5faebd6cFix a typo introduced when refactoring the raw socket code.
Nicholas J. Kain
2011-06-29 19:17:32 -04:00
4c1c1715feRefactor the send and listen socket creation functions to share common code.
Nicholas J. Kain
2011-06-28 23:56:12 -04:00
52fbeb46adFix 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. Kain
2011-06-28 23:50:36 -04:00
d1f36cf75efsync() the leasefile after writing a new lease IP so that it's instantly updated to disk.
Nicholas J. Kain
2011-06-28 13:47:36 -04:00
ac38a15c9fDon'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. Kain
2011-06-28 06:32:10 -04:00
8dc93aad54Cosmetic cleanups to options.c.
Nicholas J. Kain
2011-06-27 15:19:54 -04:00
55a397c2c9Add the gentoo script for interfacing ndhc with the net configuration init scripts to version control.
Nicholas J. Kain
2011-06-27 15:09:29 -04:00
27524d9d34Use the new libc_random_u32() in ncmlib to replace random_xid().
Nicholas J. Kain
2011-06-27 15:07:00 -04:00
b72b551a0dCosmetic changes to packet.c.
Nicholas J. Kain
2011-06-27 13:01:39 -04:00
55f24fd2a3Make 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. Kain
2011-06-27 12:53:35 -04:00
63d9763345Remove init_header() and clean up init_packet() and its callers.
Nicholas J. Kain
2011-06-27 12:20:22 -04:00
1e2698b402If 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. Kain
2011-06-26 18:21:40 -04:00
057211d5f5Make 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. Kain
2011-06-26 17:50:35 -04:00
0581cc9aedTrivial cosmetic corrections.
Nicholas J. Kain
2011-06-26 17:37:57 -04:00
864ad73b20Remove 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. Kain
2011-06-26 17:25:00 -04:00
b70070e592Define stateless functions to validate the checksum of an ip header and of a udp packet and use them in get_raw_packet().
Nicholas J. Kain
2011-06-26 16:33:07 -04:00
7d0e05504fDefine 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. Kain
2011-06-26 10:21:02 -04:00
f43b656673Make 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. Kain
2011-06-25 16:55:00 -04:00
5b3aee93abTell 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. Kain
2011-06-25 16:31:21 -04:00
c37d815754Rewrite the ARP ping code to properly use modern interfaces. In detail:
Nicholas J. Kain
2011-06-25 13:02:56 -04:00
8f5eb7e921Remove invariant args to arpping().
Nicholas J. Kain
2011-06-25 11:42:15 -04:00
7ee0001e97Constant correctness: socket(PF_*, ...) -> socket(AF_*, ...)
Nicholas J. Kain
2011-06-25 11:11:48 -04:00
e50c429235Handle errors in fcntl() if O_NONBLOCK fails.
Nicholas J. Kain
2011-06-25 10:46:24 -04:00
71f59d0433Remove socket.[ch] : code is merged into packet.c
Nicholas J. Kain
2011-06-25 10:40:41 -04:00
7d206e45b6Make raw listen sockets nonblocking. They should have been so all along. Minor constant correction: PF_PACKET -> AF_PACKET
Nicholas J. Kain
2011-06-25 10:18:14 -04:00
19f7e6d11eSilence 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. Kain
2011-06-25 10:02:09 -04:00
5cf572c2fdMerge dhcpmsg.[ch] into packet.[ch].
Nicholas J. Kain
2011-06-11 11:19:05 -04:00
6191a07eb3Move get_raw_packet() to packet.c and make get_packet() and get_raw_packet() static functions.
Nicholas J. Kain
2011-06-11 11:05:53 -04:00
52306aa217Remove some old and now misleading comments.
Nicholas J. Kain
2011-06-11 10:59:00 -04:00
13862b488cCosmetic improvements for change_listen_mode(). Printed messages now look better, and epoll_add() is not called before exit() in the failure case.
Nicholas J. Kain
2011-06-11 05:03:33 -04:00
25ee07db95Remove sleep() calls from raw packet receipt error handling.
Nicholas J. Kain
2011-06-11 04:48:25 -04:00
9cfcfefd4eConsolidate DHCP_MAGIC check for packet.cookie field. Minor cosmetic cleanups for DHCP packet receipt handling.
Nicholas J. Kain
2011-06-11 04:27:56 -04:00
7c6b07ca75Tweak 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. Kain
2011-06-11 04:09:05 -04:00
6222d6ec0bUpdate 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. Kain
2011-06-10 14:07:03 -04:00
109dfd74c6Tolerate 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. Kain
2011-06-10 14:04:50 -04:00
bd49819f28Fix 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. Kain
2011-06-10 13:53:05 -04:00
387502255fClean up logging prints in arp.c.
Nicholas J. Kain
2011-06-02 10:48:58 -04:00
927ed47b58Print explicit warning messages when ARP packets fail in arp_validate().
Nicholas J. Kain
2011-06-02 10:41:34 -04:00
8ede75738fWhen 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. Kain
2011-05-31 11:55:26 -04:00
bec1d30279Add arpreply_clear() helper.
Nicholas J. Kain
2011-05-31 11:24:40 -04:00
96fee03a16Use memcmp() rather than pointer type aliasing in handle_arp_response().
Nicholas J. Kain
2011-05-31 11:14:50 -04:00
96f640e36cMore strictly validate ARP responses from remote servers.
Nicholas J. Kain
2011-05-31 11:01:08 -04:00
d72b24a2feTheoretical 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. Kain
2011-05-30 10:54:05 -04:00
03f0e8719eTidy up DESIGN. It was hopelessly out of date.
Nicholas J. Kain
2011-05-01 21:05:39 -04:00
59beb159d3Place the ifchange socket in /var/state/ifchange within the chroot jail and change configuration instructions as well.
Nicholas J. Kain
2011-05-01 20:43:29 -04:00
b3f9115689Add 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. Kain
2011-04-30 07:30:07 -04:00
e96dab80felseek() after ftruncate() just to be safe.
Nicholas J. Kain
2011-04-25 01:08:03 -04:00
da193ae35aAdd support for writing lease files.
Nicholas J. Kain
2011-04-19 16:37:43 -04:00
c7ff945be8Shrink a delay and whitespace fix.
Nicholas J. Kain
2011-03-31 15:28:32 -04:00
996983143eOnly query gateway hwaddr when binding a new lease. Don't bother when just renewing or rebinding a lease.
Nicholas J. Kain
2011-03-31 15:05:05 -04:00
a7db2c4bd2Make 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. Kain
2011-03-31 02:32:34 -04:00
f4aa2058dbGet rid of a very old blocking sleep that triggered after a DHCP NAK is received.
Nicholas J. Kain
2011-03-31 00:03:07 -04:00
a6fa236700Massive cosmetic patch: update or add copyright headers, untabify, and change all unsigned char to uint8_t.
Nicholas J. Kain
2011-03-30 23:59:22 -04:00
147e2d0fd9Untabify and headerize config.h.
Nicholas J. Kain
2011-03-30 23:33:46 -04:00
b5e5685d01Fetch the gateway hardware address after receiving a router option in a DHCP lease.
Nicholas J. Kain
2011-03-30 23:17:27 -04:00
e1eb41e1c0Remove a debugging print.
Nicholas J. Kain
2011-03-30 20:21:44 -04:00
03717e1593If 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. Kain
2011-03-30 20:13:48 -04:00
de23d2241dImprove 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. Kain
2011-03-30 18:58:09 -04:00
18e6f8d2c6Remove a unnecessary debug print from add_u32_option().
Nicholas J. Kain
2011-03-30 16:41:29 -04:00
953443f688Untabify and headerize ifchange.[ch].
Nicholas J. Kain
2011-03-30 16:38:53 -04:00
6265a0e973Untabify options.[ch].
Nicholas J. Kain
2011-03-30 16:35:23 -04:00
09613fd77aFold req_opts[] and list_opts[] into options[].type, and modify accessors accordingly.
Nicholas J. Kain
2011-03-30 16:34:09 -04:00
5d7bcbb2d4Change parameters for add_option_request_list(). Make all unsigned char into uint8_t in options.[ch].
Nicholas J. Kain
2011-03-30 16:05:28 -04:00
ddf9daf8e4Do more boundary and sanity checking when adding dhcp options. Simplify parameter list for ifchd_cmd().
Nicholas J. Kain
2011-03-30 15:57:01 -04:00
0e62d46f8bExplicitly track length in get_end_option_idx(). Rename get_options() to get_option_data() and end_options() to get_end_option_idx().
Nicholas J. Kain
2011-03-30 12:04:38 -04:00
97978711deIsolate the dhcp_option options[] array to options.c and provide abstract accessors for its data.
Nicholas J. Kain
2011-03-30 11:36:27 -04:00
16460699fcUse 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. Kain
2011-03-30 11:16:38 -04:00
97137ec3fcHandle STRING options properly in fill_options and refactor a bit.
Nicholas J. Kain
2011-03-30 10:39:11 -04:00
7c32f968c9Perform length and type checking in ifchange.c:fill_options.c().
Nicholas J. Kain
2011-03-30 10:13:34 -04:00
1437f520caRewrite 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. Kain
2011-03-30 09:35:17 -04:00
f0865812d2Kill unused function find_options() and unused struct option_set.
Nicholas J. Kain
2011-03-30 08:21:06 -04:00
2719d12d3cstruct dhcp_option flags field is now exclusively for type, so rename it. Remove unused struct dhcp_option types.
Nicholas J. Kain
2011-03-30 08:19:08 -04:00
f28c0c7445OPTION_LIST is unused, remove it.
Nicholas J. Kain
2011-03-30 08:12:56 -04:00
d4171420a1Fix 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. Kain
2011-03-30 08:02:25 -04:00