summaryrefslogtreecommitdiffstats
path: root/src/vnet
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2019-12-29 23:55:18 +0000
committerDamjan Marion <dmarion@me.com>2020-01-27 20:40:30 +0000
commit59ff918ea5b86112ffc89054aa38107703354585 (patch)
tree0e6dc887ead19b7be828954a08b1e15da81ddb58 /src/vnet
parent3b37125bdb0251181f90a429a4532b339711cf89 (diff)
tunnel: Common types for IP tunnels
Type: refactor Signed-off-by: Neale Ranns <nranns@cisco.com> Change-Id: I18dcdb7af3e327f6cacdbcb1e52b89f13d6ba6e2
Diffstat (limited to 'src/vnet')
-rw-r--r--src/vnet/CMakeLists.txt19
-rw-r--r--src/vnet/gre/gre.api15
-rw-r--r--src/vnet/gre/gre.h23
-rw-r--r--src/vnet/gre/gre_api.c39
-rw-r--r--src/vnet/gre/interface.c37
-rw-r--r--src/vnet/gre/node.c12
-rw-r--r--src/vnet/ipip/ipip.api6
-rw-r--r--src/vnet/ipip/ipip.c40
-rw-r--r--src/vnet/ipip/ipip.h28
-rw-r--r--src/vnet/ipip/ipip_api.c8
-rw-r--r--src/vnet/ipip/ipip_cli.c4
-rw-r--r--src/vnet/ipip/ipip_types_api.c53
-rw-r--r--src/vnet/ipip/node.c4
-rw-r--r--src/vnet/ipsec/ipsec_api.c3
-rw-r--r--src/vnet/ipsec/ipsec_cli.c3
-rw-r--r--src/vnet/tunnel/tunnel.c58
-rw-r--r--src/vnet/tunnel/tunnel.h66
-rw-r--r--src/vnet/tunnel/tunnel_types.api (renamed from src/vnet/ipip/ipip_types.api)31
-rw-r--r--src/vnet/tunnel/tunnel_types_api.c87
-rw-r--r--src/vnet/tunnel/tunnel_types_api.h (renamed from src/vnet/ipip/ipip_types_api.h)18
20 files changed, 322 insertions, 232 deletions
diff --git a/src/vnet/CMakeLists.txt b/src/vnet/CMakeLists.txt
index 04a8b1d4e09..16d5cacdcd8 100644
--- a/src/vnet/CMakeLists.txt
+++ b/src/vnet/CMakeLists.txt
@@ -734,7 +734,6 @@ list(APPEND VNET_SOURCES
ipip/sixrd.c
ipip/ipip_api.c
ipip/ipip_cli.c
- ipip/ipip_types_api.c
)
list(APPEND VNET_MULTIARCH_SOURCES
@@ -743,15 +742,29 @@ list(APPEND VNET_MULTIARCH_SOURCES
list(APPEND VNET_HEADERS
ipip/ipip.h
- ipip/ipip_types_api.h
)
list(APPEND VNET_API_FILES
- ipip/ipip_types.api
ipip/ipip.api
)
##############################################################################
+# Tunnel infra
+##############################################################################
+list(APPEND VNET_SOURCES
+ tunnel/tunnel.c
+ tunnel/tunnel_types_api.c
+)
+
+list(APPEND VNET_API_FILES
+ tunnel/tunnel_types.api
+)
+
+list(APPEND VNET_HEADERS
+ tunnel/tunnel.h
+)
+
+##############################################################################
# Tunnel protocol: l2tpv3
##############################################################################
list(APPEND VNET_SOURCES
diff --git a/src/vnet/gre/gre.api b/src/vnet/gre/gre.api
index d79beebb94d..0a98178ca87 100644
--- a/src/vnet/gre/gre.api
+++ b/src/vnet/gre/gre.api
@@ -14,9 +14,10 @@
* limitations under the License.
*/
-option version = "2.0.1";
+option version = "2.0.2";
import "vnet/interface_types.api";
+import "vnet/tunnel/tunnel_types.api";
import "vnet/ip/ip_types.api";
/** \brief A GRE tunnel type
@@ -28,16 +29,6 @@ enum gre_tunnel_type : u8
GRE_API_TUNNEL_TYPE_ERSPAN,
};
-/** \brief A GRE tunnel mode
-*/
-enum gre_tunnel_mode : u8
-{
- /* point-to-point */
- GRE_API_TUNNEL_MODE_P2P,
- /* multi-point */
- GRE_API_TUNNEL_MODE_MP,
-};
-
/** \brief A GRE tunnel
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
@@ -52,7 +43,7 @@ enum gre_tunnel_mode : u8
typedef gre_tunnel
{
vl_api_gre_tunnel_type_t type;
- vl_api_gre_tunnel_mode_t mode;
+ vl_api_tunnel_mode_t mode;
u16 session_id;
u32 instance;
u32 outer_table_id;
diff --git a/src/vnet/gre/gre.h b/src/vnet/gre/gre.h
index 6989cf48ea0..7f6ff0be9dc 100644
--- a/src/vnet/gre/gre.h
+++ b/src/vnet/gre/gre.h
@@ -24,6 +24,7 @@
#include <vnet/pg/pg.h>
#include <vnet/ip/format.h>
#include <vnet/adj/adj_types.h>
+#include <vnet/tunnel/tunnel.h>
extern vnet_hw_interface_class_t gre_hw_interface_class;
extern vnet_hw_interface_class_t mgre_hw_interface_class;
@@ -61,18 +62,6 @@ typedef enum gre_tunnel_type_t_
extern u8 *format_gre_tunnel_type (u8 * s, va_list * args);
-#define foreach_gre_tunnel_mode \
- _(P2P, "point-to-point") \
- _(MP, "multi-point") \
-
-typedef enum gre_tunnel_mode_t_
-{
-#define _(n, s) GRE_TUNNEL_MODE_##n,
- foreach_gre_tunnel_mode
-#undef _
-} __clib_packed gre_tunnel_mode_t;
-
-extern u8 *format_gre_tunnel_mode (u8 * s, va_list * args);
/**
* A GRE payload protocol registration
@@ -107,7 +96,7 @@ typedef struct gre_tunnel_key_common_t_
u32 fib_index;
u16 session_id;
gre_tunnel_type_t type;
- gre_tunnel_mode_t mode;
+ tunnel_mode_t mode;
};
u64 as_u64;
};
@@ -215,7 +204,7 @@ typedef struct
u32 hw_if_index;
u32 sw_if_index;
gre_tunnel_type_t type;
- gre_tunnel_mode_t mode;
+ tunnel_mode_t mode;
/**
* an L2 tunnel always rquires an L2 midchain. cache here for DP.
@@ -363,7 +352,7 @@ typedef struct
{
u8 is_add;
gre_tunnel_type_t type;
- gre_tunnel_mode_t mode;
+ tunnel_mode_t mode;
u8 is_ipv6;
u32 instance;
ip46_address_t src, dst;
@@ -379,7 +368,7 @@ gre_mk_key4 (ip4_address_t src,
ip4_address_t dst,
u32 fib_index,
gre_tunnel_type_t ttype,
- gre_tunnel_mode_t tmode, u16 session_id, gre_tunnel_key4_t * key)
+ tunnel_mode_t tmode, u16 session_id, gre_tunnel_key4_t * key)
{
key->gtk_src = src;
key->gtk_dst = dst;
@@ -402,7 +391,7 @@ gre_mk_key6 (const ip6_address_t * src,
const ip6_address_t * dst,
u32 fib_index,
gre_tunnel_type_t ttype,
- gre_tunnel_mode_t tmode, u16 session_id, gre_tunnel_key6_t * key)
+ tunnel_mode_t tmode, u16 session_id, gre_tunnel_key6_t * key)
{
key->gtk_src = *src;
key->gtk_dst = *dst;
diff --git a/src/vnet/gre/gre_api.c b/src/vnet/gre/gre_api.c
index be91f758777..619b5fc233c 100644
--- a/src/vnet/gre/gre_api.c
+++ b/src/vnet/gre/gre_api.c
@@ -25,6 +25,7 @@
#include <vnet/gre/gre.h>
#include <vnet/fib/fib_table.h>
+#include <vnet/tunnel/tunnel_types_api.h>
#include <vnet/ip/ip_types_api.h>
#include <vnet/vnet_msg_enum.h>
@@ -83,40 +84,6 @@ gre_tunnel_type_encode (gre_tunnel_type_t in)
return (out);
}
-static int
-gre_tunnel_mode_decode (vl_api_gre_tunnel_mode_t in, gre_tunnel_mode_t * out)
-{
- switch (in)
- {
-#define _(n, v) \
- case GRE_API_TUNNEL_MODE_##n: \
- *out = GRE_TUNNEL_MODE_##n; \
- return (0);
- foreach_gre_tunnel_mode
-#undef _
- }
-
- return (VNET_API_ERROR_INVALID_VALUE_2);
-}
-
-static vl_api_gre_tunnel_mode_t
-gre_tunnel_mode_encode (gre_tunnel_mode_t in)
-{
- vl_api_gre_tunnel_mode_t out = GRE_API_TUNNEL_MODE_P2P;
-
- switch (in)
- {
-#define _(n, v) \
- case GRE_TUNNEL_MODE_##n: \
- out = GRE_API_TUNNEL_MODE_##n; \
- break;
- foreach_gre_tunnel_mode
-#undef _
- }
-
- return (out);
-}
-
static void vl_api_gre_tunnel_add_del_t_handler
(vl_api_gre_tunnel_add_del_t * mp)
{
@@ -146,7 +113,7 @@ static void vl_api_gre_tunnel_add_del_t_handler
if (rv)
goto out;
- rv = gre_tunnel_mode_decode (mp->tunnel.mode, &a->mode);
+ rv = tunnel_mode_decode (mp->tunnel.mode, &a->mode);
if (rv)
goto out;
@@ -185,7 +152,7 @@ static void send_gre_tunnel_details
(t->outer_fib_index, t->tunnel_dst.fp_proto));
rmp->tunnel.type = gre_tunnel_type_encode (t->type);
- rmp->tunnel.mode = gre_tunnel_mode_encode (t->mode);
+ rmp->tunnel.mode = tunnel_mode_encode (t->mode);
rmp->tunnel.instance = htonl (t->user_instance);
rmp->tunnel.sw_if_index = htonl (t->sw_if_index);
rmp->tunnel.session_id = htons (t->session_id);
diff --git a/src/vnet/gre/interface.c b/src/vnet/gre/interface.c
index fab12b4f9c0..59bf21d6dc2 100644
--- a/src/vnet/gre/interface.c
+++ b/src/vnet/gre/interface.c
@@ -44,23 +44,6 @@ format_gre_tunnel_type (u8 * s, va_list * args)
return (s);
}
-u8 *
-format_gre_tunnel_mode (u8 * s, va_list * args)
-{
- gre_tunnel_mode_t mode = va_arg (*args, int);
-
- switch (mode)
- {
-#define _(n, v) case GRE_TUNNEL_MODE_##n: \
- s = format (s, "%s", v); \
- break;
- foreach_gre_tunnel_mode
-#undef _
- }
-
- return (s);
-}
-
static u8 *
format_gre_tunnel (u8 * s, va_list * args)
{
@@ -73,7 +56,7 @@ format_gre_tunnel (u8 * s, va_list * args)
t->outer_fib_index, t->sw_if_index);
s = format (s, "payload %U ", format_gre_tunnel_type, t->type);
- s = format (s, "%U ", format_gre_tunnel_mode, t->mode);
+ s = format (s, "%U ", format_tunnel_mode, t->mode);
if (t->type == GRE_TUNNEL_TYPE_ERSPAN)
s = format (s, "session %d ", t->session_id);
@@ -212,12 +195,12 @@ gre_nhrp_mk_key (const gre_tunnel_t * t,
gre_mk_key4 (t->tunnel_src.ip4,
nh->fp_addr.ip4,
nhrp_entry_get_fib_index (ne),
- t->type, GRE_TUNNEL_MODE_P2P, 0, &key->gtk_v4);
+ t->type, TUNNEL_MODE_P2P, 0, &key->gtk_v4);
else
gre_mk_key6 (&t->tunnel_src.ip6,
&nh->fp_addr.ip6,
nhrp_entry_get_fib_index (ne),
- t->type, GRE_TUNNEL_MODE_P2P, 0, &key->gtk_v6);
+ t->type, TUNNEL_MODE_P2P, 0, &key->gtk_v6);
}
static void
@@ -336,7 +319,7 @@ vnet_gre_tunnel_add (vnet_gre_tunnel_add_del_args_t * a,
if (t->type == GRE_TUNNEL_TYPE_L3)
{
- if (t->mode == GRE_TUNNEL_MODE_P2P)
+ if (t->mode == TUNNEL_MODE_P2P)
hw_if_index =
vnet_register_interface (vnm, gre_device_class.index, t_idx,
gre_hw_interface_class.index, t_idx);
@@ -404,7 +387,7 @@ vnet_gre_tunnel_add (vnet_gre_tunnel_add_del_args_t * a,
gre_tunnel_db_add (t, &key);
- if (t->mode == GRE_TUNNEL_MODE_MP)
+ if (t->mode == TUNNEL_MODE_MP)
nhrp_walk_itf (t->sw_if_index, gre_tunnel_add_nhrp_walk, t);
if (t->type == GRE_TUNNEL_TYPE_ERSPAN)
@@ -460,7 +443,7 @@ vnet_gre_tunnel_delete (vnet_gre_tunnel_add_del_args_t * a,
if (NULL == t)
return VNET_API_ERROR_NO_SUCH_ENTRY;
- if (t->mode == GRE_TUNNEL_MODE_MP)
+ if (t->mode == TUNNEL_MODE_MP)
nhrp_walk_itf (t->sw_if_index, gre_tunnel_delete_nhrp_walk, t);
sw_if_index = t->sw_if_index;
@@ -518,7 +501,7 @@ vnet_gre_tunnel_add_del (vnet_gre_tunnel_add_del_args_t * a,
if (a->session_id > GTK_SESSION_ID_MAX)
return VNET_API_ERROR_INVALID_SESSION_ID;
- if (a->mode == GRE_TUNNEL_MODE_MP && !ip46_address_is_zero (&a->dst))
+ if (a->mode == TUNNEL_MODE_MP && !ip46_address_is_zero (&a->dst))
return (VNET_API_ERROR_INVALID_DST_ADDRESS);
if (a->is_add)
@@ -572,7 +555,7 @@ create_gre_tunnel_command_fn (vlib_main_t * vm,
u32 instance = ~0;
u32 outer_table_id = 0;
gre_tunnel_type_t t_type = GRE_TUNNEL_TYPE_L3;
- gre_tunnel_mode_t t_mode = GRE_TUNNEL_MODE_P2P;
+ tunnel_mode_t t_mode = TUNNEL_MODE_P2P;
u32 session_id = 0;
int rv;
u8 is_add = 1;
@@ -596,7 +579,7 @@ create_gre_tunnel_command_fn (vlib_main_t * vm,
else if (unformat (line_input, "outer-table-id %d", &outer_table_id))
;
else if (unformat (line_input, "multipoint"))
- t_mode = GRE_TUNNEL_MODE_MP;
+ t_mode = TUNNEL_MODE_MP;
else if (unformat (line_input, "teb"))
t_type = GRE_TUNNEL_TYPE_TEB;
else if (unformat (line_input, "erspan %d", &session_id))
@@ -615,7 +598,7 @@ create_gre_tunnel_command_fn (vlib_main_t * vm,
goto done;
}
- if (t_mode != GRE_TUNNEL_MODE_MP && ip46_address_is_zero (&dst))
+ if (t_mode != TUNNEL_MODE_MP && ip46_address_is_zero (&dst))
{
error = clib_error_return (0, "destination address not specified");
goto done;
diff --git a/src/vnet/gre/node.c b/src/vnet/gre/node.c
index 14fb0877a93..92523069f05 100644
--- a/src/vnet/gre/node.c
+++ b/src/vnet/gre/node.c
@@ -245,11 +245,11 @@ gre_input (vlib_main_t * vm,
gre_mk_key6 (&ip6[0]->dst_address,
&ip6[0]->src_address,
vnet_buffer (b[0])->ip.fib_index,
- type[0], GRE_TUNNEL_MODE_P2P, 0, &key[0].gtk_v6);
+ type[0], TUNNEL_MODE_P2P, 0, &key[0].gtk_v6);
gre_mk_key6 (&ip6[1]->dst_address,
&ip6[1]->src_address,
vnet_buffer (b[1])->ip.fib_index,
- type[1], GRE_TUNNEL_MODE_P2P, 0, &key[1].gtk_v6);
+ type[1], TUNNEL_MODE_P2P, 0, &key[1].gtk_v6);
matched[0] = gre_match_key6 (&cached_key.gtk_v6, &key[0].gtk_v6);
matched[1] = gre_match_key6 (&cached_key.gtk_v6, &key[1].gtk_v6);
}
@@ -258,11 +258,11 @@ gre_input (vlib_main_t * vm,
gre_mk_key4 (ip4[0]->dst_address,
ip4[0]->src_address,
vnet_buffer (b[0])->ip.fib_index,
- type[0], GRE_TUNNEL_MODE_P2P, 0, &key[0].gtk_v4);
+ type[0], TUNNEL_MODE_P2P, 0, &key[0].gtk_v4);
gre_mk_key4 (ip4[1]->dst_address,
ip4[1]->src_address,
vnet_buffer (b[1])->ip.fib_index,
- type[1], GRE_TUNNEL_MODE_P2P, 0, &key[1].gtk_v4);
+ type[1], TUNNEL_MODE_P2P, 0, &key[1].gtk_v4);
matched[0] = gre_match_key4 (&cached_key.gtk_v4, &key[0].gtk_v4);
matched[1] = gre_match_key4 (&cached_key.gtk_v4, &key[1].gtk_v4);
}
@@ -381,7 +381,7 @@ gre_input (vlib_main_t * vm,
gre_mk_key6 (&ip6[0]->dst_address,
&ip6[0]->src_address,
vnet_buffer (b[0])->ip.fib_index,
- type[0], GRE_TUNNEL_MODE_P2P, 0, &key[0].gtk_v6);
+ type[0], TUNNEL_MODE_P2P, 0, &key[0].gtk_v6);
matched[0] = gre_match_key6 (&cached_key.gtk_v6, &key[0].gtk_v6);
}
else
@@ -389,7 +389,7 @@ gre_input (vlib_main_t * vm,
gre_mk_key4 (ip4[0]->dst_address,
ip4[0]->src_address,
vnet_buffer (b[0])->ip.fib_index,
- type[0], GRE_TUNNEL_MODE_P2P, 0, &key[0].gtk_v4);
+ type[0], TUNNEL_MODE_P2P, 0, &key[0].gtk_v4);
matched[0] = gre_match_key4 (&cached_key.gtk_v4, &key[0].gtk_v4);
}
diff --git a/src/vnet/ipip/ipip.api b/src/vnet/ipip/ipip.api
index baf0e508cf0..8ba31363b17 100644
--- a/src/vnet/ipip/ipip.api
+++ b/src/vnet/ipip/ipip.api
@@ -49,11 +49,11 @@
*
*/
-option version = "2.0.0";
+option version = "2.0.1";
import "vnet/interface_types.api";
import "vnet/ip/ip_types.api";
-import "vnet/ipip/ipip_types.api";
+import "vnet/tunnel/tunnel_types.api";
/**
* An IP{v4,v6} over IP{v4,v6} tunnel.
@@ -66,7 +66,7 @@ typedef ipip_tunnel
vl_api_interface_index_t sw_if_index; /* ignored on create, set in
details/dump */
u32 table_id;
- vl_api_ipip_tunnel_flags_t flags;
+ vl_api_tunnel_encap_decap_flags_t flags;
vl_api_ip_dscp_t dscp; /* DSCP value for the tunnel encap,
ignored if ECNAP_COPY_DSCP flag is set */
};
diff --git a/src/vnet/ipip/ipip.c b/src/vnet/ipip/ipip.c
index d68e8152972..05460fbbe34 100644
--- a/src/vnet/ipip/ipip.c
+++ b/src/vnet/ipip/ipip.c
@@ -75,9 +75,9 @@ ipip_build_rewrite (vnet_main_t * vnm, u32 sw_if_index,
ip4->src_address.as_u32 = t->tunnel_src.ip4.as_u32;
ip4->dst_address.as_u32 = t->tunnel_dst.ip4.as_u32;
ip4->checksum = ip4_header_checksum (ip4);
- if (!(t->flags & IPIP_TUNNEL_FLAG_ENCAP_COPY_DSCP))
+ if (!(t->flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP))
ip4_header_set_dscp (ip4, t->dscp);
- if (t->flags & IPIP_TUNNEL_FLAG_ENCAP_SET_DF)
+ if (t->flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_SET_DF)
ip4_header_set_df (ip4);
break;
@@ -92,7 +92,7 @@ ipip_build_rewrite (vnet_main_t * vnm, u32 sw_if_index,
ip6->src_address.as_u64[1] = t->tunnel_src.ip6.as_u64[1];
ip6->dst_address.as_u64[0] = t->tunnel_dst.ip6.as_u64[0];
ip6->dst_address.as_u64[1] = t->tunnel_dst.ip6.as_u64[1];
- if (!(t->flags & IPIP_TUNNEL_FLAG_ENCAP_COPY_DSCP))
+ if (!(t->flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP))
ip6_set_dscp_network_order (ip6, t->dscp);
break;
@@ -116,11 +116,11 @@ ipip4_fixup (vlib_main_t * vm, const ip_adjacency_t * adj, vlib_buffer_t * b,
{
case VNET_LINK_IP6:
ip4->protocol = IP_PROTOCOL_IPV6;
- if (t->flags & IPIP_TUNNEL_FLAG_ENCAP_COPY_DSCP)
+ if (t->flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
ip4_header_set_dscp (ip4,
ip6_dscp_network_order ((ip6_header_t *) (ip4 +
1)));
- if (t->flags & IPIP_TUNNEL_FLAG_ENCAP_COPY_ECN)
+ if (t->flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN)
ip4_header_set_ecn (ip4,
ip6_ecn_network_order ((ip6_header_t *) (ip4 +
1)));
@@ -128,11 +128,11 @@ ipip4_fixup (vlib_main_t * vm, const ip_adjacency_t * adj, vlib_buffer_t * b,
case VNET_LINK_IP4:
ip4->protocol = IP_PROTOCOL_IP_IN_IP;
- if (t->flags & IPIP_TUNNEL_FLAG_ENCAP_COPY_DSCP)
+ if (t->flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
ip4_header_set_dscp (ip4, ip4_header_get_dscp (ip4 + 1));
- if (t->flags & IPIP_TUNNEL_FLAG_ENCAP_COPY_ECN)
+ if (t->flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN)
ip4_header_set_ecn (ip4, ip4_header_get_ecn (ip4 + 1));
- if ((t->flags & IPIP_TUNNEL_FLAG_ENCAP_COPY_DF) &&
+ if ((t->flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DF) &&
ip4_header_get_df (ip4 + 1))
ip4_header_set_df (ip4);
break;
@@ -163,18 +163,18 @@ ipip6_fixup (vlib_main_t * vm, const ip_adjacency_t * adj, vlib_buffer_t * b,
{
case VNET_LINK_IP6:
ip6->protocol = IP_PROTOCOL_IPV6;
- if (t->flags & IPIP_TUNNEL_FLAG_ENCAP_COPY_DSCP)
+ if (t->flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
ip6_set_dscp_network_order (ip6, ip6_dscp_network_order (ip6 + 1));
- if (t->flags & IPIP_TUNNEL_FLAG_ENCAP_COPY_ECN)
+ if (t->flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN)
ip6_set_ecn_network_order (ip6, ip6_ecn_network_order (ip6 + 1));
break;
case VNET_LINK_IP4:
ip6->protocol = IP_PROTOCOL_IP_IN_IP;
- if (t->flags & IPIP_TUNNEL_FLAG_ENCAP_COPY_DSCP)
+ if (t->flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
ip6_set_dscp_network_order
(ip6, ip4_header_get_dscp ((ip4_header_t *) (ip6 + 1)));
- if (t->flags & IPIP_TUNNEL_FLAG_ENCAP_COPY_ECN)
+ if (t->flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN)
ip6_set_ecn_network_order
(ip6, ip4_header_get_ecn ((ip4_header_t *) (ip6 + 1)));
break;
@@ -265,20 +265,6 @@ ipip_update_adj (vnet_main_t * vnm, u32 sw_if_index, adj_index_t ai)
ipip_tunnel_stack (ai);
}
-u8 *
-format_ipip_tunnel_flags (u8 * s, va_list * args)
-{
- ipip_tunnel_flags_t f = va_arg (*args, int);
-
- if (f == IPIP_TUNNEL_FLAG_NONE)
- return (format (s, "none"));
-
-#define _(a,b,c) if (f & IPIP_TUNNEL_FLAG_##a) s = format(s, "%s ", b);
- forech_ipip_tunnel_flag
-#undef _
- return (s);
-}
-
static u8 *
format_ipip_tunnel_name (u8 * s, va_list * args)
{
@@ -413,7 +399,7 @@ ipip_tunnel_db_remove (ipip_tunnel_t * t)
int
ipip_add_tunnel (ipip_transport_t transport,
u32 instance, ip46_address_t * src, ip46_address_t * dst,
- u32 fib_index, ipip_tunnel_flags_t flags,
+ u32 fib_index, tunnel_encap_decap_flags_t flags,
ip_dscp_t dscp, u32 * sw_if_indexp)
{
ipip_main_t *gm = &ipip_main;
diff --git a/src/vnet/ipip/ipip.h b/src/vnet/ipip/ipip.h
index be944507b40..a3732f75128 100644
--- a/src/vnet/ipip/ipip.h
+++ b/src/vnet/ipip/ipip.h
@@ -22,7 +22,7 @@
#include <vnet/ip/ip6_packet.h>
#include <vnet/ip/format.h>
#include <vnet/ip/ip.h>
-#include <vnet/vnet.h>
+#include <vnet/tunnel/tunnel.h>
extern vnet_hw_interface_class_t ipip_hw_interface_class;
@@ -65,28 +65,6 @@ typedef enum
} ipip_mode_t;
/**
- * Keep these idenitical to those in ipip.api
- */
-#define forech_ipip_tunnel_flag \
- _(NONE, "none", 0x0) \
- _(ENCAP_COPY_DF, "encap-copy-df", 0x1) \
- _(ENCAP_SET_DF, "encap-set-df", 0x2) \
- _(ENCAP_COPY_DSCP, "encap-copy-dscp", 0x4) \
- _(ENCAP_COPY_ECN, "encap-copy-ecn", 0x8) \
- _(DECAP_COPY_ECN, "decap-copy-ecn", 0x10)
-
-typedef enum ipip_tunnel_flags_t_
-{
-#define _(a,b,c) IPIP_TUNNEL_FLAG_##a = c,
- forech_ipip_tunnel_flag
-#undef _
-} __clib_packed ipip_tunnel_flags_t;
-
-#define IPIP_TUNNEL_FLAG_MASK (0x1f)
-
-extern u8 *format_ipip_tunnel_flags (u8 * s, va_list * args);
-
-/**
* @brief A representation of a IPIP tunnel
*/
typedef struct
@@ -104,7 +82,7 @@ typedef struct
u32 sw_if_index;
u32 dev_instance; /* Real device instance in tunnel vector */
u32 user_instance; /* Instance name being shown to user */
- ipip_tunnel_flags_t flags;
+ tunnel_encap_decap_flags_t flags;
ip_dscp_t dscp;
struct
@@ -166,7 +144,7 @@ sixrd_get_addr_net (const ipip_tunnel_t * t, u64 dal)
int ipip_add_tunnel (ipip_transport_t transport, u32 instance,
ip46_address_t * src, ip46_address_t * dst,
- u32 fib_index, ipip_tunnel_flags_t flags,
+ u32 fib_index, tunnel_encap_decap_flags_t flags,
ip_dscp_t dscp, u32 * sw_if_indexp);
int ipip_del_tunnel (u32 sw_if_index);
int sixrd_add_tunnel (ip6_address_t * ip6_prefix, u8 ip6_prefix_len,
diff --git a/src/vnet/ipip/ipip_api.c b/src/vnet/ipip/ipip_api.c
index 47ff159b703..4f6aa7f3dbe 100644
--- a/src/vnet/ipip/ipip_api.c
+++ b/src/vnet/ipip/ipip_api.c
@@ -22,7 +22,7 @@
#include <vnet/ipip/ipip.h>
#include <vnet/vnet.h>
#include <vnet/ip/ip_types_api.h>
-#include <vnet/ipip/ipip_types_api.h>
+#include <vnet/tunnel/tunnel_types_api.h>
#include <vnet/ipip/ipip.api_enum.h>
#include <vnet/ipip/ipip.api_types.h>
@@ -37,7 +37,7 @@ vl_api_ipip_add_tunnel_t_handler (vl_api_ipip_add_tunnel_t * mp)
vl_api_ipip_add_tunnel_reply_t *rmp;
int rv = 0;
u32 fib_index, sw_if_index = ~0;
- ipip_tunnel_flags_t flags;
+ tunnel_encap_decap_flags_t flags;
ip46_address_t src, dst;
ip46_type_t itype[2];
@@ -56,7 +56,7 @@ vl_api_ipip_add_tunnel_t_handler (vl_api_ipip_add_tunnel_t * mp)
goto out;
}
- rv = ipip_tunnel_flags_decode (mp->tunnel.flags, &flags);
+ rv = tunnel_encap_decap_flags_decode (mp->tunnel.flags, &flags);
if (rv)
goto out;
@@ -119,7 +119,7 @@ send_ipip_tunnel_details (ipip_tunnel_t * t, vl_api_ipip_tunnel_dump_t * mp)
rmp->tunnel.instance = htonl (t->user_instance);
rmp->tunnel.sw_if_index = htonl (t->sw_if_index);
rmp->tunnel.dscp = ip_dscp_encode(t->dscp);
- rmp->tunnel.flags = ipip_tunnel_flags_encode(t->flags);
+ rmp->tunnel.flags = tunnel_encap_decap_flags_encode(t->flags);
}));
/* *INDENT-ON* */
}
diff --git a/src/vnet/ipip/ipip_cli.c b/src/vnet/ipip/ipip_cli.c
index e252f3a519e..09f2ebae228 100644
--- a/src/vnet/ipip/ipip_cli.c
+++ b/src/vnet/ipip/ipip_cli.c
@@ -82,7 +82,7 @@ static clib_error_t *create_ipip_tunnel_command_fn(vlib_main_t *vm,
&src,
&dst,
fib_index,
- IPIP_TUNNEL_FLAG_NONE,
+ TUNNEL_ENCAP_DECAP_FLAG_NONE,
IP_DSCP_CS0,
&sw_if_index);
}
@@ -192,7 +192,7 @@ static u8 *format_ipip_tunnel(u8 *s, va_list *args) {
s = format(s, "table-ID %d sw-if-idx %d flags [%U] dscp %U",
table_id, t->sw_if_index,
- format_ipip_tunnel_flags, t->flags,
+ format_tunnel_encap_decap_flags, t->flags,
format_ip_dscp, t->dscp);
return s;
diff --git a/src/vnet/ipip/ipip_types_api.c b/src/vnet/ipip/ipip_types_api.c
deleted file mode 100644
index 5625b85af68..00000000000
--- a/src/vnet/ipip/ipip_types_api.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * ipip_api.c - ipip api
- *
- * Copyright (c) 2018 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <vnet/api_errno.h>
-#include <vnet/ipip/ipip_types_api.h>
-
-#include <vnet/ipip/ipip_types.api_enum.h>
-#include <vnet/ipip/ipip_types.api_types.h>
-
-
-STATIC_ASSERT (sizeof (vl_api_ipip_tunnel_flags_t) ==
- sizeof (ipip_tunnel_flags_t),
- "IPIP tunnel API and internal flags enum size differ");
-
-int
-ipip_tunnel_flags_decode (vl_api_ipip_tunnel_flags_t f,
- ipip_tunnel_flags_t * o)
-{
- if (f & ~IPIP_TUNNEL_FLAG_MASK)
- /* unknown flags set */
- return (VNET_API_ERROR_INVALID_VALUE_2);
-
- *o = (ipip_tunnel_flags_t) f;
- return (0);
-}
-
-vl_api_ipip_tunnel_flags_t
-ipip_tunnel_flags_encode (ipip_tunnel_flags_t f)
-{
- return ((vl_api_ipip_tunnel_flags_t) f);
-}
-
-/*
- * fd.io coding-style-patch-verification: ON
- *
- * Local Variables:
- * eval: (c-set-style "gnu")
- * End:
- */
diff --git a/src/vnet/ipip/node.c b/src/vnet/ipip/node.c
index cd26b8a8b85..bc0250ad6ef 100644
--- a/src/vnet/ipip/node.c
+++ b/src/vnet/ipip/node.c
@@ -161,7 +161,7 @@ ipip_input (vlib_main_t * vm, vlib_node_runtime_t * node,
{
next0 = IPIP_INPUT_NEXT_IP6_INPUT;
- if (t0->flags & IPIP_TUNNEL_FLAG_DECAP_COPY_ECN)
+ if (t0->flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN)
{
if (is_ipv6)
ip6_set_ecn_network_order ((ip60 + 1),
@@ -174,7 +174,7 @@ ipip_input (vlib_main_t * vm, vlib_node_runtime_t * node,
else if (inner_protocol0 == IP_PROTOCOL_IP_IN_IP)
{
next0 = IPIP_INPUT_NEXT_IP4_INPUT;
- if (t0->flags & IPIP_TUNNEL_FLAG_DECAP_COPY_ECN)
+ if (t0->flags & TUNNEL_ENCAP_DECAP_FLAG_DECAP_COPY_ECN)
{
if (is_ipv6)
ip4_header_set_ecn_w_chksum ((ip4_header_t *) (ip60 + 1),
diff --git a/src/vnet/ipsec/ipsec_api.c b/src/vnet/ipsec/ipsec_api.c
index 4252acd2688..87f59313e55 100644
--- a/src/vnet/ipsec/ipsec_api.c
+++ b/src/vnet/ipsec/ipsec_api.c
@@ -646,7 +646,8 @@ vl_api_ipsec_tunnel_if_add_del_t_handler (vl_api_ipsec_tunnel_if_add_del_t *
(mp->renumber ? ntohl (mp->show_instance) : ~0),
&local_ip,
&remote_ip, fib_index,
- IPIP_TUNNEL_FLAG_NONE, IP_DSCP_CS0, &sw_if_index);
+ TUNNEL_ENCAP_DECAP_FLAG_NONE, IP_DSCP_CS0,
+ &sw_if_index);
if (rv)
goto done;
diff --git a/src/vnet/ipsec/ipsec_cli.c b/src/vnet/ipsec/ipsec_cli.c
index e4121605fdc..f04ccc8dc8a 100644
--- a/src/vnet/ipsec/ipsec_cli.c
+++ b/src/vnet/ipsec/ipsec_cli.c
@@ -842,7 +842,8 @@ create_ipsec_tunnel_command_fn (vlib_main_t * vm,
rv =
ipip_add_tunnel (ipv6_set ? IPIP_TRANSPORT_IP6 : IPIP_TRANSPORT_IP4,
instance, &local_ip, &remote_ip, fib_index,
- IPIP_TUNNEL_FLAG_NONE, IP_DSCP_CS0, &sw_if_index);
+ TUNNEL_ENCAP_DECAP_FLAG_NONE, IP_DSCP_CS0,
+ &sw_if_index);
rv |=
ipsec_sa_add_and_lock (ipsec_tun_mk_local_sa_id (sw_if_index),
local_spi, IPSEC_PROTOCOL_ESP, crypto_alg,
diff --git a/src/vnet/tunnel/tunnel.c b/src/vnet/tunnel/tunnel.c
new file mode 100644
index 00000000000..83b1046b526
--- /dev/null
+++ b/src/vnet/tunnel/tunnel.c
@@ -0,0 +1,58 @@
+/*
+ * tunnel.h: shared definitions for tunnels.
+ *
+ * Copyright (c) 2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <vnet/tunnel/tunnel.h>
+
+u8 *
+format_tunnel_mode (u8 * s, va_list * args)
+{
+ tunnel_mode_t mode = va_arg (*args, int);
+
+ switch (mode)
+ {
+#define _(n, v) case TUNNEL_MODE_##n: \
+ s = format (s, "%s", v); \
+ break;
+ foreach_tunnel_mode
+#undef _
+ }
+
+ return (s);
+}
+
+u8 *
+format_tunnel_encap_decap_flags (u8 * s, va_list * args)
+{
+ tunnel_encap_decap_flags_t f = va_arg (*args, int);
+
+ if (f == TUNNEL_ENCAP_DECAP_FLAG_NONE)
+ return (format (s, "none"));
+
+#define _(a,b,c) if (f & TUNNEL_ENCAP_DECAP_FLAG_##a) s = format(s, "%s ", b);
+ forech_tunnel_encap_decap_flag
+#undef _
+ return (s);
+}
+
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vnet/tunnel/tunnel.h b/src/vnet/tunnel/tunnel.h
new file mode 100644
index 00000000000..e3390f5a165
--- /dev/null
+++ b/src/vnet/tunnel/tunnel.h
@@ -0,0 +1,66 @@
+/*
+ * tunnel.h: shared definitions for tunnels.
+ *
+ * Copyright (c) 2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TUNNEL_H__
+#define __TUNNEL_H__
+
+#include <vlib/vlib.h>
+
+#define foreach_tunnel_mode \
+ _(P2P, "point-to-point") \
+ _(MP, "multi-point") \
+
+typedef enum tunnel_mode_t_
+{
+#define _(n, s) TUNNEL_MODE_##n,
+ foreach_tunnel_mode
+#undef _
+} __clib_packed tunnel_mode_t;
+
+extern u8 *format_tunnel_mode (u8 * s, va_list * args);
+
+/**
+ * Keep these idenitical to those in ipip.api
+ */
+#define forech_tunnel_encap_decap_flag \
+ _(NONE, "none", 0x0) \
+ _(ENCAP_COPY_DF, "encap-copy-df", 0x1) \
+ _(ENCAP_SET_DF, "encap-set-df", 0x2) \
+ _(ENCAP_COPY_DSCP, "encap-copy-dscp", 0x4) \
+ _(ENCAP_COPY_ECN, "encap-copy-ecn", 0x8) \
+ _(DECAP_COPY_ECN, "decap-copy-ecn", 0x10)
+
+typedef enum tunnel_encap_decap_flags_t_
+{
+#define _(a,b,c) TUNNEL_ENCAP_DECAP_FLAG_##a = c,
+ forech_tunnel_encap_decap_flag
+#undef _
+} __clib_packed tunnel_encap_decap_flags_t;
+
+#define TUNNEL_FLAG_MASK (0x1f)
+
+extern u8 *format_tunnel_encap_decap_flags (u8 * s, va_list * args);
+
+#endif
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vnet/ipip/ipip_types.api b/src/vnet/tunnel/tunnel_types.api
index 3e52fe74c1d..103948d08c7 100644
--- a/src/vnet/ipip/ipip_types.api
+++ b/src/vnet/tunnel/tunnel_types.api
@@ -17,17 +17,34 @@
/**
* Flags controlling tunnel behaviour
*/
-enum ipip_tunnel_flags : u8
+enum tunnel_encap_decap_flags : u8
{
- IPIP_TUNNEL_API_FLAG_NONE = 0,
+ TUNNEL_API_ENCAP_DECAP_FLAG_NONE = 0,
/** at encap, copy the DF bit of the payload into the tunnel header */
- IPIP_TUNNEL_API_FLAG_ENCAP_COPY_DF = 0x1,
+ TUNNEL_API_ENCAP_DECAP_FLAG_ENCAP_COPY_DF = 0x1,
/** at encap, set the DF bit in the tunnel header */
- IPIP_TUNNEL_API_FLAG_ENCAP_SET_DF = 0x2,
+ TUNNEL_API_ENCAP_DECAP_FLAG_ENCAP_SET_DF = 0x2,
/** at encap, copy the DSCP bits of the payload into the tunnel header */
- IPIP_TUNNEL_API_FLAG_ENCAP_COPY_DSCP = 0x4,
+ TUNNEL_API_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP = 0x4,
/** at encap, copy the ECN bit of the payload into the tunnel header */
- IPIP_TUNNEL_API_FLAG_ENCAP_COPY_ECN = 0x8,
+ TUNNEL_API_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN = 0x8,
/** at decap, copy the ECN bit of the tunnel header into the payload */
- IPIP_TUNNEL_API_FLAG_DECAP_COPY_ECN = 0x10,
+ TUNNEL_API_ENCAP_DECAP_FLAG_DECAP_COPY_ECN = 0x10,
};
+
+/**
+ * tunnel mode
+ */
+enum tunnel_mode : u8
+{
+ /** point-to-point */
+ TUNNEL_API_MODE_P2P,
+ /** multi-point */
+ TUNNEL_API_MODE_MP,
+};
+
+/*
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vnet/tunnel/tunnel_types_api.c b/src/vnet/tunnel/tunnel_types_api.c
new file mode 100644
index 00000000000..1d48178e9df
--- /dev/null
+++ b/src/vnet/tunnel/tunnel_types_api.c
@@ -0,0 +1,87 @@
+/*
+ * tunnel_api.c - tunnel api
+ *
+ * Copyright (c) 2018 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <vnet/api_errno.h>
+#include <vnet/tunnel/tunnel_types_api.h>
+
+#include <vnet/tunnel/tunnel_types.api_enum.h>
+#include <vnet/tunnel/tunnel_types.api_types.h>
+
+
+STATIC_ASSERT (sizeof (vl_api_tunnel_encap_decap_flags_t) ==
+ sizeof (tunnel_encap_decap_flags_t),
+ "tunnel API and internal flags enum size differ");
+
+int
+tunnel_encap_decap_flags_decode (vl_api_tunnel_encap_decap_flags_t f,
+ tunnel_encap_decap_flags_t * o)
+{
+ if (f & ~TUNNEL_FLAG_MASK)
+ /* unknown flags set */
+ return (VNET_API_ERROR_INVALID_VALUE_2);
+
+ *o = (tunnel_encap_decap_flags_t) f;
+ return (0);
+}
+
+vl_api_tunnel_encap_decap_flags_t
+tunnel_encap_decap_flags_encode (tunnel_encap_decap_flags_t f)
+{
+ return ((vl_api_tunnel_encap_decap_flags_t) f);
+}
+
+int
+tunnel_mode_decode (vl_api_tunnel_mode_t in, tunnel_mode_t * out)
+{
+ switch (in)
+ {
+#define _(n, v) \
+ case TUNNEL_API_MODE_##n: \
+ *out = TUNNEL_MODE_##n; \
+ return (0);
+ foreach_tunnel_mode
+#undef _
+ }
+
+ return (VNET_API_ERROR_INVALID_VALUE_2);
+}
+
+vl_api_tunnel_mode_t
+tunnel_mode_encode (tunnel_mode_t in)
+{
+ vl_api_tunnel_mode_t out = TUNNEL_API_MODE_P2P;
+
+ switch (in)
+ {
+#define _(n, v) \
+ case TUNNEL_MODE_##n: \
+ out = TUNNEL_API_MODE_##n; \
+ break;
+ foreach_tunnel_mode
+#undef _
+ }
+
+ return (out);
+}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vnet/ipip/ipip_types_api.h b/src/vnet/tunnel/tunnel_types_api.h
index 17b1f1bb210..06439dc87c1 100644
--- a/src/vnet/ipip/ipip_types_api.h
+++ b/src/vnet/tunnel/tunnel_types_api.h
@@ -13,22 +13,28 @@
* limitations under the License.
*/
-#ifndef __IPIP_TYPES_API_H__
-#define __IPIP_TYPES_API_H__
+#ifndef __TUNNEL_TYPES_API_H__
+#define __TUNNEL_TYPES_API_H__
/**
* Conversion functions to/from (decode/encode) API types to VPP internal types
*/
-#include <vnet/ipip/ipip.h>
-#include <vnet/ipip/ipip.api_types.h>
+#include <vnet/tunnel/tunnel.h>
+#include <vnet/tunnel/tunnel_types.api_types.h>
/**
* These enum decode/encodes use 'int' as the type for the enum because
* one cannot forward declare an enum
*/
-extern int ipip_tunnel_flags_decode (u8 _f, ipip_tunnel_flags_t * out);
-extern u8 ipip_tunnel_flags_encode (ipip_tunnel_flags_t f);
+extern int tunnel_encap_decap_flags_decode (vl_api_tunnel_encap_decap_flags_t
+ _f,
+ tunnel_encap_decap_flags_t * out);
+extern vl_api_tunnel_encap_decap_flags_t
+tunnel_encap_decap_flags_encode (tunnel_encap_decap_flags_t f);
+
+extern int tunnel_mode_decode (vl_api_tunnel_mode_t in, tunnel_mode_t * out);
+extern vl_api_tunnel_mode_t tunnel_mode_encode (tunnel_mode_t in);
#endif