]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - misc/ss.c
Merge branch 'master' of git://git.kernel.org/pub/scm/network/iproute2/iproute2-next
[mirror_iproute2.git] / misc / ss.c
index efa8778160e3fda91daeab782fe071f1d065ac61..3ef151fbf1f1b3856e95a1baa751a1cdd27d10b7 100644 (file)
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -35,6 +35,7 @@
 #include "libnetlink.h"
 #include "namespace.h"
 #include "SNAPSHOT.h"
+#include "rt_names.h"
 
 #include <linux/tcp.h>
 #include <linux/sock_diag.h>
@@ -51,6 +52,7 @@
 #include <linux/tipc.h>
 #include <linux/tipc_netlink.h>
 #include <linux/tipc_sockets_diag.h>
+#include <linux/tls.h>
 
 /* AF_VSOCK/PF_VSOCK is only provided since glibc 2.18 */
 #ifndef PF_VSOCK
@@ -120,7 +122,6 @@ static int follow_events;
 static int sctp_ino;
 static int show_tipcinfo;
 static int show_tos;
-int numeric;
 int oneline;
 
 enum col_id {
@@ -133,6 +134,7 @@ enum col_id {
        COL_RADDR,
        COL_RSERV,
        COL_EXT,
+       COL_PROC,
        COL_MAX
 };
 
@@ -160,6 +162,7 @@ static struct column columns[] = {
        { ALIGN_LEFT,   "Port",                 "",     0, 0, 0 },
        { ALIGN_RIGHT,  "Peer Address:",        " ",    0, 0, 0 },
        { ALIGN_LEFT,   "Port",                 "",     0, 0, 0 },
+       { ALIGN_LEFT,   "Process",              "",     0, 0, 0 },
        { ALIGN_LEFT,   "",                     "",     0, 0, 0 },
 };
 
@@ -1132,10 +1135,10 @@ static void buf_free_all(void)
        buffer.chunks = 0;
 }
 
-/* Get current screen width, default to 80 columns if TIOCGWINSZ fails */
+/* Get current screen width, returns -1 if TIOCGWINSZ fails */
 static int render_screen_width(void)
 {
-       int width = 80;
+       int width = -1;
 
        if (isatty(STDOUT_FILENO)) {
                struct winsize w;
@@ -1156,9 +1159,15 @@ static int render_screen_width(void)
  */
 static void render_calc_width(void)
 {
-       int screen_width = render_screen_width();
+       int screen_width, first, len = 0, linecols = 0;
        struct column *c, *eol = columns - 1;
-       int first, len = 0, linecols = 0;
+       bool compact_output = false;
+
+       screen_width = render_screen_width();
+       if (screen_width == -1) {
+               screen_width = INT_MAX;
+               compact_output = true;
+       }
 
        /* First pass: set width for each column to measured content length */
        for (first = 1, c = columns; c - columns < COL_MAX; c++) {
@@ -1180,6 +1189,11 @@ static void render_calc_width(void)
                        first = 0;
        }
 
+       if (compact_output) {
+               /* Compact output, skip extending columns. */
+               return;
+       }
+
        /* Second pass: find out newlines and distribute available spacing */
        for (c = columns; c - columns < COL_MAX; c++) {
                int pad, spacing, rem, last;
@@ -1287,6 +1301,11 @@ static void render(void)
 
                token = buf_token_next(token);
        }
+       /* Deal with final end-of-line when the last non-empty field printed
+        * is not the last field.
+        */
+       if (line_started)
+               printf("\n");
 
        buf_free_all();
        current_field = columns;
@@ -2751,6 +2770,72 @@ static void print_md5sig(struct tcp_diag_md5sig *sig)
        print_escape_buf(sig->tcpm_key, sig->tcpm_keylen, " ,");
 }
 
+static void tcp_tls_version(struct rtattr *attr)
+{
+       u_int16_t val;
+
+       if (!attr)
+               return;
+       val = rta_getattr_u16(attr);
+
+       switch (val) {
+       case TLS_1_2_VERSION:
+               out(" version: 1.2");
+               break;
+       case TLS_1_3_VERSION:
+               out(" version: 1.3");
+               break;
+       default:
+               out(" version: unknown(%hu)", val);
+               break;
+       }
+}
+
+static void tcp_tls_cipher(struct rtattr *attr)
+{
+       u_int16_t val;
+
+       if (!attr)
+               return;
+       val = rta_getattr_u16(attr);
+
+       switch (val) {
+       case TLS_CIPHER_AES_GCM_128:
+               out(" cipher: aes-gcm-128");
+               break;
+       case TLS_CIPHER_AES_GCM_256:
+               out(" cipher: aes-gcm-256");
+               break;
+       }
+}
+
+static void tcp_tls_conf(const char *name, struct rtattr *attr)
+{
+       u_int16_t val;
+
+       if (!attr)
+               return;
+       val = rta_getattr_u16(attr);
+
+       switch (val) {
+       case TLS_CONF_BASE:
+               out(" %s: none", name);
+               break;
+       case TLS_CONF_SW:
+               out(" %s: sw", name);
+               break;
+       case TLS_CONF_HW:
+               out(" %s: hw", name);
+               break;
+       case TLS_CONF_HW_RECORD:
+               out(" %s: hw-record", name);
+               break;
+       default:
+               out(" %s: unknown(%hu)", name, val);
+               break;
+       }
+}
+
 #define TCPI_HAS_OPT(info, opt) !!(info->tcpi_options & (opt))
 
 static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r,
@@ -2906,6 +2991,28 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r,
                        print_md5sig(sig++);
                }
        }
+       if (tb[INET_DIAG_ULP_INFO]) {
+               struct rtattr *ulpinfo[INET_ULP_INFO_MAX + 1] = { 0 };
+
+               parse_rtattr_nested(ulpinfo, INET_ULP_INFO_MAX,
+                                   tb[INET_DIAG_ULP_INFO]);
+
+               if (ulpinfo[INET_ULP_INFO_NAME])
+                       out(" tcp-ulp-%s",
+                           rta_getattr_str(ulpinfo[INET_ULP_INFO_NAME]));
+
+               if (ulpinfo[INET_ULP_INFO_TLS]) {
+                       struct rtattr *tlsinfo[TLS_INFO_MAX + 1] = { 0 };
+
+                       parse_rtattr_nested(tlsinfo, TLS_INFO_MAX,
+                                           ulpinfo[INET_ULP_INFO_TLS]);
+
+                       tcp_tls_version(tlsinfo[TLS_INFO_VERSION]);
+                       tcp_tls_cipher(tlsinfo[TLS_INFO_CIPHER]);
+                       tcp_tls_conf("rxconf", tlsinfo[TLS_INFO_RXCONF]);
+                       tcp_tls_conf("txconf", tlsinfo[TLS_INFO_TXCONF]);
+               }
+       }
 }
 
 static const char *format_host_sa(struct sockaddr_storage *sa)