nat: refactor and split fo EI/ED features p.2
[vpp.git] / src / plugins / nat / nat44-ei / nat44_ei.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  * @file nat44_ei.h
17  * NAT44 endpoint independent plugin declarations
18  */
19 #ifndef __included_nat44_ei_h__
20 #define __included_nat44_ei_h__
21
22 typedef struct
23 {
24   /* maximum number of users */
25   u32 users;
26   /* maximum number of sessions */
27   u32 sessions;
28   /* maximum number of ssessions per user */
29   u32 user_sessions;
30
31   /* plugin features */
32   u8 static_mapping_only;
33   u8 connection_tracking;
34   u8 out2in_dpo;
35
36   u32 inside_vrf;
37   u32 outside_vrf;
38
39 } nat44_ei_config_t;
40
41 typedef struct
42 {
43   u32 translations;
44   u32 translation_buckets;
45   u32 user_buckets;
46
47   nat44_ei_config_t rconfig;
48
49 } nat44_ei_main_t;
50
51 int nat44_ei_plugin_enable (nat44_ei_config_t c);
52
53 int nat44_ei_plugin_disable ();
54
55 /**
56  * @brief Delete specific NAT44 EI user and his sessions
57  *
58  * @param addr         IPv4 address
59  * @param fib_index    FIB table index
60  */
61 int nat44_ei_user_del (ip4_address_t *addr, u32 fib_index);
62
63 /**
64  * @brief Delete session for static mapping
65  *
66  * @param addr         IPv4 address
67  * @param fib_index    FIB table index
68  */
69 void nat44_ei_static_mapping_del_sessions (snat_main_t *sm,
70                                            snat_main_per_thread_data_t *tsm,
71                                            snat_user_key_t u_key,
72                                            int addr_only, ip4_address_t e_addr,
73                                            u16 e_port);
74
75 u32 nat44_ei_get_in2out_worker_index (ip4_header_t *ip0, u32 rx_fib_index0,
76                                       u8 is_output);
77
78 u32 nat44_ei_get_out2in_worker_index (vlib_buffer_t *b, ip4_header_t *ip0,
79                                       u32 rx_fib_index0, u8 is_output);
80
81 /**
82  * @brief Set address and port assignment algorithm to default/standard
83  */
84 void nat44_ei_set_alloc_default (void);
85
86 /**
87  * @brief Set address and port assignment algorithm for MAP-E CE
88  *
89  * @param psid        Port Set Identifier value
90  * @param psid_offset number of offset bits
91  * @param psid_length length of PSID
92  */
93 void nat44_ei_set_alloc_mape (u16 psid, u16 psid_offset, u16 psid_length);
94
95 /**
96  * @brief Set address and port assignment algorithm for port range
97  *
98  * @param start_port beginning of the port range
99  * @param end_port   end of the port range
100  */
101 void nat44_ei_set_alloc_range (u16 start_port, u16 end_port);
102
103 /**
104  * @brief Add/delete NAT44-EI static mapping
105  *
106  * @param l_addr       local IPv4 address
107  * @param e_addr       external IPv4 address
108  * @param l_port       local port number
109  * @param e_port       external port number
110  * @param proto        L4 protocol
111  * @param sw_if_index  use interface address as external IPv4 address
112  * @param vrf_id       local VRF ID
113  * @param addr_only    1 = 1:1NAT, 0 = 1:1NAPT
114  * @param identity_nat identity NAT
115  * @param tag opaque   string tag
116  * @param is_add       1 = add, 0 = delete
117  *
118  * @return 0 on success, non-zero value otherwise
119
120  */
121 int nat44_ei_add_del_static_mapping (ip4_address_t l_addr,
122                                      ip4_address_t e_addr, u16 l_port,
123                                      u16 e_port, nat_protocol_t proto,
124                                      u32 sw_if_index, u32 vrf_id, u8 addr_only,
125                                      u8 identity_nat, u8 *tag, u8 is_add);
126
127 /**
128  * @brief Delete NAT44-EI session
129  *
130  * @param addr   IPv4 address
131  * @param port   L4 port number
132  * @param proto  L4 protocol
133  * @param vrf_id VRF ID
134  * @param is_in  1 = inside network address and port pair, 0 = outside
135  *
136  * @return 0 on success, non-zero value otherwise
137  */
138 int nat44_ei_del_session (snat_main_t *sm, ip4_address_t *addr, u16 port,
139                           nat_protocol_t proto, u32 vrf_id, int is_in);
140
141 /**
142  * @brief Match NAT44-EI static mapping.
143  *
144  * @param key             address and port to match
145  * @param addr            external/local address of the matched mapping
146  * @param port            port of the matched mapping
147  * @param fib_index       fib index of the matched mapping
148  * @param by_external     if 0 match by local address otherwise match by
149  * external address
150  * @param is_addr_only    1 if matched mapping is address only
151  * @param is_identity_nat 1 if indentity mapping
152  *
153  * @returns 0 if match found otherwise 1.
154  */
155 int nat44_ei_static_mapping_match (ip4_address_t match_addr, u16 match_port,
156                                    u32 match_fib_index,
157                                    nat_protocol_t match_protocol,
158                                    ip4_address_t *mapping_addr,
159                                    u16 *mapping_port, u32 *mapping_fib_index,
160                                    u8 by_external, u8 *is_addr_only,
161                                    u8 *is_identity_nat);
162
163 /**
164  * @brief Clear all active NAT44-EI sessions.
165  */
166 void nat44_ei_sessions_clear ();
167
168 #endif /* __included_nat44_ei_h__ */
169 /*
170  * fd.io coding-style-patch-verification: ON
171  *
172  * Local Variables:
173  * eval: (c-set-style "gnu")
174  * End:
175  */