ip6_mroute.h revision 171260
1154047Sgrehan/*	$FreeBSD: head/sys/netinet6/ip6_mroute.h 171260 2007-07-05 16:29:40Z delphij $	*/
2154047Sgrehan/*	$KAME: ip6_mroute.h,v 1.19 2001/06/14 06:12:55 suz Exp $	*/
3204977Simp
4204977Simp/*-
5154047Sgrehan * Copyright (C) 1998 WIDE Project.
6154047Sgrehan * All rights reserved.
7154047Sgrehan *
8154047Sgrehan * Redistribution and use in source and binary forms, with or without
9154047Sgrehan * modification, are permitted provided that the following conditions
10154047Sgrehan * are met:
11154047Sgrehan * 1. Redistributions of source code must retain the above copyright
12154047Sgrehan *    notice, this list of conditions and the following disclaimer.
13154047Sgrehan * 2. Redistributions in binary form must reproduce the above copyright
14154047Sgrehan *    notice, this list of conditions and the following disclaimer in the
15154047Sgrehan *    documentation and/or other materials provided with the distribution.
16154047Sgrehan * 3. Neither the name of the project nor the names of its contributors
17154047Sgrehan *    may be used to endorse or promote products derived from this software
18154047Sgrehan *    without specific prior written permission.
19154047Sgrehan *
20154047Sgrehan * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21154047Sgrehan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22154047Sgrehan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23154047Sgrehan * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24154047Sgrehan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25154047Sgrehan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26154047Sgrehan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27154047Sgrehan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28288424Sjhb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29288424Sjhb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30154047Sgrehan * SUCH DAMAGE.
31288424Sjhb */
32154047Sgrehan
33168569Sdelphij/*	BSDI ip_mroute.h,v 2.5 1996/10/11 16:01:48 pjd Exp	*/
34154047Sgrehan
35154047Sgrehan/*
36154047Sgrehan * Definitions for IP multicast forwarding.
37154047Sgrehan *
38154047Sgrehan * Written by David Waitzman, BBN Labs, August 1988.
39154047Sgrehan * Modified by Steve Deering, Stanford, February 1989.
40294849Sjhb * Modified by Ajit Thyagarajan, PARC, August 1993.
41154047Sgrehan * Modified by Ajit Thyagarajan, PARC, August 1994.
42154047Sgrehan * Modified by Ahmed Helmy, USC, September 1996.
43154047Sgrehan *
44288424Sjhb * MROUTING Revision: 1.2
45288424Sjhb */
46240562Szont
47240005Szont#ifndef _NETINET6_IP6_MROUTE_H_
48240005Szont#define _NETINET6_IP6_MROUTE_H_
49288424Sjhb
50240562Szont/*
51288424Sjhb * Multicast Routing set/getsockopt commands.
52154047Sgrehan */
53240562Szont#ifdef _KERNEL
54288424Sjhb#define MRT6_OINIT		100	/* initialize forwarder (omrt6msg) */
55240562Szont#endif
56240005Szont#define MRT6_DONE		101	/* shut down forwarder */
57288424Sjhb#define MRT6_ADD_MIF		102	/* add multicast interface */
58240005Szont#define MRT6_DEL_MIF		103	/* delete multicast interface */
59154047Sgrehan#define MRT6_ADD_MFC		104	/* insert forwarding cache entry */
60240005Szont#define MRT6_DEL_MFC		105	/* delete forwarding cache entry */
61288424Sjhb#define MRT6_PIM                107     /* enable pim code */
62240005Szont#define MRT6_INIT		108	/* initialize forwarder (mrt6msg) */
63240005Szont
64288424Sjhb#if BSD >= 199103
65288424Sjhb#define GET_TIME(t)	microtime(&t)
66288424Sjhb#elif defined(sun)
67240005Szont#define GET_TIME(t)	uniqtime(&t)
68288424Sjhb#else
69288424Sjhb#define GET_TIME(t)	((t) = time)
70288424Sjhb#endif
71288424Sjhb
72288424Sjhb/*
73288424Sjhb * Types and macros for handling bitmaps with one bit per multicast interface.
74288424Sjhb */
75288424Sjhbtypedef u_short mifi_t;		/* type of a mif index */
76240005Szont#define MAXMIFS		64
77154047Sgrehan
78288424Sjhb#ifndef	IF_SETSIZE
79288424Sjhb#define	IF_SETSIZE	256
80240005Szont#endif
81288424Sjhb
82240005Szonttypedef	u_int32_t	if_mask;
83240005Szont#define	NIFBITS	(sizeof(if_mask) * NBBY)	/* bits per mask */
84288424Sjhb
85288424Sjhb#ifndef howmany
86240562Szont#define	howmany(x, y)	(((x) + ((y) - 1)) / (y))
87240005Szont#endif
88288424Sjhb
89240005Szonttypedef	struct if_set {
90154047Sgrehan	if_mask	ifs_bits[howmany(IF_SETSIZE, NIFBITS)];
91288424Sjhb} if_set;
92154047Sgrehan
93154047Sgrehan#define	IF_SET(n, p)	((p)->ifs_bits[(n)/NIFBITS] |= (1 << ((n) % NIFBITS)))
94288424Sjhb#define	IF_CLR(n, p)	((p)->ifs_bits[(n)/NIFBITS] &= ~(1 << ((n) % NIFBITS)))
95288424Sjhb#define	IF_ISSET(n, p)	((p)->ifs_bits[(n)/NIFBITS] & (1 << ((n) % NIFBITS)))
96154047Sgrehan#define	IF_COPY(f, t)	bcopy(f, t, sizeof(*(f)))
97240005Szont#define	IF_ZERO(p)	bzero(p, sizeof(*(p)))
98240562Szont
99154047Sgrehan/*
100240562Szont * Argument structure for MRT6_ADD_IF.
101240562Szont */
102288424Sjhbstruct mif6ctl {
103240005Szont	mifi_t	    mif6c_mifi;		/* the index of the mif to be added  */
104240005Szont	u_char	    mif6c_flags;	/* MIFF_ flags defined below         */
105154047Sgrehan	u_short	    mif6c_pifi;		/* the index of the physical IF */
106288424Sjhb};
107288424Sjhb
108288424Sjhb#define	MIFF_REGISTER	0x1	/* mif represents a register end-point */
109288424Sjhb
110288424Sjhb/*
111288424Sjhb * Argument structure for MRT6_ADD_MFC and MRT6_DEL_MFC
112154047Sgrehan */
113289239Sbdrewerystruct mf6cctl {
114288424Sjhb	struct sockaddr_in6 mf6cc_origin;	/* IPv6 origin of mcasts */
115295056Sjhb	struct sockaddr_in6 mf6cc_mcastgrp; /* multicast group associated */
116288424Sjhb	mifi_t		mf6cc_parent;	/* incoming ifindex */
117288424Sjhb	struct if_set	mf6cc_ifset;	/* set of forwarding ifs */
118288424Sjhb};
119154047Sgrehan
120289239Sbdrewery/*
121 * The kernel's multicast routing statistics.
122 */
123struct mrt6stat {
124	u_quad_t mrt6s_mfc_lookups;	/* # forw. cache hash table hits   */
125	u_quad_t mrt6s_mfc_misses;	/* # forw. cache hash table misses */
126	u_quad_t mrt6s_upcalls;		/* # calls to multicast routing daemon */
127	u_quad_t mrt6s_no_route;	/* no route for packet's origin    */
128	u_quad_t mrt6s_bad_tunnel;	/* malformed tunnel options        */
129	u_quad_t mrt6s_cant_tunnel;	/* no room for tunnel options      */
130	u_quad_t mrt6s_wrong_if;	/* arrived on wrong interface	   */
131	u_quad_t mrt6s_upq_ovflw;	/* upcall Q overflow		   */
132	u_quad_t mrt6s_cache_cleanups;	/* # entries with no upcalls	   */
133	u_quad_t mrt6s_drop_sel;	/* pkts dropped selectively        */
134	u_quad_t mrt6s_q_overflow;	/* pkts dropped - Q overflow       */
135	u_quad_t mrt6s_pkt2large;	/* pkts dropped - size > BKT SIZE  */
136	u_quad_t mrt6s_upq_sockfull;	/* upcalls dropped - socket full   */
137};
138
139#ifdef MRT6_OINIT
140/*
141 * Struct used to communicate from kernel to multicast router
142 * note the convenient similarity to an IPv6 header.
143 * XXX old version, superseded by mrt6msg.
144 */
145struct omrt6msg {
146	u_long	    unused1;
147	u_char	    im6_msgtype;		/* what type of message	    */
148#if 0
149#define MRT6MSG_NOCACHE	1
150#define MRT6MSG_WRONGMIF	2
151#define MRT6MSG_WHOLEPKT	3		/* used for user level encap*/
152#endif
153	u_char	    im6_mbz;			/* must be zero		    */
154	u_char	    im6_mif;			/* mif rec'd on		    */
155	u_char	    unused2;
156	struct in6_addr  im6_src, im6_dst;
157};
158#endif
159
160/*
161 * Structure used to communicate from kernel to multicast router.
162 * We'll overlay the structure onto an MLD header (not an IPv6 header
163 * like igmpmsg{} used for IPv4 implementation). This is because this
164 * structure will be passed via an IPv6 raw socket, on which an application
165 * will only receive the payload i.e. the data after the IPv6 header and all
166 * the extension headers. (see Section 3 of RFC3542)
167 */
168struct mrt6msg {
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_msgtype;		/* what type of message	    */
174	u_int16_t   im6_mif;			/* mif rec'd on		    */
175	u_int32_t   im6_pad;			/* padding for 64bit arch   */
176	struct in6_addr  im6_src, im6_dst;
177};
178
179/*
180 * Argument structure used by multicast routing daemon to get src-grp
181 * packet counts
182 */
183struct sioc_sg_req6 {
184	struct sockaddr_in6 src;
185	struct sockaddr_in6 grp;
186	u_quad_t pktcnt;
187	u_quad_t bytecnt;
188	u_quad_t wrong_if;
189};
190
191/*
192 * Argument structure used by mrouted to get mif pkt counts
193 */
194struct sioc_mif_req6 {
195	mifi_t mifi;		/* mif number				*/
196	u_quad_t icount;	/* Input packet count on mif		*/
197	u_quad_t ocount;	/* Output packet count on mif		*/
198	u_quad_t ibytes;	/* Input byte count on mif		*/
199	u_quad_t obytes;	/* Output byte count on mif		*/
200};
201
202#if defined(_KERNEL) || defined(KERNEL)
203/*
204 * The kernel's multicast-interface structure.
205 */
206struct mif6 {
207        u_char		m6_flags;	/* MIFF_ flags defined above         */
208	u_int		m6_rate_limit;	/* max rate			     */
209	struct in6_addr	m6_lcl_addr;	/* local interface address           */
210	struct ifnet    *m6_ifp;	/* pointer to interface              */
211	u_quad_t	m6_pkt_in;	/* # pkts in on interface            */
212	u_quad_t	m6_pkt_out;	/* # pkts out on interface           */
213	u_quad_t	m6_bytes_in;	/* # bytes in on interface	     */
214	u_quad_t	m6_bytes_out;	/* # bytes out on interface	     */
215	struct route_in6 m6_route;/* cached route if this is a tunnel */
216#ifdef notyet
217	u_int		m6_rsvp_on;	/* RSVP listening on this vif */
218	struct socket   *m6_rsvpd;	/* RSVP daemon socket */
219#endif
220};
221
222/*
223 * The kernel's multicast forwarding cache entry structure
224 */
225struct mf6c {
226	struct sockaddr_in6  mf6c_origin;	/* IPv6 origin of mcasts     */
227	struct sockaddr_in6  mf6c_mcastgrp;	/* multicast group associated*/
228	mifi_t		 mf6c_parent;		/* incoming IF               */
229	struct if_set	 mf6c_ifset;		/* set of outgoing IFs */
230
231	u_quad_t	mf6c_pkt_cnt;		/* pkt count for src-grp     */
232	u_quad_t	mf6c_byte_cnt;		/* byte count for src-grp    */
233	u_quad_t	mf6c_wrong_if;		/* wrong if for src-grp	     */
234	int		mf6c_expire;		/* time to clean entry up    */
235	struct timeval  mf6c_last_assert;	/* last time I sent an assert*/
236	struct rtdetq  *mf6c_stall;		/* pkts waiting for route */
237	struct mf6c    *mf6c_next;		/* hash table linkage */
238};
239
240#define MF6C_INCOMPLETE_PARENT ((mifi_t)-1)
241
242/*
243 * Argument structure used for pkt info. while upcall is made
244 */
245#ifndef _NETINET_IP_MROUTE_H_
246struct rtdetq {		/* XXX: rtdetq is also defined in ip_mroute.h */
247    struct mbuf		*m;		/* A copy of the packet		    */
248    struct ifnet	*ifp;		/* Interface pkt came in on	    */
249#ifdef UPCALL_TIMING
250    struct timeval	t;		/* Timestamp */
251#endif /* UPCALL_TIMING */
252    struct rtdetq	*next;
253};
254#endif /* _NETINET_IP_MROUTE_H_ */
255
256#define MF6CTBLSIZ	256
257#if (MF6CTBLSIZ & (MF6CTBLSIZ - 1)) == 0	  /* from sys:route.h */
258#define MF6CHASHMOD(h)	((h) & (MF6CTBLSIZ - 1))
259#else
260#define MF6CHASHMOD(h)	((h) % MF6CTBLSIZ)
261#endif
262
263#define MAX_UPQ6	4		/* max. no of pkts in upcall Q */
264
265extern int	(*ip6_mrouter_set)(struct socket *so, struct sockopt *sopt);
266extern int	(*ip6_mrouter_get)(struct socket *so, struct sockopt *sopt);
267extern int	(*ip6_mrouter_done)(void);
268extern int	(*mrt6_ioctl)(int, caddr_t);
269#endif /* _KERNEL */
270
271#endif /* !_NETINET6_IP6_MROUTE_H_ */
272