summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/socket/epsocket/epsocket.go
diff options
context:
space:
mode:
authorIan Gudger <igudger@google.com>2019-03-08 15:48:16 -0800
committerShentubot <shentubot@google.com>2019-03-08 15:49:17 -0800
commit56a61282953b46c8f8b707d5948a2d3958dced0c (patch)
tree2336f9f92e227d5f43bbad81cee80c527573a6a2 /pkg/sentry/socket/epsocket/epsocket.go
parent832589cb076a638ca53076ebb66afb9fac4597d1 (diff)
Implement IP_MULTICAST_LOOP.
IP_MULTICAST_LOOP controls whether or not multicast packets sent on the default route are looped back. In order to implement this switch, support for sending and looping back multicast packets on the default route had to be implemented. For now we only support IPv4 multicast. PiperOrigin-RevId: 237534603 Change-Id: I490ac7ff8e8ebef417c7eb049a919c29d156ac1c
Diffstat (limited to 'pkg/sentry/socket/epsocket/epsocket.go')
-rw-r--r--pkg/sentry/socket/epsocket/epsocket.go37
1 files changed, 36 insertions, 1 deletions
diff --git a/pkg/sentry/socket/epsocket/epsocket.go b/pkg/sentry/socket/epsocket/epsocket.go
index 4e547ea33..f7636e056 100644
--- a/pkg/sentry/socket/epsocket/epsocket.go
+++ b/pkg/sentry/socket/epsocket/epsocket.go
@@ -911,6 +911,21 @@ func getSockOptIP(t *kernel.Task, ep commonEndpoint, name, outLen int) (interfac
}
return rv.InetMulticastRequest, nil
+ case linux.IP_MULTICAST_LOOP:
+ if outLen < sizeOfInt32 {
+ return nil, syserr.ErrInvalidArgument
+ }
+
+ var v tcpip.MulticastLoopOption
+ if err := ep.GetSockOpt(&v); err != nil {
+ return nil, syserr.TranslateNetstackError(err)
+ }
+
+ if v {
+ return int32(1), nil
+ }
+ return int32(0), nil
+
default:
emitUnimplementedEventIP(t, name)
}
@@ -1178,6 +1193,15 @@ func copyInMulticastRequest(optVal []byte) (linux.InetMulticastRequestWithNIC, *
return req, nil
}
+// reduceToByte ORs all of the bytes in the input.
+func reduceToByte(buf []byte) byte {
+ var out byte
+ for _, b := range buf {
+ out |= b
+ }
+ return out
+}
+
// setSockOptIP implements SetSockOpt when level is SOL_IP.
func setSockOptIP(t *kernel.Task, ep commonEndpoint, name int, optVal []byte) *syserr.Error {
switch name {
@@ -1235,6 +1259,18 @@ func setSockOptIP(t *kernel.Task, ep commonEndpoint, name int, optVal []byte) *s
InterfaceAddr: bytesToIPAddress(req.InterfaceAddr[:]),
}))
+ case linux.IP_MULTICAST_LOOP:
+ if len(optVal) < 1 {
+ return syserr.ErrInvalidArgument
+ }
+ if len(optVal) > sizeOfInt32 {
+ optVal = optVal[:sizeOfInt32]
+ }
+
+ return syserr.TranslateNetstackError(ep.SetSockOpt(
+ tcpip.MulticastLoopOption(reduceToByte(optVal) != 0),
+ ))
+
case linux.MCAST_JOIN_GROUP:
// FIXME: Implement MCAST_JOIN_GROUP.
t.Kernel().EmitUnimplementedEvent(t)
@@ -1252,7 +1288,6 @@ func setSockOptIP(t *kernel.Task, ep commonEndpoint, name int, optVal []byte) *s
linux.IP_MSFILTER,
linux.IP_MTU_DISCOVER,
linux.IP_MULTICAST_ALL,
- linux.IP_MULTICAST_LOOP,
linux.IP_NODEFRAG,
linux.IP_OPTIONS,
linux.IP_PASSSEC,