From 7cd468a3d7dee7d6c92f69a0bb7061ae208ec727 Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Mon, 19 Dec 2016 23:05:39 +0100 Subject: Reorganize source tree to use single autotools instance Change-Id: I7b51f88292e057c6443b12224486f2d0c9f8ae23 Signed-off-by: Damjan Marion --- src/vnet/vxlan/vxlan_api.c | 253 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 src/vnet/vxlan/vxlan_api.c (limited to 'src/vnet/vxlan/vxlan_api.c') diff --git a/src/vnet/vxlan/vxlan_api.c b/src/vnet/vxlan/vxlan_api.c new file mode 100644 index 00000000..6c9cbd79 --- /dev/null +++ b/src/vnet/vxlan/vxlan_api.c @@ -0,0 +1,253 @@ +/* + *------------------------------------------------------------------ + * vxlan_api.c - vxlan api + * + * 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 +#include + +#include +#include +#include +#include +#include + +#include + +#define vl_typedefs /* define message structures */ +#include +#undef vl_typedefs + +#define vl_endianfun /* define message structures */ +#include +#undef vl_endianfun + +/* instantiate all the print functions we know about */ +#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) +#define vl_printfun +#include +#undef vl_printfun + +#include + +#define foreach_vpe_api_msg \ +_(SW_INTERFACE_SET_VXLAN_BYPASS, sw_interface_set_vxlan_bypass) \ +_(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \ +_(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) + +static void + vl_api_sw_interface_set_vxlan_bypass_t_handler + (vl_api_sw_interface_set_vxlan_bypass_t * mp) +{ + vl_api_sw_interface_set_vxlan_bypass_reply_t *rmp; + int rv = 0; + u32 sw_if_index = ntohl (mp->sw_if_index); + + VALIDATE_SW_IF_INDEX (mp); + + if (mp->is_ipv6) + { + /* not yet implemented */ + } + else + vnet_feature_enable_disable ("ip4-unicast", "ip4-vxlan-bypass", + sw_if_index, mp->enable, 0, 0); + + BAD_SW_IF_INDEX_LABEL; + + REPLY_MACRO (VL_API_SW_INTERFACE_SET_VXLAN_BYPASS_REPLY); +} + +static void vl_api_vxlan_add_del_tunnel_t_handler + (vl_api_vxlan_add_del_tunnel_t * mp) +{ + 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)); + 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); + + /* Check src & dst are different */ + 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)) + { + 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); + +out: + /* *INDENT-OFF* */ + REPLY_MACRO2(VL_API_VXLAN_ADD_DEL_TUNNEL_REPLY, + ({ + rmp->sw_if_index = ntohl (sw_if_index); + })); + /* *INDENT-ON* */ +} + +static void send_vxlan_tunnel_details + (vxlan_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context) +{ + vl_api_vxlan_tunnel_details_t *rmp; + ip4_main_t *im4 = &ip4_main; + ip6_main_t *im6 = &ip6_main; + u8 is_ipv6 = !ip46_address_is_ip4 (&t->dst); + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + memset (rmp, 0, sizeof (*rmp)); + rmp->_vl_msg_id = ntohs (VL_API_VXLAN_TUNNEL_DETAILS); + if (is_ipv6) + { + memcpy (rmp->src_address, t->src.ip6.as_u8, 16); + memcpy (rmp->dst_address, t->dst.ip6.as_u8, 16); + rmp->encap_vrf_id = htonl (im6->fibs[t->encap_fib_index].ft_table_id); + } + else + { + memcpy (rmp->src_address, t->src.ip4.as_u8, 4); + memcpy (rmp->dst_address, t->dst.ip4.as_u8, 4); + rmp->encap_vrf_id = htonl (im4->fibs[t->encap_fib_index].ft_table_id); + } + rmp->mcast_sw_if_index = htonl (t->mcast_sw_if_index); + rmp->vni = htonl (t->vni); + rmp->decap_next_index = htonl (t->decap_next_index); + rmp->sw_if_index = htonl (t->sw_if_index); + rmp->is_ipv6 = is_ipv6; + rmp->context = context; + + vl_msg_api_send_shmem (q, (u8 *) & rmp); +} + +static void vl_api_vxlan_tunnel_dump_t_handler + (vl_api_vxlan_tunnel_dump_t * mp) +{ + unix_shared_memory_queue_t *q; + vxlan_main_t *vxm = &vxlan_main; + vxlan_tunnel_t *t; + u32 sw_if_index; + + q = vl_api_client_index_to_input_queue (mp->client_index); + if (q == 0) + { + return; + } + + sw_if_index = ntohl (mp->sw_if_index); + + if (~0 == sw_if_index) + { + /* *INDENT-OFF* */ + pool_foreach (t, vxm->tunnels, + ({ + send_vxlan_tunnel_details(t, q, mp->context); + })); + /* *INDENT-ON* */ + } + else + { + if ((sw_if_index >= vec_len (vxm->tunnel_index_by_sw_if_index)) || + (~0 == vxm->tunnel_index_by_sw_if_index[sw_if_index])) + { + return; + } + t = &vxm->tunnels[vxm->tunnel_index_by_sw_if_index[sw_if_index]]; + send_vxlan_tunnel_details (t, q, mp->context); + } +} + +/* + * vpe_api_hookup + * Add vpe's API message handlers to the table. + * vlib has alread mapped shared memory and + * added the client registration handlers. + * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() + */ +#define vl_msg_name_crc_list +#include +#undef vl_msg_name_crc_list + +static void +setup_message_id_table (api_main_t * am) +{ +#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); + foreach_vl_msg_name_crc_vxlan; +#undef _ +} + +static clib_error_t * +vxlan_api_hookup (vlib_main_t * vm) +{ + api_main_t *am = &api_main; + +#define _(N,n) \ + vl_msg_api_set_handlers(VL_API_##N, #n, \ + vl_api_##n##_t_handler, \ + vl_noop_handler, \ + vl_api_##n##_t_endian, \ + vl_api_##n##_t_print, \ + sizeof(vl_api_##n##_t), 1); + foreach_vpe_api_msg; +#undef _ + + am->api_trace_cfg[VL_API_VXLAN_ADD_DEL_TUNNEL].size += 16 * sizeof (u32); + + /* + * Set up the (msg_name, crc, message-id) table + */ + setup_message_id_table (am); + + return 0; +} + +VLIB_API_INIT_FUNCTION (vxlan_api_hookup); + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ -- cgit 1.2.3-korg From 2b81eb830393fe88c8247cb9015bdaf4060f6ceb Mon Sep 17 00:00:00 2001 From: John Lo Date: Mon, 30 Jan 2017 13:12:10 -0500 Subject: Add vxlan-bypass feature to IP6 forwarding path Add vxlan-bypass feature which can be enabled on the IP6 underlay interface which receive VXLAN packets to accelerate VXLAN decap processing. The CLI to enable/disable it is: set interface ip6 vxlan-bypass [del] The vxlan-bypass feature is already supported on the IP4 underlay interface. The CLI to enable/disable it is: set interface ip vxlan-bypass [del] Move vxlan-bypass API/CLI support code from decap.c to vxlan.c. Also fixed two issues in the VXLAN decap path in the vxlan-input node: 1. Add verification of VXLAN packet FIB index with the encap-vrf-id of the VXLAN tunnel. 2. Fix checking of VXLANoIPv6 packet mcast DIP against that of the IP6 mcast VXLAN tunnel. Change-Id: I2bad4074a468c48fbb8bb5ac64f6437190756ed2 Signed-off-by: John Lo --- src/vat/api_format.c | 4 +- src/vnet/ip/ip6.h | 4 + src/vnet/ip/ip6_forward.c | 9 +- src/vnet/vxlan/decap.c | 455 ++++++++++++++++++++++++++++----------------- src/vnet/vxlan/vxlan.c | 171 +++++++++++++++++ src/vnet/vxlan/vxlan.h | 2 + src/vnet/vxlan/vxlan_api.c | 9 +- 7 files changed, 470 insertions(+), 184 deletions(-) (limited to 'src/vnet/vxlan/vxlan_api.c') diff --git a/src/vat/api_format.c b/src/vat/api_format.c index 6a450993..d4834b70 100644 --- a/src/vat/api_format.c +++ b/src/vat/api_format.c @@ -5491,7 +5491,7 @@ api_sw_interface_set_vxlan_bypass (vat_main_t * vam) f64 timeout; u32 sw_if_index = 0; u8 sw_if_index_set = 0; - u8 is_enable = 0; + u8 is_enable = 1; u8 is_ipv6 = 0; /* Parse args required to build the message */ @@ -17876,7 +17876,7 @@ _(sw_interface_set_mpls_enable, \ _(sw_interface_set_vpath, \ " | sw_if_index enable | disable") \ _(sw_interface_set_vxlan_bypass, \ - " | sw_if_index [ip4 | ip6] enable | disable") \ + " | sw_if_index [ip4 | ip6] [enable | disable]") \ _(sw_interface_set_l2_xconnect, \ "rx | rx_sw_if_index tx | tx_sw_if_index \n" \ "enable | disable") \ diff --git a/src/vnet/ip/ip6.h b/src/vnet/ip/ip6.h index 6fecd42d..15269873 100644 --- a/src/vnet/ip/ip6.h +++ b/src/vnet/ip/ip6.h @@ -426,6 +426,10 @@ int vnet_ip6_nd_term (vlib_main_t * vm, ip6_header_t * ip, u32 sw_if_index, u16 bd_index, u8 shg); +u8 *format_ip6_forward_next_trace (u8 * s, va_list * args); + +u32 ip6_tcp_udp_icmp_validate_checksum (vlib_main_t * vm, vlib_buffer_t * p0); + int vnet_set_ip6_classify_intfc (vlib_main_t * vm, u32 sw_if_index, u32 table_index); extern vlib_node_registration_t ip6_lookup_node; diff --git a/src/vnet/ip/ip6_forward.c b/src/vnet/ip/ip6_forward.c index ac47b3ad..50951c27 100644 --- a/src/vnet/ip/ip6_forward.c +++ b/src/vnet/ip/ip6_forward.c @@ -588,6 +588,13 @@ VNET_FEATURE_INIT (ip6_vpath, static) = { .arc_name = "ip6-unicast", .node_name = "vpath-input-ip6", + .runs_before = VNET_FEATURES ("ip6-vxlan-bypass"), +}; + +VNET_FEATURE_INIT (ip6_vxlan_bypass, static) = +{ + .arc_name = "ip6-unicast", + .node_name = "ip6-vxlan-bypass", .runs_before = VNET_FEATURES ("ip6-lookup"), }; @@ -921,7 +928,7 @@ typedef struct } ip6_forward_next_trace_t; -static u8 * +u8 * format_ip6_forward_next_trace (u8 * s, va_list * args) { CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); diff --git a/src/vnet/vxlan/decap.c b/src/vnet/vxlan/decap.c index 73e50ffe..d5a9442f 100644 --- a/src/vnet/vxlan/decap.c +++ b/src/vnet/vxlan/decap.c @@ -48,6 +48,25 @@ static u8 * format_vxlan_rx_trace (u8 * s, va_list * args) return s; } +always_inline u32 +validate_vxlan_fib (vlib_buffer_t *b, vxlan_tunnel_t *t, u32 is_ip4) +{ + u32 fib_index, sw_if_index; + + sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX]; + + if (is_ip4) + fib_index = (vnet_buffer (b)->sw_if_index[VLIB_TX] == (u32) ~ 0) ? + vec_elt (ip4_main.fib_index_by_sw_if_index, sw_if_index) : + vnet_buffer (b)->sw_if_index[VLIB_TX]; + else + fib_index = (vnet_buffer (b)->sw_if_index[VLIB_TX] == (u32) ~ 0) ? + vec_elt (ip6_main.fib_index_by_sw_if_index, sw_if_index) : + vnet_buffer (b)->sw_if_index[VLIB_TX]; + + return (fib_index == t->encap_fib_index); +} + always_inline uword vxlan_input (vlib_main_t * vm, vlib_node_runtime_t * node, @@ -191,7 +210,15 @@ vxlan_input (vlib_main_t * vm, tunnel_index0 = last_tunnel_index; t0 = pool_elt_at_index (vxm->tunnels, tunnel_index0); - /* Validate VXLAN tunnel SIP against packet DIP */ + /* Validate VXLAN tunnel encap-fib index agaist packet */ + if (PREDICT_FALSE (validate_vxlan_fib (b0, t0, is_ip4) == 0)) + { + error0 = VXLAN_ERROR_NO_SUCH_TUNNEL; + next0 = VXLAN_INPUT_NEXT_DROP; + goto trace0; + } + + /* Validate VXLAN tunnel SIP against packet DIP */ if (PREDICT_TRUE (ip4_0->dst_address.as_u32 == t0->src.ip4.as_u32)) goto next0; /* valid packet */ if (PREDICT_FALSE (ip4_address_is_multicast (&ip4_0->dst_address))) @@ -232,6 +259,14 @@ vxlan_input (vlib_main_t * vm, tunnel_index0 = last_tunnel_index; t0 = pool_elt_at_index (vxm->tunnels, tunnel_index0); + /* Validate VXLAN tunnel encap-fib index agaist packet */ + if (PREDICT_FALSE (validate_vxlan_fib (b0, t0, is_ip4) == 0)) + { + error0 = VXLAN_ERROR_NO_SUCH_TUNNEL; + next0 = VXLAN_INPUT_NEXT_DROP; + goto trace0; + } + /* Validate VXLAN tunnel SIP against packet DIP */ if (PREDICT_TRUE (ip6_address_is_equal (&ip6_0->dst_address, &t0->src.ip6))) @@ -241,7 +276,7 @@ vxlan_input (vlib_main_t * vm, key6_0.src.as_u64[0] = ip6_0->dst_address.as_u64[0]; key6_0.src.as_u64[1] = ip6_0->dst_address.as_u64[1]; key6_0.vni = vxlan0->vni_reserved; - p0 = hash_get (vxm->vxlan6_tunnel_by_key, &key6_0); + p0 = hash_get_mem (vxm->vxlan6_tunnel_by_key, &key6_0); if (PREDICT_TRUE (p0 != NULL)) { mt0 = pool_elt_at_index (vxm->tunnels, p0[0]); @@ -327,6 +362,14 @@ vxlan_input (vlib_main_t * vm, tunnel_index1 = last_tunnel_index; t1 = pool_elt_at_index (vxm->tunnels, tunnel_index1); + /* Validate VXLAN tunnel encap-fib index agaist packet */ + if (PREDICT_FALSE (validate_vxlan_fib (b1, t1, is_ip4) == 0)) + { + error1 = VXLAN_ERROR_NO_SUCH_TUNNEL; + next1 = VXLAN_INPUT_NEXT_DROP; + goto trace1; + } + /* Validate VXLAN tunnel SIP against packet DIP */ if (PREDICT_TRUE (ip4_1->dst_address.as_u32 == t1->src.ip4.as_u32)) goto next1; /* valid packet */ @@ -370,6 +413,14 @@ vxlan_input (vlib_main_t * vm, tunnel_index1 = last_tunnel_index; t1 = pool_elt_at_index (vxm->tunnels, tunnel_index1); + /* Validate VXLAN tunnel encap-fib index agaist packet */ + if (PREDICT_FALSE (validate_vxlan_fib (b1, t1, is_ip4) == 0)) + { + error1 = VXLAN_ERROR_NO_SUCH_TUNNEL; + next1 = VXLAN_INPUT_NEXT_DROP; + goto trace1; + } + /* Validate VXLAN tunnel SIP against packet DIP */ if (PREDICT_TRUE (ip6_address_is_equal (&ip6_1->dst_address, &t1->src.ip6))) @@ -379,7 +430,7 @@ vxlan_input (vlib_main_t * vm, key6_1.src.as_u64[0] = ip6_1->dst_address.as_u64[0]; key6_1.src.as_u64[1] = ip6_1->dst_address.as_u64[1]; key6_1.vni = vxlan1->vni_reserved; - p1 = hash_get (vxm->vxlan6_tunnel_by_key, &key6_1); + p1 = hash_get_mem (vxm->vxlan6_tunnel_by_key, &key6_1); if (PREDICT_TRUE (p1 != NULL)) { mt1 = pool_elt_at_index (vxm->tunnels, p1[0]); @@ -519,6 +570,14 @@ vxlan_input (vlib_main_t * vm, tunnel_index0 = last_tunnel_index; t0 = pool_elt_at_index (vxm->tunnels, tunnel_index0); + /* Validate VXLAN tunnel encap-fib index agaist packet */ + if (PREDICT_FALSE (validate_vxlan_fib (b0, t0, is_ip4) == 0)) + { + error0 = VXLAN_ERROR_NO_SUCH_TUNNEL; + next0 = VXLAN_INPUT_NEXT_DROP; + goto trace00; + } + /* Validate VXLAN tunnel SIP against packet DIP */ if (PREDICT_TRUE (ip4_0->dst_address.as_u32 == t0->src.ip4.as_u32)) goto next00; /* valid packet */ @@ -560,6 +619,14 @@ vxlan_input (vlib_main_t * vm, tunnel_index0 = last_tunnel_index; t0 = pool_elt_at_index (vxm->tunnels, tunnel_index0); + /* Validate VXLAN tunnel encap-fib index agaist packet */ + if (PREDICT_FALSE (validate_vxlan_fib (b0, t0, is_ip4) == 0)) + { + error0 = VXLAN_ERROR_NO_SUCH_TUNNEL; + next0 = VXLAN_INPUT_NEXT_DROP; + goto trace00; + } + /* Validate VXLAN tunnel SIP against packet DIP */ if (PREDICT_TRUE (ip6_address_is_equal (&ip6_0->dst_address, &t0->src.ip6))) @@ -569,7 +636,7 @@ vxlan_input (vlib_main_t * vm, key6_0.src.as_u64[0] = ip6_0->dst_address.as_u64[0]; key6_0.src.as_u64[1] = ip6_0->dst_address.as_u64[1]; key6_0.vni = vxlan0->vni_reserved; - p0 = hash_get (vxm->vxlan6_tunnel_by_key, &key6_0); + p0 = hash_get_mem (vxm->vxlan6_tunnel_by_key, &key6_0); if (PREDICT_TRUE (p0 != NULL)) { mt0 = pool_elt_at_index (vxm->tunnels, p0[0]); @@ -729,9 +796,9 @@ typedef enum { always_inline uword ip_vxlan_bypass_inline (vlib_main_t * vm, - vlib_node_runtime_t * node, - vlib_frame_t * frame, - u32 is_ip4) + vlib_node_runtime_t * node, + vlib_frame_t * frame, + u32 is_ip4) { vxlan_main_t * vxm = &vxlan_main; u32 * from, * to_next, n_left_from, n_left_to_next, next_index; @@ -756,7 +823,8 @@ ip_vxlan_bypass_inline (vlib_main_t * vm, while (n_left_from >= 4 && n_left_to_next >= 2) { vlib_buffer_t * b0, * b1; - ip4_header_t * ip0, * ip1; + ip4_header_t * ip40, * ip41; + ip6_header_t * ip60, * ip61; udp_header_t * udp0, * udp1; u32 bi0, ip_len0, udp_len0, flags0, next0; u32 bi1, ip_len1, udp_len1, flags1, next1; @@ -787,39 +855,65 @@ ip_vxlan_bypass_inline (vlib_main_t * vm, b0 = vlib_get_buffer (vm, bi0); b1 = vlib_get_buffer (vm, bi1); - ip0 = vlib_buffer_get_current (b0); - ip1 = vlib_buffer_get_current (b1); + if (is_ip4) + { + ip40 = vlib_buffer_get_current (b0); + ip41 = vlib_buffer_get_current (b1); + } + else + { + ip60 = vlib_buffer_get_current (b0); + ip61 = vlib_buffer_get_current (b1); + } /* Setup packet for next IP feature */ vnet_feature_next(vnet_buffer(b0)->sw_if_index[VLIB_RX], &next0, b0); vnet_feature_next(vnet_buffer(b1)->sw_if_index[VLIB_RX], &next1, b1); - /* Treat IP frag packets as "experimental" protocol for now - until support of IP frag reassembly is implemented */ - proto0 = ip4_is_fragment(ip0) ? 0xfe : ip0->protocol; - proto1 = ip4_is_fragment(ip1) ? 0xfe : ip1->protocol; + if (is_ip4) + { + /* Treat IP frag packets as "experimental" protocol for now + until support of IP frag reassembly is implemented */ + proto0 = ip4_is_fragment(ip40) ? 0xfe : ip40->protocol; + proto1 = ip4_is_fragment(ip41) ? 0xfe : ip41->protocol; + } + else + { + proto0 = ip60->protocol; + proto1 = ip61->protocol; + } /* Process packet 0 */ if (proto0 != IP_PROTOCOL_UDP) goto exit0; /* not UDP packet */ - udp0 = ip4_next_header (ip0); + if (is_ip4) + udp0 = ip4_next_header (ip40); + else + udp0 = ip6_next_header (ip60); + if (udp0->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_vxlan)) goto exit0; /* not VXLAN packet */ + /* Validate DIP against VTEPs*/ if (is_ip4) { - if (addr4.as_u32 != ip0->dst_address.as_u32) + if (addr4.as_u32 != ip40->dst_address.as_u32) { - if (!hash_get (vxm->vtep4, ip0->dst_address.as_u32)) - goto exit0; /* no local VTEP for VXLAN packet */ - addr4 = ip0->dst_address; + if (!hash_get (vxm->vtep4, ip40->dst_address.as_u32)) + goto exit0; /* no local VTEP for VXLAN packet */ + addr4 = ip40->dst_address; + } + } + else + { + if (!ip6_address_is_equal (&addr6, &ip60->dst_address)) + { + if (!hash_get_mem (vxm->vtep6, &ip60->dst_address)) + goto exit0; /* no local VTEP for VXLAN packet */ + addr6 = ip60->dst_address; } } - else goto exit0; /* IP6 VXLAN bypass not yet supported */ - - /* vxlan-input node expect current at VXLAN header */ - vlib_buffer_advance (b0, sizeof(ip4_header_t)+sizeof(udp_header_t)); flags0 = b0->flags; good_udp0 = (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0; @@ -828,49 +922,80 @@ ip_vxlan_bypass_inline (vlib_main_t * vm, good_udp0 |= udp0->checksum == 0; /* Verify UDP length */ - ip_len0 = clib_net_to_host_u16 (ip0->length); + if (is_ip4) + ip_len0 = clib_net_to_host_u16 (ip40->length); + else + ip_len0 = clib_net_to_host_u16 (ip60->payload_length); udp_len0 = clib_net_to_host_u16 (udp0->length); - len_diff0 = ip_len0 - udp_len0; /* Verify UDP checksum */ if (PREDICT_FALSE (!good_udp0)) { - if (!(flags0 & IP_BUFFER_L4_CHECKSUM_COMPUTED)) - flags0 = ip4_tcp_udp_validate_checksum (vm, b0); - good_udp0 = - (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0; + if ((flags0 & IP_BUFFER_L4_CHECKSUM_COMPUTED) == 0) + { + if (is_ip4) + flags0 = ip4_tcp_udp_validate_checksum (vm, b0); + else + flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0); + good_udp0 = + (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0; + } } - error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM; - error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH; + if (is_ip4) + { + error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM; + error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH; + } + else + { + error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM; + error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH; + } next0 = error0 ? IP_VXLAN_BYPASS_NEXT_DROP : IP_VXLAN_BYPASS_NEXT_VXLAN; b0->error = error0 ? error_node->errors[error0] : 0; + /* vxlan-input node expect current at VXLAN header */ + if (is_ip4) + vlib_buffer_advance (b0, sizeof(ip4_header_t)+sizeof(udp_header_t)); + else + vlib_buffer_advance (b0, sizeof(ip6_header_t)+sizeof(udp_header_t)); + exit0: /* Process packet 1 */ if (proto1 != IP_PROTOCOL_UDP) goto exit1; /* not UDP packet */ - udp1 = ip4_next_header (ip1); + if (is_ip4) + udp1 = ip4_next_header (ip41); + else + udp1 = ip6_next_header (ip61); + if (udp1->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_vxlan)) goto exit1; /* not VXLAN packet */ + /* Validate DIP against VTEPs*/ if (is_ip4) { - if (addr4.as_u32 != ip1->dst_address.as_u32) + if (addr4.as_u32 != ip41->dst_address.as_u32) { - if (!hash_get (vxm->vtep4, ip1->dst_address.as_u32)) - goto exit1; /* no local VTEP for VXLAN packet */ - addr4 = ip1->dst_address; - } + if (!hash_get (vxm->vtep4, ip41->dst_address.as_u32)) + goto exit1; /* no local VTEP for VXLAN packet */ + addr4 = ip41->dst_address; + } + } + else + { + if (!ip6_address_is_equal (&addr6, &ip61->dst_address)) + { + if (!hash_get_mem (vxm->vtep6, &ip61->dst_address)) + goto exit1; /* no local VTEP for VXLAN packet */ + addr6 = ip61->dst_address; + } } - else goto exit1; /* IP6 VXLAN bypass not yet supported */ - - /* vxlan-input node expect current at VXLAN header */ - vlib_buffer_advance (b1, sizeof(ip4_header_t)+sizeof(udp_header_t)); flags1 = b1->flags; good_udp1 = (flags1 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0; @@ -879,27 +1004,48 @@ ip_vxlan_bypass_inline (vlib_main_t * vm, good_udp1 |= udp1->checksum == 0; /* Verify UDP length */ - ip_len1 = clib_net_to_host_u16 (ip1->length); + if (is_ip4) + ip_len1 = clib_net_to_host_u16 (ip41->length); + else + ip_len1 = clib_net_to_host_u16 (ip61->payload_length); udp_len1 = clib_net_to_host_u16 (udp1->length); - len_diff1 = ip_len1 - udp_len1; /* Verify UDP checksum */ if (PREDICT_FALSE (!good_udp1)) { - if (!(flags1 & IP_BUFFER_L4_CHECKSUM_COMPUTED)) - flags1 = ip4_tcp_udp_validate_checksum (vm, b1); - good_udp1 = - (flags1 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0; + if ((flags1 & IP_BUFFER_L4_CHECKSUM_COMPUTED) == 0) + { + if (is_ip4) + flags1 = ip4_tcp_udp_validate_checksum (vm, b1); + else + flags1 = ip6_tcp_udp_icmp_validate_checksum (vm, b1); + good_udp1 = + (flags1 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0; + } } - error1 = good_udp1 ? 0 : IP4_ERROR_UDP_CHECKSUM; - error1 = (len_diff1 >= 0) ? error1 : IP4_ERROR_UDP_LENGTH; + if (is_ip4) + { + error1 = good_udp1 ? 0 : IP4_ERROR_UDP_CHECKSUM; + error1 = (len_diff1 >= 0) ? error1 : IP4_ERROR_UDP_LENGTH; + } + else + { + error1 = good_udp1 ? 0 : IP4_ERROR_UDP_CHECKSUM; + error1 = (len_diff1 >= 0) ? error1 : IP4_ERROR_UDP_LENGTH; + } next1 = error1 ? IP_VXLAN_BYPASS_NEXT_DROP : IP_VXLAN_BYPASS_NEXT_VXLAN; b1->error = error1 ? error_node->errors[error1] : 0; + /* vxlan-input node expect current at VXLAN header */ + if (is_ip4) + vlib_buffer_advance (b1, sizeof(ip4_header_t)+sizeof(udp_header_t)); + else + vlib_buffer_advance (b1, sizeof(ip6_header_t)+sizeof(udp_header_t)); + exit1: vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next, n_left_to_next, @@ -909,7 +1055,8 @@ ip_vxlan_bypass_inline (vlib_main_t * vm, while (n_left_from > 0 && n_left_to_next > 0) { vlib_buffer_t * b0; - ip4_header_t * ip0; + ip4_header_t * ip40; + ip6_header_t * ip60; udp_header_t * udp0; u32 bi0, ip_len0, udp_len0, flags0, next0; i32 len_diff0; @@ -922,35 +1069,51 @@ ip_vxlan_bypass_inline (vlib_main_t * vm, n_left_to_next -= 1; b0 = vlib_get_buffer (vm, bi0); - ip0 = vlib_buffer_get_current (b0); + if (is_ip4) + ip40 = vlib_buffer_get_current (b0); + else + ip60 = vlib_buffer_get_current (b0); /* Setup packet for next IP feature */ vnet_feature_next(vnet_buffer(b0)->sw_if_index[VLIB_RX], &next0, b0); - /* Treat IP frag packets as "experimental" protocol for now - until support of IP frag reassembly is implemented */ - proto0 = ip4_is_fragment(ip0) ? 0xfe : ip0->protocol; + if (is_ip4) + /* Treat IP4 frag packets as "experimental" protocol for now + until support of IP frag reassembly is implemented */ + proto0 = ip4_is_fragment(ip40) ? 0xfe : ip40->protocol; + else + proto0 = ip60->protocol; if (proto0 != IP_PROTOCOL_UDP) goto exit; /* not UDP packet */ - udp0 = ip4_next_header (ip0); + if (is_ip4) + udp0 = ip4_next_header (ip40); + else + udp0 = ip6_next_header (ip60); + if (udp0->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_vxlan)) goto exit; /* not VXLAN packet */ + /* Validate DIP against VTEPs*/ if (is_ip4) { - if (addr4.as_u32 != ip0->dst_address.as_u32) + if (addr4.as_u32 != ip40->dst_address.as_u32) { - if (!hash_get (vxm->vtep4, ip0->dst_address.as_u32)) - goto exit; /* no local VTEP for VXLAN packet */ - addr4 = ip0->dst_address; - } + if (!hash_get (vxm->vtep4, ip40->dst_address.as_u32)) + goto exit; /* no local VTEP for VXLAN packet */ + addr4 = ip40->dst_address; + } + } + else + { + if (!ip6_address_is_equal (&addr6, &ip60->dst_address)) + { + if (!hash_get_mem (vxm->vtep6, &ip60->dst_address)) + goto exit; /* no local VTEP for VXLAN packet */ + addr6 = ip60->dst_address; + } } - else goto exit; /* IP6 VXLAN bypass not yet supported */ - - /* vxlan-input node expect current at VXLAN header */ - vlib_buffer_advance (b0, sizeof(ip4_header_t)+sizeof(udp_header_t)); flags0 = b0->flags; good_udp0 = (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0; @@ -959,27 +1122,48 @@ ip_vxlan_bypass_inline (vlib_main_t * vm, good_udp0 |= udp0->checksum == 0; /* Verify UDP length */ - ip_len0 = clib_net_to_host_u16 (ip0->length); + if (is_ip4) + ip_len0 = clib_net_to_host_u16 (ip40->length); + else + ip_len0 = clib_net_to_host_u16 (ip60->payload_length); udp_len0 = clib_net_to_host_u16 (udp0->length); - len_diff0 = ip_len0 - udp_len0; /* Verify UDP checksum */ if (PREDICT_FALSE (!good_udp0)) { - if (!(flags0 & IP_BUFFER_L4_CHECKSUM_COMPUTED)) - flags0 = ip4_tcp_udp_validate_checksum (vm, b0); - good_udp0 = - (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0; + if ((flags0 & IP_BUFFER_L4_CHECKSUM_COMPUTED) == 0) + { + if (is_ip4) + flags0 = ip4_tcp_udp_validate_checksum (vm, b0); + else + flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0); + good_udp0 = + (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0; + } } - error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM; - error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH; + if (is_ip4) + { + error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM; + error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH; + } + else + { + error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM; + error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH; + } next0 = error0 ? IP_VXLAN_BYPASS_NEXT_DROP : IP_VXLAN_BYPASS_NEXT_VXLAN; b0->error = error0 ? error_node->errors[error0] : 0; + /* vxlan-input node expect current at VXLAN header */ + if (is_ip4) + vlib_buffer_advance (b0, sizeof(ip4_header_t)+sizeof(udp_header_t)); + else + vlib_buffer_advance (b0, sizeof(ip6_header_t)+sizeof(udp_header_t)); + exit: vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, n_left_to_next, @@ -1017,114 +1201,39 @@ VLIB_REGISTER_NODE (ip4_vxlan_bypass_node) = { VLIB_NODE_FUNCTION_MULTIARCH (ip4_vxlan_bypass_node,ip4_vxlan_bypass) +/* Dummy init function to get us linked in. */ +clib_error_t * ip4_vxlan_bypass_init (vlib_main_t * vm) +{ return 0; } -static clib_error_t * -set_ip_vxlan_bypass (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - unformat_input_t _line_input, * line_input = &_line_input; - vnet_main_t * vnm = vnet_get_main(); - clib_error_t * error = 0; - u32 sw_if_index, is_del; - - sw_if_index = ~0; - is_del = 0; - - if (! unformat_user (input, unformat_line_input, line_input)) - return 0; +VLIB_INIT_FUNCTION (ip4_vxlan_bypass_init); - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat_user (line_input, unformat_vnet_sw_interface, vnm, &sw_if_index)) - ; - else if (unformat (line_input, "del")) - is_del = 1; - else - { - error = unformat_parse_error (line_input); - goto done; - } - } +static uword +ip6_vxlan_bypass (vlib_main_t * vm, + vlib_node_runtime_t * node, + vlib_frame_t * frame) +{ + return ip_vxlan_bypass_inline (vm, node, frame, /* is_ip4 */ 0); +} - if (~0 == sw_if_index) - { - error = clib_error_return (0, "unknown interface `%U'", - format_unformat_error, line_input); - goto done; - } +VLIB_REGISTER_NODE (ip6_vxlan_bypass_node) = { + .function = ip6_vxlan_bypass, + .name = "ip6-vxlan-bypass", + .vector_size = sizeof (u32), - vnet_feature_enable_disable ("ip4-unicast", "ip4-vxlan-bypass", sw_if_index, - is_del == 0, 0, 0); - done: - return error; -} + .n_next_nodes = IP_VXLAN_BYPASS_N_NEXT, + .next_nodes = { + [IP_VXLAN_BYPASS_NEXT_DROP] = "error-drop", + [IP_VXLAN_BYPASS_NEXT_VXLAN] = "vxlan6-input", + }, -/*? - * This command adds the 'ip4-vxlan-bypass' graph node for a given interface. - * By adding the IPv4 vxlan-bypass graph node to an interface, the node checks - * for and validate input vxlan packet and bypass ip4-lookup, ip4-local, - * ip4-udp-lookup nodes to speedup vxlan packet forwarding. This node will - * cause extra overhead to for non-vxlan packets which is kept at a minimum. - * - * @cliexpar - * @parblock - * Example of graph node before ip4-vxlan-bypass is enabled: - * @cliexstart{show vlib graph ip4-vxlan-bypass} - * Name Next Previous - * ip4-vxlan-bypass error-drop [0] - * vxlan4-input [1] - * ip4-lookup [2] - * @cliexend - * - * Example of how to enable ip4-vxlan-bypass on an interface: - * @cliexcmd{set interface ip vxlan-bypass GigabitEthernet2/0/0} - * - * Example of graph node after ip4-vxlan-bypass is enabled: - * @cliexstart{show vlib graph ip4-vxlan-bypass} - * Name Next Previous - * ip4-vxlan-bypass error-drop [0] ip4-input - * vxlan4-input [1] ip4-input-no-checksum - * ip4-lookup [2] - * @cliexend - * - * Example of how to display the feature enabed on an interface: - * @cliexstart{show ip interface features GigabitEthernet2/0/0} - * IP feature paths configured on GigabitEthernet2/0/0... - * - * ipv4 unicast: - * ip4-vxlan-bypass - * ip4-lookup - * - * ipv4 multicast: - * ip4-lookup-multicast - * - * ipv4 multicast: - * interface-output - * - * ipv6 unicast: - * ip6-lookup - * - * ipv6 multicast: - * ip6-lookup - * - * ipv6 multicast: - * interface-output - * @cliexend - * - * Example of how to disable unicast source checking on an interface: - * @cliexcmd{set interface ip vxlan-bypass GigabitEthernet2/0/0 del} - * @endparblock -?*/ -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (set_interface_ip_vxlan_bypass_command, static) = { - .path = "set interface ip vxlan-bypass", - .function = set_ip_vxlan_bypass, - .short_help = "set interface ip vxlan-bypass [del]", + .format_buffer = format_ip6_header, + .format_trace = format_ip6_forward_next_trace, }; +VLIB_NODE_FUNCTION_MULTIARCH (ip6_vxlan_bypass_node,ip6_vxlan_bypass) + /* Dummy init function to get us linked in. */ -clib_error_t * ip4_vxlan_bypass_init (vlib_main_t * vm) +clib_error_t * ip6_vxlan_bypass_init (vlib_main_t * vm) { return 0; } -VLIB_INIT_FUNCTION (ip4_vxlan_bypass_init); +VLIB_INIT_FUNCTION (ip6_vxlan_bypass_init); diff --git a/src/vnet/vxlan/vxlan.c b/src/vnet/vxlan/vxlan.c index 9ed42875..02465eb4 100644 --- a/src/vnet/vxlan/vxlan.c +++ b/src/vnet/vxlan/vxlan.c @@ -921,6 +921,177 @@ VLIB_CLI_COMMAND (show_vxlan_tunnel_command, static) = { /* *INDENT-ON* */ +void vnet_int_vxlan_bypass_mode (u32 sw_if_index, + u8 is_ip6, + u8 is_enable) +{ + if (is_ip6) + vnet_feature_enable_disable ("ip6-unicast", "ip6-vxlan-bypass", + sw_if_index, is_enable, 0, 0); + else + vnet_feature_enable_disable ("ip4-unicast", "ip4-vxlan-bypass", + sw_if_index, is_enable, 0, 0); +} + + +static clib_error_t * +set_ip_vxlan_bypass (u32 is_ip6, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + unformat_input_t _line_input, * line_input = &_line_input; + vnet_main_t * vnm = vnet_get_main(); + clib_error_t * error = 0; + u32 sw_if_index, is_enable; + + sw_if_index = ~0; + is_enable = 1; + + if (! unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat_user (line_input, unformat_vnet_sw_interface, vnm, &sw_if_index)) + ; + else if (unformat (line_input, "del")) + is_enable = 0; + else + { + error = unformat_parse_error (line_input); + goto done; + } + } + + if (~0 == sw_if_index) + { + error = clib_error_return (0, "unknown interface `%U'", + format_unformat_error, line_input); + goto done; + } + + vnet_int_vxlan_bypass_mode (sw_if_index, is_ip6, is_enable); + + done: + return error; +} + +static clib_error_t * +set_ip4_vxlan_bypass (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + return set_ip_vxlan_bypass (0, input, cmd); +} + +/*? + * This command adds the 'ip4-vxlan-bypass' graph node for a given interface. + * By adding the IPv4 vxlan-bypass graph node to an interface, the node checks + * for and validate input vxlan packet and bypass ip4-lookup, ip4-local, + * ip4-udp-lookup nodes to speedup vxlan packet forwarding. This node will + * cause extra overhead to for non-vxlan packets which is kept at a minimum. + * + * @cliexpar + * @parblock + * Example of graph node before ip4-vxlan-bypass is enabled: + * @cliexstart{show vlib graph ip4-vxlan-bypass} + * Name Next Previous + * ip4-vxlan-bypass error-drop [0] + * vxlan4-input [1] + * ip4-lookup [2] + * @cliexend + * + * Example of how to enable ip4-vxlan-bypass on an interface: + * @cliexcmd{set interface ip vxlan-bypass GigabitEthernet2/0/0} + * + * Example of graph node after ip4-vxlan-bypass is enabled: + * @cliexstart{show vlib graph ip4-vxlan-bypass} + * Name Next Previous + * ip4-vxlan-bypass error-drop [0] ip4-input + * vxlan4-input [1] ip4-input-no-checksum + * ip4-lookup [2] + * @cliexend + * + * Example of how to display the feature enabed on an interface: + * @cliexstart{show ip interface features GigabitEthernet2/0/0} + * IP feature paths configured on GigabitEthernet2/0/0... + * ... + * ipv4 unicast: + * ip4-vxlan-bypass + * ip4-lookup + * ... + * @cliexend + * + * Example of how to disable ip4-vxlan-bypass on an interface: + * @cliexcmd{set interface ip vxlan-bypass GigabitEthernet2/0/0 del} + * @endparblock +?*/ +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (set_interface_ip_vxlan_bypass_command, static) = { + .path = "set interface ip vxlan-bypass", + .function = set_ip4_vxlan_bypass, + .short_help = "set interface ip vxlan-bypass [del]", +}; +/* *INDENT-ON* */ + +static clib_error_t * +set_ip6_vxlan_bypass (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + return set_ip_vxlan_bypass (1, input, cmd); +} + +/*? + * This command adds the 'ip6-vxlan-bypass' graph node for a given interface. + * By adding the IPv6 vxlan-bypass graph node to an interface, the node checks + * for and validate input vxlan packet and bypass ip6-lookup, ip6-local, + * ip6-udp-lookup nodes to speedup vxlan packet forwarding. This node will + * cause extra overhead to for non-vxlan packets which is kept at a minimum. + * + * @cliexpar + * @parblock + * Example of graph node before ip6-vxlan-bypass is enabled: + * @cliexstart{show vlib graph ip6-vxlan-bypass} + * Name Next Previous + * ip6-vxlan-bypass error-drop [0] + * vxlan6-input [1] + * ip6-lookup [2] + * @cliexend + * + * Example of how to enable ip6-vxlan-bypass on an interface: + * @cliexcmd{set interface ip6 vxlan-bypass GigabitEthernet2/0/0} + * + * Example of graph node after ip6-vxlan-bypass is enabled: + * @cliexstart{show vlib graph ip6-vxlan-bypass} + * Name Next Previous + * ip6-vxlan-bypass error-drop [0] ip6-input + * vxlan6-input [1] ip4-input-no-checksum + * ip6-lookup [2] + * @cliexend + * + * Example of how to display the feature enabed on an interface: + * @cliexstart{show ip interface features GigabitEthernet2/0/0} + * IP feature paths configured on GigabitEthernet2/0/0... + * ... + * ipv6 unicast: + * ip6-vxlan-bypass + * ip6-lookup + * ... + * @cliexend + * + * Example of how to disable ip6-vxlan-bypass on an interface: + * @cliexcmd{set interface ip6 vxlan-bypass GigabitEthernet2/0/0 del} + * @endparblock +?*/ +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (set_interface_ip6_vxlan_bypass_command, static) = { + .path = "set interface ip6 vxlan-bypass", + .function = set_ip6_vxlan_bypass, + .short_help = "set interface ip vxlan-bypass [del]", +}; +/* *INDENT-ON* */ + clib_error_t *vxlan_init (vlib_main_t *vm) { vxlan_main_t * vxm = &vxlan_main; diff --git a/src/vnet/vxlan/vxlan.h b/src/vnet/vxlan/vxlan.h index ab9b2333..adfa3a8e 100644 --- a/src/vnet/vxlan/vxlan.h +++ b/src/vnet/vxlan/vxlan.h @@ -183,4 +183,6 @@ typedef struct { int vnet_vxlan_add_del_tunnel (vnet_vxlan_add_del_tunnel_args_t *a, u32 * sw_if_indexp); +void vnet_int_vxlan_bypass_mode +(u32 sw_if_index, u8 is_ip6, u8 is_enable); #endif /* included_vnet_vxlan_h */ diff --git a/src/vnet/vxlan/vxlan_api.c b/src/vnet/vxlan/vxlan_api.c index 6c9cbd79..c726c7c5 100644 --- a/src/vnet/vxlan/vxlan_api.c +++ b/src/vnet/vxlan/vxlan_api.c @@ -59,14 +59,7 @@ static void VALIDATE_SW_IF_INDEX (mp); - if (mp->is_ipv6) - { - /* not yet implemented */ - } - else - vnet_feature_enable_disable ("ip4-unicast", "ip4-vxlan-bypass", - sw_if_index, mp->enable, 0, 0); - + vnet_int_vxlan_bypass_mode (sw_if_index, mp->is_ipv6, mp->enable); BAD_SW_IF_INDEX_LABEL; REPLY_MACRO (VL_API_SW_INTERFACE_SET_VXLAN_BYPASS_REPLY); -- cgit 1.2.3-korg From e101e1f52f1da71575588fac30b984a0e94fb5a7 Mon Sep 17 00:00:00 2001 From: Eyal Bari Date: Wed, 15 Mar 2017 08:23:42 +0200 Subject: VXLAN:add hidden multicast interface check and some refactoring Change-Id: I99e3c5e782ce65cb9779ccc3a9a3151ef1429e07 Signed-off-by: Eyal Bari --- src/vat/api_format.c | 6 ++---- src/vnet/ip/ip6_packet.h | 14 ++++++++------ src/vnet/vxlan/vxlan_api.c | 40 +++++++++++++++++----------------------- src/vpp/api/custom_dump.c | 6 ++---- 4 files changed, 29 insertions(+), 37 deletions(-) (limited to 'src/vnet/vxlan/vxlan_api.c') diff --git a/src/vat/api_format.c b/src/vat/api_format.c index e6e4acd9..391fe9cf 100644 --- a/src/vat/api_format.c +++ b/src/vat/api_format.c @@ -10671,10 +10671,8 @@ static void vl_api_vxlan_tunnel_details_t_handler (vl_api_vxlan_tunnel_details_t * mp) { vat_main_t *vam = &vat_main; - ip46_address_t src, dst; - - ip46_from_addr_buf (mp->is_ipv6, mp->src_address, &src); - ip46_from_addr_buf (mp->is_ipv6, mp->dst_address, &dst); + ip46_address_t src = to_ip46 (mp->is_ipv6, mp->dst_address); + ip46_address_t dst = to_ip46 (mp->is_ipv6, mp->src_address); print (vam->ofp, "%11d%24U%24U%14d%18d%13d%19d", ntohl (mp->sw_if_index), diff --git a/src/vnet/ip/ip6_packet.h b/src/vnet/ip/ip6_packet.h index bb7d7039..cdd7eed5 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 c726c7c5..a2d41232 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* */ diff --git a/src/vpp/api/custom_dump.c b/src/vpp/api/custom_dump.c index 648ac5f3..a76840a2 100644 --- a/src/vpp/api/custom_dump.c +++ b/src/vpp/api/custom_dump.c @@ -1384,10 +1384,8 @@ static void *vl_api_vxlan_add_del_tunnel_t_print u8 *s; s = format (0, "SCRIPT: vxlan_add_del_tunnel "); - ip46_address_t src, dst; - - ip46_from_addr_buf (mp->is_ipv6, mp->dst_address, &dst); - ip46_from_addr_buf (mp->is_ipv6, mp->src_address, &src); + ip46_address_t src = to_ip46 (mp->is_ipv6, mp->dst_address); + ip46_address_t dst = to_ip46 (mp->is_ipv6, mp->src_address); u8 is_grp = ip46_address_is_multicast (&dst); char *dst_name = is_grp ? "group" : "dst"; -- cgit 1.2.3-korg