QuantumEntangledAndy / neolink

An RTSP bridge to Reolink IP cameras
GNU Affero General Public License v3.0
330 stars 45 forks source link

Local discovery fails (Debian) when no default route #179

Closed iam-TJ closed 5 months ago

iam-TJ commented 11 months ago

Describe the bug ``No discovery packet is broadcast whendiscovery = "local"`

$ ./neolink --version
[2023-10-30T22:50:12Z INFO  neolink] Neolink e47a0d5734b0a06b53bd8d78be9ca2f6b8396480 release
neolink 0.6.2

$ cat argusPT.toml 
bind = "0.0.0.0"

[[cameras]]
name = "argusPT"
discovery = "local" 
username = "admin"
password = "password"
uid = "95270004T22YP1W5"
#address = "10.254.1.64"

tj@noc:~/neolink_linux_armhf$ ./neolink rtsp --config=argusPT.toml                                                                                                                                
[2023-10-30T22:24:30Z INFO  neolink] Neolink 459c9255ada7ebda281eba32a8a9b94a30c471f0 release
[2023-10-30T22:24:30Z INFO  neolink::rtsp] argusPT: Rtsp Staring                          
[2023-10-30T22:24:30Z INFO  neolink::rtsp] Starting RTSP Server at 0.0.0.0:8554                                                                                                                   
[2023-10-30T22:24:30Z INFO  neolink::utils] argusPT: Connecting to camera at UID: 95270004T22YP1W5
[2023-10-30T22:24:30Z INFO  neolink_core::bc_protocol] argusPT: Trying local discovery                                                                                                            
[2023-10-30T22:24:45Z WARN  neolink::common::camthread] argusPT: Connection Lost: Failed to connect to camera argusPT at UID: 95270004T22YP1W5 on channel 0                                       

    Caused by:                                                                                   
        Timed out while waiting for camera reply                                                                                                                                                  
[2023-10-30T22:24:45Z INFO  neolink::common::camthread] argusPT: Attempt reconnect in 50ms
...

Occurs on both Debian 12 amd64 (and Raspbian 12 armhf). strace reports:

2500  sendto(10, ":\317\207*\271\0\0\0\1\0\0\0\375\0\0\0AeO\5t\2Ur\346\240\32?:\\~W"..., 205, MSG_NOSIGNAL, {sa_family=AF_INET, sin_port=htons(2015), sin_addr=inet_addr("255.255.255.255")}, 16) 
= -1 ENETUNREACH (Network is unreachable)

Changing the configuration to use the IPv4 address:

tj@noc:~/neolink_linux_armhf$ ./neolink rtsp --config=argusPT.toml                                
[2023-10-30T22:55:27Z INFO  neolink] Neolink 459c9255ada7ebda281eba32a8a9b94a30c471f0 release
[2023-10-30T22:55:27Z INFO  neolink::rtsp] argusPT: Rtsp Staring
[2023-10-30T22:55:27Z INFO  neolink::rtsp] Starting RTSP Server at 0.0.0.0:8554                                                                                                                   
[2023-10-30T22:55:27Z INFO  neolink::utils] argusPT: Connecting to camera at Address: 10.254.1.64 
[2023-10-30T22:55:27Z INFO  neolink_core::bc_protocol] argusPT: Trying TCP discovery
[2023-10-30T22:55:27Z INFO  neolink_core::bc_protocol] arg
usPT: Discovery failed
[2023-10-30T22:55:27Z WARN  neolink::common::camthread] argusPT: Connection Lost: Failed to connect to camera argusPT at Address: 10.254.1.64 on channel 0

    Caused by:
        Cannot contact camera at given address
[2023-10-30T22:55:27Z INFO  neolink::common::camthread] argusPT: Attempt reconnect in 50ms
...

There's a termshark (tshark/tdump) monitoring the interface the Argus PT is connected to and no packets are seen originating from neolink for either UID or address discovery methods.

The local network is IPv6 only and only routes IPv6 externally; I've added a DHCP server on the LOCAL virtual bridge interface for RFC1918 private addresses and the camera uses DHCPv4 to gain its IPv4 of 10.254.1.64 (no sign of it using the IPv6RA nor DHCPv6). The camera immediately starts making DNS queries to a non-existent DNS server (and not-locally-used) at 192.168.1.31 initially asking for pushx.reolink.com and after a few failures, p2p.reolink.com. I assume the DNS server address is hard-coded in the camera firmware.

I'd like to resolve why neolink is not managing to send the discovery packet. I've tried using `bind = "10.254.1.65" but that seems only relevant to the RTSP server socket.

