Is it possible to use mmap_pack for linux without root access?

Linux has a function to provide efficient capture of network packets by mmapping a shared buffer between the kernel and the user. I am trying to use this interface in such a way that it does not require root access (since I do not have it).

Often packet_mmap is used to directly view all packets on the network, which will require root access. My application only needs the standard linux interface of a UDP socket. I want to use package_mmap solely for efficiency - now syscalls consumes more than 50% of my processor cycles.

Is there a way to configure packet_mmap so that it can be used from user space?

+7
source share
2 answers

Looking at the Linux Git kernel repository, it looks like neither PF_INET sockets nor PF_INET6 sockets support memory access, so if

My application only needs the standard linux interface of a UDP socket. I want to use package_mmap solely for efficiency - now syscalls consumes more than 50% of my processor cycles.

you mean that you want to use memory access for a regular UDP or TCP socket, unfortunately you cannot. The same goes for raw IP sockets.

Sockets

PF_PACKET support memory-compatible access, but they require elevated privileges, whether you use memory access or not. They do not replace the PF_INET or PF_INET6 ; they are a mechanism for reading and writing data link packets, so if you want to run regular Internet applications on them, good luck:

  • You will have to reuse the IP address and any transport protocol you use (UDP, TCP, etc.);
  • somehow you have to keep the IP kernel and transport protocol stack from processing these packets;

and you really don't want to do this.

(Note that with “elevated privileges” I do not necessarily mean “root privileges”; it is enough to have CAP_NET_RAW privileges. However, as I already noted, if you are trying to replace normal socket access, you want to use PF_PACKET sockets.)

+3
source

Although this really does not answer the question (as it specifically relates to the mm_ap package), given your options:

  • Receiving UDP packets
  • Want to reduce system calls, nothing more.
  • Desire to use Linux-specific features, but not root
  • The features of mass_pack are not really needed or not needed.

I would recommend you completely forget about the_mmap package and instead take a look at recvmmsg (pay attention to spelling, not a typo).

recvmmsg does not require special privileges, it is very intuitive (there are no obscure things, it works just like readv ), and it allows you to receive many packets in one call, which significantly reduces the overhead of syscall.

+4
source

All Articles