icmp: Account for ICMP out errors
authorEric Dumazet <eric.dumazet@gmail.com>
Sat, 3 Apr 2010 22:09:04 +0000 (15:09 -0700)
committerDavid S. Miller <davem@davemloft.net>
Sat, 3 Apr 2010 22:09:04 +0000 (15:09 -0700)
When ip_append() fails because of socket limit or memory shortage,
increment ICMP_MIB_OUTERRORS counter, so that "netstat -s" can report
these errors.

LANG=C netstat -s | grep "ICMP messages failed"
    0 ICMP messages failed

For IPV6, implement ICMP6_MIB_OUTERRORS counter as well.

# grep Icmp6OutErrors /proc/net/dev_snmp6/*
/proc/net/dev_snmp6/eth0:Icmp6OutErrors                    0
/proc/net/dev_snmp6/lo:Icmp6OutErrors                    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/icmp.c
net/ipv6/icmp.c
net/ipv6/proc.c

index d2a9aa3c6c8807c8f1f348831f694078aac69b5e..52797714ade7a737b974b39fe2c2df9859318768 100644 (file)
@@ -100,6 +100,7 @@ enum
        ICMP6_MIB_INMSGS,                       /* InMsgs */
        ICMP6_MIB_INERRORS,                     /* InErrors */
        ICMP6_MIB_OUTMSGS,                      /* OutMsgs */
+       ICMP6_MIB_OUTERRORS,                    /* OutErrors */
        __ICMP6_MIB_MAX
 };
 
index 4b4c2bcd15db4b4464be428a954ee8686769b68b..d2aa7438c52366e864ece0d65fe970a02584ae17 100644 (file)
@@ -330,9 +330,10 @@ static void icmp_push_reply(struct icmp_bxm *icmp_param,
        if (ip_append_data(sk, icmp_glue_bits, icmp_param,
                           icmp_param->data_len+icmp_param->head_len,
                           icmp_param->head_len,
-                          ipc, rt, MSG_DONTWAIT) < 0)
+                          ipc, rt, MSG_DONTWAIT) < 0) {
+               ICMP_INC_STATS_BH(sock_net(sk), ICMP_MIB_OUTERRORS);
                ip_flush_pending_frames(sk);
-       else if ((skb = skb_peek(&sk->sk_write_queue)) != NULL) {
+       else if ((skb = skb_peek(&sk->sk_write_queue)) != NULL) {
                struct icmphdr *icmph = icmp_hdr(skb);
                __wsum csum = 0;
                struct sk_buff *skb1;
index eb9abe24bdf0b1e277724958cfd113280936048e..a00c18aa6c8d1a2830da7a94d7e398cd69a17e35 100644 (file)
@@ -482,6 +482,7 @@ route_done:
                              np->tclass, NULL, &fl, (struct rt6_info*)dst,
                              MSG_DONTWAIT);
        if (err) {
+               ICMP6_INC_STATS_BH(net, idev, ICMP6_MIB_OUTMSGS);
                ip6_flush_pending_frames(sk);
                goto out_put;
        }
@@ -562,6 +563,7 @@ static void icmpv6_echo_reply(struct sk_buff *skb)
                                (struct rt6_info*)dst, MSG_DONTWAIT);
 
        if (err) {
+               ICMP6_INC_STATS_BH(net, idev, ICMP6_MIB_OUTMSGS);
                ip6_flush_pending_frames(sk);
                goto out_put;
        }
index 58344c0fbd13a3603d29eef3adc6a96f36ff1248..458eabfbe130a8cd76fb47ce9ec00bce28341ebd 100644 (file)
@@ -97,6 +97,7 @@ static const struct snmp_mib snmp6_icmp6_list[] = {
        SNMP_MIB_ITEM("Icmp6InMsgs", ICMP6_MIB_INMSGS),
        SNMP_MIB_ITEM("Icmp6InErrors", ICMP6_MIB_INERRORS),
        SNMP_MIB_ITEM("Icmp6OutMsgs", ICMP6_MIB_OUTMSGS),
+       SNMP_MIB_ITEM("Icmp6OutErrors", ICMP6_MIB_OUTERRORS),
        SNMP_MIB_SENTINEL
 };