1 /*	$OpenBSD: ip_mroute.h,v 1.9 2002/06/09 16:26:10 itojun Exp $	*/
2 /*	$NetBSD: ip_mroute.h,v 1.10 1996/02/13 23:42:55 christos 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  *
15  * MROUTING Revision: 1.2
16  */
17 
18 #include <sys/queue.h>
19 
20 /*
21  * Multicast Routing set/getsockopt commands.
22  */
23 #define	MRT_INIT		100	/* initialize forwarder */
24 #define	MRT_DONE		101	/* shut down forwarder */
25 #define	MRT_ADD_VIF		102	/* create virtual interface */
26 #define	MRT_DEL_VIF		103	/* delete virtual interface */
27 #define	MRT_ADD_MFC		104	/* insert forwarding cache entry */
28 #define	MRT_DEL_MFC		105	/* delete forwarding cache entry */
29 #define	MRT_VERSION		106	/* get kernel version number */
30 #define	MRT_ASSERT		107	/* enable PIM assert processing */
31 
32 
33 /*
34  * Types and macros for handling bitmaps with one bit per virtual interface.
35  */
36 #define	MAXVIFS 32
37 typedef u_int32_t vifbitmap_t;
38 typedef u_int16_t vifi_t;		/* type of a vif index */
39 
40 #define	VIFM_SET(n, m)			((m) |= (1 << (n)))
41 #define	VIFM_CLR(n, m)			((m) &= ~(1 << (n)))
42 #define	VIFM_ISSET(n, m)		((m) & (1 << (n)))
43 #define	VIFM_SETALL(m)			((m) = 0xffffffff)
44 #define	VIFM_CLRALL(m)			((m) = 0x00000000)
45 #define	VIFM_COPY(mfrom, mto)		((mto) = (mfrom))
46 #define	VIFM_SAME(m1, m2)		((m1) == (m2))
47 
48 #define	VIFF_TUNNEL	0x1		/* vif represents a tunnel end-point */
49 #define	VIFF_SRCRT	0x2		/* tunnel uses IP src routing */
50 
51 /*
52  * Argument structure for MRT_ADD_VIF.
53  * (MRT_DEL_VIF takes a single vifi_t argument.)
54  */
55 struct vifctl {
56 	vifi_t	  vifc_vifi;	    	/* the index of the vif to be added */
57 	u_int8_t  vifc_flags;     	/* VIFF_ flags defined below */
58 	u_int8_t  vifc_threshold; 	/* min ttl required to forward on vif */
59 	u_int32_t vifc_rate_limit;	/* max rate */
60 	struct	  in_addr vifc_lcl_addr;/* local interface address */
61 	struct	  in_addr vifc_rmt_addr;/* remote address (tunnels only) */
62 };
63 
64 /*
65  * Argument structure for MRT_ADD_MFC and MRT_DEL_MFC.
66  * (mfcc_tos to be added at a future point)
67  */
68 struct mfcctl {
69 	struct	 in_addr mfcc_origin;	/* ip origin of mcasts */
70 	struct	 in_addr mfcc_mcastgrp;	/* multicast group associated */
71 	vifi_t	 mfcc_parent;		/* incoming vif */
72 	u_int8_t mfcc_ttls[MAXVIFS];	/* forwarding ttls on vifs */
73 };
74 
75 /*
76  * Argument structure used by mrouted to get src-grp pkt counts.
77  */
78 struct sioc_sg_req {
79 	struct	in_addr src;
80 	struct	in_addr grp;
81 	u_long	pktcnt;
82 	u_long	bytecnt;
83 	u_long	wrong_if;
84 };
85 
86 /*
87  * Argument structure used by mrouted to get vif pkt counts.
88  */
89 struct sioc_vif_req {
90 	vifi_t	vifi;			/* vif number */
91 	u_long	icount;			/* input packet count on vif */
92 	u_long	ocount;			/* output packet count on vif */
93 	u_long	ibytes;			/* input byte count on vif */
94 	u_long	obytes;			/* output byte count on vif */
95 };
96 
97 
98 /*
99  * The kernel's multicast routing statistics.
100  */
101 struct mrtstat {
102 	u_long	mrts_mfc_lookups;	/* # forw. cache hash table hits */
103 	u_long	mrts_mfc_misses;	/* # forw. cache hash table misses */
104 	u_long	mrts_upcalls;		/* # calls to mrouted */
105 	u_long	mrts_no_route;		/* no route for packet's origin */
106 	u_long	mrts_bad_tunnel;	/* malformed tunnel options */
107 	u_long	mrts_cant_tunnel;	/* no room for tunnel options */
108 	u_long	mrts_wrong_if;		/* arrived on wrong interface */
109 	u_long	mrts_upq_ovflw;		/* upcall Q overflow */
110 	u_long	mrts_cache_cleanups;	/* # entries with no upcalls */
111 	u_long	mrts_drop_sel;     	/* pkts dropped selectively */
112 	u_long	mrts_q_overflow;    	/* pkts dropped - Q overflow */
113 	u_long	mrts_pkt2large;     	/* pkts dropped - size > BKT SIZE */
114 	u_long	mrts_upq_sockfull;	/* upcalls dropped - socket full */
115 };
116 
117 
118 #ifdef _KERNEL
119 
120 /*
121  * Token bucket filter at each vif
122  */
123 struct tbf {
124 	u_int32_t last_pkt_t;		/* arr. time of last pkt */
125 	u_int32_t n_tok;		/* no of tokens in bucket */
126 	u_int32_t q_len;		/* length of queue at this vif */
127 };
128 
129 /*
130  * The kernel's virtual-interface structure.
131  */
132 struct vif {
133 	u_int8_t  v_flags;		/* VIFF_ flags defined above */
134 	u_int8_t  v_threshold;		/* min ttl required to forward on vif */
135 	u_int32_t v_rate_limit;		/* max rate */
136 	struct	  tbf v_tbf;		/* token bucket structure at intf. */
137 	struct	  in_addr v_lcl_addr;	/* local interface address */
138 	struct	  in_addr v_rmt_addr;	/* remote address (tunnels only) */
139 	struct	  ifnet *v_ifp;		/* pointer to interface */
140 	u_long	  v_pkt_in;		/* # pkts in on interface */
141 	u_long	  v_pkt_out;		/* # pkts out on interface */
142 	u_long	  v_bytes_in;		/* # bytes in on interface */
143 	u_long	  v_bytes_out;		/* # bytes out on interface */
144 	struct	  route v_route;	/* cached route if this is a tunnel */
145 #ifdef RSVP_ISI
146 	int	  v_rsvp_on;		/* # RSVP listening on this vif */
147 	struct	  socket *v_rsvpd;	/* # RSVPD daemon */
148 #endif /* RSVP_ISI */
149 };
150 
151 /*
152  * The kernel's multicast forwarding cache entry structure.
153  * (A field for the type of service (mfc_tos) is to be added
154  * at a future point.)
155  */
156 struct mfc {
157 	LIST_ENTRY(mfc) mfc_hash;
158 	struct	 in_addr mfc_origin;	 	/* ip origin of mcasts */
159 	struct	 in_addr mfc_mcastgrp;  	/* multicast group associated */
160 	vifi_t	 mfc_parent;			/* incoming vif */
161 	u_int8_t mfc_ttls[MAXVIFS]; 		/* forwarding ttls on vifs */
162 	u_long	 mfc_pkt_cnt;			/* pkt count for src-grp */
163 	u_long	 mfc_byte_cnt;			/* byte count for src-grp */
164 	u_long	 mfc_wrong_if;			/* wrong if for src-grp	*/
165 	int	 mfc_expire;			/* time to clean entry up */
166 	struct	 timeval mfc_last_assert;	/* last time I sent an assert */
167 	struct	 rtdetq *mfc_stall;		/* pkts waiting for route */
168 };
169 
170 /*
171  * Structure used to communicate from kernel to multicast router.
172  * (Note the convenient similarity to an IP packet.)
173  */
174 struct igmpmsg {
175 	u_int32_t unused1;
176 	u_int32_t unused2;
177 	u_int8_t  im_msgtype;		/* what type of message */
178 #define IGMPMSG_NOCACHE		1
179 #define IGMPMSG_WRONGVIF	2
180 	u_int8_t  im_mbz;		/* must be zero */
181 	u_int8_t  im_vif;		/* vif rec'd on */
182 	u_int8_t  unused3;
183 	struct	  in_addr im_src, im_dst;
184 };
185 
186 /*
187  * Argument structure used for pkt info. while upcall is made.
188  */
189 struct rtdetq {
190 	struct	mbuf *m;		/* a copy of the packet */
191 	struct	ifnet *ifp;		/* interface pkt came in on */
192 #ifdef UPCALL_TIMING
193 	struct	timeval t;		/* timestamp */
194 #endif /* UPCALL_TIMING */
195 	struct	rtdetq *next;
196 };
197 
198 #define	MFCTBLSIZ	256
199 #define	MAX_UPQ		4		/* max. no of pkts in upcall Q */
200 
201 /*
202  * Token bucket filter code
203  */
204 #define	MAX_BKT_SIZE    10000		/* 10K bytes size */
205 #define	MAXQSIZE        10		/* max. no of pkts in token queue */
206 
207 /*
208  * Queue structure at each vif
209  */
210 struct pkt_queue {
211 	u_int32_t pkt_len;		/* length of packet in queue */
212 	struct	  mbuf *pkt_m;		/* pointer to packet mbuf */
213 	struct	  ip *pkt_ip;		/* pointer to ip header */
214 };
215 
216 int	ip_mrouter_set(int, struct socket *, struct mbuf **);
217 int	ip_mrouter_get(int, struct socket *, struct mbuf **);
218 int	mrt_ioctl(u_long, caddr_t);
219 int	ip_mrouter_done(void);
220 void	reset_vif(struct vif *);
221 void	vif_delete(struct ifnet *);
222 #ifdef RSVP_ISI
223 int	ip_mforward(struct mbuf *, struct ifnet *, struct ip_moptions *);
224 int	legal_vif_num(int);
225 int	ip_rsvp_vif_init(struct socket *, struct mbuf *);
226 int	ip_rsvp_vif_done(struct socket *, struct mbuf *);
227 void	ip_rsvp_force_done(struct socket *);
228 void rsvp_input(struct mbuf *, int, int);
229 #else
230 int	ip_mforward(struct mbuf *, struct ifnet *);
231 #endif /* RSVP_ISI */
232 
233 void	ipip_mroute_input(struct mbuf *, ...);
234 
235 #endif /* _KERNEL */
236 #endif /* _NETINET_IP_MROUTE_H_ */
237