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