From: Gavin Li <gav...@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 <gav...@nvidia.com>
Reviewed-by: Roi Dayan <r...@nvidia.com>
Reviewed-by: Simon Horman <simon.hor...@corigine.com>
Acked-by: Eelco Chaudron <echau...@redhat.com>
---
 lib/tc.c | 15 ++++++++-------
 lib/tc.h | 34 ++++++++++++++++++----------------
 2 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/lib/tc.c b/lib/tc.c
index 270dc95ce53b..223fe6e5e5e9 100644
--- a/lib/tc.c
+++ b/lib/tc.c
@@ -701,7 +701,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;
@@ -716,7 +716,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;
             }
@@ -828,13 +828,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;
          }
@@ -3446,8 +3446,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;
@@ -3536,9 +3537,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 {
-- 
2.38.0

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to