From 8b596af3db0baa3df58aadaa8fe86b070b770989 Mon Sep 17 00:00:00 2001 From: Herbert Wolverson Date: Fri, 14 Nov 2025 14:48:10 -0600 Subject: [PATCH] WIP: Issue with overlapping minor numbers not being properly in the free list. Includes test against it. --- src/LibreQoS.py | 38 +++++++++++++++++----- src/bakery_integration_test.py | 58 ++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 8 deletions(-) diff --git a/src/LibreQoS.py b/src/LibreQoS.py index 726abcd9..f3a67333 100755 --- a/src/LibreQoS.py +++ b/src/LibreQoS.py @@ -1480,14 +1480,17 @@ def refreshShapers(): 'insertion_order': int(site_insert_counter), } site_insert_counter += 1 - # Remove the site's minor from the planner's free list for this CPU - try: - fm = st.get('free_minors') - if isinstance(fm, list) and 0 <= cpu_int < len(fm) and isinstance(fm[cpu_int], list): - if int(minor_int) in fm[cpu_int]: - fm[cpu_int].remove(int(minor_int)) - except Exception: - pass + # Always reserve the site's minor in the free list, even for synthetic nodes + try: + st = planner.getState() + fm = st.get('free_minors') + cpu_int = int(queue - 1) + minor_int = int(chosen_minor) + if isinstance(fm, list) and 0 <= cpu_int < len(fm) and isinstance(fm[cpu_int], list): + if int(minor_int) in fm[cpu_int]: + fm[cpu_int].remove(int(minor_int)) + except Exception: + pass except Exception: # Planner is optional; ignore errors during capture pass @@ -1889,6 +1892,25 @@ def refreshShapers(): if chosen_minor is None: # Fallback to reserved sequential range; ensure we never collide with the site's minor (<3 reserved) chosen_minor = max(4, int(current_minor)) + # Guard against collision with the parent site's own minor (e.g., 0xd) + try: + site_minor = int(node.get('classMinor', '0x0'), 16) + except Exception: + site_minor = -1 + if chosen_minor == site_minor: + chosen_minor += 1 + # Also guard against collisions within this node's already-assigned circuits + try: + used_minors = set() + for c in circuits_for_node: + try: + used_minors.add(int(str(c.get('classMinor', '0x0')), 16)) + except Exception: + pass + while chosen_minor in used_minors: + chosen_minor += 1 + except Exception: + pass current_minor = chosen_minor + 1 flowIDstring = hex(major_int) + ':' + hex(chosen_minor) upFlowIDstring = hex(major_int + stickOffset) + ':' + hex(chosen_minor) diff --git a/src/bakery_integration_test.py b/src/bakery_integration_test.py index 83aee8f3..05f0c60b 100644 --- a/src/bakery_integration_test.py +++ b/src/bakery_integration_test.py @@ -507,6 +507,55 @@ def _qdisc_show(iface: str) -> Tuple[int, str, str]: return _tc(["qdisc", "show", "dev", iface]) +def check_no_site_circuit_minor_collisions() -> Tuple[bool, List[str]]: + """Verify that no circuit under any node shares the same classMinor as its parent node. + + This guards against regressions where a circuit could be assigned the site/PN's minor, + causing qdiscs to attach at the site handle instead of the circuit handle. + """ + msgs: List[str] = [] + qs = _load_queuing_structure() + if not isinstance(qs, dict): + return False, ["minor collision check: queuingStructure.json not found"] + net = qs.get("Network") + if not isinstance(net, dict): + return False, ["minor collision check: queuingStructure has no 'Network'"] + + def hx(v) -> Optional[int]: + try: + s = str(v) + return int(s, 16) if s.startswith("0x") else int(s) + except Exception: + return None + + ok = True + + def walk(node_map: Dict[str, dict]): + nonlocal ok + for name, node in node_map.items(): + if not isinstance(node, dict): + continue + site_minor = hx(node.get("classMinor")) + if isinstance(node.get("circuits"), list) and site_minor is not None: + for c in node.get("circuits", []): + try: + cmin = hx(c.get("classMinor")) + cid = str(c.get("circuitID", "")) + if cmin is not None and cmin == site_minor: + msgs.append(f"minor collision check: circuit {cid} under '{name}' shares site minor 0x{site_minor:x}") + ok = False + except Exception: + pass + ch = node.get("children") + if isinstance(ch, dict): + walk(ch) + + walk(net) + if ok: + msgs.append("minor collision check: no site/circuit minor collisions detected") + return ok, msgs + + # ----------------------- # IP mapping checks # ----------------------- @@ -1104,6 +1153,11 @@ def run_tiered_suite(log: LogReader, timeout_s: float, results: List[str]) -> bo results.extend(msgs) ok &= passed2 + _mark_step("sanity: no site/circuit minor collisions") + passed2b, msgs2b = check_no_site_circuit_minor_collisions() + results.extend(msgs2b) + ok &= passed2b + _mark_step("sanity: orphan circuit assigned under Generated_PN with original speeds") passed3, msgs3 = test_orphan_circuit_assignment(rows) results.extend(msgs3) @@ -1118,6 +1172,10 @@ def run_tiered_suite(log: LogReader, timeout_s: float, results: List[str]) -> bo passed4, msgs4 = check_generated_pn_tc_bandwidths() results.extend(msgs4) ok &= passed4 + _mark_step("sanity: no site/circuit minor collisions (post-orphan)") + passed4b, msgs4b = check_no_site_circuit_minor_collisions() + results.extend(msgs4b) + ok &= passed4b _mark_step("sanity: orphan circuit HTB attached to PN parent in tc") passed5, msgs5 = check_orphan_tc_attachment("99901") results.extend(msgs5) -- knotmirror 0.0.1