]> git.saurik.com Git - apple/xnu.git/blob - bsd/netinet/ip_mroute.h
0a38bf2605686dc2cd2612404f2bc0e3a1d8bdf7
[apple/xnu.git] / bsd / netinet / ip_mroute.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /*
24 * Copyright (c) 1989 Stephen Deering.
25 * Copyright (c) 1992, 1993
26 * The Regents of the University of California. All rights reserved.
27 *
28 * This code is derived from software contributed to Berkeley by
29 * Stephen Deering of Stanford University.
30 *
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
33 * are met:
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 3. All advertising materials mentioning features or use of this software
40 * must display the following acknowledgement:
41 * This product includes software developed by the University of
42 * California, Berkeley and its contributors.
43 * 4. Neither the name of the University nor the names of its contributors
44 * may be used to endorse or promote products derived from this software
45 * without specific prior written permission.
46 *
47 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * SUCH DAMAGE.
58 *
59 * @(#)ip_mroute.h 8.1 (Berkeley) 6/10/93
60 */
61
62 #ifndef _NETINET_IP_MROUTE_H_
63 #define _NETINET_IP_MROUTE_H_
64 #include <sys/appleapiopts.h>
65
66 /*
67 * Definitions for IP multicast forwarding.
68 *
69 * Written by David Waitzman, BBN Labs, August 1988.
70 * Modified by Steve Deering, Stanford, February 1989.
71 * Modified by Ajit Thyagarajan, PARC, August 1993.
72 * Modified by Ajit Thyagarajan, PARC, August 1994.
73 *
74 * MROUTING Revision: 3.3.1.3
75 */
76
77
78 /*
79 * Multicast Routing set/getsockopt commands.
80 */
81 #define MRT_INIT 100 /* initialize forwarder */
82 #define MRT_DONE 101 /* shut down forwarder */
83 #define MRT_ADD_VIF 102 /* create virtual interface */
84 #define MRT_DEL_VIF 103 /* delete virtual interface */
85 #define MRT_ADD_MFC 104 /* insert forwarding cache entry */
86 #define MRT_DEL_MFC 105 /* delete forwarding cache entry */
87 #define MRT_VERSION 106 /* get kernel version number */
88 #define MRT_ASSERT 107 /* enable PIM assert processing */
89
90
91 #ifdef KERNEL_PRIVATE
92 #define GET_TIME(t) microtime(&t)
93 #endif KERNEL_PRIVATE
94
95 /*
96 * Types and macros for handling bitmaps with one bit per virtual interface.
97 */
98 #define MAXVIFS 32
99 typedef u_long vifbitmap_t;
100 typedef u_short vifi_t; /* type of a vif index */
101 #define ALL_VIFS (vifi_t)-1
102
103 #define VIFM_SET(n, m) ((m) |= (1 << (n)))
104 #define VIFM_CLR(n, m) ((m) &= ~(1 << (n)))
105 #define VIFM_ISSET(n, m) ((m) & (1 << (n)))
106 #define VIFM_CLRALL(m) ((m) = 0x00000000)
107 #define VIFM_COPY(mfrom, mto) ((mto) = (mfrom))
108 #define VIFM_SAME(m1, m2) ((m1) == (m2))
109
110
111 /*
112 * Argument structure for MRT_ADD_VIF.
113 * (MRT_DEL_VIF takes a single vifi_t argument.)
114 */
115 struct vifctl {
116 vifi_t vifc_vifi; /* the index of the vif to be added */
117 u_char vifc_flags; /* VIFF_ flags defined below */
118 u_char vifc_threshold; /* min ttl required to forward on vif */
119 u_int vifc_rate_limit; /* max rate */
120 struct in_addr vifc_lcl_addr; /* local interface address */
121 struct in_addr vifc_rmt_addr; /* remote address (tunnels only) */
122 };
123
124 #define VIFF_TUNNEL 0x1 /* vif represents a tunnel end-point */
125 #define VIFF_SRCRT 0x2 /* tunnel uses IP source routing */
126
127 /*
128 * Argument structure for MRT_ADD_MFC and MRT_DEL_MFC
129 * (mfcc_tos to be added at a future point)
130 */
131 struct mfcctl {
132 struct in_addr mfcc_origin; /* ip origin of mcasts */
133 struct in_addr mfcc_mcastgrp; /* multicast group associated*/
134 vifi_t mfcc_parent; /* incoming vif */
135 u_char mfcc_ttls[MAXVIFS]; /* forwarding ttls on vifs */
136 };
137
138 /*
139 * The kernel's multicast routing statistics.
140 */
141 struct mrtstat {
142 u_long mrts_mfc_lookups; /* # forw. cache hash table hits */
143 u_long mrts_mfc_misses; /* # forw. cache hash table misses */
144 u_long mrts_upcalls; /* # calls to mrouted */
145 u_long mrts_no_route; /* no route for packet's origin */
146 u_long mrts_bad_tunnel; /* malformed tunnel options */
147 u_long mrts_cant_tunnel; /* no room for tunnel options */
148 u_long mrts_wrong_if; /* arrived on wrong interface */
149 u_long mrts_upq_ovflw; /* upcall Q overflow */
150 u_long mrts_cache_cleanups; /* # entries with no upcalls */
151 u_long mrts_drop_sel; /* pkts dropped selectively */
152 u_long mrts_q_overflow; /* pkts dropped - Q overflow */
153 u_long mrts_pkt2large; /* pkts dropped - size > BKT SIZE */
154 u_long mrts_upq_sockfull; /* upcalls dropped - socket full */
155 };
156
157 /*
158 * Argument structure used by mrouted to get src-grp pkt counts
159 */
160 struct sioc_sg_req {
161 struct in_addr src;
162 struct in_addr grp;
163 u_long pktcnt;
164 u_long bytecnt;
165 u_long wrong_if;
166 };
167
168 /*
169 * Argument structure used by mrouted to get vif pkt counts
170 */
171 struct sioc_vif_req {
172 vifi_t vifi; /* vif number */
173 u_long icount; /* Input packet count on vif */
174 u_long ocount; /* Output packet count on vif */
175 u_long ibytes; /* Input byte count on vif */
176 u_long obytes; /* Output byte count on vif */
177 };
178
179 #ifdef PRIVATE
180 /*
181 * The kernel's virtual-interface structure.
182 */
183 struct tbf;
184 struct ifnet;
185 struct socket;
186 struct vif {
187 u_char v_flags; /* VIFF_ flags defined above */
188 u_char v_threshold; /* min ttl required to forward on vif*/
189 u_int v_rate_limit; /* max rate */
190 struct tbf *v_tbf; /* token bucket structure at intf. */
191 struct in_addr v_lcl_addr; /* local interface address */
192 struct in_addr v_rmt_addr; /* remote address (tunnels only) */
193 struct ifnet *v_ifp; /* pointer to interface */
194 u_long v_pkt_in; /* # pkts in on interface */
195 u_long v_pkt_out; /* # pkts out on interface */
196 u_long v_bytes_in; /* # bytes in on interface */
197 u_long v_bytes_out; /* # bytes out on interface */
198 struct route v_route; /* cached route if this is a tunnel */
199 u_int v_rsvp_on; /* RSVP listening on this vif */
200 struct socket *v_rsvpd; /* RSVP daemon socket */
201 };
202 #endif
203
204 /*
205 * The kernel's multicast forwarding cache entry structure
206 * (A field for the type of service (mfc_tos) is to be added
207 * at a future point)
208 */
209 struct mfc {
210 struct in_addr mfc_origin; /* IP origin of mcasts */
211 struct in_addr mfc_mcastgrp; /* multicast group associated*/
212 vifi_t mfc_parent; /* incoming vif */
213 u_char mfc_ttls[MAXVIFS]; /* forwarding ttls on vifs */
214 u_long mfc_pkt_cnt; /* pkt count for src-grp */
215 u_long mfc_byte_cnt; /* byte count for src-grp */
216 u_long mfc_wrong_if; /* wrong if for src-grp */
217 int mfc_expire; /* time to clean entry up */
218 struct timeval mfc_last_assert; /* last time I sent an assert*/
219 struct rtdetq *mfc_stall; /* q of packets awaiting mfc */
220 struct mfc *mfc_next; /* next mfc entry */
221 };
222
223 /*
224 * Struct used to communicate from kernel to multicast router
225 * note the convenient similarity to an IP packet
226 */
227 struct igmpmsg {
228 u_long unused1;
229 u_long unused2;
230 u_char im_msgtype; /* what type of message */
231 #define IGMPMSG_NOCACHE 1
232 #define IGMPMSG_WRONGVIF 2
233 u_char im_mbz; /* must be zero */
234 u_char im_vif; /* vif rec'd on */
235 u_char unused3;
236 struct in_addr im_src, im_dst;
237 };
238 #define MFCTBLSIZ 256
239
240 #ifdef KERNEL_PRIVATE
241 /*
242 * Argument structure used for pkt info. while upcall is made
243 */
244 struct rtdetq {
245 struct mbuf *m; /* A copy of the packet */
246 struct ifnet *ifp; /* Interface pkt came in on */
247 vifi_t xmt_vif; /* Saved copy of imo_multicast_vif */
248 #if UPCALL_TIMING
249 struct timeval t; /* Timestamp */
250 #endif /* UPCALL_TIMING */
251 struct rtdetq *next; /* Next in list of packets */
252 };
253
254 #if (MFCTBLSIZ & (MFCTBLSIZ - 1)) == 0 /* from sys:route.h */
255 #define MFCHASHMOD(h) ((h) & (MFCTBLSIZ - 1))
256 #else
257 #define MFCHASHMOD(h) ((h) % MFCTBLSIZ)
258 #endif
259
260 #define MAX_UPQ 4 /* max. no of pkts in upcall Q */
261
262 /*
263 * Token Bucket filter code
264 */
265 #define MAX_BKT_SIZE 10000 /* 10K bytes size */
266 #define MAXQSIZE 10 /* max # of pkts in queue */
267
268 /*
269 * the token bucket filter at each vif
270 */
271 struct tbf
272 {
273 struct timeval tbf_last_pkt_t; /* arr. time of last pkt */
274 u_long tbf_n_tok; /* no of tokens in bucket */
275 u_long tbf_q_len; /* length of queue at this vif */
276 u_long tbf_max_q_len; /* max. queue length */
277 struct mbuf *tbf_q; /* Packet queue */
278 struct mbuf *tbf_t; /* tail-insertion pointer */
279 };
280
281
282 struct sockopt;
283
284 extern int (*ip_mrouter_set)(struct socket *, struct sockopt *);
285 extern int (*ip_mrouter_get)(struct socket *, struct sockopt *);
286 extern int (*ip_mrouter_done)(void);
287 #if MROUTING
288 extern int (*mrt_ioctl)(int, caddr_t);
289 #else
290 extern int (*mrt_ioctl)(int, caddr_t, struct proc *);
291 #endif
292
293 #endif KERNEL_PRIVATE
294 #endif _NETINET_IP_MROUTE_H_