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>
This commit is contained in:
parent
54b237a058
commit
114aa720fa
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue