MFC r1.6 r1.30 r1.28 (HEAD):
[dragonfly.git] / usr.sbin / mrouted / vif.h
blob1ef5c11633facd5dddc2b1ad01465e4d982dbea4
1 /*
2 * The mrouted program is covered by the license in the accompanying file
3 * named "LICENSE". Use of the mrouted program represents acceptance of
4 * the terms and conditions listed in that file.
6 * The mrouted program is COPYRIGHT 1989 by The Board of Trustees of
7 * Leland Stanford Junior University.
10 * $FreeBSD: src/usr.sbin/mrouted/vif.h,v 1.10 1999/08/28 01:17:09 peter Exp $
11 * $DragonFly: src/usr.sbin/mrouted/vif.h,v 1.2 2003/06/17 04:29:57 dillon Exp $
12 * vif.h,v 3.8.4.26 1998/01/14 21:21:19 fenner Exp
17 * Bitmap handling functions.
18 * These should be fast but generic. bytes can be slow to zero and compare,
19 * words are hard to make generic. Thus two sets of macros (yuk).
23 * The VIFM_ functions should migrate out of <netinet/ip_mroute.h>, since
24 * the kernel no longer uses vifbitmaps.
26 #ifndef VIFM_SET
27 typedef u_long vifbitmap_t;
29 #define VIFM_SET(n, m) ((m) |= (1 << (n)))
30 #define VIFM_CLR(n, m) ((m) &= ~(1 << (n)))
31 #define VIFM_ISSET(n, m) ((m) & (1 << (n)))
32 #define VIFM_CLRALL(m) ((m) = 0x00000000)
33 #define VIFM_COPY(mfrom, mto) ((mto) = (mfrom))
34 #define VIFM_SAME(m1, m2) ((m1) == (m2))
35 #endif
37 * And <netinet/ip_mroute.h> was missing some required functions anyway
39 #ifndef VIFM_SETALL
40 #define VIFM_SETALL(m) ((m) = ~0)
41 #endif
42 #define VIFM_ISSET_ONLY(n, m) ((m) == (1 << (n)))
43 #define VIFM_ISEMPTY(m) ((m) == 0)
44 #define VIFM_CLR_MASK(m, mask) ((m) &= ~(mask))
45 #define VIFM_SET_MASK(m, mask) ((m) |= (mask))
48 * Neighbor bitmaps are, for efficiency, implemented as a struct
49 * containing two variables of a native machine type. If you
50 * have a native type that's bigger than a long, define it below.
52 #define NBRTYPE u_long
53 #define NBRBITS sizeof(NBRTYPE) * 8
55 typedef struct {
56 NBRTYPE hi;
57 NBRTYPE lo;
58 } nbrbitmap_t;
59 #define MAXNBRS 2 * NBRBITS
60 #define NO_NBR MAXNBRS
62 #define NBRM_SET(n, m) (((n) < NBRBITS) ? ((m).lo |= (1 << (n))) : \
63 ((m).hi |= (1 << (n - NBRBITS))))
64 #define NBRM_CLR(n, m) (((n) < NBRBITS) ? ((m).lo &= ~(1 << (n))) : \
65 ((m).hi &= ~(1 << (n - NBRBITS))))
66 #define NBRM_ISSET(n, m) (((n) < NBRBITS) ? ((m).lo & (1 << (n))) : \
67 ((m).hi & (1 << ((n) - NBRBITS))))
68 #define NBRM_CLRALL(m) ((m).lo = (m).hi = 0)
69 #define NBRM_COPY(mfrom, mto) ((mto).lo = (mfrom).lo, (mto).hi = (mfrom).hi)
70 #define NBRM_SAME(m1, m2) (((m1).lo == (m2).lo) && ((m1).hi == (m2).hi))
71 #define NBRM_ISEMPTY(m) (((m).lo == 0) && ((m).hi == 0))
72 #define NBRM_SETMASK(m, mask) (((m).lo |= (mask).lo),((m).hi |= (mask).hi))
73 #define NBRM_CLRMASK(m, mask) (((m).lo &= ~(mask).lo),((m).hi &= ~(mask).hi))
74 #define NBRM_MASK(m, mask) (((m).lo &= (mask).lo),((m).hi &= (mask).hi))
75 #define NBRM_ISSETMASK(m, mask) (((m).lo & (mask).lo) || ((m).hi & (mask).hi))
76 #define NBRM_ISSETALLMASK(m, mask)\
77 ((((m).lo & (mask).lo) == (mask).lo) && \
78 (((m).hi & (mask).hi) == (mask).hi))
80 * This macro is TRUE if all the subordinates have been pruned, or if
81 * there are no subordinates on this vif.
82 * The arguments is the map of subordinates, the map of neighbors on the
83 * vif, and the map of received prunes.
85 #define SUBS_ARE_PRUNED(sub, vifmask, prunes) \
86 (((sub).lo & (vifmask).lo) == ((prunes).lo & (vifmask).lo & (sub).lo) && \
87 ((sub).hi & (vifmask).hi) == ((prunes).hi & (vifmask).hi & (sub).hi))
89 struct blastinfo {
90 char * bi_buf; /* Pointer to malloced storage */
91 char * bi_cur; /* The update to process next */
92 char * bi_end; /* The place to put the next update */
93 int bi_len; /* Size of malloced storage */
94 int bi_timer; /* Timer to run process_blaster_report */
98 * User level Virtual Interface structure
100 * A "virtual interface" is either a physical, multicast-capable interface
101 * (called a "phyint") or a virtual point-to-point link (called a "tunnel").
102 * (Note: all addresses, subnet numbers and masks are kept in NETWORK order.)
104 struct uvif {
105 u_int uv_flags; /* VIFF_ flags defined below */
106 u_char uv_metric; /* cost of this vif */
107 u_char uv_admetric; /* advertised cost of this vif */
108 u_char uv_threshold; /* min ttl required to forward on vif */
109 u_int uv_rate_limit; /* rate limit on this vif */
110 u_int32 uv_lcl_addr; /* local address of this vif */
111 u_int32 uv_rmt_addr; /* remote end-point addr (tunnels only) */
112 u_int32 uv_dst_addr; /* destination for DVMRP messages */
113 u_int32 uv_subnet; /* subnet number (phyints only) */
114 u_int32 uv_subnetmask; /* subnet mask (phyints only) */
115 u_int32 uv_subnetbcast;/* subnet broadcast addr (phyints only) */
116 char uv_name[IFNAMSIZ]; /* interface name */
117 struct listaddr *uv_groups; /* list of local groups (phyints only) */
118 struct listaddr *uv_neighbors; /* list of neighboring routers */
119 nbrbitmap_t uv_nbrmap; /* bitmap of active neighboring routers */
120 struct listaddr *uv_querier; /* IGMP querier on vif */
121 int uv_igmpv1_warn;/* To rate-limit IGMPv1 warnings */
122 int uv_prune_lifetime; /* Prune lifetime or 0 for default */
123 struct vif_acl *uv_acl; /* access control list of groups */
124 int uv_leaf_timer; /* time until this vif is considrd leaf */
125 struct phaddr *uv_addrs; /* Additional subnets on this vif */
126 struct vif_filter *uv_filter; /* Route filters on this vif */
127 struct blastinfo uv_blaster; /* Info about route blasters */
128 int uv_nbrup; /* Counter for neighbor up events */
129 int uv_icmp_warn; /* To rate-limit ICMP warnings */
130 u_int uv_nroutes; /* # of routes with this vif as parent */
131 struct ip *uv_encap_hdr; /* Pre-formed header to encapsulate msgs*/
134 #define uv_blasterbuf uv_blaster.bi_buf
135 #define uv_blastercur uv_blaster.bi_cur
136 #define uv_blasterend uv_blaster.bi_end
137 #define uv_blasterlen uv_blaster.bi_len
138 #define uv_blastertimer uv_blaster.bi_timer
140 #define VIFF_KERNEL_FLAGS (VIFF_TUNNEL|VIFF_SRCRT)
141 #define VIFF_DOWN 0x000100 /* kernel state of interface */
142 #define VIFF_DISABLED 0x000200 /* administratively disabled */
143 #define VIFF_QUERIER 0x000400 /* I am the subnet's querier */
144 #define VIFF_ONEWAY 0x000800 /* Maybe one way interface */
145 #define VIFF_LEAF 0x001000 /* all neighbors are leaves */
146 #define VIFF_IGMPV1 0x002000 /* Act as an IGMPv1 Router */
147 #define VIFF_REXMIT_PRUNES 0x004000 /* retransmit prunes */
148 #define VIFF_PASSIVE 0x008000 /* passive tunnel */
149 #define VIFF_ALLOW_NONPRUNERS 0x010000 /* ok to peer with nonprunrs */
150 #define VIFF_NOFLOOD 0x020000 /* don't flood on this vif */
151 #define VIFF_NOTRANSIT 0x040000 /* don't transit these vifs */
152 #define VIFF_BLASTER 0x080000 /* nbr on vif blasts routes */
153 #define VIFF_FORCE_LEAF 0x100000 /* ignore nbrs on this vif */
154 #define VIFF_OTUNNEL 0x200000 /* DVMRP msgs "beside" tunnel*/
156 #define AVOID_TRANSIT(v, r) \
157 (((r)->rt_parent != NO_VIF) && \
158 ((r)->rt_gateway != 0) && \
159 (uvifs[(v)].uv_flags & VIFF_NOTRANSIT) && \
160 (uvifs[(r)->rt_parent].uv_flags & VIFF_NOTRANSIT))
162 struct phaddr {
163 struct phaddr *pa_next;
164 u_int32 pa_subnet; /* extra subnet */
165 u_int32 pa_subnetmask; /* netmask of extra subnet */
166 u_int32 pa_subnetbcast; /* broadcast of extra subnet */
169 struct vif_acl {
170 struct vif_acl *acl_next; /* next acl member */
171 u_int32 acl_addr; /* Group address */
172 u_int32 acl_mask; /* Group addr. mask */
175 struct vif_filter {
176 int vf_type;
177 #define VFT_ACCEPT 1
178 #define VFT_DENY 2
179 int vf_flags;
180 #define VFF_BIDIR 1
181 struct vf_element *vf_filter;
184 struct vf_element {
185 struct vf_element *vfe_next;
186 u_int32 vfe_addr;
187 u_int32 vfe_mask;
188 int vfe_flags;
189 #define VFEF_EXACT 0x0001
192 struct listaddr {
193 struct listaddr *al_next; /* link to next addr, MUST BE FIRST */
194 u_int32 al_addr; /* local group or neighbor address */
195 u_long al_timer; /* for timing out group or neighbor */
196 time_t al_ctime; /* entry creation time */
197 union {
198 struct {
199 u_int32 alur_genid; /* generation id for neighbor */
200 u_int alur_nroutes; /* # of routes w/ nbr as parent */
201 u_char alur_pv; /* router protocol version */
202 u_char alur_mv; /* router mrouted version */
203 u_char alur_index; /* neighbor index */
204 } alu_router;
205 struct {
206 u_int32 alug_reporter; /* a host which reported membership */
207 u_long alug_timerid; /* timer for group membership */
208 u_long alug_query; /* timer for repeated leave query */
209 u_char alug_old; /* time since heard old report */
210 } alu_group;
211 } al_alu;
212 u_short al_flags; /* flags related to this neighbor */
214 #define al_genid al_alu.alu_router.alur_genid
215 #define al_nroutes al_alu.alu_router.alur_nroutes
216 #define al_pv al_alu.alu_router.alur_pv
217 #define al_mv al_alu.alu_router.alur_mv
218 #define al_index al_alu.alu_router.alur_index
219 #define al_reporter al_alu.alu_group.alug_reporter
220 #define al_old al_alu.alu_group.alug_old
221 #define al_timerid al_alu.alu_group.alug_timerid
222 #define al_query al_alu.alu_group.alug_query
224 #define NBRF_LEAF 0x0001 /* This neighbor is a leaf */
225 #define NBRF_GENID 0x0100 /* I know this neighbor's genid */
226 #define NBRF_WAITING 0x0200 /* Waiting for peering to come up */
227 #define NBRF_ONEWAY 0x0400 /* One-way peering */
228 #define NBRF_TOOOLD 0x0800 /* Too old (policy decision) */
229 #define NBRF_TOOMANYROUTES 0x1000 /* Neighbor is spouting routes */
230 #define NBRF_NOTPRUNING 0x2000 /* Neighbor doesn't appear to prune */
233 * Don't peer with neighbors with any of these flags set
235 #define NBRF_DONTPEER (NBRF_WAITING|NBRF_ONEWAY|NBRF_TOOOLD| \
236 NBRF_TOOMANYROUTES|NBRF_NOTPRUNING)
238 #define NO_VIF ((vifi_t)MAXVIFS) /* An invalid vif index */