net: sock: introduce sk_error_report

This patch introduces a function wrapper to call the sk_error_report
callback. That will prepare to add additional handling whenever
sk_error_report is called, for example to trace socket errors.

Signed-off-by: Alexander Aring <aahringo@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Alexander Aring 2021-06-27 18:48:21 -04:00 committed by David S. Miller
parent 7f4e5c5b8c
commit e3ae2365ef
42 changed files with 75 additions and 67 deletions

View File

@ -2134,7 +2134,7 @@ static void chtls_abort_req_rss(struct sock *sk, struct sk_buff *skb)
sk->sk_err = ETIMEDOUT;
if (!sock_flag(sk, SOCK_DEAD))
sk->sk_error_report(sk);
sk_error_report(sk);
if (sk->sk_state == TCP_SYN_RECV && !abort_syn_rcv(sk, skb))
return;

View File

@ -734,7 +734,7 @@ static void vhost_vsock_reset_orphans(struct sock *sk)
vsk->peer_shutdown = SHUTDOWN_MASK;
sk->sk_state = SS_UNCONNECTED;
sk->sk_err = ECONNRESET;
sk->sk_error_report(sk);
sk_error_report(sk);
}
static int vhost_vsock_dev_release(struct inode *inode, struct file *file)

View File

@ -347,7 +347,7 @@ static inline void sk_psock_report_error(struct sk_psock *psock, int err)
struct sock *sk = psock->sk;
sk->sk_err = err;
sk->sk_error_report(sk);
sk_error_report(sk);
}
struct sk_psock *sk_psock_init(struct sock *sk, int node);

View File

@ -2281,6 +2281,8 @@ static inline int sock_error(struct sock *sk)
return -err;
}
void sk_error_report(struct sock *sk);
static inline unsigned long sock_wspace(struct sock *sk)
{
int amt = 0;

View File

@ -469,7 +469,7 @@ static inline bool tls_is_sk_tx_device_offloaded(struct sock *sk)
static inline void tls_err_abort(struct sock *sk, int err)
{
sk->sk_err = err;
sk->sk_error_report(sk);
sk_error_report(sk);
}
static inline bool tls_bigint_increment(unsigned char *seq, int len)

View File

@ -243,7 +243,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
cf_sk->sk.sk_err = ECONNRESET;
set_rx_flow_on(cf_sk);
cf_sk->sk.sk_error_report(&cf_sk->sk);
sk_error_report(&cf_sk->sk);
break;
default:

View File

@ -1417,7 +1417,7 @@ static void bcm_notify(struct bcm_sock *bo, unsigned long msg,
if (notify_enodev) {
sk->sk_err = ENODEV;
if (!sock_flag(sk, SOCK_DEAD))
sk->sk_error_report(sk);
sk_error_report(sk);
}
break;
@ -1425,7 +1425,7 @@ static void bcm_notify(struct bcm_sock *bo, unsigned long msg,
if (bo->bound && bo->ifindex == dev->ifindex) {
sk->sk_err = ENETDOWN;
if (!sock_flag(sk, SOCK_DEAD))
sk->sk_error_report(sk);
sk_error_report(sk);
}
}
}

View File

@ -168,7 +168,7 @@ static enum hrtimer_restart isotp_rx_timer_handler(struct hrtimer *hrtimer)
/* report 'connection timed out' */
sk->sk_err = ETIMEDOUT;
if (!sock_flag(sk, SOCK_DEAD))
sk->sk_error_report(sk);
sk_error_report(sk);
/* reset rx state */
so->rx.state = ISOTP_IDLE;
@ -339,7 +339,7 @@ static int isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae)
/* malformed PDU - report 'not a data message' */
sk->sk_err = EBADMSG;
if (!sock_flag(sk, SOCK_DEAD))
sk->sk_error_report(sk);
sk_error_report(sk);
so->tx.state = ISOTP_IDLE;
wake_up_interruptible(&so->wait);
@ -392,7 +392,7 @@ static int isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae)
/* overflow on receiver side - report 'message too long' */
sk->sk_err = EMSGSIZE;
if (!sock_flag(sk, SOCK_DEAD))
sk->sk_error_report(sk);
sk_error_report(sk);
fallthrough;
default:
@ -420,7 +420,7 @@ static int isotp_rcv_sf(struct sock *sk, struct canfd_frame *cf, int pcilen,
/* malformed PDU - report 'not a data message' */
sk->sk_err = EBADMSG;
if (!sock_flag(sk, SOCK_DEAD))
sk->sk_error_report(sk);
sk_error_report(sk);
return 1;
}
@ -535,7 +535,7 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
/* wrong sn detected - report 'illegal byte sequence' */
sk->sk_err = EILSEQ;
if (!sock_flag(sk, SOCK_DEAD))
sk->sk_error_report(sk);
sk_error_report(sk);
/* reset rx state */
so->rx.state = ISOTP_IDLE;
@ -559,7 +559,7 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
/* malformed PDU - report 'not a data message' */
sk->sk_err = EBADMSG;
if (!sock_flag(sk, SOCK_DEAD))
sk->sk_error_report(sk);
sk_error_report(sk);
return 1;
}
@ -758,7 +758,7 @@ static enum hrtimer_restart isotp_tx_timer_handler(struct hrtimer *hrtimer)
/* report 'communication error on send' */
sk->sk_err = ECOMM;
if (!sock_flag(sk, SOCK_DEAD))
sk->sk_error_report(sk);
sk_error_report(sk);
/* reset tx state */
so->tx.state = ISOTP_IDLE;
@ -1157,7 +1157,7 @@ static int isotp_bind(struct socket *sock, struct sockaddr *uaddr, int len)
if (notify_enetdown) {
sk->sk_err = ENETDOWN;
if (!sock_flag(sk, SOCK_DEAD))
sk->sk_error_report(sk);
sk_error_report(sk);
}
return err;
@ -1356,13 +1356,13 @@ static void isotp_notify(struct isotp_sock *so, unsigned long msg,
sk->sk_err = ENODEV;
if (!sock_flag(sk, SOCK_DEAD))
sk->sk_error_report(sk);
sk_error_report(sk);
break;
case NETDEV_DOWN:
sk->sk_err = ENETDOWN;
if (!sock_flag(sk, SOCK_DEAD))
sk->sk_error_report(sk);
sk_error_report(sk);
break;
}
}

