3d0f46580a
options.c: Add an add_option_clientid() variant for ndhs to use, and silence an unused function warning that triggers when compiling ndhs.
Nicholas J. Kain2014-03-18 01:51:58 -04:00
742baf6d7b
get_end_option_idx() has a useless conditional that always evaluates to the same value. Remove it, and introduce a slightly less useless conditional that prevents a possible one-byte-read past the end of packet.
Nicholas J. Kain2014-03-18 01:38:58 -04:00
e8687ba29f
Make validate_dhcp_packet()'s magic cookie length check clearer by using offsetof().
Nicholas J. Kain2014-03-18 01:36:14 -04:00
1e2c40eb81
Functions don't need explicit extern linkage in headers in C99, as it is the default. Standardize on leaving out the extern keyword as it is less clutter.
Nicholas J. Kain2014-03-17 22:10:58 -04:00
a052d069b7
nlattr was being used where rtattr should have been used. Happily, the types are almost identical (same number of fields, each field has the same length), so the code worked anyway, but nlattr and rtattr are distinct.
Nicholas J. Kain2014-03-17 20:22:20 -04:00
8416d5a633
Make nl.c:nl_rtattr_parse() use the standard NLMSG_* and RTA_* macros. It's easier to verify correct behavior this way.
Nicholas J. Kain2014-03-17 20:02:22 -04:00
268e88dc24
Make nl_getifdata() use a netlink sequence number generated from the tv_nsec field from clock_gettime(CLOCK_REALTIME), and actually check that the sequence number matches that of the netlink replies.
Nicholas J. Kain2014-03-17 06:15:59 -04:00
6460346bb6
Fix the NLMSG_LENGTH() arguments in nl.c. Somehow it worked before by lucky coincidence, but the types provided to the sizeof were wrong.
Nicholas J. Kain2014-03-17 06:14:14 -04:00
22fede861f
Netlink is pickier than the ioctl interfaces and requires the link to manually be set to an 'up' state before much of anything can be changed. Ensure that this is done very early in ndhc's lifetime, and record the link status at startup time so that the hardware link status monitoring will not get confused. A perform_ifup() function is added to faciliate this need.
Nicholas J. Kain2014-03-17 05:56:30 -04:00
3de2f42f4c
If we get a NLMSG_DONE in response to trying to delete the existing ip addresses associated with a link, then there are no existing ip addresses to delete; don't print an error in this case.
Nicholas J. Kain2014-03-17 05:41:48 -04:00
83610972c3
If link_(un|)set_flags() does not need to change the existing flags to satisfy the request, then return 1 rather than 0 and do not ask netlink to perform any changes.
Nicholas J. Kain2014-03-17 05:35:34 -04:00
b0a5132d72
Cosmetic cleanups to ifchd.c. No functional change.
Nicholas J. Kain2014-03-17 05:33:00 -04:00
3e78ffd576
We don't need to disable hardware link status while ifch is working; if the link status goes down, we will fail horribly anyway because ARP will fail, so we must keep track of the link status to be safe.
Nicholas J. Kain2014-03-17 03:17:24 -04:00
03bd10ed88
When setting the MTU via netlink, we must be careful to preserve the link flags or bad things will happen (such as the link being set down).
Nicholas J. Kain2014-03-17 03:16:02 -04:00
6fcc43d169
Hardware link status can 'bounce' erratically while link properties are being updated, so perform status debouncing.
Nicholas J. Kain2014-03-17 02:55:47 -04:00
d8e3dc61ea
Make the netlink link flags and router setting code work properly.
Nicholas J. Kain2014-03-17 02:07:30 -04:00
50d6284fee
Use netlink for setting link flags instead of ioctl.
Nicholas J. Kain2014-03-16 05:10:21 -04:00
cce93139d0
Delete old IP addresses associated with the interface when setting the DHCP-assigned IP, broadcast, and subnet.
Nicholas J. Kain2014-03-15 04:43:29 -04:00
7bf1cc419e
nl_recv_buf() must be non-blocking; enforce it with the MSG_DONTWAIT flag. At the same time, properly handle EINTR.
Nicholas J. Kain2014-03-15 04:35:07 -04:00
7627298c07
The ip4 protocol change broke on the send side; fix it by explicitly zeroing the send buffer. It's less finicky than special-casing the ip4 command to use strnkcpy instead of strnkcat.
Nicholas J. Kain2014-03-15 04:32:44 -04:00
19d009891a
When updating the IP and broadcast addresses, clear out any old IP and broadcast addresses that may be still bound to the interface.
Nicholas J. Kain2014-03-15 02:44:43 -04:00
8faae4a0fd
Check that the return message type is not NLMSG_ERROR when setting the ip and broadcast addresses.
Nicholas J. Kain2014-03-14 23:28:56 -04:00
6a9e8c5a57
Disable seccomp-filter unless ENABLE_SECCOMP_FILTER is defined.
Nicholas J. Kain2014-03-14 23:24:22 -04:00
312884dfc5
When execute_buffer() is passed an invalid command, print the bad command when logging the error.
Nicholas J. Kain2014-03-14 20:48:33 -04:00
4afddd471a
The getopt_long shortarg string needed a ':' after 'C' as it has a mandatory argument.
Nicholas J. Kain2014-03-14 20:47:57 -04:00
971c6085d8
ifchd.c: If resolv_conf_fd < 0, it is invalid. -1 is the explicit uninitialized value, but there is no need to limit the guard to -1.
Nicholas J. Kain2014-03-12 20:58:27 -04:00
4feac2ea35
Rename ifchd_cmd_str() to ifchd_cmd_bytes() as it can handle byte sequences without a terminating nul.
Nicholas J. Kain2014-03-12 20:47:39 -04:00
73ad3b1419
Mark external function prototypes in state.h as extern.
Nicholas J. Kain2014-03-12 20:39:55 -04:00
b9a30f0653
Move external definitions of functions in ifchd.c to ifchd.h instead of defining them manually in ndhc.c.
Nicholas J. Kain2014-03-12 16:13:47 -04:00
9bf79b6034
Update the nk_random calls to use the new re-entrant-safe API.
Nicholas J. Kain2014-03-12 15:41:34 -04:00
54a7f54a4a
Move add_rtattr() from ifset.c to nl.c as nl_add_rtatr().
Nicholas J. Kain2014-03-12 15:25:07 -04:00
1222f4f22a
Handle sendto() returning EINTR in nl_sendgetlink(), and print if an error is encountered while performing sendto().
Nicholas J. Kain2014-03-12 15:14:40 -04:00
b7b353acdc
Store the interface index in the client_config before forking off the subprocesses. ndhc-ifch can then use the stored interface index when setting the interface ip/subnet/broadcast via netlink instead of having to use ioctl to re-fetch the interface index.
Nicholas J. Kain2014-03-12 15:07:37 -04:00
80f82c2451
options.c: Don't trust the options length field in do_get_dhcp_opt() to not be longer than the total option length.
Nicholas J. Kain2014-03-12 13:30:55 -04:00
765f3de274
Use strncmp rather than strcmp in netlink.c when fetching the interface MAC address and index.
Nicholas J. Kain2014-03-12 13:03:34 -04:00
84b36f0e02
Remove -Wcast-qual. The warnings are not useful on the ndhc code, and I would effectively end up silencing them via the (uintptr_t) casting hack.
Nicholas J. Kain2014-03-10 22:56:01 -04:00
e7838d542b
Fix the remaining signed/unsigned comparison warnings. Nothing stands out as being dangerous or buggy.
Nicholas J. Kain2014-03-10 19:00:08 -04:00
e50bd431d6
dhcp.c: handle_packet() calls get_(raw|cooked)_packet(), which returns a signed value where values <0 are errors and >= 0 are lengths. Convert to an unsigned length value if the return is a length.
Nicholas J. Kain2014-03-10 18:58:53 -04:00
1824802fb2
Merge ifchd into ndhc. Rather than function as entirely separate daemons, ndhc will fork off an ifchd child that it will communicate with via pipes rather than by connecting to a SO_PEERCRED AF_UNIX socket.
Nicholas J. Kain2014-03-10 00:52:56 -04:00
520ba6fd31
Mark function prototypes in ifchd/linux.h as extern. Update copyright dates and do some cosmetic changes, too.
Nicholas J. Kain2014-03-09 12:32:30 -04:00
06b65de08c
Add a perform_ip_subnet_bcast() function that uses Linux netlink sockets to set the interface ip, subnet, and broadcast address simultaneously.
Nicholas J. Kain2014-03-09 09:46:05 -04:00
81a9fe1c8e
inet_pton() can return 0 or -1 as errors. We wern't likely to see -1 in practice (it's documented to be only emitted when inet_pton is provided an unrecognized address family), but best to be completely correct.
Nicholas J. Kain2014-03-09 09:42:49 -04:00
3ef87c1f26
ifchd: Make the command parser much more strict. It now has a concept of argument types and command types.
Nicholas J. Kain2013-05-11 10:59:04 -04:00
62d69e1909
Lists of IPs should be comma-separated rather than semicolon or space-separated.
Nicholas J. Kain2013-05-10 13:46:58 -04:00
1fc06c6e4f
ifchd: Print NYI messages to log if we received a command where the handler is not yet implemented.
Nicholas J. Kain2013-05-10 13:45:09 -04:00
7ab11e8295
Add strnkcpy() and strnkcat(). These are similar to strlcpy and strlcat, but simply return a bool indicating whether the destination received a truncated copy of the source (true if truncation occurs else false).
Nicholas J. Kain2013-05-06 07:06:33 -04:00
f807e10e76
Make the ARP-based lease address collision checks configurable in delay times and number of probes.
Nicholas J. Kain2013-02-09 00:30:19 -05:00
22e5a60671
Drop packet fragments in the BPF program. No compliant stack should fragment DHCP messages anyway, since the IPv4 min MTU is 576 bytes and the max DHCP message size + IP and UDP headers is less than that, but it is still worth checking.
Nicholas J. Kain2012-07-23 13:18:23 -04:00