Home | History | Annotate | Line # | Download | only in netinet
ip_carp.h revision 1.5.4.1
      1  1.5.4.1      yamt /*	$NetBSD: ip_carp.h,v 1.5.4.1 2010/03/11 15:04:28 yamt Exp $	*/
      2      1.1  liamjfoy /*	$OpenBSD: ip_carp.h,v 1.18 2005/04/20 23:00:41 mpf Exp $	*/
      3      1.1  liamjfoy 
      4      1.1  liamjfoy /*
      5      1.1  liamjfoy  * Copyright (c) 2002 Michael Shalayeff. All rights reserved.
      6      1.1  liamjfoy  * Copyright (c) 2003 Ryan McBride. All rights reserved.
      7      1.1  liamjfoy  *
      8      1.1  liamjfoy  * Redistribution and use in source and binary forms, with or without
      9      1.1  liamjfoy  * modification, are permitted provided that the following conditions
     10      1.1  liamjfoy  * are met:
     11      1.1  liamjfoy  * 1. Redistributions of source code must retain the above copyright
     12      1.1  liamjfoy  *    notice, this list of conditions and the following disclaimer.
     13      1.1  liamjfoy  * 2. Redistributions in binary form must reproduce the above copyright
     14      1.1  liamjfoy  *    notice, this list of conditions and the following disclaimer in the
     15      1.1  liamjfoy  *    documentation and/or other materials provided with the distribution.
     16      1.1  liamjfoy  *
     17      1.1  liamjfoy  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18      1.1  liamjfoy  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19      1.1  liamjfoy  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20      1.1  liamjfoy  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
     21      1.1  liamjfoy  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     22      1.1  liamjfoy  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     23      1.1  liamjfoy  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     24      1.1  liamjfoy  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     25      1.1  liamjfoy  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     26      1.1  liamjfoy  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     27      1.1  liamjfoy  * THE POSSIBILITY OF SUCH DAMAGE.
     28      1.1  liamjfoy  */
     29      1.1  liamjfoy 
     30      1.1  liamjfoy #ifndef _NETINET_IP_CARP_H_
     31      1.1  liamjfoy #define _NETINET_IP_CARP_H_
     32      1.1  liamjfoy 
     33      1.1  liamjfoy /*
     34      1.1  liamjfoy  * The CARP header layout is as follows:
     35      1.1  liamjfoy  *
     36      1.1  liamjfoy  *     0                   1                   2                   3
     37      1.1  liamjfoy  *     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
     38      1.1  liamjfoy  *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     39      1.1  liamjfoy  *    |Version| Type  | VirtualHostID |    AdvSkew    |    Auth Len   |
     40      1.1  liamjfoy  *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     41      1.1  liamjfoy  *    |   Reserved    |     AdvBase   |          Checksum             |
     42      1.1  liamjfoy  *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     43      1.1  liamjfoy  *    |                         Counter (1)                           |
     44      1.1  liamjfoy  *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     45      1.1  liamjfoy  *    |                         Counter (2)                           |
     46      1.1  liamjfoy  *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     47      1.1  liamjfoy  *    |                        SHA-1 HMAC (1)                         |
     48      1.1  liamjfoy  *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     49      1.1  liamjfoy  *    |                        SHA-1 HMAC (2)                         |
     50      1.1  liamjfoy  *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     51      1.1  liamjfoy  *    |                        SHA-1 HMAC (3)                         |
     52      1.1  liamjfoy  *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     53      1.1  liamjfoy  *    |                        SHA-1 HMAC (4)                         |
     54      1.1  liamjfoy  *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     55      1.1  liamjfoy  *    |                        SHA-1 HMAC (5)                         |
     56      1.1  liamjfoy  *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     57      1.1  liamjfoy  *
     58      1.1  liamjfoy  */
     59      1.1  liamjfoy 
     60      1.1  liamjfoy struct carp_header {
     61      1.1  liamjfoy #if BYTE_ORDER == LITTLE_ENDIAN
     62      1.5    dyoung 	unsigned int	carp_type:4,
     63      1.1  liamjfoy 			carp_version:4;
     64      1.1  liamjfoy #endif
     65      1.1  liamjfoy #if BYTE_ORDER == BIG_ENDIAN
     66      1.5    dyoung 	unsigned int	carp_version:4,
     67      1.1  liamjfoy 			carp_type:4;
     68      1.1  liamjfoy #endif
     69      1.1  liamjfoy 	u_int8_t	carp_vhid;	/* virtual host id */
     70      1.1  liamjfoy 	u_int8_t	carp_advskew;	/* advertisement skew */
     71      1.1  liamjfoy 	u_int8_t	carp_authlen;   /* size of counter+md, 32bit chunks */
     72      1.1  liamjfoy 	u_int8_t	carp_pad1;	/* reserved */
     73      1.1  liamjfoy 	u_int8_t	carp_advbase;	/* advertisement interval */
     74      1.1  liamjfoy 	u_int16_t	carp_cksum;
     75      1.1  liamjfoy 	u_int32_t	carp_counter[2];
     76      1.1  liamjfoy 	unsigned char	carp_md[20];	/* SHA1 HMAC */
     77      1.1  liamjfoy } __packed;
     78      1.1  liamjfoy 
     79      1.1  liamjfoy #define	CARP_DFLTTL		255
     80      1.1  liamjfoy 
     81      1.1  liamjfoy /* carp_version */
     82      1.1  liamjfoy #define	CARP_VERSION		2
     83      1.1  liamjfoy 
     84      1.1  liamjfoy /* carp_type */
     85      1.1  liamjfoy #define	CARP_ADVERTISEMENT	0x01
     86      1.1  liamjfoy 
     87      1.1  liamjfoy #define	CARP_KEY_LEN		20	/* a sha1 hash of a passphrase */
     88      1.1  liamjfoy 
     89      1.1  liamjfoy /* carp_advbase */
     90      1.1  liamjfoy #define	CARP_DFLTINTV		1
     91      1.1  liamjfoy 
     92      1.1  liamjfoy /*
     93      1.1  liamjfoy  * Statistics.
     94      1.1  liamjfoy  */
     95      1.4   thorpej #define	CARP_STAT_IPACKETS	0	/* total input packets, IPv4 */
     96      1.4   thorpej #define	CARP_STAT_IPACKETS6	1	/* total input packets, IPv6 */
     97      1.4   thorpej #define	CARP_STAT_BADIF		2	/* wrong interface */
     98      1.4   thorpej #define	CARP_STAT_BADTTL	3	/* TTL is not CARP_DFLTTL */
     99      1.4   thorpej #define	CARP_STAT_HDROPS	4	/* packets shorter than hdr */
    100      1.4   thorpej #define	CARP_STAT_BADSUM	5	/* bad checksum */
    101      1.4   thorpej #define	CARP_STAT_BADVER	6	/* bad (incl unsupported) version */
    102      1.4   thorpej #define	CARP_STAT_BADLEN	7	/* data length does not match */
    103      1.4   thorpej #define	CARP_STAT_BADAUTH	8	/* bad authentication */
    104      1.4   thorpej #define	CARP_STAT_BADVHID	9	/* bad VHID */
    105      1.4   thorpej #define	CARP_STAT_BADADDRS	10	/* bad address list */
    106      1.4   thorpej #define	CARP_STAT_OPACKETS	11	/* total output packets, IPv4 */
    107      1.4   thorpej #define	CARP_STAT_OPACKETS6	12	/* total output packets, IPv6 */
    108      1.4   thorpej #define	CARP_STAT_ONOMEM	13	/* no memory for an mbuf */
    109      1.4   thorpej #define	CARP_STAT_OSTATES	14	/* total state updates sent */
    110      1.4   thorpej #define	CARP_STAT_PREEMPT	15	/* in enabled, preemptions */
    111      1.1  liamjfoy 
    112      1.4   thorpej #define	CARP_NSTATS		16
    113      1.1  liamjfoy 
    114      1.1  liamjfoy #define CARPDEVNAMSIZ	16
    115      1.1  liamjfoy #ifdef IFNAMSIZ
    116      1.1  liamjfoy #if CARPDEVNAMSIZ != IFNAMSIZ
    117      1.1  liamjfoy #error
    118      1.1  liamjfoy #endif
    119      1.1  liamjfoy #endif
    120      1.1  liamjfoy 
    121      1.1  liamjfoy /*
    122      1.1  liamjfoy  * Configuration structure for SIOCSVH SIOCGVH
    123      1.1  liamjfoy  */
    124      1.1  liamjfoy struct carpreq {
    125      1.1  liamjfoy 	int		carpr_state;
    126      1.1  liamjfoy #define	CARP_STATES	"INIT", "BACKUP", "MASTER"
    127      1.1  liamjfoy #define	CARP_MAXSTATE	2
    128      1.1  liamjfoy 
    129      1.1  liamjfoy 	char		carpr_carpdev[CARPDEVNAMSIZ];
    130      1.1  liamjfoy 	int		carpr_vhid;
    131      1.1  liamjfoy 	int		carpr_advskew;
    132      1.1  liamjfoy 	int		carpr_advbase;
    133      1.1  liamjfoy 	unsigned char	carpr_key[CARP_KEY_LEN];
    134      1.1  liamjfoy };
    135      1.1  liamjfoy 
    136      1.1  liamjfoy /*
    137      1.1  liamjfoy  * Names for CARP sysctl objects
    138      1.1  liamjfoy  */
    139      1.1  liamjfoy #define	CARPCTL_ALLOW		1	/* accept incoming CARP packets */
    140      1.1  liamjfoy #define	CARPCTL_PREEMPT		2	/* high-pri backup preemption mode */
    141      1.1  liamjfoy #define	CARPCTL_LOG		3	/* log bad packets */
    142      1.1  liamjfoy #define	CARPCTL_ARPBALANCE	4	/* balance arp responses */
    143      1.1  liamjfoy #define CARPCTL_STATS		5	/* carp statistics */
    144      1.1  liamjfoy #define	CARPCTL_MAXID		6
    145      1.1  liamjfoy 
    146      1.1  liamjfoy #define	CARPCTL_NAMES { \
    147      1.1  liamjfoy 	{ 0, 0 }, \
    148      1.1  liamjfoy 	{ "allow", CTLTYPE_INT }, \
    149      1.1  liamjfoy 	{ "preempt", CTLTYPE_INT }, \
    150      1.1  liamjfoy 	{ "log", CTLTYPE_INT }, \
    151      1.1  liamjfoy 	{ "arpbalance", CTLTYPE_INT }, \
    152      1.1  liamjfoy }
    153      1.1  liamjfoy 
    154      1.1  liamjfoy #ifdef _KERNEL
    155  1.5.4.1      yamt void		 carp_init(void);
    156      1.1  liamjfoy void		 carp_ifdetach (struct ifnet *);
    157      1.1  liamjfoy void		 carp_proto_input (struct mbuf *, ...);
    158      1.1  liamjfoy void		 carp_carpdev_state(void *);
    159      1.1  liamjfoy int		 carp6_proto_input(struct mbuf **, int *, int);
    160      1.1  liamjfoy int		 carp_iamatch(struct in_ifaddr *, u_char *,
    161      1.1  liamjfoy 		     u_int32_t *, u_int32_t);
    162      1.1  liamjfoy struct ifaddr	*carp_iamatch6(void *, struct in6_addr *);
    163      1.1  liamjfoy struct ifnet	*carp_ourether(void *, struct ether_header *, u_char, int);
    164      1.1  liamjfoy int		 carp_input(struct mbuf *, u_int8_t *, u_int8_t *, u_int16_t);
    165      1.3    dyoung int		 carp_output(struct ifnet *, struct mbuf *,
    166      1.3    dyoung 		     const struct sockaddr *, struct rtentry *);
    167      1.1  liamjfoy #endif /* _KERNEL */
    168      1.1  liamjfoy #endif /* _NETINET_IP_CARP_H_ */
    169