Skip to content

Commit 27f3984

Browse files
ayushr2gvisor-bot
authored andcommitted
hostinet: Add SO_ORIGINAL_DST and IP6T_ORIGINAL_DST.
Acknowledgements: handpickencounter <[email protected]>. Fixes #8564 PiperOrigin-RevId: 751587679
1 parent 73c7442 commit 27f3984

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

pkg/abi/linux/socket.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,5 +731,10 @@ type ICMP6Filter struct {
731731
Filter [8]uint32
732732
}
733733

734-
// SizeOfICMP6Filter is the size of ICMP6Filter struct.
735-
var SizeOfICMP6Filter = uint32((*ICMP6Filter)(nil).SizeBytes())
734+
// Size of corresponding structs.
735+
var (
736+
ICMP6FilterSize = (*ICMP6Filter)(nil).SizeBytes()
737+
SockAddrInetSize = (*SockAddrInet)(nil).SizeBytes()
738+
SockAddrInet6Size = (*SockAddrInet6)(nil).SizeBytes()
739+
SockAddrLinkSize = (*SockAddrLink)(nil).SizeBytes()
740+
)

pkg/sentry/socket/hostinet/sockopt.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ var SockOpts = []SockOpt{
7171
{linux.SOL_IP, linux.IP_RECVTTL, sizeofInt32, true, true},
7272
{linux.SOL_IP, linux.IP_TOS, 0 /* Can be 32, 16, or 8 bits */, true, true},
7373
{linux.SOL_IP, linux.IP_TTL, sizeofInt32, true, true},
74+
{linux.SOL_IP, linux.SO_ORIGINAL_DST, uint64(linux.SockAddrInetSize), true, false},
7475

7576
{linux.SOL_IPV6, linux.IPV6_CHECKSUM, sizeofInt32, true, true},
7677
{linux.SOL_IPV6, linux.IPV6_MULTICAST_HOPS, sizeofInt32, true, true},
@@ -82,6 +83,7 @@ var SockOpts = []SockOpt{
8283
{linux.SOL_IPV6, linux.IPV6_TCLASS, sizeofInt32, true, true},
8384
{linux.SOL_IPV6, linux.IPV6_UNICAST_HOPS, sizeofInt32, true, true},
8485
{linux.SOL_IPV6, linux.IPV6_V6ONLY, sizeofInt32, true, true},
86+
{linux.SOL_IPV6, linux.IP6T_ORIGINAL_DST, uint64(linux.SockAddrInet6Size), true, false},
8587

8688
{linux.SOL_SOCKET, linux.SO_ACCEPTCONN, sizeofInt32, true, true},
8789
{linux.SOL_SOCKET, linux.SO_BINDTODEVICE, 0, true, true},
@@ -116,7 +118,7 @@ var SockOpts = []SockOpt{
116118
{linux.SOL_TCP, linux.TCP_USER_TIMEOUT, sizeofInt32, true, true},
117119
{linux.SOL_TCP, linux.TCP_WINDOW_CLAMP, sizeofInt32, true, true},
118120

119-
{linux.SOL_ICMPV6, linux.ICMPV6_FILTER, uint64(linux.SizeOfICMP6Filter), true, true},
121+
{linux.SOL_ICMPV6, linux.ICMPV6_FILTER, uint64(linux.ICMP6FilterSize), true, true},
120122
}
121123

122124
// sockOptMap is a map of {level, name} -> SockOpts. It is an optimization for

pkg/sentry/socket/netstack/netstack.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,6 @@ func (s *sock) SetSockOpt(t *kernel.Task, level int, name int, optVal []byte) *s
672672
return SetSockOpt(t, s, s.Endpoint, level, name, optVal)
673673
}
674674

675-
var sockAddrInetSize = (*linux.SockAddrInet)(nil).SizeBytes()
676-
var sockAddrInet6Size = (*linux.SockAddrInet6)(nil).SizeBytes()
677-
var sockAddrLinkSize = (*linux.SockAddrLink)(nil).SizeBytes()
678-
679675
// minSockAddrLen returns the minimum length in bytes of a socket address for
680676
// the socket's family.
681677
func (s *sock) minSockAddrLen() int {
@@ -685,11 +681,11 @@ func (s *sock) minSockAddrLen() int {
685681
case linux.AF_UNIX:
686682
return addressFamilySize
687683
case linux.AF_INET:
688-
return sockAddrInetSize
684+
return linux.SockAddrInetSize
689685
case linux.AF_INET6:
690-
return sockAddrInet6Size
686+
return linux.SockAddrInet6Size
691687
case linux.AF_PACKET:
692-
return sockAddrLinkSize
688+
return linux.SockAddrLinkSize
693689
case linux.AF_UNSPEC:
694690
return addressFamilySize
695691
default:
@@ -807,7 +803,7 @@ func (s *sock) Bind(_ *kernel.Task, sockaddr []byte) *syserr.Error {
807803
// not needed for AF_PACKET bind.
808804
if family == linux.AF_PACKET {
809805
var a linux.SockAddrLink
810-
if len(sockaddr) < sockAddrLinkSize {
806+
if len(sockaddr) < linux.SockAddrLinkSize {
811807
return syserr.ErrInvalidArgument
812808
}
813809
a.UnmarshalBytes(sockaddr)
@@ -1537,7 +1533,7 @@ func getSockOptIPv6(t *kernel.Task, s socket.Socket, ep commonEndpoint, name int
15371533
return &v, nil
15381534

15391535
case linux.IP6T_ORIGINAL_DST:
1540-
if outLen < sockAddrInet6Size {
1536+
if outLen < linux.SockAddrInet6Size {
15411537
return nil, syserr.ErrInvalidArgument
15421538
}
15431539

@@ -1765,7 +1761,7 @@ func getSockOptIP(t *kernel.Task, s socket.Socket, ep commonEndpoint, name int,
17651761
return &v, nil
17661762

17671763
case linux.SO_ORIGINAL_DST:
1768-
if outLen < sockAddrInetSize {
1764+
if outLen < linux.SockAddrInetSize {
17691765
return nil, syserr.ErrInvalidArgument
17701766
}
17711767

0 commit comments

Comments
 (0)