mirror of
https://github.com/systemd/systemd.git
synced 2025-03-19 22:50:17 +03:00
Merge pull request #18157 from ssahani/vlan-qos
network: Allow to configure VLan egress qos maps
This commit is contained in:
commit
048be097d2
@ -491,6 +491,28 @@
|
||||
like physical interfaces. When unset, the kernel's default will be used.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><varname>EgressQOSMaps=</varname></term>
|
||||
<listitem>
|
||||
<para>Defines a mapping of Linux internal packet priority (<constant>SO_PRIORITY</constant>) to VLAN header
|
||||
PCP field for outgoing frames. Takes a whitespace-separated list of unsigned integer pairs in the format
|
||||
<literal>from</literal>-<literal>to</literal>, e.g., <literal>21-7 45-5</literal> ranges 1–4294967294.
|
||||
Note that <literal>from</literal> must be greater than or equal to <literal>to</literal>. When unset,
|
||||
the kernel's default will be used.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><varname>IngressQOSMaps=</varname></term>
|
||||
<listitem>
|
||||
<para>Defines a mapping of Linux internal packet priority (<constant>SO_PRIORITY</constant>) to VLAN header
|
||||
PCP field for incoming frames. Takes a whitespace-separated list of unsigned integer pairs in the format
|
||||
<literal>from</literal>-<literal>to</literal>, e.g., <literal>21-7 45-5</literal> ranges 1–4294967294.
|
||||
Note that <literal>from</literal> must be greater than or equal to <literal>to</literal>. When unset,
|
||||
the kernel's default will be used.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</refsect1>
|
||||
|
||||
|
@ -152,13 +152,20 @@ static const NLType rtnl_link_info_data_bridge_types[] = {
|
||||
[IFLA_BR_MCAST_IGMP_VERSION] = { .type = NETLINK_TYPE_U8 },
|
||||
};
|
||||
|
||||
static const NLType rtnl_vlan_qos_map_types[] = {
|
||||
[IFLA_VLAN_QOS_MAPPING] = { .size = sizeof(struct ifla_vlan_qos_mapping) },
|
||||
};
|
||||
|
||||
static const NLTypeSystem rtnl_vlan_qos_map_type_system = {
|
||||
.count = ELEMENTSOF(rtnl_vlan_qos_map_types),
|
||||
.types = rtnl_vlan_qos_map_types,
|
||||
};
|
||||
|
||||
static const NLType rtnl_link_info_data_vlan_types[] = {
|
||||
[IFLA_VLAN_ID] = { .type = NETLINK_TYPE_U16 },
|
||||
/*
|
||||
[IFLA_VLAN_FLAGS] = { .len = sizeof(struct ifla_vlan_flags) },
|
||||
[IFLA_VLAN_EGRESS_QOS] = { .type = NETLINK_TYPE_NESTED },
|
||||
[IFLA_VLAN_INGRESS_QOS] = { .type = NETLINK_TYPE_NESTED },
|
||||
*/
|
||||
[IFLA_VLAN_FLAGS] = { .size = sizeof(struct ifla_vlan_flags) },
|
||||
[IFLA_VLAN_EGRESS_QOS] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_vlan_qos_map_type_system },
|
||||
[IFLA_VLAN_INGRESS_QOS] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_vlan_qos_map_type_system },
|
||||
[IFLA_VLAN_PROTOCOL] = { .type = NETLINK_TYPE_U16 },
|
||||
};
|
||||
|
||||
|
@ -53,6 +53,8 @@ VLAN.GVRP, config_parse_tristate,
|
||||
VLAN.MVRP, config_parse_tristate, 0, offsetof(VLan, mvrp)
|
||||
VLAN.LooseBinding, config_parse_tristate, 0, offsetof(VLan, loose_binding)
|
||||
VLAN.ReorderHeader, config_parse_tristate, 0, offsetof(VLan, reorder_hdr)
|
||||
VLAN.EgressQOSMaps, config_parse_vlan_qos_maps, 0, offsetof(VLan, egress_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)
|
||||
MACVTAP.Mode, config_parse_macvlan_mode, 0, offsetof(MacVlan, mode)
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <net/if.h>
|
||||
#include <linux/if_vlan.h>
|
||||
|
||||
#include "parse-util.h"
|
||||
#include "vlan-util.h"
|
||||
#include "vlan.h"
|
||||
|
||||
@ -54,9 +55,129 @@ static int netdev_vlan_fill_message_create(NetDev *netdev, Link *link, sd_netlin
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_VLAN_FLAGS attribute: %m");
|
||||
|
||||
if (!set_isempty(v->egress_qos_maps)) {
|
||||
struct ifla_vlan_qos_mapping *m;
|
||||
|
||||
r = sd_netlink_message_open_container(req, IFLA_VLAN_EGRESS_QOS);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not open container IFLA_VLAN_EGRESS_QOS: %m");
|
||||
|
||||
SET_FOREACH(m, v->egress_qos_maps) {
|
||||
r = sd_netlink_message_append_data(req, IFLA_VLAN_QOS_MAPPING, m, sizeof(struct ifla_vlan_qos_mapping));
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_VLAN_QOS_MAPPING attribute: %m");
|
||||
}
|
||||
|
||||
r = sd_netlink_message_close_container(req);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not close container IFLA_VLAN_EGRESS_QOS: %m");
|
||||
}
|
||||
|
||||
if (!set_isempty(v->ingress_qos_maps)) {
|
||||
struct ifla_vlan_qos_mapping *m;
|
||||
|
||||
r = sd_netlink_message_open_container(req, IFLA_VLAN_INGRESS_QOS);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not open container IFLA_VLAN_INGRESS_QOS: %m");
|
||||
|
||||
SET_FOREACH(m, v->ingress_qos_maps) {
|
||||
r = sd_netlink_message_append_data(req, IFLA_VLAN_QOS_MAPPING, m, sizeof(struct ifla_vlan_qos_mapping));
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_VLAN_QOS_MAPPING attribute: %m");
|
||||
}
|
||||
|
||||
r = sd_netlink_message_close_container(req);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not close container IFLA_VLAN_INGRESS_QOS: %m");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void vlan_qos_maps_hash_func(const struct ifla_vlan_qos_mapping *x, struct siphash *state) {
|
||||
siphash24_compress(&x->from, sizeof(x->from), state);
|
||||
siphash24_compress(&x->to, sizeof(x->to), state);
|
||||
}
|
||||
|
||||
static int vlan_qos_maps_compare_func(const struct ifla_vlan_qos_mapping *a, const struct ifla_vlan_qos_mapping *b) {
|
||||
int r;
|
||||
|
||||
r = CMP(a->from, b->from);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
return CMP(a->to, b->to);
|
||||
}
|
||||
|
||||
DEFINE_PRIVATE_HASH_OPS_WITH_KEY_DESTRUCTOR(
|
||||
vlan_qos_maps_hash_ops,
|
||||
struct ifla_vlan_qos_mapping,
|
||||
vlan_qos_maps_hash_func,
|
||||
vlan_qos_maps_compare_func,
|
||||
free);
|
||||
|
||||
int config_parse_vlan_qos_maps(
|
||||
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) {
|
||||
|
||||
Set **s = data;
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
assert(data);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
*s = set_free(*s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (const char *p = rvalue;;) {
|
||||
_cleanup_free_ struct ifla_vlan_qos_mapping *m = NULL;
|
||||
_cleanup_free_ char *w = NULL;
|
||||
|
||||
r = extract_first_word(&p, &w, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE);
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s, ignoring: %s", lvalue, rvalue);
|
||||
return 0;
|
||||
}
|
||||
if (r == 0)
|
||||
return 0;
|
||||
|
||||
m = new0(struct ifla_vlan_qos_mapping, 1);
|
||||
if (!m)
|
||||
return log_oom();
|
||||
|
||||
r = parse_range(w, &m->from, &m->to);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s, ignoring: %s", lvalue, w);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (m->to > m->from || m->to == 0 || m->from == 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid %s, ignoring: %s", lvalue, w);
|
||||
continue;
|
||||
}
|
||||
|
||||
r = set_ensure_consume(s, &vlan_qos_maps_hash_ops, TAKE_PTR(m));
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to store %s, ignoring: %s", lvalue, w);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int netdev_vlan_verify(NetDev *netdev, const char *filename) {
|
||||
VLan *v;
|
||||
|
||||
@ -75,6 +196,17 @@ static int netdev_vlan_verify(NetDev *netdev, const char *filename) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void vlan_done(NetDev *n) {
|
||||
VLan *v;
|
||||
|
||||
v = VLAN(n);
|
||||
|
||||
assert(v);
|
||||
|
||||
set_free(v->egress_qos_maps);
|
||||
set_free(v->ingress_qos_maps);
|
||||
}
|
||||
|
||||
static void vlan_init(NetDev *netdev) {
|
||||
VLan *v = VLAN(netdev);
|
||||
|
||||
@ -96,4 +228,5 @@ const NetDevVTable vlan_vtable = {
|
||||
.fill_message_create = netdev_vlan_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
.config_verify = netdev_vlan_verify,
|
||||
.done = vlan_done,
|
||||
};
|
||||
|
@ -4,6 +4,7 @@
|
||||
typedef struct VLan VLan;
|
||||
|
||||
#include "netdev.h"
|
||||
#include "set.h"
|
||||
|
||||
struct VLan {
|
||||
NetDev meta;
|
||||
@ -15,7 +16,12 @@ struct VLan {
|
||||
int mvrp;
|
||||
int loose_binding;
|
||||
int reorder_hdr;
|
||||
|
||||
Set *egress_qos_maps;
|
||||
Set *ingress_qos_maps;
|
||||
};
|
||||
|
||||
DEFINE_NETDEV_CAST(VLAN, VLan);
|
||||
extern const NetDevVTable vlan_vtable;
|
||||
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_vlan_qos_maps);
|
||||
|
@ -5,6 +5,8 @@ ReorderHeader=
|
||||
Id=
|
||||
GVRP=
|
||||
Protocol=
|
||||
EgressQOSMaps=
|
||||
IngressQOSMaps=
|
||||
[MACVLAN]
|
||||
Mode=
|
||||
SourceMACAddress=
|
||||
|
Loading…
x
Reference in New Issue
Block a user