Re: [PATCH net-next 2/2] trace: tcp: fully support trace_tcp_send_reset

2024-03-10 Thread Ratheesh Kannoth
> From: Jason Xing 
> Sent: Monday, March 11, 2024 10:30 AM
> To: Ratheesh Kannoth 
> Cc: eduma...@google.com; mhira...@kernel.org;
> mathieu.desnoy...@efficios.com; rost...@goodmis.org; k...@kernel.org;
> pab...@redhat.com; da...@davemloft.net; net...@vger.kernel.org; linux-
> trace-ker...@vger.kernel.org; Jason Xing 
> Subject: [EXTERNAL] Re: [PATCH net-next 2/2] trace: tcp: fully support
> trace_tcp_send_reset
> 
> > > + ),
> > > +
> > > + TP_printk("skbaddr=%p skaddr=%p src=%pISpc dest=%pISpc
> > > + state=%s",
> > Could you consider using %px ? is it permitted ? it will be easy to track 
> > skb.
> 
> I prefer not to use %px because we cannot make use of the real address of
> skb. Besides, using %px would leak kernel addresses.
> 
> Here is the Documentation (see Documentation/core-api/printk-formats.rst):
> "Pointers printed without a specifier extension (i.e unadorned %p) are
> hashed to give a unique identifier without leaking kernel addresses to user
> space."
> 
> Perhaps, that's the reason why all the tracepoints didn't print in %px 
> format:)
> 
ACK, I understand that.  In offload cases, or in mostly in IOVA space, we often 
end up changing this locally to %px to debug and track skb. 
That is why I asked the question. 
 
