1 /* 2 * Copyright (c) 2002 Michael Shalayeff. All rights reserved. 3 * Copyright (c) 2003 Ryan McBride. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 18 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 22 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 23 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 24 * THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 /* 28 * The CARP header layout is as follows: 29 * 30 * 0 1 2 3 31 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 32 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 33 * |Version| Type | VirtualHostID | AdvSkew | Auth Len | 34 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 35 * | Reserved | AdvBase | Checksum | 36 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 37 * | Counter (1) | 38 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 39 * | Counter (2) | 40 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 41 * | SHA-1 HMAC (1) | 42 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 43 * | SHA-1 HMAC (2) | 44 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 45 * | SHA-1 HMAC (3) | 46 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 47 * | SHA-1 HMAC (4) | 48 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 49 * | SHA-1 HMAC (5) | 50 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 51 * 52 */ 53 54 #ifndef __IP_CARP_H__ 55 #define __IP_CARP_H__ 1 56 57 struct carp_header { 58 #ifdef WORDS_BIGENDIAN 59 u_int8_t carp_version:4, 60 carp_type:4; 61 #else 62 u_int8_t carp_type:4, 63 carp_version:4; 64 #endif 65 u_int8_t carp_vhid; /* virtual host id */ 66 u_int8_t carp_advskew; /* advertisement skew */ 67 u_int8_t carp_authlen; /* size of counter+md, 32bit chunks */ 68 u_int8_t carp_pad1; /* reserved */ 69 u_int8_t carp_advbase; /* advertisement interval */ 70 u_int16_t carp_cksum; 71 u_int32_t carp_counter[2]; 72 unsigned char carp_md[20]; /* SHA1 HMAC */ 73 } __packed; 74 75 #define CARP_DFLTTL 255 76 77 /* carp_version */ 78 #define CARP_VERSION 2 79 80 /* carp_type */ 81 #define CARP_ADVERTISEMENT 0x01 82 83 #define CARP_KEY_LEN 20 /* a sha1 hash of a passphrase */ 84 85 /* carp_advbase */ 86 #define CARP_DFLTINTV 1 87 88 #define CARP_BULK_UPDATE_MIN_DELAY 240 89 90 /* 91 * Statistics. 92 */ 93 struct carpstats { 94 u_int64_t carps_ipackets; /* total input packets, IPv4 */ 95 u_int64_t carps_ipackets6; /* total input packets, IPv6 */ 96 u_int64_t carps_badif; /* wrong interface */ 97 u_int64_t carps_badttl; /* TTL is not CARP_DFLTTL */ 98 u_int64_t carps_hdrops; /* packets shorter than header */ 99 u_int64_t carps_badsum; /* bad checksum */ 100 u_int64_t carps_badver; /* bad (incl unsupp) version */ 101 u_int64_t carps_badlen; /* data length does not match */ 102 u_int64_t carps_badauth; /* bad authentication */ 103 u_int64_t carps_badvhid; /* bad VHID */ 104 u_int64_t carps_badaddrs; /* bad address list */ 105 106 u_int64_t carps_opackets; /* total output packets, IPv4 */ 107 u_int64_t carps_opackets6; /* total output packets, IPv6 */ 108 u_int64_t carps_onomem; /* no memory for an mbuf */ 109 u_int64_t carps_ostates; /* total state updates sent */ 110 111 u_int64_t carps_preempt; /* if enabled, preemptions */ 112 }; 113 114 /* 115 * Configuration structure for SIOCSVH SIOCGVH 116 */ 117 struct carpreq { 118 int carpr_state; 119 #define CARP_STATES "INIT", "BACKUP", "MASTER" 120 #define CARP_MAXSTATE 2 121 int carpr_vhid; 122 int carpr_advskew; 123 int carpr_advbase; 124 unsigned char carpr_key[CARP_KEY_LEN]; 125 }; 126 #define SIOCSVH _IOWR('i', 245, struct ifreq) 127 #define SIOCGVH _IOWR('i', 246, struct ifreq) 128 129 /* 130 * Names for CARP sysctl objects 131 */ 132 #define CARPCTL_ALLOW 1 /* accept incoming CARP packets */ 133 #define CARPCTL_PREEMPT 2 /* high-pri backup preemption mode */ 134 #define CARPCTL_LOG 3 /* log bad packets */ 135 #define CARPCTL_ARPBALANCE 4 /* balance arp responses */ 136 #define CARPCTL_MAXID 5 137 138 #define CARPCTL_NAMES { \ 139 { 0, 0 }, \ 140 { "allow", CTLTYPE_INT }, \ 141 { "preempt", CTLTYPE_INT }, \ 142 { "log", CTLTYPE_INT }, \ 143 { "arpbalance", CTLTYPE_INT }, \ 144 } 145 146 #endif 147