Date: Fri, 21 Dec 2012 04:11:48 -0800 From: Garrett Cooper <yanegomi@gmail.com> To: Kevin Lo <kevlo@freebsd.org> Cc: src-committers@freebsd.org, freebsd-net@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org, Rick Macklem <rmacklem@uoguelph.ca> Subject: Broken error handling with AF_* and socket(2) [was Re: svn commit: r243965 - in head/sys: kern sys] Message-ID: <CAGH67wQhapDDqGjKGgdBwNR7GsJBwTk7Fh7tCuCV4zh7B-Yduw@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
[-- Attachment #1 --] On Thu, Dec 6, 2012 at 6:22 PM, Kevin Lo <kevlo@freebsd.org> wrote: > Author: kevlo > Date: Fri Dec 7 02:22:48 2012 > New Revision: 243965 > URL: http://svnweb.freebsd.org/changeset/base/243965 > > Log: > - according to POSIX, make socket(2) return EAFNOSUPPORT rather than > EPROTONOSUPPORT if the address family is not supported. > - introduce pffinddomain() to find a domain by family and use it as > appropriate. > > Reviewed by: glebius This commit broke netgraph (and potentially more things). I fixed netgraph locally like so: $ git diff lib/libnetgraph/ diff --git a/lib/libnetgraph/sock.c b/lib/libnetgraph/sock.c index fca3900..5f9f563 100644 --- a/lib/libnetgraph/sock.c +++ b/lib/libnetgraph/sock.c @@ -71,10 +71,10 @@ NgMkSockNode(const char *name, int *csp, int *dsp) name = NULL; /* Create control socket; this also creates the netgraph node. - If we get an EPROTONOSUPPORT then the socket node type is + If we get an EAFNOSUPPORT then the socket node type is not loaded, so load it and try again. */ if ((cs = socket(AF_NETGRAPH, SOCK_DGRAM, NG_CONTROL)) < 0) { - if (errno == EPROTONOSUPPORT) { + if (errno == EAFNOSUPPORT) { if (kldload(NG_SOCKET_KLD) < 0) { errnosv = errno; if (_gNgDebugLevel >= 1) Reproing the issue was trivial using the ether.bridge example script setup with appropriate interfaces. I have the patch with the netgraph fix attached, along with other potential fixes that needs to be more properly tested. Thanks, -Garrett [-- Attachment #2 --] From cc6f74b2b219d283f345eb3196694145c33a385e Mon Sep 17 00:00:00 2001 From: Garrett Cooper <yanegomi@gmail.com> Date: Fri, 21 Dec 2012 04:10:07 -0800 Subject: [PATCH] Fix socket calls on error post-r243965 Signed-off-by: Garrett Cooper <yanegomi@gmail.com> --- bin/date/netdate.c | 2 +- lib/libnetgraph/sock.c | 4 ++-- sbin/hastd/parse.y | 2 +- sbin/ifconfig/af_nd6.c | 2 +- sbin/ifconfig/ifconfig.c | 2 +- usr.sbin/mtest/mtest.c | 4 ++-- usr.sbin/nfsd/nfsd.c | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/bin/date/netdate.c b/bin/date/netdate.c index b085be4..e506e6d 100644 --- a/bin/date/netdate.c +++ b/bin/date/netdate.c @@ -85,7 +85,7 @@ netsettime(time_t tval) dest.sin_addr.s_addr = htonl((u_long)INADDR_ANY); s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) { - if (errno != EPROTONOSUPPORT) + if (errno != EAFNOSUPPORT) warn("timed"); return (retval = 2); } diff --git a/lib/libnetgraph/sock.c b/lib/libnetgraph/sock.c index fca3900..5f9f563 100644 --- a/lib/libnetgraph/sock.c +++ b/lib/libnetgraph/sock.c @@ -71,10 +71,10 @@ NgMkSockNode(const char *name, int *csp, int *dsp) name = NULL; /* Create control socket; this also creates the netgraph node. - If we get an EPROTONOSUPPORT then the socket node type is + If we get an EAFNOSUPPORT then the socket node type is not loaded, so load it and try again. */ if ((cs = socket(AF_NETGRAPH, SOCK_DGRAM, NG_CONTROL)) < 0) { - if (errno == EPROTONOSUPPORT) { + if (errno == EAFNOSUPPORT) { if (kldload(NG_SOCKET_KLD) < 0) { errnosv = errno; if (_gNgDebugLevel >= 1) diff --git a/sbin/hastd/parse.y b/sbin/hastd/parse.y index a20b61a..04ea7ab 100644 --- a/sbin/hastd/parse.y +++ b/sbin/hastd/parse.y @@ -769,7 +769,7 @@ family_supported(int family) int sock; sock = socket(family, SOCK_STREAM, 0); - if (sock == -1 && errno == EPROTONOSUPPORT) + if (sock == -1 && errno == EAFNOSUPPORT) return (false); if (sock >= 0) (void)close(sock); diff --git a/sbin/ifconfig/af_nd6.c b/sbin/ifconfig/af_nd6.c index 654e2d9..80065f6 100644 --- a/sbin/ifconfig/af_nd6.c +++ b/sbin/ifconfig/af_nd6.c @@ -148,7 +148,7 @@ nd6_status(int s) memset(&nd, 0, sizeof(nd)); strncpy(nd.ifname, ifr.ifr_name, sizeof(nd.ifname)); if ((s6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { - if (errno != EPROTONOSUPPORT) + if (errno != EAFNOSUPPORT) warn("socket(AF_INET6, SOCK_DGRAM)"); return; } diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 870acdd..983e21f 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -520,7 +520,7 @@ top: AF_LOCAL : afp->af_af; if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0 && - (uafp != NULL || errno != EPROTONOSUPPORT || + (uafp != NULL || errno != EAFNOSUPPORT || (s = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0)) err(1, "socket(family %u,SOCK_DGRAM", ifr.ifr_addr.sa_family); diff --git a/usr.sbin/mtest/mtest.c b/usr.sbin/mtest/mtest.c index 60f7e09..a28fab7 100644 --- a/usr.sbin/mtest/mtest.c +++ b/usr.sbin/mtest/mtest.c @@ -204,12 +204,12 @@ main(int argc, char **argv) s6 = -1; #ifdef INET s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (s == -1 && errno != EPROTONOSUPPORT) + if (s == -1 && errno != EAFNOSUPPORT) err(1, "can't open IPv4 socket"); #endif #ifdef INET6 s6 = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); - if (s6 == -1 && errno != EPROTONOSUPPORT) + if (s6 == -1 && errno != EAFNOSUPPORT) err(1, "can't open IPv6 socket"); #endif if (s == -1 && s6 == -1) diff --git a/usr.sbin/nfsd/nfsd.c b/usr.sbin/nfsd/nfsd.c index 6a2f785..2fef7f5 100644 --- a/usr.sbin/nfsd/nfsd.c +++ b/usr.sbin/nfsd/nfsd.c @@ -264,7 +264,7 @@ main(int argc, char **argv) ip6flag = 1; s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); if (s == -1) { - if (errno != EPROTONOSUPPORT) + if (errno != EAFNOSUPPORT) err(1, "socket"); ip6flag = 0; } else if (getnetconfigent("udp6") == NULL || -- 1.8.0
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAGH67wQhapDDqGjKGgdBwNR7GsJBwTk7Fh7tCuCV4zh7B-Yduw>
