aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/lisp-cp
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2019-11-12 17:16:47 +0000
committerFlorin Coras <florin.coras@gmail.com>2019-11-12 18:56:04 +0000
commitea93e48cf6e918937422638cb574964b88a146b6 (patch)
treec35f8c921a8a9175b0dbf89e3e0775abc433e521 /src/vnet/lisp-cp
parentc046d709e1e493d20fee80f8c23b4106be67a98e (diff)
ip: IP address and prefix types (moved from LISP)
Type: refactor Change-Id: I2c6b59013bfd21136a2955442c779685f951932b Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'src/vnet/lisp-cp')
-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
8 files changed, 92 insertions, 422 deletions
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 8a0ffffd9cf..3f18a5dee70 100644
--- a/src/vnet/lisp-cp/lisp_api.c
+++ b/src/vnet/lisp-cp/lisp_api.c
@@ -99,7 +99,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;
@@ -205,13 +206,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;
@@ -301,7 +302,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);
@@ -318,7 +319,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);
@@ -407,7 +408,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);
@@ -446,12 +447,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;
@@ -459,7 +460,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* */
}
@@ -708,7 +709,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);
@@ -735,9 +736,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;
@@ -818,7 +819,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),
@@ -897,13 +898,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)));
@@ -946,13 +947,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)));
@@ -1059,7 +1060,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 447b68f377c..17d4afc8267 100644
--- a/src/vnet/lisp-cp/one_api.c
+++ b/src/vnet/lisp-cp/one_api.c
@@ -146,7 +146,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;
@@ -289,13 +290,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;
@@ -396,7 +397,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);
@@ -413,7 +414,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);
@@ -519,7 +520,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);
@@ -558,12 +559,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;
@@ -571,7 +572,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* */
}
@@ -818,7 +819,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);
@@ -845,9 +846,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;
@@ -927,7 +928,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),
@@ -1013,13 +1014,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)));
@@ -1062,13 +1063,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)));
@@ -1175,7 +1176,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);
@@ -1460,7 +1461,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);
@@ -1509,7 +1510,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);
@@ -1533,7 +1534,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);
@@ -1550,7 +1551,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;