From: Gavin Li
Add TC offload support for filtering vxlan tunnels with gbp option
Signed-off-by: Gavin Li
Reviewed-by: Gavi Teitz
Reviewed-by: Roi Dayan
Reviewed-by: Simon Horman
---
include/linux/pkt_cls.h | 13 ++
lib/netdev-offload-tc.c | 17
lib/tc.c| 92 +++--
lib/tc.h| 7
4 files changed, 117 insertions(+), 12 deletions(-)
diff --git a/include/linux/pkt_cls.h b/include/linux/pkt_cls.h
index a8cd8db5bf88..fb4a7ecea4cc 100644
--- a/include/linux/pkt_cls.h
+++ b/include/linux/pkt_cls.h
@@ -273,6 +273,10 @@ enum {
* TCA_TUNNEL_KEY_ENC_OPTS_GENEVE
* attributes
*/
+ TCA_FLOWER_KEY_ENC_OPTS_VXLAN, /* Nested
+* TCA_TUNNEL_KEY_ENC_OPTS_VXLAN
+* attributes
+*/
__TCA_FLOWER_KEY_ENC_OPTS_MAX,
};
@@ -290,6 +294,15 @@ enum {
#define TCA_FLOWER_KEY_ENC_OPT_GENEVE_MAX \
(__TCA_FLOWER_KEY_ENC_OPT_GENEVE_MAX - 1)
+enum {
+ TCA_FLOWER_KEY_ENC_OPT_VXLAN_UNSPEC,
+ TCA_FLOWER_KEY_ENC_OPT_VXLAN_GBP, /* u32 */
+ __TCA_FLOWER_KEY_ENC_OPT_VXLAN_MAX,
+};
+
+#define TCA_FLOWER_KEY_ENC_OPT_VXLAN_MAX \
+ (__TCA_FLOWER_KEY_ENC_OPT_VXLAN_MAX - 1)
+
enum {
TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT = (1 << 0),
TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST = (1 << 1),
diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c
index 4f26dd8cca5f..1c97681bc92b 100644
--- a/lib/netdev-offload-tc.c
+++ b/lib/netdev-offload-tc.c
@@ -1234,6 +1234,15 @@ parse_tc_flower_to_match(const struct netdev *netdev,
match_set_tun_tp_dst_masked(match, flower->key.tunnel.tp_dst,
flower->mask.tunnel.tp_dst);
}
+if (flower->mask.tunnel.gbp.id) {
+match_set_tun_gbp_id_masked(match, flower->key.tunnel.gbp.id,
+flower->mask.tunnel.gbp.id);
+}
+if (flower->mask.tunnel.gbp.flags) {
+match_set_tun_gbp_flags_masked(match,
+ flower->key.tunnel.gbp.flags,
+ flower->mask.tunnel.gbp.flags);
+}
if (!strcmp(netdev_get_type(netdev), "geneve")) {
flower_tun_opt_to_match(match, flower);
@@ -2193,6 +2202,9 @@ netdev_tc_flow_put(struct netdev *netdev, struct match
*match,
flower.key.tunnel.ttl = tnl->ip_ttl;
flower.key.tunnel.tp_src = tnl->tp_src;
flower.key.tunnel.tp_dst = tnl->tp_dst;
+flower.key.tunnel.gbp.id = tnl->gbp_id;
+flower.key.tunnel.gbp.flags = tnl->gbp_flags;
+flower.key.tunnel.gbp.id_present = !!tnl_mask->gbp_id;
flower.mask.tunnel.ipv4.ipv4_src = tnl_mask->ip_src;
flower.mask.tunnel.ipv4.ipv4_dst = tnl_mask->ip_dst;
@@ -2207,6 +2219,9 @@ netdev_tc_flow_put(struct netdev *netdev, struct match
*match,
* Degrading the flow down to exact match for now as a workaround. */
flower.mask.tunnel.tp_dst = OVS_BE16_MAX;
flower.mask.tunnel.id = (tnl->flags & FLOW_TNL_F_KEY) ?
tnl_mask->tun_id : 0;
+flower.mask.tunnel.gbp.id = tnl_mask->gbp_id;
+flower.mask.tunnel.gbp.flags = tnl_mask->gbp_flags;
+flower.mask.tunnel.gbp.id_present = !!tnl_mask->gbp_id;
memset(&tnl_mask->ip_src, 0, sizeof tnl_mask->ip_src);
memset(&tnl_mask->ip_dst, 0, sizeof tnl_mask->ip_dst);
@@ -2218,6 +2233,8 @@ netdev_tc_flow_put(struct netdev *netdev, struct match
*match,
memset(&tnl_mask->tp_dst, 0, sizeof tnl_mask->tp_dst);
memset(&tnl_mask->tun_id, 0, sizeof tnl_mask->tun_id);
+memset(&tnl_mask->gbp_id, 0, sizeof tnl_mask->gbp_id);
+memset(&tnl_mask->gbp_flags, 0, sizeof tnl_mask->gbp_flags);
tnl_mask->flags &= ~FLOW_TNL_F_KEY;
/* XXX: This is wrong! We're ignoring DF and CSUM flags configuration
diff --git a/lib/tc.c b/lib/tc.c
index 223fe6e5e5e9..ae1ca57c9d2a 100644
--- a/lib/tc.c
+++ b/lib/tc.c
@@ -39,6 +39,7 @@
#include "coverage.h"
#include "netlink-socket.h"
#include "netlink.h"
+#include "odp-util.h"
#include "openvswitch/ofpbuf.h"
#include "openvswitch/util.h"
#include "openvswitch/vlog.h"
@@ -699,6 +700,38 @@ nl_parse_geneve_key(const struct nlattr *in_nlattr,
return 0;
}
+static int
+nl_parse_vxlan_key(const struct nlattr *in_nlattr,
+ struct tc_flower_tunnel *tunnel)
+{
+const struct ofpbuf *msg;
+struct nlattr *nla;
+struct ofpbuf buf;
+uint32_t gbp_raw;
+size_t left;
+
+nl_attr_get_nested(in_nlattr, &buf);
+msg = &buf;
+
+NL_ATTR_FOR_EACH (nla, left, ofpbuf_at(msg, 0, 0), msg->size) {
+uint16_t type = nl_attr_type(nla);
+
+switc