aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2011-04-28 17:31:47 -0400
committerDavid S. Miller <davem@davemloft.net>2011-04-29 01:26:00 -0400
commitcf91166223772ef4a2ed98b9874958bf6a2470df (patch)
treef8c86cc60798db9e4469031a8dceb5fcb512fb81 /net
parent5c1e6aa300a7a669dc469d2dcb20172c6bd8fed9 (diff)
net: Use non-zero allocations in dst_alloc().
Make dst_alloc() and it's users explicitly initialize the entire entry. The zero'ing done by kmem_cache_zalloc() was almost entirely redundant. Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/core/dst.c20
-rw-r--r--net/decnet/dn_route.c2
-rw-r--r--net/ipv4/route.c78
-rw-r--r--net/ipv6/route.c8
-rw-r--r--net/xfrm/xfrm_policy.c1
5 files changed, 74 insertions, 35 deletions
diff --git a/net/core/dst.c b/net/core/dst.c
index 9505778ec800..30f009327b62 100644
--- a/net/core/dst.c
+++ b/net/core/dst.c
@@ -175,22 +175,36 @@ void *dst_alloc(struct dst_ops *ops, struct net_device *dev,
175 if (ops->gc(ops)) 175 if (ops->gc(ops))
176 return NULL; 176 return NULL;
177 } 177 }
178 dst = kmem_cache_zalloc(ops->kmem_cachep, GFP_ATOMIC); 178 dst = kmem_cache_alloc(ops->kmem_cachep, GFP_ATOMIC);
179 if (!dst) 179 if (!dst)
180 return NULL; 180 return NULL;
181 dst->ops = ops; 181 dst->child = NULL;
182 dst->dev = dev; 182 dst->dev = dev;
183 if (dev) 183 if (dev)
184 dev_hold(dev); 184 dev_hold(dev);
185 dst->ops = ops;
185 dst_init_metrics(dst, dst_default_metrics, true); 186 dst_init_metrics(dst, dst_default_metrics, true);
187 dst->expires = 0UL;
186 dst->path = dst; 188 dst->path = dst;
189 dst->neighbour = NULL;
190 dst->hh = NULL;
191#ifdef CONFIG_XFRM
192 dst->xfrm = NULL;
193#endif
187 dst->input = dst_discard; 194 dst->input = dst_discard;
188 dst->output = dst_discard; 195 dst->output = dst_discard;
189 196 dst->error = 0;
190 dst->obsolete = initial_obsolete; 197 dst->obsolete = initial_obsolete;
198 dst->header_len = 0;
199 dst->trailer_len = 0;
200#ifdef CONFIG_IP_ROUTE_CLASSID
201 dst->tclassid = 0;
202#endif
191 atomic_set(&dst->__refcnt, initial_ref); 203 atomic_set(&dst->__refcnt, initial_ref);
204 dst->__use = 0;
192 dst->lastuse = jiffies; 205 dst->lastuse = jiffies;
193 dst->flags = flags; 206 dst->flags = flags;
207 dst->next = NULL;
194#if RT_CACHE_DEBUG >= 2 208#if RT_CACHE_DEBUG >= 2
195 atomic_inc(&dst_total); 209 atomic_inc(&dst_total);
196#endif 210#endif
diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c
index f489b081c25d..74544bc6fdec 100644
--- a/net/decnet/dn_route.c
+++ b/net/decnet/dn_route.c
@@ -1129,6 +1129,7 @@ make_route:
1129 if (rt == NULL) 1129 if (rt == NULL)
1130 goto e_nobufs; 1130 goto e_nobufs;
1131 1131
1132 memset(&rt->fld, 0, sizeof(rt->fld));
1132 rt->fld.saddr = oldflp->saddr; 1133 rt->fld.saddr = oldflp->saddr;
1133 rt->fld.daddr = oldflp->daddr; 1134 rt->fld.daddr = oldflp->daddr;
1134 rt->fld.flowidn_oif = oldflp->flowidn_oif; 1135 rt->fld.flowidn_oif = oldflp->flowidn_oif;
@@ -1398,6 +1399,7 @@ make_route:
1398 if (rt == NULL) 1399 if (rt == NULL)
1399 goto e_nobufs; 1400 goto e_nobufs;
1400 1401
1402 memset(&rt->fld, 0, sizeof(rt->fld));
1401 rt->rt_saddr = fld.saddr; 1403 rt->rt_saddr = fld.saddr;
1402 rt->rt_daddr = fld.daddr; 1404 rt->rt_daddr = fld.daddr;
1403 rt->rt_gateway = fld.daddr; 1405 rt->rt_gateway = fld.daddr;
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index b471d89b57ee..fb9211adf079 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1830,7 +1830,6 @@ static void rt_set_nexthop(struct rtable *rt, const struct flowi4 *oldflp4,
1830#endif 1830#endif
1831 set_class_tag(rt, itag); 1831 set_class_tag(rt, itag);
1832#endif 1832#endif
1833 rt->rt_type = type;
1834} 1833}
1835 1834
1836static struct rtable *rt_dst_alloc(struct net_device *dev, 1835static struct rtable *rt_dst_alloc(struct net_device *dev,
@@ -1877,25 +1876,28 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
1877 if (!rth) 1876 if (!rth)
1878 goto e_nobufs; 1877 goto e_nobufs;
1879 1878
1879#ifdef CONFIG_IP_ROUTE_CLASSID
1880 rth->dst.tclassid = itag;
1881#endif
1880 rth->dst.output = ip_rt_bug; 1882 rth->dst.output = ip_rt_bug;
1881 1883
1882 rth->rt_key_dst = daddr; 1884 rth->rt_key_dst = daddr;
1883 rth->rt_dst = daddr;
1884 rth->rt_tos = tos;
1885 rth->rt_mark = skb->mark;
1886 rth->rt_key_src = saddr; 1885 rth->rt_key_src = saddr;
1886 rth->rt_genid = rt_genid(dev_net(dev));
1887 rth->rt_flags = RTCF_MULTICAST;
1888 rth->rt_type = RTN_MULTICAST;
1889 rth->rt_tos = tos;
1890 rth->rt_dst = daddr;
1887 rth->rt_src = saddr; 1891 rth->rt_src = saddr;
1888#ifdef CONFIG_IP_ROUTE_CLASSID
1889 rth->dst.tclassid = itag;
1890#endif
1891 rth->rt_route_iif = dev->ifindex; 1892 rth->rt_route_iif = dev->ifindex;
1892 rth->rt_iif = dev->ifindex; 1893 rth->rt_iif = dev->ifindex;
1893 rth->rt_oif = 0; 1894 rth->rt_oif = 0;
1895 rth->rt_mark = skb->mark;
1894 rth->rt_gateway = daddr; 1896 rth->rt_gateway = daddr;
1895 rth->rt_spec_dst= spec_dst; 1897 rth->rt_spec_dst= spec_dst;
1896 rth->rt_genid = rt_genid(dev_net(dev)); 1898 rth->rt_peer_genid = 0;
1897 rth->rt_flags = RTCF_MULTICAST; 1899 rth->peer = NULL;
1898 rth->rt_type = RTN_MULTICAST; 1900 rth->fi = NULL;
1899 if (our) { 1901 if (our) {
1900 rth->dst.input= ip_local_deliver; 1902 rth->dst.input= ip_local_deliver;
1901 rth->rt_flags |= RTCF_LOCAL; 1903 rth->rt_flags |= RTCF_LOCAL;
@@ -2017,25 +2019,28 @@ static int __mkroute_input(struct sk_buff *skb,
2017 } 2019 }
2018 2020
2019 rth->rt_key_dst = daddr; 2021 rth->rt_key_dst = daddr;
2020 rth->rt_dst = daddr;
2021 rth->rt_tos = tos;
2022 rth->rt_mark = skb->mark;
2023 rth->rt_key_src = saddr; 2022 rth->rt_key_src = saddr;
2023 rth->rt_genid = rt_genid(dev_net(rth->dst.dev));
2024 rth->rt_flags = flags;
2025 rth->rt_type = res->type;
2026 rth->rt_tos = tos;
2027 rth->rt_dst = daddr;
2024 rth->rt_src = saddr; 2028 rth->rt_src = saddr;
2025 rth->rt_gateway = daddr;
2026 rth->rt_route_iif = in_dev->dev->ifindex; 2029 rth->rt_route_iif = in_dev->dev->ifindex;
2027 rth->rt_iif = in_dev->dev->ifindex; 2030 rth->rt_iif = in_dev->dev->ifindex;
2028 rth->rt_oif = 0; 2031 rth->rt_oif = 0;
2032 rth->rt_mark = skb->mark;
2033 rth->rt_gateway = daddr;
2029 rth->rt_spec_dst= spec_dst; 2034 rth->rt_spec_dst= spec_dst;
2035 rth->rt_peer_genid = 0;
2036 rth->peer = NULL;
2037 rth->fi = NULL;
2030 2038
2031 rth->dst.input = ip_forward; 2039 rth->dst.input = ip_forward;
2032 rth->dst.output = ip_output; 2040 rth->dst.output = ip_output;
2033 rth->rt_genid = rt_genid(dev_net(rth->dst.dev));
2034 2041
2035 rt_set_nexthop(rth, NULL, res, res->fi, res->type, itag); 2042 rt_set_nexthop(rth, NULL, res, res->fi, res->type, itag);
2036 2043
2037 rth->rt_flags = flags;
2038
2039 *result = rth; 2044 *result = rth;
2040 err = 0; 2045 err = 0;
2041 cleanup: 2046 cleanup:
@@ -2187,30 +2192,37 @@ local_input:
2187 if (!rth) 2192 if (!rth)
2188 goto e_nobufs; 2193 goto e_nobufs;
2189 2194
2195 rth->dst.input= ip_local_deliver;
2190 rth->dst.output= ip_rt_bug; 2196 rth->dst.output= ip_rt_bug;
2191 rth->rt_genid = rt_genid(net); 2197#ifdef CONFIG_IP_ROUTE_CLASSID
2198 rth->dst.tclassid = itag;
2199#endif
2192 2200
2193 rth->rt_key_dst = daddr; 2201 rth->rt_key_dst = daddr;
2194 rth->rt_dst = daddr;
2195 rth->rt_tos = tos;
2196 rth->rt_mark = skb->mark;
2197 rth->rt_key_src = saddr; 2202 rth->rt_key_src = saddr;
2203 rth->rt_genid = rt_genid(net);
2204 rth->rt_flags = flags|RTCF_LOCAL;
2205 rth->rt_type = res.type;
2206 rth->rt_tos = tos;
2207 rth->rt_dst = daddr;
2198 rth->rt_src = saddr; 2208 rth->rt_src = saddr;
2199#ifdef CONFIG_IP_ROUTE_CLASSID 2209#ifdef CONFIG_IP_ROUTE_CLASSID
2200 rth->dst.tclassid = itag; 2210 rth->dst.tclassid = itag;
2201#endif 2211#endif
2202 rth->rt_route_iif = dev->ifindex; 2212 rth->rt_route_iif = dev->ifindex;
2203 rth->rt_iif = dev->ifindex; 2213 rth->rt_iif = dev->ifindex;
2214 rth->rt_oif = 0;
2215 rth->rt_mark = skb->mark;
2204 rth->rt_gateway = daddr; 2216 rth->rt_gateway = daddr;
2205 rth->rt_spec_dst= spec_dst; 2217 rth->rt_spec_dst= spec_dst;
2206 rth->dst.input= ip_local_deliver; 2218 rth->rt_peer_genid = 0;
2207 rth->rt_flags = flags|RTCF_LOCAL; 2219 rth->peer = NULL;
2220 rth->fi = NULL;
2208 if (res.type == RTN_UNREACHABLE) { 2221 if (res.type == RTN_UNREACHABLE) {
2209 rth->dst.input= ip_error; 2222 rth->dst.input= ip_error;
2210 rth->dst.error= -err; 2223 rth->dst.error= -err;
2211 rth->rt_flags &= ~RTCF_LOCAL; 2224 rth->rt_flags &= ~RTCF_LOCAL;
2212 } 2225 }
2213 rth->rt_type = res.type;
2214 hash = rt_hash(daddr, saddr, fl4.flowi4_iif, rt_genid(net)); 2226 hash = rt_hash(daddr, saddr, fl4.flowi4_iif, rt_genid(net));
2215 rth = rt_intern_hash(hash, rth, skb, fl4.flowi4_iif); 2227 rth = rt_intern_hash(hash, rth, skb, fl4.flowi4_iif);
2216 err = 0; 2228 err = 0;
@@ -2391,20 +2403,25 @@ static struct rtable *__mkroute_output(const struct fib_result *res,
2391 if (!rth) 2403 if (!rth)
2392 return ERR_PTR(-ENOBUFS); 2404 return ERR_PTR(-ENOBUFS);
2393 2405
2406 rth->dst.output = ip_output;
2407
2394 rth->rt_key_dst = oldflp4->daddr; 2408 rth->rt_key_dst = oldflp4->daddr;
2395 rth->rt_tos = tos;
2396 rth->rt_key_src = oldflp4->saddr; 2409 rth->rt_key_src = oldflp4->saddr;
2397 rth->rt_oif = oldflp4->flowi4_oif; 2410 rth->rt_genid = rt_genid(dev_net(dev_out));
2398 rth->rt_mark = oldflp4->flowi4_mark; 2411 rth->rt_flags = flags;
2412 rth->rt_type = type;
2413 rth->rt_tos = tos;
2399 rth->rt_dst = fl4->daddr; 2414 rth->rt_dst = fl4->daddr;
2400 rth->rt_src = fl4->saddr; 2415 rth->rt_src = fl4->saddr;
2401 rth->rt_route_iif = 0; 2416 rth->rt_route_iif = 0;
2402 rth->rt_iif = oldflp4->flowi4_oif ? : dev_out->ifindex; 2417 rth->rt_iif = oldflp4->flowi4_oif ? : dev_out->ifindex;
2418 rth->rt_oif = oldflp4->flowi4_oif;
2419 rth->rt_mark = oldflp4->flowi4_mark;
2403 rth->rt_gateway = fl4->daddr; 2420 rth->rt_gateway = fl4->daddr;
2404 rth->rt_spec_dst= fl4->saddr; 2421 rth->rt_spec_dst= fl4->saddr;
2405 2422 rth->rt_peer_genid = 0;
2406 rth->dst.output=ip_output; 2423 rth->peer = NULL;
2407 rth->rt_genid = rt_genid(dev_net(dev_out)); 2424 rth->fi = NULL;
2408 2425
2409 RT_CACHE_STAT_INC(out_slow_tot); 2426 RT_CACHE_STAT_INC(out_slow_tot);
2410 2427
@@ -2432,7 +2449,6 @@ static struct rtable *__mkroute_output(const struct fib_result *res,
2432 2449
2433 rt_set_nexthop(rth, oldflp4, res, fi, type, 0); 2450 rt_set_nexthop(rth, oldflp4, res, fi, type, 0);
2434 2451
2435 rth->rt_flags = flags;
2436 return rth; 2452 return rth;
2437} 2453}
2438 2454
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index e8b2bb9060ef..f1be5c5c85ef 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -230,7 +230,11 @@ static struct rt6_info ip6_blk_hole_entry_template = {
230static inline struct rt6_info *ip6_dst_alloc(struct dst_ops *ops, 230static inline struct rt6_info *ip6_dst_alloc(struct dst_ops *ops,
231 struct net_device *dev) 231 struct net_device *dev)
232{ 232{
233 return (struct rt6_info *)dst_alloc(ops, dev, 0, 0, 0); 233 struct rt6_info *rt = dst_alloc(ops, dev, 0, 0, 0);
234
235 memset(&rt->rt6i_table, 0, sizeof(*rt) - sizeof(struct dst_entry));
236
237 return rt;
234} 238}
235 239
236static void ip6_dst_destroy(struct dst_entry *dst) 240static void ip6_dst_destroy(struct dst_entry *dst)
@@ -887,6 +891,8 @@ struct dst_entry *ip6_blackhole_route(struct net *net, struct dst_entry *dst_ori
887 891
888 rt = dst_alloc(&ip6_dst_blackhole_ops, ort->dst.dev, 1, 0, 0); 892 rt = dst_alloc(&ip6_dst_blackhole_ops, ort->dst.dev, 1, 0, 0);
889 if (rt) { 893 if (rt) {
894 memset(&rt->rt6i_table, 0, sizeof(*rt) - sizeof(struct dst_entry));
895
890 new = &rt->dst; 896 new = &rt->dst;
891 897
892 new->__use = 1; 898 new->__use = 1;
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 70552c4e2272..00bcb88386c2 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -1349,6 +1349,7 @@ static inline struct xfrm_dst *xfrm_alloc_dst(struct net *net, int family)
1349 BUG(); 1349 BUG();
1350 } 1350 }
1351 xdst = dst_alloc(dst_ops, NULL, 0, 0, 0); 1351 xdst = dst_alloc(dst_ops, NULL, 0, 0, 0);
1352 memset(&xdst->u.rt6.rt6i_table, 0, sizeof(*xdst) - sizeof(struct dst_entry));
1352 xfrm_policy_put_afinfo(afinfo); 1353 xfrm_policy_put_afinfo(afinfo);
1353 1354
1354 if (likely(xdst)) 1355 if (likely(xdst))