diff options
author | Archie Cobbs <archie@FreeBSD.org> | 2000-01-28 00:48:27 +0000 |
---|---|---|
committer | Archie Cobbs <archie@FreeBSD.org> | 2000-01-28 00:48:27 +0000 |
commit | fbffcf6685123749e437fcddcb034f2bc1b59ae1 (patch) | |
tree | 60560e9a850530e7a2bd5609facc37aff054c0a4 /lib/libnetgraph | |
parent | 1177ed6f2969024374aa7ebfc0b654fa4d2ee471 (diff) |
Have NgMkSockNode() load the socket node type KLD if it's not
already loaded (indicated by EPROTONOSUPPORT from socket(2)).
Notes
Notes:
svn path=/head/; revision=56708
Diffstat (limited to 'lib/libnetgraph')
-rw-r--r-- | lib/libnetgraph/internal.h | 2 | ||||
-rw-r--r-- | lib/libnetgraph/netgraph.3 | 5 | ||||
-rw-r--r-- | lib/libnetgraph/sock.c | 19 |
3 files changed, 24 insertions, 2 deletions
diff --git a/lib/libnetgraph/internal.h b/lib/libnetgraph/internal.h index d521cfa5039d..99b5eccac427 100644 --- a/lib/libnetgraph/internal.h +++ b/lib/libnetgraph/internal.h @@ -41,9 +41,11 @@ */ #include <sys/types.h> +#include <sys/param.h> #include <sys/time.h> #include <sys/socket.h> #include <sys/select.h> +#include <sys/linker.h> #include <stdlib.h> #include <stdio.h> diff --git a/lib/libnetgraph/netgraph.3 b/lib/libnetgraph/netgraph.3 index 8f336583a14a..c30dc1bdb48e 100644 --- a/lib/libnetgraph/netgraph.3 +++ b/lib/libnetgraph/netgraph.3 @@ -95,6 +95,8 @@ associated with the node; either or .Fa "dsp" may be NULL if only one socket is desired. +.Fn NgMkSockNode +loads the socket node type KLD if it's not already loaded. .Pp .Fn NgNameNode assigns a global name to the node addressed by @@ -273,10 +275,11 @@ ASCII control message array or fixed width string buffer overflow. .El .Sh SEE ALSO .Xr netgraph 4 , +.Xr kld 4 , .Xr socket 2 , .Xr select 2 , .Xr warnx 3 , -.Xr ng_socket 8 . +.Xr ng_socket 8 .Sh HISTORY The .Nm netgraph diff --git a/lib/libnetgraph/sock.c b/lib/libnetgraph/sock.c index b8bb9e65a364..c5a82341162a 100644 --- a/lib/libnetgraph/sock.c +++ b/lib/libnetgraph/sock.c @@ -48,6 +48,9 @@ #include "netgraph.h" #include "internal.h" +/* The socket node type KLD */ +#define NG_SOCKET_KLD "ng_socket.ko" + /* * Create a socket type node and give it the supplied name. * Return data and control sockets corresponding to the node. @@ -65,14 +68,28 @@ NgMkSockNode(const char *name, int *csp, int *dsp) if (name && *name == 0) name = NULL; - /* Create control socket; this also creates the netgraph node */ + /* Create control socket; this also creates the netgraph node. + If we get a EPROTONOSUPPORT 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 (kldload(NG_SOCKET_KLD) < 0) { + errnosv = errno; + if (_gNgDebugLevel >= 1) + NGLOG("can't load %s", NG_SOCKET_KLD); + goto errout; + } + cs = socket(AF_NETGRAPH, SOCK_DGRAM, NG_CONTROL); + if (cs >= 0) + goto gotNode; + } errnosv = errno; if (_gNgDebugLevel >= 1) NGLOG("socket"); goto errout; } +gotNode: /* Assign the node the desired name, if any */ if (name != NULL) { u_char sbuf[NG_NODELEN + 3]; |