ip6_mroute.h revision 1.3 1 /* $NetBSD: ip6_mroute.h,v 1.3 1999/07/03 21:30:19 thorpej Exp $ */
2
3 /*
4 * Copyright (C) 1998 WIDE Project.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32 /* BSDI ip_mroute.h,v 2.5 1996/10/11 16:01:48 pjd Exp */
33
34 /*
35 * Definitions for IP multicast forwarding.
36 *
37 * Written by David Waitzman, BBN Labs, August 1988.
38 * Modified by Steve Deering, Stanford, February 1989.
39 * Modified by Ajit Thyagarajan, PARC, August 1993.
40 * Modified by Ajit Thyagarajan, PARC, August 1994.
41 * Modified by Ahmed Helmy, USC, September 1996.
42 *
43 * MROUTING Revision: 1.2
44 */
45
46 #ifndef _NETINET6_IP6_MROUTE_H_
47 #define _NETINET6_IP6_MROUTE_H_
48
49 #ifdef __NetBSD__
50 # ifdef _KERNEL
51 # define KERNEL
52 # endif
53 #endif
54
55 /*
56 * Multicast Routing set/getsockopt commands.
57 */
58 #define MRT6_INIT 100 /* initialize forwarder */
59 #define MRT6_DONE 101 /* shut down forwarder */
60 #define MRT6_ADD_MIF 102 /* add multicast interface */
61 #define MRT6_DEL_MIF 103 /* delete multicast interface */
62 #define MRT6_ADD_MFC 104 /* insert forwarding cache entry */
63 #define MRT6_DEL_MFC 105 /* delete forwarding cache entry */
64 #define MRT6_PIM 107 /* enable pim code */
65
66 #if BSD >= 199103
67 #define GET_TIME(t) microtime(&t)
68 #elif defined(sun)
69 #define GET_TIME(t) uniqtime(&t)
70 #else
71 #define GET_TIME(t) ((t) = time)
72 #endif
73
74 /*
75 * Types and macros for handling bitmaps with one bit per multicast interface.
76 */
77 typedef u_short mifi_t; /* type of a mif index */
78 #define MAXMIFS 64
79
80 #ifndef IF_SETSIZE
81 #define IF_SETSIZE 256
82 #endif
83
84 typedef long if_mask;
85 #define NIFBITS (sizeof(if_mask) * NBBY) /* bits per mask */
86
87 #ifndef howmany
88 #define howmany(x, y) (((x) + ((y) - 1)) / (y))
89 #endif
90
91 typedef struct if_set {
92 fd_mask ifs_bits[howmany(IF_SETSIZE, NIFBITS)];
93 } if_set;
94
95 #define IF_SET(n, p) ((p)->ifs_bits[(n)/NIFBITS] |= (1 << ((n) % NIFBITS)))
96 #define IF_CLR(n, p) ((p)->ifs_bits[(n)/NIFBITS] &= ~(1 << ((n) % NIFBITS)))
97 #define IF_ISSET(n, p) ((p)->ifs_bits[(n)/NIFBITS] & (1 << ((n) % NIFBITS)))
98 #define IF_COPY(f, t) bcopy(f, t, sizeof(*(f)))
99 #define IF_ZERO(p) bzero(p, sizeof(*(p)))
100
101 /*
102 * Argument structure for MRT6_ADD_IF.
103 */
104 struct mif6ctl {
105 mifi_t mif6c_mifi; /* the index of the mif to be added */
106 u_char mif6c_flags; /* MIFF_ flags defined below */
107 u_short mif6c_pifi; /* the index of the physical IF */
108 #ifdef notyet
109 u_int mif6c_rate_limit; /* max rate */
110 #endif
111 };
112
113 #define MIFF_REGISTER 0x1 /* mif represents a register end-point */
114
115 /*
116 * Argument structure for MRT6_ADD_MFC and MRT6_DEL_MFC
117 */
118 struct mf6cctl {
119 struct sockaddr_in6 mf6cc_origin; /* IPv6 origin of mcasts */
120 struct sockaddr_in6 mf6cc_mcastgrp; /* multicast group associated */
121 mifi_t mf6cc_parent; /* incoming ifindex */
122 struct if_set mf6cc_ifset; /* set of forwarding ifs */
123 };
124
125 /*
126 * The kernel's multicast routing statistics.
127 */
128 #ifdef __bsdi__
129 struct mrt6stat {
130 u_quad_t mrt6s_mfc_lookups; /* # forw. cache hash table hits */
131 u_quad_t mrt6s_mfc_misses; /* # forw. cache hash table misses */
132 u_quad_t mrt6s_upcalls; /* # calls to mrouted */
133 u_quad_t mrt6s_no_route; /* no route for packet's origin */
134 u_quad_t mrt6s_bad_tunnel; /* malformed tunnel options */
135 u_quad_t mrt6s_cant_tunnel; /* no room for tunnel options */
136 u_quad_t mrt6s_wrong_if; /* arrived on wrong interface */
137 u_quad_t mrt6s_upq_ovflw; /* upcall Q overflow */
138 u_quad_t mrt6s_cache_cleanups; /* # entries with no upcalls */
139 u_quad_t mrt6s_drop_sel; /* pkts dropped selectively */
140 u_quad_t mrt6s_q_overflow; /* pkts dropped - Q overflow */
141 u_quad_t mrt6s_pkt2large; /* pkts dropped - size > BKT SIZE */
142 u_quad_t mrt6s_upq_sockfull; /* upcalls dropped - socket full */
143 };
144 #else
145 struct mrt6stat {
146 u_long mrt6s_mfc_lookups; /* # forw. cache hash table hits */
147 u_long mrt6s_mfc_misses; /* # forw. cache hash table misses */
148 u_long mrt6s_upcalls; /* # calls to mrouted */
149 u_long mrt6s_no_route; /* no route for packet's origin */
150 u_long mrt6s_bad_tunnel; /* malformed tunnel options */
151 u_long mrt6s_cant_tunnel; /* no room for tunnel options */
152 u_long mrt6s_wrong_if; /* arrived on wrong interface */
153 u_long mrt6s_upq_ovflw; /* upcall Q overflow */
154 u_long mrt6s_cache_cleanups; /* # entries with no upcalls */
155 u_long mrt6s_drop_sel; /* pkts dropped selectively */
156 u_long mrt6s_q_overflow; /* pkts dropped - Q overflow */
157 u_long mrt6s_pkt2large; /* pkts dropped - size > BKT SIZE */
158 u_long mrt6s_upq_sockfull; /* upcalls dropped - socket full */
159 };
160 #endif
161
162 /*
163 * Struct used to communicate from kernel to multicast router
164 * note the convenient similarity to an IPv6 header.
165 */
166 struct mrt6msg {
167 u_long unused1;
168 u_char im6_msgtype; /* what type of message */
169 #define MRT6MSG_NOCACHE 1
170 #define MRT6MSG_WRONGMIF 2
171 #define MRT6MSG_WHOLEPKT 3 /* used for user level encap*/
172 u_char im6_mbz; /* must be zero */
173 u_char im6_mif; /* mif rec'd on */
174 u_char unused2;
175 struct in6_addr im6_src, im6_dst;
176 };
177
178 /*
179 * Argument structure used by mrouted to get src-grp pkt counts
180 */
181 struct sioc6_sg_req {
182 struct in6_addr src;
183 struct in6_addr grp;
184 u_long pktcnt;
185 u_long bytecnt;
186 u_long wrong_if;
187 };
188
189 /*
190 * Argument structure used by multicast routing daemon to get src-grp
191 * packet counts
192 */
193 struct sioc_sg_req6 {
194 struct sockaddr_in6 src;
195 struct sockaddr_in6 grp;
196 u_long pktcnt;
197 u_long bytecnt;
198 u_long wrong_if;
199 };
200
201 /*
202 * Argument structure used by mrouted to get mif pkt counts
203 */
204 struct sioc_mif_req6 {
205 mifi_t mifi; /* mif number */
206 u_long icount; /* Input packet count on mif */
207 u_long ocount; /* Output packet count on mif */
208 u_long ibytes; /* Input byte count on mif */
209 u_long obytes; /* Output byte count on mif */
210 };
211
212 #ifdef KERNEL
213 /*
214 * The kernel's multicast-interface structure.
215 */
216 struct mif6 {
217 u_char m6_flags; /* MIFF_ flags defined above */
218 u_int m6_rate_limit; /* max rate */
219 #ifdef notyet
220 struct tbf *m6_tbf; /* token bucket structure at intf. */
221 #endif
222 struct in6_addr m6_lcl_addr; /* local interface address */
223 struct ifnet *m6_ifp; /* pointer to interface */
224 u_long m6_pkt_in; /* # pkts in on interface */
225 u_long m6_pkt_out; /* # pkts out on interface */
226 u_long m6_bytes_in; /* # bytes in on interface */
227 u_long m6_bytes_out; /* # bytes out on interface */
228 struct route_in6 m6_route;/* cached route if this is a tunnel */
229 #ifdef notyet
230 u_int m6_rsvp_on; /* RSVP listening on this vif */
231 struct socket *m6_rsvpd; /* RSVP daemon socket */
232 #endif
233 };
234
235 /*
236 * The kernel's multicast forwarding cache entry structure
237 */
238 struct mf6c {
239 struct sockaddr_in6 mf6c_origin; /* IPv6 origin of mcasts */
240 struct sockaddr_in6 mf6c_mcastgrp; /* multicast group associated*/
241 mifi_t mf6c_parent; /* incoming IF */
242 struct if_set mf6c_ifset; /* set of outgoing IFs */
243
244 u_long mf6c_pkt_cnt; /* pkt count for src-grp */
245 u_long mf6c_byte_cnt; /* byte count for src-grp */
246 u_long mf6c_wrong_if; /* wrong if for src-grp */
247 int mf6c_expire; /* time to clean entry up */
248 struct timeval mf6c_last_assert; /* last time I sent an assert*/
249 struct rtdetq *mf6c_stall; /* pkts waiting for route */
250 struct mf6c *mf6c_next; /* hash table linkage */
251 };
252
253 #define MF6C_INCOMPLETE_PARENT ((mifi_t)-1)
254
255 /*
256 * Argument structure used for pkt info. while upcall is made
257 */
258 #ifndef _NETINET_IP_MROUTE_H_
259 struct rtdetq { /* XXX: rtdetq is also defined in ip_mroute.h */
260 struct mbuf *m; /* A copy of the packet */
261 struct ifnet *ifp; /* Interface pkt came in on */
262 #ifdef UPCALL_TIMING
263 struct timeval t; /* Timestamp */
264 #endif /* UPCALL_TIMING */
265 struct rtdetq *next;
266 };
267 #endif /* _NETINET_IP_MROUTE_H_ */
268
269 #define MF6CTBLSIZ 256
270 #if (MF6CTBLSIZ & (MF6CTBLSIZ - 1)) == 0 /* from sys:route.h */
271 #define MF6CHASHMOD(h) ((h) & (MF6CTBLSIZ - 1))
272 #else
273 #define MF6CHASHMOD(h) ((h) % MF6CTBLSIZ)
274 #endif
275
276 #define MAX_UPQ6 4 /* max. no of pkts in upcall Q */
277
278 int ip6_mrouter_set __P((int, struct socket *, struct mbuf *));
279 int ip6_mrouter_get __P((int, struct socket *, struct mbuf **));
280 int ip6_mrouter_done __P((void));
281 int mrt6_ioctl __P((int, caddr_t));
282 #endif /* KERNEL */
283
284 #endif /* !_NETINET6_IP6_MROUTE_H_ */
285