[PATCH 10/11] Use helper when comparing hardware addresses
Daniel M. Weeks
weeksd2 at rpi.edu
Fri Apr 17 03:56:15 AEST 2020
Since hwaddr fields may store hardware addresses of different lengths,
it's necessary to use hwaddr_cmp which will compare lengths before
comparing contents.
In some cases this was already done but the helper has been substituted
for consistency.
Signed-off-by: Daniel M. Weeks <weeksd2 at rpi.edu>
---
discover/network.c | 12 ++++++------
discover/sysinfo.c | 11 +++--------
ui/ncurses/nc-config.c | 5 +++--
3 files changed, 12 insertions(+), 16 deletions(-)
diff --git a/discover/network.c b/discover/network.c
index 8637fc8..a2a17e0 100644
--- a/discover/network.c
+++ b/discover/network.c
@@ -101,7 +101,7 @@ static const struct interface_config *find_config_by_hwaddr(
for (i = 0; i < config->network.n_interfaces; i++) {
struct interface_config *ifconf = config->network.interfaces[i];
- if (!memcmp(ifconf->hwaddr, hwaddr, HWADDR_SIZE))
+ if (!hwaddr_cmp(ifconf->hwaddr, ifconf->hwaddr_len, hwaddr, hwaddr_len))
return ifconf;
}
@@ -618,8 +618,8 @@ static int network_handle_nlmsg(struct network *network, struct nlmsghdr *nlmsg)
strncpy(interface->name, ifname, sizeof(interface->name) - 1);
list_for_each_entry(&network->interfaces, tmp, list)
- if (memcmp(interface->hwaddr, tmp->hwaddr,
- sizeof(interface->hwaddr)) == 0) {
+ if (hwaddr_cmp(interface->hwaddr, interface->hwaddr_len,
+ tmp->hwaddr, tmp->hwaddr_len) == 0) {
pb_log("%s: %s has duplicate MAC address, ignoring\n",
__func__, interface->name);
talloc_free(interface);
@@ -691,8 +691,8 @@ void network_mark_interface_ready(struct device_handler *handler,
strncpy(interface->name, ifname, sizeof(interface->name) - 1);
list_for_each_entry(&network->interfaces, tmp, list)
- if (memcmp(interface->hwaddr, tmp->hwaddr,
- sizeof(interface->hwaddr)) == 0) {
+ if (hwaddr_cmp(interface->hwaddr, interface->hwaddr_len,
+ tmp->hwaddr, tmp->hwaddr_len) == 0) {
pb_log("%s: %s has duplicate MAC address, ignoring\n",
__func__, interface->name);
talloc_free(interface);
@@ -716,7 +716,7 @@ void network_mark_interface_ready(struct device_handler *handler,
talloc_strdup(interface->dev->device, ifname);
}
- if (memcmp(interface->hwaddr, mac, hwsize) != 0) {
+ if (hwaddr_cmp(interface->hwaddr, interface->hwaddr_len, mac, hwsize) != 0) {
macstr = mac_bytes_to_string(interface, mac, hwsize);
pb_log("Warning - new MAC for interface %d does not match: %s\n",
ifindex, macstr);
diff --git a/discover/sysinfo.c b/discover/sysinfo.c
index 74d1eae..73012e8 100644
--- a/discover/sysinfo.c
+++ b/discover/sysinfo.c
@@ -5,6 +5,7 @@
#include <process/process.h>
#include <log/log.h>
+#include <util/util.h>
#include "discover-server.h"
#include "platform.h"
#include "sysinfo.h"
@@ -37,10 +38,7 @@ void system_info_set_interface_address(unsigned int hwaddr_size,
for (i = 0; i < sysinfo->n_interfaces; i++) {
if_info = sysinfo->interfaces[i];
- if (if_info->hwaddr_size != hwaddr_size)
- continue;
-
- if (memcmp(if_info->hwaddr, hwaddr, hwaddr_size))
+ if (hwaddr_cmp(if_info->hwaddr, if_info->hwaddr_size, hwaddr, hwaddr_size))
continue;
/* Found an existing interface. Notify clients if a new address
@@ -68,10 +66,7 @@ void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr,
if_info = sysinfo->interfaces[i];
- if (if_info->hwaddr_size != hwaddr_size)
- continue;
-
- if (memcmp(if_info->hwaddr, hwaddr, hwaddr_size))
+ if (hwaddr_cmp(if_info->hwaddr, if_info->hwaddr_size, hwaddr, hwaddr_size))
continue;
/* Found an existing interface. Notify clients on any name or
diff --git a/ui/ncurses/nc-config.c b/ui/ncurses/nc-config.c
index d72955e..4eb2499 100644
--- a/ui/ncurses/nc-config.c
+++ b/ui/ncurses/nc-config.c
@@ -29,6 +29,7 @@
#include <log/log.h>
#include <i18n/i18n.h>
+#include <util/util.h>
#include "nc-cui.h"
#include "nc-config.h"
#include "nc-widgets.h"
@@ -988,8 +989,8 @@ static void config_screen_setup_widgets(struct config_screen *screen,
char str[50], mac[20];
bool is_default;
- is_default = ifcfg && !memcmp(ifcfg->hwaddr, info->hwaddr,
- sizeof(ifcfg->hwaddr));
+ is_default = ifcfg && !hwaddr_cmp(ifcfg->hwaddr, ifcfg->hwaddr_len, info->hwaddr,
+ info->hwaddr_size);
mac_str(info->hwaddr, info->hwaddr_size, mac, sizeof(mac));
snprintf(str, sizeof(str), "%s [%s, %s]", info->name, mac,
--
Daniel M. Weeks
--
Daniel M. Weeks
Lead HPC Developer
Center for Computational Innovations
Rensselaer Polytechnic Institute
Troy, NY 12180
518-276-4458
More information about the Petitboot
mailing list