/* $OpenBSD: ip_carp.h,v 1.8 2004/07/29 22:12:15 mcbride Exp $ */12/*-3* SPDX-License-Identifier: BSD-2-Clause4*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 without9* modification, are permitted provided that the following conditions10* are met:11* 1. Redistributions of source code must retain the above copyright12* notice, this list of conditions and the following disclaimer.13* 2. Redistributions in binary form must reproduce the above copyright14* notice, this list of conditions and the following disclaimer in the15* documentation and/or other materials provided with the distribution.16*17* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR18* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES19* 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 DAMAGES22* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR23* 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) ARISING26* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF27* THE POSSIBILITY OF SUCH DAMAGE.28*/2930#ifndef _IP_CARP_H31#define _IP_CARP_H3233#ifdef _KERNEL34/*35* The CARP header layout is as follows:36*37* 0 1 2 338* 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 139* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+40* |Version| Type | VirtualHostID | AdvSkew | Auth Len |41* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+42* | Reserved | AdvBase | Checksum |43* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+44* | Counter (1) |45* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+46* | Counter (2) |47* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+48* | SHA-1 HMAC (1) |49* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+50* | SHA-1 HMAC (2) |51* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+52* | SHA-1 HMAC (3) |53* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+54* | SHA-1 HMAC (4) |55* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+56* | SHA-1 HMAC (5) |57* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+58*59*/6061struct carp_header {62#if BYTE_ORDER == LITTLE_ENDIAN63u_int8_t carp_type:4,64carp_version:4;65#endif66#if BYTE_ORDER == BIG_ENDIAN67u_int8_t carp_version:4,68carp_type:4;69#endif70u_int8_t carp_vhid; /* virtual host id */71u_int8_t carp_advskew; /* advertisement skew */72u_int8_t carp_authlen; /* size of counter+md, 32bit chunks */73u_int8_t carp_pad1; /* reserved */74u_int8_t carp_advbase; /* advertisement interval */75u_int16_t carp_cksum;76u_int32_t carp_counter[2];77unsigned char carp_md[20]; /* SHA1 HMAC */78} __packed;7980CTASSERT(sizeof(struct carp_header) == 36);8182/*83* The VRRPv3 header layout is as follows:84* See RFC9568, 5.1. VRRP Packet Format85*86* 0 1 2 387* 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 188* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+89* |Version| Type | Virtual Rtr ID| Priority |Count IPvX Addr|90* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+91* |(rsvd) | Max Adver Int | Checksum |92* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+93* | |94* + +95* | IPvX Address(es) |96* + +97* + +98* + +99* + +100* | |101* + +102* | |103* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+104*105*/106107struct vrrpv3_header {108#if BYTE_ORDER == LITTLE_ENDIAN109uint8_t vrrp_type:4,110vrrp_version:4;111#endif112#if BYTE_ORDER == BIG_ENDIAN113uint8_t vrrp_version:4,114vrrp_type:4;115#endif116uint8_t vrrp_vrtid;117uint8_t vrrp_priority;118uint8_t vrrp_count_addr;119uint16_t vrrp_max_adver_int;120uint16_t vrrp_checksum;121} __packed;122123CTASSERT(sizeof(struct vrrpv3_header) == 8);124#endif /* _KERNEL */125126#define CARP_DFLTTL 255127128/* carp_type */129#define CARP_ADVERTISEMENT 0x01130131#define CARP_KEY_LEN 20 /* a sha1 hash of a passphrase */132133/* carp_advbase */134#define CARP_DFLTINTV 1135136#define VRRP_TYPE_ADVERTISEMENT 0x01137#define VRRP_MAX_INTERVAL (0x1000 - 1)138/*139* Statistics.140*/141struct carpstats {142uint64_t carps_ipackets; /* total input packets, IPv4 */143uint64_t carps_ipackets6; /* total input packets, IPv6 */144uint64_t carps_badif; /* wrong interface */145uint64_t carps_badttl; /* TTL is not CARP_DFLTTL */146uint64_t carps_hdrops; /* packets shorter than hdr */147uint64_t carps_badsum; /* bad checksum */148uint64_t carps_badver; /* bad (incl unsupp) version */149uint64_t carps_badlen; /* data length does not match */150uint64_t carps_badauth; /* bad authentication */151uint64_t carps_badvhid; /* bad VHID */152uint64_t carps_badaddrs; /* bad address list */153154uint64_t carps_opackets; /* total output packets, IPv4 */155uint64_t carps_opackets6; /* total output packets, IPv6 */156uint64_t carps_onomem; /* no memory for an mbuf */157uint64_t carps_ostates; /* total state updates sent */158159uint64_t carps_preempt; /* if enabled, preemptions */160};161162/*163* Configuration structure for SIOCSVH SIOCGVH164*/165struct carpreq {166int carpr_count;167int carpr_vhid;168#define CARP_MAXVHID 255169int carpr_state;170#define CARP_STATES "INIT", "BACKUP", "MASTER"171#define CARP_MAXSTATE 2172int carpr_advskew;173#define CARP_MAXSKEW 240174int carpr_advbase;175unsigned char carpr_key[CARP_KEY_LEN];176};177#define SIOCSVH _IOWR('i', 245, struct ifreq)178#define SIOCGVH _IOWR('i', 246, struct ifreq)179180typedef enum carp_version {181CARP_VERSION_CARP = 2,182CARP_VERSION_VRRPv3 = 3,183} carp_version_t;184185#ifdef _KERNEL186int carp_ioctl(struct ifreq *, u_long, struct thread *);187int carp_attach(struct ifaddr *, int);188void carp_detach(struct ifaddr *, bool);189void carp_carpdev_state(struct ifnet *);190int carp_output (struct ifnet *, struct mbuf *,191const struct sockaddr *);192int carp_master(struct ifaddr *);193int carp_iamatch(struct ifaddr *, uint8_t **);194struct ifaddr *carp_iamatch6(struct ifnet *, struct in6_addr *);195char * carp_macmatch6(struct ifnet *, struct mbuf *, const struct in6_addr *);196int carp_forus(struct ifnet *, u_char *);197198/* These are external networking stack hooks for CARP */199/* net/if.c */200extern int (*carp_ioctl_p)(struct ifreq *, u_long, struct thread *);201extern int (*carp_attach_p)(struct ifaddr *, int);202extern void (*carp_detach_p)(struct ifaddr *, bool);203extern void (*carp_linkstate_p)(struct ifnet *);204extern void (*carp_demote_adj_p)(int, char *);205extern int (*carp_master_p)(struct ifaddr *);206/* net/if_bridge.c net/if_ethersubr.c */207extern int (*carp_forus_p)(struct ifnet *, u_char *);208/* net/if_ethersubr.c */209extern int (*carp_output_p)(struct ifnet *, struct mbuf *,210const struct sockaddr *);211/* net/rtsock.c */212extern int (*carp_get_vhid_p)(struct ifaddr *);213#ifdef INET214/* netinet/if_ether.c */215extern int (*carp_iamatch_p)(struct ifaddr *, uint8_t **);216#endif217#ifdef INET6218/* netinet6/nd6_nbr.c */219extern struct ifaddr *(*carp_iamatch6_p)(struct ifnet *, struct in6_addr *);220extern char * (*carp_macmatch6_p)(struct ifnet *, struct mbuf *,221const struct in6_addr *);222#endif223#endif224#endif /* _IP_CARP_H */225226227