diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-07-17 01:43:18 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-07-17 01:43:18 +0000 |
commit | 1d81bf5f979b77928a1a890675b6905862e6fa75 (patch) | |
tree | 0b3624920fa4989888305eb02bdaaca5aff6ae50 /pkg/tcpip/transport | |
parent | 667702d0dd27926f9963d3a1571e0362f45c204e (diff) | |
parent | dcf6ddc2772b8fcf824f1f48e0281e1cc80b93ea (diff) |
Merge release-20200622.1-173-gdcf6ddc27 (automated)
Diffstat (limited to 'pkg/tcpip/transport')
-rw-r--r-- | pkg/tcpip/transport/packet/endpoint.go | 18 | ||||
-rw-r--r-- | pkg/tcpip/transport/packet/packet_state_autogen.go | 3 |
2 files changed, 19 insertions, 2 deletions
diff --git a/pkg/tcpip/transport/packet/endpoint.go b/pkg/tcpip/transport/packet/endpoint.go index 92b487381..7b2083a09 100644 --- a/pkg/tcpip/transport/packet/endpoint.go +++ b/pkg/tcpip/transport/packet/endpoint.go @@ -45,6 +45,9 @@ type packet struct { timestampNS int64 // senderAddr is the network address of the sender. senderAddr tcpip.FullAddress + // packetInfo holds additional information like the protocol + // of the packet etc. + packetInfo tcpip.LinkPacketInfo } // endpoint is the packet socket implementation of tcpip.Endpoint. It is legal @@ -151,8 +154,8 @@ func (ep *endpoint) Close() { // ModerateRecvBuf implements tcpip.Endpoint.ModerateRecvBuf. func (ep *endpoint) ModerateRecvBuf(copied int) {} -// Read implements tcpip.Endpoint.Read. -func (ep *endpoint) Read(addr *tcpip.FullAddress) (buffer.View, tcpip.ControlMessages, *tcpip.Error) { +// Read implements tcpip.PacketEndpoint.ReadPacket. +func (ep *endpoint) ReadPacket(addr *tcpip.FullAddress, info *tcpip.LinkPacketInfo) (buffer.View, tcpip.ControlMessages, *tcpip.Error) { ep.rcvMu.Lock() // If there's no data to read, return that read would block or that the @@ -177,9 +180,18 @@ func (ep *endpoint) Read(addr *tcpip.FullAddress) (buffer.View, tcpip.ControlMes *addr = packet.senderAddr } + if info != nil { + *info = packet.packetInfo + } + return packet.data.ToView(), tcpip.ControlMessages{HasTimestamp: true, Timestamp: packet.timestampNS}, nil } +// Read implements tcpip.Endpoint.Read. +func (ep *endpoint) Read(addr *tcpip.FullAddress) (buffer.View, tcpip.ControlMessages, *tcpip.Error) { + return ep.ReadPacket(addr, nil) +} + func (ep *endpoint) Write(p tcpip.Payloader, opts tcpip.WriteOptions) (int64, <-chan struct{}, *tcpip.Error) { // TODO(b/129292371): Implement. return 0, nil, tcpip.ErrInvalidOptionValue @@ -428,12 +440,14 @@ func (ep *endpoint) HandlePacket(nicID tcpip.NICID, localAddr tcpip.LinkAddress, NIC: nicID, Addr: tcpip.Address(hdr.SourceAddress()), } + packet.packetInfo.Protocol = netProto } else { // Guess the would-be ethernet header. packet.senderAddr = tcpip.FullAddress{ NIC: nicID, Addr: tcpip.Address(localAddr), } + packet.packetInfo.Protocol = netProto } if ep.cooked { diff --git a/pkg/tcpip/transport/packet/packet_state_autogen.go b/pkg/tcpip/transport/packet/packet_state_autogen.go index b7fa1cdc9..e13dd7827 100644 --- a/pkg/tcpip/transport/packet/packet_state_autogen.go +++ b/pkg/tcpip/transport/packet/packet_state_autogen.go @@ -17,6 +17,7 @@ func (x *packet) StateFields() []string { "data", "timestampNS", "senderAddr", + "packetInfo", } } @@ -29,6 +30,7 @@ func (x *packet) StateSave(m state.Sink) { m.Save(0, &x.packetEntry) m.Save(2, &x.timestampNS) m.Save(3, &x.senderAddr) + m.Save(4, &x.packetInfo) } func (x *packet) afterLoad() {} @@ -37,6 +39,7 @@ func (x *packet) StateLoad(m state.Source) { m.Load(0, &x.packetEntry) m.Load(2, &x.timestampNS) m.Load(3, &x.senderAddr) + m.Load(4, &x.packetInfo) m.LoadValue(1, new(buffer.VectorisedView), func(y interface{}) { x.loadData(y.(buffer.VectorisedView)) }) } |