NetBSD-Bugs archive

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

kern/49243: IPv4 multicast socket options do not work on AF_INET6 sockets



>Number:         49243
>Category:       kern
>Synopsis:       IPv4 multicast socket options do not work on AF_INET6 sockets
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Sep 29 15:35:01 +0000 2014
>Originator:     Jared McNeill
>Release:        7.0_BETA
>Organization:
>Environment:
NetBSD undine 7.0_BETA NetBSD 7.0_BETA (RPI) #7: Sun Sep 21 12:31:24 ADT 2014  jmcneill@grey:/home/jmcneill/netbsd/7/src/sys/arch/evbarm/compile/obj/RPI evbarm

>Description:
There is no way (that I can tell) to do IPv4 multicast ops using an AF_INET6 socket. This restricts the functionality of IPv4-mapped address usage. IP_MULTICAST_IF, IP_MULTICAST_TTL, IP_MULTICAST_LOOP, IP_ADD_MEMBERSHIP, and IP_DROP_MEMBERSHIP all fail, altho I suspect any sockopt with IPPROTO_IP will.

The following test program using IP_ADD_MEMBERSHIP works on Linux and fails on NetBSD. I suspect COMPAT_LINUX would also fail but I haven't tested it.

I've also included another test that attempts to use IPV6_JOIN_GROUP with an IPv4-mapped group; this fails as well with EINVAL because of this check: http://nxr.netbsd.org/xref/src/sys/netinet6/ip6_output.c#2357
>How-To-Repeat:
/* Try to IP_ADD_MEMBERSHIP on an AF_INET6 socket -> ENOPROTOOPT */

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int
main(int argc, char *argv[])
{
        struct ip_mreq mreq;
        int s, rv;

        s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
        assert(s != -1);

        memset(&mreq, 0, sizeof(mreq));
        mreq.imr_multiaddr.s_addr = inet_addr("239.255.255.250");
        mreq.imr_interface.s_addr = INADDR_ANY;
        rv = setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));
        if (rv == -1) {
                perror("setsockopt IP_ADD_MEMBERSHIP");
                return EXIT_FAILURE;
        }

        printf("success\n");
        return EXIT_SUCCESS;
}



/* Try to IPV6_JOIN_GROUP with an IPv4-mapped multicast group -> EINVAL */

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int
main(int argc, char *argv[])
{
        struct ipv6_mreq mreq;
        int s, rv;

        s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
        assert(s != -1);


        memset(&mreq, 0, sizeof(mreq));
        rv = inet_pton(AF_INET6, "::FFFF:239.255.255.250",
            &mreq.ipv6mr_multiaddr);
        assert(rv == 1);
        mreq.ipv6mr_interface = 0;
        rv = setsockopt(s, IPPROTO_IPV6, IPV6_JOIN_GROUP,
            &mreq, sizeof(mreq));
        if (rv == -1) {
                perror("setsockopt IPV6_JOIN_GROUP");
                return EXIT_FAILURE;
        }

        printf("success\n");
        return EXIT_SUCCESS;
}

>Fix:



Home | Main Index | Thread Index | Old Index