APuP/batman-adv: address #1200 review (fail-fast primitives, limed guard, cleanup)#16
Open
Fede654 wants to merge 4 commits into
Open
APuP/batman-adv: address #1200 review (fail-fast primitives, limed guard, cleanup)#16Fede654 wants to merge 4 commits into
Fede654 wants to merge 4 commits into
Conversation
Calling utils.split without a separator is symptomatic of a bug in the
caller, so fail fast with assert() rather than silently defaulting to a
whitespace separator. Also drops the nil/empty-string guard that was only
added to paper over network.get_mac returning nil (fixed at its source in
a separate commit); every caller passes an explicit non-empty separator and
gmatch already yields {} for an empty input string, so behaviour for valid
callers is unchanged.
Addresses review: "empty separator should be treated as error, the function
should fail in that case because calling it without separator is symptomatic
of something wrong in the caller."
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
network.get_mac() now assert()s when the interface has no MAC (i.e. it does not exist) instead of returning nil, so a caller bug surfaces immediately with a clear message instead of propagating a nil up the call stack. The unit test is updated accordingly to assert the error. network.device_exists() is reimplemented to stat /sys/class/net/<dev> via fs.lstat -- the same lookup already used by network.assert_interface_exists and network.get_own_macs -- instead of shelling out to "ip link show" and parsing stdout. It is on the hot path of every APuP peer notification, so a single stat is both cheaper and consistent with the rest of the module. Addresses review: "better to fail ASAP if the MAC address for a non-existent device is requested, instead of propagating a nil value upstream" and the NAK on the nil-returning test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
During a "wifi down" / "wifi up" cycle the APuP peer interfaces are not torn down in sync with the rest of the radio, so limed can be notified about a peer whose linux device no longer exists. This is an expected transient (the peer reappears once it re-associates), not an error. Move the network.device_exists() guard ahead of network.createStatic() so we skip the peer before touching it: createStatic shells out to "ip link set up" and "ip address add" on the device, which are exactly the calls that produced the "No such device" errors. The verbose pasted-log comment is replaced with a concise explanation answering the reviewer's question (normal transient, not an error), and the skip log line now actually interpolates the ifname (it was passed as a second arg to a utils.log/string.format call with no format specifier, so it was silently dropped). Addresses review question on whether the missing-interface condition is normal or an error. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The unique per-peer MAC was assigned to a global `macaddr` (missing `local`), leaking it into the global namespace; scope it to the function. The byte layout is unchanged (02 : id[2] : id[3] : radio[4] : radio[5] : radio[6], i.e. a locally-administered unicast MAC, two bytes from the md5-derived interface id and the low three bytes of the radio MAC) and is now documented inline. The utils.log call uses a proper format string instead of concatenation (utils.log runs string.format, so a stray '%' in a value would have thrown), and the commented-out "batctl if add" dead code is replaced by a one-line note explaining the interface is attached to batman-adv through the static config. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up on libremesh#1200 picking up the pending review changes (per @javierbrk's "if anyone wants to pick it up in the meantime, that's ok with me"). This PR targets the
fix/ap-up_batman_macbranch so it folds back into libremesh#1200.Each commit maps to a specific review request and keeps the design criteria already agreed in the thread (fail-fast primitives, defensive handling only at the call site, reuse of existing idioms, no leaked globals / dead code). All unit tests pass (
./run_tests): 305 successes / 0 failures / 0 errors, unchanged count vs. the current head.Changes
1.
utils.splitfails on an empty separator (commit 1)Replaces the silent whitespace default with
assert(sep ~= nil and sep ~= '', ...), and drops the nil/empty-string guard that was only there to absorbget_macreturningnil(now fixed at its source). Audited all 18 call sites: every one passes an explicit non-empty separator, andgmatchalready yields{}for an empty input string, so valid callers are unaffected.2.
network.get_macfails fast;device_existsvia stat (commit 2)get_macnowasserts when the interface has no MAC (does not exist) instead of returningnil, surfacing the caller bug with a clear message. The NAK'd test is updated toassert.has_error. Separately,network.device_existsis reimplemented withfs.lstat("/sys/class/net/"..dev)— the same lookup already used bynetwork.assert_interface_existsandget_own_macs— instead ofio.popen("ip link show")+ stdout parsing, since it runs on the hot path of every peer notification.3.
limed: skip a missing APuP peer before configuring it (commit 3)Moves the
device_existsguard ahead ofnetwork.createStatic, sincecreateStaticis what shells out toip link set up/ip address addand produced theNo such deviceerrors. The verbose pasted-log comment is replaced by a concise explanation: this is an expected transient during awifi down/wifi upcycle (the APuP peer interfaces are not torn down in sync and reappear on re-association), not an error. Also fixes the skip log line, which passed the ifname as a second arg to astring.formatcall with no specifier, silently dropping it.4.
lime-proto-batadv: scope the per-peer MAC to a local + cleanup (commit 4)macaddrwas assigned withoutlocal, leaking a global; scoped to the function. The derivation is unchanged and now documented inline:02 : id[2] : id[3] : radio[4] : radio[5] : radio[6](locally-administered unicast; two bytes from the md5-derived interface id, low three bytes from the radio MAC — unique per peer, keeps node identity).utils.loguses a format string instead of concatenation, and the commented-outbatctl if adddead code is replaced with a one-line rationale.Design note
The review asked for fail-fast in the primitives; the defensive
nil-tolerance existed because of thewifi down/uprace. These reconcile by keeping the primitives strict and putting the tolerance only where the transient is legitimate — thedevice_existsguard inlimed— which is exactly what makes the downstream fail-fast safe. No robustness is lost.