root/netinet/ip_carp.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


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

/* [<][>][^][v][top][bottom][index][help] */