Re: p5-IO-Socket-INET6 fix raw sockets

2013-03-30 Thread Alexander Bluhm
On Sat, Mar 30, 2013 at 06:30:52PM +0100, Eric Faurot wrote:
> On Sat, Mar 30, 2013 at 04:39:47PM +0100, Alexander Bluhm wrote:
> > On Sat, Mar 30, 2013 at 02:30:55PM +, Stuart Henderson wrote:
> 
> > > Most other OS are going to be using something closer to the libbind
> > > (ISC) resolver which allows this so I think it would make more sense to
> > > adjust getaddrinfo_async_run() to allow '0' for raw sockets, rather
> > > than patch users.
> > 
> > Makes sense.
> > 
> > > Thinking possibly something like this, but untested:
> > 
> > This fixes my problem.
> > 
> 
> This is a simpler diff. get_port() returns 0 if servname is NULL, and
> the last argument is just a boolean.

Works for me.  OK bluhm@

> 
> Eric.
> 
> Index: getaddrinfo_async.c
> ===
> RCS file: /cvs/src/lib/libc/asr/getaddrinfo_async.c,v
> retrieving revision 1.12
> diff -u -r1.12 getaddrinfo_async.c
> --- getaddrinfo_async.c   28 Mar 2013 11:47:23 -  1.12
> +++ getaddrinfo_async.c   30 Mar 2013 17:23:07 -
> @@ -170,7 +170,7 @@
>   }
>  
>   if (ai->ai_socktype == SOCK_RAW &&
> - as->as.ai.servname != NULL) {
> + get_port(as->as.ai.servname, NULL, 1) != 0) {
>   ar->ar_gai_errno = EAI_SERVICE;
>   async_set_state(as, ASR_STATE_HALT);
>   break;



Re: p5-IO-Socket-INET6 fix raw sockets

2013-03-30 Thread Eric Faurot
On Sat, Mar 30, 2013 at 04:39:47PM +0100, Alexander Bluhm wrote:
> On Sat, Mar 30, 2013 at 02:30:55PM +, Stuart Henderson wrote:

> > Most other OS are going to be using something closer to the libbind
> > (ISC) resolver which allows this so I think it would make more sense to
> > adjust getaddrinfo_async_run() to allow '0' for raw sockets, rather
> > than patch users.
> 
> Makes sense.
> 
> > Thinking possibly something like this, but untested:
> 
> This fixes my problem.
> 

This is a simpler diff. get_port() returns 0 if servname is NULL, and
the last argument is just a boolean.

Eric.

Index: getaddrinfo_async.c
===
RCS file: /cvs/src/lib/libc/asr/getaddrinfo_async.c,v
retrieving revision 1.12
diff -u -r1.12 getaddrinfo_async.c
--- getaddrinfo_async.c 28 Mar 2013 11:47:23 -  1.12
+++ getaddrinfo_async.c 30 Mar 2013 17:23:07 -
@@ -170,7 +170,7 @@
}
 
