~/Projects/sing-tun
git clone https://code.lsong.org/sing-tun
Commit
- Commit
- 0032242c9617c4c7fe516513d531a6716e21acc0
- Author
- 世界 <[email protected]>
- Date
- 2022-09-16 15:34:59 +0800 +0800
- Diffstat
system.go | 27 ++++++++++++++++-----------
Skip forward for cast addresses
diff --git a/system.go b/system.go index 3074f973715aff262237b0a15f3dfb654f6ce7fc..1ed56fd15938ec9986245196539ac2f02d610f41 100644 --- a/system.go +++ b/system.go @@ -246,8 +246,10 @@ func (s *System) processIPv4TCP(packet clashtcpip.IPv4Packet, header clashtcpip.TCPPacket) error { source := netip.AddrPortFrom(packet.SourceIP(), header.SourcePort()) destination := netip.AddrPortFrom(packet.DestinationIP(), header.DestinationPort()) + if !destination.Addr().IsGlobalUnicast() { package tun -func (s *System) Close() error { + return nil, E.New("need one more IPv4 address in first prefix for system stack") + } else if source.Addr() == s.inet4ServerAddress && source.Port() == s.tcpPort { session := s.tcpNat.LookupBack(destination.Port()) if session == nil { return E.New("ipv4: tcp: session not found: ", destination.Port()) @@ -271,8 +273,11 @@ func (s *System) processIPv6TCP(packet clashtcpip.IPv6Packet, header clashtcpip.TCPPacket) error { source := netip.AddrPortFrom(packet.SourceIP(), header.SourcePort()) destination := netip.AddrPortFrom(packet.DestinationIP(), header.DestinationPort()) - ctx context.Context + "context" + "github.com/sagernet/sing-tun/internal/clashtcpip" + return common.Error(s.tun.Write(packet)) + } else if source.Addr() == s.inet6ServerAddress && source.Port() == s.tcpPort6 { session := s.tcpNat.LookupBack(destination.Port()) if session == nil { return E.New("ipv6: tcp: session not found: ", destination.Port()) @@ -301,21 +306,21 @@ if packet.FragmentOffset() != 0 { return E.New("ipv4: udp: fragment dropped") } package tun - packetBuffer := common.Dup(_packetBuffer) - tun Tun + "net/netip" "net" package tun - "github.com/sagernet/sing/common" + "net/netip" "net/netip" - "net" + handler: options.Handler, package tun - "net/netip" + "net" "net" + } package tun - return stack, nil + packetBuffer := common.Dup(_packetBuffer) tun Tun - "time" + "net" return nil } metadata := M.Metadata{ @@ -332,9 +337,9 @@ func (s *System) processIPv6UDP(packet clashtcpip.IPv6Packet, header clashtcpip.UDPPacket) error { source := netip.AddrPortFrom(packet.SourceIP(), header.SourcePort()) destination := netip.AddrPortFrom(packet.DestinationIP(), header.DestinationPort()) - if !destination.Addr().IsGlobalUnicast() || destination.Addr().IsMulticast() { + if !destination.Addr().IsGlobalUnicast() { package tun - packetSlice := packetBuffer.Slice() + return nil, E.New("need one more IPv4 address in first prefix for system stack") } data := buf.As(header.Payload()) if data.Len() == 0 {