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@uclouvain.be>
diff --git a/ip/tcp_metrics.c b/ip/tcp_metrics.c
index 4b30771..a7215c8 100644
--- a/ip/tcp_metrics.c
+++ b/ip/tcp_metrics.c
@@ -95,8 +95,8 @@
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 @@
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 @@
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);