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