3 * snat.h - simple nat definitions
5 * Copyright (c) 2016 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 #ifndef __included_snat_h__
19 #define __included_snat_h__
21 #include <vnet/vnet.h>
22 #include <vnet/ip/ip.h>
23 #include <vnet/ethernet/ethernet.h>
24 #include <vnet/ip/icmp46_packet.h>
25 #include <vnet/api_errno.h>
26 #include <vppinfra/bihash_8_8.h>
27 #include <vppinfra/dlist.h>
28 #include <vppinfra/error.h>
29 #include <vlibapi/api.h>
60 SNAT_PROTOCOL_UDP = 0,
66 typedef CLIB_PACKED(struct {
67 snat_session_key_t out2in; /* 0-15 */
69 snat_session_key_t in2out; /* 16-31 */
71 u32 flags; /* 32-35 */
73 /* per-user translations */
74 u32 per_user_index; /* 36-39 */
76 u32 per_user_list_head_index; /* 40-43 */
78 /* Last heard timer */
79 f64 last_heard; /* 44-51 */
81 u64 total_bytes; /* 52-59 */
83 u32 total_pkts; /* 60-63 */
86 u32 outside_address_index; /* 64-67 */
90 #define SNAT_SESSION_STATIC (1<<0)
94 u32 sessions_per_user_list_head_index;
101 uword * busy_port_bitmap;
105 /* Main lookup tables */
106 clib_bihash_8_8_t out2in;
107 clib_bihash_8_8_t in2out;
109 /* Find-a-user => src address lookup */
110 clib_bihash_8_8_t user_hash;
116 snat_session_t * sessions;
118 /* Vector of outside addresses */
119 snat_address_t * addresses;
121 /* Pool of doubly-linked list elements */
122 dlist_elt_t * list_pool;
124 /* Randomize port allocation order */
127 /* ip4 feature path indices */
128 u32 rx_feature_in2out;
129 u32 rx_feature_out2in;
131 /* Config parameters */
132 u32 translation_buckets;
133 u32 translation_memory_size;
135 u32 user_memory_size;
136 u32 max_translations_per_user;
138 u32 outside_fib_index;
140 /* API message ID base */
144 vlib_main_t * vlib_main;
145 vnet_main_t * vnet_main;
146 ip4_main_t * ip4_main;
147 ip_lookup_main_t * ip4_lookup_main;
148 ethernet_main_t * ethernet_main;
149 api_main_t * api_main;
152 extern snat_main_t snat_main;
153 extern vlib_node_registration_t snat_in2out_node;
154 extern vlib_node_registration_t snat_out2in_node;
156 void snat_free_outside_address_and_port (snat_main_t * sm,
157 snat_session_key_t * k,
160 int snat_alloc_outside_address_and_port (snat_main_t * sm,
161 snat_session_key_t * k,
162 u32 * address_indexp);
163 format_function_t format_snat_user;
166 u32 cached_sw_if_index;
167 u32 cached_ip4_address;
171 * Why is this here? Because we don't need to touch this layer to
172 * simply reply to an icmp. We need to change id to a unique
173 * value to NAT an echo request/reply.
179 } icmp_echo_header_t;
181 #endif /* __included_snat_h__ */