aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Dumazet <eric.dumazet@gmail.com>2010-06-03 23:03:40 -0400
committerDavid S. Miller <davem@davemloft.net>2010-06-03 23:03:40 -0400
commitc6d409cfd0fd41e7a0847875e4338ad648c9b96b (patch)
tree7f346c6f41db5b448ebab504f3fae6bb0f28cf79
parent849c45423c0c108e08d67644728cc9b0ed225fa1 (diff)
From abbffa2aa9bd6f8df16d0d0a102af677510d8b9a Mon Sep 17 00:00:00 2001
From: Eric Dumazet <eric.dumazet@gmail.com> Date: Thu, 3 Jun 2010 04:29:41 +0000 Subject: [PATCH 2/3] net: net/socket.c and net/compat.c cleanups cleanup patch, to match modern coding style. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> --- net/compat.c | 47 ++++++++--------- net/socket.c | 165 ++++++++++++++++++++++++++++------------------------------ 2 files changed, 102 insertions(+), 110 deletions(-) diff --git a/net/compat.c b/net/compat.c index 1cf7590..63d260e 100644 --- a/net/compat.c +++ b/net/compat.c @@ -81,7 +81,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov, int tot_len; if (kern_msg->msg_namelen) { - if (mode==VERIFY_READ) { + if (mode == VERIFY_READ) { int err = move_addr_to_kernel(kern_msg->msg_name, kern_msg->msg_namelen, kern_address); @@ -354,7 +354,7 @@ static int do_set_attach_filter(struct socket *sock, int level, int optname, static int do_set_sock_timeout(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen) { - struct compat_timeval __user *up = (struct compat_timeval __user *) optval; + struct compat_timeval __user *up = (struct compat_timeval __user *)optval; struct timeval ktime; mm_segment_t old_fs; int err; @@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level, return -EFAULT; old_fs = get_fs(); set_fs(KERNEL_DS); - err = sock_setsockopt(sock, level, optname, (char *) &ktime, sizeof(ktime)); + err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime)); set_fs(old_fs); return err; @@ -389,11 +389,10 @@ asmlinkage long compat_sys_setsockopt(int fd, int level, int optname, char __user *optval, unsigned int optlen) { int err; - struct socket *sock; + struct socket *sock = sockfd_lookup(fd, &err); - if ((sock = sockfd_lookup(fd, &err))!=NULL) - { - err = security_socket_setsockopt(sock,level,optname); + if (sock) { + err = security_socket_setsockopt(sock, level, optname); if (err) { sockfd_put(sock); return err; @@ -453,7 +452,7 @@ static int compat_sock_getsockopt(struct socket *sock, int level, int optname, int compat_sock_get_timestamp(struct sock *sk, struct timeval __user *userstamp) { struct compat_timeval __user *ctv = - (struct compat_timeval __user*) userstamp; + (struct compat_timeval __user *) userstamp; int err = -ENOENT; struct timeval tv; @@ -477,7 +476,7 @@ EXPORT_SYMBOL(compat_sock_get_timestamp); int compat_sock_get_timestampns(struct sock *sk, struct timespec __user *userstamp) { struct compat_timespec __user *ctv = - (struct compat_timespec __user*) userstamp; + (struct compat_timespec __user *) userstamp; int err = -ENOENT; struct timespec ts; @@ -502,12 +501,10 @@ asmlinkage long compat_sys_getsockopt(int fd, int level, int optname, char __user *optval, int __user *optlen) { int err; - struct socket *sock; + struct socket *sock = sockfd_lookup(fd, &err); - if ((sock = sockfd_lookup(fd, &err))!=NULL) - { - err = security_socket_getsockopt(sock, level, - optname); + if (sock) { + err = security_socket_getsockopt(sock, level, optname); if (err) { sockfd_put(sock); return err; @@ -557,7 +554,7 @@ struct compat_group_filter { int compat_mc_setsockopt(struct sock *sock, int level, int optname, char __user *optval, unsigned int optlen, - int (*setsockopt)(struct sock *,int,int,char __user *,unsigned int)) + int (*setsockopt)(struct sock *, int, int, char __user *, unsigned int)) { char __user *koptval = optval; int koptlen = optlen; @@ -640,12 +637,11 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname, } return setsockopt(sock, level, optname, koptval, koptlen); } - EXPORT_SYMBOL(compat_mc_setsockopt); int compat_mc_getsockopt(struct sock *sock, int level, int optname, char __user *optval, int __user *optlen, - int (*getsockopt)(struct sock *,int,int,char __user *,int __user *)) + int (*getsockopt)(struct sock *, int, int, char __user *, int __user *)) { struct compat_group_filter __user *gf32 = (void *)optval; struct group_filter __user *kgf; @@ -681,7 +677,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname, __put_user(interface, &kgf->gf_interface) || __put_user(fmode, &kgf->gf_fmode) || __put_user(numsrc, &kgf->gf_numsrc) || - copy_in_user(&kgf->gf_group,&gf32->gf_group,sizeof(kgf->gf_group))) + copy_in_user(&kgf->gf_group, &gf32->gf_group, sizeof(kgf->gf_group))) return -EFAULT; err = getsockopt(sock, level, optname, (char __user *)kgf, koptlen); @@ -714,21 +710,22 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname, copylen = numsrc * sizeof(gf32->gf_slist[0]); if (copylen > klen) copylen = klen; - if (copy_in_user(gf32->gf_slist, kgf->gf_slist, copylen)) + if (copy_in_user(gf32->gf_slist, kgf->gf_slist, copylen)) return -EFAULT; } return err; } - EXPORT_SYMBOL(compat_mc_getsockopt); /* Argument list sizes for compat_sys_socketcall */ #define AL(x) ((x) * sizeof(u32)) -static unsigned char nas[20]={AL(0),AL(3),AL(3),AL(3),AL(2),AL(3), - AL(3),AL(3),AL(4),AL(4),AL(4),AL(6), - AL(6),AL(2),AL(5),AL(5),AL(3),AL(3), - AL(4),AL(5)}; +static unsigned char nas[20] = { + AL(0), AL(3), AL(3), AL(3), AL(2), AL(3), + AL(3), AL(3), AL(4), AL(4), AL(4), AL(6), + AL(6), AL(2), AL(5), AL(5), AL(3), AL(3), + AL(4), AL(5) +}; #undef AL asmlinkage long compat_sys_sendmsg(int fd, struct compat_msghdr __user *msg, unsigned flags) @@ -827,7 +824,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args) compat_ptr(a[4]), compat_ptr(a[5])); break; case SYS_SHUTDOWN: - ret = sys_shutdown(a0,a1); + ret = sys_shutdown(a0, a1); break; case SYS_SETSOCKOPT: ret = compat_sys_setsockopt(a0, a1, a[2], diff --git a/net/socket.c b/net/socket.c index 367d547..b63c051 100644 --- a/net/socket.c +++ b/net/socket.c @@ -124,7 +124,7 @@ static int sock_fasync(int fd, struct file *filp, int on); static ssize_t sock_sendpage(struct file *file, struct page *page, int offset, size_t size, loff_t *ppos, int more); static ssize_t sock_splice_read(struct file *file, loff_t *ppos, - struct pipe_inode_info *pipe, size_t len, + struct pipe_inode_info *pipe, size_t len, unsigned int flags); /* @@ -162,7 +162,7 @@ static const struct net_proto_family *net_families[NPROTO] __read_mostly; * Statistics counters of the socket lists */ -static DEFINE_PER_CPU(int, sockets_in_use) = 0; +static DEFINE_PER_CPU(int, sockets_in_use); /* * Support routines. @@ -309,9 +309,9 @@ static int init_inodecache(void) } static const struct super_operations sockfs_ops = { - .alloc_inode = sock_alloc_inode, - .destroy_inode =sock_destroy_inode, - .statfs = simple_statfs, + .alloc_inode = sock_alloc_inode, + .destroy_inode = sock_destroy_inode, + .statfs = simple_statfs, }; static int sockfs_get_sb(struct file_system_type *fs_type, @@ -411,6 +411,7 @@ int sock_map_fd(struct socket *sock, int flags) return fd; } +EXPORT_SYMBOL(sock_map_fd); static struct socket *sock_from_file(struct file *file, int *err) { @@ -422,7 +423,7 @@ static struct socket *sock_from_file(struct file *file, int *err) } /** - * sockfd_lookup - Go from a file number to its socket slot + * sockfd_lookup - Go from a file number to its socket slot * @fd: file handle * @err: pointer to an error code return * @@ -450,6 +451,7 @@ struct socket *sockfd_lookup(int fd, int *err) fput(file); return sock; } +EXPORT_SYMBOL(sockfd_lookup); static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed) { @@ -540,6 +542,7 @@ void sock_release(struct socket *sock) } sock->file = NULL; } +EXPORT_SYMBOL(sock_release); int sock_tx_timestamp(struct msghdr *msg, struct sock *sk, union skb_shared_tx *shtx) @@ -586,6 +589,7 @@ int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) ret = wait_on_sync_kiocb(&iocb); return ret; } +EXPORT_SYMBOL(sock_sendmsg); int kernel_sendmsg(struct socket *sock, struct msghdr *msg, struct kvec *vec, size_t num, size_t size) @@ -604,6 +608,7 @@ int kernel_sendmsg(struct socket *sock, struct msghdr *msg, set_fs(oldfs); return result; } +EXPORT_SYMBOL(kernel_sendmsg); static int ktime2ts(ktime_t kt, struct timespec *ts) { @@ -664,7 +669,6 @@ void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk, put_cmsg(msg, SOL_SOCKET, SCM_TIMESTAMPING, sizeof(ts), &ts); } - EXPORT_SYMBOL_GPL(__sock_recv_timestamp); inline void sock_recv_drops(struct msghdr *msg, struct sock *sk, struct sk_buff *skb) @@ -720,6 +724,7 @@ int sock_recvmsg(struct socket *sock, struct msghdr *msg, ret = wait_on_sync_kiocb(&iocb); return ret; } +EXPORT_SYMBOL(sock_recvmsg); static int sock_recvmsg_nosec(struct socket *sock, struct msghdr *msg, size_t size, int flags) @@ -752,6 +757,7 @@ int kernel_recvmsg(struct socket *sock, struct msghdr *msg, set_fs(oldfs); return result; } +EXPORT_SYMBOL(kernel_recvmsg); static void sock_aio_dtor(struct kiocb *iocb) { @@ -774,7 +780,7 @@ static ssize_t sock_sendpage(struct file *file, struct page *page, } static ssize_t sock_splice_read(struct file *file, loff_t *ppos, - struct pipe_inode_info *pipe, size_t len, + struct pipe_inode_info *pipe, size_t len, unsigned int flags) { struct socket *sock = file->private_data; @@ -887,7 +893,7 @@ static ssize_t sock_aio_write(struct kiocb *iocb, const struct iovec *iov, */ static DEFINE_MUTEX(br_ioctl_mutex); -static int (*br_ioctl_hook) (struct net *, unsigned int cmd, void __user *arg) = NULL; +static int (*br_ioctl_hook) (struct net *, unsigned int cmd, void __user *arg); void brioctl_set(int (*hook) (struct net *, unsigned int, void __user *)) { @@ -895,7 +901,6 @@ void brioctl_set(int (*hook) (struct net *, unsigned int, void __user *)) br_ioctl_hook = hook; mutex_unlock(&br_ioctl_mutex); } - EXPORT_SYMBOL(brioctl_set); static DEFINE_MUTEX(vlan_ioctl_mutex); @@ -907,7 +912,6 @@ void vlan_ioctl_set(int (*hook) (struct net *, void __user *)) vlan_ioctl_hook = hook; mutex_unlock(&vlan_ioctl_mutex); } - EXPORT_SYMBOL(vlan_ioctl_set); static DEFINE_MUTEX(dlci_ioctl_mutex); @@ -919,7 +923,6 @@ void dlci_ioctl_set(int (*hook) (unsigned int, void __user *)) dlci_ioctl_hook = hook; mutex_unlock(&dlci_ioctl_mutex); } - EXPORT_SYMBOL(dlci_ioctl_set); static long sock_do_ioctl(struct net *net, struct socket *sock, @@ -1047,6 +1050,7 @@ out_release: sock = NULL; goto out; } +EXPORT_SYMBOL(sock_create_lite); /* No kernel lock held - perfect */ static unsigned int sock_poll(struct file *file, poll_table *wait) @@ -1147,6 +1151,7 @@ call_kill: rcu_read_unlock(); return 0; } +EXPORT_SYMBOL(sock_wake_async); static int __sock_create(struct net *net, int family, int type, int protocol, struct socket **res, int kern) @@ -1265,11 +1270,13 @@ int sock_create(int family, int type, int protocol, struct socket **res) { return __sock_create(current->nsproxy->net_ns, family, type, protocol, res, 0); } +EXPORT_SYMBOL(sock_create); int sock_create_kern(int family, int type, int protocol, struct socket **res) { return __sock_create(&init_net, family, type, protocol, res, 1); } +EXPORT_SYMBOL(sock_create_kern); SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol) { @@ -1474,7 +1481,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr, goto out; err = -ENFILE; - if (!(newsock = sock_alloc())) + newsock = sock_alloc(); + if (!newsock) goto out_put; newsock->type = sock->type; @@ -1861,8 +1869,7 @@ SYSCALL_DEFINE3(sendmsg, int, fd, struct msghdr __user *, msg, unsigned, flags) if (MSG_CMSG_COMPAT & flags) { if (get_compat_msghdr(&msg_sys, msg_compat)) return -EFAULT; - } - else if (copy_from_user(&msg_sys, msg, sizeof(struct msghdr))) + } else if (copy_from_user(&msg_sys, msg, sizeof(struct msghdr))) return -EFAULT; sock = sockfd_lookup_light(fd, &err, &fput_needed); @@ -1964,8 +1971,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg, if (MSG_CMSG_COMPAT & flags) { if (get_compat_msghdr(msg_sys, msg_compat)) return -EFAULT; - } - else if (copy_from_user(msg_sys, msg, sizeof(struct msghdr))) + } else if (copy_from_user(msg_sys, msg, sizeof(struct msghdr))) return -EFAULT; err = -EMSGSIZE; @@ -2191,10 +2197,10 @@ SYSCALL_DEFINE5(recvmmsg, int, fd, struct mmsghdr __user *, mmsg, /* Argument list sizes for sys_socketcall */ #define AL(x) ((x) * sizeof(unsigned long)) static const unsigned char nargs[20] = { - AL(0),AL(3),AL(3),AL(3),AL(2),AL(3), - AL(3),AL(3),AL(4),AL(4),AL(4),AL(6), - AL(6),AL(2),AL(5),AL(5),AL(3),AL(3), - AL(4),AL(5) + AL(0), AL(3), AL(3), AL(3), AL(2), AL(3), + AL(3), AL(3), AL(4), AL(4), AL(4), AL(6), + AL(6), AL(2), AL(5), AL(5), AL(3), AL(3), + AL(4), AL(5) }; #undef AL @@ -2340,6 +2346,7 @@ int sock_register(const struct net_proto_family *ops) printk(KERN_INFO "NET: Registered protocol family %d\n", ops->family); return err; } +EXPORT_SYMBOL(sock_register); /** * sock_unregister - remove a protocol handler @@ -2366,6 +2373,7 @@ void sock_unregister(int family) printk(KERN_INFO "NET: Unregistered protocol family %d\n", family); } +EXPORT_SYMBOL(sock_unregister); static int __init sock_init(void) { @@ -2490,13 +2498,13 @@ static int dev_ifconf(struct net *net, struct compat_ifconf __user *uifc32) ifc.ifc_req = NULL; uifc = compat_alloc_user_space(sizeof(struct ifconf)); } else { - size_t len =((ifc32.ifc_len / sizeof (struct compat_ifreq)) + 1) * - sizeof (struct ifreq); + size_t len = ((ifc32.ifc_len / sizeof(struct compat_ifreq)) + 1) * + sizeof(struct ifreq); uifc = compat_alloc_user_space(sizeof(struct ifconf) + len); ifc.ifc_len = len; ifr = ifc.ifc_req = (void __user *)(uifc + 1); ifr32 = compat_ptr(ifc32.ifcbuf); - for (i = 0; i < ifc32.ifc_len; i += sizeof (struct compat_ifreq)) { + for (i = 0; i < ifc32.ifc_len; i += sizeof(struct compat_ifreq)) { if (copy_in_user(ifr, ifr32, sizeof(struct compat_ifreq))) return -EFAULT; ifr++; @@ -2516,9 +2524,9 @@ static int dev_ifconf(struct net *net, struct compat_ifconf __user *uifc32) ifr = ifc.ifc_req; ifr32 = compat_ptr(ifc32.ifcbuf); for (i = 0, j = 0; - i + sizeof (struct compat_ifreq) <= ifc32.ifc_len && j < ifc.ifc_len; - i += sizeof (struct compat_ifreq), j += sizeof (struct ifreq)) { - if (copy_in_user(ifr32, ifr, sizeof (struct compat_ifreq))) + i + sizeof(struct compat_ifreq) <= ifc32.ifc_len && j < ifc.ifc_len; + i += sizeof(struct compat_ifreq), j += sizeof(struct ifreq)) { + if (copy_in_user(ifr32, ifr, sizeof(struct compat_ifreq))) return -EFAULT; ifr32++; ifr++; @@ -2567,7 +2575,7 @@ static int compat_siocwandev(struct net *net, struct compat_ifreq __user *uifr32 compat_uptr_t uptr32; struct ifreq __user *uifr; - uifr = compat_alloc_user_space(sizeof (*uifr)); + uifr = compat_alloc_user_space(sizeof(*uifr)); if (copy_in_user(uifr, uifr32, sizeof(struct compat_ifreq))) return -EFAULT; @@ -2601,9 +2609,9 @@ static int bond_ioctl(struct net *net, unsigned int cmd, return -EFAULT; old_fs = get_fs(); - set_fs (KERNEL_DS); + set_fs(KERNEL_DS); err = dev_ioctl(net, cmd, &kifr); - set_fs (old_fs); + set_fs(old_fs); return err; case SIOCBONDSLAVEINFOQUERY: @@ -2710,9 +2718,9 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd, return -EFAULT; old_fs = get_fs(); - set_fs (KERNEL_DS); + set_fs(KERNEL_DS); err = dev_ioctl(net, cmd, (void __user *)&ifr); - set_fs (old_fs); + set_fs(old_fs); if (cmd == SIOCGIFMAP && !err) { err = copy_to_user(uifr32, &ifr, sizeof(ifr.ifr_name)); @@ -2734,7 +2742,7 @@ static int compat_siocshwtstamp(struct net *net, struct compat_ifreq __user *uif compat_uptr_t uptr32; struct ifreq __user *uifr; - uifr = compat_alloc_user_space(sizeof (*uifr)); + uifr = compat_alloc_user_space(sizeof(*uifr)); if (copy_in_user(uifr, uifr32, sizeof(struct compat_ifreq))) return -EFAULT; @@ -2750,20 +2758,20 @@ static int compat_siocshwtstamp(struct net *net, struct compat_ifreq __user *uif } struct rtentry32 { - u32 rt_pad1; + u32 rt_pad1; struct sockaddr rt_dst; /* target address */ struct sockaddr rt_gateway; /* gateway addr (RTF_GATEWAY) */ struct sockaddr rt_genmask; /* target network mask (IP) */ - unsigned short rt_flags; - short rt_pad2; - u32 rt_pad3; - unsigned char rt_tos; - unsigned char rt_class; - short rt_pad4; - short rt_metric; /* +1 for binary compatibility! */ + unsigned short rt_flags; + short rt_pad2; + u32 rt_pad3; + unsigned char rt_tos; + unsigned char rt_class; + short rt_pad4; + short rt_metric; /* +1 for binary compatibility! */ /* char * */ u32 rt_dev; /* forcing the device at add */ - u32 rt_mtu; /* per route MTU/Window */ - u32 rt_window; /* Window clamping */ + u32 rt_mtu; /* per route MTU/Window */ + u32 rt_window; /* Window clamping */ unsigned short rt_irtt; /* Initial RTT */ }; @@ -2793,29 +2801,29 @@ static int routing_ioctl(struct net *net, struct socket *sock, if (sock && sock->sk && sock->sk->sk_family == AF_INET6) { /* ipv6 */ struct in6_rtmsg32 __user *ur6 = argp; - ret = copy_from_user (&r6.rtmsg_dst, &(ur6->rtmsg_dst), + ret = copy_from_user(&r6.rtmsg_dst, &(ur6->rtmsg_dst), 3 * sizeof(struct in6_addr)); - ret |= __get_user (r6.rtmsg_type, &(ur6->rtmsg_type)); - ret |= __get_user (r6.rtmsg_dst_len, &(ur6->rtmsg_dst_len)); - ret |= __get_user (r6.rtmsg_src_len, &(ur6->rtmsg_src_len)); - ret |= __get_user (r6.rtmsg_metric, &(ur6->rtmsg_metric)); - ret |= __get_user (r6.rtmsg_info, &(ur6->rtmsg_info)); - ret |= __get_user (r6.rtmsg_flags, &(ur6->rtmsg_flags)); - ret |= __get_user (r6.rtmsg_ifindex, &(ur6->rtmsg_ifindex)); + ret |= __get_user(r6.rtmsg_type, &(ur6->rtmsg_type)); + ret |= __get_user(r6.rtmsg_dst_len, &(ur6->rtmsg_dst_len)); + ret |= __get_user(r6.rtmsg_src_len, &(ur6->rtmsg_src_len)); + ret |= __get_user(r6.rtmsg_metric, &(ur6->rtmsg_metric)); + ret |= __get_user(r6.rtmsg_info, &(ur6->rtmsg_info)); + ret |= __get_user(r6.rtmsg_flags, &(ur6->rtmsg_flags)); + ret |= __get_user(r6.rtmsg_ifindex, &(ur6->rtmsg_ifindex)); r = (void *) &r6; } else { /* ipv4 */ struct rtentry32 __user *ur4 = argp; - ret = copy_from_user (&r4.rt_dst, &(ur4->rt_dst), + ret = copy_from_user(&r4.rt_dst, &(ur4->rt_dst), 3 * sizeof(struct sockaddr)); - ret |= __get_user (r4.rt_flags, &(ur4->rt_flags)); - ret |= __get_user (r4.rt_metric, &(ur4->rt_metric)); - ret |= __get_user (r4.rt_mtu, &(ur4->rt_mtu)); - ret |= __get_user (r4.rt_window, &(ur4->rt_window)); - ret |= __get_user (r4.rt_irtt, &(ur4->rt_irtt)); - ret |= __get_user (rtdev, &(ur4->rt_dev)); + ret |= __get_user(r4.rt_flags, &(ur4->rt_flags)); + ret |= __get_user(r4.rt_metric, &(ur4->rt_metric)); + ret |= __get_user(r4.rt_mtu, &(ur4->rt_mtu)); + ret |= __get_user(r4.rt_window, &(ur4->rt_window)); + ret |= __get_user(r4.rt_irtt, &(ur4->rt_irtt)); + ret |= __get_user(rtdev, &(ur4->rt_dev)); if (rtdev) { - ret |= copy_from_user (devname, compat_ptr(rtdev), 15); + ret |= copy_from_user(devname, compat_ptr(rtdev), 15); r4.rt_dev = devname; devname[15] = 0; } else r4.rt_dev = NULL; @@ -2828,9 +2836,9 @@ static int routing_ioctl(struct net *net, struct socket *sock, goto out; } - set_fs (KERNEL_DS); + set_fs(KERNEL_DS); ret = sock_do_ioctl(net, sock, cmd, (unsigned long) r); - set_fs (old_fs); + set_fs(old_fs); out: return ret; @@ -2993,11 +3001,13 @@ int kernel_bind(struct socket *sock, struct sockaddr *addr, int addrlen) { return sock->ops->bind(sock, addr, addrlen); } +EXPORT_SYMBOL(kernel_bind); int kernel_listen(struct socket *sock, int backlog) { return sock->ops->listen(sock, backlog); } +EXPORT_SYMBOL(kernel_listen); int kernel_accept(struct socket *sock, struct socket **newsock, int flags) { @@ -3022,24 +3032,28 @@ int kernel_accept(struct socket *sock, struct socket **newsock, int flags) done: return err; } +EXPORT_SYMBOL(kernel_accept); int kernel_connect(struct socket *sock, struct sockaddr *addr, int addrlen, int flags) { return sock->ops->connect(sock, addr, addrlen, flags); } +EXPORT_SYMBOL(kernel_connect); int kernel_getsockname(struct socket *sock, struct sockaddr *addr, int *addrlen) { return sock->ops->getname(sock, addr, addrlen, 0); } +EXPORT_SYMBOL(kernel_getsockname); int kernel_getpeername(struct socket *sock, struct sockaddr *addr, int *addrlen) { return sock->ops->getname(sock, addr, addrlen, 1); } +EXPORT_SYMBOL(kernel_getpeername); int kernel_getsockopt(struct socket *sock, int level, int optname, char *optval, int *optlen) @@ -3056,6 +3070,7 @@ int kernel_getsockopt(struct socket *sock, int level, int optname, set_fs(oldfs); return err; } +EXPORT_SYMBOL(kernel_getsockopt); int kernel_setsockopt(struct socket *sock, int level, int optname, char *optval, unsigned int optlen) @@ -3072,6 +3087,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname, set_fs(oldfs); return err; } +EXPORT_SYMBOL(kernel_setsockopt); int kernel_sendpage(struct socket *sock, struct page *page, int offset, size_t size, int flags) @@ -3083,6 +3099,7 @@ int kernel_sendpage(struct socket *sock, struct page *page, int offset, return sock_no_sendpage(sock, page, offset, size, flags); } +EXPORT_SYMBOL(kernel_sendpage); int kernel_sock_ioctl(struct socket *sock, int cmd, unsigned long arg) { @@ -3095,33 +3112,11 @@ int kernel_sock_ioctl(struct socket *sock, int cmd, unsigned long arg) return err; } +EXPORT_SYMBOL(kernel_sock_ioctl); int kernel_sock_shutdown(struct socket *sock, enum sock_shutdown_cmd how) { return sock->ops->shutdown(sock, how); } - -EXPORT_SYMBOL(sock_create); -EXPORT_SYMBOL(sock_create_kern); -EXPORT_SYMBOL(sock_create_lite); -EXPORT_SYMBOL(sock_map_fd); -EXPORT_SYMBOL(sock_recvmsg); -EXPORT_SYMBOL(sock_register); -EXPORT_SYMBOL(sock_release); -EXPORT_SYMBOL(sock_sendmsg); -EXPORT_SYMBOL(sock_unregister); -EXPORT_SYMBOL(sock_wake_async); -EXPORT_SYMBOL(sockfd_lookup); -EXPORT_SYMBOL(kernel_sendmsg); -EXPORT_SYMBOL(kernel_recvmsg); -EXPORT_SYMBOL(kernel_bind); -EXPORT_SYMBOL(kernel_listen); -EXPORT_SYMBOL(kernel_accept); -EXPORT_SYMBOL(kernel_connect); -EXPORT_SYMBOL(kernel_getsockname); -EXPORT_SYMBOL(kernel_getpeername); -EXPORT_SYMBOL(kernel_getsockopt); -EXPORT_SYMBOL(kernel_setsockopt); -EXPORT_SYMBOL(kernel_sendpage); -EXPORT_SYMBOL(kernel_sock_ioctl); EXPORT_SYMBOL(kernel_sock_shutdown); + -- 1.7.0.4
-rw-r--r--net/compat.c47
-rw-r--r--net/socket.c164
2 files changed, 101 insertions, 110 deletions
diff --git a/net/compat.c b/net/compat.c
index 1cf75905f132..63d260e81472 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -81,7 +81,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
81 int tot_len; 81 int tot_len;
82 82
83 if (kern_msg->msg_namelen) { 83 if (kern_msg->msg_namelen) {
84 if (mode==VERIFY_READ) { 84 if (mode == VERIFY_READ) {
85 int err = move_addr_to_kernel(kern_msg->msg_name, 85 int err = move_addr_to_kernel(kern_msg->msg_name,
86 kern_msg->msg_namelen, 86 kern_msg->msg_namelen,
87 kern_address); 87 kern_address);
@@ -354,7 +354,7 @@ static int do_set_attach_filter(struct socket *sock, int level, int optname,
354static int do_set_sock_timeout(struct socket *sock, int level, 354static int do_set_sock_timeout(struct socket *sock, int level,
355 int optname, char __user *optval, unsigned int optlen) 355 int optname, char __user *optval, unsigned int optlen)
356{ 356{
357 struct compat_timeval __user *up = (struct compat_timeval __user *) optval; 357 struct compat_timeval __user *up = (struct compat_timeval __user *)optval;
358 struct timeval ktime; 358 struct timeval ktime;
359 mm_segment_t old_fs; 359 mm_segment_t old_fs;
360 int err; 360 int err;
@@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
367 return -EFAULT; 367 return -EFAULT;
368 old_fs = get_fs(); 368 old_fs = get_fs();
369 set_fs(KERNEL_DS); 369 set_fs(KERNEL_DS);
370 err = sock_setsockopt(sock, level, optname, (char *) &ktime, sizeof(ktime)); 370 err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
371 set_fs(old_fs); 371 set_fs(old_fs);
372 372
373 return err; 373 return err;
@@ -389,11 +389,10 @@ asmlinkage long compat_sys_setsockopt(int fd, int level, int optname,
389 char __user *optval, unsigned int optlen) 389 char __user *optval, unsigned int optlen)
390{ 390{
391 int err; 391 int err;
392 struct socket *sock; 392 struct socket *sock = sockfd_lookup(fd, &err);
393 393
394 if ((sock = sockfd_lookup(fd, &err))!=NULL) 394 if (sock) {
395 { 395 err = security_socket_setsockopt(sock, level, optname);
396 err = security_socket_setsockopt(sock,level,optname);
397 if (err) { 396 if (err) {
398 sockfd_put(sock); 397 sockfd_put(sock);
399 return err; 398 return err;
@@ -453,7 +452,7 @@ static int compat_sock_getsockopt(struct socket *sock, int level, int optname,
453int compat_sock_get_timestamp(struct sock *sk, struct timeval __user *userstamp) 452int compat_sock_get_timestamp(struct sock *sk, struct timeval __user *userstamp)
454{ 453{
455 struct compat_timeval __user *ctv = 454 struct compat_timeval __user *ctv =
456 (struct compat_timeval __user*) userstamp; 455 (struct compat_timeval __user *) userstamp;
457 int err = -ENOENT; 456 int err = -ENOENT;
458 struct timeval tv; 457 struct timeval tv;
459 458
@@ -477,7 +476,7 @@ EXPORT_SYMBOL(compat_sock_get_timestamp);
477int compat_sock_get_timestampns(struct sock *sk, struct timespec __user *userstamp) 476int compat_sock_get_timestampns(struct sock *sk, struct timespec __user *userstamp)
478{ 477{
479 struct compat_timespec __user *ctv = 478 struct compat_timespec __user *ctv =
480 (struct compat_timespec __user*) userstamp; 479 (struct compat_timespec __user *) userstamp;
481 int err = -ENOENT; 480 int err = -ENOENT;
482 struct timespec ts; 481 struct timespec ts;
483 482
@@ -502,12 +501,10 @@ asmlinkage long compat_sys_getsockopt(int fd, int level, int optname,
502 char __user *optval, int __user *optlen) 501 char __user *optval, int __user *optlen)
503{ 502{
504 int err; 503 int err;
505 struct socket *sock; 504 struct socket *sock = sockfd_lookup(fd, &err);
506 505
507 if ((sock = sockfd_lookup(fd, &err))!=NULL) 506 if (sock) {
508 { 507 err = security_socket_getsockopt(sock, level, optname);
509 err = security_socket_getsockopt(sock, level,
510 optname);
511 if (err) { 508 if (err) {
512 sockfd_put(sock); 509 sockfd_put(sock);
513 return err; 510 return err;
@@ -557,7 +554,7 @@ struct compat_group_filter {
557 554
558int compat_mc_setsockopt(struct sock *sock, int level, int optname, 555int compat_mc_setsockopt(struct sock *sock, int level, int optname,
559 char __user *optval, unsigned int optlen, 556 char __user *optval, unsigned int optlen,
560 int (*setsockopt)(struct sock *,int,int,char __user *,unsigned int)) 557 int (*setsockopt)(struct sock *, int, int, char __user *, unsigned int))
561{ 558{
562 char __user *koptval = optval; 559 char __user *koptval = optval;
563 int koptlen = optlen; 560 int koptlen = optlen;
@@ -640,12 +637,11 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
640 } 637 }
641 return setsockopt(sock, level, optname, koptval, koptlen); 638 return setsockopt(sock, level, optname, koptval, koptlen);
642} 639}
643
644EXPORT_SYMBOL(compat_mc_setsockopt); 640EXPORT_SYMBOL(compat_mc_setsockopt);
645 641
646int compat_mc_getsockopt(struct sock *sock, int level, int optname, 642int compat_mc_getsockopt(struct sock *sock, int level, int optname,
647 char __user *optval, int __user *optlen, 643 char __user *optval, int __user *optlen,
648 int (*getsockopt)(struct sock *,int,int,char __user *,int __user *)) 644 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
649{ 645{
650 struct compat_group_filter __user *gf32 = (void *)optval; 646 struct compat_group_filter __user *gf32 = (void *)optval;
651 struct group_filter __user *kgf; 647 struct group_filter __user *kgf;
@@ -681,7 +677,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
681 __put_user(interface, &kgf->gf_interface) || 677 __put_user(interface, &kgf->gf_interface) ||
682 __put_user(fmode, &kgf->gf_fmode) || 678 __put_user(fmode, &kgf->gf_fmode) ||
683 __put_user(numsrc, &kgf->gf_numsrc) || 679 __put_user(numsrc, &kgf->gf_numsrc) ||
684 copy_in_user(&kgf->gf_group,&gf32->gf_group,sizeof(kgf->gf_group))) 680 copy_in_user(&kgf->gf_group, &gf32->gf_group, sizeof(kgf->gf_group)))
685 return -EFAULT; 681 return -EFAULT;
686 682
687 err = getsockopt(sock, level, optname, (char __user *)kgf, koptlen); 683 err = getsockopt(sock, level, optname, (char __user *)kgf, koptlen);
@@ -714,21 +710,22 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
714 copylen = numsrc * sizeof(gf32->gf_slist[0]); 710 copylen = numsrc * sizeof(gf32->gf_slist[0]);
715 if (copylen > klen) 711 if (copylen > klen)
716 copylen = klen; 712 copylen = klen;
717 if (copy_in_user(gf32->gf_slist, kgf->gf_slist, copylen)) 713 if (copy_in_user(gf32->gf_slist, kgf->gf_slist, copylen))
718 return -EFAULT; 714 return -EFAULT;
719 } 715 }
720 return err; 716 return err;
721} 717}
722
723EXPORT_SYMBOL(compat_mc_getsockopt); 718EXPORT_SYMBOL(compat_mc_getsockopt);
724 719
725 720
726/* Argument list sizes for compat_sys_socketcall */ 721/* Argument list sizes for compat_sys_socketcall */
727#define AL(x) ((x) * sizeof(u32)) 722#define AL(x) ((x) * sizeof(u32))
728static unsigned char nas[20]={AL(0),AL(3),AL(3),AL(3),AL(2),AL(3), 723static unsigned char nas[20] = {
729 AL(3),AL(3),AL(4),AL(4),AL(4),AL(6), 724 AL(0), AL(3), AL(3), AL(3), AL(2), AL(3),
730 AL(6),AL(2),AL(5),AL(5),AL(3),AL(3), 725 AL(3), AL(3), AL(4), AL(4), AL(4), AL(6),
731 AL(4),AL(5)}; 726 AL(6), AL(2), AL(5), AL(5), AL(3), AL(3),
727 AL(4), AL(5)
728};
732#undef AL 729#undef AL
733 730
734asmlinkage long compat_sys_sendmsg(int fd, struct compat_msghdr __user *msg, unsigned flags) 731asmlinkage long compat_sys_sendmsg(int fd, struct compat_msghdr __user *msg, unsigned flags)
@@ -827,7 +824,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
827 compat_ptr(a[4]), compat_ptr(a[5])); 824 compat_ptr(a[4]), compat_ptr(a[5]));
828 break; 825 break;
829 case SYS_SHUTDOWN: 826 case SYS_SHUTDOWN:
830 ret = sys_shutdown(a0,a1); 827 ret = sys_shutdown(a0, a1);
831 break; 828 break;
832 case SYS_SETSOCKOPT: 829 case SYS_SETSOCKOPT:
833 ret = compat_sys_setsockopt(a0, a1, a[2], 830 ret = compat_sys_setsockopt(a0, a1, a[2],
diff --git a/net/socket.c b/net/socket.c
index 367d5477d00f..acfa1738663d 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -124,7 +124,7 @@ static int sock_fasync(int fd, struct file *filp, int on);
124static ssize_t sock_sendpage(struct file *file, struct page *page, 124static ssize_t sock_sendpage(struct file *file, struct page *page,
125 int offset, size_t size, loff_t *ppos, int more); 125 int offset, size_t size, loff_t *ppos, int more);
126static ssize_t sock_splice_read(struct file *file, loff_t *ppos, 126static ssize_t sock_splice_read(struct file *file, loff_t *ppos,
127 struct pipe_inode_info *pipe, size_t len, 127 struct pipe_inode_info *pipe, size_t len,
128 unsigned int flags); 128 unsigned int flags);
129 129
130/* 130/*
@@ -162,7 +162,7 @@ static const struct net_proto_family *net_families[NPROTO] __read_mostly;
162 * Statistics counters of the socket lists 162 * Statistics counters of the socket lists
163 */ 163 */
164 164
165static DEFINE_PER_CPU(int, sockets_in_use) = 0; 165static DEFINE_PER_CPU(int, sockets_in_use);
166 166
167/* 167/*
168 * Support routines. 168 * Support routines.
@@ -309,9 +309,9 @@ static int init_inodecache(void)
309} 309}
310 310
311static const struct super_operations sockfs_ops = { 311static const struct super_operations sockfs_ops = {
312 .alloc_inode = sock_alloc_inode, 312 .alloc_inode = sock_alloc_inode,
313 .destroy_inode =sock_destroy_inode, 313 .destroy_inode = sock_destroy_inode,
314 .statfs = simple_statfs, 314 .statfs = simple_statfs,
315}; 315};
316 316
317static int sockfs_get_sb(struct file_system_type *fs_type, 317static int sockfs_get_sb(struct file_system_type *fs_type,
@@ -411,6 +411,7 @@ int sock_map_fd(struct socket *sock, int flags)
411 411
412 return fd; 412 return fd;
413} 413}
414EXPORT_SYMBOL(sock_map_fd);
414 415
415static struct socket *sock_from_file(struct file *file, int *err) 416static struct socket *sock_from_file(struct file *file, int *err)
416{ 417{
@@ -422,7 +423,7 @@ static struct socket *sock_from_file(struct file *file, int *err)
422} 423}
423 424
424/** 425/**
425 * sockfd_lookup - Go from a file number to its socket slot 426 * sockfd_lookup - Go from a file number to its socket slot
426 * @fd: file handle 427 * @fd: file handle
427 * @err: pointer to an error code return 428 * @err: pointer to an error code return
428 * 429 *
@@ -450,6 +451,7 @@ struct socket *sockfd_lookup(int fd, int *err)
450 fput(file); 451 fput(file);
451 return sock; 452 return sock;
452} 453}
454EXPORT_SYMBOL(sockfd_lookup);
453 455
454static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed) 456static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed)
455{ 457{
@@ -540,6 +542,7 @@ void sock_release(struct socket *sock)
540 } 542 }
541 sock->file = NULL; 543 sock->file = NULL;
542} 544}
545EXPORT_SYMBOL(sock_release);
543 546
544int sock_tx_timestamp(struct msghdr *msg, struct sock *sk, 547int sock_tx_timestamp(struct msghdr *msg, struct sock *sk,
545 union skb_shared_tx *shtx) 548 union skb_shared_tx *shtx)
@@ -586,6 +589,7 @@ int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
586 ret = wait_on_sync_kiocb(&iocb); 589 ret = wait_on_sync_kiocb(&iocb);
587 return ret; 590 return ret;
588} 591}
592EXPORT_SYMBOL(sock_sendmsg);
589 593
590int kernel_sendmsg(struct socket *sock, struct msghdr *msg, 594int kernel_sendmsg(struct socket *sock, struct msghdr *msg,
591 struct kvec *vec, size_t num, size_t size) 595 struct kvec *vec, size_t num, size_t size)
@@ -604,6 +608,7 @@ int kernel_sendmsg(struct socket *sock, struct msghdr *msg,
604 set_fs(oldfs); 608 set_fs(oldfs);
605 return result; 609 return result;
606} 610}
611EXPORT_SYMBOL(kernel_sendmsg);
607 612
608static int ktime2ts(ktime_t kt, struct timespec *ts) 613static int ktime2ts(ktime_t kt, struct timespec *ts)
609{ 614{
@@ -664,7 +669,6 @@ void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk,
664 put_cmsg(msg, SOL_SOCKET, 669 put_cmsg(msg, SOL_SOCKET,
665 SCM_TIMESTAMPING, sizeof(ts), &ts); 670 SCM_TIMESTAMPING, sizeof(ts), &ts);
666} 671}
667
668EXPORT_SYMBOL_GPL(__sock_recv_timestamp); 672EXPORT_SYMBOL_GPL(__sock_recv_timestamp);
669 673
670inline void sock_recv_drops(struct msghdr *msg, struct sock *sk, struct sk_buff *skb) 674inline void sock_recv_drops(struct msghdr *msg, struct sock *sk, struct sk_buff *skb)
@@ -720,6 +724,7 @@ int sock_recvmsg(struct socket *sock, struct msghdr *msg,
720 ret = wait_on_sync_kiocb(&iocb); 724 ret = wait_on_sync_kiocb(&iocb);
721 return ret; 725 return ret;
722} 726}
727EXPORT_SYMBOL(sock_recvmsg);
723 728
724static int sock_recvmsg_nosec(struct socket *sock, struct msghdr *msg, 729static int sock_recvmsg_nosec(struct socket *sock, struct msghdr *msg,
725 size_t size, int flags) 730 size_t size, int flags)
@@ -752,6 +757,7 @@ int kernel_recvmsg(struct socket *sock, struct msghdr *msg,
752 set_fs(oldfs); 757 set_fs(oldfs);
753 return result; 758 return result;
754} 759}
760EXPORT_SYMBOL(kernel_recvmsg);
755 761
756static void sock_aio_dtor(struct kiocb *iocb) 762static void sock_aio_dtor(struct kiocb *iocb)
757{ 763{
@@ -774,7 +780,7 @@ static ssize_t sock_sendpage(struct file *file, struct page *page,
774} 780}
775 781
776static ssize_t sock_splice_read(struct file *file, loff_t *ppos, 782static ssize_t sock_splice_read(struct file *file, loff_t *ppos,
777 struct pipe_inode_info *pipe, size_t len, 783 struct pipe_inode_info *pipe, size_t len,
778 unsigned int flags) 784 unsigned int flags)
779{ 785{
780 struct socket *sock = file->private_data; 786 struct socket *sock = file->private_data;
@@ -887,7 +893,7 @@ static ssize_t sock_aio_write(struct kiocb *iocb, const struct iovec *iov,
887 */ 893 */
888 894
889static DEFINE_MUTEX(br_ioctl_mutex); 895static DEFINE_MUTEX(br_ioctl_mutex);
890static int (*br_ioctl_hook) (struct net *, unsigned int cmd, void __user *arg) = NULL; 896static int (*br_ioctl_hook) (struct net *, unsigned int cmd, void __user *arg);
891 897
892void brioctl_set(int (*hook) (struct net *, unsigned int, void __user *)) 898void brioctl_set(int (*hook) (struct net *, unsigned int, void __user *))
893{ 899{
@@ -895,7 +901,6 @@ void brioctl_set(int (*hook) (struct net *, unsigned int, void __user *))
895 br_ioctl_hook = hook; 901 br_ioctl_hook = hook;
896 mutex_unlock(&br_ioctl_mutex); 902 mutex_unlock(&br_ioctl_mutex);
897} 903}
898
899EXPORT_SYMBOL(brioctl_set); 904EXPORT_SYMBOL(brioctl_set);
900 905
901static DEFINE_MUTEX(vlan_ioctl_mutex); 906static DEFINE_MUTEX(vlan_ioctl_mutex);
@@ -907,7 +912,6 @@ void vlan_ioctl_set(int (*hook) (struct net *, void __user *))
907 vlan_ioctl_hook = hook; 912 vlan_ioctl_hook = hook;
908 mutex_unlock(&vlan_ioctl_mutex); 913 mutex_unlock(&vlan_ioctl_mutex);
909} 914}
910
911EXPORT_SYMBOL(vlan_ioctl_set); 915EXPORT_SYMBOL(vlan_ioctl_set);
912 916
913static DEFINE_MUTEX(dlci_ioctl_mutex); 917static DEFINE_MUTEX(dlci_ioctl_mutex);
@@ -919,7 +923,6 @@ void dlci_ioctl_set(int (*hook) (unsigned int, void __user *))
919 dlci_ioctl_hook = hook; 923 dlci_ioctl_hook = hook;
920 mutex_unlock(&dlci_ioctl_mutex); 924 mutex_unlock(&dlci_ioctl_mutex);
921} 925}
922
923EXPORT_SYMBOL(dlci_ioctl_set); 926EXPORT_SYMBOL(dlci_ioctl_set);
924 927
925static long sock_do_ioctl(struct net *net, struct socket *sock, 928static long sock_do_ioctl(struct net *net, struct socket *sock,
@@ -1047,6 +1050,7 @@ out_release:
1047 sock = NULL; 1050 sock = NULL;
1048 goto out; 1051 goto out;
1049} 1052}
1053EXPORT_SYMBOL(sock_create_lite);
1050 1054
1051/* No kernel lock held - perfect */ 1055/* No kernel lock held - perfect */
1052static unsigned int sock_poll(struct file *file, poll_table *wait) 1056static unsigned int sock_poll(struct file *file, poll_table *wait)
@@ -1147,6 +1151,7 @@ call_kill:
1147 rcu_read_unlock(); 1151 rcu_read_unlock();
1148 return 0; 1152 return 0;
1149} 1153}
1154EXPORT_SYMBOL(sock_wake_async);
1150 1155
1151static int __sock_create(struct net *net, int family, int type, int protocol, 1156static int __sock_create(struct net *net, int family, int type, int protocol,
1152 struct socket **res, int kern) 1157 struct socket **res, int kern)
@@ -1265,11 +1270,13 @@ int sock_create(int family, int type, int protocol, struct socket **res)
1265{ 1270{
1266 return __sock_create(current->nsproxy->net_ns, family, type, protocol, res, 0); 1271 return __sock_create(current->nsproxy->net_ns, family, type, protocol, res, 0);
1267} 1272}
1273EXPORT_SYMBOL(sock_create);
1268 1274
1269int sock_create_kern(int family, int type, int protocol, struct socket **res) 1275int sock_create_kern(int family, int type, int protocol, struct socket **res)
1270{ 1276{
1271 return __sock_create(&init_net, family, type, protocol, res, 1); 1277 return __sock_create(&init_net, family, type, protocol, res, 1);
1272} 1278}
1279EXPORT_SYMBOL(sock_create_kern);
1273 1280
1274SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol) 1281SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
1275{ 1282{
@@ -1474,7 +1481,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
1474 goto out; 1481 goto out;
1475 1482
1476 err = -ENFILE; 1483 err = -ENFILE;
1477 if (!(newsock = sock_alloc())) 1484 newsock = sock_alloc();
1485 if (!newsock)
1478 goto out_put; 1486 goto out_put;
1479 1487
1480 newsock->type = sock->type; 1488 newsock->type = sock->type;
@@ -1861,8 +1869,7 @@ SYSCALL_DEFINE3(sendmsg, int, fd, struct msghdr __user *, msg, unsigned, flags)
1861 if (MSG_CMSG_COMPAT & flags) { 1869 if (MSG_CMSG_COMPAT & flags) {
1862 if (get_compat_msghdr(&msg_sys, msg_compat)) 1870 if (get_compat_msghdr(&msg_sys, msg_compat))
1863 return -EFAULT; 1871 return -EFAULT;
1864 } 1872 } else if (copy_from_user(&msg_sys, msg, sizeof(struct msghdr)))
1865 else if (copy_from_user(&msg_sys, msg, sizeof(struct msghdr)))
1866 return -EFAULT; 1873 return -EFAULT;
1867 1874
1868 sock = sockfd_lookup_light(fd, &err, &fput_needed); 1875 sock = sockfd_lookup_light(fd, &err, &fput_needed);
@@ -1964,8 +1971,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
1964 if (MSG_CMSG_COMPAT & flags) { 1971 if (MSG_CMSG_COMPAT & flags) {
1965 if (get_compat_msghdr(msg_sys, msg_compat)) 1972 if (get_compat_msghdr(msg_sys, msg_compat))
1966 return -EFAULT; 1973 return -EFAULT;
1967 } 1974 } else if (copy_from_user(msg_sys, msg, sizeof(struct msghdr)))
1968 else if (copy_from_user(msg_sys, msg, sizeof(struct msghdr)))
1969 return -EFAULT; 1975 return -EFAULT;
1970 1976
1971 err = -EMSGSIZE; 1977 err = -EMSGSIZE;
@@ -2191,10 +2197,10 @@ SYSCALL_DEFINE5(recvmmsg, int, fd, struct mmsghdr __user *, mmsg,
2191/* Argument list sizes for sys_socketcall */ 2197/* Argument list sizes for sys_socketcall */
2192#define AL(x) ((x) * sizeof(unsigned long)) 2198#define AL(x) ((x) * sizeof(unsigned long))
2193static const unsigned char nargs[20] = { 2199static const unsigned char nargs[20] = {
2194 AL(0),AL(3),AL(3),AL(3),AL(2),AL(3), 2200 AL(0), AL(3), AL(3), AL(3), AL(2), AL(3),
2195 AL(3),AL(3),AL(4),AL(4),AL(4),AL(6), 2201 AL(3), AL(3), AL(4), AL(4), AL(4), AL(6),
2196 AL(6),AL(2),AL(5),AL(5),AL(3),AL(3), 2202 AL(6), AL(2), AL(5), AL(5), AL(3), AL(3),
2197 AL(4),AL(5) 2203 AL(4), AL(5)
2198}; 2204};
2199 2205
2200#undef AL 2206#undef AL
@@ -2340,6 +2346,7 @@ int sock_register(const struct net_proto_family *ops)
2340 printk(KERN_INFO "NET: Registered protocol family %d\n", ops->family); 2346 printk(KERN_INFO "NET: Registered protocol family %d\n", ops->family);
2341 return err; 2347 return err;
2342} 2348}
2349EXPORT_SYMBOL(sock_register);
2343 2350
2344/** 2351/**
2345 * sock_unregister - remove a protocol handler 2352 * sock_unregister - remove a protocol handler
@@ -2366,6 +2373,7 @@ void sock_unregister(int family)
2366 2373
2367 printk(KERN_INFO "NET: Unregistered protocol family %d\n", family); 2374 printk(KERN_INFO "NET: Unregistered protocol family %d\n", family);
2368} 2375}
2376EXPORT_SYMBOL(sock_unregister);
2369 2377
2370static int __init sock_init(void) 2378static int __init sock_init(void)
2371{ 2379{
@@ -2490,13 +2498,13 @@ static int dev_ifconf(struct net *net, struct compat_ifconf __user *uifc32)
2490 ifc.ifc_req = NULL; 2498 ifc.ifc_req = NULL;
2491 uifc = compat_alloc_user_space(sizeof(struct ifconf)); 2499 uifc = compat_alloc_user_space(sizeof(struct ifconf));
2492 } else { 2500 } else {
2493 size_t len =((ifc32.ifc_len / sizeof (struct compat_ifreq)) + 1) * 2501 size_t len = ((ifc32.ifc_len / sizeof(struct compat_ifreq)) + 1) *
2494 sizeof (struct ifreq); 2502 sizeof(struct ifreq);
2495 uifc = compat_alloc_user_space(sizeof(struct ifconf) + len); 2503 uifc = compat_alloc_user_space(sizeof(struct ifconf) + len);
2496 ifc.ifc_len = len; 2504 ifc.ifc_len = len;
2497 ifr = ifc.ifc_req = (void __user *)(uifc + 1); 2505 ifr = ifc.ifc_req = (void __user *)(uifc + 1);
2498 ifr32 = compat_ptr(ifc32.ifcbuf); 2506 ifr32 = compat_ptr(ifc32.ifcbuf);
2499 for (i = 0; i < ifc32.ifc_len; i += sizeof (struct compat_ifreq)) { 2507 for (i = 0; i < ifc32.ifc_len; i += sizeof(struct compat_ifreq)) {
2500 if (copy_in_user(ifr, ifr32, sizeof(struct compat_ifreq))) 2508 if (copy_in_user(ifr, ifr32, sizeof(struct compat_ifreq)))
2501 return -EFAULT; 2509 return -EFAULT;
2502 ifr++; 2510 ifr++;
@@ -2516,9 +2524,9 @@ static int dev_ifconf(struct net *net, struct compat_ifconf __user *uifc32)
2516 ifr = ifc.ifc_req; 2524 ifr = ifc.ifc_req;
2517 ifr32 = compat_ptr(ifc32.ifcbuf); 2525 ifr32 = compat_ptr(ifc32.ifcbuf);
2518 for (i = 0, j = 0; 2526 for (i = 0, j = 0;
2519 i + sizeof (struct compat_ifreq) <= ifc32.ifc_len && j < ifc.ifc_len; 2527 i + sizeof(struct compat_ifreq) <= ifc32.ifc_len && j < ifc.ifc_len;
2520 i += sizeof (struct compat_ifreq), j += sizeof (struct ifreq)) { 2528 i += sizeof(struct compat_ifreq), j += sizeof(struct ifreq)) {
2521 if (copy_in_user(ifr32, ifr, sizeof (struct compat_ifreq))) 2529 if (copy_in_user(ifr32, ifr, sizeof(struct compat_ifreq)))
2522 return -EFAULT; 2530 return -EFAULT;
2523 ifr32++; 2531 ifr32++;
2524 ifr++; 2532 ifr++;
@@ -2567,7 +2575,7 @@ static int compat_siocwandev(struct net *net, struct compat_ifreq __user *uifr32
2567 compat_uptr_t uptr32; 2575 compat_uptr_t uptr32;
2568 struct ifreq __user *uifr; 2576 struct ifreq __user *uifr;
2569 2577
2570 uifr = compat_alloc_user_space(sizeof (*uifr)); 2578 uifr = compat_alloc_user_space(sizeof(*uifr));
2571 if (copy_in_user(uifr, uifr32, sizeof(struct compat_ifreq))) 2579 if (copy_in_user(uifr, uifr32, sizeof(struct compat_ifreq)))
2572 return -EFAULT; 2580 return -EFAULT;
2573 2581
@@ -2601,9 +2609,9 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
2601 return -EFAULT; 2609 return -EFAULT;
2602 2610
2603 old_fs = get_fs(); 2611 old_fs = get_fs();
2604 set_fs (KERNEL_DS); 2612 set_fs(KERNEL_DS);
2605 err = dev_ioctl(net, cmd, &kifr); 2613 err = dev_ioctl(net, cmd, &kifr);
2606 set_fs (old_fs); 2614 set_fs(old_fs);
2607 2615
2608 return err; 2616 return err;
2609 case SIOCBONDSLAVEINFOQUERY: 2617 case SIOCBONDSLAVEINFOQUERY:
@@ -2710,9 +2718,9 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
2710 return -EFAULT; 2718 return -EFAULT;
2711 2719
2712 old_fs = get_fs(); 2720 old_fs = get_fs();
2713 set_fs (KERNEL_DS); 2721 set_fs(KERNEL_DS);
2714 err = dev_ioctl(net, cmd, (void __user *)&ifr); 2722 err = dev_ioctl(net, cmd, (void __user *)&ifr);
2715 set_fs (old_fs); 2723 set_fs(old_fs);
2716 2724
2717 if (cmd == SIOCGIFMAP && !err) { 2725 if (cmd == SIOCGIFMAP && !err) {
2718 err = copy_to_user(uifr32, &ifr, sizeof(ifr.ifr_name)); 2726 err = copy_to_user(uifr32, &ifr, sizeof(ifr.ifr_name));
@@ -2734,7 +2742,7 @@ static int compat_siocshwtstamp(struct net *net, struct compat_ifreq __user *uif
2734 compat_uptr_t uptr32; 2742 compat_uptr_t uptr32;
2735 struct ifreq __user *uifr; 2743 struct ifreq __user *uifr;
2736 2744
2737 uifr = compat_alloc_user_space(sizeof (*uifr)); 2745 uifr = compat_alloc_user_space(sizeof(*uifr));
2738 if (copy_in_user(uifr, uifr32, sizeof(struct compat_ifreq))) 2746 if (copy_in_user(uifr, uifr32, sizeof(struct compat_ifreq)))
2739 return -EFAULT; 2747 return -EFAULT;
2740 2748
@@ -2750,20 +2758,20 @@ static int compat_siocshwtstamp(struct net *net, struct compat_ifreq __user *uif
2750} 2758}
2751 2759
2752struct rtentry32 { 2760struct rtentry32 {
2753 u32 rt_pad1; 2761 u32 rt_pad1;
2754 struct sockaddr rt_dst; /* target address */ 2762 struct sockaddr rt_dst; /* target address */
2755 struct sockaddr rt_gateway; /* gateway addr (RTF_GATEWAY) */ 2763 struct sockaddr rt_gateway; /* gateway addr (RTF_GATEWAY) */
2756 struct sockaddr rt_genmask; /* target network mask (IP) */ 2764 struct sockaddr rt_genmask; /* target network mask (IP) */
2757 unsigned short rt_flags; 2765 unsigned short rt_flags;
2758 short rt_pad2; 2766 short rt_pad2;
2759 u32 rt_pad3; 2767 u32 rt_pad3;
2760 unsigned char rt_tos; 2768 unsigned char rt_tos;
2761 unsigned char rt_class; 2769 unsigned char rt_class;
2762 short rt_pad4; 2770 short rt_pad4;
2763 short rt_metric; /* +1 for binary compatibility! */ 2771 short rt_metric; /* +1 for binary compatibility! */
2764 /* char * */ u32 rt_dev; /* forcing the device at add */ 2772 /* char * */ u32 rt_dev; /* forcing the device at add */
2765 u32 rt_mtu; /* per route MTU/Window */ 2773 u32 rt_mtu; /* per route MTU/Window */
2766 u32 rt_window; /* Window clamping */ 2774 u32 rt_window; /* Window clamping */
2767 unsigned short rt_irtt; /* Initial RTT */ 2775 unsigned short rt_irtt; /* Initial RTT */
2768}; 2776};
2769 2777
@@ -2793,29 +2801,29 @@ static int routing_ioctl(struct net *net, struct socket *sock,
2793 2801
2794 if (sock && sock->sk && sock->sk->sk_family == AF_INET6) { /* ipv6 */ 2802 if (sock && sock->sk && sock->sk->sk_family == AF_INET6) { /* ipv6 */
2795 struct in6_rtmsg32 __user *ur6 = argp; 2803 struct in6_rtmsg32 __user *ur6 = argp;
2796 ret = copy_from_user (&r6.rtmsg_dst, &(ur6->rtmsg_dst), 2804 ret = copy_from_user(&r6.rtmsg_dst, &(ur6->rtmsg_dst),
2797 3 * sizeof(struct in6_addr)); 2805 3 * sizeof(struct in6_addr));
2798 ret |= __get_user (r6.rtmsg_type, &(ur6->rtmsg_type)); 2806 ret |= __get_user(r6.rtmsg_type, &(ur6->rtmsg_type));
2799 ret |= __get_user (r6.rtmsg_dst_len, &(ur6->rtmsg_dst_len)); 2807 ret |= __get_user(r6.rtmsg_dst_len, &(ur6->rtmsg_dst_len));
2800 ret |= __get_user (r6.rtmsg_src_len, &(ur6->rtmsg_src_len)); 2808 ret |= __get_user(r6.rtmsg_src_len, &(ur6->rtmsg_src_len));
2801 ret |= __get_user (r6.rtmsg_metric, &(ur6->rtmsg_metric)); 2809 ret |= __get_user(r6.rtmsg_metric, &(ur6->rtmsg_metric));
2802 ret |= __get_user (r6.rtmsg_info, &(ur6->rtmsg_info)); 2810 ret |= __get_user(r6.rtmsg_info, &(ur6->rtmsg_info));
2803 ret |= __get_user (r6.rtmsg_flags, &(ur6->rtmsg_flags)); 2811 ret |= __get_user(r6.rtmsg_flags, &(ur6->rtmsg_flags));
2804 ret |= __get_user (r6.rtmsg_ifindex, &(ur6->rtmsg_ifindex)); 2812 ret |= __get_user(r6.rtmsg_ifindex, &(ur6->rtmsg_ifindex));
2805 2813
2806 r = (void *) &r6; 2814 r = (void *) &r6;
2807 } else { /* ipv4 */ 2815 } else { /* ipv4 */
2808 struct rtentry32 __user *ur4 = argp; 2816 struct rtentry32 __user *ur4 = argp;
2809 ret = copy_from_user (&r4.rt_dst, &(ur4->rt_dst), 2817 ret = copy_from_user(&r4.rt_dst, &(ur4->rt_dst),
2810 3 * sizeof(struct sockaddr)); 2818 3 * sizeof(struct sockaddr));
2811 ret |= __get_user (r4.rt_flags, &(ur4->rt_flags)); 2819 ret |= __get_user(r4.rt_flags, &(ur4->rt_flags));
2812 ret |= __get_user (r4.rt_metric, &(ur4->rt_metric)); 2820 ret |= __get_user(r4.rt_metric, &(ur4->rt_metric));
2813 ret |= __get_user (r4.rt_mtu, &(ur4->rt_mtu)); 2821 ret |= __get_user(r4.rt_mtu, &(ur4->rt_mtu));
2814 ret |= __get_user (r4.rt_window, &(ur4->rt_window)); 2822 ret |= __get_user(r4.rt_window, &(ur4->rt_window));
2815 ret |= __get_user (r4.rt_irtt, &(ur4->rt_irtt)); 2823 ret |= __get_user(r4.rt_irtt, &(ur4->rt_irtt));
2816 ret |= __get_user (rtdev, &(ur4->rt_dev)); 2824 ret |= __get_user(rtdev, &(ur4->rt_dev));
2817 if (rtdev) { 2825 if (rtdev) {
2818 ret |= copy_from_user (devname, compat_ptr(rtdev), 15); 2826 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
2819 r4.rt_dev = devname; devname[15] = 0; 2827 r4.rt_dev = devname; devname[15] = 0;
2820 } else 2828 } else
2821 r4.rt_dev = NULL; 2829 r4.rt_dev = NULL;
@@ -2828,9 +2836,9 @@ static int routing_ioctl(struct net *net, struct socket *sock,
2828 goto out; 2836 goto out;
2829 } 2837 }
2830 2838
2831 set_fs (KERNEL_DS); 2839 set_fs(KERNEL_DS);
2832 ret = sock_do_ioctl(net, sock, cmd, (unsigned long) r); 2840 ret = sock_do_ioctl(net, sock, cmd, (unsigned long) r);
2833 set_fs (old_fs); 2841 set_fs(old_fs);
2834 2842
2835out: 2843out:
2836 return ret; 2844 return ret;
@@ -2993,11 +3001,13 @@ int kernel_bind(struct socket *sock, struct sockaddr *addr, int addrlen)
2993{ 3001{
2994 return sock->ops->bind(sock, addr, addrlen); 3002 return sock->ops->bind(sock, addr, addrlen);
2995} 3003}
3004EXPORT_SYMBOL(kernel_bind);
2996 3005
2997int kernel_listen(struct socket *sock, int backlog) 3006int kernel_listen(struct socket *sock, int backlog)
2998{ 3007{
2999 return sock->ops->listen(sock, backlog); 3008 return sock->ops->listen(sock, backlog);
3000} 3009}
3010EXPORT_SYMBOL(kernel_listen);
3001 3011
3002int kernel_accept(struct socket *sock, struct socket **newsock, int flags) 3012int kernel_accept(struct socket *sock, struct socket **newsock, int flags)
3003{ 3013{
@@ -3022,24 +3032,28 @@ int kernel_accept(struct socket *sock, struct socket **newsock, int flags)
3022done: 3032done:
3023 return err; 3033 return err;
3024} 3034}
3035EXPORT_SYMBOL(kernel_accept);
3025 3036
3026int kernel_connect(struct socket *sock, struct sockaddr *addr, int addrlen, 3037int kernel_connect(struct socket *sock, struct sockaddr *addr, int addrlen,
3027 int flags) 3038 int flags)
3028{ 3039{
3029 return sock->ops->connect(sock, addr, addrlen, flags); 3040 return sock->ops->connect(sock, addr, addrlen, flags);
3030} 3041}
3042EXPORT_SYMBOL(kernel_connect);
3031 3043
3032int kernel_getsockname(struct socket *sock, struct sockaddr *addr, 3044int kernel_getsockname(struct socket *sock, struct sockaddr *addr,
3033 int *addrlen) 3045 int *addrlen)
3034{ 3046{
3035 return sock->ops->getname(sock, addr, addrlen, 0); 3047 return sock->ops->getname(sock, addr, addrlen, 0);
3036} 3048}
3049EXPORT_SYMBOL(kernel_getsockname);
3037 3050
3038int kernel_getpeername(struct socket *sock, struct sockaddr *addr, 3051int kernel_getpeername(struct socket *sock, struct sockaddr *addr,
3039 int *addrlen) 3052 int *addrlen)
3040{ 3053{
3041 return sock->ops->getname(sock, addr, addrlen, 1); 3054 return sock->ops->getname(sock, addr, addrlen, 1);
3042} 3055}
3056EXPORT_SYMBOL(kernel_getpeername);
3043 3057
3044int kernel_getsockopt(struct socket *sock, int level, int optname, 3058int kernel_getsockopt(struct socket *sock, int level, int optname,
3045 char *optval, int *optlen) 3059 char *optval, int *optlen)
@@ -3056,6 +3070,7 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
3056 set_fs(oldfs); 3070 set_fs(oldfs);
3057 return err; 3071 return err;
3058} 3072}
3073EXPORT_SYMBOL(kernel_getsockopt);
3059 3074
3060int kernel_setsockopt(struct socket *sock, int level, int optname, 3075int kernel_setsockopt(struct socket *sock, int level, int optname,
3061 char *optval, unsigned int optlen) 3076 char *optval, unsigned int optlen)
@@ -3072,6 +3087,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
3072 set_fs(oldfs); 3087 set_fs(oldfs);
3073 return err; 3088 return err;
3074} 3089}
3090EXPORT_SYMBOL(kernel_setsockopt);
3075 3091
3076int kernel_sendpage(struct socket *sock, struct page *page, int offset, 3092int kernel_sendpage(struct socket *sock, struct page *page, int offset,
3077 size_t size, int flags) 3093 size_t size, int flags)
@@ -3083,6 +3099,7 @@ int kernel_sendpage(struct socket *sock, struct page *page, int offset,
3083 3099
3084 return sock_no_sendpage(sock, page, offset, size, flags); 3100 return sock_no_sendpage(sock, page, offset, size, flags);
3085} 3101}
3102EXPORT_SYMBOL(kernel_sendpage);
3086 3103
3087int kernel_sock_ioctl(struct socket *sock, int cmd, unsigned long arg) 3104int kernel_sock_ioctl(struct socket *sock, int cmd, unsigned long arg)
3088{ 3105{
@@ -3095,33 +3112,10 @@ int kernel_sock_ioctl(struct socket *sock, int cmd, unsigned long arg)
3095 3112
3096 return err; 3113 return err;
3097} 3114}
3115EXPORT_SYMBOL(kernel_sock_ioctl);
3098 3116
3099int kernel_sock_shutdown(struct socket *sock, enum sock_shutdown_cmd how) 3117int kernel_sock_shutdown(struct socket *sock, enum sock_shutdown_cmd how)
3100{ 3118{
3101 return sock->ops->shutdown(sock, how); 3119 return sock->ops->shutdown(sock, how);
3102} 3120}
3103
3104EXPORT_SYMBOL(sock_create);
3105EXPORT_SYMBOL(sock_create_kern);
3106EXPORT_SYMBOL(sock_create_lite);
3107EXPORT_SYMBOL(sock_map_fd);
3108EXPORT_SYMBOL(sock_recvmsg);
3109EXPORT_SYMBOL(sock_register);
3110EXPORT_SYMBOL(sock_release);
3111EXPORT_SYMBOL(sock_sendmsg);
3112EXPORT_SYMBOL(sock_unregister);
3113EXPORT_SYMBOL(sock_wake_async);
3114EXPORT_SYMBOL(sockfd_lookup);
3115EXPORT_SYMBOL(kernel_sendmsg);
3116EXPORT_SYMBOL(kernel_recvmsg);
3117EXPORT_SYMBOL(kernel_bind);
3118EXPORT_SYMBOL(kernel_listen);
3119EXPORT_SYMBOL(kernel_accept);
3120EXPORT_SYMBOL(kernel_connect);
3121EXPORT_SYMBOL(kernel_getsockname);
3122EXPORT_SYMBOL(kernel_getpeername);
3123EXPORT_SYMBOL(kernel_getsockopt);
3124EXPORT_SYMBOL(kernel_setsockopt);
3125EXPORT_SYMBOL(kernel_sendpage);
3126EXPORT_SYMBOL(kernel_sock_ioctl);
3127EXPORT_SYMBOL(kernel_sock_shutdown); 3121EXPORT_SYMBOL(kernel_sock_shutdown);