Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Sep 2011 13:38:28 +0900 (JST)
From:      Hiroki Sato <hrs@FreeBSD.org>
To:        current@FreeBSD.org
Subject:   RFC: /etc/pccard_ether triggered by usbus
Message-ID:  <20110921.133828.1346903263789064527.hrs@allbsd.org>

next in thread | raw e-mail | index | archive | help
----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)----



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110921.133828.1346903263789064527.hrs>