From 908ea5f3a45a050a878de16d5acde6eda1b77d9f Mon Sep 17 00:00:00 2001 From: Pavel Zhukov Date: Thu, 21 Feb 2019 10:42:50 +0100 Subject: [PATCH 20/28] Discover all hwaddress for xid uniqueness --- common/discover.c | 2 ++ common/lpf.c | 27 ++++++++++++++++++++++----- includes/dhcpd.h | 3 +++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/common/discover.c b/common/discover.c index b4b1959..96dcdcf 100644 --- a/common/discover.c +++ b/common/discover.c @@ -653,6 +653,8 @@ discover_interfaces(int state) { interface_dereference(&tmp, MDL); tmp = interfaces; /* XXX */ } + if (tmp != NULL) + try_hw_addr(tmp); if (dhcp_interface_discovery_hook) { (*dhcp_interface_discovery_hook)(tmp); diff --git a/common/lpf.c b/common/lpf.c index fcaa13d..77a5668 100644 --- a/common/lpf.c +++ b/common/lpf.c @@ -713,8 +713,22 @@ ioctl_get_ll(char *name) return sll; } +// define ? +void try_hw_addr(struct interface_info *info){ + get_hw_addr2(info); +}; + void get_hw_addr(struct interface_info *info) +{ + if (get_hw_addr2(info) == ISC_R_NOTFOUND){ + log_fatal("Unsupported device type for \"%s\"", + info->name); + } +} + +isc_result_t +get_hw_addr2(struct interface_info *info) { struct hardware *hw = &info->hw_address; char *name = info->name; @@ -724,7 +738,8 @@ get_hw_addr(struct interface_info *info) int sll_allocated = 0; char *dup = NULL; char *colon = NULL; - + isc_result_t result = ISC_R_SUCCESS; + if (getifaddrs(&ifaddrs) == -1) log_fatal("Failed to get interfaces"); @@ -808,14 +823,16 @@ get_hw_addr(struct interface_info *info) hw->hbuf[4] = 0xef; break; #endif - default: - freeifaddrs(ifaddrs); - log_fatal("Unsupported device type %hu for \"%s\"", - sll->sll_hatype, name); + default: + log_error("Unsupported device type %hu for \"%s\"", + sll->sll_hatype, name); + result = ISC_R_NOTFOUND; + } if (sll_allocated) dfree(sll, MDL); freeifaddrs(ifaddrs); + return result; } #endif diff --git a/includes/dhcpd.h b/includes/dhcpd.h index e9e52e7..fabad01 100644 --- a/includes/dhcpd.h +++ b/includes/dhcpd.h @@ -2653,7 +2653,10 @@ void print_dns_status (int, struct dhcp_ddns_cb *, isc_result_t); #endif const char *print_time(TIME); + void get_hw_addr(struct interface_info *info); +void try_hw_addr(struct interface_info *info); +isc_result_t get_hw_addr2(struct interface_info *info); char *buf_to_hex (const unsigned char *s, unsigned len, const char *file, int line); char *format_lease_id(const unsigned char *s, unsigned len, int format, -- 2.35.1