dhclient - Add 6-byte MAC address to the log entries for DHCP ACK/NAK/OFFER.
authorAntonio Huete Jimenez <tuxillo@quantumachine.net>
Tue, 31 Jul 2012 20:29:29 +0000 (22:29 +0200)
committerAntonio Huete Jimenez <tuxillo@quantumachine.net>
Sun, 19 Aug 2012 14:30:14 +0000 (16:30 +0200)
- Log the packets before checking the client state. Makes it easy to find
  MACs for 'surprise' DHCP servers.
- Swap ifi status check logic to be the first one.

sbin/dhclient/dhclient.c
sbin/dhclient/dhcpd.h
sbin/dhclient/dispatch.c
sbin/dhclient/options.c

index fad1df2..a409730 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: src/sbin/dhclient/dhclient.c,v 1.120 2008/06/07 03:22:26 deraadt Exp $ */
+/* $OpenBSD: src/sbin/dhclient/dhclient.c,v 1.124 2009/03/10 23:19:36 krw Exp $ */
 
 /*
  * Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -589,8 +589,6 @@ dhcpack(struct iaddr client_addr, struct option_data *options)
 {
        struct client_lease *lease;
 
-       if (client->xid != client->packet.xid)
-               return;
 
        if (client->state != S_REBOOTING &&
            client->state != S_REQUESTING &&
@@ -598,7 +596,6 @@ dhcpack(struct iaddr client_addr, struct option_data *options)
            client->state != S_REBINDING)
                return;
 
-       note("DHCPACK from %s", piaddr(client_addr));
 
        lease = packet_to_lease(options);
        if (!lease) {
@@ -731,13 +728,10 @@ dhcpoffer(struct iaddr client_addr, struct option_data *options)
        char *name = options[DHO_DHCP_MESSAGE_TYPE].len ? "DHCPOFFER" :
            "BOOTREPLY";
 
-       if (client->xid != client->packet.xid)
-               return;
 
        if (client->state != S_SELECTING)
                return;
 
-       note("%s from %s", name, piaddr(client_addr));
 
        /* If this lease doesn't supply the minimum required parameters,
           blow it off. */
@@ -909,8 +903,6 @@ packet_to_lease(struct option_data *options)
 void
 dhcpnak(struct iaddr client_addr, struct option_data *options)
 {
-       if (client->xid != client->packet.xid)
-               return;
 
        if (client->state != S_REBOOTING &&
            client->state != S_REQUESTING &&
@@ -918,7 +910,6 @@ dhcpnak(struct iaddr client_addr, struct option_data *options)
            client->state != S_REBINDING)
                return;
 
-       note("DHCPNAK from %s", piaddr(client_addr));
 
        if (!client->active) {
                note("DHCPNAK with no active lease.");
index 7d8601c..db7ac74 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: src/sbin/dhclient/dhcpd.h,v 1.67 2008/05/26 03:11:48 deraadt Exp $    */
+/* $OpenBSD: src/sbin/dhclient/dhcpd.h,v 1.68 2009/03/10 23:19:36 krw Exp $ */
 
 /*
  * Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -51,6 +51,7 @@
 #include <net/if_dl.h>
 #include <net/route.h>
 #include <netinet/in.h>
+#include <netinet/if_ether.h>
 
 #include <ctype.h>
 #include <errno.h>
index 1057966..38461c7 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: src/sbin/dhclient/dispatch.c,v 1.42 2008/05/26 03:11:49 deraadt Exp $ */
+/* $OpenBSD: src/sbin/dhclient/dispatch.c,v 1.43 2009/02/19 03:29:21 krw Exp $ */
 
 /*
  * Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -183,8 +183,7 @@ another:
                }
 
                if ((fds[0].revents & (POLLIN | POLLHUP))) {
-                       if (ifi->linkstat &&
-                           ifi && ifi->rfdesc != -1)
+                       if (ifi && ifi->linkstat && ifi->rfdesc != -1)
                                got_one();
                }
                if ((fds[1].revents & (POLLIN | POLLHUP))) {
index d56ee2e..c77e315 100644 (file)
@@ -1,5 +1,4 @@
-/*     $OpenBSD: options.c,v 1.36 2007/06/02 01:29:11 pvalchev Exp $   */
-/*     $DragonFly: src/sbin/dhclient/options.c,v 1.1 2008/08/30 16:07:58 hasso Exp $   */
+/* $OpenBSD: src/sbin/dhclient/options.c,v 1.37 2009/03/10 23:19:36 krw Exp $ */
 
 /* DHCP options parsing and reassembly. */
 
@@ -491,6 +490,15 @@ do_packet(int len, unsigned int from_port, struct iaddr from,
                type = "BOOTREPLY";
        }
 
+       if (handler && client->xid == client->packet.xid) {
+               if (hfrom->hlen == 6)
+                       note("%s from %s (%s)", type, piaddr(from),
+                           ether_ntoa((struct ether_addr *)hfrom->haddr));
+               else
+                       note("%s from %s", type, piaddr(from));
+       } else
+               handler = NULL;
+
        for (ap = config->reject_list; ap && handler; ap = ap->next)
                if (addr_eq(from, ap->addr)) {
                        note("%s from %s rejected.", type, piaddr(from));