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