diff mbox series

[ovs-dev,v10,2/5] tnl-ports: Support multiple nw_protos.

Message ID 20230324100538.70290-3-nmiki@yahoo-corp.jp
State Changes Requested
Headers show
Series userspace: Add SRv6 tunnel support. | 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 fail test: fail

Commit Message

Nobuhiro MIKI March 24, 2023, 10:05 a.m. UTC
In some tunnels, inner packet needs to support both IPv4
and IPv6. Therefore, this patch improves to allow two
protocols to be tied together in one tunneling.

Signed-off-by: Nobuhiro MIKI <nmiki@yahoo-corp.jp>
---
 lib/tnl-ports.c | 83 ++++++++++++++++++++++++++++++-------------------
 1 file changed, 51 insertions(+), 32 deletions(-)

Comments

Ilya Maximets March 24, 2023, 1:04 p.m. UTC | #1
On 3/24/23 11:05, Nobuhiro MIKI wrote:
> In some tunnels, inner packet needs to support both IPv4
> and IPv6. Therefore, this patch improves to allow two
> protocols to be tied together in one tunneling.
> 
> Signed-off-by: Nobuhiro MIKI <nmiki@yahoo-corp.jp>
> ---
>  lib/tnl-ports.c | 83 ++++++++++++++++++++++++++++++-------------------
>  1 file changed, 51 insertions(+), 32 deletions(-)
> 
> diff --git a/lib/tnl-ports.c b/lib/tnl-ports.c
> index 050eafa6b8c3..3948bc10e6b0 100644
> --- a/lib/tnl-ports.c
> +++ b/lib/tnl-ports.c
> @@ -161,40 +161,31 @@ map_insert_ipdev__(struct ip_device *ip_dev, char dev_name[],
>      }
>  }
>  
> -static uint8_t
> -tnl_type_to_nw_proto(const char type[])
> +static void
> +tnl_type_to_nw_proto(const char type[], uint8_t nw_protos[2])
>  {
> -    if (!strcmp(type, "geneve")) {
> -        return IPPROTO_UDP;
> +    nw_protos[0] = nw_protos[1] = 0;
> +
> +    if (!strcmp(type, "geneve") || !strcmp(type, "vxlan") ||
> +        !strcmp(type, "gtpu")) {
> +        nw_protos[0] = IPPROTO_UDP;
> +    } else if (!strcmp(type, "stt")) {
> +        nw_protos[0] = IPPROTO_TCP;
> +    } else if (!strcmp(type, "gre") || !strcmp(type, "erspan") ||
> +               !strcmp(type, "ip6erspan") || !strcmp(type, "ip6gre")) {
> +        nw_protos[0] = IPPROTO_GRE;
> +    } else if (!strcmp(type, "srv6")) {
> +        nw_protos[0] = IPPROTO_IPIP;
> +        nw_protos[1] = IPPROTO_IPV6;

This last srv6 part belongs to patch #4.

>      }
> -    if (!strcmp(type, "stt")) {
> -        return IPPROTO_TCP;
> -    }
> -    if (!strcmp(type, "gre") || !strcmp(type, "erspan") ||
> -        !strcmp(type, "ip6erspan") || !strcmp(type, "ip6gre")) {
> -        return IPPROTO_GRE;
> -    }
> -    if (!strcmp(type, "vxlan")) {
> -        return IPPROTO_UDP;
> -    }
> -    if (!strcmp(type, "gtpu")) {
> -        return IPPROTO_UDP;
> -    }
> -    return 0;
>  }
>  
> -void
> -tnl_port_map_insert(odp_port_t port, ovs_be16 tp_port,
> -                    const char dev_name[], const char type[])
> +static void
> +tnl_port_map_insert__(odp_port_t port, ovs_be16 tp_port,
> +                      const char dev_name[], uint8_t nw_proto)
>  {
>      struct tnl_port *p;
>      struct ip_device *ip_dev;
> -    uint8_t nw_proto;
> -
> -    nw_proto = tnl_type_to_nw_proto(type);
> -    if (!nw_proto) {
> -        return;
> -    }
>  
>      ovs_mutex_lock(&mutex);
>      LIST_FOR_EACH(p, node, &port_list) {
> @@ -220,6 +211,22 @@ out:
>      ovs_mutex_unlock(&mutex);
>  }
>  
> +void
> +tnl_port_map_insert(odp_port_t port, ovs_be16 tp_port,
> +                    const char dev_name[], const char type[])
> +{
> +    uint8_t nw_protos[2];
> +    int i;
> +
> +    tnl_type_to_nw_proto(type, nw_protos);
> +
> +    for (i = 0; i < 2; i++) {
> +        if (nw_protos[i]) {
> +            tnl_port_map_insert__(port, tp_port, dev_name, nw_protos[i]);
> +        }
> +    }
> +}
> +
>  static void
>  tnl_port_unref(const struct cls_rule *cr)
>  {
> @@ -256,14 +263,11 @@ ipdev_map_delete(struct ip_device *ip_dev, ovs_be16 tp_port, uint8_t nw_proto)
>      }
>  }
>  
> -void
> -tnl_port_map_delete(odp_port_t port, const char type[])
> +static void
> +tnl_port_map_delete__(odp_port_t port, uint8_t nw_proto)
>  {
>      struct tnl_port *p;
>      struct ip_device *ip_dev;
> -    uint8_t nw_proto;
> -
> -    nw_proto = tnl_type_to_nw_proto(type);
>  
>      ovs_mutex_lock(&mutex);
>      LIST_FOR_EACH_SAFE (p, node, &port_list) {
> @@ -280,6 +284,21 @@ tnl_port_map_delete(odp_port_t port, const char type[])
>      ovs_mutex_unlock(&mutex);
>  }
>  
> +void
> +tnl_port_map_delete(odp_port_t port, const char type[])
> +{
> +    uint8_t nw_protos[2];
> +    int i;
> +
> +    tnl_type_to_nw_proto(type, nw_protos);
> +
> +    for (i = 0; i < 2; i++) {
> +        if (nw_protos[i]) {
> +            tnl_port_map_delete__(port, nw_protos[i]);
> +        }
> +    }
> +}
> +
>  /* 'flow' is non-const to allow for temporary modifications during the lookup.
>   * Any changes are restored before returning. */
>  odp_port_t
diff mbox series

Patch

diff --git a/lib/tnl-ports.c b/lib/tnl-ports.c
index 050eafa6b8c3..3948bc10e6b0 100644
--- a/lib/tnl-ports.c
+++ b/lib/tnl-ports.c
@@ -161,40 +161,31 @@  map_insert_ipdev__(struct ip_device *ip_dev, char dev_name[],
     }
 }
 
-static uint8_t
-tnl_type_to_nw_proto(const char type[])
+static void
+tnl_type_to_nw_proto(const char type[], uint8_t nw_protos[2])
 {
-    if (!strcmp(type, "geneve")) {
-        return IPPROTO_UDP;
+    nw_protos[0] = nw_protos[1] = 0;
+
+    if (!strcmp(type, "geneve") || !strcmp(type, "vxlan") ||
+        !strcmp(type, "gtpu")) {
+        nw_protos[0] = IPPROTO_UDP;
+    } else if (!strcmp(type, "stt")) {
+        nw_protos[0] = IPPROTO_TCP;
+    } else if (!strcmp(type, "gre") || !strcmp(type, "erspan") ||
+               !strcmp(type, "ip6erspan") || !strcmp(type, "ip6gre")) {
+        nw_protos[0] = IPPROTO_GRE;
+    } else if (!strcmp(type, "srv6")) {
+        nw_protos[0] = IPPROTO_IPIP;
+        nw_protos[1] = IPPROTO_IPV6;
     }
-    if (!strcmp(type, "stt")) {
-        return IPPROTO_TCP;
-    }
-    if (!strcmp(type, "gre") || !strcmp(type, "erspan") ||
-        !strcmp(type, "ip6erspan") || !strcmp(type, "ip6gre")) {
-        return IPPROTO_GRE;
-    }
-    if (!strcmp(type, "vxlan")) {
-        return IPPROTO_UDP;
-    }
-    if (!strcmp(type, "gtpu")) {
-        return IPPROTO_UDP;
-    }
-    return 0;
 }
 
-void
-tnl_port_map_insert(odp_port_t port, ovs_be16 tp_port,
-                    const char dev_name[], const char type[])
+static void
+tnl_port_map_insert__(odp_port_t port, ovs_be16 tp_port,
+                      const char dev_name[], uint8_t nw_proto)
 {
     struct tnl_port *p;
     struct ip_device *ip_dev;
-    uint8_t nw_proto;
-
-    nw_proto = tnl_type_to_nw_proto(type);
-    if (!nw_proto) {
-        return;
-    }
 
     ovs_mutex_lock(&mutex);
     LIST_FOR_EACH(p, node, &port_list) {
@@ -220,6 +211,22 @@  out:
     ovs_mutex_unlock(&mutex);
 }
 
+void
+tnl_port_map_insert(odp_port_t port, ovs_be16 tp_port,
+                    const char dev_name[], const char type[])
+{
+    uint8_t nw_protos[2];
+    int i;
+
+    tnl_type_to_nw_proto(type, nw_protos);
+
+    for (i = 0; i < 2; i++) {
+        if (nw_protos[i]) {
+            tnl_port_map_insert__(port, tp_port, dev_name, nw_protos[i]);
+        }
+    }
+}
+
 static void
 tnl_port_unref(const struct cls_rule *cr)
 {
@@ -256,14 +263,11 @@  ipdev_map_delete(struct ip_device *ip_dev, ovs_be16 tp_port, uint8_t nw_proto)
     }
 }
 
-void
-tnl_port_map_delete(odp_port_t port, const char type[])
+static void
+tnl_port_map_delete__(odp_port_t port, uint8_t nw_proto)
 {
     struct tnl_port *p;
     struct ip_device *ip_dev;
-    uint8_t nw_proto;
-
-    nw_proto = tnl_type_to_nw_proto(type);
 
     ovs_mutex_lock(&mutex);
     LIST_FOR_EACH_SAFE (p, node, &port_list) {
@@ -280,6 +284,21 @@  tnl_port_map_delete(odp_port_t port, const char type[])
     ovs_mutex_unlock(&mutex);
 }
 
+void
+tnl_port_map_delete(odp_port_t port, const char type[])
+{
+    uint8_t nw_protos[2];
+    int i;
+
+    tnl_type_to_nw_proto(type, nw_protos);
+
+    for (i = 0; i < 2; i++) {
+        if (nw_protos[i]) {
+            tnl_port_map_delete__(port, nw_protos[i]);
+        }
+    }
+}
+
 /* 'flow' is non-const to allow for temporary modifications during the lookup.
  * Any changes are restored before returning. */
 odp_port_t