summaryrefslogtreecommitdiffhomepage
path: root/pkg/abi
diff options
context:
space:
mode:
authorRahat Mahmood <rahat@google.com>2019-08-08 16:49:18 -0700
committergVisor bot <gvisor-bot@google.com>2019-08-08 16:50:33 -0700
commit7bfad8ebb6ce71c0fe90a1e4f5897f62809fa58b (patch)
treea579fecdddb331e141f44bcfb61dfe7bdbcba84d /pkg/abi
parent13a98df49ea1b36cd21c528293b626a6a3639f0b (diff)
Return a well-defined socket address type from socket funtions.
Previously we were representing socket addresses as an interface{}, which allowed any type which could be binary.Marshal()ed to be used as a socket address. This is fine when the address is passed to userspace via the linux ABI, but is problematic when used from within the sentry such as by networking procfs files. PiperOrigin-RevId: 262460640
Diffstat (limited to 'pkg/abi')
-rw-r--r--pkg/abi/linux/socket.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/pkg/abi/linux/socket.go b/pkg/abi/linux/socket.go
index 6d22002c4..e53165622 100644
--- a/pkg/abi/linux/socket.go
+++ b/pkg/abi/linux/socket.go
@@ -267,6 +267,20 @@ type SockAddrUnix struct {
Path [UnixPathMax]int8
}
+// SockAddr represents a union of valid socket address types. This is logically
+// equivalent to struct sockaddr. SockAddr ensures that a well-defined set of
+// types can be used as socket addresses.
+type SockAddr interface {
+ // implementsSockAddr exists purely to allow a type to indicate that they
+ // implement this interface. This method is a no-op and shouldn't be called.
+ implementsSockAddr()
+}
+
+func (s *SockAddrInet) implementsSockAddr() {}
+func (s *SockAddrInet6) implementsSockAddr() {}
+func (s *SockAddrUnix) implementsSockAddr() {}
+func (s *SockAddrNetlink) implementsSockAddr() {}
+
// Linger is struct linger, from include/linux/socket.h.
type Linger struct {
OnOff int32