draft: Tun respond ICMP port unreachable when rejecting UDP packets

This commit is contained in:
H1JK
2026-01-01 06:48:36 +08:00
parent 1f8bee9710
commit 58c4110b57
9 changed files with 100 additions and 16 deletions

View File

@@ -33,6 +33,9 @@ type WriterWithUpstream = network.WriterWithUpstream
type WithUpstreamWriter = network.WithUpstreamWriter
type WithUpstream = common.WithUpstream
type HandshakeSuccess = network.HandshakeSuccess
type HandshakeFailure = network.HandshakeFailure
var UnwrapReader = network.UnwrapReader
var UnwrapWriter = network.UnwrapWriter

31
common/utils/cast.go Normal file
View File

@@ -0,0 +1,31 @@
package utils
import (
"fmt"
"net"
)
type WithUpstream interface {
Upstream() any
}
type stdWithUpstreamNetConn interface {
NetConn() net.Conn
}
func Cast[T any](obj any) (_ T, _ bool) {
if c, ok := obj.(T); ok {
fmt.Printf("Got 1: %T\n", obj) // TODO
return c, true
}
if u, ok := obj.(WithUpstream); ok {
fmt.Printf("Upstream 2: %T\n", obj) // TODO
return Cast[T](u.Upstream())
}
if u, ok := obj.(stdWithUpstreamNetConn); ok {
fmt.Printf("Std 3: %T\n", obj) // TODO
return Cast[T](u.NetConn())
}
fmt.Printf("Failed: %T\n", obj) // TODO
return
}