From eef630a8d46091a71bb3b7dba5021c7edc419352 Mon Sep 17 00:00:00 2001 From: sbruens Date: Fri, 20 Dec 2024 15:44:34 -0500 Subject: [PATCH] Add some comments to the timeout value. --- service/udp_linux.go | 10 ++++++---- service/udp_other.go | 9 ++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/service/udp_linux.go b/service/udp_linux.go index f0b8bad4..10b3282f 100644 --- a/service/udp_linux.go +++ b/service/udp_linux.go @@ -26,7 +26,9 @@ import ( ) type udpListener struct { - natTimeout time.Duration + // NAT mapping timeout is the default time a mapping will stay active + // without packets traversing the NAT, applied to non-DNS packets. + timeout time.Duration // fwmark can be used in conjunction with other Linux networking features like cgroups, network // namespaces, and TC (Traffic Control) for sophisticated network management. // Value of 0 disables fwmark (SO_MARK) (Linux only) @@ -35,8 +37,8 @@ type udpListener struct { // NewPacketListener creates a new PacketListener that listens on UDP // and optionally sets a firewall mark on the socket (Linux only). -func MakeTargetUDPListener(natTimeout time.Duration, fwmark uint) transport.PacketListener { - return &udpListener{natTimeout: natTimeout, fwmark: fwmark} +func MakeTargetUDPListener(timeout time.Duration, fwmark uint) transport.PacketListener { + return &udpListener{timeout: timeout, fwmark: fwmark} } func (ln *udpListener) ListenPacket(ctx context.Context) (net.PacketConn, error) { @@ -59,5 +61,5 @@ func (ln *udpListener) ListenPacket(ctx context.Context) (net.PacketConn, error) } } - return &timedPacketConn{PacketConn: conn, defaultTimeout: ln.natTimeout}, nil + return &timedPacketConn{PacketConn: conn, defaultTimeout: ln.timeout}, nil } diff --git a/service/udp_other.go b/service/udp_other.go index c67e59f3..0cfde76a 100644 --- a/service/udp_other.go +++ b/service/udp_other.go @@ -26,12 +26,15 @@ import ( type udpListener struct { *transport.UDPListener - natTimeout time.Duration + + // NAT mapping timeout is the default time a mapping will stay active + // without packets traversing the NAT, applied to non-DNS packets. + timeout time.Duration } // fwmark can be used in conjunction with other Linux networking features like cgroups, network namespaces, and TC (Traffic Control) for sophisticated network management. // Value of 0 disables fwmark (SO_MARK) -func MakeTargetUDPListener(natTimeout time.Duration, fwmark uint) transport.PacketListener { +func MakeTargetUDPListener(timeout time.Duration, fwmark uint) transport.PacketListener { if fwmark != 0 { panic("fwmark is linux-specific feature and should be 0") } @@ -43,5 +46,5 @@ func (ln *udpListener) ListenPacket(ctx context.Context) (net.PacketConn, error) if err != nil { return nil, err } - return &timedPacketConn{PacketConn: conn, defaultTimeout: ln.natTimeout}, nil + return &timedPacketConn{PacketConn: conn, defaultTimeout: ln.timeout}, nil }