FD.io VPP  v17.04.2-2-ga8f93f8
Vector Packet Processing
ip4_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 #include "sixrd.h"
17 
19 
20 typedef enum {
25 
26 /*
27  * ip4_sixrd_sec_check
28  */
31 {
32  u32 a = sixrd_get_addr(d, sa6.as_u64[0]);
33  clib_warning("Security check: %U %U", format_ip4_address, &a, format_ip4_address, &sa4);
34  if (PREDICT_FALSE(sixrd_get_addr(d, sa6.as_u64[0]) != sa4.as_u32))
35  *error = SIXRD_ERROR_SEC_CHECK;
36 }
37 
38 /*
39  * ip4_sixrd
40  */
41 static uword
43  vlib_node_runtime_t *node,
44  vlib_frame_t *frame)
45 {
46  u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
48  u32 decap = 0;
49 
50  from = vlib_frame_vector_args(frame);
51  n_left_from = frame->n_vectors;
52  next_index = node->cached_next_index;
53  while (n_left_from > 0) {
54  vlib_get_next_frame(vm, node, next_index, to_next, n_left_to_next);
55 
56  /* Single loop */
57  while (n_left_from > 0 && n_left_to_next > 0) {
58  u32 pi0;
59  vlib_buffer_t *p0;
60  u8 error0 = SIXRD_ERROR_NONE;
61  sixrd_domain_t *d0 = 0;
62  ip4_header_t *ip40;
63  ip6_header_t *ip60;
64  u32 sixrd_domain_index0 = ~0;
65  u32 next0;
66 
67  pi0 = to_next[0] = from[0];
68  from += 1;
69  n_left_from -= 1;
70  to_next +=1;
71  n_left_to_next -= 1;
72 
73  p0 = vlib_get_buffer(vm, pi0);
74  ip40 = vlib_buffer_get_current(p0);
75 
76  /* Throw away anything that isn't IP in IP. */
77  if (PREDICT_TRUE(ip40->protocol == IP_PROTOCOL_IPV6 && clib_net_to_host_u16(ip40->length) >= 60)) {
78  vlib_buffer_advance(p0, sizeof(ip4_header_t));
79  ip60 = vlib_buffer_get_current(p0);
80  d0 = ip4_sixrd_get_domain(vnet_buffer(p0)->ip.adj_index[VLIB_TX], (ip6_address_t *)&ip60->src_address,
81  &sixrd_domain_index0, &error0);
82  } else {
83  error0 = SIXRD_ERROR_BAD_PROTOCOL;
84  }
85  if (d0) {
86  /* SIXRD inbound security check */
87  ip4_sixrd_sec_check(d0, ip40->src_address, ip60->src_address, &error0);
88  }
89 
90  next0 = error0 == SIXRD_ERROR_NONE ? IP4_SIXRD_NEXT_IP6_LOOKUP : IP4_SIXRD_NEXT_DROP;
91 
93  sixrd_trace_t *tr = vlib_add_trace(vm, node, p0, sizeof(*tr));
94  tr->sixrd_domain_index = sixrd_domain_index0;
95  }
96 
97  p0->error = error_node->errors[error0];
98  if (PREDICT_TRUE(error0 == SIXRD_ERROR_NONE)) decap++;
99  vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, pi0, next0);
100 
101  }
102  vlib_put_next_frame(vm, node, next_index, n_left_to_next);
103  }
104  vlib_node_increment_counter(vm, ip4_sixrd_node.index, SIXRD_ERROR_DECAPSULATED, decap);
105 
106  return frame->n_vectors;
107 }
108 
109 static char *sixrd_error_strings[] = {
110 #define _(sym,string) string,
112 #undef _
113 };
114 
116  .function = ip4_sixrd,
117  .name = "ip4-sixrd",
118  .vector_size = sizeof(u32),
119  .format_trace = format_sixrd_trace,
120  .n_errors = SIXRD_N_ERROR,
121  .error_strings = sixrd_error_strings,
122  .n_next_nodes = IP4_SIXRD_N_NEXT,
123  .next_nodes = {
124  [IP4_SIXRD_NEXT_IP6_LOOKUP] = "ip6-lookup",
125  [IP4_SIXRD_NEXT_DROP] = "error-drop",
126  },
127 };
static uword ip4_sixrd(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ip4_sixrd.c:42
static vlib_node_registration_t ip4_sixrd_node
(constructor) VLIB_REGISTER_NODE (ip4_sixrd_node)
Definition: ip4_sixrd.c:18
a
Definition: bitmap.h:516
static_always_inline sixrd_domain_t * ip4_sixrd_get_domain(u32 sdi, ip6_address_t *addr, u32 *sixrd_domain_index, u8 *error)
Definition: sixrd.h:120
ip4_address_t src_address
Definition: ip4_packet.h:163
#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
vlib_error_t * errors
Vector of errors for this node.
Definition: node.h:418
static_always_inline u32 sixrd_get_addr(sixrd_domain_t *d, u64 dal)
Definition: sixrd.h:88
ip6_address_t src_address
Definition: ip6_packet.h:341
static char * sixrd_error_strings[]
Definition: ip4_sixrd.c:109
format_function_t format_ip4_address
Definition: format.h:79
#define static_always_inline
Definition: clib.h:85
#define foreach_sixrd_error
Definition: sixrd.h:52
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:350
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:1115
u16 n_vectors
Definition: node.h:344
vlib_main_t * vm
Definition: buffer.c:276
#define clib_warning(format, args...)
Definition: error.h:59
#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:455
unsigned int u32
Definition: types.h:88
ip4_sixrd_next_t
Definition: ip4_sixrd.c:20
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 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:253
#define vnet_buffer(b)
Definition: buffer.h:294
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:143
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_always_inline void ip4_sixrd_sec_check(sixrd_domain_t *d, ip4_address_t sa4, ip6_address_t sa6, u8 *error)
Definition: ip4_sixrd.c:30