FD.io VPP  v17.07.01-10-g3be13f0
Vector Packet Processing
ip6_sixrd.c
Go to the documentation of this file.
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:
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  *---------------------------------------------------------------------------
15  */
16 /*
17  * Defines used for testing various optimisation schemes
18  */
19 #define SIXRD_ENCAP_DUAL 0
20 
21 #include "sixrd.h"
22 
24 
25 typedef enum {
30 
31 /*
32  * ip6_sixrd
33  */
34 static uword
36  vlib_node_runtime_t *node,
37  vlib_frame_t *frame)
38 {
39  u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
41  u32 encap = 0;
42  from = vlib_frame_vector_args(frame);
43  n_left_from = frame->n_vectors;
44  next_index = node->cached_next_index;
45 
46  while (n_left_from > 0) {
47  vlib_get_next_frame(vm, node, next_index, to_next, n_left_to_next);
48 
49  while (n_left_from > 0 && n_left_to_next > 0) {
50  u32 pi0;
51  vlib_buffer_t *p0;
52  sixrd_domain_t *d0;
53  u8 error0 = SIXRD_ERROR_NONE;
54  ip6_header_t *ip60;
55  ip4_header_t *ip4h0;
57  u32 sixrd_domain_index0 = ~0;
58 
59  pi0 = to_next[0] = from[0];
60  from += 1;
61  n_left_from -= 1;
62  to_next +=1;
63  n_left_to_next -= 1;
64 
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);
69  ASSERT(d0);
70 
71  /* SIXRD calc */
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;
76 
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;
82  ip4h0->tos = 0;
83  ip4h0->length = clib_host_to_net_u16(len);
84  ip4h0->fragment_id = 0;
85  ip4h0->flags_and_fragment_offset = 0;
86  ip4h0->ttl = 0x40;
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);
91 
92  next0 = error0 == SIXRD_ERROR_NONE ? IP6_SIXRD_NEXT_IP4_LOOKUP : IP6_SIXRD_NEXT_DROP;
93 
95  sixrd_trace_t *tr = vlib_add_trace(vm, node, p0, sizeof(*tr));
96  tr->sixrd_domain_index = sixrd_domain_index0;
97  }
98 
99  p0->error = error_node->errors[error0];
100  if (PREDICT_TRUE(error0 == SIXRD_ERROR_NONE)) encap++;
101 
102  vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, pi0, next0);
103  }
104  vlib_put_next_frame(vm, node, next_index, n_left_to_next);
105  }
106  vlib_node_increment_counter(vm, ip6_sixrd_node.index, SIXRD_ERROR_ENCAPSULATED, encap);
107 
108  return frame->n_vectors;
109 }
110 
111 static char *sixrd_error_strings[] = {
112 #define _(sym,string) string,
114 #undef _
115 };
116 
118  .function = ip6_sixrd,
119  .name = "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,
125  .next_nodes = {
126  [IP6_SIXRD_NEXT_IP4_LOOKUP] = "ip4-lookup",
127  [IP6_SIXRD_NEXT_DROP] = "error-drop",
128  },
129 };
ip4_address_t ip4_src
Definition: sixrd.h:33
ip6_sixrd_next_t
Definition: ip6_sixrd.c:25
static_always_inline sixrd_domain_t * ip6_sixrd_get_domain(u32 sdi, u32 *sixrd_domain_index)
Definition: sixrd.h:102
ip4_address_t src_address
Definition: ip4_packet.h:164
static uword ip6_sixrd(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ip6_sixrd.c:35
#define PREDICT_TRUE(x)
Definition: clib.h:98
u64 as_u64[2]
Definition: ip6_packet.h:51
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
Definition: main.c:459
struct _vlib_node_registration vlib_node_registration_t
u16 flags_and_fragment_offset
Definition: ip4_packet.h:145
vlib_error_t * errors
Vector of errors for this node.
Definition: node.h:419
static_always_inline u32 sixrd_get_addr(sixrd_domain_t *d, u64 dal)
Definition: sixrd.h:88
static char * sixrd_error_strings[]
Definition: ip6_sixrd.c:111
ip4_address_t dst_address
Definition: ip4_packet.h:164
unsigned long u64
Definition: types.h:89
#define foreach_sixrd_error
Definition: sixrd.h:52
static vlib_node_registration_t ip6_sixrd_node
(constructor) VLIB_REGISTER_NODE (ip6_sixrd_node)
Definition: ip6_sixrd.c:23
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:188
#define PREDICT_FALSE(x)
Definition: clib.h:97
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:216
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:366
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:113
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1131
u16 n_vectors
Definition: node.h:345
#define VLIB_BUFFER_IS_TRACED
Definition: buffer.h:85
static vlib_node_runtime_t * vlib_node_get_runtime(vlib_main_t *vm, u32 node_index)
Get node runtime by node index.
Definition: node_funcs.h:88
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:460
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:201
u64 uword
Definition: types.h:112
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:55
u32 sixrd_domain_index
Definition: sixrd.h:79
Definition: defs.h:47
u8 * format_sixrd_trace(u8 *s, va_list *args)
Definition: sixrd.c:322
unsigned short u16
Definition: types.h:57
u16 payload_length
Definition: ip6_packet.h:332
unsigned char u8
Definition: types.h:56
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:269
#define vnet_buffer(b)
Definition: buffer.h:304
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:144
u8 ip_version_and_header_length
Definition: ip4_packet.h:132
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:74
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:57
static u16 ip4_header_checksum(ip4_header_t *i)
Definition: ip4_packet.h:239
ip6_address_t dst_address
Definition: ip6_packet.h:341