Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: factor out __inet_listen_sk() helper

The mptcp protocol maintains an additional socket just to easily
invoke a few stream operations on the first subflow. One of them
is inet_listen().

Factor out an helper operating directly on the (locked) struct sock,
to allow get rid of the above dependency in the next patch without
duplicating the existing code.

No functional changes intended.

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Acked-by: Mat Martineau <martineau@kernel.org>
Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Paolo Abeni and committed by
David S. Miller
71a9a874 8cf2ebdc

+23 -16
+1
include/net/inet_common.h
··· 40 40 int flags); 41 41 int inet_shutdown(struct socket *sock, int how); 42 42 int inet_listen(struct socket *sock, int backlog); 43 + int __inet_listen_sk(struct sock *sk, int backlog); 43 44 void inet_sock_destruct(struct sock *sk); 44 45 int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len); 45 46 int inet_bind_sk(struct sock *sk, struct sockaddr *uaddr, int addr_len);
+22 -16
net/ipv4/af_inet.c
··· 187 187 return 0; 188 188 } 189 189 190 - /* 191 - * Move a socket into listening state. 192 - */ 193 - int inet_listen(struct socket *sock, int backlog) 190 + int __inet_listen_sk(struct sock *sk, int backlog) 194 191 { 195 - struct sock *sk = sock->sk; 196 - unsigned char old_state; 192 + unsigned char old_state = sk->sk_state; 197 193 int err, tcp_fastopen; 198 194 199 - lock_sock(sk); 200 - 201 - err = -EINVAL; 202 - if (sock->state != SS_UNCONNECTED || sock->type != SOCK_STREAM) 203 - goto out; 204 - 205 - old_state = sk->sk_state; 206 195 if (!((1 << old_state) & (TCPF_CLOSE | TCPF_LISTEN))) 207 - goto out; 196 + return -EINVAL; 208 197 209 198 WRITE_ONCE(sk->sk_max_ack_backlog, backlog); 210 199 /* Really, if the socket is already in listen state ··· 216 227 217 228 err = inet_csk_listen_start(sk); 218 229 if (err) 219 - goto out; 230 + return err; 231 + 220 232 tcp_call_bpf(sk, BPF_SOCK_OPS_TCP_LISTEN_CB, 0, NULL); 221 233 } 222 - err = 0; 234 + return 0; 235 + } 236 + 237 + /* 238 + * Move a socket into listening state. 239 + */ 240 + int inet_listen(struct socket *sock, int backlog) 241 + { 242 + struct sock *sk = sock->sk; 243 + int err = -EINVAL; 244 + 245 + lock_sock(sk); 246 + 247 + if (sock->state != SS_UNCONNECTED || sock->type != SOCK_STREAM) 248 + goto out; 249 + 250 + err = __inet_listen_sk(sk, backlog); 223 251 224 252 out: 225 253 release_sock(sk);