]> git.ipfire.org Git - thirdparty/dhcp.git/blame - includes/failover.h
copy rights update
[thirdparty/dhcp.git] / includes / failover.h
CommitLineData
b3677620
TL
1/* failover.h
2
3 Definitions for address trees... */
4
5/*
49a7fb58 6 * Copyright (C) 2004-2022 Internet Systems Consortium, Inc. ("ISC")
98311e4b 7 * Copyright (c) 2000-2003 by Internet Software Consortium
b3677620 8 *
7512d88b
TM
9 * This Source Code Form is subject to the terms of the Mozilla Public
10 * License, v. 2.0. If a copy of the MPL was not distributed with this
11 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
b3677620 12 *
98311e4b
DH
13 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
19 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
b3677620 20 *
98311e4b 21 * Internet Systems Consortium, Inc.
429a56d7
TM
22 * PO Box 360
23 * Newmarket, NH 03857 USA
98311e4b 24 * <info@isc.org>
2c85ac9b 25 * https://www.isc.org/
49733f31 26 *
b3677620
TL
27 */
28
438f5f95 29#if defined (FAILOVER_PROTOCOL)
d9eefc5d 30struct failover_option_info {
b3677620 31 int code;
c689c0c9 32 const char *name;
2ac47e02
TL
33 enum { FT_UINT8, FT_IPADDR, FT_UINT32, FT_BYTES, FT_TEXT_OR_BYTES,
34 FT_DDNS, FT_DDNS1, FT_UINT16, FT_TEXT,
35 FT_UNDEF, FT_DIGEST } type;
b3677620 36 int num_present;
d9eefc5d
TL
37 int offset;
38 u_int32_t bit;
b3677620
TL
39};
40
d9eefc5d 41typedef struct {
c689c0c9 42 unsigned count;
d9eefc5d
TL
43 u_int8_t *data;
44} failover_option_t;
45
2426234f
DH
46/* Failover configuration defaults. */
47#ifndef DEFAULT_MAX_BALANCE_TIME
48# define DEFAULT_MAX_BALANCE_TIME 3600
49#endif
50
51#ifndef DEFAULT_MIN_BALANCE_TIME
52# define DEFAULT_MIN_BALANCE_TIME 60
53#endif
54
55#ifndef DEFAULT_MAX_LEASE_MISBALANCE
56# define DEFAULT_MAX_LEASE_MISBALANCE 15
57#endif
58
59#ifndef DEFAULT_MAX_LEASE_OWNERSHIP
60# define DEFAULT_MAX_LEASE_OWNERSHIP 10
61#endif
62
63#ifndef DEFAULT_MAX_FLYING_UPDATES
64# define DEFAULT_MAX_FLYING_UPDATES 100
65#endif
66
67#ifndef DEFAULT_MAX_RESPONSE_DELAY
68# define DEFAULT_MAX_RESPONSE_DELAY 20
69#endif
70
d340bc24
DH
71/*
72 * IANA has assigned ports 647 ("dhcp-failover") and 847 ("dhcp-failover2").
73 * Of these, only port 647 is mentioned in the -12 draft revision. We're not
74 * sure if they are supposed to indicate primary and secondary? No matter,
75 * we'll stick to the -12 draft revision level.
76 */
77#ifndef DEFAULT_FAILOVER_PORT
78# define DEFAULT_FAILOVER_PORT 647
79#endif
80
c689c0c9 81#define FM_OFFSET(x) (long)(&(((failover_message_t *)0) -> x))
b3677620 82
a55ccdd0
DH
83/* All of the below definitions are mandated by draft-ietf-dhc-failover-12.
84 * The Sections referenced are Sections within that document of that
85 * version, and may be different in other documents of other versions.
86 */
87
88/* Failover message options from Section 12: */
89#define FTO_ADDRESSES_TRANSFERRED 1
90#define FTB_ADDRESSES_TRANSFERRED 0x00000002
b3677620
TL
91#define FTO_ASSIGNED_IP_ADDRESS 2
92#define FTB_ASSIGNED_IP_ADDRESS 0x00000004
a55ccdd0
DH
93#define FTO_BINDING_STATUS 3
94#define FTB_BINDING_STATUS 0x00000008
95#define FTO_CLIENT_IDENTIFIER 4
96#define FTB_CLIENT_IDENTIFIER 0x00000010
97#define FTO_CHADDR 5
98#define FTB_CHADDR 0x00000020
99#define FTO_CLTT 6
100#define FTB_CLTT 0x00000040
101#define FTO_REPLY_OPTIONS 7
102#define FTB_REPLY_OPTIONS 0x00000080
103#define FTO_REQUEST_OPTIONS 8
104#define FTB_REQUEST_OPTIONS 0x00000100
105#define FTO_DDNS 9
106#define FTB_DDNS 0x00000200
107#define FTO_DELAYED_SERVICE 10
108#define FTB_DELAYED_SERVICE 0x00000400
109#define FTO_HBA 11
110#define FTB_HBA 0x00000800
111#define FTO_IP_FLAGS 12
112#define FTB_IP_FLAGS 0x00001000
c689c0c9
TL
113#define FTO_LEASE_EXPIRY 13
114#define FTB_LEASE_EXPIRY 0x00002000
a55ccdd0
DH
115#define FTO_MAX_UNACKED 14
116#define FTB_MAX_UNACKED 0x00004000
117#define FTO_MCLT 15
118#define FTB_MCLT 0x00008000
119#define FTO_MESSAGE 16
120#define FTB_MESSAGE 0x00010000
121#define FTO_MESSAGE_DIGEST 17
122#define FTB_MESSAGE_DIGEST 0x00020000
123#define FTO_POTENTIAL_EXPIRY 18
124#define FTB_POTENTIAL_EXPIRY 0x00040000
125#define FTO_RECEIVE_TIMER 19
126#define FTB_RECEIVE_TIMER 0x00080000
127#define FTO_PROTOCOL_VERSION 20
128#define FTB_PROTOCOL_VERSION 0x00100000
129#define FTO_REJECT_REASON 21
130#define FTB_REJECT_REASON 0x00200000
131#define FTO_RELATIONSHIP_NAME 22
132#define FTB_RELATIONSHIP_NAME 0x00400000
133#define FTO_SERVER_FLAGS 23
134#define FTB_SERVER_FLAGS 0x00800000
135#define FTO_SERVER_STATE 24
136#define FTB_SERVER_STATE 0x01000000
137#define FTO_STOS 25
138#define FTB_STOS 0x02000000
139#define FTO_TLS_REPLY 26
140#define FTB_TLS_REPLY 0x04000000
b3677620
TL
141#define FTO_TLS_REQUEST 27
142#define FTB_TLS_REQUEST 0x08000000
a55ccdd0
DH
143#define FTO_VENDOR_CLASS 28
144#define FTB_VENDOR_CLASS 0x10000000
145#define FTO_VENDOR_OPTIONS 29
146#define FTB_VENDOR_OPTIONS 0x20000000
147
148#define FTO_MAX FTO_VENDOR_OPTIONS
149
150/* Failover protocol message types from Section 6.1: */
b3677620
TL
151#define FTM_POOLREQ 1
152#define FTM_POOLRESP 2
153#define FTM_BNDUPD 3
154#define FTM_BNDACK 4
155#define FTM_CONNECT 5
156#define FTM_CONNECTACK 6
a55ccdd0 157#define FTM_UPDREQALL 7
b3677620 158#define FTM_UPDDONE 8
a55ccdd0 159#define FTM_UPDREQ 9
b3677620
TL
160#define FTM_STATE 10
161#define FTM_CONTACT 11
162#define FTM_DISCONNECT 12
d9eefc5d 163
e1b18c69
TM
164#define FTM_MAX FTM_DISCONNECT
165
a55ccdd0 166/* Reject reasons from Section 12.21: */
999d7de6
TL
167#define FTR_ILLEGAL_IP_ADDR 1
168#define FTR_FATAL_CONFLICT 2
169#define FTR_MISSING_BINDINFO 3
170#define FTR_TIMEMISMATCH 4
171#define FTR_INVALID_MCLT 5
172#define FTR_MISC_REJECT 6
173#define FTR_DUP_CONNECTION 7
174#define FTR_INVALID_PARTNER 8
175#define FTR_TLS_UNSUPPORTED 9
176#define FTR_TLS_UNCONFIGURED 10
177#define FTR_TLS_REQUIRED 11
178#define FTR_DIGEST_UNSUPPORTED 12
179#define FTR_DIGEST_UNCONFIGURED 13
180#define FTR_VERSION_MISMATCH 14
a55ccdd0
DH
181#define FTR_OUTDATED_BIND_INFO 15
182#define FTR_LESS_CRIT_BIND_INFO 16
183#define FTR_NO_TRAFFIC 17
184#define FTR_HBA_CONFLICT 18
185#define FTR_IP_NOT_RESERVED 19
186#define FTR_IP_DIGEST_FAILURE 20
187#define FTR_IP_MISSING_DIGEST 21
999d7de6
TL
188#define FTR_UNKNOWN 254
189
a55ccdd0
DH
190/* Message size limitations defined in Section 6.1: */
191#define DHCP_FAILOVER_MIN_MESSAGE_SIZE 12
d9eefc5d
TL
192#define DHCP_FAILOVER_MAX_MESSAGE_SIZE 2048
193
a55ccdd0
DH
194/* Failover server flags from Section 12.23: */
195#define FTF_SERVER_STARTUP 1
196
197/* DDNS flags from Section 12.9. These are really their names. */
198#define FTF_DDNS_C 0x0001
199#define FTF_DDNS_A 0x0002
200#define FTF_DDNS_D 0x0004
201#define FTF_DDNS_P 0x0008
202
203/* FTO_IP_FLAGS contents from Section 12.12: */
204#define FTF_IP_FLAG_RESERVE 0x0001
205#define FTF_IP_FLAG_BOOTP 0x0002
206
207/* FTO_MESSAGE_DIGEST Type Codes from Section 12.17: */
208#define FTT_MESSAGE_DIGEST_HMAC_MD5 0x01
ea2169d4 209
988c1ca7
DN
210typedef struct failover_message {
211 int refcnt;
212 struct failover_message *next;
213
a55ccdd0
DH
214 int options_present;
215
216 u_int32_t time;
217 u_int32_t xid;
d9eefc5d 218 u_int8_t type;
c689c0c9 219
a55ccdd0 220 /* One-byte options. */
c689c0c9 221 u_int8_t binding_status;
a55ccdd0 222 u_int8_t delayed_service;
c689c0c9
TL
223 u_int8_t protocol_version;
224 u_int8_t reject_reason;
225 u_int8_t server_flags;
226 u_int8_t server_state;
227 u_int8_t tls_reply;
228 u_int8_t tls_request;
a55ccdd0
DH
229
230 /* Two-byte options. */
231 u_int16_t ip_flags;
232
233 /* Four-byte options. */
c689c0c9
TL
234 u_int32_t addresses_transferred;
235 u_int32_t assigned_addr;
a55ccdd0 236 u_int32_t cltt;
c689c0c9 237 u_int32_t expiry;
c689c0c9
TL
238 u_int32_t max_unacked;
239 u_int32_t mclt;
240 u_int32_t potential_expiry;
241 u_int32_t receive_timer;
a55ccdd0
DH
242 u_int32_t stos;
243
244 /* Arbitrary field options. */
c689c0c9
TL
245 failover_option_t chaddr;
246 failover_option_t client_identifier;
247 failover_option_t hba;
248 failover_option_t message;
a55ccdd0
DH
249 failover_option_t message_digest;
250 failover_option_t relationship_name;
c689c0c9
TL
251 failover_option_t reply_options;
252 failover_option_t request_options;
c689c0c9
TL
253 failover_option_t vendor_class;
254 failover_option_t vendor_options;
255
a55ccdd0
DH
256 /* Special contents options. */
257 ddns_fqdn_t ddns;
d9eefc5d
TL
258} failover_message_t;
259
260typedef struct {
261 OMAPI_OBJECT_PREAMBLE;
80f2771e 262 struct option_cache *peer_address;
d9eefc5d
TL
263 unsigned peer_port;
264 int options_present;
265 enum dhcp_flink_state {
266 dhcp_flink_start,
267 dhcp_flink_message_length_wait,
268 dhcp_flink_message_wait,
269 dhcp_flink_disconnected,
270 dhcp_flink_state_max
271 } state;
272 failover_message_t *imsg;
c689c0c9 273 struct _dhcp_failover_state *state_object;
d9eefc5d
TL
274 u_int16_t imsg_len;
275 unsigned imsg_count;
276 u_int8_t imsg_payoff; /* Pay*load* offset. :') */
c689c0c9 277 u_int32_t xid;
d9eefc5d
TL
278} dhcp_failover_link_t;
279
fcbeefb3 280typedef struct _dhcp_failover_listener {
d9eefc5d 281 OMAPI_OBJECT_PREAMBLE;
fcbeefb3
TL
282 struct _dhcp_failover_listener *next;
283 omapi_addr_t address;
d9eefc5d 284} dhcp_failover_listener_t;
438f5f95 285#endif /* FAILOVER_PROTOCOL */
d9eefc5d 286
a55ccdd0 287/* A failover peer's running state. */
80f2771e 288enum failover_state {
a55ccdd0
DH
289 unknown_state = 0, /* XXX: Not a standard state. */
290 startup = 1,
291 normal = 2,
292 communications_interrupted = 3,
293 partner_down = 4,
294 potential_conflict = 5,
295 recover = 6,
296 paused = 7,
297 shut_down = 8,
298 recover_done = 9,
299 resolution_interrupted = 10,
300 conflict_done = 11,
301
302 /* Draft revision 12 of the failover protocol documents a RECOVER-WAIT
303 * state, but does not enumerate its value in the section 12.24
304 * table. ISC DHCP 3.0.x used value 254 even though the state was
305 * not documented at all. For the time being, we will continue to use
306 * this value.
307 */
308 recover_wait = 254
ea2169d4
TL
309};
310
311/* Service states are simplifications of failover states, particularly
312 useful because the startup state isn't actually implementable as a
c57db45c 313 separate failover state without maintaining a state stack. */
ea2169d4
TL
314
315enum service_state {
316 unknown_service_state,
317 cooperating,
318 not_cooperating,
319 service_partner_down,
320 not_responding,
321 service_startup
80f2771e
TL
322};
323
438f5f95 324#if defined (FAILOVER_PROTOCOL)
fcbeefb3
TL
325typedef struct _dhcp_failover_config {
326 struct option_cache *address;
327 int port;
328 u_int32_t max_flying_updates;
329 enum failover_state state;
330 TIME stos;
331 u_int32_t max_response_delay;
332} dhcp_failover_config_t;
333
d9eefc5d
TL
334typedef struct _dhcp_failover_state {
335 OMAPI_OBJECT_PREAMBLE;
336 struct _dhcp_failover_state *next;
80f2771e 337 char *name; /* Name of this failover instance. */
fcbeefb3
TL
338 dhcp_failover_config_t me; /* My configuration. */
339 dhcp_failover_config_t partner; /* Partner's configuration. */
340 enum failover_state saved_state; /* Saved state during startup. */
999d7de6 341 struct data_string server_identifier; /* Server identifier (IP addr) */
80f2771e 342 u_int32_t mclt;
f3886ff3
TL
343
344 u_int8_t *hba; /* Hash bucket array for load balancing. */
345 int load_balance_max_secs;
80f2771e 346
a546f6b6 347 u_int32_t max_lease_misbalance, max_lease_ownership;
2426234f
DH
348 u_int32_t max_balance, min_balance;
349 TIME last_balance, sched_balance;
350
9e3eb22a
DH
351 u_int32_t auto_partner_down;
352
ea2169d4
TL
353 enum service_state service_state;
354 const char *nrr; /* Printable reason why we're in the
355 not_responding service state (empty
356 string if we are responding. */
80f2771e 357
20916cae
TL
358 dhcp_failover_link_t *link_to_peer; /* Currently-established link
359 to peer. */
f3886ff3 360
80f2771e
TL
361 enum {
362 primary, secondary
363 } i_am; /* We are primary or secondary in this relationship. */
364
365 TIME last_packet_sent; /* Timestamp on last packet we sent. */
366 TIME last_timestamp_received; /* The last timestamp we sent that
367 has been returned by our partner. */
368 TIME skew; /* The skew between our clock and our partner's. */
f3886ff3
TL
369 struct lease *update_queue_head; /* List of leases we haven't sent
370 to peer. */
371 struct lease *update_queue_tail;
372
373 struct lease *ack_queue_head; /* List of lease updates the peer
80f2771e 374 hasn't yet acked. */
f3886ff3 375 struct lease *ack_queue_tail;
ea2169d4
TL
376
377 struct lease *send_update_done; /* When we get a BNDACK for this
378 lease, send an UPDDONE message. */
80f2771e
TL
379 int cur_unacked_updates; /* Number of updates we've sent
380 that have not yet been acked. */
988c1ca7
DN
381
382 /* List of messages which we haven't
383 acked yet. */
384 failover_message_t *toack_queue_head;
385 failover_message_t *toack_queue_tail;
386 int pending_acks; /* Number of messages in the toack
387 queue. */
a609e69b
TL
388 int pool_count; /* Number of pools referencing this
389 failover state object. */
98311e4b
DH
390 int curUPD; /* If an UPDREQ* message is in motion,
391 this value indicates which one. */
a55ccdd0 392 u_int32_t updxid; /* XID of UPDREQ* message in action. */
d9eefc5d
TL
393} dhcp_failover_state_t;
394
30593241
TM
395extern int check_secs_byte_order; /* check byte order of secs field when true */
396
c689c0c9 397#define DHCP_FAILOVER_VERSION 1
438f5f95 398#endif /* FAILOVER_PROTOCOL */