summaryrefslogtreecommitdiffstats
path: root/src/vnet
diff options
context:
space:
mode:
authorEyal Bari <ebari@cisco.com>2017-03-15 08:23:42 +0200
committerJohn Lo <loj@cisco.com>2017-03-15 12:44:00 +0000
commite101e1f52f1da71575588fac30b984a0e94fb5a7 (patch)
tree11fcadb6249f343b52a7957d612158edee9d9059 /src/vnet
parent3bde40778cc2bf5fab6b13d81eca0180f7d27af3 (diff)
VXLAN:add hidden multicast interface check
and some refactoring Change-Id: I99e3c5e782ce65cb9779ccc3a9a3151ef1429e07 Signed-off-by: Eyal Bari <ebari@cisco.com>
Diffstat (limited to 'src/vnet')
-rw-r--r--src/vnet/ip/ip6_packet.h14
-rw-r--r--src/vnet/vxlan/vxlan_api.c40
2 files changed, 25 insertions, 29 deletions
diff --git a/src/vnet/ip/ip6_packet.h b/src/vnet/ip/ip6_packet.h
index bb7d703926b..cdd7eed5a82 100644
--- a/src/vnet/ip/ip6_packet.h
+++ b/src/vnet/ip/ip6_packet.h
@@ -82,21 +82,23 @@ typedef CLIB_PACKED (union {
#define ip46_address_is_equal(a1, a2) (((a1)->as_u64[0] == (a2)->as_u64[0]) \
&& ((a1)->as_u64[1] == (a2)->as_u64[1]))
-always_inline void
-ip46_from_addr_buf (u32 is_ipv6, u8 * buf, ip46_address_t * ip)
+always_inline ip46_address_t
+to_ip46 (u32 is_ipv6, u8 * buf)
{
+ ip46_address_t ip;
if (is_ipv6)
- ip->ip6 = *((ip6_address_t *) buf);
+ ip.ip6 = *((ip6_address_t *) buf);
else
- ip46_address_set_ip4 (ip, (ip4_address_t *) buf);
+ ip46_address_set_ip4 (&ip, (ip4_address_t *) buf);
+ return ip;
}
+
always_inline void
ip6_addr_fib_init (ip6_address_fib_t * addr_fib, ip6_address_t * address,
u32 fib_index)
{
- addr_fib->ip6_addr.as_u64[0] = address->as_u64[0];
- addr_fib->ip6_addr.as_u64[1] = address->as_u64[1];
+ addr_fib->ip6_addr = *address;
addr_fib->fib_index = fib_index;
}
diff --git a/src/vnet/vxlan/vxlan_api.c b/src/vnet/vxlan/vxlan_api.c
index c726c7c5b6a..a2d412322fb 100644
--- a/src/vnet/vxlan/vxlan_api.c
+++ b/src/vnet/vxlan/vxlan_api.c
@@ -70,47 +70,41 @@ static void vl_api_vxlan_add_del_tunnel_t_handler
{
vl_api_vxlan_add_del_tunnel_reply_t *rmp;
int rv = 0;
- vnet_vxlan_add_del_tunnel_args_t _a, *a = &_a;
- u32 encap_fib_index;
- uword *p;
ip4_main_t *im = &ip4_main;
- vnet_main_t *vnm = vnet_get_main ();
- u32 sw_if_index = ~0;
- p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
+ uword *p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
if (!p)
{
rv = VNET_API_ERROR_NO_SUCH_FIB;
goto out;
}
- encap_fib_index = p[0];
- memset (a, 0, sizeof (*a));
-
- a->is_add = mp->is_add;
- a->is_ip6 = mp->is_ipv6;
- /* ip addresses sent in network byte order */
- ip46_from_addr_buf (mp->is_ipv6, mp->dst_address, &a->dst);
- ip46_from_addr_buf (mp->is_ipv6, mp->src_address, &a->src);
+ vnet_vxlan_add_del_tunnel_args_t a = {
+ .is_add = mp->is_add,
+ .is_ip6 = mp->is_ipv6,
+ .mcast_sw_if_index = ntohl (mp->mcast_sw_if_index),
+ .encap_fib_index = p[0],
+ .decap_next_index = ntohl (mp->decap_next_index),
+ .vni = ntohl (mp->vni),
+ .dst = to_ip46 (mp->is_ipv6, mp->dst_address),
+ .src = to_ip46 (mp->is_ipv6, mp->src_address),
+ };
/* Check src & dst are different */
- if (ip46_address_cmp (&a->dst, &a->src) == 0)
+ if (ip46_address_cmp (&a.dst, &a.src) == 0)
{
rv = VNET_API_ERROR_SAME_SRC_DST;
goto out;
}
- a->mcast_sw_if_index = ntohl (mp->mcast_sw_if_index);
- if (ip46_address_is_multicast (&a->dst) &&
- pool_is_free_index (vnm->interface_main.sw_interfaces,
- a->mcast_sw_if_index))
+ if (ip46_address_is_multicast (&a.dst) &&
+ !vnet_sw_if_index_is_api_valid (a.mcast_sw_if_index))
{
rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
goto out;
}
- a->encap_fib_index = encap_fib_index;
- a->decap_next_index = ntohl (mp->decap_next_index);
- a->vni = ntohl (mp->vni);
- rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
+
+ u32 sw_if_index = ~0;
+ rv = vnet_vxlan_add_del_tunnel (&a, &sw_if_index);
out:
/* *INDENT-OFF* */