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