ICMP statistics incomplete (patch)

David Woodhouse (D.W.Woodhouse@nortel.co.uk)
Tue, 19 Aug 1997 21:05:50 +0100


This is a multipart MIME message.

--===_0_Tue_Aug_19_21:03:18_BST_1997
Content-Type: text/plain; charset=us-ascii

I just noticed that the field icmpOutEchos is never increased. Obviously this
is because ping sends raw IP and doesn't go through the icmp protocol code.
Here's a not-very-nice patch to detect ICMP Echo Request packets in
raw_sendto()
and make the SNMP stats work. The second case (header not included) is the one
which is exercised on my system (ping from RH 4.2), and the first (really
ugly) case isn't tested.

--===_0_Tue_Aug_19_21:03:18_BST_1997
Content-Type: application/octet-stream
Content-Description: rawpatch

--- linux/net/ipv4/raw.c.virgin Thu Jun 26 20:33:41 1997
+++ linux/net/ipv4/raw.c Tue Aug 19 20:50:08 1997
@@ -347,9 +347,35 @@
rfh.saddr = rt->rt_src;
if (!ipc.addr)
ipc.addr = rt->rt_dst;
- if(sk->ip_hdrincl)
+ if(sk->ip_hdrincl) {
+ struct iphdr *iph=0;
+ u_char buf;
+
+ if (!raw_getfrag(&rfh, &buf, (u_int)&iph->protocol, 1)
+ && buf == IPPROTO_ICMP) {
+ if (!raw_getfrag(&rfh, &buf, 0, 1)) {
+ if (!raw_getfrag(&rfh, &buf,
+ ((struct iphdr *)&buf)->ihl << 2, 1)
+ && buf == ICMP_ECHO) {
+ icmp_statistics.IcmpOutEchos++;
+ icmp_statistics.IcmpOutMsgs++;
+ }
+ }
+ }
+
err=ip_build_xmit(sk, raw_getrawfrag, &rfh, len, &ipc, rt, msg->msg_flags);
+ }
else {
+ if (sk->protocol == IPPROTO_ICMP) {
+ u_char buf;
+
+ raw_getfrag (&rfh, &buf, 0, 1);
+ if (buf == ICMP_ECHO) {
+ icmp_statistics.IcmpOutEchos++;
+ icmp_statistics.IcmpOutMsgs++;
+ }
+ }
+
if (len>65535-sizeof(struct iphdr))
err = -EMSGSIZE;
else

--===_0_Tue_Aug_19_21:03:18_BST_1997
Content-Type: text/plain; charset=us-ascii

David Woodhouse, CB3 9AN http://dwmw2.robinson.cam.ac.uk/
dwmw2@cam.ac.uk Tel: 0976 658355
D.W.Woodhouse@nortel.co.uk Tel: 01279 402332

--===_0_Tue_Aug_19_21:03:18_BST_1997--