FreeBSD kernel IPv4 code
ip_carp.h
Go to the documentation of this file.
1/* $FreeBSD$ */
2/* $OpenBSD: ip_carp.h,v 1.8 2004/07/29 22:12:15 mcbride Exp $ */
3
4/*-
5 * SPDX-License-Identifier: BSD-2-Clause
6 *
7 * Copyright (c) 2002 Michael Shalayeff. All rights reserved.
8 * Copyright (c) 2003 Ryan McBride. All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29 * THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef _IP_CARP_H
33#define _IP_CARP_H
34
35/*
36 * The CARP header layout is as follows:
37 *
38 * 0 1 2 3
39 * 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
40 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 * |Version| Type | VirtualHostID | AdvSkew | Auth Len |
42 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 * | Reserved | AdvBase | Checksum |
44 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 * | Counter (1) |
46 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47 * | Counter (2) |
48 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49 * | SHA-1 HMAC (1) |
50 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51 * | SHA-1 HMAC (2) |
52 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
53 * | SHA-1 HMAC (3) |
54 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
55 * | SHA-1 HMAC (4) |
56 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
57 * | SHA-1 HMAC (5) |
58 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
59 *
60 */
61
63#if BYTE_ORDER == LITTLE_ENDIAN
64 u_int8_t carp_type:4,
66#endif
67#if BYTE_ORDER == BIG_ENDIAN
68 u_int8_t carp_version:4,
69 carp_type:4;
70#endif
71 u_int8_t carp_vhid; /* virtual host id */
72 u_int8_t carp_advskew; /* advertisement skew */
73 u_int8_t carp_authlen; /* size of counter+md, 32bit chunks */
74 u_int8_t carp_pad1; /* reserved */
75 u_int8_t carp_advbase; /* advertisement interval */
76 u_int16_t carp_cksum;
77 u_int32_t carp_counter[2];
78 unsigned char carp_md[20]; /* SHA1 HMAC */
80
81#ifdef CTASSERT
82CTASSERT(sizeof(struct carp_header) == 36);
83#endif
84
85#define CARP_DFLTTL 255
86
87/* carp_version */
88#define CARP_VERSION 2
89
90/* carp_type */
91#define CARP_ADVERTISEMENT 0x01
92
93#define CARP_KEY_LEN 20 /* a sha1 hash of a passphrase */
94
95/* carp_advbase */
96#define CARP_DFLTINTV 1
97
98/*
99 * Statistics.
100 */
101struct carpstats {
102 uint64_t carps_ipackets; /* total input packets, IPv4 */
103 uint64_t carps_ipackets6; /* total input packets, IPv6 */
104 uint64_t carps_badif; /* wrong interface */
105 uint64_t carps_badttl; /* TTL is not CARP_DFLTTL */
106 uint64_t carps_hdrops; /* packets shorter than hdr */
107 uint64_t carps_badsum; /* bad checksum */
108 uint64_t carps_badver; /* bad (incl unsupp) version */
109 uint64_t carps_badlen; /* data length does not match */
110 uint64_t carps_badauth; /* bad authentication */
111 uint64_t carps_badvhid; /* bad VHID */
112 uint64_t carps_badaddrs; /* bad address list */
113
114 uint64_t carps_opackets; /* total output packets, IPv4 */
115 uint64_t carps_opackets6; /* total output packets, IPv6 */
116 uint64_t carps_onomem; /* no memory for an mbuf */
117 uint64_t carps_ostates; /* total state updates sent */
118
119 uint64_t carps_preempt; /* if enabled, preemptions */
120};
121
122/*
123 * Configuration structure for SIOCSVH SIOCGVH
124 */
125struct carpreq {
128#define CARP_MAXVHID 255
130#define CARP_STATES "INIT", "BACKUP", "MASTER"
131#define CARP_MAXSTATE 2
133#define CARP_MAXSKEW 240
135 unsigned char carpr_key[CARP_KEY_LEN];
136};
137#define SIOCSVH _IOWR('i', 245, struct ifreq)
138#define SIOCGVH _IOWR('i', 246, struct ifreq)
139
140#ifdef _KERNEL
141int carp_ioctl(struct ifreq *, u_long, struct thread *);
142int carp_attach(struct ifaddr *, int);
143void carp_detach(struct ifaddr *, bool);
144void carp_carpdev_state(struct ifnet *);
145int carp_input(struct mbuf **, int *, int);
146int carp6_input (struct mbuf **, int *, int);
147int carp_output (struct ifnet *, struct mbuf *,
148 const struct sockaddr *);
149int carp_master(struct ifaddr *);
150int carp_iamatch(struct ifaddr *, uint8_t **);
151struct ifaddr *carp_iamatch6(struct ifnet *, struct in6_addr *);
152char * carp_macmatch6(struct ifnet *, struct mbuf *, const struct in6_addr *);
153int carp_forus(struct ifnet *, u_char *);
154
155/* These are external networking stack hooks for CARP */
156/* net/if.c */
157extern int (*carp_ioctl_p)(struct ifreq *, u_long, struct thread *);
158extern int (*carp_attach_p)(struct ifaddr *, int);
159extern void (*carp_detach_p)(struct ifaddr *, bool);
160extern void (*carp_linkstate_p)(struct ifnet *);
161extern void (*carp_demote_adj_p)(int, char *);
162extern int (*carp_master_p)(struct ifaddr *);
163/* net/if_bridge.c net/if_ethersubr.c */
164extern int (*carp_forus_p)(struct ifnet *, u_char *);
165/* net/if_ethersubr.c */
166extern int (*carp_output_p)(struct ifnet *, struct mbuf *,
167 const struct sockaddr *);
168/* net/rtsock.c */
169extern int (*carp_get_vhid_p)(struct ifaddr *);
170#ifdef INET
171/* netinet/if_ether.c */
172extern int (*carp_iamatch_p)(struct ifaddr *, uint8_t **);
173#endif
174#ifdef INET6
175/* netinet6/nd6_nbr.c */
176extern struct ifaddr *(*carp_iamatch6_p)(struct ifnet *, struct in6_addr *);
177extern char * (*carp_macmatch6_p)(struct ifnet *, struct mbuf *,
178 const struct in6_addr *);
179#endif
180#endif
181#endif /* _IP_CARP_H */
__uint8_t uint8_t
Definition: in.h:52
CTASSERT(DXR_TRIE_BITS >=16 &&DXR_TRIE_BITS<=24)
#define CARP_KEY_LEN
Definition: ip_carp.h:93
int carp_iamatch(struct ifaddr *, uint8_t **)
int(* carp_output_p)(struct ifnet *, struct mbuf *, const struct sockaddr *)
void carp_carpdev_state(struct ifnet *)
int carp_forus(struct ifnet *, u_char *)
Definition: ip_carp.c:1243
int carp_input(struct mbuf **, int *, int)
int(* carp_ioctl_p)(struct ifreq *, u_long, struct thread *)
int carp_master(struct ifaddr *)
Definition: ip_carp.c:1124
int(* carp_get_vhid_p)(struct ifaddr *)
int(* carp_master_p)(struct ifaddr *)
void carp_detach(struct ifaddr *, bool)
Definition: ip_carp.c:1986
void(* carp_linkstate_p)(struct ifnet *)
int carp_ioctl(struct ifreq *, u_long, struct thread *)
Definition: ip_carp.c:1733
int carp_output(struct ifnet *, struct mbuf *, const struct sockaddr *)
Definition: ip_carp.c:1527
struct carp_header __packed
char * carp_macmatch6(struct ifnet *, struct mbuf *, const struct in6_addr *)
void(* carp_demote_adj_p)(int, char *)
int carp_attach(struct ifaddr *, int)
Definition: ip_carp.c:1910
void(* carp_detach_p)(struct ifaddr *, bool)
int carp6_input(struct mbuf **, int *, int)
struct ifaddr * carp_iamatch6(struct ifnet *, struct in6_addr *)
int(* carp_forus_p)(struct ifnet *, u_char *)
int(* carp_attach_p)(struct ifaddr *, int)
u_int8_t carp_advskew
Definition: ip_carp.h:72
u_int8_t carp_advbase
Definition: ip_carp.h:75
u_int8_t carp_type
Definition: ip_carp.h:64
u_int8_t carp_authlen
Definition: ip_carp.h:73
unsigned char carp_md[20]
Definition: ip_carp.h:78
u_int32_t carp_counter[2]
Definition: ip_carp.h:77
u_int8_t carp_pad1
Definition: ip_carp.h:74
u_int16_t carp_cksum
Definition: ip_carp.h:76
u_int8_t carp_vhid
Definition: ip_carp.h:71
u_int8_t carp_version
Definition: ip_carp.h:65
int carpr_advbase
Definition: ip_carp.h:134
int carpr_count
Definition: ip_carp.h:126
int carpr_state
Definition: ip_carp.h:129
int carpr_vhid
Definition: ip_carp.h:127
unsigned char carpr_key[CARP_KEY_LEN]
Definition: ip_carp.h:135
int carpr_advskew
Definition: ip_carp.h:132
uint64_t carps_badauth
Definition: ip_carp.h:110
uint64_t carps_badver
Definition: ip_carp.h:108
uint64_t carps_ipackets6
Definition: ip_carp.h:103
uint64_t carps_badttl
Definition: ip_carp.h:105
uint64_t carps_opackets6
Definition: ip_carp.h:115
uint64_t carps_preempt
Definition: ip_carp.h:119
uint64_t carps_badsum
Definition: ip_carp.h:107
uint64_t carps_ipackets
Definition: ip_carp.h:102
uint64_t carps_badlen
Definition: ip_carp.h:109
uint64_t carps_badaddrs
Definition: ip_carp.h:112
uint64_t carps_badif
Definition: ip_carp.h:104
uint64_t carps_hdrops
Definition: ip_carp.h:106
uint64_t carps_onomem
Definition: ip_carp.h:116
uint64_t carps_ostates
Definition: ip_carp.h:117
uint64_t carps_badvhid
Definition: ip_carp.h:111
uint64_t carps_opackets
Definition: ip_carp.h:114