ip_mroute.h revision 2531
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
382531Swollman * $Id: ip_mroute.h,v 1.3 1994/08/21 05:27:32 paul Exp $
391541Srgrimes */
401541Srgrimes
412169Spaul#ifndef _NETINET_IP_MROUTE_H_
422169Spaul#define _NETINET_IP_MROUTE_H_
432169Spaul
441541Srgrimes/*
451541Srgrimes * Definitions for the kernel part of DVMRP,
461541Srgrimes * a Distance-Vector Multicast Routing Protocol.
471541Srgrimes * (See RFC-1075.)
481541Srgrimes *
491541Srgrimes * Written by David Waitzman, BBN Labs, August 1988.
501541Srgrimes * Modified by Steve Deering, Stanford, February 1989.
512531Swollman * Modified by Ajit Thyagarajan, PARC, August 1993.
522531Swollman * Modified by Ajit Thyagarajan, PARC, August 1994.
531541Srgrimes *
542531Swollman * MROUTING 1.5
551541Srgrimes */
561541Srgrimes
571541Srgrimes
581541Srgrimes/*
591541Srgrimes * DVMRP-specific setsockopt commands.
601541Srgrimes */
612531Swollman#define	DVMRP_INIT	100	/* initialize forwarder */
622531Swollman#define	DVMRP_DONE	101	/* shut down forwarder */
632531Swollman#define	DVMRP_ADD_VIF	102	/* create virtual interface */
642531Swollman#define	DVMRP_DEL_VIF	103	/* delete virtual interface */
652531Swollman#define DVMRP_ADD_MFC	104	/* insert forwarding cache entry */
662531Swollman#define DVMRP_DEL_MFC	105	/* delete forwarding cache entry */
671541Srgrimes
682531Swollman#define GET_TIME(t)	microtime(&t)
691541Srgrimes
701541Srgrimes/*
711541Srgrimes * Types and macros for handling bitmaps with one bit per virtual interface.
721541Srgrimes */
731541Srgrimes#define	MAXVIFS 32
741541Srgrimestypedef u_long vifbitmap_t;
751541Srgrimestypedef u_short vifi_t;		/* type of a vif index */
761541Srgrimes
771541Srgrimes#define	VIFM_SET(n, m)		((m) |= (1 << (n)))
781541Srgrimes#define	VIFM_CLR(n, m)		((m) &= ~(1 << (n)))
791541Srgrimes#define	VIFM_ISSET(n, m)	((m) & (1 << (n)))
801541Srgrimes#define	VIFM_CLRALL(m)		((m) = 0x00000000)
811541Srgrimes#define	VIFM_COPY(mfrom, mto)	((mto) = (mfrom))
821541Srgrimes#define	VIFM_SAME(m1, m2)	((m1) == (m2))
831541Srgrimes
841541Srgrimes
851541Srgrimes/*
862531Swollman * Argument structure for DVMRP_ADD_VIF.
871541Srgrimes * (DVMRP_DEL_VIF takes a single vifi_t argument.)
881541Srgrimes */
891541Srgrimesstruct vifctl {
901541Srgrimes	vifi_t	    vifc_vifi;	    	/* the index of the vif to be added */
911541Srgrimes	u_char	    vifc_flags;     	/* VIFF_ flags defined below */
921541Srgrimes	u_char	    vifc_threshold; 	/* min ttl required to forward on vif */
932531Swollman	u_int	vifc_rate_limit; /* max tate */
941541Srgrimes	struct	in_addr vifc_lcl_addr;	/* local interface address */
951541Srgrimes	struct	in_addr vifc_rmt_addr;	/* remote address (tunnels only) */
961541Srgrimes};
971541Srgrimes
981541Srgrimes#define	VIFF_TUNNEL	0x1		/* vif represents a tunnel end-point */
992531Swollman#define VIFF_SRCRT	0x2	/* tunnel uses IP source routing */
1001541Srgrimes
1012531Swollman/*
1022531Swollman * Argument structure for DVMRP_ADD_MFC
1032531Swollman * (mfcc_tos to be added at a future point)
1042531Swollman */
1052531Swollmanstruct mfcctl {
1062531Swollman    struct in_addr  mfcc_origin;		/* subnet origin of mcasts   */
1072531Swollman    struct in_addr  mfcc_mcastgrp; 		/* multicast group associated*/
1082531Swollman    struct in_addr  mfcc_originmask;		/* subnet mask for origin    */
1092531Swollman    vifi_t	    mfcc_parent;   		/* incoming vif              */
1102531Swollman    u_char	    mfcc_ttls[MAXVIFS]; 	/* forwarding ttls on vifs   */
1112531Swollman};
1121541Srgrimes
1131541Srgrimes/*
1142531Swollman * Argument structure for DVMRP_DEL_MFC
1151541Srgrimes */
1162531Swollmanstruct delmfcctl {
1172531Swollman    struct in_addr  mfcc_origin;    /* subnet origin of multicasts      */
1182531Swollman    struct in_addr  mfcc_mcastgrp;  /* multicast group assoc. w/ origin */
1191541Srgrimes};
1201541Srgrimes
1212531Swollman/*
1222531Swollman * Argument structure used by RSVP daemon to get vif information
1232531Swollman */
1242531Swollmanstruct vif_req {
1252531Swollman    u_char         v_flags;         /* VIFF_ flags defined above           */
1262531Swollman    u_char         v_threshold;     /* min ttl required to forward on vif  */
1272531Swollman    struct in_addr v_lcl_addr;      /* local interface address             */
1282531Swollman    struct in_addr v_rmt_addr;
1292531Swollman    char           v_if_name[IFNAMSIZ];  /* if name */
1302531Swollman};
1311541Srgrimes
1322531Swollmanstruct vif_conf {
1332531Swollman    u_int          vifc_len;
1342531Swollman    u_int          vifc_num;
1352531Swollman    struct vif_req *vifc_req;
1362531Swollman};
1372531Swollman
1381541Srgrimes/*
1392531Swollman * The kernel's multicast routing statistics.
1401541Srgrimes */
1412531Swollmanstruct mrtstat {
1422531Swollman    u_long	mrts_mfc_lookups;	/* # forw. cache hash table hits   */
1432531Swollman    u_long	mrts_mfc_misses;	/* # forw. cache hash table misses */
1442531Swollman    u_long	mrts_upcalls;		/* # calls to mrouted              */
1452531Swollman    u_long	mrts_no_route;		/* no route for packet's origin    */
1462531Swollman    u_long	mrts_bad_tunnel;	/* malformed tunnel options        */
1472531Swollman    u_long	mrts_cant_tunnel;	/* no room for tunnel options      */
1482531Swollman    u_long	mrts_wrong_if;		/* arrived on wrong interface	   */
1492531Swollman    u_long	mrts_upq_ovflw;		/* upcall Q overflow		   */
1502531Swollman    u_long	mrts_cache_cleanups;	/* # entries with no upcalls 	   */
1512531Swollman    u_long  	mrts_drop_sel;     	/* pkts dropped selectively        */
1522531Swollman    u_long  	mrts_q_overflow;    	/* pkts dropped - Q overflow       */
1532531Swollman    u_long  	mrts_pkt2large;     	/* pkts dropped - size > BKT SIZE  */
1541541Srgrimes};
1551541Srgrimes
1562531Swollman/*
1572531Swollman * Argument structure used by mrouted to get src-grp pkt counts
1582531Swollman */
1592531Swollmanstruct sioc_sg_req {
1602531Swollman    struct in_addr src;
1612531Swollman    struct in_addr grp;
1622531Swollman    u_long count;
1632531Swollman};
1641541Srgrimes
1652531Swollman/*
1662531Swollman * Argument structure used by mrouted to get vif pkt counts
1672531Swollman */
1682531Swollmanstruct sioc_vif_req {
1692531Swollman    vifi_t vifi;
1702531Swollman    u_long icount;
1712531Swollman    u_long ocount;
1722531Swollman};
1732531Swollman
1742531Swollman
1751541Srgrimes#ifdef KERNEL
1761541Srgrimes
1772531Swollmanstruct vif {
1782531Swollman    u_char   		v_flags;     	/* VIFF_ flags defined above         */
1792531Swollman    u_char   		v_threshold;	/* min ttl required to forward on vif*/
1802531Swollman    u_int      		v_rate_limit; 	/* max rate			     */
1812531Swollman    struct tbf 	       *v_tbf;       	/* token bucket structure at intf.   */
1822531Swollman    struct in_addr 	v_lcl_addr;   	/* local interface address           */
1832531Swollman    struct in_addr 	v_rmt_addr;   	/* remote address (tunnels only)     */
1842531Swollman    struct ifnet       *v_ifp;	     	/* pointer to interface              */
1852531Swollman    u_long		v_pkt_in;	/* # pkts in on interface            */
1862531Swollman    u_long		v_pkt_out;	/* # pkts out on interface           */
1872531Swollman};
1882531Swollman
1891541Srgrimes/*
1902531Swollman * The kernel's multicast forwarding cache entry structure
1912531Swollman * (A field for the type of service (mfc_tos) is to be added
1922531Swollman * at a future point)
1931541Srgrimes */
1942531Swollmanstruct mfc {
1952531Swollman    struct in_addr  mfc_origin;	 		/* subnet origin of mcasts   */
1962531Swollman    struct in_addr  mfc_mcastgrp;  		/* multicast group associated*/
1972531Swollman    struct in_addr  mfc_originmask;		/* subnet mask for origin    */
1982531Swollman    vifi_t	    mfc_parent; 		/* incoming vif              */
1992531Swollman    u_char	    mfc_ttls[MAXVIFS]; 		/* forwarding ttls on vifs   */
2002531Swollman    u_long	    mfc_pkt_cnt;		/* pkt count for src-grp     */
2011541Srgrimes};
2021541Srgrimes
2031541Srgrimes/*
2042531Swollman * Argument structure used for pkt info. while upcall is made
2051541Srgrimes */
2062531Swollmanstruct rtdetq {
2072531Swollman    struct mbuf 	*m;
2082531Swollman    struct ifnet	*ifp;
2092531Swollman    u_long		tunnel_src;
2102531Swollman    struct ip_moptions *imo;
2111541Srgrimes};
2121541Srgrimes
2132531Swollman#define MFCTBLSIZ	256
2142531Swollman#if (MFCTBLSIZ & (MFCTBLSIZ - 1)) == 0	  /* from sys:route.h */
2152531Swollman#define MFCHASHMOD(h)	((h) & (MFCTBLSIZ - 1))
2161541Srgrimes#else
2172531Swollman#define MFCHASHMOD(h)	((h) % MFCTBLSIZ)
2181541Srgrimes#endif
2191541Srgrimes
2202531Swollman#define MAX_UPQ	4		/* max. no of pkts in upcall Q */
2212531Swollman
2221541Srgrimes/*
2232531Swollman * Token Bucket filter code
2241541Srgrimes */
2252531Swollman#define MAX_BKT_SIZE    10000             /* 10K bytes size 		*/
2262531Swollman#define MAXQSIZE        10                /* max # of pkts in queue 	*/
2272531Swollman
2282531Swollman/*
2292531Swollman * queue structure at each vif
2302531Swollman */
2312531Swollmanstruct pkt_queue
2322531Swollman{
2332531Swollman    u_long pkt_len;               /* length of packet in queue 	*/
2342531Swollman    struct mbuf *pkt_m;           /* pointer to packet mbuf	*/
2352531Swollman    struct ip  *pkt_ip;           /* pointer to ip header	*/
2362531Swollman    struct ip_moptions *pkt_imo; /* IP multicast options assoc. with pkt */
2371541Srgrimes};
2381541Srgrimes
2392531Swollman/*
2402531Swollman * the token bucket filter at each vif
2412531Swollman */
2422531Swollmanstruct tbf
2432531Swollman{
2442531Swollman    u_long last_pkt_t;	/* arr. time of last pkt 	*/
2452531Swollman    u_long n_tok;      	/* no of tokens in bucket 	*/
2462531Swollman    u_long q_len;    	/* length of queue at this vif	*/
2472531Swollman};
2481541Srgrimes
2491541Srgrimesint	ip_mrouter_cmd __P((int, struct socket *, struct mbuf *));
2501541Srgrimesint	ip_mrouter_done __P((void));
2511541Srgrimes
2521541Srgrimes#endif /* KERNEL */
2531541Srgrimes
2542531Swollman#endif /* _NETINET_IP_MROUTE_H_ */
255