Josh wrote:mchael wrote:why a struct? Why not a multi col array? Be faster and easier if working with a database or file structure.
What does an array have to do with a structure? Do you know why Andy needs the requested structure? I'm sorry mchael but you have no idea what you're talking about.
Thanks for your support josh. I was trying to get netfilter queue working in linux to create a userland bridge where i could inspect packets passing between two ethernet interfaces. In the end i went with AF_PACKET raw sockets. It currently passes 1Gbit/sec at around 10% cpu usage on a quad core i5 machine. I think most of the usage is in the kernal. Code below if anyone wants to experiment. You need two spare ethernet adapters and you will have to enter the index number for each one. You must use ethtool to turn off offloading stuff on each ethernet adapter. You must also put each adapter in promiscuous mode.
Code: Select all
sudo ethtool --offload enp1s0f0 gro off <-- do for both interfaces
sudo ip link set enp1s0f0 promisc on <-- do for both interfaces
Code: Select all
;run as root or start PB with sudo if you are using the debugger
#AF_PACKET = 17
#SOCK_RAW = 3
#ETH_P_ALL = $0003
Structure sockaddr_ll
sll_family.u ;/* Always AF_PACKET */
sll_protocol.u ;/* Physical layer protocol */
sll_ifindex.i ;/* Interface number */
sll_hatype.u ;/* ARP hardware type */
sll_pkttype.b ;/* Packet type */
sll_halen.b ;/* Length of address */
sll_addr.b[8] ;/* Physical layer address */
EndStructure
Global socket1, socket2
;it's ugly but I used these 2 lines to get the index values for the two interfaces. Quick and dirty :)
;if_indextoname_(3, @iface)
;iface1.s = PeekS(@iface,-1,#PB_Ascii)
Procedure in(*val)
Debug "Thread 1 Started"
*sptr = socket_config.sockaddr_ll
socket1 = socket_(#AF_PACKET, #SOCK_RAW, htons_(#ETH_P_ALL))
If socket1 <> -1
socket_config\sll_family = #AF_PACKET
socket_config\sll_ifindex = 3
socket_config\sll_protocol = htons_(#ETH_P_ALL)
If bind_(socket1, *sptr, SizeOf(socket_config)) = 0
*buffer = AllocateMemory(65536)
Repeat
recv = recv_(socket1, *buffer, 65536, 0);, info, SizeOf(info))
If recv > 0
send_(socket2, *buffer, recv, 0)
Else
Debug "in error"
EndIf
ForEver
EndIf
EndIf
EndProcedure
Procedure out(*val)
Debug "Thread 2 Started"
*sptr = socket_config.sockaddr_ll
socket2 = socket_(#AF_PACKET, #SOCK_RAW, htons_(#ETH_P_ALL))
If socket2 <> -1
socket_config\sll_family = #AF_PACKET
socket_config\sll_ifindex = 4
socket_config\sll_protocol = htons_(#ETH_P_ALL)
If bind_(socket2, *sptr, SizeOf(socket_config)) = 0
*buffer = AllocateMemory(65536)
Repeat
recv = recv_(socket2, *buffer, 65536, 0);, info, SizeOf(info))
If recv > 0
send_(socket1, *buffer, recv, 0)
Else
Debug "in error"
EndIf
ForEver
EndIf
EndIf
EndProcedure
in = CreateThread(@in(), 0)
out = CreateThread(@out(), 0)
WaitThread(in)