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:
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.
17 * @brief NAT active-passive HA
20 #ifndef __included_nat_ha_h__
21 #define __included_nat_ha_h__
23 #include <vnet/vnet.h>
24 #include <vnet/ip/ip.h>
27 /* Call back functions for received HA events on passive/failover */
28 typedef void (*nat_ha_sadd_cb_t) (ip4_address_t * in_addr, u16 in_port,
29 ip4_address_t * out_addr, u16 out_port,
30 ip4_address_t * eh_addr, u16 eh_port,
31 ip4_address_t * ehn_addr, u16 ehn_port,
32 u8 proto, u32 fib_index, u16 flags,
35 typedef void (*nat_ha_sdel_cb_t) (ip4_address_t * out_addr, u16 out_port,
36 ip4_address_t * eh_addr, u16 eh_port,
37 u8 proto, u32 fib_index, u32 thread_index);
38 typedef void (*nat_ha_sref_cb_t) (ip4_address_t * out_addr, u16 out_port,
39 ip4_address_t * eh_addr, u16 eh_port,
40 u8 proto, u32 fib_index, u32 total_pkts,
41 u64 total_bytes, u32 thread_index);
44 * @brief Enable NAT HA
46 void nat_ha_enable ();
49 * @brief Disable NAT HA
51 void nat_ha_disable ();
54 * @brief Initialize NAT HA
56 void nat_ha_init (vlib_main_t * vm, u32 num_workers, u32 num_threads);
59 * @brief Set HA listener (local settings)
61 * @param addr local IP4 address
62 * @param port local UDP port number
63 * @param path_mtu path MTU between local and failover
65 * @returns 0 on success, non-zero value otherwise.
67 int nat_ha_set_listener (ip4_address_t * addr, u16 port, u32 path_mtu);
70 * @brief Get HA listener/local configuration
72 void nat_ha_get_listener (ip4_address_t * addr, u16 * port, u32 * path_mtu);
75 * @brief Set HA failover (remote settings)
77 * @param addr failover IP4 address
78 * @param port failvoer UDP port number
79 * @param session_refresh_interval number of seconds after which to send
80 * session counters refresh
82 * @returns 0 on success, non-zero value otherwise.
84 int nat_ha_set_failover (ip4_address_t * addr, u16 port,
85 u32 session_refresh_interval);
88 * @brief Get HA failover/remote settings
90 void nat_ha_get_failover (ip4_address_t * addr, u16 * port,
91 u32 * session_refresh_interval);
94 * @brief Create session add HA event
96 * @param in_addr inside IPv4 address
97 * @param in_port inside L4 port number
98 * @param out_addr outside IPv4 address
99 * @param out_port outside L4 port number
100 * @param eh_addr external host IPv4 address
101 * @param eh_port external host L4 port number
102 * @param ehn_addr external host IPv4 address after translation
103 * @param ehn_port external host L4 port number after translation
104 * @param proto L4 protocol
105 * @param fib_index fib index
106 * @param flags session flags
107 * @param thread_index thread index
108 * @param is_resync 1 if HA resync
110 void nat_ha_sadd (ip4_address_t * in_addr, u16 in_port,
111 ip4_address_t * out_addr, u16 out_port,
112 ip4_address_t * eh_addr, u16 eh_port,
113 ip4_address_t * ehn_addr, u16 ehn_port, u8 proto,
114 u32 fib_index, u16 flags, u32 thread_index, u8 is_resync);
117 * @brief Create session delete HA event
119 * @param out_addr outside IPv4 address
120 * @param out_port outside L4 port number
121 * @param eh_addr external host IPv4 address
122 * @param eh_port external host L4 port number
123 * @param proto L4 protocol
124 * @param fib_index fib index
125 * @param thread_index thread index
127 void nat_ha_sdel (ip4_address_t * out_addr, u16 out_port,
128 ip4_address_t * eh_addr, u16 eh_port, u8 proto,
129 u32 fib_index, u32 thread_index);
132 * @brief Create session refresh HA event
134 * @param out_addr outside IPv4 address
135 * @param out_port outside L4 port number
136 * @param eh_addr external host IPv4 address
137 * @param eh_port external host L4 port number
138 * @param proto L4 protocol
139 * @param fib_index fib index
140 * @param total_pkts total packets processed
141 * @param total_bytes total bytes processed
142 * @param thread_index thread index
143 * @param last_refreshed last session refresh time
144 * @param now current time
146 void nat_ha_sref (ip4_address_t * out_addr, u16 out_port,
147 ip4_address_t * eh_addr, u16 eh_port, u8 proto,
148 u32 fib_index, u32 total_pkts, u64 total_bytes,
149 u32 thread_index, f64 * last_refreshed, f64 now);
152 * @brief Flush the current HA data (for testing)
154 void nat_ha_flush (u8 is_resync);
156 typedef void (*nat_ha_resync_event_cb_t) (u32 client_index, u32 pid,
160 * @brief Resync HA (resend existing sessions to new failover)
162 int nat_ha_resync (u32 client_index, u32 pid,
163 nat_ha_resync_event_cb_t event_callback);
166 * @brief Get resync status
168 * @param in_resync 1 if resync in progress
169 * @param resync_ack_missed number of missed (not ACKed) messages
171 void nat_ha_get_resync_status (u8 * in_resync, u32 * resync_ack_missed);
173 #endif /* __included_nat_ha_h__ */
176 * fd.io coding-style-patch-verification: ON
179 * eval: (c-set-style "gnu")