Line data Source code
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 :
38 2312 : VLIB_NODE_FN(pnat_input_node)
39 : (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame) {
40 12 : return pnat_node_inline(vm, node, frame, PNAT_IP4_INPUT, VLIB_RX);
41 : }
42 2303 : VLIB_NODE_FN(pnat_output_node)
43 : (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame) {
44 3 : return pnat_node_inline(vm, node, frame, PNAT_IP4_OUTPUT, VLIB_TX);
45 : }
46 :
47 : #ifndef CLIB_MARCH_VARIANT
48 46680 : VLIB_REGISTER_NODE(pnat_input_node) = {
49 : .name = "pnat-input",
50 : .vector_size = sizeof(u32),
51 : .format_trace = format_pnat_trace,
52 : .type = VLIB_NODE_TYPE_INTERNAL,
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 :
62 46680 : VLIB_REGISTER_NODE(pnat_output_node) = {
63 : .name = "pnat-output",
64 : .vector_size = sizeof(u32),
65 : .format_trace = format_pnat_trace,
66 : .type = VLIB_NODE_TYPE_INTERNAL,
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 25343 : 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 25343 : 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 : };
|