From: YOSHIFUJI Hideaki
Sent: 1/25/2006 7:32:09 AM
> Hello.
> 
> In article <[EMAIL PROTECTED]> (at Tue, 24 Jan 2006 16:38:26 -0800), "Kris 
> Katterjohn" <[EMAIL PROTECTED]> says:
> 
> > +           if (optlen != sizeof val)
>                               sizeof(val)
> 
> Please use "sizeof(foo)" instead of "sizeof foo".
> 
> > --- 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
> 
> Don't change values. Just add
>    #define PACKET_ACCUMULATE_STATISTICS 8

Okey-dokey.

I asked before when I sent the original patch to linux-kernel if it was okay to
change the values, but never got an answer back (then I sent it here to netdev a
little later when I got a clue :)). I guess I forgot to ask it again.

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-25 11:00:34.000000000 -0600
@@ -39,6 +39,7 @@ struct sockaddr_ll
 #define PACKET_RX_RING                 5
 #define PACKET_STATISTICS              6
 #define PACKET_COPY_THRESH             7
+#define PACKET_ACCUMULATE_STATISTICS   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

Reply via email to