FD.io VPP  v21.06-3-gbb25fbf28
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/dslite.h>
16 
17 typedef enum
18 {
23 
25 #define _(sym,string) string,
27 #undef _
28 };
29 
33 {
34  u32 n_left_from, *from, *to_next;
37 
39  n_left_from = frame->n_vectors;
40  next_index = node->cached_next_index;
41 
42  while (n_left_from > 0)
43  {
44  u32 n_left_to_next;
45 
46  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
47 
48  while (n_left_from > 0 && n_left_to_next > 0)
49  {
50  u32 bi0;
51  vlib_buffer_t *b0;
53  u8 error0 = DSLITE_ERROR_CE_ENCAP;
54  ip4_header_t *ip40;
55  ip6_header_t *ip60;
56  u32 proto0;
57 
58  /* speculatively enqueue b0 to the current next frame */
59  bi0 = from[0];
60  to_next[0] = bi0;
61  from += 1;
62  to_next += 1;
63  n_left_from -= 1;
64  n_left_to_next -= 1;
65 
66  b0 = vlib_get_buffer (vm, bi0);
67  ip40 = vlib_buffer_get_current (b0);
68  proto0 = ip_proto_to_nat_proto (ip40->protocol);
69 
70  if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
71  {
72  error0 = DSLITE_ERROR_UNSUPPORTED_PROTOCOL;
74  goto trace0;
75  }
76 
77  /* Construct IPv6 header */
78  vlib_buffer_advance (b0, -(sizeof (ip6_header_t)));
79  ip60 = vlib_buffer_get_current (b0);
81  clib_host_to_net_u32 ((6 << 28) + (ip40->tos << 20));
82  ip60->payload_length = ip40->length;
83  ip60->protocol = IP_PROTOCOL_IP_IN_IP;
84  ip60->hop_limit = ip40->ttl;
85  ip60->dst_address.as_u64[0] = dm->aftr_ip6_addr.as_u64[0];
86  ip60->dst_address.as_u64[1] = dm->aftr_ip6_addr.as_u64[1];
87  ip60->src_address.as_u64[0] = dm->b4_ip6_addr.as_u64[0];
88  ip60->src_address.as_u64[1] = dm->b4_ip6_addr.as_u64[1];
89 
90  trace0:
92  && (b0->flags & VLIB_BUFFER_IS_TRACED)))
93  {
94  dslite_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
95  t->next_index = next0;
96  }
97 
98  b0->error = node->errors[error0];
99 
100  /* verify speculative enqueue, maybe switch current next frame */
102  n_left_to_next, bi0, next0);
103  }
104  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
105  }
106 
107  return frame->n_vectors;
108 }
109 
110 /* *INDENT-OFF* */
112  .name = "dslite-ce-encap",
113  .vector_size = sizeof (u32),
114  .format_trace = format_dslite_ce_trace,
117  .error_strings = dslite_ce_encap_error_strings,
118  .n_next_nodes = DSLITE_CE_ENCAP_N_NEXT,
119  /* edit / add dispositions here */
120  .next_nodes = {
121  [DSLITE_CE_ENCAP_NEXT_DROP] = "error-drop",
122  [DSLITE_CE_ENCAP_NEXT_IP6_LOOKUP] = "ip6-lookup",
123  },
124 };
125 /* *INDENT-ON* */
126 
127 /*
128  * fd.io coding-style-patch-verification: ON
129  *
130  * Local Variables:
131  * eval: (c-set-style "gnu")
132  * End:
133  */
foreach_dslite_error
#define foreach_dslite_error
Definition: dslite.h:145
DSLITE_CE_ENCAP_N_NEXT
@ DSLITE_CE_ENCAP_N_NEXT
Definition: dslite_ce_encap.c:21
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
dslite.h
dslite_main_t
Definition: dslite.h:103
next_index
nat44_ei_hairpin_src_next_t next_index
Definition: nat44_ei_hairpinning.c:412
vlib_get_buffer
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:111
ip6_header_t::protocol
u8 protocol
Definition: ip6_packet.h:304
ip_proto_to_nat_proto
static nat_protocol_t ip_proto_to_nat_proto(u8 ip_proto)
Common NAT inline functions.
Definition: inlines.h:24
VLIB_NODE_TYPE_INTERNAL
@ VLIB_NODE_TYPE_INTERNAL
Definition: node.h:72
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
ip6_header_t::hop_limit
u8 hop_limit
Definition: ip6_packet.h:307
dslite_ce_encap_next_t
dslite_ce_encap_next_t
Definition: dslite_ce_encap.c:17
dslite_ce_encap_node
vlib_node_registration_t dslite_ce_encap_node
(constructor) VLIB_REGISTER_NODE (dslite_ce_encap_node)
Definition: dslite_ce_encap.c:111
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
dslite_main_t::aftr_ip6_addr
ip6_address_t aftr_ip6_addr
Definition: dslite.h:105
vlib_frame_t
Definition: node.h:372
ip4_header_t
Definition: ip4_packet.h:87
ip4_header_t::tos
ip_dscp_t tos
Definition: ip4_packet.h:96
ip4_header_t::length
u16 length
Definition: ip4_packet.h:99
DSLITE_CE_ENCAP_NEXT_DROP
@ DSLITE_CE_ENCAP_NEXT_DROP
Definition: dslite_ce_encap.c:20
vlib_buffer_advance
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:276
vlib_buffer_t::error
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:145
VLIB_NODE_FN
#define VLIB_NODE_FN(node)
Definition: node.h:202
VLIB_NODE_FLAG_TRACE
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:291
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
ARRAY_LEN
#define ARRAY_LEN(x)
Definition: clib.h:70
vlib_frame_vector_args
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:301
DSLITE_CE_ENCAP_NEXT_IP6_LOOKUP
@ DSLITE_CE_ENCAP_NEXT_IP6_LOOKUP
Definition: dslite_ce_encap.c:19
ip6_header_t::dst_address
ip6_address_t dst_address
Definition: ip6_packet.h:310
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
vlib_validate_buffer_enqueue_x1
#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:224
vlib_put_next_frame
vlib_put_next_frame(vm, node, next_index, 0)
u32
unsigned int u32
Definition: types.h:88
ip4_header_t::ttl
u8 ttl
Definition: ip4_packet.h:112
dslite_trace_t
Definition: dslite.h:134
dslite_main_t::b4_ip6_addr
ip6_address_t b4_ip6_addr
Definition: dslite.h:107
ip6_header_t
Definition: ip6_packet.h:294
ip6_header_t::src_address
ip6_address_t src_address
Definition: ip6_packet.h:310
vlib_main_t
Definition: main.h:102
format_dslite_ce_trace
u8 * format_dslite_ce_trace(u8 *s, va_list *args)
Definition: dslite.c:271
vlib_add_trace
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace.c:628
u8
unsigned char u8
Definition: types.h:56
vlib_buffer_get_current
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:257
dslite_trace_t::next_index
u32 next_index
Definition: dslite.h:136
dslite_main
dslite_main_t dslite_main
Definition: dslite.c:21
ip6_header_t::payload_length
u16 payload_length
Definition: ip6_packet.h:301
vlib_node_runtime_t
Definition: node.h:454
dslite_ce_encap_error_strings
static char * dslite_ce_encap_error_strings[]
Definition: dslite_ce_encap.c:24
from
from
Definition: nat44_ei_hairpinning.c:415
vlib_get_next_frame
#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:395
n_left_from
n_left_from
Definition: nat44_ei_hairpinning.c:416
ip6_header_t::ip_version_traffic_class_and_flow_label
u32 ip_version_traffic_class_and_flow_label
Definition: ip6_packet.h:297
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
ip4_header_t::protocol
u8 protocol
Definition: ip4_packet.h:115
vlib_buffer_t::flags
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index,...
Definition: buffer.h:133
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169