Skip to content

Commit f5b0a87

Browse files
committed
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 <[email protected]>
1 parent f8126f1 commit f5b0a87

File tree

7 files changed

+35
-21
lines changed

7 files changed

+35
-21
lines changed

include/net/dst.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,19 @@ struct dst_entry {
6565
unsigned short pending_confirm;
6666

6767
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+
*/
6877
short obsolete;
78+
#define DST_OBSOLETE_NONE 0
79+
#define DST_OBSOLETE_DEAD 2
80+
#define DST_OBSOLETE_FORCE_CHK -1
6981
unsigned short header_len; /* more space at head required */
7082
unsigned short trailer_len; /* space to reserve at tail */
7183
#ifdef CONFIG_IP_ROUTE_CLASSID
@@ -359,7 +371,7 @@ extern struct dst_entry *dst_destroy(struct dst_entry *dst);
359371

360372
static inline void dst_free(struct dst_entry *dst)
361373
{
362-
if (dst->obsolete > 1)
374+
if (dst->obsolete > 0)
363375
return;
364376
if (!atomic_read(&dst->__refcnt)) {
365377
dst = dst_destroy(dst);

net/core/dst.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static void dst_gc_task(struct work_struct *work)
9494
* But we do not have state "obsoleted, but
9595
* referenced by parent", so it is right.
9696
*/
97-
if (dst->obsolete > 1)
97+
if (dst->obsolete > 0)
9898
continue;
9999

100100
___dst_free(dst);
@@ -202,7 +202,7 @@ static void ___dst_free(struct dst_entry *dst)
202202
*/
203203
if (dst->dev == NULL || !(dst->dev->flags&IFF_UP))
204204
dst->input = dst->output = dst_discard;
205-
dst->obsolete = 2;
205+
dst->obsolete = DST_OBSOLETE_DEAD;
206206
}
207207

208208
void __dst_free(struct dst_entry *dst)

net/decnet/dn_route.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ static int dn_route_output_slow(struct dst_entry **pprt, const struct flowidn *o
11761176
if (dev_out->flags & IFF_LOOPBACK)
11771177
flags |= RTCF_LOCAL;
11781178

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);
11801180
if (rt == NULL)
11811181
goto e_nobufs;
11821182

@@ -1444,7 +1444,7 @@ static int dn_route_input_slow(struct sk_buff *skb)
14441444
}
14451445

14461446
make_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);
14481448
if (rt == NULL)
14491449
goto e_nobufs;
14501450

