Migrate clashtcpip to gVisor tcpip copied

This commit is contained in:
世界 2024-10-22 15:33:49 +08:00
parent 7f8e556bb0
commit 1793988a6d
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
43 changed files with 7370 additions and 1340 deletions

View file

@ -3,20 +3,21 @@ package tun
import (
"strconv"
"github.com/sagernet/sing-tun/internal/clashtcpip"
"github.com/sagernet/sing-tun/internal/gtcpip"
"github.com/sagernet/sing-tun/internal/gtcpip/header"
F "github.com/sagernet/sing/common/format"
N "github.com/sagernet/sing/common/network"
)
func NetworkName(network uint8) string {
switch network {
case clashtcpip.TCP:
switch tcpip.TransportProtocolNumber(network) {
case header.TCPProtocolNumber:
return N.NetworkTCP
case clashtcpip.UDP:
case header.UDPProtocolNumber:
return N.NetworkUDP
case clashtcpip.ICMP:
case header.ICMPv4ProtocolNumber:
return N.NetworkICMPv4
case clashtcpip.ICMPv6:
case header.ICMPv6ProtocolNumber:
return N.NetworkICMPv6
}
return F.ToString(network)
@ -25,13 +26,13 @@ func NetworkName(network uint8) string {
func NetworkFromName(name string) uint8 {
switch name {
case N.NetworkTCP:
return clashtcpip.TCP
return uint8(header.TCPProtocolNumber)
case N.NetworkUDP:
return clashtcpip.UDP
return uint8(header.UDPProtocolNumber)
case N.NetworkICMPv4:
return clashtcpip.ICMP
return uint8(header.ICMPv4ProtocolNumber)
case N.NetworkICMPv6:
return clashtcpip.ICMPv6
return uint8(header.ICMPv6ProtocolNumber)
}
parseNetwork, err := strconv.ParseUint(name, 10, 8)
if err != nil {