xfrm: removes a superfluous check and add a statistic
authorLi RongQing <roy.qing.li@gmail.com>
Fri, 28 Dec 2012 08:06:28 +0000 (16:06 +0800)
committerSteffen Klassert <steffen.klassert@secunet.com>
Mon, 7 Jan 2013 10:18:58 +0000 (11:18 +0100)
Remove the check if x->km.state equal to XFRM_STATE_VALID in
xfrm_state_check_expire(), which will be done before call
xfrm_state_check_expire().

add a LINUX_MIB_XFRMOUTSTATEINVALID statistic to record the
outbound error due to invalid xfrm state.

Signed-off-by: Li RongQing <roy.qing.li@gmail.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
include/uapi/linux/snmp.h
net/xfrm/xfrm_output.c
net/xfrm/xfrm_proc.c
net/xfrm/xfrm_state.c

index fdfba235f9f1a9bb6b8fc03958ae1982404dd125..b49eab89c9fd4461c155ec1b60083aeab1234e44 100644 (file)
@@ -278,6 +278,7 @@ enum
        LINUX_MIB_XFRMOUTPOLDEAD,               /* XfrmOutPolDead */
        LINUX_MIB_XFRMOUTPOLERROR,              /* XfrmOutPolError */
        LINUX_MIB_XFRMFWDHDRERROR,              /* XfrmFwdHdrError*/
+       LINUX_MIB_XFRMOUTSTATEINVALID,          /* XfrmOutStateInvalid */
        __LINUX_MIB_XFRMMAX
 };
 
index 95a338c89f99d87af24ffa97faf17e1a7ef700e8..3670526e70b97e804e90404036c89a5e54b5dcf5 100644 (file)
@@ -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 error_nolock;
+               }
+
                err = xfrm_state_check_expire(x);
                if (err) {
                        XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEEXPIRED);
index d0a1af8ed5846d07e73c605f0d119b9f8d87d0b4..603903853e89802099ca81aaba6a9f38bc38c161 100644 (file)
@@ -43,6 +43,7 @@ static const struct snmp_mib xfrm_mib_list[] = {
        SNMP_MIB_ITEM("XfrmOutPolDead", LINUX_MIB_XFRMOUTPOLDEAD),
        SNMP_MIB_ITEM("XfrmOutPolError", LINUX_MIB_XFRMOUTPOLERROR),
        SNMP_MIB_ITEM("XfrmFwdHdrError", LINUX_MIB_XFRMFWDHDRERROR),
+       SNMP_MIB_ITEM("XfrmOutStateInvalid", LINUX_MIB_XFRMOUTSTATEINVALID),
        SNMP_MIB_SENTINEL
 };
 
index 3459692092ec1f44220d02a4d73d82613896793d..05db2362a23167d48b4107cd345130bd6e9c4982 100644 (file)
@@ -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;