diff --git a/x/configurl/disorder.go b/x/configurl/disorder.go index b36cf34f..da0695c5 100644 --- a/x/configurl/disorder.go +++ b/x/configurl/disorder.go @@ -32,7 +32,7 @@ func registerDisorderDialer(r TypeRegistry[transport.StreamDialer], typeID strin prefixBytesStr := config.URL.Opaque prefixBytes, err := strconv.Atoi(prefixBytesStr) if err != nil { - return nil, fmt.Errorf("prefixBytes is not a number: %v. Split config should be in split: format", prefixBytesStr) + return nil, fmt.Errorf("disoder: could not parse splice position: %v", err) } return disorder.NewStreamDialer(sd, int64(prefixBytes)) }) diff --git a/x/disorder/stream_dialer.go b/x/disorder/stream_dialer.go index bde4b409..30989f49 100644 --- a/x/disorder/stream_dialer.go +++ b/x/disorder/stream_dialer.go @@ -57,7 +57,7 @@ func (d *disorderDialer) DialStream(ctx context.Context, remoteAddr string) (tra return nil, err } - oldTTL, err := setTtl(innerConn, 1) + oldTTL, err := setHopLimit(innerConn, 1) if err != nil { return nil, fmt.Errorf("disorder strategy: failed to change ttl: %w", err) } @@ -67,12 +67,12 @@ func (d *disorderDialer) DialStream(ctx context.Context, remoteAddr string) (tra return transport.WrapConn(innerConn, innerConn, dw), nil } -// setTtl changes the socket TTL and returns the old value +// setHopLimit changes the socket TTL for IPv4 (or HopLimit for IPv6) and returns the old value // socket must be `*net.TCPConn` -func setTtl(conn net.Conn, ttl int) (oldTTL int, err error) { +func setHopLimit(conn net.Conn, ttl int) (oldTTL int, err error) { addr, err := netip.ParseAddrPort(conn.RemoteAddr().String()) if err != nil { - return 0, err + return 0, fmt.Errorf("could not parse remote addr: %w", err) } switch { @@ -84,6 +84,8 @@ func setTtl(conn net.Conn, ttl int) (oldTTL int, err error) { conn := ipv6.NewConn(conn) oldTTL, _ = conn.HopLimit() err = conn.SetHopLimit(ttl) + default: + return 0, fmt.Errorf("unknown remote addr type (%v)", addr.Addr().String()) } if err != nil { return 0, fmt.Errorf("failed to change TTL: %w", err) diff --git a/x/disorder/writer.go b/x/disorder/writer.go index db729cdc..d7a87cf8 100644 --- a/x/disorder/writer.go +++ b/x/disorder/writer.go @@ -53,7 +53,7 @@ func (w *disorderWriter) Write(data []byte) (written int, err error) { data = data[written:] } w.resetTTL.Do(func() { - _, err = setTtl(w.conn, w.oldTTL) + _, err = setHopLimit(w.conn, w.oldTTL) }) if err != nil { return written, fmt.Errorf("setsockopt IPPROTO_IP/IP_TTL error: %w", err)