Chore: update stack icmp

This commit is contained in:
xjasonlyu
2021-02-06 17:22:46 +08:00
parent b1700c62f4
commit 6763ca4852

View File

@@ -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
}