[UDP]: Defer InDataGrams increment until recvmsg() does checksum
Thanks dave, herbert, gerrit, andi and other people for your
discussion about this problem.
UdpInDatagrams can be confusing because it counts packets that
might be dropped later.
Move UdpInDatagrams into recvmsg() as allowed by the RFC.
Signed-off-by: Wang Chen <wangchen@cn.fujitsu.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
diff --git a/Documentation/networking/udplite.txt b/Documentation/networking/udplite.txt
index b6409ca..3870f28 100644
--- a/Documentation/networking/udplite.txt
+++ b/Documentation/networking/udplite.txt
@@ -236,7 +236,7 @@
This displays UDP-Lite statistics variables, whose meaning is as follows.
- InDatagrams: Total number of received datagrams.
+ InDatagrams: The total number of datagrams delivered to users.
NoPorts: Number of packets received to an unknown port.
These cases are counted separately (not as InErrors).
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 03c400c..3465d4a 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -873,6 +873,8 @@
if (err)
goto out_free;
+ UDP_INC_STATS_USER(UDP_MIB_INDATAGRAMS, is_udplite);
+
sock_recv_timestamp(msg, sk, skb);
/* Copy the address. */
@@ -966,10 +968,8 @@
int ret;
ret = (*up->encap_rcv)(sk, skb);
- if (ret <= 0) {
- UDP_INC_STATS_BH(UDP_MIB_INDATAGRAMS, up->pcflag);
+ if (ret <= 0)
return -ret;
- }
}
/* FALLTHROUGH -- it's a UDP Packet */
@@ -1023,7 +1023,6 @@
goto drop;
}
- UDP_INC_STATS_BH(UDP_MIB_INDATAGRAMS, up->pcflag);
return 0;
drop:
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index ee1cc3f..b0474a6 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -164,6 +164,8 @@
if (err)
goto out_free;
+ UDP6_INC_STATS_USER(UDP_MIB_INDATAGRAMS, is_udplite);
+
sock_recv_timestamp(msg, sk, skb);
/* Copy the address. */
@@ -292,7 +294,7 @@
UDP6_INC_STATS_BH(UDP_MIB_RCVBUFERRORS, up->pcflag);
goto drop;
}
- UDP6_INC_STATS_BH(UDP_MIB_INDATAGRAMS, up->pcflag);
+
return 0;
drop:
UDP6_INC_STATS_BH(UDP_MIB_INERRORS, up->pcflag);