[PATCH 07/11] Set hwaddr_len field when hwaddr is set

Daniel M. Weeks weeksd2 at rpi.edu
Fri Apr 17 03:55:21 AEST 2020


The new hwaddr_len field should be set any time the hwaddr field is set
to indicate the true length of hwaddr. In the future, the buffer size
may not be indicative of the actual address length.

Signed-off-by: Daniel M. Weeks <weeksd2 at rpi.edu>
---
 discover/ipmi.c             | 1 +
 discover/network.c          | 1 +
 discover/platform-powerpc.c | 2 ++
 lib/pb-config/pb-config.c   | 1 +
 ui/ncurses/nc-config.c      | 1 +
 5 files changed, 6 insertions(+)

diff --git a/discover/ipmi.c b/discover/ipmi.c
index 32319fc..14a9e07 100644
--- a/discover/ipmi.c
+++ b/discover/ipmi.c
@@ -271,6 +271,7 @@ int parse_ipmi_interface_override(struct config *config, uint8_t *buf,
 
 	/* Hardware Address */
 	memcpy(ifconf->hwaddr, &buf[i], hwsize);
+	ifconf->hwaddr_len = hwsize;
 	i += hwsize;
 
 	/* Check 1-byte ignore and method flags */
diff --git a/discover/network.c b/discover/network.c
index 99f97b7..0433c70 100644
--- a/discover/network.c
+++ b/discover/network.c
@@ -686,6 +686,7 @@ void network_mark_interface_ready(struct device_handler *handler,
 		interface->ifindex = ifindex;
 		interface->state = IFSTATE_NEW;
 		memcpy(interface->hwaddr, mac, hwsize);
+		interface->hwaddr_len = hwsize;
 		strncpy(interface->name, ifname, sizeof(interface->name) - 1);
 
 		list_for_each_entry(&network->interfaces, tmp, list)
diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c
index 4c3c63a..be2fbab 100644
--- a/discover/platform-powerpc.c
+++ b/discover/platform-powerpc.c
@@ -266,6 +266,8 @@ static int parse_hwaddr(struct interface_config *ifconf, char *str)
 	if (strlen(str) != strlen("00:00:00:00:00:00"))
 		return -1;
 
+	ifconf->hwaddr_len = strlen(str) / 3 + 1;
+
 	for (i = 0; i < HWADDR_SIZE; i++) {
 		char byte[3], *endp;
 		unsigned long x;
diff --git a/lib/pb-config/pb-config.c b/lib/pb-config/pb-config.c
index 7fa925c..b21626f 100644
--- a/lib/pb-config/pb-config.c
+++ b/lib/pb-config/pb-config.c
@@ -14,6 +14,7 @@ static struct interface_config *config_copy_interface(struct config *ctx,
 						struct interface_config);
 
 	memcpy(dest->hwaddr, src->hwaddr, sizeof(src->hwaddr));
+	dest->hwaddr_len = src->hwaddr_len;
 	dest->ignore = src->ignore;
 
 	if (dest->ignore)
diff --git a/ui/ncurses/nc-config.c b/ui/ncurses/nc-config.c
index 5c0f23b..d72955e 100644
--- a/ui/ncurses/nc-config.c
+++ b/ui/ncurses/nc-config.c
@@ -278,6 +278,7 @@ static int screen_process_form(struct config_screen *screen)
 		idx = widget_select_get_value(screen->widgets.iface_f);
 		memcpy(iface->hwaddr, sysinfo->interfaces[idx]->hwaddr,
 				sizeof(iface->hwaddr));
+		iface->hwaddr_len = sysinfo->interfaces[idx]->hwaddr_size;
 	}
 
 	if (net_conf_type == NET_CONF_TYPE_DHCP_ONE) {
-- 
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