1 /*---------------------------------------------------------------------------
2 * Copyright (c) 2009-2014 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.
14 *---------------------------------------------------------------------------
17 * Defines used for testing various optimisation schemes
19 #define SIXRD_ENCAP_DUAL 0
23 static vlib_node_registration_t ip6_sixrd_node;
26 IP6_SIXRD_NEXT_IP4_LOOKUP,
35 ip6_sixrd (vlib_main_t *vm,
36 vlib_node_runtime_t *node,
39 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
40 vlib_node_runtime_t *error_node = vlib_node_get_runtime(vm, ip6_sixrd_node.index);
42 from = vlib_frame_vector_args(frame);
43 n_left_from = frame->n_vectors;
44 next_index = node->cached_next_index;
46 while (n_left_from > 0) {
47 vlib_get_next_frame(vm, node, next_index, to_next, n_left_to_next);
49 while (n_left_from > 0 && n_left_to_next > 0) {
53 u8 error0 = SIXRD_ERROR_NONE;
56 u32 next0 = IP6_SIXRD_NEXT_IP4_LOOKUP;
57 u32 sixrd_domain_index0 = ~0;
59 pi0 = to_next[0] = from[0];
65 p0 = vlib_get_buffer(vm, pi0);
66 ip60 = vlib_buffer_get_current(p0);
67 // p0->current_length = clib_net_to_host_u16(ip40->length);
68 d0 = ip6_sixrd_get_domain(vnet_buffer(p0)->ip.adj_index[VLIB_TX], &sixrd_domain_index0);
72 u64 dal60 = clib_net_to_host_u64(ip60->dst_address.as_u64[0]);
73 u32 da40 = sixrd_get_addr(d0, dal60);
74 u16 len = clib_net_to_host_u16(ip60->payload_length) + 60;
75 if (da40 == 0) error0 = SIXRD_ERROR_UNKNOWN;
77 /* construct ipv4 header */
78 vlib_buffer_advance(p0, - (sizeof(ip4_header_t)));
79 ip4h0 = vlib_buffer_get_current(p0);
80 vnet_buffer(p0)->sw_if_index[VLIB_TX] = (u32)~0;
81 ip4h0->ip_version_and_header_length = 0x45;
83 ip4h0->length = clib_host_to_net_u16(len);
84 ip4h0->fragment_id = 0;
85 ip4h0->flags_and_fragment_offset = 0;
87 ip4h0->protocol = IP_PROTOCOL_IPV6;
88 ip4h0->src_address = d0->ip4_src;
89 ip4h0->dst_address.as_u32 = clib_host_to_net_u32(da40);
90 ip4h0->checksum = ip4_header_checksum(ip4h0);
92 next0 = error0 == SIXRD_ERROR_NONE ? IP6_SIXRD_NEXT_IP4_LOOKUP : IP6_SIXRD_NEXT_DROP;
94 if (PREDICT_FALSE(p0->flags & VLIB_BUFFER_IS_TRACED)) {
95 sixrd_trace_t *tr = vlib_add_trace(vm, node, p0, sizeof(*tr));
96 tr->sixrd_domain_index = sixrd_domain_index0;
99 p0->error = error_node->errors[error0];
100 if (PREDICT_TRUE(error0 == SIXRD_ERROR_NONE)) encap++;
102 vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, pi0, next0);
104 vlib_put_next_frame(vm, node, next_index, n_left_to_next);
106 vlib_node_increment_counter(vm, ip6_sixrd_node.index, SIXRD_ERROR_ENCAPSULATED, encap);
108 return frame->n_vectors;
111 static char *sixrd_error_strings[] = {
112 #define _(sym,string) string,
117 VLIB_REGISTER_NODE(ip6_sixrd_node,static) = {
118 .function = ip6_sixrd,
120 .vector_size = sizeof(u32),
121 .format_trace = format_sixrd_trace,
122 .n_errors = SIXRD_N_ERROR,
123 .error_strings = sixrd_error_strings,
124 .n_next_nodes = IP6_SIXRD_N_NEXT,
126 [IP6_SIXRD_NEXT_IP4_LOOKUP] = "ip4-lookup",
127 [IP6_SIXRD_NEXT_DROP] = "error-drop",