blob: a9e7fc4c461fa6679c39a51b214d242e1c22b873 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Authors:
3 * Copyright 2001, 2002 by Robert Olsson <robert.olsson@its.uu.se>
4 * Uppsala University and
5 * Swedish University of Agricultural Sciences
6 *
7 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
8 * Ben Greear <greearb@candelatech.com>
Jan Engelhardt96de0e22007-10-19 23:21:04 +02009 * Jens Låås <jens.laas@data.slu.se>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
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.
15 *
16 *
17 * A tool for loading the network with preconfigurated packets.
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +090018 * The tool is implemented as a linux module. Parameters are output
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 * 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.
22 *
23 * Additional hacking by:
24 *
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>
46 *
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +090047 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 * as a "fastpath" with a configurable number of clones after alloc's.
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +090050 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 * clones.
53 *
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +090054 * Also moved to /proc/net/pktgen/
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 * --ro
56 *
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>
60 *
61 * Integrated to 2.5.x 021029 --Lucio Maciel (luciomaciel@zipmail.com.br)
62 *
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +090063 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 * 021124 Finished major redesign and rewrite for new functionality.
65 * See Documentation/networking/pktgen.txt for how to use this.
66 *
67 * The new operation:
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +090068 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 * way. The if_lock should be possible to remove when add/rem_device is merged
73 * into this too.
74 *
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +090075 * By design there should only be *one* "controlling" process. In practice
76 * multiple write accesses gives unpredictable result. Understood by "write"
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 * to /proc gives result code thats should be read be the "writer".
Stephen Hemmingerb4099fa2005-10-14 15:32:22 -070078 * For practical use this should be no problem.
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 *
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +090080 * Note when adding devices to a specific CPU there good idea to also assign
81 * /proc/irq/XX/smp_affinity so TX-interrupts gets bound to the same CPU.
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 * --ro
83 *
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +090084 * Fix refcount off by one if first packet fails, potential null deref,
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 * memleak 030710- KJP
86 *
87 * First "ranges" functionality for ipv6 030726 --ro
88 *
89 * Included flow support. 030802 ANK.
90 *
91 * Fixed unaligned access on IA-64 Grant Grundler <grundler@parisc-linux.org>
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +090092 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 * Remove if fix from added Harald Welte <laforge@netfilter.org> 040419
94 * ia64 compilation fix from Aron Griffis <aron@hp.com> 040604
95 *
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +090096 * New xmit() return, do_div and misc clean up by Stephen Hemminger
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 * <shemminger@osdl.org> 040923
98 *
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +090099 * Randy Dunlap fixed u64 printk compiler waring
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 *
101 * Remove FCS from BW calculation. Lennert Buytenhek <buytenh@wantstofly.org>
102 * New time handling. Lennert Buytenhek <buytenh@wantstofly.org> 041213
103 *
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +0900104 * Corrections from Nikolai Malykh (nmalykh@bilim.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 * Removed unused flags F_SET_SRCMAC & F_SET_SRCIP 041230
106 *
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +0900107 * interruptible_sleep_on_timeout() replaced Nishanth Aravamudan <nacc@us.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 * 050103
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800109 *
110 * MPLS support by Steven Whitehouse <steve@chygwyn.com>
111 *
Francesco Fondelli34954dd2006-09-27 16:30:44 -0700112 * 802.1Q/Q-in-Q support by Francesco Fondelli (FF) <francesco.fondelli@gmail.com>
113 *
Adit Ranadivece5d0b42007-09-16 14:52:15 -0700114 * Fixed src_mac command to set source mac of packet to value specified in
115 * command by Adit Ranadive <adit.262@gmail.com>
116 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 */
Joe Perchesf9467ea2010-06-21 12:29:14 +0000118
119#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121#include <linux/sys.h>
122#include <linux/types.h>
123#include <linux/module.h>
124#include <linux/moduleparam.h>
125#include <linux/kernel.h>
Luiz Capitulino222fa072006-03-20 22:24:27 -0800126#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#include <linux/sched.h>
128#include <linux/slab.h>
129#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130#include <linux/unistd.h>
131#include <linux/string.h>
132#include <linux/ptrace.h>
133#include <linux/errno.h>
134#include <linux/ioport.h>
135#include <linux/interrupt.h>
Randy Dunlap4fc268d2006-01-11 12:17:47 -0800136#include <linux/capability.h>
Stephen Hemminger2bc481c2009-08-28 23:41:29 -0700137#include <linux/hrtimer.h>
Andrew Morton09fe3ef2007-04-12 14:45:32 -0700138#include <linux/freezer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#include <linux/delay.h>
140#include <linux/timer.h>
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -0800141#include <linux/list.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#include <linux/init.h>
143#include <linux/skbuff.h>
144#include <linux/netdevice.h>
145#include <linux/inet.h>
146#include <linux/inetdevice.h>
147#include <linux/rtnetlink.h>
148#include <linux/if_arp.h>
Francesco Fondelli34954dd2006-09-27 16:30:44 -0700149#include <linux/if_vlan.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150#include <linux/in.h>
151#include <linux/ip.h>
152#include <linux/ipv6.h>
153#include <linux/udp.h>
154#include <linux/proc_fs.h>
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700155#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156#include <linux/wait.h>
Kris Katterjohnf404e9a2006-01-17 13:04:57 -0800157#include <linux/etherdevice.h>
David S. Milleree74baa2007-01-01 20:51:53 -0800158#include <linux/kthread.h>
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200159#include <net/net_namespace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160#include <net/checksum.h>
161#include <net/ipv6.h>
162#include <net/addrconf.h>
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -0700163#ifdef CONFIG_XFRM
164#include <net/xfrm.h>
165#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166#include <asm/byteorder.h>
167#include <linux/rcupdate.h>
Jiri Slaby1977f032007-10-18 23:40:25 -0700168#include <linux/bitops.h>
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000169#include <linux/io.h>
170#include <linux/timex.h>
171#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172#include <asm/dma.h>
Luiz Capitulino222f1802006-03-20 22:16:13 -0800173#include <asm/div64.h> /* do_div */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Daniel Turull43d28b62010-06-09 22:49:57 +0000175#define VERSION "2.74"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176#define IP_NAME_SZ 32
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800177#define MAX_MPLS_LABELS 16 /* This is the max label stack depth */
Stephen Hemmingerd5f1ce92007-03-04 16:08:08 -0800178#define MPLS_STACK_BOTTOM htonl(0x00000100)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Joe Perchesf9467ea2010-06-21 12:29:14 +0000180#define func_enter() pr_debug("entering %s\n", __func__);
181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182/* Device flag bits */
Luiz Capitulino222f1802006-03-20 22:16:13 -0800183#define F_IPSRC_RND (1<<0) /* IP-Src Random */
184#define F_IPDST_RND (1<<1) /* IP-Dst Random */
185#define F_UDPSRC_RND (1<<2) /* UDP-Src Random */
186#define F_UDPDST_RND (1<<3) /* UDP-Dst Random */
187#define F_MACSRC_RND (1<<4) /* MAC-Src Random */
188#define F_MACDST_RND (1<<5) /* MAC-Dst Random */
189#define F_TXSIZE_RND (1<<6) /* Transmit size is random */
190#define F_IPV6 (1<<7) /* Interface in IPV6 Mode */
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800191#define F_MPLS_RND (1<<8) /* Random MPLS labels */
Francesco Fondelli34954dd2006-09-27 16:30:44 -0700192#define F_VID_RND (1<<9) /* Random VLAN ID */
193#define F_SVID_RND (1<<10) /* Random SVLAN ID */
Jamal Hadi Salim007a5312007-07-02 22:40:36 -0700194#define F_FLOW_SEQ (1<<11) /* Sequential flows */
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -0700195#define F_IPSEC_ON (1<<12) /* ipsec on for flows */
Robert Olsson45b270f2007-08-28 15:45:55 -0700196#define F_QUEUE_MAP_RND (1<<13) /* queue map Random */
Robert Olssone6fce5b2008-08-07 02:23:01 -0700197#define F_QUEUE_MAP_CPU (1<<14) /* queue map mirrors smp_processor_id() */
Robert Olssone99b99b2010-03-18 22:44:30 +0000198#define F_NODE (1<<15) /* Node memory alloc*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200/* Thread control flag bits */
Stephen Hemminger6b80d6a2009-09-22 19:41:42 +0000201#define T_STOP (1<<0) /* Stop run */
202#define T_RUN (1<<1) /* Start run */
203#define T_REMDEVALL (1<<2) /* Remove all devs */
204#define T_REMDEV (1<<3) /* Remove one dev */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206/* If lock -- can be removed after some work */
207#define if_lock(t) spin_lock(&(t->if_lock));
208#define if_unlock(t) spin_unlock(&(t->if_lock));
209
210/* Used to help with determining the pkts on receive */
211#define PKTGEN_MAGIC 0xbe9be955
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700212#define PG_PROC_DIR "pktgen"
213#define PGCTRL "pgctrl"
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000214static struct proc_dir_entry *pg_proc_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216#define MAX_CFLOWS 65536
217
Francesco Fondelli34954dd2006-09-27 16:30:44 -0700218#define VLAN_TAG_SIZE(x) ((x)->vlan_id == 0xffff ? 0 : 4)
219#define SVLAN_TAG_SIZE(x) ((x)->svlan_id == 0xffff ? 0 : 4)
220
Luiz Capitulino222f1802006-03-20 22:16:13 -0800221struct flow_state {
Al Viro252e3342006-11-14 20:48:11 -0800222 __be32 cur_daddr;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800223 int count;
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -0700224#ifdef CONFIG_XFRM
225 struct xfrm_state *x;
226#endif
Jamal Hadi Salim007a5312007-07-02 22:40:36 -0700227 __u32 flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228};
229
Jamal Hadi Salim007a5312007-07-02 22:40:36 -0700230/* flow flag bits */
231#define F_INIT (1<<0) /* flow has been initialized */
232
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233struct pktgen_dev {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 /*
235 * Try to keep frequent/infrequent used vars. separated.
236 */
Stephen Hemminger39df2322007-03-04 16:11:51 -0800237 struct proc_dir_entry *entry; /* proc file */
238 struct pktgen_thread *pg_thread;/* the owner */
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000239 struct list_head list; /* chaining in the thread's run-queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000241 int running; /* if false, the test will stop */
Luiz Capitulino222f1802006-03-20 22:16:13 -0800242
243 /* If min != max, then we will either do a linear iteration, or
244 * we will do a random selection from within the range.
245 */
246 __u32 flags;
Arthur Kepner95ed63f2006-03-20 21:26:56 -0800247 int removal_mark; /* non-zero => the device is marked for
248 * removal by worker thread */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Luiz Capitulino222f1802006-03-20 22:16:13 -0800250 int min_pkt_size; /* = ETH_ZLEN; */
251 int max_pkt_size; /* = ETH_ZLEN; */
Jamal Hadi Salim16dab722007-07-02 22:39:50 -0700252 int pkt_overhead; /* overhead for MPLS, VLANs, IPSEC etc */
Luiz Capitulino222f1802006-03-20 22:16:13 -0800253 int nfrags;
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +0000254 u64 delay; /* nano-seconds */
255
Luiz Capitulino222f1802006-03-20 22:16:13 -0800256 __u64 count; /* Default No packets to send */
257 __u64 sofar; /* How many pkts we've sent so far */
258 __u64 tx_bytes; /* How many bytes we've transmitted */
John Fastabendf466dba2009-12-23 22:02:57 -0800259 __u64 errors; /* Errors when trying to transmit, */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Luiz Capitulino222f1802006-03-20 22:16:13 -0800261 /* runtime counters relating to clone_skb */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
Luiz Capitulino222f1802006-03-20 22:16:13 -0800263 __u64 allocated_skbs;
264 __u32 clone_count;
265 int last_ok; /* Was last skb sent?
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000266 * Or a failed transmit of some sort?
267 * This will keep sequence numbers in order
Luiz Capitulino222f1802006-03-20 22:16:13 -0800268 */
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +0000269 ktime_t next_tx;
270 ktime_t started_at;
271 ktime_t stopped_at;
272 u64 idle_acc; /* nano-seconds */
273
Luiz Capitulino222f1802006-03-20 22:16:13 -0800274 __u32 seq_num;
275
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000276 int clone_skb; /*
277 * Use multiple SKBs during packet gen.
278 * If this number is greater than 1, then
279 * that many copies of the same packet will be
280 * sent before a new packet is allocated.
281 * If you want to send 1024 identical packets
282 * before creating a new packet,
283 * set clone_skb to 1024.
Luiz Capitulino222f1802006-03-20 22:16:13 -0800284 */
285
286 char dst_min[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */
287 char dst_max[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */
288 char src_min[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */
289 char src_max[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */
290
291 struct in6_addr in6_saddr;
292 struct in6_addr in6_daddr;
293 struct in6_addr cur_in6_daddr;
294 struct in6_addr cur_in6_saddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 /* For ranges */
Luiz Capitulino222f1802006-03-20 22:16:13 -0800296 struct in6_addr min_in6_daddr;
297 struct in6_addr max_in6_daddr;
298 struct in6_addr min_in6_saddr;
299 struct in6_addr max_in6_saddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Luiz Capitulino222f1802006-03-20 22:16:13 -0800301 /* If we're doing ranges, random or incremental, then this
302 * defines the min/max for those ranges.
303 */
Al Viro252e3342006-11-14 20:48:11 -0800304 __be32 saddr_min; /* inclusive, source IP address */
305 __be32 saddr_max; /* exclusive, source IP address */
306 __be32 daddr_min; /* inclusive, dest IP address */
307 __be32 daddr_max; /* exclusive, dest IP address */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Luiz Capitulino222f1802006-03-20 22:16:13 -0800309 __u16 udp_src_min; /* inclusive, source UDP port */
310 __u16 udp_src_max; /* exclusive, source UDP port */
311 __u16 udp_dst_min; /* inclusive, dest UDP port */
312 __u16 udp_dst_max; /* exclusive, dest UDP port */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Francesco Fondelli1ca77682006-09-27 16:32:03 -0700314 /* DSCP + ECN */
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000315 __u8 tos; /* six MSB of (former) IPv4 TOS
316 are for dscp codepoint */
317 __u8 traffic_class; /* ditto for the (former) Traffic Class in IPv6
318 (see RFC 3260, sec. 4) */
Francesco Fondelli1ca77682006-09-27 16:32:03 -0700319
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800320 /* MPLS */
321 unsigned nr_labels; /* Depth of stack, 0 = no MPLS */
322 __be32 labels[MAX_MPLS_LABELS];
323
Francesco Fondelli34954dd2006-09-27 16:30:44 -0700324 /* VLAN/SVLAN (802.1Q/Q-in-Q) */
325 __u8 vlan_p;
326 __u8 vlan_cfi;
327 __u16 vlan_id; /* 0xffff means no vlan tag */
328
329 __u8 svlan_p;
330 __u8 svlan_cfi;
331 __u16 svlan_id; /* 0xffff means no svlan tag */
332
Luiz Capitulino222f1802006-03-20 22:16:13 -0800333 __u32 src_mac_count; /* How many MACs to iterate through */
334 __u32 dst_mac_count; /* How many MACs to iterate through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
Luiz Capitulino222f1802006-03-20 22:16:13 -0800336 unsigned char dst_mac[ETH_ALEN];
337 unsigned char src_mac[ETH_ALEN];
338
339 __u32 cur_dst_mac_offset;
340 __u32 cur_src_mac_offset;
Al Viro252e3342006-11-14 20:48:11 -0800341 __be32 cur_saddr;
342 __be32 cur_daddr;
Eric Dumazet66ed1e52009-10-24 06:55:20 -0700343 __u16 ip_id;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800344 __u16 cur_udp_dst;
345 __u16 cur_udp_src;
Robert Olsson45b270f2007-08-28 15:45:55 -0700346 __u16 cur_queue_map;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800347 __u32 cur_pkt_size;
Eric Dumazetbaac8562009-11-05 21:04:32 -0800348 __u32 last_pkt_size;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800349
350 __u8 hh[14];
351 /* = {
352 0x00, 0x80, 0xC8, 0x79, 0xB3, 0xCB,
353
354 We fill in SRC address later
355 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
356 0x08, 0x00
357 };
358 */
359 __u16 pad; /* pad out the hh struct to an even 16 bytes */
360
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000361 struct sk_buff *skb; /* skb we are to transmit next, used for when we
Luiz Capitulino222f1802006-03-20 22:16:13 -0800362 * are transmitting the same one multiple times
363 */
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000364 struct net_device *odev; /* The out-going device.
365 * Note that the device should have it's
366 * pg_info pointer pointing back to this
367 * device.
368 * Set when the user specifies the out-going
369 * device name (not when the inject is
370 * started as it used to do.)
371 */
Eric Dumazet593f63b2009-11-23 01:44:37 +0000372 char odevname[32];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 struct flow_state *flows;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800374 unsigned cflows; /* Concurrent flows (config) */
375 unsigned lflow; /* Flow length (config) */
376 unsigned nflows; /* accumulated flows (stats) */
Jamal Hadi Salim007a5312007-07-02 22:40:36 -0700377 unsigned curfl; /* current sequenced flow (state)*/
Robert Olsson45b270f2007-08-28 15:45:55 -0700378
379 u16 queue_map_min;
380 u16 queue_map_max;
John Fastabend9e50e3a2010-11-16 19:12:28 +0000381 __u32 skb_priority; /* skb priority field */
Robert Olssone99b99b2010-03-18 22:44:30 +0000382 int node; /* Memory node */
Robert Olsson45b270f2007-08-28 15:45:55 -0700383
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -0700384#ifdef CONFIG_XFRM
385 __u8 ipsmode; /* IPSEC mode (config) */
386 __u8 ipsproto; /* IPSEC type (config) */
387#endif
Stephen Hemminger39df2322007-03-04 16:11:51 -0800388 char result[512];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389};
390
391struct pktgen_hdr {
Al Viro252e3342006-11-14 20:48:11 -0800392 __be32 pgh_magic;
393 __be32 seq_num;
394 __be32 tv_sec;
395 __be32 tv_usec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396};
397
Eric Dumazet551eaff2010-11-21 10:26:44 -0800398static bool pktgen_exiting __read_mostly;
399
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400struct pktgen_thread {
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000401 spinlock_t if_lock; /* for list of devices */
Luiz Capitulinoc26a8012006-03-20 22:18:16 -0800402 struct list_head if_list; /* All device here */
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -0800403 struct list_head th_list;
David S. Milleree74baa2007-01-01 20:51:53 -0800404 struct task_struct *tsk;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800405 char result[512];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000407 /* Field for thread to receive "posted" events terminate,
408 stop ifs etc. */
Luiz Capitulino222f1802006-03-20 22:16:13 -0800409
410 u32 control;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 int cpu;
412
Luiz Capitulino222f1802006-03-20 22:16:13 -0800413 wait_queue_head_t queue;
Denis V. Lunevd3ede322008-05-20 15:12:44 -0700414 struct completion start_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415};
416
417#define REMOVE 1
418#define FIND 0
419
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +0000420static inline ktime_t ktime_now(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421{
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +0000422 struct timespec ts;
423 ktime_get_ts(&ts);
424
425 return timespec_to_ktime(ts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426}
427
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +0000428/* This works even if 32 bit because of careful byte order choice */
429static inline int ktime_lt(const ktime_t cmp1, const ktime_t cmp2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430{
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +0000431 return cmp1.tv64 < cmp2.tv64;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432}
433
Stephen Hemmingerc3d2f522009-08-27 13:55:20 +0000434static const char version[] =
Joe Perchesf9467ea2010-06-21 12:29:14 +0000435 "Packet Generator for packet performance testing. "
436 "Version: " VERSION "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Luiz Capitulino222f1802006-03-20 22:16:13 -0800438static int pktgen_remove_device(struct pktgen_thread *t, struct pktgen_dev *i);
439static int pktgen_add_device(struct pktgen_thread *t, const char *ifname);
440static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t,
Eric Dumazet3e984842009-11-24 14:50:53 -0800441 const char *ifname, bool exact);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442static int pktgen_device_event(struct notifier_block *, unsigned long, void *);
443static void pktgen_run_all_threads(void);
Jesse Brandeburgeb37b412008-11-10 16:48:03 -0800444static void pktgen_reset_all_threads(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445static void pktgen_stop_all_threads_ifs(void);
Stephen Hemminger3bda06a2009-08-27 13:55:10 +0000446
Luiz Capitulino222f1802006-03-20 22:16:13 -0800447static void pktgen_stop(struct pktgen_thread *t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448static void pktgen_clear_counters(struct pktgen_dev *pkt_dev);
Stephen Hemminger39df2322007-03-04 16:11:51 -0800449
Luiz Capitulino222f1802006-03-20 22:16:13 -0800450static unsigned int scan_ip6(const char *s, char ip[16]);
451static unsigned int fmt_ip6(char *s, const char ip[16]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
453/* Module parameters, defaults. */
Stephen Hemminger65c5b782009-08-27 13:55:09 +0000454static int pg_count_d __read_mostly = 1000;
455static int pg_delay_d __read_mostly;
456static int pg_clone_skb_d __read_mostly;
457static int debug __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
Luiz Capitulino222fa072006-03-20 22:24:27 -0800459static DEFINE_MUTEX(pktgen_thread_lock);
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -0800460static LIST_HEAD(pktgen_threads);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462static struct notifier_block pktgen_notifier_block = {
463 .notifier_call = pktgen_device_event,
464};
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466/*
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +0900467 * /proc handling functions
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 *
469 */
470
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700471static int pgctrl_show(struct seq_file *seq, void *v)
Luiz Capitulino222f1802006-03-20 22:16:13 -0800472{
Stephen Hemmingerc3d2f522009-08-27 13:55:20 +0000473 seq_puts(seq, version);
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700474 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475}
476
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000477static ssize_t pgctrl_write(struct file *file, const char __user *buf,
478 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 int err = 0;
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700481 char data[128];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Luiz Capitulino222f1802006-03-20 22:16:13 -0800483 if (!capable(CAP_NET_ADMIN)) {
484 err = -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 goto out;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800486 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700488 if (count > sizeof(data))
489 count = sizeof(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 if (copy_from_user(data, buf, count)) {
Stephen Hemmingerb4099fa2005-10-14 15:32:22 -0700492 err = -EFAULT;
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700493 goto out;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800494 }
495 data[count - 1] = 0; /* Make string */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
Luiz Capitulino222f1802006-03-20 22:16:13 -0800497 if (!strcmp(data, "stop"))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 pktgen_stop_all_threads_ifs();
499
Luiz Capitulino222f1802006-03-20 22:16:13 -0800500 else if (!strcmp(data, "start"))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 pktgen_run_all_threads();
502
Jesse Brandeburgeb37b412008-11-10 16:48:03 -0800503 else if (!strcmp(data, "reset"))
504 pktgen_reset_all_threads();
505
Luiz Capitulino222f1802006-03-20 22:16:13 -0800506 else
Joe Perchesf9467ea2010-06-21 12:29:14 +0000507 pr_warning("Unknown command: %s\n", data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
509 err = count;
510
Luiz Capitulino222f1802006-03-20 22:16:13 -0800511out:
512 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513}
514
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700515static int pgctrl_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516{
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700517 return single_open(file, pgctrl_show, PDE(inode)->data);
518}
519
Arjan van de Ven9a321442007-02-12 00:55:35 -0800520static const struct file_operations pktgen_fops = {
Luiz Capitulino222f1802006-03-20 22:16:13 -0800521 .owner = THIS_MODULE,
522 .open = pgctrl_open,
523 .read = seq_read,
524 .llseek = seq_lseek,
525 .write = pgctrl_write,
526 .release = single_release,
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700527};
528
529static int pktgen_if_show(struct seq_file *seq, void *v)
530{
Stephen Hemminger648fda72009-08-27 13:55:07 +0000531 const struct pktgen_dev *pkt_dev = seq->private;
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +0000532 ktime_t stopped;
533 u64 idle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
Luiz Capitulino222f1802006-03-20 22:16:13 -0800535 seq_printf(seq,
536 "Params: count %llu min_pkt_size: %u max_pkt_size: %u\n",
537 (unsigned long long)pkt_dev->count, pkt_dev->min_pkt_size,
538 pkt_dev->max_pkt_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
Luiz Capitulino222f1802006-03-20 22:16:13 -0800540 seq_printf(seq,
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +0000541 " frags: %d delay: %llu clone_skb: %d ifname: %s\n",
542 pkt_dev->nfrags, (unsigned long long) pkt_dev->delay,
Eric Dumazet593f63b2009-11-23 01:44:37 +0000543 pkt_dev->clone_skb, pkt_dev->odevname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Luiz Capitulino222f1802006-03-20 22:16:13 -0800545 seq_printf(seq, " flows: %u flowlen: %u\n", pkt_dev->cflows,
546 pkt_dev->lflow);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Robert Olsson45b270f2007-08-28 15:45:55 -0700548 seq_printf(seq,
549 " queue_map_min: %u queue_map_max: %u\n",
550 pkt_dev->queue_map_min,
551 pkt_dev->queue_map_max);
552
John Fastabend9e50e3a2010-11-16 19:12:28 +0000553 if (pkt_dev->skb_priority)
554 seq_printf(seq, " skb_priority: %u\n",
555 pkt_dev->skb_priority);
556
Luiz Capitulino222f1802006-03-20 22:16:13 -0800557 if (pkt_dev->flags & F_IPV6) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 char b1[128], b2[128], b3[128];
Luiz Capitulino222f1802006-03-20 22:16:13 -0800559 fmt_ip6(b1, pkt_dev->in6_saddr.s6_addr);
560 fmt_ip6(b2, pkt_dev->min_in6_saddr.s6_addr);
561 fmt_ip6(b3, pkt_dev->max_in6_saddr.s6_addr);
562 seq_printf(seq,
563 " saddr: %s min_saddr: %s max_saddr: %s\n", b1,
564 b2, b3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
Luiz Capitulino222f1802006-03-20 22:16:13 -0800566 fmt_ip6(b1, pkt_dev->in6_daddr.s6_addr);
567 fmt_ip6(b2, pkt_dev->min_in6_daddr.s6_addr);
568 fmt_ip6(b3, pkt_dev->max_in6_daddr.s6_addr);
569 seq_printf(seq,
570 " daddr: %s min_daddr: %s max_daddr: %s\n", b1,
571 b2, b3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000573 } else {
Luiz Capitulino222f1802006-03-20 22:16:13 -0800574 seq_printf(seq,
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000575 " dst_min: %s dst_max: %s\n",
576 pkt_dev->dst_min, pkt_dev->dst_max);
577 seq_printf(seq,
578 " src_min: %s src_max: %s\n",
579 pkt_dev->src_min, pkt_dev->src_max);
580 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700582 seq_puts(seq, " src_mac: ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Johannes Berge1749612008-10-27 15:59:26 -0700584 seq_printf(seq, "%pM ",
585 is_zero_ether_addr(pkt_dev->src_mac) ?
586 pkt_dev->odev->dev_addr : pkt_dev->src_mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
Luiz Capitulino222f1802006-03-20 22:16:13 -0800588 seq_printf(seq, "dst_mac: ");
Johannes Berge1749612008-10-27 15:59:26 -0700589 seq_printf(seq, "%pM\n", pkt_dev->dst_mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Luiz Capitulino222f1802006-03-20 22:16:13 -0800591 seq_printf(seq,
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000592 " udp_src_min: %d udp_src_max: %d"
593 " udp_dst_min: %d udp_dst_max: %d\n",
Luiz Capitulino222f1802006-03-20 22:16:13 -0800594 pkt_dev->udp_src_min, pkt_dev->udp_src_max,
595 pkt_dev->udp_dst_min, pkt_dev->udp_dst_max);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Luiz Capitulino222f1802006-03-20 22:16:13 -0800597 seq_printf(seq,
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800598 " src_mac_count: %d dst_mac_count: %d\n",
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700599 pkt_dev->src_mac_count, pkt_dev->dst_mac_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800601 if (pkt_dev->nr_labels) {
602 unsigned i;
603 seq_printf(seq, " mpls: ");
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700604 for (i = 0; i < pkt_dev->nr_labels; i++)
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800605 seq_printf(seq, "%08x%s", ntohl(pkt_dev->labels[i]),
606 i == pkt_dev->nr_labels-1 ? "\n" : ", ");
607 }
608
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000609 if (pkt_dev->vlan_id != 0xffff)
Francesco Fondelli34954dd2006-09-27 16:30:44 -0700610 seq_printf(seq, " vlan_id: %u vlan_p: %u vlan_cfi: %u\n",
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000611 pkt_dev->vlan_id, pkt_dev->vlan_p,
612 pkt_dev->vlan_cfi);
Francesco Fondelli34954dd2006-09-27 16:30:44 -0700613
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000614 if (pkt_dev->svlan_id != 0xffff)
Francesco Fondelli34954dd2006-09-27 16:30:44 -0700615 seq_printf(seq, " svlan_id: %u vlan_p: %u vlan_cfi: %u\n",
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000616 pkt_dev->svlan_id, pkt_dev->svlan_p,
617 pkt_dev->svlan_cfi);
Francesco Fondelli34954dd2006-09-27 16:30:44 -0700618
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000619 if (pkt_dev->tos)
Francesco Fondelli1ca77682006-09-27 16:32:03 -0700620 seq_printf(seq, " tos: 0x%02x\n", pkt_dev->tos);
Francesco Fondelli1ca77682006-09-27 16:32:03 -0700621
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000622 if (pkt_dev->traffic_class)
Francesco Fondelli1ca77682006-09-27 16:32:03 -0700623 seq_printf(seq, " traffic_class: 0x%02x\n", pkt_dev->traffic_class);
Francesco Fondelli1ca77682006-09-27 16:32:03 -0700624
Robert Olssone99b99b2010-03-18 22:44:30 +0000625 if (pkt_dev->node >= 0)
626 seq_printf(seq, " node: %d\n", pkt_dev->node);
627
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800628 seq_printf(seq, " Flags: ");
629
Luiz Capitulino222f1802006-03-20 22:16:13 -0800630 if (pkt_dev->flags & F_IPV6)
631 seq_printf(seq, "IPV6 ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
Luiz Capitulino222f1802006-03-20 22:16:13 -0800633 if (pkt_dev->flags & F_IPSRC_RND)
634 seq_printf(seq, "IPSRC_RND ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
Luiz Capitulino222f1802006-03-20 22:16:13 -0800636 if (pkt_dev->flags & F_IPDST_RND)
637 seq_printf(seq, "IPDST_RND ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Luiz Capitulino222f1802006-03-20 22:16:13 -0800639 if (pkt_dev->flags & F_TXSIZE_RND)
640 seq_printf(seq, "TXSIZE_RND ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
Luiz Capitulino222f1802006-03-20 22:16:13 -0800642 if (pkt_dev->flags & F_UDPSRC_RND)
643 seq_printf(seq, "UDPSRC_RND ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
Luiz Capitulino222f1802006-03-20 22:16:13 -0800645 if (pkt_dev->flags & F_UDPDST_RND)
646 seq_printf(seq, "UDPDST_RND ");
647
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800648 if (pkt_dev->flags & F_MPLS_RND)
649 seq_printf(seq, "MPLS_RND ");
650
Robert Olsson45b270f2007-08-28 15:45:55 -0700651 if (pkt_dev->flags & F_QUEUE_MAP_RND)
652 seq_printf(seq, "QUEUE_MAP_RND ");
653
Robert Olssone6fce5b2008-08-07 02:23:01 -0700654 if (pkt_dev->flags & F_QUEUE_MAP_CPU)
655 seq_printf(seq, "QUEUE_MAP_CPU ");
656
Jamal Hadi Salim007a5312007-07-02 22:40:36 -0700657 if (pkt_dev->cflows) {
658 if (pkt_dev->flags & F_FLOW_SEQ)
659 seq_printf(seq, "FLOW_SEQ "); /*in sequence flows*/
660 else
661 seq_printf(seq, "FLOW_RND ");
662 }
663
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -0700664#ifdef CONFIG_XFRM
665 if (pkt_dev->flags & F_IPSEC_ON)
666 seq_printf(seq, "IPSEC ");
667#endif
668
Luiz Capitulino222f1802006-03-20 22:16:13 -0800669 if (pkt_dev->flags & F_MACSRC_RND)
670 seq_printf(seq, "MACSRC_RND ");
671
672 if (pkt_dev->flags & F_MACDST_RND)
673 seq_printf(seq, "MACDST_RND ");
674
Francesco Fondelli34954dd2006-09-27 16:30:44 -0700675 if (pkt_dev->flags & F_VID_RND)
676 seq_printf(seq, "VID_RND ");
677
678 if (pkt_dev->flags & F_SVID_RND)
679 seq_printf(seq, "SVID_RND ");
680
Robert Olssone99b99b2010-03-18 22:44:30 +0000681 if (pkt_dev->flags & F_NODE)
682 seq_printf(seq, "NODE_ALLOC ");
683
Luiz Capitulino222f1802006-03-20 22:16:13 -0800684 seq_puts(seq, "\n");
685
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +0000686 /* not really stopped, more like last-running-at */
687 stopped = pkt_dev->running ? ktime_now() : pkt_dev->stopped_at;
688 idle = pkt_dev->idle_acc;
689 do_div(idle, NSEC_PER_USEC);
Luiz Capitulino222f1802006-03-20 22:16:13 -0800690
691 seq_printf(seq,
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +0000692 "Current:\n pkts-sofar: %llu errors: %llu\n",
Luiz Capitulino222f1802006-03-20 22:16:13 -0800693 (unsigned long long)pkt_dev->sofar,
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +0000694 (unsigned long long)pkt_dev->errors);
695
696 seq_printf(seq,
697 " started: %lluus stopped: %lluus idle: %lluus\n",
698 (unsigned long long) ktime_to_us(pkt_dev->started_at),
699 (unsigned long long) ktime_to_us(stopped),
700 (unsigned long long) idle);
Luiz Capitulino222f1802006-03-20 22:16:13 -0800701
702 seq_printf(seq,
703 " seq_num: %d cur_dst_mac_offset: %d cur_src_mac_offset: %d\n",
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700704 pkt_dev->seq_num, pkt_dev->cur_dst_mac_offset,
705 pkt_dev->cur_src_mac_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
Luiz Capitulino222f1802006-03-20 22:16:13 -0800707 if (pkt_dev->flags & F_IPV6) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 char b1[128], b2[128];
Luiz Capitulino222f1802006-03-20 22:16:13 -0800709 fmt_ip6(b1, pkt_dev->cur_in6_daddr.s6_addr);
710 fmt_ip6(b2, pkt_dev->cur_in6_saddr.s6_addr);
711 seq_printf(seq, " cur_saddr: %s cur_daddr: %s\n", b2, b1);
712 } else
713 seq_printf(seq, " cur_saddr: 0x%x cur_daddr: 0x%x\n",
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700714 pkt_dev->cur_saddr, pkt_dev->cur_daddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
Luiz Capitulino222f1802006-03-20 22:16:13 -0800716 seq_printf(seq, " cur_udp_dst: %d cur_udp_src: %d\n",
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700717 pkt_dev->cur_udp_dst, pkt_dev->cur_udp_src);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
Robert Olsson45b270f2007-08-28 15:45:55 -0700719 seq_printf(seq, " cur_queue_map: %u\n", pkt_dev->cur_queue_map);
720
Luiz Capitulino222f1802006-03-20 22:16:13 -0800721 seq_printf(seq, " flows: %u\n", pkt_dev->nflows);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
723 if (pkt_dev->result[0])
Luiz Capitulino222f1802006-03-20 22:16:13 -0800724 seq_printf(seq, "Result: %s\n", pkt_dev->result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 else
Luiz Capitulino222f1802006-03-20 22:16:13 -0800726 seq_printf(seq, "Result: Idle\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700728 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729}
730
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800731
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000732static int hex32_arg(const char __user *user_buffer, unsigned long maxlen,
733 __u32 *num)
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800734{
735 int i = 0;
736 *num = 0;
737
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700738 for (; i < maxlen; i++) {
Andy Shevchenko82fd5b52010-09-20 20:40:26 +0000739 int value;
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800740 char c;
741 *num <<= 4;
742 if (get_user(c, &user_buffer[i]))
743 return -EFAULT;
Andy Shevchenko82fd5b52010-09-20 20:40:26 +0000744 value = hex_to_bin(c);
745 if (value >= 0)
746 *num |= value;
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800747 else
748 break;
749 }
750 return i;
751}
752
Luiz Capitulino222f1802006-03-20 22:16:13 -0800753static int count_trail_chars(const char __user * user_buffer,
754 unsigned int maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755{
756 int i;
757
758 for (i = 0; i < maxlen; i++) {
Luiz Capitulino222f1802006-03-20 22:16:13 -0800759 char c;
760 if (get_user(c, &user_buffer[i]))
761 return -EFAULT;
762 switch (c) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 case '\"':
764 case '\n':
765 case '\r':
766 case '\t':
767 case ' ':
768 case '=':
769 break;
770 default:
771 goto done;
Stephen Hemminger3ff50b72007-04-20 17:09:22 -0700772 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 }
774done:
775 return i;
776}
777
Luiz Capitulino222f1802006-03-20 22:16:13 -0800778static unsigned long num_arg(const char __user * user_buffer,
779 unsigned long maxlen, unsigned long *num)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780{
Paul Gortmakerd6182222010-10-18 12:14:44 +0000781 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 *num = 0;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800783
Paul Gortmakerd6182222010-10-18 12:14:44 +0000784 for (i = 0; i < maxlen; i++) {
Luiz Capitulino222f1802006-03-20 22:16:13 -0800785 char c;
786 if (get_user(c, &user_buffer[i]))
787 return -EFAULT;
788 if ((c >= '0') && (c <= '9')) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 *num *= 10;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800790 *num += c - '0';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 } else
792 break;
793 }
794 return i;
795}
796
Luiz Capitulino222f1802006-03-20 22:16:13 -0800797static int strn_len(const char __user * user_buffer, unsigned int maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798{
Paul Gortmakerd6182222010-10-18 12:14:44 +0000799 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
Paul Gortmakerd6182222010-10-18 12:14:44 +0000801 for (i = 0; i < maxlen; i++) {
Luiz Capitulino222f1802006-03-20 22:16:13 -0800802 char c;
803 if (get_user(c, &user_buffer[i]))
804 return -EFAULT;
805 switch (c) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 case '\"':
807 case '\n':
808 case '\r':
809 case '\t':
810 case ' ':
811 goto done_str;
812 break;
813 default:
814 break;
Stephen Hemminger3ff50b72007-04-20 17:09:22 -0700815 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 }
817done_str:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 return i;
819}
820
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800821static ssize_t get_labels(const char __user *buffer, struct pktgen_dev *pkt_dev)
822{
823 unsigned n = 0;
824 char c;
825 ssize_t i = 0;
826 int len;
827
828 pkt_dev->nr_labels = 0;
829 do {
830 __u32 tmp;
Francesco Fondelli1ca77682006-09-27 16:32:03 -0700831 len = hex32_arg(&buffer[i], 8, &tmp);
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800832 if (len <= 0)
833 return len;
834 pkt_dev->labels[n] = htonl(tmp);
835 if (pkt_dev->labels[n] & MPLS_STACK_BOTTOM)
836 pkt_dev->flags |= F_MPLS_RND;
837 i += len;
838 if (get_user(c, &buffer[i]))
839 return -EFAULT;
840 i++;
841 n++;
842 if (n >= MAX_MPLS_LABELS)
843 return -E2BIG;
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700844 } while (c == ',');
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800845
846 pkt_dev->nr_labels = n;
847 return i;
848}
849
Luiz Capitulino222f1802006-03-20 22:16:13 -0800850static ssize_t pktgen_if_write(struct file *file,
851 const char __user * user_buffer, size_t count,
852 loff_t * offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853{
Joe Perches8a994a72010-07-12 10:50:23 +0000854 struct seq_file *seq = file->private_data;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800855 struct pktgen_dev *pkt_dev = seq->private;
Paul Gortmakerd6182222010-10-18 12:14:44 +0000856 int i, max, len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 char name[16], valstr[32];
858 unsigned long value = 0;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800859 char *pg_result = NULL;
860 int tmp = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 char buf[128];
Luiz Capitulino222f1802006-03-20 22:16:13 -0800862
863 pg_result = &(pkt_dev->result[0]);
864
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 if (count < 1) {
Joe Perchesf9467ea2010-06-21 12:29:14 +0000866 pr_warning("wrong command format\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 return -EINVAL;
868 }
Luiz Capitulino222f1802006-03-20 22:16:13 -0800869
Paul Gortmakerd6182222010-10-18 12:14:44 +0000870 max = count;
871 tmp = count_trail_chars(user_buffer, max);
Luiz Capitulino222f1802006-03-20 22:16:13 -0800872 if (tmp < 0) {
Joe Perchesf9467ea2010-06-21 12:29:14 +0000873 pr_warning("illegal format\n");
Luiz Capitulino222f1802006-03-20 22:16:13 -0800874 return tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 }
Paul Gortmakerd6182222010-10-18 12:14:44 +0000876 i = tmp;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800877
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 /* Read variable name */
879
880 len = strn_len(&user_buffer[i], sizeof(name) - 1);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000881 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -0800882 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000883
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 memset(name, 0, sizeof(name));
Luiz Capitulino222f1802006-03-20 22:16:13 -0800885 if (copy_from_user(name, &user_buffer[i], len))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 return -EFAULT;
887 i += len;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800888
889 max = count - i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 len = count_trail_chars(&user_buffer[i], max);
Luiz Capitulino222f1802006-03-20 22:16:13 -0800891 if (len < 0)
892 return len;
893
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 i += len;
895
896 if (debug) {
Dmitry Torokhov86c2c0a2010-11-06 20:11:38 +0000897 size_t copy = min_t(size_t, count, 1023);
Nelson Elhage448d7b52010-10-28 11:31:07 -0700898 char tb[copy + 1];
899 if (copy_from_user(tb, user_buffer, copy))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 return -EFAULT;
Nelson Elhage448d7b52010-10-28 11:31:07 -0700901 tb[copy] = 0;
David S. Miller25a8b252007-07-30 16:11:48 -0700902 printk(KERN_DEBUG "pktgen: %s,%lu buffer -:%s:-\n", name,
Luiz Capitulino222f1802006-03-20 22:16:13 -0800903 (unsigned long)count, tb);
904 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
906 if (!strcmp(name, "min_pkt_size")) {
907 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000908 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -0800909 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000910
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 i += len;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800912 if (value < 14 + 20 + 8)
913 value = 14 + 20 + 8;
914 if (value != pkt_dev->min_pkt_size) {
915 pkt_dev->min_pkt_size = value;
916 pkt_dev->cur_pkt_size = value;
917 }
918 sprintf(pg_result, "OK: min_pkt_size=%u",
919 pkt_dev->min_pkt_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 return count;
921 }
922
Luiz Capitulino222f1802006-03-20 22:16:13 -0800923 if (!strcmp(name, "max_pkt_size")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000925 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -0800926 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000927
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 i += len;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800929 if (value < 14 + 20 + 8)
930 value = 14 + 20 + 8;
931 if (value != pkt_dev->max_pkt_size) {
932 pkt_dev->max_pkt_size = value;
933 pkt_dev->cur_pkt_size = value;
934 }
935 sprintf(pg_result, "OK: max_pkt_size=%u",
936 pkt_dev->max_pkt_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 return count;
938 }
939
Luiz Capitulino222f1802006-03-20 22:16:13 -0800940 /* Shortcut for min = max */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
942 if (!strcmp(name, "pkt_size")) {
943 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000944 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -0800945 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000946
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 i += len;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800948 if (value < 14 + 20 + 8)
949 value = 14 + 20 + 8;
950 if (value != pkt_dev->min_pkt_size) {
951 pkt_dev->min_pkt_size = value;
952 pkt_dev->max_pkt_size = value;
953 pkt_dev->cur_pkt_size = value;
954 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 sprintf(pg_result, "OK: pkt_size=%u", pkt_dev->min_pkt_size);
956 return count;
957 }
958
Luiz Capitulino222f1802006-03-20 22:16:13 -0800959 if (!strcmp(name, "debug")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000961 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -0800962 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000963
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 i += len;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800965 debug = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 sprintf(pg_result, "OK: debug=%u", debug);
967 return count;
968 }
969
Luiz Capitulino222f1802006-03-20 22:16:13 -0800970 if (!strcmp(name, "frags")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000972 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -0800973 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000974
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 i += len;
976 pkt_dev->nfrags = value;
977 sprintf(pg_result, "OK: frags=%u", pkt_dev->nfrags);
978 return count;
979 }
980 if (!strcmp(name, "delay")) {
981 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000982 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -0800983 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000984
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 i += len;
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +0000986 if (value == 0x7FFFFFFF)
987 pkt_dev->delay = ULLONG_MAX;
988 else
Eric Dumazet9240d712009-10-03 01:39:18 +0000989 pkt_dev->delay = (u64)value;
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +0000990
991 sprintf(pg_result, "OK: delay=%llu",
992 (unsigned long long) pkt_dev->delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 return count;
994 }
Daniel Turull43d28b62010-06-09 22:49:57 +0000995 if (!strcmp(name, "rate")) {
996 len = num_arg(&user_buffer[i], 10, &value);
997 if (len < 0)
998 return len;
999
1000 i += len;
1001 if (!value)
1002 return len;
1003 pkt_dev->delay = pkt_dev->min_pkt_size*8*NSEC_PER_USEC/value;
1004 if (debug)
Joe Perchesf9467ea2010-06-21 12:29:14 +00001005 pr_info("Delay set at: %llu ns\n", pkt_dev->delay);
Daniel Turull43d28b62010-06-09 22:49:57 +00001006
1007 sprintf(pg_result, "OK: rate=%lu", value);
1008 return count;
1009 }
1010 if (!strcmp(name, "ratep")) {
1011 len = num_arg(&user_buffer[i], 10, &value);
1012 if (len < 0)
1013 return len;
1014
1015 i += len;
1016 if (!value)
1017 return len;
1018 pkt_dev->delay = NSEC_PER_SEC/value;
1019 if (debug)
Joe Perchesf9467ea2010-06-21 12:29:14 +00001020 pr_info("Delay set at: %llu ns\n", pkt_dev->delay);
Daniel Turull43d28b62010-06-09 22:49:57 +00001021
1022 sprintf(pg_result, "OK: rate=%lu", value);
1023 return count;
1024 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08001025 if (!strcmp(name, "udp_src_min")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001027 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001028 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001029
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 i += len;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001031 if (value != pkt_dev->udp_src_min) {
1032 pkt_dev->udp_src_min = value;
1033 pkt_dev->cur_udp_src = value;
1034 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 sprintf(pg_result, "OK: udp_src_min=%u", pkt_dev->udp_src_min);
1036 return count;
1037 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08001038 if (!strcmp(name, "udp_dst_min")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001040 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001041 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001042
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 i += len;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001044 if (value != pkt_dev->udp_dst_min) {
1045 pkt_dev->udp_dst_min = value;
1046 pkt_dev->cur_udp_dst = value;
1047 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 sprintf(pg_result, "OK: udp_dst_min=%u", pkt_dev->udp_dst_min);
1049 return count;
1050 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08001051 if (!strcmp(name, "udp_src_max")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001053 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001054 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001055
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 i += len;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001057 if (value != pkt_dev->udp_src_max) {
1058 pkt_dev->udp_src_max = value;
1059 pkt_dev->cur_udp_src = value;
1060 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 sprintf(pg_result, "OK: udp_src_max=%u", pkt_dev->udp_src_max);
1062 return count;
1063 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08001064 if (!strcmp(name, "udp_dst_max")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001066 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001067 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001068
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 i += len;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001070 if (value != pkt_dev->udp_dst_max) {
1071 pkt_dev->udp_dst_max = value;
1072 pkt_dev->cur_udp_dst = value;
1073 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 sprintf(pg_result, "OK: udp_dst_max=%u", pkt_dev->udp_dst_max);
1075 return count;
1076 }
1077 if (!strcmp(name, "clone_skb")) {
1078 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001079 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001080 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001081
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 i += len;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001083 pkt_dev->clone_skb = value;
1084
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 sprintf(pg_result, "OK: clone_skb=%d", pkt_dev->clone_skb);
1086 return count;
1087 }
1088 if (!strcmp(name, "count")) {
1089 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001090 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001091 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001092
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 i += len;
1094 pkt_dev->count = value;
1095 sprintf(pg_result, "OK: count=%llu",
Luiz Capitulino222f1802006-03-20 22:16:13 -08001096 (unsigned long long)pkt_dev->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 return count;
1098 }
1099 if (!strcmp(name, "src_mac_count")) {
1100 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001101 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001102 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001103
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 i += len;
1105 if (pkt_dev->src_mac_count != value) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08001106 pkt_dev->src_mac_count = value;
1107 pkt_dev->cur_src_mac_offset = 0;
1108 }
1109 sprintf(pg_result, "OK: src_mac_count=%d",
1110 pkt_dev->src_mac_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 return count;
1112 }
1113 if (!strcmp(name, "dst_mac_count")) {
1114 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001115 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001116 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001117
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 i += len;
1119 if (pkt_dev->dst_mac_count != value) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08001120 pkt_dev->dst_mac_count = value;
1121 pkt_dev->cur_dst_mac_offset = 0;
1122 }
1123 sprintf(pg_result, "OK: dst_mac_count=%d",
1124 pkt_dev->dst_mac_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 return count;
1126 }
Robert Olssone99b99b2010-03-18 22:44:30 +00001127 if (!strcmp(name, "node")) {
1128 len = num_arg(&user_buffer[i], 10, &value);
1129 if (len < 0)
1130 return len;
1131
1132 i += len;
1133
1134 if (node_possible(value)) {
1135 pkt_dev->node = value;
1136 sprintf(pg_result, "OK: node=%d", pkt_dev->node);
1137 }
1138 else
1139 sprintf(pg_result, "ERROR: node not possible");
1140 return count;
1141 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 if (!strcmp(name, "flag")) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08001143 char f[32];
1144 memset(f, 0, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 len = strn_len(&user_buffer[i], sizeof(f) - 1);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001146 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001147 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001148
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 if (copy_from_user(f, &user_buffer[i], len))
1150 return -EFAULT;
1151 i += len;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001152 if (strcmp(f, "IPSRC_RND") == 0)
1153 pkt_dev->flags |= F_IPSRC_RND;
1154
1155 else if (strcmp(f, "!IPSRC_RND") == 0)
1156 pkt_dev->flags &= ~F_IPSRC_RND;
1157
1158 else if (strcmp(f, "TXSIZE_RND") == 0)
1159 pkt_dev->flags |= F_TXSIZE_RND;
1160
1161 else if (strcmp(f, "!TXSIZE_RND") == 0)
1162 pkt_dev->flags &= ~F_TXSIZE_RND;
1163
1164 else if (strcmp(f, "IPDST_RND") == 0)
1165 pkt_dev->flags |= F_IPDST_RND;
1166
1167 else if (strcmp(f, "!IPDST_RND") == 0)
1168 pkt_dev->flags &= ~F_IPDST_RND;
1169
1170 else if (strcmp(f, "UDPSRC_RND") == 0)
1171 pkt_dev->flags |= F_UDPSRC_RND;
1172
1173 else if (strcmp(f, "!UDPSRC_RND") == 0)
1174 pkt_dev->flags &= ~F_UDPSRC_RND;
1175
1176 else if (strcmp(f, "UDPDST_RND") == 0)
1177 pkt_dev->flags |= F_UDPDST_RND;
1178
1179 else if (strcmp(f, "!UDPDST_RND") == 0)
1180 pkt_dev->flags &= ~F_UDPDST_RND;
1181
1182 else if (strcmp(f, "MACSRC_RND") == 0)
1183 pkt_dev->flags |= F_MACSRC_RND;
1184
1185 else if (strcmp(f, "!MACSRC_RND") == 0)
1186 pkt_dev->flags &= ~F_MACSRC_RND;
1187
1188 else if (strcmp(f, "MACDST_RND") == 0)
1189 pkt_dev->flags |= F_MACDST_RND;
1190
1191 else if (strcmp(f, "!MACDST_RND") == 0)
1192 pkt_dev->flags &= ~F_MACDST_RND;
1193
Steven Whitehouseca6549a2006-03-23 01:10:26 -08001194 else if (strcmp(f, "MPLS_RND") == 0)
1195 pkt_dev->flags |= F_MPLS_RND;
1196
1197 else if (strcmp(f, "!MPLS_RND") == 0)
1198 pkt_dev->flags &= ~F_MPLS_RND;
1199
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001200 else if (strcmp(f, "VID_RND") == 0)
1201 pkt_dev->flags |= F_VID_RND;
1202
1203 else if (strcmp(f, "!VID_RND") == 0)
1204 pkt_dev->flags &= ~F_VID_RND;
1205
1206 else if (strcmp(f, "SVID_RND") == 0)
1207 pkt_dev->flags |= F_SVID_RND;
1208
1209 else if (strcmp(f, "!SVID_RND") == 0)
1210 pkt_dev->flags &= ~F_SVID_RND;
1211
Jamal Hadi Salim007a5312007-07-02 22:40:36 -07001212 else if (strcmp(f, "FLOW_SEQ") == 0)
1213 pkt_dev->flags |= F_FLOW_SEQ;
1214
Robert Olsson45b270f2007-08-28 15:45:55 -07001215 else if (strcmp(f, "QUEUE_MAP_RND") == 0)
1216 pkt_dev->flags |= F_QUEUE_MAP_RND;
1217
1218 else if (strcmp(f, "!QUEUE_MAP_RND") == 0)
1219 pkt_dev->flags &= ~F_QUEUE_MAP_RND;
Robert Olssone6fce5b2008-08-07 02:23:01 -07001220
1221 else if (strcmp(f, "QUEUE_MAP_CPU") == 0)
1222 pkt_dev->flags |= F_QUEUE_MAP_CPU;
1223
1224 else if (strcmp(f, "!QUEUE_MAP_CPU") == 0)
1225 pkt_dev->flags &= ~F_QUEUE_MAP_CPU;
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07001226#ifdef CONFIG_XFRM
1227 else if (strcmp(f, "IPSEC") == 0)
1228 pkt_dev->flags |= F_IPSEC_ON;
1229#endif
1230
Francesco Fondelli1ca77682006-09-27 16:32:03 -07001231 else if (strcmp(f, "!IPV6") == 0)
1232 pkt_dev->flags &= ~F_IPV6;
1233
Robert Olssone99b99b2010-03-18 22:44:30 +00001234 else if (strcmp(f, "NODE_ALLOC") == 0)
1235 pkt_dev->flags |= F_NODE;
1236
1237 else if (strcmp(f, "!NODE_ALLOC") == 0)
1238 pkt_dev->flags &= ~F_NODE;
1239
Luiz Capitulino222f1802006-03-20 22:16:13 -08001240 else {
1241 sprintf(pg_result,
1242 "Flag -:%s:- unknown\nAvailable flags, (prepend ! to un-set flag):\n%s",
1243 f,
Francesco Fondelli1ca77682006-09-27 16:32:03 -07001244 "IPSRC_RND, IPDST_RND, UDPSRC_RND, UDPDST_RND, "
Robert Olssone99b99b2010-03-18 22:44:30 +00001245 "MACSRC_RND, MACDST_RND, TXSIZE_RND, IPV6, MPLS_RND, VID_RND, SVID_RND, FLOW_SEQ, IPSEC, NODE_ALLOC\n");
Luiz Capitulino222f1802006-03-20 22:16:13 -08001246 return count;
1247 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 sprintf(pg_result, "OK: flags=0x%x", pkt_dev->flags);
1249 return count;
1250 }
1251 if (!strcmp(name, "dst_min") || !strcmp(name, "dst")) {
1252 len = strn_len(&user_buffer[i], sizeof(pkt_dev->dst_min) - 1);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001253 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001254 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255
Luiz Capitulino222f1802006-03-20 22:16:13 -08001256 if (copy_from_user(buf, &user_buffer[i], len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 return -EFAULT;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001258 buf[len] = 0;
1259 if (strcmp(buf, pkt_dev->dst_min) != 0) {
1260 memset(pkt_dev->dst_min, 0, sizeof(pkt_dev->dst_min));
1261 strncpy(pkt_dev->dst_min, buf, len);
1262 pkt_dev->daddr_min = in_aton(pkt_dev->dst_min);
1263 pkt_dev->cur_daddr = pkt_dev->daddr_min;
1264 }
1265 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001266 printk(KERN_DEBUG "pktgen: dst_min set to: %s\n",
Luiz Capitulino222f1802006-03-20 22:16:13 -08001267 pkt_dev->dst_min);
1268 i += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 sprintf(pg_result, "OK: dst_min=%s", pkt_dev->dst_min);
1270 return count;
1271 }
1272 if (!strcmp(name, "dst_max")) {
1273 len = strn_len(&user_buffer[i], sizeof(pkt_dev->dst_max) - 1);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001274 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001275 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001276
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277
Luiz Capitulino222f1802006-03-20 22:16:13 -08001278 if (copy_from_user(buf, &user_buffer[i], len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 return -EFAULT;
1280
Luiz Capitulino222f1802006-03-20 22:16:13 -08001281 buf[len] = 0;
1282 if (strcmp(buf, pkt_dev->dst_max) != 0) {
1283 memset(pkt_dev->dst_max, 0, sizeof(pkt_dev->dst_max));
1284 strncpy(pkt_dev->dst_max, buf, len);
1285 pkt_dev->daddr_max = in_aton(pkt_dev->dst_max);
1286 pkt_dev->cur_daddr = pkt_dev->daddr_max;
1287 }
1288 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001289 printk(KERN_DEBUG "pktgen: dst_max set to: %s\n",
Luiz Capitulino222f1802006-03-20 22:16:13 -08001290 pkt_dev->dst_max);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 i += len;
1292 sprintf(pg_result, "OK: dst_max=%s", pkt_dev->dst_max);
1293 return count;
1294 }
1295 if (!strcmp(name, "dst6")) {
1296 len = strn_len(&user_buffer[i], sizeof(buf) - 1);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001297 if (len < 0)
1298 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299
1300 pkt_dev->flags |= F_IPV6;
1301
Luiz Capitulino222f1802006-03-20 22:16:13 -08001302 if (copy_from_user(buf, &user_buffer[i], len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 return -EFAULT;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001304 buf[len] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305
1306 scan_ip6(buf, pkt_dev->in6_daddr.s6_addr);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001307 fmt_ip6(buf, pkt_dev->in6_daddr.s6_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308
1309 ipv6_addr_copy(&pkt_dev->cur_in6_daddr, &pkt_dev->in6_daddr);
1310
Luiz Capitulino222f1802006-03-20 22:16:13 -08001311 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001312 printk(KERN_DEBUG "pktgen: dst6 set to: %s\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313
Luiz Capitulino222f1802006-03-20 22:16:13 -08001314 i += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 sprintf(pg_result, "OK: dst6=%s", buf);
1316 return count;
1317 }
1318 if (!strcmp(name, "dst6_min")) {
1319 len = strn_len(&user_buffer[i], sizeof(buf) - 1);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001320 if (len < 0)
1321 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322
1323 pkt_dev->flags |= F_IPV6;
1324
Luiz Capitulino222f1802006-03-20 22:16:13 -08001325 if (copy_from_user(buf, &user_buffer[i], len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 return -EFAULT;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001327 buf[len] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328
1329 scan_ip6(buf, pkt_dev->min_in6_daddr.s6_addr);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001330 fmt_ip6(buf, pkt_dev->min_in6_daddr.s6_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
Luiz Capitulino222f1802006-03-20 22:16:13 -08001332 ipv6_addr_copy(&pkt_dev->cur_in6_daddr,
1333 &pkt_dev->min_in6_daddr);
1334 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001335 printk(KERN_DEBUG "pktgen: dst6_min set to: %s\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
Luiz Capitulino222f1802006-03-20 22:16:13 -08001337 i += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 sprintf(pg_result, "OK: dst6_min=%s", buf);
1339 return count;
1340 }
1341 if (!strcmp(name, "dst6_max")) {
1342 len = strn_len(&user_buffer[i], sizeof(buf) - 1);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001343 if (len < 0)
1344 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
1346 pkt_dev->flags |= F_IPV6;
1347
Luiz Capitulino222f1802006-03-20 22:16:13 -08001348 if (copy_from_user(buf, &user_buffer[i], len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 return -EFAULT;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001350 buf[len] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351
1352 scan_ip6(buf, pkt_dev->max_in6_daddr.s6_addr);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001353 fmt_ip6(buf, pkt_dev->max_in6_daddr.s6_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
Luiz Capitulino222f1802006-03-20 22:16:13 -08001355 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001356 printk(KERN_DEBUG "pktgen: dst6_max set to: %s\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
Luiz Capitulino222f1802006-03-20 22:16:13 -08001358 i += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 sprintf(pg_result, "OK: dst6_max=%s", buf);
1360 return count;
1361 }
1362 if (!strcmp(name, "src6")) {
1363 len = strn_len(&user_buffer[i], sizeof(buf) - 1);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001364 if (len < 0)
1365 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
1367 pkt_dev->flags |= F_IPV6;
1368
Luiz Capitulino222f1802006-03-20 22:16:13 -08001369 if (copy_from_user(buf, &user_buffer[i], len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 return -EFAULT;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001371 buf[len] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372
1373 scan_ip6(buf, pkt_dev->in6_saddr.s6_addr);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001374 fmt_ip6(buf, pkt_dev->in6_saddr.s6_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375
1376 ipv6_addr_copy(&pkt_dev->cur_in6_saddr, &pkt_dev->in6_saddr);
1377
Luiz Capitulino222f1802006-03-20 22:16:13 -08001378 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001379 printk(KERN_DEBUG "pktgen: src6 set to: %s\n", buf);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001380
1381 i += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 sprintf(pg_result, "OK: src6=%s", buf);
1383 return count;
1384 }
1385 if (!strcmp(name, "src_min")) {
1386 len = strn_len(&user_buffer[i], sizeof(pkt_dev->src_min) - 1);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001387 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001388 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001389
Luiz Capitulino222f1802006-03-20 22:16:13 -08001390 if (copy_from_user(buf, &user_buffer[i], len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 return -EFAULT;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001392 buf[len] = 0;
1393 if (strcmp(buf, pkt_dev->src_min) != 0) {
1394 memset(pkt_dev->src_min, 0, sizeof(pkt_dev->src_min));
1395 strncpy(pkt_dev->src_min, buf, len);
1396 pkt_dev->saddr_min = in_aton(pkt_dev->src_min);
1397 pkt_dev->cur_saddr = pkt_dev->saddr_min;
1398 }
1399 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001400 printk(KERN_DEBUG "pktgen: src_min set to: %s\n",
Luiz Capitulino222f1802006-03-20 22:16:13 -08001401 pkt_dev->src_min);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 i += len;
1403 sprintf(pg_result, "OK: src_min=%s", pkt_dev->src_min);
1404 return count;
1405 }
1406 if (!strcmp(name, "src_max")) {
1407 len = strn_len(&user_buffer[i], sizeof(pkt_dev->src_max) - 1);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001408 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001409 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001410
Luiz Capitulino222f1802006-03-20 22:16:13 -08001411 if (copy_from_user(buf, &user_buffer[i], len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 return -EFAULT;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001413 buf[len] = 0;
1414 if (strcmp(buf, pkt_dev->src_max) != 0) {
1415 memset(pkt_dev->src_max, 0, sizeof(pkt_dev->src_max));
1416 strncpy(pkt_dev->src_max, buf, len);
1417 pkt_dev->saddr_max = in_aton(pkt_dev->src_max);
1418 pkt_dev->cur_saddr = pkt_dev->saddr_max;
1419 }
1420 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001421 printk(KERN_DEBUG "pktgen: src_max set to: %s\n",
Luiz Capitulino222f1802006-03-20 22:16:13 -08001422 pkt_dev->src_max);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 i += len;
1424 sprintf(pg_result, "OK: src_max=%s", pkt_dev->src_max);
1425 return count;
1426 }
1427 if (!strcmp(name, "dst_mac")) {
1428 char *v = valstr;
Kris Katterjohnf404e9a2006-01-17 13:04:57 -08001429 unsigned char old_dmac[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 unsigned char *m = pkt_dev->dst_mac;
Kris Katterjohnf404e9a2006-01-17 13:04:57 -08001431 memcpy(old_dmac, pkt_dev->dst_mac, ETH_ALEN);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001432
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 len = strn_len(&user_buffer[i], sizeof(valstr) - 1);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001434 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001435 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001436
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 memset(valstr, 0, sizeof(valstr));
Luiz Capitulino222f1802006-03-20 22:16:13 -08001438 if (copy_from_user(valstr, &user_buffer[i], len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 return -EFAULT;
1440 i += len;
1441
Luiz Capitulino222f1802006-03-20 22:16:13 -08001442 for (*m = 0; *v && m < pkt_dev->dst_mac + 6; v++) {
Andy Shevchenko451e07a2010-07-23 03:18:10 +00001443 int value;
1444
1445 value = hex_to_bin(*v);
1446 if (value >= 0)
1447 *m = *m * 16 + value;
1448
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 if (*v == ':') {
1450 m++;
1451 *m = 0;
1452 }
1453 }
1454
1455 /* Set up Dest MAC */
Kris Katterjohnf404e9a2006-01-17 13:04:57 -08001456 if (compare_ether_addr(old_dmac, pkt_dev->dst_mac))
1457 memcpy(&(pkt_dev->hh[0]), pkt_dev->dst_mac, ETH_ALEN);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001458
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 sprintf(pg_result, "OK: dstmac");
1460 return count;
1461 }
1462 if (!strcmp(name, "src_mac")) {
1463 char *v = valstr;
Adit Ranadivece5d0b42007-09-16 14:52:15 -07001464 unsigned char old_smac[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 unsigned char *m = pkt_dev->src_mac;
1466
Adit Ranadivece5d0b42007-09-16 14:52:15 -07001467 memcpy(old_smac, pkt_dev->src_mac, ETH_ALEN);
1468
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 len = strn_len(&user_buffer[i], sizeof(valstr) - 1);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001470 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001471 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001472
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 memset(valstr, 0, sizeof(valstr));
Luiz Capitulino222f1802006-03-20 22:16:13 -08001474 if (copy_from_user(valstr, &user_buffer[i], len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 return -EFAULT;
1476 i += len;
1477
Luiz Capitulino222f1802006-03-20 22:16:13 -08001478 for (*m = 0; *v && m < pkt_dev->src_mac + 6; v++) {
Andy Shevchenko451e07a2010-07-23 03:18:10 +00001479 int value;
1480
1481 value = hex_to_bin(*v);
1482 if (value >= 0)
1483 *m = *m * 16 + value;
1484
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 if (*v == ':') {
1486 m++;
1487 *m = 0;
1488 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08001489 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490
Adit Ranadivece5d0b42007-09-16 14:52:15 -07001491 /* Set up Src MAC */
1492 if (compare_ether_addr(old_smac, pkt_dev->src_mac))
1493 memcpy(&(pkt_dev->hh[6]), pkt_dev->src_mac, ETH_ALEN);
1494
Luiz Capitulino222f1802006-03-20 22:16:13 -08001495 sprintf(pg_result, "OK: srcmac");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 return count;
1497 }
1498
Luiz Capitulino222f1802006-03-20 22:16:13 -08001499 if (!strcmp(name, "clear_counters")) {
1500 pktgen_clear_counters(pkt_dev);
1501 sprintf(pg_result, "OK: Clearing counters.\n");
1502 return count;
1503 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504
1505 if (!strcmp(name, "flows")) {
1506 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001507 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001508 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001509
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 i += len;
1511 if (value > MAX_CFLOWS)
1512 value = MAX_CFLOWS;
1513
1514 pkt_dev->cflows = value;
1515 sprintf(pg_result, "OK: flows=%u", pkt_dev->cflows);
1516 return count;
1517 }
1518
1519 if (!strcmp(name, "flowlen")) {
1520 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001521 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001522 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001523
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 i += len;
1525 pkt_dev->lflow = value;
1526 sprintf(pg_result, "OK: flowlen=%u", pkt_dev->lflow);
1527 return count;
1528 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08001529
Robert Olsson45b270f2007-08-28 15:45:55 -07001530 if (!strcmp(name, "queue_map_min")) {
1531 len = num_arg(&user_buffer[i], 5, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001532 if (len < 0)
Robert Olsson45b270f2007-08-28 15:45:55 -07001533 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001534
Robert Olsson45b270f2007-08-28 15:45:55 -07001535 i += len;
1536 pkt_dev->queue_map_min = value;
1537 sprintf(pg_result, "OK: queue_map_min=%u", pkt_dev->queue_map_min);
1538 return count;
1539 }
1540
1541 if (!strcmp(name, "queue_map_max")) {
1542 len = num_arg(&user_buffer[i], 5, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001543 if (len < 0)
Robert Olsson45b270f2007-08-28 15:45:55 -07001544 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001545
Robert Olsson45b270f2007-08-28 15:45:55 -07001546 i += len;
1547 pkt_dev->queue_map_max = value;
1548 sprintf(pg_result, "OK: queue_map_max=%u", pkt_dev->queue_map_max);
1549 return count;
1550 }
1551
Steven Whitehouseca6549a2006-03-23 01:10:26 -08001552 if (!strcmp(name, "mpls")) {
Stephen Hemmingercfcabdc2007-10-09 01:59:42 -07001553 unsigned n, cnt;
1554
Steven Whitehouseca6549a2006-03-23 01:10:26 -08001555 len = get_labels(&user_buffer[i], pkt_dev);
Stephen Hemmingercfcabdc2007-10-09 01:59:42 -07001556 if (len < 0)
1557 return len;
Steven Whitehouseca6549a2006-03-23 01:10:26 -08001558 i += len;
Stephen Hemmingercfcabdc2007-10-09 01:59:42 -07001559 cnt = sprintf(pg_result, "OK: mpls=");
Stephen Hemmingere71a4782007-04-10 20:10:33 -07001560 for (n = 0; n < pkt_dev->nr_labels; n++)
Stephen Hemmingercfcabdc2007-10-09 01:59:42 -07001561 cnt += sprintf(pg_result + cnt,
1562 "%08x%s", ntohl(pkt_dev->labels[n]),
1563 n == pkt_dev->nr_labels-1 ? "" : ",");
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001564
1565 if (pkt_dev->nr_labels && pkt_dev->vlan_id != 0xffff) {
1566 pkt_dev->vlan_id = 0xffff; /* turn off VLAN/SVLAN */
1567 pkt_dev->svlan_id = 0xffff;
1568
1569 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001570 printk(KERN_DEBUG "pktgen: VLAN/SVLAN auto turned off\n");
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001571 }
1572 return count;
1573 }
1574
1575 if (!strcmp(name, "vlan_id")) {
1576 len = num_arg(&user_buffer[i], 4, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001577 if (len < 0)
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001578 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001579
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001580 i += len;
1581 if (value <= 4095) {
1582 pkt_dev->vlan_id = value; /* turn on VLAN */
1583
1584 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001585 printk(KERN_DEBUG "pktgen: VLAN turned on\n");
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001586
1587 if (debug && pkt_dev->nr_labels)
David S. Miller25a8b252007-07-30 16:11:48 -07001588 printk(KERN_DEBUG "pktgen: MPLS auto turned off\n");
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001589
1590 pkt_dev->nr_labels = 0; /* turn off MPLS */
1591 sprintf(pg_result, "OK: vlan_id=%u", pkt_dev->vlan_id);
1592 } else {
1593 pkt_dev->vlan_id = 0xffff; /* turn off VLAN/SVLAN */
1594 pkt_dev->svlan_id = 0xffff;
1595
1596 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001597 printk(KERN_DEBUG "pktgen: VLAN/SVLAN turned off\n");
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001598 }
1599 return count;
1600 }
1601
1602 if (!strcmp(name, "vlan_p")) {
1603 len = num_arg(&user_buffer[i], 1, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001604 if (len < 0)
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001605 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001606
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001607 i += len;
1608 if ((value <= 7) && (pkt_dev->vlan_id != 0xffff)) {
1609 pkt_dev->vlan_p = value;
1610 sprintf(pg_result, "OK: vlan_p=%u", pkt_dev->vlan_p);
1611 } else {
1612 sprintf(pg_result, "ERROR: vlan_p must be 0-7");
1613 }
1614 return count;
1615 }
1616
1617 if (!strcmp(name, "vlan_cfi")) {
1618 len = num_arg(&user_buffer[i], 1, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001619 if (len < 0)
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001620 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001621
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001622 i += len;
1623 if ((value <= 1) && (pkt_dev->vlan_id != 0xffff)) {
1624 pkt_dev->vlan_cfi = value;
1625 sprintf(pg_result, "OK: vlan_cfi=%u", pkt_dev->vlan_cfi);
1626 } else {
1627 sprintf(pg_result, "ERROR: vlan_cfi must be 0-1");
1628 }
1629 return count;
1630 }
1631
1632 if (!strcmp(name, "svlan_id")) {
1633 len = num_arg(&user_buffer[i], 4, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001634 if (len < 0)
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001635 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001636
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001637 i += len;
1638 if ((value <= 4095) && ((pkt_dev->vlan_id != 0xffff))) {
1639 pkt_dev->svlan_id = value; /* turn on SVLAN */
1640
1641 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001642 printk(KERN_DEBUG "pktgen: SVLAN turned on\n");
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001643
1644 if (debug && pkt_dev->nr_labels)
David S. Miller25a8b252007-07-30 16:11:48 -07001645 printk(KERN_DEBUG "pktgen: MPLS auto turned off\n");
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001646
1647 pkt_dev->nr_labels = 0; /* turn off MPLS */
1648 sprintf(pg_result, "OK: svlan_id=%u", pkt_dev->svlan_id);
1649 } else {
1650 pkt_dev->vlan_id = 0xffff; /* turn off VLAN/SVLAN */
1651 pkt_dev->svlan_id = 0xffff;
1652
1653 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001654 printk(KERN_DEBUG "pktgen: VLAN/SVLAN turned off\n");
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001655 }
1656 return count;
1657 }
1658
1659 if (!strcmp(name, "svlan_p")) {
1660 len = num_arg(&user_buffer[i], 1, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001661 if (len < 0)
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001662 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001663
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001664 i += len;
1665 if ((value <= 7) && (pkt_dev->svlan_id != 0xffff)) {
1666 pkt_dev->svlan_p = value;
1667 sprintf(pg_result, "OK: svlan_p=%u", pkt_dev->svlan_p);
1668 } else {
1669 sprintf(pg_result, "ERROR: svlan_p must be 0-7");
1670 }
1671 return count;
1672 }
1673
1674 if (!strcmp(name, "svlan_cfi")) {
1675 len = num_arg(&user_buffer[i], 1, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001676 if (len < 0)
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001677 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001678
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001679 i += len;
1680 if ((value <= 1) && (pkt_dev->svlan_id != 0xffff)) {
1681 pkt_dev->svlan_cfi = value;
1682 sprintf(pg_result, "OK: svlan_cfi=%u", pkt_dev->svlan_cfi);
1683 } else {
1684 sprintf(pg_result, "ERROR: svlan_cfi must be 0-1");
1685 }
Steven Whitehouseca6549a2006-03-23 01:10:26 -08001686 return count;
1687 }
1688
Francesco Fondelli1ca77682006-09-27 16:32:03 -07001689 if (!strcmp(name, "tos")) {
1690 __u32 tmp_value = 0;
1691 len = hex32_arg(&user_buffer[i], 2, &tmp_value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001692 if (len < 0)
Francesco Fondelli1ca77682006-09-27 16:32:03 -07001693 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001694
Francesco Fondelli1ca77682006-09-27 16:32:03 -07001695 i += len;
1696 if (len == 2) {
1697 pkt_dev->tos = tmp_value;
1698 sprintf(pg_result, "OK: tos=0x%02x", pkt_dev->tos);
1699 } else {
1700 sprintf(pg_result, "ERROR: tos must be 00-ff");
1701 }
1702 return count;
1703 }
1704
1705 if (!strcmp(name, "traffic_class")) {
1706 __u32 tmp_value = 0;
1707 len = hex32_arg(&user_buffer[i], 2, &tmp_value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001708 if (len < 0)
Francesco Fondelli1ca77682006-09-27 16:32:03 -07001709 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001710
Francesco Fondelli1ca77682006-09-27 16:32:03 -07001711 i += len;
1712 if (len == 2) {
1713 pkt_dev->traffic_class = tmp_value;
1714 sprintf(pg_result, "OK: traffic_class=0x%02x", pkt_dev->traffic_class);
1715 } else {
1716 sprintf(pg_result, "ERROR: traffic_class must be 00-ff");
1717 }
1718 return count;
1719 }
1720
John Fastabend9e50e3a2010-11-16 19:12:28 +00001721 if (!strcmp(name, "skb_priority")) {
1722 len = num_arg(&user_buffer[i], 9, &value);
1723 if (len < 0)
1724 return len;
1725
1726 i += len;
1727 pkt_dev->skb_priority = value;
1728 sprintf(pg_result, "OK: skb_priority=%i",
1729 pkt_dev->skb_priority);
1730 return count;
1731 }
1732
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 sprintf(pkt_dev->result, "No such parameter \"%s\"", name);
1734 return -EINVAL;
1735}
1736
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001737static int pktgen_if_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738{
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001739 return single_open(file, pktgen_if_show, PDE(inode)->data);
1740}
1741
Arjan van de Ven9a321442007-02-12 00:55:35 -08001742static const struct file_operations pktgen_if_fops = {
Luiz Capitulino222f1802006-03-20 22:16:13 -08001743 .owner = THIS_MODULE,
1744 .open = pktgen_if_open,
1745 .read = seq_read,
1746 .llseek = seq_lseek,
1747 .write = pktgen_if_write,
1748 .release = single_release,
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001749};
1750
1751static int pktgen_thread_show(struct seq_file *seq, void *v)
1752{
Luiz Capitulino222f1802006-03-20 22:16:13 -08001753 struct pktgen_thread *t = seq->private;
Stephen Hemminger648fda72009-08-27 13:55:07 +00001754 const struct pktgen_dev *pkt_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001756 BUG_ON(!t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757
Luiz Capitulino222f1802006-03-20 22:16:13 -08001758 seq_printf(seq, "Running: ");
1759
1760 if_lock(t);
Luiz Capitulinoc26a8012006-03-20 22:18:16 -08001761 list_for_each_entry(pkt_dev, &t->if_list, list)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001762 if (pkt_dev->running)
Eric Dumazet593f63b2009-11-23 01:44:37 +00001763 seq_printf(seq, "%s ", pkt_dev->odevname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764
Luiz Capitulino222f1802006-03-20 22:16:13 -08001765 seq_printf(seq, "\nStopped: ");
1766
Luiz Capitulinoc26a8012006-03-20 22:18:16 -08001767 list_for_each_entry(pkt_dev, &t->if_list, list)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001768 if (!pkt_dev->running)
Eric Dumazet593f63b2009-11-23 01:44:37 +00001769 seq_printf(seq, "%s ", pkt_dev->odevname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770
1771 if (t->result[0])
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001772 seq_printf(seq, "\nResult: %s\n", t->result);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 else
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001774 seq_printf(seq, "\nResult: NA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775
Luiz Capitulino222f1802006-03-20 22:16:13 -08001776 if_unlock(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001778 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779}
1780
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001781static ssize_t pktgen_thread_write(struct file *file,
Luiz Capitulino222f1802006-03-20 22:16:13 -08001782 const char __user * user_buffer,
1783 size_t count, loff_t * offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784{
Joe Perches8a994a72010-07-12 10:50:23 +00001785 struct seq_file *seq = file->private_data;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001786 struct pktgen_thread *t = seq->private;
Paul Gortmakerd6182222010-10-18 12:14:44 +00001787 int i, max, len, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 char name[40];
Luiz Capitulino222f1802006-03-20 22:16:13 -08001789 char *pg_result;
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001790
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 if (count < 1) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08001792 // sprintf(pg_result, "Wrong command format");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 return -EINVAL;
1794 }
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001795
Paul Gortmakerd6182222010-10-18 12:14:44 +00001796 max = count;
1797 len = count_trail_chars(user_buffer, max);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001798 if (len < 0)
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001799 return len;
1800
Paul Gortmakerd6182222010-10-18 12:14:44 +00001801 i = len;
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001802
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 /* Read variable name */
1804
1805 len = strn_len(&user_buffer[i], sizeof(name) - 1);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001806 if (len < 0)
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001807 return len;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001808
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 memset(name, 0, sizeof(name));
1810 if (copy_from_user(name, &user_buffer[i], len))
1811 return -EFAULT;
1812 i += len;
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001813
Luiz Capitulino222f1802006-03-20 22:16:13 -08001814 max = count - i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 len = count_trail_chars(&user_buffer[i], max);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001816 if (len < 0)
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001817 return len;
1818
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 i += len;
1820
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001821 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001822 printk(KERN_DEBUG "pktgen: t=%s, count=%lu\n",
1823 name, (unsigned long)count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824
Luiz Capitulino222f1802006-03-20 22:16:13 -08001825 if (!t) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00001826 pr_err("ERROR: No thread\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 ret = -EINVAL;
1828 goto out;
1829 }
1830
1831 pg_result = &(t->result[0]);
1832
Luiz Capitulino222f1802006-03-20 22:16:13 -08001833 if (!strcmp(name, "add_device")) {
1834 char f[32];
1835 memset(f, 0, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 len = strn_len(&user_buffer[i], sizeof(f) - 1);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001837 if (len < 0) {
1838 ret = len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 goto out;
1840 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08001841 if (copy_from_user(f, &user_buffer[i], len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 return -EFAULT;
1843 i += len;
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08001844 mutex_lock(&pktgen_thread_lock);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001845 pktgen_add_device(t, f);
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08001846 mutex_unlock(&pktgen_thread_lock);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001847 ret = count;
1848 sprintf(pg_result, "OK: add_device=%s", f);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 goto out;
1850 }
1851
Luiz Capitulino222f1802006-03-20 22:16:13 -08001852 if (!strcmp(name, "rem_device_all")) {
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08001853 mutex_lock(&pktgen_thread_lock);
Arthur Kepner95ed63f2006-03-20 21:26:56 -08001854 t->control |= T_REMDEVALL;
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08001855 mutex_unlock(&pktgen_thread_lock);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001856 schedule_timeout_interruptible(msecs_to_jiffies(125)); /* Propagate thread->control */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 ret = count;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001858 sprintf(pg_result, "OK: rem_device_all");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 goto out;
1860 }
1861
Luiz Capitulino222f1802006-03-20 22:16:13 -08001862 if (!strcmp(name, "max_before_softirq")) {
Robert Olssonb1639112007-08-28 15:46:58 -07001863 sprintf(pg_result, "OK: Note! max_before_softirq is obsoleted -- Do not use");
Luiz Capitulino222f1802006-03-20 22:16:13 -08001864 ret = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 goto out;
1866 }
1867
1868 ret = -EINVAL;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001869out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 return ret;
1871}
1872
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001873static int pktgen_thread_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874{
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001875 return single_open(file, pktgen_thread_show, PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876}
1877
Arjan van de Ven9a321442007-02-12 00:55:35 -08001878static const struct file_operations pktgen_thread_fops = {
Luiz Capitulino222f1802006-03-20 22:16:13 -08001879 .owner = THIS_MODULE,
1880 .open = pktgen_thread_open,
1881 .read = seq_read,
1882 .llseek = seq_lseek,
1883 .write = pktgen_thread_write,
1884 .release = single_release,
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001885};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886
1887/* Think find or remove for NN */
Luiz Capitulino222f1802006-03-20 22:16:13 -08001888static struct pktgen_dev *__pktgen_NN_threads(const char *ifname, int remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889{
1890 struct pktgen_thread *t;
1891 struct pktgen_dev *pkt_dev = NULL;
Eric Dumazet3e984842009-11-24 14:50:53 -08001892 bool exact = (remove == FIND);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08001894 list_for_each_entry(t, &pktgen_threads, th_list) {
Eric Dumazet3e984842009-11-24 14:50:53 -08001895 pkt_dev = pktgen_find_dev(t, ifname, exact);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 if (pkt_dev) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08001897 if (remove) {
1898 if_lock(t);
1899 pkt_dev->removal_mark = 1;
1900 t->control |= T_REMDEV;
1901 if_unlock(t);
1902 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 break;
1904 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08001906 return pkt_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907}
1908
Arthur Kepner95ed63f2006-03-20 21:26:56 -08001909/*
1910 * mark a device for removal
1911 */
Stephen Hemminger39df2322007-03-04 16:11:51 -08001912static void pktgen_mark_device(const char *ifname)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913{
1914 struct pktgen_dev *pkt_dev = NULL;
Arthur Kepner95ed63f2006-03-20 21:26:56 -08001915 const int max_tries = 10, msec_per_try = 125;
1916 int i = 0;
Arthur Kepner95ed63f2006-03-20 21:26:56 -08001917
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08001918 mutex_lock(&pktgen_thread_lock);
Joe Perchesf9467ea2010-06-21 12:29:14 +00001919 pr_debug("%s: marking %s for removal\n", __func__, ifname);
Arthur Kepner95ed63f2006-03-20 21:26:56 -08001920
Luiz Capitulino222f1802006-03-20 22:16:13 -08001921 while (1) {
Arthur Kepner95ed63f2006-03-20 21:26:56 -08001922
1923 pkt_dev = __pktgen_NN_threads(ifname, REMOVE);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001924 if (pkt_dev == NULL)
1925 break; /* success */
Arthur Kepner95ed63f2006-03-20 21:26:56 -08001926
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08001927 mutex_unlock(&pktgen_thread_lock);
Joe Perchesf9467ea2010-06-21 12:29:14 +00001928 pr_debug("%s: waiting for %s to disappear....\n",
1929 __func__, ifname);
Arthur Kepner95ed63f2006-03-20 21:26:56 -08001930 schedule_timeout_interruptible(msecs_to_jiffies(msec_per_try));
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08001931 mutex_lock(&pktgen_thread_lock);
Arthur Kepner95ed63f2006-03-20 21:26:56 -08001932
1933 if (++i >= max_tries) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00001934 pr_err("%s: timed out after waiting %d msec for device %s to be removed\n",
1935 __func__, msec_per_try * i, ifname);
Arthur Kepner95ed63f2006-03-20 21:26:56 -08001936 break;
1937 }
1938
1939 }
1940
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08001941 mutex_unlock(&pktgen_thread_lock);
Stephen Hemminger39df2322007-03-04 16:11:51 -08001942}
Arthur Kepner95ed63f2006-03-20 21:26:56 -08001943
Stephen Hemminger39df2322007-03-04 16:11:51 -08001944static void pktgen_change_name(struct net_device *dev)
1945{
1946 struct pktgen_thread *t;
1947
1948 list_for_each_entry(t, &pktgen_threads, th_list) {
1949 struct pktgen_dev *pkt_dev;
1950
1951 list_for_each_entry(pkt_dev, &t->if_list, list) {
1952 if (pkt_dev->odev != dev)
1953 continue;
1954
1955 remove_proc_entry(pkt_dev->entry->name, pg_proc_dir);
1956
Alexey Dobriyan29753152009-08-28 23:34:43 -07001957 pkt_dev->entry = proc_create_data(dev->name, 0600,
1958 pg_proc_dir,
1959 &pktgen_if_fops,
1960 pkt_dev);
Stephen Hemminger39df2322007-03-04 16:11:51 -08001961 if (!pkt_dev->entry)
Joe Perchesf9467ea2010-06-21 12:29:14 +00001962 pr_err("can't move proc entry for '%s'\n",
1963 dev->name);
Stephen Hemminger39df2322007-03-04 16:11:51 -08001964 break;
1965 }
1966 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967}
1968
Luiz Capitulino222f1802006-03-20 22:16:13 -08001969static int pktgen_device_event(struct notifier_block *unused,
1970 unsigned long event, void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971{
Stephen Hemminger39df2322007-03-04 16:11:51 -08001972 struct net_device *dev = ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973
YOSHIFUJI Hideaki721499e2008-07-19 22:34:43 -07001974 if (!net_eq(dev_net(dev), &init_net))
Eric W. Biedermane9dc8652007-09-12 13:02:17 +02001975 return NOTIFY_DONE;
1976
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977 /* It is OK that we do not hold the group lock right now,
1978 * as we run under the RTNL lock.
1979 */
1980
1981 switch (event) {
Stephen Hemminger39df2322007-03-04 16:11:51 -08001982 case NETDEV_CHANGENAME:
1983 pktgen_change_name(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 break;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001985
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 case NETDEV_UNREGISTER:
Luiz Capitulino222f1802006-03-20 22:16:13 -08001987 pktgen_mark_device(dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 break;
Stephen Hemminger3ff50b72007-04-20 17:09:22 -07001989 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990
1991 return NOTIFY_DONE;
1992}
1993
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001994static struct net_device *pktgen_dev_get_by_name(struct pktgen_dev *pkt_dev,
1995 const char *ifname)
Robert Olssone6fce5b2008-08-07 02:23:01 -07001996{
1997 char b[IFNAMSIZ+5];
Paul Gortmakerd6182222010-10-18 12:14:44 +00001998 int i;
Robert Olssone6fce5b2008-08-07 02:23:01 -07001999
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00002000 for (i = 0; ifname[i] != '@'; i++) {
2001 if (i == IFNAMSIZ)
Robert Olssone6fce5b2008-08-07 02:23:01 -07002002 break;
2003
2004 b[i] = ifname[i];
2005 }
2006 b[i] = 0;
2007
2008 return dev_get_by_name(&init_net, b);
2009}
2010
2011
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012/* Associate pktgen_dev with a device. */
2013
Stephen Hemminger39df2322007-03-04 16:11:51 -08002014static int pktgen_setup_dev(struct pktgen_dev *pkt_dev, const char *ifname)
Luiz Capitulino222f1802006-03-20 22:16:13 -08002015{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 struct net_device *odev;
Stephen Hemminger39df2322007-03-04 16:11:51 -08002017 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018
2019 /* Clean old setups */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 if (pkt_dev->odev) {
2021 dev_put(pkt_dev->odev);
Luiz Capitulino222f1802006-03-20 22:16:13 -08002022 pkt_dev->odev = NULL;
2023 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024
Robert Olssone6fce5b2008-08-07 02:23:01 -07002025 odev = pktgen_dev_get_by_name(pkt_dev, ifname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 if (!odev) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00002027 pr_err("no such netdevice: \"%s\"\n", ifname);
Stephen Hemminger39df2322007-03-04 16:11:51 -08002028 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 }
Stephen Hemminger39df2322007-03-04 16:11:51 -08002030
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 if (odev->type != ARPHRD_ETHER) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00002032 pr_err("not an ethernet device: \"%s\"\n", ifname);
Stephen Hemminger39df2322007-03-04 16:11:51 -08002033 err = -EINVAL;
2034 } else if (!netif_running(odev)) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00002035 pr_err("device is down: \"%s\"\n", ifname);
Stephen Hemminger39df2322007-03-04 16:11:51 -08002036 err = -ENETDOWN;
2037 } else {
2038 pkt_dev->odev = odev;
2039 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08002041
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 dev_put(odev);
Stephen Hemminger39df2322007-03-04 16:11:51 -08002043 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044}
2045
2046/* Read pkt_dev from the interface and set up internal pktgen_dev
2047 * structure to have the right information to create/send packets
2048 */
2049static void pktgen_setup_inject(struct pktgen_dev *pkt_dev)
2050{
Andrew Gallatin64c00d82008-08-13 15:16:00 -07002051 int ntxq;
2052
Luiz Capitulino222f1802006-03-20 22:16:13 -08002053 if (!pkt_dev->odev) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00002054 pr_err("ERROR: pkt_dev->odev == NULL in setup_inject\n");
Luiz Capitulino222f1802006-03-20 22:16:13 -08002055 sprintf(pkt_dev->result,
2056 "ERROR: pkt_dev->odev == NULL in setup_inject.\n");
2057 return;
2058 }
2059
Andrew Gallatin64c00d82008-08-13 15:16:00 -07002060 /* make sure that we don't pick a non-existing transmit queue */
2061 ntxq = pkt_dev->odev->real_num_tx_queues;
Robert Olssonbfdbc0a2008-11-19 14:09:47 -08002062
Andrew Gallatin64c00d82008-08-13 15:16:00 -07002063 if (ntxq <= pkt_dev->queue_map_min) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00002064 pr_warning("WARNING: Requested queue_map_min (zero-based) (%d) exceeds valid range [0 - %d] for (%d) queues on %s, resetting\n",
2065 pkt_dev->queue_map_min, (ntxq ?: 1) - 1, ntxq,
2066 pkt_dev->odevname);
Andrew Gallatin64c00d82008-08-13 15:16:00 -07002067 pkt_dev->queue_map_min = ntxq - 1;
2068 }
Jesse Brandeburg88271662008-10-28 13:21:51 -07002069 if (pkt_dev->queue_map_max >= ntxq) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00002070 pr_warning("WARNING: Requested queue_map_max (zero-based) (%d) exceeds valid range [0 - %d] for (%d) queues on %s, resetting\n",
2071 pkt_dev->queue_map_max, (ntxq ?: 1) - 1, ntxq,
2072 pkt_dev->odevname);
Andrew Gallatin64c00d82008-08-13 15:16:00 -07002073 pkt_dev->queue_map_max = ntxq - 1;
2074 }
2075
Luiz Capitulino222f1802006-03-20 22:16:13 -08002076 /* Default to the interface's mac if not explicitly set. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077
Kris Katterjohnf404e9a2006-01-17 13:04:57 -08002078 if (is_zero_ether_addr(pkt_dev->src_mac))
Luiz Capitulino222f1802006-03-20 22:16:13 -08002079 memcpy(&(pkt_dev->hh[6]), pkt_dev->odev->dev_addr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080
Luiz Capitulino222f1802006-03-20 22:16:13 -08002081 /* Set up Dest MAC */
Kris Katterjohnf404e9a2006-01-17 13:04:57 -08002082 memcpy(&(pkt_dev->hh[0]), pkt_dev->dst_mac, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083
Luiz Capitulino222f1802006-03-20 22:16:13 -08002084 /* Set up pkt size */
2085 pkt_dev->cur_pkt_size = pkt_dev->min_pkt_size;
2086
2087 if (pkt_dev->flags & F_IPV6) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 /*
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09002089 * Skip this automatic address setting until locks or functions
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 * gets exported
2091 */
2092
2093#ifdef NOTNOW
Luiz Capitulino222f1802006-03-20 22:16:13 -08002094 int i, set = 0, err = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 struct inet6_dev *idev;
2096
Luiz Capitulino222f1802006-03-20 22:16:13 -08002097 for (i = 0; i < IN6_ADDR_HSIZE; i++)
2098 if (pkt_dev->cur_in6_saddr.s6_addr[i]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 set = 1;
2100 break;
2101 }
2102
Luiz Capitulino222f1802006-03-20 22:16:13 -08002103 if (!set) {
2104
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 /*
2106 * Use linklevel address if unconfigured.
2107 *
2108 * use ipv6_get_lladdr if/when it's get exported
2109 */
2110
YOSHIFUJI Hideaki8814c4b2006-09-22 14:44:24 -07002111 rcu_read_lock();
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00002112 idev = __in6_dev_get(pkt_dev->odev);
2113 if (idev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 struct inet6_ifaddr *ifp;
2115
2116 read_lock_bh(&idev->lock);
Luiz Capitulino222f1802006-03-20 22:16:13 -08002117 for (ifp = idev->addr_list; ifp;
2118 ifp = ifp->if_next) {
Joe Perchesf64f9e72009-11-29 16:55:45 -08002119 if (ifp->scope == IFA_LINK &&
2120 !(ifp->flags & IFA_F_TENTATIVE)) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08002121 ipv6_addr_copy(&pkt_dev->
2122 cur_in6_saddr,
2123 &ifp->addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 err = 0;
2125 break;
2126 }
2127 }
2128 read_unlock_bh(&idev->lock);
2129 }
YOSHIFUJI Hideaki8814c4b2006-09-22 14:44:24 -07002130 rcu_read_unlock();
Luiz Capitulino222f1802006-03-20 22:16:13 -08002131 if (err)
Joe Perchesf9467ea2010-06-21 12:29:14 +00002132 pr_err("ERROR: IPv6 link address not available\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 }
2134#endif
Luiz Capitulino222f1802006-03-20 22:16:13 -08002135 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 pkt_dev->saddr_min = 0;
2137 pkt_dev->saddr_max = 0;
2138 if (strlen(pkt_dev->src_min) == 0) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08002139
2140 struct in_device *in_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141
2142 rcu_read_lock();
Herbert Xue5ed6392005-10-03 14:35:55 -07002143 in_dev = __in_dev_get_rcu(pkt_dev->odev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144 if (in_dev) {
2145 if (in_dev->ifa_list) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08002146 pkt_dev->saddr_min =
2147 in_dev->ifa_list->ifa_address;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 pkt_dev->saddr_max = pkt_dev->saddr_min;
2149 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 }
2151 rcu_read_unlock();
Luiz Capitulino222f1802006-03-20 22:16:13 -08002152 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 pkt_dev->saddr_min = in_aton(pkt_dev->src_min);
2154 pkt_dev->saddr_max = in_aton(pkt_dev->src_max);
2155 }
2156
2157 pkt_dev->daddr_min = in_aton(pkt_dev->dst_min);
2158 pkt_dev->daddr_max = in_aton(pkt_dev->dst_max);
2159 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08002160 /* Initialize current values. */
2161 pkt_dev->cur_dst_mac_offset = 0;
2162 pkt_dev->cur_src_mac_offset = 0;
2163 pkt_dev->cur_saddr = pkt_dev->saddr_min;
2164 pkt_dev->cur_daddr = pkt_dev->daddr_min;
2165 pkt_dev->cur_udp_dst = pkt_dev->udp_dst_min;
2166 pkt_dev->cur_udp_src = pkt_dev->udp_src_min;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 pkt_dev->nflows = 0;
2168}
2169
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00002171static void spin(struct pktgen_dev *pkt_dev, ktime_t spin_until)
2172{
Stephen Hemmingeref879792009-09-22 19:41:43 +00002173 ktime_t start_time, end_time;
Eric Dumazet417bc4b2009-10-01 09:29:45 -07002174 s64 remaining;
Stephen Hemminger2bc481c2009-08-28 23:41:29 -07002175 struct hrtimer_sleeper t;
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00002176
Stephen Hemminger2bc481c2009-08-28 23:41:29 -07002177 hrtimer_init_on_stack(&t.timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
2178 hrtimer_set_expires(&t.timer, spin_until);
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00002179
Daniel Turull43d28b62010-06-09 22:49:57 +00002180 remaining = ktime_to_ns(hrtimer_expires_remaining(&t.timer));
Eric Dumazet417bc4b2009-10-01 09:29:45 -07002181 if (remaining <= 0) {
2182 pkt_dev->next_tx = ktime_add_ns(spin_until, pkt_dev->delay);
Stephen Hemminger2bc481c2009-08-28 23:41:29 -07002183 return;
Eric Dumazet417bc4b2009-10-01 09:29:45 -07002184 }
Stephen Hemminger2bc481c2009-08-28 23:41:29 -07002185
Stephen Hemmingeref879792009-09-22 19:41:43 +00002186 start_time = ktime_now();
Daniel Turull43d28b62010-06-09 22:49:57 +00002187 if (remaining < 100000)
2188 ndelay(remaining); /* really small just spin */
Stephen Hemminger2bc481c2009-08-28 23:41:29 -07002189 else {
2190 /* see do_nanosleep */
2191 hrtimer_init_sleeper(&t, current);
2192 do {
2193 set_current_state(TASK_INTERRUPTIBLE);
2194 hrtimer_start_expires(&t.timer, HRTIMER_MODE_ABS);
2195 if (!hrtimer_active(&t.timer))
2196 t.task = NULL;
2197
2198 if (likely(t.task))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200
Stephen Hemminger2bc481c2009-08-28 23:41:29 -07002201 hrtimer_cancel(&t.timer);
2202 } while (t.task && pkt_dev->running && !signal_pending(current));
2203 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 }
Stephen Hemmingeref879792009-09-22 19:41:43 +00002205 end_time = ktime_now();
2206
2207 pkt_dev->idle_acc += ktime_to_ns(ktime_sub(end_time, start_time));
Daniel Turull07a0f0f2010-06-10 23:08:11 -07002208 pkt_dev->next_tx = ktime_add_ns(spin_until, pkt_dev->delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209}
2210
Jamal Hadi Salim16dab722007-07-02 22:39:50 -07002211static inline void set_pkt_overhead(struct pktgen_dev *pkt_dev)
2212{
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002213 pkt_dev->pkt_overhead = 0;
Jamal Hadi Salim16dab722007-07-02 22:39:50 -07002214 pkt_dev->pkt_overhead += pkt_dev->nr_labels*sizeof(u32);
2215 pkt_dev->pkt_overhead += VLAN_TAG_SIZE(pkt_dev);
2216 pkt_dev->pkt_overhead += SVLAN_TAG_SIZE(pkt_dev);
2217}
2218
Stephen Hemminger648fda72009-08-27 13:55:07 +00002219static inline int f_seen(const struct pktgen_dev *pkt_dev, int flow)
Jamal Hadi Salim007a5312007-07-02 22:40:36 -07002220{
Stephen Hemminger648fda72009-08-27 13:55:07 +00002221 return !!(pkt_dev->flows[flow].flags & F_INIT);
Jamal Hadi Salim007a5312007-07-02 22:40:36 -07002222}
2223
2224static inline int f_pick(struct pktgen_dev *pkt_dev)
2225{
2226 int flow = pkt_dev->curfl;
2227
2228 if (pkt_dev->flags & F_FLOW_SEQ) {
2229 if (pkt_dev->flows[flow].count >= pkt_dev->lflow) {
2230 /* reset time */
2231 pkt_dev->flows[flow].count = 0;
Robert Olsson1211a642008-08-05 18:44:26 -07002232 pkt_dev->flows[flow].flags = 0;
Jamal Hadi Salim007a5312007-07-02 22:40:36 -07002233 pkt_dev->curfl += 1;
2234 if (pkt_dev->curfl >= pkt_dev->cflows)
2235 pkt_dev->curfl = 0; /*reset */
2236 }
2237 } else {
2238 flow = random32() % pkt_dev->cflows;
Robert Olsson1211a642008-08-05 18:44:26 -07002239 pkt_dev->curfl = flow;
Jamal Hadi Salim007a5312007-07-02 22:40:36 -07002240
Robert Olsson1211a642008-08-05 18:44:26 -07002241 if (pkt_dev->flows[flow].count > pkt_dev->lflow) {
Jamal Hadi Salim007a5312007-07-02 22:40:36 -07002242 pkt_dev->flows[flow].count = 0;
Robert Olsson1211a642008-08-05 18:44:26 -07002243 pkt_dev->flows[flow].flags = 0;
2244 }
Jamal Hadi Salim007a5312007-07-02 22:40:36 -07002245 }
2246
2247 return pkt_dev->curfl;
2248}
2249
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002250
2251#ifdef CONFIG_XFRM
2252/* If there was already an IPSEC SA, we keep it as is, else
2253 * we go look for it ...
2254*/
Jamal Hadi Salimbd557752010-02-22 16:20:22 -08002255#define DUMMY_MARK 0
Adrian Bunkfea1ab02007-07-30 18:04:09 -07002256static void get_ipsec_sa(struct pktgen_dev *pkt_dev, int flow)
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002257{
2258 struct xfrm_state *x = pkt_dev->flows[flow].x;
2259 if (!x) {
2260 /*slow path: we dont already have xfrm_state*/
Jamal Hadi Salimbd557752010-02-22 16:20:22 -08002261 x = xfrm_stateonly_find(&init_net, DUMMY_MARK,
Alexey Dobriyan5447c5e2008-11-25 17:31:51 -08002262 (xfrm_address_t *)&pkt_dev->cur_daddr,
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002263 (xfrm_address_t *)&pkt_dev->cur_saddr,
2264 AF_INET,
2265 pkt_dev->ipsmode,
2266 pkt_dev->ipsproto, 0);
2267 if (x) {
2268 pkt_dev->flows[flow].x = x;
2269 set_pkt_overhead(pkt_dev);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00002270 pkt_dev->pkt_overhead += x->props.header_len;
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002271 }
2272
2273 }
2274}
2275#endif
David S. Millerfd2ea0a2008-07-17 01:56:23 -07002276static void set_cur_queue_map(struct pktgen_dev *pkt_dev)
2277{
Robert Olssone6fce5b2008-08-07 02:23:01 -07002278
2279 if (pkt_dev->flags & F_QUEUE_MAP_CPU)
2280 pkt_dev->cur_queue_map = smp_processor_id();
2281
Eric Dumazet896a7cf2009-10-02 20:24:59 +00002282 else if (pkt_dev->queue_map_min <= pkt_dev->queue_map_max) {
David S. Millerfd2ea0a2008-07-17 01:56:23 -07002283 __u16 t;
2284 if (pkt_dev->flags & F_QUEUE_MAP_RND) {
2285 t = random32() %
2286 (pkt_dev->queue_map_max -
2287 pkt_dev->queue_map_min + 1)
2288 + pkt_dev->queue_map_min;
2289 } else {
2290 t = pkt_dev->cur_queue_map + 1;
2291 if (t > pkt_dev->queue_map_max)
2292 t = pkt_dev->queue_map_min;
2293 }
2294 pkt_dev->cur_queue_map = t;
2295 }
Robert Olssonbfdbc0a2008-11-19 14:09:47 -08002296 pkt_dev->cur_queue_map = pkt_dev->cur_queue_map % pkt_dev->odev->real_num_tx_queues;
David S. Millerfd2ea0a2008-07-17 01:56:23 -07002297}
2298
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299/* Increment/randomize headers according to flags and current values
2300 * for IP src/dest, UDP src/dst port, MAC-Addr src/dst
2301 */
Luiz Capitulino222f1802006-03-20 22:16:13 -08002302static void mod_cur_headers(struct pktgen_dev *pkt_dev)
2303{
2304 __u32 imn;
2305 __u32 imx;
2306 int flow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307
Jamal Hadi Salim007a5312007-07-02 22:40:36 -07002308 if (pkt_dev->cflows)
2309 flow = f_pick(pkt_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310
2311 /* Deal with source MAC */
Luiz Capitulino222f1802006-03-20 22:16:13 -08002312 if (pkt_dev->src_mac_count > 1) {
2313 __u32 mc;
2314 __u32 tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315
Luiz Capitulino222f1802006-03-20 22:16:13 -08002316 if (pkt_dev->flags & F_MACSRC_RND)
Stephen Hemminger5fa6fc72007-03-04 16:07:28 -08002317 mc = random32() % pkt_dev->src_mac_count;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002318 else {
2319 mc = pkt_dev->cur_src_mac_offset++;
Robert Olssonff2a79a2008-08-05 18:45:05 -07002320 if (pkt_dev->cur_src_mac_offset >=
Luiz Capitulino222f1802006-03-20 22:16:13 -08002321 pkt_dev->src_mac_count)
2322 pkt_dev->cur_src_mac_offset = 0;
2323 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324
Luiz Capitulino222f1802006-03-20 22:16:13 -08002325 tmp = pkt_dev->src_mac[5] + (mc & 0xFF);
2326 pkt_dev->hh[11] = tmp;
2327 tmp = (pkt_dev->src_mac[4] + ((mc >> 8) & 0xFF) + (tmp >> 8));
2328 pkt_dev->hh[10] = tmp;
2329 tmp = (pkt_dev->src_mac[3] + ((mc >> 16) & 0xFF) + (tmp >> 8));
2330 pkt_dev->hh[9] = tmp;
2331 tmp = (pkt_dev->src_mac[2] + ((mc >> 24) & 0xFF) + (tmp >> 8));
2332 pkt_dev->hh[8] = tmp;
2333 tmp = (pkt_dev->src_mac[1] + (tmp >> 8));
2334 pkt_dev->hh[7] = tmp;
2335 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336
Luiz Capitulino222f1802006-03-20 22:16:13 -08002337 /* Deal with Destination MAC */
2338 if (pkt_dev->dst_mac_count > 1) {
2339 __u32 mc;
2340 __u32 tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
Luiz Capitulino222f1802006-03-20 22:16:13 -08002342 if (pkt_dev->flags & F_MACDST_RND)
Stephen Hemminger5fa6fc72007-03-04 16:07:28 -08002343 mc = random32() % pkt_dev->dst_mac_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344
Luiz Capitulino222f1802006-03-20 22:16:13 -08002345 else {
2346 mc = pkt_dev->cur_dst_mac_offset++;
Robert Olssonff2a79a2008-08-05 18:45:05 -07002347 if (pkt_dev->cur_dst_mac_offset >=
Luiz Capitulino222f1802006-03-20 22:16:13 -08002348 pkt_dev->dst_mac_count) {
2349 pkt_dev->cur_dst_mac_offset = 0;
2350 }
2351 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352
Luiz Capitulino222f1802006-03-20 22:16:13 -08002353 tmp = pkt_dev->dst_mac[5] + (mc & 0xFF);
2354 pkt_dev->hh[5] = tmp;
2355 tmp = (pkt_dev->dst_mac[4] + ((mc >> 8) & 0xFF) + (tmp >> 8));
2356 pkt_dev->hh[4] = tmp;
2357 tmp = (pkt_dev->dst_mac[3] + ((mc >> 16) & 0xFF) + (tmp >> 8));
2358 pkt_dev->hh[3] = tmp;
2359 tmp = (pkt_dev->dst_mac[2] + ((mc >> 24) & 0xFF) + (tmp >> 8));
2360 pkt_dev->hh[2] = tmp;
2361 tmp = (pkt_dev->dst_mac[1] + (tmp >> 8));
2362 pkt_dev->hh[1] = tmp;
2363 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002365 if (pkt_dev->flags & F_MPLS_RND) {
2366 unsigned i;
Stephen Hemmingere71a4782007-04-10 20:10:33 -07002367 for (i = 0; i < pkt_dev->nr_labels; i++)
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002368 if (pkt_dev->labels[i] & MPLS_STACK_BOTTOM)
2369 pkt_dev->labels[i] = MPLS_STACK_BOTTOM |
Stephen Hemminger5fa6fc72007-03-04 16:07:28 -08002370 ((__force __be32)random32() &
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002371 htonl(0x000fffff));
2372 }
2373
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002374 if ((pkt_dev->flags & F_VID_RND) && (pkt_dev->vlan_id != 0xffff)) {
Stephen Hemminger5fa6fc72007-03-04 16:07:28 -08002375 pkt_dev->vlan_id = random32() & (4096-1);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002376 }
2377
2378 if ((pkt_dev->flags & F_SVID_RND) && (pkt_dev->svlan_id != 0xffff)) {
Stephen Hemminger5fa6fc72007-03-04 16:07:28 -08002379 pkt_dev->svlan_id = random32() & (4096 - 1);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002380 }
2381
Luiz Capitulino222f1802006-03-20 22:16:13 -08002382 if (pkt_dev->udp_src_min < pkt_dev->udp_src_max) {
2383 if (pkt_dev->flags & F_UDPSRC_RND)
Stephen Hemminger5fa6fc72007-03-04 16:07:28 -08002384 pkt_dev->cur_udp_src = random32() %
2385 (pkt_dev->udp_src_max - pkt_dev->udp_src_min)
2386 + pkt_dev->udp_src_min;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387
Luiz Capitulino222f1802006-03-20 22:16:13 -08002388 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 pkt_dev->cur_udp_src++;
2390 if (pkt_dev->cur_udp_src >= pkt_dev->udp_src_max)
2391 pkt_dev->cur_udp_src = pkt_dev->udp_src_min;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002392 }
2393 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394
Luiz Capitulino222f1802006-03-20 22:16:13 -08002395 if (pkt_dev->udp_dst_min < pkt_dev->udp_dst_max) {
2396 if (pkt_dev->flags & F_UDPDST_RND) {
Stephen Hemminger5fa6fc72007-03-04 16:07:28 -08002397 pkt_dev->cur_udp_dst = random32() %
2398 (pkt_dev->udp_dst_max - pkt_dev->udp_dst_min)
2399 + pkt_dev->udp_dst_min;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002400 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 pkt_dev->cur_udp_dst++;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002402 if (pkt_dev->cur_udp_dst >= pkt_dev->udp_dst_max)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 pkt_dev->cur_udp_dst = pkt_dev->udp_dst_min;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002404 }
2405 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406
2407 if (!(pkt_dev->flags & F_IPV6)) {
2408
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00002409 imn = ntohl(pkt_dev->saddr_min);
2410 imx = ntohl(pkt_dev->saddr_max);
2411 if (imn < imx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 __u32 t;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002413 if (pkt_dev->flags & F_IPSRC_RND)
Stephen Hemminger5fa6fc72007-03-04 16:07:28 -08002414 t = random32() % (imx - imn) + imn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 else {
2416 t = ntohl(pkt_dev->cur_saddr);
2417 t++;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00002418 if (t > imx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 t = imn;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00002420
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 }
2422 pkt_dev->cur_saddr = htonl(t);
2423 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08002424
Jamal Hadi Salim007a5312007-07-02 22:40:36 -07002425 if (pkt_dev->cflows && f_seen(pkt_dev, flow)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 pkt_dev->cur_daddr = pkt_dev->flows[flow].cur_daddr;
2427 } else {
Al Viro252e3342006-11-14 20:48:11 -08002428 imn = ntohl(pkt_dev->daddr_min);
2429 imx = ntohl(pkt_dev->daddr_max);
2430 if (imn < imx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 __u32 t;
Al Viro252e3342006-11-14 20:48:11 -08002432 __be32 s;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 if (pkt_dev->flags & F_IPDST_RND) {
2434
Stephen Hemminger5fa6fc72007-03-04 16:07:28 -08002435 t = random32() % (imx - imn) + imn;
Al Viro252e3342006-11-14 20:48:11 -08002436 s = htonl(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437
Joe Perches21cf2252007-12-16 13:44:00 -08002438 while (ipv4_is_loopback(s) ||
2439 ipv4_is_multicast(s) ||
Jan Engelhardt1e637c72008-01-21 03:18:08 -08002440 ipv4_is_lbcast(s) ||
Joe Perches21cf2252007-12-16 13:44:00 -08002441 ipv4_is_zeronet(s) ||
2442 ipv4_is_local_multicast(s)) {
Stephen Hemminger5fa6fc72007-03-04 16:07:28 -08002443 t = random32() % (imx - imn) + imn;
Al Viro252e3342006-11-14 20:48:11 -08002444 s = htonl(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 }
Al Viro252e3342006-11-14 20:48:11 -08002446 pkt_dev->cur_daddr = s;
2447 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 t = ntohl(pkt_dev->cur_daddr);
2449 t++;
2450 if (t > imx) {
2451 t = imn;
2452 }
2453 pkt_dev->cur_daddr = htonl(t);
2454 }
2455 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08002456 if (pkt_dev->cflows) {
Jamal Hadi Salim007a5312007-07-02 22:40:36 -07002457 pkt_dev->flows[flow].flags |= F_INIT;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002458 pkt_dev->flows[flow].cur_daddr =
2459 pkt_dev->cur_daddr;
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002460#ifdef CONFIG_XFRM
2461 if (pkt_dev->flags & F_IPSEC_ON)
2462 get_ipsec_sa(pkt_dev, flow);
2463#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 pkt_dev->nflows++;
2465 }
2466 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08002467 } else { /* IPV6 * */
2468
2469 if (pkt_dev->min_in6_daddr.s6_addr32[0] == 0 &&
2470 pkt_dev->min_in6_daddr.s6_addr32[1] == 0 &&
2471 pkt_dev->min_in6_daddr.s6_addr32[2] == 0 &&
2472 pkt_dev->min_in6_daddr.s6_addr32[3] == 0) ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 else {
2474 int i;
2475
2476 /* Only random destinations yet */
2477
Luiz Capitulino222f1802006-03-20 22:16:13 -08002478 for (i = 0; i < 4; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 pkt_dev->cur_in6_daddr.s6_addr32[i] =
Stephen Hemminger5fa6fc72007-03-04 16:07:28 -08002480 (((__force __be32)random32() |
Luiz Capitulino222f1802006-03-20 22:16:13 -08002481 pkt_dev->min_in6_daddr.s6_addr32[i]) &
2482 pkt_dev->max_in6_daddr.s6_addr32[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08002484 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 }
2486
Luiz Capitulino222f1802006-03-20 22:16:13 -08002487 if (pkt_dev->min_pkt_size < pkt_dev->max_pkt_size) {
2488 __u32 t;
2489 if (pkt_dev->flags & F_TXSIZE_RND) {
Stephen Hemminger5fa6fc72007-03-04 16:07:28 -08002490 t = random32() %
2491 (pkt_dev->max_pkt_size - pkt_dev->min_pkt_size)
2492 + pkt_dev->min_pkt_size;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002493 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 t = pkt_dev->cur_pkt_size + 1;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002495 if (t > pkt_dev->max_pkt_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 t = pkt_dev->min_pkt_size;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002497 }
2498 pkt_dev->cur_pkt_size = t;
2499 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500
David S. Millerfd2ea0a2008-07-17 01:56:23 -07002501 set_cur_queue_map(pkt_dev);
Robert Olsson45b270f2007-08-28 15:45:55 -07002502
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 pkt_dev->flows[flow].count++;
2504}
2505
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002506
2507#ifdef CONFIG_XFRM
2508static int pktgen_output_ipsec(struct sk_buff *skb, struct pktgen_dev *pkt_dev)
2509{
2510 struct xfrm_state *x = pkt_dev->flows[pkt_dev->curfl].x;
2511 int err = 0;
2512 struct iphdr *iph;
2513
2514 if (!x)
2515 return 0;
2516 /* XXX: we dont support tunnel mode for now until
2517 * we resolve the dst issue */
2518 if (x->props.mode != XFRM_MODE_TRANSPORT)
2519 return 0;
2520
2521 spin_lock(&x->lock);
2522 iph = ip_hdr(skb);
2523
Herbert Xu13996372007-10-17 21:35:51 -07002524 err = x->outer_mode->output(x, skb);
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002525 if (err)
2526 goto error;
2527 err = x->type->output(x, skb);
2528 if (err)
2529 goto error;
2530
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00002531 x->curlft.bytes += skb->len;
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002532 x->curlft.packets++;
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002533error:
2534 spin_unlock(&x->lock);
2535 return err;
2536}
2537
Stephen Hemminger475ac1e2009-08-27 13:55:08 +00002538static void free_SAs(struct pktgen_dev *pkt_dev)
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002539{
2540 if (pkt_dev->cflows) {
2541 /* let go of the SAs if we have them */
Paul Gortmakerd6182222010-10-18 12:14:44 +00002542 int i;
2543 for (i = 0; i < pkt_dev->cflows; i++) {
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002544 struct xfrm_state *x = pkt_dev->flows[i].x;
2545 if (x) {
2546 xfrm_state_put(x);
2547 pkt_dev->flows[i].x = NULL;
2548 }
2549 }
2550 }
2551}
2552
Stephen Hemminger475ac1e2009-08-27 13:55:08 +00002553static int process_ipsec(struct pktgen_dev *pkt_dev,
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002554 struct sk_buff *skb, __be16 protocol)
2555{
2556 if (pkt_dev->flags & F_IPSEC_ON) {
2557 struct xfrm_state *x = pkt_dev->flows[pkt_dev->curfl].x;
2558 int nhead = 0;
2559 if (x) {
2560 int ret;
2561 __u8 *eth;
2562 nhead = x->props.header_len - skb_headroom(skb);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00002563 if (nhead > 0) {
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002564 ret = pskb_expand_head(skb, nhead, 0, GFP_ATOMIC);
2565 if (ret < 0) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00002566 pr_err("Error expanding ipsec packet %d\n",
2567 ret);
Ilpo Järvinenb4bb4ac2008-10-13 18:43:59 -07002568 goto err;
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002569 }
2570 }
2571
2572 /* ipsec is not expecting ll header */
2573 skb_pull(skb, ETH_HLEN);
2574 ret = pktgen_output_ipsec(skb, pkt_dev);
2575 if (ret) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00002576 pr_err("Error creating ipsec packet %d\n", ret);
Ilpo Järvinenb4bb4ac2008-10-13 18:43:59 -07002577 goto err;
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002578 }
2579 /* restore ll */
2580 eth = (__u8 *) skb_push(skb, ETH_HLEN);
2581 memcpy(eth, pkt_dev->hh, 12);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00002582 *(u16 *) &eth[12] = protocol;
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002583 }
2584 }
2585 return 1;
Ilpo Järvinenb4bb4ac2008-10-13 18:43:59 -07002586err:
2587 kfree_skb(skb);
2588 return 0;
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002589}
2590#endif
2591
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002592static void mpls_push(__be32 *mpls, struct pktgen_dev *pkt_dev)
2593{
2594 unsigned i;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00002595 for (i = 0; i < pkt_dev->nr_labels; i++)
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002596 *mpls++ = pkt_dev->labels[i] & ~MPLS_STACK_BOTTOM;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00002597
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002598 mpls--;
2599 *mpls |= MPLS_STACK_BOTTOM;
2600}
2601
Al Viro0f37c602006-11-03 03:49:56 -08002602static inline __be16 build_tci(unsigned int id, unsigned int cfi,
2603 unsigned int prio)
2604{
2605 return htons(id | (cfi << 12) | (prio << 13));
2606}
2607
Luiz Capitulino222f1802006-03-20 22:16:13 -08002608static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
2609 struct pktgen_dev *pkt_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610{
2611 struct sk_buff *skb = NULL;
2612 __u8 *eth;
2613 struct udphdr *udph;
2614 int datalen, iplen;
2615 struct iphdr *iph;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002616 struct pktgen_hdr *pgh = NULL;
Stephen Hemmingerd5f1ce92007-03-04 16:08:08 -08002617 __be16 protocol = htons(ETH_P_IP);
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002618 __be32 *mpls;
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002619 __be16 *vlan_tci = NULL; /* Encapsulates priority and VLAN ID */
2620 __be16 *vlan_encapsulated_proto = NULL; /* packet type ID field (or len) for VLAN tag */
2621 __be16 *svlan_tci = NULL; /* Encapsulates priority and SVLAN ID */
2622 __be16 *svlan_encapsulated_proto = NULL; /* packet type ID field (or len) for SVLAN tag */
David S. Millerfd2ea0a2008-07-17 01:56:23 -07002623 u16 queue_map;
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002624
2625 if (pkt_dev->nr_labels)
Stephen Hemmingerd5f1ce92007-03-04 16:08:08 -08002626 protocol = htons(ETH_P_MPLS_UC);
Luiz Capitulino222f1802006-03-20 22:16:13 -08002627
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002628 if (pkt_dev->vlan_id != 0xffff)
Stephen Hemmingerd5f1ce92007-03-04 16:08:08 -08002629 protocol = htons(ETH_P_8021Q);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002630
Robert Olsson64053be2005-06-26 15:27:10 -07002631 /* Update any of the values, used when we're incrementing various
2632 * fields.
2633 */
2634 mod_cur_headers(pkt_dev);
Junchang Wangeb589062010-11-07 23:19:43 +00002635 queue_map = pkt_dev->cur_queue_map;
Robert Olsson64053be2005-06-26 15:27:10 -07002636
David S. Miller7ac54592006-01-18 14:19:10 -08002637 datalen = (odev->hard_header_len + 16) & ~0xf;
Robert Olssone99b99b2010-03-18 22:44:30 +00002638
2639 if (pkt_dev->flags & F_NODE) {
2640 int node;
2641
2642 if (pkt_dev->node >= 0)
2643 node = pkt_dev->node;
2644 else
2645 node = numa_node_id();
2646
2647 skb = __alloc_skb(NET_SKB_PAD + pkt_dev->cur_pkt_size + 64
2648 + datalen + pkt_dev->pkt_overhead, GFP_NOWAIT, 0, node);
2649 if (likely(skb)) {
2650 skb_reserve(skb, NET_SKB_PAD);
2651 skb->dev = odev;
2652 }
2653 }
2654 else
2655 skb = __netdev_alloc_skb(odev,
2656 pkt_dev->cur_pkt_size + 64
2657 + datalen + pkt_dev->pkt_overhead, GFP_NOWAIT);
2658
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 if (!skb) {
2660 sprintf(pkt_dev->result, "No memory");
2661 return NULL;
2662 }
Junchang Wanga8d764b2010-12-08 16:55:16 +00002663 prefetchw(skb->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664
David S. Miller7ac54592006-01-18 14:19:10 -08002665 skb_reserve(skb, datalen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666
2667 /* Reserve for ethernet and IP header */
2668 eth = (__u8 *) skb_push(skb, 14);
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002669 mpls = (__be32 *)skb_put(skb, pkt_dev->nr_labels*sizeof(__u32));
2670 if (pkt_dev->nr_labels)
2671 mpls_push(mpls, pkt_dev);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002672
2673 if (pkt_dev->vlan_id != 0xffff) {
Stephen Hemmingere71a4782007-04-10 20:10:33 -07002674 if (pkt_dev->svlan_id != 0xffff) {
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002675 svlan_tci = (__be16 *)skb_put(skb, sizeof(__be16));
Al Viro0f37c602006-11-03 03:49:56 -08002676 *svlan_tci = build_tci(pkt_dev->svlan_id,
2677 pkt_dev->svlan_cfi,
2678 pkt_dev->svlan_p);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002679 svlan_encapsulated_proto = (__be16 *)skb_put(skb, sizeof(__be16));
Stephen Hemmingerd5f1ce92007-03-04 16:08:08 -08002680 *svlan_encapsulated_proto = htons(ETH_P_8021Q);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002681 }
2682 vlan_tci = (__be16 *)skb_put(skb, sizeof(__be16));
Al Viro0f37c602006-11-03 03:49:56 -08002683 *vlan_tci = build_tci(pkt_dev->vlan_id,
2684 pkt_dev->vlan_cfi,
2685 pkt_dev->vlan_p);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002686 vlan_encapsulated_proto = (__be16 *)skb_put(skb, sizeof(__be16));
Stephen Hemmingerd5f1ce92007-03-04 16:08:08 -08002687 *vlan_encapsulated_proto = htons(ETH_P_IP);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002688 }
2689
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07002690 skb->network_header = skb->tail;
Arnaldo Carvalho de Melob0e380b2007-04-10 21:21:55 -07002691 skb->transport_header = skb->network_header + sizeof(struct iphdr);
Arnaldo Carvalho de Meloddc7b8e2007-03-15 21:42:27 -03002692 skb_put(skb, sizeof(struct iphdr) + sizeof(struct udphdr));
David S. Millerfd2ea0a2008-07-17 01:56:23 -07002693 skb_set_queue_mapping(skb, queue_map);
John Fastabend9e50e3a2010-11-16 19:12:28 +00002694 skb->priority = pkt_dev->skb_priority;
2695
Arnaldo Carvalho de Meloddc7b8e2007-03-15 21:42:27 -03002696 iph = ip_hdr(skb);
2697 udph = udp_hdr(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699 memcpy(eth, pkt_dev->hh, 12);
Al Viro252e3342006-11-14 20:48:11 -08002700 *(__be16 *) & eth[12] = protocol;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002702 /* Eth + IPh + UDPh + mpls */
2703 datalen = pkt_dev->cur_pkt_size - 14 - 20 - 8 -
Jamal Hadi Salim16dab722007-07-02 22:39:50 -07002704 pkt_dev->pkt_overhead;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002705 if (datalen < sizeof(struct pktgen_hdr))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 datalen = sizeof(struct pktgen_hdr);
Luiz Capitulino222f1802006-03-20 22:16:13 -08002707
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 udph->source = htons(pkt_dev->cur_udp_src);
2709 udph->dest = htons(pkt_dev->cur_udp_dst);
Luiz Capitulino222f1802006-03-20 22:16:13 -08002710 udph->len = htons(datalen + 8); /* DATA + udphdr */
2711 udph->check = 0; /* No checksum */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712
2713 iph->ihl = 5;
2714 iph->version = 4;
2715 iph->ttl = 32;
Francesco Fondelli1ca77682006-09-27 16:32:03 -07002716 iph->tos = pkt_dev->tos;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002717 iph->protocol = IPPROTO_UDP; /* UDP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 iph->saddr = pkt_dev->cur_saddr;
2719 iph->daddr = pkt_dev->cur_daddr;
Eric Dumazet66ed1e52009-10-24 06:55:20 -07002720 iph->id = htons(pkt_dev->ip_id);
2721 pkt_dev->ip_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 iph->frag_off = 0;
2723 iplen = 20 + 8 + datalen;
2724 iph->tot_len = htons(iplen);
2725 iph->check = 0;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002726 iph->check = ip_fast_csum((void *)iph, iph->ihl);
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002727 skb->protocol = protocol;
Arnaldo Carvalho de Melob0e380b2007-04-10 21:21:55 -07002728 skb->mac_header = (skb->network_header - ETH_HLEN -
Jamal Hadi Salim16dab722007-07-02 22:39:50 -07002729 pkt_dev->pkt_overhead);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 skb->dev = odev;
2731 skb->pkt_type = PACKET_HOST;
2732
Eric Dumazet66ed1e52009-10-24 06:55:20 -07002733 if (pkt_dev->nfrags <= 0) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08002734 pgh = (struct pktgen_hdr *)skb_put(skb, datalen);
Eric Dumazet66ed1e52009-10-24 06:55:20 -07002735 memset(pgh + 1, 0, datalen - sizeof(struct pktgen_hdr));
2736 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 int frags = pkt_dev->nfrags;
Eric Dumazet66ed1e52009-10-24 06:55:20 -07002738 int i, len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739
Luiz Capitulino222f1802006-03-20 22:16:13 -08002740 pgh = (struct pktgen_hdr *)(((char *)(udph)) + 8);
2741
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 if (frags > MAX_SKB_FRAGS)
2743 frags = MAX_SKB_FRAGS;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002744 if (datalen > frags * PAGE_SIZE) {
Eric Dumazet66ed1e52009-10-24 06:55:20 -07002745 len = datalen - frags * PAGE_SIZE;
2746 memset(skb_put(skb, len), 0, len);
Luiz Capitulino222f1802006-03-20 22:16:13 -08002747 datalen = frags * PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 }
2749
2750 i = 0;
2751 while (datalen > 0) {
Eric Dumazet66ed1e52009-10-24 06:55:20 -07002752 struct page *page = alloc_pages(GFP_KERNEL | __GFP_ZERO, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 skb_shinfo(skb)->frags[i].page = page;
2754 skb_shinfo(skb)->frags[i].page_offset = 0;
2755 skb_shinfo(skb)->frags[i].size =
Luiz Capitulino222f1802006-03-20 22:16:13 -08002756 (datalen < PAGE_SIZE ? datalen : PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 datalen -= skb_shinfo(skb)->frags[i].size;
2758 skb->len += skb_shinfo(skb)->frags[i].size;
2759 skb->data_len += skb_shinfo(skb)->frags[i].size;
2760 i++;
2761 skb_shinfo(skb)->nr_frags = i;
2762 }
2763
2764 while (i < frags) {
2765 int rem;
2766
2767 if (i == 0)
2768 break;
2769
2770 rem = skb_shinfo(skb)->frags[i - 1].size / 2;
2771 if (rem == 0)
2772 break;
2773
2774 skb_shinfo(skb)->frags[i - 1].size -= rem;
2775
Luiz Capitulino222f1802006-03-20 22:16:13 -08002776 skb_shinfo(skb)->frags[i] =
2777 skb_shinfo(skb)->frags[i - 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 get_page(skb_shinfo(skb)->frags[i].page);
Luiz Capitulino222f1802006-03-20 22:16:13 -08002779 skb_shinfo(skb)->frags[i].page =
2780 skb_shinfo(skb)->frags[i - 1].page;
2781 skb_shinfo(skb)->frags[i].page_offset +=
2782 skb_shinfo(skb)->frags[i - 1].size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 skb_shinfo(skb)->frags[i].size = rem;
2784 i++;
2785 skb_shinfo(skb)->nr_frags = i;
2786 }
2787 }
2788
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00002789 /* Stamp the time, and sequence number,
2790 * convert them to network byte order
2791 */
Luiz Capitulino222f1802006-03-20 22:16:13 -08002792 if (pgh) {
2793 struct timeval timestamp;
2794
2795 pgh->pgh_magic = htonl(PKTGEN_MAGIC);
2796 pgh->seq_num = htonl(pkt_dev->seq_num);
2797
2798 do_gettimeofday(&timestamp);
2799 pgh->tv_sec = htonl(timestamp.tv_sec);
2800 pgh->tv_usec = htonl(timestamp.tv_usec);
2801 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08002802
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002803#ifdef CONFIG_XFRM
2804 if (!process_ipsec(pkt_dev, skb, protocol))
2805 return NULL;
2806#endif
2807
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808 return skb;
2809}
2810
2811/*
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09002812 * scan_ip6, fmt_ip taken from dietlibc-0.21
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 * Author Felix von Leitner <felix-dietlibc@fefe.de>
2814 *
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09002815 * Slightly modified for kernel.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816 * Should be candidate for net/ipv4/utils.c
2817 * --ro
2818 */
2819
Luiz Capitulino222f1802006-03-20 22:16:13 -08002820static unsigned int scan_ip6(const char *s, char ip[16])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821{
2822 unsigned int i;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002823 unsigned int len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 unsigned long u;
2825 char suffix[16];
Luiz Capitulino222f1802006-03-20 22:16:13 -08002826 unsigned int prefixlen = 0;
2827 unsigned int suffixlen = 0;
Al Viro252e3342006-11-14 20:48:11 -08002828 __be32 tmp;
Stephen Hemmingercfcabdc2007-10-09 01:59:42 -07002829 char *pos;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830
Luiz Capitulino222f1802006-03-20 22:16:13 -08002831 for (i = 0; i < 16; i++)
2832 ip[i] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833
2834 for (;;) {
2835 if (*s == ':') {
2836 len++;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002837 if (s[1] == ':') { /* Found "::", skip to part 2 */
2838 s += 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839 len++;
2840 break;
2841 }
2842 s++;
2843 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844
Stephen Hemmingercfcabdc2007-10-09 01:59:42 -07002845 u = simple_strtoul(s, &pos, 16);
2846 i = pos - s;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002847 if (!i)
2848 return 0;
2849 if (prefixlen == 12 && s[i] == '.') {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850
2851 /* the last 4 bytes may be written as IPv4 address */
2852
2853 tmp = in_aton(s);
Luiz Capitulino222f1802006-03-20 22:16:13 -08002854 memcpy((struct in_addr *)(ip + 12), &tmp, sizeof(tmp));
2855 return i + len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 }
2857 ip[prefixlen++] = (u >> 8);
2858 ip[prefixlen++] = (u & 255);
Luiz Capitulino222f1802006-03-20 22:16:13 -08002859 s += i;
2860 len += i;
2861 if (prefixlen == 16)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862 return len;
2863 }
2864
2865/* part 2, after "::" */
2866 for (;;) {
2867 if (*s == ':') {
Luiz Capitulino222f1802006-03-20 22:16:13 -08002868 if (suffixlen == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 break;
2870 s++;
2871 len++;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002872 } else if (suffixlen != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873 break;
Stephen Hemmingercfcabdc2007-10-09 01:59:42 -07002874
2875 u = simple_strtol(s, &pos, 16);
2876 i = pos - s;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 if (!i) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08002878 if (*s)
2879 len--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 break;
2881 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08002882 if (suffixlen + prefixlen <= 12 && s[i] == '.') {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 tmp = in_aton(s);
Luiz Capitulino222f1802006-03-20 22:16:13 -08002884 memcpy((struct in_addr *)(suffix + suffixlen), &tmp,
2885 sizeof(tmp));
2886 suffixlen += 4;
2887 len += strlen(s);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 break;
2889 }
2890 suffix[suffixlen++] = (u >> 8);
2891 suffix[suffixlen++] = (u & 255);
Luiz Capitulino222f1802006-03-20 22:16:13 -08002892 s += i;
2893 len += i;
2894 if (prefixlen + suffixlen == 16)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895 break;
2896 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08002897 for (i = 0; i < suffixlen; i++)
2898 ip[16 - suffixlen + i] = suffix[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 return len;
2900}
2901
Luiz Capitulino222f1802006-03-20 22:16:13 -08002902static char tohex(char hexdigit)
2903{
2904 return hexdigit > 9 ? hexdigit + 'a' - 10 : hexdigit + '0';
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905}
2906
Luiz Capitulino222f1802006-03-20 22:16:13 -08002907static int fmt_xlong(char *s, unsigned int i)
2908{
2909 char *bak = s;
2910 *s = tohex((i >> 12) & 0xf);
2911 if (s != bak || *s != '0')
2912 ++s;
2913 *s = tohex((i >> 8) & 0xf);
2914 if (s != bak || *s != '0')
2915 ++s;
2916 *s = tohex((i >> 4) & 0xf);
2917 if (s != bak || *s != '0')
2918 ++s;
2919 *s = tohex(i & 0xf);
2920 return s - bak + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921}
2922
Luiz Capitulino222f1802006-03-20 22:16:13 -08002923static unsigned int fmt_ip6(char *s, const char ip[16])
2924{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 unsigned int len;
2926 unsigned int i;
2927 unsigned int temp;
2928 unsigned int compressing;
2929 int j;
2930
Luiz Capitulino222f1802006-03-20 22:16:13 -08002931 len = 0;
2932 compressing = 0;
2933 for (j = 0; j < 16; j += 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934
2935#ifdef V4MAPPEDPREFIX
Luiz Capitulino222f1802006-03-20 22:16:13 -08002936 if (j == 12 && !memcmp(ip, V4mappedprefix, 12)) {
2937 inet_ntoa_r(*(struct in_addr *)(ip + 12), s);
2938 temp = strlen(s);
2939 return len + temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 }
2941#endif
Luiz Capitulino222f1802006-03-20 22:16:13 -08002942 temp = ((unsigned long)(unsigned char)ip[j] << 8) +
2943 (unsigned long)(unsigned char)ip[j + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 if (temp == 0) {
2945 if (!compressing) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08002946 compressing = 1;
2947 if (j == 0) {
2948 *s++ = ':';
2949 ++len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 }
2951 }
2952 } else {
2953 if (compressing) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08002954 compressing = 0;
2955 *s++ = ':';
2956 ++len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08002958 i = fmt_xlong(s, temp);
2959 len += i;
2960 s += i;
2961 if (j < 14) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 *s++ = ':';
2963 ++len;
2964 }
2965 }
2966 }
2967 if (compressing) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08002968 *s++ = ':';
2969 ++len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08002971 *s = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 return len;
2973}
2974
Luiz Capitulino222f1802006-03-20 22:16:13 -08002975static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
2976 struct pktgen_dev *pkt_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977{
2978 struct sk_buff *skb = NULL;
2979 __u8 *eth;
2980 struct udphdr *udph;
2981 int datalen;
2982 struct ipv6hdr *iph;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002983 struct pktgen_hdr *pgh = NULL;
Stephen Hemmingerd5f1ce92007-03-04 16:08:08 -08002984 __be16 protocol = htons(ETH_P_IPV6);
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002985 __be32 *mpls;
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002986 __be16 *vlan_tci = NULL; /* Encapsulates priority and VLAN ID */
2987 __be16 *vlan_encapsulated_proto = NULL; /* packet type ID field (or len) for VLAN tag */
2988 __be16 *svlan_tci = NULL; /* Encapsulates priority and SVLAN ID */
2989 __be16 *svlan_encapsulated_proto = NULL; /* packet type ID field (or len) for SVLAN tag */
David S. Millerfd2ea0a2008-07-17 01:56:23 -07002990 u16 queue_map;
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002991
2992 if (pkt_dev->nr_labels)
Stephen Hemmingerd5f1ce92007-03-04 16:08:08 -08002993 protocol = htons(ETH_P_MPLS_UC);
Robert Olsson64053be2005-06-26 15:27:10 -07002994
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002995 if (pkt_dev->vlan_id != 0xffff)
Stephen Hemmingerd5f1ce92007-03-04 16:08:08 -08002996 protocol = htons(ETH_P_8021Q);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002997
Robert Olsson64053be2005-06-26 15:27:10 -07002998 /* Update any of the values, used when we're incrementing various
2999 * fields.
3000 */
3001 mod_cur_headers(pkt_dev);
Junchang Wangeb589062010-11-07 23:19:43 +00003002 queue_map = pkt_dev->cur_queue_map;
Robert Olsson64053be2005-06-26 15:27:10 -07003003
Stephen Hemmingere4707572009-08-27 13:55:13 +00003004 skb = __netdev_alloc_skb(odev,
3005 pkt_dev->cur_pkt_size + 64
3006 + 16 + pkt_dev->pkt_overhead, GFP_NOWAIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 if (!skb) {
3008 sprintf(pkt_dev->result, "No memory");
3009 return NULL;
3010 }
Junchang Wanga8d764b2010-12-08 16:55:16 +00003011 prefetchw(skb->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012
3013 skb_reserve(skb, 16);
3014
3015 /* Reserve for ethernet and IP header */
3016 eth = (__u8 *) skb_push(skb, 14);
Steven Whitehouseca6549a2006-03-23 01:10:26 -08003017 mpls = (__be32 *)skb_put(skb, pkt_dev->nr_labels*sizeof(__u32));
3018 if (pkt_dev->nr_labels)
3019 mpls_push(mpls, pkt_dev);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07003020
3021 if (pkt_dev->vlan_id != 0xffff) {
Stephen Hemmingere71a4782007-04-10 20:10:33 -07003022 if (pkt_dev->svlan_id != 0xffff) {
Francesco Fondelli34954dd2006-09-27 16:30:44 -07003023 svlan_tci = (__be16 *)skb_put(skb, sizeof(__be16));
Al Viro0f37c602006-11-03 03:49:56 -08003024 *svlan_tci = build_tci(pkt_dev->svlan_id,
3025 pkt_dev->svlan_cfi,
3026 pkt_dev->svlan_p);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07003027 svlan_encapsulated_proto = (__be16 *)skb_put(skb, sizeof(__be16));
Stephen Hemmingerd5f1ce92007-03-04 16:08:08 -08003028 *svlan_encapsulated_proto = htons(ETH_P_8021Q);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07003029 }
3030 vlan_tci = (__be16 *)skb_put(skb, sizeof(__be16));
Al Viro0f37c602006-11-03 03:49:56 -08003031 *vlan_tci = build_tci(pkt_dev->vlan_id,
3032 pkt_dev->vlan_cfi,
3033 pkt_dev->vlan_p);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07003034 vlan_encapsulated_proto = (__be16 *)skb_put(skb, sizeof(__be16));
Stephen Hemmingerd5f1ce92007-03-04 16:08:08 -08003035 *vlan_encapsulated_proto = htons(ETH_P_IPV6);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07003036 }
3037
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07003038 skb->network_header = skb->tail;
Arnaldo Carvalho de Melob0e380b2007-04-10 21:21:55 -07003039 skb->transport_header = skb->network_header + sizeof(struct ipv6hdr);
Arnaldo Carvalho de Meloddc7b8e2007-03-15 21:42:27 -03003040 skb_put(skb, sizeof(struct ipv6hdr) + sizeof(struct udphdr));
David S. Millerfd2ea0a2008-07-17 01:56:23 -07003041 skb_set_queue_mapping(skb, queue_map);
John Fastabend9e50e3a2010-11-16 19:12:28 +00003042 skb->priority = pkt_dev->skb_priority;
Arnaldo Carvalho de Meloddc7b8e2007-03-15 21:42:27 -03003043 iph = ipv6_hdr(skb);
3044 udph = udp_hdr(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 memcpy(eth, pkt_dev->hh, 12);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00003047 *(__be16 *) &eth[12] = protocol;
Robert Olsson64053be2005-06-26 15:27:10 -07003048
Steven Whitehouseca6549a2006-03-23 01:10:26 -08003049 /* Eth + IPh + UDPh + mpls */
3050 datalen = pkt_dev->cur_pkt_size - 14 -
3051 sizeof(struct ipv6hdr) - sizeof(struct udphdr) -
Jamal Hadi Salim16dab722007-07-02 22:39:50 -07003052 pkt_dev->pkt_overhead;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053
Luiz Capitulino222f1802006-03-20 22:16:13 -08003054 if (datalen < sizeof(struct pktgen_hdr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 datalen = sizeof(struct pktgen_hdr);
3056 if (net_ratelimit())
Joe Perchesf9467ea2010-06-21 12:29:14 +00003057 pr_info("increased datalen to %d\n", datalen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 }
3059
3060 udph->source = htons(pkt_dev->cur_udp_src);
3061 udph->dest = htons(pkt_dev->cur_udp_dst);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003062 udph->len = htons(datalen + sizeof(struct udphdr));
3063 udph->check = 0; /* No checksum */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064
Stephen Hemmingerd5f1ce92007-03-04 16:08:08 -08003065 *(__be32 *) iph = htonl(0x60000000); /* Version + flow */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066
Francesco Fondelli1ca77682006-09-27 16:32:03 -07003067 if (pkt_dev->traffic_class) {
3068 /* Version + traffic class + flow (0) */
Al Viro252e3342006-11-14 20:48:11 -08003069 *(__be32 *)iph |= htonl(0x60000000 | (pkt_dev->traffic_class << 20));
Francesco Fondelli1ca77682006-09-27 16:32:03 -07003070 }
3071
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 iph->hop_limit = 32;
3073
3074 iph->payload_len = htons(sizeof(struct udphdr) + datalen);
3075 iph->nexthdr = IPPROTO_UDP;
3076
3077 ipv6_addr_copy(&iph->daddr, &pkt_dev->cur_in6_daddr);
3078 ipv6_addr_copy(&iph->saddr, &pkt_dev->cur_in6_saddr);
3079
Arnaldo Carvalho de Melob0e380b2007-04-10 21:21:55 -07003080 skb->mac_header = (skb->network_header - ETH_HLEN -
Jamal Hadi Salim16dab722007-07-02 22:39:50 -07003081 pkt_dev->pkt_overhead);
Steven Whitehouseca6549a2006-03-23 01:10:26 -08003082 skb->protocol = protocol;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083 skb->dev = odev;
3084 skb->pkt_type = PACKET_HOST;
3085
Luiz Capitulino222f1802006-03-20 22:16:13 -08003086 if (pkt_dev->nfrags <= 0)
3087 pgh = (struct pktgen_hdr *)skb_put(skb, datalen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088 else {
3089 int frags = pkt_dev->nfrags;
3090 int i;
3091
Luiz Capitulino222f1802006-03-20 22:16:13 -08003092 pgh = (struct pktgen_hdr *)(((char *)(udph)) + 8);
3093
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 if (frags > MAX_SKB_FRAGS)
3095 frags = MAX_SKB_FRAGS;
Luiz Capitulino222f1802006-03-20 22:16:13 -08003096 if (datalen > frags * PAGE_SIZE) {
3097 skb_put(skb, datalen - frags * PAGE_SIZE);
3098 datalen = frags * PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 }
3100
3101 i = 0;
3102 while (datalen > 0) {
3103 struct page *page = alloc_pages(GFP_KERNEL, 0);
3104 skb_shinfo(skb)->frags[i].page = page;
3105 skb_shinfo(skb)->frags[i].page_offset = 0;
3106 skb_shinfo(skb)->frags[i].size =
Luiz Capitulino222f1802006-03-20 22:16:13 -08003107 (datalen < PAGE_SIZE ? datalen : PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 datalen -= skb_shinfo(skb)->frags[i].size;
3109 skb->len += skb_shinfo(skb)->frags[i].size;
3110 skb->data_len += skb_shinfo(skb)->frags[i].size;
3111 i++;
3112 skb_shinfo(skb)->nr_frags = i;
3113 }
3114
3115 while (i < frags) {
3116 int rem;
3117
3118 if (i == 0)
3119 break;
3120
3121 rem = skb_shinfo(skb)->frags[i - 1].size / 2;
3122 if (rem == 0)
3123 break;
3124
3125 skb_shinfo(skb)->frags[i - 1].size -= rem;
3126
Luiz Capitulino222f1802006-03-20 22:16:13 -08003127 skb_shinfo(skb)->frags[i] =
3128 skb_shinfo(skb)->frags[i - 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129 get_page(skb_shinfo(skb)->frags[i].page);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003130 skb_shinfo(skb)->frags[i].page =
3131 skb_shinfo(skb)->frags[i - 1].page;
3132 skb_shinfo(skb)->frags[i].page_offset +=
3133 skb_shinfo(skb)->frags[i - 1].size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134 skb_shinfo(skb)->frags[i].size = rem;
3135 i++;
3136 skb_shinfo(skb)->nr_frags = i;
3137 }
3138 }
3139
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00003140 /* Stamp the time, and sequence number,
3141 * convert them to network byte order
3142 * should we update cloned packets too ?
3143 */
Luiz Capitulino222f1802006-03-20 22:16:13 -08003144 if (pgh) {
3145 struct timeval timestamp;
3146
3147 pgh->pgh_magic = htonl(PKTGEN_MAGIC);
3148 pgh->seq_num = htonl(pkt_dev->seq_num);
3149
3150 do_gettimeofday(&timestamp);
3151 pgh->tv_sec = htonl(timestamp.tv_sec);
3152 pgh->tv_usec = htonl(timestamp.tv_usec);
3153 }
Francesco Fondelli34954dd2006-09-27 16:30:44 -07003154 /* pkt_dev->seq_num++; FF: you really mean this? */
Luiz Capitulino222f1802006-03-20 22:16:13 -08003155
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156 return skb;
3157}
3158
Stephen Hemminger475ac1e2009-08-27 13:55:08 +00003159static struct sk_buff *fill_packet(struct net_device *odev,
3160 struct pktgen_dev *pkt_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161{
Luiz Capitulino222f1802006-03-20 22:16:13 -08003162 if (pkt_dev->flags & F_IPV6)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163 return fill_packet_ipv6(odev, pkt_dev);
3164 else
3165 return fill_packet_ipv4(odev, pkt_dev);
3166}
3167
Luiz Capitulino222f1802006-03-20 22:16:13 -08003168static void pktgen_clear_counters(struct pktgen_dev *pkt_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169{
Luiz Capitulino222f1802006-03-20 22:16:13 -08003170 pkt_dev->seq_num = 1;
3171 pkt_dev->idle_acc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 pkt_dev->sofar = 0;
Luiz Capitulino222f1802006-03-20 22:16:13 -08003173 pkt_dev->tx_bytes = 0;
3174 pkt_dev->errors = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175}
3176
3177/* Set up structure for sending pkts, clear counters */
3178
3179static void pktgen_run(struct pktgen_thread *t)
3180{
Luiz Capitulinoc26a8012006-03-20 22:18:16 -08003181 struct pktgen_dev *pkt_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182 int started = 0;
3183
Joe Perchesf9467ea2010-06-21 12:29:14 +00003184 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185
3186 if_lock(t);
Luiz Capitulinoc26a8012006-03-20 22:18:16 -08003187 list_for_each_entry(pkt_dev, &t->if_list, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188
3189 /*
3190 * setup odev and create initial packet.
3191 */
3192 pktgen_setup_inject(pkt_dev);
3193
Luiz Capitulino222f1802006-03-20 22:16:13 -08003194 if (pkt_dev->odev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195 pktgen_clear_counters(pkt_dev);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003196 pkt_dev->running = 1; /* Cranke yeself! */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197 pkt_dev->skb = NULL;
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00003198 pkt_dev->started_at =
3199 pkt_dev->next_tx = ktime_now();
3200
Jamal Hadi Salim16dab722007-07-02 22:39:50 -07003201 set_pkt_overhead(pkt_dev);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003202
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203 strcpy(pkt_dev->result, "Starting");
3204 started++;
Luiz Capitulino222f1802006-03-20 22:16:13 -08003205 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 strcpy(pkt_dev->result, "Error starting");
3207 }
3208 if_unlock(t);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003209 if (started)
3210 t->control &= ~(T_STOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211}
3212
3213static void pktgen_stop_all_threads_ifs(void)
3214{
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003215 struct pktgen_thread *t;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216
Joe Perchesf9467ea2010-06-21 12:29:14 +00003217 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08003219 mutex_lock(&pktgen_thread_lock);
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003220
3221 list_for_each_entry(t, &pktgen_threads, th_list)
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003222 t->control |= T_STOP;
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003223
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08003224 mutex_unlock(&pktgen_thread_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225}
3226
Stephen Hemminger648fda72009-08-27 13:55:07 +00003227static int thread_is_running(const struct pktgen_thread *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228{
Stephen Hemminger648fda72009-08-27 13:55:07 +00003229 const struct pktgen_dev *pkt_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230
Luiz Capitulinoc26a8012006-03-20 22:18:16 -08003231 list_for_each_entry(pkt_dev, &t->if_list, list)
Stephen Hemminger648fda72009-08-27 13:55:07 +00003232 if (pkt_dev->running)
3233 return 1;
3234 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235}
3236
Luiz Capitulino222f1802006-03-20 22:16:13 -08003237static int pktgen_wait_thread_run(struct pktgen_thread *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238{
Luiz Capitulino222f1802006-03-20 22:16:13 -08003239 if_lock(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240
Luiz Capitulino222f1802006-03-20 22:16:13 -08003241 while (thread_is_running(t)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242
Luiz Capitulino222f1802006-03-20 22:16:13 -08003243 if_unlock(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244
Luiz Capitulino222f1802006-03-20 22:16:13 -08003245 msleep_interruptible(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246
Luiz Capitulino222f1802006-03-20 22:16:13 -08003247 if (signal_pending(current))
3248 goto signal;
3249 if_lock(t);
3250 }
3251 if_unlock(t);
3252 return 1;
3253signal:
3254 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255}
3256
3257static int pktgen_wait_all_threads_run(void)
3258{
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003259 struct pktgen_thread *t;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260 int sig = 1;
Luiz Capitulino222f1802006-03-20 22:16:13 -08003261
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08003262 mutex_lock(&pktgen_thread_lock);
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003263
3264 list_for_each_entry(t, &pktgen_threads, th_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 sig = pktgen_wait_thread_run(t);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003266 if (sig == 0)
3267 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268 }
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003269
3270 if (sig == 0)
3271 list_for_each_entry(t, &pktgen_threads, th_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 t->control |= (T_STOP);
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003273
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08003274 mutex_unlock(&pktgen_thread_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275 return sig;
3276}
3277
3278static void pktgen_run_all_threads(void)
3279{
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003280 struct pktgen_thread *t;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281
Joe Perchesf9467ea2010-06-21 12:29:14 +00003282 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08003284 mutex_lock(&pktgen_thread_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003286 list_for_each_entry(t, &pktgen_threads, th_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287 t->control |= (T_RUN);
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003288
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08003289 mutex_unlock(&pktgen_thread_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00003291 /* Propagate thread->control */
3292 schedule_timeout_interruptible(msecs_to_jiffies(125));
Luiz Capitulino222f1802006-03-20 22:16:13 -08003293
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 pktgen_wait_all_threads_run();
3295}
3296
Jesse Brandeburgeb37b412008-11-10 16:48:03 -08003297static void pktgen_reset_all_threads(void)
3298{
3299 struct pktgen_thread *t;
3300
Joe Perchesf9467ea2010-06-21 12:29:14 +00003301 func_enter();
Jesse Brandeburgeb37b412008-11-10 16:48:03 -08003302
3303 mutex_lock(&pktgen_thread_lock);
3304
3305 list_for_each_entry(t, &pktgen_threads, th_list)
3306 t->control |= (T_REMDEVALL);
3307
3308 mutex_unlock(&pktgen_thread_lock);
3309
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00003310 /* Propagate thread->control */
3311 schedule_timeout_interruptible(msecs_to_jiffies(125));
Jesse Brandeburgeb37b412008-11-10 16:48:03 -08003312
3313 pktgen_wait_all_threads_run();
3314}
3315
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316static void show_results(struct pktgen_dev *pkt_dev, int nr_frags)
3317{
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00003318 __u64 bps, mbps, pps;
Luiz Capitulino222f1802006-03-20 22:16:13 -08003319 char *p = pkt_dev->result;
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00003320 ktime_t elapsed = ktime_sub(pkt_dev->stopped_at,
3321 pkt_dev->started_at);
3322 ktime_t idle = ns_to_ktime(pkt_dev->idle_acc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00003324 p += sprintf(p, "OK: %llu(c%llu+d%llu) nsec, %llu (%dbyte,%dfrags)\n",
3325 (unsigned long long)ktime_to_us(elapsed),
3326 (unsigned long long)ktime_to_us(ktime_sub(elapsed, idle)),
3327 (unsigned long long)ktime_to_us(idle),
Luiz Capitulino222f1802006-03-20 22:16:13 -08003328 (unsigned long long)pkt_dev->sofar,
3329 pkt_dev->cur_pkt_size, nr_frags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00003331 pps = div64_u64(pkt_dev->sofar * NSEC_PER_SEC,
3332 ktime_to_ns(elapsed));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333
Luiz Capitulino222f1802006-03-20 22:16:13 -08003334 bps = pps * 8 * pkt_dev->cur_pkt_size;
3335
3336 mbps = bps;
3337 do_div(mbps, 1000000);
3338 p += sprintf(p, " %llupps %lluMb/sec (%llubps) errors: %llu",
3339 (unsigned long long)pps,
3340 (unsigned long long)mbps,
3341 (unsigned long long)bps,
3342 (unsigned long long)pkt_dev->errors);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344
3345/* Set stopped-at timer, remove from running list, do counters & statistics */
Luiz Capitulino222f1802006-03-20 22:16:13 -08003346static int pktgen_stop_device(struct pktgen_dev *pkt_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003347{
Luiz Capitulino222f1802006-03-20 22:16:13 -08003348 int nr_frags = pkt_dev->skb ? skb_shinfo(pkt_dev->skb)->nr_frags : -1;
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003349
Luiz Capitulino222f1802006-03-20 22:16:13 -08003350 if (!pkt_dev->running) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00003351 pr_warning("interface: %s is already stopped\n",
3352 pkt_dev->odevname);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003353 return -EINVAL;
3354 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355
Stephen Hemminger3bda06a2009-08-27 13:55:10 +00003356 kfree_skb(pkt_dev->skb);
3357 pkt_dev->skb = NULL;
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00003358 pkt_dev->stopped_at = ktime_now();
Luiz Capitulino222f1802006-03-20 22:16:13 -08003359 pkt_dev->running = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003361 show_results(pkt_dev, nr_frags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362
Luiz Capitulino222f1802006-03-20 22:16:13 -08003363 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364}
3365
Luiz Capitulino222f1802006-03-20 22:16:13 -08003366static struct pktgen_dev *next_to_run(struct pktgen_thread *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367{
Luiz Capitulinoc26a8012006-03-20 22:18:16 -08003368 struct pktgen_dev *pkt_dev, *best = NULL;
Luiz Capitulino222f1802006-03-20 22:16:13 -08003369
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370 if_lock(t);
3371
Luiz Capitulinoc26a8012006-03-20 22:18:16 -08003372 list_for_each_entry(pkt_dev, &t->if_list, list) {
3373 if (!pkt_dev->running)
Luiz Capitulino222f1802006-03-20 22:16:13 -08003374 continue;
3375 if (best == NULL)
Luiz Capitulinoc26a8012006-03-20 22:18:16 -08003376 best = pkt_dev;
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00003377 else if (ktime_lt(pkt_dev->next_tx, best->next_tx))
Luiz Capitulinoc26a8012006-03-20 22:18:16 -08003378 best = pkt_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379 }
3380 if_unlock(t);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003381 return best;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382}
3383
Luiz Capitulino222f1802006-03-20 22:16:13 -08003384static void pktgen_stop(struct pktgen_thread *t)
3385{
Luiz Capitulinoc26a8012006-03-20 22:18:16 -08003386 struct pktgen_dev *pkt_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387
Joe Perchesf9467ea2010-06-21 12:29:14 +00003388 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389
Luiz Capitulino222f1802006-03-20 22:16:13 -08003390 if_lock(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391
Luiz Capitulinoc26a8012006-03-20 22:18:16 -08003392 list_for_each_entry(pkt_dev, &t->if_list, list) {
3393 pktgen_stop_device(pkt_dev);
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003394 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395
Luiz Capitulino222f1802006-03-20 22:16:13 -08003396 if_unlock(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397}
3398
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003399/*
3400 * one of our devices needs to be removed - find it
3401 * and remove it
3402 */
3403static void pktgen_rem_one_if(struct pktgen_thread *t)
3404{
Luiz Capitulinoc26a8012006-03-20 22:18:16 -08003405 struct list_head *q, *n;
3406 struct pktgen_dev *cur;
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003407
Joe Perchesf9467ea2010-06-21 12:29:14 +00003408 func_enter();
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003409
3410 if_lock(t);
3411
Luiz Capitulinoc26a8012006-03-20 22:18:16 -08003412 list_for_each_safe(q, n, &t->if_list) {
3413 cur = list_entry(q, struct pktgen_dev, list);
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003414
Luiz Capitulino222f1802006-03-20 22:16:13 -08003415 if (!cur->removal_mark)
3416 continue;
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003417
Wei Yongjun86dc1ad2009-02-25 00:31:54 +00003418 kfree_skb(cur->skb);
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003419 cur->skb = NULL;
3420
3421 pktgen_remove_device(t, cur);
3422
3423 break;
3424 }
3425
3426 if_unlock(t);
3427}
3428
Luiz Capitulino222f1802006-03-20 22:16:13 -08003429static void pktgen_rem_all_ifs(struct pktgen_thread *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430{
Luiz Capitulinoc26a8012006-03-20 22:18:16 -08003431 struct list_head *q, *n;
3432 struct pktgen_dev *cur;
Luiz Capitulino222f1802006-03-20 22:16:13 -08003433
Joe Perchesf9467ea2010-06-21 12:29:14 +00003434 func_enter();
3435
Luiz Capitulino222f1802006-03-20 22:16:13 -08003436 /* Remove all devices, free mem */
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003437
Luiz Capitulino222f1802006-03-20 22:16:13 -08003438 if_lock(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439
Luiz Capitulinoc26a8012006-03-20 22:18:16 -08003440 list_for_each_safe(q, n, &t->if_list) {
3441 cur = list_entry(q, struct pktgen_dev, list);
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003442
Wei Yongjun86dc1ad2009-02-25 00:31:54 +00003443 kfree_skb(cur->skb);
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003444 cur->skb = NULL;
3445
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446 pktgen_remove_device(t, cur);
3447 }
3448
Luiz Capitulino222f1802006-03-20 22:16:13 -08003449 if_unlock(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450}
3451
Luiz Capitulino222f1802006-03-20 22:16:13 -08003452static void pktgen_rem_thread(struct pktgen_thread *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453{
Luiz Capitulino222f1802006-03-20 22:16:13 -08003454 /* Remove from the thread list */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455
David S. Milleree74baa2007-01-01 20:51:53 -08003456 remove_proc_entry(t->tsk->comm, pg_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458}
3459
Stephen Hemmingeref879792009-09-22 19:41:43 +00003460static void pktgen_resched(struct pktgen_dev *pkt_dev)
Stephen Hemminger3791dec2009-08-27 13:55:11 +00003461{
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00003462 ktime_t idle_start = ktime_now();
Stephen Hemmingeref879792009-09-22 19:41:43 +00003463 schedule();
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00003464 pkt_dev->idle_acc += ktime_to_ns(ktime_sub(ktime_now(), idle_start));
Stephen Hemminger3791dec2009-08-27 13:55:11 +00003465}
3466
Stephen Hemmingeref879792009-09-22 19:41:43 +00003467static void pktgen_wait_for_skb(struct pktgen_dev *pkt_dev)
3468{
3469 ktime_t idle_start = ktime_now();
3470
3471 while (atomic_read(&(pkt_dev->skb->users)) != 1) {
3472 if (signal_pending(current))
3473 break;
3474
3475 if (need_resched())
3476 pktgen_resched(pkt_dev);
3477 else
3478 cpu_relax();
3479 }
3480 pkt_dev->idle_acc += ktime_to_ns(ktime_sub(ktime_now(), idle_start));
3481}
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00003482
Stephen Hemminger475ac1e2009-08-27 13:55:08 +00003483static void pktgen_xmit(struct pktgen_dev *pkt_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484{
Stephen Hemminger00829822008-11-20 20:14:53 -08003485 struct net_device *odev = pkt_dev->odev;
Stephen Hemminger6fef4c02009-08-31 19:50:41 +00003486 netdev_tx_t (*xmit)(struct sk_buff *, struct net_device *)
Stephen Hemminger00829822008-11-20 20:14:53 -08003487 = odev->netdev_ops->ndo_start_xmit;
David S. Millerfd2ea0a2008-07-17 01:56:23 -07003488 struct netdev_queue *txq;
David S. Millerfd2ea0a2008-07-17 01:56:23 -07003489 u16 queue_map;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490 int ret;
3491
Stephen Hemmingeref879792009-09-22 19:41:43 +00003492 /* If device is offline, then don't send */
3493 if (unlikely(!netif_running(odev) || !netif_carrier_ok(odev))) {
3494 pktgen_stop_device(pkt_dev);
Stephen Hemminger3791dec2009-08-27 13:55:11 +00003495 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08003497
Stephen Hemmingeref879792009-09-22 19:41:43 +00003498 /* This is max DELAY, this has special meaning of
3499 * "never transmit"
3500 */
3501 if (unlikely(pkt_dev->delay == ULLONG_MAX)) {
3502 pkt_dev->next_tx = ktime_add_ns(ktime_now(), ULONG_MAX);
3503 return;
3504 }
3505
3506 /* If no skb or clone count exhausted then get new one */
Stephen Hemminger7d7bb1c2009-08-27 13:55:12 +00003507 if (!pkt_dev->skb || (pkt_dev->last_ok &&
3508 ++pkt_dev->clone_count >= pkt_dev->clone_skb)) {
3509 /* build a new pkt */
3510 kfree_skb(pkt_dev->skb);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003511
Stephen Hemminger7d7bb1c2009-08-27 13:55:12 +00003512 pkt_dev->skb = fill_packet(odev, pkt_dev);
3513 if (pkt_dev->skb == NULL) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00003514 pr_err("ERROR: couldn't allocate skb in fill_packet\n");
Stephen Hemminger7d7bb1c2009-08-27 13:55:12 +00003515 schedule();
3516 pkt_dev->clone_count--; /* back out increment, OOM */
3517 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 }
Eric Dumazetbaac8562009-11-05 21:04:32 -08003519 pkt_dev->last_pkt_size = pkt_dev->skb->len;
Stephen Hemminger7d7bb1c2009-08-27 13:55:12 +00003520 pkt_dev->allocated_skbs++;
3521 pkt_dev->clone_count = 0; /* reset counter */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522 }
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003523
Stephen Hemmingeref879792009-09-22 19:41:43 +00003524 if (pkt_dev->delay && pkt_dev->last_ok)
3525 spin(pkt_dev, pkt_dev->next_tx);
3526
David S. Millerfd2ea0a2008-07-17 01:56:23 -07003527 queue_map = skb_get_queue_mapping(pkt_dev->skb);
3528 txq = netdev_get_tx_queue(odev, queue_map);
3529
3530 __netif_tx_lock_bh(txq);
Stephen Hemmingeref879792009-09-22 19:41:43 +00003531
Eric Dumazet5a0d2262010-11-23 10:42:02 +00003532 if (unlikely(netif_tx_queue_frozen_or_stopped(txq))) {
Stephen Hemmingeref879792009-09-22 19:41:43 +00003533 ret = NETDEV_TX_BUSY;
Eric Dumazet0835acf2009-09-30 13:03:33 +00003534 pkt_dev->last_ok = 0;
3535 goto unlock;
3536 }
3537 atomic_inc(&(pkt_dev->skb->users));
3538 ret = (*xmit)(pkt_dev->skb, odev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539
Stephen Hemmingeref879792009-09-22 19:41:43 +00003540 switch (ret) {
3541 case NETDEV_TX_OK:
3542 txq_trans_update(txq);
3543 pkt_dev->last_ok = 1;
3544 pkt_dev->sofar++;
3545 pkt_dev->seq_num++;
Eric Dumazetbaac8562009-11-05 21:04:32 -08003546 pkt_dev->tx_bytes += pkt_dev->last_pkt_size;
Stephen Hemmingeref879792009-09-22 19:41:43 +00003547 break;
John Fastabendf466dba2009-12-23 22:02:57 -08003548 case NET_XMIT_DROP:
3549 case NET_XMIT_CN:
3550 case NET_XMIT_POLICED:
3551 /* skb has been consumed */
3552 pkt_dev->errors++;
3553 break;
Stephen Hemmingeref879792009-09-22 19:41:43 +00003554 default: /* Drivers are not supposed to return other values! */
3555 if (net_ratelimit())
Joe Perches58231182010-12-20 10:30:06 -08003556 pr_info("%s xmit error: %d\n", pkt_dev->odevname, ret);
Stephen Hemmingeref879792009-09-22 19:41:43 +00003557 pkt_dev->errors++;
3558 /* fallthru */
3559 case NETDEV_TX_LOCKED:
3560 case NETDEV_TX_BUSY:
3561 /* Retry it next time */
3562 atomic_dec(&(pkt_dev->skb->users));
3563 pkt_dev->last_ok = 0;
Luiz Capitulino222f1802006-03-20 22:16:13 -08003564 }
Eric Dumazet0835acf2009-09-30 13:03:33 +00003565unlock:
David S. Millerfd2ea0a2008-07-17 01:56:23 -07003566 __netif_tx_unlock_bh(txq);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003567
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568 /* If pkt_dev->count is zero, then run forever */
3569 if ((pkt_dev->count != 0) && (pkt_dev->sofar >= pkt_dev->count)) {
Stephen Hemmingeref879792009-09-22 19:41:43 +00003570 pktgen_wait_for_skb(pkt_dev);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003571
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572 /* Done with this */
3573 pktgen_stop_device(pkt_dev);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003574 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08003575}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09003577/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578 * Main loop of the thread goes here
3579 */
3580
David S. Milleree74baa2007-01-01 20:51:53 -08003581static int pktgen_thread_worker(void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003582{
3583 DEFINE_WAIT(wait);
David S. Milleree74baa2007-01-01 20:51:53 -08003584 struct pktgen_thread *t = arg;
Luiz Capitulino222f1802006-03-20 22:16:13 -08003585 struct pktgen_dev *pkt_dev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003586 int cpu = t->cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003587
David S. Milleree74baa2007-01-01 20:51:53 -08003588 BUG_ON(smp_processor_id() != cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003589
3590 init_waitqueue_head(&t->queue);
Denis V. Lunevd3ede322008-05-20 15:12:44 -07003591 complete(&t->start_done);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592
Joe Perchesf9467ea2010-06-21 12:29:14 +00003593 pr_debug("starting pktgen/%d: pid=%d\n", cpu, task_pid_nr(current));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003594
David S. Milleree74baa2007-01-01 20:51:53 -08003595 set_current_state(TASK_INTERRUPTIBLE);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003596
Rafael J. Wysocki83144182007-07-17 04:03:35 -07003597 set_freezable();
3598
David S. Milleree74baa2007-01-01 20:51:53 -08003599 while (!kthread_should_stop()) {
3600 pkt_dev = next_to_run(t);
3601
Stephen Hemmingeref879792009-09-22 19:41:43 +00003602 if (unlikely(!pkt_dev && t->control == 0)) {
Eric Dumazet551eaff2010-11-21 10:26:44 -08003603 if (pktgen_exiting)
3604 break;
Stephen Hemmingeref879792009-09-22 19:41:43 +00003605 wait_event_interruptible_timeout(t->queue,
3606 t->control != 0,
3607 HZ/10);
Rafael J. Wysocki1b3f7202010-02-04 14:00:41 -08003608 try_to_freeze();
Stephen Hemmingeref879792009-09-22 19:41:43 +00003609 continue;
David S. Milleree74baa2007-01-01 20:51:53 -08003610 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08003611
Linus Torvalds1da177e2005-04-16 15:20:36 -07003612 __set_current_state(TASK_RUNNING);
3613
Stephen Hemmingeref879792009-09-22 19:41:43 +00003614 if (likely(pkt_dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615 pktgen_xmit(pkt_dev);
3616
Stephen Hemmingeref879792009-09-22 19:41:43 +00003617 if (need_resched())
3618 pktgen_resched(pkt_dev);
3619 else
3620 cpu_relax();
3621 }
3622
Luiz Capitulino222f1802006-03-20 22:16:13 -08003623 if (t->control & T_STOP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624 pktgen_stop(t);
3625 t->control &= ~(T_STOP);
3626 }
3627
Luiz Capitulino222f1802006-03-20 22:16:13 -08003628 if (t->control & T_RUN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629 pktgen_run(t);
3630 t->control &= ~(T_RUN);
3631 }
3632
Luiz Capitulino222f1802006-03-20 22:16:13 -08003633 if (t->control & T_REMDEVALL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634 pktgen_rem_all_ifs(t);
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003635 t->control &= ~(T_REMDEVALL);
3636 }
3637
Luiz Capitulino222f1802006-03-20 22:16:13 -08003638 if (t->control & T_REMDEV) {
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003639 pktgen_rem_one_if(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640 t->control &= ~(T_REMDEV);
3641 }
3642
Andrew Morton09fe3ef2007-04-12 14:45:32 -07003643 try_to_freeze();
3644
David S. Milleree74baa2007-01-01 20:51:53 -08003645 set_current_state(TASK_INTERRUPTIBLE);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003646 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647
Joe Perchesf9467ea2010-06-21 12:29:14 +00003648 pr_debug("%s stopping all device\n", t->tsk->comm);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003649 pktgen_stop(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650
Joe Perchesf9467ea2010-06-21 12:29:14 +00003651 pr_debug("%s removing all device\n", t->tsk->comm);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003652 pktgen_rem_all_ifs(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003653
Joe Perchesf9467ea2010-06-21 12:29:14 +00003654 pr_debug("%s removing thread\n", t->tsk->comm);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003655 pktgen_rem_thread(t);
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003656
Eric Dumazet551eaff2010-11-21 10:26:44 -08003657 /* Wait for kthread_stop */
3658 while (!kthread_should_stop()) {
3659 set_current_state(TASK_INTERRUPTIBLE);
3660 schedule();
3661 }
3662 __set_current_state(TASK_RUNNING);
3663
David S. Milleree74baa2007-01-01 20:51:53 -08003664 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003665}
3666
Luiz Capitulino222f1802006-03-20 22:16:13 -08003667static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t,
Eric Dumazet3e984842009-11-24 14:50:53 -08003668 const char *ifname, bool exact)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669{
Luiz Capitulinoc26a8012006-03-20 22:18:16 -08003670 struct pktgen_dev *p, *pkt_dev = NULL;
Eric Dumazet3e984842009-11-24 14:50:53 -08003671 size_t len = strlen(ifname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672
Eric Dumazet3e984842009-11-24 14:50:53 -08003673 if_lock(t);
Luiz Capitulinoc26a8012006-03-20 22:18:16 -08003674 list_for_each_entry(p, &t->if_list, list)
Eric Dumazet3e984842009-11-24 14:50:53 -08003675 if (strncmp(p->odevname, ifname, len) == 0) {
3676 if (p->odevname[len]) {
3677 if (exact || p->odevname[len] != '@')
3678 continue;
3679 }
Luiz Capitulinoc26a8012006-03-20 22:18:16 -08003680 pkt_dev = p;
Luiz Capitulino222f1802006-03-20 22:16:13 -08003681 break;
3682 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683
Luiz Capitulino222f1802006-03-20 22:16:13 -08003684 if_unlock(t);
Joe Perchesf9467ea2010-06-21 12:29:14 +00003685 pr_debug("find_dev(%s) returning %p\n", ifname, pkt_dev);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003686 return pkt_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687}
3688
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09003689/*
3690 * Adds a dev at front of if_list.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691 */
3692
Luiz Capitulino222f1802006-03-20 22:16:13 -08003693static int add_dev_to_thread(struct pktgen_thread *t,
3694 struct pktgen_dev *pkt_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695{
3696 int rv = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003697
Luiz Capitulino222f1802006-03-20 22:16:13 -08003698 if_lock(t);
3699
3700 if (pkt_dev->pg_thread) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00003701 pr_err("ERROR: already assigned to a thread\n");
Luiz Capitulino222f1802006-03-20 22:16:13 -08003702 rv = -EBUSY;
3703 goto out;
3704 }
Luiz Capitulinoc26a8012006-03-20 22:18:16 -08003705
3706 list_add(&pkt_dev->list, &t->if_list);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003707 pkt_dev->pg_thread = t;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708 pkt_dev->running = 0;
3709
Luiz Capitulino222f1802006-03-20 22:16:13 -08003710out:
3711 if_unlock(t);
3712 return rv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713}
3714
3715/* Called under thread lock */
3716
Luiz Capitulino222f1802006-03-20 22:16:13 -08003717static int pktgen_add_device(struct pktgen_thread *t, const char *ifname)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003718{
Luiz Capitulino222f1802006-03-20 22:16:13 -08003719 struct pktgen_dev *pkt_dev;
Stephen Hemminger39df2322007-03-04 16:11:51 -08003720 int err;
Eric Dumazet3291b9d2009-11-29 00:44:33 -08003721 int node = cpu_to_node(t->cpu);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003722
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723 /* We don't allow a device to be on several threads */
3724
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003725 pkt_dev = __pktgen_NN_threads(ifname, FIND);
3726 if (pkt_dev) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00003727 pr_err("ERROR: interface already used\n");
Luiz Capitulino222f1802006-03-20 22:16:13 -08003728 return -EBUSY;
3729 }
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003730
Eric Dumazet3291b9d2009-11-29 00:44:33 -08003731 pkt_dev = kzalloc_node(sizeof(struct pktgen_dev), GFP_KERNEL, node);
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003732 if (!pkt_dev)
3733 return -ENOMEM;
3734
Eric Dumazet593f63b2009-11-23 01:44:37 +00003735 strcpy(pkt_dev->odevname, ifname);
Eric Dumazet3291b9d2009-11-29 00:44:33 -08003736 pkt_dev->flows = vmalloc_node(MAX_CFLOWS * sizeof(struct flow_state),
3737 node);
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003738 if (pkt_dev->flows == NULL) {
3739 kfree(pkt_dev);
3740 return -ENOMEM;
3741 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08003742 memset(pkt_dev->flows, 0, MAX_CFLOWS * sizeof(struct flow_state));
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003743
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003744 pkt_dev->removal_mark = 0;
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003745 pkt_dev->min_pkt_size = ETH_ZLEN;
3746 pkt_dev->max_pkt_size = ETH_ZLEN;
3747 pkt_dev->nfrags = 0;
3748 pkt_dev->clone_skb = pg_clone_skb_d;
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00003749 pkt_dev->delay = pg_delay_d;
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003750 pkt_dev->count = pg_count_d;
3751 pkt_dev->sofar = 0;
Luiz Capitulino222f1802006-03-20 22:16:13 -08003752 pkt_dev->udp_src_min = 9; /* sink port */
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003753 pkt_dev->udp_src_max = 9;
3754 pkt_dev->udp_dst_min = 9;
3755 pkt_dev->udp_dst_max = 9;
3756
Francesco Fondelli34954dd2006-09-27 16:30:44 -07003757 pkt_dev->vlan_p = 0;
3758 pkt_dev->vlan_cfi = 0;
3759 pkt_dev->vlan_id = 0xffff;
3760 pkt_dev->svlan_p = 0;
3761 pkt_dev->svlan_cfi = 0;
3762 pkt_dev->svlan_id = 0xffff;
Robert Olssone99b99b2010-03-18 22:44:30 +00003763 pkt_dev->node = -1;
Francesco Fondelli34954dd2006-09-27 16:30:44 -07003764
Stephen Hemminger39df2322007-03-04 16:11:51 -08003765 err = pktgen_setup_dev(pkt_dev, ifname);
3766 if (err)
3767 goto out1;
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003768
Denis V. Lunev5efdccb2008-05-02 02:46:22 -07003769 pkt_dev->entry = proc_create_data(ifname, 0600, pg_proc_dir,
3770 &pktgen_if_fops, pkt_dev);
Stephen Hemminger39df2322007-03-04 16:11:51 -08003771 if (!pkt_dev->entry) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00003772 pr_err("cannot create %s/%s procfs entry\n",
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003773 PG_PROC_DIR, ifname);
Stephen Hemminger39df2322007-03-04 16:11:51 -08003774 err = -EINVAL;
3775 goto out2;
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003776 }
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07003777#ifdef CONFIG_XFRM
3778 pkt_dev->ipsmode = XFRM_MODE_TRANSPORT;
3779 pkt_dev->ipsproto = IPPROTO_ESP;
3780#endif
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003781
3782 return add_dev_to_thread(t, pkt_dev);
Stephen Hemminger39df2322007-03-04 16:11:51 -08003783out2:
3784 dev_put(pkt_dev->odev);
3785out1:
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07003786#ifdef CONFIG_XFRM
3787 free_SAs(pkt_dev);
3788#endif
Figo.zhang1d0ebfe2009-06-08 00:40:35 -07003789 vfree(pkt_dev->flows);
Stephen Hemminger39df2322007-03-04 16:11:51 -08003790 kfree(pkt_dev);
3791 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792}
3793
David S. Milleree74baa2007-01-01 20:51:53 -08003794static int __init pktgen_create_thread(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795{
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003796 struct pktgen_thread *t;
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003797 struct proc_dir_entry *pe;
David S. Milleree74baa2007-01-01 20:51:53 -08003798 struct task_struct *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003799
Eric Dumazet3291b9d2009-11-29 00:44:33 -08003800 t = kzalloc_node(sizeof(struct pktgen_thread), GFP_KERNEL,
3801 cpu_to_node(cpu));
Luiz Capitulino222f1802006-03-20 22:16:13 -08003802 if (!t) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00003803 pr_err("ERROR: out of memory, can't create new thread\n");
Luiz Capitulino222f1802006-03-20 22:16:13 -08003804 return -ENOMEM;
3805 }
3806
Luiz Capitulino222f1802006-03-20 22:16:13 -08003807 spin_lock_init(&t->if_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808 t->cpu = cpu;
Luiz Capitulino222f1802006-03-20 22:16:13 -08003809
David S. Milleree74baa2007-01-01 20:51:53 -08003810 INIT_LIST_HEAD(&t->if_list);
3811
3812 list_add_tail(&t->th_list, &pktgen_threads);
Denis V. Lunevd3ede322008-05-20 15:12:44 -07003813 init_completion(&t->start_done);
David S. Milleree74baa2007-01-01 20:51:53 -08003814
3815 p = kthread_create(pktgen_thread_worker, t, "kpktgend_%d", cpu);
3816 if (IS_ERR(p)) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00003817 pr_err("kernel_thread() failed for cpu %d\n", t->cpu);
David S. Milleree74baa2007-01-01 20:51:53 -08003818 list_del(&t->th_list);
3819 kfree(t);
3820 return PTR_ERR(p);
3821 }
3822 kthread_bind(p, cpu);
3823 t->tsk = p;
3824
Denis V. Lunev5efdccb2008-05-02 02:46:22 -07003825 pe = proc_create_data(t->tsk->comm, 0600, pg_proc_dir,
3826 &pktgen_thread_fops, t);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003827 if (!pe) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00003828 pr_err("cannot create %s/%s procfs entry\n",
David S. Milleree74baa2007-01-01 20:51:53 -08003829 PG_PROC_DIR, t->tsk->comm);
3830 kthread_stop(p);
3831 list_del(&t->th_list);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003832 kfree(t);
3833 return -EINVAL;
3834 }
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003835
David S. Milleree74baa2007-01-01 20:51:53 -08003836 wake_up_process(p);
Denis V. Lunevd3ede322008-05-20 15:12:44 -07003837 wait_for_completion(&t->start_done);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838
3839 return 0;
3840}
3841
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09003842/*
3843 * Removes a device from the thread if_list.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844 */
Luiz Capitulino222f1802006-03-20 22:16:13 -08003845static void _rem_dev_from_if_list(struct pktgen_thread *t,
3846 struct pktgen_dev *pkt_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847{
Luiz Capitulinoc26a8012006-03-20 22:18:16 -08003848 struct list_head *q, *n;
3849 struct pktgen_dev *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850
Luiz Capitulinoc26a8012006-03-20 22:18:16 -08003851 list_for_each_safe(q, n, &t->if_list) {
3852 p = list_entry(q, struct pktgen_dev, list);
3853 if (p == pkt_dev)
3854 list_del(&p->list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855 }
3856}
3857
Luiz Capitulino222f1802006-03-20 22:16:13 -08003858static int pktgen_remove_device(struct pktgen_thread *t,
3859 struct pktgen_dev *pkt_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860{
3861
Joe Perchesf9467ea2010-06-21 12:29:14 +00003862 pr_debug("remove_device pkt_dev=%p\n", pkt_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863
Luiz Capitulino222f1802006-03-20 22:16:13 -08003864 if (pkt_dev->running) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00003865 pr_warning("WARNING: trying to remove a running interface, stopping it now\n");
Luiz Capitulino222f1802006-03-20 22:16:13 -08003866 pktgen_stop_device(pkt_dev);
3867 }
3868
3869 /* Dis-associate from the interface */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870
3871 if (pkt_dev->odev) {
3872 dev_put(pkt_dev->odev);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003873 pkt_dev->odev = NULL;
3874 }
3875
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876 /* And update the thread if_list */
3877
3878 _rem_dev_from_if_list(t, pkt_dev);
3879
Stephen Hemminger39df2322007-03-04 16:11:51 -08003880 if (pkt_dev->entry)
3881 remove_proc_entry(pkt_dev->entry->name, pg_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07003883#ifdef CONFIG_XFRM
3884 free_SAs(pkt_dev);
3885#endif
Figo.zhang1d0ebfe2009-06-08 00:40:35 -07003886 vfree(pkt_dev->flows);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887 kfree(pkt_dev);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003888 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003889}
3890
Luiz Capitulino222f1802006-03-20 22:16:13 -08003891static int __init pg_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892{
3893 int cpu;
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003894 struct proc_dir_entry *pe;
3895
Joe Perchesf9467ea2010-06-21 12:29:14 +00003896 pr_info("%s", version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897
Eric W. Biederman457c4cb2007-09-12 12:01:34 +02003898 pg_proc_dir = proc_mkdir(PG_PROC_DIR, init_net.proc_net);
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003899 if (!pg_proc_dir)
3900 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003901
Wang Chen25296d52008-02-28 14:11:49 -08003902 pe = proc_create(PGCTRL, 0600, pg_proc_dir, &pktgen_fops);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003903 if (pe == NULL) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00003904 pr_err("ERROR: cannot create %s procfs entry\n", PGCTRL);
Eric W. Biederman457c4cb2007-09-12 12:01:34 +02003905 proc_net_remove(&init_net, PG_PROC_DIR);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003906 return -EINVAL;
3907 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 /* Register us to receive netdevice events */
3910 register_netdevice_notifier(&pktgen_notifier_block);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003911
John Hawkes670c02c2005-10-13 09:30:31 -07003912 for_each_online_cpu(cpu) {
Luiz Capitulino8024bb22006-03-20 22:17:55 -08003913 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003914
David S. Milleree74baa2007-01-01 20:51:53 -08003915 err = pktgen_create_thread(cpu);
Luiz Capitulino8024bb22006-03-20 22:17:55 -08003916 if (err)
Joe Perchesf9467ea2010-06-21 12:29:14 +00003917 pr_warning("WARNING: Cannot create thread for cpu %d (%d)\n",
3918 cpu, err);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003919 }
Luiz Capitulino8024bb22006-03-20 22:17:55 -08003920
3921 if (list_empty(&pktgen_threads)) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00003922 pr_err("ERROR: Initialization failed for all threads\n");
Luiz Capitulino8024bb22006-03-20 22:17:55 -08003923 unregister_netdevice_notifier(&pktgen_notifier_block);
3924 remove_proc_entry(PGCTRL, pg_proc_dir);
Eric W. Biederman457c4cb2007-09-12 12:01:34 +02003925 proc_net_remove(&init_net, PG_PROC_DIR);
Luiz Capitulino8024bb22006-03-20 22:17:55 -08003926 return -ENODEV;
3927 }
3928
Luiz Capitulino222f1802006-03-20 22:16:13 -08003929 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930}
3931
3932static void __exit pg_cleanup(void)
3933{
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003934 struct pktgen_thread *t;
3935 struct list_head *q, *n;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003936
Luiz Capitulino222f1802006-03-20 22:16:13 -08003937 /* Stop all interfaces & threads */
Eric Dumazet551eaff2010-11-21 10:26:44 -08003938 pktgen_exiting = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003940 list_for_each_safe(q, n, &pktgen_threads) {
3941 t = list_entry(q, struct pktgen_thread, th_list);
David S. Milleree74baa2007-01-01 20:51:53 -08003942 kthread_stop(t->tsk);
3943 kfree(t);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003944 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003945
Luiz Capitulino222f1802006-03-20 22:16:13 -08003946 /* Un-register us from receiving netdevice events */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003947 unregister_netdevice_notifier(&pktgen_notifier_block);
3948
Luiz Capitulino222f1802006-03-20 22:16:13 -08003949 /* Clean up proc file system */
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003950 remove_proc_entry(PGCTRL, pg_proc_dir);
Eric W. Biederman457c4cb2007-09-12 12:01:34 +02003951 proc_net_remove(&init_net, PG_PROC_DIR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003952}
3953
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954module_init(pg_init);
3955module_exit(pg_cleanup);
3956
Stephen Hemmingerc3d2f522009-08-27 13:55:20 +00003957MODULE_AUTHOR("Robert Olsson <robert.olsson@its.uu.se>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003958MODULE_DESCRIPTION("Packet Generator tool");
3959MODULE_LICENSE("GPL");
Stephen Hemmingerc3d2f522009-08-27 13:55:20 +00003960MODULE_VERSION(VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961module_param(pg_count_d, int, 0);
Stephen Hemmingerc3d2f522009-08-27 13:55:20 +00003962MODULE_PARM_DESC(pg_count_d, "Default number of packets to inject");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003963module_param(pg_delay_d, int, 0);
Stephen Hemmingerc3d2f522009-08-27 13:55:20 +00003964MODULE_PARM_DESC(pg_delay_d, "Default delay between packets (nanoseconds)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965module_param(pg_clone_skb_d, int, 0);
Stephen Hemmingerc3d2f522009-08-27 13:55:20 +00003966MODULE_PARM_DESC(pg_clone_skb_d, "Default number of copies of the same packet");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967module_param(debug, int, 0);
Stephen Hemmingerc3d2f522009-08-27 13:55:20 +00003968MODULE_PARM_DESC(debug, "Enable debugging of pktgen module");