Skip to content

Commit

Permalink
network: Introduce SR-IOV
Browse files Browse the repository at this point in the history
  • Loading branch information
ssahani committed Jun 19, 2020
1 parent 2a71d57 commit f4cbeb6
Show file tree
Hide file tree
Showing 11 changed files with 609 additions and 4 deletions.
63 changes: 63 additions & 0 deletions man/systemd.network.xml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,69 @@
</variablelist>
</refsect1>

<refsect1>
<title>[SRIOV] Section Options</title>
<para>The <literal>[SRIOV]</literal> section accepts the
following keys. Specify several <literal>[SRIOV]</literal>
sections to configure several nexthop. SR-IOV is a specification that allows a PCIe device to appear to
be multiple separate physical PCIe devices.</para>

<variablelist class='network-directives'>
<varlistentry>
<term><varname>VirtualFunction=</varname></term>
<listitem>
<para>Specifies the virtual function number. Takes an unsigned integer ranges 0..4294967294.
This is mandatory.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><varname>VLanId=</varname></term>
<listitem>
<para>Specifies Vlan ID of the virtual function. Takes an unsigned integer ranges 1...4095.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><varname>QualityOfService=</varname></term>
<listitem>
<para>Specifies quality of service of vlan of the virtual function. Takes an unsigned integer ranges 1..4294967294.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><varname>MACSpoofCheck=</varname></term>
<listitem>
<para>A boolen. Controls the MAC spoof checking. Defaults to unset.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><varname>QueryReceiveSideScaling=</varname></term>
<listitem>
<para>A boolen. Allows to query VF RSS information like RSS hash key may be considered sensitive on some devices where
this information is shared between VF and PF. Defaults to unset.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><varname>Trust=</varname></term>
<listitem>
<para>A boolen. Allows to set trust mode of virtual function. Defaults to unset.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><varname>LinkState=</varname></term>
<listitem>
<para>Allows to set the link state of vitual function. Takes a boolen or a special value
<liternal>auto</literal>. Defaults to unset.</para>
</listitem>
</varlistentry>

</variablelist>
</refsect1>

<refsect1>
<title>[Network] Section Options</title>

Expand Down
43 changes: 39 additions & 4 deletions src/libsystemd/sd-netlink/netlink-types.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,43 @@ static const NLTypeSystem rtnl_prop_list_type_system = {
.types = rtnl_prop_list_types,
};

static const NLType rtnl_vf_vlan_list_types[] = {
[IFLA_VF_VLAN_INFO] = { .size = sizeof(struct ifla_vf_vlan_info) },
};

static const NLTypeSystem rtnl_vf_vlan_type_system = {
.count = ELEMENTSOF(rtnl_vf_vlan_list_types),
.types = rtnl_vf_vlan_list_types,
};

static const NLType rtnl_vf_vlan_info_types[] = {
[IFLA_VF_MAC] = { .size = sizeof(struct ifla_vf_mac) },
[IFLA_VF_VLAN] = { .size = sizeof(struct ifla_vf_vlan) },
[IFLA_VF_TX_RATE] = { .size = sizeof(struct ifla_vf_tx_rate) },
[IFLA_VF_SPOOFCHK] = { .size = sizeof(struct ifla_vf_spoofchk) },
[IFLA_VF_RATE] = { .size = sizeof(struct ifla_vf_rate) },
[IFLA_VF_LINK_STATE] = { .size = sizeof(struct ifla_vf_link_state) },
[IFLA_VF_RSS_QUERY_EN] = { .size = sizeof(struct ifla_vf_rss_query_en) },
[IFLA_VF_TRUST] = { .size = sizeof(struct ifla_vf_trust) },
[IFLA_VF_IB_NODE_GUID] = { .size = sizeof(struct ifla_vf_guid) },
[IFLA_VF_IB_PORT_GUID] = { .size = sizeof(struct ifla_vf_guid) },
[IFLA_VF_VLAN_LIST] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_vf_vlan_type_system},
};

static const NLTypeSystem rtnl_vf_vlan_info_type_system = {
.count = ELEMENTSOF(rtnl_vf_vlan_info_types),
.types = rtnl_vf_vlan_info_types,
};

