From: YOSHIFUJI Hideaki Sent: 1/24/2006 3:20:32 PM > We can merge PACKET_AUTO_STATISTICS and PACKET_MANUAL_STATISTICS, > into one, e.g. PACKET_ACCUMULATED_STATISTICS, and we can reuse > PACKET_STATISTICS for resetting; > case PACKET_ACCUMULATED_STATISTICS: > { > int val; > if (len < sizeof(val)) > return -EINVAL; > if (copy_from_user(&val, optval, len)) > return -EFAULT; > po->auto_reset_stats = val; > return 0; > } > > case PACKET_STATISTICS: > 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; > > And, please provide getsockopt side. Thanks. > > --yoshfuji
This compiled fine, but is untested do to -rc1-git4 totally screwing up. It let me do almost nothing. I could test it on an earlier version (say -rc1) if it would be useful. I wasn't exactly sure what to do when writing the getsockopt ACCUMULATE, but I think I got it right. Signed-off-by: Kris Katterjohn <[EMAIL PROTECTED]> --- x/net/packet/af_packet.c 2006-01-24 18:27:41.000000000 -0600 +++ y/net/packet/af_packet.c 2006-01-24 18:02:21.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_ACCUMULATE_STATISTICS + * [gs]etsockopt options and added + * PACKET_STATISTICS setsockopt option. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -190,6 +193,7 @@ struct packet_sock { /* struct sock has to be the first member of packet_sock */ struct sock sk; struct tpacket_stats stats; + int accumulate_stats; #ifdef CONFIG_PACKET_MMAP char * *pg_vec; unsigned int head; @@ -1021,6 +1025,7 @@ static int packet_create(struct socket * po = pkt_sk(sk); sk->sk_family = PF_PACKET; po->num = protocol; + po->accumulate_stats = 0; sk->sk_destruct = packet_sock_destruct; atomic_inc(&packet_socks_nr); @@ -1325,6 +1330,7 @@ static int packet_setsockopt(struct socket *sock, int level, int optname, char __user *optval, int optlen) { struct sock *sk = sock->sk; + struct packet_sock *po = pkt_sk(sk); int ret; if (level != SOL_PACKET) @@ -1353,6 +1359,26 @@ packet_setsockopt(struct socket *sock, i return ret; } #endif + + case PACKET_ACCUMULATE_STATISTICS: + { + int val; + + if (optlen != sizeof val) + return -EINVAL; + if (copy_from_user(&val, optval, optlen)) + return -EFAULT; + + po->accumulate_stats = !!val; + return 0; + } + + case PACKET_STATISTICS: + 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: { @@ -1399,6 +1425,15 @@ static int packet_getsockopt(struct sock return -EINVAL; switch(optname) { + case PACKET_ACCUMULATE_STATISTICS: + { + if (len != sizeof po->accumulate_stats) + return -EINVAL; + if (copy_to_user(optval, &po->accumulate_stats, len)) + return -EFAULT; + break; + } + case PACKET_STATISTICS: { struct tpacket_stats st; @@ -1407,7 +1442,8 @@ 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)); + if (!po->accumulate_stats) + memset(&po->stats, 0, sizeof po->stats); spin_unlock_bh(&sk->sk_receive_queue.lock); st.tp_packets += st.tp_drops; --- x/include/linux/if_packet.h 2006-01-24 18:27:41.000000000 -0600 +++ y/include/linux/if_packet.h 2006-01-24 17:50:02.000000000 -0600 @@ -37,8 +37,9 @@ struct sockaddr_ll #define PACKET_RECV_OUTPUT 3 /* 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_ACCUMULATE_STATISTICS 6 +#define PACKET_STATISTICS 7 +#define PACKET_COPY_THRESH 8 struct tpacket_stats { - To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html