tcp: Add SNMP counters for backlog and min_ttl drops
authorEric Dumazet <eric.dumazet@gmail.com>
Sun, 7 Mar 2010 23:21:57 +0000 (23:21 +0000)
committerDavid S. Miller <davem@davemloft.net>
Mon, 8 Mar 2010 18:45:27 +0000 (10:45 -0800)
Commit 6b03a53a (tcp: use limited socket backlog) added the possibility
of dropping frames when backlog queue is full.

Commit d218d111 (tcp: Generalized TTL Security Mechanism) added the
possibility of dropping frames when TTL is under a given limit.

This patch adds new SNMP MIB entries, named TCPBacklogDrop and
TCPMinTTLDrop, published in /proc/net/netstat in TcpExt: line

netstat -s | egrep "TCPBacklogDrop|TCPMinTTLDrop"
    TCPBacklogDrop: 0
    TCPMinTTLDrop: 0

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/snmp.h
net/ipv4/proc.c
net/ipv4/tcp_ipv4.c
net/ipv6/tcp_ipv6.c

index e28f5a0182e85fcba41a420c305e0f78bfaa318e..4435d1084755f07a3cbf7439a55d98aa5c0f7b4c 100644 (file)
@@ -225,6 +225,8 @@ enum
        LINUX_MIB_SACKSHIFTED,
        LINUX_MIB_SACKMERGED,
        LINUX_MIB_SACKSHIFTFALLBACK,
+       LINUX_MIB_TCPBACKLOGDROP,
+       LINUX_MIB_TCPMINTTLDROP, /* RFC 5082 */
        __LINUX_MIB_MAX
 };
 
index 242ed23073702bfa6365e4f7c49c888c55615774..4f1f337f4337836169f19536de6adf4ba7c23064 100644 (file)
@@ -249,6 +249,8 @@ static const struct snmp_mib snmp4_net_list[] = {
        SNMP_MIB_ITEM("TCPSackShifted", LINUX_MIB_SACKSHIFTED),
        SNMP_MIB_ITEM("TCPSackMerged", LINUX_MIB_SACKMERGED),
        SNMP_MIB_ITEM("TCPSackShiftFallback", LINUX_MIB_SACKSHIFTFALLBACK),
+       SNMP_MIB_ITEM("TCPBacklogDrop", LINUX_MIB_TCPBACKLOGDROP),
+       SNMP_MIB_ITEM("TCPMinTTLDrop", LINUX_MIB_TCPMINTTLDROP),
        SNMP_MIB_SENTINEL
 };
 
index 1915f7dc30e6abba10d1273403660a18726abc55..8d51d39ad1bb80b25834a18bb2aacddadc692a6d 100644 (file)
@@ -1651,8 +1651,10 @@ int tcp_v4_rcv(struct sk_buff *skb)
        if (!sk)
                goto no_tcp_socket;
 
-       if (iph->ttl < inet_sk(sk)->min_ttl)
+       if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
+               NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
                goto discard_and_relse;
+       }
 
 process:
        if (sk->sk_state == TCP_TIME_WAIT)
@@ -1682,8 +1684,9 @@ process:
                        if (!tcp_prequeue(sk, skb))
                                ret = tcp_v4_do_rcv(sk, skb);
                }
-       } else if (sk_add_backlog(sk, skb)) {
+       } else if (unlikely(sk_add_backlog(sk, skb))) {
                bh_unlock_sock(sk);
+               NET_INC_STATS_BH(net, LINUX_MIB_TCPBACKLOGDROP);
                goto discard_and_relse;
        }
        bh_unlock_sock(sk);
index 2c378b1bd5cfedfbe3773e2ebc34e2665eb97994..9b6dbba80d312913278f50e059b1d19b4a554cfe 100644 (file)
@@ -1740,8 +1740,9 @@ process:
                        if (!tcp_prequeue(sk, skb))
                                ret = tcp_v6_do_rcv(sk, skb);
                }
-       } else if (sk_add_backlog(sk, skb)) {
+       } else if (unlikely(sk_add_backlog(sk, skb))) {
                bh_unlock_sock(sk);
+               NET_INC_STATS_BH(net, LINUX_MIB_TCPBACKLOGDROP);
                goto discard_and_relse;
        }
        bh_unlock_sock(sk);