Skip to content

Commit

Permalink
net: change proto and proto_ops accept type
Browse files Browse the repository at this point in the history
Rather than pass in flags, error pointer, and whether this is a kernel
invocation or not, add a struct proto_accept_arg struct as the argument.
This then holds all of these arguments, and prepares accept for being
able to pass back more information.

No functional changes in this patch.

Acked-by: Jakub Kicinski <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
axboe committed May 14, 2024
1 parent fe6532b commit 92ef0fd
Show file tree
Hide file tree
Showing 34 changed files with 132 additions and 111 deletions.
11 changes: 6 additions & 5 deletions crypto/af_alg.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ static int alg_setsockopt(struct socket *sock, int level, int optname,
return err;
}

int af_alg_accept(struct sock *sk, struct socket *newsock, bool kern)
int af_alg_accept(struct sock *sk, struct socket *newsock,
struct proto_accept_arg *arg)
{
struct alg_sock *ask = alg_sk(sk);
const struct af_alg_type *type;
Expand All @@ -422,7 +423,7 @@ int af_alg_accept(struct sock *sk, struct socket *newsock, bool kern)
if (!type)
goto unlock;

sk2 = sk_alloc(sock_net(sk), PF_ALG, GFP_KERNEL, &alg_proto, kern);
sk2 = sk_alloc(sock_net(sk), PF_ALG, GFP_KERNEL, &alg_proto, arg->kern);
err = -ENOMEM;
if (!sk2)
goto unlock;
Expand Down Expand Up @@ -468,10 +469,10 @@ int af_alg_accept(struct sock *sk, struct socket *newsock, bool kern)
}
EXPORT_SYMBOL_GPL(af_alg_accept);

static int alg_accept(struct socket *sock, struct socket *newsock, int flags,
bool kern)
static int alg_accept(struct socket *sock, struct socket *newsock,
struct proto_accept_arg *arg)
{
return af_alg_accept(sock->sk, newsock, kern);
return af_alg_accept(sock->sk, newsock, arg);
}

static const struct proto_ops alg_proto_ops = {
Expand Down
10 changes: 5 additions & 5 deletions crypto/algif_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ static int hash_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
return err ?: len;
}

