wlantest: Add RELOG command to reopen log/capture files

This can be used similarly to the wpa_supplicant RELOG command to
rotate log and capture files.

Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2013-11-17 21:11:35 +02:00
parent 0e91337d54
commit c99a721e5b
5 changed files with 54 additions and 10 deletions

View file

@ -1,6 +1,6 @@
/* /*
* wlantest control interface * wlantest control interface
* Copyright (c) 2010, Jouni Malinen <j@w1.fi> * Copyright (c) 2010-2013, Jouni Malinen <j@w1.fi>
* *
* This software may be distributed under the terms of the BSD license. * This software may be distributed under the terms of the BSD license.
* See README for more details. * See README for more details.
@ -1187,6 +1187,14 @@ static void ctrl_send_(struct wlantest *wt, int sock, u8 *cmd, size_t clen)
} }
static void ctrl_relog(struct wlantest *wt, int sock)
{
int res = wlantest_relog(wt);
ctrl_send_simple(wt, sock, res ? WLANTEST_CTRL_FAILURE :
WLANTEST_CTRL_SUCCESS);
}
static void ctrl_read(int sock, void *eloop_ctx, void *sock_ctx) static void ctrl_read(int sock, void *eloop_ctx, void *sock_ctx)
{ {
struct wlantest *wt = eloop_ctx; struct wlantest *wt = eloop_ctx;
@ -1270,6 +1278,9 @@ static void ctrl_read(int sock, void *eloop_ctx, void *sock_ctx)
case WLANTEST_CTRL_SEND: case WLANTEST_CTRL_SEND:
ctrl_send_(wt, sock, buf + 4, len - 4); ctrl_send_(wt, sock, buf + 4, len - 4);
break; break;
case WLANTEST_CTRL_RELOG:
ctrl_relog(wt, sock);
break;
default: default:
ctrl_send_simple(wt, sock, WLANTEST_CTRL_UNKNOWN_CMD); ctrl_send_simple(wt, sock, WLANTEST_CTRL_UNKNOWN_CMD);
break; break;

View file

@ -1,6 +1,6 @@
/* /*
* wlantest - IEEE 802.11 protocol monitoring and testing tool * wlantest - IEEE 802.11 protocol monitoring and testing tool
* Copyright (c) 2010-2011, Jouni Malinen <j@w1.fi> * Copyright (c) 2010-2013, Jouni Malinen <j@w1.fi>
* *
* This software may be distributed under the terms of the BSD license. * This software may be distributed under the terms of the BSD license.
* See README for more details. * See README for more details.
@ -245,15 +245,35 @@ size_t notes_len(struct wlantest *wt, size_t hdrlen)
} }
int wlantest_relog(struct wlantest *wt)
{
int ret = 0;
wpa_printf(MSG_INFO, "Re-open log/capture files");
if (wt->write_file) {
write_pcap_deinit(wt);
if (write_pcap_init(wt, wt->write_file) < 0)
ret = -1;
}
if (wt->pcapng_file) {
write_pcapng_deinit(wt);
if (write_pcapng_init(wt, wt->pcapng_file) < 0)
ret = -1;
}
return ret;
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int c; int c;
const char *read_file = NULL; const char *read_file = NULL;
const char *read_wired_file = NULL; const char *read_wired_file = NULL;
const char *write_file = NULL;
const char *ifname = NULL; const char *ifname = NULL;
const char *ifname_wired = NULL; const char *ifname_wired = NULL;
const char *pcapng_file = NULL;
struct wlantest wt; struct wlantest wt;
int ctrl_iface = 0; int ctrl_iface = 0;
@ -294,7 +314,7 @@ int main(int argc, char *argv[])
ifname_wired = optarg; ifname_wired = optarg;
break; break;
case 'n': case 'n':
pcapng_file = optarg; wt.pcapng_file = optarg;
break; break;
case 'p': case 'p':
add_passphrase(&wt, optarg); add_passphrase(&wt, optarg);
@ -312,7 +332,7 @@ int main(int argc, char *argv[])
read_wired_file = optarg; read_wired_file = optarg;
break; break;
case 'w': case 'w':
write_file = optarg; wt.write_file = optarg;
break; break;
case 'W': case 'W':
if (add_wep(&wt, optarg) < 0) if (add_wep(&wt, optarg) < 0)
@ -333,10 +353,10 @@ int main(int argc, char *argv[])
if (eloop_init()) if (eloop_init())
return -1; return -1;
if (write_file && write_pcap_init(&wt, write_file) < 0) if (wt.write_file && write_pcap_init(&wt, wt.write_file) < 0)
return -1; return -1;
if (pcapng_file && write_pcapng_init(&wt, pcapng_file) < 0) if (wt.pcapng_file && write_pcapng_init(&wt, wt.pcapng_file) < 0)
return -1; return -1;
if (read_wired_file && read_wired_cap_file(&wt, read_wired_file) < 0) if (read_wired_file && read_wired_cap_file(&wt, read_wired_file) < 0)

View file

@ -1,6 +1,6 @@
/* /*
* wlantest - IEEE 802.11 protocol monitoring and testing tool * wlantest - IEEE 802.11 protocol monitoring and testing tool
* Copyright (c) 2010, Jouni Malinen <j@w1.fi> * Copyright (c) 2010-2013, Jouni Malinen <j@w1.fi>
* *
* This software may be distributed under the terms of the BSD license. * This software may be distributed under the terms of the BSD license.
* See README for more details. * See README for more details.
@ -188,6 +188,9 @@ struct wlantest {
char *notes[MAX_NOTES]; char *notes[MAX_NOTES];
size_t num_notes; size_t num_notes;
const char *write_file;
const char *pcapng_file;
}; };
void add_note(struct wlantest *wt, int level, const char *fmt, ...) void add_note(struct wlantest *wt, int level, const char *fmt, ...)
@ -286,4 +289,6 @@ int wlantest_inject(struct wlantest *wt, struct wlantest_bss *bss,
struct wlantest_sta *sta, u8 *frame, size_t len, struct wlantest_sta *sta, u8 *frame, size_t len,
enum wlantest_inject_protection prot); enum wlantest_inject_protection prot);
int wlantest_relog(struct wlantest *wt);
#endif /* WLANTEST_H */ #endif /* WLANTEST_H */

