mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
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
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
|
||||
+3
-3
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user