diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2014-07-25 15:50:12 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2014-08-12 11:05:17 +0200 |
commit | 03e3d73dca588d2411bc1223c7cbd22ba2273b1e (patch) | |
tree | fc1a04e1c22f110063cae8f066f6f1e17c416da5 | |
parent | 99d4dd920960f1c2a030cf2e0ccd395c013d8384 (diff) |
netsniff-ng: Add command line option to disable hardware time stamping
Allow to disable hardware time stamping using the command line switch
(-N/--no-hwtimestamp). This might be useful in situations where hardware
time stamps are skewed somehow.
Reference: #129
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r-- | netsniff-ng.8 | 7 | ||||
-rw-r--r-- | netsniff-ng.c | 18 | ||||
-rw-r--r-- | netsniff-ng.zsh | 1 |
3 files changed, 21 insertions, 5 deletions
diff --git a/netsniff-ng.8 b/netsniff-ng.8 index c6356bf..b6f129a 100644 --- a/netsniff-ng.8 +++ b/netsniff-ng.8 @@ -153,6 +153,13 @@ randomize packet order in the output ring buffer. The networking interface will not be put into promiscuous mode. By default, promiscuous mode is turned on. .PP +.SS -N, --no-hwtimestamp +Disable taking hardware time stamps for RX packets. By default, if the network +device supports hardware time stamping, the hardware time stamps will be used +when writing packets to pcap files. This option disables this behavior and +forces (kernel based) software time stamps to be used, even if hardware time +stamps are available. +.PP .SS -A, --no-sock-mem On startup and shutdown, netsniff-ng tries to increase socket read and write buffers if appropriate. This option will prevent netsniff-ng from doing diff --git a/netsniff-ng.c b/netsniff-ng.c index 397f50d..af36d5c 100644 --- a/netsniff-ng.c +++ b/netsniff-ng.c @@ -57,7 +57,7 @@ struct ctx { int cpu, rfraw, dump, print_mode, dump_dir, packet_type; unsigned long kpull, dump_interval, tx_bytes, tx_packets; size_t reserve_size; - bool randomize, promiscuous, enforce, jumbo, dump_bpf, verbose; + bool randomize, promiscuous, enforce, jumbo, dump_bpf, hwtimestamp, verbose; enum pcap_ops_groups pcap; enum dump_mode dump_mode; uid_t uid; gid_t gid; uint32_t link_type, magic; }; @@ -65,7 +65,7 @@ struct ctx { static volatile sig_atomic_t sigint = 0; static volatile bool next_dump = false; -static const char *short_options = "d:i:o:rf:MJt:S:k:n:b:HQmcsqXlvhF:RGAP:Vu:g:T:DBU"; +static const char *short_options = "d:i:o:rf:MNJt:S:k:n:b:HQmcsqXlvhF:RGAP:Vu:g:T:DBU"; static const struct option long_options[] = { {"dev", required_argument, NULL, 'd'}, {"in", required_argument, NULL, 'i'}, @@ -88,6 +88,7 @@ static const struct option long_options[] = { {"clrw", no_argument, NULL, 'c'}, {"jumbo-support", no_argument, NULL, 'J'}, {"no-promisc", no_argument, NULL, 'M'}, + {"no-hwtimestamp", no_argument, NULL, 'N'}, {"prio-high", no_argument, NULL, 'H'}, {"notouch-irq", no_argument, NULL, 'Q'}, {"dump-pcap-types", no_argument, NULL, 'D'}, @@ -890,9 +891,11 @@ static void recv_only_or_dump(struct ctx *ctx) bpf_dump_all(&bpf_ops); bpf_attach_to_sock(sock, &bpf_ops); - ret = set_sockopt_hwtimestamp(sock, ctx->device_in); - if (ret == 0 && ctx->verbose) - printf("HW timestamping enabled\n"); + if (ctx->hwtimestamp) { + ret = set_sockopt_hwtimestamp(sock, ctx->device_in); + if (ret == 0 && ctx->verbose) + printf("HW timestamping enabled\n"); + } ring_rx_setup(&rx_ring, sock, size, ifindex, &rx_poll, true, true, ctx->verbose); @@ -1005,6 +1008,7 @@ static void init_ctx(struct ctx *ctx) ctx->promiscuous = true; ctx->randomize = false; + ctx->hwtimestamp = true; } static void destroy_ctx(struct ctx *ctx) @@ -1036,6 +1040,7 @@ static void __noreturn help(void) " -r|--rand Randomize packet forwarding order (dev->dev)\n" " -M|--no-promisc No promiscuous mode for netdev\n" " -A|--no-sock-mem Don't tune core socket memory\n" + " -N|--no-hwtimestamp Disable hardware time stamping\n" " -m|--mmap Mmap(2) pcap file I/O, e.g. for replaying pcaps\n" " -G|--sg Scatter/gather pcap file I/O\n" " -c|--clrw Use slower read(2)/write(2) I/O\n" @@ -1138,6 +1143,9 @@ int main(int argc, char **argv) case 'M': ctx.promiscuous = false; break; + case 'N': + ctx.hwtimestamp = false; + break; case 'A': setsockmem = false; break; diff --git a/netsniff-ng.zsh b/netsniff-ng.zsh index 682d66d..f60f867 100644 --- a/netsniff-ng.zsh +++ b/netsniff-ng.zsh @@ -47,6 +47,7 @@ _arguments -s -S \ "(-B --dump-bpf)"{-B,--dump-bpf}"[Dump generated BPF assembly]" \ "(-r --rand)"{-r,--rand}"[Randomize packet forwarding order (dev->dev)]" \ "(-M --no-promisc)"{-M,--no-promisc}"[No promiscuous mode for netdev]" \ + "(-N --no-hwtimestamp)"{-N,--no-hwtimestamp}"[Disable hardware timestamping]" \ "(-A --no-sock-mem)"{-A,--no-sock-mem}"[Don\'t tune core socket memory]" \ "(-m --mmap)"{-m,--mmap}"[Mmap(2) pcap file i.e., for replaying pcaps]" \ "(-G --sg)"{-G,--sg}"[Scatter/gather pcap file I/O]" \ |