Skip to content

Commit

Permalink
net: sock: introduce sk_error_report
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Alexander Aring authored and davem330 committed Jun 29, 2021
1 parent 7f4e5c5 commit e3ae236
Show file tree
Hide file tree
Showing 42 changed files with 75 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion drivers/vhost/vsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion include/linux/skmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions include/net/sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion include/net/tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion net/caif/caif_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions net/can/bcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1417,15 +1417,15 @@ 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;

case NETDEV_DOWN:
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);
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions net/can/isotp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions net/can/j1939/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions net/can/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions net/core/skbuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions net/dccp/ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions net/dccp/ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion net/dccp/proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion net/dccp/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions net/ipv4/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions net/ipv4/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/tcp_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/*
Expand Down
4 changes: 2 additions & 2 deletions net/ipv4/tcp_ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/tcp_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions net/ipv4/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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:
Expand Down
Loading

0 comments on commit e3ae236

Please sign in to comment.