Thread (9 messages) 9 messages, 5 authors, 2021-01-17

Re: [dpdk-dev] [PATCH v2 2/2] net/netvsc: support VF device hot add/remove

From: Long Li <longli@microsoft.com>
Date: 2021-01-06 02:51:07

Subject: Re: [dpdk-dev] [PATCH v2 2/2] net/netvsc: support VF device hot
add/remove

On Mon, 21 Dec 2020 13:33:22 -0800
Long Li [off-list ref] wrote:
quoted
	/* trying to get mac address if this is a network device*/
+		s = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
+		if (s == -1) {
+			PMD_DRV_LOG(ERR, "Failed to create socket
errno %d\n",
quoted
+				    errno);
+			break;
+		}
+		strlcpy(req.ifr_name, dir->d_name, sizeof(req.ifr_name));
+		ret = ioctl(s, SIOCGIFHWADDR, &req);
+		close(s);
+		if (ret == -1) {
+			PMD_DRV_LOG(ERR, "Failed to send
SIOCGIFHWADDR for "
quoted
+				    "device %s\n", dir->d_name);
+			break;
+		}
+		if (req.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
+			closedir(di);
+			return;
+		}
You have sysfs directory open at this point, would it be easier to continue
with sysfs to find the mac address?

		snprintf(ifpath, sizeof(ifpath), "%s/address", dir->d_name);
		fd = openat(dirfd(di), ifpath, O_RDONLY);
		read(fd...)
I think sending SIOCGIFHWADDR through socket is safer. This is the same as vdev_netvsc does. If the network hardware is not ethernet, reading the address directly from sysfs may require some additional parsing.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help