From owner-freebsd-current@FreeBSD.ORG Wed Sep 21 04:41:29 2011 Return-Path: Delivered-To: current@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5F5AB1065673 for ; Wed, 21 Sep 2011 04:41:29 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from mail.allbsd.org (gatekeeper-int.allbsd.org [IPv6:2001:2f0:104:e002::2]) by mx1.freebsd.org (Postfix) with ESMTP id 4B6068FC12 for ; Wed, 21 Sep 2011 04:41:27 +0000 (UTC) Received: from alph.allbsd.org ([IPv6:2001:2f0:104:e010:862b:2bff:febc:8956]) (authenticated bits=128) by mail.allbsd.org (8.14.4/8.14.4) with ESMTP id p8L4fEvS058527 for ; Wed, 21 Sep 2011 13:41:24 +0900 (JST) (envelope-from hrs@FreeBSD.org) Received: from localhost (localhost [IPv6:::1]) (authenticated bits=0) by alph.allbsd.org (8.14.4/8.14.4) with ESMTP id p8L4fCJV039539 for ; Wed, 21 Sep 2011 13:41:13 +0900 (JST) (envelope-from hrs@FreeBSD.org) Date: Wed, 21 Sep 2011 13:38:28 +0900 (JST) Message-Id: <20110921.133828.1346903263789064527.hrs@allbsd.org> To: current@FreeBSD.org From: Hiroki Sato X-PGPkey-fingerprint: BDB3 443F A5DD B3D0 A530 FFD7 4F2C D3D8 2793 CF2D X-Mailer: Mew version 6.3.51 on Emacs 23.3 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Multipart/Signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="--Security_Multipart0(Wed_Sep_21_13_38_28_2011_901)--" Content-Transfer-Encoding: 7bit X-Virus-Scanned: clamav-milter 0.97 at gatekeeper.allbsd.org X-Virus-Status: Clean X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.3 (mail.allbsd.org [IPv6:2001:2f0:104:e001::32]); Wed, 21 Sep 2011 13:41:25 +0900 (JST) X-Spam-Status: No, score=-104.6 required=13.0 tests=BAYES_00, CONTENT_TYPE_PRESENT, RDNS_NONE, SPF_SOFTFAIL, USER_IN_WHITELIST autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on gatekeeper.allbsd.org Cc: Subject: RFC: /etc/pccard_ether triggered by usbus X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Sep 2011 04:41:29 -0000 ----Security_Multipart0(Wed_Sep_21_13_38_28_2011_901)-- Content-Type: Multipart/Mixed; boundary="--Next_Part(Wed_Sep_21_13_38_28_2011_390)--" Content-Transfer-Encoding: 7bit ----Next_Part(Wed_Sep_21_13_38_28_2011_390)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi, I would like your comments about adding NOT operator into string match rule in devd.conf. The reason is as follows. After the USB packet filter was added, devctl attach notifications from an IFT_USB interface like "!system=IFNET subsystem=usbus0 type=ATTACH" trigger a default rule for interface initialization in devd.conf. Although it is harmless in most cases, it would be great if we can filter out the notifications because it can result in a slower booting. However, the devd supports no NOT operator in a string match. The attached patch is to add the "!" operator into the match sub-statement. For example, match "bus" "pccard[0-9]+" matches the content of bus against a regex pccard[0-9]+. The "!" operator like the following match "bus" "!pccard[0-9]+" inverts the logic. I am still not sure if this is the best approach but I could not find another way. Filtering out it in if_attach() or adding a new variable like "configurable=yes" in the notification looks overkill to me. Any comments/suggestions? -- Hiroki ----Next_Part(Wed_Sep_21_13_38_28_2011_390)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="devd.cc.20110921-1.diff" Index: etc/devd.conf =================================================================== --- etc/devd.conf (revision 225668) +++ etc/devd.conf (working copy) @@ -38,6 +38,7 @@ # notify 0 { match "system" "IFNET"; + match "subsystem" "!usbus[0-9]+"; match "type" "ATTACH"; action "/etc/pccard_ether $subsystem start"; }; Index: sbin/devd/devd.hh =================================================================== --- sbin/devd/devd.hh (revision 225668) +++ sbin/devd/devd.hh (working copy) @@ -92,6 +92,7 @@ private: std::string _var; std::string _re; + bool _inv; regex_t _regex; }; Index: sbin/devd/devd.cc =================================================================== --- sbin/devd/devd.cc (revision 225668) +++ sbin/devd/devd.cc (working copy) @@ -251,7 +251,14 @@ : _var(var) { _re = "^"; - _re.append(c.expand_string(string(re))); + if (!c.expand_string(string(re)).empty() && + c.expand_string(string(re)).at(0) == '!') { + _re.append(c.expand_string(string(re)).substr(1)); + _inv = 1; + } else { + _re.append(c.expand_string(string(re))); + _inv = 0; + } _re.append("$"); regcomp(&_regex, _re.c_str(), REG_EXTENDED | REG_NOSUB | REG_ICASE); } @@ -268,10 +275,13 @@ bool retval; if (Dflag) - fprintf(stderr, "Testing %s=%s against %s\n", _var.c_str(), - value.c_str(), _re.c_str()); + fprintf(stderr, "Testing %s=%s against %s, invert=%d\n", + _var.c_str(), value.c_str(), _re.c_str(), _inv); retval = (regexec(&_regex, value.c_str(), 0, NULL, 0) == 0); + if (_inv == 1) + retval = (retval == 0) ? 1 : 0; + return retval; } ----Next_Part(Wed_Sep_21_13_38_28_2011_390)---- ----Security_Multipart0(Wed_Sep_21_13_38_28_2011_901)-- Content-Type: application/pgp-signature Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (FreeBSD) iEYEABECAAYFAk55akQACgkQTyzT2CeTzy0pcACfRFxTb9mcajHA8alf8CK4xl1e DkMAoJUlHb2HIv8jvX8+R8/SPFbz6zlx =wldQ -----END PGP SIGNATURE----- ----Security_Multipart0(Wed_Sep_21_13_38_28_2011_901)----