xref: /openbsd/sys/netinet6/ip6_mroute.h (revision 2028c273)
1 /*	$OpenBSD: ip6_mroute.h,v 1.23 2022/05/05 13:57:41 claudio Exp $	*/
2 /*	$KAME: ip6_mroute.h,v 1.17 2001/02/10 02:05:52 itojun Exp $	*/
3 
4 /*
5  * Copyright (C) 1998 WIDE Project.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the project nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32 
33 /*
34  * Definitions for IP multicast forwarding.
35  *
36  * Written by David Waitzman, BBN Labs, August 1988.
37  * Modified by Steve Deering, Stanford, February 1989.
38  * Modified by Ajit Thyagarajan, PARC, August 1993.
39  * Modified by Ajit Thyagarajan, PARC, August 1994.
40  * Modified by Ahmed Helmy, USC, September 1996.
41  *
42  * MROUTING Revision: 1.2
43  */
44 
45 #ifndef _NETINET6_IP6_MROUTE_H_
46 #define _NETINET6_IP6_MROUTE_H_
47 
48 /*
49  * Multicast Routing set/getsockopt commands.
50  */
51 #define MRT6_DONE		101	/* shut down forwarder */
52 #define MRT6_ADD_MIF		102	/* add multicast interface */
53 #define MRT6_DEL_MIF		103	/* delete multicast interface */
54 #define MRT6_ADD_MFC		104	/* insert forwarding cache entry */
55 #define MRT6_DEL_MFC		105	/* delete forwarding cache entry */
56 #define MRT6_INIT		108	/* initialize forwarder (mrt6msg) */
57 
58 /*
59  * Types and macros for handling bitmaps with one bit per multicast interface.
60  */
61 typedef u_short mifi_t;		/* type of a mif index */
62 #define MAXMIFS		64
63 
64 /*
65  * Assume inclusion of sys/param.h or sys/select.h for howmany()
66  */
67 #define	__NIFBITS	(sizeof(uint32_t) * 8)	/* bits per mask */
68 typedef	struct if_set {
69 	uint32_t	ifs_bits[howmany(256, __NIFBITS)];
70 } if_set;
71 
72 #define	IF_SET(n, p) \
73 	((p)->ifs_bits[(n)/__NIFBITS] |= (1U << ((n) % __NIFBITS)))
74 #define	IF_CLR(n, p) \
75 	((p)->ifs_bits[(n)/__NIFBITS] &= ~(1U << ((n) % __NIFBITS)))
76 #define	IF_ISSET(n, p) \
77 	((p)->ifs_bits[(n)/__NIFBITS] & (1U << ((n) % __NIFBITS)))
78 #define	IF_COPY(f, t)	memcpy(t, f, sizeof(*(f)))
79 #define	IF_ZERO(p)	memset(p, 0, sizeof(*(p)))
80 
81 /*
82  * Argument structure for MRT6_ADD_IF.
83  */
84 struct mif6ctl {
85 	mifi_t	    mif6c_mifi;		/* the index of the mif to be added  */
86 	u_char	    mif6c_flags;	/* MIFF_ flags defined below         */
87 	u_short	    mif6c_pifi;		/* the index of the physical IF */
88 #ifdef notyet
89 	u_int	    mif6c_rate_limit;    /* max rate			     */
90 #endif
91 };
92 
93 #define	MIFF_REGISTER	0x1	/* mif represents a register end-point */
94 
95 #define MF6C_INCOMPLETE_PARENT ((mifi_t)-1)
96 
97 /*
98  * Argument structure for MRT6_ADD_MFC and MRT6_DEL_MFC
99  */
100 struct mf6cctl {
101 	struct sockaddr_in6 mf6cc_origin;	/* IPv6 origin of mcasts */
102 	struct sockaddr_in6 mf6cc_mcastgrp; /* multicast group associated */
103 	mifi_t		mf6cc_parent;	/* incoming ifindex */
104 	struct if_set	mf6cc_ifset;	/* set of forwarding ifs */
105 };
106 
107 /* structure used to get all the mif entries via sysctl */
108 struct mif6info {
109 	struct in6_addr	m6_lcl_addr;	/* local interface address           */
110 	u_int16_t	m6_ifindex;	/* interface index                   */
111 	u_int64_t	m6_pkt_in;	/* # pkts in on interface            */
112 	u_int64_t	m6_pkt_out;	/* # pkts out on interface           */
113 	u_int64_t	m6_bytes_in;	/* # bytes in on interface	     */
114 	u_int64_t	m6_bytes_out;	/* # bytes out on interface	     */
115 	u_int		m6_rate_limit;	/* max rate			     */
116 	mifi_t		m6_mifi;
117         u_char		m6_flags;	/* MIFF_ flags defined above         */
118 };
119 
120 /* structure used to get all the mf6c entries via sysctl */
121 struct mf6cinfo {
122 	struct sockaddr_in6  mf6c_origin;	/* IPv6 origin of mcasts     */
123 	struct sockaddr_in6  mf6c_mcastgrp;	/* multicast group associated*/
124 	mifi_t		 mf6c_parent;		/* incoming IF               */
125 	struct if_set	 mf6c_ifset;		/* set of outgoing IFs */
126 
127 	u_int64_t	mf6c_pkt_cnt;		/* pkt count for src-grp     */
128 	u_int64_t	mf6c_byte_cnt;		/* byte count for src-grp    */
129 	u_int64_t	mf6c_stall_cnt;		/* pkt-cnt waiting for route */
130 };
131 
132 /*
133  * The kernel's multicast routing statistics.
134  */
135 struct mrt6stat {
136 	u_int64_t mrt6s_mfc_lookups;	/* # forw. cache hash table hits   */
137 	u_int64_t mrt6s_mfc_misses;	/* # forw. cache hash table misses */
138 	u_int64_t mrt6s_upcalls;	/* # calls to mrouted              */
139 	u_int64_t mrt6s_no_route;	/* no route for packet's origin    */
140 	u_int64_t mrt6s_bad_tunnel;	/* malformed tunnel options        */
141 	u_int64_t mrt6s_cant_tunnel;	/* no room for tunnel options      */
142 	u_int64_t mrt6s_wrong_if;	/* arrived on wrong interface	   */
143 	u_int64_t mrt6s_upq_ovflw;	/* upcall Q overflow		   */
144 	u_int64_t mrt6s_cache_cleanups;	/* # entries with no upcalls	   */
145 	u_int64_t mrt6s_drop_sel;	/* pkts dropped selectively        */
146 	u_int64_t mrt6s_q_overflow;	/* pkts dropped - Q overflow       */
147 	u_int64_t mrt6s_pkt2large;	/* pkts dropped - size > BKT SIZE  */
148 	u_int64_t mrt6s_upq_sockfull;	/* upcalls dropped - socket full   */
149 };
150 
151 /*
152  * Structure used to communicate from kernel to multicast router.
153  * We'll overlay the structure onto an MLD header (not an IPv6 header
154  * like igmpmsg{} used for IPv4 implementation). This is because this
155  * structure will be passed via an IPv6 raw socket, on which an application
156  * will only receive the payload i.e. the data after the IPv6 header and all
157  * the extension headers. (see Section 3 of draft-ietf-ipngwg-2292bis-01)
158  */
159 struct mrt6msg {
160 #define MRT6MSG_NOCACHE		1
161 #define MRT6MSG_WRONGMIF	2
162 #define MRT6MSG_WHOLEPKT	3		/* used for user level encap*/
163 	u_char	    im6_mbz;			/* must be zero		    */
164 	u_char	    im6_msgtype;		/* what type of message	    */
165 	u_int16_t   im6_mif;			/* mif rec'd on		    */
166 	u_int32_t   im6_pad;			/* padding for 64bit arch   */
167 	struct in6_addr  im6_src, im6_dst;
168 };
169 
170 /*
171  * Argument structure used by multicast routing daemon to get src-grp
172  * packet counts
173  */
174 struct sioc_sg_req6 {
175 	struct sockaddr_in6 src;
176 	struct sockaddr_in6 grp;
177 	u_int64_t pktcnt;
178 	u_int64_t bytecnt;
179 	u_int64_t wrong_if;
180 };
181 
182 /*
183  * Argument structure used by mrouted to get mif pkt counts
184  */
185 struct sioc_mif_req6 {
186 	mifi_t mifi;		/* mif number				*/
187 	u_int64_t icount;	/* Input packet count on mif		*/
188 	u_int64_t ocount;	/* Output packet count on mif		*/
189 	u_int64_t ibytes;	/* Input byte count on mif		*/
190 	u_int64_t obytes;	/* Output byte count on mif		*/
191 };
192 
193 #if defined(_KERNEL)
194 /* How frequent should we look for expired entries (in seconds). */
195 #define	MCAST_EXPIRE_TIMEOUT	30
196 
197 extern struct rttimer_queue ip6_mrouterq;
198 void	mf6c_expire_route(struct rtentry *, u_int);
199 
200 /*
201  * The kernel's multicast-interface structure.
202  */
203 struct mif6 {
204 	mifi_t		m6_mifi;	/* mif index			     */
205         u_char		m6_flags;	/* MIFF_ flags defined above         */
206 	u_int		m6_rate_limit;	/* max rate			     */
207 #ifdef notyet
208 	struct tbf      *m6_tbf;	/* token bucket structure at intf.   */
209 #endif
210 	struct in6_addr	m6_lcl_addr;	/* local interface address           */
211 	u_int64_t	m6_pkt_in;	/* # pkts in on interface            */
212 	u_int64_t	m6_pkt_out;	/* # pkts out on interface           */
213 	u_int64_t	m6_bytes_in;	/* # bytes in on interface	     */
214 	u_int64_t	m6_bytes_out;	/* # bytes out on interface	     */
215 };
216 
217 /*
218  * The kernel's multicast forwarding cache entry structure
219  */
220 struct mf6c {
221 	struct sockaddr_in6  mf6c_origin;	/* IPv6 origin of mcasts     */
222 	struct sockaddr_in6  mf6c_mcastgrp;	/* multicast group associated*/
223 	mifi_t		 mf6c_parent;		/* incoming IF               */
224 
225 	u_int64_t	mf6c_pkt_cnt;		/* pkt count for src-grp     */
226 	u_int64_t	mf6c_byte_cnt;		/* byte count for src-grp    */
227 	u_int64_t	mf6c_wrong_if;		/* wrong if for src-grp	     */
228 	int		mf6c_expire;		/* time to clean entry up    */
229 };
230 
231 int	ip6_mrouter_set(int, struct socket *, struct mbuf *);
232 int	ip6_mrouter_get(int, struct socket *, struct mbuf *);
233 int	ip6_mrouter_done(struct socket *);
234 void	ip6_mrouter_detach(struct ifnet *);
235 int	mrt6_ioctl(struct socket *, u_long, caddr_t);
236 int	mrt6_sysctl_mif(void *, size_t *);
237 int	mrt6_sysctl_mfc(void *, size_t *);
238 #endif /* _KERNEL */
239 
240 #endif /* !_NETINET6_IP6_MROUTE_H_ */
241