lists.openwall.net | lists / announce owl-users owl-dev john-users john-dev passwdqc-users yescrypt popa3d-users / oss-security kernel-hardening musl sabotage tlsify passwords / crypt-dev xvendor / Bugtraq Full-Disclosure linux-kernel linux-netdev linux-ext4 linux-hardening PHC | |
Open Source and information security mailing list archives
| ||
|
Date: Thu, 6 Feb 2014 23:15:03 +0100 From: Christoph Paasch <christoph.paasch@...ouvain.be> To: Stephen Hemminger <stephen@...workplumber.org> Cc: netdev@...r.kernel.org Subject: [PATCH iproute2 2/3] tcp_metrics: Display source-address This patch allows to display the source-IP. stype will be used in the next patch that allows to remove based on the source-IP. Signed-off-by: Christoph Paasch <christoph.paasch@...ouvain.be> --- include/linux/tcp_metrics.h | 2 ++ ip/tcp_metrics.c | 30 ++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/include/linux/tcp_metrics.h b/include/linux/tcp_metrics.h index cb5157b55f32..54a37b13f2c4 100644 --- a/include/linux/tcp_metrics.h +++ b/include/linux/tcp_metrics.h @@ -35,6 +35,8 @@ enum { TCP_METRICS_ATTR_FOPEN_SYN_DROPS, /* u16, count of drops */ TCP_METRICS_ATTR_FOPEN_SYN_DROP_TS, /* msecs age */ TCP_METRICS_ATTR_FOPEN_COOKIE, /* binary */ + TCP_METRICS_ATTR_SADDR_IPV4, /* u32 */ + TCP_METRICS_ATTR_SADDR_IPV6, /* binary */ __TCP_METRICS_ATTR_MAX, }; diff --git a/ip/tcp_metrics.c b/ip/tcp_metrics.c index 4b30771ae3a8..a7215c86379f 100644 --- a/ip/tcp_metrics.c +++ b/ip/tcp_metrics.c @@ -95,8 +95,8 @@ static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n, struct rtattr *attrs[TCP_METRICS_ATTR_MAX + 1], *a; int len = n->nlmsg_len; char abuf[256]; - inet_prefix daddr; - int family, i, atype, dlen = 0; + inet_prefix daddr, saddr; + int family, i, atype, stype, dlen = 0, slen = 0; if (n->nlmsg_type != genl_family) return -1; @@ -135,6 +135,26 @@ static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n, return 0; } + a = attrs[TCP_METRICS_ATTR_SADDR_IPV4]; + if (a) { + if (f.saddr.family && f.saddr.family != AF_INET) + return 0; + memcpy(&saddr.data, RTA_DATA(a), 4); + saddr.bytelen = 4; + stype = TCP_METRICS_ATTR_SADDR_IPV4; + slen = RTA_PAYLOAD(a); + } else { + a = attrs[TCP_METRICS_ATTR_SADDR_IPV6]; + if (a) { + if (f.saddr.family && f.saddr.family != AF_INET6) + return 0; + memcpy(&saddr.data, RTA_DATA(a), 16); + saddr.bytelen = 16; + stype = TCP_METRICS_ATTR_SADDR_IPV6; + slen = RTA_PAYLOAD(a); + } + } + if (f.daddr.family && f.daddr.bitlen >= 0 && inet_addr_match(&daddr, &f.daddr, f.daddr.bitlen)) return 0; @@ -248,6 +268,12 @@ static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n, fprintf(fp, " fo_cookie %s", cookie); } + if (slen) { + fprintf(fp, " source %s", + format_host(family, slen, &saddr.data, abuf, + sizeof(abuf))); + } + fprintf(fp, "\n"); fflush(fp); -- 1.8.3.2 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@...r.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists