DEFINE_STRING_TABLE_LOOKUP(ethtool_link_mode_bit, enum ethtool_link_mode_bit_indices);
-static int ethtool_connect(int *ret) {
+static int ethtool_connect(int *ethtool_fd) {
int fd;
- assert_return(ret, -EINVAL);
+ assert(ethtool_fd);
+
+ /* This does nothing if already connected. */
+ if (*ethtool_fd >= 0)
+ return 0;
fd = socket_ioctl_fd();
if (fd < 0)
return log_debug_errno(fd, "ethtool: could not create control socket: %m");
- *ret = fd;
-
+ *ethtool_fd = fd;
return 0;
}
assert(ifname);
assert(ret);
- if (*ethtool_fd < 0) {
- r = ethtool_connect(ethtool_fd);
- if (r < 0)
- return r;
- }
+ r = ethtool_connect(ethtool_fd);
+ if (r < 0)
+ return r;
strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
assert(ethtool_fd);
assert(ifname);
- if (*ethtool_fd < 0) {
- r = ethtool_connect(ethtool_fd);
- if (r < 0)
- return r;
- }
+ r = ethtool_connect(ethtool_fd);
+ if (r < 0)
+ return r;
strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
if (!ethtool_fd)
ethtool_fd = &fd;
-
- if (*ethtool_fd < 0) {
- r = ethtool_connect(ethtool_fd);
- if (r < 0)
- return r;
- }
+ r = ethtool_connect(ethtool_fd);
+ if (r < 0)
+ return r;
strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
if (speed == 0 && duplex == _DUP_INVALID)
return 0;
- if (*ethtool_fd < 0) {
- r = ethtool_connect(ethtool_fd);
- if (r < 0)
- return r;
- }
+ r = ethtool_connect(ethtool_fd);
+ if (r < 0)
+ return r;
strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
if (wol == _WOL_INVALID)
return 0;
- if (*ethtool_fd < 0) {
- r = ethtool_connect(ethtool_fd);
- if (r < 0)
- return r;
- }
+ r = ethtool_connect(ethtool_fd);
+ if (r < 0)
+ return r;
strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
assert(ifname);
assert(ring);
- if (*ethtool_fd < 0) {
- r = ethtool_connect(ethtool_fd);
- if (r < 0)
- return r;
- }
+ r = ethtool_connect(ethtool_fd);
+ if (r < 0)
+ return r;
strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
assert(ifname);
assert(features);
- if (*ethtool_fd < 0) {
- r = ethtool_connect(ethtool_fd);
- if (r < 0)
- return r;
- }
+ r = ethtool_connect(ethtool_fd);
+ if (r < 0)
+ return r;
strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
return 0;
}
- if (*fd < 0) {
- r = ethtool_connect(fd);
- if (r < 0)
- return r;
- }
+ r = ethtool_connect(fd);
+ if (r < 0)
+ return r;
strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
assert(ifname);
assert(channels);
- if (*fd < 0) {
- r = ethtool_connect(fd);
- if (r < 0)
- return r;
- }
+ r = ethtool_connect(fd);
+ if (r < 0)
+ return r;
strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
assert(fd);
assert(ifname);
- if (*fd < 0) {
- r = ethtool_connect(fd);
- if (r < 0)
- return r;
- }
+ r = ethtool_connect(fd);
+ if (r < 0)
+ return r;
strscpy(ifr.ifr_name, IFNAMSIZ, ifname);