View File

@ -1009,7 +1009,7 @@ void j1939_sk_send_loop_abort(struct sock *sk, int err)
{
sk->sk_err = err;
sk->sk_error_report(sk);
sk_error_report(sk);
}
static int j1939_sk_send_loop(struct j1939_priv *priv, struct sock *sk,
@ -1189,7 +1189,7 @@ void j1939_sk_netdev_event_netdown(struct j1939_priv *priv)
list_for_each_entry(jsk, &priv->j1939_socks, list) {
jsk->sk.sk_err = error_code;
if (!sock_flag(&jsk->sk, SOCK_DEAD))
jsk->sk.sk_error_report(&jsk->sk);
sk_error_report(&jsk->sk);
j1939_sk_queue_drop_all(priv, jsk, error_code);
}

View File

@ -295,13 +295,13 @@ static void raw_notify(struct raw_sock *ro, unsigned long msg,
sk->sk_err = ENODEV;
if (!sock_flag(sk, SOCK_DEAD))
sk->sk_error_report(sk);
sk_error_report(sk);
break;
case NETDEV_DOWN:
sk->sk_err = ENETDOWN;
if (!sock_flag(sk, SOCK_DEAD))
sk->sk_error_report(sk);
sk_error_report(sk);
break;
}
}
@ -488,7 +488,7 @@ static int raw_bind(struct socket *sock, struct sockaddr *uaddr, int len)
if (notify_enetdown) {
sk->sk_err = ENETDOWN;
if (!sock_flag(sk, SOCK_DEAD))
sk->sk_error_report(sk);
sk_error_report(sk);
}
return err;

View File

@ -1294,7 +1294,7 @@ static void __msg_zerocopy_callback(struct ubuf_info *uarg)
}
spin_unlock_irqrestore(&q->lock, flags);
sk->sk_error_report(sk);
sk_error_report(sk);
release:
consume_skb(skb);
@ -4685,7 +4685,7 @@ int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb)
skb_queue_tail(&sk->sk_error_queue, skb);
if (!sock_flag(sk, SOCK_DEAD))
sk->sk_error_report(sk);
sk_error_report(sk);
return 0;
}
EXPORT_SYMBOL(sock_queue_err_skb);
@ -4716,7 +4716,7 @@ struct sk_buff *sock_dequeue_err_skb(struct sock *sk)
sk->sk_err = 0;
if (skb_next)
sk->sk_error_report(sk);
sk_error_report(sk);
return skb;
}

View File

