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][-n|--num <uint>]
33 [-r|--rand][-t|--gap <usec>][-S|--ring-size <size>]
34 [-k|--kernel-pull <usec>][-b|--bind-cpu <cpu>][-B|--unbind-cpu <cpu>]
35 [-H|--prio-high][-Q|--notouch-irq][-v|--version][-h|--help]
39 A high-performance network traffic generator that uses the zero-copy TX_RING
40 for network I/O. For instance, on comodity Gigabit hardware up to 1,488,095 pps
41 64 Byte pps have been achieved with trafgen.
47 =item trafgen --dev eth0 --conf trafgen.txf --bind-cpu 0
49 Use packet configuration trafgen.txf, eth0 as transmission device and CPU0
50 for binding the process.
60 Print help text and lists all options.
66 =item -d|--dev <netdev>
68 Device for transmission i.e., eth0.
70 =item -c|--conf <conf>
72 Path to packet configuration file.
74 =item -J|--jumbo-support
76 Support for 64KB Super Jumbo Frames
80 Number of packets to generate before exiting.
81 0 means forever until SIGINT.
85 Randomize packet selection process instead of round-robin.
89 Interpacket gap in microseconds.
91 =item -S|--ring-size <size>
93 Manually set ring size to <size>: mmap space in KB/MB/GB.
95 =item -k|--kernel-pull <uint>
97 Kernel pull from user interval in microseconds.
98 Default value is 10 microseconds.
100 =item -b|--bind-cpu <cpu>
102 Bind to specific CPU (or CPU-range).
104 =item -B|--unbind-cpu <cpu>
106 Forbid to use specific CPU (or CPU-range).
110 Make this high priority process.
112 =item -Q|--notouch-irq
114 Do not touch IRQ CPU affinity of NIC.
122 =item Generate traffic defined in trafgen.txf on eth0 using CPU 0
124 trafgen --dev eth0 --conf trafgen.txf --bind-cpu 0
126 =item Generate traffic on eth0 using CPU 0, wait 100 us between packets
128 trafgen --dev eth0 --conf trafgen.txf --bind-cpu 0 --gap 100
130 =item Generate 100,000 packet on eth0 using CPU 0
132 trafgen --dev eth0 --conf trafgen.txf --bind-cpu 0 --num 100000
138 Written by Daniel Borkmann <daniel@netsniff-ng.org>
142 Documentation by Emmanuel Roullit <emmanuel@netsniff-ng.org>
146 Please report bugs to <bugs@netsniff-ng.org>
157 #include <sys/socket.h>
158 #include <sys/types.h>
159 #include <sys/stat.h>
160 #include <sys/time.h>
167 #include <net/ethernet.h>
170 #include "opt_memcpy.h"
178 #include "timespec.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 sig_atomic_t sigint
= 0;
233 static const char *short_options
= "d:c:n:t:vJhS:HQb:B:rk:";
235 static struct option long_options
[] = {
236 {"dev", required_argument
, 0, 'd'},
237 {"conf", required_argument
, 0, 'c'},
238 {"num", required_argument
, 0, 'n'},
239 {"gap", required_argument
, 0, 't'},
240 {"ring-size", required_argument
, 0, 'S'},
241 {"bind-cpu", required_argument
, 0, 'b'},
242 {"unbind-cpu", required_argument
, 0, 'B'},
243 {"kernel-pull", required_argument
, 0, 'k'},
244 {"jumbo-support", no_argument
, 0, 'J'},
245 {"rand", no_argument
, 0, 'r'},
246 {"prio-high", no_argument
, 0, 'H'},
247 {"notouch-irq", no_argument
, 0, 'Q'},
248 {"version", no_argument
, 0, 'v'},
249 {"help", no_argument
, 0, 'h'},
253 static struct itimerval itimer
;
255 static unsigned long interval
= TX_KERNEL_PULL_INT
;
257 static inline uint8_t lcrand(uint8_t val
)
259 return 0xFF & (3 * val
+ 3);
262 static void signal_handler(int number
)
275 static void timer_elapsed(int number
)
277 itimer
.it_interval
.tv_sec
= 0;
278 itimer
.it_interval
.tv_usec
= interval
;
279 itimer
.it_value
.tv_sec
= 0;
280 itimer
.it_value
.tv_usec
= interval
;
282 pull_and_flush_tx_ring(sock
);
283 setitimer(ITIMER_REAL
, &itimer
, NULL
);
286 static void header(void)
288 printf("%s%s%s\n", colorize_start(bold
), "trafgen "
289 VERSION_STRING
, colorize_end());
292 static void help(void)
294 printf("\ntrafgen %s, high-perf zero-copy network packet generator\n",
296 printf("http://www.netsniff-ng.org\n\n");
297 printf("Usage: trafgen [options]\n");
298 printf("Options:\n");
299 printf(" -d|--dev <netdev> Networking Device i.e., eth0\n");
300 printf(" -c|--conf <file> Packet configuration file\n");
301 printf(" -J|--jumbo-support Support for 64KB Super Jumbo Frames\n");
302 printf(" Default TX slot: 2048Byte\n");
303 printf(" -n|--num <uint> Number of packets until exit\n");
304 printf(" `-- 0 Loop until interrupt (default)\n");
305 printf(" `- n Send n packets and done\n");
306 printf(" -r|--rand Randomize packet selection process\n");
307 printf(" Instead of a round robin selection\n");
308 printf(" -t|--gap <uint> Interpacket gap in us (approx)\n");
309 printf(" -S|--ring-size <size> Manually set ring size to <size>:\n");
310 printf(" mmap space in KB/MB/GB, e.g. \'10MB\'\n");
311 printf(" -k|--kernel-pull <uint>Kernel pull from user interval in us\n");
312 printf(" Default is 10us where the TX_RING\n");
313 printf(" is populated with payload from uspace\n");
314 printf(" -b|--bind-cpu <cpu> Bind to specific CPU (or CPU-range)\n");
315 printf(" -B|--unbind-cpu <cpu> Forbid to use specific CPU (or CPU-range)\n");
316 printf(" -H|--prio-high Make this high priority process\n");
317 printf(" -Q|--notouch-irq Do not touch IRQ CPU affinity of NIC\n");
318 printf(" -v|--version Show version\n");
319 printf(" -h|--help Guess what?!\n");
321 printf("Examples:\n");
322 printf(" See trafgen.txf for configuration file examples.\n");
323 printf(" trafgen --dev eth0 --conf trafgen.txf --bind-cpu 0\n");
324 printf(" trafgen --dev eth0 --conf trafgen.txf --rand --gap 1000\n");
325 printf(" trafgen --dev eth0 --conf trafgen.txf --bind-cpu 0 --num 10 --rand\n");
328 printf(" This tool is targeted for network developers! You should\n");
329 printf(" be aware of what you are doing and what these options above\n");
330 printf(" mean! Only use this tool in an isolated LAN that you own!\n");
332 printf("Please report bugs to <bugs@netsniff-ng.org>\n");
333 printf("Copyright (C) 2011 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,\n");
334 printf("Swiss federal institute of technology (ETH Zurich)\n");
335 printf("License: GNU GPL version 2\n");
336 printf("This is free software: you are free to change and redistribute it.\n");
337 printf("There is NO WARRANTY, to the extent permitted by law.\n\n");
342 static void version(void)
344 printf("\ntrafgen %s, high-perf zero-copy network packet generator\n",
346 printf("http://www.netsniff-ng.org\n\n");
347 printf("Please report bugs to <bugs@netsniff-ng.org>\n");
348 printf("Copyright (C) 2011 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,\n");
349 printf("Swiss federal institute of technology (ETH Zurich)\n");
350 printf("License: GNU GPL version 2\n");
351 printf("This is free software: you are free to change and redistribute it.\n");
352 printf("There is NO WARRANTY, to the extent permitted by law.\n\n");
358 * TX_RING doen't allow us to specify inter-packet gaps, see
359 * http://lingrok.org/source/xref/linux-2.6-linus/net/packet/af_packet.c,
360 * function tpacket_fill_skb(), so instead, we use sendto(2). Since
361 * this is also not high-perf, copying between address spaces is okay.
363 static void tx_tgap_or_die(struct mode
*mode
, struct pktconf
*cfg
)
365 int ifindex
, mtu
, ret
;
367 struct sockaddr_ll s_addr
;
368 unsigned long num
= 1;
371 struct randomizer
*rnd
;
374 panic("Panic over invalid args for TX trigger!\n");
376 panic("Panic over invalid args for TX trigger!\n");
377 if (!device_up_and_running(mode
->device
))
378 panic("Device not up and running!\n");
380 mtu
= device_mtu(mode
->device
);
381 for (l
= 0; l
< cfg
->len
; ++l
) {
382 /* eth src + eth dst + type == 14, fcs added by driver */
383 if (cfg
->pkts
[l
].plen
> mtu
+ 14)
384 panic("Device MTU < than your packet size!\n");
385 if (cfg
->pkts
[l
].plen
<= 14)
386 panic("Device packet size too short!\n");
391 pkt
= xmalloc_aligned(mtu
, 64);
393 ifindex
= device_ifindex(mode
->device
);
398 printf("MD: TX %s %luus\n\n", mode
->rand
? "RND" : "RR", cfg
->gap
);
399 printf("Running! Hang up with ^C!\n\n");
401 memset(&s_addr
, 0, sizeof(s_addr
));
402 s_addr
.sll_family
= PF_PACKET
;
403 s_addr
.sll_halen
= ETH_ALEN
;
404 s_addr
.sll_ifindex
= ifindex
;
407 while (likely(sigint
== 0) && likely(num
> 0)) {
408 for (c
= 0; c
< cfg
->pkts
[l
].clen
; ++c
) {
409 cnt
= &(cfg
->pkts
[l
].cnt
[c
]);
410 cnt
->val
-= cnt
->min
;
411 cnt
->val
= (cnt
->val
+ cnt
->inc
) %
412 (cnt
->max
- cnt
->min
+ 1);
413 cnt
->val
+= cnt
->min
;
414 cfg
->pkts
[l
].payload
[cnt
->off
] = cnt
->val
;
417 for (r
= 0; r
< cfg
->pkts
[l
].rlen
; ++r
) {
418 rnd
= &(cfg
->pkts
[l
].rnd
[r
]);
419 rnd
->val
= lcrand(rnd
->val
);
420 cfg
->pkts
[l
].payload
[rnd
->off
] = rnd
->val
;
423 __memcpy(pkt
, cfg
->pkts
[l
].payload
, cfg
->pkts
[l
].plen
);
424 mode
->stats
.tx_bytes
+= cfg
->pkts
[l
].plen
;
425 mode
->stats
.tx_packets
++;
427 ret
= sendto(sock
, pkt
, cfg
->pkts
[l
].plen
, 0,
428 (struct sockaddr
*) &s_addr
, sizeof(s_addr
));
430 whine("sendto error!\n");
432 l
= mt_rand_int32() % cfg
->len
;
449 printf("\r%12lu frames outgoing\n", mode
->stats
.tx_packets
);
450 printf("\r%12lu bytes outgoing\n", mode
->stats
.tx_bytes
);
453 static void tx_fire_or_die(struct mode
*mode
, struct pktconf
*cfg
)
455 int irq
, ifindex
, mtu
;
456 unsigned int size
, it
= 0;
457 unsigned long num
= 1;
461 struct frame_map
*hdr
;
463 struct randomizer
*rnd
;
466 panic("Panic over invalid args for TX trigger!\n");
468 panic("Panic over invalid args for TX trigger!\n");
469 if (!device_up_and_running(mode
->device
))
470 panic("Device not up and running!\n");
472 mtu
= device_mtu(mode
->device
);
473 for (l
= 0; l
< cfg
->len
; ++l
) {
474 /* eth src + eth dst + type == 14, fcs added by driver */
475 if (cfg
->pkts
[l
].plen
> mtu
+ 14)
476 panic("Device MTU < than your packet size!\n");
477 if (cfg
->pkts
[l
].plen
<= 14)
478 panic("Device packet size too short!\n");
484 memset(&tx_ring
, 0, sizeof(tx_ring
));
486 ifindex
= device_ifindex(mode
->device
);
487 size
= ring_size(mode
->device
, mode
->reserve_size
);
489 set_packet_loss_discard(sock
);
490 setup_tx_ring_layout(sock
, &tx_ring
, size
, mode
->jumbo_support
);
491 create_tx_ring(sock
, &tx_ring
);
492 mmap_tx_ring(sock
, &tx_ring
);
493 alloc_tx_ring_frames(&tx_ring
);
494 bind_tx_ring(sock
, &tx_ring
, ifindex
);
495 mt_init_by_seed_time();
497 if (mode
->cpu
>= 0 && ifindex
> 0) {
498 irq
= device_irq_number(mode
->device
);
499 device_bind_irq_to_cpu(mode
->cpu
, irq
);
500 printf("IRQ: %s:%d > CPU%d\n", mode
->device
, irq
,
505 interval
= mode
->kpull
;
509 printf("MD: FIRE %s %luus\n\n", mode
->rand
? "RND" : "RR", interval
);
510 printf("Running! Hang up with ^C!\n\n");
512 itimer
.it_interval
.tv_sec
= 0;
513 itimer
.it_interval
.tv_usec
= interval
;
514 itimer
.it_value
.tv_sec
= 0;
515 itimer
.it_value
.tv_usec
= interval
;
516 setitimer(ITIMER_REAL
, &itimer
, NULL
);
519 while (likely(sigint
== 0) && likely(num
> 0)) {
520 while (user_may_pull_from_tx(tx_ring
.frames
[it
].iov_base
) &&
522 hdr
= tx_ring
.frames
[it
].iov_base
;
523 /* Kernel assumes: data = ph.raw + po->tp_hdrlen -
524 * sizeof(struct sockaddr_ll); */
525 out
= ((uint8_t *) hdr
) + TPACKET_HDRLEN
-
526 sizeof(struct sockaddr_ll
);
528 hdr
->tp_h
.tp_snaplen
= cfg
->pkts
[l
].plen
;
529 hdr
->tp_h
.tp_len
= cfg
->pkts
[l
].plen
;
531 for (c
= 0; c
< cfg
->pkts
[l
].clen
; ++c
) {
532 cnt
= &(cfg
->pkts
[l
].cnt
[c
]);
533 cnt
->val
-= cnt
->min
;
534 cnt
->val
= (cnt
->val
+ cnt
->inc
) %
535 (cnt
->max
- cnt
->min
+ 1);
536 cnt
->val
+= cnt
->min
;
537 cfg
->pkts
[l
].payload
[cnt
->off
] = cnt
->val
;
540 for (r
= 0; r
< cfg
->pkts
[l
].rlen
; ++r
) {
541 rnd
= &(cfg
->pkts
[l
].rnd
[r
]);
542 rnd
->val
= lcrand(rnd
->val
);
543 cfg
->pkts
[l
].payload
[rnd
->off
] = rnd
->val
;
546 __memcpy(out
, cfg
->pkts
[l
].payload
, cfg
->pkts
[l
].plen
);
547 mode
->stats
.tx_bytes
+= cfg
->pkts
[l
].plen
;
548 mode
->stats
.tx_packets
++;
551 l
= mt_rand_int32() % cfg
->len
;
558 kernel_may_pull_from_tx(&hdr
->tp_h
);
559 next_slot(&it
, &tx_ring
);
563 if (unlikely(sigint
== 1))
568 destroy_tx_ring(sock
, &tx_ring
);
573 printf("\r%12lu frames outgoing\n", mode
->stats
.tx_packets
);
574 printf("\r%12lu bytes outgoing\n", mode
->stats
.tx_bytes
);
582 static inline char *getuint_or_obj(char *in
, uint32_t *out
, int *type
)
586 } else if (*in
== '$') {
588 if (!strncmp("II", in
, strlen("II"))) {
590 in
= getuint(in
, out
);
592 } else if (!strncmp("PRB", in
, strlen("PRB"))) {
596 panic("Syntax error!\n");
598 in
= getuint(in
, out
);
605 static void dump_conf(struct pktconf
*cfg
)
609 info("n %lu, gap %lu us, pkts %zu\n", cfg
->num
, cfg
->gap
, cfg
->len
);
613 for (i
= 0; i
< cfg
->len
; ++i
) {
614 info("[%zu] pkt\n", i
);
615 info(" len %zu cnts %zu rnds %zu\n", cfg
->pkts
[i
].plen
,
616 cfg
->pkts
[i
].clen
, cfg
->pkts
[i
].rlen
);
618 for (j
= 0; j
< cfg
->pkts
[i
].plen
; ++j
)
619 info("%02x ", cfg
->pkts
[i
].payload
[j
]);
621 for (j
= 0; j
< cfg
->pkts
[i
].clen
; ++j
)
622 info(" cnt%zu [%u,%u], inc %u, off %zu\n",
623 j
, cfg
->pkts
[i
].cnt
[j
].min
,
624 cfg
->pkts
[i
].cnt
[j
].max
,
625 cfg
->pkts
[i
].cnt
[j
].inc
,
626 cfg
->pkts
[i
].cnt
[j
].off
);
627 for (j
= 0; j
< cfg
->pkts
[i
].rlen
; ++j
)
628 info(" rnd%zu off %zu\n",
629 j
, cfg
->pkts
[i
].rnd
[j
].off
);
633 /* Seems to need a rewrite later ;-) */
634 static void parse_conf_or_die(char *file
, struct pktconf
*cfg
)
636 unsigned int withinpkt
= 0;
637 unsigned long line
= 0;
638 char *pb
, buff
[1024];
640 struct counter
*cnts
= NULL
;
645 panic("Panic over invalid args for the parser!\n");
647 fp
= fopen(file
, "r");
649 panic("Cannot open config file!\n");
650 memset(buff
, 0, sizeof(buff
));
655 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
657 buff
[sizeof(buff
) - 1] = 0;
660 /* A comment or junk. Skip this line */
661 if (*pb
== '#' || *pb
== '\n') {
662 memset(buff
, 0, sizeof(buff
));
666 if (!withinpkt
&& *pb
== '$') {
668 if (!strncmp("II", pb
, strlen("II"))) {
669 uint32_t id
, min
= 0, max
= 0xFF, inc
= 1;
671 pb
= getuint(pb
, &id
);
672 pb
= skipchar(pb
, ':');
674 pb
= getuint(pb
, &min
);
675 pb
= skipchar(pb
, ',');
676 pb
= getuint(pb
, &max
);
677 pb
= skipchar(pb
, ',');
678 pb
= getuint(pb
, &inc
);
680 cnts
= xrealloc(cnts
, 1, l
* sizeof(*cnts
));
681 cnts
[l
- 1].id
= 0xFF & id
;
682 cnts
[l
- 1].min
= 0xFF & min
;
683 cnts
[l
- 1].max
= 0xFF & max
;
684 cnts
[l
- 1].inc
= 0xFF & inc
;
685 if (cnts
[l
- 1].min
>= cnts
[l
- 1].max
)
686 panic("Counter min >= max!\n");
687 if (cnts
[l
- 1].inc
>= cnts
[l
- 1].max
)
688 panic("Counter inc >= max!\n");
689 } else if (!strncmp("P", pb
, strlen("P"))) {
692 pb
= getuint(pb
, &id
);
694 pb
= skipchar(pb
, '{');
697 cfg
->pkts
= xrealloc(cfg
->pkts
, 1,
698 cfg
->len
* sizeof(*cfg
->pkts
));
699 memset(&cfg
->pkts
[cfg
->len
- 1], 0,
700 sizeof(cfg
->pkts
[cfg
->len
- 1]));
703 panic("Unknown instruction! Syntax error "
704 "on line %lu!\n", line
);
705 } else if (withinpkt
&& *pb
== '}') {
707 } else if (withinpkt
) {
712 pb
= getuint_or_obj(pb
, &val
, &type
);
713 if (type
== TYPE_EOL
)
715 if (type
== TYPE_CNT
) {
718 for (i
= 0; i
< l
; ++i
) {
719 if (val
== cnts
[i
].id
) {
725 panic("Counter %u not found!\n");
728 z
= ++(cfg
->pkts
[cfg
->len
- 1].clen
);
729 cfg
->pkts
[cfg
->len
- 1].cnt
=
730 xrealloc(cfg
->pkts
[cfg
->len
- 1].cnt
,
731 1, z
* sizeof(struct counter
));
732 new = &cfg
->pkts
[cfg
->len
- 1].cnt
[z
- 1];
733 new->min
= cnts
[i
].min
;
734 new->max
= cnts
[i
].max
;
735 new->inc
= cnts
[i
].inc
;
738 } else if (type
== TYPE_RND
) {
740 struct randomizer
*new;
743 z
= ++(cfg
->pkts
[cfg
->len
- 1].rlen
);
744 cfg
->pkts
[cfg
->len
- 1].rnd
=
745 xrealloc(cfg
->pkts
[cfg
->len
- 1].rnd
,
746 1, z
* sizeof(struct randomizer
));
747 new = &cfg
->pkts
[cfg
->len
- 1].rnd
[z
- 1];
752 cfg
->pkts
[cfg
->len
- 1].plen
++;
753 cfg
->pkts
[cfg
->len
- 1].payload
=
754 xrealloc(cfg
->pkts
[cfg
->len
- 1].payload
,
755 1, cfg
->pkts
[cfg
->len
- 1].plen
);
756 cfg
->pkts
[cfg
->len
- 1].payload
[cfg
->pkts
[cfg
->len
- 1].plen
- 1] =
759 pb
= skipchar_s(pb
, ',');
762 panic("Syntax error!\n");
763 memset(buff
, 0, sizeof(buff
));
772 static void cleanup_cfg(struct pktconf
*cfg
)
776 for (l
= 0; l
< cfg
->len
; ++l
) {
777 if (cfg
->pkts
[l
].plen
> 0)
778 xfree(cfg
->pkts
[l
].payload
);
779 if (cfg
->pkts
[l
].clen
> 0)
780 xfree(cfg
->pkts
[l
].cnt
);
781 if (cfg
->pkts
[l
].rlen
> 0)
782 xfree(cfg
->pkts
[l
].rnd
);
789 static int main_loop(struct mode
*mode
, char *confname
, unsigned long pkts
,
792 struct pktconf cfg
= {
798 parse_conf_or_die(confname
, &cfg
);
800 tx_tgap_or_die(mode
, &cfg
);
802 tx_fire_or_die(mode
, &cfg
);
808 int main(int argc
, char **argv
)
810 int c
, opt_index
, ret
, i
, j
;
811 char *confname
= NULL
, *ptr
;
812 unsigned long pkts
= 0, gap
= 0;
813 bool prio_high
= false;
816 check_for_root_maybe_die();
818 memset(&mode
, 0, sizeof(mode
));
819 mode
.cpu
= CPU_UNKNOWN
;
821 while ((c
= getopt_long(argc
, argv
, short_options
, long_options
,
822 &opt_index
)) != EOF
) {
831 mode
.device
= xstrndup(optarg
, IFNAMSIZ
);
837 mode
.jumbo_support
= 1;
840 confname
= xstrdup(optarg
);
843 mode
.kpull
= atol(optarg
);
853 mode
.reserve_size
= 0;
855 for (j
= i
= strlen(optarg
); i
> 0; --i
) {
856 if (!isdigit(optarg
[j
- i
]))
861 if (!strncmp(ptr
, "KB", strlen("KB")))
862 mode
.reserve_size
= 1 << 10;
863 else if (!strncmp(ptr
, "MB", strlen("MB")))
864 mode
.reserve_size
= 1 << 20;
865 else if (!strncmp(ptr
, "GB", strlen("GB")))
866 mode
.reserve_size
= 1 << 30;
868 panic("Syntax error in ring size param!\n");
871 mode
.reserve_size
*= atoi(optarg
);
874 set_cpu_affinity(optarg
, 0);
875 /* Take the first CPU for rebinding the IRQ */
876 if (mode
.cpu
!= CPU_NOTOUCH
)
877 mode
.cpu
= atoi(optarg
);
880 set_cpu_affinity(optarg
, 1);
886 mode
.cpu
= CPU_NOTOUCH
;
898 panic("Option -%c requires an argument!\n",
902 whine("Unknown option character "
903 "`0x%X\'!\n", optopt
);
913 if (mode
.device
== NULL
)
914 panic("No networking device given!\n");
915 if (confname
== NULL
)
916 panic("No configuration file given!\n");
917 if (device_mtu(mode
.device
) == 0)
918 panic("This is no networking device!\n");
919 if (device_up_and_running(mode
.device
) == 0)
920 panic("Networking device not running!\n");
922 register_signal(SIGINT
, signal_handler
);
923 register_signal(SIGHUP
, signal_handler
);
924 register_signal_f(SIGALRM
, timer_elapsed
, SA_SIGINFO
);
928 if (prio_high
== true) {
929 set_proc_prio(get_default_proc_prio());
930 set_sched_status(get_default_sched_policy(),
931 get_default_sched_prio());
934 ret
= main_loop(&mode
, confname
, pkts
, gap
);