]>
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
));
30 static int prefix_banner
;
32 static void usage(void)
34 fprintf(stderr
, "Usage: bridge monitor [file | link | fdb | mdb | all]\n");
38 static int accept_msg(struct rtnl_ctrl_data
*ctrl
,
39 struct nlmsghdr
*n
, void *arg
)
46 switch (n
->nlmsg_type
) {
50 fprintf(fp
, "[LINK]");
52 return print_linkinfo(n
, arg
);
57 fprintf(fp
, "[NEIGH]");
58 return print_fdb(n
, arg
);
64 return print_mdb_mon(n
, arg
);
67 print_nlmsg_timestamp(fp
, n
);
75 int do_monitor(int argc
, char **argv
)
78 unsigned int groups
= ~RTMGRP_TC
;
86 if (matches(*argv
, "file") == 0) {
89 } else if (matches(*argv
, "link") == 0) {
92 } else if (matches(*argv
, "fdb") == 0) {
95 } else if (matches(*argv
, "mdb") == 0) {
98 } else if (strcmp(*argv
, "all") == 0) {
101 } else if (matches(*argv
, "help") == 0) {
104 fprintf(stderr
, "Argument \"%s\" is unknown, try \"bridge monitor help\".\n", *argv
);
111 groups
|= nl_mgrp(RTNLGRP_LINK
);
114 groups
|= nl_mgrp(RTNLGRP_NEIGH
);
118 groups
|= nl_mgrp(RTNLGRP_MDB
);
125 fp
= fopen(file
, "r");
127 perror("Cannot fopen");
130 err
= rtnl_from_file(fp
, accept_msg
, stdout
);
135 if (rtnl_open(&rth
, groups
) < 0)
139 if (rtnl_listen(&rth
, accept_msg
, stdout
) < 0)