summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2019-11-12 17:16:47 +0000
committerNeale Ranns <nranns@cisco.com>2019-12-02 21:44:10 +0000
commitd6d0edbf055ecabdec289727cef08becd9aca9b8 (patch)
tree222c75c3290d59fc3146197563353b6a74ebf8c5
parent77d760d708dcfe35aa805bd86381bc0bcb28f677 (diff)
ip: IP address and prefix types (moved from LISP)
Type: refactor Change-Id: I2c6b59013bfd21136a2955442c779685f951932b Signed-off-by: Neale Ranns <nranns@cisco.com> (cherry picked from commit ea93e48cf6e918937422638cb574964b88a146b6)
-rw-r--r--src/plugins/unittest/lisp_cp_test.c40
-rw-r--r--src/vat/api_format.c6
-rw-r--r--src/vnet/CMakeLists.txt2
-rw-r--r--src/vnet/ip/ip.h17
-rw-r--r--src/vnet/ip/ip_types.c287
-rw-r--r--src/vnet/ip/ip_types.h98
-rw-r--r--src/vnet/lisp-cp/control.c47
-rw-r--r--src/vnet/lisp-cp/gid_dictionary.c20
-rw-r--r--src/vnet/lisp-cp/lisp_api.c37
-rw-r--r--src/vnet/lisp-cp/lisp_types.c299
-rw-r--r--src/vnet/lisp-cp/lisp_types.h56
-rw-r--r--src/vnet/lisp-cp/one_api.c45
-rw-r--r--src/vnet/lisp-cp/one_cli.c2
-rw-r--r--src/vnet/lisp-cp/packets.c8
-rw-r--r--src/vnet/lisp-gpe/lisp_gpe.c10
-rw-r--r--src/vnet/lisp-gpe/lisp_gpe_adjacency.c8
-rw-r--r--src/vnet/lisp-gpe/lisp_gpe_api.c12
-rw-r--r--src/vnet/lisp-gpe/lisp_gpe_fwd_entry.c8
-rw-r--r--src/vnet/lisp-gpe/lisp_gpe_sub_interface.h4
-rw-r--r--src/vnet/lisp-gpe/lisp_gpe_tunnel.c2
-rw-r--r--test/test_lisp.py20
21 files changed, 545 insertions, 483 deletions
diff --git a/src/plugins/unittest/lisp_cp_test.c b/src/plugins/unittest/lisp_cp_test.c
index cda2c52e88a..3480b8cf8ee 100644
--- a/src/plugins/unittest/lisp_cp_test.c
+++ b/src/plugins/unittest/lisp_cp_test.c
@@ -82,11 +82,11 @@ test_lisp_msg_push_ecm ()
la.type = GID_ADDR_IP_PREFIX;
la.ippref.addr.ip.v4.as_u32 = 0xa1b2c3d4;
- la.ippref.addr.version = IP4;
+ la.ippref.addr.version = AF_IP4;
ra.type = GID_ADDR_IP_PREFIX;
ra.ippref.addr.ip.v4.as_u32 = 0x90817263;
- ra.ippref.addr.version = IP4;
+ ra.ippref.addr.version = AF_IP4;
ecm_hdr_t *lh = lisp_msg_push_ecm (vm, b, lp, rp, &la, &ra);
@@ -206,12 +206,12 @@ build_map_request (lisp_cp_main_t * lcm, vlib_buffer_t * b,
gid_address_type (seid) = GID_ADDR_IP_PREFIX;
ip_address_t *ip_addr = &gid_address_ip (seid);
ip_addr_v4 (ip_addr).as_u32 = 0x12345678;
- seid->ippref.addr.version = IP4;
+ seid->ippref.addr.version = AF_IP4;
gid_address_type (deid) = GID_ADDR_IP_PREFIX;
ip_address_t *ip_addr2 = &gid_address_ip (deid);
ip_addr_v4 (ip_addr2).as_u32 = 0x9abcdef0;
- deid->ippref.addr.version = IP4;
+ deid->ippref.addr.version = AF_IP4;
gid_address_ippref_len (deid) = 24;
h = lisp_msg_put_mreq (lcm, b, seid, deid, rlocs,
@@ -229,7 +229,7 @@ generate_rlocs (gid_address_t ** rlocs, u32 * count)
gid_address_type (gid_addr) = GID_ADDR_IP_PREFIX;
- ip_addr_version (addr) = IP4;
+ ip_addr_version (addr) = AF_IP4;
ip_addr_v4 (addr).data_u32 = 0x10203040;
vec_add1 (rlocs[0], gid_addr[0]);
@@ -237,7 +237,7 @@ generate_rlocs (gid_address_t ** rlocs, u32 * count)
ip_addr_v6 (addr).as_u32[1] = 0xbbaa9988;
ip_addr_v6 (addr).as_u32[2] = 0x77665544;
ip_addr_v6 (addr).as_u32[3] = 0x33221100;
- ip_addr_version (addr) = IP6;
+ ip_addr_version (addr) = AF_IP6;
vec_add1 (rlocs[0], gid_addr[0]);
}
@@ -265,24 +265,24 @@ test_lisp_msg_parse ()
_assert (len == 2 + 4
/* Source-EID-AFI field lenght + IPv4 address length */ );
_assert (gid.ippref.addr.ip.v4.as_u32 == 0x12345678);
- _assert (gid.ippref.addr.version == IP4);
+ _assert (gid.ippref.addr.version == AF_IP4);
u8 rloc_count = MREQ_ITR_RLOC_COUNT (h) + 1;
lisp_msg_parse_itr_rlocs (b, &rlocs, rloc_count);
_assert (vec_len (rlocs) == 2);
_assert (rlocs[0].ippref.addr.ip.v4.as_u32 == 0x10203040);
- _assert (rlocs[0].ippref.addr.version == IP4);
+ _assert (rlocs[0].ippref.addr.version == AF_IP4);
_assert (rlocs[1].ippref.addr.ip.v6.as_u32[0] == 0xffeeddcc);
_assert (rlocs[1].ippref.addr.ip.v6.as_u32[1] == 0xbbaa9988);
_assert (rlocs[1].ippref.addr.ip.v6.as_u32[2] == 0x77665544);
_assert (rlocs[1].ippref.addr.ip.v6.as_u32[3] == 0x33221100);
- _assert (rlocs[1].ippref.addr.version == IP6);
+ _assert (rlocs[1].ippref.addr.version == AF_IP6);
lisp_msg_parse_eid_rec (b, &eid);
_assert (eid.ippref.addr.ip.v4.as_u32 == 0x9abcdef0);
- _assert (eid.ippref.addr.version == IP4);
+ _assert (eid.ippref.addr.version == AF_IP4);
_assert (eid.ippref.len == 24);
done:
@@ -301,7 +301,7 @@ test_lisp_msg_put_mreq_with_lcaf ()
gid_address_t *rlocs = 0;
ip_prefix_t ippref;
- ip_prefix_version (&ippref) = IP4;
+ ip_prefix_version (&ippref) = AF_IP4;
ip4_address_t *ip = &ip_prefix_v4 (&ippref);
ip->as_u32 = 0x11223344;
ippref.len = 32;
@@ -434,7 +434,7 @@ build_test_map_records ()
.ippref = {
.addr = {
.ip.v4.as_u32 = 0x99887766,
- .version = IP4
+ .version = AF_IP4
}
}
}
@@ -663,7 +663,7 @@ test_lisp_parse_lcaf ()
_assert (gid_address_type (&locs[0].address) == GID_ADDR_IP_PREFIX);
_assert (gid_address_vni (&locs[0].address) == 0x09);
ip_prefix_t *ip_pref = &gid_address_ippref (&locs[0].address);
- _assert (IP4 == ip_prefix_version (ip_pref));
+ _assert (AF_IP4 == ip_prefix_version (ip_pref));
/* 2nd locator - LCAF entry with ipv6 address */
_assert (locs[1].local == 0);
@@ -675,7 +675,7 @@ test_lisp_parse_lcaf ()
_assert (gid_address_type (&locs[1].address) == GID_ADDR_IP_PREFIX);
_assert (0x22446688 == gid_address_vni (&locs[1].address));
ip_pref = &gid_address_ippref (&locs[1].address);
- _assert (IP6 == ip_prefix_version (ip_pref));
+ _assert (AF_IP6 == ip_prefix_version (ip_pref));
/* 3rd locator - simple ipv4 address */
_assert (gid_address_type (&locs[2].address) == GID_ADDR_IP_PREFIX);
@@ -727,7 +727,7 @@ test_locator_type (void)
gid_address_type (gid) = GID_ADDR_IP_PREFIX;
gid_address_ippref_len (gid) = 24;
ippref = &gid_address_ippref (gid);
- ip_prefix_version (ippref) = IP4;
+ ip_prefix_version (ippref) = AF_IP4;
ip_prefix_len (ippref) = 0;
ip4_address_t *ip4 = &ip_prefix_v4 (ippref);
ip4->as_u32 = 0x20304050;
@@ -749,7 +749,7 @@ test_locator_type (void)
loc2.local = 0;
ip_prefix_t nested_ippref;
- ip_prefix_version (&nested_ippref) = IP4;
+ ip_prefix_version (&nested_ippref) = AF_IP4;
ip_prefix_len (&nested_ippref) = 0;
ip4 = &ip_prefix_v4 (&nested_ippref);
ip4->as_u32 = 0x33882299;
@@ -1030,7 +1030,7 @@ test_gid_parse_lcaf_complex ()
_assert (ip6->as_u32[1] == 0xddccbb10);
_assert (ip6->as_u32[2] == 0xddccbb10);
_assert (ip6->as_u32[3] == 0xddccbb10);
- _assert (ip_prefix_version (ip_pref) == IP6);
+ _assert (ip_prefix_version (ip_pref) == AF_IP6);
done:
gid_address_free (gid_addr);
@@ -1127,7 +1127,7 @@ test_src_dst_with_vni_serdes (void)
.len = 24,
.addr =
{
- .version = IP4,
+ .version = AF_IP4,
.ip.v4.data = { 0x1, 0x2, 0x3, 0x0 }
}
}
@@ -1141,7 +1141,7 @@ test_src_dst_with_vni_serdes (void)
.len = 16,
.addr =
{
- .version = IP4,
+ .version = AF_IP4,
.ip.v4.data = { 0x9, 0x8, 0x0, 0x0 }
}
}
@@ -1302,7 +1302,7 @@ test_gid_address_write (void)
u8 *b = clib_mem_alloc (500);
clib_memset (b, 0, 500);
- ip_prefix_version (ippref) = IP4;
+ ip_prefix_version (ippref) = AF_IP4;
ip_prefix_len (ippref) = 9;
ip4_address_t *ip4 = &ip_prefix_v4 (ippref);
ip4->as_u32 = 0xaabbccdd;
diff --git a/src/vat/api_format.c b/src/vat/api_format.c
index afbfde0fdfb..652fe0310c2 100644
--- a/src/vat/api_format.c
+++ b/src/vat/api_format.c
@@ -16597,13 +16597,13 @@ api_one_use_petr (vat_main_t * vam)
if (unformat (input, "%U", unformat_ip4_address, &ip_addr_v4 (&ip)))
{
is_add = 1;
- ip_addr_version (&ip) = IP4;
+ ip_addr_version (&ip) = AF_IP4;
}
else
if (unformat (input, "%U", unformat_ip6_address, &ip_addr_v6 (&ip)))
{
is_add = 1;
- ip_addr_version (&ip) = IP6;
+ ip_addr_version (&ip) = AF_IP6;
}
else
{
@@ -16617,7 +16617,7 @@ api_one_use_petr (vat_main_t * vam)
mp->is_add = is_add;
if (is_add)
{
- mp->is_ip4 = ip_addr_version (&ip) == IP4 ? 1 : 0;
+ mp->is_ip4 = ip_addr_version (&ip) == AF_IP4 ? 1 : 0;
if (mp->is_ip4)
clib_memcpy (mp->address, &ip, 4);
else
diff --git a/src/vnet/CMakeLists.txt b/src/vnet/CMakeLists.txt
index 197f3c31eb6..4b7972dd960 100644
--- a/src/vnet/CMakeLists.txt
+++ b/src/vnet/CMakeLists.txt
@@ -451,6 +451,7 @@ list(APPEND VNET_SOURCES
ip/ip_init.c
ip/ip_in_out_acl.c
ip/ip_punt_drop.c
+ ip/ip_types.c
ip/lookup.c
ip/punt_api.c
ip/punt.c
@@ -489,6 +490,7 @@ list(APPEND VNET_HEADERS
ip/ip_packet.h
ip/ip_source_and_port_range_check.h
ip/ip_neighbor.h
+ ip/ip_types.h
ip/lookup.h
ip/ports.def
ip/protocols.def
diff --git a/src/vnet/ip/ip.h b/src/vnet/ip/ip.h
index 65ccaef40c2..22daaabc096 100644
--- a/src/vnet/ip/ip.h
+++ b/src/vnet/ip/ip.h
@@ -46,6 +46,7 @@
#include <vnet/vnet.h>
+#include <vnet/ip/ip_types.h>
#include <vnet/ip/format.h>
#include <vnet/ip/ip_packet.h>
#include <vnet/ip/lookup.h>
@@ -65,22 +66,6 @@
#include <vnet/ip/icmp6.h>
#include <vnet/classify/vnet_classify.h>
-typedef enum ip_address_family_t_
-{
- AF_IP4,
- AF_IP6,
-} ip_address_family_t;
-
-extern uword unformat_ip_address_family (unformat_input_t * input,
- va_list * args);
-extern u8 *format_ip_address_family (u8 * s, va_list * args);
-
-#define FOR_EACH_IP_ADDRESS_FAMILY(_af) \
- for (_af = AF_IP4; _af <= AF_IP6; _af++)
-
-#define u8_ptr_add(ptr, index) (((u8 *)ptr) + index)
-#define u16_net_add(u, val) clib_host_to_net_u16(clib_net_to_host_u16(u) + (val))
-
/* Per protocol info. */
typedef struct
{
diff --git a/src/vnet/ip/ip_types.c b/src/vnet/ip/ip_types.c
new file mode 100644
index 00000000000..3378da6625d
--- /dev/null
+++ b/src/vnet/ip/ip_types.c
@@ -0,0 +1,287 @@
+/*
+ * Copyright (c) 2016 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/ip/ip_types.h>
+#include <vnet/ip/format.h>
+
+u8 *
+format_ip_address (u8 * s, va_list * args)
+{
+ ip_address_t *a = va_arg (*args, ip_address_t *);
+ u8 ver = ip_addr_version (a);
+ if (ver == AF_IP4)
+ {
+ return format (s, "%U", format_ip4_address, &ip_addr_v4 (a));
+ }
+ else if (ver == AF_IP6)
+ {
+ return format (s, "%U", format_ip6_address, &ip_addr_v6 (a));
+ }
+ else
+ {
+ clib_warning ("Can't format IP version %d!", ver);
+ return 0;
+ }
+}
+
+uword
+unformat_ip_address (unformat_input_t * input, va_list * args)
+{
+ ip_address_t *a = va_arg (*args, ip_address_t *);
+
+ clib_memset (a, 0, sizeof (*a));
+ if (unformat (input, "%U", unformat_ip4_address, &ip_addr_v4 (a)))
+ ip_addr_version (a) = AF_IP4;
+ else if (unformat_user (input, unformat_ip6_address, &ip_addr_v6 (a)))
+ ip_addr_version (a) = AF_IP6;
+ else
+ return 0;
+ return 1;
+}
+
+u8 *
+format_ip_prefix (u8 * s, va_list * args)
+{
+ ip_prefix_t *a = va_arg (*args, ip_prefix_t *);
+ return format (s, "%U/%d", format_ip_address, &ip_prefix_addr (a),
+ ip_prefix_len (a));
+}
+
+uword
+unformat_ip_prefix (unformat_input_t * input, va_list * args)
+{
+ ip_prefix_t *a = va_arg (*args, ip_prefix_t *);
+ if (unformat (input, "%U/%d", unformat_ip_address, &ip_prefix_addr (a),
+ &ip_prefix_len (a)))
+ {
+ if ((ip_prefix_version (a) == AF_IP4 && 32 < ip_prefix_len (a)) ||
+ (ip_prefix_version (a) == AF_IP6 && 128 < ip_prefix_len (a)))
+ {
+ clib_warning ("Prefix length to big: %d!", ip_prefix_len (a));
+ return 0;
+ }
+ ip_prefix_normalize (a);
+ }
+ else
+ return 0;
+ return 1;
+}
+
+u16
+ip_address_size (const ip_address_t * a)
+{
+ switch (ip_addr_version (a))
+ {
+ case AF_IP4:
+ return sizeof (ip4_address_t);
+ break;
+ case AF_IP6:
+ return sizeof (ip6_address_t);
+ break;
+ }
+ return 0;
+}
+
+int
+ip_address_cmp (const ip_address_t * ip1, const ip_address_t * ip2)
+{
+ int res = 0;
+ if (ip_addr_version (ip1) != ip_addr_version (ip2))
+ return -1;
+ res =
+ memcmp (&ip_addr_addr (ip1), &ip_addr_addr (ip2), ip_address_size (ip1));
+
+ if (res < 0)
+ res = 2;
+ else if (res > 0)
+ res = 1;
+
+ return res;
+}
+
+void
+ip_address_copy (ip_address_t * dst, const ip_address_t * src)
+{
+ if (AF_IP4 == ip_addr_version (src))
+ {
+ /* don't copy any garbage from the union */
+ clib_memset (dst, 0, sizeof (*dst));
+ dst->ip.v4 = src->ip.v4;
+ dst->version = AF_IP4;
+ }
+ else
+ {
+ clib_memcpy (dst, src, sizeof (ip_address_t));
+ }
+}
+
+void
+ip_address_copy_addr (void *dst, const ip_address_t * src)
+{
+ clib_memcpy (dst, src, ip_address_size (src));
+}
+
+u16
+ip_version_to_size (u8 ver)
+{
+ switch (ver)
+ {
+ case AF_IP4:
+ return sizeof (ip4_address_t);
+ break;
+ case AF_IP6:
+ return sizeof (ip6_address_t);
+ break;
+ }
+ return 0;
+}
+
+void
+ip_address_set (ip_address_t * dst, const void *src, u8 version)
+{
+ clib_memcpy (dst, src, ip_version_to_size (version));
+ ip_addr_version (dst) = version;
+}
+
+void
+ip_address_to_46 (const ip_address_t * addr,
+ ip46_address_t * a, fib_protocol_t * proto)
+{
+ *proto = (AF_IP4 == ip_addr_version (addr) ?
+ FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
+ switch (*proto)
+ {
+ case FIB_PROTOCOL_IP4:
+ ip46_address_set_ip4 (a, &addr->ip.v4);
+ break;
+ case FIB_PROTOCOL_IP6:
+ a->ip6 = addr->ip.v6;
+ break;
+ default:
+ ASSERT (0);
+ break;
+ }
+}
+
+static void
+ip_prefix_normalize_ip4 (ip4_address_t * ip4, u8 preflen)
+{
+ u32 mask = ~0;
+
+ ASSERT (ip4);
+
+ if (32 <= preflen)
+ {
+ return;
+ }
+
+ mask = pow2_mask (preflen) << (32 - preflen);
+ mask = clib_host_to_net_u32 (mask);
+ ip4->data_u32 &= mask;
+}
+
+static void
+ip_prefix_normalize_ip6 (ip6_address_t * ip6, u8 preflen)
+{
+ u8 mask_6[16];
+ u32 *m;
+ u8 j, i0, i1;
+
+ ASSERT (ip6);
+
+ clib_memset (mask_6, 0, sizeof (mask_6));
+
+ if (128 <= preflen)
+ {
+ return;
+ }
+
+ i1 = preflen % 32;
+ i0 = preflen / 32;
+ m = (u32 *) & mask_6[0];
+
+ for (j = 0; j < i0; j++)
+ {
+ m[j] = ~0;
+ }
+
+ if (i1)
+ {
+ m[i0] = clib_host_to_net_u32 (pow2_mask (i1) << (32 - i1));
+ }
+
+ for (j = 0; j < sizeof (mask_6); j++)
+ {
+ ip6->as_u8[j] &= mask_6[j];
+ }
+}
+
+void
+ip_prefix_normalize (ip_prefix_t * a)
+{
+ u8 preflen = ip_prefix_len (a);
+
+ switch (ip_prefix_version (a))
+ {
+ case AF_IP4:
+ ip_prefix_normalize_ip4 (&ip_prefix_v4 (a), preflen);
+ break;
+
+ case AF_IP6:
+ ip_prefix_normalize_ip6 (&ip_prefix_v6 (a), preflen);
+ break;
+
+ default:
+ ASSERT (0);
+ }
+}
+
+void
+ip_prefix_copy (void *dst, void *src)
+{
+ clib_memcpy (dst, src, sizeof (ip_prefix_t));
+}
+
+int
+ip_prefix_cmp (ip_prefix_t * p1, ip_prefix_t * p2)
+{
+ int cmp = 0;
+
+ ip_prefix_normalize (p1);
+ ip_prefix_normalize (p2);
+
+ cmp = ip_address_cmp (&ip_prefix_addr (p1), &ip_prefix_addr (p2));
+ if (cmp == 0)
+ {
+ if (ip_prefix_len (p1) < ip_prefix_len (p2))
+ {
+ cmp = 1;
+ }
+ else
+ {
+ if (ip_prefix_len (p1) > ip_prefix_len (p2))
+ cmp = 2;
+ }
+ }
+ return cmp;
+}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vnet/ip/ip_types.h b/src/vnet/ip/ip_types.h
new file mode 100644
index 00000000000..d2927252434
--- /dev/null
+++ b/src/vnet/ip/ip_types.h
@@ -0,0 +1,98 @@
+/*
+ * 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 __IP_TYPES_H__
+#define __IP_TYPES_H__
+
+#include <vnet/fib/fib_types.h>
+
+typedef enum ip_address_family_t_
+{
+ AF_IP4,
+ AF_IP6,
+} ip_address_family_t;
+
+extern uword unformat_ip_address_family (unformat_input_t * input,
+ va_list * args);
+extern u8 *format_ip_address_family (u8 * s, va_list * args);
+
+#define FOR_EACH_IP_ADDRESS_FAMILY(_af) \
+ for (_af = AF_IP4; _af <= AF_IP6; _af++)
+
+#define u8_ptr_add(ptr, index) (((u8 *)ptr) + index)
+#define u16_net_add(u, val) clib_host_to_net_u16(clib_net_to_host_u16(u) + (val))
+
+/* *INDENT-OFF* */
+typedef struct ip_address
+{
+ union
+ {
+ ip4_address_t v4;
+ ip6_address_t v6;
+ } ip;
+ ip_address_family_t version;
+} __clib_packed ip_address_t;
+/* *INDENT-ON* */
+
+#define ip_addr_addr(_a) (_a)->ip
+#define ip_addr_v4(_a) (_a)->ip.v4
+#define ip_addr_v6(_a) (_a)->ip.v6
+#define ip_addr_version(_a) (_a)->version
+
+extern int ip_address_cmp (const ip_address_t * ip1,
+ const ip_address_t * ip2);
+extern void ip_address_copy (ip_address_t * dst, const ip_address_t * src);
+extern void ip_address_copy_addr (void *dst, const ip_address_t * src);
+extern void ip_address_set (ip_address_t * dst, const void *src, u8 version);
+extern u16 ip_address_size (const ip_address_t * a);
+extern u16 ip_version_to_size (u8 ver);
+extern u8 *format_ip_address (u8 * s, va_list * args);
+extern uword unformat_ip_address (unformat_input_t * input, va_list * args);
+extern void ip_address_to_46 (const ip_address_t * addr,
+ ip46_address_t * a, fib_protocol_t * proto);
+
+/* *INDENT-OFF* */
+typedef struct ip_prefix
+{
+ ip_address_t addr;
+ u8 len;
+} __clib_packed ip_prefix_t;
+/* *INDENT-ON* */
+
+#define ip_prefix_addr(_a) (_a)->addr
+#define ip_prefix_version(_a) ip_addr_version(&ip_prefix_addr(_a))
+#define ip_prefix_len(_a) (_a)->len
+#define ip_prefix_v4(_a) ip_addr_v4(&ip_prefix_addr(_a))
+#define ip_prefix_v6(_a) ip_addr_v6(&ip_prefix_addr(_a))
+
+extern int ip_prefix_cmp (ip_prefix_t * p1, ip_prefix_t * p2);
+extern void ip_prefix_normalize (ip_prefix_t * a);
+
+extern void ip_address_to_fib_prefix (const ip_address_t * addr,
+ fib_prefix_t * prefix);
+extern void ip_prefix_to_fib_prefix (const ip_prefix_t * ipp,
+ fib_prefix_t * fibp);
+extern u8 *format_ip_prefix (u8 * s, va_list * args);
+extern uword unformat_ip_prefix (unformat_input_t * input, va_list * args);
+
+#endif /* __IP_TYPES_H__ */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vnet/lisp-cp/control.c b/src/vnet/lisp-cp/control.c
index 774eae7352b..420a6db4e5a 100644
--- a/src/vnet/lisp-cp/control.c
+++ b/src/vnet/lisp-cp/control.c
@@ -114,7 +114,7 @@ ip_interface_get_first_ip_address (lisp_cp_main_t * lcm, u32 sw_if_index,
ip_lookup_main_t *lm;
void *addr;
- lm = (version == IP4) ? &lcm->im4->lookup_main : &lcm->im6->lookup_main;
+ lm = (version == AF_IP4) ? &lcm->im4->lookup_main : &lcm->im6->lookup_main;
addr = ip_interface_get_first_address (lm, sw_if_index, version);
if (!addr)
return 0;
@@ -129,7 +129,7 @@ ip_interface_get_first_ip_address (lisp_cp_main_t * lcm, u32 sw_if_index,
void
ip_address_to_fib_prefix (const ip_address_t * addr, fib_prefix_t * prefix)
{
- if (addr->version == IP4)
+ if (addr->version == AF_IP4)
{
prefix->fp_len = 32;
prefix->fp_proto = FIB_PROTOCOL_IP4;
@@ -189,7 +189,7 @@ ip_fib_get_first_egress_ip_for_dst (lisp_cp_main_t * lcm, ip_address_t * dst,
ipver = ip_addr_version (dst);
- lm = (ipver == IP4) ? &lcm->im4->lookup_main : &lcm->im6->lookup_main;
+ lm = (ipver == AF_IP4) ? &lcm->im4->lookup_main : &lcm->im6->lookup_main;
si = ip_fib_get_egress_iface_for_dst (lcm, dst);
if ((u32) ~ 0 == si)
@@ -904,7 +904,7 @@ add_l2_arp_bd (BVT (clib_bihash_kv) * kvp, void *arg)
{
u32 **ht = arg;
u32 version = (u32) kvp->key[0];
- if (IP6 == version)
+ if (AF_IP6 == version)
return;
u32 bd = (u32) (kvp->key[0] >> 32);
@@ -927,7 +927,7 @@ add_ndp_bd (BVT (clib_bihash_kv) * kvp, void *arg)
{
u32 **ht = arg;
u32 version = (u32) kvp->key[0];
- if (IP4 == version)
+ if (AF_IP4 == version)
return;
u32 bd = (u32) (kvp->key[0] >> 32);
@@ -958,7 +958,7 @@ add_l2_arp_entry (BVT (clib_bihash_kv) * kvp, void *arg)
lisp_api_l2_arp_entry_t **vector = a->vector, e;
u32 version = (u32) kvp->key[0];
- if (IP6 == version)
+ if (AF_IP6 == version)
return;
u32 bd = (u32) (kvp->key[0] >> 32);
@@ -993,7 +993,7 @@ add_ndp_entry (BVT (clib_bihash_kv) * kvp, void *arg)
lisp_api_ndp_entry_t **vector = a->vector, e;
u32 version = (u32) kvp->key[0];
- if (IP4 == version)
+ if (AF_IP4 == version)
return;
u32 bd = (u32) (kvp->key[0] >> 32);
@@ -2513,7 +2513,7 @@ build_itr_rloc_list (lisp_cp_main_t * lcm, locator_set_t * loc_set)
loc->sw_if_index, 1 /* unnumbered */,
({
addr = ip_interface_address_get_address (&lcm->im4->lookup_main, ia);
- ip_address_set (rloc, addr, IP4);
+ ip_address_set (rloc, addr, AF_IP4);
ip_prefix_len (ippref) = 32;
ip_prefix_normalize (ippref);
vec_add1 (rlocs, gid[0]);
@@ -2524,7 +2524,7 @@ build_itr_rloc_list (lisp_cp_main_t * lcm, locator_set_t * loc_set)
loc->sw_if_index, 1 /* unnumbered */,
({
addr = ip_interface_address_get_address (&lcm->im6->lookup_main, ia);
- ip_address_set (rloc, addr, IP6);
+ ip_address_set (rloc, addr, AF_IP6);
ip_prefix_len (ippref) = 128;
ip_prefix_normalize (ippref);
vec_add1 (rlocs, gid[0]);
@@ -2687,7 +2687,7 @@ add_locators (lisp_cp_main_t * lcm, mapping_t * m, u32 locator_set_index,
({
addr = ip_interface_address_get_address (&lcm->im4->lookup_main,
ia);
- ip_address_set (new_ip, addr, IP4);
+ ip_address_set (new_ip, addr, AF_IP4);
}));
/* Add ipv6 locators */
@@ -2696,7 +2696,7 @@ add_locators (lisp_cp_main_t * lcm, mapping_t * m, u32 locator_set_index,
({
addr = ip_interface_address_get_address (&lcm->im6->lookup_main,
ia);
- ip_address_set (new_ip, addr, IP6);
+ ip_address_set (new_ip, addr, AF_IP6);
}));
/* *INDENT-ON* */
@@ -2919,7 +2919,7 @@ send_rloc_probe (lisp_cp_main_t * lcm, gid_address_t * deid,
vnet_buffer (b)->sw_if_index[VLIB_TX] = 0;
- next_index = (ip_addr_version (rloc) == IP4) ?
+ next_index = (ip_addr_version (rloc) == AF_IP4) ?
ip4_lookup_node.index : ip6_lookup_node.index;
f = vlib_get_frame_to_node (lcm->vlib_main, next_index);
@@ -3031,7 +3031,7 @@ send_map_register (lisp_cp_main_t * lcm, u8 want_map_notif)
vnet_buffer (b)->sw_if_index[VLIB_TX] = 0;
- next_index = (ip_addr_version (&lcm->active_map_server) == IP4) ?
+ next_index = (ip_addr_version (&lcm->active_map_server) == AF_IP4) ?
ip4_lookup_node.index : ip6_lookup_node.index;
f = vlib_get_frame_to_node (lcm->vlib_main, next_index);
@@ -3178,7 +3178,7 @@ _send_encapsulated_map_request (lisp_cp_main_t * lcm,
/* set fib index to default and lookup node */
vnet_buffer (b)->sw_if_index[VLIB_TX] = 0;
- next_index = (ip_addr_version (&lcm->active_map_resolver) == IP4) ?
+ next_index = (ip_addr_version (&lcm->active_map_resolver) == AF_IP4) ?
ip4_lookup_node.index : ip6_lookup_node.index;
f = vlib_get_frame_to_node (lcm->vlib_main, next_index);
@@ -3233,14 +3233,14 @@ get_src_and_dst_ip (void *hdr, ip_address_t * src, ip_address_t * dst)
if ((ip4->ip_version_and_header_length & 0xF0) == 0x40)
{
- ip_address_set (src, &ip4->src_address, IP4);
- ip_address_set (dst, &ip4->dst_address, IP4);
+ ip_address_set (src, &ip4->src_address, AF_IP4);
+ ip_address_set (dst, &ip4->dst_address, AF_IP4);
}
else
{
ip6 = hdr;
- ip_address_set (src, &ip6->src_address, IP6);
- ip_address_set (dst, &ip6->dst_address, IP6);
+ ip_address_set (src, &ip6->src_address, AF_IP6);
+ ip_address_set (dst, &ip6->dst_address, AF_IP6);
}
}
@@ -3252,7 +3252,8 @@ lisp_get_vni_from_buffer_ip (lisp_cp_main_t * lcm, vlib_buffer_t * b,
u32 vni = ~0, table_id = ~0;
table_id = fib_table_get_table_id_for_sw_if_index ((version ==
- IP4 ? FIB_PROTOCOL_IP4 :
+ AF_IP4 ?
+ FIB_PROTOCOL_IP4 :
FIB_PROTOCOL_IP6),
vnet_buffer
(b)->sw_if_index
@@ -3350,7 +3351,7 @@ get_src_and_dst_eids_from_buffer (lisp_cp_main_t * lcm, vlib_buffer_t * b,
{
clib_memset (&gid_address_arp_ndp_ip (dst), 0,
sizeof (ip_address_t));
- ip_addr_version (&gid_address_arp_ndp_ip (dst)) = IP4;
+ ip_addr_version (&gid_address_arp_ndp_ip (dst)) = AF_IP4;
gid_address_arp_ndp_bd (dst) = ~0;
return;
}
@@ -3383,7 +3384,7 @@ get_src_and_dst_eids_from_buffer (lisp_cp_main_t * lcm, vlib_buffer_t * b,
clib_memset (&gid_address_arp_ndp_ip (dst), 0,
sizeof (ip_address_t));
ip_addr_version (&gid_address_arp_ndp_ip (dst)) =
- IP6;
+ AF_IP6;
gid_address_arp_ndp_bd (dst) = ~0;
gid_address_type (src) = GID_ADDR_NO_ADDRESS;
return;
@@ -3392,7 +3393,7 @@ get_src_and_dst_eids_from_buffer (lisp_cp_main_t * lcm, vlib_buffer_t * b,
gid_address_ndp_bd (dst) =
lisp_get_bd_from_buffer_eth (b);
ip_address_set (&gid_address_arp_ndp_ip (dst),
- &ndh->target_address, IP6);
+ &ndh->target_address, AF_IP6);
return;
}
}
@@ -4228,7 +4229,7 @@ send_map_reply (lisp_cp_main_t * lcm, u32 mi, ip_address_t * dst,
free_map_register_records (records);
vnet_buffer (b)->sw_if_index[VLIB_TX] = 0;
- next_index = (ip_addr_version (&lcm->active_map_resolver) == IP4) ?
+ next_index = (ip_addr_version (&lcm->active_map_resolver) == AF_IP4) ?
ip4_lookup_node.index : ip6_lookup_node.index;
f = vlib_get_frame_to_node (lcm->vlib_main, next_index);
diff --git a/src/vnet/lisp-cp/gid_dictionary.c b/src/vnet/lisp-cp/gid_dictionary.c
index b2060a62c8e..3fd98c737c8 100644
--- a/src/vnet/lisp-cp/gid_dictionary.c
+++ b/src/vnet/lisp-cp/gid_dictionary.c
@@ -126,7 +126,7 @@ gid_dict_foreach_subprefix (gid_dictionary_t * db, gid_address_t * eid,
{
ip_prefix_t *ippref = &gid_address_sd_dst_ippref (eid);
- if (IP4 == ip_prefix_version (ippref))
+ if (AF_IP4 == ip_prefix_version (ippref))
gid_dict_foreach_ip4_subprefix (db, gid_address_vni (eid),
&gid_address_sd_src_ippref (eid),
&gid_address_sd_dst_ippref (eid), cb,
@@ -295,7 +295,7 @@ ip_sd_lookup (gid_dictionary_t * db, u32 vni, ip_prefix_t * dst,
switch (ip_prefix_version (dst))
{
- case IP4:
+ case AF_IP4:
sfi = ip4_lookup (&db->dst_ip4_table, vni, dst);
if (GID_LOOKUP_MISS != sfi)
sfib4 = pool_elt_at_index (db->src_ip4_table_pool, sfi);
@@ -312,7 +312,7 @@ ip_sd_lookup (gid_dictionary_t * db, u32 vni, ip_prefix_t * dst,
return ip4_lookup (sfib4, 0, src);
break;
- case IP6:
+ case AF_IP6:
sfi = ip6_lookup (&db->dst_ip6_table, vni, dst);
if (GID_LOOKUP_MISS != sfi)
sfib6 = pool_elt_at_index (db->src_ip6_table_pool, sfi);
@@ -323,7 +323,7 @@ ip_sd_lookup (gid_dictionary_t * db, u32 vni, ip_prefix_t * dst,
{
ip_prefix_t sp;
clib_memset (&sp, 0, sizeof (sp));
- ip_prefix_version (&sp) = IP6;
+ ip_prefix_version (&sp) = AF_IP6;
return ip6_lookup_exact_match (sfib6, 0, &sp);
}
else
@@ -342,7 +342,7 @@ static void
make_arp_ndp_key (BVT (clib_bihash_kv) * kv, u32 bd, ip_address_t * addr)
{
kv->key[0] = ((u64) bd << 32) | (u32) ip_addr_version (addr);
- if (ip_addr_version (addr) == IP4)
+ if (ip_addr_version (addr) == AF_IP4)
{
kv->key[1] = (u64) addr->ip.v4.as_u32;
kv->key[2] = (u64) 0;
@@ -830,7 +830,7 @@ add_del_sd_ip6_key (gid_dictionary_t * db, u32 vni, ip_prefix_t * dst_pref,
{
ip_prefix_t sp;
clib_memset (&sp, 0, sizeof (sp));
- ip_prefix_version (&sp) = IP6;
+ ip_prefix_version (&sp) = AF_IP6;
add_del_ip6_key (sfib, 0 /* vni */ , &sp, val, is_add);
}
}
@@ -847,7 +847,7 @@ add_del_sd_ip6_key (gid_dictionary_t * db, u32 vni, ip_prefix_t * dst_pref,
{
ip_prefix_t sp;
clib_memset (&sp, 0, sizeof (sp));
- ip_prefix_version (&sp) = IP6;
+ ip_prefix_version (&sp) = AF_IP6;
old_val =
add_del_ip6_key (sfib, 0 /* vni */ , &sp, val, is_add);
}
@@ -864,7 +864,7 @@ add_del_sd_ip6_key (gid_dictionary_t * db, u32 vni, ip_prefix_t * dst_pref,
{
ip_prefix_t sp;
clib_memset (&sp, 0, sizeof (sp));
- ip_prefix_version (&sp) = IP6;
+ ip_prefix_version (&sp) = AF_IP6;
old_val = add_del_ip6_key (sfib, 0, &sp, 0, is_add);
}
@@ -884,10 +884,10 @@ add_del_ip (gid_dictionary_t * db, u32 vni, ip_prefix_t * dst_key,
{
switch (ip_prefix_version (dst_key))
{
- case IP4:
+ case AF_IP4:
return add_del_sd_ip4_key (db, vni, dst_key, src_key, value, is_add);
break;
- case IP6:
+ case AF_IP6:
return add_del_sd_ip6_key (db, vni, dst_key, src_key, value, is_add);
break;
default:
diff --git a/src/vnet/lisp-cp/lisp_api.c b/src/vnet/lisp-cp/lisp_api.c
index 5d426b6277c..de13beb92d6 100644
--- a/src/vnet/lisp-cp/lisp_api.c
+++ b/src/vnet/lisp-cp/lisp_api.c
@@ -103,7 +103,8 @@ unformat_lisp_locs (vl_api_remote_locator_t * rmt_locs, u32 rloc_num)
/* remote locators */
r = &rmt_locs[i];
clib_memset (&loc, 0, sizeof (loc));
- gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
+ gid_address_ip_set (&loc.address, &r->addr,
+ r->is_ip4 ? AF_IP4 : AF_IP6);
loc.priority = r->priority;
loc.weight = r->weight;
@@ -209,13 +210,13 @@ unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
{
case 0: /* ipv4 */
gid_address_type (dst) = GID_ADDR_IP_PREFIX;
- gid_address_ip_set (dst, src, IP4);
+ gid_address_ip_set (dst, src, AF_IP4);
gid_address_ippref_len (dst) = len;
ip_prefix_normalize (&gid_address_ippref (dst));
break;
case 1: /* ipv6 */
gid_address_type (dst) = GID_ADDR_IP_PREFIX;
- gid_address_ip_set (dst, src, IP6);
+ gid_address_ip_set (dst, src, AF_IP6);
gid_address_ippref_len (dst) = len;
ip_prefix_normalize (&gid_address_ippref (dst));
break;
@@ -305,7 +306,7 @@ vl_api_lisp_add_del_map_server_t_handler (vl_api_lisp_add_del_map_server_t
clib_memset (&addr, 0, sizeof (addr));
- ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
+ ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? AF_IP6 : AF_IP4);
rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_SERVER_REPLY);
@@ -322,7 +323,7 @@ vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
clib_memset (a, 0, sizeof (a[0]));
a->is_add = mp->is_add;
- ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
+ ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? AF_IP6 : AF_IP4);
rv = vnet_lisp_add_del_map_resolver (a);
@@ -411,7 +412,7 @@ vl_api_lisp_use_petr_t_handler (vl_api_lisp_use_petr_t * mp)
int rv = 0;
ip_address_t addr;
- ip_address_set (&addr, &mp->address, mp->is_ip4 ? IP4 : IP6);
+ ip_address_set (&addr, &mp->address, mp->is_ip4 ? AF_IP4 : AF_IP6);
rv = vnet_lisp_use_petr (&addr, mp->is_add);
REPLY_MACRO (VL_API_LISP_USE_PETR_REPLY);
@@ -450,12 +451,12 @@ vl_api_show_lisp_use_petr_t_handler (vl_api_show_lisp_use_petr_t * mp)
ip_address_t *ip = &gid_address_ip (&addr);
switch (ip_addr_version (ip))
{
- case IP4:
+ case AF_IP4:
clib_memcpy (rmp->address, &ip_addr_v4 (ip),
sizeof (ip_addr_v4 (ip)));
break;
- case IP6:
+ case AF_IP6:
clib_memcpy (rmp->address, &ip_addr_v6 (ip),
sizeof (ip_addr_v6 (ip)));
break;
@@ -463,7 +464,7 @@ vl_api_show_lisp_use_petr_t_handler (vl_api_show_lisp_use_petr_t * mp)
default:
ASSERT (0);
}
- rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4);
+ rmp->is_ip4 = (gid_address_ip_version (&addr) == AF_IP4);
});
/* *INDENT-ON* */
}
@@ -712,7 +713,7 @@ lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
switch (fid_addr_type (src))
{
case FID_ADDR_IP_PREF:
- if (ip_prefix_version (ippref) == IP4)
+ if (ip_prefix_version (ippref) == AF_IP4)
clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
else
clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
@@ -739,9 +740,9 @@ fid_type_to_api_type (fid_address_t * fid)
{
case FID_ADDR_IP_PREF:
ippref = &fid_addr_ippref (fid);
- if (ip_prefix_version (ippref) == IP4)
+ if (ip_prefix_version (ippref) == AF_IP4)
return 0;
- else if (ip_prefix_version (ippref) == IP6)
+ else if (ip_prefix_version (ippref) == AF_IP6)
return 1;
else
return ~0;
@@ -822,7 +823,7 @@ send_lisp_eid_table_details (mapping_t * mapit,
break;
case GID_ADDR_IP_PREFIX:
rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
- if (ip_prefix_version (ip_prefix) == IP4)
+ if (ip_prefix_version (ip_prefix) == AF_IP4)
{
rmp->eid_type = 0; /* ipv4 type */
clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
@@ -901,13 +902,13 @@ send_lisp_map_server_details (ip_address_t * ip, vl_api_registration_t * reg,
switch (ip_addr_version (ip))
{
- case IP4:
+ case AF_IP4:
rmp->is_ipv6 = 0;
clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
sizeof (ip_addr_v4 (ip)));
break;
- case IP6:
+ case AF_IP6:
rmp->is_ipv6 = 1;
clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
sizeof (ip_addr_v6 (ip)));
@@ -950,13 +951,13 @@ send_lisp_map_resolver_details (ip_address_t * ip,
switch (ip_addr_version (ip))
{
- case IP4:
+ case AF_IP4:
rmp->is_ipv6 = 0;
clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
sizeof (ip_addr_v4 (ip)));
break;
- case IP6:
+ case AF_IP6:
rmp->is_ipv6 = 1;
clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
sizeof (ip_addr_v6 (ip)));
@@ -1063,7 +1064,7 @@ lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs)
case GID_ADDR_IP_PREFIX:
a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
- if (gid_address_ip_version (&adj->reid) == IP4)
+ if (gid_address_ip_version (&adj->reid) == AF_IP4)
{
a.eid_type = 0; /* ipv4 type */
clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
diff --git a/src/vnet/lisp-cp/lisp_types.c b/src/vnet/lisp-cp/lisp_types.c
index cc2b1b2516f..90878654573 100644
--- a/src/vnet/lisp-cp/lisp_types.c
+++ b/src/vnet/lisp-cp/lisp_types.c
@@ -141,69 +141,6 @@ serdes_fct lcaf_parse_fcts[LCAF_TYPES] = {
#undef _
};
-u8 *
-format_ip_address (u8 * s, va_list * args)
-{
- ip_address_t *a = va_arg (*args, ip_address_t *);
- u8 ver = ip_addr_version (a);
- if (ver == IP4)
- {
- return format (s, "%U", format_ip4_address, &ip_addr_v4 (a));
- }
- else if (ver == IP6)
- {
- return format (s, "%U", format_ip6_address, &ip_addr_v6 (a));
- }
- else
- {
- clib_warning ("Can't format IP version %d!", ver);
- return 0;
- }
-}
-
-uword
-unformat_ip_address (unformat_input_t * input, va_list * args)
-{
- ip_address_t *a = va_arg (*args, ip_address_t *);
-
- clib_memset (a, 0, sizeof (*a));
- if (unformat (input, "%U", unformat_ip4_address, &ip_addr_v4 (a)))
- ip_addr_version (a) = IP4;
- else if (unformat_user (input, unformat_ip6_address, &ip_addr_v6 (a)))
- ip_addr_version (a) = IP6;
- else
- return 0;
- return 1;
-}
-
-u8 *
-format_ip_prefix (u8 * s, va_list * args)
-{
- ip_prefix_t *a = va_arg (*args, ip_prefix_t *);
- return format (s, "%U/%d", format_ip_address, &ip_prefix_addr (a),
- ip_prefix_len (a));
-}
-
-uword
-unformat_ip_prefix (unformat_input_t * input, va_list * args)
-{
- ip_prefix_t *a = va_arg (*args, ip_prefix_t *);
- if (unformat (input, "%U/%d", unformat_ip_address, &ip_prefix_addr (a),
- &ip_prefix_len (a)))
- {
- if ((ip_prefix_version (a) == IP4 && 32 < ip_prefix_len (a)) ||
- (ip_prefix_version (a) == IP6 && 128 < ip_prefix_length (a)))
- {
- clib_warning ("Prefix length to big: %d!", ip_prefix_len (a));
- return 0;
- }
- ip_prefix_normalize (a);
- }
- else
- return 0;
- return 1;
-}
-
uword
unformat_nsh_address (unformat_input_t * input, va_list * args)
{
@@ -443,49 +380,10 @@ format_negative_mapping_action (u8 * s, va_list * args)
return (s);
}
-u16
-ip_address_size (const ip_address_t * a)
-{
- switch (ip_addr_version (a))
- {
- case IP4:
- return sizeof (ip4_address_t);
- break;
- case IP6:
- return sizeof (ip6_address_t);
- break;
- }
- return 0;
-}
-
-u16
-ip_version_to_size (u8 ver)
-{
- switch (ver)
- {
- case IP4:
- return sizeof (ip4_address_t);
- break;
- case IP6:
- return sizeof (ip6_address_t);
- break;
- }
- return 0;
-}
-
u8
-ip_version_to_max_plen (u8 ver)
+ip_prefix_length (void *a)
{
- switch (ver)
- {
- case IP4:
- return 32;
- break;
- case IP6:
- return 128;
- break;
- }
- return 0;
+ return ip_prefix_len ((ip_prefix_t *) a);
}
always_inline lisp_afi_e
@@ -493,9 +391,9 @@ ip_version_to_iana_afi (u16 version)
{
switch (version)
{
- case IP4:
+ case AF_IP4:
return LISP_AFI_IP;
- case IP6:
+ case AF_IP6:
return LISP_AFI_IP6;
default:
return 0;
@@ -509,9 +407,9 @@ ip_iana_afi_to_version (lisp_afi_e afi)
switch (afi)
{
case LISP_AFI_IP:
- return IP4;
+ return AF_IP4;
case LISP_AFI_IP6:
- return IP6;
+ return AF_IP6;
default:
return 0;
}
@@ -533,7 +431,7 @@ ip_address_iana_afi (ip_address_t * a)
u8
ip_address_max_len (u8 version)
{
- return version == IP4 ? 32 : 128;
+ return version == AF_IP4 ? 32 : 128;
}
u16
@@ -553,7 +451,7 @@ ip6_address_size_to_put ()
u32
ip4_address_put (u8 * b, ip4_address_t * a)
{
- *(u16 *) b = clib_host_to_net_u16 (ip_version_to_iana_afi (IP4));
+ *(u16 *) b = clib_host_to_net_u16 (ip_version_to_iana_afi (AF_IP4));
u8 *p = b + sizeof (u16);
clib_memcpy (p, a, sizeof (*a));
return ip4_address_size_to_put ();
@@ -562,7 +460,7 @@ ip4_address_put (u8 * b, ip4_address_t * a)
u32
ip6_address_put (u8 * b, ip6_address_t * a)
{
- *(u16 *) b = clib_host_to_net_u16 (ip_version_to_iana_afi (IP6));
+ *(u16 *) b = clib_host_to_net_u16 (ip_version_to_iana_afi (AF_IP6));
u8 *p = b + sizeof (u16);
clib_memcpy (p, a, sizeof (*a));
return ip6_address_size_to_put ();
@@ -850,145 +748,6 @@ gid_address_from_ip (gid_address_t * g, ip_address_t * ip)
gid_address_ippref_len (g) = 32;
}
-int
-ip_address_cmp (const ip_address_t * ip1, const ip_address_t * ip2)
-{
- int res = 0;
- if (ip_addr_version (ip1) != ip_addr_version (ip2))
- return -1;
- res =
- memcmp (&ip_addr_addr (ip1), &ip_addr_addr (ip2), ip_address_size (ip1));
-
- if (res < 0)
- res = 2;
- else if (res > 0)
- res = 1;
-
- return res;
-}
-
-void
-ip_address_copy (ip_address_t * dst, const ip_address_t * src)
-{
- if (IP4 == ip_addr_version (src))
- {
- /* don't copy any garbage from the union */
- clib_memset (dst, 0, sizeof (*dst));
- dst->ip.v4 = src->ip.v4;
- dst->version = IP4;
- }
- else
- {
- clib_memcpy (dst, src, sizeof (ip_address_t));
- }
-}
-
-void
-ip_address_copy_addr (void *dst, const ip_address_t * src)
-{
- clib_memcpy (dst, src, ip_address_size (src));
-}
-
-void
-ip_address_set (ip_address_t * dst, const void *src, u8 version)
-{
- clib_memcpy (dst, src, ip_version_to_size (version));
- ip_addr_version (dst) = version;
-}
-
-void
-ip_address_to_46 (const ip_address_t * addr,
- ip46_address_t * a, fib_protocol_t * proto)
-{
- *proto = (IP4 == ip_addr_version (addr) ?
- FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
- switch (*proto)
- {
- case FIB_PROTOCOL_IP4:
- ip46_address_set_ip4 (a, &addr->ip.v4);
- break;
- case FIB_PROTOCOL_IP6:
- a->ip6 = addr->ip.v6;
- break;
- default:
- ASSERT (0);
- break;
- }
-}
-
-static void
-ip_prefix_normalize_ip4 (ip4_address_t * ip4, u8 preflen)
-{
- u32 mask = ~0;
-
- ASSERT (ip4);
-
- if (32 <= preflen)
- {
- return;
- }
-
- mask = pow2_mask (preflen) << (32 - preflen);
- mask = clib_host_to_net_u32 (mask);
- ip4->data_u32 &= mask;
-}
-
-static void
-ip_prefix_normalize_ip6 (ip6_address_t * ip6, u8 preflen)
-{
- u8 mask_6[16];
- u32 *m;
- u8 j, i0, i1;
-
- ASSERT (ip6);
-
- clib_memset (mask_6, 0, sizeof (mask_6));
-
- if (128 <= preflen)
- {
- return;
- }
-
- i1 = preflen % 32;
- i0 = preflen / 32;
- m = (u32 *) & mask_6[0];
-
- for (j = 0; j < i0; j++)
- {
- m[j] = ~0;
- }
-
- if (i1)
- {
- m[i0] = clib_host_to_net_u32 (pow2_mask (i1) << (32 - i1));
- }
-
- for (j = 0; j < sizeof (mask_6); j++)
- {
- ip6->as_u8[j] &= mask_6[j];
- }
-}
-
-void
-ip_prefix_normalize (ip_prefix_t * a)
-{
- u8 preflen = ip_prefix_len (a);
-
- switch (ip_prefix_version (a))
- {
- case IP4:
- ip_prefix_normalize_ip4 (&ip_prefix_v4 (a), preflen);
- break;
-
- case IP6:
- ip_prefix_normalize_ip6 (&ip_prefix_v6 (a), preflen);
- break;
-
- default:
- ASSERT (0);
- }
-}
-
void *
ip_prefix_cast (gid_address_t * a)
{
@@ -1010,28 +769,16 @@ ip_prefix_write (u8 * p, void *gid)
switch (ip_prefix_version (a))
{
- case IP4:
+ case AF_IP4:
return ip4_address_put (p, &ip_prefix_v4 (a));
break;
- case IP6:
+ case AF_IP6:
return ip6_address_put (p, &ip_prefix_v6 (a));
break;
}
return 0;
}
-u8
-ip_prefix_length (void *a)
-{
- return ip_prefix_len ((ip_prefix_t *) a);
-}
-
-void
-ip_prefix_copy (void *dst, void *src)
-{
- clib_memcpy (dst, src, sizeof (ip_prefix_t));
-}
-
void
mac_copy (void *dst, void *src)
{
@@ -1050,30 +797,6 @@ nsh_copy (void *dst, void *src)
clib_memcpy (dst, src, sizeof (nsh_t));
}
-int
-ip_prefix_cmp (ip_prefix_t * p1, ip_prefix_t * p2)
-{
- int cmp = 0;
-
- ip_prefix_normalize (p1);
- ip_prefix_normalize (p2);
-
- cmp = ip_address_cmp (&ip_prefix_addr (p1), &ip_prefix_addr (p2));
- if (cmp == 0)
- {
- if (ip_prefix_len (p1) < ip_prefix_len (p2))
- {
- cmp = 1;
- }
- else
- {
- if (ip_prefix_len (p1) > ip_prefix_len (p2))
- cmp = 2;
- }
- }
- return cmp;
-}
-
void
no_addr_copy (void *dst, void *src)
{
diff --git a/src/vnet/lisp-cp/lisp_types.h b/src/vnet/lisp-cp/lisp_types.h
index ff7880bff12..f041e0f3b4a 100644
--- a/src/vnet/lisp-cp/lisp_types.h
+++ b/src/vnet/lisp-cp/lisp_types.h
@@ -34,55 +34,6 @@ u8 *format_hmac_key_id (u8 * s, va_list * args);
typedef enum
{
- IP4,
- IP6
-} ip_address_type_t;
-
-/* *INDENT-OFF* */
-typedef CLIB_PACKED(struct ip_address
-{
- union
- {
- ip4_address_t v4;
- ip6_address_t v6;
- } ip;
- u8 version;
-}) ip_address_t;
-/* *INDENT-ON* */
-
-#define ip_addr_addr(_a) (_a)->ip
-#define ip_addr_v4(_a) (_a)->ip.v4
-#define ip_addr_v6(_a) (_a)->ip.v6
-#define ip_addr_version(_a) (_a)->version
-
-int ip_address_cmp (const ip_address_t * ip1, const ip_address_t * ip2);
-void ip_address_copy (ip_address_t * dst, const ip_address_t * src);
-void ip_address_copy_addr (void *dst, const ip_address_t * src);
-void ip_address_set (ip_address_t * dst, const void *src, u8 version);
-
-/* *INDENT-OFF* */
-typedef CLIB_PACKED(struct ip_prefix
-{
- ip_address_t addr;
- u8 len;
-}) ip_prefix_t;
-/* *INDENT-ON* */
-
-#define ip_prefix_addr(_a) (_a)->addr
-#define ip_prefix_version(_a) ip_addr_version(&ip_prefix_addr(_a))
-#define ip_prefix_len(_a) (_a)->len
-#define ip_prefix_v4(_a) ip_addr_v4(&ip_prefix_addr(_a))
-#define ip_prefix_v6(_a) ip_addr_v6(&ip_prefix_addr(_a))
-
-void ip_prefix_normalize (ip_prefix_t * a);
-
-extern void ip_address_to_fib_prefix (const ip_address_t * addr,
- fib_prefix_t * prefix);
-extern void ip_prefix_to_fib_prefix (const ip_prefix_t * ipp,
- fib_prefix_t * fibp);
-
-typedef enum
-{
/* NOTE: ip addresses are left out on purpose. Use max masked ip-prefixes
* instead */
GID_ADDR_IP_PREFIX,
@@ -216,11 +167,6 @@ typedef struct _gid_address_t
u8 vni_mask;
} gid_address_t;
-u8 *format_ip_address (u8 * s, va_list * args);
-uword unformat_ip_address (unformat_input_t * input, va_list * args);
-u8 *format_ip_prefix (u8 * s, va_list * args);
-uword unformat_ip_prefix (unformat_input_t * input, va_list * args);
-
u16 ip4_address_size_to_put ();
u16 ip6_address_size_to_put ();
u32 ip4_address_put (u8 * b, ip4_address_t * a);
@@ -230,8 +176,6 @@ u16 ip_address_size_to_write (ip_address_t * a);
u16 ip_address_iana_afi (ip_address_t * a);
u8 ip_address_max_len (u8 ver);
u32 ip_address_put (u8 * b, ip_address_t * a);
-void ip_address_to_46 (const ip_address_t * addr,
- ip46_address_t * a, fib_protocol_t * proto);
/* LISP AFI codes */
typedef enum
diff --git a/src/vnet/lisp-cp/one_api.c b/src/vnet/lisp-cp/one_api.c
index fa67536c32d..56cb74b0c77 100644
--- a/src/vnet/lisp-cp/one_api.c
+++ b/src/vnet/lisp-cp/one_api.c
@@ -155,7 +155,8 @@ unformat_one_locs (vl_api_one_remote_locator_t * rmt_locs, u32 rloc_num)
/* remote locators */
r = &rmt_locs[i];
clib_memset (&loc, 0, sizeof (loc));
- gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
+ gid_address_ip_set (&loc.address, &r->addr,
+ r->is_ip4 ? AF_IP4 : AF_IP6);
loc.priority = r->priority;
loc.weight = r->weight;
@@ -298,13 +299,13 @@ unformat_one_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
{
case 0: /* ipv4 */
gid_address_type (dst) = GID_ADDR_IP_PREFIX;
- gid_address_ip_set (dst, src, IP4);
+ gid_address_ip_set (dst, src, AF_IP4);
gid_address_ippref_len (dst) = len;
ip_prefix_normalize (&gid_address_ippref (dst));
break;
case 1: /* ipv6 */
gid_address_type (dst) = GID_ADDR_IP_PREFIX;
- gid_address_ip_set (dst, src, IP6);
+ gid_address_ip_set (dst, src, AF_IP6);
gid_address_ippref_len (dst) = len;
ip_prefix_normalize (&gid_address_ippref (dst));
break;
@@ -405,7 +406,7 @@ vl_api_one_add_del_map_server_t_handler (vl_api_one_add_del_map_server_t * mp)
clib_memset (&addr, 0, sizeof (addr));
- ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
+ ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? AF_IP6 : AF_IP4);
rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_SERVER_REPLY);
@@ -422,7 +423,7 @@ vl_api_one_add_del_map_resolver_t_handler (vl_api_one_add_del_map_resolver_t
clib_memset (a, 0, sizeof (a[0]));
a->is_add = mp->is_add;
- ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
+ ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? AF_IP6 : AF_IP4);
rv = vnet_lisp_add_del_map_resolver (a);
@@ -528,7 +529,7 @@ vl_api_one_use_petr_t_handler (vl_api_one_use_petr_t * mp)
int rv = 0;
ip_address_t addr;
- ip_address_set (&addr, &mp->address, mp->is_ip4 ? IP4 : IP6);
+ ip_address_set (&addr, &mp->address, mp->is_ip4 ? AF_IP4 : AF_IP6);
rv = vnet_lisp_use_petr (&addr, mp->is_add);
REPLY_MACRO (VL_API_ONE_USE_PETR_REPLY);
@@ -567,12 +568,12 @@ vl_api_show_one_use_petr_t_handler (vl_api_show_one_use_petr_t * mp)
ip_address_t *ip = &gid_address_ip (&addr);
switch (ip_addr_version (ip))
{
- case IP4:
+ case AF_IP4:
clib_memcpy (rmp->address, &ip_addr_v4 (ip),
sizeof (ip_addr_v4 (ip)));
break;
- case IP6:
+ case AF_IP6:
clib_memcpy (rmp->address, &ip_addr_v6 (ip),
sizeof (ip_addr_v6 (ip)));
break;
@@ -580,7 +581,7 @@ vl_api_show_one_use_petr_t_handler (vl_api_show_one_use_petr_t * mp)
default:
ASSERT (0);
}
- rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4);
+ rmp->is_ip4 = (gid_address_ip_version (&addr) == AF_IP4);
});
/* *INDENT-ON* */
}
@@ -827,7 +828,7 @@ one_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
switch (fid_addr_type (src))
{
case FID_ADDR_IP_PREF:
- if (ip_prefix_version (ippref) == IP4)
+ if (ip_prefix_version (ippref) == AF_IP4)
clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
else
clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
@@ -854,9 +855,9 @@ fid_type_to_api_type (fid_address_t * fid)
{
case FID_ADDR_IP_PREF:
ippref = &fid_addr_ippref (fid);
- if (ip_prefix_version (ippref) == IP4)
+ if (ip_prefix_version (ippref) == AF_IP4)
return 0;
- else if (ip_prefix_version (ippref) == IP6)
+ else if (ip_prefix_version (ippref) == AF_IP6)
return 1;
else
return ~0;
@@ -936,7 +937,7 @@ send_one_eid_table_details (mapping_t * mapit,
break;
case GID_ADDR_IP_PREFIX:
rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
- if (ip_prefix_version (ip_prefix) == IP4)
+ if (ip_prefix_version (ip_prefix) == AF_IP4)
{
rmp->eid_type = 0; /* ipv4 type */
clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
@@ -1022,13 +1023,13 @@ send_one_map_server_details (ip_address_t * ip, vl_api_registration_t * reg,
switch (ip_addr_version (ip))
{
- case IP4:
+ case AF_IP4:
rmp->is_ipv6 = 0;
clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
sizeof (ip_addr_v4 (ip)));
break;
- case IP6:
+ case AF_IP6:
rmp->is_ipv6 = 1;
clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
sizeof (ip_addr_v6 (ip)));
@@ -1071,13 +1072,13 @@ send_one_map_resolver_details (ip_address_t * ip,
switch (ip_addr_version (ip))
{
- case IP4:
+ case AF_IP4:
rmp->is_ipv6 = 0;
clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
sizeof (ip_addr_v4 (ip)));
break;
- case IP6:
+ case AF_IP6:
rmp->is_ipv6 = 1;
clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
sizeof (ip_addr_v6 (ip)));
@@ -1184,7 +1185,7 @@ one_adjacency_copy (vl_api_one_adjacency_t * dst, lisp_adjacency_t * adjs)
case GID_ADDR_IP_PREFIX:
a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
- if (gid_address_ip_version (&adj->reid) == IP4)
+ if (gid_address_ip_version (&adj->reid) == AF_IP4)
{
a.eid_type = 0; /* ipv4 type */
clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
@@ -1469,7 +1470,7 @@ lisp_fid_addr_to_api (fid_address_t * fid, u8 * dst, u8 * api_eid_type,
{
case FID_ADDR_IP_PREF:
*prefix_length = fid_addr_prefix_length (fid);
- if (fid_addr_ip_version (fid) == IP4)
+ if (fid_addr_ip_version (fid) == AF_IP4)
{
*api_eid_type = 0; /* ipv4 type */
clib_memcpy (dst, &fid_addr_ippref (fid), 4);
@@ -1518,7 +1519,7 @@ vl_api_one_stats_dump_t_handler (vl_api_one_stats_dump_t * mp)
&rmp->seid_pref_len);
rmp->vni = clib_host_to_net_u32 (stat->vni);
- rmp->is_ip4 = ip_addr_version (&stat->rmt_rloc) == IP4 ? 1 : 0;
+ rmp->is_ip4 = ip_addr_version (&stat->rmt_rloc) == AF_IP4 ? 1 : 0;
ip_address_copy_addr (rmp->rloc, &stat->rmt_rloc);
ip_address_copy_addr (rmp->lloc, &stat->loc_rloc);
@@ -1542,7 +1543,7 @@ static void
gid_address_arp_bd (arp) = clib_net_to_host_u32 (mp->bd);
/* vpp keeps ip4 addresses in network byte order */
- ip_address_set (&gid_address_arp_ndp_ip (arp), &mp->ip4, IP4);
+ ip_address_set (&gid_address_arp_ndp_ip (arp), &mp->ip4, AF_IP4);
rv = vnet_lisp_add_del_l2_arp_ndp_entry (arp, mp->mac, mp->is_add);
@@ -1559,7 +1560,7 @@ vl_api_one_add_del_ndp_entry_t_handler (vl_api_one_add_del_ndp_entry_t * mp)
gid_address_type (g) = GID_ADDR_NDP;
gid_address_ndp_bd (g) = clib_net_to_host_u32 (mp->bd);
- ip_address_set (&gid_address_arp_ndp_ip (g), mp->ip6, IP6);
+ ip_address_set (&gid_address_arp_ndp_ip (g), mp->ip6, AF_IP6);
rv = vnet_lisp_add_del_l2_arp_ndp_entry (g, mp->mac, mp->is_add);
diff --git a/src/vnet/lisp-cp/one_cli.c b/src/vnet/lisp-cp/one_cli.c
index e000c02e414..d5a0ee00015 100644
--- a/src/vnet/lisp-cp/one_cli.c
+++ b/src/vnet/lisp-cp/one_cli.c
@@ -323,7 +323,7 @@ lisp_add_del_ndp_entry_command_fn (vlib_main_t * vm,
}
/* build GID address */
- ip_address_set (&gid_address_arp_ndp_ip (g), &ip6, IP6);
+ ip_address_set (&gid_address_arp_ndp_ip (g), &ip6, AF_IP6);
gid_address_ndp_bd (g) = bd;
gid_address_type (g) = GID_ADDR_NDP;
rc = vnet_lisp_add_del_l2_arp_ndp_entry (g, hw_addr, is_add);
diff --git a/src/vnet/lisp-cp/packets.c b/src/vnet/lisp-cp/packets.c
index 5cb2cfa12c3..bbc3ad64572 100644
--- a/src/vnet/lisp-cp/packets.c
+++ b/src/vnet/lisp-cp/packets.c
@@ -115,11 +115,11 @@ udp_checksum (udp_header_t * uh, u32 udp_len, void *ih, u8 version)
{
switch (version)
{
- case IP4:
+ case AF_IP4:
return (udp_ip4_checksum (uh, udp_len,
((ip4_header_t *) ih)->src_address.as_u8,
((ip4_header_t *) ih)->dst_address.as_u8));
- case IP6:
+ case AF_IP6:
return (udp_ip6_checksum (ih, uh, udp_len));
default:
return ~0;
@@ -154,11 +154,11 @@ pkt_push_ip (vlib_main_t * vm, vlib_buffer_t * b, ip_address_t * src,
switch (ip_addr_version (src))
{
- case IP4:
+ case AF_IP4:
return vlib_buffer_push_ip4 (vm, b, &ip_addr_v4 (src),
&ip_addr_v4 (dst), proto, csum_offload);
break;
- case IP6:
+ case AF_IP6:
return vlib_buffer_push_ip6 (vm, b, &ip_addr_v6 (src),
&ip_addr_v6 (dst), proto);
break;
diff --git a/src/vnet/lisp-gpe/lisp_gpe.c b/src/vnet/lisp-gpe/lisp_gpe.c
index 9a10836707c..c75ad6b87cd 100644
--- a/src/vnet/lisp-gpe/lisp_gpe.c
+++ b/src/vnet/lisp-gpe/lisp_gpe.c
@@ -406,9 +406,9 @@ gpe_show_native_fwd_rpath_command_fn (vlib_main_t * vm,
lisp_gpe_main_t *lgm = &lisp_gpe_main;
fib_route_path_t *rpath;
- if (vec_len (lgm->native_fwd_rpath[IP4]))
+ if (vec_len (lgm->native_fwd_rpath[AF_IP4]))
{
- vec_foreach (rpath, lgm->native_fwd_rpath[IP4])
+ vec_foreach (rpath, lgm->native_fwd_rpath[AF_IP4])
{
vlib_cli_output (vm, "nh: %U fib_index %u sw_if_index %u",
format_ip46_address, &rpath->frp_addr,
@@ -416,9 +416,9 @@ gpe_show_native_fwd_rpath_command_fn (vlib_main_t * vm,
rpath->frp_sw_if_index);
}
}
- if (vec_len (lgm->native_fwd_rpath[IP6]))
+ if (vec_len (lgm->native_fwd_rpath[AF_IP6]))
{
- vec_foreach (rpath, lgm->native_fwd_rpath[IP6])
+ vec_foreach (rpath, lgm->native_fwd_rpath[AF_IP6])
{
vlib_cli_output (vm, "nh: %U fib_index %u sw_if_index %u",
format_ip46_address, &rpath->frp_addr, IP46_TYPE_IP6,
@@ -461,7 +461,7 @@ vnet_gpe_add_del_native_fwd_rpath (vnet_gpe_native_fwd_rpath_args_t * a)
fib_route_path_t *rpath;
u8 ip_version;
- ip_version = a->rpath.frp_proto == DPO_PROTO_IP4 ? IP4 : IP6;
+ ip_version = a->rpath.frp_proto == DPO_PROTO_IP4 ? AF_IP4 : AF_IP6;
if (a->is_add)
{
diff --git a/src/vnet/lisp-gpe/lisp_gpe_adjacency.c b/src/vnet/lisp-gpe/lisp_gpe_adjacency.c
index 1b53e4dd9fe..4b5ca17dad5 100644
--- a/src/vnet/lisp-gpe/lisp_gpe_adjacency.c
+++ b/src/vnet/lisp-gpe/lisp_gpe_adjacency.c
@@ -99,9 +99,9 @@ lisp_gpe_adj_get_fib_chain_type (const lisp_gpe_adjacency_t * ladj)
{
switch (ip_addr_version (&ladj->remote_rloc))
{
- case IP4:
+ case AF_IP4:
return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
- case IP6:
+ case AF_IP6:
return (FIB_FORW_CHAIN_TYPE_UNICAST_IP6);
default:
ASSERT (0);
@@ -116,11 +116,11 @@ ip46_address_to_ip_address (const ip46_address_t * a, ip_address_t * b)
if (ip46_address_is_ip4 (a))
{
clib_memset (b, 0, sizeof (*b));
- ip_address_set (b, &a->ip4, IP4);
+ ip_address_set (b, &a->ip4, AF_IP4);
}
else
{
- ip_address_set (b, &a->ip6, IP6);
+ ip_address_set (b, &a->ip6, AF_IP6);
}
}
diff --git a/src/vnet/lisp-gpe/lisp_gpe_api.c b/src/vnet/lisp-gpe/lisp_gpe_api.c
index 515f4844a02..16c1128c131 100644
--- a/src/vnet/lisp-gpe/lisp_gpe_api.c
+++ b/src/vnet/lisp-gpe/lisp_gpe_api.c
@@ -75,7 +75,7 @@ unformat_gpe_loc_pairs (void *locs, u32 rloc_num)
/* local locator */
r = &((vl_api_gpe_locator_t *) locs)[i];
clib_memset (&pair, 0, sizeof (pair));
- ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
+ ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? AF_IP4 : AF_IP6);
pair.weight = r->weight;
vec_add1 (pairs, pair);
@@ -86,7 +86,7 @@ unformat_gpe_loc_pairs (void *locs, u32 rloc_num)
/* remote locators */
r = &((vl_api_gpe_locator_t *) locs)[i];
p = &pairs[i - rloc_num];
- ip_address_set (&p->rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
+ ip_address_set (&p->rmt_loc, &r->addr, r->is_ip4 ? AF_IP4 : AF_IP6);
}
return pairs;
}
@@ -99,13 +99,13 @@ unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
{
case 0: /* ipv4 */
gid_address_type (dst) = GID_ADDR_IP_PREFIX;
- gid_address_ip_set (dst, src, IP4);
+ gid_address_ip_set (dst, src, AF_IP4);
gid_address_ippref_len (dst) = len;
ip_prefix_normalize (&gid_address_ippref (dst));
break;
case 1: /* ipv6 */
gid_address_type (dst) = GID_ADDR_IP_PREFIX;
- gid_address_ip_set (dst, src, IP6);
+ gid_address_ip_set (dst, src, AF_IP6);
gid_address_ippref_len (dst) = len;
ip_prefix_normalize (&gid_address_ippref (dst));
break;
@@ -135,7 +135,7 @@ lisp_api_set_locator (vl_api_gpe_locator_t * loc,
const ip_address_t * addr, u8 weight)
{
loc->weight = weight;
- if (IP4 == ip_addr_version (addr))
+ if (AF_IP4 == ip_addr_version (addr))
{
loc->is_ip4 = 1;
memcpy (loc->addr, addr, 4);
@@ -208,7 +208,7 @@ gpe_fwd_entries_copy (vl_api_gpe_fwd_entry_t * dst,
switch (fid_addr_type (&e->leid))
{
case FID_ADDR_IP_PREF:
- if (IP4 == ip_prefix_version (&fid_addr_ippref (&e->leid)))
+ if (AF_IP4 == ip_prefix_version (&fid_addr_ippref (&e->leid)))
{
memcpy (&dst[i].leid, &fid_addr_ippref (&e->leid), 4);
memcpy (&dst[i].reid, &fid_addr_ippref (&e->reid), 4);
diff --git a/src/vnet/lisp-gpe/lisp_gpe_fwd_entry.c b/src/vnet/lisp-gpe/lisp_gpe_fwd_entry.c
index 2d6cd013941..45246955248 100644
--- a/src/vnet/lisp-gpe/lisp_gpe_fwd_entry.c
+++ b/src/vnet/lisp-gpe/lisp_gpe_fwd_entry.c
@@ -87,7 +87,7 @@ ip_dst_fib_add_route (u32 dst_fib_index, const ip_prefix_t * dst_prefix)
*/
lookup_dpo_add_or_lock_w_fib_index (src_fib_index,
(ip_prefix_version (dst_prefix) ==
- IP6 ? DPO_PROTO_IP6 :
+ AF_IP6 ? DPO_PROTO_IP6 :
DPO_PROTO_IP4),
LOOKUP_UNICAST,
LOOKUP_INPUT_SRC_ADDR,
@@ -329,7 +329,7 @@ create_fib_entries (lisp_gpe_fwd_entry_t * lfe)
ip_prefix_t ippref;
fib_prefix_t fib_prefix;
u8 ip_version = ip_prefix_version (&lfe->key->rmt.ippref);
- dproto = (ip_version == IP4 ? DPO_PROTO_IP4 : DPO_PROTO_IP6);
+ dproto = (ip_version == AF_IP4 ? DPO_PROTO_IP4 : DPO_PROTO_IP6);
if (lfe->is_src_dst)
{
@@ -539,7 +539,7 @@ add_ip_fwd_entry (lisp_gpe_main_t * lgm,
lfe - lgm->lisp_fwd_entry_pool);
a->fwd_entry_index = lfe - lgm->lisp_fwd_entry_pool;
- fproto = (IP4 == ip_prefix_version (&fid_addr_ippref (&lfe->key->rmt)) ?
+ fproto = (AF_IP4 == ip_prefix_version (&fid_addr_ippref (&lfe->key->rmt)) ?
FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
lfe->type = (a->is_negative ?
@@ -581,7 +581,7 @@ del_ip_fwd_entry_i (lisp_gpe_main_t * lgm, lisp_gpe_fwd_entry_t * lfe)
delete_fib_entries (lfe);
- fproto = (IP4 == ip_prefix_version (&fid_addr_ippref (&lfe->key->rmt)) ?
+ fproto = (AF_IP4 == ip_prefix_version (&fid_addr_ippref (&lfe->key->rmt)) ?
FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
fib_table_unlock (lfe->eid_fib_index, fproto, FIB_SOURCE_LISP);
diff --git a/src/vnet/lisp-gpe/lisp_gpe_sub_interface.h b/src/vnet/lisp-gpe/lisp_gpe_sub_interface.h
index 1abb314fbb3..457db93e910 100644
--- a/src/vnet/lisp-gpe/lisp_gpe_sub_interface.h
+++ b/src/vnet/lisp-gpe/lisp_gpe_sub_interface.h
@@ -112,7 +112,7 @@ lisp_gpe_sub_interface_find_ip6 (const ip6_address_t * addr, u32 vni)
key.local_rloc.ip.v6.as_u64[0] = addr->as_u64[0];
key.local_rloc.ip.v6.as_u64[1] = addr->as_u64[1];
- key.local_rloc.version = IP6;
+ key.local_rloc.version = AF_IP6;
key.vni = vni;
p = hash_get_mem (&lisp_gpe_sub_interfaces_sw_if_index, &key);
@@ -135,7 +135,7 @@ lisp_gpe_sub_interface_find_ip4 (const ip4_address_t * addr, u32 vni)
const uword *p;
key.local_rloc.ip.v4.as_u32 = addr->as_u32;
- key.local_rloc.version = IP4;
+ key.local_rloc.version = AF_IP4;
key.vni = vni;
p = hash_get_mem (&lisp_gpe_sub_interfaces_sw_if_index, &key);
diff --git a/src/vnet/lisp-gpe/lisp_gpe_tunnel.c b/src/vnet/lisp-gpe/lisp_gpe_tunnel.c
index d0e9bc268dc..0373542ba34 100644
--- a/src/vnet/lisp-gpe/lisp_gpe_tunnel.c
+++ b/src/vnet/lisp-gpe/lisp_gpe_tunnel.c
@@ -52,7 +52,7 @@ lisp_gpe_tunnel_build_rewrite (const lisp_gpe_tunnel_t * lgt,
int len;
gpe_encap_mode_t encap_mode = vnet_gpe_get_encap_mode ();
- if (IP4 == ip_addr_version (&lgt->key->lcl))
+ if (AF_IP4 == ip_addr_version (&lgt->key->lcl))
{
ip4_udp_lisp_gpe_header_t *h0;
ip4_header_t *ip0;
diff --git a/test/test_lisp.py b/test/test_lisp.py
index 0b89b1f0d68..ca12854637a 100644
--- a/test/test_lisp.py
+++ b/test/test_lisp.py
@@ -189,5 +189,25 @@ class TestLisp(VppTestCase):
self.test_driver.run(self.deid_ip4)
+class TestLispUT(VppTestCase):
+ """ Lisp UT """
+
+ @classmethod
+ def setUpClass(cls):
+ super(TestLispUT, cls).setUpClass()
+
+ @classmethod
+ def tearDownClass(cls):
+ super(TestLispUT, cls).tearDownClass()
+
+ def test_fib(self):
+ """ LISP Unit Tests """
+ error = self.vapi.cli("test lisp cp")
+
+ if error:
+ self.logger.critical(error)
+ self.assertNotIn("Failed", error)
+
+
if __name__ == '__main__':
unittest.main(testRunner=VppTestRunner)