NetBSD Problem Report #47408

From www@NetBSD.org  Sat Jan  5 20:54:33 2013
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	by www.NetBSD.org (Postfix) with ESMTP id AD34F63E98E
	for <gnats-bugs@gnats.NetBSD.org>; Sat,  5 Jan 2013 20:54:32 +0000 (UTC)
Message-Id: <20130105205431.4DA2363E98E@www.NetBSD.org>
Date: Sat,  5 Jan 2013 20:54:31 +0000 (UTC)
From: anthony.mallet@laas.fr
Reply-To: anthony.mallet@laas.fr
To: gnats-bugs@NetBSD.org
Subject: sendto(2) issue with IPv6 UDP datagrams
X-Send-Pr-Version: www-1.0

>Number:         47408
>Category:       kern
>Synopsis:       sendto(2) issue with IPv6 UDP datagrams
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jan 05 20:55:00 +0000 2013
>Closed-Date:    Mon Oct 07 06:59:09 +0000 2013
>Last-Modified:  Mon Oct 07 06:59:09 +0000 2013
>Originator:     Anthony Mallet
>Release:        6.99.16, Thu Jan  3 14:14:16 CET 2013
>Organization:
>Environment:
NetBSD cactus 6.99.16 NetBSD 6.99.16 (CACTUS) #21: Thu Jan  3 14:14:16 CET 2013
>Description:
I'm fighting with pkgsrc/net/wide-dhcpv6. To make a long story short, I think I
finally isolated the issue, that I can reproduce with the attached test program.

It seems that, for any socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP), the second
sendto(2) call will fail with EISCONN, even though the socket is never
connected. Also, trying to explicitly connect the socket will fail. This does
not happen for AF_INET.

Here is the output of the attached test program. This is on a Jan 3 -current,
and I get the same results on another -current machine from Oct 20. I can
verify with tcpdump that the packets are correctly transmitted (or not). I could test on a Linux machine and it worked fine.

ficus[~] > gcc -Wall -o sendto sendto.c
ficus[~] > ./sendto -4
sendto: 1st sendto: PASS
sendto: 2nd sendto: PASS
sendto: 1st connect: PASS
sendto: 1st send: PASS
sendto: 2nd connect: PASS
sendto: 2nd send: PASS
ficus[~] > ./sendto -6
sendto: 1st sendto: PASS
sendto: 2nd sendto: FAIL: Socket is already connected
sendto: 1st connect: FAIL: Socket is already connected
sendto: 1s send: FAIL: Destination address required
sendto: 2nd connect: FAIL: Socket is already connected
sendto: 2nd send: FAIL: Destination address required
ficus[~] > 

>How-To-Repeat:
/* this is the sendto(2) test program */
#include <sys/socket.h>

#include <netinet/in.h>

#include <err.h>
#include <netdb.h>
#include <string.h>

int
main(int argc, const char *argv[])
{
  struct addrinfo hints;
  struct addrinfo *res;
  const char msg[] = "sendto test";
  int S, s;
  int e;

  /* lookup localhost addr, depending on argv[1] */
  memset(&hints, 0, sizeof(hints));
  if (argc > 1 && !strcmp("-6", argv[1]))
    hints.ai_family = AF_INET6;
  else
    hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_protocol = IPPROTO_UDP;
  hints.ai_flags = 0;
  e = getaddrinfo("localhost", "9999", &hints, &res);
  if (e) errx(2, "getaddrinfo: %s", gai_strerror(e));

  /* server socket */
  S = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
  if (S < 0) err(2, "server socket");
  if (bind(S, res->ai_addr, res->ai_addrlen) < 0) err(2, "bind");

  /* client socket */
  s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
  if (s < 0) err(2, "client socket");

  /* sendto */
  e = sendto(s, msg, sizeof(msg), 0, res->ai_addr, res->ai_addrlen);
  if (e != sizeof(msg))
    warn("1s sendto: FAIL");
  else
    warnx("1st sendto: PASS");

  e = sendto(s, msg, sizeof(msg), 0, res->ai_addr, res->ai_addrlen);
  if (e != sizeof(msg))
    warn("2nd sendto: FAIL");
  else
    warnx("2nd sendto: PASS");

  /* connect + send */
  e = connect(s, res->ai_addr, res->ai_addrlen);
  if (e)
    warn("1st connect: FAIL");
  else
    warnx("1st connect: PASS");
  e = send(s, msg, sizeof(msg), 0);
  if (e != sizeof(msg))
    warn("1s send: FAIL");
  else
    warnx("1st send: PASS");

  e = connect(s, res->ai_addr, res->ai_addrlen);
  if (e)
    warn("2nd connect: FAIL");
  else
    warnx("2nd connect: PASS");
  e = send(s, msg, sizeof(msg), 0);
  if (e != sizeof(msg))
    warn("2nd send: FAIL");
  else
    warnx("2nd send: PASS");

  return 0;
}

