aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2011-04-28 17:13:38 -0400
committerDavid S. Miller <davem@davemloft.net>2011-04-29 01:25:59 -0400
commit5c1e6aa300a7a669dc469d2dcb20172c6bd8fed9 (patch)
tree61796a49f8b9236eee4730ff8142e79bd43f0f51 /net/ipv4
parent778865a550e7958c1211242cc481f48d46de0f04 (diff)
net: Make dst_alloc() take more explicit initializations.
Now the dst->dev, dev->obsolete, and dst->flags values can be specified as well. Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r--net/ipv4/route.c40
1 files changed, 15 insertions, 25 deletions
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index d63f780c6941..b471d89b57ee 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1833,17 +1833,13 @@ static void rt_set_nexthop(struct rtable *rt, const struct flowi4 *oldflp4,
1833 rt->rt_type = type; 1833 rt->rt_type = type;
1834} 1834}
1835 1835
1836static struct rtable *rt_dst_alloc(bool nopolicy, bool noxfrm) 1836static struct rtable *rt_dst_alloc(struct net_device *dev,
1837 bool nopolicy, bool noxfrm)
1837{ 1838{
1838 struct rtable *rt = dst_alloc(&ipv4_dst_ops, 1); 1839 return dst_alloc(&ipv4_dst_ops, dev, 1, -1,
1839 if (rt) { 1840 DST_HOST |
1840 rt->dst.obsolete = -1; 1841 (nopolicy ? DST_NOPOLICY : 0) |
1841 1842 (noxfrm ? DST_NOXFRM : 0));
1842 rt->dst.flags = DST_HOST |
1843 (nopolicy ? DST_NOPOLICY : 0) |
1844 (noxfrm ? DST_NOXFRM : 0);
1845 }
1846 return rt;
1847} 1843}
1848 1844
1849/* called in rcu_read_lock() section */ 1845/* called in rcu_read_lock() section */
@@ -1876,7 +1872,8 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
1876 if (err < 0) 1872 if (err < 0)
1877 goto e_err; 1873 goto e_err;
1878 } 1874 }
1879 rth = rt_dst_alloc(IN_DEV_CONF_GET(in_dev, NOPOLICY), false); 1875 rth = rt_dst_alloc(init_net.loopback_dev,
1876 IN_DEV_CONF_GET(in_dev, NOPOLICY), false);
1880 if (!rth) 1877 if (!rth)
1881 goto e_nobufs; 1878 goto e_nobufs;
1882 1879
@@ -1893,8 +1890,6 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
1893#endif 1890#endif
1894 rth->rt_route_iif = dev->ifindex; 1891 rth->rt_route_iif = dev->ifindex;
1895 rth->rt_iif = dev->ifindex; 1892 rth->rt_iif = dev->ifindex;
1896 rth->dst.dev = init_net.loopback_dev;
1897 dev_hold(rth->dst.dev);
1898 rth->rt_oif = 0; 1893 rth->rt_oif = 0;
1899 rth->rt_gateway = daddr; 1894 rth->rt_gateway = daddr;
1900 rth->rt_spec_dst= spec_dst; 1895 rth->rt_spec_dst= spec_dst;
@@ -2013,7 +2008,8 @@ static int __mkroute_input(struct sk_buff *skb,
2013 } 2008 }
2014 } 2009 }
2015 2010
2016 rth = rt_dst_alloc(IN_DEV_CONF_GET(in_dev, NOPOLICY), 2011 rth = rt_dst_alloc(out_dev->dev,
2012 IN_DEV_CONF_GET(in_dev, NOPOLICY),
2017 IN_DEV_CONF_GET(out_dev, NOXFRM)); 2013 IN_DEV_CONF_GET(out_dev, NOXFRM));
2018 if (!rth) { 2014 if (!rth) {
2019 err = -ENOBUFS; 2015 err = -ENOBUFS;
@@ -2029,8 +2025,6 @@ static int __mkroute_input(struct sk_buff *skb,
2029 rth->rt_gateway = daddr; 2025 rth->rt_gateway = daddr;
2030 rth->rt_route_iif = in_dev->dev->ifindex; 2026 rth->rt_route_iif = in_dev->dev->ifindex;
2031 rth->rt_iif = in_dev->dev->ifindex; 2027 rth->rt_iif = in_dev->dev->ifindex;
2032 rth->dst.dev = (out_dev)->dev;
2033 dev_hold(rth->dst.dev);
2034 rth->rt_oif = 0; 2028 rth->rt_oif = 0;
2035 rth->rt_spec_dst= spec_dst; 2029 rth->rt_spec_dst= spec_dst;
2036 2030
@@ -2188,7 +2182,8 @@ brd_input:
2188 RT_CACHE_STAT_INC(in_brd); 2182 RT_CACHE_STAT_INC(in_brd);
2189 2183
2190local_input: 2184local_input:
2191 rth = rt_dst_alloc(IN_DEV_CONF_GET(in_dev, NOPOLICY), false); 2185 rth = rt_dst_alloc(net->loopback_dev,
2186 IN_DEV_CONF_GET(in_dev, NOPOLICY), false);
2192 if (!rth) 2187 if (!rth)
2193 goto e_nobufs; 2188 goto e_nobufs;
2194 2189
@@ -2206,8 +2201,6 @@ local_input:
2206#endif 2201#endif
2207 rth->rt_route_iif = dev->ifindex; 2202 rth->rt_route_iif = dev->ifindex;
2208 rth->rt_iif = dev->ifindex; 2203 rth->rt_iif = dev->ifindex;
2209 rth->dst.dev = net->loopback_dev;
2210 dev_hold(rth->dst.dev);
2211 rth->rt_gateway = daddr; 2204 rth->rt_gateway = daddr;
2212 rth->rt_spec_dst= spec_dst; 2205 rth->rt_spec_dst= spec_dst;
2213 rth->dst.input= ip_local_deliver; 2206 rth->dst.input= ip_local_deliver;
@@ -2392,7 +2385,8 @@ static struct rtable *__mkroute_output(const struct fib_result *res,
2392 fi = NULL; 2385 fi = NULL;
2393 } 2386 }
2394 2387
2395 rth = rt_dst_alloc(IN_DEV_CONF_GET(in_dev, NOPOLICY), 2388 rth = rt_dst_alloc(dev_out,
2389 IN_DEV_CONF_GET(in_dev, NOPOLICY),
2396 IN_DEV_CONF_GET(in_dev, NOXFRM)); 2390 IN_DEV_CONF_GET(in_dev, NOXFRM));
2397 if (!rth) 2391 if (!rth)
2398 return ERR_PTR(-ENOBUFS); 2392 return ERR_PTR(-ENOBUFS);
@@ -2406,10 +2400,6 @@ static struct rtable *__mkroute_output(const struct fib_result *res,
2406 rth->rt_src = fl4->saddr; 2400 rth->rt_src = fl4->saddr;
2407 rth->rt_route_iif = 0; 2401 rth->rt_route_iif = 0;
2408 rth->rt_iif = oldflp4->flowi4_oif ? : dev_out->ifindex; 2402 rth->rt_iif = oldflp4->flowi4_oif ? : dev_out->ifindex;
2409 /* get references to the devices that are to be hold by the routing
2410 cache entry */
2411 rth->dst.dev = dev_out;
2412 dev_hold(dev_out);
2413 rth->rt_gateway = fl4->daddr; 2403 rth->rt_gateway = fl4->daddr;
2414 rth->rt_spec_dst= fl4->saddr; 2404 rth->rt_spec_dst= fl4->saddr;
2415 2405
@@ -2711,7 +2701,7 @@ static struct dst_ops ipv4_dst_blackhole_ops = {
2711 2701
2712struct dst_entry *ipv4_blackhole_route(struct net *net, struct dst_entry *dst_orig) 2702struct dst_entry *ipv4_blackhole_route(struct net *net, struct dst_entry *dst_orig)
2713{ 2703{
2714 struct rtable *rt = dst_alloc(&ipv4_dst_blackhole_ops, 1); 2704 struct rtable *rt = dst_alloc(&ipv4_dst_blackhole_ops, NULL, 1, 0, 0);
2715 struct rtable *ort = (struct rtable *) dst_orig; 2705 struct rtable *ort = (struct rtable *) dst_orig;
2716 2706
2717 if (rt) { 2707 if (rt) {