Skip to content

Commit

Permalink
Rename ping endpoints to icmp endpoints.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 235248572
Change-Id: I5b0538b6feb365a98712c2a2d56d856fe80a8a09
  • Loading branch information
kevinGC authored and shentubot committed Feb 22, 2019
1 parent 532f4b2 commit b75aa51
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion pkg/tcpip/network/arp/BUILD
Expand Up @@ -30,6 +30,6 @@ go_test(
"//pkg/tcpip/link/sniffer",
"//pkg/tcpip/network/ipv4",
"//pkg/tcpip/stack",
"//pkg/tcpip/transport/ping",
"//pkg/tcpip/transport/icmp",
],
)
4 changes: 2 additions & 2 deletions pkg/tcpip/network/arp/arp_test.go
Expand Up @@ -26,7 +26,7 @@ import (
"gvisor.googlesource.com/gvisor/pkg/tcpip/network/arp"
"gvisor.googlesource.com/gvisor/pkg/tcpip/network/ipv4"
"gvisor.googlesource.com/gvisor/pkg/tcpip/stack"
"gvisor.googlesource.com/gvisor/pkg/tcpip/transport/ping"
"gvisor.googlesource.com/gvisor/pkg/tcpip/transport/icmp"
)

const (
Expand All @@ -43,7 +43,7 @@ type testContext struct {
}

func newTestContext(t *testing.T) *testContext {
s := stack.New([]string{ipv4.ProtocolName, arp.ProtocolName}, []string{ping.ProtocolName4}, stack.Options{})
s := stack.New([]string{ipv4.ProtocolName, arp.ProtocolName}, []string{icmp.ProtocolName4}, stack.Options{})

const defaultMTU = 65536
id, linkEP := channel.New(256, defaultMTU, stackLinkAddr)
Expand Down
2 changes: 1 addition & 1 deletion pkg/tcpip/network/ipv6/BUILD
Expand Up @@ -32,7 +32,7 @@ go_test(
"//pkg/tcpip/link/channel",
"//pkg/tcpip/link/sniffer",
"//pkg/tcpip/stack",
"//pkg/tcpip/transport/ping",
"//pkg/tcpip/transport/icmp",
"//pkg/waiter",
],
)
6 changes: 3 additions & 3 deletions pkg/tcpip/network/ipv6/icmp_test.go
Expand Up @@ -27,7 +27,7 @@ import (
"gvisor.googlesource.com/gvisor/pkg/tcpip/link/channel"
"gvisor.googlesource.com/gvisor/pkg/tcpip/link/sniffer"
"gvisor.googlesource.com/gvisor/pkg/tcpip/stack"
"gvisor.googlesource.com/gvisor/pkg/tcpip/transport/ping"
"gvisor.googlesource.com/gvisor/pkg/tcpip/transport/icmp"
"gvisor.googlesource.com/gvisor/pkg/waiter"
)

Expand Down Expand Up @@ -68,8 +68,8 @@ func (e endpointWithResolutionCapability) Capabilities() stack.LinkEndpointCapab
func newTestContext(t *testing.T) *testContext {
c := &testContext{
t: t,
s0: stack.New([]string{ProtocolName}, []string{ping.ProtocolName6}, stack.Options{}),
s1: stack.New([]string{ProtocolName}, []string{ping.ProtocolName6}, stack.Options{}),
s0: stack.New([]string{ProtocolName}, []string{icmp.ProtocolName6}, stack.Options{}),
s1: stack.New([]string{ProtocolName}, []string{icmp.ProtocolName6}, stack.Options{}),
icmpCh: make(chan icmpInfo, 10),
}

Expand Down
20 changes: 10 additions & 10 deletions pkg/tcpip/transport/ping/BUILD → pkg/tcpip/transport/icmp/BUILD
Expand Up @@ -4,26 +4,26 @@ load("//tools/go_generics:defs.bzl", "go_template_instance")
load("//tools/go_stateify:defs.bzl", "go_library")

go_template_instance(
name = "ping_packet_list",
out = "ping_packet_list.go",
package = "ping",
prefix = "pingPacket",
name = "icmp_packet_list",
out = "icmp_packet_list.go",
package = "icmp",
prefix = "icmpPacket",
template = "//pkg/ilist:generic_list",
types = {
"Element": "*pingPacket",
"Linker": "*pingPacket",
"Element": "*icmpPacket",
"Linker": "*icmpPacket",
},
)

go_library(
name = "ping",
name = "icmp",
srcs = [
"endpoint.go",
"endpoint_state.go",
"ping_packet_list.go",
"icmp_packet_list.go",
"protocol.go",
],
importpath = "gvisor.googlesource.com/gvisor/pkg/tcpip/transport/ping",
importpath = "gvisor.googlesource.com/gvisor/pkg/tcpip/transport/icmp",
imports = ["gvisor.googlesource.com/gvisor/pkg/tcpip/buffer"],
visibility = ["//visibility:public"],
deps = [
Expand All @@ -39,7 +39,7 @@ go_library(
filegroup(
name = "autogen",
srcs = [
"ping_packet_list.go",
"icmp_packet_list.go",
],
visibility = ["//:sandbox"],
)
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package ping
package icmp

import (
"encoding/binary"
Expand All @@ -27,8 +27,8 @@ import (
)

// +stateify savable
type pingPacket struct {
pingPacketEntry
type icmpPacket struct {
icmpPacketEntry
senderAddress tcpip.FullAddress
data buffer.VectorisedView `state:".(buffer.VectorisedView)"`
timestamp int64
Expand All @@ -46,10 +46,10 @@ const (
stateClosed
)

// endpoint represents a ping endpoint. This struct serves as the interface
// between users of the endpoint and the protocol implementation; it is legal to
// have concurrent goroutines make calls into the endpoint, they are properly
// synchronized.
// endpoint represents an ICMP (ping) endpoint. This struct serves as the
// interface between users of the endpoint and the protocol implementation; it
// is legal to have concurrent goroutines make calls into the endpoint, they
// are properly synchronized.
type endpoint struct {
// The following fields are initialized at creation time and do not
// change throughout the lifetime of the endpoint.
Expand All @@ -62,7 +62,7 @@ type endpoint struct {
// protected by rcvMu.
rcvMu sync.Mutex `state:"nosave"`
rcvReady bool
rcvList pingPacketList
rcvList icmpPacketList
rcvBufSizeMax int `state:".(int)"`
rcvBufSize int
rcvClosed bool
Expand Down Expand Up @@ -669,7 +669,7 @@ func (e *endpoint) HandlePacket(r *stack.Route, id stack.TransportEndpointID, vv
wasEmpty := e.rcvBufSize == 0

// Push new packet into receive list and increment the buffer size.
pkt := &pingPacket{
pkt := &icmpPacket{
senderAddress: tcpip.FullAddress{
NIC: r.NICID(),
Addr: id.RemoteAddress,
Expand Down
Expand Up @@ -12,23 +12,23 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package ping
package icmp

import (
"gvisor.googlesource.com/gvisor/pkg/tcpip"
"gvisor.googlesource.com/gvisor/pkg/tcpip/buffer"
"gvisor.googlesource.com/gvisor/pkg/tcpip/stack"
)

// saveData saves pingPacket.data field.
func (p *pingPacket) saveData() buffer.VectorisedView {
// saveData saves icmpPacket.data field.
func (p *icmpPacket) saveData() buffer.VectorisedView {
// We cannot save p.data directly as p.data.views may alias to p.views,
// which is not allowed by state framework (in-struct pointer).
return p.data.Clone(nil)
}

// loadData loads pingPacket.data field.
func (p *pingPacket) loadData(data buffer.VectorisedView) {
// loadData loads icmpPacket.data field.
func (p *icmpPacket) loadData(data buffer.VectorisedView) {
// NOTE: We cannot do the p.data = data.Clone(p.views[:]) optimization
// here because data.views is not guaranteed to be loaded by now. Plus,
// data.views will be allocated anyway so there really is little point
Expand Down
Expand Up @@ -12,15 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package ping contains the implementation of the ICMP and IPv6-ICMP transport
// Package icmp contains the implementation of the ICMP and IPv6-ICMP transport
// protocols for use in ping. To use it in the networking stack, this package
// must be added to the project, and
// activated on the stack by passing ping.ProtocolName (or "ping") and/or
// ping.ProtocolName6 (or "ping6") as one of the transport protocols when
// activated on the stack by passing icmp.ProtocolName (or "icmp") and/or
// icmp.ProtocolName6 (or "icmp6") as one of the transport protocols when
// calling stack.New(). Then endpoints can be created by passing
// ping.ProtocolNumber or ping.ProtocolNumber6 as the transport protocol number
// icmp.ProtocolNumber or icmp.ProtocolNumber6 as the transport protocol number
// when calling Stack.NewEndpoint().
package ping
package icmp

import (
"encoding/binary"
Expand All @@ -34,14 +34,14 @@ import (
)

const (
// ProtocolName4 is the string representation of the ping protocol name.
ProtocolName4 = "ping4"
// ProtocolName4 is the string representation of the icmp protocol name.
ProtocolName4 = "icmp4"

// ProtocolNumber4 is the ICMP protocol number.
ProtocolNumber4 = header.ICMPv4ProtocolNumber

// ProtocolName6 is the string representation of the ping protocol name.
ProtocolName6 = "ping6"
// ProtocolName6 is the string representation of the icmp protocol name.
ProtocolName6 = "icmp6"

// ProtocolNumber6 is the IPv6-ICMP protocol number.
ProtocolNumber6 = header.ICMPv6ProtocolNumber
Expand All @@ -66,15 +66,15 @@ func (p *protocol) netProto() tcpip.NetworkProtocolNumber {
panic(fmt.Sprint("unknown protocol number: ", p.number))
}

// NewEndpoint creates a new ping endpoint.
// NewEndpoint creates a new icmp endpoint.
func (p *protocol) NewEndpoint(stack *stack.Stack, netProto tcpip.NetworkProtocolNumber, waiterQueue *waiter.Queue) (tcpip.Endpoint, *tcpip.Error) {
if netProto != p.netProto() {
return nil, tcpip.ErrUnknownProtocol
}
return newEndpoint(stack, netProto, p.number, waiterQueue), nil
}

// MinimumPacketSize returns the minimum valid ping packet size.
// MinimumPacketSize returns the minimum valid icmp packet size.
func (p *protocol) MinimumPacketSize() int {
switch p.number {
case ProtocolNumber4:
Expand All @@ -85,7 +85,7 @@ func (p *protocol) MinimumPacketSize() int {
panic(fmt.Sprint("unknown protocol number: ", p.number))
}

// ParsePorts returns the source and destination ports stored in the given ping
// ParsePorts returns the source and destination ports stored in the given icmp
// packet.
func (p *protocol) ParsePorts(v buffer.View) (src, dst uint16, err *tcpip.Error) {
switch p.number {
Expand Down
2 changes: 1 addition & 1 deletion runsc/boot/BUILD
Expand Up @@ -75,7 +75,7 @@ go_library(
"//pkg/tcpip/network/ipv4",
"//pkg/tcpip/network/ipv6",
"//pkg/tcpip/stack",
"//pkg/tcpip/transport/ping",
"//pkg/tcpip/transport/icmp",
"//pkg/tcpip/transport/tcp",
"//pkg/tcpip/transport/udp",
"//pkg/urpc",
Expand Down
4 changes: 2 additions & 2 deletions runsc/boot/loader.go
Expand Up @@ -51,7 +51,7 @@ import (
"gvisor.googlesource.com/gvisor/pkg/tcpip/network/ipv4"
"gvisor.googlesource.com/gvisor/pkg/tcpip/network/ipv6"
"gvisor.googlesource.com/gvisor/pkg/tcpip/stack"
"gvisor.googlesource.com/gvisor/pkg/tcpip/transport/ping"
"gvisor.googlesource.com/gvisor/pkg/tcpip/transport/icmp"
"gvisor.googlesource.com/gvisor/pkg/tcpip/transport/tcp"
"gvisor.googlesource.com/gvisor/pkg/tcpip/transport/udp"
"gvisor.googlesource.com/gvisor/runsc/boot/filter"
Expand Down Expand Up @@ -766,7 +766,7 @@ func newEmptyNetworkStack(conf *Config, clock tcpip.Clock) (inet.Stack, error) {
case NetworkNone, NetworkSandbox:
// NetworkNone sets up loopback using netstack.
netProtos := []string{ipv4.ProtocolName, ipv6.ProtocolName, arp.ProtocolName}
protoNames := []string{tcp.ProtocolName, udp.ProtocolName, ping.ProtocolName4}
protoNames := []string{tcp.ProtocolName, udp.ProtocolName, icmp.ProtocolName4}
s := epsocket.Stack{stack.New(netProtos, protoNames, stack.Options{
Clock: clock,
Stats: epsocket.Metrics,
Expand Down

0 comments on commit b75aa51

Please sign in to comment.