mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
[netstack] Move SO_REUSEPORT and SO_REUSEADDR option to SocketOptions.
This changes also introduces: - `SocketOptionsHandler` interface which can be implemented by endpoints to handle endpoint specific behavior on SetSockOpt. This is analogous to what Linux does. - `DefaultSocketOptionsHandler` which is a default implementation of the above. This is embedded in all endpoints so that we don't have to uselessly implement empty functions. Endpoints with specific behavior can override the embedded method by manually defining its own implementation. PiperOrigin-RevId: 343158301
This commit is contained in:
@@ -1112,25 +1112,16 @@ func getSockOptSocket(t *kernel.Task, s socket.SocketOps, ep commonEndpoint, fam
|
||||
return nil, syserr.ErrInvalidArgument
|
||||
}
|
||||
|
||||
v, err := ep.GetSockOptBool(tcpip.ReuseAddressOption)
|
||||
if err != nil {
|
||||
return nil, syserr.TranslateNetstackError(err)
|
||||
}
|
||||
vP := primitive.Int32(boolToInt32(v))
|
||||
return &vP, nil
|
||||
v := primitive.Int32(boolToInt32(ep.SocketOptions().GetReuseAddress()))
|
||||
return &v, nil
|
||||
|
||||
case linux.SO_REUSEPORT:
|
||||
if outLen < sizeOfInt32 {
|
||||
return nil, syserr.ErrInvalidArgument
|
||||
}
|
||||
|
||||
v, err := ep.GetSockOptBool(tcpip.ReusePortOption)
|
||||
if err != nil {
|
||||
return nil, syserr.TranslateNetstackError(err)
|
||||
}
|
||||
|
||||
vP := primitive.Int32(boolToInt32(v))
|
||||
return &vP, nil
|
||||
v := primitive.Int32(boolToInt32(ep.SocketOptions().GetReusePort()))
|
||||
return &v, nil
|
||||
|
||||
case linux.SO_BINDTODEVICE:
|
||||
var v tcpip.BindToDeviceOption
|
||||
@@ -1869,7 +1860,8 @@ func setSockOptSocket(t *kernel.Task, s socket.SocketOps, ep commonEndpoint, nam
|
||||
}
|
||||
|
||||
v := usermem.ByteOrder.Uint32(optVal)
|
||||
return syserr.TranslateNetstackError(ep.SetSockOptBool(tcpip.ReuseAddressOption, v != 0))
|
||||
ep.SocketOptions().SetReuseAddress(v != 0)
|
||||
return nil
|
||||
|
||||
case linux.SO_REUSEPORT:
|
||||
if len(optVal) < sizeOfInt32 {
|
||||
@@ -1877,7 +1869,8 @@ func setSockOptSocket(t *kernel.Task, s socket.SocketOps, ep commonEndpoint, nam
|
||||
}
|
||||
|
||||
v := usermem.ByteOrder.Uint32(optVal)
|
||||
return syserr.TranslateNetstackError(ep.SetSockOptBool(tcpip.ReusePortOption, v != 0))
|
||||
ep.SocketOptions().SetReusePort(v != 0)
|
||||
return nil
|
||||
|
||||
case linux.SO_BINDTODEVICE:
|
||||
n := bytes.IndexByte(optVal, 0)
|
||||
|
||||
Reference in New Issue
Block a user