libvma
libvma copied to clipboard
recvfrom_zcopy - can't tell address packet was received on
I have a use case of listening on 0.0.0.0
but receiving multicast packets from multiple sources. I'd like to register the destination address (specifically the OS interface ID) the packet was received on.
Normally this can be done using recvmsg
. This provides you with msghdr
, and it can be queried for those properties.However libvma provides a zero copy function only for recvfrom
.
I think the best solution is to provide an implementation of recvmsg_zcopy
, which is equivalent to recvmsg
.
Another option I see is that vma_packet_t
has a void* packet_id
member. This is probably a mem_buf_desc_t
pointer, but I'm not sure. Either way, the mem_buf_desc_t
is not exposed in vma_extra.h
, so I wonder if I am discouraged from using it or not.
So to summarize, I'll try to have it as a bug report below.
Steps to reproduce:
- Use
recvfrom_zcopy
to receive a UDP packet that can arrive from multiple sources
Actual results:
- Packet cannot be queried for its destination address (interface it was received on)
Expected results:
- An API is available to query the packet for its TCP/UDP and IP headers
This is generally solved with a vma_recvmsg_callback_t function, but I disliked this approach because the callback made it harder to relate this to the packet received later.
My preferred solution was that I added my own function to libvma to do this in socket-redirect.cpp as follows:
extern "C" int vma_get_rx_packet_info(struct vma_packet_t *pkts, sockaddr_in *src, sockaddr_in *dst, struct timespec hw_timestamp) { if (!pkts) return -1; auto p_mem_buf_desc = reinterpret_cast<const mem_buf_desc_t>(pkts->packet_id); if (src) *src = p_mem_buf_desc->rx.src; if (dst) *dst = p_mem_buf_desc->rx.dst; if (hw_timestamp) *hw_timestamp = p_mem_buf_desc->rx.timestamps.hw; return 0; }