> Thanks,
> Jason
> 
> >
> > > +   __entry->skbaddr, __entry->skaddr,
> > > +   __entry->saddr, __entry->daddr,
> > > +   __entry->state ? show_tcp_state_name(__entry->state)
> > > + : "UNKNOWN")
> > >  );
> > >
> > >  /*
> > > diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index
> > > a22ee5838751..d5c4a969c066 100644
> > > --- a/net/ipv4/tcp_ipv4.c
> > > +++ b/net/ipv4/tcp_ipv4.c
> > > @@ -868,10 +868,10 @@ static void tcp_v4_send_reset(const struct sock
> *sk, struct sk_buff *skb)
> > >*/
> > >   if (sk) {
> > >   arg.bound_dev_if = sk->sk_bound_dev_if;
> > > - if (sk_fullsock(sk))
> > > - trace_tcp_send_reset(sk, skb);
> > >   }
> > >
> > > + trace_tcp_send_reset(sk, skb);
> > > +
> > >   BUILD_BUG_ON(offsetof(struct sock, sk_bound_dev_if) !=
> > >offsetof(struct inet_timewait_sock,
> > > tw_bound_dev_if));
> > >
> > > diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index
> > > 3f4cba49e9ee..8e9c59b6c00c 100644
> > > --- a/net/ipv6/tcp_ipv6.c
> > > +++ b/net/ipv6/tcp_ipv6.c
> > > @@ -1113,7 +1113,6 @@ static void tcp_v6_send_reset(const struct sock
> *sk, struct sk_buff *skb)
> > >   if (sk) {
> > >   oif = sk->sk_bound_dev_if;
> > >   if (sk_fullsock(sk)) {
> > > - trace_tcp_send_reset(sk, skb);
> > >   if (inet6_test_bit(REPFLOW, sk))
> > >   label = ip6_flowlabel(ipv6h);
> > >   priority = READ_ONCE(sk->sk_priority); @@
> > > -1129,6 +1128,8 @@ static void tcp_v6_send_reset(const struct sock *sk,
> struct sk_buff *skb)
> > >   label = ip6_flowlabel(ipv6h);
> > >   }
> > >
> > > + trace_tcp_send_reset(sk, skb);
> > > +
> > >   tcp_v6_send_response(sk, skb, seq, ack_seq, 0, 0, 0, oif, 1,
> > >ipv6_get_dsfield(ipv6h), label, priority, 
> > > txhash,
> > >&key);
> > > --
> > > 2.37.3
> > >


Re: [PATCH net-next 2/2] trace: tcp: fully support trace_tcp_send_reset

2024-03-10 Thread Jason Xing
On Mon, Mar 11, 2024 at 11:27 AM Ratheesh Kannoth  wrote:
>
> On 2024-03-11 at 08:11:04, Jason Xing (kerneljasonx...@gmail.com) wrote:
> > From: Jason Xing 
> >
> > Prior to this patch, what we can see by enabling trace_tcp_send is
> > only happening under two circumstances:
> > 1) active rst mode
> > 2) non-active rst mode and based on the full socket
> >
> > That means the inconsistency occurs if we use tcpdump and trace
> > simultaneously to see how rst happens.
> >
> > It's necessary that we should take into other cases into considerations,
> > say:
> > 1) time-wait socket
> > 2) no socket
> > ...
> >
> > By parsing the incoming skb and reversing its 4-turple can
> > we know the exact 'flow' which might not exist.
> >
> > Samples after applied this patch:
> > 1. tcp_send_reset: skbaddr=XXX skaddr=XXX src=ip:port dest=ip:port
> > state=TCP_ESTABLISHED
> > 2. tcp_send_reset: skbaddr=000...000 skaddr=XXX src=ip:port dest=ip:port
> > state=UNKNOWN
> > Note:
> > 1) UNKNOWN means we cannot extract the right information from skb.
> > 2) skbaddr/skaddr could be 0
> >
> > Signed-off-by: Jason Xing 
> > ---
> >  include/trace/events/tcp.h | 39 --
> >  net/ipv4/tcp_ipv4.c|  4 ++--
> >  net/ipv6/tcp_ipv6.c|  3 ++-
> >  3 files changed, 41 insertions(+), 5 deletions(-)
> >
> > diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h
> > index 2495a1d579be..6c09d7941583 100644
> > --- a/include/trace/events/tcp.h
> > +++ b/include/trace/events/tcp.h
> > @@ -107,11 +107,46 @@ DEFINE_EVENT(tcp_event_sk_skb, tcp_retransmit_skb,
> >   * skb of trace_tcp_send_reset is the skb that caused RST. In case of
> >   * active reset, skb should be NULL
> >   */
> > -DEFINE_EVENT(tcp_event_sk_skb, tcp_send_reset,
> > +TRACE_EVENT(tcp_send_reset,
> >
> >   TP_PROTO(const struct sock *sk, const struct sk_buff *skb),
> >
> > - TP_ARGS(sk, skb)
> > + TP_ARGS(sk, skb),
> > +
> > + TP_STRUCT__entry(
> > + __field(const void *, skbaddr)
> > + __field(const void *, skaddr)
> > + __field(int, state)
> > + __array(__u8, saddr, sizeof(struct sockaddr_in6))
> > + __array(__u8, daddr, sizeof(struct sockaddr_in6))
> > + ),
> > +
> > + TP_fast_assign(
> > + __entry->skbaddr = skb;
> > + __entry->skaddr = sk;
> > + /* Zero means unknown state. */
> > + __entry->state = sk ? sk->sk_state : 0;
> > +
> > + memset(__entry->saddr, 0, sizeof(struct sockaddr_in6));
> > + memset(__entry->daddr, 0, sizeof(struct sockaddr_in6));
> > +
> > + if (sk && sk_fullsock(sk)) {
> > + const struct inet_sock *inet = inet_sk(sk);
> > +
> > + TP_STORE_ADDR_PORTS(__entry, inet, sk);
> > + } else {
> > + /*
> > +  * We should reverse the 4-turple of skb, so later
> > +  * it can print the right flow direction of rst.
> > +  */
> > + TP_STORE_ADDR_PORTS_SKB(skb, entry->daddr, 
> > entry->saddr);
> > + }
> > + ),
> > +
> > + TP_printk("skbaddr=%p skaddr=%p src=%pISpc dest=%pISpc state=%s",
> Could you consider using %px ? is it permitted ? it will be easy to track skb.

I prefer not to use %px because we cannot make use of the real address
of skb. Besides, using %px would leak kernel addresses.

Here is the Documentation (see Documentation/core-api/printk-formats.rst):
"Pointers printed without a specifier extension (i.e unadorned %p) are
hashed to give a unique identifier without leaking kernel addresses to user
space."

Perhaps, that's the reason why all the tracepoints didn't print in %px format:)

Thanks,
Jason

>
> > +   __entry->skbaddr, __entry->skaddr,
> > +   __entry->saddr, __entry->daddr,
> > +   __entry->state ? show_tcp_state_name(__entry->state) : 
> > "UNKNOWN")
> >  );
> >
> >  /*
> > diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
> > index a22ee5838751..d5c4a969c066 100644
> > --- a/net/ipv4/tcp_ipv4.c
> > +++ b/net/ipv4/tcp_ipv4.c
> > @@ -868,10 +868,10 @@ static void tcp_v4_send_reset(const struct sock *sk, 
> > struct sk_buff *skb)
> >*/
> >   if (sk) {
> >   arg.bound_dev_if = sk->sk_bound_dev_if;
> > - if (sk_fullsock(sk))
> > - trace_tcp_send_reset(sk, skb);
> >   }
> >
> > + trace_tcp_send_reset(sk, skb);
> > +
> >   BUILD_BUG_ON(offsetof(struct sock, sk_bound_dev_if) !=
> >offsetof(struct inet_timewait_sock, tw_bound_dev_if));
> >
> > diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
> > index 3f4cba49e9ee..8e9c59b6c00c 100644
> > --- a/net/ipv6/tcp_ipv6.c
> > +++ b/net/ipv6/tcp_ipv6.c
> > @@ -1113,7 +1113,6 @@ static void tcp_v6_send_reset(const struct sock *sk, 
> > struct sk_buff *skb)
> >   if (sk) {
> >  

Re: [PATCH net-next 1/2] trace: adjust TP_STORE_ADDR_PORTS_SKB() parameters

2024-03-10 Thread Jason Xing
On Mon, Mar 11, 2024 at 11:23 AM Ratheesh Kannoth  wrote:
>
> On 2024-03-11 at 08:11:03, Jason Xing (kerneljasonx...@gmail.com) wrote:
> > From: Jason Xing 
> >
> > Introducing entry_saddr and entry_daddr parameters in this macro
> > for later use can help us record the reverse 4-turple by analyzing
> Did you mean tuple ? what is turple ?
>
> > the 4-turple of the incoming skb when receiving.

Oh, thanks for reminding me. I always remember the wrong word... Yes,
it is tuple.

Thanks,
Jason

> >
> > Signed-off-by: Jason Xing 
> > ---
> >  include/trace/events/tcp.h | 21 +++--
> >  1 file changed, 11 insertions(+), 10 deletions(-)
> >
> > diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h
> > index 699dafd204ea..2495a1d579be 100644
> > --- a/include/trace/events/tcp.h
> > +++ b/include/trace/events/tcp.h
> > @@ -302,15 +302,15 @@ TRACE_EVENT(tcp_probe,
> > __entry->skbaddr, __entry->skaddr)
> >  );



Re: [PATCH net-next 2/2] trace: tcp: fully support trace_tcp_send_reset

2024-03-10 Thread Ratheesh Kannoth
On 2024-03-11 at 08:11:04, Jason Xing (kerneljasonx...@gmail.com) wrote:
> From: Jason Xing 
>
> Prior to this patch, what we can see by enabling trace_tcp_send is
> only happening under two circumstances:
> 1) active rst mode
> 2) non-active rst mode and based on the full socket
>
> That means the inconsistency occurs if we use tcpdump and trace
> simultaneously to see how rst happens.
>
> It's necessary that we should take into other cases into considerations,
> say:
> 1) time-wait socket
> 2) no socket
> ...
>
> By parsing the incoming skb and reversing its 4-turple can
> we know the exact 'flow' which might not exist.
>
> Samples after applied this patch:
> 1. tcp_send_reset: skbaddr=XXX skaddr=XXX src=ip:port dest=ip:port
> state=TCP_ESTABLISHED
> 2. tcp_send_reset: skbaddr=000...000 skaddr=XXX src=ip:port dest=ip:port
> state=UNKNOWN
> Note:
> 1) UNKNOWN means we cannot extract the right information from skb.
> 2) skbaddr/skaddr could be 0
>
> Signed-off-by: Jason Xing 
> ---
>  include/trace/events/tcp.h | 39 --
>  net/ipv4/tcp_ipv4.c|  4 ++--
>  net/ipv6/tcp_ipv6.c|  3 ++-
>  3 files changed, 41 insertions(+), 5 deletions(-)
>
> diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h
> index 2495a1d579be..6c09d7941583 100644
> --- a/include/trace/events/tcp.h
> +++ b/include/trace/events/tcp.h
> @@ -107,11 +107,46 @@ DEFINE_EVENT(tcp_event_sk_skb, tcp_retransmit_skb,
>   * skb of trace_tcp_send_reset is the skb that caused RST. In case of
>   * active reset, skb should be NULL
>   */
> -DEFINE_EVENT(tcp_event_sk_skb, tcp_send_reset,
> +TRACE_EVENT(tcp_send_reset,
>
>   TP_PROTO(const struct sock *sk, const struct sk_buff *skb),
>
> - TP_ARGS(sk, skb)
> + TP_ARGS(sk, skb),
> +
> + TP_STRUCT__entry(
> + __field(const void *, skbaddr)
> + __field(const void *, skaddr)
> + __field(int, state)
> + __array(__u8, saddr, sizeof(struct sockaddr_in6))
> + __array(__u8, daddr, sizeof(struct sockaddr_in6))
> + ),
> +
> + TP_fast_assign(
> + __entry->skbaddr = skb;
> + __entry->skaddr = sk;
> + /* Zero means unknown state. */
> + __entry->state = sk ? sk->sk_state : 0;
> +
> + memset(__entry->saddr, 0, sizeof(struct sockaddr_in6));
> + memset(__entry->daddr, 0, sizeof(struct sockaddr_in6));
> +
> + if (sk && sk_fullsock(sk)) {
> + const struct inet_sock *inet = inet_sk(sk);
> +
> + TP_STORE_ADDR_PORTS(__entry, inet, sk);
> + } else {
> + /*
> +  * We should reverse the 4-turple of skb, so later
> +  * it can print the right flow direction of rst.
> +  */
> + TP_STORE_ADDR_PORTS_SKB(skb, entry->daddr, 
> entry->saddr);
> + }
> + ),
> +
> + TP_printk("skbaddr=%p skaddr=%p src=%pISpc dest=%pISpc state=%s",
Could you consider using %px ? is it permitted ? it will be easy to track skb.

> +   __entry->skbaddr, __entry->skaddr,
> +   __entry->saddr, __entry->daddr,
> +   __entry->state ? show_tcp_state_name(__entry->state) : 
> "UNKNOWN")
>  );
>
>  /*
> diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
> index a22ee5838751..d5c4a969c066 100644
> --- a/net/ipv4/tcp_ipv4.c
> +++ b/net/ipv4/tcp_ipv4.c
> @@ -868,10 +868,10 @@ static void tcp_v4_send_reset(const struct sock *sk, 
> struct sk_buff *skb)
>*/
>   if (sk) {
>   arg.bound_dev_if = sk->sk_bound_dev_if;
> - if (sk_fullsock(sk))
> - trace_tcp_send_reset(sk, skb);
>   }
>
> + trace_tcp_send_reset(sk, skb);
> +
>   BUILD_BUG_ON(offsetof(struct sock, sk_bound_dev_if) !=
>offsetof(struct inet_timewait_sock, tw_bound_dev_if));
>
> diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
> index 3f4cba49e9ee..8e9c59b6c00c 100644
> --- a/net/ipv6/tcp_ipv6.c
> +++ b/net/ipv6/tcp_ipv6.c
> @@ -1113,7 +1113,6 @@ static void tcp_v6_send_reset(const struct sock *sk, 
> struct sk_buff *skb)
>   if (sk) {
>   oif = sk->sk_bound_dev_if;
>   if (sk_fullsock(sk)) {
> - trace_tcp_send_reset(sk, skb);
>   if (inet6_test_bit(REPFLOW, sk))
>   label = ip6_flowlabel(ipv6h);
>   priority = READ_ONCE(sk->sk_priority);
> @@ -1129,6 +1128,8 @@ static void tcp_v6_send_reset(const struct sock *sk, 
> struct sk_buff *skb)
>   label = ip6_flowlabel(ipv6h);
>   }
>
> + trace_tcp_send_reset(sk, skb);
> +
>   tcp_v6_send_response(sk, skb, seq, ack_seq, 0, 0, 0, oif, 1,
>ipv6_get_dsfield(ipv6h), label, priority, txhash,
>&key);
> --
> 2.37.3
>



Re: [PATCH net-next 1/2] trace: adjust TP_STORE_ADDR_PORTS_SKB() parameters

2024-03-10 Thread Ratheesh Kannoth
On 2024-03-11 at 08:11:03, Jason Xing (kerneljasonx...@gmail.com) wrote:
> From: Jason Xing 
>
> Introducing entry_saddr and entry_daddr parameters in this macro
> for later use can help us record the reverse 4-turple by analyzing
Did you mean tuple ? what is turple ?

> the 4-turple of the incoming skb when receiving.
>
> Signed-off-by: Jason Xing 
> ---
>  include/trace/events/tcp.h | 21 +++--
>  1 file changed, 11 insertions(+), 10 deletions(-)
>
> diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h
> index 699dafd204ea..2495a1d579be 100644
> --- a/include/trace/events/tcp.h
> +++ b/include/trace/events/tcp.h
> @@ -302,15 +302,15 @@ TRACE_EVENT(tcp_probe,
> __entry->skbaddr, __entry->skaddr)
>  );



[PATCH net-next 2/2] trace: tcp: fully support trace_tcp_send_reset

2024-03-10 Thread Jason Xing
From: Jason Xing 

Prior to this patch, what we can see by enabling trace_tcp_send is
only happening under two circumstances:
1) active rst mode
2) non-active rst mode and based on the full socket

