I am interested in accessing network packets via "bus-mastering" in a C++ application on Linux. I have a few questions relating to this overall topic:

1) How will I know which memory address range the "bus-mastering"-enabled Network card is writing the data to and would this be kernel or user space?

2) If #2 is "Kernel space", how could I change the card so that it writes to memory in user space?

3a) How can I access this particular user-space memory area from C++?

3b) I understand you cannot just start accessing memory areas of other processes from one application, only those explicitly "shared"- so how do I ensure the memory area written to directly by the network card is explicitly for sharing?

4) How do I know whether a network card implements "bus-mastering"?

I have come across the term PACKET_MMAP - is this going to be what I need?

有帮助吗?

解决方案

If you mmap a region of memory, and give the address of that to the OS, the OS can lock that region (so that it doesn't become swapped out) and get the physical address of the memory.

It is not at all used for that purpose, but the code in drivers/xen/privcmd.c, in the function mmap_mfn_range called from privcmd_ioctl_mmap (indirectly, by traverse_map). This in turn calls remap_area_mfn_pte_fn from xen_remap_domain_mfn_range.

So, if you do something along those lines in the driver, such that the pages are locked into memory and belong to the application, you can program the physical address(es) of the mmap'd region into the hardware of the network driver, and get the data directly to the user-mode memory that was mmap'd by the user code.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top