]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Look up interface packet was received on if inst->interface not set
authorNick Porter <nick@portercomputing.co.uk>
Tue, 17 Jun 2025 08:55:46 +0000 (09:55 +0100)
committerNick Porter <nick@portercomputing.co.uk>
Tue, 17 Jun 2025 08:55:46 +0000 (09:55 +0100)
Allows a DHCP server to be set to listen on 0.0.0.0 and not bound to a
specific interface to handle broadcast DHCP requests on multiple
interfaces.

src/listen/dhcpv4/proto_dhcpv4_udp.c

index 2743f5a4b80d0ee71c48e3b0d41bdcb422f7d03f..3f9a79d65df52b56859f22f819a104a57a166ac7 100644 (file)
@@ -411,6 +411,11 @@ static ssize_t mod_write(fr_listen_t *li, void *packet_ctx, UNUSED fr_time_t req
                         *      are broadcast.
                         */
                case FR_DHCP_OFFER:
+               {
+                       char if_name[IFNAMSIZ] = "";
+#ifdef WITH_IFINDEX_NAME_RESOLUTION
+                       if (!inst->interface && socket.inet.ifindex) fr_ifname_from_ifindex(if_name, socket.inet.ifindex);
+#endif
                        /*
                         *      If the packet was unicast from the
                         *      client, unicast it back without
@@ -426,7 +431,7 @@ static ssize_t mod_write(fr_listen_t *li, void *packet_ctx, UNUSED fr_time_t req
                                DEBUG("Reply will be unicast to YIADDR.");
 
 #ifdef SIOCSARP
-                       } else if (inst->broadcast && inst->interface) {
+                       } else if (inst->broadcast && (inst->interface || if_name[0])) {
                                uint8_t macaddr[6];
                                uint8_t ipaddr[4];
 
@@ -443,7 +448,7 @@ static ssize_t mod_write(fr_listen_t *li, void *packet_ctx, UNUSED fr_time_t req
                                 *      local ARP table and then
                                 *      unicast the reply.
                                 */
-                               if (fr_arp_entry_add(thread->sockfd, inst->interface, ipaddr, macaddr) == 0) {
+                               if (fr_arp_entry_add(thread->sockfd, inst->interface ? inst->interface : if_name, ipaddr, macaddr) == 0) {
                                        DEBUG("Reply will be unicast to YIADDR, done ARP table updates.");
                                        memcpy(&socket.inet.dst_ipaddr.addr.v4.s_addr, &packet->yiaddr, 4);
                                } else {
@@ -456,6 +461,7 @@ static ssize_t mod_write(fr_listen_t *li, void *packet_ctx, UNUSED fr_time_t req
                                DEBUG("Reply will be broadcast as we do not create raw UDP sockets.");
                                socket.inet.dst_ipaddr.addr.v4.s_addr = INADDR_BROADCAST;
                        }
+               }
                        break;
 
                        /*