That means the inconsistency occurs if we use tcpdump and trace
simultaneously to see how rst happens.

It's necessary that we should take into other cases into considerations,
say:
1) time-wait socket
2) no socket
...

By parsing the incoming skb and reversing its 4-turple can
we know the exact 'flow' which might not exist.

Samples after applied this patch:
1. tcp_send_reset: skbaddr=XXX skaddr=XXX src=ip:port dest=ip:port
state=TCP_ESTABLISHED
2. tcp_send_reset: skbaddr=000...000 skaddr=XXX src=ip:port dest=ip:port
state=UNKNOWN
Note:
1) UNKNOWN means we cannot extract the right information from skb.
2) skbaddr/skaddr could be 0

Signed-off-by: Jason Xing 
---
 include/trace/events/tcp.h | 39 --
 net/ipv4/tcp_ipv4.c|  4 ++--
 net/ipv6/tcp_ipv6.c|  3 ++-
 3 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h
index 2495a1d579be..6c09d7941583 100644
--- a/include/trace/events/tcp.h
+++ b/include/trace/events/tcp.h
@@ -107,11 +107,46 @@ DEFINE_EVENT(tcp_event_sk_skb, tcp_retransmit_skb,
  * skb of trace_tcp_send_reset is the skb that caused RST. In case of
  * active reset, skb should be NULL
  */
-DEFINE_EVENT(tcp_event_sk_skb, tcp_send_reset,
+TRACE_EVENT(tcp_send_reset,
 
TP_PROTO(const struct sock *sk, const struct sk_buff *skb),
 
-   TP_ARGS(sk, skb)
+   TP_ARGS(sk, skb),
+
+   TP_STRUCT__entry(
+   __field(const void *, skbaddr)
+   __field(const void *, skaddr)
+   __field(int, state)
+   __array(__u8, saddr, sizeof(struct sockaddr_in6))
+   __array(__u8, daddr, sizeof(struct sockaddr_in6))
+   ),
+
+   TP_fast_assign(
+   __entry->skbaddr = skb;
+   __entry->skaddr = sk;
+   /* Zero means unknown state. */
+   __entry->state = sk ? sk->sk_state : 0;
+
+   memset(__entry->saddr, 0, sizeof(struct sockaddr_in6));
+   memset(__entry->daddr, 0, sizeof(struct sockaddr_in6));
+
+   if (sk && sk_fullsock(sk)) {
+   const struct inet_sock *inet = inet_sk(sk);
+
+   TP_STORE_ADDR_PORTS(__entry, inet, sk);
+   } else {
+   /*
+* We should reverse the 4-turple of skb, so later
+* it can print the right flow direction of rst.
+*/
+   TP_STORE_ADDR_PORTS_SKB(skb, entry->daddr, 
entry->saddr);
+   }
+   ),
+
+   TP_printk("skbaddr=%p skaddr=%p src=%pISpc dest=%pISpc state=%s",
+ __entry->skbaddr, __entry->skaddr,
+ __entry->saddr, __entry->daddr,
+ __entry->state ? show_tcp_state_name(__entry->state) : 
"UNKNOWN")
 );
 
 /*
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index a22ee5838751..d5c4a969c066 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -868,10 +868,10 @@ static void tcp_v4_send_reset(const struct sock *sk, 
struct sk_buff *skb)
 */
if (sk) {
arg.bound_dev_if = sk->sk_bound_dev_if;
-   if (sk_fullsock(sk))
-   trace_tcp_send_reset(sk, skb);
}
 
+   trace_tcp_send_reset(sk, skb);
+
BUILD_BUG_ON(offsetof(struct sock, sk_bound_dev_if) !=
 offsetof(struct inet_timewait_sock, tw_bound_dev_if));
 
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 3f4cba49e9ee..8e9c59b6c00c 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -1113,7 +1113,6 @@ static void tcp_v6_send_reset(const struct sock *sk, 
struct sk_buff *skb)
if (sk) {
oif = sk->sk_bound_dev_if;
if (sk_fullsock(sk)) {
-   trace_tcp_send_reset(sk, skb);
if (inet6_test_bit(REPFLOW, sk))
label = ip6_flowlabel(ipv6h);
priority = READ_ONCE(sk->sk_priority);
@@ -1129,6 +1128,8 @@ static void tcp_v6_send_reset(const struct sock *sk, 
struct sk_buff *skb)
label = ip6_flowlabel(ipv6h);
}
 
+   trace_tcp_send_reset(sk, skb);
+
tcp_v6_send_response(sk, skb, seq, ack_seq, 0, 0, 0, oif, 1,
 ipv6_get_dsfield(ipv6h), label, priority, txhash,
 &key);
-- 
2.37.3




[PATCH net-next 1/2] trace: adjust TP_STORE_ADDR_PORTS_SKB() parameters

2024-03-10 Thread Jason Xing
From: Jason Xing 

Introducing entry_saddr and entry_daddr parameters in this macro
for later use can help us record the reverse 4-turple by analyzing
the 4-turple of the incoming skb when receiving.

Signed-off-by: Jason Xing 
---
 include/trace/events/tcp.h | 21 +++--
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h
index 699dafd204ea..2495a1d579be 100644
--- a/include/trace/events/tcp.h
+++ b/include/trace/events/tcp.h
@@ -302,15 +302,15 @@ TRACE_EVENT(tcp_probe,
  __entry->skbaddr, __entry->skaddr)
 );
 
-#define TP_STORE_ADDR_PORTS_SKB_V4(__entry, skb)   \
+#define TP_STORE_ADDR_PORTS_SKB_V4(skb, entry_saddr, entry_daddr)  \
do {\
const struct tcphdr *th = (const struct tcphdr *)skb->data; \
-   struct sockaddr_in *v4 = (void *)__entry->saddr;\
+   struct sockaddr_in *v4 = (void *)entry_saddr;   \
\
v4->sin_family = AF_INET;   \
v4->sin_port = th->source;  \
v4->sin_addr.s_addr = ip_hdr(skb)->saddr;   \
-   v4 = (void *)__entry->daddr;\
+   v4 = (void *)entry_daddr;   \
v4->sin_family = AF_INET;   \
v4->sin_port = th->dest;\
v4->sin_addr.s_addr = ip_hdr(skb)->daddr;   \
@@ -318,29 +318,30 @@ TRACE_EVENT(tcp_probe,
 
 #if IS_ENABLED(CONFIG_IPV6)
 
-#define TP_STORE_ADDR_PORTS_SKB(__entry, skb)  \
+#define TP_STORE_ADDR_PORTS_SKB(skb, entry_saddr, entry_daddr) \
do {\
const struct iphdr *iph = ip_hdr(skb);  \
\
if (iph->version == 6) {\
const struct tcphdr *th = (const struct tcphdr 
*)skb->data; \
-   struct sockaddr_in6 *v6 = (void *)__entry->saddr; \
+   struct sockaddr_in6 *v6 = (void *)entry_saddr;  \
\
v6->sin6_family = AF_INET6; \
v6->sin6_port = th->source; \
v6->sin6_addr = ipv6_hdr(skb)->saddr;   \
-   v6 = (void *)__entry->daddr;\
+   v6 = (void *)entry_daddr;   \
v6->sin6_family = AF_INET6; \
v6->sin6_port = th->dest;   \
v6->sin6_addr = ipv6_hdr(skb)->daddr;   \
} else  \
-   TP_STORE_ADDR_PORTS_SKB_V4(__entry, skb);   \
+   TP_STORE_ADDR_PORTS_SKB_V4(skb, entry_saddr,\
+  entry_daddr); \
} while (0)
 
 #else
 
-#define TP_STORE_ADDR_PORTS_SKB(__entry, skb)  \
-   TP_STORE_ADDR_PORTS_SKB_V4(__entry, skb)
+#define TP_STORE_ADDR_PORTS_SKB(skb, entry_saddr, entry_daddr) \
+   TP_STORE_ADDR_PORTS_SKB_V4(skb, entry_saddr, entry_daddr)
 
 #endif
 
@@ -365,7 +366,7 @@ DECLARE_EVENT_CLASS(tcp_event_skb,
memset(__entry->saddr, 0, sizeof(struct sockaddr_in6));
memset(__entry->daddr, 0, sizeof(struct sockaddr_in6));
 
-   TP_STORE_ADDR_PORTS_SKB(__entry, skb);
+   TP_STORE_ADDR_PORTS_SKB(skb, __entry->saddr, __entry->daddr);
),
 
TP_printk("skbaddr=%p src=%pISpc dest=%pISpc",
-- 
2.37.3




[PATCH net-next 0/2] tcp: make trace of reset logic complete

2024-03-10 Thread Jason Xing
From: Jason Xing 

Before this, we miss some cases where the TCP layer could send rst but
we cannot trace it. So I decided to complete it :)

Jason Xing (2):
  trace: adjust TP_STORE_ADDR_PORTS_SKB() parameters
  trace: tcp: fully support trace_tcp_send_reset

 include/trace/events/tcp.h | 60 ++
 net/ipv4/tcp_ipv4.c|  4 +--
 net/ipv6/tcp_ipv6.c|  3 +-
 3 files changed, 52 insertions(+), 15 deletions(-)

-- 
2.37.3




[PATCH net-next 3/3] trace: use TP_STORE_ADDRS() macro in inet_sock_set_state()

2024-03-10 Thread Jason Xing
From: Jason Xing 

As the title said, use the macro directly like the patch[1] did
to avoid those duplications. No functional change.

[1]
commit 6a6b0b9914e7 ("tcp: Avoid preprocessor directives in tracepoint macro 
args")

Signed-off-by: Jason Xing 
---
 include/trace/events/sock.h | 17 ++---
 1 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/include/trace/events/sock.h b/include/trace/events/sock.h
index 4397f7bfa406..0d1c5ce4e6a6 100644
--- a/include/trace/events/sock.h
+++ b/include/trace/events/sock.h
@@ -160,7 +160,6 @@ TRACE_EVENT(inet_sock_set_state,
 
TP_fast_assign(
const struct inet_sock *inet = inet_sk(sk);
-   struct in6_addr *pin6;
__be32 *p32;
 
__entry->skaddr = sk;
@@ -178,20 +177,8 @@ TRACE_EVENT(inet_sock_set_state,
p32 = (__be32 *) __entry->daddr;
*p32 =  inet->inet_daddr;
 
-#if IS_ENABLED(CONFIG_IPV6)
-   if (sk->sk_family == AF_INET6) {
-   pin6 = (struct in6_addr *)__entry->saddr_v6;
-   *pin6 = sk->sk_v6_rcv_saddr;
-   pin6 = (struct in6_addr *)__entry->daddr_v6;
-   *pin6 = sk->sk_v6_daddr;
-   } else
-#endif
-   {
-   pin6 = (struct in6_addr *)__entry->saddr_v6;
-   ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
-   pin6 = (struct in6_addr *)__entry->daddr_v6;
-   ipv6_addr_set_v4mapped(inet->inet_daddr, pin6);
-   }
+   TP_STORE_ADDRS(__entry, inet->inet_saddr, inet->inet_daddr,
+  sk->sk_v6_rcv_saddr, sk->sk_v6_daddr);
),
 
TP_printk("family=%s protocol=%s sport=%hu dport=%hu saddr=%pI4 
daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c oldstate=%s newstate=%s",
-- 
2.37.3




[PATCH net-next 2/3] trace: use TP_STORE_ADDRS() macro in inet_sk_error_report()

2024-03-10 Thread Jason Xing
From: Jason Xing 

As the title said, use the macro directly like the patch[1] did
to avoid those duplications. No functional change.

[1]
commit 6a6b0b9914e7 ("tcp: Avoid preprocessor directives in tracepoint macro 
args")

Signed-off-by: Jason Xing 
---
 include/trace/events/sock.h | 18 +++---
 1 file changed, 3 insertions(+), 15 deletions(-)

diff --git a/include/trace/events/sock.h b/include/trace/events/sock.h
index fd206a6ab5b8..4397f7bfa406 100644
--- a/include/trace/events/sock.h
+++ b/include/trace/events/sock.h
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define family_names   \
EM(AF_INET) \
@@ -223,7 +224,6 @@ TRACE_EVENT(inet_sk_error_report,
 
TP_fast_assign(
const struct inet_sock *inet = inet_sk(sk);
-   struct in6_addr *pin6;
__be32 *p32;
 
__entry->error = sk->sk_err;
@@ -238,20 +238,8 @@ TRACE_EVENT(inet_sk_error_report,
p32 = (__be32 *) __entry->daddr;
*p32 =  inet->inet_daddr;
 
-#if IS_ENABLED(CONFIG_IPV6)
-   if (sk->sk_family == AF_INET6) {
-   pin6 = (struct in6_addr *)__entry->saddr_v6;
-   *pin6 = sk->sk_v6_rcv_saddr;
-   pin6 = (struct in6_addr *)__entry->daddr_v6;
-   *pin6 = sk->sk_v6_daddr;
-   } else
-#endif
-   {
-   pin6 = (struct in6_addr *)__entry->saddr_v6;
-   ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
-   pin6 = (struct in6_addr *)__entry->daddr_v6;
-   ipv6_addr_set_v4mapped(inet->inet_daddr, pin6);
-   }
+   TP_STORE_ADDRS(__entry, inet->inet_saddr, inet->inet_daddr,
+  sk->sk_v6_rcv_saddr, sk->sk_v6_daddr);
),
 
TP_printk("family=%s protocol=%s sport=%hu dport=%hu saddr=%pI4 
daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c error=%d",
-- 
2.37.3




[PATCH net-next 1/3] trace: move to TP_STORE_ADDRS related macro to net_probe_common.h

2024-03-10 Thread Jason Xing
From: Jason Xing 

Put the macro into another standalone file for better extension.
Some tracepoints can use this common part in the future.

Signed-off-by: Jason Xing 
---
 include/trace/events/net_probe_common.h | 29 +
 include/trace/events/tcp.h  | 29 -
 2 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/include/trace/events/net_probe_common.h 
b/include/trace/events/net_probe_common.h
index 3930119cab08..b1f9a4d3ee13 100644
--- a/include/trace/events/net_probe_common.h
+++ b/include/trace/events/net_probe_common.h
@@ -41,4 +41,33 @@
 
 #endif
 
+#define TP_STORE_V4MAPPED(__entry, saddr, daddr)   \
+   do {\
+   struct in6_addr *pin6;  \
+   \
+   pin6 = (struct in6_addr *)__entry->saddr_v6;\
+   ipv6_addr_set_v4mapped(saddr, pin6);\
+   pin6 = (struct in6_addr *)__entry->daddr_v6;\
+   ipv6_addr_set_v4mapped(daddr, pin6);\
+   } while (0)
+
+#if IS_ENABLED(CONFIG_IPV6)
+#define TP_STORE_ADDRS(__entry, saddr, daddr, saddr6, daddr6)  \
+   do {\
+   if (sk->sk_family == AF_INET6) {\
+   struct in6_addr *pin6;  \
+   \
+   pin6 = (struct in6_addr *)__entry->saddr_v6;\
+   *pin6 = saddr6; \
+   pin6 = (struct in6_addr *)__entry->daddr_v6;\
+   *pin6 = daddr6; \
+   } else {\
+   TP_STORE_V4MAPPED(__entry, saddr, daddr);   \
+   }   \
+   } while (0)
+#else
+#define TP_STORE_ADDRS(__entry, saddr, daddr, saddr6, daddr6)  \
+   TP_STORE_V4MAPPED(__entry, saddr, daddr)
+#endif
+
 #endif
diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h
index 699dafd204ea..3c08a0846c47 100644
--- a/include/trace/events/tcp.h
+++ b/include/trace/events/tcp.h
@@ -12,35 +12,6 @@
 #include 
 #include 
 
-#define TP_STORE_V4MAPPED(__entry, saddr, daddr)   \
-   do {\
-   struct in6_addr *pin6;  \
-   \
-   pin6 = (struct in6_addr *)__entry->saddr_v6;\
-   ipv6_addr_set_v4mapped(saddr, pin6);\
-   pin6 = (struct in6_addr *)__entry->daddr_v6;\
-   ipv6_addr_set_v4mapped(daddr, pin6);\
-   } while (0)
-
-#if IS_ENABLED(CONFIG_IPV6)
-#define TP_STORE_ADDRS(__entry, saddr, daddr, saddr6, daddr6)  \
-   do {\
-   if (sk->sk_family == AF_INET6) {\
-   struct in6_addr *pin6;  \
-   \
-   pin6 = (struct in6_addr *)__entry->saddr_v6;\
-   *pin6 = saddr6; \
-   pin6 = (struct in6_addr *)__entry->daddr_v6;\
-   *pin6 = daddr6; \
-   } else {\
-   TP_STORE_V4MAPPED(__entry, saddr, daddr);   \
-   }   \
-   } while (0)
-#else
-#define TP_STORE_ADDRS(__entry, saddr, daddr, saddr6, daddr6)  \
-   TP_STORE_V4MAPPED(__entry, saddr, daddr)
-#endif
-
 /*
  * tcp event with arguments sk and skb
  *
-- 
2.37.3




[PATCH net-next 0/3] trace: use TP_STORE_ADDRS macro

2024-03-10 Thread Jason Xing
From: Jason Xing 

Using the macro for other tracepoints use to be more concise.
No functional change.

Jason Xing (3):
  trace: move to TP_STORE_ADDRS related macro to net_probe_common.h
  trace: use TP_STORE_ADDRS() macro in inet_sk_error_report()
  trace: use TP_STORE_ADDRS() macro in inet_sock_set_state()

 include/trace/events/net_probe_common.h | 29 
 include/trace/events/sock.h | 35 -
 include/trace/events/tcp.h  | 29 
 3 files changed, 34 insertions(+), 59 deletions(-)

-- 
2.37.3