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