Home | History | Annotate | Line # | Download | only in netinet
ip_mroute.h revision 1.9
      1  1.9  mycroft /*	$NetBSD: ip_mroute.h,v 1.9 1995/05/31 21:50:43 mycroft Exp $	*/
      2  1.6      cgd 
      3  1.1  hpeyerl /*
      4  1.9  mycroft  * Definitions for IP multicast forwarding.
      5  1.1  hpeyerl  *
      6  1.1  hpeyerl  * Written by David Waitzman, BBN Labs, August 1988.
      7  1.1  hpeyerl  * Modified by Steve Deering, Stanford, February 1989.
      8  1.9  mycroft  * Modified by Ajit Thyagarajan, PARC, August 1993.
      9  1.9  mycroft  * Modified by Ajit Thyagarajan, PARC, August 1994.
     10  1.1  hpeyerl  *
     11  1.9  mycroft  * MROUTING Revision: 1.2
     12  1.1  hpeyerl  */
     13  1.1  hpeyerl 
     14  1.9  mycroft #include <sys/queue.h>
     15  1.1  hpeyerl 
     16  1.1  hpeyerl /*
     17  1.9  mycroft  * Multicast Routing set/getsockopt commands.
     18  1.1  hpeyerl  */
     19  1.9  mycroft #define	MRT_INIT		100	/* initialize forwarder */
     20  1.9  mycroft #define	MRT_DONE		101	/* shut down forwarder */
     21  1.9  mycroft #define	MRT_ADD_VIF		102	/* create virtual interface */
     22  1.9  mycroft #define	MRT_DEL_VIF		103	/* delete virtual interface */
     23  1.9  mycroft #define	MRT_ADD_MFC		104	/* insert forwarding cache entry */
     24  1.9  mycroft #define	MRT_DEL_MFC		105	/* delete forwarding cache entry */
     25  1.9  mycroft #define	MRT_VERSION		106	/* get kernel version number */
     26  1.9  mycroft #define	MRT_ASSERT		107	/* enable PIM assert processing */
     27  1.1  hpeyerl 
     28  1.1  hpeyerl 
     29  1.1  hpeyerl /*
     30  1.1  hpeyerl  * Types and macros for handling bitmaps with one bit per virtual interface.
     31  1.1  hpeyerl  */
     32  1.1  hpeyerl #define	MAXVIFS 32
     33  1.8      cgd typedef u_int32_t vifbitmap_t;
     34  1.9  mycroft typedef u_int16_t vifi_t;		/* type of a vif index */
     35  1.1  hpeyerl 
     36  1.9  mycroft #define	VIFM_SET(n, m)			((m) |= (1 << (n)))
     37  1.9  mycroft #define	VIFM_CLR(n, m)			((m) &= ~(1 << (n)))
     38  1.9  mycroft #define	VIFM_ISSET(n, m)		((m) & (1 << (n)))
     39  1.9  mycroft #define	VIFM_SETALL(m)			((m) = 0xffffffff)
     40  1.9  mycroft #define	VIFM_CLRALL(m)			((m) = 0x00000000)
     41  1.9  mycroft #define	VIFM_COPY(mfrom, mto)		((mto) = (mfrom))
     42  1.9  mycroft #define	VIFM_SAME(m1, m2)		((m1) == (m2))
     43  1.1  hpeyerl 
     44  1.9  mycroft #define	VIFF_TUNNEL	0x1		/* vif represents a tunnel end-point */
     45  1.9  mycroft #define	VIFF_SRCRT	0x2		/* tunnel uses IP src routing */
     46  1.1  hpeyerl 
     47  1.1  hpeyerl /*
     48  1.9  mycroft  * Argument structure for MRT_ADD_VIF.
     49  1.9  mycroft  * (MRT_DEL_VIF takes a single vifi_t argument.)
     50  1.1  hpeyerl  */
     51  1.1  hpeyerl struct vifctl {
     52  1.9  mycroft 	vifi_t	  vifc_vifi;	    	/* the index of the vif to be added */
     53  1.9  mycroft 	u_int8_t  vifc_flags;     	/* VIFF_ flags defined below */
     54  1.9  mycroft 	u_int8_t  vifc_threshold; 	/* min ttl required to forward on vif */
     55  1.9  mycroft 	u_int32_t vifc_rate_limit;	/* max rate */
     56  1.9  mycroft 	struct	  in_addr vifc_lcl_addr;/* local interface address */
     57  1.9  mycroft 	struct	  in_addr vifc_rmt_addr;/* remote address (tunnels only) */
     58  1.1  hpeyerl };
     59  1.1  hpeyerl 
     60  1.1  hpeyerl /*
     61  1.9  mycroft  * Argument structure for MRT_ADD_MFC and MRT_DEL_MFC.
     62  1.9  mycroft  * (mfcc_tos to be added at a future point)
     63  1.1  hpeyerl  */
     64  1.9  mycroft struct mfcctl {
     65  1.9  mycroft 	struct	 in_addr mfcc_origin;	/* ip origin of mcasts */
     66  1.9  mycroft 	struct	 in_addr mfcc_mcastgrp;	/* multicast group associated */
     67  1.9  mycroft 	vifi_t	 mfcc_parent;		/* incoming vif */
     68  1.9  mycroft 	u_int8_t mfcc_ttls[MAXVIFS];	/* forwarding ttls on vifs */
     69  1.1  hpeyerl };
     70  1.9  mycroft 
     71  1.1  hpeyerl /*
     72  1.9  mycroft  * Argument structure used by mrouted to get src-grp pkt counts.
     73  1.1  hpeyerl  */
     74  1.9  mycroft struct sioc_sg_req {
     75  1.9  mycroft 	struct	in_addr src;
     76  1.9  mycroft 	struct	in_addr grp;
     77  1.9  mycroft 	u_long	pktcnt;
     78  1.9  mycroft 	u_long	bytecnt;
     79  1.9  mycroft 	u_long	wrong_if;
     80  1.1  hpeyerl };
     81  1.9  mycroft 
     82  1.1  hpeyerl /*
     83  1.9  mycroft  * Argument structure used by mrouted to get vif pkt counts.
     84  1.1  hpeyerl  */
     85  1.9  mycroft struct sioc_vif_req {
     86  1.9  mycroft 	vifi_t	vifi;			/* vif number */
     87  1.9  mycroft 	u_long	icount;			/* input packet count on vif */
     88  1.9  mycroft 	u_long	ocount;			/* output packet count on vif */
     89  1.9  mycroft 	u_long	ibytes;			/* input byte count on vif */
     90  1.9  mycroft 	u_long	obytes;			/* output byte count on vif */
     91  1.1  hpeyerl };
     92  1.1  hpeyerl 
     93  1.1  hpeyerl 
     94  1.1  hpeyerl /*
     95  1.1  hpeyerl  * The kernel's multicast routing statistics.
     96  1.1  hpeyerl  */
     97  1.1  hpeyerl struct mrtstat {
     98  1.9  mycroft 	u_long	mrts_mfc_lookups;	/* # forw. cache hash table hits */
     99  1.9  mycroft 	u_long	mrts_mfc_misses;	/* # forw. cache hash table misses */
    100  1.9  mycroft 	u_long	mrts_upcalls;		/* # calls to mrouted */
    101  1.1  hpeyerl 	u_long	mrts_no_route;		/* no route for packet's origin */
    102  1.1  hpeyerl 	u_long	mrts_bad_tunnel;	/* malformed tunnel options */
    103  1.1  hpeyerl 	u_long	mrts_cant_tunnel;	/* no room for tunnel options */
    104  1.5   brezak 	u_long	mrts_wrong_if;		/* arrived on wrong interface */
    105  1.9  mycroft 	u_long	mrts_upq_ovflw;		/* upcall Q overflow */
    106  1.9  mycroft 	u_long	mrts_cache_cleanups;	/* # entries with no upcalls */
    107  1.9  mycroft 	u_long	mrts_drop_sel;     	/* pkts dropped selectively */
    108  1.9  mycroft 	u_long	mrts_q_overflow;    	/* pkts dropped - Q overflow */
    109  1.9  mycroft 	u_long	mrts_pkt2large;     	/* pkts dropped - size > BKT SIZE */
    110  1.9  mycroft 	u_long	mrts_upq_sockfull;	/* upcalls dropped - socket full */
    111  1.9  mycroft };
    112  1.9  mycroft 
    113  1.9  mycroft 
    114  1.9  mycroft #ifdef _KERNEL
    115  1.9  mycroft 
    116  1.9  mycroft /*
    117  1.9  mycroft  * Token bucket filter at each vif
    118  1.9  mycroft  */
    119  1.9  mycroft struct tbf {
    120  1.9  mycroft 	u_int32_t last_pkt_t;		/* arr. time of last pkt */
    121  1.9  mycroft 	u_int32_t n_tok;		/* no of tokens in bucket */
    122  1.9  mycroft 	u_int32_t q_len;		/* length of queue at this vif */
    123  1.1  hpeyerl };
    124  1.1  hpeyerl 
    125  1.9  mycroft /*
    126  1.9  mycroft  * The kernel's virtual-interface structure.
    127  1.9  mycroft  */
    128  1.9  mycroft struct vif {
    129  1.9  mycroft 	u_int8_t  v_flags;		/* VIFF_ flags defined above */
    130  1.9  mycroft 	u_int8_t  v_threshold;		/* min ttl required to forward on vif */
    131  1.9  mycroft 	u_int32_t v_rate_limit;		/* max rate */
    132  1.9  mycroft 	struct	  tbf v_tbf;		/* token bucket structure at intf. */
    133  1.9  mycroft 	struct	  in_addr v_lcl_addr;	/* local interface address */
    134  1.9  mycroft 	struct	  in_addr v_rmt_addr;	/* remote address (tunnels only) */
    135  1.9  mycroft 	struct	  ifnet *v_ifp;		/* pointer to interface */
    136  1.9  mycroft 	u_long	  v_pkt_in;		/* # pkts in on interface */
    137  1.9  mycroft 	u_long	  v_pkt_out;		/* # pkts out on interface */
    138  1.9  mycroft 	u_long	  v_bytes_in;		/* # bytes in on interface */
    139  1.9  mycroft 	u_long	  v_bytes_out;		/* # bytes out on interface */
    140  1.9  mycroft 	struct	  route v_route;	/* cached route if this is a tunnel */
    141  1.9  mycroft #ifdef RSVP_ISI
    142  1.9  mycroft 	int	  v_rsvp_on;		/* # RSVP listening on this vif */
    143  1.9  mycroft 	struct	  socket *v_rsvpd;	/* # RSVPD daemon */
    144  1.9  mycroft #endif /* RSVP_ISI */
    145  1.9  mycroft };
    146  1.9  mycroft 
    147  1.9  mycroft /*
    148  1.9  mycroft  * The kernel's multicast forwarding cache entry structure.
    149  1.9  mycroft  * (A field for the type of service (mfc_tos) is to be added
    150  1.9  mycroft  * at a future point.)
    151  1.9  mycroft  */
    152  1.9  mycroft struct mfc {
    153  1.9  mycroft 	LIST_ENTRY(mfc) mfc_hash;
    154  1.9  mycroft 	struct	 in_addr mfc_origin;	 	/* ip origin of mcasts */
    155  1.9  mycroft 	struct	 in_addr mfc_mcastgrp;  	/* multicast group associated */
    156  1.9  mycroft 	vifi_t	 mfc_parent;			/* incoming vif */
    157  1.9  mycroft 	u_int8_t mfc_ttls[MAXVIFS]; 		/* forwarding ttls on vifs */
    158  1.9  mycroft 	u_long	 mfc_pkt_cnt;			/* pkt count for src-grp */
    159  1.9  mycroft 	u_long	 mfc_byte_cnt;			/* byte count for src-grp */
    160  1.9  mycroft 	u_long	 mfc_wrong_if;			/* wrong if for src-grp	*/
    161  1.9  mycroft 	int	 mfc_expire;			/* time to clean entry up */
    162  1.9  mycroft 	struct	 timeval mfc_last_assert;	/* last time I sent an assert */
    163  1.9  mycroft 	struct	 rtdetq *mfc_stall;		/* pkts waiting for route */
    164  1.9  mycroft };
    165  1.9  mycroft 
    166  1.9  mycroft /*
    167  1.9  mycroft  * Structure used to communicate from kernel to multicast router.
    168  1.9  mycroft  * (Note the convenient similarity to an IP packet.)
    169  1.9  mycroft  */
    170  1.9  mycroft struct igmpmsg {
    171  1.9  mycroft 	u_int32_t unused1;
    172  1.9  mycroft 	u_int32_t unused2;
    173  1.9  mycroft 	u_int8_t  im_msgtype;		/* what type of message */
    174  1.9  mycroft #define IGMPMSG_NOCACHE		1
    175  1.9  mycroft #define IGMPMSG_WRONGVIF	2
    176  1.9  mycroft 	u_int8_t  im_mbz;		/* must be zero */
    177  1.9  mycroft 	u_int8_t  im_vif;		/* vif rec'd on */
    178  1.9  mycroft 	u_int8_t  unused3;
    179  1.9  mycroft 	struct	  in_addr im_src, im_dst;
    180  1.9  mycroft };
    181  1.9  mycroft 
    182  1.9  mycroft /*
    183  1.9  mycroft  * Argument structure used for pkt info. while upcall is made.
    184  1.9  mycroft  */
    185  1.9  mycroft struct rtdetq {
    186  1.9  mycroft 	struct	mbuf *m;		/* a copy of the packet */
    187  1.9  mycroft 	struct	ifnet *ifp;		/* interface pkt came in on */
    188  1.9  mycroft #ifdef UPCALL_TIMING
    189  1.9  mycroft 	struct	timeval t;		/* timestamp */
    190  1.9  mycroft #endif /* UPCALL_TIMING */
    191  1.9  mycroft 	struct	rtdetq *next;
    192  1.9  mycroft };
    193  1.9  mycroft 
    194  1.9  mycroft #define	MFCTBLSIZ	256
    195  1.9  mycroft #define	MAX_UPQ		4		/* max. no of pkts in upcall Q */
    196  1.9  mycroft 
    197  1.9  mycroft /*
    198  1.9  mycroft  * Token bucket filter code
    199  1.9  mycroft  */
    200  1.9  mycroft #define	MAX_BKT_SIZE    10000		/* 10K bytes size */
    201  1.9  mycroft #define	MAXQSIZE        10		/* max. no of pkts in token queue */
    202  1.9  mycroft 
    203  1.9  mycroft /*
    204  1.9  mycroft  * Queue structure at each vif
    205  1.9  mycroft  */
    206  1.9  mycroft struct pkt_queue {
    207  1.9  mycroft 	u_int32_t pkt_len;		/* length of packet in queue */
    208  1.9  mycroft 	struct	  mbuf *pkt_m;		/* pointer to packet mbuf */
    209  1.9  mycroft 	struct	  ip *pkt_ip;		/* pointer to ip header */
    210  1.9  mycroft };
    211  1.9  mycroft 
    212  1.9  mycroft 
    213  1.5   brezak int	ip_mforward __P((struct mbuf *, struct ifnet *));
    214  1.9  mycroft int	ip_mrouter_get __P((int, struct socket *, struct mbuf **));
    215  1.9  mycroft int	ip_mrouter_set __P((int, struct socket *, struct mbuf **));
    216  1.3  mycroft int	ip_mrouter_done __P((void));
    217  1.9  mycroft 
    218  1.7      jtc #endif /* _KERNEL */
    219