netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2] packet: doc: how to PACKET_MMAP with one packet socket for rx and tx
@ 2014-01-08 14:46 Norbert van Bolhuis
  2014-01-08 14:48 ` Daniel Borkmann
  0 siblings, 1 reply; 3+ messages in thread
From: Norbert van Bolhuis @ 2014-01-08 14:46 UTC (permalink / raw)
  To: netdev; +Cc: Daniel Borkmann


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 |   18 ++++++++++++++++++
  1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/Documentation/networking/packet_mmap.txt b/Documentation/networking/packet_mmap.txt
index 723bf3d..5566c20 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,19 @@ 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:
+
+    ...
+    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.
+
  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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next v2] packet: doc: how to PACKET_MMAP with one packet socket for rx and tx
  2014-01-08 14:46 [PATCH net-next v2] packet: doc: how to PACKET_MMAP with one packet socket for rx and tx Norbert van Bolhuis
@ 2014-01-08 14:48 ` Daniel Borkmann
  2014-01-10  4:10   ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Borkmann @ 2014-01-08 14:48 UTC (permalink / raw)
  To: Norbert van Bolhuis; +Cc: netdev

On 01/08/2014 03:46 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>

Acked-by: Daniel Borkmann <dborkman@redhat.com>

Thanks Norbert!

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next v2] packet: doc: how to PACKET_MMAP with one packet socket for rx and tx
  2014-01-08 14:48 ` Daniel Borkmann
@ 2014-01-10  4:10   ` David Miller
  0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2014-01-10  4:10 UTC (permalink / raw)
  To: dborkman; +Cc: nvbolhuis, netdev

From: Daniel Borkmann <dborkman@redhat.com>
Date: Wed, 08 Jan 2014 15:48:14 +0100

> On 01/08/2014 03:46 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>
> 
> Acked-by: Daniel Borkmann <dborkman@redhat.com>

This doesn't apply to net-next.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-01-10  4:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-08 14:46 [PATCH net-next v2] packet: doc: how to PACKET_MMAP with one packet socket for rx and tx Norbert van Bolhuis
2014-01-08 14:48 ` Daniel Borkmann
2014-01-10  4:10   ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).