return 0;
}
-int ethtool_get_driver(int fd, const char *ifname, char **ret) {
+int ethtool_get_driver(int *fd, const char *ifname, char **ret) {
struct ethtool_drvinfo ecmd = {
.cmd = ETHTOOL_GDRVINFO
};
char *d;
int r;
+ if (*fd < 0) {
+ r = ethtool_connect(fd);
+ if (r < 0) {
+ log_warning("link_config: could not connect to ethtool: %s", strerror(-r));
+ return r;
+ }
+ }
+
strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
- r = ioctl(fd, SIOCETHTOOL, &ifr);
+ r = ioctl(*fd, SIOCETHTOOL, &ifr);
if (r < 0)
return -errno;
return 0;
}
-int ethtool_set_speed(int fd, const char *ifname, unsigned int speed, Duplex duplex)
+int ethtool_set_speed(int *fd, const char *ifname, unsigned int speed, Duplex duplex)
{
struct ethtool_cmd ecmd = {
.cmd = ETHTOOL_GSET
if (speed == 0 && duplex == _DUP_INVALID)
return 0;
+ if (*fd < 0) {
+ r = ethtool_connect(fd);
+ if (r < 0) {
+ log_warning("link_config: could not connect to ethtool: %s", strerror(-r));
+ return r;
+ }
+ }
+
strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
- r = ioctl(fd, SIOCETHTOOL, &ifr);
+ r = ioctl(*fd, SIOCETHTOOL, &ifr);
if (r < 0)
return -errno;
if (need_update) {
ecmd.cmd = ETHTOOL_SSET;
- r = ioctl(fd, SIOCETHTOOL, &ifr);
+ r = ioctl(*fd, SIOCETHTOOL, &ifr);
if (r < 0)
return -errno;
}
return 0;
}
-int ethtool_set_wol(int fd, const char *ifname, WakeOnLan wol) {
+int ethtool_set_wol(int *fd, const char *ifname, WakeOnLan wol) {
struct ethtool_wolinfo ecmd = {
.cmd = ETHTOOL_GWOL
};
if (wol == _WOL_INVALID)
return 0;
+ if (*fd < 0) {
+ r = ethtool_connect(fd);
+ if (r < 0) {
+ log_warning("link_config: could not connect to ethtool: %s", strerror(-r));
+ return r;
+ }
+ }
+
strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
- r = ioctl(fd, SIOCETHTOOL, &ifr);
+ r = ioctl(*fd, SIOCETHTOOL, &ifr);
if (r < 0)
return -errno;
if (need_update) {
ecmd.cmd = ETHTOOL_SWOL;
- r = ioctl(fd, SIOCETHTOOL, &ifr);
+ r = ioctl(*fd, SIOCETHTOOL, &ifr);
if (r < 0)
return -errno;
}