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