monitor: Add option to not print rtnl output

This commit is contained in:
Denis Kenzior 2016-07-13 10:14:28 -05:00
parent c6fb438c73
commit d6a9b0f85a
3 changed files with 17 additions and 5 deletions

View File

@ -49,6 +49,7 @@
static struct nlmon *nlmon = NULL;
static const char *writer_path = NULL;
static struct l_timeout *timeout = NULL;
static bool nortnl;
#define NLA_OK(nla,len) ((len) >= (int) sizeof(struct nlattr) && \
(nla)->nla_len >= sizeof(struct nlattr) && \
@ -104,7 +105,7 @@ static void genl_parse(uint16_t type, const void *data, uint32_t len,
return;
if (!strcmp(name, NL80211_GENL_NAME)) {
nlmon = nlmon_open(ifname, id, writer_path);
nlmon = nlmon_open(ifname, id, writer_path, nortnl);
if (!nlmon)
l_main_quit();
}
@ -681,6 +682,7 @@ static const struct option main_options[] = {
{ "analyze", required_argument, NULL, 'a' },
{ "nl80211", required_argument, NULL, 'F' },
{ "interface", required_argument, NULL, 'i' },
{ "nortnl", no_argument, NULL, 'n' },
{ "version", no_argument, NULL, 'v' },
{ "help", no_argument, NULL, 'h' },
{ }
@ -700,7 +702,7 @@ int main(int argc, char *argv[])
for (;;) {
int opt;
opt = getopt_long(argc, argv, "r:w:a:F:i:vh",
opt = getopt_long(argc, argv, "r:w:a:F:i:nvh",
main_options, NULL);
if (opt < 0)
break;
@ -738,6 +740,9 @@ int main(int argc, char *argv[])
case 'i':
ifname = optarg;
break;
case 'n':
nortnl = true;
break;
case 'v':
printf("%s\n", VERSION);
return EXIT_SUCCESS;

View File

@ -93,6 +93,7 @@ struct nlmon {
struct l_io *pae_io;
struct l_queue *req_list;
struct pcap *pcap;
bool nortnl;
};
struct nlmon_req {
@ -4616,7 +4617,10 @@ static bool nlmon_receive(struct l_io *io, void *user_data)
switch (proto_type) {
case NETLINK_ROUTE:
store_netlink(nlmon, tv, proto_type, nlmsg);
nlmon_print_rtnl(nlmon, tv, nlmsg, nlmsg->nlmsg_len);
if (!nlmon->nortnl)
nlmon_print_rtnl(nlmon, tv, nlmsg,
nlmsg->nlmsg_len);
break;
case NETLINK_GENERIC:
nlmon_message(nlmon, tv, tp, nlmsg);
@ -4920,7 +4924,8 @@ static struct l_io *open_pae(void)
return io;
}
struct nlmon *nlmon_open(const char *ifname, uint16_t id, const char *pathname)
struct nlmon *nlmon_open(const char *ifname, uint16_t id, const char *pathname,
bool nortnl)
{
struct nlmon *nlmon;
struct l_io *io, *pae_io;
@ -4953,6 +4958,7 @@ struct nlmon *nlmon_open(const char *ifname, uint16_t id, const char *pathname)
nlmon->pae_io = pae_io;
nlmon->req_list = l_queue_new();
nlmon->pcap = pcap;
nlmon->nortnl = nortnl;
l_io_set_read_handler(nlmon->io, nlmon_receive, nlmon, NULL);
l_io_set_read_handler(nlmon->pae_io, pae_receive, nlmon, NULL);

View File

@ -25,7 +25,8 @@
struct nlmon;
struct nlmon *nlmon_open(const char *ifname, uint16_t id, const char *pathname);
struct nlmon *nlmon_open(const char *ifname, uint16_t id, const char *pathname,
bool nortnl);
void nlmon_close(struct nlmon *nlmon);
struct nlmon *nlmon_create(uint16_t id);