ip_mroute.h revision 11042:2d6e217af1b4
1298770Sdelphij/*
2275970Scy * CDDL HEADER START
3275970Scy *
4275970Scy * The contents of this file are subject to the terms of the
5275970Scy * Common Development and Distribution License (the "License").
6298770Sdelphij * You may not use this file except in compliance with the License.
7275970Scy *
8275970Scy * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9275970Scy * or http://www.opensolaris.org/os/licensing.
10275970Scy * See the License for the specific language governing permissions
11275970Scy * and limitations under the License.
12275970Scy *
13275970Scy * When distributing Covered Code, include this CDDL HEADER in each
14275970Scy * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15275970Scy * If applicable, add the following below this CDDL HEADER, with the
16275970Scy * fields enclosed by brackets "[]" replaced with your own identifying
17275970Scy * information: Portions Copyright [yyyy] [name of copyright owner]
18275970Scy *
19275970Scy * CDDL HEADER END
20275970Scy */
21275970Scy
22275970Scy/*
23275970Scy * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24275970Scy * Use is subject to license terms.
25275970Scy */
26275970Scy/* Copyright (c) 1990 Mentat Inc. */
27275970Scy
28275970Scy#ifndef	_NETINET_IP_MROUTE_H
29275970Scy#define	_NETINET_IP_MROUTE_H
30275970Scy
31275970Scy#ifdef	__cplusplus
32275970Scyextern "C" {
33275970Scy#endif
34275970Scy
35275970Scy/*
36275970Scy * Definitions for the kernel part of DVMRP,
37275970Scy * a Distance-Vector Multicast Routing Protocol.
38275970Scy * (See RFC-1075.)
39275970Scy *
40275970Scy * Written by David Waitzman, BBN Labs, August 1988.
41275970Scy * Modified by Steve Deering, Stanford, February 1989.
42275970Scy * Modified by Ajit Thyagarajan, PARC, August 1993.
43275970Scy * Modified by Ajit Thyagarajan, PARC, August 1994.
44275970Scy *
45275970Scy * MROUTING 3.5
46275970Scy */
47275970Scy
48275970Scy/*
49275970Scy * DVMRP-specific setsockopt commands.
50275970Scy */
51275970Scy
52275970Scy#define	MRT_INIT		100	/* initialize forwarder */
53275970Scy#define	MRT_DONE		101	/* shut down forwarder */
54275970Scy#define	MRT_ADD_VIF		102	/* create virtual interface */
55275970Scy#define	MRT_DEL_VIF		103	/* delete virtual interface */
56275970Scy#define	MRT_ADD_MFC		104	/* insert forwarding cache entry */
57275970Scy#define	MRT_DEL_MFC		105	/* delete forwarding cache entry */
58275970Scy#define	MRT_VERSION		106	/* get kernel version number */
59275970Scy#define	MRT_ASSERT		107	/* enable PIM assert processing */
60275970Scy
61275970Scy/*
62275970Scy * Types and macros for handling bitmaps with one bit per virtual interface.
63275970Scy */
64275970Scy#define	MAXVIFS			32
65275970Scytypedef uint_t			vifbitmap_t;
66275970Scytypedef ushort_t		vifi_t;	/* type of a vif index */
67275970Scy#define	ALL_VIFS		(vifi_t)-1
68275970Scy
69275970Scy#define	VIFM_SET(n, m)		((m) |=  (1 << (n)))
70275970Scy#define	VIFM_CLR(n, m)		((m) &= ~(1 << (n)))
71275970Scy#define	VIFM_ISSET(n, m)	((m) &   (1 << (n)))
72275970Scy#define	VIFM_CLRALL(m)		((m) = 0x00000000)
73275970Scy#define	VIFM_COPY(mfrom, mto)	((mto) = (mfrom))
74275970Scy#define	VIFM_SAME(m1, m2)	((m1) == (m2))
75275970Scy
76275970Scy
77275970Scy/*
78275970Scy * Argument structure for MRT_ADD_VIF. Also used for netstat.
79275970Scy * (MRT_DEL_VIF takes a single vifi_t argument.)
80275970Scy */
81275970Scystruct vifctl {
82275970Scy    vifi_t	vifc_vifi;	/* the index of the vif to be added   */
83275970Scy	uchar_t	vifc_flags;	/* VIFF_ flags defined below	*/
84275970Scy	uchar_t	vifc_threshold;		/* min ttl required to forward on vif */
85275970Scy	uint_t	vifc_rate_limit;	/* max rate	*/
86275970Scy	struct	in_addr	vifc_lcl_addr;	/* local interface address	*/
87275970Scy	struct	in_addr	vifc_rmt_addr;	/* remote address(tunnels only)	*/
88275970Scy	/*
89275970Scy	 * vifc_pkt_in/out in Solaris, to report out of the kernel.
90275970Scy	 * Not nec. in BSD.
91275970Scy	 */
92275970Scy	uint_t	vifc_pkt_in;		/* # Pkts in on interface	*/
93275970Scy	uint_t	vifc_pkt_out;		/* # Pkts out on interface	*/
94275970Scy};
95275970Scy
96275970Scy#define	VIFF_TUNNEL	0x1		/* vif represents a tunnel end-point */
97275970Scy#define	VIFF_SRCRT	0x2		/* tunnel uses IP src routing	*/
98275970Scy#define	VIFF_REGISTER	0x4		/* for RPF check of PIM Register msg */
99275970Scy
100275970Scy/*
101275970Scy * Argument structure for MRT_ADD_MFC and MRT_DEL_MFC
102275970Scy * (mfcc_tos to be added at a future point)
103275970Scy */
104275970Scystruct mfcctl {
105275970Scy    struct	in_addr	mfcc_origin;	/* ip origin of mcasts	*/
106275970Scy    struct	in_addr	mfcc_mcastgrp; 	/* multicast group associated */
107275970Scy    vifi_t		mfcc_parent;	/* incoming vif	*/
108275970Scy    uint_t		mfcc_pkt_cnt;	/* pkt count for src-grp	*/
109275970Scy    uchar_t		mfcc_ttls[MAXVIFS]; 	/* forwarding ttls on vifs    */
110275970Scy};
111275970Scy
112275970Scy/*
113275970Scy * The kernel's multicast routing statistics.
114298770Sdelphij */
115298770Sdelphijstruct mrtstat {
116298770Sdelphij    uint_t	mrts_mfcfind_lookups;	/* #forwarding cache table lookups */
117298770Sdelphij    uint_t	mrts_mfcfind_misses;    /* # forwarding cache table misses */
118298770Sdelphij    uint_t	mrts_mfc_hits;		/* forwarding pkt mfctable hits	   */
119298770Sdelphij    uint_t	mrts_mfc_misses;	/* forwarding pkt mfctable misses  */
120298770Sdelphij    uint_t	mrts_upcalls;		/* # calls to mrouted		   */
121298770Sdelphij    uint_t	mrts_fwd_in;		/* # packets potentially forwarded */
122275970Scy    uint_t	mrts_fwd_out;		/* # resulting outgoing packets    */
123275970Scy    uint_t	mrts_fwd_drop;		/* # dropped for lack of resources */
124275970Scy    uint_t	mrts_bad_tunnel;	/* malformed tunnel options	   */
125275970Scy    uint_t	mrts_cant_tunnel;	/* no room for tunnel options	   */
126275970Scy    uint_t	mrts_wrong_if;		/* arrived on wrong interface	   */
127275970Scy    uint_t	mrts_upq_ovflw;		/* upcall Q overflow		   */
128275970Scy    uint_t	mrts_cache_cleanups;	/* # entries with no upcalls	   */
129275970Scy    uint_t	mrts_drop_sel;		/* pkts dropped selectively	   */
130275970Scy    uint_t	mrts_q_overflow;	/* pkts dropped - Q overflow	   */
131275970Scy    uint_t	mrts_pkt2large;		/* pkts dropped - size > BKT SIZE  */
132275970Scy    uint_t	mrts_vifctlSize;	/* Size of vifctl		   */
133275970Scy    uint_t	mrts_mfcctlSize;	/* Size of mfcctl		   */
134275970Scy    uint_t 	mrts_pim_badversion;    /* dtgrms dropped - bad version */
135275970Scy    uint_t 	mrts_pim_rcv_badcsum;   /* dtgrms dropped - bad checksum */
136275970Scy    uint_t 	mrts_pim_badregisters;  /* dtgrms dropped - bad register pkts */
137275970Scy    uint_t 	mrts_pim_regforwards;   /* dtgrms to be forwd - register pkts */
138275970Scy    uint_t 	mrts_pim_regsend_drops; /* dtgrms dropped - register send */
139275970Scy    uint_t	mrts_pim_malformed;	/* dtgrms dropped - packet malformed */
140275970Scy    uint_t	mrts_pim_nomemory;	/* dtgrms dropped - no memory to fwd. */
141275970Scy};
142275970Scy
143275970Scy/*
144275970Scy * Argument structure used by mrouted to get src-grp pkt counts
145275970Scy */
146275970Scystruct sioc_sg_req {
147275970Scy    struct in_addr src;
148275970Scy    struct in_addr grp;
149275970Scy    uint_t pktcnt;
150275970Scy    uint_t bytecnt;
151275970Scy    uint_t wrong_if;
152275970Scy};
153275970Scy
154275970Scy/*
155275970Scy * Argument structure used by mrouted to get vif pkt counts
156298770Sdelphij */
157275970Scystruct sioc_vif_req {
158275970Scy    vifi_t	vifi;		/* vif number				*/
159275970Scy    uint_t	icount;		/* Input packet count on vif		*/
160275970Scy    uint_t	ocount;		/* Output packet count on vif		*/
161275970Scy    uint_t	ibytes;		/* Input byte count on vif		*/
162275970Scy    uint_t	obytes;		/* Output byte count on vif		*/
163275970Scy};
164298770Sdelphij
165298770Sdelphij#ifdef _KERNEL
166275970Scy/*
167275970Scy * The kernel's virtual-interface structure.
168275970Scy */
169275970Scystruct vif {
170275970Scy	uchar_t		v_flags;	/* VIFF_ flags defined above	*/
171275970Scy	uchar_t		v_threshold;	/* Min ttl required to forward on vif */
172275970Scy	uint_t		v_rate_limit;	/* Max rate, in kbits/sec	*/
173298770Sdelphij	struct tbf	*v_tbf;		/* Token bkt structure at intf.	*/
174275970Scy	struct in_addr	v_lcl_addr;	/* Local interface address	*/
175275970Scy	struct in_addr	v_rmt_addr;	/* Remote address(tunnels only)	*/
176275970Scy	struct ipif_s 	*v_ipif;	/* Pointer to logical interface	*/
177275970Scy	uint_t		v_pkt_in;	/* # Pkts in on interface	*/
178275970Scy	uint_t		v_pkt_out;	/* # Pkts out on interface	*/
179275970Scy	uint_t		v_bytes_in;	/* # Bytes in on interface	*/
180275970Scy	uint_t		v_bytes_out;	/* # Bytes out on interface	*/
181275970Scy	timeout_id_t	v_timeout_id;	/* Qtimeout return id	*/
182275970Scy	/*
183275970Scy	 * struct route	v_route;	Cached route if this is a tunnel
184275970Scy	 *				Used in bsd for performance
185275970Scy	 */
186275970Scy	uint_t			v_refcnt;
187275970Scy	uchar_t 		v_marks;
188275970Scy	kmutex_t		v_lock;
189275970Scy	ilm_t			*v_ilm;	/* allmulti join */
190275970Scy};
191275970Scy
192275970Scy/*
193275970Scy * vif is not being used. However if refcnt != 0 than its being initalized.
194275970Scy */
195275970Scy#define	VIF_MARK_NOTINUSE	0x0	/* see comment above */
196275970Scy
197275970Scy#define	VIF_MARK_CONDEMNED	0x1	/* delete when refcnt goes to zero. */
198275970Scy
199275970Scy#define	VIF_MARK_GOOD		0x2	/* vif is good */
200275970Scy
201275970Scy#define	VIF_MARK_INUSE		VIF_MARK_CONDEMNED | VIF_MARK_GOOD
202275970Scy
203275970Scy/*
204275970Scy * The kernel's multicast forwarding cache entry structure
205275970Scy * (A field for the type of service (mfc_tos) is to be added
206275970Scy * at a future point)
207275970Scy */
208275970Scystruct mfc {
209275970Scy    struct in_addr	mfc_origin;	/* ip origin of mcasts	*/
210275970Scy    struct in_addr  	mfc_mcastgrp;	/* multicast group associated */
211275970Scy    vifi_t		mfc_parent;	/* incoming vif	*/
212275970Scy    uchar_t		mfc_ttls[MAXVIFS];	/* forwarding ttls on vifs    */
213275970Scy    uint_t		mfc_pkt_cnt;	/* pkt count for src-grp	*/
214275970Scy    uint_t		mfc_byte_cnt;	/* byte count for src-grp	*/
215275970Scy    uint_t		mfc_wrong_if;	/* wrong if for src-grp	*/
216275970Scy    struct timespec  	mfc_last_assert;	/* last time I sent an assert */
217275970Scy    struct rtdetq	*mfc_rte;	/* pending upcall	*/
218275970Scy    timeout_id_t	mfc_timeout_id;	/* qtimeout return id	*/
219275970Scy    struct mfc		*mfc_next;
220275970Scy    uchar_t 		mfc_marks;
221275970Scy    kmutex_t		mfc_mutex;	/* protects fields and rte list */
222275970Scy};
223275970Scy
224275970Scy/*
225275970Scy * mfc bucket structure.
226275970Scy */
227275970Scystruct mfcb {
228275970Scy    struct mfc  *mfcb_mfc;	/* first mfc in this bucket */
229275970Scy    kmutex_t	mfcb_lock;
230275970Scy    uint_t	mfcb_refcnt;	/* protected by mfcb_lock */
231275970Scy    uchar_t	mfcb_marks;	/* protected by mfcb_lock */
232275970Scy};
233275970Scy
234275970Scy#define	MFCB_MARK_CONDEMNED	0x1
235275970Scy
236275970Scy/*
237275970Scy * Argument structure used for pkt info. while upcall is made
238275970Scy */
239275970Scystruct rtdetq {
240275970Scy    mblk_t		*mp;		/*  A copy of the packet	*/
241275970Scy    ill_t		*ill;		/*  Interface pkt came in on	*/
242275970Scy    struct rtdetq	*rte_next;
243275970Scy};
244275970Scy#endif
245275970Scy
246275970Scy/*
247275970Scy * Struct used to communicate from kernel to multicast router
248275970Scy * note the convenient similarity to an IP packet
249275970Scy */
250275970Scystruct igmpmsg {
251275970Scy    uint_t	    unused1;
252275970Scy    uint_t	    unused2;
253275970Scy    uchar_t	    im_msgtype;			/* what type of message	    */
254275970Scy#define	IGMPMSG_NOCACHE		1
255275970Scy#define	IGMPMSG_WRONGVIF	2
256275970Scy#define	IGMPMSG_WHOLEPKT	3
257275970Scy    uchar_t	    im_mbz;			/* must be zero		    */
258275970Scy    uchar_t	    im_vif;			/* vif rec'd on		    */
259275970Scy    uchar_t	    unused3;
260275970Scy    struct in_addr  im_src, im_dst;
261275970Scy};
262275970Scy
263275970Scy#ifdef _KERNEL
264275970Scy#define	MFCTBLSIZ	256
265275970Scy#if (MFCTBLSIZ & (MFCTBLSIZ - 1)) == 0	  /* from sys:route.h */
266275970Scy#define	MFCHASHMOD(h)	((h) & (MFCTBLSIZ - 1))
267275970Scy#else
268275970Scy#define	MFCHASHMOD(h)	((h) % MFCTBLSIZ)
269275970Scy#endif
270275970Scy
271275970Scy#define	MAX_UPQ	4		/* max. no of pkts in upcall Q */
272275970Scy
273275970Scy/*
274275970Scy * Token Bucket filter code
275275970Scy */
276275970Scy#define	MAX_BKT_SIZE	10000		/* 10K bytes size 		*/
277275970Scy#define	MAXQSIZE	10		/* max # of pkts in queue 	*/
278275970Scy#define	TOKEN_SIZE	8		/* number of bits in token	*/
279275970Scy
280275970Scy/*
281275970Scy * The token bucket filter at each vif
282275970Scy */
283275970Scystruct tbf {
284275970Scy    timespec_t 		tbf_last_pkt_t; /* arr. time of last pkt 	*/
285275970Scy    uint_t 		tbf_n_tok;	/* no of tokens in bucket 	*/
286275970Scy    uint_t 		tbf_q_len;    	/* length of queue at this vif	*/
287275970Scy    uint_t 		tbf_max_q_len;  /* max queue length		*/
288275970Scy    mblk_t		*tbf_q;		/* Packet queue	*/
289275970Scy    mblk_t		*tbf_t;		/* Tail-insertion pointer	*/
290275970Scy    kmutex_t 		tbf_lock;	/* lock on the tbf		*/
291275970Scy};
292275970Scy
293275970Scy#endif /* _KERNEL */
294275970Scy
295275970Scy#ifdef	__cplusplus
296275970Scy}
297275970Scy#endif
298275970Scy
299298770Sdelphij#endif	/* _NETINET_IP_MROUTE_H */
300298770Sdelphij