]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - tc/tc_monitor.c
iproute2: add check_libbpf() and get_libbpf_version()
[mirror_iproute2.git] / tc / tc_monitor.c
index 0efe0343db0becd181bb2d5376d8f9d0f0ca1b6a..f8816cc53a46a077d7bd9f6f6f5e6269af3edb89 100644 (file)
@@ -13,7 +13,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -30,31 +29,37 @@ static void usage(void) __attribute__((noreturn));
 
 static void usage(void)
 {
-       fprintf(stderr, "Usage: tc monitor\n");
+       fprintf(stderr, "Usage: tc [-timestamp [-tshort] monitor\n");
        exit(-1);
 }
 
 
-static int accept_tcmsg(const struct sockaddr_nl *who,
+static int accept_tcmsg(struct rtnl_ctrl_data *ctrl,
                        struct nlmsghdr *n, void *arg)
 {
-       FILE *fp = (FILE*)arg;
+       FILE *fp = (FILE *)arg;
 
-       if (n->nlmsg_type == RTM_NEWTFILTER || n->nlmsg_type == RTM_DELTFILTER) {
-               print_filter(who, n, arg);
+       if (timestamp)
+               print_timestamp(fp);
+
+       if (n->nlmsg_type == RTM_NEWTFILTER ||
+           n->nlmsg_type == RTM_DELTFILTER ||
+           n->nlmsg_type == RTM_NEWCHAIN ||
+           n->nlmsg_type == RTM_DELCHAIN) {
+               print_filter(n, arg);
                return 0;
        }
        if (n->nlmsg_type == RTM_NEWTCLASS || n->nlmsg_type == RTM_DELTCLASS) {
-               print_class(who, n, arg);
+               print_class(n, arg);
                return 0;
        }
        if (n->nlmsg_type == RTM_NEWQDISC || n->nlmsg_type == RTM_DELQDISC) {
-               print_qdisc(who, n, arg);
+               print_qdisc(n, arg);
                return 0;
        }
        if (n->nlmsg_type == RTM_GETACTION || n->nlmsg_type == RTM_NEWACTION ||
            n->nlmsg_type == RTM_DELACTION) {
-               print_action(who, n, arg);
+               print_action(n, arg);
                return 0;
        }
        if (n->nlmsg_type != NLMSG_ERROR && n->nlmsg_type != NLMSG_NOOP &&
@@ -69,7 +74,7 @@ int do_tcmonitor(int argc, char **argv)
 {
        struct rtnl_handle rth;
        char *file = NULL;
-       unsigned groups = nl_mgrp(RTNLGRP_TC);
+       unsigned int groups = nl_mgrp(RTNLGRP_TC);
 
        while (argc > 0) {
                if (matches(*argv, "file") == 0) {
@@ -87,13 +92,17 @@ int do_tcmonitor(int argc, char **argv)
        }
 
        if (file) {
-               FILE *fp;
-               fp = fopen(file, "r");
+               FILE *fp = fopen(file, "r");
+               int ret;
+
                if (fp == NULL) {
                        perror("Cannot fopen");
                        exit(-1);
                }
-               return rtnl_from_file(fp, accept_tcmsg, (void*)stdout);
+
+               ret = rtnl_from_file(fp, accept_tcmsg, stdout);
+               fclose(fp);
+               return ret;
        }
 
        if (rtnl_open(&rth, groups) < 0)
@@ -101,7 +110,7 @@ int do_tcmonitor(int argc, char **argv)
 
        ll_init_map(&rth);
 
-       if (rtnl_listen(&rth, accept_tcmsg, (void*)stdout) < 0) {
+       if (rtnl_listen(&rth, accept_tcmsg, (void *)stdout) < 0) {
                rtnl_close(&rth);
                exit(2);
        }