Broken error handling with AF_* and socket(2) [was Re: svn commit: r243965 - in head/sys: kern sys]

Garrett Cooper yanegomi at gmail.com
Fri Dec 21 12:11:50 UTC 2012


On Thu, Dec 6, 2012 at 6:22 PM, Kevin Lo <kevlo at 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-socket-calls-on-error-post-r243965.patch
Type: application/octet-stream
Size: 4003 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/svn-src-all/attachments/20121221/77c02e9b/attachment.obj>


More information about the svn-src-all mailing list