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