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 * @dev_tracker: refcount tracker for @dev reference
16 * @bytes_in: statistic; bytes ingressing
17 * @bytes_out: statistic; bytes egresing
18 * @pkt_in: statistic; packets ingressing
19 * @pkt_out: statistic; packets egressing
20 * @rate_limit: Traffic shaping (NI)
21 * @threshold: TTL threshold
22 * @flags: Control flags
23 * @link: Physical interface index
24 * @dev_parent_id: device parent id
25 * @local: Local address
26 * @remote: Remote address for tunnels
29 struct net_device __rcu *dev;
30 netdevice_tracker dev_tracker;
31 unsigned long bytes_in, bytes_out;
32 unsigned long pkt_in, pkt_out;
33 unsigned long rate_limit;
34 unsigned char threshold;
38 /* Currently only used by ipmr */
39 struct netdev_phys_item_id dev_parent_id;
43 struct vif_entry_notifier_info {
44 struct fib_notifier_info info;
45 struct net_device *dev;
46 unsigned short vif_index;
47 unsigned short vif_flags;
51 static inline int mr_call_vif_notifier(struct notifier_block *nb,
52 unsigned short family,
53 enum fib_event_type event_type,
54 struct vif_device *vif,
55 struct net_device *vif_dev,
56 unsigned short vif_index, u32 tb_id,
57 struct netlink_ext_ack *extack)
59 struct vif_entry_notifier_info info = {
65 .vif_index = vif_index,
66 .vif_flags = vif->flags,
70 return call_fib_notifier(nb, event_type, &info.info);
73 static inline int mr_call_vif_notifiers(struct net *net,
74 unsigned short family,
75 enum fib_event_type event_type,
76 struct vif_device *vif,
77 struct net_device *vif_dev,
78 unsigned short vif_index, u32 tb_id,
79 unsigned int *ipmr_seq)
81 struct vif_entry_notifier_info info = {
86 .vif_index = vif_index,
87 .vif_flags = vif->flags,
93 return call_fib_notifiers(net, event_type, &info.info);
97 /* This one is nasty; value is defined in uapi using different symbols for
98 * mroute and morute6 but both map into same 32.
103 /* Note: This helper is deprecated. */
104 #define VIF_EXISTS(_mrt, _idx) (!!rcu_access_pointer((_mrt)->vif_table[_idx].dev))
107 * MFC_STATIC - the entry was added statically (not by a routing daemon)
108 * MFC_OFFLOAD - the entry was offloaded to the hardware
112 MFC_OFFLOAD = BIT(1),
116 * struct mr_mfc - common multicast routing entries
117 * @mnode: rhashtable list
118 * @mfc_parent: source interface (iif)
119 * @mfc_flags: entry flags
120 * @expires: unresolved entry expire time
121 * @unresolved: unresolved cached skbs
122 * @last_assert: time of last assert
123 * @minvif: minimum VIF id
124 * @maxvif: maximum VIF id
125 * @bytes: bytes that have passed for this entry
126 * @pkt: packets that have passed for this entry
127 * @wrong_if: number of wrong source interface hits
128 * @lastuse: time of last use of the group (traffic or update)
129 * @ttls: OIF TTL threshold array
130 * @refcount: reference count for this entry
131 * @list: global entry list
132 * @rcu: used for entry destruction
133 * @free: Operation used for freeing an entry under RCU
136 struct rhlist_head mnode;
137 unsigned short mfc_parent;
142 unsigned long expires;
143 struct sk_buff_head unresolved;
146 unsigned long last_assert;
151 unsigned long wrong_if;
152 unsigned long lastuse;
153 unsigned char ttls[MAXVIFS];
157 struct list_head list;
159 void (*free)(struct rcu_head *head);
162 static inline void mr_cache_put(struct mr_mfc *c)
164 if (refcount_dec_and_test(&c->mfc_un.res.refcount))
165 call_rcu(&c->rcu, c->free);
168 static inline void mr_cache_hold(struct mr_mfc *c)
170 refcount_inc(&c->mfc_un.res.refcount);
173 struct mfc_entry_notifier_info {
174 struct fib_notifier_info info;
179 static inline int mr_call_mfc_notifier(struct notifier_block *nb,
180 unsigned short family,
181 enum fib_event_type event_type,
182 struct mr_mfc *mfc, u32 tb_id,
183 struct netlink_ext_ack *extack)
185 struct mfc_entry_notifier_info info = {
194 return call_fib_notifier(nb, event_type, &info.info);
197 static inline int mr_call_mfc_notifiers(struct net *net,
198 unsigned short family,
199 enum fib_event_type event_type,
200 struct mr_mfc *mfc, u32 tb_id,
201 unsigned int *ipmr_seq)
203 struct mfc_entry_notifier_info info = {
213 return call_fib_notifiers(net, event_type, &info.info);
219 * struct mr_table_ops - callbacks and info for protocol-specific ops
220 * @rht_params: parameters for accessing the MFC hash
221 * @cmparg_any: a hash key to be used for matching on (*,*) routes
223 struct mr_table_ops {
224 const struct rhashtable_params *rht_params;
229 * struct mr_table - a multicast routing table
230 * @list: entry within a list of multicast routing tables
231 * @net: net where this table belongs
232 * @ops: protocol specific operations
233 * @id: identifier of the table
234 * @mroute_sk: socket associated with the table
235 * @ipmr_expire_timer: timer for handling unresolved routes
236 * @mfc_unres_queue: list of unresolved MFC entries
237 * @vif_table: array containing all possible vifs
238 * @mfc_hash: Hash table of all resolved routes for easy lookup
239 * @mfc_cache_list: list of resovled routes for possible traversal
240 * @maxvif: Identifier of highest value vif currently in use
241 * @cache_resolve_queue_len: current size of unresolved queue
242 * @mroute_do_assert: Whether to inform userspace on wrong ingress
243 * @mroute_do_pim: Whether to receive IGMP PIMv1
244 * @mroute_reg_vif_num: PIM-device vif index
247 struct list_head list;
249 struct mr_table_ops ops;
251 struct sock __rcu *mroute_sk;
252 struct timer_list ipmr_expire_timer;
253 struct list_head mfc_unres_queue;
254 struct vif_device vif_table[MAXVIFS];
255 struct rhltable mfc_hash;
256 struct list_head mfc_cache_list;
258 atomic_t cache_resolve_queue_len;
259 bool mroute_do_assert;
261 bool mroute_do_wrvifwhole;
262 int mroute_reg_vif_num;
265 #ifdef CONFIG_IP_MROUTE_COMMON
266 void vif_device_init(struct vif_device *v,
267 struct net_device *dev,
268 unsigned long rate_limit,
269 unsigned char threshold,
270 unsigned short flags,
271 unsigned short get_iflink_mask);
274 mr_table_alloc(struct net *net, u32 id,
275 struct mr_table_ops *ops,
276 void (*expire_func)(struct timer_list *t),
277 void (*table_set)(struct mr_table *mrt,
280 /* These actually return 'struct mr_mfc *', but to avoid need for explicit
281 * castings they simply return void.
283 void *mr_mfc_find_parent(struct mr_table *mrt,
284 void *hasharg, int parent);
285 void *mr_mfc_find_any_parent(struct mr_table *mrt, int vifi);
286 void *mr_mfc_find_any(struct mr_table *mrt, int vifi, void *hasharg);
288 int mr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb,
289 struct mr_mfc *c, struct rtmsg *rtm);
290 int mr_table_dump(struct mr_table *mrt, struct sk_buff *skb,
291 struct netlink_callback *cb,
292 int (*fill)(struct mr_table *mrt, struct sk_buff *skb,
293 u32 portid, u32 seq, struct mr_mfc *c,
295 spinlock_t *lock, struct fib_dump_filter *filter);
296 int mr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb,
297 struct mr_table *(*iter)(struct net *net,
298 struct mr_table *mrt),
299 int (*fill)(struct mr_table *mrt,
301 u32 portid, u32 seq, struct mr_mfc *c,
303 spinlock_t *lock, struct fib_dump_filter *filter);
305 int mr_dump(struct net *net, struct notifier_block *nb, unsigned short family,
306 int (*rules_dump)(struct net *net,
307 struct notifier_block *nb,
308 struct netlink_ext_ack *extack),
309 struct mr_table *(*mr_iter)(struct net *net,
310 struct mr_table *mrt),
311 struct netlink_ext_ack *extack);
313 static inline void vif_device_init(struct vif_device *v,
314 struct net_device *dev,
315 unsigned long rate_limit,
316 unsigned char threshold,
317 unsigned short flags,
318 unsigned short get_iflink_mask)
322 static inline void *mr_mfc_find_parent(struct mr_table *mrt,
323 void *hasharg, int parent)
328 static inline void *mr_mfc_find_any_parent(struct mr_table *mrt,
334 static inline struct mr_mfc *mr_mfc_find_any(struct mr_table *mrt,
335 int vifi, void *hasharg)
340 static inline int mr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb,
341 struct mr_mfc *c, struct rtmsg *rtm)
347 mr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb,
348 struct mr_table *(*iter)(struct net *net,
349 struct mr_table *mrt),
350 int (*fill)(struct mr_table *mrt,
352 u32 portid, u32 seq, struct mr_mfc *c,
354 spinlock_t *lock, struct fib_dump_filter *filter)
359 static inline int mr_dump(struct net *net, struct notifier_block *nb,
360 unsigned short family,
361 int (*rules_dump)(struct net *net,
362 struct notifier_block *nb,
363 struct netlink_ext_ack *extack),
364 struct mr_table *(*mr_iter)(struct net *net,
365 struct mr_table *mrt),
366 struct netlink_ext_ack *extack)
372 static inline void *mr_mfc_find(struct mr_table *mrt, void *hasharg)
374 return mr_mfc_find_parent(mrt, hasharg, -1);
377 #ifdef CONFIG_PROC_FS
379 struct seq_net_private p;
380 struct mr_table *mrt;
385 struct seq_net_private p;
386 struct mr_table *mrt;
387 struct list_head *cache;
389 /* Lock protecting the mr_table's unresolved queue */
393 #ifdef CONFIG_IP_MROUTE_COMMON
394 void *mr_vif_seq_idx(struct net *net, struct mr_vif_iter *iter, loff_t pos);
395 void *mr_vif_seq_next(struct seq_file *seq, void *v, loff_t *pos);
397 static inline void *mr_vif_seq_start(struct seq_file *seq, loff_t *pos)
399 return *pos ? mr_vif_seq_idx(seq_file_net(seq),
400 seq->private, *pos - 1)
404 /* These actually return 'struct mr_mfc *', but to avoid need for explicit
405 * castings they simply return void.
407 void *mr_mfc_seq_idx(struct net *net,
408 struct mr_mfc_iter *it, loff_t pos);
409 void *mr_mfc_seq_next(struct seq_file *seq, void *v,
412 static inline void *mr_mfc_seq_start(struct seq_file *seq, loff_t *pos,
413 struct mr_table *mrt, spinlock_t *lock)
415 struct mr_mfc_iter *it = seq->private;
421 return *pos ? mr_mfc_seq_idx(seq_file_net(seq),
422 seq->private, *pos - 1)
426 static inline void mr_mfc_seq_stop(struct seq_file *seq, void *v)
428 struct mr_mfc_iter *it = seq->private;
429 struct mr_table *mrt = it->mrt;
431 if (it->cache == &mrt->mfc_unres_queue)
432 spin_unlock_bh(it->lock);
433 else if (it->cache == &mrt->mfc_cache_list)
437 static inline void *mr_vif_seq_idx(struct net *net, struct mr_vif_iter *iter,
443 static inline void *mr_vif_seq_next(struct seq_file *seq,
444 void *v, loff_t *pos)
449 static inline void *mr_vif_seq_start(struct seq_file *seq, loff_t *pos)
454 static inline void *mr_mfc_seq_idx(struct net *net,
455 struct mr_mfc_iter *it, loff_t pos)
460 static inline void *mr_mfc_seq_next(struct seq_file *seq, void *v,
466 static inline void *mr_mfc_seq_start(struct seq_file *seq, loff_t *pos,
467 struct mr_table *mrt, spinlock_t *lock)
472 static inline void mr_mfc_seq_stop(struct seq_file *seq, void *v)