aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNorbert van Bolhuis <nvbolhuis@aimvalley.nl>2014-01-10 04:22:37 -0500
committerDavid S. Miller <davem@davemloft.net>2014-01-13 17:45:59 -0500
commit7e11daa7c19ec319fa4b750fd249a18957f17797 (patch)
tree57227f64774c356c4643e35d4de97faddb34217b
parent6daaf0de2f3170206f57e7881adfbd8682cdd7fb (diff)
packet: doc: describe PACKET_MMAP with one packet socket for rx and tx
Document how to use one AF_PACKET mmap socket for RX and TX. Signed-off-by: Norbert van Bolhuis <nvbolhuis@aimvalley.nl> Signed-off-by: Daniel Borkmann <dborkman@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--Documentation/networking/packet_mmap.txt18
1 files changed, 18 insertions, 0 deletions
diff --git a/Documentation/networking/packet_mmap.txt b/Documentation/networking/packet_mmap.txt
index 723bf3d33a6e..91ffe1d9e8ca 100644
--- a/Documentation/networking/packet_mmap.txt
+++ b/Documentation/networking/packet_mmap.txt
@@ -98,6 +98,11 @@ by the kernel.
98The destruction of the socket and all associated resources 98The destruction of the socket and all associated resources
99is done by a simple call to close(fd). 99is done by a simple call to close(fd).
100 100
101Similarly as without PACKET_MMAP, it is possible to use one socket
102for capture and transmission. This can be done by mapping the
103allocated RX and TX buffer ring with a single mmap() call.
104See "Mapping and use of the circular buffer (ring)".
105
101Next I will describe PACKET_MMAP settings and its constraints, 106Next I will describe PACKET_MMAP settings and its constraints,
102also the mapping of the circular buffer in the user process and 107also the mapping of the circular buffer in the user process and
103the use of this buffer. 108the use of this buffer.
@@ -414,6 +419,19 @@ tp_block_size/tp_frame_size frames there will be a gap between
414the frames. This is because a frame cannot be spawn across two 419the frames. This is because a frame cannot be spawn across two
415blocks. 420blocks.
416 421
422To use one socket for capture and transmission, the mapping of both the
423RX and TX buffer ring has to be done with one call to mmap:
424
425 ...
426 setsockopt(fd, SOL_PACKET, PACKET_RX_RING, &foo, sizeof(foo));
427 setsockopt(fd, SOL_PACKET, PACKET_TX_RING, &bar, sizeof(bar));
428 ...
429 rx_ring = mmap(0, size * 2, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
430 tx_ring = rx_ring + size;
431
432RX must be the first as the kernel maps the TX ring memory right
433after the RX one.
434
417At the beginning of each frame there is an status field (see 435At the beginning of each frame there is an status field (see
418struct tpacket_hdr). If this field is 0 means that the frame is ready 436struct tpacket_hdr). If this field is 0 means that the frame is ready
419to be used for the kernel, If not, there is a frame the user can read 437to be used for the kernel, If not, there is a frame the user can read