Simon Tasker

Games, apps, and the occasional detour.

App Dev · · 4 min read

NetLay: One app, several sites, no leaks

A tool built for one network had quietly assumed there was only one, so a lease imported at one site taught a printer at another site the wrong MAC address.

10.9.9.9 is not a device#

Private address ranges repeat. That sentence is obvious to anybody who has worked on more than one network, and the whole of this post is what happens when an application has not internalised it.

10.9.9.9 is a laptop at one site and a printer at another. Both are correct. Both are in NetLay, on different layouts. And everything I built in post twenty four, which identifies a device by its MAC and looks up where that MAC has been seen, was matching on the address alone.

Four ways the sites leaked.#

All of these were reproduced, which is the only reason I believe them.

A DHCP lease file imported for one site taught a printer at the other site the laptop's MAC address, because the lease said that address belongs to that MAC and nothing recorded which building the lease came from.

The laptop running NetLay travels between home and work, so its own ARP table is a list of things it has spoken to recently at whichever site it is currently in. Those sightings were applied to whichever map had a matching address, which is to say the wrong one, half the time.

A discovery scan of 10.0.10.5 at one site overwrote the other site's row for the same address, and then the host helpfully showed up as already being on the map, which it was, just not that one.

And VLAN names were global. Importing the second site's VLAN 10, which they call Voice, silently kept the first site's name for it, which is Staff. Same number, different meaning, one name.

One rule fixed most of it.#

Every sighting now carries the site it came from, whenever the source knows. A lease knows which layout it was imported for. A scan knows which layout it ran against. An ARP cache pulled over SNMP from a switch or a router belongs to whichever layout that device is on.

That leaves one source with no site attached, which is the ARP table of the machine NetLay is running on. For those, a sighting only counts for a layout whose address plan contains that address.

Which is the second time the subnet work from post twenty seven has paid for itself, in a place I did not build it for. The address plan knows which ranges belong to which site, so it can answer a question the ARP table cannot, which is where this sighting happened.

Discovered hosts became one row per layout and address, with the next scan adopting any old row. VLAN numbers stay shared across the system, because a VLAN number means something, but names and colours are per layout now, with a line in the VLAN window telling you when a name is local and what the shared one is.

Upgrading a database that somebody is using.#

There is a unique index in the way of all this, and SQLite cannot drop a constraint in place, so the table has to be rebuilt. On a database with real data in it, on a machine somebody else might be using.

So: try it on a copy of the real database first and check every row survived, that the integrity check passes, and that running it twice is harmless.

That rehearsal found something I would otherwise have hit in production. The upgrade assumed every table had already been registered by the web application having imported its models, which is true when the app starts normally and not true when the upgrade is run on its own. It registers them itself now.

Then for real, in order: the start up backup from the last post, the upgrade, the integrity check. Which is the first time that backup has been load bearing rather than theoretical, five days after I added it.

Twenty smaller ones.#

The second half of this phase was a list of ordinary bugs, each now with a test that reproduces it.

A single IPv6 subnet in an address plan stopped the map opening altogether, because Python will not sort IPv4 and IPv6 networks in the same list.

Around three percent of MAC addresses read over SNMP vanished, because the raw bytes were decoded as text and back again, and some of them are not valid text. The fix is to keep the original bytes alongside the readable version, which is a lesson about binary data wearing a string costume.

A ping now request during a poll was dropped, because a flag was cleared after the work rather than before it.

The importer decided an uplink already existed if any link anywhere used the same port number.

Renaming an SSID renamed clients on every layout. The tracker and the map disagreed about a virtual machine's VLAN. Windows lease times were read as if they were UTC. And HPE servers were still being typed as PCs, which is the bug I found while commenting the code three posts ago and finally fixed.

Next time, the performance phase, and the eight seconds that should have been a tenth of a second.