diff options
author | David Ahern <dsa@cumulusnetworks.com> | 2015-09-02 16:58:34 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-09-15 15:01:40 -0400 |
commit | d08c4f355403840fad98d9918db51a7113f38ee8 (patch) | |
tree | 0ca7d2acb0a1b90cb4e9445220f033ea531da244 /net/ipv4 | |
parent | 64d1def7d33856824d2c5c6fd6d4579d4d54bb87 (diff) |
net: Refactor rtable initialization
All callers to rt_dst_alloc have nearly the same initialization following
a successful allocation. Consolidate it into rt_dst_alloc.
Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r-- | net/ipv4/route.c | 85 |
1 files changed, 33 insertions, 52 deletions
diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 5f4a5565ad8b..eaefeadce07c 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c | |||
@@ -1438,12 +1438,33 @@ static void rt_set_nexthop(struct rtable *rt, __be32 daddr, | |||
1438 | } | 1438 | } |
1439 | 1439 | ||
1440 | static struct rtable *rt_dst_alloc(struct net_device *dev, | 1440 | static struct rtable *rt_dst_alloc(struct net_device *dev, |
1441 | unsigned int flags, u16 type, | ||
1441 | bool nopolicy, bool noxfrm, bool will_cache) | 1442 | bool nopolicy, bool noxfrm, bool will_cache) |
1442 | { | 1443 | { |
1443 | return dst_alloc(&ipv4_dst_ops, dev, 1, DST_OBSOLETE_FORCE_CHK, | 1444 | struct rtable *rt; |
1444 | (will_cache ? 0 : (DST_HOST | DST_NOCACHE)) | | 1445 | |
1445 | (nopolicy ? DST_NOPOLICY : 0) | | 1446 | rt = dst_alloc(&ipv4_dst_ops, dev, 1, DST_OBSOLETE_FORCE_CHK, |
1446 | (noxfrm ? DST_NOXFRM : 0)); | 1447 | (will_cache ? 0 : (DST_HOST | DST_NOCACHE)) | |
1448 | (nopolicy ? DST_NOPOLICY : 0) | | ||
1449 | (noxfrm ? DST_NOXFRM : 0)); | ||
1450 | |||
1451 | if (rt) { | ||
1452 | rt->rt_genid = rt_genid_ipv4(dev_net(dev)); | ||
1453 | rt->rt_flags = flags; | ||
1454 | rt->rt_type = type; | ||
1455 | rt->rt_is_input = 0; | ||
1456 | rt->rt_iif = 0; | ||
1457 | rt->rt_pmtu = 0; | ||
1458 | rt->rt_gateway = 0; | ||
1459 | rt->rt_uses_gateway = 0; | ||
1460 | INIT_LIST_HEAD(&rt->rt_uncached); | ||
1461 | |||
1462 | rt->dst.output = ip_output; | ||
1463 | if (flags & RTCF_LOCAL) | ||
1464 | rt->dst.input = ip_local_deliver; | ||
1465 | } | ||
1466 | |||
1467 | return rt; | ||
1447 | } | 1468 | } |
1448 | 1469 | ||
1449 | /* called in rcu_read_lock() section */ | 1470 | /* called in rcu_read_lock() section */ |
@@ -1452,6 +1473,7 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr, | |||
1452 | { | 1473 | { |
1453 | struct rtable *rth; | 1474 | struct rtable *rth; |
1454 | struct in_device *in_dev = __in_dev_get_rcu(dev); | 1475 | struct in_device *in_dev = __in_dev_get_rcu(dev); |
1476 | unsigned int flags = RTCF_MULTICAST; | ||
1455 | u32 itag = 0; | 1477 | u32 itag = 0; |
1456 | int err; | 1478 | int err; |
1457 | 1479 | ||
@@ -1477,7 +1499,10 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr, | |||
1477 | if (err < 0) | 1499 | if (err < 0) |
1478 | goto e_err; | 1500 | goto e_err; |
1479 | } | 1501 | } |
1480 | rth = rt_dst_alloc(dev_net(dev)->loopback_dev, | 1502 | if (our) |
1503 | flags |= RTCF_LOCAL; | ||
1504 | |||
1505 | rth = rt_dst_alloc(dev_net(dev)->loopback_dev, flags, RTN_MULTICAST, | ||
1481 | IN_DEV_CONF_GET(in_dev, NOPOLICY), false, false); | 1506 | IN_DEV_CONF_GET(in_dev, NOPOLICY), false, false); |
1482 | if (!rth) | 1507 | if (!rth) |
1483 | goto e_nobufs; | 1508 | goto e_nobufs; |
@@ -1486,20 +1511,7 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr, | |||
1486 | rth->dst.tclassid = itag; | 1511 | rth->dst.tclassid = itag; |
1487 | #endif | 1512 | #endif |
1488 | rth->dst.output = ip_rt_bug; | 1513 | rth->dst.output = ip_rt_bug; |
1489 | |||
1490 | rth->rt_genid = rt_genid_ipv4(dev_net(dev)); | ||
1491 | rth->rt_flags = RTCF_MULTICAST; | ||
1492 | rth->rt_type = RTN_MULTICAST; | ||
1493 | rth->rt_is_input= 1; | 1514 | rth->rt_is_input= 1; |
1494 | rth->rt_iif = 0; | ||
1495 | rth->rt_pmtu = 0; | ||
1496 | rth->rt_gateway = 0; | ||
1497 | rth->rt_uses_gateway = 0; | ||
1498 | INIT_LIST_HEAD(&rth->rt_uncached); | ||
1499 | if (our) { | ||
1500 | rth->dst.input= ip_local_deliver; | ||
1501 | rth->rt_flags |= RTCF_LOCAL; | ||
1502 | } | ||
1503 | 1515 | ||
1504 | #ifdef CONFIG_IP_MROUTE | 1516 | #ifdef CONFIG_IP_MROUTE |
1505 | if (!ipv4_is_local_multicast(daddr) && IN_DEV_MFORWARD(in_dev)) | 1517 | if (!ipv4_is_local_multicast(daddr) && IN_DEV_MFORWARD(in_dev)) |
@@ -1608,7 +1620,7 @@ static int __mkroute_input(struct sk_buff *skb, | |||
1608 | } | 1620 | } |
1609 | } | 1621 | } |
1610 | 1622 | ||
1611 | rth = rt_dst_alloc(out_dev->dev, | 1623 | rth = rt_dst_alloc(out_dev->dev, 0, res->type, |
1612 | IN_DEV_CONF_GET(in_dev, NOPOLICY), | 1624 | IN_DEV_CONF_GET(in_dev, NOPOLICY), |
1613 | IN_DEV_CONF_GET(out_dev, NOXFRM), do_cache); | 1625 | IN_DEV_CONF_GET(out_dev, NOXFRM), do_cache); |
1614 | if (!rth) { | 1626 | if (!rth) { |
@@ -1616,19 +1628,10 @@ static int __mkroute_input(struct sk_buff *skb, | |||
1616 | goto cleanup; | 1628 | goto cleanup; |
1617 | } | 1629 | } |
1618 | 1630 | ||
1619 | rth->rt_genid = rt_genid_ipv4(dev_net(rth->dst.dev)); | ||
1620 | rth->rt_flags = 0; | ||
1621 | rth->rt_type = res->type; | ||
1622 | rth->rt_is_input = 1; | 1631 | rth->rt_is_input = 1; |
1623 | rth->rt_iif = 0; | ||
1624 | rth->rt_pmtu = 0; | ||
1625 | rth->rt_gateway = 0; | ||
1626 | rth->rt_uses_gateway = 0; | ||
1627 | INIT_LIST_HEAD(&rth->rt_uncached); | ||
1628 | RT_CACHE_STAT_INC(in_slow_tot); | 1632 | RT_CACHE_STAT_INC(in_slow_tot); |
1629 | 1633 | ||
1630 | rth->dst.input = ip_forward; | 1634 | rth->dst.input = ip_forward; |
1631 | rth->dst.output = ip_output; | ||
1632 | 1635 | ||
1633 | rt_set_nexthop(rth, daddr, res, fnhe, res->fi, res->type, itag); | 1636 | rt_set_nexthop(rth, daddr, res, fnhe, res->fi, res->type, itag); |
1634 | if (lwtunnel_output_redirect(rth->dst.lwtstate)) { | 1637 | if (lwtunnel_output_redirect(rth->dst.lwtstate)) { |
@@ -1795,26 +1798,16 @@ local_input: | |||
1795 | } | 1798 | } |
1796 | } | 1799 | } |
1797 | 1800 | ||
1798 | rth = rt_dst_alloc(net->loopback_dev, | 1801 | rth = rt_dst_alloc(net->loopback_dev, flags | RTCF_LOCAL, res.type, |
1799 | IN_DEV_CONF_GET(in_dev, NOPOLICY), false, do_cache); | 1802 | IN_DEV_CONF_GET(in_dev, NOPOLICY), false, do_cache); |
1800 | if (!rth) | 1803 | if (!rth) |
1801 | goto e_nobufs; | 1804 | goto e_nobufs; |
1802 | 1805 | ||
1803 | rth->dst.input= ip_local_deliver; | ||
1804 | rth->dst.output= ip_rt_bug; | 1806 | rth->dst.output= ip_rt_bug; |
1805 | #ifdef CONFIG_IP_ROUTE_CLASSID | 1807 | #ifdef CONFIG_IP_ROUTE_CLASSID |
1806 | rth->dst.tclassid = itag; | 1808 | rth->dst.tclassid = itag; |
1807 | #endif | 1809 | #endif |
1808 | |||
1809 | rth->rt_genid = rt_genid_ipv4(net); | ||
1810 | rth->rt_flags = flags|RTCF_LOCAL; | ||
1811 | rth->rt_type = res.type; | ||
1812 | rth->rt_is_input = 1; | 1810 | rth->rt_is_input = 1; |
1813 | rth->rt_iif = 0; | ||
1814 | rth->rt_pmtu = 0; | ||
1815 | rth->rt_gateway = 0; | ||
1816 | rth->rt_uses_gateway = 0; | ||
1817 | INIT_LIST_HEAD(&rth->rt_uncached); | ||
1818 | 1811 | ||
1819 | RT_CACHE_STAT_INC(in_slow_tot); | 1812 | RT_CACHE_STAT_INC(in_slow_tot); |
1820 | if (res.type == RTN_UNREACHABLE) { | 1813 | if (res.type == RTN_UNREACHABLE) { |
@@ -1987,28 +1980,16 @@ static struct rtable *__mkroute_output(const struct fib_result *res, | |||
1987 | } | 1980 | } |
1988 | 1981 | ||
1989 | add: | 1982 | add: |
1990 | rth = rt_dst_alloc(dev_out, | 1983 | rth = rt_dst_alloc(dev_out, flags, type, |
1991 | IN_DEV_CONF_GET(in_dev, NOPOLICY), | 1984 | IN_DEV_CONF_GET(in_dev, NOPOLICY), |
1992 | IN_DEV_CONF_GET(in_dev, NOXFRM), | 1985 | IN_DEV_CONF_GET(in_dev, NOXFRM), |
1993 | do_cache); | 1986 | do_cache); |
1994 | if (!rth) | 1987 | if (!rth) |
1995 | return ERR_PTR(-ENOBUFS); | 1988 | return ERR_PTR(-ENOBUFS); |
1996 | 1989 | ||
1997 | rth->dst.output = ip_output; | ||
1998 | |||
1999 | rth->rt_genid = rt_genid_ipv4(dev_net(dev_out)); | ||
2000 | rth->rt_flags = flags; | ||
2001 | rth->rt_type = type; | ||
2002 | rth->rt_is_input = 0; | ||
2003 | rth->rt_iif = orig_oif ? : 0; | 1990 | rth->rt_iif = orig_oif ? : 0; |
2004 | rth->rt_pmtu = 0; | ||
2005 | rth->rt_gateway = 0; | ||
2006 | rth->rt_uses_gateway = 0; | ||
2007 | INIT_LIST_HEAD(&rth->rt_uncached); | ||
2008 | RT_CACHE_STAT_INC(out_slow_tot); | 1991 | RT_CACHE_STAT_INC(out_slow_tot); |
2009 | 1992 | ||
2010 | if (flags & RTCF_LOCAL) | ||
2011 | rth->dst.input = ip_local_deliver; | ||
2012 | if (flags & (RTCF_BROADCAST | RTCF_MULTICAST)) { | 1993 | if (flags & (RTCF_BROADCAST | RTCF_MULTICAST)) { |
2013 | if (flags & RTCF_LOCAL && | 1994 | if (flags & RTCF_LOCAL && |
2014 | !(dev_out->flags & IFF_LOOPBACK)) { | 1995 | !(dev_out->flags & IFF_LOOPBACK)) { |