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"
197 struct randomizer
*rnd
;
209 unsigned long tx_bytes
;
210 unsigned long tx_packets
;
219 /* 0 for automatic, > 0 for manual */
220 unsigned int reserve_size
;
224 #define CPU_UNKNOWN -1
225 #define CPU_NOTOUCH -2
227 sig_atomic_t sigint
= 0;
229 static const char *short_options
= "d:c:n:t:vJhS:HQb:B:rk:";
231 static struct option long_options
[] = {
232 {"dev", required_argument
, 0, 'd'},
233 {"conf", required_argument
, 0, 'c'},
234 {"num", required_argument
, 0, 'n'},
235 {"gap", required_argument
, 0, 't'},
236 {"ring-size", required_argument
, 0, 'S'},
237 {"bind-cpu", required_argument
, 0, 'b'},
238 {"unbind-cpu", required_argument
, 0, 'B'},
239 {"kernel-pull", required_argument
, 0, 'k'},
240 {"jumbo-support", no_argument
, 0, 'J'},
241 {"rand", no_argument
, 0, 'r'},
242 {"prio-high", no_argument
, 0, 'H'},
243 {"notouch-irq", no_argument
, 0, 'Q'},
244 {"version", no_argument
, 0, 'v'},
245 {"help", no_argument
, 0, 'h'},
249 static struct itimerval itimer
;
251 static unsigned long interval
= TX_KERNEL_PULL_INT
;
253 static inline uint8_t lcrand(uint8_t val
)
255 return 0xFF & (3 * val
+ 3);
258 static void signal_handler(int number
)
271 static void timer_elapsed(int number
)
273 itimer
.it_interval
.tv_sec
= 0;
274 itimer
.it_interval
.tv_usec
= interval
;
275 itimer
.it_value
.tv_sec
= 0;
276 itimer
.it_value
.tv_usec
= interval
;
278 pull_and_flush_tx_ring(sock
);
279 setitimer(ITIMER_REAL
, &itimer
, NULL
);
282 static void header(void)
284 printf("%s%s%s\n", colorize_start(bold
), "trafgen "
285 VERSION_STRING
, colorize_end());
288 static void help(void)
290 printf("\ntrafgen %s, high-perf zero-copy network packet generator\n",
292 printf("http://www.netsniff-ng.org\n\n");
293 printf("Usage: trafgen [options]\n");
294 printf("Options:\n");
295 printf(" -d|--dev <netdev> Networking Device i.e., eth0\n");
296 printf(" -c|--conf <file> Packet configuration file\n");
297 printf(" -J|--jumbo-support Support for 64KB Super Jumbo Frames\n");
298 printf(" Default TX slot: 2048Byte\n");
299 printf(" -n|--num <uint> Number of packets until exit\n");
300 printf(" `-- 0 Loop until interrupt (default)\n");
301 printf(" `- n Send n packets and done\n");
302 printf(" -r|--rand Randomize packet selection process\n");
303 printf(" Instead of a round robin selection\n");
304 printf(" -t|--gap <uint> Interpacket gap in us (approx)\n");
305 printf(" -S|--ring-size <size> Manually set ring size to <size>:\n");
306 printf(" mmap space in KB/MB/GB, e.g. \'10MB\'\n");
307 printf(" -k|--kernel-pull <uint>Kernel pull from user interval in us\n");
308 printf(" Default is 10us where the TX_RING\n");
309 printf(" is populated with payload from uspace\n");
310 printf(" -b|--bind-cpu <cpu> Bind to specific CPU (or CPU-range)\n");
311 printf(" -B|--unbind-cpu <cpu> Forbid to use specific CPU (or CPU-range)\n");
312 printf(" -H|--prio-high Make this high priority process\n");
313 printf(" -Q|--notouch-irq Do not touch IRQ CPU affinity of NIC\n");
314 printf(" -v|--version Show version\n");
315 printf(" -h|--help Guess what?!\n");
317 printf("Examples:\n");
318 printf(" See trafgen.txf for configuration file examples.\n");
319 printf(" trafgen --dev eth0 --conf trafgen.txf --bind-cpu 0\n");
320 printf(" trafgen --dev eth0 --conf trafgen.txf --rand --gap 1000\n");
321 printf(" trafgen --dev eth0 --conf trafgen.txf --bind-cpu 0 --num 10 --rand\n");
324 printf(" This tool is targeted for network developers! You should\n");
325 printf(" be aware of what you are doing and what these options above\n");
326 printf(" mean! Only use this tool in an isolated LAN that you own!\n");
328 printf("Please report bugs to <bugs@netsniff-ng.org>\n");
329 printf("Copyright (C) 2011-2012 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,\n");
330 printf("Swiss federal institute of technology (ETH Zurich)\n");
331 printf("License: GNU GPL version 2\n");
332 printf("This is free software: you are free to change and redistribute it.\n");
333 printf("There is NO WARRANTY, to the extent permitted by law.\n\n");
337 static void version(void)
339 printf("\ntrafgen %s, high-perf zero-copy network packet generator\n",
341 printf("http://www.netsniff-ng.org\n\n");
342 printf("Please report bugs to <bugs@netsniff-ng.org>\n");
343 printf("Copyright (C) 2011-2012 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,\n");
344 printf("Swiss federal institute of technology (ETH Zurich)\n");
345 printf("License: GNU GPL version 2\n");
346 printf("This is free software: you are free to change and redistribute it.\n");
347 printf("There is NO WARRANTY, to the extent permitted by law.\n\n");
352 * TX_RING doen't allow us to specify inter-packet gaps, see
353 * http://lingrok.org/source/xref/linux-2.6-linus/net/packet/af_packet.c,
354 * function tpacket_fill_skb(), so instead, we use sendto(2). Since
355 * this is also not high-perf, copying between address spaces is okay.
357 static void tx_tgap_or_die(struct mode
*mode
, struct pktconf
*cfg
)
359 int ifindex
, mtu
, ret
;
361 struct sockaddr_ll s_addr
;
362 unsigned long num
= 1;
365 struct randomizer
*rnd
;
368 panic("Panic over invalid args for TX trigger!\n");
370 panic("Panic over invalid args for TX trigger!\n");
371 if (!device_up_and_running(mode
->device
))
372 panic("Device not up and running!\n");
374 mtu
= device_mtu(mode
->device
);
375 for (l
= 0; l
< cfg
->len
; ++l
) {
376 /* eth src + eth dst + type == 14, fcs added by driver */
377 if (cfg
->pkts
[l
].plen
> mtu
+ 14)
378 panic("Device MTU < than your packet size!\n");
379 if (cfg
->pkts
[l
].plen
<= 14)
380 panic("Device packet size too short!\n");
385 pkt
= xmalloc_aligned(mtu
, 64);
387 ifindex
= device_ifindex(mode
->device
);
392 printf("MD: TX %s %luus\n\n", mode
->rand
? "RND" : "RR", cfg
->gap
);
393 printf("Running! Hang up with ^C!\n\n");
395 memset(&s_addr
, 0, sizeof(s_addr
));
396 s_addr
.sll_family
= PF_PACKET
;
397 s_addr
.sll_halen
= ETH_ALEN
;
398 s_addr
.sll_ifindex
= ifindex
;
401 while (likely(sigint
== 0) && likely(num
> 0)) {
402 for (c
= 0; c
< cfg
->pkts
[l
].clen
; ++c
) {
403 cnt
= &(cfg
->pkts
[l
].cnt
[c
]);
404 cnt
->val
-= cnt
->min
;
405 cnt
->val
= (cnt
->val
+ cnt
->inc
) %
406 (cnt
->max
- cnt
->min
+ 1);
407 cnt
->val
+= cnt
->min
;
408 cfg
->pkts
[l
].payload
[cnt
->off
] = cnt
->val
;
411 for (r
= 0; r
< cfg
->pkts
[l
].rlen
; ++r
) {
412 rnd
= &(cfg
->pkts
[l
].rnd
[r
]);
413 rnd
->val
= lcrand(rnd
->val
);
414 cfg
->pkts
[l
].payload
[rnd
->off
] = rnd
->val
;
417 __memcpy(pkt
, cfg
->pkts
[l
].payload
, cfg
->pkts
[l
].plen
);
418 mode
->stats
.tx_bytes
+= cfg
->pkts
[l
].plen
;
419 mode
->stats
.tx_packets
++;
421 ret
= sendto(sock
, pkt
, cfg
->pkts
[l
].plen
, 0,
422 (struct sockaddr
*) &s_addr
, sizeof(s_addr
));
424 whine("sendto error!\n");
426 l
= mt_rand_int32() % cfg
->len
;
443 printf("\r%12lu frames outgoing\n", mode
->stats
.tx_packets
);
444 printf("\r%12lu bytes outgoing\n", mode
->stats
.tx_bytes
);
447 static void tx_fire_or_die(struct mode
*mode
, struct pktconf
*cfg
)
449 int irq
, ifindex
, mtu
;
450 unsigned int size
, it
= 0;
451 unsigned long num
= 1;
455 struct frame_map
*hdr
;
457 struct randomizer
*rnd
;
460 panic("Panic over invalid args for TX trigger!\n");
462 panic("Panic over invalid args for TX trigger!\n");
463 if (!device_up_and_running(mode
->device
))
464 panic("Device not up and running!\n");
466 mtu
= device_mtu(mode
->device
);
467 for (l
= 0; l
< cfg
->len
; ++l
) {
468 /* eth src + eth dst + type == 14, fcs added by driver */
469 if (cfg
->pkts
[l
].plen
> mtu
+ 14)
470 panic("Device MTU < than your packet size!\n");
471 if (cfg
->pkts
[l
].plen
<= 14)
472 panic("Device packet size too short!\n");
478 memset(&tx_ring
, 0, sizeof(tx_ring
));
480 ifindex
= device_ifindex(mode
->device
);
481 size
= ring_size(mode
->device
, mode
->reserve_size
);
483 set_packet_loss_discard(sock
);
484 setup_tx_ring_layout(sock
, &tx_ring
, size
, mode
->jumbo_support
);
485 create_tx_ring(sock
, &tx_ring
);
486 mmap_tx_ring(sock
, &tx_ring
);
487 alloc_tx_ring_frames(&tx_ring
);
488 bind_tx_ring(sock
, &tx_ring
, ifindex
);
489 mt_init_by_seed_time();
491 if (mode
->cpu
>= 0 && ifindex
> 0) {
492 irq
= device_irq_number(mode
->device
);
493 device_bind_irq_to_cpu(mode
->cpu
, irq
);
494 printf("IRQ: %s:%d > CPU%d\n", mode
->device
, irq
,
499 interval
= mode
->kpull
;
503 printf("MD: FIRE %s %luus\n\n", mode
->rand
? "RND" : "RR", interval
);
504 printf("Running! Hang up with ^C!\n\n");
506 itimer
.it_interval
.tv_sec
= 0;
507 itimer
.it_interval
.tv_usec
= interval
;
508 itimer
.it_value
.tv_sec
= 0;
509 itimer
.it_value
.tv_usec
= interval
;
510 setitimer(ITIMER_REAL
, &itimer
, NULL
);
513 while (likely(sigint
== 0) && likely(num
> 0)) {
514 while (user_may_pull_from_tx(tx_ring
.frames
[it
].iov_base
) &&
516 hdr
= tx_ring
.frames
[it
].iov_base
;
517 /* Kernel assumes: data = ph.raw + po->tp_hdrlen -
518 * sizeof(struct sockaddr_ll); */
519 out
= ((uint8_t *) hdr
) + TPACKET_HDRLEN
-
520 sizeof(struct sockaddr_ll
);
522 hdr
->tp_h
.tp_snaplen
= cfg
->pkts
[l
].plen
;
523 hdr
->tp_h
.tp_len
= cfg
->pkts
[l
].plen
;
525 for (c
= 0; c
< cfg
->pkts
[l
].clen
; ++c
) {
526 cnt
= &(cfg
->pkts
[l
].cnt
[c
]);
527 cnt
->val
-= cnt
->min
;
528 cnt
->val
= (cnt
->val
+ cnt
->inc
) %
529 (cnt
->max
- cnt
->min
+ 1);
530 cnt
->val
+= cnt
->min
;
531 cfg
->pkts
[l
].payload
[cnt
->off
] = cnt
->val
;
534 for (r
= 0; r
< cfg
->pkts
[l
].rlen
; ++r
) {
535 rnd
= &(cfg
->pkts
[l
].rnd
[r
]);
536 rnd
->val
= lcrand(rnd
->val
);
537 cfg
->pkts
[l
].payload
[rnd
->off
] = rnd
->val
;
540 __memcpy(out
, cfg
->pkts
[l
].payload
, cfg
->pkts
[l
].plen
);
541 mode
->stats
.tx_bytes
+= cfg
->pkts
[l
].plen
;
542 mode
->stats
.tx_packets
++;
545 l
= mt_rand_int32() % cfg
->len
;
552 kernel_may_pull_from_tx(&hdr
->tp_h
);
553 next_slot(&it
, &tx_ring
);
557 if (unlikely(sigint
== 1))
562 destroy_tx_ring(sock
, &tx_ring
);
567 printf("\r%12lu frames outgoing\n", mode
->stats
.tx_packets
);
568 printf("\r%12lu bytes outgoing\n", mode
->stats
.tx_bytes
);
576 static inline char *getuint_or_obj(char *in
, uint32_t *out
, int *type
)
580 } else if (*in
== '$') {
582 if (!strncmp("II", in
, strlen("II"))) {
584 in
= getuint(in
, out
);
586 } else if (!strncmp("PRB", in
, strlen("PRB"))) {
590 panic("Syntax error!\n");
592 in
= getuint(in
, out
);
599 static void dump_conf(struct pktconf
*cfg
)
603 printf("n %lu, gap %lu us, pkts %zu\n", cfg
->num
, cfg
->gap
, cfg
->len
);
606 for (i
= 0; i
< cfg
->len
; ++i
) {
607 printf("[%zu] pkt\n", i
);
608 printf(" len %zu cnts %zu rnds %zu\n", cfg
->pkts
[i
].plen
,
609 cfg
->pkts
[i
].clen
, cfg
->pkts
[i
].rlen
);
611 for (j
= 0; j
< cfg
->pkts
[i
].plen
; ++j
)
612 printf("%02x ", cfg
->pkts
[i
].payload
[j
]);
614 for (j
= 0; j
< cfg
->pkts
[i
].clen
; ++j
)
615 printf(" cnt%zu [%u,%u], inc %u, off %zu\n",
616 j
, cfg
->pkts
[i
].cnt
[j
].min
,
617 cfg
->pkts
[i
].cnt
[j
].max
,
618 cfg
->pkts
[i
].cnt
[j
].inc
,
619 cfg
->pkts
[i
].cnt
[j
].off
);
620 for (j
= 0; j
< cfg
->pkts
[i
].rlen
; ++j
)
621 printf(" rnd%zu off %zu\n",
622 j
, cfg
->pkts
[i
].rnd
[j
].off
);
626 /* Seems to need a rewrite later ;-) */
627 static void parse_conf_or_die(char *file
, struct pktconf
*cfg
)
629 unsigned int withinpkt
= 0;
630 unsigned long line
= 0;
631 char *pb
, buff
[1024];
633 struct counter
*cnts
= NULL
;
638 panic("Panic over invalid args for the parser!\n");
640 fp
= fopen(file
, "r");
642 panic("Cannot open config file!\n");
643 memset(buff
, 0, sizeof(buff
));
648 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
650 buff
[sizeof(buff
) - 1] = 0;
653 /* A comment or junk. Skip this line */
654 if (*pb
== '#' || *pb
== '\n') {
655 memset(buff
, 0, sizeof(buff
));
659 if (!withinpkt
&& *pb
== '$') {
661 if (!strncmp("II", pb
, strlen("II"))) {
662 uint32_t id
, min
= 0, max
= 0xFF, inc
= 1;
664 pb
= getuint(pb
, &id
);
665 pb
= skipchar(pb
, ':');
667 pb
= getuint(pb
, &min
);
668 pb
= skipchar(pb
, ',');
669 pb
= getuint(pb
, &max
);
670 pb
= skipchar(pb
, ',');
671 pb
= getuint(pb
, &inc
);
673 cnts
= xrealloc(cnts
, 1, l
* sizeof(*cnts
));
674 cnts
[l
- 1].id
= 0xFF & id
;
675 cnts
[l
- 1].min
= 0xFF & min
;
676 cnts
[l
- 1].max
= 0xFF & max
;
677 cnts
[l
- 1].inc
= 0xFF & inc
;
678 if (cnts
[l
- 1].min
>= cnts
[l
- 1].max
)
679 panic("Counter min >= max!\n");
680 if (cnts
[l
- 1].inc
>= cnts
[l
- 1].max
)
681 panic("Counter inc >= max!\n");
682 } else if (!strncmp("P", pb
, strlen("P"))) {
685 pb
= getuint(pb
, &id
);
687 pb
= skipchar(pb
, '{');
690 cfg
->pkts
= xrealloc(cfg
->pkts
, 1,
691 cfg
->len
* sizeof(*cfg
->pkts
));
692 memset(&cfg
->pkts
[cfg
->len
- 1], 0,
693 sizeof(cfg
->pkts
[cfg
->len
- 1]));
696 panic("Unknown instruction! Syntax error "
697 "on line %lu!\n", line
);
698 } else if (withinpkt
&& *pb
== '}') {
700 } else if (withinpkt
) {
705 pb
= getuint_or_obj(pb
, &val
, &type
);
706 if (type
== TYPE_EOL
)
708 if (type
== TYPE_CNT
) {
711 for (i
= 0; i
< l
; ++i
) {
712 if (val
== cnts
[i
].id
) {
718 panic("Counter %u not found!\n");
721 z
= ++(cfg
->pkts
[cfg
->len
- 1].clen
);
722 cfg
->pkts
[cfg
->len
- 1].cnt
=
723 xrealloc(cfg
->pkts
[cfg
->len
- 1].cnt
,
724 1, z
* sizeof(struct counter
));
725 new = &cfg
->pkts
[cfg
->len
- 1].cnt
[z
- 1];
726 new->min
= cnts
[i
].min
;
727 new->max
= cnts
[i
].max
;
728 new->inc
= cnts
[i
].inc
;
731 } else if (type
== TYPE_RND
) {
733 struct randomizer
*new;
736 z
= ++(cfg
->pkts
[cfg
->len
- 1].rlen
);
737 cfg
->pkts
[cfg
->len
- 1].rnd
=
738 xrealloc(cfg
->pkts
[cfg
->len
- 1].rnd
,
739 1, z
* sizeof(struct randomizer
));
740 new = &cfg
->pkts
[cfg
->len
- 1].rnd
[z
- 1];
745 cfg
->pkts
[cfg
->len
- 1].plen
++;
746 cfg
->pkts
[cfg
->len
- 1].payload
=
747 xrealloc(cfg
->pkts
[cfg
->len
- 1].payload
,
748 1, cfg
->pkts
[cfg
->len
- 1].plen
);
749 cfg
->pkts
[cfg
->len
- 1].payload
[cfg
->pkts
[cfg
->len
- 1].plen
- 1] =
752 pb
= skipchar_s(pb
, ',');
755 panic("Syntax error!\n");
756 memset(buff
, 0, sizeof(buff
));
765 static void cleanup_cfg(struct pktconf
*cfg
)
769 for (l
= 0; l
< cfg
->len
; ++l
) {
770 if (cfg
->pkts
[l
].plen
> 0)
771 xfree(cfg
->pkts
[l
].payload
);
772 if (cfg
->pkts
[l
].clen
> 0)
773 xfree(cfg
->pkts
[l
].cnt
);
774 if (cfg
->pkts
[l
].rlen
> 0)
775 xfree(cfg
->pkts
[l
].rnd
);
782 static int main_loop(struct mode
*mode
, char *confname
, unsigned long pkts
,
785 struct pktconf cfg
= {
791 parse_conf_or_die(confname
, &cfg
);
793 tx_tgap_or_die(mode
, &cfg
);
795 tx_fire_or_die(mode
, &cfg
);
801 int main(int argc
, char **argv
)
803 int c
, opt_index
, ret
, i
, j
;
804 char *confname
= NULL
, *ptr
;
805 unsigned long pkts
= 0, gap
= 0;
806 bool prio_high
= false;
809 check_for_root_maybe_die();
811 memset(&mode
, 0, sizeof(mode
));
812 mode
.cpu
= CPU_UNKNOWN
;
814 while ((c
= getopt_long(argc
, argv
, short_options
, long_options
,
815 &opt_index
)) != EOF
) {
824 mode
.device
= xstrndup(optarg
, IFNAMSIZ
);
830 mode
.jumbo_support
= 1;
833 confname
= xstrdup(optarg
);
836 mode
.kpull
= atol(optarg
);
846 mode
.reserve_size
= 0;
848 for (j
= i
= strlen(optarg
); i
> 0; --i
) {
849 if (!isdigit(optarg
[j
- i
]))
854 if (!strncmp(ptr
, "KB", strlen("KB")))
855 mode
.reserve_size
= 1 << 10;
856 else if (!strncmp(ptr
, "MB", strlen("MB")))
857 mode
.reserve_size
= 1 << 20;
858 else if (!strncmp(ptr
, "GB", strlen("GB")))
859 mode
.reserve_size
= 1 << 30;
861 panic("Syntax error in ring size param!\n");
864 mode
.reserve_size
*= atoi(optarg
);
867 set_cpu_affinity(optarg
, 0);
868 /* Take the first CPU for rebinding the IRQ */
869 if (mode
.cpu
!= CPU_NOTOUCH
)
870 mode
.cpu
= atoi(optarg
);
873 set_cpu_affinity(optarg
, 1);
879 mode
.cpu
= CPU_NOTOUCH
;
891 panic("Option -%c requires an argument!\n",
895 whine("Unknown option character "
896 "`0x%X\'!\n", optopt
);
906 if (mode
.device
== NULL
)
907 panic("No networking device given!\n");
908 if (confname
== NULL
)
909 panic("No configuration file given!\n");
910 if (device_mtu(mode
.device
) == 0)
911 panic("This is no networking device!\n");
912 if (device_up_and_running(mode
.device
) == 0)
913 panic("Networking device not running!\n");
915 register_signal(SIGINT
, signal_handler
);
916 register_signal(SIGHUP
, signal_handler
);
917 register_signal_f(SIGALRM
, timer_elapsed
, SA_SIGINFO
);
921 if (prio_high
== true) {
922 set_proc_prio(get_default_proc_prio());
923 set_sched_status(get_default_sched_policy(),
924 get_default_sched_prio());
927 ret
= main_loop(&mode
, confname
, pkts
, gap
);