Merge pull request #14523 from keszybz/refactorings

Refactorings inspired by recent pull requests
This commit is contained in:
Yu Watanabe 2020-01-09 12:50:11 +09:00 committed by GitHub
commit 125c7814fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 138 additions and 239 deletions

View File

@ -69,7 +69,13 @@
The following keys are accepted:</para>
<variablelist class='network-directives'>
<varlistentry>
<!-- This list is reused in systemd.network(3), hence maintain a specific order:
1. device matches shared between the two lists
2. non-shared settings
3. host matches shared between the two lists
-->
<varlistentry id='mac-address'>
<term><varname>MACAddress=</varname></term>
<listitem>
<para>A whitespace-separated list of hardware addresses. Use full colon-, hyphen- or dot-delimited hexadecimal. See the example below.
@ -80,7 +86,8 @@
<programlisting>MACAddress=01:23:45:67:89:ab 00-11-22-33-44-55 AABB.CCDD.EEFF</programlisting></para>
</listitem>
</varlistentry>
<varlistentry>
<varlistentry id='permanent-mac-address'>
<term><varname>PermanentMACAddress=</varname></term>
<listitem>
<para>A whitespace-separated list of hardware's permanent addresses. While
@ -91,18 +98,8 @@
of hardware addresses defined prior to this is reset.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>OriginalName=</varname></term>
<listitem>
<para>A whitespace-separated list of shell-style globs matching
the device name, as exposed by the udev property
"INTERFACE". This cannot be used to match on names that have
already been changed from userspace. Caution is advised when matching on
kernel-assigned names, as they are known to be unstable
between reboots.</para>
</listitem>
</varlistentry>
<varlistentry>
<varlistentry id='path'>
<term><varname>Path=</varname></term>
<listitem>
<para>A whitespace-separated list of shell-style globs matching
@ -110,23 +107,27 @@
<varname>ID_PATH</varname>.</para>
</listitem>
</varlistentry>
<varlistentry>
<varlistentry id='driver'>
<term><varname>Driver=</varname></term>
<listitem>
<para>A whitespace-separated list of shell-style globs matching the driver currently bound to the
device, as exposed by the udev property <varname>ID_NET_DRIVER</varname> of its parent device, or if that
is not set, the driver as exposed by <command>ethtool -i</command> of the device itself.</para>
device, as exposed by the udev property <varname>ID_NET_DRIVER</varname> of its parent device, or
if that is not set, the driver as exposed by <command>ethtool -i</command> of the device itself.
If the list is prefixed with a "!", the test is inverted.</para>
</listitem>
</varlistentry>
<varlistentry>
<varlistentry id='type'>
<term><varname>Type=</varname></term>
<listitem>
<para>A whitespace-separated list of shell-style globs matching
the device type, as exposed by the udev
property <varname>DEVTYPE</varname>.</para>
<para>A whitespace-separated list of shell-style globs matching the device type, as exposed by
the udev property <literal>DEVTYPE</literal>. If the list is prefixed with a "!", the test is
inverted.</para>
</listitem>
</varlistentry>
<varlistentry>
<varlistentry id='property'>
<term><varname>Property=</varname></term>
<listitem>
<para>A whitespace-separated list of udev property name with its value after a equal
@ -141,7 +142,18 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>OriginalName=</varname></term>
<listitem>
<para>A whitespace-separated list of shell-style globs matching the device name, as exposed by the
udev property "INTERFACE". This cannot be used to match on names that have already been changed
from userspace. Caution is advised when matching on kernel-assigned names, as they are known to be
unstable between reboots.</para>
</listitem>
</varlistentry>
<varlistentry id='host'>
<term><varname>Host=</varname></term>
<listitem>
<para>Matches against the hostname or machine ID of the host. See <varname>ConditionHost=</varname> in
@ -151,7 +163,8 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<varlistentry id='virtualization'>
<term><varname>Virtualization=</varname></term>
<listitem>
<para>Checks whether the system is executed in a virtualized environment and optionally test
@ -162,7 +175,8 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<varlistentry id='kernel-command-line'>
<term><varname>KernelCommandLine=</varname></term>
<listitem>
<para>Checks whether a specific kernel command line option is set. See
@ -173,7 +187,8 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<varlistentry id='kernel-version'>
<term><varname>KernelVersion=</varname></term>
<listitem>
<para>Checks whether the kernel version (as reported by <command>uname -r</command>) matches a certain
@ -184,7 +199,8 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<varlistentry id='architecture'>
<term><varname>Architecture=</varname></term>
<listitem>
<para>Checks whether the system is running on a specific architecture. See

