NetBSD Problem Report #49243
From www@NetBSD.org Mon Sep 29 15:34:31 2014
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
by mollari.NetBSD.org (Postfix) with ESMTPS id 7AC2FA65B9
for <gnats-bugs@gnats.NetBSD.org>; Mon, 29 Sep 2014 15:34:31 +0000 (UTC)
Message-Id: <20140929153429.D331CA65BA@mollari.NetBSD.org>
Date: Mon, 29 Sep 2014 15:34:29 +0000 (UTC)
From: jmcneill@invisible.ca
Reply-To: jmcneill@invisible.ca
To: gnats-bugs@NetBSD.org
Subject: IPv4 multicast socket options do not work on AF_INET6 sockets
X-Send-Pr-Version: www-1.0
>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:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.