synfinatic / udp-proxy-2020

A crappy UDP router for the year 2020 and beyond
MIT License
106 stars 7 forks source link

Remote phone devices are not discovered #121

Closed sjtuross closed 11 months ago

sjtuross commented 1 year ago

I tried my iPhone and Android devices. Both are not discovered as audio devices when Wireguard VPN is on, although they can connect to roon core (version 1.8) while your tool is running.

I run the latest release 0.0.11 on OpenWrt x64 router with the below command. I checked this issue #95 but I don't do NAT in my Wireguard setup. Could you take a look the attached log and pcap files and advise how I can troubleshoot further? Thanks a ton!

./udp-proxy-2020 --port 9003 --interface eth0,wg0 --level trace

pcap.zip

root@openwrt:/tmp# ./udp-proxy-2020 --port 9003 --interface eth0,wg0 --level trace
DEBUG   eth0: ifIndex: 3                             
DEBUG   eth0 network: ip+net            string: 192.168.1.1/24 
DEBUG   eth0 network: ip+net            string: 192.168.1.239/24 
DEBUG   eth0 network: ip+net            string: 192.168.1.238/24 
DEBUG   eth0 network: ip+net            string: 192.168.1.237/24 
DEBUG   eth0 network: ip+net            string: 192.168.1.111/24 
DEBUG   eth0 network: ip+net            string: 192.168.1.110/24 
DEBUG   eth0 network: ip+net            string: 192.168.1.106/24 
DEBUG   eth0 network: ip+net            string: 192.168.1.103/24 
DEBUG   eth0 network: ip+net            string: 192.168.1.102/24 
DEBUG   eth0 network: ip+net            string: 192.168.1.101/24 
DEBUG   eth0 network: ip+net            string: 192.168.1.100/24 
DEBUG   eth0 network: ip+net            string: 240e:388:130d:3501::1/64 
DEBUG   eth0 network: ip+net            string: 2408:820c:d2a:2b71::1/64 
DEBUG   eth0 network: ip+net            string: fd63:7368:7868:1::1/64 
DEBUG   eth0 network: ip+net            string: fe80::c683:4fff:fe18:14a3/64 
DEBUG   Listen: (main.Listen) {
 iname: (string) (len=4) "eth0",
 netif: (*net.Interface)(0xc000170fc0)({
  Index: (int) 3,
  MTU: (int) 1500,
  Name: (string) (len=4) "eth0",
  HardwareAddr: (net.HardwareAddr) (len=6 cap=38080) c4:83:4f:18:14:a3,
  Flags: (net.Flags) up|broadcast|multicast
 }),
 ports: ([]int32) (len=1 cap=1) {
  (int32) 9003
 },
 ipaddr: (string) (len=13) "192.168.1.255",
 promisc: (bool) false,
 handle: (*pcap.Handle)(<nil>),
 writer: (*pcapgo.Writer)(<nil>),
 inwriter: (*pcapgo.Writer)(<nil>),
 outwriter: (*pcapgo.Writer)(<nil>),
 timeout: (time.Duration) 250ms,
 clientTTL: (time.Duration) 0s,
 sendpkt: (chan main.Send) (cap=100) 0xc0000b8780,
 clients: (map[string]time.Time) {
 }
} 
DEBUG   wg0: ifIndex: 8621                           
DEBUG   Listen: (main.Listen) {
 iname: (string) (len=3) "wg0",
 netif: (*net.Interface)(0xc00022c600)({
  Index: (int) 8621,
  MTU: (int) 1420,
  Name: (string) (len=3) "wg0",
  HardwareAddr: (net.HardwareAddr) ,
  Flags: (net.Flags) up|pointtopoint
 }),
 ports: ([]int32) (len=1 cap=1) {
  (int32) 9003
 },
 ipaddr: (string) "",
 promisc: (bool) true,
 handle: (*pcap.Handle)(<nil>),
 writer: (*pcapgo.Writer)(<nil>),
 inwriter: (*pcapgo.Writer)(<nil>),
 outwriter: (*pcapgo.Writer)(<nil>),
 timeout: (time.Duration) 250ms,
 clientTTL: (time.Duration) 0s,
 sendpkt: (chan main.Send) (cap=100) 0xc0000b8840,
 clients: (map[string]time.Time) {
 }
} 
DEBUG   eth0: applying BPF Filter: (udp port 9003) and (src net 192.168.1.0/24 or src net 192.168.1.0/24 or src net 192.168.1.0/24 or src net 192.168.1.0/24 or src net 192.168.1.0/24 or src net 192.168.1.0/24 or src net 192.168.1.0/24 or src net 192.168.1.0/24 or src net 192.168.1.0/24 or src net 192.168.1.0/24 or src net 192.168.1.0/24) 
DEBUG   Opened pcap handle on eth0                   
DEBUG   wg0: applying BPF Filter: (udp port 9003) and (src net 10.61.1.0/24) 
DEBUG   Opened pcap handle on wg0                    
DEBUG   Initialization complete!                     
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(wg0) ticker                    
DEBUG   wg0: Learned client IP: 10.61.1.9            
DEBUG   wg0: received packet and fowarding onto other interfaces 
DEBUG   eth0: sending out because we're not wg0      
DEBUG   processing packet from wg0 on eth0           
DEBUG   eth0 => 192.168.1.255: packet len: 140       
DEBUG   eth0: received packet and fowarding onto other interfaces 
DEBUG   wg0: sending out because we're not eth0      
DEBUG   processing packet from eth0 on wg0           
DEBUG   wg0 => 10.61.1.9: packet len: 491            
DEBUG   eth0: received packet and fowarding onto other interfaces 
DEBUG   wg0: sending out because we're not eth0      
DEBUG   eth0: received packet and fowarding onto other interfaces 
DEBUG   wg0: sending out because we're not eth0      
DEBUG   eth0: received packet and fowarding onto other interfaces 
DEBUG   wg0: sending out because we're not eth0      
DEBUG   processing packet from eth0 on wg0           
DEBUG   eth0: received packet and fowarding onto other interfaces 
DEBUG   wg0: sending out because we're not eth0      
DEBUG   eth0: received packet and fowarding onto other interfaces 
DEBUG   wg0: sending out because we're not eth0      
DEBUG   wg0 => 10.61.1.9: packet len: 126            
DEBUG   eth0: received packet and fowarding onto other interfaces 
DEBUG   wg0: sending out because we're not eth0      
DEBUG   processing packet from eth0 on wg0           
DEBUG   wg0 => 10.61.1.9: packet len: 126            
DEBUG   processing packet from eth0 on wg0           
DEBUG   wg0 => 10.61.1.9: packet len: 126            
DEBUG   processing packet from eth0 on wg0           
DEBUG   wg0 => 10.61.1.9: packet len: 126            
DEBUG   processing packet from eth0 on wg0           
DEBUG   wg0 => 10.61.1.9: packet len: 126            
DEBUG   processing packet from eth0 on wg0           
DEBUG   wg0 => 10.61.1.9: packet len: 126            
DEBUG   eth0: received packet and fowarding onto other interfaces 
DEBUG   wg0: sending out because we're not eth0      
DEBUG   eth0: received packet and fowarding onto other interfaces 
DEBUG   wg0: sending out because we're not eth0      
DEBUG   eth0: received packet and fowarding onto other interfaces 
DEBUG   processing packet from eth0 on wg0           
DEBUG   wg0: sending out because we're not eth0      
DEBUG   eth0: received packet and fowarding onto other interfaces 
DEBUG   wg0: sending out because we're not eth0      
DEBUG   eth0: received packet and fowarding onto other interfaces 
DEBUG   wg0: sending out because we're not eth0      
DEBUG   eth0: received packet and fowarding onto other interfaces 
DEBUG   wg0: sending out because we're not eth0      
DEBUG   wg0 => 10.61.1.9: packet len: 126            
DEBUG   processing packet from eth0 on wg0           
DEBUG   wg0 => 10.61.1.9: packet len: 126            
DEBUG   processing packet from eth0 on wg0           
DEBUG   wg0 => 10.61.1.9: packet len: 126            
DEBUG   processing packet from eth0 on wg0           
DEBUG   wg0 => 10.61.1.9: packet len: 126            
DEBUG   processing packet from eth0 on wg0           
DEBUG   wg0 => 10.61.1.9: packet len: 126            
DEBUG   processing packet from eth0 on wg0           
DEBUG   wg0 => 10.61.1.9: packet len: 126            
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(eth0) ticker                   
DEBUG   wg0: Learned client IP: 10.61.1.9            
DEBUG   wg0: received packet and fowarding onto other interfaces 
DEBUG   eth0: sending out because we're not wg0      
DEBUG   wg0: Learned client IP: 10.61.1.9            
DEBUG   wg0: received packet and fowarding onto other interfaces 
DEBUG   eth0: sending out because we're not wg0      
DEBUG   processing packet from wg0 on eth0           
DEBUG   eth0 => 192.168.1.255: packet len: 140       
DEBUG   processing packet from wg0 on eth0           
DEBUG   eth0 => 192.168.1.255: packet len: 140       
DEBUG   eth0: received packet and fowarding onto other interfaces 
DEBUG   wg0: sending out because we're not eth0      
DEBUG   processing packet from eth0 on wg0           
DEBUG   wg0 => 10.61.1.9: packet len: 491            
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(wg0) ticker                    
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(eth0) ticker                   
DEBUG   handlePackets(wg0) ticker
root@openwrt:/tmp# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr C4:83:4F:18:14:A3  
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::c683:4fff:fe18:14a3/64 Scope:Link
          inet6 addr: 2408:820c:d2a:2b71::1/64 Scope:Global
          inet6 addr: fd63:7368:7868:1::1/64 Scope:Global
          inet6 addr: 240e:388:130d:3501::1/64 Scope:Global
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:223498593909 errors:0 dropped:1225017 overruns:0 frame:0
          TX packets:178636157492 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:164991199483021 (150.0 TiB)  TX bytes:130312987646528 (118.5 TiB)
          Interrupt:20 

