Annotation of embedaddon/pimd/vif.h, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (c) 1998-2001
                      3:  * University of Southern California/Information Sciences Institute.
                      4:  * All rights reserved.
                      5:  *
                      6:  * Redistribution and use in source and binary forms, with or without
                      7:  * modification, are permitted provided that the following conditions
                      8:  * are met:
                      9:  * 1. Redistributions of source code must retain the above copyright
                     10:  *    notice, this list of conditions and the following disclaimer.
                     11:  * 2. Redistributions in binary form must reproduce the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer in the
                     13:  *    documentation and/or other materials provided with the distribution.
                     14:  * 3. Neither the name of the project nor the names of its contributors
                     15:  *    may be used to endorse or promote products derived from this software
                     16:  *    without specific prior written permission.
                     17:  *
                     18:  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
                     19:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     20:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     21:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
                     22:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     23:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     24:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     25:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     26:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     27:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     28:  * SUCH DAMAGE.
                     29:  */
                     30: /*
                     31:  * Part of this program has been derived from mrouted.
                     32:  * The mrouted program is covered by the license in the accompanying file
                     33:  * named "LICENSE.mrouted".
                     34:  *
                     35:  * The mrouted program is COPYRIGHT 1989 by The Board of Trustees of
                     36:  * Leland Stanford Junior University.
                     37:  *
                     38:  */
                     39: 
                     40: 
                     41: /*
                     42:  * Bitmap handling functions.
                     43:  * These should be fast but generic.  bytes can be slow to zero and compare,
                     44:  * words are hard to make generic.  Thus two sets of macros (yuk).
                     45:  */
                     46: 
                     47: /*
                     48:  * The VIFM_ functions should migrate out of <netinet/ip_mroute.h>, since
                     49:  * the kernel no longer uses vifbitmaps.
                     50:  */
                     51: #ifndef VIFM_SET
                     52: 
                     53: typedef        uint32_t vifbitmap_t;
                     54: 
                     55: #define        VIFM_SET(n, m)                  ((m) |=  (1 << (n)))
                     56: #define        VIFM_CLR(n, m)                  ((m) &= ~(1 << (n)))
                     57: #define        VIFM_ISSET(n, m)                ((m) &   (1 << (n)))
                     58: #define VIFM_CLRALL(m)                 ((m) = 0x00000000)
                     59: #define VIFM_COPY(mfrom, mto)          ((mto) = (mfrom))
                     60: #define VIFM_SAME(m1, m2)              ((m1) == (m2))
                     61: #endif
                     62: /*
                     63:  * And <netinet/ip_mroute.h> was missing some required functions anyway
                     64:  */
                     65: #if !defined(VIFM_SETALL)
                     66: #define        VIFM_SETALL(m)                  ((m) = ~0)
                     67: #endif
                     68: #define        VIFM_ISSET_ONLY(n, m)           ((m) == (1 << (n)))
                     69: #define        VIFM_ISEMPTY(m)                 ((m) == 0)
                     70: #define        VIFM_CLR_MASK(m, mask)          ((m) &= ~(mask))
                     71: #define        VIFM_SET_MASK(m, mask)          ((m) |= (mask))
                     72: #define VIFM_MERGE(m1, m2, result)      ((result) = (m1) | (m2))
                     73: 
                     74: /* Check whether I am the last hop on some LAN */
                     75: #define VIFM_LASTHOP_ROUTER(leaves, oifs)    ((leaves) & (oifs))
                     76: 
                     77: /*
                     78:  * Neighbor bitmaps are, for efficiency, implemented as a struct
                     79:  * containing two variables of a native machine type.  If you
                     80:  * have a native type that's bigger than a long, define it below.
                     81:  */
                     82: #define        NBRTYPE         uint32_t
                     83: #define NBRBITS                sizeof(NBRTYPE) * 8
                     84: 
                     85: typedef struct {
                     86:     NBRTYPE hi;
                     87:     NBRTYPE lo;
                     88: } nbrbitmap_t;
                     89: #define        MAXNBRS         2 * NBRBITS
                     90: 
                     91: #define        NBRM_SET(n, m)          (((n) < NBRBITS) ? ((m).lo |= (1 << (n))) :  \
                     92:                                      ((m).hi |= (1 << (n - NBRBITS))))
                     93: #define        NBRM_CLR(n, m)          (((n) < NBRBITS) ? ((m).lo &= ~(1 << (n))) : \
                     94:                                      ((m).hi &= ~(1 << (n - NBRBITS))))
                     95: #define        NBRM_ISSET(n, m)        (((n) < NBRBITS) ? ((m).lo & (1 << (n))) :   \
                     96:                                      ((m).hi & (1 << ((n) - NBRBITS))))
                     97: #define        NBRM_CLRALL(m)          ((m).lo = (m).hi = 0)
                     98: #define        NBRM_COPY(mfrom, mto)   ((mto).lo = (mfrom).lo, (mto).hi = (mfrom).hi)
                     99: #define        NBRM_SAME(m1, m2)       (((m1).lo == (m2).lo) && ((m1).hi == (m2).hi))
                    100: #define        NBRM_ISEMPTY(m)         (((m).lo == 0) && ((m).hi == 0))
                    101: #define        NBRM_SETMASK(m, mask)   (((m).lo |= (mask).lo),((m).hi |= (mask).hi))
                    102: #define        NBRM_CLRMASK(m, mask)   (((m).lo &= ~(mask).lo),((m).hi &= ~(mask).hi))
                    103: #define        NBRM_MASK(m, mask)      (((m).lo &= (mask).lo),((m).hi &= (mask).hi))
                    104: #define        NBRM_ISSETMASK(m, mask) (((m).lo & (mask).lo) || ((m).hi & (mask).hi))
                    105: #define        NBRM_ISSETALLMASK(m, mask)\
                    106:                                ((((m).lo & (mask).lo) == (mask).lo) && \
                    107:                                 (((m).hi & (mask).hi) == (mask).hi))
                    108: /*
                    109:  * This macro is TRUE if all the subordinates have been pruned, or if
                    110:  * there are no subordinates on this vif.
                    111:  * The arguments is the map of subordinates, the map of neighbors on the
                    112:  * vif, and the map of received prunes.
                    113:  */
                    114: #define        SUBS_ARE_PRUNED(sub, vifmask, prunes)   \
                    115:     (((sub).lo & (vifmask).lo) == ((prunes).lo & (vifmask).lo & (sub).lo) && \
                    116:      ((sub).hi & (vifmask).hi) == ((prunes).hi & (vifmask).hi & (sub).hi))
                    117: 
                    118: /*
                    119:  * User level Virtual Interface structure
                    120:  *
                    121:  * A "virtual interface" is either a physical, multicast-capable interface
                    122:  * (called a "phyint"), a virtual point-to-point link (called a "tunnel")
                    123:  * or a "register vif" used by PIM. The register vif is used by the
                    124:  * Designated Router (DR) to send encapsulated data packets to the
                    125:  * Rendevous Point (RP) for a particular group. The data packets are 
                    126:  * encapsulated in PIM messages (IPPROTO_PIM = 103) and then unicast to 
                    127:  * the RP.
                    128:  * (Note: all addresses, subnet numbers and masks are kept in NETWORK order.)
                    129:  */
                    130: struct uvif {
                    131:     u_int           uv_flags;      /* VIFF_ flags defined below            */
                    132:     uint8_t         uv_metric;     /* cost of this vif                     */
                    133:     uint8_t         uv_admetric;   /* advertised cost of this vif          */
                    134:     uint8_t         uv_threshold;  /* min ttl required to forward on vif   */
                    135:     u_int           uv_rate_limit; /* rate limit on this vif               */
                    136:     int              uv_mtu;        /* Initially interface MTU, then PMTU   */
                    137:     uint32_t        uv_lcl_addr;   /* local address of this vif            */
                    138:     uint32_t        uv_rmt_addr;   /* remote end-point addr (tunnels only) */
                    139:     uint32_t        uv_dst_addr;   /* destination for DVMRP/PIM messages   */
                    140:     uint32_t        uv_subnet;     /* subnet number         (phyints only) */
                    141:     uint32_t        uv_subnetmask; /* subnet mask           (phyints only) */
                    142:     uint32_t        uv_subnetbcast;/* subnet broadcast addr (phyints only) */
                    143:     char            uv_name[IFNAMSIZ]; /* interface name                   */
                    144:     struct listaddr *uv_groups;     /* list of local groups  (phyints only) */
                    145:     struct listaddr *uv_dvmrp_neighbors; /* list of neighboring routers     */
                    146:     nbrbitmap_t             uv_nbrmap;     /* bitmap of active neighboring routers */
                    147:     struct listaddr *uv_querier;    /* IGMP querier on vif                  */
                    148:     int                     uv_igmpv1_warn;/* To rate-limit IGMPv1 warnings        */
                    149:     int                     uv_prune_lifetime; /* Prune lifetime or 0 for default  */
                    150:     struct vif_acl  *uv_acl;       /* access control list of groups        */
                    151:     int                     uv_leaf_timer; /* time until this vif is considrd leaf */
                    152:     struct phaddr   *uv_addrs;     /* Additional subnets on this vif       */
                    153:     struct vif_filter *uv_filter;   /* Route filters on this vif           */
                    154:     uint16_t       uv_hello_timer; /* Timer for sending PIM hello msgs     */
                    155:     uint32_t        uv_dr_prio;     /* PIM Hello DR Priority                */
                    156:     uint32_t        uv_genid;       /* Random PIM Hello Generation ID       */
                    157:     uint16_t       uv_gq_timer;    /* Group Query timer                    */
                    158:     uint16_t        uv_jp_timer;    /* The Join/Prune timer                 */
                    159:     int             uv_local_pref;  /* default local preference for assert  */
                    160:     int             uv_local_metric;/* default local metric for assert      */
                    161:     struct pim_nbr_entry *uv_pim_neighbors; /* list of PIM neighbor routers */
                    162: #ifdef __linux__
                    163:     int             uv_ifindex;     /* because RTNETLINK returns only index */
                    164: #endif /* __linux__ */
                    165: };
                    166: 
                    167: /* TODO: define VIFF_KERNEL_FLAGS */
                    168: #define VIFF_KERNEL_FLAGS      (VIFF_TUNNEL | VIFF_SRCRT)
                    169: #define VIFF_DOWN              0x000100       /* kernel state of interface */
                    170: #define VIFF_DISABLED          0x000200       /* administratively disabled */
                    171: #define VIFF_QUERIER           0x000400       /* I am the subnet's querier */
                    172: #define VIFF_ONEWAY            0x000800       /* Maybe one way interface   */
                    173: #define VIFF_LEAF              0x001000       /* all neighbors are leaves  */
                    174: #define VIFF_IGMPV1            0x002000       /* Act as an IGMPv1 Router   */
                    175: #define        VIFF_REXMIT_PRUNES      0x004000       /* retransmit prunes         */
                    176: #define VIFF_PASSIVE           0x008000       /* passive tunnel            */
                    177: #define        VIFF_ALLOW_NONPRUNERS   0x010000       /* ok to peer with nonprunrs */
                    178: #define VIFF_NOFLOOD           0x020000       /* don't flood on this vif   */
                    179: #define        VIFF_DR                 0x040000       /* designated router         */
                    180: /* TODO: VIFF_NONBRS == VIFF_ONEWAY? */
                    181: #define        VIFF_NONBRS             0x080000       /* no neighbor on vif        */
                    182: #define VIFF_POINT_TO_POINT     0x100000       /* point-to-point link       */
                    183: #define VIFF_PIM_NBR            0x200000       /* PIM neighbor              */
                    184: #define VIFF_DVMRP_NBR          0x400000       /* DVMRP neighbor            */
                    185: #define VIFF_IGMPV2            0x800000       /* Act as an IGMPv2 Router   */
                    186: 
                    187: struct phaddr {
                    188:     struct phaddr   *pa_next;
                    189:     uint32_t        pa_subnet;         /* extra subnet                 */
                    190:     uint32_t        pa_subnetmask;     /* netmask of extra subnet      */
                    191:     uint32_t        pa_subnetbcast;    /* broadcast of extra subnet    */
                    192: };
                    193: 
                    194: /* The Access Control List (list with scoped addresses) member */
                    195: struct vif_acl {
                    196:     struct vif_acl  *acl_next;     /* next acl member         */
                    197:     uint32_t        acl_addr;      /* Group address           */
                    198:     uint32_t        acl_mask;      /* Group addr. mask        */
                    199: };
                    200: 
                    201: struct vif_filter {
                    202:     int                        vf_type;
                    203: #define        VFT_ACCEPT      1
                    204: #define        VFT_DENY        2
                    205:     int                        vf_flags;
                    206: #define        VFF_BIDIR       1
                    207:     struct vf_element  *vf_filter;
                    208: };
                    209: 
                    210: struct vf_element {
                    211:     struct vf_element  *vfe_next;
                    212:     uint32_t           vfe_addr;
                    213:     uint32_t           vfe_mask;
                    214:     int                        vfe_flags;
                    215: #define        VFEF_EXACT      0x0001
                    216: };
                    217: 
                    218: struct listaddr {
                    219:     struct listaddr *al_next;          /* link to next addr, MUST BE FIRST */
                    220:     uint32_t        al_addr;           /* local group or neighbor address  */
                    221:     struct listaddr *al_sources;       /* link to sources */
                    222:     uint32_t        al_timer;          /* for timing out group or neighbor */
                    223:     time_t          al_ctime;          /* entry creation time              */
                    224:     union {
                    225:        uint32_t     alu_genid;         /* generation id for neighbor       */
                    226:        uint32_t     alu_reporter;      /* a host which reported membership */
                    227:     } al_alu;
                    228:     uint8_t         al_pv;             /* router protocol version          */
                    229:     uint8_t         al_mv;             /* router mrouted version           */
                    230:     uint8_t         al_old;            /* time since heard old report      */
                    231:     uint8_t         al_index;          /* neighbor index                   */
                    232:     uint32_t        al_timerid;        /* timer for group membership       */
                    233:     uint32_t        al_query;          /* timer for repeated leave query   */
                    234:     uint16_t        al_flags;          /* flags related to this neighbor   */
                    235:     u_long          al_versiontimer;   /* timer for version switch    */
                    236: };
                    237: #define        al_genid        al_alu.alu_genid
                    238: #define        al_reporter     al_alu.alu_reporter
                    239: 
                    240: #define        NBRF_LEAF               0x0001  /* This neighbor is a leaf          */
                    241: #define        NBRF_GENID              0x0100  /* I know this neighbor's genid     */
                    242: #define        NBRF_WAITING            0x0200  /* Waiting for peering to come up   */
                    243: #define        NBRF_ONEWAY             0x0400  /* One-way peering                  */
                    244: #define        NBRF_TOOOLD             0x0800  /* Too old (policy decision)        */
                    245: #define        NBRF_TOOMANYROUTES      0x1000  /* Neighbor is spouting routes      */
                    246: #define        NBRF_NOTPRUNING         0x2000  /* Neighbor doesn't appear to prune */
                    247: 
                    248: /*
                    249:  * Don't peer with neighbors with any of these flags set
                    250:  */
                    251: #define        NBRF_DONTPEER           (NBRF_WAITING|NBRF_ONEWAY|NBRF_TOOOLD| \
                    252:                                 NBRF_TOOMANYROUTES|NBRF_NOTPRUNING)
                    253: 
                    254: #define NO_VIF         ((vifi_t)MAXVIFS)  /* An invalid vif index */
                    255:   
                    256: 
                    257: /*
                    258:  * Used to get the RPF neighbor and IIF info
                    259:  * for a given source from the unicast routing table. 
                    260:  */
                    261: struct rpfctl {
                    262:     struct in_addr source; /* the source for which we want iif and rpfnbr */
                    263:     struct in_addr rpfneighbor;/* next hop towards the source */
                    264:     vifi_t iif; /* the incoming interface to reach the next hop */
                    265: };
                    266: 
                    267: /**
                    268:  * Local Variables:
                    269:  *  version-control: t
                    270:  *  indent-tabs-mode: t
                    271:  *  c-file-style: "ellemtel"
                    272:  *  c-basic-offset: 4
                    273:  * End:
                    274:  */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>