FD.io VPP  v18.07-rc0-415-g6c78436
Vector Packet Processing
dslite_ce_decap.c
Go to the documentation of this file.
1 /*
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:
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 #include <nat/dslite.h>
16 #include <nat/nat_inlines.h>
17 
19 
20 typedef enum
21 {
27 
29 #define _(sym,string) string,
31 #undef _
32 };
33 
34 static uword
36  vlib_frame_t * frame)
37 {
38  u32 n_left_from, *from, *to_next;
39  dslite_ce_decap_next_t next_index;
40 
41  from = vlib_frame_vector_args (frame);
42  n_left_from = frame->n_vectors;
43  next_index = node->cached_next_index;
44 
45  while (n_left_from > 0)
46  {
47  u32 n_left_to_next;
48 
49  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
50 
51  while (n_left_from > 0 && n_left_to_next > 0)
52  {
53  u32 bi0;
54  vlib_buffer_t *b0;
56  u8 error0 = DSLITE_ERROR_CE_DECAP;
57  ip4_header_t *ip40;
58  ip6_header_t *ip60;
59  u32 proto0;
60 
61  /* speculatively enqueue b0 to the current next frame */
62  bi0 = from[0];
63  to_next[0] = bi0;
64  from += 1;
65  to_next += 1;
66  n_left_from -= 1;
67  n_left_to_next -= 1;
68 
69  b0 = vlib_get_buffer (vm, bi0);
70  ip60 = vlib_buffer_get_current (b0);
71 
72  if (PREDICT_FALSE (ip60->protocol != IP_PROTOCOL_IP_IN_IP))
73  {
74  if (ip60->protocol == IP_PROTOCOL_ICMP6)
75  {
77  goto trace0;
78  }
79  error0 = DSLITE_ERROR_BAD_IP6_PROTOCOL;
81  goto trace0;
82  }
83 
84  ip40 = vlib_buffer_get_current (b0) + sizeof (ip6_header_t);
85  proto0 = ip_proto_to_snat_proto (ip40->protocol);
86 
87  if (PREDICT_FALSE (proto0 == ~0))
88  {
89  error0 = DSLITE_ERROR_UNSUPPORTED_PROTOCOL;
91  goto trace0;
92  }
93 
94  ip40->tos =
95  (clib_net_to_host_u32
96  (ip60->ip_version_traffic_class_and_flow_label) & 0x0ff00000) >>
97  20;
98  vlib_buffer_advance (b0, sizeof (ip6_header_t));
99 
100  trace0:
102  && (b0->flags & VLIB_BUFFER_IS_TRACED)))
103  {
104  dslite_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
105  t->next_index = next0;
106  }
107 
108  b0->error = node->errors[error0];
109 
110  /* verify speculative enqueue, maybe switch current next frame */
111  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
112  n_left_to_next, bi0, next0);
113  }
114  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
115  }
116 
117  return frame->n_vectors;
118 }
119 
120 /* *INDENT-OFF* */
122  .function = dslite_ce_decap_node_fn,
123  .name = "dslite-ce-decap",
124  .vector_size = sizeof (u32),
125  .format_trace = format_dslite_ce_trace,
126  .type = VLIB_NODE_TYPE_INTERNAL,
128  .error_strings = dslite_ce_decap_error_strings,
129  .n_next_nodes = DSLITE_CE_DECAP_N_NEXT,
130  /* edit / add dispositions here */
131  .next_nodes = {
132  [DSLITE_CE_DECAP_NEXT_DROP] = "error-drop",
133  [DSLITE_CE_DECAP_NEXT_IP4_LOOKUP] = "ip4-lookup",
134  [DSLITE_IN2OUT_NEXT_IP6_ICMP] = "ip6-icmp-input",
135  },
136 };
137 /* *INDENT-ON* */
138 
140 
141 /*
142  * fd.io coding-style-patch-verification: ON
143  *
144  * Local Variables:
145  * eval: (c-set-style "gnu")
146  * End:
147  */
static char * dslite_ce_decap_error_strings[]
VLIB_NODE_FUNCTION_MULTIARCH(dslite_ce_decap_node, dslite_ce_decap_node_fn)
vlib_error_t * errors
Vector of errors for this node.
Definition: node.h:451
vlib_node_registration_t dslite_ce_decap_node
(constructor) VLIB_REGISTER_NODE (dslite_ce_decap_node)
unsigned char u8
Definition: types.h:56
unsigned int u32
Definition: types.h:88
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:202
#define PREDICT_FALSE(x)
Definition: clib.h:105
#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:218
#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:364
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:135
static uword dslite_ce_decap_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:153
u16 n_vectors
Definition: node.h:380
vlib_main_t * vm
Definition: buffer.c:294
#define ARRAY_LEN(x)
Definition: clib.h:59
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:454
dslite_ce_decap_next_t
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:492
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:215
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
struct _vlib_node_registration vlib_node_registration_t
u32 ip_version_traffic_class_and_flow_label
Definition: ip6_packet.h:334
static u32 ip_proto_to_snat_proto(u8 ip_proto)
The NAT inline functions.
Definition: nat_inlines.h:25
u32 next_index
Definition: dslite.h:98
u64 uword
Definition: types.h:112
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:267
#define foreach_dslite_error
Definition: dslite.h:107
u16 flags
Copy of main node flags.
Definition: node.h:486
u8 * format_dslite_ce_trace(u8 *s, va_list *args)
Definition: dslite.c:234
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:295
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:111
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