Browse Source

feat(wan): accept an optional ipv6 in the pusher contract (#2226) (#2274)

Nacho 2 ngày trước cách đây
mục cha
commit
2cb33fae4e

+ 1 - 0
CHANGELOG.md

@@ -9,6 +9,7 @@ y este proyecto se adhiere a [Versionado Semántico](https://semver.org/lang/es/
 
 ### Added
 
+- The WAN section accepts an optional `ipv6` field, so an external pusher that reads the uplink's global IPv6 (the gfiber pusher does) can push it instead of journalling it. The server passes it through to the WAN panel and to the WAN port tile, and a unit that reports only IPv6 keeps its address instead of being treated as having no WAN data. The native agent does not probe it yet, so nothing changes for routers on their own agent (#2226). Thanks to @brainnoms for the contract.
 - The vendor catalog accepts a third mode, `node`, for pushers that must run on the monitored host itself: a Kubernetes node that reads its own kubelet and `/proc`, a Docker host, a storage box. The Integrations page registers the row, issues the token and shows the environment to set, and the server never downloads, installs, starts or stops anything there. Start and stop answer `not_managed`, update only refreshes the published version so the page can point at the download, edit keeps to the label and the interval, and the row stays `pending` until the pusher's first push makes it live (#2272).
 - A host that runs other machines - an RKE2 node, a PVE box, a Docker host - can report the guests nested inside it through an optional `workloads` section in the push: stable id, name, kind and state per guest. The server keeps the census as reported and shows it on the unit's detail page, a count and a list with each workload's state. It is detail data, not graph data: a node with a hundred pods does not draw a hundred clients (#2227). Thanks to @brainnoms for the contract.
 - A unit that is not the gateway can keep the neighbours of its uplink out of its client list. The agent reports its logical networks with their Linux devices, the router detail page shows a Client discovery panel with Automatic, On or Off per network, and Automatic ignores the network that carries the unit's uplink (`br-*` bridges excepted, where an AP's uplink is its own LAN). Only devices attributed from ARP alone are filtered: a wireless association or an FDB entry still wins (#2235).

+ 5 - 0
agent/probe/probe.go

@@ -346,6 +346,11 @@ type WanInfo struct {
 	IP      string   `json:"ip,omitempty"`      // dirección IPv4 pública
 	Gateway string   `json:"gateway,omitempty"` // puerta de enlace (nexthop/ptpaddress)
 	DNS     []string `json:"dns,omitempty"`     // servidores DNS
+	// IPv6 es la dirección global (sin ULA) de la interfaz WAN cuando el
+	// origen la conoce: el agente nativo no la sondea todavía, un pusher
+	// externo sí puede mandarla (#2226). Vacía o ausente con agentes y
+	// pushers antiguos, que es lo que ya hacían.
+	IPv6 string `json:"ipv6,omitempty"`
 	// Port es la interfaz por debajo del protocolo: la boca por la que sale
 	// internet ("lan1" para un PPPoE sobre esa boca, "eth1.20" con VLAN).
 	// Vacía cuando el uplink no pasa por ninguna (módem celular).

+ 2 - 0
app/public/locales/en/translation.json

@@ -1224,6 +1224,7 @@
       "usedOf_one": "{{used}} of {{total}} port in use",
       "usedOf_other": "{{used}} of {{total}} ports in use",
       "wanPublicIp": "Public IP",
+      "wanIpv6": "IPv6",
       "wanGateway": "Gateway",
       "wanDns": "DNS",
       "deviceDetail": "Detail",
@@ -1326,6 +1327,7 @@
       "chartAria": "Gateway WAN traffic. Current download {{down}} Mbps, upload {{up}} Mbps.",
       "fiber": "Fiber {{plan}}",
       "publicIp": "Public IP",
+      "ipv6": "IPv6",
       "title": "WAN network",
       "totalToday": "Total today",
       "speedtestTitle": "Measured speed",

+ 2 - 0
app/public/locales/es/translation.json

@@ -1224,6 +1224,7 @@
       "usedOf_one": "{{used}} de {{total}} boca en uso",
       "usedOf_other": "{{used}} de {{total}} bocas en uso",
       "wanPublicIp": "IP pública",
+      "wanIpv6": "IPv6",
       "wanGateway": "Puerta de enlace",
       "wanDns": "Servidor DNS",
       "deviceDetail": "Detalle",
@@ -1326,6 +1327,7 @@
       "chartAria": "Tráfico WAN de la puerta de enlace. Descarga actual {{down}} Mbps, subida {{up}} Mbps.",
       "fiber": "Fibra {{plan}}",
       "publicIp": "IP pública",
+      "ipv6": "IPv6",
       "title": "Red WAN",
       "totalToday": "Total hoy",
       "speedtestTitle": "Velocidad medida",

+ 2 - 0
app/public/locales/ru/translation.json

@@ -1251,6 +1251,7 @@
       "usedOf_many": "занято {{used}} из {{total}} портов",
       "usedOf_other": "занято {{used}} из {{total}} порта",
       "wanPublicIp": "Публичный IP",
+      "wanIpv6": "IPv6",
       "wanGateway": "Шлюз",
       "wanDns": "DNS",
       "deviceDetail": "Подробнее",
@@ -1359,6 +1360,7 @@
       "chartAria": "Трафик WAN шлюза. Сейчас приём {{down}} Мбит/с, отдача {{up}} Мбит/с.",
       "fiber": "Оптика {{plan}}",
       "publicIp": "Публичный IP",
+      "ipv6": "IPv6",
       "title": "Сеть WAN",
       "totalToday": "Всего сегодня",
       "speedtestTitle": "Измеренная скорость",

+ 2 - 0
app/public/locales/zh/translation.json

@@ -940,6 +940,7 @@
       "usedOf_one": "{{total}} 个端口中 {{used}} 个在用",
       "usedOf_other": "{{total}} 个端口中 {{used}} 个在用",
       "wanPublicIp": "公网 IP",
+      "wanIpv6": "IPv6",
       "wanGateway": "网关",
       "wanDns": "DNS",
       "deviceDetail": "详情",
@@ -1008,6 +1009,7 @@
       "chartAria": "网关 WAN 流量。当前下载 {{down}} Mbps,上传 {{up}} Mbps。",
       "fiber": "光纤 {{plan}}",
       "publicIp": "公网 IP",
+      "ipv6": "IPv6",
       "title": "WAN 网络",
       "totalToday": "今日总量",
       "speedtestTitle": "实测速率",

+ 2 - 1
app/src/components/routers/PortPanel.tsx

@@ -39,7 +39,7 @@ function Jack({ port, index, wan }: { port: EthPort; index: number; wan?: WanInf
     ? t('routerDetail.ports.ariaUsed', { label: port.label, connectedTo: portPeerLabel(port) || t('routerDetail.ports.unknownDevice'), speed: port.speed ? `, ${port.speed}` : '' })
     : t('routerDetail.ports.ariaFree', { label: port.label })
 
-  const hasWanInfo = isWan && wan && (wan.proto || wan.publicIp || wan.gateway || (wan.dns?.length ?? 0) > 0)
+  const hasWanInfo = isWan && wan && (wan.proto || wan.publicIp || wan.ipv6 || wan.gateway || (wan.dns?.length ?? 0) > 0)
 
   return (
     <Tooltip>
@@ -200,6 +200,7 @@ function Jack({ port, index, wan }: { port: EthPort; index: number; wan?: WanInf
             {isWan && hasWanInfo && wan ? (
               <div className="mt-2 grid grid-cols-2 gap-1.5">
                 {wan.publicIp && <MiniStat label={t('routerDetail.ports.wanPublicIp')} value={wan.publicIp} />}
+                {wan.ipv6 && <MiniStat label={t('routerDetail.ports.wanIpv6')} value={wan.ipv6} />}
                 {wan.gateway && <MiniStat label={t('routerDetail.ports.wanGateway')} value={wan.gateway} />}
                 {wan.dns && wan.dns.length > 0 && (
                   <div className="col-span-2">

+ 3 - 0
app/src/components/routers/WanLatency.tsx

@@ -61,6 +61,9 @@ export function WanLatency({ extras }: { extras?: RouterExtras }) {
 
   const WAN_METRICS = [
     { label: t('routerDetail.wan.publicIp'), value: wan.publicIp },
+    // #2226: solo cuando el origen la reporta. Un pusher que no la manda
+    // deja el panel exactamente como estaba.
+    ...(wan.ipv6 ? [{ label: t('routerDetail.wan.ipv6'), value: wan.ipv6 }] : []),
     { label: 'ISP', value: `${wan.isp} · ${t('routerDetail.wan.fiber', { plan: wan.plan.replace(' Mbps', '') })}` },
     { label: t('routerDetail.wan.totalToday'), value: fmtBytes(wan.total24h) },
   ] as const

+ 2 - 0
app/src/data/types.ts

@@ -141,6 +141,8 @@ export interface WanInfo {
   proto?: string
   gateway?: string
   dns?: string[]
+  /** IPv6 global del uplink (#2226). Ausente si el origen no la reporta. */
+  ipv6?: string
   /** Velocidad contratada declarada por el admin (Mbps, issue #151). Ausente si no configurada. */
   contractDownMbps?: number
   contractUpMbps?: number

+ 1 - 1
docs/external-integrations.md

@@ -70,7 +70,7 @@ Follow the hardware evidence rules in [CONTRIBUTING.md](../CONTRIBUTING.md). A n
 Start read-only. A useful first slice normally contains only data that already fits the contract:
 
 - System and board information through `data.system`.
-- WAN state through `data.wan`.
+- WAN state through `data.wan`, with its optional `ipv6` for the uplink's global IPv6 address (#2226).
 - Associated clients and radios through `data.wireless`.
 - DHCP leases through `data.dhcp`.
 - FDB and Ethernet ports through `data.fdb`.

+ 48 - 0
server-go/internal/adapters/agent_wan_test.go

@@ -118,3 +118,51 @@ func TestPolledFromAgentTakesReservationsFromPayload(t *testing.T) {
 		t.Fatalf("reservations from the payload: %+v", p.reservations)
 	}
 }
+
+// TestPolledFromAgentTomaElIPv6DelPayload (#2226): el campo opcional viaja del
+// JSON al wanInfo sin tocar la sonda SSH, y una unidad que solo publica IPv6
+// también lo conserva (el overview no puede tragárselo por falta de IPv4).
+func TestPolledFromAgentTomaElIPv6DelPayload(t *testing.T) {
+	l := NewLive(nil, nil, []RouterConfig{
+		{ID: "gateway", Host: "192.0.2.1", Name: "gateway", IsGateway: true, AgentOnly: true},
+	}, nil)
+	payload := &probe.Payload{
+		Router: "gateway", Ts: 1, Version: "3.0.52",
+		Data: probe.PayloadData{Wan: &probe.WanInfo{
+			Proto: "dhcp", IP: "203.0.113.45", IPv6: "2001:db8::45",
+		}},
+	}
+	p := l.polledFromAgent(l.routers[0], payload)
+	if p.wanInfo.IPv6 != "2001:db8::45" {
+		t.Fatalf("IPv6 del payload: %+v", p.wanInfo)
+	}
+
+	v6only := &probe.Payload{
+		Router: "gateway", Ts: 2, Version: "3.0.52",
+		Data: probe.PayloadData{Wan: &probe.WanInfo{IPv6: "2001:db8::46"}},
+	}
+	p = l.polledFromAgent(l.routers[0], v6only)
+	if p.wanInfo.IPv6 != "2001:db8::46" || p.wanInfo.IP != "" {
+		t.Fatalf("una unidad solo IPv6 debe conservar la dirección: %+v", p.wanInfo)
+	}
+}
+
+// TestDefaultWanPublicaIPv6 (#2226): la vista WAN del overview pasa el campo
+// tal cual y no lo inventa cuando el origen no lo manda.
+func TestDefaultWanPublicaIPv6(t *testing.T) {
+	gw := &RouterConfig{ID: "gateway", Host: "192.0.2.1", IsGateway: true, AgentOnly: true}
+	l := NewLive(nil, nil, []RouterConfig{*gw}, nil)
+	l.mu.Lock()
+	l.lastPolled["gateway"] = &routerPolled{wanInfo: probe.WanInfo{IPv6: "2001:db8::45"}}
+	l.mu.Unlock()
+	if got := l.defaultWan(gw).IPv6; got != "2001:db8::45" {
+		t.Fatalf("wan.IPv6 = %q, want the pushed address", got)
+	}
+
+	l.mu.Lock()
+	l.lastPolled["gateway"] = &routerPolled{wanInfo: probe.WanInfo{IP: "203.0.113.45"}}
+	l.mu.Unlock()
+	if got := l.defaultWan(gw).IPv6; got != "" {
+		t.Fatalf("wan.IPv6 = %q, want empty when the source sends no v6", got)
+	}
+}

+ 6 - 3
server-go/internal/adapters/live.go

@@ -1419,7 +1419,7 @@ func (l *Live) pollRouter(ctx context.Context, cfg RouterConfig) (*routerPolled,
 		gw := l.gatewayCfg
 		client := l.clients[cfg.ID]
 		l.mu.Unlock()
-		hasWan := p.wanInfo.Proto != "" || p.wanInfo.IP != "" || p.wanInfo.Gateway != ""
+		hasWan := p.wanInfo.Proto != "" || p.wanInfo.IP != "" || p.wanInfo.Gateway != "" || p.wanInfo.IPv6 != ""
 		if gw != nil && cfg.ID == gw.ID && client != nil && !hasWan {
 			p.wanInfo = l.probeWanInfo(cfg.ID, client).Wan
 		}
@@ -1832,7 +1832,7 @@ func displayRole(p *routerPolled, cfg RouterConfig, isGw bool) (string, string)
 	}
 	wireless := len(p.wireless) > 0 || len(p.wirelessSide) > 0 || len(p.radios) > 0
 	wan := p.wanInfo.Proto != "" || p.wanInfo.IP != "" || p.wanInfo.Gateway != "" ||
-		p.wanInfo.Port != "" || p.multiWan != nil
+		p.wanInfo.Port != "" || p.wanInfo.IPv6 != "" || p.multiWan != nil
 	if wireless && !wan {
 		return "Punto de acceso", "AP"
 	}
@@ -4788,13 +4788,16 @@ func (l *Live) defaultWan(gw *RouterConfig) WAN {
 			wan.LossPct = *p.lossPct
 		}
 		// Conexión WAN real (issue #276): proto/IP/gateway/DNS desde ubus.
-		if wi := p.wanInfo; wi.IP != "" || wi.Proto != "" {
+		// #2226: una unidad que solo publica IPv6 (pusher K8s, gateway con
+		// v6 y sin v4) también entra, o su dirección se quedaría fuera.
+		if wi := p.wanInfo; wi.IP != "" || wi.Proto != "" || wi.IPv6 != "" {
 			wan.Proto = wi.Proto
 			if wi.IP != "" {
 				wan.PublicIP = wi.IP
 			}
 			wan.Gateway = wi.Gateway
 			wan.DNS = wi.DNS
+			wan.IPv6 = wi.IPv6
 		}
 	}
 	// Resumen del día desde la BD (issue #169): pico de hoy, media y total

+ 4 - 0
server-go/internal/adapters/types.go

@@ -84,6 +84,10 @@ type WAN struct {
 	Proto   string   `json:"proto,omitempty"`
 	Gateway string   `json:"gateway,omitempty"`
 	DNS     []string `json:"dns,omitempty"`
+	// IPv6 (#2226): la dirección global (sin ULA) del uplink, opcional. La
+	// manda el origen que la conoce (hoy, un pusher externo), no el agente
+	// nativo. Ausente = el origen no la reporta, que es lo que ya pasaba.
+	IPv6 string `json:"ipv6,omitempty"`
 	// ContractDownMbps/ContractUpMbps: velocidad contratada declarada por el
 	// admin en Ajustes (issue #151). Punteros: ausentes (null) si no está
 	// configurado. Los inyecta el server en handleOverview desde el kv — el