35 Commits

Author SHA1 Message Date
Nicholas J. Kain
1f514cbb50 Hide details of the listen mode implementation in packet.c. 2011-06-30 21:33:38 -04:00
Nicholas J. Kain
e77190e2e9 Make frenew() less insane. It was most likely subtly buggy before depending
on state.
2011-06-30 03:43:09 -04:00
Nicholas J. Kain
8fffc5721f Calculate the renewTime timeout more accurately: take the delay in ARP
checking into account.

Rename t1 and t2 to renewTime and rebindTime.
2011-06-30 01:50:50 -04:00
Nicholas J. Kain
d89e9f89c2 Rename ARP_GW_CHECK to BOUND_GW_CHECK and call anfrelease() rather than
frelease() for this state.
2011-06-30 00:39:17 -04:00
Nicholas J. Kain
6ea5ac0d5d Don't special case DS_ARP_CHECK in nfrelease(). 2011-06-30 00:01:02 -04:00
Nicholas J. Kain
76ecfffce2 Centralize DHCP timeout, packet reciept, and user-demanded action handling
into state.[ch].  Remove timeout.c.
2011-06-29 23:47:31 -04:00
Nicholas J. Kain
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.
2011-06-28 23:50:36 -04:00
Nicholas J. Kain
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.
2011-06-26 18:21:40 -04:00
Nicholas J. Kain
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.

Lots of cosmetic cleanups.  Highlights:
- Remove pointless enums that just define sizeof for various structures.
- Rename struct dhcpMessage to struct dhcpmsg.
2011-06-26 17:25:00 -04:00
Nicholas J. Kain
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).

More paranoia against packets being sent to incorrect interfaces:
- Bind arp socket to a specific interface via bind().
- Use SO_BINDTODEVICE for udp send sockets.  It was already used for udp
  listen sockets.

Flatten indentation in arp_(open|close)_fd().
Use C99 initializers in packet.c.
Add more error message prints to packet.c.
2011-06-25 16:31:21 -04:00
Nicholas J. Kain
c37d815754 Rewrite the ARP ping code to properly use modern interfaces. In detail:
- Use AF_PACKET and SOCK_RAW rather than the decade-deprecated
  SOCK_PACKET interface.
- Separate out socket creation code into a subfunction.
- Use C99 initializers for packet and address structures.
- Cosmetic cleanups.
2011-06-25 13:02:56 -04:00
Nicholas J. Kain
8f5eb7e921 Remove invariant args to arpping(). 2011-06-25 11:42:15 -04:00
Nicholas J. Kain
7ee0001e97 Constant correctness: socket(PF_*, ...) -> socket(AF_*, ...) 2011-06-25 11:11:48 -04:00
Nicholas J. Kain
e50c429235 Handle errors in fcntl() if O_NONBLOCK fails. 2011-06-25 10:46:24 -04:00
Nicholas J. Kain
71f59d0433 Remove socket.[ch] : code is merged into packet.c 2011-06-25 10:40:41 -04:00
Nicholas J. Kain
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.
2011-06-25 10:02:09 -04:00
Nicholas J. Kain
5cf572c2fd Merge dhcpmsg.[ch] into packet.[ch]. 2011-06-11 11:19: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
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
da193ae35a Add support for writing lease files. 2011-04-19 16:37:43 -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
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
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
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
13d9119f3a Remove dhcpd.h. 2011-03-30 05:55:12 -04:00
Nicholas J. Kain
a53a82bbc5 After fork(), a signalfd-created file descriptor still returns signal info
for the parent.  Close and recreate a new signalfd after forking into the
background.
2010-12-27 10:05:43 -05:00
Nicholas J. Kain
11e71837fd Set arp socket as nonblocking. 2010-12-26 18:19:39 -05:00
Nicholas J. Kain
6f483045f4 Remove redundant #include. 2010-12-26 18:17:41 -05:00
Nicholas J. Kain
c0b699ba88 Rename script.[ch] to ifchange.[ch]. 2010-12-24 10:12:41 -05:00
Nicholas J. Kain
08f7db1637 Rename clientpacket.c to dhcpmsg.c. 2010-12-24 10:01:12 -05:00
Nicholas J. Kain
d04916aec5 Rename arpping.[ch] to arp.[ch]. 2010-12-24 09:58:47 -05:00