chirpstack / chirpstack-gateway-bridge

ChirpStack Gateway Bridge abstracts Packet Forwarder protocols into Protobuf or JSON over MQTT.
https://www.chirpstack.io
MIT License
423 stars 272 forks source link

ChirpStack Gateway Bridge binds to udp6 only #235

Open soosp opened 4 months ago

soosp commented 4 months ago

What happened?

If you have IPv6 configured and set

udp_bind = "0.0.0.0:1700"

in your /etc/chirpstack-gateway-bridge/chirpstack-gateway-bridge.toml file (this isthe default setting), ChirpStack Gateway Bridge binds to ipv6 socket only:

# netstat -lnup | grep 1700
udp6       0      0 :::1700                 :::*                                4077/chirpstack-gat

If you set a valid IPv4 socket, it binds only to it as expected.

Tested with the latest precompiled Debian binaries.

What did you expect?

It binds only IPv4 socket or both IPv4 and IPv6.

Steps to reproduce this issue

Steps:

  1. Set up an IPv4 end IPv6 dual stack configuration with static adresses.
  2. Leave udp_bind parameter on the default 0.0.0.0:1700 value.
  3. See if it binds to the IPv4 socket.

Could you share your log output?

# chirpstack-gateway-bridge -c /etc/chirpstack-gateway-bridge/chirpstack-gateway-bridge.toml
INFO[0000] starting ChirpStack Gateway Bridge            docs="https://www.chirpstack.io/gateway-bridge/" version=4.0.11
INFO[0000] backend/semtechudp: starting gateway udp listener  addr="0.0.0.0:1700"
WARN[0000] [store]    memorystore wiped                  module=mqtt
INFO[0000] integration/mqtt: connected to mqtt broker

Your Environment

Component Version
Application Server
Network Server
Gateway Bridge v4.0.11
Chirpstack API
Geolocation
Concentratord
brocaar commented 4 months ago

Could you confirm if there is an actual issue? Are you unable to receive UDP data from IPv4 interfaces when binding to 0.0.0.0:1700? I don't think there is, see also this Go issue: https://github.com/golang/go/issues/48723.

soosp commented 4 months ago

Yes, the ChirpStack Gateway Bridge started on a terminal:

# chirpstack-gateway-bridge -c /etc/chirpstack-gateway-bridge/chirpstack-gateway-bridge.toml
INFO[0000] starting ChirpStack Gateway Bridge            docs="https://www.chirpstack.io/gateway-bridge/" version=4.0.11
INFO[0000] backend/semtechudp: starting gateway udp listener  addr="0.0.0.0:1700"
WARN[0000] [store]    memorystore wiped                  module=mqtt
INFO[0000] integration/mqtt: connected to mqtt broker

Meanwhile I check the bindings on an another terminal:

# netstat -lun
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
udp6       0      0 :::1700                 :::*
soosp commented 4 months ago

A solution (workaround?) should be to add udp4_bind and udp6_bind options instead of udp_bind.

brocaar commented 4 months ago

But what is the actual problem? I can see that when I start the ChirpStack Gateway Bridge it will show as udp6 0 0 :::1700 :::* in netstat, but it accepts UDP data over IPv4 just fine.

From the Go documentation:

For UDP and IP networks, if the host in the address parameter is empty or a literal unspecified IP address, ListenPacket listens on all available IP addresses of the local system except multicast IP addresses.