FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
cnat_session.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 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 __CNAT_SESSION_H__
17 #define __CNAT_SESSION_H__
18 
19 #include <vnet/udp/udp_packet.h>
20 
21 #include <cnat/cnat_types.h>
22 #include <cnat/cnat_client.h>
23 #include <cnat/cnat_bihash.h>
24 
25 /**
26  * A session represents the memory of a translation.
27  * In the tx direction (from behind to in front of the NAT), the
28  * session is preserved so subsequent packets follow the same path
29  * even if the translation has been updated. In the tx direction
30  * the session represents the swap from the VIP to the server address
31  * In the RX direction the swap is from the server address/port to VIP.
32  *
33  * A session exists only as key and value in the bihash, there is no
34  * pool for this object. If there were a pool, one would need to be
35  * concerned about what worker is using it.
36  */
37 typedef struct cnat_session_t_
38 {
39  /**
40  * this key sits in the same memory location a 'key' in the bihash kvp
41  */
42  struct
43  {
44  /**
45  * IP 4/6 address in the rx/tx direction
46  */
47  ip46_address_t cs_ip[VLIB_N_DIR];
48 
49  /**
50  * ports in rx/tx
51  */
53 
54  /**
55  * The IP protocol TCP or UDP only supported
56  */
58 
59  /**
60  * The address family describing the IP addresses
61  */
63 
64  /**
65  * input / output / fib session
66  */
68 
69  u8 __cs_pad;
70  } key;
71  /**
72  * this value sits in the same memory location a 'value' in the bihash kvp
73  */
74  struct
75  {
76  /**
77  * The IP address to translate to.
78  */
79  ip46_address_t cs_ip[VLIB_N_DIR];
80 
81  /**
82  * the port to translate to.
83  */
85 
86  /**
87  * The load balance object to use to forward
88  */
90 
91  /**
92  * Persist translation->ct_lb.dpoi_next_node
93  */
95 
96  /**
97  * Timestamp index this session was last used
98  */
100 
101  /**
102  * session flags
103  */
105 
106  u32 __pad;
107  } value;
109 
111 {
112  /**
113  * Indicates a return path session that was source NATed
114  * on the way in.
115  */
117  /**
118  * This session source port was allocated, free it on cleanup
119  */
121  /**
122  * This session doesn't have a client, do not attempt to free it
123  */
125 
126  /* Do not actually translate the packet but still forward it
127  * Used for Maglev, with an encap */
129 
130  /* Debug flag marking return sessions */
133 
135 {
140 
141 extern u8 *format_cnat_session (u8 * s, va_list * args);
142 
143 /**
144  * Ensure the session object correctly overlays the bihash key/value pair
145  */
148  "key overlaps");
151  "value overlaps");
152 STATIC_ASSERT (sizeof (cnat_session_t) == sizeof (cnat_bihash_kv_t),
153  "session kvp");
154 
155 /**
156  * The DB of sessions
157  */
159 
160 /**
161  * Callback function invoked during a walk of all translations
162  */
164  session, void *ctx);
165 
166 /**
167  * Walk/visit each of the cnat session
168  */
169 extern void cnat_session_walk (cnat_session_walk_cb_t cb, void *ctx);
170 
171 /**
172  * Scan the session DB for expired sessions
173  */
174 extern u64 cnat_session_scan (vlib_main_t * vm, f64 start_time, int i);
175 
176 /**
177  * Purge all the sessions
178  */
179 extern int cnat_session_purge (void);
180 
181 /**
182  * Free a session & update refcounts
183  */
184 extern void cnat_session_free (cnat_session_t * session);
185 
186 /**
187  * Port cleanup callback
188  */
189 extern void (*cnat_free_port_cb) (u16 port, ip_protocol_t iproto);
190 
191 /*
192  * fd.io coding-style-patch-verification: ON
193  *
194  * Local Variables:
195  * eval: (c-set-style "gnu")
196  * End:
197  */
198 
199 #endif
cnat_bihash_t
clib_bihash_40_56_t cnat_bihash_t
Definition: cnat_bihash.h:107
cnat_session_t_::cs_ip
ip46_address_t cs_ip[VLIB_N_DIR]
IP 4/6 address in the rx/tx direction.
Definition: cnat_session.h:47
cnat_session_t_::cs_lbi
index_t cs_lbi
The load balance object to use to forward.
Definition: cnat_session.h:89
CNAT_SESSION_FLAG_NO_CLIENT
@ CNAT_SESSION_FLAG_NO_CLIENT
This session doesn't have a client, do not attempt to free it.
Definition: cnat_session.h:124
clib_bihash_kv_40_56_t
Definition: cnat_bihash.h:41
u16
unsigned short u16
Definition: types.h:57
CNAT_LOCATION_INPUT
@ CNAT_LOCATION_INPUT
Definition: cnat_session.h:136
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
cnat_session_t
struct cnat_session_t_ cnat_session_t
A session represents the memory of a translation.
cnat_session_t_::dpoi_next_node
u32 dpoi_next_node
Persist translation->ct_lb.dpoi_next_node.
Definition: cnat_session.h:94
port
u16 port
Definition: lb_types.api:73
cnat_session_t_
A session represents the memory of a translation.
Definition: cnat_session.h:37
cnat_session_t_::key
struct cnat_session_t_::@645 key
this key sits in the same memory location a 'key' in the bihash kvp
cnat_session_t_::cs_af
u8 cs_af
The address family describing the IP addresses.
Definition: cnat_session.h:62
cnat_session_location_t_
cnat_session_location_t_
Definition: cnat_session.h:134
cnat_session_free
void cnat_session_free(cnat_session_t *session)
Free a session & update refcounts.
Definition: cnat_session.c:144
key
typedef key
Definition: ipsec_types.api:91
cnat_types.h
STRUCT_OFFSET_OF
#define STRUCT_OFFSET_OF(t, f)
Definition: clib.h:73
index_t
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:43
CNAT_SESSION_FLAG_HAS_SNAT
@ CNAT_SESSION_FLAG_HAS_SNAT
Indicates a return path session that was source NATed on the way in.
Definition: cnat_session.h:116
udp_packet.h
cnat_session_purge
int cnat_session_purge(void)
Purge all the sessions.
Definition: cnat_session.c:159
cnat_session_flag_t_
cnat_session_flag_t_
Definition: cnat_session.h:110
f64
double f64
Definition: types.h:142
cnat_session_db
cnat_bihash_t cnat_session_db
The DB of sessions.
Definition: cnat_session.c:23
STATIC_ASSERT
STATIC_ASSERT(STRUCT_OFFSET_OF(cnat_session_t, key)==STRUCT_OFFSET_OF(cnat_bihash_kv_t, key), "key overlaps")
Ensure the session object correctly overlays the bihash key/value pair.
cnat_session_t_::cs_ts_index
u32 cs_ts_index
Timestamp index this session was last used.
Definition: cnat_session.h:99
cnat_session_t_::cs_proto
ip_protocol_t cs_proto
The IP protocol TCP or UDP only supported.
Definition: cnat_session.h:57
format_cnat_session
u8 * format_cnat_session(u8 *s, va_list *args)
Definition: cnat_session.c:92
cnat_session_location_t
enum cnat_session_location_t_ cnat_session_location_t
cnat_session_t_::cs_loc
u8 cs_loc
input / output / fib session
Definition: cnat_session.h:67
cnat_session_t_::flags
u32 flags
session flags
Definition: cnat_session.h:104
u64
unsigned long u64
Definition: types.h:89
cnat_session_scan
u64 cnat_session_scan(vlib_main_t *vm, f64 start_time, int i)
Scan the session DB for expired sessions.
Definition: cnat_session.c:176
CNAT_SESSION_FLAG_NO_NAT
@ CNAT_SESSION_FLAG_NO_NAT
Definition: cnat_session.h:128
cnat_free_port_cb
void(* cnat_free_port_cb)(u16 port, ip_protocol_t iproto)
Port cleanup callback.
Definition: cnat_session.c:24
cnat_session_walk_cb_t
walk_rc_t(* cnat_session_walk_cb_t)(const cnat_session_t *session, void *ctx)
Callback function invoked during a walk of all translations.
Definition: cnat_session.h:163
u32
unsigned int u32
Definition: types.h:88
CNAT_SESSION_IS_RETURN
@ CNAT_SESSION_IS_RETURN
Definition: cnat_session.h:131
CNAT_SESSION_FLAG_ALLOC_PORT
@ CNAT_SESSION_FLAG_ALLOC_PORT
This session source port was allocated, free it on cleanup.
Definition: cnat_session.h:120
cnat_session_flag_t
enum cnat_session_flag_t_ cnat_session_flag_t
cnat_session_walk
void cnat_session_walk(cnat_session_walk_cb_t cb, void *ctx)
Walk/visit each of the cnat session.
Definition: cnat_session.c:44
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
cnat_client.h
value
u8 value
Definition: qos.api:54
VLIB_N_DIR
#define VLIB_N_DIR
Definition: defs.h:57
ip_protocol_t
enum ip_protocol ip_protocol_t
vlib_main_t
Definition: main.h:102
CNAT_LOCATION_OUTPUT
@ CNAT_LOCATION_OUTPUT
Definition: cnat_session.h:137
u8
unsigned char u8
Definition: types.h:56
i
int i
Definition: flowhash_template.h:376
cnat_session_t_::value
struct cnat_session_t_::@646 value
this value sits in the same memory location a 'value' in the bihash kvp
CNAT_LOCATION_FIB
@ CNAT_LOCATION_FIB
Definition: cnat_session.h:138
cnat_bihash.h
walk_rc_t
enum walk_rc_t_ walk_rc_t
Walk return code.
cnat_session_t_::cs_port
u16 cs_port[VLIB_N_DIR]
ports in rx/tx
Definition: cnat_session.h:52