LinkedIn Sourceforge

Vincent's Blog

Pleasure in the job puts perfection in the work (Aristote)

My TV is in quarantine, how I can find my NAS files again ?

Posted on 2026-11-29 10:24:00 from Vincent in OpenBSD Firewall NAS

Give a shoutout to Ben Iwara on unsplash.com

Modern TVs are small computers that run software you don't control, talk to servers you never chose, and update themselves whenever they like. Mine, an LG, had a full view of my home network: the NAS, the printers, the laptops, the backups. One evening I decided that was enough and moved the TV to its own VLAN, with access to the Internet and nothing else. It worked perfectly. The streaming apps still played, the TV could no longer see the rest of the house, and I felt rather pleased with myself. Then I opened the media player to watch a film from the NAS, and the NAS was gone. No error, no timeout, nothing: the server had simply vanished from the list. This is the story of why that happens, why the obvious fixes are bad ones, and how a small Python script on an OpenBSD firewall gave the TV back its films without giving it back the network.


Why the TV got its own VLAN

Smart TVs do not have a good reputation on privacy, and LG is no exception. Back in 2013, a British blogger found his LG TV reporting the channels he watched, and even the names of files on a USB stick, to LG, even with the relevant option turned off. Since then, almost every manufacturer has adopted automatic content recognition (ACR), which LG calls Live Plus: the TV fingerprints what is on screen, including what comes from HDMI devices, and sends it home. The Markup explained how it works, a UCL-led study measured it on LG and Samsung sets, and RTINGS saw regular data uploads even when ACR was not the obvious cause. In December 2025, the Texas Attorney General sued LG and four other manufacturers over this collection. More recently, while strongly denying claims that its TVs record audio, LG confirmed that its TVs scan for other devices on the local network, calling it a standard feature.

That last point was the one that bothered me most. I can turn off Live Plus in a menu, but I cannot audit what the TV does on my LAN, and a TV stops getting security updates long before it stops working. So I decided to treat it as an untrusted device.

My home network is a classic setup. An OpenBSD firewall routes between several VLANs, see vlan(4), and filters everything with pf.conf(5). The main LAN, say 192.168.1.0/24, holds the trusted machines, including a NAS at 192.168.1.10 that runs minidlna to serve videos and music. I created a separate TV VLAN, say 192.168.50.0/24, and wrote pf rules that let it reach the Internet but block every private address range. From the TV's point of view, my home network no longer exists.

That was exactly the goal, and it was also exactly the problem.

How a TV finds a media server

DLNA, the protocol family behind "media server" menus on TVs, works in two very different steps.

The first step is discovery, done with SSDP (Simple Service Discovery Protocol, part of the UPnP Device Architecture). When you open the media app, the TV sends an M-SEARCH request as UDP multicast to 239.255.255.250, port 1900. Every media server that hears it answers with a short unicast message containing a LOCATION header: the URL of its device description, for minidlna something like http://192.168.1.10:8200/rootDesc.xml. Servers also announce themselves on their own, by sending NOTIFY ssdp:alive messages to the same multicast group every few minutes.

The second step is playback. Once the TV knows the LOCATION, it fetches the XML description over HTTP, browses the content, and streams the files over ordinary TCP connections to port 8200 on the NAS.

The second step is plain unicast TCP. A router forwards it between VLANs like any other traffic, and one pf rule is enough to allow it. The first step is the one that breaks.

Multicast stays home

A packet sent to 239.255.255.250 with a TTL of 1, which is what SSDP uses, is a link-local affair. It reaches the hosts on the same layer-2 segment, and the router does not forward it to other networks (see multicast(4) and ip(4) for how OpenBSD handles it). That is the correct behaviour, and it is the whole point of putting devices on separate
VLANs.

So after the move, the TV's M-SEARCH dies on the TV VLAN and never reaches the NAS. The NAS's NOTIFY announcements die on the main LAN and never reach the TV. Neither side has done anything wrong, and neither can see the other. The TV could have streamed from the NAS without trouble, if only it knew the NAS existed.

The fixes I didn't want

The first idea that comes to mind is to bridge the two VLANs with bridge(4) or veb(4). Discovery would work again, because multicast would flow freely. But the TV would also be back on the home LAN at layer 2, which undoes the very isolation I had just built. That is not a fix, it is a rollback.

The second idea is multicast routing, with something like igmpproxy or a full multicast routing daemon. That forwards multicast groups between networks. It would work, but it is a large hammer for a tiny nail: I don't want all multicast between the VLANs, I want one TV to learn the address of one server. It would also let the TV talk SSDP to every UPnP device on the main LAN, which is precisely the kind of discovery I wanted to stop.

The third idea is to move the NAS, or give it a second interface on the TV VLAN. That puts a trusted machine full of my data next to the untrusted one, which is backwards.

What I needed was much smaller: someone on the TV VLAN who answers the TV's question with the NAS's address.

Answering on behalf of the NAS

