summaryrefslogtreecommitdiffstats
path: root/src/plugins/nat/nat_ha.h
blob: 92fc3373673ac3f89237c17f4b5b2c68db545482 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
 * Copyright (c) 2019 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * @file
 * @brief NAT active-passive HA
 */

#ifndef __included_nat_ha_h__
#define __included_nat_ha_h__

#include <vnet/vnet.h>
#include <vnet/ip/ip.h>

/* Call back functions for received HA events on passive/failover */
typedef void (*nat_ha_sadd_cb_t) (ip4_address_t * in_addr, u16 in_port,
				  ip4_address_t * out_addr, u16 out_port,
				  ip4_address_t * eh_addr, u16 eh_port,
				  ip4_address_t * ehn_addr, u16 ehn_port,
				  u8 proto, u32 fib_index, u16 flags,
				  u32 thread_index);
typedef void (*nat_ha_sdel_cb_t) (ip4_address_t * out_addr, u16 out_port,
				  ip4_address_t * eh_addr, u16 eh_port,
				  u8 proto, u32 fib_index, u32 thread_index);
typedef void (*nat_ha_sref_cb_t) (ip4_address_t * out_addr, u16 out_port,
				  ip4_address_t * eh_addr, u16 eh_port,
				  u8 proto, u32 fib_index, u32 total_pkts,
				  u64 total_bytes, u32 thread_index);

/**
 * @brief Enable NAT HA, set callbacks
 */
void nat_ha_enable (nat_ha_sadd_cb_t sadd_cb, nat_ha_sdel_cb_t sdel_cb,
		    nat_ha_sref_cb_t sref_cb);

/**
 * @brief Initialize NAT HA
 */
void nat_ha_init (vlib_main_t * vm, u32 num_workers, u32 num_threads);

/**
 * @brief Set HA listener (local settings)
 *
 * @param addr local IP4 address
 * @param port local UDP port number
 * @param path_mtu path MTU between local and failover
 *
 * @returns 0 on success, non-zero value otherwise.
 */
int nat_ha_set_listener (ip4_address_t * addr, u16 port, u32 path_mtu);

/**
 * @brief Get HA listener/local configuration
 */
void nat_ha_get_listener (ip4_address_t * addr, u16 * port, u32 * path_mtu);

/**
 * @brief Set HA failover (remote settings)
 *
 * @param addr failover IP4 address
 * @param port failvoer UDP port number
 * @param session_refresh_interval number of seconds after which to send
 *                                 session counters refresh
 *
 * @returns 0 on success, non-zero value otherwise.
 */
int nat_ha_set_failover (ip4_address_t * addr, u16 port,
			 u32 session_refresh_interval);

/**
 * @brief Get HA failover/remote settings
 */
void nat_ha_get_failover (ip4_address_t * addr, u16 * port,
			  u32 * session_refresh_interval);

/**
 * @brief Create session add HA event
 *
 * @param in_addr inside IPv4 address
 * @param in_port inside L4 port number
 * @param out_addr outside IPv4 address
 * @param out_port outside L4 port number
 * @param eh_addr external host IPv4 address
 * @param eh_port external host L4 port number
 * @param ehn_addr external host IPv4 address after translation
 * @param ehn_port external host L4 port number after translation
 * @param proto L4 protocol
 * @param fib_index fib index
 * @param flags session flags
 * @param thread_index thread index
 * @param is_resync 1 if HA resync
 */
void nat_ha_sadd (ip4_address_t * in_addr, u16 in_port,
		  ip4_address_t * out_addr, u16 out_port,
		  ip4_address_t * eh_addr, u16 eh_port,
		  ip4_address_t * ehn_addr, u16 ehn_port, u8 proto,
		  u32 fib_index, u16 flags, u32 thread_index, u8 is_resync);

/**
 * @brief Create session delete HA event
 *
 * @param out_addr outside IPv4 address
 * @param out_port outside L4 port number
 * @param eh_addr external host IPv4 address
 * @param eh_port external host L4 port number
 * @param proto L4 protocol
 * @param fib_index fib index
 * @param thread_index thread index
 */
void nat_ha_sdel (ip4_address_t * out_addr, u16 out_port,
		  ip4_address_t * eh_addr, u16 eh_port, u8 proto,
		  u32 fib_index, u32 thread_index);

/**
 * @brief Create session refresh HA event
 *
 * @param out_addr outside IPv4 address
 * @param out_port outside L4 port number
 * @param eh_addr external host IPv4 address
 * @param eh_port external host L4 port number
 * @param proto L4 protocol
 * @param fib_index fib index
 * @param total_pkts total packets processed
 * @param total_bytes total bytes processed
 * @param thread_index thread index
 * @param last_refreshed last session refresh time
 * @param now current time
 */
void nat_ha_sref (ip4_address_t * out_addr, u16 out_port,
		  ip4_address_t * eh_addr, u16 eh_port, u8 proto,
		  u32 fib_index, u32 total_pkts, u64 total_bytes,
		  u32 thread_index, f64 * last_refreshed, f64 now);

/**
 * @brief Flush the current HA data (for testing)
 */
void nat_ha_flush (u8 is_resync);

typedef void (*nat_ha_resync_event_cb_t) (u32 client_index, u32 pid,
					  u32 missed_count);

/**
 * @brief Resync HA (resend existing sessions to new failover)
 */
int nat_ha_resync (u32 client_index, u32 pid,
		   nat_ha_resync_event_cb_t event_callback);

/**
 * @brief Get resync status
 *
 * @param in_resync 1 if resync in progress
 * @param resync_ack_missed number of missed (not ACKed) messages
 */
void nat_ha_get_resync_status (u8 * in_resync, u32 * resync_ack_missed);

#endif /* __included_nat_ha_h__ */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */