2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2011 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'.
28 trafgen - a high-performance zero-copy network packet generator
32 trafgen [-d|--dev <netdev>][-c|--conf <file>][-J|--jumbo-support]
33 [-x|--interactive][-n|--num <uint>][-r|--rand][-t|--gap <usec>]
34 [-S|--ring-size <size>][-k|--kernel-pull <usec>][-b|--bind-cpu <cpu>]
35 [-B|--unbind-cpu <cpu>][-H|--prio-high][-Q|--notouch-irq][-v|--version]
40 A high-performance network traffic generator that uses the zero-copy TX_RING
41 for network I/O. For instance, on comodity Gigabit hardware up to 1,488,095 pps
42 64 Byte pps have been achieved with trafgen.
48 =item trafgen --dev eth0 --conf trafgen.txf --bind-cpu 0
50 Use packet configuration trafgen.txf, eth0 as transmission device and CPU0
51 for binding the process.
61 Print help text and lists all options.
67 =item -d|--dev <netdev>
69 Device for transmission i.e., eth0.
71 =item -c|--conf <conf>
73 Path to packet configuration file.
75 =item -x|--interactive
77 Start trafgen in interactive mode.
79 =item -J|--jumbo-support
81 Support for 64KB Super Jumbo Frames
85 Number of packets to generate before exiting.
86 0 means forever until SIGINT.
90 Randomize packet selection process instead of round-robin.
94 Interpacket gap in microseconds.
96 =item -S|--ring-size <size>
98 Manually set ring size to <size>: mmap space in KB/MB/GB.
100 =item -k|--kernel-pull <uint>
102 Kernel pull from user interval in microseconds.
103 Default value is 10 microseconds.
105 =item -b|--bind-cpu <cpu>
107 Bind to specific CPU (or CPU-range).
109 =item -B|--unbind-cpu <cpu>
111 Forbid to use specific CPU (or CPU-range).
115 Make this high priority process.
117 =item -Q|--notouch-irq
119 Do not touch IRQ CPU affinity of NIC.
127 =item Generate traffic defined in trafgen.txf on eth0 using CPU 0
129 trafgen --dev eth0 --conf trafgen.txf --bind-cpu 0
131 =item Generate traffic on eth0 using CPU 0, wait 100 us between packets
133 trafgen --dev eth0 --conf trafgen.txf --bind-cpu 0 --gap 100
135 =item Generate 100,000 packet on eth0 using CPU 0
137 trafgen --dev eth0 --conf trafgen.txf --bind-cpu 0 --num 100000
143 Written by Daniel Borkmann <daniel@netsniff-ng.org>
147 Documentation by Emmanuel Roullit <emmanuel@netsniff-ng.org>
151 Please report bugs to <bugs@netsniff-ng.org>
162 #include <sys/socket.h>
163 #include <sys/types.h>
164 #include <sys/stat.h>
165 #include <sys/time.h>
171 #include <net/ethernet.h>
201 struct randomizer
*rnd
;
213 unsigned long tx_bytes
;
214 unsigned long tx_packets
;
223 /* 0 for automatic, > 0 for manual */
224 unsigned int reserve_size
;
228 #define CPU_UNKNOWN -1
229 #define CPU_NOTOUCH -2
231 extern int main_loop_interactive(struct mode
*mode
, char *confname
);
233 sig_atomic_t sigint
= 0;
235 static const char *short_options
= "d:c:n:t:vJhS:HQb:B:rk:x";
237 static struct option long_options
[] = {
238 {"dev", required_argument
, 0, 'd'},
239 {"conf", required_argument
, 0, 'c'},
240 {"num", required_argument
, 0, 'n'},
241 {"gap", required_argument
, 0, 't'},
242 {"ring-size", required_argument
, 0, 'S'},
243 {"bind-cpu", required_argument
, 0, 'b'},
244 {"unbind-cpu", required_argument
, 0, 'B'},
245 {"kernel-pull", required_argument
, 0, 'k'},
246 {"jumbo-support", no_argument
, 0, 'J'},
247 {"interactive", no_argument
, 0, 'x'},
248 {"rand", no_argument
, 0, 'r'},
249 {"prio-high", no_argument
, 0, 'H'},
250 {"notouch-irq", no_argument
, 0, 'Q'},
251 {"version", no_argument
, 0, 'v'},
252 {"help", no_argument
, 0, 'h'},
256 static struct itimerval itimer
;
258 static unsigned long interval
= TX_KERNEL_PULL_INT
;
260 static inline uint8_t lcrand(uint8_t val
)
262 return 0xFF & (3 * val
+ 3);
265 static void signal_handler(int number
)
278 static void timer_elapsed(int number
)
280 itimer
.it_interval
.tv_sec
= 0;
281 itimer
.it_interval
.tv_usec
= interval
;
282 itimer
.it_value
.tv_sec
= 0;
283 itimer
.it_value
.tv_usec
= interval
;
285 pull_and_flush_tx_ring(sock
);
286 setitimer(ITIMER_REAL
, &itimer
, NULL
);
289 static void header(void)
291 printf("%s%s%s\n", colorize_start(bold
), "trafgen "
292 VERSION_STRING
, colorize_end());
295 static void help(void)
297 printf("\ntrafgen %s, high-perf zero-copy network packet generator\n",
299 printf("http://www.netsniff-ng.org\n\n");
300 printf("Usage: trafgen [options]\n");
301 printf("Options:\n");
302 printf(" -d|--dev <netdev> Networking Device i.e., eth0\n");
303 printf(" -c|--conf <file> Packet configuration file\n");
304 printf(" -x|--interactive Start trafgen in interactive mode\n");
305 printf(" -J|--jumbo-support Support for 64KB Super Jumbo Frames\n");
306 printf(" Default TX slot: 2048Byte\n");
307 printf(" -n|--num <uint> Number of packets until exit\n");
308 printf(" `-- 0 Loop until interrupt (default)\n");
309 printf(" `- n Send n packets and done\n");
310 printf(" -r|--rand Randomize packet selection process\n");
311 printf(" Instead of a round robin selection\n");
312 printf(" -t|--gap <uint> Interpacket gap in us (approx)\n");
313 printf(" -S|--ring-size <size> Manually set ring size to <size>:\n");
314 printf(" mmap space in KB/MB/GB, e.g. \'10MB\'\n");
315 printf(" -k|--kernel-pull <uint>Kernel pull from user interval in us\n");
316 printf(" Default is 10us where the TX_RING\n");
317 printf(" is populated with payload from uspace\n");
318 printf(" -b|--bind-cpu <cpu> Bind to specific CPU (or CPU-range)\n");
319 printf(" -B|--unbind-cpu <cpu> Forbid to use specific CPU (or CPU-range)\n");
320 printf(" -H|--prio-high Make this high priority process\n");
321 printf(" -Q|--notouch-irq Do not touch IRQ CPU affinity of NIC\n");
322 printf(" -v|--version Show version\n");
323 printf(" -h|--help Guess what?!\n");
325 printf("Examples:\n");
326 printf(" See trafgen.txf for configuration file examples.\n");
327 printf(" trafgen --dev eth0 --conf trafgen.txf --bind-cpu 0\n");
328 printf(" trafgen --dev eth0 --conf trafgen.txf --rand --gap 1000\n");
329 printf(" trafgen --dev eth0 --conf trafgen.txf --bind-cpu 0 --num 10 --rand\n");
330 printf(" trafgen --interactive\n");
331 printf(" trafgen --interactive --dev mgmt0 (only start server on mgmt0)\n");
332 printf(" trafgen --interactive --conf trafgen-cli.batch\n");
335 printf(" This tool is targeted for network developers! You should\n");
336 printf(" be aware of what you are doing and what these options above\n");
337 printf(" mean! Only use this tool in an isolated LAN that you own!\n");
339 printf("Please report bugs to <bugs@netsniff-ng.org>\n");
340 printf("Copyright (C) 2011-2012 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,\n");
341 printf("Swiss federal institute of technology (ETH Zurich)\n");
342 printf("License: GNU GPL version 2\n");
343 printf("This is free software: you are free to change and redistribute it.\n");
344 printf("There is NO WARRANTY, to the extent permitted by law.\n\n");
348 static void version(void)
350 printf("\ntrafgen %s, high-perf zero-copy network packet generator\n",
352 printf("http://www.netsniff-ng.org\n\n");
353 printf("Please report bugs to <bugs@netsniff-ng.org>\n");
354 printf("Copyright (C) 2011-2012 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,\n");
355 printf("Swiss federal institute of technology (ETH Zurich)\n");
356 printf("License: GNU GPL version 2\n");
357 printf("This is free software: you are free to change and redistribute it.\n");
358 printf("There is NO WARRANTY, to the extent permitted by law.\n\n");
363 * TX_RING doen't allow us to specify inter-packet gaps, see
364 * http://lingrok.org/source/xref/linux-2.6-linus/net/packet/af_packet.c,
365 * function tpacket_fill_skb(), so instead, we use sendto(2). Since
366 * this is also not high-perf, copying between address spaces is okay.
368 static void tx_tgap_or_die(struct mode
*mode
, struct pktconf
*cfg
)
370 int ifindex
, mtu
, ret
;
372 struct sockaddr_ll s_addr
;
373 unsigned long num
= 1;
376 struct randomizer
*rnd
;
379 panic("Panic over invalid args for TX trigger!\n");
381 panic("Panic over invalid args for TX trigger!\n");
382 if (!device_up_and_running(mode
->device
))
383 panic("Device not up and running!\n");
385 mtu
= device_mtu(mode
->device
);
386 for (l
= 0; l
< cfg
->len
; ++l
) {
387 /* eth src + eth dst + type == 14, fcs added by driver */
388 if (cfg
->pkts
[l
].plen
> mtu
+ 14)
389 panic("Device MTU < than your packet size!\n");
390 if (cfg
->pkts
[l
].plen
<= 14)
391 panic("Device packet size too short!\n");
395 pkt
= xmalloc_aligned(mtu
, 64);
396 fmemset(pkt
, 0, mtu
);
397 ifindex
= device_ifindex(mode
->device
);
402 printf("MD: TX %s %luus\n\n", mode
->rand
? "RND" : "RR", cfg
->gap
);
403 printf("Running! Hang up with ^C!\n\n");
405 fmemset(&s_addr
, 0, sizeof(s_addr
));
406 s_addr
.sll_family
= PF_PACKET
;
407 s_addr
.sll_halen
= ETH_ALEN
;
408 s_addr
.sll_ifindex
= ifindex
;
411 while (likely(sigint
== 0) && likely(num
> 0)) {
412 for (c
= 0; c
< cfg
->pkts
[l
].clen
; ++c
) {
413 cnt
= &(cfg
->pkts
[l
].cnt
[c
]);
414 cnt
->val
-= cnt
->min
;
415 cnt
->val
= (cnt
->val
+ cnt
->inc
) %
416 (cnt
->max
- cnt
->min
+ 1);
417 cnt
->val
+= cnt
->min
;
418 cfg
->pkts
[l
].payload
[cnt
->off
] = cnt
->val
;
421 for (r
= 0; r
< cfg
->pkts
[l
].rlen
; ++r
) {
422 rnd
= &(cfg
->pkts
[l
].rnd
[r
]);
423 rnd
->val
= lcrand(rnd
->val
);
424 cfg
->pkts
[l
].payload
[rnd
->off
] = rnd
->val
;
427 fmemcpy(pkt
, cfg
->pkts
[l
].payload
, cfg
->pkts
[l
].plen
);
428 mode
->stats
.tx_bytes
+= cfg
->pkts
[l
].plen
;
429 mode
->stats
.tx_packets
++;
431 ret
= sendto(sock
, pkt
, cfg
->pkts
[l
].plen
, 0,
432 (struct sockaddr
*) &s_addr
, sizeof(s_addr
));
434 whine("sendto error!\n");
436 l
= mt_rand_int32() % cfg
->len
;
453 printf("\r%12lu frames outgoing\n", mode
->stats
.tx_packets
);
454 printf("\r%12lu bytes outgoing\n", mode
->stats
.tx_bytes
);
457 static void tx_fire_or_die(struct mode
*mode
, struct pktconf
*cfg
)
459 int irq
, ifindex
, mtu
;
460 unsigned int size
, it
= 0;
461 unsigned long num
= 1;
465 struct frame_map
*hdr
;
467 struct randomizer
*rnd
;
470 panic("Panic over invalid args for TX trigger!\n");
472 panic("Panic over invalid args for TX trigger!\n");
473 if (!device_up_and_running(mode
->device
))
474 panic("Device not up and running!\n");
476 mtu
= device_mtu(mode
->device
);
477 for (l
= 0; l
< cfg
->len
; ++l
) {
478 /* eth src + eth dst + type == 14, fcs added by driver */
479 if (cfg
->pkts
[l
].plen
> mtu
+ 14)
480 panic("Device MTU < than your packet size!\n");
481 if (cfg
->pkts
[l
].plen
<= 14)
482 panic("Device packet size too short!\n");
487 fmemset(&tx_ring
, 0, sizeof(tx_ring
));
489 ifindex
= device_ifindex(mode
->device
);
490 size
= ring_size(mode
->device
, mode
->reserve_size
);
492 set_packet_loss_discard(sock
);
493 setup_tx_ring_layout(sock
, &tx_ring
, size
, mode
->jumbo_support
);
494 create_tx_ring(sock
, &tx_ring
);
495 mmap_tx_ring(sock
, &tx_ring
);
496 alloc_tx_ring_frames(&tx_ring
);
497 bind_tx_ring(sock
, &tx_ring
, ifindex
);
498 mt_init_by_seed_time();
500 if (mode
->cpu
>= 0 && ifindex
> 0) {
501 irq
= device_irq_number(mode
->device
);
502 device_bind_irq_to_cpu(mode
->cpu
, irq
);
503 printf("IRQ: %s:%d > CPU%d\n", mode
->device
, irq
,
508 interval
= mode
->kpull
;
512 printf("MD: FIRE %s %luus\n\n", mode
->rand
? "RND" : "RR", interval
);
513 printf("Running! Hang up with ^C!\n\n");
515 itimer
.it_interval
.tv_sec
= 0;
516 itimer
.it_interval
.tv_usec
= interval
;
517 itimer
.it_value
.tv_sec
= 0;
518 itimer
.it_value
.tv_usec
= interval
;
519 setitimer(ITIMER_REAL
, &itimer
, NULL
);
522 while (likely(sigint
== 0) && likely(num
> 0)) {
523 while (user_may_pull_from_tx(tx_ring
.frames
[it
].iov_base
) &&
525 hdr
= tx_ring
.frames
[it
].iov_base
;
526 /* Kernel assumes: data = ph.raw + po->tp_hdrlen -
527 * sizeof(struct sockaddr_ll); */
528 out
= ((uint8_t *) hdr
) + TPACKET_HDRLEN
-
529 sizeof(struct sockaddr_ll
);
531 hdr
->tp_h
.tp_snaplen
= cfg
->pkts
[l
].plen
;
532 hdr
->tp_h
.tp_len
= cfg
->pkts
[l
].plen
;
534 for (c
= 0; c
< cfg
->pkts
[l
].clen
; ++c
) {
535 cnt
= &(cfg
->pkts
[l
].cnt
[c
]);
536 cnt
->val
-= cnt
->min
;
537 cnt
->val
= (cnt
->val
+ cnt
->inc
) %
538 (cnt
->max
- cnt
->min
+ 1);
539 cnt
->val
+= cnt
->min
;
540 cfg
->pkts
[l
].payload
[cnt
->off
] = cnt
->val
;
543 for (r
= 0; r
< cfg
->pkts
[l
].rlen
; ++r
) {
544 rnd
= &(cfg
->pkts
[l
].rnd
[r
]);
545 rnd
->val
= lcrand(rnd
->val
);
546 cfg
->pkts
[l
].payload
[rnd
->off
] = rnd
->val
;
549 fmemcpy(out
, cfg
->pkts
[l
].payload
, cfg
->pkts
[l
].plen
);
550 mode
->stats
.tx_bytes
+= cfg
->pkts
[l
].plen
;
551 mode
->stats
.tx_packets
++;
554 l
= mt_rand_int32() % cfg
->len
;
561 kernel_may_pull_from_tx(&hdr
->tp_h
);
562 next_slot_prewr(&it
, &tx_ring
);
566 if (unlikely(sigint
== 1))
571 destroy_tx_ring(sock
, &tx_ring
);
576 printf("\r%12lu frames outgoing\n", mode
->stats
.tx_packets
);
577 printf("\r%12lu bytes outgoing\n", mode
->stats
.tx_bytes
);
585 static inline char *getuint_or_obj(char *in
, uint32_t *out
, int *type
)
589 } else if (*in
== '$') {
591 if (!strncmp("II", in
, strlen("II"))) {
593 in
= getuint(in
, out
);
595 } else if (!strncmp("PRB", in
, strlen("PRB"))) {
599 panic("Syntax error!\n");
601 in
= getuint(in
, out
);
608 static void dump_conf(struct pktconf
*cfg
)
612 printf("n %lu, gap %lu us, pkts %zu\n", cfg
->num
, cfg
->gap
, cfg
->len
);
615 for (i
= 0; i
< cfg
->len
; ++i
) {
616 printf("[%zu] pkt\n", i
);
617 printf(" len %zu cnts %zu rnds %zu\n", cfg
->pkts
[i
].plen
,
618 cfg
->pkts
[i
].clen
, cfg
->pkts
[i
].rlen
);
620 for (j
= 0; j
< cfg
->pkts
[i
].plen
; ++j
)
621 printf("%02x ", cfg
->pkts
[i
].payload
[j
]);
623 for (j
= 0; j
< cfg
->pkts
[i
].clen
; ++j
)
624 printf(" cnt%zu [%u,%u], inc %u, off %ld\n",
625 j
, cfg
->pkts
[i
].cnt
[j
].min
,
626 cfg
->pkts
[i
].cnt
[j
].max
,
627 cfg
->pkts
[i
].cnt
[j
].inc
,
628 cfg
->pkts
[i
].cnt
[j
].off
);
629 for (j
= 0; j
< cfg
->pkts
[i
].rlen
; ++j
)
630 printf(" rnd%zu off %ld\n",
631 j
, cfg
->pkts
[i
].rnd
[j
].off
);
635 /* Seems to need a rewrite later ;-) */
636 static void parse_conf_or_die(char *file
, struct pktconf
*cfg
)
638 unsigned int withinpkt
= 0;
639 unsigned long line
= 0;
640 char *pb
, buff
[1024];
642 struct counter
*cnts
= NULL
;
647 panic("Panic over invalid args for the parser!\n");
649 fp
= fopen(file
, "r");
651 panic("Cannot open config file!\n");
652 fmemset(buff
, 0, sizeof(buff
));
657 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
659 buff
[sizeof(buff
) - 1] = 0;
662 /* A comment or junk. Skip this line */
663 if (*pb
== '#' || *pb
== '\n') {
664 fmemset(buff
, 0, sizeof(buff
));
668 if (!withinpkt
&& *pb
== '$') {
670 if (!strncmp("II", pb
, strlen("II"))) {
671 uint32_t id
, min
= 0, max
= 0xFF, inc
= 1;
673 pb
= getuint(pb
, &id
);
674 pb
= skipchar(pb
, ':');
676 pb
= getuint(pb
, &min
);
677 pb
= skipchar(pb
, ',');
678 pb
= getuint(pb
, &max
);
679 pb
= skipchar(pb
, ',');
680 pb
= getuint(pb
, &inc
);
682 cnts
= xrealloc(cnts
, 1, l
* sizeof(*cnts
));
683 cnts
[l
- 1].id
= 0xFF & id
;
684 cnts
[l
- 1].min
= 0xFF & min
;
685 cnts
[l
- 1].max
= 0xFF & max
;
686 cnts
[l
- 1].inc
= 0xFF & inc
;
687 if (cnts
[l
- 1].min
>= cnts
[l
- 1].max
)
688 panic("Counter min >= max!\n");
689 if (cnts
[l
- 1].inc
>= cnts
[l
- 1].max
)
690 panic("Counter inc >= max!\n");
691 } else if (!strncmp("P", pb
, strlen("P"))) {
694 pb
= getuint(pb
, &id
);
696 pb
= skipchar(pb
, '{');
699 cfg
->pkts
= xrealloc(cfg
->pkts
, 1,
700 cfg
->len
* sizeof(*cfg
->pkts
));
701 fmemset(&cfg
->pkts
[cfg
->len
- 1], 0,
702 sizeof(cfg
->pkts
[cfg
->len
- 1]));
705 panic("Unknown instruction! Syntax error "
706 "on line %lu!\n", line
);
707 } else if (withinpkt
&& *pb
== '}') {
709 } else if (withinpkt
) {
714 pb
= getuint_or_obj(pb
, &val
, &type
);
715 if (type
== TYPE_EOL
)
717 if (type
== TYPE_CNT
) {
720 for (i
= 0; i
< l
; ++i
) {
721 if (val
== cnts
[i
].id
) {
727 panic("Counter %u not found!\n");
730 z
= ++(cfg
->pkts
[cfg
->len
- 1].clen
);
731 cfg
->pkts
[cfg
->len
- 1].cnt
=
732 xrealloc(cfg
->pkts
[cfg
->len
- 1].cnt
,
733 1, z
* sizeof(struct counter
));
734 new = &cfg
->pkts
[cfg
->len
- 1].cnt
[z
- 1];
735 new->min
= cnts
[i
].min
;
736 new->max
= cnts
[i
].max
;
737 new->inc
= cnts
[i
].inc
;
740 } else if (type
== TYPE_RND
) {
742 struct randomizer
*new;
745 z
= ++(cfg
->pkts
[cfg
->len
- 1].rlen
);
746 cfg
->pkts
[cfg
->len
- 1].rnd
=
747 xrealloc(cfg
->pkts
[cfg
->len
- 1].rnd
,
748 1, z
* sizeof(struct randomizer
));
749 new = &cfg
->pkts
[cfg
->len
- 1].rnd
[z
- 1];
754 cfg
->pkts
[cfg
->len
- 1].plen
++;
755 cfg
->pkts
[cfg
->len
- 1].payload
=
756 xrealloc(cfg
->pkts
[cfg
->len
- 1].payload
,
757 1, cfg
->pkts
[cfg
->len
- 1].plen
);
758 cfg
->pkts
[cfg
->len
- 1].payload
[cfg
->pkts
[cfg
->len
- 1].plen
- 1] =
761 pb
= skipchar_s(pb
, ',');
764 panic("Syntax error!\n");
765 fmemset(buff
, 0, sizeof(buff
));
774 static void cleanup_cfg(struct pktconf
*cfg
)
778 for (l
= 0; l
< cfg
->len
; ++l
) {
779 if (cfg
->pkts
[l
].plen
> 0)
780 xfree(cfg
->pkts
[l
].payload
);
781 if (cfg
->pkts
[l
].clen
> 0)
782 xfree(cfg
->pkts
[l
].cnt
);
783 if (cfg
->pkts
[l
].rlen
> 0)
784 xfree(cfg
->pkts
[l
].rnd
);
791 static int main_loop(struct mode
*mode
, char *confname
, unsigned long pkts
,
794 struct pktconf cfg
= {
800 parse_conf_or_die(confname
, &cfg
);
802 tx_tgap_or_die(mode
, &cfg
);
804 tx_fire_or_die(mode
, &cfg
);
810 int main(int argc
, char **argv
)
812 int c
, opt_index
, ret
, i
, j
, interactive
= 0;
813 char *confname
= NULL
, *ptr
;
814 unsigned long pkts
= 0, gap
= 0;
815 bool prio_high
= false;
818 check_for_root_maybe_die();
820 fmemset(&mode
, 0, sizeof(mode
));
821 mode
.cpu
= CPU_UNKNOWN
;
823 while ((c
= getopt_long(argc
, argv
, short_options
, long_options
,
824 &opt_index
)) != EOF
) {
833 mode
.device
= xstrndup(optarg
, IFNAMSIZ
);
842 mode
.jumbo_support
= 1;
845 confname
= xstrdup(optarg
);
848 mode
.kpull
= atol(optarg
);
858 mode
.reserve_size
= 0;
860 for (j
= i
= strlen(optarg
); i
> 0; --i
) {
861 if (!isdigit(optarg
[j
- i
]))
866 if (!strncmp(ptr
, "KB", strlen("KB")))
867 mode
.reserve_size
= 1 << 10;
868 else if (!strncmp(ptr
, "MB", strlen("MB")))
869 mode
.reserve_size
= 1 << 20;
870 else if (!strncmp(ptr
, "GB", strlen("GB")))
871 mode
.reserve_size
= 1 << 30;
873 panic("Syntax error in ring size param!\n");
876 mode
.reserve_size
*= atoi(optarg
);
879 set_cpu_affinity(optarg
, 0);
880 /* Take the first CPU for rebinding the IRQ */
881 if (mode
.cpu
!= CPU_NOTOUCH
)
882 mode
.cpu
= atoi(optarg
);
885 set_cpu_affinity(optarg
, 1);
891 mode
.cpu
= CPU_NOTOUCH
;
903 panic("Option -%c requires an argument!\n",
907 whine("Unknown option character "
908 "`0x%X\'!\n", optopt
);
916 if (!interactive
&& argc
< 5)
918 if (interactive
&& argc
< 2)
920 if (!interactive
&& mode
.device
== NULL
)
921 panic("No networking device given!\n");
922 if (!interactive
&& confname
== NULL
)
923 panic("No configuration file given!\n");
924 if (!interactive
&& device_mtu(mode
.device
) == 0)
925 panic("This is no networking device!\n");
926 if (!interactive
&& device_up_and_running(mode
.device
) == 0)
927 panic("Networking device not running!\n");
929 register_signal(SIGINT
, signal_handler
);
930 register_signal(SIGHUP
, signal_handler
);
931 register_signal_f(SIGALRM
, timer_elapsed
, SA_SIGINFO
);
935 if (prio_high
== true) {
936 set_proc_prio(get_default_proc_prio());
937 set_sched_status(get_default_sched_policy(),
938 get_default_sched_prio());
942 ret
= main_loop_interactive(&mode
, confname
);
944 ret
= main_loop(&mode
, confname
, pkts
, gap
);