提交 edc88e20 编写于 作者: J John Ferlan

virnetdev: Use virNetDevSetupControl in virNetDevSendEthtoolIoctl

Use virNetDevSetupControl instead of open coding using socket(AF_LOCAL...)
and clearing virIfreq.

By using virNetDevSetupControl, the socket is then opened using
AF_PACKET which requires being privileged (effectively root) in
order to complete successfully.  Since that's now a requirement,
then the ioctl(SIOCETHTOOL) should not fail with EPERM, thus it
is removed from the filtered listed of failure codes.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
上级 d0a3a1ff
...@@ -3151,24 +3151,19 @@ static int ...@@ -3151,24 +3151,19 @@ static int
virNetDevSendEthtoolIoctl(const char *ifname, void *cmd) virNetDevSendEthtoolIoctl(const char *ifname, void *cmd)
{ {
int ret = -1; int ret = -1;
int sock = -1; int fd = -1;
virIfreq ifr; struct ifreq ifr;
sock = socket(AF_LOCAL, SOCK_DGRAM, 0); /* Ultimately uses AF_PACKET for socket which requires privileged
if (sock < 0) { * daemon support.
virReportSystemError(errno, "%s", _("Cannot open control socket")); */
goto cleanup; if ((fd = virNetDevSetupControl(ifname, &ifr)) < 0)
} return ret;
memset(&ifr, 0, sizeof(ifr));
strcpy(ifr.ifr_name, ifname);
ifr.ifr_data = cmd; ifr.ifr_data = cmd;
ret = ioctl(sock, SIOCETHTOOL, &ifr); ret = ioctl(fd, SIOCETHTOOL, &ifr);
if (ret != 0) { if (ret != 0) {
switch (errno) { switch (errno) {
case EPERM: /* attempt to call SIOCETHTOOL from unprivileged code */
VIR_DEBUG("ethtool ioctl: permission denied");
break;
case EINVAL: /* kernel doesn't support SIOCETHTOOL */ case EINVAL: /* kernel doesn't support SIOCETHTOOL */
VIR_DEBUG("ethtool ioctl: invalid request"); VIR_DEBUG("ethtool ioctl: invalid request");
break; break;
...@@ -3182,8 +3177,7 @@ virNetDevSendEthtoolIoctl(const char *ifname, void *cmd) ...@@ -3182,8 +3177,7 @@ virNetDevSendEthtoolIoctl(const char *ifname, void *cmd)
} }
cleanup: cleanup:
if (sock) VIR_FORCE_CLOSE(fd);
VIR_FORCE_CLOSE(sock);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册