]>
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 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 static 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
);
75 return print_mdb(who
, n
, arg
);
78 return show_mark(fp
, n
);
87 int do_monitor(int argc
, char **argv
)
90 unsigned groups
= ~RTMGRP_TC
;
98 if (matches(*argv
, "file") == 0) {
101 } else if (matches(*argv
, "link") == 0) {
104 } else if (matches(*argv
, "fdb") == 0) {
107 } else if (matches(*argv
, "mdb") == 0) {
110 } else if (strcmp(*argv
, "all") == 0) {
113 } else if (matches(*argv
, "help") == 0) {
116 fprintf(stderr
, "Argument \"%s\" is unknown, try \"bridge monitor help\".\n", *argv
);
123 groups
|= nl_mgrp(RTNLGRP_LINK
);
126 groups
|= nl_mgrp(RTNLGRP_NEIGH
);
130 groups
|= nl_mgrp(RTNLGRP_MDB
);
136 fp
= fopen(file
, "r");
138 perror("Cannot fopen");
141 err
= rtnl_from_file(fp
, accept_msg
, stdout
);
146 if (rtnl_open(&rth
, groups
) < 0)
150 if (rtnl_listen(&rth
, accept_msg
, stdout
) < 0)