ip_mroute.h revision 1.26 1 1.26 elad /* $NetBSD: ip_mroute.h,v 1.26 2005/12/10 23:36:23 elad Exp $ */
2 1.24 manu
3 1.24 manu #ifndef _NETINET_IP_MROUTE_H_
4 1.24 manu #define _NETINET_IP_MROUTE_H_
5 1.6 cgd
6 1.1 hpeyerl /*
7 1.9 mycroft * Definitions for IP multicast forwarding.
8 1.1 hpeyerl *
9 1.1 hpeyerl * Written by David Waitzman, BBN Labs, August 1988.
10 1.1 hpeyerl * Modified by Steve Deering, Stanford, February 1989.
11 1.9 mycroft * Modified by Ajit Thyagarajan, PARC, August 1993.
12 1.9 mycroft * Modified by Ajit Thyagarajan, PARC, August 1994.
13 1.24 manu * Modified by Ahmed Helmy, SGI, June 1996.
14 1.24 manu * Modified by Pavlin Radoslavov, ICSI, October 2002.
15 1.1 hpeyerl *
16 1.9 mycroft * MROUTING Revision: 1.2
17 1.24 manu * and PIM-SMv2 and PIM-DM support, advanced API support,
18 1.24 manu * bandwidth metering and signaling.
19 1.1 hpeyerl */
20 1.1 hpeyerl
21 1.9 mycroft #include <sys/queue.h>
22 1.18 thorpej #include <sys/callout.h>
23 1.1 hpeyerl
24 1.1 hpeyerl /*
25 1.9 mycroft * Multicast Routing set/getsockopt commands.
26 1.1 hpeyerl */
27 1.9 mycroft #define MRT_INIT 100 /* initialize forwarder */
28 1.9 mycroft #define MRT_DONE 101 /* shut down forwarder */
29 1.9 mycroft #define MRT_ADD_VIF 102 /* create virtual interface */
30 1.9 mycroft #define MRT_DEL_VIF 103 /* delete virtual interface */
31 1.9 mycroft #define MRT_ADD_MFC 104 /* insert forwarding cache entry */
32 1.9 mycroft #define MRT_DEL_MFC 105 /* delete forwarding cache entry */
33 1.9 mycroft #define MRT_VERSION 106 /* get kernel version number */
34 1.24 manu #define MRT_ASSERT 107 /* enable assert processing */
35 1.24 manu #define MRT_PIM MRT_ASSERT /* enable PIM processing */
36 1.24 manu #define MRT_API_SUPPORT 109 /* supported MRT API */
37 1.24 manu #define MRT_API_CONFIG 110 /* config MRT API */
38 1.24 manu #define MRT_ADD_BW_UPCALL 111 /* create bandwidth monitor */
39 1.24 manu #define MRT_DEL_BW_UPCALL 112 /* delete bandwidth monitor */
40 1.1 hpeyerl
41 1.1 hpeyerl
42 1.1 hpeyerl /*
43 1.1 hpeyerl * Types and macros for handling bitmaps with one bit per virtual interface.
44 1.1 hpeyerl */
45 1.1 hpeyerl #define MAXVIFS 32
46 1.8 cgd typedef u_int32_t vifbitmap_t;
47 1.9 mycroft typedef u_int16_t vifi_t; /* type of a vif index */
48 1.1 hpeyerl
49 1.9 mycroft #define VIFM_SET(n, m) ((m) |= (1 << (n)))
50 1.9 mycroft #define VIFM_CLR(n, m) ((m) &= ~(1 << (n)))
51 1.9 mycroft #define VIFM_ISSET(n, m) ((m) & (1 << (n)))
52 1.9 mycroft #define VIFM_SETALL(m) ((m) = 0xffffffff)
53 1.9 mycroft #define VIFM_CLRALL(m) ((m) = 0x00000000)
54 1.9 mycroft #define VIFM_COPY(mfrom, mto) ((mto) = (mfrom))
55 1.9 mycroft #define VIFM_SAME(m1, m2) ((m1) == (m2))
56 1.1 hpeyerl
57 1.9 mycroft #define VIFF_TUNNEL 0x1 /* vif represents a tunnel end-point */
58 1.9 mycroft #define VIFF_SRCRT 0x2 /* tunnel uses IP src routing */
59 1.24 manu #define VIFF_REGISTER 0x4 /* used for PIM Register encap/decap */
60 1.1 hpeyerl
61 1.1 hpeyerl /*
62 1.9 mycroft * Argument structure for MRT_ADD_VIF.
63 1.9 mycroft * (MRT_DEL_VIF takes a single vifi_t argument.)
64 1.1 hpeyerl */
65 1.1 hpeyerl struct vifctl {
66 1.9 mycroft vifi_t vifc_vifi; /* the index of the vif to be added */
67 1.9 mycroft u_int8_t vifc_flags; /* VIFF_ flags defined below */
68 1.9 mycroft u_int8_t vifc_threshold; /* min ttl required to forward on vif */
69 1.9 mycroft u_int32_t vifc_rate_limit; /* max rate */
70 1.9 mycroft struct in_addr vifc_lcl_addr;/* local interface address */
71 1.9 mycroft struct in_addr vifc_rmt_addr;/* remote address (tunnels only) */
72 1.1 hpeyerl };
73 1.1 hpeyerl
74 1.1 hpeyerl /*
75 1.9 mycroft * Argument structure for MRT_ADD_MFC and MRT_DEL_MFC.
76 1.24 manu * XXX if you change this, make sure to change struct mfcctl2 as well.
77 1.1 hpeyerl */
78 1.9 mycroft struct mfcctl {
79 1.9 mycroft struct in_addr mfcc_origin; /* ip origin of mcasts */
80 1.9 mycroft struct in_addr mfcc_mcastgrp; /* multicast group associated */
81 1.9 mycroft vifi_t mfcc_parent; /* incoming vif */
82 1.9 mycroft u_int8_t mfcc_ttls[MAXVIFS]; /* forwarding ttls on vifs */
83 1.1 hpeyerl };
84 1.20 itojun
85 1.1 hpeyerl /*
86 1.24 manu * The new argument structure for MRT_ADD_MFC and MRT_DEL_MFC overlays
87 1.24 manu * and extends the old struct mfcctl.
88 1.24 manu */
89 1.24 manu struct mfcctl2 {
90 1.24 manu /* the mfcctl fields */
91 1.24 manu struct in_addr mfcc_origin; /* ip origin of mcasts */
92 1.24 manu struct in_addr mfcc_mcastgrp; /* multicast group associated*/
93 1.24 manu vifi_t mfcc_parent; /* incoming vif */
94 1.24 manu u_int8_t mfcc_ttls[MAXVIFS]; /* forwarding ttls on vifs */
95 1.24 manu
96 1.24 manu /* extension fields */
97 1.24 manu u_int8_t mfcc_flags[MAXVIFS]; /* the MRT_MFC_FLAGS_* flags */
98 1.24 manu struct in_addr mfcc_rp; /* the RP address */
99 1.24 manu };
100 1.24 manu /*
101 1.24 manu * The advanced-API flags.
102 1.24 manu *
103 1.24 manu * The MRT_MFC_FLAGS_XXX API flags are also used as flags
104 1.24 manu * for the mfcc_flags field.
105 1.24 manu */
106 1.24 manu #define MRT_MFC_FLAGS_DISABLE_WRONGVIF (1 << 0) /* disable WRONGVIF signals */
107 1.24 manu #define MRT_MFC_FLAGS_BORDER_VIF (1 << 1) /* border vif */
108 1.24 manu #define MRT_MFC_RP (1 << 8) /* enable RP address */
109 1.24 manu #define MRT_MFC_BW_UPCALL (1 << 9) /* enable bw upcalls */
110 1.24 manu #define MRT_MFC_FLAGS_ALL (MRT_MFC_FLAGS_DISABLE_WRONGVIF | \
111 1.24 manu MRT_MFC_FLAGS_BORDER_VIF)
112 1.24 manu #define MRT_API_FLAGS_ALL (MRT_MFC_FLAGS_ALL | \
113 1.24 manu MRT_MFC_RP | \
114 1.24 manu MRT_MFC_BW_UPCALL)
115 1.24 manu
116 1.24 manu /*
117 1.24 manu * Structure for installing or delivering an upcall if the
118 1.24 manu * measured bandwidth is above or below a threshold.
119 1.24 manu *
120 1.24 manu * User programs (e.g. daemons) may have a need to know when the
121 1.24 manu * bandwidth used by some data flow is above or below some threshold.
122 1.24 manu * This interface allows the userland to specify the threshold (in
123 1.24 manu * bytes and/or packets) and the measurement interval. Flows are
124 1.24 manu * all packet with the same source and destination IP address.
125 1.24 manu * At the moment the code is only used for multicast destinations
126 1.24 manu * but there is nothing that prevents its use for unicast.
127 1.24 manu *
128 1.24 manu * The measurement interval cannot be shorter than some Tmin (currently, 3s).
129 1.24 manu * The threshold is set in packets and/or bytes per_interval.
130 1.24 manu *
131 1.24 manu * Measurement works as follows:
132 1.24 manu *
133 1.25 perry * For >= measurements:
134 1.24 manu * The first packet marks the start of a measurement interval.
135 1.24 manu * During an interval we count packets and bytes, and when we
136 1.24 manu * pass the threshold we deliver an upcall and we are done.
137 1.24 manu * The first packet after the end of the interval resets the
138 1.24 manu * count and restarts the measurement.
139 1.24 manu *
140 1.24 manu * For <= measurement:
141 1.24 manu * We start a timer to fire at the end of the interval, and
142 1.24 manu * then for each incoming packet we count packets and bytes.
143 1.24 manu * When the timer fires, we compare the value with the threshold,
144 1.24 manu * schedule an upcall if we are below, and restart the measurement
145 1.24 manu * (reschedule timer and zero counters).
146 1.24 manu */
147 1.24 manu
148 1.24 manu struct bw_data {
149 1.24 manu struct timeval b_time;
150 1.24 manu u_int64_t b_packets;
151 1.24 manu u_int64_t b_bytes;
152 1.24 manu };
153 1.24 manu
154 1.24 manu struct bw_upcall {
155 1.24 manu struct in_addr bu_src; /* source address */
156 1.24 manu struct in_addr bu_dst; /* destination address */
157 1.24 manu u_int32_t bu_flags; /* misc flags (see below) */
158 1.24 manu #define BW_UPCALL_UNIT_PACKETS (1 << 0) /* threshold (in packets) */
159 1.24 manu #define BW_UPCALL_UNIT_BYTES (1 << 1) /* threshold (in bytes) */
160 1.24 manu #define BW_UPCALL_GEQ (1 << 2) /* upcall if bw >= threshold */
161 1.24 manu #define BW_UPCALL_LEQ (1 << 3) /* upcall if bw <= threshold */
162 1.24 manu #define BW_UPCALL_DELETE_ALL (1 << 4) /* delete all upcalls for s,d*/
163 1.24 manu struct bw_data bu_threshold; /* the bw threshold */
164 1.24 manu struct bw_data bu_measured; /* the measured bw */
165 1.24 manu };
166 1.24 manu
167 1.24 manu /* max. number of upcalls to deliver together */
168 1.24 manu #define BW_UPCALLS_MAX 128
169 1.24 manu /* min. threshold time interval for bandwidth measurement */
170 1.24 manu #define BW_UPCALL_THRESHOLD_INTERVAL_MIN_SEC 3
171 1.24 manu #define BW_UPCALL_THRESHOLD_INTERVAL_MIN_USEC 0
172 1.24 manu
173 1.24 manu /*
174 1.9 mycroft * Argument structure used by mrouted to get src-grp pkt counts.
175 1.1 hpeyerl */
176 1.9 mycroft struct sioc_sg_req {
177 1.9 mycroft struct in_addr src;
178 1.9 mycroft struct in_addr grp;
179 1.9 mycroft u_long pktcnt;
180 1.9 mycroft u_long bytecnt;
181 1.9 mycroft u_long wrong_if;
182 1.1 hpeyerl };
183 1.20 itojun
184 1.1 hpeyerl /*
185 1.9 mycroft * Argument structure used by mrouted to get vif pkt counts.
186 1.1 hpeyerl */
187 1.9 mycroft struct sioc_vif_req {
188 1.9 mycroft vifi_t vifi; /* vif number */
189 1.9 mycroft u_long icount; /* input packet count on vif */
190 1.9 mycroft u_long ocount; /* output packet count on vif */
191 1.9 mycroft u_long ibytes; /* input byte count on vif */
192 1.9 mycroft u_long obytes; /* output byte count on vif */
193 1.1 hpeyerl };
194 1.1 hpeyerl
195 1.1 hpeyerl
196 1.1 hpeyerl /*
197 1.1 hpeyerl * The kernel's multicast routing statistics.
198 1.1 hpeyerl */
199 1.1 hpeyerl struct mrtstat {
200 1.9 mycroft u_long mrts_mfc_lookups; /* # forw. cache hash table hits */
201 1.9 mycroft u_long mrts_mfc_misses; /* # forw. cache hash table misses */
202 1.9 mycroft u_long mrts_upcalls; /* # calls to mrouted */
203 1.1 hpeyerl u_long mrts_no_route; /* no route for packet's origin */
204 1.1 hpeyerl u_long mrts_bad_tunnel; /* malformed tunnel options */
205 1.1 hpeyerl u_long mrts_cant_tunnel; /* no room for tunnel options */
206 1.5 brezak u_long mrts_wrong_if; /* arrived on wrong interface */
207 1.9 mycroft u_long mrts_upq_ovflw; /* upcall Q overflow */
208 1.9 mycroft u_long mrts_cache_cleanups; /* # entries with no upcalls */
209 1.9 mycroft u_long mrts_drop_sel; /* pkts dropped selectively */
210 1.9 mycroft u_long mrts_q_overflow; /* pkts dropped - Q overflow */
211 1.9 mycroft u_long mrts_pkt2large; /* pkts dropped - size > BKT SIZE */
212 1.9 mycroft u_long mrts_upq_sockfull; /* upcalls dropped - socket full */
213 1.9 mycroft };
214 1.20 itojun
215 1.9 mycroft
216 1.9 mycroft #ifdef _KERNEL
217 1.9 mycroft
218 1.9 mycroft /*
219 1.9 mycroft * The kernel's virtual-interface structure.
220 1.9 mycroft */
221 1.19 itojun struct encaptab;
222 1.9 mycroft struct vif {
223 1.12 mycroft struct mbuf *tbf_q, **tbf_t; /* packet queue */
224 1.12 mycroft struct timeval tbf_last_pkt_t; /* arr. time of last pkt */
225 1.12 mycroft u_int32_t tbf_n_tok; /* no of tokens in bucket */
226 1.12 mycroft u_int32_t tbf_q_len; /* length of queue at this vif */
227 1.12 mycroft u_int32_t tbf_max_q_len; /* max. queue length */
228 1.12 mycroft
229 1.9 mycroft u_int8_t v_flags; /* VIFF_ flags defined above */
230 1.9 mycroft u_int8_t v_threshold; /* min ttl required to forward on vif */
231 1.9 mycroft u_int32_t v_rate_limit; /* max rate */
232 1.9 mycroft struct in_addr v_lcl_addr; /* local interface address */
233 1.9 mycroft struct in_addr v_rmt_addr; /* remote address (tunnels only) */
234 1.9 mycroft struct ifnet *v_ifp; /* pointer to interface */
235 1.9 mycroft u_long v_pkt_in; /* # pkts in on interface */
236 1.9 mycroft u_long v_pkt_out; /* # pkts out on interface */
237 1.9 mycroft u_long v_bytes_in; /* # bytes in on interface */
238 1.9 mycroft u_long v_bytes_out; /* # bytes out on interface */
239 1.9 mycroft struct route v_route; /* cached route if this is a tunnel */
240 1.18 thorpej struct callout v_repq_ch; /* for tbf_reprocess_q() */
241 1.9 mycroft #ifdef RSVP_ISI
242 1.9 mycroft int v_rsvp_on; /* # RSVP listening on this vif */
243 1.9 mycroft struct socket *v_rsvpd; /* # RSVPD daemon */
244 1.9 mycroft #endif /* RSVP_ISI */
245 1.19 itojun const struct encaptab *v_encap_cookie;
246 1.9 mycroft };
247 1.9 mycroft
248 1.9 mycroft /*
249 1.9 mycroft * The kernel's multicast forwarding cache entry structure.
250 1.20 itojun * (A field for the type of service (mfc_tos) is to be added
251 1.9 mycroft * at a future point.)
252 1.9 mycroft */
253 1.9 mycroft struct mfc {
254 1.9 mycroft LIST_ENTRY(mfc) mfc_hash;
255 1.9 mycroft struct in_addr mfc_origin; /* ip origin of mcasts */
256 1.9 mycroft struct in_addr mfc_mcastgrp; /* multicast group associated */
257 1.9 mycroft vifi_t mfc_parent; /* incoming vif */
258 1.9 mycroft u_int8_t mfc_ttls[MAXVIFS]; /* forwarding ttls on vifs */
259 1.9 mycroft u_long mfc_pkt_cnt; /* pkt count for src-grp */
260 1.9 mycroft u_long mfc_byte_cnt; /* byte count for src-grp */
261 1.9 mycroft u_long mfc_wrong_if; /* wrong if for src-grp */
262 1.9 mycroft int mfc_expire; /* time to clean entry up */
263 1.9 mycroft struct timeval mfc_last_assert; /* last time I sent an assert */
264 1.9 mycroft struct rtdetq *mfc_stall; /* pkts waiting for route */
265 1.24 manu u_int8_t mfc_flags[MAXVIFS]; /* the MRT_MFC_FLAGS_* flags */
266 1.24 manu struct in_addr mfc_rp; /* the RP address */
267 1.24 manu struct bw_meter *mfc_bw_meter; /* list of bandwidth meters */
268 1.9 mycroft };
269 1.9 mycroft
270 1.9 mycroft /*
271 1.9 mycroft * Structure used to communicate from kernel to multicast router.
272 1.9 mycroft * (Note the convenient similarity to an IP packet.)
273 1.9 mycroft */
274 1.9 mycroft struct igmpmsg {
275 1.9 mycroft u_int32_t unused1;
276 1.9 mycroft u_int32_t unused2;
277 1.9 mycroft u_int8_t im_msgtype; /* what type of message */
278 1.24 manu #define IGMPMSG_NOCACHE 1 /* no MFC in the kernel */
279 1.24 manu #define IGMPMSG_WRONGVIF 2 /* packet came from wrong interface */
280 1.24 manu #define IGMPMSG_WHOLEPKT 3 /* PIM pkt for user level encap. */
281 1.24 manu #define IGMPMSG_BW_UPCALL 4 /* BW monitoring upcall */
282 1.9 mycroft u_int8_t im_mbz; /* must be zero */
283 1.9 mycroft u_int8_t im_vif; /* vif rec'd on */
284 1.9 mycroft u_int8_t unused3;
285 1.9 mycroft struct in_addr im_src, im_dst;
286 1.17 thorpej } __attribute__((__packed__));
287 1.9 mycroft
288 1.9 mycroft /*
289 1.9 mycroft * Argument structure used for pkt info. while upcall is made.
290 1.9 mycroft */
291 1.9 mycroft struct rtdetq {
292 1.9 mycroft struct mbuf *m; /* a copy of the packet */
293 1.9 mycroft struct ifnet *ifp; /* interface pkt came in on */
294 1.9 mycroft #ifdef UPCALL_TIMING
295 1.9 mycroft struct timeval t; /* timestamp */
296 1.9 mycroft #endif /* UPCALL_TIMING */
297 1.9 mycroft struct rtdetq *next;
298 1.9 mycroft };
299 1.9 mycroft
300 1.9 mycroft #define MFCTBLSIZ 256
301 1.9 mycroft #define MAX_UPQ 4 /* max. no of pkts in upcall Q */
302 1.20 itojun
303 1.9 mycroft /*
304 1.20 itojun * Token bucket filter code
305 1.9 mycroft */
306 1.9 mycroft #define MAX_BKT_SIZE 10000 /* 10K bytes size */
307 1.9 mycroft #define MAXQSIZE 10 /* max. no of pkts in token queue */
308 1.20 itojun
309 1.24 manu /*
310 1.24 manu * Structure for measuring the bandwidth and sending an upcall if the
311 1.24 manu * measured bandwidth is above or below a threshold.
312 1.24 manu */
313 1.24 manu struct bw_meter {
314 1.24 manu struct bw_meter *bm_mfc_next; /* next bw meter (same mfc) */
315 1.24 manu struct bw_meter *bm_time_next; /* next bw meter (same time) */
316 1.24 manu uint32_t bm_time_hash; /* the time hash value */
317 1.24 manu struct mfc *bm_mfc; /* the corresponding mfc */
318 1.24 manu uint32_t bm_flags; /* misc flags (see below) */
319 1.24 manu #define BW_METER_UNIT_PACKETS (1 << 0) /* threshold (in packets) */
320 1.24 manu #define BW_METER_UNIT_BYTES (1 << 1) /* threshold (in bytes) */
321 1.24 manu #define BW_METER_GEQ (1 << 2) /* upcall if bw >= threshold */
322 1.24 manu #define BW_METER_LEQ (1 << 3) /* upcall if bw <= threshold */
323 1.24 manu #define BW_METER_USER_FLAGS (BW_METER_UNIT_PACKETS | \
324 1.24 manu BW_METER_UNIT_BYTES | \
325 1.24 manu BW_METER_GEQ | \
326 1.24 manu BW_METER_LEQ)
327 1.24 manu
328 1.24 manu #define BW_METER_UPCALL_DELIVERED (1 << 24) /* upcall was delivered */
329 1.24 manu
330 1.24 manu struct bw_data bm_threshold; /* the upcall threshold */
331 1.24 manu struct bw_data bm_measured; /* the measured bw */
332 1.24 manu struct timeval bm_start_time; /* abs. time */
333 1.24 manu };
334 1.12 mycroft
335 1.24 manu int ip_mrouter_set(struct socket *, int, struct mbuf **);
336 1.24 manu int ip_mrouter_get(struct socket *, int, struct mbuf **);
337 1.24 manu int mrt_ioctl(struct socket *, u_long, caddr_t);
338 1.24 manu int ip_mrouter_done(void);
339 1.24 manu void ip_mrouter_detach(struct ifnet *);
340 1.24 manu void reset_vif(struct vif *);
341 1.10 christos #ifdef RSVP_ISI
342 1.24 manu int ip_mforward(struct mbuf *, struct ifnet *, struct ip_moptions *);
343 1.24 manu int legal_vif_num(int);
344 1.24 manu int ip_rsvp_vif_init(struct socket *, struct mbuf *);
345 1.24 manu int ip_rsvp_vif_done(struct socket *, struct mbuf *);
346 1.24 manu void ip_rsvp_force_done(struct socket *);
347 1.24 manu void rsvp_input(struct mbuf *, int, int);
348 1.10 christos #else
349 1.24 manu int ip_mforward(struct mbuf *, struct ifnet *);
350 1.10 christos #endif
351 1.9 mycroft
352 1.7 jtc #endif /* _KERNEL */
353 1.13 perry
354 1.26 elad #endif /* !_NETINET_IP_MROUTE_H_ */
355