Add support for rpcinet ioctl(2).

This change will add support for ioctls that have previously
been supported by netstack.

LINE_LENGTH_IGNORE

PiperOrigin-RevId: 199544114
Change-Id: I3769202c19502c3b7d05e06ea9552acfd9255893
This commit is contained in:
Brian Geffon
2018-06-06 15:53:26 -07:00
committed by Shentubot
parent 0c34b460f2
commit 79fef54eb1
2 changed files with 68 additions and 9 deletions
+61 -2
View File
@@ -56,6 +56,10 @@ type socketOperations struct {
// Verify that we actually implement socket.Socket.
var _ = socket.Socket(&socketOperations{})
const (
sizeOfIfReq = 40
)
// New creates a new RPC socket.
func newSocketFile(ctx context.Context, stack *Stack, family int, skType int, protocol int) (*fs.File, *syserr.Error) {
id, c := stack.rpcConn.NewRequest(pb.SyscallRequest{Args: &pb.SyscallRequest_Socket{&pb.SocketRequest{Family: int64(family), Type: int64(skType | syscall.SOCK_NONBLOCK), Protocol: int64(protocol)}}}, false /* ignoreResult */)
@@ -290,7 +294,11 @@ func (s *socketOperations) Accept(t *kernel.Task, peerRequested bool, flags int,
return 0, nil, 0, syserr.FromError(err)
}
return fd, payload.Address.Address, payload.Address.Length, nil
if peerRequested {
return fd, payload.Address.Address, payload.Address.Length, nil
}
return fd, nil, 0, nil
}
// Bind implements socket.Socket.Bind.
@@ -385,9 +393,60 @@ func (s *socketOperations) GetSockName(t *kernel.Task) (interface{}, uint32, *sy
return addr.Address, addr.Length, nil
}
func rpcIoctl(t *kernel.Task, fd, cmd uint32, arg []byte) ([]byte, error) {
stack := t.NetworkContext().(*Stack)
id, c := stack.rpcConn.NewRequest(pb.SyscallRequest{Args: &pb.SyscallRequest_Ioctl{&pb.IOCtlRequest{Fd: fd, Cmd: cmd, Arg: arg}}}, false /* ignoreResult */)
<-c
res := stack.rpcConn.Request(id).Result.(*pb.SyscallResponse_Ioctl).Ioctl.Result
if e, ok := res.(*pb.IOCtlResponse_ErrorNumber); ok {
return nil, syscall.Errno(e.ErrorNumber)
}
return res.(*pb.IOCtlResponse_Value).Value, nil
}
// Ioctl implements fs.FileOperations.Ioctl.
func (s *socketOperations) Ioctl(ctx context.Context, io usermem.IO, args arch.SyscallArguments) (uintptr, error) {
return 0, syserror.ENOTTY
t := ctx.(*kernel.Task)
cmd := uint32(args[1].Int())
arg := args[2].Pointer()
var buf []byte
switch cmd {
// The following ioctls take 4 byte argument parameters.
case syscall.TIOCINQ, syscall.TIOCOUTQ:
buf = make([]byte, 4)
// The following ioctls have args which are sizeof(struct ifreq).
case syscall.SIOCGIFINDEX, syscall.SIOCGIFNETMASK, syscall.SIOCGIFHWADDR, syscall.SIOCGIFNAME, syscall.SIOCGIFFLAGS:
buf = make([]byte, sizeOfIfReq)
default:
return 0, syserror.ENOTTY
}
_, err := io.CopyIn(ctx, arg, buf, usermem.IOOpts{
AddressSpaceActive: true,
})
if err != nil {
return 0, err
}
v, err := rpcIoctl(t, s.fd, cmd, buf)
if err != nil {
return 0, err
}
if len(v) != len(buf) {
return 0, syserror.EINVAL
}
_, err = io.CopyOut(ctx, arg, v, usermem.IOOpts{
AddressSpaceActive: true,
})
return 0, err
}
func rpcRecvMsg(t *kernel.Task, req *pb.SyscallRequest_Recvmsg) (*pb.RecvmsgResponse_ResultPayload, *syserr.Error) {
+7 -7
View File
@@ -8,7 +8,7 @@ package syscall_rpc;
message SendmsgRequest {
uint32 fd = 1;
bytes data = 2;
bytes data = 2 [ctype = CORD];
bytes address = 3;
bool more = 4;
bool end_of_record = 5;
@@ -24,13 +24,13 @@ message SendmsgResponse {
message IOCtlRequest {
uint32 fd = 1;
uint32 cmd = 2;
uint64 arg = 3;
bytes arg = 3;
}
message IOCtlResponse {
oneof result {
uint32 error_number = 1;
uint64 value = 2;
bytes value = 2;
}
}
@@ -63,7 +63,7 @@ message ReadRequest {
message ReadResponse {
oneof result {
uint32 error_number = 1;
bytes data = 2;
bytes data = 2 [ctype = CORD];
}
}
@@ -74,13 +74,13 @@ message ReadFileRequest {
message ReadFileResponse {
oneof result {
uint32 error_number = 1;
bytes data = 2;
bytes data = 2 [ctype = CORD];
}
}
message WriteRequest {
uint32 fd = 1;
bytes data = 2;
bytes data = 2 [ctype = CORD];
}
message WriteResponse {
@@ -107,7 +107,7 @@ message AddressResponse {
message RecvmsgResponse {
message ResultPayload {
bytes data = 1;
bytes data = 1 [ctype = CORD];
AddressResponse address = 2;
uint32 length = 3;
}