Skip to content

feat: --proxy and --source-addr on every connecting command; go-modbus v1.14.2 - #32

Merged
boeboe merged 2 commits into
mainfrom
feat/proxy-source-addr
Nov 9, 2026
Merged

boeboe merged 2 commits into
mainfrom
feat/proxy-source-addr

Conversation

@boeboe

@boeboe boeboe commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Every command that connects to a device (all client commands, client sunspec included, and discover) gets --proxy and --source-addr, set as go-modbus v1.14.2's Config.Dialer. Modelled on otfabric/s7commctl#23.

  • --proxy socks5://host:port / socks5h:// (MODBUSCTL_PROXY): SOCKS5 CONNECT (RFC 1928), no auth, no new dependency (internal/netdial, ported from s7commctl).
  • --source-addr <ip> (MODBUSCTL_SOURCE_ADDR): binds a TCPAddr for tcp transports and a UDPAddr for udp ones; with --proxy, the connection to the proxy is the one bound.
  • Transport rules (config.ValidateDialConfig, checked in validateModbusEndpoint before anything is sent):
    • --proxy: tcp, tcp+tls, rtuovertcp, asciiovertcp. With udp or rtuoverudp it is rejected, because SOCKS5 UDP ASSOCIATE is not implemented.
    • --source-addr: every network transport.
    • Both are rejected with rtu:// / ascii://.
  • tcp+tls:// handshakes end to end through the proxy. The certificate is checked against the URL host; a test confirms this.
  • discover: the only dialing outside go-modbus is connectDiscovery, and it now uses the same dialer. --resolve-mac with --proxy is rejected, since ARP cannot see hosts behind the proxy. healthcheck/main.go dials the local server only and is unchanged.

Exit code: invalid values exit 3 (invalid_input), not 2. That is how this repo treats invalid flag values, the TLS flags included (docs/exitcodes.md). Exit 2 here is for parser and usage errors only. A proxy that is down or refuses the connection exits 4 and names the proxy and its reply. No test depends on go-modbus's dial message text.

Tests

  • internal/netdial, internal/socks5test: both 100 % coverage. They include the UDP source binding.
  • cmd/client: each connecting command goes through the scripted proxy to the fake device at a TEST-NET address that only the proxy forwards. Also tested:
    • rtuovertcp / asciiovertcp / tcp+tls over socks5h
    • a refusing proxy (nothing reaches the device, no capture is left behind)
    • --source-addr on tcp, udp and with the proxy, plus an unassignable address
    • every rejection on every command, with zero device requests
  • cmd/discover: a /30 discovered through the proxy, --source-addr, and the invalid combinations.
  • internal/validate, internal/config: per-transport tables and env loading.

make check is green (total coverage 96.8 %, per-package floor met), and make e2e passes.

Docs

The README has a new transport section, two env-table rows and a discover note. SECURITY.md has a Proxies section, and RELEASE.md has a ## v3.7.0 section. Not released.

🤖 Generated with Claude Code

…s v1.14.1

Every client command (sunspec included) and discover take --proxy
(socks5:// or socks5h://, RFC 1928 CONNECT, no auth) and --source-addr,
set as modbus.Config.Dialer. --proxy applies to tcp, tcp+tls, rtuovertcp
and asciiovertcp; with udp or rtuoverudp it is invalid input, as is either
flag with rtu:// or ascii://, and discover --resolve-mac with --proxy.
--source-addr binds a UDP address for udp transports. TLS verification
stays against the URL host.

The SOCKS5 dialer and the scripted test proxy are ported from
otfabric/s7commctl#23.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.87234% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/modbus/client.go 80.95% 2 Missing and 2 partials ⚠️
internal/modbus/discover.go 50.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@boeboe boeboe changed the title feat: --proxy and --source-addr on every connecting command; go-modbus v1.14.1 feat: --proxy and --source-addr on every connecting command; go-modbus v1.14.2 Nov 9, 2026
@boeboe
boeboe merged commit dbad7b9 into main Nov 9, 2026
23 checks passed
@boeboe
boeboe deleted the feat/proxy-source-addr branch November 9, 2026 22:49
boeboe added a commit that referenced this pull request Nov 9, 2026
Invalid --proxy/--source-addr in buildDeviceClientConfig, openDeviceLink,
openRecordingLink and CollectDiscover, the dialer set or left nil, and
CollectDiscover through the test proxy (follow-up to #32).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant