From fdb4bb1b8935b02642bc8394223c0a029a8d29b9 Mon Sep 17 00:00:00 2001 From: Brian Somers Date: Tue, 16 Nov 1999 21:57:34 +0000 Subject: [PATCH] Use modfind() to check if a kld is already loaded. Submitted mostly by: green --- usr.sbin/ppp/bundle.c | 18 +++++++----------- usr.sbin/ppp/ether.c | 16 +++++----------- usr.sbin/ppp/id.c | 2 +- usr.sbin/ppp/id.h | 2 +- 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/usr.sbin/ppp/bundle.c b/usr.sbin/ppp/bundle.c index 7f47e05e3842..dcc07f267603 100644 --- a/usr.sbin/ppp/bundle.c +++ b/usr.sbin/ppp/bundle.c @@ -47,6 +47,7 @@ #include #if defined(__FreeBSD__) && !defined(NOKLDLOAD) #include +#include #endif #include #include @@ -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; diff --git a/usr.sbin/ppp/ether.c b/usr.sbin/ppp/ether.c index da20f9f40832..52ae0835ee52 100644 --- a/usr.sbin/ppp/ether.c +++ b/usr.sbin/ppp/ether.c @@ -49,6 +49,7 @@ #include #if defined(__FreeBSD__) && !defined(NOKLDLOAD) #include +#include #endif #include #include @@ -409,22 +410,15 @@ ether_Create(struct physical *p) int ifacelen, providerlen, oldflag; char connectpath[sizeof dev->hook + 2]; /* .: */ -#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; diff --git a/usr.sbin/ppp/id.c b/usr.sbin/ppp/id.c index 3ca74c63bf03..06aad0294177 100644 --- a/usr.sbin/ppp/id.c +++ b/usr.sbin/ppp/id.c @@ -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) { diff --git a/usr.sbin/ppp/id.h b/usr.sbin/ppp/id.h index bba273f209cb..3254f6437580 100644 --- a/usr.sbin/ppp/id.h +++ b/usr.sbin/ppp/id.h @@ -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