Re: [iproute2 1/1] ss: Add support for TIPC socket diag in ss tool

2018-03-27 Thread Stephen Hemminger
On Fri, 23 Mar 2018 15:01:02 +0100
GhantaKrishnamurthy MohanKrishna 
 wrote:

> For iproute 4.x
> Allow TIPC socket statistics to be dumped with --tipc
> and tipc specific info with --tipcinfo.
> 
> Acked-by: Jon Maloy 
> Signed-off-by: GhantaKrishnamurthy MohanKrishna 
> 
> Signed-off-by: Parthasarathy Bhuvaragan 
> ---
>  misc/ss.c | 166 
> +-
>  1 file changed, 164 insertions(+), 2 deletions(-)
> 
> diff --git a/misc/ss.c b/misc/ss.c
> index e047f9c04582..812f45717af9 100644
> --- a/misc/ss.c
> +++ b/misc/ss.c
> @@ -45,6 +45,10 @@
>  #include 
>  #include 
>  #include 
> +#include 
> +#include 
> +#include 
> +#include 

This needs to be against iproute2-next, not master since there is no 
tipc_sockets_diag.h
in Linus's tree.

All the header files for iproute2 include/uapi/linux come from upstream kernel
via 'make headers_install'. Therefore you need to have tipc_sockets_diag.h in
kernel already.


RE: [iproute2 1/1] ss: Add support for TIPC socket diag in ss tool

2018-03-23 Thread Jon Maloy
Hi Mohan,
I remember you mentioned the possibility to add this functionality to the tipc 
tool, too.
Would it be easy to add a 'tipc ss' command that just calls 'ss' with the same 
parameters? I.e., no duplication of functionality ?

///jon


> -Original Message-
> From: Mohan Krishna Ghanta Krishnamurthy
> Sent: Friday, March 23, 2018 10:01
> To: tipc-discuss...@lists.sourceforge.net; Jon Maloy
> ; ma...@donjonn.com;
> ying@windriver.com; Mohan Krishna Ghanta Krishnamurthy
> ;
> netdev@vger.kernel.org; step...@networkplumber.org
> Cc: Parthasarathy Bhuvaragan 
> Subject: [iproute2 1/1] ss: Add support for TIPC socket diag in ss tool
> 
> For iproute 4.x
> Allow TIPC socket statistics to be dumped with --tipc and tipc specific info
> with --tipcinfo.
> 
> Acked-by: Jon Maloy 
> Signed-off-by: GhantaKrishnamurthy MohanKrishna
> 
> Signed-off-by: Parthasarathy Bhuvaragan
> 
> ---
>  misc/ss.c | 166
> ++
> +++-
>  1 file changed, 164 insertions(+), 2 deletions(-)
> 
> diff --git a/misc/ss.c b/misc/ss.c
> index e047f9c04582..812f45717af9 100644
> --- a/misc/ss.c
> +++ b/misc/ss.c
> @@ -45,6 +45,10 @@
>  #include 
>  #include 
>  #include 
> +#include 
> +#include 
> +#include 
> +#include 
> 
>  #define MAGIC_SEQ 123456
>  #define BUF_CHUNK (1024 * 1024)
> @@ -104,6 +108,7 @@ int show_sock_ctx;
>  int show_header = 1;
>  int follow_events;
>  int sctp_ino;
> +int show_tipcinfo;
> 
>  enum col_id {
>   COL_NETID,
> @@ -191,6 +196,7 @@ enum {
>   SCTP_DB,
>   VSOCK_ST_DB,
>   VSOCK_DG_DB,
> + TIPC_DB,
>   MAX_DB
>  };
> 
> @@ -230,6 +236,7 @@ enum {
> 
>  #define SS_ALL ((1 << SS_MAX) - 1)
>  #define SS_CONN (SS_ALL &
> ~((1< ))
> +#define TIPC_SS_CONN
> ((1< 
>  #include "ssfilter.h"
> 
> @@ -297,6 +304,10 @@ static const struct filter default_dbs[MAX_DB] = {
>   .states   = SS_CONN,
>   .families = FAMILY_MASK(AF_VSOCK),
>   },
> + [TIPC_DB] = {
> + .states   = TIPC_SS_CONN,
> + .families = FAMILY_MASK(AF_TIPC),
> + },
>  };
> 
>  static const struct filter default_afs[AF_MAX] = { @@ -324,6 +335,10 @@
> static const struct filter default_afs[AF_MAX] = {
>   .dbs= VSOCK_DBM,
>   .states = SS_CONN,
>   },
> + [AF_TIPC] = {
> + .dbs= (1 << TIPC_DB),
> + .states = TIPC_SS_CONN,
> + },
>  };
> 
>  static int do_default = 1;
> @@ -364,6 +379,7 @@ static void filter_default_dbs(struct filter *f)
>   filter_db_set(f, SCTP_DB);
>   filter_db_set(f, VSOCK_ST_DB);
>   filter_db_set(f, VSOCK_DG_DB);
> + filter_db_set(f, TIPC_DB);
>  }
> 
>  static void filter_states_set(struct filter *f, int states) @@ -748,6 +764,14
> @@ static const char *sctp_sstate_name[] = {
>   [SCTP_STATE_SHUTDOWN_ACK_SENT] = "ACK_SENT",  };
> 
> +static const char * const stype_nameg[] = {
> + "UNKNOWN",
> + [SOCK_STREAM] = "STREAM",
> + [SOCK_DGRAM] = "DGRAM",
> + [SOCK_RDM] = "RDM",
> + [SOCK_SEQPACKET] = "SEQPACKET",
> +};
> +
>  struct sockstat {
>   struct sockstat*next;
>   unsigned inttype;
> @@ -888,6 +912,22 @@ static const char *vsock_netid_name(int type)
>   }
>  }
> 
> +static const char *tipc_netid_name(int type) {
> + switch (type) {
> + case SOCK_STREAM:
> + return "ti_st";
> + case SOCK_DGRAM:
> + return "ti_dg";
> + case SOCK_RDM:
> + return "ti_rd";
> + case SOCK_SEQPACKET:
> + return "ti_sq";
> + default:
> + return "???";
> + }
> +}
> +
>  /* Allocate and initialize a new buffer chunk */  static struct buf_chunk
> *buf_chunk_new(void)  { @@ -1274,6 +1314,9 @@ static void
> sock_state_print(struct sockstat *s)
>   case AF_NETLINK:
>   sock_name = "nl";
>   break;
> + case AF_TIPC:
> + sock_name = tipc_netid_name(s->type);
> + break;
>   case AF_VSOCK:
>   sock_name = vsock_netid_name(s->type);
>   break;
> @@ -4250,6 +4293,105 @@ static int vsock_show(struct filter *f)
>   return handle_netlink_request(f, , sizeof(req),
> vsock_show_sock);  }
> 
> +static void tipc_sock_addr_print(struct rtattr *net_addr, struct rtattr
> +*id) {
> + uint32_t node = rta_getattr_u32(net_addr);
> + uint32_t identity = rta_getattr_u32(id);
> +
> + SPRINT_BUF(addr) = {};
> + SPRINT_BUF(port) = {};
> +
> + sprintf(addr, "%u", node);
> + sprintf(port, "%u", identity);
> + sock_addr_print(addr, ":", port, NULL);
> +
> +}
> +
> +static int