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>
12 * struct vif_device - interface representor for multicast routing
13 * @dev: network device being used
14 * @bytes_in: statistic; bytes ingressing
15 * @bytes_out: statistic; bytes egresing
16 * @pkt_in: statistic; packets ingressing
17 * @pkt_out: statistic; packets egressing
18 * @rate_limit: Traffic shaping (NI)
19 * @threshold: TTL threshold
20 * @flags: Control flags
21 * @link: Physical interface index
22 * @dev_parent_id: device parent id
23 * @local: Local address
24 * @remote: Remote address for tunnels
27 struct net_device *dev;
28 unsigned long bytes_in, bytes_out;
29 unsigned long pkt_in, pkt_out;
30 unsigned long rate_limit;
31 unsigned char threshold;
35 /* Currently only used by ipmr */
36 struct netdev_phys_item_id dev_parent_id;
40 struct vif_entry_notifier_info {
41 struct fib_notifier_info info;
42 struct net_device *dev;
43 unsigned short vif_index;
44 unsigned short vif_flags;
48 static inline int mr_call_vif_notifier(struct notifier_block *nb,
50 unsigned short family,
51 enum fib_event_type event_type,
52 struct vif_device *vif,
53 unsigned short vif_index, u32 tb_id)
55 struct vif_entry_notifier_info info = {
61 .vif_index = vif_index,
62 .vif_flags = vif->flags,
66 return call_fib_notifier(nb, net, event_type, &info.info);
69 static inline int mr_call_vif_notifiers(struct net *net,
70 unsigned short family,
71 enum fib_event_type event_type,
72 struct vif_device *vif,
73 unsigned short vif_index, u32 tb_id,
74 unsigned int *ipmr_seq)
76 struct vif_entry_notifier_info info = {
82 .vif_index = vif_index,
83 .vif_flags = vif->flags,
89 return call_fib_notifiers(net, event_type, &info.info);
93 /* This one is nasty; value is defined in uapi using different symbols for
94 * mroute and morute6 but both map into same 32.
99 #define VIF_EXISTS(_mrt, _idx) (!!((_mrt)->vif_table[_idx].dev))
102 * MFC_STATIC - the entry was added statically (not by a routing daemon)
103 * MFC_OFFLOAD - the entry was offloaded to the hardware
107 MFC_OFFLOAD = BIT(1),
111 * struct mr_mfc - common multicast routing entries
112 * @mnode: rhashtable list
113 * @mfc_parent: source interface (iif)
114 * @mfc_flags: entry flags
115 * @expires: unresolved entry expire time
116 * @unresolved: unresolved cached skbs
117 * @last_assert: time of last assert
118 * @minvif: minimum VIF id
119 * @maxvif: maximum VIF id
120 * @bytes: bytes that have passed for this entry
121 * @pkt: packets that have passed for this entry
122 * @wrong_if: number of wrong source interface hits
123 * @lastuse: time of last use of the group (traffic or update)
124 * @ttls: OIF TTL threshold array
125 * @refcount: reference count for this entry
126 * @list: global entry list
127 * @rcu: used for entry destruction
128 * @free: Operation used for freeing an entry under RCU
131 struct rhlist_head mnode;
132 unsigned short mfc_parent;
137 unsigned long expires;
138 struct sk_buff_head unresolved;
141 unsigned long last_assert;
146 unsigned long wrong_if;
147 unsigned long lastuse;
148 unsigned char ttls[MAXVIFS];
152 struct list_head list;
154 void (*free)(struct rcu_head *head);
157 static inline void mr_cache_put(struct mr_mfc *c)
159 if (refcount_dec_and_test(&c->mfc_un.res.refcount))
160 call_rcu(&c->rcu, c->free);
163 static inline void mr_cache_hold(struct mr_mfc *c)
165 refcount_inc(&c->mfc_un.res.refcount);
168 struct mfc_entry_notifier_info {
169 struct fib_notifier_info info;
174 static inline int mr_call_mfc_notifier(struct notifier_block *nb,
176 unsigned short family,
177 enum fib_event_type event_type,
178 struct mr_mfc *mfc, u32 tb_id)
180 struct mfc_entry_notifier_info info = {
189 return call_fib_notifier(nb, net, event_type, &info.info);
192 static inline int mr_call_mfc_notifiers(struct net *net,
193 unsigned short family,
194 enum fib_event_type event_type,
195 struct mr_mfc *mfc, u32 tb_id,
196 unsigned int *ipmr_seq)
198 struct mfc_entry_notifier_info info = {
209 return call_fib_notifiers(net, event_type, &info.info);
215 * struct mr_table_ops - callbacks and info for protocol-specific ops
216 * @rht_params: parameters for accessing the MFC hash
217 * @cmparg_any: a hash key to be used for matching on (*,*) routes
219 struct mr_table_ops {
220 const struct rhashtable_params *rht_params;
225 * struct mr_table - a multicast routing table
226 * @list: entry within a list of multicast routing tables
227 * @net: net where this table belongs
228 * @ops: protocol specific operations
229 * @id: identifier of the table
230 * @mroute_sk: socket associated with the table
231 * @ipmr_expire_timer: timer for handling unresolved routes
232 * @mfc_unres_queue: list of unresolved MFC entries
233 * @vif_table: array containing all possible vifs
234 * @mfc_hash: Hash table of all resolved routes for easy lookup
235 * @mfc_cache_list: list of resovled routes for possible traversal
236 * @maxvif: Identifier of highest value vif currently in use
237 * @cache_resolve_queue_len: current size of unresolved queue
238 * @mroute_do_assert: Whether to inform userspace on wrong ingress
239 * @mroute_do_pim: Whether to receive IGMP PIMv1
240 * @mroute_reg_vif_num: PIM-device vif index
243 struct list_head list;
245 struct mr_table_ops ops;
247 struct sock __rcu *mroute_sk;
248 struct timer_list ipmr_expire_timer;
249 struct list_head mfc_unres_queue;
250 struct vif_device vif_table[MAXVIFS];
251 struct rhltable mfc_hash;
252 struct list_head mfc_cache_list;
254 atomic_t cache_resolve_queue_len;
255 bool mroute_do_assert;
257 bool mroute_do_wrvifwhole;
258 int mroute_reg_vif_num;
261 #ifdef CONFIG_IP_MROUTE_COMMON
262 void vif_device_init(struct vif_device *v,
263 struct net_device *dev,
264 unsigned long rate_limit,
265 unsigned char threshold,
266 unsigned short flags,
267 unsigned short get_iflink_mask);
270 mr_table_alloc(struct net *net, u32 id,
271 struct mr_table_ops *ops,
272 void (*expire_func)(struct timer_list *t),
273 void (*table_set)(struct mr_table *mrt,
276 /* These actually return 'struct mr_mfc *', but to avoid need for explicit
277 * castings they simply return void.
279 void *mr_mfc_find_parent(struct mr_table *mrt,
280 void *hasharg, int parent);
281 void *mr_mfc_find_any_parent(struct mr_table *mrt, int vifi);
282 void *mr_mfc_find_any(struct mr_table *mrt, int vifi, void *hasharg);
284 int mr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb,
285 struct mr_mfc *c, struct rtmsg *rtm);
286 int mr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb,
287 struct mr_table *(*iter)(struct net *net,
288 struct mr_table *mrt),
289 int (*fill)(struct mr_table *mrt,
291 u32 portid, u32 seq, struct mr_mfc *c,
295 int mr_dump(struct net *net, struct notifier_block *nb, unsigned short family,
296 int (*rules_dump)(struct net *net,
297 struct notifier_block *nb),
298 struct mr_table *(*mr_iter)(struct net *net,
299 struct mr_table *mrt),
302 static inline void vif_device_init(struct vif_device *v,
303 struct net_device *dev,
304 unsigned long rate_limit,
305 unsigned char threshold,
306 unsigned short flags,
307 unsigned short get_iflink_mask)
311 static inline void *mr_mfc_find_parent(struct mr_table *mrt,
312 void *hasharg, int parent)
317 static inline void *mr_mfc_find_any_parent(struct mr_table *mrt,
323 static inline struct mr_mfc *mr_mfc_find_any(struct mr_table *mrt,
324 int vifi, void *hasharg)
329 static inline int mr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb,
330 struct mr_mfc *c, struct rtmsg *rtm)
336 mr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb,
337 struct mr_table *(*iter)(struct net *net,
338 struct mr_table *mrt),
339 int (*fill)(struct mr_table *mrt,
341 u32 portid, u32 seq, struct mr_mfc *c,
348 static inline int mr_dump(struct net *net, struct notifier_block *nb,
349 unsigned short family,
350 int (*rules_dump)(struct net *net,
351 struct notifier_block *nb),
352 struct mr_table *(*mr_iter)(struct net *net,
353 struct mr_table *mrt),
360 static inline void *mr_mfc_find(struct mr_table *mrt, void *hasharg)
362 return mr_mfc_find_parent(mrt, hasharg, -1);
365 #ifdef CONFIG_PROC_FS
367 struct seq_net_private p;
368 struct mr_table *mrt;
373 struct seq_net_private p;
374 struct mr_table *mrt;
375 struct list_head *cache;
377 /* Lock protecting the mr_table's unresolved queue */
381 #ifdef CONFIG_IP_MROUTE_COMMON
382 void *mr_vif_seq_idx(struct net *net, struct mr_vif_iter *iter, loff_t pos);
383 void *mr_vif_seq_next(struct seq_file *seq, void *v, loff_t *pos);
385 static inline void *mr_vif_seq_start(struct seq_file *seq, loff_t *pos)
387 return *pos ? mr_vif_seq_idx(seq_file_net(seq),
388 seq->private, *pos - 1)
392 /* These actually return 'struct mr_mfc *', but to avoid need for explicit
393 * castings they simply return void.
395 void *mr_mfc_seq_idx(struct net *net,
396 struct mr_mfc_iter *it, loff_t pos);
397 void *mr_mfc_seq_next(struct seq_file *seq, void *v,
400 static inline void *mr_mfc_seq_start(struct seq_file *seq, loff_t *pos,
401 struct mr_table *mrt, spinlock_t *lock)
403 struct mr_mfc_iter *it = seq->private;
409 return *pos ? mr_mfc_seq_idx(seq_file_net(seq),
410 seq->private, *pos - 1)
414 static inline void mr_mfc_seq_stop(struct seq_file *seq, void *v)
416 struct mr_mfc_iter *it = seq->private;
417 struct mr_table *mrt = it->mrt;
419 if (it->cache == &mrt->mfc_unres_queue)
420 spin_unlock_bh(it->lock);
421 else if (it->cache == &mrt->mfc_cache_list)
425 static inline void *mr_vif_seq_idx(struct net *net, struct mr_vif_iter *iter,
431 static inline void *mr_vif_seq_next(struct seq_file *seq,
432 void *v, loff_t *pos)
437 static inline void *mr_vif_seq_start(struct seq_file *seq, loff_t *pos)
442 static inline void *mr_mfc_seq_idx(struct net *net,
443 struct mr_mfc_iter *it, loff_t pos)
448 static inline void *mr_mfc_seq_next(struct seq_file *seq, void *v,
454 static inline void *mr_mfc_seq_start(struct seq_file *seq, loff_t *pos,
455 struct mr_table *mrt, spinlock_t *lock)
460 static inline void mr_mfc_seq_stop(struct seq_file *seq, void *v)