aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/ipip
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet/ipip')
-rw-r--r--src/vnet/ipip/ipip.api34
-rw-r--r--src/vnet/ipip/ipip_api.c60
2 files changed, 48 insertions, 46 deletions
diff --git a/src/vnet/ipip/ipip.api b/src/vnet/ipip/ipip.api
index 3dc087c954f..e8051fde7f8 100644
--- a/src/vnet/ipip/ipip.api
+++ b/src/vnet/ipip/ipip.api
@@ -1,3 +1,4 @@
+/* Hey Emacs use -*- mode: C -*- */
/*
* Copyright (c) 2018 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -48,8 +49,23 @@
*
*/
-option version = "1.1.0";
+option version = "1.2.0";
import "vnet/interface_types.api";
+import "vnet/ip/ip_types.api";
+
+/**
+ * An IP{v4,v6} over IP{v4,v6} tunnel.
+ */
+typedef ipip_tunnel
+{
+ u32 instance; /* If non-~0, specifies a custom dev instance */
+ vl_api_address_t src;
+ vl_api_address_t dst;
+ u32 sw_if_index; /* ignored on create, set in details/dump */
+u32 table_id;
+ u8 tc_tos; /* If ~0, the TOS/TC value is copied from
+ inner packet, otherwise set to value */
+};
/**
* Create an IP{v4,v6} over IP{v4,v6} tunnel.
@@ -58,13 +74,7 @@ define ipip_add_tunnel
{
u32 client_index;
u32 context;
- u8 is_ipv6;
- u32 instance; /* If non-~0, specifies a custom dev instance */
- u8 src_address[16];
- u8 dst_address[16];
- u32 table_id;
- u8 tc_tos; /* If ~0, the TOS/TC value is copied from
- inner packet, otherwise set to value */
+ vl_api_ipip_tunnel_t tunnel;
};
define ipip_add_tunnel_reply
@@ -133,13 +143,7 @@ define ipip_tunnel_dump
define ipip_tunnel_details
{
u32 context;
- vl_api_interface_index_t sw_if_index;
- u32 instance;
- u8 is_ipv6;
- u8 src_address[16];
- u8 dst_address[16];
- u32 fib_index;
- u8 tc_tos;
+ vl_api_ipip_tunnel_t tunnel;
};
/*
diff --git a/src/vnet/ipip/ipip_api.c b/src/vnet/ipip/ipip_api.c
index 2abac0b9772..f97aaf78bd4 100644
--- a/src/vnet/ipip/ipip_api.c
+++ b/src/vnet/ipip/ipip_api.c
@@ -22,6 +22,7 @@
#include <vnet/ipip/ipip.h>
#include <vnet/vnet.h>
#include <vnet/vnet_msg_enum.h>
+#include <vnet/ip/ip_types_api.h>
#define vl_typedefs /* define message structures */
#include <vnet/vnet_all_api_h.h>
@@ -52,23 +53,26 @@ 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;
- ip46_address_t src = ip46_address_initializer, dst =
- ip46_address_initializer;
+ ip46_address_t src, dst;
+ ip46_type_t itype[2];
- /* ip addresses sent in network byte order */
- if (mp->is_ipv6)
+ itype[0] = ip_address_decode (&mp->tunnel.src, &src);
+ itype[1] = ip_address_decode (&mp->tunnel.dst, &dst);
+
+ if (itype[0] != itype[1])
{
- clib_memcpy (&src.ip6, mp->src_address, 16);
- clib_memcpy (&dst.ip6, mp->dst_address, 16);
+ rv = VNET_API_ERROR_INVALID_PROTOCOL;
+ goto out;
}
- else
+
+ if (ip46_address_is_equal (&src, &dst))
{
- clib_memcpy (&src.ip4, mp->src_address, 4);
- clib_memcpy (&dst.ip4, mp->dst_address, 4);
+ rv = VNET_API_ERROR_SAME_SRC_DST;
+ goto out;
}
- fib_index =
- fib_table_find (fib_ip_proto (mp->is_ipv6), ntohl (mp->table_id));
+ fib_index = fib_table_find (fib_proto_from_ip46 (itype[0]),
+ ntohl (mp->tunnel.table_id));
if (~0 == fib_index)
{
@@ -76,13 +80,14 @@ vl_api_ipip_add_tunnel_t_handler (vl_api_ipip_add_tunnel_t * mp)
}
else
{
- rv = ipip_add_tunnel ((mp->is_ipv6 ?
+ rv = ipip_add_tunnel ((itype[0] == IP46_TYPE_IP6 ?
IPIP_TRANSPORT_IP6 :
IPIP_TRANSPORT_IP4),
- ntohl (mp->instance), &src, &dst,
- fib_index, mp->tc_tos, &sw_if_index);
+ ntohl (mp->tunnel.instance), &src, &dst,
+ fib_index, mp->tunnel.tc_tos, &sw_if_index);
}
+out:
/* *INDENT-OFF* */
REPLY_MACRO2(VL_API_IPIP_ADD_TUNNEL_REPLY,
({
@@ -112,24 +117,17 @@ send_ipip_tunnel_details (ipip_tunnel_t * t,
rmp = vl_msg_api_alloc (sizeof (*rmp));
clib_memset (rmp, 0, sizeof (*rmp));
rmp->_vl_msg_id = htons (VL_API_IPIP_TUNNEL_DETAILS);
- if (is_ipv6)
- {
- clib_memcpy (rmp->src_address, &t->tunnel_src.ip6.as_u8, 16);
- clib_memcpy (rmp->dst_address, &t->tunnel_dst.ip6.as_u8, 16);
- ft = fib_table_get (t->fib_index, FIB_PROTOCOL_IP6);
- rmp->fib_index = htonl (ft->ft_table_id);
- }
- else
- {
- clib_memcpy (rmp->src_address, &t->tunnel_src.ip4.as_u8, 4);
- clib_memcpy (rmp->dst_address, &t->tunnel_dst.ip4.as_u8, 4);
- ft = fib_table_get (t->fib_index, FIB_PROTOCOL_IP4);
- rmp->fib_index = htonl (ft->ft_table_id);
- }
- rmp->instance = htonl (t->user_instance);
- rmp->sw_if_index = htonl (t->sw_if_index);
+
+ ip_address_encode (&t->tunnel_src, IP46_TYPE_ANY, &rmp->tunnel.src);
+ ip_address_encode (&t->tunnel_dst, IP46_TYPE_ANY, &rmp->tunnel.dst);
+
+ ft = fib_table_get (t->fib_index, (is_ipv6 ? FIB_PROTOCOL_IP6 :
+ FIB_PROTOCOL_IP4));
+
+ rmp->tunnel.table_id = htonl (ft->ft_table_id);
+ rmp->tunnel.instance = htonl (t->user_instance);
+ rmp->tunnel.sw_if_index = htonl (t->sw_if_index);
rmp->context = context;
- rmp->is_ipv6 = is_ipv6;
vl_api_send_msg (reg, (u8 *) rmp);
}