FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
pnat.h
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 #ifndef included_pnat_h
17 #define included_pnat_h
18 
19 #include <stdbool.h>
20 #include <vnet/ip/ip4_packet.h>
21 #include <vppinfra/bihash_16_8.h>
22 
23 #define PNAT_FLOW_HASH_BUCKETS 256
24 
25 /* Definitions from pnat.api */
26 #include <pnat/pnat.api_types.h>
27 typedef vl_api_pnat_match_tuple_t pnat_match_tuple_t;
28 typedef vl_api_pnat_rewrite_tuple_t pnat_rewrite_tuple_t;
29 typedef vl_api_pnat_mask_t pnat_mask_t;
30 typedef vl_api_pnat_attachment_point_t pnat_attachment_point_t;
31 
32 /* Rewrite instructions */
33 typedef enum {
34  PNAT_INSTR_NONE = 1 << 0,
42 
43 typedef struct {
44  u64 as_u64[2];
46 
47 /* Session cache entries */
48 typedef struct {
49  /* What to translate to */
51 
52  /* Stored in network byte order */
57 
58  /* Byte copy inside of packet */
61 
62  u8 clear_offset; /* Clear byte */
63 
64  /* Used for trace/show commands */
68 
69 /* Interface object */
70 typedef struct {
74 
75  /* Feature chain enabled on interface */
77 
80 
81 /* Globals */
82 typedef struct {
83  bool enabled;
84 
85  clib_bihash_16_8_t flowhash; /* Bi-directional */
86 
87  /* Interface pool */
90 
91  /* Translations pool */
93 
95 } pnat_main_t;
96 extern pnat_main_t pnat_main;
97 
99 
100 /* Packet trace information */
101 typedef struct {
105 } pnat_trace_t;
106 
108  u32 *binding_index);
109 int pnat_binding_del(u32 binding_index);
111  u32 binding_index);
113  u32 binding_index);
115  pnat_match_tuple_t *match);
116 
117 static inline void
121  kv->key[0] = (u64)src.as_u32 << 32 | dst.as_u32;
122  kv->key[0] &= mask.as_u64[0];
123  kv->key[1] =
124  (u64)protocol << 56 | (u64)sw_if_index << 36 | (u64)attachment << 32;
125  kv->key[1] |= (u32)sport << 16 | dport;
126  kv->key[1] &= mask.as_u64[1];
127 }
128 
129 #endif
pnat_trace_t::pool_index
u32 pool_index
Definition: pnat.h:102
pnat_match_tuple_t
vl_api_pnat_match_tuple_t pnat_match_tuple_t
Definition: pnat.h:27
pnat_instructions_t
pnat_instructions_t
Definition: pnat.h:33
pnat_trace_t::match
pnat_match_tuple_t match
Definition: pnat.h:103
pnat_mask_fast_t
Definition: pnat.h:43
pnat_flow_lookup
u32 pnat_flow_lookup(u32 sw_if_index, pnat_attachment_point_t attachment, pnat_match_tuple_t *match)
Definition: pnat.c:310
pnat_translation_t::rewrite
pnat_rewrite_tuple_t rewrite
Definition: pnat.h:66
pnat_translation_t::from_offset
u8 from_offset
Definition: pnat.h:59
u16
unsigned short u16
Definition: types.h:57
pnat_mask_t
vl_api_pnat_mask_t pnat_mask_t
Definition: pnat.h:29
pnat_main_t::interface_by_sw_if_index
u32 * interface_by_sw_if_index
Definition: pnat.h:89
pnat_main_t
Definition: pnat.h:82
pnat_interface_t::sw_if_index
u32 sw_if_index
Definition: pnat.h:71
sport
u16 sport
Definition: pnat.api:43
pnat_rewrite_tuple_t
vl_api_pnat_rewrite_tuple_t pnat_rewrite_tuple_t
Definition: pnat.h:28
PNAT_INSTR_DESTINATION_PORT
@ PNAT_INSTR_DESTINATION_PORT
Definition: pnat.h:38
PNAT_INSTR_SOURCE_PORT
@ PNAT_INSTR_SOURCE_PORT
Definition: pnat.h:36
pnat_trace_t::rewrite
pnat_rewrite_tuple_t rewrite
Definition: pnat.h:104
pnat_binding_del
int pnat_binding_del(u32 binding_index)
Definition: pnat.c:392
pnat_translation_t::post_sa
ip4_address_t post_sa
Definition: pnat.h:53
pnat_main_t::translations
pnat_translation_t * translations
Definition: pnat.h:92
pnat_translation_t::to_offset
u8 to_offset
Definition: pnat.h:60
pnat_interface_t::refcount
u32 refcount
Definition: pnat.h:78
pnat_interface_by_sw_if_index
pnat_interface_t * pnat_interface_by_sw_if_index(u32 sw_if_index)
Definition: pnat.c:38
mask
vl_api_pnat_mask_t mask
Definition: pnat.api:45
src
vl_api_address_t src
Definition: gre.api:54
ip4_address_t
Definition: ip4_packet.h:50
pnat_main_t::msg_id_base
u16 msg_id_base
Definition: pnat.h:94
PNAT_INSTR_NONE
@ PNAT_INSTR_NONE
Definition: pnat.h:34
ip4_packet.h
pnat_binding_add
int pnat_binding_add(pnat_match_tuple_t *match, pnat_rewrite_tuple_t *rewrite, u32 *binding_index)
Definition: pnat.c:271
pnat_translation_t::post_dp
u16 post_dp
Definition: pnat.h:56
clib_bihash_kv_16_8_t
Definition: bihash_16_8.h:40
pnat_binding_attach
int pnat_binding_attach(u32 sw_if_index, pnat_attachment_point_t attachment, u32 binding_index)
Definition: pnat.c:329
pnat_translation_t
Definition: pnat.h:48
u64
unsigned long u64
Definition: types.h:89
pnat_translation_t::post_sp
u16 post_sp
Definition: pnat.h:55
clib_bihash_kv_16_8_t::key
u64 key[2]
Definition: bihash_16_8.h:42
pnat_interface_t
Definition: pnat.h:70
dport
u16 dport
Definition: pnat.api:44
u32
unsigned int u32
Definition: types.h:88
pnat_translation_t::instructions
pnat_instructions_t instructions
Definition: pnat.h:50
pnat_translation_t::clear_offset
u8 clear_offset
Definition: pnat.h:62
protocol
vl_api_ip_proto_t protocol
Definition: lb_types.api:72
dst
vl_api_ip4_address_t dst
Definition: pnat.api:41
PNAT_INSTR_CLEAR_BYTE
@ PNAT_INSTR_CLEAR_BYTE
Definition: pnat.h:40
as_u64
u64 as_u64
Definition: bihash_doc.h:63
pnat_main_t::flowhash
clib_bihash_16_8_t flowhash
Definition: pnat.h:85
bihash_16_8.h
pnat_binding_detach
int pnat_binding_detach(u32 sw_if_index, pnat_attachment_point_t attachment, u32 binding_index)
Definition: pnat.c:364
u8
unsigned char u8
Definition: types.h:56
PNAT_ATTACHMENT_POINT_MAX
@ PNAT_ATTACHMENT_POINT_MAX
Definition: pnat.api:35
pnat_translation_t::match
pnat_match_tuple_t match
Definition: pnat.h:65
PNAT_INSTR_DESTINATION_ADDRESS
@ PNAT_INSTR_DESTINATION_ADDRESS
Definition: pnat.h:37
pnat_trace_t
Definition: pnat.h:101
PNAT_INSTR_COPY_BYTE
@ PNAT_INSTR_COPY_BYTE
Definition: pnat.h:39
pnat_calc_key
static void pnat_calc_key(u32 sw_if_index, pnat_attachment_point_t attachment, ip4_address_t src, ip4_address_t dst, u8 protocol, u16 sport, u16 dport, pnat_mask_fast_t mask, clib_bihash_kv_16_8_t *kv)
Definition: pnat.h:118
pnat_main_t::interfaces
pnat_interface_t * interfaces
Definition: pnat.h:88
pnat_translation_t::post_da
ip4_address_t post_da
Definition: pnat.h:54
PNAT_INSTR_SOURCE_ADDRESS
@ PNAT_INSTR_SOURCE_ADDRESS
Definition: pnat.h:35
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
rewrite
rewrite
Definition: pnat.api:158
pnat_attachment_point_t
vl_api_pnat_attachment_point_t pnat_attachment_point_t
Definition: pnat.h:30
pnat_main
pnat_main_t pnat_main
Definition: pnat.c:32
pnat_main_t::enabled
bool enabled
Definition: pnat.h:83