Skip to content

Commit a64efe1

Browse files
dsaherndavem330
authored andcommitted
net/ipv6: introduce fib6_info struct and helpers
Add fib6_info struct and alloc, destroy, hold and release helpers. Signed-off-by: David Ahern <dsahern@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 23fb93a commit a64efe1

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

include/net/ip6_fib.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#endif
3939

4040
struct rt6_info;
41+
struct fib6_info;
4142

4243
struct fib6_config {
4344
u32 fc_table;
@@ -132,6 +133,46 @@ struct fib6_nh {
132133
int nh_weight;
133134
};
134135

136+
struct fib6_info {
137+
struct fib6_table *rt6i_table;
138+
struct fib6_info __rcu *rt6_next;
139+
struct fib6_node __rcu *rt6i_node;
140+
141+
/* Multipath routes:
142+
* siblings is a list of fib6_info that have the the same metric/weight,
143+
* destination, but not the same gateway. nsiblings is just a cache
144+
* to speed up lookup.
145+
*/
146+
struct list_head rt6i_siblings;
147+
unsigned int rt6i_nsiblings;
148+
149+
atomic_t rt6i_ref;
150+
struct inet6_dev *rt6i_idev;
151+
unsigned long expires;
152+
struct dst_metrics *fib6_metrics;
153+
#define fib6_pmtu fib6_metrics->metrics[RTAX_MTU-1]
154+
155+
struct rt6key rt6i_dst;
156+
u32 rt6i_flags;
157+
struct rt6key rt6i_src;
158+
struct rt6key rt6i_prefsrc;
159+
160+
struct rt6_info * __percpu *rt6i_pcpu;
161+
struct rt6_exception_bucket __rcu *rt6i_exception_bucket;
162+
163+
u32 rt6i_metric;
164+
u8 rt6i_protocol;
165+
u8 fib6_type;
166+
u8 exception_bucket_flushed:1,
167+
should_flush:1,
168+
dst_nocount:1,
169+
dst_nopolicy:1,
170+
dst_host:1,
171+
unused:3;
172+
173+
struct fib6_nh fib6_nh;
174+
};
175+
135176
struct rt6_info {
136177
struct dst_entry dst;
137178
struct rt6_info __rcu *rt6_next;
@@ -291,6 +332,20 @@ static inline void ip6_rt_put(struct rt6_info *rt)
291332

292333
void rt6_free_pcpu(struct rt6_info *non_pcpu_rt);
293334

335+
struct rt6_info *fib6_info_alloc(gfp_t gfp_flags);
336+
void fib6_info_destroy(struct rt6_info *f6i);
337+
338+
static inline void fib6_info_hold(struct rt6_info *f6i)
339+
{
340+
atomic_inc(&f6i->rt6i_ref);
341+
}
342+
343+
static inline void fib6_info_release(struct rt6_info *f6i)
344+
{
345+
if (f6i && atomic_dec_and_test(&f6i->rt6i_ref))
346+
fib6_info_destroy(f6i);
347+
}
348+
294349
static inline void rt6_hold(struct rt6_info *rt)
295350
{
296351
atomic_inc(&rt->rt6i_ref);

net/ipv6/ip6_fib.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,66 @@ static __be32 addr_bit_set(const void *token, int fn_bit)
145145
addr[fn_bit >> 5];
146146
}
147147

148+
struct rt6_info *fib6_info_alloc(gfp_t gfp_flags)
149+
{
150+
struct rt6_info *f6i;
151+
152+
f6i = kzalloc(sizeof(*f6i), gfp_flags);
153+
if (!f6i)
154+
return NULL;
155+
156+
f6i->rt6i_pcpu = alloc_percpu_gfp(struct rt6_info *, gfp_flags);
157+
if (!f6i->rt6i_pcpu) {
158+
kfree(f6i);
159+
return NULL;
160+
}
161+
162+
INIT_LIST_HEAD(&f6i->rt6i_siblings);
163+
f6i->fib6_metrics = (struct dst_metrics *)&dst_default_metrics;
164+
165+
atomic_inc(&f6i->rt6i_ref);
166+
167+
return f6i;
168+
}
169+
170+
void fib6_info_destroy(struct rt6_info *f6i)
171+
{
172+
struct rt6_exception_bucket *bucket;
173+
174+
WARN_ON(f6i->rt6i_node);
175+
176+
bucket = rcu_dereference_protected(f6i->rt6i_exception_bucket, 1);
177+
if (bucket) {
178+
f6i->rt6i_exception_bucket = NULL;
179+
kfree(bucket);
180+
}
181+
182+
if (f6i->rt6i_pcpu) {
183+
int cpu;
184+
185+
for_each_possible_cpu(cpu) {
186+
struct rt6_info **ppcpu_rt;
187+
struct rt6_info *pcpu_rt;
188+
189+
ppcpu_rt = per_cpu_ptr(f6i->rt6i_pcpu, cpu);
190+
pcpu_rt = *ppcpu_rt;
191+
if (pcpu_rt) {
192+
dst_dev_put(&pcpu_rt->dst);
193+
dst_release(&pcpu_rt->dst);
194+
*ppcpu_rt = NULL;
195+
}
196+
}
197+
}
198+
199+
if (f6i->rt6i_idev)
200+
in6_dev_put(f6i->rt6i_idev);
201+
if (f6i->fib6_nh.nh_dev)
202+
dev_put(f6i->fib6_nh.nh_dev);
203+
204+
kfree(f6i);
205+
}
206+
EXPORT_SYMBOL_GPL(fib6_info_destroy);
207+
148208
static struct fib6_node *node_alloc(struct net *net)
149209
{
150210
struct fib6_node *fn;

0 commit comments

Comments
 (0)