Eyal Bari | 3ce0b08 | 2018-01-17 12:06:32 +0200 | [diff] [blame] | 1 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Cisco and/or its affiliates. |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at: |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #include <vppinfra/error.h> |
| 17 | #include <vppinfra/hash.h> |
| 18 | #include <vnet/vnet.h> |
| 19 | #include <vnet/ip/ip.h> |
| 20 | #include <vnet/ethernet/ethernet.h> |
Mohsin Kazmi | dbd5fb3 | 2020-06-02 15:21:03 +0200 | [diff] [blame] | 21 | #include <vnet/interface_output.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 22 | #include <vnet/vxlan/vxlan.h> |
Igor Mikhailov (imichail) | 6636440 | 2018-04-24 21:53:00 -0700 | [diff] [blame] | 23 | #include <vnet/qos/qos_types.h> |
eyal bari | 82e21d7 | 2018-04-26 13:14:55 +0300 | [diff] [blame] | 24 | #include <vnet/adj/rewrite.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 25 | |
| 26 | /* Statistics (not all errors) */ |
| 27 | #define foreach_vxlan_encap_error \ |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 28 | _(ENCAPSULATED, "good packets encapsulated") |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 29 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 30 | static char *vxlan_encap_error_strings[] = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 31 | #define _(sym,string) string, |
| 32 | foreach_vxlan_encap_error |
| 33 | #undef _ |
| 34 | }; |
| 35 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 36 | typedef enum |
| 37 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 38 | #define _(sym,str) VXLAN_ENCAP_ERROR_##sym, |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 39 | foreach_vxlan_encap_error |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 40 | #undef _ |
| 41 | VXLAN_ENCAP_N_ERROR, |
| 42 | } vxlan_encap_error_t; |
| 43 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 44 | typedef enum |
| 45 | { |
| 46 | VXLAN_ENCAP_NEXT_DROP, |
| 47 | VXLAN_ENCAP_N_NEXT, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 48 | } vxlan_encap_next_t; |
| 49 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 50 | typedef struct |
| 51 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 52 | u32 tunnel_index; |
| 53 | u32 vni; |
| 54 | } vxlan_encap_trace_t; |
| 55 | |
Filip Tehlar | e1714d3 | 2019-03-05 03:01:43 -0800 | [diff] [blame] | 56 | #ifndef CLIB_MARCH_VARIANT |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 57 | u8 * |
| 58 | format_vxlan_encap_trace (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 59 | { |
| 60 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 61 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 62 | vxlan_encap_trace_t *t = va_arg (*args, vxlan_encap_trace_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 63 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 64 | s = format (s, "VXLAN encap to vxlan_tunnel%d vni %d", |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 65 | t->tunnel_index, t->vni); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 66 | return s; |
| 67 | } |
Filip Tehlar | e1714d3 | 2019-03-05 03:01:43 -0800 | [diff] [blame] | 68 | #endif |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 69 | |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 70 | always_inline uword |
| 71 | vxlan_encap_inline (vlib_main_t * vm, |
| 72 | vlib_node_runtime_t * node, |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 73 | vlib_frame_t * from_frame, u8 is_ip4, u8 csum_offload) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 74 | { |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 75 | u32 n_left_from, next_index, *from, *to_next; |
| 76 | vxlan_main_t *vxm = &vxlan_main; |
| 77 | vnet_main_t *vnm = vxm->vnet_main; |
| 78 | vnet_interface_main_t *im = &vnm->interface_main; |
| 79 | vlib_combined_counter_main_t *tx_counter = |
| 80 | im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_TX; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 81 | u32 pkts_encapsulated = 0; |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 82 | u32 thread_index = vlib_get_thread_index (); |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 83 | u32 sw_if_index0 = 0, sw_if_index1 = 0; |
| 84 | u32 next0 = 0, next1 = 0; |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 85 | vxlan_tunnel_t *t0 = NULL, *t1 = NULL; |
John Lo | 25d417f | 2018-02-15 15:47:53 -0500 | [diff] [blame] | 86 | index_t dpoi_idx0 = INDEX_INVALID, dpoi_idx1 = INDEX_INVALID; |
Zhiyong Yang | 102dd1c | 2020-03-27 13:04:38 +0000 | [diff] [blame] | 87 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE]; |
| 88 | vlib_buffer_t **b = bufs; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 89 | |
| 90 | from = vlib_frame_vector_args (from_frame); |
| 91 | n_left_from = from_frame->n_vectors; |
| 92 | |
| 93 | next_index = node->cached_next_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 94 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 95 | STATIC_ASSERT_SIZEOF (ip6_vxlan_header_t, 56); |
| 96 | STATIC_ASSERT_SIZEOF (ip4_vxlan_header_t, 36); |
Eyal Bari | 3ce0b08 | 2018-01-17 12:06:32 +0200 | [diff] [blame] | 97 | |
eyal bari | 82e21d7 | 2018-04-26 13:14:55 +0300 | [diff] [blame] | 98 | u8 const underlay_hdr_len = is_ip4 ? |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 99 | sizeof (ip4_vxlan_header_t) : sizeof (ip6_vxlan_header_t); |
| 100 | u16 const l3_len = is_ip4 ? sizeof (ip4_header_t) : sizeof (ip6_header_t); |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame^] | 101 | u32 const csum_flags = |
| 102 | is_ip4 ? VNET_BUFFER_F_IS_IP4 | VNET_BUFFER_F_L3_HDR_OFFSET_VALID | |
| 103 | VNET_BUFFER_F_L4_HDR_OFFSET_VALID : |
| 104 | VNET_BUFFER_F_IS_IP6 | VNET_BUFFER_F_L3_HDR_OFFSET_VALID | |
| 105 | VNET_BUFFER_F_L4_HDR_OFFSET_VALID; |
| 106 | u32 const outer_packet_csum_offload_flags = |
| 107 | is_ip4 ? VNET_BUFFER_OFFLOAD_F_IP_CKSUM | VNET_BUFFER_OFFLOAD_F_UDP_CKSUM : |
| 108 | VNET_BUFFER_OFFLOAD_F_UDP_CKSUM; |
Mohsin Kazmi | dbd5fb3 | 2020-06-02 15:21:03 +0200 | [diff] [blame] | 109 | u32 const inner_packet_removed_flags = |
| 110 | VNET_BUFFER_F_IS_IP4 | VNET_BUFFER_F_IS_IP6 | |
| 111 | VNET_BUFFER_F_L2_HDR_OFFSET_VALID | VNET_BUFFER_F_L3_HDR_OFFSET_VALID | |
| 112 | VNET_BUFFER_F_L4_HDR_OFFSET_VALID; |
| 113 | |
Zhiyong Yang | 102dd1c | 2020-03-27 13:04:38 +0000 | [diff] [blame] | 114 | vlib_get_buffers (vm, from, bufs, n_left_from); |
Eyal Bari | 3ce0b08 | 2018-01-17 12:06:32 +0200 | [diff] [blame] | 115 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 116 | while (n_left_from > 0) |
| 117 | { |
| 118 | u32 n_left_to_next; |
| 119 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 120 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 121 | |
| 122 | while (n_left_from >= 4 && n_left_to_next >= 2) |
| 123 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 124 | /* Prefetch next iteration. */ |
| 125 | { |
Zhiyong Yang | 102dd1c | 2020-03-27 13:04:38 +0000 | [diff] [blame] | 126 | vlib_prefetch_buffer_header (b[2], LOAD); |
| 127 | vlib_prefetch_buffer_header (b[3], LOAD); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 128 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 129 | CLIB_PREFETCH (b[2]->data - CLIB_CACHE_LINE_BYTES, |
| 130 | 2 * CLIB_CACHE_LINE_BYTES, LOAD); |
| 131 | CLIB_PREFETCH (b[3]->data - CLIB_CACHE_LINE_BYTES, |
| 132 | 2 * CLIB_CACHE_LINE_BYTES, LOAD); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 133 | } |
| 134 | |
eyal bari | 82e21d7 | 2018-04-26 13:14:55 +0300 | [diff] [blame] | 135 | u32 bi0 = to_next[0] = from[0]; |
| 136 | u32 bi1 = to_next[1] = from[1]; |
| 137 | from += 2; |
| 138 | to_next += 2; |
| 139 | n_left_to_next -= 2; |
| 140 | n_left_from -= 2; |
Eyal Bari | 3ce0b08 | 2018-01-17 12:06:32 +0200 | [diff] [blame] | 141 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 142 | vlib_buffer_t *b0 = b[0]; |
| 143 | vlib_buffer_t *b1 = b[1]; |
Zhiyong Yang | 102dd1c | 2020-03-27 13:04:38 +0000 | [diff] [blame] | 144 | b += 2; |
| 145 | |
Mohsin Kazmi | dbd5fb3 | 2020-06-02 15:21:03 +0200 | [diff] [blame] | 146 | u32 or_flags = b0->flags | b1->flags; |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame^] | 147 | if (csum_offload && (or_flags & VNET_BUFFER_F_OFFLOAD)) |
Mohsin Kazmi | dbd5fb3 | 2020-06-02 15:21:03 +0200 | [diff] [blame] | 148 | { |
| 149 | /* Only calculate the non-GSO packet csum offload */ |
| 150 | if ((b0->flags & VNET_BUFFER_F_GSO) == 0) |
| 151 | { |
| 152 | vnet_calc_checksums_inline (vm, b0, |
| 153 | b0->flags & |
| 154 | VNET_BUFFER_F_IS_IP4, |
| 155 | b0->flags & |
| 156 | VNET_BUFFER_F_IS_IP6); |
| 157 | b0->flags &= ~inner_packet_removed_flags; |
| 158 | } |
| 159 | if ((b1->flags & VNET_BUFFER_F_GSO) == 0) |
| 160 | { |
| 161 | vnet_calc_checksums_inline (vm, b1, |
| 162 | b1->flags & |
| 163 | VNET_BUFFER_F_IS_IP4, |
| 164 | b1->flags & |
| 165 | VNET_BUFFER_F_IS_IP6); |
| 166 | b1->flags &= ~inner_packet_removed_flags; |
| 167 | } |
| 168 | } |
| 169 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 170 | u32 flow_hash0 = vnet_l2_compute_flow_hash (b0); |
| 171 | u32 flow_hash1 = vnet_l2_compute_flow_hash (b1); |
Eyal Bari | 3ce0b08 | 2018-01-17 12:06:32 +0200 | [diff] [blame] | 172 | |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 173 | /* Get next node index and adj index from tunnel next_dpo */ |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 174 | if (sw_if_index0 != vnet_buffer (b0)->sw_if_index[VLIB_TX]) |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 175 | { |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 176 | sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX]; |
| 177 | vnet_hw_interface_t *hi0 = |
| 178 | vnet_get_sup_hw_interface (vnm, sw_if_index0); |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 179 | t0 = &vxm->tunnels[hi0->dev_instance]; |
John Lo | 25d417f | 2018-02-15 15:47:53 -0500 | [diff] [blame] | 180 | /* Note: change to always set next0 if it may set to drop */ |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 181 | next0 = t0->next_dpo.dpoi_next_node; |
John Lo | 25d417f | 2018-02-15 15:47:53 -0500 | [diff] [blame] | 182 | dpoi_idx0 = t0->next_dpo.dpoi_index; |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 183 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 184 | |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 185 | /* Get next node index and adj index from tunnel next_dpo */ |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 186 | if (sw_if_index1 != vnet_buffer (b1)->sw_if_index[VLIB_TX]) |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 187 | { |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 188 | if (sw_if_index0 == vnet_buffer (b1)->sw_if_index[VLIB_TX]) |
| 189 | { |
John Lo | 25d417f | 2018-02-15 15:47:53 -0500 | [diff] [blame] | 190 | sw_if_index1 = sw_if_index0; |
| 191 | t1 = t0; |
| 192 | next1 = next0; |
| 193 | dpoi_idx1 = dpoi_idx0; |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 194 | } |
John Lo | 25d417f | 2018-02-15 15:47:53 -0500 | [diff] [blame] | 195 | else |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 196 | { |
| 197 | sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_TX]; |
| 198 | vnet_hw_interface_t *hi1 = |
| 199 | vnet_get_sup_hw_interface (vnm, sw_if_index1); |
John Lo | 25d417f | 2018-02-15 15:47:53 -0500 | [diff] [blame] | 200 | t1 = &vxm->tunnels[hi1->dev_instance]; |
| 201 | /* Note: change to always set next1 if it may set to drop */ |
| 202 | next1 = t1->next_dpo.dpoi_next_node; |
| 203 | dpoi_idx1 = t1->next_dpo.dpoi_index; |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 204 | } |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 205 | } |
John Lo | 25d417f | 2018-02-15 15:47:53 -0500 | [diff] [blame] | 206 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 207 | vnet_buffer (b0)->ip.adj_index[VLIB_TX] = dpoi_idx0; |
| 208 | vnet_buffer (b1)->ip.adj_index[VLIB_TX] = dpoi_idx1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 209 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 210 | ASSERT (t0->rewrite_header.data_bytes == underlay_hdr_len); |
| 211 | ASSERT (t1->rewrite_header.data_bytes == underlay_hdr_len); |
| 212 | vnet_rewrite_two_headers (*t0, *t1, vlib_buffer_get_current (b0), |
| 213 | vlib_buffer_get_current (b1), |
| 214 | underlay_hdr_len); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 215 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 216 | vlib_buffer_advance (b0, -underlay_hdr_len); |
| 217 | vlib_buffer_advance (b1, -underlay_hdr_len); |
Eyal Bari | 3ce0b08 | 2018-01-17 12:06:32 +0200 | [diff] [blame] | 218 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 219 | u32 len0 = vlib_buffer_length_in_chain (vm, b0); |
| 220 | u32 len1 = vlib_buffer_length_in_chain (vm, b1); |
| 221 | u16 payload_l0 = clib_host_to_net_u16 (len0 - l3_len); |
| 222 | u16 payload_l1 = clib_host_to_net_u16 (len1 - l3_len); |
Eyal Bari | 3ce0b08 | 2018-01-17 12:06:32 +0200 | [diff] [blame] | 223 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 224 | void *underlay0 = vlib_buffer_get_current (b0); |
| 225 | void *underlay1 = vlib_buffer_get_current (b1); |
eyal bari | 82e21d7 | 2018-04-26 13:14:55 +0300 | [diff] [blame] | 226 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 227 | ip4_header_t *ip4_0, *ip4_1; |
Igor Mikhailov (imichail) | 6636440 | 2018-04-24 21:53:00 -0700 | [diff] [blame] | 228 | qos_bits_t ip4_0_tos = 0, ip4_1_tos = 0; |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 229 | ip6_header_t *ip6_0, *ip6_1; |
| 230 | udp_header_t *udp0, *udp1; |
| 231 | u8 *l3_0, *l3_1; |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 232 | if (is_ip4) |
| 233 | { |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 234 | ip4_vxlan_header_t *hdr0 = underlay0; |
| 235 | ip4_vxlan_header_t *hdr1 = underlay1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 236 | |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 237 | /* Fix the IP4 checksum and length */ |
Eyal Bari | 3ce0b08 | 2018-01-17 12:06:32 +0200 | [diff] [blame] | 238 | ip4_0 = &hdr0->ip4; |
| 239 | ip4_1 = &hdr1->ip4; |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 240 | ip4_0->length = clib_host_to_net_u16 (len0); |
| 241 | ip4_1->length = clib_host_to_net_u16 (len1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 242 | |
Igor Mikhailov (imichail) | 6636440 | 2018-04-24 21:53:00 -0700 | [diff] [blame] | 243 | if (PREDICT_FALSE (b0->flags & VNET_BUFFER_F_QOS_DATA_VALID)) |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 244 | { |
Igor Mikhailov (imichail) | 6636440 | 2018-04-24 21:53:00 -0700 | [diff] [blame] | 245 | ip4_0_tos = vnet_buffer2 (b0)->qos.bits; |
| 246 | ip4_0->tos = ip4_0_tos; |
| 247 | } |
| 248 | if (PREDICT_FALSE (b1->flags & VNET_BUFFER_F_QOS_DATA_VALID)) |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 249 | { |
Igor Mikhailov (imichail) | 6636440 | 2018-04-24 21:53:00 -0700 | [diff] [blame] | 250 | ip4_1_tos = vnet_buffer2 (b1)->qos.bits; |
| 251 | ip4_1->tos = ip4_1_tos; |
| 252 | } |
| 253 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 254 | l3_0 = (u8 *) ip4_0; |
| 255 | l3_1 = (u8 *) ip4_1; |
Eyal Bari | 3ce0b08 | 2018-01-17 12:06:32 +0200 | [diff] [blame] | 256 | udp0 = &hdr0->udp; |
| 257 | udp1 = &hdr1->udp; |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 258 | } |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 259 | else /* ipv6 */ |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 260 | { |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 261 | ip6_vxlan_header_t *hdr0 = underlay0; |
| 262 | ip6_vxlan_header_t *hdr1 = underlay1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 263 | |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 264 | /* Fix IP6 payload length */ |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 265 | ip6_0 = &hdr0->ip6; |
| 266 | ip6_1 = &hdr1->ip6; |
Eyal Bari | 3ce0b08 | 2018-01-17 12:06:32 +0200 | [diff] [blame] | 267 | ip6_0->payload_length = payload_l0; |
| 268 | ip6_1->payload_length = payload_l1; |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 269 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 270 | l3_0 = (u8 *) ip6_0; |
| 271 | l3_1 = (u8 *) ip6_1; |
| 272 | udp0 = &hdr0->udp; |
| 273 | udp1 = &hdr1->udp; |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 274 | } |
Chris Luke | 99cb335 | 2016-04-26 10:49:53 -0400 | [diff] [blame] | 275 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 276 | /* Fix UDP length and set source port */ |
| 277 | udp0->length = payload_l0; |
| 278 | udp0->src_port = flow_hash0; |
| 279 | udp1->length = payload_l1; |
| 280 | udp1->src_port = flow_hash1; |
Eyal Bari | 3ce0b08 | 2018-01-17 12:06:32 +0200 | [diff] [blame] | 281 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 282 | if (csum_offload) |
| 283 | { |
| 284 | b0->flags |= csum_flags; |
| 285 | vnet_buffer (b0)->l3_hdr_offset = l3_0 - b0->data; |
| 286 | vnet_buffer (b0)->l4_hdr_offset = (u8 *) udp0 - b0->data; |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame^] | 287 | vnet_buffer_offload_flags_set (b0, |
| 288 | outer_packet_csum_offload_flags); |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 289 | b1->flags |= csum_flags; |
| 290 | vnet_buffer (b1)->l3_hdr_offset = l3_1 - b1->data; |
| 291 | vnet_buffer (b1)->l4_hdr_offset = (u8 *) udp1 - b1->data; |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame^] | 292 | vnet_buffer_offload_flags_set (b1, |
| 293 | outer_packet_csum_offload_flags); |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 294 | } |
| 295 | /* IPv4 UDP checksum only if checksum offload is used */ |
| 296 | else if (is_ip4) |
| 297 | { |
| 298 | ip_csum_t sum0 = ip4_0->checksum; |
| 299 | sum0 = ip_csum_update (sum0, 0, ip4_0->length, ip4_header_t, |
| 300 | length /* changed member */ ); |
Igor Mikhailov (imichail) | 6636440 | 2018-04-24 21:53:00 -0700 | [diff] [blame] | 301 | if (PREDICT_FALSE (ip4_0_tos)) |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 302 | { |
Igor Mikhailov (imichail) | 6636440 | 2018-04-24 21:53:00 -0700 | [diff] [blame] | 303 | sum0 = ip_csum_update (sum0, 0, ip4_0_tos, ip4_header_t, |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 304 | tos /* changed member */ ); |
Igor Mikhailov (imichail) | 6636440 | 2018-04-24 21:53:00 -0700 | [diff] [blame] | 305 | } |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 306 | ip4_0->checksum = ip_csum_fold (sum0); |
| 307 | ip_csum_t sum1 = ip4_1->checksum; |
| 308 | sum1 = ip_csum_update (sum1, 0, ip4_1->length, ip4_header_t, |
| 309 | length /* changed member */ ); |
Igor Mikhailov (imichail) | 6636440 | 2018-04-24 21:53:00 -0700 | [diff] [blame] | 310 | if (PREDICT_FALSE (ip4_1_tos)) |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 311 | { |
Igor Mikhailov (imichail) | 6636440 | 2018-04-24 21:53:00 -0700 | [diff] [blame] | 312 | sum1 = ip_csum_update (sum1, 0, ip4_1_tos, ip4_header_t, |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 313 | tos /* changed member */ ); |
Igor Mikhailov (imichail) | 6636440 | 2018-04-24 21:53:00 -0700 | [diff] [blame] | 314 | } |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 315 | ip4_1->checksum = ip_csum_fold (sum1); |
| 316 | } |
| 317 | /* IPv6 UDP checksum is mandatory */ |
| 318 | else |
| 319 | { |
| 320 | int bogus = 0; |
Eyal Bari | 3ce0b08 | 2018-01-17 12:06:32 +0200 | [diff] [blame] | 321 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 322 | udp0->checksum = ip6_tcp_udp_icmp_compute_checksum |
| 323 | (vm, b0, ip6_0, &bogus); |
| 324 | ASSERT (bogus == 0); |
| 325 | if (udp0->checksum == 0) |
| 326 | udp0->checksum = 0xffff; |
| 327 | udp1->checksum = ip6_tcp_udp_icmp_compute_checksum |
| 328 | (vm, b1, ip6_1, &bogus); |
| 329 | ASSERT (bogus == 0); |
| 330 | if (udp1->checksum == 0) |
| 331 | udp1->checksum = 0xffff; |
| 332 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 333 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 334 | /* save inner packet flow_hash for load-balance node */ |
| 335 | vnet_buffer (b0)->ip.flow_hash = flow_hash0; |
| 336 | vnet_buffer (b1)->ip.flow_hash = flow_hash1; |
Shawn Ji | 623b4f8 | 2019-12-18 10:10:54 +0800 | [diff] [blame] | 337 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 338 | if (sw_if_index0 == sw_if_index1) |
| 339 | { |
| 340 | vlib_increment_combined_counter (tx_counter, thread_index, |
| 341 | sw_if_index0, 2, len0 + len1); |
| 342 | } |
| 343 | else |
| 344 | { |
| 345 | vlib_increment_combined_counter (tx_counter, thread_index, |
| 346 | sw_if_index0, 1, len0); |
| 347 | vlib_increment_combined_counter (tx_counter, thread_index, |
| 348 | sw_if_index1, 1, len1); |
| 349 | } |
| 350 | pkts_encapsulated += 2; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 351 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 352 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 353 | { |
| 354 | vxlan_encap_trace_t *tr = |
| 355 | vlib_add_trace (vm, node, b0, sizeof (*tr)); |
| 356 | tr->tunnel_index = t0 - vxm->tunnels; |
| 357 | tr->vni = t0->vni; |
| 358 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 359 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 360 | if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED)) |
| 361 | { |
| 362 | vxlan_encap_trace_t *tr = |
| 363 | vlib_add_trace (vm, node, b1, sizeof (*tr)); |
| 364 | tr->tunnel_index = t1 - vxm->tunnels; |
| 365 | tr->vni = t1->vni; |
| 366 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 367 | |
| 368 | vlib_validate_buffer_enqueue_x2 (vm, node, next_index, |
| 369 | to_next, n_left_to_next, |
| 370 | bi0, bi1, next0, next1); |
| 371 | } |
| 372 | |
| 373 | while (n_left_from > 0 && n_left_to_next > 0) |
| 374 | { |
eyal bari | 82e21d7 | 2018-04-26 13:14:55 +0300 | [diff] [blame] | 375 | u32 bi0 = to_next[0] = from[0]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 376 | from += 1; |
| 377 | to_next += 1; |
| 378 | n_left_from -= 1; |
| 379 | n_left_to_next -= 1; |
| 380 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 381 | vlib_buffer_t *b0 = b[0]; |
Zhiyong Yang | 102dd1c | 2020-03-27 13:04:38 +0000 | [diff] [blame] | 382 | b += 1; |
| 383 | |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame^] | 384 | if (csum_offload && (b0->flags & VNET_BUFFER_F_OFFLOAD)) |
Mohsin Kazmi | dbd5fb3 | 2020-06-02 15:21:03 +0200 | [diff] [blame] | 385 | { |
| 386 | /* Only calculate the non-GSO packet csum offload */ |
| 387 | if ((b0->flags & VNET_BUFFER_F_GSO) == 0) |
| 388 | { |
| 389 | vnet_calc_checksums_inline (vm, b0, |
| 390 | b0->flags & |
| 391 | VNET_BUFFER_F_IS_IP4, |
| 392 | b0->flags & |
| 393 | VNET_BUFFER_F_IS_IP6); |
| 394 | b0->flags &= ~inner_packet_removed_flags; |
| 395 | } |
| 396 | } |
| 397 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 398 | u32 flow_hash0 = vnet_l2_compute_flow_hash (b0); |
eyal bari | 82e21d7 | 2018-04-26 13:14:55 +0300 | [diff] [blame] | 399 | |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 400 | /* Get next node index and adj index from tunnel next_dpo */ |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 401 | if (sw_if_index0 != vnet_buffer (b0)->sw_if_index[VLIB_TX]) |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 402 | { |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 403 | sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX]; |
| 404 | vnet_hw_interface_t *hi0 = |
| 405 | vnet_get_sup_hw_interface (vnm, sw_if_index0); |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 406 | t0 = &vxm->tunnels[hi0->dev_instance]; |
| 407 | /* Note: change to always set next0 if it may be set to drop */ |
| 408 | next0 = t0->next_dpo.dpoi_next_node; |
John Lo | 25d417f | 2018-02-15 15:47:53 -0500 | [diff] [blame] | 409 | dpoi_idx0 = t0->next_dpo.dpoi_index; |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 410 | } |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 411 | vnet_buffer (b0)->ip.adj_index[VLIB_TX] = dpoi_idx0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 412 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 413 | ASSERT (t0->rewrite_header.data_bytes == underlay_hdr_len); |
| 414 | vnet_rewrite_one_header (*t0, vlib_buffer_get_current (b0), |
| 415 | underlay_hdr_len); |
eyal bari | 82e21d7 | 2018-04-26 13:14:55 +0300 | [diff] [blame] | 416 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 417 | vlib_buffer_advance (b0, -underlay_hdr_len); |
| 418 | void *underlay0 = vlib_buffer_get_current (b0); |
eyal bari | 82e21d7 | 2018-04-26 13:14:55 +0300 | [diff] [blame] | 419 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 420 | u32 len0 = vlib_buffer_length_in_chain (vm, b0); |
| 421 | u16 payload_l0 = clib_host_to_net_u16 (len0 - l3_len); |
Eyal Bari | 3ce0b08 | 2018-01-17 12:06:32 +0200 | [diff] [blame] | 422 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 423 | udp_header_t *udp0; |
| 424 | ip4_header_t *ip4_0; |
Igor Mikhailov (imichail) | 6636440 | 2018-04-24 21:53:00 -0700 | [diff] [blame] | 425 | qos_bits_t ip4_0_tos = 0; |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 426 | ip6_header_t *ip6_0; |
| 427 | u8 *l3_0; |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 428 | if (is_ip4) |
| 429 | { |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 430 | ip4_vxlan_header_t *hdr = underlay0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 431 | |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 432 | /* Fix the IP4 checksum and length */ |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 433 | ip4_0 = &hdr->ip4; |
| 434 | ip4_0->length = clib_host_to_net_u16 (len0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 435 | |
Igor Mikhailov (imichail) | 6636440 | 2018-04-24 21:53:00 -0700 | [diff] [blame] | 436 | if (PREDICT_FALSE (b0->flags & VNET_BUFFER_F_QOS_DATA_VALID)) |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 437 | { |
Igor Mikhailov (imichail) | 6636440 | 2018-04-24 21:53:00 -0700 | [diff] [blame] | 438 | ip4_0_tos = vnet_buffer2 (b0)->qos.bits; |
| 439 | ip4_0->tos = ip4_0_tos; |
| 440 | } |
| 441 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 442 | l3_0 = (u8 *) ip4_0; |
Eyal Bari | 3ce0b08 | 2018-01-17 12:06:32 +0200 | [diff] [blame] | 443 | udp0 = &hdr->udp; |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 444 | } |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 445 | else /* ip6 path */ |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 446 | { |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 447 | ip6_vxlan_header_t *hdr = underlay0; |
Chris Luke | 99cb335 | 2016-04-26 10:49:53 -0400 | [diff] [blame] | 448 | |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 449 | /* Fix IP6 payload length */ |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 450 | ip6_0 = &hdr->ip6; |
Eyal Bari | 3ce0b08 | 2018-01-17 12:06:32 +0200 | [diff] [blame] | 451 | ip6_0->payload_length = payload_l0; |
Chris Luke | 99cb335 | 2016-04-26 10:49:53 -0400 | [diff] [blame] | 452 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 453 | l3_0 = (u8 *) ip6_0; |
| 454 | udp0 = &hdr->udp; |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 455 | } |
| 456 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 457 | /* Fix UDP length and set source port */ |
| 458 | udp0->length = payload_l0; |
| 459 | udp0->src_port = flow_hash0; |
Eyal Bari | 3ce0b08 | 2018-01-17 12:06:32 +0200 | [diff] [blame] | 460 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 461 | if (csum_offload) |
| 462 | { |
| 463 | b0->flags |= csum_flags; |
| 464 | vnet_buffer (b0)->l3_hdr_offset = l3_0 - b0->data; |
| 465 | vnet_buffer (b0)->l4_hdr_offset = (u8 *) udp0 - b0->data; |
Mohsin Kazmi | 6809538 | 2021-02-10 11:26:24 +0100 | [diff] [blame^] | 466 | vnet_buffer_offload_flags_set (b0, |
| 467 | outer_packet_csum_offload_flags); |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 468 | } |
| 469 | /* IPv4 UDP checksum only if checksum offload is used */ |
| 470 | else if (is_ip4) |
| 471 | { |
| 472 | ip_csum_t sum0 = ip4_0->checksum; |
| 473 | sum0 = ip_csum_update (sum0, 0, ip4_0->length, ip4_header_t, |
| 474 | length /* changed member */ ); |
Igor Mikhailov (imichail) | 6636440 | 2018-04-24 21:53:00 -0700 | [diff] [blame] | 475 | if (PREDICT_FALSE (ip4_0_tos)) |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 476 | { |
Igor Mikhailov (imichail) | 6636440 | 2018-04-24 21:53:00 -0700 | [diff] [blame] | 477 | sum0 = ip_csum_update (sum0, 0, ip4_0_tos, ip4_header_t, |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 478 | tos /* changed member */ ); |
Igor Mikhailov (imichail) | 6636440 | 2018-04-24 21:53:00 -0700 | [diff] [blame] | 479 | } |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 480 | ip4_0->checksum = ip_csum_fold (sum0); |
| 481 | } |
| 482 | /* IPv6 UDP checksum is mandatory */ |
| 483 | else |
| 484 | { |
| 485 | int bogus = 0; |
Eyal Bari | 3ce0b08 | 2018-01-17 12:06:32 +0200 | [diff] [blame] | 486 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 487 | udp0->checksum = ip6_tcp_udp_icmp_compute_checksum |
| 488 | (vm, b0, ip6_0, &bogus); |
| 489 | ASSERT (bogus == 0); |
| 490 | if (udp0->checksum == 0) |
| 491 | udp0->checksum = 0xffff; |
| 492 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 493 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 494 | /* reuse inner packet flow_hash for load-balance node */ |
| 495 | vnet_buffer (b0)->ip.flow_hash = flow_hash0; |
Shawn Ji | 623b4f8 | 2019-12-18 10:10:54 +0800 | [diff] [blame] | 496 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 497 | vlib_increment_combined_counter (tx_counter, thread_index, |
| 498 | sw_if_index0, 1, len0); |
| 499 | pkts_encapsulated++; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 500 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 501 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 502 | { |
| 503 | vxlan_encap_trace_t *tr = |
| 504 | vlib_add_trace (vm, node, b0, sizeof (*tr)); |
| 505 | tr->tunnel_index = t0 - vxm->tunnels; |
| 506 | tr->vni = t0->vni; |
| 507 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 508 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 509 | to_next, n_left_to_next, |
| 510 | bi0, next0); |
| 511 | } |
| 512 | |
| 513 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 514 | } |
| 515 | |
| 516 | /* Do we still need this now that tunnel tx stats is kept? */ |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 517 | vlib_node_increment_counter (vm, node->node_index, |
| 518 | VXLAN_ENCAP_ERROR_ENCAPSULATED, |
| 519 | pkts_encapsulated); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 520 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 521 | return from_frame->n_vectors; |
| 522 | } |
| 523 | |
Filip Tehlar | e1714d3 | 2019-03-05 03:01:43 -0800 | [diff] [blame] | 524 | VLIB_NODE_FN (vxlan4_encap_node) (vlib_main_t * vm, |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 525 | vlib_node_runtime_t * node, |
| 526 | vlib_frame_t * from_frame) |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 527 | { |
John Lo | f4215a6 | 2017-09-18 00:20:05 -0400 | [diff] [blame] | 528 | /* Disable chksum offload as setup overhead in tx node is not worthwhile |
| 529 | for ip4 header checksum only, unless udp checksum is also required */ |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 530 | return vxlan_encap_inline (vm, node, from_frame, /* is_ip4 */ 1, |
John Lo | f4215a6 | 2017-09-18 00:20:05 -0400 | [diff] [blame] | 531 | /* csum_offload */ 0); |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 532 | } |
| 533 | |
Filip Tehlar | e1714d3 | 2019-03-05 03:01:43 -0800 | [diff] [blame] | 534 | VLIB_NODE_FN (vxlan6_encap_node) (vlib_main_t * vm, |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 535 | vlib_node_runtime_t * node, |
| 536 | vlib_frame_t * from_frame) |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 537 | { |
John Lo | f4215a6 | 2017-09-18 00:20:05 -0400 | [diff] [blame] | 538 | /* Enable checksum offload for ip6 as udp checksum is mandatory, */ |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 539 | return vxlan_encap_inline (vm, node, from_frame, /* is_ip4 */ 0, |
John Lo | f4215a6 | 2017-09-18 00:20:05 -0400 | [diff] [blame] | 540 | /* csum_offload */ 1); |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 541 | } |
| 542 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 543 | /* *INDENT-OFF* */ |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 544 | VLIB_REGISTER_NODE (vxlan4_encap_node) = { |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 545 | .name = "vxlan4-encap", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 546 | .vector_size = sizeof (u32), |
| 547 | .format_trace = format_vxlan_encap_trace, |
| 548 | .type = VLIB_NODE_TYPE_INTERNAL, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 549 | .n_errors = ARRAY_LEN(vxlan_encap_error_strings), |
| 550 | .error_strings = vxlan_encap_error_strings, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 551 | .n_next_nodes = VXLAN_ENCAP_N_NEXT, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 552 | .next_nodes = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 553 | [VXLAN_ENCAP_NEXT_DROP] = "error-drop", |
| 554 | }, |
| 555 | }; |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 556 | |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 557 | VLIB_REGISTER_NODE (vxlan6_encap_node) = { |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 558 | .name = "vxlan6-encap", |
| 559 | .vector_size = sizeof (u32), |
| 560 | .format_trace = format_vxlan_encap_trace, |
| 561 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 562 | .n_errors = ARRAY_LEN(vxlan_encap_error_strings), |
| 563 | .error_strings = vxlan_encap_error_strings, |
| 564 | .n_next_nodes = VXLAN_ENCAP_N_NEXT, |
| 565 | .next_nodes = { |
| 566 | [VXLAN_ENCAP_NEXT_DROP] = "error-drop", |
| 567 | }, |
| 568 | }; |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 569 | /* *INDENT-ON* */ |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 570 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 571 | /* |
| 572 | * fd.io coding-style-patch-verification: ON |
| 573 | * |
| 574 | * Local Variables: |
| 575 | * eval: (c-set-style "gnu") |
| 576 | * End: |
| 577 | */ |