ip6_mroute.h revision 162797
164562Sgshapiro/*	$FreeBSD: head/sys/netinet6/ip6_mroute.h 162797 2006-09-29 16:16:41Z bms $	*/
264562Sgshapiro/*	$KAME: ip6_mroute.h,v 1.19 2001/06/14 06:12:55 suz Exp $	*/
364562Sgshapiro
464562Sgshapiro/*-
564562Sgshapiro * Copyright (C) 1998 WIDE Project.
664562Sgshapiro * All rights reserved.
764562Sgshapiro *
864562Sgshapiro * Redistribution and use in source and binary forms, with or without
964562Sgshapiro * modification, are permitted provided that the following conditions
1064562Sgshapiro * are met:
1166494Sgshapiro * 1. Redistributions of source code must retain the above copyright
1264562Sgshapiro *    notice, this list of conditions and the following disclaimer.
1364562Sgshapiro * 2. Redistributions in binary form must reproduce the above copyright
1464562Sgshapiro *    notice, this list of conditions and the following disclaimer in the
1564562Sgshapiro *    documentation and/or other materials provided with the distribution.
1664562Sgshapiro * 3. Neither the name of the project nor the names of its contributors
1764562Sgshapiro *    may be used to endorse or promote products derived from this software
1864562Sgshapiro *    without specific prior written permission.
1964562Sgshapiro *
2064562Sgshapiro * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
2164562Sgshapiro * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2264562Sgshapiro * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2364562Sgshapiro * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
2464562Sgshapiro * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2564562Sgshapiro * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2664562Sgshapiro * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2764562Sgshapiro * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2864562Sgshapiro * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2964562Sgshapiro * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3064562Sgshapiro * SUCH DAMAGE.
3164562Sgshapiro */
3264562Sgshapiro
3364562Sgshapiro/*	BSDI ip_mroute.h,v 2.5 1996/10/11 16:01:48 pjd Exp	*/
3464562Sgshapiro
3564562Sgshapiro/*
3664562Sgshapiro * Definitions for IP multicast forwarding.
3764562Sgshapiro *
3864562Sgshapiro * Written by David Waitzman, BBN Labs, August 1988.
3964562Sgshapiro * Modified by Steve Deering, Stanford, February 1989.
4064562Sgshapiro * Modified by Ajit Thyagarajan, PARC, August 1993.
4164562Sgshapiro * Modified by Ajit Thyagarajan, PARC, August 1994.
4264562Sgshapiro * Modified by Ahmed Helmy, USC, September 1996.
4364562Sgshapiro *
4464562Sgshapiro * MROUTING Revision: 1.2
4564562Sgshapiro */
4664562Sgshapiro
4764562Sgshapiro#ifndef _NETINET6_IP6_MROUTE_H_
4864562Sgshapiro#define _NETINET6_IP6_MROUTE_H_
4964562Sgshapiro
5064562Sgshapiro/*
5164562Sgshapiro * Multicast Routing set/getsockopt commands.
5264562Sgshapiro */
5364562Sgshapiro#ifdef _KERNEL
5464562Sgshapiro#define MRT6_OINIT		100	/* initialize forwarder (omrt6msg) */
5564562Sgshapiro#endif
5664562Sgshapiro#define MRT6_DONE		101	/* shut down forwarder */
5764562Sgshapiro#define MRT6_ADD_MIF		102	/* add multicast interface */
5864562Sgshapiro#define MRT6_DEL_MIF		103	/* delete multicast interface */
5964562Sgshapiro#define MRT6_ADD_MFC		104	/* insert forwarding cache entry */
6064562Sgshapiro#define MRT6_DEL_MFC		105	/* delete forwarding cache entry */
6164562Sgshapiro#define MRT6_PIM                107     /* enable pim code */
6264562Sgshapiro#define MRT6_INIT		108	/* initialize forwarder (mrt6msg) */
6364562Sgshapiro
6464562Sgshapiro#if BSD >= 199103
6566494Sgshapiro#define GET_TIME(t)	microtime(&t)
6666494Sgshapiro#elif defined(sun)
6766494Sgshapiro#define GET_TIME(t)	uniqtime(&t)
6866494Sgshapiro#else
6966494Sgshapiro#define GET_TIME(t)	((t) = time)
7066494Sgshapiro#endif
7166494Sgshapiro
7266494Sgshapiro/*
7366494Sgshapiro * Types and macros for handling bitmaps with one bit per multicast interface.
7466494Sgshapiro */
7566494Sgshapirotypedef u_short mifi_t;		/* type of a mif index */
7666494Sgshapiro#define MAXMIFS		64
7766494Sgshapiro
7864562Sgshapiro#ifndef	IF_SETSIZE
7966494Sgshapiro#define	IF_SETSIZE	256
8066494Sgshapiro#endif
8166494Sgshapiro
8266494Sgshapirotypedef	u_int32_t	if_mask;
8366494Sgshapiro#define	NIFBITS	(sizeof(if_mask) * NBBY)	/* bits per mask */
8466494Sgshapiro
8566494Sgshapiro#ifndef howmany
8666494Sgshapiro#define	howmany(x, y)	(((x) + ((y) - 1)) / (y))
8766494Sgshapiro#endif
8866494Sgshapiro
8966494Sgshapirotypedef	struct if_set {
9066494Sgshapiro	if_mask	ifs_bits[howmany(IF_SETSIZE, NIFBITS)];
9166494Sgshapiro} if_set;
9266494Sgshapiro
9366494Sgshapiro#define	IF_SET(n, p)	((p)->ifs_bits[(n)/NIFBITS] |= (1 << ((n) % NIFBITS)))
9466494Sgshapiro#define	IF_CLR(n, p)	((p)->ifs_bits[(n)/NIFBITS] &= ~(1 << ((n) % NIFBITS)))
9566494Sgshapiro#define	IF_ISSET(n, p)	((p)->ifs_bits[(n)/NIFBITS] & (1 << ((n) % NIFBITS)))
9666494Sgshapiro#define	IF_COPY(f, t)	bcopy(f, t, sizeof(*(f)))
9766494Sgshapiro#define	IF_ZERO(p)	bzero(p, sizeof(*(p)))
9866494Sgshapiro
9966494Sgshapiro/*
10066494Sgshapiro * Argument structure for MRT6_ADD_IF.
10166494Sgshapiro */
10266494Sgshapirostruct mif6ctl {
10366494Sgshapiro	mifi_t	    mif6c_mifi;	    	/* the index of the mif to be added  */
10466494Sgshapiro	u_char	    mif6c_flags;     	/* MIFF_ flags defined below         */
10566494Sgshapiro	u_short	    mif6c_pifi;		/* the index of the physical IF */
10666494Sgshapiro#ifdef notyet
10766494Sgshapiro	u_int	    mif6c_rate_limit;    /* max rate           		     */
10866494Sgshapiro#endif
10966494Sgshapiro};
11066494Sgshapiro
11166494Sgshapiro#define	MIFF_REGISTER	0x1	/* mif represents a register end-point */
11266494Sgshapiro
11366494Sgshapiro/*
11466494Sgshapiro * Argument structure for MRT6_ADD_MFC and MRT6_DEL_MFC
11566494Sgshapiro */
11666494Sgshapirostruct mf6cctl {
11766494Sgshapiro	struct sockaddr_in6 mf6cc_origin;	/* IPv6 origin of mcasts */
11866494Sgshapiro	struct sockaddr_in6 mf6cc_mcastgrp; /* multicast group associated */
11966494Sgshapiro	mifi_t		mf6cc_parent;	/* incoming ifindex */
12066494Sgshapiro	struct if_set	mf6cc_ifset;	/* set of forwarding ifs */
12166494Sgshapiro};
12266494Sgshapiro
12366494Sgshapiro/*
12466494Sgshapiro * The kernel's multicast routing statistics.
12566494Sgshapiro */
12666494Sgshapirostruct mrt6stat {
12766494Sgshapiro	u_quad_t mrt6s_mfc_lookups;	/* # forw. cache hash table hits   */
12866494Sgshapiro	u_quad_t mrt6s_mfc_misses;	/* # forw. cache hash table misses */
12966494Sgshapiro	u_quad_t mrt6s_upcalls;		/* # calls to multicast routing daemon */
13066494Sgshapiro	u_quad_t mrt6s_no_route;	/* no route for packet's origin    */
13166494Sgshapiro	u_quad_t mrt6s_bad_tunnel;	/* malformed tunnel options        */
13266494Sgshapiro	u_quad_t mrt6s_cant_tunnel;	/* no room for tunnel options      */
13366494Sgshapiro	u_quad_t mrt6s_wrong_if;	/* arrived on wrong interface	   */
13466494Sgshapiro	u_quad_t mrt6s_upq_ovflw;	/* upcall Q overflow		   */
13566494Sgshapiro	u_quad_t mrt6s_cache_cleanups;	/* # entries with no upcalls 	   */
13666494Sgshapiro	u_quad_t mrt6s_drop_sel;     	/* pkts dropped selectively        */
13766494Sgshapiro	u_quad_t mrt6s_q_overflow;    	/* pkts dropped - Q overflow       */
13866494Sgshapiro	u_quad_t mrt6s_pkt2large;     	/* pkts dropped - size > BKT SIZE  */
13966494Sgshapiro	u_quad_t mrt6s_upq_sockfull;	/* upcalls dropped - socket full   */
14066494Sgshapiro};
14166494Sgshapiro
14266494Sgshapiro#ifdef MRT6_OINIT
14366494Sgshapiro/*
14466494Sgshapiro * Struct used to communicate from kernel to multicast router
14566494Sgshapiro * note the convenient similarity to an IPv6 header.
14666494Sgshapiro * XXX old version, superseded by mrt6msg.
14766494Sgshapiro */
14866494Sgshapirostruct omrt6msg {
14966494Sgshapiro	u_long	    unused1;
15066494Sgshapiro	u_char	    im6_msgtype;		/* what type of message	    */
15166494Sgshapiro#if 0
15266494Sgshapiro#define MRT6MSG_NOCACHE	1
15366494Sgshapiro#define MRT6MSG_WRONGMIF	2
15466494Sgshapiro#define MRT6MSG_WHOLEPKT	3		/* used for user level encap*/
15566494Sgshapiro#endif
15666494Sgshapiro	u_char	    im6_mbz;			/* must be zero		    */
15766494Sgshapiro	u_char	    im6_mif;			/* mif rec'd on		    */
15866494Sgshapiro	u_char	    unused2;
15966494Sgshapiro	struct in6_addr  im6_src, im6_dst;
16066494Sgshapiro};
16166494Sgshapiro#endif
16266494Sgshapiro
16366494Sgshapiro/*
16466494Sgshapiro * Structure used to communicate from kernel to multicast router.
16566494Sgshapiro * We'll overlay the structure onto an MLD header (not an IPv6 header
16666494Sgshapiro * like igmpmsg{} used for IPv4 implementation). This is because this
16764562Sgshapiro * structure will be passed via an IPv6 raw socket, on which an application
16864562Sgshapiro * will only receive the payload i.e. the data after the IPv6 header and all
16964562Sgshapiro * the extension headers. (see Section 3 of RFC3542)
17064562Sgshapiro */
17164562Sgshapirostruct mrt6msg {
17264562Sgshapiro#define MRT6MSG_NOCACHE		1
17364562Sgshapiro#define MRT6MSG_WRONGMIF	2
17464562Sgshapiro#define MRT6MSG_WHOLEPKT	3		/* used for user level encap*/
17564562Sgshapiro	u_char	    im6_mbz;			/* must be zero		    */
17664562Sgshapiro	u_char	    im6_msgtype;		/* what type of message	    */
17764562Sgshapiro	u_int16_t   im6_mif;			/* mif rec'd on		    */
17864562Sgshapiro	u_int32_t   im6_pad;			/* padding for 64bit arch   */
17964562Sgshapiro	struct in6_addr  im6_src, im6_dst;
18064562Sgshapiro};
18164562Sgshapiro
18264562Sgshapiro/*
18364562Sgshapiro * Argument structure used by multicast routing daemon to get src-grp
18464562Sgshapiro * packet counts
18564562Sgshapiro */
18664562Sgshapirostruct sioc_sg_req6 {
18764562Sgshapiro	struct sockaddr_in6 src;
18864562Sgshapiro	struct sockaddr_in6 grp;
18964562Sgshapiro	u_quad_t pktcnt;
19064562Sgshapiro	u_quad_t bytecnt;
19164562Sgshapiro	u_quad_t wrong_if;
19264562Sgshapiro};
19364562Sgshapiro
19464562Sgshapiro/*
19564562Sgshapiro * Argument structure used by mrouted to get mif pkt counts
19664562Sgshapiro */
19764562Sgshapirostruct sioc_mif_req6 {
19864562Sgshapiro	mifi_t mifi;		/* mif number				*/
19964562Sgshapiro	u_quad_t icount;	/* Input packet count on mif		*/
20064562Sgshapiro	u_quad_t ocount;	/* Output packet count on mif		*/
20164562Sgshapiro	u_quad_t ibytes;	/* Input byte count on mif		*/
20264562Sgshapiro	u_quad_t obytes;	/* Output byte count on mif		*/
20364562Sgshapiro};
20464562Sgshapiro
20564562Sgshapiro#if defined(_KERNEL) || defined(KERNEL)
20664562Sgshapiro/*
20764562Sgshapiro * The kernel's multicast-interface structure.
20864562Sgshapiro */
20964562Sgshapirostruct mif6 {
21064562Sgshapiro        u_char   	m6_flags;     	/* MIFF_ flags defined above         */
21164562Sgshapiro	u_int      	m6_rate_limit; 	/* max rate			     */
21264562Sgshapiro#ifdef notyet
21364562Sgshapiro	struct tbf      *m6_tbf;      	/* token bucket structure at intf.   */
21464562Sgshapiro#endif
21564562Sgshapiro	struct in6_addr	m6_lcl_addr;   	/* local interface address           */
21664562Sgshapiro	struct ifnet    *m6_ifp;     	/* pointer to interface              */
21764562Sgshapiro	u_quad_t	m6_pkt_in;	/* # pkts in on interface            */
21864562Sgshapiro	u_quad_t	m6_pkt_out;	/* # pkts out on interface           */
21964562Sgshapiro	u_quad_t	m6_bytes_in;	/* # bytes in on interface	     */
22064562Sgshapiro	u_quad_t	m6_bytes_out;	/* # bytes out on interface	     */
22164562Sgshapiro	struct route_in6 m6_route;/* cached route if this is a tunnel */
22264562Sgshapiro#ifdef notyet
22364562Sgshapiro	u_int		m6_rsvp_on;	/* RSVP listening on this vif */
22464562Sgshapiro	struct socket   *m6_rsvpd;	/* RSVP daemon socket */
22564562Sgshapiro#endif
22664562Sgshapiro};
22764562Sgshapiro
22864562Sgshapiro/*
22964562Sgshapiro * The kernel's multicast forwarding cache entry structure
23064562Sgshapiro */
23164562Sgshapirostruct mf6c {
23264562Sgshapiro	struct sockaddr_in6  mf6c_origin;	/* IPv6 origin of mcasts     */
23364562Sgshapiro	struct sockaddr_in6  mf6c_mcastgrp;	/* multicast group associated*/
23464562Sgshapiro	mifi_t	    	 mf6c_parent; 		/* incoming IF               */
23564562Sgshapiro	struct if_set	 mf6c_ifset;		/* set of outgoing IFs */
23664562Sgshapiro
23764562Sgshapiro	u_quad_t    	mf6c_pkt_cnt;		/* pkt count for src-grp     */
23864562Sgshapiro	u_quad_t    	mf6c_byte_cnt;		/* byte count for src-grp    */
23964562Sgshapiro	u_quad_t    	mf6c_wrong_if;		/* wrong if for src-grp	     */
24064562Sgshapiro	int	    	mf6c_expire;		/* time to clean entry up    */
24164562Sgshapiro	struct timeval  mf6c_last_assert;	/* last time I sent an assert*/
24264562Sgshapiro	struct rtdetq  *mf6c_stall;		/* pkts waiting for route */
24364562Sgshapiro	struct mf6c    *mf6c_next;		/* hash table linkage */
24464562Sgshapiro};
24564562Sgshapiro
24664562Sgshapiro#define MF6C_INCOMPLETE_PARENT ((mifi_t)-1)
24764562Sgshapiro
24864562Sgshapiro/*
24964562Sgshapiro * Argument structure used for pkt info. while upcall is made
25064562Sgshapiro */
25164562Sgshapiro#ifndef _NETINET_IP_MROUTE_H_
25264562Sgshapirostruct rtdetq {		/* XXX: rtdetq is also defined in ip_mroute.h */
25364562Sgshapiro    struct mbuf 	*m;		/* A copy of the packet	    	    */
25464562Sgshapiro    struct ifnet	*ifp;		/* Interface pkt came in on 	    */
25564562Sgshapiro#ifdef UPCALL_TIMING
25664562Sgshapiro    struct timeval	t;		/* Timestamp */
25764562Sgshapiro#endif /* UPCALL_TIMING */
25864562Sgshapiro    struct rtdetq	*next;
25964562Sgshapiro};
26064562Sgshapiro#endif /* _NETINET_IP_MROUTE_H_ */
26164562Sgshapiro
26264562Sgshapiro#define MF6CTBLSIZ	256
26364562Sgshapiro#if (MF6CTBLSIZ & (MF6CTBLSIZ - 1)) == 0	  /* from sys:route.h */
26464562Sgshapiro#define MF6CHASHMOD(h)	((h) & (MF6CTBLSIZ - 1))
26564562Sgshapiro#else
26664562Sgshapiro#define MF6CHASHMOD(h)	((h) % MF6CTBLSIZ)
26764562Sgshapiro#endif
26864562Sgshapiro
26964562Sgshapiro#define MAX_UPQ6	4		/* max. no of pkts in upcall Q */
27064562Sgshapiro
27164562Sgshapiroint	ip6_mrouter_set __P((struct socket *so, struct sockopt *sopt));
27264562Sgshapiroint	ip6_mrouter_get __P((struct socket *so, struct sockopt *sopt));
27364562Sgshapiroint	ip6_mrouter_done __P((void));
27464562Sgshapiroint	mrt6_ioctl __P((int, caddr_t));
27564562Sgshapiro#endif /* _KERNEL */
27664562Sgshapiro
27764562Sgshapiro#endif /* !_NETINET6_IP6_MROUTE_H_ */
27864562Sgshapiro