@ -331,6 +331,12 @@ int __sk_backlog_rcv(struct sock *sk, struct sk_buff *skb)
}
EXPORT_SYMBOL(__sk_backlog_rcv);
void sk_error_report(struct sock *sk)
{
sk->sk_error_report(sk);
}
EXPORT_SYMBOL(sk_error_report);
static int sock_get_timeout(long timeo, void *optval, bool old_timeval)
{
struct __kernel_sock_timeval tv;

View File

@ -329,7 +329,7 @@ static int dccp_v4_err(struct sk_buff *skb, u32 info)
__DCCP_INC_STATS(DCCP_MIB_ATTEMPTFAILS);
sk->sk_err = err;
sk->sk_error_report(sk);
sk_error_report(sk);
dccp_done(sk);
} else
@ -356,7 +356,7 @@ static int dccp_v4_err(struct sk_buff *skb, u32 info)
inet = inet_sk(sk);
if (!sock_owned_by_user(sk) && inet->recverr) {
sk->sk_err = err;
sk->sk_error_report(sk);
sk_error_report(sk);
} else /* Only an error on timeout */
sk->sk_err_soft = err;
out:

View File

@ -172,7 +172,7 @@ static int dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
* Wake people up to see the error
* (see connect in sock.c)
*/
sk->sk_error_report(sk);
sk_error_report(sk);
dccp_done(sk);
} else
sk->sk_err_soft = err;
@ -181,7 +181,7 @@ static int dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
if (!sock_owned_by_user(sk) && np->recverr) {
sk->sk_err = err;
sk->sk_error_report(sk);
sk_error_report(sk);
} else
sk->sk_err_soft = err;

View File

@ -302,7 +302,7 @@ int dccp_disconnect(struct sock *sk, int flags)
WARN_ON(inet->inet_num && !icsk->icsk_bind_hash);
sk->sk_error_report(sk);
sk_error_report(sk);
return 0;
}

View File

@ -20,7 +20,7 @@ int sysctl_dccp_retries2 __read_mostly = TCP_RETR2;
static void dccp_write_err(struct sock *sk)
{
sk->sk_err = sk->sk_err_soft ? : ETIMEDOUT;
sk->sk_error_report(sk);
sk_error_report(sk);
dccp_send_reset(sk, DCCP_RESET_CODE_ABORTED);
dccp_done(sk);

View File

@ -573,7 +573,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
}
}
sk->sk_err = err;
sk->sk_error_report(sk);
sk_error_report(sk);
out:
sock_put(sk);
}

View File

@ -280,7 +280,7 @@ static void raw_err(struct sock *sk, struct sk_buff *skb, u32 info)
if (inet->recverr || harderr) {
sk->sk_err = err;
sk->sk_error_report(sk);
sk_error_report(sk);
}
}
@ -929,7 +929,7 @@ int raw_abort(struct sock *sk, int err)
lock_sock(sk);
sk->sk_err = err;
sk->sk_error_report(sk);
sk_error_report(sk);
__udp_disconnect(sk, 0);
release_sock(sk);

View File

@ -3059,7 +3059,7 @@ int tcp_disconnect(struct sock *sk, int flags)
sk->sk_frag.offset = 0;
}
sk->sk_error_report(sk);
sk_error_report(sk);
return 0;
}
EXPORT_SYMBOL(tcp_disconnect);
@ -4448,7 +4448,7 @@ int tcp_abort(struct sock *sk, int err)
sk->sk_err = err;
/* This barrier is coupled with smp_rmb() in tcp_poll() */
smp_wmb();
sk->sk_error_report(sk);
sk_error_report(sk);
if (tcp_need_reset(sk->sk_state))
tcp_send_active_reset(sk, GFP_ATOMIC);
tcp_done(sk);

View File

@ -4270,7 +4270,7 @@ void tcp_reset(struct sock *sk, struct sk_buff *skb)
tcp_done(sk);
if (!sock_flag(sk, SOCK_DEAD))
sk->sk_error_report(sk);
sk_error_report(sk);
}
/*

View File

@ -585,7 +585,7 @@ int tcp_v4_err(struct sk_buff *skb, u32 info)
if (!sock_owned_by_user(sk)) {
sk->sk_err = err;
sk->sk_error_report(sk);
sk_error_report(sk);
tcp_done(sk);
} else {
@ -613,7 +613,7 @@ int tcp_v4_err(struct sk_buff *skb, u32 info)
inet = inet_sk(sk);
if (!sock_owned_by_user(sk) && inet->recverr) {
sk->sk_err = err;
sk->sk_error_report(sk);
sk_error_report(sk);
} else { /* Only an error on timeout */
sk->sk_err_soft = err;
}

