diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2017-07-06 16:56:53 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2017-07-06 16:56:53 +0000 |
commit | 6abd85c74fb722fc81d76d967d723c80c7be2cef (patch) | |
tree | 9252dd50b3b061633fbbf19fbe4923854c4e2f87 /sbin/dhclient/dispatch.c | |
parent | b291e991517ca300b5f49789f609e3c005f72b55 (diff) |
cons_options() only needs to know a buffer and a length to
pack options into. Not all the gory details of interface_info.
Move some of the raw packet processing out of options.c's
do_packet() and into the more obvious dispatch.c's
packethandler().
Mention that RFC791 is why we use 576-byte UDP packets.
Diffstat (limited to 'sbin/dhclient/dispatch.c')
-rw-r--r-- | sbin/dhclient/dispatch.c | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c index 325f6b6cc8e..a9d4fc8aba0 100644 --- a/sbin/dhclient/dispatch.c +++ b/sbin/dhclient/dispatch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dispatch.c,v 1.130 2017/07/01 23:27:56 krw Exp $ */ +/* $OpenBSD: dispatch.c,v 1.131 2017/07/06 16:56:52 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -53,6 +53,8 @@ #include <netinet/in.h> #include <netinet/if_ether.h> +#include <arpa/inet.h> + #include <errno.h> #include <ifaddrs.h> #include <imsg.h> @@ -198,10 +200,12 @@ dispatch(struct interface_info *ifi, int routefd) void packethandler(struct interface_info *ifi) { - struct sockaddr_in from; - struct ether_addr hfrom; - struct in_addr ifrom; - ssize_t result; + struct sockaddr_in from; + struct ether_addr hfrom; + struct in_addr ifrom; + struct dhcp_packet *packet = &ifi->recv_packet; + struct reject_elem *ap; + ssize_t result; if ((result = receive_packet(ifi, &from, &hfrom)) == -1) { ifi->errors++; @@ -219,6 +223,39 @@ packethandler(struct interface_info *ifi) ifrom.s_addr = from.sin_addr.s_addr; + if (packet->hlen != ETHER_ADDR_LEN) { +#ifdef DEBUG + log_debug("Discarding packet with hlen != %s (%u)", + ifi->name, packet->hlen); +#endif /* DEBUG */ + return; + } else if (memcmp(&ifi->hw_address, packet->chaddr, + sizeof(ifi->hw_address))) { +#ifdef DEBUG + log_debug("Discarding packet with chaddr != %s (%s)", + ifi->name, + ether_ntoa((struct ether_addr *)packet->chaddr)); +#endif /* DEBUG */ + return; + } + + if (ifi->xid != packet->xid) { +#ifdef DEBUG + log_debug("Discarding packet with XID != %u (%u)", ifi->xid, + packet->xid); +#endif /* DEBUG */ + return; + } + + TAILQ_FOREACH(ap, &config->reject_list, next) + if (ifrom.s_addr == ap->addr.s_addr) { +#ifdef DEBUG + log_debug("Discarding packet from address on reject " + "list (%s)", inet_ntoa(ifrom)); +#endif /* DEBUG */ + return; + } + do_packet(ifi, from.sin_port, ifrom, &hfrom); } |