]>
git.proxmox.com Git - mirror_iproute2.git/blob - bridge/monitor.c
2 * brmonitor.c "bridge 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: Stephen Hemminger <shemminger@vyatta.com>
17 #include <sys/socket.h>
20 #include <netinet/in.h>
21 #include <linux/if_bridge.h>
22 #include <linux/neighbour.h>
26 #include "br_common.h"
29 static void usage(void) __attribute__((noreturn
));
32 static void usage(void)
34 fprintf(stderr
, "Usage: bridge monitor\n");
38 static int show_mark(FILE *fp
, const struct nlmsghdr
*n
)
41 time_t secs
= ((__u32
*)NLMSG_DATA(n
))[0];
42 long usecs
= ((__u32
*)NLMSG_DATA(n
))[1];
43 tstr
= asctime(localtime(&secs
));
44 tstr
[strlen(tstr
)-1] = 0;
45 fprintf(fp
, "Timestamp: %s %lu us\n", tstr
, usecs
);
49 int accept_msg(const struct sockaddr_nl
*who
,
50 struct nlmsghdr
*n
, void *arg
)
57 switch (n
->nlmsg_type
) {
61 fprintf(fp
, "[LINK]");
63 return print_linkinfo(who
, n
, arg
);
68 fprintf(fp
, "[NEIGH]");
69 return print_fdb(who
, n
, arg
);
72 return show_mark(fp
, n
);
81 int do_monitor(int argc
, char **argv
)
84 unsigned groups
= ~RTMGRP_TC
;
91 if (matches(*argv
, "file") == 0) {
94 } else if (matches(*argv
, "link") == 0) {
97 } else if (matches(*argv
, "fdb") == 0) {
100 } else if (strcmp(*argv
, "all") == 0) {
103 } else if (matches(*argv
, "help") == 0) {
106 fprintf(stderr
, "Argument \"%s\" is unknown, try \"bridge monitor help\".\n", *argv
);
113 groups
|= nl_mgrp(RTNLGRP_LINK
);
116 groups
|= nl_mgrp(RTNLGRP_NEIGH
);
121 fp
= fopen(file
, "r");
123 perror("Cannot fopen");
126 return rtnl_from_file(fp
, accept_msg
, stdout
);
129 if (rtnl_open(&rth
, groups
) < 0)
133 if (rtnl_listen(&rth
, accept_msg
, stdout
) < 0)