From 9c34ecf434669478f11206504318df2363cf8e2e Mon Sep 17 00:00:00 2001 From: Matteo Di Lorenzi Date: Thu, 26 Feb 2026 14:23:44 +0100 Subject: [PATCH 1/2] fix(ns.qos): invert bandwidth for non-WAN interfaces in QoS settings --- packages/ns-api/files/ns.qos | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/ns-api/files/ns.qos b/packages/ns-api/files/ns.qos index bbcb85aab..20541956a 100755 --- a/packages/ns-api/files/ns.qos +++ b/packages/ns-api/files/ns.qos @@ -14,6 +14,16 @@ from nethsec import utils from nethsec.utils import ValidationError +def is_wan_interface(e_uci, interface_name): + """Check if an interface is a WAN interface""" + try: + wan_interfaces = e_uci.get('firewall', 'ns_wan', 'network', dtype=str, default=[], list=True) + return interface_name in wan_interfaces + except: + # assume WAN to avoid inverting bandwidth for unknown interfaces + return True + + def validate(data): if 'interface' not in data: raise ValidationError('name', 'required') @@ -69,12 +79,17 @@ elif cmd == 'call': device = [item['device'] for config_name, item in network_interfaces if config_name == key][0] except: continue + upload = int(interface['bandwidth_up'].removesuffix('mbit')) + download = int(interface['bandwidth_down'].removesuffix('mbit')) + # invert if not WAN interface + if not is_wan_interface(e_uci, key): + upload, download = download, upload result.append({ 'interface': key, 'device': device, 'disabled': interface['disabled'] == '1', - 'upload': int(interface['bandwidth_up'].removesuffix('mbit')), - 'download': int(interface['bandwidth_down'].removesuffix('mbit')), + 'upload': upload, + 'download': download, }) print(json.dumps({'rules': result})) @@ -86,6 +101,10 @@ elif cmd == 'call': if data['interface'] not in utils.get_all_by_type(e_uci, 'network', 'interface').keys(): raise ValidationError('name', 'invalid') + # invert bandwidth for non-WAN interfaces before saving + if not is_wan_interface(e_uci, data['interface']): + data['upload'], data['download'] = data['download'], data['upload'] + e_uci.set('qosify', data['interface'], 'interface') e_uci.set('qosify', data['interface'], 'name', data['interface']) e_uci.set('qosify', data['interface'], 'disabled', data['disabled']) @@ -129,6 +148,10 @@ elif cmd == 'call': if data['interface'] not in utils.get_all_by_type(e_uci, 'qosify', 'interface').keys(): raise ValidationError('name', 'invalid') + # invert bandwidth for non-WAN interfaces before saving + if not is_wan_interface(e_uci, data['interface']): + data['upload'], data['download'] = data['download'], data['upload'] + e_uci.set('qosify', data['interface'], 'disabled', data['disabled']) e_uci.set('qosify', data['interface'], 'bandwidth_up', f'{data["upload"]}mbit') e_uci.set('qosify', data['interface'], 'bandwidth_down', f'{data["download"]}mbit') From 043bc73b6eba2c8c36c5f7c240b5b5ee8b10a1a0 Mon Sep 17 00:00:00 2001 From: Matteo Di Lorenzi Date: Thu, 26 Feb 2026 15:41:42 +0100 Subject: [PATCH 2/2] fix(ns.qos): refactor bandwidth inversion logic for better readability --- packages/ns-api/files/ns.qos | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/ns-api/files/ns.qos b/packages/ns-api/files/ns.qos index 20541956a..95f811d66 100755 --- a/packages/ns-api/files/ns.qos +++ b/packages/ns-api/files/ns.qos @@ -83,7 +83,9 @@ elif cmd == 'call': download = int(interface['bandwidth_down'].removesuffix('mbit')) # invert if not WAN interface if not is_wan_interface(e_uci, key): - upload, download = download, upload + temp = upload + upload = download + download = temp result.append({ 'interface': key, 'device': device, @@ -103,7 +105,9 @@ elif cmd == 'call': # invert bandwidth for non-WAN interfaces before saving if not is_wan_interface(e_uci, data['interface']): - data['upload'], data['download'] = data['download'], data['upload'] + upload = data['upload'] + data['upload'] = data['download'] + data['download'] = upload e_uci.set('qosify', data['interface'], 'interface') e_uci.set('qosify', data['interface'], 'name', data['interface']) @@ -150,7 +154,9 @@ elif cmd == 'call': # invert bandwidth for non-WAN interfaces before saving if not is_wan_interface(e_uci, data['interface']): - data['upload'], data['download'] = data['download'], data['upload'] + upload = data['upload'] + data['upload'] = data['download'] + data['download'] = upload e_uci.set('qosify', data['interface'], 'disabled', data['disabled']) e_uci.set('qosify', data['interface'], 'bandwidth_up', f'{data["upload"]}mbit')