packet: doc: how to PACKET_MMAP with one packet socket for rx and tx
Subsystems (3)
PATCH 1/1 packet: doc: how to PACKET_MMAP with one packet socket for rx and tx
Describe how to use one AF_PACKET socket for rx and tx.
Cc Daniel Borkmann <[email protected]>
Signed-off-by Norbert van Bolhuis <[email protected]>
--- Documentation/networking/packet_mmap.txt | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-)
Documentation/networking/packet_mmap.txt +14 -0
@@ -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: + + 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
Quoted 26 lines · Norbert van Bolhuis
Describe how to use one
AF_PACKETsocket for rx and tx.Cc Daniel Borkmann <[email protected]>Signed-off-by Norbert van Bolhuis <[email protected]>--- Documentation/networking/packet_mmap.txt | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-)Documentation/networking/packet_mmap.txt +5
-0@@ -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.
Documentation/networking/packet_mmap.txt tp_block_size/tp_frame_size frames there will be a gap between · line 423
Quoted 5 lines
Documentation/networking/packet_mmap.txt +2
-0@@ -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));
...Documentation/networking/packet_mmap.txt tp_block_size/tp_frame_size frames there will be a gap between · line 429
Quoted 5 lines
Documentation/networking/packet_mmap.txt +5
-0+ 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!
Quoted 3 lines
Documentation/networking/packet_mmap.txt +0
-0At 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