View File

@ -68,7 +68,7 @@ u32 tcp_clamp_probe0_to_user_timeout(const struct sock *sk, u32 when)
static void tcp_write_err(struct sock *sk)
{
sk->sk_err = sk->sk_err_soft ? : ETIMEDOUT;
sk->sk_error_report(sk);
sk_error_report(sk);
tcp_write_queue_purge(sk);
tcp_done(sk);

View File

@ -776,7 +776,7 @@ int __udp4_lib_err(struct sk_buff *skb, u32 info, struct udp_table *udptable)
ip_icmp_error(sk, skb, err, uh->dest, info, (u8 *)(uh+1));
sk->sk_err = err;
sk->sk_error_report(sk);
sk_error_report(sk);
out:
return 0;
}
@ -2867,7 +2867,7 @@ int udp_abort(struct sock *sk, int err)
goto out;
sk->sk_err = err;
sk->sk_error_report(sk);
sk_error_report(sk);
__udp_disconnect(sk, 0);
out:

View File

@ -354,7 +354,7 @@ static void rawv6_err(struct sock *sk, struct sk_buff *skb,
if (np->recverr || harderr) {
sk->sk_err = err;
sk->sk_error_report(sk);
sk_error_report(sk);
}
}

View File

@ -467,7 +467,7 @@ static int tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
if (!sock_owned_by_user(sk)) {
sk->sk_err = err;
sk->sk_error_report(sk); /* Wake people up to see the error (see connect in sock.c) */
sk_error_report(sk); /* Wake people up to see the error (see connect in sock.c) */
tcp_done(sk);
} else
@ -486,7 +486,7 @@ static int tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
if (!sock_owned_by_user(sk) && np->recverr) {
sk->sk_err = err;
sk->sk_error_report(sk);
sk_error_report(sk);
} else
sk->sk_err_soft = err;

View File

@ -610,7 +610,7 @@ int __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
}
sk->sk_err = err;
sk->sk_error_report(sk);
sk_error_report(sk);
out:
return 0;
}

View File

@ -47,7 +47,7 @@ static inline struct kcm_tx_msg *kcm_tx_msg(struct sk_buff *skb)
static void report_csk_error(struct sock *csk, int err)
{
csk->sk_err = EPIPE;
csk->sk_error_report(csk);
sk_error_report(csk);
}
static void kcm_abort_tx_psock(struct kcm_psock *psock, int err,

View File

@ -1240,7 +1240,7 @@ void __mptcp_error_report(struct sock *sk)
/* This barrier is coupled with smp_rmb() in mptcp_poll() */
smp_wmb();
sk->sk_error_report(sk);
sk_error_report(sk);
break;
}
}

View File

@ -351,7 +351,7 @@ static void netlink_overrun(struct sock *sk)
if (!test_and_set_bit(NETLINK_S_CONGESTED,
&nlk_sk(sk)->state)) {
sk->sk_err = ENOBUFS;
sk->sk_error_report(sk);
sk_error_report(sk);
}
}
atomic_inc(&sk->sk_drops);
@ -1576,7 +1576,7 @@ static int do_one_set_err(struct sock *sk, struct netlink_set_err_data *p)
}
sk->sk_err = p->code;
sk->sk_error_report(sk);
sk_error_report(sk);
out:
return ret;
}
@ -2012,7 +2012,7 @@ static int netlink_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
ret = netlink_dump(sk);
if (ret) {
sk->sk_err = -ret;
sk->sk_error_report(sk);
sk_error_report(sk);
}
}
@ -2439,7 +2439,7 @@ void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err,
skb = nlmsg_new(payload + tlvlen, GFP_KERNEL);
if (!skb) {
NETLINK_CB(in_skb).sk->sk_err = ENOBUFS;
NETLINK_CB(in_skb).sk->sk_error_report(NETLINK_CB(in_skb).sk);
sk_error_report(NETLINK_CB(in_skb).sk);
return;
}

View File

@ -49,7 +49,7 @@ static void rawsock_report_error(struct sock *sk, int err)
sk->sk_shutdown = SHUTDOWN_MASK;
sk->sk_err = -err;
sk->sk_error_report(sk);
sk_error_report(sk);
rawsock_write_queue_purge(sk);
}

View File

