ferm icon indicating copy to clipboard operation
ferm copied to clipboard

Allow specifying mod set multiple times

Open markkrj opened this issue 3 years ago • 2 comments

Fixes #84

ipset matching module doesn't allow specifying multiple --match-set for a single -m set, so, we'll keep every mod set specified in the config.

@MaxKellermann feel free to edit this PR directly or close it if you have a better idea, as I'm not a programmer.

markkrj avatar Jul 26 '22 15:07 markkrj

I'm testing a script that runs before ferm and output rules that are later included by ferm, and after I opened this PR, I noticed that more modules (in this case, -m comment --comment) does not accept the same parameter multiple times for a single match instance. So I wonder, why did you put this restriction in the first place @MaxKellermann? I know that this is an old project, so maybe you don't remember 😅, but if it was just for sake of cleaner iptables output, it might be worth removing this restriction altogether and just keep what was input by the user...

So if user input:

mod set match-set valid-sources src mod set ! match-set invalid-dests MASQUERADE;

it would correctly render:

-A POSTROUTING --match set --match-set valid-sources src --match set ! --match-set invalid-dests dst --jump MASQUERADE

instead of current behavior:

-A POSTROUTING --match set --match-set valid-sources src ! --match-set invalid-dests dst --jump MASQUERADE

Currently, I patched ferm like this PR (but now included the comment module in the regex), but if there was no downside, I'd prefer removing it altogether...

markkrj avatar Jul 27 '22 14:07 markkrj

I think this might need a more evolved patch, as I just tested this:

comment this comment is comment a comment test NOP;

and ferm outputs: -A INPUT --match comment --comment this --comment is --comment a --comment test

which iptables complains:

iptables -A POSTROUTING --match comment --comment this --comment is --comment a --comment test
iptables v1.8.4 (legacy): comment: option "--comment" can only be used once.

Try `iptables -h' or 'iptables --help' for more information.

markkrj avatar Jul 27 '22 14:07 markkrj