if (ai->ai_socktype == SOCK_RAW &&
-   as->as.ai.servname != NULL) {
+   get_port(as->as.ai.servname, NULL, 1) != 0) {
ar->ar_gai_errno = EAI_SERVICE;
async_set_state(as, ASR_STATE_HALT);
break;



Re: p5-IO-Socket-INET6 fix raw sockets

2013-03-30 Thread Alexander Bluhm
On Sat, Mar 30, 2013 at 02:30:55PM +, Stuart Henderson wrote:
> On 2013/03/30 14:39, Alexander Bluhm wrote:
> > Hi,
> > 
> > Using IO::Socket::INET6 fails when creating raw sockets.  Our
> > getaddrinfo() seems to behave more strictly.  This is not related
> > to new perl or new resolver.  I was also broken in OpenBSD 5.0.
> >
> > +The OpenBSD getaddrinfo() does not allow any port number for raw
> > +sockets.  Avoid a 'service not supported for ai_socktype' error and
> > +use '' instead of 0 in this case.
> 
> It looks like IO::Socket::INET in base perl would be affected too.

No.  Works for me.

> Most other OS are going to be using something closer to the libbind
> (ISC) resolver which allows this so I think it would make more sense to
> adjust getaddrinfo_async_run() to allow '0' for raw sockets, rather
> than patch users.

Makes sense.

> Thinking possibly something like this, but untested:

This fixes my problem.

> Index: getaddrinfo_async.c
> ===
> RCS file: /cvs/src/lib/libc/asr/getaddrinfo_async.c,v
> retrieving revision 1.12
> diff -u -p -r1.12 getaddrinfo_async.c
> --- getaddrinfo_async.c   28 Mar 2013 11:47:23 -  1.12
> +++ getaddrinfo_async.c   30 Mar 2013 14:28:18 -
> @@ -170,7 +170,9 @@ getaddrinfo_async_run(struct async *as, 
>   }
>  
>   if (ai->ai_socktype == SOCK_RAW &&
> - as->as.ai.servname != NULL) {
> + as->as.ai.servname != NULL &&
> + get_port(as->as.ai.servname, NULL,
> + as->as.ai.hints.ai_flags & AI_NUMERICSERV) != 0) {

Would get_port(as->as.ai.servname, NULL, AI_NUMERICSERV) != 0
be better?  There is no named service with port 0.

>   ar->ar_gai_errno = EAI_SERVICE;
>   async_set_state(as, ASR_STATE_HALT);
>   break;
> 

bluhm



Re: p5-IO-Socket-INET6 fix raw sockets

2013-03-30 Thread Stuart Henderson
On 2013/03/30 14:39, Alexander Bluhm wrote:
> Hi,
> 
> Using IO::Socket::INET6 fails when creating raw sockets.  Our
> getaddrinfo() seems to behave more strictly.  This is not related
> to new perl or new resolver.  I was also broken in OpenBSD 5.0.

It looks like IO::Socket::INET in base perl would be affected too.

Most other OS are going to be using something closer to the libbind
(ISC) resolver which allows this so I think it would make more sense to
adjust getaddrinfo_async_run() to allow '0' for raw sockets, rather
than patch users.

Thinking possibly something like this, but untested:

Index: getaddrinfo_async.c
===
RCS file: /cvs/src/lib/libc/asr/getaddrinfo_async.c,v
retrieving revision 1.12
diff -u -p -r1.12 getaddrinfo_async.c
--- getaddrinfo_async.c 28 Mar 2013 11:47:23 -  1.12
+++ getaddrinfo_async.c 30 Mar 2013 14:28:18 -
@@ -170,7 +170,9 @@ getaddrinfo_async_run(struct async *as, 
}
 
if (ai->ai_socktype == SOCK_RAW &&
-   as->as.ai.servname != NULL) {
+   as->as.ai.servname != NULL &&
+   get_port(as->as.ai.servname, NULL,
+   as->as.ai.hints.ai_flags & AI_NUMERICSERV) != 0) {
ar->ar_gai_errno = EAI_SERVICE;
async_set_state(as, ASR_STATE_HALT);
break;




p5-IO-Socket-INET6 fix raw sockets

2013-03-30 Thread Alexander Bluhm
Hi,

Using IO::Socket::INET6 fails when creating raw sockets.  Our
getaddrinfo() seems to behave more strictly.  This is not related
to new perl or new resolver.  I was also broken in OpenBSD 5.0.

ok?

bluhm

Index: net/p5-IO-Socket-INET6/Makefile
===
RCS file: /data/mirror/openbsd/cvs/ports/net/p5-IO-Socket-INET6/Makefile,v
retrieving revision 1.12
diff -u -p -r1.12 Makefile
--- net/p5-IO-Socket-INET6/Makefile 11 Mar 2013 11:35:50 -  1.12
+++ net/p5-IO-Socket-INET6/Makefile 30 Mar 2013 03:05:52 -
@@ -3,6 +3,7 @@
 COMMENT =  object interface for AF_INET and AF_INET6 domain sockets
 
 DISTNAME = IO-Socket-INET6-2.69
+REVISION = 1
 
 CATEGORIES =   net
 
@@ -14,6 +15,6 @@ PERMIT_PACKAGE_CDROM =Yes
 MODULES =  cpan
 BUILD_DEPENDS =${RUN_DEPENDS}
 RUN_DEPENDS =  net/p5-Socket6>=0.12
-TEST_DEPENDS = devel/p5-Test-Pod-Coverage devel/p5-Test-Pod
+TEST_DEPENDS = devel/p5-Test-Pod-Coverage devel/p5-Test-Pod
 
 .include 
Index: net/p5-IO-Socket-INET6/patches/patch-lib_IO_Socket_INET6_pm
===
RCS file: net/p5-IO-Socket-INET6/patches/patch-lib_IO_Socket_INET6_pm
diff -N net/p5-IO-Socket-INET6/patches/patch-lib_IO_Socket_INET6_pm
--- /dev/null   1 Jan 1970 00:00:00 -
+++ net/p5-IO-Socket-INET6/patches/patch-lib_IO_Socket_INET6_pm 30 Mar 2013 
13:23:14 -
@@ -0,0 +1,32 @@
+$OpenBSD$
+
+The OpenBSD getaddrinfo() does not allow any port number for raw
+sockets.  Avoid a 'service not supported for ai_socktype' error and
+use '' instead of 0 in this case.
+
+--- lib/IO/Socket/INET6.pm.origMon Nov 28 13:57:54 2011
 lib/IO/Socket/INET6.pm Sat Mar 30 04:17:38 2013
+@@ -152,11 +152,11 @@ sub configure {
+ $arg->{LocalPort},
+ $arg->{Proto}
+ ) or return _error($sock, $!, "sock_info: $@");
+-$laddr ||= '';
+-$lport ||= 0;
+ $proto ||= (getprotobyname('tcp'))[2];
++my $type = $arg->{Type} || $socket_type{(getprotobynumber($proto))[0]};
++$laddr ||= '';
++$lport ||= $type == SOCK_RAW ? '' : 0;
+ 
+-
+ # MSWin32 expects at least one of $laddr or $lport to be specified
+ # and does not accept 0 for $lport if $laddr is specified.
+ if ($^O eq 'MSWin32') {
+@@ -167,8 +167,6 @@ sub configure {
+ $lport = '';
+ }
+ } 
+-
+-my $type = $arg->{Type} || $socket_type{(getprotobynumber($proto))[0]};
+ 
+ # parse Peer*
+ my($rport,$raddr);