Set src IP on more situations.
authorAlan T. DeKok <aland@freeradius.org>
Thu, 13 Mar 2014 15:18:08 +0000 (11:18 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 13 Mar 2014 15:18:08 +0000 (11:18 -0400)
If the admin set "ipaddr = *", and no "src_ipaddr = ...", then
we used to send packets from 0.0.0.0.  That's wrong.

We now look for server identifier or server IP address.
If one of those is found, we use that as the source IP

src/main/dhcpd.c

index 57ff913..14f5ee7 100644 (file)
@@ -408,6 +408,19 @@ static int dhcp_process(REQUEST *request)
        request->reply->src_ipaddr.af = AF_INET;
        request->reply->src_ipaddr.ipaddr.ip4addr.s_addr = sock->src_ipaddr.ipaddr.ip4addr.s_addr;
 
+       /*
+        *      They didn't set a proper src_ipaddr, but we want to
+        *      send the packet with a source IP.  If there's a server
+        *      identifier, use it.
+        */
+       if (request->reply->src_ipaddr.ipaddr.ip4addr.s_addr == INADDR_ANY) {
+               vp = pairfind(request->reply->vps, DHCP2ATTR(265)); /* DHCP-Server-IP-Address */
+               if (!vp) vp = pairfind(request->reply->vps, DHCP2ATTR(54)); /* DHCP-DHCP-Server-Identifier */
+               if (vp) {
+                       request->reply->src_ipaddr.ipaddr.ip4addr.s_addr = vp->vp_ipaddr;
+               }
+       }
+
        request->reply->dst_port = request->packet->src_port;
        request->reply->src_port = request->packet->dst_port;