Support icmpv6 transport protocol

PiperOrigin-RevId: 346101076
This commit is contained in:
Peter Johnston
2020-12-07 08:44:44 -08:00
committed by gVisor bot
parent a97ceec01b
commit eeb23531eb
8 changed files with 136 additions and 5 deletions
+1 -1
View File
@@ -207,7 +207,7 @@ swgso-tests: load-basic-images
hostnet-tests: load-basic-images
@$(call submake,install-runtime RUNTIME="hostnet" ARGS="--network=host")
@$(call submake,test-runtime RUNTIME="hostnet" OPTIONS="--test_arg=-checkpoint=false" TARGETS="$(INTEGRATION_TARGETS)")
@$(call submake,test-runtime RUNTIME="hostnet" OPTIONS="--test_arg=-checkpoint=false --test_arg=-hostnet=true" TARGETS="$(INTEGRATION_TARGETS)")
.PHONY: hostnet-tests
kvm-tests: load-basic-images
+7
View File
@@ -0,0 +1,7 @@
FROM ubuntu:bionic
WORKDIR /root
COPY ping4.sh .
RUN chmod +x ping4.sh
RUN apt-get update && apt-get install -y iputils-ping
+25
View File
@@ -0,0 +1,25 @@
#!/bin/bash
# Copyright 2020 The gVisor Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -euo pipefail
# The docker API doesn't provide for starting a container, running a command,
# and getting the exit status of the command in one go. The most straightforward
# way to do this is to verify the output of the command, so we output nothing on
# success and an error message on failure.
if ! out=$(ping -c 10 127.0.0.1); then
echo "$out"
fi
+7
View File
@@ -0,0 +1,7 @@
FROM ubuntu:bionic
WORKDIR /root
COPY ping6.sh .
RUN chmod +x ping6.sh
RUN apt-get update && apt-get install -y iputils-ping iproute2
+32
View File
@@ -0,0 +1,32 @@
#!/bin/bash
# Copyright 2020 The gVisor Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -euo pipefail
# Enable ipv6 on loopback if it's not already enabled. Runsc doesn't enable ipv6
# loopback unless an ipv6 address was assigned to the container, which docker
# does not do by default.
if ! [[ $(ip -6 addr show dev lo) ]]; then
ip addr add ::1 dev lo
fi
# The docker API doesn't provide for starting a container, running a command,
# and getting the exit status of the command in one go. The most straightforward
# way to do this is to verify the output of the command, so we output nothing on
# success and an error message on failure.
if ! out=$(/bin/ping6 -c 10 ::1); then
echo "$out"
fi
+9 -3
View File
@@ -48,9 +48,10 @@ import (
)
var (
checkpoint = flag.Bool("checkpoint", true, "control checkpoint/restore support")
partition = flag.Int("partition", 1, "partition number, this is 1-indexed")
totalPartitions = flag.Int("total_partitions", 1, "total number of partitions")
checkpoint = flag.Bool("checkpoint", true, "control checkpoint/restore support")
partition = flag.Int("partition", 1, "partition number, this is 1-indexed")
totalPartitions = flag.Int("total_partitions", 1, "total number of partitions")
isRunningWithHostNet = flag.Bool("hostnet", false, "whether test is running with hostnet")
)
// IsCheckpointSupported returns the relevant command line flag.
@@ -58,6 +59,11 @@ func IsCheckpointSupported() bool {
return *checkpoint
}
// IsRunningWithHostNet returns the relevant command line flag.
func IsRunningWithHostNet() bool {
return *isRunningWithHostNet
}
// ImageByName mangles the image name used locally. This depends on the image
// build infrastructure in images/ and tools/vm.
func ImageByName(name string) string {
+6 -1
View File
@@ -1082,7 +1082,12 @@ func newRootNetworkNamespace(conf *config.Config, clock tcpip.Clock, uniqueID st
func newEmptySandboxNetworkStack(clock tcpip.Clock, uniqueID stack.UniqueID) (inet.Stack, error) {
netProtos := []stack.NetworkProtocolFactory{ipv4.NewProtocol, ipv6.NewProtocol, arp.NewProtocol}
transProtos := []stack.TransportProtocolFactory{tcp.NewProtocol, udp.NewProtocol, icmp.NewProtocol4}
transProtos := []stack.TransportProtocolFactory{
tcp.NewProtocol,
udp.NewProtocol,
icmp.NewProtocol4,
icmp.NewProtocol6,
}
s := netstack.Stack{stack.New(stack.Options{
NetworkProtocols: netProtos,
TransportProtocols: transProtos,
+49
View File
@@ -494,6 +494,55 @@ func TestLink(t *testing.T) {
}
}
// This test ensures we can run ping without errors.
func TestPing4Loopback(t *testing.T) {
if testutil.IsRunningWithHostNet() {
// TODO(gvisor.dev/issue/5011): support ICMP sockets in hostnet and enable
// this test.
t.Skip("hostnet only supports TCP/UDP sockets, so ping is not supported.")
}
ctx := context.Background()
d := dockerutil.MakeContainer(ctx, t)
defer d.CleanUp(ctx)
if got, err := d.Run(ctx, dockerutil.RunOpts{
Image: "basic/ping4test",
}, "/root/ping4.sh"); err != nil {
t.Fatalf("docker run failed: %s", err)
} else if got != "" {
t.Errorf("test failed:\n%s", got)
}
}
// This test ensures we can enable ipv6 on loopback and run ping6 without
// errors.
func TestPing6Loopback(t *testing.T) {
if testutil.IsRunningWithHostNet() {
// TODO(gvisor.dev/issue/5011): support ICMP sockets in hostnet and enable
// this test.
t.Skip("hostnet only supports TCP/UDP sockets, so ping6 is not supported.")
}
ctx := context.Background()
d := dockerutil.MakeContainer(ctx, t)
defer d.CleanUp(ctx)
if got, err := d.Run(ctx, dockerutil.RunOpts{
Image: "basic/ping6test",
// The CAP_NET_ADMIN capability is required to use the `ip` utility, which
// we use to enable ipv6 on loopback.
//
// By default, ipv6 loopback is not enabled by runsc, because docker does
// not assign an ipv6 address to the test container.
CapAdd: []string{"NET_ADMIN"},
}, "/root/ping6.sh"); err != nil {
t.Fatalf("docker run failed: %s", err)
} else if got != "" {
t.Errorf("test failed:\n%s", got)
}
}
func TestMain(m *testing.M) {
dockerutil.EnsureSupportedDockerVersion()
flag.Parse()