nat: nat44 enable/disable dynamic config
[vpp.git] / src / plugins / nat / nat_ha.h
1 /*
2  * Copyright (c) 2019 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
17  * @brief NAT active-passive HA
18  */
19
20 #ifndef __included_nat_ha_h__
21 #define __included_nat_ha_h__
22
23 #include <vnet/vnet.h>
24 #include <vnet/ip/ip.h>
25
26 /* Call back functions for received HA events on passive/failover */
27 typedef void (*nat_ha_sadd_cb_t) (ip4_address_t * in_addr, u16 in_port,
28                                   ip4_address_t * out_addr, u16 out_port,
29                                   ip4_address_t * eh_addr, u16 eh_port,
30                                   ip4_address_t * ehn_addr, u16 ehn_port,
31                                   u8 proto, u32 fib_index, u16 flags,
32                                   u32 thread_index);
33 typedef void (*nat_ha_sdel_cb_t) (ip4_address_t * out_addr, u16 out_port,
34                                   ip4_address_t * eh_addr, u16 eh_port,
35                                   u8 proto, u32 fib_index, u32 thread_index);
36 typedef void (*nat_ha_sref_cb_t) (ip4_address_t * out_addr, u16 out_port,
37                                   ip4_address_t * eh_addr, u16 eh_port,
38                                   u8 proto, u32 fib_index, u32 total_pkts,
39                                   u64 total_bytes, u32 thread_index);
40
41 /**
42  * @brief Enable NAT HA, set callbacks
43  */
44 void nat_ha_enable (nat_ha_sadd_cb_t sadd_cb, nat_ha_sdel_cb_t sdel_cb,
45                     nat_ha_sref_cb_t sref_cb);
46
47 /**
48  * @brief Initialize NAT HA
49  */
50 void nat_ha_init (vlib_main_t * vm, u32 num_workers, u32 num_threads);
51
52 /**
53  * @brief Set HA listener (local settings)
54  *
55  * @param addr local IP4 address
56  * @param port local UDP port number
57  * @param path_mtu path MTU between local and failover
58  *
59  * @returns 0 on success, non-zero value otherwise.
60  */
61 int nat_ha_set_listener (ip4_address_t * addr, u16 port, u32 path_mtu);
62
63 /**
64  * @brief Get HA listener/local configuration
65  */
66 void nat_ha_get_listener (ip4_address_t * addr, u16 * port, u32 * path_mtu);
67
68 /**
69  * @brief Set HA failover (remote settings)
70  *
71  * @param addr failover IP4 address
72  * @param port failvoer UDP port number
73  * @param session_refresh_interval number of seconds after which to send
74  *                                 session counters refresh
75  *
76  * @returns 0 on success, non-zero value otherwise.
77  */
78 int nat_ha_set_failover (ip4_address_t * addr, u16 port,
79                          u32 session_refresh_interval);
80
81 /**
82  * @brief Get HA failover/remote settings
83  */
84 void nat_ha_get_failover (ip4_address_t * addr, u16 * port,
85                           u32 * session_refresh_interval);
86
87 /**
88  * @brief Create session add HA event
89  *
90  * @param in_addr inside IPv4 address
91  * @param in_port inside L4 port number
92  * @param out_addr outside IPv4 address
93  * @param out_port outside L4 port number
94  * @param eh_addr external host IPv4 address
95  * @param eh_port external host L4 port number
96  * @param ehn_addr external host IPv4 address after translation
97  * @param ehn_port external host L4 port number after translation
98  * @param proto L4 protocol
99  * @param fib_index fib index
100  * @param flags session flags
101  * @param thread_index thread index
102  * @param is_resync 1 if HA resync
103  */
104 void nat_ha_sadd (ip4_address_t * in_addr, u16 in_port,
105                   ip4_address_t * out_addr, u16 out_port,
106                   ip4_address_t * eh_addr, u16 eh_port,
107                   ip4_address_t * ehn_addr, u16 ehn_port, u8 proto,
108                   u32 fib_index, u16 flags, u32 thread_index, u8 is_resync);
109
110 /**
111  * @brief Create session delete HA event
112  *
113  * @param out_addr outside IPv4 address
114  * @param out_port outside L4 port number
115  * @param eh_addr external host IPv4 address
116  * @param eh_port external host L4 port number
117  * @param proto L4 protocol
118  * @param fib_index fib index
119  * @param thread_index thread index
120  */
121 void nat_ha_sdel (ip4_address_t * out_addr, u16 out_port,
122                   ip4_address_t * eh_addr, u16 eh_port, u8 proto,
123                   u32 fib_index, u32 thread_index);
124
125 /**
126  * @brief Create session refresh HA event
127  *
128  * @param out_addr outside IPv4 address
129  * @param out_port outside L4 port number
130  * @param eh_addr external host IPv4 address
131  * @param eh_port external host L4 port number
132  * @param proto L4 protocol
133  * @param fib_index fib index
134  * @param total_pkts total packets processed
135  * @param total_bytes total bytes processed
136  * @param thread_index thread index
137  * @param last_refreshed last session refresh time
138  * @param now current time
139  */
140 void nat_ha_sref (ip4_address_t * out_addr, u16 out_port,
141                   ip4_address_t * eh_addr, u16 eh_port, u8 proto,
142                   u32 fib_index, u32 total_pkts, u64 total_bytes,
143                   u32 thread_index, f64 * last_refreshed, f64 now);
144
145 /**
146  * @brief Flush the current HA data (for testing)
147  */
148 void nat_ha_flush (u8 is_resync);
149
150 typedef void (*nat_ha_resync_event_cb_t) (u32 client_index, u32 pid,
151                                           u32 missed_count);
152
153 /**
154  * @brief Resync HA (resend existing sessions to new failover)
155  */
156 int nat_ha_resync (u32 client_index, u32 pid,
157                    nat_ha_resync_event_cb_t event_callback);
158
159 /**
160  * @brief Get resync status
161  *
162  * @param in_resync 1 if resync in progress
163  * @param resync_ack_missed number of missed (not ACKed) messages
164  */
165 void nat_ha_get_resync_status (u8 * in_resync, u32 * resync_ack_missed);
166
167 #endif /* __included_nat_ha_h__ */
168
169 /*
170  * fd.io coding-style-patch-verification: ON
171  *
172  * Local Variables:
173  * eval: (c-set-style "gnu")
174  * End:
175  */