| 1 | /*	$OpenBSD: ip_mroute.h,v 1.34 2025/05/09 14:43:47 jan Exp $	*/ |
| 2 | /*	$NetBSD: ip_mroute.h,v 1.23 2004/04/21 17:49:46 itojun Exp $	*/ |
| 3 | |
| 4 | #ifndef _NETINET_IP_MROUTE_H_ |
| 5 | #define _NETINET_IP_MROUTE_H_ |
| 6 | |
| 7 | /* |
| 8 | * Definitions for IP multicast forwarding. |
| 9 | * |
| 10 | * Written by David Waitzman, BBN Labs, August 1988. |
| 11 | * Modified by Steve Deering, Stanford, February 1989. |
| 12 | * Modified by Ajit Thyagarajan, PARC, August 1993. |
| 13 | * Modified by Ajit Thyagarajan, PARC, August 1994. |
| 14 | * Modified by Ahmed Helmy, SGI, June 1996. |
| 15 | * Modified by Pavlin Radoslavov, ICSI, October 2002. |
| 16 | * |
| 17 | * MROUTING Revision: 1.2 |
| 18 | * advanced API support, bandwidth metering and signaling. |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | * Multicast Routing set/getsockopt commands. |
| 23 | */ |
| 24 | #define	MRT_INIT		100	/* initialize forwarder */ |
| 25 | #define	MRT_DONE		101	/* shut down forwarder */ |
| 26 | #define	MRT_ADD_VIF		102	/* create virtual interface */ |
| 27 | #define	MRT_DEL_VIF		103	/* delete virtual interface */ |
| 28 | #define	MRT_ADD_MFC		104	/* insert forwarding cache entry */ |
| 29 | #define	MRT_DEL_MFC		105	/* delete forwarding cache entry */ |
| 30 | #define	MRT_VERSION		106	/* get kernel version number */ |
| 31 | #define	MRT_ASSERT		107	/* enable assert processing */ |
| 32 | #define	MRT_API_SUPPORT		109	/* supported MRT API */ |
| 33 | #define	MRT_API_CONFIG		110	/* config MRT API */ |
| 34 | |
| 35 | /* |
| 36 | * Types and macros for handling bitmaps with one bit per virtual interface. |
| 37 | */ |
| 38 | #define	MAXVIFS 32 |
| 39 | typedef u_int32_t vifbitmap_t; |
| 40 | typedef u_int16_t vifi_t;		/* type of a vif index */ |
| 41 | |
| 42 | #define	VIFM_SET(n, m)			((m) |= (1 << (n))) |
| 43 | #define	VIFM_CLR(n, m)			((m) &= ~(1 << (n))) |
| 44 | #define	VIFM_ISSET(n, m)		((m) & (1 << (n))) |
| 45 | #define	VIFM_CLRALL(m)			((m) = 0x00000000) |
| 46 | #define	VIFM_COPY(mfrom, mto)		((mto) = (mfrom)) |
| 47 | #define	VIFM_SAME(m1, m2)		((m1) == (m2)) |
| 48 | |
| 49 | #define	VIFF_TUNNEL	0x1		/* vif represents a tunnel end-point */ |
| 50 | #define	VIFF_SRCRT	0x2		/* tunnel uses IP src routing */ |
| 51 | |
| 52 | /* |
| 53 | * Argument structure for MRT_ADD_VIF. |
| 54 | * (MRT_DEL_VIF takes a single vifi_t argument.) |
| 55 | */ |
| 56 | struct vifctl { |
| 57 | 	vifi_t	 vifc_vifi;		/* the index of the vif to be added */ |
| 58 | 	u_int8_t vifc_flags;		/* VIFF_ flags defined above */ |
| 59 | 	u_int8_t vifc_threshold;	/* min ttl required to forward on vif */ |
| 60 | 	u_int32_t vifc_rate_limit;	/* ignored */ |
| 61 | 	struct	 in_addr vifc_lcl_addr;/* local interface address */ |
| 62 | 	struct	 in_addr vifc_rmt_addr;/* remote address (tunnels only) */ |
| 63 | }; |
| 64 | |
| 65 | /* |
| 66 | * Argument structure for MRT_ADD_MFC and MRT_DEL_MFC. |
| 67 | * XXX if you change this, make sure to change struct mfcctl2 as well. |
| 68 | */ |
| 69 | struct mfcctl { |
| 70 | 	struct	 in_addr mfcc_origin;	/* ip origin of mcasts */ |
| 71 | 	struct	 in_addr mfcc_mcastgrp;	/* multicast group associated */ |
| 72 | 	vifi_t	 mfcc_parent;		/* incoming vif */ |
| 73 | 	u_int8_t mfcc_ttls[MAXVIFS];	/* forwarding ttls on vifs */ |
| 74 | }; |
| 75 | |
| 76 | /* |
| 77 | * The new argument structure for MRT_ADD_MFC and MRT_DEL_MFC overlays |
| 78 | * and extends the old struct mfcctl. |
| 79 | */ |
| 80 | struct mfcctl2 { |
| 81 | 	/* the mfcctl fields */ |
| 82 | 	struct in_addr	mfcc_origin;		/* ip origin of mcasts	 */ |
| 83 | 	struct in_addr	mfcc_mcastgrp;		/* multicast group associated*/ |
| 84 | 	vifi_t		mfcc_parent;		/* incoming vif		 */ |
| 85 | 	u_int8_t	mfcc_ttls[MAXVIFS];	/* forwarding ttls on vifs */ |
| 86 | |
| 87 | 	/* extension fields */ |
| 88 | 	u_int8_t	mfcc_flags[MAXVIFS];	/* the MRT_MFC_FLAGS_* flags */ |
| 89 | 	struct in_addr	mfcc_rp;		/* the RP address */ |
| 90 | }; |
| 91 | /* |
| 92 | * The advanced-API flags. |
| 93 | * |
| 94 | * The MRT_MFC_FLAGS_XXX API flags are also used as flags |
| 95 | * for the mfcc_flags field. |
| 96 | */ |
| 97 | #define	MRT_MFC_FLAGS_DISABLE_WRONGVIF	(1 << 0) /* disable WRONGVIF signals */ |
| 98 | #define	MRT_MFC_RP			(1 << 8) /* enable RP address	 */ |
| 99 | #define	MRT_MFC_BW_UPCALL		(1 << 9) /* enable bw upcalls	 */ |
| 100 | #define	MRT_MFC_FLAGS_ALL		(MRT_MFC_FLAGS_DISABLE_WRONGVIF) |
| 101 | #define	MRT_API_FLAGS_ALL		(MRT_MFC_FLAGS_ALL |		 \ |
| 102 | 					 MRT_MFC_RP |			 \ |
| 103 | 					 MRT_MFC_BW_UPCALL) |
| 104 | |
| 105 | /* structure used to get all the mfc entries */ |
| 106 | struct mfcinfo { |
| 107 | 	struct	 in_addr mfc_origin;	/* ip origin of mcasts */ |
| 108 | 	struct	 in_addr mfc_mcastgrp;	/* multicast group associated */ |
| 109 | 	vifi_t	 mfc_parent;		/* incoming vif */ |
| 110 | 	u_long	 mfc_pkt_cnt;		/* pkt count for src-grp */ |
| 111 | 	u_long	 mfc_byte_cnt;		/* byte count for src-grp */ |
| 112 | 	u_int8_t mfc_ttls[MAXVIFS];	/* forwarding ttls on vifs */ |
| 113 | }; |
| 114 | |
| 115 | /* structure used to get all the vif entries */ |
| 116 | struct vifinfo { |
| 117 | 	vifi_t	 v_vifi;		/* the index of the vif to be added */ |
| 118 | 	u_int8_t v_flags;		/* VIFF_ flags defined above */ |
| 119 | 	u_int8_t v_threshold;		/* min ttl required to forward on vif */ |
| 120 | 	struct	 in_addr v_lcl_addr;	/* local interface address */ |
| 121 | 	struct	 in_addr v_rmt_addr;	/* remote address (tunnels only) */ |
| 122 | 	u_long	 v_pkt_in;		/* # pkts in on interface */ |
| 123 | 	u_long	 v_pkt_out;		/* # pkts out on interface */ |
| 124 | 	u_long	 v_bytes_in;		/* # bytes in on interface */ |
| 125 | 	u_long	 v_bytes_out;		/* # bytes out on interface */ |
| 126 | }; |
| 127 | |
| 128 | /* |
| 129 | * Argument structure used by mrouted to get src-grp pkt counts. |
| 130 | */ |
| 131 | struct sioc_sg_req { |
| 132 | 	struct	in_addr src; |
| 133 | 	struct	in_addr grp; |
| 134 | 	u_long	pktcnt; |
| 135 | 	u_long	bytecnt; |
| 136 | 	u_long	wrong_if; |
| 137 | }; |
| 138 | |
| 139 | /* |
| 140 | * Argument structure used by mrouted to get vif pkt counts. |
| 141 | */ |
| 142 | struct sioc_vif_req { |
| 143 | 	vifi_t	vifi;			/* vif number */ |
| 144 | 	u_long	icount;			/* input packet count on vif */ |
| 145 | 	u_long	ocount;			/* output packet count on vif */ |
| 146 | 	u_long	ibytes;			/* input byte count on vif */ |
| 147 | 	u_long	obytes;			/* output byte count on vif */ |
| 148 | }; |
| 149 | |
| 150 | |
| 151 | /* |
| 152 | * The kernel's multicast routing statistics. |
| 153 | */ |
| 154 | struct mrtstat { |
| 155 | 	u_long	mrts_mfc_lookups;	/* # forw. cache hash table hits */ |
| 156 | 	u_long	mrts_mfc_misses;	/* # forw. cache hash table misses */ |
| 157 | 	u_long	mrts_upcalls;		/* # calls to mrouted */ |
| 158 | 	u_long	mrts_no_route;		/* no route for packet's origin */ |
| 159 | 	u_long	mrts_bad_tunnel;	/* malformed tunnel options */ |
| 160 | 	u_long	mrts_cant_tunnel;	/* no room for tunnel options */ |
| 161 | 	u_long	mrts_wrong_if;		/* arrived on wrong interface */ |
| 162 | 	u_long	mrts_upq_ovflw;		/* upcall Q overflow */ |
| 163 | 	u_long	mrts_cache_cleanups;	/* # entries with no upcalls */ |
| 164 | 	u_long	mrts_drop_sel;		/* pkts dropped selectively */ |
| 165 | 	u_long	mrts_q_overflow;	/* pkts dropped - Q overflow */ |
| 166 | 	u_long	mrts_pkt2large;		/* pkts dropped - size > BKT SIZE */ |
| 167 | 	u_long	mrts_upq_sockfull;	/* upcalls dropped - socket full */ |
| 168 | }; |
| 169 | |
| 170 | #ifdef _KERNEL |
| 171 | |
| 172 | enum mrtstat_counters { |
| 173 | 	mrts_mfc_lookups, |
| 174 | 	mrts_mfc_misses, |
| 175 | 	mrts_upcalls, |
| 176 | 	mrts_no_route, |
| 177 | 	mrts_bad_tunnel, |
| 178 | 	mrts_cant_tunnel, |
| 179 | 	mrts_wrong_if, |
| 180 | 	mrts_upq_ovflw, |
| 181 | 	mrts_cache_cleanups, |
| 182 | 	mrts_drop_sel, |
| 183 | 	mrts_q_overflow, |
| 184 | 	mrts_pkt2large, |
| 185 | 	mrts_upq_sockfull, |
| 186 | 	mrts_ncounters |
| 187 | }; |
| 188 | |
| 189 | extern struct cpumem *mrtcounters; |
| 190 | |
| 191 | static inline void |
| 192 | mrtstat_inc(enum mrtstat_counters c) |
| 193 | { |
| 194 | 	counters_inc(mrtcounters, c); |
| 195 | } |
| 196 | |
| 197 | /* How frequent should we look for expired entries (in seconds). */ |
| 198 | #define MCAST_EXPIRE_FREQUENCY		30 |
| 199 | |
| 200 | extern int ip_mrtproto; |
| 201 | |
| 202 | /* |
| 203 | * The kernel's virtual-interface structure. |
| 204 | */ |
| 205 | struct vif { |
| 206 | 	vifi_t v_id;			/* Virtual interface index */ |
| 207 | 	u_int8_t v_flags;		/* VIFF_ flags defined above */ |
| 208 | 	u_int8_t v_threshold;		/* min ttl required to forward on vif */ |
| 209 | 	struct	 in_addr v_lcl_addr;	/* local interface address */ |
| 210 | 	struct	 in_addr v_rmt_addr;	/* remote address (tunnels only) */ |
| 211 | 	u_long	 v_pkt_in;		/* # pkts in on interface */ |
| 212 | 	u_long	 v_pkt_out;		/* # pkts out on interface */ |
| 213 | 	u_long	 v_bytes_in;		/* # bytes in on interface */ |
| 214 | 	u_long	 v_bytes_out;		/* # bytes out on interface */ |
| 215 | }; |
| 216 | |
| 217 | /* |
| 218 | * The kernel's multicast forwarding cache entry structure. |
| 219 | * (A field for the type of service (mfc_tos) is to be added |
| 220 | * at a future point.) |
| 221 | */ |
| 222 | struct mfc { |
| 223 | 	vifi_t	 mfc_parent;			/* incoming vif */ |
| 224 | 	u_long	 mfc_pkt_cnt;			/* pkt count for src-grp */ |
| 225 | 	u_long	 mfc_byte_cnt;			/* byte count for src-grp */ |
| 226 | 	u_long	 mfc_wrong_if;			/* wrong if for src-grp	*/ |
| 227 | 	uint8_t	 mfc_ttl;			/* route interface ttl */ |
| 228 | 	uint8_t mfc_flags;			/* MRT_MFC_FLAGS_* flags */ |
| 229 | 	struct in_addr	mfc_rp;			/* the RP address	 */ |
| 230 | 	u_long	 mfc_expire;			/* expire timer */ |
| 231 | }; |
| 232 | |
| 233 | /* |
| 234 | * Structure used to communicate from kernel to multicast router. |
| 235 | * (Note the convenient similarity to an IP packet.) |
| 236 | */ |
| 237 | struct igmpmsg { |
| 238 | 	u_int32_t unused1; |
| 239 | 	u_int32_t unused2; |
| 240 | 	u_int8_t im_msgtype;		/* what type of message */ |
| 241 | #define	IGMPMSG_NOCACHE		1	/* no MFC in the kernel		 */ |
| 242 | #define	IGMPMSG_WRONGVIF	2	/* packet came from wrong interface */ |
| 243 | #define	IGMPMSG_BW_UPCALL	4	/* BW monitoring upcall		 */ |
| 244 | 	u_int8_t im_mbz;		/* must be zero */ |
| 245 | 	u_int8_t im_vif;		/* vif rec'd on */ |
| 246 | 	u_int8_t unused3; |
| 247 | 	struct	 in_addr im_src, im_dst; |
| 248 | }; |
| 249 | |
| 250 | int	ip_mrouter_set(struct socket *, int, struct mbuf *); |
| 251 | int	ip_mrouter_get(struct socket *, int, struct mbuf *); |
| 252 | void	mrt_init(void); |
| 253 | int	mrt_ioctl(struct socket *, u_long, caddr_t); |
| 254 | int	mrt_sysctl_vif(void *, size_t *); |
| 255 | int	mrt_sysctl_mrtstat(void *, size_t *, void *); |
| 256 | int	mrt_sysctl_mfc(void *, size_t *); |
| 257 | int	ip_mrouter_done(struct socket *); |
| 258 | void	vif_delete(struct ifnet *); |
| 259 | |
| 260 | #endif /* _KERNEL */ |
| 261 | #endif /* _NETINET_IP_MROUTE_H_ */ |