From 9d5239e7147d4385064a06ed159ae709c2006deb Mon Sep 17 00:00:00 2001 From: Arthur Sfez Date: Tue, 22 Feb 2022 16:16:33 -0800 Subject: [PATCH] Rename ControlMessages type to indicate the cmsg direction With the introduction of sendable control messages, the original cmsg type is now renamed to ReceivableControlMessages. PiperOrigin-RevId: 430319598 --- pkg/sentry/socket/netstack/netstack.go | 6 +++--- pkg/sentry/socket/socket.go | 6 +++--- pkg/tcpip/checker/checker.go | 28 +++++++++++++------------- pkg/tcpip/tcpip.go | 6 +++--- pkg/tcpip/tcpip_state.go | 4 ++-- pkg/tcpip/transport/icmp/endpoint.go | 2 +- pkg/tcpip/transport/packet/endpoint.go | 2 +- pkg/tcpip/transport/raw/endpoint.go | 2 +- pkg/tcpip/transport/udp/endpoint.go | 2 +- 9 files changed, 29 insertions(+), 29 deletions(-) diff --git a/pkg/sentry/socket/netstack/netstack.go b/pkg/sentry/socket/netstack/netstack.go index 10b12ce5e..1537cff43 100644 --- a/pkg/sentry/socket/netstack/netstack.go +++ b/pkg/sentry/socket/netstack/netstack.go @@ -2897,7 +2897,7 @@ func (s *socketOpsCommon) nonBlockingRead(ctx context.Context, dst usermem.IOSeq return res.Count, 0, nil, 0, cmsg, syserr.TranslateNetstackError(err) } -func (s *socketOpsCommon) controlMessages(cm tcpip.ControlMessages) socket.ControlMessages { +func (s *socketOpsCommon) controlMessages(cm tcpip.ReceivableControlMessages) socket.ControlMessages { readCM := socket.NewIPControlMessages(s.family, cm) return socket.ControlMessages{ IP: socket.IPControlMessages{ @@ -2927,7 +2927,7 @@ func (s *socketOpsCommon) controlMessages(cm tcpip.ControlMessages) socket.Contr // successfully writing packet data out to userspace. // // Precondition: s.readMu must be locked. -func (s *socketOpsCommon) updateTimestamp(cm tcpip.ControlMessages) { +func (s *socketOpsCommon) updateTimestamp(cm tcpip.ReceivableControlMessages) { // Save the SIOCGSTAMP timestamp only if SO_TIMESTAMP is disabled. if !s.sockOptTimestamp { s.timestampValid = true @@ -2984,7 +2984,7 @@ func (s *socketOpsCommon) recvErr(t *kernel.Task, dst usermem.IOSequence) (int, // The original destination address of the datagram that caused the error is // supplied via msg_name. -- recvmsg(2) dstAddr, dstAddrLen := socket.ConvertAddress(addrFamilyFromNetProto(sockErr.NetProto), sockErr.Dst) - cmgs := socket.ControlMessages{IP: socket.NewIPControlMessages(s.family, tcpip.ControlMessages{SockErr: sockErr})} + cmgs := socket.ControlMessages{IP: socket.NewIPControlMessages(s.family, tcpip.ReceivableControlMessages{SockErr: sockErr})} return n, msgFlags, dstAddr, dstAddrLen, cmgs, syserr.FromError(err) } diff --git a/pkg/sentry/socket/socket.go b/pkg/sentry/socket/socket.go index 0261071bf..8e1fa4764 100644 --- a/pkg/sentry/socket/socket.go +++ b/pkg/sentry/socket/socket.go @@ -119,9 +119,9 @@ func sockErrCmsgToLinux(sockErr *tcpip.SockError) linux.SockErrCMsg { } } -// NewIPControlMessages converts the tcpip ControlMessages (which does not have -// Linux specific format) to Linux format. -func NewIPControlMessages(family int, cmgs tcpip.ControlMessages) IPControlMessages { +// NewIPControlMessages converts the tcpip.ReceivableControlMessages (which does +// not have Linux specific format) to Linux format. +func NewIPControlMessages(family int, cmgs tcpip.ReceivableControlMessages) IPControlMessages { var orgDstAddr linux.SockAddr if cmgs.HasOriginalDstAddress { orgDstAddr, _ = ConvertAddress(family, cmgs.OriginalDstAddress) diff --git a/pkg/tcpip/checker/checker.go b/pkg/tcpip/checker/checker.go index f18286d53..e718e5f66 100644 --- a/pkg/tcpip/checker/checker.go +++ b/pkg/tcpip/checker/checker.go @@ -36,7 +36,7 @@ type NetworkChecker func(*testing.T, []header.Network) type TransportChecker func(*testing.T, header.Transport) // ControlMessagesChecker is a function to check a property of ancillary data. -type ControlMessagesChecker func(*testing.T, tcpip.ControlMessages) +type ControlMessagesChecker func(*testing.T, tcpip.ReceivableControlMessages) // IPv4 checks the validity and properties of the given IPv4 packet. It is // expected to be used in conjunction with other network checkers for specific @@ -289,7 +289,7 @@ func FragmentFlags(flags uint8) NetworkChecker { // ReceiveTClass creates a checker that checks the TCLASS field in // ControlMessages. func ReceiveTClass(want uint32) ControlMessagesChecker { - return func(t *testing.T, cm tcpip.ControlMessages) { + return func(t *testing.T, cm tcpip.ReceivableControlMessages) { t.Helper() if !cm.HasTClass { t.Error("got cm.HasTClass = false, want = true") @@ -302,7 +302,7 @@ func ReceiveTClass(want uint32) ControlMessagesChecker { // NoTClassReceived creates a checker that checks the absence of the TCLASS // field in ControlMessages. func NoTClassReceived() ControlMessagesChecker { - return func(t *testing.T, cm tcpip.ControlMessages) { + return func(t *testing.T, cm tcpip.ReceivableControlMessages) { t.Helper() if cm.HasTClass { t.Error("got cm.HasTClass = true, want = false") @@ -312,7 +312,7 @@ func NoTClassReceived() ControlMessagesChecker { // ReceiveTOS creates a checker that checks the TOS field in ControlMessages. func ReceiveTOS(want uint8) ControlMessagesChecker { - return func(t *testing.T, cm tcpip.ControlMessages) { + return func(t *testing.T, cm tcpip.ReceivableControlMessages) { t.Helper() if !cm.HasTOS { t.Error("got cm.HasTOS = false, want = true") @@ -325,7 +325,7 @@ func ReceiveTOS(want uint8) ControlMessagesChecker { // NoTOSReceived creates a checker that checks the absence of the TOS field in // ControlMessages. func NoTOSReceived() ControlMessagesChecker { - return func(t *testing.T, cm tcpip.ControlMessages) { + return func(t *testing.T, cm tcpip.ReceivableControlMessages) { t.Helper() if cm.HasTOS { t.Error("got cm.HasTOS = true, want = false") @@ -336,7 +336,7 @@ func NoTOSReceived() ControlMessagesChecker { // ReceiveTTL creates a checker that checks the TTL field in // ControlMessages. func ReceiveTTL(want uint8) ControlMessagesChecker { - return func(t *testing.T, cm tcpip.ControlMessages) { + return func(t *testing.T, cm tcpip.ReceivableControlMessages) { t.Helper() if !cm.HasTTL { t.Errorf("got cm.HasTTL = %t, want = true", cm.HasTTL) @@ -349,7 +349,7 @@ func ReceiveTTL(want uint8) ControlMessagesChecker { // NoTTLReceived creates a checker that checks the absence of the TTL field in // ControlMessages. func NoTTLReceived() ControlMessagesChecker { - return func(t *testing.T, cm tcpip.ControlMessages) { + return func(t *testing.T, cm tcpip.ReceivableControlMessages) { t.Helper() if cm.HasTTL { t.Error("got cm.HasTTL = true, want = false") @@ -360,7 +360,7 @@ func NoTTLReceived() ControlMessagesChecker { // ReceiveHopLimit creates a checker that checks the HopLimit field in // ControlMessages. func ReceiveHopLimit(want uint8) ControlMessagesChecker { - return func(t *testing.T, cm tcpip.ControlMessages) { + return func(t *testing.T, cm tcpip.ReceivableControlMessages) { t.Helper() if !cm.HasHopLimit { t.Errorf("got cm.HasHopLimit = %t, want = true", cm.HasHopLimit) @@ -373,7 +373,7 @@ func ReceiveHopLimit(want uint8) ControlMessagesChecker { // NoHopLimitReceived creates a checker that checks the absence of the HopLimit // field in ControlMessages. func NoHopLimitReceived() ControlMessagesChecker { - return func(t *testing.T, cm tcpip.ControlMessages) { + return func(t *testing.T, cm tcpip.ReceivableControlMessages) { t.Helper() if cm.HasHopLimit { t.Error("got cm.HasHopLimit = true, want = false") @@ -384,7 +384,7 @@ func NoHopLimitReceived() ControlMessagesChecker { // ReceiveIPPacketInfo creates a checker that checks the PacketInfo field in // ControlMessages. func ReceiveIPPacketInfo(want tcpip.IPPacketInfo) ControlMessagesChecker { - return func(t *testing.T, cm tcpip.ControlMessages) { + return func(t *testing.T, cm tcpip.ReceivableControlMessages) { t.Helper() if !cm.HasIPPacketInfo { t.Error("got cm.HasIPPacketInfo = false, want = true") @@ -397,7 +397,7 @@ func ReceiveIPPacketInfo(want tcpip.IPPacketInfo) ControlMessagesChecker { // NoIPPacketInfoReceived creates a checker that checks the PacketInfo field in // ControlMessages. func NoIPPacketInfoReceived() ControlMessagesChecker { - return func(t *testing.T, cm tcpip.ControlMessages) { + return func(t *testing.T, cm tcpip.ReceivableControlMessages) { t.Helper() if cm.HasIPPacketInfo { t.Error("got cm.HasIPPacketInfo = true, want = false") @@ -408,7 +408,7 @@ func NoIPPacketInfoReceived() ControlMessagesChecker { // ReceiveIPv6PacketInfo creates a checker that checks the IPv6PacketInfo field // in ControlMessages. func ReceiveIPv6PacketInfo(want tcpip.IPv6PacketInfo) ControlMessagesChecker { - return func(t *testing.T, cm tcpip.ControlMessages) { + return func(t *testing.T, cm tcpip.ReceivableControlMessages) { t.Helper() if !cm.HasIPv6PacketInfo { t.Error("got cm.HasIPv6PacketInfo = false, want = true") @@ -421,7 +421,7 @@ func ReceiveIPv6PacketInfo(want tcpip.IPv6PacketInfo) ControlMessagesChecker { // NoIPv6PacketInfoReceived creates a checker that checks the PacketInfo field // in ControlMessages. func NoIPv6PacketInfoReceived() ControlMessagesChecker { - return func(t *testing.T, cm tcpip.ControlMessages) { + return func(t *testing.T, cm tcpip.ReceivableControlMessages) { t.Helper() if cm.HasIPv6PacketInfo { t.Error("got cm.HasIPv6PacketInfo = true, want = false") @@ -432,7 +432,7 @@ func NoIPv6PacketInfoReceived() ControlMessagesChecker { // ReceiveOriginalDstAddr creates a checker that checks the OriginalDstAddress // field in ControlMessages. func ReceiveOriginalDstAddr(want tcpip.FullAddress) ControlMessagesChecker { - return func(t *testing.T, cm tcpip.ControlMessages) { + return func(t *testing.T, cm tcpip.ReceivableControlMessages) { t.Helper() if !cm.HasOriginalDstAddress { t.Error("got cm.HasOriginalDstAddress = false, want = true") diff --git a/pkg/tcpip/tcpip.go b/pkg/tcpip/tcpip.go index 64e7f0f43..726d3ac6c 100644 --- a/pkg/tcpip/tcpip.go +++ b/pkg/tcpip/tcpip.go @@ -416,10 +416,10 @@ func (l *LimitedWriter) Write(p []byte) (int, error) { return n, err } -// A ControlMessages contains socket control messages for IP sockets. +// ReceivableControlMessages holds control messages that can be received. // // +stateify savable -type ControlMessages struct { +type ReceivableControlMessages struct { // HasTimestamp indicates whether Timestamp is valid/set. HasTimestamp bool @@ -514,7 +514,7 @@ type ReadResult struct { Total int // ControlMessages is the control messages received. - ControlMessages ControlMessages + ControlMessages ReceivableControlMessages // RemoteAddr is the remote address if ReadOptions.NeedAddr is true. RemoteAddr FullAddress diff --git a/pkg/tcpip/tcpip_state.go b/pkg/tcpip/tcpip_state.go index 1953e24a1..5181e355a 100644 --- a/pkg/tcpip/tcpip_state.go +++ b/pkg/tcpip/tcpip_state.go @@ -18,10 +18,10 @@ import ( "time" ) -func (c *ControlMessages) saveTimestamp() int64 { +func (c *ReceivableControlMessages) saveTimestamp() int64 { return c.Timestamp.UnixNano() } -func (c *ControlMessages) loadTimestamp(nsec int64) { +func (c *ReceivableControlMessages) loadTimestamp(nsec int64) { c.Timestamp = time.Unix(0, nsec) } diff --git a/pkg/tcpip/transport/icmp/endpoint.go b/pkg/tcpip/transport/icmp/endpoint.go index a995614fb..f939bd966 100644 --- a/pkg/tcpip/transport/icmp/endpoint.go +++ b/pkg/tcpip/transport/icmp/endpoint.go @@ -187,7 +187,7 @@ func (e *endpoint) Read(dst io.Writer, opts tcpip.ReadOptions) (tcpip.ReadResult // Control Messages // TODO(https://gvisor.dev/issue/7012): Share control message code with other // network endpoints. - cm := tcpip.ControlMessages{ + cm := tcpip.ReceivableControlMessages{ HasTimestamp: true, Timestamp: p.receivedAt, } diff --git a/pkg/tcpip/transport/packet/endpoint.go b/pkg/tcpip/transport/packet/endpoint.go index d3250df7d..7afc88c1a 100644 --- a/pkg/tcpip/transport/packet/endpoint.go +++ b/pkg/tcpip/transport/packet/endpoint.go @@ -180,7 +180,7 @@ func (ep *endpoint) Read(dst io.Writer, opts tcpip.ReadOptions) (tcpip.ReadResul res := tcpip.ReadResult{ Total: packet.data.Size(), - ControlMessages: tcpip.ControlMessages{ + ControlMessages: tcpip.ReceivableControlMessages{ HasTimestamp: true, Timestamp: packet.receivedAt, }, diff --git a/pkg/tcpip/transport/raw/endpoint.go b/pkg/tcpip/transport/raw/endpoint.go index a9d3cb0ee..089de7f7a 100644 --- a/pkg/tcpip/transport/raw/endpoint.go +++ b/pkg/tcpip/transport/raw/endpoint.go @@ -236,7 +236,7 @@ func (e *endpoint) Read(dst io.Writer, opts tcpip.ReadOptions) (tcpip.ReadResult // Control Messages // TODO(https://gvisor.dev/issue/7012): Share control message code with other // network endpoints. - cm := tcpip.ControlMessages{ + cm := tcpip.ReceivableControlMessages{ HasTimestamp: true, Timestamp: pkt.receivedAt, } diff --git a/pkg/tcpip/transport/udp/endpoint.go b/pkg/tcpip/transport/udp/endpoint.go index 5ca019d86..07e13e970 100644 --- a/pkg/tcpip/transport/udp/endpoint.go +++ b/pkg/tcpip/transport/udp/endpoint.go @@ -239,7 +239,7 @@ func (e *endpoint) Read(dst io.Writer, opts tcpip.ReadOptions) (tcpip.ReadResult // Control Messages // TODO(https://gvisor.dev/issue/7012): Share control message code with other // network endpoints. - cm := tcpip.ControlMessages{ + cm := tcpip.ReceivableControlMessages{ HasTimestamp: true, Timestamp: p.receivedAt, }