2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2011 - 2013 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,
5 * Swiss federal institute of technology (ETH Zurich)
6 * Subject to the GPL, version 2.
8 * A high-performance network traffic generator that uses the zero-copy
9 * kernelspace TX_RING for network I/O. On comodity Gigabit hardware up
10 * to 1,488,095 pps 64 Byte pps have been achieved with 2 trafgen instances
11 * bound to different CPUs from the userspace and turned off pause frames,
12 * ask Ronald from NST (Network Security Toolkit) for more details. ;-)
13 * So, this line-rate result is the very same as pktgen from kernelspace!
15 * Who can now hold the fords when the King of the Nine Riders comes? And
16 * other armies will come. I am too late. All is lost. I tarried on the
17 * way. All is lost. Even if my errand is performed, no one will ever
18 * know. There will be no one I can tell. It will be in vain.
20 * -- The Lord of the Rings, Frodo thinking,
21 * Chapter 'The Stairs of Cirith Ungol'.
29 #include <sys/socket.h>
30 #include <sys/types.h>
31 #include <sys/fsuid.h>
36 #include <net/ethernet.h>
37 #include <netinet/in.h>
38 #include <netinet/ip.h>
39 #include <linux/icmp.h>
40 #include <arpa/inet.h>
56 #include "trafgen_conf.h"
61 bool rand
, rfraw
, jumbo_support
, verbose
, smoke_test
;
62 unsigned long kpull
, num
, gap
, reserve_size
, cpus
;
63 struct sockaddr_in dest
;
64 char *device
, *device_trans
, *rhost
;
68 unsigned long long tx_packets
, tx_bytes
;
69 unsigned long tv_sec
, tv_usec
;
73 #define CPU_STATS_STATE_CFG 1
74 #define CPU_STATS_STATE_RES 2
76 sig_atomic_t sigint
= 0;
78 struct packet
*packets
= NULL
;
81 struct packet_dyn
*packet_dyn
= NULL
;
84 static const char *short_options
= "d:c:n:t:vJhS:rk:i:o:VRsP:";
85 static const struct option long_options
[] = {
86 {"dev", required_argument
, NULL
, 'd'},
87 {"out", required_argument
, NULL
, 'o'},
88 {"in", required_argument
, NULL
, 'i'},
89 {"conf", required_argument
, NULL
, 'c'},
90 {"num", required_argument
, NULL
, 'n'},
91 {"gap", required_argument
, NULL
, 't'},
92 {"cpus", required_argument
, NULL
, 'P'},
93 {"ring-size", required_argument
, NULL
, 'S'},
94 {"kernel-pull", required_argument
, NULL
, 'k'},
95 {"smoke-test", required_argument
, NULL
, 's'},
96 {"jumbo-support", no_argument
, NULL
, 'J'},
97 {"rfraw", no_argument
, NULL
, 'R'},
98 {"rand", no_argument
, NULL
, 'r'},
99 {"verbose", no_argument
, NULL
, 'V'},
100 {"version", no_argument
, NULL
, 'v'},
101 {"help", no_argument
, NULL
, 'h'},
107 static struct itimerval itimer
;
109 static unsigned long interval
= TX_KERNEL_PULL_INT
;
111 static struct cpu_stats
*stats
;
113 #define set_system_socket_memory(vals) \
115 if ((vals[0] = get_system_socket_mem(sock_rmem_max)) < SMEM_SUG_MAX) \
116 set_system_socket_mem(sock_rmem_max, SMEM_SUG_MAX); \
117 if ((vals[1] = get_system_socket_mem(sock_rmem_def)) < SMEM_SUG_DEF) \
118 set_system_socket_mem(sock_rmem_def, SMEM_SUG_DEF); \
119 if ((vals[2] = get_system_socket_mem(sock_wmem_max)) < SMEM_SUG_MAX) \
120 set_system_socket_mem(sock_wmem_max, SMEM_SUG_MAX); \
121 if ((vals[3] = get_system_socket_mem(sock_wmem_def)) < SMEM_SUG_DEF) \
122 set_system_socket_mem(sock_wmem_def, SMEM_SUG_DEF); \
125 #define reset_system_socket_memory(vals) \
127 set_system_socket_mem(sock_rmem_max, vals[0]); \
128 set_system_socket_mem(sock_rmem_def, vals[1]); \
129 set_system_socket_mem(sock_wmem_max, vals[2]); \
130 set_system_socket_mem(sock_wmem_def, vals[3]); \
134 # define ICMP_FILTER 1
141 static void signal_handler(int number
)
152 static void timer_elapsed(int number
)
154 itimer
.it_interval
.tv_sec
= 0;
155 itimer
.it_interval
.tv_usec
= interval
;
157 itimer
.it_value
.tv_sec
= 0;
158 itimer
.it_value
.tv_usec
= interval
;
160 pull_and_flush_tx_ring(sock
);
161 setitimer(ITIMER_REAL
, &itimer
, NULL
);
164 static void header(void)
166 printf("%s%s%s\n", colorize_start(bold
), "trafgen " VERSION_STRING
, colorize_end());
169 static void help(void)
171 printf("\ntrafgen %s, multithreaded zero-copy network packet generator\n", VERSION_STRING
);
172 puts("http://www.netsniff-ng.org\n\n"
173 "Usage: trafgen [options]\n"
175 " -o|-d|--out|--dev <netdev> Networking Device i.e., eth0\n"
176 " -i|-c|--in|--conf <cfg-file> Packet configuration file\n"
177 " -J|--jumbo-support Support 64KB Super Jumbo Frames (def: 2048B)\n"
178 " -R|--rfraw Inject raw 802.11 frames\n"
179 " -s|--smoke-test <ipv4-receiver> Test if machine survived packet\n"
180 " -n|--num <uint> Number of packets until exit (def: 0)\n"
181 " -r|--rand Randomize packet selection (def: round robin)\n"
182 " -P|--cpus <uint> Specify number of forks(<= CPUs) (def: #CPUs)\n"
183 " -t|--gap <uint> Interpacket gap in us (approx)\n"
184 " -S|--ring-size <size> Manually set mmap size (KB/MB/GB): e.g.\'10MB\'\n"
185 " -k|--kernel-pull <uint> Kernel batch interval in us (def: 10us)\n"
186 " -V|--verbose Be more verbose\n"
187 " -v|--version Show version\n"
188 " -h|--help Guess what?!\n\n"
190 " See trafgen.txf for configuration file examples.\n"
191 " trafgen --dev eth0 --conf trafgen.txf\n"
192 " trafgen --dev eth0 --conf trafgen.txf --smoke-test 10.0.0.1\n"
193 " trafgen --dev wlan0 --rfraw --conf beacon-test.txf -V --cpus 2\n"
194 " trafgen --dev eth0 --conf trafgen.txf --rand --gap 1000\n"
195 " trafgen --dev eth0 --conf trafgen.txf --rand --num 1400000 -k1000\n\n"
196 "Packet config examples:\n"
197 " Run packet on all CPUs: { fill(0xff, 64) }\n"
198 " Run packet only on CPU1: cpu(1): { fill(0xff, 64) }\n"
199 " Run packet only on CPU1-2: cpu(1:2): { fill(0xff, 64) }\n"
201 " Smoke test example: machine A, 10.0.0.2 (trafgen) is directly\n"
202 " connected to machine B (test kernel), 10.0.0.1. If ICMP reply fails\n"
203 " we assume the kernel crashed, thus we print the packet and quit.\n\n"
204 " This tool is targeted for network developers! You should\n"
205 " be aware of what you are doing and what these options above\n"
206 " mean! Only use this tool in an isolated LAN that you own!\n\n"
207 "Please report bugs to <bugs@netsniff-ng.org>\n"
208 "Copyright (C) 2011-2013 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,\n"
209 "Swiss federal institute of technology (ETH Zurich)\n"
210 "License: GNU GPL version 2.0\n"
211 "This is free software: you are free to change and redistribute it.\n"
212 "There is NO WARRANTY, to the extent permitted by law.\n");
216 static void version(void)
218 printf("\ntrafgen %s, multithreaded zero-copy network packet generator\n", VERSION_STRING
);
219 puts("http://www.netsniff-ng.org\n\n"
220 "Please report bugs to <bugs@netsniff-ng.org>\n"
221 "Copyright (C) 2011-2013 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,\n"
222 "Swiss federal institute of technology (ETH Zurich)\n"
223 "License: GNU GPL version 2.0\n"
224 "This is free software: you are free to change and redistribute it.\n"
225 "There is NO WARRANTY, to the extent permitted by law.\n");
229 static inline void apply_counter(int counter_id
)
232 size_t counter_max
= packet_dyn
[counter_id
].clen
;
234 for (j
= 0; j
< counter_max
; ++j
) {
236 struct counter
*counter
;
238 counter
= &packet_dyn
[counter_id
].cnt
[j
];
239 val
= counter
->val
- counter
->min
;
241 switch (counter
->type
) {
243 val
= (val
+ counter
->inc
) % (counter
->max
- counter
->min
+ 1);
246 val
= (val
- counter
->inc
) % (counter
->min
- counter
->max
+ 1);
252 counter
->val
= val
+ counter
->min
;
253 packets
[counter_id
].payload
[counter
->off
] = val
;
257 static inline void apply_randomizer(int rand_id
)
260 size_t rand_max
= packet_dyn
[rand_id
].rlen
;
262 for (j
= 0; j
< rand_max
; ++j
) {
264 struct randomizer
*randomizer
;
266 val
= (uint8_t) rand();
268 randomizer
= &packet_dyn
[rand_id
].rnd
[j
];
269 randomizer
->val
= val
;
271 packets
[rand_id
].payload
[randomizer
->off
] = val
;
275 static struct cpu_stats
*setup_shared_var(unsigned long cpus
)
278 char zbuff
[cpus
* sizeof(struct cpu_stats
)];
279 struct cpu_stats
*buff
;
281 memset(zbuff
, 0, sizeof(zbuff
));
283 fd
= creat(".tmp_mmap", S_IRUSR
| S_IWUSR
);
287 fd
= open_or_die_m(".tmp_mmap", O_RDWR
| O_CREAT
| O_TRUNC
,
289 write_or_die(fd
, zbuff
, sizeof(zbuff
));
291 buff
= (void *) mmap(0, sizeof(zbuff
), PROT_READ
| PROT_WRITE
,
293 if (buff
== (void *) -1)
294 panic("Cannot setup shared variable!\n");
299 memset(buff
, 0, sizeof(zbuff
));
304 static void destroy_shared_var(void *buff
, unsigned long cpus
)
306 munmap(buff
, cpus
* sizeof(struct cpu_stats
));
309 static void dump_trafgen_snippet(uint8_t *payload
, size_t len
)
314 for (i
= 0; i
< len
; ++i
) {
317 printf("0x%02x, ", payload
[i
]);
323 static inline unsigned short csum(unsigned short *buf
, int nwords
)
327 for (sum
= 0; nwords
> 0; nwords
--)
329 sum
= (sum
>> 16) + (sum
& 0xffff);
335 static int xmit_smoke_setup(struct ctx
*ctx
)
337 int icmp_sock
, ret
, ttl
= 64;
338 struct icmp_filter filter
;
340 icmp_sock
= socket(AF_INET
, SOCK_RAW
, IPPROTO_ICMP
);
342 panic("Cannot get a ICMP socket: %s!\n", strerror(errno
));
344 filter
.data
= ~(1 << ICMP_ECHOREPLY
);
346 ret
= setsockopt(icmp_sock
, SOL_RAW
, ICMP_FILTER
, &filter
, sizeof(filter
));
348 panic("Cannot install filter!\n");
350 ret
= setsockopt(icmp_sock
, SOL_IP
, IP_TTL
, &ttl
, sizeof(ttl
));
352 panic("Cannot set TTL!\n");
354 memset(&ctx
->dest
, 0, sizeof(ctx
->dest
));
355 ctx
->dest
.sin_family
= AF_INET
;
356 ctx
->dest
.sin_port
= 0;
358 ret
= inet_aton(ctx
->rhost
, &ctx
->dest
.sin_addr
);
360 panic("Cannot resolv address!\n");
365 static int xmit_smoke_probe(int icmp_sock
, struct ctx
*ctx
)
367 int ret
, i
, probes
= 5;
368 short ident
, cnt
= 1;
369 uint8_t outpack
[512], *data
;
370 struct icmphdr
*icmp
;
372 size_t len
= sizeof(*icmp
) + 56;
373 struct sockaddr_in from
;
375 struct pollfd fds
= {
380 while (probes
-- > 0) {
381 ident
= htons((short) rand());
383 memset(outpack
, 0, sizeof(outpack
));
384 icmp
= (void *) outpack
;
385 icmp
->type
= ICMP_ECHO
;
388 icmp
->un
.echo
.id
= ident
;
389 icmp
->un
.echo
.sequence
= htons(cnt
++);
391 data
= ((uint8_t *) outpack
+ sizeof(*icmp
));
392 for (i
= 0; i
< 56; ++i
)
393 data
[i
] = (uint8_t) rand();
395 icmp
->checksum
= csum((unsigned short *) outpack
,
396 len
/ sizeof(unsigned short));
398 ret
= sendto(icmp_sock
, outpack
, len
, MSG_DONTWAIT
,
399 (struct sockaddr
*) &ctx
->dest
, sizeof(ctx
->dest
));
400 if (unlikely(ret
!= len
))
401 panic("Cannot send out probe: %s!\n", strerror(errno
));
403 ret
= poll(&fds
, 1, 500);
405 panic("Poll failed!\n");
407 if (fds
.revents
& POLLIN
) {
408 ret
= recvfrom(icmp_sock
, outpack
, sizeof(outpack
), 0,
409 (struct sockaddr
*) &from
, &from_len
);
410 if (unlikely(ret
<= 0))
411 panic("Probe receive failed!\n");
412 if (unlikely(from_len
!= sizeof(ctx
->dest
)))
414 if (unlikely(memcmp(&from
, &ctx
->dest
, sizeof(ctx
->dest
))))
416 if (unlikely(ret
< sizeof(*ip
) + sizeof(*icmp
)))
418 ip
= (void *) outpack
;
419 if (unlikely(ip
->ihl
* 4 + sizeof(*icmp
) > ret
))
421 icmp
= (void *) outpack
+ ip
->ihl
* 4;
422 if (unlikely(icmp
->un
.echo
.id
!= ident
))
432 static void xmit_slowpath_or_die(struct ctx
*ctx
, int cpu
)
434 int ret
, icmp_sock
= -1;
435 unsigned long num
= 1, i
= 0;
436 struct timeval start
, end
, diff
;
437 unsigned long long tx_bytes
= 0, tx_packets
= 0;
438 struct sockaddr_ll saddr
= {
439 .sll_family
= PF_PACKET
,
440 .sll_halen
= ETH_ALEN
,
441 .sll_ifindex
= device_ifindex(ctx
->device
),
448 icmp_sock
= xmit_smoke_setup(ctx
);
450 bug_on(gettimeofday(&start
, NULL
));
452 while (likely(sigint
== 0) && likely(num
> 0)) {
456 ret
= sendto(sock
, packets
[i
].payload
, packets
[i
].len
, 0,
457 (struct sockaddr
*) &saddr
, sizeof(saddr
));
458 if (unlikely(ret
< 0)) {
459 if (errno
== ENOBUFS
) {
464 panic("Sendto error: %s!\n", strerror(errno
));
467 tx_bytes
+= packets
[i
].len
;
470 if (ctx
->smoke_test
) {
471 ret
= xmit_smoke_probe(icmp_sock
, ctx
);
472 if (unlikely(ret
< 0)) {
473 printf("%sSmoke test alert:%s\n", colorize_start(bold
), colorize_end());
474 printf(" Remote host seems to be unresponsive to ICMP pings!\n");
475 printf(" Last instance was packet%lu, trafgen snippet:\n\n", i
);
477 dump_trafgen_snippet(packets
[i
].payload
, packets
[i
].len
);
496 bug_on(gettimeofday(&end
, NULL
));
497 diff
= tv_subtract(end
, start
);
502 stats
[cpu
].tx_packets
= tx_packets
;
503 stats
[cpu
].tx_bytes
= tx_bytes
;
504 stats
[cpu
].tv_sec
= diff
.tv_sec
;
505 stats
[cpu
].tv_usec
= diff
.tv_usec
;
506 stats
[cpu
].state
= CPU_STATS_STATE_RES
;
509 static void xmit_fastpath_or_die(struct ctx
*ctx
, int cpu
)
511 int ifindex
= device_ifindex(ctx
->device
);
514 unsigned long num
= 1, i
= 0, size
;
516 struct frame_map
*hdr
;
517 struct timeval start
, end
, diff
;
518 unsigned long long tx_bytes
= 0, tx_packets
= 0;
520 fmemset(&tx_ring
, 0, sizeof(tx_ring
));
522 size
= ring_size(ctx
->device
, ctx
->reserve_size
);
524 set_sock_prio(sock
, 512);
525 set_packet_loss_discard(sock
);
527 setup_tx_ring_layout(sock
, &tx_ring
, size
, ctx
->jumbo_support
);
528 create_tx_ring(sock
, &tx_ring
, ctx
->verbose
);
529 mmap_tx_ring(sock
, &tx_ring
);
530 alloc_tx_ring_frames(&tx_ring
);
531 bind_tx_ring(sock
, &tx_ring
, ifindex
);
534 interval
= ctx
->kpull
;
538 itimer
.it_interval
.tv_sec
= 0;
539 itimer
.it_interval
.tv_usec
= interval
;
541 itimer
.it_value
.tv_sec
= 0;
542 itimer
.it_value
.tv_usec
= interval
;
544 setitimer(ITIMER_REAL
, &itimer
, NULL
);
546 bug_on(gettimeofday(&start
, NULL
));
548 while (likely(sigint
== 0) && likely(num
> 0)) {
549 while (user_may_pull_from_tx(tx_ring
.frames
[it
].iov_base
) && likely(num
> 0)) {
550 hdr
= tx_ring
.frames
[it
].iov_base
;
552 /* Kernel assumes: data = ph.raw + po->tp_hdrlen -
553 * sizeof(struct sockaddr_ll); */
554 out
= ((uint8_t *) hdr
) + TPACKET2_HDRLEN
- sizeof(struct sockaddr_ll
);
556 hdr
->tp_h
.tp_snaplen
= packets
[i
].len
;
557 hdr
->tp_h
.tp_len
= packets
[i
].len
;
562 fmemcpy(out
, packets
[i
].payload
, packets
[i
].len
);
564 tx_bytes
+= packets
[i
].len
;
574 kernel_may_pull_from_tx(&hdr
->tp_h
);
577 if (it
>= tx_ring
.layout
.tp_frame_nr
)
583 if (unlikely(sigint
== 1))
588 bug_on(gettimeofday(&end
, NULL
));
589 diff
= tv_subtract(end
, start
);
591 destroy_tx_ring(sock
, &tx_ring
);
593 stats
[cpu
].tx_packets
= tx_packets
;
594 stats
[cpu
].tx_bytes
= tx_bytes
;
595 stats
[cpu
].tv_sec
= diff
.tv_sec
;
596 stats
[cpu
].tv_usec
= diff
.tv_usec
;
597 stats
[cpu
].state
= CPU_STATS_STATE_RES
;
600 static int xmit_packet_precheck(struct ctx
*ctx
, int cpu
)
603 unsigned long plen_total
;
604 size_t mtu
, total_len
= 0;
606 bug_on(plen
!= dlen
);
608 for (i
= 0; i
< plen
; ++i
)
609 total_len
+= packets
[i
].len
;
611 stats
[cpu
].tx_packets
= plen
;
612 stats
[cpu
].tx_bytes
= total_len
;
613 stats
[cpu
].state
= CPU_STATS_STATE_CFG
;
615 for (i
= 0, plen_total
= plen
; i
< ctx
->cpus
; i
++) {
618 while (stats
[i
].state
!= CPU_STATS_STATE_CFG
)
620 plen_total
+= stats
[i
].tx_packets
;
624 ctx
->num
= (unsigned long) round((1.0 * plen
/ plen_total
) * ctx
->num
);
626 for (mtu
= device_mtu(ctx
->device
), i
= 0; i
< plen
; ++i
) {
627 if (packets
[i
].len
> mtu
+ 14)
628 panic("Device MTU < than packet%d's size!\n", i
);
629 if (packets
[i
].len
<= 14)
630 panic("Packet%d's size too short!\n", i
);
634 memset(&stats
[cpu
], 0, sizeof(stats
[cpu
]));
635 stats
[cpu
].state
= CPU_STATS_STATE_RES
;
642 static void main_loop(struct ctx
*ctx
, char *confname
, bool slow
, int cpu
)
644 compile_packets(confname
, ctx
->verbose
, cpu
);
645 if (xmit_packet_precheck(ctx
, cpu
) < 0)
650 size_t total_len
= 0, total_pkts
= 0;
652 for (i
= 0; i
< ctx
->cpus
; ++i
) {
653 total_len
+= stats
[i
].tx_bytes
;
654 total_pkts
+= stats
[i
].tx_packets
;
657 printf("%6zu packets to schedule\n", total_pkts
);
658 printf("%6zu bytes in total\n", total_len
);
659 printf("Running! Hang up with ^C!\n\n");
666 xmit_slowpath_or_die(ctx
, cpu
);
668 xmit_fastpath_or_die(ctx
, cpu
);
675 int main(int argc
, char **argv
)
678 int c
, opt_index
, i
, j
, vals
[4] = {0}, irq
;
679 char *confname
= NULL
, *ptr
;
680 unsigned long cpus_tmp
, num_orig
= 0;
681 unsigned long long tx_packets
, tx_bytes
;
688 fmemset(&ctx
, 0, sizeof(ctx
));
689 ctx
.cpus
= get_number_cpus_online();
691 while ((c
= getopt_long(argc
, argv
, short_options
, long_options
,
692 &opt_index
)) != EOF
) {
704 cpus_tmp
= strtoul(optarg
, NULL
, 0);
705 if (cpus_tmp
> 0 && cpus_tmp
< ctx
.cpus
)
710 ctx
.device
= xstrndup(optarg
, IFNAMSIZ
);
718 ctx
.smoke_test
= true;
719 ctx
.rhost
= xstrdup(optarg
);
725 ctx
.jumbo_support
= true;
729 confname
= xstrdup(optarg
);
732 ctx
.kpull
= strtoul(optarg
, NULL
, 0);
735 num_orig
= ctx
.num
= strtoul(optarg
, NULL
, 0);
739 ctx
.gap
= strtoul(optarg
, NULL
, 0);
741 /* Fall back to single core to have correct timing */
746 ctx
.reserve_size
= 0;
748 for (j
= i
= strlen(optarg
); i
> 0; --i
) {
749 if (!isdigit(optarg
[j
- i
]))
754 if (!strncmp(ptr
, "KB", strlen("KB")))
755 ctx
.reserve_size
= 1 << 10;
756 else if (!strncmp(ptr
, "MB", strlen("MB")))
757 ctx
.reserve_size
= 1 << 20;
758 else if (!strncmp(ptr
, "GB", strlen("GB")))
759 ctx
.reserve_size
= 1 << 30;
761 panic("Syntax error in ring size param!\n");
764 ctx
.reserve_size
*= strtol(optarg
, NULL
, 0);
778 panic("Option -%c requires an argument!\n",
782 whine("Unknown option character "
783 "`0x%X\'!\n", optopt
);
793 if (ctx
.device
== NULL
)
794 panic("No networking device given!\n");
795 if (confname
== NULL
)
796 panic("No configuration file given!\n");
797 if (device_mtu(ctx
.device
) == 0)
798 panic("This is no networking device!\n");
799 if (!ctx
.rfraw
&& device_up_and_running(ctx
.device
) == 0)
800 panic("Networking device not running!\n");
802 register_signal(SIGINT
, signal_handler
);
803 register_signal(SIGHUP
, signal_handler
);
804 register_signal_f(SIGALRM
, timer_elapsed
, SA_SIGINFO
);
808 set_system_socket_memory(vals
);
811 ctx
.device_trans
= xstrdup(ctx
.device
);
814 enter_rfmon_mac80211(ctx
.device_trans
, &ctx
.device
);
818 irq
= device_irq_number(ctx
.device
);
819 device_reset_irq_affinity(irq
);
821 if (ctx
.num
> 0 && ctx
.num
<= ctx
.cpus
)
824 stats
= setup_shared_var(ctx
.cpus
);
826 for (i
= 0; i
< ctx
.cpus
; i
++) {
832 main_loop(&ctx
, confname
, slow
, i
);
836 panic("Cannot fork processes!\n");
840 for (i
= 0; i
< ctx
.cpus
; i
++) {
847 leave_rfmon_mac80211(ctx
.device_trans
, ctx
.device
);
849 reset_system_socket_memory(vals
);
851 for (i
= 0, tx_packets
= tx_bytes
= 0; i
< ctx
.cpus
; i
++) {
852 while (stats
[i
].state
!= CPU_STATS_STATE_RES
)
854 tx_packets
+= stats
[i
].tx_packets
;
855 tx_bytes
+= stats
[i
].tx_bytes
;
858 if (num_orig
> 0 && sigint
== 0)
859 bug_on(num_orig
!= tx_packets
);
863 printf("\r%12llu packets outgoing\n", tx_packets
);
864 printf("\r%12llu bytes outgoing\n", tx_bytes
);
865 for (i
= 0; i
< ctx
.cpus
; i
++)
866 printf("\r%12lu sec, %lu usec on CPU%d (%llu packets)\n",
867 stats
[i
].tv_sec
, stats
[i
].tv_usec
, i
,
868 stats
[i
].tx_packets
);
871 destroy_shared_var(stats
, ctx
.cpus
);
874 free(ctx
.device_trans
);