includes/failover.h

Go to the documentation of this file.
00001 /* failover.h
00002 
00003    Definitions for address trees... */
00004 
00005 /*
00006  * Copyright (c) 2004,2005,2007,2009,2014 by Internet Systems Consortium, Inc. ("ISC")
00007  * Copyright (c) 2000-2003 by Internet Software Consortium
00008  *
00009  * Permission to use, copy, modify, and distribute this software for any
00010  * purpose with or without fee is hereby granted, provided that the above
00011  * copyright notice and this permission notice appear in all copies.
00012  *
00013  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
00014  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00015  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
00016  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00017  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00018  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
00019  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00020  *
00021  *   Internet Systems Consortium, Inc.
00022  *   950 Charter Street
00023  *   Redwood City, CA 94063
00024  *   <info@isc.org>
00025  *   https://www.isc.org/
00026  *
00027  */
00028 
00029 #if defined (FAILOVER_PROTOCOL)
00030 struct failover_option_info {
00031         int code;
00032         const char *name;
00033         enum { FT_UINT8, FT_IPADDR, FT_UINT32, FT_BYTES, FT_TEXT_OR_BYTES,
00034                FT_DDNS, FT_DDNS1, FT_UINT16, FT_TEXT,
00035                FT_UNDEF, FT_DIGEST } type;
00036         int num_present;
00037         int offset;
00038         u_int32_t bit;
00039 };
00040 
00041 typedef struct {
00042         unsigned count;
00043         u_int8_t *data;
00044 } failover_option_t;
00045 
00046 /* Failover configuration defaults. */
00047 #ifndef  DEFAULT_MAX_BALANCE_TIME
00048 # define DEFAULT_MAX_BALANCE_TIME       3600
00049 #endif
00050 
00051 #ifndef  DEFAULT_MIN_BALANCE_TIME
00052 # define DEFAULT_MIN_BALANCE_TIME       60
00053 #endif
00054 
00055 #ifndef  DEFAULT_MAX_LEASE_MISBALANCE
00056 # define DEFAULT_MAX_LEASE_MISBALANCE   15
00057 #endif
00058 
00059 #ifndef  DEFAULT_MAX_LEASE_OWNERSHIP
00060 # define DEFAULT_MAX_LEASE_OWNERSHIP    10
00061 #endif
00062 
00063 #ifndef  DEFAULT_MAX_FLYING_UPDATES
00064 # define DEFAULT_MAX_FLYING_UPDATES     100
00065 #endif
00066 
00067 #ifndef  DEFAULT_MAX_RESPONSE_DELAY
00068 # define DEFAULT_MAX_RESPONSE_DELAY     20
00069 #endif
00070 
00071 /*
00072  * IANA has assigned ports 647 ("dhcp-failover") and 847 ("dhcp-failover2").
00073  * Of these, only port 647 is mentioned in the -12 draft revision.  We're not
00074  * sure if they are supposed to indicate primary and secondary?  No matter,
00075  * we'll stick to the -12 draft revision level.
00076  */
00077 #ifndef  DEFAULT_FAILOVER_PORT
00078 # define DEFAULT_FAILOVER_PORT          647
00079 #endif
00080 
00081 #define FM_OFFSET(x) (long)(&(((failover_message_t *)0) -> x))
00082 
00083 /* All of the below definitions are mandated by draft-ietf-dhc-failover-12.
00084  * The Sections referenced are Sections within that document of that
00085  * version, and may be different in other documents of other versions.
00086  */
00087 
00088 /* Failover message options from Section 12: */
00089 #define FTO_ADDRESSES_TRANSFERRED       1
00090 #define FTB_ADDRESSES_TRANSFERRED               0x00000002
00091 #define FTO_ASSIGNED_IP_ADDRESS         2
00092 #define FTB_ASSIGNED_IP_ADDRESS                 0x00000004
00093 #define FTO_BINDING_STATUS              3
00094 #define FTB_BINDING_STATUS                      0x00000008
00095 #define FTO_CLIENT_IDENTIFIER           4
00096 #define FTB_CLIENT_IDENTIFIER                   0x00000010
00097 #define FTO_CHADDR                      5
00098 #define FTB_CHADDR                              0x00000020
00099 #define FTO_CLTT                        6
00100 #define FTB_CLTT                                0x00000040
00101 #define FTO_REPLY_OPTIONS               7
00102 #define FTB_REPLY_OPTIONS                       0x00000080
00103 #define FTO_REQUEST_OPTIONS             8
00104 #define FTB_REQUEST_OPTIONS                     0x00000100
00105 #define FTO_DDNS                        9
00106 #define FTB_DDNS                                0x00000200
00107 #define FTO_DELAYED_SERVICE             10
00108 #define FTB_DELAYED_SERVICE                     0x00000400
00109 #define FTO_HBA                         11
00110 #define FTB_HBA                                 0x00000800
00111 #define FTO_IP_FLAGS                    12
00112 #define FTB_IP_FLAGS                            0x00001000
00113 #define FTO_LEASE_EXPIRY                13
00114 #define FTB_LEASE_EXPIRY                        0x00002000
00115 #define FTO_MAX_UNACKED                 14
00116 #define FTB_MAX_UNACKED                         0x00004000
00117 #define FTO_MCLT                        15
00118 #define FTB_MCLT                                0x00008000
00119 #define FTO_MESSAGE                     16
00120 #define FTB_MESSAGE                             0x00010000
00121 #define FTO_MESSAGE_DIGEST              17
00122 #define FTB_MESSAGE_DIGEST                      0x00020000
00123 #define FTO_POTENTIAL_EXPIRY            18
00124 #define FTB_POTENTIAL_EXPIRY                    0x00040000
00125 #define FTO_RECEIVE_TIMER               19
00126 #define FTB_RECEIVE_TIMER                       0x00080000
00127 #define FTO_PROTOCOL_VERSION            20
00128 #define FTB_PROTOCOL_VERSION                    0x00100000
00129 #define FTO_REJECT_REASON               21
00130 #define FTB_REJECT_REASON                       0x00200000
00131 #define FTO_RELATIONSHIP_NAME           22
00132 #define FTB_RELATIONSHIP_NAME                   0x00400000
00133 #define FTO_SERVER_FLAGS                23
00134 #define FTB_SERVER_FLAGS                        0x00800000
00135 #define FTO_SERVER_STATE                24
00136 #define FTB_SERVER_STATE                        0x01000000
00137 #define FTO_STOS                        25
00138 #define FTB_STOS                                0x02000000
00139 #define FTO_TLS_REPLY                   26
00140 #define FTB_TLS_REPLY                           0x04000000
00141 #define FTO_TLS_REQUEST                 27
00142 #define FTB_TLS_REQUEST                         0x08000000
00143 #define FTO_VENDOR_CLASS                28
00144 #define FTB_VENDOR_CLASS                        0x10000000
00145 #define FTO_VENDOR_OPTIONS              29
00146 #define FTB_VENDOR_OPTIONS                      0x20000000
00147 
00148 #define FTO_MAX                         FTO_VENDOR_OPTIONS
00149 
00150 /* Failover protocol message types from Section 6.1: */
00151 #define FTM_POOLREQ             1
00152 #define FTM_POOLRESP            2
00153 #define FTM_BNDUPD              3
00154 #define FTM_BNDACK              4
00155 #define FTM_CONNECT             5
00156 #define FTM_CONNECTACK          6
00157 #define FTM_UPDREQALL           7
00158 #define FTM_UPDDONE             8
00159 #define FTM_UPDREQ              9
00160 #define FTM_STATE               10
00161 #define FTM_CONTACT             11
00162 #define FTM_DISCONNECT          12
00163 
00164 /* Reject reasons from Section 12.21: */
00165 #define FTR_ILLEGAL_IP_ADDR     1
00166 #define FTR_FATAL_CONFLICT      2
00167 #define FTR_MISSING_BINDINFO    3
00168 #define FTR_TIMEMISMATCH        4
00169 #define FTR_INVALID_MCLT        5
00170 #define FTR_MISC_REJECT         6
00171 #define FTR_DUP_CONNECTION      7
00172 #define FTR_INVALID_PARTNER     8
00173 #define FTR_TLS_UNSUPPORTED     9
00174 #define FTR_TLS_UNCONFIGURED    10
00175 #define FTR_TLS_REQUIRED        11
00176 #define FTR_DIGEST_UNSUPPORTED  12
00177 #define FTR_DIGEST_UNCONFIGURED 13
00178 #define FTR_VERSION_MISMATCH    14
00179 #define FTR_OUTDATED_BIND_INFO  15
00180 #define FTR_LESS_CRIT_BIND_INFO 16
00181 #define FTR_NO_TRAFFIC          17
00182 #define FTR_HBA_CONFLICT        18
00183 #define FTR_IP_NOT_RESERVED     19
00184 #define FTR_IP_DIGEST_FAILURE   20
00185 #define FTR_IP_MISSING_DIGEST   21
00186 #define FTR_UNKNOWN             254
00187 
00188 /* Message size limitations defined in Section 6.1: */
00189 #define DHCP_FAILOVER_MIN_MESSAGE_SIZE    12
00190 #define DHCP_FAILOVER_MAX_MESSAGE_SIZE  2048
00191 
00192 /* Failover server flags from Section 12.23: */
00193 #define FTF_SERVER_STARTUP      1
00194 
00195 /* DDNS flags from Section 12.9.  These are really their names. */
00196 #define FTF_DDNS_C              0x0001
00197 #define FTF_DDNS_A              0x0002
00198 #define FTF_DDNS_D              0x0004
00199 #define FTF_DDNS_P              0x0008
00200 
00201 /* FTO_IP_FLAGS contents from Section 12.12: */
00202 #define FTF_IP_FLAG_RESERVE     0x0001
00203 #define FTF_IP_FLAG_BOOTP       0x0002
00204 
00205 /* FTO_MESSAGE_DIGEST Type Codes from Section 12.17: */
00206 #define FTT_MESSAGE_DIGEST_HMAC_MD5     0x01
00207 
00208 typedef struct failover_message {
00209         int refcnt;
00210         struct failover_message *next;
00211 
00212         int options_present;
00213 
00214         u_int32_t time;
00215         u_int32_t xid;
00216         u_int8_t type;
00217 
00218         /* One-byte options. */
00219         u_int8_t binding_status;
00220         u_int8_t delayed_service;
00221         u_int8_t protocol_version;
00222         u_int8_t reject_reason;
00223         u_int8_t server_flags;
00224         u_int8_t server_state;
00225         u_int8_t tls_reply;
00226         u_int8_t tls_request;
00227 
00228         /* Two-byte options. */
00229         u_int16_t ip_flags;
00230 
00231         /* Four-byte options. */
00232         u_int32_t addresses_transferred;
00233         u_int32_t assigned_addr;
00234         u_int32_t cltt;
00235         u_int32_t expiry;
00236         u_int32_t max_unacked;
00237         u_int32_t mclt;
00238         u_int32_t potential_expiry;
00239         u_int32_t receive_timer;
00240         u_int32_t stos;
00241 
00242         /* Arbitrary field options. */
00243         failover_option_t chaddr;
00244         failover_option_t client_identifier;
00245         failover_option_t hba;
00246         failover_option_t message;
00247         failover_option_t message_digest;
00248         failover_option_t relationship_name;
00249         failover_option_t reply_options;
00250         failover_option_t request_options;
00251         failover_option_t vendor_class;
00252         failover_option_t vendor_options;
00253 
00254         /* Special contents options. */
00255         ddns_fqdn_t ddns;
00256 } failover_message_t;
00257 
00258 typedef struct {
00259         OMAPI_OBJECT_PREAMBLE;
00260         struct option_cache *peer_address;
00261         unsigned peer_port;
00262         int options_present;
00263         enum dhcp_flink_state {
00264                 dhcp_flink_start,
00265                 dhcp_flink_message_length_wait,
00266                 dhcp_flink_message_wait,
00267                 dhcp_flink_disconnected,
00268                 dhcp_flink_state_max
00269         } state;
00270         failover_message_t *imsg;
00271         struct _dhcp_failover_state *state_object;
00272         u_int16_t imsg_len;
00273         unsigned imsg_count;
00274         u_int8_t imsg_payoff; /* Pay*load* offset. :') */
00275         u_int32_t xid;
00276 } dhcp_failover_link_t;
00277 
00278 typedef struct _dhcp_failover_listener {
00279         OMAPI_OBJECT_PREAMBLE;
00280         struct _dhcp_failover_listener *next;
00281         omapi_addr_t address;
00282 } dhcp_failover_listener_t;
00283 #endif /* FAILOVER_PROTOCOL */
00284 
00285 /* A failover peer's running state. */
00286 enum failover_state {
00287         unknown_state                   =  0, /* XXX: Not a standard state. */
00288         startup                         =  1,
00289         normal                          =  2,
00290         communications_interrupted      =  3,
00291         partner_down                    =  4,
00292         potential_conflict              =  5,
00293         recover                         =  6,
00294         paused                          =  7,
00295         shut_down                       =  8,
00296         recover_done                    =  9,
00297         resolution_interrupted          = 10,
00298         conflict_done                   = 11,
00299 
00300         /* Draft revision 12 of the failover protocol documents a RECOVER-WAIT
00301          * state, but does not enumerate its value in the section 12.24
00302          * table.  ISC DHCP 3.0.x used value 254 even though the state was
00303          * not documented at all.  For the time being, we will continue to use
00304          * this value.
00305          */
00306         recover_wait                    = 254
00307 };
00308 
00309 /* Service states are simplifications of failover states, particularly
00310    useful because the startup state isn't actually implementable as a
00311    separate failover state without maintaining a state stack. */
00312 
00313 enum service_state {
00314         unknown_service_state,
00315         cooperating,
00316         not_cooperating,
00317         service_partner_down,
00318         not_responding,
00319         service_startup
00320 };
00321 
00322 #if defined (FAILOVER_PROTOCOL)
00323 typedef struct _dhcp_failover_config {
00324         struct option_cache *address;
00325         int port;
00326         u_int32_t max_flying_updates;
00327         enum failover_state state;
00328         TIME stos;
00329         u_int32_t max_response_delay;
00330 } dhcp_failover_config_t;
00331 
00332 typedef struct _dhcp_failover_state {
00333         OMAPI_OBJECT_PREAMBLE;
00334         struct _dhcp_failover_state *next;
00335         char *name;                     /* Name of this failover instance. */
00336         dhcp_failover_config_t me;      /* My configuration. */
00337         dhcp_failover_config_t partner; /* Partner's configuration. */
00338         enum failover_state saved_state; /* Saved state during startup. */
00339         struct data_string server_identifier; /* Server identifier (IP addr) */
00340         u_int32_t mclt;
00341 
00342         u_int8_t *hba;  /* Hash bucket array for load balancing. */
00343         int load_balance_max_secs;
00344 
00345         u_int32_t max_lease_misbalance, max_lease_ownership;
00346         u_int32_t max_balance, min_balance;
00347         TIME last_balance, sched_balance;
00348 
00349         u_int32_t auto_partner_down;
00350 
00351         enum service_state service_state;
00352         const char *nrr;        /* Printable reason why we're in the
00353                                    not_responding service state (empty
00354                                    string if we are responding. */
00355 
00356         dhcp_failover_link_t *link_to_peer;     /* Currently-established link
00357                                                    to peer. */
00358 
00359         enum {
00360                 primary, secondary
00361         } i_am;         /* We are primary or secondary in this relationship. */
00362 
00363         TIME last_packet_sent;          /* Timestamp on last packet we sent. */
00364         TIME last_timestamp_received;   /* The last timestamp we sent that
00365                                            has been returned by our partner. */
00366         TIME skew;      /* The skew between our clock and our partner's. */
00367         struct lease *update_queue_head; /* List of leases we haven't sent
00368                                             to peer. */
00369         struct lease *update_queue_tail;
00370 
00371         struct lease *ack_queue_head;   /* List of lease updates the peer
00372                                            hasn't yet acked. */
00373         struct lease *ack_queue_tail;
00374 
00375         struct lease *send_update_done; /* When we get a BNDACK for this
00376                                            lease, send an UPDDONE message. */
00377         int cur_unacked_updates;        /* Number of updates we've sent
00378                                            that have not yet been acked. */
00379 
00380                                         /* List of messages which we haven't
00381                                            acked yet. */
00382         failover_message_t *toack_queue_head;
00383         failover_message_t *toack_queue_tail;
00384         int pending_acks;               /* Number of messages in the toack
00385                                            queue. */
00386         int pool_count;                 /* Number of pools referencing this
00387                                            failover state object. */
00388         int curUPD;                     /* If an UPDREQ* message is in motion,
00389                                            this value indicates which one. */
00390         u_int32_t updxid;               /* XID of UPDREQ* message in action. */
00391 } dhcp_failover_state_t;
00392 
00393 #define DHCP_FAILOVER_VERSION           1
00394 #endif /* FAILOVER_PROTOCOL */

Generated on 5 Apr 2014 for ISC DHCP by  doxygen 1.6.1