You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2026/09/22 15:59:30 UTC
(plc4x) branch develop updated: fix(plc4go/bacnetip): stop injecting a port-sharing option nothing reads
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new 892d49ae02 fix(plc4go/bacnetip): stop injecting a port-sharing option nothing reads
892d49ae02 is described below
commit 892d49ae0297cf13b427a398f137a3ec307a8368
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Tue Sep 22 17:58:26 2026 +0200
fix(plc4go/bacnetip): stop injecting a port-sharing option nothing reads
The driver set a port-sharing option under a bare name while the udp transport
reads it under the transport's own code, so it never arrived where it was meant
to go. Its only effect was the driver reporting one of its own options as
unknown and ignoring it.
Setting the name the transport does read would not have helped either. The
socket option behind it is documented as a no-op: SO_REUSEPORT does not deliver
broadcast traffic to several host-local BACnet stacks, because the kernel hashes
each broadcast to a single socket, so a second stack still misses traffic.
Sharing the well-known port needs a userland demultiplexer, which is what the
discoverer already says in the comment where it gave the approach up.
Remove the injection, and pin that the driver hands the transport no option
without a reader.
---
plc4go/internal/bacnetip/Driver.go | 4 ---
.../bacnetip/DriverTransportDecoration_test.go | 34 ++++++++++++++++++++++
2 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/plc4go/internal/bacnetip/Driver.go b/plc4go/internal/bacnetip/Driver.go
index ed7a7f63e4..5808728f36 100644
--- a/plc4go/internal/bacnetip/Driver.go
+++ b/plc4go/internal/bacnetip/Driver.go
@@ -84,10 +84,6 @@ func (d *Driver) GetConnection(ctx context.Context, transportUrl url.URL, transp
}
// Provide a default-port to the transport, used if the user doesn't provide one in the connection string.
driverOptions["defaultUdpPort"] = []string{strconv.FormatUint(uint64(model.Constant_BACNETUDPDEFAULTPORT), 10)}
- // Set so_reuse by default so multiple BACnet processes can share the BACnet/IP UDP port.
- if _, ok := driverOptions["so-reuse"]; !ok {
- driverOptions["so-reuse"] = []string{"true"}
- }
// BACnet/IP uses port 47808 on both sides of a conversation; spec-conformant
// peers (bacpypes3, EcoStruxure, Niagara, ...) send unsolicited messages
// and responses back to the well-known port regardless of the request's
diff --git a/plc4go/internal/bacnetip/DriverTransportDecoration_test.go b/plc4go/internal/bacnetip/DriverTransportDecoration_test.go
index a14918e808..7ffa8a0e4f 100644
--- a/plc4go/internal/bacnetip/DriverTransportDecoration_test.go
+++ b/plc4go/internal/bacnetip/DriverTransportDecoration_test.go
@@ -41,10 +41,12 @@ type decoratedUdpTransport struct {
inner *udp.Transport
used bool
+ opts map[string][]string
}
func (d *decoratedUdpTransport) CreateTransportInstanceForLocalAddress(transportUrl url.URL, opts map[string][]string, localAddress *net.UDPAddr, _options ...options.WithOption) (transports.TransportInstance, error) {
d.used = true
+ d.opts = opts
return d.inner.CreateTransportInstanceForLocalAddress(transportUrl, opts, localAddress, _options...)
}
@@ -72,3 +74,35 @@ func TestDriverAcceptsDecoratedUdpTransport(t *testing.T) {
assert.True(t, decorated.used, "the driver must go through the decorator, not around it")
}
+
+// TestDriverInjectsNoOptionNothingReads pins that the driver stops handing the transport an
+// option that has no reader.
+//
+// The port-sharing option was injected under a bare name while the transport reads it under the
+// transport's own code, so it never arrived. It could not have helped if it had: the socket
+// option behind it is a documented no-op, because the kernel hashes each broadcast to a single
+// socket and a second stack on the same host still misses traffic. All the injection achieved
+// was a warning that the driver does not know the option -- which is true, and the reason to
+// stop setting it.
+func TestDriverInjectsNoOptionNothingReads(t *testing.T) {
+ inner := udp.NewTransport()
+ decorated := &decoratedUdpTransport{Transport: inner, inner: inner}
+
+ driver := NewDriver()
+ t.Cleanup(func() { _ = driver.Close() })
+
+ connection, err := driver.GetConnection(
+ context.Background(),
+ url.URL{Scheme: "udp", Host: "127.0.0.1:47808"},
+ map[string]transports.Transport{"udp": decorated},
+ map[string][]string{"local-port": {"0"}},
+ )
+ require.NoError(t, err)
+ require.NotNil(t, connection)
+ t.Cleanup(func() { _ = connection.Close() })
+
+ assert.NotContains(t, decorated.opts, "so-reuse",
+ "nothing reads this key, and the socket option behind it does nothing")
+ assert.NotContains(t, decorated.opts, "udp.so-reuse",
+ "setting the key the transport does read would enable a documented no-op")
+}