asmlinkage long compat_sys_getsockopt(int fd, int level, int optname, char __user *optval, int __user *optlen) { if (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO) return do_get_sock_timeout(fd, level, optname, optval, optlen); return sys_getsockopt(fd, level, optname, optval, optlen); }
static int do_get_sock_timeout(int fd, int level, int optname, char __user *optval, int __user *optlen) { struct compat_timeval __user *up; struct timeval ktime; mm_segment_t old_fs; int len, err; up = (struct compat_timeval __user *) optval; if (get_user(len, optlen)) return -EFAULT; if (len < sizeof(*up)) return -EINVAL; len = sizeof(ktime); old_fs = get_fs(); set_fs(KERNEL_DS); err = sys_getsockopt(fd, level, optname, (char *) &ktime, &len); set_fs(old_fs); if (!err) { if (put_user(sizeof(*up), optlen) || !access_ok(VERIFY_WRITE, up, sizeof(*up)) || __put_user(ktime.tv_sec, &up->tv_sec) || __put_user(ktime.tv_usec, &up->tv_usec)) err = -EFAULT; } return err; }
asmlinkage int sunos_getsockopt(int fd, int level, int optname, char __user *optval, int __user *optlen) { int tr_opt = optname; int ret; if (level == SOL_IP) { /* Multicast socketopts (ttl, membership) */ if (tr_opt >=2 && tr_opt <= 6) tr_opt += 30; } ret = sys_getsockopt(fd, level, tr_opt, optval, optlen); return ret; }
/* * Get socket option. */ PJ_DEF(pj_status_t) pj_sock_getsockopt( pj_sock_t sockfd, pj_uint16_t level, pj_uint16_t optname, void *optval, int *optlen) { mm_segment_t oldfs; long err; PJ_CHECK_STACK(); oldfs = get_fs(); set_fs(KERNEL_DS); err = sys_getsockopt( sockfd, level, optname, optval, optlen); set_fs(oldfs); if (err) return PJ_RETURN_OS_ERROR(-err); else return PJ_SUCCESS; }
void handle_faf_getsockopt (struct rpc_desc *desc, void *msgIn, size_t size) { struct faf_getsockopt_msg *msg = msgIn; struct prev_root prev_root; const struct cred *old_cred; int r, err; err = unpack_context(desc, &prev_root, &old_cred); if (err) { rpc_cancel(desc); return; } err = prepare_ruaccess(desc); if (err) goto out_err; r = sys_getsockopt(msg->server_fd, msg->level, msg->optname, msg->optval, msg->optlen); err = cleanup_ruaccess(desc); if (err) goto out_err; err = rpc_pack_type(desc, r); goto out_err; exit: restore_context(&prev_root, old_cred); return; out_err: rpc_cancel(desc); if (err > 0) err = -ENOMEM; r = err; goto exit; }
DEFINE_SYSCALL(socketcall, int, call, uintptr_t *, args) { if (call < 1 || call > SYS_SENDMMSG) return -L_EINVAL; if (!mm_check_read(args, nargs[call])) return -L_EFAULT; switch (call) { case SYS_SOCKET: return sys_socket(args[0], args[1], args[2]); case SYS_BIND: return sys_bind(args[0], (const struct sockaddr *)args[1], args[2]); case SYS_CONNECT: return sys_connect(args[0], (const struct sockaddr *)args[1], args[2]); case SYS_LISTEN: return sys_listen(args[0], args[1]); case SYS_ACCEPT: return sys_accept(args[0], (struct sockaddr *)args[1], (int *)args[2]); case SYS_GETSOCKNAME: return sys_getsockname(args[0], (struct sockaddr *)args[1], (int *)args[2]); case SYS_GETPEERNAME: return sys_getpeername(args[0], (struct sockaddr *)args[1], (int *)args[2]); case SYS_SEND: return sys_send(args[0], (const void *)args[1], args[2], args[3]); case SYS_RECV: return sys_recv(args[0], (void *)args[1], args[2], args[3]); case SYS_SENDTO: return sys_sendto(args[0], (const void *)args[1], args[2], args[3], (const struct sockaddr *)args[4], args[5]); case SYS_RECVFROM: return sys_recvfrom(args[0], (void *)args[1], args[2], args[3], (struct sockaddr *)args[4], (int *)args[5]); case SYS_SHUTDOWN: return sys_shutdown(args[0], args[1]); case SYS_SETSOCKOPT: return sys_setsockopt(args[0], args[1], args[2], (const void *)args[3], args[4]); case SYS_GETSOCKOPT: return sys_getsockopt(args[0], args[1], args[2], (void *)args[3], (int *)args[4]); case SYS_SENDMSG: return sys_sendmsg(args[0], (const struct msghdr *)args[1], args[2]); case SYS_RECVMSG: return sys_recvmsg(args[0], (struct msghdr *)args[1], args[2]); case SYS_ACCEPT4: return sys_accept4(args[0], (struct sockaddr *)args[1], (int *)args[2], args[3]); case SYS_SENDMMSG: return sys_sendmmsg(args[0], (struct mmsghdr *)args[1], args[2], args[3]); default: { log_error("Unimplemented socketcall: %d", call); return -L_EINVAL; } } }
int so_socksys(struct socksysreq *req) { int err = -EINVAL; int cmd = req->args[0]; if ((1 << cmd) & ((1 << SO_ACCEPT) | (1 << SO_BIND) | (1 << SO_CONNECT) | (1 << SO_GETPEERNAME) | (1 << SO_GETSOCKNAME) | (1 << SO_GETSOCKOPT) | (1 << SO_LISTEN) | (1 << SO_RECV) | (1 << SO_RECVFROM) | (1 << SO_SEND) | (1 << SO_SENDTO) | (1 << SO_SETSOCKOPT) | (1 << SO_SHUTDOWN) | (1 << SO_RECVMSG) | (1 << SO_SENDMSG))) { int fd = req->args[1]; (void) fd; /* These are all socket related and accept a file (socket) descriptor as their first argument. In situations where we are incapable of providing back a real socket, we must here first distinguish if the file descriptor corresponds to a socket or a stream. */ #if 0 if (it_is_a_socket) { #endif /* In this case, we have a real socket from the operating system's perspective and we can simply pass the arguments to the appropriate system call. */ #if 0 switch (cmd) { case SO_ACCEPT: /* FIXME: 32/64 conversion */ err = sys_accept(fd, (struct sockaddr *) req->args[2], req->args[3]); break; case SO_BIND: /* FIXME: 32/64 conversion */ err = sys_bind(fd, (struct sockaddr *) req->args[2], req->args[3]); break; case SO_CONNECT: /* FIXME: 32/64 conversion */ err = sys_connect(fd, (struct sockaddr *) req->args[2], req->args[3]); break; case SO_GETPEERNAME: /* FIXME: 32/64 conversion */ err = sys_getpeername(fd, (struct sockaddr *) req->args[2], (int *) req->args[3]); break; case SO_GETSOCKNAME: /* FIXME: 32/64 conversion */ err = sys_getsockname(fd, (struct sockaddr *) req->args[2], (int *) req->args[3]); break; case SO_GETSOCKOPT: /* FIXME: 32/64 conversion */ err = sys_getsockopt(fd, req->args[2], req->args[3], (char *) req->args[4], (int *) req->args[5]); break; case SO_LISTEN: /* FIXME: 32/64 conversion */ err = sys_listen(fd, req->args[2]); break; case SO_RECV: /* FIXME: 32/64 conversion */ err = sys_recv(fd, (void *) req->args[2], req->args[3], req->args[4]); break; case SO_RECVFROM: /* FIXME: 32/64 conversion */ err = sys_recvfrom(fd, (void *) req->args[2], req->args[3], req->args[4], (struct sockaddr *) req->args[5], (int *) req->args[6]); break; case SO_SEND: /* FIXME: 32/64 conversion */ err = sys_send(fd, (void *) req->args[2], req->args[3], req->args[4]); break; case SO_SENDTO: /* FIXME: 32/64 conversion */ err = sys_sendto(fd, (void *) req->args[2], req->args[3], req->args[4], (struct sockaddr *) req->args[5], req->args[6]); break; case SO_SETSOCKOPT: /* FIXME: 32/64 conversion */ err = sys_setsockopt(fd, req->args[2], req->args[3], (char *) req->args[4], req->args[5]); break; case SO_SHUTDOWN: /* FIXME: 32/64 conversion */ err = sys_shutdown(fd, req->args[2]); break; case SO_RECVMSG: /* FIXME: 32/64 conversion */ err = sys_recvmsg(fd, (struct msghdr *) req->args[2], req->args[3]); break; case SO_SENDMSG: /* FIXME: 32/64 conversion */ err = sys_sendmsg(fd, (struct msghdr *) req->args[2], req->args[3]); break; } #endif #if 0 } else { /* In this case, we do not have a real socket, but have a TPI stream from the operating system's perspective, and we will directly call the associated TPI routine. */ switch (cmd) { case SO_ACCEPT: /* FIXME: 32/64 conversion */ err = tpi_accept(fd, (struct sockaddr *) req->args[2], req->args[3]); break; case SO_BIND: /* FIXME: 32/64 conversion */ err = tpi_bind(fd, (struct sockaddr *) req->args[2], req->args[3]); break; case SO_CONNECT: /* FIXME: 32/64 conversion */ err = tpi_connect(fd, (struct sockaddr *) req->args[2], req->args[3]); break; case SO_GETPEERNAME: /* FIXME: 32/64 conversion */ err = tpi_getpeername(fd, (struct sockaddr *) req->args[2], (int *) req->args[3]); break; case SO_GETSOCKNAME: /* FIXME: 32/64 conversion */ err = tpi_getsockname(fd, (struct sockaddr *) req->args[2], (int *) req->args[3]); break; case SO_GETSOCKOPT: /* FIXME: 32/64 conversion */ err = tpi_getsockopt(fd, req->args[2], req->args[3], (char *) req->args[4], (int *) req->args[5]); break; case SO_LISTEN: /* FIXME: 32/64 conversion */ err = tpi_listen(fd, req->args[2]); break; case SO_RECV: /* FIXME: 32/64 conversion */ err = tpi_recv(fd, (void *) req->args[2], req->args[3], req->args[4]); break; case SO_RECVFROM: /* FIXME: 32/64 conversion */ err = tpi_recvfrom(fd, (void *) req->args[2], req->args[3], req->args[4], (struct sockaddr *) req->args[5], (int *) req->args[6]); break; case SO_SEND: /* FIXME: 32/64 conversion */ err = tpi_send(fd, (void *) req->args[2], req->args[3], req->args[4]); break; case SO_SENDTO: /* FIXME: 32/64 conversion */ err = tpi_sendto(fd, (void *) req->args[2], req->args[3], req->args[4], (struct sockaddr *) req->args[5], req->args[6]); break; case SO_SETSOCKOPT: /* FIXME: 32/64 conversion */ err = tpi_setsockopt(fd, req->args[2], req->args[3], (char *) req->args[4], req->args[5]); break; case SO_SHUTDOWN: /* FIXME: 32/64 conversion */ err = tpi_shutdown(fd, req->args[2]); break; case SO_RECVMSG: /* FIXME: 32/64 conversion */ err = tpi_recvmsg(fd, (struct msghdr *) req->args[2], req->args[3]); break; case SO_SENDMSG: /* FIXME: 32/64 conversion */ err = tpi_sendmsg(fd, (struct msghdr *) req->args[2], req->args[3]); break; } } #endif } if ((1 << cmd) & ((1 << SO_SOCKET) | (1 << SO_SOCKPAIR) | (1 << SO_SELECT) | (1 << SO_GETIPDOMAIN) | (1 << SO_SETIPDOMAIN) | (1 << SO_ADJTIME) | (1 << SO_SETREUID) | (1 << SO_SETREGID) | (1 << SO_GETTIME) | (1 << SO_SETTIME) | (1 << SO_GETITIMER) | (1 << SO_SETITIMER))) { /* These are BSD compatibiltiy functions and are how we create sockets in the first place. The BSD compatibility functions all have system calls in Linux, but we provide them for backward compatibility (to what!?). */ #if 0 switch (cmd) { case SO_SOCKET: /* FIXME: 32/64 conversion */ /* XXX: don't think so..., after checking for a stream */ err = sys_socket(req->args[1], req->args[2], req->args[3]); break; case SO_SOCKPAIR: /* FIXME: 32/64 conversion */ /* XXX: don't think so..., after checking for a stream */ err = sys_socketpair(req->args[1], req->args[2], req->args[3], (int *) req->args[4]); err = -EOPNOTSUPP; break; case SO_SELECT: /* FIXME: 32/64 conversion */ err = sys_select(req->args[1], (fd_set *) req->args[2], (fd_set *) req->args[3], (fd_set *) req->args[4], (struct timeval *) req->args[5]); break; case SO_GETIPDOMAIN: /* FIXME: 32/64 conversion */ todo(("Process SO_GETIPDOMAIN for compatibility.\n")); /* does not exist in Linux, need to use sys_newuname and copy the domainname portion */ err = -ENOSYS; break; case SO_SETIPDOMAIN: /* FIXME: 32/64 conversion */ err = sys_setdomainname((char *) req->args[1], req->args[2]); break; case SO_ADJTIME: /* FIXME: 32/64 conversion */ err = sys_admtimex((struct timex *) req->args[1]); break; case SO_SETREUID: /* FIXME: 32/64 conversion */ err = sys_setreuid(req->args[1], req->args[2]); break; case SO_SETREGID: /* FIXME: 32/64 conversion */ err = sys_setregid(req->args[1], req->args[2]); break; case SO_GETTIME: /* FIXME: 32/64 conversion */ err = sys_gettimeofday((struct timeval *) req->args[1], (struct timezone *) req->args[2]); break; case SO_SETTIME: /* FIXME: 32/64 conversion */ err = sys_settimeofday((struct timeval *) req->args[1], (struct timezone *) req->args[2]); break; case SO_GETITIMER: /* FIXME: 32/64 conversion */ err = sys_getitimer(req->args[1], (struct itimerval *) req->args[2]); break; case SO_SETITIMER: /* FIXME: 32/64 conversion */ err = sys_getitimer(req->args[1], (struct itimerval *) req->args[2], (struct itimerval *) req->args[3]); break; } #endif } return (err); }
/* * system call vectors. since i want to rewrite sockets as streams, we have * this level of indirection. not a lot of overhead, since more of the work is * done via read/write/select directly */ int sys_socketcall(int call, unsigned long *args) { switch (call) { case SYS_SOCKET: verify_area(args, 3 * sizeof(long)); return sock_socket(get_fs_long(args+0), get_fs_long(args+1), get_fs_long(args+2)); case SYS_BIND: verify_area(args, 3 * sizeof(long)); return sock_bind(get_fs_long(args+0), (struct sockaddr *)get_fs_long(args+1), get_fs_long(args+2)); case SYS_CONNECT: verify_area(args, 3 * sizeof(long)); return sock_connect(get_fs_long(args+0), (struct sockaddr *)get_fs_long(args+1), get_fs_long(args+2)); case SYS_LISTEN: verify_area(args, 2 * sizeof(long)); return sock_listen(get_fs_long(args+0), get_fs_long(args+1)); case SYS_ACCEPT: verify_area(args, 3 * sizeof(long)); return sock_accept(get_fs_long(args+0), (struct sockaddr *)get_fs_long(args+1), (int *)get_fs_long(args+2)); case SYS_GETSOCKNAME: verify_area(args, 3 * sizeof(long)); return sock_getsockname(get_fs_long(args+0), (struct sockaddr *)get_fs_long(args+1), (int *)get_fs_long(args+2)); case SYS_GETPEERNAME: verify_area(args, 3 * sizeof(long)); return sock_getpeername(get_fs_long(args+0), (struct sockaddr *)get_fs_long(args+1), (int *)get_fs_long(args+2)); case SYS_SOCKETPAIR: verify_area(args, 4 * sizeof(long)); return sock_socketpair(get_fs_long(args+0), get_fs_long(args+1), get_fs_long(args+2), (int *)get_fs_long(args+3)); case SYS_SEND: verify_area(args, 4 * sizeof (unsigned long)); return ( sys_send (get_fs_long(args+0), (void *)get_fs_long(args+1), get_fs_long(args+2), get_fs_long(args+3))); case SYS_SENDTO: verify_area(args, 6 * sizeof (unsigned long)); return ( sys_sendto (get_fs_long(args+0), (void *)get_fs_long(args+1), get_fs_long(args+2), get_fs_long(args+3), (struct sockaddr *)get_fs_long(args+4), get_fs_long(args+5))); case SYS_RECV: verify_area(args, 4 * sizeof (unsigned long)); return ( sys_recv (get_fs_long(args+0), (void *)get_fs_long(args+1), get_fs_long(args+2), get_fs_long(args+3))); case SYS_RECVFROM: verify_area(args, 6 * sizeof (unsigned long)); return ( sys_recvfrom (get_fs_long(args+0), (void *)get_fs_long(args+1), get_fs_long(args+2), get_fs_long(args+3), (struct sockaddr *)get_fs_long(args+4), (int *)get_fs_long(args+5))); case SYS_SHUTDOWN: verify_area (args, 2* sizeof (unsigned long)); return ( sys_shutdown (get_fs_long (args+0), get_fs_long (args+1))); case SYS_SETSOCKOPT: verify_area (args, 5*sizeof (unsigned long)); return (sys_setsockopt (get_fs_long (args+0), get_fs_long (args+1), get_fs_long (args+2), (char *)get_fs_long (args+3), get_fs_long (args+4))); case SYS_GETSOCKOPT: verify_area (args, 5*sizeof (unsigned long)); return (sys_getsockopt (get_fs_long (args+0), get_fs_long (args+1), get_fs_long (args+2), (char *)get_fs_long (args+3), (int *)get_fs_long (args+4))); default: return -EINVAL; } }