summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2021-09-19 20:19:42 +0000
committergVisor bot <gvisor-bot@google.com>2021-09-19 20:19:42 +0000
commit453feae0e363ce6f8de82f1c2af107a001c37709 (patch)
tree6330eaf5295aae5c39a3c68a0d5670e20a59c2c1 /pkg/tcpip
parentd5c50f7005285605bf5fbc4b2fa604fd295cb957 (diff)
parent89a0011c100d778cd8a0cc5e1b14996461c66629 (diff)
Merge release-20210906.0-46-g89a0011c1 (automated)
Diffstat (limited to 'pkg/tcpip')
-rw-r--r--pkg/tcpip/socketops.go18
-rw-r--r--pkg/tcpip/tcpip.go14
-rw-r--r--pkg/tcpip/tcpip_state_autogen.go98
-rw-r--r--pkg/tcpip/transport/udp/endpoint.go18
4 files changed, 112 insertions, 36 deletions
diff --git a/pkg/tcpip/socketops.go b/pkg/tcpip/socketops.go
index 34ac62444..b0b2d0afd 100644
--- a/pkg/tcpip/socketops.go
+++ b/pkg/tcpip/socketops.go
@@ -170,10 +170,14 @@ type SocketOptions struct {
// message is passed with incoming packets.
receiveTClassEnabled uint32
- // receivePacketInfoEnabled is used to specify if more inforamtion is
- // provided with incoming packets such as interface index and address.
+ // receivePacketInfoEnabled is used to specify if more information is
+ // provided with incoming IPv4 packets.
receivePacketInfoEnabled uint32
+ // receivePacketInfoEnabled is used to specify if more information is
+ // provided with incoming IPv6 packets.
+ receiveIPv6PacketInfoEnabled uint32
+
// hdrIncludeEnabled is used to indicate for a raw endpoint that all packets
// being written have an IP header and the endpoint should not attach an IP
// header.
@@ -360,6 +364,16 @@ func (so *SocketOptions) SetReceivePacketInfo(v bool) {
storeAtomicBool(&so.receivePacketInfoEnabled, v)
}
+// GetIPv6ReceivePacketInfo gets value for IPV6_RECVPKTINFO option.
+func (so *SocketOptions) GetIPv6ReceivePacketInfo() bool {
+ return atomic.LoadUint32(&so.receiveIPv6PacketInfoEnabled) != 0
+}
+
+// SetIPv6ReceivePacketInfo sets value for IPV6_RECVPKTINFO option.
+func (so *SocketOptions) SetIPv6ReceivePacketInfo(v bool) {
+ storeAtomicBool(&so.receiveIPv6PacketInfoEnabled, v)
+}
+
// GetHeaderIncluded gets value for IP_HDRINCL option.
func (so *SocketOptions) GetHeaderIncluded() bool {
return atomic.LoadUint32(&so.hdrIncludedEnabled) != 0
diff --git a/pkg/tcpip/tcpip.go b/pkg/tcpip/tcpip.go
index a9ce148b9..c5e896295 100644
--- a/pkg/tcpip/tcpip.go
+++ b/pkg/tcpip/tcpip.go
@@ -451,6 +451,12 @@ type ControlMessages struct {
// PacketInfo holds interface and address data on an incoming packet.
PacketInfo IPPacketInfo
+ // HasIPv6PacketInfo indicates whether IPv6PacketInfo is set.
+ HasIPv6PacketInfo bool
+
+ // IPv6PacketInfo holds interface and address data on an incoming packet.
+ IPv6PacketInfo IPv6PacketInfo
+
// HasOriginalDestinationAddress indicates whether OriginalDstAddress is
// set.
HasOriginalDstAddress bool
@@ -1164,6 +1170,14 @@ type IPPacketInfo struct {
DestinationAddr Address
}
+// IPv6PacketInfo is the message structure for IPV6_PKTINFO.
+//
+// +stateify savable
+type IPv6PacketInfo struct {
+ Addr Address
+ NIC NICID
+}
+
// SendBufferSizeOption is used by stack.(Stack*).Option/SetOption to
// get/set the default, min and max send buffer sizes.
type SendBufferSizeOption struct {
diff --git a/pkg/tcpip/tcpip_state_autogen.go b/pkg/tcpip/tcpip_state_autogen.go
index 9c34de9ef..c3df463eb 100644
--- a/pkg/tcpip/tcpip_state_autogen.go
+++ b/pkg/tcpip/tcpip_state_autogen.go
@@ -898,6 +898,7 @@ func (so *SocketOptions) StateFields() []string {
"receiveTOSEnabled",
"receiveTClassEnabled",
"receivePacketInfoEnabled",
+ "receiveIPv6PacketInfoEnabled",
"hdrIncludedEnabled",
"v6OnlyEnabled",
"quickAckEnabled",
@@ -929,18 +930,19 @@ func (so *SocketOptions) StateSave(stateSinkObject state.Sink) {
stateSinkObject.Save(8, &so.receiveTOSEnabled)
stateSinkObject.Save(9, &so.receiveTClassEnabled)
stateSinkObject.Save(10, &so.receivePacketInfoEnabled)
- stateSinkObject.Save(11, &so.hdrIncludedEnabled)
- stateSinkObject.Save(12, &so.v6OnlyEnabled)
- stateSinkObject.Save(13, &so.quickAckEnabled)
- stateSinkObject.Save(14, &so.delayOptionEnabled)
- stateSinkObject.Save(15, &so.corkOptionEnabled)
- stateSinkObject.Save(16, &so.receiveOriginalDstAddress)
- stateSinkObject.Save(17, &so.recvErrEnabled)
- stateSinkObject.Save(18, &so.errQueue)
- stateSinkObject.Save(19, &so.bindToDevice)
- stateSinkObject.Save(20, &so.sendBufferSize)
- stateSinkObject.Save(21, &so.receiveBufferSize)
- stateSinkObject.Save(22, &so.linger)
+ stateSinkObject.Save(11, &so.receiveIPv6PacketInfoEnabled)
+ stateSinkObject.Save(12, &so.hdrIncludedEnabled)
+ stateSinkObject.Save(13, &so.v6OnlyEnabled)
+ stateSinkObject.Save(14, &so.quickAckEnabled)
+ stateSinkObject.Save(15, &so.delayOptionEnabled)
+ stateSinkObject.Save(16, &so.corkOptionEnabled)
+ stateSinkObject.Save(17, &so.receiveOriginalDstAddress)
+ stateSinkObject.Save(18, &so.recvErrEnabled)
+ stateSinkObject.Save(19, &so.errQueue)
+ stateSinkObject.Save(20, &so.bindToDevice)
+ stateSinkObject.Save(21, &so.sendBufferSize)
+ stateSinkObject.Save(22, &so.receiveBufferSize)
+ stateSinkObject.Save(23, &so.linger)
}
func (so *SocketOptions) afterLoad() {}
@@ -958,18 +960,19 @@ func (so *SocketOptions) StateLoad(stateSourceObject state.Source) {
stateSourceObject.Load(8, &so.receiveTOSEnabled)
stateSourceObject.Load(9, &so.receiveTClassEnabled)
stateSourceObject.Load(10, &so.receivePacketInfoEnabled)
- stateSourceObject.Load(11, &so.hdrIncludedEnabled)
- stateSourceObject.Load(12, &so.v6OnlyEnabled)
- stateSourceObject.Load(13, &so.quickAckEnabled)
- stateSourceObject.Load(14, &so.delayOptionEnabled)
- stateSourceObject.Load(15, &so.corkOptionEnabled)
- stateSourceObject.Load(16, &so.receiveOriginalDstAddress)
- stateSourceObject.Load(17, &so.recvErrEnabled)
- stateSourceObject.Load(18, &so.errQueue)
- stateSourceObject.Load(19, &so.bindToDevice)
- stateSourceObject.Load(20, &so.sendBufferSize)
- stateSourceObject.Load(21, &so.receiveBufferSize)
- stateSourceObject.Load(22, &so.linger)
+ stateSourceObject.Load(11, &so.receiveIPv6PacketInfoEnabled)
+ stateSourceObject.Load(12, &so.hdrIncludedEnabled)
+ stateSourceObject.Load(13, &so.v6OnlyEnabled)
+ stateSourceObject.Load(14, &so.quickAckEnabled)
+ stateSourceObject.Load(15, &so.delayOptionEnabled)
+ stateSourceObject.Load(16, &so.corkOptionEnabled)
+ stateSourceObject.Load(17, &so.receiveOriginalDstAddress)
+ stateSourceObject.Load(18, &so.recvErrEnabled)
+ stateSourceObject.Load(19, &so.errQueue)
+ stateSourceObject.Load(20, &so.bindToDevice)
+ stateSourceObject.Load(21, &so.sendBufferSize)
+ stateSourceObject.Load(22, &so.receiveBufferSize)
+ stateSourceObject.Load(23, &so.linger)
}
func (l *LocalSockError) StateTypeName() string {
@@ -1136,6 +1139,8 @@ func (c *ControlMessages) StateFields() []string {
"TClass",
"HasIPPacketInfo",
"PacketInfo",
+ "HasIPv6PacketInfo",
+ "IPv6PacketInfo",
"HasOriginalDstAddress",
"OriginalDstAddress",
"SockErr",
@@ -1157,9 +1162,11 @@ 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)
- stateSinkObject.Save(12, &c.SockErr)
+ stateSinkObject.Save(10, &c.HasIPv6PacketInfo)
+ stateSinkObject.Save(11, &c.IPv6PacketInfo)
+ stateSinkObject.Save(12, &c.HasOriginalDstAddress)
+ stateSinkObject.Save(13, &c.OriginalDstAddress)
+ stateSinkObject.Save(14, &c.SockErr)
}
func (c *ControlMessages) afterLoad() {}
@@ -1176,9 +1183,11 @@ 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)
- stateSourceObject.Load(12, &c.SockErr)
+ stateSourceObject.Load(10, &c.HasIPv6PacketInfo)
+ stateSourceObject.Load(11, &c.IPv6PacketInfo)
+ stateSourceObject.Load(12, &c.HasOriginalDstAddress)
+ stateSourceObject.Load(13, &c.OriginalDstAddress)
+ stateSourceObject.Load(14, &c.SockErr)
}
func (l *LinkPacketInfo) StateTypeName() string {
@@ -1268,6 +1277,34 @@ func (i *IPPacketInfo) StateLoad(stateSourceObject state.Source) {
stateSourceObject.Load(2, &i.DestinationAddr)
}
+func (i *IPv6PacketInfo) StateTypeName() string {
+ return "pkg/tcpip.IPv6PacketInfo"
+}
+
+func (i *IPv6PacketInfo) StateFields() []string {
+ return []string{
+ "Addr",
+ "NIC",
+ }
+}
+
+func (i *IPv6PacketInfo) beforeSave() {}
+
+// +checklocksignore
+func (i *IPv6PacketInfo) StateSave(stateSinkObject state.Sink) {
+ i.beforeSave()
+ stateSinkObject.Save(0, &i.Addr)
+ stateSinkObject.Save(1, &i.NIC)
+}
+
+func (i *IPv6PacketInfo) afterLoad() {}
+
+// +checklocksignore
+func (i *IPv6PacketInfo) StateLoad(stateSourceObject state.Source) {
+ stateSourceObject.Load(0, &i.Addr)
+ stateSourceObject.Load(1, &i.NIC)
+}
+
func init() {
state.Register((*ErrAborted)(nil))
state.Register((*ErrAddressFamilyNotSupported)(nil))
@@ -1320,4 +1357,5 @@ func init() {
state.Register((*LinkPacketInfo)(nil))
state.Register((*LingerOption)(nil))
state.Register((*IPPacketInfo)(nil))
+ state.Register((*IPv6PacketInfo)(nil))
}
diff --git a/pkg/tcpip/transport/udp/endpoint.go b/pkg/tcpip/transport/udp/endpoint.go
index 4255457f9..b355fa7eb 100644
--- a/pkg/tcpip/transport/udp/endpoint.go
+++ b/pkg/tcpip/transport/udp/endpoint.go
@@ -243,19 +243,29 @@ func (e *endpoint) Read(dst io.Writer, opts tcpip.ReadOptions) (tcpip.ReadResult
cm.HasTOS = true
cm.TOS = p.tos
}
+
+ if e.ops.GetReceivePacketInfo() {
+ cm.HasIPPacketInfo = true
+ cm.PacketInfo = p.packetInfo
+ }
case header.IPv6ProtocolNumber:
if e.ops.GetReceiveTClass() {
cm.HasTClass = true
// Although TClass is an 8-bit value it's read in the CMsg as a uint32.
cm.TClass = uint32(p.tos)
}
+
+ if e.ops.GetIPv6ReceivePacketInfo() {
+ cm.HasIPv6PacketInfo = true
+ cm.IPv6PacketInfo = tcpip.IPv6PacketInfo{
+ NIC: p.packetInfo.NIC,
+ Addr: p.packetInfo.DestinationAddr,
+ }
+ }
default:
panic(fmt.Sprintf("unrecognized network protocol = %d", p.netProto))
}
- if e.ops.GetReceivePacketInfo() {
- cm.HasIPPacketInfo = true
- cm.PacketInfo = p.packetInfo
- }
+
if e.ops.GetReceiveOriginalDstAddress() {
cm.HasOriginalDstAddress = true
cm.OriginalDstAddress = p.destinationAddress