linprocfs - Introduce /proc/mounts
[dragonfly.git] / sys / net / ip_mroute / ip_mroute.h
blobec0964e65e4f3b393f34bab89702701c954cec36
1 /*
2 * Copyright (c) 1989 Stephen Deering.
3 * Copyright (c) 1992, 1993
4 * The Regents of the University of California. All rights reserved.
6 * This code is derived from software contributed to Berkeley by
7 * Stephen Deering of Stanford University.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
37 * @(#)ip_mroute.h 8.1 (Berkeley) 6/10/93
38 * $FreeBSD: src/sys/netinet/ip_mroute.h,v 1.17.2.3 2003/08/24 08:24:38 hsu Exp $
39 * $DragonFly: src/sys/net/ip_mroute/ip_mroute.h,v 1.3 2003/08/24 23:07:07 hsu Exp $
42 #ifndef _NETINET_IP_MROUTE_H_
43 #define _NETINET_IP_MROUTE_H_
46 * Definitions for IP multicast forwarding.
48 * Written by David Waitzman, BBN Labs, August 1988.
49 * Modified by Steve Deering, Stanford, February 1989.
50 * Modified by Ajit Thyagarajan, PARC, August 1993.
51 * Modified by Ajit Thyagarajan, PARC, August 1994.
52 * Modified by Ahmed Helmy, SGI, June 1996.
53 * Modified by Pavlin Radoslavov, ICSI, October 2002.
55 * MROUTING Revision: 3.3.1.3
56 * and PIM-SMv2 and PIM-DM support, advanced API support,
57 * bandwidth metering and signaling.
62 * Multicast Routing set/getsockopt commands.
64 #define MRT_INIT 100 /* initialize forwarder */
65 #define MRT_DONE 101 /* shut down forwarder */
66 #define MRT_ADD_VIF 102 /* create virtual interface */
67 #define MRT_DEL_VIF 103 /* delete virtual interface */
68 #define MRT_ADD_MFC 104 /* insert forwarding cache entry */
69 #define MRT_DEL_MFC 105 /* delete forwarding cache entry */
70 #define MRT_VERSION 106 /* get kernel version number */
71 #define MRT_ASSERT 107 /* enable assert processing */
72 #define MRT_PIM MRT_ASSERT /* enable PIM processing */
73 #define MRT_API_SUPPORT 109 /* supported MRT API */
74 #define MRT_API_CONFIG 110 /* config MRT API */
75 #define MRT_ADD_BW_UPCALL 111 /* create bandwidth monitor */
76 #define MRT_DEL_BW_UPCALL 112 /* delete bandwidth monitor */
79 #define GET_TIME(t) microtime(&t)
82 * Types and macros for handling bitmaps with one bit per virtual interface.
84 #define MAXVIFS 32
85 typedef u_long vifbitmap_t;
86 typedef u_short vifi_t; /* type of a vif index */
87 #define ALL_VIFS (vifi_t)-1
89 #define VIFM_SET(n, m) ((m) |= (1 << (n)))
90 #define VIFM_CLR(n, m) ((m) &= ~(1 << (n)))
91 #define VIFM_ISSET(n, m) ((m) & (1 << (n)))
92 #define VIFM_CLRALL(m) ((m) = 0x00000000)
93 #define VIFM_COPY(mfrom, mto) ((mto) = (mfrom))
94 #define VIFM_SAME(m1, m2) ((m1) == (m2))
98 * Argument structure for MRT_ADD_VIF.
99 * (MRT_DEL_VIF takes a single vifi_t argument.)
101 struct vifctl {
102 vifi_t vifc_vifi; /* the index of the vif to be added */
103 u_char vifc_flags; /* VIFF_ flags defined below */
104 u_char vifc_threshold; /* min ttl required to forward on vif */
105 u_int vifc_rate_limit; /* max rate */
106 struct in_addr vifc_lcl_addr; /* local interface address */
107 struct in_addr vifc_rmt_addr; /* remote address (tunnels only) */
110 #define VIFF_TUNNEL 0x1 /* vif represents a tunnel end-point */
111 #define VIFF_SRCRT 0x2 /* tunnel uses IP source routing */
112 #define VIFF_REGISTER 0x4 /* used for PIM Register encap/decap */
115 * Argument structure for MRT_ADD_MFC and MRT_DEL_MFC
116 * XXX if you change this, make sure to change struct mfcctl2 as well.
118 struct mfcctl {
119 struct in_addr mfcc_origin; /* ip origin of mcasts */
120 struct in_addr mfcc_mcastgrp; /* multicast group associated*/
121 vifi_t mfcc_parent; /* incoming vif */
122 u_char mfcc_ttls[MAXVIFS]; /* forwarding ttls on vifs */
126 * The new argument structure for MRT_ADD_MFC and MRT_DEL_MFC overlays
127 * and extends the old struct mfcctl.
129 struct mfcctl2 {
130 /* the mfcctl fields */
131 struct in_addr mfcc_origin; /* ip origin of mcasts */
132 struct in_addr mfcc_mcastgrp; /* multicast group associated*/
133 vifi_t mfcc_parent; /* incoming vif */
134 u_char mfcc_ttls[MAXVIFS]; /* forwarding ttls on vifs */
136 /* extension fields */
137 uint8_t mfcc_flags[MAXVIFS]; /* the MRT_MFC_FLAGS_* flags */
138 struct in_addr mfcc_rp; /* the RP address */
141 * The advanced-API flags.
143 * The MRT_MFC_FLAGS_XXX API flags are also used as flags
144 * for the mfcc_flags field.
146 #define MRT_MFC_FLAGS_DISABLE_WRONGVIF (1 << 0) /* disable WRONGVIF signals */
147 #define MRT_MFC_FLAGS_BORDER_VIF (1 << 1) /* border vif */
148 #define MRT_MFC_RP (1 << 8) /* enable RP address */
149 #define MRT_MFC_BW_UPCALL (1 << 9) /* enable bw upcalls */
150 #define MRT_MFC_FLAGS_ALL (MRT_MFC_FLAGS_DISABLE_WRONGVIF | \
151 MRT_MFC_FLAGS_BORDER_VIF)
152 #define MRT_API_FLAGS_ALL (MRT_MFC_FLAGS_ALL | \
153 MRT_MFC_RP | \
154 MRT_MFC_BW_UPCALL)
157 * Structure for installing or delivering an upcall if the
158 * measured bandwidth is above or below a threshold.
160 * User programs (e.g. daemons) may have a need to know when the
161 * bandwidth used by some data flow is above or below some threshold.
162 * This interface allows the userland to specify the threshold (in
163 * bytes and/or packets) and the measurement interval. Flows are
164 * all packet with the same source and destination IP address.
165 * At the moment the code is only used for multicast destinations
166 * but there is nothing that prevents its use for unicast.
168 * The measurement interval cannot be shorter than some Tmin (currently, 3s).
169 * The threshold is set in packets and/or bytes per_interval.
171 * Measurement works as follows:
173 * For >= measurements:
174 * The first packet marks the start of a measurement interval.
175 * During an interval we count packets and bytes, and when we
176 * pass the threshold we deliver an upcall and we are done.
177 * The first packet after the end of the interval resets the
178 * count and restarts the measurement.
180 * For <= measurement:
181 * We start a timer to fire at the end of the interval, and
182 * then for each incoming packet we count packets and bytes.
183 * When the timer fires, we compare the value with the threshold,
184 * schedule an upcall if we are below, and restart the measurement
185 * (reschedule timer and zero counters).
188 struct bw_data {
189 struct timeval b_time;
190 uint64_t b_packets;
191 uint64_t b_bytes;
194 struct bw_upcall {
195 struct in_addr bu_src; /* source address */
196 struct in_addr bu_dst; /* destination address */
197 uint32_t bu_flags; /* misc flags (see below) */
198 #define BW_UPCALL_UNIT_PACKETS (1 << 0) /* threshold (in packets) */
199 #define BW_UPCALL_UNIT_BYTES (1 << 1) /* threshold (in bytes) */
200 #define BW_UPCALL_GEQ (1 << 2) /* upcall if bw >= threshold */
201 #define BW_UPCALL_LEQ (1 << 3) /* upcall if bw <= threshold */
202 #define BW_UPCALL_DELETE_ALL (1 << 4) /* delete all upcalls for s,d*/
203 struct bw_data bu_threshold; /* the bw threshold */
204 struct bw_data bu_measured; /* the measured bw */
207 /* max. number of upcalls to deliver together */
208 #define BW_UPCALLS_MAX 128
209 /* min. threshold time interval for bandwidth measurement */
210 #define BW_UPCALL_THRESHOLD_INTERVAL_MIN_SEC 3
211 #define BW_UPCALL_THRESHOLD_INTERVAL_MIN_USEC 0
214 * The kernel's multicast routing statistics.
216 struct mrtstat {
217 u_long mrts_mfc_lookups; /* # forw. cache hash table hits */
218 u_long mrts_mfc_misses; /* # forw. cache hash table misses */
219 u_long mrts_upcalls; /* # calls to mrouted */
220 u_long mrts_no_route; /* no route for packet's origin */
221 u_long mrts_bad_tunnel; /* malformed tunnel options */
222 u_long mrts_cant_tunnel; /* no room for tunnel options */
223 u_long mrts_wrong_if; /* arrived on wrong interface */
224 u_long mrts_upq_ovflw; /* upcall Q overflow */
225 u_long mrts_cache_cleanups; /* # entries with no upcalls */
226 u_long mrts_drop_sel; /* pkts dropped selectively */
227 u_long mrts_q_overflow; /* pkts dropped - Q overflow */
228 u_long mrts_pkt2large; /* pkts dropped - size > BKT SIZE */
229 u_long mrts_upq_sockfull; /* upcalls dropped - socket full */
233 * Argument structure used by mrouted to get src-grp pkt counts
235 struct sioc_sg_req {
236 struct in_addr src;
237 struct in_addr grp;
238 u_long pktcnt;
239 u_long bytecnt;
240 u_long wrong_if;
244 * Argument structure used by mrouted to get vif pkt counts
246 struct sioc_vif_req {
247 vifi_t vifi; /* vif number */
248 u_long icount; /* Input packet count on vif */
249 u_long ocount; /* Output packet count on vif */
250 u_long ibytes; /* Input byte count on vif */
251 u_long obytes; /* Output byte count on vif */
256 * The kernel's virtual-interface structure.
258 struct vif {
259 u_char v_flags; /* VIFF_ flags defined above */
260 u_char v_threshold; /* min ttl required to forward on vif*/
261 u_int v_rate_limit; /* max rate */
262 struct tbf *v_tbf; /* token bucket structure at intf. */
263 struct in_addr v_lcl_addr; /* local interface address */
264 struct in_addr v_rmt_addr; /* remote address (tunnels only) */
265 struct ifnet *v_ifp; /* pointer to interface */
266 u_long v_pkt_in; /* # pkts in on interface */
267 u_long v_pkt_out; /* # pkts out on interface */
268 u_long v_bytes_in; /* # bytes in on interface */
269 u_long v_bytes_out; /* # bytes out on interface */
270 struct route v_route; /* cached route if this is a tunnel */
271 u_int v_rsvp_on; /* RSVP listening on this vif */
272 struct socket *v_rsvpd; /* RSVP daemon socket */
276 * The kernel's multicast forwarding cache entry structure
277 * (A field for the type of service (mfc_tos) is to be added
278 * at a future point)
280 struct mfc {
281 struct in_addr mfc_origin; /* IP origin of mcasts */
282 struct in_addr mfc_mcastgrp; /* multicast group associated*/
283 vifi_t mfc_parent; /* incoming vif */
284 u_char mfc_ttls[MAXVIFS]; /* forwarding ttls on vifs */
285 u_long mfc_pkt_cnt; /* pkt count for src-grp */
286 u_long mfc_byte_cnt; /* byte count for src-grp */
287 u_long mfc_wrong_if; /* wrong if for src-grp */
288 int mfc_expire; /* time to clean entry up */
289 struct timeval mfc_last_assert; /* last time I sent an assert*/
290 struct rtdetq *mfc_stall; /* q of packets awaiting mfc */
291 struct mfc *mfc_next; /* next mfc entry */
292 uint8_t mfc_flags[MAXVIFS]; /* the MRT_MFC_FLAGS_* flags */
293 struct in_addr mfc_rp; /* the RP address */
294 struct bw_meter *mfc_bw_meter; /* list of bandwidth meters */
298 * Struct used to communicate from kernel to multicast router
299 * note the convenient similarity to an IP packet
301 struct igmpmsg {
302 u_long unused1;
303 u_long unused2;
304 u_char im_msgtype; /* what type of message */
305 #define IGMPMSG_NOCACHE 1 /* no MFC in the kernel */
306 #define IGMPMSG_WRONGVIF 2 /* packet came from wrong interface */
307 #define IGMPMSG_WHOLEPKT 3 /* PIM pkt for user level encap. */
308 #define IGMPMSG_BW_UPCALL 4 /* BW monitoring upcall */
309 u_char im_mbz; /* must be zero */
310 u_char im_vif; /* vif rec'd on */
311 u_char unused3;
312 struct in_addr im_src, im_dst;
316 * Argument structure used for pkt info. while upcall is made
318 struct rtdetq {
319 struct mbuf *m; /* A copy of the packet */
320 struct ifnet *ifp; /* Interface pkt came in on */
321 vifi_t xmt_vif; /* Saved copy of imo_multicast_vif */
322 struct rtdetq *next; /* Next in list of packets */
325 #define MFCTBLSIZ 256
326 #if (MFCTBLSIZ & (MFCTBLSIZ - 1)) == 0 /* from sys:route.h */
327 #define MFCHASHMOD(h) ((h) & (MFCTBLSIZ - 1))
328 #else
329 #define MFCHASHMOD(h) ((h) % MFCTBLSIZ)
330 #endif
332 #define MAX_UPQ 4 /* max. no of pkts in upcall Q */
335 * Token Bucket filter code
337 #define MAX_BKT_SIZE 10000 /* 10K bytes size */
338 #define MAXQSIZE 10 /* max # of pkts in queue */
341 * the token bucket filter at each vif
343 struct tbf
345 struct timeval tbf_last_pkt_t; /* arr. time of last pkt */
346 u_long tbf_n_tok; /* no of tokens in bucket */
347 u_long tbf_q_len; /* length of queue at this vif */
348 u_long tbf_max_q_len; /* max. queue length */
349 struct mbuf *tbf_q; /* Packet queue */
350 struct mbuf *tbf_t; /* tail-insertion pointer */
354 * Structure for measuring the bandwidth and sending an upcall if the
355 * measured bandwidth is above or below a threshold.
357 struct bw_meter {
358 struct bw_meter *bm_mfc_next; /* next bw meter (same mfc) */
359 struct bw_meter *bm_time_next; /* next bw meter (same time) */
360 uint32_t bm_time_hash; /* the time hash value */
361 struct mfc *bm_mfc; /* the corresponding mfc */
362 uint32_t bm_flags; /* misc flags (see below) */
363 #define BW_METER_UNIT_PACKETS (1 << 0) /* threshold (in packets) */
364 #define BW_METER_UNIT_BYTES (1 << 1) /* threshold (in bytes) */
365 #define BW_METER_GEQ (1 << 2) /* upcall if bw >= threshold */
366 #define BW_METER_LEQ (1 << 3) /* upcall if bw <= threshold */
367 #define BW_METER_USER_FLAGS (BW_METER_UNIT_PACKETS | \
368 BW_METER_UNIT_BYTES | \
369 BW_METER_GEQ | \
370 BW_METER_LEQ)
372 #define BW_METER_UPCALL_DELIVERED (1 << 24) /* upcall was delivered */
374 struct bw_data bm_threshold; /* the upcall threshold */
375 struct bw_data bm_measured; /* the measured bw */
376 struct timeval bm_start_time; /* abs. time */
379 #ifdef _KERNEL
381 struct sockopt;
383 extern int (*ip_mrouter_set)(struct socket *, struct sockopt *);
384 extern int (*ip_mrouter_get)(struct socket *, struct sockopt *);
385 extern int (*ip_mrouter_done)(void);
386 extern int (*mrt_ioctl)(int, caddr_t);
388 #endif /* _KERNEL */
390 #endif /* _NETINET_IP_MROUTE_H_ */