SetSockOptSocket handles linux setsockopt(2) when level is SOL_SOCKET.
(t *kernel.Task, s socket.Socket, ep commonEndpoint, name int, optVal []byte)
| 1973 | |
| 1974 | // SetSockOptSocket handles linux setsockopt(2) when level is SOL_SOCKET. |
| 1975 | func SetSockOptSocket(t *kernel.Task, s socket.Socket, ep commonEndpoint, name int, optVal []byte) *syserr.Error { |
| 1976 | switch name { |
| 1977 | case linux.SO_SNDBUF: |
| 1978 | if len(optVal) < sizeOfInt32 { |
| 1979 | return syserr.ErrInvalidArgument |
| 1980 | } |
| 1981 | |
| 1982 | v := hostarch.ByteOrder.Uint32(optVal) |
| 1983 | min, max := ep.SocketOptions().SendBufferLimits() |
| 1984 | clamped := clampBufSize(int64(v), min, max, false /* ignoreMax */) |
| 1985 | ep.SocketOptions().SetSendBufferSize(clamped, true /* notify */) |
| 1986 | return nil |
| 1987 | |
| 1988 | case linux.SO_RCVBUF: |
| 1989 | if len(optVal) < sizeOfInt32 { |
| 1990 | return syserr.ErrInvalidArgument |
| 1991 | } |
| 1992 | |
| 1993 | v := hostarch.ByteOrder.Uint32(optVal) |
| 1994 | min, max := ep.SocketOptions().ReceiveBufferLimits() |
| 1995 | clamped := clampBufSize(int64(v), min, max, false /* ignoreMax */) |
| 1996 | ep.SocketOptions().SetReceiveBufferSize(clamped, true /* notify */) |
| 1997 | return nil |
| 1998 | |
| 1999 | case linux.SO_RCVBUFFORCE: |
| 2000 | if len(optVal) < sizeOfInt32 { |
| 2001 | return syserr.ErrInvalidArgument |
| 2002 | } |
| 2003 | |
| 2004 | if !t.HasRootCapability(linux.CAP_NET_ADMIN) { |
| 2005 | return syserr.ErrNotPermitted |
| 2006 | } |
| 2007 | |
| 2008 | v := hostarch.ByteOrder.Uint32(optVal) |
| 2009 | min, max := ep.SocketOptions().ReceiveBufferLimits() |
| 2010 | clamped := clampBufSize(int64(v), min, max, true /* ignoreMax */) |
| 2011 | ep.SocketOptions().SetReceiveBufferSize(clamped, true /* notify */) |
| 2012 | return nil |
| 2013 | |
| 2014 | case linux.SO_REUSEADDR: |
| 2015 | if len(optVal) < sizeOfInt32 { |
| 2016 | return syserr.ErrInvalidArgument |
| 2017 | } |
| 2018 | |
| 2019 | v := hostarch.ByteOrder.Uint32(optVal) |
| 2020 | ep.SocketOptions().SetReuseAddress(v != 0) |
| 2021 | return nil |
| 2022 | |
| 2023 | case linux.SO_REUSEPORT: |
| 2024 | if len(optVal) < sizeOfInt32 { |
| 2025 | return syserr.ErrInvalidArgument |
| 2026 | } |
| 2027 | |
| 2028 | v := hostarch.ByteOrder.Uint32(optVal) |
| 2029 | ep.SocketOptions().SetReusePort(v != 0) |
| 2030 | return nil |
| 2031 | |
| 2032 | case linux.SO_BINDTODEVICE: |
no test coverage detected
searching dependent graphs…