From: "Kris Katterjohn" <kjak@ispwest.com>
To: linux-kernel@vger.kernel.org
Cc: torvalds@osdl.org
Subject: [PATCH] Resetting packet statistics
Date: Mon, 28 Nov 2005 19:55:52 -0800 [thread overview]
Message-ID: <9188864830a243e8a5ed8ce75d1b098f.kjak@ispwest.com> (raw)
These patches keep getsockopt(PACKET_STATISTICS) from resetting the packet
stats to zero and it creates PACKET_RESET_STATISTICS, which is used with
setsockopt(), to zero the packet stats.
Signed-off by: Kris Katterjohn <kjak@users.sourceforge.net>
---
Before I start: This is a diff from 2.6.14 and I am not subscribed so please CC
me on any replies.
I doubt I'm the only one who's a little annoyed that we have to keep track of the
packet count in userland after getsockopt(PACKET_STATISTICS). I did a little
searching but didn't find a patch similar to this so I'm not sure if I'm the only
one who thinks this is a generally Good Thing or not.
The ways these affect programs:
1) Programs can set the packet count to zero at anytime without having to make a
struct tpacket_stats just to reset it with getsockopt()
2) Programs don't need extra variables to hold packet counts (think libpcap),
they just call getsockopt(PACKET_STATISTICS) multiple times for updated stats.
NOTE:
The second patch adds PACKET_RESET_STATISTICS to include/linux/if_packet.h, but I
don't know if it's okay to #define it as "7" since that was PACKET_COPY_THRESH's
value. I did it so that the two PACKET*STATISTICS macros would be next to each
other. I checked the glibc header netpacket/packet.h and it doesn't even define
PACKET_COPY_THRESH so it shouldn't cause any problems (that I can see).
Thanks!
---
--- x/net/packet/af_packet.c 2005-10-27 19:02:08.000000000 -0500
+++ y/net/packet/af_packet.c 2005-11-28 21:49:37.000000000 -0600
@@ -41,6 +41,9 @@
* will simply extend the hardware address
* byte arrays at the end of sockaddr_ll
* and packet_mreq.
+ * Kris Katterjohn : Added PACKET_RESET_STATISTICS setsockopt
+ * option. PACKET_STATISTICS no longer sets
+ * stats to zero. 2005-11-28
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -1352,6 +1355,17 @@ packet_setsockopt(struct socket *sock, i
return ret;
}
#endif
+
+ case PACKET_RESET_STATISTICS:
+ {
+ struct packet_sock *po = pkt_sk(sk);
+
+ spin_lock_bh(&sk->sk_receive_queue.lock);
+ memset(&po->stats, 0, sizeof(po->stats));
+ spin_unlock_bh(&sk->sk_receive_queue.lock);
+ return 0;
+ }
+
#ifdef CONFIG_PACKET_MMAP
case PACKET_RX_RING:
{
@@ -1406,7 +1420,6 @@ static int packet_getsockopt(struct sock
len = sizeof(struct tpacket_stats);
spin_lock_bh(&sk->sk_receive_queue.lock);
st = po->stats;
- memset(&po->stats, 0, sizeof(st));
spin_unlock_bh(&sk->sk_receive_queue.lock);
st.tp_packets += st.tp_drops;
--- x/include/linux/if_packet.h 2005-10-27 19:02:08.000000000 -0500
+++ y/include/linux/if_packet.h 2005-11-28 21:49:37.000000000 -0600
@@ -38,7 +38,8 @@ struct sockaddr_ll
/* Value 4 is still used by obsolete turbo-packet. */
#define PACKET_RX_RING 5
#define PACKET_STATISTICS 6
-#define PACKET_COPY_THRESH 7
+#define PACKET_RESET_STATISTICS 7
+#define PACKET_COPY_THRESH 8
struct tpacket_stats
{
next reply other threads:[~2005-11-29 3:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-29 3:55 Kris Katterjohn [this message]
2005-11-29 6:12 ` David S. Miller
2005-11-29 6:28 Kris Katterjohn
2005-11-29 7:02 ` David S. Miller
2005-11-29 9:20 Kris Katterjohn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9188864830a243e8a5ed8ce75d1b098f.kjak@ispwest.com \
--to=kjak@ispwest.com \
--cc=kjak@users.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@osdl.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®