From ecd44e680576c793f2a943d00301215f09882c59 Mon Sep 17 00:00:00 2001 From: Petr Vorel Date: Sun, 8 Oct 2017 16:39:16 +0200 Subject: [PATCH 1/4] tests: Remove bashisms (s/source/.) Signed-off-by: Petr Vorel --- testsuite/tests/ip/link/new_link.t | 2 +- testsuite/tests/ip/link/show_dev_wo_vf_rate.t | 2 +- testsuite/tests/ip/netns/set_nsid.t | 2 +- testsuite/tests/ip/netns/set_nsid_batch.t | 2 +- testsuite/tests/ip/route/add_default_route.t | 4 ++-- testsuite/tests/ip/tunnel/add_tunnel.t | 2 +- testsuite/tests/tc/cls-testbed.t | 2 +- testsuite/tests/tc/dsmark.t | 2 +- testsuite/tests/tc/pedit.t | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/testsuite/tests/ip/link/new_link.t b/testsuite/tests/ip/link/new_link.t index 699adbcd..c17650a2 100755 --- a/testsuite/tests/ip/link/new_link.t +++ b/testsuite/tests/ip/link/new_link.t @@ -1,6 +1,6 @@ #!/bin/sh -source lib/generic.sh +. lib/generic.sh ts_log "[Testing add/del virtual links]" diff --git a/testsuite/tests/ip/link/show_dev_wo_vf_rate.t b/testsuite/tests/ip/link/show_dev_wo_vf_rate.t index a600ba65..5b3c004e 100755 --- a/testsuite/tests/ip/link/show_dev_wo_vf_rate.t +++ b/testsuite/tests/ip/link/show_dev_wo_vf_rate.t @@ -1,6 +1,6 @@ #!/bin/sh -source lib/generic.sh +. lib/generic.sh NL_FILE="tests/ip/link/dev_wo_vf_rate.nl" ts_ip "$0" "Show VF devices w/o VF rate info" -d monitor file $NL_FILE diff --git a/testsuite/tests/ip/netns/set_nsid.t b/testsuite/tests/ip/netns/set_nsid.t index 606d45ab..8f8c7792 100755 --- a/testsuite/tests/ip/netns/set_nsid.t +++ b/testsuite/tests/ip/netns/set_nsid.t @@ -1,6 +1,6 @@ #!/bin/sh -source lib/generic.sh +. lib/generic.sh ts_log "[Testing netns nsid]" diff --git a/testsuite/tests/ip/netns/set_nsid_batch.t b/testsuite/tests/ip/netns/set_nsid_batch.t index abb3f1bb..196fd4b3 100755 --- a/testsuite/tests/ip/netns/set_nsid_batch.t +++ b/testsuite/tests/ip/netns/set_nsid_batch.t @@ -1,6 +1,6 @@ #!/bin/sh -source lib/generic.sh +. lib/generic.sh ts_log "[Testing netns nsid in batch mode]" diff --git a/testsuite/tests/ip/route/add_default_route.t b/testsuite/tests/ip/route/add_default_route.t index e5ea6473..0b566f1f 100755 --- a/testsuite/tests/ip/route/add_default_route.t +++ b/testsuite/tests/ip/route/add_default_route.t @@ -1,6 +1,6 @@ -#!/bin/sh +#!/bin/bash -source lib/generic.sh +. lib/generic.sh ts_log "[Testing add default route]" diff --git a/testsuite/tests/ip/tunnel/add_tunnel.t b/testsuite/tests/ip/tunnel/add_tunnel.t index 18f6e370..3f5a9d3c 100755 --- a/testsuite/tests/ip/tunnel/add_tunnel.t +++ b/testsuite/tests/ip/tunnel/add_tunnel.t @@ -1,6 +1,6 @@ #!/bin/sh -source lib/generic.sh +. lib/generic.sh TUNNEL_NAME="tunnel_test_ip" diff --git a/testsuite/tests/tc/cls-testbed.t b/testsuite/tests/tc/cls-testbed.t index 2afc26fc..d5c21e5c 100755 --- a/testsuite/tests/tc/cls-testbed.t +++ b/testsuite/tests/tc/cls-testbed.t @@ -1,7 +1,7 @@ #!/bin/bash # vim: ft=sh -source lib/generic.sh +. lib/generic.sh QDISCS="cbq htb dsmark" diff --git a/testsuite/tests/tc/dsmark.t b/testsuite/tests/tc/dsmark.t index 6934165e..177585e6 100755 --- a/testsuite/tests/tc/dsmark.t +++ b/testsuite/tests/tc/dsmark.t @@ -1,7 +1,7 @@ #!/bin/bash # vim: ft=sh -source lib/generic.sh +. lib/generic.sh ts_qdisc_available "dsmark" if [ $? -eq 0 ]; then diff --git a/testsuite/tests/tc/pedit.t b/testsuite/tests/tc/pedit.t index e9b6c333..8d531a05 100755 --- a/testsuite/tests/tc/pedit.t +++ b/testsuite/tests/tc/pedit.t @@ -1,6 +1,6 @@ #!/bin/sh -source lib/generic.sh +. lib/generic.sh DEV="$(rand_dev)" ts_ip "$0" "Add $DEV dummy interface" link add dev $DEV type dummy From 4f6b73380d2c84b98b7beffe6ca73f635ab72a06 Mon Sep 17 00:00:00 2001 From: Baruch Siach Date: Mon, 9 Oct 2017 08:49:44 +0300 Subject: [PATCH 2/4] lib: fix multiple strlcpy definition Some C libraries, like uClibc and musl, provide BSD compatible strlcpy(). Add check_strlcpy() to configure, and avoid defining strlcpy and strlcat when the C library provides them. This fixes the following static link error with uClibc-ng: .../sysroot/usr/lib/libc.a(strlcpy.os): In function `strlcpy': strlcpy.c:(.text+0x0): multiple definition of `strlcpy' ../lib/libutil.a(utils.o):utils.c:(.text+0x1ddc): first defined here collect2: error: ld returned 1 exit status Acked-by: Phil Sutter Signed-off-by: Baruch Siach --- configure | 24 ++++++++++++++++++++++++ lib/utils.c | 2 ++ 2 files changed, 26 insertions(+) diff --git a/configure b/configure index 7be8fb11..f0668ab3 100755 --- a/configure +++ b/configure @@ -326,6 +326,27 @@ EOF rm -f $TMPDIR/dbtest.c $TMPDIR/dbtest } +check_strlcpy() +{ + cat >$TMPDIR/strtest.c < +int main(int argc, char **argv) { + char dst[10]; + strlcpy(dst, "test", sizeof(dst)); + return 0; +} +EOF + $CC -I$INCLUDE -o $TMPDIR/strtest $TMPDIR/strtest.c >/dev/null 2>&1 + if [ $? -eq 0 ] + then + echo "no" + else + echo 'CFLAGS += -DNEED_STRLCPY' >>$CONFIG + echo "yes" + fi + rm -f $TMPDIR/strtest.c $TMPDIR/strtest +} + quiet_config() { cat < Date: Fri, 6 Oct 2017 16:48:19 -0700 Subject: [PATCH 3/4] utils: add print_escape_buf to format and print arbitrary bytes Keep it as simple as possible for now: just escape anything that is not isprint-able, is among the "escape" parameter or '\' as an octal escape sequence. This should be pretty easy to extend if any other user needs something more complex in the future. Signed-off-by: Ivan Delalande --- include/utils.h | 2 ++ lib/utils.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/utils.h b/include/utils.h index 76addb32..3d91c50d 100644 --- a/include/utils.h +++ b/include/utils.h @@ -195,6 +195,8 @@ static inline void __jiffies_to_tv(struct timeval *tv, unsigned long jiffies) tv->tv_usec = tvusec - 1000000 * tv->tv_sec; } +void print_escape_buf(const __u8 *buf, size_t len, const char *escape); + int print_timestamp(FILE *fp); void print_nlmsg_timestamp(FILE *fp, const struct nlmsghdr *n); diff --git a/lib/utils.c b/lib/utils.c index 632fd0dd..ac155bf5 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "rt_names.h" #include "utils.h" @@ -1047,6 +1048,20 @@ int addr64_n2a(__u64 addr, char *buff, size_t len) return written; } +/* Print buffer and escape bytes that are !isprint or among 'escape' */ +void print_escape_buf(const __u8 *buf, size_t len, const char *escape) +{ + size_t i; + + for (i = 0; i < len; ++i) { + if (isprint(buf[i]) && buf[i] != '\\' && + !strchr(escape, buf[i])) + printf("%c", buf[i]); + else + printf("\\%03o", buf[i]); + } +} + int print_timestamp(FILE *fp) { struct timeval tv; From da9cc6ab90186e5c1b6dd1d194c18c967e1a7869 Mon Sep 17 00:00:00 2001 From: Ivan Delalande Date: Fri, 6 Oct 2017 16:48:20 -0700 Subject: [PATCH 4/4] 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 --- misc/ss.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/misc/ss.c b/misc/ss.c index dd8dfaa4..09bff8a7 100644 --- a/misc/ss.c +++ b/misc/ss.c @@ -2153,6 +2153,16 @@ static void print_skmeminfo(struct rtattr *tb[], int attrtype) printf(")"); } +static void print_md5sig(struct tcp_diag_md5sig *sig) +{ + printf("%s/%d=", + format_host(sig->tcpm_family, + sig->tcpm_family == AF_INET6 ? 16 : 4, + &sig->tcpm_addr), + sig->tcpm_prefixlen); + print_escape_buf(sig->tcpm_key, sig->tcpm_keylen, " ,"); +} + #define TCPI_HAS_OPT(info, opt) !!(info->tcpi_options & (opt)) 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, free(s.dctcp); free(s.bbr_info); } + if (tb[INET_DIAG_MD5SIG]) { + struct tcp_diag_md5sig *sig = RTA_DATA(tb[INET_DIAG_MD5SIG]); + int len = RTA_PAYLOAD(tb[INET_DIAG_MD5SIG]); + + printf(" md5keys:"); + print_md5sig(sig++); + for (len -= sizeof(*sig); len > 0; len -= sizeof(*sig)) { + printf(","); + print_md5sig(sig++); + } + } } static const char *format_host_sa(struct sockaddr_storage *sa)