Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recvfrom_zcopy - can't tell address packet was received on #829

Open
danfruehauf opened this issue Mar 29, 2019 · 1 comment
Open

recvfrom_zcopy - can't tell address packet was received on #829

danfruehauf opened this issue Mar 29, 2019 · 1 comment

Comments

@danfruehauf
Copy link

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:

  1. Use recvfrom_zcopy to receive a UDP packet that can arrive from multiple sources

Actual results:

  1. Packet cannot be queried for its destination address (interface it was received on)

Expected results:

  1. An API is available to query the packet for its TCP/UDP and IP headers
@srockdavew
Copy link

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants