From dce80974dcd2114ebb4a3ed3060d4d636cbb9d1d Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Mon, 20 Apr 2015 12:43:08 +0300 Subject: netsniff-ng: Delete rfmon mac80211 device in case of panic netsniff-ng does not delete created rfmon device in case of panic (for example - bad pcap filter expression), so added ability to add callback func when panic will be happen and delete rfmon device. Signed-off-by: Vadim Kochan Signed-off-by: Tobias Klauser --- netsniff-ng.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'netsniff-ng.c') diff --git a/netsniff-ng.c b/netsniff-ng.c index 2eafe31..c0d70c8 100644 --- a/netsniff-ng.c +++ b/netsniff-ng.c @@ -184,6 +184,20 @@ static inline bool dump_to_pcap(struct ctx *ctx) return ctx->dump; } +static void on_panic_del_rfmon(void *arg) +{ + leave_rfmon_mac80211(arg); +} + +static inline void setup_rfmon_mac80211_dev(struct ctx *ctx, char **rfmon_dev) +{ + ctx->device_trans = xstrdup(*rfmon_dev); + xfree(*rfmon_dev); + + enter_rfmon_mac80211(ctx->device_trans, rfmon_dev); + panic_func_add(on_panic_del_rfmon, *rfmon_dev); +} + static void pcap_to_xmit(struct ctx *ctx) { uint8_t *out = NULL; @@ -227,10 +241,8 @@ static void pcap_to_xmit(struct ctx *ctx) } if (ctx->rfraw) { - ctx->device_trans = xstrdup(ctx->device_out); - xfree(ctx->device_out); + setup_rfmon_mac80211_dev(ctx, &ctx->device_out); - enter_rfmon_mac80211(ctx->device_trans, &ctx->device_out); if (ctx->link_type != LINKTYPE_IEEE802_11 && ctx->link_type != LINKTYPE_IEEE802_11_RADIOTAP) panic("Wrong linktype of pcap!\n"); @@ -1464,12 +1476,8 @@ int main(int argc, char **argv) } if (device_mtu(ctx.device_in) || !strncmp("any", ctx.device_in, strlen(ctx.device_in))) { - if (ctx.rfraw) { - ctx.device_trans = xstrdup(ctx.device_in); - xfree(ctx.device_in); - - enter_rfmon_mac80211(ctx.device_trans, &ctx.device_in); - } + if (ctx.rfraw) + setup_rfmon_mac80211_dev(&ctx, &ctx.device_in); ctx.link_type = pcap_devtype_to_linktype(ctx.device_in); -- cgit v1.2.3-54-g00ecf