Have NgMkSockNode() load the socket node type KLD if it's not
already loaded (indicated by EPROTONOSUPPORT from socket(2)).
This commit is contained in:
parent
1177ed6f29
commit
fbffcf6685
@ -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>
|
||||
|
@ -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
|
||||
|
@ -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];
|
||||
|
Loading…
Reference in New Issue
Block a user