net/ipv4/route.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ static void rt_set_nexthop(struct rtable *rt, const struct flowi4 *fl4,
12211221
static struct rtable *rt_dst_alloc(struct net_device *dev,
12221222
bool nopolicy, bool noxfrm)
12231223
{
1224-
return dst_alloc(&ipv4_dst_ops, dev, 1, -1,
1224+
return dst_alloc(&ipv4_dst_ops, dev, 1, DST_OBSOLETE_FORCE_CHK,
12251225
DST_HOST | DST_NOCACHE |
12261226
(nopolicy ? DST_NOPOLICY : 0) |
12271227
(noxfrm ? DST_NOXFRM : 0));
@@ -1969,9 +1969,10 @@ static struct dst_ops ipv4_dst_blackhole_ops = {
19691969

19701970
struct dst_entry *ipv4_blackhole_route(struct net *net, struct dst_entry *dst_orig)
19711971
{
1972-
struct rtable *rt = dst_alloc(&ipv4_dst_blackhole_ops, NULL, 1, 0, 0);
19731972
struct rtable *ort = (struct rtable *) dst_orig;
1973+
struct rtable *rt;
19741974

1975+
rt = dst_alloc(&ipv4_dst_blackhole_ops, NULL, 1, DST_OBSOLETE_NONE, 0);
19751976
if (rt) {
19761977
struct dst_entry *new = &rt->dst;
19771978

net/ipv6/route.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ static inline struct rt6_info *ip6_dst_alloc(struct net *net,
281281
struct fib6_table *table)
282282
{
283283
struct rt6_info *rt = dst_alloc(&net->ipv6.ip6_dst_ops, dev,
284-
0, 0, flags);
284+
0, DST_OBSOLETE_NONE, flags);
285285

286286
if (rt) {
287287
struct dst_entry *dst = &rt->dst;
@@ -985,7 +985,7 @@ struct dst_entry *ip6_blackhole_route(struct net *net, struct dst_entry *dst_ori
985985
struct rt6_info *rt, *ort = (struct rt6_info *) dst_orig;
986986
struct dst_entry *new = NULL;
987987

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);
989989
if (rt) {
990990
new = &rt->dst;
991991

net/sctp/transport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ void sctp_transport_set_owner(struct sctp_transport *transport,
216216
void sctp_transport_pmtu(struct sctp_transport *transport, struct sock *sk)
217217
{
218218
/* 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) {
220220
dst_release(transport->dst);
221221
transport->af_specific->get_dst(transport, &transport->saddr,
222222
&transport->fl, sk);

net/xfrm/xfrm_policy.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ static inline struct xfrm_dst *xfrm_alloc_dst(struct net *net, int family)
13501350
default:
13511351
BUG();
13521352
}
1353-
xdst = dst_alloc(dst_ops, NULL, 0, 0, 0);
1353+
xdst = dst_alloc(dst_ops, NULL, 0, DST_OBSOLETE_NONE, 0);
13541354

13551355
if (likely(xdst)) {
13561356
struct dst_entry *dst = &xdst->u.dst;
@@ -1477,7 +1477,7 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy,
14771477
dst1->xfrm = xfrm[i];
14781478
xdst->xfrm_genid = xfrm[i]->genid;
14791479

1480-
dst1->obsolete = -1;
1480+
dst1->obsolete = DST_OBSOLETE_FORCE_CHK;
14811481
dst1->flags |= DST_HOST;
14821482
dst1->lastuse = now;
14831483

@@ -2219,12 +2219,13 @@ EXPORT_SYMBOL(__xfrm_route_forward);
22192219
static struct dst_entry *xfrm_dst_check(struct dst_entry *dst, u32 cookie)
22202220
{
22212221
/* Code (such as __xfrm4_bundle_create()) sets dst->obsolete
2222-
* to "-1" to force all XFRM destinations to get validated by
2223-
* dst_ops->check on every use. We do this because when a
2224-
* normal route referenced by an XFRM dst is obsoleted we do
2225-
* not go looking around for all parent referencing XFRM dsts
2226-
* so that we can invalidate them. It is just too much work.
2227-
* Instead we make the checks here on every use. For example:
2222+
* to DST_OBSOLETE_FORCE_CHK to force all XFRM destinations to
2223+
* get validated by dst_ops->check on every use. We do this
2224+
* because when a normal route referenced by an XFRM dst is
2225+
* obsoleted we do not go looking around for all parent
2226+
* referencing XFRM dsts so that we can invalidate them. It
2227+
* is just too much work. Instead we make the checks here on
2228+
* every use. For example:
22282229
*
22292230
* XFRM dst A --> IPv4 dst X
22302231
*
@@ -2234,9 +2235,9 @@ static struct dst_entry *xfrm_dst_check(struct dst_entry *dst, u32 cookie)
22342235
* stale_bundle() check.
22352236
*
22362237
* 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-
* positive non-zero integer. If an XFRM dst has been pruned
2239-
* like this, we want to force a new route lookup.
2238+
* dst which causes it's ->obsolete field to be set to
2239+
* DST_OBSOLETE_DEAD. If an XFRM dst has been pruned like
2240+
* this, we want to force a new route lookup.
22402241
*/
22412242
if (dst->obsolete < 0 && !stale_bundle(dst))
22422243
return dst;

0 commit comments

Comments
 (0)