session: remove ipv6 lookup threading assert
[vpp.git] / src / plugins / cnat / cnat_snat_policy.h
1 /*
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:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15
16 #ifndef __CNAT_SNAT_H__
17 #define __CNAT_SNAT_H__
18
19 #include <cnat/cnat_types.h>
20 #include <cnat/cnat_session.h>
21
22 /* function to use to decide whether to snat connections in the output
23  * feature. Returns 1 if we should source NAT */
24 typedef int (*cnat_snat_policy_t) (vlib_buffer_t *b, cnat_session_t *session);
25
26 typedef struct cnat_snat_pfx_table_meta_t_
27 {
28   u32 dst_address_length_refcounts[129];
29   u16 *prefix_lengths_in_search_order;
30   uword *non_empty_dst_address_length_bitmap;
31 } cnat_snat_pfx_table_meta_t;
32
33 typedef struct cnat_snat_exclude_pfx_table_t_
34 {
35   /* Stores (ip family, prefix & mask) */
36   clib_bihash_24_8_t ip_hash;
37   /* family dependant cache */
38   cnat_snat_pfx_table_meta_t meta[2];
39   /* Precomputed ip masks (ip4 & ip6) */
40   ip6_address_t ip_masks[129];
41 } cnat_snat_exclude_pfx_table_t;
42
43 typedef enum cnat_snat_interface_map_type_t_
44 {
45   CNAT_SNAT_IF_MAP_INCLUDE_V4 = AF_IP4,
46   CNAT_SNAT_IF_MAP_INCLUDE_V6 = AF_IP6,
47   CNAT_SNAT_IF_MAP_INCLUDE_POD,
48   /* CNAT_SNAT_IF_MAP_INCLUDE_HOST is used for interfaces used for punt,
49      replicating uplink */
50   CNAT_SNAT_IF_MAP_INCLUDE_HOST,
51   CNAT_N_SNAT_IF_MAP,
52 } cnat_snat_interface_map_type_t;
53
54 typedef enum cnat_snat_policy_type_t_
55 {
56   CNAT_SNAT_POLICY_NONE = 0,
57   CNAT_SNAT_POLICY_IF_PFX = 1,
58   CNAT_SNAT_POLICY_K8S = 2,
59 } cnat_snat_policy_type_t;
60
61 typedef struct cnat_snat_policy_main_t_
62 {
63   /* Longest prefix Match table for source NATing */
64   cnat_snat_exclude_pfx_table_t excluded_pfx;
65
66   /* interface maps including or excluding sw_if_indexes  */
67   clib_bitmap_t *interface_maps[CNAT_N_SNAT_IF_MAP];
68
69   /* SNAT policy for the output feature node */
70   cnat_snat_policy_t snat_policy;
71
72   /* Ip4 Address to use for source NATing */
73   cnat_endpoint_t snat_ip4;
74
75   /* Ip6 Address to use for source NATing */
76   cnat_endpoint_t snat_ip6;
77
78 } cnat_snat_policy_main_t;
79
80 extern cnat_snat_policy_main_t cnat_snat_policy_main;
81
82 extern void cnat_set_snat (ip4_address_t *ip4, ip6_address_t *ip6,
83                            u32 sw_if_index);
84 extern int cnat_snat_policy_add_pfx (ip_prefix_t *pfx);
85 extern int cnat_snat_policy_del_pfx (ip_prefix_t *pfx);
86 extern int cnat_set_snat_policy (cnat_snat_policy_type_t policy);
87 extern int cnat_snat_policy_add_del_if (u32 sw_if_index, u8 is_add,
88                                         cnat_snat_interface_map_type_t table);
89
90 int cnat_search_snat_prefix (ip46_address_t *addr, ip_address_family_t af);
91
92 /*
93  * fd.io coding-style-patch-verification: ON
94  *
95  * Local Variables:
96  * eval: (c-set-style "gnu")
97  * End:
98  */
99
100 #endif