Skip to content

Conversation

@saldry
Copy link

@saldry saldry commented Jan 7, 2026

Translate inverted limits to nft limit rate over which specifies that the rule is matching packets over the rate limit.

@brada4
Copy link

brada4 commented Jan 7, 2026

Why dont you add a single bool parameter that limit is in reverse? Same lines already touched...

@saldry
Copy link
Author

saldry commented Jan 7, 2026

Why dont you add a single bool parameter that limit is in reverse? Same lines already touched...

I didn't realize that approach. I'll try it later...

@saldry saldry marked this pull request as draft January 7, 2026 13:18
Translate inverted limits to nft `limit rate over` which specifies that
the rule is matching packets over the rate limit.

Signed-off-by: Fengyu Wu <saldry@proton.me>
@saldry saldry marked this pull request as ready for review January 7, 2026 13:52
@saldry
Copy link
Author

saldry commented Jan 7, 2026

Updated. Please check :) @brada4

@saldry saldry changed the title fw4: add support for over_limit templates: allow inverted limits Jan 7, 2026
@brada4
Copy link

brada4 commented Jan 7, 2026

You need to load new parameter in root/usr/share/ucode/fw4.uc
Maybe call it limit_over to not invent new nomenclature?

@saldry
Copy link
Author

saldry commented Jan 8, 2026

You need to load new parameter in root/usr/share/ucode/fw4.uc

parse_invert: function(val) {
if (val == null)
return null;
let rv = { invert: false };
rv.val = trim(replace(val, /^[ \t]*!/, () => (rv.invert = true, '')));
return length(rv.val) ? rv : null;
},
parse_limit: function(val) {
let rv = this.parse_invert(val);
let m = rv ? match(rv.val, /^([0-9]+)(\/([a-z]+))?$/) : null;
if (!m)
return null;
let n = +m[1];
let u = m[3] ? this.parse_enum(m[3], [ "second", "minute", "hour", "day" ]) : "second";
if (!u)
return null;
rv.rate = n;
rv.unit = u;
return rv;
},

I'm afraid I don't quite understand what you mean. limit.invert/rv.invert is available since parse_limit and parse_invert. And it works well in my tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants