From owner-svn-soc-all@freebsd.org Mon Jun 13 23:18:07 2016 Return-Path: Delivered-To: svn-soc-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 82BB7AF08A1 for ; Mon, 13 Jun 2016 23:18:07 +0000 (UTC) (envelope-from yuanxunzhang@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4F4F5264C for ; Mon, 13 Jun 2016 23:18:07 +0000 (UTC) (envelope-from yuanxunzhang@FreeBSD.org) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.15.2/8.15.2) with ESMTP id u5DNI7N7001548 for ; Mon, 13 Jun 2016 23:18:07 GMT (envelope-from yuanxunzhang@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u5DNI6Gx001536 for svn-soc-all@FreeBSD.org; Mon, 13 Jun 2016 23:18:06 GMT (envelope-from yuanxunzhang@FreeBSD.org) Date: Mon, 13 Jun 2016 23:18:06 GMT Message-Id: <201606132318.u5DNI6Gx001536@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to yuanxunzhang@FreeBSD.org using -f From: yuanxunzhang@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r305167 - soc2016/yuanxunzhang/head/usr.sbin/eaps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Jun 2016 23:18:07 -0000 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 __FBSDID("$FreeBSD$"); +#include +#include #include #include #include @@ -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");