Procházet zdrojové kódy

feat(devices): expose selected name source

Part of #2163
Nacho před 1 týdnem
rodič
revize
20fd901e0b

+ 1 - 0
CHANGELOG.md

@@ -9,6 +9,7 @@ y este proyecto se adhiere a [Versionado Semántico](https://semver.org/lang/es/
 
 ### Added
 
+- The client detail and API expose the source of the selected name: DHCP, mDNS, reverse DNS, reservation, known-MAC alias, GL.iNet or manual. The attribution persists through retention and server restarts without changing name selection (#2163).
 - Remote AdGuard Home connections can use HTTPS, with an explicit opt-in for a private instance's self-signed certificate. Existing configurations keep HTTP and strict certificate verification by default, and `ADGUARD_INSECURE_SKIP_VERIFY=1` provides the same opt-in for environment-based setups (#2167, reported by @tam481).
 - mDNS TXT model and manufacturer metadata can now disambiguate products that share a service. Real fixtures distinguish LG TVs from Marantz speakers over AirPlay, and old agents keep the existing generic behavior (#2158).
 

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

@@ -453,6 +453,16 @@
     "copyIp": "Copy IP",
     "detail": {
       "linkedMacs": "Linked MACs",
+      "nameSource": "Name source",
+      "source": {
+        "dhcp": "DHCP",
+        "mdns": "mDNS",
+        "rdns": "Reverse DNS",
+        "reservation": "DHCP reservation",
+        "known_mac": "Known MAC alias",
+        "glinet": "GL.iNet",
+        "manual": "Manual"
+      },
       "dhcpLease": "DHCP lease",
       "firstSeen": "First seen",
       "lastSeen": "Last seen",

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

@@ -453,6 +453,16 @@
     "copyIp": "Copiar IP",
     "detail": {
       "linkedMacs": "MACs enlazadas",
+      "nameSource": "Fuente del nombre",
+      "source": {
+        "dhcp": "DHCP",
+        "mdns": "mDNS",
+        "rdns": "DNS inverso",
+        "reservation": "Reserva DHCP",
+        "known_mac": "Alias de MAC conocida",
+        "glinet": "GL.iNet",
+        "manual": "Manual"
+      },
       "dhcpLease": "Concesión DHCP",
       "firstSeen": "Primera vez vista",
       "lastSeen": "Última vez vista",

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

@@ -467,6 +467,16 @@
     "copyIp": "Копировать IP",
     "detail": {
       "linkedMacs": "Связанные MAC",
+      "nameSource": "Источник имени",
+      "source": {
+        "dhcp": "DHCP",
+        "mdns": "mDNS",
+        "rdns": "Обратный DNS",
+        "reservation": "Резервирование DHCP",
+        "known_mac": "Псевдоним известного MAC",
+        "glinet": "GL.iNet",
+        "manual": "Вручную"
+      },
       "dhcpLease": "Аренда DHCP",
       "firstSeen": "Первое появление",
       "lastSeen": "Последнее появление",

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

@@ -371,6 +371,16 @@
     "copyIp": "复制 IP",
     "detail": {
       "linkedMacs": "已关联 MAC",
+      "nameSource": "名称来源",
+      "source": {
+        "dhcp": "DHCP",
+        "mdns": "mDNS",
+        "rdns": "反向 DNS",
+        "reservation": "DHCP 预留",
+        "known_mac": "已知 MAC 别名",
+        "glinet": "GL.iNet",
+        "manual": "手动"
+      },
       "dhcpLease": "DHCP 租约",
       "firstSeen": "首次发现",
       "lastSeen": "最近发现",

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

@@ -274,6 +274,8 @@ export interface Device {
   speedMbps?: number
   id: string
   name: string
+  /** Evidencia que produjo el nombre visible: dhcp, mdns, rdns, reserva, alias, GL.iNet o manual. */
+  nameSource?: 'dhcp' | 'mdns' | 'rdns' | 'reservation' | 'known_mac' | 'glinet' | 'manual'
   type: DeviceType
   manufacturer: string
   ip: string

+ 3 - 0
app/src/pages/Devices.tsx

@@ -931,6 +931,9 @@ function DeviceDetail({
       <DetailItem label="Hostname" mono>
         {device.hostname || <span className="text-text-muted">—</span>}
       </DetailItem>
+      <DetailItem label={t('devices.detail.nameSource')}>
+        {device.nameSource ? t(`devices.detail.source.${device.nameSource}`) : <span className="text-text-muted">—</span>}
+      </DetailItem>
       {hasAdGuard && (
         <div className="min-w-0">
           <div className="text-label uppercase text-text-muted">AdGuard</div>

+ 22 - 8
server-go/internal/adapters/device_seen.go

@@ -199,12 +199,14 @@ func (l *Live) noteDevicesSeen(devices []Device, nowMs int64) []Device {
 	// reaparece sin mDNS no pise el nombre y el tipo buenos del registro.
 	existing := map[string]bool{}
 	retainedNames := map[string]string{}
-	if rows, err := l.db.Query("SELECT mac, COALESCE(name, '') FROM device_seen"); err == nil {
+	retainedSources := map[string]string{}
+	if rows, err := l.db.Query("SELECT mac, COALESCE(name, ''), COALESCE(name_source, '') FROM device_seen"); err == nil {
 		for rows.Next() {
-			var m, name string
-			if rows.Scan(&m, &name) == nil {
+			var m, name, source string
+			if rows.Scan(&m, &name, &source) == nil {
 				existing[m] = true
 				retainedNames[m] = name
+				retainedSources[m] = source
 			}
 		}
 		rows.Close()
@@ -215,11 +217,12 @@ func (l *Live) noteDevicesSeen(devices []Device, nowMs int64) []Device {
 		return nil
 	}
 	defer tx.Rollback() //nolint:errcheck // no-op tras Commit
-	stmt, err := tx.Prepare(`INSERT INTO device_seen (mac, first_seen, last_seen, name, ip, device_type) VALUES (?, ?, ?, ?, ?, ?)
+	stmt, err := tx.Prepare(`INSERT INTO device_seen (mac, first_seen, last_seen, name, ip, device_type, name_source) VALUES (?, ?, ?, ?, ?, ?, ?)
 		ON CONFLICT(mac) DO UPDATE SET last_seen = excluded.last_seen,
 			name = CASE WHEN excluded.name != '' THEN excluded.name ELSE device_seen.name END,
 			ip = CASE WHEN excluded.ip != '' THEN excluded.ip ELSE device_seen.ip END,
-			device_type = CASE WHEN excluded.device_type != '' THEN excluded.device_type ELSE device_seen.device_type END`)
+			device_type = CASE WHEN excluded.device_type != '' THEN excluded.device_type ELSE device_seen.device_type END,
+			name_source = CASE WHEN excluded.name_source != '' THEN excluded.name_source ELSE device_seen.name_source END`)
 	if err != nil {
 		return nil
 	}
@@ -244,10 +247,15 @@ func (l *Live) noteDevicesSeen(devices []Device, nowMs int64) []Device {
 			name = d.Name
 		}
 		deviceType := inferredDeviceType(d)
+		nameSource := d.NameSource
+		if nameSource == "" && name != "" && retainedNames[mac] == name && retainedSources[mac] != "" {
+			nameSource = retainedSources[mac]
+		}
 		if name == "" && !d.namePinned && isGeneratedDeviceName(d.Name) && retainedNames[mac] != "" && !isGeneratedDeviceName(retainedNames[mac]) {
 			// A transient loss of mDNS brought the DHCP placeholder back. Empty
 			// name and type make the upsert keep the better retained identity.
 			deviceType = ""
+			nameSource = ""
 		}
 		// #1818: el alta guarda el primer avistamiento real, no el del ciclo en
 		// que el cliente supero el minuto de permanencia.
@@ -255,7 +263,7 @@ func (l *Live) noteDevicesSeen(devices []Device, nowMs int64) []Device {
 		if d.FirstSeenMs > 0 && d.FirstSeenMs < nowMs {
 			first = d.FirstSeenMs
 		}
-		if _, err := stmt.Exec(mac, first, nowMs, name, saneIP(d.IP), deviceType); err != nil {
+		if _, err := stmt.Exec(mac, first, nowMs, name, saneIP(d.IP), deviceType, nameSource); err != nil {
 			return nil
 		}
 		// #1323: primera vez CON nombre (los sin nombre los cubre
@@ -377,6 +385,9 @@ func (l *Live) applyDeviceSeen(devices []Device) {
 			if s.ip != "" && devices[i].IP == "" {
 				devices[i].IP = saneIP(s.ip)
 			}
+			if s.nameSource != "" {
+				devices[i].NameSource = s.nameSource
+			}
 			// #1315: stickiness del tipo. La clasificación viva se rehizo con
 			// el nombre ya degradado y cayó en "desconocido": se conserva el
 			// último tipo inferido (no override) del registro. Un override
@@ -396,6 +407,7 @@ type seenRow struct {
 	first, last int64
 	name, ip    string
 	deviceType  string
+	nameSource  string
 }
 
 // isNewToday: el registro (#954) se abrió en el día local del server. Mismo
@@ -444,7 +456,7 @@ func countNewToday(devices []Device) int {
 // #1315: un nombre con forma de MAC (BDs contaminadas por ciclos previos)
 // se devuelve vacío: nunca se restaura ni emite una MAC como nombre.
 func (l *Live) seenByMac() (map[string]seenRow, error) {
-	rows, err := l.db.DB.Query(`SELECT mac, first_seen, last_seen, COALESCE(name, ''), COALESCE(ip, ''), COALESCE(device_type, '') FROM device_seen`)
+	rows, err := l.db.DB.Query(`SELECT mac, first_seen, last_seen, COALESCE(name, ''), COALESCE(ip, ''), COALESCE(device_type, ''), COALESCE(name_source, '') FROM device_seen`)
 	if err != nil {
 		return nil, err
 	}
@@ -453,7 +465,7 @@ func (l *Live) seenByMac() (map[string]seenRow, error) {
 	for rows.Next() {
 		var mac string
 		var s seenRow
-		if err := rows.Scan(&mac, &s.first, &s.last, &s.name, &s.ip, &s.deviceType); err != nil {
+		if err := rows.Scan(&mac, &s.first, &s.last, &s.name, &s.ip, &s.deviceType, &s.nameSource); err != nil {
 			return nil, err
 		}
 		if isMACLike(s.name) {
@@ -522,6 +534,7 @@ func (l *Live) ghostDevices(devices []Device) []Device {
 			Band:        "—",
 			FirstSeenMs: s.first,
 			LastSeenMs:  s.last,
+			NameSource:  s.nameSource,
 			IsNew:       s.isNewToday(now),
 			NewThisWeek: s.isNewThisWeek(now),
 		}
@@ -546,6 +559,7 @@ func (l *Live) ghostDevices(devices []Device) []Device {
 			if ov.Name != "" {
 				d.Name = ov.Name
 				d.NameOverride = ov.Name
+				d.NameSource = "manual"
 			}
 			if ov.DeviceType != "" {
 				d.Type = ov.DeviceType

+ 8 - 0
server-go/internal/adapters/live.go

@@ -4053,8 +4053,10 @@ func (l *Live) buildDevices(polled map[string]*routerPolled, wanPort string) []D
 			switch {
 			case lease.Hostname != "":
 				d.Name = lease.Hostname
+				d.NameSource = "dhcp"
 			case hasRes && res.Name != "":
 				d.Name = res.Name
+				d.NameSource = "reservation"
 			default:
 				d.Name = mac
 			}
@@ -4074,6 +4076,7 @@ func (l *Live) buildDevices(polled map[string]*routerPolled, wanPort string) []D
 			if hasRes {
 				if res.Name != "" {
 					d.Name = res.Name
+					d.NameSource = "reservation"
 				}
 				d.IP = res.IP
 			}
@@ -4083,6 +4086,7 @@ func (l *Live) buildDevices(polled map[string]*routerPolled, wanPort string) []D
 				d.IP = gl.IP
 				if gl.Hostname != "" {
 					d.Name = gl.Hostname
+					d.NameSource = "glinet"
 				}
 			}
 		}
@@ -4100,6 +4104,7 @@ func (l *Live) buildDevices(polled map[string]*routerPolled, wanPort string) []D
 		// alias (Name != MAC) el dispositivo deja de ser "desconocido".
 		if alias, ok := knownMacs[mac]; ok && alias != "" {
 			d.Name = alias
+			d.NameSource = "known_mac"
 			d.namePinned = true
 		}
 		// issue #437/#797: overrides manuales (icono, nombre) se aplican sobre
@@ -4112,6 +4117,7 @@ func (l *Live) buildDevices(polled map[string]*routerPolled, wanPort string) []D
 			if ov.Name != "" {
 				d.Name = ov.Name
 				d.NameOverride = ov.Name
+				d.NameSource = "manual"
 				d.namePinned = true
 			}
 		}
@@ -4138,6 +4144,7 @@ func (l *Live) buildDevices(polled map[string]*routerPolled, wanPort string) []D
 				if !d.namePinned && !isGeneratedDeviceName(host) && (d.Name == mac || isGeneratedDeviceName(d.Name)) {
 					previousName := d.Name
 					d.Name = host
+					d.NameSource = "mdns"
 					// The first guess only had the MAC or a placeholder. Let the
 					// mDNS hostname feed the same rules without replacing other evidence.
 					if d.Type == "desconocido" || isGeneratedDeviceName(previousName) {
@@ -4150,6 +4157,7 @@ func (l *Live) buildDevices(polled map[string]*routerPolled, wanPort string) []D
 		if d.Name == mac && d.IP != "" {
 			if host := l.rdns.Name(d.IP); host != "" {
 				d.Name = host
+				d.NameSource = "rdns"
 				// The type above was guessed from the MAC, which says
 				// nothing. Guess it again now that there is a hostname.
 				d.Type = GuessDeviceType(d.Name, d.Manufacturer, vendorClass, clientID, lldpCapsByMac[mac])

+ 46 - 35
server-go/internal/adapters/mdns_placeholder_test.go

@@ -19,42 +19,47 @@ func TestBuildDevicesMdnsReplacesOnlyUnpinnedPlaceholders(t *testing.T) {
 		overrideType    string
 		wantName        string
 		wantType        string
+		wantSource      string
 	}{
 		{
-			name:     "mDNS name replaces an Android DHCP placeholder",
-			mac:      "02:00:00:00:10:01",
-			ip:       "192.0.2.101",
-			dhcpName: "android-7F3A9C2D",
-			mdnsName: "iPhone-de-Nacho",
-			wantName: "iPhone-de-Nacho",
-			wantType: "movil",
+			name:       "mDNS name replaces an Android DHCP placeholder",
+			mac:        "02:00:00:00:10:01",
+			ip:         "192.0.2.101",
+			dhcpName:   "android-7F3A9C2D",
+			mdnsName:   "iPhone-de-Nacho",
+			wantName:   "iPhone-de-Nacho",
+			wantType:   "movil",
+			wantSource: "mdns",
 		},
 		{
-			name:     "mDNS name and type replace an Android DHCP placeholder",
-			mac:      "02:00:00:00:10:02",
-			ip:       "192.0.2.102",
-			dhcpName: "android-7F3A9C2D",
-			mdnsName: "roomba-cocina",
-			wantName: "roomba-cocina",
-			wantType: "aspirador",
+			name:       "mDNS name and type replace an Android DHCP placeholder",
+			mac:        "02:00:00:00:10:02",
+			ip:         "192.0.2.102",
+			dhcpName:   "android-7F3A9C2D",
+			mdnsName:   "roomba-cocina",
+			wantName:   "roomba-cocina",
+			wantType:   "aspirador",
+			wantSource: "mdns",
 		},
 		{
-			name:     "meaningful DHCP hostname stays",
-			mac:      "02:00:00:00:10:03",
-			ip:       "192.0.2.103",
-			dhcpName: "laptop-ana",
-			mdnsName: "roomba-cocina",
-			wantName: "laptop-ana",
-			wantType: "portatil",
+			name:       "meaningful DHCP hostname stays",
+			mac:        "02:00:00:00:10:03",
+			ip:         "192.0.2.103",
+			dhcpName:   "laptop-ana",
+			mdnsName:   "roomba-cocina",
+			wantName:   "laptop-ana",
+			wantType:   "portatil",
+			wantSource: "dhcp",
 		},
 		{
-			name:     "mDNS placeholder cannot replace a meaningful DHCP hostname",
-			mac:      "02:00:00:00:10:04",
-			ip:       "192.0.2.104",
-			dhcpName: "laptop-ana",
-			mdnsName: "android-7F3A9C2D",
-			wantName: "laptop-ana",
-			wantType: "portatil",
+			name:       "mDNS placeholder cannot replace a meaningful DHCP hostname",
+			mac:        "02:00:00:00:10:04",
+			ip:         "192.0.2.104",
+			dhcpName:   "laptop-ana",
+			mdnsName:   "android-7F3A9C2D",
+			wantName:   "laptop-ana",
+			wantType:   "portatil",
+			wantSource: "dhcp",
 		},
 		{
 			name:            "DHCP reservation name stays",
@@ -64,15 +69,17 @@ func TestBuildDevicesMdnsReplacesOnlyUnpinnedPlaceholders(t *testing.T) {
 			reservationName: "Reserva Ana",
 			wantName:        "Reserva Ana",
 			wantType:        "desconocido",
+			wantSource:      "reservation",
 		},
 		{
-			name:      "known MAC alias stays",
-			mac:       "02:00:00:00:10:06",
-			ip:        "192.0.2.106",
-			mdnsName:  "roomba-cocina",
-			aliasName: "Alias Ana",
-			wantName:  "Alias Ana",
-			wantType:  "desconocido",
+			name:       "known MAC alias stays",
+			mac:        "02:00:00:00:10:06",
+			ip:         "192.0.2.106",
+			mdnsName:   "roomba-cocina",
+			aliasName:  "Alias Ana",
+			wantName:   "Alias Ana",
+			wantType:   "desconocido",
+			wantSource: "known_mac",
 		},
 		{
 			name:         "manual name and type stay",
@@ -84,6 +91,7 @@ func TestBuildDevicesMdnsReplacesOnlyUnpinnedPlaceholders(t *testing.T) {
 			overrideType: "consola",
 			wantName:     "Consola salón",
 			wantType:     "consola",
+			wantSource:   "manual",
 		},
 	}
 
@@ -140,6 +148,9 @@ func TestBuildDevicesMdnsReplacesOnlyUnpinnedPlaceholders(t *testing.T) {
 				if d.Type != tt.wantType {
 					t.Errorf("type = %q, want %q", d.Type, tt.wantType)
 				}
+				if d.NameSource != tt.wantSource {
+					t.Errorf("nameSource = %q, want %q", d.NameSource, tt.wantSource)
+				}
 				return
 			}
 			t.Fatalf("device %s not found", tt.mac)

+ 70 - 0
server-go/internal/adapters/name_source_test.go

@@ -0,0 +1,70 @@
+package adapters
+
+import (
+	"path/filepath"
+	"testing"
+
+	"github.com/gnacho/netpulse/agent/probe"
+	"github.com/gnacho/netpulse/server-go/internal/db"
+)
+
+func TestBuildDevicesNameSourceGLiNet(t *testing.T) {
+	cfg := RouterConfig{ID: "gateway", Host: "192.0.2.1", Name: "glinet", IsGateway: true, AgentOnly: true}
+	l := NewLive(nil, nil, []RouterConfig{cfg}, nil)
+	payload := &probe.Payload{
+		Router: "gateway", Ts: 1, Version: "2.54.0",
+		Data: probe.PayloadData{
+			FDB: &probe.FDBData{MACs: map[string]string{"02:00:00:00:20:01": "lan2"}},
+			DHCP: &probe.DHCPData{GlClients: []probe.DhcpLease{{
+				MAC: "02:00:00:00:20:01", IP: "192.0.2.201", Hostname: "gl-client",
+			}}},
+		},
+	}
+	devices := l.buildDevices(map[string]*routerPolled{"gateway": l.polledFromAgent(cfg, payload)}, "")
+	if len(devices) != 1 || devices[0].Name != "gl-client" || devices[0].NameSource != "glinet" {
+		t.Fatalf("devices = %+v, want gl-client with glinet source", devices)
+	}
+}
+
+func TestNameSourceSurvivesRetentionAndRestart(t *testing.T) {
+	d := openLiveTestDB(t)
+	cfg := RouterConfig{ID: "gateway", Host: "192.0.2.1", Name: "openwrt", IsGateway: true, AgentOnly: true}
+	l := NewLive(nil, d, []RouterConfig{cfg}, nil)
+	const mac = "02:00:00:00:10:09"
+	const ip = "192.0.2.109"
+
+	first := l.buildDevices(map[string]*routerPolled{"gateway": l.polledFromAgent(cfg, mdnsPlaceholderPayload(mac, ip, "android-7F3A9C2D", "roomba-cocina", true))}, "")
+	l.noteDevicesSeen(first, 1000)
+	l.applyDeviceSeen(first)
+	if len(first) != 1 || first[0].NameSource != "mdns" {
+		t.Fatalf("first cycle nameSource = %+v, want mdns", first)
+	}
+
+	second := l.buildDevices(map[string]*routerPolled{"gateway": l.polledFromAgent(cfg, mdnsPlaceholderPayload(mac, ip, "android-7F3A9C2D", "", false))}, "")
+	l.noteDevicesSeen(second, 2000)
+	l.applyDeviceSeen(second)
+	if len(second) != 1 || second[0].NameSource != "mdns" {
+		t.Fatalf("retained nameSource = %+v, want mdns", second)
+	}
+	var stored string
+	if err := d.QueryRow("SELECT name_source FROM device_seen WHERE mac = ?", mac).Scan(&stored); err != nil {
+		t.Fatal(err)
+	}
+	if stored != "mdns" {
+		t.Fatalf("stored name_source = %q, want mdns", stored)
+	}
+
+	if err := d.Close(); err != nil {
+		t.Fatalf("close before reopen: %v", err)
+	}
+	reopened, err := db.Open(filepath.Dir(d.Path))
+	if err != nil {
+		t.Fatalf("reopen: %v", err)
+	}
+	defer reopened.Close()
+	liveAfterRestart := NewLive(nil, reopened, []RouterConfig{cfg}, nil)
+	ghosts := liveAfterRestart.ghostDevices(nil)
+	if len(ghosts) != 1 || ghosts[0].NameSource != "mdns" {
+		t.Fatalf("after restart = %+v, want one ghost with mdns source", ghosts)
+	}
+}

+ 6 - 0
server-go/internal/adapters/rdns_builddevices_test.go

@@ -50,6 +50,9 @@ func TestBuildDevicesNamesFromReverseDNS(t *testing.T) {
 	if got := devs["5C:E2:8C:00:00:04"].Name; got != "switch-garage" {
 		t.Fatalf("static host: got %q, want switch-garage", got)
 	}
+	if got := devs["5C:E2:8C:00:00:04"].NameSource; got != "rdns" {
+		t.Fatalf("static host nameSource: got %q, want rdns", got)
+	}
 	// The type is guessed again after the PTR name lands: "switch-garage"
 	// matches the switch rule, while a bare MAC can only be "desconocido".
 	if got := devs["5C:E2:8C:00:00:04"].Type; got != "switch" {
@@ -58,6 +61,9 @@ func TestBuildDevicesNamesFromReverseDNS(t *testing.T) {
 	if got := devs["AA:BB:CC:00:00:70"].Name; got != "laptop" {
 		t.Fatalf("leased host: got %q, want laptop", got)
 	}
+	if got := devs["AA:BB:CC:00:00:70"].NameSource; got != "dhcp" {
+		t.Fatalf("leased host nameSource: got %q, want dhcp", got)
+	}
 	if n := f.count("172.16.16.70"); n != 0 {
 		t.Fatalf("named device was looked up %d times", n)
 	}

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

@@ -333,8 +333,10 @@ type DeviceTotals struct {
 // (SPEC §2.9); el resto solo existe en demo (ausentes en live).
 // SignalDbm es null cuando no hay medida (nunca ausente).
 type Device struct {
-	ID           string `json:"id"`
-	Name         string `json:"name"`
+	ID   string `json:"id"`
+	Name string `json:"name"`
+	// NameSource: evidencia que produjo el nombre visible. Vacío = desconocida.
+	NameSource   string `json:"nameSource,omitempty"`
 	Type         string `json:"type"`
 	Manufacturer string `json:"manufacturer"`
 	IP           string `json:"ip"`

+ 2 - 0
server-go/internal/db/db.go

@@ -718,6 +718,8 @@ func Open(dir string, opts ...OpenOption) (*DB, error) {
 	migrate(sqldb, "routers", "snmp_enabled", "ALTER TABLE routers ADD COLUMN snmp_enabled INTEGER NOT NULL DEFAULT 0")
 	// #1145: último nombre conocido del cliente (retención indefinida).
 	migrate(sqldb, "device_seen", "name", "ALTER TABLE device_seen ADD COLUMN name TEXT NOT NULL DEFAULT ''")
+	// #2163: evidencia que produjo el nombre elegido; vacía en filas antiguas.
+	migrate(sqldb, "device_seen", "name_source", "ALTER TABLE device_seen ADD COLUMN name_source TEXT NOT NULL DEFAULT ''")
 	// #1151: última IP conocida (los fantasmas la conservan para la lista y
 	// las sugerencias de enlace).
 	migrate(sqldb, "device_seen", "ip", "ALTER TABLE device_seen ADD COLUMN ip TEXT NOT NULL DEFAULT ''")