View file

@ -740,6 +740,12 @@ static char ** complete_get_bss_counter(int s, const char *str, int pos)
} }
static int cmd_relog(int s, int argc, char *argv[])
{
return cmd_simple(s, WLANTEST_CTRL_RELOG);
}
struct tdls_counters { struct tdls_counters {
const char *name; const char *name;
enum wlantest_tdls_counter num; enum wlantest_tdls_counter num;
@ -1496,6 +1502,7 @@ static const struct wlantest_cli_cmd wlantest_cli_commands[] = {
{ "get_bss_counter", cmd_get_bss_counter, { "get_bss_counter", cmd_get_bss_counter,
"<counter> <BSSID> = get BSS counter value", "<counter> <BSSID> = get BSS counter value",
complete_get_bss_counter }, complete_get_bss_counter },
{ "relog", cmd_relog, "= re-open log-file (allow rolling logs)", NULL },
{ NULL, NULL, NULL, NULL } { NULL, NULL, NULL, NULL }
}; };

View file

@ -1,6 +1,6 @@
/* /*
* wlantest control interface * wlantest control interface
* Copyright (c) 2010, Jouni Malinen <j@w1.fi> * Copyright (c) 2010-2013, Jouni Malinen <j@w1.fi>
* *
* This software may be distributed under the terms of the BSD license. * This software may be distributed under the terms of the BSD license.
* See README for more details. * See README for more details.
@ -35,6 +35,7 @@ enum wlantest_ctrl_cmd {
WLANTEST_CTRL_SEND, WLANTEST_CTRL_SEND,
WLANTEST_CTRL_CLEAR_TDLS_COUNTERS, WLANTEST_CTRL_CLEAR_TDLS_COUNTERS,
WLANTEST_CTRL_GET_TDLS_COUNTER, WLANTEST_CTRL_GET_TDLS_COUNTER,
WLANTEST_CTRL_RELOG,
}; };
enum wlantest_ctrl_attr { enum wlantest_ctrl_attr {