Skip to content

Commit c79fa61

Browse files
committed
Merge branch 'inet-sk_error-tracers'
Alexander Aring says: ==================== net: sock: add tracers for inet socket errors this patch series introduce tracers for sk_error_report socket callback calls. The use-case is that a user space application can monitor them and making an own heuristic about bad peer connections even over a socket lifetime. To make a specific example it could be use in the Linux cluster world to fence a "bad" behaving node. For now it's okay to only trace inet sockets. Other socket families can introduce their own tracers easily. Example output with trace-cmd: <idle>-0 [003] 201.799437: inet_sk_error_report: family=AF_INET protocol=IPPROTO_TCP sport=21064 dport=38941 saddr=192.168.122.57 daddr=192.168.122.251 saddrv6=::ffff:192.168.122.57 daddrv6=::ffff:192.168.122.251 error=104 - Alex changes since v2: - change "sk.sk_error_report(&ipc->sk);" to "sk_error_report(&ipc->sk);" in net/qrtr/qrtr.c ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 7f4e5c5 + e6a3e44 commit c79fa61

File tree

43 files changed

+145
-67
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+145
-67
lines changed

drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2134,7 +2134,7 @@ static void chtls_abort_req_rss(struct sock *sk, struct sk_buff *skb)
21342134
sk->sk_err = ETIMEDOUT;
21352135

21362136
if (!sock_flag(sk, SOCK_DEAD))
2137-
sk->sk_error_report(sk);
2137+
sk_error_report(sk);
21382138

21392139
if (sk->sk_state == TCP_SYN_RECV && !abort_syn_rcv(sk, skb))
21402140
return;

drivers/vhost/vsock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ static void vhost_vsock_reset_orphans(struct sock *sk)
734734
vsk->peer_shutdown = SHUTDOWN_MASK;
735735
sk->sk_state = SS_UNCONNECTED;
736736
sk->sk_err = ECONNRESET;
737-
sk->sk_error_report(sk);
737+
sk_error_report(sk);
738738
}
739739

740740
static int vhost_vsock_dev_release(struct inode *inode, struct file *file)

include/linux/skmsg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ static inline void sk_psock_report_error(struct sk_psock *psock, int err)
347347
struct sock *sk = psock->sk;
348348

349349
sk->sk_err = err;
350-
sk->sk_error_report(sk);
350+
sk_error_report(sk);
351351
}
352352

353353
struct sk_psock *sk_psock_init(struct sock *sk, int node);

include/net/sock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,6 +2281,8 @@ static inline int sock_error(struct sock *sk)
22812281
return -err;
22822282
}
22832283

2284+
void sk_error_report(struct sock *sk);
2285+
22842286
static inline unsigned long sock_wspace(struct sock *sk)
22852287
{
22862288
int amt = 0;

include/net/tls.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ static inline bool tls_is_sk_tx_device_offloaded(struct sock *sk)
469469
static inline void tls_err_abort(struct sock *sk, int err)
470470
{
471471
sk->sk_err = err;
472-
sk->sk_error_report(sk);
472+
sk_error_report(sk);
473473
}
474474

475475
static inline bool tls_bigint_increment(unsigned char *seq, int len)

include/trace/events/sock.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,66 @@ TRACE_EVENT(inet_sock_set_state,
201201
show_tcp_state_name(__entry->newstate))
202202
);
203203

204+
TRACE_EVENT(inet_sk_error_report,
205+
206+
TP_PROTO(const struct sock *sk),
207+
208+
TP_ARGS(sk),
209+
210+
TP_STRUCT__entry(
211+
__field(int, error)
212+
__field(__u16, sport)
213+
__field(__u16, dport)
214+
__field(__u16, family)
215+
__field(__u16, protocol)
216+
__array(__u8, saddr, 4)
217+
__array(__u8, daddr, 4)
218+
__array(__u8, saddr_v6, 16)
219+
__array(__u8, daddr_v6, 16)
220+
),
221+
222+
TP_fast_assign(
223+
struct inet_sock *inet = inet_sk(sk);
224+
struct in6_addr *pin6;
225+
__be32 *p32;
226+
227+
__entry->error = sk->sk_err;
228+
__entry->family = sk->sk_family;
229+
__entry->protocol = sk->sk_protocol;
230+
__entry->sport = ntohs(inet->inet_sport);
231+
__entry->dport = ntohs(inet->inet_dport);
232+
233+
p32 = (__be32 *) __entry->saddr;
234+
*p32 = inet->inet_saddr;
235+
236+
p32 = (__be32 *) __entry->daddr;
237+
*p32 = inet->inet_daddr;
238+
239+
#if IS_ENABLED(CONFIG_IPV6)
240+
if (sk->sk_family == AF_INET6) {
241+
pin6 = (struct in6_addr *)__entry->saddr_v6;
242+
*pin6 = sk->sk_v6_rcv_saddr;
243+
pin6 = (struct in6_addr *)__entry->daddr_v6;
244+
*pin6 = sk->sk_v6_daddr;
245+
} else
246+
#endif
247+
{
248+
pin6 = (struct in6_addr *)__entry->saddr_v6;
249+
ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
250+
pin6 = (struct in6_addr *)__entry->daddr_v6;
251+
ipv6_addr_set_v4mapped(inet->inet_daddr, pin6);
252+
}
253+
),
254+
255+
TP_printk("family=%s protocol=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c error=%d",
256+
show_family_name(__entry->family),
257+
show_inet_protocol_name(__entry->protocol),
258+
__entry->sport, __entry->dport,
259+
__entry->saddr, __entry->daddr,
260+
__entry->saddr_v6, __entry->daddr_v6,
261+
__entry->error)
262+
);
263+
204264
#endif /* _TRACE_SOCK_H */
205265

206266
/* This part must be outside protection */

