2 * nsh_node.c - nsh nodes
4 * Copyright (c) 2013 Cisco and/or its affiliates.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <vnet/vnet.h>
19 #include <vnet/plugin/plugin.h>
23 nsh_md2_encap (vlib_buffer_t * b, nsh_base_header_t * hdr,
24 nsh_entry_t * nsh_entry)
26 nsh_main_t *nm = &nsh_main;
27 nsh_base_header_t *nsh_base;
28 nsh_tlv_header_t *opt0;
29 nsh_tlv_header_t *limit0;
30 nsh_tlv_header_t *nsh_md2;
31 nsh_option_map_t *nsh_option;
32 u8 old_option_size = 0;
33 u8 new_option_size = 0;
35 /* Populate the NSH Header */
36 opt0 = (nsh_tlv_header_t *) (nsh_entry->tlvs_data);
37 limit0 = (nsh_tlv_header_t *) (nsh_entry->tlvs_data + nsh_entry->tlvs_len);
39 nsh_md2 = (nsh_tlv_header_t *) ((u8 *) hdr /*nsh_entry->rewrite */ +
40 sizeof (nsh_base_header_t));
41 nsh_entry->rewrite_size = sizeof (nsh_base_header_t);
43 /* Scan the set of variable metadata, process ones that we understand */
46 old_option_size = sizeof (nsh_tlv_header_t) + opt0->length;
48 old_option_size = ((old_option_size + 3) >> 2) << 2;
50 nsh_option = nsh_md2_lookup_option (opt0->class, opt0->type);
51 if (nsh_option == NULL)
56 if (nm->options[nsh_option->option_id])
58 if ((*nm->options[nsh_option->option_id]) (b, nsh_md2))
63 /* option length may be varied */
64 new_option_size = sizeof (nsh_tlv_header_t) + nsh_md2->length;
66 new_option_size = ((new_option_size + 3) >> 2) << 2;
67 nsh_entry->rewrite_size += new_option_size;
69 nsh_md2 = (nsh_tlv_header_t *) (((u8 *) nsh_md2) + new_option_size);
70 opt0 = (nsh_tlv_header_t *) (((u8 *) opt0) + old_option_size);
76 opt0 = (nsh_tlv_header_t *) (((u8 *) opt0) + old_option_size);
80 /* update nsh header's length */
81 nsh_base = (nsh_base_header_t *) nsh_entry->rewrite;
82 nsh_base->length = (nsh_base->length & NSH_TTL_L2_MASK) |
83 ((nsh_entry->rewrite_size >> 2) & NSH_LEN_MASK);
88 nsh_md2_swap (vlib_buffer_t * b,
89 nsh_base_header_t * hdr,
91 nsh_entry_t * nsh_entry, u32 * next, u32 drop_node_val)
93 nsh_main_t *nm = &nsh_main;
94 nsh_base_header_t *nsh_base;
95 nsh_tlv_header_t *opt0;
96 nsh_tlv_header_t *limit0;
97 nsh_tlv_header_t *nsh_md2;
98 nsh_option_map_t *nsh_option;
99 u8 old_option_size = 0;
100 u8 new_option_size = 0;
102 /* Populate the NSH Header */
103 opt0 = (nsh_md2_data_t *) (hdr + 1);
104 limit0 = (nsh_md2_data_t *) ((u8 *) hdr + header_len);
107 (nsh_tlv_header_t *) (nsh_entry->rewrite + sizeof (nsh_base_header_t));
108 nsh_entry->rewrite_size = sizeof (nsh_base_header_t);
110 /* Scan the set of variable metadata, process ones that we understand */
111 while (opt0 < limit0)
113 old_option_size = sizeof (nsh_tlv_header_t) + opt0->length;
114 /* round to 4-byte */
115 old_option_size = ((old_option_size + 3) >> 2) << 2;
117 nsh_option = nsh_md2_lookup_option (opt0->class, opt0->type);
118 if (nsh_option == NULL)
123 if (nm->swap_options[nsh_option->option_id])
125 if ((*nm->swap_options[nsh_option->option_id]) (b, opt0, nsh_md2))
130 /* option length may be varied */
131 new_option_size = sizeof (nsh_tlv_header_t) + nsh_md2->length;
132 /* round to 4-byte */
133 new_option_size = ((new_option_size + 3) >> 2) << 2;
134 nsh_entry->rewrite_size += new_option_size;
135 nsh_md2 = (nsh_tlv_header_t *) (((u8 *) nsh_md2) + new_option_size);
137 opt0 = (nsh_tlv_header_t *) (((u8 *) opt0) + old_option_size);
143 opt0 = (nsh_tlv_header_t *) (((u8 *) opt0) + old_option_size);
147 /* update nsh header's length */
148 nsh_base = (nsh_base_header_t *) nsh_entry->rewrite;
149 nsh_base->length = (nsh_base->length & NSH_TTL_L2_MASK) |
150 ((nsh_entry->rewrite_size >> 2) & NSH_LEN_MASK);
155 nsh_md2_decap (vlib_buffer_t * b,
156 nsh_base_header_t * hdr,
157 u32 * header_len, u32 * next, u32 drop_node_val)
159 nsh_main_t *nm = &nsh_main;
160 nsh_md2_data_t *opt0;
161 nsh_md2_data_t *limit0;
162 nsh_option_map_t *nsh_option;
165 /* Populate the NSH Header */
166 opt0 = (nsh_md2_data_t *) (hdr + 1);
167 limit0 = (nsh_md2_data_t *) ((u8 *) hdr + *header_len);
169 /* Scan the set of variable metadata, process ones that we understand */
170 while (opt0 < limit0)
172 nsh_option = nsh_md2_lookup_option (opt0->class, opt0->type);
173 if (nsh_option == NULL)
175 *next = drop_node_val;
179 if (nm->pop_options[nsh_option->option_id])
181 if ((*nm->pop_options[nsh_option->option_id]) (b, opt0))
183 *next = drop_node_val;
187 /* round to 4-byte */
188 option_len = ((opt0->length + 3) >> 2) << 2;
190 (nsh_md2_data_t *) (((u8 *) opt0) + sizeof (nsh_md2_data_t) +
193 (nm->decap_v4_next_override) ? (nm->decap_v4_next_override) : (*next);
194 *header_len = (nm->decap_v4_next_override) ? 0 : (*header_len);
201 nsh_input_map (vlib_main_t * vm,
202 vlib_node_runtime_t * node,
203 vlib_frame_t * from_frame, u32 node_type)
205 u32 n_left_from, next_index, *from, *to_next;
206 nsh_main_t *nm = &nsh_main;
208 from = vlib_frame_vector_args (from_frame);
209 n_left_from = from_frame->n_vectors;
211 next_index = node->cached_next_index;
213 while (n_left_from > 0)
217 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
219 while (n_left_from >= 4 && n_left_to_next >= 2)
222 vlib_buffer_t *b0, *b1;
223 u32 next0 = NSH_NODE_NEXT_DROP, next1 = NSH_NODE_NEXT_DROP;
224 uword *entry0, *entry1;
225 nsh_base_header_t *hdr0 = 0, *hdr1 = 0;
226 u32 header_len0 = 0, header_len1 = 0;
227 u32 nsp_nsi0, nsp_nsi1;
230 nsh_map_t *map0 = 0, *map1 = 0;
231 nsh_entry_t *nsh_entry0 = 0, *nsh_entry1 = 0;
232 nsh_base_header_t *encap_hdr0 = 0, *encap_hdr1 = 0;
233 u32 encap_hdr_len0 = 0, encap_hdr_len1 = 0;
234 nsh_proxy_session_by_key_t key0, key1;
236 nsh_proxy_session_t *proxy0, *proxy1;
237 u32 sw_if_index0 = 0, sw_if_index1 = 0;
238 ethernet_header_t dummy_eth0, dummy_eth1;
240 /* Prefetch next iteration. */
242 vlib_buffer_t *p2, *p3;
244 p2 = vlib_get_buffer (vm, from[2]);
245 p3 = vlib_get_buffer (vm, from[3]);
247 vlib_prefetch_buffer_header (p2, LOAD);
248 vlib_prefetch_buffer_header (p3, LOAD);
250 CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
251 CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
266 b0 = vlib_get_buffer (vm, bi0);
267 b1 = vlib_get_buffer (vm, bi1);
268 hdr0 = vlib_buffer_get_current (b0);
269 hdr1 = vlib_buffer_get_current (b1);
271 /* Process packet 0 */
272 if (node_type == NSH_INPUT_TYPE)
274 nsp_nsi0 = hdr0->nsp_nsi;
275 header_len0 = (hdr0->length & NSH_LEN_MASK) * 4;
276 ttl0 = (hdr0->ver_o_c & NSH_TTL_H4_MASK) << 2 |
277 (hdr0->length & NSH_TTL_L2_MASK) >> 6;
279 if (PREDICT_FALSE (ttl0 == 0))
281 error0 = NSH_NODE_ERROR_INVALID_TTL;
285 else if (node_type == NSH_CLASSIFIER_TYPE)
288 clib_host_to_net_u32 (vnet_buffer (b0)->
289 l2_classify.opaque_index);
291 else if (node_type == NSH_AWARE_VNF_PROXY_TYPE)
293 /* Push dummy Eth header */
294 char dummy_dst_address[6] =
295 { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
296 char dummy_src_address[6] =
297 { 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc };
298 clib_memcpy_fast (dummy_eth0.dst_address, dummy_dst_address, 6);
299 clib_memcpy_fast (dummy_eth0.src_address, dummy_src_address, 6);
300 dummy_eth0.type = 0x0800;
301 vlib_buffer_advance (b0, -(word) sizeof (ethernet_header_t));
302 hdr0 = vlib_buffer_get_current (b0);
303 clib_memcpy_fast (hdr0, &dummy_eth0,
304 (word) sizeof (ethernet_header_t));
306 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX];
307 nsp_nsi0 = nm->tunnel_index_by_sw_if_index[sw_if_index0];
311 clib_memset (&key0, 0, sizeof (key0));
312 key0.transport_type = NSH_NODE_NEXT_ENCAP_VXLAN4;
313 key0.transport_index = vnet_buffer (b0)->sw_if_index[VLIB_RX];
315 p0 = hash_get_mem (nm->nsh_proxy_session_by_key, &key0);
316 if (PREDICT_FALSE (p0 == 0))
318 error0 = NSH_NODE_ERROR_NO_PROXY;
322 proxy0 = pool_elt_at_index (nm->nsh_proxy_sessions, p0[0]);
323 if (PREDICT_FALSE (proxy0 == 0))
325 error0 = NSH_NODE_ERROR_NO_PROXY;
328 nsp_nsi0 = proxy0->nsp_nsi;
331 entry0 = hash_get_mem (nm->nsh_mapping_by_key, &nsp_nsi0);
332 if (PREDICT_FALSE (entry0 == 0))
334 error0 = NSH_NODE_ERROR_NO_MAPPING;
338 /* Entry should point to a mapping ... */
339 map0 = pool_elt_at_index (nm->nsh_mappings, entry0[0]);
340 if (PREDICT_FALSE (map0 == 0))
342 error0 = NSH_NODE_ERROR_NO_MAPPING;
346 /* set up things for next node to transmit ie which node to handle it and where */
347 next0 = map0->next_node;
348 vnet_buffer (b0)->sw_if_index[VLIB_TX] = map0->sw_if_index;
349 vnet_buffer (b0)->ip.adj_index[VLIB_TX] = map0->adj_index;
351 if (PREDICT_FALSE (map0->nsh_action == NSH_ACTION_POP))
354 if (PREDICT_FALSE (hdr0->md_type == 2))
356 nsh_md2_decap (b0, hdr0, &header_len0, &next0,
358 if (PREDICT_FALSE (next0 == NSH_NODE_NEXT_DROP))
360 error0 = NSH_NODE_ERROR_INVALID_OPTIONS;
363 vnet_buffer (b0)->sw_if_index[VLIB_RX] =
364 map0->rx_sw_if_index;
368 vlib_buffer_advance (b0, (word) header_len0);
372 entry0 = hash_get_mem (nm->nsh_entry_by_key, &map0->mapped_nsp_nsi);
373 if (PREDICT_FALSE (entry0 == 0))
375 error0 = NSH_NODE_ERROR_NO_ENTRY;
380 (nsh_entry_t *) pool_elt_at_index (nm->nsh_entries, entry0[0]);
381 encap_hdr0 = (nsh_base_header_t *) (nsh_entry0->rewrite);
382 /* rewrite_size should equal to (encap_hdr0->length * 4) */
383 encap_hdr_len0 = nsh_entry0->rewrite_size;
385 if (PREDICT_TRUE (map0->nsh_action == NSH_ACTION_SWAP))
388 if (PREDICT_FALSE (hdr0->md_type == 2))
390 nsh_md2_swap (b0, hdr0, header_len0, nsh_entry0,
391 &next0, NSH_NODE_NEXT_DROP);
392 if (PREDICT_FALSE (next0 == NSH_NODE_NEXT_DROP))
394 error0 = NSH_NODE_ERROR_INVALID_OPTIONS;
399 /* Pop old NSH header */
400 vlib_buffer_advance (b0, (word) header_len0);
402 /* After processing, md2's length may be varied */
403 encap_hdr_len0 = nsh_entry0->rewrite_size;
404 /* Push new NSH header */
405 vlib_buffer_advance (b0, -(word) encap_hdr_len0);
406 hdr0 = vlib_buffer_get_current (b0);
407 clib_memcpy_fast (hdr0, encap_hdr0, (word) encap_hdr_len0);
412 if (PREDICT_TRUE (map0->nsh_action == NSH_ACTION_PUSH))
414 /* After processing, md2's length may be varied */
415 encap_hdr_len0 = nsh_entry0->rewrite_size;
416 /* Push new NSH header */
417 vlib_buffer_advance (b0, -(word) encap_hdr_len0);
418 hdr0 = vlib_buffer_get_current (b0);
419 clib_memcpy_fast (hdr0, encap_hdr0, (word) encap_hdr_len0);
422 if (PREDICT_FALSE (nsh_entry0->nsh_base.md_type == 2))
424 nsh_md2_encap (b0, hdr0, nsh_entry0);
430 b0->error = error0 ? node->errors[error0] : 0;
432 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
434 nsh_input_trace_t *tr =
435 vlib_add_trace (vm, node, b0, sizeof (*tr));
436 clib_memcpy_fast (&(tr->trace_data), hdr0,
437 ((hdr0->length & NSH_LEN_MASK) * 4));
440 /* Process packet 1 */
441 if (node_type == NSH_INPUT_TYPE)
443 nsp_nsi1 = hdr1->nsp_nsi;
444 header_len1 = (hdr1->length & NSH_LEN_MASK) * 4;
445 ttl1 = (hdr1->ver_o_c & NSH_TTL_H4_MASK) << 2 |
446 (hdr1->length & NSH_TTL_L2_MASK) >> 6;
448 if (PREDICT_FALSE (ttl1 == 0))
450 error1 = NSH_NODE_ERROR_INVALID_TTL;
454 else if (node_type == NSH_CLASSIFIER_TYPE)
457 clib_host_to_net_u32 (vnet_buffer (b1)->
458 l2_classify.opaque_index);
460 else if (node_type == NSH_AWARE_VNF_PROXY_TYPE)
462 /* Push dummy Eth header */
463 char dummy_dst_address[6] =
464 { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
465 char dummy_src_address[6] =
466 { 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc };
467 clib_memcpy_fast (dummy_eth1.dst_address, dummy_dst_address, 6);
468 clib_memcpy_fast (dummy_eth1.src_address, dummy_src_address, 6);
469 dummy_eth1.type = 0x0800;
470 vlib_buffer_advance (b1, -(word) sizeof (ethernet_header_t));
471 hdr1 = vlib_buffer_get_current (b1);
472 clib_memcpy_fast (hdr1, &dummy_eth1,
473 (word) sizeof (ethernet_header_t));
475 sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_TX];
476 nsp_nsi1 = nm->tunnel_index_by_sw_if_index[sw_if_index1];
480 clib_memset (&key1, 0, sizeof (key1));
481 key1.transport_type = NSH_NODE_NEXT_ENCAP_VXLAN4;
482 key1.transport_index = vnet_buffer (b1)->sw_if_index[VLIB_RX];
484 p1 = hash_get_mem (nm->nsh_proxy_session_by_key, &key1);
485 if (PREDICT_FALSE (p1 == 0))
487 error1 = NSH_NODE_ERROR_NO_PROXY;
491 proxy1 = pool_elt_at_index (nm->nsh_proxy_sessions, p1[0]);
492 if (PREDICT_FALSE (proxy1 == 0))
494 error1 = NSH_NODE_ERROR_NO_PROXY;
497 nsp_nsi1 = proxy1->nsp_nsi;
500 entry1 = hash_get_mem (nm->nsh_mapping_by_key, &nsp_nsi1);
501 if (PREDICT_FALSE (entry1 == 0))
503 error1 = NSH_NODE_ERROR_NO_MAPPING;
507 /* Entry should point to a mapping ... */
508 map1 = pool_elt_at_index (nm->nsh_mappings, entry1[0]);
509 if (PREDICT_FALSE (map1 == 0))
511 error1 = NSH_NODE_ERROR_NO_MAPPING;
515 /* set up things for next node to transmit ie which node to handle it and where */
516 next1 = map1->next_node;
517 vnet_buffer (b1)->sw_if_index[VLIB_TX] = map1->sw_if_index;
518 vnet_buffer (b1)->ip.adj_index[VLIB_TX] = map1->adj_index;
520 if (PREDICT_FALSE (map1->nsh_action == NSH_ACTION_POP))
523 if (PREDICT_FALSE (hdr1->md_type == 2))
525 nsh_md2_decap (b1, hdr1, &header_len1, &next1,
527 if (PREDICT_FALSE (next1 == NSH_NODE_NEXT_DROP))
529 error1 = NSH_NODE_ERROR_INVALID_OPTIONS;
532 vnet_buffer (b1)->sw_if_index[VLIB_RX] =
533 map1->rx_sw_if_index;
537 vlib_buffer_advance (b1, (word) header_len1);
541 entry1 = hash_get_mem (nm->nsh_entry_by_key, &map1->mapped_nsp_nsi);
542 if (PREDICT_FALSE (entry1 == 0))
544 error1 = NSH_NODE_ERROR_NO_ENTRY;
549 (nsh_entry_t *) pool_elt_at_index (nm->nsh_entries, entry1[0]);
550 encap_hdr1 = (nsh_base_header_t *) (nsh_entry1->rewrite);
551 /* rewrite_size should equal to (encap_hdr0->length * 4) */
552 encap_hdr_len1 = nsh_entry1->rewrite_size;
554 if (PREDICT_TRUE (map1->nsh_action == NSH_ACTION_SWAP))
557 if (PREDICT_FALSE (hdr1->md_type == 2))
559 nsh_md2_swap (b1, hdr1, header_len1, nsh_entry1,
560 &next1, NSH_NODE_NEXT_DROP);
561 if (PREDICT_FALSE (next1 == NSH_NODE_NEXT_DROP))
563 error1 = NSH_NODE_ERROR_INVALID_OPTIONS;
568 /* Pop old NSH header */
569 vlib_buffer_advance (b1, (word) header_len1);
571 /* After processing, md2's length may be varied */
572 encap_hdr_len1 = nsh_entry1->rewrite_size;
573 /* Push new NSH header */
574 vlib_buffer_advance (b1, -(word) encap_hdr_len1);
575 hdr1 = vlib_buffer_get_current (b1);
576 clib_memcpy_fast (hdr1, encap_hdr1, (word) encap_hdr_len1);
581 if (PREDICT_FALSE (map1->nsh_action == NSH_ACTION_PUSH))
583 /* After processing, md2's length may be varied */
584 encap_hdr_len1 = nsh_entry1->rewrite_size;
585 /* Push new NSH header */
586 vlib_buffer_advance (b1, -(word) encap_hdr_len1);
587 hdr1 = vlib_buffer_get_current (b1);
588 clib_memcpy_fast (hdr1, encap_hdr1, (word) encap_hdr_len1);
591 if (PREDICT_FALSE (nsh_entry1->nsh_base.md_type == 2))
593 nsh_md2_encap (b1, hdr1, nsh_entry1);
599 b1->error = error1 ? node->errors[error1] : 0;
601 if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED))
603 nsh_input_trace_t *tr =
604 vlib_add_trace (vm, node, b1, sizeof (*tr));
605 clib_memcpy_fast (&(tr->trace_data), hdr1,
606 ((hdr1->length & NSH_LEN_MASK) * 4));
609 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
610 n_left_to_next, bi0, bi1, next0,
615 while (n_left_from > 0 && n_left_to_next > 0)
618 vlib_buffer_t *b0 = NULL;
619 u32 next0 = NSH_NODE_NEXT_DROP;
621 nsh_base_header_t *hdr0 = 0;
627 nsh_entry_t *nsh_entry0 = 0;
628 nsh_base_header_t *encap_hdr0 = 0;
629 u32 encap_hdr_len0 = 0;
630 nsh_proxy_session_by_key_t key0;
632 nsh_proxy_session_t *proxy0 = 0;
633 u32 sw_if_index0 = 0;
634 ethernet_header_t dummy_eth0;
644 b0 = vlib_get_buffer (vm, bi0);
645 hdr0 = vlib_buffer_get_current (b0);
647 if (node_type == NSH_INPUT_TYPE)
649 nsp_nsi0 = hdr0->nsp_nsi;
650 header_len0 = (hdr0->length & NSH_LEN_MASK) * 4;
651 ttl0 = (hdr0->ver_o_c & NSH_TTL_H4_MASK) << 2 |
652 (hdr0->length & NSH_TTL_L2_MASK) >> 6;
654 if (PREDICT_FALSE (ttl0 == 0))
656 error0 = NSH_NODE_ERROR_INVALID_TTL;
660 else if (node_type == NSH_CLASSIFIER_TYPE)
663 clib_host_to_net_u32 (vnet_buffer (b0)->
664 l2_classify.opaque_index);
666 else if (node_type == NSH_AWARE_VNF_PROXY_TYPE)
668 /* Push dummy Eth header */
669 char dummy_dst_address[6] =
670 { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
671 char dummy_src_address[6] =
672 { 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc };
673 clib_memcpy_fast (dummy_eth0.dst_address, dummy_dst_address, 6);
674 clib_memcpy_fast (dummy_eth0.src_address, dummy_src_address, 6);
675 dummy_eth0.type = 0x0800;
676 vlib_buffer_advance (b0, -(word) sizeof (ethernet_header_t));
677 hdr0 = vlib_buffer_get_current (b0);
678 clib_memcpy_fast (hdr0, &dummy_eth0,
679 (word) sizeof (ethernet_header_t));
681 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX];
682 nsp_nsi0 = nm->tunnel_index_by_sw_if_index[sw_if_index0];
686 clib_memset (&key0, 0, sizeof (key0));
687 key0.transport_type = NSH_NODE_NEXT_ENCAP_VXLAN4;
688 key0.transport_index = vnet_buffer (b0)->sw_if_index[VLIB_RX];
690 p0 = hash_get_mem (nm->nsh_proxy_session_by_key, &key0);
691 if (PREDICT_FALSE (p0 == 0))
693 error0 = NSH_NODE_ERROR_NO_PROXY;
697 proxy0 = pool_elt_at_index (nm->nsh_proxy_sessions, p0[0]);
698 if (PREDICT_FALSE (proxy0 == 0))
700 error0 = NSH_NODE_ERROR_NO_PROXY;
703 nsp_nsi0 = proxy0->nsp_nsi;
706 entry0 = hash_get_mem (nm->nsh_mapping_by_key, &nsp_nsi0);
708 if (PREDICT_FALSE (entry0 == 0))
710 error0 = NSH_NODE_ERROR_NO_MAPPING;
714 /* Entry should point to a mapping ... */
715 map0 = pool_elt_at_index (nm->nsh_mappings, entry0[0]);
717 if (PREDICT_FALSE (map0 == 0))
719 error0 = NSH_NODE_ERROR_NO_MAPPING;
723 /* set up things for next node to transmit ie which node to handle it and where */
724 next0 = map0->next_node;
725 vnet_buffer (b0)->sw_if_index[VLIB_TX] = map0->sw_if_index;
726 vnet_buffer (b0)->ip.adj_index[VLIB_TX] = map0->adj_index;
727 vnet_buffer (b0)->sw_if_index[VLIB_RX] = map0->nsh_sw_if;
729 if (PREDICT_FALSE (map0->nsh_action == NSH_ACTION_POP))
732 if (PREDICT_FALSE (hdr0->md_type == 2))
734 nsh_md2_decap (b0, hdr0, &header_len0, &next0,
736 if (PREDICT_FALSE (next0 == NSH_NODE_NEXT_DROP))
738 error0 = NSH_NODE_ERROR_INVALID_OPTIONS;
741 vnet_buffer (b0)->sw_if_index[VLIB_RX] =
742 map0->rx_sw_if_index;
746 vlib_buffer_advance (b0, (word) header_len0);
750 entry0 = hash_get_mem (nm->nsh_entry_by_key, &map0->mapped_nsp_nsi);
751 if (PREDICT_FALSE (entry0 == 0))
753 error0 = NSH_NODE_ERROR_NO_ENTRY;
758 (nsh_entry_t *) pool_elt_at_index (nm->nsh_entries, entry0[0]);
759 encap_hdr0 = (nsh_base_header_t *) (nsh_entry0->rewrite);
760 /* rewrite_size should equal to (encap_hdr0->length * 4) */
761 encap_hdr_len0 = nsh_entry0->rewrite_size;
763 if (PREDICT_TRUE (map0->nsh_action == NSH_ACTION_SWAP))
766 if (PREDICT_FALSE (hdr0->md_type == 2))
768 nsh_md2_swap (b0, hdr0, header_len0, nsh_entry0,
769 &next0, NSH_NODE_NEXT_DROP);
770 if (PREDICT_FALSE (next0 == NSH_NODE_NEXT_DROP))
772 error0 = NSH_NODE_ERROR_INVALID_OPTIONS;
777 /* Pop old NSH header */
778 vlib_buffer_advance (b0, (word) header_len0);
780 /* After processing, md2's length may be varied */
781 encap_hdr_len0 = nsh_entry0->rewrite_size;
782 /* Push new NSH header */
783 vlib_buffer_advance (b0, -(word) encap_hdr_len0);
784 hdr0 = vlib_buffer_get_current (b0);
785 clib_memcpy_fast (hdr0, encap_hdr0, (word) encap_hdr_len0);
790 if (PREDICT_TRUE (map0->nsh_action == NSH_ACTION_PUSH))
792 /* After processing, md2's length may be varied */
793 encap_hdr_len0 = nsh_entry0->rewrite_size;
794 /* Push new NSH header */
795 vlib_buffer_advance (b0, -(word) encap_hdr_len0);
796 hdr0 = vlib_buffer_get_current (b0);
797 clib_memcpy_fast (hdr0, encap_hdr0, (word) encap_hdr_len0);
799 if (PREDICT_FALSE (nsh_entry0->nsh_base.md_type == 2))
801 nsh_md2_encap (b0, hdr0, nsh_entry0);
806 trace00:b0->error = error0 ? node->errors[error0] : 0;
808 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
810 nsh_input_trace_t *tr =
811 vlib_add_trace (vm, node, b0, sizeof (*tr));
812 clib_memcpy_fast (&(tr->trace_data[0]), hdr0,
813 ((hdr0->length & NSH_LEN_MASK) * 4));
816 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
817 n_left_to_next, bi0, next0);
820 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
824 return from_frame->n_vectors;
828 * @brief Graph processing dispatch function for NSH Input
835 * @return from_frame->n_vectors
838 VLIB_NODE_FN (nsh_input_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
839 vlib_frame_t * from_frame)
841 return nsh_input_map (vm, node, from_frame, NSH_INPUT_TYPE);
845 * @brief Graph processing dispatch function for NSH-Proxy
852 * @return from_frame->n_vectors
855 VLIB_NODE_FN (nsh_proxy_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
856 vlib_frame_t * from_frame)
858 return nsh_input_map (vm, node, from_frame, NSH_PROXY_TYPE);
862 * @brief Graph processing dispatch function for NSH Classifier
864 * @node nsh_classifier
869 * @return from_frame->n_vectors
872 VLIB_NODE_FN (nsh_classifier_node) (vlib_main_t * vm,
873 vlib_node_runtime_t * node,
874 vlib_frame_t * from_frame)
876 return nsh_input_map (vm, node, from_frame, NSH_CLASSIFIER_TYPE);
880 * @brief Graph processing dispatch function for NSH-AWARE-VNF-PROXY
882 * @node nsh_aware_vnf_proxy
887 * @return from_frame->n_vectors
890 VLIB_NODE_FN (nsh_aware_vnf_proxy_node) (vlib_main_t * vm,
891 vlib_node_runtime_t * node,
892 vlib_frame_t * from_frame)
894 return nsh_input_map (vm, node, from_frame, NSH_AWARE_VNF_PROXY_TYPE);
897 static char *nsh_node_error_strings[] = {
898 #define _(sym,string) string,
899 foreach_nsh_node_error
905 /* register nsh-input node */
906 VLIB_REGISTER_NODE (nsh_input_node) = {
908 .vector_size = sizeof (u32),
909 .format_trace = format_nsh_node_map_trace,
910 .format_buffer = format_nsh_header,
911 .type = VLIB_NODE_TYPE_INTERNAL,
912 .n_errors = ARRAY_LEN (nsh_node_error_strings),
913 .error_strings = nsh_node_error_strings,
914 .n_next_nodes = NSH_NODE_N_NEXT,
916 #define _(s,n) [NSH_NODE_NEXT_##s] = n,
917 foreach_nsh_node_next
922 /* register nsh-proxy node */
923 VLIB_REGISTER_NODE (nsh_proxy_node) =
926 .vector_size = sizeof (u32),
927 .format_trace = format_nsh_node_map_trace,
928 .format_buffer = format_nsh_header,
929 .type = VLIB_NODE_TYPE_INTERNAL,
930 .n_errors = ARRAY_LEN (nsh_node_error_strings),
931 .error_strings = nsh_node_error_strings,
932 .n_next_nodes = NSH_NODE_N_NEXT,
934 #define _(s,n) [NSH_NODE_NEXT_##s] = n,
935 foreach_nsh_node_next
940 /* register nsh-classifier node */
941 VLIB_REGISTER_NODE (nsh_classifier_node) =
943 .name = "nsh-classifier",
944 .vector_size = sizeof (u32),
945 .format_trace = format_nsh_node_map_trace,
946 .format_buffer = format_nsh_header,
947 .type = VLIB_NODE_TYPE_INTERNAL,
948 .n_errors = ARRAY_LEN (nsh_node_error_strings),
949 .error_strings = nsh_node_error_strings,
950 .n_next_nodes = NSH_NODE_N_NEXT,
952 #define _(s,n) [NSH_NODE_NEXT_##s] = n,
953 foreach_nsh_node_next
958 /* register nsh-aware-vnf-proxy node */
959 VLIB_REGISTER_NODE (nsh_aware_vnf_proxy_node) =
961 .name = "nsh-aware-vnf-proxy",
962 .vector_size = sizeof (u32),
963 .format_trace = format_nsh_node_map_trace,
964 .format_buffer = format_nsh_header,
965 .type = VLIB_NODE_TYPE_INTERNAL,
966 .n_errors = ARRAY_LEN (nsh_node_error_strings),
967 .error_strings = nsh_node_error_strings,
968 .n_next_nodes = NSH_NODE_N_NEXT,
970 #define _(s,n) [NSH_NODE_NEXT_##s] = n,
971 foreach_nsh_node_next
978 * fd.io coding-style-patch-verification: ON
981 * eval: (c-set-style "gnu")