aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2019-05-26 11:34:27 -0700
committerOle Trøan <otroan@employees.org>2019-05-27 13:18:05 +0000
commitcbd0824d6cec24ea2502ffdcdb1666d090f848cf (patch)
tree488c969f7c7429e07d159cdec229e8f362ad1fdc
parentbbd6b746e09cc4ae4239173081d95349e0263759 (diff)
IPIP tunnel: use address types on API
Change-Id: Ida6a8f96bd858246e993250087bed45e7084ede1 Signed-off-by: Neale Ranns <nranns@cisco.com>
-rw-r--r--src/vnet/ipip/ipip.api34
-rw-r--r--src/vnet/ipip/ipip_api.c60
-rw-r--r--test/test_ipip.py46
-rw-r--r--test/vpp_papi_provider.py1
4 files changed, 73 insertions, 68 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);
}
diff --git a/test/test_ipip.py b/test/test_ipip.py
index 137e3c54dff..6f1d3b883c0 100644
--- a/test/test_ipip.py
+++ b/test/test_ipip.py
@@ -17,6 +17,19 @@ IPIP tests.
"""
+def ipip_add_tunnel(test, src, dst, table_id=0, tc_tos=0xff):
+ """ Add a IPIP tunnel """
+ return test.vapi.ipip_add_tunnel(
+ tunnel={
+ 'src': src,
+ 'dst': dst,
+ 'table_id': table_id,
+ 'instance': 0xffffffff,
+ 'tc_tos': tc_tos
+ }
+ )
+
+
class TestIPIP(VppTestCase):
""" IPIP Test Case """
@@ -71,10 +84,10 @@ class TestIPIP(VppTestCase):
p_payload = UDP(sport=1234, dport=1234)
# IPv4 transport
- rv = self.vapi.ipip_add_tunnel(
- src_address=self.pg0.local_ip4n,
- dst_address=self.pg1.remote_ip4n,
- is_ipv6=0, tc_tos=0xFF)
+ rv = ipip_add_tunnel(self,
+ self.pg0.local_ip4,
+ self.pg1.remote_ip4,
+ tc_tos=0xFF)
sw_if_index = rv.sw_if_index
# Set interface up and enable IP on it
@@ -226,9 +239,7 @@ class TestIPIP(VppTestCase):
def test_ipip_create(self):
""" ipip create / delete interface test """
- rv = self.vapi.ipip_add_tunnel(
- src_address=inet_pton(AF_INET, '1.2.3.4'),
- dst_address=inet_pton(AF_INET, '2.3.4.5'), is_ipv6=0)
+ rv = ipip_add_tunnel(self, '1.2.3.4', '2.3.4.5')
sw_if_index = rv.sw_if_index
self.vapi.ipip_del_tunnel(sw_if_index)
@@ -237,10 +248,7 @@ class TestIPIP(VppTestCase):
t = VppIpTable(self, 20)
t.add_vpp_config()
- rv = self.vapi.ipip_add_tunnel(
- src_address=inet_pton(AF_INET, '1.2.3.4'),
- dst_address=inet_pton(AF_INET, '2.3.4.5'), is_ipv6=0,
- table_id=20)
+ rv = ipip_add_tunnel(self, '1.2.3.4', '2.3.4.5', table_id=20)
sw_if_index = rv.sw_if_index
self.vapi.ipip_del_tunnel(sw_if_index)
@@ -283,9 +291,10 @@ class TestIPIP6(VppTestCase):
def setup_tunnel(self):
# IPv6 transport
- rv = self.vapi.ipip_add_tunnel(
- src_address=self.pg0.local_ip6n,
- dst_address=self.pg1.remote_ip6n, tc_tos=255)
+ rv = ipip_add_tunnel(self,
+ self.pg0.local_ip6,
+ self.pg1.remote_ip6,
+ tc_tos=255)
sw_if_index = rv.sw_if_index
self.tunnel_if_index = sw_if_index
@@ -502,9 +511,7 @@ class TestIPIP6(VppTestCase):
def test_ipip_create(self):
""" ipip create / delete interface test """
- rv = self.vapi.ipip_add_tunnel(
- src_address=inet_pton(AF_INET, '1.2.3.4'),
- dst_address=inet_pton(AF_INET, '2.3.4.5'), is_ipv6=0)
+ rv = ipip_add_tunnel(self, '1.2.3.4', '2.3.4.5')
sw_if_index = rv.sw_if_index
self.vapi.ipip_del_tunnel(sw_if_index)
@@ -513,10 +520,7 @@ class TestIPIP6(VppTestCase):
t = VppIpTable(self, 20)
t.add_vpp_config()
- rv = self.vapi.ipip_add_tunnel(
- src_address=inet_pton(AF_INET, '1.2.3.4'),
- dst_address=inet_pton(AF_INET, '2.3.4.5'), is_ipv6=0,
- table_id=20)
+ rv = ipip_add_tunnel(self, '1.2.3.4', '2.3.4.5', table_id=20)
sw_if_index = rv.sw_if_index
self.vapi.ipip_del_tunnel(sw_if_index)
diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py
index 8084a7ffd8d..f32a5a848a3 100644
--- a/test/vpp_papi_provider.py
+++ b/test/vpp_papi_provider.py
@@ -69,7 +69,6 @@ defaultmapping = {
'ip_punt_redirect': {'is_add': 1, },
'ip_table_add_del': {'is_add': 1, },
'ip_unnumbered_dump': {'sw_if_index': 4294967295, },
- 'ipip_add_tunnel': {'is_ipv6': 1, 'instance': 4294967295, },
'ipsec_interface_add_del_spd': {'is_add': 1, },
'ipsec_sad_entry_add_del': {'is_add': 1, },
'ipsec_spd_add_del': {'is_add': 1, },