mirror of
https://github.com/SagerNet/sing-tun.git
synced 2025-09-26 20:51:13 +08:00
ping: Fix not handling reject
This commit is contained in:
5
stack.go
5
stack.go
@@ -12,7 +12,10 @@ import (
|
|||||||
"github.com/sagernet/sing/common/logger"
|
"github.com/sagernet/sing/common/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrDrop = E.New("drop connections by rule")
|
var (
|
||||||
|
ErrDrop = E.New("drop by rule")
|
||||||
|
ErrReset = E.New("reset by rule")
|
||||||
|
)
|
||||||
|
|
||||||
type Stack interface {
|
type Stack interface {
|
||||||
Start() error
|
Start() error
|
||||||
|
@@ -4,6 +4,7 @@ package tun
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -73,7 +74,10 @@ func (f *ICMPForwarder) HandlePacket(id stack.TransportEndpointID, pkt *stack.Pa
|
|||||||
timeout,
|
timeout,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if errors.Is(err, ErrReset) {
|
||||||
|
gWriteUnreachable(f.stack, pkt)
|
||||||
|
return true
|
||||||
|
} else if errors.Is(err, ErrDrop) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if action != nil {
|
if action != nil {
|
||||||
@@ -132,7 +136,10 @@ func (f *ICMPForwarder) HandlePacket(id stack.TransportEndpointID, pkt *stack.Pa
|
|||||||
timeout,
|
timeout,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if errors.Is(err, ErrReset) {
|
||||||
|
gWriteUnreachable(f.stack, pkt)
|
||||||
|
return true
|
||||||
|
} else if errors.Is(err, ErrDrop) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if action != nil {
|
if action != nil {
|
||||||
|
@@ -668,7 +668,11 @@ func (s *System) processIPv4ICMP(ipHdr header.IPv4, icmpHdr header.ICMPv4) (bool
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, nil
|
if errors.Is(err, ErrReset) {
|
||||||
|
return false, s.rejectIPv4WithICMP(ipHdr, header.ICMPv4PortUnreachable)
|
||||||
|
} else if errors.Is(err, ErrDrop) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if action != nil {
|
if action != nil {
|
||||||
return false, action.WritePacket(buf.As(ipHdr).ToOwned())
|
return false, action.WritePacket(buf.As(ipHdr).ToOwned())
|
||||||
@@ -739,7 +743,9 @@ func (s *System) processIPv6ICMP(ipHdr header.IPv6, icmpHdr header.ICMPv6) (bool
|
|||||||
timeout,
|
timeout,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if errors.Is(err, ErrReset) {
|
||||||
|
return false, s.rejectIPv6WithICMP(ipHdr, header.ICMPv6PortUnreachable)
|
||||||
|
} else if errors.Is(err, ErrDrop) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
if action != nil {
|
if action != nil {
|
||||||
|
Reference in New Issue
Block a user