net: Move free of fib_metrics to helper
authorDavid Ahern <dsahern@gmail.com>
Fri, 5 Oct 2018 03:07:52 +0000 (20:07 -0700)
committerDavid S. Miller <davem@davemloft.net>
Fri, 5 Oct 2018 04:54:10 +0000 (21:54 -0700)
Move the refcounting and potential free of dst metrics associated
with a fib entry to a helper and use it in both ipv4 and ipv6.

Signed-off-by: David Ahern <dsahern@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/ip.h
net/ipv4/fib_semantics.c
net/ipv6/ip6_fib.c

index 8cbe7e8c9e1e06e347163d077e03b5cb327fc015..8fdd58ce580d6124ded9ba4a9b53b6ceb00a1f70 100644 (file)
@@ -422,6 +422,12 @@ static inline unsigned int ip_skb_dst_mtu(struct sock *sk,
 
 struct dst_metrics *ip_fib_metrics_init(struct net *net, struct nlattr *fc_mx,
                                        int fc_mx_len);
+static inline void ip_fib_metrics_put(struct dst_metrics *fib_metrics)
+{
+       if (fib_metrics != &dst_default_metrics &&
+           refcount_dec_and_test(&fib_metrics->refcnt))
+               kfree(fib_metrics);
+}
 
 u32 ip_idents_reserve(u32 hash, int segs);
 void __ip_select_ident(struct net *net, struct iphdr *iph, int segs);
index e8f4add597edafa4d19b9deab4074d87e10777c0..f8c7ec8171a82820d1bbffb8a211589467d7afec 100644 (file)
@@ -208,7 +208,6 @@ static void rt_fibinfo_free_cpus(struct rtable __rcu * __percpu *rtp)
 static void free_fib_info_rcu(struct rcu_head *head)
 {
        struct fib_info *fi = container_of(head, struct fib_info, rcu);
-       struct dst_metrics *m;
 
        change_nexthops(fi) {
                if (nexthop_nh->nh_dev)
@@ -219,9 +218,8 @@ static void free_fib_info_rcu(struct rcu_head *head)
                rt_fibinfo_free(&nexthop_nh->nh_rth_input);
        } endfor_nexthops(fi);
 
-       m = fi->fib_metrics;
-       if (m != &dst_default_metrics && refcount_dec_and_test(&m->refcnt))
-               kfree(m);
+       ip_fib_metrics_put(fi->fib_metrics);
+
        kfree(fi);
 }
 
index de063780a1750bacfec8a24ed42406f9103c78df..cf709eadc932b7eeb1450cb8c1ba3c65e0848954 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/list.h>
 #include <linux/slab.h>
 
+#include <net/ip.h>
 #include <net/ipv6.h>
 #include <net/ndisc.h>
 #include <net/addrconf.h>
@@ -169,7 +170,6 @@ void fib6_info_destroy_rcu(struct rcu_head *head)
 {
        struct fib6_info *f6i = container_of(head, struct fib6_info, rcu);
        struct rt6_exception_bucket *bucket;
-       struct dst_metrics *m;
 
        WARN_ON(f6i->fib6_node);
 
@@ -201,9 +201,7 @@ void fib6_info_destroy_rcu(struct rcu_head *head)
        if (f6i->fib6_nh.nh_dev)
                dev_put(f6i->fib6_nh.nh_dev);
 
-       m = f6i->fib6_metrics;
-       if (m != &dst_default_metrics && refcount_dec_and_test(&m->refcnt))
-               kfree(m);
+       ip_fib_metrics_put(f6i->fib6_metrics);
 
        kfree(f6i);
 }