Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ipv6: introduce ip6_rt_put()

As suggested by Eric, we could introduce a helper function
for ipv6 too, to avoid checking if rt is NULL before
dst_release().

Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Cong Wang <amwang@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Amerigo Wang and committed by
David S. Miller
94e187c0 6da025fa

+32 -26
+9
include/net/ip6_fib.h
··· 213 213 dst_hold(new); 214 214 } 215 215 216 + static inline void ip6_rt_put(struct rt6_info *rt) 217 + { 218 + /* dst_release() accepts a NULL parameter. 219 + * We rely on dst being first structure in struct rt6_info 220 + */ 221 + BUILD_BUG_ON(offsetof(struct rt6_info, dst) != 0); 222 + dst_release(&rt->dst); 223 + } 224 + 216 225 struct fib6_walker_t { 217 226 struct list_head lh; 218 227 struct fib6_node *root, *node;
+3 -4
net/ipv6/addrconf.c
··· 699 699 pr_warn("Freeing alive inet6 address %p\n", ifp); 700 700 return; 701 701 } 702 - dst_release(&ifp->rt->dst); 702 + ip6_rt_put(ifp->rt); 703 703 704 704 kfree_rcu(ifp, rcu); 705 705 } ··· 951 951 rt6_set_expires(rt, expires); 952 952 } 953 953 } 954 - dst_release(&rt->dst); 954 + ip6_rt_put(rt); 955 955 } 956 956 957 957 /* clean up prefsrc entries */ ··· 2027 2027 addrconf_prefix_route(&pinfo->prefix, pinfo->prefix_len, 2028 2028 dev, expires, flags); 2029 2029 } 2030 - if (rt) 2031 - dst_release(&rt->dst); 2030 + ip6_rt_put(rt); 2032 2031 } 2033 2032 2034 2033 /* Try to figure out our local address for this prefix */
+1 -1
net/ipv6/anycast.c
··· 84 84 rt = rt6_lookup(net, addr, NULL, 0, 0); 85 85 if (rt) { 86 86 dev = rt->dst.dev; 87 - dst_release(&rt->dst); 87 + ip6_rt_put(rt); 88 88 } else if (ishost) { 89 89 err = -EADDRNOTAVAIL; 90 90 goto error;
+1 -1
net/ipv6/fib6_rules.c
··· 100 100 goto out; 101 101 } 102 102 again: 103 - dst_release(&rt->dst); 103 + ip6_rt_put(rt); 104 104 rt = NULL; 105 105 goto out; 106 106
+1 -1
net/ipv6/ip6_gre.c
··· 1069 1069 dev->mtu = IPV6_MIN_MTU; 1070 1070 } 1071 1071 } 1072 - dst_release(&rt->dst); 1072 + ip6_rt_put(rt); 1073 1073 } 1074 1074 1075 1075 t->hlen = addend;
+2 -2
net/ipv6/ip6_output.c
··· 755 755 if (err == 0) { 756 756 IP6_INC_STATS(net, ip6_dst_idev(&rt->dst), 757 757 IPSTATS_MIB_FRAGOKS); 758 - dst_release(&rt->dst); 758 + ip6_rt_put(rt); 759 759 return 0; 760 760 } 761 761 ··· 767 767 768 768 IP6_INC_STATS(net, ip6_dst_idev(&rt->dst), 769 769 IPSTATS_MIB_FRAGFAILS); 770 - dst_release(&rt->dst); 770 + ip6_rt_put(rt); 771 771 return err; 772 772 773 773 slow_path_clean:
+2 -3
net/ipv6/ip6_tunnel.c
··· 663 663 664 664 icmpv6_send(skb2, rel_type, rel_code, rel_info); 665 665 666 - if (rt) 667 - dst_release(&rt->dst); 666 + ip6_rt_put(rt); 668 667 669 668 kfree_skb(skb2); 670 669 } ··· 1207 1208 if (dev->mtu < IPV6_MIN_MTU) 1208 1209 dev->mtu = IPV6_MIN_MTU; 1209 1210 } 1210 - dst_release(&rt->dst); 1211 + ip6_rt_put(rt); 1211 1212 } 1212 1213 } 1213 1214
+2 -2
net/ipv6/mcast.c
··· 163 163 rt = rt6_lookup(net, addr, NULL, 0, 0); 164 164 if (rt) { 165 165 dev = rt->dst.dev; 166 - dst_release(&rt->dst); 166 + ip6_rt_put(rt); 167 167 } 168 168 } else 169 169 dev = dev_get_by_index_rcu(net, ifindex); ··· 260 260 261 261 if (rt) { 262 262 dev = rt->dst.dev; 263 - dst_release(&rt->dst); 263 + ip6_rt_put(rt); 264 264 } 265 265 } else 266 266 dev = dev_get_by_index_rcu(net, ifindex);
+3 -4
net/ipv6/ndisc.c
··· 1145 1145 ND_PRINTK(0, err, 1146 1146 "RA: %s got default router without neighbour\n", 1147 1147 __func__); 1148 - dst_release(&rt->dst); 1148 + ip6_rt_put(rt); 1149 1149 return; 1150 1150 } 1151 1151 } ··· 1170 1170 ND_PRINTK(0, err, 1171 1171 "RA: %s got default router without neighbour\n", 1172 1172 __func__); 1173 - dst_release(&rt->dst); 1173 + ip6_rt_put(rt); 1174 1174 return; 1175 1175 } 1176 1176 neigh->flags |= NTF_ROUTER; ··· 1326 1326 ND_PRINTK(2, warn, "RA: invalid RA options\n"); 1327 1327 } 1328 1328 out: 1329 - if (rt) 1330 - dst_release(&rt->dst); 1329 + ip6_rt_put(rt); 1331 1330 if (neigh) 1332 1331 neigh_release(neigh); 1333 1332 }
+1 -1
net/ipv6/netfilter/ip6t_rpfilter.c
··· 67 67 if (rt->rt6i_idev->dev == dev || (flags & XT_RPFILTER_LOOSE)) 68 68 ret = true; 69 69 out: 70 - dst_release(&rt->dst); 70 + ip6_rt_put(rt); 71 71 return ret; 72 72 } 73 73
+7 -7
net/ipv6/route.c
··· 732 732 else 733 733 rt6_set_expires(rt, jiffies + HZ * lifetime); 734 734 735 - dst_release(&rt->dst); 735 + ip6_rt_put(rt); 736 736 } 737 737 return 0; 738 738 } ··· 948 948 else 949 949 goto out2; 950 950 951 - dst_release(&rt->dst); 951 + ip6_rt_put(rt); 952 952 rt = nrt ? : net->ipv6.ip6_null_entry; 953 953 954 954 dst_hold(&rt->dst); ··· 965 965 * Race condition! In the gap, when table->tb6_lock was 966 966 * released someone could insert this route. Relookup. 967 967 */ 968 - dst_release(&rt->dst); 968 + ip6_rt_put(rt); 969 969 goto relookup; 970 970 971 971 out: ··· 1576 1576 goto out; 1577 1577 if (dev) { 1578 1578 if (dev != grt->dst.dev) { 1579 - dst_release(&grt->dst); 1579 + ip6_rt_put(grt); 1580 1580 goto out; 1581 1581 } 1582 1582 } else { ··· 1587 1587 } 1588 1588 if (!(grt->rt6i_flags & RTF_GATEWAY)) 1589 1589 err = 0; 1590 - dst_release(&grt->dst); 1590 + ip6_rt_put(grt); 1591 1591 1592 1592 if (err) 1593 1593 goto out; ··· 1673 1673 write_unlock_bh(&table->tb6_lock); 1674 1674 1675 1675 out: 1676 - dst_release(&rt->dst); 1676 + ip6_rt_put(rt); 1677 1677 return err; 1678 1678 } 1679 1679 ··· 2732 2732 2733 2733 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); 2734 2734 if (!skb) { 2735 - dst_release(&rt->dst); 2735 + ip6_rt_put(rt); 2736 2736 err = -ENOBUFS; 2737 2737 goto errout; 2738 2738 }