Networking [Tab]
31 min
1) Network Adapters (grid)
UI columns: Adapter Name • Status • MAC Address • IP Assignment (DHCP/Static) • IPv4 Address • IPv6 Address • VLAN ID • Connected To
1.1 Data model (where to store)
- Primary table: device_network_adapter for adapters and IP config (arrays), DHCP metadata, link state, speed/duplex, type, VLAN, etc.
- To show “Connected To” (switch/port), use network_connection. When a switch is the discovery vantage point, its physical network_device_port (local) can point to a remote endpoint NIC (your adapter) via remote_network_adapter_id. UI can then display the switch name/port.
- If you also manage switch ports, the local side lives in network_device_port. Joins flow: endpoint NIC → network_connection.remote_network_adapter_id → network_device_port (local) → switch device.
1.2 Collection (how to gather)
A) Endpoint agent (Windows / Linux / macOS)
- Adapter inventory & link state
- Windows: Get-NetAdapter, Get-NetAdapterAdvancedProperty, Get-NetIPAddress, Get-DnsClientServerAddress, Get-NetIPConfiguration.
- Linux: ip link show, ip -j addr, ethtool <iface> (speed/duplex), /proc/net/wireless (wifi), NetworkManager (nmcli -g), or systemd-networkd files.
- macOS: networksetup -listallhardwareports, ifconfig -a, ipconfig getpacket <iface> (DHCP), route -n get default (gateway), scutil --dns (DNS).
- DHCP vs Static (for “IP Assignment”):
- Windows: Win32_NetworkAdapterConfiguration.DHCPEnabled or Get-NetIPInterface and Dhcp state.
- Linux: detect via NM/systemd config (e.g., /etc/NetworkManager/system-connections/*.nmconnection, /etc/systemd/network/*.network) or presence of active dhclient lease in /var/lib/dhcp*/.
- macOS: networksetup -getinfo <service> shows “DHCP Configuration” vs “Manual”.
- VLAN ID:
- Windows: Get-NetAdapterAdvancedProperty -DisplayName "VLAN ID" or *PriorityVLANTag (varies by NIC driver).
- Linux: /proc/net/vlan/config, ip -d link show (look for vlan id <n>).
- macOS: VLANs are configured as separate services; list via networksetup -listVLANs.
- IPv6: ensure you collect both global and link-local; store all in ip_address_v6[].
Normalize into device_network_adapter:
- name, description, mac_address, status (Up/Down/Disabled), interface_type (Ethernet/Wi-Fi/Loopback/Tunnel), speed_mbps, duplex_mode, physical_adapter flags; arrays for ip_address_v4, ip_address_v6, subnet_mask_v4, subnet_mask_v6, default_gateway_v4, default_gateway_v6, dns_server[], wins_server[]; plus DHCP fields and vlan_id.
- Record source precedence in last_seen_source (Agent vs Intune) for merge logic.
B) Network probe (LLDP/CDP/MAC tables) for “Connected To”
- Poll access switches/edges over SNMP and collect:
- LLDP/Cisco CDP neighbor tables (remote sysName, portId, platform, management IP, VLAN).
- MAC address tables (bridge FDB) to map endpoint MAC → switch port when LLDP isn’t present.
- Build/refresh network_device_port for each physical port discovered. Then write network_connection rows linking local network_device_port.id to remote endpoint (remote_device_id and/or remote_network_adapter_id) by MAC/IP correlation.
1.3 Delta / retention
- For adapters: upsert by (device_id, mac_address, name) heuristic; mark unchanged ones as active; hide stale when not observed for N days; keep updated_at current on change.
- For connections: update last_seen_at per discovery; if not seen after X cycles, set status='Inactive' but retain first_seen_at for audit.
1.4 Rendering (example query plan)
- Base: SELECT * FROM device_network_adapter WHERE device_id = :id ORDER BY name;
- Connected To: for each adapter, SELECT nd.device_id AS switch_id, d.name AS switch_name, nd.port_name FROM network_connection nc JOIN network_device_port nd ON nd.id = nc.local_port_id JOIN device d ON d.id = nd.device_id WHERE nc.remote_network_adapter_id = :adapter_id AND nc.status='Active' ORDER BY nc.last_seen_at DESC LIMIT 1;
2) Open Ports (grid)
UI columns: Port • Protocol • Local Address • Process Name • Status
2.1 Data model
- Use device_open_port for listeners and active connections (store local/remote, state, owning PID, service banner/version). Index by device_id and (optionally) process_id.
- Link to running processes via device_process (per-snapshot process metadata).
2.2 Collection
A) Endpoint agent
- Windows:Get-NetTCPConnection -State Listen,Established -OwningProcess, Get-NetUDPEndpoint, fall back to netstat -abno; map OwningProcess → process snapshot.
- Linux: ss -tunlp (listeners) and ss -tuno (connections); optionally lsof -nPi.
- macOS:lsof -nPiTCP -sTCP:LISTEN, lsof -nPiUDP, or netstat -vanp tcp/udp.
- Service banner (optional): short, safe banner grabs for common ports (e.g., tcp/22, tcp/80/443) with low timeouts.
Normalize into device_open_port:
- local_address, port, protocol, state (TCP only), optional remote_address/remote_port for established connections, process_id, service_name, service_version, and timestamps first_seen_at, last_seen_at. Use active_in_scan as a working flag during each run; set active=false for ports not seen after grace.
B) Process table to show “Process Name”
- Take a process snapshot right before or after the port scan. Insert/update device_process with (device_id, pid, start_time) uniqueness to avoid dupes.
2.3 Delta / retention
- If a port was previously seen, update last_seen_at; if missing in a new scan, do not immediately delete—flip active after N missed scans. Indexes already support fast lookups.
2.4 Rendering
- Show only active rows sorted by (protocol, port). Join (optional) to most recent process snapshot by device_id+pid.
3) Static Routes (grid)
UI columns: Destination • Netmask (prefix) • Gateway • Interface • Metric
3.1 Data model
- Use device_static_route with destination_cidr, gateway_ip, optional interface_name/index, metric, persistent, and last_seen_at. Unique key defends against dupes per interface.
3.2 Collection
- Windows:Get-NetRoute -PolicyStore ActiveStore | Where-Object {$_.RouteMetric -ne $null}; filter RouteMetric, DestinationPrefix, InterfaceAlias/Index, NextHop.
- Linux: ip route show + ip -j route for JSON; capture metric, dev, proto static.
- macOS:netstat -nr (or route -n get) and parse; persistent routes stored in /Library/Preferences/SystemConfiguration/preferences.plist or MDM profiles.
- Map device interface name/index to your adapter record when possible.
3.3 Delta / retention
- Upsert by (device_id, destination_cidr, gateway_ip, interface_index); refresh last_seen_at; mark active=false when not observed. Index on device_id supports tab load.
4) Directory & Cloud Identity (right rail)
UI fields:
AD Domain • AD Joined • AD Last Contact • Entra ID Tenant • Entra ID Joined • Intune Managed • Intune Last Sync
4.1 Data model & mapping
- AD Domain / AD Joined / AD Last Contact:
- Link the device to an ad_computer row (DN, last_logon_timestamp, etc.) and its ad_domain (domain_name). “AD Joined = Yes” if an ad_computer exists for the device; “AD Last Contact” = ad_computer.last_logon_timestamp (safest replicated timestamp).
- Entra ID Tenant:
- Use your Microsoft 365/Entra integration instance tenant_id and primary_domain for display (e.g., example.onmicrosoft.com).
- Entra ID Joined (join type):
- If you already added a table/column for device join state (e.g., azure_ad_device.join_type or device.azure_ad_join_type), populate from Graph/Intune (Hybrid/AzureADJoined/AzureADRegistered). If not present, add one (recommended).
- Intune Managed / Intune Last Sync:
- A device is “Intune Managed = Yes” if device.intune_device_id is set; “Intune Last Sync” comes from device.intune_last_checkin_at.
4.2 Collection
A) AD (on-prem)
- Windows agents can report AD join (domain membership) via Win32_ComputerSystem.Domain, dsregcmd /status (hybrid hints), plus computer DN. Backfill and keep authoritative directory attributes via LDAP reads on your directory connector.
B) Entra ID / Intune (cloud)
- Use Microsoft Graph:
- Intune device properties (check-in time, compliance, join type).
- Directory tenant info (primary domain). Store tenant metadata in integration_instance (already modeled).
5) Internet Connectivity (right rail)
UI fields: External IP Address • Last Public IP Check
5.1 Data model
- Use device.external_ip_address for the current external IP. Add device.external_ip_last_check_at TIMESTAMPTZ (if not already present) to drive the “Last Public IP Check” timestamp. (You already have device.external_ip_address.)
5.2 Collection
- From each agent, hit a tiny, redundant set of endpoints (e.g., anycast STUN or a simple HTTPS “what is my IP” behind your domain).
- Record the detected IP and the timestamp as the check time; debounce updates (only write when value changes or after a long interval) to avoid churn for NAT-shared IPs.
- For multi-NIC servers, this is outbound NAT IP—document that the value is site-level in many environments. Optionally also compute a location/site level external IP rollup.
6) Source-of-truth, merge rules & schedules
- Per-field precedence: In general: Agent > Intune > Directory > Probes for adapter details; Probes are authoritative for “Connected To” (switch port) and VLAN on the switch side; AD is authoritative for AD presence/last logon; Intune is authoritative for MDM/Entra join. Persist most-recent last_seen_source for adapters.
- Frequencies (defaults):
- Adapters & routes: every 4–8 hours on servers; 8–24 hours on workstations; on boot and NIC change via event hooks.
- Open ports quick scan: every 2–4 hours (servers) / 8–24 hours (workstations). Banner grabs are opt-in and low-rate.
- Switch discovery via probes: every 1–4 hours (or trap-driven).
- Cloud (Graph/Intune): every 2–6 hours for device & tenant metadata; AD LDAP every 4 hours.
7) Data validation & normalization
- MAC canonicalization: store lowercase, colon-less or colon-normalized consistently in device_network_adapter.mac_address; index exists for lookups.
- IP lists: always store all addresses in arrays; pick the “primary” for display as the first routable non-link-local entry.
- VLAN: prefer switch-reported access VLAN; if endpoint reports trunk/VLANs, show adapter’s configured VLAN in the grid and (optionally) show the switch-port VLAN on hover (“Connected To”).
- Routes: compute human “Netmask” column from destination_cidr prefix when rendering.
8) Security & performance
- Least privilege:
- Windows agent queries use standard WMI/PowerShell; no admin required for most reads (except some NIC advanced props).
- Linux/macOS stick to read-only commands; avoid sudo where possible.
- SNMP read-only for probes; rate-limit walks; use LLDP/CDP tables directly to minimize load.
- PII & secrets: never store DHCP options with sensitive data; banner grabs: redact tokens; don’t persist payloads beyond service_name/service_version.
- Resiliency: exponential backoff on Graph/APIs; cache tenant metadata; concurrent scans are bounded.
9) API & UI contracts
- Adapters endpointGET /devices/:id/network/adapters returns an array of adapters plus a nested connectedTo (if found): { switchDeviceId, switchName, portName, lastSeenAt }. Backed by device_network_adapter + network_connection.
- Open ports endpoint GET /devices/:id/network/open-ports supports ?onlyActive=true and returns process names by best-effort join to the latest device_process snapshot.
- Static routes endpointGET /devices/:id/network/static-routes lists active routes with destination, prefix, gateway, interface, metric.
- Identity panel endpointGET /devices/:id/identity-summary composes from AD (ad_domain.domain_name, ad_computer.last_logon_timestamp), Intune (device.intune_device_id, device.intune_last_checkin_at), Entra tenant (integration_instance.primary_domain), and your Entra join field/table.
10) Ingestion/delta algorithms (pseudo)
- Adapters: upsert each observed adapter; after a scan, mark any rows for the device not seen as active=false (soft-delete). Keep history via updated_at.
- Open ports: during a run, set active_in_scan=true for each seen line; after the run, flip rows with active_in_scan=false to active=false. Update last_seen_at.
- Static routes: upsert and bump last_seen_at; mark missing as inactive after grace.
- Connections: if a probe sees the same remote NIC on a different port, update local_port_id and last_seen_at; keep first_seen_at for audit.
11) Edge cases
- Multiple IPs per NIC: display first usable; expose all in details. (Your arrays already model this.)
- No LLDP/CDP: fall back to MAC-table correlation; if multiple ports claim the MAC (e.g., port-security err), mark “Connected To” ambiguous.
- Teamed/bonded NICs: present team as a logical adapter with member MACs in details; on Linux, interpret bond0 and member slaves.
- Virtual NICs: set physical_adapter=false; populate virtual_switch_name if known (e.g., Hyper-V/ESXi).
- UDP: no connection “state”; show “Listening” if bound locally.
12) Testing & acceptance criteria
- Adapters:
- Unplug/plug cable or disable/enable NIC and confirm status updates within one scan cycle.
- Assign static IP → agent reports dhcp_enabled=false; switch to DHCP → true.
- Create VLAN sub-interface on Linux/macOS and confirm vlan_id mapping.
- Open ports:
- Start/stop a listener (nc -l 0.0.0.0 8888) and verify rows appear/disappear with correct state and process name.
- Ensure active_in_scan flip works when port disappears.
- Routes:
- Add/delete a static route and validate upsert + last_seen_at and inactive marking.
- Connected To:
- Move patch from port A to port B and confirm network_connection.local_port_id updates and UI reflects the new port with a fresh last_seen_at.
- Identity panel:
- Disable AD account and confirm last_logon_timestamp no longer advances; Intune unenroll test shows intune_device_id cleared and managed flag flips.
- Internet connectivity:
- Rotate NAT IP (test lab) and verify device.external_ip_address changes and “Last Public IP Check” updates when the value changes.
13) What you may still need to add (small deltas)
- Entra join type field (if missing): add device.azure_ad_join_type VARCHAR(20) or a small azure_ad_device table to track device ↔ directory object & join state (Hybrid/AADJoined/AADRegistered).
- Last public IP check (if missing): add device.external_ip_last_check_at TIMESTAMPTZ to support the timestamp displayed in the right rail.
If you want, I can follow up with concrete agent scripts/commands per OS and a set of SQL views for the tab to make the UI wiring trivial.