Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 2 | * Copyright (c) 2016 Cisco and/or its affiliates. |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
Florin Coras | ff0bf13 | 2016-09-05 19:30:35 +0200 | [diff] [blame] | 15 | /** |
| 16 | * @file |
| 17 | * @brief L2 LISP-GPE decap code. |
| 18 | * |
| 19 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 20 | #include <vlib/vlib.h> |
| 21 | #include <vnet/pg/pg.h> |
| 22 | #include <vnet/lisp-gpe/lisp_gpe.h> |
| 23 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 24 | typedef struct |
| 25 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 26 | u32 next_index; |
| 27 | u32 tunnel_index; |
| 28 | u32 error; |
| 29 | lisp_gpe_header_t h; |
| 30 | } lisp_gpe_rx_trace_t; |
| 31 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 32 | static u8 * |
| 33 | format_lisp_gpe_rx_trace (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 34 | { |
| 35 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 36 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 37 | lisp_gpe_rx_trace_t *t = va_arg (*args, lisp_gpe_rx_trace_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 38 | |
| 39 | if (t->tunnel_index != ~0) |
| 40 | { |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 41 | s = format (s, "LISP-GPE: tunnel %d next %d error %d", t->tunnel_index, |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 42 | t->next_index, t->error); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 43 | } |
| 44 | else |
| 45 | { |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 46 | s = format (s, "LISP-GPE: no tunnel next %d error %d\n", t->next_index, |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 47 | t->error); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 48 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 49 | s = format (s, "\n %U", format_lisp_gpe_header_with_length, &t->h, |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 50 | (u32) sizeof (t->h) /* max size */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 51 | return s; |
| 52 | } |
| 53 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 54 | static u32 next_proto_to_next_index[LISP_GPE_NEXT_PROTOS] = { |
| 55 | LISP_GPE_INPUT_NEXT_DROP, |
| 56 | LISP_GPE_INPUT_NEXT_IP4_INPUT, |
| 57 | LISP_GPE_INPUT_NEXT_IP6_INPUT, |
| 58 | LISP_GPE_INPUT_NEXT_L2_INPUT, |
| 59 | LISP_GPE_INPUT_NEXT_DROP |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 60 | }; |
| 61 | |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 62 | always_inline u32 |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 63 | next_protocol_to_next_index (lisp_gpe_header_t * lgh, u8 * next_header) |
| 64 | { |
Florin Coras | c7e91e4 | 2016-05-02 18:26:26 +0200 | [diff] [blame] | 65 | /* lisp-gpe router */ |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 66 | if (PREDICT_TRUE ((lgh->flags & LISP_GPE_FLAGS_P) |
| 67 | && lgh->next_protocol < LISP_GPE_NEXT_PROTOS)) |
Florin Coras | c7e91e4 | 2016-05-02 18:26:26 +0200 | [diff] [blame] | 68 | return next_proto_to_next_index[lgh->next_protocol]; |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 69 | /* legacy lisp router */ |
Florin Coras | c7e91e4 | 2016-05-02 18:26:26 +0200 | [diff] [blame] | 70 | else if ((lgh->flags & LISP_GPE_FLAGS_P) == 0) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 71 | { |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 72 | ip4_header_t *iph = (ip4_header_t *) next_header; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 73 | if ((iph->ip_version_and_header_length & 0xF0) == 0x40) |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 74 | return LISP_GPE_INPUT_NEXT_IP4_INPUT; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 75 | else if ((iph->ip_version_and_header_length & 0xF0) == 0x60) |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 76 | return LISP_GPE_INPUT_NEXT_IP6_INPUT; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 77 | else |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 78 | return LISP_GPE_INPUT_NEXT_DROP; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 79 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 80 | else |
| 81 | return LISP_GPE_INPUT_NEXT_DROP; |
| 82 | } |
| 83 | |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 84 | always_inline tunnel_lookup_t * |
| 85 | next_index_to_iface (lisp_gpe_main_t * lgm, u32 next_index) |
| 86 | { |
| 87 | if (LISP_GPE_INPUT_NEXT_IP4_INPUT == next_index |
| 88 | || LISP_GPE_INPUT_NEXT_IP6_INPUT == next_index) |
| 89 | return &lgm->l3_ifaces; |
| 90 | else if (LISP_GPE_INPUT_NEXT_L2_INPUT == next_index) |
| 91 | return &lgm->l2_ifaces; |
Florin Coras | 263440e | 2017-02-22 23:38:08 -0800 | [diff] [blame^] | 92 | else if (LISP_GPE_INPUT_NEXT_NSH_INPUT == next_index) |
| 93 | return &lgm->nsh_ifaces; |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 94 | clib_warning ("next_index not associated to an interface!"); |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 95 | return 0; |
| 96 | } |
| 97 | |
Florin Coras | 0f6b796 | 2016-06-21 22:32:47 +0200 | [diff] [blame] | 98 | static_always_inline void |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 99 | incr_decap_stats (vnet_main_t * vnm, u32 cpu_index, u32 length, |
| 100 | u32 sw_if_index, u32 * last_sw_if_index, u32 * n_packets, |
| 101 | u32 * n_bytes) |
Florin Coras | 0f6b796 | 2016-06-21 22:32:47 +0200 | [diff] [blame] | 102 | { |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 103 | vnet_interface_main_t *im; |
Florin Coras | 0f6b796 | 2016-06-21 22:32:47 +0200 | [diff] [blame] | 104 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 105 | if (PREDICT_TRUE (sw_if_index == *last_sw_if_index)) |
Florin Coras | 0f6b796 | 2016-06-21 22:32:47 +0200 | [diff] [blame] | 106 | { |
| 107 | *n_packets += 1; |
| 108 | *n_bytes += length; |
| 109 | } |
| 110 | else |
| 111 | { |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 112 | if (PREDICT_TRUE (*last_sw_if_index != ~0)) |
| 113 | { |
| 114 | im = &vnm->interface_main; |
Florin Coras | 0f6b796 | 2016-06-21 22:32:47 +0200 | [diff] [blame] | 115 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 116 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 117 | VNET_INTERFACE_COUNTER_RX, |
| 118 | cpu_index, *last_sw_if_index, |
| 119 | *n_packets, *n_bytes); |
| 120 | } |
Florin Coras | 0f6b796 | 2016-06-21 22:32:47 +0200 | [diff] [blame] | 121 | *last_sw_if_index = sw_if_index; |
| 122 | *n_packets = 1; |
| 123 | *n_bytes = length; |
| 124 | } |
| 125 | } |
| 126 | |
Florin Coras | ff0bf13 | 2016-09-05 19:30:35 +0200 | [diff] [blame] | 127 | /** |
| 128 | * @brief LISP-GPE decap dispatcher. |
| 129 | * @node lisp_gpe_input_inline |
| 130 | * |
| 131 | * LISP-GPE decap dispatcher. |
| 132 | * |
| 133 | * Decaps IP-UDP-LISP-GPE header and based on the next protocol and in the |
| 134 | * GPE header and the vni decides the next node to forward the packet to. |
| 135 | * |
| 136 | * @param[in] vm vlib_main_t corresponding to current thread. |
| 137 | * @param[in] node vlib_node_runtime_t data for this node. |
| 138 | * @param[in] frame vlib_frame_t whose contents should be dispatched. |
| 139 | * |
| 140 | * @return number of vectors in frame. |
| 141 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 142 | static uword |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 143 | lisp_gpe_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node, |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 144 | vlib_frame_t * from_frame, u8 is_v4) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 145 | { |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 146 | u32 n_left_from, next_index, *from, *to_next, cpu_index; |
Florin Coras | 0f6b796 | 2016-06-21 22:32:47 +0200 | [diff] [blame] | 147 | u32 n_bytes = 0, n_packets = 0, last_sw_if_index = ~0, drops = 0; |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 148 | lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 149 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 150 | cpu_index = os_get_cpu_number (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 151 | from = vlib_frame_vector_args (from_frame); |
| 152 | n_left_from = from_frame->n_vectors; |
| 153 | |
| 154 | next_index = node->cached_next_index; |
| 155 | |
| 156 | while (n_left_from > 0) |
| 157 | { |
| 158 | u32 n_left_to_next; |
| 159 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 160 | 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] | 161 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 162 | while (n_left_from >= 4 && n_left_to_next >= 2) |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 163 | { |
| 164 | u32 bi0, bi1; |
| 165 | vlib_buffer_t *b0, *b1; |
| 166 | ip4_udp_lisp_gpe_header_t *iul4_0, *iul4_1; |
| 167 | ip6_udp_lisp_gpe_header_t *iul6_0, *iul6_1; |
| 168 | lisp_gpe_header_t *lh0, *lh1; |
| 169 | u32 next0, next1, error0, error1; |
| 170 | uword *si0, *si1; |
| 171 | tunnel_lookup_t *tl0, *tl1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 172 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 173 | /* Prefetch next iteration. */ |
| 174 | { |
| 175 | vlib_buffer_t *p2, *p3; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 176 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 177 | p2 = vlib_get_buffer (vm, from[2]); |
| 178 | p3 = vlib_get_buffer (vm, from[3]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 179 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 180 | vlib_prefetch_buffer_header (p2, LOAD); |
| 181 | vlib_prefetch_buffer_header (p3, LOAD); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 182 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 183 | CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD); |
| 184 | CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD); |
| 185 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 186 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 187 | bi0 = from[0]; |
| 188 | bi1 = from[1]; |
| 189 | to_next[0] = bi0; |
| 190 | to_next[1] = bi1; |
| 191 | from += 2; |
| 192 | to_next += 2; |
| 193 | n_left_to_next -= 2; |
| 194 | n_left_from -= 2; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 195 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 196 | b0 = vlib_get_buffer (vm, bi0); |
| 197 | b1 = vlib_get_buffer (vm, bi1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 198 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 199 | /* udp leaves current_data pointing at the lisp header */ |
| 200 | if (is_v4) |
| 201 | { |
| 202 | vlib_buffer_advance (b0, |
| 203 | -(word) (sizeof (udp_header_t) + |
| 204 | sizeof (ip4_header_t))); |
| 205 | vlib_buffer_advance (b1, |
| 206 | -(word) (sizeof (udp_header_t) + |
| 207 | sizeof (ip4_header_t))); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 208 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 209 | iul4_0 = vlib_buffer_get_current (b0); |
| 210 | iul4_1 = vlib_buffer_get_current (b1); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 211 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 212 | /* pop (ip, udp, lisp-gpe) */ |
| 213 | vlib_buffer_advance (b0, sizeof (*iul4_0)); |
| 214 | vlib_buffer_advance (b1, sizeof (*iul4_1)); |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 215 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 216 | lh0 = &iul4_0->lisp; |
| 217 | lh1 = &iul4_1->lisp; |
| 218 | } |
| 219 | else |
| 220 | { |
| 221 | vlib_buffer_advance (b0, |
| 222 | -(word) (sizeof (udp_header_t) + |
| 223 | sizeof (ip6_header_t))); |
| 224 | vlib_buffer_advance (b1, |
| 225 | -(word) (sizeof (udp_header_t) + |
| 226 | sizeof (ip6_header_t))); |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 227 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 228 | iul6_0 = vlib_buffer_get_current (b0); |
| 229 | iul6_1 = vlib_buffer_get_current (b1); |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 230 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 231 | /* pop (ip, udp, lisp-gpe) */ |
| 232 | vlib_buffer_advance (b0, sizeof (*iul6_0)); |
| 233 | vlib_buffer_advance (b1, sizeof (*iul6_1)); |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 234 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 235 | lh0 = &iul6_0->lisp; |
| 236 | lh1 = &iul6_1->lisp; |
| 237 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 238 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 239 | /* determine next_index from lisp-gpe header */ |
| 240 | next0 = next_protocol_to_next_index (lh0, |
| 241 | vlib_buffer_get_current (b0)); |
| 242 | next1 = next_protocol_to_next_index (lh1, |
| 243 | vlib_buffer_get_current (b1)); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 244 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 245 | /* determine if tunnel is l2 or l3 */ |
| 246 | tl0 = next_index_to_iface (lgm, next0); |
| 247 | tl1 = next_index_to_iface (lgm, next1); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 248 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 249 | /* map iid/vni to lisp-gpe sw_if_index which is used by ipx_input to |
| 250 | * decide the rx vrf and the input features to be applied */ |
| 251 | si0 = hash_get (tl0->sw_if_index_by_vni, |
| 252 | clib_net_to_host_u32 (lh0->iid)); |
| 253 | si1 = hash_get (tl1->sw_if_index_by_vni, |
| 254 | clib_net_to_host_u32 (lh1->iid)); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 255 | |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 256 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 257 | /* Required to make the l2 tag push / pop code work on l2 subifs */ |
| 258 | vnet_update_l2_len (b0); |
| 259 | vnet_update_l2_len (b1); |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 260 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 261 | if (si0) |
| 262 | { |
| 263 | incr_decap_stats (lgm->vnet_main, cpu_index, |
| 264 | vlib_buffer_length_in_chain (vm, b0), si0[0], |
| 265 | &last_sw_if_index, &n_packets, &n_bytes); |
| 266 | vnet_buffer (b0)->sw_if_index[VLIB_RX] = si0[0]; |
| 267 | error0 = 0; |
| 268 | } |
| 269 | else |
| 270 | { |
| 271 | next0 = LISP_GPE_INPUT_NEXT_DROP; |
| 272 | error0 = LISP_GPE_ERROR_NO_TUNNEL; |
| 273 | drops++; |
| 274 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 275 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 276 | if (si1) |
| 277 | { |
| 278 | incr_decap_stats (lgm->vnet_main, cpu_index, |
| 279 | vlib_buffer_length_in_chain (vm, b1), si1[0], |
| 280 | &last_sw_if_index, &n_packets, &n_bytes); |
| 281 | vnet_buffer (b1)->sw_if_index[VLIB_RX] = si1[0]; |
| 282 | error1 = 0; |
| 283 | } |
| 284 | else |
| 285 | { |
| 286 | next1 = LISP_GPE_INPUT_NEXT_DROP; |
| 287 | error1 = LISP_GPE_ERROR_NO_TUNNEL; |
| 288 | drops++; |
| 289 | } |
Florin Coras | 577c355 | 2016-04-21 00:45:40 +0200 | [diff] [blame] | 290 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 291 | b0->error = error0 ? node->errors[error0] : 0; |
| 292 | b1->error = error1 ? node->errors[error1] : 0; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 293 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 294 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 295 | { |
| 296 | lisp_gpe_rx_trace_t *tr = vlib_add_trace (vm, node, b0, |
| 297 | sizeof (*tr)); |
| 298 | tr->next_index = next0; |
| 299 | tr->error = error0; |
| 300 | tr->h = lh0[0]; |
| 301 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 302 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 303 | if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED)) |
| 304 | { |
| 305 | lisp_gpe_rx_trace_t *tr = vlib_add_trace (vm, node, b1, |
| 306 | sizeof (*tr)); |
| 307 | tr->next_index = next1; |
| 308 | tr->error = error1; |
| 309 | tr->h = lh1[0]; |
| 310 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 311 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 312 | vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next, |
| 313 | n_left_to_next, bi0, bi1, next0, |
| 314 | next1); |
| 315 | } |
| 316 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 317 | while (n_left_from > 0 && n_left_to_next > 0) |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 318 | { |
| 319 | u32 bi0; |
| 320 | vlib_buffer_t *b0; |
| 321 | u32 next0; |
| 322 | ip4_udp_lisp_gpe_header_t *iul4_0; |
| 323 | ip6_udp_lisp_gpe_header_t *iul6_0; |
| 324 | lisp_gpe_header_t *lh0; |
| 325 | u32 error0; |
| 326 | uword *si0; |
| 327 | tunnel_lookup_t *tl0; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 328 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 329 | bi0 = from[0]; |
| 330 | to_next[0] = bi0; |
| 331 | from += 1; |
| 332 | to_next += 1; |
| 333 | n_left_from -= 1; |
| 334 | n_left_to_next -= 1; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 335 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 336 | b0 = vlib_get_buffer (vm, bi0); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 337 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 338 | /* udp leaves current_data pointing at the lisp header |
| 339 | * TODO: there's no difference in processing between v4 and v6 |
| 340 | * encapsulated packets so the code should be simplified if ip header |
| 341 | * info is not going to be used for dp smrs/dpsec */ |
| 342 | if (is_v4) |
| 343 | { |
| 344 | vlib_buffer_advance (b0, |
| 345 | -(word) (sizeof (udp_header_t) + |
| 346 | sizeof (ip4_header_t))); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 347 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 348 | iul4_0 = vlib_buffer_get_current (b0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 349 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 350 | /* pop (ip, udp, lisp-gpe) */ |
| 351 | vlib_buffer_advance (b0, sizeof (*iul4_0)); |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 352 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 353 | lh0 = &iul4_0->lisp; |
| 354 | } |
| 355 | else |
| 356 | { |
| 357 | vlib_buffer_advance (b0, |
| 358 | -(word) (sizeof (udp_header_t) + |
| 359 | sizeof (ip6_header_t))); |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 360 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 361 | iul6_0 = vlib_buffer_get_current (b0); |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 362 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 363 | /* pop (ip, udp, lisp-gpe) */ |
| 364 | vlib_buffer_advance (b0, sizeof (*iul6_0)); |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 365 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 366 | lh0 = &iul6_0->lisp; |
| 367 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 368 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 369 | /* TODO if security is to be implemented, something similar to RPF, |
| 370 | * probably we'd like to check that the peer is allowed to send us |
| 371 | * packets. For this, we should use the tunnel table OR check that |
| 372 | * we have a mapping for the source eid and that the outer source of |
| 373 | * the packet is one of its locators */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 374 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 375 | /* determine next_index from lisp-gpe header */ |
| 376 | next0 = next_protocol_to_next_index (lh0, |
| 377 | vlib_buffer_get_current (b0)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 378 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 379 | /* determine if tunnel is l2 or l3 */ |
| 380 | tl0 = next_index_to_iface (lgm, next0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 381 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 382 | /* map iid/vni to lisp-gpe sw_if_index which is used by ipx_input to |
Florin Coras | f195019 | 2016-10-25 16:47:52 +0200 | [diff] [blame] | 383 | * decide the rx vrf and the input features to be applied. |
| 384 | * NOTE: vni uses only the first 24 bits */ |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 385 | si0 = hash_get (tl0->sw_if_index_by_vni, |
Florin Coras | f195019 | 2016-10-25 16:47:52 +0200 | [diff] [blame] | 386 | clib_net_to_host_u32 (lh0->iid << 8)); |
Florin Coras | 577c355 | 2016-04-21 00:45:40 +0200 | [diff] [blame] | 387 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 388 | /* Required to make the l2 tag push / pop code work on l2 subifs */ |
| 389 | vnet_update_l2_len (b0); |
Florin Coras | 1a1adc7 | 2016-07-22 01:45:30 +0200 | [diff] [blame] | 390 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 391 | if (si0) |
| 392 | { |
| 393 | incr_decap_stats (lgm->vnet_main, cpu_index, |
| 394 | vlib_buffer_length_in_chain (vm, b0), si0[0], |
| 395 | &last_sw_if_index, &n_packets, &n_bytes); |
| 396 | vnet_buffer (b0)->sw_if_index[VLIB_RX] = si0[0]; |
| 397 | error0 = 0; |
| 398 | } |
| 399 | else |
| 400 | { |
| 401 | next0 = LISP_GPE_INPUT_NEXT_DROP; |
| 402 | error0 = LISP_GPE_ERROR_NO_TUNNEL; |
| 403 | drops++; |
| 404 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 405 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 406 | /* TODO error handling if security is implemented */ |
| 407 | b0->error = error0 ? node->errors[error0] : 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 408 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 409 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 410 | { |
| 411 | lisp_gpe_rx_trace_t *tr = vlib_add_trace (vm, node, b0, |
| 412 | sizeof (*tr)); |
| 413 | tr->next_index = next0; |
| 414 | tr->error = error0; |
| 415 | tr->h = lh0[0]; |
| 416 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 417 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 418 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, |
| 419 | n_left_to_next, bi0, next0); |
| 420 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 421 | |
| 422 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 423 | } |
Florin Coras | 0f6b796 | 2016-06-21 22:32:47 +0200 | [diff] [blame] | 424 | |
| 425 | /* flush iface stats */ |
| 426 | incr_decap_stats (lgm->vnet_main, cpu_index, 0, ~0, &last_sw_if_index, |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 427 | &n_packets, &n_bytes); |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 428 | vlib_node_increment_counter (vm, lisp_gpe_ip4_input_node.index, |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 429 | LISP_GPE_ERROR_NO_TUNNEL, drops); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 430 | return from_frame->n_vectors; |
| 431 | } |
| 432 | |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 433 | static uword |
| 434 | lisp_gpe_ip4_input (vlib_main_t * vm, vlib_node_runtime_t * node, |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 435 | vlib_frame_t * from_frame) |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 436 | { |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 437 | return lisp_gpe_input_inline (vm, node, from_frame, 1); |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | static uword |
| 441 | lisp_gpe_ip6_input (vlib_main_t * vm, vlib_node_runtime_t * node, |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 442 | vlib_frame_t * from_frame) |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 443 | { |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 444 | return lisp_gpe_input_inline (vm, node, from_frame, 0); |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 445 | } |
| 446 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 447 | static char *lisp_gpe_ip4_input_error_strings[] = { |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 448 | #define lisp_gpe_error(n,s) s, |
| 449 | #include <vnet/lisp-gpe/lisp_gpe_error.def> |
| 450 | #undef lisp_gpe_error |
| 451 | }; |
| 452 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 453 | /* *INDENT-OFF* */ |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 454 | VLIB_REGISTER_NODE (lisp_gpe_ip4_input_node) = { |
| 455 | .function = lisp_gpe_ip4_input, |
| 456 | .name = "lisp-gpe-ip4-input", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 457 | /* Takes a vector of packets. */ |
| 458 | .vector_size = sizeof (u32), |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 459 | .n_next_nodes = LISP_GPE_INPUT_N_NEXT, |
| 460 | .next_nodes = { |
| 461 | #define _(s,n) [LISP_GPE_INPUT_NEXT_##s] = n, |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 462 | foreach_lisp_gpe_ip_input_next |
| 463 | #undef _ |
| 464 | }, |
| 465 | |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 466 | .n_errors = ARRAY_LEN (lisp_gpe_ip4_input_error_strings), |
| 467 | .error_strings = lisp_gpe_ip4_input_error_strings, |
| 468 | |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 469 | .format_buffer = format_lisp_gpe_header_with_length, |
| 470 | .format_trace = format_lisp_gpe_rx_trace, |
| 471 | // $$$$ .unformat_buffer = unformat_lisp_gpe_header, |
| 472 | }; |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 473 | /* *INDENT-ON* */ |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 474 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 475 | /* *INDENT-OFF* */ |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 476 | VLIB_REGISTER_NODE (lisp_gpe_ip6_input_node) = { |
| 477 | .function = lisp_gpe_ip6_input, |
| 478 | .name = "lisp-gpe-ip6-input", |
| 479 | /* Takes a vector of packets. */ |
| 480 | .vector_size = sizeof (u32), |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 481 | .n_next_nodes = LISP_GPE_INPUT_N_NEXT, |
| 482 | .next_nodes = { |
| 483 | #define _(s,n) [LISP_GPE_INPUT_NEXT_##s] = n, |
| 484 | foreach_lisp_gpe_ip_input_next |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 485 | #undef _ |
| 486 | }, |
| 487 | |
Florin Coras | f727db9 | 2016-06-23 15:01:58 +0200 | [diff] [blame] | 488 | .n_errors = ARRAY_LEN (lisp_gpe_ip4_input_error_strings), |
| 489 | .error_strings = lisp_gpe_ip4_input_error_strings, |
| 490 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 491 | .format_buffer = format_lisp_gpe_header_with_length, |
| 492 | .format_trace = format_lisp_gpe_rx_trace, |
| 493 | // $$$$ .unformat_buffer = unformat_lisp_gpe_header, |
| 494 | }; |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 495 | /* *INDENT-ON* */ |
| 496 | |
Florin Coras | 263440e | 2017-02-22 23:38:08 -0800 | [diff] [blame^] | 497 | /** |
| 498 | * Adds arc from lisp-gpe-input to nsh-input if nsh-input is available |
| 499 | */ |
| 500 | static void |
| 501 | gpe_add_arc_from_input_to_nsh () |
| 502 | { |
| 503 | lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); |
| 504 | vlib_main_t *vm = lgm->vlib_main; |
| 505 | vlib_node_t *nsh_input; |
| 506 | |
| 507 | /* Arc already exists */ |
| 508 | if (next_proto_to_next_index[LISP_GPE_NEXT_PROTO_NSH] |
| 509 | != LISP_GPE_INPUT_NEXT_DROP) |
| 510 | return; |
| 511 | |
| 512 | /* Check if nsh-input is available */ |
| 513 | if ((nsh_input = vlib_get_node_by_name (vm, (u8 *) "nsh-input"))) |
| 514 | { |
| 515 | u32 slot4, slot6; |
| 516 | slot4 = vlib_node_add_next_with_slot (vm, lisp_gpe_ip4_input_node.index, |
| 517 | nsh_input->index, |
| 518 | LISP_GPE_NEXT_PROTO_NSH); |
| 519 | slot6 = vlib_node_add_next_with_slot (vm, lisp_gpe_ip6_input_node.index, |
| 520 | nsh_input->index, |
| 521 | LISP_GPE_NEXT_PROTO_NSH); |
| 522 | ASSERT (slot4 == slot6 && slot4 == LISP_GPE_INPUT_NEXT_NSH_INPUT); |
| 523 | |
| 524 | next_proto_to_next_index[LISP_GPE_NEXT_PROTO_NSH] = slot4; |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | /** GPE decap init function. */ |
| 529 | clib_error_t * |
| 530 | gpe_decap_init (vlib_main_t * vm) |
| 531 | { |
| 532 | clib_error_t *error = 0; |
| 533 | |
| 534 | if ((error = vlib_call_init_function (vm, lisp_gpe_init))) |
| 535 | return error; |
| 536 | |
| 537 | gpe_add_arc_from_input_to_nsh (); |
| 538 | return 0; |
| 539 | } |
| 540 | |
| 541 | VLIB_INIT_FUNCTION (gpe_decap_init); |
| 542 | |
Florin Coras | 220beac | 2016-08-16 23:04:00 +0200 | [diff] [blame] | 543 | /* |
| 544 | * fd.io coding-style-patch-verification: ON |
| 545 | * |
| 546 | * Local Variables: |
| 547 | * eval: (c-set-style "gnu") |
| 548 | * End: |
| 549 | */ |