~ubuntu-branches/ubuntu/oneiric/isc-dhcp/oneiric-security

« back to all changes in this revision

Viewing changes to includes/failover.h

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Pollock
  • Date: 2009-09-02 22:34:25 UTC
  • Revision ID: james.westby@ubuntu.com-20090902223425-nypo7bkftxffq41m
Tags: upstream-4.1.0
ImportĀ upstreamĀ versionĀ 4.1.0

Show diffs side-by-side

added added

removed removed

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