Pass timeout to PrepareConnection

This commit is contained in:
世界 2025-08-24 18:59:55 +08:00
parent 9532c7f1f6
commit ff4941daa4
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
7 changed files with 24 additions and 12 deletions

View file

@ -609,7 +609,7 @@ func (s *System) processIPv6UDP(ipHdr header.IPv6, udpHdr header.UDP) error {
}
func (s *System) preparePacketConnection(source M.Socksaddr, destination M.Socksaddr, userData any) (bool, context.Context, N.PacketWriter, N.CloseHandlerFunc) {
_, pErr := s.handler.PrepareConnection(N.NetworkUDP, source, destination, nil)
_, pErr := s.handler.PrepareConnection(N.NetworkUDP, source, destination, nil, 0)
if pErr != nil {
if !errors.Is(pErr, ErrDrop) {
if source.IsIPv4() {
@ -658,12 +658,13 @@ func (s *System) processIPv4ICMP(ipHdr header.IPv4, icmpHdr header.ICMPv4) (bool
sourceAddr := ipHdr.SourceAddr()
destinationAddr := ipHdr.DestinationAddr()
if destinationAddr != s.inet4Address {
action, err := s.directNat.Lookup(DirectRouteSession{Source: sourceAddr, Destination: destinationAddr}, func() (DirectRouteDestination, error) {
action, err := s.directNat.Lookup(DirectRouteSession{Source: sourceAddr, Destination: destinationAddr}, func(timeout time.Duration) (DirectRouteDestination, error) {
return s.handler.PrepareConnection(
N.NetworkICMPv4,
M.SocksaddrFrom(sourceAddr, 0),
M.SocksaddrFrom(destinationAddr, 0),
&systemICMPDirectPacketWriter4{s.tun, s.frontHeadroom + PacketOffset, sourceAddr},
timeout,
)
})
if err != nil {
@ -729,12 +730,13 @@ func (s *System) processIPv6ICMP(ipHdr header.IPv6, icmpHdr header.ICMPv6) (bool
sourceAddr := ipHdr.SourceAddr()
destinationAddr := ipHdr.DestinationAddr()
if destinationAddr != s.inet6Address {
action, err := s.directNat.Lookup(DirectRouteSession{Source: sourceAddr, Destination: destinationAddr}, func() (DirectRouteDestination, error) {
action, err := s.directNat.Lookup(DirectRouteSession{Source: sourceAddr, Destination: destinationAddr}, func(timeout time.Duration) (DirectRouteDestination, error) {
return s.handler.PrepareConnection(
N.NetworkICMPv6,
M.SocksaddrFrom(sourceAddr, 0),
M.SocksaddrFrom(destinationAddr, 0),
&systemICMPDirectPacketWriter6{s.tun, s.frontHeadroom + PacketOffset, sourceAddr},
timeout,
)
})
if err != nil {