Use modfind() to check if a kld is already loaded.
Submitted mostly by: green
This commit is contained in:
parent
fa089ea40a
commit
e6e4bcef43
@ -47,6 +47,7 @@
|
||||
#include <sys/wait.h>
|
||||
#if defined(__FreeBSD__) && !defined(NOKLDLOAD)
|
||||
#include <sys/linker.h>
|
||||
#include <sys/module.h>
|
||||
#endif
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
@ -607,7 +608,7 @@ bundle_Create(const char *prefix, int type, int unit, const char **argv)
|
||||
static struct bundle bundle; /* there can be only one */
|
||||
int enoentcount, err, minunit, maxunit;
|
||||
const char *ifname;
|
||||
#ifdef KLDSYM_LOOKUP
|
||||
#if defined(__FreeBSD__) && !defined(NOKLDLOAD)
|
||||
int kldtried;
|
||||
#endif
|
||||
#if defined(TUNSIFMODE) || defined(TUNSLMODE)
|
||||
@ -628,7 +629,7 @@ bundle_Create(const char *prefix, int type, int unit, const char **argv)
|
||||
}
|
||||
err = ENOENT;
|
||||
enoentcount = 0;
|
||||
#ifdef KLDSYM_LOOKUP
|
||||
#if defined(__FreeBSD__) && !defined(NOKLDLOAD)
|
||||
kldtried = 0;
|
||||
#endif
|
||||
for (bundle.unit = minunit; bundle.unit != maxunit; bundle.unit++) {
|
||||
@ -638,18 +639,13 @@ bundle_Create(const char *prefix, int type, int unit, const char **argv)
|
||||
if (bundle.dev.fd >= 0)
|
||||
break;
|
||||
else if (errno == ENXIO) {
|
||||
#ifdef KLDSYM_LOOKUP
|
||||
#if defined(__FreeBSD__) && !defined(NOKLDLOAD)
|
||||
if (bundle.unit == minunit && !kldtried++) {
|
||||
/*
|
||||
* XXX: For some odd reason, FreeBSD (right now) allows if_tun.ko to
|
||||
* load even when the kernel contains the tun device. This lookup
|
||||
* should go away when this is fixed, leaving just the kldload().
|
||||
* Note also that kldsym() finds static symbols...
|
||||
* Attempt to load the tunnel interface KLD if it isn't loaded
|
||||
* already.
|
||||
*/
|
||||
char devsw[] = "tun_cdevsw";
|
||||
struct kld_sym_lookup ksl = { sizeof ksl, devsw, 0, 0 };
|
||||
|
||||
if (kldsym(0, KLDSYM_LOOKUP, &ksl) == -1) {
|
||||
if (modfind("if_tun") == -1) {
|
||||
if (ID0kldload("if_tun") != -1) {
|
||||
bundle.unit--;
|
||||
continue;
|
||||
|
@ -49,6 +49,7 @@
|
||||
#include <sys/fcntl.h>
|
||||
#if defined(__FreeBSD__) && !defined(NOKLDLOAD)
|
||||
#include <sys/linker.h>
|
||||
#include <sys/module.h>
|
||||
#endif
|
||||
#include <sys/uio.h>
|
||||
#include <termios.h>
|
||||
@ -409,22 +410,15 @@ ether_Create(struct physical *p)
|
||||
int ifacelen, providerlen, oldflag;
|
||||
char connectpath[sizeof dev->hook + 2]; /* .:<hook> */
|
||||
|
||||
#ifdef KLDSYM_LOOKUP
|
||||
/* First make sure we've got the right code loaded */
|
||||
char basesym[] = "ng_make_node", socksym[] = "ngdomain";
|
||||
struct kld_sym_lookup baselookup = { sizeof baselookup, basesym, 0, 0 };
|
||||
struct kld_sym_lookup socklookup = { sizeof socklookup, socksym, 0, 0 };
|
||||
#endif
|
||||
|
||||
p->fd--; /* We own the device - change fd */
|
||||
|
||||
#ifdef KLDSYM_LOOKUP
|
||||
if (kldsym(0, KLDSYM_LOOKUP, &baselookup) == -1) {
|
||||
log_Printf(LogWARN, "Can't run without options NETGRAPH in the kernel\n");
|
||||
#if defined(__FreeBSD__) && !defined(NOKLDLOAD)
|
||||
if (modfind("netgraph") == -1) {
|
||||
log_Printf(LogWARN, "Netgraph is not built into the kernel\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (kldsym(0, KLDSYM_LOOKUP, &socklookup) == -1 &&
|
||||
if (modfind("ng_socket") == -1 &&
|
||||
ID0kldload("ng_socket") == -1) {
|
||||
log_Printf(LogWARN, "kldload: ng_socket: %s\n", strerror(errno));
|
||||
return NULL;
|
||||
|
@ -269,7 +269,7 @@ ID0kill(pid_t pid, int sig)
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef KLDSYM_LOOKUP
|
||||
#if defined(__FreeBSD__) && !defined(NOKLDLOAD)
|
||||
int
|
||||
ID0kldload(const char *dev)
|
||||
{
|
||||
|
@ -45,6 +45,6 @@ extern void ID0logout(const char *, int);
|
||||
extern int ID0bind_un(int, const struct sockaddr_un *);
|
||||
extern int ID0connect_un(int, const struct sockaddr_un *);
|
||||
extern int ID0kill(pid_t, int);
|
||||
#ifdef KLDSYM_LOOKUP
|
||||
#if defined(__FreeBSD__) && !defined(NOKLDLOAD)
|
||||
extern int ID0kldload(const char *);
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user