feat(os): NetworkInterface values and NetworkInterface.all on Linux #542
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/539-network-interfaces"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #539
OS slice 5, step 2a of #129.
std/os/network:NetworkInterface,InterfaceAddress(withsubnet()),InterfaceStatus,InterfaceKind, exported fromstd/osand documented.Posix.interfaceEntries, overgetifaddrsanswers a tab-separated line per address and per link; the MTU, operstate and type come from/sys/class/net/<name>/throughreadSystemFile. Pure parsers and grouping are tested on every machine.OsError.Unsupported(step 2b).InterfaceAddress.subnet()answersResult<Subnet, OsError>(OS.md 5.5 updated): a value built by hand can carry a prefix length out of range, andSubnet.ofneeds a masked network address, so it masks first.Notes for review:
runtime/os/posix.ccould not be compiled where this was written (no C compiler); CI is the first compile.runtime/include/torb_natives.handruntime/machine_natives.care not regenerated here (the available nightly predates main's natives);tools/land.sh buildwrites them.CI red on
7e22ec4:ci / tier A (linux-x64),ci / tier B (linux-x64),ci / tools/release-sync and tools/registry (linux-x64),ci / the playground (torb as WebAssembly)and the aggregateci / gatesfailed (bootstrap, the same-C check, pdisc and commit messages are green). I cannot read the job logs with the reviewer token, so I name no cause with certainty; the likeliest one is what the PR body says:runtime/machine_natives.candruntime/include/torb_natives.hdo not yet listtorb_os_posix_interface_entries(main has the neighbouringtorb_os_posix_*entries in both), so the newPosix.interfaceEntriesnative has no table entry where tier A/B run it. Regenerate them withtools/land.sh buildand push; also check the playground and release-sync failures separately, since those may be a different cause. My read of the diff found no other blocker (C inposix.c, the parsers,subnet()masking and the tests look right), so the next green run brings the review back.Pushed
415690d:runtime/machine_natives.candruntime/include/torb_natives.hnow listtorb_os_posix_interface_entries(entry sorted betweenhost_nameandprocess_identity, later machine natives renumbered, count 325 -> 326; table checked for gaps).tools/land.sh buildcannot run here (no C compiler/bootstrap), so this is written by hand to the generator's pattern; CI is the check. The playground and release-sync failures of7e22ec4could not be diagnosed (job logs are not readable with my token); if they stay red on the new head I will look at them separately. Re-requesting review.CI red on
415690d:ci / tier B (linux-x64),ci / the playground (torb as WebAssembly)and the aggregateci / gates. Tier A, release-sync, the same-C check, bootstrap, pdisc and commit messages are green now, so the natives-table fix worked.tier B (linux-x64)also fails on main (39eae32, push run), so it is most likely not caused by this PR; confirm on the job log, which I cannot read with the reviewer token.the playground (torb as WebAssembly)passes on main and fails on this PR (both heads), so it is PR-related. Likeliest cause, unconfirmed: the newruntime/os/posix.ccode is guarded bydefined(__unix__) || defined(__APPLE__), which the WebAssembly toolchain may also satisfy, and it now includes<ifaddrs.h>,<net/if.h>and<netpacket/packet.h>, which wasm libcs commonly lack. If so, narrow the guard of the interface code (for example__linux__for the Linux half,Unsupportedelsewhere) so the wasm build skips it.My read of the diff found no other blocker. Your request stays pending; the next CI run brings the review back.
Pushed
932585d: the interface code ofruntime/os/posix.c(the<ifaddrs.h>/<net/if.h>includes and everything from the flag bits totorb_os_posix_interface_entries) is now built only under__linux__ || __APPLE__ || __FreeBSD__, the same condition under whichmachine_natives.ccalls it, so the WebAssembly build of the playground (which defines__unix__) skips it; the otherPosixfunctions are unchanged. Cause of the playground failure is inferred from the toolchain, not from a job log.tier B (linux-x64)also fails on main (39eae32) per your read, so I leave it. Re-requesting review.CI red on
932585d:ci / the playground (torb as WebAssembly)(and the aggregateci / gates);ci / tier B (linux-x64)too, which also fails on main (39eae32push run), so I do not hold it against this PR. Tier A, bootstrap, release-sync, the same-C check, pdisc and commit messages are green.415690d: 1m41s). That is too short for the emcc compile of the C to have started, so this looks like the job or its container not starting (or the artifact download) rather than theposix.cguard. I cannot read job logs with the reviewer token. Please re-run theci / the playgroundjob (or push an empty-diff rebase if you cannot re-run it) and read its log; if it still fails, the log names the cause.__linux__. If it does, the narrowed guard__linux__ || __APPLE__ || __FreeBSD__still pulls<ifaddrs.h>/<netpacket/packet.h>into the wasm build, and the guard needs&& !defined(__EMSCRIPTEN__)(here and inmachine_natives.c).My read of the diff found no other blocker (parsers,
subnet()masking, C inposix.c, tests instd/os/tests/network.test.trb, docs). Red CI is not a review round: my request stays pending and the next CI run brings the review back.932585d820db4968d662Read the job logs (Actions API works with my token). Findings on
932585d:the playground (torb as WebAssembly)failed in 5s at "Downloading single artifact":Failed to ListArtifacts: Unable to make request: ECONNREFUSED. That is the runner failing to reach the artifact service, before any emcc step ran; theposix.cguard is not involved (and the earlier415690dfailure was the real compile, which the guard fixed).tier B (linux-x64): 330 passed, 4 failed, alltests/conformance/resource-*.trb(resource-bytes/name/text without allocation budget, resource-missing panics on the shipped file). Nothing instd/osor the interface code; main fixed exactly these in403ee176("allocation budget for resource-missing").db4968d, which brings the tier B fix and a fresh playground run. No code change otherwise. I did not add!defined(__EMSCRIPTEN__): the other__linux__ || __APPLE__ || __FreeBSD__guards inmachine_natives.cwould break the wasm build too if emscripten defined__linux__, and the playground compiled up to the415690drun; if the new run still fails at the C compile I will add it. Re-requesting review.Not mergeable on
db4968d: rebase onto main (acf8510); no other blockers. CI is green ondb4968d. Main gained 5 commits since the merge base (403ee17: x86 cpuid/decoders) that touch the same files, so Forgejo reports a conflict:runtime/machine_natives.c,runtime/include/torb_natives.h,runtime/include/torb_os.h,compiler/src/backend/c/natives.trb,std/os/src/lib.trb,docs/design/OS.md,docs/design/NATIVES.md,docs/standard-library/os.mdand its skill copy. Mind the natives table: the newtorb_os_posix_interface_entriesentry must keep the sorted order and the renumbering/count consistent with the new x86 natives. The rebase's CI run brings the review back.db4968d6620ac069f9e0Rebased onto main (
acf8510), new head0ac069f. Conflicts weredocs/design/NATIVES.md(counts now keep 201 / total 558) andruntime/machine_natives.c; the latter I rebuilt from main's file instead of merging the renumbering by hand:torb_os_posix_interface_entriesis native 190 (betweenhost_nameandprocess_identity), everything from there renumbered +1 including the x86 cpuid natives, count 327 -> 328; checked that the table lists 0..327 without gaps and that every native 0..327 has exactly one definition.torb_natives.hmerged cleanly (entry sorted betweenhostNameandprocessIdentity). pdisc index/check green. No code change otherwise. Re-requesting review.Approved on
0ac069f(re-review after the rebase ontoacf8510; CI green, combined status success).std/os/tests/network.test.trbcovers parsers, grouping,mtuOf/statusOf/kindOf/isWireless,subnet()masking and its range errors; tier A, tier B, playground, same-C check, release-sync green on this head.getifaddrsloop skips NULLifa_addr, handles NULL netmask, prefix length from the leading ones, buffer doubling, UTF-8 failure path frees the buffer; parsers reject malformed lines withOsError.Malformed;/sysmisses fall back to 0/Unknown/Other without failing.Posix.interfaceEntriesis declared innatives.trb,torb_natives.h,torb_os.h,posix.candmachine_natives.c; the same-C check and tier A confirm the renumbering after the rebase.__linux__ || __APPLE__ || __FreeBSD__, other systems answerOsError.Unsupported; the playground build is green.Posixboundary, documented in NATIVES.md.Non-blocking:
InterfaceFactsmerges flags with|over an interface's lines; they are identical per interface, so=from the first line would say the same more directly.NetworkInterface.allfollowsgetifaddrs(first appearance), which matches index order on Linux in practice; the doc says "order of their indexes", so a sort byindexwould make the promise hold by construction.