diff options
-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 d521cfa..99b5ecc 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 8f33658..c30dc1b 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 b8bb9e6..c5a8234 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]; |