2 * Copyright (c) 2017 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #ifndef __included_nat64_db_h__
20 #define __included_nat64_db_h__
22 #include <vppinfra/bihash_24_8.h>
23 #include <vppinfra/bihash_48_8.h>
24 #include <snat/snat.h>
41 } nat64_db_bib_entry_key_t;
44 typedef CLIB_PACKED(struct
46 ip6_address_t in_addr;
48 ip4_address_t out_addr;
54 }) nat64_db_bib_entry_t;
61 #define _(N, i, n, s) \
62 nat64_db_bib_entry_t *_##n##_bib;
68 clib_bihash_24_8_t in2out;
69 clib_bihash_24_8_t out2in;
78 ip46_address_t l_addr;
79 ip46_address_t r_addr;
88 } nat64_db_st_entry_key_t;
91 typedef CLIB_PACKED(struct
93 ip6_address_t in_r_addr;
94 ip4_address_t out_r_addr;
100 }) nat64_db_st_entry_t;
107 #define _(N, i, n, s) \
108 nat64_db_st_entry_t *_##n##_st;
109 foreach_snat_protocol
114 clib_bihash_48_8_t in2out;
115 clib_bihash_48_8_t out2in;
125 * @brief Initialize NAT64 DB.
127 * @param db NAT64 DB.
129 * @returns 0 on success, non-zero value otherwise.
131 int nat64_db_init (nat64_db_t * db);
134 * @brief Create new NAT64 BIB entry.
136 * @param db NAT64 DB.
137 * @param in_addr Inside IPv6 address.
138 * @param out_addr Outside IPv4 address.
139 * @param in_port Inside port number.
140 * @param out_port Outside port number.
141 * @param fib_index FIB index.
142 * @param proto L4 protocol.
143 * @param is_static 1 if static, 0 if dynamic.
145 * @returns BIB entry on success, 0 otherwise.
147 nat64_db_bib_entry_t *nat64_db_bib_entry_create (nat64_db_t * db,
148 ip6_address_t * in_addr,
149 ip4_address_t * out_addr,
150 u16 in_port, u16 out_port,
152 snat_protocol_t proto,
156 * @brief Free NAT64 BIB entry.
158 * @param db NAT64 DB.
159 * @param bibe BIB entry.
161 void nat64_db_bib_entry_free (nat64_db_t * db, nat64_db_bib_entry_t * bibe);
164 * @brief Call back function when walking NAT64 BIB, non-zero
165 * return value stop walk.
167 typedef int (*nat64_db_bib_walk_fn_t) (nat64_db_bib_entry_t * bibe,
170 * @brief Walk NAT64 BIB.
172 * @param db NAT64 DB.
173 * @param proto BIB protocol (TCP/UDP/ICMP).
174 * @param fn The function to invoke on each entry visited.
175 * @param ctx A context passed in the visit function.
177 void nat64_db_bib_walk (nat64_db_t * db, snat_protocol_t proto,
178 nat64_db_bib_walk_fn_t fn, void *ctx);
181 * @brief Find NAT64 BIB entry.
183 * @param db NAT64 DB.
184 * @param addr IP address.
185 * @param port Port number.
186 * @param proto L4 protocol.
187 * @param fib_index FIB index.
188 * @param is_ip6 1 if find by IPv6 (inside) address, 0 by IPv4 (outside).
190 * @return BIB entry if found.
192 nat64_db_bib_entry_t *nat64_db_bib_entry_find (nat64_db_t * db,
193 ip46_address_t * addr,
195 snat_protocol_t proto,
196 u32 fib_index, u8 is_ip6);
199 * @brief Get BIB entry by index and protocol.
201 * @param db NAT64 DB.
202 * @param proto L4 protocol.
203 * @param bibe_index BIB entry index.
205 * @return BIB entry if found.
207 nat64_db_bib_entry_t *nat64_db_bib_entry_by_index (nat64_db_t * db,
208 snat_protocol_t proto,
211 * @brief Create new NAT64 session table entry.
213 * @param db NAT64 DB.
214 * @param bibe Corresponding BIB entry.
215 * @param in_r_addr Inside IPv6 address of the remote host.
216 * @param out_r_addr Outside IPv4 address of the remote host.
217 * @param r_port Remote host port number.
219 * @returns BIB entry on success, 0 otherwise.
221 nat64_db_st_entry_t *nat64_db_st_entry_create (nat64_db_t * db,
222 nat64_db_bib_entry_t * bibe,
223 ip6_address_t * in_r_addr,
224 ip4_address_t * out_r_addr,
228 * @brief Free NAT64 session table entry.
230 * @param db NAT64 DB.
231 * @param ste Session table entry.
233 void nat64_db_st_entry_free (nat64_db_t * db, nat64_db_st_entry_t * ste);
236 * @brief Find NAT64 session table entry.
238 * @param db NAT64 DB.
239 * @param l_addr Local host address.
240 * @param r_addr Remote host address.
241 * @param l_port Local host port number.
242 * @param r_port Remote host port number.
243 * @param proto L4 protocol.
244 * @param fib_index FIB index.
245 * @param is_ip6 1 if find by IPv6 (inside) address, 0 by IPv4 (outside).
247 * @return BIB entry if found.
249 nat64_db_st_entry_t *nat64_db_st_entry_find (nat64_db_t * db,
250 ip46_address_t * l_addr,
251 ip46_address_t * r_addr,
252 u16 l_port, u16 r_port,
253 snat_protocol_t proto,
254 u32 fib_index, u8 is_ip6);
257 * @brief Call back function when walking NAT64 session table, non-zero
258 * return value stop walk.
260 typedef int (*nat64_db_st_walk_fn_t) (nat64_db_st_entry_t * ste, void *ctx);
263 * @brief Walk NAT64 session table.
265 * @param db NAT64 DB.
266 * @param proto Session table protocol (TCP/UDP/ICMP).
267 * @param fn The function to invoke on each entry visited.
268 * @param ctx A context passed in the visit function.
270 void nat64_db_st_walk (nat64_db_t * db, snat_protocol_t proto,
271 nat64_db_st_walk_fn_t fn, void *ctx);
274 * @brief Free expired session entries in session tables.
276 * @param db NAT64 DB.
277 * @param now Current time.
279 void nad64_db_st_free_expired (nat64_db_t * db, u32 now);
281 #endif /* __included_nat64_db_h__ */
284 * fd.io coding-style-patch-verification: ON
287 * eval: (c-set-style "gnu")