3 * Copyright 2001, 2002 by Robert Olsson <robert.olsson@its.uu.se>
4 * Uppsala University and
5 * Swedish University of Agricultural Sciences
7 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
8 * Ben Greear <greearb@candelatech.com>
9 * Jens Låås <jens.laas@data.slu.se>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
17 * A tool for loading the network with preconfigurated packets.
18 * The tool is implemented as a linux module. Parameters are output
19 * device, delay (to hard_xmit), number of packets, and whether
20 * to use multiple SKBs or just the same one.
21 * pktgen uses the installed interface's output routine.
23 * Additional hacking by:
25 * Jens.Laas@data.slu.se
26 * Improved by ANK. 010120.
27 * Improved by ANK even more. 010212.
28 * MAC address typo fixed. 010417 --ro
29 * Integrated. 020301 --DaveM
30 * Added multiskb option 020301 --DaveM
31 * Scaling of results. 020417--sigurdur@linpro.no
32 * Significant re-work of the module:
33 * * Convert to threaded model to more efficiently be able to transmit
34 * and receive on multiple interfaces at once.
35 * * Converted many counters to __u64 to allow longer runs.
36 * * Allow configuration of ranges, like min/max IP address, MACs,
37 * and UDP-ports, for both source and destination, and can
38 * set to use a random distribution or sequentially walk the range.
39 * * Can now change most values after starting.
40 * * Place 12-byte packet in UDP payload with magic number,
41 * sequence number, and timestamp.
42 * * Add receiver code that detects dropped pkts, re-ordered pkts, and
43 * latencies (with micro-second) precision.
44 * * Add IOCTL interface to easily get counters & configuration.
45 * --Ben Greear <greearb@candelatech.com>
47 * Renamed multiskb to clone_skb and cleaned up sending core for two distinct
48 * skb modes. A clone_skb=0 mode for Ben "ranges" work and a clone_skb != 0
49 * as a "fastpath" with a configurable number of clones after alloc's.
50 * clone_skb=0 means all packets are allocated this also means ranges time
51 * stamps etc can be used. clone_skb=100 means 1 malloc is followed by 100
54 * Also moved to /proc/net/pktgen/
57 * Sept 10: Fixed threading/locking. Lots of bone-headed and more clever
58 * mistakes. Also merged in DaveM's patch in the -pre6 patch.
59 * --Ben Greear <greearb@candelatech.com>
61 * Integrated to 2.5.x 021029 --Lucio Maciel (luciomaciel@zipmail.com.br)
64 * 021124 Finished major redesign and rewrite for new functionality.
65 * See Documentation/networking/pktgen.txt for how to use this.
68 * For each CPU one thread/process is created at start. This process checks
69 * for running devices in the if_list and sends packets until count is 0 it
70 * also the thread checks the thread->control which is used for inter-process
71 * communication. controlling process "posts" operations to the threads this
73 * The if_list is RCU protected, and the if_lock remains to protect updating
74 * of if_list, from "add_device" as it invoked from userspace (via proc write).
76 * By design there should only be *one* "controlling" process. In practice
77 * multiple write accesses gives unpredictable result. Understood by "write"
78 * to /proc gives result code thats should be read be the "writer".
79 * For practical use this should be no problem.
81 * Note when adding devices to a specific CPU there good idea to also assign
82 * /proc/irq/XX/smp_affinity so TX-interrupts gets bound to the same CPU.
85 * Fix refcount off by one if first packet fails, potential null deref,
88 * First "ranges" functionality for ipv6 030726 --ro
90 * Included flow support. 030802 ANK.
92 * Fixed unaligned access on IA-64 Grant Grundler <grundler@parisc-linux.org>
94 * Remove if fix from added Harald Welte <laforge@netfilter.org> 040419
95 * ia64 compilation fix from Aron Griffis <aron@hp.com> 040604
97 * New xmit() return, do_div and misc clean up by Stephen Hemminger
98 * <shemminger@osdl.org> 040923
100 * Randy Dunlap fixed u64 printk compiler warning
102 * Remove FCS from BW calculation. Lennert Buytenhek <buytenh@wantstofly.org>
103 * New time handling. Lennert Buytenhek <buytenh@wantstofly.org> 041213
105 * Corrections from Nikolai Malykh (nmalykh@bilim.com)
106 * Removed unused flags F_SET_SRCMAC & F_SET_SRCIP 041230
108 * interruptible_sleep_on_timeout() replaced Nishanth Aravamudan <nacc@us.ibm.com>
111 * MPLS support by Steven Whitehouse <steve@chygwyn.com>
113 * 802.1Q/Q-in-Q support by Francesco Fondelli (FF) <francesco.fondelli@gmail.com>
115 * Fixed src_mac command to set source mac of packet to value specified in
116 * command by Adit Ranadive <adit.262@gmail.com>
120 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
122 #include <linux/sys.h>
123 #include <linux/types.h>
124 #include <linux/module.h>
125 #include <linux/moduleparam.h>
126 #include <linux/kernel.h>
127 #include <linux/mutex.h>
128 #include <linux/sched.h>
129 #include <linux/slab.h>
130 #include <linux/vmalloc.h>
131 #include <linux/unistd.h>
132 #include <linux/string.h>
133 #include <linux/ptrace.h>
134 #include <linux/errno.h>
135 #include <linux/ioport.h>
136 #include <linux/interrupt.h>
137 #include <linux/capability.h>
138 #include <linux/hrtimer.h>
139 #include <linux/freezer.h>
140 #include <linux/delay.h>
141 #include <linux/timer.h>
142 #include <linux/list.h>
143 #include <linux/init.h>
144 #include <linux/skbuff.h>
145 #include <linux/netdevice.h>
146 #include <linux/inet.h>
147 #include <linux/inetdevice.h>
148 #include <linux/rtnetlink.h>
149 #include <linux/if_arp.h>
150 #include <linux/if_vlan.h>
151 #include <linux/in.h>
152 #include <linux/ip.h>
153 #include <linux/ipv6.h>
154 #include <linux/udp.h>
155 #include <linux/proc_fs.h>
156 #include <linux/seq_file.h>
157 #include <linux/wait.h>
158 #include <linux/etherdevice.h>
159 #include <linux/kthread.h>
160 #include <linux/prefetch.h>
161 #include <linux/mmzone.h>
162 #include <net/net_namespace.h>
163 #include <net/checksum.h>
164 #include <net/ipv6.h>
166 #include <net/ip6_checksum.h>
167 #include <net/addrconf.h>
169 #include <net/xfrm.h>
171 #include <net/netns/generic.h>
172 #include <asm/byteorder.h>
173 #include <linux/rcupdate.h>
174 #include <linux/bitops.h>
175 #include <linux/io.h>
176 #include <linux/timex.h>
177 #include <linux/uaccess.h>
179 #include <asm/div64.h> /* do_div */
181 #define VERSION "2.75"
182 #define IP_NAME_SZ 32
183 #define MAX_MPLS_LABELS 16 /* This is the max label stack depth */
184 #define MPLS_STACK_BOTTOM htonl(0x00000100)
186 #define func_enter() pr_debug("entering %s\n", __func__);
189 pf(IPV6) /* Interface in IPV6 Mode */ \
190 pf(IPSRC_RND) /* IP-Src Random */ \
191 pf(IPDST_RND) /* IP-Dst Random */ \
192 pf(TXSIZE_RND) /* Transmit size is random */ \
193 pf(UDPSRC_RND) /* UDP-Src Random */ \
194 pf(UDPDST_RND) /* UDP-Dst Random */ \
195 pf(UDPCSUM) /* Include UDP checksum */ \
196 pf(NO_TIMESTAMP) /* Don't timestamp packets (default TS) */ \
197 pf(MPLS_RND) /* Random MPLS labels */ \
198 pf(QUEUE_MAP_RND) /* queue map Random */ \
199 pf(QUEUE_MAP_CPU) /* queue map mirrors smp_processor_id() */ \
200 pf(FLOW_SEQ) /* Sequential flows */ \
201 pf(IPSEC) /* ipsec on for flows */ \
202 pf(MACSRC_RND) /* MAC-Src Random */ \
203 pf(MACDST_RND) /* MAC-Dst Random */ \
204 pf(VID_RND) /* Random VLAN ID */ \
205 pf(SVID_RND) /* Random SVLAN ID */ \
206 pf(NODE) /* Node memory alloc*/ \
208 #define pf(flag) flag##_SHIFT,
214 /* Device flag bits */
215 #define pf(flag) static const __u32 F_##flag = (1<<flag##_SHIFT);
219 #define pf(flag) __stringify(flag),
220 static char *pkt_flag_names
[] = {
225 #define NR_PKT_FLAGS ARRAY_SIZE(pkt_flag_names)
227 /* Thread control flag bits */
228 #define T_STOP (1<<0) /* Stop run */
229 #define T_RUN (1<<1) /* Start run */
230 #define T_REMDEVALL (1<<2) /* Remove all devs */
231 #define T_REMDEV (1<<3) /* Remove one dev */
234 #define M_START_XMIT 0 /* Default normal TX */
235 #define M_NETIF_RECEIVE 1 /* Inject packets into stack */
236 #define M_QUEUE_XMIT 2 /* Inject packet into qdisc */
238 /* If lock -- protects updating of if_list */
239 #define if_lock(t) mutex_lock(&(t->if_lock));
240 #define if_unlock(t) mutex_unlock(&(t->if_lock));
242 /* Used to help with determining the pkts on receive */
243 #define PKTGEN_MAGIC 0xbe9be955
244 #define PG_PROC_DIR "pktgen"
245 #define PGCTRL "pgctrl"
247 #define MAX_CFLOWS 65536
249 #define VLAN_TAG_SIZE(x) ((x)->vlan_id == 0xffff ? 0 : 4)
250 #define SVLAN_TAG_SIZE(x) ((x)->svlan_id == 0xffff ? 0 : 4)
256 struct xfrm_state
*x
;
262 #define F_INIT (1<<0) /* flow has been initialized */
266 * Try to keep frequent/infrequent used vars. separated.
268 struct proc_dir_entry
*entry
; /* proc file */
269 struct pktgen_thread
*pg_thread
;/* the owner */
270 struct list_head list
; /* chaining in the thread's run-queue */
271 struct rcu_head rcu
; /* freed by RCU */
273 int running
; /* if false, the test will stop */
275 /* If min != max, then we will either do a linear iteration, or
276 * we will do a random selection from within the range.
282 int pkt_overhead
; /* overhead for MPLS, VLANs, IPSEC etc */
284 int removal_mark
; /* non-zero => the device is marked for
285 * removal by worker thread */
288 u64 delay
; /* nano-seconds */
290 __u64 count
; /* Default No packets to send */
291 __u64 sofar
; /* How many pkts we've sent so far */
292 __u64 tx_bytes
; /* How many bytes we've transmitted */
293 __u64 errors
; /* Errors when trying to transmit, */
295 /* runtime counters relating to clone_skb */
298 int last_ok
; /* Was last skb sent?
299 * Or a failed transmit of some sort?
300 * This will keep sequence numbers in order
305 u64 idle_acc
; /* nano-seconds */
310 * Use multiple SKBs during packet gen.
311 * If this number is greater than 1, then
312 * that many copies of the same packet will be
313 * sent before a new packet is allocated.
314 * If you want to send 1024 identical packets
315 * before creating a new packet,
316 * set clone_skb to 1024.
319 char dst_min
[IP_NAME_SZ
]; /* IP, ie 1.2.3.4 */
320 char dst_max
[IP_NAME_SZ
]; /* IP, ie 1.2.3.4 */
321 char src_min
[IP_NAME_SZ
]; /* IP, ie 1.2.3.4 */
322 char src_max
[IP_NAME_SZ
]; /* IP, ie 1.2.3.4 */
324 struct in6_addr in6_saddr
;
325 struct in6_addr in6_daddr
;
326 struct in6_addr cur_in6_daddr
;
327 struct in6_addr cur_in6_saddr
;
329 struct in6_addr min_in6_daddr
;
330 struct in6_addr max_in6_daddr
;
331 struct in6_addr min_in6_saddr
;
332 struct in6_addr max_in6_saddr
;
334 /* If we're doing ranges, random or incremental, then this
335 * defines the min/max for those ranges.
337 __be32 saddr_min
; /* inclusive, source IP address */
338 __be32 saddr_max
; /* exclusive, source IP address */
339 __be32 daddr_min
; /* inclusive, dest IP address */
340 __be32 daddr_max
; /* exclusive, dest IP address */
342 __u16 udp_src_min
; /* inclusive, source UDP port */
343 __u16 udp_src_max
; /* exclusive, source UDP port */
344 __u16 udp_dst_min
; /* inclusive, dest UDP port */
345 __u16 udp_dst_max
; /* exclusive, dest UDP port */
348 __u8 tos
; /* six MSB of (former) IPv4 TOS
349 are for dscp codepoint */
350 __u8 traffic_class
; /* ditto for the (former) Traffic Class in IPv6
351 (see RFC 3260, sec. 4) */
354 unsigned int nr_labels
; /* Depth of stack, 0 = no MPLS */
355 __be32 labels
[MAX_MPLS_LABELS
];
357 /* VLAN/SVLAN (802.1Q/Q-in-Q) */
360 __u16 vlan_id
; /* 0xffff means no vlan tag */
364 __u16 svlan_id
; /* 0xffff means no svlan tag */
366 __u32 src_mac_count
; /* How many MACs to iterate through */
367 __u32 dst_mac_count
; /* How many MACs to iterate through */
369 unsigned char dst_mac
[ETH_ALEN
];
370 unsigned char src_mac
[ETH_ALEN
];
372 __u32 cur_dst_mac_offset
;
373 __u32 cur_src_mac_offset
;
385 0x00, 0x80, 0xC8, 0x79, 0xB3, 0xCB,
387 We fill in SRC address later
388 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
392 __u16 pad
; /* pad out the hh struct to an even 16 bytes */
394 struct sk_buff
*skb
; /* skb we are to transmit next, used for when we
395 * are transmitting the same one multiple times
397 struct net_device
*odev
; /* The out-going device.
398 * Note that the device should have it's
399 * pg_info pointer pointing back to this
401 * Set when the user specifies the out-going
402 * device name (not when the inject is
403 * started as it used to do.)
406 struct flow_state
*flows
;
407 unsigned int cflows
; /* Concurrent flows (config) */
408 unsigned int lflow
; /* Flow length (config) */
409 unsigned int nflows
; /* accumulated flows (stats) */
410 unsigned int curfl
; /* current sequenced flow (state)*/
414 __u32 skb_priority
; /* skb priority field */
415 unsigned int burst
; /* number of duplicated packets to burst */
416 int node
; /* Memory node */
419 __u8 ipsmode
; /* IPSEC mode (config) */
420 __u8 ipsproto
; /* IPSEC type (config) */
422 struct xfrm_dst xdst
;
423 struct dst_ops dstops
;
436 static unsigned int pg_net_id __read_mostly
;
440 struct proc_dir_entry
*proc_dir
;
441 struct list_head pktgen_threads
;
445 struct pktgen_thread
{
446 struct mutex if_lock
; /* for list of devices */
447 struct list_head if_list
; /* All device here */
448 struct list_head th_list
;
449 struct task_struct
*tsk
;
452 /* Field for thread to receive "posted" events terminate,
458 wait_queue_head_t queue
;
459 struct completion start_done
;
460 struct pktgen_net
*net
;
466 static const char version
[] =
467 "Packet Generator for packet performance testing. "
468 "Version: " VERSION
"\n";
470 static int pktgen_remove_device(struct pktgen_thread
*t
, struct pktgen_dev
*i
);
471 static int pktgen_add_device(struct pktgen_thread
*t
, const char *ifname
);
472 static struct pktgen_dev
*pktgen_find_dev(struct pktgen_thread
*t
,
473 const char *ifname
, bool exact
);
474 static int pktgen_device_event(struct notifier_block
*, unsigned long, void *);
475 static void pktgen_run_all_threads(struct pktgen_net
*pn
);
476 static void pktgen_reset_all_threads(struct pktgen_net
*pn
);
477 static void pktgen_stop_all_threads_ifs(struct pktgen_net
*pn
);
479 static void pktgen_stop(struct pktgen_thread
*t
);
480 static void pktgen_clear_counters(struct pktgen_dev
*pkt_dev
);
482 /* Module parameters, defaults. */
483 static int pg_count_d __read_mostly
= 1000;
484 static int pg_delay_d __read_mostly
;
485 static int pg_clone_skb_d __read_mostly
;
486 static int debug __read_mostly
;
488 static DEFINE_MUTEX(pktgen_thread_lock
);
490 static struct notifier_block pktgen_notifier_block
= {
491 .notifier_call
= pktgen_device_event
,
495 * /proc handling functions
499 static int pgctrl_show(struct seq_file
*seq
, void *v
)
501 seq_puts(seq
, version
);
505 static ssize_t
pgctrl_write(struct file
*file
, const char __user
*buf
,
506 size_t count
, loff_t
*ppos
)
509 struct pktgen_net
*pn
= net_generic(current
->nsproxy
->net_ns
, pg_net_id
);
511 if (!capable(CAP_NET_ADMIN
))
517 if (count
> sizeof(data
))
518 count
= sizeof(data
);
520 if (copy_from_user(data
, buf
, count
))
523 data
[count
- 1] = 0; /* Strip trailing '\n' and terminate string */
525 if (!strcmp(data
, "stop"))
526 pktgen_stop_all_threads_ifs(pn
);
528 else if (!strcmp(data
, "start"))
529 pktgen_run_all_threads(pn
);
531 else if (!strcmp(data
, "reset"))
532 pktgen_reset_all_threads(pn
);
540 static int pgctrl_open(struct inode
*inode
, struct file
*file
)
542 return single_open(file
, pgctrl_show
, PDE_DATA(inode
));
545 static const struct file_operations pktgen_fops
= {
549 .write
= pgctrl_write
,
550 .release
= single_release
,
553 static int pktgen_if_show(struct seq_file
*seq
, void *v
)
555 const struct pktgen_dev
*pkt_dev
= seq
->private;
561 "Params: count %llu min_pkt_size: %u max_pkt_size: %u\n",
562 (unsigned long long)pkt_dev
->count
, pkt_dev
->min_pkt_size
,
563 pkt_dev
->max_pkt_size
);
566 " frags: %d delay: %llu clone_skb: %d ifname: %s\n",
567 pkt_dev
->nfrags
, (unsigned long long) pkt_dev
->delay
,
568 pkt_dev
->clone_skb
, pkt_dev
->odevname
);
570 seq_printf(seq
, " flows: %u flowlen: %u\n", pkt_dev
->cflows
,
574 " queue_map_min: %u queue_map_max: %u\n",
575 pkt_dev
->queue_map_min
,
576 pkt_dev
->queue_map_max
);
578 if (pkt_dev
->skb_priority
)
579 seq_printf(seq
, " skb_priority: %u\n",
580 pkt_dev
->skb_priority
);
582 if (pkt_dev
->flags
& F_IPV6
) {
584 " saddr: %pI6c min_saddr: %pI6c max_saddr: %pI6c\n"
585 " daddr: %pI6c min_daddr: %pI6c max_daddr: %pI6c\n",
587 &pkt_dev
->min_in6_saddr
, &pkt_dev
->max_in6_saddr
,
589 &pkt_dev
->min_in6_daddr
, &pkt_dev
->max_in6_daddr
);
592 " dst_min: %s dst_max: %s\n",
593 pkt_dev
->dst_min
, pkt_dev
->dst_max
);
595 " src_min: %s src_max: %s\n",
596 pkt_dev
->src_min
, pkt_dev
->src_max
);
599 seq_puts(seq
, " src_mac: ");
601 seq_printf(seq
, "%pM ",
602 is_zero_ether_addr(pkt_dev
->src_mac
) ?
603 pkt_dev
->odev
->dev_addr
: pkt_dev
->src_mac
);
605 seq_puts(seq
, "dst_mac: ");
606 seq_printf(seq
, "%pM\n", pkt_dev
->dst_mac
);
609 " udp_src_min: %d udp_src_max: %d"
610 " udp_dst_min: %d udp_dst_max: %d\n",
611 pkt_dev
->udp_src_min
, pkt_dev
->udp_src_max
,
612 pkt_dev
->udp_dst_min
, pkt_dev
->udp_dst_max
);
615 " src_mac_count: %d dst_mac_count: %d\n",
616 pkt_dev
->src_mac_count
, pkt_dev
->dst_mac_count
);
618 if (pkt_dev
->nr_labels
) {
619 seq_puts(seq
, " mpls: ");
620 for (i
= 0; i
< pkt_dev
->nr_labels
; i
++)
621 seq_printf(seq
, "%08x%s", ntohl(pkt_dev
->labels
[i
]),
622 i
== pkt_dev
->nr_labels
-1 ? "\n" : ", ");
625 if (pkt_dev
->vlan_id
!= 0xffff)
626 seq_printf(seq
, " vlan_id: %u vlan_p: %u vlan_cfi: %u\n",
627 pkt_dev
->vlan_id
, pkt_dev
->vlan_p
,
630 if (pkt_dev
->svlan_id
!= 0xffff)
631 seq_printf(seq
, " svlan_id: %u vlan_p: %u vlan_cfi: %u\n",
632 pkt_dev
->svlan_id
, pkt_dev
->svlan_p
,
636 seq_printf(seq
, " tos: 0x%02x\n", pkt_dev
->tos
);
638 if (pkt_dev
->traffic_class
)
639 seq_printf(seq
, " traffic_class: 0x%02x\n", pkt_dev
->traffic_class
);
641 if (pkt_dev
->burst
> 1)
642 seq_printf(seq
, " burst: %d\n", pkt_dev
->burst
);
644 if (pkt_dev
->node
>= 0)
645 seq_printf(seq
, " node: %d\n", pkt_dev
->node
);
647 if (pkt_dev
->xmit_mode
== M_NETIF_RECEIVE
)
648 seq_puts(seq
, " xmit_mode: netif_receive\n");
649 else if (pkt_dev
->xmit_mode
== M_QUEUE_XMIT
)
650 seq_puts(seq
, " xmit_mode: xmit_queue\n");
652 seq_puts(seq
, " Flags: ");
654 for (i
= 0; i
< NR_PKT_FLAGS
; i
++) {
656 if (!pkt_dev
->cflows
)
659 if (pkt_dev
->flags
& (1 << i
))
660 seq_printf(seq
, "%s ", pkt_flag_names
[i
]);
661 else if (i
== F_FLOW_SEQ
)
662 seq_puts(seq
, "FLOW_RND ");
665 if (i
== F_IPSEC
&& pkt_dev
->spi
)
666 seq_printf(seq
, "spi:%u", pkt_dev
->spi
);
672 /* not really stopped, more like last-running-at */
673 stopped
= pkt_dev
->running
? ktime_get() : pkt_dev
->stopped_at
;
674 idle
= pkt_dev
->idle_acc
;
675 do_div(idle
, NSEC_PER_USEC
);
678 "Current:\n pkts-sofar: %llu errors: %llu\n",
679 (unsigned long long)pkt_dev
->sofar
,
680 (unsigned long long)pkt_dev
->errors
);
683 " started: %lluus stopped: %lluus idle: %lluus\n",
684 (unsigned long long) ktime_to_us(pkt_dev
->started_at
),
685 (unsigned long long) ktime_to_us(stopped
),
686 (unsigned long long) idle
);
689 " seq_num: %d cur_dst_mac_offset: %d cur_src_mac_offset: %d\n",
690 pkt_dev
->seq_num
, pkt_dev
->cur_dst_mac_offset
,
691 pkt_dev
->cur_src_mac_offset
);
693 if (pkt_dev
->flags
& F_IPV6
) {
694 seq_printf(seq
, " cur_saddr: %pI6c cur_daddr: %pI6c\n",
695 &pkt_dev
->cur_in6_saddr
,
696 &pkt_dev
->cur_in6_daddr
);
698 seq_printf(seq
, " cur_saddr: %pI4 cur_daddr: %pI4\n",
699 &pkt_dev
->cur_saddr
, &pkt_dev
->cur_daddr
);
701 seq_printf(seq
, " cur_udp_dst: %d cur_udp_src: %d\n",
702 pkt_dev
->cur_udp_dst
, pkt_dev
->cur_udp_src
);
704 seq_printf(seq
, " cur_queue_map: %u\n", pkt_dev
->cur_queue_map
);
706 seq_printf(seq
, " flows: %u\n", pkt_dev
->nflows
);
708 if (pkt_dev
->result
[0])
709 seq_printf(seq
, "Result: %s\n", pkt_dev
->result
);
711 seq_puts(seq
, "Result: Idle\n");
717 static int hex32_arg(const char __user
*user_buffer
, unsigned long maxlen
,
723 for (; i
< maxlen
; i
++) {
727 if (get_user(c
, &user_buffer
[i
]))
729 value
= hex_to_bin(c
);
738 static int count_trail_chars(const char __user
* user_buffer
,
743 for (i
= 0; i
< maxlen
; i
++) {
745 if (get_user(c
, &user_buffer
[i
]))
763 static long num_arg(const char __user
*user_buffer
, unsigned long maxlen
,
769 for (i
= 0; i
< maxlen
; i
++) {
771 if (get_user(c
, &user_buffer
[i
]))
773 if ((c
>= '0') && (c
<= '9')) {
782 static int strn_len(const char __user
* user_buffer
, unsigned int maxlen
)
786 for (i
= 0; i
< maxlen
; i
++) {
788 if (get_user(c
, &user_buffer
[i
]))
805 static ssize_t
get_labels(const char __user
*buffer
, struct pktgen_dev
*pkt_dev
)
812 pkt_dev
->nr_labels
= 0;
815 len
= hex32_arg(&buffer
[i
], 8, &tmp
);
818 pkt_dev
->labels
[n
] = htonl(tmp
);
819 if (pkt_dev
->labels
[n
] & MPLS_STACK_BOTTOM
)
820 pkt_dev
->flags
|= F_MPLS_RND
;
822 if (get_user(c
, &buffer
[i
]))
826 if (n
>= MAX_MPLS_LABELS
)
830 pkt_dev
->nr_labels
= n
;
834 static __u32
pktgen_read_flag(const char *f
, bool *disable
)
843 for (i
= 0; i
< NR_PKT_FLAGS
; i
++) {
844 if (!IS_ENABLED(CONFIG_XFRM
) && i
== IPSEC_SHIFT
)
847 /* allow only disabling ipv6 flag */
848 if (!*disable
&& i
== IPV6_SHIFT
)
851 if (strcmp(f
, pkt_flag_names
[i
]) == 0)
855 if (strcmp(f
, "FLOW_RND") == 0) {
856 *disable
= !*disable
;
863 static ssize_t
pktgen_if_write(struct file
*file
,
864 const char __user
* user_buffer
, size_t count
,
867 struct seq_file
*seq
= file
->private_data
;
868 struct pktgen_dev
*pkt_dev
= seq
->private;
870 char name
[16], valstr
[32];
871 unsigned long value
= 0;
872 char *pg_result
= NULL
;
876 pg_result
= &(pkt_dev
->result
[0]);
879 pr_warn("wrong command format\n");
884 tmp
= count_trail_chars(user_buffer
, max
);
886 pr_warn("illegal format\n");
891 /* Read variable name */
893 len
= strn_len(&user_buffer
[i
], sizeof(name
) - 1);
897 memset(name
, 0, sizeof(name
));
898 if (copy_from_user(name
, &user_buffer
[i
], len
))
903 len
= count_trail_chars(&user_buffer
[i
], max
);
910 size_t copy
= min_t(size_t, count
+ 1, 1024);
911 char *tp
= strndup_user(user_buffer
, copy
);
916 pr_debug("%s,%zu buffer -:%s:-\n", name
, count
, tp
);
920 if (!strcmp(name
, "min_pkt_size")) {
921 len
= num_arg(&user_buffer
[i
], 10, &value
);
926 if (value
< 14 + 20 + 8)
928 if (value
!= pkt_dev
->min_pkt_size
) {
929 pkt_dev
->min_pkt_size
= value
;
930 pkt_dev
->cur_pkt_size
= value
;
932 sprintf(pg_result
, "OK: min_pkt_size=%u",
933 pkt_dev
->min_pkt_size
);
937 if (!strcmp(name
, "max_pkt_size")) {
938 len
= num_arg(&user_buffer
[i
], 10, &value
);
943 if (value
< 14 + 20 + 8)
945 if (value
!= pkt_dev
->max_pkt_size
) {
946 pkt_dev
->max_pkt_size
= value
;
947 pkt_dev
->cur_pkt_size
= value
;
949 sprintf(pg_result
, "OK: max_pkt_size=%u",
950 pkt_dev
->max_pkt_size
);
954 /* Shortcut for min = max */
956 if (!strcmp(name
, "pkt_size")) {
957 len
= num_arg(&user_buffer
[i
], 10, &value
);
962 if (value
< 14 + 20 + 8)
964 if (value
!= pkt_dev
->min_pkt_size
) {
965 pkt_dev
->min_pkt_size
= value
;
966 pkt_dev
->max_pkt_size
= value
;
967 pkt_dev
->cur_pkt_size
= value
;
969 sprintf(pg_result
, "OK: pkt_size=%u", pkt_dev
->min_pkt_size
);
973 if (!strcmp(name
, "debug")) {
974 len
= num_arg(&user_buffer
[i
], 10, &value
);
980 sprintf(pg_result
, "OK: debug=%u", debug
);
984 if (!strcmp(name
, "frags")) {
985 len
= num_arg(&user_buffer
[i
], 10, &value
);
990 pkt_dev
->nfrags
= value
;
991 sprintf(pg_result
, "OK: frags=%u", pkt_dev
->nfrags
);
994 if (!strcmp(name
, "delay")) {
995 len
= num_arg(&user_buffer
[i
], 10, &value
);
1000 if (value
== 0x7FFFFFFF)
1001 pkt_dev
->delay
= ULLONG_MAX
;
1003 pkt_dev
->delay
= (u64
)value
;
1005 sprintf(pg_result
, "OK: delay=%llu",
1006 (unsigned long long) pkt_dev
->delay
);
1009 if (!strcmp(name
, "rate")) {
1010 len
= num_arg(&user_buffer
[i
], 10, &value
);
1017 pkt_dev
->delay
= pkt_dev
->min_pkt_size
*8*NSEC_PER_USEC
/value
;
1019 pr_info("Delay set at: %llu ns\n", pkt_dev
->delay
);
1021 sprintf(pg_result
, "OK: rate=%lu", value
);
1024 if (!strcmp(name
, "ratep")) {
1025 len
= num_arg(&user_buffer
[i
], 10, &value
);
1032 pkt_dev
->delay
= NSEC_PER_SEC
/value
;
1034 pr_info("Delay set at: %llu ns\n", pkt_dev
->delay
);
1036 sprintf(pg_result
, "OK: rate=%lu", value
);
1039 if (!strcmp(name
, "udp_src_min")) {
1040 len
= num_arg(&user_buffer
[i
], 10, &value
);
1045 if (value
!= pkt_dev
->udp_src_min
) {
1046 pkt_dev
->udp_src_min
= value
;
1047 pkt_dev
->cur_udp_src
= value
;
1049 sprintf(pg_result
, "OK: udp_src_min=%u", pkt_dev
->udp_src_min
);
1052 if (!strcmp(name
, "udp_dst_min")) {
1053 len
= num_arg(&user_buffer
[i
], 10, &value
);
1058 if (value
!= pkt_dev
->udp_dst_min
) {
1059 pkt_dev
->udp_dst_min
= value
;
1060 pkt_dev
->cur_udp_dst
= value
;
1062 sprintf(pg_result
, "OK: udp_dst_min=%u", pkt_dev
->udp_dst_min
);
1065 if (!strcmp(name
, "udp_src_max")) {
1066 len
= num_arg(&user_buffer
[i
], 10, &value
);
1071 if (value
!= pkt_dev
->udp_src_max
) {
1072 pkt_dev
->udp_src_max
= value
;
1073 pkt_dev
->cur_udp_src
= value
;
1075 sprintf(pg_result
, "OK: udp_src_max=%u", pkt_dev
->udp_src_max
);
1078 if (!strcmp(name
, "udp_dst_max")) {
1079 len
= num_arg(&user_buffer
[i
], 10, &value
);
1084 if (value
!= pkt_dev
->udp_dst_max
) {
1085 pkt_dev
->udp_dst_max
= value
;
1086 pkt_dev
->cur_udp_dst
= value
;
1088 sprintf(pg_result
, "OK: udp_dst_max=%u", pkt_dev
->udp_dst_max
);
1091 if (!strcmp(name
, "clone_skb")) {
1092 len
= num_arg(&user_buffer
[i
], 10, &value
);
1096 ((pkt_dev
->xmit_mode
== M_NETIF_RECEIVE
) ||
1097 !(pkt_dev
->odev
->priv_flags
& IFF_TX_SKB_SHARING
)))
1100 pkt_dev
->clone_skb
= value
;
1102 sprintf(pg_result
, "OK: clone_skb=%d", pkt_dev
->clone_skb
);
1105 if (!strcmp(name
, "count")) {
1106 len
= num_arg(&user_buffer
[i
], 10, &value
);
1111 pkt_dev
->count
= value
;
1112 sprintf(pg_result
, "OK: count=%llu",
1113 (unsigned long long)pkt_dev
->count
);
1116 if (!strcmp(name
, "src_mac_count")) {
1117 len
= num_arg(&user_buffer
[i
], 10, &value
);
1122 if (pkt_dev
->src_mac_count
!= value
) {
1123 pkt_dev
->src_mac_count
= value
;
1124 pkt_dev
->cur_src_mac_offset
= 0;
1126 sprintf(pg_result
, "OK: src_mac_count=%d",
1127 pkt_dev
->src_mac_count
);
1130 if (!strcmp(name
, "dst_mac_count")) {
1131 len
= num_arg(&user_buffer
[i
], 10, &value
);
1136 if (pkt_dev
->dst_mac_count
!= value
) {
1137 pkt_dev
->dst_mac_count
= value
;
1138 pkt_dev
->cur_dst_mac_offset
= 0;
1140 sprintf(pg_result
, "OK: dst_mac_count=%d",
1141 pkt_dev
->dst_mac_count
);
1144 if (!strcmp(name
, "burst")) {
1145 len
= num_arg(&user_buffer
[i
], 10, &value
);
1151 ((pkt_dev
->xmit_mode
== M_QUEUE_XMIT
) ||
1152 ((pkt_dev
->xmit_mode
== M_START_XMIT
) &&
1153 (!(pkt_dev
->odev
->priv_flags
& IFF_TX_SKB_SHARING
)))))
1155 pkt_dev
->burst
= value
< 1 ? 1 : value
;
1156 sprintf(pg_result
, "OK: burst=%d", pkt_dev
->burst
);
1159 if (!strcmp(name
, "node")) {
1160 len
= num_arg(&user_buffer
[i
], 10, &value
);
1166 if (node_possible(value
)) {
1167 pkt_dev
->node
= value
;
1168 sprintf(pg_result
, "OK: node=%d", pkt_dev
->node
);
1169 if (pkt_dev
->page
) {
1170 put_page(pkt_dev
->page
);
1171 pkt_dev
->page
= NULL
;
1175 sprintf(pg_result
, "ERROR: node not possible");
1178 if (!strcmp(name
, "xmit_mode")) {
1182 len
= strn_len(&user_buffer
[i
], sizeof(f
) - 1);
1186 if (copy_from_user(f
, &user_buffer
[i
], len
))
1190 if (strcmp(f
, "start_xmit") == 0) {
1191 pkt_dev
->xmit_mode
= M_START_XMIT
;
1192 } else if (strcmp(f
, "netif_receive") == 0) {
1193 /* clone_skb set earlier, not supported in this mode */
1194 if (pkt_dev
->clone_skb
> 0)
1197 pkt_dev
->xmit_mode
= M_NETIF_RECEIVE
;
1199 /* make sure new packet is allocated every time
1200 * pktgen_xmit() is called
1202 pkt_dev
->last_ok
= 1;
1204 /* override clone_skb if user passed default value
1205 * at module loading time
1207 pkt_dev
->clone_skb
= 0;
1208 } else if (strcmp(f
, "queue_xmit") == 0) {
1209 pkt_dev
->xmit_mode
= M_QUEUE_XMIT
;
1210 pkt_dev
->last_ok
= 1;
1213 "xmit_mode -:%s:- unknown\nAvailable modes: %s",
1214 f
, "start_xmit, netif_receive\n");
1217 sprintf(pg_result
, "OK: xmit_mode=%s", f
);
1220 if (!strcmp(name
, "flag")) {
1223 bool disable
= false;
1226 len
= strn_len(&user_buffer
[i
], sizeof(f
) - 1);
1230 if (copy_from_user(f
, &user_buffer
[i
], len
))
1234 flag
= pktgen_read_flag(f
, &disable
);
1238 pkt_dev
->flags
&= ~flag
;
1240 pkt_dev
->flags
|= flag
;
1243 "Flag -:%s:- unknown\nAvailable flags, (prepend ! to un-set flag):\n%s",
1245 "IPSRC_RND, IPDST_RND, UDPSRC_RND, UDPDST_RND, "
1246 "MACSRC_RND, MACDST_RND, TXSIZE_RND, IPV6, "
1247 "MPLS_RND, VID_RND, SVID_RND, FLOW_SEQ, "
1248 "QUEUE_MAP_RND, QUEUE_MAP_CPU, UDPCSUM, "
1256 sprintf(pg_result
, "OK: flags=0x%x", pkt_dev
->flags
);
1259 if (!strcmp(name
, "dst_min") || !strcmp(name
, "dst")) {
1260 len
= strn_len(&user_buffer
[i
], sizeof(pkt_dev
->dst_min
) - 1);
1264 if (copy_from_user(buf
, &user_buffer
[i
], len
))
1267 if (strcmp(buf
, pkt_dev
->dst_min
) != 0) {
1268 memset(pkt_dev
->dst_min
, 0, sizeof(pkt_dev
->dst_min
));
1269 strcpy(pkt_dev
->dst_min
, buf
);
1270 pkt_dev
->daddr_min
= in_aton(pkt_dev
->dst_min
);
1271 pkt_dev
->cur_daddr
= pkt_dev
->daddr_min
;
1274 pr_debug("dst_min set to: %s\n", pkt_dev
->dst_min
);
1276 sprintf(pg_result
, "OK: dst_min=%s", pkt_dev
->dst_min
);
1279 if (!strcmp(name
, "dst_max")) {
1280 len
= strn_len(&user_buffer
[i
], sizeof(pkt_dev
->dst_max
) - 1);
1284 if (copy_from_user(buf
, &user_buffer
[i
], len
))
1287 if (strcmp(buf
, pkt_dev
->dst_max
) != 0) {
1288 memset(pkt_dev
->dst_max
, 0, sizeof(pkt_dev
->dst_max
));
1289 strcpy(pkt_dev
->dst_max
, buf
);
1290 pkt_dev
->daddr_max
= in_aton(pkt_dev
->dst_max
);
1291 pkt_dev
->cur_daddr
= pkt_dev
->daddr_max
;
1294 pr_debug("dst_max set to: %s\n", pkt_dev
->dst_max
);
1296 sprintf(pg_result
, "OK: dst_max=%s", pkt_dev
->dst_max
);
1299 if (!strcmp(name
, "dst6")) {
1300 len
= strn_len(&user_buffer
[i
], sizeof(buf
) - 1);
1304 pkt_dev
->flags
|= F_IPV6
;
1306 if (copy_from_user(buf
, &user_buffer
[i
], len
))
1310 in6_pton(buf
, -1, pkt_dev
->in6_daddr
.s6_addr
, -1, NULL
);
1311 snprintf(buf
, sizeof(buf
), "%pI6c", &pkt_dev
->in6_daddr
);
1313 pkt_dev
->cur_in6_daddr
= pkt_dev
->in6_daddr
;
1316 pr_debug("dst6 set to: %s\n", buf
);
1319 sprintf(pg_result
, "OK: dst6=%s", buf
);
1322 if (!strcmp(name
, "dst6_min")) {
1323 len
= strn_len(&user_buffer
[i
], sizeof(buf
) - 1);
1327 pkt_dev
->flags
|= F_IPV6
;
1329 if (copy_from_user(buf
, &user_buffer
[i
], len
))
1333 in6_pton(buf
, -1, pkt_dev
->min_in6_daddr
.s6_addr
, -1, NULL
);
1334 snprintf(buf
, sizeof(buf
), "%pI6c", &pkt_dev
->min_in6_daddr
);
1336 pkt_dev
->cur_in6_daddr
= pkt_dev
->min_in6_daddr
;
1338 pr_debug("dst6_min set to: %s\n", buf
);
1341 sprintf(pg_result
, "OK: dst6_min=%s", buf
);
1344 if (!strcmp(name
, "dst6_max")) {
1345 len
= strn_len(&user_buffer
[i
], sizeof(buf
) - 1);
1349 pkt_dev
->flags
|= F_IPV6
;
1351 if (copy_from_user(buf
, &user_buffer
[i
], len
))
1355 in6_pton(buf
, -1, pkt_dev
->max_in6_daddr
.s6_addr
, -1, NULL
);
1356 snprintf(buf
, sizeof(buf
), "%pI6c", &pkt_dev
->max_in6_daddr
);
1359 pr_debug("dst6_max set to: %s\n", buf
);
1362 sprintf(pg_result
, "OK: dst6_max=%s", buf
);
1365 if (!strcmp(name
, "src6")) {
1366 len
= strn_len(&user_buffer
[i
], sizeof(buf
) - 1);
1370 pkt_dev
->flags
|= F_IPV6
;
1372 if (copy_from_user(buf
, &user_buffer
[i
], len
))
1376 in6_pton(buf
, -1, pkt_dev
->in6_saddr
.s6_addr
, -1, NULL
);
1377 snprintf(buf
, sizeof(buf
), "%pI6c", &pkt_dev
->in6_saddr
);
1379 pkt_dev
->cur_in6_saddr
= pkt_dev
->in6_saddr
;
1382 pr_debug("src6 set to: %s\n", buf
);
1385 sprintf(pg_result
, "OK: src6=%s", buf
);
1388 if (!strcmp(name
, "src_min")) {
1389 len
= strn_len(&user_buffer
[i
], sizeof(pkt_dev
->src_min
) - 1);
1393 if (copy_from_user(buf
, &user_buffer
[i
], len
))
1396 if (strcmp(buf
, pkt_dev
->src_min
) != 0) {
1397 memset(pkt_dev
->src_min
, 0, sizeof(pkt_dev
->src_min
));
1398 strcpy(pkt_dev
->src_min
, buf
);
1399 pkt_dev
->saddr_min
= in_aton(pkt_dev
->src_min
);
1400 pkt_dev
->cur_saddr
= pkt_dev
->saddr_min
;
1403 pr_debug("src_min set to: %s\n", pkt_dev
->src_min
);
1405 sprintf(pg_result
, "OK: src_min=%s", pkt_dev
->src_min
);
1408 if (!strcmp(name
, "src_max")) {
1409 len
= strn_len(&user_buffer
[i
], sizeof(pkt_dev
->src_max
) - 1);
1413 if (copy_from_user(buf
, &user_buffer
[i
], len
))
1416 if (strcmp(buf
, pkt_dev
->src_max
) != 0) {
1417 memset(pkt_dev
->src_max
, 0, sizeof(pkt_dev
->src_max
));
1418 strcpy(pkt_dev
->src_max
, buf
);
1419 pkt_dev
->saddr_max
= in_aton(pkt_dev
->src_max
);
1420 pkt_dev
->cur_saddr
= pkt_dev
->saddr_max
;
1423 pr_debug("src_max set to: %s\n", pkt_dev
->src_max
);
1425 sprintf(pg_result
, "OK: src_max=%s", pkt_dev
->src_max
);
1428 if (!strcmp(name
, "dst_mac")) {
1429 len
= strn_len(&user_buffer
[i
], sizeof(valstr
) - 1);
1433 memset(valstr
, 0, sizeof(valstr
));
1434 if (copy_from_user(valstr
, &user_buffer
[i
], len
))
1437 if (!mac_pton(valstr
, pkt_dev
->dst_mac
))
1439 /* Set up Dest MAC */
1440 ether_addr_copy(&pkt_dev
->hh
[0], pkt_dev
->dst_mac
);
1442 sprintf(pg_result
, "OK: dstmac %pM", pkt_dev
->dst_mac
);
1445 if (!strcmp(name
, "src_mac")) {
1446 len
= strn_len(&user_buffer
[i
], sizeof(valstr
) - 1);
1450 memset(valstr
, 0, sizeof(valstr
));
1451 if (copy_from_user(valstr
, &user_buffer
[i
], len
))
1454 if (!mac_pton(valstr
, pkt_dev
->src_mac
))
1456 /* Set up Src MAC */
1457 ether_addr_copy(&pkt_dev
->hh
[6], pkt_dev
->src_mac
);
1459 sprintf(pg_result
, "OK: srcmac %pM", pkt_dev
->src_mac
);
1463 if (!strcmp(name
, "clear_counters")) {
1464 pktgen_clear_counters(pkt_dev
);
1465 sprintf(pg_result
, "OK: Clearing counters.\n");
1469 if (!strcmp(name
, "flows")) {
1470 len
= num_arg(&user_buffer
[i
], 10, &value
);
1475 if (value
> MAX_CFLOWS
)
1478 pkt_dev
->cflows
= value
;
1479 sprintf(pg_result
, "OK: flows=%u", pkt_dev
->cflows
);
1483 if (!strcmp(name
, "spi")) {
1484 len
= num_arg(&user_buffer
[i
], 10, &value
);
1489 pkt_dev
->spi
= value
;
1490 sprintf(pg_result
, "OK: spi=%u", pkt_dev
->spi
);
1494 if (!strcmp(name
, "flowlen")) {
1495 len
= num_arg(&user_buffer
[i
], 10, &value
);
1500 pkt_dev
->lflow
= value
;
1501 sprintf(pg_result
, "OK: flowlen=%u", pkt_dev
->lflow
);
1505 if (!strcmp(name
, "queue_map_min")) {
1506 len
= num_arg(&user_buffer
[i
], 5, &value
);
1511 pkt_dev
->queue_map_min
= value
;
1512 sprintf(pg_result
, "OK: queue_map_min=%u", pkt_dev
->queue_map_min
);
1516 if (!strcmp(name
, "queue_map_max")) {
1517 len
= num_arg(&user_buffer
[i
], 5, &value
);
1522 pkt_dev
->queue_map_max
= value
;
1523 sprintf(pg_result
, "OK: queue_map_max=%u", pkt_dev
->queue_map_max
);
1527 if (!strcmp(name
, "mpls")) {
1528 unsigned int n
, cnt
;
1530 len
= get_labels(&user_buffer
[i
], pkt_dev
);
1534 cnt
= sprintf(pg_result
, "OK: mpls=");
1535 for (n
= 0; n
< pkt_dev
->nr_labels
; n
++)
1536 cnt
+= sprintf(pg_result
+ cnt
,
1537 "%08x%s", ntohl(pkt_dev
->labels
[n
]),
1538 n
== pkt_dev
->nr_labels
-1 ? "" : ",");
1540 if (pkt_dev
->nr_labels
&& pkt_dev
->vlan_id
!= 0xffff) {
1541 pkt_dev
->vlan_id
= 0xffff; /* turn off VLAN/SVLAN */
1542 pkt_dev
->svlan_id
= 0xffff;
1545 pr_debug("VLAN/SVLAN auto turned off\n");
1550 if (!strcmp(name
, "vlan_id")) {
1551 len
= num_arg(&user_buffer
[i
], 4, &value
);
1556 if (value
<= 4095) {
1557 pkt_dev
->vlan_id
= value
; /* turn on VLAN */
1560 pr_debug("VLAN turned on\n");
1562 if (debug
&& pkt_dev
->nr_labels
)
1563 pr_debug("MPLS auto turned off\n");
1565 pkt_dev
->nr_labels
= 0; /* turn off MPLS */
1566 sprintf(pg_result
, "OK: vlan_id=%u", pkt_dev
->vlan_id
);
1568 pkt_dev
->vlan_id
= 0xffff; /* turn off VLAN/SVLAN */
1569 pkt_dev
->svlan_id
= 0xffff;
1572 pr_debug("VLAN/SVLAN turned off\n");
1577 if (!strcmp(name
, "vlan_p")) {
1578 len
= num_arg(&user_buffer
[i
], 1, &value
);
1583 if ((value
<= 7) && (pkt_dev
->vlan_id
!= 0xffff)) {
1584 pkt_dev
->vlan_p
= value
;
1585 sprintf(pg_result
, "OK: vlan_p=%u", pkt_dev
->vlan_p
);
1587 sprintf(pg_result
, "ERROR: vlan_p must be 0-7");
1592 if (!strcmp(name
, "vlan_cfi")) {
1593 len
= num_arg(&user_buffer
[i
], 1, &value
);
1598 if ((value
<= 1) && (pkt_dev
->vlan_id
!= 0xffff)) {
1599 pkt_dev
->vlan_cfi
= value
;
1600 sprintf(pg_result
, "OK: vlan_cfi=%u", pkt_dev
->vlan_cfi
);
1602 sprintf(pg_result
, "ERROR: vlan_cfi must be 0-1");
1607 if (!strcmp(name
, "svlan_id")) {
1608 len
= num_arg(&user_buffer
[i
], 4, &value
);
1613 if ((value
<= 4095) && ((pkt_dev
->vlan_id
!= 0xffff))) {
1614 pkt_dev
->svlan_id
= value
; /* turn on SVLAN */
1617 pr_debug("SVLAN turned on\n");
1619 if (debug
&& pkt_dev
->nr_labels
)
1620 pr_debug("MPLS auto turned off\n");
1622 pkt_dev
->nr_labels
= 0; /* turn off MPLS */
1623 sprintf(pg_result
, "OK: svlan_id=%u", pkt_dev
->svlan_id
);
1625 pkt_dev
->vlan_id
= 0xffff; /* turn off VLAN/SVLAN */
1626 pkt_dev
->svlan_id
= 0xffff;
1629 pr_debug("VLAN/SVLAN turned off\n");
1634 if (!strcmp(name
, "svlan_p")) {
1635 len
= num_arg(&user_buffer
[i
], 1, &value
);
1640 if ((value
<= 7) && (pkt_dev
->svlan_id
!= 0xffff)) {
1641 pkt_dev
->svlan_p
= value
;
1642 sprintf(pg_result
, "OK: svlan_p=%u", pkt_dev
->svlan_p
);
1644 sprintf(pg_result
, "ERROR: svlan_p must be 0-7");
1649 if (!strcmp(name
, "svlan_cfi")) {
1650 len
= num_arg(&user_buffer
[i
], 1, &value
);
1655 if ((value
<= 1) && (pkt_dev
->svlan_id
!= 0xffff)) {
1656 pkt_dev
->svlan_cfi
= value
;
1657 sprintf(pg_result
, "OK: svlan_cfi=%u", pkt_dev
->svlan_cfi
);
1659 sprintf(pg_result
, "ERROR: svlan_cfi must be 0-1");
1664 if (!strcmp(name
, "tos")) {
1665 __u32 tmp_value
= 0;
1666 len
= hex32_arg(&user_buffer
[i
], 2, &tmp_value
);
1672 pkt_dev
->tos
= tmp_value
;
1673 sprintf(pg_result
, "OK: tos=0x%02x", pkt_dev
->tos
);
1675 sprintf(pg_result
, "ERROR: tos must be 00-ff");
1680 if (!strcmp(name
, "traffic_class")) {
1681 __u32 tmp_value
= 0;
1682 len
= hex32_arg(&user_buffer
[i
], 2, &tmp_value
);
1688 pkt_dev
->traffic_class
= tmp_value
;
1689 sprintf(pg_result
, "OK: traffic_class=0x%02x", pkt_dev
->traffic_class
);
1691 sprintf(pg_result
, "ERROR: traffic_class must be 00-ff");
1696 if (!strcmp(name
, "skb_priority")) {
1697 len
= num_arg(&user_buffer
[i
], 9, &value
);
1702 pkt_dev
->skb_priority
= value
;
1703 sprintf(pg_result
, "OK: skb_priority=%i",
1704 pkt_dev
->skb_priority
);
1708 sprintf(pkt_dev
->result
, "No such parameter \"%s\"", name
);
1712 static int pktgen_if_open(struct inode
*inode
, struct file
*file
)
1714 return single_open(file
, pktgen_if_show
, PDE_DATA(inode
));
1717 static const struct file_operations pktgen_if_fops
= {
1718 .open
= pktgen_if_open
,
1720 .llseek
= seq_lseek
,
1721 .write
= pktgen_if_write
,
1722 .release
= single_release
,
1725 static int pktgen_thread_show(struct seq_file
*seq
, void *v
)
1727 struct pktgen_thread
*t
= seq
->private;
1728 const struct pktgen_dev
*pkt_dev
;
1732 seq_puts(seq
, "Running: ");
1735 list_for_each_entry_rcu(pkt_dev
, &t
->if_list
, list
)
1736 if (pkt_dev
->running
)
1737 seq_printf(seq
, "%s ", pkt_dev
->odevname
);
1739 seq_puts(seq
, "\nStopped: ");
1741 list_for_each_entry_rcu(pkt_dev
, &t
->if_list
, list
)
1742 if (!pkt_dev
->running
)
1743 seq_printf(seq
, "%s ", pkt_dev
->odevname
);
1746 seq_printf(seq
, "\nResult: %s\n", t
->result
);
1748 seq_puts(seq
, "\nResult: NA\n");
1755 static ssize_t
pktgen_thread_write(struct file
*file
,
1756 const char __user
* user_buffer
,
1757 size_t count
, loff_t
* offset
)
1759 struct seq_file
*seq
= file
->private_data
;
1760 struct pktgen_thread
*t
= seq
->private;
1761 int i
, max
, len
, ret
;
1766 // sprintf(pg_result, "Wrong command format");
1771 len
= count_trail_chars(user_buffer
, max
);
1777 /* Read variable name */
1779 len
= strn_len(&user_buffer
[i
], sizeof(name
) - 1);
1783 memset(name
, 0, sizeof(name
));
1784 if (copy_from_user(name
, &user_buffer
[i
], len
))
1789 len
= count_trail_chars(&user_buffer
[i
], max
);
1796 pr_debug("t=%s, count=%lu\n", name
, (unsigned long)count
);
1799 pr_err("ERROR: No thread\n");
1804 pg_result
= &(t
->result
[0]);
1806 if (!strcmp(name
, "add_device")) {
1809 len
= strn_len(&user_buffer
[i
], sizeof(f
) - 1);
1814 if (copy_from_user(f
, &user_buffer
[i
], len
))
1817 mutex_lock(&pktgen_thread_lock
);
1818 ret
= pktgen_add_device(t
, f
);
1819 mutex_unlock(&pktgen_thread_lock
);
1822 sprintf(pg_result
, "OK: add_device=%s", f
);
1824 sprintf(pg_result
, "ERROR: can not add device %s", f
);
1828 if (!strcmp(name
, "rem_device_all")) {
1829 mutex_lock(&pktgen_thread_lock
);
1830 t
->control
|= T_REMDEVALL
;
1831 mutex_unlock(&pktgen_thread_lock
);
1832 schedule_timeout_interruptible(msecs_to_jiffies(125)); /* Propagate thread->control */
1834 sprintf(pg_result
, "OK: rem_device_all");
1838 if (!strcmp(name
, "max_before_softirq")) {
1839 sprintf(pg_result
, "OK: Note! max_before_softirq is obsoleted -- Do not use");
1849 static int pktgen_thread_open(struct inode
*inode
, struct file
*file
)
1851 return single_open(file
, pktgen_thread_show
, PDE_DATA(inode
));
1854 static const struct file_operations pktgen_thread_fops
= {
1855 .open
= pktgen_thread_open
,
1857 .llseek
= seq_lseek
,
1858 .write
= pktgen_thread_write
,
1859 .release
= single_release
,
1862 /* Think find or remove for NN */
1863 static struct pktgen_dev
*__pktgen_NN_threads(const struct pktgen_net
*pn
,
1864 const char *ifname
, int remove
)
1866 struct pktgen_thread
*t
;
1867 struct pktgen_dev
*pkt_dev
= NULL
;
1868 bool exact
= (remove
== FIND
);
1870 list_for_each_entry(t
, &pn
->pktgen_threads
, th_list
) {
1871 pkt_dev
= pktgen_find_dev(t
, ifname
, exact
);
1874 pkt_dev
->removal_mark
= 1;
1875 t
->control
|= T_REMDEV
;
1884 * mark a device for removal
1886 static void pktgen_mark_device(const struct pktgen_net
*pn
, const char *ifname
)
1888 struct pktgen_dev
*pkt_dev
= NULL
;
1889 const int max_tries
= 10, msec_per_try
= 125;
1892 mutex_lock(&pktgen_thread_lock
);
1893 pr_debug("%s: marking %s for removal\n", __func__
, ifname
);
1897 pkt_dev
= __pktgen_NN_threads(pn
, ifname
, REMOVE
);
1898 if (pkt_dev
== NULL
)
1899 break; /* success */
1901 mutex_unlock(&pktgen_thread_lock
);
1902 pr_debug("%s: waiting for %s to disappear....\n",
1904 schedule_timeout_interruptible(msecs_to_jiffies(msec_per_try
));
1905 mutex_lock(&pktgen_thread_lock
);
1907 if (++i
>= max_tries
) {
1908 pr_err("%s: timed out after waiting %d msec for device %s to be removed\n",
1909 __func__
, msec_per_try
* i
, ifname
);
1915 mutex_unlock(&pktgen_thread_lock
);
1918 static void pktgen_change_name(const struct pktgen_net
*pn
, struct net_device
*dev
)
1920 struct pktgen_thread
*t
;
1922 mutex_lock(&pktgen_thread_lock
);
1924 list_for_each_entry(t
, &pn
->pktgen_threads
, th_list
) {
1925 struct pktgen_dev
*pkt_dev
;
1928 list_for_each_entry(pkt_dev
, &t
->if_list
, list
) {
1929 if (pkt_dev
->odev
!= dev
)
1932 proc_remove(pkt_dev
->entry
);
1934 pkt_dev
->entry
= proc_create_data(dev
->name
, 0600,
1938 if (!pkt_dev
->entry
)
1939 pr_err("can't move proc entry for '%s'\n",
1945 mutex_unlock(&pktgen_thread_lock
);
1948 static int pktgen_device_event(struct notifier_block
*unused
,
1949 unsigned long event
, void *ptr
)
1951 struct net_device
*dev
= netdev_notifier_info_to_dev(ptr
);
1952 struct pktgen_net
*pn
= net_generic(dev_net(dev
), pg_net_id
);
1954 if (pn
->pktgen_exiting
)
1957 /* It is OK that we do not hold the group lock right now,
1958 * as we run under the RTNL lock.
1962 case NETDEV_CHANGENAME
:
1963 pktgen_change_name(pn
, dev
);
1966 case NETDEV_UNREGISTER
:
1967 pktgen_mark_device(pn
, dev
->name
);
1974 static struct net_device
*pktgen_dev_get_by_name(const struct pktgen_net
*pn
,
1975 struct pktgen_dev
*pkt_dev
,
1981 for (i
= 0; ifname
[i
] != '@'; i
++) {
1989 return dev_get_by_name(pn
->net
, b
);
1993 /* Associate pktgen_dev with a device. */
1995 static int pktgen_setup_dev(const struct pktgen_net
*pn
,
1996 struct pktgen_dev
*pkt_dev
, const char *ifname
)
1998 struct net_device
*odev
;
2001 /* Clean old setups */
2002 if (pkt_dev
->odev
) {
2003 dev_put(pkt_dev
->odev
);
2004 pkt_dev
->odev
= NULL
;
2007 odev
= pktgen_dev_get_by_name(pn
, pkt_dev
, ifname
);
2009 pr_err("no such netdevice: \"%s\"\n", ifname
);
2013 if (odev
->type
!= ARPHRD_ETHER
) {
2014 pr_err("not an ethernet device: \"%s\"\n", ifname
);
2016 } else if (!netif_running(odev
)) {
2017 pr_err("device is down: \"%s\"\n", ifname
);
2020 pkt_dev
->odev
= odev
;
2028 /* Read pkt_dev from the interface and set up internal pktgen_dev
2029 * structure to have the right information to create/send packets
2031 static void pktgen_setup_inject(struct pktgen_dev
*pkt_dev
)
2035 if (!pkt_dev
->odev
) {
2036 pr_err("ERROR: pkt_dev->odev == NULL in setup_inject\n");
2037 sprintf(pkt_dev
->result
,
2038 "ERROR: pkt_dev->odev == NULL in setup_inject.\n");
2042 /* make sure that we don't pick a non-existing transmit queue */
2043 ntxq
= pkt_dev
->odev
->real_num_tx_queues
;
2045 if (ntxq
<= pkt_dev
->queue_map_min
) {
2046 pr_warn("WARNING: Requested queue_map_min (zero-based) (%d) exceeds valid range [0 - %d] for (%d) queues on %s, resetting\n",
2047 pkt_dev
->queue_map_min
, (ntxq
?: 1) - 1, ntxq
,
2049 pkt_dev
->queue_map_min
= (ntxq
?: 1) - 1;
2051 if (pkt_dev
->queue_map_max
>= ntxq
) {
2052 pr_warn("WARNING: Requested queue_map_max (zero-based) (%d) exceeds valid range [0 - %d] for (%d) queues on %s, resetting\n",
2053 pkt_dev
->queue_map_max
, (ntxq
?: 1) - 1, ntxq
,
2055 pkt_dev
->queue_map_max
= (ntxq
?: 1) - 1;
2058 /* Default to the interface's mac if not explicitly set. */
2060 if (is_zero_ether_addr(pkt_dev
->src_mac
))
2061 ether_addr_copy(&(pkt_dev
->hh
[6]), pkt_dev
->odev
->dev_addr
);
2063 /* Set up Dest MAC */
2064 ether_addr_copy(&(pkt_dev
->hh
[0]), pkt_dev
->dst_mac
);
2066 if (pkt_dev
->flags
& F_IPV6
) {
2067 int i
, set
= 0, err
= 1;
2068 struct inet6_dev
*idev
;
2070 if (pkt_dev
->min_pkt_size
== 0) {
2071 pkt_dev
->min_pkt_size
= 14 + sizeof(struct ipv6hdr
)
2072 + sizeof(struct udphdr
)
2073 + sizeof(struct pktgen_hdr
)
2074 + pkt_dev
->pkt_overhead
;
2077 for (i
= 0; i
< sizeof(struct in6_addr
); i
++)
2078 if (pkt_dev
->cur_in6_saddr
.s6_addr
[i
]) {
2086 * Use linklevel address if unconfigured.
2088 * use ipv6_get_lladdr if/when it's get exported
2092 idev
= __in6_dev_get(pkt_dev
->odev
);
2094 struct inet6_ifaddr
*ifp
;
2096 read_lock_bh(&idev
->lock
);
2097 list_for_each_entry(ifp
, &idev
->addr_list
, if_list
) {
2098 if ((ifp
->scope
& IFA_LINK
) &&
2099 !(ifp
->flags
& IFA_F_TENTATIVE
)) {
2100 pkt_dev
->cur_in6_saddr
= ifp
->addr
;
2105 read_unlock_bh(&idev
->lock
);
2109 pr_err("ERROR: IPv6 link address not available\n");
2112 if (pkt_dev
->min_pkt_size
== 0) {
2113 pkt_dev
->min_pkt_size
= 14 + sizeof(struct iphdr
)
2114 + sizeof(struct udphdr
)
2115 + sizeof(struct pktgen_hdr
)
2116 + pkt_dev
->pkt_overhead
;
2119 pkt_dev
->saddr_min
= 0;
2120 pkt_dev
->saddr_max
= 0;
2121 if (strlen(pkt_dev
->src_min
) == 0) {
2123 struct in_device
*in_dev
;
2126 in_dev
= __in_dev_get_rcu(pkt_dev
->odev
);
2128 if (in_dev
->ifa_list
) {
2129 pkt_dev
->saddr_min
=
2130 in_dev
->ifa_list
->ifa_address
;
2131 pkt_dev
->saddr_max
= pkt_dev
->saddr_min
;
2136 pkt_dev
->saddr_min
= in_aton(pkt_dev
->src_min
);
2137 pkt_dev
->saddr_max
= in_aton(pkt_dev
->src_max
);
2140 pkt_dev
->daddr_min
= in_aton(pkt_dev
->dst_min
);
2141 pkt_dev
->daddr_max
= in_aton(pkt_dev
->dst_max
);
2143 /* Initialize current values. */
2144 pkt_dev
->cur_pkt_size
= pkt_dev
->min_pkt_size
;
2145 if (pkt_dev
->min_pkt_size
> pkt_dev
->max_pkt_size
)
2146 pkt_dev
->max_pkt_size
= pkt_dev
->min_pkt_size
;
2148 pkt_dev
->cur_dst_mac_offset
= 0;
2149 pkt_dev
->cur_src_mac_offset
= 0;
2150 pkt_dev
->cur_saddr
= pkt_dev
->saddr_min
;
2151 pkt_dev
->cur_daddr
= pkt_dev
->daddr_min
;
2152 pkt_dev
->cur_udp_dst
= pkt_dev
->udp_dst_min
;
2153 pkt_dev
->cur_udp_src
= pkt_dev
->udp_src_min
;
2154 pkt_dev
->nflows
= 0;
2158 static void spin(struct pktgen_dev
*pkt_dev
, ktime_t spin_until
)
2160 ktime_t start_time
, end_time
;
2162 struct hrtimer_sleeper t
;
2164 hrtimer_init_on_stack(&t
.timer
, CLOCK_MONOTONIC
, HRTIMER_MODE_ABS
);
2165 hrtimer_set_expires(&t
.timer
, spin_until
);
2167 remaining
= ktime_to_ns(hrtimer_expires_remaining(&t
.timer
));
2171 start_time
= ktime_get();
2172 if (remaining
< 100000) {
2173 /* for small delays (<100us), just loop until limit is reached */
2175 end_time
= ktime_get();
2176 } while (ktime_compare(end_time
, spin_until
) < 0);
2178 /* see do_nanosleep */
2179 hrtimer_init_sleeper(&t
, current
);
2181 set_current_state(TASK_INTERRUPTIBLE
);
2182 hrtimer_start_expires(&t
.timer
, HRTIMER_MODE_ABS
);
2187 hrtimer_cancel(&t
.timer
);
2188 } while (t
.task
&& pkt_dev
->running
&& !signal_pending(current
));
2189 __set_current_state(TASK_RUNNING
);
2190 end_time
= ktime_get();
2193 pkt_dev
->idle_acc
+= ktime_to_ns(ktime_sub(end_time
, start_time
));
2195 pkt_dev
->next_tx
= ktime_add_ns(spin_until
, pkt_dev
->delay
);
2196 destroy_hrtimer_on_stack(&t
.timer
);
2199 static inline void set_pkt_overhead(struct pktgen_dev
*pkt_dev
)
2201 pkt_dev
->pkt_overhead
= 0;
2202 pkt_dev
->pkt_overhead
+= pkt_dev
->nr_labels
*sizeof(u32
);
2203 pkt_dev
->pkt_overhead
+= VLAN_TAG_SIZE(pkt_dev
);
2204 pkt_dev
->pkt_overhead
+= SVLAN_TAG_SIZE(pkt_dev
);
2207 static inline int f_seen(const struct pktgen_dev
*pkt_dev
, int flow
)
2209 return !!(pkt_dev
->flows
[flow
].flags
& F_INIT
);
2212 static inline int f_pick(struct pktgen_dev
*pkt_dev
)
2214 int flow
= pkt_dev
->curfl
;
2216 if (pkt_dev
->flags
& F_FLOW_SEQ
) {
2217 if (pkt_dev
->flows
[flow
].count
>= pkt_dev
->lflow
) {
2219 pkt_dev
->flows
[flow
].count
= 0;
2220 pkt_dev
->flows
[flow
].flags
= 0;
2221 pkt_dev
->curfl
+= 1;
2222 if (pkt_dev
->curfl
>= pkt_dev
->cflows
)
2223 pkt_dev
->curfl
= 0; /*reset */
2226 flow
= prandom_u32() % pkt_dev
->cflows
;
2227 pkt_dev
->curfl
= flow
;
2229 if (pkt_dev
->flows
[flow
].count
> pkt_dev
->lflow
) {
2230 pkt_dev
->flows
[flow
].count
= 0;
2231 pkt_dev
->flows
[flow
].flags
= 0;
2235 return pkt_dev
->curfl
;
2240 /* If there was already an IPSEC SA, we keep it as is, else
2241 * we go look for it ...
2243 #define DUMMY_MARK 0
2244 static void get_ipsec_sa(struct pktgen_dev
*pkt_dev
, int flow
)
2246 struct xfrm_state
*x
= pkt_dev
->flows
[flow
].x
;
2247 struct pktgen_net
*pn
= net_generic(dev_net(pkt_dev
->odev
), pg_net_id
);
2251 /* We need as quick as possible to find the right SA
2252 * Searching with minimum criteria to archieve this.
2254 x
= xfrm_state_lookup_byspi(pn
->net
, htonl(pkt_dev
->spi
), AF_INET
);
2256 /* slow path: we dont already have xfrm_state */
2257 x
= xfrm_stateonly_find(pn
->net
, DUMMY_MARK
, 0,
2258 (xfrm_address_t
*)&pkt_dev
->cur_daddr
,
2259 (xfrm_address_t
*)&pkt_dev
->cur_saddr
,
2262 pkt_dev
->ipsproto
, 0);
2265 pkt_dev
->flows
[flow
].x
= x
;
2266 set_pkt_overhead(pkt_dev
);
2267 pkt_dev
->pkt_overhead
+= x
->props
.header_len
;
2273 static void set_cur_queue_map(struct pktgen_dev
*pkt_dev
)
2276 if (pkt_dev
->flags
& F_QUEUE_MAP_CPU
)
2277 pkt_dev
->cur_queue_map
= smp_processor_id();
2279 else if (pkt_dev
->queue_map_min
<= pkt_dev
->queue_map_max
) {
2281 if (pkt_dev
->flags
& F_QUEUE_MAP_RND
) {
2283 (pkt_dev
->queue_map_max
-
2284 pkt_dev
->queue_map_min
+ 1)
2285 + pkt_dev
->queue_map_min
;
2287 t
= pkt_dev
->cur_queue_map
+ 1;
2288 if (t
> pkt_dev
->queue_map_max
)
2289 t
= pkt_dev
->queue_map_min
;
2291 pkt_dev
->cur_queue_map
= t
;
2293 pkt_dev
->cur_queue_map
= pkt_dev
->cur_queue_map
% pkt_dev
->odev
->real_num_tx_queues
;
2296 /* Increment/randomize headers according to flags and current values
2297 * for IP src/dest, UDP src/dst port, MAC-Addr src/dst
2299 static void mod_cur_headers(struct pktgen_dev
*pkt_dev
)
2305 if (pkt_dev
->cflows
)
2306 flow
= f_pick(pkt_dev
);
2308 /* Deal with source MAC */
2309 if (pkt_dev
->src_mac_count
> 1) {
2313 if (pkt_dev
->flags
& F_MACSRC_RND
)
2314 mc
= prandom_u32() % pkt_dev
->src_mac_count
;
2316 mc
= pkt_dev
->cur_src_mac_offset
++;
2317 if (pkt_dev
->cur_src_mac_offset
>=
2318 pkt_dev
->src_mac_count
)
2319 pkt_dev
->cur_src_mac_offset
= 0;
2322 tmp
= pkt_dev
->src_mac
[5] + (mc
& 0xFF);
2323 pkt_dev
->hh
[11] = tmp
;
2324 tmp
= (pkt_dev
->src_mac
[4] + ((mc
>> 8) & 0xFF) + (tmp
>> 8));
2325 pkt_dev
->hh
[10] = tmp
;
2326 tmp
= (pkt_dev
->src_mac
[3] + ((mc
>> 16) & 0xFF) + (tmp
>> 8));
2327 pkt_dev
->hh
[9] = tmp
;
2328 tmp
= (pkt_dev
->src_mac
[2] + ((mc
>> 24) & 0xFF) + (tmp
>> 8));
2329 pkt_dev
->hh
[8] = tmp
;
2330 tmp
= (pkt_dev
->src_mac
[1] + (tmp
>> 8));
2331 pkt_dev
->hh
[7] = tmp
;
2334 /* Deal with Destination MAC */
2335 if (pkt_dev
->dst_mac_count
> 1) {
2339 if (pkt_dev
->flags
& F_MACDST_RND
)
2340 mc
= prandom_u32() % pkt_dev
->dst_mac_count
;
2343 mc
= pkt_dev
->cur_dst_mac_offset
++;
2344 if (pkt_dev
->cur_dst_mac_offset
>=
2345 pkt_dev
->dst_mac_count
) {
2346 pkt_dev
->cur_dst_mac_offset
= 0;
2350 tmp
= pkt_dev
->dst_mac
[5] + (mc
& 0xFF);
2351 pkt_dev
->hh
[5] = tmp
;
2352 tmp
= (pkt_dev
->dst_mac
[4] + ((mc
>> 8) & 0xFF) + (tmp
>> 8));
2353 pkt_dev
->hh
[4] = tmp
;
2354 tmp
= (pkt_dev
->dst_mac
[3] + ((mc
>> 16) & 0xFF) + (tmp
>> 8));
2355 pkt_dev
->hh
[3] = tmp
;
2356 tmp
= (pkt_dev
->dst_mac
[2] + ((mc
>> 24) & 0xFF) + (tmp
>> 8));
2357 pkt_dev
->hh
[2] = tmp
;
2358 tmp
= (pkt_dev
->dst_mac
[1] + (tmp
>> 8));
2359 pkt_dev
->hh
[1] = tmp
;
2362 if (pkt_dev
->flags
& F_MPLS_RND
) {
2364 for (i
= 0; i
< pkt_dev
->nr_labels
; i
++)
2365 if (pkt_dev
->labels
[i
] & MPLS_STACK_BOTTOM
)
2366 pkt_dev
->labels
[i
] = MPLS_STACK_BOTTOM
|
2367 ((__force __be32
)prandom_u32() &
2371 if ((pkt_dev
->flags
& F_VID_RND
) && (pkt_dev
->vlan_id
!= 0xffff)) {
2372 pkt_dev
->vlan_id
= prandom_u32() & (4096 - 1);
2375 if ((pkt_dev
->flags
& F_SVID_RND
) && (pkt_dev
->svlan_id
!= 0xffff)) {
2376 pkt_dev
->svlan_id
= prandom_u32() & (4096 - 1);
2379 if (pkt_dev
->udp_src_min
< pkt_dev
->udp_src_max
) {
2380 if (pkt_dev
->flags
& F_UDPSRC_RND
)
2381 pkt_dev
->cur_udp_src
= prandom_u32() %
2382 (pkt_dev
->udp_src_max
- pkt_dev
->udp_src_min
)
2383 + pkt_dev
->udp_src_min
;
2386 pkt_dev
->cur_udp_src
++;
2387 if (pkt_dev
->cur_udp_src
>= pkt_dev
->udp_src_max
)
2388 pkt_dev
->cur_udp_src
= pkt_dev
->udp_src_min
;
2392 if (pkt_dev
->udp_dst_min
< pkt_dev
->udp_dst_max
) {
2393 if (pkt_dev
->flags
& F_UDPDST_RND
) {
2394 pkt_dev
->cur_udp_dst
= prandom_u32() %
2395 (pkt_dev
->udp_dst_max
- pkt_dev
->udp_dst_min
)
2396 + pkt_dev
->udp_dst_min
;
2398 pkt_dev
->cur_udp_dst
++;
2399 if (pkt_dev
->cur_udp_dst
>= pkt_dev
->udp_dst_max
)
2400 pkt_dev
->cur_udp_dst
= pkt_dev
->udp_dst_min
;
2404 if (!(pkt_dev
->flags
& F_IPV6
)) {
2406 imn
= ntohl(pkt_dev
->saddr_min
);
2407 imx
= ntohl(pkt_dev
->saddr_max
);
2410 if (pkt_dev
->flags
& F_IPSRC_RND
)
2411 t
= prandom_u32() % (imx
- imn
) + imn
;
2413 t
= ntohl(pkt_dev
->cur_saddr
);
2419 pkt_dev
->cur_saddr
= htonl(t
);
2422 if (pkt_dev
->cflows
&& f_seen(pkt_dev
, flow
)) {
2423 pkt_dev
->cur_daddr
= pkt_dev
->flows
[flow
].cur_daddr
;
2425 imn
= ntohl(pkt_dev
->daddr_min
);
2426 imx
= ntohl(pkt_dev
->daddr_max
);
2430 if (pkt_dev
->flags
& F_IPDST_RND
) {
2436 } while (ipv4_is_loopback(s
) ||
2437 ipv4_is_multicast(s
) ||
2438 ipv4_is_lbcast(s
) ||
2439 ipv4_is_zeronet(s
) ||
2440 ipv4_is_local_multicast(s
));
2441 pkt_dev
->cur_daddr
= s
;
2443 t
= ntohl(pkt_dev
->cur_daddr
);
2448 pkt_dev
->cur_daddr
= htonl(t
);
2451 if (pkt_dev
->cflows
) {
2452 pkt_dev
->flows
[flow
].flags
|= F_INIT
;
2453 pkt_dev
->flows
[flow
].cur_daddr
=
2456 if (pkt_dev
->flags
& F_IPSEC
)
2457 get_ipsec_sa(pkt_dev
, flow
);
2462 } else { /* IPV6 * */
2464 if (!ipv6_addr_any(&pkt_dev
->min_in6_daddr
)) {
2467 /* Only random destinations yet */
2469 for (i
= 0; i
< 4; i
++) {
2470 pkt_dev
->cur_in6_daddr
.s6_addr32
[i
] =
2471 (((__force __be32
)prandom_u32() |
2472 pkt_dev
->min_in6_daddr
.s6_addr32
[i
]) &
2473 pkt_dev
->max_in6_daddr
.s6_addr32
[i
]);
2478 if (pkt_dev
->min_pkt_size
< pkt_dev
->max_pkt_size
) {
2480 if (pkt_dev
->flags
& F_TXSIZE_RND
) {
2482 (pkt_dev
->max_pkt_size
- pkt_dev
->min_pkt_size
)
2483 + pkt_dev
->min_pkt_size
;
2485 t
= pkt_dev
->cur_pkt_size
+ 1;
2486 if (t
> pkt_dev
->max_pkt_size
)
2487 t
= pkt_dev
->min_pkt_size
;
2489 pkt_dev
->cur_pkt_size
= t
;
2492 set_cur_queue_map(pkt_dev
);
2494 pkt_dev
->flows
[flow
].count
++;
2499 static u32 pktgen_dst_metrics
[RTAX_MAX
+ 1] = {
2501 [RTAX_HOPLIMIT
] = 0x5, /* Set a static hoplimit */
2504 static int pktgen_output_ipsec(struct sk_buff
*skb
, struct pktgen_dev
*pkt_dev
)
2506 struct xfrm_state
*x
= pkt_dev
->flows
[pkt_dev
->curfl
].x
;
2508 struct net
*net
= dev_net(pkt_dev
->odev
);
2512 /* XXX: we dont support tunnel mode for now until
2513 * we resolve the dst issue */
2514 if ((x
->props
.mode
!= XFRM_MODE_TRANSPORT
) && (pkt_dev
->spi
== 0))
2517 /* But when user specify an valid SPI, transformation
2518 * supports both transport/tunnel mode + ESP/AH type.
2520 if ((x
->props
.mode
== XFRM_MODE_TUNNEL
) && (pkt_dev
->spi
!= 0))
2521 skb
->_skb_refdst
= (unsigned long)&pkt_dev
->xdst
.u
.dst
| SKB_DST_NOREF
;
2524 err
= x
->outer_mode
->output(x
, skb
);
2525 rcu_read_unlock_bh();
2527 XFRM_INC_STATS(net
, LINUX_MIB_XFRMOUTSTATEMODEERROR
);
2530 err
= x
->type
->output(x
, skb
);
2532 XFRM_INC_STATS(net
, LINUX_MIB_XFRMOUTSTATEPROTOERROR
);
2535 spin_lock_bh(&x
->lock
);
2536 x
->curlft
.bytes
+= skb
->len
;
2537 x
->curlft
.packets
++;
2538 spin_unlock_bh(&x
->lock
);
2543 static void free_SAs(struct pktgen_dev
*pkt_dev
)
2545 if (pkt_dev
->cflows
) {
2546 /* let go of the SAs if we have them */
2548 for (i
= 0; i
< pkt_dev
->cflows
; i
++) {
2549 struct xfrm_state
*x
= pkt_dev
->flows
[i
].x
;
2552 pkt_dev
->flows
[i
].x
= NULL
;
2558 static int process_ipsec(struct pktgen_dev
*pkt_dev
,
2559 struct sk_buff
*skb
, __be16 protocol
)
2561 if (pkt_dev
->flags
& F_IPSEC
) {
2562 struct xfrm_state
*x
= pkt_dev
->flows
[pkt_dev
->curfl
].x
;
2569 nhead
= x
->props
.header_len
- skb_headroom(skb
);
2571 ret
= pskb_expand_head(skb
, nhead
, 0, GFP_ATOMIC
);
2573 pr_err("Error expanding ipsec packet %d\n",
2579 /* ipsec is not expecting ll header */
2580 skb_pull(skb
, ETH_HLEN
);
2581 ret
= pktgen_output_ipsec(skb
, pkt_dev
);
2583 pr_err("Error creating ipsec packet %d\n", ret
);
2587 eth
= skb_push(skb
, ETH_HLEN
);
2588 memcpy(eth
, pkt_dev
->hh
, 2 * ETH_ALEN
);
2589 eth
->h_proto
= protocol
;
2591 /* Update IPv4 header len as well as checksum value */
2593 iph
->tot_len
= htons(skb
->len
- ETH_HLEN
);
2604 static void mpls_push(__be32
*mpls
, struct pktgen_dev
*pkt_dev
)
2607 for (i
= 0; i
< pkt_dev
->nr_labels
; i
++)
2608 *mpls
++ = pkt_dev
->labels
[i
] & ~MPLS_STACK_BOTTOM
;
2611 *mpls
|= MPLS_STACK_BOTTOM
;
2614 static inline __be16
build_tci(unsigned int id
, unsigned int cfi
,
2617 return htons(id
| (cfi
<< 12) | (prio
<< 13));
2620 static void pktgen_finalize_skb(struct pktgen_dev
*pkt_dev
, struct sk_buff
*skb
,
2623 struct timespec64 timestamp
;
2624 struct pktgen_hdr
*pgh
;
2626 pgh
= skb_put(skb
, sizeof(*pgh
));
2627 datalen
-= sizeof(*pgh
);
2629 if (pkt_dev
->nfrags
<= 0) {
2630 skb_put_zero(skb
, datalen
);
2632 int frags
= pkt_dev
->nfrags
;
2637 if (frags
> MAX_SKB_FRAGS
)
2638 frags
= MAX_SKB_FRAGS
;
2639 len
= datalen
- frags
* PAGE_SIZE
;
2641 skb_put_zero(skb
, len
);
2642 datalen
= frags
* PAGE_SIZE
;
2646 frag_len
= (datalen
/frags
) < PAGE_SIZE
?
2647 (datalen
/frags
) : PAGE_SIZE
;
2648 while (datalen
> 0) {
2649 if (unlikely(!pkt_dev
->page
)) {
2650 int node
= numa_node_id();
2652 if (pkt_dev
->node
>= 0 && (pkt_dev
->flags
& F_NODE
))
2653 node
= pkt_dev
->node
;
2654 pkt_dev
->page
= alloc_pages_node(node
, GFP_KERNEL
| __GFP_ZERO
, 0);
2658 get_page(pkt_dev
->page
);
2659 skb_frag_set_page(skb
, i
, pkt_dev
->page
);
2660 skb_shinfo(skb
)->frags
[i
].page_offset
= 0;
2661 /*last fragment, fill rest of data*/
2662 if (i
== (frags
- 1))
2663 skb_frag_size_set(&skb_shinfo(skb
)->frags
[i
],
2664 (datalen
< PAGE_SIZE
? datalen
: PAGE_SIZE
));
2666 skb_frag_size_set(&skb_shinfo(skb
)->frags
[i
], frag_len
);
2667 datalen
-= skb_frag_size(&skb_shinfo(skb
)->frags
[i
]);
2668 skb
->len
+= skb_frag_size(&skb_shinfo(skb
)->frags
[i
]);
2669 skb
->data_len
+= skb_frag_size(&skb_shinfo(skb
)->frags
[i
]);
2671 skb_shinfo(skb
)->nr_frags
= i
;
2675 /* Stamp the time, and sequence number,
2676 * convert them to network byte order
2678 pgh
->pgh_magic
= htonl(PKTGEN_MAGIC
);
2679 pgh
->seq_num
= htonl(pkt_dev
->seq_num
);
2681 if (pkt_dev
->flags
& F_NO_TIMESTAMP
) {
2686 * pgh->tv_sec wraps in y2106 when interpreted as unsigned
2687 * as done by wireshark, or y2038 when interpreted as signed.
2688 * This is probably harmless, but if anyone wants to improve
2689 * it, we could introduce a variant that puts 64-bit nanoseconds
2690 * into the respective header bytes.
2691 * This would also be slightly faster to read.
2693 ktime_get_real_ts64(×tamp
);
2694 pgh
->tv_sec
= htonl(timestamp
.tv_sec
);
2695 pgh
->tv_usec
= htonl(timestamp
.tv_nsec
/ NSEC_PER_USEC
);
2699 static struct sk_buff
*pktgen_alloc_skb(struct net_device
*dev
,
2700 struct pktgen_dev
*pkt_dev
)
2702 unsigned int extralen
= LL_RESERVED_SPACE(dev
);
2703 struct sk_buff
*skb
= NULL
;
2706 size
= pkt_dev
->cur_pkt_size
+ 64 + extralen
+ pkt_dev
->pkt_overhead
;
2707 if (pkt_dev
->flags
& F_NODE
) {
2708 int node
= pkt_dev
->node
>= 0 ? pkt_dev
->node
: numa_node_id();
2710 skb
= __alloc_skb(NET_SKB_PAD
+ size
, GFP_NOWAIT
, 0, node
);
2712 skb_reserve(skb
, NET_SKB_PAD
);
2716 skb
= __netdev_alloc_skb(dev
, size
, GFP_NOWAIT
);
2719 /* the caller pre-fetches from skb->data and reserves for the mac hdr */
2721 skb_reserve(skb
, extralen
- 16);
2726 static struct sk_buff
*fill_packet_ipv4(struct net_device
*odev
,
2727 struct pktgen_dev
*pkt_dev
)
2729 struct sk_buff
*skb
= NULL
;
2731 struct udphdr
*udph
;
2734 __be16 protocol
= htons(ETH_P_IP
);
2736 __be16
*vlan_tci
= NULL
; /* Encapsulates priority and VLAN ID */
2737 __be16
*vlan_encapsulated_proto
= NULL
; /* packet type ID field (or len) for VLAN tag */
2738 __be16
*svlan_tci
= NULL
; /* Encapsulates priority and SVLAN ID */
2739 __be16
*svlan_encapsulated_proto
= NULL
; /* packet type ID field (or len) for SVLAN tag */
2742 if (pkt_dev
->nr_labels
)
2743 protocol
= htons(ETH_P_MPLS_UC
);
2745 if (pkt_dev
->vlan_id
!= 0xffff)
2746 protocol
= htons(ETH_P_8021Q
);
2748 /* Update any of the values, used when we're incrementing various
2751 mod_cur_headers(pkt_dev
);
2752 queue_map
= pkt_dev
->cur_queue_map
;
2754 skb
= pktgen_alloc_skb(odev
, pkt_dev
);
2756 sprintf(pkt_dev
->result
, "No memory");
2760 prefetchw(skb
->data
);
2761 skb_reserve(skb
, 16);
2763 /* Reserve for ethernet and IP header */
2764 eth
= skb_push(skb
, 14);
2765 mpls
= skb_put(skb
, pkt_dev
->nr_labels
* sizeof(__u32
));
2766 if (pkt_dev
->nr_labels
)
2767 mpls_push(mpls
, pkt_dev
);
2769 if (pkt_dev
->vlan_id
!= 0xffff) {
2770 if (pkt_dev
->svlan_id
!= 0xffff) {
2771 svlan_tci
= skb_put(skb
, sizeof(__be16
));
2772 *svlan_tci
= build_tci(pkt_dev
->svlan_id
,
2775 svlan_encapsulated_proto
= skb_put(skb
,
2777 *svlan_encapsulated_proto
= htons(ETH_P_8021Q
);
2779 vlan_tci
= skb_put(skb
, sizeof(__be16
));
2780 *vlan_tci
= build_tci(pkt_dev
->vlan_id
,
2783 vlan_encapsulated_proto
= skb_put(skb
, sizeof(__be16
));
2784 *vlan_encapsulated_proto
= htons(ETH_P_IP
);
2787 skb_reset_mac_header(skb
);
2788 skb_set_network_header(skb
, skb
->len
);
2789 iph
= skb_put(skb
, sizeof(struct iphdr
));
2791 skb_set_transport_header(skb
, skb
->len
);
2792 udph
= skb_put(skb
, sizeof(struct udphdr
));
2793 skb_set_queue_mapping(skb
, queue_map
);
2794 skb
->priority
= pkt_dev
->skb_priority
;
2796 memcpy(eth
, pkt_dev
->hh
, 12);
2797 *(__be16
*) & eth
[12] = protocol
;
2799 /* Eth + IPh + UDPh + mpls */
2800 datalen
= pkt_dev
->cur_pkt_size
- 14 - 20 - 8 -
2801 pkt_dev
->pkt_overhead
;
2802 if (datalen
< 0 || datalen
< sizeof(struct pktgen_hdr
))
2803 datalen
= sizeof(struct pktgen_hdr
);
2805 udph
->source
= htons(pkt_dev
->cur_udp_src
);
2806 udph
->dest
= htons(pkt_dev
->cur_udp_dst
);
2807 udph
->len
= htons(datalen
+ 8); /* DATA + udphdr */
2813 iph
->tos
= pkt_dev
->tos
;
2814 iph
->protocol
= IPPROTO_UDP
; /* UDP */
2815 iph
->saddr
= pkt_dev
->cur_saddr
;
2816 iph
->daddr
= pkt_dev
->cur_daddr
;
2817 iph
->id
= htons(pkt_dev
->ip_id
);
2820 iplen
= 20 + 8 + datalen
;
2821 iph
->tot_len
= htons(iplen
);
2823 skb
->protocol
= protocol
;
2825 skb
->pkt_type
= PACKET_HOST
;
2827 pktgen_finalize_skb(pkt_dev
, skb
, datalen
);
2829 if (!(pkt_dev
->flags
& F_UDPCSUM
)) {
2830 skb
->ip_summed
= CHECKSUM_NONE
;
2831 } else if (odev
->features
& (NETIF_F_HW_CSUM
| NETIF_F_IP_CSUM
)) {
2832 skb
->ip_summed
= CHECKSUM_PARTIAL
;
2834 udp4_hwcsum(skb
, iph
->saddr
, iph
->daddr
);
2836 __wsum csum
= skb_checksum(skb
, skb_transport_offset(skb
), datalen
+ 8, 0);
2838 /* add protocol-dependent pseudo-header */
2839 udph
->check
= csum_tcpudp_magic(iph
->saddr
, iph
->daddr
,
2840 datalen
+ 8, IPPROTO_UDP
, csum
);
2842 if (udph
->check
== 0)
2843 udph
->check
= CSUM_MANGLED_0
;
2847 if (!process_ipsec(pkt_dev
, skb
, protocol
))
2854 static struct sk_buff
*fill_packet_ipv6(struct net_device
*odev
,
2855 struct pktgen_dev
*pkt_dev
)
2857 struct sk_buff
*skb
= NULL
;
2859 struct udphdr
*udph
;
2860 int datalen
, udplen
;
2861 struct ipv6hdr
*iph
;
2862 __be16 protocol
= htons(ETH_P_IPV6
);
2864 __be16
*vlan_tci
= NULL
; /* Encapsulates priority and VLAN ID */
2865 __be16
*vlan_encapsulated_proto
= NULL
; /* packet type ID field (or len) for VLAN tag */
2866 __be16
*svlan_tci
= NULL
; /* Encapsulates priority and SVLAN ID */
2867 __be16
*svlan_encapsulated_proto
= NULL
; /* packet type ID field (or len) for SVLAN tag */
2870 if (pkt_dev
->nr_labels
)
2871 protocol
= htons(ETH_P_MPLS_UC
);
2873 if (pkt_dev
->vlan_id
!= 0xffff)
2874 protocol
= htons(ETH_P_8021Q
);
2876 /* Update any of the values, used when we're incrementing various
2879 mod_cur_headers(pkt_dev
);
2880 queue_map
= pkt_dev
->cur_queue_map
;
2882 skb
= pktgen_alloc_skb(odev
, pkt_dev
);
2884 sprintf(pkt_dev
->result
, "No memory");
2888 prefetchw(skb
->data
);
2889 skb_reserve(skb
, 16);
2891 /* Reserve for ethernet and IP header */
2892 eth
= skb_push(skb
, 14);
2893 mpls
= skb_put(skb
, pkt_dev
->nr_labels
* sizeof(__u32
));
2894 if (pkt_dev
->nr_labels
)
2895 mpls_push(mpls
, pkt_dev
);
2897 if (pkt_dev
->vlan_id
!= 0xffff) {
2898 if (pkt_dev
->svlan_id
!= 0xffff) {
2899 svlan_tci
= skb_put(skb
, sizeof(__be16
));
2900 *svlan_tci
= build_tci(pkt_dev
->svlan_id
,
2903 svlan_encapsulated_proto
= skb_put(skb
,
2905 *svlan_encapsulated_proto
= htons(ETH_P_8021Q
);
2907 vlan_tci
= skb_put(skb
, sizeof(__be16
));
2908 *vlan_tci
= build_tci(pkt_dev
->vlan_id
,
2911 vlan_encapsulated_proto
= skb_put(skb
, sizeof(__be16
));
2912 *vlan_encapsulated_proto
= htons(ETH_P_IPV6
);
2915 skb_reset_mac_header(skb
);
2916 skb_set_network_header(skb
, skb
->len
);
2917 iph
= skb_put(skb
, sizeof(struct ipv6hdr
));
2919 skb_set_transport_header(skb
, skb
->len
);
2920 udph
= skb_put(skb
, sizeof(struct udphdr
));
2921 skb_set_queue_mapping(skb
, queue_map
);
2922 skb
->priority
= pkt_dev
->skb_priority
;
2924 memcpy(eth
, pkt_dev
->hh
, 12);
2925 *(__be16
*) ð
[12] = protocol
;
2927 /* Eth + IPh + UDPh + mpls */
2928 datalen
= pkt_dev
->cur_pkt_size
- 14 -
2929 sizeof(struct ipv6hdr
) - sizeof(struct udphdr
) -
2930 pkt_dev
->pkt_overhead
;
2932 if (datalen
< 0 || datalen
< sizeof(struct pktgen_hdr
)) {
2933 datalen
= sizeof(struct pktgen_hdr
);
2934 net_info_ratelimited("increased datalen to %d\n", datalen
);
2937 udplen
= datalen
+ sizeof(struct udphdr
);
2938 udph
->source
= htons(pkt_dev
->cur_udp_src
);
2939 udph
->dest
= htons(pkt_dev
->cur_udp_dst
);
2940 udph
->len
= htons(udplen
);
2943 *(__be32
*) iph
= htonl(0x60000000); /* Version + flow */
2945 if (pkt_dev
->traffic_class
) {
2946 /* Version + traffic class + flow (0) */
2947 *(__be32
*)iph
|= htonl(0x60000000 | (pkt_dev
->traffic_class
<< 20));
2950 iph
->hop_limit
= 32;
2952 iph
->payload_len
= htons(udplen
);
2953 iph
->nexthdr
= IPPROTO_UDP
;
2955 iph
->daddr
= pkt_dev
->cur_in6_daddr
;
2956 iph
->saddr
= pkt_dev
->cur_in6_saddr
;
2958 skb
->protocol
= protocol
;
2960 skb
->pkt_type
= PACKET_HOST
;
2962 pktgen_finalize_skb(pkt_dev
, skb
, datalen
);
2964 if (!(pkt_dev
->flags
& F_UDPCSUM
)) {
2965 skb
->ip_summed
= CHECKSUM_NONE
;
2966 } else if (odev
->features
& (NETIF_F_HW_CSUM
| NETIF_F_IPV6_CSUM
)) {
2967 skb
->ip_summed
= CHECKSUM_PARTIAL
;
2968 skb
->csum_start
= skb_transport_header(skb
) - skb
->head
;
2969 skb
->csum_offset
= offsetof(struct udphdr
, check
);
2970 udph
->check
= ~csum_ipv6_magic(&iph
->saddr
, &iph
->daddr
, udplen
, IPPROTO_UDP
, 0);
2972 __wsum csum
= skb_checksum(skb
, skb_transport_offset(skb
), udplen
, 0);
2974 /* add protocol-dependent pseudo-header */
2975 udph
->check
= csum_ipv6_magic(&iph
->saddr
, &iph
->daddr
, udplen
, IPPROTO_UDP
, csum
);
2977 if (udph
->check
== 0)
2978 udph
->check
= CSUM_MANGLED_0
;
2984 static struct sk_buff
*fill_packet(struct net_device
*odev
,
2985 struct pktgen_dev
*pkt_dev
)
2987 if (pkt_dev
->flags
& F_IPV6
)
2988 return fill_packet_ipv6(odev
, pkt_dev
);
2990 return fill_packet_ipv4(odev
, pkt_dev
);
2993 static void pktgen_clear_counters(struct pktgen_dev
*pkt_dev
)
2995 pkt_dev
->seq_num
= 1;
2996 pkt_dev
->idle_acc
= 0;
2998 pkt_dev
->tx_bytes
= 0;
2999 pkt_dev
->errors
= 0;
3002 /* Set up structure for sending pkts, clear counters */
3004 static void pktgen_run(struct pktgen_thread
*t
)
3006 struct pktgen_dev
*pkt_dev
;
3012 list_for_each_entry_rcu(pkt_dev
, &t
->if_list
, list
) {
3015 * setup odev and create initial packet.
3017 pktgen_setup_inject(pkt_dev
);
3019 if (pkt_dev
->odev
) {
3020 pktgen_clear_counters(pkt_dev
);
3021 pkt_dev
->skb
= NULL
;
3022 pkt_dev
->started_at
= pkt_dev
->next_tx
= ktime_get();
3024 set_pkt_overhead(pkt_dev
);
3026 strcpy(pkt_dev
->result
, "Starting");
3027 pkt_dev
->running
= 1; /* Cranke yeself! */
3030 strcpy(pkt_dev
->result
, "Error starting");
3034 t
->control
&= ~(T_STOP
);
3037 static void pktgen_stop_all_threads_ifs(struct pktgen_net
*pn
)
3039 struct pktgen_thread
*t
;
3043 mutex_lock(&pktgen_thread_lock
);
3045 list_for_each_entry(t
, &pn
->pktgen_threads
, th_list
)
3046 t
->control
|= T_STOP
;
3048 mutex_unlock(&pktgen_thread_lock
);
3051 static int thread_is_running(const struct pktgen_thread
*t
)
3053 const struct pktgen_dev
*pkt_dev
;
3056 list_for_each_entry_rcu(pkt_dev
, &t
->if_list
, list
)
3057 if (pkt_dev
->running
) {
3065 static int pktgen_wait_thread_run(struct pktgen_thread
*t
)
3067 while (thread_is_running(t
)) {
3069 msleep_interruptible(100);
3071 if (signal_pending(current
))
3079 static int pktgen_wait_all_threads_run(struct pktgen_net
*pn
)
3081 struct pktgen_thread
*t
;
3084 mutex_lock(&pktgen_thread_lock
);
3086 list_for_each_entry(t
, &pn
->pktgen_threads
, th_list
) {
3087 sig
= pktgen_wait_thread_run(t
);
3093 list_for_each_entry(t
, &pn
->pktgen_threads
, th_list
)
3094 t
->control
|= (T_STOP
);
3096 mutex_unlock(&pktgen_thread_lock
);
3100 static void pktgen_run_all_threads(struct pktgen_net
*pn
)
3102 struct pktgen_thread
*t
;
3106 mutex_lock(&pktgen_thread_lock
);
3108 list_for_each_entry(t
, &pn
->pktgen_threads
, th_list
)
3109 t
->control
|= (T_RUN
);
3111 mutex_unlock(&pktgen_thread_lock
);
3113 /* Propagate thread->control */
3114 schedule_timeout_interruptible(msecs_to_jiffies(125));
3116 pktgen_wait_all_threads_run(pn
);
3119 static void pktgen_reset_all_threads(struct pktgen_net
*pn
)
3121 struct pktgen_thread
*t
;
3125 mutex_lock(&pktgen_thread_lock
);
3127 list_for_each_entry(t
, &pn
->pktgen_threads
, th_list
)
3128 t
->control
|= (T_REMDEVALL
);
3130 mutex_unlock(&pktgen_thread_lock
);
3132 /* Propagate thread->control */
3133 schedule_timeout_interruptible(msecs_to_jiffies(125));
3135 pktgen_wait_all_threads_run(pn
);
3138 static void show_results(struct pktgen_dev
*pkt_dev
, int nr_frags
)
3140 __u64 bps
, mbps
, pps
;
3141 char *p
= pkt_dev
->result
;
3142 ktime_t elapsed
= ktime_sub(pkt_dev
->stopped_at
,
3143 pkt_dev
->started_at
);
3144 ktime_t idle
= ns_to_ktime(pkt_dev
->idle_acc
);
3146 p
+= sprintf(p
, "OK: %llu(c%llu+d%llu) usec, %llu (%dbyte,%dfrags)\n",
3147 (unsigned long long)ktime_to_us(elapsed
),
3148 (unsigned long long)ktime_to_us(ktime_sub(elapsed
, idle
)),
3149 (unsigned long long)ktime_to_us(idle
),
3150 (unsigned long long)pkt_dev
->sofar
,
3151 pkt_dev
->cur_pkt_size
, nr_frags
);
3153 pps
= div64_u64(pkt_dev
->sofar
* NSEC_PER_SEC
,
3154 ktime_to_ns(elapsed
));
3156 bps
= pps
* 8 * pkt_dev
->cur_pkt_size
;
3159 do_div(mbps
, 1000000);
3160 p
+= sprintf(p
, " %llupps %lluMb/sec (%llubps) errors: %llu",
3161 (unsigned long long)pps
,
3162 (unsigned long long)mbps
,
3163 (unsigned long long)bps
,
3164 (unsigned long long)pkt_dev
->errors
);
3167 /* Set stopped-at timer, remove from running list, do counters & statistics */
3168 static int pktgen_stop_device(struct pktgen_dev
*pkt_dev
)
3170 int nr_frags
= pkt_dev
->skb
? skb_shinfo(pkt_dev
->skb
)->nr_frags
: -1;
3172 if (!pkt_dev
->running
) {
3173 pr_warn("interface: %s is already stopped\n",
3178 pkt_dev
->running
= 0;
3179 kfree_skb(pkt_dev
->skb
);
3180 pkt_dev
->skb
= NULL
;
3181 pkt_dev
->stopped_at
= ktime_get();
3183 show_results(pkt_dev
, nr_frags
);
3188 static struct pktgen_dev
*next_to_run(struct pktgen_thread
*t
)
3190 struct pktgen_dev
*pkt_dev
, *best
= NULL
;
3193 list_for_each_entry_rcu(pkt_dev
, &t
->if_list
, list
) {
3194 if (!pkt_dev
->running
)
3198 else if (ktime_compare(pkt_dev
->next_tx
, best
->next_tx
) < 0)
3206 static void pktgen_stop(struct pktgen_thread
*t
)
3208 struct pktgen_dev
*pkt_dev
;
3214 list_for_each_entry_rcu(pkt_dev
, &t
->if_list
, list
) {
3215 pktgen_stop_device(pkt_dev
);
3222 * one of our devices needs to be removed - find it
3225 static void pktgen_rem_one_if(struct pktgen_thread
*t
)
3227 struct list_head
*q
, *n
;
3228 struct pktgen_dev
*cur
;
3232 list_for_each_safe(q
, n
, &t
->if_list
) {
3233 cur
= list_entry(q
, struct pktgen_dev
, list
);
3235 if (!cur
->removal_mark
)
3238 kfree_skb(cur
->skb
);
3241 pktgen_remove_device(t
, cur
);
3247 static void pktgen_rem_all_ifs(struct pktgen_thread
*t
)
3249 struct list_head
*q
, *n
;
3250 struct pktgen_dev
*cur
;
3254 /* Remove all devices, free mem */
3256 list_for_each_safe(q
, n
, &t
->if_list
) {
3257 cur
= list_entry(q
, struct pktgen_dev
, list
);
3259 kfree_skb(cur
->skb
);
3262 pktgen_remove_device(t
, cur
);
3266 static void pktgen_rem_thread(struct pktgen_thread
*t
)
3268 /* Remove from the thread list */
3269 remove_proc_entry(t
->tsk
->comm
, t
->net
->proc_dir
);
3272 static void pktgen_resched(struct pktgen_dev
*pkt_dev
)
3274 ktime_t idle_start
= ktime_get();
3276 pkt_dev
->idle_acc
+= ktime_to_ns(ktime_sub(ktime_get(), idle_start
));
3279 static void pktgen_wait_for_skb(struct pktgen_dev
*pkt_dev
)
3281 ktime_t idle_start
= ktime_get();
3283 while (refcount_read(&(pkt_dev
->skb
->users
)) != 1) {
3284 if (signal_pending(current
))
3288 pktgen_resched(pkt_dev
);
3292 pkt_dev
->idle_acc
+= ktime_to_ns(ktime_sub(ktime_get(), idle_start
));
3295 static void pktgen_xmit(struct pktgen_dev
*pkt_dev
)
3297 unsigned int burst
= READ_ONCE(pkt_dev
->burst
);
3298 struct net_device
*odev
= pkt_dev
->odev
;
3299 struct netdev_queue
*txq
;
3300 struct sk_buff
*skb
;
3303 /* If device is offline, then don't send */
3304 if (unlikely(!netif_running(odev
) || !netif_carrier_ok(odev
))) {
3305 pktgen_stop_device(pkt_dev
);
3309 /* This is max DELAY, this has special meaning of
3312 if (unlikely(pkt_dev
->delay
== ULLONG_MAX
)) {
3313 pkt_dev
->next_tx
= ktime_add_ns(ktime_get(), ULONG_MAX
);
3317 /* If no skb or clone count exhausted then get new one */
3318 if (!pkt_dev
->skb
|| (pkt_dev
->last_ok
&&
3319 ++pkt_dev
->clone_count
>= pkt_dev
->clone_skb
)) {
3320 /* build a new pkt */
3321 kfree_skb(pkt_dev
->skb
);
3323 pkt_dev
->skb
= fill_packet(odev
, pkt_dev
);
3324 if (pkt_dev
->skb
== NULL
) {
3325 pr_err("ERROR: couldn't allocate skb in fill_packet\n");
3327 pkt_dev
->clone_count
--; /* back out increment, OOM */
3330 pkt_dev
->last_pkt_size
= pkt_dev
->skb
->len
;
3331 pkt_dev
->clone_count
= 0; /* reset counter */
3334 if (pkt_dev
->delay
&& pkt_dev
->last_ok
)
3335 spin(pkt_dev
, pkt_dev
->next_tx
);
3337 if (pkt_dev
->xmit_mode
== M_NETIF_RECEIVE
) {
3339 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
3340 refcount_add(burst
, &skb
->users
);
3343 ret
= netif_receive_skb(skb
);
3344 if (ret
== NET_RX_DROP
)
3348 if (refcount_read(&skb
->users
) != burst
) {
3349 /* skb was queued by rps/rfs or taps,
3350 * so cannot reuse this skb
3352 WARN_ON(refcount_sub_and_test(burst
- 1, &skb
->users
));
3353 /* get out of the loop and wait
3354 * until skb is consumed
3358 /* skb was 'freed' by stack, so clean few
3362 } while (--burst
> 0);
3363 goto out
; /* Skips xmit_mode M_START_XMIT */
3364 } else if (pkt_dev
->xmit_mode
== M_QUEUE_XMIT
) {
3366 refcount_inc(&pkt_dev
->skb
->users
);
3368 ret
= dev_queue_xmit(pkt_dev
->skb
);
3370 case NET_XMIT_SUCCESS
:
3373 pkt_dev
->tx_bytes
+= pkt_dev
->last_pkt_size
;
3377 /* These are all valid return codes for a qdisc but
3378 * indicate packets are being dropped or will likely
3381 case NETDEV_TX_BUSY
:
3382 /* qdisc may call dev_hard_start_xmit directly in cases
3383 * where no queues exist e.g. loopback device, virtual
3384 * devices, etc. In this case we need to handle
3389 net_info_ratelimited("%s xmit error: %d\n",
3390 pkt_dev
->odevname
, ret
);
3396 txq
= skb_get_tx_queue(odev
, pkt_dev
->skb
);
3400 HARD_TX_LOCK(odev
, txq
, smp_processor_id());
3402 if (unlikely(netif_xmit_frozen_or_drv_stopped(txq
))) {
3403 ret
= NETDEV_TX_BUSY
;
3404 pkt_dev
->last_ok
= 0;
3407 refcount_add(burst
, &pkt_dev
->skb
->users
);
3410 ret
= netdev_start_xmit(pkt_dev
->skb
, odev
, txq
, --burst
> 0);
3414 pkt_dev
->last_ok
= 1;
3417 pkt_dev
->tx_bytes
+= pkt_dev
->last_pkt_size
;
3418 if (burst
> 0 && !netif_xmit_frozen_or_drv_stopped(txq
))
3423 /* skb has been consumed */
3426 default: /* Drivers are not supposed to return other values! */
3427 net_info_ratelimited("%s xmit error: %d\n",
3428 pkt_dev
->odevname
, ret
);
3431 case NETDEV_TX_BUSY
:
3432 /* Retry it next time */
3433 refcount_dec(&(pkt_dev
->skb
->users
));
3434 pkt_dev
->last_ok
= 0;
3436 if (unlikely(burst
))
3437 WARN_ON(refcount_sub_and_test(burst
, &pkt_dev
->skb
->users
));
3439 HARD_TX_UNLOCK(odev
, txq
);
3444 /* If pkt_dev->count is zero, then run forever */
3445 if ((pkt_dev
->count
!= 0) && (pkt_dev
->sofar
>= pkt_dev
->count
)) {
3446 pktgen_wait_for_skb(pkt_dev
);
3448 /* Done with this */
3449 pktgen_stop_device(pkt_dev
);
3454 * Main loop of the thread goes here
3457 static int pktgen_thread_worker(void *arg
)
3460 struct pktgen_thread
*t
= arg
;
3461 struct pktgen_dev
*pkt_dev
= NULL
;
3464 BUG_ON(smp_processor_id() != cpu
);
3466 init_waitqueue_head(&t
->queue
);
3467 complete(&t
->start_done
);
3469 pr_debug("starting pktgen/%d: pid=%d\n", cpu
, task_pid_nr(current
));
3473 while (!kthread_should_stop()) {
3474 pkt_dev
= next_to_run(t
);
3476 if (unlikely(!pkt_dev
&& t
->control
== 0)) {
3477 if (t
->net
->pktgen_exiting
)
3479 wait_event_interruptible_timeout(t
->queue
,
3486 if (likely(pkt_dev
)) {
3487 pktgen_xmit(pkt_dev
);
3490 pktgen_resched(pkt_dev
);
3495 if (t
->control
& T_STOP
) {
3497 t
->control
&= ~(T_STOP
);
3500 if (t
->control
& T_RUN
) {
3502 t
->control
&= ~(T_RUN
);
3505 if (t
->control
& T_REMDEVALL
) {
3506 pktgen_rem_all_ifs(t
);
3507 t
->control
&= ~(T_REMDEVALL
);
3510 if (t
->control
& T_REMDEV
) {
3511 pktgen_rem_one_if(t
);
3512 t
->control
&= ~(T_REMDEV
);
3518 pr_debug("%s stopping all device\n", t
->tsk
->comm
);
3521 pr_debug("%s removing all device\n", t
->tsk
->comm
);
3522 pktgen_rem_all_ifs(t
);
3524 pr_debug("%s removing thread\n", t
->tsk
->comm
);
3525 pktgen_rem_thread(t
);
3530 static struct pktgen_dev
*pktgen_find_dev(struct pktgen_thread
*t
,
3531 const char *ifname
, bool exact
)
3533 struct pktgen_dev
*p
, *pkt_dev
= NULL
;
3534 size_t len
= strlen(ifname
);
3537 list_for_each_entry_rcu(p
, &t
->if_list
, list
)
3538 if (strncmp(p
->odevname
, ifname
, len
) == 0) {
3539 if (p
->odevname
[len
]) {
3540 if (exact
|| p
->odevname
[len
] != '@')
3548 pr_debug("find_dev(%s) returning %p\n", ifname
, pkt_dev
);
3553 * Adds a dev at front of if_list.
3556 static int add_dev_to_thread(struct pktgen_thread
*t
,
3557 struct pktgen_dev
*pkt_dev
)
3561 /* This function cannot be called concurrently, as its called
3562 * under pktgen_thread_lock mutex, but it can run from
3563 * userspace on another CPU than the kthread. The if_lock()
3564 * is used here to sync with concurrent instances of
3565 * _rem_dev_from_if_list() invoked via kthread, which is also
3566 * updating the if_list */
3569 if (pkt_dev
->pg_thread
) {
3570 pr_err("ERROR: already assigned to a thread\n");
3575 pkt_dev
->running
= 0;
3576 pkt_dev
->pg_thread
= t
;
3577 list_add_rcu(&pkt_dev
->list
, &t
->if_list
);
3584 /* Called under thread lock */
3586 static int pktgen_add_device(struct pktgen_thread
*t
, const char *ifname
)
3588 struct pktgen_dev
*pkt_dev
;
3590 int node
= cpu_to_node(t
->cpu
);
3592 /* We don't allow a device to be on several threads */
3594 pkt_dev
= __pktgen_NN_threads(t
->net
, ifname
, FIND
);
3596 pr_err("ERROR: interface already used\n");
3600 pkt_dev
= kzalloc_node(sizeof(struct pktgen_dev
), GFP_KERNEL
, node
);
3604 strcpy(pkt_dev
->odevname
, ifname
);
3605 pkt_dev
->flows
= vzalloc_node(array_size(MAX_CFLOWS
,
3606 sizeof(struct flow_state
)),
3608 if (pkt_dev
->flows
== NULL
) {
3613 pkt_dev
->removal_mark
= 0;
3614 pkt_dev
->nfrags
= 0;
3615 pkt_dev
->delay
= pg_delay_d
;
3616 pkt_dev
->count
= pg_count_d
;
3618 pkt_dev
->udp_src_min
= 9; /* sink port */
3619 pkt_dev
->udp_src_max
= 9;
3620 pkt_dev
->udp_dst_min
= 9;
3621 pkt_dev
->udp_dst_max
= 9;
3622 pkt_dev
->vlan_p
= 0;
3623 pkt_dev
->vlan_cfi
= 0;
3624 pkt_dev
->vlan_id
= 0xffff;
3625 pkt_dev
->svlan_p
= 0;
3626 pkt_dev
->svlan_cfi
= 0;
3627 pkt_dev
->svlan_id
= 0xffff;
3629 pkt_dev
->node
= NUMA_NO_NODE
;
3631 err
= pktgen_setup_dev(t
->net
, pkt_dev
, ifname
);
3634 if (pkt_dev
->odev
->priv_flags
& IFF_TX_SKB_SHARING
)
3635 pkt_dev
->clone_skb
= pg_clone_skb_d
;
3637 pkt_dev
->entry
= proc_create_data(ifname
, 0600, t
->net
->proc_dir
,
3638 &pktgen_if_fops
, pkt_dev
);
3639 if (!pkt_dev
->entry
) {
3640 pr_err("cannot create %s/%s procfs entry\n",
3641 PG_PROC_DIR
, ifname
);
3646 pkt_dev
->ipsmode
= XFRM_MODE_TRANSPORT
;
3647 pkt_dev
->ipsproto
= IPPROTO_ESP
;
3649 /* xfrm tunnel mode needs additional dst to extract outter
3650 * ip header protocol/ttl/id field, here creat a phony one.
3651 * instead of looking for a valid rt, which definitely hurting
3652 * performance under such circumstance.
3654 pkt_dev
->dstops
.family
= AF_INET
;
3655 pkt_dev
->xdst
.u
.dst
.dev
= pkt_dev
->odev
;
3656 dst_init_metrics(&pkt_dev
->xdst
.u
.dst
, pktgen_dst_metrics
, false);
3657 pkt_dev
->xdst
.child
= &pkt_dev
->xdst
.u
.dst
;
3658 pkt_dev
->xdst
.u
.dst
.ops
= &pkt_dev
->dstops
;
3661 return add_dev_to_thread(t
, pkt_dev
);
3663 dev_put(pkt_dev
->odev
);
3668 vfree(pkt_dev
->flows
);
3673 static int __net_init
pktgen_create_thread(int cpu
, struct pktgen_net
*pn
)
3675 struct pktgen_thread
*t
;
3676 struct proc_dir_entry
*pe
;
3677 struct task_struct
*p
;
3679 t
= kzalloc_node(sizeof(struct pktgen_thread
), GFP_KERNEL
,
3682 pr_err("ERROR: out of memory, can't create new thread\n");
3686 mutex_init(&t
->if_lock
);
3689 INIT_LIST_HEAD(&t
->if_list
);
3691 list_add_tail(&t
->th_list
, &pn
->pktgen_threads
);
3692 init_completion(&t
->start_done
);
3694 p
= kthread_create_on_node(pktgen_thread_worker
,
3697 "kpktgend_%d", cpu
);
3699 pr_err("kernel_thread() failed for cpu %d\n", t
->cpu
);
3700 list_del(&t
->th_list
);
3704 kthread_bind(p
, cpu
);
3707 pe
= proc_create_data(t
->tsk
->comm
, 0600, pn
->proc_dir
,
3708 &pktgen_thread_fops
, t
);
3710 pr_err("cannot create %s/%s procfs entry\n",
3711 PG_PROC_DIR
, t
->tsk
->comm
);
3713 list_del(&t
->th_list
);
3721 wait_for_completion(&t
->start_done
);
3727 * Removes a device from the thread if_list.
3729 static void _rem_dev_from_if_list(struct pktgen_thread
*t
,
3730 struct pktgen_dev
*pkt_dev
)
3732 struct list_head
*q
, *n
;
3733 struct pktgen_dev
*p
;
3736 list_for_each_safe(q
, n
, &t
->if_list
) {
3737 p
= list_entry(q
, struct pktgen_dev
, list
);
3739 list_del_rcu(&p
->list
);
3744 static int pktgen_remove_device(struct pktgen_thread
*t
,
3745 struct pktgen_dev
*pkt_dev
)
3747 pr_debug("remove_device pkt_dev=%p\n", pkt_dev
);
3749 if (pkt_dev
->running
) {
3750 pr_warn("WARNING: trying to remove a running interface, stopping it now\n");
3751 pktgen_stop_device(pkt_dev
);
3754 /* Dis-associate from the interface */
3756 if (pkt_dev
->odev
) {
3757 dev_put(pkt_dev
->odev
);
3758 pkt_dev
->odev
= NULL
;
3761 /* Remove proc before if_list entry, because add_device uses
3762 * list to determine if interface already exist, avoid race
3763 * with proc_create_data() */
3764 proc_remove(pkt_dev
->entry
);
3766 /* And update the thread if_list */
3767 _rem_dev_from_if_list(t
, pkt_dev
);
3772 vfree(pkt_dev
->flows
);
3774 put_page(pkt_dev
->page
);
3775 kfree_rcu(pkt_dev
, rcu
);
3779 static int __net_init
pg_net_init(struct net
*net
)
3781 struct pktgen_net
*pn
= net_generic(net
, pg_net_id
);
3782 struct proc_dir_entry
*pe
;
3786 INIT_LIST_HEAD(&pn
->pktgen_threads
);
3787 pn
->pktgen_exiting
= false;
3788 pn
->proc_dir
= proc_mkdir(PG_PROC_DIR
, pn
->net
->proc_net
);
3789 if (!pn
->proc_dir
) {
3790 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR
);
3793 pe
= proc_create(PGCTRL
, 0600, pn
->proc_dir
, &pktgen_fops
);
3795 pr_err("cannot create %s procfs entry\n", PGCTRL
);
3800 for_each_online_cpu(cpu
) {
3803 err
= pktgen_create_thread(cpu
, pn
);
3805 pr_warn("Cannot create thread for cpu %d (%d)\n",
3809 if (list_empty(&pn
->pktgen_threads
)) {
3810 pr_err("Initialization failed for all threads\n");
3818 remove_proc_entry(PGCTRL
, pn
->proc_dir
);
3820 remove_proc_entry(PG_PROC_DIR
, pn
->net
->proc_net
);
3824 static void __net_exit
pg_net_exit(struct net
*net
)
3826 struct pktgen_net
*pn
= net_generic(net
, pg_net_id
);
3827 struct pktgen_thread
*t
;
3828 struct list_head
*q
, *n
;
3831 /* Stop all interfaces & threads */
3832 pn
->pktgen_exiting
= true;
3834 mutex_lock(&pktgen_thread_lock
);
3835 list_splice_init(&pn
->pktgen_threads
, &list
);
3836 mutex_unlock(&pktgen_thread_lock
);
3838 list_for_each_safe(q
, n
, &list
) {
3839 t
= list_entry(q
, struct pktgen_thread
, th_list
);
3840 list_del(&t
->th_list
);
3841 kthread_stop(t
->tsk
);
3842 put_task_struct(t
->tsk
);
3846 remove_proc_entry(PGCTRL
, pn
->proc_dir
);
3847 remove_proc_entry(PG_PROC_DIR
, pn
->net
->proc_net
);
3850 static struct pernet_operations pg_net_ops
= {
3851 .init
= pg_net_init
,
3852 .exit
= pg_net_exit
,
3854 .size
= sizeof(struct pktgen_net
),
3857 static int __init
pg_init(void)
3861 pr_info("%s", version
);
3862 ret
= register_pernet_subsys(&pg_net_ops
);
3865 ret
= register_netdevice_notifier(&pktgen_notifier_block
);
3867 unregister_pernet_subsys(&pg_net_ops
);
3872 static void __exit
pg_cleanup(void)
3874 unregister_netdevice_notifier(&pktgen_notifier_block
);
3875 unregister_pernet_subsys(&pg_net_ops
);
3876 /* Don't need rcu_barrier() due to use of kfree_rcu() */
3879 module_init(pg_init
);
3880 module_exit(pg_cleanup
);
3882 MODULE_AUTHOR("Robert Olsson <robert.olsson@its.uu.se>");
3883 MODULE_DESCRIPTION("Packet Generator tool");
3884 MODULE_LICENSE("GPL");
3885 MODULE_VERSION(VERSION
);
3886 module_param(pg_count_d
, int, 0);
3887 MODULE_PARM_DESC(pg_count_d
, "Default number of packets to inject");
3888 module_param(pg_delay_d
, int, 0);
3889 MODULE_PARM_DESC(pg_delay_d
, "Default delay between packets (nanoseconds)");
3890 module_param(pg_clone_skb_d
, int, 0);
3891 MODULE_PARM_DESC(pg_clone_skb_d
, "Default number of copies of the same packet");
3892 module_param(debug
, int, 0);
3893 MODULE_PARM_DESC(debug
, "Enable debugging of pktgen module");