Initial import from FreeBSD RELENG_4:
[games.git] / contrib / isc-dhcp / includes / failover.h
1 /* failover.h
2
3    Definitions for address trees... */
4
5 /*
6  * Copyright (c) 2000-2001 Internet Software Consortium.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of The Internet Software Consortium nor the names
19  *    of its contributors may be used to endorse or promote products derived
20  *    from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
23  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED.  IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
27  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  * This software has been written for the Internet Software Consortium
37  * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
38  * To learn more about the Internet Software Consortium, see
39  * ``http://www.isc.org/''.  To learn more about Vixie Enterprises,
40  * see ``http://www.vix.com''.   To learn more about Nominum, Inc., see
41  * ``http://www.nominum.com''.
42  */
43
44 #if defined (FAILOVER_PROTOCOL)
45 struct failover_option_info {
46         int code;
47         const char *name;
48         enum { FT_UINT8, FT_IPADDR, FT_UINT32, FT_BYTES, FT_TEXT_OR_BYTES,
49                FT_DDNS, FT_DDNS1, FT_UINT16, FT_TEXT,
50                FT_UNDEF, FT_DIGEST } type;
51         int num_present;
52         int offset;
53         u_int32_t bit;
54 };
55
56 typedef struct {
57         unsigned count;
58         u_int8_t *data;
59 } failover_option_t;
60
61 #define FM_OFFSET(x) (long)(&(((failover_message_t *)0) -> x))
62
63 /* Failover message options: */
64 #define FTO_BINDING_STATUS              1
65 #define FTB_BINDING_STATUS                      0x00000002
66 #define FTO_ASSIGNED_IP_ADDRESS         2
67 #define FTB_ASSIGNED_IP_ADDRESS                 0x00000004
68 #define FTO_SERVER_ADDR                 3
69 #define FTB_SERVER_ADDR                         0x00000008
70 #define FTO_ADDRESSES_TRANSFERRED       4
71 #define FTB_ADDRESSES_TRANSFERRED               0x00000010
72 #define FTO_CLIENT_IDENTIFIER           5
73 #define FTB_CLIENT_IDENTIFIER                   0x00000020
74 #define FTO_CHADDR                      6
75 #define FTB_CHADDR                              0x00000040
76 #define FTO_DDNS                        7
77 #define FTB_DDNS                                0x00000080
78 #define FTO_REJECT_REASON               8
79 #define FTB_REJECT_REASON                       0x00000100
80 #define FTO_MESSAGE                     9
81 #define FTB_MESSAGE                             0x00000200
82 #define FTO_MCLT                        10
83 #define FTB_MCLT                                0x00000400
84 #define FTO_VENDOR_CLASS                11
85 #define FTB_VENDOR_CLASS                        0x00000800
86 #define FTO_LEASE_EXPIRY                13
87 #define FTB_LEASE_EXPIRY                        0x00002000
88 #define FTO_POTENTIAL_EXPIRY            14
89 #define FTB_POTENTIAL_EXPIRY                    0x00004000
90 #define FTO_GRACE_EXPIRY                15
91 #define FTB_GRACE_EXPIRY                        0x00008000
92 #define FTO_CLTT                        16
93 #define FTB_CLTT                                0x00010000
94 #define FTO_STOS                        17
95 #define FTB_STOS                                0x00020000
96 #define FTO_SERVER_STATE                18
97 #define FTB_SERVER_STATE                        0x00040000
98 #define FTO_SERVER_FLAGS                19
99 #define FTB_SERVER_FLAGS                        0x00080000
100 #define FTO_VENDOR_OPTIONS              20
101 #define FTB_VENDOR_OPTIONS                      0x00100000
102 #define FTO_MAX_UNACKED                 21
103 #define FTB_MAX_UNACKED                         0x00200000
104 #define FTO_RECEIVE_TIMER               23
105 #define FTB_RECEIVE_TIMER                       0x00800000
106 #define FTO_HBA                         24
107 #define FTB_HBA                                 0x01000000
108 #define FTO_MESSAGE_DIGEST              25
109 #define FTB_MESSAGE_DIGEST                      0x02000000
110 #define FTO_PROTOCOL_VERSION            26
111 #define FTB_PROTOCOL_VERSION                    0x04000000
112 #define FTO_TLS_REQUEST                 27
113 #define FTB_TLS_REQUEST                         0x08000000
114 #define FTO_TLS_REPLY                   28
115 #define FTB_TLS_REPLY                           0x10000000
116 #define FTO_REQUEST_OPTIONS             29
117 #define FTB_REQUEST_OPTIONS                     0x20000000
118 #define FTO_REPLY_OPTIONS               30
119 #define FTB_REPLY_OPTIONS                       0x40000000
120 #define FTO_MAX                         FTO_REPLY_OPTIONS
121
122 /* Failover protocol message types: */
123 #define FTM_POOLREQ             1
124 #define FTM_POOLRESP            2
125 #define FTM_BNDUPD              3
126 #define FTM_BNDACK              4
127 #define FTM_CONNECT             5
128 #define FTM_CONNECTACK          6
129 #define FTM_UPDREQ              7
130 #define FTM_UPDDONE             8
131 #define FTM_UPDREQALL           9
132 #define FTM_STATE               10
133 #define FTM_CONTACT             11
134 #define FTM_DISCONNECT          12
135
136 /* Reject reasons: */
137
138 #define FTR_ILLEGAL_IP_ADDR     1
139 #define FTR_FATAL_CONFLICT      2
140 #define FTR_MISSING_BINDINFO    3
141 #define FTR_TIMEMISMATCH        4
142 #define FTR_INVALID_MCLT        5
143 #define FTR_MISC_REJECT         6
144 #define FTR_DUP_CONNECTION      7
145 #define FTR_INVALID_PARTNER     8
146 #define FTR_TLS_UNSUPPORTED     9
147 #define FTR_TLS_UNCONFIGURED    10
148 #define FTR_TLS_REQUIRED        11
149 #define FTR_DIGEST_UNSUPPORTED  12
150 #define FTR_DIGEST_UNCONFIGURED 13
151 #define FTR_VERSION_MISMATCH    14
152 #define FTR_MISSING_BIND_INFO   15
153 #define FTR_OUTDATED_BIND_INFO  16
154 #define FTR_LESS_CRIT_BIND_INFO 17
155 #define FTR_NO_TRAFFIC          18
156 #define FTR_HBA_CONFLICT        19
157 #define FTR_UNKNOWN             254
158
159 #define DHCP_FAILOVER_MAX_MESSAGE_SIZE  2048
160
161 /* Failover server flags. */
162 #define FTF_STARTUP     1
163
164 typedef struct failover_message {
165         int refcnt;
166         struct failover_message *next;
167
168         u_int8_t type;
169
170         u_int8_t binding_status;
171         u_int8_t protocol_version;
172         u_int8_t reject_reason;
173         u_int8_t server_flags;
174         u_int8_t server_state;
175         u_int8_t tls_reply;
176         u_int8_t tls_request;
177         u_int32_t stos;
178         u_int32_t time;
179         u_int32_t xid;
180         u_int32_t addresses_transferred;
181         u_int32_t assigned_addr;
182         u_int32_t client_ltt;
183         u_int32_t expiry;
184         u_int32_t grace_expiry;
185         u_int32_t max_unacked;
186         u_int32_t mclt;
187         u_int32_t potential_expiry;
188         u_int32_t receive_timer;
189         u_int32_t server_addr;
190         failover_option_t chaddr;
191         failover_option_t client_identifier;
192         failover_option_t hba;
193         failover_option_t message;
194         failover_option_t reply_options;
195         failover_option_t request_options;
196         ddns_fqdn_t ddns;
197         failover_option_t vendor_class;
198         failover_option_t vendor_options;
199
200         int options_present;
201 } failover_message_t;
202
203 typedef struct {
204         OMAPI_OBJECT_PREAMBLE;
205         struct option_cache *peer_address;
206         unsigned peer_port;
207         int options_present;
208         enum dhcp_flink_state {
209                 dhcp_flink_start,
210                 dhcp_flink_message_length_wait,
211                 dhcp_flink_message_wait,
212                 dhcp_flink_disconnected,
213                 dhcp_flink_state_max
214         } state;
215         failover_message_t *imsg;
216         struct _dhcp_failover_state *state_object;
217         u_int16_t imsg_len;
218         unsigned imsg_count;
219         u_int8_t imsg_payoff; /* Pay*load* offset. :') */
220         u_int32_t xid;
221 } dhcp_failover_link_t;
222
223 typedef struct _dhcp_failover_listener {
224         OMAPI_OBJECT_PREAMBLE;
225         struct _dhcp_failover_listener *next;
226         omapi_addr_t address;
227 } dhcp_failover_listener_t;
228 #endif /* FAILOVER_PROTOCOL */
229
230 /* A failover peer. */
231 enum failover_state {
232         unknown_state,
233         partner_down,
234         normal,
235         communications_interrupted,
236         resolution_interrupted,
237         potential_conflict,
238         recover,
239         recover_done,
240         shut_down,
241         paused,
242         startup,
243         recover_wait
244 };
245
246 /* Service states are simplifications of failover states, particularly
247    useful because the startup state isn't actually implementable as a
248    seperate failover state without maintaining a state stack. */
249
250 enum service_state {
251         unknown_service_state,
252         cooperating,
253         not_cooperating,
254         service_partner_down,
255         not_responding,
256         service_startup
257 };
258
259 #if defined (FAILOVER_PROTOCOL)
260 typedef struct _dhcp_failover_config {
261         struct option_cache *address;
262         int port;
263         u_int32_t max_flying_updates;
264         enum failover_state state;
265         TIME stos;
266         u_int32_t max_response_delay;
267 } dhcp_failover_config_t;
268
269 typedef struct _dhcp_failover_state {
270         OMAPI_OBJECT_PREAMBLE;
271         struct _dhcp_failover_state *next;
272         char *name;                     /* Name of this failover instance. */
273         dhcp_failover_config_t me;      /* My configuration. */
274         dhcp_failover_config_t partner; /* Partner's configuration. */
275         enum failover_state saved_state; /* Saved state during startup. */
276         struct data_string server_identifier; /* Server identifier (IP addr) */
277         u_int32_t mclt;
278
279         u_int8_t *hba;  /* Hash bucket array for load balancing. */
280         int load_balance_max_secs;
281
282         enum service_state service_state;
283         const char *nrr;        /* Printable reason why we're in the
284                                    not_responding service state (empty
285                                    string if we are responding. */
286
287         dhcp_failover_link_t *link_to_peer;     /* Currently-established link
288                                                    to peer. */
289
290         enum {
291                 primary, secondary
292         } i_am;         /* We are primary or secondary in this relationship. */
293
294         TIME last_packet_sent;          /* Timestamp on last packet we sent. */
295         TIME last_timestamp_received;   /* The last timestamp we sent that
296                                            has been returned by our partner. */
297         TIME skew;      /* The skew between our clock and our partner's. */
298         struct lease *update_queue_head; /* List of leases we haven't sent
299                                             to peer. */
300         struct lease *update_queue_tail;
301
302         struct lease *ack_queue_head;   /* List of lease updates the peer
303                                            hasn't yet acked. */
304         struct lease *ack_queue_tail;
305
306         struct lease *send_update_done; /* When we get a BNDACK for this
307                                            lease, send an UPDDONE message. */
308         int cur_unacked_updates;        /* Number of updates we've sent
309                                            that have not yet been acked. */
310
311                                         /* List of messages which we haven't
312                                            acked yet. */
313         failover_message_t *toack_queue_head;
314         failover_message_t *toack_queue_tail;
315         int pending_acks;               /* Number of messages in the toack
316                                            queue. */
317         int pool_count;                 /* Number of pools referencing this
318                                            failover state object. */
319 } dhcp_failover_state_t;
320
321 #define DHCP_FAILOVER_VERSION           1
322 #endif /* FAILOVER_PROTOCOL */