[PATCH] Fix tcp_v4_send_synack() comment

2008-02-13 Thread Kris Katterjohn

Hey everyone,

I've attached a patch that fixes the comment above tcp_v4_send_synack() 
in ipv4/tcp_ipv4.c.


Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

Thanks,
Kris Katterjohn
--- net/ipv4/tcp_ipv4.c	2008-02-10 23:51:11.0 -0600
+++ net/ipv4/tcp_ipv4.c	2008-02-13 18:31:44.0 -0600
@@ -735,7 +735,7 @@ static void tcp_v4_reqsk_send_ack(struct
 }
 
 /*
- *	Send a SYN-ACK after having received an ACK.
+ *	Send a SYN-ACK after having received a SYN.
  *	This still operates on a request_sock only, not on a big
  *	socket.
  */


[PATCH] Reorder ACK/RST checking in LISTEN state

2008-02-12 Thread Kris Katterjohn

Hey everyone,

[I'm not subscribed, so please CC me on any replies]

I've attached a patch that changes the order of the ACK and RST checking 
in the LISTEN state in tcp_rcv_state_process() in tcp_input.c


Before:  If an ACK/RST packet is received, then tcp_rcv_state_process() 
would return 1 because of the ACK.  Then (following the function calls 
in tcp_ipv4.c and tcp_minisocks.c), tcp_v4_send_reset() is called--but 
since there is a RST in the packet it just returns.  After this, the 
kfree_skb() is called.  The same goes in tcp_ipv6.c as well.


But if the order of the ACK and RST checking is reversed, __kfree_skb() 
is called in tcp_rcv_state_process() because of the RST and the function 
returns 0, which skips that other useless stuff.


This is the order specified on page 65 of RFC 793 anyway.

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

Thanks,
Kris Katterjohn
--- net/ipv4/tcp_input.c	2008-02-13 00:05:59.0 -0600
+++ net/ipv4/tcp_input.c	2008-02-13 00:10:40.0 -0600
@@ -4962,12 +4962,12 @@ int tcp_rcv_state_process(struct sock *s
 		goto discard;
 
 	case TCP_LISTEN:
-		if (th-ack)
-			return 1;
-
 		if (th-rst)
 			goto discard;
 
+		if (th-ack)
+			return 1;
+
 		if (th-syn) {
 			if (icsk-icsk_af_ops-conn_request(sk, skb)  0)
 return 1;


[PATCH (final?)] Additional options for resetting packet statistics

2006-01-27 Thread Kris Katterjohn
Okay, it's probably now or never for this patch :)

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]
Signed-off-by: YOSHIFUJI Hideaki [EMAIL PROTECTED]

--- x/net/packet/af_packet.c2006-01-25 22:18:41.0 -0600
+++ y/net/packet/af_packet.c2006-01-25 22:18:57.0 -0600
@@ -190,6 +190,7 @@ struct packet_sock {
/* struct sock has to be the first member of packet_sock */
struct sock sk;
struct tpacket_statsstats;
+   int accumulate_stats;
 #ifdef CONFIG_PACKET_MMAP
char *  *pg_vec;
unsigned inthead;
@@ -1325,6 +1326,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 +1355,28 @@ packet_setsockopt(struct socket *sock, i
return ret;
}
 #endif
+
+   case PACKET_ACCUMULATE_STATISTICS:
+   {
+   int val;
+
+   if (optlen  sizeof(val))
+   return -EINVAL;
+   if (optlen  sizeof(val))
+   optlen = sizeof(val);
+   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 +1423,15 @@ static int packet_getsockopt(struct sock
return -EINVAL;

switch(optname) {
+   case PACKET_ACCUMULATE_STATISTICS:
+   {
+   if (len  sizeof(po-accumulate_stats))
+   len = sizeof(po-accumulate_stats);
+   if (copy_to_user(optval, po-accumulate_stats, len))
+   return -EFAULT;
+   break;
+   }
+
case PACKET_STATISTICS:
{
struct tpacket_stats st;
@@ -1407,7 +1440,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.0 -0600
+++ y/include/linux/if_packet.h 2006-01-25 11:00:34.0 -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


Re: [PATCH] Additional options for resetting packet statistics

2006-01-25 Thread Kris Katterjohn
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.0 -0600
  +++ y/include/linux/if_packet.h 2006-01-24 17:50:02.0 -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.c2006-01-24 18:27:41.0 -0600
+++ y/net/packet/af_packet.c2006-01-24 18:02:21.0 -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_statsstats;
+   int accumulate_stats;
 #ifdef CONFIG_PACKET_MMAP
char *  *pg_vec;
unsigned inthead;
@@ -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.0 -0600
+++ y/include/linux/if_packet.h 2006-01-25 11:00:34.0 -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

[PATCH (ready to apply?)] Additional options for resetting packet statistics

2006-01-25 Thread Kris Katterjohn
From: YOSHIFUJI Hideaki
Sent: 1/25/2006 1:34:19 PM
 Hello.
 
 In article [EMAIL PROTECTED] (at Wed, 25 Jan 2006 09:13:26 -0800), Kris 
 Katterjohn [EMAIL PROTECTED] says:
 
 
  +
  +   case PACKET_ACCUMULATE_STATISTICS:
  +   {
  +   int val;
  +
  +   if (optlen != sizeof(val))
  +   return -EINVAL;
 
 I think this is too strict.
 if (optlen  sizeof(val))
 return -EINVAL;
 if (optlen  sizeof(val))
 optlen = sizeof(val);
 
  +   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;
 
 This does not conform to POSIX.
 
 if (len  sizeof(po-accumulate_stats))
 len = sizeof(po-accumulate_stats);
 
 
 Otherwise, it seems fine to me.
 
 Signed-off-by: YOSHIFUJI Hideaki [EMAIL PROTECTED]

Okey-dokey.

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

--- x/net/packet/af_packet.c2006-01-25 15:48:17.0 -0600
+++ y/net/packet/af_packet.c2006-01-25 15:48:12.0 -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_statsstats;
+   int accumulate_stats;
 #ifdef CONFIG_PACKET_MMAP
char *  *pg_vec;
unsigned inthead;
@@ -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,28 @@ packet_setsockopt(struct socket *sock, i
return ret;
}
 #endif
+
+   case PACKET_ACCUMULATE_STATISTICS:
+   {
+   int val;
+
+   if (optlen  sizeof(val))
+   return -EINVAL;
+   if (optlen  sizeof(val))
+   optlen = sizeof(val);
+   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 +1427,17 @@ static int packet_getsockopt(struct sock
return -EINVAL;

switch(optname) {
+   case PACKET_ACCUMULATE_STATISTICS:
+   {
+   if (len  sizeof(po-accumulate_stats))
+   return -EINVAL;
+   if (len  sizeof(po-accumulate_stats))
+   len = sizeof(po-accumulate_stats);
+   if (copy_to_user(optval, po-accumulate_stats, len))
+   return -EFAULT;
+   break;
+   }
+
case PACKET_STATISTICS:
{
struct tpacket_stats st;
@@ -1407,7 +1446,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

Re: [PATCH (ready to apply?)] Additional options for resettingpacket statistics

2006-01-25 Thread Kris Katterjohn
From: Herbert Xu
Sent: 1/25/2006 6:45:50 PM
 Kris Katterjohn [EMAIL PROTECTED] wrote:
 
  @@ -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;
 
 This is unnecessary as sk_alloc zeros the whole structure.
 
 Cheers,

Okay.


From: jamal
Sent: 1/25/2006 6:52:55 PM
 On Wed, 2006-25-01 at 13:57 -0800, Kris Katterjohn wrote:
 
  Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]
  
  --- x/net/packet/af_packet.c2006-01-25 15:48:17.0 -0600
  +++ y/net/packet/af_packet.c2006-01-25 15:48:12.0 -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 looks old school friend. Your name and comments go in the log text
 and not in the source file.
 
 cheers,
 jamal

Okay.

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

--- x/net/packet/af_packet.c2006-01-25 21:33:08.0 -0600
+++ y/net/packet/af_packet.c2006-01-25 21:32:42.0 -0600
@@ -190,6 +190,7 @@ struct packet_sock {
/* struct sock has to be the first member of packet_sock */
struct sock sk;
struct tpacket_statsstats;
+   int accumulate_stats;
 #ifdef CONFIG_PACKET_MMAP
char *  *pg_vec;
unsigned inthead;
@@ -1325,6 +1326,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 +1355,28 @@ packet_setsockopt(struct socket *sock, i
return ret;
}
 #endif
+
+   case PACKET_ACCUMULATE_STATISTICS:
+   {
+   int val;
+
+   if (optlen  sizeof(val))
+   return -EINVAL;
+   if (optlen  sizeof(val))
+   optlen = sizeof(val);
+   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 +1423,17 @@ static int packet_getsockopt(struct sock
return -EINVAL;

switch(optname) {
+   case PACKET_ACCUMULATE_STATISTICS:
+   {
+   if (len  sizeof(po-accumulate_stats))
+   return -EINVAL;
+   if (len  sizeof(po-accumulate_stats))
+   len = sizeof(po-accumulate_stats);
+   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.0 -0600
+++ y/include/linux/if_packet.h 2006-01-25 11:00:34.0 -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


Re: [PATCH (ready to apply?)] Additional options forresettingpacket statistics

2006-01-25 Thread Kris Katterjohn
From: YOSHIFUJI Hideaki
Sent: 1/25/2006 7:50:55 PM
 In article [EMAIL PROTECTED] (at Wed, 25 Jan 2006 19:46:07 -0800), Kris 
 Katterjohn [EMAIL PROTECTED] says:
 
  @@ -1399,6 +1423,17 @@ static int packet_getsockopt(struct sock
  return -EINVAL;
  
  switch(optname) {
  +   case PACKET_ACCUMULATE_STATISTICS:
  +   {
  +   if (len  sizeof(po-accumulate_stats))
  +   return -EINVAL;
  +   if (len  sizeof(po-accumulate_stats))
  +   len = sizeof(po-accumulate_stats);
  +   if (copy_to_user(optval, po-accumulate_stats, len))
  +   return -EFAULT;
  +   break;
  +   }
  +
 
 For getsockopt(), you need to truncate the value instead of returning -EINVAL
 if optlen len is not enough.  Thus, remove
 if (len  sizeof(po-accumulate_stats)) return -EINVAL;.
 
 Thanks.
 
 --yoshfuji

Okey-dokey.

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

--- x/net/packet/af_packet.c2006-01-25 22:18:41.0 -0600
+++ y/net/packet/af_packet.c2006-01-25 22:18:57.0 -0600
@@ -190,6 +190,7 @@ struct packet_sock {
/* struct sock has to be the first member of packet_sock */
struct sock sk;
struct tpacket_statsstats;
+   int accumulate_stats;
 #ifdef CONFIG_PACKET_MMAP
char *  *pg_vec;
unsigned inthead;
@@ -1325,6 +1326,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 +1355,28 @@ packet_setsockopt(struct socket *sock, i
return ret;
}
 #endif
+
+   case PACKET_ACCUMULATE_STATISTICS:
+   {
+   int val;
+
+   if (optlen  sizeof(val))
+   return -EINVAL;
+   if (optlen  sizeof(val))
+   optlen = sizeof(val);
+   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 +1423,15 @@ static int packet_getsockopt(struct sock
return -EINVAL;

switch(optname) {
+   case PACKET_ACCUMULATE_STATISTICS:
+   {
+   if (len  sizeof(po-accumulate_stats))
+   len = sizeof(po-accumulate_stats);
+   if (copy_to_user(optval, po-accumulate_stats, len))
+   return -EFAULT;
+   break;
+   }
+
case PACKET_STATISTICS:
{
struct tpacket_stats st;
@@ -1407,7 +1440,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.0 -0600
+++ y/include/linux/if_packet.h 2006-01-25 11:00:34.0 -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


Re: [PATCH] Additional options for resetting packet statistics

2006-01-24 Thread Kris Katterjohn
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.c2006-01-24 18:27:41.0 -0600
+++ y/net/packet/af_packet.c2006-01-24 18:02:21.0 -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_statsstats;
+   int accumulate_stats;
 #ifdef CONFIG_PACKET_MMAP
char *  *pg_vec;
unsigned inthead;
@@ -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.0 -0600
+++ y/include/linux/if_packet.h 2006-01-24 17:50:02.0 -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

Re: [PATCH] Additional options for resetting packet statistics

2006-01-24 Thread Kris Katterjohn
From: Kris Katterjohn
Sent: 1/24/2006 4:38:26 PM
 --- x/include/linux/if_packet.h   2006-01-24 18:27:41.0 -0600
 +++ y/include/linux/if_packet.h   2006-01-24 17:50:02.0 -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_STATISTICS6
 -#define PACKET_COPY_THRESH   7
 +#define PACKET_ACCUMULATE_STATISTICS 6
 
 +#define PACKET_STATISTICS7
 +#define PACKET_COPY_THRESH   8
  
  struct tpacket_stats
  {

Whoops, I guess I accidentally hit ENTER there between ACCUMULATE_STATISTICS and
STATISTICS. Sorry.

-
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


Re: [PATCH] Put SKF_* definitions inside '#ifdef __KERNEL__' in linux/filter.h

2006-01-20 Thread Kris Katterjohn
From: Herbert Xu
Sent: 1/20/2006 1:51:56 AM
 Kris Katterjohn [EMAIL PROTECTED] wrote:
  This wraps '#ifdef __KERNEL__' around the definitions for SKF_* in 
  linux/filter.h
 
 Why? The whole point these macros are here is so that user-space can
 use them.

I was reading filter.h and I noticed that the SKF_* definitions weren't inside 
the
#ifdef __KERNEL__, so I thought about why a user would need it if it only 
handles
ancillary data. I couldn't think of a reason, so I googled a bit and didn't find
anything that convinced me that user's would be using it. So I moved the #ifdef
and sent in the patch. After I saw your email this morning I googled again for a
few minutes and finally saw that SKF_AD_OFF and SKF_AD_PROTOCOL were used by
pcap-linux.c.

Whoopsie. Thanks.

-
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


[PATCH] Fix more whitespace issues in net/core/filter.c

2006-01-20 Thread Kris Katterjohn
This fixes some whitespace issues in net/core/filter.c

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

Thanks.

--- x/net/core/filter.c 2006-01-20 18:15:19.0 -0600
+++ y/net/core/filter.c 2006-01-20 18:48:48.0 -0600
@@ -64,7 +64,7 @@ static inline void *load_pointer(struct 
 }
 
 /**
- * sk_run_filter   -   run a filter on a socket
+ * sk_run_filter - run a filter on a socket
  * @skb: buffer to run the filter on
  * @filter: filter to apply
  * @flen: length of filter
@@ -78,8 +78,8 @@ unsigned int sk_run_filter(struct sk_buf
 {
struct sock_filter *fentry; /* We walk down these */
void *ptr;
-   u32 A = 0;  /* Accumulator */
-   u32 X = 0;  /* Index Register */
+   u32 A = 0;  /* Accumulator */
+   u32 X = 0;  /* Index Register */
u32 mem[BPF_MEMWORDS];  /* Scratch Memory Store */
u32 tmp;
int k;


-
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


[PATCH] Fix some whitespace issues in af_packet.c

2006-01-20 Thread Kris Katterjohn
This fixes some whitespace issues in af_packet.c

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

Thanks.

--- x/net/packet/af_packet.c2006-01-18 15:16:05.0 -0600
+++ y/net/packet/af_packet.c2006-01-20 18:53:18.0 -0600
@@ -365,7 +365,7 @@ static int packet_sendmsg_spkt(struct ki
 */
 
err = -EMSGSIZE;
-   if(lendev-mtu+dev-hard_header_len)
+   if(lendev-mtu+dev-hard_header_len)
goto out_unlock;
 
err = -ENOBUFS;
@@ -1392,8 +1392,8 @@ static int packet_getsockopt(struct sock
if (level != SOL_PACKET)
return -ENOPROTOOPT;
 
-   if (get_user(len,optlen))
-   return -EFAULT;
+   if (get_user(len,optlen))
+   return -EFAULT;
 
if (len  0)
return -EINVAL;
@@ -1419,9 +1419,9 @@ static int packet_getsockopt(struct sock
return -ENOPROTOOPT;
}
 
-   if (put_user(len, optlen))
-   return -EFAULT;
-   return 0;
+   if (put_user(len, optlen))
+   return -EFAULT;
+   return 0;
 }
 
 


-
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


Re: [PATCH] Fix some whitespace issues in af_packet.c

2006-01-20 Thread Kris Katterjohn
From: Joe Perches
Sent: 1/20/2006 7:21:59 PM
 On Fri, 2006-01-20 at 17:44 -0800, Ben Greear wrote:
  Kris Katterjohn wrote:
   This fixes some whitespace issues in af_packet.c
 
 Perhaps this instead?
 
 Whitespace
 comment wrapping to  80 columns
 remove unnecessary assigns
 remove unnecessary parentheses from returns
 add KERN_INFO to printk
 move 1 assign out of an if

Hmm.. I suppose that'd work too :)

-
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


[PATCH] Add KERN_INFO to printk()s in pktgen.c

2006-01-20 Thread Kris Katterjohn
This adds KERN_INFO to bare printk()s in pktgen.c

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

Thanks.

--- x/net/core/pktgen.c 2006-01-20 21:51:08.0 -0600
+++ y/net/core/pktgen.c 2006-01-20 21:51:03.0 -0600
@@ -415,7 +415,7 @@ static inline __u64 tv_to_us(const struc
 static inline __u64 pg_div(__u64 n, __u32 base) {
 __u64 tmp = n;
 do_div(tmp, base);
-/* printk(pktgen: pg_div, n: %llu  base: %d  rv: %llu\n,
+/* printk(KERN_INFO pktgen: pg_div, n: %llu  base: %d  rv: %llu\n,
   n, base, tmp); */
 return tmp;
 }
@@ -536,7 +536,7 @@ static ssize_t pgctrl_write(struct file*
pktgen_run_all_threads();
 
else 
-   printk(pktgen: Unknown command: %s\n, data);
+   printk(KERN_INFO pktgen: Unknown command: %s\n, data);
 
err = count;
 
@@ -765,14 +765,14 @@ static ssize_t pktgen_if_write(struct fi
 pg_result = (pkt_dev-result[0]);
 
if (count  1) {
-   printk(pktgen: wrong command format\n);
+   printk(KERN_INFO pktgen: wrong command format\n);
return -EINVAL;
}
   
max = count - i;
tmp = count_trail_chars(user_buffer[i], max);
 if (tmp  0) { 
-   printk(pktgen: illegal format\n);
+   printk(KERN_INFO pktgen: illegal format\n);
return tmp; 
}
 i += tmp;
@@ -798,7 +798,7 @@ static ssize_t pktgen_if_write(struct fi
 if (copy_from_user(tb, user_buffer, count))
return -EFAULT;
 tb[count] = 0;
-   printk(pktgen: %s,%lu  buffer -:%s:-\n, name,
+   printk(KERN_INFO pktgen: %s,%lu  buffer -:%s:-\n, name,
   (unsigned long) count, tb);
 }
 
@@ -1035,7 +1035,8 @@ static ssize_t pktgen_if_write(struct fi
 pkt_dev-cur_daddr = pkt_dev-daddr_min;
 }
 if(debug)
-printk(pktgen: dst_min set to: %s\n, 
pkt_dev-dst_min);
+printk(KERN_INFO pktgen: dst_min set to: %s\n,
+   pkt_dev-dst_min);
 i += len;
sprintf(pg_result, OK: dst_min=%s, pkt_dev-dst_min);
return count;
@@ -1055,7 +1056,8 @@ static ssize_t pktgen_if_write(struct fi
 pkt_dev-cur_daddr = pkt_dev-daddr_max;
 }
if(debug)
-   printk(pktgen: dst_max set to: %s\n, 
pkt_dev-dst_max);
+   printk(KERN_INFO pktgen: dst_max set to: %s\n,
+  pkt_dev-dst_max);
i += len;
sprintf(pg_result, OK: dst_max=%s, pkt_dev-dst_max);
return count;
@@ -1076,7 +1078,7 @@ static ssize_t pktgen_if_write(struct fi
ipv6_addr_copy(pkt_dev-cur_in6_daddr, pkt_dev-in6_daddr);
 
 if(debug) 
-   printk(pktgen: dst6 set to: %s\n, buf);
+   printk(KERN_INFO pktgen: dst6 set to: %s\n, buf);
 
 i += len;
sprintf(pg_result, OK: dst6=%s, buf);
@@ -1097,7 +1099,7 @@ static ssize_t pktgen_if_write(struct fi
 
ipv6_addr_copy(pkt_dev-cur_in6_daddr, 
pkt_dev-min_in6_daddr);
 if(debug) 
-   printk(pktgen: dst6_min set to: %s\n, buf);
+   printk(KERN_INFO pktgen: dst6_min set to: %s\n, buf);
 
 i += len;
sprintf(pg_result, OK: dst6_min=%s, buf);
@@ -1117,7 +1119,7 @@ static ssize_t pktgen_if_write(struct fi
fmt_ip6(buf,  pkt_dev-max_in6_daddr.s6_addr);
 
 if(debug) 
-   printk(pktgen: dst6_max set to: %s\n, buf);
+   printk(KERN_INFO pktgen: dst6_max set to: %s\n, buf);
 
 i += len;
sprintf(pg_result, OK: dst6_max=%s, buf);
@@ -1139,7 +1141,7 @@ static ssize_t pktgen_if_write(struct fi
ipv6_addr_copy(pkt_dev-cur_in6_saddr, pkt_dev-in6_saddr);
 
 if(debug) 
-   printk(pktgen: src6 set to: %s\n, buf);
+   printk(KERN_INFO pktgen: src6 set to: %s\n, buf);

 i += len;
sprintf(pg_result, OK: src6=%s, buf);
@@ -1158,7 +1160,8 @@ static ssize_t pktgen_if_write(struct fi
 pkt_dev-cur_saddr = pkt_dev-saddr_min;
 }
if(debug)
-   printk(pktgen: src_min set to: %s\n, 
pkt_dev-src_min);
+   printk(KERN_INFO pktgen: src_min set to: %s\n,
+  pkt_dev-src_min);
i += len;
sprintf(pg_result, OK: src_min=%s, pkt_dev-src_min);
return count;
@@ -1176,7 +1179,8 @@ static ssize_t pktgen_if_write(struct fi

[PATCH] Put SKF_* definitions inside '#ifdef __KERNEL__' in linux/filter.h

2006-01-19 Thread Kris Katterjohn
This wraps '#ifdef __KERNEL__' around the definitions for SKF_* in 
linux/filter.h

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

Thanks.

--- x/include/linux/filter.h2006-01-18 15:16:02.0 -0600
+++ y/include/linux/filter.h2006-01-19 20:44:06.0 -0600
@@ -126,6 +126,7 @@ static inline unsigned int sk_filter_len
  */
 #define BPF_MEMWORDS 16
 
+#ifdef __KERNEL__
 /* RATIONALE. Negative offsets are invalid in BPF.
We use them to reference ancillary data.
Unlike introduction new instructions, it does not break
@@ -139,7 +140,6 @@ static inline unsigned int sk_filter_len
 #define SKF_NET_OFF   (-0x10)
 #define SKF_LL_OFF(-0x20)
 
-#ifdef __KERNEL__
 struct sk_buff;
 struct sock;
 


-
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


Re: [PATCH] Remove MANY unneeded header files in net/core/filter.c

2006-01-18 Thread Kris Katterjohn
From: Herbert Xu
Sent: 1/18/2006 1:28:38 AM
 Kris Katterjohn [EMAIL PROTECTED] wrote:
  
  -#include linux/module.h
 
 Well I decided to double-check your patch.  It seems that the very first
 removal is bogus.  This file is needed for EXPORT_SYMBOL.
 
 Please recheck the rest.

Since it can't be a module and is always built in, we can just remove the
EXPORT_SYMBOL()s, right?

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

--- x/net/core/filter.c 2006-01-18 08:35:22.0 -0600
+++ y/net/core/filter.c 2006-01-18 08:35:04.0 -0600
@@ -422,5 +422,3 @@ int sk_attach_filter(struct sock_fprog *
return err;
 }
 
-EXPORT_SYMBOL(sk_chk_filter);
-EXPORT_SYMBOL(sk_run_filter);


-
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


Re: [PATCH] Remove MANY unneeded header files in net/core/filter.c

2006-01-18 Thread Kris Katterjohn
From: Herbert Xu
Sent: 1/18/2006 12:26:12 PM
 On Wed, Jan 18, 2006 at 06:42:06AM -0800, Kris Katterjohn wrote:
  
  Since it can't be a module and is always built in, we can just remove the
  EXPORT_SYMBOL()s, right?
 
 No, these are there so that other modules can use these symboles.

Okay, gotcha.

I went through again and I'm pretty confident in this patch. I added a few 
headers, some of which whose #includes were nested 2/3 files into others.

Let me know what you think (or if you see any obvious screwups). Thanks!

--- x/net/core/filter.c 2006-01-18 16:08:42.0 -0600
+++ y/net/core/filter.c 2006-01-18 16:08:36.0 -0600
@@ -18,21 +18,12 @@
 
 #include linux/module.h
 #include linux/types.h
-#include linux/sched.h
-#include linux/mm.h
-#include linux/fcntl.h
-#include linux/socket.h
-#include linux/in.h
-#include linux/inet.h
-#include linux/netdevice.h
-#include linux/if_packet.h
-#include net/ip.h
-#include net/protocol.h
 #include linux/skbuff.h
 #include net/sock.h
 #include linux/errno.h
-#include linux/timer.h
-#include asm/system.h
+#include asm/atomic.h
+#include asm/bug.h
+#include asm/byteorder.h
 #include asm/uaccess.h
 #include linux/filter.h
 


-
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


Re: [PATCH] Remove MANY unneeded header files in net/core/filter.c

2006-01-18 Thread Kris Katterjohn
From: Herbert Xu
Sent: 1/18/2006 4:02:18 PM
 On Wed, Jan 18, 2006 at 02:15:37PM -0800, Kris Katterjohn wrote:
   
   #include linux/module.h
   #include linux/types.h
  -#include linux/sched.h
 
 OK.
 
  -#include linux/mm.h
 
 Needed for GFP_*.  Replace this with gfp.h if you want.
 
  -#include linux/fcntl.h
  -#include linux/socket.h
  -#include linux/in.h
  -#include linux/inet.h
 
 OK.
 
  -#include linux/netdevice.h
 
 We need this for skb-dev-ifindex.

But we know we have struct net_device because it's used in linux/skbuff.h (for
skb-dev of course). I'm not saying it doesn't make sense, just that it seems to
me that it's probably not needed. No matter, though.

  -#include linux/if_packet.h
  -#include net/ip.h
  -#include net/protocol.h
 
 OK.
 
  -#include linux/timer.h
 
 OK, but you should add linux/spinlock.h.
 
  -#include asm/system.h
  +#include asm/atomic.h
  +#include asm/bug.h
  +#include asm/byteorder.h
 
 Looks good.
 
 Thanks,

All righty then.

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

--- x/net/core/filter.c 2006-01-18 18:28:44.0 -0600
+++ y/net/core/filter.c 2006-01-18 18:28:33.0 -0600
@@ -18,21 +18,15 @@
 
 #include linux/module.h
 #include linux/types.h
-#include linux/sched.h
-#include linux/mm.h
-#include linux/fcntl.h
-#include linux/socket.h
-#include linux/in.h
-#include linux/inet.h
 #include linux/netdevice.h
-#include linux/if_packet.h
-#include net/ip.h
-#include net/protocol.h
 #include linux/skbuff.h
+#include linux/gfp.h
 #include net/sock.h
 #include linux/errno.h
-#include linux/timer.h
-#include asm/system.h
+#include linux/spinlock.h
+#include asm/atomic.h
+#include asm/bug.h
+#include asm/byteorder.h
 #include asm/uaccess.h
 #include linux/filter.h
 


-
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


[PATCH] Remove MANY unneeded header files in net/core/filter.c

2006-01-17 Thread Kris Katterjohn
This removes many unneeded header files in net/core/filter.c

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

This is a diff against -rc1.

This compiles fine with no warnings and seems to run perfectly fine.

Are there any headers I'm deleting that _should_ be there, but not necessarily
required for a clean compilation? If so, let me know and I'll redo the patch.

Thanks!

--- x/net/core/filter.c 2006-01-17 10:54:42.0 -0600
+++ y/net/core/filter.c 2006-01-17 10:55:01.0 -0600
@@ -16,24 +16,9 @@
  * Kris Katterjohn - Added many additional checks in sk_chk_filter()
  */
 
-#include linux/module.h
-#include linux/types.h
-#include linux/sched.h
-#include linux/mm.h
-#include linux/fcntl.h
-#include linux/socket.h
-#include linux/in.h
-#include linux/inet.h
-#include linux/netdevice.h
-#include linux/if_packet.h
-#include net/ip.h
-#include net/protocol.h
 #include linux/skbuff.h
 #include net/sock.h
 #include linux/errno.h
-#include linux/timer.h
-#include asm/system.h
-#include asm/uaccess.h
 #include linux/filter.h
 
 /* No hurry in this branch */


-
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


[PATCH] Use is_zero_ether_addr() in net/core/netpoll.c

2006-01-17 Thread Kris Katterjohn
This replaces a memcmp() with is_zero_ether_addr().

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

Thanks!

--- x/net/core/netpoll.c2006-01-17 08:25:32.0 -0600
+++ y/net/core/netpoll.c2006-01-17 15:45:01.0 -0600
@@ -703,7 +703,7 @@ int netpoll_setup(struct netpoll *np)
}
}
 
-   if (!memcmp(np-local_mac, \0\0\0\0\0\0, 6)  ndev-dev_addr)
+   if (is_zero_ether_addr(np-local_mac)  ndev-dev_addr)
memcpy(np-local_mac, ndev-dev_addr, 6);
 
if (!np-local_ip) {


-
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


Re: [PATCH] Remove MANY unneeded header files in net/core/filter.c

2006-01-17 Thread Kris Katterjohn
From: David S. Miller
Sent: 1/17/2006 3:18:08 PM
 From: Kris Katterjohn [EMAIL PROTECTED]
 Date: Tue, 17 Jan 2006 09:03:22 -0800
 
  Are there any headers I'm deleting that _should_ be there, but not
  necessarily required for a clean compilation? If so, let me know and
  I'll redo the patch.
 
 If the build still works, that doesn't mean much :-)
 
 Often you get the necessary headers by accident through another header
 you are actually including.
 
 The only tried and true way to go about this is to really look at what
 interfaces and data types the whole C file uses and make sure the
 necessary headers are there.
 
 Other folks take another approach, wherein you pick a specific header
 file or interface, and walk over the tree making sure the header is
 used where it is needed and only where it is needed.
 
 It would be nice to automate this, but that's not easy.

I went through and after following the structures, macros and functions, I was
still able to strip out most of the #includes.

You may want to double check, but these are the things that require extra
headers:

u32
struct sk_buff
struct sk_filter
struct sock_fprog
struct sock_filter
skb_header_pointer()
ntohl()/ntohs()/htons()
sock_kmalloc()
spin_lock_bh()/spin_unlock_bh()
atomic_set()
copy_from_user()
BPF_*
SKF_*_OFF

..and all are accounted for in the remaining headers.

And, yes, it would be very nice to automate this :)

Thanks!

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

--- x/net/core/filter.c 2006-01-17 19:36:06.0 -0600
+++ y/net/core/filter.c 2006-01-17 20:22:25.0 -0600
@@ -16,23 +16,11 @@
  * Kris Katterjohn - Added many additional checks in sk_chk_filter()
  */
 
-#include linux/module.h
 #include linux/types.h
-#include linux/sched.h
 #include linux/mm.h
-#include linux/fcntl.h
-#include linux/socket.h
-#include linux/in.h
-#include linux/inet.h
-#include linux/netdevice.h
-#include linux/if_packet.h
-#include net/ip.h
-#include net/protocol.h
 #include linux/skbuff.h
 #include net/sock.h
 #include linux/errno.h
-#include linux/timer.h
-#include asm/system.h
 #include asm/uaccess.h
 #include linux/filter.h
 


-
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


[PATCH] Replacing with (compare|is_zero)_ether_addr() and ETH_ALEN in pktgen.c

2006-01-15 Thread Kris Katterjohn
This replaces some tests with is_zero_ether_addr(), memcmp(one, two, 6) with
compare_ether_addr(one, two), and 6 with ETH_ALEN where appropriate.

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

Thanks!

--- x/net/core/pktgen.c 2006-01-15 21:29:21.0 -0600
+++ y/net/core/pktgen.c 2006-01-15 21:33:24.0 -0600
@@ -139,6 +139,7 @@
 #include linux/proc_fs.h
 #include linux/seq_file.h
 #include linux/wait.h
+#include linux/etherdevice.h
 #include net/checksum.h
 #include net/ipv6.h
 #include net/addrconf.h
@@ -281,8 +282,8 @@ struct pktgen_dev {
 __u32 src_mac_count; /* How many MACs to iterate through */
 __u32 dst_mac_count; /* How many MACs to iterate through */
 
-unsigned char dst_mac[6];
-unsigned char src_mac[6];
+unsigned char dst_mac[ETH_ALEN];
+unsigned char src_mac[ETH_ALEN];
 
 __u32 cur_dst_mac_offset;
 __u32 cur_src_mac_offset;
@@ -594,16 +595,9 @@ static int pktgen_if_show(struct seq_fil
 
seq_puts(seq,  src_mac: );
 
-   if ((pkt_dev-src_mac[0] == 0)  
-   (pkt_dev-src_mac[1] == 0)  
-   (pkt_dev-src_mac[2] == 0)  
-   (pkt_dev-src_mac[3] == 0)  
-   (pkt_dev-src_mac[4] == 0)  
-   (pkt_dev-src_mac[5] == 0)) 
-
+   if (is_zero_ether_addr(pkt_dev-src_mac))
for (i = 0; i  6; i++) 
seq_printf(seq,  %02X%s, pkt_dev-odev-dev_addr[i], 
i == 5 ?: :);
-
else 
for (i = 0; i  6; i++) 
seq_printf(seq,  %02X%s, pkt_dev-src_mac[i], i == 5 
?: :);
@@ -1189,9 +1183,9 @@ static ssize_t pktgen_if_write(struct fi
}
if (!strcmp(name, dst_mac)) {
char *v = valstr;
-unsigned char old_dmac[6];
+   unsigned char old_dmac[ETH_ALEN];
unsigned char *m = pkt_dev-dst_mac;
-memcpy(old_dmac, pkt_dev-dst_mac, 6);
+   memcpy(old_dmac, pkt_dev-dst_mac, ETH_ALEN);
 
len = strn_len(user_buffer[i], sizeof(valstr) - 1);
 if (len  0) { return len; }
@@ -1220,8 +1214,8 @@ static ssize_t pktgen_if_write(struct fi
}
 
/* Set up Dest MAC */
-if (memcmp(old_dmac, pkt_dev-dst_mac, 6) != 0) 
-memcpy((pkt_dev-hh[0]), pkt_dev-dst_mac, 6);
+   if (compare_ether_addr(old_dmac, pkt_dev-dst_mac))
+   memcpy((pkt_dev-hh[0]), pkt_dev-dst_mac, ETH_ALEN);
 
sprintf(pg_result, OK: dstmac);
return count;
@@ -1560,17 +1554,11 @@ static void pktgen_setup_inject(struct p
 
 /* Default to the interface's mac if not explicitly set. */
 
-   if ((pkt_dev-src_mac[0] == 0)  
-   (pkt_dev-src_mac[1] == 0)  
-   (pkt_dev-src_mac[2] == 0)  
-   (pkt_dev-src_mac[3] == 0)  
-   (pkt_dev-src_mac[4] == 0)  
-   (pkt_dev-src_mac[5] == 0)) {
+   if (is_zero_ether_addr(pkt_dev-src_mac))
+  memcpy((pkt_dev-hh[6]), pkt_dev-odev-dev_addr, ETH_ALEN);
 
-  memcpy((pkt_dev-hh[6]), pkt_dev-odev-dev_addr, 6);
-   }
 /* Set up Dest MAC */
-memcpy((pkt_dev-hh[0]), pkt_dev-dst_mac, 6);
+   memcpy((pkt_dev-hh[0]), pkt_dev-dst_mac, ETH_ALEN);
 
 /* Set up pkt size */
 pkt_dev-cur_pkt_size = pkt_dev-min_pkt_size;


-
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


[PATCH] signed long - long

2006-01-14 Thread Kris Katterjohn
This changes signed long to long.

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

Thanks!

--- x/net/dccp/ackvec.c 2006-01-14 09:58:35.0 -0600
+++ y/net/dccp/ackvec.c 2006-01-14 10:17:24.0 -0600
@@ -144,7 +144,7 @@ static inline int dccp_ackvec_set_buf_he
 const unsigned char state)
 {
unsigned int gap;
-   signed long new_head;
+   long new_head;
 
if (av-dccpav_vec_len + packets  av-dccpav_buf_len)
return -ENOBUFS;

--- x/net/rxrpc/krxtimod.c  2006-01-02 21:21:10.0 -0600
+++ y/net/rxrpc/krxtimod.c  2006-01-14 10:17:29.0 -0600
@@ -81,7 +81,7 @@ static int krxtimod(void *arg)
 
for (;;) {
unsigned long jif;
-   signed long timeout;
+   long timeout;
 
/* deal with the server being asked to die */
if (krxtimod_die) {

--- x/net/rxrpc/proc.c  2006-01-02 21:21:10.0 -0600
+++ y/net/rxrpc/proc.c  2006-01-14 10:17:46.0 -0600
@@ -361,7 +361,7 @@ static void rxrpc_proc_peers_stop(struct
 static int rxrpc_proc_peers_show(struct seq_file *m, void *v)
 {
struct rxrpc_peer *peer = list_entry(v, struct rxrpc_peer, proc_link);
-   signed long timeout;
+   long timeout;
 
/* display header on line 1 */
if (v == SEQ_START_TOKEN) {
@@ -373,8 +373,8 @@ static int rxrpc_proc_peers_show(struct 
/* display one peer per line on subsequent lines */
timeout = 0;
if (!list_empty(peer-timeout.link))
-   timeout = (signed long) peer-timeout.timo_jif -
-   (signed long) jiffies;
+   timeout = (long) peer-timeout.timo_jif -
+   (long) jiffies;
 
seq_printf(m, %5hu %08x %5d %5d %8ld %5Zu %7lu\n,
   peer-trans-port,
@@ -468,7 +468,7 @@ static void rxrpc_proc_conns_stop(struct
 static int rxrpc_proc_conns_show(struct seq_file *m, void *v)
 {
struct rxrpc_connection *conn;
-   signed long timeout;
+   long timeout;
 
conn = list_entry(v, struct rxrpc_connection, proc_link);
 
@@ -484,8 +484,8 @@ static int rxrpc_proc_conns_show(struct 
/* display one conn per line on subsequent lines */
timeout = 0;
if (!list_empty(conn-timeout.link))
-   timeout = (signed long) conn-timeout.timo_jif -
-   (signed long) jiffies;
+   timeout = (long) conn-timeout.timo_jif -
+   (long) jiffies;
 
seq_printf(m,
   %5hu %08x %5hu %04hx %08x %-3.3s %08x %08x %5Zu %8ld\n,


-
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


[PATCH] Fix whitespace issues in net/core/filter.c

2006-01-14 Thread Kris Katterjohn
This fixes some whitespace issues in net/core/filter.c

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

Thanks!

--- x/net/core/filter.c 2006-01-14 10:06:40.0 -0600
+++ y/net/core/filter.c 2006-01-14 10:33:16.0 -0600
@@ -74,7 +74,6 @@ static inline void *load_pointer(struct 
  * filtering, filter is the array of filter instructions, and
  * len is the number of filter blocks in the array.
  */
- 
 unsigned int sk_run_filter(struct sk_buff *skb, struct sock_filter *filter, 
int flen)
 {
struct sock_filter *fentry; /* We walk down these */
@@ -175,7 +174,7 @@ unsigned int sk_run_filter(struct sk_buf
continue;
case BPF_LD|BPF_W|BPF_ABS:
k = fentry-k;
- load_w:
+load_w:
ptr = load_pointer(skb, k, 4, tmp);
if (ptr != NULL) {
A = ntohl(*(u32 *)ptr);
@@ -184,7 +183,7 @@ unsigned int sk_run_filter(struct sk_buf
break;
case BPF_LD|BPF_H|BPF_ABS:
k = fentry-k;
- load_h:
+load_h:
ptr = load_pointer(skb, k, 2, tmp);
if (ptr != NULL) {
A = ntohs(*(u16 *)ptr);
@@ -374,7 +373,7 @@ int sk_chk_filter(struct sock_filter *fi
case BPF_JMP|BPF_JSET|BPF_K:
case BPF_JMP|BPF_JSET|BPF_X:
/* for conditionals both must be safe */
-   if (pc + ftest-jt + 1 = flen ||
+   if (pc + ftest-jt + 1 = flen ||
pc + ftest-jf + 1 = flen)
return -EINVAL;
break;
@@ -384,7 +383,7 @@ int sk_chk_filter(struct sock_filter *fi
}
}
 
-return (BPF_CLASS(filter[flen - 1].code) == BPF_RET) ? 0 : -EINVAL;
+   return (BPF_CLASS(filter[flen - 1].code) == BPF_RET) ? 0 : -EINVAL;
 }
 
 /**
@@ -404,8 +403,8 @@ int sk_attach_filter(struct sock_fprog *
int err;
 
/* Make sure new filter is there and in the right amounts. */
-if (fprog-filter == NULL)
-return -EINVAL;
+   if (fprog-filter == NULL)
+   return -EINVAL;
 
fp = sock_kmalloc(sk, fsize+sizeof(*fp), GFP_KERNEL);
if (!fp)


-
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


Re: [PATCH] signed long - long

2006-01-14 Thread Kris Katterjohn
From: Al Viro
Sent: 1/14/2006 10:25:34 AM
 On Sat, Jan 14, 2006 at 09:38:44AM -0800, Kris Katterjohn wrote:
  From: Lennert Buytenhek
  Sent: 1/14/2006 9:23:19 AM
   Hmmm, is 'long' guaranteed to be signed?
   
   --L
  
  All integral types are except char.
 
 That would get you about B-...
 
   a) char itself is not an integer type; signed char and unsigned char
 are.
   b) _Bool is unsigned and it is an integer type.
   c) it's implementation-dependent whether bitfields declared as
 int are signed or unsigned; signed int is needed there to get guaranteed
 signed behaviour.
 
 That said, original question would qualify for F...

I learned C with KR (ANSI) and it says:

The signed specifier is useful for forcing char objects to carry a sign; it is
permissible but redundant with other integral types.

So from that I got that char was of integral type because it says it's redundant
for _other_ integral types. And I got that char is the only integral type that
is not signed by default.

It's certainly possible I'm wrong about char itself not being an integer, and
I almost never use _Bool, so I didn't think about it being integral probably
because I'm used to Java's boolean type. And bitfields didn't even cross my mind
when I sent that last email :)

But in this case (the patch) the changes are okay... right?

Kris

-
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


[PATCH] Clean up comments for sk_chk_filter()

2006-01-12 Thread Kris Katterjohn
This removes redundant comments, and moves one comment to a better location.

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

We all ready know the filter must end with a RET instruction because it says so
in the header comment for sk_chk_filter(). And I think the header comment is a
better place to say that the jumps are always forward.

-EINVAL is always returned for an error, so we'd might as well just say that.

Let me know what you think. Thanks!

--- x/net/core/filter.c 2006-01-12 14:13:21.0 -0600
+++ y/net/core/filter.c 2006-01-12 14:50:54.0 -0600
@@ -287,7 +287,9 @@ load_b:
  * no references or jumps that are out of range, no illegal
  * instructions, and must end with a RET instruction.
  *
- * Returns 0 if the rule set is legal or a negative errno code if not.
+ * All jumps are forward as they are not signed.
+ *
+ * Returns 0 if the rule set is legal or -EINVAL if not.
  */
 int sk_chk_filter(struct sock_filter *filter, int flen)
 {
@@ -299,7 +301,6 @@ int sk_chk_filter(struct sock_filter *fi
 
/* check the filter code now */
for (pc = 0; pc  flen; pc++) {
-   /* all jumps are forward as they are not signed */
ftest = filter[pc];
 
/* Only allow valid instructions */
@@ -383,11 +384,6 @@ int sk_chk_filter(struct sock_filter *fi
}
}
 
-   /*
-* The program must end with a return. We don't care where they
-* jumped within the script (its always forwards) but in the end
-* they _will_ hit this.
-*/
 return (BPF_CLASS(filter[flen - 1].code) == BPF_RET) ? 0 : -EINVAL;
 }
 


-
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


[PATCH] Remove more unneeded typecasts on *malloc()

2006-01-11 Thread Kris Katterjohn
This removes more unneeded casts on the return value for kmalloc(),
sock_kmalloc(), and vmalloc().

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

This is a diff against 2.6.15-git7.

Thanks!

--- x/net/atm/lec.c 2006-01-11 07:08:52.0 -0600
+++ y/net/atm/lec.c 2006-01-11 07:15:57.0 -0600
@@ -1811,8 +1811,7 @@ make_entry(struct lec_priv *priv, unsign
 {
 struct lec_arp_table *to_return;
 
-to_return = (struct lec_arp_table *) kmalloc(sizeof(struct 
lec_arp_table),
-GFP_ATOMIC);
+to_return = kmalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
 if (!to_return) {
 printk(LEC: Arp entry kmalloc failed\n);
 return NULL;

--- x/net/bridge/netfilter/ebtables.c   2006-01-02 21:21:10.0 -0600
+++ y/net/bridge/netfilter/ebtables.c   2006-01-11 07:16:08.0 -0600
@@ -944,7 +944,7 @@ static int do_replace(void __user *user,
if (countersize)
memset(newinfo-counters, 0, countersize);
 
-   newinfo-entries = (char *)vmalloc(tmp.entries_size);
+   newinfo-entries = vmalloc(tmp.entries_size);
if (!newinfo-entries) {
ret = -ENOMEM;
goto free_newinfo;
@@ -1146,7 +1146,7 @@ int ebt_register_table(struct ebt_table 
if (!newinfo)
return -ENOMEM;
 
-   newinfo-entries = (char *)vmalloc(table-table-entries_size);
+   newinfo-entries = vmalloc(table-table-entries_size);
if (!(newinfo-entries))
goto free_newinfo;
 
--- x/net/core/dev_mcast.c  2006-01-02 21:21:10.0 -0600
+++ y/net/core/dev_mcast.c  2006-01-11 07:16:14.0 -0600
@@ -158,7 +158,7 @@ int dev_mc_add(struct net_device *dev, v
int err = 0;
struct dev_mc_list *dmi, *dmi1;
 
-   dmi1 = (struct dev_mc_list *)kmalloc(sizeof(*dmi), GFP_ATOMIC);
+   dmi1 = kmalloc(sizeof(*dmi), GFP_ATOMIC);
 
spin_lock_bh(dev-xmit_lock);
for (dmi = dev-mc_list; dmi != NULL; dmi = dmi-next) {

--- x/net/ipv4/igmp.c   2006-01-11 07:08:53.0 -0600
+++ y/net/ipv4/igmp.c   2006-01-11 07:22:07.0 -0600
@@ -975,7 +975,7 @@ static void igmpv3_add_delrec(struct in_
 * for deleted items allows change reports to use common code with
 * non-deleted or query-response MCA's.
 */
-   pmc = (struct ip_mc_list *)kmalloc(sizeof(*pmc), GFP_KERNEL);
+   pmc = kmalloc(sizeof(*pmc), GFP_KERNEL);
if (!pmc)
return;
memset(pmc, 0, sizeof(*pmc));
@@ -1155,7 +1155,7 @@ void ip_mc_inc_group(struct in_device *i
}
}
 
-   im = (struct ip_mc_list *)kmalloc(sizeof(*im), GFP_KERNEL);
+   im = kmalloc(sizeof(*im), GFP_KERNEL);
if (!im)
goto out;
 
@@ -1476,7 +1476,7 @@ static int ip_mc_add1_src(struct ip_mc_l
psf_prev = psf;
}
if (!psf) {
-   psf = (struct ip_sf_list *)kmalloc(sizeof(*psf), GFP_ATOMIC);
+   psf = kmalloc(sizeof(*psf), GFP_ATOMIC);
if (!psf)
return -ENOBUFS;
memset(psf, 0, sizeof(*psf));
@@ -1659,7 +1659,7 @@ int ip_mc_join_group(struct sock *sk , s
err = -ENOBUFS;
if (count = sysctl_igmp_max_memberships)
goto done;
-   iml = (struct ip_mc_socklist *)sock_kmalloc(sk,sizeof(*iml),GFP_KERNEL);
+   iml = sock_kmalloc(sk,sizeof(*iml),GFP_KERNEL);
if (iml == NULL)
goto done;
 
@@ -1823,8 +1823,7 @@ int ip_mc_source(int add, int omode, str
 
if (psl)
count += psl-sl_max;
-   newpsl = (struct ip_sf_socklist *)sock_kmalloc(sk,
-   IP_SFLSIZE(count), GFP_KERNEL);
+   newpsl = sock_kmalloc(sk, IP_SFLSIZE(count), GFP_KERNEL);
if (!newpsl) {
err = -ENOBUFS;
goto done;
@@ -1907,8 +1906,8 @@ int ip_mc_msfilter(struct sock *sk, stru
goto done;
}
if (msf-imsf_numsrc) {
-   newpsl = (struct ip_sf_socklist *)sock_kmalloc(sk,
-   IP_SFLSIZE(msf-imsf_numsrc), GFP_KERNEL);
+   newpsl = sock_kmalloc(sk, IP_SFLSIZE(msf-imsf_numsrc),
+  GFP_KERNEL);
if (!newpsl) {
err = -ENOBUFS;
goto done;

--- x/net/ipv4/ip_sockglue.c2006-01-11 07:08:53.0 -0600
+++ y/net/ipv4/ip_sockglue.c2006-01-11 07:17:00.0 -0600
@@ -621,7 +621,7 @@ int ip_setsockopt(struct sock *sk, int l
err = -ENOBUFS;
break;
}
-   msf = (struct ip_msfilter *)kmalloc(optlen, GFP_KERNEL);
+   msf = kmalloc(optlen, GFP_KERNEL

[PATCH] Change memcmp(,,ETH_ALEN) to compare_ether_addr()

2006-01-09 Thread Kris Katterjohn
This changes some memcmp(one,two,ETH_ALEN) to compare_ether_addr(one,two).

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

This is a diff from 2.6.15. It compiles fine and seems to work fine.

Thanks!

--- x/net/8021q/vlan_dev.c  2006-01-02 21:21:10.0 -0600
+++ y/net/8021q/vlan_dev.c  2006-01-09 12:52:46.0 -0600
@@ -214,7 +214,7 @@ int vlan_skb_recv(struct sk_buff *skb, s
 * This allows the VLAN to have a different MAC than the 
underlying
 * device, and still route correctly.
 */
-   if (memcmp(eth_hdr(skb)-h_dest, skb-dev-dev_addr, ETH_ALEN) 
== 0) {
+   if (!compare_ether_addr(eth_hdr(skb)-h_dest, 
skb-dev-dev_addr)) {
/* It is for our (changed) MAC-address! */
skb-pkt_type = PACKET_HOST;
}

--- x/net/atm/br2684.c  2006-01-02 21:21:10.0 -0600
+++ y/net/atm/br2684.c  2006-01-09 12:53:37.0 -0600
@@ -296,13 +296,13 @@ static inline __be16 br_type_trans(struc
eth = eth_hdr(skb);
 
if (*eth-h_dest  1) {
-   if (memcmp(eth-h_dest, dev-broadcast, ETH_ALEN) == 0)
+   if (!compare_ether_addr(eth-h_dest, dev-broadcast))
skb-pkt_type = PACKET_BROADCAST;
else
skb-pkt_type = PACKET_MULTICAST;
}
 
-   else if (memcmp(eth-h_dest, dev-dev_addr, ETH_ALEN))
+   else if (compare_ether_addr(eth-h_dest, dev-dev_addr))
skb-pkt_type = PACKET_OTHERHOST;
 
if (ntohs(eth-h_proto) = 1536)

--- x/net/atm/lec.c 2006-01-02 21:21:10.0 -0600
+++ y/net/atm/lec.c 2006-01-09 12:58:07.0 -0600
@@ -1321,7 +1321,7 @@ static int lane2_associate_req (struct n
 struct sk_buff *skb;
 struct lec_priv *priv = (struct lec_priv*)dev-priv;
 
-if ( memcmp(lan_dst, dev-dev_addr, ETH_ALEN) != 0 )
+if (compare_ether_addr(lan_dst, dev-dev_addr))
 return (0);   /* not our mac address */
 
 kfree(priv-tlvs); /* NULL if there was no previous association */
@@ -1798,7 +1798,7 @@ lec_arp_find(struct lec_priv *priv,
   
 to_return = priv-lec_arp_tables[place];
 while(to_return) {
-if (memcmp(mac_addr, to_return-mac_addr, ETH_ALEN) == 0) {
+if (!compare_ether_addr(mac_addr, to_return-mac_addr)) {
 return to_return;
 }
 to_return = to_return-next;
@@ -2002,7 +2002,7 @@ lec_arp_resolve(struct lec_priv *priv, u
 return priv-mcast_vcc;
 break;
 case 2:  /* LANE2 wants arp for multicast addresses */
-if ( memcmp(mac_to_find, bus_mac, ETH_ALEN) == 0)
+if (!compare_ether_addr(mac_to_find, bus_mac))
 return priv-mcast_vcc;
 break;
 default:

--- x/net/atm/mpc.c 2006-01-02 21:21:10.0 -0600
+++ y/net/atm/mpc.c 2006-01-09 12:54:12.0 -0600
@@ -552,7 +552,7 @@ static int mpc_send_packet(struct sk_buf
goto non_ip; /* Multi-Protocol Over ATM :-) */
 
while (i  mpc-number_of_mps_macs) {
-   if (memcmp(eth-h_dest, (mpc-mps_macs + i*ETH_ALEN), ETH_ALEN) 
== 0)
+   if (!compare_ether_addr(eth-h_dest, (mpc-mps_macs + 
i*ETH_ALEN)))
if ( send_via_shortcut(skb, mpc) == 0 )   /* 
try shortcut */
return 0; /* 
success! */
i++;

--- x/net/bluetooth/bnep/core.c 2006-01-02 21:21:10.0 -0600
+++ y/net/bluetooth/bnep/core.c 2006-01-09 12:54:45.0 -0600
@@ -75,7 +75,7 @@ static struct bnep_session *__bnep_get_s
 
list_for_each(p, bnep_session_list) {
s = list_entry(p, struct bnep_session, list);   
-   if (!memcmp(dst, s-eh.h_source, ETH_ALEN))
+   if (!compare_ether_addr(dst, s-eh.h_source))
return s;
}
return NULL;
@@ -420,10 +420,10 @@ static inline int bnep_tx_frame(struct b
iv[il++] = (struct kvec) { type, 1 };
len++;
 
-   if (!memcmp(eh-h_dest, s-eh.h_source, ETH_ALEN))
+   if (!compare_ether_addr(eh-h_dest, s-eh.h_source))
type |= 0x01;
 
-   if (!memcmp(eh-h_source, s-eh.h_dest, ETH_ALEN))
+   if (!compare_ether_addr(eh-h_source, s-eh.h_dest))
type |= 0x02;
 
if (type)

--- x/net/bridge/netfilter/ebt_stp.c2006-01-02 21:21:10.0 -0600
+++ y/net/bridge/netfilter/ebt_stp.c2006-01-09 12:55:25.0 -0600
@@ -164,8 +164,8 @@ static int ebt_stp_check(const char *tab
if (datalen != len)
return -EINVAL;
/* Make sure the match only receives stp frames */
-   if (memcmp(e-destmac, bridge_ula, ETH_ALEN

[PATCH] sk_chk_filter() filter length should be unsigned

2006-01-09 Thread Kris Katterjohn
This makes the filter length in sk_chk_filter() unsigned as it should be.

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

This is a diff from 2.6.15.

The length should never be negative, and if the length were negative, the for
loop would fail.

Thanks!

--- x/net/core/filter.c 2006-01-02 21:21:10.0 -0600
+++ y/net/core/filter.c 2006-01-09 15:22:37.0 -0600
@@ -288,10 +288,10 @@ load_b:
  *
  * Returns 0 if the rule set is legal or a negative errno code if not.
  */
-int sk_chk_filter(struct sock_filter *filter, int flen)
+int sk_chk_filter(struct sock_filter *filter, unsigned int flen)
 {
struct sock_filter *ftest;
-   int pc;
+   unsigned int pc;
 
if (flen == 0 || flen  BPF_MAXINSNS)
return -EINVAL;
@@ -308,7 +308,7 @@ int sk_chk_filter(struct sock_filter *fi
 * Compare this with conditional jumps below,
 * where offsets are limited. --ANK (981016)
 */
-   if (ftest-k = (unsigned)(flen-pc-1))
+   if (ftest-k = flen - pc - 1)
return -EINVAL;
} else {
/* for conditionals both must be safe */

--- x/include/linux/filter.h2006-01-02 21:21:10.0 -0600
+++ y/include/linux/filter.h2006-01-09 15:29:27.0 -0600
@@ -145,7 +145,7 @@ struct sock;
 
 extern int sk_run_filter(struct sk_buff *skb, struct sock_filter *filter, int 
flen);
 extern int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk);
-extern int sk_chk_filter(struct sock_filter *filter, int flen);
+extern int sk_chk_filter(struct sock_filter *filter, unsigned int flen);
 #endif /* __KERNEL__ */
 
 #endif /* __LINUX_FILTER_H__ */


-
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


Re: [PATCH] sk_chk_filter() filter length should be unsigned

2006-01-09 Thread Kris Katterjohn
From: Kris Katterjohn
Sent: 1/9/2006 1:36:49 PM
 This makes the filter length in sk_chk_filter() unsigned as it should be.
 
 Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]
 
 This is a diff from 2.6.15.

Here's a new patch against 2.6.15-git5:

--- x/net/core/filter.c 2006-01-09 12:17:03.0 -0600
+++ y/net/core/filter.c 2006-01-09 18:19:07.0 -0600
@@ -289,10 +289,10 @@ load_b:
  *
  * Returns 0 if the rule set is legal or a negative errno code if not.
  */
-int sk_chk_filter(struct sock_filter *filter, int flen)
+int sk_chk_filter(struct sock_filter *filter, unsigned int flen)
 {
struct sock_filter *ftest;
-   int pc;
+   unsigned int pc;
 
if (flen == 0 || flen  BPF_MAXINSNS)
return -EINVAL;
@@ -360,7 +360,7 @@ int sk_chk_filter(struct sock_filter *fi
 * Compare this with conditional jumps below,
 * where offsets are limited. --ANK (981016)
 */
-   if (ftest-k = (unsigned)(flen-pc-1))
+   if (ftest-k = flen - pc - 1)
return -EINVAL;
break;
 
--- x/include/linux/filter.h2006-01-09 12:16:58.0 -0600
+++ y/include/linux/filter.h2006-01-09 18:19:28.0 -0600
@@ -145,7 +145,7 @@ struct sock;
 
 extern unsigned int sk_run_filter(struct sk_buff *skb, struct sock_filter 
*filter, int flen);
 extern int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk);
-extern int sk_chk_filter(struct sock_filter *filter, int flen);
+extern int sk_chk_filter(struct sock_filter *filter, unsigned int flen);
 #endif /* __KERNEL__ */
 
 #endif /* __LINUX_FILTER_H__ */


-
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


Re: [PATCH] sk_chk_filter() filter length should be unsigned

2006-01-09 Thread Kris Katterjohn
From: Patrick McHardy
Sent: 1/9/2006 4:24:18 PM
 Kris Katterjohn wrote:
  This makes the filter length in sk_chk_filter() unsigned as it should be.
  
  Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]
  
  This is a diff from 2.6.15.
  
  The length should never be negative, and if the length were negative, the 
  for
  loop would fail.
  
 
  -   if (ftest-k = (unsigned)(flen-pc-1))
  +   if (ftest-k = flen - pc - 1)
 
 NAK. The subtraction makes the whole expressions signed, so
 a very large ftest-k is interpreted as a negative number
 and passes the test.

Okey-dokey. Against git5:

--- x/net/core/filter.c 2006-01-09 12:17:03.0 -0600
+++ y/net/core/filter.c 2006-01-09 18:19:07.0 -0600
@@ -289,10 +289,10 @@ load_b:
  *
  * Returns 0 if the rule set is legal or a negative errno code if not.
  */
-int sk_chk_filter(struct sock_filter *filter, int flen)
+int sk_chk_filter(struct sock_filter *filter, unsigned int flen)
 {
struct sock_filter *ftest;
-   int pc;
+   unsigned int pc;
 
if (flen == 0 || flen  BPF_MAXINSNS)
return -EINVAL;
 
--- x/include/linux/filter.h2006-01-09 12:16:58.0 -0600
+++ y/include/linux/filter.h2006-01-09 18:19:28.0 -0600
@@ -145,7 +145,7 @@ struct sock;
 
 extern unsigned int sk_run_filter(struct sk_buff *skb, struct sock_filter 
*filter, int flen);
 extern int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk);
-extern int sk_chk_filter(struct sock_filter *filter, int flen);
+extern int sk_chk_filter(struct sock_filter *filter, unsigned int flen);
 #endif /* __KERNEL__ */
 
 #endif /* __LINUX_FILTER_H__ */


-
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


[PATCH] Fix spelling error in debug message

2006-01-09 Thread Kris Katterjohn
This fixes the misspelling of the word receive in a debugging message.

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

This is a diff from 2.6.15-git5.

Thanks!

--- x/net/ieee80211/ieee80211_rx.c  2006-01-09 17:28:34.0 -0600
+++ y/net/ieee80211/ieee80211_rx.c  2006-01-09 19:26:05.0 -0600
@@ -1439,7 +1439,7 @@ void ieee80211_rx_mgt(struct ieee80211_d
break;
 
case IEEE80211_STYPE_PROBE_REQ:
-   IEEE80211_DEBUG_MGMT(recieved auth (%d)\n,
+   IEEE80211_DEBUG_MGMT(received auth (%d)\n,
 WLAN_FC_GET_STYPE(le16_to_cpu
   (header-frame_ctl)));
 
@@ -1473,7 +1473,7 @@ void ieee80211_rx_mgt(struct ieee80211_d
break;
case IEEE80211_STYPE_AUTH:
 
-   IEEE80211_DEBUG_MGMT(recieved auth (%d)\n,
+   IEEE80211_DEBUG_MGMT(received auth (%d)\n,
 WLAN_FC_GET_STYPE(le16_to_cpu
   (header-frame_ctl)));
 


-
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


[PATCH] Fix grammar for comment for compare_ether_addr()

2006-01-09 Thread Kris Katterjohn
This fixes the wording in the comment for compare_ether_addr().

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

This is a diff from 2.6.15-git5.

Thanks!

--- x/include/linux/etherdevice.h   2006-01-09 12:16:58.0 -0600
+++ y/include/linux/etherdevice.h   2006-01-09 20:10:12.0 -0600
@@ -113,8 +113,8 @@ static inline void random_ether_addr(u8 
 
 /**
  * compare_ether_addr - Compare two Ethernet addresses
- * @addr1: Pointer to a six-byte array containing the Ethernet address
- * @addr2: Pointer other six-byte array containing the Ethernet address
+ * @addr1: Pointer to a six-byte array containing an Ethernet address
+ * @addr2: Pointer to another six-byte array containing an Ethernet address
  *
  * Compare two ethernet addresses, returns 0 if equal
  */


-
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


[PATCH] Additional options for resetting packet statistics

2006-01-07 Thread Kris Katterjohn
This adds some setsockopt(SOL_PACKET) options for changing the behavior when
getting packet statistics from the kernel.

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

This is a diff from 2.6.15 and I AM subscribed to netdev, so you dont' need to
CC me anymore.

I sent this to the linux-kernel mailing-list at the end of November, so I'm
resending it here now.

This adds PACKET_AUTO_STATISTICS, PACKET_MANUAL_STATISTICS, and
PACKET_RESET_STATISTICS setsockopt() options.

PACKET_AUTO_STATISTICS is the default and the kernel will zero the packet
statistics when the PACKET_STATISTICS getsockopt() call is used.
PACKET_MANUAL_STATISTICS changes is so that the kernel won't zero the stats
unless you use PACKET_RESET_STATISTICS or call PACKET_AUTO_STATISTICS to go
back to the default behavior.

This way you don't have to keep track of the stats in userland if you use
PACKET_MANUAL_STATISTICS/PACKET_RESET_STATISTICS.

You can zero the stats with PACKET_RESET_STATISTICS even if you are in AUTO
mode.

Thanks!

--- x/net/packet/af_packet.c2006-01-07 11:31:07.0 -0600
+++ y/net/packet/af_packet.c2006-01-07 11:28:56.0 -0600
@@ -41,6 +41,12 @@
  * will simply extend the hardware address
  * byte arrays at the end of sockaddr_ll 
  * and packet_mreq.
+ * Kris Katterjohn :   Added setsockopt options:
+ * PACKET_AUTO_STATISTICS,
+ * PACKET_MANUAL_STATISTICS, and
+ * PACKET_RESET_STATISTICS to handle the
+ * zero-ing of packet stats when using
+ * PACKET_STATISTICS. 2005-11-29.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -189,6 +195,7 @@ struct packet_sock {
/* struct sock has to be the first member of packet_sock */
struct sock sk;
struct tpacket_statsstats;
+   int auto_reset_stats;
 #ifdef CONFIG_PACKET_MMAP
char *  *pg_vec;
unsigned inthead;
@@ -1020,6 +1027,7 @@ static int packet_create(struct socket *
po = pkt_sk(sk);
sk-sk_family = PF_PACKET;
po-num = protocol;
+   po-auto_reset_stats = 1;
 
sk-sk_destruct = packet_sock_destruct;
atomic_inc(packet_socks_nr);
@@ -1324,6 +1332,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)
@@ -1352,6 +1361,21 @@ packet_setsockopt(struct socket *sock, i
return ret;
}
 #endif
+
+   case PACKET_AUTO_STATISTICS:
+   po-auto_reset_stats = 1;
+   return 0;
+
+   case PACKET_MANUAL_STATISTICS:
+   po-auto_reset_stats = 0;
+   return 0;
+
+   case PACKET_RESET_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:
{
@@ -1406,7 +1430,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-auto_reset_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-02 21:21:10.0 -0600
+++ y/include/linux/if_packet.h 2006-01-07 11:43:47.0 -0600
@@ -38,7 +38,10 @@ 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_AUTO_STATISTICS 7
+#define PACKET_MANUAL_STATISTICS   8
+#define PACKET_RESET_STATISTICS9
+#define PACKET_COPY_THRESH 10
 
 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


[PATCH] Change some if (x) BUG(); to BUG_ON(x);

2006-01-07 Thread Kris Katterjohn
This changes some simple if (x) BUG(); statements to BUG_ON(x);

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

This is a diff from 2.6.15.

Obviously I wasn't able to test these changes per se, but is there a reason they
wouldn't work correctly?

Thanks!

--- x/net/core/dev.c2006-01-02 21:21:10.0 -0600
+++ y/net/core/dev.c2006-01-07 20:00:45.0 -0600
@@ -1092,15 +1092,12 @@ int skb_checksum_help(struct sk_buff *sk
goto out;
}
 
-   if (offset  (int)skb-len)
-   BUG();
+   BUG_ON(offset  (int)skb-len);
csum = skb_checksum(skb, offset, skb-len-offset, 0);
 
offset = skb-tail - skb-h.raw;
-   if (offset = 0)
-   BUG();
-   if (skb-csum + 2  offset)
-   BUG();
+   BUG_ON(offset = 0);
+   BUG_ON(skb-csum + 2  offset);
 
*(u16*)(skb-h.raw + skb-csum) = csum_fold(csum);
skb-ip_summed = CHECKSUM_NONE;

--- x/net/core/skbuff.c 2006-01-02 21:21:10.0 -0600
+++ y/net/core/skbuff.c 2006-01-07 20:01:55.0 -0600
@@ -792,8 +792,7 @@ int ___pskb_trim(struct sk_buff *skb, un
int end = offset + skb_shinfo(skb)-frags[i].size;
if (end  len) {
if (skb_cloned(skb)) {
-   if (!realloc)
-   BUG();
+   BUG_ON(!realloc);
if (pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
return -ENOMEM;
}
@@ -895,8 +894,7 @@ unsigned char *__pskb_pull_tail(struct s
struct sk_buff *insp = NULL;
 
do {
-   if (!list)
-   BUG();
+   BUG_ON(!list);
 
if (list-len = eat) {
/* Eaten as whole. */
@@ -1200,8 +1198,7 @@ unsigned int skb_checksum(const struct s
start = end;
}
}
-   if (len)
-   BUG();
+   BUG_ON(len);
 
return csum;
 }
@@ -1283,8 +1280,7 @@ unsigned int skb_copy_and_csum_bits(cons
start = end;
}
}
-   if (len)
-   BUG();
+   BUG_ON(len);
return csum;
 }
 
@@ -1298,8 +1294,7 @@ void skb_copy_and_csum_dev(const struct 
else
csstart = skb_headlen(skb);
 
-   if (csstart  skb_headlen(skb))
-   BUG();
+   BUG_ON(csstart  skb_headlen(skb));
 
memcpy(to, skb-data, csstart);
 
--- x/net/ipv4/icmp.c   2006-01-02 21:21:10.0 -0600
+++ y/net/ipv4/icmp.c   2006-01-07 20:02:07.0 -0600
@@ -898,8 +898,7 @@ static void icmp_address_reply(struct sk
u32 _mask, *mp;
 
mp = skb_header_pointer(skb, 0, sizeof(_mask), _mask);
-   if (mp == NULL)
-   BUG();
+   BUG_ON(mp == NULL);
for (ifa = in_dev-ifa_list; ifa; ifa = ifa-ifa_next) {
if (*mp == ifa-ifa_mask 
inet_ifa_match(rt-rt_src, ifa))

--- x/net/ipv4/inetpeer.c   2006-01-02 21:21:10.0 -0600
+++ y/net/ipv4/inetpeer.c   2006-01-07 20:02:26.0 -0600
@@ -304,8 +304,7 @@ static void unlink_from_pool(struct inet
/* look for a node to insert instead of p */
struct inet_peer *t;
t = lookup_rightempty(p);
-   if (*stackptr[-1] != t)
-   BUG();
+   BUG_ON(*stackptr[-1] != t);
**--stackptr = t-avl_left;
/* t is removed, t-v4daddr  x-v4daddr for any
 * x in p-avl_left subtree.
@@ -314,8 +313,7 @@ static void unlink_from_pool(struct inet
t-avl_left = p-avl_left;
t-avl_right = p-avl_right;
t-avl_height = p-avl_height;
-   if (delp[1] != p-avl_left)
-   BUG();
+   BUG_ON(delp[1] != p-avl_left);
delp[1] = t-avl_left; /* was p-avl_left */
}
peer_avl_rebalance(stack, stackptr);

--- x/net/ipv4/tcp_input.c  2006-01-02 21:21:10.0 -0600
+++ y/net/ipv4/tcp_input.c  2006-01-07 20:02:54.0 -0600
@@ -3307,7 +3307,7 @@ tcp_collapse(struct sock *sk, struct sk_
int offset = start - TCP_SKB_CB(skb)-seq;
int size = TCP_SKB_CB(skb)-end_seq - start;
 
-   if (offset  0) BUG();
+   BUG_ON(offset  0);
if (size  0) {
size = min(copy, size);
if (skb_copy_bits(skb, offset, skb_put(nskb, 
size), size))

--- x/net/key

Re: [PATCH] Change sk_run_filter()'s return type in net/core/filter.c

2006-01-06 Thread Kris Katterjohn
From: Patrick McHardy
Sent: 1/6/2006 1:36:24 AM
 Please use unsigned int not just unsigned.

Ta-da!

--- x/net/core/filter.c 2006-01-05 12:27:17.0 -0600
+++ y/net/core/filter.c 2006-01-05 17:02:32.0 -0600
@@ -75,7 +75,7 @@ static inline void *load_pointer(struct 
  * len is the number of filter blocks in the array.
  */
  
-int sk_run_filter(struct sk_buff *skb, struct sock_filter *filter, int flen)
+unsigned int sk_run_filter(struct sk_buff *skb, struct sock_filter *filter, 
int flen)
 {
struct sock_filter *fentry; /* We walk down these */
void *ptr;
@@ -241,9 +241,9 @@ load_b:
A = X;
continue;
case BPF_RET|BPF_K:
-   return ((unsigned int)fentry-k);
+   return fentry-k;
case BPF_RET|BPF_A:
-   return ((unsigned int)A);
+   return A;
case BPF_ST:
mem[fentry-k] = A;
continue;

--- x/include/linux/filter.h2006-01-02 21:21:10.0 -0600
+++ y/include/linux/filter.h2006-01-05 17:02:58.0 -0600
@@ -143,7 +143,7 @@ static inline unsigned int sk_filter_len
 struct sk_buff;
 struct sock;
 
-extern int sk_run_filter(struct sk_buff *skb, struct sock_filter *filter, int 
flen);
+extern unsigned int sk_run_filter(struct sk_buff *skb, struct sock_filter 
*filter, int flen);
 extern int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk);
 extern int sk_chk_filter(struct sock_filter *filter, int flen);
 #endif /* __KERNEL__ */

--- x/include/net/sock.h2006-01-05 23:06:00.0 -0600
+++ y/include/net/sock.h2006-01-05 23:06:06.0 -0600
@@ -856,8 +856,8 @@ static inline int sk_filter(struct sock 

filter = sk-sk_filter;
if (filter) {
-   int pkt_len = sk_run_filter(skb, filter-insns,
-   filter-len);
+   unsigned int pkt_len = sk_run_filter(skb, filter-insns,
+filter-len);
if (!pkt_len)
err = -EPERM;
else


-
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


[PATCH] Use newer is_multicast_ether_addr() in some files

2006-01-06 Thread Kris Katterjohn
This uses is_multicast_ether_addr() because it has recently been changed to do
the same thing these seperate tests are doing.

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

Thanks!

--- x/net/atm/br2684.c  2006-01-02 21:21:10.0 -0600
+++ y/net/atm/br2684.c  2006-01-06 12:34:47.0 -0600
@@ -295,7 +295,7 @@ static inline __be16 br_type_trans(struc
unsigned char *rawp;
eth = eth_hdr(skb);
 
-   if (*eth-h_dest  1) {
+   if (is_multicast_ether_addr(eth-h_dest)) {
if (memcmp(eth-h_dest, dev-broadcast, ETH_ALEN) == 0)
skb-pkt_type = PACKET_BROADCAST;
else


--- x/net/bridge/br_input.c 2006-01-02 21:21:10.0 -0600
+++ y/net/bridge/br_input.c 2006-01-06 12:31:59.0 -0600
@@ -63,7 +63,7 @@ int br_handle_frame_finish(struct sk_buf
}
}
 
-   if (dest[0]  1) {
+   if (is_multicast_ether_addr(dest)) {
br_flood_forward(br, skb, !passedup);
if (!passedup)
br_pass_frame_up(br, skb);


--- x/net/ethernet/eth.c2006-01-05 21:28:02.0 -0600
+++ y/net/ethernet/eth.c2006-01-06 12:21:04.0 -0600
@@ -163,7 +163,7 @@ __be16 eth_type_trans(struct sk_buff *sk
skb_pull(skb,ETH_HLEN);
eth = eth_hdr(skb);

-   if (*eth-h_dest1) {
+   if (is_multicast_ether_addr(eth-h_dest)) {
if (!compare_ether_addr(eth-h_dest, dev-broadcast))
skb-pkt_type = PACKET_BROADCAST;
else


-
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


Re: [PATCH] Use newer is_multicast_ether_addr() in some files

2006-01-06 Thread Kris Katterjohn
From: Patrick McHardy
Sent: 1/6/2006 12:52:34 PM

 Randy.Dunlap wrote:
  On Fri, 6 Jan 2006, Patrick McHardy wrote:
  
 --- x/net/atm/br2684.c 2006-01-02 21:21:10.0 -0600
 +++ y/net/atm/br2684.c 2006-01-06 12:34:47.0 -0600
 @@ -295,7 +295,7 @@ static inline __be16 br_type_trans(struc
unsigned char *rawp;
eth = eth_hdr(skb);
 
 -  if (*eth-h_dest  1) {
 +  if (is_multicast_ether_addr(eth-h_dest)) {
 
 This is not equivalent, is_multicast_ether_addr() ignores
 addresses starting with 0xff.
  
  It used to.  Not today afaict.
 
 You're right, Stephen changed it two days ago.

That's why I said the newer is_multicast_ether_addr(). Sorry for the confusion.

-
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


[PATCH] Remove old comments and code in net/ethernet/eth.c

2006-01-06 Thread Kris Katterjohn
This removes an old comment and old commented-out code that's been there since
at least as far back as 2.4.0.

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

Thanks!

--- x/net/ethernet/eth.c2006-01-06 12:49:27.0 -0600
+++ y/net/ethernet/eth.c2006-01-06 18:01:43.0 -0600
@@ -168,20 +168,8 @@ __be16 eth_type_trans(struct sk_buff *sk
skb-pkt_type = PACKET_BROADCAST;
else
skb-pkt_type = PACKET_MULTICAST;
-   }
-   
-   /*
-*  This ALLMULTI check should be redundant by 1.4
-*  so don't forget to remove it.
-*
-*  Seems, you forgot to remove it. All silly devices
-*  seems to set IFF_PROMISC.
-*/
-
-   else if(1 /*dev-flagsIFF_PROMISC*/) {
-   if (unlikely(compare_ether_addr(eth-h_dest, dev-dev_addr)))
-   skb-pkt_type = PACKET_OTHERHOST;
-   }
+   } else if (unlikely(compare_ether_addr(eth-h_dest, dev-dev_addr)))
+   skb-pkt_type = PACKET_OTHERHOST;

if (ntohs(eth-h_proto) = 1536)
return eth-h_proto;


-
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


Re: [PATCH] Remove old comments and code in net/ethernet/eth.c

2006-01-06 Thread Kris Katterjohn
From: David S. Miller
Sent: 1/6/2006 4:08:33 PM
 From: Kris Katterjohn [EMAIL PROTECTED]
 Date: Fri, 6 Jan 2006 16:05:36 -0800
 
  This removes an old comment and old commented-out code that's been there 
  since
  at least as far back as 2.4.0.
  
  Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]
 
 It's instructive to keep it there so that nobody in the
 future tries to add the optimization without understanding
 why it's wrong.

Okay then. That makes sense.

-
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


[PATCH] Localizing a variable in net/core/filter.c

2006-01-06 Thread Kris Katterjohn
This localizes a variable to the function it's used in.

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

I assume tmp was used for a reason instead of using a variable local to the if()
in load_pointer(), but I can't figure out why. So I wrote this patch changing it
in case it was just a mistake or something left over from something else.

So in other words, can you explain to me why it was done the way it was done? If
not, I think my patch takes care of it.

Also, I tested it my way and everything seems to be working quite well.

Thanks!

--- x/net/core/filter.c 2006-01-06 16:51:51.0 -0600
+++ y/net/core/filter.c 2006-01-06 18:17:43.0 -0600
@@ -51,12 +51,12 @@ static void *__load_pointer(struct sk_bu
return NULL;
 }
 
-static inline void *load_pointer(struct sk_buff *skb, int k,
- unsigned int size, void *buffer)
+static inline void *load_pointer(struct sk_buff *skb, int k, unsigned int size)
 {
-   if (k = 0)
+   if (k = 0) {
+   u32 *buffer = NULL;
return skb_header_pointer(skb, k, size, buffer);
-   else {
+   } else {
if (k = SKF_AD_OFF)
return NULL;
return __load_pointer(skb, k);
@@ -82,7 +82,6 @@ unsigned int sk_run_filter(struct sk_buf
u32 A = 0;  /* Accumulator */
u32 X = 0;  /* Index Register */
u32 mem[BPF_MEMWORDS];  /* Scratch Memory Store */
-   u32 tmp;
int k;
int pc;
 
@@ -176,7 +175,7 @@ unsigned int sk_run_filter(struct sk_buf
case BPF_LD|BPF_W|BPF_ABS:
k = fentry-k;
  load_w:
-   ptr = load_pointer(skb, k, 4, tmp);
+   ptr = load_pointer(skb, k, 4);
if (ptr != NULL) {
A = ntohl(*(u32 *)ptr);
continue;
@@ -185,7 +184,7 @@ unsigned int sk_run_filter(struct sk_buf
case BPF_LD|BPF_H|BPF_ABS:
k = fentry-k;
  load_h:
-   ptr = load_pointer(skb, k, 2, tmp);
+   ptr = load_pointer(skb, k, 2);
if (ptr != NULL) {
A = ntohs(*(u16 *)ptr);
continue;
@@ -194,7 +193,7 @@ unsigned int sk_run_filter(struct sk_buf
case BPF_LD|BPF_B|BPF_ABS:
k = fentry-k;
 load_b:
-   ptr = load_pointer(skb, k, 1, tmp);
+   ptr = load_pointer(skb, k, 1);
if (ptr != NULL) {
A = *(u8 *)ptr;
continue;
@@ -216,7 +215,7 @@ load_b:
k = X + fentry-k;
goto load_b;
case BPF_LDX|BPF_B|BPF_MSH:
-   ptr = load_pointer(skb, fentry-k, 1, tmp);
+   ptr = load_pointer(skb, fentry-k, 1);
if (ptr != NULL) {
X = (*(u8 *)ptr  0xf)  2;
continue;


-
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


Re: [PATCH] Localizing a variable in net/core/filter.c

2006-01-06 Thread Kris Katterjohn
From: Patrick McHardy
Sent: 1/6/2006 5:12:33 PM
  -static inline void *load_pointer(struct sk_buff *skb, int k,
  - unsigned int size, void *buffer)
  +static inline void *load_pointer(struct sk_buff *skb, int k, unsigned int 
  size)
   {
  -   if (k = 0)
  +   if (k = 0) {
  +   u32 *buffer = NULL;
  return skb_header_pointer(skb, k, size, buffer);
 
 This is wrong, skb_header_pointer needs a pointer to a buffer
 to which it can copy the packet contents if they are located
 in the non-linear area.

Ah, gotcha.

--- x/net/core/filter.c 2006-01-06 19:14:34.0 -0600
+++ y/net/core/filter.c 2006-01-06 19:14:26.0 -0600
@@ -51,12 +51,12 @@ static void *__load_pointer(struct sk_bu
return NULL;
 }
 
-static inline void *load_pointer(struct sk_buff *skb, int k,
- unsigned int size, void *buffer)
+static inline void *load_pointer(struct sk_buff *skb, int k, unsigned int size)
 {
-   if (k = 0)
-   return skb_header_pointer(skb, k, size, buffer);
-   else {
+   if (k = 0) {
+   u32 buffer;
+   return skb_header_pointer(skb, k, size, buffer);
+   } else {
if (k = SKF_AD_OFF)
return NULL;
return __load_pointer(skb, k);
@@ -82,7 +82,6 @@ unsigned int sk_run_filter(struct sk_buf
u32 A = 0;  /* Accumulator */
u32 X = 0;  /* Index Register */
u32 mem[BPF_MEMWORDS];  /* Scratch Memory Store */
-   u32 tmp;
int k;
int pc;
 
@@ -176,7 +175,7 @@ unsigned int sk_run_filter(struct sk_buf
case BPF_LD|BPF_W|BPF_ABS:
k = fentry-k;
  load_w:
-   ptr = load_pointer(skb, k, 4, tmp);
+   ptr = load_pointer(skb, k, 4);
if (ptr != NULL) {
A = ntohl(*(u32 *)ptr);
continue;
@@ -185,7 +184,7 @@ unsigned int sk_run_filter(struct sk_buf
case BPF_LD|BPF_H|BPF_ABS:
k = fentry-k;
  load_h:
-   ptr = load_pointer(skb, k, 2, tmp);
+   ptr = load_pointer(skb, k, 2);
if (ptr != NULL) {
A = ntohs(*(u16 *)ptr);
continue;
@@ -194,7 +193,7 @@ unsigned int sk_run_filter(struct sk_buf
case BPF_LD|BPF_B|BPF_ABS:
k = fentry-k;
 load_b:
-   ptr = load_pointer(skb, k, 1, tmp);
+   ptr = load_pointer(skb, k, 1);
if (ptr != NULL) {
A = *(u8 *)ptr;
continue;
@@ -216,7 +215,7 @@ load_b:
k = X + fentry-k;
goto load_b;
case BPF_LDX|BPF_B|BPF_MSH:
-   ptr = load_pointer(skb, fentry-k, 1, tmp);
+   ptr = load_pointer(skb, fentry-k, 1);
if (ptr != NULL) {
X = (*(u8 *)ptr  0xf)  2;
continue;


-
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


Re: [PATCH] Localizing a variable in net/core/filter.c

2006-01-06 Thread Kris Katterjohn
From: Patrick McHardy
Sent: 1/6/2006 5:20:44 PM
  -static inline void *load_pointer(struct sk_buff *skb, int k,
  - unsigned int size, void *buffer)
  +static inline void *load_pointer(struct sk_buff *skb, int k, unsigned int 
  size)
   {
  -   if (k = 0)
  -   return skb_header_pointer(skb, k, size, buffer);
  -   else {
  +   if (k = 0) {
  +   u32 buffer;
  +   return skb_header_pointer(skb, k, size, buffer);
 
 This is also wrong, now you returning an address from load_pointer's
 stackframe.

So the whole thing is wrong? If so, I guess I understand why it was done the 
way it
was before.

Shouldn't gcc warn about this kind of thing?

-
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


Re: [PATCH] Localizing a variable in net/core/filter.c

2006-01-06 Thread Kris Katterjohn
From: David S. Miller
Sent: 1/6/2006 5:29:20 PM
 From: Kris Katterjohn [EMAIL PROTECTED]
 Date: Fri, 6 Jan 2006 17:25:32 -0800
 
  So the whole thing is wrong? If so, I guess I understand why it was
  done the way it was before.
 
 It's using the local variable in the parent function as a temporary
 scratch area if the SKB isn't linear and we need to copy the packet
 data out from the scatter-gather list of the SKB.
 
 Read the implementation of skb_header_pointer() and be confused
 no further.

Okay.. the last horse finally crossed the finish line. Thanks.

-
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


[PATCH] Change sk_run_filter()'s return type in net/core/filter.c

2006-01-05 Thread Kris Katterjohn
This changes sk_run_filter()'s return type from int to unsigned.

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

Zero all ready gets returned if an error occurs, and net/packet/af_packet.c
treats the return type as unsigned anyway. For some reason, under the BPF RET
statements, fentry-k and A were cast to unsigned when A is all ready unsigned
and they'd both be converted back to int! I dropped the cast on both; fentry-k
get converted anyway.

No other files need to be changed because no return values are really changed.

Thanks!

--- x/net/core/filter.c 2006-01-05 12:27:17.0 -0600
+++ y/net/core/filter.c 2006-01-05 17:02:32.0 -0600
@@ -75,7 +75,7 @@ static inline void *load_pointer(struct 
  * len is the number of filter blocks in the array.
  */
  
-int sk_run_filter(struct sk_buff *skb, struct sock_filter *filter, int flen)
+unsigned sk_run_filter(struct sk_buff *skb, struct sock_filter *filter, int 
flen)
 {
struct sock_filter *fentry; /* We walk down these */
void *ptr;
@@ -241,9 +241,9 @@ load_b:
A = X;
continue;
case BPF_RET|BPF_K:
-   return ((unsigned int)fentry-k);
+   return fentry-k;
case BPF_RET|BPF_A:
-   return ((unsigned int)A);
+   return A;
case BPF_ST:
mem[fentry-k] = A;
continue;

--- x/include/linux/filter.h2006-01-02 21:21:10.0 -0600
+++ y/include/linux/filter.h2006-01-05 17:02:58.0 -0600
@@ -143,7 +143,7 @@ static inline unsigned int sk_filter_len
 struct sk_buff;
 struct sock;
 
-extern int sk_run_filter(struct sk_buff *skb, struct sock_filter *filter, int 
flen);
+extern unsigned sk_run_filter(struct sk_buff *skb, struct sock_filter *filter, 
int flen);
 extern int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk);
 extern int sk_chk_filter(struct sock_filter *filter, int flen);
 #endif /* __KERNEL__ */


-
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


Re: [PATCH] Change sk_run_filter()'s return type in net/core/filter.c

2006-01-05 Thread Kris Katterjohn
 Whoops! Here you go:

Whoops again. Screwed that last patch up. I gotta stop doing this stuff when I'm
tired and I need to check myself :)

Sorry. Again.

--- x/net/core/filter.c 2006-01-05 12:27:17.0 -0600
+++ y/net/core/filter.c 2006-01-05 17:02:32.0 -0600
@@ -75,7 +75,7 @@ static inline void *load_pointer(struct 
  * len is the number of filter blocks in the array.
  */
  
-int sk_run_filter(struct sk_buff *skb, struct sock_filter *filter, int flen)
+unsigned sk_run_filter(struct sk_buff *skb, struct sock_filter *filter, int 
flen)
 {
struct sock_filter *fentry; /* We walk down these */
void *ptr;
@@ -241,9 +241,9 @@ load_b:
A = X;
continue;
case BPF_RET|BPF_K:
-   return ((unsigned int)fentry-k);
+   return fentry-k;
case BPF_RET|BPF_A:
-   return ((unsigned int)A);
+   return A;
case BPF_ST:
mem[fentry-k] = A;
continue;

--- x/include/linux/filter.h2006-01-02 21:21:10.0 -0600
+++ y/include/linux/filter.h2006-01-05 17:02:58.0 -0600
@@ -143,7 +143,7 @@ static inline unsigned int sk_filter_len
 struct sk_buff;
 struct sock;
 
-extern int sk_run_filter(struct sk_buff *skb, struct sock_filter *filter, int 
flen);
+extern unsigned sk_run_filter(struct sk_buff *skb, struct sock_filter *filter, 
int flen);
 extern int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk);
 extern int sk_chk_filter(struct sock_filter *filter, int flen);
 #endif /* __KERNEL__ */

--- x/include/net/sock.h2006-01-05 23:06:00.0 -0600
+++ y/include/net/sock.h2006-01-05 23:06:06.0 -0600
@@ -856,8 +856,8 @@ static inline int sk_filter(struct sock 

filter = sk-sk_filter;
if (filter) {
-   int pkt_len = sk_run_filter(skb, filter-insns,
-   filter-len);
+   unsigned pkt_len = sk_run_filter(skb, filter-insns,
+filter-len);
if (!pkt_len)
err = -EPERM;
else


-
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


Re: [PATCH (should be ready to apply)] More instruction checks fornet/core/filter.c

2006-01-04 Thread Kris Katterjohn
From: David S. Miller
 From: Kris Katterjohn [EMAIL PROTECTED]
 Your email client has corrupted the patch spacing and tabbing.
 Please fix this.

Really? Have my other patches been screwed up, too? My email client has
upgraded recently (although I'm not sure what it was supposed to be updating),
so I'm sending this one from the old web-based version. It should work because I
sent my other patches through this one.

It won't be a problem for me to send the patch as an attachment if this one
screws up, will it?

Sorry about this.

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

--- x/net/core/filter.c 2006-01-03 11:09:07.0 -0600
+++ y/net/core/filter.c 2006-01-03 21:42:02.0 -0600
@@ -13,6 +13,7 @@
  * 2 of the License, or (at your option) any later version.
  *
  * Andi Kleen - Fix a few bad bugs and races.
+ * Kris Katterjohn - Added many additional checks in sk_chk_filter()
  */
 
 #include linux/module.h
@@ -250,7 +251,7 @@ load_b:
mem[fentry-k] = X;
continue;
default:
-   /* Invalid instruction counts as RET */
+   WARN_ON(1);
return 0;
}
 
@@ -283,8 +284,8 @@ load_b:
  *
  * Check the user's filter code. If we let some ugly
  * filter code slip through kaboom! The filter must contain
- * no references or jumps that are out of range, no illegal instructions
- * and no backward jumps. It must end with a RET instruction
+ * no references or jumps that are out of range, no illegal
+ * instructions, and must end with a RET instruction.
  *
  * Returns 0 if the rule set is legal or a negative errno code if not.
  */
@@ -300,38 +301,85 @@ int sk_chk_filter(struct sock_filter *fi
for (pc = 0; pc  flen; pc++) {
/* all jumps are forward as they are not signed */
ftest = filter[pc];
-   if (BPF_CLASS(ftest-code) == BPF_JMP) {
-   /* but they mustn't jump off the end */
-   if (BPF_OP(ftest-code) == BPF_JA) {
-   /*
-* Note, the large ftest-k might cause loops.
-* Compare this with conditional jumps below,
-* where offsets are limited. --ANK (981016)
-*/
-   if (ftest-k = (unsigned)(flen-pc-1))
-   return -EINVAL;
-   } else {
-   /* for conditionals both must be safe */
-   if (pc + ftest-jt +1 = flen ||
-   pc + ftest-jf +1 = flen)
-   return -EINVAL;
-   }
-   }
 
-   /* check for division by zero   -Kris Katterjohn 2005-10-30 */
-   if (ftest-code == (BPF_ALU|BPF_DIV|BPF_K)  ftest-k == 0)
-   return -EINVAL;
+   /* Only allow valid instructions */
+   switch (ftest-code) {
+   case BPF_ALU|BPF_ADD|BPF_K:
+   case BPF_ALU|BPF_ADD|BPF_X:
+   case BPF_ALU|BPF_SUB|BPF_K:
+   case BPF_ALU|BPF_SUB|BPF_X:
+   case BPF_ALU|BPF_MUL|BPF_K:
+   case BPF_ALU|BPF_MUL|BPF_X:
+   case BPF_ALU|BPF_DIV|BPF_X:
+   case BPF_ALU|BPF_AND|BPF_K:
+   case BPF_ALU|BPF_AND|BPF_X:
+   case BPF_ALU|BPF_OR|BPF_K:
+   case BPF_ALU|BPF_OR|BPF_X:
+   case BPF_ALU|BPF_LSH|BPF_K:
+   case BPF_ALU|BPF_LSH|BPF_X:
+   case BPF_ALU|BPF_RSH|BPF_K:
+   case BPF_ALU|BPF_RSH|BPF_X:
+   case BPF_ALU|BPF_NEG:
+   case BPF_LD|BPF_W|BPF_ABS:
+   case BPF_LD|BPF_H|BPF_ABS:
+   case BPF_LD|BPF_B|BPF_ABS:
+   case BPF_LD|BPF_W|BPF_LEN:
+   case BPF_LD|BPF_W|BPF_IND:
+   case BPF_LD|BPF_H|BPF_IND:
+   case BPF_LD|BPF_B|BPF_IND:
+   case BPF_LD|BPF_IMM:
+   case BPF_LDX|BPF_W|BPF_LEN:
+   case BPF_LDX|BPF_B|BPF_MSH:
+   case BPF_LDX|BPF_IMM:
+   case BPF_MISC|BPF_TAX:
+   case BPF_MISC|BPF_TXA:
+   case BPF_RET|BPF_K:
+   case BPF_RET|BPF_A:
+   break;
+
+   /* Some instructions need special checks */
 
-   /* check that memory operations use valid addresses. */
-   if (ftest-k = BPF_MEMWORDS) {
-   /* but it might not be a memory operation... */
-   switch (ftest-code) {
-   case BPF_ST:
-   case BPF_STX:   
-   case BPF_LD|BPF_MEM:
-   case BPF_LDX|BPF_MEM:   
+   case BPF_ALU|BPF_DIV|BPF_K

[PATCH] Remove unneeded variable in net/packet/af_packet.c

2006-01-04 Thread Kris Katterjohn
This removes an unneeded ret variable and returns directly.

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

I am now subscribed to the list, so there's no need to CC me anymore.

Thanks!

--- x/net/packet/af_packet.c2006-01-02 21:21:10.0 -0600
+++ y/net/packet/af_packet.c2006-01-04 17:44:17.0 -0600
@@ -1324,7 +1324,6 @@ static int
 packet_setsockopt(struct socket *sock, int level, int optname, char __user 
*optval, int optlen)
 {
struct sock *sk = sock-sk;
-   int ret;
 
if (level != SOL_PACKET)
return -ENOPROTOOPT;
@@ -1346,10 +1345,9 @@ packet_setsockopt(struct socket *sock, i
if (len  (mreq.mr_alen + offsetof(struct packet_mreq, 
mr_address)))
return -EINVAL;
if (optname == PACKET_ADD_MEMBERSHIP)
-   ret = packet_mc_add(sk, mreq);
+   return packet_mc_add(sk, mreq);
else
-   ret = packet_mc_drop(sk, mreq);
-   return ret;
+   return packet_mc_drop(sk, mreq);
}
 #endif
 #ifdef CONFIG_PACKET_MMAP


-
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


[PATCH] Change 1500 to ETH_DATA_LEN in some files

2006-01-04 Thread Kris Katterjohn
These patches add the header linux/if_ether.h and change 1500 to ETH_DATA_LEN in
some files.

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

At first I wasn't going to change anything under net/ipv[46], but I then saw 
that
ipv6/ip6_tunnel.c used ETH_DATA_LEN, so I went ahead and changed them, too.

A grep -R 1500 /usr/src/linux/net yields a few results, but these files that I
patched seem to be the ones that fit best with ETH_DATA_LEN.

Let me know what you think. Thanks!

--- x/net/bridge/br_if.c2006-01-02 21:21:10.0 -0600
+++ y/net/bridge/br_if.c2006-01-04 21:25:10.0 -0600
@@ -20,6 +20,7 @@
 #include linux/module.h
 #include linux/init.h
 #include linux/rtnetlink.h
+#include linux/if_ether.h
 #include net/sock.h
 
 #include br_private.h
@@ -295,7 +296,7 @@ int br_del_bridge(const char *name)
return ret;
 }
 
-/* Mtu of the bridge pseudo-device 1500 or the minimum of the ports */
+/* MTU of the bridge pseudo-device: ETH_DATA_LEN or the minimum of the ports */
 int br_min_mtu(const struct net_bridge *br)
 {
const struct net_bridge_port *p;
@@ -304,7 +305,7 @@ int br_min_mtu(const struct net_bridge *
ASSERT_RTNL();
 
if (list_empty(br-port_list))
-   mtu = 1500;
+   mtu = ETH_DATA_LEN;
else {
list_for_each_entry(p, br-port_list, list) {
if (!mtu  || p-dev-mtu  mtu)

--- x/net/ethernet/eth.c2006-01-02 21:21:10.0 -0600
+++ y/net/ethernet/eth.c2006-01-04 21:25:29.0 -0600
@@ -53,6 +53,7 @@
 #include linux/errno.h
 #include linux/config.h
 #include linux/init.h
+#include linux/if_ether.h
 #include net/dst.h
 #include net/arp.h
 #include net/sock.h
@@ -251,7 +252,7 @@ static int eth_mac_addr(struct net_devic
 
 static int eth_change_mtu(struct net_device *dev, int new_mtu)
 {
-   if ((new_mtu  68) || (new_mtu  1500))
+   if (new_mtu  68 || new_mtu  ETH_DATA_LEN)
return -EINVAL;
dev-mtu = new_mtu;
return 0;
@@ -272,7 +273,7 @@ void ether_setup(struct net_device *dev)
 
dev-type   = ARPHRD_ETHER;
dev-hard_header_len= ETH_HLEN;
-   dev-mtu= 1500; /* eth_mtu */
+   dev-mtu= ETH_DATA_LEN;
dev-addr_len   = ETH_ALEN;
dev-tx_queue_len   = 1000; /* Ethernet wants good queues */
dev-flags  = IFF_BROADCAST|IFF_MULTICAST;

--- x/net/ipv4/ip_gre.c 2006-01-02 21:21:10.0 -0600
+++ y/net/ipv4/ip_gre.c 2006-01-04 21:26:03.0 -0600
@@ -28,6 +28,7 @@
 #include linux/inetdevice.h
 #include linux/igmp.h
 #include linux/netfilter_ipv4.h
+#include linux/if_ether.h
 
 #include net/sock.h
 #include net/ip.h
@@ -1140,7 +1141,7 @@ static void ipgre_tunnel_setup(struct ne
 
dev-type   = ARPHRD_IPGRE;
dev-hard_header_len= LL_MAX_HEADER + sizeof(struct iphdr) + 4;
-   dev-mtu= 1500 - sizeof(struct iphdr) - 4;
+   dev-mtu= ETH_DATA_LEN - sizeof(struct iphdr) - 4;
dev-flags  = IFF_NOARP;
dev-iflink = 0;
dev-addr_len   = 4;
@@ -1152,7 +1153,7 @@ static int ipgre_tunnel_init(struct net_
struct ip_tunnel *tunnel;
struct iphdr *iph;
int hlen = LL_MAX_HEADER;
-   int mtu = 1500;
+   int mtu = ETH_DATA_LEN;
int addend = sizeof(struct iphdr) + 4;
 
tunnel = (struct ip_tunnel*)dev-priv;

--- x/net/ipv4/ipip.c   2006-01-02 21:21:10.0 -0600
+++ y/net/ipv4/ipip.c   2006-01-04 21:26:18.0 -0600
@@ -108,6 +108,7 @@
 #include linux/mroute.h
 #include linux/init.h
 #include linux/netfilter_ipv4.h
+#include linux/if_ether.h
 
 #include net/sock.h
 #include net/ip.h
@@ -786,7 +787,7 @@ static void ipip_tunnel_setup(struct net
 
dev-type   = ARPHRD_TUNNEL;
dev-hard_header_len= LL_MAX_HEADER + sizeof(struct iphdr);
-   dev-mtu= 1500 - sizeof(struct iphdr);
+   dev-mtu= ETH_DATA_LEN - sizeof(struct iphdr);
dev-flags  = IFF_NOARP;
dev-iflink = 0;
dev-addr_len   = 4;

--- x/net/ipv4/ipmr.c   2006-01-02 21:21:10.0 -0600
+++ y/net/ipv4/ipmr.c   2006-01-04 21:26:32.0 -0600
@@ -49,6 +49,7 @@
 #include linux/seq_file.h
 #include linux/mroute.h
 #include linux/init.h
+#include linux/if_ether.h
 #include net/ip.h
 #include net/protocol.h
 #include linux/skbuff.h
@@ -192,7 +193,7 @@ static struct net_device_stats *reg_vif_
 static void reg_vif_setup(struct net_device *dev)
 {
dev-type   = ARPHRD_PIMREG;
-   dev-mtu= 1500 - sizeof(struct iphdr) - 8;
+   dev-mtu= ETH_DATA_LEN - sizeof(struct iphdr) - 8;
dev-flags  = IFF_NOARP;
dev-hard_start_xmit= reg_vif_xmit;
dev-get_stats

Re: [PATCH] More instruction checks for net/core/filter.c

2006-01-03 Thread Kris Katterjohn
From : Patrick McHardy
Kris Katterjohn wrote:
 So keep the return statement, then?

Lets agree on adding WARN_ON(1) before the return statement.

Sounds good to me.

 After some googling, I found this OpenBSD kernel code which does a lot of 
 what my
 patch would add, but uses BPF_CLASS as you suggested earlier:
 
 http://fxr.watson.org/fxr/source//net/bpf_filter.c?v=OPENBSD
 
 My guess would be there isn't any requirement to return for a bad instruction
 while running the filter.

No, the paper doesn't mention anything like that, so your patch seems
fine. Interestingly it does mention that a division by 0 should abort
the filter with a return value of 0 - but the BSDs also catch this
during validation.

I reread it and saw that part about division by zero. I didn't catch that 
before.



Here's the new (and hopefully final) patch. It's a diff from 2.6.15:


--- x/net/core/filter.c 2006-01-03 10:53:52.0 -0600
+++ y/net/core/filter.c 2006-01-03 11:02:44.0 -0600
@@ -13,6 +13,7 @@
* 2 of the License, or (at your option) any later version.
*
* Andi Kleen - Fix a few bad bugs and races.
+ * Kris Katterjohn - Added many additional checks in sk_chk_filter()
*/

#include linux/module.h
@@ -250,7 +251,7 @@ load_b:
mem[fentry-k] = X;
continue;
default:
-   /* Invalid instruction counts as RET */
+   WARN_ON(1);
return 0;
}

@@ -300,38 +301,85 @@ int sk_chk_filter(struct sock_filter *fi
for (pc = 0; pc  flen; pc++) {
/* all jumps are forward as they are not signed */
ftest = amp;filter[pc];
-   if (BPF_CLASS(ftest-code) == BPF_JMP) {
-   /* but they mustn't jump off the end */
-   if (BPF_OP(ftest-code) == BPF_JA) {
-   /*
-* Note, the large ftest-k might cause loops.
-* Compare this with conditional jumps below,
-* where offsets are limited. --ANK (981016)
-*/
-   if (ftest-k = (unsigned)(flen-pc-1))
-   return -EINVAL;
-   } else {
-   /* for conditionals both must be safe */
-   if (pc + ftest-jt +1 = flen ||
-pc + ftest-jf +1 = flen)
-   return -EINVAL;
-   }
-   }

-   /* check for division by zero -Kris Katterjohn 2005-10-30 */
-   if (ftest-code == (BPF_ALU|BPF_DIV|BPF_K) amp;amp; ftest-k 
== 0)
-   return -EINVAL;
+   /* Only allow valid instructions */
+   switch (ftest-code) {
+   case BPF_ALU|BPF_ADD|BPF_K:
+   case BPF_ALU|BPF_ADD|BPF_X:
+   case BPF_ALU|BPF_SUB|BPF_K:
+   case BPF_ALU|BPF_SUB|BPF_X:
+   case BPF_ALU|BPF_MUL|BPF_K:
+   case BPF_ALU|BPF_MUL|BPF_X:
+   case BPF_ALU|BPF_DIV|BPF_X:
+   case BPF_ALU|BPF_AND|BPF_K:
+   case BPF_ALU|BPF_AND|BPF_X:
+   case BPF_ALU|BPF_OR|BPF_K:
+   case BPF_ALU|BPF_OR|BPF_X:
+   case BPF_ALU|BPF_LSH|BPF_K:
+   case BPF_ALU|BPF_LSH|BPF_X:
+   case BPF_ALU|BPF_RSH|BPF_K:
+   case BPF_ALU|BPF_RSH|BPF_X:
+   case BPF_ALU|BPF_NEG:
+   case BPF_LD|BPF_W|BPF_ABS:
+   case BPF_LD|BPF_H|BPF_ABS:
+   case BPF_LD|BPF_B|BPF_ABS:
+   case BPF_LD|BPF_W|BPF_LEN:
+   case BPF_LD|BPF_W|BPF_IND:
+   case BPF_LD|BPF_H|BPF_IND:
+   case BPF_LD|BPF_B|BPF_IND:
+   case BPF_LD|BPF_IMM:
+   case BPF_LDX|BPF_W|BPF_LEN:
+   case BPF_LDX|BPF_B|BPF_MSH:
+   case BPF_LDX|BPF_IMM:
+   case BPF_MISC|BPF_TAX:
+   case BPF_MISC|BPF_TXA:
+   case BPF_RET|BPF_K:
+   case BPF_RET|BPF_A:
+   break;
+
+   /* Some instructions need special checks */

-   /* check that memory operations use valid addresses. */
-   if (ftest-k = BPF_MEMWORDS) {
-   /* but it might not be a memory operation... */
-   switch (ftest-code) {
-   case BPF_ST:
-   case BPF_STX:   
-   case BPF_LD|BPF_MEM:
-   case BPF_LDX|BPF_MEM:   
+   case BPF_ALU|BPF_DIV|BPF_K:
+   /* check for division by zero */
+   if (ftest-k == 0)
return -EINVAL;
-   }
+   break

Re: [PATCH] More instruction checks for net/core/filter.c

2005-12-30 Thread Kris Katterjohn
From: Patrick McHardy
 Kris Katterjohn wrote:
  From: Patrick McHardy
  
 Kris Katterjohn wrote:
 
 --- x/net/core/filter.c2005-12-28 16:51:35.0 -0600
 +++ y/net/core/filter.c2005-12-28 16:53:32.0 -0600
 @@ -250,7 +250,7 @@ load_b:
mem[fentry-k] = X;
continue;
default:
 -  /* Invalid instruction counts as RET */
 +  /* Should never be reached */
 
 This stuff has had a number of bad bugs before, if it can't be reached,
 please call BUG or something similar instead of silently ignoring the
 error.
  
  
  I'll just remove the default label and return statement.
 
 Thats even worse, it will fall through to the second switch statement.
 Just call BUG(), since it means you forgot to check something.

I'm 99.99% sure I didn't forget anything. I just left it there in my first patch
because it was there before. Everything is checked for in sk_chk_filter(), so
the default branch will never be used. And if you think we need the default
branch, why call BUG instead of just returning 0 as before?

  The runtime is for BPF_ALU|BPF_DIV|BPF_X, not BPF_ALU|BPF_DIV|BPF_K. The 
  BPF_K
  instruction is constant and can be checked for at any time, but with BPF_X,
  it changes with each packet and must be checked at runtime.
 
 Ah, I missed that you already moved the check for div-by-constant
 in a previous patch. So the entire point of this patch is to remove
 the default-branch in the switch-statement? That hardly seems worth
 the additional amount of code.

No. The point of this patch is to stop a bad filter instruction from causing the
kernel to loop in sk_run_filter(), but always return 0. If we check to make sure
only valid instructions are used in sk_chk_filter(), then we eliminate that
problem. My idea is to check for everything in sk_chk_filter(). Check everything
there and make sure that when sk_run_filter() is called, it shouldn't have any
problems. I moved the check for constant-division-by-zero to sk_chk_filter() 
because it could be checked there. Now, I think a check for only valid
instructions should be there too, because we can go ahead and check it there.
sk_chk_filter() should return an error if the filter is bad, not allow it and
have sk_run_filter() give you nothing.

-
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


Re: [PATCH] More instruction checks for net/core/filter.c

2005-12-30 Thread Kris Katterjohn
From: Patrick McHardy
 Kris Katterjohn wrote:
  From: Patrick McHardy
  
 Thats even worse, it will fall through to the second switch statement.
 Just call BUG(), since it means you forgot to check something.
  
  
  I'm 99.99% sure I didn't forget anything. I just left it there in my first 
  patch
  because it was there before. Everything is checked for in sk_chk_filter(), 
  so
  the default branch will never be used. And if you think we need the default
  branch, why call BUG instead of just returning 0 as before?
 
 Because it means a check was missing. We had a number of bad bugs
 in there before, better to find them quick than have them lurking
 around until someone does an code audit. But in this case I tend
 to agree with you, it doesn't seem to affect anything critical.

So keep the return statement, then?

  No. The point of this patch is to stop a bad filter instruction from 
  causing the
  kernel to loop in sk_run_filter(), but always return 0. If we check to make 
  sure
  only valid instructions are used in sk_chk_filter(), then we eliminate that
  problem.
 
 That seems to be a purely theoretical problem, the common case is
 correctly compiled filters from libpcap. BTW: I haven't read the
 BPF specs/paper/whatever, but if this is documented behaviour,
 something might actually be relying on it.

I don't use libpcap much anymore (not because it's bad or anything) and I've 
seen
many programs that don't and just use custom BPF filters. I think it's a 
definite
plus to check these things in sk_chk_filter().

The only thing I've read over BPF is that USENIX paper from (I think) 1993 and I
don't recall it saying anything about the actual implementation of it, just 
going
over the instruction set. See below, though.

   My idea is to check for everything in sk_chk_filter(). Check everything
  there and make sure that when sk_run_filter() is called, it shouldn't have 
  any
  problems. I moved the check for constant-division-by-zero to 
  sk_chk_filter() because it could be checked there. Now, I think a check for 
  only valid
  instructions should be there too, because we can go ahead and check it 
  there.
  sk_chk_filter() should return an error if the filter is bad, not allow it 
  and
  have sk_run_filter() give you nothing.
 
 Well, I'm not convinced that there is a problem, but I do agree that its
 good to return an error for invalid filters - if they are actually
 invalid and its not documented behaviour to accept unknown instructions
 and treat them as return.

After some googling, I found this OpenBSD kernel code which does a lot of what 
my
patch would add, but uses BPF_CLASS as you suggested earlier:

http://fxr.watson.org/fxr/source//net/bpf_filter.c?v=OPENBSD

My guess would be there isn't any requirement to return for a bad instruction
while running the filter.

-
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


[PATCH] Remove needless variables in net/core/sock.c

2005-12-28 Thread Kris Katterjohn
Removes needless filter variables.

Signed-off by: Kris Katterjohn [EMAIL PROTECTED]

---

This is a diff from 2.6.15-rc7 and I'm not subscribed so please CC me on any
replies.

Thanks!

--- x/net/core/sock.c   2005-12-28 15:10:33.0 -0600
+++ y/net/core/sock.c   2005-12-28 15:10:44.0 -0600
@@ -195,7 +195,6 @@ int sock_setsockopt(struct socket *sock,
char __user *optval, int optlen)
 {
struct sock *sk=sock-sk;
-   struct sk_filter *filter;
int val;
int valbool;
struct linger ling;
@@ -444,15 +443,13 @@ set_rcvbuf:
break;
 
case SO_DETACH_FILTER:
-   spin_lock_bh(sk-sk_lock.slock);
-   filter = sk-sk_filter;
-if (filter) {
+   if (sk-sk_filter) {
+   spin_lock_bh(sk-sk_lock.slock);
+   sk_filter_release(sk, sk-sk_filter);
sk-sk_filter = NULL;
spin_unlock_bh(sk-sk_lock.slock);
-   sk_filter_release(sk, filter);
break;
}
-   spin_unlock_bh(sk-sk_lock.slock);
ret = -ENONET;
break;
 
@@ -678,15 +675,13 @@ out_free:
 
 void sk_free(struct sock *sk)
 {
-   struct sk_filter *filter;
struct module *owner = sk-sk_prot_creator-owner;
 
if (sk-sk_destruct)
sk-sk_destruct(sk);
 
-   filter = sk-sk_filter;
-   if (filter) {
-   sk_filter_release(sk, filter);
+   if (sk-sk_filter) {
+   sk_filter_release(sk, sk-sk_filter);
sk-sk_filter = NULL;
}
 
@@ -709,8 +704,6 @@ struct sock *sk_clone(const struct sock 
struct sock *newsk = sk_alloc(sk-sk_family, priority, sk-sk_prot, 0);
 
if (newsk != NULL) {
-   struct sk_filter *filter;
-
memcpy(newsk, sk, sk-sk_prot-obj_size);
 
/* SANITY */
@@ -737,9 +730,8 @@ struct sock *sk_clone(const struct sock 
sock_reset_flag(newsk, SOCK_DONE);
skb_queue_head_init(newsk-sk_error_queue);
 
-   filter = newsk-sk_filter;
-   if (filter != NULL)
-   sk_filter_charge(newsk, filter);
+   if (newsk-sk_filter != NULL)
+   sk_filter_charge(newsk, newsk-sk_filter);
 
if (unlikely(xfrm_sk_clone_policy(newsk))) {
/* It is still raw copy of parent, so invalidate


-
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


Re: [PATCH] Remove needless variables in net/core/sock.c

2005-12-28 Thread Kris Katterjohn
From: David S. Miller
 From: Kris Katterjohn [EMAIL PROTECTED]
 Date: Wed, 28 Dec 2005 13:38:02 -0800
 
  Unless you mean sk_filter could get set to NULL after the test, but
  before it's used.
 
 That's exactly what I mean.

Okey-dokey then.

-
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


[PATCH] More instruction checks for net/core/filter.c

2005-12-28 Thread Kris Katterjohn
This only allows valid filter instructions to be passed to the kernel.

Signed-off by: Kris Katterjohn [EMAIL PROTECTED]

---

This is a diff from 2.6.15-rc7 and I'm not subscribed so please CC me on 
replies.

I know I've sent a few patches for net/core/filter.c recently, and this should
be my last one for a while :)

This stops invalid filters from the beginning rather than looping through a bad
filter and not returning any packets.

All additional checks are still performed on the special instructions.

I've tested it and everything seems to work fine.

Thanks!

--- x/net/core/filter.c 2005-12-28 16:51:35.0 -0600
+++ y/net/core/filter.c 2005-12-28 16:53:32.0 -0600
@@ -250,7 +250,7 @@ load_b:
mem[fentry-k] = X;
continue;
default:
-   /* Invalid instruction counts as RET */
+   /* Should never be reached */
return 0;
}
 
@@ -300,38 +300,87 @@ int sk_chk_filter(struct sock_filter *fi
for (pc = 0; pc  flen; pc++) {
/* all jumps are forward as they are not signed */
ftest = filter[pc];
-   if (BPF_CLASS(ftest-code) == BPF_JMP) {
-   /* but they mustn't jump off the end */
-   if (BPF_OP(ftest-code) == BPF_JA) {
-   /*
-* Note, the large ftest-k might cause loops.
-* Compare this with conditional jumps below,
-* where offsets are limited. --ANK (981016)
-*/
-   if (ftest-k = (unsigned)(flen-pc-1))
-   return -EINVAL;
-   } else {
-   /* for conditionals both must be safe */
-   if (pc + ftest-jt +1 = flen ||
-   pc + ftest-jf +1 = flen)
-   return -EINVAL;
-   }
-   }
 
-   /* check for division by zero   -Kris Katterjohn 2005-10-30 */
-   if (ftest-code == (BPF_ALU|BPF_DIV|BPF_K)  ftest-k == 0)
-   return -EINVAL;
+   /* Only allow valid instructions -Kris Katterjohn 2005-12-28 */
+   switch (ftest-code) {
+   case BPF_ALU|BPF_ADD|BPF_K:
+   case BPF_ALU|BPF_ADD|BPF_X:
+   case BPF_ALU|BPF_SUB|BPF_K:
+   case BPF_ALU|BPF_SUB|BPF_X:
+   case BPF_ALU|BPF_MUL|BPF_K:
+   case BPF_ALU|BPF_MUL|BPF_X:
+   case BPF_ALU|BPF_DIV|BPF_X:
+   case BPF_ALU|BPF_AND|BPF_K:
+   case BPF_ALU|BPF_AND|BPF_X:
+   case BPF_ALU|BPF_OR|BPF_K:
+   case BPF_ALU|BPF_OR|BPF_X:
+   case BPF_ALU|BPF_LSH|BPF_K:
+   case BPF_ALU|BPF_LSH|BPF_X:
+   case BPF_ALU|BPF_RSH|BPF_K:
+   case BPF_ALU|BPF_RSH|BPF_X:
+   case BPF_ALU|BPF_NEG:
+   case BPF_LD|BPF_W|BPF_ABS:
+   case BPF_LD|BPF_H|BPF_ABS:
+   case BPF_LD|BPF_B|BPF_ABS:
+   case BPF_LD|BPF_W|BPF_LEN:
+   case BPF_LD|BPF_W|BPF_IND:
+   case BPF_LD|BPF_H|BPF_IND:
+   case BPF_LD|BPF_B|BPF_IND:
+   case BPF_LD|BPF_IMM:
+   case BPF_LDX|BPF_W|BPF_LEN:
+   case BPF_LDX|BPF_B|BPF_MSH:
+   case BPF_LDX|BPF_IMM:
+   case BPF_MISC|BPF_TAX:
+   case BPF_MISC|BPF_TXA:
+   case BPF_RET|BPF_K:
+   case BPF_RET|BPF_A:
+   break;
+
+   /* Some instructions need special checks */
+
+   case BPF_ALU|BPF_DIV|BPF_K:
+   /* check for division by zero 
+*-Kris Katterjohn 2005-10-30
+*/
+   if (ftest-k == 0)
+   return -EINVAL;
+   break;
+
+   case BPF_LD|BPF_MEM:
+   case BPF_LDX|BPF_MEM:
+   case BPF_ST:
+   case BPF_STX:
+   /* check for invalid memory addresses */
+   if (ftest-k = BPF_MEMWORDS)
+   return -EINVAL;
+   break;
 
-   /* check that memory operations use valid addresses. */
-   if (ftest-k = BPF_MEMWORDS) {
-   /* but it might not be a memory operation... */
-   switch (ftest-code) {
-   case BPF_ST:
-   case BPF_STX:   
-   case BPF_LD|BPF_MEM:
-   case BPF_LDX|BPF_MEM:   
+   case BPF_JMP|BPF_JA

[PATCH] Socket filter instruction limit validation

2005-12-06 Thread Kris Katterjohn
This patch checks to make sure that the number of instructions doesn't surpass
BPF_MAXINSNS in sk_chk_filter().

Signed-off-by: Kris Katterjohn [EMAIL PROTECTED]

---

This is a diff from 2.6.15-rc5. And I am not subscribed, so please CC me on any
replies.

The previous check in sk_chk_filter() doesn't seem very logical to me because it
should either be limited to BPF_MAXINSNS or only limited by the max value of an
`int' (not really limited). sk_attach_filter() and get_filter() in
drivers/net/ppp_generic.c limit it to BPF_MAXINSNS, but get_filter() in
drivers/isdn/i4l/isdn_ppp.c and anything else that will use it only get this
seemingly random limit.

This way it is checked for in only one place, and has a single constant limit.

Thanks!

--- x/net/core/filter.c 2005-12-06 04:01:50.0 -0600
+++ y/net/core/filter.c 2005-12-06 04:04:23.0 -0600
@@ -293,7 +293,8 @@ int sk_chk_filter(struct sock_filter *fi
struct sock_filter *ftest;
int pc;
 
-   if (((unsigned int)flen = (~0U / sizeof(struct sock_filter))) || flen 
== 0) 
+   /* check for valid number of instructions -Kris Katterjohn 2005-12-06 */
+   if (flen == 0 || flen  BPF_MAXINSNS)
return -EINVAL;
 
/* check the filter code now */
@@ -359,9 +360,9 @@ int sk_attach_filter(struct sock_fprog *
unsigned int fsize = sizeof(struct sock_filter) * fprog-len;
int err;
 
-   /* Make sure new filter is there and in the right amounts. */
-if (fprog-filter == NULL || fprog-len  BPF_MAXINSNS)
-return -EINVAL;
+   /* Make sure new filter is there */
+   if (fprog-filter == NULL)
+   return -EINVAL;
 
fp = sock_kmalloc(sk, fsize+sizeof(*fp), GFP_KERNEL);
if (!fp)


-
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