Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

sendmmsg() on NetBSD vs Linux



Hello list,

we've been recently reported that Knot DNS segfaults on NetBSD 7.

I've found that the problem is in the newly added sendmmsg() interface.
It's behavior slightly differs from the implementation in Linux. The
sendmmsg() on NetBSD modifies the msg_hdr.msg_iov member of the supplied
struct mmsg_hdr, which doesn't happen on Linux.

Sample code:

#define _GNU_SOURCE
#include <assert.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <arpa/inet.h>

int main(void)
{
        struct sockaddr_in6 sa = { 0 };
        sa.sin6_family = AF_INET6;
        sa.sin6_addr = in6addr_loopback;
        sa.sin6_port = htons(20000);

        int sock = socket(sa.sin6_family, SOCK_DGRAM, 0);
        assert(sock);

        char buffer[] = "hello";
        struct iovec io = { 0 };
        struct mmsghdr msg = {{ 0 }};

        msg.msg_hdr.msg_name = &sa;
        msg.msg_hdr.msg_namelen = sizeof(sa);
        msg.msg_hdr.msg_iov = &io;
        msg.msg_hdr.msg_iovlen = 1;
        io.iov_base = &buffer;
        io.iov_len = sizeof(buffer);

        sendmmsg(sock, &msg, 1, 0);
        assert(msg.msg_hdr.msg_iov == &io);

        close(sock);

        return 0;
}

The assertion after sendmmsg() fails on NetBSD:

netbsd-64$ ./a.out
assertion "msg.msg_hdr.msg_iov == &io" failed: file "./send.c", line 31,
function "main"
[1]   Abort trap (core dumped) ./a.out

I haven't found documentation describing the modification of input
parameters by sendmmsg(). But at the moment, our implementation relies
on the Linux behavior because we are reusing the structure.

Before implementing any workaround in our code, I wanted to check with
you, NetBSD developers. As this is originally a Linux interface, I would
prefer this was resolved in NetBSD by mimicking the Linux behavior. What
do you think?

Best regards,

Jan


Home | Main Index | Thread Index | Old Index