diff --git a/stack/icmp.go b/stack/icmp.go index 51d8556..87b2dd4 100755 --- a/stack/icmp.go +++ b/stack/icmp.go @@ -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 -}