ip_mroute.h revision 92723
11573Srgrimes/*
214287Spst * Copyright (c) 1989 Stephen Deering.
31573Srgrimes * Copyright (c) 1992, 1993
41573Srgrimes *	The Regents of the University of California.  All rights reserved.
51573Srgrimes *
61573Srgrimes * This code is derived from software contributed to Berkeley by
71573Srgrimes * Stephen Deering of Stanford University.
81573Srgrimes *
91573Srgrimes * Redistribution and use in source and binary forms, with or without
101573Srgrimes * modification, are permitted provided that the following conditions
111573Srgrimes * are met:
121573Srgrimes * 1. Redistributions of source code must retain the above copyright
131573Srgrimes *    notice, this list of conditions and the following disclaimer.
141573Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
151573Srgrimes *    notice, this list of conditions and the following disclaimer in the
161573Srgrimes *    documentation and/or other materials provided with the distribution.
171573Srgrimes * 3. All advertising materials mentioning features or use of this software
181573Srgrimes *    must display the following acknowledgement:
191573Srgrimes *	This product includes software developed by the University of
201573Srgrimes *	California, Berkeley and its contributors.
211573Srgrimes * 4. Neither the name of the University nor the names of its contributors
221573Srgrimes *    may be used to endorse or promote products derived from this software
231573Srgrimes *    without specific prior written permission.
241573Srgrimes *
251573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
261573Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
271573Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
281573Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
291573Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
301573Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
311573Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
321573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
331573Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
341573Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
351573Srgrimes * SUCH DAMAGE.
3614287Spst *
3772092Sasmodai *	@(#)ip_mroute.h	8.1 (Berkeley) 6/10/93
381573Srgrimes * $FreeBSD: head/sys/netinet/ip_mroute.h 92723 2002-03-19 21:25:46Z alfred $
391573Srgrimes */
401573Srgrimes
411573Srgrimes#ifndef _NETINET_IP_MROUTE_H_
421573Srgrimes#define _NETINET_IP_MROUTE_H_
431573Srgrimes
441573Srgrimes/*
451573Srgrimes * Definitions for IP multicast forwarding.
461573Srgrimes *
471573Srgrimes * Written by David Waitzman, BBN Labs, August 1988.
481573Srgrimes * Modified by Steve Deering, Stanford, February 1989.
4914287Spst * Modified by Ajit Thyagarajan, PARC, August 1993.
5014287Spst * Modified by Ajit Thyagarajan, PARC, August 1994.
5114287Spst *
5214287Spst * MROUTING Revision: 3.3.1.3
5314287Spst */
5414287Spst
551573Srgrimes
561573Srgrimes/*
571573Srgrimes * Multicast Routing set/getsockopt commands.
581573Srgrimes */
591573Srgrimes#define	MRT_INIT	100	/* initialize forwarder */
601573Srgrimes#define	MRT_DONE	101	/* shut down forwarder */
611573Srgrimes#define	MRT_ADD_VIF	102	/* create virtual interface */
621573Srgrimes#define	MRT_DEL_VIF	103	/* delete virtual interface */
631573Srgrimes#define MRT_ADD_MFC	104	/* insert forwarding cache entry */
641573Srgrimes#define MRT_DEL_MFC	105	/* delete forwarding cache entry */
651573Srgrimes#define MRT_VERSION	106	/* get kernel version number */
6614287Spst#define MRT_ASSERT      107     /* enable PIM assert processing */
6714287Spst
6814287Spst
6914287Spst#define GET_TIME(t)	microtime(&t)
7014287Spst
7114287Spst/*
7214287Spst * Types and macros for handling bitmaps with one bit per virtual interface.
7314287Spst */
7414287Spst#define	MAXVIFS 32
7514287Spsttypedef u_long vifbitmap_t;
7614287Spsttypedef u_short vifi_t;		/* type of a vif index */
7714287Spst#define ALL_VIFS (vifi_t)-1
7814287Spst
7914287Spst#define	VIFM_SET(n, m)		((m) |= (1 << (n)))
8014287Spst#define	VIFM_CLR(n, m)		((m) &= ~(1 << (n)))
8114287Spst#define	VIFM_ISSET(n, m)	((m) & (1 << (n)))
8214287Spst#define	VIFM_CLRALL(m)		((m) = 0x00000000)
8314287Spst#define	VIFM_COPY(mfrom, mto)	((mto) = (mfrom))
8414287Spst#define	VIFM_SAME(m1, m2)	((m1) == (m2))
8514287Spst
8614287Spst
8714287Spst/*
8814287Spst * Argument structure for MRT_ADD_VIF.
8914287Spst * (MRT_DEL_VIF takes a single vifi_t argument.)
9014287Spst */
911573Srgrimesstruct vifctl {
921573Srgrimes	vifi_t	vifc_vifi;	    	/* the index of the vif to be added */
9314287Spst	u_char	vifc_flags;     	/* VIFF_ flags defined below */
9414287Spst	u_char	vifc_threshold; 	/* min ttl required to forward on vif */
9514287Spst	u_int	vifc_rate_limit;	/* max rate */
9614287Spst	struct	in_addr vifc_lcl_addr;	/* local interface address */
9714287Spst	struct	in_addr vifc_rmt_addr;	/* remote address (tunnels only) */
9814287Spst};
9992905Sobrien
10014287Spst#define	VIFF_TUNNEL	0x1		/* vif represents a tunnel end-point */
10114287Spst#define VIFF_SRCRT	0x2		/* tunnel uses IP source routing */
10214287Spst
10314287Spst/*
10414287Spst * Argument structure for MRT_ADD_MFC and MRT_DEL_MFC
10514287Spst * (mfcc_tos to be added at a future point)
10614287Spst */
10714287Spststruct mfcctl {
10872092Sasmodai    struct in_addr  mfcc_origin;		/* ip origin of mcasts       */
10914287Spst    struct in_addr  mfcc_mcastgrp; 		/* multicast group associated*/
11014287Spst    vifi_t	    mfcc_parent;   		/* incoming vif              */
11114287Spst    u_char	    mfcc_ttls[MAXVIFS]; 	/* forwarding ttls on vifs   */
11214287Spst};
11314287Spst
11414287Spst/*
11514287Spst * The kernel's multicast routing statistics.
11614287Spst */
11714287Spststruct mrtstat {
11814287Spst    u_long	mrts_mfc_lookups;	/* # forw. cache hash table hits   */
11914287Spst    u_long	mrts_mfc_misses;	/* # forw. cache hash table misses */
1201573Srgrimes    u_long	mrts_upcalls;		/* # calls to mrouted              */
1211573Srgrimes    u_long	mrts_no_route;		/* no route for packet's origin    */
1221573Srgrimes    u_long	mrts_bad_tunnel;	/* malformed tunnel options        */
1231573Srgrimes    u_long	mrts_cant_tunnel;	/* no room for tunnel options      */
1241573Srgrimes    u_long	mrts_wrong_if;		/* arrived on wrong interface	   */
1251573Srgrimes    u_long	mrts_upq_ovflw;		/* upcall Q overflow		   */
1261573Srgrimes    u_long	mrts_cache_cleanups;	/* # entries with no upcalls 	   */
1271573Srgrimes    u_long  	mrts_drop_sel;     	/* pkts dropped selectively        */
1281573Srgrimes    u_long  	mrts_q_overflow;    	/* pkts dropped - Q overflow       */
1291573Srgrimes    u_long  	mrts_pkt2large;     	/* pkts dropped - size > BKT SIZE  */
1301573Srgrimes    u_long	mrts_upq_sockfull;	/* upcalls dropped - socket full */
1311573Srgrimes};
1321573Srgrimes
1331573Srgrimes/*
1341573Srgrimes * Argument structure used by mrouted to get src-grp pkt counts
1351573Srgrimes */
1361573Srgrimesstruct sioc_sg_req {
1371573Srgrimes    struct in_addr src;
1381573Srgrimes    struct in_addr grp;
1391573Srgrimes    u_long pktcnt;
1401573Srgrimes    u_long bytecnt;
1411573Srgrimes    u_long wrong_if;
14214287Spst};
1431573Srgrimes
1441573Srgrimes/*
14514287Spst * Argument structure used by mrouted to get vif pkt counts
14614287Spst */
14714287Spststruct sioc_vif_req {
14814287Spst    vifi_t vifi;		/* vif number				*/
14914287Spst    u_long icount;		/* Input packet count on vif		*/
1501573Srgrimes    u_long ocount;		/* Output packet count on vif		*/
1511573Srgrimes    u_long ibytes;		/* Input byte count on vif		*/
1521573Srgrimes    u_long obytes;		/* Output byte count on vif		*/
1531573Srgrimes};
1541573Srgrimes
1551573Srgrimes
1561573Srgrimes/*
1571573Srgrimes * The kernel's virtual-interface structure.
1581573Srgrimes */
1591573Srgrimesstruct vif {
1601573Srgrimes    u_char   		v_flags;     	/* VIFF_ flags defined above         */
1611573Srgrimes    u_char   		v_threshold;	/* min ttl required to forward on vif*/
1621573Srgrimes    u_int      		v_rate_limit; 	/* max rate			     */
1631573Srgrimes    struct tbf 	       *v_tbf;       	/* token bucket structure at intf.   */
1641573Srgrimes    struct in_addr 	v_lcl_addr;   	/* local interface address           */
1651573Srgrimes    struct in_addr 	v_rmt_addr;   	/* remote address (tunnels only)     */
1661573Srgrimes    struct ifnet       *v_ifp;	     	/* pointer to interface              */
1671573Srgrimes    u_long		v_pkt_in;	/* # pkts in on interface            */
1681573Srgrimes    u_long		v_pkt_out;	/* # pkts out on interface           */
16914287Spst    u_long		v_bytes_in;	/* # bytes in on interface	     */
1701573Srgrimes    u_long		v_bytes_out;	/* # bytes out on interface	     */
17114287Spst    struct route	v_route;	/* cached route if this is a tunnel */
1721573Srgrimes    u_int		v_rsvp_on;	/* RSVP listening on this vif */
1731573Srgrimes    struct socket      *v_rsvpd;	/* RSVP daemon socket */
1741573Srgrimes};
1751573Srgrimes
1761573Srgrimes/*
1771573Srgrimes * The kernel's multicast forwarding cache entry structure
1781573Srgrimes * (A field for the type of service (mfc_tos) is to be added
1791573Srgrimes * at a future point)
1801573Srgrimes */
1811573Srgrimesstruct mfc {
1821573Srgrimes    struct in_addr  mfc_origin;	 		/* IP origin of mcasts   */
1831573Srgrimes    struct in_addr  mfc_mcastgrp;  		/* multicast group associated*/
1841573Srgrimes    vifi_t	    mfc_parent; 		/* incoming vif              */
1851573Srgrimes    u_char	    mfc_ttls[MAXVIFS]; 		/* forwarding ttls on vifs   */
1861573Srgrimes    u_long	    mfc_pkt_cnt;		/* pkt count for src-grp     */
1871573Srgrimes    u_long	    mfc_byte_cnt;		/* byte count for src-grp    */
1881573Srgrimes    u_long	    mfc_wrong_if;		/* wrong if for src-grp	     */
1891573Srgrimes    int		    mfc_expire;			/* time to clean entry up    */
1901573Srgrimes    struct timeval  mfc_last_assert;		/* last time I sent an assert*/
1911573Srgrimes    struct rtdetq  *mfc_stall;			/* q of packets awaiting mfc */
1921573Srgrimes    struct mfc     *mfc_next;			/* next mfc entry            */
1931573Srgrimes};
1941573Srgrimes
1951573Srgrimes/*
1961573Srgrimes * Struct used to communicate from kernel to multicast router
1971573Srgrimes * note the convenient similarity to an IP packet
1988870Srgrimes */
1991573Srgrimesstruct igmpmsg {
2001573Srgrimes    u_long	    unused1;
2011573Srgrimes    u_long	    unused2;
2021573Srgrimes    u_char	    im_msgtype;			/* what type of message	    */
2031573Srgrimes#define IGMPMSG_NOCACHE		1
2041573Srgrimes#define IGMPMSG_WRONGVIF	2
2051573Srgrimes    u_char	    im_mbz;			/* must be zero		    */
2061573Srgrimes    u_char	    im_vif;			/* vif rec'd on		    */
2071573Srgrimes    u_char	    unused3;
2081573Srgrimes    struct in_addr  im_src, im_dst;
2091573Srgrimes};
2101573Srgrimes
2111573Srgrimes/*
2121573Srgrimes * Argument structure used for pkt info. while upcall is made
2131573Srgrimes */
2141573Srgrimesstruct rtdetq {
2151573Srgrimes    struct mbuf 	*m;		/* A copy of the packet		    */
2161573Srgrimes    struct ifnet	*ifp;		/* Interface pkt came in on	    */
2171573Srgrimes    vifi_t		xmt_vif;	/* Saved copy of imo_multicast_vif  */
2181573Srgrimes#ifdef UPCALL_TIMING
2191573Srgrimes    struct timeval	t;		/* Timestamp */
2201573Srgrimes#endif /* UPCALL_TIMING */
2211573Srgrimes    struct rtdetq	*next;		/* Next in list of packets          */
2221573Srgrimes};
2231573Srgrimes
2241573Srgrimes#define MFCTBLSIZ	256
2251573Srgrimes#if (MFCTBLSIZ & (MFCTBLSIZ - 1)) == 0	  /* from sys:route.h */
2261573Srgrimes#define MFCHASHMOD(h)	((h) & (MFCTBLSIZ - 1))
2271573Srgrimes#else
2281573Srgrimes#define MFCHASHMOD(h)	((h) % MFCTBLSIZ)
2291573Srgrimes#endif
2301573Srgrimes
2311573Srgrimes#define MAX_UPQ	4		/* max. no of pkts in upcall Q */
2321573Srgrimes
2338870Srgrimes/*
2341573Srgrimes * Token Bucket filter code
2351573Srgrimes */
2361573Srgrimes#define MAX_BKT_SIZE    10000             /* 10K bytes size 		*/
2371573Srgrimes#define MAXQSIZE        10                /* max # of pkts in queue 	*/
2381573Srgrimes
2391573Srgrimes/*
2401573Srgrimes * the token bucket filter at each vif
2411573Srgrimes */
2421573Srgrimesstruct tbf
2431573Srgrimes{
2441573Srgrimes    struct timeval tbf_last_pkt_t; /* arr. time of last pkt 	*/
2451573Srgrimes    u_long tbf_n_tok;      	/* no of tokens in bucket 	*/
2461573Srgrimes    u_long tbf_q_len;    	/* length of queue at this vif	*/
2471573Srgrimes    u_long tbf_max_q_len;	/* max. queue length		*/
2481573Srgrimes    struct mbuf *tbf_q;		/* Packet queue			*/
2491573Srgrimes    struct mbuf *tbf_t;		/* tail-insertion pointer	*/
2501573Srgrimes};
2511573Srgrimes
2521573Srgrimes#ifdef _KERNEL
2531573Srgrimes
2541573Srgrimesstruct sockopt;
2551573Srgrimes
2561573Srgrimesextern int	(*ip_mrouter_set)(struct socket *, struct sockopt *);
2571573Srgrimesextern int	(*ip_mrouter_get)(struct socket *, struct sockopt *);
2581573Srgrimesextern int	(*ip_mrouter_done)(void);
2591573Srgrimesextern int	(*mrt_ioctl)(int, caddr_t);
2601573Srgrimes
2611573Srgrimes#endif /* _KERNEL */
2621573Srgrimes
2631573Srgrimes#endif /* _NETINET_IP_MROUTE_H_ */
2641573Srgrimes