root@openwrt:/tmp# ifconfig wg0
wg0       Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inet addr:10.61.1.1  P-t-P:10.61.1.1  Mask:255.255.255.0
          UP POINTOPOINT RUNNING NOARP  MTU:1420  Metric:1
          RX packets:40438 errors:0 dropped:0 overruns:0 frame:0
          TX packets:24637 errors:5 dropped:3 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:37559720 (35.8 MiB)  TX bytes:5737992 (5.4 MiB)
synfinatic commented 1 year ago

based on the pcaps you've provided, your phone is not responding to the queries from your Roon Core. This would explain your problem. Generally speaking this seems to be a Roon client bug. Best I can say is to fully quit/exit Roon on your phone, make sure you are connected to VPN first, and then start Roon.

github-actions[bot] commented 11 months ago

This issue is stale because it has been open for 14 days with no response from the reporter. It will be automatically closed in 14 days from this message.

github-actions[bot] commented 11 months ago

This issue was closed because it has been inactive for 28 days.

sjtuross commented 5 months ago

Hey @synfinatic I think I found the cause. See the screenshot below from the pcap I originally provided. The phone app communicates from a dynamic port 50188 and the core connects back to it. If this port is not forwarded, connection fails, and then the core falls back connecting to 9003 which the phone app is not listening on I believe.

So I tried including 50188 as one additional port, the phone device can be discovered as audio device and it plays fine.

./udp-proxy-2020 --port 9003,50188 --interface eth0,wg0 --level trace

The remaining problem is that the dynamic port could change time to time. Sometimes it's 52027. Do you have any suggestion how to solve this?

image

synfinatic commented 5 months ago

Hi @sjtuross,

Yes, the Roon clients open an ephemeral, high numbered port. This port is fairly random and determined by the underlying OS's TCP/IP stack. However, if you look at your screenshot, you'll see packet 4 has a destination port of 9003. So this packet is being forwarded by udp-proxy-2020.

Anyways, the thing is that udp-proxy-2020 only really needs to forward broadcast/multicast packets. Packets with unicast addresses (your phone or Roon Server) should be forwarded by your router/firewall where udp-proxy-2020 runs. So if you need to specify ports other than 9003 or to unicast addresses like you have highlighted, that means your firewall/router isn't configured correctly.

sjtuross commented 5 months ago

Thank you for the insights. It works now. The problem is that the routable ip range set on my phone for wireguard vpn is too strict.