1 #ifndef __LINUX_MROUTE_H
2 #define __LINUX_MROUTE_H
3 
4 #include <linux/sockios.h>
5 #include <linux/types.h>
6 #ifdef __KERNEL__
7 #include <linux/in.h>
8 #endif
9 
10 /*
11  *	Based on the MROUTING 3.5 defines primarily to keep
12  *	source compatibility with BSD.
13  *
14  *	See the mrouted code for the original history.
15  *
16  *      Protocol Independent Multicast (PIM) data structures included
17  *      Carlos Picoto (cap@di.fc.ul.pt)
18  *
19  */
20 
21 #define MRT_BASE	200
22 #define MRT_INIT	(MRT_BASE)	/* Activate the kernel mroute code 	*/
23 #define MRT_DONE	(MRT_BASE+1)	/* Shutdown the kernel mroute		*/
24 #define MRT_ADD_VIF	(MRT_BASE+2)	/* Add a virtual interface		*/
25 #define MRT_DEL_VIF	(MRT_BASE+3)	/* Delete a virtual interface		*/
26 #define MRT_ADD_MFC	(MRT_BASE+4)	/* Add a multicast forwarding entry	*/
27 #define MRT_DEL_MFC	(MRT_BASE+5)	/* Delete a multicast forwarding entry	*/
28 #define MRT_VERSION	(MRT_BASE+6)	/* Get the kernel multicast version	*/
29 #define MRT_ASSERT	(MRT_BASE+7)	/* Activate PIM assert mode		*/
30 #define MRT_PIM		(MRT_BASE+8)	/* enable PIM code			*/
31 #define MRT_TABLE	(MRT_BASE+9)	/* Specify mroute table ID		*/
32 
33 #define SIOCGETVIFCNT	SIOCPROTOPRIVATE	/* IP protocol privates */
34 #define SIOCGETSGCNT	(SIOCPROTOPRIVATE+1)
35 #define SIOCGETRPF	(SIOCPROTOPRIVATE+2)
36 
37 #define MAXVIFS		32
38 typedef unsigned long vifbitmap_t;	/* User mode code depends on this lot */
39 typedef unsigned short vifi_t;
40 #define ALL_VIFS	((vifi_t)(-1))
41 
42 /*
43  *	Same idea as select
44  */
45 
46 #define VIFM_SET(n,m)	((m)|=(1<<(n)))
47 #define VIFM_CLR(n,m)	((m)&=~(1<<(n)))
48 #define VIFM_ISSET(n,m)	((m)&(1<<(n)))
49 #define VIFM_CLRALL(m)	((m)=0)
50 #define VIFM_COPY(mfrom,mto)	((mto)=(mfrom))
51 #define VIFM_SAME(m1,m2)	((m1)==(m2))
52 
53 /*
54  *	Passed by mrouted for an MRT_ADD_VIF - again we use the
55  *	mrouted 3.6 structures for compatibility
56  */
57 
58 struct vifctl {
59 	vifi_t	vifc_vifi;		/* Index of VIF */
60 	unsigned char vifc_flags;	/* VIFF_ flags */
61 	unsigned char vifc_threshold;	/* ttl limit */
62 	unsigned int vifc_rate_limit;	/* Rate limiter values (NI) */
63 	union {
64 		struct in_addr vifc_lcl_addr;     /* Local interface address */
65 		int            vifc_lcl_ifindex;  /* Local interface index   */
66 	};
67 	struct in_addr vifc_rmt_addr;	/* IPIP tunnel addr */
68 };
69 
70 #define VIFF_TUNNEL		0x1	/* IPIP tunnel */
71 #define VIFF_SRCRT		0x2	/* NI */
72 #define VIFF_REGISTER		0x4	/* register vif	*/
73 #define VIFF_USE_IFINDEX	0x8	/* use vifc_lcl_ifindex instead of
74 					   vifc_lcl_addr to find an interface */
75 
76 /*
77  *	Cache manipulation structures for mrouted and PIMd
78  */
79 
80 struct mfcctl {
81 	struct in_addr mfcc_origin;		/* Origin of mcast	*/
82 	struct in_addr mfcc_mcastgrp;		/* Group in question	*/
83 	vifi_t	mfcc_parent;			/* Where it arrived	*/
84 	unsigned char mfcc_ttls[MAXVIFS];	/* Where it is going	*/
85 	unsigned int mfcc_pkt_cnt;		/* pkt count for src-grp */
86 	unsigned int mfcc_byte_cnt;
87 	unsigned int mfcc_wrong_if;
88 	int	     mfcc_expire;
89 };
90 
91 /*
92  *	Group count retrieval for mrouted
93  */
94 
95 struct sioc_sg_req {
96 	struct in_addr src;
97 	struct in_addr grp;
98 	unsigned long pktcnt;
99 	unsigned long bytecnt;
100 	unsigned long wrong_if;
101 };
102 
103 /*
104  *	To get vif packet counts
105  */
106 
107 struct sioc_vif_req {
108 	vifi_t	vifi;		/* Which iface */
109 	unsigned long icount;	/* In packets */
110 	unsigned long ocount;	/* Out packets */
111 	unsigned long ibytes;	/* In bytes */
112 	unsigned long obytes;	/* Out bytes */
113 };
114 
115 /*
116  *	This is the format the mroute daemon expects to see IGMP control
117  *	data. Magically happens to be like an IP packet as per the original
118  */
119 
120 struct igmpmsg {
121 	__u32 unused1,unused2;
122 	unsigned char im_msgtype;		/* What is this */
123 	unsigned char im_mbz;			/* Must be zero */
124 	unsigned char im_vif;			/* Interface (this ought to be a vifi_t!) */
125 	unsigned char unused3;
126 	struct in_addr im_src,im_dst;
127 };
128 
129 /*
130  *	That's all usermode folks
131  */
132 
133 #ifdef __KERNEL__
134 #include <linux/pim.h>
135 #include <net/sock.h>
136 
137 #ifdef CONFIG_IP_MROUTE
ip_mroute_opt(int opt)138 static inline int ip_mroute_opt(int opt)
139 {
140 	return (opt >= MRT_BASE) && (opt <= MRT_BASE + 10);
141 }
142 #else
ip_mroute_opt(int opt)143 static inline int ip_mroute_opt(int opt)
144 {
145 	return 0;
146 }
147 #endif
148 
149 #ifdef CONFIG_IP_MROUTE
150 extern int ip_mroute_setsockopt(struct sock *, int, char __user *, unsigned int);
151 extern int ip_mroute_getsockopt(struct sock *, int, char __user *, int __user *);
152 extern int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg);
153 extern int ipmr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
154 extern int ip_mr_init(void);
155 #else
156 static inline
ip_mroute_setsockopt(struct sock * sock,int optname,char __user * optval,unsigned int optlen)157 int ip_mroute_setsockopt(struct sock *sock,
158 			 int optname, char __user *optval, unsigned int optlen)
159 {
160 	return -ENOPROTOOPT;
161 }
162 
163 static inline
ip_mroute_getsockopt(struct sock * sock,int optname,char __user * optval,int __user * optlen)164 int ip_mroute_getsockopt(struct sock *sock,
165 			 int optname, char __user *optval, int __user *optlen)
166 {
167 	return -ENOPROTOOPT;
168 }
169 
170 static inline
ipmr_ioctl(struct sock * sk,int cmd,void __user * arg)171 int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg)
172 {
173 	return -ENOIOCTLCMD;
174 }
175 
ip_mr_init(void)176 static inline int ip_mr_init(void)
177 {
178 	return 0;
179 }
180 #endif
181 
182 struct vif_device {
183 	struct net_device 	*dev;			/* Device we are using */
184 	unsigned long	bytes_in,bytes_out;
185 	unsigned long	pkt_in,pkt_out;		/* Statistics 			*/
186 	unsigned long	rate_limit;		/* Traffic shaping (NI) 	*/
187 	unsigned char	threshold;		/* TTL threshold 		*/
188 	unsigned short	flags;			/* Control flags 		*/
189 	__be32		local,remote;		/* Addresses(remote for tunnels)*/
190 	int		link;			/* Physical interface index	*/
191 };
192 
193 #define VIFF_STATIC 0x8000
194 
195 struct mfc_cache {
196 	struct list_head list;
197 	__be32 mfc_mcastgrp;			/* Group the entry belongs to 	*/
198 	__be32 mfc_origin;			/* Source of packet 		*/
199 	vifi_t mfc_parent;			/* Source interface		*/
200 	int mfc_flags;				/* Flags on line		*/
201 
202 	union {
203 		struct {
204 			unsigned long expires;
205 			struct sk_buff_head unresolved;	/* Unresolved buffers		*/
206 		} unres;
207 		struct {
208 			unsigned long last_assert;
209 			int minvif;
210 			int maxvif;
211 			unsigned long bytes;
212 			unsigned long pkt;
213 			unsigned long wrong_if;
214 			unsigned char ttls[MAXVIFS];	/* TTL thresholds		*/
215 		} res;
216 	} mfc_un;
217 	struct rcu_head	rcu;
218 };
219 
220 #define MFC_STATIC		1
221 #define MFC_NOTIFY		2
222 
223 #define MFC_LINES		64
224 
225 #ifdef __BIG_ENDIAN
226 #define MFC_HASH(a,b)	(((((__force u32)(__be32)a)>>24)^(((__force u32)(__be32)b)>>26))&(MFC_LINES-1))
227 #else
228 #define MFC_HASH(a,b)	((((__force u32)(__be32)a)^(((__force u32)(__be32)b)>>2))&(MFC_LINES-1))
229 #endif
230 
231 #endif
232 
233 
234 #define MFC_ASSERT_THRESH (3*HZ)		/* Maximal freq. of asserts */
235 
236 /*
237  *	Pseudo messages used by mrouted
238  */
239 
240 #define IGMPMSG_NOCACHE		1		/* Kern cache fill request to mrouted */
241 #define IGMPMSG_WRONGVIF	2		/* For PIM assert processing (unused) */
242 #define IGMPMSG_WHOLEPKT	3		/* For PIM Register processing */
243 
244 #ifdef __KERNEL__
245 struct rtmsg;
246 extern int ipmr_get_route(struct net *net, struct sk_buff *skb,
247 			  struct rtmsg *rtm, int nowait);
248 #endif
249 
250 #endif
251