]>
Commit | Line | Data |
---|---|---|
6853f21f YM |
1 | /* Linux multicast routing support |
2 | * Common logic shared by IPv4 [ipmr] and IPv6 [ip6mr] implementation | |
3 | */ | |
4 | ||
5 | #include <linux/mroute_base.h> | |
6 | ||
7 | /* Sets everything common except 'dev', since that is done under locking */ | |
8 | void vif_device_init(struct vif_device *v, | |
9 | struct net_device *dev, | |
10 | unsigned long rate_limit, | |
11 | unsigned char threshold, | |
12 | unsigned short flags, | |
13 | unsigned short get_iflink_mask) | |
14 | { | |
15 | v->dev = NULL; | |
16 | v->bytes_in = 0; | |
17 | v->bytes_out = 0; | |
18 | v->pkt_in = 0; | |
19 | v->pkt_out = 0; | |
20 | v->rate_limit = rate_limit; | |
21 | v->flags = flags; | |
22 | v->threshold = threshold; | |
23 | if (v->flags & get_iflink_mask) | |
24 | v->link = dev_get_iflink(dev); | |
25 | else | |
26 | v->link = dev->ifindex; | |
27 | } | |
28 | EXPORT_SYMBOL(vif_device_init); | |
0bbbf0e7 YM |
29 | |
30 | struct mr_table * | |
31 | mr_table_alloc(struct net *net, u32 id, | |
845c9a7a | 32 | struct mr_table_ops *ops, |
0bbbf0e7 YM |
33 | void (*expire_func)(struct timer_list *t), |
34 | void (*table_set)(struct mr_table *mrt, | |
35 | struct net *net)) | |
36 | { | |
37 | struct mr_table *mrt; | |
38 | ||
39 | mrt = kzalloc(sizeof(*mrt), GFP_KERNEL); | |
40 | if (!mrt) | |
41 | return NULL; | |
42 | mrt->id = id; | |
43 | write_pnet(&mrt->net, net); | |
44 | ||
845c9a7a YM |
45 | mrt->ops = *ops; |
46 | rhltable_init(&mrt->mfc_hash, mrt->ops.rht_params); | |
0bbbf0e7 YM |
47 | INIT_LIST_HEAD(&mrt->mfc_cache_list); |
48 | INIT_LIST_HEAD(&mrt->mfc_unres_queue); | |
49 | ||
50 | timer_setup(&mrt->ipmr_expire_timer, expire_func, 0); | |
51 | ||
52 | mrt->mroute_reg_vif_num = -1; | |
53 | table_set(mrt, net); | |
54 | return mrt; | |
55 | } | |
56 | EXPORT_SYMBOL(mr_table_alloc); | |
845c9a7a YM |
57 | |
58 | void *mr_mfc_find_parent(struct mr_table *mrt, void *hasharg, int parent) | |
59 | { | |
60 | struct rhlist_head *tmp, *list; | |
61 | struct mr_mfc *c; | |
62 | ||
63 | list = rhltable_lookup(&mrt->mfc_hash, hasharg, *mrt->ops.rht_params); | |
64 | rhl_for_each_entry_rcu(c, tmp, list, mnode) | |
65 | if (parent == -1 || parent == c->mfc_parent) | |
66 | return c; | |
67 | ||
68 | return NULL; | |
69 | } | |
70 | EXPORT_SYMBOL(mr_mfc_find_parent); | |
71 | ||
72 | void *mr_mfc_find_any_parent(struct mr_table *mrt, int vifi) | |
73 | { | |
74 | struct rhlist_head *tmp, *list; | |
75 | struct mr_mfc *c; | |
76 | ||
77 | list = rhltable_lookup(&mrt->mfc_hash, mrt->ops.cmparg_any, | |
78 | *mrt->ops.rht_params); | |
79 | rhl_for_each_entry_rcu(c, tmp, list, mnode) | |
80 | if (c->mfc_un.res.ttls[vifi] < 255) | |
81 | return c; | |
82 | ||
83 | return NULL; | |
84 | } | |
85 | EXPORT_SYMBOL(mr_mfc_find_any_parent); | |
86 | ||
87 | void *mr_mfc_find_any(struct mr_table *mrt, int vifi, void *hasharg) | |
88 | { | |
89 | struct rhlist_head *tmp, *list; | |
90 | struct mr_mfc *c, *proxy; | |
91 | ||
92 | list = rhltable_lookup(&mrt->mfc_hash, hasharg, *mrt->ops.rht_params); | |
93 | rhl_for_each_entry_rcu(c, tmp, list, mnode) { | |
94 | if (c->mfc_un.res.ttls[vifi] < 255) | |
95 | return c; | |
96 | ||
97 | /* It's ok if the vifi is part of the static tree */ | |
98 | proxy = mr_mfc_find_any_parent(mrt, c->mfc_parent); | |
99 | if (proxy && proxy->mfc_un.res.ttls[vifi] < 255) | |
100 | return c; | |
101 | } | |
102 | ||
103 | return mr_mfc_find_any_parent(mrt, vifi); | |
104 | } | |
105 | EXPORT_SYMBOL(mr_mfc_find_any); | |
c8d61968 YM |
106 | |
107 | #ifdef CONFIG_PROC_FS | |
3feda6b4 YM |
108 | void *mr_vif_seq_idx(struct net *net, struct mr_vif_iter *iter, loff_t pos) |
109 | { | |
110 | struct mr_table *mrt = iter->mrt; | |
111 | ||
112 | for (iter->ct = 0; iter->ct < mrt->maxvif; ++iter->ct) { | |
113 | if (!VIF_EXISTS(mrt, iter->ct)) | |
114 | continue; | |
115 | if (pos-- == 0) | |
116 | return &mrt->vif_table[iter->ct]; | |
117 | } | |
118 | return NULL; | |
119 | } | |
120 | EXPORT_SYMBOL(mr_vif_seq_idx); | |
121 | ||
122 | void *mr_vif_seq_next(struct seq_file *seq, void *v, loff_t *pos) | |
123 | { | |
124 | struct mr_vif_iter *iter = seq->private; | |
125 | struct net *net = seq_file_net(seq); | |
126 | struct mr_table *mrt = iter->mrt; | |
127 | ||
128 | ++*pos; | |
129 | if (v == SEQ_START_TOKEN) | |
130 | return mr_vif_seq_idx(net, iter, 0); | |
131 | ||
132 | while (++iter->ct < mrt->maxvif) { | |
133 | if (!VIF_EXISTS(mrt, iter->ct)) | |
134 | continue; | |
135 | return &mrt->vif_table[iter->ct]; | |
136 | } | |
137 | return NULL; | |
138 | } | |
139 | EXPORT_SYMBOL(mr_vif_seq_next); | |
140 | ||
c8d61968 YM |
141 | void *mr_mfc_seq_idx(struct net *net, |
142 | struct mr_mfc_iter *it, loff_t pos) | |
143 | { | |
144 | struct mr_table *mrt = it->mrt; | |
145 | struct mr_mfc *mfc; | |
146 | ||
147 | rcu_read_lock(); | |
148 | it->cache = &mrt->mfc_cache_list; | |
149 | list_for_each_entry_rcu(mfc, &mrt->mfc_cache_list, list) | |
150 | if (pos-- == 0) | |
151 | return mfc; | |
152 | rcu_read_unlock(); | |
153 | ||
154 | spin_lock_bh(it->lock); | |
155 | it->cache = &mrt->mfc_unres_queue; | |
156 | list_for_each_entry(mfc, it->cache, list) | |
157 | if (pos-- == 0) | |
158 | return mfc; | |
159 | spin_unlock_bh(it->lock); | |
160 | ||
161 | it->cache = NULL; | |
162 | return NULL; | |
163 | } | |
164 | EXPORT_SYMBOL(mr_mfc_seq_idx); | |
165 | ||
166 | void *mr_mfc_seq_next(struct seq_file *seq, void *v, | |
167 | loff_t *pos) | |
168 | { | |
169 | struct mr_mfc_iter *it = seq->private; | |
170 | struct net *net = seq_file_net(seq); | |
171 | struct mr_table *mrt = it->mrt; | |
172 | struct mr_mfc *c = v; | |
173 | ||
174 | ++*pos; | |
175 | ||
176 | if (v == SEQ_START_TOKEN) | |
177 | return mr_mfc_seq_idx(net, seq->private, 0); | |
178 | ||
179 | if (c->list.next != it->cache) | |
180 | return list_entry(c->list.next, struct mr_mfc, list); | |
181 | ||
182 | if (it->cache == &mrt->mfc_unres_queue) | |
183 | goto end_of_list; | |
184 | ||
185 | /* exhausted cache_array, show unresolved */ | |
186 | rcu_read_unlock(); | |
187 | it->cache = &mrt->mfc_unres_queue; | |
188 | ||
189 | spin_lock_bh(it->lock); | |
190 | if (!list_empty(it->cache)) | |
191 | return list_first_entry(it->cache, struct mr_mfc, list); | |
192 | ||
193 | end_of_list: | |
194 | spin_unlock_bh(it->lock); | |
195 | it->cache = NULL; | |
196 | ||
197 | return NULL; | |
198 | } | |
199 | EXPORT_SYMBOL(mr_mfc_seq_next); | |
200 | #endif |