2 * Copyright (c) 2018 Cisco and/or its affiliates.
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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
15 #include <nat/dslite/dslite.h>
19 DSLITE_CE_DECAP_NEXT_IP4_LOOKUP,
20 DSLITE_IN2OUT_NEXT_IP6_ICMP,
21 DSLITE_CE_DECAP_NEXT_DROP,
22 DSLITE_CE_DECAP_N_NEXT,
23 } dslite_ce_decap_next_t;
25 static char *dslite_ce_decap_error_strings[] = {
26 #define _(sym,string) string,
31 VLIB_NODE_FN (dslite_ce_decap_node) (vlib_main_t * vm,
32 vlib_node_runtime_t * node,
35 u32 n_left_from, *from, *to_next;
36 dslite_ce_decap_next_t next_index;
38 from = vlib_frame_vector_args (frame);
39 n_left_from = frame->n_vectors;
40 next_index = node->cached_next_index;
42 while (n_left_from > 0)
46 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
48 while (n_left_from > 0 && n_left_to_next > 0)
52 u32 next0 = DSLITE_CE_DECAP_NEXT_IP4_LOOKUP;
53 u8 error0 = DSLITE_ERROR_CE_DECAP;
58 /* speculatively enqueue b0 to the current next frame */
66 b0 = vlib_get_buffer (vm, bi0);
67 ip60 = vlib_buffer_get_current (b0);
69 if (PREDICT_FALSE (ip60->protocol != IP_PROTOCOL_IP_IN_IP))
71 if (ip60->protocol == IP_PROTOCOL_ICMP6)
73 next0 = DSLITE_IN2OUT_NEXT_IP6_ICMP;
76 error0 = DSLITE_ERROR_BAD_IP6_PROTOCOL;
77 next0 = DSLITE_CE_DECAP_NEXT_DROP;
81 ip40 = vlib_buffer_get_current (b0) + sizeof (ip6_header_t);
82 proto0 = ip_proto_to_nat_proto (ip40->protocol);
84 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
86 error0 = DSLITE_ERROR_UNSUPPORTED_PROTOCOL;
87 next0 = DSLITE_CE_DECAP_NEXT_DROP;
93 (ip60->ip_version_traffic_class_and_flow_label) & 0x0ff00000) >>
95 vlib_buffer_advance (b0, sizeof (ip6_header_t));
98 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
99 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
101 dslite_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
102 t->next_index = next0;
105 b0->error = node->errors[error0];
107 /* verify speculative enqueue, maybe switch current next frame */
108 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
109 n_left_to_next, bi0, next0);
111 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
114 return frame->n_vectors;
117 VLIB_REGISTER_NODE (dslite_ce_decap_node) = {
118 .name = "dslite-ce-decap",
119 .vector_size = sizeof (u32),
120 .format_trace = format_dslite_ce_trace,
121 .type = VLIB_NODE_TYPE_INTERNAL,
122 .n_errors = ARRAY_LEN (dslite_ce_decap_error_strings),
123 .error_strings = dslite_ce_decap_error_strings,
124 .n_next_nodes = DSLITE_CE_DECAP_N_NEXT,
125 /* edit / add dispositions here */
127 [DSLITE_CE_DECAP_NEXT_DROP] = "error-drop",
128 [DSLITE_CE_DECAP_NEXT_IP4_LOOKUP] = "ip4-lookup",
129 [DSLITE_IN2OUT_NEXT_IP6_ICMP] = "ip6-icmp-input",
134 * fd.io coding-style-patch-verification: ON
137 * eval: (c-set-style "gnu")