NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
16.48k stars 12.97k forks source link

hdhomerun_config cannot see HDHR-US (libhdhomerun) #223177

Open deftdawg opened 1 year ago

deftdawg commented 1 year ago

Describe the bug

I have a HDHomeRun Dual (HDHR-US), libhdhomerun / hdhomerun_config discover is not able to see the device at all, though the device is accessible from a web browser and ping-able from the same machine.

image

The device is operational as shown by hdhomerun_config running on an KDE Neon (Ubuntu) machine in the bottom half of this screenshot: image

I can also stream with it to both Android and IOS devices on the same network.

Steps To Reproduce

Steps to reproduce the behavior:

  1. add libhdromerun to pkgs in nixos/configuration.nix
  2. rebuild
  3. run hdhomerun_config discover

Expected behavior

See bottom half of second screenshot where the HDHR device is discovered and it's device_id and IP are displayed.

Notify maintainers

@titanous

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[deftdawg@nixos:~/source]$ nix-shell -p nix-info --run "nix-info -m"
these 3 paths will be fetched (0.63 MiB download, 9.25 MiB unpacked):
  /nix/store/m6pqvzyprlr073z4v2q59wdi7ga8g5qd-file-5.43
  /nix/store/qy5mvspgxdrpcmzyv7rgwfzhb5mqj31q-gnumake-4.3
  /nix/store/vy1gljyx0hx57bjnsyj05g3xw1bm2v6m-stdenv-linux
copying path '/nix/store/m6pqvzyprlr073z4v2q59wdi7ga8g5qd-file-5.43' from 'https://cache.nixos.org'...
copying path '/nix/store/qy5mvspgxdrpcmzyv7rgwfzhb5mqj31q-gnumake-4.3' from 'https://cache.nixos.org'...
copying path '/nix/store/vy1gljyx0hx57bjnsyj05g3xw1bm2v6m-stdenv-linux' from 'https://cache.nixos.org'...
 - system: `"x86_64-linux"`
 - host os: `Linux 6.2.7, NixOS, 22.11 (Raccoon), 22.11.3299.9ef6e7727f4`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.11.1`
 - channels(root): `"nixos-22.11"`
 - channels(deftdawg): `""`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
deftdawg commented 1 year ago

As an added sanity check I built it from source on both NixOS and Ubuntu...

curl -LO https://download.silicondust.com/hdhomerun/libhdhomerun.tgz
# nix-shell -p gnumake # on Nix
make

The result is the same... no devices found on nixos; hdhomerun device 10142C7C found at 192.168.0.19 on KDE Neon

image

Running sudo hdhomerun_config discover also did not make a difference.

Could this be some kind of firewall or networking restriction on NixOS?

deftdawg commented 2 months ago

I've figured out the problem... image

Wireshark shows the UDP broadcast originates from a random port (i.e. 57656) destined for 65001 on the tuner, the response is sent to back from the tuner (65001) to port libhdhomerun broadcast from (57656), which is then dropped by the nixos firewall because the port is not a valid destination.

This means the documentation included in the nix for libhdhomerun is misleading: https://github.com/NixOS/nixpkgs/blob/3c7aa07f180ea32026c7c708fcfee6a2448f773a/pkgs/development/libraries/libhdhomerun/default.nix#L5

Rather the user must allow traffic be accepted from the UDP source port 65001 like this:

[deftdawg@maxsun:~]$ hdhomerun_config discover
no devices found

[deftdawg@maxsun:~]$ sudo iptables -I nixos-fw -p udp --sport 65001 -j nixos-fw-accept

[deftdawg@maxsun:~]$ hdhomerun_config discover
hdhomerun device 10142C7C found at 10.0.0.11

Will test if this is effective in /etc/nixos/configuration.nix:

  networking.firewall.extraCommands = "iptables -I nixos-fw -p udp --sport 65001 -j nixos-fw-accept"; # libhdhomerun

UPDATE: After a reboot, I can confirm the above configuration.nix firewall.extraCommands does resolve the problem.

@sielicki

sielicki commented 2 months ago

Do you use ipv6?

deftdawg commented 2 months ago

Do you use ipv6?

I've not specifically enabled it, but my nic does have both IPv4 and IPv6 addresses and my router has public IPv4 and IPv6 addresses.

Wireshark shows the traffic as being IPv4.

Why do you ask?