The firewall already has a leg in both VLANs. It sees the TV's multicast on the TV VLAN, and it can reach the NAS on the main LAN. So I wrote ssdp_bridge.py, a small daemon that runs on the firewall and answers discovery as if it were the NAS:

TV (TV VLAN) --M-SEARCH, multicast-----------------> firewall (ssdp_bridge.py)
TV           <--200 OK, LOCATION=http://<NAS>:8200/rootDesc.xml-- firewall
TV           --HTTP tcp 8200, routed by pf---------> NAS (minidlna, main LAN)

The script is not a relay. It does not forward packets from one VLAN to the other, and it never carries a single byte of media. It only speaks SSDP on the TV VLAN, and every answer it gives points to the real NAS. Once the TV has the LOCATION, it opens its own HTTP connection to the NAS, and pf decides whether that connection is allowed.

To make its answers indistinguishable from the real thing, the script starts by reading the NAS's rootDesc.xml. From it, it takes the device identifier (the UDN), the device and service types, and the Server header that minidlna sends. With those, it builds the same 200 OK responses minidlna would send, and the TV has no reason to doubt them. It reads the description again before each round of announcements, so if the NAS is reinstalled or its identifier changes, the bridge follows along.

In practice the daemon does three things:

  1. It joins the multicast group 239.255.255.250 on its TV VLAN address and listens for M-SEARCH requests. When the search target matches (or is ssdp:all), it answers each one with a unicast 200 OK, after a random delay within the MX value the TV asked for, as the specification requires.
  2. Every 300 seconds, it sends NOTIFY ssdp:alive messages on the TV VLAN, so a TV that is already switched on sees the NAS appear without having to search.
  3. When it stops, it sends NOTIFY ssdp:byebye, so the TV removes the server cleanly instead of waiting for the cache to expire.

The whole thing uses only the Python 3 standard library: socket, urllib, xml.etree and a few threads. It runs as root, because port 1900 is below 1024.

One OpenBSD detail is worth mentioning, because it cost me a little time. On Linux, the IP_MULTICAST_TTL and IP_MULTICAST_LOOP socket options happily accept an int. On OpenBSD, ip(4) documents them as u_char, so they must be packed as a single byte, or setsockopt fails:

s.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, struct.pack("B", 1))
s.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_LOOP, struct.pack("B", 0))

Two firewalls, one voice

If, like me, you run a redundant pair of firewalls sharing the gateway address through carp(4), the bridge should run on both, so that discovery keeps working when one of them fails. But if both answered every search, the TV would receive each answer twice.

The fix is a --carp option. Before answering or announcing, the script runs ifconfig(8) on the given carp interface, and it speaks only if that interface reports carp: MASTER. The backup firewall stays silent until it takes over. If the script cannot tell, it answers anyway: a duplicate answer is harmless, a missing one is not.

Each firewall listens on its own address on the TV VLAN (--ifip), not on the shared CARP address, because that is the address it uses to join the multicast group and to send its announcements. On a single firewall, simply leave out --carp.

Opening exactly the right doors in pf

With pf, nothing passes unless a rule says so, and that is how I like it. DLNA through the bridge needs six flows, and each one deserves a rule I can name:

# Flow From → To
1 TV searches for servers (M-SEARCH) TV → 239.255.255.250:1900
2 Bridge answers the TV (200 OK) firewall :1900 → TV
3 Bridge announces the NAS (NOTIFY) firewall :1900 → 239.255.255.250:1900
4 TV streams from the NAS TV → NAS:8200
5 Home LAN reaches the TV main LAN → TV
6 Bridge reads rootDesc.xml from the NAS firewall → NAS:8200

The first flow is usually covered by the TV's outbound rule already, because 239.0.0.0/8 is not one of the private ranges it blocks. The others need a few lines in the TV section, placed after the rule that blocks private addresses, since in pf the last matching rule wins. With $tv_if the TV VLAN interface, $lan_if the main LAN interface and $nas the NAS address:

# flow 4: the TV streams from minidlna (HTTP)
pass proto tcp from $tv_if:network to $nas port 8200 label "tv-dlna"

# flow 2: unicast "200 OK" answers from ssdp_bridge.py to the TV
pass out on $tv_if proto udp from $tv_if:network port 1900 to $tv_if:network label "tv-ssdp"

# flow 3: NOTIFY alive/byebye sent by ssdp_bridge.py on the TV VLAN
pass out on $tv_if proto udp from ($tv_if) port 1900 to 239.255.255.250 port 1900 label "tv-ssdp"

# flow 5: the home LAN may reach the TV
pass from $lan_if:network to $tv_if:network label "lan-to-tv"

# optional: the NAS's own announcements on the LAN are useless now, drop them unlogged
block in quick on $lan_if proto udp from $nas to 239.255.255.250 port 1900 label "nas-ssdp-noise"

Notice the asymmetry. The TV may open exactly one kind of connection into my network: TCP to port 8200 on the NAS. Everything else on the main LAN stays as invisible as before. The home LAN, on the other hand, may reach the TV, which is the direction of trust I want.