static const NLType rtnl_link_io_srv_types[] = {
[IFLA_VF_INFO] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_vf_vlan_info_type_system },
};

static const NLTypeSystem rtnl_io_srv_type_system = {
.count = ELEMENTSOF(rtnl_link_io_srv_types),
.types = rtnl_link_io_srv_types,
};

static const NLType rtnl_link_types[] = {
[IFLA_ADDRESS] = { .type = NETLINK_TYPE_ETHER_ADDR },
[IFLA_BROADCAST] = { .type = NETLINK_TYPE_ETHER_ADDR },
Expand Down Expand Up @@ -564,10 +601,8 @@ static const NLType rtnl_link_types[] = {
[IFLA_LINKINFO] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_link_info_type_system },
[IFLA_NET_NS_PID] = { .type = NETLINK_TYPE_U32 },
[IFLA_IFALIAS] = { .type = NETLINK_TYPE_STRING, .size = IFALIASZ - 1 },
/*
[IFLA_NUM_VF],
[IFLA_VFINFO_LIST] = {. type = NETLINK_TYPE_NESTED, },
*/
[IFLA_NUM_VF] = { .type = NETLINK_TYPE_U32 },
[IFLA_VFINFO_LIST] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_io_srv_type_system },
[IFLA_STATS64] = { .size = sizeof(struct rtnl_link_stats64) },
/*
[IFLA_VF_PORTS] = { .type = NETLINK_TYPE_NESTED },
Expand Down
2 changes: 2 additions & 0 deletions src/network/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ sources = files('''
networkd-routing-policy-rule.h
networkd-speed-meter.c
networkd-speed-meter.h
networkd-sriov.c
networkd-sriov.h
networkd-util.c
networkd-util.h
networkd-wifi.c
Expand Down
31 changes: 31 additions & 0 deletions src/network/networkd-link.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <netinet/in.h>
#include <linux/if.h>
#include <linux/if_arp.h>
#include <linux/if_link.h>
#include <unistd.h>

#include "alloc-util.h"
Expand Down Expand Up @@ -31,6 +32,7 @@
#include "networkd-manager.h"
#include "networkd-ndisc.h"
#include "networkd-neighbor.h"
#include "networkd-sriov.h"
#include "networkd-radv.h"
#include "networkd-routing-policy-rule.h"
#include "networkd-wifi.h"
Expand Down Expand Up @@ -1124,6 +1126,9 @@ void link_check_ready(Link *link) {
if (!link->tc_configured)
return;

if (!link->sr_iov_configured)
return;

if (link_has_carrier(link) || !link->network->configure_without_carrier) {

if (link_ipv4ll_enabled(link, ADDRESS_FAMILY_IPV4) && !link->ipv4ll_address)
Expand Down Expand Up @@ -2837,6 +2842,28 @@ static int link_configure_traffic_control(Link *link) {
return 0;
}

static int link_configure_sr_iov(Link *link) {
SRIOV *sr_iov;
Iterator i;
int r;

link->sr_iov_configured = false;
link->sr_iov_messages = 0;

ORDERED_HASHMAP_FOREACH(sr_iov, link->network->sr_iov_by_section, i) {
r = sr_iov_configure(link, sr_iov);
if (r < 0)
return r;
}

if (link->sr_iov_messages == 0)
link->sr_iov_configured = true;
else
log_link_debug(link, "Configuring SR-IOV");

return 0;
}

static int link_configure(Link *link) {
int r;

Expand All @@ -2848,6 +2875,10 @@ static int link_configure(Link *link) {
if (r < 0)
return r;

r = link_configure_sr_iov(link);
if (r < 0)
return r;

if (link->iftype == ARPHRD_CAN)
return link_configure_can(link);

Expand Down
2 changes: 2 additions & 0 deletions src/network/networkd-link.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ typedef struct Link {
unsigned routing_policy_rule_messages;
unsigned routing_policy_rule_remove_messages;
unsigned tc_messages;
unsigned sr_iov_messages;
unsigned enslaving;

Set *addresses;
Expand Down Expand Up @@ -127,6 +128,7 @@ typedef struct Link {
bool static_nexthops_configured:1;
bool routing_policy_rules_configured:1;
bool tc_configured:1;
bool sr_iov_configured:1;
bool setting_mtu:1;
bool setting_genmode:1;
bool ipv6_mtu_set:1;
Expand Down
8 changes: 8 additions & 0 deletions src/network/networkd-network-gperf.gperf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ _Pragma("GCC diagnostic ignored \"-Wimplicit-fallthrough\"")
#include "networkd-ipv4ll.h"
#include "networkd-ndisc.h"
#include "networkd-network.h"
#include "networkd-sriov.h"
#include "qdisc.h"
#include "tclass.h"
#include "vlan-util.h"
Expand Down Expand Up @@ -54,6 +55,13 @@ Link.AllMulticast, config_parse_tristate,
Link.Unmanaged, config_parse_bool, 0, offsetof(Network, unmanaged)
Link.IPv6LinkLocalAddressGenerationMode, config_parse_link_ipv6_address_gen_mode, 0, offsetof(Network, ipv6_address_gen_mode)
Link.RequiredForOnline, config_parse_required_for_online, 0, 0
SRIOV.VirtualFunction, config_parse_sr_iov_uint32, 0, 0
SRIOV.VLanId, config_parse_sr_iov_uint32, 0, 0
SRIOV.QualityOfService, config_parse_sr_iov_uint32, 0, 0
SRIOV.MACSpoofCheck, config_parse_sr_iov_boolean, 0, 0
SRIOV.QueryReceiveSideScaling, config_parse_sr_iov_boolean, 0, 0
SRIOV.Trust, config_parse_sr_iov_boolean, 0, 0
SRIOV.LinkState, config_parse_sr_iov_link_state, 0, 0
Network.Description, config_parse_string, 0, offsetof(Network, description)
Network.Bridge, config_parse_ifname, 0, offsetof(Network, bridge_name)
Network.Bond, config_parse_ifname, 0, offsetof(Network, bond_name)
Expand Down
9 changes: 9 additions & 0 deletions src/network/networkd-network.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "network-internal.h"
#include "networkd-manager.h"
#include "networkd-network.h"
#include "networkd-sriov.h"
#include "parse-util.h"
#include "path-lookup.h"
#include "set.h"
Expand Down Expand Up @@ -158,6 +159,7 @@ int network_verify(Network *network) {
Route *route, *route_next;
FdbEntry *fdb, *fdb_next;
TrafficControl *tc;
SRIOV *sr_iov;
Iterator i;

assert(network);
Expand Down Expand Up @@ -330,6 +332,11 @@ int network_verify(Network *network) {
if (traffic_control_section_verify(tc, &has_root, &has_clsact) < 0)
traffic_control_free(tc);

ORDERED_HASHMAP_FOREACH(sr_iov, network->sr_iov_by_section, i) {
if (sr_iov_section_verify(sr_iov) < 0)
sr_iov_free(sr_iov);
}

return 0;
}

Expand Down Expand Up @@ -484,6 +491,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
filename, NETWORK_DIRS, dropin_dirname,
"Match\0"
"Link\0"
"SRIOV\0"
"Network\0"
"Address\0"
"Neighbor\0"
Expand Down Expand Up @@ -730,6 +738,7 @@ static Network *network_free(Network *network) {
hashmap_free(network->prefixes_by_section);
hashmap_free(network->route_prefixes_by_section);
hashmap_free(network->rules_by_section);
ordered_hashmap_free_with_destructor(network->sr_iov_by_section, sr_iov_free);
ordered_hashmap_free_with_destructor(network->tc_by_section, traffic_control_free);

if (network->manager &&
Expand Down
1 change: 1 addition & 0 deletions src/network/networkd-network.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ struct Network {
Hashmap *route_prefixes_by_section;
Hashmap *rules_by_section;
OrderedHashmap *tc_by_section;
OrderedHashmap *sr_iov_by_section;

/* All kinds of DNS configuration */
struct in_addr_data *dns;
Expand Down

0 comments on commit f4cbeb6

Please sign in to comment.