diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-02-13 19:02:24 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-02-13 19:02:24 +0000 |
commit | 69e7dd7077f7ae0fc4f94a1759a03ff8162f7e8a (patch) | |
tree | 86eb415c695d90299bd4c7e0ed49cecd2b9037e5 /pkg/tcpip | |
parent | dc1144e4ef518f6a7fbe78ee438af856d8d105f9 (diff) | |
parent | 69bf39e8a47d3b4dcbbd04d2e8df476cdfab5e74 (diff) |
Merge release-20200211.0-11-g69bf39e (automated)
Diffstat (limited to 'pkg/tcpip')
-rw-r--r-- | pkg/tcpip/tcpip.go | 25 | ||||
-rwxr-xr-x | pkg/tcpip/tcpip_state_autogen.go | 20 | ||||
-rw-r--r-- | pkg/tcpip/transport/udp/endpoint.go | 26 | ||||
-rwxr-xr-x | pkg/tcpip/transport/udp/udp_state_autogen.go | 4 |
4 files changed, 75 insertions, 0 deletions
diff --git a/pkg/tcpip/tcpip.go b/pkg/tcpip/tcpip.go index 0e944712f..9ca39ce40 100644 --- a/pkg/tcpip/tcpip.go +++ b/pkg/tcpip/tcpip.go @@ -328,6 +328,12 @@ type ControlMessages struct { // Tclass is the IPv6 traffic class of the associated packet. TClass int32 + + // HasIPPacketInfo indicates whether PacketInfo is set. + HasIPPacketInfo bool + + // PacketInfo holds interface and address data on an incoming packet. + PacketInfo IPPacketInfo } // Endpoint is the interface implemented by transport protocols (e.g., tcp, udp) @@ -503,6 +509,11 @@ const ( // V6OnlyOption is used by {G,S}etSockOptBool to specify whether an IPv6 // socket is to be restricted to sending and receiving IPv6 packets only. V6OnlyOption + + // ReceiveIPPacketInfoOption is used by {G,S}etSockOptBool to specify + // if more inforamtion is provided with incoming packets such + // as interface index and address. + ReceiveIPPacketInfoOption ) // SockOptInt represents socket options which values have the int type. @@ -685,6 +696,20 @@ type IPv4TOSOption uint8 // for all subsequent outgoing IPv6 packets from the endpoint. type IPv6TrafficClassOption uint8 +// IPPacketInfo is the message struture for IP_PKTINFO. +// +// +stateify savable +type IPPacketInfo struct { + // NIC is the ID of the NIC to be used. + NIC NICID + + // LocalAddr is the local address. + LocalAddr Address + + // DestinationAddr is the destination address. + DestinationAddr Address +} + // Route is a row in the routing table. It specifies through which NIC (and // gateway) sets of packets should be routed. A row is considered viable if the // masked target address matches the destination address in the row. diff --git a/pkg/tcpip/tcpip_state_autogen.go b/pkg/tcpip/tcpip_state_autogen.go index 688c1d777..272b21d87 100755 --- a/pkg/tcpip/tcpip_state_autogen.go +++ b/pkg/tcpip/tcpip_state_autogen.go @@ -57,6 +57,8 @@ func (x *ControlMessages) save(m state.Map) { m.Save("TOS", &x.TOS) m.Save("HasTClass", &x.HasTClass) m.Save("TClass", &x.TClass) + m.Save("HasIPPacketInfo", &x.HasIPPacketInfo) + m.Save("PacketInfo", &x.PacketInfo) } func (x *ControlMessages) afterLoad() {} @@ -69,10 +71,28 @@ func (x *ControlMessages) load(m state.Map) { m.Load("TOS", &x.TOS) m.Load("HasTClass", &x.HasTClass) m.Load("TClass", &x.TClass) + m.Load("HasIPPacketInfo", &x.HasIPPacketInfo) + m.Load("PacketInfo", &x.PacketInfo) +} + +func (x *IPPacketInfo) beforeSave() {} +func (x *IPPacketInfo) save(m state.Map) { + x.beforeSave() + m.Save("NIC", &x.NIC) + m.Save("LocalAddr", &x.LocalAddr) + m.Save("DestinationAddr", &x.DestinationAddr) +} + +func (x *IPPacketInfo) afterLoad() {} +func (x *IPPacketInfo) load(m state.Map) { + m.Load("NIC", &x.NIC) + m.Load("LocalAddr", &x.LocalAddr) + m.Load("DestinationAddr", &x.DestinationAddr) } func init() { state.Register("pkg/tcpip.PacketBuffer", (*PacketBuffer)(nil), state.Fns{Save: (*PacketBuffer).save, Load: (*PacketBuffer).load}) state.Register("pkg/tcpip.FullAddress", (*FullAddress)(nil), state.Fns{Save: (*FullAddress).save, Load: (*FullAddress).load}) state.Register("pkg/tcpip.ControlMessages", (*ControlMessages)(nil), state.Fns{Save: (*ControlMessages).save, Load: (*ControlMessages).load}) + state.Register("pkg/tcpip.IPPacketInfo", (*IPPacketInfo)(nil), state.Fns{Save: (*IPPacketInfo).save, Load: (*IPPacketInfo).load}) } diff --git a/pkg/tcpip/transport/udp/endpoint.go b/pkg/tcpip/transport/udp/endpoint.go index c9cbed8f4..3fe91cac2 100644 --- a/pkg/tcpip/transport/udp/endpoint.go +++ b/pkg/tcpip/transport/udp/endpoint.go @@ -29,6 +29,7 @@ import ( type udpPacket struct { udpPacketEntry senderAddress tcpip.FullAddress + packetInfo tcpip.IPPacketInfo data buffer.VectorisedView `state:".(buffer.VectorisedView)"` timestamp int64 tos uint8 @@ -118,6 +119,9 @@ type endpoint struct { // as ancillary data to ControlMessages on Read. receiveTOS bool + // receiveIPPacketInfo determines if the packet info is returned by Read. + receiveIPPacketInfo bool + // shutdownFlags represent the current shutdown state of the endpoint. shutdownFlags tcpip.ShutdownFlags @@ -254,11 +258,17 @@ func (e *endpoint) Read(addr *tcpip.FullAddress) (buffer.View, tcpip.ControlMess } e.mu.RLock() receiveTOS := e.receiveTOS + receiveIPPacketInfo := e.receiveIPPacketInfo e.mu.RUnlock() if receiveTOS { cm.HasTOS = true cm.TOS = p.tos } + + if receiveIPPacketInfo { + cm.HasIPPacketInfo = true + cm.PacketInfo = p.packetInfo + } return p.data.ToView(), cm, nil } @@ -495,6 +505,13 @@ func (e *endpoint) SetSockOptBool(opt tcpip.SockOptBool, v bool) *tcpip.Error { } e.v6only = v + return nil + + case tcpip.ReceiveIPPacketInfoOption: + e.mu.Lock() + e.receiveIPPacketInfo = v + e.mu.Unlock() + return nil } return nil @@ -703,6 +720,12 @@ func (e *endpoint) GetSockOptBool(opt tcpip.SockOptBool) (bool, *tcpip.Error) { e.mu.RUnlock() return v, nil + + case tcpip.ReceiveIPPacketInfoOption: + e.mu.RLock() + v := e.receiveIPPacketInfo + e.mu.RUnlock() + return v, nil } return false, tcpip.ErrUnknownProtocolOption @@ -1247,6 +1270,9 @@ func (e *endpoint) HandlePacket(r *stack.Route, id stack.TransportEndpointID, pk switch r.NetProto { case header.IPv4ProtocolNumber: packet.tos, _ = header.IPv4(pkt.NetworkHeader).TOS() + packet.packetInfo.LocalAddr = r.LocalAddress + packet.packetInfo.DestinationAddr = r.RemoteAddress + packet.packetInfo.NIC = r.NICID() } packet.timestamp = e.stack.NowNanoseconds() diff --git a/pkg/tcpip/transport/udp/udp_state_autogen.go b/pkg/tcpip/transport/udp/udp_state_autogen.go index 9f78f44f1..092b2fdca 100755 --- a/pkg/tcpip/transport/udp/udp_state_autogen.go +++ b/pkg/tcpip/transport/udp/udp_state_autogen.go @@ -14,6 +14,7 @@ func (x *udpPacket) save(m state.Map) { m.SaveValue("data", data) m.Save("udpPacketEntry", &x.udpPacketEntry) m.Save("senderAddress", &x.senderAddress) + m.Save("packetInfo", &x.packetInfo) m.Save("timestamp", &x.timestamp) m.Save("tos", &x.tos) } @@ -22,6 +23,7 @@ func (x *udpPacket) afterLoad() {} func (x *udpPacket) load(m state.Map) { m.Load("udpPacketEntry", &x.udpPacketEntry) m.Load("senderAddress", &x.senderAddress) + m.Load("packetInfo", &x.packetInfo) m.Load("timestamp", &x.timestamp) m.Load("tos", &x.tos) m.LoadValue("data", new(buffer.VectorisedView), func(y interface{}) { x.loadData(y.(buffer.VectorisedView)) }) @@ -54,6 +56,7 @@ func (x *endpoint) save(m state.Map) { m.Save("boundPortFlags", &x.boundPortFlags) m.Save("sendTOS", &x.sendTOS) m.Save("receiveTOS", &x.receiveTOS) + m.Save("receiveIPPacketInfo", &x.receiveIPPacketInfo) m.Save("shutdownFlags", &x.shutdownFlags) m.Save("multicastMemberships", &x.multicastMemberships) m.Save("effectiveNetProtos", &x.effectiveNetProtos) @@ -83,6 +86,7 @@ func (x *endpoint) load(m state.Map) { m.Load("boundPortFlags", &x.boundPortFlags) m.Load("sendTOS", &x.sendTOS) m.Load("receiveTOS", &x.receiveTOS) + m.Load("receiveIPPacketInfo", &x.receiveIPPacketInfo) m.Load("shutdownFlags", &x.shutdownFlags) m.Load("multicastMemberships", &x.multicastMemberships) m.Load("effectiveNetProtos", &x.effectiveNetProtos) |