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