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.h>
16 #include <nat/nat_inlines.h>
18 vlib_node_registration_t dslite_ce_encap_node;
22 DSLITE_CE_ENCAP_NEXT_IP6_LOOKUP,
23 DSLITE_CE_ENCAP_NEXT_DROP,
24 DSLITE_CE_ENCAP_N_NEXT,
25 } dslite_ce_encap_next_t;
27 static char *dslite_ce_encap_error_strings[] = {
28 #define _(sym,string) string,
34 dslite_ce_encap_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
37 u32 n_left_from, *from, *to_next;
38 dslite_ce_encap_next_t next_index;
39 dslite_main_t *dm = &dslite_main;
41 from = vlib_frame_vector_args (frame);
42 n_left_from = frame->n_vectors;
43 next_index = node->cached_next_index;
45 while (n_left_from > 0)
49 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
51 while (n_left_from > 0 && n_left_to_next > 0)
55 u32 next0 = DSLITE_CE_ENCAP_NEXT_IP6_LOOKUP;
56 u8 error0 = DSLITE_ERROR_CE_ENCAP;
61 /* speculatively enqueue b0 to the current next frame */
69 b0 = vlib_get_buffer (vm, bi0);
70 ip40 = vlib_buffer_get_current (b0);
71 proto0 = ip_proto_to_snat_proto (ip40->protocol);
73 if (PREDICT_FALSE (proto0 == ~0))
75 error0 = DSLITE_ERROR_UNSUPPORTED_PROTOCOL;
76 next0 = DSLITE_CE_ENCAP_NEXT_DROP;
80 /* Construct IPv6 header */
81 vlib_buffer_advance (b0, -(sizeof (ip6_header_t)));
82 ip60 = vlib_buffer_get_current (b0);
83 ip60->ip_version_traffic_class_and_flow_label =
84 clib_host_to_net_u32 ((6 << 28) + (ip40->tos << 20));
85 ip60->payload_length = ip40->length;
86 ip60->protocol = IP_PROTOCOL_IP_IN_IP;
87 ip60->hop_limit = ip40->ttl;
88 ip60->dst_address.as_u64[0] = dm->aftr_ip6_addr.as_u64[0];
89 ip60->dst_address.as_u64[1] = dm->aftr_ip6_addr.as_u64[1];
90 ip60->src_address.as_u64[0] = dm->b4_ip6_addr.as_u64[0];
91 ip60->src_address.as_u64[1] = dm->b4_ip6_addr.as_u64[1];
94 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
95 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
97 dslite_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
98 t->next_index = next0;
101 b0->error = node->errors[error0];
103 /* verify speculative enqueue, maybe switch current next frame */
104 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
105 n_left_to_next, bi0, next0);
107 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
110 return frame->n_vectors;
114 VLIB_REGISTER_NODE (dslite_ce_encap_node) = {
115 .function = dslite_ce_encap_node_fn,
116 .name = "dslite-ce-encap",
117 .vector_size = sizeof (u32),
118 .format_trace = format_dslite_ce_trace,
119 .type = VLIB_NODE_TYPE_INTERNAL,
120 .n_errors = ARRAY_LEN (dslite_ce_encap_error_strings),
121 .error_strings = dslite_ce_encap_error_strings,
122 .n_next_nodes = DSLITE_CE_ENCAP_N_NEXT,
123 /* edit / add dispositions here */
125 [DSLITE_CE_ENCAP_NEXT_DROP] = "error-drop",
126 [DSLITE_CE_ENCAP_NEXT_IP6_LOOKUP] = "ip6-lookup",
131 VLIB_NODE_FUNCTION_MULTIARCH (dslite_ce_encap_node, dslite_ce_encap_node_fn);
134 * fd.io coding-style-patch-verification: ON
137 * eval: (c-set-style "gnu")