>Fix:

>Release-Note:

>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/47408 CVS commit: src/sys/netinet6
Date: Sat, 5 Jan 2013 19:17:15 -0500

 Module Name:	src
 Committed By:	christos
 Date:		Sun Jan  6 00:17:14 UTC 2013

 Modified Files:
 	src/sys/netinet6: udp6_output.c

 Log Message:
 PR/47408: Anthony Mallet: sendto(2) issue with IPv6 UDP datagrams
 - don't connect when the local port is 0, just set the local port number.
 - remove redundant assignment
 XXX: pullup-6


 To generate a diff of this commit:
 cvs rdiff -u -r1.43 -r1.44 src/sys/netinet6/udp6_output.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: Anthony Mallet <anthony.mallet@laas.fr>
To: gnats-bugs@netbsd.org
Cc: kern-bug-people@netbsd.org,
    gnats-admin@netbsd.org,
    netbsd-bugs@netbsd.org
Subject: Re: PR/47408 CVS commit: src/sys/netinet6
Date: Sun, 6 Jan 2013 02:16:31 +0100

 On Sunday, at 00:20, Christos Zoulas wrote:
 |  Log Message:
 |  PR/47408: Anthony Mallet: sendto(2) issue with IPv6 UDP datagrams
 |  - don't connect when the local port is 0, just set the local port number.
 |  - remove redundant assignment
 |  XXX: pullup-6

 Nice & quick, this makes dhcp6s work :). Thanks!

From: christos@zoulas.com (Christos Zoulas)
To: Anthony Mallet <anthony.mallet@laas.fr>, gnats-bugs@netbsd.org
Cc: kern-bug-people@netbsd.org, gnats-admin@netbsd.org, 
	netbsd-bugs@netbsd.org
Subject: Re: PR/47408 CVS commit: src/sys/netinet6
Date: Sat, 5 Jan 2013 20:21:02 -0500

 On Jan 6,  2:16am, anthony.mallet@laas.fr (Anthony Mallet) wrote:
 -- Subject: Re: PR/47408 CVS commit: src/sys/netinet6

 | Nice & quick, this makes dhcp6s work :). Thanks!

 Your test made it simple :-)

 christos

From: "Jeff Rizzo" <riz@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/47408 CVS commit: [netbsd-6] src/sys/netinet6
Date: Sun, 31 Mar 2013 20:20:08 +0000

 Module Name:	src
 Committed By:	riz
 Date:		Sun Mar 31 20:20:08 UTC 2013

 Modified Files:
 	src/sys/netinet6 [netbsd-6]: udp6_output.c

 Log Message:
 Pull up following revision(s) (requested by christos in ticket #853):
 	sys/netinet6/udp6_output.c: revision 1.44
 PR/47408: Anthony Mallet: sendto(2) issue with IPv6 UDP datagrams
 - don't connect when the local port is 0, just set the local port number.
 - remove redundant assignment
 XXX: pullup-6


 To generate a diff of this commit:
 cvs rdiff -u -r1.43 -r1.43.8.1 src/sys/netinet6/udp6_output.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Jeff Rizzo" <riz@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/47408 CVS commit: [netbsd-6-0] src/sys/netinet6
Date: Sun, 31 Mar 2013 20:20:31 +0000

 Module Name:	src
 Committed By:	riz
 Date:		Sun Mar 31 20:20:31 UTC 2013

 Modified Files:
 	src/sys/netinet6 [netbsd-6-0]: udp6_output.c

 Log Message:
 Pull up following revision(s) (requested by christos in ticket #853):
 	sys/netinet6/udp6_output.c: revision 1.44
 PR/47408: Anthony Mallet: sendto(2) issue with IPv6 UDP datagrams
 - don't connect when the local port is 0, just set the local port number.
 - remove redundant assignment
 XXX: pullup-6


 To generate a diff of this commit:
 cvs rdiff -u -r1.43 -r1.43.14.1 src/sys/netinet6/udp6_output.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Mon, 07 Oct 2013 06:59:09 +0000
State-Changed-Why:
Fixed and pulled up.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(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-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.