mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-08 18:20:41 +08:00
Chore: update stack icmp
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
package stack
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"gvisor.dev/gvisor/pkg/tcpip"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/header"
|
||||
)
|
||||
|
||||
func withICMPHandler() Option {
|
||||
@@ -13,28 +11,14 @@ func withICMPHandler() Option {
|
||||
// This will handle all incoming ICMP packets.
|
||||
s.SetRouteTable([]tcpip.Route{
|
||||
{
|
||||
Destination: mustSubnet("0.0.0.0/0"),
|
||||
Destination: header.IPv4EmptySubnet,
|
||||
NIC: s.nicID,
|
||||
},
|
||||
{
|
||||
Destination: mustSubnet("::/0"),
|
||||
Destination: header.IPv6EmptySubnet,
|
||||
NIC: s.nicID,
|
||||
},
|
||||
})
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// mustSubnet returns tcpip.Subnet from CIDR string.
|
||||
func mustSubnet(s string) tcpip.Subnet {
|
||||
_, ipNet, err := net.ParseCIDR(s)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("parse CIDR: %w", err))
|
||||
}
|
||||
|
||||
subnet, err := tcpip.NewSubnet(tcpip.Address(ipNet.IP), tcpip.AddressMask(ipNet.Mask))
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("new subnet: %w", err))
|
||||
}
|
||||
return subnet
|
||||
}
|
||||
|
Reference in New Issue
Block a user