FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
pnat_node.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 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  * Policy NAT.
18  * Match packet against rule in a hash and translate according to given
19  * instructions. Rules are kept in a flow-cache bihash. Instructions in a pool
20  * of translation entries.
21  *
22  * All rules for a given interface/direction must use the same lookup pattern.
23  * E.g. SA+SP.
24  *
25  * A dynamic NAT would punt to slow path on a miss in the flow cache, in this
26  * case the miss behaviour is configurable. Default behaviour is pass packet
27  * along unchanged.
28  *
29  * The data structures are shared and assuming that updates to the tables are
30  * rare. Data-structures are protected depending on the API/CLI barriers.
31  */
32 
33 #include <stdbool.h>
34 #include <vlib/vlib.h>
35 #include <pnat/pnat.api_enum.h> /* For error counters */
36 #include "pnat_node.h" /* Graph nodes */
37 
41 }
45 }
46 
47 #ifndef CLIB_MARCH_VARIANT
49  .name = "pnat-input",
50  .vector_size = sizeof(u32),
51  .format_trace = format_pnat_trace,
53  .n_errors = PNAT_N_ERROR,
54  .error_counters = pnat_error_counters,
55  .n_next_nodes = PNAT_N_NEXT,
56  .next_nodes =
57  {
58  [PNAT_NEXT_DROP] = "error-drop",
59  },
60 };
61 
63  .name = "pnat-output",
64  .vector_size = sizeof(u32),
65  .format_trace = format_pnat_trace,
67  .n_errors = PNAT_N_ERROR,
68  .error_counters = pnat_error_counters,
69  .sibling_of = "pnat-input",
70 };
71 #endif
72 
73 /* Hook up features */
74 VNET_FEATURE_INIT(pnat_input, static) = {
75  .arc_name = "ip4-unicast",
76  .node_name = "pnat-input",
77  .runs_after = VNET_FEATURES("ip4-sv-reassembly-feature"),
78 };
79 VNET_FEATURE_INIT(pnat_output, static) = {
80  .arc_name = "ip4-output",
81  .node_name = "pnat-output",
82  .runs_after = VNET_FEATURES("ip4-sv-reassembly-output-feature"),
83 };
vlib.h
format_pnat_trace
static u8 * format_pnat_trace(u8 *s, va_list *args)
Definition: pnat_node.h:30
VNET_FEATURE_INIT
VNET_FEATURE_INIT(pnat_input, static)
VLIB_NODE_TYPE_INTERNAL
@ VLIB_NODE_TYPE_INTERNAL
Definition: node.h:72
PNAT_NEXT_DROP
@ PNAT_NEXT_DROP
Definition: pnat_node.h:26
VLIB_RX
@ VLIB_RX
Definition: defs.h:46
vlib_frame_t
Definition: node.h:372
VLIB_NODE_FN
#define VLIB_NODE_FN(node)
Definition: node.h:202
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: pnat_node.c:39
pnat_node_inline
static_always_inline uword pnat_node_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, pnat_attachment_point_t attachment, int dir)
Definition: pnat_node.h:149
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
node
vlib_main_t vlib_node_runtime_t * node
Definition: pnat_node.c:39
pnat_node.h
pnat_input_node
vlib_node_registration_t pnat_input_node
(constructor) VLIB_REGISTER_NODE (pnat_input_node)
Definition: pnat_node.c:48
u32
unsigned int u32
Definition: types.h:88
vlib_main_t
Definition: main.h:102
VNET_FEATURES
#define VNET_FEATURES(...)
Definition: feature.h:470
pnat_output_node
vlib_node_registration_t pnat_output_node
(constructor) VLIB_REGISTER_NODE (pnat_output_node)
Definition: pnat_node.c:62
pnat_error_counters
vlib_error_desc_t pnat_error_counters[10]
Definition: pnat_test_stubs.h:41
PNAT_N_NEXT
@ PNAT_N_NEXT
Definition: pnat_node.h:26
vm
vlib_main_t * vm
Definition: pnat_node.c:39
PNAT_IP4_OUTPUT
@ PNAT_IP4_OUTPUT
Definition: pnat.api:34
vlib_node_runtime_t
Definition: node.h:454
PNAT_IP4_INPUT
@ PNAT_IP4_INPUT
Definition: pnat.api:33
VLIB_TX
@ VLIB_TX
Definition: defs.h:47
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169