Skip to content

Commit da9cc6a

Browse files
colonashemminger
authored andcommitted
ss: print MD5 signature keys configured on TCP sockets
These keys are reported by kernel 4.14 and later under the INET_DIAG_MD5SIG attribute, when INET_DIAG_INFO is requested (ss -i) and we have CAP_NET_ADMIN. The additional output looks like: md5keys:fe80::/64=signing_key,10.1.2.0/24=foobar,::1/128=Test Signed-off-by: Ivan Delalande <colona@arista.com>
1 parent 7c72df5 commit da9cc6a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

misc/ss.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,6 +2153,16 @@ static void print_skmeminfo(struct rtattr *tb[], int attrtype)
21532153
printf(")");
21542154
}
21552155

2156+
static void print_md5sig(struct tcp_diag_md5sig *sig)
2157+
{
2158+
printf("%s/%d=",
2159+
format_host(sig->tcpm_family,
2160+
sig->tcpm_family == AF_INET6 ? 16 : 4,
2161+
&sig->tcpm_addr),
2162+
sig->tcpm_prefixlen);
2163+
print_escape_buf(sig->tcpm_key, sig->tcpm_keylen, " ,");
2164+
}
2165+
21562166
#define TCPI_HAS_OPT(info, opt) !!(info->tcpi_options & (opt))
21572167

21582168
static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r,
@@ -2289,6 +2299,17 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r,
22892299
free(s.dctcp);
22902300
free(s.bbr_info);
22912301
}
2302+
if (tb[INET_DIAG_MD5SIG]) {
2303+
struct tcp_diag_md5sig *sig = RTA_DATA(tb[INET_DIAG_MD5SIG]);
2304+
int len = RTA_PAYLOAD(tb[INET_DIAG_MD5SIG]);
2305+
2306+
printf(" md5keys:");
2307+
print_md5sig(sig++);
2308+
for (len -= sizeof(*sig); len > 0; len -= sizeof(*sig)) {
2309+
printf(",");
2310+
print_md5sig(sig++);
2311+
}
2312+
}
22922313
}
22932314

22942315
static const char *format_host_sa(struct sockaddr_storage *sa)

0 commit comments

Comments
 (0)