]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
Fix for interface detection when no IPv4 addresses available.
authorShane Kerr <shane@isc.org>
Tue, 14 Aug 2007 14:08:16 +0000 (14:08 +0000)
committerShane Kerr <shane@isc.org>
Tue, 14 Aug 2007 14:08:16 +0000 (14:08 +0000)
See RT ticket #17086 for more.

RELNOTES
common/discover.c

index 650224676f18e729204910b13f2e47e696c04b8b..3e88863e737068ac3c90a253e7edfad6936b9eed 100644 (file)
--- a/RELNOTES
+++ b/RELNOTES
@@ -53,6 +53,9 @@ suggested fixes to <dhcp-users@isc.org>.
 
                        Changes since 4.0.0a2
 
+- Fix for startup where there are no IPv4 addresses on an interface.
+  Thanks to Marcus Goller for reporting the bug.
+
 - Fixed file descriptor leak on listen failure. Thanks to Tom Clark.
 
 - Bug in server configuration parser caused server to get stuck on
index 362280bb3afdd253e781d62660a77c2eff4e9d05..c2488dc7b19635039d5cba8477ca26335041c29d 100644 (file)
@@ -233,7 +233,7 @@ begin_iface_scan(struct iface_conf_list *ifaces) {
        int lifnum;
 #endif
 
-       ifaces->sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+       ifaces->sock = socket(local_family, SOCK_DGRAM, IPPROTO_UDP);
        if (ifaces->sock < 0) {
                log_error("Error creating socket to list interfaces; %m");
                return 0;
@@ -1152,12 +1152,24 @@ discover_interfaces(int state) {
                               ? tmp -> shared_network -> subnets
                               : (struct subnet *)0);
                     subnet; subnet = subnet -> next_sibling) {
-                       if (!subnet -> interface_address.len) {
-                               /* Set the interface address for this subnet
-                                  to the first address we found. */
-                               subnet -> interface_address.len = 4;
-                               memcpy (subnet -> interface_address.iabuf,
-                                       &tmp->addresses[0].s_addr, 4);
+                       /* Set the interface address for this subnet
+                          to the first address we found. */
+                       if (subnet->interface_address.len == 0) {
+                               if (tmp->address_count > 0) {
+                                       subnet->interface_address.len = 4;
+                                       memcpy(subnet->interface_address.iabuf,
+                                              &tmp->addresses[0].s_addr, 4);
+                               } else if (tmp->v6address_count > 0) {
+                                       subnet->interface_address.len = 16;
+                                       memcpy(subnet->interface_address.iabuf,
+                                              &tmp->v6addresses[0].s6_addr, 
+                                              16);
+                               } else {
+                                       /* XXX: should be one */
+                                       log_error("%s missing an interface "
+                                                 "address", tmp->name);
+                                       continue;
+                               }
                        }
                }