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.
16 #ifndef __CNAT_SRC_POLICY_H__
17 #define __CNAT_SRC_POLICY_H__
19 // #include <vnet/udp/udp.h>
20 #include <cnat/cnat_types.h>
21 #include <cnat/cnat_session.h>
22 #include <cnat/cnat_translation.h>
28 CNAT_SPORT_PROTO_ICMP,
29 CNAT_SPORT_PROTO_ICMP6,
33 typedef enum cnat_source_policy_errors_
35 CNAT_SOURCE_ERROR_EXHAUSTED_PORTS,
36 CNAT_SOURCE_ERROR_USE_DEFAULT,
38 } cnat_source_policy_errors_t;
40 typedef struct cnat_src_port_allocator_
42 /* Source ports bitmap for snat */
45 /* Lock for src_ports access */
47 } cnat_src_port_allocator_t;
49 /* function to use to compute source (IP, port) for a new session to a vip */
50 typedef cnat_source_policy_errors_t (*cnat_vip_source_policy_t)
51 (vlib_main_t * vm, vlib_buffer_t * b, cnat_session_t * session,
52 u32 * rsession_flags, const cnat_translation_t * ct,
53 cnat_node_ctx_t * ctx);
55 typedef struct cnat_src_policy_main_
57 cnat_vip_source_policy_t vip_policy;
58 cnat_vip_source_policy_t default_policy;
60 /* Per proto source ports allocator for snat */
61 cnat_src_port_allocator_t *src_ports;
62 } cnat_src_policy_main_t;
64 extern cnat_src_policy_main_t cnat_src_policy_main;
66 void cnat_register_vip_src_policy (cnat_vip_source_policy_t fp);
67 int cnat_allocate_port (u16 * port, ip_protocol_t iproto);
68 void cnat_free_port (u16 port, ip_protocol_t iproto);
71 * fd.io coding-style-patch-verification: ON
74 * eval: (c-set-style "gnu")