Commit a9e29e55 authored by Arseny Krasnov's avatar Arseny Krasnov Committed by David S. Miller

af_vsock: update functions for connectible socket

Prepare af_vsock.c for SEQPACKET support: rename some functions such
as setsockopt(), getsockopt(), connect(), recvmsg(), sendmsg() in general
manner, because they are shared with stream sockets.
Signed-off-by: default avatarArseny Krasnov <arseny.krasnov@kaspersky.com>
Reviewed-by: default avatarStefano Garzarella <sgarzare@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 57806b28
...@@ -604,7 +604,7 @@ static void vsock_pending_work(struct work_struct *work) ...@@ -604,7 +604,7 @@ static void vsock_pending_work(struct work_struct *work)
/**** SOCKET OPERATIONS ****/ /**** SOCKET OPERATIONS ****/
static int __vsock_bind_stream(struct vsock_sock *vsk, static int __vsock_bind_connectible(struct vsock_sock *vsk,
struct sockaddr_vm *addr) struct sockaddr_vm *addr)
{ {
static u32 port; static u32 port;
...@@ -685,7 +685,7 @@ static int __vsock_bind(struct sock *sk, struct sockaddr_vm *addr) ...@@ -685,7 +685,7 @@ static int __vsock_bind(struct sock *sk, struct sockaddr_vm *addr)
switch (sk->sk_socket->type) { switch (sk->sk_socket->type) {
case SOCK_STREAM: case SOCK_STREAM:
spin_lock_bh(&vsock_table_lock); spin_lock_bh(&vsock_table_lock);
retval = __vsock_bind_stream(vsk, addr); retval = __vsock_bind_connectible(vsk, addr);
spin_unlock_bh(&vsock_table_lock); spin_unlock_bh(&vsock_table_lock);
break; break;
...@@ -768,6 +768,11 @@ static struct sock *__vsock_create(struct net *net, ...@@ -768,6 +768,11 @@ static struct sock *__vsock_create(struct net *net,
return sk; return sk;
} }
static bool sock_type_connectible(u16 type)
{
return type == SOCK_STREAM;
}
static void __vsock_release(struct sock *sk, int level) static void __vsock_release(struct sock *sk, int level)
{ {
if (sk) { if (sk) {
...@@ -786,7 +791,7 @@ static void __vsock_release(struct sock *sk, int level) ...@@ -786,7 +791,7 @@ static void __vsock_release(struct sock *sk, int level)
if (vsk->transport) if (vsk->transport)
vsk->transport->release(vsk); vsk->transport->release(vsk);
else if (sk->sk_type == SOCK_STREAM) else if (sock_type_connectible(sk->sk_type))
vsock_remove_sock(vsk); vsock_remove_sock(vsk);
sock_orphan(sk); sock_orphan(sk);
...@@ -948,7 +953,7 @@ static int vsock_shutdown(struct socket *sock, int mode) ...@@ -948,7 +953,7 @@ static int vsock_shutdown(struct socket *sock, int mode)
lock_sock(sk); lock_sock(sk);
if (sock->state == SS_UNCONNECTED) { if (sock->state == SS_UNCONNECTED) {
err = -ENOTCONN; err = -ENOTCONN;
if (sk->sk_type == SOCK_STREAM) if (sock_type_connectible(sk->sk_type))
goto out; goto out;
} else { } else {
sock->state = SS_DISCONNECTING; sock->state = SS_DISCONNECTING;
...@@ -961,7 +966,7 @@ static int vsock_shutdown(struct socket *sock, int mode) ...@@ -961,7 +966,7 @@ static int vsock_shutdown(struct socket *sock, int mode)
sk->sk_shutdown |= mode; sk->sk_shutdown |= mode;
sk->sk_state_change(sk); sk->sk_state_change(sk);
if (sk->sk_type == SOCK_STREAM) { if (sock_type_connectible(sk->sk_type)) {
sock_reset_flag(sk, SOCK_DONE); sock_reset_flag(sk, SOCK_DONE);
vsock_send_shutdown(sk, mode); vsock_send_shutdown(sk, mode);
} }
...@@ -1016,7 +1021,7 @@ static __poll_t vsock_poll(struct file *file, struct socket *sock, ...@@ -1016,7 +1021,7 @@ static __poll_t vsock_poll(struct file *file, struct socket *sock,
if (!(sk->sk_shutdown & SEND_SHUTDOWN)) if (!(sk->sk_shutdown & SEND_SHUTDOWN))
mask |= EPOLLOUT | EPOLLWRNORM | EPOLLWRBAND; mask |= EPOLLOUT | EPOLLWRNORM | EPOLLWRBAND;
} else if (sock->type == SOCK_STREAM) { } else if (sock_type_connectible(sk->sk_type)) {
const struct vsock_transport *transport; const struct vsock_transport *transport;
lock_sock(sk); lock_sock(sk);
...@@ -1263,7 +1268,7 @@ static void vsock_connect_timeout(struct work_struct *work) ...@@ -1263,7 +1268,7 @@ static void vsock_connect_timeout(struct work_struct *work)
sock_put(sk); sock_put(sk);
} }
static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr, static int vsock_connect(struct socket *sock, struct sockaddr *addr,
int addr_len, int flags) int addr_len, int flags)
{ {
int err; int err;
...@@ -1414,7 +1419,7 @@ static int vsock_accept(struct socket *sock, struct socket *newsock, int flags, ...@@ -1414,7 +1419,7 @@ static int vsock_accept(struct socket *sock, struct socket *newsock, int flags,
lock_sock(listener); lock_sock(listener);
if (sock->type != SOCK_STREAM) { if (!sock_type_connectible(sock->type)) {
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
goto out; goto out;
} }
...@@ -1491,7 +1496,7 @@ static int vsock_listen(struct socket *sock, int backlog) ...@@ -1491,7 +1496,7 @@ static int vsock_listen(struct socket *sock, int backlog)
lock_sock(sk); lock_sock(sk);
if (sock->type != SOCK_STREAM) { if (!sock_type_connectible(sk->sk_type)) {
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
goto out; goto out;
} }
...@@ -1535,7 +1540,7 @@ static void vsock_update_buffer_size(struct vsock_sock *vsk, ...@@ -1535,7 +1540,7 @@ static void vsock_update_buffer_size(struct vsock_sock *vsk,
vsk->buffer_size = val; vsk->buffer_size = val;
} }
static int vsock_stream_setsockopt(struct socket *sock, static int vsock_connectible_setsockopt(struct socket *sock,
int level, int level,
int optname, int optname,
sockptr_t optval, sockptr_t optval,
...@@ -1617,7 +1622,7 @@ static int vsock_stream_setsockopt(struct socket *sock, ...@@ -1617,7 +1622,7 @@ static int vsock_stream_setsockopt(struct socket *sock,
return err; return err;
} }
static int vsock_stream_getsockopt(struct socket *sock, static int vsock_connectible_getsockopt(struct socket *sock,
int level, int optname, int level, int optname,
char __user *optval, char __user *optval,
int __user *optlen) int __user *optlen)
...@@ -1688,7 +1693,7 @@ static int vsock_stream_getsockopt(struct socket *sock, ...@@ -1688,7 +1693,7 @@ static int vsock_stream_getsockopt(struct socket *sock,
return 0; return 0;
} }
static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg, static int vsock_connectible_sendmsg(struct socket *sock, struct msghdr *msg,
size_t len) size_t len)
{ {
struct sock *sk; struct sock *sk;
...@@ -1828,9 +1833,8 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg, ...@@ -1828,9 +1833,8 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg,
return err; return err;
} }
static int static int
vsock_stream_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
int flags) int flags)
{ {
struct sock *sk; struct sock *sk;
...@@ -2007,7 +2011,7 @@ static const struct proto_ops vsock_stream_ops = { ...@@ -2007,7 +2011,7 @@ static const struct proto_ops vsock_stream_ops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.release = vsock_release, .release = vsock_release,
.bind = vsock_bind, .bind = vsock_bind,
.connect = vsock_stream_connect, .connect = vsock_connect,
.socketpair = sock_no_socketpair, .socketpair = sock_no_socketpair,
.accept = vsock_accept, .accept = vsock_accept,
.getname = vsock_getname, .getname = vsock_getname,
...@@ -2015,10 +2019,10 @@ static const struct proto_ops vsock_stream_ops = { ...@@ -2015,10 +2019,10 @@ static const struct proto_ops vsock_stream_ops = {
.ioctl = sock_no_ioctl, .ioctl = sock_no_ioctl,
.listen = vsock_listen, .listen = vsock_listen,
.shutdown = vsock_shutdown, .shutdown = vsock_shutdown,
.setsockopt = vsock_stream_setsockopt, .setsockopt = vsock_connectible_setsockopt,
.getsockopt = vsock_stream_getsockopt, .getsockopt = vsock_connectible_getsockopt,
.sendmsg = vsock_stream_sendmsg, .sendmsg = vsock_connectible_sendmsg,
.recvmsg = vsock_stream_recvmsg, .recvmsg = vsock_connectible_recvmsg,
.mmap = sock_no_mmap, .mmap = sock_no_mmap,
.sendpage = sock_no_sendpage, .sendpage = sock_no_sendpage,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment