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>
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,
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);
42 * @brief Initialize NAT HA
44 void nat_ha_init (vlib_main_t * vm, nat_ha_sadd_cb_t sadd_cb,
45 nat_ha_sdel_cb_t sdel_cb, nat_ha_sref_cb_t sref_cb);
48 * @brief Set HA listener (local settings)
50 * @param addr local IP4 address
51 * @param port local UDP port number
52 * @param path_mtu path MTU between local and failover
54 * @returns 0 on success, non-zero value otherwise.
56 int nat_ha_set_listener (ip4_address_t * addr, u16 port, u32 path_mtu);
59 * @brief Get HA listener/local configuration
61 void nat_ha_get_listener (ip4_address_t * addr, u16 * port, u32 * path_mtu);
64 * @brief Set HA failover (remote settings)
66 * @param addr failover IP4 address
67 * @param port failvoer UDP port number
68 * @param session_refresh_interval number of seconds after which to send
69 * session counters refresh
71 * @returns 0 on success, non-zero value otherwise.
73 int nat_ha_set_failover (ip4_address_t * addr, u16 port,
74 u32 session_refresh_interval);
77 * @brief Get HA failover/remote settings
79 void nat_ha_get_failover (ip4_address_t * addr, u16 * port,
80 u32 * session_refresh_interval);
83 * @brief Create session add HA event
85 * @param in_addr inside IPv4 address
86 * @param in_port inside L4 port number
87 * @param out_addr outside IPv4 address
88 * @param out_port outside L4 port number
89 * @param eh_addr external host IPv4 address
90 * @param eh_port external host L4 port number
91 * @param ehn_addr external host IPv4 address after translation
92 * @param ehn_port external host L4 port number after translation
93 * @param proto L4 protocol
94 * @param fib_index fib index
95 * @param flags session flags
96 * @param thread_index thread index
97 * @param is_resync 1 if HA resync
99 void nat_ha_sadd (ip4_address_t * in_addr, u16 in_port,
100 ip4_address_t * out_addr, u16 out_port,
101 ip4_address_t * eh_addr, u16 eh_port,
102 ip4_address_t * ehn_addr, u16 ehn_port, u8 proto,
103 u32 fib_index, u16 flags, u32 thread_index, u8 is_resync);
106 * @brief Create session delete HA event
108 * @param out_addr outside IPv4 address
109 * @param out_port outside L4 port number
110 * @param eh_addr external host IPv4 address
111 * @param eh_port external host L4 port number
112 * @param proto L4 protocol
113 * @param fib_index fib index
114 * @param thread_index thread index
116 void nat_ha_sdel (ip4_address_t * out_addr, u16 out_port,
117 ip4_address_t * eh_addr, u16 eh_port, u8 proto,
118 u32 fib_index, u32 thread_index);
121 * @brief Create session refresh HA event
123 * @param out_addr outside IPv4 address
124 * @param out_port outside L4 port number
125 * @param eh_addr external host IPv4 address
126 * @param eh_port external host L4 port number
127 * @param proto L4 protocol
128 * @param fib_index fib index
129 * @param total_pkts total packets processed
130 * @param total_bytes total bytes processed
131 * @param thread_index thread index
132 * @param last_refreshed last session refresh time
133 * @param now current time
135 void nat_ha_sref (ip4_address_t * out_addr, u16 out_port,
136 ip4_address_t * eh_addr, u16 eh_port, u8 proto,
137 u32 fib_index, u32 total_pkts, u64 total_bytes,
138 u32 thread_index, f64 * last_refreshed, f64 now);
141 * @brief Flush the current HA data (for testing)
143 void nat_ha_flush (u8 is_resync);
145 typedef void (*nat_ha_resync_event_cb_t) (u32 client_index, u32 pid,
149 * @brief Resync HA (resend existing sessions to new failover)
151 int nat_ha_resync (u32 client_index, u32 pid,
152 nat_ha_resync_event_cb_t event_callback);
155 * @brief Get resync status
157 * @param in_resync 1 if resync in progress
158 * @param resync_ack_missed number of missed (not ACKed) messages
160 void nat_ha_get_resync_status (u8 * in_resync, u32 * resync_ack_missed);
162 #endif /* __included_nat_ha_h__ */
165 * fd.io coding-style-patch-verification: ON
168 * eval: (c-set-style "gnu")