Skip to contentSkip to conversation

xfrm: do not check x->km.state

PATCH In review [email protected] 3 participants 6 messages Dec 13, 2012 – Dec 15, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfrm: do not check x->km.state

From: Li RongQing <[email protected]>

do not check x->km.state, it will be checked by succedent xfrm_state_check_expire()

---
 net/ipv6/xfrm6_input.c |    1 -
 net/xfrm/xfrm_input.c  |    4 ----
 2 files changed, 0 insertions(+), 5 deletions(-)
net/ipv6/xfrm6_input.c +0 -1
index f8c3cf8..de4babd 100644
@@ -108,7 +108,6 @@ int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
 		spin_lock(&x->lock);
 
 		if ((!i || (x->props.flags & XFRM_STATE_WILDRECV)) &&
-		    likely(x->km.state == XFRM_STATE_VALID) &&
 		    !xfrm_state_check_expire(x)) {
 			spin_unlock(&x->lock);
 			if (x->type->input(x, skb) > 0) {
net/xfrm/xfrm_input.c +0 -4
index ab2bb42..a8fbb09 100644
@@ -163,10 +163,6 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
 		skb->sp->xvec[skb->sp->len++] = x;
 
 		spin_lock(&x->lock);
-		if (unlikely(x->km.state != XFRM_STATE_VALID)) {
-			XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEINVALID);
-			goto drop_unlock;
-		}
 
 		if ((x->encap ? x->encap->encap_type : 0) != encap_type) {
 			XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEMISMATCH);
Signature · 1 line
1.7.5.4
maintainer
#1 lore raw
Quoted 28 lines · On Thu, Dec 13, 2012 at 05:06:00PM +0800, [email protected] wrote:

From: Li RongQing <[email protected]>

do not check x->km.state, it will be checked by succedent xfrm_state_check_expire()

---
 net/ipv6/xfrm6_input.c |    1 -
 net/xfrm/xfrm_input.c  |    4 ----
 2 files changed, 0 insertions(+), 5 deletions(-)
net/ipv6/xfrm6_input.c +0 -1
index f8c3cf8..de4babd 100644
@@ -108,7 +108,6 @@ int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
 		spin_lock(&x->lock);
 
 		if ((!i || (x->props.flags & XFRM_STATE_WILDRECV)) &&
-		    likely(x->km.state == XFRM_STATE_VALID) &&
 		    !xfrm_state_check_expire(x)) {
 			spin_unlock(&x->lock);
 			if (x->type->input(x, skb) > 0) {
net/xfrm/xfrm_input.c +0 -0
index ab2bb42..a8fbb09 100644

net/xfrm/xfrm_input.c int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) · line 169

Quoted 7 lines
net/xfrm/xfrm_input.c +0 -4
@@ -163,10 +163,6 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
 		skb->sp->xvec[skb->sp->len++] = x;
 
 		spin_lock(&x->lock);
-		if (unlikely(x->km.state != XFRM_STATE_VALID)) {
-			XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEINVALID);
-			goto drop_unlock;
-		}

This would remove the only place where the LINUX_MIB_XFRMINSTATEINVALID statistics counter is incremented. I think it would be better to ensure a valid state before we call xfrm_state_check_expire(). This would make the statistics more accurate and we can remove the x->km.state check from xfrm_state_check_expire().

maintainer
#2 lore raw

From: Steffen Klassert <[email protected]>
Date: Thu, 13 Dec 2012 11:19:48 +0100

Quoted 7 lines · On Thu, Dec 13, 2012 at 05:06:00PM +0800, [email protected] wrote:
Quoted 6 lines

From: Li RongQing <[email protected]>

do not check x->km.state, it will be checked by succedent xfrm_state_check_expire()

...

Quoted 5 lines

This would remove the only place where the LINUX_MIB_XFRMINSTATEINVALID statistics counter is incremented. I think it would be better to ensure a valid state before we call xfrm_state_check_expire(). This would make the statistics more accurate and we can remove the x->km.state check from xfrm_state_check_expire().

Agreed.

#3 lore raw

2012/12/14 David Miller <[email protected]>:

Quoted 10 lines

From: Steffen Klassert <[email protected]>
Date: Thu, 13 Dec 2012 11:19:48 +0100

Quoted 7 lines · On Thu, Dec 13, 2012 at 05:06:00PM +0800, [email protected] wrote:
Quoted 6 lines

From: Li RongQing <[email protected]>

do not check x->km.state, it will be checked by succedent xfrm_state_check_expire()

Quoted 8 lines

...

Quoted 5 lines

This would remove the only place where the LINUX_MIB_XFRMINSTATEINVALID statistics counter is incremented. I think it would be better to ensure a valid state before we call xfrm_state_check_expire(). This would make the statistics more accurate and we can remove the x->km.state check from xfrm_state_check_expire().

Agreed.

Thanks.

since xfrm_output_one() calls xfrm_state_check_expire() too, but without checking (x->km.state != XFRM_STATE_VALID), I think we can not directly remove the check of km.state from xfrm_state_check_expire(). I have two option, which one do you think it is better?

1. remove this check in xfrm_state_check_expire, and add a check in xfrm_output_one

net/xfrm/xfrm_output.c +6 -0
index 95a338c..c245370 100644
@@ -61,6 +61,12 @@ static int xfrm_output_one(struct sk_buff *skb, int err)
                }
 
                spin_lock_bh(&x->lock);
