Skip to content

Commit faa041a

Browse files
dsaherndavem330
authored andcommitted
ipv4: Create cleanup helper for fib_nh
Move the fib_nh cleanup code from free_fib_info_rcu into a new helper, fib_nh_release. Move classid accounting into fib_nh_release which is called per fib_nh to make accounting symmetrical with fib_nh_init. Export the helper to allow for use with nexthop objects in the future. Signed-off-by: David Ahern <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e4516ef commit faa041a

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

include/net/ip_fib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ void fib_select_path(struct net *net, struct fib_result *res,
419419
int fib_nh_init(struct net *net, struct fib_nh *fib_nh,
420420
struct fib_config *cfg, int nh_weight,
421421
struct netlink_ext_ack *extack);
422+
void fib_nh_release(struct net *net, struct fib_nh *fib_nh);
422423

423424
/* Exported by fib_trie.c */
424425
void fib_trie_init(void);

net/ipv4/fib_semantics.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,18 +204,28 @@ static void rt_fibinfo_free_cpus(struct rtable __rcu * __percpu *rtp)
204204
free_percpu(rtp);
205205
}
206206

207+
void fib_nh_release(struct net *net, struct fib_nh *fib_nh)
208+
{
209+
#ifdef CONFIG_IP_ROUTE_CLASSID
210+
if (fib_nh->nh_tclassid)
211+
net->ipv4.fib_num_tclassid_users--;
212+
#endif
213+
if (fib_nh->nh_dev)
214+
dev_put(fib_nh->nh_dev);
215+
216+
lwtstate_put(fib_nh->nh_lwtstate);
217+
free_nh_exceptions(fib_nh);
218+
rt_fibinfo_free_cpus(fib_nh->nh_pcpu_rth_output);
219+
rt_fibinfo_free(&fib_nh->nh_rth_input);
220+
}
221+
207222
/* Release a nexthop info record */
208223
static void free_fib_info_rcu(struct rcu_head *head)
209224
{
210225
struct fib_info *fi = container_of(head, struct fib_info, rcu);
211226

212227
change_nexthops(fi) {
213-
if (nexthop_nh->nh_dev)
214-
dev_put(nexthop_nh->nh_dev);
215-
lwtstate_put(nexthop_nh->nh_lwtstate);
216-
free_nh_exceptions(nexthop_nh);
217-
rt_fibinfo_free_cpus(nexthop_nh->nh_pcpu_rth_output);
218-
rt_fibinfo_free(&nexthop_nh->nh_rth_input);
228+
fib_nh_release(fi->fib_net, nexthop_nh);
219229
} endfor_nexthops(fi);
220230

221231
ip_fib_metrics_put(fi->fib_metrics);
@@ -230,12 +240,7 @@ void free_fib_info(struct fib_info *fi)
230240
return;
231241
}
232242
fib_info_cnt--;
233-
#ifdef CONFIG_IP_ROUTE_CLASSID
234-
change_nexthops(fi) {
235-
if (nexthop_nh->nh_tclassid)
236-
fi->fib_net->ipv4.fib_num_tclassid_users--;
237-
} endfor_nexthops(fi);
238-
#endif
243+
239244
call_rcu(&fi->rcu, free_fib_info_rcu);
240245
}
241246
EXPORT_SYMBOL_GPL(free_fib_info);

0 commit comments

Comments
 (0)