aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2012-07-19 15:31:33 -0400
committerDavid S. Miller <davem@davemloft.net>2012-07-20 16:31:21 -0400
commitf5b0a8743601a4477419171f5046bd07d1c080a0 (patch)
tree92e17ec293c3d0e35a0deda5d3bbf43710fb96ff
parentf8126f1d5136be1ca1a3536d43ad7a710b5620f8 (diff)
net: Document dst->obsolete better.
Add a big comment explaining how the field works, and use defines instead of magic constants for the values assigned to it. Suggested by Joe Perches. Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/dst.h14
-rw-r--r--net/core/dst.c4
-rw-r--r--net/decnet/dn_route.c4
-rw-r--r--net/ipv4/route.c5
-rw-r--r--net/ipv6/route.c4
-rw-r--r--net/sctp/transport.c2
-rw-r--r--net/xfrm/xfrm_policy.c23
7 files changed, 35 insertions, 21 deletions
diff --git a/include/net/dst.h b/include/net/dst.h
index 51610468c63d..0df661a0c295 100644
--- a/include/net/dst.h
+++ b/include/net/dst.h
@@ -65,7 +65,19 @@ struct dst_entry {
65 unsigned short pending_confirm; 65 unsigned short pending_confirm;
66 66
67 short error; 67 short error;
68
69 /* A non-zero value of dst->obsolete forces by-hand validation
70 * of the route entry. Positive values are set by the generic
71 * dst layer to indicate that the entry has been forcefully
72 * destroyed.
73 *
74 * Negative values are used by the implementation layer code to
75 * force invocation of the dst_ops->check() method.
76 */
68 short obsolete; 77 short obsolete;
78#define DST_OBSOLETE_NONE 0
79#define DST_OBSOLETE_DEAD 2
80#define DST_OBSOLETE_FORCE_CHK -1
69 unsigned short header_len; /* more space at head required */ 81 unsigned short header_len; /* more space at head required */
70 unsigned short trailer_len; /* space to reserve at tail */ 82 unsigned short trailer_len; /* space to reserve at tail */
71#ifdef CONFIG_IP_ROUTE_CLASSID 83#ifdef CONFIG_IP_ROUTE_CLASSID
@@ -359,7 +371,7 @@ extern struct dst_entry *dst_destroy(struct dst_entry *dst);
359 371
360static inline void dst_free(struct dst_entry *dst) 372static inline void dst_free(struct dst_entry *dst)
361{ 373{
362 if (dst->obsolete > 1) 374 if (dst->obsolete > 0)
363 return; 375 return;
364 if (!atomic_read(&dst->__refcnt)) { 376 if (!atomic_read(&dst->__refcnt)) {
365 dst = dst_destroy(dst); 377 dst = dst_destroy(dst);
diff --git a/net/core/dst.c b/net/core/dst.c
index 07bacff84aa4..069d51d29414 100644
--- a/net/core/dst.c
+++ b/net/core/dst.c
@@ -94,7 +94,7 @@ loop:
94 * But we do not have state "obsoleted, but 94 * But we do not have state "obsoleted, but
95 * referenced by parent", so it is right. 95 * referenced by parent", so it is right.
96 */ 96 */
97 if (dst->obsolete > 1) 97 if (dst->obsolete > 0)
98 continue; 98 continue;
99 99
100 ___dst_free(dst); 100 ___dst_free(dst);
@@ -202,7 +202,7 @@ static void ___dst_free(struct dst_entry *dst)
202 */ 202 */
203 if (dst->dev == NULL || !(dst->dev->flags&IFF_UP)) 203 if (dst->dev == NULL || !(dst->dev->flags&IFF_UP))
204 dst->input = dst->output = dst_discard; 204 dst->input = dst->output = dst_discard;
205 dst->obsolete = 2; 205 dst->obsolete = DST_OBSOLETE_DEAD;
206} 206}
207 207
208void __dst_free(struct dst_entry *dst) 208void __dst_free(struct dst_entry *dst)
diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c
index 47de90d8fe94..23cc11dd4e40 100644
--- a/net/decnet/dn_route.c
+++ b/net/decnet/dn_route.c
@@ -1176,7 +1176,7 @@ make_route:
1176 if (dev_out->flags & IFF_LOOPBACK) 1176 if (dev_out->flags & IFF_LOOPBACK)
1177 flags |= RTCF_LOCAL; 1177 flags |= RTCF_LOCAL;
1178 1178
1179 rt = dst_alloc(&dn_dst_ops, dev_out, 1, 0, DST_HOST); 1179 rt = dst_alloc(&dn_dst_ops, dev_out, 1, DST_OBSOLETE_NONE, DST_HOST);
1180 if (rt == NULL) 1180 if (rt == NULL)
1181 goto e_nobufs; 1181 goto e_nobufs;
1182 1182
@@ -1444,7 +1444,7 @@ static int dn_route_input_slow(struct sk_buff *skb)
1444 } 1444 }
1445 1445
1446make_route: 1446make_route:
1447 rt = dst_alloc(&dn_dst_ops, out_dev, 0, 0, DST_HOST); 1447 rt = dst_alloc(&dn_dst_ops, out_dev, 0, DST_OBSOLETE_NONE, DST_HOST);
1448 if (rt == NULL) 1448 if (rt == NULL)
1449 goto e_nobufs; 1449 goto e_nobufs;
1450 1450
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index d1d579638092..50d2498c9284 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1221,7 +1221,7 @@ static void rt_set_nexthop(struct rtable *rt, const struct flowi4 *fl4,
1221static struct rtable *rt_dst_alloc(struct net_device *dev, 1221static struct rtable *rt_dst_alloc(struct net_device *dev,
1222 bool nopolicy, bool noxfrm) 1222 bool nopolicy, bool noxfrm)
1223{ 1223{
1224 return dst_alloc(&ipv4_dst_ops, dev, 1, -1, 1224 return dst_alloc(&ipv4_dst_ops, dev, 1, DST_OBSOLETE_FORCE_CHK,
1225 DST_HOST | DST_NOCACHE | 1225 DST_HOST | DST_NOCACHE |
1226 (nopolicy ? DST_NOPOLICY : 0) | 1226 (nopolicy ? DST_NOPOLICY : 0) |
1227 (noxfrm ? DST_NOXFRM : 0)); 1227 (noxfrm ? DST_NOXFRM : 0));
@@ -1969,9 +1969,10 @@ static struct dst_ops ipv4_dst_blackhole_ops = {
1969 1969
1970struct dst_entry *ipv4_blackhole_route(struct net *net, struct dst_entry *dst_orig) 1970struct dst_entry *ipv4_blackhole_route(struct net *net, struct dst_entry *dst_orig)
1971{ 1971{
1972 struct rtable *rt = dst_alloc(&ipv4_dst_blackhole_ops, NULL, 1, 0, 0);
1973 struct rtable *ort = (struct rtable *) dst_orig; 1972 struct rtable *ort = (struct rtable *) dst_orig;
1973 struct rtable *rt;
1974 1974
1975 rt = dst_alloc(&ipv4_dst_blackhole_ops, NULL, 1, DST_OBSOLETE_NONE, 0);
1975 if (rt) { 1976 if (rt) {
1976 struct dst_entry *new = &rt->dst; 1977 struct dst_entry *new = &rt->dst;
1977 1978
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 84f6564dd372..cf02cb97bbdd 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -281,7 +281,7 @@ static inline struct rt6_info *ip6_dst_alloc(struct net *net,
281 struct fib6_table *table) 281 struct fib6_table *table)
282{ 282{
283 struct rt6_info *rt = dst_alloc(&net->ipv6.ip6_dst_ops, dev, 283 struct rt6_info *rt = dst_alloc(&net->ipv6.ip6_dst_ops, dev,
284 0, 0, flags); 284 0, DST_OBSOLETE_NONE, flags);
285 285
286 if (rt) { 286 if (rt) {
287 struct dst_entry *dst = &rt->dst; 287 struct dst_entry *dst = &rt->dst;
@@ -985,7 +985,7 @@ struct dst_entry *ip6_blackhole_route(struct net *net, struct dst_entry *dst_ori
985 struct rt6_info *rt, *ort = (struct rt6_info *) dst_orig; 985 struct rt6_info *rt, *ort = (struct rt6_info *) dst_orig;
986 struct dst_entry *new = NULL; 986 struct dst_entry *new = NULL;
987 987
988 rt = dst_alloc(&ip6_dst_blackhole_ops, ort->dst.dev, 1, 0, 0); 988 rt = dst_alloc(&ip6_dst_blackhole_ops, ort->dst.dev, 1, DST_OBSOLETE_NONE, 0);
989 if (rt) { 989 if (rt) {
990 new = &rt->dst; 990 new = &rt->dst;
991 991
diff --git a/net/sctp/transport.c b/net/sctp/transport.c
index a6b7ee9ce28a..ec3a12b9b802 100644
--- a/net/sctp/transport.c
+++ b/net/sctp/transport.c
@@ -216,7 +216,7 @@ void sctp_transport_set_owner(struct sctp_transport *transport,
216void sctp_transport_pmtu(struct sctp_transport *transport, struct sock *sk) 216void sctp_transport_pmtu(struct sctp_transport *transport, struct sock *sk)
217{ 217{
218 /* If we don't have a fresh route, look one up */ 218 /* If we don't have a fresh route, look one up */
219 if (!transport->dst || transport->dst->obsolete > 1) { 219 if (!transport->dst || transport->dst->obsolete) {
220 dst_release(transport->dst); 220 dst_release(transport->dst);
221 transport->af_specific->get_dst(transport, &transport->saddr, 221 transport->af_specific->get_dst(transport, &transport->saddr,
222 &transport->fl, sk); 222 &transport->fl, sk);
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 65bd1ca51517..c5a5165a5927 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -1350,7 +1350,7 @@ static inline struct xfrm_dst *xfrm_alloc_dst(struct net *net, int family)
1350 default: 1350 default:
1351 BUG(); 1351 BUG();
1352 } 1352 }
1353 xdst = dst_alloc(dst_ops, NULL, 0, 0, 0); 1353 xdst = dst_alloc(dst_ops, NULL, 0, DST_OBSOLETE_NONE, 0);
1354 1354
1355 if (likely(xdst)) { 1355 if (likely(xdst)) {
1356 struct dst_entry *dst = &xdst->u.dst; 1356 struct dst_entry *dst = &xdst->u.dst;
@@ -1477,7 +1477,7 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy,
1477 dst1->xfrm = xfrm[i]; 1477 dst1->xfrm = xfrm[i];
1478 xdst->xfrm_genid = xfrm[i]->genid; 1478 xdst->xfrm_genid = xfrm[i]->genid;
1479 1479
1480 dst1->obsolete = -1; 1480 dst1->obsolete = DST_OBSOLETE_FORCE_CHK;
1481 dst1->flags |= DST_HOST; 1481 dst1->flags |= DST_HOST;
1482 dst1->lastuse = now; 1482 dst1->lastuse = now;
1483 1483
@@ -2219,12 +2219,13 @@ EXPORT_SYMBOL(__xfrm_route_forward);
2219static struct dst_entry *xfrm_dst_check(struct dst_entry *dst, u32 cookie) 2219static struct dst_entry *xfrm_dst_check(struct dst_entry *dst, u32 cookie)
2220{ 2220{
2221 /* Code (such as __xfrm4_bundle_create()) sets dst->obsolete 2221 /* Code (such as __xfrm4_bundle_create()) sets dst->obsolete
2222 * to "-1" to force all XFRM destinations to get validated by 2222 * to DST_OBSOLETE_FORCE_CHK to force all XFRM destinations to
2223 * dst_ops->check on every use. We do this because when a 2223 * get validated by dst_ops->check on every use. We do this
2224 * normal route referenced by an XFRM dst is obsoleted we do 2224 * because when a normal route referenced by an XFRM dst is
2225 * not go looking around for all parent referencing XFRM dsts 2225 * obsoleted we do not go looking around for all parent
2226 * so that we can invalidate them. It is just too much work. 2226 * referencing XFRM dsts so that we can invalidate them. It
2227 * Instead we make the checks here on every use. For example: 2227 * is just too much work. Instead we make the checks here on
2228 * every use. For example:
2228 * 2229 *
2229 * XFRM dst A --> IPv4 dst X 2230 * XFRM dst A --> IPv4 dst X
2230 * 2231 *
@@ -2234,9 +2235,9 @@ static struct dst_entry *xfrm_dst_check(struct dst_entry *dst, u32 cookie)
2234 * stale_bundle() check. 2235 * stale_bundle() check.
2235 * 2236 *
2236 * When a policy's bundle is pruned, we dst_free() the XFRM 2237 * When a policy's bundle is pruned, we dst_free() the XFRM
2237 * dst which causes it's ->obsolete field to be set to a 2238 * dst which causes it's ->obsolete field to be set to
2238 * positive non-zero integer. If an XFRM dst has been pruned 2239 * DST_OBSOLETE_DEAD. If an XFRM dst has been pruned like
2239 * like this, we want to force a new route lookup. 2240 * this, we want to force a new route lookup.
2240 */ 2241 */
2241 if (dst->obsolete < 0 && !stale_bundle(dst)) 2242 if (dst->obsolete < 0 && !stale_bundle(dst))
2242 return dst; 2243 return dst;