@ -3206,7 +3206,7 @@ static int packet_do_bind(struct sock *sk, const char *name, int ifindex,
} else {
sk->sk_err = ENETDOWN;
if (!sock_flag(sk, SOCK_DEAD))
sk->sk_error_report(sk);
sk_error_report(sk);
}
out_unlock:
@ -4103,7 +4103,7 @@ static int packet_notifier(struct notifier_block *this,
__unregister_prot_hook(sk, false);
sk->sk_err = ENETDOWN;
if (!sock_flag(sk, SOCK_DEAD))
sk->sk_error_report(sk);
sk_error_report(sk);
}
if (msg == NETDEV_UNREGISTER) {
packet_cached_dev_reset(po);

View File

@ -751,7 +751,7 @@ static void qrtr_reset_ports(void)
xa_for_each_start(&qrtr_ports, index, ipc, 1) {
sock_hold(&ipc->sk);
ipc->sk.sk_err = ENETRESET;
ipc->sk.sk_error_report(&ipc->sk);
sk_error_report(&ipc->sk);
sock_put(&ipc->sk);
}
rcu_read_unlock();

View File

@ -593,7 +593,7 @@ static void sctp_v4_err_handle(struct sctp_transport *t, struct sk_buff *skb,
}
if (!sock_owned_by_user(sk) && inet_sk(sk)->recverr) {
sk->sk_err = err;
sk->sk_error_report(sk);
sk_error_report(sk);
} else { /* Only an error on timeout */
sk->sk_err_soft = err;
}

View File

@ -152,7 +152,7 @@ static void sctp_v6_err_handle(struct sctp_transport *t, struct sk_buff *skb,
icmpv6_err_convert(type, code, &err);
if (!sock_owned_by_user(sk) && np->recverr) {
sk->sk_err = err;
sk->sk_error_report(sk);
sk_error_report(sk);
} else {
sk->sk_err_soft = err;
}

View File

@ -2218,7 +2218,7 @@ static int smc_setsockopt(struct socket *sock, int level, int optname,
optval, optlen);
if (smc->clcsock->sk->sk_err) {
sk->sk_err = smc->clcsock->sk->sk_err;
sk->sk_error_report(sk);
sk_error_report(sk);
}
if (optlen < sizeof(int))

View File

@ -58,7 +58,7 @@ static void strp_abort_strp(struct strparser *strp, int err)
/* Report an error on the lower socket */
sk->sk_err = -err;
sk->sk_error_report(sk);
sk_error_report(sk);
}
}

View File

@ -491,7 +491,7 @@ static void unix_dgram_disconnected(struct sock *sk, struct sock *other)
*/
if (!sock_flag(other, SOCK_DEAD) && unix_peer(other) == sk) {
other->sk_err = ECONNRESET;
other->sk_error_report(other);
sk_error_report(other);
}
}
}

View File

@ -1281,7 +1281,7 @@ static void vsock_connect_timeout(struct work_struct *work)
(sk->sk_shutdown != SHUTDOWN_MASK)) {
sk->sk_state = TCP_CLOSE;
sk->sk_err = ETIMEDOUT;
sk->sk_error_report(sk);
sk_error_report(sk);
vsock_transport_cancel_pkt(vsk);
}
release_sock(sk);

View File

@ -360,7 +360,7 @@ static void virtio_vsock_reset_sock(struct sock *sk)
lock_sock(sk);
sk->sk_state = TCP_CLOSE;
sk->sk_err = ECONNRESET;
sk->sk_error_report(sk);
sk_error_report(sk);
release_sock(sk);
}

View File

@ -1007,7 +1007,7 @@ virtio_transport_recv_connecting(struct sock *sk,
virtio_transport_reset(vsk, pkt);
sk->sk_state = TCP_CLOSE;
sk->sk_err = skerr;
sk->sk_error_report(sk);
sk_error_report(sk);
return err;
}

View File

@ -831,7 +831,7 @@ static void vmci_transport_handle_detach(struct sock *sk)
sk->sk_state = TCP_CLOSE;
sk->sk_err = ECONNRESET;
sk->sk_error_report(sk);
sk_error_report(sk);
return;
}
sk->sk_state = TCP_CLOSE;
@ -1365,7 +1365,7 @@ vmci_transport_recv_connecting_client(struct sock *sk,
sk->sk_state = TCP_CLOSE;
sk->sk_err = skerr;
sk->sk_error_report(sk);
sk_error_report(sk);
return err;
}

View File

@ -1313,7 +1313,7 @@ static int xsk_notifier(struct notifier_block *this,
if (xs->dev == dev) {
sk->sk_err = ENETDOWN;
if (!sock_flag(sk, SOCK_DEAD))
sk->sk_error_report(sk);
sk_error_report(sk);
xsk_unbind_dev(xs);