Allow rebinding packet socket protocol

...to change the network protocol a packet socket may receive packets
from.

This CL is a portion of an originally larger CL that was split with
https://github.com/google/gvisor/commit/a8ad692fd36cbaf7f5a6b9af39d601053dbee338
being the dependent CL. That CL (accidentally) included the change in
the endpoint's `afterLoad` method to take the required lock when
accessing the endpoint's netProto field. That change should have been in
this CL.

The CL that made the change mentioned in the commit message is
cl/396946187.

PiperOrigin-RevId: 397412582
This commit is contained in:
Ghanan Gowripalan
2021-09-17 15:37:08 -07:00
committed by gVisor bot
parent 4076153be6
commit 7dacdbef52
4 changed files with 180 additions and 20 deletions
+1 -4
View File
@@ -672,13 +672,10 @@ func (s *socketOpsCommon) Bind(t *kernel.Task, sockaddr []byte) *syserr.Error {
}
a.UnmarshalBytes(sockaddr[:sockAddrLinkSize])
if a.Protocol != uint16(s.protocol) {
return syserr.ErrInvalidArgument
}
addr = tcpip.FullAddress{
NIC: tcpip.NICID(a.InterfaceIndex),
Addr: tcpip.Address(a.HardwareAddr[:header.EthernetAddressSize]),
Port: socket.Ntohs(a.Protocol),
}
} else {
if s.minSockAddrLen() > len(sockaddr) {