mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-09 02:30:05 +08:00
Chore: update stack icmp
This commit is contained in:
@@ -1,10 +1,8 @@
|
|||||||
package stack
|
package stack
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net"
|
|
||||||
|
|
||||||
"gvisor.dev/gvisor/pkg/tcpip"
|
"gvisor.dev/gvisor/pkg/tcpip"
|
||||||
|
"gvisor.dev/gvisor/pkg/tcpip/header"
|
||||||
)
|
)
|
||||||
|
|
||||||
func withICMPHandler() Option {
|
func withICMPHandler() Option {
|
||||||
@@ -13,28 +11,14 @@ func withICMPHandler() Option {
|
|||||||
// This will handle all incoming ICMP packets.
|
// This will handle all incoming ICMP packets.
|
||||||
s.SetRouteTable([]tcpip.Route{
|
s.SetRouteTable([]tcpip.Route{
|
||||||
{
|
{
|
||||||
Destination: mustSubnet("0.0.0.0/0"),
|
Destination: header.IPv4EmptySubnet,
|
||||||
NIC: s.nicID,
|
NIC: s.nicID,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Destination: mustSubnet("::/0"),
|
Destination: header.IPv6EmptySubnet,
|
||||||
NIC: s.nicID,
|
NIC: s.nicID,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return nil
|
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