View File

@ -3,7 +3,8 @@
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
<!-- SPDX-License-Identifier: LGPL-2.1+ -->
<refentry id="systemd.network" conditional='ENABLE_NETWORKD'>
<refentry id="systemd.network" conditional='ENABLE_NETWORKD'
xmlns:xi="http://www.w3.org/2001/XInclude">
<refentryinfo>
<title>systemd.network</title>
@ -86,60 +87,13 @@
The following keys are accepted:</para>
<variablelist class='network-directives'>
<varlistentry>
<term><varname>MACAddress=</varname></term>
<listitem>
<para>A whitespace-separated list of hardware addresses. Use full colon-, hyphen- or dot-delimited hexadecimal. See the example below.
This option may appear more than once, in which case the lists are merged. If the empty string is assigned to this option, the list
of hardware addresses defined prior to this is reset.</para>
<xi:include href="systemd.link.xml" xpointer="mac-address" />
<xi:include href="systemd.link.xml" xpointer="permanent-mac-address" />
<xi:include href="systemd.link.xml" xpointer="path" />
<xi:include href="systemd.link.xml" xpointer="driver" />
<xi:include href="systemd.link.xml" xpointer="type" />
<xi:include href="systemd.link.xml" xpointer="property" />
<para>Example:
<programlisting>MACAddress=01:23:45:67:89:ab 00-11-22-33-44-55 AABB.CCDD.EEFF</programlisting></para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>PermanentMACAddress=</varname></term>
<listitem>
<para>A whitespace-separated list of hardware's permanent addresses. While
<varname>MACAddress=</varname> matches the device's current MAC address, this matches the
device's permanent MAC address, which may be different from the current one. Use full
colon-, hyphen- or dot-delimited hexadecimal. This option may appear more than once, in
which case the lists are merged. If the empty string is assigned to this option, the list
of hardware addresses defined prior to this is reset.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>Path=</varname></term>
<listitem>
<para>A whitespace-separated list of shell-style globs
matching the persistent path, as exposed by the udev
property <literal>ID_PATH</literal>. If the list is
prefixed with a "!", the test is inverted; i.e. it is
true when <literal>ID_PATH</literal> does not match any
item in the list.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>Driver=</varname></term>
<listitem>
<para>A whitespace-separated list of shell-style globs
matching the driver currently bound to the device, as
exposed by the udev property <literal>ID_NET_DRIVER</literal>
of its parent device, or if that is not set the driver
as exposed by <literal>ethtool -i</literal> of the
device itself. If the list is prefixed with a "!", the
test is inverted.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>Type=</varname></term>
<listitem>
<para>A whitespace-separated list of shell-style globs
matching the device type, as exposed by the udev property
<literal>DEVTYPE</literal>. If the list is prefixed with
a "!", the test is inverted.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>Name=</varname></term>
<listitem>
@ -148,21 +102,7 @@
list is prefixed with a "!", the test is inverted.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>Property=</varname></term>
<listitem>
<para>A whitespace-separated list of udev property name with its value after a equal
(<literal>=</literal>). If multiple properties are specified, the test results are ANDed.
If the list is prefixed with a "!", the test is inverted. If a value contains white
spaces, then please quote whole key and value pair. If a value contains quotation, then
please escape the quotation with <literal>\</literal>.</para>
<para>Example: if a .network file has the following:
<programlisting>Property=ID_MODEL_ID=9999 "ID_VENDOR_FROM_DATABASE=vendor name" "KEY=with \"quotation\""</programlisting>
then, the .network file matches only when an interface has all the above three properties.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>WLANInterfaceType=</varname></term>
<listitem>
@ -175,6 +115,7 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>SSID=</varname></term>
<listitem>
@ -183,6 +124,7 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>BSSID=</varname></term>
<listitem>
@ -193,61 +135,12 @@
prior to this is reset.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>Host=</varname></term>
<listitem>
<para>Matches against the hostname or machine ID of the host. See
<literal>ConditionHost=</literal> in
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
for details. When prefixed with an exclamation mark (<literal>!</literal>), the result is negated.
If an empty string is assigned, then previously assigned value is cleared.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>Virtualization=</varname></term>
<listitem>
<para>Checks whether the system is executed in a virtualized environment and optionally test
whether it is a specific implementation. See <literal>ConditionVirtualization=</literal> in
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
for details. When prefixed with an exclamation mark (<literal>!</literal>), the result is negated.
If an empty string is assigned, then previously assigned value is cleared.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>KernelCommandLine=</varname></term>
<listitem>
<para>Checks whether a specific kernel command line option is set. See
<literal>ConditionKernelCommandLine=</literal> in
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
for details. When prefixed with an exclamation mark (<literal>!</literal>), the result is negated.
If an empty string is assigned, then previously assigned value is cleared.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>KernelVersion=</varname></term>
<listitem>
<para>Checks whether the kernel version (as reported by <command>uname -r</command>) matches a
certain expression. See <literal>ConditionKernelVersion=</literal> in
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
for details. When prefixed with an exclamation mark (<literal>!</literal>), the result is negated.
If an empty string is assigned, then previously assigned value is cleared.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>Architecture=</varname></term>
<listitem>
<para>Checks whether the system is running on a specific architecture. See
<literal>ConditionArchitecture=</literal> in
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
for details. When prefixed with an exclamation mark (<literal>!</literal>), the result is negated.
If an empty string is assigned, then previously assigned value is cleared.
</para>
</listitem>
</varlistentry>
<xi:include href="systemd.link.xml" xpointer="host" />
<xi:include href="systemd.link.xml" xpointer="virtualization" />
<xi:include href="systemd.link.xml" xpointer="kernel-command-line" />
<xi:include href="systemd.link.xml" xpointer="kernel-version" />
<xi:include href="systemd.link.xml" xpointer="architecture" />
</variablelist>
</refsect1>