net/caif/caif_socket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
243243
cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
244244
cf_sk->sk.sk_err = ECONNRESET;
245245
set_rx_flow_on(cf_sk);
246-
cf_sk->sk.sk_error_report(&cf_sk->sk);
246+
sk_error_report(&cf_sk->sk);
247247
break;
248248

249249
default:

net/can/bcm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,15 +1417,15 @@ static void bcm_notify(struct bcm_sock *bo, unsigned long msg,
14171417
if (notify_enodev) {
14181418
sk->sk_err = ENODEV;
14191419
if (!sock_flag(sk, SOCK_DEAD))
1420-
sk->sk_error_report(sk);
1420+
sk_error_report(sk);
14211421
}
14221422
break;
14231423

14241424
case NETDEV_DOWN:
14251425
if (bo->bound && bo->ifindex == dev->ifindex) {
14261426
sk->sk_err = ENETDOWN;
14271427
if (!sock_flag(sk, SOCK_DEAD))
1428-
sk->sk_error_report(sk);
1428+
sk_error_report(sk);
14291429
}
14301430
}
14311431
}

net/can/isotp.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static enum hrtimer_restart isotp_rx_timer_handler(struct hrtimer *hrtimer)
168168
/* report 'connection timed out' */
169169
sk->sk_err = ETIMEDOUT;
170170
if (!sock_flag(sk, SOCK_DEAD))
171-
sk->sk_error_report(sk);
171+
sk_error_report(sk);
172172

173173
/* reset rx state */
174174
so->rx.state = ISOTP_IDLE;
@@ -339,7 +339,7 @@ static int isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae)
339339
/* malformed PDU - report 'not a data message' */
340340
sk->sk_err = EBADMSG;
341341
if (!sock_flag(sk, SOCK_DEAD))
342-
sk->sk_error_report(sk);
342+
sk_error_report(sk);
343343

344344
so->tx.state = ISOTP_IDLE;
345345
wake_up_interruptible(&so->wait);
@@ -392,7 +392,7 @@ static int isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae)
392392
/* overflow on receiver side - report 'message too long' */
393393
sk->sk_err = EMSGSIZE;
394394
if (!sock_flag(sk, SOCK_DEAD))
395-
sk->sk_error_report(sk);
395+
sk_error_report(sk);
396396
fallthrough;
397397

398398
default:
@@ -420,7 +420,7 @@ static int isotp_rcv_sf(struct sock *sk, struct canfd_frame *cf, int pcilen,
420420
/* malformed PDU - report 'not a data message' */
421421
sk->sk_err = EBADMSG;
422422
if (!sock_flag(sk, SOCK_DEAD))
423-
sk->sk_error_report(sk);
423+
sk_error_report(sk);
424424
return 1;
425425
}
426426

@@ -535,7 +535,7 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
535535
/* wrong sn detected - report 'illegal byte sequence' */
536536
sk->sk_err = EILSEQ;
537537
if (!sock_flag(sk, SOCK_DEAD))
538-
sk->sk_error_report(sk);
538+
sk_error_report(sk);
539539

540540
/* reset rx state */
541541
so->rx.state = ISOTP_IDLE;
@@ -559,7 +559,7 @@ static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
559559
/* malformed PDU - report 'not a data message' */
560560
sk->sk_err = EBADMSG;
561561
if (!sock_flag(sk, SOCK_DEAD))
562-
sk->sk_error_report(sk);
562+
sk_error_report(sk);
563563
return 1;
564564
}
565565

@@ -758,7 +758,7 @@ static enum hrtimer_restart isotp_tx_timer_handler(struct hrtimer *hrtimer)
758758
/* report 'communication error on send' */
759759
sk->sk_err = ECOMM;
760760
if (!sock_flag(sk, SOCK_DEAD))
761-
sk->sk_error_report(sk);
761+
sk_error_report(sk);
762762

763763
/* reset tx state */
764764
so->tx.state = ISOTP_IDLE;
@@ -1157,7 +1157,7 @@ static int isotp_bind(struct socket *sock, struct sockaddr *uaddr, int len)
11571157
if (notify_enetdown) {
11581158
sk->sk_err = ENETDOWN;
11591159
if (!sock_flag(sk, SOCK_DEAD))
1160-
sk->sk_error_report(sk);
1160+
sk_error_report(sk);
11611161
}
11621162

11631163
return err;
@@ -1356,13 +1356,13 @@ static void isotp_notify(struct isotp_sock *so, unsigned long msg,
13561356

13571357
sk->sk_err = ENODEV;
13581358
if (!sock_flag(sk, SOCK_DEAD))
1359-
sk->sk_error_report(sk);
1359+
sk_error_report(sk);
13601360
break;
13611361

13621362
case NETDEV_DOWN:
13631363
sk->sk_err = ENETDOWN;
13641364
if (!sock_flag(sk, SOCK_DEAD))
1365-
sk->sk_error_report(sk);
1365+
sk_error_report(sk);
13661366
break;
13671367
}
13681368
}

net/can/j1939/socket.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ void j1939_sk_send_loop_abort(struct sock *sk, int err)
10091009
{
10101010
sk->sk_err = err;
10111011

1012-
sk->sk_error_report(sk);
1012+
sk_error_report(sk);
10131013
}
10141014

10151015
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)
11891189
list_for_each_entry(jsk, &priv->j1939_socks, list) {
11901190
jsk->sk.sk_err = error_code;
11911191
if (!sock_flag(&jsk->sk, SOCK_DEAD))
1192-
jsk->sk.sk_error_report(&jsk->sk);
1192+
sk_error_report(&jsk->sk);
11931193

11941194
j1939_sk_queue_drop_all(priv, jsk, error_code);
11951195
}

0 commit comments

Comments
 (0)