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 = 1,
36 CNAT_SOURCE_ERROR_USE_DEFAULT = 2,
37 } cnat_source_policy_errors_t;
39 typedef struct cnat_src_port_allocator_
41 /* Source ports bitmap for snat */
44 /* Lock for src_ports access */
46 } cnat_src_port_allocator_t;
48 /* function to use to compute source (IP, port) for a new session to a vip */
49 typedef cnat_source_policy_errors_t (*cnat_vip_source_policy_t)
50 (vlib_main_t * vm, vlib_buffer_t * b, cnat_session_t * session,
51 u32 * rsession_flags, const cnat_translation_t * ct,
52 cnat_node_ctx_t * ctx);
54 typedef struct cnat_src_policy_main_
56 cnat_vip_source_policy_t vip_policy;
57 cnat_vip_source_policy_t default_policy;
59 /* Per proto source ports allocator for snat */
60 cnat_src_port_allocator_t *src_ports;
61 } cnat_src_policy_main_t;
63 extern cnat_src_policy_main_t cnat_src_policy_main;
65 void cnat_register_vip_src_policy (cnat_vip_source_policy_t fp);
66 int cnat_allocate_port (u16 * port, ip_protocol_t iproto);
67 void cnat_free_port (u16 port, ip_protocol_t iproto);
70 * fd.io coding-style-patch-verification: ON
73 * eval: (c-set-style "gnu")