View File

@ -391,22 +391,20 @@ static int source_io_register(
int enabled,
uint32_t events) {
struct epoll_event ev;
int r;
assert(s);
assert(s->type == SOURCE_IO);
assert(enabled != SD_EVENT_OFF);
ev = (struct epoll_event) {
struct epoll_event ev = {
.events = events | (enabled == SD_EVENT_ONESHOT ? EPOLLONESHOT : 0),
.data.ptr = s,
};
int r;
if (s->io.registered)
r = epoll_ctl(s->event->epoll_fd, EPOLL_CTL_MOD, s->io.fd, &ev);
else
r = epoll_ctl(s->event->epoll_fd, EPOLL_CTL_ADD, s->io.fd, &ev);
r = epoll_ctl(s->event->epoll_fd,
s->io.registered ? EPOLL_CTL_MOD : EPOLL_CTL_ADD,
s->io.fd,
&ev);
if (r < 0)
return -errno;
@ -441,9 +439,7 @@ static int source_child_pidfd_register(sd_event_source *s, int enabled) {
assert(enabled != SD_EVENT_OFF);
if (EVENT_SOURCE_WATCH_PIDFD(s)) {
struct epoll_event ev;
ev = (struct epoll_event) {
struct epoll_event ev = {
.events = EPOLLIN | (enabled == SD_EVENT_ONESHOT ? EPOLLONESHOT : 0),
.data.ptr = s,
};
@ -549,7 +545,6 @@ static int event_make_signal_data(
int sig,
struct signal_data **ret) {
struct epoll_event ev;
struct signal_data *d;
bool added = false;
sigset_t ss_copy;
@ -616,7 +611,7 @@ static int event_make_signal_data(
d->fd = fd_move_above_stdio(r);
ev = (struct epoll_event) {
struct epoll_event ev = {
.events = EPOLLIN,
.data.ptr = d,
};
@ -1042,33 +1037,31 @@ static int event_setup_timer_fd(
struct clock_data *d,
clockid_t clock) {
struct epoll_event ev;
int r, fd;
assert(e);
assert(d);
if (_likely_(d->fd >= 0))
return 0;
_cleanup_close_ int fd = -1;
int r;
fd = timerfd_create(clock, TFD_NONBLOCK|TFD_CLOEXEC);
if (fd < 0)
return -errno;
fd = fd_move_above_stdio(fd);
ev = (struct epoll_event) {
struct epoll_event ev = {
.events = EPOLLIN,
.data.ptr = d,
};
r = epoll_ctl(e->epoll_fd, EPOLL_CTL_ADD, fd, &ev);
if (r < 0) {
safe_close(fd);
if (r < 0)
return -errno;
}
d->fd = fd;
d->fd = TAKE_FD(fd);
return 0;
}
@ -1552,7 +1545,6 @@ static int event_make_inotify_data(
_cleanup_close_ int fd = -1;
struct inotify_data *d;
struct epoll_event ev;
int r;
assert(e);
@ -1591,7 +1583,7 @@ static int event_make_inotify_data(
return r;
}
ev = (struct epoll_event) {
struct epoll_event ev = {
.events = EPOLLIN,
.data.ptr = d,
};
@ -3844,8 +3836,6 @@ _public_ int sd_event_set_watchdog(sd_event *e, int b) {
return e->watchdog;
if (b) {
struct epoll_event ev;
r = sd_watchdog_enabled(false, &e->watchdog_period);
if (r <= 0)
return r;
@ -3862,7 +3852,7 @@ _public_ int sd_event_set_watchdog(sd_event *e, int b) {
if (r < 0)
goto fail;
ev = (struct epoll_event) {
struct epoll_event ev = {
.events = EPOLLIN,
.data.ptr = INT_TO_PTR(SOURCE_WATCHDOG),
};

View File

@ -324,9 +324,8 @@ static int decode_link(sd_netlink_message *m, LinkInfo *info, char **patterns) {
sd_netlink_message_read_ether_addr(m, IFLA_ADDRESS, &info->mac_address) >= 0 &&
memcmp(&info->mac_address, &ETHER_ADDR_NULL, sizeof(struct ether_addr)) != 0;
_cleanup_close_ int fd = -1;
info->has_permanent_mac_address =
ethtool_get_permanent_macaddr(&fd, info->name, &info->permanent_mac_address) >= 0 &&
ethtool_get_permanent_macaddr(NULL, info->name, &info->permanent_mac_address) >= 0 &&
memcmp(&info->permanent_mac_address, &ETHER_ADDR_NULL, sizeof(struct ether_addr)) != 0 &&
memcmp(&info->permanent_mac_address, &info->mac_address, sizeof(struct ether_addr)) != 0;

View File

@ -618,8 +618,7 @@ static int link_new(Manager *manager, sd_netlink_message *message, Link **ret) {
if (r < 0)
log_link_debug_errno(link, r, "MAC address not found for new device, continuing without");
_cleanup_close_ int fd = -1;
r = ethtool_get_permanent_macaddr(&fd, link->ifname, &link->permanent_mac);
r = ethtool_get_permanent_macaddr(NULL, link->ifname, &link->permanent_mac);
if (r < 0)
log_link_debug_errno(link, r, "Permanent MAC address not found for new device, continuing without: %m");

View File

@ -9,6 +9,7 @@
#include "conf-parser.h"
#include "ethtool-util.h"
#include "extract-word.h"
#include "fd-util.h"
#include "log.h"
#include "memory-util.h"
#include "socket-util.h"
@ -145,7 +146,7 @@ static int ethtool_connect_or_warn(int *ret, bool warn) {
return 0;
}
int ethtool_get_driver(int *fd, const char *ifname, char **ret) {
int ethtool_get_driver(int *ethtool_fd, const char *ifname, char **ret) {
struct ethtool_drvinfo ecmd = {
.cmd = ETHTOOL_GDRVINFO
};
@ -155,15 +156,15 @@ int ethtool_get_driver(int *fd, const char *ifname, char **ret) {
char *d;
int r;
if (*fd < 0) {
r = ethtool_connect_or_warn(fd, true);
if (*ethtool_fd < 0) {
r = ethtool_connect_or_warn(ethtool_fd, true);
if (r < 0)
return r;
}
strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
r = ioctl(*fd, SIOCETHTOOL, &ifr);
r = ioctl(*ethtool_fd, SIOCETHTOOL, &ifr);
if (r < 0)
return -errno;
@ -175,7 +176,7 @@ int ethtool_get_driver(int *fd, const char *ifname, char **ret) {
return 0;
}
int ethtool_get_link_info(int *fd, const char *ifname,
int ethtool_get_link_info(int *ethtool_fd, const char *ifname,
int *ret_autonegotiation, size_t *ret_speed,
Duplex *ret_duplex, NetDevPort *ret_port) {
struct ethtool_cmd ecmd = {
@ -186,15 +187,15 @@ int ethtool_get_link_info(int *fd, const char *ifname,
};
int r;
if (*fd < 0) {
r = ethtool_connect_or_warn(fd, false);
if (*ethtool_fd < 0) {
r = ethtool_connect_or_warn(ethtool_fd, false);
if (r < 0)
return r;
}
strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
r = ioctl(*fd, SIOCETHTOOL, &ifr);
r = ioctl(*ethtool_fd, SIOCETHTOOL, &ifr);
if (r < 0)
return -errno;
@ -218,47 +219,48 @@ int ethtool_get_link_info(int *fd, const char *ifname,
return 0;
}
int ethtool_get_permanent_macaddr(int *fd, const char *ifname, struct ether_addr *ret) {
_cleanup_free_ struct ethtool_perm_addr *epaddr = NULL;
struct ifreq ifr;
int ethtool_get_permanent_macaddr(int *ethtool_fd, const char *ifname, struct ether_addr *ret) {
_cleanup_close_ int fd = -1;
struct {
struct ethtool_perm_addr addr;
uint8_t space[MAX_ADDR_LEN];
} epaddr = {
.addr.cmd = ETHTOOL_GPERMADDR,
.addr.size = MAX_ADDR_LEN,
};
struct ifreq ifr = {
.ifr_data = (caddr_t) &epaddr,
};
int r;
assert(fd);
assert(ifname);
assert(ret);
if (*fd < 0) {
r = ethtool_connect_or_warn(fd, false);
if (!ethtool_fd)
ethtool_fd = &fd;
if (*ethtool_fd < 0) {
r = ethtool_connect_or_warn(ethtool_fd, false);
if (r < 0)
return r;
}
epaddr = malloc(offsetof(struct ethtool_perm_addr, data) + MAX_ADDR_LEN);
if (!epaddr)
return -ENOMEM;
epaddr->cmd = ETHTOOL_GPERMADDR;
epaddr->size = MAX_ADDR_LEN;
ifr = (struct ifreq) {
.ifr_data = (caddr_t) epaddr,
};
strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
r = ioctl(*fd, SIOCETHTOOL, &ifr);
r = ioctl(*ethtool_fd, SIOCETHTOOL, &ifr);
if (r < 0)
return -errno;
if (epaddr->size != 6)
if (epaddr.addr.size != 6)
return -EOPNOTSUPP;
for (size_t i = 0; i < epaddr->size; i++)
ret->ether_addr_octet[i] = epaddr->data[i];
for (size_t i = 0; i < epaddr.addr.size; i++)
ret->ether_addr_octet[i] = epaddr.addr.data[i];
return 0;
}
int ethtool_set_speed(int *fd, const char *ifname, unsigned speed, Duplex duplex) {
int ethtool_set_speed(int *ethtool_fd, const char *ifname, unsigned speed, Duplex duplex) {
struct ethtool_cmd ecmd = {
.cmd = ETHTOOL_GSET
};
@ -271,15 +273,15 @@ int ethtool_set_speed(int *fd, const char *ifname, unsigned speed, Duplex duplex
if (speed == 0 && duplex == _DUP_INVALID)
return 0;
if (*fd < 0) {
r = ethtool_connect_or_warn(fd, true);
if (*ethtool_fd < 0) {
r = ethtool_connect_or_warn(ethtool_fd, true);
if (r < 0)
return r;
}
strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
r = ioctl(*fd, SIOCETHTOOL, &ifr);
r = ioctl(*ethtool_fd, SIOCETHTOOL, &ifr);
if (r < 0)
return -errno;
@ -308,7 +310,7 @@ int ethtool_set_speed(int *fd, const char *ifname, unsigned speed, Duplex duplex
if (need_update) {
ecmd.cmd = ETHTOOL_SSET;
r = ioctl(*fd, SIOCETHTOOL, &ifr);
r = ioctl(*ethtool_fd, SIOCETHTOOL, &ifr);
if (r < 0)
return -errno;
}
@ -316,7 +318,7 @@ int ethtool_set_speed(int *fd, const char *ifname, unsigned speed, Duplex duplex
return 0;
}
int ethtool_set_wol(int *fd, const char *ifname, WakeOnLan wol) {
int ethtool_set_wol(int *ethtool_fd, const char *ifname, WakeOnLan wol) {
struct ethtool_wolinfo ecmd = {
.cmd = ETHTOOL_GWOL
};
@ -329,15 +331,15 @@ int ethtool_set_wol(int *fd, const char *ifname, WakeOnLan wol) {
if (wol == _WOL_INVALID)
return 0;
if (*fd < 0) {
r = ethtool_connect_or_warn(fd, true);
if (*ethtool_fd < 0) {
r = ethtool_connect_or_warn(ethtool_fd, true);
if (r < 0)
return r;
}
strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
r = ioctl(*fd, SIOCETHTOOL, &ifr);
r = ioctl(*ethtool_fd, SIOCETHTOOL, &ifr);
if (r < 0)
return -errno;
@ -397,7 +399,7 @@ int ethtool_set_wol(int *fd, const char *ifname, WakeOnLan wol) {
if (need_update) {
ecmd.cmd = ETHTOOL_SWOL;
r = ioctl(*fd, SIOCETHTOOL, &ifr);
r = ioctl(*ethtool_fd, SIOCETHTOOL, &ifr);
if (r < 0)
return -errno;
}
@ -405,7 +407,7 @@ int ethtool_set_wol(int *fd, const char *ifname, WakeOnLan wol) {
return 0;
}
int ethtool_set_nic_buffer_size(int *fd, const char *ifname, netdev_ring_param *ring) {
int ethtool_set_nic_buffer_size(int *ethtool_fd, const char *ifname, netdev_ring_param *ring) {
struct ethtool_ringparam ecmd = {
.cmd = ETHTOOL_GRINGPARAM
};
@ -415,15 +417,15 @@ int ethtool_set_nic_buffer_size(int *fd, const char *ifname, netdev_ring_param *
bool need_update = false;
int r;
if (*fd < 0) {
r = ethtool_connect_or_warn(fd, true);
if (*ethtool_fd < 0) {
r = ethtool_connect_or_warn(ethtool_fd, true);
if (r < 0)
return r;
}
strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
r = ioctl(*fd, SIOCETHTOOL, &ifr);
r = ioctl(*ethtool_fd, SIOCETHTOOL, &ifr);
if (r < 0)
return -errno;
@ -444,7 +446,7 @@ int ethtool_set_nic_buffer_size(int *fd, const char *ifname, netdev_ring_param *
if (need_update) {
ecmd.cmd = ETHTOOL_SRINGPARAM;
r = ioctl(*fd, SIOCETHTOOL, &ifr);
r = ioctl(*ethtool_fd, SIOCETHTOOL, &ifr);
if (r < 0)
return -errno;
}
@ -452,7 +454,7 @@ int ethtool_set_nic_buffer_size(int *fd, const char *ifname, netdev_ring_param *
return 0;
}
static int get_stringset(int fd, struct ifreq *ifr, int stringset_id, struct ethtool_gstrings **gstrings) {
static int get_stringset(int ethtool_fd, struct ifreq *ifr, int stringset_id, struct ethtool_gstrings **gstrings) {
_cleanup_free_ struct ethtool_gstrings *strings = NULL;
struct {
struct ethtool_sset_info info;
@ -468,7 +470,7 @@ static int get_stringset(int fd, struct ifreq *ifr, int stringset_id, struct eth
ifr->ifr_data = (void *) &buffer.info;
r = ioctl(fd, SIOCETHTOOL, ifr);
r = ioctl(ethtool_fd, SIOCETHTOOL, ifr);
if (r < 0)
return -errno;
@ -487,7 +489,7 @@ static int get_stringset(int fd, struct ifreq *ifr, int stringset_id, struct eth
ifr->ifr_data = (void *) strings;
r = ioctl(fd, SIOCETHTOOL, ifr);
r = ioctl(ethtool_fd, SIOCETHTOOL, ifr);
if (r < 0)
return -errno;
@ -507,21 +509,21 @@ static int find_feature_index(struct ethtool_gstrings *strings, const char *feat
return -ENODATA;
}
int ethtool_set_features(int *fd, const char *ifname, int *features) {
int ethtool_set_features(int *ethtool_fd, const char *ifname, int *features) {
_cleanup_free_ struct ethtool_gstrings *strings = NULL;
struct ethtool_sfeatures *sfeatures;
int block, bit, i, r;
struct ifreq ifr = {};
if (*fd < 0) {
r = ethtool_connect_or_warn(fd, true);
if (*ethtool_fd < 0) {
r = ethtool_connect_or_warn(ethtool_fd, true);
if (r < 0)
return r;
}
strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
r = get_stringset(*fd, &ifr, ETH_SS_FEATURES, &strings);
r = get_stringset(*ethtool_fd, &ifr, ETH_SS_FEATURES, &strings);
if (r < 0)
return log_warning_errno(r, "ethtool: could not get ethtool features for %s", ifname);
@ -553,7 +555,7 @@ int ethtool_set_features(int *fd, const char *ifname, int *features) {
ifr.ifr_data = (void *) sfeatures;
r = ioctl(*fd, SIOCETHTOOL, &ifr);
r = ioctl(*ethtool_fd, SIOCETHTOOL, &ifr);
if (r < 0)
return log_warning_errno(r, "ethtool: could not set ethtool features for %s", ifname);

View File

@ -88,19 +88,19 @@ typedef struct netdev_ring_param {
bool tx_pending_set;
} netdev_ring_param;
int ethtool_get_driver(int *fd, const char *ifname, char **ret);
int ethtool_get_link_info(int *fd, const char *ifname,
int ethtool_get_driver(int *ethtool_fd, const char *ifname, char **ret);
int ethtool_get_link_info(int *ethtool_fd, const char *ifname,
int *ret_autonegotiation, size_t *ret_speed,
Duplex *ret_duplex, NetDevPort *ret_port);
int ethtool_get_permanent_macaddr(int *fd, const char *ifname, struct ether_addr *ret);
int ethtool_set_speed(int *fd, const char *ifname, unsigned speed, Duplex duplex);
int ethtool_set_wol(int *fd, const char *ifname, WakeOnLan wol);
int ethtool_set_nic_buffer_size(int *fd, const char *ifname, netdev_ring_param *ring);
int ethtool_set_features(int *fd, const char *ifname, int *features);
int ethtool_set_glinksettings(int *fd, const char *ifname,
int ethtool_get_permanent_macaddr(int *ethtool_fd, const char *ifname, struct ether_addr *ret);
int ethtool_set_speed(int *ethtool_fd, const char *ifname, unsigned speed, Duplex duplex);
int ethtool_set_wol(int *ethtool_fd, const char *ifname, WakeOnLan wol);
int ethtool_set_nic_buffer_size(int *ethtool_fd, const char *ifname, netdev_ring_param *ring);
int ethtool_set_features(int *ethtool_fd, const char *ifname, int *features);
int ethtool_set_glinksettings(int *ethtool_fd, const char *ifname,
int autonegotiation, uint32_t advertise[static N_ADVERTISE],
size_t speed, Duplex duplex, NetDevPort port);
int ethtool_set_channels(int *fd, const char *ifname, netdev_channels *channels);
int ethtool_set_channels(int *ethtool_fd, const char *ifname, netdev_channels *channels);
const char *duplex_to_string(Duplex d) _const_;
Duplex duplex_from_string(const char *d) _pure_;