static int hash_accept(struct socket *sock, struct socket *newsock, int flags,
bool kern)
static int hash_accept(struct socket *sock, struct socket *newsock,
struct proto_accept_arg *arg)
{
struct sock *sk = sock->sk;
struct alg_sock *ask = alg_sk(sk);
Expand Down Expand Up @@ -252,7 +252,7 @@ static int hash_accept(struct socket *sock, struct socket *newsock, int flags,
if (err)
goto out_free_state;

err = af_alg_accept(ask->parent, newsock, kern);
err = af_alg_accept(ask->parent, newsock, arg);
if (err)
goto out_free_state;

Expand Down Expand Up @@ -355,15 +355,15 @@ static int hash_recvmsg_nokey(struct socket *sock, struct msghdr *msg,
}

static int hash_accept_nokey(struct socket *sock, struct socket *newsock,
int flags, bool kern)
struct proto_accept_arg *arg)
{
int err;

err = hash_check_key(sock);
if (err)
return err;

return hash_accept(sock, newsock, flags, kern);
return hash_accept(sock, newsock, arg);
}

static struct proto_ops algif_hash_ops_nokey = {
Expand Down
6 changes: 5 additions & 1 deletion drivers/xen/pvcalls-back.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,10 @@ static void __pvcalls_back_accept(struct work_struct *work)
{
struct sockpass_mapping *mappass = container_of(
work, struct sockpass_mapping, register_work);
struct proto_accept_arg arg = {
.flags = O_NONBLOCK,
.kern = true,
};
struct sock_mapping *map;
struct pvcalls_ioworker *iow;
struct pvcalls_fedata *fedata;
Expand Down Expand Up @@ -548,7 +552,7 @@ static void __pvcalls_back_accept(struct work_struct *work)
sock->type = mappass->sock->type;
sock->ops = mappass->sock->ops;

ret = inet_accept(mappass->sock, sock, O_NONBLOCK, true);
ret = inet_accept(mappass->sock, sock, &arg);
if (ret == -EAGAIN) {
sock_release(sock);
return;
Expand Down
5 changes: 4 additions & 1 deletion fs/ocfs2/cluster/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1784,6 +1784,9 @@ static int o2net_accept_one(struct socket *sock, int *more)
struct o2nm_node *node = NULL;
struct o2nm_node *local_node = NULL;
struct o2net_sock_container *sc = NULL;
struct proto_accept_arg arg = {
.flags = O_NONBLOCK,
};
struct o2net_node *nn;
unsigned int nofs_flag;

Expand All @@ -1802,7 +1805,7 @@ static int o2net_accept_one(struct socket *sock, int *more)

new_sock->type = sock->type;
new_sock->ops = sock->ops;
ret = sock->ops->accept(sock, new_sock, O_NONBLOCK, false);
ret = sock->ops->accept(sock, new_sock, &arg);
if (ret < 0)
goto out;

Expand Down
3 changes: 2 additions & 1 deletion include/crypto/if_alg.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ int af_alg_unregister_type(const struct af_alg_type *type);

int af_alg_release(struct socket *sock);
void af_alg_release_parent(struct sock *sk);
int af_alg_accept(struct sock *sk, struct socket *newsock, bool kern);
int af_alg_accept(struct sock *sk, struct socket *newsock,
struct proto_accept_arg *arg);

void af_alg_free_sg(struct af_alg_sgl *sgl);

Expand Down
4 changes: 3 additions & 1 deletion include/linux/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ struct sockaddr;
struct msghdr;
struct module;
struct sk_buff;
struct proto_accept_arg;
typedef int (*sk_read_actor_t)(read_descriptor_t *, struct sk_buff *,
unsigned int, size_t);
typedef int (*skb_read_actor_t)(struct sock *, struct sk_buff *);
Expand All @@ -171,7 +172,8 @@ struct proto_ops {
int (*socketpair)(struct socket *sock1,
struct socket *sock2);
int (*accept) (struct socket *sock,
struct socket *newsock, int flags, bool kern);
struct socket *newsock,
struct proto_accept_arg *arg);
int (*getname) (struct socket *sock,
struct sockaddr *addr,
int peer);
Expand Down
4 changes: 2 additions & 2 deletions include/net/inet_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ int __inet_stream_connect(struct socket *sock, struct sockaddr *uaddr,
int addr_len, int flags, int is_sendmsg);
int inet_dgram_connect(struct socket *sock, struct sockaddr *uaddr,
int addr_len, int flags);
int inet_accept(struct socket *sock, struct socket *newsock, int flags,
bool kern);
int inet_accept(struct socket *sock, struct socket *newsock,
struct proto_accept_arg *arg);
void __inet_accept(struct socket *sock, struct socket *newsock,
struct sock *newsk);
int inet_send_prepare(struct sock *sk);
Expand Down
2 changes: 1 addition & 1 deletion include/net/inet_connection_sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ inet_csk_rto_backoff(const struct inet_connection_sock *icsk,
return (unsigned long)min_t(u64, when, max_when);
}

struct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern);
struct sock *inet_csk_accept(struct sock *sk, struct proto_accept_arg *arg);

int inet_csk_get_port(struct sock *sk, unsigned short snum);

Expand Down
12 changes: 9 additions & 3 deletions include/net/sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,12 @@ static inline void sk_prot_clear_nulls(struct sock *sk, int size)
size - offsetof(struct sock, sk_node.pprev));
}

struct proto_accept_arg {
int flags;
int err;
bool kern;
};

/* Networking protocol blocks we attach to sockets.
* socket layer -> transport layer interface
*/
Expand All @@ -1208,8 +1214,8 @@ struct proto {
int addr_len);
int (*disconnect)(struct sock *sk, int flags);

struct sock * (*accept)(struct sock *sk, int flags, int *err,
bool kern);
struct sock * (*accept)(struct sock *sk,
struct proto_accept_arg *arg);

int (*ioctl)(struct sock *sk, int cmd,
int *karg);
Expand Down Expand Up @@ -1804,7 +1810,7 @@ int sock_cmsg_send(struct sock *sk, struct msghdr *msg,
int sock_no_bind(struct socket *, struct sockaddr *, int);
int sock_no_connect(struct socket *, struct sockaddr *, int, int);
int sock_no_socketpair(struct socket *, struct socket *);
int sock_no_accept(struct socket *, struct socket *, int, bool);
int sock_no_accept(struct socket *, struct socket *, struct proto_accept_arg *);
int sock_no_getname(struct socket *, struct sockaddr *, int);
int sock_no_ioctl(struct socket *, unsigned int, unsigned long);
int sock_no_listen(struct socket *, int);
Expand Down
8 changes: 4 additions & 4 deletions net/atm/svc.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ static int svc_listen(struct socket *sock, int backlog)
return error;
}

static int svc_accept(struct socket *sock, struct socket *newsock, int flags,
bool kern)
static int svc_accept(struct socket *sock, struct socket *newsock,
struct proto_accept_arg *arg)
{
struct sock *sk = sock->sk;
struct sk_buff *skb;
Expand All @@ -336,7 +336,7 @@ static int svc_accept(struct socket *sock, struct socket *newsock, int flags,

lock_sock(sk);

error = svc_create(sock_net(sk), newsock, 0, kern);
error = svc_create(sock_net(sk), newsock, 0, arg->kern);
if (error)
goto out;

Expand All @@ -355,7 +355,7 @@ static int svc_accept(struct socket *sock, struct socket *newsock, int flags,
error = -sk->sk_err;
break;
}
if (flags & O_NONBLOCK) {
if (arg->flags & O_NONBLOCK) {
error = -EAGAIN;
break;
}
Expand Down
6 changes: 3 additions & 3 deletions net/ax25/af_ax25.c
Original file line number Diff line number Diff line change
Expand Up @@ -1373,8 +1373,8 @@ static int __must_check ax25_connect(struct socket *sock,
return err;
}

static int ax25_accept(struct socket *sock, struct socket *newsock, int flags,
bool kern)
static int ax25_accept(struct socket *sock, struct socket *newsock,
struct proto_accept_arg *arg)
{
struct sk_buff *skb;
struct sock *newsk;
Expand Down Expand Up @@ -1409,7 +1409,7 @@ static int ax25_accept(struct socket *sock, struct socket *newsock, int flags,
if (skb)
break;

if (flags & O_NONBLOCK) {
if (arg->flags & O_NONBLOCK) {
err = -EWOULDBLOCK;
break;
}
Expand Down
4 changes: 2 additions & 2 deletions net/bluetooth/iso.c
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ static int iso_sock_listen(struct socket *sock, int backlog)
}

static int iso_sock_accept(struct socket *sock, struct socket *newsock,
int flags, bool kern)
struct proto_accept_arg *arg)
{
DEFINE_WAIT_FUNC(wait, woken_wake_function);
struct sock *sk = sock->sk, *ch;
Expand All @@ -1195,7 +1195,7 @@ static int iso_sock_accept(struct socket *sock, struct socket *newsock,

lock_sock(sk);

timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
timeo = sock_rcvtimeo(sk, arg->flags & O_NONBLOCK);

BT_DBG("sk %p timeo %ld", sk, timeo);

Expand Down
4 changes: 2 additions & 2 deletions net/bluetooth/l2cap_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ static int l2cap_sock_listen(struct socket *sock, int backlog)
}

static int l2cap_sock_accept(struct socket *sock, struct socket *newsock,
int flags, bool kern)
struct proto_accept_arg *arg)
{
DEFINE_WAIT_FUNC(wait, woken_wake_function);
struct sock *sk = sock->sk, *nsk;
Expand All @@ -336,7 +336,7 @@ static int l2cap_sock_accept(struct socket *sock, struct socket *newsock,

lock_sock_nested(sk, L2CAP_NESTING_PARENT);

timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
timeo = sock_rcvtimeo(sk, arg->flags & O_NONBLOCK);

BT_DBG("sk %p timeo %ld", sk, timeo);

Expand Down
6 changes: 3 additions & 3 deletions net/bluetooth/rfcomm/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ static int rfcomm_sock_listen(struct socket *sock, int backlog)
return err;
}

static int rfcomm_sock_accept(struct socket *sock, struct socket *newsock, int flags,
bool kern)
static int rfcomm_sock_accept(struct socket *sock, struct socket *newsock,
struct proto_accept_arg *arg)
{
DEFINE_WAIT_FUNC(wait, woken_wake_function);
struct sock *sk = sock->sk, *nsk;
Expand All @@ -483,7 +483,7 @@ static int rfcomm_sock_accept(struct socket *sock, struct socket *newsock, int f
goto done;
}

timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
timeo = sock_rcvtimeo(sk, arg->flags & O_NONBLOCK);

BT_DBG("sk %p timeo %ld", sk, timeo);

Expand Down
4 changes: 2 additions & 2 deletions net/bluetooth/sco.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ static int sco_sock_listen(struct socket *sock, int backlog)
}

static int sco_sock_accept(struct socket *sock, struct socket *newsock,
int flags, bool kern)
struct proto_accept_arg *arg)
{
DEFINE_WAIT_FUNC(wait, woken_wake_function);
struct sock *sk = sock->sk, *ch;
Expand All @@ -656,7 +656,7 @@ static int sco_sock_accept(struct socket *sock, struct socket *newsock,

lock_sock(sk);

timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
timeo = sock_rcvtimeo(sk, arg->flags & O_NONBLOCK);

BT_DBG("sk %p timeo %ld", sk, timeo);

Expand Down
4 changes: 2 additions & 2 deletions net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -3241,8 +3241,8 @@ int sock_no_socketpair(struct socket *sock1, struct socket *sock2)
}
EXPORT_SYMBOL(sock_no_socketpair);

int sock_no_accept(struct socket *sock, struct socket *newsock, int flags,
bool kern)
int sock_no_accept(struct socket *sock, struct socket *newsock,
struct proto_accept_arg *arg)
{
return -EOPNOTSUPP;
}
Expand Down
10 changes: 5 additions & 5 deletions net/ipv4/af_inet.c
Original file line number Diff line number Diff line change
Expand Up @@ -771,16 +771,16 @@ void __inet_accept(struct socket *sock, struct socket *newsock, struct sock *new
* Accept a pending connection. The TCP layer now gives BSD semantics.
*/

int inet_accept(struct socket *sock, struct socket *newsock, int flags,
bool kern)
int inet_accept(struct socket *sock, struct socket *newsock,
struct proto_accept_arg *arg)
{
struct sock *sk1 = sock->sk, *sk2;
int err = -EINVAL;

/* IPV6_ADDRFORM can change sk->sk_prot under us. */
sk2 = READ_ONCE(sk1->sk_prot)->accept(sk1, flags, &err, kern);
arg->err = -EINVAL;
sk2 = READ_ONCE(sk1->sk_prot)->accept(sk1, arg);
if (!sk2)
return err;
return arg->err;

lock_sock(sk2);
__inet_accept(sock, newsock, sk2);
Expand Down
6 changes: 3 additions & 3 deletions net/ipv4/inet_connection_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ static int inet_csk_wait_for_connect(struct sock *sk, long timeo)
/*
* This will accept the next outstanding connection.
*/
struct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern)
struct sock *inet_csk_accept(struct sock *sk, struct proto_accept_arg *arg)
{
struct inet_connection_sock *icsk = inet_csk(sk);
struct request_sock_queue *queue = &icsk->icsk_accept_queue;
Expand All @@ -680,7 +680,7 @@ struct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern)

/* Find already established connection */
if (reqsk_queue_empty(queue)) {
long timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
long timeo = sock_rcvtimeo(sk, arg->flags & O_NONBLOCK);

/* If this is a non blocking socket don't sleep */
error = -EAGAIN;
Expand Down Expand Up @@ -745,7 +745,7 @@ struct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern)
out_err:
newsk = NULL;
req = NULL;
*err = error;
arg->err = error;
goto out;
}
EXPORT_SYMBOL(inet_csk_accept);
Expand Down
4 changes: 2 additions & 2 deletions net/iucv/af_iucv.c
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ static int iucv_sock_listen(struct socket *sock, int backlog)

/* Accept a pending connection */
static int iucv_sock_accept(struct socket *sock, struct socket *newsock,
int flags, bool kern)
struct proto_accept_arg *arg)
{
DECLARE_WAITQUEUE(wait, current);
struct sock *sk = sock->sk, *nsk;
Expand All @@ -809,7 +809,7 @@ static int iucv_sock_accept(struct socket *sock, struct socket *newsock,
goto done;
}

timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
timeo = sock_rcvtimeo(sk, arg->flags & O_NONBLOCK);

/* Wait for an incoming connection */
add_wait_queue_exclusive(sk_sleep(sk), &wait);
Expand Down
Loading

0 comments on commit 92ef0fd

Please sign in to comment.