Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# go-ethernetip Releases

## v0.8.3

**Date:** 2026-11-16
**Previous release:** v0.8.2

## Summary

A patch release on v0.8.2. No exported identifier is added, removed or
changed.

## Changes

### Fixes

- **scanner**: `Open` reports `ErrNotConnected` when the client's session
ends between the Forward_Open reply and the opening of the I/O
connection. It returned `ErrInvalidOption` ("production without an
interval or destination"), an error about the configuration, for what
is a lost connection: the target's address, taken from the session, was
gone. The Forward_Close is still tried, as on the other failures after
a Forward_Open. The chaos test of `e2e` met this as a connection killed
at that moment.

### Tests

- `TestOpenSessionEndedAfterForwardOpen`: a session that has ended after
the reply gives `ErrNotConnected`, not `ErrInvalidOption`, and one
Forward_Close request.

---

## v0.8.2

**Date:** 2026-11-16
Expand Down
14 changes: 13 additions & 1 deletion scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,15 @@ func (io *IO) open(ctx context.Context) error {
_ = c.ForwardClose(ctx, cip.ForwardClose{Triad: fo.Triad, Path: path})
return err
}
target := targetIP(c.RemoteAddr())
target := targetIP(remoteAddr(c))
if !target.IsValid() {
// The session ended after the reply: the I/O connection has no
// target to send to or accept from. That is a connection error, not
// an invalid option; the Forward_Close goes out if the client
// reconnects in time, else the target's connection times out.
_ = c.ForwardClose(ctx, cip.ForwardClose{Triad: fo.Triad, Path: path})
return fmt.Errorf("%w: the session ended after the Forward_Open reply", ethernetip.ErrNotConnected)
}
dst := netip.AddrPortFrom(target, encap.IOPort)
var group netip.Addr
for _, it := range rItems {
Expand Down Expand Up @@ -599,6 +607,10 @@ func checkAPIs(reply cip.ForwardOpenReply, otRPI, floor time.Duration) error {
return nil
}

// remoteAddr is the target's end of the client's session, or nil when the
// client has none. A test replaces it to end the session at a given step.
var remoteAddr = (*client.Client).RemoteAddr

func targetIP(a net.Addr) netip.Addr {
if ta, ok := a.(*net.TCPAddr); ok {
if ip, ok := netip.AddrFromSlice(ta.IP); ok {
Expand Down
20 changes: 20 additions & 0 deletions scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,26 @@ func okReply(fo cip.ForwardOpen) cip.ForwardOpenReply {
return cip.ForwardOpenReply{OTConnID: 0x77, TOConnID: fo.TOConnID, Triad: fo.Triad, OTAPI: fo.OTRPI, TOAPI: fo.TORPI}
}

// The session ends between the Forward_Open reply and the opening of the
// I/O connection (the chaos test met it as a connection killed at that
// moment): Open reports ErrNotConnected, not ErrInvalidOption, and tries
// the Forward_Close.
func TestOpenSessionEndedAfterForwardOpen(t *testing.T) {
f := newFakeTarget(t, func(fo cip.ForwardOpen) (cip.ForwardOpenReply, []encap.Item) { return okReply(fo), nil })
c := dial(t, f.ln.Addr().String())
s := newScanner(t, c)
saved := remoteAddr
remoteAddr = func(*client.Client) net.Addr { return nil }
t.Cleanup(func() { remoteAddr = saved })
io, err := s.Open(ctxT(t), owner(5*time.Millisecond))
if !errors.Is(err, ethernetip.ErrNotConnected) || errors.Is(err, ethernetip.ErrInvalidOption) {
t.Fatalf("Open = %v, %v; want ErrNotConnected", io, err)
}
if f.closes.Load() != 1 {
t.Fatalf("%d Forward_Close requests, want 1", f.closes.Load())
}
}

func TestMulticastWithoutGroup(t *testing.T) {
f := newFakeTarget(t, func(fo cip.ForwardOpen) (cip.ForwardOpenReply, []encap.Item) {
// A malformed item and a unicast T->O address: no group.
Expand Down
Loading