The sixth flow, the bridge reading the NAS description, may already be allowed by a general LAN rule. If that rule logs to pflog(4), a fetch every 300 seconds quickly fills the log. A dedicated, later rule matches the same traffic without log:

pass proto tcp from self to $nas port 8200 label "self-nas-dlna"

As always, check before you load, with pfctl(8):

pfctl -nf /etc/pf.conf && pfctl -f /etc/pf.conf

A proper OpenBSD daemon

A script started by hand in a tmux session is not a service. OpenBSD makes it very easy to turn it into one: a short script in /etc/rc.d/, built on rc.subr(8), is all it takes.

#!/bin/ksh
daemon="/usr/local/bin/python3 /root/nas_bridge/ssdp_bridge.py"
daemon_flags=""     # must be set with: rcctl set ssdp_bridge flags ...
daemon_logger="daemon.info"

. /etc/rc.d/rc.subr

pexp="/usr/local/bin/python3 /root/nas_bridge/ssdp_bridge.py.*"
rc_bg=YES
rc_reload=NO

rc_cmd $1

rc_bg=YES lets rc.subr put the process in the background, daemon_logger sends its output to syslogd(8), and pexp tells rc.subr how to recognise the process, since its name is python3, not ssdp_bridge. The script catches SIGTERM like a Ctrl-C, so rcctl stop sends the ssdp:byebye before exiting.

The per-firewall settings live where they belong, in rc.conf.local, set with rcctl(8):

rcctl enable ssdp_bridge
rcctl set ssdp_bridge flags --location http://192.168.1.10:8200/rootDesc.xml \
    --ifip 192.168.50.2 --carp carp1     # use the second firewall's own address there
rcctl start ssdp_bridge

At boot, the NAS is not always reachable yet when the firewall starts. Instead of failing, the script retries every 10 seconds until it can read rootDesc.xml, and only then starts answering.

Watching it work

Run in the foreground with -v, the script tells its story line by line. The first line shows what it learned from the NAS:

server <minidlna Server header> | UDN uuid:... | N types

Then, when the TV's media app opens, M-SEARCH from <TV address> appears, followed by the 200 OK answers. On the wire, tcpdump(8) confirms the conversation:

tcpdump -ni <tv_if> port 1900
tcpdump -nei pflog0 host <TV address>

The first shows the SSDP exchange on the TV VLAN; the second shows what pf blocks, which is the quickest way to find a missing rule.

And on the TV, the NAS was back in the list, with its usual name, as if it had never left.

The source code

The complete script is available here: ssdp_bridge.py. It is a single file of fewer than 300 lines, with no dependency beyond Python 3, which on OpenBSD comes from the packages with pkg_add(1). It is short enough to be read in one sitting, and I would encourage you to do so before running it as root on your firewall: that is good practice for any code found on a blog, including mine.

The code follows the steps described above. The Description class fetches and parses the server's rootDesc.xml, two small functions build the 200 OK and NOTIFY messages, carp_is_master() asks ifconfig(8) who is in charge, and the Bridge class ties it all together: one thread listens for searches, another sends the periodic announcements. Its options are listed with --help:

usage: ssdp_bridge.py [-h] --location LOCATION --ifip IFIP [--carp CARP]
                      [--interval INTERVAL] [--max-delay MAX_DELAY] [-v]

Only --location (the URL of the server's description) and --ifip (the firewall's own address on the client VLAN) are required. Nothing in the script is specific to minidlna or to LG: it should work with any UPnP media server whose description it can read, and any DLNA client that accepts a server on another subnet.

The limits

This approach rests on one assumption: that the TV accepts a media server on another subnet. Most do, because the LOCATION is just a URL. A few strict implementations, however, ignore any server that is not on their own network. For those, no amount of SSDP can help, because the TV discards the answer itself.

The bridge is also written for one server. It reads one description and speaks for one device. Supporting several would be simple, but I have one NAS, and one is what I need.

And of course, isolating the TV on the network does nothing against what it sends to its manufacturer over the Internet. For that, turning off Live Plus and the other "viewing information" agreements in the TV's settings is still worth doing, and checking again after each firmware update.

Conclusion

The TV now lives in its own small world: it can reach the Internet, and the only thing it can reach at home is port 8200 on the NAS. It cannot scan my network, cannot see my laptops, and cannot talk to the other UPnP devices in the house. Yet from the sofa, nothing has changed: the media app opens, the NAS is there, the film plays.

The lesson goes beyond TVs. Network isolation breaks every protocol that relies on "everyone on the same wire can hear me": SSDP, mDNS, and their cousins. The tempting reaction is to tear down the wall again, with a bridge or a multicast router. The better one is to look closely at what the protocol actually needs. Here, it needed one sentence spoken on the right VLAN, "the media server is over there", and fewer than 300 lines of Python on a firewall were enough to say it.

Security and convenience are often presented as opposites. Sometimes, they only need a small interpreter between them.



👍 0, 👎 0
displayed: 122



What is the first vowel of the word Python?