From: Daniel Borkmann <dborkman@redhat.com>
To: Norbert van Bolhuis <nvbolhuis@aimvalley.nl>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH net-next] packet: doc: how to PACKET_MMAP with one packet socket for rx and tx
Date: Wed, 08 Jan 2014 15:29:38 +0100 [thread overview]
Message-ID: <52CD60D2.5040608@redhat.com> (raw)
In-Reply-To: <52CD5F44.2090307@aimvalley.nl>
On 01/08/2014 03:23 PM, Norbert van Bolhuis wrote:
>
> Describe how to use one AF_PACKET socket for rx and tx.
>
> Cc: Daniel Borkmann <dborkman@redhat.com>
> Signed-off-by: Norbert van Bolhuis <nvbolhuis@aimvalley.nl>
> ---
> Documentation/networking/packet_mmap.txt | 14 ++++++++++++++
> 1 files changed, 14 insertions(+), 0 deletions(-)
>
> diff --git a/Documentation/networking/packet_mmap.txt b/Documentation/networking/packet_mmap.txt
> index 723bf3d..2503a5a 100644
> --- a/Documentation/networking/packet_mmap.txt
> +++ b/Documentation/networking/packet_mmap.txt
> @@ -98,6 +98,11 @@ by the kernel.
> The destruction of the socket and all associated resources
> is done by a simple call to close(fd).
>
> +As without PACKET_MMAP, it is possible to use one socket for
> +capture and transmission. This can be done by mapping the
> +allocated RX and TX buffer ring with a single mmap() call. See
> +"Mapping and use of the circular buffer (ring)".
> +
> Next I will describe PACKET_MMAP settings and its constraints,
> also the mapping of the circular buffer in the user process and
> the use of this buffer.
> @@ -414,6 +419,15 @@ tp_block_size/tp_frame_size frames there will be a gap between
> the frames. This is because a frame cannot be spawn across two
> blocks.
>
> +To use one socket for capture and transmission, the mapping of both the RX
> +and TX buffer ring has to be done with one call to mmap:
As this caused some confusion in the past for some people, it would be
great to mention here in this example also:
...
setsockopt(fd, SOL_PACKET, PACKET_RX_RING, &foo, sizeof(foo));
setsockopt(fd, SOL_PACKET, PACKET_TX_RING, &bar, sizeof(bar));
...
> + rx_ring = mmap(0, size * 2, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
> + tx_ring = rx_ring + size;
> +
> +RX must be the first as the kernel maps the TX ring memory right after
> +the RX one.
Otherwise looks perfect!
> At the beginning of each frame there is an status field (see
> struct tpacket_hdr). If this field is 0 means that the frame is ready
> to be used for the kernel, If not, there is a frame the user can read
prev parent reply other threads:[~2014-01-08 14:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-08 14:23 [PATCH net-next] packet: doc: how to PACKET_MMAP with one packet socket for rx and tx Norbert van Bolhuis
2014-01-08 14:29 ` Daniel Borkmann [this message]
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=52CD60D2.5040608@redhat.com \
--to=dborkman@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=nvbolhuis@aimvalley.nl \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.