Skip to contentSkip to conversation

doc: nft.8: Mention wildcard interface matching

PATCH Superseded Phil Sutter 2 participants 6 messages Feb 6, 2020 – Feb 10, 2020 netfilter

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/2 doc: nft.8: Mention wildcard interface matching

Special meaning of asterisk in interface names wasn't described anywhere.

---
 doc/primary-expression.txt | 7 +++++++
 1 file changed, 7 insertions(+)
doc/primary-expression.txt +7 -0
index 94eccc20241a2..b15df015e5484 100644
@@ -36,6 +36,13 @@ add such a rule, it will stop matching if the interface gets renamed and it
 will match again in case interface gets deleted and later a new interface
 with the same name is created.
 
+Like with iptables, wildcard matching on interface name prefixes is available for
+*iifname* and *oifname* matches by appending an asterisk (*) character. Note
+however that unlike iptables, nftables does not accept interface names
+consisting of the wildcard character only - users are supposed to just skip
+those always matching expressions. In order to match on literal asterisk
+character at end of interface name, one may escape it using backslash (\).
+
 .Meta expression types
 [options="header"]
 |==================
Signature · 1 line
2.24.1
author reviewer
#1 lore raw

PATCH 2/2 scanner: Extend asteriskstring definition

Accept sole escaped asterisks as well as unescaped asterisks if surrounded by strings. The latter is merely cosmetic, but literal asterisk will help when translating from iptables where asterisk has no special meaning.

---
 src/scanner.l | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/scanner.l +1 -1
index 99ee83559d2eb..da9bacee23eb5 100644
@@ -120,7 +120,7 @@ numberstring	({decstring}|{hexstring})
 letter		[a-zA-Z]
 string		({letter}|[_.])({letter}|{digit}|[/\-_\.])*
 quotedstring	\"[^"]*\"
-asteriskstring	({string}\*|{string}\\\*)
+asteriskstring	({string}\*|{string}\\\*|\\\*|{string}\*{string})
 comment		#.*$
 slash		\/
 
Signature · 1 line
2.24.1
#2 lore raw

Re: [nft PATCH 2/2] scanner: Extend asteriskstring definition

Quoted 15 lines · Phil Sutter

Accept sole escaped asterisks as well as unescaped asterisks if surrounded by strings. The latter is merely cosmetic, but literal asterisk will help when translating from iptables where asterisk has no special meaning.

---
 src/scanner.l | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/scanner.l +0 -0
index 99ee83559d2eb..da9bacee23eb5 100644

src/scanner.l numberstring ({decstring}|{hexstring}) · line 123

Quoted 5 lines
src/scanner.l +1 -1
@@ -120,7 +120,7 @@ numberstring	({decstring}|{hexstring})
 letter		[a-zA-Z]
 string		({letter}|[_.])({letter}|{digit}|[/\-_\.])*
 quotedstring	\"[^"]*\"
-asteriskstring	({string}\*|{string}\\\*)
+asteriskstring	({string}\*|{string}\\\*|\\\*|{string}\*{string})

Probably this:

        {string}\\\*{string})

instead of:

        {string}\*{string})

?

The escaping makes it probably clear that there is no support for infix wildcard matching?

This asteriskstring rule is falling under the string rule in bison. This is allowing to use \\\* for log messages too, and elsewhere.

author reviewer
#3 lore raw

Re: [nft PATCH 2/2] scanner: Extend asteriskstring definition

Hi Pablo,

Quoted 26 lines · Pablo Neira Ayuso
Quoted 15 lines · Phil Sutter

Accept sole escaped asterisks as well as unescaped asterisks if surrounded by strings. The latter is merely cosmetic, but literal asterisk will help when translating from iptables where asterisk has no special meaning.

---
 src/scanner.l | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/scanner.l +0 -0
index 99ee83559d2eb..da9bacee23eb5 100644

src/scanner.l numberstring ({decstring}|{hexstring}) · line 123

Quoted 5 lines
src/scanner.l +1 -1
@@ -120,7 +120,7 @@ numberstring	({decstring}|{hexstring})
 letter		[a-zA-Z]
 string		({letter}|[_.])({letter}|{digit}|[/\-_\.])*
 quotedstring	\"[^"]*\"
