From d992e267ee237ffa7883eb0c5ac281afcecc61d5 Mon Sep 17 00:00:00 2001 From: zhang-mingyi66 Date: Sat, 15 Jul 2023 00:12:56 +0800 Subject: [PATCH] net, bpf: Add a writeable_tracepoint to inet_stream_connect hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I7LE1H -------------------------------------------------- A trace point is added to the connection process. Theebpf program can be mounted to modify the return value of the function. This is mandatory for delaying the establishment of an ebpf link. After the connection is complete, a message is returned immediately and no unnecessary operation is performed. Signed-off-by: zhang-mingyi66 --- include/trace/events/sock.h | 15 +++++++++++++++ net/ipv4/af_inet.c | 1 + 2 files changed, 16 insertions(+) diff --git a/include/trace/events/sock.h b/include/trace/events/sock.h index fd206a6ab5b8..289682e3d4e1 100644 --- a/include/trace/events/sock.h +++ b/include/trace/events/sock.h @@ -332,6 +332,21 @@ DEFINE_EVENT(sock_msg_length, sock_recv_length, TP_ARGS(sk, ret, flags) ); + +#undef NET_DECLARE_TRACE +#ifdef DECLARE_TRACE_WRITABLE +#define NET_DECLARE_TRACE(call, proto, args, size) \ + DECLARE_TRACE_WRITABLE(call, PARAMS(proto), PARAMS(args), size) +#else +#define NET_DECLARE_TRACE(call, proto, args, size) \ + DECLARE_TRACE(call, PARAMS(proto), PARAMS(args)) +#endif + +NET_DECLARE_TRACE(connect_ret, + TP_PROTO(int *err), + TP_ARGS(err), + sizeof(int)); + #endif /* _TRACE_SOCK_H */ /* This part must be outside protection */ diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index 4a76ebf793b8..06029ded2d72 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -728,6 +728,7 @@ int inet_stream_connect(struct socket *sock, struct sockaddr *uaddr, lock_sock(sock->sk); err = __inet_stream_connect(sock, uaddr, addr_len, flags, 0); release_sock(sock->sk); + trace_connect_ret(&err); return err; } EXPORT_SYMBOL(inet_stream_connect); -- GitLab