The UniFi Black Hole: My Switch Keeps Getting Confused About Which Device It's Talking To


estimated read time: 10 minutes

The UniFi Black Hole: My Switch Keeps Getting Confused About Which Device It's Talking To

Back in April I wrote a post telling you to move inter-VLAN routing onto your UniFi switch. It took my PC to NAS transfers from about 1.2Gbps to 2.3Gbps and I was very pleased with myself.

This is the post about what that has cost me since.

Seventeen times in the last five weeks, my USW Pro Max 16 PoE has picked one machine on the network and cut it off from everything outside its own VLAN. No internet, no DNS, nothing. The longest ran for over 2 days before I noticed. We've taken to calling it the black hole, because traffic for that one machine goes in and never comes out. I haven't solved it. What I have got is a fairly thick case file, a couple of fixes that work most of the time, and a theory I can't prove yet. So this is part one.


Everything was green

The first victim was the VM that runs my GitHub Actions runners. One morning in October the builds just stopped. The VM was up. I could SSH to it from another machine on the same VLAN. Prometheus was scraping it quite happily. The UniFi controller showed it connected, right port, right IP, right MAC.

It just had no internet, and nothing on another VLAN could reach it. It could ping everything on its own VLAN and nothing beyond it.

In true IT cookbook 101, I turned it off-and-on again. And.. nothing. In the end I added a second IP address to it while I was poking about, and it sprang back to life. I didn't understand why, so I wrote it down and moved on.

Soon after, the whack-a-mole started. First Home Assistant, then Kubernetes, in some cases minutes later, in others days apart. Each one a different machine, each one with every health check I own showing green. That's the nasty part of this fault. All my monitoring sat inside the same VLAN as the victims, and inside the VLAN everything works.

Catching it in the act

On the sixth one I finally ran a packet capture on the Proxmox host while it was broken, and that changed the whole picture.

What I discovered was, the traffic hadn't been dropped. It was being delivered to entirely the wrong machine.

Every packet the switch routed towards the runner was leaving with Home Assistant's MAC address on it. The runner sent a DNS query out, the reply came back through the switch, and the switch handed it to Home Assistant, which quite reasonably threw it away. From the runner's side it looked like shouting into a void.

In plain English, the switch's contacts had been corrupted. The address it had on file for that one machine was wrong. It knows which machine has which IP address, and it shows you the right answer if you ask. But the part of the switch that actually forwards packets at speed keeps its own copy of that information, and for one machine that copy was wrong.

I checked the obvious alternative, that something on my network was lying to the switch. During one outage the runner asked the switch "who has the gateway?" sixteen times, with its correct MAC on every request, and the switch answered every single one. So the switch was being told the right answer over and over, and carried on sending the traffic somewhere else.

The wrong address isn't always the same either. So far it's been Home Assistant, a Netgear switch on a completely different port, a phone on the Wi-Fi, a Raspberry Pi, and on one occasion 00:00:00:00:00:00, which isn't anybody.

What fixes it (sometimes)

This is the bit you probably searched for, so here's the scoreboard. I'm using made up addresses throughout.

  1. Rebooting the victim. Never works.

  2. Re-announcing the victim's own IP with a gratuitous ARP. Never works.

  3. A gratuitous ARP for a new, unused IP, sent from the victim's MAC. Worked the first five times. It has failed every time since the start of November.

  4. Deleting the victim's entry from the switch's neighbour table. Five out of six. You need SSH on the switch for this one:

    ip neigh del 10.0.5.50 dev intfv1
    

    The switch asks for the address again within milliseconds, so it doesn't cost anything.

  5. Giving the victim a temporary second IP and pinging the gateway from it. Three out of three so far, including the one time number 4 failed:

    sudo ip addr add 10.0.5.249/32 dev eth0
    ping -c3 -I 10.0.5.249 10.0.5.1
    sudo ip addr del 10.0.5.249/32 dev eth0
    
  6. Rebooting the switch. Always works. It also came back 49 hours later.