+
+                if (unlikely(x->km.state != XFRM_STATE_VALID)) {
+                        XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEINVALID);
+                        goto drop_unlock;
+                }
+
                err = xfrm_state_check_expire(x);
                if (err) {
                        XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEEXPIRED);
net/xfrm/xfrm_proc.c +1 -0
index d0a1af8..e4cd441 100644
@@ -39,6 +39,7 @@ static const struct snmp_mib xfrm_mib_list[] = {
        SNMP_MIB_ITEM("XfrmOutStateModeError", LINUX_MIB_XFRMOUTSTATEMODEERROR),
        SNMP_MIB_ITEM("XfrmOutStateSeqError", LINUX_MIB_XFRMOUTSTATESEQERROR),
        SNMP_MIB_ITEM("XfrmOutStateExpired", LINUX_MIB_XFRMOUTSTATEEXPIRED),
+       SNMP_MIB_ITEM("XfrmOutStateInvalid", LINUX_MIB_XFRMOUTSTATEINVALID),
        SNMP_MIB_ITEM("XfrmOutPolBlock", LINUX_MIB_XFRMOUTPOLBLOCK),
        SNMP_MIB_ITEM("XfrmOutPolDead", LINUX_MIB_XFRMOUTPOLDEAD),
        SNMP_MIB_ITEM("XfrmOutPolError", LINUX_MIB_XFRMOUTPOLERROR),
net/xfrm/xfrm_state.c +0 -3
index 3459692..05db236 100644
@@ -1370,9 +1370,6 @@ int xfrm_state_check_expire(struct xfrm_state *x)
        if (!x->curlft.use_time)
                x->curlft.use_time = get_seconds();
 
-       if (x->km.state != XFRM_STATE_VALID)
-               return -EINVAL;
-
        if (x->curlft.bytes >= x->lft.hard_byte_limit ||
            x->curlft.packets >= x->lft.hard_packet_limit) {
                x->km.state = XFRM_STATE_EXPIRED;

2. Only remove this check in xfrm6_input.c

net/ipv6/xfrm6_input.c +0 -0
@@ -109,7 +109,6 @@ int xfrm6_input_addr(struct sk_buff *skb,

xfrm_address_t *daddr,

                if ((!i || (x->props.flags & XFRM_STATE_WILDRECV)) &&
-                    likely(x->km.state == XFRM_STATE_VALID) &&
                     !xfrm_state_check_expire(x)) {
                        spin_unlock(&x->lock);
                        if (x->type->input(x, skb) > 0) {
                                /* found a valid state */
maintainer
#4 lore raw
Quoted 9 lines · RongQing Li

since xfrm_output_one() calls xfrm_state_check_expire() too, but without checking (x->km.state != XFRM_STATE_VALID), I think we can not directly remove the check of km.state from xfrm_state_check_expire(). I have two option, which one do you think it is better?

1. remove this check in xfrm_state_check_expire, and add a check in xfrm_output_one

I think the first option ist the better one. It removes a superfluous check and we get some more statistics.

#5 lore raw

2012/12/14 Steffen Klassert <[email protected]>:

Quoted 6 lines
Quoted 3 lines

1. remove this check in xfrm_state_check_expire, and add a check in xfrm_output_one

I think the first option ist the better one. It removes a superfluous check and we get some more statistics.

I see, thanks

-Roy