Netdev List
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: David Miller <davem@davemloft.net>
Cc: victor@inliniac.net, netdev@vger.kernel.org
Subject: Re: [PATCH 2/2] packet: Add fanout support.
Date: Tue, 05 Jul 2011 06:33:49 +0200	[thread overview]
Message-ID: <1309840429.2720.26.camel@edumazet-laptop> (raw)
In-Reply-To: <20110704.212014.236340473910292460.davem@davemloft.net>

Le lundi 04 juillet 2011 à 21:20 -0700, David Miller a écrit :
> Fanouts allow packet capturing to be demuxed to a set of AF_PACKET
> sockets.  Two fanout policies are implemented:
> 
> 1) Hashing based upon skb->rxhash
> 
> 2) Pure round-robin
> 
> An AF_PACKET socket must be fully bound before it tries to add itself
> to a fanout.  All AF_PACKET sockets trying to join the same fanout
> must all have the same bind settings.
> 
> Fanouts are identified (within a network namespace) by a 16-bit ID.
> The first socket to try to add itself to a fanout with a particular
> ID, creates that fanout.  When the last socket leaves the fanout
> (which happens only when the socket is closed), that fanout is
> destroyed.
> 
> Signed-off-by: David S. Miller <davem@davemloft.net>
> ---
>  include/linux/if_packet.h |    4 +
>  net/packet/af_packet.c    |  250 ++++++++++++++++++++++++++++++++++++++++++++-
>  2 files changed, 249 insertions(+), 5 deletions(-)
> 
> diff --git a/include/linux/if_packet.h b/include/linux/if_packet.h
> index 7b31863..1efa1cb 100644
> --- a/include/linux/if_packet.h
> +++ b/include/linux/if_packet.h
> @@ -49,6 +49,10 @@ struct sockaddr_ll {
>  #define PACKET_VNET_HDR			15
>  #define PACKET_TX_TIMESTAMP		16
>  #define PACKET_TIMESTAMP		17
> +#define PACKET_FANOUT			18
> +
> +#define PACKET_FANOUT_HASH		0
> +#define PACKET_FANOUT_LB		1
>  
>  struct tpacket_stats {
>  	unsigned int	tp_packets;
> diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
> index bb281bf..7db1e12 100644
> --- a/net/packet/af_packet.c
> +++ b/net/packet/af_packet.c
> @@ -187,9 +187,11 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg);
>  
>  static void packet_flush_mclist(struct sock *sk);
>  
> +struct packet_fanout;
>  struct packet_sock {
>  	/* struct sock has to be the first member of packet_sock */
>  	struct sock		sk;
> +	struct packet_fanout	*fanout;
>  	struct tpacket_stats	stats;
>  	struct packet_ring_buffer	rx_ring;
>  	struct packet_ring_buffer	tx_ring;
> @@ -212,6 +214,24 @@ struct packet_sock {
>  	struct packet_type	prot_hook ____cacheline_aligned_in_smp;
>  };
>  
> +#define PACKET_FANOUT_MAX	2048
> +
> +struct packet_fanout {
> +#ifdef CONFIG_NET_NS
> +	struct net		*net;
> +#endif
> +	int			num_members;
> +	u16			id;
> +	u8			type;
> +	u8			pad;
> +	atomic_t		rr_cur;
> +	struct list_head	list;
> +	struct sock		*arr[PACKET_FANOUT_MAX];

Thats about 16Kbytes, yet you use kzalloc()

> +	spinlock_t		lock;
> +	atomic_t		sk_ref;
> +	struct packet_type	prot_hook ____cacheline_aligned_in_smp;
> +};
> +

Maybe use a dynamic array ? I suspect most uses wont even reach 16
sockets anyway...


  reply	other threads:[~2011-07-05  4:33 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-05  4:20 [PATCH 2/2] packet: Add fanout support David Miller
2011-07-05  4:33 ` Eric Dumazet [this message]
2011-07-05  4:36   ` David Miller
2011-07-05  6:21 ` Eric Dumazet
2011-07-05  6:56   ` Victor Julien
2011-07-05  7:00     ` Eric Dumazet
2011-07-05  7:06       ` Victor Julien
2011-07-05  7:50       ` David Miller
2011-07-05  7:52         ` Victor Julien
2011-07-05  8:02           ` David Miller
2011-07-05  8:47             ` Hagen Paul Pfeifer
2011-07-05  8:48             ` Victor Julien
2011-07-05  9:01               ` David Miller
2011-07-05 16:03       ` Loke, Chetan
2011-07-05 16:08         ` David Miller
2011-07-05 16:16         ` Eric Dumazet
2011-07-05 16:21           ` Victor Julien
2011-07-05 16:23             ` Eric Dumazet
2011-07-05 17:15               ` Victor Julien
2011-07-05 18:26                 ` Eric Dumazet
2011-07-05 18:34                   ` Victor Julien
2011-07-05 17:35           ` Loke, Chetan
2011-07-05 18:20             ` Eric Dumazet
2011-07-05 21:10               ` Loke, Chetan
2011-07-05  7:48     ` David Miller
2011-07-05  7:46   ` David Miller
2011-07-05  9:50     ` Eric Dumazet
2011-07-05 10:07       ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1309840429.2720.26.camel@edumazet-laptop \
    --to=eric.dumazet@gmail.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=victor@inliniac.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox