xref: /linux-6.15/include/linux/mroute_base.h (revision 0bbbf0e7)
1 #ifndef __LINUX_MROUTE_BASE_H
2 #define __LINUX_MROUTE_BASE_H
3 
4 #include <linux/netdevice.h>
5 #include <linux/rhashtable.h>
6 #include <net/net_namespace.h>
7 #include <net/sock.h>
8 
9 /**
10  * struct vif_device - interface representor for multicast routing
11  * @dev: network device being used
12  * @bytes_in: statistic; bytes ingressing
13  * @bytes_out: statistic; bytes egresing
14  * @pkt_in: statistic; packets ingressing
15  * @pkt_out: statistic; packets egressing
16  * @rate_limit: Traffic shaping (NI)
17  * @threshold: TTL threshold
18  * @flags: Control flags
19  * @link: Physical interface index
20  * @dev_parent_id: device parent id
21  * @local: Local address
22  * @remote: Remote address for tunnels
23  */
24 struct vif_device {
25 	struct net_device *dev;
26 	unsigned long bytes_in, bytes_out;
27 	unsigned long pkt_in, pkt_out;
28 	unsigned long rate_limit;
29 	unsigned char threshold;
30 	unsigned short flags;
31 	int link;
32 
33 	/* Currently only used by ipmr */
34 	struct netdev_phys_item_id dev_parent_id;
35 	__be32 local, remote;
36 };
37 
38 #ifndef MAXVIFS
39 /* This one is nasty; value is defined in uapi using different symbols for
40  * mroute and morute6 but both map into same 32.
41  */
42 #define MAXVIFS	32
43 #endif
44 
45 #define VIF_EXISTS(_mrt, _idx) (!!((_mrt)->vif_table[_idx].dev))
46 
47 /**
48  * struct mr_table - a multicast routing table
49  * @list: entry within a list of multicast routing tables
50  * @net: net where this table belongs
51  * @id: identifier of the table
52  * @mroute_sk: socket associated with the table
53  * @ipmr_expire_timer: timer for handling unresolved routes
54  * @mfc_unres_queue: list of unresolved MFC entries
55  * @vif_table: array containing all possible vifs
56  * @mfc_hash: Hash table of all resolved routes for easy lookup
57  * @mfc_cache_list: list of resovled routes for possible traversal
58  * @maxvif: Identifier of highest value vif currently in use
59  * @cache_resolve_queue_len: current size of unresolved queue
60  * @mroute_do_assert: Whether to inform userspace on wrong ingress
61  * @mroute_do_pim: Whether to receive IGMP PIMv1
62  * @mroute_reg_vif_num: PIM-device vif index
63  */
64 struct mr_table {
65 	struct list_head	list;
66 	possible_net_t		net;
67 	u32			id;
68 	struct sock __rcu	*mroute_sk;
69 	struct timer_list	ipmr_expire_timer;
70 	struct list_head	mfc_unres_queue;
71 	struct vif_device	vif_table[MAXVIFS];
72 	struct rhltable		mfc_hash;
73 	struct list_head	mfc_cache_list;
74 	int			maxvif;
75 	atomic_t		cache_resolve_queue_len;
76 	bool			mroute_do_assert;
77 	bool			mroute_do_pim;
78 	int			mroute_reg_vif_num;
79 };
80 
81 #ifdef CONFIG_IP_MROUTE_COMMON
82 void vif_device_init(struct vif_device *v,
83 		     struct net_device *dev,
84 		     unsigned long rate_limit,
85 		     unsigned char threshold,
86 		     unsigned short flags,
87 		     unsigned short get_iflink_mask);
88 
89 struct mr_table *
90 mr_table_alloc(struct net *net, u32 id,
91 	       const struct rhashtable_params *rht_params,
92 	       void (*expire_func)(struct timer_list *t),
93 	       void (*table_set)(struct mr_table *mrt,
94 				 struct net *net));
95 #else
96 static inline void vif_device_init(struct vif_device *v,
97 				   struct net_device *dev,
98 				   unsigned long rate_limit,
99 				   unsigned char threshold,
100 				   unsigned short flags,
101 				   unsigned short get_iflink_mask)
102 {
103 }
104 
105 static inline struct mr_table *
106 mr_table_alloc(struct net *net, u32 id,
107 	       const struct rhashtable_params *rht_params,
108 	       void (*expire_func)(struct timer_list *t),
109 	       void (*table_set)(struct mr_table *mrt,
110 				 struct net *net))
111 {
112 	return NULL;
113 }
114 #endif
115 #endif
116