There's a catch with all of them. Five times now, fixing one machine has been followed within about ten minutes by a different machine going down. Twice the new victim was the very machine whose MAC address the first victim's traffic had been going to. Remember that, because it matters later.

What it isn't

I've spent a lot of evenings being wrong about this, so I may as well save you some.

Building the case

I opened a support case with Ubiquiti in October. To be fair to them, the first person I spoke to understood the problem straight away and escalated it. The escalation team asked for a live capture during the next occurrence, which was reasonable, so I wrote a script to grab everything in one go before fixing anything. They asked me to try the Early Access firmware, which I did. It came back. The last update says it has been forwarded to the team for further investigation.

In the meantime I needed to actually know when it was happening, because finding out from a broken build two days later was getting old. The trick is to test every machine twice: once from inside its own VLAN, and once from another VLAN so the traffic has to be routed by the switch. If the routed test fails and the local one passes, an alert goes off and I go and look. A machine that's simply switched off fails both, so it stays quiet. On its own that isn't a diagnosis, mind. A firewall rule or a missing route would look exactly the same from the outside, so it's still the packet capture showing the wrong MAC address that tells me it's the black hole and not something I've broken myself.

I also ran an experiment I'm less proud of. In the middle of all this I moved my main VLAN onto the switch as well, for the speed. Ten days later the switch black-holed my desktop, along with the AI assistant session running on it, which had been helping me investigate and went deaf mid-sentence. That VLAN went back to the Dream Machine the same night.

I suppose the silver lining here was, the PC's never been black holed since, which points to the issue residing only on networks that are routed through the switch.

That started an argument which is still going. I think this is a layer 2 problem. The AI thinks it's layer 3. There is a bet.

Looking inside the switch

This week we found something I haven't seen written up anywhere. If you SSH to the switch, there's a diagnostic shell from the chip manufacturer sitting on it:

/usr/share/librtk/diag

The chip is a Realtek RTL93xx, and this shell lets you read the tables the hardware is actually forwarding from, rather than what the software believes:

l3 dump host ip from begin to end
l3 dump next-hop from begin to end

The first one shows that every IP the switch routes to points at a numbered record. The second shows which MAC address each numbered record holds. That numbered record is the thing that goes wrong.

Here's what I found, on a day when nothing was broken:

All of those oddities belong to Kubernetes nodes that hold MetalLB addresses, which are IPs that hop from one machine to another by design.

So the working theory goes like this. When an IP address moves to a different machine, the switch's software loses track of which record belongs to whom. Sooner or later two machines end up sharing one, and whoever wrote to it last wins. That would explain why the wrong MAC nearly always belongs to a real device, and why fixing one machine breaks another: the fix rewrites the shared record, and the other owner loses. It doesn't explain the time the address was all zeros. My guess is a record that had been emptied and not yet reused, but that is a guess.

I want to be clear that this is a theory. I've shown the bookkeeping is a mess. I haven't shown that the mess is what causes the fault. MetalLB activity lines up with about half of the recent occurrences, which is enough to be interesting and nowhere near enough to be proof.

As for the bet, at the moment it's looking like an annoying draw. The chip ties these records to its layer 2 table, which is my point. Only routed traffic ever reads them, which is the AI's.

Where it stands

Nobody else seems to have written this one up. The closest I've found is a forum thread from last year about the bigger Pro Max switches having layer 3 trouble, which support first put down to hardware and then fixed in firmware. Different symptoms, same family.

What happens next:

  1. The next time it breaks, I dump those two tables before fixing anything. If the victim's record holds the wrong MAC while the switch's own ARP table holds the right one, that's the proof, and it goes straight to Ubiquiti.
  2. I have to decide whether to move routing back to the Dream Machine and give up the speed I wrote a whole post about. The way things are going, I probably will.

To be continued...

Related Articles