From 60e49cf9e1e1fc6acc2f80a1abd6636bbd906332 Mon Sep 17 00:00:00 2001 From: Susant Sahani Date: Thu, 14 Jan 2021 14:01:38 +0100 Subject: [PATCH 1/4] basic: Add macvlan netlink attributes --- src/basic/linux/if_link.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/basic/linux/if_link.h b/src/basic/linux/if_link.h index c4b23f06f69..82708c6db43 100644 --- a/src/basic/linux/if_link.h +++ b/src/basic/linux/if_link.h @@ -75,8 +75,9 @@ struct rtnl_link_stats { * * @rx_dropped: Number of packets received but not processed, * e.g. due to lack of resources or unsupported protocol. - * For hardware interfaces this counter should not include packets - * dropped by the device which are counted separately in + * For hardware interfaces this counter may include packets discarded + * due to L2 address filtering but should not include packets dropped + * by the device due to buffer exhaustion which are counted separately in * @rx_missed_errors (since procfs folds those two counters together). * * @tx_dropped: Number of packets dropped on their way to transmission, @@ -588,6 +589,8 @@ enum { IFLA_MACVLAN_MACADDR, IFLA_MACVLAN_MACADDR_DATA, IFLA_MACVLAN_MACADDR_COUNT, + IFLA_MACVLAN_BC_QUEUE_LEN, + IFLA_MACVLAN_BC_QUEUE_LEN_USED, __IFLA_MACVLAN_MAX, }; From c9b31b17508206ede7cc155a8d75657630dd429e Mon Sep 17 00:00:00 2001 From: Susant Sahani Date: Wed, 13 Jan 2021 11:35:50 +0100 Subject: [PATCH 2/4] sd-netlink: Supprt netlink types bitfield and reject --- src/libsystemd/sd-netlink/netlink-types.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libsystemd/sd-netlink/netlink-types.h b/src/libsystemd/sd-netlink/netlink-types.h index 1e93ed78cf8..d1f20810e75 100644 --- a/src/libsystemd/sd-netlink/netlink-types.h +++ b/src/libsystemd/sd-netlink/netlink-types.h @@ -22,6 +22,8 @@ enum { NETLINK_TYPE_UNION, NETLINK_TYPE_SOCKADDR, NETLINK_TYPE_BINARY, + NETLINK_TYPE_BITFIELD32, /* NLA_BITFIELD32 */ + NETLINK_TYPE_REJECT, /* NLA_REJECT */ }; typedef enum NLMatchType { From 7e27a7458c56caba6913000576023f083b5433ed Mon Sep 17 00:00:00 2001 From: Susant Sahani Date: Wed, 13 Jan 2021 11:37:02 +0100 Subject: [PATCH 3/4] sd-netlink: mcvlan - add new attributes --- src/libsystemd/sd-netlink/netlink-types.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/libsystemd/sd-netlink/netlink-types.c b/src/libsystemd/sd-netlink/netlink-types.c index cff029f3cc9..87ce45b4c92 100644 --- a/src/libsystemd/sd-netlink/netlink-types.c +++ b/src/libsystemd/sd-netlink/netlink-types.c @@ -105,10 +105,13 @@ static const NLTypeSystem rtnl_macvlan_macaddr_type_system = { }; static const NLType rtnl_link_info_data_macvlan_types[] = { - [IFLA_MACVLAN_MODE] = { .type = NETLINK_TYPE_U32 }, - [IFLA_MACVLAN_FLAGS] = { .type = NETLINK_TYPE_U16 }, - [IFLA_MACVLAN_MACADDR_MODE] = { .type = NETLINK_TYPE_U32 }, - [IFLA_MACVLAN_MACADDR_DATA] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_macvlan_macaddr_type_system }, + [IFLA_MACVLAN_MODE] = { .type = NETLINK_TYPE_U32 }, + [IFLA_MACVLAN_FLAGS] = { .type = NETLINK_TYPE_U16 }, + [IFLA_MACVLAN_MACADDR_MODE] = { .type = NETLINK_TYPE_U32 }, + [IFLA_MACVLAN_MACADDR_DATA] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_macvlan_macaddr_type_system }, + [IFLA_MACVLAN_MACADDR_COUNT] = { .type = NETLINK_TYPE_U32 }, + [IFLA_MACVLAN_BC_QUEUE_LEN] = { .type = NETLINK_TYPE_U32 }, + [IFLA_MACVLAN_BC_QUEUE_LEN_USED] = { .type = NETLINK_TYPE_REJECT }, }; static const NLType rtnl_link_info_data_bridge_types[] = { From dca0a4e13128b4f84f5af169ddadf5903cca4f8d Mon Sep 17 00:00:00 2001 From: Susant Sahani Date: Sun, 17 Jan 2021 08:39:28 +0100 Subject: [PATCH 4/4] network: macvlan - add support to configure rx queue for broadcast/multicast --- man/systemd.netdev.xml | 7 +++ src/network/netdev/macvlan.c | 53 +++++++++++++++++++ src/network/netdev/macvlan.h | 3 ++ src/network/netdev/netdev-gperf.gperf | 1 + .../fuzz/fuzz-netdev-parser/directives.netdev | 1 + 5 files changed, 65 insertions(+) diff --git a/man/systemd.netdev.xml b/man/systemd.netdev.xml index 9bb7491a6ea..baa734bcb24 100644 --- a/man/systemd.netdev.xml +++ b/man/systemd.netdev.xml @@ -546,6 +546,13 @@ to this is reset. Defaults to unset. + + BroadcastMulticastQueueLength= + + Specifies the length of the receive queue for broadcast/multicast packets. An unsigned + integer in the range 0—4294967294. Defaults to unset. + + diff --git a/src/network/netdev/macvlan.c b/src/network/netdev/macvlan.c index 9bdcf627b40..46b08261482 100644 --- a/src/network/netdev/macvlan.c +++ b/src/network/netdev/macvlan.c @@ -5,6 +5,7 @@ #include "conf-parser.h" #include "macvlan.h" #include "macvlan-util.h" +#include "parse-util.h" DEFINE_CONFIG_PARSE_ENUM(config_parse_macvlan_mode, macvlan_mode, MacVlanMode, "Failed to parse macvlan mode"); @@ -51,6 +52,57 @@ static int netdev_macvlan_fill_message_create(NetDev *netdev, Link *link, sd_net return log_netdev_error_errno(netdev, r, "Could not append IFLA_MACVLAN_MODE attribute: %m"); } + if (m->bc_queue_length != UINT32_MAX) { + r = sd_netlink_message_append_u32(req, IFLA_MACVLAN_BC_QUEUE_LEN, m->bc_queue_length); + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_MACVLAN_BC_QUEUE_LEN attribute: %m"); + } + + return 0; +} + +int config_parse_macvlan_broadcast_queue_size( + const char *unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + + MacVlan *m = userdata; + uint32_t v; + int r; + + assert(filename); + assert(section); + assert(lvalue); + assert(rvalue); + assert(data); + assert(userdata); + + if (isempty(rvalue)) { + m->bc_queue_length = UINT32_MAX; + return 0; + } + + r = safe_atou32(rvalue, &v); + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, + "Failed to parse BroadcastMulticastQueueLength=%s, ignoring assignment: %m", rvalue); + return 0; + } + + if (v == UINT32_MAX) { + log_syntax(unit, LOG_WARNING, filename, line, 0, + "Invalid BroadcastMulticastQueueLength=%s, ignoring assignment: %m", rvalue); + return 0; + } + + m->bc_queue_length = v; return 0; } @@ -82,6 +134,7 @@ static void macvlan_init(NetDev *n) { assert(m); m->mode = _NETDEV_MACVLAN_MODE_INVALID; + m->bc_queue_length = UINT32_MAX; } const NetDevVTable macvtap_vtable = { diff --git a/src/network/netdev/macvlan.h b/src/network/netdev/macvlan.h index cb7eece67f5..c45fc4fd339 100644 --- a/src/network/netdev/macvlan.h +++ b/src/network/netdev/macvlan.h @@ -12,6 +12,8 @@ struct MacVlan { MacVlanMode mode; Set *match_source_mac; + + uint32_t bc_queue_length; }; DEFINE_NETDEV_CAST(MACVLAN, MacVlan); @@ -20,3 +22,4 @@ extern const NetDevVTable macvlan_vtable; extern const NetDevVTable macvtap_vtable; CONFIG_PARSER_PROTOTYPE(config_parse_macvlan_mode); +CONFIG_PARSER_PROTOTYPE(config_parse_macvlan_broadcast_queue_size); diff --git a/src/network/netdev/netdev-gperf.gperf b/src/network/netdev/netdev-gperf.gperf index 720bacc7f55..680063eb3b6 100644 --- a/src/network/netdev/netdev-gperf.gperf +++ b/src/network/netdev/netdev-gperf.gperf @@ -57,6 +57,7 @@ VLAN.EgressQOSMaps, config_parse_vlan_qos_maps, VLAN.IngressQOSMaps, config_parse_vlan_qos_maps, 0, offsetof(VLan, ingress_qos_maps) MACVLAN.Mode, config_parse_macvlan_mode, 0, offsetof(MacVlan, mode) MACVLAN.SourceMACAddress, config_parse_hwaddrs, 0, offsetof(MacVlan, match_source_mac) +MACVLAN.BroadcastMulticastQueueLength, config_parse_macvlan_broadcast_queue_size, 0, offsetof(MacVlan, bc_queue_length) MACVTAP.Mode, config_parse_macvlan_mode, 0, offsetof(MacVlan, mode) MACVTAP.SourceMACAddress, config_parse_hwaddrs, 0, offsetof(MacVlan, match_source_mac) IPVLAN.Mode, config_parse_ipvlan_mode, 0, offsetof(IPVlan, mode) diff --git a/test/fuzz/fuzz-netdev-parser/directives.netdev b/test/fuzz/fuzz-netdev-parser/directives.netdev index 8c36e31a0e7..05007852072 100644 --- a/test/fuzz/fuzz-netdev-parser/directives.netdev +++ b/test/fuzz/fuzz-netdev-parser/directives.netdev @@ -10,6 +10,7 @@ IngressQOSMaps= [MACVLAN] Mode= SourceMACAddress= +BroadcastMulticastQueueLength= [WireGuard] ListenPort= PrivateKey=