[Dnsmasq-discuss] Tag requests for a DHCP address from devices using a Locally Administered MAC address

dev at lutean.com dev at lutean.com
Mon Jul 27 19:12:02 BST 2020


Hi everyone,

The following proposed patch includes my attempt at a man page change. It also includes Vladislav Grishenko's suggestion to tag LAA source addresses independently from multicast addresses.

If these changes are acceptable, I propose the following commit message:

DHCP requests from ethernet MAC addresses that have either the Locally Administered Address flag set or the multicast flag set automatically get tagged with "laa" and "multicast" respectively before further processing.

Todd Sankey

--- a/man/dnsmasq.8
+++ b/man/dnsmasq.8
@@ -2152,9 +2152,24 @@ include set:<tag>, including one from the
 .B --dhcp-range
 used to allocate the address, one from any matching 
 .B --dhcp-host
-(and "known" or "known-othernet" if a \fB--dhcp-host\fP matches)
-The tag "bootp" is set for BOOTP requests, and a tag whose name is the 
-name of the interface on which the request arrived is also set.
+In addition, several tags may be applied automatically. These are:
+.PP
+.B - "known"
+if a \fB--dhcp-host\fP matches and it is being used
+.PP
+.B - "known-othernet"
+if a \fB--dhcp-host\fP matches but it cannot be used because it does not apply on the network the request was received on
+.PP
+.B - "bootp"
+if the request is a BOOTP request
+.PP
+.B - "laa"
+if the request source MAC address is a Locally Administered Address
+.PP
+.B - "multicast"
+if the request source MAC address is a multicast address
+.PP
+- the name of the interface on which the request arrived.
 
 Any configuration lines which include one or more tag:<tag> constructs
 will only be valid if all that tags are matched in the set derived
diff --git a/src/rfc2131.c b/src/rfc2131.c
index fc54aab..4358b52 100644
--- a/src/rfc2131.c
+++ b/src/rfc2131.c
@@ -93,7 +93,7 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
   unsigned char *agent_id = NULL, *uuid = NULL;
   unsigned char *emac = NULL;
   int vendor_class_len = 0, emac_len = 0;
-  struct dhcp_netid known_id, iface_id, cpewan_id;
+  struct dhcp_netid known_id, iface_id, cpewan_id, laa_id, multicast_id;
   struct dhcp_opt *o;
   unsigned char pxe_uuid[17];
   unsigned char *oui = NULL, *serial = NULL;
@@ -114,6 +114,30 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
   if (mess->htype == 0 && mess->hlen != 0)
     return 0;
 
+  /* Ethernet addresses have 2 special bits, the 2 LSbs of the first address byte.
+     Check those 2 special bytes and tag DHCP requests from devices for the unusual
+     cases of these 2 bits. */
+  if (mess->htype == ARPHRD_ETHER && (mess->chaddr[0] & 3))
+  {
+    /* Check if sender has a Locally-Administered ethernet Address and set a tag if so. */
+    /* Locally Administered Addresses (LAA) have the 2nd LSb of the first address byte set */
+    if ((mess->chaddr[0] & 2) == 2)
+    {
+      laa_id.net = "laa";
+      laa_id.next = netid;
+      netid = &laa_id;
+    }
+
+    /* Check if sender has a multicast ethernet and set a tag if so. */
+    /* Multicast addresses have the LSb of the first address by set. Set a tag it multicast. */
+    if ((mess->chaddr[0] & 1) == 1)
+    {
+      multicast_id.net = "multicast";
+      multicast_id.next = netid;
+      netid = &multicast_id;
+    }
+  }
+
   /* check for DHCP rather than BOOTP */
   if ((opt = option_find(mess, sz, OPTION_MESSAGE_TYPE, 1)))
     {




More information about the Dnsmasq-discuss mailing list