Files
mesh-catalog/modules/networkmanager/cmd/uplink-tools/manager.go
T
jochen 1dec6eb02c M7 networkmanager: its tools and health
The bundle serves uplink_sign_in, uplink_names_again, uplink_rating_again,
uplink_publish_again and uplink_health: the read of the reaction, the three acts the
parts do by themselves, and the watcher process's health, which also gives the names
again where the resolver no longer holds them.

Builds: design 08 sign-in-page §13, §23
2026-11-24 21:25:17 +01:00

72 lines
2.1 KiB
Go

package main
// NetworkManager's word on each link's names: `nmcli device show`, read in its terse form. A link
// NetworkManager does not manage — a tunnel a VPN client raised with `ip`, the mesh's own — is not in it,
// and the links verb says the link without what the manager does not know.
import (
"context"
"strings"
stdio "git.novox.be/novox/mesh-sdk/go"
)
func managerDNS(ctx context.Context) (map[string]LinkDNS, error) {
out, err := execRunner(ctx, "nmcli", "-t", "-f", "GENERAL.DEVICE,GENERAL.STATE,IP4.DNS,IP6.DNS,IP4.DOMAIN,IP6.DOMAIN",
"device", "show")
if err != nil {
return nil, err
}
return parseNmcli(out), nil
}
// parseNmcli reads `nmcli -t device show`: blocks of KEY:value lines, one block per device.
func parseNmcli(out string) map[string]LinkDNS {
links := map[string]LinkDNS{}
device := ""
var cur LinkDNS
flush := func() {
if device != "" && (len(cur.Servers) > 0 || len(cur.Domains) > 0) {
cur.Manager = "NetworkManager"
links[device] = cur
}
device, cur = "", LinkDNS{}
}
for _, line := range strings.Split(out, "\n") {
key, value, ok := strings.Cut(strings.TrimSpace(line), ":")
if !ok {
continue
}
switch {
case key == "GENERAL.DEVICE":
flush()
device = value
case key == "GENERAL.STATE":
cur.State = value
case strings.HasPrefix(key, "IP4.DNS"), strings.HasPrefix(key, "IP6.DNS"):
cur.Servers = append(cur.Servers, value)
case strings.HasPrefix(key, "IP4.DOMAIN"), strings.HasPrefix(key, "IP6.DOMAIN"):
cur.Domains = append(cur.Domains, value)
}
}
flush()
return links
}
// holder is what networkmanager adds to the seat's verbs (design 08 sign-in-page §11): the watcher, `uplink-tools
// watch`.
func holder(m Machine) holderOwn {
own := holderOwn{Commands: map[string]func([]string) error{"watch": watch}}
f, err := theFolder()
if err != nil {
journal("the module's folder: %v", err)
return own
}
b := newBundle(f)
own.Tools = b.tools()
own.Start = func() {
b.start(bundleRuns{files: fileEvents, fileMade: fileMade, onHeartbeat: stdio.OnHeartbeat, subscribe: stdio.Subscribe})
}
return own
}