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.
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.
- 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.
- 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.
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.
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.
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.
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.