Home | History | Annotate | Line # | Download | only in netinet
      1  1.36       kim /*	$NetBSD: ip_mroute.h,v 1.36 2025/07/28 21:25:00 kim Exp $	*/
      2  1.24      manu 
      3  1.24      manu #ifndef _NETINET_IP_MROUTE_H_
      4  1.24      manu #define _NETINET_IP_MROUTE_H_
      5   1.6       cgd 
      6   1.1   hpeyerl /*
      7   1.9   mycroft  * Definitions for IP multicast forwarding.
      8   1.1   hpeyerl  *
      9   1.1   hpeyerl  * Written by David Waitzman, BBN Labs, August 1988.
     10   1.1   hpeyerl  * Modified by Steve Deering, Stanford, February 1989.
     11   1.9   mycroft  * Modified by Ajit Thyagarajan, PARC, August 1993.
     12   1.9   mycroft  * Modified by Ajit Thyagarajan, PARC, August 1994.
     13  1.24      manu  * Modified by Ahmed Helmy, SGI, June 1996.
     14  1.24      manu  * Modified by Pavlin Radoslavov, ICSI, October 2002.
     15   1.1   hpeyerl  *
     16   1.9   mycroft  * MROUTING Revision: 1.2
     17  1.24      manu  * and PIM-SMv2 and PIM-DM support, advanced API support,
     18  1.24      manu  * bandwidth metering and signaling.
     19   1.1   hpeyerl  */
     20   1.1   hpeyerl 
     21   1.9   mycroft #include <sys/queue.h>
     22  1.18   thorpej #include <sys/callout.h>
     23   1.1   hpeyerl 
     24   1.1   hpeyerl /*
     25   1.9   mycroft  * Multicast Routing set/getsockopt commands.
     26   1.1   hpeyerl  */
     27   1.9   mycroft #define	MRT_INIT		100	/* initialize forwarder */
     28   1.9   mycroft #define	MRT_DONE		101	/* shut down forwarder */
     29   1.9   mycroft #define	MRT_ADD_VIF		102	/* create virtual interface */
     30   1.9   mycroft #define	MRT_DEL_VIF		103	/* delete virtual interface */
     31   1.9   mycroft #define	MRT_ADD_MFC		104	/* insert forwarding cache entry */
     32   1.9   mycroft #define	MRT_DEL_MFC		105	/* delete forwarding cache entry */
     33   1.9   mycroft #define	MRT_VERSION		106	/* get kernel version number */
     34  1.24      manu #define	MRT_ASSERT		107	/* enable assert processing */
     35  1.24      manu #define MRT_PIM			MRT_ASSERT /* enable PIM processing */
     36  1.24      manu #define MRT_API_SUPPORT		109	/* supported MRT API */
     37  1.24      manu #define MRT_API_CONFIG		110	/* config MRT API */
     38  1.24      manu #define MRT_ADD_BW_UPCALL	111	/* create bandwidth monitor */
     39  1.24      manu #define MRT_DEL_BW_UPCALL	112	/* delete bandwidth monitor */
     40   1.1   hpeyerl 
     41   1.1   hpeyerl /*
     42   1.1   hpeyerl  * Types and macros for handling bitmaps with one bit per virtual interface.
     43   1.1   hpeyerl  */
     44   1.1   hpeyerl #define	MAXVIFS 32
     45   1.8       cgd typedef u_int32_t vifbitmap_t;
     46   1.9   mycroft typedef u_int16_t vifi_t;		/* type of a vif index */
     47   1.1   hpeyerl 
     48   1.9   mycroft #define	VIFM_SET(n, m)			((m) |= (1 << (n)))
     49   1.9   mycroft #define	VIFM_CLR(n, m)			((m) &= ~(1 << (n)))
     50   1.9   mycroft #define	VIFM_ISSET(n, m)		((m) & (1 << (n)))
     51   1.9   mycroft #define	VIFM_SETALL(m)			((m) = 0xffffffff)
     52   1.9   mycroft #define	VIFM_CLRALL(m)			((m) = 0x00000000)
     53   1.9   mycroft #define	VIFM_COPY(mfrom, mto)		((mto) = (mfrom))
     54   1.9   mycroft #define	VIFM_SAME(m1, m2)		((m1) == (m2))
     55   1.1   hpeyerl 
     56   1.9   mycroft #define	VIFF_TUNNEL	0x1		/* vif represents a tunnel end-point */
     57   1.9   mycroft #define	VIFF_SRCRT	0x2		/* tunnel uses IP src routing */
     58  1.24      manu #define VIFF_REGISTER	0x4		/* used for PIM Register encap/decap */
     59   1.1   hpeyerl 
     60   1.1   hpeyerl /*
     61   1.9   mycroft  * Argument structure for MRT_ADD_VIF.
     62   1.9   mycroft  * (MRT_DEL_VIF takes a single vifi_t argument.)
     63   1.1   hpeyerl  */
     64   1.1   hpeyerl struct vifctl {
     65   1.9   mycroft 	vifi_t	  vifc_vifi;	    	/* the index of the vif to be added */
     66   1.9   mycroft 	u_int8_t  vifc_flags;     	/* VIFF_ flags defined below */
     67   1.9   mycroft 	u_int8_t  vifc_threshold; 	/* min ttl required to forward on vif */
     68   1.9   mycroft 	u_int32_t vifc_rate_limit;	/* max rate */
     69   1.9   mycroft 	struct	  in_addr vifc_lcl_addr;/* local interface address */
     70   1.9   mycroft 	struct	  in_addr vifc_rmt_addr;/* remote address (tunnels only) */
     71   1.1   hpeyerl };
     72   1.1   hpeyerl 
     73   1.1   hpeyerl /*
     74   1.9   mycroft  * Argument structure for MRT_ADD_MFC and MRT_DEL_MFC.
     75  1.24      manu  * XXX if you change this, make sure to change struct mfcctl2 as well.
     76   1.1   hpeyerl  */
     77   1.9   mycroft struct mfcctl {
     78   1.9   mycroft 	struct	 in_addr mfcc_origin;	/* ip origin of mcasts */
     79   1.9   mycroft 	struct	 in_addr mfcc_mcastgrp;	/* multicast group associated */
     80   1.9   mycroft 	vifi_t	 mfcc_parent;		/* incoming vif */
     81   1.9   mycroft 	u_int8_t mfcc_ttls[MAXVIFS];	/* forwarding ttls on vifs */
     82   1.1   hpeyerl };
     83  1.20    itojun 
     84   1.1   hpeyerl /*
     85  1.24      manu  * The new argument structure for MRT_ADD_MFC and MRT_DEL_MFC overlays
     86  1.24      manu  * and extends the old struct mfcctl.
     87  1.24      manu  */
     88  1.24      manu struct mfcctl2 {
     89  1.24      manu 	/* the mfcctl fields */
     90  1.24      manu 	struct in_addr	mfcc_origin;		/* ip origin of mcasts	     */
     91  1.24      manu 	struct in_addr	mfcc_mcastgrp;		/* multicast group associated*/
     92  1.24      manu 	vifi_t		mfcc_parent;		/* incoming vif		     */
     93  1.24      manu 	u_int8_t	mfcc_ttls[MAXVIFS]; 	/* forwarding ttls on vifs   */
     94  1.24      manu 
     95  1.24      manu 	/* extension fields */
     96  1.24      manu 	u_int8_t	mfcc_flags[MAXVIFS];	/* the MRT_MFC_FLAGS_* flags */
     97  1.24      manu 	struct in_addr	mfcc_rp;		/* the RP address            */
     98  1.24      manu };
     99  1.36       kim 
    100  1.24      manu /*
    101  1.24      manu  * The advanced-API flags.
    102  1.24      manu  *
    103  1.24      manu  * The MRT_MFC_FLAGS_XXX API flags are also used as flags
    104  1.24      manu  * for the mfcc_flags field.
    105  1.24      manu  */
    106  1.24      manu #define	MRT_MFC_FLAGS_DISABLE_WRONGVIF	(1 << 0) /* disable WRONGVIF signals */
    107  1.24      manu #define	MRT_MFC_FLAGS_BORDER_VIF	(1 << 1) /* border vif		     */
    108  1.24      manu #define MRT_MFC_RP			(1 << 8) /* enable RP address	     */
    109  1.24      manu #define MRT_MFC_BW_UPCALL		(1 << 9) /* enable bw upcalls	     */
    110  1.24      manu #define MRT_MFC_FLAGS_ALL		(MRT_MFC_FLAGS_DISABLE_WRONGVIF |    \
    111  1.24      manu 					 MRT_MFC_FLAGS_BORDER_VIF)
    112  1.24      manu #define MRT_API_FLAGS_ALL		(MRT_MFC_FLAGS_ALL |		     \
    113  1.24      manu 					 MRT_MFC_RP |			     \
    114  1.24      manu 					 MRT_MFC_BW_UPCALL)
    115  1.24      manu 
    116  1.24      manu /*
    117  1.24      manu  * Structure for installing or delivering an upcall if the
    118  1.24      manu  * measured bandwidth is above or below a threshold.
    119  1.24      manu  *
    120  1.24      manu  * User programs (e.g. daemons) may have a need to know when the
    121  1.24      manu  * bandwidth used by some data flow is above or below some threshold.
    122  1.24      manu  * This interface allows the userland to specify the threshold (in
    123  1.24      manu  * bytes and/or packets) and the measurement interval. Flows are
    124  1.24      manu  * all packet with the same source and destination IP address.
    125  1.24      manu  * At the moment the code is only used for multicast destinations
    126  1.24      manu  * but there is nothing that prevents its use for unicast.
    127  1.24      manu  *
    128  1.24      manu  * The measurement interval cannot be shorter than some Tmin (currently, 3s).
    129  1.24      manu  * The threshold is set in packets and/or bytes per_interval.
    130  1.24      manu  *
    131  1.24      manu  * Measurement works as follows:
    132  1.24      manu  *
    133  1.25     perry  * For >= measurements:
    134  1.24      manu  * The first packet marks the start of a measurement interval.
    135  1.24      manu  * During an interval we count packets and bytes, and when we
    136  1.24      manu  * pass the threshold we deliver an upcall and we are done.
    137  1.24      manu  * The first packet after the end of the interval resets the
    138  1.24      manu  * count and restarts the measurement.
    139  1.24      manu  *
    140  1.24      manu  * For <= measurement:
    141  1.24      manu  * We start a timer to fire at the end of the interval, and
    142  1.24      manu  * then for each incoming packet we count packets and bytes.
    143  1.24      manu  * When the timer fires, we compare the value with the threshold,
    144  1.24      manu  * schedule an upcall if we are below, and restart the measurement
    145  1.24      manu  * (reschedule timer and zero counters).
    146  1.24      manu  */
    147  1.24      manu 
    148  1.24      manu struct bw_data {
    149  1.24      manu 	struct timeval	b_time;
    150  1.24      manu 	u_int64_t	b_packets;
    151  1.24      manu 	u_int64_t	b_bytes;
    152  1.24      manu };
    153  1.24      manu 
    154  1.24      manu struct bw_upcall {
    155  1.24      manu 	struct in_addr	bu_src;			/* source address            */
    156  1.24      manu 	struct in_addr	bu_dst;			/* destination address       */
    157  1.24      manu 	u_int32_t	bu_flags;		/* misc flags (see below)    */
    158  1.24      manu #define BW_UPCALL_UNIT_PACKETS   (1 << 0)	/* threshold (in packets)    */
    159  1.24      manu #define BW_UPCALL_UNIT_BYTES     (1 << 1)	/* threshold (in bytes)      */
    160  1.24      manu #define BW_UPCALL_GEQ            (1 << 2)	/* upcall if bw >= threshold */
    161  1.24      manu #define BW_UPCALL_LEQ            (1 << 3)	/* upcall if bw <= threshold */
    162  1.24      manu #define BW_UPCALL_DELETE_ALL     (1 << 4)	/* delete all upcalls for s,d*/
    163  1.24      manu 	struct bw_data	bu_threshold;		/* the bw threshold	     */
    164  1.24      manu 	struct bw_data	bu_measured;		/* the measured bw	     */
    165  1.24      manu };
    166  1.24      manu 
    167  1.24      manu /* max. number of upcalls to deliver together */
    168  1.24      manu #define BW_UPCALLS_MAX				128
    169  1.24      manu /* min. threshold time interval for bandwidth measurement */
    170  1.24      manu #define BW_UPCALL_THRESHOLD_INTERVAL_MIN_SEC	3
    171  1.24      manu #define BW_UPCALL_THRESHOLD_INTERVAL_MIN_USEC	0
    172  1.24      manu 
    173  1.24      manu /*
    174   1.9   mycroft  * Argument structure used by mrouted to get src-grp pkt counts.
    175   1.1   hpeyerl  */
    176   1.9   mycroft struct sioc_sg_req {
    177   1.9   mycroft 	struct	in_addr src;
    178   1.9   mycroft 	struct	in_addr grp;
    179   1.9   mycroft 	u_long	pktcnt;
    180   1.9   mycroft 	u_long	bytecnt;
    181   1.9   mycroft 	u_long	wrong_if;
    182   1.1   hpeyerl };
    183  1.20    itojun 
    184   1.1   hpeyerl /*
    185   1.9   mycroft  * Argument structure used by mrouted to get vif pkt counts.
    186   1.1   hpeyerl  */
    187   1.9   mycroft struct sioc_vif_req {
    188   1.9   mycroft 	vifi_t	vifi;			/* vif number */
    189   1.9   mycroft 	u_long	icount;			/* input packet count on vif */
    190   1.9   mycroft 	u_long	ocount;			/* output packet count on vif */
    191   1.9   mycroft 	u_long	ibytes;			/* input byte count on vif */
    192   1.9   mycroft 	u_long	obytes;			/* output byte count on vif */
    193   1.1   hpeyerl };
    194   1.1   hpeyerl 
    195   1.1   hpeyerl /*
    196   1.1   hpeyerl  * The kernel's multicast routing statistics.
    197   1.1   hpeyerl  */
    198   1.1   hpeyerl struct mrtstat {
    199   1.9   mycroft 	u_long	mrts_mfc_lookups;	/* # forw. cache hash table hits */
    200   1.9   mycroft 	u_long	mrts_mfc_misses;	/* # forw. cache hash table misses */
    201   1.9   mycroft 	u_long	mrts_upcalls;		/* # calls to mrouted */
    202   1.1   hpeyerl 	u_long	mrts_no_route;		/* no route for packet's origin */
    203   1.1   hpeyerl 	u_long	mrts_bad_tunnel;	/* malformed tunnel options */
    204   1.1   hpeyerl 	u_long	mrts_cant_tunnel;	/* no room for tunnel options */
    205   1.5    brezak 	u_long	mrts_wrong_if;		/* arrived on wrong interface */
    206   1.9   mycroft 	u_long	mrts_upq_ovflw;		/* upcall Q overflow */
    207   1.9   mycroft 	u_long	mrts_cache_cleanups;	/* # entries with no upcalls */
    208   1.9   mycroft 	u_long	mrts_drop_sel;     	/* pkts dropped selectively */
    209   1.9   mycroft 	u_long	mrts_q_overflow;    	/* pkts dropped - Q overflow */
    210   1.9   mycroft 	u_long	mrts_pkt2large;     	/* pkts dropped - size > BKT SIZE */
    211   1.9   mycroft 	u_long	mrts_upq_sockfull;	/* upcalls dropped - socket full */
    212   1.9   mycroft };
    213  1.20    itojun 
    214  1.36       kim /*
    215  1.36       kim  * Structure used to communicate from kernel to multicast router.
    216  1.36       kim  * (Note the convenient similarity to an IP packet.)
    217  1.36       kim  */
    218  1.36       kim struct igmpmsg {
    219  1.36       kim 	u_int32_t unused1;
    220  1.36       kim 	u_int32_t unused2;
    221  1.36       kim 	u_int8_t  im_msgtype;		/* what type of message */
    222  1.36       kim #define IGMPMSG_NOCACHE		1	/* no MFC in the kernel		    */
    223  1.36       kim #define IGMPMSG_WRONGVIF	2	/* packet came from wrong interface */
    224  1.36       kim #define	IGMPMSG_WHOLEPKT	3	/* PIM pkt for user level encap.    */
    225  1.36       kim #define	IGMPMSG_BW_UPCALL	4	/* BW monitoring upcall		    */
    226  1.36       kim 	u_int8_t  im_mbz;		/* must be zero */
    227  1.36       kim 	u_int8_t  im_vif;		/* vif rec'd on */
    228  1.36       kim 	u_int8_t  unused3;
    229  1.36       kim 	struct	  in_addr im_src, im_dst;
    230  1.36       kim };
    231  1.36       kim #ifdef __CTASSERT
    232  1.36       kim __CTASSERT(sizeof(struct igmpmsg) == 20);
    233  1.36       kim #endif
    234   1.9   mycroft 
    235   1.9   mycroft #ifdef _KERNEL
    236   1.9   mycroft 
    237   1.9   mycroft /*
    238   1.9   mycroft  * The kernel's virtual-interface structure.
    239   1.9   mycroft  */
    240  1.19    itojun struct encaptab;
    241   1.9   mycroft struct vif {
    242  1.12   mycroft 	struct	  mbuf *tbf_q, **tbf_t;	/* packet queue */
    243  1.12   mycroft 	struct	  timeval tbf_last_pkt_t; /* arr. time of last pkt */
    244  1.12   mycroft 	u_int32_t tbf_n_tok;		/* no of tokens in bucket */
    245  1.12   mycroft 	u_int32_t tbf_q_len;		/* length of queue at this vif */
    246  1.12   mycroft 	u_int32_t tbf_max_q_len;	/* max. queue length */
    247  1.12   mycroft 
    248   1.9   mycroft 	u_int8_t  v_flags;		/* VIFF_ flags defined above */
    249   1.9   mycroft 	u_int8_t  v_threshold;		/* min ttl required to forward on vif */
    250   1.9   mycroft 	u_int32_t v_rate_limit;		/* max rate */
    251   1.9   mycroft 	struct	  in_addr v_lcl_addr;	/* local interface address */
    252   1.9   mycroft 	struct	  in_addr v_rmt_addr;	/* remote address (tunnels only) */
    253   1.9   mycroft 	struct	  ifnet *v_ifp;		/* pointer to interface */
    254   1.9   mycroft 	u_long	  v_pkt_in;		/* # pkts in on interface */
    255   1.9   mycroft 	u_long	  v_pkt_out;		/* # pkts out on interface */
    256   1.9   mycroft 	u_long	  v_bytes_in;		/* # bytes in on interface */
    257   1.9   mycroft 	u_long	  v_bytes_out;		/* # bytes out on interface */
    258   1.9   mycroft 	struct	  route v_route;	/* cached route if this is a tunnel */
    259  1.28        ad 	callout_t v_repq_ch;		/* for tbf_reprocess_q() */
    260  1.19    itojun 	const struct encaptab *v_encap_cookie;
    261   1.9   mycroft };
    262   1.9   mycroft 
    263   1.9   mycroft /*
    264   1.9   mycroft  * The kernel's multicast forwarding cache entry structure.
    265  1.20    itojun  * (A field for the type of service (mfc_tos) is to be added
    266   1.9   mycroft  * at a future point.)
    267   1.9   mycroft  */
    268   1.9   mycroft struct mfc {
    269   1.9   mycroft 	LIST_ENTRY(mfc) mfc_hash;
    270   1.9   mycroft 	struct	 in_addr mfc_origin;	 	/* ip origin of mcasts */
    271   1.9   mycroft 	struct	 in_addr mfc_mcastgrp;  	/* multicast group associated */
    272   1.9   mycroft 	vifi_t	 mfc_parent;			/* incoming vif */
    273   1.9   mycroft 	u_int8_t mfc_ttls[MAXVIFS]; 		/* forwarding ttls on vifs */
    274   1.9   mycroft 	u_long	 mfc_pkt_cnt;			/* pkt count for src-grp */
    275   1.9   mycroft 	u_long	 mfc_byte_cnt;			/* byte count for src-grp */
    276   1.9   mycroft 	u_long	 mfc_wrong_if;			/* wrong if for src-grp	*/
    277   1.9   mycroft 	int	 mfc_expire;			/* time to clean entry up */
    278   1.9   mycroft 	struct	 timeval mfc_last_assert;	/* last time I sent an assert */
    279   1.9   mycroft 	struct	 rtdetq *mfc_stall;		/* pkts waiting for route */
    280  1.24      manu 	u_int8_t mfc_flags[MAXVIFS];		/* the MRT_MFC_FLAGS_* flags */
    281  1.24      manu 	struct	 in_addr mfc_rp;		/* the RP address	     */
    282  1.24      manu 	struct	 bw_meter *mfc_bw_meter;	/* list of bandwidth meters  */
    283   1.9   mycroft };
    284   1.9   mycroft 
    285   1.9   mycroft /*
    286   1.9   mycroft  * Argument structure used for pkt info. while upcall is made.
    287   1.9   mycroft  */
    288   1.9   mycroft struct rtdetq {
    289   1.9   mycroft 	struct	mbuf *m;		/* a copy of the packet */
    290   1.9   mycroft 	struct	ifnet *ifp;		/* interface pkt came in on */
    291   1.9   mycroft #ifdef UPCALL_TIMING
    292   1.9   mycroft 	struct	timeval t;		/* timestamp */
    293   1.9   mycroft #endif /* UPCALL_TIMING */
    294   1.9   mycroft 	struct	rtdetq *next;
    295   1.9   mycroft };
    296   1.9   mycroft 
    297   1.9   mycroft #define	MFCTBLSIZ	256
    298   1.9   mycroft #define	MAX_UPQ		4		/* max. no of pkts in upcall Q */
    299  1.20    itojun 
    300   1.9   mycroft /*
    301  1.20    itojun  * Token bucket filter code
    302   1.9   mycroft  */
    303   1.9   mycroft #define	MAX_BKT_SIZE    10000		/* 10K bytes size */
    304   1.9   mycroft #define	MAXQSIZE        10		/* max. no of pkts in token queue */
    305  1.20    itojun 
    306  1.24      manu /*
    307  1.24      manu  * Structure for measuring the bandwidth and sending an upcall if the
    308  1.24      manu  * measured bandwidth is above or below a threshold.
    309  1.24      manu  */
    310  1.24      manu struct bw_meter {
    311  1.24      manu 	struct bw_meter	*bm_mfc_next;		/* next bw meter (same mfc)  */
    312  1.24      manu 	struct bw_meter	*bm_time_next;		/* next bw meter (same time) */
    313  1.24      manu 	uint32_t	bm_time_hash;		/* the time hash value       */
    314  1.24      manu 	struct mfc	*bm_mfc;		/* the corresponding mfc     */
    315  1.24      manu 	uint32_t	bm_flags;		/* misc flags (see below)    */
    316  1.24      manu #define BW_METER_UNIT_PACKETS	(1 << 0)	/* threshold (in packets)    */
    317  1.24      manu #define BW_METER_UNIT_BYTES	(1 << 1)	/* threshold (in bytes)      */
    318  1.24      manu #define BW_METER_GEQ		(1 << 2)	/* upcall if bw >= threshold */
    319  1.24      manu #define BW_METER_LEQ		(1 << 3)	/* upcall if bw <= threshold */
    320  1.24      manu #define BW_METER_USER_FLAGS 	(BW_METER_UNIT_PACKETS |		\
    321  1.24      manu 				 BW_METER_UNIT_BYTES |			\
    322  1.24      manu 				 BW_METER_GEQ |				\
    323  1.24      manu 				 BW_METER_LEQ)
    324  1.24      manu 
    325  1.24      manu #define BW_METER_UPCALL_DELIVERED (1 << 24)	/* upcall was delivered      */
    326  1.24      manu 
    327  1.24      manu 	struct bw_data	bm_threshold;		/* the upcall threshold	     */
    328  1.24      manu 	struct bw_data	bm_measured;		/* the measured bw	     */
    329  1.24      manu 	struct timeval	bm_start_time;		/* abs. time		     */
    330  1.24      manu };
    331  1.12   mycroft 
    332  1.36       kim struct sockopt; /* from <sys/socketvar.h> */
    333  1.36       kim 
    334  1.30    plunky int	ip_mrouter_set(struct socket *, struct sockopt *);
    335  1.30    plunky int	ip_mrouter_get(struct socket *, struct sockopt *);
    336  1.27  christos int	mrt_ioctl(struct socket *, u_long, void *);
    337  1.24      manu int	ip_mrouter_done(void);
    338  1.24      manu void	ip_mrouter_detach(struct ifnet *);
    339  1.24      manu void	reset_vif(struct vif *);
    340  1.24      manu int	ip_mforward(struct mbuf *, struct ifnet *);
    341   1.9   mycroft 
    342   1.7       jtc #endif /* _KERNEL */
    343  1.13     perry 
    344  1.26      elad #endif /* !_NETINET_IP_MROUTE_H_ */
    345