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 <net/net_namespace.h>
162 #include <net/checksum.h>
163 #include <net/ipv6.h>
165 #include <net/ip6_checksum.h>
166 #include <net/addrconf.h>
168 #include <net/xfrm.h>
170 #include <net/netns/generic.h>
171 #include <asm/byteorder.h>
172 #include <linux/rcupdate.h>
173 #include <linux/bitops.h>
174 #include <linux/io.h>
175 #include <linux/timex.h>
176 #include <linux/uaccess.h>
178 #include <asm/div64.h> /* do_div */
180 #define VERSION "2.75"
181 #define IP_NAME_SZ 32
182 #define MAX_MPLS_LABELS 16 /* This is the max label stack depth */
183 #define MPLS_STACK_BOTTOM htonl(0x00000100)
185 #define func_enter() pr_debug("entering %s\n", __func__);
188 pf(IPV6) /* Interface in IPV6 Mode */ \
189 pf(IPSRC_RND) /* IP-Src Random */ \
190 pf(IPDST_RND) /* IP-Dst Random */ \
191 pf(TXSIZE_RND) /* Transmit size is random */ \
192 pf(UDPSRC_RND) /* UDP-Src Random */ \
193 pf(UDPDST_RND) /* UDP-Dst Random */ \
194 pf(UDPCSUM) /* Include UDP checksum */ \
195 pf(NO_TIMESTAMP) /* Don't timestamp packets (default TS) */ \
196 pf(MPLS_RND) /* Random MPLS labels */ \
197 pf(QUEUE_MAP_RND) /* queue map Random */ \
198 pf(QUEUE_MAP_CPU) /* queue map mirrors smp_processor_id() */ \
199 pf(FLOW_SEQ) /* Sequential flows */ \
200 pf(IPSEC) /* ipsec on for flows */ \
201 pf(MACSRC_RND) /* MAC-Src Random */ \
202 pf(MACDST_RND) /* MAC-Dst Random */ \
203 pf(VID_RND) /* Random VLAN ID */ \
204 pf(SVID_RND) /* Random SVLAN ID */ \
205 pf(NODE) /* Node memory alloc*/ \
207 #define pf(flag) flag##_SHIFT,
213 /* Device flag bits */
214 #define pf(flag) static const __u32 F_##flag = (1<<flag##_SHIFT);
218 #define pf(flag) __stringify(flag),
219 static char *pkt_flag_names
[] = {
224 #define NR_PKT_FLAGS ARRAY_SIZE(pkt_flag_names)
226 /* Thread control flag bits */
227 #define T_STOP (1<<0) /* Stop run */
228 #define T_RUN (1<<1) /* Start run */
229 #define T_REMDEVALL (1<<2) /* Remove all devs */
230 #define T_REMDEV (1<<3) /* Remove one dev */
233 #define M_START_XMIT 0 /* Default normal TX */
234 #define M_NETIF_RECEIVE 1 /* Inject packets into stack */
235 #define M_QUEUE_XMIT 2 /* Inject packet into qdisc */
237 /* If lock -- protects updating of if_list */
238 #define if_lock(t) mutex_lock(&(t->if_lock));
239 #define if_unlock(t) mutex_unlock(&(t->if_lock));
241 /* Used to help with determining the pkts on receive */
242 #define PKTGEN_MAGIC 0xbe9be955
243 #define PG_PROC_DIR "pktgen"
244 #define PGCTRL "pgctrl"
246 #define MAX_CFLOWS 65536
248 #define VLAN_TAG_SIZE(x) ((x)->vlan_id == 0xffff ? 0 : 4)
249 #define SVLAN_TAG_SIZE(x) ((x)->svlan_id == 0xffff ? 0 : 4)
255 struct xfrm_state
*x
;
261 #define F_INIT (1<<0) /* flow has been initialized */
265 * Try to keep frequent/infrequent used vars. separated.
267 struct proc_dir_entry
*entry
; /* proc file */
268 struct pktgen_thread
*pg_thread
;/* the owner */
269 struct list_head list
; /* chaining in the thread's run-queue */
270 struct rcu_head rcu
; /* freed by RCU */
272 int running
; /* if false, the test will stop */
274 /* If min != max, then we will either do a linear iteration, or
275 * we will do a random selection from within the range.
281 int pkt_overhead
; /* overhead for MPLS, VLANs, IPSEC etc */
283 int removal_mark
; /* non-zero => the device is marked for
284 * removal by worker thread */
287 u64 delay
; /* nano-seconds */
289 __u64 count
; /* Default No packets to send */
290 __u64 sofar
; /* How many pkts we've sent so far */
291 __u64 tx_bytes
; /* How many bytes we've transmitted */
292 __u64 errors
; /* Errors when trying to transmit, */
294 /* runtime counters relating to clone_skb */
297 int last_ok
; /* Was last skb sent?
298 * Or a failed transmit of some sort?
299 * This will keep sequence numbers in order
304 u64 idle_acc
; /* nano-seconds */
309 * Use multiple SKBs during packet gen.
310 * If this number is greater than 1, then
311 * that many copies of the same packet will be
312 * sent before a new packet is allocated.
313 * If you want to send 1024 identical packets
314 * before creating a new packet,
315 * set clone_skb to 1024.
318 char dst_min
[IP_NAME_SZ
]; /* IP, ie 1.2.3.4 */
319 char dst_max
[IP_NAME_SZ
]; /* IP, ie 1.2.3.4 */
320 char src_min
[IP_NAME_SZ
]; /* IP, ie 1.2.3.4 */
321 char src_max
[IP_NAME_SZ
]; /* IP, ie 1.2.3.4 */
323 struct in6_addr in6_saddr
;
324 struct in6_addr in6_daddr
;
325 struct in6_addr cur_in6_daddr
;
326 struct in6_addr cur_in6_saddr
;
328 struct in6_addr min_in6_daddr
;
329 struct in6_addr max_in6_daddr
;
330 struct in6_addr min_in6_saddr
;
331 struct in6_addr max_in6_saddr
;
333 /* If we're doing ranges, random or incremental, then this
334 * defines the min/max for those ranges.
336 __be32 saddr_min
; /* inclusive, source IP address */
337 __be32 saddr_max
; /* exclusive, source IP address */
338 __be32 daddr_min
; /* inclusive, dest IP address */
339 __be32 daddr_max
; /* exclusive, dest IP address */
341 __u16 udp_src_min
; /* inclusive, source UDP port */
342 __u16 udp_src_max
; /* exclusive, source UDP port */
343 __u16 udp_dst_min
; /* inclusive, dest UDP port */
344 __u16 udp_dst_max
; /* exclusive, dest UDP port */
347 __u8 tos
; /* six MSB of (former) IPv4 TOS
348 are for dscp codepoint */
349 __u8 traffic_class
; /* ditto for the (former) Traffic Class in IPv6
350 (see RFC 3260, sec. 4) */
353 unsigned int nr_labels
; /* Depth of stack, 0 = no MPLS */
354 __be32 labels
[MAX_MPLS_LABELS
];
356 /* VLAN/SVLAN (802.1Q/Q-in-Q) */
359 __u16 vlan_id
; /* 0xffff means no vlan tag */
363 __u16 svlan_id
; /* 0xffff means no svlan tag */
365 __u32 src_mac_count
; /* How many MACs to iterate through */
366 __u32 dst_mac_count
; /* How many MACs to iterate through */
368 unsigned char dst_mac
[ETH_ALEN
];
369 unsigned char src_mac
[ETH_ALEN
];
371 __u32 cur_dst_mac_offset
;
372 __u32 cur_src_mac_offset
;
384 0x00, 0x80, 0xC8, 0x79, 0xB3, 0xCB,
386 We fill in SRC address later
387 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
391 __u16 pad
; /* pad out the hh struct to an even 16 bytes */
393 struct sk_buff
*skb
; /* skb we are to transmit next, used for when we
394 * are transmitting the same one multiple times
396 struct net_device
*odev
; /* The out-going device.
397 * Note that the device should have it's
398 * pg_info pointer pointing back to this
400 * Set when the user specifies the out-going
401 * device name (not when the inject is
402 * started as it used to do.)
405 struct flow_state
*flows
;
406 unsigned int cflows
; /* Concurrent flows (config) */
407 unsigned int lflow
; /* Flow length (config) */
408 unsigned int nflows
; /* accumulated flows (stats) */
409 unsigned int curfl
; /* current sequenced flow (state)*/
413 __u32 skb_priority
; /* skb priority field */
414 unsigned int burst
; /* number of duplicated packets to burst */
415 int node
; /* Memory node */
418 __u8 ipsmode
; /* IPSEC mode (config) */
419 __u8 ipsproto
; /* IPSEC type (config) */
421 struct xfrm_dst xdst
;
422 struct dst_ops dstops
;
435 static unsigned int pg_net_id __read_mostly
;
439 struct proc_dir_entry
*proc_dir
;
440 struct list_head pktgen_threads
;
444 struct pktgen_thread
{
445 struct mutex if_lock
; /* for list of devices */
446 struct list_head if_list
; /* All device here */
447 struct list_head th_list
;
448 struct task_struct
*tsk
;
451 /* Field for thread to receive "posted" events terminate,
457 wait_queue_head_t queue
;
458 struct completion start_done
;
459 struct pktgen_net
*net
;
465 static const char version
[] =
466 "Packet Generator for packet performance testing. "
467 "Version: " VERSION
"\n";
469 static int pktgen_remove_device(struct pktgen_thread
*t
, struct pktgen_dev
*i
);
470 static int pktgen_add_device(struct pktgen_thread
*t
, const char *ifname
);
471 static struct pktgen_dev
*pktgen_find_dev(struct pktgen_thread
*t
,
472 const char *ifname
, bool exact
);
473 static int pktgen_device_event(struct notifier_block
*, unsigned long, void *);
474 static void pktgen_run_all_threads(struct pktgen_net
*pn
);
475 static void pktgen_reset_all_threads(struct pktgen_net
*pn
);
476 static void pktgen_stop_all_threads_ifs(struct pktgen_net
*pn
);
478 static void pktgen_stop(struct pktgen_thread
*t
);
479 static void pktgen_clear_counters(struct pktgen_dev
*pkt_dev
);
481 /* Module parameters, defaults. */
482 static int pg_count_d __read_mostly
= 1000;
483 static int pg_delay_d __read_mostly
;
484 static int pg_clone_skb_d __read_mostly
;
485 static int debug __read_mostly
;
487 static DEFINE_MUTEX(pktgen_thread_lock
);
489 static struct notifier_block pktgen_notifier_block
= {
490 .notifier_call
= pktgen_device_event
,
494 * /proc handling functions
498 static int pgctrl_show(struct seq_file
*seq
, void *v
)
500 seq_puts(seq
, version
);
504 static ssize_t
pgctrl_write(struct file
*file
, const char __user
*buf
,
505 size_t count
, loff_t
*ppos
)
508 struct pktgen_net
*pn
= net_generic(current
->nsproxy
->net_ns
, pg_net_id
);
510 if (!capable(CAP_NET_ADMIN
))
516 if (count
> sizeof(data
))
517 count
= sizeof(data
);
519 if (copy_from_user(data
, buf
, count
))
522 data
[count
- 1] = 0; /* Strip trailing '\n' and terminate string */
524 if (!strcmp(data
, "stop"))
525 pktgen_stop_all_threads_ifs(pn
);
527 else if (!strcmp(data
, "start"))
528 pktgen_run_all_threads(pn
);
530 else if (!strcmp(data
, "reset"))
531 pktgen_reset_all_threads(pn
);
539 static int pgctrl_open(struct inode
*inode
, struct file
*file
)
541 return single_open(file
, pgctrl_show
, PDE_DATA(inode
));
544 static const struct file_operations pktgen_fops
= {
548 .write
= pgctrl_write
,
549 .release
= single_release
,
552 static int pktgen_if_show(struct seq_file
*seq
, void *v
)
554 const struct pktgen_dev
*pkt_dev
= seq
->private;
560 "Params: count %llu min_pkt_size: %u max_pkt_size: %u\n",
561 (unsigned long long)pkt_dev
->count
, pkt_dev
->min_pkt_size
,
562 pkt_dev
->max_pkt_size
);
565 " frags: %d delay: %llu clone_skb: %d ifname: %s\n",
566 pkt_dev
->nfrags
, (unsigned long long) pkt_dev
->delay
,
567 pkt_dev
->clone_skb
, pkt_dev
->odevname
);
569 seq_printf(seq
, " flows: %u flowlen: %u\n", pkt_dev
->cflows
,
573 " queue_map_min: %u queue_map_max: %u\n",
574 pkt_dev
->queue_map_min
,
575 pkt_dev
->queue_map_max
);
577 if (pkt_dev
->skb_priority
)
578 seq_printf(seq
, " skb_priority: %u\n",
579 pkt_dev
->skb_priority
);
581 if (pkt_dev
->flags
& F_IPV6
) {
583 " saddr: %pI6c min_saddr: %pI6c max_saddr: %pI6c\n"
584 " daddr: %pI6c min_daddr: %pI6c max_daddr: %pI6c\n",
586 &pkt_dev
->min_in6_saddr
, &pkt_dev
->max_in6_saddr
,
588 &pkt_dev
->min_in6_daddr
, &pkt_dev
->max_in6_daddr
);
591 " dst_min: %s dst_max: %s\n",
592 pkt_dev
->dst_min
, pkt_dev
->dst_max
);
594 " src_min: %s src_max: %s\n",
595 pkt_dev
->src_min
, pkt_dev
->src_max
);
598 seq_puts(seq
, " src_mac: ");
600 seq_printf(seq
, "%pM ",
601 is_zero_ether_addr(pkt_dev
->src_mac
) ?
602 pkt_dev
->odev
->dev_addr
: pkt_dev
->src_mac
);
604 seq_puts(seq
, "dst_mac: ");
605 seq_printf(seq
, "%pM\n", pkt_dev
->dst_mac
);
608 " udp_src_min: %d udp_src_max: %d"
609 " udp_dst_min: %d udp_dst_max: %d\n",
610 pkt_dev
->udp_src_min
, pkt_dev
->udp_src_max
,
611 pkt_dev
->udp_dst_min
, pkt_dev
->udp_dst_max
);
614 " src_mac_count: %d dst_mac_count: %d\n",
615 pkt_dev
->src_mac_count
, pkt_dev
->dst_mac_count
);
617 if (pkt_dev
->nr_labels
) {
618 seq_puts(seq
, " mpls: ");
619 for (i
= 0; i
< pkt_dev
->nr_labels
; i
++)
620 seq_printf(seq
, "%08x%s", ntohl(pkt_dev
->labels
[i
]),
621 i
== pkt_dev
->nr_labels
-1 ? "\n" : ", ");
624 if (pkt_dev
->vlan_id
!= 0xffff)
625 seq_printf(seq
, " vlan_id: %u vlan_p: %u vlan_cfi: %u\n",
626 pkt_dev
->vlan_id
, pkt_dev
->vlan_p
,
629 if (pkt_dev
->svlan_id
!= 0xffff)
630 seq_printf(seq
, " svlan_id: %u vlan_p: %u vlan_cfi: %u\n",
631 pkt_dev
->svlan_id
, pkt_dev
->svlan_p
,
635 seq_printf(seq
, " tos: 0x%02x\n", pkt_dev
->tos
);
637 if (pkt_dev
->traffic_class
)
638 seq_printf(seq
, " traffic_class: 0x%02x\n", pkt_dev
->traffic_class
);
640 if (pkt_dev
->burst
> 1)
641 seq_printf(seq
, " burst: %d\n", pkt_dev
->burst
);
643 if (pkt_dev
->node
>= 0)
644 seq_printf(seq
, " node: %d\n", pkt_dev
->node
);
646 if (pkt_dev
->xmit_mode
== M_NETIF_RECEIVE
)
647 seq_puts(seq
, " xmit_mode: netif_receive\n");
648 else if (pkt_dev
->xmit_mode
== M_QUEUE_XMIT
)
649 seq_puts(seq
, " xmit_mode: xmit_queue\n");
651 seq_puts(seq
, " Flags: ");
653 for (i
= 0; i
< NR_PKT_FLAGS
; i
++) {
655 if (!pkt_dev
->cflows
)
658 if (pkt_dev
->flags
& (1 << i
))
659 seq_printf(seq
, "%s ", pkt_flag_names
[i
]);
660 else if (i
== F_FLOW_SEQ
)
661 seq_puts(seq
, "FLOW_RND ");
664 if (i
== F_IPSEC
&& pkt_dev
->spi
)
665 seq_printf(seq
, "spi:%u", pkt_dev
->spi
);
671 /* not really stopped, more like last-running-at */
672 stopped
= pkt_dev
->running
? ktime_get() : pkt_dev
->stopped_at
;
673 idle
= pkt_dev
->idle_acc
;
674 do_div(idle
, NSEC_PER_USEC
);
677 "Current:\n pkts-sofar: %llu errors: %llu\n",
678 (unsigned long long)pkt_dev
->sofar
,
679 (unsigned long long)pkt_dev
->errors
);
682 " started: %lluus stopped: %lluus idle: %lluus\n",
683 (unsigned long long) ktime_to_us(pkt_dev
->started_at
),
684 (unsigned long long) ktime_to_us(stopped
),
685 (unsigned long long) idle
);
688 " seq_num: %d cur_dst_mac_offset: %d cur_src_mac_offset: %d\n",
689 pkt_dev
->seq_num
, pkt_dev
->cur_dst_mac_offset
,
690 pkt_dev
->cur_src_mac_offset
);
692 if (pkt_dev
->flags
& F_IPV6
) {
693 seq_printf(seq
, " cur_saddr: %pI6c cur_daddr: %pI6c\n",
694 &pkt_dev
->cur_in6_saddr
,
695 &pkt_dev
->cur_in6_daddr
);
697 seq_printf(seq
, " cur_saddr: %pI4 cur_daddr: %pI4\n",
698 &pkt_dev
->cur_saddr
, &pkt_dev
->cur_daddr
);
700 seq_printf(seq
, " cur_udp_dst: %d cur_udp_src: %d\n",
701 pkt_dev
->cur_udp_dst
, pkt_dev
->cur_udp_src
);
703 seq_printf(seq
, " cur_queue_map: %u\n", pkt_dev
->cur_queue_map
);
705 seq_printf(seq
, " flows: %u\n", pkt_dev
->nflows
);
707 if (pkt_dev
->result
[0])
708 seq_printf(seq
, "Result: %s\n", pkt_dev
->result
);
710 seq_puts(seq
, "Result: Idle\n");
716 static int hex32_arg(const char __user
*user_buffer
, unsigned long maxlen
,
722 for (; i
< maxlen
; i
++) {
726 if (get_user(c
, &user_buffer
[i
]))
728 value
= hex_to_bin(c
);
737 static int count_trail_chars(const char __user
* user_buffer
,
742 for (i
= 0; i
< maxlen
; i
++) {
744 if (get_user(c
, &user_buffer
[i
]))
762 static long num_arg(const char __user
*user_buffer
, unsigned long maxlen
,
768 for (i
= 0; i
< maxlen
; i
++) {
770 if (get_user(c
, &user_buffer
[i
]))
772 if ((c
>= '0') && (c
<= '9')) {
781 static int strn_len(const char __user
* user_buffer
, unsigned int maxlen
)
785 for (i
= 0; i
< maxlen
; i
++) {
787 if (get_user(c
, &user_buffer
[i
]))
804 static ssize_t
get_labels(const char __user
*buffer
, struct pktgen_dev
*pkt_dev
)
811 pkt_dev
->nr_labels
= 0;
814 len
= hex32_arg(&buffer
[i
], 8, &tmp
);
817 pkt_dev
->labels
[n
] = htonl(tmp
);
818 if (pkt_dev
->labels
[n
] & MPLS_STACK_BOTTOM
)
819 pkt_dev
->flags
|= F_MPLS_RND
;
821 if (get_user(c
, &buffer
[i
]))
825 if (n
>= MAX_MPLS_LABELS
)
829 pkt_dev
->nr_labels
= n
;
833 static __u32
pktgen_read_flag(const char *f
, bool *disable
)
842 for (i
= 0; i
< NR_PKT_FLAGS
; i
++) {
843 if (!IS_ENABLED(CONFIG_XFRM
) && i
== IPSEC_SHIFT
)
846 /* allow only disabling ipv6 flag */
847 if (!*disable
&& i
== IPV6_SHIFT
)
850 if (strcmp(f
, pkt_flag_names
[i
]) == 0)
854 if (strcmp(f
, "FLOW_RND") == 0) {
855 *disable
= !*disable
;
862 static ssize_t
pktgen_if_write(struct file
*file
,
863 const char __user
* user_buffer
, size_t count
,
866 struct seq_file
*seq
= file
->private_data
;
867 struct pktgen_dev
*pkt_dev
= seq
->private;
869 char name
[16], valstr
[32];
870 unsigned long value
= 0;
871 char *pg_result
= NULL
;
875 pg_result
= &(pkt_dev
->result
[0]);
878 pr_warn("wrong command format\n");
883 tmp
= count_trail_chars(user_buffer
, max
);
885 pr_warn("illegal format\n");
890 /* Read variable name */
892 len
= strn_len(&user_buffer
[i
], sizeof(name
) - 1);
896 memset(name
, 0, sizeof(name
));
897 if (copy_from_user(name
, &user_buffer
[i
], len
))
902 len
= count_trail_chars(&user_buffer
[i
], max
);
909 size_t copy
= min_t(size_t, count
, 1023);
911 if (copy_from_user(tb
, user_buffer
, copy
))
914 pr_debug("%s,%lu buffer -:%s:-\n",
915 name
, (unsigned long)count
, tb
);
918 if (!strcmp(name
, "min_pkt_size")) {
919 len
= num_arg(&user_buffer
[i
], 10, &value
);
924 if (value
< 14 + 20 + 8)
926 if (value
!= pkt_dev
->min_pkt_size
) {
927 pkt_dev
->min_pkt_size
= value
;
928 pkt_dev
->cur_pkt_size
= value
;
930 sprintf(pg_result
, "OK: min_pkt_size=%u",
931 pkt_dev
->min_pkt_size
);
935 if (!strcmp(name
, "max_pkt_size")) {
936 len
= num_arg(&user_buffer
[i
], 10, &value
);
941 if (value
< 14 + 20 + 8)
943 if (value
!= pkt_dev
->max_pkt_size
) {
944 pkt_dev
->max_pkt_size
= value
;
945 pkt_dev
->cur_pkt_size
= value
;
947 sprintf(pg_result
, "OK: max_pkt_size=%u",
948 pkt_dev
->max_pkt_size
);
952 /* Shortcut for min = max */
954 if (!strcmp(name
, "pkt_size")) {
955 len
= num_arg(&user_buffer
[i
], 10, &value
);
960 if (value
< 14 + 20 + 8)
962 if (value
!= pkt_dev
->min_pkt_size
) {
963 pkt_dev
->min_pkt_size
= value
;
964 pkt_dev
->max_pkt_size
= value
;
965 pkt_dev
->cur_pkt_size
= value
;
967 sprintf(pg_result
, "OK: pkt_size=%u", pkt_dev
->min_pkt_size
);
971 if (!strcmp(name
, "debug")) {
972 len
= num_arg(&user_buffer
[i
], 10, &value
);
978 sprintf(pg_result
, "OK: debug=%u", debug
);
982 if (!strcmp(name
, "frags")) {
983 len
= num_arg(&user_buffer
[i
], 10, &value
);
988 pkt_dev
->nfrags
= value
;
989 sprintf(pg_result
, "OK: frags=%u", pkt_dev
->nfrags
);
992 if (!strcmp(name
, "delay")) {
993 len
= num_arg(&user_buffer
[i
], 10, &value
);
998 if (value
== 0x7FFFFFFF)
999 pkt_dev
->delay
= ULLONG_MAX
;
1001 pkt_dev
->delay
= (u64
)value
;
1003 sprintf(pg_result
, "OK: delay=%llu",
1004 (unsigned long long) pkt_dev
->delay
);
1007 if (!strcmp(name
, "rate")) {
1008 len
= num_arg(&user_buffer
[i
], 10, &value
);
1015 pkt_dev
->delay
= pkt_dev
->min_pkt_size
*8*NSEC_PER_USEC
/value
;
1017 pr_info("Delay set at: %llu ns\n", pkt_dev
->delay
);
1019 sprintf(pg_result
, "OK: rate=%lu", value
);
1022 if (!strcmp(name
, "ratep")) {
1023 len
= num_arg(&user_buffer
[i
], 10, &value
);
1030 pkt_dev
->delay
= NSEC_PER_SEC
/value
;
1032 pr_info("Delay set at: %llu ns\n", pkt_dev
->delay
);
1034 sprintf(pg_result
, "OK: rate=%lu", value
);
1037 if (!strcmp(name
, "udp_src_min")) {
1038 len
= num_arg(&user_buffer
[i
], 10, &value
);
1043 if (value
!= pkt_dev
->udp_src_min
) {
1044 pkt_dev
->udp_src_min
= value
;
1045 pkt_dev
->cur_udp_src
= value
;
1047 sprintf(pg_result
, "OK: udp_src_min=%u", pkt_dev
->udp_src_min
);
1050 if (!strcmp(name
, "udp_dst_min")) {
1051 len
= num_arg(&user_buffer
[i
], 10, &value
);
1056 if (value
!= pkt_dev
->udp_dst_min
) {
1057 pkt_dev
->udp_dst_min
= value
;
1058 pkt_dev
->cur_udp_dst
= value
;
1060 sprintf(pg_result
, "OK: udp_dst_min=%u", pkt_dev
->udp_dst_min
);
1063 if (!strcmp(name
, "udp_src_max")) {
1064 len
= num_arg(&user_buffer
[i
], 10, &value
);
1069 if (value
!= pkt_dev
->udp_src_max
) {
1070 pkt_dev
->udp_src_max
= value
;
1071 pkt_dev
->cur_udp_src
= value
;
1073 sprintf(pg_result
, "OK: udp_src_max=%u", pkt_dev
->udp_src_max
);
1076 if (!strcmp(name
, "udp_dst_max")) {
1077 len
= num_arg(&user_buffer
[i
], 10, &value
);
1082 if (value
!= pkt_dev
->udp_dst_max
) {
1083 pkt_dev
->udp_dst_max
= value
;
1084 pkt_dev
->cur_udp_dst
= value
;
1086 sprintf(pg_result
, "OK: udp_dst_max=%u", pkt_dev
->udp_dst_max
);
1089 if (!strcmp(name
, "clone_skb")) {
1090 len
= num_arg(&user_buffer
[i
], 10, &value
);
1094 ((pkt_dev
->xmit_mode
== M_NETIF_RECEIVE
) ||
1095 !(pkt_dev
->odev
->priv_flags
& IFF_TX_SKB_SHARING
)))
1098 pkt_dev
->clone_skb
= value
;
1100 sprintf(pg_result
, "OK: clone_skb=%d", pkt_dev
->clone_skb
);
1103 if (!strcmp(name
, "count")) {
1104 len
= num_arg(&user_buffer
[i
], 10, &value
);
1109 pkt_dev
->count
= value
;
1110 sprintf(pg_result
, "OK: count=%llu",
1111 (unsigned long long)pkt_dev
->count
);
1114 if (!strcmp(name
, "src_mac_count")) {
1115 len
= num_arg(&user_buffer
[i
], 10, &value
);
1120 if (pkt_dev
->src_mac_count
!= value
) {
1121 pkt_dev
->src_mac_count
= value
;
1122 pkt_dev
->cur_src_mac_offset
= 0;
1124 sprintf(pg_result
, "OK: src_mac_count=%d",
1125 pkt_dev
->src_mac_count
);
1128 if (!strcmp(name
, "dst_mac_count")) {
1129 len
= num_arg(&user_buffer
[i
], 10, &value
);
1134 if (pkt_dev
->dst_mac_count
!= value
) {
1135 pkt_dev
->dst_mac_count
= value
;
1136 pkt_dev
->cur_dst_mac_offset
= 0;
1138 sprintf(pg_result
, "OK: dst_mac_count=%d",
1139 pkt_dev
->dst_mac_count
);
1142 if (!strcmp(name
, "burst")) {
1143 len
= num_arg(&user_buffer
[i
], 10, &value
);
1149 ((pkt_dev
->xmit_mode
== M_QUEUE_XMIT
) ||
1150 ((pkt_dev
->xmit_mode
== M_START_XMIT
) &&
1151 (!(pkt_dev
->odev
->priv_flags
& IFF_TX_SKB_SHARING
)))))
1153 pkt_dev
->burst
= value
< 1 ? 1 : value
;
1154 sprintf(pg_result
, "OK: burst=%d", pkt_dev
->burst
);
1157 if (!strcmp(name
, "node")) {
1158 len
= num_arg(&user_buffer
[i
], 10, &value
);
1164 if (node_possible(value
)) {
1165 pkt_dev
->node
= value
;
1166 sprintf(pg_result
, "OK: node=%d", pkt_dev
->node
);
1167 if (pkt_dev
->page
) {
1168 put_page(pkt_dev
->page
);
1169 pkt_dev
->page
= NULL
;
1173 sprintf(pg_result
, "ERROR: node not possible");
1176 if (!strcmp(name
, "xmit_mode")) {
1180 len
= strn_len(&user_buffer
[i
], sizeof(f
) - 1);
1184 if (copy_from_user(f
, &user_buffer
[i
], len
))
1188 if (strcmp(f
, "start_xmit") == 0) {
1189 pkt_dev
->xmit_mode
= M_START_XMIT
;
1190 } else if (strcmp(f
, "netif_receive") == 0) {
1191 /* clone_skb set earlier, not supported in this mode */
1192 if (pkt_dev
->clone_skb
> 0)
1195 pkt_dev
->xmit_mode
= M_NETIF_RECEIVE
;
1197 /* make sure new packet is allocated every time
1198 * pktgen_xmit() is called
1200 pkt_dev
->last_ok
= 1;
1202 /* override clone_skb if user passed default value
1203 * at module loading time
1205 pkt_dev
->clone_skb
= 0;
1206 } else if (strcmp(f
, "queue_xmit") == 0) {
1207 pkt_dev
->xmit_mode
= M_QUEUE_XMIT
;
1208 pkt_dev
->last_ok
= 1;
1211 "xmit_mode -:%s:- unknown\nAvailable modes: %s",
1212 f
, "start_xmit, netif_receive\n");
1215 sprintf(pg_result
, "OK: xmit_mode=%s", f
);
1218 if (!strcmp(name
, "flag")) {
1221 bool disable
= false;
1224 len
= strn_len(&user_buffer
[i
], sizeof(f
) - 1);
1228 if (copy_from_user(f
, &user_buffer
[i
], len
))
1232 flag
= pktgen_read_flag(f
, &disable
);
1236 pkt_dev
->flags
&= ~flag
;
1238 pkt_dev
->flags
|= flag
;
1241 "Flag -:%s:- unknown\nAvailable flags, (prepend ! to un-set flag):\n%s",
1243 "IPSRC_RND, IPDST_RND, UDPSRC_RND, UDPDST_RND, "
1244 "MACSRC_RND, MACDST_RND, TXSIZE_RND, IPV6, "
1245 "MPLS_RND, VID_RND, SVID_RND, FLOW_SEQ, "
1246 "QUEUE_MAP_RND, QUEUE_MAP_CPU, UDPCSUM, "
1254 sprintf(pg_result
, "OK: flags=0x%x", pkt_dev
->flags
);
1257 if (!strcmp(name
, "dst_min") || !strcmp(name
, "dst")) {
1258 len
= strn_len(&user_buffer
[i
], sizeof(pkt_dev
->dst_min
) - 1);
1262 if (copy_from_user(buf
, &user_buffer
[i
], len
))
1265 if (strcmp(buf
, pkt_dev
->dst_min
) != 0) {
1266 memset(pkt_dev
->dst_min
, 0, sizeof(pkt_dev
->dst_min
));
1267 strncpy(pkt_dev
->dst_min
, buf
, len
);
1268 pkt_dev
->daddr_min
= in_aton(pkt_dev
->dst_min
);
1269 pkt_dev
->cur_daddr
= pkt_dev
->daddr_min
;
1272 pr_debug("dst_min set to: %s\n", pkt_dev
->dst_min
);
1274 sprintf(pg_result
, "OK: dst_min=%s", pkt_dev
->dst_min
);
1277 if (!strcmp(name
, "dst_max")) {
1278 len
= strn_len(&user_buffer
[i
], sizeof(pkt_dev
->dst_max
) - 1);
1283 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 strncpy(pkt_dev
->dst_max
, buf
, len
);
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 strncpy(pkt_dev
->src_min
, buf
, len
);
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 strncpy(pkt_dev
->src_max
, buf
, len
);
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
,
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(MAX_CFLOWS
* sizeof(struct flow_state
),
3607 if (pkt_dev
->flows
== NULL
) {
3612 pkt_dev
->removal_mark
= 0;
3613 pkt_dev
->nfrags
= 0;
3614 pkt_dev
->delay
= pg_delay_d
;
3615 pkt_dev
->count
= pg_count_d
;
3617 pkt_dev
->udp_src_min
= 9; /* sink port */
3618 pkt_dev
->udp_src_max
= 9;
3619 pkt_dev
->udp_dst_min
= 9;
3620 pkt_dev
->udp_dst_max
= 9;
3621 pkt_dev
->vlan_p
= 0;
3622 pkt_dev
->vlan_cfi
= 0;
3623 pkt_dev
->vlan_id
= 0xffff;
3624 pkt_dev
->svlan_p
= 0;
3625 pkt_dev
->svlan_cfi
= 0;
3626 pkt_dev
->svlan_id
= 0xffff;
3630 err
= pktgen_setup_dev(t
->net
, pkt_dev
, ifname
);
3633 if (pkt_dev
->odev
->priv_flags
& IFF_TX_SKB_SHARING
)
3634 pkt_dev
->clone_skb
= pg_clone_skb_d
;
3636 pkt_dev
->entry
= proc_create_data(ifname
, 0600, t
->net
->proc_dir
,
3637 &pktgen_if_fops
, pkt_dev
);
3638 if (!pkt_dev
->entry
) {
3639 pr_err("cannot create %s/%s procfs entry\n",
3640 PG_PROC_DIR
, ifname
);
3645 pkt_dev
->ipsmode
= XFRM_MODE_TRANSPORT
;
3646 pkt_dev
->ipsproto
= IPPROTO_ESP
;
3648 /* xfrm tunnel mode needs additional dst to extract outter
3649 * ip header protocol/ttl/id field, here creat a phony one.
3650 * instead of looking for a valid rt, which definitely hurting
3651 * performance under such circumstance.
3653 pkt_dev
->dstops
.family
= AF_INET
;
3654 pkt_dev
->xdst
.u
.dst
.dev
= pkt_dev
->odev
;
3655 dst_init_metrics(&pkt_dev
->xdst
.u
.dst
, pktgen_dst_metrics
, false);
3656 pkt_dev
->xdst
.child
= &pkt_dev
->xdst
.u
.dst
;
3657 pkt_dev
->xdst
.u
.dst
.ops
= &pkt_dev
->dstops
;
3660 return add_dev_to_thread(t
, pkt_dev
);
3662 dev_put(pkt_dev
->odev
);
3667 vfree(pkt_dev
->flows
);
3672 static int __net_init
pktgen_create_thread(int cpu
, struct pktgen_net
*pn
)
3674 struct pktgen_thread
*t
;
3675 struct proc_dir_entry
*pe
;
3676 struct task_struct
*p
;
3678 t
= kzalloc_node(sizeof(struct pktgen_thread
), GFP_KERNEL
,
3681 pr_err("ERROR: out of memory, can't create new thread\n");
3685 mutex_init(&t
->if_lock
);
3688 INIT_LIST_HEAD(&t
->if_list
);
3690 list_add_tail(&t
->th_list
, &pn
->pktgen_threads
);
3691 init_completion(&t
->start_done
);
3693 p
= kthread_create_on_node(pktgen_thread_worker
,
3696 "kpktgend_%d", cpu
);
3698 pr_err("kernel_thread() failed for cpu %d\n", t
->cpu
);
3699 list_del(&t
->th_list
);
3703 kthread_bind(p
, cpu
);
3706 pe
= proc_create_data(t
->tsk
->comm
, 0600, pn
->proc_dir
,
3707 &pktgen_thread_fops
, t
);
3709 pr_err("cannot create %s/%s procfs entry\n",
3710 PG_PROC_DIR
, t
->tsk
->comm
);
3712 list_del(&t
->th_list
);
3720 wait_for_completion(&t
->start_done
);
3726 * Removes a device from the thread if_list.
3728 static void _rem_dev_from_if_list(struct pktgen_thread
*t
,
3729 struct pktgen_dev
*pkt_dev
)
3731 struct list_head
*q
, *n
;
3732 struct pktgen_dev
*p
;
3735 list_for_each_safe(q
, n
, &t
->if_list
) {
3736 p
= list_entry(q
, struct pktgen_dev
, list
);
3738 list_del_rcu(&p
->list
);
3743 static int pktgen_remove_device(struct pktgen_thread
*t
,
3744 struct pktgen_dev
*pkt_dev
)
3746 pr_debug("remove_device pkt_dev=%p\n", pkt_dev
);
3748 if (pkt_dev
->running
) {
3749 pr_warn("WARNING: trying to remove a running interface, stopping it now\n");
3750 pktgen_stop_device(pkt_dev
);
3753 /* Dis-associate from the interface */
3755 if (pkt_dev
->odev
) {
3756 dev_put(pkt_dev
->odev
);
3757 pkt_dev
->odev
= NULL
;
3760 /* Remove proc before if_list entry, because add_device uses
3761 * list to determine if interface already exist, avoid race
3762 * with proc_create_data() */
3763 proc_remove(pkt_dev
->entry
);
3765 /* And update the thread if_list */
3766 _rem_dev_from_if_list(t
, pkt_dev
);
3771 vfree(pkt_dev
->flows
);
3773 put_page(pkt_dev
->page
);
3774 kfree_rcu(pkt_dev
, rcu
);
3778 static int __net_init
pg_net_init(struct net
*net
)
3780 struct pktgen_net
*pn
= net_generic(net
, pg_net_id
);
3781 struct proc_dir_entry
*pe
;
3785 INIT_LIST_HEAD(&pn
->pktgen_threads
);
3786 pn
->pktgen_exiting
= false;
3787 pn
->proc_dir
= proc_mkdir(PG_PROC_DIR
, pn
->net
->proc_net
);
3788 if (!pn
->proc_dir
) {
3789 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR
);
3792 pe
= proc_create(PGCTRL
, 0600, pn
->proc_dir
, &pktgen_fops
);
3794 pr_err("cannot create %s procfs entry\n", PGCTRL
);
3799 for_each_online_cpu(cpu
) {
3802 err
= pktgen_create_thread(cpu
, pn
);
3804 pr_warn("Cannot create thread for cpu %d (%d)\n",
3808 if (list_empty(&pn
->pktgen_threads
)) {
3809 pr_err("Initialization failed for all threads\n");
3817 remove_proc_entry(PGCTRL
, pn
->proc_dir
);
3819 remove_proc_entry(PG_PROC_DIR
, pn
->net
->proc_net
);
3823 static void __net_exit
pg_net_exit(struct net
*net
)
3825 struct pktgen_net
*pn
= net_generic(net
, pg_net_id
);
3826 struct pktgen_thread
*t
;
3827 struct list_head
*q
, *n
;
3830 /* Stop all interfaces & threads */
3831 pn
->pktgen_exiting
= true;
3833 mutex_lock(&pktgen_thread_lock
);
3834 list_splice_init(&pn
->pktgen_threads
, &list
);
3835 mutex_unlock(&pktgen_thread_lock
);
3837 list_for_each_safe(q
, n
, &list
) {
3838 t
= list_entry(q
, struct pktgen_thread
, th_list
);
3839 list_del(&t
->th_list
);
3840 kthread_stop(t
->tsk
);
3841 put_task_struct(t
->tsk
);
3845 remove_proc_entry(PGCTRL
, pn
->proc_dir
);
3846 remove_proc_entry(PG_PROC_DIR
, pn
->net
->proc_net
);
3849 static struct pernet_operations pg_net_ops
= {
3850 .init
= pg_net_init
,
3851 .exit
= pg_net_exit
,
3853 .size
= sizeof(struct pktgen_net
),
3856 static int __init
pg_init(void)
3860 pr_info("%s", version
);
3861 ret
= register_pernet_subsys(&pg_net_ops
);
3864 ret
= register_netdevice_notifier(&pktgen_notifier_block
);
3866 unregister_pernet_subsys(&pg_net_ops
);
3871 static void __exit
pg_cleanup(void)
3873 unregister_netdevice_notifier(&pktgen_notifier_block
);
3874 unregister_pernet_subsys(&pg_net_ops
);
3875 /* Don't need rcu_barrier() due to use of kfree_rcu() */
3878 module_init(pg_init
);
3879 module_exit(pg_cleanup
);
3881 MODULE_AUTHOR("Robert Olsson <robert.olsson@its.uu.se>");
3882 MODULE_DESCRIPTION("Packet Generator tool");
3883 MODULE_LICENSE("GPL");
3884 MODULE_VERSION(VERSION
);
3885 module_param(pg_count_d
, int, 0);
3886 MODULE_PARM_DESC(pg_count_d
, "Default number of packets to inject");
3887 module_param(pg_delay_d
, int, 0);
3888 MODULE_PARM_DESC(pg_delay_d
, "Default delay between packets (nanoseconds)");
3889 module_param(pg_clone_skb_d
, int, 0);
3890 MODULE_PARM_DESC(pg_clone_skb_d
, "Default number of copies of the same packet");
3891 module_param(debug
, int, 0);
3892 MODULE_PARM_DESC(debug
, "Enable debugging of pktgen module");