FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
dslite_ce_encap.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 
18 typedef enum
19 {
24 
26 #define _(sym,string) string,
28 #undef _
29 };
30 
32  vlib_node_runtime_t * node,
33  vlib_frame_t * frame)
34 {
35  u32 n_left_from, *from, *to_next;
36  dslite_ce_encap_next_t next_index;
38 
39  from = vlib_frame_vector_args (frame);
40  n_left_from = frame->n_vectors;
41  next_index = node->cached_next_index;
42 
43  while (n_left_from > 0)
44  {
45  u32 n_left_to_next;
46 
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  {
51  u32 bi0;
52  vlib_buffer_t *b0;
54  u8 error0 = DSLITE_ERROR_CE_ENCAP;
55  ip4_header_t *ip40;
56  ip6_header_t *ip60;
57  u32 proto0;
58 
59  /* speculatively enqueue b0 to the current next frame */
60  bi0 = from[0];
61  to_next[0] = bi0;
62  from += 1;
63  to_next += 1;
64  n_left_from -= 1;
65  n_left_to_next -= 1;
66 
67  b0 = vlib_get_buffer (vm, bi0);
68  ip40 = vlib_buffer_get_current (b0);
69  proto0 = ip_proto_to_snat_proto (ip40->protocol);
70 
71  if (PREDICT_FALSE (proto0 == ~0))
72  {
73  error0 = DSLITE_ERROR_UNSUPPORTED_PROTOCOL;
75  goto trace0;
76  }
77 
78  /* Construct IPv6 header */
79  vlib_buffer_advance (b0, -(sizeof (ip6_header_t)));
80  ip60 = vlib_buffer_get_current (b0);
82  clib_host_to_net_u32 ((6 << 28) + (ip40->tos << 20));
83  ip60->payload_length = ip40->length;
84  ip60->protocol = IP_PROTOCOL_IP_IN_IP;
85  ip60->hop_limit = ip40->ttl;
86  ip60->dst_address.as_u64[0] = dm->aftr_ip6_addr.as_u64[0];
87  ip60->dst_address.as_u64[1] = dm->aftr_ip6_addr.as_u64[1];
88  ip60->src_address.as_u64[0] = dm->b4_ip6_addr.as_u64[0];
89  ip60->src_address.as_u64[1] = dm->b4_ip6_addr.as_u64[1];
90 
91  trace0:
92  if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
93  && (b0->flags & VLIB_BUFFER_IS_TRACED)))
94  {
95  dslite_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
96  t->next_index = next0;
97  }
98 
99  b0->error = node->errors[error0];
100 
101  /* verify speculative enqueue, maybe switch current next frame */
102  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
103  n_left_to_next, bi0, next0);
104  }
105  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
106  }
107 
108  return frame->n_vectors;
109 }
110 
111 /* *INDENT-OFF* */
113  .name = "dslite-ce-encap",
114  .vector_size = sizeof (u32),
115  .format_trace = format_dslite_ce_trace,
118  .error_strings = dslite_ce_encap_error_strings,
119  .n_next_nodes = DSLITE_CE_ENCAP_N_NEXT,
120  /* edit / add dispositions here */
121  .next_nodes = {
122  [DSLITE_CE_ENCAP_NEXT_DROP] = "error-drop",
123  [DSLITE_CE_ENCAP_NEXT_IP6_LOOKUP] = "ip6-lookup",
124  },
125 };
126 /* *INDENT-ON* */
127 
128 /*
129  * fd.io coding-style-patch-verification: ON
130  *
131  * Local Variables:
132  * eval: (c-set-style "gnu")
133  * End:
134  */
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:124
u64 as_u64[2]
Definition: ip6_packet.h:51
dslite_ce_encap_next_t
#define VLIB_NODE_FN(node)
Definition: node.h:202
ip6_address_t src_address
Definition: ip6_packet.h:383
unsigned char u8
Definition: types.h:56
ip6_address_t b4_ip6_addr
Definition: dslite.h:82
unsigned int u32
Definition: types.h:88
vl_api_fib_path_type_t type
Definition: fib_types.api:123
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:136
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:229
#define PREDICT_FALSE(x)
Definition: clib.h:112
#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:338
ip6_address_t aftr_ip6_addr
Definition: dslite.h:80
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
vlib_main_t * vm
Definition: buffer.c:323
dslite_main_t dslite_main
Definition: dslite.c:19
#define ARRAY_LEN(x)
Definition: clib.h:63
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:456
static char * dslite_ce_encap_error_strings[]
vlib_node_registration_t dslite_ce_encap_node
(constructor) VLIB_REGISTER_NODE (dslite_ce_encap_node)
ip_dscp_t tos
Definition: ip4_packet.h:141
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:248
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 ip_version_traffic_class_and_flow_label
Definition: ip6_packet.h:370
u16 payload_length
Definition: ip6_packet.h:374
static u32 ip_proto_to_snat_proto(u8 ip_proto)
Definition: nat_inlines.h:147
u32 next_index
Definition: dslite.h:106
VLIB buffer representation.
Definition: buffer.h:102
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:244
#define foreach_dslite_error
Definition: dslite.h:115
u8 * format_dslite_ce_trace(u8 *s, va_list *args)
Definition: dslite.c:254
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:302
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85
ip6_address_t dst_address
Definition: ip6_packet.h:383