(root)/
strace-6.5/
src/
netlink_inet_diag.c
       1  /*
       2   * Copyright (c) 2016 Fabien Siron <fabien.siron@epita.fr>
       3   * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
       4   * Copyright (c) 2017-2022 The strace developers.
       5   * All rights reserved.
       6   *
       7   * SPDX-License-Identifier: LGPL-2.1-or-later
       8   */
       9  
      10  #include "defs.h"
      11  #include "netlink.h"
      12  #include "netlink_sock_diag.h"
      13  #include "nlattr.h"
      14  
      15  #include <arpa/inet.h>
      16  
      17  #include <linux/sock_diag.h>
      18  #include <linux/inet_diag.h>
      19  #include <linux/mptcp.h>
      20  #include <linux/tcp.h>
      21  #include <linux/tls.h>
      22  
      23  #include "xlat/inet_diag_attrs.h"
      24  #include "xlat/inet_diag_bpf_storage_attrs.h"
      25  #include "xlat/inet_diag_bpf_storages_attrs.h"
      26  #include "xlat/inet_diag_bytecodes.h"
      27  #include "xlat/inet_diag_extended_flags.h"
      28  #include "xlat/inet_diag_req_attrs.h"
      29  #include "xlat/inet_diag_shutdown_flags.h"
      30  #include "xlat/inet_diag_ulp_info_attrs.h"
      31  #include "xlat/inet_diag_ulp_info_mptcp_attrs.h"
      32  #include "xlat/inet_diag_ulp_info_tls_attrs.h"
      33  
      34  #include "xlat/mptcp_subflow_flags.h"
      35  
      36  #include "xlat/tcp_states.h"
      37  #include "xlat/tcp_state_flags.h"
      38  
      39  #include "xlat/tls_info_ciphers.h"
      40  #include "xlat/tls_info_configs.h"
      41  #include "xlat/tls_info_versions.h"
      42  
      43  
      44  void
      45  print_inet_diag_sockid(const struct inet_diag_sockid *id, const uint8_t family)
      46  {
      47  	tprint_struct_begin();
      48  	PRINT_FIELD_NET_PORT(*id, idiag_sport);
      49  	tprint_struct_next();
      50  	PRINT_FIELD_NET_PORT(*id, idiag_dport);
      51  	tprint_struct_next();
      52  	PRINT_FIELD_INET_ADDR(*id, idiag_src, family);
      53  	tprint_struct_next();
      54  	PRINT_FIELD_INET_ADDR(*id, idiag_dst, family);
      55  	tprint_struct_next();
      56  	PRINT_FIELD_IFINDEX(*id, idiag_if);
      57  	tprint_struct_next();
      58  	PRINT_FIELD_COOKIE(*id, idiag_cookie);
      59  	tprint_struct_end();
      60  }
      61  
      62  static void
      63  decode_inet_diag_hostcond(struct tcb *const tcp,
      64  			  const kernel_ulong_t addr,
      65  			  const unsigned int len)
      66  {
      67  	struct inet_diag_hostcond cond;
      68  
      69  	if (len < sizeof(cond)) {
      70  		printstr_ex(tcp, addr, len, QUOTE_FORCE_HEX);
      71  		return;
      72  	}
      73  	if (umove_or_printaddr(tcp, addr, &cond))
      74  		return;
      75  
      76  	tprint_struct_begin();
      77  	PRINT_FIELD_XVAL(cond, family, addrfams, "AF_???");
      78  	tprint_struct_next();
      79  	PRINT_FIELD_U(cond, prefix_len);
      80  	tprint_struct_next();
      81  	PRINT_FIELD_U(cond, port);
      82  
      83  	if (len > sizeof(cond)) {
      84  		tprint_struct_next();
      85  		decode_inet_addr(tcp, addr + sizeof(cond),
      86  				 len - sizeof(cond), cond.family, "addr");
      87  	}
      88  	tprint_struct_end();
      89  }
      90  
      91  static void
      92  print_inet_diag_bc_op(const struct inet_diag_bc_op *const op)
      93  {
      94  	tprint_struct_begin();
      95  	PRINT_FIELD_XVAL(*op, code, inet_diag_bytecodes, "INET_DIAG_BC_???");
      96  	tprint_struct_next();
      97  	PRINT_FIELD_U(*op, yes);
      98  	tprint_struct_next();
      99  	PRINT_FIELD_U(*op, no);
     100  	tprint_struct_end();
     101  }
     102  
     103  static void
     104  decode_inet_diag_markcond(struct tcb *const tcp,
     105  			  const kernel_ulong_t addr,
     106  			  const unsigned int len)
     107  {
     108  	struct inet_diag_markcond markcond;
     109  
     110  	if (len < sizeof(markcond))
     111  		printstr_ex(tcp, addr, len, QUOTE_FORCE_HEX);
     112  	else if (!umove_or_printaddr(tcp, addr, &markcond)) {
     113  		tprint_struct_begin();
     114  		PRINT_FIELD_U(markcond, mark);
     115  		tprint_struct_next();
     116  		PRINT_FIELD_U(markcond, mask);
     117  		tprint_struct_end();
     118  	}
     119  }
     120  
     121  static void
     122  decode_bytecode_data(struct tcb *const tcp,
     123  		     const kernel_ulong_t addr,
     124  		     const unsigned int len,
     125  		     const unsigned char code)
     126  {
     127  	switch (code) {
     128  	case INET_DIAG_BC_S_COND:
     129  	case INET_DIAG_BC_D_COND:
     130  		decode_inet_diag_hostcond(tcp, addr, len);
     131  		break;
     132  	case INET_DIAG_BC_DEV_COND: {
     133  		uint32_t ifindex;
     134  
     135  		if (len < sizeof(ifindex))
     136  			printstr_ex(tcp, addr, len, QUOTE_FORCE_HEX);
     137  		else if (!umove_or_printaddr(tcp, addr, &ifindex))
     138  			print_ifindex(ifindex);
     139  		break;
     140  	}
     141  	case INET_DIAG_BC_S_GE:
     142  	case INET_DIAG_BC_S_LE:
     143  	case INET_DIAG_BC_D_GE:
     144  	case INET_DIAG_BC_D_LE: {
     145  		struct inet_diag_bc_op op;
     146  
     147  		if (len < sizeof(op))
     148  			printstr_ex(tcp, addr, len, QUOTE_FORCE_HEX);
     149  		else if (!umove_or_printaddr(tcp, addr, &op))
     150  			print_inet_diag_bc_op(&op);
     151  		break;
     152  	}
     153  	case INET_DIAG_BC_MARK_COND:
     154  		decode_inet_diag_markcond(tcp, addr, len);
     155  		break;
     156  	case INET_DIAG_BC_AUTO:
     157  	case INET_DIAG_BC_JMP:
     158  	case INET_DIAG_BC_NOP:
     159  	default:
     160  		printstr_ex(tcp, addr, len, QUOTE_FORCE_HEX);
     161  		break;
     162  	}
     163  }
     164  
     165  static bool
     166  decode_inet_diag_bc_op(struct tcb *const tcp,
     167  		       const kernel_ulong_t addr,
     168  		       const unsigned int len,
     169  		       const void *const opaque_data)
     170  {
     171  	struct inet_diag_bc_op op;
     172  
     173  	if (len < sizeof(op))
     174  		return false;
     175  	if (umove_or_printaddr(tcp, addr, &op))
     176  		return true;
     177  
     178  	print_inet_diag_bc_op(&op);
     179  
     180  	if (len > sizeof(op)) {
     181  		tprint_array_next();
     182  		decode_bytecode_data(tcp, addr + sizeof(op),
     183  				     len - sizeof(op), op.code);
     184  	}
     185  
     186  	return true;
     187  }
     188  
     189  static const nla_decoder_t inet_diag_req_nla_decoders[] = {
     190  	[INET_DIAG_REQ_NONE]		= NULL,
     191  	[INET_DIAG_REQ_BYTECODE]	= decode_inet_diag_bc_op,
     192  	[INET_DIAG_REQ_SK_BPF_STORAGES]	= NULL, /* no payload */
     193  	[INET_DIAG_REQ_PROTOCOL]	= decode_nla_ip_proto,
     194  };
     195  
     196  static void
     197  decode_inet_diag_req_compat(struct tcb *const tcp,
     198  			    const struct nlmsghdr *const nlmsghdr,
     199  			    const uint8_t family,
     200  			    const kernel_ulong_t addr,
     201  			    const unsigned int len)
     202  {
     203  	struct inet_diag_req req = { .idiag_family = family };
     204  	size_t offset = sizeof(req.idiag_family);
     205  	bool decode_nla = false;
     206  
     207  	tprint_struct_begin();
     208  	PRINT_FIELD_XVAL(req, idiag_family, addrfams, "AF_???");
     209  	tprint_struct_next();
     210  
     211  	if (len >= sizeof(req)) {
     212  		if (!umoven_or_printaddr(tcp, addr + offset,
     213  					 sizeof(req) - offset,
     214  					 (char *) &req + offset)) {
     215  			PRINT_FIELD_U(req, idiag_src_len);
     216  			tprint_struct_next();
     217  			PRINT_FIELD_U(req, idiag_dst_len);
     218  			tprint_struct_next();
     219  			PRINT_FIELD_FLAGS(req, idiag_ext,
     220  					  inet_diag_extended_flags,
     221  					  "1<<INET_DIAG_\?\?\?-1");
     222  			tprint_struct_next();
     223  			PRINT_FIELD_INET_DIAG_SOCKID(req, id,
     224  						     req.idiag_family);
     225  			tprint_struct_next();
     226  			PRINT_FIELD_FLAGS(req, idiag_states,
     227  					  tcp_state_flags, "1<<TCP_???");
     228  			tprint_struct_next();
     229  			PRINT_FIELD_U(req, idiag_dbs);
     230  			decode_nla = true;
     231  		}
     232  	} else
     233  		tprint_more_data_follows();
     234  	tprint_struct_end();
     235  
     236  	offset = NLMSG_ALIGN(sizeof(req));
     237  	if (decode_nla && len > offset) {
     238  		tprint_array_next();
     239  		decode_nlattr(tcp, addr + offset, len - offset,
     240  			      inet_diag_req_attrs, "INET_DIAG_REQ_???",
     241  			      inet_diag_req_nla_decoders,
     242  			      ARRAY_SIZE(inet_diag_req_nla_decoders), NULL);
     243  	}
     244  }
     245  
     246  static void
     247  decode_inet_diag_req_v2(struct tcb *const tcp,
     248  			const struct nlmsghdr *const nlmsghdr,
     249  			const uint8_t family,
     250  			const kernel_ulong_t addr,
     251  			const unsigned int len)
     252  {
     253  	struct inet_diag_req_v2 req = { .sdiag_family = family };
     254  	size_t offset = sizeof(req.sdiag_family);
     255  	bool decode_nla = false;
     256  
     257  	tprint_struct_begin();
     258  	PRINT_FIELD_XVAL(req, sdiag_family, addrfams, "AF_???");
     259  	tprint_struct_next();
     260  
     261  	if (len >= sizeof(req)) {
     262  		if (!umoven_or_printaddr(tcp, addr + offset,
     263  					 sizeof(req) - offset,
     264  					 (char *) &req + offset)) {
     265  			PRINT_FIELD_XVAL(req, sdiag_protocol,
     266  					 inet_protocols, "IPPROTO_???");
     267  			tprint_struct_next();
     268  			PRINT_FIELD_FLAGS(req, idiag_ext,
     269  					  inet_diag_extended_flags,
     270  					  "1<<INET_DIAG_\?\?\?-1");
     271  			tprint_struct_next();
     272  			PRINT_FIELD_FLAGS(req, idiag_states,
     273  					  tcp_state_flags, "1<<TCP_???");
     274  			tprint_struct_next();
     275  			PRINT_FIELD_INET_DIAG_SOCKID(req, id,
     276  						     req.sdiag_family);
     277  			decode_nla = true;
     278  		}
     279  	} else
     280  		tprint_more_data_follows();
     281  	tprint_struct_end();
     282  
     283  	offset = NLMSG_ALIGN(sizeof(req));
     284  	if (decode_nla && len > offset) {
     285  		tprint_array_next();
     286  		decode_nlattr(tcp, addr + offset, len - offset,
     287  			      inet_diag_req_attrs, "INET_DIAG_REQ_???",
     288  			      inet_diag_req_nla_decoders,
     289  			      ARRAY_SIZE(inet_diag_req_nla_decoders), NULL);
     290  	}
     291  }
     292  
     293  DECL_NETLINK_DIAG_DECODER(decode_inet_diag_req)
     294  {
     295  	if (nlmsghdr->nlmsg_type == TCPDIAG_GETSOCK
     296  	    || nlmsghdr->nlmsg_type == DCCPDIAG_GETSOCK)
     297  		decode_inet_diag_req_compat(tcp, nlmsghdr, family, addr, len);
     298  	else
     299  		decode_inet_diag_req_v2(tcp, nlmsghdr, family, addr, len);
     300  }
     301  
     302  static bool
     303  decode_inet_diag_meminfo(struct tcb *const tcp,
     304  			 const kernel_ulong_t addr,
     305  			 const unsigned int len,
     306  			 const void *const opaque_data)
     307  {
     308  	struct inet_diag_meminfo minfo;
     309  
     310  	if (len < sizeof(minfo))
     311  		return false;
     312  	if (umove_or_printaddr(tcp, addr, &minfo))
     313  		return true;
     314  
     315  	tprint_struct_begin();
     316  	PRINT_FIELD_U(minfo, idiag_rmem);
     317  	tprint_struct_next();
     318  	PRINT_FIELD_U(minfo, idiag_wmem);
     319  	tprint_struct_next();
     320  	PRINT_FIELD_U(minfo, idiag_fmem);
     321  	tprint_struct_next();
     322  	PRINT_FIELD_U(minfo, idiag_tmem);
     323  	tprint_struct_end();
     324  
     325  	return true;
     326  }
     327  
     328  void
     329  print_tcpvegas_info(struct tcb *tcp, const struct tcpvegas_info *const vegas,
     330  		    const unsigned int len)
     331  {
     332  	MAYBE_PRINT_FIELD_LEN(tprint_struct_begin(),
     333  			      *vegas, tcpv_enabled, len, PRINT_FIELD_U);
     334  	MAYBE_PRINT_FIELD_LEN(tprint_struct_next(),
     335  			      *vegas, tcpv_rttcnt, len, PRINT_FIELD_U);
     336  	MAYBE_PRINT_FIELD_LEN(tprint_struct_next(),
     337  			      *vegas, tcpv_rtt, len, PRINT_FIELD_U);
     338  	MAYBE_PRINT_FIELD_LEN(tprint_struct_next(),
     339  			      *vegas, tcpv_minrtt, len, PRINT_FIELD_U);
     340  	tprint_struct_end();
     341  }
     342  
     343  static bool
     344  decode_tcpvegas_info(struct tcb *const tcp,
     345  		     const kernel_ulong_t addr,
     346  		     const unsigned int len,
     347  		     const void *const opaque_data)
     348  {
     349  	struct tcpvegas_info vegas;
     350  
     351  	if (len < sizeof(vegas))
     352  		return false;
     353  	if (umove_or_printaddr(tcp, addr, &vegas))
     354  		return true;
     355  
     356  	print_tcpvegas_info(tcp, &vegas, len);
     357  
     358  	return true;
     359  }
     360  
     361  static bool
     362  decode_diag_shutdown(struct tcb *const tcp,
     363  		     const kernel_ulong_t addr,
     364  		     const unsigned int len,
     365  		     const void *const opaque_data)
     366  {
     367  	struct decode_nla_xlat_opts opts = {
     368  		.xlat  = inet_diag_shutdown_flags,
     369  		.dflt  = "???_SHUTDOWN",
     370  		/*
     371  		 * While these values are exposed to the user space all over
     372  		 * the place, the associated RCV_SHUTDOWN/SEND_SHUTDOWN
     373  		 * constants are not part of UAPI for whatever reason,
     374  		 * hence we cannot print only the symbolic names.
     375  		 */
     376  		.style = xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW
     377  			 ? XLAT_STYLE_RAW : XLAT_STYLE_VERBOSE,
     378  		.size  = 1,
     379  	};
     380  
     381  	return decode_nla_flags(tcp, addr, len, &opts);
     382  }
     383  
     384  void
     385  print_tcp_dctcp_info(struct tcb *tcp, const struct tcp_dctcp_info *const dctcp,
     386  		     const unsigned int len)
     387  {
     388  	MAYBE_PRINT_FIELD_LEN(tprint_struct_begin(),
     389  			      *dctcp, dctcp_enabled, len, PRINT_FIELD_U);
     390  	MAYBE_PRINT_FIELD_LEN(tprint_struct_next(),
     391  			      *dctcp, dctcp_ce_state, len, PRINT_FIELD_U);
     392  	MAYBE_PRINT_FIELD_LEN(tprint_struct_next(),
     393  			      *dctcp, dctcp_alpha, len, PRINT_FIELD_U);
     394  	MAYBE_PRINT_FIELD_LEN(tprint_struct_next(),
     395  			      *dctcp, dctcp_ab_ecn, len, PRINT_FIELD_U);
     396  	MAYBE_PRINT_FIELD_LEN(tprint_struct_next(),
     397  			      *dctcp, dctcp_ab_tot, len, PRINT_FIELD_U);
     398  	tprint_struct_end();
     399  }
     400  
     401  static bool
     402  decode_tcp_dctcp_info(struct tcb *const tcp,
     403  		      const kernel_ulong_t addr,
     404  		      const unsigned int len,
     405  		      const void *const opaque_data)
     406  {
     407  	struct tcp_dctcp_info dctcp;
     408  
     409  	if (len < sizeof(dctcp))
     410  		return false;
     411  	if (umove_or_printaddr(tcp, addr, &dctcp))
     412  		return true;
     413  
     414  	print_tcp_dctcp_info(tcp, &dctcp, len);
     415  
     416  	return true;
     417  }
     418  
     419  static bool
     420  print_sockaddr_array_member(struct tcb *const tcp, void *const elem_buf,
     421  			    const size_t elem_size, void *const data)
     422  {
     423  	print_sockaddr(tcp, elem_buf, elem_size);
     424  
     425  	return true;
     426  }
     427  
     428  static bool
     429  decode_nla_sockaddrs(struct tcb *const tcp,
     430  		     const kernel_ulong_t addr,
     431  		     const unsigned int len,
     432  		     const void *const opaque_data)
     433  {
     434  	struct sockaddr_storage sas;
     435  	const size_t nmemb = len / sizeof(sas);
     436  
     437  	if (!nmemb)
     438  		return false;
     439  
     440  	print_array(tcp, addr, nmemb, &sas, sizeof(sas),
     441  		    tfetch_mem, print_sockaddr_array_member, 0);
     442  
     443  	return true;
     444  }
     445  
     446  void
     447  print_tcp_bbr_info(struct tcb *tcp, const struct tcp_bbr_info *const bbr,
     448  		   const unsigned int len)
     449  {
     450  	MAYBE_PRINT_FIELD_LEN(tprint_struct_begin(),
     451  			      *bbr, bbr_bw_lo, len, PRINT_FIELD_X);
     452  	MAYBE_PRINT_FIELD_LEN(tprint_struct_next(),
     453  			      *bbr, bbr_bw_hi, len, PRINT_FIELD_X);
     454  	MAYBE_PRINT_FIELD_LEN(tprint_struct_next(),
     455  			      *bbr, bbr_min_rtt, len, PRINT_FIELD_U);
     456  	MAYBE_PRINT_FIELD_LEN(tprint_struct_next(),
     457  			      *bbr, bbr_pacing_gain, len, PRINT_FIELD_U);
     458  	MAYBE_PRINT_FIELD_LEN(tprint_struct_next(),
     459  			      *bbr, bbr_cwnd_gain, len, PRINT_FIELD_U);
     460  	tprint_struct_end();
     461  }
     462  
     463  static bool
     464  decode_tcp_bbr_info(struct tcb *const tcp,
     465  		    const kernel_ulong_t addr,
     466  		    const unsigned int len,
     467  		    const void *const opaque_data)
     468  {
     469  	struct tcp_bbr_info bbr;
     470  
     471  	if (len < sizeof(bbr))
     472  		return false;
     473  	if (umove_or_printaddr(tcp, addr, &bbr))
     474  		return true;
     475  
     476  	print_tcp_bbr_info(tcp, &bbr, len);
     477  
     478  	return true;
     479  }
     480  
     481  static bool
     482  print_tcp_md5sig(struct tcb *const tcp, void *const elem_buf,
     483  		 const size_t elem_size, void *const data)
     484  {
     485  	const struct tcp_diag_md5sig *const sig =
     486  			(const struct tcp_diag_md5sig *) elem_buf;
     487  
     488  	tprint_struct_begin();
     489  	PRINT_FIELD_XVAL(*sig, tcpm_family, addrfams, "AF_???");
     490  	tprint_struct_next();
     491  	PRINT_FIELD_U(*sig, tcpm_prefixlen);
     492  	tprint_struct_next();
     493  	PRINT_FIELD_U(*sig, tcpm_keylen);
     494  	tprint_struct_next();
     495  	PRINT_FIELD_INET_ADDR(*sig, tcpm_addr, sig->tcpm_family);
     496  	tprint_struct_next();
     497  	PRINT_FIELD_HEX_ARRAY_UPTO(*sig, tcpm_key,
     498  				   MIN(sizeof(sig->tcpm_key),
     499  				       sig->tcpm_keylen));
     500  	tprint_struct_end();
     501  
     502  	return true;
     503  }
     504  
     505  static bool
     506  decode_tcp_md5sig(struct tcb *const tcp,
     507  		  const kernel_ulong_t addr,
     508  		  const unsigned int len,
     509  		  const void *const opaque_data)
     510  {
     511  	struct tcp_diag_md5sig sig;
     512  	const size_t nmemb = len / sizeof(sig);
     513  
     514  	if (!nmemb)
     515  		return false;
     516  
     517  	print_array(tcp, addr, nmemb, &sig, sizeof(sig),
     518  		    tfetch_mem, print_tcp_md5sig, 0);
     519  
     520  	return true;
     521  }
     522  
     523  static bool
     524  decode_tls_version(struct tcb *const tcp,
     525  		   const kernel_ulong_t addr,
     526  		   const unsigned int len,
     527  		   const void *const opaque_data)
     528  {
     529  	static const struct decode_nla_xlat_opts opts = {
     530  		.xlat  = tls_info_versions,
     531  		.dflt  = "TLS_???_VERSION",
     532  		.size  = 2,
     533  	};
     534  
     535  	return decode_nla_xval(tcp, addr, len, &opts);
     536  }
     537  
     538  static bool
     539  decode_tls_cipher(struct tcb *const tcp,
     540  		  const kernel_ulong_t addr,
     541  		  const unsigned int len,
     542  		  const void *const opaque_data)
     543  {
     544  	static const struct decode_nla_xlat_opts opts = {
     545  		.xlat  = tls_info_ciphers,
     546  		.dflt  = "TLS_CIPHER_???",
     547  		.size  = 2,
     548  	};
     549  
     550  	return decode_nla_xval(tcp, addr, len, &opts);
     551  }
     552  
     553  static bool
     554  decode_tls_config(struct tcb *const tcp,
     555  		  const kernel_ulong_t addr,
     556  		  const unsigned int len,
     557  		  const void *const opaque_data)
     558  {
     559  	static const struct decode_nla_xlat_opts opts = {
     560  		.xlat  = tls_info_configs,
     561  		.dflt  = "TLS_CONF_???",
     562  		.size  = 2,
     563  	};
     564  
     565  	return decode_nla_xval(tcp, addr, len, &opts);
     566  }
     567  
     568  static const nla_decoder_t diag_ulp_info_tls_nla_decoders[] = {
     569  	[TLS_INFO_UNSPEC]	= NULL,
     570  	[TLS_INFO_VERSION]	= decode_tls_version,
     571  	[TLS_INFO_CIPHER]	= decode_tls_cipher,
     572  	[TLS_INFO_TXCONF]	= decode_tls_config,
     573  	[TLS_INFO_RXCONF]	= decode_tls_config,
     574  	[TLS_INFO_ZC_RO_TX]	= NULL, /* flag nlattr, no payload */
     575  	[TLS_INFO_RX_NO_PAD]	= NULL, /* flag nlattr, no payload */
     576  };
     577  
     578  static bool
     579  decode_diag_ulp_info_tls(struct tcb *const tcp,
     580  			 const kernel_ulong_t addr,
     581  			 const unsigned int len,
     582  			 const void *const opaque_data)
     583  {
     584  	decode_nlattr(tcp, addr, len, inet_diag_ulp_info_tls_attrs,
     585  		      "TLS_INFO_???",
     586  		      ARRSZ_PAIR(diag_ulp_info_tls_nla_decoders), NULL);
     587  
     588  	return true;
     589  }
     590  
     591  static bool
     592  decode_mptcp_subflow_flags(struct tcb *const tcp,
     593  			   const kernel_ulong_t addr,
     594  			   const unsigned int len,
     595  			   const void *const opaque_data)
     596  {
     597  	static const struct decode_nla_xlat_opts opts = {
     598  		.xlat  = mptcp_subflow_flags,
     599  		.dflt  = "MPTCP_SUBFLOW_FLAG_???",
     600  		.size  = 4,
     601  	};
     602  
     603  	return decode_nla_flags(tcp, addr, len, &opts);
     604  }
     605  
     606  static const nla_decoder_t diag_ulp_info_mptcp_nla_decoders[] = {
     607  	[MPTCP_SUBFLOW_ATTR_UNSPEC]		= NULL,
     608  	[MPTCP_SUBFLOW_ATTR_TOKEN_REM]		= decode_nla_x32,
     609  	[MPTCP_SUBFLOW_ATTR_TOKEN_LOC]		= decode_nla_x32,
     610  	[MPTCP_SUBFLOW_ATTR_RELWRITE_SEQ]	= decode_nla_u32,
     611  	[MPTCP_SUBFLOW_ATTR_MAP_SEQ]		= decode_nla_u64,
     612  	[MPTCP_SUBFLOW_ATTR_MAP_SFSEQ]		= decode_nla_u32,
     613  	[MPTCP_SUBFLOW_ATTR_SSN_OFFSET]		= decode_nla_u32,
     614  	[MPTCP_SUBFLOW_ATTR_MAP_DATALEN]	= decode_nla_u16,
     615  	[MPTCP_SUBFLOW_ATTR_FLAGS]		= decode_mptcp_subflow_flags,
     616  	[MPTCP_SUBFLOW_ATTR_ID_REM]		= decode_nla_u8,
     617  	[MPTCP_SUBFLOW_ATTR_ID_LOC]		= decode_nla_u8,
     618  	[MPTCP_SUBFLOW_ATTR_PAD]		= NULL,
     619  };
     620  
     621  static bool
     622  decode_diag_ulp_info_mptcp(struct tcb *const tcp,
     623  			   const kernel_ulong_t addr,
     624  			   const unsigned int len,
     625  			   const void *const opaque_data)
     626  {
     627  	decode_nlattr(tcp, addr, len, inet_diag_ulp_info_mptcp_attrs,
     628  		      "MPTCP_SUBFLOW_ATTR_???",
     629  		      ARRSZ_PAIR(diag_ulp_info_mptcp_nla_decoders), NULL);
     630  
     631  	return true;
     632  }
     633  
     634  static const nla_decoder_t diag_ulp_info_nla_decoders[] = {
     635  	[INET_ULP_INFO_UNSPEC]	= NULL,
     636  	[INET_ULP_INFO_NAME]	= decode_nla_str,
     637  	/*
     638  	 * In theory, the decoding of INTEL_ULP_* attributes depends
     639  	 * on the value of INET_ULP_INFO_NAME attribute, but, luckily,
     640  	 * all currently implemented ULPs that return information
     641  	 * simply use their own attribute types.
     642  	 */
     643  	[INET_ULP_INFO_TLS]	= decode_diag_ulp_info_tls,
     644  	[INET_ULP_INFO_MPTCP]	= decode_diag_ulp_info_mptcp,
     645  };
     646  
     647  static bool
     648  decode_diag_ulp_info(struct tcb *const tcp,
     649  		     const kernel_ulong_t addr,
     650  		     const unsigned int len,
     651  		     const void *const opaque_data)
     652  {
     653  	decode_nlattr(tcp, addr, len, inet_diag_ulp_info_attrs,
     654  		      "INET_ULP_INFO_???",
     655  		      ARRSZ_PAIR(diag_ulp_info_nla_decoders), NULL);
     656  
     657  	return true;
     658  }
     659  
     660  static const nla_decoder_t diag_bpf_storage_nla_decoders[] = {
     661  	[SK_DIAG_BPF_STORAGE_NONE]	= NULL,
     662  	[SK_DIAG_BPF_STORAGE_PAD]	= NULL,
     663  	[SK_DIAG_BPF_STORAGE_MAP_ID]	= decode_nla_u32,
     664  	[SK_DIAG_BPF_STORAGE_MAP_VALUE]	= decode_nla_xint,
     665  };
     666  
     667  static bool
     668  decode_diag_bpf_storage(struct tcb *const tcp,
     669  			const kernel_ulong_t addr,
     670  			const unsigned int len,
     671  			const void *const opaque_data)
     672  {
     673  	decode_nlattr(tcp, addr, len, inet_diag_bpf_storage_attrs,
     674  		      "SK_DIAG_BPF_STORAGE_???",
     675  		      ARRSZ_PAIR(diag_bpf_storage_nla_decoders), NULL);
     676  
     677  	return true;
     678  }
     679  
     680  static const nla_decoder_t diag_bpf_storages_nla_decoders[] = {
     681  	[SK_DIAG_BPF_STORAGE_REP_NONE]	= NULL,
     682  	[SK_DIAG_BPF_STORAGE]		= decode_diag_bpf_storage,
     683  };
     684  
     685  static bool
     686  decode_diag_bpf_storages(struct tcb *const tcp,
     687  			 const kernel_ulong_t addr,
     688  			 const unsigned int len,
     689  			 const void *const opaque_data)
     690  {
     691  	decode_nlattr(tcp, addr, len, inet_diag_bpf_storages_attrs,
     692  		      "SK_DIAG_BPF_STORAGE_???",
     693  		      ARRSZ_PAIR(diag_bpf_storages_nla_decoders), NULL);
     694  
     695  	return true;
     696  }
     697  
     698  static bool
     699  decode_diag_sockopt(struct tcb *const tcp,
     700  		    const kernel_ulong_t addr,
     701  		    const unsigned int len,
     702  		    const void *const opaque_data)
     703  {
     704  	/*
     705  	 * The own version of struct inet_diag_sockopt here since
     706  	 * there is no trivial way to detect new bit fields and, as a result,
     707  	 * shrinkage of the "unused" field.
     708  	 */
     709  	struct inet_diag_sockopt {
     710  		uint8_t	recverr			:1,
     711  			is_icsk			:1,
     712  			freebind		:1,
     713  			hdrincl			:1,
     714  			mc_loop			:1,
     715  			transparent		:1,
     716  			mc_all			:1,
     717  			nodefrag		:1;
     718  		uint8_t	bind_address_no_port	:1,
     719  			recverr_rfc4884		:1,
     720  			defer_connect		:1,
     721  			unused			:5;
     722  	} sockopt;
     723  
     724  	if (len < sizeof(sockopt))
     725  		return false;
     726  	if (umove_or_printaddr(tcp, addr, &sockopt))
     727  		return true;
     728  
     729  	void (*delim_f)(void) = tprint_struct_begin;
     730  
     731  #define OPT_PRINT_FIELD_U(where_, field_)				\
     732  	do {								\
     733  		if (!abbrev(tcp) || ((where_).field_)) {		\
     734  			delim_f();					\
     735  			delim_f = tprint_struct_next;			\
     736  			PRINT_FIELD_U_CAST((where_), field_, uint8_t);	\
     737  		}							\
     738  	} while (0)
     739  
     740  	OPT_PRINT_FIELD_U(sockopt, recverr);
     741  	OPT_PRINT_FIELD_U(sockopt, is_icsk);
     742  	OPT_PRINT_FIELD_U(sockopt, freebind);
     743  	OPT_PRINT_FIELD_U(sockopt, hdrincl);
     744  	OPT_PRINT_FIELD_U(sockopt, mc_loop);
     745  	OPT_PRINT_FIELD_U(sockopt, transparent);
     746  	OPT_PRINT_FIELD_U(sockopt, mc_all);
     747  	OPT_PRINT_FIELD_U(sockopt, nodefrag);
     748  	OPT_PRINT_FIELD_U(sockopt, bind_address_no_port);
     749  	OPT_PRINT_FIELD_U(sockopt, recverr_rfc4884);
     750  	OPT_PRINT_FIELD_U(sockopt, defer_connect);
     751  
     752  	if (!abbrev(tcp) || sockopt.unused) {
     753  		delim_f();
     754  		delim_f = tprint_struct_next;
     755  		PRINT_FIELD_X_CAST(sockopt, unused, uint8_t);
     756  		tprints_comment("bits 3..8");
     757  	}
     758  
     759  	if (delim_f == tprint_struct_begin)
     760  		tprint_struct_begin();
     761  
     762  	tprint_struct_end();
     763  
     764  #undef OPT_PRINT_FIELD_U
     765  
     766  	print_nonzero_bytes(tcp, tprint_array_next, addr, sizeof(sockopt),
     767  			    MIN(len, get_pagesize()), QUOTE_FORCE_HEX);
     768  
     769  	return true;
     770  }
     771  
     772  static const nla_decoder_t inet_diag_msg_nla_decoders[] = {
     773  	[INET_DIAG_MEMINFO]		= decode_inet_diag_meminfo,
     774  	[INET_DIAG_INFO]		= NULL,		/* unimplemented */
     775  	[INET_DIAG_VEGASINFO]		= decode_tcpvegas_info,
     776  	[INET_DIAG_CONG]		= decode_nla_str,
     777  	[INET_DIAG_TOS]			= decode_nla_u8,
     778  	[INET_DIAG_TCLASS]		= decode_nla_u8,
     779  	[INET_DIAG_SKMEMINFO]		= decode_nla_meminfo,
     780  	[INET_DIAG_SHUTDOWN]		= decode_diag_shutdown,
     781  	[INET_DIAG_DCTCPINFO]		= decode_tcp_dctcp_info,
     782  	[INET_DIAG_PROTOCOL]		= decode_nla_ip_proto,
     783  	[INET_DIAG_SKV6ONLY]		= decode_nla_u8,
     784  	[INET_DIAG_LOCALS]		= decode_nla_sockaddrs,
     785  	[INET_DIAG_PEERS]		= decode_nla_sockaddrs,
     786  	[INET_DIAG_PAD]			= NULL,
     787  	[INET_DIAG_MARK]		= decode_nla_u32,
     788  	[INET_DIAG_BBRINFO]		= decode_tcp_bbr_info,
     789  	[INET_DIAG_CLASS_ID]		= decode_nla_u32,
     790  	[INET_DIAG_MD5SIG]		= decode_tcp_md5sig,
     791  	[INET_DIAG_ULP_INFO]		= decode_diag_ulp_info,
     792  	[INET_DIAG_SK_BPF_STORAGES]	= decode_diag_bpf_storages,
     793  	[INET_DIAG_CGROUP_ID]		= decode_nla_u64,
     794  	[INET_DIAG_SOCKOPT]		= decode_diag_sockopt,
     795  };
     796  
     797  DECL_NETLINK_DIAG_DECODER(decode_inet_diag_msg)
     798  {
     799  	struct inet_diag_msg msg = { .idiag_family = family };
     800  	size_t offset = sizeof(msg.idiag_family);
     801  	bool decode_nla = false;
     802  
     803  	tprint_struct_begin();
     804  	PRINT_FIELD_XVAL(msg, idiag_family, addrfams, "AF_???");
     805  	tprint_struct_next();
     806  
     807  	if (len >= sizeof(msg)) {
     808  		if (!umoven_or_printaddr(tcp, addr + offset,
     809  					 sizeof(msg) - offset,
     810  					 (char *) &msg + offset)) {
     811  			PRINT_FIELD_XVAL(msg, idiag_state,
     812  					 tcp_states, "TCP_???");
     813  			tprint_struct_next();
     814  			PRINT_FIELD_U(msg, idiag_timer);
     815  			tprint_struct_next();
     816  			PRINT_FIELD_U(msg, idiag_retrans);
     817  			tprint_struct_next();
     818  			PRINT_FIELD_INET_DIAG_SOCKID(msg, id,
     819  						     msg.idiag_family);
     820  			tprint_struct_next();
     821  			PRINT_FIELD_U(msg, idiag_expires);
     822  			tprint_struct_next();
     823  			PRINT_FIELD_U(msg, idiag_rqueue);
     824  			tprint_struct_next();
     825  			PRINT_FIELD_U(msg, idiag_wqueue);
     826  			tprint_struct_next();
     827  			PRINT_FIELD_U(msg, idiag_uid);
     828  			tprint_struct_next();
     829  			PRINT_FIELD_U(msg, idiag_inode);
     830  			decode_nla = true;
     831  		}
     832  	} else
     833  		tprint_more_data_follows();
     834  	tprint_struct_end();
     835  
     836  	offset = NLMSG_ALIGN(sizeof(msg));
     837  	if (decode_nla && len > offset) {
     838  		tprint_array_next();
     839  		decode_nlattr(tcp, addr + offset, len - offset,
     840  			      inet_diag_attrs, "INET_DIAG_???",
     841  			      inet_diag_msg_nla_decoders,
     842  			      ARRAY_SIZE(inet_diag_msg_nla_decoders), NULL);
     843  	}
     844  }