diff mbox series

[net-next,2/2] tcp: handle TCP_TIME_WAIT/TCP_NEW_SYN_RECV in tcp_set_state tracepoint

Message ID 1510237564-6013-2-git-send-email-laoar.shao@gmail.com
State Changes Requested, archived
Delegated to: David Miller
Headers show
Series [net-next,1/2] net/tcp: track all TCP/IP state transition in tcp_set_state | expand

Commit Message

Yafang Shao Nov. 9, 2017, 2:26 p.m. UTC
When TCP connetion in TCP_TIME_WAIT or TCP_NEW_SYN_RECV state, it can't
get the sport/dport/saddr/daddr from inet_sock.

trace_tcp_set_state may be called when the oldstate in these two states.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 include/trace/events/tcp.h | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

Comments

Eric Dumazet Nov. 9, 2017, 2:52 p.m. UTC | #1
On Thu, 2017-11-09 at 14:26 +0000, Yafang Shao wrote:
> When TCP connetion in TCP_TIME_WAIT or TCP_NEW_SYN_RECV state, it can't
> get the sport/dport/saddr/daddr from inet_sock.
> 
> trace_tcp_set_state may be called when the oldstate in these two states.
> 
> Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> ---
>  include/trace/events/tcp.h | 33 ++++++++++++++++++++++++++-------
>  1 file changed, 26 insertions(+), 7 deletions(-)
> 
> diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h
> index 07cccca..1982a71 100644
> --- a/include/trace/events/tcp.h
> +++ b/include/trace/events/tcp.h
> @@ -196,7 +196,6 @@
>  	),
>  
>  	TP_fast_assign(
> -		struct inet_sock *inet = inet_sk(sk);
>  		struct in6_addr *pin6;
>  		__be32 *p32;
>  
> @@ -204,14 +203,34 @@
>  		__entry->oldstate = oldstate;
>  		__entry->newstate = newstate;
>  
> -		__entry->sport = ntohs(inet->inet_sport);
> -		__entry->dport = ntohs(inet->inet_dport);
> +		if (oldstate == TCP_TIME_WAIT) {
> +			__entry->sport = ntohs(inet_twsk(sk)->tw_sport);
> +			__entry->dport = ntohs(inet_twsk(sk)->tw_dport);
>  
> -		p32 = (__be32 *) __entry->saddr;
> -		*p32 = inet->inet_saddr;
> +			p32 = (__be32 *) __entry->saddr;
> +			*p32 = inet_twsk(sk)->tw_rcv_saddr;
>  
> -		p32 = (__be32 *) __entry->daddr;
> -		*p32 =  inet->inet_daddr;
> +			p32 = (__be32 *) __entry->daddr;
> +			*p32 = inet_twsk(sk)->tw_daddr;
> +		} else if (oldstate == TCP_NEW_SYN_RECV) {
> +			__entry->sport = inet_rsk(inet_reqsk(sk))->ir_num;
> +			__entry->dport = ntohs(inet_rsk(inet_reqsk(sk))->ir_rmt_port);
> +
> +			p32 = (__be32 *) __entry->saddr;
> +			*p32 = inet_rsk(inet_reqsk(sk))->ir_loc_addr;
> +
> +			p32 = (__be32 *) __entry->daddr;
> +			*p32 = inet_rsk(inet_reqsk(sk))->ir_rmt_addr;
> +		} else {
> +			__entry->sport = ntohs(inet_sk(sk)->inet_sport);
> +			__entry->dport = ntohs(inet_sk(sk)->inet_dport);
> +
> +			p32 = (__be32 *) __entry->saddr;
> +			*p32 = inet_sk(sk)->inet_saddr;
> +
> +			p32 = (__be32 *) __entry->daddr;
> +			*p32 =  inet_sk(sk)->inet_daddr;
> +		}


Wow.


Since all three variants of sockets (full sockets, request sockets,
timewait sockets) are all hashed into ehash table these days, they all
have the fields at the same offset

For IPv4, that would be :

__sk_common.skc_daddr    (or inet_daddr)
__sk_common.skc_rcv_saddr (or inet_rcv_saddr )
__sk_common.skc_dport     (or inet_dport)
__sk_common.skc_num       (or inet_num)

Look at __inet_lookup_established() and INET_MATCH() : They deal with
the three variants, without having to look at sk_state.

If you were using the fields that are common to all sockets, no need to
add all this unnecessary complexity.
Eric Dumazet Nov. 9, 2017, 2:58 p.m. UTC | #2
On Thu, 2017-11-09 at 06:52 -0800, Eric Dumazet wrote:

> Wow.
> 
> 
> Since all three variants of sockets (full sockets, request sockets,
> timewait sockets) are all hashed into ehash table these days, they all
> have the fields at the same offset
> 
> For IPv4, that would be :
> 
> __sk_common.skc_daddr    (or inet_daddr)
> __sk_common.skc_rcv_saddr (or inet_rcv_saddr )
> __sk_common.skc_dport     (or inet_dport)
> __sk_common.skc_num       (or inet_num)
> 
> Look at __inet_lookup_established() and INET_MATCH() : They deal with
> the three variants, without having to look at sk_state.
> 
> If you were using the fields that are common to all sockets, no need to
> add all this unnecessary complexity.
> 

Not to mention that your patch took care of IPv4 only.

I can not say how sad I am that in 2017 IPv6 seems to be second class
citizen.
Yafang Shao Nov. 9, 2017, 3:11 p.m. UTC | #3
2017-11-09 22:58 GMT+08:00 Eric Dumazet <eric.dumazet@gmail.com>:
> On Thu, 2017-11-09 at 06:52 -0800, Eric Dumazet wrote:
>
>> Wow.
>>
>>
>> Since all three variants of sockets (full sockets, request sockets,
>> timewait sockets) are all hashed into ehash table these days, they all
>> have the fields at the same offset
>>
>> For IPv4, that would be :
>>
>> __sk_common.skc_daddr    (or inet_daddr)
>> __sk_common.skc_rcv_saddr (or inet_rcv_saddr )
>> __sk_common.skc_dport     (or inet_dport)
>> __sk_common.skc_num       (or inet_num)
>>
>> Look at __inet_lookup_established() and INET_MATCH() : They deal with
>> the three variants, without having to look at sk_state.
>>
>> If you were using the fields that are common to all sockets, no need to
>> add all this unnecessary complexity.
>>
>
> Not to mention that your patch took care of IPv4 only.
>
> I can not say how sad I am that in 2017 IPv6 seems to be second class
> citizen.
>

I'm also very sad that I'm still using IPv4 in 2017 : (

Okay then another issue,
shoule we reduce the complexity in  the function tcp4_seq_show() ?

Thanks
Yafang
Eric Dumazet Nov. 9, 2017, 3:18 p.m. UTC | #4
On Thu, 2017-11-09 at 23:11 +0800, Yafang Shao wrote:

> I'm also very sad that I'm still using IPv4 in 2017 : (
> 
> Okay then another issue,
> shoule we reduce the complexity in  the function tcp4_seq_show() ?

This is irrelevant really.

I do not see how tcp4_seq_show() could avoid testing sk_state.
kernel test robot Nov. 12, 2017, 2:15 p.m. UTC | #5
Hi Yafang,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Yafang-Shao/net-tcp-track-all-TCP-IP-state-transition-in-tcp_set_state/20171112-203643
config: i386-randconfig-i1-201746 (attached as .config)
compiler: gcc-6 (Debian 6.4.0-9) 6.4.0 20171026
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   In file included from include/trace/define_trace.h:96:0,
                    from include/trace/events/tcp.h:318,
                    from net/core/net-traces.c:35:
   include/trace/events/tcp.h: In function 'trace_event_raw_event_tcp_set_state':
>> include/trace/events/tcp.h:245:27: error: 'inet' undeclared (first use in this function)
       ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
                              ^
   include/trace/trace_events.h:719:4: note: in definition of macro 'DECLARE_EVENT_CLASS'
     { assign; }       \
       ^~~~~~
   include/trace/trace_events.h:78:9: note: in expansion of macro 'PARAMS'
            PARAMS(assign),         \
            ^~~~~~
   include/trace/events/tcp.h:180:1: note: in expansion of macro 'TRACE_EVENT'
    TRACE_EVENT(tcp_set_state,
    ^~~~~~~~~~~
   include/trace/events/tcp.h:198:2: note: in expansion of macro 'TP_fast_assign'
     TP_fast_assign(
     ^~~~~~~~~~~~~~
   include/trace/events/tcp.h:245:27: note: each undeclared identifier is reported only once for each function it appears in
       ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
                              ^
   include/trace/trace_events.h:719:4: note: in definition of macro 'DECLARE_EVENT_CLASS'
     { assign; }       \
       ^~~~~~
   include/trace/trace_events.h:78:9: note: in expansion of macro 'PARAMS'
            PARAMS(assign),         \
            ^~~~~~
   include/trace/events/tcp.h:180:1: note: in expansion of macro 'TRACE_EVENT'
    TRACE_EVENT(tcp_set_state,
    ^~~~~~~~~~~
   include/trace/events/tcp.h:198:2: note: in expansion of macro 'TP_fast_assign'
     TP_fast_assign(
     ^~~~~~~~~~~~~~
   In file included from include/trace/define_trace.h:97:0,
                    from include/trace/events/tcp.h:318,
                    from net/core/net-traces.c:35:
   include/trace/events/tcp.h: In function 'perf_trace_tcp_set_state':
>> include/trace/events/tcp.h:245:27: error: 'inet' undeclared (first use in this function)
       ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
                              ^
   include/trace/perf.h:66:4: note: in definition of macro 'DECLARE_EVENT_CLASS'
     { assign; }       \
       ^~~~~~
   include/trace/trace_events.h:78:9: note: in expansion of macro 'PARAMS'
            PARAMS(assign),         \
            ^~~~~~
   include/trace/events/tcp.h:180:1: note: in expansion of macro 'TRACE_EVENT'
    TRACE_EVENT(tcp_set_state,
    ^~~~~~~~~~~
   include/trace/events/tcp.h:198:2: note: in expansion of macro 'TP_fast_assign'
     TP_fast_assign(
     ^~~~~~~~~~~~~~

vim +/inet +245 include/trace/events/tcp.h

e8fce239 Song Liu    2017-10-23  181  
e8fce239 Song Liu    2017-10-23  182  	TP_PROTO(const struct sock *sk, const int oldstate, const int newstate),
e8fce239 Song Liu    2017-10-23  183  
e8fce239 Song Liu    2017-10-23  184  	TP_ARGS(sk, oldstate, newstate),
e8fce239 Song Liu    2017-10-23  185  
e8fce239 Song Liu    2017-10-23  186  	TP_STRUCT__entry(
e8fce239 Song Liu    2017-10-23  187  		__field(const void *, skaddr)
e8fce239 Song Liu    2017-10-23  188  		__field(int, oldstate)
e8fce239 Song Liu    2017-10-23  189  		__field(int, newstate)
e8fce239 Song Liu    2017-10-23  190  		__field(__u16, sport)
e8fce239 Song Liu    2017-10-23  191  		__field(__u16, dport)
e8fce239 Song Liu    2017-10-23  192  		__array(__u8, saddr, 4)
e8fce239 Song Liu    2017-10-23  193  		__array(__u8, daddr, 4)
e8fce239 Song Liu    2017-10-23  194  		__array(__u8, saddr_v6, 16)
e8fce239 Song Liu    2017-10-23  195  		__array(__u8, daddr_v6, 16)
e8fce239 Song Liu    2017-10-23  196  	),
e8fce239 Song Liu    2017-10-23  197  
e8fce239 Song Liu    2017-10-23  198  	TP_fast_assign(
e8fce239 Song Liu    2017-10-23  199  		struct in6_addr *pin6;
e8fce239 Song Liu    2017-10-23  200  		__be32 *p32;
e8fce239 Song Liu    2017-10-23  201  
e8fce239 Song Liu    2017-10-23  202  		__entry->skaddr = sk;
e8fce239 Song Liu    2017-10-23  203  		__entry->oldstate = oldstate;
e8fce239 Song Liu    2017-10-23  204  		__entry->newstate = newstate;
e8fce239 Song Liu    2017-10-23  205  
e346c952 Yafang Shao 2017-11-09  206  		if (oldstate == TCP_TIME_WAIT) {
e346c952 Yafang Shao 2017-11-09  207  			__entry->sport = ntohs(inet_twsk(sk)->tw_sport);
e346c952 Yafang Shao 2017-11-09  208  			__entry->dport = ntohs(inet_twsk(sk)->tw_dport);
e8fce239 Song Liu    2017-10-23  209  
e8fce239 Song Liu    2017-10-23  210  			p32 = (__be32 *) __entry->saddr;
e346c952 Yafang Shao 2017-11-09  211  			*p32 = inet_twsk(sk)->tw_rcv_saddr;
e8fce239 Song Liu    2017-10-23  212  
e8fce239 Song Liu    2017-10-23  213  			p32 = (__be32 *) __entry->daddr;
e346c952 Yafang Shao 2017-11-09  214  			*p32 = inet_twsk(sk)->tw_daddr;
e346c952 Yafang Shao 2017-11-09  215  		} else if (oldstate == TCP_NEW_SYN_RECV) {
e346c952 Yafang Shao 2017-11-09  216  			__entry->sport = inet_rsk(inet_reqsk(sk))->ir_num;
e346c952 Yafang Shao 2017-11-09  217  			__entry->dport = ntohs(inet_rsk(inet_reqsk(sk))->ir_rmt_port);
e346c952 Yafang Shao 2017-11-09  218  
e346c952 Yafang Shao 2017-11-09  219  			p32 = (__be32 *) __entry->saddr;
e346c952 Yafang Shao 2017-11-09  220  			*p32 = inet_rsk(inet_reqsk(sk))->ir_loc_addr;
e346c952 Yafang Shao 2017-11-09  221  
e346c952 Yafang Shao 2017-11-09  222  			p32 = (__be32 *) __entry->daddr;
e346c952 Yafang Shao 2017-11-09  223  			*p32 = inet_rsk(inet_reqsk(sk))->ir_rmt_addr;
e346c952 Yafang Shao 2017-11-09  224  		} else {
e346c952 Yafang Shao 2017-11-09  225  			__entry->sport = ntohs(inet_sk(sk)->inet_sport);
e346c952 Yafang Shao 2017-11-09  226  			__entry->dport = ntohs(inet_sk(sk)->inet_dport);
e346c952 Yafang Shao 2017-11-09  227  
e346c952 Yafang Shao 2017-11-09  228  			p32 = (__be32 *) __entry->saddr;
e346c952 Yafang Shao 2017-11-09  229  			*p32 = inet_sk(sk)->inet_saddr;
e346c952 Yafang Shao 2017-11-09  230  
e346c952 Yafang Shao 2017-11-09  231  			p32 = (__be32 *) __entry->daddr;
e346c952 Yafang Shao 2017-11-09  232  			*p32 =  inet_sk(sk)->inet_daddr;
e346c952 Yafang Shao 2017-11-09  233  		}
e8fce239 Song Liu    2017-10-23  234  
e8fce239 Song Liu    2017-10-23  235  #if IS_ENABLED(CONFIG_IPV6)
e8fce239 Song Liu    2017-10-23  236  		if (sk->sk_family == AF_INET6) {
e8fce239 Song Liu    2017-10-23  237  			pin6 = (struct in6_addr *)__entry->saddr_v6;
e8fce239 Song Liu    2017-10-23  238  			*pin6 = sk->sk_v6_rcv_saddr;
e8fce239 Song Liu    2017-10-23  239  			pin6 = (struct in6_addr *)__entry->daddr_v6;
e8fce239 Song Liu    2017-10-23  240  			*pin6 = sk->sk_v6_daddr;
e8fce239 Song Liu    2017-10-23  241  		} else
e8fce239 Song Liu    2017-10-23  242  #endif
e8fce239 Song Liu    2017-10-23  243  		{
e8fce239 Song Liu    2017-10-23  244  			pin6 = (struct in6_addr *)__entry->saddr_v6;
e8fce239 Song Liu    2017-10-23 @245  			ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
e8fce239 Song Liu    2017-10-23  246  			pin6 = (struct in6_addr *)__entry->daddr_v6;
e8fce239 Song Liu    2017-10-23  247  			ipv6_addr_set_v4mapped(inet->inet_daddr, pin6);
e8fce239 Song Liu    2017-10-23  248  		}
e8fce239 Song Liu    2017-10-23  249  	),
e8fce239 Song Liu    2017-10-23  250  
e8fce239 Song Liu    2017-10-23  251  	TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c oldstate=%s newstate=%s",
e8fce239 Song Liu    2017-10-23  252  		  __entry->sport, __entry->dport,
e8fce239 Song Liu    2017-10-23  253  		  __entry->saddr, __entry->daddr,
e8fce239 Song Liu    2017-10-23  254  		  __entry->saddr_v6, __entry->daddr_v6,
e8fce239 Song Liu    2017-10-23  255  		  show_tcp_state_name(__entry->oldstate),
e8fce239 Song Liu    2017-10-23  256  		  show_tcp_state_name(__entry->newstate))
e8fce239 Song Liu    2017-10-23  257  );
e8fce239 Song Liu    2017-10-23  258  
cf34ce3d Song Liu    2017-10-30  259  TRACE_EVENT(tcp_retransmit_synack,
cf34ce3d Song Liu    2017-10-30  260  
cf34ce3d Song Liu    2017-10-30  261  	TP_PROTO(const struct sock *sk, const struct request_sock *req),
cf34ce3d Song Liu    2017-10-30  262  
cf34ce3d Song Liu    2017-10-30  263  	TP_ARGS(sk, req),
cf34ce3d Song Liu    2017-10-30  264  
cf34ce3d Song Liu    2017-10-30  265  	TP_STRUCT__entry(
cf34ce3d Song Liu    2017-10-30  266  		__field(const void *, skaddr)
cf34ce3d Song Liu    2017-10-30  267  		__field(const void *, req)
cf34ce3d Song Liu    2017-10-30  268  		__field(__u16, sport)
cf34ce3d Song Liu    2017-10-30  269  		__field(__u16, dport)
cf34ce3d Song Liu    2017-10-30  270  		__array(__u8, saddr, 4)
cf34ce3d Song Liu    2017-10-30  271  		__array(__u8, daddr, 4)
cf34ce3d Song Liu    2017-10-30  272  		__array(__u8, saddr_v6, 16)
cf34ce3d Song Liu    2017-10-30  273  		__array(__u8, daddr_v6, 16)
cf34ce3d Song Liu    2017-10-30  274  	),
cf34ce3d Song Liu    2017-10-30  275  
cf34ce3d Song Liu    2017-10-30  276  	TP_fast_assign(
cf34ce3d Song Liu    2017-10-30  277  		struct inet_request_sock *ireq = inet_rsk(req);
cf34ce3d Song Liu    2017-10-30  278  		struct in6_addr *pin6;
cf34ce3d Song Liu    2017-10-30  279  		__be32 *p32;
cf34ce3d Song Liu    2017-10-30  280  
cf34ce3d Song Liu    2017-10-30  281  		__entry->skaddr = sk;
cf34ce3d Song Liu    2017-10-30  282  		__entry->req = req;
cf34ce3d Song Liu    2017-10-30  283  
cf34ce3d Song Liu    2017-10-30  284  		__entry->sport = ireq->ir_num;
cf34ce3d Song Liu    2017-10-30  285  		__entry->dport = ntohs(ireq->ir_rmt_port);
cf34ce3d Song Liu    2017-10-30  286  
cf34ce3d Song Liu    2017-10-30  287  		p32 = (__be32 *) __entry->saddr;
cf34ce3d Song Liu    2017-10-30  288  		*p32 = ireq->ir_loc_addr;
cf34ce3d Song Liu    2017-10-30  289  
cf34ce3d Song Liu    2017-10-30  290  		p32 = (__be32 *) __entry->daddr;
cf34ce3d Song Liu    2017-10-30  291  		*p32 = ireq->ir_rmt_addr;
cf34ce3d Song Liu    2017-10-30  292  
cf34ce3d Song Liu    2017-10-30  293  #if IS_ENABLED(CONFIG_IPV6)
cf34ce3d Song Liu    2017-10-30  294  		if (sk->sk_family == AF_INET6) {
cf34ce3d Song Liu    2017-10-30  295  			pin6 = (struct in6_addr *)__entry->saddr_v6;
cf34ce3d Song Liu    2017-10-30  296  			*pin6 = ireq->ir_v6_loc_addr;
cf34ce3d Song Liu    2017-10-30  297  			pin6 = (struct in6_addr *)__entry->daddr_v6;
cf34ce3d Song Liu    2017-10-30  298  			*pin6 = ireq->ir_v6_rmt_addr;
cf34ce3d Song Liu    2017-10-30  299  		} else
cf34ce3d Song Liu    2017-10-30  300  #endif
cf34ce3d Song Liu    2017-10-30  301  		{
cf34ce3d Song Liu    2017-10-30  302  			pin6 = (struct in6_addr *)__entry->saddr_v6;
cf34ce3d Song Liu    2017-10-30  303  			ipv6_addr_set_v4mapped(ireq->ir_loc_addr, pin6);
cf34ce3d Song Liu    2017-10-30  304  			pin6 = (struct in6_addr *)__entry->daddr_v6;
cf34ce3d Song Liu    2017-10-30  305  			ipv6_addr_set_v4mapped(ireq->ir_rmt_addr, pin6);
cf34ce3d Song Liu    2017-10-30  306  		}
cf34ce3d Song Liu    2017-10-30  307  	),
cf34ce3d Song Liu    2017-10-30  308  
cf34ce3d Song Liu    2017-10-30  309  	TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c",
cf34ce3d Song Liu    2017-10-30  310  		  __entry->sport, __entry->dport,
cf34ce3d Song Liu    2017-10-30  311  		  __entry->saddr, __entry->daddr,
cf34ce3d Song Liu    2017-10-30  312  		  __entry->saddr_v6, __entry->daddr_v6)
cf34ce3d Song Liu    2017-10-30  313  );
cf34ce3d Song Liu    2017-10-30  314  
e086101b Cong Wang   2017-10-13  315  #endif /* _TRACE_TCP_H */
e086101b Cong Wang   2017-10-13  316  
e086101b Cong Wang   2017-10-13  317  /* This part must be outside protection */
e086101b Cong Wang   2017-10-13 @318  #include <trace/define_trace.h>

:::::: The code at line 245 was first introduced by commit
:::::: e8fce23946b7e7eadf25ad78d8207c22903dfe27 tcp: add tracepoint trace_tcp_set_state()

:::::: TO: Song Liu <songliubraving@fb.com>
:::::: CC: David S. Miller <davem@davemloft.net>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
kernel test robot Nov. 12, 2017, 3:40 p.m. UTC | #6
Hi Yafang,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Yafang-Shao/net-tcp-track-all-TCP-IP-state-transition-in-tcp_set_state/20171112-203643
config: mips-malta_kvm_defconfig (attached as .config)
compiler: mipsel-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=mips 

All errors (new ones prefixed by >>):

   In file included from include/trace/define_trace.h:96:0,
                    from include/trace/events/tcp.h:318,
                    from net//core/net-traces.c:35:
   include/trace/events/tcp.h: In function 'trace_event_raw_event_tcp_set_state':
>> include/trace/events/tcp.h:245:27: error: 'inet' undeclared (first use in this function); did you mean 'net'?
       ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
                              ^
   include/trace/trace_events.h:719:4: note: in definition of macro 'DECLARE_EVENT_CLASS'
     { assign; }       \
       ^~~~~~
   include/trace/trace_events.h:78:9: note: in expansion of macro 'PARAMS'
            PARAMS(assign),         \
            ^~~~~~
   include/trace/events/tcp.h:180:1: note: in expansion of macro 'TRACE_EVENT'
    TRACE_EVENT(tcp_set_state,
    ^~~~~~~~~~~
   include/trace/events/tcp.h:198:2: note: in expansion of macro 'TP_fast_assign'
     TP_fast_assign(
     ^~~~~~~~~~~~~~
   include/trace/events/tcp.h:245:27: note: each undeclared identifier is reported only once for each function it appears in
       ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
                              ^
   include/trace/trace_events.h:719:4: note: in definition of macro 'DECLARE_EVENT_CLASS'
     { assign; }       \
       ^~~~~~
   include/trace/trace_events.h:78:9: note: in expansion of macro 'PARAMS'
            PARAMS(assign),         \
            ^~~~~~
   include/trace/events/tcp.h:180:1: note: in expansion of macro 'TRACE_EVENT'
    TRACE_EVENT(tcp_set_state,
    ^~~~~~~~~~~
   include/trace/events/tcp.h:198:2: note: in expansion of macro 'TP_fast_assign'
     TP_fast_assign(
     ^~~~~~~~~~~~~~
   In file included from include/trace/define_trace.h:97:0,
                    from include/trace/events/tcp.h:318,
                    from net//core/net-traces.c:35:
   include/trace/events/tcp.h: In function 'perf_trace_tcp_set_state':
>> include/trace/events/tcp.h:245:27: error: 'inet' undeclared (first use in this function); did you mean 'net'?
       ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
                              ^
   include/trace/perf.h:66:4: note: in definition of macro 'DECLARE_EVENT_CLASS'
     { assign; }       \
       ^~~~~~
   include/trace/trace_events.h:78:9: note: in expansion of macro 'PARAMS'
            PARAMS(assign),         \
            ^~~~~~
   include/trace/events/tcp.h:180:1: note: in expansion of macro 'TRACE_EVENT'
    TRACE_EVENT(tcp_set_state,
    ^~~~~~~~~~~
   include/trace/events/tcp.h:198:2: note: in expansion of macro 'TP_fast_assign'
     TP_fast_assign(
     ^~~~~~~~~~~~~~

vim +245 include/trace/events/tcp.h

e8fce239 Song Liu    2017-10-23  181  
e8fce239 Song Liu    2017-10-23  182  	TP_PROTO(const struct sock *sk, const int oldstate, const int newstate),
e8fce239 Song Liu    2017-10-23  183  
e8fce239 Song Liu    2017-10-23  184  	TP_ARGS(sk, oldstate, newstate),
e8fce239 Song Liu    2017-10-23  185  
e8fce239 Song Liu    2017-10-23  186  	TP_STRUCT__entry(
e8fce239 Song Liu    2017-10-23  187  		__field(const void *, skaddr)
e8fce239 Song Liu    2017-10-23  188  		__field(int, oldstate)
e8fce239 Song Liu    2017-10-23  189  		__field(int, newstate)
e8fce239 Song Liu    2017-10-23  190  		__field(__u16, sport)
e8fce239 Song Liu    2017-10-23  191  		__field(__u16, dport)
e8fce239 Song Liu    2017-10-23  192  		__array(__u8, saddr, 4)
e8fce239 Song Liu    2017-10-23  193  		__array(__u8, daddr, 4)
e8fce239 Song Liu    2017-10-23  194  		__array(__u8, saddr_v6, 16)
e8fce239 Song Liu    2017-10-23  195  		__array(__u8, daddr_v6, 16)
e8fce239 Song Liu    2017-10-23  196  	),
e8fce239 Song Liu    2017-10-23  197  
e8fce239 Song Liu    2017-10-23  198  	TP_fast_assign(
e8fce239 Song Liu    2017-10-23  199  		struct in6_addr *pin6;
e8fce239 Song Liu    2017-10-23  200  		__be32 *p32;
e8fce239 Song Liu    2017-10-23  201  
e8fce239 Song Liu    2017-10-23  202  		__entry->skaddr = sk;
e8fce239 Song Liu    2017-10-23  203  		__entry->oldstate = oldstate;
e8fce239 Song Liu    2017-10-23  204  		__entry->newstate = newstate;
e8fce239 Song Liu    2017-10-23  205  
e346c952 Yafang Shao 2017-11-09  206  		if (oldstate == TCP_TIME_WAIT) {
e346c952 Yafang Shao 2017-11-09  207  			__entry->sport = ntohs(inet_twsk(sk)->tw_sport);
e346c952 Yafang Shao 2017-11-09  208  			__entry->dport = ntohs(inet_twsk(sk)->tw_dport);
e8fce239 Song Liu    2017-10-23  209  
e8fce239 Song Liu    2017-10-23  210  			p32 = (__be32 *) __entry->saddr;
e346c952 Yafang Shao 2017-11-09  211  			*p32 = inet_twsk(sk)->tw_rcv_saddr;
e8fce239 Song Liu    2017-10-23  212  
e8fce239 Song Liu    2017-10-23  213  			p32 = (__be32 *) __entry->daddr;
e346c952 Yafang Shao 2017-11-09  214  			*p32 = inet_twsk(sk)->tw_daddr;
e346c952 Yafang Shao 2017-11-09  215  		} else if (oldstate == TCP_NEW_SYN_RECV) {
e346c952 Yafang Shao 2017-11-09  216  			__entry->sport = inet_rsk(inet_reqsk(sk))->ir_num;
e346c952 Yafang Shao 2017-11-09  217  			__entry->dport = ntohs(inet_rsk(inet_reqsk(sk))->ir_rmt_port);
e346c952 Yafang Shao 2017-11-09  218  
e346c952 Yafang Shao 2017-11-09  219  			p32 = (__be32 *) __entry->saddr;
e346c952 Yafang Shao 2017-11-09  220  			*p32 = inet_rsk(inet_reqsk(sk))->ir_loc_addr;
e346c952 Yafang Shao 2017-11-09  221  
e346c952 Yafang Shao 2017-11-09  222  			p32 = (__be32 *) __entry->daddr;
e346c952 Yafang Shao 2017-11-09  223  			*p32 = inet_rsk(inet_reqsk(sk))->ir_rmt_addr;
e346c952 Yafang Shao 2017-11-09  224  		} else {
e346c952 Yafang Shao 2017-11-09  225  			__entry->sport = ntohs(inet_sk(sk)->inet_sport);
e346c952 Yafang Shao 2017-11-09  226  			__entry->dport = ntohs(inet_sk(sk)->inet_dport);
e346c952 Yafang Shao 2017-11-09  227  
e346c952 Yafang Shao 2017-11-09  228  			p32 = (__be32 *) __entry->saddr;
e346c952 Yafang Shao 2017-11-09  229  			*p32 = inet_sk(sk)->inet_saddr;
e346c952 Yafang Shao 2017-11-09  230  
e346c952 Yafang Shao 2017-11-09  231  			p32 = (__be32 *) __entry->daddr;
e346c952 Yafang Shao 2017-11-09  232  			*p32 =  inet_sk(sk)->inet_daddr;
e346c952 Yafang Shao 2017-11-09  233  		}
e8fce239 Song Liu    2017-10-23  234  
e8fce239 Song Liu    2017-10-23  235  #if IS_ENABLED(CONFIG_IPV6)
e8fce239 Song Liu    2017-10-23  236  		if (sk->sk_family == AF_INET6) {
e8fce239 Song Liu    2017-10-23  237  			pin6 = (struct in6_addr *)__entry->saddr_v6;
e8fce239 Song Liu    2017-10-23  238  			*pin6 = sk->sk_v6_rcv_saddr;
e8fce239 Song Liu    2017-10-23  239  			pin6 = (struct in6_addr *)__entry->daddr_v6;
e8fce239 Song Liu    2017-10-23  240  			*pin6 = sk->sk_v6_daddr;
e8fce239 Song Liu    2017-10-23  241  		} else
e8fce239 Song Liu    2017-10-23  242  #endif
e8fce239 Song Liu    2017-10-23  243  		{
e8fce239 Song Liu    2017-10-23  244  			pin6 = (struct in6_addr *)__entry->saddr_v6;
e8fce239 Song Liu    2017-10-23 @245  			ipv6_addr_set_v4mapped(inet->inet_saddr, pin6);
e8fce239 Song Liu    2017-10-23  246  			pin6 = (struct in6_addr *)__entry->daddr_v6;
e8fce239 Song Liu    2017-10-23  247  			ipv6_addr_set_v4mapped(inet->inet_daddr, pin6);
e8fce239 Song Liu    2017-10-23  248  		}
e8fce239 Song Liu    2017-10-23  249  	),
e8fce239 Song Liu    2017-10-23  250  
e8fce239 Song Liu    2017-10-23  251  	TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c oldstate=%s newstate=%s",
e8fce239 Song Liu    2017-10-23  252  		  __entry->sport, __entry->dport,
e8fce239 Song Liu    2017-10-23  253  		  __entry->saddr, __entry->daddr,
e8fce239 Song Liu    2017-10-23  254  		  __entry->saddr_v6, __entry->daddr_v6,
e8fce239 Song Liu    2017-10-23  255  		  show_tcp_state_name(__entry->oldstate),
e8fce239 Song Liu    2017-10-23  256  		  show_tcp_state_name(__entry->newstate))
e8fce239 Song Liu    2017-10-23  257  );
e8fce239 Song Liu    2017-10-23  258  
cf34ce3d Song Liu    2017-10-30  259  TRACE_EVENT(tcp_retransmit_synack,
cf34ce3d Song Liu    2017-10-30  260  
cf34ce3d Song Liu    2017-10-30  261  	TP_PROTO(const struct sock *sk, const struct request_sock *req),
cf34ce3d Song Liu    2017-10-30  262  
cf34ce3d Song Liu    2017-10-30  263  	TP_ARGS(sk, req),
cf34ce3d Song Liu    2017-10-30  264  
cf34ce3d Song Liu    2017-10-30  265  	TP_STRUCT__entry(
cf34ce3d Song Liu    2017-10-30  266  		__field(const void *, skaddr)
cf34ce3d Song Liu    2017-10-30  267  		__field(const void *, req)
cf34ce3d Song Liu    2017-10-30  268  		__field(__u16, sport)
cf34ce3d Song Liu    2017-10-30  269  		__field(__u16, dport)
cf34ce3d Song Liu    2017-10-30  270  		__array(__u8, saddr, 4)
cf34ce3d Song Liu    2017-10-30  271  		__array(__u8, daddr, 4)
cf34ce3d Song Liu    2017-10-30  272  		__array(__u8, saddr_v6, 16)
cf34ce3d Song Liu    2017-10-30  273  		__array(__u8, daddr_v6, 16)
cf34ce3d Song Liu    2017-10-30  274  	),
cf34ce3d Song Liu    2017-10-30  275  
cf34ce3d Song Liu    2017-10-30  276  	TP_fast_assign(
cf34ce3d Song Liu    2017-10-30  277  		struct inet_request_sock *ireq = inet_rsk(req);
cf34ce3d Song Liu    2017-10-30  278  		struct in6_addr *pin6;
cf34ce3d Song Liu    2017-10-30  279  		__be32 *p32;
cf34ce3d Song Liu    2017-10-30  280  
cf34ce3d Song Liu    2017-10-30  281  		__entry->skaddr = sk;
cf34ce3d Song Liu    2017-10-30  282  		__entry->req = req;
cf34ce3d Song Liu    2017-10-30  283  
cf34ce3d Song Liu    2017-10-30  284  		__entry->sport = ireq->ir_num;
cf34ce3d Song Liu    2017-10-30  285  		__entry->dport = ntohs(ireq->ir_rmt_port);
cf34ce3d Song Liu    2017-10-30  286  
cf34ce3d Song Liu    2017-10-30  287  		p32 = (__be32 *) __entry->saddr;
cf34ce3d Song Liu    2017-10-30  288  		*p32 = ireq->ir_loc_addr;
cf34ce3d Song Liu    2017-10-30  289  
cf34ce3d Song Liu    2017-10-30  290  		p32 = (__be32 *) __entry->daddr;
cf34ce3d Song Liu    2017-10-30  291  		*p32 = ireq->ir_rmt_addr;
cf34ce3d Song Liu    2017-10-30  292  
cf34ce3d Song Liu    2017-10-30  293  #if IS_ENABLED(CONFIG_IPV6)
cf34ce3d Song Liu    2017-10-30  294  		if (sk->sk_family == AF_INET6) {
cf34ce3d Song Liu    2017-10-30  295  			pin6 = (struct in6_addr *)__entry->saddr_v6;
cf34ce3d Song Liu    2017-10-30  296  			*pin6 = ireq->ir_v6_loc_addr;
cf34ce3d Song Liu    2017-10-30  297  			pin6 = (struct in6_addr *)__entry->daddr_v6;
cf34ce3d Song Liu    2017-10-30  298  			*pin6 = ireq->ir_v6_rmt_addr;
cf34ce3d Song Liu    2017-10-30  299  		} else
cf34ce3d Song Liu    2017-10-30  300  #endif
cf34ce3d Song Liu    2017-10-30  301  		{
cf34ce3d Song Liu    2017-10-30  302  			pin6 = (struct in6_addr *)__entry->saddr_v6;
cf34ce3d Song Liu    2017-10-30  303  			ipv6_addr_set_v4mapped(ireq->ir_loc_addr, pin6);
cf34ce3d Song Liu    2017-10-30  304  			pin6 = (struct in6_addr *)__entry->daddr_v6;
cf34ce3d Song Liu    2017-10-30  305  			ipv6_addr_set_v4mapped(ireq->ir_rmt_addr, pin6);
cf34ce3d Song Liu    2017-10-30  306  		}
cf34ce3d Song Liu    2017-10-30  307  	),
cf34ce3d Song Liu    2017-10-30  308  
cf34ce3d Song Liu    2017-10-30  309  	TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c",
cf34ce3d Song Liu    2017-10-30  310  		  __entry->sport, __entry->dport,
cf34ce3d Song Liu    2017-10-30  311  		  __entry->saddr, __entry->daddr,
cf34ce3d Song Liu    2017-10-30  312  		  __entry->saddr_v6, __entry->daddr_v6)
cf34ce3d Song Liu    2017-10-30  313  );
cf34ce3d Song Liu    2017-10-30  314  
e086101b Cong Wang   2017-10-13  315  #endif /* _TRACE_TCP_H */
e086101b Cong Wang   2017-10-13  316  
e086101b Cong Wang   2017-10-13  317  /* This part must be outside protection */
e086101b Cong Wang   2017-10-13 @318  #include <trace/define_trace.h>

:::::: The code at line 245 was first introduced by commit
:::::: e8fce23946b7e7eadf25ad78d8207c22903dfe27 tcp: add tracepoint trace_tcp_set_state()

:::::: TO: Song Liu <songliubraving@fb.com>
:::::: CC: David S. Miller <davem@davemloft.net>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox series

Patch

diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h
index 07cccca..1982a71 100644
--- a/include/trace/events/tcp.h
+++ b/include/trace/events/tcp.h
@@ -196,7 +196,6 @@ 
 	),
 
 	TP_fast_assign(
-		struct inet_sock *inet = inet_sk(sk);
 		struct in6_addr *pin6;
 		__be32 *p32;
 
@@ -204,14 +203,34 @@ 
 		__entry->oldstate = oldstate;
 		__entry->newstate = newstate;
 
-		__entry->sport = ntohs(inet->inet_sport);
-		__entry->dport = ntohs(inet->inet_dport);
+		if (oldstate == TCP_TIME_WAIT) {
+			__entry->sport = ntohs(inet_twsk(sk)->tw_sport);
+			__entry->dport = ntohs(inet_twsk(sk)->tw_dport);
 
-		p32 = (__be32 *) __entry->saddr;
-		*p32 = inet->inet_saddr;
+			p32 = (__be32 *) __entry->saddr;
+			*p32 = inet_twsk(sk)->tw_rcv_saddr;
 
-		p32 = (__be32 *) __entry->daddr;
-		*p32 =  inet->inet_daddr;
+			p32 = (__be32 *) __entry->daddr;
+			*p32 = inet_twsk(sk)->tw_daddr;
+		} else if (oldstate == TCP_NEW_SYN_RECV) {
+			__entry->sport = inet_rsk(inet_reqsk(sk))->ir_num;
+			__entry->dport = ntohs(inet_rsk(inet_reqsk(sk))->ir_rmt_port);
+
+			p32 = (__be32 *) __entry->saddr;
+			*p32 = inet_rsk(inet_reqsk(sk))->ir_loc_addr;
+
+			p32 = (__be32 *) __entry->daddr;
+			*p32 = inet_rsk(inet_reqsk(sk))->ir_rmt_addr;
+		} else {
+			__entry->sport = ntohs(inet_sk(sk)->inet_sport);
+			__entry->dport = ntohs(inet_sk(sk)->inet_dport);
+
+			p32 = (__be32 *) __entry->saddr;
+			*p32 = inet_sk(sk)->inet_saddr;
+
+			p32 = (__be32 *) __entry->daddr;
+			*p32 =  inet_sk(sk)->inet_daddr;
+		}
 
 #if IS_ENABLED(CONFIG_IPV6)
 		if (sk->sk_family == AF_INET6) {