From d70787d340b3967fd691fbbd079dece329f7a65c Mon Sep 17 00:00:00 2001 From: Kevin Krakauer Date: Fri, 4 May 2018 16:21:38 -0700 Subject: sentry: Adds the SIOCGIFNETMASK ioctl to epsocket. PiperOrigin-RevId: 195489319 Change-Id: I0841d41d042c6f91aa8d7f62c127213aa7953eac --- pkg/sentry/socket/epsocket/epsocket.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'pkg/sentry/socket') diff --git a/pkg/sentry/socket/epsocket/epsocket.go b/pkg/sentry/socket/epsocket/epsocket.go index 5701ecfac..a45dcd551 100644 --- a/pkg/sentry/socket/epsocket/epsocket.go +++ b/pkg/sentry/socket/epsocket/epsocket.go @@ -1109,7 +1109,20 @@ func (s *SocketOperations) interfaceIoctl(ctx context.Context, io usermem.IO, ar case syscall.SIOCGIFNETMASK: // Gets the network mask of a device. - // TODO: Implement. + for _, addr := range s.stack.InterfaceAddrs()[index] { + // This ioctl is only compatible with AF_INET addresses. + if addr.Family != linux.AF_INET { + continue + } + // Populate ifr.ifr_netmask (type sockaddr). + usermem.ByteOrder.PutUint16(ifr.Data[0:2], uint16(linux.AF_INET)) + usermem.ByteOrder.PutUint16(ifr.Data[2:4], 0) + var mask uint32 = 0xffffffff << (32 - addr.PrefixLen) + // Netmask is expected to be returned as a big endian + // value. + binary.BigEndian.PutUint32(ifr.Data[4:8], mask) + break + } default: // Not a valid call. -- cgit v1.2.3