blob: 52fc1e08a7c47d2a2d09e546d817e312c7d337cb [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 Viro252e33462006-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 Viro252e33462006-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 Viro252e33462006-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 Viro252e33462006-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
398struct pktgen_thread {
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000399 spinlock_t if_lock; /* for list of devices */
Luiz Capitulinoc26a80162006-03-20 22:18:16 -0800400 struct list_head if_list; /* All device here */
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -0800401 struct list_head th_list;
David S. Milleree74baa2007-01-01 20:51:53 -0800402 struct task_struct *tsk;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800403 char result[512];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000405 /* Field for thread to receive "posted" events terminate,
406 stop ifs etc. */
Luiz Capitulino222f1802006-03-20 22:16:13 -0800407
408 u32 control;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 int cpu;
410
Luiz Capitulino222f1802006-03-20 22:16:13 -0800411 wait_queue_head_t queue;
Denis V. Lunevd3ede322008-05-20 15:12:44 -0700412 struct completion start_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413};
414
415#define REMOVE 1
416#define FIND 0
417
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +0000418static inline ktime_t ktime_now(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419{
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +0000420 struct timespec ts;
421 ktime_get_ts(&ts);
422
423 return timespec_to_ktime(ts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424}
425
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +0000426/* This works even if 32 bit because of careful byte order choice */
427static inline int ktime_lt(const ktime_t cmp1, const ktime_t cmp2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428{
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +0000429 return cmp1.tv64 < cmp2.tv64;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430}
431
Stephen Hemmingerc3d2f522009-08-27 13:55:20 +0000432static const char version[] =
Joe Perchesf9467ea2010-06-21 12:29:14 +0000433 "Packet Generator for packet performance testing. "
434 "Version: " VERSION "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Luiz Capitulino222f1802006-03-20 22:16:13 -0800436static int pktgen_remove_device(struct pktgen_thread *t, struct pktgen_dev *i);
437static int pktgen_add_device(struct pktgen_thread *t, const char *ifname);
438static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t,
Eric Dumazet3e984842009-11-24 14:50:53 -0800439 const char *ifname, bool exact);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440static int pktgen_device_event(struct notifier_block *, unsigned long, void *);
441static void pktgen_run_all_threads(void);
Jesse Brandeburgeb37b412008-11-10 16:48:03 -0800442static void pktgen_reset_all_threads(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443static void pktgen_stop_all_threads_ifs(void);
Stephen Hemminger3bda06a2009-08-27 13:55:10 +0000444
Luiz Capitulino222f1802006-03-20 22:16:13 -0800445static void pktgen_stop(struct pktgen_thread *t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446static void pktgen_clear_counters(struct pktgen_dev *pkt_dev);
Stephen Hemminger39df2322007-03-04 16:11:51 -0800447
Luiz Capitulino222f1802006-03-20 22:16:13 -0800448static unsigned int scan_ip6(const char *s, char ip[16]);
449static unsigned int fmt_ip6(char *s, const char ip[16]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
451/* Module parameters, defaults. */
Stephen Hemminger65c5b782009-08-27 13:55:09 +0000452static int pg_count_d __read_mostly = 1000;
453static int pg_delay_d __read_mostly;
454static int pg_clone_skb_d __read_mostly;
455static int debug __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
Luiz Capitulino222fa072006-03-20 22:24:27 -0800457static DEFINE_MUTEX(pktgen_thread_lock);
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -0800458static LIST_HEAD(pktgen_threads);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460static struct notifier_block pktgen_notifier_block = {
461 .notifier_call = pktgen_device_event,
462};
463
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464/*
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +0900465 * /proc handling functions
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 *
467 */
468
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700469static int pgctrl_show(struct seq_file *seq, void *v)
Luiz Capitulino222f1802006-03-20 22:16:13 -0800470{
Stephen Hemmingerc3d2f522009-08-27 13:55:20 +0000471 seq_puts(seq, version);
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700472 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473}
474
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000475static ssize_t pgctrl_write(struct file *file, const char __user *buf,
476 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 int err = 0;
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700479 char data[128];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
Luiz Capitulino222f1802006-03-20 22:16:13 -0800481 if (!capable(CAP_NET_ADMIN)) {
482 err = -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 goto out;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800484 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700486 if (count > sizeof(data))
487 count = sizeof(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 if (copy_from_user(data, buf, count)) {
Stephen Hemmingerb4099fa2005-10-14 15:32:22 -0700490 err = -EFAULT;
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700491 goto out;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800492 }
493 data[count - 1] = 0; /* Make string */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Luiz Capitulino222f1802006-03-20 22:16:13 -0800495 if (!strcmp(data, "stop"))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 pktgen_stop_all_threads_ifs();
497
Luiz Capitulino222f1802006-03-20 22:16:13 -0800498 else if (!strcmp(data, "start"))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 pktgen_run_all_threads();
500
Jesse Brandeburgeb37b412008-11-10 16:48:03 -0800501 else if (!strcmp(data, "reset"))
502 pktgen_reset_all_threads();
503
Luiz Capitulino222f1802006-03-20 22:16:13 -0800504 else
Joe Perchesf9467ea2010-06-21 12:29:14 +0000505 pr_warning("Unknown command: %s\n", data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
507 err = count;
508
Luiz Capitulino222f1802006-03-20 22:16:13 -0800509out:
510 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511}
512
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700513static int pgctrl_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514{
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700515 return single_open(file, pgctrl_show, PDE(inode)->data);
516}
517
Arjan van de Ven9a321442007-02-12 00:55:35 -0800518static const struct file_operations pktgen_fops = {
Luiz Capitulino222f1802006-03-20 22:16:13 -0800519 .owner = THIS_MODULE,
520 .open = pgctrl_open,
521 .read = seq_read,
522 .llseek = seq_lseek,
523 .write = pgctrl_write,
524 .release = single_release,
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700525};
526
527static int pktgen_if_show(struct seq_file *seq, void *v)
528{
Stephen Hemminger648fda72009-08-27 13:55:07 +0000529 const struct pktgen_dev *pkt_dev = seq->private;
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +0000530 ktime_t stopped;
531 u64 idle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Luiz Capitulino222f1802006-03-20 22:16:13 -0800533 seq_printf(seq,
534 "Params: count %llu min_pkt_size: %u max_pkt_size: %u\n",
535 (unsigned long long)pkt_dev->count, pkt_dev->min_pkt_size,
536 pkt_dev->max_pkt_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
Luiz Capitulino222f1802006-03-20 22:16:13 -0800538 seq_printf(seq,
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +0000539 " frags: %d delay: %llu clone_skb: %d ifname: %s\n",
540 pkt_dev->nfrags, (unsigned long long) pkt_dev->delay,
Eric Dumazet593f63b2009-11-23 01:44:37 +0000541 pkt_dev->clone_skb, pkt_dev->odevname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
Luiz Capitulino222f1802006-03-20 22:16:13 -0800543 seq_printf(seq, " flows: %u flowlen: %u\n", pkt_dev->cflows,
544 pkt_dev->lflow);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Robert Olsson45b270f2007-08-28 15:45:55 -0700546 seq_printf(seq,
547 " queue_map_min: %u queue_map_max: %u\n",
548 pkt_dev->queue_map_min,
549 pkt_dev->queue_map_max);
550
John Fastabend9e50e3a2010-11-16 19:12:28 +0000551 if (pkt_dev->skb_priority)
552 seq_printf(seq, " skb_priority: %u\n",
553 pkt_dev->skb_priority);
554
Luiz Capitulino222f1802006-03-20 22:16:13 -0800555 if (pkt_dev->flags & F_IPV6) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 char b1[128], b2[128], b3[128];
Luiz Capitulino222f1802006-03-20 22:16:13 -0800557 fmt_ip6(b1, pkt_dev->in6_saddr.s6_addr);
558 fmt_ip6(b2, pkt_dev->min_in6_saddr.s6_addr);
559 fmt_ip6(b3, pkt_dev->max_in6_saddr.s6_addr);
560 seq_printf(seq,
561 " saddr: %s min_saddr: %s max_saddr: %s\n", b1,
562 b2, b3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
Luiz Capitulino222f1802006-03-20 22:16:13 -0800564 fmt_ip6(b1, pkt_dev->in6_daddr.s6_addr);
565 fmt_ip6(b2, pkt_dev->min_in6_daddr.s6_addr);
566 fmt_ip6(b3, pkt_dev->max_in6_daddr.s6_addr);
567 seq_printf(seq,
568 " daddr: %s min_daddr: %s max_daddr: %s\n", b1,
569 b2, b3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000571 } else {
Luiz Capitulino222f1802006-03-20 22:16:13 -0800572 seq_printf(seq,
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000573 " dst_min: %s dst_max: %s\n",
574 pkt_dev->dst_min, pkt_dev->dst_max);
575 seq_printf(seq,
576 " src_min: %s src_max: %s\n",
577 pkt_dev->src_min, pkt_dev->src_max);
578 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700580 seq_puts(seq, " src_mac: ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
Johannes Berge1749612008-10-27 15:59:26 -0700582 seq_printf(seq, "%pM ",
583 is_zero_ether_addr(pkt_dev->src_mac) ?
584 pkt_dev->odev->dev_addr : pkt_dev->src_mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
Luiz Capitulino222f1802006-03-20 22:16:13 -0800586 seq_printf(seq, "dst_mac: ");
Johannes Berge1749612008-10-27 15:59:26 -0700587 seq_printf(seq, "%pM\n", pkt_dev->dst_mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
Luiz Capitulino222f1802006-03-20 22:16:13 -0800589 seq_printf(seq,
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000590 " udp_src_min: %d udp_src_max: %d"
591 " udp_dst_min: %d udp_dst_max: %d\n",
Luiz Capitulino222f1802006-03-20 22:16:13 -0800592 pkt_dev->udp_src_min, pkt_dev->udp_src_max,
593 pkt_dev->udp_dst_min, pkt_dev->udp_dst_max);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
Luiz Capitulino222f1802006-03-20 22:16:13 -0800595 seq_printf(seq,
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800596 " src_mac_count: %d dst_mac_count: %d\n",
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700597 pkt_dev->src_mac_count, pkt_dev->dst_mac_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800599 if (pkt_dev->nr_labels) {
600 unsigned i;
601 seq_printf(seq, " mpls: ");
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700602 for (i = 0; i < pkt_dev->nr_labels; i++)
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800603 seq_printf(seq, "%08x%s", ntohl(pkt_dev->labels[i]),
604 i == pkt_dev->nr_labels-1 ? "\n" : ", ");
605 }
606
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000607 if (pkt_dev->vlan_id != 0xffff)
Francesco Fondelli34954dd2006-09-27 16:30:44 -0700608 seq_printf(seq, " vlan_id: %u vlan_p: %u vlan_cfi: %u\n",
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000609 pkt_dev->vlan_id, pkt_dev->vlan_p,
610 pkt_dev->vlan_cfi);
Francesco Fondelli34954dd2006-09-27 16:30:44 -0700611
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000612 if (pkt_dev->svlan_id != 0xffff)
Francesco Fondelli34954dd2006-09-27 16:30:44 -0700613 seq_printf(seq, " svlan_id: %u vlan_p: %u vlan_cfi: %u\n",
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000614 pkt_dev->svlan_id, pkt_dev->svlan_p,
615 pkt_dev->svlan_cfi);
Francesco Fondelli34954dd2006-09-27 16:30:44 -0700616
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000617 if (pkt_dev->tos)
Francesco Fondelli1ca77682006-09-27 16:32:03 -0700618 seq_printf(seq, " tos: 0x%02x\n", pkt_dev->tos);
Francesco Fondelli1ca77682006-09-27 16:32:03 -0700619
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000620 if (pkt_dev->traffic_class)
Francesco Fondelli1ca77682006-09-27 16:32:03 -0700621 seq_printf(seq, " traffic_class: 0x%02x\n", pkt_dev->traffic_class);
Francesco Fondelli1ca77682006-09-27 16:32:03 -0700622
Robert Olssone99b99b2010-03-18 22:44:30 +0000623 if (pkt_dev->node >= 0)
624 seq_printf(seq, " node: %d\n", pkt_dev->node);
625
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800626 seq_printf(seq, " Flags: ");
627
Luiz Capitulino222f1802006-03-20 22:16:13 -0800628 if (pkt_dev->flags & F_IPV6)
629 seq_printf(seq, "IPV6 ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
Luiz Capitulino222f1802006-03-20 22:16:13 -0800631 if (pkt_dev->flags & F_IPSRC_RND)
632 seq_printf(seq, "IPSRC_RND ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
Luiz Capitulino222f1802006-03-20 22:16:13 -0800634 if (pkt_dev->flags & F_IPDST_RND)
635 seq_printf(seq, "IPDST_RND ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
Luiz Capitulino222f1802006-03-20 22:16:13 -0800637 if (pkt_dev->flags & F_TXSIZE_RND)
638 seq_printf(seq, "TXSIZE_RND ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
Luiz Capitulino222f1802006-03-20 22:16:13 -0800640 if (pkt_dev->flags & F_UDPSRC_RND)
641 seq_printf(seq, "UDPSRC_RND ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
Luiz Capitulino222f1802006-03-20 22:16:13 -0800643 if (pkt_dev->flags & F_UDPDST_RND)
644 seq_printf(seq, "UDPDST_RND ");
645
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800646 if (pkt_dev->flags & F_MPLS_RND)
647 seq_printf(seq, "MPLS_RND ");
648
Robert Olsson45b270f2007-08-28 15:45:55 -0700649 if (pkt_dev->flags & F_QUEUE_MAP_RND)
650 seq_printf(seq, "QUEUE_MAP_RND ");
651
Robert Olssone6fce5b2008-08-07 02:23:01 -0700652 if (pkt_dev->flags & F_QUEUE_MAP_CPU)
653 seq_printf(seq, "QUEUE_MAP_CPU ");
654
Jamal Hadi Salim007a5312007-07-02 22:40:36 -0700655 if (pkt_dev->cflows) {
656 if (pkt_dev->flags & F_FLOW_SEQ)
657 seq_printf(seq, "FLOW_SEQ "); /*in sequence flows*/
658 else
659 seq_printf(seq, "FLOW_RND ");
660 }
661
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -0700662#ifdef CONFIG_XFRM
663 if (pkt_dev->flags & F_IPSEC_ON)
664 seq_printf(seq, "IPSEC ");
665#endif
666
Luiz Capitulino222f1802006-03-20 22:16:13 -0800667 if (pkt_dev->flags & F_MACSRC_RND)
668 seq_printf(seq, "MACSRC_RND ");
669
670 if (pkt_dev->flags & F_MACDST_RND)
671 seq_printf(seq, "MACDST_RND ");
672
Francesco Fondelli34954dd2006-09-27 16:30:44 -0700673 if (pkt_dev->flags & F_VID_RND)
674 seq_printf(seq, "VID_RND ");
675
676 if (pkt_dev->flags & F_SVID_RND)
677 seq_printf(seq, "SVID_RND ");
678
Robert Olssone99b99b2010-03-18 22:44:30 +0000679 if (pkt_dev->flags & F_NODE)
680 seq_printf(seq, "NODE_ALLOC ");
681
Luiz Capitulino222f1802006-03-20 22:16:13 -0800682 seq_puts(seq, "\n");
683
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +0000684 /* not really stopped, more like last-running-at */
685 stopped = pkt_dev->running ? ktime_now() : pkt_dev->stopped_at;
686 idle = pkt_dev->idle_acc;
687 do_div(idle, NSEC_PER_USEC);
Luiz Capitulino222f1802006-03-20 22:16:13 -0800688
689 seq_printf(seq,
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +0000690 "Current:\n pkts-sofar: %llu errors: %llu\n",
Luiz Capitulino222f1802006-03-20 22:16:13 -0800691 (unsigned long long)pkt_dev->sofar,
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +0000692 (unsigned long long)pkt_dev->errors);
693
694 seq_printf(seq,
695 " started: %lluus stopped: %lluus idle: %lluus\n",
696 (unsigned long long) ktime_to_us(pkt_dev->started_at),
697 (unsigned long long) ktime_to_us(stopped),
698 (unsigned long long) idle);
Luiz Capitulino222f1802006-03-20 22:16:13 -0800699
700 seq_printf(seq,
701 " seq_num: %d cur_dst_mac_offset: %d cur_src_mac_offset: %d\n",
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700702 pkt_dev->seq_num, pkt_dev->cur_dst_mac_offset,
703 pkt_dev->cur_src_mac_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Luiz Capitulino222f1802006-03-20 22:16:13 -0800705 if (pkt_dev->flags & F_IPV6) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 char b1[128], b2[128];
Luiz Capitulino222f1802006-03-20 22:16:13 -0800707 fmt_ip6(b1, pkt_dev->cur_in6_daddr.s6_addr);
708 fmt_ip6(b2, pkt_dev->cur_in6_saddr.s6_addr);
709 seq_printf(seq, " cur_saddr: %s cur_daddr: %s\n", b2, b1);
710 } else
711 seq_printf(seq, " cur_saddr: 0x%x cur_daddr: 0x%x\n",
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700712 pkt_dev->cur_saddr, pkt_dev->cur_daddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
Luiz Capitulino222f1802006-03-20 22:16:13 -0800714 seq_printf(seq, " cur_udp_dst: %d cur_udp_src: %d\n",
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700715 pkt_dev->cur_udp_dst, pkt_dev->cur_udp_src);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
Robert Olsson45b270f2007-08-28 15:45:55 -0700717 seq_printf(seq, " cur_queue_map: %u\n", pkt_dev->cur_queue_map);
718
Luiz Capitulino222f1802006-03-20 22:16:13 -0800719 seq_printf(seq, " flows: %u\n", pkt_dev->nflows);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
721 if (pkt_dev->result[0])
Luiz Capitulino222f1802006-03-20 22:16:13 -0800722 seq_printf(seq, "Result: %s\n", pkt_dev->result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 else
Luiz Capitulino222f1802006-03-20 22:16:13 -0800724 seq_printf(seq, "Result: Idle\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -0700726 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727}
728
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800729
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000730static int hex32_arg(const char __user *user_buffer, unsigned long maxlen,
731 __u32 *num)
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800732{
733 int i = 0;
734 *num = 0;
735
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700736 for (; i < maxlen; i++) {
Andy Shevchenko82fd5b52010-09-20 20:40:26 +0000737 int value;
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800738 char c;
739 *num <<= 4;
740 if (get_user(c, &user_buffer[i]))
741 return -EFAULT;
Andy Shevchenko82fd5b52010-09-20 20:40:26 +0000742 value = hex_to_bin(c);
743 if (value >= 0)
744 *num |= value;
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800745 else
746 break;
747 }
748 return i;
749}
750
Luiz Capitulino222f1802006-03-20 22:16:13 -0800751static int count_trail_chars(const char __user * user_buffer,
752 unsigned int maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753{
754 int i;
755
756 for (i = 0; i < maxlen; i++) {
Luiz Capitulino222f1802006-03-20 22:16:13 -0800757 char c;
758 if (get_user(c, &user_buffer[i]))
759 return -EFAULT;
760 switch (c) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 case '\"':
762 case '\n':
763 case '\r':
764 case '\t':
765 case ' ':
766 case '=':
767 break;
768 default:
769 goto done;
Stephen Hemminger3ff50b72007-04-20 17:09:22 -0700770 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 }
772done:
773 return i;
774}
775
Luiz Capitulino222f1802006-03-20 22:16:13 -0800776static unsigned long num_arg(const char __user * user_buffer,
777 unsigned long maxlen, unsigned long *num)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778{
Paul Gortmakerd6182222010-10-18 12:14:44 +0000779 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 *num = 0;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800781
Paul Gortmakerd6182222010-10-18 12:14:44 +0000782 for (i = 0; i < maxlen; i++) {
Luiz Capitulino222f1802006-03-20 22:16:13 -0800783 char c;
784 if (get_user(c, &user_buffer[i]))
785 return -EFAULT;
786 if ((c >= '0') && (c <= '9')) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 *num *= 10;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800788 *num += c - '0';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 } else
790 break;
791 }
792 return i;
793}
794
Luiz Capitulino222f1802006-03-20 22:16:13 -0800795static int strn_len(const char __user * user_buffer, unsigned int maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796{
Paul Gortmakerd6182222010-10-18 12:14:44 +0000797 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
Paul Gortmakerd6182222010-10-18 12:14:44 +0000799 for (i = 0; i < maxlen; i++) {
Luiz Capitulino222f1802006-03-20 22:16:13 -0800800 char c;
801 if (get_user(c, &user_buffer[i]))
802 return -EFAULT;
803 switch (c) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 case '\"':
805 case '\n':
806 case '\r':
807 case '\t':
808 case ' ':
809 goto done_str;
810 break;
811 default:
812 break;
Stephen Hemminger3ff50b72007-04-20 17:09:22 -0700813 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 }
815done_str:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 return i;
817}
818
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800819static ssize_t get_labels(const char __user *buffer, struct pktgen_dev *pkt_dev)
820{
821 unsigned n = 0;
822 char c;
823 ssize_t i = 0;
824 int len;
825
826 pkt_dev->nr_labels = 0;
827 do {
828 __u32 tmp;
Francesco Fondelli1ca77682006-09-27 16:32:03 -0700829 len = hex32_arg(&buffer[i], 8, &tmp);
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800830 if (len <= 0)
831 return len;
832 pkt_dev->labels[n] = htonl(tmp);
833 if (pkt_dev->labels[n] & MPLS_STACK_BOTTOM)
834 pkt_dev->flags |= F_MPLS_RND;
835 i += len;
836 if (get_user(c, &buffer[i]))
837 return -EFAULT;
838 i++;
839 n++;
840 if (n >= MAX_MPLS_LABELS)
841 return -E2BIG;
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700842 } while (c == ',');
Steven Whitehouseca6549a2006-03-23 01:10:26 -0800843
844 pkt_dev->nr_labels = n;
845 return i;
846}
847
Luiz Capitulino222f1802006-03-20 22:16:13 -0800848static ssize_t pktgen_if_write(struct file *file,
849 const char __user * user_buffer, size_t count,
850 loff_t * offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851{
Joe Perches8a994a72010-07-12 10:50:23 +0000852 struct seq_file *seq = file->private_data;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800853 struct pktgen_dev *pkt_dev = seq->private;
Paul Gortmakerd6182222010-10-18 12:14:44 +0000854 int i, max, len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 char name[16], valstr[32];
856 unsigned long value = 0;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800857 char *pg_result = NULL;
858 int tmp = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 char buf[128];
Luiz Capitulino222f1802006-03-20 22:16:13 -0800860
861 pg_result = &(pkt_dev->result[0]);
862
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 if (count < 1) {
Joe Perchesf9467ea2010-06-21 12:29:14 +0000864 pr_warning("wrong command format\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 return -EINVAL;
866 }
Luiz Capitulino222f1802006-03-20 22:16:13 -0800867
Paul Gortmakerd6182222010-10-18 12:14:44 +0000868 max = count;
869 tmp = count_trail_chars(user_buffer, max);
Luiz Capitulino222f1802006-03-20 22:16:13 -0800870 if (tmp < 0) {
Joe Perchesf9467ea2010-06-21 12:29:14 +0000871 pr_warning("illegal format\n");
Luiz Capitulino222f1802006-03-20 22:16:13 -0800872 return tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 }
Paul Gortmakerd6182222010-10-18 12:14:44 +0000874 i = tmp;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800875
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 /* Read variable name */
877
878 len = strn_len(&user_buffer[i], sizeof(name) - 1);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000879 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -0800880 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000881
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 memset(name, 0, sizeof(name));
Luiz Capitulino222f1802006-03-20 22:16:13 -0800883 if (copy_from_user(name, &user_buffer[i], len))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 return -EFAULT;
885 i += len;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800886
887 max = count - i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 len = count_trail_chars(&user_buffer[i], max);
Luiz Capitulino222f1802006-03-20 22:16:13 -0800889 if (len < 0)
890 return len;
891
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 i += len;
893
894 if (debug) {
Dmitry Torokhov86c2c0a2010-11-06 20:11:38 +0000895 size_t copy = min_t(size_t, count, 1023);
Nelson Elhage448d7b52010-10-28 11:31:07 -0700896 char tb[copy + 1];
897 if (copy_from_user(tb, user_buffer, copy))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 return -EFAULT;
Nelson Elhage448d7b52010-10-28 11:31:07 -0700899 tb[copy] = 0;
David S. Miller25a8b252007-07-30 16:11:48 -0700900 printk(KERN_DEBUG "pktgen: %s,%lu buffer -:%s:-\n", name,
Luiz Capitulino222f1802006-03-20 22:16:13 -0800901 (unsigned long)count, tb);
902 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
904 if (!strcmp(name, "min_pkt_size")) {
905 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000906 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -0800907 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000908
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 i += len;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800910 if (value < 14 + 20 + 8)
911 value = 14 + 20 + 8;
912 if (value != pkt_dev->min_pkt_size) {
913 pkt_dev->min_pkt_size = value;
914 pkt_dev->cur_pkt_size = value;
915 }
916 sprintf(pg_result, "OK: min_pkt_size=%u",
917 pkt_dev->min_pkt_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 return count;
919 }
920
Luiz Capitulino222f1802006-03-20 22:16:13 -0800921 if (!strcmp(name, "max_pkt_size")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000923 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -0800924 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000925
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 i += len;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800927 if (value < 14 + 20 + 8)
928 value = 14 + 20 + 8;
929 if (value != pkt_dev->max_pkt_size) {
930 pkt_dev->max_pkt_size = value;
931 pkt_dev->cur_pkt_size = value;
932 }
933 sprintf(pg_result, "OK: max_pkt_size=%u",
934 pkt_dev->max_pkt_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 return count;
936 }
937
Luiz Capitulino222f1802006-03-20 22:16:13 -0800938 /* Shortcut for min = max */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
940 if (!strcmp(name, "pkt_size")) {
941 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000942 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -0800943 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000944
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 i += len;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800946 if (value < 14 + 20 + 8)
947 value = 14 + 20 + 8;
948 if (value != pkt_dev->min_pkt_size) {
949 pkt_dev->min_pkt_size = value;
950 pkt_dev->max_pkt_size = value;
951 pkt_dev->cur_pkt_size = value;
952 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 sprintf(pg_result, "OK: pkt_size=%u", pkt_dev->min_pkt_size);
954 return count;
955 }
956
Luiz Capitulino222f1802006-03-20 22:16:13 -0800957 if (!strcmp(name, "debug")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000959 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -0800960 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000961
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 i += len;
Luiz Capitulino222f1802006-03-20 22:16:13 -0800963 debug = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 sprintf(pg_result, "OK: debug=%u", debug);
965 return count;
966 }
967
Luiz Capitulino222f1802006-03-20 22:16:13 -0800968 if (!strcmp(name, "frags")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000970 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -0800971 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000972
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 i += len;
974 pkt_dev->nfrags = value;
975 sprintf(pg_result, "OK: frags=%u", pkt_dev->nfrags);
976 return count;
977 }
978 if (!strcmp(name, "delay")) {
979 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000980 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -0800981 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +0000982
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 i += len;
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +0000984 if (value == 0x7FFFFFFF)
985 pkt_dev->delay = ULLONG_MAX;
986 else
Eric Dumazet9240d712009-10-03 01:39:18 +0000987 pkt_dev->delay = (u64)value;
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +0000988
989 sprintf(pg_result, "OK: delay=%llu",
990 (unsigned long long) pkt_dev->delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 return count;
992 }
Daniel Turull43d28b62010-06-09 22:49:57 +0000993 if (!strcmp(name, "rate")) {
994 len = num_arg(&user_buffer[i], 10, &value);
995 if (len < 0)
996 return len;
997
998 i += len;
999 if (!value)
1000 return len;
1001 pkt_dev->delay = pkt_dev->min_pkt_size*8*NSEC_PER_USEC/value;
1002 if (debug)
Joe Perchesf9467ea2010-06-21 12:29:14 +00001003 pr_info("Delay set at: %llu ns\n", pkt_dev->delay);
Daniel Turull43d28b62010-06-09 22:49:57 +00001004
1005 sprintf(pg_result, "OK: rate=%lu", value);
1006 return count;
1007 }
1008 if (!strcmp(name, "ratep")) {
1009 len = num_arg(&user_buffer[i], 10, &value);
1010 if (len < 0)
1011 return len;
1012
1013 i += len;
1014 if (!value)
1015 return len;
1016 pkt_dev->delay = NSEC_PER_SEC/value;
1017 if (debug)
Joe Perchesf9467ea2010-06-21 12:29:14 +00001018 pr_info("Delay set at: %llu ns\n", pkt_dev->delay);
Daniel Turull43d28b62010-06-09 22:49:57 +00001019
1020 sprintf(pg_result, "OK: rate=%lu", value);
1021 return count;
1022 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08001023 if (!strcmp(name, "udp_src_min")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001025 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001026 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001027
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 i += len;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001029 if (value != pkt_dev->udp_src_min) {
1030 pkt_dev->udp_src_min = value;
1031 pkt_dev->cur_udp_src = value;
1032 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 sprintf(pg_result, "OK: udp_src_min=%u", pkt_dev->udp_src_min);
1034 return count;
1035 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08001036 if (!strcmp(name, "udp_dst_min")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001038 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001039 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001040
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 i += len;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001042 if (value != pkt_dev->udp_dst_min) {
1043 pkt_dev->udp_dst_min = value;
1044 pkt_dev->cur_udp_dst = value;
1045 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 sprintf(pg_result, "OK: udp_dst_min=%u", pkt_dev->udp_dst_min);
1047 return count;
1048 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08001049 if (!strcmp(name, "udp_src_max")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001051 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001052 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001053
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 i += len;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001055 if (value != pkt_dev->udp_src_max) {
1056 pkt_dev->udp_src_max = value;
1057 pkt_dev->cur_udp_src = value;
1058 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 sprintf(pg_result, "OK: udp_src_max=%u", pkt_dev->udp_src_max);
1060 return count;
1061 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08001062 if (!strcmp(name, "udp_dst_max")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001064 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001065 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001066
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 i += len;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001068 if (value != pkt_dev->udp_dst_max) {
1069 pkt_dev->udp_dst_max = value;
1070 pkt_dev->cur_udp_dst = value;
1071 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 sprintf(pg_result, "OK: udp_dst_max=%u", pkt_dev->udp_dst_max);
1073 return count;
1074 }
1075 if (!strcmp(name, "clone_skb")) {
1076 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001077 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001078 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001079
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 i += len;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001081 pkt_dev->clone_skb = value;
1082
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 sprintf(pg_result, "OK: clone_skb=%d", pkt_dev->clone_skb);
1084 return count;
1085 }
1086 if (!strcmp(name, "count")) {
1087 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001088 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001089 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001090
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 i += len;
1092 pkt_dev->count = value;
1093 sprintf(pg_result, "OK: count=%llu",
Luiz Capitulino222f1802006-03-20 22:16:13 -08001094 (unsigned long long)pkt_dev->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 return count;
1096 }
1097 if (!strcmp(name, "src_mac_count")) {
1098 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001099 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001100 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001101
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 i += len;
1103 if (pkt_dev->src_mac_count != value) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08001104 pkt_dev->src_mac_count = value;
1105 pkt_dev->cur_src_mac_offset = 0;
1106 }
1107 sprintf(pg_result, "OK: src_mac_count=%d",
1108 pkt_dev->src_mac_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 return count;
1110 }
1111 if (!strcmp(name, "dst_mac_count")) {
1112 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001113 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001114 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001115
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 i += len;
1117 if (pkt_dev->dst_mac_count != value) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08001118 pkt_dev->dst_mac_count = value;
1119 pkt_dev->cur_dst_mac_offset = 0;
1120 }
1121 sprintf(pg_result, "OK: dst_mac_count=%d",
1122 pkt_dev->dst_mac_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 return count;
1124 }
Robert Olssone99b99b2010-03-18 22:44:30 +00001125 if (!strcmp(name, "node")) {
1126 len = num_arg(&user_buffer[i], 10, &value);
1127 if (len < 0)
1128 return len;
1129
1130 i += len;
1131
1132 if (node_possible(value)) {
1133 pkt_dev->node = value;
1134 sprintf(pg_result, "OK: node=%d", pkt_dev->node);
1135 }
1136 else
1137 sprintf(pg_result, "ERROR: node not possible");
1138 return count;
1139 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 if (!strcmp(name, "flag")) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08001141 char f[32];
1142 memset(f, 0, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 len = strn_len(&user_buffer[i], sizeof(f) - 1);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001144 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001145 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001146
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 if (copy_from_user(f, &user_buffer[i], len))
1148 return -EFAULT;
1149 i += len;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001150 if (strcmp(f, "IPSRC_RND") == 0)
1151 pkt_dev->flags |= F_IPSRC_RND;
1152
1153 else if (strcmp(f, "!IPSRC_RND") == 0)
1154 pkt_dev->flags &= ~F_IPSRC_RND;
1155
1156 else if (strcmp(f, "TXSIZE_RND") == 0)
1157 pkt_dev->flags |= F_TXSIZE_RND;
1158
1159 else if (strcmp(f, "!TXSIZE_RND") == 0)
1160 pkt_dev->flags &= ~F_TXSIZE_RND;
1161
1162 else if (strcmp(f, "IPDST_RND") == 0)
1163 pkt_dev->flags |= F_IPDST_RND;
1164
1165 else if (strcmp(f, "!IPDST_RND") == 0)
1166 pkt_dev->flags &= ~F_IPDST_RND;
1167
1168 else if (strcmp(f, "UDPSRC_RND") == 0)
1169 pkt_dev->flags |= F_UDPSRC_RND;
1170
1171 else if (strcmp(f, "!UDPSRC_RND") == 0)
1172 pkt_dev->flags &= ~F_UDPSRC_RND;
1173
1174 else if (strcmp(f, "UDPDST_RND") == 0)
1175 pkt_dev->flags |= F_UDPDST_RND;
1176
1177 else if (strcmp(f, "!UDPDST_RND") == 0)
1178 pkt_dev->flags &= ~F_UDPDST_RND;
1179
1180 else if (strcmp(f, "MACSRC_RND") == 0)
1181 pkt_dev->flags |= F_MACSRC_RND;
1182
1183 else if (strcmp(f, "!MACSRC_RND") == 0)
1184 pkt_dev->flags &= ~F_MACSRC_RND;
1185
1186 else if (strcmp(f, "MACDST_RND") == 0)
1187 pkt_dev->flags |= F_MACDST_RND;
1188
1189 else if (strcmp(f, "!MACDST_RND") == 0)
1190 pkt_dev->flags &= ~F_MACDST_RND;
1191
Steven Whitehouseca6549a2006-03-23 01:10:26 -08001192 else if (strcmp(f, "MPLS_RND") == 0)
1193 pkt_dev->flags |= F_MPLS_RND;
1194
1195 else if (strcmp(f, "!MPLS_RND") == 0)
1196 pkt_dev->flags &= ~F_MPLS_RND;
1197
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001198 else if (strcmp(f, "VID_RND") == 0)
1199 pkt_dev->flags |= F_VID_RND;
1200
1201 else if (strcmp(f, "!VID_RND") == 0)
1202 pkt_dev->flags &= ~F_VID_RND;
1203
1204 else if (strcmp(f, "SVID_RND") == 0)
1205 pkt_dev->flags |= F_SVID_RND;
1206
1207 else if (strcmp(f, "!SVID_RND") == 0)
1208 pkt_dev->flags &= ~F_SVID_RND;
1209
Jamal Hadi Salim007a5312007-07-02 22:40:36 -07001210 else if (strcmp(f, "FLOW_SEQ") == 0)
1211 pkt_dev->flags |= F_FLOW_SEQ;
1212
Robert Olsson45b270f2007-08-28 15:45:55 -07001213 else if (strcmp(f, "QUEUE_MAP_RND") == 0)
1214 pkt_dev->flags |= F_QUEUE_MAP_RND;
1215
1216 else if (strcmp(f, "!QUEUE_MAP_RND") == 0)
1217 pkt_dev->flags &= ~F_QUEUE_MAP_RND;
Robert Olssone6fce5b2008-08-07 02:23:01 -07001218
1219 else if (strcmp(f, "QUEUE_MAP_CPU") == 0)
1220 pkt_dev->flags |= F_QUEUE_MAP_CPU;
1221
1222 else if (strcmp(f, "!QUEUE_MAP_CPU") == 0)
1223 pkt_dev->flags &= ~F_QUEUE_MAP_CPU;
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07001224#ifdef CONFIG_XFRM
1225 else if (strcmp(f, "IPSEC") == 0)
1226 pkt_dev->flags |= F_IPSEC_ON;
1227#endif
1228
Francesco Fondelli1ca77682006-09-27 16:32:03 -07001229 else if (strcmp(f, "!IPV6") == 0)
1230 pkt_dev->flags &= ~F_IPV6;
1231
Robert Olssone99b99b2010-03-18 22:44:30 +00001232 else if (strcmp(f, "NODE_ALLOC") == 0)
1233 pkt_dev->flags |= F_NODE;
1234
1235 else if (strcmp(f, "!NODE_ALLOC") == 0)
1236 pkt_dev->flags &= ~F_NODE;
1237
Luiz Capitulino222f1802006-03-20 22:16:13 -08001238 else {
1239 sprintf(pg_result,
1240 "Flag -:%s:- unknown\nAvailable flags, (prepend ! to un-set flag):\n%s",
1241 f,
Francesco Fondelli1ca77682006-09-27 16:32:03 -07001242 "IPSRC_RND, IPDST_RND, UDPSRC_RND, UDPDST_RND, "
Robert Olssone99b99b2010-03-18 22:44:30 +00001243 "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 -08001244 return count;
1245 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 sprintf(pg_result, "OK: flags=0x%x", pkt_dev->flags);
1247 return count;
1248 }
1249 if (!strcmp(name, "dst_min") || !strcmp(name, "dst")) {
1250 len = strn_len(&user_buffer[i], sizeof(pkt_dev->dst_min) - 1);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001251 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001252 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253
Luiz Capitulino222f1802006-03-20 22:16:13 -08001254 if (copy_from_user(buf, &user_buffer[i], len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 return -EFAULT;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001256 buf[len] = 0;
1257 if (strcmp(buf, pkt_dev->dst_min) != 0) {
1258 memset(pkt_dev->dst_min, 0, sizeof(pkt_dev->dst_min));
1259 strncpy(pkt_dev->dst_min, buf, len);
1260 pkt_dev->daddr_min = in_aton(pkt_dev->dst_min);
1261 pkt_dev->cur_daddr = pkt_dev->daddr_min;
1262 }
1263 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001264 printk(KERN_DEBUG "pktgen: dst_min set to: %s\n",
Luiz Capitulino222f1802006-03-20 22:16:13 -08001265 pkt_dev->dst_min);
1266 i += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 sprintf(pg_result, "OK: dst_min=%s", pkt_dev->dst_min);
1268 return count;
1269 }
1270 if (!strcmp(name, "dst_max")) {
1271 len = strn_len(&user_buffer[i], sizeof(pkt_dev->dst_max) - 1);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001272 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001273 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001274
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
Luiz Capitulino222f1802006-03-20 22:16:13 -08001276 if (copy_from_user(buf, &user_buffer[i], len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 return -EFAULT;
1278
Luiz Capitulino222f1802006-03-20 22:16:13 -08001279 buf[len] = 0;
1280 if (strcmp(buf, pkt_dev->dst_max) != 0) {
1281 memset(pkt_dev->dst_max, 0, sizeof(pkt_dev->dst_max));
1282 strncpy(pkt_dev->dst_max, buf, len);
1283 pkt_dev->daddr_max = in_aton(pkt_dev->dst_max);
1284 pkt_dev->cur_daddr = pkt_dev->daddr_max;
1285 }
1286 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001287 printk(KERN_DEBUG "pktgen: dst_max set to: %s\n",
Luiz Capitulino222f1802006-03-20 22:16:13 -08001288 pkt_dev->dst_max);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 i += len;
1290 sprintf(pg_result, "OK: dst_max=%s", pkt_dev->dst_max);
1291 return count;
1292 }
1293 if (!strcmp(name, "dst6")) {
1294 len = strn_len(&user_buffer[i], sizeof(buf) - 1);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001295 if (len < 0)
1296 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
1298 pkt_dev->flags |= F_IPV6;
1299
Luiz Capitulino222f1802006-03-20 22:16:13 -08001300 if (copy_from_user(buf, &user_buffer[i], len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 return -EFAULT;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001302 buf[len] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303
1304 scan_ip6(buf, pkt_dev->in6_daddr.s6_addr);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001305 fmt_ip6(buf, pkt_dev->in6_daddr.s6_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
1307 ipv6_addr_copy(&pkt_dev->cur_in6_daddr, &pkt_dev->in6_daddr);
1308
Luiz Capitulino222f1802006-03-20 22:16:13 -08001309 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001310 printk(KERN_DEBUG "pktgen: dst6 set to: %s\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Luiz Capitulino222f1802006-03-20 22:16:13 -08001312 i += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 sprintf(pg_result, "OK: dst6=%s", buf);
1314 return count;
1315 }
1316 if (!strcmp(name, "dst6_min")) {
1317 len = strn_len(&user_buffer[i], sizeof(buf) - 1);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001318 if (len < 0)
1319 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320
1321 pkt_dev->flags |= F_IPV6;
1322
Luiz Capitulino222f1802006-03-20 22:16:13 -08001323 if (copy_from_user(buf, &user_buffer[i], len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 return -EFAULT;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001325 buf[len] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326
1327 scan_ip6(buf, pkt_dev->min_in6_daddr.s6_addr);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001328 fmt_ip6(buf, pkt_dev->min_in6_daddr.s6_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
Luiz Capitulino222f1802006-03-20 22:16:13 -08001330 ipv6_addr_copy(&pkt_dev->cur_in6_daddr,
1331 &pkt_dev->min_in6_daddr);
1332 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001333 printk(KERN_DEBUG "pktgen: dst6_min set to: %s\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334
Luiz Capitulino222f1802006-03-20 22:16:13 -08001335 i += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 sprintf(pg_result, "OK: dst6_min=%s", buf);
1337 return count;
1338 }
1339 if (!strcmp(name, "dst6_max")) {
1340 len = strn_len(&user_buffer[i], sizeof(buf) - 1);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001341 if (len < 0)
1342 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
1344 pkt_dev->flags |= F_IPV6;
1345
Luiz Capitulino222f1802006-03-20 22:16:13 -08001346 if (copy_from_user(buf, &user_buffer[i], len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 return -EFAULT;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001348 buf[len] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349
1350 scan_ip6(buf, pkt_dev->max_in6_daddr.s6_addr);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001351 fmt_ip6(buf, pkt_dev->max_in6_daddr.s6_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
Luiz Capitulino222f1802006-03-20 22:16:13 -08001353 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001354 printk(KERN_DEBUG "pktgen: dst6_max set to: %s\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355
Luiz Capitulino222f1802006-03-20 22:16:13 -08001356 i += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 sprintf(pg_result, "OK: dst6_max=%s", buf);
1358 return count;
1359 }
1360 if (!strcmp(name, "src6")) {
1361 len = strn_len(&user_buffer[i], sizeof(buf) - 1);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001362 if (len < 0)
1363 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364
1365 pkt_dev->flags |= F_IPV6;
1366
Luiz Capitulino222f1802006-03-20 22:16:13 -08001367 if (copy_from_user(buf, &user_buffer[i], len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 return -EFAULT;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001369 buf[len] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370
1371 scan_ip6(buf, pkt_dev->in6_saddr.s6_addr);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001372 fmt_ip6(buf, pkt_dev->in6_saddr.s6_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373
1374 ipv6_addr_copy(&pkt_dev->cur_in6_saddr, &pkt_dev->in6_saddr);
1375
Luiz Capitulino222f1802006-03-20 22:16:13 -08001376 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001377 printk(KERN_DEBUG "pktgen: src6 set to: %s\n", buf);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001378
1379 i += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 sprintf(pg_result, "OK: src6=%s", buf);
1381 return count;
1382 }
1383 if (!strcmp(name, "src_min")) {
1384 len = strn_len(&user_buffer[i], sizeof(pkt_dev->src_min) - 1);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001385 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001386 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001387
Luiz Capitulino222f1802006-03-20 22:16:13 -08001388 if (copy_from_user(buf, &user_buffer[i], len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 return -EFAULT;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001390 buf[len] = 0;
1391 if (strcmp(buf, pkt_dev->src_min) != 0) {
1392 memset(pkt_dev->src_min, 0, sizeof(pkt_dev->src_min));
1393 strncpy(pkt_dev->src_min, buf, len);
1394 pkt_dev->saddr_min = in_aton(pkt_dev->src_min);
1395 pkt_dev->cur_saddr = pkt_dev->saddr_min;
1396 }
1397 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001398 printk(KERN_DEBUG "pktgen: src_min set to: %s\n",
Luiz Capitulino222f1802006-03-20 22:16:13 -08001399 pkt_dev->src_min);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 i += len;
1401 sprintf(pg_result, "OK: src_min=%s", pkt_dev->src_min);
1402 return count;
1403 }
1404 if (!strcmp(name, "src_max")) {
1405 len = strn_len(&user_buffer[i], sizeof(pkt_dev->src_max) - 1);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001406 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001407 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001408
Luiz Capitulino222f1802006-03-20 22:16:13 -08001409 if (copy_from_user(buf, &user_buffer[i], len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 return -EFAULT;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001411 buf[len] = 0;
1412 if (strcmp(buf, pkt_dev->src_max) != 0) {
1413 memset(pkt_dev->src_max, 0, sizeof(pkt_dev->src_max));
1414 strncpy(pkt_dev->src_max, buf, len);
1415 pkt_dev->saddr_max = in_aton(pkt_dev->src_max);
1416 pkt_dev->cur_saddr = pkt_dev->saddr_max;
1417 }
1418 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001419 printk(KERN_DEBUG "pktgen: src_max set to: %s\n",
Luiz Capitulino222f1802006-03-20 22:16:13 -08001420 pkt_dev->src_max);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 i += len;
1422 sprintf(pg_result, "OK: src_max=%s", pkt_dev->src_max);
1423 return count;
1424 }
1425 if (!strcmp(name, "dst_mac")) {
1426 char *v = valstr;
Kris Katterjohnf404e9a2006-01-17 13:04:57 -08001427 unsigned char old_dmac[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 unsigned char *m = pkt_dev->dst_mac;
Kris Katterjohnf404e9a2006-01-17 13:04:57 -08001429 memcpy(old_dmac, pkt_dev->dst_mac, ETH_ALEN);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001430
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 len = strn_len(&user_buffer[i], sizeof(valstr) - 1);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001432 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001433 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001434
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 memset(valstr, 0, sizeof(valstr));
Luiz Capitulino222f1802006-03-20 22:16:13 -08001436 if (copy_from_user(valstr, &user_buffer[i], len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 return -EFAULT;
1438 i += len;
1439
Luiz Capitulino222f1802006-03-20 22:16:13 -08001440 for (*m = 0; *v && m < pkt_dev->dst_mac + 6; v++) {
Andy Shevchenko451e07a2010-07-23 03:18:10 +00001441 int value;
1442
1443 value = hex_to_bin(*v);
1444 if (value >= 0)
1445 *m = *m * 16 + value;
1446
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 if (*v == ':') {
1448 m++;
1449 *m = 0;
1450 }
1451 }
1452
1453 /* Set up Dest MAC */
Kris Katterjohnf404e9a2006-01-17 13:04:57 -08001454 if (compare_ether_addr(old_dmac, pkt_dev->dst_mac))
1455 memcpy(&(pkt_dev->hh[0]), pkt_dev->dst_mac, ETH_ALEN);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001456
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 sprintf(pg_result, "OK: dstmac");
1458 return count;
1459 }
1460 if (!strcmp(name, "src_mac")) {
1461 char *v = valstr;
Adit Ranadivece5d0b42007-09-16 14:52:15 -07001462 unsigned char old_smac[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 unsigned char *m = pkt_dev->src_mac;
1464
Adit Ranadivece5d0b42007-09-16 14:52:15 -07001465 memcpy(old_smac, pkt_dev->src_mac, ETH_ALEN);
1466
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 len = strn_len(&user_buffer[i], sizeof(valstr) - 1);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001468 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001469 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001470
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 memset(valstr, 0, sizeof(valstr));
Luiz Capitulino222f1802006-03-20 22:16:13 -08001472 if (copy_from_user(valstr, &user_buffer[i], len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 return -EFAULT;
1474 i += len;
1475
Luiz Capitulino222f1802006-03-20 22:16:13 -08001476 for (*m = 0; *v && m < pkt_dev->src_mac + 6; v++) {
Andy Shevchenko451e07a2010-07-23 03:18:10 +00001477 int value;
1478
1479 value = hex_to_bin(*v);
1480 if (value >= 0)
1481 *m = *m * 16 + value;
1482
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 if (*v == ':') {
1484 m++;
1485 *m = 0;
1486 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08001487 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
Adit Ranadivece5d0b42007-09-16 14:52:15 -07001489 /* Set up Src MAC */
1490 if (compare_ether_addr(old_smac, pkt_dev->src_mac))
1491 memcpy(&(pkt_dev->hh[6]), pkt_dev->src_mac, ETH_ALEN);
1492
Luiz Capitulino222f1802006-03-20 22:16:13 -08001493 sprintf(pg_result, "OK: srcmac");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 return count;
1495 }
1496
Luiz Capitulino222f1802006-03-20 22:16:13 -08001497 if (!strcmp(name, "clear_counters")) {
1498 pktgen_clear_counters(pkt_dev);
1499 sprintf(pg_result, "OK: Clearing counters.\n");
1500 return count;
1501 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502
1503 if (!strcmp(name, "flows")) {
1504 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001505 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001506 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001507
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 i += len;
1509 if (value > MAX_CFLOWS)
1510 value = MAX_CFLOWS;
1511
1512 pkt_dev->cflows = value;
1513 sprintf(pg_result, "OK: flows=%u", pkt_dev->cflows);
1514 return count;
1515 }
1516
1517 if (!strcmp(name, "flowlen")) {
1518 len = num_arg(&user_buffer[i], 10, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001519 if (len < 0)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001520 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001521
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 i += len;
1523 pkt_dev->lflow = value;
1524 sprintf(pg_result, "OK: flowlen=%u", pkt_dev->lflow);
1525 return count;
1526 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08001527
Robert Olsson45b270f2007-08-28 15:45:55 -07001528 if (!strcmp(name, "queue_map_min")) {
1529 len = num_arg(&user_buffer[i], 5, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001530 if (len < 0)
Robert Olsson45b270f2007-08-28 15:45:55 -07001531 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001532
Robert Olsson45b270f2007-08-28 15:45:55 -07001533 i += len;
1534 pkt_dev->queue_map_min = value;
1535 sprintf(pg_result, "OK: queue_map_min=%u", pkt_dev->queue_map_min);
1536 return count;
1537 }
1538
1539 if (!strcmp(name, "queue_map_max")) {
1540 len = num_arg(&user_buffer[i], 5, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001541 if (len < 0)
Robert Olsson45b270f2007-08-28 15:45:55 -07001542 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001543
Robert Olsson45b270f2007-08-28 15:45:55 -07001544 i += len;
1545 pkt_dev->queue_map_max = value;
1546 sprintf(pg_result, "OK: queue_map_max=%u", pkt_dev->queue_map_max);
1547 return count;
1548 }
1549
Steven Whitehouseca6549a2006-03-23 01:10:26 -08001550 if (!strcmp(name, "mpls")) {
Stephen Hemmingercfcabdc2007-10-09 01:59:42 -07001551 unsigned n, cnt;
1552
Steven Whitehouseca6549a2006-03-23 01:10:26 -08001553 len = get_labels(&user_buffer[i], pkt_dev);
Stephen Hemmingercfcabdc2007-10-09 01:59:42 -07001554 if (len < 0)
1555 return len;
Steven Whitehouseca6549a2006-03-23 01:10:26 -08001556 i += len;
Stephen Hemmingercfcabdc2007-10-09 01:59:42 -07001557 cnt = sprintf(pg_result, "OK: mpls=");
Stephen Hemmingere71a4782007-04-10 20:10:33 -07001558 for (n = 0; n < pkt_dev->nr_labels; n++)
Stephen Hemmingercfcabdc2007-10-09 01:59:42 -07001559 cnt += sprintf(pg_result + cnt,
1560 "%08x%s", ntohl(pkt_dev->labels[n]),
1561 n == pkt_dev->nr_labels-1 ? "" : ",");
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001562
1563 if (pkt_dev->nr_labels && pkt_dev->vlan_id != 0xffff) {
1564 pkt_dev->vlan_id = 0xffff; /* turn off VLAN/SVLAN */
1565 pkt_dev->svlan_id = 0xffff;
1566
1567 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001568 printk(KERN_DEBUG "pktgen: VLAN/SVLAN auto turned off\n");
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001569 }
1570 return count;
1571 }
1572
1573 if (!strcmp(name, "vlan_id")) {
1574 len = num_arg(&user_buffer[i], 4, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001575 if (len < 0)
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001576 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001577
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001578 i += len;
1579 if (value <= 4095) {
1580 pkt_dev->vlan_id = value; /* turn on VLAN */
1581
1582 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001583 printk(KERN_DEBUG "pktgen: VLAN turned on\n");
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001584
1585 if (debug && pkt_dev->nr_labels)
David S. Miller25a8b252007-07-30 16:11:48 -07001586 printk(KERN_DEBUG "pktgen: MPLS auto turned off\n");
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001587
1588 pkt_dev->nr_labels = 0; /* turn off MPLS */
1589 sprintf(pg_result, "OK: vlan_id=%u", pkt_dev->vlan_id);
1590 } else {
1591 pkt_dev->vlan_id = 0xffff; /* turn off VLAN/SVLAN */
1592 pkt_dev->svlan_id = 0xffff;
1593
1594 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001595 printk(KERN_DEBUG "pktgen: VLAN/SVLAN turned off\n");
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001596 }
1597 return count;
1598 }
1599
1600 if (!strcmp(name, "vlan_p")) {
1601 len = num_arg(&user_buffer[i], 1, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001602 if (len < 0)
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001603 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001604
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001605 i += len;
1606 if ((value <= 7) && (pkt_dev->vlan_id != 0xffff)) {
1607 pkt_dev->vlan_p = value;
1608 sprintf(pg_result, "OK: vlan_p=%u", pkt_dev->vlan_p);
1609 } else {
1610 sprintf(pg_result, "ERROR: vlan_p must be 0-7");
1611 }
1612 return count;
1613 }
1614
1615 if (!strcmp(name, "vlan_cfi")) {
1616 len = num_arg(&user_buffer[i], 1, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001617 if (len < 0)
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001618 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001619
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001620 i += len;
1621 if ((value <= 1) && (pkt_dev->vlan_id != 0xffff)) {
1622 pkt_dev->vlan_cfi = value;
1623 sprintf(pg_result, "OK: vlan_cfi=%u", pkt_dev->vlan_cfi);
1624 } else {
1625 sprintf(pg_result, "ERROR: vlan_cfi must be 0-1");
1626 }
1627 return count;
1628 }
1629
1630 if (!strcmp(name, "svlan_id")) {
1631 len = num_arg(&user_buffer[i], 4, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001632 if (len < 0)
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001633 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001634
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001635 i += len;
1636 if ((value <= 4095) && ((pkt_dev->vlan_id != 0xffff))) {
1637 pkt_dev->svlan_id = value; /* turn on SVLAN */
1638
1639 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001640 printk(KERN_DEBUG "pktgen: SVLAN turned on\n");
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001641
1642 if (debug && pkt_dev->nr_labels)
David S. Miller25a8b252007-07-30 16:11:48 -07001643 printk(KERN_DEBUG "pktgen: MPLS auto turned off\n");
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001644
1645 pkt_dev->nr_labels = 0; /* turn off MPLS */
1646 sprintf(pg_result, "OK: svlan_id=%u", pkt_dev->svlan_id);
1647 } else {
1648 pkt_dev->vlan_id = 0xffff; /* turn off VLAN/SVLAN */
1649 pkt_dev->svlan_id = 0xffff;
1650
1651 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001652 printk(KERN_DEBUG "pktgen: VLAN/SVLAN turned off\n");
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001653 }
1654 return count;
1655 }
1656
1657 if (!strcmp(name, "svlan_p")) {
1658 len = num_arg(&user_buffer[i], 1, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001659 if (len < 0)
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001660 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001661
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001662 i += len;
1663 if ((value <= 7) && (pkt_dev->svlan_id != 0xffff)) {
1664 pkt_dev->svlan_p = value;
1665 sprintf(pg_result, "OK: svlan_p=%u", pkt_dev->svlan_p);
1666 } else {
1667 sprintf(pg_result, "ERROR: svlan_p must be 0-7");
1668 }
1669 return count;
1670 }
1671
1672 if (!strcmp(name, "svlan_cfi")) {
1673 len = num_arg(&user_buffer[i], 1, &value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001674 if (len < 0)
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001675 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001676
Francesco Fondelli34954dd2006-09-27 16:30:44 -07001677 i += len;
1678 if ((value <= 1) && (pkt_dev->svlan_id != 0xffff)) {
1679 pkt_dev->svlan_cfi = value;
1680 sprintf(pg_result, "OK: svlan_cfi=%u", pkt_dev->svlan_cfi);
1681 } else {
1682 sprintf(pg_result, "ERROR: svlan_cfi must be 0-1");
1683 }
Steven Whitehouseca6549a2006-03-23 01:10:26 -08001684 return count;
1685 }
1686
Francesco Fondelli1ca77682006-09-27 16:32:03 -07001687 if (!strcmp(name, "tos")) {
1688 __u32 tmp_value = 0;
1689 len = hex32_arg(&user_buffer[i], 2, &tmp_value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001690 if (len < 0)
Francesco Fondelli1ca77682006-09-27 16:32:03 -07001691 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001692
Francesco Fondelli1ca77682006-09-27 16:32:03 -07001693 i += len;
1694 if (len == 2) {
1695 pkt_dev->tos = tmp_value;
1696 sprintf(pg_result, "OK: tos=0x%02x", pkt_dev->tos);
1697 } else {
1698 sprintf(pg_result, "ERROR: tos must be 00-ff");
1699 }
1700 return count;
1701 }
1702
1703 if (!strcmp(name, "traffic_class")) {
1704 __u32 tmp_value = 0;
1705 len = hex32_arg(&user_buffer[i], 2, &tmp_value);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001706 if (len < 0)
Francesco Fondelli1ca77682006-09-27 16:32:03 -07001707 return len;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001708
Francesco Fondelli1ca77682006-09-27 16:32:03 -07001709 i += len;
1710 if (len == 2) {
1711 pkt_dev->traffic_class = tmp_value;
1712 sprintf(pg_result, "OK: traffic_class=0x%02x", pkt_dev->traffic_class);
1713 } else {
1714 sprintf(pg_result, "ERROR: traffic_class must be 00-ff");
1715 }
1716 return count;
1717 }
1718
John Fastabend9e50e3a2010-11-16 19:12:28 +00001719 if (!strcmp(name, "skb_priority")) {
1720 len = num_arg(&user_buffer[i], 9, &value);
1721 if (len < 0)
1722 return len;
1723
1724 i += len;
1725 pkt_dev->skb_priority = value;
1726 sprintf(pg_result, "OK: skb_priority=%i",
1727 pkt_dev->skb_priority);
1728 return count;
1729 }
1730
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 sprintf(pkt_dev->result, "No such parameter \"%s\"", name);
1732 return -EINVAL;
1733}
1734
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001735static int pktgen_if_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736{
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001737 return single_open(file, pktgen_if_show, PDE(inode)->data);
1738}
1739
Arjan van de Ven9a321442007-02-12 00:55:35 -08001740static const struct file_operations pktgen_if_fops = {
Luiz Capitulino222f1802006-03-20 22:16:13 -08001741 .owner = THIS_MODULE,
1742 .open = pktgen_if_open,
1743 .read = seq_read,
1744 .llseek = seq_lseek,
1745 .write = pktgen_if_write,
1746 .release = single_release,
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001747};
1748
1749static int pktgen_thread_show(struct seq_file *seq, void *v)
1750{
Luiz Capitulino222f1802006-03-20 22:16:13 -08001751 struct pktgen_thread *t = seq->private;
Stephen Hemminger648fda72009-08-27 13:55:07 +00001752 const struct pktgen_dev *pkt_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001754 BUG_ON(!t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755
Luiz Capitulino222f1802006-03-20 22:16:13 -08001756 seq_printf(seq, "Running: ");
1757
1758 if_lock(t);
Luiz Capitulinoc26a80162006-03-20 22:18:16 -08001759 list_for_each_entry(pkt_dev, &t->if_list, list)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001760 if (pkt_dev->running)
Eric Dumazet593f63b2009-11-23 01:44:37 +00001761 seq_printf(seq, "%s ", pkt_dev->odevname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762
Luiz Capitulino222f1802006-03-20 22:16:13 -08001763 seq_printf(seq, "\nStopped: ");
1764
Luiz Capitulinoc26a80162006-03-20 22:18:16 -08001765 list_for_each_entry(pkt_dev, &t->if_list, list)
Luiz Capitulino222f1802006-03-20 22:16:13 -08001766 if (!pkt_dev->running)
Eric Dumazet593f63b2009-11-23 01:44:37 +00001767 seq_printf(seq, "%s ", pkt_dev->odevname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768
1769 if (t->result[0])
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001770 seq_printf(seq, "\nResult: %s\n", t->result);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 else
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001772 seq_printf(seq, "\nResult: NA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773
Luiz Capitulino222f1802006-03-20 22:16:13 -08001774 if_unlock(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001776 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777}
1778
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001779static ssize_t pktgen_thread_write(struct file *file,
Luiz Capitulino222f1802006-03-20 22:16:13 -08001780 const char __user * user_buffer,
1781 size_t count, loff_t * offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782{
Joe Perches8a994a72010-07-12 10:50:23 +00001783 struct seq_file *seq = file->private_data;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001784 struct pktgen_thread *t = seq->private;
Paul Gortmakerd6182222010-10-18 12:14:44 +00001785 int i, max, len, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 char name[40];
Luiz Capitulino222f1802006-03-20 22:16:13 -08001787 char *pg_result;
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001788
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 if (count < 1) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08001790 // sprintf(pg_result, "Wrong command format");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 return -EINVAL;
1792 }
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001793
Paul Gortmakerd6182222010-10-18 12:14:44 +00001794 max = count;
1795 len = count_trail_chars(user_buffer, max);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001796 if (len < 0)
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001797 return len;
1798
Paul Gortmakerd6182222010-10-18 12:14:44 +00001799 i = len;
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001800
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 /* Read variable name */
1802
1803 len = strn_len(&user_buffer[i], sizeof(name) - 1);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001804 if (len < 0)
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001805 return len;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001806
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 memset(name, 0, sizeof(name));
1808 if (copy_from_user(name, &user_buffer[i], len))
1809 return -EFAULT;
1810 i += len;
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001811
Luiz Capitulino222f1802006-03-20 22:16:13 -08001812 max = count - i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 len = count_trail_chars(&user_buffer[i], max);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001814 if (len < 0)
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001815 return len;
1816
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 i += len;
1818
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001819 if (debug)
David S. Miller25a8b252007-07-30 16:11:48 -07001820 printk(KERN_DEBUG "pktgen: t=%s, count=%lu\n",
1821 name, (unsigned long)count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822
Luiz Capitulino222f1802006-03-20 22:16:13 -08001823 if (!t) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00001824 pr_err("ERROR: No thread\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 ret = -EINVAL;
1826 goto out;
1827 }
1828
1829 pg_result = &(t->result[0]);
1830
Luiz Capitulino222f1802006-03-20 22:16:13 -08001831 if (!strcmp(name, "add_device")) {
1832 char f[32];
1833 memset(f, 0, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 len = strn_len(&user_buffer[i], sizeof(f) - 1);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001835 if (len < 0) {
1836 ret = len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 goto out;
1838 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08001839 if (copy_from_user(f, &user_buffer[i], len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 return -EFAULT;
1841 i += len;
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08001842 mutex_lock(&pktgen_thread_lock);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001843 pktgen_add_device(t, f);
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08001844 mutex_unlock(&pktgen_thread_lock);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001845 ret = count;
1846 sprintf(pg_result, "OK: add_device=%s", f);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 goto out;
1848 }
1849
Luiz Capitulino222f1802006-03-20 22:16:13 -08001850 if (!strcmp(name, "rem_device_all")) {
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08001851 mutex_lock(&pktgen_thread_lock);
Arthur Kepner95ed63f2006-03-20 21:26:56 -08001852 t->control |= T_REMDEVALL;
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08001853 mutex_unlock(&pktgen_thread_lock);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001854 schedule_timeout_interruptible(msecs_to_jiffies(125)); /* Propagate thread->control */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 ret = count;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001856 sprintf(pg_result, "OK: rem_device_all");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 goto out;
1858 }
1859
Luiz Capitulino222f1802006-03-20 22:16:13 -08001860 if (!strcmp(name, "max_before_softirq")) {
Robert Olssonb1639112007-08-28 15:46:58 -07001861 sprintf(pg_result, "OK: Note! max_before_softirq is obsoleted -- Do not use");
Luiz Capitulino222f1802006-03-20 22:16:13 -08001862 ret = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 goto out;
1864 }
1865
1866 ret = -EINVAL;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001867out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 return ret;
1869}
1870
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001871static int pktgen_thread_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872{
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001873 return single_open(file, pktgen_thread_show, PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874}
1875
Arjan van de Ven9a321442007-02-12 00:55:35 -08001876static const struct file_operations pktgen_thread_fops = {
Luiz Capitulino222f1802006-03-20 22:16:13 -08001877 .owner = THIS_MODULE,
1878 .open = pktgen_thread_open,
1879 .read = seq_read,
1880 .llseek = seq_lseek,
1881 .write = pktgen_thread_write,
1882 .release = single_release,
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07001883};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884
1885/* Think find or remove for NN */
Luiz Capitulino222f1802006-03-20 22:16:13 -08001886static struct pktgen_dev *__pktgen_NN_threads(const char *ifname, int remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887{
1888 struct pktgen_thread *t;
1889 struct pktgen_dev *pkt_dev = NULL;
Eric Dumazet3e984842009-11-24 14:50:53 -08001890 bool exact = (remove == FIND);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08001892 list_for_each_entry(t, &pktgen_threads, th_list) {
Eric Dumazet3e984842009-11-24 14:50:53 -08001893 pkt_dev = pktgen_find_dev(t, ifname, exact);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 if (pkt_dev) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08001895 if (remove) {
1896 if_lock(t);
1897 pkt_dev->removal_mark = 1;
1898 t->control |= T_REMDEV;
1899 if_unlock(t);
1900 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 break;
1902 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08001904 return pkt_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905}
1906
Arthur Kepner95ed63f2006-03-20 21:26:56 -08001907/*
1908 * mark a device for removal
1909 */
Stephen Hemminger39df2322007-03-04 16:11:51 -08001910static void pktgen_mark_device(const char *ifname)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911{
1912 struct pktgen_dev *pkt_dev = NULL;
Arthur Kepner95ed63f2006-03-20 21:26:56 -08001913 const int max_tries = 10, msec_per_try = 125;
1914 int i = 0;
Arthur Kepner95ed63f2006-03-20 21:26:56 -08001915
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08001916 mutex_lock(&pktgen_thread_lock);
Joe Perchesf9467ea2010-06-21 12:29:14 +00001917 pr_debug("%s: marking %s for removal\n", __func__, ifname);
Arthur Kepner95ed63f2006-03-20 21:26:56 -08001918
Luiz Capitulino222f1802006-03-20 22:16:13 -08001919 while (1) {
Arthur Kepner95ed63f2006-03-20 21:26:56 -08001920
1921 pkt_dev = __pktgen_NN_threads(ifname, REMOVE);
Luiz Capitulino222f1802006-03-20 22:16:13 -08001922 if (pkt_dev == NULL)
1923 break; /* success */
Arthur Kepner95ed63f2006-03-20 21:26:56 -08001924
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08001925 mutex_unlock(&pktgen_thread_lock);
Joe Perchesf9467ea2010-06-21 12:29:14 +00001926 pr_debug("%s: waiting for %s to disappear....\n",
1927 __func__, ifname);
Arthur Kepner95ed63f2006-03-20 21:26:56 -08001928 schedule_timeout_interruptible(msecs_to_jiffies(msec_per_try));
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08001929 mutex_lock(&pktgen_thread_lock);
Arthur Kepner95ed63f2006-03-20 21:26:56 -08001930
1931 if (++i >= max_tries) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00001932 pr_err("%s: timed out after waiting %d msec for device %s to be removed\n",
1933 __func__, msec_per_try * i, ifname);
Arthur Kepner95ed63f2006-03-20 21:26:56 -08001934 break;
1935 }
1936
1937 }
1938
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08001939 mutex_unlock(&pktgen_thread_lock);
Stephen Hemminger39df2322007-03-04 16:11:51 -08001940}
Arthur Kepner95ed63f2006-03-20 21:26:56 -08001941
Stephen Hemminger39df2322007-03-04 16:11:51 -08001942static void pktgen_change_name(struct net_device *dev)
1943{
1944 struct pktgen_thread *t;
1945
1946 list_for_each_entry(t, &pktgen_threads, th_list) {
1947 struct pktgen_dev *pkt_dev;
1948
1949 list_for_each_entry(pkt_dev, &t->if_list, list) {
1950 if (pkt_dev->odev != dev)
1951 continue;
1952
1953 remove_proc_entry(pkt_dev->entry->name, pg_proc_dir);
1954
Alexey Dobriyan29753152009-08-28 23:34:43 -07001955 pkt_dev->entry = proc_create_data(dev->name, 0600,
1956 pg_proc_dir,
1957 &pktgen_if_fops,
1958 pkt_dev);
Stephen Hemminger39df2322007-03-04 16:11:51 -08001959 if (!pkt_dev->entry)
Joe Perchesf9467ea2010-06-21 12:29:14 +00001960 pr_err("can't move proc entry for '%s'\n",
1961 dev->name);
Stephen Hemminger39df2322007-03-04 16:11:51 -08001962 break;
1963 }
1964 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965}
1966
Luiz Capitulino222f1802006-03-20 22:16:13 -08001967static int pktgen_device_event(struct notifier_block *unused,
1968 unsigned long event, void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969{
Stephen Hemminger39df2322007-03-04 16:11:51 -08001970 struct net_device *dev = ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971
YOSHIFUJI Hideaki721499e2008-07-19 22:34:43 -07001972 if (!net_eq(dev_net(dev), &init_net))
Eric W. Biedermane9dc8652007-09-12 13:02:17 +02001973 return NOTIFY_DONE;
1974
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 /* It is OK that we do not hold the group lock right now,
1976 * as we run under the RTNL lock.
1977 */
1978
1979 switch (event) {
Stephen Hemminger39df2322007-03-04 16:11:51 -08001980 case NETDEV_CHANGENAME:
1981 pktgen_change_name(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982 break;
Luiz Capitulino222f1802006-03-20 22:16:13 -08001983
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 case NETDEV_UNREGISTER:
Luiz Capitulino222f1802006-03-20 22:16:13 -08001985 pktgen_mark_device(dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 break;
Stephen Hemminger3ff50b72007-04-20 17:09:22 -07001987 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988
1989 return NOTIFY_DONE;
1990}
1991
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001992static struct net_device *pktgen_dev_get_by_name(struct pktgen_dev *pkt_dev,
1993 const char *ifname)
Robert Olssone6fce5b2008-08-07 02:23:01 -07001994{
1995 char b[IFNAMSIZ+5];
Paul Gortmakerd6182222010-10-18 12:14:44 +00001996 int i;
Robert Olssone6fce5b2008-08-07 02:23:01 -07001997
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00001998 for (i = 0; ifname[i] != '@'; i++) {
1999 if (i == IFNAMSIZ)
Robert Olssone6fce5b2008-08-07 02:23:01 -07002000 break;
2001
2002 b[i] = ifname[i];
2003 }
2004 b[i] = 0;
2005
2006 return dev_get_by_name(&init_net, b);
2007}
2008
2009
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010/* Associate pktgen_dev with a device. */
2011
Stephen Hemminger39df2322007-03-04 16:11:51 -08002012static int pktgen_setup_dev(struct pktgen_dev *pkt_dev, const char *ifname)
Luiz Capitulino222f1802006-03-20 22:16:13 -08002013{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 struct net_device *odev;
Stephen Hemminger39df2322007-03-04 16:11:51 -08002015 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016
2017 /* Clean old setups */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 if (pkt_dev->odev) {
2019 dev_put(pkt_dev->odev);
Luiz Capitulino222f1802006-03-20 22:16:13 -08002020 pkt_dev->odev = NULL;
2021 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022
Robert Olssone6fce5b2008-08-07 02:23:01 -07002023 odev = pktgen_dev_get_by_name(pkt_dev, ifname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 if (!odev) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00002025 pr_err("no such netdevice: \"%s\"\n", ifname);
Stephen Hemminger39df2322007-03-04 16:11:51 -08002026 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 }
Stephen Hemminger39df2322007-03-04 16:11:51 -08002028
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 if (odev->type != ARPHRD_ETHER) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00002030 pr_err("not an ethernet device: \"%s\"\n", ifname);
Stephen Hemminger39df2322007-03-04 16:11:51 -08002031 err = -EINVAL;
2032 } else if (!netif_running(odev)) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00002033 pr_err("device is down: \"%s\"\n", ifname);
Stephen Hemminger39df2322007-03-04 16:11:51 -08002034 err = -ENETDOWN;
2035 } else {
2036 pkt_dev->odev = odev;
2037 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08002039
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 dev_put(odev);
Stephen Hemminger39df2322007-03-04 16:11:51 -08002041 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042}
2043
2044/* Read pkt_dev from the interface and set up internal pktgen_dev
2045 * structure to have the right information to create/send packets
2046 */
2047static void pktgen_setup_inject(struct pktgen_dev *pkt_dev)
2048{
Andrew Gallatin64c00d82008-08-13 15:16:00 -07002049 int ntxq;
2050
Luiz Capitulino222f1802006-03-20 22:16:13 -08002051 if (!pkt_dev->odev) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00002052 pr_err("ERROR: pkt_dev->odev == NULL in setup_inject\n");
Luiz Capitulino222f1802006-03-20 22:16:13 -08002053 sprintf(pkt_dev->result,
2054 "ERROR: pkt_dev->odev == NULL in setup_inject.\n");
2055 return;
2056 }
2057
Andrew Gallatin64c00d82008-08-13 15:16:00 -07002058 /* make sure that we don't pick a non-existing transmit queue */
2059 ntxq = pkt_dev->odev->real_num_tx_queues;
Robert Olssonbfdbc0a2008-11-19 14:09:47 -08002060
Andrew Gallatin64c00d82008-08-13 15:16:00 -07002061 if (ntxq <= pkt_dev->queue_map_min) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00002062 pr_warning("WARNING: Requested queue_map_min (zero-based) (%d) exceeds valid range [0 - %d] for (%d) queues on %s, resetting\n",
2063 pkt_dev->queue_map_min, (ntxq ?: 1) - 1, ntxq,
2064 pkt_dev->odevname);
Andrew Gallatin64c00d82008-08-13 15:16:00 -07002065 pkt_dev->queue_map_min = ntxq - 1;
2066 }
Jesse Brandeburg88271662008-10-28 13:21:51 -07002067 if (pkt_dev->queue_map_max >= ntxq) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00002068 pr_warning("WARNING: Requested queue_map_max (zero-based) (%d) exceeds valid range [0 - %d] for (%d) queues on %s, resetting\n",
2069 pkt_dev->queue_map_max, (ntxq ?: 1) - 1, ntxq,
2070 pkt_dev->odevname);
Andrew Gallatin64c00d82008-08-13 15:16:00 -07002071 pkt_dev->queue_map_max = ntxq - 1;
2072 }
2073
Luiz Capitulino222f1802006-03-20 22:16:13 -08002074 /* Default to the interface's mac if not explicitly set. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075
Kris Katterjohnf404e9a2006-01-17 13:04:57 -08002076 if (is_zero_ether_addr(pkt_dev->src_mac))
Luiz Capitulino222f1802006-03-20 22:16:13 -08002077 memcpy(&(pkt_dev->hh[6]), pkt_dev->odev->dev_addr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078
Luiz Capitulino222f1802006-03-20 22:16:13 -08002079 /* Set up Dest MAC */
Kris Katterjohnf404e9a2006-01-17 13:04:57 -08002080 memcpy(&(pkt_dev->hh[0]), pkt_dev->dst_mac, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
Luiz Capitulino222f1802006-03-20 22:16:13 -08002082 /* Set up pkt size */
2083 pkt_dev->cur_pkt_size = pkt_dev->min_pkt_size;
2084
2085 if (pkt_dev->flags & F_IPV6) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 /*
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09002087 * Skip this automatic address setting until locks or functions
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 * gets exported
2089 */
2090
2091#ifdef NOTNOW
Luiz Capitulino222f1802006-03-20 22:16:13 -08002092 int i, set = 0, err = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 struct inet6_dev *idev;
2094
Luiz Capitulino222f1802006-03-20 22:16:13 -08002095 for (i = 0; i < IN6_ADDR_HSIZE; i++)
2096 if (pkt_dev->cur_in6_saddr.s6_addr[i]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 set = 1;
2098 break;
2099 }
2100
Luiz Capitulino222f1802006-03-20 22:16:13 -08002101 if (!set) {
2102
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 /*
2104 * Use linklevel address if unconfigured.
2105 *
2106 * use ipv6_get_lladdr if/when it's get exported
2107 */
2108
YOSHIFUJI Hideaki8814c4b2006-09-22 14:44:24 -07002109 rcu_read_lock();
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00002110 idev = __in6_dev_get(pkt_dev->odev);
2111 if (idev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 struct inet6_ifaddr *ifp;
2113
2114 read_lock_bh(&idev->lock);
Luiz Capitulino222f1802006-03-20 22:16:13 -08002115 for (ifp = idev->addr_list; ifp;
2116 ifp = ifp->if_next) {
Joe Perchesf64f9e72009-11-29 16:55:45 -08002117 if (ifp->scope == IFA_LINK &&
2118 !(ifp->flags & IFA_F_TENTATIVE)) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08002119 ipv6_addr_copy(&pkt_dev->
2120 cur_in6_saddr,
2121 &ifp->addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 err = 0;
2123 break;
2124 }
2125 }
2126 read_unlock_bh(&idev->lock);
2127 }
YOSHIFUJI Hideaki8814c4b2006-09-22 14:44:24 -07002128 rcu_read_unlock();
Luiz Capitulino222f1802006-03-20 22:16:13 -08002129 if (err)
Joe Perchesf9467ea2010-06-21 12:29:14 +00002130 pr_err("ERROR: IPv6 link address not available\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 }
2132#endif
Luiz Capitulino222f1802006-03-20 22:16:13 -08002133 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 pkt_dev->saddr_min = 0;
2135 pkt_dev->saddr_max = 0;
2136 if (strlen(pkt_dev->src_min) == 0) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08002137
2138 struct in_device *in_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139
2140 rcu_read_lock();
Herbert Xue5ed6392005-10-03 14:35:55 -07002141 in_dev = __in_dev_get_rcu(pkt_dev->odev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 if (in_dev) {
2143 if (in_dev->ifa_list) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08002144 pkt_dev->saddr_min =
2145 in_dev->ifa_list->ifa_address;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 pkt_dev->saddr_max = pkt_dev->saddr_min;
2147 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 }
2149 rcu_read_unlock();
Luiz Capitulino222f1802006-03-20 22:16:13 -08002150 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 pkt_dev->saddr_min = in_aton(pkt_dev->src_min);
2152 pkt_dev->saddr_max = in_aton(pkt_dev->src_max);
2153 }
2154
2155 pkt_dev->daddr_min = in_aton(pkt_dev->dst_min);
2156 pkt_dev->daddr_max = in_aton(pkt_dev->dst_max);
2157 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08002158 /* Initialize current values. */
2159 pkt_dev->cur_dst_mac_offset = 0;
2160 pkt_dev->cur_src_mac_offset = 0;
2161 pkt_dev->cur_saddr = pkt_dev->saddr_min;
2162 pkt_dev->cur_daddr = pkt_dev->daddr_min;
2163 pkt_dev->cur_udp_dst = pkt_dev->udp_dst_min;
2164 pkt_dev->cur_udp_src = pkt_dev->udp_src_min;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 pkt_dev->nflows = 0;
2166}
2167
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00002169static void spin(struct pktgen_dev *pkt_dev, ktime_t spin_until)
2170{
Stephen Hemmingeref879792009-09-22 19:41:43 +00002171 ktime_t start_time, end_time;
Eric Dumazet417bc4b2009-10-01 09:29:45 -07002172 s64 remaining;
Stephen Hemminger2bc481c2009-08-28 23:41:29 -07002173 struct hrtimer_sleeper t;
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00002174
Stephen Hemminger2bc481c2009-08-28 23:41:29 -07002175 hrtimer_init_on_stack(&t.timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
2176 hrtimer_set_expires(&t.timer, spin_until);
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00002177
Daniel Turull43d28b62010-06-09 22:49:57 +00002178 remaining = ktime_to_ns(hrtimer_expires_remaining(&t.timer));
Eric Dumazet417bc4b2009-10-01 09:29:45 -07002179 if (remaining <= 0) {
2180 pkt_dev->next_tx = ktime_add_ns(spin_until, pkt_dev->delay);
Stephen Hemminger2bc481c2009-08-28 23:41:29 -07002181 return;
Eric Dumazet417bc4b2009-10-01 09:29:45 -07002182 }
Stephen Hemminger2bc481c2009-08-28 23:41:29 -07002183
Stephen Hemmingeref879792009-09-22 19:41:43 +00002184 start_time = ktime_now();
Daniel Turull43d28b62010-06-09 22:49:57 +00002185 if (remaining < 100000)
2186 ndelay(remaining); /* really small just spin */
Stephen Hemminger2bc481c2009-08-28 23:41:29 -07002187 else {
2188 /* see do_nanosleep */
2189 hrtimer_init_sleeper(&t, current);
2190 do {
2191 set_current_state(TASK_INTERRUPTIBLE);
2192 hrtimer_start_expires(&t.timer, HRTIMER_MODE_ABS);
2193 if (!hrtimer_active(&t.timer))
2194 t.task = NULL;
2195
2196 if (likely(t.task))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198
Stephen Hemminger2bc481c2009-08-28 23:41:29 -07002199 hrtimer_cancel(&t.timer);
2200 } while (t.task && pkt_dev->running && !signal_pending(current));
2201 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 }
Stephen Hemmingeref879792009-09-22 19:41:43 +00002203 end_time = ktime_now();
2204
2205 pkt_dev->idle_acc += ktime_to_ns(ktime_sub(end_time, start_time));
Daniel Turull07a0f0f2010-06-10 23:08:11 -07002206 pkt_dev->next_tx = ktime_add_ns(spin_until, pkt_dev->delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207}
2208
Jamal Hadi Salim16dab722007-07-02 22:39:50 -07002209static inline void set_pkt_overhead(struct pktgen_dev *pkt_dev)
2210{
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002211 pkt_dev->pkt_overhead = 0;
Jamal Hadi Salim16dab722007-07-02 22:39:50 -07002212 pkt_dev->pkt_overhead += pkt_dev->nr_labels*sizeof(u32);
2213 pkt_dev->pkt_overhead += VLAN_TAG_SIZE(pkt_dev);
2214 pkt_dev->pkt_overhead += SVLAN_TAG_SIZE(pkt_dev);
2215}
2216
Stephen Hemminger648fda72009-08-27 13:55:07 +00002217static inline int f_seen(const struct pktgen_dev *pkt_dev, int flow)
Jamal Hadi Salim007a5312007-07-02 22:40:36 -07002218{
Stephen Hemminger648fda72009-08-27 13:55:07 +00002219 return !!(pkt_dev->flows[flow].flags & F_INIT);
Jamal Hadi Salim007a5312007-07-02 22:40:36 -07002220}
2221
2222static inline int f_pick(struct pktgen_dev *pkt_dev)
2223{
2224 int flow = pkt_dev->curfl;
2225
2226 if (pkt_dev->flags & F_FLOW_SEQ) {
2227 if (pkt_dev->flows[flow].count >= pkt_dev->lflow) {
2228 /* reset time */
2229 pkt_dev->flows[flow].count = 0;
Robert Olsson1211a642008-08-05 18:44:26 -07002230 pkt_dev->flows[flow].flags = 0;
Jamal Hadi Salim007a5312007-07-02 22:40:36 -07002231 pkt_dev->curfl += 1;
2232 if (pkt_dev->curfl >= pkt_dev->cflows)
2233 pkt_dev->curfl = 0; /*reset */
2234 }
2235 } else {
2236 flow = random32() % pkt_dev->cflows;
Robert Olsson1211a642008-08-05 18:44:26 -07002237 pkt_dev->curfl = flow;
Jamal Hadi Salim007a5312007-07-02 22:40:36 -07002238
Robert Olsson1211a642008-08-05 18:44:26 -07002239 if (pkt_dev->flows[flow].count > pkt_dev->lflow) {
Jamal Hadi Salim007a5312007-07-02 22:40:36 -07002240 pkt_dev->flows[flow].count = 0;
Robert Olsson1211a642008-08-05 18:44:26 -07002241 pkt_dev->flows[flow].flags = 0;
2242 }
Jamal Hadi Salim007a5312007-07-02 22:40:36 -07002243 }
2244
2245 return pkt_dev->curfl;
2246}
2247
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002248
2249#ifdef CONFIG_XFRM
2250/* If there was already an IPSEC SA, we keep it as is, else
2251 * we go look for it ...
2252*/
Jamal Hadi Salimbd557752010-02-22 16:20:22 -08002253#define DUMMY_MARK 0
Adrian Bunkfea1ab02007-07-30 18:04:09 -07002254static void get_ipsec_sa(struct pktgen_dev *pkt_dev, int flow)
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002255{
2256 struct xfrm_state *x = pkt_dev->flows[flow].x;
2257 if (!x) {
2258 /*slow path: we dont already have xfrm_state*/
Jamal Hadi Salimbd557752010-02-22 16:20:22 -08002259 x = xfrm_stateonly_find(&init_net, DUMMY_MARK,
Alexey Dobriyan5447c5e2008-11-25 17:31:51 -08002260 (xfrm_address_t *)&pkt_dev->cur_daddr,
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002261 (xfrm_address_t *)&pkt_dev->cur_saddr,
2262 AF_INET,
2263 pkt_dev->ipsmode,
2264 pkt_dev->ipsproto, 0);
2265 if (x) {
2266 pkt_dev->flows[flow].x = x;
2267 set_pkt_overhead(pkt_dev);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00002268 pkt_dev->pkt_overhead += x->props.header_len;
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002269 }
2270
2271 }
2272}
2273#endif
David S. Millerfd2ea0a2008-07-17 01:56:23 -07002274static void set_cur_queue_map(struct pktgen_dev *pkt_dev)
2275{
Robert Olssone6fce5b2008-08-07 02:23:01 -07002276
2277 if (pkt_dev->flags & F_QUEUE_MAP_CPU)
2278 pkt_dev->cur_queue_map = smp_processor_id();
2279
Eric Dumazet896a7cf2009-10-02 20:24:59 +00002280 else if (pkt_dev->queue_map_min <= pkt_dev->queue_map_max) {
David S. Millerfd2ea0a2008-07-17 01:56:23 -07002281 __u16 t;
2282 if (pkt_dev->flags & F_QUEUE_MAP_RND) {
2283 t = random32() %
2284 (pkt_dev->queue_map_max -
2285 pkt_dev->queue_map_min + 1)
2286 + pkt_dev->queue_map_min;
2287 } else {
2288 t = pkt_dev->cur_queue_map + 1;
2289 if (t > pkt_dev->queue_map_max)
2290 t = pkt_dev->queue_map_min;
2291 }
2292 pkt_dev->cur_queue_map = t;
2293 }
Robert Olssonbfdbc0a2008-11-19 14:09:47 -08002294 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 -07002295}
2296
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297/* Increment/randomize headers according to flags and current values
2298 * for IP src/dest, UDP src/dst port, MAC-Addr src/dst
2299 */
Luiz Capitulino222f1802006-03-20 22:16:13 -08002300static void mod_cur_headers(struct pktgen_dev *pkt_dev)
2301{
2302 __u32 imn;
2303 __u32 imx;
2304 int flow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305
Jamal Hadi Salim007a5312007-07-02 22:40:36 -07002306 if (pkt_dev->cflows)
2307 flow = f_pick(pkt_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308
2309 /* Deal with source MAC */
Luiz Capitulino222f1802006-03-20 22:16:13 -08002310 if (pkt_dev->src_mac_count > 1) {
2311 __u32 mc;
2312 __u32 tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313
Luiz Capitulino222f1802006-03-20 22:16:13 -08002314 if (pkt_dev->flags & F_MACSRC_RND)
Stephen Hemminger5fa6fc72007-03-04 16:07:28 -08002315 mc = random32() % pkt_dev->src_mac_count;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002316 else {
2317 mc = pkt_dev->cur_src_mac_offset++;
Robert Olssonff2a79a2008-08-05 18:45:05 -07002318 if (pkt_dev->cur_src_mac_offset >=
Luiz Capitulino222f1802006-03-20 22:16:13 -08002319 pkt_dev->src_mac_count)
2320 pkt_dev->cur_src_mac_offset = 0;
2321 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322
Luiz Capitulino222f1802006-03-20 22:16:13 -08002323 tmp = pkt_dev->src_mac[5] + (mc & 0xFF);
2324 pkt_dev->hh[11] = tmp;
2325 tmp = (pkt_dev->src_mac[4] + ((mc >> 8) & 0xFF) + (tmp >> 8));
2326 pkt_dev->hh[10] = tmp;
2327 tmp = (pkt_dev->src_mac[3] + ((mc >> 16) & 0xFF) + (tmp >> 8));
2328 pkt_dev->hh[9] = tmp;
2329 tmp = (pkt_dev->src_mac[2] + ((mc >> 24) & 0xFF) + (tmp >> 8));
2330 pkt_dev->hh[8] = tmp;
2331 tmp = (pkt_dev->src_mac[1] + (tmp >> 8));
2332 pkt_dev->hh[7] = tmp;
2333 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334
Luiz Capitulino222f1802006-03-20 22:16:13 -08002335 /* Deal with Destination MAC */
2336 if (pkt_dev->dst_mac_count > 1) {
2337 __u32 mc;
2338 __u32 tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339
Luiz Capitulino222f1802006-03-20 22:16:13 -08002340 if (pkt_dev->flags & F_MACDST_RND)
Stephen Hemminger5fa6fc72007-03-04 16:07:28 -08002341 mc = random32() % pkt_dev->dst_mac_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342
Luiz Capitulino222f1802006-03-20 22:16:13 -08002343 else {
2344 mc = pkt_dev->cur_dst_mac_offset++;
Robert Olssonff2a79a2008-08-05 18:45:05 -07002345 if (pkt_dev->cur_dst_mac_offset >=
Luiz Capitulino222f1802006-03-20 22:16:13 -08002346 pkt_dev->dst_mac_count) {
2347 pkt_dev->cur_dst_mac_offset = 0;
2348 }
2349 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350
Luiz Capitulino222f1802006-03-20 22:16:13 -08002351 tmp = pkt_dev->dst_mac[5] + (mc & 0xFF);
2352 pkt_dev->hh[5] = tmp;
2353 tmp = (pkt_dev->dst_mac[4] + ((mc >> 8) & 0xFF) + (tmp >> 8));
2354 pkt_dev->hh[4] = tmp;
2355 tmp = (pkt_dev->dst_mac[3] + ((mc >> 16) & 0xFF) + (tmp >> 8));
2356 pkt_dev->hh[3] = tmp;
2357 tmp = (pkt_dev->dst_mac[2] + ((mc >> 24) & 0xFF) + (tmp >> 8));
2358 pkt_dev->hh[2] = tmp;
2359 tmp = (pkt_dev->dst_mac[1] + (tmp >> 8));
2360 pkt_dev->hh[1] = tmp;
2361 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002363 if (pkt_dev->flags & F_MPLS_RND) {
2364 unsigned i;
Stephen Hemmingere71a4782007-04-10 20:10:33 -07002365 for (i = 0; i < pkt_dev->nr_labels; i++)
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002366 if (pkt_dev->labels[i] & MPLS_STACK_BOTTOM)
2367 pkt_dev->labels[i] = MPLS_STACK_BOTTOM |
Stephen Hemminger5fa6fc72007-03-04 16:07:28 -08002368 ((__force __be32)random32() &
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002369 htonl(0x000fffff));
2370 }
2371
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002372 if ((pkt_dev->flags & F_VID_RND) && (pkt_dev->vlan_id != 0xffff)) {
Stephen Hemminger5fa6fc72007-03-04 16:07:28 -08002373 pkt_dev->vlan_id = random32() & (4096-1);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002374 }
2375
2376 if ((pkt_dev->flags & F_SVID_RND) && (pkt_dev->svlan_id != 0xffff)) {
Stephen Hemminger5fa6fc72007-03-04 16:07:28 -08002377 pkt_dev->svlan_id = random32() & (4096 - 1);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002378 }
2379
Luiz Capitulino222f1802006-03-20 22:16:13 -08002380 if (pkt_dev->udp_src_min < pkt_dev->udp_src_max) {
2381 if (pkt_dev->flags & F_UDPSRC_RND)
Stephen Hemminger5fa6fc72007-03-04 16:07:28 -08002382 pkt_dev->cur_udp_src = random32() %
2383 (pkt_dev->udp_src_max - pkt_dev->udp_src_min)
2384 + pkt_dev->udp_src_min;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385
Luiz Capitulino222f1802006-03-20 22:16:13 -08002386 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 pkt_dev->cur_udp_src++;
2388 if (pkt_dev->cur_udp_src >= pkt_dev->udp_src_max)
2389 pkt_dev->cur_udp_src = pkt_dev->udp_src_min;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002390 }
2391 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392
Luiz Capitulino222f1802006-03-20 22:16:13 -08002393 if (pkt_dev->udp_dst_min < pkt_dev->udp_dst_max) {
2394 if (pkt_dev->flags & F_UDPDST_RND) {
Stephen Hemminger5fa6fc72007-03-04 16:07:28 -08002395 pkt_dev->cur_udp_dst = random32() %
2396 (pkt_dev->udp_dst_max - pkt_dev->udp_dst_min)
2397 + pkt_dev->udp_dst_min;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002398 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 pkt_dev->cur_udp_dst++;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002400 if (pkt_dev->cur_udp_dst >= pkt_dev->udp_dst_max)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 pkt_dev->cur_udp_dst = pkt_dev->udp_dst_min;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002402 }
2403 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404
2405 if (!(pkt_dev->flags & F_IPV6)) {
2406
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00002407 imn = ntohl(pkt_dev->saddr_min);
2408 imx = ntohl(pkt_dev->saddr_max);
2409 if (imn < imx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 __u32 t;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002411 if (pkt_dev->flags & F_IPSRC_RND)
Stephen Hemminger5fa6fc72007-03-04 16:07:28 -08002412 t = random32() % (imx - imn) + imn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 else {
2414 t = ntohl(pkt_dev->cur_saddr);
2415 t++;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00002416 if (t > imx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 t = imn;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00002418
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 }
2420 pkt_dev->cur_saddr = htonl(t);
2421 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08002422
Jamal Hadi Salim007a5312007-07-02 22:40:36 -07002423 if (pkt_dev->cflows && f_seen(pkt_dev, flow)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 pkt_dev->cur_daddr = pkt_dev->flows[flow].cur_daddr;
2425 } else {
Al Viro252e33462006-11-14 20:48:11 -08002426 imn = ntohl(pkt_dev->daddr_min);
2427 imx = ntohl(pkt_dev->daddr_max);
2428 if (imn < imx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 __u32 t;
Al Viro252e33462006-11-14 20:48:11 -08002430 __be32 s;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 if (pkt_dev->flags & F_IPDST_RND) {
2432
Stephen Hemminger5fa6fc72007-03-04 16:07:28 -08002433 t = random32() % (imx - imn) + imn;
Al Viro252e33462006-11-14 20:48:11 -08002434 s = htonl(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435
Joe Perches21cf2252007-12-16 13:44:00 -08002436 while (ipv4_is_loopback(s) ||
2437 ipv4_is_multicast(s) ||
Jan Engelhardt1e637c72008-01-21 03:18:08 -08002438 ipv4_is_lbcast(s) ||
Joe Perches21cf2252007-12-16 13:44:00 -08002439 ipv4_is_zeronet(s) ||
2440 ipv4_is_local_multicast(s)) {
Stephen Hemminger5fa6fc72007-03-04 16:07:28 -08002441 t = random32() % (imx - imn) + imn;
Al Viro252e33462006-11-14 20:48:11 -08002442 s = htonl(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 }
Al Viro252e33462006-11-14 20:48:11 -08002444 pkt_dev->cur_daddr = s;
2445 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 t = ntohl(pkt_dev->cur_daddr);
2447 t++;
2448 if (t > imx) {
2449 t = imn;
2450 }
2451 pkt_dev->cur_daddr = htonl(t);
2452 }
2453 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08002454 if (pkt_dev->cflows) {
Jamal Hadi Salim007a5312007-07-02 22:40:36 -07002455 pkt_dev->flows[flow].flags |= F_INIT;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002456 pkt_dev->flows[flow].cur_daddr =
2457 pkt_dev->cur_daddr;
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002458#ifdef CONFIG_XFRM
2459 if (pkt_dev->flags & F_IPSEC_ON)
2460 get_ipsec_sa(pkt_dev, flow);
2461#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 pkt_dev->nflows++;
2463 }
2464 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08002465 } else { /* IPV6 * */
2466
2467 if (pkt_dev->min_in6_daddr.s6_addr32[0] == 0 &&
2468 pkt_dev->min_in6_daddr.s6_addr32[1] == 0 &&
2469 pkt_dev->min_in6_daddr.s6_addr32[2] == 0 &&
2470 pkt_dev->min_in6_daddr.s6_addr32[3] == 0) ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 else {
2472 int i;
2473
2474 /* Only random destinations yet */
2475
Luiz Capitulino222f1802006-03-20 22:16:13 -08002476 for (i = 0; i < 4; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 pkt_dev->cur_in6_daddr.s6_addr32[i] =
Stephen Hemminger5fa6fc72007-03-04 16:07:28 -08002478 (((__force __be32)random32() |
Luiz Capitulino222f1802006-03-20 22:16:13 -08002479 pkt_dev->min_in6_daddr.s6_addr32[i]) &
2480 pkt_dev->max_in6_daddr.s6_addr32[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08002482 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 }
2484
Luiz Capitulino222f1802006-03-20 22:16:13 -08002485 if (pkt_dev->min_pkt_size < pkt_dev->max_pkt_size) {
2486 __u32 t;
2487 if (pkt_dev->flags & F_TXSIZE_RND) {
Stephen Hemminger5fa6fc72007-03-04 16:07:28 -08002488 t = random32() %
2489 (pkt_dev->max_pkt_size - pkt_dev->min_pkt_size)
2490 + pkt_dev->min_pkt_size;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002491 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 t = pkt_dev->cur_pkt_size + 1;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002493 if (t > pkt_dev->max_pkt_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 t = pkt_dev->min_pkt_size;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002495 }
2496 pkt_dev->cur_pkt_size = t;
2497 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498
David S. Millerfd2ea0a2008-07-17 01:56:23 -07002499 set_cur_queue_map(pkt_dev);
Robert Olsson45b270f2007-08-28 15:45:55 -07002500
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 pkt_dev->flows[flow].count++;
2502}
2503
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002504
2505#ifdef CONFIG_XFRM
2506static int pktgen_output_ipsec(struct sk_buff *skb, struct pktgen_dev *pkt_dev)
2507{
2508 struct xfrm_state *x = pkt_dev->flows[pkt_dev->curfl].x;
2509 int err = 0;
2510 struct iphdr *iph;
2511
2512 if (!x)
2513 return 0;
2514 /* XXX: we dont support tunnel mode for now until
2515 * we resolve the dst issue */
2516 if (x->props.mode != XFRM_MODE_TRANSPORT)
2517 return 0;
2518
2519 spin_lock(&x->lock);
2520 iph = ip_hdr(skb);
2521
Herbert Xu13996372007-10-17 21:35:51 -07002522 err = x->outer_mode->output(x, skb);
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002523 if (err)
2524 goto error;
2525 err = x->type->output(x, skb);
2526 if (err)
2527 goto error;
2528
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00002529 x->curlft.bytes += skb->len;
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002530 x->curlft.packets++;
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002531error:
2532 spin_unlock(&x->lock);
2533 return err;
2534}
2535
Stephen Hemminger475ac1e2009-08-27 13:55:08 +00002536static void free_SAs(struct pktgen_dev *pkt_dev)
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002537{
2538 if (pkt_dev->cflows) {
2539 /* let go of the SAs if we have them */
Paul Gortmakerd6182222010-10-18 12:14:44 +00002540 int i;
2541 for (i = 0; i < pkt_dev->cflows; i++) {
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002542 struct xfrm_state *x = pkt_dev->flows[i].x;
2543 if (x) {
2544 xfrm_state_put(x);
2545 pkt_dev->flows[i].x = NULL;
2546 }
2547 }
2548 }
2549}
2550
Stephen Hemminger475ac1e2009-08-27 13:55:08 +00002551static int process_ipsec(struct pktgen_dev *pkt_dev,
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002552 struct sk_buff *skb, __be16 protocol)
2553{
2554 if (pkt_dev->flags & F_IPSEC_ON) {
2555 struct xfrm_state *x = pkt_dev->flows[pkt_dev->curfl].x;
2556 int nhead = 0;
2557 if (x) {
2558 int ret;
2559 __u8 *eth;
2560 nhead = x->props.header_len - skb_headroom(skb);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00002561 if (nhead > 0) {
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002562 ret = pskb_expand_head(skb, nhead, 0, GFP_ATOMIC);
2563 if (ret < 0) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00002564 pr_err("Error expanding ipsec packet %d\n",
2565 ret);
Ilpo Järvinenb4bb4ac2008-10-13 18:43:59 -07002566 goto err;
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002567 }
2568 }
2569
2570 /* ipsec is not expecting ll header */
2571 skb_pull(skb, ETH_HLEN);
2572 ret = pktgen_output_ipsec(skb, pkt_dev);
2573 if (ret) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00002574 pr_err("Error creating ipsec packet %d\n", ret);
Ilpo Järvinenb4bb4ac2008-10-13 18:43:59 -07002575 goto err;
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002576 }
2577 /* restore ll */
2578 eth = (__u8 *) skb_push(skb, ETH_HLEN);
2579 memcpy(eth, pkt_dev->hh, 12);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00002580 *(u16 *) &eth[12] = protocol;
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002581 }
2582 }
2583 return 1;
Ilpo Järvinenb4bb4ac2008-10-13 18:43:59 -07002584err:
2585 kfree_skb(skb);
2586 return 0;
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002587}
2588#endif
2589
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002590static void mpls_push(__be32 *mpls, struct pktgen_dev *pkt_dev)
2591{
2592 unsigned i;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00002593 for (i = 0; i < pkt_dev->nr_labels; i++)
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002594 *mpls++ = pkt_dev->labels[i] & ~MPLS_STACK_BOTTOM;
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00002595
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002596 mpls--;
2597 *mpls |= MPLS_STACK_BOTTOM;
2598}
2599
Al Viro0f37c602006-11-03 03:49:56 -08002600static inline __be16 build_tci(unsigned int id, unsigned int cfi,
2601 unsigned int prio)
2602{
2603 return htons(id | (cfi << 12) | (prio << 13));
2604}
2605
Luiz Capitulino222f1802006-03-20 22:16:13 -08002606static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
2607 struct pktgen_dev *pkt_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608{
2609 struct sk_buff *skb = NULL;
2610 __u8 *eth;
2611 struct udphdr *udph;
2612 int datalen, iplen;
2613 struct iphdr *iph;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002614 struct pktgen_hdr *pgh = NULL;
Stephen Hemmingerd5f1ce92007-03-04 16:08:08 -08002615 __be16 protocol = htons(ETH_P_IP);
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002616 __be32 *mpls;
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002617 __be16 *vlan_tci = NULL; /* Encapsulates priority and VLAN ID */
2618 __be16 *vlan_encapsulated_proto = NULL; /* packet type ID field (or len) for VLAN tag */
2619 __be16 *svlan_tci = NULL; /* Encapsulates priority and SVLAN ID */
2620 __be16 *svlan_encapsulated_proto = NULL; /* packet type ID field (or len) for SVLAN tag */
David S. Millerfd2ea0a2008-07-17 01:56:23 -07002621 u16 queue_map;
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002622
2623 if (pkt_dev->nr_labels)
Stephen Hemmingerd5f1ce92007-03-04 16:08:08 -08002624 protocol = htons(ETH_P_MPLS_UC);
Luiz Capitulino222f1802006-03-20 22:16:13 -08002625
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002626 if (pkt_dev->vlan_id != 0xffff)
Stephen Hemmingerd5f1ce92007-03-04 16:08:08 -08002627 protocol = htons(ETH_P_8021Q);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002628
Robert Olsson64053be2005-06-26 15:27:10 -07002629 /* Update any of the values, used when we're incrementing various
2630 * fields.
2631 */
2632 mod_cur_headers(pkt_dev);
Junchang Wangeb589062010-11-07 23:19:43 +00002633 queue_map = pkt_dev->cur_queue_map;
Robert Olsson64053be2005-06-26 15:27:10 -07002634
David S. Miller7ac54592006-01-18 14:19:10 -08002635 datalen = (odev->hard_header_len + 16) & ~0xf;
Robert Olssone99b99b2010-03-18 22:44:30 +00002636
2637 if (pkt_dev->flags & F_NODE) {
2638 int node;
2639
2640 if (pkt_dev->node >= 0)
2641 node = pkt_dev->node;
2642 else
2643 node = numa_node_id();
2644
2645 skb = __alloc_skb(NET_SKB_PAD + pkt_dev->cur_pkt_size + 64
2646 + datalen + pkt_dev->pkt_overhead, GFP_NOWAIT, 0, node);
2647 if (likely(skb)) {
2648 skb_reserve(skb, NET_SKB_PAD);
2649 skb->dev = odev;
2650 }
2651 }
2652 else
2653 skb = __netdev_alloc_skb(odev,
2654 pkt_dev->cur_pkt_size + 64
2655 + datalen + pkt_dev->pkt_overhead, GFP_NOWAIT);
2656
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 if (!skb) {
2658 sprintf(pkt_dev->result, "No memory");
2659 return NULL;
2660 }
2661
David S. Miller7ac54592006-01-18 14:19:10 -08002662 skb_reserve(skb, datalen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663
2664 /* Reserve for ethernet and IP header */
2665 eth = (__u8 *) skb_push(skb, 14);
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002666 mpls = (__be32 *)skb_put(skb, pkt_dev->nr_labels*sizeof(__u32));
2667 if (pkt_dev->nr_labels)
2668 mpls_push(mpls, pkt_dev);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002669
2670 if (pkt_dev->vlan_id != 0xffff) {
Stephen Hemmingere71a4782007-04-10 20:10:33 -07002671 if (pkt_dev->svlan_id != 0xffff) {
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002672 svlan_tci = (__be16 *)skb_put(skb, sizeof(__be16));
Al Viro0f37c602006-11-03 03:49:56 -08002673 *svlan_tci = build_tci(pkt_dev->svlan_id,
2674 pkt_dev->svlan_cfi,
2675 pkt_dev->svlan_p);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002676 svlan_encapsulated_proto = (__be16 *)skb_put(skb, sizeof(__be16));
Stephen Hemmingerd5f1ce92007-03-04 16:08:08 -08002677 *svlan_encapsulated_proto = htons(ETH_P_8021Q);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002678 }
2679 vlan_tci = (__be16 *)skb_put(skb, sizeof(__be16));
Al Viro0f37c602006-11-03 03:49:56 -08002680 *vlan_tci = build_tci(pkt_dev->vlan_id,
2681 pkt_dev->vlan_cfi,
2682 pkt_dev->vlan_p);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002683 vlan_encapsulated_proto = (__be16 *)skb_put(skb, sizeof(__be16));
Stephen Hemmingerd5f1ce92007-03-04 16:08:08 -08002684 *vlan_encapsulated_proto = htons(ETH_P_IP);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002685 }
2686
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07002687 skb->network_header = skb->tail;
Arnaldo Carvalho de Melob0e380b2007-04-10 21:21:55 -07002688 skb->transport_header = skb->network_header + sizeof(struct iphdr);
Arnaldo Carvalho de Meloddc7b8e2007-03-15 21:42:27 -03002689 skb_put(skb, sizeof(struct iphdr) + sizeof(struct udphdr));
David S. Millerfd2ea0a2008-07-17 01:56:23 -07002690 skb_set_queue_mapping(skb, queue_map);
John Fastabend9e50e3a2010-11-16 19:12:28 +00002691 skb->priority = pkt_dev->skb_priority;
2692
Arnaldo Carvalho de Meloddc7b8e2007-03-15 21:42:27 -03002693 iph = ip_hdr(skb);
2694 udph = udp_hdr(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 memcpy(eth, pkt_dev->hh, 12);
Al Viro252e33462006-11-14 20:48:11 -08002697 *(__be16 *) & eth[12] = protocol;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002699 /* Eth + IPh + UDPh + mpls */
2700 datalen = pkt_dev->cur_pkt_size - 14 - 20 - 8 -
Jamal Hadi Salim16dab722007-07-02 22:39:50 -07002701 pkt_dev->pkt_overhead;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002702 if (datalen < sizeof(struct pktgen_hdr))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 datalen = sizeof(struct pktgen_hdr);
Luiz Capitulino222f1802006-03-20 22:16:13 -08002704
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 udph->source = htons(pkt_dev->cur_udp_src);
2706 udph->dest = htons(pkt_dev->cur_udp_dst);
Luiz Capitulino222f1802006-03-20 22:16:13 -08002707 udph->len = htons(datalen + 8); /* DATA + udphdr */
2708 udph->check = 0; /* No checksum */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709
2710 iph->ihl = 5;
2711 iph->version = 4;
2712 iph->ttl = 32;
Francesco Fondelli1ca77682006-09-27 16:32:03 -07002713 iph->tos = pkt_dev->tos;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002714 iph->protocol = IPPROTO_UDP; /* UDP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 iph->saddr = pkt_dev->cur_saddr;
2716 iph->daddr = pkt_dev->cur_daddr;
Eric Dumazet66ed1e52009-10-24 06:55:20 -07002717 iph->id = htons(pkt_dev->ip_id);
2718 pkt_dev->ip_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719 iph->frag_off = 0;
2720 iplen = 20 + 8 + datalen;
2721 iph->tot_len = htons(iplen);
2722 iph->check = 0;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002723 iph->check = ip_fast_csum((void *)iph, iph->ihl);
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002724 skb->protocol = protocol;
Arnaldo Carvalho de Melob0e380b2007-04-10 21:21:55 -07002725 skb->mac_header = (skb->network_header - ETH_HLEN -
Jamal Hadi Salim16dab722007-07-02 22:39:50 -07002726 pkt_dev->pkt_overhead);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 skb->dev = odev;
2728 skb->pkt_type = PACKET_HOST;
2729
Eric Dumazet66ed1e52009-10-24 06:55:20 -07002730 if (pkt_dev->nfrags <= 0) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08002731 pgh = (struct pktgen_hdr *)skb_put(skb, datalen);
Eric Dumazet66ed1e52009-10-24 06:55:20 -07002732 memset(pgh + 1, 0, datalen - sizeof(struct pktgen_hdr));
2733 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 int frags = pkt_dev->nfrags;
Eric Dumazet66ed1e52009-10-24 06:55:20 -07002735 int i, len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736
Luiz Capitulino222f1802006-03-20 22:16:13 -08002737 pgh = (struct pktgen_hdr *)(((char *)(udph)) + 8);
2738
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 if (frags > MAX_SKB_FRAGS)
2740 frags = MAX_SKB_FRAGS;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002741 if (datalen > frags * PAGE_SIZE) {
Eric Dumazet66ed1e52009-10-24 06:55:20 -07002742 len = datalen - frags * PAGE_SIZE;
2743 memset(skb_put(skb, len), 0, len);
Luiz Capitulino222f1802006-03-20 22:16:13 -08002744 datalen = frags * PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 }
2746
2747 i = 0;
2748 while (datalen > 0) {
Eric Dumazet66ed1e52009-10-24 06:55:20 -07002749 struct page *page = alloc_pages(GFP_KERNEL | __GFP_ZERO, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 skb_shinfo(skb)->frags[i].page = page;
2751 skb_shinfo(skb)->frags[i].page_offset = 0;
2752 skb_shinfo(skb)->frags[i].size =
Luiz Capitulino222f1802006-03-20 22:16:13 -08002753 (datalen < PAGE_SIZE ? datalen : PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 datalen -= skb_shinfo(skb)->frags[i].size;
2755 skb->len += skb_shinfo(skb)->frags[i].size;
2756 skb->data_len += skb_shinfo(skb)->frags[i].size;
2757 i++;
2758 skb_shinfo(skb)->nr_frags = i;
2759 }
2760
2761 while (i < frags) {
2762 int rem;
2763
2764 if (i == 0)
2765 break;
2766
2767 rem = skb_shinfo(skb)->frags[i - 1].size / 2;
2768 if (rem == 0)
2769 break;
2770
2771 skb_shinfo(skb)->frags[i - 1].size -= rem;
2772
Luiz Capitulino222f1802006-03-20 22:16:13 -08002773 skb_shinfo(skb)->frags[i] =
2774 skb_shinfo(skb)->frags[i - 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 get_page(skb_shinfo(skb)->frags[i].page);
Luiz Capitulino222f1802006-03-20 22:16:13 -08002776 skb_shinfo(skb)->frags[i].page =
2777 skb_shinfo(skb)->frags[i - 1].page;
2778 skb_shinfo(skb)->frags[i].page_offset +=
2779 skb_shinfo(skb)->frags[i - 1].size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 skb_shinfo(skb)->frags[i].size = rem;
2781 i++;
2782 skb_shinfo(skb)->nr_frags = i;
2783 }
2784 }
2785
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00002786 /* Stamp the time, and sequence number,
2787 * convert them to network byte order
2788 */
Luiz Capitulino222f1802006-03-20 22:16:13 -08002789 if (pgh) {
2790 struct timeval timestamp;
2791
2792 pgh->pgh_magic = htonl(PKTGEN_MAGIC);
2793 pgh->seq_num = htonl(pkt_dev->seq_num);
2794
2795 do_gettimeofday(&timestamp);
2796 pgh->tv_sec = htonl(timestamp.tv_sec);
2797 pgh->tv_usec = htonl(timestamp.tv_usec);
2798 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08002799
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07002800#ifdef CONFIG_XFRM
2801 if (!process_ipsec(pkt_dev, skb, protocol))
2802 return NULL;
2803#endif
2804
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 return skb;
2806}
2807
2808/*
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09002809 * scan_ip6, fmt_ip taken from dietlibc-0.21
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810 * Author Felix von Leitner <felix-dietlibc@fefe.de>
2811 *
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09002812 * Slightly modified for kernel.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 * Should be candidate for net/ipv4/utils.c
2814 * --ro
2815 */
2816
Luiz Capitulino222f1802006-03-20 22:16:13 -08002817static unsigned int scan_ip6(const char *s, char ip[16])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818{
2819 unsigned int i;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002820 unsigned int len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 unsigned long u;
2822 char suffix[16];
Luiz Capitulino222f1802006-03-20 22:16:13 -08002823 unsigned int prefixlen = 0;
2824 unsigned int suffixlen = 0;
Al Viro252e33462006-11-14 20:48:11 -08002825 __be32 tmp;
Stephen Hemmingercfcabdc2007-10-09 01:59:42 -07002826 char *pos;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827
Luiz Capitulino222f1802006-03-20 22:16:13 -08002828 for (i = 0; i < 16; i++)
2829 ip[i] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830
2831 for (;;) {
2832 if (*s == ':') {
2833 len++;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002834 if (s[1] == ':') { /* Found "::", skip to part 2 */
2835 s += 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 len++;
2837 break;
2838 }
2839 s++;
2840 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841
Stephen Hemmingercfcabdc2007-10-09 01:59:42 -07002842 u = simple_strtoul(s, &pos, 16);
2843 i = pos - s;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002844 if (!i)
2845 return 0;
2846 if (prefixlen == 12 && s[i] == '.') {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847
2848 /* the last 4 bytes may be written as IPv4 address */
2849
2850 tmp = in_aton(s);
Luiz Capitulino222f1802006-03-20 22:16:13 -08002851 memcpy((struct in_addr *)(ip + 12), &tmp, sizeof(tmp));
2852 return i + len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 }
2854 ip[prefixlen++] = (u >> 8);
2855 ip[prefixlen++] = (u & 255);
Luiz Capitulino222f1802006-03-20 22:16:13 -08002856 s += i;
2857 len += i;
2858 if (prefixlen == 16)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859 return len;
2860 }
2861
2862/* part 2, after "::" */
2863 for (;;) {
2864 if (*s == ':') {
Luiz Capitulino222f1802006-03-20 22:16:13 -08002865 if (suffixlen == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 break;
2867 s++;
2868 len++;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002869 } else if (suffixlen != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 break;
Stephen Hemmingercfcabdc2007-10-09 01:59:42 -07002871
2872 u = simple_strtol(s, &pos, 16);
2873 i = pos - s;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 if (!i) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08002875 if (*s)
2876 len--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 break;
2878 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08002879 if (suffixlen + prefixlen <= 12 && s[i] == '.') {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 tmp = in_aton(s);
Luiz Capitulino222f1802006-03-20 22:16:13 -08002881 memcpy((struct in_addr *)(suffix + suffixlen), &tmp,
2882 sizeof(tmp));
2883 suffixlen += 4;
2884 len += strlen(s);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 break;
2886 }
2887 suffix[suffixlen++] = (u >> 8);
2888 suffix[suffixlen++] = (u & 255);
Luiz Capitulino222f1802006-03-20 22:16:13 -08002889 s += i;
2890 len += i;
2891 if (prefixlen + suffixlen == 16)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 break;
2893 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08002894 for (i = 0; i < suffixlen; i++)
2895 ip[16 - suffixlen + i] = suffix[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896 return len;
2897}
2898
Luiz Capitulino222f1802006-03-20 22:16:13 -08002899static char tohex(char hexdigit)
2900{
2901 return hexdigit > 9 ? hexdigit + 'a' - 10 : hexdigit + '0';
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902}
2903
Luiz Capitulino222f1802006-03-20 22:16:13 -08002904static int fmt_xlong(char *s, unsigned int i)
2905{
2906 char *bak = s;
2907 *s = tohex((i >> 12) & 0xf);
2908 if (s != bak || *s != '0')
2909 ++s;
2910 *s = tohex((i >> 8) & 0xf);
2911 if (s != bak || *s != '0')
2912 ++s;
2913 *s = tohex((i >> 4) & 0xf);
2914 if (s != bak || *s != '0')
2915 ++s;
2916 *s = tohex(i & 0xf);
2917 return s - bak + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918}
2919
Luiz Capitulino222f1802006-03-20 22:16:13 -08002920static unsigned int fmt_ip6(char *s, const char ip[16])
2921{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 unsigned int len;
2923 unsigned int i;
2924 unsigned int temp;
2925 unsigned int compressing;
2926 int j;
2927
Luiz Capitulino222f1802006-03-20 22:16:13 -08002928 len = 0;
2929 compressing = 0;
2930 for (j = 0; j < 16; j += 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931
2932#ifdef V4MAPPEDPREFIX
Luiz Capitulino222f1802006-03-20 22:16:13 -08002933 if (j == 12 && !memcmp(ip, V4mappedprefix, 12)) {
2934 inet_ntoa_r(*(struct in_addr *)(ip + 12), s);
2935 temp = strlen(s);
2936 return len + temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 }
2938#endif
Luiz Capitulino222f1802006-03-20 22:16:13 -08002939 temp = ((unsigned long)(unsigned char)ip[j] << 8) +
2940 (unsigned long)(unsigned char)ip[j + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 if (temp == 0) {
2942 if (!compressing) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08002943 compressing = 1;
2944 if (j == 0) {
2945 *s++ = ':';
2946 ++len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 }
2948 }
2949 } else {
2950 if (compressing) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08002951 compressing = 0;
2952 *s++ = ':';
2953 ++len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08002955 i = fmt_xlong(s, temp);
2956 len += i;
2957 s += i;
2958 if (j < 14) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959 *s++ = ':';
2960 ++len;
2961 }
2962 }
2963 }
2964 if (compressing) {
Luiz Capitulino222f1802006-03-20 22:16:13 -08002965 *s++ = ':';
2966 ++len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08002968 *s = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 return len;
2970}
2971
Luiz Capitulino222f1802006-03-20 22:16:13 -08002972static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
2973 struct pktgen_dev *pkt_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974{
2975 struct sk_buff *skb = NULL;
2976 __u8 *eth;
2977 struct udphdr *udph;
2978 int datalen;
2979 struct ipv6hdr *iph;
Luiz Capitulino222f1802006-03-20 22:16:13 -08002980 struct pktgen_hdr *pgh = NULL;
Stephen Hemmingerd5f1ce92007-03-04 16:08:08 -08002981 __be16 protocol = htons(ETH_P_IPV6);
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002982 __be32 *mpls;
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002983 __be16 *vlan_tci = NULL; /* Encapsulates priority and VLAN ID */
2984 __be16 *vlan_encapsulated_proto = NULL; /* packet type ID field (or len) for VLAN tag */
2985 __be16 *svlan_tci = NULL; /* Encapsulates priority and SVLAN ID */
2986 __be16 *svlan_encapsulated_proto = NULL; /* packet type ID field (or len) for SVLAN tag */
David S. Millerfd2ea0a2008-07-17 01:56:23 -07002987 u16 queue_map;
Steven Whitehouseca6549a2006-03-23 01:10:26 -08002988
2989 if (pkt_dev->nr_labels)
Stephen Hemmingerd5f1ce92007-03-04 16:08:08 -08002990 protocol = htons(ETH_P_MPLS_UC);
Robert Olsson64053be2005-06-26 15:27:10 -07002991
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002992 if (pkt_dev->vlan_id != 0xffff)
Stephen Hemmingerd5f1ce92007-03-04 16:08:08 -08002993 protocol = htons(ETH_P_8021Q);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07002994
Robert Olsson64053be2005-06-26 15:27:10 -07002995 /* Update any of the values, used when we're incrementing various
2996 * fields.
2997 */
2998 mod_cur_headers(pkt_dev);
Junchang Wangeb589062010-11-07 23:19:43 +00002999 queue_map = pkt_dev->cur_queue_map;
Robert Olsson64053be2005-06-26 15:27:10 -07003000
Stephen Hemmingere4707572009-08-27 13:55:13 +00003001 skb = __netdev_alloc_skb(odev,
3002 pkt_dev->cur_pkt_size + 64
3003 + 16 + pkt_dev->pkt_overhead, GFP_NOWAIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 if (!skb) {
3005 sprintf(pkt_dev->result, "No memory");
3006 return NULL;
3007 }
3008
3009 skb_reserve(skb, 16);
3010
3011 /* Reserve for ethernet and IP header */
3012 eth = (__u8 *) skb_push(skb, 14);
Steven Whitehouseca6549a2006-03-23 01:10:26 -08003013 mpls = (__be32 *)skb_put(skb, pkt_dev->nr_labels*sizeof(__u32));
3014 if (pkt_dev->nr_labels)
3015 mpls_push(mpls, pkt_dev);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07003016
3017 if (pkt_dev->vlan_id != 0xffff) {
Stephen Hemmingere71a4782007-04-10 20:10:33 -07003018 if (pkt_dev->svlan_id != 0xffff) {
Francesco Fondelli34954dd2006-09-27 16:30:44 -07003019 svlan_tci = (__be16 *)skb_put(skb, sizeof(__be16));
Al Viro0f37c602006-11-03 03:49:56 -08003020 *svlan_tci = build_tci(pkt_dev->svlan_id,
3021 pkt_dev->svlan_cfi,
3022 pkt_dev->svlan_p);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07003023 svlan_encapsulated_proto = (__be16 *)skb_put(skb, sizeof(__be16));
Stephen Hemmingerd5f1ce92007-03-04 16:08:08 -08003024 *svlan_encapsulated_proto = htons(ETH_P_8021Q);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07003025 }
3026 vlan_tci = (__be16 *)skb_put(skb, sizeof(__be16));
Al Viro0f37c602006-11-03 03:49:56 -08003027 *vlan_tci = build_tci(pkt_dev->vlan_id,
3028 pkt_dev->vlan_cfi,
3029 pkt_dev->vlan_p);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07003030 vlan_encapsulated_proto = (__be16 *)skb_put(skb, sizeof(__be16));
Stephen Hemmingerd5f1ce92007-03-04 16:08:08 -08003031 *vlan_encapsulated_proto = htons(ETH_P_IPV6);
Francesco Fondelli34954dd2006-09-27 16:30:44 -07003032 }
3033
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07003034 skb->network_header = skb->tail;
Arnaldo Carvalho de Melob0e380b2007-04-10 21:21:55 -07003035 skb->transport_header = skb->network_header + sizeof(struct ipv6hdr);
Arnaldo Carvalho de Meloddc7b8e2007-03-15 21:42:27 -03003036 skb_put(skb, sizeof(struct ipv6hdr) + sizeof(struct udphdr));
David S. Millerfd2ea0a2008-07-17 01:56:23 -07003037 skb_set_queue_mapping(skb, queue_map);
John Fastabend9e50e3a2010-11-16 19:12:28 +00003038 skb->priority = pkt_dev->skb_priority;
Arnaldo Carvalho de Meloddc7b8e2007-03-15 21:42:27 -03003039 iph = ipv6_hdr(skb);
3040 udph = udp_hdr(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 memcpy(eth, pkt_dev->hh, 12);
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00003043 *(__be16 *) &eth[12] = protocol;
Robert Olsson64053be2005-06-26 15:27:10 -07003044
Steven Whitehouseca6549a2006-03-23 01:10:26 -08003045 /* Eth + IPh + UDPh + mpls */
3046 datalen = pkt_dev->cur_pkt_size - 14 -
3047 sizeof(struct ipv6hdr) - sizeof(struct udphdr) -
Jamal Hadi Salim16dab722007-07-02 22:39:50 -07003048 pkt_dev->pkt_overhead;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049
Luiz Capitulino222f1802006-03-20 22:16:13 -08003050 if (datalen < sizeof(struct pktgen_hdr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 datalen = sizeof(struct pktgen_hdr);
3052 if (net_ratelimit())
Joe Perchesf9467ea2010-06-21 12:29:14 +00003053 pr_info("increased datalen to %d\n", datalen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054 }
3055
3056 udph->source = htons(pkt_dev->cur_udp_src);
3057 udph->dest = htons(pkt_dev->cur_udp_dst);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003058 udph->len = htons(datalen + sizeof(struct udphdr));
3059 udph->check = 0; /* No checksum */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060
Stephen Hemmingerd5f1ce92007-03-04 16:08:08 -08003061 *(__be32 *) iph = htonl(0x60000000); /* Version + flow */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062
Francesco Fondelli1ca77682006-09-27 16:32:03 -07003063 if (pkt_dev->traffic_class) {
3064 /* Version + traffic class + flow (0) */
Al Viro252e33462006-11-14 20:48:11 -08003065 *(__be32 *)iph |= htonl(0x60000000 | (pkt_dev->traffic_class << 20));
Francesco Fondelli1ca77682006-09-27 16:32:03 -07003066 }
3067
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 iph->hop_limit = 32;
3069
3070 iph->payload_len = htons(sizeof(struct udphdr) + datalen);
3071 iph->nexthdr = IPPROTO_UDP;
3072
3073 ipv6_addr_copy(&iph->daddr, &pkt_dev->cur_in6_daddr);
3074 ipv6_addr_copy(&iph->saddr, &pkt_dev->cur_in6_saddr);
3075
Arnaldo Carvalho de Melob0e380b2007-04-10 21:21:55 -07003076 skb->mac_header = (skb->network_header - ETH_HLEN -
Jamal Hadi Salim16dab722007-07-02 22:39:50 -07003077 pkt_dev->pkt_overhead);
Steven Whitehouseca6549a2006-03-23 01:10:26 -08003078 skb->protocol = protocol;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 skb->dev = odev;
3080 skb->pkt_type = PACKET_HOST;
3081
Luiz Capitulino222f1802006-03-20 22:16:13 -08003082 if (pkt_dev->nfrags <= 0)
3083 pgh = (struct pktgen_hdr *)skb_put(skb, datalen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 else {
3085 int frags = pkt_dev->nfrags;
3086 int i;
3087
Luiz Capitulino222f1802006-03-20 22:16:13 -08003088 pgh = (struct pktgen_hdr *)(((char *)(udph)) + 8);
3089
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 if (frags > MAX_SKB_FRAGS)
3091 frags = MAX_SKB_FRAGS;
Luiz Capitulino222f1802006-03-20 22:16:13 -08003092 if (datalen > frags * PAGE_SIZE) {
3093 skb_put(skb, datalen - frags * PAGE_SIZE);
3094 datalen = frags * PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095 }
3096
3097 i = 0;
3098 while (datalen > 0) {
3099 struct page *page = alloc_pages(GFP_KERNEL, 0);
3100 skb_shinfo(skb)->frags[i].page = page;
3101 skb_shinfo(skb)->frags[i].page_offset = 0;
3102 skb_shinfo(skb)->frags[i].size =
Luiz Capitulino222f1802006-03-20 22:16:13 -08003103 (datalen < PAGE_SIZE ? datalen : PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104 datalen -= skb_shinfo(skb)->frags[i].size;
3105 skb->len += skb_shinfo(skb)->frags[i].size;
3106 skb->data_len += skb_shinfo(skb)->frags[i].size;
3107 i++;
3108 skb_shinfo(skb)->nr_frags = i;
3109 }
3110
3111 while (i < frags) {
3112 int rem;
3113
3114 if (i == 0)
3115 break;
3116
3117 rem = skb_shinfo(skb)->frags[i - 1].size / 2;
3118 if (rem == 0)
3119 break;
3120
3121 skb_shinfo(skb)->frags[i - 1].size -= rem;
3122
Luiz Capitulino222f1802006-03-20 22:16:13 -08003123 skb_shinfo(skb)->frags[i] =
3124 skb_shinfo(skb)->frags[i - 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125 get_page(skb_shinfo(skb)->frags[i].page);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003126 skb_shinfo(skb)->frags[i].page =
3127 skb_shinfo(skb)->frags[i - 1].page;
3128 skb_shinfo(skb)->frags[i].page_offset +=
3129 skb_shinfo(skb)->frags[i - 1].size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130 skb_shinfo(skb)->frags[i].size = rem;
3131 i++;
3132 skb_shinfo(skb)->nr_frags = i;
3133 }
3134 }
3135
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00003136 /* Stamp the time, and sequence number,
3137 * convert them to network byte order
3138 * should we update cloned packets too ?
3139 */
Luiz Capitulino222f1802006-03-20 22:16:13 -08003140 if (pgh) {
3141 struct timeval timestamp;
3142
3143 pgh->pgh_magic = htonl(PKTGEN_MAGIC);
3144 pgh->seq_num = htonl(pkt_dev->seq_num);
3145
3146 do_gettimeofday(&timestamp);
3147 pgh->tv_sec = htonl(timestamp.tv_sec);
3148 pgh->tv_usec = htonl(timestamp.tv_usec);
3149 }
Francesco Fondelli34954dd2006-09-27 16:30:44 -07003150 /* pkt_dev->seq_num++; FF: you really mean this? */
Luiz Capitulino222f1802006-03-20 22:16:13 -08003151
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 return skb;
3153}
3154
Stephen Hemminger475ac1e2009-08-27 13:55:08 +00003155static struct sk_buff *fill_packet(struct net_device *odev,
3156 struct pktgen_dev *pkt_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157{
Luiz Capitulino222f1802006-03-20 22:16:13 -08003158 if (pkt_dev->flags & F_IPV6)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159 return fill_packet_ipv6(odev, pkt_dev);
3160 else
3161 return fill_packet_ipv4(odev, pkt_dev);
3162}
3163
Luiz Capitulino222f1802006-03-20 22:16:13 -08003164static void pktgen_clear_counters(struct pktgen_dev *pkt_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165{
Luiz Capitulino222f1802006-03-20 22:16:13 -08003166 pkt_dev->seq_num = 1;
3167 pkt_dev->idle_acc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 pkt_dev->sofar = 0;
Luiz Capitulino222f1802006-03-20 22:16:13 -08003169 pkt_dev->tx_bytes = 0;
3170 pkt_dev->errors = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171}
3172
3173/* Set up structure for sending pkts, clear counters */
3174
3175static void pktgen_run(struct pktgen_thread *t)
3176{
Luiz Capitulinoc26a80162006-03-20 22:18:16 -08003177 struct pktgen_dev *pkt_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 int started = 0;
3179
Joe Perchesf9467ea2010-06-21 12:29:14 +00003180 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181
3182 if_lock(t);
Luiz Capitulinoc26a80162006-03-20 22:18:16 -08003183 list_for_each_entry(pkt_dev, &t->if_list, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184
3185 /*
3186 * setup odev and create initial packet.
3187 */
3188 pktgen_setup_inject(pkt_dev);
3189
Luiz Capitulino222f1802006-03-20 22:16:13 -08003190 if (pkt_dev->odev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 pktgen_clear_counters(pkt_dev);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003192 pkt_dev->running = 1; /* Cranke yeself! */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 pkt_dev->skb = NULL;
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00003194 pkt_dev->started_at =
3195 pkt_dev->next_tx = ktime_now();
3196
Jamal Hadi Salim16dab722007-07-02 22:39:50 -07003197 set_pkt_overhead(pkt_dev);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003198
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 strcpy(pkt_dev->result, "Starting");
3200 started++;
Luiz Capitulino222f1802006-03-20 22:16:13 -08003201 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 strcpy(pkt_dev->result, "Error starting");
3203 }
3204 if_unlock(t);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003205 if (started)
3206 t->control &= ~(T_STOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207}
3208
3209static void pktgen_stop_all_threads_ifs(void)
3210{
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003211 struct pktgen_thread *t;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212
Joe Perchesf9467ea2010-06-21 12:29:14 +00003213 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08003215 mutex_lock(&pktgen_thread_lock);
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003216
3217 list_for_each_entry(t, &pktgen_threads, th_list)
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003218 t->control |= T_STOP;
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003219
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08003220 mutex_unlock(&pktgen_thread_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221}
3222
Stephen Hemminger648fda72009-08-27 13:55:07 +00003223static int thread_is_running(const struct pktgen_thread *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224{
Stephen Hemminger648fda72009-08-27 13:55:07 +00003225 const struct pktgen_dev *pkt_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226
Luiz Capitulinoc26a80162006-03-20 22:18:16 -08003227 list_for_each_entry(pkt_dev, &t->if_list, list)
Stephen Hemminger648fda72009-08-27 13:55:07 +00003228 if (pkt_dev->running)
3229 return 1;
3230 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231}
3232
Luiz Capitulino222f1802006-03-20 22:16:13 -08003233static int pktgen_wait_thread_run(struct pktgen_thread *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234{
Luiz Capitulino222f1802006-03-20 22:16:13 -08003235 if_lock(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236
Luiz Capitulino222f1802006-03-20 22:16:13 -08003237 while (thread_is_running(t)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238
Luiz Capitulino222f1802006-03-20 22:16:13 -08003239 if_unlock(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240
Luiz Capitulino222f1802006-03-20 22:16:13 -08003241 msleep_interruptible(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242
Luiz Capitulino222f1802006-03-20 22:16:13 -08003243 if (signal_pending(current))
3244 goto signal;
3245 if_lock(t);
3246 }
3247 if_unlock(t);
3248 return 1;
3249signal:
3250 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251}
3252
3253static int pktgen_wait_all_threads_run(void)
3254{
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003255 struct pktgen_thread *t;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256 int sig = 1;
Luiz Capitulino222f1802006-03-20 22:16:13 -08003257
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08003258 mutex_lock(&pktgen_thread_lock);
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003259
3260 list_for_each_entry(t, &pktgen_threads, th_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 sig = pktgen_wait_thread_run(t);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003262 if (sig == 0)
3263 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 }
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003265
3266 if (sig == 0)
3267 list_for_each_entry(t, &pktgen_threads, th_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268 t->control |= (T_STOP);
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003269
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08003270 mutex_unlock(&pktgen_thread_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271 return sig;
3272}
3273
3274static void pktgen_run_all_threads(void)
3275{
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003276 struct pktgen_thread *t;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277
Joe Perchesf9467ea2010-06-21 12:29:14 +00003278 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08003280 mutex_lock(&pktgen_thread_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003282 list_for_each_entry(t, &pktgen_threads, th_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 t->control |= (T_RUN);
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003284
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08003285 mutex_unlock(&pktgen_thread_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00003287 /* Propagate thread->control */
3288 schedule_timeout_interruptible(msecs_to_jiffies(125));
Luiz Capitulino222f1802006-03-20 22:16:13 -08003289
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 pktgen_wait_all_threads_run();
3291}
3292
Jesse Brandeburgeb37b412008-11-10 16:48:03 -08003293static void pktgen_reset_all_threads(void)
3294{
3295 struct pktgen_thread *t;
3296
Joe Perchesf9467ea2010-06-21 12:29:14 +00003297 func_enter();
Jesse Brandeburgeb37b412008-11-10 16:48:03 -08003298
3299 mutex_lock(&pktgen_thread_lock);
3300
3301 list_for_each_entry(t, &pktgen_threads, th_list)
3302 t->control |= (T_REMDEVALL);
3303
3304 mutex_unlock(&pktgen_thread_lock);
3305
Stephen Hemminger63adc6f2009-08-27 13:55:19 +00003306 /* Propagate thread->control */
3307 schedule_timeout_interruptible(msecs_to_jiffies(125));
Jesse Brandeburgeb37b412008-11-10 16:48:03 -08003308
3309 pktgen_wait_all_threads_run();
3310}
3311
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312static void show_results(struct pktgen_dev *pkt_dev, int nr_frags)
3313{
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00003314 __u64 bps, mbps, pps;
Luiz Capitulino222f1802006-03-20 22:16:13 -08003315 char *p = pkt_dev->result;
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00003316 ktime_t elapsed = ktime_sub(pkt_dev->stopped_at,
3317 pkt_dev->started_at);
3318 ktime_t idle = ns_to_ktime(pkt_dev->idle_acc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00003320 p += sprintf(p, "OK: %llu(c%llu+d%llu) nsec, %llu (%dbyte,%dfrags)\n",
3321 (unsigned long long)ktime_to_us(elapsed),
3322 (unsigned long long)ktime_to_us(ktime_sub(elapsed, idle)),
3323 (unsigned long long)ktime_to_us(idle),
Luiz Capitulino222f1802006-03-20 22:16:13 -08003324 (unsigned long long)pkt_dev->sofar,
3325 pkt_dev->cur_pkt_size, nr_frags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00003327 pps = div64_u64(pkt_dev->sofar * NSEC_PER_SEC,
3328 ktime_to_ns(elapsed));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329
Luiz Capitulino222f1802006-03-20 22:16:13 -08003330 bps = pps * 8 * pkt_dev->cur_pkt_size;
3331
3332 mbps = bps;
3333 do_div(mbps, 1000000);
3334 p += sprintf(p, " %llupps %lluMb/sec (%llubps) errors: %llu",
3335 (unsigned long long)pps,
3336 (unsigned long long)mbps,
3337 (unsigned long long)bps,
3338 (unsigned long long)pkt_dev->errors);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340
3341/* Set stopped-at timer, remove from running list, do counters & statistics */
Luiz Capitulino222f1802006-03-20 22:16:13 -08003342static int pktgen_stop_device(struct pktgen_dev *pkt_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343{
Luiz Capitulino222f1802006-03-20 22:16:13 -08003344 int nr_frags = pkt_dev->skb ? skb_shinfo(pkt_dev->skb)->nr_frags : -1;
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003345
Luiz Capitulino222f1802006-03-20 22:16:13 -08003346 if (!pkt_dev->running) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00003347 pr_warning("interface: %s is already stopped\n",
3348 pkt_dev->odevname);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003349 return -EINVAL;
3350 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351
Stephen Hemminger3bda06a2009-08-27 13:55:10 +00003352 kfree_skb(pkt_dev->skb);
3353 pkt_dev->skb = NULL;
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00003354 pkt_dev->stopped_at = ktime_now();
Luiz Capitulino222f1802006-03-20 22:16:13 -08003355 pkt_dev->running = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003357 show_results(pkt_dev, nr_frags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358
Luiz Capitulino222f1802006-03-20 22:16:13 -08003359 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360}
3361
Luiz Capitulino222f1802006-03-20 22:16:13 -08003362static struct pktgen_dev *next_to_run(struct pktgen_thread *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363{
Luiz Capitulinoc26a80162006-03-20 22:18:16 -08003364 struct pktgen_dev *pkt_dev, *best = NULL;
Luiz Capitulino222f1802006-03-20 22:16:13 -08003365
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 if_lock(t);
3367
Luiz Capitulinoc26a80162006-03-20 22:18:16 -08003368 list_for_each_entry(pkt_dev, &t->if_list, list) {
3369 if (!pkt_dev->running)
Luiz Capitulino222f1802006-03-20 22:16:13 -08003370 continue;
3371 if (best == NULL)
Luiz Capitulinoc26a80162006-03-20 22:18:16 -08003372 best = pkt_dev;
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00003373 else if (ktime_lt(pkt_dev->next_tx, best->next_tx))
Luiz Capitulinoc26a80162006-03-20 22:18:16 -08003374 best = pkt_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375 }
3376 if_unlock(t);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003377 return best;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378}
3379
Luiz Capitulino222f1802006-03-20 22:16:13 -08003380static void pktgen_stop(struct pktgen_thread *t)
3381{
Luiz Capitulinoc26a80162006-03-20 22:18:16 -08003382 struct pktgen_dev *pkt_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383
Joe Perchesf9467ea2010-06-21 12:29:14 +00003384 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385
Luiz Capitulino222f1802006-03-20 22:16:13 -08003386 if_lock(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387
Luiz Capitulinoc26a80162006-03-20 22:18:16 -08003388 list_for_each_entry(pkt_dev, &t->if_list, list) {
3389 pktgen_stop_device(pkt_dev);
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003390 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391
Luiz Capitulino222f1802006-03-20 22:16:13 -08003392 if_unlock(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393}
3394
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003395/*
3396 * one of our devices needs to be removed - find it
3397 * and remove it
3398 */
3399static void pktgen_rem_one_if(struct pktgen_thread *t)
3400{
Luiz Capitulinoc26a80162006-03-20 22:18:16 -08003401 struct list_head *q, *n;
3402 struct pktgen_dev *cur;
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003403
Joe Perchesf9467ea2010-06-21 12:29:14 +00003404 func_enter();
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003405
3406 if_lock(t);
3407
Luiz Capitulinoc26a80162006-03-20 22:18:16 -08003408 list_for_each_safe(q, n, &t->if_list) {
3409 cur = list_entry(q, struct pktgen_dev, list);
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003410
Luiz Capitulino222f1802006-03-20 22:16:13 -08003411 if (!cur->removal_mark)
3412 continue;
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003413
Wei Yongjun86dc1ad2009-02-25 00:31:54 +00003414 kfree_skb(cur->skb);
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003415 cur->skb = NULL;
3416
3417 pktgen_remove_device(t, cur);
3418
3419 break;
3420 }
3421
3422 if_unlock(t);
3423}
3424
Luiz Capitulino222f1802006-03-20 22:16:13 -08003425static void pktgen_rem_all_ifs(struct pktgen_thread *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426{
Luiz Capitulinoc26a80162006-03-20 22:18:16 -08003427 struct list_head *q, *n;
3428 struct pktgen_dev *cur;
Luiz Capitulino222f1802006-03-20 22:16:13 -08003429
Joe Perchesf9467ea2010-06-21 12:29:14 +00003430 func_enter();
3431
Luiz Capitulino222f1802006-03-20 22:16:13 -08003432 /* Remove all devices, free mem */
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003433
Luiz Capitulino222f1802006-03-20 22:16:13 -08003434 if_lock(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435
Luiz Capitulinoc26a80162006-03-20 22:18:16 -08003436 list_for_each_safe(q, n, &t->if_list) {
3437 cur = list_entry(q, struct pktgen_dev, list);
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003438
Wei Yongjun86dc1ad2009-02-25 00:31:54 +00003439 kfree_skb(cur->skb);
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003440 cur->skb = NULL;
3441
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442 pktgen_remove_device(t, cur);
3443 }
3444
Luiz Capitulino222f1802006-03-20 22:16:13 -08003445 if_unlock(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446}
3447
Luiz Capitulino222f1802006-03-20 22:16:13 -08003448static void pktgen_rem_thread(struct pktgen_thread *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449{
Luiz Capitulino222f1802006-03-20 22:16:13 -08003450 /* Remove from the thread list */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451
David S. Milleree74baa2007-01-01 20:51:53 -08003452 remove_proc_entry(t->tsk->comm, pg_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08003454 mutex_lock(&pktgen_thread_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003456 list_del(&t->th_list);
3457
Luiz Capitulino6146e6a2006-03-20 22:24:45 -08003458 mutex_unlock(&pktgen_thread_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459}
3460
Stephen Hemmingeref879792009-09-22 19:41:43 +00003461static void pktgen_resched(struct pktgen_dev *pkt_dev)
Stephen Hemminger3791dec2009-08-27 13:55:11 +00003462{
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00003463 ktime_t idle_start = ktime_now();
Stephen Hemmingeref879792009-09-22 19:41:43 +00003464 schedule();
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00003465 pkt_dev->idle_acc += ktime_to_ns(ktime_sub(ktime_now(), idle_start));
Stephen Hemminger3791dec2009-08-27 13:55:11 +00003466}
3467
Stephen Hemmingeref879792009-09-22 19:41:43 +00003468static void pktgen_wait_for_skb(struct pktgen_dev *pkt_dev)
3469{
3470 ktime_t idle_start = ktime_now();
3471
3472 while (atomic_read(&(pkt_dev->skb->users)) != 1) {
3473 if (signal_pending(current))
3474 break;
3475
3476 if (need_resched())
3477 pktgen_resched(pkt_dev);
3478 else
3479 cpu_relax();
3480 }
3481 pkt_dev->idle_acc += ktime_to_ns(ktime_sub(ktime_now(), idle_start));
3482}
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00003483
Stephen Hemminger475ac1e2009-08-27 13:55:08 +00003484static void pktgen_xmit(struct pktgen_dev *pkt_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485{
Stephen Hemminger00829822008-11-20 20:14:53 -08003486 struct net_device *odev = pkt_dev->odev;
Stephen Hemminger6fef4c02009-08-31 19:50:41 +00003487 netdev_tx_t (*xmit)(struct sk_buff *, struct net_device *)
Stephen Hemminger00829822008-11-20 20:14:53 -08003488 = odev->netdev_ops->ndo_start_xmit;
David S. Millerfd2ea0a2008-07-17 01:56:23 -07003489 struct netdev_queue *txq;
David S. Millerfd2ea0a2008-07-17 01:56:23 -07003490 u16 queue_map;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003491 int ret;
3492
Stephen Hemmingeref879792009-09-22 19:41:43 +00003493 /* If device is offline, then don't send */
3494 if (unlikely(!netif_running(odev) || !netif_carrier_ok(odev))) {
3495 pktgen_stop_device(pkt_dev);
Stephen Hemminger3791dec2009-08-27 13:55:11 +00003496 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08003498
Stephen Hemmingeref879792009-09-22 19:41:43 +00003499 /* This is max DELAY, this has special meaning of
3500 * "never transmit"
3501 */
3502 if (unlikely(pkt_dev->delay == ULLONG_MAX)) {
3503 pkt_dev->next_tx = ktime_add_ns(ktime_now(), ULONG_MAX);
3504 return;
3505 }
3506
3507 /* If no skb or clone count exhausted then get new one */
Stephen Hemminger7d7bb1c2009-08-27 13:55:12 +00003508 if (!pkt_dev->skb || (pkt_dev->last_ok &&
3509 ++pkt_dev->clone_count >= pkt_dev->clone_skb)) {
3510 /* build a new pkt */
3511 kfree_skb(pkt_dev->skb);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003512
Stephen Hemminger7d7bb1c2009-08-27 13:55:12 +00003513 pkt_dev->skb = fill_packet(odev, pkt_dev);
3514 if (pkt_dev->skb == NULL) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00003515 pr_err("ERROR: couldn't allocate skb in fill_packet\n");
Stephen Hemminger7d7bb1c2009-08-27 13:55:12 +00003516 schedule();
3517 pkt_dev->clone_count--; /* back out increment, OOM */
3518 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519 }
Eric Dumazetbaac8562009-11-05 21:04:32 -08003520 pkt_dev->last_pkt_size = pkt_dev->skb->len;
Stephen Hemminger7d7bb1c2009-08-27 13:55:12 +00003521 pkt_dev->allocated_skbs++;
3522 pkt_dev->clone_count = 0; /* reset counter */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523 }
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003524
Stephen Hemmingeref879792009-09-22 19:41:43 +00003525 if (pkt_dev->delay && pkt_dev->last_ok)
3526 spin(pkt_dev, pkt_dev->next_tx);
3527
David S. Millerfd2ea0a2008-07-17 01:56:23 -07003528 queue_map = skb_get_queue_mapping(pkt_dev->skb);
3529 txq = netdev_get_tx_queue(odev, queue_map);
3530
3531 __netif_tx_lock_bh(txq);
Stephen Hemmingeref879792009-09-22 19:41:43 +00003532
Eric Dumazet0835acf2009-09-30 13:03:33 +00003533 if (unlikely(netif_tx_queue_stopped(txq) || netif_tx_queue_frozen(txq))) {
Stephen Hemmingeref879792009-09-22 19:41:43 +00003534 ret = NETDEV_TX_BUSY;
Eric Dumazet0835acf2009-09-30 13:03:33 +00003535 pkt_dev->last_ok = 0;
3536 goto unlock;
3537 }
3538 atomic_inc(&(pkt_dev->skb->users));
3539 ret = (*xmit)(pkt_dev->skb, odev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540
Stephen Hemmingeref879792009-09-22 19:41:43 +00003541 switch (ret) {
3542 case NETDEV_TX_OK:
3543 txq_trans_update(txq);
3544 pkt_dev->last_ok = 1;
3545 pkt_dev->sofar++;
3546 pkt_dev->seq_num++;
Eric Dumazetbaac8562009-11-05 21:04:32 -08003547 pkt_dev->tx_bytes += pkt_dev->last_pkt_size;
Stephen Hemmingeref879792009-09-22 19:41:43 +00003548 break;
John Fastabendf466dba2009-12-23 22:02:57 -08003549 case NET_XMIT_DROP:
3550 case NET_XMIT_CN:
3551 case NET_XMIT_POLICED:
3552 /* skb has been consumed */
3553 pkt_dev->errors++;
3554 break;
Stephen Hemmingeref879792009-09-22 19:41:43 +00003555 default: /* Drivers are not supposed to return other values! */
3556 if (net_ratelimit())
3557 pr_info("pktgen: %s xmit error: %d\n",
Eric Dumazet593f63b2009-11-23 01:44:37 +00003558 pkt_dev->odevname, ret);
Stephen Hemmingeref879792009-09-22 19:41:43 +00003559 pkt_dev->errors++;
3560 /* fallthru */
3561 case NETDEV_TX_LOCKED:
3562 case NETDEV_TX_BUSY:
3563 /* Retry it next time */
3564 atomic_dec(&(pkt_dev->skb->users));
3565 pkt_dev->last_ok = 0;
Luiz Capitulino222f1802006-03-20 22:16:13 -08003566 }
Eric Dumazet0835acf2009-09-30 13:03:33 +00003567unlock:
David S. Millerfd2ea0a2008-07-17 01:56:23 -07003568 __netif_tx_unlock_bh(txq);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003569
Linus Torvalds1da177e2005-04-16 15:20:36 -07003570 /* If pkt_dev->count is zero, then run forever */
3571 if ((pkt_dev->count != 0) && (pkt_dev->sofar >= pkt_dev->count)) {
Stephen Hemmingeref879792009-09-22 19:41:43 +00003572 pktgen_wait_for_skb(pkt_dev);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003573
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574 /* Done with this */
3575 pktgen_stop_device(pkt_dev);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003576 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08003577}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09003579/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003580 * Main loop of the thread goes here
3581 */
3582
David S. Milleree74baa2007-01-01 20:51:53 -08003583static int pktgen_thread_worker(void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584{
3585 DEFINE_WAIT(wait);
David S. Milleree74baa2007-01-01 20:51:53 -08003586 struct pktgen_thread *t = arg;
Luiz Capitulino222f1802006-03-20 22:16:13 -08003587 struct pktgen_dev *pkt_dev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588 int cpu = t->cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003589
David S. Milleree74baa2007-01-01 20:51:53 -08003590 BUG_ON(smp_processor_id() != cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003591
3592 init_waitqueue_head(&t->queue);
Denis V. Lunevd3ede322008-05-20 15:12:44 -07003593 complete(&t->start_done);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003594
Joe Perchesf9467ea2010-06-21 12:29:14 +00003595 pr_debug("starting pktgen/%d: pid=%d\n", cpu, task_pid_nr(current));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003596
David S. Milleree74baa2007-01-01 20:51:53 -08003597 set_current_state(TASK_INTERRUPTIBLE);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003598
Rafael J. Wysocki83144182007-07-17 04:03:35 -07003599 set_freezable();
3600
David S. Milleree74baa2007-01-01 20:51:53 -08003601 while (!kthread_should_stop()) {
3602 pkt_dev = next_to_run(t);
3603
Stephen Hemmingeref879792009-09-22 19:41:43 +00003604 if (unlikely(!pkt_dev && t->control == 0)) {
3605 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
David S. Milleree74baa2007-01-01 20:51:53 -08003657 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658}
3659
Luiz Capitulino222f1802006-03-20 22:16:13 -08003660static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t,
Eric Dumazet3e984842009-11-24 14:50:53 -08003661 const char *ifname, bool exact)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662{
Luiz Capitulinoc26a80162006-03-20 22:18:16 -08003663 struct pktgen_dev *p, *pkt_dev = NULL;
Eric Dumazet3e984842009-11-24 14:50:53 -08003664 size_t len = strlen(ifname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003665
Eric Dumazet3e984842009-11-24 14:50:53 -08003666 if_lock(t);
Luiz Capitulinoc26a80162006-03-20 22:18:16 -08003667 list_for_each_entry(p, &t->if_list, list)
Eric Dumazet3e984842009-11-24 14:50:53 -08003668 if (strncmp(p->odevname, ifname, len) == 0) {
3669 if (p->odevname[len]) {
3670 if (exact || p->odevname[len] != '@')
3671 continue;
3672 }
Luiz Capitulinoc26a80162006-03-20 22:18:16 -08003673 pkt_dev = p;
Luiz Capitulino222f1802006-03-20 22:16:13 -08003674 break;
3675 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676
Luiz Capitulino222f1802006-03-20 22:16:13 -08003677 if_unlock(t);
Joe Perchesf9467ea2010-06-21 12:29:14 +00003678 pr_debug("find_dev(%s) returning %p\n", ifname, pkt_dev);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003679 return pkt_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003680}
3681
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09003682/*
3683 * Adds a dev at front of if_list.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003684 */
3685
Luiz Capitulino222f1802006-03-20 22:16:13 -08003686static int add_dev_to_thread(struct pktgen_thread *t,
3687 struct pktgen_dev *pkt_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688{
3689 int rv = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003690
Luiz Capitulino222f1802006-03-20 22:16:13 -08003691 if_lock(t);
3692
3693 if (pkt_dev->pg_thread) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00003694 pr_err("ERROR: already assigned to a thread\n");
Luiz Capitulino222f1802006-03-20 22:16:13 -08003695 rv = -EBUSY;
3696 goto out;
3697 }
Luiz Capitulinoc26a80162006-03-20 22:18:16 -08003698
3699 list_add(&pkt_dev->list, &t->if_list);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003700 pkt_dev->pg_thread = t;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701 pkt_dev->running = 0;
3702
Luiz Capitulino222f1802006-03-20 22:16:13 -08003703out:
3704 if_unlock(t);
3705 return rv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003706}
3707
3708/* Called under thread lock */
3709
Luiz Capitulino222f1802006-03-20 22:16:13 -08003710static int pktgen_add_device(struct pktgen_thread *t, const char *ifname)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711{
Luiz Capitulino222f1802006-03-20 22:16:13 -08003712 struct pktgen_dev *pkt_dev;
Stephen Hemminger39df2322007-03-04 16:11:51 -08003713 int err;
Eric Dumazet3291b9d2009-11-29 00:44:33 -08003714 int node = cpu_to_node(t->cpu);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003715
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 /* We don't allow a device to be on several threads */
3717
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003718 pkt_dev = __pktgen_NN_threads(ifname, FIND);
3719 if (pkt_dev) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00003720 pr_err("ERROR: interface already used\n");
Luiz Capitulino222f1802006-03-20 22:16:13 -08003721 return -EBUSY;
3722 }
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003723
Eric Dumazet3291b9d2009-11-29 00:44:33 -08003724 pkt_dev = kzalloc_node(sizeof(struct pktgen_dev), GFP_KERNEL, node);
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003725 if (!pkt_dev)
3726 return -ENOMEM;
3727
Eric Dumazet593f63b2009-11-23 01:44:37 +00003728 strcpy(pkt_dev->odevname, ifname);
Eric Dumazet3291b9d2009-11-29 00:44:33 -08003729 pkt_dev->flows = vmalloc_node(MAX_CFLOWS * sizeof(struct flow_state),
3730 node);
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003731 if (pkt_dev->flows == NULL) {
3732 kfree(pkt_dev);
3733 return -ENOMEM;
3734 }
Luiz Capitulino222f1802006-03-20 22:16:13 -08003735 memset(pkt_dev->flows, 0, MAX_CFLOWS * sizeof(struct flow_state));
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003736
Arthur Kepner95ed63f2006-03-20 21:26:56 -08003737 pkt_dev->removal_mark = 0;
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003738 pkt_dev->min_pkt_size = ETH_ZLEN;
3739 pkt_dev->max_pkt_size = ETH_ZLEN;
3740 pkt_dev->nfrags = 0;
3741 pkt_dev->clone_skb = pg_clone_skb_d;
Stephen Hemmingerfd29cf72009-08-27 13:55:16 +00003742 pkt_dev->delay = pg_delay_d;
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003743 pkt_dev->count = pg_count_d;
3744 pkt_dev->sofar = 0;
Luiz Capitulino222f1802006-03-20 22:16:13 -08003745 pkt_dev->udp_src_min = 9; /* sink port */
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003746 pkt_dev->udp_src_max = 9;
3747 pkt_dev->udp_dst_min = 9;
3748 pkt_dev->udp_dst_max = 9;
3749
Francesco Fondelli34954dd2006-09-27 16:30:44 -07003750 pkt_dev->vlan_p = 0;
3751 pkt_dev->vlan_cfi = 0;
3752 pkt_dev->vlan_id = 0xffff;
3753 pkt_dev->svlan_p = 0;
3754 pkt_dev->svlan_cfi = 0;
3755 pkt_dev->svlan_id = 0xffff;
Robert Olssone99b99b2010-03-18 22:44:30 +00003756 pkt_dev->node = -1;
Francesco Fondelli34954dd2006-09-27 16:30:44 -07003757
Stephen Hemminger39df2322007-03-04 16:11:51 -08003758 err = pktgen_setup_dev(pkt_dev, ifname);
3759 if (err)
3760 goto out1;
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003761
Denis V. Lunev5efdccb2008-05-02 02:46:22 -07003762 pkt_dev->entry = proc_create_data(ifname, 0600, pg_proc_dir,
3763 &pktgen_if_fops, pkt_dev);
Stephen Hemminger39df2322007-03-04 16:11:51 -08003764 if (!pkt_dev->entry) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00003765 pr_err("cannot create %s/%s procfs entry\n",
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003766 PG_PROC_DIR, ifname);
Stephen Hemminger39df2322007-03-04 16:11:51 -08003767 err = -EINVAL;
3768 goto out2;
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003769 }
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07003770#ifdef CONFIG_XFRM
3771 pkt_dev->ipsmode = XFRM_MODE_TRANSPORT;
3772 pkt_dev->ipsproto = IPPROTO_ESP;
3773#endif
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003774
3775 return add_dev_to_thread(t, pkt_dev);
Stephen Hemminger39df2322007-03-04 16:11:51 -08003776out2:
3777 dev_put(pkt_dev->odev);
3778out1:
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07003779#ifdef CONFIG_XFRM
3780 free_SAs(pkt_dev);
3781#endif
Figo.zhang1d0ebfe2009-06-08 00:40:35 -07003782 vfree(pkt_dev->flows);
Stephen Hemminger39df2322007-03-04 16:11:51 -08003783 kfree(pkt_dev);
3784 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785}
3786
David S. Milleree74baa2007-01-01 20:51:53 -08003787static int __init pktgen_create_thread(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788{
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003789 struct pktgen_thread *t;
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003790 struct proc_dir_entry *pe;
David S. Milleree74baa2007-01-01 20:51:53 -08003791 struct task_struct *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792
Eric Dumazet3291b9d2009-11-29 00:44:33 -08003793 t = kzalloc_node(sizeof(struct pktgen_thread), GFP_KERNEL,
3794 cpu_to_node(cpu));
Luiz Capitulino222f1802006-03-20 22:16:13 -08003795 if (!t) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00003796 pr_err("ERROR: out of memory, can't create new thread\n");
Luiz Capitulino222f1802006-03-20 22:16:13 -08003797 return -ENOMEM;
3798 }
3799
Luiz Capitulino222f1802006-03-20 22:16:13 -08003800 spin_lock_init(&t->if_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801 t->cpu = cpu;
Luiz Capitulino222f1802006-03-20 22:16:13 -08003802
David S. Milleree74baa2007-01-01 20:51:53 -08003803 INIT_LIST_HEAD(&t->if_list);
3804
3805 list_add_tail(&t->th_list, &pktgen_threads);
Denis V. Lunevd3ede322008-05-20 15:12:44 -07003806 init_completion(&t->start_done);
David S. Milleree74baa2007-01-01 20:51:53 -08003807
3808 p = kthread_create(pktgen_thread_worker, t, "kpktgend_%d", cpu);
3809 if (IS_ERR(p)) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00003810 pr_err("kernel_thread() failed for cpu %d\n", t->cpu);
David S. Milleree74baa2007-01-01 20:51:53 -08003811 list_del(&t->th_list);
3812 kfree(t);
3813 return PTR_ERR(p);
3814 }
3815 kthread_bind(p, cpu);
3816 t->tsk = p;
3817
Denis V. Lunev5efdccb2008-05-02 02:46:22 -07003818 pe = proc_create_data(t->tsk->comm, 0600, pg_proc_dir,
3819 &pktgen_thread_fops, t);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003820 if (!pe) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00003821 pr_err("cannot create %s/%s procfs entry\n",
David S. Milleree74baa2007-01-01 20:51:53 -08003822 PG_PROC_DIR, t->tsk->comm);
3823 kthread_stop(p);
3824 list_del(&t->th_list);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003825 kfree(t);
3826 return -EINVAL;
3827 }
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003828
David S. Milleree74baa2007-01-01 20:51:53 -08003829 wake_up_process(p);
Denis V. Lunevd3ede322008-05-20 15:12:44 -07003830 wait_for_completion(&t->start_done);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831
3832 return 0;
3833}
3834
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09003835/*
3836 * Removes a device from the thread if_list.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837 */
Luiz Capitulino222f1802006-03-20 22:16:13 -08003838static void _rem_dev_from_if_list(struct pktgen_thread *t,
3839 struct pktgen_dev *pkt_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840{
Luiz Capitulinoc26a80162006-03-20 22:18:16 -08003841 struct list_head *q, *n;
3842 struct pktgen_dev *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843
Luiz Capitulinoc26a80162006-03-20 22:18:16 -08003844 list_for_each_safe(q, n, &t->if_list) {
3845 p = list_entry(q, struct pktgen_dev, list);
3846 if (p == pkt_dev)
3847 list_del(&p->list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848 }
3849}
3850
Luiz Capitulino222f1802006-03-20 22:16:13 -08003851static int pktgen_remove_device(struct pktgen_thread *t,
3852 struct pktgen_dev *pkt_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853{
3854
Joe Perchesf9467ea2010-06-21 12:29:14 +00003855 pr_debug("remove_device pkt_dev=%p\n", pkt_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856
Luiz Capitulino222f1802006-03-20 22:16:13 -08003857 if (pkt_dev->running) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00003858 pr_warning("WARNING: trying to remove a running interface, stopping it now\n");
Luiz Capitulino222f1802006-03-20 22:16:13 -08003859 pktgen_stop_device(pkt_dev);
3860 }
3861
3862 /* Dis-associate from the interface */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863
3864 if (pkt_dev->odev) {
3865 dev_put(pkt_dev->odev);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003866 pkt_dev->odev = NULL;
3867 }
3868
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869 /* And update the thread if_list */
3870
3871 _rem_dev_from_if_list(t, pkt_dev);
3872
Stephen Hemminger39df2322007-03-04 16:11:51 -08003873 if (pkt_dev->entry)
3874 remove_proc_entry(pkt_dev->entry->name, pg_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003875
Jamal Hadi Salima553e4a2007-07-02 22:41:59 -07003876#ifdef CONFIG_XFRM
3877 free_SAs(pkt_dev);
3878#endif
Figo.zhang1d0ebfe2009-06-08 00:40:35 -07003879 vfree(pkt_dev->flows);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880 kfree(pkt_dev);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003881 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882}
3883
Luiz Capitulino222f1802006-03-20 22:16:13 -08003884static int __init pg_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885{
3886 int cpu;
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003887 struct proc_dir_entry *pe;
3888
Joe Perchesf9467ea2010-06-21 12:29:14 +00003889 pr_info("%s", version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890
Eric W. Biederman457c4cb2007-09-12 12:01:34 +02003891 pg_proc_dir = proc_mkdir(PG_PROC_DIR, init_net.proc_net);
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003892 if (!pg_proc_dir)
3893 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894
Wang Chen25296d52008-02-28 14:11:49 -08003895 pe = proc_create(PGCTRL, 0600, pg_proc_dir, &pktgen_fops);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003896 if (pe == NULL) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00003897 pr_err("ERROR: cannot create %s procfs entry\n", PGCTRL);
Eric W. Biederman457c4cb2007-09-12 12:01:34 +02003898 proc_net_remove(&init_net, PG_PROC_DIR);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003899 return -EINVAL;
3900 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003901
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902 /* Register us to receive netdevice events */
3903 register_netdevice_notifier(&pktgen_notifier_block);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003904
John Hawkes670c02c2005-10-13 09:30:31 -07003905 for_each_online_cpu(cpu) {
Luiz Capitulino8024bb22006-03-20 22:17:55 -08003906 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907
David S. Milleree74baa2007-01-01 20:51:53 -08003908 err = pktgen_create_thread(cpu);
Luiz Capitulino8024bb22006-03-20 22:17:55 -08003909 if (err)
Joe Perchesf9467ea2010-06-21 12:29:14 +00003910 pr_warning("WARNING: Cannot create thread for cpu %d (%d)\n",
3911 cpu, err);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003912 }
Luiz Capitulino8024bb22006-03-20 22:17:55 -08003913
3914 if (list_empty(&pktgen_threads)) {
Joe Perchesf9467ea2010-06-21 12:29:14 +00003915 pr_err("ERROR: Initialization failed for all threads\n");
Luiz Capitulino8024bb22006-03-20 22:17:55 -08003916 unregister_netdevice_notifier(&pktgen_notifier_block);
3917 remove_proc_entry(PGCTRL, pg_proc_dir);
Eric W. Biederman457c4cb2007-09-12 12:01:34 +02003918 proc_net_remove(&init_net, PG_PROC_DIR);
Luiz Capitulino8024bb22006-03-20 22:17:55 -08003919 return -ENODEV;
3920 }
3921
Luiz Capitulino222f1802006-03-20 22:16:13 -08003922 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923}
3924
3925static void __exit pg_cleanup(void)
3926{
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003927 struct pktgen_thread *t;
3928 struct list_head *q, *n;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929
Luiz Capitulino222f1802006-03-20 22:16:13 -08003930 /* Stop all interfaces & threads */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931
Luiz Capitulinocdcdbe02006-03-20 22:16:40 -08003932 list_for_each_safe(q, n, &pktgen_threads) {
3933 t = list_entry(q, struct pktgen_thread, th_list);
David S. Milleree74baa2007-01-01 20:51:53 -08003934 kthread_stop(t->tsk);
3935 kfree(t);
Luiz Capitulino222f1802006-03-20 22:16:13 -08003936 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937
Luiz Capitulino222f1802006-03-20 22:16:13 -08003938 /* Un-register us from receiving netdevice events */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939 unregister_netdevice_notifier(&pktgen_notifier_block);
3940
Luiz Capitulino222f1802006-03-20 22:16:13 -08003941 /* Clean up proc file system */
Stephen Hemmingerd50a6b562005-10-14 15:42:33 -07003942 remove_proc_entry(PGCTRL, pg_proc_dir);
Eric W. Biederman457c4cb2007-09-12 12:01:34 +02003943 proc_net_remove(&init_net, PG_PROC_DIR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944}
3945
Linus Torvalds1da177e2005-04-16 15:20:36 -07003946module_init(pg_init);
3947module_exit(pg_cleanup);
3948
Stephen Hemmingerc3d2f522009-08-27 13:55:20 +00003949MODULE_AUTHOR("Robert Olsson <robert.olsson@its.uu.se>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003950MODULE_DESCRIPTION("Packet Generator tool");
3951MODULE_LICENSE("GPL");
Stephen Hemmingerc3d2f522009-08-27 13:55:20 +00003952MODULE_VERSION(VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953module_param(pg_count_d, int, 0);
Stephen Hemmingerc3d2f522009-08-27 13:55:20 +00003954MODULE_PARM_DESC(pg_count_d, "Default number of packets to inject");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003955module_param(pg_delay_d, int, 0);
Stephen Hemmingerc3d2f522009-08-27 13:55:20 +00003956MODULE_PARM_DESC(pg_delay_d, "Default delay between packets (nanoseconds)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003957module_param(pg_clone_skb_d, int, 0);
Stephen Hemmingerc3d2f522009-08-27 13:55:20 +00003958MODULE_PARM_DESC(pg_clone_skb_d, "Default number of copies of the same packet");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003959module_param(debug, int, 0);
Stephen Hemmingerc3d2f522009-08-27 13:55:20 +00003960MODULE_PARM_DESC(debug, "Enable debugging of pktgen module");