pbr[1.2.3]: refactor iface-priority to bring it in line with 1.2.2#91
pbr[1.2.3]: refactor iface-priority to bring it in line with 1.2.2#91stangri merged 1 commit intomossdef-org:1.2.3from
Conversation
Apparently a commit from 1.2.2 to make sure sport rule and prefix_length rule are first (lowest priority) was not carried over. This PR should correct that Signed-off-by: Erik Conijn <egc112@msn.com>
There was a problem hiding this comment.
Pull request overview
This PR adjusts how ip rule priorities are assigned for global (interface-independent) rules in pbr[1.2.3], aiming to match the behavior from 1.2.2 where WireGuard sport and suppress_prefixlength rules should be evaluated before other PBR rules.
Changes:
- Introduces a
priocursor initialized fromiface_prioritywhen creating global rules. - Decrements
prioas WireGuard serversportrules are added to avoid sharing the same priority. - Uses the resulting
priofor thesuppress_prefixlengthrule and updatesiface_priorityaccordingly.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -1017,29 +1018,29 @@ function create_pbr(fs_mod, uci_mod, ubus_mod) { | |||
| if (disabled != '1' && listen_port) { | |||
| if (cfg.uplink_interface4) { | |||
| let tbl = pkg.ip_table_prefix + '_' + cfg.uplink_interface4; | |||
| let prio = '' + iface_priority; | |||
| system(pkg.ip_full + ' -4 rule del sport ' + listen_port + ' table ' + tbl + ' priority ' + prio + ' 2>/dev/null'); | |||
| sh.ip('-4', 'rule', 'add', 'sport', listen_port, 'table', tbl, 'priority', prio); | |||
| if (cfg.ipv6_enabled) { | |||
| system(pkg.ip_full + ' -6 rule del sport ' + listen_port + ' table ' + tbl + ' priority ' + prio + ' 2>/dev/null'); | |||
| sh.ip('-6', 'rule', 'add', 'sport', listen_port, 'table', tbl, 'priority', prio); | |||
| } | |||
| prio = '' + (+prio - 1); | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| let spl_prio = '' + (int(cfg.uplink_ip_rules_priority) + 1); | |||
| system(pkg.ip_full + ' -4 rule del priority ' + spl_prio + ' 2>/dev/null'); | |||
| system(pkg.ip_full + ' -4 rule del priority ' + prio + ' 2>/dev/null'); | |||
| system(pkg.ip_full + ' -4 rule del lookup main suppress_prefixlength ' + cfg.prefixlength + ' 2>/dev/null'); | |||
| sh.try_cmd(state.errors, pkg.ip_full, '-4', 'rule', 'add', 'lookup', 'main', 'suppress_prefixlength', | |||
| '' + cfg.prefixlength, 'pref', spl_prio); | |||
| '' + cfg.prefixlength, 'pref', prio); | |||
| if (cfg.ipv6_enabled) { | |||
| system(pkg.ip_full + ' -6 rule del priority ' + spl_prio + ' 2>/dev/null'); | |||
| system(pkg.ip_full + ' -6 rule del priority ' + prio + ' 2>/dev/null'); | |||
| system(pkg.ip_full + ' -6 rule del lookup main suppress_prefixlength ' + cfg.prefixlength + ' 2>/dev/null'); | |||
There was a problem hiding this comment.
I have tested it and all rules are cleared because ther is just one suppress_prefixlength rule.
There could be more then one WireGuard servers ,I have tested with two and that also works.
So keep it as is
| system(pkg.ip_full + ' -4 rule del sport ' + listen_port + ' table ' + tbl + ' priority ' + prio + ' 2>/dev/null'); | ||
| sh.ip('-4', 'rule', 'add', 'sport', listen_port, 'table', tbl, 'priority', prio); | ||
| if (cfg.ipv6_enabled) { | ||
| system(pkg.ip_full + ' -6 rule del sport ' + listen_port + ' table ' + tbl + ' priority ' + prio + ' 2>/dev/null'); |
There was a problem hiding this comment.
There could be other suppress prefix length rules and we do not want to delete those.
But thinking about it I think the whole rule is probably redundant anyway but I will check that later for now just keep it as is
|
thanks Erik! |
Apparently a commit from 1.2.2 to make sure sport rule and prefix_length rule are first (lowest priority) was not carried over.
This PR should correct that