ip_mroute.h revision 55205
11541Srgrimes/*
21541Srgrimes * Copyright (c) 1989 Stephen Deering.
31541Srgrimes * Copyright (c) 1992, 1993
41541Srgrimes *	The Regents of the University of California.  All rights reserved.
51541Srgrimes *
61541Srgrimes * This code is derived from software contributed to Berkeley by
71541Srgrimes * Stephen Deering of Stanford University.
81541Srgrimes *
91541Srgrimes * Redistribution and use in source and binary forms, with or without
101541Srgrimes * modification, are permitted provided that the following conditions
111541Srgrimes * are met:
121541Srgrimes * 1. Redistributions of source code must retain the above copyright
131541Srgrimes *    notice, this list of conditions and the following disclaimer.
141541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
151541Srgrimes *    notice, this list of conditions and the following disclaimer in the
161541Srgrimes *    documentation and/or other materials provided with the distribution.
171541Srgrimes * 3. All advertising materials mentioning features or use of this software
181541Srgrimes *    must display the following acknowledgement:
191541Srgrimes *	This product includes software developed by the University of
201541Srgrimes *	California, Berkeley and its contributors.
211541Srgrimes * 4. Neither the name of the University nor the names of its contributors
221541Srgrimes *    may be used to endorse or promote products derived from this software
231541Srgrimes *    without specific prior written permission.
241541Srgrimes *
251541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
261541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
271541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
281541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
291541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
301541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
311541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
321541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
331541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
341541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
351541Srgrimes * SUCH DAMAGE.
361541Srgrimes *
371541Srgrimes *	@(#)ip_mroute.h	8.1 (Berkeley) 6/10/93
3850477Speter * $FreeBSD: head/sys/netinet/ip_mroute.h 55205 1999-12-29 04:46:21Z peter $
391541Srgrimes */
401541Srgrimes
412169Spaul#ifndef _NETINET_IP_MROUTE_H_
422169Spaul#define _NETINET_IP_MROUTE_H_
432169Spaul
441541Srgrimes/*
459209Swollman * Definitions for IP multicast forwarding.
461541Srgrimes *
471541Srgrimes * Written by David Waitzman, BBN Labs, August 1988.
481541Srgrimes * Modified by Steve Deering, Stanford, February 1989.
492531Swollman * Modified by Ajit Thyagarajan, PARC, August 1993.
502531Swollman * Modified by Ajit Thyagarajan, PARC, August 1994.
511541Srgrimes *
529209Swollman * MROUTING Revision: 3.3.1.3
531541Srgrimes */
541541Srgrimes
551541Srgrimes
561541Srgrimes/*
579209Swollman * Multicast Routing set/getsockopt commands.
581541Srgrimes */
599209Swollman#define	MRT_INIT	100	/* initialize forwarder */
609209Swollman#define	MRT_DONE	101	/* shut down forwarder */
619209Swollman#define	MRT_ADD_VIF	102	/* create virtual interface */
629209Swollman#define	MRT_DEL_VIF	103	/* delete virtual interface */
639209Swollman#define MRT_ADD_MFC	104	/* insert forwarding cache entry */
649209Swollman#define MRT_DEL_MFC	105	/* delete forwarding cache entry */
659209Swollman#define MRT_VERSION	106	/* get kernel version number */
669209Swollman#define MRT_ASSERT      107     /* enable PIM assert processing */
671541Srgrimes
689209Swollman
692531Swollman#define GET_TIME(t)	microtime(&t)
701541Srgrimes
711541Srgrimes/*
721541Srgrimes * Types and macros for handling bitmaps with one bit per virtual interface.
731541Srgrimes */
741541Srgrimes#define	MAXVIFS 32
751541Srgrimestypedef u_long vifbitmap_t;
761541Srgrimestypedef u_short vifi_t;		/* type of a vif index */
779209Swollman#define ALL_VIFS (vifi_t)-1
781541Srgrimes
791541Srgrimes#define	VIFM_SET(n, m)		((m) |= (1 << (n)))
801541Srgrimes#define	VIFM_CLR(n, m)		((m) &= ~(1 << (n)))
811541Srgrimes#define	VIFM_ISSET(n, m)	((m) & (1 << (n)))
821541Srgrimes#define	VIFM_CLRALL(m)		((m) = 0x00000000)
831541Srgrimes#define	VIFM_COPY(mfrom, mto)	((mto) = (mfrom))
841541Srgrimes#define	VIFM_SAME(m1, m2)	((m1) == (m2))
851541Srgrimes
861541Srgrimes
871541Srgrimes/*
889209Swollman * Argument structure for MRT_ADD_VIF.
899209Swollman * (MRT_DEL_VIF takes a single vifi_t argument.)
901541Srgrimes */
911541Srgrimesstruct vifctl {
929209Swollman	vifi_t	vifc_vifi;	    	/* the index of the vif to be added */
939209Swollman	u_char	vifc_flags;     	/* VIFF_ flags defined below */
949209Swollman	u_char	vifc_threshold; 	/* min ttl required to forward on vif */
959209Swollman	u_int	vifc_rate_limit;	/* max rate */
961541Srgrimes	struct	in_addr vifc_lcl_addr;	/* local interface address */
971541Srgrimes	struct	in_addr vifc_rmt_addr;	/* remote address (tunnels only) */
981541Srgrimes};
991541Srgrimes
1001541Srgrimes#define	VIFF_TUNNEL	0x1		/* vif represents a tunnel end-point */
1019209Swollman#define VIFF_SRCRT	0x2		/* tunnel uses IP source routing */
1021541Srgrimes
1032531Swollman/*
1049209Swollman * Argument structure for MRT_ADD_MFC and MRT_DEL_MFC
1052531Swollman * (mfcc_tos to be added at a future point)
1062531Swollman */
1072531Swollmanstruct mfcctl {
1089209Swollman    struct in_addr  mfcc_origin;		/* ip origin of mcasts       */
1092531Swollman    struct in_addr  mfcc_mcastgrp; 		/* multicast group associated*/
1102531Swollman    vifi_t	    mfcc_parent;   		/* incoming vif              */
1112531Swollman    u_char	    mfcc_ttls[MAXVIFS]; 	/* forwarding ttls on vifs   */
1122531Swollman};
1131541Srgrimes
1141541Srgrimes/*
1152531Swollman * The kernel's multicast routing statistics.
1161541Srgrimes */
1172531Swollmanstruct mrtstat {
1182531Swollman    u_long	mrts_mfc_lookups;	/* # forw. cache hash table hits   */
1192531Swollman    u_long	mrts_mfc_misses;	/* # forw. cache hash table misses */
1202531Swollman    u_long	mrts_upcalls;		/* # calls to mrouted              */
1212531Swollman    u_long	mrts_no_route;		/* no route for packet's origin    */
1222531Swollman    u_long	mrts_bad_tunnel;	/* malformed tunnel options        */
1232531Swollman    u_long	mrts_cant_tunnel;	/* no room for tunnel options      */
1242531Swollman    u_long	mrts_wrong_if;		/* arrived on wrong interface	   */
1252531Swollman    u_long	mrts_upq_ovflw;		/* upcall Q overflow		   */
1262531Swollman    u_long	mrts_cache_cleanups;	/* # entries with no upcalls 	   */
1272531Swollman    u_long  	mrts_drop_sel;     	/* pkts dropped selectively        */
1282531Swollman    u_long  	mrts_q_overflow;    	/* pkts dropped - Q overflow       */
1292531Swollman    u_long  	mrts_pkt2large;     	/* pkts dropped - size > BKT SIZE  */
1309209Swollman    u_long	mrts_upq_sockfull;	/* upcalls dropped - socket full */
1311541Srgrimes};
1321541Srgrimes
1332531Swollman/*
1342531Swollman * Argument structure used by mrouted to get src-grp pkt counts
1352531Swollman */
1362531Swollmanstruct sioc_sg_req {
1372531Swollman    struct in_addr src;
1382531Swollman    struct in_addr grp;
1399209Swollman    u_long pktcnt;
1409209Swollman    u_long bytecnt;
1419209Swollman    u_long wrong_if;
1422531Swollman};
1431541Srgrimes
1442531Swollman/*
1452531Swollman * Argument structure used by mrouted to get vif pkt counts
1462531Swollman */
1472531Swollmanstruct sioc_vif_req {
1489209Swollman    vifi_t vifi;		/* vif number				*/
1499209Swollman    u_long icount;		/* Input packet count on vif		*/
1509209Swollman    u_long ocount;		/* Output packet count on vif		*/
1519209Swollman    u_long ibytes;		/* Input byte count on vif		*/
1529209Swollman    u_long obytes;		/* Output byte count on vif		*/
1532531Swollman};
1549209Swollman
1552531Swollman
1569209Swollman/*
1579209Swollman * The kernel's virtual-interface structure.
1589209Swollman */
1592531Swollmanstruct vif {
1602531Swollman    u_char   		v_flags;     	/* VIFF_ flags defined above         */
1612531Swollman    u_char   		v_threshold;	/* min ttl required to forward on vif*/
1622531Swollman    u_int      		v_rate_limit; 	/* max rate			     */
1632531Swollman    struct tbf 	       *v_tbf;       	/* token bucket structure at intf.   */
1642531Swollman    struct in_addr 	v_lcl_addr;   	/* local interface address           */
1652531Swollman    struct in_addr 	v_rmt_addr;   	/* remote address (tunnels only)     */
1662531Swollman    struct ifnet       *v_ifp;	     	/* pointer to interface              */
1672531Swollman    u_long		v_pkt_in;	/* # pkts in on interface            */
1682531Swollman    u_long		v_pkt_out;	/* # pkts out on interface           */
1699209Swollman    u_long		v_bytes_in;	/* # bytes in on interface	     */
1709209Swollman    u_long		v_bytes_out;	/* # bytes out on interface	     */
1719209Swollman    struct route	v_route;	/* cached route if this is a tunnel */
1729209Swollman    u_int		v_rsvp_on;	/* RSVP listening on this vif */
1739209Swollman    struct socket      *v_rsvpd;	/* RSVP daemon socket */
1742531Swollman};
1752531Swollman
1761541Srgrimes/*
1779209Swollman * The kernel's multicast forwarding cache entry structure
1789209Swollman * (A field for the type of service (mfc_tos) is to be added
1792531Swollman * at a future point)
1801541Srgrimes */
1812531Swollmanstruct mfc {
1829209Swollman    struct in_addr  mfc_origin;	 		/* IP origin of mcasts   */
1832531Swollman    struct in_addr  mfc_mcastgrp;  		/* multicast group associated*/
1842531Swollman    vifi_t	    mfc_parent; 		/* incoming vif              */
1852531Swollman    u_char	    mfc_ttls[MAXVIFS]; 		/* forwarding ttls on vifs   */
1862531Swollman    u_long	    mfc_pkt_cnt;		/* pkt count for src-grp     */
1879209Swollman    u_long	    mfc_byte_cnt;		/* byte count for src-grp    */
1889209Swollman    u_long	    mfc_wrong_if;		/* wrong if for src-grp	     */
1899209Swollman    int		    mfc_expire;			/* time to clean entry up    */
1909209Swollman    struct timeval  mfc_last_assert;		/* last time I sent an assert*/
19142777Sfenner    struct rtdetq  *mfc_stall;			/* q of packets awaiting mfc */
19242777Sfenner    struct mfc     *mfc_next;			/* next mfc entry            */
1931541Srgrimes};
1941541Srgrimes
1951541Srgrimes/*
1969209Swollman * Struct used to communicate from kernel to multicast router
1979209Swollman * note the convenient similarity to an IP packet
1989209Swollman */
1999209Swollmanstruct igmpmsg {
2009209Swollman    u_long	    unused1;
2019209Swollman    u_long	    unused2;
2029209Swollman    u_char	    im_msgtype;			/* what type of message	    */
2039209Swollman#define IGMPMSG_NOCACHE		1
2049209Swollman#define IGMPMSG_WRONGVIF	2
2059209Swollman    u_char	    im_mbz;			/* must be zero		    */
2069209Swollman    u_char	    im_vif;			/* vif rec'd on		    */
2079209Swollman    u_char	    unused3;
2089209Swollman    struct in_addr  im_src, im_dst;
2099209Swollman};
2109209Swollman
2119209Swollman/*
2122531Swollman * Argument structure used for pkt info. while upcall is made
2131541Srgrimes */
2142531Swollmanstruct rtdetq {
2159209Swollman    struct mbuf 	*m;		/* A copy of the packet		    */
2169209Swollman    struct ifnet	*ifp;		/* Interface pkt came in on	    */
2179209Swollman    vifi_t		xmt_vif;	/* Saved copy of imo_multicast_vif  */
2189209Swollman#ifdef UPCALL_TIMING
2199209Swollman    struct timeval	t;		/* Timestamp */
2209209Swollman#endif /* UPCALL_TIMING */
22142777Sfenner    struct rtdetq	*next;		/* Next in list of packets          */
2221541Srgrimes};
2231541Srgrimes
2242531Swollman#define MFCTBLSIZ	256
2252531Swollman#if (MFCTBLSIZ & (MFCTBLSIZ - 1)) == 0	  /* from sys:route.h */
2262531Swollman#define MFCHASHMOD(h)	((h) & (MFCTBLSIZ - 1))
2271541Srgrimes#else
2282531Swollman#define MFCHASHMOD(h)	((h) % MFCTBLSIZ)
2291541Srgrimes#endif
2301541Srgrimes
2312531Swollman#define MAX_UPQ	4		/* max. no of pkts in upcall Q */
2322531Swollman
2331541Srgrimes/*
2349209Swollman * Token Bucket filter code
2351541Srgrimes */
2362531Swollman#define MAX_BKT_SIZE    10000             /* 10K bytes size 		*/
2372531Swollman#define MAXQSIZE        10                /* max # of pkts in queue 	*/
2382531Swollman
2392531Swollman/*
2402531Swollman * the token bucket filter at each vif
2412531Swollman */
2422531Swollmanstruct tbf
2432531Swollman{
24410203Swollman    struct timeval tbf_last_pkt_t; /* arr. time of last pkt 	*/
24510203Swollman    u_long tbf_n_tok;      	/* no of tokens in bucket 	*/
24610203Swollman    u_long tbf_q_len;    	/* length of queue at this vif	*/
24710203Swollman    u_long tbf_max_q_len;	/* max. queue length		*/
24810203Swollman    struct mbuf *tbf_q;		/* Packet queue			*/
24910203Swollman    struct mbuf *tbf_t;		/* tail-insertion pointer	*/
2502531Swollman};
2511541Srgrimes
25255205Speter#ifdef _KERNEL
25321261Swollman
25438482Swollmanstruct sockopt;
25538482Swollman
25638482Swollmanextern int	(*ip_mrouter_set) __P((struct socket *, struct sockopt *));
25738482Swollmanextern int	(*ip_mrouter_get) __P((struct socket *, struct sockopt *));
2582754Swollmanextern int	(*ip_mrouter_done) __P((void));
25912579Sbde#ifdef MROUTING
26012579Sbdeextern int	(*mrt_ioctl) __P((int, caddr_t));
26112579Sbde#else
2627090Sbdeextern int	(*mrt_ioctl) __P((int, caddr_t, struct proc *));
26312579Sbde#endif
2641541Srgrimes
26555205Speter#endif /* _KERNEL */
2661541Srgrimes
2672531Swollman#endif /* _NETINET_IP_MROUTE_H_ */
268