1 #ifndef __LINUX_MROUTE_BASE_H
2 #define __LINUX_MROUTE_BASE_H
4 #include <linux/netdevice.h>
5 #include <linux/rhashtable-types.h>
6 #include <linux/spinlock.h>
7 #include <net/net_namespace.h>
9 #include <net/fib_notifier.h>
10 #include <net/ip_fib.h>
13 * struct vif_device - interface representor for multicast routing
14 * @dev: network device being used
15 * @bytes_in: statistic; bytes ingressing
16 * @bytes_out: statistic; bytes egresing
17 * @pkt_in: statistic; packets ingressing
18 * @pkt_out: statistic; packets egressing
19 * @rate_limit: Traffic shaping (NI)
20 * @threshold: TTL threshold
21 * @flags: Control flags
22 * @link: Physical interface index
23 * @dev_parent_id: device parent id
24 * @local: Local address
25 * @remote: Remote address for tunnels
28 struct net_device
*dev
;
29 unsigned long bytes_in
, bytes_out
;
30 unsigned long pkt_in
, pkt_out
;
31 unsigned long rate_limit
;
32 unsigned char threshold
;
36 /* Currently only used by ipmr */
37 struct netdev_phys_item_id dev_parent_id
;
41 struct vif_entry_notifier_info
{
42 struct fib_notifier_info info
;
43 struct net_device
*dev
;
44 unsigned short vif_index
;
45 unsigned short vif_flags
;
49 static inline int mr_call_vif_notifier(struct notifier_block
*nb
,
51 unsigned short family
,
52 enum fib_event_type event_type
,
53 struct vif_device
*vif
,
54 unsigned short vif_index
, u32 tb_id
)
56 struct vif_entry_notifier_info info
= {
62 .vif_index
= vif_index
,
63 .vif_flags
= vif
->flags
,
67 return call_fib_notifier(nb
, net
, event_type
, &info
.info
);
70 static inline int mr_call_vif_notifiers(struct net
*net
,
71 unsigned short family
,
72 enum fib_event_type event_type
,
73 struct vif_device
*vif
,
74 unsigned short vif_index
, u32 tb_id
,
75 unsigned int *ipmr_seq
)
77 struct vif_entry_notifier_info info
= {
83 .vif_index
= vif_index
,
84 .vif_flags
= vif
->flags
,
90 return call_fib_notifiers(net
, event_type
, &info
.info
);
94 /* This one is nasty; value is defined in uapi using different symbols for
95 * mroute and morute6 but both map into same 32.
100 #define VIF_EXISTS(_mrt, _idx) (!!((_mrt)->vif_table[_idx].dev))
103 * MFC_STATIC - the entry was added statically (not by a routing daemon)
104 * MFC_OFFLOAD - the entry was offloaded to the hardware
108 MFC_OFFLOAD
= BIT(1),
112 * struct mr_mfc - common multicast routing entries
113 * @mnode: rhashtable list
114 * @mfc_parent: source interface (iif)
115 * @mfc_flags: entry flags
116 * @expires: unresolved entry expire time
117 * @unresolved: unresolved cached skbs
118 * @last_assert: time of last assert
119 * @minvif: minimum VIF id
120 * @maxvif: maximum VIF id
121 * @bytes: bytes that have passed for this entry
122 * @pkt: packets that have passed for this entry
123 * @wrong_if: number of wrong source interface hits
124 * @lastuse: time of last use of the group (traffic or update)
125 * @ttls: OIF TTL threshold array
126 * @refcount: reference count for this entry
127 * @list: global entry list
128 * @rcu: used for entry destruction
129 * @free: Operation used for freeing an entry under RCU
132 struct rhlist_head mnode
;
133 unsigned short mfc_parent
;
138 unsigned long expires
;
139 struct sk_buff_head unresolved
;
142 unsigned long last_assert
;
147 unsigned long wrong_if
;
148 unsigned long lastuse
;
149 unsigned char ttls
[MAXVIFS
];
153 struct list_head list
;
155 void (*free
)(struct rcu_head
*head
);
158 static inline void mr_cache_put(struct mr_mfc
*c
)
160 if (refcount_dec_and_test(&c
->mfc_un
.res
.refcount
))
161 call_rcu(&c
->rcu
, c
->free
);
164 static inline void mr_cache_hold(struct mr_mfc
*c
)
166 refcount_inc(&c
->mfc_un
.res
.refcount
);
169 struct mfc_entry_notifier_info
{
170 struct fib_notifier_info info
;
175 static inline int mr_call_mfc_notifier(struct notifier_block
*nb
,
177 unsigned short family
,
178 enum fib_event_type event_type
,
179 struct mr_mfc
*mfc
, u32 tb_id
)
181 struct mfc_entry_notifier_info info
= {
190 return call_fib_notifier(nb
, net
, event_type
, &info
.info
);
193 static inline int mr_call_mfc_notifiers(struct net
*net
,
194 unsigned short family
,
195 enum fib_event_type event_type
,
196 struct mr_mfc
*mfc
, u32 tb_id
,
197 unsigned int *ipmr_seq
)
199 struct mfc_entry_notifier_info info
= {
210 return call_fib_notifiers(net
, event_type
, &info
.info
);
216 * struct mr_table_ops - callbacks and info for protocol-specific ops
217 * @rht_params: parameters for accessing the MFC hash
218 * @cmparg_any: a hash key to be used for matching on (*,*) routes
220 struct mr_table_ops
{
221 const struct rhashtable_params
*rht_params
;
226 * struct mr_table - a multicast routing table
227 * @list: entry within a list of multicast routing tables
228 * @net: net where this table belongs
229 * @ops: protocol specific operations
230 * @id: identifier of the table
231 * @mroute_sk: socket associated with the table
232 * @ipmr_expire_timer: timer for handling unresolved routes
233 * @mfc_unres_queue: list of unresolved MFC entries
234 * @vif_table: array containing all possible vifs
235 * @mfc_hash: Hash table of all resolved routes for easy lookup
236 * @mfc_cache_list: list of resovled routes for possible traversal
237 * @maxvif: Identifier of highest value vif currently in use
238 * @cache_resolve_queue_len: current size of unresolved queue
239 * @mroute_do_assert: Whether to inform userspace on wrong ingress
240 * @mroute_do_pim: Whether to receive IGMP PIMv1
241 * @mroute_reg_vif_num: PIM-device vif index
244 struct list_head list
;
246 struct mr_table_ops ops
;
248 struct sock __rcu
*mroute_sk
;
249 struct timer_list ipmr_expire_timer
;
250 struct list_head mfc_unres_queue
;
251 struct vif_device vif_table
[MAXVIFS
];
252 struct rhltable mfc_hash
;
253 struct list_head mfc_cache_list
;
255 atomic_t cache_resolve_queue_len
;
256 bool mroute_do_assert
;
258 bool mroute_do_wrvifwhole
;
259 int mroute_reg_vif_num
;
262 #ifdef CONFIG_IP_MROUTE_COMMON
263 void vif_device_init(struct vif_device
*v
,
264 struct net_device
*dev
,
265 unsigned long rate_limit
,
266 unsigned char threshold
,
267 unsigned short flags
,
268 unsigned short get_iflink_mask
);
271 mr_table_alloc(struct net
*net
, u32 id
,
272 struct mr_table_ops
*ops
,
273 void (*expire_func
)(struct timer_list
*t
),
274 void (*table_set
)(struct mr_table
*mrt
,
277 /* These actually return 'struct mr_mfc *', but to avoid need for explicit
278 * castings they simply return void.
280 void *mr_mfc_find_parent(struct mr_table
*mrt
,
281 void *hasharg
, int parent
);
282 void *mr_mfc_find_any_parent(struct mr_table
*mrt
, int vifi
);
283 void *mr_mfc_find_any(struct mr_table
*mrt
, int vifi
, void *hasharg
);
285 int mr_fill_mroute(struct mr_table
*mrt
, struct sk_buff
*skb
,
286 struct mr_mfc
*c
, struct rtmsg
*rtm
);
287 int mr_table_dump(struct mr_table
*mrt
, struct sk_buff
*skb
,
288 struct netlink_callback
*cb
,
289 int (*fill
)(struct mr_table
*mrt
, struct sk_buff
*skb
,
290 u32 portid
, u32 seq
, struct mr_mfc
*c
,
292 spinlock_t
*lock
, struct fib_dump_filter
*filter
);
293 int mr_rtm_dumproute(struct sk_buff
*skb
, struct netlink_callback
*cb
,
294 struct mr_table
*(*iter
)(struct net
*net
,
295 struct mr_table
*mrt
),
296 int (*fill
)(struct mr_table
*mrt
,
298 u32 portid
, u32 seq
, struct mr_mfc
*c
,
300 spinlock_t
*lock
, struct fib_dump_filter
*filter
);
302 int mr_dump(struct net
*net
, struct notifier_block
*nb
, unsigned short family
,
303 int (*rules_dump
)(struct net
*net
,
304 struct notifier_block
*nb
),
305 struct mr_table
*(*mr_iter
)(struct net
*net
,
306 struct mr_table
*mrt
),
309 static inline void vif_device_init(struct vif_device
*v
,
310 struct net_device
*dev
,
311 unsigned long rate_limit
,
312 unsigned char threshold
,
313 unsigned short flags
,
314 unsigned short get_iflink_mask
)
318 static inline void *mr_mfc_find_parent(struct mr_table
*mrt
,
319 void *hasharg
, int parent
)
324 static inline void *mr_mfc_find_any_parent(struct mr_table
*mrt
,
330 static inline struct mr_mfc
*mr_mfc_find_any(struct mr_table
*mrt
,
331 int vifi
, void *hasharg
)
336 static inline int mr_fill_mroute(struct mr_table
*mrt
, struct sk_buff
*skb
,
337 struct mr_mfc
*c
, struct rtmsg
*rtm
)
343 mr_rtm_dumproute(struct sk_buff
*skb
, struct netlink_callback
*cb
,
344 struct mr_table
*(*iter
)(struct net
*net
,
345 struct mr_table
*mrt
),
346 int (*fill
)(struct mr_table
*mrt
,
348 u32 portid
, u32 seq
, struct mr_mfc
*c
,
350 spinlock_t
*lock
, struct fib_dump_filter
*filter
)
355 static inline int mr_dump(struct net
*net
, struct notifier_block
*nb
,
356 unsigned short family
,
357 int (*rules_dump
)(struct net
*net
,
358 struct notifier_block
*nb
),
359 struct mr_table
*(*mr_iter
)(struct net
*net
,
360 struct mr_table
*mrt
),
367 static inline void *mr_mfc_find(struct mr_table
*mrt
, void *hasharg
)
369 return mr_mfc_find_parent(mrt
, hasharg
, -1);
372 #ifdef CONFIG_PROC_FS
374 struct seq_net_private p
;
375 struct mr_table
*mrt
;
380 struct seq_net_private p
;
381 struct mr_table
*mrt
;
382 struct list_head
*cache
;
384 /* Lock protecting the mr_table's unresolved queue */
388 #ifdef CONFIG_IP_MROUTE_COMMON
389 void *mr_vif_seq_idx(struct net
*net
, struct mr_vif_iter
*iter
, loff_t pos
);
390 void *mr_vif_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
);
392 static inline void *mr_vif_seq_start(struct seq_file
*seq
, loff_t
*pos
)
394 return *pos
? mr_vif_seq_idx(seq_file_net(seq
),
395 seq
->private, *pos
- 1)
399 /* These actually return 'struct mr_mfc *', but to avoid need for explicit
400 * castings they simply return void.
402 void *mr_mfc_seq_idx(struct net
*net
,
403 struct mr_mfc_iter
*it
, loff_t pos
);
404 void *mr_mfc_seq_next(struct seq_file
*seq
, void *v
,
407 static inline void *mr_mfc_seq_start(struct seq_file
*seq
, loff_t
*pos
,
408 struct mr_table
*mrt
, spinlock_t
*lock
)
410 struct mr_mfc_iter
*it
= seq
->private;
416 return *pos
? mr_mfc_seq_idx(seq_file_net(seq
),
417 seq
->private, *pos
- 1)
421 static inline void mr_mfc_seq_stop(struct seq_file
*seq
, void *v
)
423 struct mr_mfc_iter
*it
= seq
->private;
424 struct mr_table
*mrt
= it
->mrt
;
426 if (it
->cache
== &mrt
->mfc_unres_queue
)
427 spin_unlock_bh(it
->lock
);
428 else if (it
->cache
== &mrt
->mfc_cache_list
)
432 static inline void *mr_vif_seq_idx(struct net
*net
, struct mr_vif_iter
*iter
,
438 static inline void *mr_vif_seq_next(struct seq_file
*seq
,
439 void *v
, loff_t
*pos
)
444 static inline void *mr_vif_seq_start(struct seq_file
*seq
, loff_t
*pos
)
449 static inline void *mr_mfc_seq_idx(struct net
*net
,
450 struct mr_mfc_iter
*it
, loff_t pos
)
455 static inline void *mr_mfc_seq_next(struct seq_file
*seq
, void *v
,
461 static inline void *mr_mfc_seq_start(struct seq_file
*seq
, loff_t
*pos
,
462 struct mr_table
*mrt
, spinlock_t
*lock
)
467 static inline void mr_mfc_seq_stop(struct seq_file
*seq
, void *v
)