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:
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.
17 * @brief NAT port/address allocation lib
20 #ifndef included_nat_lib_alloc_h__
21 #define included_nat_lib_alloc_h__
23 #include <vnet/ip/ip.h>
24 #include <nat/lib/nat_proto.h>
26 typedef struct nat_ip4_pool_addr_s nat_ip4_pool_addr_t;
27 typedef struct nat_ip4_addr_port_s nat_ip4_addr_port_t;
28 typedef struct nat_ip4_pool_s nat_ip4_pool_t;
30 typedef void (nat_add_del_ip4_pool_addr_cb_t) (ip4_address_t addr,
31 u8 is_add, void *opaque);
33 typedef int (nat_alloc_ip4_addr_and_port_cb_t) (nat_ip4_pool_t * pool,
39 nat_ip4_addr_port_t * out);
41 struct nat_ip4_pool_addr_s
46 #define _(N, i, n, s) \
47 u16 busy_##n##_ports; \
48 u16 * busy_##n##_ports_per_thread; \
49 uword * busy_##n##_port_bitmap;
55 struct nat_ip4_addr_port_s
63 nat_add_del_ip4_pool_addr_cb_t *add_del_pool_addr_cb;
64 nat_alloc_ip4_addr_and_port_cb_t *alloc_addr_and_port_cb;
65 nat_ip4_pool_addr_t *pool_addr;
70 nat_add_del_ip4_pool_addr (nat_ip4_pool_t * pool,
71 ip4_address_t addr, u8 is_add);
74 nat_add_del_ip4_pool_addrs (nat_ip4_pool_t * pool,
76 u32 count, u8 is_add, void *opaque);
79 nat_alloc_ip4_addr_and_port_cb_default (nat_ip4_pool_t * pool,
85 nat_ip4_addr_port_t * out);
88 nat_alloc_ip4_addr_and_port (nat_ip4_pool_t * pool,
93 u16 protocol, nat_ip4_addr_port_t * out);
96 nat_free_ip4_addr_and_port (nat_ip4_pool_t * pool,
98 u16 protocol, nat_ip4_addr_port_t * in);
100 #endif /* included_nat_lib_alloc_h__ */
103 * fd.io coding-style-patch-verification: ON
106 * eval: (c-set-style "gnu")