]>
git.proxmox.com Git - mirror_iproute2.git/blob - tc/tc_monitor.c
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
17 #include <sys/socket.h>
18 #include <netinet/in.h>
19 #include <arpa/inet.h>
25 #include "tc_common.h"
28 static void usage(void) __attribute__((noreturn
));
30 static void usage(void)
32 fprintf(stderr
, "Usage: tc [-timestamp [-tshort] monitor\n");
37 static int accept_tcmsg(struct rtnl_ctrl_data
*ctrl
,
38 struct nlmsghdr
*n
, void *arg
)
40 FILE *fp
= (FILE *)arg
;
45 if (n
->nlmsg_type
== RTM_NEWTFILTER
||
46 n
->nlmsg_type
== RTM_DELTFILTER
||
47 n
->nlmsg_type
== RTM_NEWCHAIN
||
48 n
->nlmsg_type
== RTM_DELCHAIN
) {
52 if (n
->nlmsg_type
== RTM_NEWTCLASS
|| n
->nlmsg_type
== RTM_DELTCLASS
) {
56 if (n
->nlmsg_type
== RTM_NEWQDISC
|| n
->nlmsg_type
== RTM_DELQDISC
) {
60 if (n
->nlmsg_type
== RTM_GETACTION
|| n
->nlmsg_type
== RTM_NEWACTION
||
61 n
->nlmsg_type
== RTM_DELACTION
) {
65 if (n
->nlmsg_type
!= NLMSG_ERROR
&& n
->nlmsg_type
!= NLMSG_NOOP
&&
66 n
->nlmsg_type
!= NLMSG_DONE
) {
67 fprintf(fp
, "Unknown message: length %08d type %08x flags %08x\n",
68 n
->nlmsg_len
, n
->nlmsg_type
, n
->nlmsg_flags
);
73 int do_tcmonitor(int argc
, char **argv
)
75 struct rtnl_handle rth
;
77 unsigned int groups
= nl_mgrp(RTNLGRP_TC
);
80 if (matches(*argv
, "file") == 0) {
84 if (matches(*argv
, "help") == 0) {
87 fprintf(stderr
, "Argument \"%s\" is unknown, try \"tc monitor help\".\n", *argv
);
95 FILE *fp
= fopen(file
, "r");
99 perror("Cannot fopen");
103 ret
= rtnl_from_file(fp
, accept_tcmsg
, stdout
);
108 if (rtnl_open(&rth
, groups
) < 0)
113 if (rtnl_listen(&rth
, accept_tcmsg
, (void *)stdout
) < 0) {