]>
git.proxmox.com Git - mirror_iproute2.git/blob - tc/tc_monitor.c
ebb94320837bd123f721d134c6892a194169ae32
2 * tc_monitor.c "tc monitor".
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Authors: Jamal Hadi Salim
18 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
26 #include "tc_common.h"
29 static void usage(void) __attribute__((noreturn
));
31 static void usage(void)
33 fprintf(stderr
, "Usage: tc [-timestamp [-tshort] monitor\n");
38 static int accept_tcmsg(const struct sockaddr_nl
*who
,
39 struct rtnl_ctrl_data
*ctrl
,
40 struct nlmsghdr
*n
, void *arg
)
42 FILE *fp
= (FILE*)arg
;
47 if (n
->nlmsg_type
== RTM_NEWTFILTER
|| n
->nlmsg_type
== RTM_DELTFILTER
) {
48 print_filter(who
, n
, arg
);
51 if (n
->nlmsg_type
== RTM_NEWTCLASS
|| n
->nlmsg_type
== RTM_DELTCLASS
) {
52 print_class(who
, n
, arg
);
55 if (n
->nlmsg_type
== RTM_NEWQDISC
|| n
->nlmsg_type
== RTM_DELQDISC
) {
56 print_qdisc(who
, n
, arg
);
59 if (n
->nlmsg_type
== RTM_GETACTION
|| n
->nlmsg_type
== RTM_NEWACTION
||
60 n
->nlmsg_type
== RTM_DELACTION
) {
61 print_action(who
, n
, arg
);
64 if (n
->nlmsg_type
!= NLMSG_ERROR
&& n
->nlmsg_type
!= NLMSG_NOOP
&&
65 n
->nlmsg_type
!= NLMSG_DONE
) {
66 fprintf(fp
, "Unknown message: length %08d type %08x flags %08x\n",
67 n
->nlmsg_len
, n
->nlmsg_type
, n
->nlmsg_flags
);
72 int do_tcmonitor(int argc
, char **argv
)
74 struct rtnl_handle rth
;
76 unsigned groups
= nl_mgrp(RTNLGRP_TC
);
79 if (matches(*argv
, "file") == 0) {
83 if (matches(*argv
, "help") == 0) {
86 fprintf(stderr
, "Argument \"%s\" is unknown, try \"tc monitor help\".\n", *argv
);
94 FILE *fp
= fopen(file
, "r");
98 perror("Cannot fopen");
102 ret
= rtnl_from_file(fp
, accept_tcmsg
, stdout
);
107 if (rtnl_open(&rth
, groups
) < 0)
112 if (rtnl_listen(&rth
, accept_tcmsg
, (void*)stdout
) < 0) {