From 5c5bfbb4231e4c7fec148a4649603e79d8ad7a55 Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Tue, 15 May 2018 15:08:47 -0700 Subject: [PATCH] monitor: added scan/wiphy flags Specifying --noscan will filter out any scan related packets Specifying --nowiphy will filter out any "new wiphy" packets --- monitor/main.c | 18 ++++++++++++++---- monitor/nlmon.c | 24 ++++++++++++++++++------ monitor/nlmon.h | 8 +++++++- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/monitor/main.c b/monitor/main.c index bf5da9df..2c0e6190 100644 --- a/monitor/main.c +++ b/monitor/main.c @@ -49,7 +49,7 @@ static struct nlmon *nlmon = NULL; static const char *writer_path = NULL; static struct l_timeout *timeout = NULL; -static bool nortnl; +static struct nlmon_config config; #define NLA_OK(nla,len) ((len) >= (int) sizeof(struct nlattr) && \ (nla)->nla_len >= sizeof(struct nlattr) && \ @@ -105,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, nortnl); + nlmon = nlmon_open(ifname, id, writer_path, &config); if (!nlmon) l_main_quit(); } @@ -674,6 +674,8 @@ static void usage(void) "\t-a, --analyze Analyze netlink PCAP trace file\n" "\t-i, --interface Use specified netlink monitor\n" "\t-n, --nortnl Don't show RTNL output\n" + "\t-y, --nowiphy Don't show 'New Wiphy' output\n" + "\t-s, --noscan Don't show scan result output\n" "\t-h, --help Show help options\n"); } @@ -684,6 +686,8 @@ static const struct option main_options[] = { { "nl80211", required_argument, NULL, 'F' }, { "interface", required_argument, NULL, 'i' }, { "nortnl", no_argument, NULL, 'n' }, + { "nowiphy", no_argument, NULL, 'y' }, + { "noscan", no_argument, NULL, 's' }, { "version", no_argument, NULL, 'v' }, { "help", no_argument, NULL, 'h' }, { } @@ -703,7 +707,7 @@ int main(int argc, char *argv[]) for (;;) { int opt; - opt = getopt_long(argc, argv, "r:w:a:F:i:nvh", + opt = getopt_long(argc, argv, "r:w:a:F:i:nvhys", main_options, NULL); if (opt < 0) break; @@ -742,7 +746,13 @@ int main(int argc, char *argv[]) ifname = optarg; break; case 'n': - nortnl = true; + config.nortnl = true; + break; + case 'y': + config.nowiphy = true; + break; + case 's': + config.noscan = true; break; case 'v': printf("%s\n", VERSION); diff --git a/monitor/nlmon.c b/monitor/nlmon.c index 81650b2e..9de30b7e 100644 --- a/monitor/nlmon.c +++ b/monitor/nlmon.c @@ -94,6 +94,8 @@ struct nlmon { struct l_queue *req_list; struct pcap *pcap; bool nortnl; + bool nowiphy; + bool noscan; }; struct nlmon_req { @@ -3945,7 +3947,8 @@ static void netlink_str(char *str, size_t size, } } -static void print_message(const struct timeval *tv, enum msg_type type, +static void print_message(struct nlmon *nlmon, const struct timeval *tv, + enum msg_type type, uint16_t flags, int status, uint8_t cmd, uint8_t version, const void *data, uint32_t len) @@ -3957,6 +3960,13 @@ static void print_message(const struct timeval *tv, enum msg_type type, bool out = false; int i; + if (nlmon->nowiphy && (cmd == NL80211_CMD_NEW_WIPHY)) + return; + + if (nlmon->noscan && ((cmd == NL80211_CMD_NEW_SCAN_RESULTS) || + (cmd == NL80211_CMD_TRIGGER_SCAN))) + return; + switch (type) { case MSG_REQUEST: label = "Request"; @@ -4099,7 +4109,7 @@ static void nlmon_message(struct nlmon *nlmon, const struct timeval *tv, } store_message(nlmon, tv, nlmsg); - print_message(tv, type, nlmsg->nlmsg_flags, status, + print_message(nlmon, tv, type, nlmsg->nlmsg_flags, status, req->cmd, req->version, NULL, sizeof(status)); nlmon_req_free(req); @@ -4128,7 +4138,7 @@ static void nlmon_message(struct nlmon *nlmon, const struct timeval *tv, l_queue_push_tail(nlmon->req_list, req); store_message(nlmon, tv, nlmsg); - print_message(tv, MSG_REQUEST, flags, 0, + print_message(nlmon, tv, MSG_REQUEST, flags, 0, req->cmd, req->version, NLMSG_DATA(nlmsg) + GENL_HDRLEN, NLMSG_PAYLOAD(nlmsg, GENL_HDRLEN)); @@ -4151,7 +4161,7 @@ static void nlmon_message(struct nlmon *nlmon, const struct timeval *tv, } store_message(nlmon, tv, nlmsg); - print_message(tv, type, nlmsg->nlmsg_flags, 0, + print_message(nlmon, tv, type, nlmsg->nlmsg_flags, 0, genlmsg->cmd, genlmsg->version, NLMSG_DATA(nlmsg) + GENL_HDRLEN, NLMSG_PAYLOAD(nlmsg, GENL_HDRLEN)); @@ -5288,7 +5298,7 @@ static struct l_io *open_pae(void) } struct nlmon *nlmon_open(const char *ifname, uint16_t id, const char *pathname, - bool nortnl) + const struct nlmon_config *config) { struct nlmon *nlmon; struct l_io *io, *pae_io; @@ -5321,7 +5331,9 @@ 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; + nlmon->nortnl = config->nortnl; + nlmon->nowiphy = config->nowiphy; + nlmon->noscan = config->noscan; l_io_set_read_handler(nlmon->io, nlmon_receive, nlmon, NULL); l_io_set_read_handler(nlmon->pae_io, pae_receive, nlmon, NULL); diff --git a/monitor/nlmon.h b/monitor/nlmon.h index d833e07d..9b26a5ef 100644 --- a/monitor/nlmon.h +++ b/monitor/nlmon.h @@ -25,8 +25,14 @@ struct nlmon; +struct nlmon_config { + bool nortnl; + bool nowiphy; + bool noscan; +}; + struct nlmon *nlmon_open(const char *ifname, uint16_t id, const char *pathname, - bool nortnl); + const struct nlmon_config *config); void nlmon_close(struct nlmon *nlmon); struct nlmon *nlmon_create(uint16_t id);