[PATCH 4/5] Do not require ID_NET_NAME_MAC from udev

Daniel M. Weeks weeksd2 at rpi.edu
Fri Apr 17 04:02:30 AEST 2020


If ID_NET_NAME_MAC is not available for an interface, try to find the
hardware address of the interface. If a compatible address is found,
ready the interface.

Signed-off-by: Daniel M. Weeks <weeksd2 at rpi.edu>
---
 discover/udev.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/discover/udev.c b/discover/udev.c
index 470bbc3..8a32815 100644
--- a/discover/udev.c
+++ b/discover/udev.c
@@ -242,9 +242,11 @@ static int udev_check_interface_ready(struct device_handler *handler,
 		struct udev_device *dev)
 {
 	const char *name, *name_path, *ifindex, *interface, *mac_name;
-	uint8_t *mac;
+	uint8_t *mac, *hwaddr;
 	char byte[3];
 	unsigned int i, j;
+	int len;
+	int ret = -1;
 
 
 	name = udev_device_get_sysname(dev);
@@ -259,12 +261,36 @@ static int udev_check_interface_ready(struct device_handler *handler,
 	mac_name = udev_device_get_property_value(dev, "ID_NET_NAME_MAC");
 
 	/* Physical interfaces should have all of these properties */
-	if (!name_path || !ifindex || !interface || !mac_name) {
+	if (!ifindex || !interface) {
 		pb_debug("%s: interface %s missing properties\n",
 				__func__, name);
 		return -1;
 	}
 
+	if (!mac_name) {
+		pb_debug("%s: ready non-MAC interface %s\n",
+				__func__, name);
+
+		/* only try to get up to 8 bytes (IB GUID length) */
+		hwaddr = talloc_array(handler, uint8_t, MAX_HWADDR_SIZE);
+		if (!hwaddr)
+			return -1;
+
+		len = network_get_hwaddr(name, hwaddr, MAX_HWADDR_SIZE);
+		if (len < 0) {
+			pb_log("Unable to get hwaddr for %s\n", name);
+		} else if (len > MAX_HWADDR_SIZE) {
+			pb_log("hwaddr for %s too long\n", name);
+		} else {
+			pb_debug("Got %d byte hwaddr for %s\n", len, name);
+			network_mark_interface_ready(handler, atoi(ifindex),
+				interface, hwaddr, len);
+			ret = 0;
+		}
+		talloc_free(hwaddr);
+		return ret;
+	}
+
 	/* ID_NET_NAME_MAC format is enxMACADDR */
 	if (strlen(mac_name) < 15) {
 		pb_debug("%s: Unexpected MAC format: %s\n",
-- 
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