diff options
author | Pau Espin Pedrol <pespin.shar@gmail.com> | 2020-05-17 20:39:44 +0200 |
---|---|---|
committer | Hans Dedecker <dedeckeh@gmail.com> | 2020-05-21 20:08:48 +0200 |
commit | 74e0222eeb9e62f4d5073a5b3d9208678782a198 (patch) | |
tree | 7198184cf4410dd5d1a3f41a32782dafa4ea3037 | |
parent | cfccdc22ca6d8f28d70a2546a495c9ead4bbb765 (diff) |
vlandev: support setting ingress/egress QoS mappings
It allows setting mappings for instance this way:
"""
config device
option name 'vlan41'
option type '8021q'
option vid '41'
option ifname 'eth1'
list ingress_qos_mapping '1:2'
list ingress_qos_mapping '2:5'
list egress_qos_mapping '0:3'
"""
Signed-off-by: Pau Espin Pedrol <pespin.shar@gmail.com>
Tested-by: Pedro <pedrowrt@cas.cat>
-rw-r--r-- | system-linux.c | 25 | ||||
-rw-r--r-- | system.h | 9 | ||||
-rw-r--r-- | vlandev.c | 72 |
3 files changed, 105 insertions, 1 deletions
diff --git a/system-linux.c b/system-linux.c index 62636c4..c225175 100644 --- a/system-linux.c +++ b/system-linux.c @@ -74,6 +74,7 @@ #include "netifd.h" #include "device.h" #include "system.h" +#include "utils.h" struct event_socket { struct uloop_fd uloop; @@ -1401,8 +1402,10 @@ int system_vlan_del(struct device *dev) int system_vlandev_add(struct device *vlandev, struct device *dev, struct vlandev_config *cfg) { struct nl_msg *msg; - struct nlattr *linkinfo, *data; + struct nlattr *linkinfo, *data, *qos; struct ifinfomsg iim = { .ifi_family = AF_UNSPEC }; + struct vlan_qos_mapping *elem; + struct ifla_vlan_qos_mapping nl_qos_map; int rv; msg = nlmsg_alloc_simple(RTM_NEWLINK, NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL); @@ -1431,6 +1434,26 @@ int system_vlandev_add(struct device *vlandev, struct device *dev, struct vlande netifd_log_message(L_WARNING, "%s Your kernel is older than linux 3.10.0, 802.1ad is not supported defaulting to 802.1q", vlandev->type->name); #endif + if (!(qos = nla_nest_start(msg, IFLA_VLAN_INGRESS_QOS))) + goto nla_put_failure; + + vlist_simple_for_each_element(&cfg->ingress_qos_mapping_list, elem, node) { + nl_qos_map.from = elem->from; + nl_qos_map.to = elem->to; + nla_put(msg, IFLA_VLAN_QOS_MAPPING, sizeof(nl_qos_map), &nl_qos_map); + } + nla_nest_end(msg, qos); + + if (!(qos = nla_nest_start(msg, IFLA_VLAN_EGRESS_QOS))) + goto nla_put_failure; + + vlist_simple_for_each_element(&cfg->egress_qos_mapping_list, elem, node) { + nl_qos_map.from = elem->from; + nl_qos_map.to = elem->to; + nla_put(msg, IFLA_VLAN_QOS_MAPPING, sizeof(nl_qos_map), &nl_qos_map); + } + nla_nest_end(msg, qos); + nla_nest_end(msg, data); nla_nest_end(msg, linkinfo); @@ -21,6 +21,7 @@ #include "device.h" #include "interface-ip.h" #include "iprule.h" +#include "utils.h" enum tunnel_param { TUNNEL_ATTR_TYPE, @@ -158,9 +159,17 @@ enum vlan_proto { VLAN_PROTO_8021AD = 0x88A8 }; +struct vlan_qos_mapping { + struct vlist_simple_node node; /* entry in vlandev_config->{e,in}gress_qos_mapping_list */ + uint32_t from; + uint32_t to; +}; + struct vlandev_config { enum vlan_proto proto; uint16_t vid; + struct vlist_simple_tree ingress_qos_mapping_list; /* list of struct vlan_qos_mapping */ + struct vlist_simple_tree egress_qos_mapping_list; /* list of struct vlan_qos_mapping */ }; static inline int system_get_addr_family(unsigned int flags) @@ -13,21 +13,27 @@ */ #include <string.h> +#include <inttypes.h> #include "netifd.h" #include "device.h" #include "interface.h" #include "system.h" +#include "utils.h" enum { VLANDEV_ATTR_IFNAME, VLANDEV_ATTR_VID, + VLANDEV_ATTR_INGRESS_QOS_MAPPING, + VLANDEV_ATTR_EGRESS_QOS_MAPPING, __VLANDEV_ATTR_MAX }; static const struct blobmsg_policy vlandev_attrs[__VLANDEV_ATTR_MAX] = { [VLANDEV_ATTR_IFNAME] = { "ifname", BLOBMSG_TYPE_STRING }, [VLANDEV_ATTR_VID] = { "vid", BLOBMSG_TYPE_INT32 }, + [VLANDEV_ATTR_INGRESS_QOS_MAPPING] = { "ingress_qos_mapping", BLOBMSG_TYPE_ARRAY }, + [VLANDEV_ATTR_EGRESS_QOS_MAPPING] = { "egress_qos_mapping", BLOBMSG_TYPE_ARRAY }, }; static const struct uci_blob_param_list vlandev_attr_list = { @@ -126,9 +132,30 @@ vlandev_free(struct device *dev) mvdev = container_of(dev, struct vlandev_device, dev); device_remove_user(&mvdev->parent); free(mvdev->config_data); + vlist_simple_flush_all(&mvdev->config.ingress_qos_mapping_list); + vlist_simple_flush_all(&mvdev->config.egress_qos_mapping_list); free(mvdev); } +static void vlandev_qos_mapping_dump(struct blob_buf *b, const char *name, const struct vlist_simple_tree *qos_mapping_li) +{ + const struct vlan_qos_mapping *elem; + void *a, *t; + + a = blobmsg_open_array(b, name); + + vlist_simple_for_each_element(qos_mapping_li, elem, node) { + t = blobmsg_open_table(b, NULL); + + blobmsg_add_u32(b, "from", elem->from); + blobmsg_add_u32(b, "to", elem->to); + + blobmsg_close_table(b, t); + } + + blobmsg_close_array(b, a); +} + static void vlandev_dump_info(struct device *dev, struct blob_buf *b) { @@ -137,6 +164,8 @@ vlandev_dump_info(struct device *dev, struct blob_buf *b) mvdev = container_of(dev, struct vlandev_device, dev); blobmsg_add_string(b, "parent", mvdev->parent.dev->ifname); system_if_dump_info(dev, b); + vlandev_qos_mapping_dump(b, "ingress_qos_mapping", &mvdev->config.ingress_qos_mapping_list); + vlandev_qos_mapping_dump(b, "egress_qos_mapping", &mvdev->config.egress_qos_mapping_list); } static void @@ -152,6 +181,32 @@ vlandev_config_init(struct device *dev) device_add_user(&mvdev->parent, basedev); } +static void vlandev_qos_mapping_list_apply(struct vlist_simple_tree *qos_mapping_li, struct blob_attr *list) +{ + struct blob_attr *cur; + struct vlan_qos_mapping *qos_mapping; + int rem, rc; + + blobmsg_for_each_attr(cur, list, rem) { + if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING) + continue; + + if (!blobmsg_check_attr(cur, false)) + continue; + + qos_mapping = calloc(1, sizeof(*qos_mapping)); + if (!qos_mapping) + continue; + + rc = sscanf(blobmsg_data(cur), "%" PRIu32 ":%" PRIu32, &qos_mapping->from, &qos_mapping->to); + if (rc != 2) { + free(qos_mapping); + continue; + } + vlist_simple_add(qos_mapping_li, &qos_mapping->node); + } +} + static void vlandev_apply_settings(struct vlandev_device *mvdev, struct blob_attr **tb) { @@ -162,8 +217,20 @@ vlandev_apply_settings(struct vlandev_device *mvdev, struct blob_attr **tb) VLAN_PROTO_8021Q : VLAN_PROTO_8021AD; cfg->vid = 1; + vlist_simple_update(&cfg->ingress_qos_mapping_list); + vlist_simple_update(&cfg->egress_qos_mapping_list); + if ((cur = tb[VLANDEV_ATTR_VID])) cfg->vid = (uint16_t) blobmsg_get_u32(cur); + + if ((cur = tb[VLANDEV_ATTR_INGRESS_QOS_MAPPING])) + vlandev_qos_mapping_list_apply(&cfg->ingress_qos_mapping_list, cur); + + if ((cur = tb[VLANDEV_ATTR_EGRESS_QOS_MAPPING])) + vlandev_qos_mapping_list_apply(&cfg->egress_qos_mapping_list, cur); + + vlist_simple_flush(&cfg->ingress_qos_mapping_list); + vlist_simple_flush(&cfg->egress_qos_mapping_list); } static enum dev_change_type @@ -221,6 +288,11 @@ vlandev_create(const char *name, struct device_type *devtype, if (!mvdev) return NULL; + vlist_simple_init(&mvdev->config.ingress_qos_mapping_list, + struct vlan_qos_mapping, node); + vlist_simple_init(&mvdev->config.egress_qos_mapping_list, + struct vlan_qos_mapping, node); + dev = &mvdev->dev; if (device_init(dev, devtype, name) < 0) { |