Date: Mon, 13 Jun 2016 23:18:06 GMT From: yuanxunzhang@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r305167 - soc2016/yuanxunzhang/head/usr.sbin/eaps Message-ID: <201606132318.u5DNI6Gx001536@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: yuanxunzhang Date: Mon Jun 13 23:18:06 2016 New Revision: 305167 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305167 Log: EAPS: load the eaps module, when user create eaps instance Modified: soc2016/yuanxunzhang/head/usr.sbin/eaps/eaps.c Modified: soc2016/yuanxunzhang/head/usr.sbin/eaps/eaps.c ============================================================================== --- soc2016/yuanxunzhang/head/usr.sbin/eaps/eaps.c Mon Jun 13 22:31:16 2016 (r305166) +++ soc2016/yuanxunzhang/head/usr.sbin/eaps/eaps.c Mon Jun 13 23:18:06 2016 (r305167) @@ -31,6 +31,8 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); +#include <sys/module.h> +#include <sys/linker.h> #include <net/if.h> #include <sys/param.h> #include <sys/file.h> @@ -54,9 +56,7 @@ * EAPS Command Line Module - configure, and display eaps */ -/* -* EAPS Configuration Descriptor -*/ +static const char eaps_ifname[] = "eaps"; static struct keytab { const char *kt_cp; @@ -71,6 +71,7 @@ static void delete_domain(int, char **); static void display(int, char **); static void usage(const char *); +void load_module(const char *); int main(int argc, char **argv) @@ -98,6 +99,35 @@ return retval; } +void +load_module(const char *module_name) +{ + struct module_stat mstat; + + mstat.version = sizeof(struct module_stat); + + for (fileid = kldnext(0); fileid > 0; fileid = kldnext(fileid)) { + /* scan modules in file */ + for (modid = kldfirstmod(fileid); modid > 0; + modid = modfnext(modid)) { + if (modstat(modid, &mstat) < 0) + continue; + /* strip bus name if present */ + if ((cp = strchr(mstat.name, '/')) != NULL) { + cp++; + } else { + cp = mstat.name; + } + /* already loaded? */ + if (strcmp(module_name, cp) == 0) + return; + } + } + + /* not present, we should try to load it */ + kldload(module_name); +} + static void create_domain(int argc, char **argv, int s) { @@ -107,10 +137,13 @@ printf("Create eaps %s!\n", domain_name); // Create EAPS interface + /* check and maybe load support for this interface */ + load_module(eaps_ifname); + struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); - (void) strlcpy(ifr.ifr_name, "eaps", sizeof(ifr.ifr_name)); + (void) strlcpy(ifr.ifr_name, eaps_ifname, sizeof(ifr.ifr_name)); if (ioctl(s, SIOCIFCREATE2, &ifr) < 0) err(1, "SIOCIFCREATE2");
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201606132318.u5DNI6Gx001536>