]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
tcp_metrics: Display source-address
authorChristoph Paasch <christoph.paasch@uclouvain.be>
Thu, 6 Feb 2014 22:15:03 +0000 (23:15 +0100)
committerStephen Hemminger <stephen@networkplumber.org>
Mon, 10 Feb 2014 22:46:11 +0000 (14:46 -0800)
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>
ip/tcp_metrics.c

index 4b30771ae3a85979ae238cc721d1003cac4ffc79..a7215c86379fd670a65d4bc89a67b96070962ef5 100644 (file)
@@ -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);