diff options
Diffstat (limited to 'pkg/tcpip')
-rw-r--r-- | pkg/tcpip/socketops.go | 14 | ||||
-rw-r--r-- | pkg/tcpip/tcpip.go | 8 | ||||
-rw-r--r-- | pkg/tcpip/tcpip_state_autogen.go | 9 | ||||
-rw-r--r-- | pkg/tcpip/transport/udp/endpoint.go | 18 | ||||
-rw-r--r-- | pkg/tcpip/transport/udp/udp_state_autogen.go | 19 |
5 files changed, 56 insertions, 12 deletions
diff --git a/pkg/tcpip/socketops.go b/pkg/tcpip/socketops.go index c53698a6a..b14df9e09 100644 --- a/pkg/tcpip/socketops.go +++ b/pkg/tcpip/socketops.go @@ -130,6 +130,10 @@ type SocketOptions struct { // corkOptionEnabled is used to specify if data should be held until segments // are full by the TCP transport protocol. corkOptionEnabled uint32 + + // receiveOriginalDstAddress is used to specify if the original destination of + // the incoming packet should be returned as an ancillary message. + receiveOriginalDstAddress uint32 } // InitHandler initializes the handler. This must be called before using the @@ -302,3 +306,13 @@ func (so *SocketOptions) SetCorkOption(v bool) { storeAtomicBool(&so.corkOptionEnabled, v) so.handler.OnCorkOptionSet(v) } + +// GetReceiveOriginalDstAddress gets value for IP(V6)_RECVORIGDSTADDR option. +func (so *SocketOptions) GetReceiveOriginalDstAddress() bool { + return atomic.LoadUint32(&so.receiveOriginalDstAddress) != 0 +} + +// SetReceiveOriginalDstAddress sets value for IP(V6)_RECVORIGDSTADDR option. +func (so *SocketOptions) SetReceiveOriginalDstAddress(v bool) { + storeAtomicBool(&so.receiveOriginalDstAddress, v) +} diff --git a/pkg/tcpip/tcpip.go b/pkg/tcpip/tcpip.go index 23e597365..0d2dad881 100644 --- a/pkg/tcpip/tcpip.go +++ b/pkg/tcpip/tcpip.go @@ -492,6 +492,14 @@ type ControlMessages struct { // PacketInfo holds interface and address data on an incoming packet. PacketInfo IPPacketInfo + + // HasOriginalDestinationAddress indicates whether OriginalDstAddress is + // set. + HasOriginalDstAddress bool + + // OriginalDestinationAddress holds the original destination address + // and port of the incoming packet. + OriginalDstAddress FullAddress } // PacketOwner is used to get UID and GID of the packet. diff --git a/pkg/tcpip/tcpip_state_autogen.go b/pkg/tcpip/tcpip_state_autogen.go index 94e40e30e..36ef19575 100644 --- a/pkg/tcpip/tcpip_state_autogen.go +++ b/pkg/tcpip/tcpip_state_autogen.go @@ -28,6 +28,7 @@ func (so *SocketOptions) StateFields() []string { "quickAckEnabled", "delayOptionEnabled", "corkOptionEnabled", + "receiveOriginalDstAddress", } } @@ -51,6 +52,7 @@ func (so *SocketOptions) StateSave(stateSinkObject state.Sink) { stateSinkObject.Save(13, &so.quickAckEnabled) stateSinkObject.Save(14, &so.delayOptionEnabled) stateSinkObject.Save(15, &so.corkOptionEnabled) + stateSinkObject.Save(16, &so.receiveOriginalDstAddress) } func (so *SocketOptions) afterLoad() {} @@ -72,6 +74,7 @@ func (so *SocketOptions) StateLoad(stateSourceObject state.Source) { stateSourceObject.Load(13, &so.quickAckEnabled) stateSourceObject.Load(14, &so.delayOptionEnabled) stateSourceObject.Load(15, &so.corkOptionEnabled) + stateSourceObject.Load(16, &so.receiveOriginalDstAddress) } func (e *Error) StateTypeName() string { @@ -145,6 +148,8 @@ func (c *ControlMessages) StateFields() []string { "TClass", "HasIPPacketInfo", "PacketInfo", + "HasOriginalDstAddress", + "OriginalDstAddress", } } @@ -162,6 +167,8 @@ func (c *ControlMessages) StateSave(stateSinkObject state.Sink) { stateSinkObject.Save(7, &c.TClass) stateSinkObject.Save(8, &c.HasIPPacketInfo) stateSinkObject.Save(9, &c.PacketInfo) + stateSinkObject.Save(10, &c.HasOriginalDstAddress) + stateSinkObject.Save(11, &c.OriginalDstAddress) } func (c *ControlMessages) afterLoad() {} @@ -177,6 +184,8 @@ func (c *ControlMessages) StateLoad(stateSourceObject state.Source) { stateSourceObject.Load(7, &c.TClass) stateSourceObject.Load(8, &c.HasIPPacketInfo) stateSourceObject.Load(9, &c.PacketInfo) + stateSourceObject.Load(10, &c.HasOriginalDstAddress) + stateSourceObject.Load(11, &c.OriginalDstAddress) } func (l *LinkPacketInfo) StateTypeName() string { diff --git a/pkg/tcpip/transport/udp/endpoint.go b/pkg/tcpip/transport/udp/endpoint.go index ee1bb29f8..04596183e 100644 --- a/pkg/tcpip/transport/udp/endpoint.go +++ b/pkg/tcpip/transport/udp/endpoint.go @@ -30,10 +30,11 @@ import ( // +stateify savable type udpPacket struct { udpPacketEntry - senderAddress tcpip.FullAddress - packetInfo tcpip.IPPacketInfo - data buffer.VectorisedView `state:".(buffer.VectorisedView)"` - timestamp int64 + senderAddress tcpip.FullAddress + destinationAddress tcpip.FullAddress + packetInfo tcpip.IPPacketInfo + data buffer.VectorisedView `state:".(buffer.VectorisedView)"` + timestamp int64 // tos stores either the receiveTOS or receiveTClass value. tos uint8 } @@ -323,6 +324,10 @@ func (e *endpoint) Read(addr *tcpip.FullAddress) (buffer.View, tcpip.ControlMess cm.HasIPPacketInfo = true cm.PacketInfo = p.packetInfo } + if e.ops.GetReceiveOriginalDstAddress() { + cm.HasOriginalDstAddress = true + cm.OriginalDstAddress = p.destinationAddress + } return p.data.ToView(), cm, nil } @@ -1314,6 +1319,11 @@ func (e *endpoint) HandlePacket(id stack.TransportEndpointID, pkt *stack.PacketB Addr: id.RemoteAddress, Port: hdr.SourcePort(), }, + destinationAddress: tcpip.FullAddress{ + NIC: pkt.NICID, + Addr: id.LocalAddress, + Port: header.UDP(hdr).DestinationPort(), + }, } packet.data = pkt.Data e.rcvList.PushBack(packet) diff --git a/pkg/tcpip/transport/udp/udp_state_autogen.go b/pkg/tcpip/transport/udp/udp_state_autogen.go index dc6afdff9..451d8eff0 100644 --- a/pkg/tcpip/transport/udp/udp_state_autogen.go +++ b/pkg/tcpip/transport/udp/udp_state_autogen.go @@ -15,6 +15,7 @@ func (u *udpPacket) StateFields() []string { return []string{ "udpPacketEntry", "senderAddress", + "destinationAddress", "packetInfo", "data", "timestamp", @@ -27,12 +28,13 @@ func (u *udpPacket) beforeSave() {} func (u *udpPacket) StateSave(stateSinkObject state.Sink) { u.beforeSave() var dataValue buffer.VectorisedView = u.saveData() - stateSinkObject.SaveValue(3, dataValue) + stateSinkObject.SaveValue(4, dataValue) stateSinkObject.Save(0, &u.udpPacketEntry) stateSinkObject.Save(1, &u.senderAddress) - stateSinkObject.Save(2, &u.packetInfo) - stateSinkObject.Save(4, &u.timestamp) - stateSinkObject.Save(5, &u.tos) + stateSinkObject.Save(2, &u.destinationAddress) + stateSinkObject.Save(3, &u.packetInfo) + stateSinkObject.Save(5, &u.timestamp) + stateSinkObject.Save(6, &u.tos) } func (u *udpPacket) afterLoad() {} @@ -40,10 +42,11 @@ func (u *udpPacket) afterLoad() {} func (u *udpPacket) StateLoad(stateSourceObject state.Source) { stateSourceObject.Load(0, &u.udpPacketEntry) stateSourceObject.Load(1, &u.senderAddress) - stateSourceObject.Load(2, &u.packetInfo) - stateSourceObject.Load(4, &u.timestamp) - stateSourceObject.Load(5, &u.tos) - stateSourceObject.LoadValue(3, new(buffer.VectorisedView), func(y interface{}) { u.loadData(y.(buffer.VectorisedView)) }) + stateSourceObject.Load(2, &u.destinationAddress) + stateSourceObject.Load(3, &u.packetInfo) + stateSourceObject.Load(5, &u.timestamp) + stateSourceObject.Load(6, &u.tos) + stateSourceObject.LoadValue(4, new(buffer.VectorisedView), func(y interface{}) { u.loadData(y.(buffer.VectorisedView)) }) } func (e *endpoint) StateTypeName() string { |