]>
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 [file | link | fdb | mdb | all]\n");
38 static int accept_msg(const struct sockaddr_nl
*who
,
39 struct rtnl_ctrl_data
*ctrl
,
40 struct nlmsghdr
*n
, void *arg
)
47 switch (n
->nlmsg_type
) {
51 fprintf(fp
, "[LINK]");
53 return print_linkinfo(who
, n
, arg
);
58 fprintf(fp
, "[NEIGH]");
59 return print_fdb(who
, n
, arg
);
65 return print_mdb(who
, n
, arg
);
68 print_nlmsg_timestamp(fp
, n
);
76 int do_monitor(int argc
, char **argv
)
79 unsigned int groups
= ~RTMGRP_TC
;
87 if (matches(*argv
, "file") == 0) {
90 } else if (matches(*argv
, "link") == 0) {
93 } else if (matches(*argv
, "fdb") == 0) {
96 } else if (matches(*argv
, "mdb") == 0) {
99 } else if (strcmp(*argv
, "all") == 0) {
102 } else if (matches(*argv
, "help") == 0) {
105 fprintf(stderr
, "Argument \"%s\" is unknown, try \"bridge monitor help\".\n", *argv
);
112 groups
|= nl_mgrp(RTNLGRP_LINK
);
115 groups
|= nl_mgrp(RTNLGRP_NEIGH
);
119 groups
|= nl_mgrp(RTNLGRP_MDB
);
126 fp
= fopen(file
, "r");
128 perror("Cannot fopen");
131 err
= rtnl_from_file(fp
, accept_msg
, stdout
);
136 if (rtnl_open(&rth
, groups
) < 0)
140 if (rtnl_listen(&rth
, accept_msg
, stdout
) < 0)