diff mbox series

[ovs-dev,1/7] tc: Pass tunnel entirely to tunnel option parse and put functions

Message ID 20230425063238.2366798-2-roid@nvidia.com
State Superseded
Headers show
Series Add vxlan gbp offload with TC | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test fail github build: failed
ovsrobot/intel-ovs-compilation success test: success

Commit Message

Roi Dayan April 25, 2023, 6:32 a.m. UTC
From: Gavin Li <gavinl@nvidia.com>

Tc flower tunnel key options were encoded in nl_msg_put_flower_tunnel_opts
and decoded in nl_parse_flower_tunnel_opts. Only geneve was supported.

To avoid adding more arguments to the function to support more vxlan
options in the future, change the function arguments to pass tunnel
entirely to it instead of keep adding new arguments.

Signed-off-by: Gavin Li <gavinl@nvidia.com>
Reviewed-by: Roi Dayan <roid@nvidia.com>
---
 lib/tc.c | 15 ++++++++-------
 lib/tc.h | 34 ++++++++++++++++++----------------
 2 files changed, 26 insertions(+), 23 deletions(-)
diff mbox series

Patch

diff --git a/lib/tc.c b/lib/tc.c
index 4c07e22162e7..87615e979f1a 100644
--- a/lib/tc.c
+++ b/lib/tc.c
@@ -698,7 +698,7 @@  nl_parse_geneve_key(const struct nlattr *in_nlattr,
 
 static int
 nl_parse_flower_tunnel_opts(struct nlattr *options,
-                            struct tun_metadata *metadata)
+                            struct tc_flower_tunnel *tunnel)
 {
     const struct ofpbuf *msg;
     struct nlattr *nla;
@@ -713,7 +713,7 @@  nl_parse_flower_tunnel_opts(struct nlattr *options,
         uint16_t type = nl_attr_type(nla);
         switch (type) {
         case TCA_FLOWER_KEY_ENC_OPTS_GENEVE:
-            err = nl_parse_geneve_key(nla, metadata);
+            err = nl_parse_geneve_key(nla, &tunnel->metadata);
             if (err) {
                 return err;
             }
@@ -825,13 +825,13 @@  nl_parse_flower_tunnel(struct nlattr **attrs, struct tc_flower *flower)
     if (attrs[TCA_FLOWER_KEY_ENC_OPTS] &&
         attrs[TCA_FLOWER_KEY_ENC_OPTS_MASK]) {
          err = nl_parse_flower_tunnel_opts(attrs[TCA_FLOWER_KEY_ENC_OPTS],
-                                           &flower->key.tunnel.metadata);
+                                           &flower->key.tunnel);
          if (err) {
              return err;
          }
 
          err = nl_parse_flower_tunnel_opts(attrs[TCA_FLOWER_KEY_ENC_OPTS_MASK],
-                                           &flower->mask.tunnel.metadata);
+                                           &flower->mask.tunnel);
          if (err) {
              return err;
          }
@@ -3431,8 +3431,9 @@  nl_msg_put_masked_value(struct ofpbuf *request, uint16_t type,
 
 static void
 nl_msg_put_flower_tunnel_opts(struct ofpbuf *request, uint16_t type,
-                              struct tun_metadata *metadata)
+                              struct tc_flower_tunnel *tunnel)
 {
+    struct tun_metadata *metadata = &tunnel->metadata;
     struct geneve_opt *opt;
     size_t outer, inner;
     int len, cnt = 0;
@@ -3521,9 +3522,9 @@  nl_msg_put_flower_tunnel(struct ofpbuf *request, struct tc_flower *flower)
         nl_msg_put_be32(request, TCA_FLOWER_KEY_ENC_KEY_ID, id);
     }
     nl_msg_put_flower_tunnel_opts(request, TCA_FLOWER_KEY_ENC_OPTS,
-                                  &flower->key.tunnel.metadata);
+                                  &flower->key.tunnel);
     nl_msg_put_flower_tunnel_opts(request, TCA_FLOWER_KEY_ENC_OPTS_MASK,
-                                  &flower->mask.tunnel.metadata);
+                                  &flower->mask.tunnel);
 }
 
 #define FLOWER_PUT_MASKED_VALUE(member, type) \
diff --git a/lib/tc.h b/lib/tc.h
index cdd3b4f60ec8..b9d449677ed9 100644
--- a/lib/tc.h
+++ b/lib/tc.h
@@ -105,6 +105,23 @@  struct tc_cookie {
     size_t len;
 };
 
+struct tc_flower_tunnel {
+    struct {
+        ovs_be32 ipv4_src;
+        ovs_be32 ipv4_dst;
+    } ipv4;
+    struct {
+        struct in6_addr ipv6_src;
+        struct in6_addr ipv6_dst;
+    } ipv6;
+    uint8_t tos;
+    uint8_t ttl;
+    ovs_be16 tp_src;
+    ovs_be16 tp_dst;
+    ovs_be64 id;
+    struct tun_metadata metadata;
+};
+
 struct tc_flower_key {
     ovs_be16 eth_type;
     uint8_t ip_proto;
@@ -161,22 +178,7 @@  struct tc_flower_key {
         uint8_t rewrite_tclass;
     } ipv6;
 
-    struct {
-        struct {
-            ovs_be32 ipv4_src;
-            ovs_be32 ipv4_dst;
-        } ipv4;
-        struct {
-            struct in6_addr ipv6_src;
-            struct in6_addr ipv6_dst;
-        } ipv6;
-        uint8_t tos;
-        uint8_t ttl;
-        ovs_be16 tp_src;
-        ovs_be16 tp_dst;
-        ovs_be64 id;
-        struct tun_metadata metadata;
-    } tunnel;
+    struct tc_flower_tunnel tunnel;
 };
 
 enum tc_action_type {