FD.io VPP  v21.01.1
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/bihash_40_48.h>
24 
25 
26 /**
27  * A session represents the memory of a translation.
28  * In the tx direction (from behind to in front of the NAT), the
29  * session is preserved so subsequent packets follow the same path
30  * even if the translation has been updated. In the tx direction
31  * the session represents the swap from the VIP to the server address
32  * In the RX direction the swap is from the server address/port to VIP.
33  *
34  * A session exists only as key and value in the bihash, there is no
35  * pool for this object. If there were a pool, one would need to be
36  * concerned about what worker is using it.
37  */
38 typedef struct cnat_session_t_
39 {
40  /**
41  * this key sits in the same memory location a 'key' in the bihash kvp
42  */
43  struct
44  {
45  /**
46  * IP 4/6 address in the rx/tx direction
47  */
48  ip46_address_t cs_ip[VLIB_N_DIR];
49 
50  /**
51  * ports in rx/tx
52  */
54 
55  /**
56  * The IP protocol TCP or UDP only supported
57  */
59 
60  /**
61  * The address family describing the IP addresses
62  */
64 
65  /**
66  * spare space
67  */
68  u8 __cs_pad[2];
69  } key;
70  /**
71  * this value sits in the same memory location a 'value' in the bihash kvp
72  */
73  struct
74  {
75  /**
76  * The IP address to translate to.
77  */
78  ip46_address_t cs_ip[VLIB_N_DIR];
79 
80  /**
81  * the port to translate to.
82  */
84 
85  /**
86  * The load balance object to use to forward
87  */
89 
90  /**
91  * Timestamp index this session was last used
92  */
94 
95  union
96  {
97  /**
98  * session flags if cs_lbi == INDEX_INVALID
99  */
101  /**
102  * Persist translation->ct_lb.dpoi_next_node
103  * when cs_lbi != INDEX_INVALID
104  */
106  };
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  */
126 
127 extern u8 *format_cnat_session (u8 * s, va_list * args);
128 
129 /**
130  * Ensure the session object correctly overlays the bihash key/value pair
131  */
134  "key overlaps");
137  "value overlaps");
139  "session kvp");
140 
141 /**
142  * The DB of sessions
143  */
144 extern clib_bihash_40_48_t cnat_session_db;
145 
146 /**
147  * Callback function invoked during a walk of all translations
148  */
150  session, void *ctx);
151 
152 /**
153  * Walk/visit each of the cnat session
154  */
155 extern void cnat_session_walk (cnat_session_walk_cb_t cb, void *ctx);
156 
157 /**
158  * Scan the session DB for expired sessions
159  */
160 extern u64 cnat_session_scan (vlib_main_t * vm, f64 start_time, int i);
161 
162 /**
163  * Purge all the sessions
164  */
165 extern int cnat_session_purge (void);
166 
167 /**
168  * Free a session & update refcounts
169  */
170 extern void cnat_session_free (cnat_session_t * session);
171 
172 /**
173  * Port cleanup callback
174  */
175 extern void (*cnat_free_port_cb) (u16 port, ip_protocol_t iproto);
176 
177 /*
178  * fd.io coding-style-patch-verification: ON
179  *
180  * Local Variables:
181  * eval: (c-set-style "gnu")
182  * End:
183  */
184 
185 #endif
This session source port was allocated, free it on cleanup.
Definition: cnat_session.h:120
This session doesn&#39;t have a client, do not attempt to free it.
Definition: cnat_session.h:124
unsigned long u64
Definition: types.h:89
struct cnat_session_t_::@632 key
this key sits in the same memory location a &#39;key&#39; in the bihash kvp
u16 cs_port[VLIB_N_DIR]
ports in rx/tx
Definition: cnat_session.h:53
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:41
#define STRUCT_OFFSET_OF(t, f)
Definition: clib.h:70
vlib_main_t * vm
Definition: in2out_ed.c:1580
unsigned char u8
Definition: types.h:56
double f64
Definition: types.h:142
A session represents the memory of a translation.
Definition: cnat_session.h:38
enum walk_rc_t_ walk_rc_t
Walk return code.
u8 cs_af
The address family describing the IP addresses.
Definition: cnat_session.h:63
STATIC_ASSERT(STRUCT_OFFSET_OF(cnat_session_t, key)==STRUCT_OFFSET_OF(clib_bihash_kv_40_48_t, key), "key overlaps")
Ensure the session object correctly overlays the bihash key/value pair.
cnat_session_flag_t_
Definition: cnat_session.h:110
unsigned int u32
Definition: types.h:88
ip46_address_t cs_ip[VLIB_N_DIR]
IP 4/6 address in the rx/tx direction.
Definition: cnat_session.h:48
u32 cs_ts_index
Timestamp index this session was last used.
Definition: cnat_session.h:93
Indicates a return path session that was source NATed on the way in.
Definition: cnat_session.h:116
enum ip_protocol ip_protocol_t
long ctx[MAX_CONNS]
Definition: main.c:144
void cnat_session_free(cnat_session_t *session)
Free a session & update refcounts.
Definition: cnat_session.c:127
unsigned short u16
Definition: types.h:57
int cnat_session_purge(void)
Purge all the sessions.
Definition: cnat_session.c:142
u32 ct_index
Persist translation->ct_lb.dpoi_next_node when cs_lbi != INDEX_INVALID.
Definition: cnat_session.h:105
index_t cs_lbi
The load balance object to use to forward.
Definition: cnat_session.h:88
u8 * format_cnat_session(u8 *s, va_list *args)
Definition: cnat_session.c:71
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
u64 cnat_session_scan(vlib_main_t *vm, f64 start_time, int i)
Scan the session DB for expired sessions.
Definition: cnat_session.c:159
u32 flags
session flags if cs_lbi == INDEX_INVALID
Definition: cnat_session.h:100
#define VLIB_N_DIR
Definition: defs.h:57
struct cnat_session_t_ cnat_session_t
A session represents the memory of a translation.
void cnat_session_walk(cnat_session_walk_cb_t cb, void *ctx)
Walk/visit each of the cnat session.
Definition: cnat_session.c:45
ip_protocol_t cs_proto
The IP protocol TCP or UDP only supported.
Definition: cnat_session.h:58
clib_bihash_40_48_t cnat_session_db
The DB of sessions.
Definition: cnat_session.c:24
void(* cnat_free_port_cb)(u16 port, ip_protocol_t iproto)
Port cleanup callback.
Definition: cnat_session.c:25
u16 port
Definition: lb_types.api:73
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:149
enum cnat_session_flag_t_ cnat_session_flag_t
struct cnat_session_t_::@633 value
this value sits in the same memory location a &#39;value&#39; in the bihash kvp