-asteriskstring	({string}\*|{string}\\\*)
+asteriskstring	({string}\*|{string}\\\*|\\\*|{string}\*{string})

Probably this:

        {string}\\\*{string})
Quoted 8 lines

instead of:

        {string}\*{string})

?

The escaping makes it probably clear that there is no support for infix wildcard matching?

Ah, you're right. I assumed it wasn't necessary to escape the asterisk mid-string, but if we ever added support for infix wildcards (no matter how unlikely) we were in real trouble.

BTW: Given how confusing bison-generated error messages are, maybe I should introduce "infixasteriskstring" in scanner.l to catch unescaped infix asterisks and generate a readable error message from there?

Quoted 2 lines

This asteriskstring rule is falling under the string rule in bison. This is allowing to use \\\* for log messages too, and elsewhere.

Ah, that's right. Good, bad, ugly? Just a "neutral remark" from you? :)

Thanks, Phil

#4 lore raw

Re: [nft PATCH 2/2] scanner: Extend asteriskstring definition

Quoted 33 lines · Phil Sutter

Hi Pablo,

Quoted 30 lines · Pablo Neira Ayuso
Quoted 15 lines · Phil Sutter

Accept sole escaped asterisks as well as unescaped asterisks if surrounded by strings. The latter is merely cosmetic, but literal asterisk will help when translating from iptables where asterisk has no special meaning.

---
 src/scanner.l | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/scanner.l +0 -0
index 99ee83559d2eb..da9bacee23eb5 100644

src/scanner.l numberstring ({decstring}|{hexstring}) · line 123

Quoted 5 lines
src/scanner.l +1 -1
@@ -120,7 +120,7 @@ numberstring	({decstring}|{hexstring})
 letter		[a-zA-Z]
 string		({letter}|[_.])({letter}|{digit}|[/\-_\.])*
 quotedstring	\"[^"]*\"
-asteriskstring	({string}\*|{string}\\\*)
+asteriskstring	({string}\*|{string}\\\*|\\\*|{string}\*{string})

Probably this:

        {string}\\\*{string})

instead of:

        {string}\*{string})
Quoted 8 lines
Quoted 4 lines

?

The escaping makes it probably clear that there is no support for infix wildcard matching?

Ah, you're right. I assumed it wasn't necessary to escape the asterisk mid-string, but if we ever added support for infix wildcards (no matter how unlikely) we were in real trouble.

Yes, I don't expect mid-string matching in the future, but you never know, so better reserve this just in case :-)

Quoted 3 lines

BTW: Given how confusing bison-generated error messages are, maybe I should introduce "infixasteriskstring" in scanner.l to catch unescaped infix asterisks and generate a readable error message from there?

bison syntax error reporting is not great, yes. If you think that makes it easier for error reporting as a short term way to address the issue, that's fine with me.

Quoted 4 lines
Quoted 2 lines

This asteriskstring rule is falling under the string rule in bison. This is allowing to use \\\* for log messages too, and elsewhere.

Ah, that's right. Good, bad, ugly? Just a "neutral remark" from you? :)

Just a remark, no issue.

author reviewer
#5 lore raw

Re: [nft PATCH 2/2] scanner: Extend asteriskstring definition

Hi Pablo,

On Sun, Feb 09, 2020 at 11:21:43PM +0100, Pablo Neira Ayuso wrote:
[...]

Quoted 2 lines

Yes, I don't expect mid-string matching in the future, but you never know, so better reserve this just in case :-)

DONE, please see v2 I just sent.

Quoted 7 lines
Quoted 3 lines

BTW: Given how confusing bison-generated error messages are, maybe I should introduce "infixasteriskstring" in scanner.l to catch unescaped infix asterisks and generate a readable error message from there?

bison syntax error reporting is not great, yes. If you think that makes it easier for error reporting as a short term way to address the issue, that's fine with me.

Tried, but didn't go well - proper error reporting is best put into parser_bison, but there one can't complain about mid-string asterisk "anywhere" but only in defined places. So in others the then known token will make error messages even more confusing.

Cheers, Phil