Another data point: earlier I did a full nmap scan of the camera's IPv4 address (nmap -n -p1-65535) and no ports were discovered open - is this expected?

The camera is new; I connected it to the WiFi access point using the Android app QR-code method. (the AP is the RaspberryPi noc running hostapd and bridging the wireless and wired ports on the virtual bridge LOCAL).

Anything I can do to help solve this I will; up to and including patching and recompiling.

iam-TJ commented 11 months ago

Answering my own question (again!). It turns out that neolink fails if there is no IPv4 default route set. It might be worth adding a check for that since it is non-trivial to diagnose. On the amd64 host (not the Raspi AP) I added the Raspi as the default gateway:

sudo ip addr add default via 10.254.1.65

$ ./neolink rtsp --config=argusPT.toml
[2023-10-30T23:43:15Z INFO  neolink] Neolink e47a0d5734b0a06b53bd8d78be9ca2f6b8396480 release
[2023-10-30T23:43:15Z INFO  neolink::rtsp] Starting RTSP Server at 10.254.1.66:8554
[2023-10-30T23:43:15Z INFO  neolink::rtsp] argusPT: Rtsp Staring
[2023-10-30T23:43:15Z INFO  neolink::utils] argusPT: Connecting to camera at UID: 95270004T22YP1W5
[2023-10-30T23:43:15Z INFO  neolink_core::bc_protocol] argusPT: Trying local discovery
[2023-10-30T23:43:17Z INFO  neolink_core::bc_protocol] argusPT: Local discovery success 95270004T22YP1W5 at 10.254.1.64:18304
[2023-10-30T23:43:17Z INFO  neolink::utils] argusPT: Logging in
[2023-10-30T23:43:18Z INFO  neolink::utils] argusPT: Connected and logged in
[2023-10-30T23:43:18Z INFO  neolink::common::camthread] argusPT: Camera time is already set: 2023-10-30 15:39:14.0 +08:00:00
[2023-10-30T23:43:19Z INFO  neolink::common::neocam] argusPT: Model Reolink Argus PT
[2023-10-30T23:43:19Z INFO  neolink::common::neocam] argusPT: Firmware Version v3.0.0.1045_22061301
[2023-10-30T23:43:20Z INFO  neolink::rtsp] argusPT: Avaliable at /argusPT/main, /argusPT/Main, /argusPT/mainStream, /argusPT/MainStream, /argusPT/Mainstream, /argusPT/mainstream, /argusPT
[2023-10-30T23:43:21Z INFO  neolink::rtsp] argusPT: Avaliable at /argusPT/sub, /argusPT/Sub, /argusPT/subStream, /argusPT/SubStream, /argusPT/Substream, /argusPT/substream

It failed initially since I had a password ="password" in the configuration; removing that gave the successful connection shown above. The error was:

[2023-10-30T23:42:48Z ERROR neolink::common::camthread] Login credentials were not accepted

The default gateway doesn't have to lead anywhere - as long as there is one set neolink succeeeds! On the Raspi I set its gateway to the amd64 host!

QuantumEntangledAndy commented 11 months ago

So all cameras I have seen are ipv4 only. The reolink servers only take and distribute ipv4 addresses too, so I wrote the code remote/map/relay to reflect this. For local though I think I tried to keep it working on both,

The default bind in neolink is 0.0.0.0 though, so that might be the issue

QuantumEntangledAndy commented 5 months ago

Closing this as there is not much actionable changes here, we cannot connect to an ipv4 camera if we do not have an ipv4 route