PACKET_MMAP for normal sockets.

369 views
Skip to first unread message

John Hening

unread,
Jun 6, 2018, 8:10:16 AM6/6/18
to mechanical-sympathy
 
This file documents the mmap() facility available with the PACKET
socket interface on 2.4/2.6/3.x kernels. This type of sockets is used for
i) capture network traffic with utilities like tcpdump, ii) transmit network
traffic, or any other that needs raw access to network interface.


I consider using it to try improving performance of my simple-java-networking-library and test how it works.

But, from documentation I read that it is a facility available with the PACKET socket interface. So, the my question is


1. Is it possible to use that for normal (AF_INET, SOCK_DGRAM/SOCK_STREAM) socket to send/receive a message?
2. Use cases:

i) capture network traffic with utilities like tcpdump,
ii) transmit network traffic, or any other that needs raw access to network interface.
also don't indicates on possibility to use that for "normal" sockets.
3. Do you have any experience with that?

Michael Barker

unread,
Jun 9, 2018, 9:53:19 PM6/9/18
to mechanica...@googlegroups.com
Hi,

I recently finished a small project at work using packet_mmap

1. Is it possible to use that for normal (AF_INET, SOCK_DGRAM/SOCK_STREAM) socket to send/receive a message?

I've only used AF_PACKET, SOCK_RAW.  It looks like SOCK_DGRAM can be used if you don't need the link level information, but you are still restricted to AF_PACKET.
 
2. Use cases:

i) capture network traffic with utilities like tcpdump,
That was our use case.
ii) transmit network traffic, or any other that needs raw access to network interface.
also don't indicates on possibility to use that for "normal" sockets.

AFAIK, packet_mmap is for use cases where you don't need the kernel to provide the networking services, e.g. IP, TCP, UDP.  So you would either be providing that yourself or not need it (e.g. packet capture).
 
3. Do you have any experience with that?

The only other point to note from our experience with using packet_mmap is that the experience from Java was not great.  Mostly because of the security restrictions.  Using AF_PACKET (and SOCK_RAW) requires privileged access, so you need to either run as root or have CAP_NET_RAW (CAP_IPC_LOCK is also required on some kernel versions) set as a capability on the binary.  Capabilities don't work with Java as they need to be set on the Java runtime binary (e.g. /usr/bin/java) and doing this messes up the JVM as it loses it's default search paths for shared libraries and fails to start.  We've favoured doing this type of privileged access in C and using IPC to transfer the data to Java.

Mike.

Greg Young

unread,
Jun 10, 2018, 5:19:38 AM6/10/18
to mechanica...@googlegroups.com
What was the performance cost on the interop? What speed of network can you handle? Is this something that should not be surfaced?

--
You received this message because you are subscribed to the Google Groups "mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mechanical-symp...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Studying for the Turing test
Reply all
Reply to author
Forward
0 new messages