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
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;
 }

Attachment: pgpCnMydnPFSv.pgp
Description: PGP signature

Reply via email to