Skip to content

Commit

Permalink
inet: factor out inet_send_prepare()
Browse files Browse the repository at this point in the history
The same code is replicated verbatim in multiple places, and the next
patches will introduce an additional user for it. Factor out a
helper and use it where appropriate. No functional change intended.

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Paolo Abeni authored and David S. Miller committed Jul 3, 2019
1 parent 2559d7c commit e473093
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions include/net/inet_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ 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_send_prepare(struct sock *sk);
int inet_sendmsg(struct socket *sock, struct msghdr *msg, size_t size);
ssize_t inet_sendpage(struct socket *sock, struct page *page, int offset,
size_t size, int flags);
Expand Down
21 changes: 13 additions & 8 deletions net/ipv4/af_inet.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,17 +784,26 @@ int inet_getname(struct socket *sock, struct sockaddr *uaddr,
}
EXPORT_SYMBOL(inet_getname);

int inet_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
int inet_send_prepare(struct sock *sk)
{
struct sock *sk = sock->sk;

sock_rps_record_flow(sk);

/* We may need to bind the socket. */
if (!inet_sk(sk)->inet_num && !sk->sk_prot->no_autobind &&
inet_autobind(sk))
return -EAGAIN;

return 0;
}
EXPORT_SYMBOL_GPL(inet_send_prepare);

int inet_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
{
struct sock *sk = sock->sk;

if (unlikely(inet_send_prepare(sk)))
return -EAGAIN;

return sk->sk_prot->sendmsg(sk, msg, size);
}
EXPORT_SYMBOL(inet_sendmsg);
Expand All @@ -804,11 +813,7 @@ ssize_t inet_sendpage(struct socket *sock, struct page *page, int offset,
{
struct sock *sk = sock->sk;

sock_rps_record_flow(sk);

/* We may need to bind the socket. */
if (!inet_sk(sk)->inet_num && !sk->sk_prot->no_autobind &&
inet_autobind(sk))
if (unlikely(inet_send_prepare(sk)))
return -EAGAIN;

if (sk->sk_prot->sendpage)
Expand Down

0 comments on commit e473093

Please sign in to comment.