]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
link : add support to configure Offload features (#4017)
authorSusant Sahani <ssahani@users.noreply.github.com>
Tue, 30 Aug 2016 14:52:04 +0000 (20:22 +0530)
committerLennart Poettering <lennart@poettering.net>
Tue, 30 Aug 2016 14:52:04 +0000 (16:52 +0200)
This patch supports these features to be on or off

Generic Segmentation Offload
TCP Segmentation Offload
UDP Segmentation Offload

fixes #432

man/systemd.link.xml
src/udev/net/ethtool-util.c
src/udev/net/ethtool-util.h
src/udev/net/link-config-gperf.gperf
src/udev/net/link-config.c
src/udev/net/link-config.h

index d5b4d1038d245ac3589de2f5b608b33c8866ca6e..313e4a4aa3b61ef5363954b7287d477926722d58 100644 (file)
           </variablelist>
         </listitem>
       </varlistentry>
+      <varlistentry>
+        <term><varname>TCPSegmentationOffload=</varname></term>
+        <listitem>
+          <para>The TCP Segmentation Offload (TSO) when true enables
+          TCP segmentation offload. Takes a boolean value.
+          Defaults to "unset".</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><varname>GenericSegmentationOffload=</varname></term>
+        <listitem>
+          <para>The Generic Segmentation Offload (GSO) when true enables
+          generic segmentation offload. Takes a boolean value.
+          Defaults to "unset".</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><varname>UDPSegmentationOffload=</varname></term>
+        <listitem>
+          <para>The UDP Segmentation Offload (USO) when true enables
+          UDP segmentation offload. Takes a boolean value.
+          Defaults to "unset".</para>
+        </listitem>
+      </varlistentry>
     </variablelist>
   </refsect1>
 
index c00ff79123d6d400b831968c3b98bca8952c4f52..5143eb5a9d40b6a74f3b15c5d71f7fa6bf75f16f 100644 (file)
@@ -46,6 +46,12 @@ static const char* const wol_table[_WOL_MAX] = {
 DEFINE_STRING_TABLE_LOOKUP(wol, WakeOnLan);
 DEFINE_CONFIG_PARSE_ENUM(config_parse_wol, wol, WakeOnLan, "Failed to parse WakeOnLan setting");
 
+static const char* const netdev_feature_table[_NET_DEV_FEAT_MAX] = {
+        [NET_DEV_FEAT_GSO] = "tx-generic-segmentation",
+        [NET_DEV_FEAT_TSO] = "tx-tcp-segmentation",
+        [NET_DEV_FEAT_UFO] = "tx-udp-fragmentation",
+};
+
 int ethtool_connect(int *ret) {
         int fd;
 
@@ -206,3 +212,108 @@ int ethtool_set_wol(int *fd, const char *ifname, WakeOnLan wol) {
 
         return 0;
 }
+
+static int ethtool_get_stringset(int *fd, struct ifreq *ifr, int stringset_id, struct ethtool_gstrings **gstrings) {
+        _cleanup_free_ struct ethtool_gstrings *strings = NULL;
+        struct ethtool_sset_info info =  {
+                .cmd = ETHTOOL_GSSET_INFO,
+                .reserved = 0,
+                .sset_mask = 1ULL << stringset_id,
+        };
+        unsigned len;
+        int r;
+
+        ifr->ifr_data = (void *) &info;
+
+        r = ioctl(*fd, SIOCETHTOOL, ifr);
+        if (r < 0)
+                return -errno;
+
+        if (!info.sset_mask)
+                return -EINVAL;
+
+        len = info.data[0];
+
+        strings = malloc0(sizeof(struct ethtool_gstrings) + len * ETH_GSTRING_LEN);
+        if (!strings)
+                return -ENOMEM;
+
+        strings->cmd = ETHTOOL_GSTRINGS;
+        strings->string_set = stringset_id;
+        strings->len = len;
+
+        ifr->ifr_data = (void *) strings;
+
+        r = ioctl(*fd, SIOCETHTOOL, ifr);
+        if (r < 0)
+                return -errno;
+
+        *gstrings = strings;
+        strings = NULL;
+
+        return 0;
+}
+
+static int find_feature_index(struct ethtool_gstrings *strings, const char *feature) {
+        unsigned i;
+
+        for (i = 0; i < strings->len; i++) {
+                if (streq((char *) &strings->data[i * ETH_GSTRING_LEN], feature))
+                        return i;
+        }
+
+        return -1;
+}
+
+int ethtool_set_features(int *fd, const char *ifname, NetDevFeature *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(fd);
+                if (r < 0)
+                        return log_warning_errno(r, "link_config: could not connect to ethtool: %m");
+        }
+
+        strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
+
+        r = ethtool_get_stringset(fd, &ifr, ETH_SS_FEATURES, &strings);
+        if (r < 0)
+                return log_warning_errno(r, "link_config: could not get ethtool features for %s", ifname);
+
+        sfeatures = alloca0(sizeof(struct ethtool_gstrings) + DIV_ROUND_UP(strings->len, 32U) * sizeof(sfeatures->features[0]));
+        sfeatures->cmd = ETHTOOL_SFEATURES;
+        sfeatures->size = DIV_ROUND_UP(strings->len, 32U);
+
+        for (i = 0; i < _NET_DEV_FEAT_MAX; i++) {
+
+                if (features[i] != -1) {
+
+                        r = find_feature_index(strings, netdev_feature_table[i]);
+                        if (r < 0) {
+                                log_warning_errno(r, "link_config: could not find feature: %s", netdev_feature_table[i]);
+                                continue;
+                        }
+
+                        block = r / 32;
+                        bit = r % 32;
+
+                        sfeatures->features[block].valid |= 1 << bit;
+
+                        if (features[i])
+                                sfeatures->features[block].requested |= 1 << bit;
+                        else
+                                sfeatures->features[block].requested &= ~(1 << bit);
+                }
+        }
+
+        ifr.ifr_data = (void *) sfeatures;
+
+        r = ioctl(*fd, SIOCETHTOOL, &ifr);
+        if (r < 0)
+                return log_warning_errno(r, "link_config: could not set ethtool features for %s", ifname);
+
+        return 0;
+}
index 7716516e7656ede13bd815e17a7455891660bee8..2b5b9fbd1a2f05c2b8d4b878bf2848b88b03647e 100644 (file)
@@ -38,11 +38,20 @@ typedef enum WakeOnLan {
         _WOL_INVALID = -1
 } WakeOnLan;
 
+typedef enum NetDevFeature {
+        NET_DEV_FEAT_GSO,
+        NET_DEV_FEAT_TSO,
+        NET_DEV_FEAT_UFO,
+        _NET_DEV_FEAT_MAX,
+        _NET_DEV_FEAT_INVALID = -1
+} NetDevFeature;
+
 int ethtool_connect(int *ret);
 
 int ethtool_get_driver(int *fd, const char *ifname, char **ret);
 int ethtool_set_speed(int *fd, const char *ifname, unsigned int speed, Duplex duplex);
 int ethtool_set_wol(int *fd, const char *ifname, WakeOnLan wol);
+int ethtool_set_features(int *fd, const char *ifname, NetDevFeature *features);
 
 const char *duplex_to_string(Duplex d) _const_;
 Duplex duplex_from_string(const char *d) _pure_;
index b25e4b3344ee559cc3f94c27501edf3308ce45eb..5c57a0cb94a7361cf87e03501e993690f0291215 100644 (file)
@@ -16,22 +16,25 @@ struct ConfigPerfItem;
 %struct-type
 %includes
 %%
-Match.MACAddress,          config_parse_hwaddr,        0,                             offsetof(link_config, match_mac)
-Match.OriginalName,        config_parse_ifnames,       0,                             offsetof(link_config, match_name)
-Match.Path,                config_parse_strv,          0,                             offsetof(link_config, match_path)
-Match.Driver,              config_parse_strv,          0,                             offsetof(link_config, match_driver)
-Match.Type,                config_parse_strv,          0,                             offsetof(link_config, match_type)
-Match.Host,                config_parse_net_condition, CONDITION_HOST,                offsetof(link_config, match_host)
-Match.Virtualization,      config_parse_net_condition, CONDITION_VIRTUALIZATION,      offsetof(link_config, match_virt)
-Match.KernelCommandLine,   config_parse_net_condition, CONDITION_KERNEL_COMMAND_LINE, offsetof(link_config, match_kernel)
-Match.Architecture,        config_parse_net_condition, CONDITION_ARCHITECTURE,        offsetof(link_config, match_arch)
-Link.Description,          config_parse_string,        0,                             offsetof(link_config, description)
-Link.MACAddressPolicy,     config_parse_mac_policy,    0,                             offsetof(link_config, mac_policy)
-Link.MACAddress,           config_parse_hwaddr,        0,                             offsetof(link_config, mac)
-Link.NamePolicy,           config_parse_name_policy,   0,                             offsetof(link_config, name_policy)
-Link.Name,                 config_parse_ifname,        0,                             offsetof(link_config, name)
-Link.Alias,                config_parse_ifalias,       0,                             offsetof(link_config, alias)
-Link.MTUBytes,             config_parse_iec_size,      0,                             offsetof(link_config, mtu)
-Link.BitsPerSecond,        config_parse_si_size,       0,                             offsetof(link_config, speed)
-Link.Duplex,               config_parse_duplex,        0,                             offsetof(link_config, duplex)
-Link.WakeOnLan,            config_parse_wol,           0,                             offsetof(link_config, wol)
+Match.MACAddress,                config_parse_hwaddr,        0,                             offsetof(link_config, match_mac)
+Match.OriginalName,              config_parse_ifnames,       0,                             offsetof(link_config, match_name)
+Match.Path,                      config_parse_strv,          0,                             offsetof(link_config, match_path)
+Match.Driver,                    config_parse_strv,          0,                             offsetof(link_config, match_driver)
+Match.Type,                      config_parse_strv,          0,                             offsetof(link_config, match_type)
+Match.Host,                      config_parse_net_condition, CONDITION_HOST,                offsetof(link_config, match_host)
+Match.Virtualization,            config_parse_net_condition, CONDITION_VIRTUALIZATION,      offsetof(link_config, match_virt)
+Match.KernelCommandLine,         config_parse_net_condition, CONDITION_KERNEL_COMMAND_LINE, offsetof(link_config, match_kernel)
+Match.Architecture,              config_parse_net_condition, CONDITION_ARCHITECTURE,        offsetof(link_config, match_arch)
+Link.Description,                config_parse_string,        0,                             offsetof(link_config, description)
+Link.MACAddressPolicy,           config_parse_mac_policy,    0,                             offsetof(link_config, mac_policy)
+Link.MACAddress,                 config_parse_hwaddr,        0,                             offsetof(link_config, mac)
+Link.NamePolicy,                 config_parse_name_policy,   0,                             offsetof(link_config, name_policy)
+Link.Name,                       config_parse_ifname,        0,                             offsetof(link_config, name)
+Link.Alias,                      config_parse_ifalias,       0,                             offsetof(link_config, alias)
+Link.MTUBytes,                   config_parse_iec_size,      0,                             offsetof(link_config, mtu)
+Link.BitsPerSecond,              config_parse_si_size,       0,                             offsetof(link_config, speed)
+Link.Duplex,                     config_parse_duplex,        0,                             offsetof(link_config, duplex)
+Link.WakeOnLan,                  config_parse_wol,           0,                             offsetof(link_config, wol)
+Link.GenericSegmentationOffload, config_parse_tristate,      0,                             offsetof(link_config, features[NET_DEV_FEAT_GSO])
+Link.TCPSegmentationOffload,     config_parse_tristate,      0,                             offsetof(link_config, features[NET_DEV_FEAT_TSO])
+Link.UDPSegmentationOffload,     config_parse_tristate,      0,                             offsetof(link_config, features[NET_DEV_FEAT_UFO])
index c66504102f8b4bd7201674cfa0d17a8701516902..eedd94e777eadcf9ae19f7a83a34add562a56350 100644 (file)
@@ -168,6 +168,8 @@ static int load_link(link_config_ctx *ctx, const char *filename) {
         link->wol = _WOL_INVALID;
         link->duplex = _DUP_INVALID;
 
+        memset(&link->features, -1, _NET_DEV_FEAT_MAX);
+
         r = config_parse(NULL, filename, file,
                          "Match\0Link\0Ethernet\0",
                          config_item_perf_lookup, link_config_gperf_lookup,
@@ -397,6 +399,10 @@ int link_config_apply(link_config_ctx *ctx, link_config *config,
                 log_warning_errno(r, "Could not set WakeOnLan of %s to %s: %m",
                                   old_name, wol_to_string(config->wol));
 
+        r = ethtool_set_features(&ctx->ethtool_fd, old_name, config->features);
+        if (r < 0)
+                log_warning_errno(r, "Could not set offload features of %s: %m", old_name);
+
         ifindex = udev_device_get_ifindex(device);
         if (ifindex <= 0) {
                 log_warning("Could not find ifindex");
index 9df5529d055c031c42365882367ad3f18c98a512..91cc0357c417260b8a5b6091d4ae5527f51c6cc8 100644 (file)
@@ -70,6 +70,7 @@ struct link_config {
         size_t speed;
         Duplex duplex;
         WakeOnLan wol;
+        NetDevFeature features[_NET_DEV_FEAT_MAX];
 
         LIST_FIELDS(link_config, links);
 };