ipmr, ip6mr: Unite logic for searching in MFC cache
[linux-block.git] / include / linux / mroute_base.h
CommitLineData
6853f21f
YM
1#ifndef __LINUX_MROUTE_BASE_H
2#define __LINUX_MROUTE_BASE_H
3
4#include <linux/netdevice.h>
b70432f7
YM
5#include <linux/rhashtable.h>
6#include <net/net_namespace.h>
7#include <net/sock.h>
6853f21f
YM
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 */
24struct 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
b70432f7
YM
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
494fff56
YM
47/**
48 * struct mr_mfc - common multicast routing entries
49 * @mnode: rhashtable list
50 * @mfc_parent: source interface (iif)
51 * @mfc_flags: entry flags
52 * @expires: unresolved entry expire time
53 * @unresolved: unresolved cached skbs
54 * @last_assert: time of last assert
55 * @minvif: minimum VIF id
56 * @maxvif: maximum VIF id
57 * @bytes: bytes that have passed for this entry
58 * @pkt: packets that have passed for this entry
59 * @wrong_if: number of wrong source interface hits
60 * @lastuse: time of last use of the group (traffic or update)
61 * @ttls: OIF TTL threshold array
62 * @refcount: reference count for this entry
63 * @list: global entry list
64 * @rcu: used for entry destruction
65 */
66struct mr_mfc {
67 struct rhlist_head mnode;
68 unsigned short mfc_parent;
69 int mfc_flags;
70
71 union {
72 struct {
73 unsigned long expires;
74 struct sk_buff_head unresolved;
75 } unres;
76 struct {
77 unsigned long last_assert;
78 int minvif;
79 int maxvif;
80 unsigned long bytes;
81 unsigned long pkt;
82 unsigned long wrong_if;
83 unsigned long lastuse;
84 unsigned char ttls[MAXVIFS];
85 refcount_t refcount;
86 } res;
87 } mfc_un;
88 struct list_head list;
89 struct rcu_head rcu;
90};
91
845c9a7a
YM
92struct mr_table;
93
94/**
95 * struct mr_table_ops - callbacks and info for protocol-specific ops
96 * @rht_params: parameters for accessing the MFC hash
97 * @cmparg_any: a hash key to be used for matching on (*,*) routes
98 */
99struct mr_table_ops {
100 const struct rhashtable_params *rht_params;
101 void *cmparg_any;
102};
103
b70432f7
YM
104/**
105 * struct mr_table - a multicast routing table
106 * @list: entry within a list of multicast routing tables
107 * @net: net where this table belongs
845c9a7a 108 * @ops: protocol specific operations
b70432f7
YM
109 * @id: identifier of the table
110 * @mroute_sk: socket associated with the table
111 * @ipmr_expire_timer: timer for handling unresolved routes
112 * @mfc_unres_queue: list of unresolved MFC entries
113 * @vif_table: array containing all possible vifs
114 * @mfc_hash: Hash table of all resolved routes for easy lookup
115 * @mfc_cache_list: list of resovled routes for possible traversal
116 * @maxvif: Identifier of highest value vif currently in use
117 * @cache_resolve_queue_len: current size of unresolved queue
118 * @mroute_do_assert: Whether to inform userspace on wrong ingress
119 * @mroute_do_pim: Whether to receive IGMP PIMv1
120 * @mroute_reg_vif_num: PIM-device vif index
121 */
122struct mr_table {
123 struct list_head list;
124 possible_net_t net;
845c9a7a 125 struct mr_table_ops ops;
b70432f7
YM
126 u32 id;
127 struct sock __rcu *mroute_sk;
128 struct timer_list ipmr_expire_timer;
129 struct list_head mfc_unres_queue;
130 struct vif_device vif_table[MAXVIFS];
131 struct rhltable mfc_hash;
132 struct list_head mfc_cache_list;
133 int maxvif;
134 atomic_t cache_resolve_queue_len;
135 bool mroute_do_assert;
136 bool mroute_do_pim;
137 int mroute_reg_vif_num;
138};
139
6853f21f
YM
140#ifdef CONFIG_IP_MROUTE_COMMON
141void vif_device_init(struct vif_device *v,
142 struct net_device *dev,
143 unsigned long rate_limit,
144 unsigned char threshold,
145 unsigned short flags,
146 unsigned short get_iflink_mask);
0bbbf0e7
YM
147
148struct mr_table *
149mr_table_alloc(struct net *net, u32 id,
845c9a7a 150 struct mr_table_ops *ops,
0bbbf0e7
YM
151 void (*expire_func)(struct timer_list *t),
152 void (*table_set)(struct mr_table *mrt,
153 struct net *net));
845c9a7a
YM
154
155/* These actually return 'struct mr_mfc *', but to avoid need for explicit
156 * castings they simply return void.
157 */
158void *mr_mfc_find_parent(struct mr_table *mrt,
159 void *hasharg, int parent);
160void *mr_mfc_find_any_parent(struct mr_table *mrt, int vifi);
161void *mr_mfc_find_any(struct mr_table *mrt, int vifi, void *hasharg);
162
6853f21f
YM
163#else
164static inline void vif_device_init(struct vif_device *v,
165 struct net_device *dev,
166 unsigned long rate_limit,
167 unsigned char threshold,
168 unsigned short flags,
169 unsigned short get_iflink_mask)
170{
171}
0bbbf0e7 172
845c9a7a 173static inline void *
0bbbf0e7 174mr_table_alloc(struct net *net, u32 id,
845c9a7a 175 struct mr_table_ops *ops,
0bbbf0e7
YM
176 void (*expire_func)(struct timer_list *t),
177 void (*table_set)(struct mr_table *mrt,
178 struct net *net))
179{
180 return NULL;
181}
845c9a7a
YM
182
183static inline void *mr_mfc_find_parent(struct mr_table *mrt,
184 void *hasharg, int parent)
185{
186 return NULL;
187}
188
189static inline void *mr_mfc_find_any_parent(struct mr_table *mrt,
190 int vifi)
191{
192 return NULL;
193}
194
195static inline struct mr_mfc *mr_mfc_find_any(struct mr_table *mrt,
196 int vifi, void *hasharg)
197{
198 return NULL;
199}
6853f21f 200#endif
845c9a7a
YM
201
202static inline void *mr_mfc_find(struct mr_table *mrt, void *hasharg)
203{
204 return mr_mfc_find_parent(mrt, hasharg, -1);
205}
6853f21f 206#endif