xref: /titanic_52/usr/src/uts/common/netinet/ip_mroute.h (revision 275c9da86e89f8abf71135cf63d9fc23671b2e60)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1991, 1997-1999, 2001, 2003 Sun Microsystems, Inc.
24  * All rights reserved.  Use is subject to license terms.
25  */
26 /* Copyright (c) 1990 Mentat Inc. */
27 
28 #ifndef	_NETINET_IP_MROUTE_H
29 #define	_NETINET_IP_MROUTE_H
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 /*
38  * Definitions for the kernel part of DVMRP,
39  * a Distance-Vector Multicast Routing Protocol.
40  * (See RFC-1075.)
41  *
42  * Written by David Waitzman, BBN Labs, August 1988.
43  * Modified by Steve Deering, Stanford, February 1989.
44  * Modified by Ajit Thyagarajan, PARC, August 1993.
45  * Modified by Ajit Thyagarajan, PARC, August 1994.
46  *
47  * MROUTING 3.5
48  */
49 
50 /*
51  * DVMRP-specific setsockopt commands.
52  */
53 
54 #define	MRT_INIT		100	/* initialize forwarder */
55 #define	MRT_DONE		101	/* shut down forwarder */
56 #define	MRT_ADD_VIF		102	/* create virtual interface */
57 #define	MRT_DEL_VIF		103	/* delete virtual interface */
58 #define	MRT_ADD_MFC		104	/* insert forwarding cache entry */
59 #define	MRT_DEL_MFC		105	/* delete forwarding cache entry */
60 #define	MRT_VERSION		106	/* get kernel version number */
61 #define	MRT_ASSERT		107	/* enable PIM assert processing */
62 
63 /*
64  * Types and macros for handling bitmaps with one bit per virtual interface.
65  */
66 #define	MAXVIFS			32
67 typedef uint_t			vifbitmap_t;
68 typedef ushort_t		vifi_t;	/* type of a vif index */
69 #define	ALL_VIFS		(vifi_t)-1
70 
71 #define	VIFM_SET(n, m)		((m) |=  (1 << (n)))
72 #define	VIFM_CLR(n, m)		((m) &= ~(1 << (n)))
73 #define	VIFM_ISSET(n, m)	((m) &   (1 << (n)))
74 #define	VIFM_CLRALL(m)		((m) = 0x00000000)
75 #define	VIFM_COPY(mfrom, mto)	((mto) = (mfrom))
76 #define	VIFM_SAME(m1, m2)	((m1) == (m2))
77 
78 
79 /*
80  * Argument structure for MRT_ADD_VIF. Also used for netstat.
81  * (MRT_DEL_VIF takes a single vifi_t argument.)
82  */
83 struct vifctl {
84     vifi_t	vifc_vifi;	/* the index of the vif to be added   */
85 	uchar_t	vifc_flags;	/* VIFF_ flags defined below	*/
86 	uchar_t	vifc_threshold;		/* min ttl required to forward on vif */
87 	uint_t	vifc_rate_limit;	/* max rate	*/
88 	struct	in_addr	vifc_lcl_addr;	/* local interface address	*/
89 	struct	in_addr	vifc_rmt_addr;	/* remote address(tunnels only)	*/
90 	/*
91 	 * vifc_pkt_in/out in Solaris, to report out of the kernel.
92 	 * Not nec. in BSD.
93 	 */
94 	uint_t	vifc_pkt_in;		/* # Pkts in on interface	*/
95 	uint_t	vifc_pkt_out;		/* # Pkts out on interface	*/
96 };
97 
98 #define	VIFF_TUNNEL	0x1		/* vif represents a tunnel end-point */
99 #define	VIFF_SRCRT	0x2		/* tunnel uses IP src routing	*/
100 #define	VIFF_REGISTER	0x4		/* for RPF check of PIM Register msg */
101 
102 /*
103  * Argument structure for MRT_ADD_MFC and MRT_DEL_MFC
104  * (mfcc_tos to be added at a future point)
105  */
106 struct mfcctl {
107     struct	in_addr	mfcc_origin;	/* ip origin of mcasts	*/
108     struct	in_addr	mfcc_mcastgrp; 	/* multicast group associated */
109     vifi_t		mfcc_parent;	/* incoming vif	*/
110     uint_t		mfcc_pkt_cnt;	/* pkt count for src-grp	*/
111     uchar_t		mfcc_ttls[MAXVIFS]; 	/* forwarding ttls on vifs    */
112 };
113 
114 /*
115  * The kernel's multicast routing statistics.
116  */
117 struct mrtstat {
118     uint_t	mrts_mfcfind_lookups;	/* #forwarding cache table lookups */
119     uint_t	mrts_mfcfind_misses;    /* # forwarding cache table misses */
120     uint_t	mrts_mfc_hits;		/* forwarding pkt mfctable hits	   */
121     uint_t	mrts_mfc_misses;	/* forwarding pkt mfctable misses  */
122     uint_t	mrts_upcalls;		/* # calls to mrouted		   */
123     uint_t	mrts_fwd_in;		/* # packets potentially forwarded */
124     uint_t	mrts_fwd_out;		/* # resulting outgoing packets    */
125     uint_t	mrts_fwd_drop;		/* # dropped for lack of resources */
126     uint_t	mrts_bad_tunnel;	/* malformed tunnel options	   */
127     uint_t	mrts_cant_tunnel;	/* no room for tunnel options	   */
128     uint_t	mrts_wrong_if;		/* arrived on wrong interface	   */
129     uint_t	mrts_upq_ovflw;		/* upcall Q overflow		   */
130     uint_t	mrts_cache_cleanups;	/* # entries with no upcalls	   */
131     uint_t	mrts_drop_sel;		/* pkts dropped selectively	   */
132     uint_t	mrts_q_overflow;	/* pkts dropped - Q overflow	   */
133     uint_t	mrts_pkt2large;		/* pkts dropped - size > BKT SIZE  */
134     uint_t	mrts_vifctlSize;	/* Size of vifctl		   */
135     uint_t	mrts_mfcctlSize;	/* Size of mfcctl		   */
136     uint_t 	mrts_pim_badversion;    /* dtgrms dropped - bad version */
137     uint_t 	mrts_pim_rcv_badcsum;   /* dtgrms dropped - bad checksum */
138     uint_t 	mrts_pim_badregisters;  /* dtgrms dropped - bad register pkts */
139     uint_t 	mrts_pim_regforwards;   /* dtgrms to be forwd - register pkts */
140     uint_t 	mrts_pim_regsend_drops; /* dtgrms dropped - register send */
141     uint_t	mrts_pim_malformed;	/* dtgrms dropped - packet malformed */
142     uint_t	mrts_pim_nomemory;	/* dtgrms dropped - no memory to fwd. */
143 };
144 
145 /*
146  * Argument structure used by mrouted to get src-grp pkt counts
147  */
148 struct sioc_sg_req {
149     struct in_addr src;
150     struct in_addr grp;
151     uint_t pktcnt;
152     uint_t bytecnt;
153     uint_t wrong_if;
154 };
155 
156 /*
157  * Argument structure used by mrouted to get vif pkt counts
158  */
159 struct sioc_vif_req {
160     vifi_t	vifi;		/* vif number				*/
161     uint_t	icount;		/* Input packet count on vif		*/
162     uint_t	ocount;		/* Output packet count on vif		*/
163     uint_t	ibytes;		/* Input byte count on vif		*/
164     uint_t	obytes;		/* Output byte count on vif		*/
165 };
166 
167 #ifdef _KERNEL
168 /*
169  * The kernel's virtual-interface structure.
170  */
171 struct vif {
172 	uchar_t		v_flags;	/* VIFF_ flags defined above	*/
173 	uchar_t		v_threshold;	/* Min ttl required to forward on vif */
174 	uint_t		v_rate_limit;	/* Max rate, in kbits/sec	*/
175 	struct tbf	*v_tbf;		/* Token bkt structure at intf.	*/
176 	struct in_addr	v_lcl_addr;	/* Local interface address	*/
177 	struct in_addr	v_rmt_addr;	/* Remote address(tunnels only)	*/
178 	struct ipif_s 	*v_ipif;	/* Pointer to logical interface	*/
179 	uint_t		v_pkt_in;	/* # Pkts in on interface	*/
180 	uint_t		v_pkt_out;	/* # Pkts out on interface	*/
181 	uint_t		v_bytes_in;	/* # Bytes in on interface	*/
182 	uint_t		v_bytes_out;	/* # Bytes out on interface	*/
183 	timeout_id_t	v_timeout_id;	/* Qtimeout return id	*/
184 	/*
185 	 * struct route	v_route;	Cached route if this is a tunnel
186 	 *				Used in bsd for performance
187 	 */
188 	uint_t			v_refcnt;
189 	uchar_t 		v_marks;
190 	kmutex_t		v_lock;
191 };
192 
193 /*
194  * vif is not being used. However if refcnt != 0 than its being initalized.
195  */
196 #define	VIF_MARK_NOTINUSE	0x0	/* see comment above */
197 
198 #define	VIF_MARK_CONDEMNED	0x1	/* delete when refcnt goes to zero. */
199 
200 #define	VIF_MARK_GOOD		0x2	/* vif is good */
201 
202 #define	VIF_MARK_INUSE		VIF_MARK_CONDEMNED | VIF_MARK_GOOD
203 
204 /*
205  * The kernel's multicast forwarding cache entry structure
206  * (A field for the type of service (mfc_tos) is to be added
207  * at a future point)
208  */
209 struct mfc {
210     struct in_addr	mfc_origin;	/* ip origin of mcasts	*/
211     struct in_addr  	mfc_mcastgrp;	/* multicast group associated */
212     vifi_t		mfc_parent;	/* incoming vif	*/
213     uchar_t		mfc_ttls[MAXVIFS];	/* forwarding ttls on vifs    */
214     uint_t		mfc_pkt_cnt;	/* pkt count for src-grp	*/
215     uint_t		mfc_byte_cnt;	/* byte count for src-grp	*/
216     uint_t		mfc_wrong_if;	/* wrong if for src-grp	*/
217     struct timespec  	mfc_last_assert;	/* last time I sent an assert */
218     struct rtdetq	*mfc_rte;	/* pending upcall	*/
219     timeout_id_t	mfc_timeout_id;	/* qtimeout return id	*/
220     struct mfc		*mfc_next;
221     uchar_t 		mfc_marks;
222     kmutex_t		mfc_mutex;	/* protects fields and rte list */
223 };
224 
225 /*
226  * mfc bucket structure.
227  */
228 struct mfcb {
229     struct mfc  *mfcb_mfc;	/* first mfc in this bucket */
230     kmutex_t	mfcb_lock;
231     uint_t	mfcb_refcnt;	/* protected by mfcb_lock */
232     uchar_t	mfcb_marks;	/* protected by mfcb_lock */
233 };
234 
235 #define	MFCB_MARK_CONDEMNED	0x1
236 
237 /*
238  * Argument structure used for pkt info. while upcall is made
239  */
240 struct rtdetq {
241     mblk_t		*mp;		/*  A copy of the packet	*/
242     ill_t		*ill;		/*  Interface pkt came in on	*/
243     struct rtdetq	*rte_next;
244 };
245 #endif
246 
247 /*
248  * Struct used to communicate from kernel to multicast router
249  * note the convenient similarity to an IP packet
250  */
251 struct igmpmsg {
252     uint_t	    unused1;
253     uint_t	    unused2;
254     uchar_t	    im_msgtype;			/* what type of message	    */
255 #define	IGMPMSG_NOCACHE		1
256 #define	IGMPMSG_WRONGVIF	2
257 #define	IGMPMSG_WHOLEPKT	3
258     uchar_t	    im_mbz;			/* must be zero		    */
259     uchar_t	    im_vif;			/* vif rec'd on		    */
260     uchar_t	    unused3;
261     struct in_addr  im_src, im_dst;
262 };
263 
264 #ifdef _KERNEL
265 #define	MFCTBLSIZ	256
266 #if (MFCTBLSIZ & (MFCTBLSIZ - 1)) == 0	  /* from sys:route.h */
267 #define	MFCHASHMOD(h)	((h) & (MFCTBLSIZ - 1))
268 #else
269 #define	MFCHASHMOD(h)	((h) % MFCTBLSIZ)
270 #endif
271 
272 #define	MAX_UPQ	4		/* max. no of pkts in upcall Q */
273 
274 /*
275  * Token Bucket filter code
276  */
277 #define	MAX_BKT_SIZE	10000		/* 10K bytes size 		*/
278 #define	MAXQSIZE	10		/* max # of pkts in queue 	*/
279 #define	TOKEN_SIZE	8		/* number of bits in token	*/
280 
281 /*
282  * The token bucket filter at each vif
283  */
284 struct tbf {
285     timespec_t 		tbf_last_pkt_t; /* arr. time of last pkt 	*/
286     uint_t 		tbf_n_tok;	/* no of tokens in bucket 	*/
287     uint_t 		tbf_q_len;    	/* length of queue at this vif	*/
288     uint_t 		tbf_max_q_len;  /* max queue length		*/
289     mblk_t		*tbf_q;		/* Packet queue	*/
290     mblk_t		*tbf_t;		/* Tail-insertion pointer	*/
291     kmutex_t 		tbf_lock;	/* lock on the tbf		*/
292 };
293 
294 #endif /* _KERNEL */
295 
296 #ifdef	__cplusplus
297 }
298 #endif
299 
300 #endif	/* _NETINET_IP_MROUTE_H */
301