ip_carp.h revision 156947
1271294Sngie/* $FreeBSD: head/sys/netinet/ip_carp.h 156947 2006-03-21 14:29:48Z glebius $ */ 2271294Sngie/* $OpenBSD: ip_carp.h,v 1.8 2004/07/29 22:12:15 mcbride Exp $ */ 3271294Sngie 4271294Sngie/* 5271294Sngie * Copyright (c) 2002 Michael Shalayeff. All rights reserved. 6271294Sngie * Copyright (c) 2003 Ryan McBride. All rights reserved. 7271294Sngie * 8271294Sngie * Redistribution and use in source and binary forms, with or without 9271294Sngie * modification, are permitted provided that the following conditions 10271294Sngie * are met: 11271294Sngie * 1. Redistributions of source code must retain the above copyright 12271294Sngie * notice, this list of conditions and the following disclaimer. 13271294Sngie * 2. Redistributions in binary form must reproduce the above copyright 14271294Sngie * notice, this list of conditions and the following disclaimer in the 15271294Sngie * documentation and/or other materials provided with the distribution. 16271294Sngie * 17271294Sngie * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18271294Sngie * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19271294Sngie * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20271294Sngie * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 21271294Sngie * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22271294Sngie * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23271294Sngie * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24271294Sngie * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25271294Sngie * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 26271294Sngie * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27271294Sngie * THE POSSIBILITY OF SUCH DAMAGE. 28271294Sngie */ 29271294Sngie 30271294Sngie#ifndef _IP_CARP_H 31271294Sngie#define _IP_CARP_H 32271294Sngie 33271294Sngie/* 34271294Sngie * The CARP header layout is as follows: 35271294Sngie * 36271294Sngie * 0 1 2 3 37271294Sngie * 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 38271294Sngie * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 39271294Sngie * |Version| Type | VirtualHostID | AdvSkew | Auth Len | 40271294Sngie * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 41271294Sngie * | Reserved | AdvBase | Checksum | 42271294Sngie * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 43271294Sngie * | Counter (1) | 44271294Sngie * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 45271294Sngie * | Counter (2) | 46271294Sngie * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 47271294Sngie * | SHA-1 HMAC (1) | 48271294Sngie * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 49271294Sngie * | SHA-1 HMAC (2) | 50271294Sngie * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 51271294Sngie * | SHA-1 HMAC (3) | 52271294Sngie * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 53271294Sngie * | SHA-1 HMAC (4) | 54271294Sngie * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 55271294Sngie * | SHA-1 HMAC (5) | 56271294Sngie * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 57271294Sngie * 58271294Sngie */ 59 60struct carp_header { 61#if BYTE_ORDER == LITTLE_ENDIAN 62 u_int8_t carp_type:4, 63 carp_version:4; 64#endif 65#if BYTE_ORDER == BIG_ENDIAN 66 u_int8_t carp_version:4, 67 carp_type:4; 68#endif 69 u_int8_t carp_vhid; /* virtual host id */ 70 u_int8_t carp_advskew; /* advertisement skew */ 71 u_int8_t carp_authlen; /* size of counter+md, 32bit chunks */ 72 u_int8_t carp_pad1; /* reserved */ 73 u_int8_t carp_advbase; /* advertisement interval */ 74 u_int16_t carp_cksum; 75 u_int32_t carp_counter[2]; 76 unsigned char carp_md[20]; /* SHA1 HMAC */ 77} __packed; 78 79#define CARP_DFLTTL 255 80 81/* carp_version */ 82#define CARP_VERSION 2 83 84/* carp_type */ 85#define CARP_ADVERTISEMENT 0x01 86 87#define CARP_KEY_LEN 20 /* a sha1 hash of a passphrase */ 88 89/* carp_advbase */ 90#define CARP_DFLTINTV 1 91 92/* 93 * Statistics. 94 */ 95struct carpstats { 96 uint64_t carps_ipackets; /* total input packets, IPv4 */ 97 uint64_t carps_ipackets6; /* total input packets, IPv6 */ 98 uint64_t carps_badif; /* wrong interface */ 99 uint64_t carps_badttl; /* TTL is not CARP_DFLTTL */ 100 uint64_t carps_hdrops; /* packets shorter than hdr */ 101 uint64_t carps_badsum; /* bad checksum */ 102 uint64_t carps_badver; /* bad (incl unsupp) version */ 103 uint64_t carps_badlen; /* data length does not match */ 104 uint64_t carps_badauth; /* bad authentication */ 105 uint64_t carps_badvhid; /* bad VHID */ 106 uint64_t carps_badaddrs; /* bad address list */ 107 108 uint64_t carps_opackets; /* total output packets, IPv4 */ 109 uint64_t carps_opackets6; /* total output packets, IPv6 */ 110 uint64_t carps_onomem; /* no memory for an mbuf */ 111 uint64_t carps_ostates; /* total state updates sent */ 112 113 uint64_t carps_preempt; /* if enabled, preemptions */ 114}; 115 116/* 117 * Configuration structure for SIOCSVH SIOCGVH 118 */ 119struct carpreq { 120 int carpr_state; 121#define CARP_STATES "INIT", "BACKUP", "MASTER" 122#define CARP_MAXSTATE 2 123 int carpr_vhid; 124 int carpr_advskew; 125 int carpr_advbase; 126 unsigned char carpr_key[CARP_KEY_LEN]; 127}; 128#define SIOCSVH _IOWR('i', 245, struct ifreq) 129#define SIOCGVH _IOWR('i', 246, struct ifreq) 130 131/* 132 * Names for CARP sysctl objects 133 */ 134#define CARPCTL_ALLOW 1 /* accept incoming CARP packets */ 135#define CARPCTL_PREEMPT 2 /* high-pri backup preemption mode */ 136#define CARPCTL_LOG 3 /* log bad packets */ 137#define CARPCTL_STATS 4 /* statistics (read-only) */ 138#define CARPCTL_ARPBALANCE 5 /* balance arp responses */ 139#define CARPCTL_MAXID 6 140 141#define CARPCTL_NAMES { \ 142 { 0, 0 }, \ 143 { "allow", CTLTYPE_INT }, \ 144 { "preempt", CTLTYPE_INT }, \ 145 { "log", CTLTYPE_INT }, \ 146 { "stats", CTLTYPE_STRUCT }, \ 147 { "arpbalance", CTLTYPE_INT }, \ 148} 149 150#ifdef _KERNEL 151void carp_carpdev_state(void *); 152void carp_input (struct mbuf *, int); 153int carp6_input (struct mbuf **, int *, int); 154int carp_output (struct ifnet *, struct mbuf *, struct sockaddr *, 155 struct rtentry *); 156int carp_iamatch (void *, struct in_ifaddr *, struct in_addr *, 157 u_int8_t **); 158struct ifaddr *carp_iamatch6(void *, struct in6_addr *); 159void *carp_macmatch6(void *, struct mbuf *, const struct in6_addr *); 160struct ifnet *carp_forus (void *, void *); 161#endif 162#endif /* _IP_CARP_H */ 163