Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 9 | * Jens Låås <jens.laas@data.slu.se> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * |
| 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 Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 18 | * The tool is implemented as a linux module. Parameters are output |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | * device, delay (to hard_xmit), number of packets, and whether |
| 20 | * to use multiple SKBs or just the same one. |
| 21 | * pktgen uses the installed interface's output routine. |
| 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 Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 47 | * Renamed multiskb to clone_skb and cleaned up sending core for two distinct |
| 48 | * skb modes. A clone_skb=0 mode for Ben "ranges" work and a clone_skb != 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | * as a "fastpath" with a configurable number of clones after alloc's. |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 50 | * clone_skb=0 means all packets are allocated this also means ranges time |
| 51 | * stamps etc can be used. clone_skb=100 means 1 malloc is followed by 100 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | * clones. |
| 53 | * |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 54 | * Also moved to /proc/net/pktgen/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | * --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 Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 63 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | * 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 Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 68 | * For each CPU one thread/process is created at start. This process checks |
| 69 | * for running devices in the if_list and sends packets until count is 0 it |
| 70 | * also the thread checks the thread->control which is used for inter-process |
| 71 | * communication. controlling process "posts" operations to the threads this |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | * way. The if_lock should be possible to remove when add/rem_device is merged |
| 73 | * into this too. |
| 74 | * |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 75 | * By design there should only be *one* "controlling" process. In practice |
| 76 | * multiple write accesses gives unpredictable result. Understood by "write" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | * to /proc gives result code thats should be read be the "writer". |
Stephen Hemminger | b4099fa | 2005-10-14 15:32:22 -0700 | [diff] [blame] | 78 | * For practical use this should be no problem. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | * |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 80 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | * --ro |
| 83 | * |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 84 | * Fix refcount off by one if first packet fails, potential null deref, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | * 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 Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 92 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | * Remove if fix from added Harald Welte <laforge@netfilter.org> 040419 |
| 94 | * ia64 compilation fix from Aron Griffis <aron@hp.com> 040604 |
| 95 | * |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 96 | * New xmit() return, do_div and misc clean up by Stephen Hemminger |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | * <shemminger@osdl.org> 040923 |
| 98 | * |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 99 | * Randy Dunlap fixed u64 printk compiler waring |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | * |
| 101 | * Remove FCS from BW calculation. Lennert Buytenhek <buytenh@wantstofly.org> |
| 102 | * New time handling. Lennert Buytenhek <buytenh@wantstofly.org> 041213 |
| 103 | * |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 104 | * Corrections from Nikolai Malykh (nmalykh@bilim.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | * Removed unused flags F_SET_SRCMAC & F_SET_SRCIP 041230 |
| 106 | * |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 107 | * interruptible_sleep_on_timeout() replaced Nishanth Aravamudan <nacc@us.ibm.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | * 050103 |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 109 | * |
| 110 | * MPLS support by Steven Whitehouse <steve@chygwyn.com> |
| 111 | * |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 112 | * 802.1Q/Q-in-Q support by Francesco Fondelli (FF) <francesco.fondelli@gmail.com> |
| 113 | * |
Adit Ranadive | ce5d0b4 | 2007-09-16 14:52:15 -0700 | [diff] [blame] | 114 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | */ |
| 118 | #include <linux/sys.h> |
| 119 | #include <linux/types.h> |
| 120 | #include <linux/module.h> |
| 121 | #include <linux/moduleparam.h> |
| 122 | #include <linux/kernel.h> |
Luiz Capitulino | 222fa07 | 2006-03-20 22:24:27 -0800 | [diff] [blame] | 123 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | #include <linux/sched.h> |
| 125 | #include <linux/slab.h> |
| 126 | #include <linux/vmalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | #include <linux/unistd.h> |
| 128 | #include <linux/string.h> |
| 129 | #include <linux/ptrace.h> |
| 130 | #include <linux/errno.h> |
| 131 | #include <linux/ioport.h> |
| 132 | #include <linux/interrupt.h> |
Randy Dunlap | 4fc268d | 2006-01-11 12:17:47 -0800 | [diff] [blame] | 133 | #include <linux/capability.h> |
Stephen Hemminger | 2bc481c | 2009-08-28 23:41:29 -0700 | [diff] [blame] | 134 | #include <linux/hrtimer.h> |
Andrew Morton | 09fe3ef | 2007-04-12 14:45:32 -0700 | [diff] [blame] | 135 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | #include <linux/delay.h> |
| 137 | #include <linux/timer.h> |
Luiz Capitulino | cdcdbe0 | 2006-03-20 22:16:40 -0800 | [diff] [blame] | 138 | #include <linux/list.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | #include <linux/init.h> |
| 140 | #include <linux/skbuff.h> |
| 141 | #include <linux/netdevice.h> |
| 142 | #include <linux/inet.h> |
| 143 | #include <linux/inetdevice.h> |
| 144 | #include <linux/rtnetlink.h> |
| 145 | #include <linux/if_arp.h> |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 146 | #include <linux/if_vlan.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | #include <linux/in.h> |
| 148 | #include <linux/ip.h> |
| 149 | #include <linux/ipv6.h> |
| 150 | #include <linux/udp.h> |
| 151 | #include <linux/proc_fs.h> |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 152 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | #include <linux/wait.h> |
Kris Katterjohn | f404e9a | 2006-01-17 13:04:57 -0800 | [diff] [blame] | 154 | #include <linux/etherdevice.h> |
David S. Miller | ee74baa | 2007-01-01 20:51:53 -0800 | [diff] [blame] | 155 | #include <linux/kthread.h> |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 156 | #include <net/net_namespace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | #include <net/checksum.h> |
| 158 | #include <net/ipv6.h> |
| 159 | #include <net/addrconf.h> |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 160 | #ifdef CONFIG_XFRM |
| 161 | #include <net/xfrm.h> |
| 162 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | #include <asm/byteorder.h> |
| 164 | #include <linux/rcupdate.h> |
Jiri Slaby | 1977f03 | 2007-10-18 23:40:25 -0700 | [diff] [blame] | 165 | #include <linux/bitops.h> |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 166 | #include <linux/io.h> |
| 167 | #include <linux/timex.h> |
| 168 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | #include <asm/dma.h> |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 170 | #include <asm/div64.h> /* do_div */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
Stephen Hemminger | c3d2f52 | 2009-08-27 13:55:20 +0000 | [diff] [blame] | 172 | #define VERSION "2.72" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | #define IP_NAME_SZ 32 |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 174 | #define MAX_MPLS_LABELS 16 /* This is the max label stack depth */ |
Stephen Hemminger | d5f1ce9 | 2007-03-04 16:08:08 -0800 | [diff] [blame] | 175 | #define MPLS_STACK_BOTTOM htonl(0x00000100) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
| 177 | /* Device flag bits */ |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 178 | #define F_IPSRC_RND (1<<0) /* IP-Src Random */ |
| 179 | #define F_IPDST_RND (1<<1) /* IP-Dst Random */ |
| 180 | #define F_UDPSRC_RND (1<<2) /* UDP-Src Random */ |
| 181 | #define F_UDPDST_RND (1<<3) /* UDP-Dst Random */ |
| 182 | #define F_MACSRC_RND (1<<4) /* MAC-Src Random */ |
| 183 | #define F_MACDST_RND (1<<5) /* MAC-Dst Random */ |
| 184 | #define F_TXSIZE_RND (1<<6) /* Transmit size is random */ |
| 185 | #define F_IPV6 (1<<7) /* Interface in IPV6 Mode */ |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 186 | #define F_MPLS_RND (1<<8) /* Random MPLS labels */ |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 187 | #define F_VID_RND (1<<9) /* Random VLAN ID */ |
| 188 | #define F_SVID_RND (1<<10) /* Random SVLAN ID */ |
Jamal Hadi Salim | 007a531 | 2007-07-02 22:40:36 -0700 | [diff] [blame] | 189 | #define F_FLOW_SEQ (1<<11) /* Sequential flows */ |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 190 | #define F_IPSEC_ON (1<<12) /* ipsec on for flows */ |
Robert Olsson | 45b270f | 2007-08-28 15:45:55 -0700 | [diff] [blame] | 191 | #define F_QUEUE_MAP_RND (1<<13) /* queue map Random */ |
Robert Olsson | e6fce5b | 2008-08-07 02:23:01 -0700 | [diff] [blame] | 192 | #define F_QUEUE_MAP_CPU (1<<14) /* queue map mirrors smp_processor_id() */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
| 194 | /* Thread control flag bits */ |
Stephen Hemminger | 6b80d6a | 2009-09-22 19:41:42 +0000 | [diff] [blame] | 195 | #define T_STOP (1<<0) /* Stop run */ |
| 196 | #define T_RUN (1<<1) /* Start run */ |
| 197 | #define T_REMDEVALL (1<<2) /* Remove all devs */ |
| 198 | #define T_REMDEV (1<<3) /* Remove one dev */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | /* If lock -- can be removed after some work */ |
| 201 | #define if_lock(t) spin_lock(&(t->if_lock)); |
| 202 | #define if_unlock(t) spin_unlock(&(t->if_lock)); |
| 203 | |
| 204 | /* Used to help with determining the pkts on receive */ |
| 205 | #define PKTGEN_MAGIC 0xbe9be955 |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 206 | #define PG_PROC_DIR "pktgen" |
| 207 | #define PGCTRL "pgctrl" |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 208 | static struct proc_dir_entry *pg_proc_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
| 210 | #define MAX_CFLOWS 65536 |
| 211 | |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 212 | #define VLAN_TAG_SIZE(x) ((x)->vlan_id == 0xffff ? 0 : 4) |
| 213 | #define SVLAN_TAG_SIZE(x) ((x)->svlan_id == 0xffff ? 0 : 4) |
| 214 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 215 | struct flow_state { |
Al Viro | 252e334 | 2006-11-14 20:48:11 -0800 | [diff] [blame] | 216 | __be32 cur_daddr; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 217 | int count; |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 218 | #ifdef CONFIG_XFRM |
| 219 | struct xfrm_state *x; |
| 220 | #endif |
Jamal Hadi Salim | 007a531 | 2007-07-02 22:40:36 -0700 | [diff] [blame] | 221 | __u32 flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | }; |
| 223 | |
Jamal Hadi Salim | 007a531 | 2007-07-02 22:40:36 -0700 | [diff] [blame] | 224 | /* flow flag bits */ |
| 225 | #define F_INIT (1<<0) /* flow has been initialized */ |
| 226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | struct pktgen_dev { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | /* |
| 229 | * Try to keep frequent/infrequent used vars. separated. |
| 230 | */ |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 231 | struct proc_dir_entry *entry; /* proc file */ |
| 232 | struct pktgen_thread *pg_thread;/* the owner */ |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 233 | struct list_head list; /* chaining in the thread's run-queue */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 235 | int running; /* if false, the test will stop */ |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 236 | |
| 237 | /* If min != max, then we will either do a linear iteration, or |
| 238 | * we will do a random selection from within the range. |
| 239 | */ |
| 240 | __u32 flags; |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 241 | int removal_mark; /* non-zero => the device is marked for |
| 242 | * removal by worker thread */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 244 | int min_pkt_size; /* = ETH_ZLEN; */ |
| 245 | int max_pkt_size; /* = ETH_ZLEN; */ |
Jamal Hadi Salim | 16dab72 | 2007-07-02 22:39:50 -0700 | [diff] [blame] | 246 | int pkt_overhead; /* overhead for MPLS, VLANs, IPSEC etc */ |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 247 | int nfrags; |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 248 | u64 delay; /* nano-seconds */ |
| 249 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 250 | __u64 count; /* Default No packets to send */ |
| 251 | __u64 sofar; /* How many pkts we've sent so far */ |
| 252 | __u64 tx_bytes; /* How many bytes we've transmitted */ |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 253 | __u64 errors; /* Errors when trying to transmit, |
| 254 | pkts will be re-sent */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 256 | /* runtime counters relating to clone_skb */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 258 | __u64 allocated_skbs; |
| 259 | __u32 clone_count; |
| 260 | int last_ok; /* Was last skb sent? |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 261 | * Or a failed transmit of some sort? |
| 262 | * This will keep sequence numbers in order |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 263 | */ |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 264 | ktime_t next_tx; |
| 265 | ktime_t started_at; |
| 266 | ktime_t stopped_at; |
| 267 | u64 idle_acc; /* nano-seconds */ |
| 268 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 269 | __u32 seq_num; |
| 270 | |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 271 | int clone_skb; /* |
| 272 | * Use multiple SKBs during packet gen. |
| 273 | * If this number is greater than 1, then |
| 274 | * that many copies of the same packet will be |
| 275 | * sent before a new packet is allocated. |
| 276 | * If you want to send 1024 identical packets |
| 277 | * before creating a new packet, |
| 278 | * set clone_skb to 1024. |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 279 | */ |
| 280 | |
| 281 | char dst_min[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */ |
| 282 | char dst_max[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */ |
| 283 | char src_min[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */ |
| 284 | char src_max[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */ |
| 285 | |
| 286 | struct in6_addr in6_saddr; |
| 287 | struct in6_addr in6_daddr; |
| 288 | struct in6_addr cur_in6_daddr; |
| 289 | struct in6_addr cur_in6_saddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | /* For ranges */ |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 291 | struct in6_addr min_in6_daddr; |
| 292 | struct in6_addr max_in6_daddr; |
| 293 | struct in6_addr min_in6_saddr; |
| 294 | struct in6_addr max_in6_saddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 296 | /* If we're doing ranges, random or incremental, then this |
| 297 | * defines the min/max for those ranges. |
| 298 | */ |
Al Viro | 252e334 | 2006-11-14 20:48:11 -0800 | [diff] [blame] | 299 | __be32 saddr_min; /* inclusive, source IP address */ |
| 300 | __be32 saddr_max; /* exclusive, source IP address */ |
| 301 | __be32 daddr_min; /* inclusive, dest IP address */ |
| 302 | __be32 daddr_max; /* exclusive, dest IP address */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 304 | __u16 udp_src_min; /* inclusive, source UDP port */ |
| 305 | __u16 udp_src_max; /* exclusive, source UDP port */ |
| 306 | __u16 udp_dst_min; /* inclusive, dest UDP port */ |
| 307 | __u16 udp_dst_max; /* exclusive, dest UDP port */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
Francesco Fondelli | 1ca7768 | 2006-09-27 16:32:03 -0700 | [diff] [blame] | 309 | /* DSCP + ECN */ |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 310 | __u8 tos; /* six MSB of (former) IPv4 TOS |
| 311 | are for dscp codepoint */ |
| 312 | __u8 traffic_class; /* ditto for the (former) Traffic Class in IPv6 |
| 313 | (see RFC 3260, sec. 4) */ |
Francesco Fondelli | 1ca7768 | 2006-09-27 16:32:03 -0700 | [diff] [blame] | 314 | |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 315 | /* MPLS */ |
| 316 | unsigned nr_labels; /* Depth of stack, 0 = no MPLS */ |
| 317 | __be32 labels[MAX_MPLS_LABELS]; |
| 318 | |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 319 | /* VLAN/SVLAN (802.1Q/Q-in-Q) */ |
| 320 | __u8 vlan_p; |
| 321 | __u8 vlan_cfi; |
| 322 | __u16 vlan_id; /* 0xffff means no vlan tag */ |
| 323 | |
| 324 | __u8 svlan_p; |
| 325 | __u8 svlan_cfi; |
| 326 | __u16 svlan_id; /* 0xffff means no svlan tag */ |
| 327 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 328 | __u32 src_mac_count; /* How many MACs to iterate through */ |
| 329 | __u32 dst_mac_count; /* How many MACs to iterate through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 331 | unsigned char dst_mac[ETH_ALEN]; |
| 332 | unsigned char src_mac[ETH_ALEN]; |
| 333 | |
| 334 | __u32 cur_dst_mac_offset; |
| 335 | __u32 cur_src_mac_offset; |
Al Viro | 252e334 | 2006-11-14 20:48:11 -0800 | [diff] [blame] | 336 | __be32 cur_saddr; |
| 337 | __be32 cur_daddr; |
Eric Dumazet | 66ed1e5 | 2009-10-24 06:55:20 -0700 | [diff] [blame^] | 338 | __u16 ip_id; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 339 | __u16 cur_udp_dst; |
| 340 | __u16 cur_udp_src; |
Robert Olsson | 45b270f | 2007-08-28 15:45:55 -0700 | [diff] [blame] | 341 | __u16 cur_queue_map; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 342 | __u32 cur_pkt_size; |
| 343 | |
| 344 | __u8 hh[14]; |
| 345 | /* = { |
| 346 | 0x00, 0x80, 0xC8, 0x79, 0xB3, 0xCB, |
| 347 | |
| 348 | We fill in SRC address later |
| 349 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 350 | 0x08, 0x00 |
| 351 | }; |
| 352 | */ |
| 353 | __u16 pad; /* pad out the hh struct to an even 16 bytes */ |
| 354 | |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 355 | struct sk_buff *skb; /* skb we are to transmit next, used for when we |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 356 | * are transmitting the same one multiple times |
| 357 | */ |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 358 | struct net_device *odev; /* The out-going device. |
| 359 | * Note that the device should have it's |
| 360 | * pg_info pointer pointing back to this |
| 361 | * device. |
| 362 | * Set when the user specifies the out-going |
| 363 | * device name (not when the inject is |
| 364 | * started as it used to do.) |
| 365 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | struct flow_state *flows; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 367 | unsigned cflows; /* Concurrent flows (config) */ |
| 368 | unsigned lflow; /* Flow length (config) */ |
| 369 | unsigned nflows; /* accumulated flows (stats) */ |
Jamal Hadi Salim | 007a531 | 2007-07-02 22:40:36 -0700 | [diff] [blame] | 370 | unsigned curfl; /* current sequenced flow (state)*/ |
Robert Olsson | 45b270f | 2007-08-28 15:45:55 -0700 | [diff] [blame] | 371 | |
| 372 | u16 queue_map_min; |
| 373 | u16 queue_map_max; |
| 374 | |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 375 | #ifdef CONFIG_XFRM |
| 376 | __u8 ipsmode; /* IPSEC mode (config) */ |
| 377 | __u8 ipsproto; /* IPSEC type (config) */ |
| 378 | #endif |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 379 | char result[512]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | }; |
| 381 | |
| 382 | struct pktgen_hdr { |
Al Viro | 252e334 | 2006-11-14 20:48:11 -0800 | [diff] [blame] | 383 | __be32 pgh_magic; |
| 384 | __be32 seq_num; |
| 385 | __be32 tv_sec; |
| 386 | __be32 tv_usec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | }; |
| 388 | |
| 389 | struct pktgen_thread { |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 390 | spinlock_t if_lock; /* for list of devices */ |
Luiz Capitulino | c26a801 | 2006-03-20 22:18:16 -0800 | [diff] [blame] | 391 | struct list_head if_list; /* All device here */ |
Luiz Capitulino | cdcdbe0 | 2006-03-20 22:16:40 -0800 | [diff] [blame] | 392 | struct list_head th_list; |
David S. Miller | ee74baa | 2007-01-01 20:51:53 -0800 | [diff] [blame] | 393 | struct task_struct *tsk; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 394 | char result[512]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 396 | /* Field for thread to receive "posted" events terminate, |
| 397 | stop ifs etc. */ |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 398 | |
| 399 | u32 control; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | int cpu; |
| 401 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 402 | wait_queue_head_t queue; |
Denis V. Lunev | d3ede32 | 2008-05-20 15:12:44 -0700 | [diff] [blame] | 403 | struct completion start_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | }; |
| 405 | |
| 406 | #define REMOVE 1 |
| 407 | #define FIND 0 |
| 408 | |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 409 | static inline ktime_t ktime_now(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | { |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 411 | struct timespec ts; |
| 412 | ktime_get_ts(&ts); |
| 413 | |
| 414 | return timespec_to_ktime(ts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 417 | /* This works even if 32 bit because of careful byte order choice */ |
| 418 | static inline int ktime_lt(const ktime_t cmp1, const ktime_t cmp2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | { |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 420 | return cmp1.tv64 < cmp2.tv64; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Stephen Hemminger | c3d2f52 | 2009-08-27 13:55:20 +0000 | [diff] [blame] | 423 | static const char version[] = |
| 424 | "pktgen " VERSION ": Packet Generator for packet performance testing.\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 426 | static int pktgen_remove_device(struct pktgen_thread *t, struct pktgen_dev *i); |
| 427 | static int pktgen_add_device(struct pktgen_thread *t, const char *ifname); |
| 428 | static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t, |
| 429 | const char *ifname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | static int pktgen_device_event(struct notifier_block *, unsigned long, void *); |
| 431 | static void pktgen_run_all_threads(void); |
Jesse Brandeburg | eb37b41 | 2008-11-10 16:48:03 -0800 | [diff] [blame] | 432 | static void pktgen_reset_all_threads(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | static void pktgen_stop_all_threads_ifs(void); |
Stephen Hemminger | 3bda06a | 2009-08-27 13:55:10 +0000 | [diff] [blame] | 434 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 435 | static void pktgen_stop(struct pktgen_thread *t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | static void pktgen_clear_counters(struct pktgen_dev *pkt_dev); |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 437 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 438 | static unsigned int scan_ip6(const char *s, char ip[16]); |
| 439 | static unsigned int fmt_ip6(char *s, const char ip[16]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
| 441 | /* Module parameters, defaults. */ |
Stephen Hemminger | 65c5b78 | 2009-08-27 13:55:09 +0000 | [diff] [blame] | 442 | static int pg_count_d __read_mostly = 1000; |
| 443 | static int pg_delay_d __read_mostly; |
| 444 | static int pg_clone_skb_d __read_mostly; |
| 445 | static int debug __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
Luiz Capitulino | 222fa07 | 2006-03-20 22:24:27 -0800 | [diff] [blame] | 447 | static DEFINE_MUTEX(pktgen_thread_lock); |
Luiz Capitulino | cdcdbe0 | 2006-03-20 22:16:40 -0800 | [diff] [blame] | 448 | static LIST_HEAD(pktgen_threads); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | static struct notifier_block pktgen_notifier_block = { |
| 451 | .notifier_call = pktgen_device_event, |
| 452 | }; |
| 453 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | /* |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 455 | * /proc handling functions |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | * |
| 457 | */ |
| 458 | |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 459 | static int pgctrl_show(struct seq_file *seq, void *v) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 460 | { |
Stephen Hemminger | c3d2f52 | 2009-08-27 13:55:20 +0000 | [diff] [blame] | 461 | seq_puts(seq, version); |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 462 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | } |
| 464 | |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 465 | static ssize_t pgctrl_write(struct file *file, const char __user *buf, |
| 466 | size_t count, loff_t *ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | int err = 0; |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 469 | char data[128]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 471 | if (!capable(CAP_NET_ADMIN)) { |
| 472 | err = -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | goto out; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 474 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 476 | if (count > sizeof(data)) |
| 477 | count = sizeof(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | if (copy_from_user(data, buf, count)) { |
Stephen Hemminger | b4099fa | 2005-10-14 15:32:22 -0700 | [diff] [blame] | 480 | err = -EFAULT; |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 481 | goto out; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 482 | } |
| 483 | data[count - 1] = 0; /* Make string */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 485 | if (!strcmp(data, "stop")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | pktgen_stop_all_threads_ifs(); |
| 487 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 488 | else if (!strcmp(data, "start")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | pktgen_run_all_threads(); |
| 490 | |
Jesse Brandeburg | eb37b41 | 2008-11-10 16:48:03 -0800 | [diff] [blame] | 491 | else if (!strcmp(data, "reset")) |
| 492 | pktgen_reset_all_threads(); |
| 493 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 494 | else |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 495 | printk(KERN_WARNING "pktgen: Unknown command: %s\n", data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
| 497 | err = count; |
| 498 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 499 | out: |
| 500 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | } |
| 502 | |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 503 | static int pgctrl_open(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | { |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 505 | return single_open(file, pgctrl_show, PDE(inode)->data); |
| 506 | } |
| 507 | |
Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 508 | static const struct file_operations pktgen_fops = { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 509 | .owner = THIS_MODULE, |
| 510 | .open = pgctrl_open, |
| 511 | .read = seq_read, |
| 512 | .llseek = seq_lseek, |
| 513 | .write = pgctrl_write, |
| 514 | .release = single_release, |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 515 | }; |
| 516 | |
| 517 | static int pktgen_if_show(struct seq_file *seq, void *v) |
| 518 | { |
Stephen Hemminger | 648fda7 | 2009-08-27 13:55:07 +0000 | [diff] [blame] | 519 | const struct pktgen_dev *pkt_dev = seq->private; |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 520 | ktime_t stopped; |
| 521 | u64 idle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 523 | seq_printf(seq, |
| 524 | "Params: count %llu min_pkt_size: %u max_pkt_size: %u\n", |
| 525 | (unsigned long long)pkt_dev->count, pkt_dev->min_pkt_size, |
| 526 | pkt_dev->max_pkt_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 528 | seq_printf(seq, |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 529 | " frags: %d delay: %llu clone_skb: %d ifname: %s\n", |
| 530 | pkt_dev->nfrags, (unsigned long long) pkt_dev->delay, |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 531 | pkt_dev->clone_skb, pkt_dev->odev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 533 | seq_printf(seq, " flows: %u flowlen: %u\n", pkt_dev->cflows, |
| 534 | pkt_dev->lflow); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | |
Robert Olsson | 45b270f | 2007-08-28 15:45:55 -0700 | [diff] [blame] | 536 | seq_printf(seq, |
| 537 | " queue_map_min: %u queue_map_max: %u\n", |
| 538 | pkt_dev->queue_map_min, |
| 539 | pkt_dev->queue_map_max); |
| 540 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 541 | if (pkt_dev->flags & F_IPV6) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | char b1[128], b2[128], b3[128]; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 543 | fmt_ip6(b1, pkt_dev->in6_saddr.s6_addr); |
| 544 | fmt_ip6(b2, pkt_dev->min_in6_saddr.s6_addr); |
| 545 | fmt_ip6(b3, pkt_dev->max_in6_saddr.s6_addr); |
| 546 | seq_printf(seq, |
| 547 | " saddr: %s min_saddr: %s max_saddr: %s\n", b1, |
| 548 | b2, b3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 550 | fmt_ip6(b1, pkt_dev->in6_daddr.s6_addr); |
| 551 | fmt_ip6(b2, pkt_dev->min_in6_daddr.s6_addr); |
| 552 | fmt_ip6(b3, pkt_dev->max_in6_daddr.s6_addr); |
| 553 | seq_printf(seq, |
| 554 | " daddr: %s min_daddr: %s max_daddr: %s\n", b1, |
| 555 | b2, b3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 557 | } else { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 558 | seq_printf(seq, |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 559 | " dst_min: %s dst_max: %s\n", |
| 560 | pkt_dev->dst_min, pkt_dev->dst_max); |
| 561 | seq_printf(seq, |
| 562 | " src_min: %s src_max: %s\n", |
| 563 | pkt_dev->src_min, pkt_dev->src_max); |
| 564 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 566 | seq_puts(seq, " src_mac: "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 568 | seq_printf(seq, "%pM ", |
| 569 | is_zero_ether_addr(pkt_dev->src_mac) ? |
| 570 | pkt_dev->odev->dev_addr : pkt_dev->src_mac); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 572 | seq_printf(seq, "dst_mac: "); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 573 | seq_printf(seq, "%pM\n", pkt_dev->dst_mac); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 575 | seq_printf(seq, |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 576 | " udp_src_min: %d udp_src_max: %d" |
| 577 | " udp_dst_min: %d udp_dst_max: %d\n", |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 578 | pkt_dev->udp_src_min, pkt_dev->udp_src_max, |
| 579 | pkt_dev->udp_dst_min, pkt_dev->udp_dst_max); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 581 | seq_printf(seq, |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 582 | " src_mac_count: %d dst_mac_count: %d\n", |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 583 | pkt_dev->src_mac_count, pkt_dev->dst_mac_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 585 | if (pkt_dev->nr_labels) { |
| 586 | unsigned i; |
| 587 | seq_printf(seq, " mpls: "); |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 588 | for (i = 0; i < pkt_dev->nr_labels; i++) |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 589 | seq_printf(seq, "%08x%s", ntohl(pkt_dev->labels[i]), |
| 590 | i == pkt_dev->nr_labels-1 ? "\n" : ", "); |
| 591 | } |
| 592 | |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 593 | if (pkt_dev->vlan_id != 0xffff) |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 594 | seq_printf(seq, " vlan_id: %u vlan_p: %u vlan_cfi: %u\n", |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 595 | pkt_dev->vlan_id, pkt_dev->vlan_p, |
| 596 | pkt_dev->vlan_cfi); |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 597 | |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 598 | if (pkt_dev->svlan_id != 0xffff) |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 599 | seq_printf(seq, " svlan_id: %u vlan_p: %u vlan_cfi: %u\n", |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 600 | pkt_dev->svlan_id, pkt_dev->svlan_p, |
| 601 | pkt_dev->svlan_cfi); |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 602 | |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 603 | if (pkt_dev->tos) |
Francesco Fondelli | 1ca7768 | 2006-09-27 16:32:03 -0700 | [diff] [blame] | 604 | seq_printf(seq, " tos: 0x%02x\n", pkt_dev->tos); |
Francesco Fondelli | 1ca7768 | 2006-09-27 16:32:03 -0700 | [diff] [blame] | 605 | |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 606 | if (pkt_dev->traffic_class) |
Francesco Fondelli | 1ca7768 | 2006-09-27 16:32:03 -0700 | [diff] [blame] | 607 | seq_printf(seq, " traffic_class: 0x%02x\n", pkt_dev->traffic_class); |
Francesco Fondelli | 1ca7768 | 2006-09-27 16:32:03 -0700 | [diff] [blame] | 608 | |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 609 | seq_printf(seq, " Flags: "); |
| 610 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 611 | if (pkt_dev->flags & F_IPV6) |
| 612 | seq_printf(seq, "IPV6 "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 614 | if (pkt_dev->flags & F_IPSRC_RND) |
| 615 | seq_printf(seq, "IPSRC_RND "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 617 | if (pkt_dev->flags & F_IPDST_RND) |
| 618 | seq_printf(seq, "IPDST_RND "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 620 | if (pkt_dev->flags & F_TXSIZE_RND) |
| 621 | seq_printf(seq, "TXSIZE_RND "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 623 | if (pkt_dev->flags & F_UDPSRC_RND) |
| 624 | seq_printf(seq, "UDPSRC_RND "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 626 | if (pkt_dev->flags & F_UDPDST_RND) |
| 627 | seq_printf(seq, "UDPDST_RND "); |
| 628 | |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 629 | if (pkt_dev->flags & F_MPLS_RND) |
| 630 | seq_printf(seq, "MPLS_RND "); |
| 631 | |
Robert Olsson | 45b270f | 2007-08-28 15:45:55 -0700 | [diff] [blame] | 632 | if (pkt_dev->flags & F_QUEUE_MAP_RND) |
| 633 | seq_printf(seq, "QUEUE_MAP_RND "); |
| 634 | |
Robert Olsson | e6fce5b | 2008-08-07 02:23:01 -0700 | [diff] [blame] | 635 | if (pkt_dev->flags & F_QUEUE_MAP_CPU) |
| 636 | seq_printf(seq, "QUEUE_MAP_CPU "); |
| 637 | |
Jamal Hadi Salim | 007a531 | 2007-07-02 22:40:36 -0700 | [diff] [blame] | 638 | if (pkt_dev->cflows) { |
| 639 | if (pkt_dev->flags & F_FLOW_SEQ) |
| 640 | seq_printf(seq, "FLOW_SEQ "); /*in sequence flows*/ |
| 641 | else |
| 642 | seq_printf(seq, "FLOW_RND "); |
| 643 | } |
| 644 | |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 645 | #ifdef CONFIG_XFRM |
| 646 | if (pkt_dev->flags & F_IPSEC_ON) |
| 647 | seq_printf(seq, "IPSEC "); |
| 648 | #endif |
| 649 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 650 | if (pkt_dev->flags & F_MACSRC_RND) |
| 651 | seq_printf(seq, "MACSRC_RND "); |
| 652 | |
| 653 | if (pkt_dev->flags & F_MACDST_RND) |
| 654 | seq_printf(seq, "MACDST_RND "); |
| 655 | |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 656 | if (pkt_dev->flags & F_VID_RND) |
| 657 | seq_printf(seq, "VID_RND "); |
| 658 | |
| 659 | if (pkt_dev->flags & F_SVID_RND) |
| 660 | seq_printf(seq, "SVID_RND "); |
| 661 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 662 | seq_puts(seq, "\n"); |
| 663 | |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 664 | /* not really stopped, more like last-running-at */ |
| 665 | stopped = pkt_dev->running ? ktime_now() : pkt_dev->stopped_at; |
| 666 | idle = pkt_dev->idle_acc; |
| 667 | do_div(idle, NSEC_PER_USEC); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 668 | |
| 669 | seq_printf(seq, |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 670 | "Current:\n pkts-sofar: %llu errors: %llu\n", |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 671 | (unsigned long long)pkt_dev->sofar, |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 672 | (unsigned long long)pkt_dev->errors); |
| 673 | |
| 674 | seq_printf(seq, |
| 675 | " started: %lluus stopped: %lluus idle: %lluus\n", |
| 676 | (unsigned long long) ktime_to_us(pkt_dev->started_at), |
| 677 | (unsigned long long) ktime_to_us(stopped), |
| 678 | (unsigned long long) idle); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 679 | |
| 680 | seq_printf(seq, |
| 681 | " seq_num: %d cur_dst_mac_offset: %d cur_src_mac_offset: %d\n", |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 682 | pkt_dev->seq_num, pkt_dev->cur_dst_mac_offset, |
| 683 | pkt_dev->cur_src_mac_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 685 | if (pkt_dev->flags & F_IPV6) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | char b1[128], b2[128]; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 687 | fmt_ip6(b1, pkt_dev->cur_in6_daddr.s6_addr); |
| 688 | fmt_ip6(b2, pkt_dev->cur_in6_saddr.s6_addr); |
| 689 | seq_printf(seq, " cur_saddr: %s cur_daddr: %s\n", b2, b1); |
| 690 | } else |
| 691 | seq_printf(seq, " cur_saddr: 0x%x cur_daddr: 0x%x\n", |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 692 | pkt_dev->cur_saddr, pkt_dev->cur_daddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 694 | seq_printf(seq, " cur_udp_dst: %d cur_udp_src: %d\n", |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 695 | pkt_dev->cur_udp_dst, pkt_dev->cur_udp_src); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | |
Robert Olsson | 45b270f | 2007-08-28 15:45:55 -0700 | [diff] [blame] | 697 | seq_printf(seq, " cur_queue_map: %u\n", pkt_dev->cur_queue_map); |
| 698 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 699 | seq_printf(seq, " flows: %u\n", pkt_dev->nflows); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | |
| 701 | if (pkt_dev->result[0]) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 702 | seq_printf(seq, "Result: %s\n", pkt_dev->result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | else |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 704 | seq_printf(seq, "Result: Idle\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 706 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | } |
| 708 | |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 709 | |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 710 | static int hex32_arg(const char __user *user_buffer, unsigned long maxlen, |
| 711 | __u32 *num) |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 712 | { |
| 713 | int i = 0; |
| 714 | *num = 0; |
| 715 | |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 716 | for (; i < maxlen; i++) { |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 717 | char c; |
| 718 | *num <<= 4; |
| 719 | if (get_user(c, &user_buffer[i])) |
| 720 | return -EFAULT; |
| 721 | if ((c >= '0') && (c <= '9')) |
| 722 | *num |= c - '0'; |
| 723 | else if ((c >= 'a') && (c <= 'f')) |
| 724 | *num |= c - 'a' + 10; |
| 725 | else if ((c >= 'A') && (c <= 'F')) |
| 726 | *num |= c - 'A' + 10; |
| 727 | else |
| 728 | break; |
| 729 | } |
| 730 | return i; |
| 731 | } |
| 732 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 733 | static int count_trail_chars(const char __user * user_buffer, |
| 734 | unsigned int maxlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | { |
| 736 | int i; |
| 737 | |
| 738 | for (i = 0; i < maxlen; i++) { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 739 | char c; |
| 740 | if (get_user(c, &user_buffer[i])) |
| 741 | return -EFAULT; |
| 742 | switch (c) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | case '\"': |
| 744 | case '\n': |
| 745 | case '\r': |
| 746 | case '\t': |
| 747 | case ' ': |
| 748 | case '=': |
| 749 | break; |
| 750 | default: |
| 751 | goto done; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 752 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | } |
| 754 | done: |
| 755 | return i; |
| 756 | } |
| 757 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 758 | static unsigned long num_arg(const char __user * user_buffer, |
| 759 | unsigned long maxlen, unsigned long *num) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | { |
| 761 | int i = 0; |
| 762 | *num = 0; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 763 | |
| 764 | for (; i < maxlen; i++) { |
| 765 | char c; |
| 766 | if (get_user(c, &user_buffer[i])) |
| 767 | return -EFAULT; |
| 768 | if ((c >= '0') && (c <= '9')) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | *num *= 10; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 770 | *num += c - '0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | } else |
| 772 | break; |
| 773 | } |
| 774 | return i; |
| 775 | } |
| 776 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 777 | static int strn_len(const char __user * user_buffer, unsigned int maxlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | { |
| 779 | int i = 0; |
| 780 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 781 | for (; i < maxlen; i++) { |
| 782 | char c; |
| 783 | if (get_user(c, &user_buffer[i])) |
| 784 | return -EFAULT; |
| 785 | switch (c) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | case '\"': |
| 787 | case '\n': |
| 788 | case '\r': |
| 789 | case '\t': |
| 790 | case ' ': |
| 791 | goto done_str; |
| 792 | break; |
| 793 | default: |
| 794 | break; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 795 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | } |
| 797 | done_str: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | return i; |
| 799 | } |
| 800 | |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 801 | static ssize_t get_labels(const char __user *buffer, struct pktgen_dev *pkt_dev) |
| 802 | { |
| 803 | unsigned n = 0; |
| 804 | char c; |
| 805 | ssize_t i = 0; |
| 806 | int len; |
| 807 | |
| 808 | pkt_dev->nr_labels = 0; |
| 809 | do { |
| 810 | __u32 tmp; |
Francesco Fondelli | 1ca7768 | 2006-09-27 16:32:03 -0700 | [diff] [blame] | 811 | len = hex32_arg(&buffer[i], 8, &tmp); |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 812 | if (len <= 0) |
| 813 | return len; |
| 814 | pkt_dev->labels[n] = htonl(tmp); |
| 815 | if (pkt_dev->labels[n] & MPLS_STACK_BOTTOM) |
| 816 | pkt_dev->flags |= F_MPLS_RND; |
| 817 | i += len; |
| 818 | if (get_user(c, &buffer[i])) |
| 819 | return -EFAULT; |
| 820 | i++; |
| 821 | n++; |
| 822 | if (n >= MAX_MPLS_LABELS) |
| 823 | return -E2BIG; |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 824 | } while (c == ','); |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 825 | |
| 826 | pkt_dev->nr_labels = n; |
| 827 | return i; |
| 828 | } |
| 829 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 830 | static ssize_t pktgen_if_write(struct file *file, |
| 831 | const char __user * user_buffer, size_t count, |
| 832 | loff_t * offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 834 | struct seq_file *seq = (struct seq_file *)file->private_data; |
| 835 | struct pktgen_dev *pkt_dev = seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | int i = 0, max, len; |
| 837 | char name[16], valstr[32]; |
| 838 | unsigned long value = 0; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 839 | char *pg_result = NULL; |
| 840 | int tmp = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | char buf[128]; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 842 | |
| 843 | pg_result = &(pkt_dev->result[0]); |
| 844 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | if (count < 1) { |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 846 | printk(KERN_WARNING "pktgen: wrong command format\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | return -EINVAL; |
| 848 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 849 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | max = count - i; |
| 851 | tmp = count_trail_chars(&user_buffer[i], max); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 852 | if (tmp < 0) { |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 853 | printk(KERN_WARNING "pktgen: illegal format\n"); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 854 | return tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 856 | i += tmp; |
| 857 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | /* Read variable name */ |
| 859 | |
| 860 | len = strn_len(&user_buffer[i], sizeof(name) - 1); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 861 | if (len < 0) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 862 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 863 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | memset(name, 0, sizeof(name)); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 865 | if (copy_from_user(name, &user_buffer[i], len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | return -EFAULT; |
| 867 | i += len; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 868 | |
| 869 | max = count - i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | len = count_trail_chars(&user_buffer[i], max); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 871 | if (len < 0) |
| 872 | return len; |
| 873 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | i += len; |
| 875 | |
| 876 | if (debug) { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 877 | char tb[count + 1]; |
| 878 | if (copy_from_user(tb, user_buffer, count)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | return -EFAULT; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 880 | tb[count] = 0; |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 881 | printk(KERN_DEBUG "pktgen: %s,%lu buffer -:%s:-\n", name, |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 882 | (unsigned long)count, tb); |
| 883 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | |
| 885 | if (!strcmp(name, "min_pkt_size")) { |
| 886 | len = num_arg(&user_buffer[i], 10, &value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 887 | if (len < 0) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 888 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 889 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | i += len; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 891 | if (value < 14 + 20 + 8) |
| 892 | value = 14 + 20 + 8; |
| 893 | if (value != pkt_dev->min_pkt_size) { |
| 894 | pkt_dev->min_pkt_size = value; |
| 895 | pkt_dev->cur_pkt_size = value; |
| 896 | } |
| 897 | sprintf(pg_result, "OK: min_pkt_size=%u", |
| 898 | pkt_dev->min_pkt_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | return count; |
| 900 | } |
| 901 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 902 | if (!strcmp(name, "max_pkt_size")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | len = num_arg(&user_buffer[i], 10, &value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 904 | if (len < 0) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 905 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 906 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | i += len; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 908 | if (value < 14 + 20 + 8) |
| 909 | value = 14 + 20 + 8; |
| 910 | if (value != pkt_dev->max_pkt_size) { |
| 911 | pkt_dev->max_pkt_size = value; |
| 912 | pkt_dev->cur_pkt_size = value; |
| 913 | } |
| 914 | sprintf(pg_result, "OK: max_pkt_size=%u", |
| 915 | pkt_dev->max_pkt_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | return count; |
| 917 | } |
| 918 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 919 | /* Shortcut for min = max */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | |
| 921 | if (!strcmp(name, "pkt_size")) { |
| 922 | len = num_arg(&user_buffer[i], 10, &value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 923 | if (len < 0) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 924 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 925 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | i += len; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 927 | if (value < 14 + 20 + 8) |
| 928 | value = 14 + 20 + 8; |
| 929 | if (value != pkt_dev->min_pkt_size) { |
| 930 | pkt_dev->min_pkt_size = value; |
| 931 | pkt_dev->max_pkt_size = value; |
| 932 | pkt_dev->cur_pkt_size = value; |
| 933 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | sprintf(pg_result, "OK: pkt_size=%u", pkt_dev->min_pkt_size); |
| 935 | return count; |
| 936 | } |
| 937 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 938 | if (!strcmp(name, "debug")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | len = num_arg(&user_buffer[i], 10, &value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 940 | if (len < 0) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 941 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 942 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | i += len; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 944 | debug = value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | sprintf(pg_result, "OK: debug=%u", debug); |
| 946 | return count; |
| 947 | } |
| 948 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 949 | if (!strcmp(name, "frags")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | len = num_arg(&user_buffer[i], 10, &value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 951 | if (len < 0) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 952 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 953 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | i += len; |
| 955 | pkt_dev->nfrags = value; |
| 956 | sprintf(pg_result, "OK: frags=%u", pkt_dev->nfrags); |
| 957 | return count; |
| 958 | } |
| 959 | if (!strcmp(name, "delay")) { |
| 960 | len = num_arg(&user_buffer[i], 10, &value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 961 | if (len < 0) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 962 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 963 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | i += len; |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 965 | if (value == 0x7FFFFFFF) |
| 966 | pkt_dev->delay = ULLONG_MAX; |
| 967 | else |
Eric Dumazet | 9240d71 | 2009-10-03 01:39:18 +0000 | [diff] [blame] | 968 | pkt_dev->delay = (u64)value; |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 969 | |
| 970 | sprintf(pg_result, "OK: delay=%llu", |
| 971 | (unsigned long long) pkt_dev->delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | return count; |
| 973 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 974 | if (!strcmp(name, "udp_src_min")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | len = num_arg(&user_buffer[i], 10, &value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 976 | if (len < 0) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 977 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 978 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | i += len; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 980 | if (value != pkt_dev->udp_src_min) { |
| 981 | pkt_dev->udp_src_min = value; |
| 982 | pkt_dev->cur_udp_src = value; |
| 983 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | sprintf(pg_result, "OK: udp_src_min=%u", pkt_dev->udp_src_min); |
| 985 | return count; |
| 986 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 987 | if (!strcmp(name, "udp_dst_min")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | len = num_arg(&user_buffer[i], 10, &value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 989 | if (len < 0) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 990 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 991 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | i += len; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 993 | if (value != pkt_dev->udp_dst_min) { |
| 994 | pkt_dev->udp_dst_min = value; |
| 995 | pkt_dev->cur_udp_dst = value; |
| 996 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | sprintf(pg_result, "OK: udp_dst_min=%u", pkt_dev->udp_dst_min); |
| 998 | return count; |
| 999 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1000 | if (!strcmp(name, "udp_src_max")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | len = num_arg(&user_buffer[i], 10, &value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1002 | if (len < 0) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1003 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1004 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | i += len; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1006 | if (value != pkt_dev->udp_src_max) { |
| 1007 | pkt_dev->udp_src_max = value; |
| 1008 | pkt_dev->cur_udp_src = value; |
| 1009 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | sprintf(pg_result, "OK: udp_src_max=%u", pkt_dev->udp_src_max); |
| 1011 | return count; |
| 1012 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1013 | if (!strcmp(name, "udp_dst_max")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | len = num_arg(&user_buffer[i], 10, &value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1015 | if (len < 0) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1016 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1017 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | i += len; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1019 | if (value != pkt_dev->udp_dst_max) { |
| 1020 | pkt_dev->udp_dst_max = value; |
| 1021 | pkt_dev->cur_udp_dst = value; |
| 1022 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | sprintf(pg_result, "OK: udp_dst_max=%u", pkt_dev->udp_dst_max); |
| 1024 | return count; |
| 1025 | } |
| 1026 | if (!strcmp(name, "clone_skb")) { |
| 1027 | len = num_arg(&user_buffer[i], 10, &value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1028 | if (len < 0) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1029 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1030 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | i += len; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1032 | pkt_dev->clone_skb = value; |
| 1033 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | sprintf(pg_result, "OK: clone_skb=%d", pkt_dev->clone_skb); |
| 1035 | return count; |
| 1036 | } |
| 1037 | if (!strcmp(name, "count")) { |
| 1038 | len = num_arg(&user_buffer[i], 10, &value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1039 | if (len < 0) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1040 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1041 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | i += len; |
| 1043 | pkt_dev->count = value; |
| 1044 | sprintf(pg_result, "OK: count=%llu", |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1045 | (unsigned long long)pkt_dev->count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | return count; |
| 1047 | } |
| 1048 | if (!strcmp(name, "src_mac_count")) { |
| 1049 | len = num_arg(&user_buffer[i], 10, &value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1050 | if (len < 0) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1051 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1052 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | i += len; |
| 1054 | if (pkt_dev->src_mac_count != value) { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1055 | pkt_dev->src_mac_count = value; |
| 1056 | pkt_dev->cur_src_mac_offset = 0; |
| 1057 | } |
| 1058 | sprintf(pg_result, "OK: src_mac_count=%d", |
| 1059 | pkt_dev->src_mac_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | return count; |
| 1061 | } |
| 1062 | if (!strcmp(name, "dst_mac_count")) { |
| 1063 | len = num_arg(&user_buffer[i], 10, &value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1064 | if (len < 0) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1065 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1066 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | i += len; |
| 1068 | if (pkt_dev->dst_mac_count != value) { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1069 | pkt_dev->dst_mac_count = value; |
| 1070 | pkt_dev->cur_dst_mac_offset = 0; |
| 1071 | } |
| 1072 | sprintf(pg_result, "OK: dst_mac_count=%d", |
| 1073 | pkt_dev->dst_mac_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | return count; |
| 1075 | } |
| 1076 | if (!strcmp(name, "flag")) { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1077 | char f[32]; |
| 1078 | memset(f, 0, 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | len = strn_len(&user_buffer[i], sizeof(f) - 1); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1080 | if (len < 0) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1081 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1082 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | if (copy_from_user(f, &user_buffer[i], len)) |
| 1084 | return -EFAULT; |
| 1085 | i += len; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1086 | if (strcmp(f, "IPSRC_RND") == 0) |
| 1087 | pkt_dev->flags |= F_IPSRC_RND; |
| 1088 | |
| 1089 | else if (strcmp(f, "!IPSRC_RND") == 0) |
| 1090 | pkt_dev->flags &= ~F_IPSRC_RND; |
| 1091 | |
| 1092 | else if (strcmp(f, "TXSIZE_RND") == 0) |
| 1093 | pkt_dev->flags |= F_TXSIZE_RND; |
| 1094 | |
| 1095 | else if (strcmp(f, "!TXSIZE_RND") == 0) |
| 1096 | pkt_dev->flags &= ~F_TXSIZE_RND; |
| 1097 | |
| 1098 | else if (strcmp(f, "IPDST_RND") == 0) |
| 1099 | pkt_dev->flags |= F_IPDST_RND; |
| 1100 | |
| 1101 | else if (strcmp(f, "!IPDST_RND") == 0) |
| 1102 | pkt_dev->flags &= ~F_IPDST_RND; |
| 1103 | |
| 1104 | else if (strcmp(f, "UDPSRC_RND") == 0) |
| 1105 | pkt_dev->flags |= F_UDPSRC_RND; |
| 1106 | |
| 1107 | else if (strcmp(f, "!UDPSRC_RND") == 0) |
| 1108 | pkt_dev->flags &= ~F_UDPSRC_RND; |
| 1109 | |
| 1110 | else if (strcmp(f, "UDPDST_RND") == 0) |
| 1111 | pkt_dev->flags |= F_UDPDST_RND; |
| 1112 | |
| 1113 | else if (strcmp(f, "!UDPDST_RND") == 0) |
| 1114 | pkt_dev->flags &= ~F_UDPDST_RND; |
| 1115 | |
| 1116 | else if (strcmp(f, "MACSRC_RND") == 0) |
| 1117 | pkt_dev->flags |= F_MACSRC_RND; |
| 1118 | |
| 1119 | else if (strcmp(f, "!MACSRC_RND") == 0) |
| 1120 | pkt_dev->flags &= ~F_MACSRC_RND; |
| 1121 | |
| 1122 | else if (strcmp(f, "MACDST_RND") == 0) |
| 1123 | pkt_dev->flags |= F_MACDST_RND; |
| 1124 | |
| 1125 | else if (strcmp(f, "!MACDST_RND") == 0) |
| 1126 | pkt_dev->flags &= ~F_MACDST_RND; |
| 1127 | |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 1128 | else if (strcmp(f, "MPLS_RND") == 0) |
| 1129 | pkt_dev->flags |= F_MPLS_RND; |
| 1130 | |
| 1131 | else if (strcmp(f, "!MPLS_RND") == 0) |
| 1132 | pkt_dev->flags &= ~F_MPLS_RND; |
| 1133 | |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 1134 | else if (strcmp(f, "VID_RND") == 0) |
| 1135 | pkt_dev->flags |= F_VID_RND; |
| 1136 | |
| 1137 | else if (strcmp(f, "!VID_RND") == 0) |
| 1138 | pkt_dev->flags &= ~F_VID_RND; |
| 1139 | |
| 1140 | else if (strcmp(f, "SVID_RND") == 0) |
| 1141 | pkt_dev->flags |= F_SVID_RND; |
| 1142 | |
| 1143 | else if (strcmp(f, "!SVID_RND") == 0) |
| 1144 | pkt_dev->flags &= ~F_SVID_RND; |
| 1145 | |
Jamal Hadi Salim | 007a531 | 2007-07-02 22:40:36 -0700 | [diff] [blame] | 1146 | else if (strcmp(f, "FLOW_SEQ") == 0) |
| 1147 | pkt_dev->flags |= F_FLOW_SEQ; |
| 1148 | |
Robert Olsson | 45b270f | 2007-08-28 15:45:55 -0700 | [diff] [blame] | 1149 | else if (strcmp(f, "QUEUE_MAP_RND") == 0) |
| 1150 | pkt_dev->flags |= F_QUEUE_MAP_RND; |
| 1151 | |
| 1152 | else if (strcmp(f, "!QUEUE_MAP_RND") == 0) |
| 1153 | pkt_dev->flags &= ~F_QUEUE_MAP_RND; |
Robert Olsson | e6fce5b | 2008-08-07 02:23:01 -0700 | [diff] [blame] | 1154 | |
| 1155 | else if (strcmp(f, "QUEUE_MAP_CPU") == 0) |
| 1156 | pkt_dev->flags |= F_QUEUE_MAP_CPU; |
| 1157 | |
| 1158 | else if (strcmp(f, "!QUEUE_MAP_CPU") == 0) |
| 1159 | pkt_dev->flags &= ~F_QUEUE_MAP_CPU; |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 1160 | #ifdef CONFIG_XFRM |
| 1161 | else if (strcmp(f, "IPSEC") == 0) |
| 1162 | pkt_dev->flags |= F_IPSEC_ON; |
| 1163 | #endif |
| 1164 | |
Francesco Fondelli | 1ca7768 | 2006-09-27 16:32:03 -0700 | [diff] [blame] | 1165 | else if (strcmp(f, "!IPV6") == 0) |
| 1166 | pkt_dev->flags &= ~F_IPV6; |
| 1167 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1168 | else { |
| 1169 | sprintf(pg_result, |
| 1170 | "Flag -:%s:- unknown\nAvailable flags, (prepend ! to un-set flag):\n%s", |
| 1171 | f, |
Francesco Fondelli | 1ca7768 | 2006-09-27 16:32:03 -0700 | [diff] [blame] | 1172 | "IPSRC_RND, IPDST_RND, UDPSRC_RND, UDPDST_RND, " |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 1173 | "MACSRC_RND, MACDST_RND, TXSIZE_RND, IPV6, MPLS_RND, VID_RND, SVID_RND, FLOW_SEQ, IPSEC\n"); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1174 | return count; |
| 1175 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | sprintf(pg_result, "OK: flags=0x%x", pkt_dev->flags); |
| 1177 | return count; |
| 1178 | } |
| 1179 | if (!strcmp(name, "dst_min") || !strcmp(name, "dst")) { |
| 1180 | len = strn_len(&user_buffer[i], sizeof(pkt_dev->dst_min) - 1); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1181 | if (len < 0) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1182 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1184 | if (copy_from_user(buf, &user_buffer[i], len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | return -EFAULT; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1186 | buf[len] = 0; |
| 1187 | if (strcmp(buf, pkt_dev->dst_min) != 0) { |
| 1188 | memset(pkt_dev->dst_min, 0, sizeof(pkt_dev->dst_min)); |
| 1189 | strncpy(pkt_dev->dst_min, buf, len); |
| 1190 | pkt_dev->daddr_min = in_aton(pkt_dev->dst_min); |
| 1191 | pkt_dev->cur_daddr = pkt_dev->daddr_min; |
| 1192 | } |
| 1193 | if (debug) |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 1194 | printk(KERN_DEBUG "pktgen: dst_min set to: %s\n", |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1195 | pkt_dev->dst_min); |
| 1196 | i += len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | sprintf(pg_result, "OK: dst_min=%s", pkt_dev->dst_min); |
| 1198 | return count; |
| 1199 | } |
| 1200 | if (!strcmp(name, "dst_max")) { |
| 1201 | len = strn_len(&user_buffer[i], sizeof(pkt_dev->dst_max) - 1); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1202 | if (len < 0) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1203 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1206 | if (copy_from_user(buf, &user_buffer[i], len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | return -EFAULT; |
| 1208 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1209 | buf[len] = 0; |
| 1210 | if (strcmp(buf, pkt_dev->dst_max) != 0) { |
| 1211 | memset(pkt_dev->dst_max, 0, sizeof(pkt_dev->dst_max)); |
| 1212 | strncpy(pkt_dev->dst_max, buf, len); |
| 1213 | pkt_dev->daddr_max = in_aton(pkt_dev->dst_max); |
| 1214 | pkt_dev->cur_daddr = pkt_dev->daddr_max; |
| 1215 | } |
| 1216 | if (debug) |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 1217 | printk(KERN_DEBUG "pktgen: dst_max set to: %s\n", |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1218 | pkt_dev->dst_max); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | i += len; |
| 1220 | sprintf(pg_result, "OK: dst_max=%s", pkt_dev->dst_max); |
| 1221 | return count; |
| 1222 | } |
| 1223 | if (!strcmp(name, "dst6")) { |
| 1224 | len = strn_len(&user_buffer[i], sizeof(buf) - 1); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1225 | if (len < 0) |
| 1226 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | |
| 1228 | pkt_dev->flags |= F_IPV6; |
| 1229 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1230 | if (copy_from_user(buf, &user_buffer[i], len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | return -EFAULT; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1232 | buf[len] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | |
| 1234 | scan_ip6(buf, pkt_dev->in6_daddr.s6_addr); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1235 | fmt_ip6(buf, pkt_dev->in6_daddr.s6_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | |
| 1237 | ipv6_addr_copy(&pkt_dev->cur_in6_daddr, &pkt_dev->in6_daddr); |
| 1238 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1239 | if (debug) |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 1240 | printk(KERN_DEBUG "pktgen: dst6 set to: %s\n", buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1242 | i += len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | sprintf(pg_result, "OK: dst6=%s", buf); |
| 1244 | return count; |
| 1245 | } |
| 1246 | if (!strcmp(name, "dst6_min")) { |
| 1247 | len = strn_len(&user_buffer[i], sizeof(buf) - 1); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1248 | if (len < 0) |
| 1249 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | |
| 1251 | pkt_dev->flags |= F_IPV6; |
| 1252 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1253 | if (copy_from_user(buf, &user_buffer[i], len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | return -EFAULT; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1255 | buf[len] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | |
| 1257 | scan_ip6(buf, pkt_dev->min_in6_daddr.s6_addr); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1258 | fmt_ip6(buf, pkt_dev->min_in6_daddr.s6_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1260 | ipv6_addr_copy(&pkt_dev->cur_in6_daddr, |
| 1261 | &pkt_dev->min_in6_daddr); |
| 1262 | if (debug) |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 1263 | printk(KERN_DEBUG "pktgen: dst6_min set to: %s\n", buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1265 | i += len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | sprintf(pg_result, "OK: dst6_min=%s", buf); |
| 1267 | return count; |
| 1268 | } |
| 1269 | if (!strcmp(name, "dst6_max")) { |
| 1270 | len = strn_len(&user_buffer[i], sizeof(buf) - 1); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1271 | if (len < 0) |
| 1272 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | |
| 1274 | pkt_dev->flags |= F_IPV6; |
| 1275 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1276 | if (copy_from_user(buf, &user_buffer[i], len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | return -EFAULT; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1278 | buf[len] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | |
| 1280 | scan_ip6(buf, pkt_dev->max_in6_daddr.s6_addr); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1281 | fmt_ip6(buf, pkt_dev->max_in6_daddr.s6_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1283 | if (debug) |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 1284 | printk(KERN_DEBUG "pktgen: dst6_max set to: %s\n", buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1286 | i += len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | sprintf(pg_result, "OK: dst6_max=%s", buf); |
| 1288 | return count; |
| 1289 | } |
| 1290 | if (!strcmp(name, "src6")) { |
| 1291 | len = strn_len(&user_buffer[i], sizeof(buf) - 1); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1292 | if (len < 0) |
| 1293 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | |
| 1295 | pkt_dev->flags |= F_IPV6; |
| 1296 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1297 | if (copy_from_user(buf, &user_buffer[i], len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | return -EFAULT; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1299 | buf[len] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | |
| 1301 | scan_ip6(buf, pkt_dev->in6_saddr.s6_addr); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1302 | fmt_ip6(buf, pkt_dev->in6_saddr.s6_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | |
| 1304 | ipv6_addr_copy(&pkt_dev->cur_in6_saddr, &pkt_dev->in6_saddr); |
| 1305 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1306 | if (debug) |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 1307 | printk(KERN_DEBUG "pktgen: src6 set to: %s\n", buf); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1308 | |
| 1309 | i += len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | sprintf(pg_result, "OK: src6=%s", buf); |
| 1311 | return count; |
| 1312 | } |
| 1313 | if (!strcmp(name, "src_min")) { |
| 1314 | len = strn_len(&user_buffer[i], sizeof(pkt_dev->src_min) - 1); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1315 | if (len < 0) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1316 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1317 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1318 | if (copy_from_user(buf, &user_buffer[i], len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | return -EFAULT; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1320 | buf[len] = 0; |
| 1321 | if (strcmp(buf, pkt_dev->src_min) != 0) { |
| 1322 | memset(pkt_dev->src_min, 0, sizeof(pkt_dev->src_min)); |
| 1323 | strncpy(pkt_dev->src_min, buf, len); |
| 1324 | pkt_dev->saddr_min = in_aton(pkt_dev->src_min); |
| 1325 | pkt_dev->cur_saddr = pkt_dev->saddr_min; |
| 1326 | } |
| 1327 | if (debug) |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 1328 | printk(KERN_DEBUG "pktgen: src_min set to: %s\n", |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1329 | pkt_dev->src_min); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | i += len; |
| 1331 | sprintf(pg_result, "OK: src_min=%s", pkt_dev->src_min); |
| 1332 | return count; |
| 1333 | } |
| 1334 | if (!strcmp(name, "src_max")) { |
| 1335 | len = strn_len(&user_buffer[i], sizeof(pkt_dev->src_max) - 1); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1336 | if (len < 0) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1337 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1338 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1339 | if (copy_from_user(buf, &user_buffer[i], len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | return -EFAULT; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1341 | buf[len] = 0; |
| 1342 | if (strcmp(buf, pkt_dev->src_max) != 0) { |
| 1343 | memset(pkt_dev->src_max, 0, sizeof(pkt_dev->src_max)); |
| 1344 | strncpy(pkt_dev->src_max, buf, len); |
| 1345 | pkt_dev->saddr_max = in_aton(pkt_dev->src_max); |
| 1346 | pkt_dev->cur_saddr = pkt_dev->saddr_max; |
| 1347 | } |
| 1348 | if (debug) |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 1349 | printk(KERN_DEBUG "pktgen: src_max set to: %s\n", |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1350 | pkt_dev->src_max); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | i += len; |
| 1352 | sprintf(pg_result, "OK: src_max=%s", pkt_dev->src_max); |
| 1353 | return count; |
| 1354 | } |
| 1355 | if (!strcmp(name, "dst_mac")) { |
| 1356 | char *v = valstr; |
Kris Katterjohn | f404e9a | 2006-01-17 13:04:57 -0800 | [diff] [blame] | 1357 | unsigned char old_dmac[ETH_ALEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | unsigned char *m = pkt_dev->dst_mac; |
Kris Katterjohn | f404e9a | 2006-01-17 13:04:57 -0800 | [diff] [blame] | 1359 | memcpy(old_dmac, pkt_dev->dst_mac, ETH_ALEN); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1360 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | len = strn_len(&user_buffer[i], sizeof(valstr) - 1); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1362 | if (len < 0) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1363 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | memset(valstr, 0, sizeof(valstr)); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1366 | if (copy_from_user(valstr, &user_buffer[i], len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | return -EFAULT; |
| 1368 | i += len; |
| 1369 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1370 | for (*m = 0; *v && m < pkt_dev->dst_mac + 6; v++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | if (*v >= '0' && *v <= '9') { |
| 1372 | *m *= 16; |
| 1373 | *m += *v - '0'; |
| 1374 | } |
| 1375 | if (*v >= 'A' && *v <= 'F') { |
| 1376 | *m *= 16; |
| 1377 | *m += *v - 'A' + 10; |
| 1378 | } |
| 1379 | if (*v >= 'a' && *v <= 'f') { |
| 1380 | *m *= 16; |
| 1381 | *m += *v - 'a' + 10; |
| 1382 | } |
| 1383 | if (*v == ':') { |
| 1384 | m++; |
| 1385 | *m = 0; |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | /* Set up Dest MAC */ |
Kris Katterjohn | f404e9a | 2006-01-17 13:04:57 -0800 | [diff] [blame] | 1390 | if (compare_ether_addr(old_dmac, pkt_dev->dst_mac)) |
| 1391 | memcpy(&(pkt_dev->hh[0]), pkt_dev->dst_mac, ETH_ALEN); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1392 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | sprintf(pg_result, "OK: dstmac"); |
| 1394 | return count; |
| 1395 | } |
| 1396 | if (!strcmp(name, "src_mac")) { |
| 1397 | char *v = valstr; |
Adit Ranadive | ce5d0b4 | 2007-09-16 14:52:15 -0700 | [diff] [blame] | 1398 | unsigned char old_smac[ETH_ALEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | unsigned char *m = pkt_dev->src_mac; |
| 1400 | |
Adit Ranadive | ce5d0b4 | 2007-09-16 14:52:15 -0700 | [diff] [blame] | 1401 | memcpy(old_smac, pkt_dev->src_mac, ETH_ALEN); |
| 1402 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | len = strn_len(&user_buffer[i], sizeof(valstr) - 1); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1404 | if (len < 0) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1405 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1406 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | memset(valstr, 0, sizeof(valstr)); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1408 | if (copy_from_user(valstr, &user_buffer[i], len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | return -EFAULT; |
| 1410 | i += len; |
| 1411 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1412 | for (*m = 0; *v && m < pkt_dev->src_mac + 6; v++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | if (*v >= '0' && *v <= '9') { |
| 1414 | *m *= 16; |
| 1415 | *m += *v - '0'; |
| 1416 | } |
| 1417 | if (*v >= 'A' && *v <= 'F') { |
| 1418 | *m *= 16; |
| 1419 | *m += *v - 'A' + 10; |
| 1420 | } |
| 1421 | if (*v >= 'a' && *v <= 'f') { |
| 1422 | *m *= 16; |
| 1423 | *m += *v - 'a' + 10; |
| 1424 | } |
| 1425 | if (*v == ':') { |
| 1426 | m++; |
| 1427 | *m = 0; |
| 1428 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1429 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | |
Adit Ranadive | ce5d0b4 | 2007-09-16 14:52:15 -0700 | [diff] [blame] | 1431 | /* Set up Src MAC */ |
| 1432 | if (compare_ether_addr(old_smac, pkt_dev->src_mac)) |
| 1433 | memcpy(&(pkt_dev->hh[6]), pkt_dev->src_mac, ETH_ALEN); |
| 1434 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1435 | sprintf(pg_result, "OK: srcmac"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | return count; |
| 1437 | } |
| 1438 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1439 | if (!strcmp(name, "clear_counters")) { |
| 1440 | pktgen_clear_counters(pkt_dev); |
| 1441 | sprintf(pg_result, "OK: Clearing counters.\n"); |
| 1442 | return count; |
| 1443 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | |
| 1445 | if (!strcmp(name, "flows")) { |
| 1446 | len = num_arg(&user_buffer[i], 10, &value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1447 | if (len < 0) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1448 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1449 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | i += len; |
| 1451 | if (value > MAX_CFLOWS) |
| 1452 | value = MAX_CFLOWS; |
| 1453 | |
| 1454 | pkt_dev->cflows = value; |
| 1455 | sprintf(pg_result, "OK: flows=%u", pkt_dev->cflows); |
| 1456 | return count; |
| 1457 | } |
| 1458 | |
| 1459 | if (!strcmp(name, "flowlen")) { |
| 1460 | len = num_arg(&user_buffer[i], 10, &value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1461 | if (len < 0) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1462 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | i += len; |
| 1465 | pkt_dev->lflow = value; |
| 1466 | sprintf(pg_result, "OK: flowlen=%u", pkt_dev->lflow); |
| 1467 | return count; |
| 1468 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1469 | |
Robert Olsson | 45b270f | 2007-08-28 15:45:55 -0700 | [diff] [blame] | 1470 | if (!strcmp(name, "queue_map_min")) { |
| 1471 | len = num_arg(&user_buffer[i], 5, &value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1472 | if (len < 0) |
Robert Olsson | 45b270f | 2007-08-28 15:45:55 -0700 | [diff] [blame] | 1473 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1474 | |
Robert Olsson | 45b270f | 2007-08-28 15:45:55 -0700 | [diff] [blame] | 1475 | i += len; |
| 1476 | pkt_dev->queue_map_min = value; |
| 1477 | sprintf(pg_result, "OK: queue_map_min=%u", pkt_dev->queue_map_min); |
| 1478 | return count; |
| 1479 | } |
| 1480 | |
| 1481 | if (!strcmp(name, "queue_map_max")) { |
| 1482 | len = num_arg(&user_buffer[i], 5, &value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1483 | if (len < 0) |
Robert Olsson | 45b270f | 2007-08-28 15:45:55 -0700 | [diff] [blame] | 1484 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1485 | |
Robert Olsson | 45b270f | 2007-08-28 15:45:55 -0700 | [diff] [blame] | 1486 | i += len; |
| 1487 | pkt_dev->queue_map_max = value; |
| 1488 | sprintf(pg_result, "OK: queue_map_max=%u", pkt_dev->queue_map_max); |
| 1489 | return count; |
| 1490 | } |
| 1491 | |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 1492 | if (!strcmp(name, "mpls")) { |
Stephen Hemminger | cfcabdc | 2007-10-09 01:59:42 -0700 | [diff] [blame] | 1493 | unsigned n, cnt; |
| 1494 | |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 1495 | len = get_labels(&user_buffer[i], pkt_dev); |
Stephen Hemminger | cfcabdc | 2007-10-09 01:59:42 -0700 | [diff] [blame] | 1496 | if (len < 0) |
| 1497 | return len; |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 1498 | i += len; |
Stephen Hemminger | cfcabdc | 2007-10-09 01:59:42 -0700 | [diff] [blame] | 1499 | cnt = sprintf(pg_result, "OK: mpls="); |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1500 | for (n = 0; n < pkt_dev->nr_labels; n++) |
Stephen Hemminger | cfcabdc | 2007-10-09 01:59:42 -0700 | [diff] [blame] | 1501 | cnt += sprintf(pg_result + cnt, |
| 1502 | "%08x%s", ntohl(pkt_dev->labels[n]), |
| 1503 | n == pkt_dev->nr_labels-1 ? "" : ","); |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 1504 | |
| 1505 | if (pkt_dev->nr_labels && pkt_dev->vlan_id != 0xffff) { |
| 1506 | pkt_dev->vlan_id = 0xffff; /* turn off VLAN/SVLAN */ |
| 1507 | pkt_dev->svlan_id = 0xffff; |
| 1508 | |
| 1509 | if (debug) |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 1510 | printk(KERN_DEBUG "pktgen: VLAN/SVLAN auto turned off\n"); |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 1511 | } |
| 1512 | return count; |
| 1513 | } |
| 1514 | |
| 1515 | if (!strcmp(name, "vlan_id")) { |
| 1516 | len = num_arg(&user_buffer[i], 4, &value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1517 | if (len < 0) |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 1518 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1519 | |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 1520 | i += len; |
| 1521 | if (value <= 4095) { |
| 1522 | pkt_dev->vlan_id = value; /* turn on VLAN */ |
| 1523 | |
| 1524 | if (debug) |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 1525 | printk(KERN_DEBUG "pktgen: VLAN turned on\n"); |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 1526 | |
| 1527 | if (debug && pkt_dev->nr_labels) |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 1528 | printk(KERN_DEBUG "pktgen: MPLS auto turned off\n"); |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 1529 | |
| 1530 | pkt_dev->nr_labels = 0; /* turn off MPLS */ |
| 1531 | sprintf(pg_result, "OK: vlan_id=%u", pkt_dev->vlan_id); |
| 1532 | } else { |
| 1533 | pkt_dev->vlan_id = 0xffff; /* turn off VLAN/SVLAN */ |
| 1534 | pkt_dev->svlan_id = 0xffff; |
| 1535 | |
| 1536 | if (debug) |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 1537 | printk(KERN_DEBUG "pktgen: VLAN/SVLAN turned off\n"); |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 1538 | } |
| 1539 | return count; |
| 1540 | } |
| 1541 | |
| 1542 | if (!strcmp(name, "vlan_p")) { |
| 1543 | len = num_arg(&user_buffer[i], 1, &value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1544 | if (len < 0) |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 1545 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1546 | |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 1547 | i += len; |
| 1548 | if ((value <= 7) && (pkt_dev->vlan_id != 0xffff)) { |
| 1549 | pkt_dev->vlan_p = value; |
| 1550 | sprintf(pg_result, "OK: vlan_p=%u", pkt_dev->vlan_p); |
| 1551 | } else { |
| 1552 | sprintf(pg_result, "ERROR: vlan_p must be 0-7"); |
| 1553 | } |
| 1554 | return count; |
| 1555 | } |
| 1556 | |
| 1557 | if (!strcmp(name, "vlan_cfi")) { |
| 1558 | len = num_arg(&user_buffer[i], 1, &value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1559 | if (len < 0) |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 1560 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1561 | |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 1562 | i += len; |
| 1563 | if ((value <= 1) && (pkt_dev->vlan_id != 0xffff)) { |
| 1564 | pkt_dev->vlan_cfi = value; |
| 1565 | sprintf(pg_result, "OK: vlan_cfi=%u", pkt_dev->vlan_cfi); |
| 1566 | } else { |
| 1567 | sprintf(pg_result, "ERROR: vlan_cfi must be 0-1"); |
| 1568 | } |
| 1569 | return count; |
| 1570 | } |
| 1571 | |
| 1572 | if (!strcmp(name, "svlan_id")) { |
| 1573 | len = num_arg(&user_buffer[i], 4, &value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1574 | if (len < 0) |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 1575 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1576 | |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 1577 | i += len; |
| 1578 | if ((value <= 4095) && ((pkt_dev->vlan_id != 0xffff))) { |
| 1579 | pkt_dev->svlan_id = value; /* turn on SVLAN */ |
| 1580 | |
| 1581 | if (debug) |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 1582 | printk(KERN_DEBUG "pktgen: SVLAN turned on\n"); |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 1583 | |
| 1584 | if (debug && pkt_dev->nr_labels) |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 1585 | printk(KERN_DEBUG "pktgen: MPLS auto turned off\n"); |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 1586 | |
| 1587 | pkt_dev->nr_labels = 0; /* turn off MPLS */ |
| 1588 | sprintf(pg_result, "OK: svlan_id=%u", pkt_dev->svlan_id); |
| 1589 | } else { |
| 1590 | pkt_dev->vlan_id = 0xffff; /* turn off VLAN/SVLAN */ |
| 1591 | pkt_dev->svlan_id = 0xffff; |
| 1592 | |
| 1593 | if (debug) |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 1594 | printk(KERN_DEBUG "pktgen: VLAN/SVLAN turned off\n"); |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 1595 | } |
| 1596 | return count; |
| 1597 | } |
| 1598 | |
| 1599 | if (!strcmp(name, "svlan_p")) { |
| 1600 | len = num_arg(&user_buffer[i], 1, &value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1601 | if (len < 0) |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 1602 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1603 | |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 1604 | i += len; |
| 1605 | if ((value <= 7) && (pkt_dev->svlan_id != 0xffff)) { |
| 1606 | pkt_dev->svlan_p = value; |
| 1607 | sprintf(pg_result, "OK: svlan_p=%u", pkt_dev->svlan_p); |
| 1608 | } else { |
| 1609 | sprintf(pg_result, "ERROR: svlan_p must be 0-7"); |
| 1610 | } |
| 1611 | return count; |
| 1612 | } |
| 1613 | |
| 1614 | if (!strcmp(name, "svlan_cfi")) { |
| 1615 | len = num_arg(&user_buffer[i], 1, &value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1616 | if (len < 0) |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 1617 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1618 | |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 1619 | i += len; |
| 1620 | if ((value <= 1) && (pkt_dev->svlan_id != 0xffff)) { |
| 1621 | pkt_dev->svlan_cfi = value; |
| 1622 | sprintf(pg_result, "OK: svlan_cfi=%u", pkt_dev->svlan_cfi); |
| 1623 | } else { |
| 1624 | sprintf(pg_result, "ERROR: svlan_cfi must be 0-1"); |
| 1625 | } |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 1626 | return count; |
| 1627 | } |
| 1628 | |
Francesco Fondelli | 1ca7768 | 2006-09-27 16:32:03 -0700 | [diff] [blame] | 1629 | if (!strcmp(name, "tos")) { |
| 1630 | __u32 tmp_value = 0; |
| 1631 | len = hex32_arg(&user_buffer[i], 2, &tmp_value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1632 | if (len < 0) |
Francesco Fondelli | 1ca7768 | 2006-09-27 16:32:03 -0700 | [diff] [blame] | 1633 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1634 | |
Francesco Fondelli | 1ca7768 | 2006-09-27 16:32:03 -0700 | [diff] [blame] | 1635 | i += len; |
| 1636 | if (len == 2) { |
| 1637 | pkt_dev->tos = tmp_value; |
| 1638 | sprintf(pg_result, "OK: tos=0x%02x", pkt_dev->tos); |
| 1639 | } else { |
| 1640 | sprintf(pg_result, "ERROR: tos must be 00-ff"); |
| 1641 | } |
| 1642 | return count; |
| 1643 | } |
| 1644 | |
| 1645 | if (!strcmp(name, "traffic_class")) { |
| 1646 | __u32 tmp_value = 0; |
| 1647 | len = hex32_arg(&user_buffer[i], 2, &tmp_value); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1648 | if (len < 0) |
Francesco Fondelli | 1ca7768 | 2006-09-27 16:32:03 -0700 | [diff] [blame] | 1649 | return len; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1650 | |
Francesco Fondelli | 1ca7768 | 2006-09-27 16:32:03 -0700 | [diff] [blame] | 1651 | i += len; |
| 1652 | if (len == 2) { |
| 1653 | pkt_dev->traffic_class = tmp_value; |
| 1654 | sprintf(pg_result, "OK: traffic_class=0x%02x", pkt_dev->traffic_class); |
| 1655 | } else { |
| 1656 | sprintf(pg_result, "ERROR: traffic_class must be 00-ff"); |
| 1657 | } |
| 1658 | return count; |
| 1659 | } |
| 1660 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | sprintf(pkt_dev->result, "No such parameter \"%s\"", name); |
| 1662 | return -EINVAL; |
| 1663 | } |
| 1664 | |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 1665 | static int pktgen_if_open(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1666 | { |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 1667 | return single_open(file, pktgen_if_show, PDE(inode)->data); |
| 1668 | } |
| 1669 | |
Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 1670 | static const struct file_operations pktgen_if_fops = { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1671 | .owner = THIS_MODULE, |
| 1672 | .open = pktgen_if_open, |
| 1673 | .read = seq_read, |
| 1674 | .llseek = seq_lseek, |
| 1675 | .write = pktgen_if_write, |
| 1676 | .release = single_release, |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 1677 | }; |
| 1678 | |
| 1679 | static int pktgen_thread_show(struct seq_file *seq, void *v) |
| 1680 | { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1681 | struct pktgen_thread *t = seq->private; |
Stephen Hemminger | 648fda7 | 2009-08-27 13:55:07 +0000 | [diff] [blame] | 1682 | const struct pktgen_dev *pkt_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 1684 | BUG_ON(!t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1686 | seq_printf(seq, "Running: "); |
| 1687 | |
| 1688 | if_lock(t); |
Luiz Capitulino | c26a801 | 2006-03-20 22:18:16 -0800 | [diff] [blame] | 1689 | list_for_each_entry(pkt_dev, &t->if_list, list) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1690 | if (pkt_dev->running) |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 1691 | seq_printf(seq, "%s ", pkt_dev->odev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1693 | seq_printf(seq, "\nStopped: "); |
| 1694 | |
Luiz Capitulino | c26a801 | 2006-03-20 22:18:16 -0800 | [diff] [blame] | 1695 | list_for_each_entry(pkt_dev, &t->if_list, list) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1696 | if (!pkt_dev->running) |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 1697 | seq_printf(seq, "%s ", pkt_dev->odev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | |
| 1699 | if (t->result[0]) |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 1700 | seq_printf(seq, "\nResult: %s\n", t->result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | else |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 1702 | seq_printf(seq, "\nResult: NA\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1704 | if_unlock(t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 1706 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | } |
| 1708 | |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 1709 | static ssize_t pktgen_thread_write(struct file *file, |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1710 | const char __user * user_buffer, |
| 1711 | size_t count, loff_t * offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1713 | struct seq_file *seq = (struct seq_file *)file->private_data; |
| 1714 | struct pktgen_thread *t = seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | int i = 0, max, len, ret; |
| 1716 | char name[40]; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1717 | char *pg_result; |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 1718 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | if (count < 1) { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1720 | // sprintf(pg_result, "Wrong command format"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | return -EINVAL; |
| 1722 | } |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 1723 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | max = count - i; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1725 | len = count_trail_chars(&user_buffer[i], max); |
| 1726 | if (len < 0) |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 1727 | return len; |
| 1728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | i += len; |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 1730 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | /* Read variable name */ |
| 1732 | |
| 1733 | len = strn_len(&user_buffer[i], sizeof(name) - 1); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1734 | if (len < 0) |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 1735 | return len; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1736 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | memset(name, 0, sizeof(name)); |
| 1738 | if (copy_from_user(name, &user_buffer[i], len)) |
| 1739 | return -EFAULT; |
| 1740 | i += len; |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 1741 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1742 | max = count - i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | len = count_trail_chars(&user_buffer[i], max); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1744 | if (len < 0) |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 1745 | return len; |
| 1746 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | i += len; |
| 1748 | |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 1749 | if (debug) |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 1750 | printk(KERN_DEBUG "pktgen: t=%s, count=%lu\n", |
| 1751 | name, (unsigned long)count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1753 | if (!t) { |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 1754 | printk(KERN_ERR "pktgen: ERROR: No thread\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | ret = -EINVAL; |
| 1756 | goto out; |
| 1757 | } |
| 1758 | |
| 1759 | pg_result = &(t->result[0]); |
| 1760 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1761 | if (!strcmp(name, "add_device")) { |
| 1762 | char f[32]; |
| 1763 | memset(f, 0, 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1764 | len = strn_len(&user_buffer[i], sizeof(f) - 1); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1765 | if (len < 0) { |
| 1766 | ret = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1767 | goto out; |
| 1768 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1769 | if (copy_from_user(f, &user_buffer[i], len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | return -EFAULT; |
| 1771 | i += len; |
Luiz Capitulino | 6146e6a | 2006-03-20 22:24:45 -0800 | [diff] [blame] | 1772 | mutex_lock(&pktgen_thread_lock); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1773 | pktgen_add_device(t, f); |
Luiz Capitulino | 6146e6a | 2006-03-20 22:24:45 -0800 | [diff] [blame] | 1774 | mutex_unlock(&pktgen_thread_lock); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1775 | ret = count; |
| 1776 | sprintf(pg_result, "OK: add_device=%s", f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | goto out; |
| 1778 | } |
| 1779 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1780 | if (!strcmp(name, "rem_device_all")) { |
Luiz Capitulino | 6146e6a | 2006-03-20 22:24:45 -0800 | [diff] [blame] | 1781 | mutex_lock(&pktgen_thread_lock); |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 1782 | t->control |= T_REMDEVALL; |
Luiz Capitulino | 6146e6a | 2006-03-20 22:24:45 -0800 | [diff] [blame] | 1783 | mutex_unlock(&pktgen_thread_lock); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1784 | schedule_timeout_interruptible(msecs_to_jiffies(125)); /* Propagate thread->control */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | ret = count; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1786 | sprintf(pg_result, "OK: rem_device_all"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | goto out; |
| 1788 | } |
| 1789 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1790 | if (!strcmp(name, "max_before_softirq")) { |
Robert Olsson | b163911 | 2007-08-28 15:46:58 -0700 | [diff] [blame] | 1791 | sprintf(pg_result, "OK: Note! max_before_softirq is obsoleted -- Do not use"); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1792 | ret = count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | goto out; |
| 1794 | } |
| 1795 | |
| 1796 | ret = -EINVAL; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1797 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | return ret; |
| 1799 | } |
| 1800 | |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 1801 | static int pktgen_thread_open(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | { |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 1803 | return single_open(file, pktgen_thread_show, PDE(inode)->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | } |
| 1805 | |
Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 1806 | static const struct file_operations pktgen_thread_fops = { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1807 | .owner = THIS_MODULE, |
| 1808 | .open = pktgen_thread_open, |
| 1809 | .read = seq_read, |
| 1810 | .llseek = seq_lseek, |
| 1811 | .write = pktgen_thread_write, |
| 1812 | .release = single_release, |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 1813 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | |
| 1815 | /* Think find or remove for NN */ |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1816 | static struct pktgen_dev *__pktgen_NN_threads(const char *ifname, int remove) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | { |
| 1818 | struct pktgen_thread *t; |
| 1819 | struct pktgen_dev *pkt_dev = NULL; |
| 1820 | |
Luiz Capitulino | cdcdbe0 | 2006-03-20 22:16:40 -0800 | [diff] [blame] | 1821 | list_for_each_entry(t, &pktgen_threads, th_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | pkt_dev = pktgen_find_dev(t, ifname); |
| 1823 | if (pkt_dev) { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1824 | if (remove) { |
| 1825 | if_lock(t); |
| 1826 | pkt_dev->removal_mark = 1; |
| 1827 | t->control |= T_REMDEV; |
| 1828 | if_unlock(t); |
| 1829 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | break; |
| 1831 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1833 | return pkt_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | } |
| 1835 | |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 1836 | /* |
| 1837 | * mark a device for removal |
| 1838 | */ |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 1839 | static void pktgen_mark_device(const char *ifname) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | { |
| 1841 | struct pktgen_dev *pkt_dev = NULL; |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 1842 | const int max_tries = 10, msec_per_try = 125; |
| 1843 | int i = 0; |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 1844 | |
Luiz Capitulino | 6146e6a | 2006-03-20 22:24:45 -0800 | [diff] [blame] | 1845 | mutex_lock(&pktgen_thread_lock); |
Stephen Hemminger | 25c4e53 | 2007-03-04 16:06:47 -0800 | [diff] [blame] | 1846 | pr_debug("pktgen: pktgen_mark_device marking %s for removal\n", ifname); |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 1847 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1848 | while (1) { |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 1849 | |
| 1850 | pkt_dev = __pktgen_NN_threads(ifname, REMOVE); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1851 | if (pkt_dev == NULL) |
| 1852 | break; /* success */ |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 1853 | |
Luiz Capitulino | 6146e6a | 2006-03-20 22:24:45 -0800 | [diff] [blame] | 1854 | mutex_unlock(&pktgen_thread_lock); |
Stephen Hemminger | 25c4e53 | 2007-03-04 16:06:47 -0800 | [diff] [blame] | 1855 | pr_debug("pktgen: pktgen_mark_device waiting for %s " |
| 1856 | "to disappear....\n", ifname); |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 1857 | schedule_timeout_interruptible(msecs_to_jiffies(msec_per_try)); |
Luiz Capitulino | 6146e6a | 2006-03-20 22:24:45 -0800 | [diff] [blame] | 1858 | mutex_lock(&pktgen_thread_lock); |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 1859 | |
| 1860 | if (++i >= max_tries) { |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 1861 | printk(KERN_ERR "pktgen_mark_device: timed out after " |
| 1862 | "waiting %d msec for device %s to be removed\n", |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1863 | msec_per_try * i, ifname); |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 1864 | break; |
| 1865 | } |
| 1866 | |
| 1867 | } |
| 1868 | |
Luiz Capitulino | 6146e6a | 2006-03-20 22:24:45 -0800 | [diff] [blame] | 1869 | mutex_unlock(&pktgen_thread_lock); |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 1870 | } |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 1871 | |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 1872 | static void pktgen_change_name(struct net_device *dev) |
| 1873 | { |
| 1874 | struct pktgen_thread *t; |
| 1875 | |
| 1876 | list_for_each_entry(t, &pktgen_threads, th_list) { |
| 1877 | struct pktgen_dev *pkt_dev; |
| 1878 | |
| 1879 | list_for_each_entry(pkt_dev, &t->if_list, list) { |
| 1880 | if (pkt_dev->odev != dev) |
| 1881 | continue; |
| 1882 | |
| 1883 | remove_proc_entry(pkt_dev->entry->name, pg_proc_dir); |
| 1884 | |
Alexey Dobriyan | 2975315 | 2009-08-28 23:34:43 -0700 | [diff] [blame] | 1885 | pkt_dev->entry = proc_create_data(dev->name, 0600, |
| 1886 | pg_proc_dir, |
| 1887 | &pktgen_if_fops, |
| 1888 | pkt_dev); |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 1889 | if (!pkt_dev->entry) |
| 1890 | printk(KERN_ERR "pktgen: can't move proc " |
| 1891 | " entry for '%s'\n", dev->name); |
| 1892 | break; |
| 1893 | } |
| 1894 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | } |
| 1896 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1897 | static int pktgen_device_event(struct notifier_block *unused, |
| 1898 | unsigned long event, void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | { |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 1900 | struct net_device *dev = ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | |
YOSHIFUJI Hideaki | 721499e | 2008-07-19 22:34:43 -0700 | [diff] [blame] | 1902 | if (!net_eq(dev_net(dev), &init_net)) |
Eric W. Biederman | e9dc865 | 2007-09-12 13:02:17 +0200 | [diff] [blame] | 1903 | return NOTIFY_DONE; |
| 1904 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | /* It is OK that we do not hold the group lock right now, |
| 1906 | * as we run under the RTNL lock. |
| 1907 | */ |
| 1908 | |
| 1909 | switch (event) { |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 1910 | case NETDEV_CHANGENAME: |
| 1911 | pktgen_change_name(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | break; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1913 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | case NETDEV_UNREGISTER: |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1915 | pktgen_mark_device(dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | break; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 1917 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | |
| 1919 | return NOTIFY_DONE; |
| 1920 | } |
| 1921 | |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1922 | static struct net_device *pktgen_dev_get_by_name(struct pktgen_dev *pkt_dev, |
| 1923 | const char *ifname) |
Robert Olsson | e6fce5b | 2008-08-07 02:23:01 -0700 | [diff] [blame] | 1924 | { |
| 1925 | char b[IFNAMSIZ+5]; |
| 1926 | int i = 0; |
| 1927 | |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1928 | for (i = 0; ifname[i] != '@'; i++) { |
| 1929 | if (i == IFNAMSIZ) |
Robert Olsson | e6fce5b | 2008-08-07 02:23:01 -0700 | [diff] [blame] | 1930 | break; |
| 1931 | |
| 1932 | b[i] = ifname[i]; |
| 1933 | } |
| 1934 | b[i] = 0; |
| 1935 | |
| 1936 | return dev_get_by_name(&init_net, b); |
| 1937 | } |
| 1938 | |
| 1939 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | /* Associate pktgen_dev with a device. */ |
| 1941 | |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 1942 | static int pktgen_setup_dev(struct pktgen_dev *pkt_dev, const char *ifname) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1943 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | struct net_device *odev; |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 1945 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | |
| 1947 | /* Clean old setups */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | if (pkt_dev->odev) { |
| 1949 | dev_put(pkt_dev->odev); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1950 | pkt_dev->odev = NULL; |
| 1951 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | |
Robert Olsson | e6fce5b | 2008-08-07 02:23:01 -0700 | [diff] [blame] | 1953 | odev = pktgen_dev_get_by_name(pkt_dev, ifname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1954 | if (!odev) { |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 1955 | printk(KERN_ERR "pktgen: no such netdevice: \"%s\"\n", ifname); |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 1956 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | } |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 1958 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1959 | if (odev->type != ARPHRD_ETHER) { |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 1960 | printk(KERN_ERR "pktgen: not an ethernet device: \"%s\"\n", ifname); |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 1961 | err = -EINVAL; |
| 1962 | } else if (!netif_running(odev)) { |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 1963 | printk(KERN_ERR "pktgen: device is down: \"%s\"\n", ifname); |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 1964 | err = -ENETDOWN; |
| 1965 | } else { |
| 1966 | pkt_dev->odev = odev; |
| 1967 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1969 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | dev_put(odev); |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 1971 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | } |
| 1973 | |
| 1974 | /* Read pkt_dev from the interface and set up internal pktgen_dev |
| 1975 | * structure to have the right information to create/send packets |
| 1976 | */ |
| 1977 | static void pktgen_setup_inject(struct pktgen_dev *pkt_dev) |
| 1978 | { |
Andrew Gallatin | 64c00d8 | 2008-08-13 15:16:00 -0700 | [diff] [blame] | 1979 | int ntxq; |
| 1980 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1981 | if (!pkt_dev->odev) { |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 1982 | printk(KERN_ERR "pktgen: ERROR: pkt_dev->odev == NULL in " |
| 1983 | "setup_inject.\n"); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 1984 | sprintf(pkt_dev->result, |
| 1985 | "ERROR: pkt_dev->odev == NULL in setup_inject.\n"); |
| 1986 | return; |
| 1987 | } |
| 1988 | |
Andrew Gallatin | 64c00d8 | 2008-08-13 15:16:00 -0700 | [diff] [blame] | 1989 | /* make sure that we don't pick a non-existing transmit queue */ |
| 1990 | ntxq = pkt_dev->odev->real_num_tx_queues; |
Robert Olsson | bfdbc0a | 2008-11-19 14:09:47 -0800 | [diff] [blame] | 1991 | |
Andrew Gallatin | 64c00d8 | 2008-08-13 15:16:00 -0700 | [diff] [blame] | 1992 | if (ntxq <= pkt_dev->queue_map_min) { |
| 1993 | printk(KERN_WARNING "pktgen: WARNING: Requested " |
Jesse Brandeburg | 8827166 | 2008-10-28 13:21:51 -0700 | [diff] [blame] | 1994 | "queue_map_min (zero-based) (%d) exceeds valid range " |
| 1995 | "[0 - %d] for (%d) queues on %s, resetting\n", |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 1996 | pkt_dev->queue_map_min, (ntxq ?: 1) - 1, ntxq, |
Jesse Brandeburg | 8827166 | 2008-10-28 13:21:51 -0700 | [diff] [blame] | 1997 | pkt_dev->odev->name); |
Andrew Gallatin | 64c00d8 | 2008-08-13 15:16:00 -0700 | [diff] [blame] | 1998 | pkt_dev->queue_map_min = ntxq - 1; |
| 1999 | } |
Jesse Brandeburg | 8827166 | 2008-10-28 13:21:51 -0700 | [diff] [blame] | 2000 | if (pkt_dev->queue_map_max >= ntxq) { |
Andrew Gallatin | 64c00d8 | 2008-08-13 15:16:00 -0700 | [diff] [blame] | 2001 | printk(KERN_WARNING "pktgen: WARNING: Requested " |
Jesse Brandeburg | 8827166 | 2008-10-28 13:21:51 -0700 | [diff] [blame] | 2002 | "queue_map_max (zero-based) (%d) exceeds valid range " |
| 2003 | "[0 - %d] for (%d) queues on %s, resetting\n", |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 2004 | pkt_dev->queue_map_max, (ntxq ?: 1) - 1, ntxq, |
Jesse Brandeburg | 8827166 | 2008-10-28 13:21:51 -0700 | [diff] [blame] | 2005 | pkt_dev->odev->name); |
Andrew Gallatin | 64c00d8 | 2008-08-13 15:16:00 -0700 | [diff] [blame] | 2006 | pkt_dev->queue_map_max = ntxq - 1; |
| 2007 | } |
| 2008 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2009 | /* Default to the interface's mac if not explicitly set. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | |
Kris Katterjohn | f404e9a | 2006-01-17 13:04:57 -0800 | [diff] [blame] | 2011 | if (is_zero_ether_addr(pkt_dev->src_mac)) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2012 | memcpy(&(pkt_dev->hh[6]), pkt_dev->odev->dev_addr, ETH_ALEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2014 | /* Set up Dest MAC */ |
Kris Katterjohn | f404e9a | 2006-01-17 13:04:57 -0800 | [diff] [blame] | 2015 | memcpy(&(pkt_dev->hh[0]), pkt_dev->dst_mac, ETH_ALEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2017 | /* Set up pkt size */ |
| 2018 | pkt_dev->cur_pkt_size = pkt_dev->min_pkt_size; |
| 2019 | |
| 2020 | if (pkt_dev->flags & F_IPV6) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | /* |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 2022 | * Skip this automatic address setting until locks or functions |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | * gets exported |
| 2024 | */ |
| 2025 | |
| 2026 | #ifdef NOTNOW |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2027 | int i, set = 0, err = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | struct inet6_dev *idev; |
| 2029 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2030 | for (i = 0; i < IN6_ADDR_HSIZE; i++) |
| 2031 | if (pkt_dev->cur_in6_saddr.s6_addr[i]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2032 | set = 1; |
| 2033 | break; |
| 2034 | } |
| 2035 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2036 | if (!set) { |
| 2037 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | /* |
| 2039 | * Use linklevel address if unconfigured. |
| 2040 | * |
| 2041 | * use ipv6_get_lladdr if/when it's get exported |
| 2042 | */ |
| 2043 | |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 2044 | rcu_read_lock(); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 2045 | idev = __in6_dev_get(pkt_dev->odev); |
| 2046 | if (idev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | struct inet6_ifaddr *ifp; |
| 2048 | |
| 2049 | read_lock_bh(&idev->lock); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2050 | for (ifp = idev->addr_list; ifp; |
| 2051 | ifp = ifp->if_next) { |
| 2052 | if (ifp->scope == IFA_LINK |
| 2053 | && !(ifp-> |
| 2054 | flags & IFA_F_TENTATIVE)) { |
| 2055 | ipv6_addr_copy(&pkt_dev-> |
| 2056 | cur_in6_saddr, |
| 2057 | &ifp->addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2058 | err = 0; |
| 2059 | break; |
| 2060 | } |
| 2061 | } |
| 2062 | read_unlock_bh(&idev->lock); |
| 2063 | } |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 2064 | rcu_read_unlock(); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2065 | if (err) |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 2066 | printk(KERN_ERR "pktgen: ERROR: IPv6 link " |
| 2067 | "address not availble.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2068 | } |
| 2069 | #endif |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2070 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | pkt_dev->saddr_min = 0; |
| 2072 | pkt_dev->saddr_max = 0; |
| 2073 | if (strlen(pkt_dev->src_min) == 0) { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2074 | |
| 2075 | struct in_device *in_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | |
| 2077 | rcu_read_lock(); |
Herbert Xu | e5ed639 | 2005-10-03 14:35:55 -0700 | [diff] [blame] | 2078 | in_dev = __in_dev_get_rcu(pkt_dev->odev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | if (in_dev) { |
| 2080 | if (in_dev->ifa_list) { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2081 | pkt_dev->saddr_min = |
| 2082 | in_dev->ifa_list->ifa_address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | pkt_dev->saddr_max = pkt_dev->saddr_min; |
| 2084 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | } |
| 2086 | rcu_read_unlock(); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2087 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2088 | pkt_dev->saddr_min = in_aton(pkt_dev->src_min); |
| 2089 | pkt_dev->saddr_max = in_aton(pkt_dev->src_max); |
| 2090 | } |
| 2091 | |
| 2092 | pkt_dev->daddr_min = in_aton(pkt_dev->dst_min); |
| 2093 | pkt_dev->daddr_max = in_aton(pkt_dev->dst_max); |
| 2094 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2095 | /* Initialize current values. */ |
| 2096 | pkt_dev->cur_dst_mac_offset = 0; |
| 2097 | pkt_dev->cur_src_mac_offset = 0; |
| 2098 | pkt_dev->cur_saddr = pkt_dev->saddr_min; |
| 2099 | pkt_dev->cur_daddr = pkt_dev->daddr_min; |
| 2100 | pkt_dev->cur_udp_dst = pkt_dev->udp_dst_min; |
| 2101 | pkt_dev->cur_udp_src = pkt_dev->udp_src_min; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | pkt_dev->nflows = 0; |
| 2103 | } |
| 2104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 2106 | static void spin(struct pktgen_dev *pkt_dev, ktime_t spin_until) |
| 2107 | { |
Stephen Hemminger | ef87979 | 2009-09-22 19:41:43 +0000 | [diff] [blame] | 2108 | ktime_t start_time, end_time; |
Eric Dumazet | 417bc4b | 2009-10-01 09:29:45 -0700 | [diff] [blame] | 2109 | s64 remaining; |
Stephen Hemminger | 2bc481c | 2009-08-28 23:41:29 -0700 | [diff] [blame] | 2110 | struct hrtimer_sleeper t; |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 2111 | |
Stephen Hemminger | 2bc481c | 2009-08-28 23:41:29 -0700 | [diff] [blame] | 2112 | hrtimer_init_on_stack(&t.timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); |
| 2113 | hrtimer_set_expires(&t.timer, spin_until); |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 2114 | |
Stephen Hemminger | 2bc481c | 2009-08-28 23:41:29 -0700 | [diff] [blame] | 2115 | remaining = ktime_to_us(hrtimer_expires_remaining(&t.timer)); |
Eric Dumazet | 417bc4b | 2009-10-01 09:29:45 -0700 | [diff] [blame] | 2116 | if (remaining <= 0) { |
| 2117 | pkt_dev->next_tx = ktime_add_ns(spin_until, pkt_dev->delay); |
Stephen Hemminger | 2bc481c | 2009-08-28 23:41:29 -0700 | [diff] [blame] | 2118 | return; |
Eric Dumazet | 417bc4b | 2009-10-01 09:29:45 -0700 | [diff] [blame] | 2119 | } |
Stephen Hemminger | 2bc481c | 2009-08-28 23:41:29 -0700 | [diff] [blame] | 2120 | |
Stephen Hemminger | ef87979 | 2009-09-22 19:41:43 +0000 | [diff] [blame] | 2121 | start_time = ktime_now(); |
Stephen Hemminger | 2bc481c | 2009-08-28 23:41:29 -0700 | [diff] [blame] | 2122 | if (remaining < 100) |
| 2123 | udelay(remaining); /* really small just spin */ |
| 2124 | else { |
| 2125 | /* see do_nanosleep */ |
| 2126 | hrtimer_init_sleeper(&t, current); |
| 2127 | do { |
| 2128 | set_current_state(TASK_INTERRUPTIBLE); |
| 2129 | hrtimer_start_expires(&t.timer, HRTIMER_MODE_ABS); |
| 2130 | if (!hrtimer_active(&t.timer)) |
| 2131 | t.task = NULL; |
| 2132 | |
| 2133 | if (likely(t.task)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | schedule(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | |
Stephen Hemminger | 2bc481c | 2009-08-28 23:41:29 -0700 | [diff] [blame] | 2136 | hrtimer_cancel(&t.timer); |
| 2137 | } while (t.task && pkt_dev->running && !signal_pending(current)); |
| 2138 | __set_current_state(TASK_RUNNING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | } |
Stephen Hemminger | ef87979 | 2009-09-22 19:41:43 +0000 | [diff] [blame] | 2140 | end_time = ktime_now(); |
| 2141 | |
| 2142 | pkt_dev->idle_acc += ktime_to_ns(ktime_sub(end_time, start_time)); |
| 2143 | pkt_dev->next_tx = ktime_add_ns(end_time, pkt_dev->delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2144 | } |
| 2145 | |
Jamal Hadi Salim | 16dab72 | 2007-07-02 22:39:50 -0700 | [diff] [blame] | 2146 | static inline void set_pkt_overhead(struct pktgen_dev *pkt_dev) |
| 2147 | { |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 2148 | pkt_dev->pkt_overhead = 0; |
Jamal Hadi Salim | 16dab72 | 2007-07-02 22:39:50 -0700 | [diff] [blame] | 2149 | pkt_dev->pkt_overhead += pkt_dev->nr_labels*sizeof(u32); |
| 2150 | pkt_dev->pkt_overhead += VLAN_TAG_SIZE(pkt_dev); |
| 2151 | pkt_dev->pkt_overhead += SVLAN_TAG_SIZE(pkt_dev); |
| 2152 | } |
| 2153 | |
Stephen Hemminger | 648fda7 | 2009-08-27 13:55:07 +0000 | [diff] [blame] | 2154 | static inline int f_seen(const struct pktgen_dev *pkt_dev, int flow) |
Jamal Hadi Salim | 007a531 | 2007-07-02 22:40:36 -0700 | [diff] [blame] | 2155 | { |
Stephen Hemminger | 648fda7 | 2009-08-27 13:55:07 +0000 | [diff] [blame] | 2156 | return !!(pkt_dev->flows[flow].flags & F_INIT); |
Jamal Hadi Salim | 007a531 | 2007-07-02 22:40:36 -0700 | [diff] [blame] | 2157 | } |
| 2158 | |
| 2159 | static inline int f_pick(struct pktgen_dev *pkt_dev) |
| 2160 | { |
| 2161 | int flow = pkt_dev->curfl; |
| 2162 | |
| 2163 | if (pkt_dev->flags & F_FLOW_SEQ) { |
| 2164 | if (pkt_dev->flows[flow].count >= pkt_dev->lflow) { |
| 2165 | /* reset time */ |
| 2166 | pkt_dev->flows[flow].count = 0; |
Robert Olsson | 1211a64 | 2008-08-05 18:44:26 -0700 | [diff] [blame] | 2167 | pkt_dev->flows[flow].flags = 0; |
Jamal Hadi Salim | 007a531 | 2007-07-02 22:40:36 -0700 | [diff] [blame] | 2168 | pkt_dev->curfl += 1; |
| 2169 | if (pkt_dev->curfl >= pkt_dev->cflows) |
| 2170 | pkt_dev->curfl = 0; /*reset */ |
| 2171 | } |
| 2172 | } else { |
| 2173 | flow = random32() % pkt_dev->cflows; |
Robert Olsson | 1211a64 | 2008-08-05 18:44:26 -0700 | [diff] [blame] | 2174 | pkt_dev->curfl = flow; |
Jamal Hadi Salim | 007a531 | 2007-07-02 22:40:36 -0700 | [diff] [blame] | 2175 | |
Robert Olsson | 1211a64 | 2008-08-05 18:44:26 -0700 | [diff] [blame] | 2176 | if (pkt_dev->flows[flow].count > pkt_dev->lflow) { |
Jamal Hadi Salim | 007a531 | 2007-07-02 22:40:36 -0700 | [diff] [blame] | 2177 | pkt_dev->flows[flow].count = 0; |
Robert Olsson | 1211a64 | 2008-08-05 18:44:26 -0700 | [diff] [blame] | 2178 | pkt_dev->flows[flow].flags = 0; |
| 2179 | } |
Jamal Hadi Salim | 007a531 | 2007-07-02 22:40:36 -0700 | [diff] [blame] | 2180 | } |
| 2181 | |
| 2182 | return pkt_dev->curfl; |
| 2183 | } |
| 2184 | |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 2185 | |
| 2186 | #ifdef CONFIG_XFRM |
| 2187 | /* If there was already an IPSEC SA, we keep it as is, else |
| 2188 | * we go look for it ... |
| 2189 | */ |
Adrian Bunk | fea1ab0 | 2007-07-30 18:04:09 -0700 | [diff] [blame] | 2190 | static void get_ipsec_sa(struct pktgen_dev *pkt_dev, int flow) |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 2191 | { |
| 2192 | struct xfrm_state *x = pkt_dev->flows[flow].x; |
| 2193 | if (!x) { |
| 2194 | /*slow path: we dont already have xfrm_state*/ |
Alexey Dobriyan | 5447c5e | 2008-11-25 17:31:51 -0800 | [diff] [blame] | 2195 | x = xfrm_stateonly_find(&init_net, |
| 2196 | (xfrm_address_t *)&pkt_dev->cur_daddr, |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 2197 | (xfrm_address_t *)&pkt_dev->cur_saddr, |
| 2198 | AF_INET, |
| 2199 | pkt_dev->ipsmode, |
| 2200 | pkt_dev->ipsproto, 0); |
| 2201 | if (x) { |
| 2202 | pkt_dev->flows[flow].x = x; |
| 2203 | set_pkt_overhead(pkt_dev); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 2204 | pkt_dev->pkt_overhead += x->props.header_len; |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 2205 | } |
| 2206 | |
| 2207 | } |
| 2208 | } |
| 2209 | #endif |
David S. Miller | fd2ea0a | 2008-07-17 01:56:23 -0700 | [diff] [blame] | 2210 | static void set_cur_queue_map(struct pktgen_dev *pkt_dev) |
| 2211 | { |
Robert Olsson | e6fce5b | 2008-08-07 02:23:01 -0700 | [diff] [blame] | 2212 | |
| 2213 | if (pkt_dev->flags & F_QUEUE_MAP_CPU) |
| 2214 | pkt_dev->cur_queue_map = smp_processor_id(); |
| 2215 | |
Eric Dumazet | 896a7cf | 2009-10-02 20:24:59 +0000 | [diff] [blame] | 2216 | else if (pkt_dev->queue_map_min <= pkt_dev->queue_map_max) { |
David S. Miller | fd2ea0a | 2008-07-17 01:56:23 -0700 | [diff] [blame] | 2217 | __u16 t; |
| 2218 | if (pkt_dev->flags & F_QUEUE_MAP_RND) { |
| 2219 | t = random32() % |
| 2220 | (pkt_dev->queue_map_max - |
| 2221 | pkt_dev->queue_map_min + 1) |
| 2222 | + pkt_dev->queue_map_min; |
| 2223 | } else { |
| 2224 | t = pkt_dev->cur_queue_map + 1; |
| 2225 | if (t > pkt_dev->queue_map_max) |
| 2226 | t = pkt_dev->queue_map_min; |
| 2227 | } |
| 2228 | pkt_dev->cur_queue_map = t; |
| 2229 | } |
Robert Olsson | bfdbc0a | 2008-11-19 14:09:47 -0800 | [diff] [blame] | 2230 | pkt_dev->cur_queue_map = pkt_dev->cur_queue_map % pkt_dev->odev->real_num_tx_queues; |
David S. Miller | fd2ea0a | 2008-07-17 01:56:23 -0700 | [diff] [blame] | 2231 | } |
| 2232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2233 | /* Increment/randomize headers according to flags and current values |
| 2234 | * for IP src/dest, UDP src/dst port, MAC-Addr src/dst |
| 2235 | */ |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2236 | static void mod_cur_headers(struct pktgen_dev *pkt_dev) |
| 2237 | { |
| 2238 | __u32 imn; |
| 2239 | __u32 imx; |
| 2240 | int flow = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2241 | |
Jamal Hadi Salim | 007a531 | 2007-07-02 22:40:36 -0700 | [diff] [blame] | 2242 | if (pkt_dev->cflows) |
| 2243 | flow = f_pick(pkt_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2244 | |
| 2245 | /* Deal with source MAC */ |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2246 | if (pkt_dev->src_mac_count > 1) { |
| 2247 | __u32 mc; |
| 2248 | __u32 tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2249 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2250 | if (pkt_dev->flags & F_MACSRC_RND) |
Stephen Hemminger | 5fa6fc7 | 2007-03-04 16:07:28 -0800 | [diff] [blame] | 2251 | mc = random32() % pkt_dev->src_mac_count; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2252 | else { |
| 2253 | mc = pkt_dev->cur_src_mac_offset++; |
Robert Olsson | ff2a79a | 2008-08-05 18:45:05 -0700 | [diff] [blame] | 2254 | if (pkt_dev->cur_src_mac_offset >= |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2255 | pkt_dev->src_mac_count) |
| 2256 | pkt_dev->cur_src_mac_offset = 0; |
| 2257 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2259 | tmp = pkt_dev->src_mac[5] + (mc & 0xFF); |
| 2260 | pkt_dev->hh[11] = tmp; |
| 2261 | tmp = (pkt_dev->src_mac[4] + ((mc >> 8) & 0xFF) + (tmp >> 8)); |
| 2262 | pkt_dev->hh[10] = tmp; |
| 2263 | tmp = (pkt_dev->src_mac[3] + ((mc >> 16) & 0xFF) + (tmp >> 8)); |
| 2264 | pkt_dev->hh[9] = tmp; |
| 2265 | tmp = (pkt_dev->src_mac[2] + ((mc >> 24) & 0xFF) + (tmp >> 8)); |
| 2266 | pkt_dev->hh[8] = tmp; |
| 2267 | tmp = (pkt_dev->src_mac[1] + (tmp >> 8)); |
| 2268 | pkt_dev->hh[7] = tmp; |
| 2269 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2270 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2271 | /* Deal with Destination MAC */ |
| 2272 | if (pkt_dev->dst_mac_count > 1) { |
| 2273 | __u32 mc; |
| 2274 | __u32 tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2276 | if (pkt_dev->flags & F_MACDST_RND) |
Stephen Hemminger | 5fa6fc7 | 2007-03-04 16:07:28 -0800 | [diff] [blame] | 2277 | mc = random32() % pkt_dev->dst_mac_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2279 | else { |
| 2280 | mc = pkt_dev->cur_dst_mac_offset++; |
Robert Olsson | ff2a79a | 2008-08-05 18:45:05 -0700 | [diff] [blame] | 2281 | if (pkt_dev->cur_dst_mac_offset >= |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2282 | pkt_dev->dst_mac_count) { |
| 2283 | pkt_dev->cur_dst_mac_offset = 0; |
| 2284 | } |
| 2285 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2287 | tmp = pkt_dev->dst_mac[5] + (mc & 0xFF); |
| 2288 | pkt_dev->hh[5] = tmp; |
| 2289 | tmp = (pkt_dev->dst_mac[4] + ((mc >> 8) & 0xFF) + (tmp >> 8)); |
| 2290 | pkt_dev->hh[4] = tmp; |
| 2291 | tmp = (pkt_dev->dst_mac[3] + ((mc >> 16) & 0xFF) + (tmp >> 8)); |
| 2292 | pkt_dev->hh[3] = tmp; |
| 2293 | tmp = (pkt_dev->dst_mac[2] + ((mc >> 24) & 0xFF) + (tmp >> 8)); |
| 2294 | pkt_dev->hh[2] = tmp; |
| 2295 | tmp = (pkt_dev->dst_mac[1] + (tmp >> 8)); |
| 2296 | pkt_dev->hh[1] = tmp; |
| 2297 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 2299 | if (pkt_dev->flags & F_MPLS_RND) { |
| 2300 | unsigned i; |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 2301 | for (i = 0; i < pkt_dev->nr_labels; i++) |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 2302 | if (pkt_dev->labels[i] & MPLS_STACK_BOTTOM) |
| 2303 | pkt_dev->labels[i] = MPLS_STACK_BOTTOM | |
Stephen Hemminger | 5fa6fc7 | 2007-03-04 16:07:28 -0800 | [diff] [blame] | 2304 | ((__force __be32)random32() & |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 2305 | htonl(0x000fffff)); |
| 2306 | } |
| 2307 | |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 2308 | if ((pkt_dev->flags & F_VID_RND) && (pkt_dev->vlan_id != 0xffff)) { |
Stephen Hemminger | 5fa6fc7 | 2007-03-04 16:07:28 -0800 | [diff] [blame] | 2309 | pkt_dev->vlan_id = random32() & (4096-1); |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 2310 | } |
| 2311 | |
| 2312 | if ((pkt_dev->flags & F_SVID_RND) && (pkt_dev->svlan_id != 0xffff)) { |
Stephen Hemminger | 5fa6fc7 | 2007-03-04 16:07:28 -0800 | [diff] [blame] | 2313 | pkt_dev->svlan_id = random32() & (4096 - 1); |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 2314 | } |
| 2315 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2316 | if (pkt_dev->udp_src_min < pkt_dev->udp_src_max) { |
| 2317 | if (pkt_dev->flags & F_UDPSRC_RND) |
Stephen Hemminger | 5fa6fc7 | 2007-03-04 16:07:28 -0800 | [diff] [blame] | 2318 | pkt_dev->cur_udp_src = random32() % |
| 2319 | (pkt_dev->udp_src_max - pkt_dev->udp_src_min) |
| 2320 | + pkt_dev->udp_src_min; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2321 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2322 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | pkt_dev->cur_udp_src++; |
| 2324 | if (pkt_dev->cur_udp_src >= pkt_dev->udp_src_max) |
| 2325 | pkt_dev->cur_udp_src = pkt_dev->udp_src_min; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2326 | } |
| 2327 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2329 | if (pkt_dev->udp_dst_min < pkt_dev->udp_dst_max) { |
| 2330 | if (pkt_dev->flags & F_UDPDST_RND) { |
Stephen Hemminger | 5fa6fc7 | 2007-03-04 16:07:28 -0800 | [diff] [blame] | 2331 | pkt_dev->cur_udp_dst = random32() % |
| 2332 | (pkt_dev->udp_dst_max - pkt_dev->udp_dst_min) |
| 2333 | + pkt_dev->udp_dst_min; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2334 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2335 | pkt_dev->cur_udp_dst++; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2336 | if (pkt_dev->cur_udp_dst >= pkt_dev->udp_dst_max) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2337 | pkt_dev->cur_udp_dst = pkt_dev->udp_dst_min; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2338 | } |
| 2339 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2340 | |
| 2341 | if (!(pkt_dev->flags & F_IPV6)) { |
| 2342 | |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 2343 | imn = ntohl(pkt_dev->saddr_min); |
| 2344 | imx = ntohl(pkt_dev->saddr_max); |
| 2345 | if (imn < imx) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | __u32 t; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2347 | if (pkt_dev->flags & F_IPSRC_RND) |
Stephen Hemminger | 5fa6fc7 | 2007-03-04 16:07:28 -0800 | [diff] [blame] | 2348 | t = random32() % (imx - imn) + imn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2349 | else { |
| 2350 | t = ntohl(pkt_dev->cur_saddr); |
| 2351 | t++; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 2352 | if (t > imx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2353 | t = imn; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 2354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | } |
| 2356 | pkt_dev->cur_saddr = htonl(t); |
| 2357 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2358 | |
Jamal Hadi Salim | 007a531 | 2007-07-02 22:40:36 -0700 | [diff] [blame] | 2359 | if (pkt_dev->cflows && f_seen(pkt_dev, flow)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | pkt_dev->cur_daddr = pkt_dev->flows[flow].cur_daddr; |
| 2361 | } else { |
Al Viro | 252e334 | 2006-11-14 20:48:11 -0800 | [diff] [blame] | 2362 | imn = ntohl(pkt_dev->daddr_min); |
| 2363 | imx = ntohl(pkt_dev->daddr_max); |
| 2364 | if (imn < imx) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2365 | __u32 t; |
Al Viro | 252e334 | 2006-11-14 20:48:11 -0800 | [diff] [blame] | 2366 | __be32 s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | if (pkt_dev->flags & F_IPDST_RND) { |
| 2368 | |
Stephen Hemminger | 5fa6fc7 | 2007-03-04 16:07:28 -0800 | [diff] [blame] | 2369 | t = random32() % (imx - imn) + imn; |
Al Viro | 252e334 | 2006-11-14 20:48:11 -0800 | [diff] [blame] | 2370 | s = htonl(t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2371 | |
Joe Perches | 21cf225 | 2007-12-16 13:44:00 -0800 | [diff] [blame] | 2372 | while (ipv4_is_loopback(s) || |
| 2373 | ipv4_is_multicast(s) || |
Jan Engelhardt | 1e637c7 | 2008-01-21 03:18:08 -0800 | [diff] [blame] | 2374 | ipv4_is_lbcast(s) || |
Joe Perches | 21cf225 | 2007-12-16 13:44:00 -0800 | [diff] [blame] | 2375 | ipv4_is_zeronet(s) || |
| 2376 | ipv4_is_local_multicast(s)) { |
Stephen Hemminger | 5fa6fc7 | 2007-03-04 16:07:28 -0800 | [diff] [blame] | 2377 | t = random32() % (imx - imn) + imn; |
Al Viro | 252e334 | 2006-11-14 20:48:11 -0800 | [diff] [blame] | 2378 | s = htonl(t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | } |
Al Viro | 252e334 | 2006-11-14 20:48:11 -0800 | [diff] [blame] | 2380 | pkt_dev->cur_daddr = s; |
| 2381 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2382 | t = ntohl(pkt_dev->cur_daddr); |
| 2383 | t++; |
| 2384 | if (t > imx) { |
| 2385 | t = imn; |
| 2386 | } |
| 2387 | pkt_dev->cur_daddr = htonl(t); |
| 2388 | } |
| 2389 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2390 | if (pkt_dev->cflows) { |
Jamal Hadi Salim | 007a531 | 2007-07-02 22:40:36 -0700 | [diff] [blame] | 2391 | pkt_dev->flows[flow].flags |= F_INIT; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2392 | pkt_dev->flows[flow].cur_daddr = |
| 2393 | pkt_dev->cur_daddr; |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 2394 | #ifdef CONFIG_XFRM |
| 2395 | if (pkt_dev->flags & F_IPSEC_ON) |
| 2396 | get_ipsec_sa(pkt_dev, flow); |
| 2397 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2398 | pkt_dev->nflows++; |
| 2399 | } |
| 2400 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2401 | } else { /* IPV6 * */ |
| 2402 | |
| 2403 | if (pkt_dev->min_in6_daddr.s6_addr32[0] == 0 && |
| 2404 | pkt_dev->min_in6_daddr.s6_addr32[1] == 0 && |
| 2405 | pkt_dev->min_in6_daddr.s6_addr32[2] == 0 && |
| 2406 | pkt_dev->min_in6_daddr.s6_addr32[3] == 0) ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2407 | else { |
| 2408 | int i; |
| 2409 | |
| 2410 | /* Only random destinations yet */ |
| 2411 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2412 | for (i = 0; i < 4; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2413 | pkt_dev->cur_in6_daddr.s6_addr32[i] = |
Stephen Hemminger | 5fa6fc7 | 2007-03-04 16:07:28 -0800 | [diff] [blame] | 2414 | (((__force __be32)random32() | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2415 | pkt_dev->min_in6_daddr.s6_addr32[i]) & |
| 2416 | pkt_dev->max_in6_daddr.s6_addr32[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2418 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | } |
| 2420 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2421 | if (pkt_dev->min_pkt_size < pkt_dev->max_pkt_size) { |
| 2422 | __u32 t; |
| 2423 | if (pkt_dev->flags & F_TXSIZE_RND) { |
Stephen Hemminger | 5fa6fc7 | 2007-03-04 16:07:28 -0800 | [diff] [blame] | 2424 | t = random32() % |
| 2425 | (pkt_dev->max_pkt_size - pkt_dev->min_pkt_size) |
| 2426 | + pkt_dev->min_pkt_size; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2427 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2428 | t = pkt_dev->cur_pkt_size + 1; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2429 | if (t > pkt_dev->max_pkt_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2430 | t = pkt_dev->min_pkt_size; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2431 | } |
| 2432 | pkt_dev->cur_pkt_size = t; |
| 2433 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | |
David S. Miller | fd2ea0a | 2008-07-17 01:56:23 -0700 | [diff] [blame] | 2435 | set_cur_queue_map(pkt_dev); |
Robert Olsson | 45b270f | 2007-08-28 15:45:55 -0700 | [diff] [blame] | 2436 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2437 | pkt_dev->flows[flow].count++; |
| 2438 | } |
| 2439 | |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 2440 | |
| 2441 | #ifdef CONFIG_XFRM |
| 2442 | static int pktgen_output_ipsec(struct sk_buff *skb, struct pktgen_dev *pkt_dev) |
| 2443 | { |
| 2444 | struct xfrm_state *x = pkt_dev->flows[pkt_dev->curfl].x; |
| 2445 | int err = 0; |
| 2446 | struct iphdr *iph; |
| 2447 | |
| 2448 | if (!x) |
| 2449 | return 0; |
| 2450 | /* XXX: we dont support tunnel mode for now until |
| 2451 | * we resolve the dst issue */ |
| 2452 | if (x->props.mode != XFRM_MODE_TRANSPORT) |
| 2453 | return 0; |
| 2454 | |
| 2455 | spin_lock(&x->lock); |
| 2456 | iph = ip_hdr(skb); |
| 2457 | |
Herbert Xu | 1399637 | 2007-10-17 21:35:51 -0700 | [diff] [blame] | 2458 | err = x->outer_mode->output(x, skb); |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 2459 | if (err) |
| 2460 | goto error; |
| 2461 | err = x->type->output(x, skb); |
| 2462 | if (err) |
| 2463 | goto error; |
| 2464 | |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 2465 | x->curlft.bytes += skb->len; |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 2466 | x->curlft.packets++; |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 2467 | error: |
| 2468 | spin_unlock(&x->lock); |
| 2469 | return err; |
| 2470 | } |
| 2471 | |
Stephen Hemminger | 475ac1e | 2009-08-27 13:55:08 +0000 | [diff] [blame] | 2472 | static void free_SAs(struct pktgen_dev *pkt_dev) |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 2473 | { |
| 2474 | if (pkt_dev->cflows) { |
| 2475 | /* let go of the SAs if we have them */ |
| 2476 | int i = 0; |
Florian Westphal | 5b5f792 | 2009-05-21 15:07:12 -0700 | [diff] [blame] | 2477 | for (; i < pkt_dev->cflows; i++) { |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 2478 | struct xfrm_state *x = pkt_dev->flows[i].x; |
| 2479 | if (x) { |
| 2480 | xfrm_state_put(x); |
| 2481 | pkt_dev->flows[i].x = NULL; |
| 2482 | } |
| 2483 | } |
| 2484 | } |
| 2485 | } |
| 2486 | |
Stephen Hemminger | 475ac1e | 2009-08-27 13:55:08 +0000 | [diff] [blame] | 2487 | static int process_ipsec(struct pktgen_dev *pkt_dev, |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 2488 | struct sk_buff *skb, __be16 protocol) |
| 2489 | { |
| 2490 | if (pkt_dev->flags & F_IPSEC_ON) { |
| 2491 | struct xfrm_state *x = pkt_dev->flows[pkt_dev->curfl].x; |
| 2492 | int nhead = 0; |
| 2493 | if (x) { |
| 2494 | int ret; |
| 2495 | __u8 *eth; |
| 2496 | nhead = x->props.header_len - skb_headroom(skb); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 2497 | if (nhead > 0) { |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 2498 | ret = pskb_expand_head(skb, nhead, 0, GFP_ATOMIC); |
| 2499 | if (ret < 0) { |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 2500 | printk(KERN_ERR "Error expanding " |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 2501 | "ipsec packet %d\n", ret); |
Ilpo Järvinen | b4bb4ac | 2008-10-13 18:43:59 -0700 | [diff] [blame] | 2502 | goto err; |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 2503 | } |
| 2504 | } |
| 2505 | |
| 2506 | /* ipsec is not expecting ll header */ |
| 2507 | skb_pull(skb, ETH_HLEN); |
| 2508 | ret = pktgen_output_ipsec(skb, pkt_dev); |
| 2509 | if (ret) { |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 2510 | printk(KERN_ERR "Error creating ipsec " |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 2511 | "packet %d\n", ret); |
Ilpo Järvinen | b4bb4ac | 2008-10-13 18:43:59 -0700 | [diff] [blame] | 2512 | goto err; |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 2513 | } |
| 2514 | /* restore ll */ |
| 2515 | eth = (__u8 *) skb_push(skb, ETH_HLEN); |
| 2516 | memcpy(eth, pkt_dev->hh, 12); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 2517 | *(u16 *) ð[12] = protocol; |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 2518 | } |
| 2519 | } |
| 2520 | return 1; |
Ilpo Järvinen | b4bb4ac | 2008-10-13 18:43:59 -0700 | [diff] [blame] | 2521 | err: |
| 2522 | kfree_skb(skb); |
| 2523 | return 0; |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 2524 | } |
| 2525 | #endif |
| 2526 | |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 2527 | static void mpls_push(__be32 *mpls, struct pktgen_dev *pkt_dev) |
| 2528 | { |
| 2529 | unsigned i; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 2530 | for (i = 0; i < pkt_dev->nr_labels; i++) |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 2531 | *mpls++ = pkt_dev->labels[i] & ~MPLS_STACK_BOTTOM; |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 2532 | |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 2533 | mpls--; |
| 2534 | *mpls |= MPLS_STACK_BOTTOM; |
| 2535 | } |
| 2536 | |
Al Viro | 0f37c60 | 2006-11-03 03:49:56 -0800 | [diff] [blame] | 2537 | static inline __be16 build_tci(unsigned int id, unsigned int cfi, |
| 2538 | unsigned int prio) |
| 2539 | { |
| 2540 | return htons(id | (cfi << 12) | (prio << 13)); |
| 2541 | } |
| 2542 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2543 | static struct sk_buff *fill_packet_ipv4(struct net_device *odev, |
| 2544 | struct pktgen_dev *pkt_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | { |
| 2546 | struct sk_buff *skb = NULL; |
| 2547 | __u8 *eth; |
| 2548 | struct udphdr *udph; |
| 2549 | int datalen, iplen; |
| 2550 | struct iphdr *iph; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2551 | struct pktgen_hdr *pgh = NULL; |
Stephen Hemminger | d5f1ce9 | 2007-03-04 16:08:08 -0800 | [diff] [blame] | 2552 | __be16 protocol = htons(ETH_P_IP); |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 2553 | __be32 *mpls; |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 2554 | __be16 *vlan_tci = NULL; /* Encapsulates priority and VLAN ID */ |
| 2555 | __be16 *vlan_encapsulated_proto = NULL; /* packet type ID field (or len) for VLAN tag */ |
| 2556 | __be16 *svlan_tci = NULL; /* Encapsulates priority and SVLAN ID */ |
| 2557 | __be16 *svlan_encapsulated_proto = NULL; /* packet type ID field (or len) for SVLAN tag */ |
David S. Miller | fd2ea0a | 2008-07-17 01:56:23 -0700 | [diff] [blame] | 2558 | u16 queue_map; |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 2559 | |
| 2560 | if (pkt_dev->nr_labels) |
Stephen Hemminger | d5f1ce9 | 2007-03-04 16:08:08 -0800 | [diff] [blame] | 2561 | protocol = htons(ETH_P_MPLS_UC); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2562 | |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 2563 | if (pkt_dev->vlan_id != 0xffff) |
Stephen Hemminger | d5f1ce9 | 2007-03-04 16:08:08 -0800 | [diff] [blame] | 2564 | protocol = htons(ETH_P_8021Q); |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 2565 | |
Robert Olsson | 64053be | 2005-06-26 15:27:10 -0700 | [diff] [blame] | 2566 | /* Update any of the values, used when we're incrementing various |
| 2567 | * fields. |
| 2568 | */ |
David S. Miller | fd2ea0a | 2008-07-17 01:56:23 -0700 | [diff] [blame] | 2569 | queue_map = pkt_dev->cur_queue_map; |
Robert Olsson | 64053be | 2005-06-26 15:27:10 -0700 | [diff] [blame] | 2570 | mod_cur_headers(pkt_dev); |
| 2571 | |
David S. Miller | 7ac5459 | 2006-01-18 14:19:10 -0800 | [diff] [blame] | 2572 | datalen = (odev->hard_header_len + 16) & ~0xf; |
Stephen Hemminger | e470757 | 2009-08-27 13:55:13 +0000 | [diff] [blame] | 2573 | skb = __netdev_alloc_skb(odev, |
| 2574 | pkt_dev->cur_pkt_size + 64 |
| 2575 | + datalen + pkt_dev->pkt_overhead, GFP_NOWAIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | if (!skb) { |
| 2577 | sprintf(pkt_dev->result, "No memory"); |
| 2578 | return NULL; |
| 2579 | } |
| 2580 | |
David S. Miller | 7ac5459 | 2006-01-18 14:19:10 -0800 | [diff] [blame] | 2581 | skb_reserve(skb, datalen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2582 | |
| 2583 | /* Reserve for ethernet and IP header */ |
| 2584 | eth = (__u8 *) skb_push(skb, 14); |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 2585 | mpls = (__be32 *)skb_put(skb, pkt_dev->nr_labels*sizeof(__u32)); |
| 2586 | if (pkt_dev->nr_labels) |
| 2587 | mpls_push(mpls, pkt_dev); |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 2588 | |
| 2589 | if (pkt_dev->vlan_id != 0xffff) { |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 2590 | if (pkt_dev->svlan_id != 0xffff) { |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 2591 | svlan_tci = (__be16 *)skb_put(skb, sizeof(__be16)); |
Al Viro | 0f37c60 | 2006-11-03 03:49:56 -0800 | [diff] [blame] | 2592 | *svlan_tci = build_tci(pkt_dev->svlan_id, |
| 2593 | pkt_dev->svlan_cfi, |
| 2594 | pkt_dev->svlan_p); |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 2595 | svlan_encapsulated_proto = (__be16 *)skb_put(skb, sizeof(__be16)); |
Stephen Hemminger | d5f1ce9 | 2007-03-04 16:08:08 -0800 | [diff] [blame] | 2596 | *svlan_encapsulated_proto = htons(ETH_P_8021Q); |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 2597 | } |
| 2598 | vlan_tci = (__be16 *)skb_put(skb, sizeof(__be16)); |
Al Viro | 0f37c60 | 2006-11-03 03:49:56 -0800 | [diff] [blame] | 2599 | *vlan_tci = build_tci(pkt_dev->vlan_id, |
| 2600 | pkt_dev->vlan_cfi, |
| 2601 | pkt_dev->vlan_p); |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 2602 | vlan_encapsulated_proto = (__be16 *)skb_put(skb, sizeof(__be16)); |
Stephen Hemminger | d5f1ce9 | 2007-03-04 16:08:08 -0800 | [diff] [blame] | 2603 | *vlan_encapsulated_proto = htons(ETH_P_IP); |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 2604 | } |
| 2605 | |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 2606 | skb->network_header = skb->tail; |
Arnaldo Carvalho de Melo | b0e380b | 2007-04-10 21:21:55 -0700 | [diff] [blame] | 2607 | skb->transport_header = skb->network_header + sizeof(struct iphdr); |
Arnaldo Carvalho de Melo | ddc7b8e | 2007-03-15 21:42:27 -0300 | [diff] [blame] | 2608 | skb_put(skb, sizeof(struct iphdr) + sizeof(struct udphdr)); |
David S. Miller | fd2ea0a | 2008-07-17 01:56:23 -0700 | [diff] [blame] | 2609 | skb_set_queue_mapping(skb, queue_map); |
Arnaldo Carvalho de Melo | ddc7b8e | 2007-03-15 21:42:27 -0300 | [diff] [blame] | 2610 | iph = ip_hdr(skb); |
| 2611 | udph = udp_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | memcpy(eth, pkt_dev->hh, 12); |
Al Viro | 252e334 | 2006-11-14 20:48:11 -0800 | [diff] [blame] | 2614 | *(__be16 *) & eth[12] = protocol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2615 | |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 2616 | /* Eth + IPh + UDPh + mpls */ |
| 2617 | datalen = pkt_dev->cur_pkt_size - 14 - 20 - 8 - |
Jamal Hadi Salim | 16dab72 | 2007-07-02 22:39:50 -0700 | [diff] [blame] | 2618 | pkt_dev->pkt_overhead; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2619 | if (datalen < sizeof(struct pktgen_hdr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2620 | datalen = sizeof(struct pktgen_hdr); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2621 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2622 | udph->source = htons(pkt_dev->cur_udp_src); |
| 2623 | udph->dest = htons(pkt_dev->cur_udp_dst); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2624 | udph->len = htons(datalen + 8); /* DATA + udphdr */ |
| 2625 | udph->check = 0; /* No checksum */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | |
| 2627 | iph->ihl = 5; |
| 2628 | iph->version = 4; |
| 2629 | iph->ttl = 32; |
Francesco Fondelli | 1ca7768 | 2006-09-27 16:32:03 -0700 | [diff] [blame] | 2630 | iph->tos = pkt_dev->tos; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2631 | iph->protocol = IPPROTO_UDP; /* UDP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2632 | iph->saddr = pkt_dev->cur_saddr; |
| 2633 | iph->daddr = pkt_dev->cur_daddr; |
Eric Dumazet | 66ed1e5 | 2009-10-24 06:55:20 -0700 | [diff] [blame^] | 2634 | iph->id = htons(pkt_dev->ip_id); |
| 2635 | pkt_dev->ip_id++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2636 | iph->frag_off = 0; |
| 2637 | iplen = 20 + 8 + datalen; |
| 2638 | iph->tot_len = htons(iplen); |
| 2639 | iph->check = 0; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2640 | iph->check = ip_fast_csum((void *)iph, iph->ihl); |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 2641 | skb->protocol = protocol; |
Arnaldo Carvalho de Melo | b0e380b | 2007-04-10 21:21:55 -0700 | [diff] [blame] | 2642 | skb->mac_header = (skb->network_header - ETH_HLEN - |
Jamal Hadi Salim | 16dab72 | 2007-07-02 22:39:50 -0700 | [diff] [blame] | 2643 | pkt_dev->pkt_overhead); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | skb->dev = odev; |
| 2645 | skb->pkt_type = PACKET_HOST; |
| 2646 | |
Eric Dumazet | 66ed1e5 | 2009-10-24 06:55:20 -0700 | [diff] [blame^] | 2647 | if (pkt_dev->nfrags <= 0) { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2648 | pgh = (struct pktgen_hdr *)skb_put(skb, datalen); |
Eric Dumazet | 66ed1e5 | 2009-10-24 06:55:20 -0700 | [diff] [blame^] | 2649 | memset(pgh + 1, 0, datalen - sizeof(struct pktgen_hdr)); |
| 2650 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2651 | int frags = pkt_dev->nfrags; |
Eric Dumazet | 66ed1e5 | 2009-10-24 06:55:20 -0700 | [diff] [blame^] | 2652 | int i, len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2654 | pgh = (struct pktgen_hdr *)(((char *)(udph)) + 8); |
| 2655 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | if (frags > MAX_SKB_FRAGS) |
| 2657 | frags = MAX_SKB_FRAGS; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2658 | if (datalen > frags * PAGE_SIZE) { |
Eric Dumazet | 66ed1e5 | 2009-10-24 06:55:20 -0700 | [diff] [blame^] | 2659 | len = datalen - frags * PAGE_SIZE; |
| 2660 | memset(skb_put(skb, len), 0, len); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2661 | datalen = frags * PAGE_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2662 | } |
| 2663 | |
| 2664 | i = 0; |
| 2665 | while (datalen > 0) { |
Eric Dumazet | 66ed1e5 | 2009-10-24 06:55:20 -0700 | [diff] [blame^] | 2666 | struct page *page = alloc_pages(GFP_KERNEL | __GFP_ZERO, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | skb_shinfo(skb)->frags[i].page = page; |
| 2668 | skb_shinfo(skb)->frags[i].page_offset = 0; |
| 2669 | skb_shinfo(skb)->frags[i].size = |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2670 | (datalen < PAGE_SIZE ? datalen : PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2671 | datalen -= skb_shinfo(skb)->frags[i].size; |
| 2672 | skb->len += skb_shinfo(skb)->frags[i].size; |
| 2673 | skb->data_len += skb_shinfo(skb)->frags[i].size; |
| 2674 | i++; |
| 2675 | skb_shinfo(skb)->nr_frags = i; |
| 2676 | } |
| 2677 | |
| 2678 | while (i < frags) { |
| 2679 | int rem; |
| 2680 | |
| 2681 | if (i == 0) |
| 2682 | break; |
| 2683 | |
| 2684 | rem = skb_shinfo(skb)->frags[i - 1].size / 2; |
| 2685 | if (rem == 0) |
| 2686 | break; |
| 2687 | |
| 2688 | skb_shinfo(skb)->frags[i - 1].size -= rem; |
| 2689 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2690 | skb_shinfo(skb)->frags[i] = |
| 2691 | skb_shinfo(skb)->frags[i - 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2692 | get_page(skb_shinfo(skb)->frags[i].page); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2693 | skb_shinfo(skb)->frags[i].page = |
| 2694 | skb_shinfo(skb)->frags[i - 1].page; |
| 2695 | skb_shinfo(skb)->frags[i].page_offset += |
| 2696 | skb_shinfo(skb)->frags[i - 1].size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2697 | skb_shinfo(skb)->frags[i].size = rem; |
| 2698 | i++; |
| 2699 | skb_shinfo(skb)->nr_frags = i; |
| 2700 | } |
| 2701 | } |
| 2702 | |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 2703 | /* Stamp the time, and sequence number, |
| 2704 | * convert them to network byte order |
| 2705 | */ |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2706 | if (pgh) { |
| 2707 | struct timeval timestamp; |
| 2708 | |
| 2709 | pgh->pgh_magic = htonl(PKTGEN_MAGIC); |
| 2710 | pgh->seq_num = htonl(pkt_dev->seq_num); |
| 2711 | |
| 2712 | do_gettimeofday(×tamp); |
| 2713 | pgh->tv_sec = htonl(timestamp.tv_sec); |
| 2714 | pgh->tv_usec = htonl(timestamp.tv_usec); |
| 2715 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2716 | |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 2717 | #ifdef CONFIG_XFRM |
| 2718 | if (!process_ipsec(pkt_dev, skb, protocol)) |
| 2719 | return NULL; |
| 2720 | #endif |
| 2721 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | return skb; |
| 2723 | } |
| 2724 | |
| 2725 | /* |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 2726 | * scan_ip6, fmt_ip taken from dietlibc-0.21 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2727 | * Author Felix von Leitner <felix-dietlibc@fefe.de> |
| 2728 | * |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 2729 | * Slightly modified for kernel. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2730 | * Should be candidate for net/ipv4/utils.c |
| 2731 | * --ro |
| 2732 | */ |
| 2733 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2734 | static unsigned int scan_ip6(const char *s, char ip[16]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | { |
| 2736 | unsigned int i; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2737 | unsigned int len = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | unsigned long u; |
| 2739 | char suffix[16]; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2740 | unsigned int prefixlen = 0; |
| 2741 | unsigned int suffixlen = 0; |
Al Viro | 252e334 | 2006-11-14 20:48:11 -0800 | [diff] [blame] | 2742 | __be32 tmp; |
Stephen Hemminger | cfcabdc | 2007-10-09 01:59:42 -0700 | [diff] [blame] | 2743 | char *pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2745 | for (i = 0; i < 16; i++) |
| 2746 | ip[i] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | |
| 2748 | for (;;) { |
| 2749 | if (*s == ':') { |
| 2750 | len++; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2751 | if (s[1] == ':') { /* Found "::", skip to part 2 */ |
| 2752 | s += 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2753 | len++; |
| 2754 | break; |
| 2755 | } |
| 2756 | s++; |
| 2757 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2758 | |
Stephen Hemminger | cfcabdc | 2007-10-09 01:59:42 -0700 | [diff] [blame] | 2759 | u = simple_strtoul(s, &pos, 16); |
| 2760 | i = pos - s; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2761 | if (!i) |
| 2762 | return 0; |
| 2763 | if (prefixlen == 12 && s[i] == '.') { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | |
| 2765 | /* the last 4 bytes may be written as IPv4 address */ |
| 2766 | |
| 2767 | tmp = in_aton(s); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2768 | memcpy((struct in_addr *)(ip + 12), &tmp, sizeof(tmp)); |
| 2769 | return i + len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | } |
| 2771 | ip[prefixlen++] = (u >> 8); |
| 2772 | ip[prefixlen++] = (u & 255); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2773 | s += i; |
| 2774 | len += i; |
| 2775 | if (prefixlen == 16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2776 | return len; |
| 2777 | } |
| 2778 | |
| 2779 | /* part 2, after "::" */ |
| 2780 | for (;;) { |
| 2781 | if (*s == ':') { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2782 | if (suffixlen == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | break; |
| 2784 | s++; |
| 2785 | len++; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2786 | } else if (suffixlen != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | break; |
Stephen Hemminger | cfcabdc | 2007-10-09 01:59:42 -0700 | [diff] [blame] | 2788 | |
| 2789 | u = simple_strtol(s, &pos, 16); |
| 2790 | i = pos - s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2791 | if (!i) { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2792 | if (*s) |
| 2793 | len--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2794 | break; |
| 2795 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2796 | if (suffixlen + prefixlen <= 12 && s[i] == '.') { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2797 | tmp = in_aton(s); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2798 | memcpy((struct in_addr *)(suffix + suffixlen), &tmp, |
| 2799 | sizeof(tmp)); |
| 2800 | suffixlen += 4; |
| 2801 | len += strlen(s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2802 | break; |
| 2803 | } |
| 2804 | suffix[suffixlen++] = (u >> 8); |
| 2805 | suffix[suffixlen++] = (u & 255); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2806 | s += i; |
| 2807 | len += i; |
| 2808 | if (prefixlen + suffixlen == 16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2809 | break; |
| 2810 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2811 | for (i = 0; i < suffixlen; i++) |
| 2812 | ip[16 - suffixlen + i] = suffix[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2813 | return len; |
| 2814 | } |
| 2815 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2816 | static char tohex(char hexdigit) |
| 2817 | { |
| 2818 | return hexdigit > 9 ? hexdigit + 'a' - 10 : hexdigit + '0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2819 | } |
| 2820 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2821 | static int fmt_xlong(char *s, unsigned int i) |
| 2822 | { |
| 2823 | char *bak = s; |
| 2824 | *s = tohex((i >> 12) & 0xf); |
| 2825 | if (s != bak || *s != '0') |
| 2826 | ++s; |
| 2827 | *s = tohex((i >> 8) & 0xf); |
| 2828 | if (s != bak || *s != '0') |
| 2829 | ++s; |
| 2830 | *s = tohex((i >> 4) & 0xf); |
| 2831 | if (s != bak || *s != '0') |
| 2832 | ++s; |
| 2833 | *s = tohex(i & 0xf); |
| 2834 | return s - bak + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | } |
| 2836 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2837 | static unsigned int fmt_ip6(char *s, const char ip[16]) |
| 2838 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2839 | unsigned int len; |
| 2840 | unsigned int i; |
| 2841 | unsigned int temp; |
| 2842 | unsigned int compressing; |
| 2843 | int j; |
| 2844 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2845 | len = 0; |
| 2846 | compressing = 0; |
| 2847 | for (j = 0; j < 16; j += 2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | |
| 2849 | #ifdef V4MAPPEDPREFIX |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2850 | if (j == 12 && !memcmp(ip, V4mappedprefix, 12)) { |
| 2851 | inet_ntoa_r(*(struct in_addr *)(ip + 12), s); |
| 2852 | temp = strlen(s); |
| 2853 | return len + temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | } |
| 2855 | #endif |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2856 | temp = ((unsigned long)(unsigned char)ip[j] << 8) + |
| 2857 | (unsigned long)(unsigned char)ip[j + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2858 | if (temp == 0) { |
| 2859 | if (!compressing) { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2860 | compressing = 1; |
| 2861 | if (j == 0) { |
| 2862 | *s++ = ':'; |
| 2863 | ++len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2864 | } |
| 2865 | } |
| 2866 | } else { |
| 2867 | if (compressing) { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2868 | compressing = 0; |
| 2869 | *s++ = ':'; |
| 2870 | ++len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2871 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2872 | i = fmt_xlong(s, temp); |
| 2873 | len += i; |
| 2874 | s += i; |
| 2875 | if (j < 14) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2876 | *s++ = ':'; |
| 2877 | ++len; |
| 2878 | } |
| 2879 | } |
| 2880 | } |
| 2881 | if (compressing) { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2882 | *s++ = ':'; |
| 2883 | ++len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2885 | *s = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2886 | return len; |
| 2887 | } |
| 2888 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2889 | static struct sk_buff *fill_packet_ipv6(struct net_device *odev, |
| 2890 | struct pktgen_dev *pkt_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2891 | { |
| 2892 | struct sk_buff *skb = NULL; |
| 2893 | __u8 *eth; |
| 2894 | struct udphdr *udph; |
| 2895 | int datalen; |
| 2896 | struct ipv6hdr *iph; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2897 | struct pktgen_hdr *pgh = NULL; |
Stephen Hemminger | d5f1ce9 | 2007-03-04 16:08:08 -0800 | [diff] [blame] | 2898 | __be16 protocol = htons(ETH_P_IPV6); |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 2899 | __be32 *mpls; |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 2900 | __be16 *vlan_tci = NULL; /* Encapsulates priority and VLAN ID */ |
| 2901 | __be16 *vlan_encapsulated_proto = NULL; /* packet type ID field (or len) for VLAN tag */ |
| 2902 | __be16 *svlan_tci = NULL; /* Encapsulates priority and SVLAN ID */ |
| 2903 | __be16 *svlan_encapsulated_proto = NULL; /* packet type ID field (or len) for SVLAN tag */ |
David S. Miller | fd2ea0a | 2008-07-17 01:56:23 -0700 | [diff] [blame] | 2904 | u16 queue_map; |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 2905 | |
| 2906 | if (pkt_dev->nr_labels) |
Stephen Hemminger | d5f1ce9 | 2007-03-04 16:08:08 -0800 | [diff] [blame] | 2907 | protocol = htons(ETH_P_MPLS_UC); |
Robert Olsson | 64053be | 2005-06-26 15:27:10 -0700 | [diff] [blame] | 2908 | |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 2909 | if (pkt_dev->vlan_id != 0xffff) |
Stephen Hemminger | d5f1ce9 | 2007-03-04 16:08:08 -0800 | [diff] [blame] | 2910 | protocol = htons(ETH_P_8021Q); |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 2911 | |
Robert Olsson | 64053be | 2005-06-26 15:27:10 -0700 | [diff] [blame] | 2912 | /* Update any of the values, used when we're incrementing various |
| 2913 | * fields. |
| 2914 | */ |
David S. Miller | fd2ea0a | 2008-07-17 01:56:23 -0700 | [diff] [blame] | 2915 | queue_map = pkt_dev->cur_queue_map; |
Robert Olsson | 64053be | 2005-06-26 15:27:10 -0700 | [diff] [blame] | 2916 | mod_cur_headers(pkt_dev); |
| 2917 | |
Stephen Hemminger | e470757 | 2009-08-27 13:55:13 +0000 | [diff] [blame] | 2918 | skb = __netdev_alloc_skb(odev, |
| 2919 | pkt_dev->cur_pkt_size + 64 |
| 2920 | + 16 + pkt_dev->pkt_overhead, GFP_NOWAIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2921 | if (!skb) { |
| 2922 | sprintf(pkt_dev->result, "No memory"); |
| 2923 | return NULL; |
| 2924 | } |
| 2925 | |
| 2926 | skb_reserve(skb, 16); |
| 2927 | |
| 2928 | /* Reserve for ethernet and IP header */ |
| 2929 | eth = (__u8 *) skb_push(skb, 14); |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 2930 | mpls = (__be32 *)skb_put(skb, pkt_dev->nr_labels*sizeof(__u32)); |
| 2931 | if (pkt_dev->nr_labels) |
| 2932 | mpls_push(mpls, pkt_dev); |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 2933 | |
| 2934 | if (pkt_dev->vlan_id != 0xffff) { |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 2935 | if (pkt_dev->svlan_id != 0xffff) { |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 2936 | svlan_tci = (__be16 *)skb_put(skb, sizeof(__be16)); |
Al Viro | 0f37c60 | 2006-11-03 03:49:56 -0800 | [diff] [blame] | 2937 | *svlan_tci = build_tci(pkt_dev->svlan_id, |
| 2938 | pkt_dev->svlan_cfi, |
| 2939 | pkt_dev->svlan_p); |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 2940 | svlan_encapsulated_proto = (__be16 *)skb_put(skb, sizeof(__be16)); |
Stephen Hemminger | d5f1ce9 | 2007-03-04 16:08:08 -0800 | [diff] [blame] | 2941 | *svlan_encapsulated_proto = htons(ETH_P_8021Q); |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 2942 | } |
| 2943 | vlan_tci = (__be16 *)skb_put(skb, sizeof(__be16)); |
Al Viro | 0f37c60 | 2006-11-03 03:49:56 -0800 | [diff] [blame] | 2944 | *vlan_tci = build_tci(pkt_dev->vlan_id, |
| 2945 | pkt_dev->vlan_cfi, |
| 2946 | pkt_dev->vlan_p); |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 2947 | vlan_encapsulated_proto = (__be16 *)skb_put(skb, sizeof(__be16)); |
Stephen Hemminger | d5f1ce9 | 2007-03-04 16:08:08 -0800 | [diff] [blame] | 2948 | *vlan_encapsulated_proto = htons(ETH_P_IPV6); |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 2949 | } |
| 2950 | |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 2951 | skb->network_header = skb->tail; |
Arnaldo Carvalho de Melo | b0e380b | 2007-04-10 21:21:55 -0700 | [diff] [blame] | 2952 | skb->transport_header = skb->network_header + sizeof(struct ipv6hdr); |
Arnaldo Carvalho de Melo | ddc7b8e | 2007-03-15 21:42:27 -0300 | [diff] [blame] | 2953 | skb_put(skb, sizeof(struct ipv6hdr) + sizeof(struct udphdr)); |
David S. Miller | fd2ea0a | 2008-07-17 01:56:23 -0700 | [diff] [blame] | 2954 | skb_set_queue_mapping(skb, queue_map); |
Arnaldo Carvalho de Melo | ddc7b8e | 2007-03-15 21:42:27 -0300 | [diff] [blame] | 2955 | iph = ipv6_hdr(skb); |
| 2956 | udph = udp_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2957 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2958 | memcpy(eth, pkt_dev->hh, 12); |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 2959 | *(__be16 *) ð[12] = protocol; |
Robert Olsson | 64053be | 2005-06-26 15:27:10 -0700 | [diff] [blame] | 2960 | |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 2961 | /* Eth + IPh + UDPh + mpls */ |
| 2962 | datalen = pkt_dev->cur_pkt_size - 14 - |
| 2963 | sizeof(struct ipv6hdr) - sizeof(struct udphdr) - |
Jamal Hadi Salim | 16dab72 | 2007-07-02 22:39:50 -0700 | [diff] [blame] | 2964 | pkt_dev->pkt_overhead; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2966 | if (datalen < sizeof(struct pktgen_hdr)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2967 | datalen = sizeof(struct pktgen_hdr); |
| 2968 | if (net_ratelimit()) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2969 | printk(KERN_INFO "pktgen: increased datalen to %d\n", |
| 2970 | datalen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2971 | } |
| 2972 | |
| 2973 | udph->source = htons(pkt_dev->cur_udp_src); |
| 2974 | udph->dest = htons(pkt_dev->cur_udp_dst); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2975 | udph->len = htons(datalen + sizeof(struct udphdr)); |
| 2976 | udph->check = 0; /* No checksum */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 | |
Stephen Hemminger | d5f1ce9 | 2007-03-04 16:08:08 -0800 | [diff] [blame] | 2978 | *(__be32 *) iph = htonl(0x60000000); /* Version + flow */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2979 | |
Francesco Fondelli | 1ca7768 | 2006-09-27 16:32:03 -0700 | [diff] [blame] | 2980 | if (pkt_dev->traffic_class) { |
| 2981 | /* Version + traffic class + flow (0) */ |
Al Viro | 252e334 | 2006-11-14 20:48:11 -0800 | [diff] [blame] | 2982 | *(__be32 *)iph |= htonl(0x60000000 | (pkt_dev->traffic_class << 20)); |
Francesco Fondelli | 1ca7768 | 2006-09-27 16:32:03 -0700 | [diff] [blame] | 2983 | } |
| 2984 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2985 | iph->hop_limit = 32; |
| 2986 | |
| 2987 | iph->payload_len = htons(sizeof(struct udphdr) + datalen); |
| 2988 | iph->nexthdr = IPPROTO_UDP; |
| 2989 | |
| 2990 | ipv6_addr_copy(&iph->daddr, &pkt_dev->cur_in6_daddr); |
| 2991 | ipv6_addr_copy(&iph->saddr, &pkt_dev->cur_in6_saddr); |
| 2992 | |
Arnaldo Carvalho de Melo | b0e380b | 2007-04-10 21:21:55 -0700 | [diff] [blame] | 2993 | skb->mac_header = (skb->network_header - ETH_HLEN - |
Jamal Hadi Salim | 16dab72 | 2007-07-02 22:39:50 -0700 | [diff] [blame] | 2994 | pkt_dev->pkt_overhead); |
Steven Whitehouse | ca6549a | 2006-03-23 01:10:26 -0800 | [diff] [blame] | 2995 | skb->protocol = protocol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2996 | skb->dev = odev; |
| 2997 | skb->pkt_type = PACKET_HOST; |
| 2998 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 2999 | if (pkt_dev->nfrags <= 0) |
| 3000 | pgh = (struct pktgen_hdr *)skb_put(skb, datalen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | else { |
| 3002 | int frags = pkt_dev->nfrags; |
| 3003 | int i; |
| 3004 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3005 | pgh = (struct pktgen_hdr *)(((char *)(udph)) + 8); |
| 3006 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3007 | if (frags > MAX_SKB_FRAGS) |
| 3008 | frags = MAX_SKB_FRAGS; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3009 | if (datalen > frags * PAGE_SIZE) { |
| 3010 | skb_put(skb, datalen - frags * PAGE_SIZE); |
| 3011 | datalen = frags * PAGE_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3012 | } |
| 3013 | |
| 3014 | i = 0; |
| 3015 | while (datalen > 0) { |
| 3016 | struct page *page = alloc_pages(GFP_KERNEL, 0); |
| 3017 | skb_shinfo(skb)->frags[i].page = page; |
| 3018 | skb_shinfo(skb)->frags[i].page_offset = 0; |
| 3019 | skb_shinfo(skb)->frags[i].size = |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3020 | (datalen < PAGE_SIZE ? datalen : PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3021 | datalen -= skb_shinfo(skb)->frags[i].size; |
| 3022 | skb->len += skb_shinfo(skb)->frags[i].size; |
| 3023 | skb->data_len += skb_shinfo(skb)->frags[i].size; |
| 3024 | i++; |
| 3025 | skb_shinfo(skb)->nr_frags = i; |
| 3026 | } |
| 3027 | |
| 3028 | while (i < frags) { |
| 3029 | int rem; |
| 3030 | |
| 3031 | if (i == 0) |
| 3032 | break; |
| 3033 | |
| 3034 | rem = skb_shinfo(skb)->frags[i - 1].size / 2; |
| 3035 | if (rem == 0) |
| 3036 | break; |
| 3037 | |
| 3038 | skb_shinfo(skb)->frags[i - 1].size -= rem; |
| 3039 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3040 | skb_shinfo(skb)->frags[i] = |
| 3041 | skb_shinfo(skb)->frags[i - 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | get_page(skb_shinfo(skb)->frags[i].page); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3043 | skb_shinfo(skb)->frags[i].page = |
| 3044 | skb_shinfo(skb)->frags[i - 1].page; |
| 3045 | skb_shinfo(skb)->frags[i].page_offset += |
| 3046 | skb_shinfo(skb)->frags[i - 1].size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | skb_shinfo(skb)->frags[i].size = rem; |
| 3048 | i++; |
| 3049 | skb_shinfo(skb)->nr_frags = i; |
| 3050 | } |
| 3051 | } |
| 3052 | |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 3053 | /* Stamp the time, and sequence number, |
| 3054 | * convert them to network byte order |
| 3055 | * should we update cloned packets too ? |
| 3056 | */ |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3057 | if (pgh) { |
| 3058 | struct timeval timestamp; |
| 3059 | |
| 3060 | pgh->pgh_magic = htonl(PKTGEN_MAGIC); |
| 3061 | pgh->seq_num = htonl(pkt_dev->seq_num); |
| 3062 | |
| 3063 | do_gettimeofday(×tamp); |
| 3064 | pgh->tv_sec = htonl(timestamp.tv_sec); |
| 3065 | pgh->tv_usec = htonl(timestamp.tv_usec); |
| 3066 | } |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 3067 | /* pkt_dev->seq_num++; FF: you really mean this? */ |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3068 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3069 | return skb; |
| 3070 | } |
| 3071 | |
Stephen Hemminger | 475ac1e | 2009-08-27 13:55:08 +0000 | [diff] [blame] | 3072 | static struct sk_buff *fill_packet(struct net_device *odev, |
| 3073 | struct pktgen_dev *pkt_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3074 | { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3075 | if (pkt_dev->flags & F_IPV6) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | return fill_packet_ipv6(odev, pkt_dev); |
| 3077 | else |
| 3078 | return fill_packet_ipv4(odev, pkt_dev); |
| 3079 | } |
| 3080 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3081 | static void pktgen_clear_counters(struct pktgen_dev *pkt_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3082 | { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3083 | pkt_dev->seq_num = 1; |
| 3084 | pkt_dev->idle_acc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | pkt_dev->sofar = 0; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3086 | pkt_dev->tx_bytes = 0; |
| 3087 | pkt_dev->errors = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3088 | } |
| 3089 | |
| 3090 | /* Set up structure for sending pkts, clear counters */ |
| 3091 | |
| 3092 | static void pktgen_run(struct pktgen_thread *t) |
| 3093 | { |
Luiz Capitulino | c26a801 | 2006-03-20 22:18:16 -0800 | [diff] [blame] | 3094 | struct pktgen_dev *pkt_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3095 | int started = 0; |
| 3096 | |
Stephen Hemminger | 25c4e53 | 2007-03-04 16:06:47 -0800 | [diff] [blame] | 3097 | pr_debug("pktgen: entering pktgen_run. %p\n", t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3098 | |
| 3099 | if_lock(t); |
Luiz Capitulino | c26a801 | 2006-03-20 22:18:16 -0800 | [diff] [blame] | 3100 | list_for_each_entry(pkt_dev, &t->if_list, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3101 | |
| 3102 | /* |
| 3103 | * setup odev and create initial packet. |
| 3104 | */ |
| 3105 | pktgen_setup_inject(pkt_dev); |
| 3106 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3107 | if (pkt_dev->odev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3108 | pktgen_clear_counters(pkt_dev); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3109 | pkt_dev->running = 1; /* Cranke yeself! */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | pkt_dev->skb = NULL; |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 3111 | pkt_dev->started_at = |
| 3112 | pkt_dev->next_tx = ktime_now(); |
| 3113 | |
Jamal Hadi Salim | 16dab72 | 2007-07-02 22:39:50 -0700 | [diff] [blame] | 3114 | set_pkt_overhead(pkt_dev); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3116 | strcpy(pkt_dev->result, "Starting"); |
| 3117 | started++; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3118 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3119 | strcpy(pkt_dev->result, "Error starting"); |
| 3120 | } |
| 3121 | if_unlock(t); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3122 | if (started) |
| 3123 | t->control &= ~(T_STOP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3124 | } |
| 3125 | |
| 3126 | static void pktgen_stop_all_threads_ifs(void) |
| 3127 | { |
Luiz Capitulino | cdcdbe0 | 2006-03-20 22:16:40 -0800 | [diff] [blame] | 3128 | struct pktgen_thread *t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3129 | |
Stephen Hemminger | 25c4e53 | 2007-03-04 16:06:47 -0800 | [diff] [blame] | 3130 | pr_debug("pktgen: entering pktgen_stop_all_threads_ifs.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3131 | |
Luiz Capitulino | 6146e6a | 2006-03-20 22:24:45 -0800 | [diff] [blame] | 3132 | mutex_lock(&pktgen_thread_lock); |
Luiz Capitulino | cdcdbe0 | 2006-03-20 22:16:40 -0800 | [diff] [blame] | 3133 | |
| 3134 | list_for_each_entry(t, &pktgen_threads, th_list) |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 3135 | t->control |= T_STOP; |
Luiz Capitulino | cdcdbe0 | 2006-03-20 22:16:40 -0800 | [diff] [blame] | 3136 | |
Luiz Capitulino | 6146e6a | 2006-03-20 22:24:45 -0800 | [diff] [blame] | 3137 | mutex_unlock(&pktgen_thread_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3138 | } |
| 3139 | |
Stephen Hemminger | 648fda7 | 2009-08-27 13:55:07 +0000 | [diff] [blame] | 3140 | static int thread_is_running(const struct pktgen_thread *t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3141 | { |
Stephen Hemminger | 648fda7 | 2009-08-27 13:55:07 +0000 | [diff] [blame] | 3142 | const struct pktgen_dev *pkt_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3143 | |
Luiz Capitulino | c26a801 | 2006-03-20 22:18:16 -0800 | [diff] [blame] | 3144 | list_for_each_entry(pkt_dev, &t->if_list, list) |
Stephen Hemminger | 648fda7 | 2009-08-27 13:55:07 +0000 | [diff] [blame] | 3145 | if (pkt_dev->running) |
| 3146 | return 1; |
| 3147 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | } |
| 3149 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3150 | static int pktgen_wait_thread_run(struct pktgen_thread *t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3152 | if_lock(t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3154 | while (thread_is_running(t)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3156 | if_unlock(t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3158 | msleep_interruptible(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3160 | if (signal_pending(current)) |
| 3161 | goto signal; |
| 3162 | if_lock(t); |
| 3163 | } |
| 3164 | if_unlock(t); |
| 3165 | return 1; |
| 3166 | signal: |
| 3167 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 | } |
| 3169 | |
| 3170 | static int pktgen_wait_all_threads_run(void) |
| 3171 | { |
Luiz Capitulino | cdcdbe0 | 2006-03-20 22:16:40 -0800 | [diff] [blame] | 3172 | struct pktgen_thread *t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | int sig = 1; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3174 | |
Luiz Capitulino | 6146e6a | 2006-03-20 22:24:45 -0800 | [diff] [blame] | 3175 | mutex_lock(&pktgen_thread_lock); |
Luiz Capitulino | cdcdbe0 | 2006-03-20 22:16:40 -0800 | [diff] [blame] | 3176 | |
| 3177 | list_for_each_entry(t, &pktgen_threads, th_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3178 | sig = pktgen_wait_thread_run(t); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3179 | if (sig == 0) |
| 3180 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | } |
Luiz Capitulino | cdcdbe0 | 2006-03-20 22:16:40 -0800 | [diff] [blame] | 3182 | |
| 3183 | if (sig == 0) |
| 3184 | list_for_each_entry(t, &pktgen_threads, th_list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | t->control |= (T_STOP); |
Luiz Capitulino | cdcdbe0 | 2006-03-20 22:16:40 -0800 | [diff] [blame] | 3186 | |
Luiz Capitulino | 6146e6a | 2006-03-20 22:24:45 -0800 | [diff] [blame] | 3187 | mutex_unlock(&pktgen_thread_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | return sig; |
| 3189 | } |
| 3190 | |
| 3191 | static void pktgen_run_all_threads(void) |
| 3192 | { |
Luiz Capitulino | cdcdbe0 | 2006-03-20 22:16:40 -0800 | [diff] [blame] | 3193 | struct pktgen_thread *t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3194 | |
Stephen Hemminger | 25c4e53 | 2007-03-04 16:06:47 -0800 | [diff] [blame] | 3195 | pr_debug("pktgen: entering pktgen_run_all_threads.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | |
Luiz Capitulino | 6146e6a | 2006-03-20 22:24:45 -0800 | [diff] [blame] | 3197 | mutex_lock(&pktgen_thread_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | |
Luiz Capitulino | cdcdbe0 | 2006-03-20 22:16:40 -0800 | [diff] [blame] | 3199 | list_for_each_entry(t, &pktgen_threads, th_list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3200 | t->control |= (T_RUN); |
Luiz Capitulino | cdcdbe0 | 2006-03-20 22:16:40 -0800 | [diff] [blame] | 3201 | |
Luiz Capitulino | 6146e6a | 2006-03-20 22:24:45 -0800 | [diff] [blame] | 3202 | mutex_unlock(&pktgen_thread_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 3204 | /* Propagate thread->control */ |
| 3205 | schedule_timeout_interruptible(msecs_to_jiffies(125)); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3207 | pktgen_wait_all_threads_run(); |
| 3208 | } |
| 3209 | |
Jesse Brandeburg | eb37b41 | 2008-11-10 16:48:03 -0800 | [diff] [blame] | 3210 | static void pktgen_reset_all_threads(void) |
| 3211 | { |
| 3212 | struct pktgen_thread *t; |
| 3213 | |
| 3214 | pr_debug("pktgen: entering pktgen_reset_all_threads.\n"); |
| 3215 | |
| 3216 | mutex_lock(&pktgen_thread_lock); |
| 3217 | |
| 3218 | list_for_each_entry(t, &pktgen_threads, th_list) |
| 3219 | t->control |= (T_REMDEVALL); |
| 3220 | |
| 3221 | mutex_unlock(&pktgen_thread_lock); |
| 3222 | |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 3223 | /* Propagate thread->control */ |
| 3224 | schedule_timeout_interruptible(msecs_to_jiffies(125)); |
Jesse Brandeburg | eb37b41 | 2008-11-10 16:48:03 -0800 | [diff] [blame] | 3225 | |
| 3226 | pktgen_wait_all_threads_run(); |
| 3227 | } |
| 3228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | static void show_results(struct pktgen_dev *pkt_dev, int nr_frags) |
| 3230 | { |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 3231 | __u64 bps, mbps, pps; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3232 | char *p = pkt_dev->result; |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 3233 | ktime_t elapsed = ktime_sub(pkt_dev->stopped_at, |
| 3234 | pkt_dev->started_at); |
| 3235 | ktime_t idle = ns_to_ktime(pkt_dev->idle_acc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3236 | |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 3237 | p += sprintf(p, "OK: %llu(c%llu+d%llu) nsec, %llu (%dbyte,%dfrags)\n", |
| 3238 | (unsigned long long)ktime_to_us(elapsed), |
| 3239 | (unsigned long long)ktime_to_us(ktime_sub(elapsed, idle)), |
| 3240 | (unsigned long long)ktime_to_us(idle), |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3241 | (unsigned long long)pkt_dev->sofar, |
| 3242 | pkt_dev->cur_pkt_size, nr_frags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3243 | |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 3244 | pps = div64_u64(pkt_dev->sofar * NSEC_PER_SEC, |
| 3245 | ktime_to_ns(elapsed)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3247 | bps = pps * 8 * pkt_dev->cur_pkt_size; |
| 3248 | |
| 3249 | mbps = bps; |
| 3250 | do_div(mbps, 1000000); |
| 3251 | p += sprintf(p, " %llupps %lluMb/sec (%llubps) errors: %llu", |
| 3252 | (unsigned long long)pps, |
| 3253 | (unsigned long long)mbps, |
| 3254 | (unsigned long long)bps, |
| 3255 | (unsigned long long)pkt_dev->errors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3256 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3257 | |
| 3258 | /* Set stopped-at timer, remove from running list, do counters & statistics */ |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3259 | static int pktgen_stop_device(struct pktgen_dev *pkt_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3261 | int nr_frags = pkt_dev->skb ? skb_shinfo(pkt_dev->skb)->nr_frags : -1; |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 3262 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3263 | if (!pkt_dev->running) { |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 3264 | printk(KERN_WARNING "pktgen: interface: %s is already " |
| 3265 | "stopped\n", pkt_dev->odev->name); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3266 | return -EINVAL; |
| 3267 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3268 | |
Stephen Hemminger | 3bda06a | 2009-08-27 13:55:10 +0000 | [diff] [blame] | 3269 | kfree_skb(pkt_dev->skb); |
| 3270 | pkt_dev->skb = NULL; |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 3271 | pkt_dev->stopped_at = ktime_now(); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3272 | pkt_dev->running = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3273 | |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 3274 | show_results(pkt_dev, nr_frags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3275 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3276 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3277 | } |
| 3278 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3279 | static struct pktgen_dev *next_to_run(struct pktgen_thread *t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3280 | { |
Luiz Capitulino | c26a801 | 2006-03-20 22:18:16 -0800 | [diff] [blame] | 3281 | struct pktgen_dev *pkt_dev, *best = NULL; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3282 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3283 | if_lock(t); |
| 3284 | |
Luiz Capitulino | c26a801 | 2006-03-20 22:18:16 -0800 | [diff] [blame] | 3285 | list_for_each_entry(pkt_dev, &t->if_list, list) { |
| 3286 | if (!pkt_dev->running) |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3287 | continue; |
| 3288 | if (best == NULL) |
Luiz Capitulino | c26a801 | 2006-03-20 22:18:16 -0800 | [diff] [blame] | 3289 | best = pkt_dev; |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 3290 | else if (ktime_lt(pkt_dev->next_tx, best->next_tx)) |
Luiz Capitulino | c26a801 | 2006-03-20 22:18:16 -0800 | [diff] [blame] | 3291 | best = pkt_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3292 | } |
| 3293 | if_unlock(t); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3294 | return best; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3295 | } |
| 3296 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3297 | static void pktgen_stop(struct pktgen_thread *t) |
| 3298 | { |
Luiz Capitulino | c26a801 | 2006-03-20 22:18:16 -0800 | [diff] [blame] | 3299 | struct pktgen_dev *pkt_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3300 | |
Stephen Hemminger | 25c4e53 | 2007-03-04 16:06:47 -0800 | [diff] [blame] | 3301 | pr_debug("pktgen: entering pktgen_stop\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3302 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3303 | if_lock(t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3304 | |
Luiz Capitulino | c26a801 | 2006-03-20 22:18:16 -0800 | [diff] [blame] | 3305 | list_for_each_entry(pkt_dev, &t->if_list, list) { |
| 3306 | pktgen_stop_device(pkt_dev); |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 3307 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3308 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3309 | if_unlock(t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3310 | } |
| 3311 | |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 3312 | /* |
| 3313 | * one of our devices needs to be removed - find it |
| 3314 | * and remove it |
| 3315 | */ |
| 3316 | static void pktgen_rem_one_if(struct pktgen_thread *t) |
| 3317 | { |
Luiz Capitulino | c26a801 | 2006-03-20 22:18:16 -0800 | [diff] [blame] | 3318 | struct list_head *q, *n; |
| 3319 | struct pktgen_dev *cur; |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 3320 | |
Stephen Hemminger | 25c4e53 | 2007-03-04 16:06:47 -0800 | [diff] [blame] | 3321 | pr_debug("pktgen: entering pktgen_rem_one_if\n"); |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 3322 | |
| 3323 | if_lock(t); |
| 3324 | |
Luiz Capitulino | c26a801 | 2006-03-20 22:18:16 -0800 | [diff] [blame] | 3325 | list_for_each_safe(q, n, &t->if_list) { |
| 3326 | cur = list_entry(q, struct pktgen_dev, list); |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 3327 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3328 | if (!cur->removal_mark) |
| 3329 | continue; |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 3330 | |
Wei Yongjun | 86dc1ad | 2009-02-25 00:31:54 +0000 | [diff] [blame] | 3331 | kfree_skb(cur->skb); |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 3332 | cur->skb = NULL; |
| 3333 | |
| 3334 | pktgen_remove_device(t, cur); |
| 3335 | |
| 3336 | break; |
| 3337 | } |
| 3338 | |
| 3339 | if_unlock(t); |
| 3340 | } |
| 3341 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3342 | static void pktgen_rem_all_ifs(struct pktgen_thread *t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3343 | { |
Luiz Capitulino | c26a801 | 2006-03-20 22:18:16 -0800 | [diff] [blame] | 3344 | struct list_head *q, *n; |
| 3345 | struct pktgen_dev *cur; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3346 | |
| 3347 | /* Remove all devices, free mem */ |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 3348 | |
Stephen Hemminger | 25c4e53 | 2007-03-04 16:06:47 -0800 | [diff] [blame] | 3349 | pr_debug("pktgen: entering pktgen_rem_all_ifs\n"); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3350 | if_lock(t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3351 | |
Luiz Capitulino | c26a801 | 2006-03-20 22:18:16 -0800 | [diff] [blame] | 3352 | list_for_each_safe(q, n, &t->if_list) { |
| 3353 | cur = list_entry(q, struct pktgen_dev, list); |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 3354 | |
Wei Yongjun | 86dc1ad | 2009-02-25 00:31:54 +0000 | [diff] [blame] | 3355 | kfree_skb(cur->skb); |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 3356 | cur->skb = NULL; |
| 3357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3358 | pktgen_remove_device(t, cur); |
| 3359 | } |
| 3360 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3361 | if_unlock(t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3362 | } |
| 3363 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3364 | static void pktgen_rem_thread(struct pktgen_thread *t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3365 | { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3366 | /* Remove from the thread list */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | |
David S. Miller | ee74baa | 2007-01-01 20:51:53 -0800 | [diff] [blame] | 3368 | remove_proc_entry(t->tsk->comm, pg_proc_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3369 | |
Luiz Capitulino | 6146e6a | 2006-03-20 22:24:45 -0800 | [diff] [blame] | 3370 | mutex_lock(&pktgen_thread_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3371 | |
Luiz Capitulino | cdcdbe0 | 2006-03-20 22:16:40 -0800 | [diff] [blame] | 3372 | list_del(&t->th_list); |
| 3373 | |
Luiz Capitulino | 6146e6a | 2006-03-20 22:24:45 -0800 | [diff] [blame] | 3374 | mutex_unlock(&pktgen_thread_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | } |
| 3376 | |
Stephen Hemminger | ef87979 | 2009-09-22 19:41:43 +0000 | [diff] [blame] | 3377 | static void pktgen_resched(struct pktgen_dev *pkt_dev) |
Stephen Hemminger | 3791dec | 2009-08-27 13:55:11 +0000 | [diff] [blame] | 3378 | { |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 3379 | ktime_t idle_start = ktime_now(); |
Stephen Hemminger | ef87979 | 2009-09-22 19:41:43 +0000 | [diff] [blame] | 3380 | schedule(); |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 3381 | pkt_dev->idle_acc += ktime_to_ns(ktime_sub(ktime_now(), idle_start)); |
Stephen Hemminger | 3791dec | 2009-08-27 13:55:11 +0000 | [diff] [blame] | 3382 | } |
| 3383 | |
Stephen Hemminger | ef87979 | 2009-09-22 19:41:43 +0000 | [diff] [blame] | 3384 | static void pktgen_wait_for_skb(struct pktgen_dev *pkt_dev) |
| 3385 | { |
| 3386 | ktime_t idle_start = ktime_now(); |
| 3387 | |
| 3388 | while (atomic_read(&(pkt_dev->skb->users)) != 1) { |
| 3389 | if (signal_pending(current)) |
| 3390 | break; |
| 3391 | |
| 3392 | if (need_resched()) |
| 3393 | pktgen_resched(pkt_dev); |
| 3394 | else |
| 3395 | cpu_relax(); |
| 3396 | } |
| 3397 | pkt_dev->idle_acc += ktime_to_ns(ktime_sub(ktime_now(), idle_start)); |
| 3398 | } |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 3399 | |
Stephen Hemminger | 475ac1e | 2009-08-27 13:55:08 +0000 | [diff] [blame] | 3400 | static void pktgen_xmit(struct pktgen_dev *pkt_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3401 | { |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 3402 | struct net_device *odev = pkt_dev->odev; |
Stephen Hemminger | 6fef4c0 | 2009-08-31 19:50:41 +0000 | [diff] [blame] | 3403 | netdev_tx_t (*xmit)(struct sk_buff *, struct net_device *) |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 3404 | = odev->netdev_ops->ndo_start_xmit; |
David S. Miller | fd2ea0a | 2008-07-17 01:56:23 -0700 | [diff] [blame] | 3405 | struct netdev_queue *txq; |
David S. Miller | fd2ea0a | 2008-07-17 01:56:23 -0700 | [diff] [blame] | 3406 | u16 queue_map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3407 | int ret; |
| 3408 | |
Stephen Hemminger | ef87979 | 2009-09-22 19:41:43 +0000 | [diff] [blame] | 3409 | /* If device is offline, then don't send */ |
| 3410 | if (unlikely(!netif_running(odev) || !netif_carrier_ok(odev))) { |
| 3411 | pktgen_stop_device(pkt_dev); |
Stephen Hemminger | 3791dec | 2009-08-27 13:55:11 +0000 | [diff] [blame] | 3412 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3414 | |
Stephen Hemminger | ef87979 | 2009-09-22 19:41:43 +0000 | [diff] [blame] | 3415 | /* This is max DELAY, this has special meaning of |
| 3416 | * "never transmit" |
| 3417 | */ |
| 3418 | if (unlikely(pkt_dev->delay == ULLONG_MAX)) { |
| 3419 | pkt_dev->next_tx = ktime_add_ns(ktime_now(), ULONG_MAX); |
| 3420 | return; |
| 3421 | } |
| 3422 | |
| 3423 | /* If no skb or clone count exhausted then get new one */ |
Stephen Hemminger | 7d7bb1c | 2009-08-27 13:55:12 +0000 | [diff] [blame] | 3424 | if (!pkt_dev->skb || (pkt_dev->last_ok && |
| 3425 | ++pkt_dev->clone_count >= pkt_dev->clone_skb)) { |
| 3426 | /* build a new pkt */ |
| 3427 | kfree_skb(pkt_dev->skb); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3428 | |
Stephen Hemminger | 7d7bb1c | 2009-08-27 13:55:12 +0000 | [diff] [blame] | 3429 | pkt_dev->skb = fill_packet(odev, pkt_dev); |
| 3430 | if (pkt_dev->skb == NULL) { |
| 3431 | printk(KERN_ERR "pktgen: ERROR: couldn't " |
| 3432 | "allocate skb in fill_packet.\n"); |
| 3433 | schedule(); |
| 3434 | pkt_dev->clone_count--; /* back out increment, OOM */ |
| 3435 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3436 | } |
Stephen Hemminger | 7d7bb1c | 2009-08-27 13:55:12 +0000 | [diff] [blame] | 3437 | |
| 3438 | pkt_dev->allocated_skbs++; |
| 3439 | pkt_dev->clone_count = 0; /* reset counter */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3440 | } |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 3441 | |
Stephen Hemminger | ef87979 | 2009-09-22 19:41:43 +0000 | [diff] [blame] | 3442 | if (pkt_dev->delay && pkt_dev->last_ok) |
| 3443 | spin(pkt_dev, pkt_dev->next_tx); |
| 3444 | |
David S. Miller | fd2ea0a | 2008-07-17 01:56:23 -0700 | [diff] [blame] | 3445 | queue_map = skb_get_queue_mapping(pkt_dev->skb); |
| 3446 | txq = netdev_get_tx_queue(odev, queue_map); |
| 3447 | |
| 3448 | __netif_tx_lock_bh(txq); |
Stephen Hemminger | ef87979 | 2009-09-22 19:41:43 +0000 | [diff] [blame] | 3449 | atomic_inc(&(pkt_dev->skb->users)); |
| 3450 | |
Stephen Hemminger | 3791dec | 2009-08-27 13:55:11 +0000 | [diff] [blame] | 3451 | if (unlikely(netif_tx_queue_stopped(txq) || netif_tx_queue_frozen(txq))) |
Stephen Hemminger | ef87979 | 2009-09-22 19:41:43 +0000 | [diff] [blame] | 3452 | ret = NETDEV_TX_BUSY; |
| 3453 | else |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 3454 | ret = (*xmit)(pkt_dev->skb, odev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | |
Stephen Hemminger | ef87979 | 2009-09-22 19:41:43 +0000 | [diff] [blame] | 3456 | switch (ret) { |
| 3457 | case NETDEV_TX_OK: |
| 3458 | txq_trans_update(txq); |
| 3459 | pkt_dev->last_ok = 1; |
| 3460 | pkt_dev->sofar++; |
| 3461 | pkt_dev->seq_num++; |
| 3462 | pkt_dev->tx_bytes += pkt_dev->cur_pkt_size; |
| 3463 | break; |
| 3464 | default: /* Drivers are not supposed to return other values! */ |
| 3465 | if (net_ratelimit()) |
| 3466 | pr_info("pktgen: %s xmit error: %d\n", |
| 3467 | odev->name, ret); |
| 3468 | pkt_dev->errors++; |
| 3469 | /* fallthru */ |
| 3470 | case NETDEV_TX_LOCKED: |
| 3471 | case NETDEV_TX_BUSY: |
| 3472 | /* Retry it next time */ |
| 3473 | atomic_dec(&(pkt_dev->skb->users)); |
| 3474 | pkt_dev->last_ok = 0; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3475 | } |
David S. Miller | fd2ea0a | 2008-07-17 01:56:23 -0700 | [diff] [blame] | 3476 | __netif_tx_unlock_bh(txq); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | /* If pkt_dev->count is zero, then run forever */ |
| 3479 | if ((pkt_dev->count != 0) && (pkt_dev->sofar >= pkt_dev->count)) { |
Stephen Hemminger | ef87979 | 2009-09-22 19:41:43 +0000 | [diff] [blame] | 3480 | pktgen_wait_for_skb(pkt_dev); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3482 | /* Done with this */ |
| 3483 | pktgen_stop_device(pkt_dev); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3484 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3485 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3486 | |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 3487 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3488 | * Main loop of the thread goes here |
| 3489 | */ |
| 3490 | |
David S. Miller | ee74baa | 2007-01-01 20:51:53 -0800 | [diff] [blame] | 3491 | static int pktgen_thread_worker(void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3492 | { |
| 3493 | DEFINE_WAIT(wait); |
David S. Miller | ee74baa | 2007-01-01 20:51:53 -0800 | [diff] [blame] | 3494 | struct pktgen_thread *t = arg; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3495 | struct pktgen_dev *pkt_dev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3496 | int cpu = t->cpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3497 | |
David S. Miller | ee74baa | 2007-01-01 20:51:53 -0800 | [diff] [blame] | 3498 | BUG_ON(smp_processor_id() != cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3499 | |
| 3500 | init_waitqueue_head(&t->queue); |
Denis V. Lunev | d3ede32 | 2008-05-20 15:12:44 -0700 | [diff] [blame] | 3501 | complete(&t->start_done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3502 | |
Stephen Hemminger | 63adc6f | 2009-08-27 13:55:19 +0000 | [diff] [blame] | 3503 | pr_debug("pktgen: starting pktgen/%d: pid=%d\n", |
| 3504 | cpu, task_pid_nr(current)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3505 | |
David S. Miller | ee74baa | 2007-01-01 20:51:53 -0800 | [diff] [blame] | 3506 | set_current_state(TASK_INTERRUPTIBLE); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3507 | |
Rafael J. Wysocki | 8314418 | 2007-07-17 04:03:35 -0700 | [diff] [blame] | 3508 | set_freezable(); |
| 3509 | |
David S. Miller | ee74baa | 2007-01-01 20:51:53 -0800 | [diff] [blame] | 3510 | while (!kthread_should_stop()) { |
| 3511 | pkt_dev = next_to_run(t); |
| 3512 | |
Stephen Hemminger | ef87979 | 2009-09-22 19:41:43 +0000 | [diff] [blame] | 3513 | if (unlikely(!pkt_dev && t->control == 0)) { |
| 3514 | wait_event_interruptible_timeout(t->queue, |
| 3515 | t->control != 0, |
| 3516 | HZ/10); |
| 3517 | continue; |
David S. Miller | ee74baa | 2007-01-01 20:51:53 -0800 | [diff] [blame] | 3518 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3519 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3520 | __set_current_state(TASK_RUNNING); |
| 3521 | |
Stephen Hemminger | ef87979 | 2009-09-22 19:41:43 +0000 | [diff] [blame] | 3522 | if (likely(pkt_dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3523 | pktgen_xmit(pkt_dev); |
| 3524 | |
Stephen Hemminger | ef87979 | 2009-09-22 19:41:43 +0000 | [diff] [blame] | 3525 | if (need_resched()) |
| 3526 | pktgen_resched(pkt_dev); |
| 3527 | else |
| 3528 | cpu_relax(); |
| 3529 | } |
| 3530 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3531 | if (t->control & T_STOP) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3532 | pktgen_stop(t); |
| 3533 | t->control &= ~(T_STOP); |
| 3534 | } |
| 3535 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3536 | if (t->control & T_RUN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3537 | pktgen_run(t); |
| 3538 | t->control &= ~(T_RUN); |
| 3539 | } |
| 3540 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3541 | if (t->control & T_REMDEVALL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3542 | pktgen_rem_all_ifs(t); |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 3543 | t->control &= ~(T_REMDEVALL); |
| 3544 | } |
| 3545 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3546 | if (t->control & T_REMDEV) { |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 3547 | pktgen_rem_one_if(t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3548 | t->control &= ~(T_REMDEV); |
| 3549 | } |
| 3550 | |
Andrew Morton | 09fe3ef | 2007-04-12 14:45:32 -0700 | [diff] [blame] | 3551 | try_to_freeze(); |
| 3552 | |
David S. Miller | ee74baa | 2007-01-01 20:51:53 -0800 | [diff] [blame] | 3553 | set_current_state(TASK_INTERRUPTIBLE); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3554 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3555 | |
Stephen Hemminger | 25c4e53 | 2007-03-04 16:06:47 -0800 | [diff] [blame] | 3556 | pr_debug("pktgen: %s stopping all device\n", t->tsk->comm); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3557 | pktgen_stop(t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3558 | |
Stephen Hemminger | 25c4e53 | 2007-03-04 16:06:47 -0800 | [diff] [blame] | 3559 | pr_debug("pktgen: %s removing all device\n", t->tsk->comm); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3560 | pktgen_rem_all_ifs(t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3561 | |
Stephen Hemminger | 25c4e53 | 2007-03-04 16:06:47 -0800 | [diff] [blame] | 3562 | pr_debug("pktgen: %s removing thread.\n", t->tsk->comm); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3563 | pktgen_rem_thread(t); |
Luiz Capitulino | cdcdbe0 | 2006-03-20 22:16:40 -0800 | [diff] [blame] | 3564 | |
David S. Miller | ee74baa | 2007-01-01 20:51:53 -0800 | [diff] [blame] | 3565 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3566 | } |
| 3567 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3568 | static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t, |
| 3569 | const char *ifname) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3570 | { |
Luiz Capitulino | c26a801 | 2006-03-20 22:18:16 -0800 | [diff] [blame] | 3571 | struct pktgen_dev *p, *pkt_dev = NULL; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3572 | if_lock(t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3573 | |
Luiz Capitulino | c26a801 | 2006-03-20 22:18:16 -0800 | [diff] [blame] | 3574 | list_for_each_entry(p, &t->if_list, list) |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 3575 | if (strncmp(p->odev->name, ifname, IFNAMSIZ) == 0) { |
Luiz Capitulino | c26a801 | 2006-03-20 22:18:16 -0800 | [diff] [blame] | 3576 | pkt_dev = p; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3577 | break; |
| 3578 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3579 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3580 | if_unlock(t); |
Stephen Hemminger | 25c4e53 | 2007-03-04 16:06:47 -0800 | [diff] [blame] | 3581 | pr_debug("pktgen: find_dev(%s) returning %p\n", ifname, pkt_dev); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3582 | return pkt_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3583 | } |
| 3584 | |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 3585 | /* |
| 3586 | * Adds a dev at front of if_list. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3587 | */ |
| 3588 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3589 | static int add_dev_to_thread(struct pktgen_thread *t, |
| 3590 | struct pktgen_dev *pkt_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3591 | { |
| 3592 | int rv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3593 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3594 | if_lock(t); |
| 3595 | |
| 3596 | if (pkt_dev->pg_thread) { |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 3597 | printk(KERN_ERR "pktgen: ERROR: already assigned " |
| 3598 | "to a thread.\n"); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3599 | rv = -EBUSY; |
| 3600 | goto out; |
| 3601 | } |
Luiz Capitulino | c26a801 | 2006-03-20 22:18:16 -0800 | [diff] [blame] | 3602 | |
| 3603 | list_add(&pkt_dev->list, &t->if_list); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3604 | pkt_dev->pg_thread = t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3605 | pkt_dev->running = 0; |
| 3606 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3607 | out: |
| 3608 | if_unlock(t); |
| 3609 | return rv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3610 | } |
| 3611 | |
| 3612 | /* Called under thread lock */ |
| 3613 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3614 | static int pktgen_add_device(struct pktgen_thread *t, const char *ifname) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3615 | { |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3616 | struct pktgen_dev *pkt_dev; |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 3617 | int err; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | /* We don't allow a device to be on several threads */ |
| 3620 | |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 3621 | pkt_dev = __pktgen_NN_threads(ifname, FIND); |
| 3622 | if (pkt_dev) { |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 3623 | printk(KERN_ERR "pktgen: ERROR: interface already used.\n"); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3624 | return -EBUSY; |
| 3625 | } |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 3626 | |
| 3627 | pkt_dev = kzalloc(sizeof(struct pktgen_dev), GFP_KERNEL); |
| 3628 | if (!pkt_dev) |
| 3629 | return -ENOMEM; |
| 3630 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3631 | pkt_dev->flows = vmalloc(MAX_CFLOWS * sizeof(struct flow_state)); |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 3632 | if (pkt_dev->flows == NULL) { |
| 3633 | kfree(pkt_dev); |
| 3634 | return -ENOMEM; |
| 3635 | } |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3636 | memset(pkt_dev->flows, 0, MAX_CFLOWS * sizeof(struct flow_state)); |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 3637 | |
Arthur Kepner | 95ed63f | 2006-03-20 21:26:56 -0800 | [diff] [blame] | 3638 | pkt_dev->removal_mark = 0; |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 3639 | pkt_dev->min_pkt_size = ETH_ZLEN; |
| 3640 | pkt_dev->max_pkt_size = ETH_ZLEN; |
| 3641 | pkt_dev->nfrags = 0; |
| 3642 | pkt_dev->clone_skb = pg_clone_skb_d; |
Stephen Hemminger | fd29cf7 | 2009-08-27 13:55:16 +0000 | [diff] [blame] | 3643 | pkt_dev->delay = pg_delay_d; |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 3644 | pkt_dev->count = pg_count_d; |
| 3645 | pkt_dev->sofar = 0; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3646 | pkt_dev->udp_src_min = 9; /* sink port */ |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 3647 | pkt_dev->udp_src_max = 9; |
| 3648 | pkt_dev->udp_dst_min = 9; |
| 3649 | pkt_dev->udp_dst_max = 9; |
| 3650 | |
Francesco Fondelli | 34954dd | 2006-09-27 16:30:44 -0700 | [diff] [blame] | 3651 | pkt_dev->vlan_p = 0; |
| 3652 | pkt_dev->vlan_cfi = 0; |
| 3653 | pkt_dev->vlan_id = 0xffff; |
| 3654 | pkt_dev->svlan_p = 0; |
| 3655 | pkt_dev->svlan_cfi = 0; |
| 3656 | pkt_dev->svlan_id = 0xffff; |
| 3657 | |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 3658 | err = pktgen_setup_dev(pkt_dev, ifname); |
| 3659 | if (err) |
| 3660 | goto out1; |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 3661 | |
Denis V. Lunev | 5efdccb | 2008-05-02 02:46:22 -0700 | [diff] [blame] | 3662 | pkt_dev->entry = proc_create_data(ifname, 0600, pg_proc_dir, |
| 3663 | &pktgen_if_fops, pkt_dev); |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 3664 | if (!pkt_dev->entry) { |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 3665 | printk(KERN_ERR "pktgen: cannot create %s/%s procfs entry.\n", |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 3666 | PG_PROC_DIR, ifname); |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 3667 | err = -EINVAL; |
| 3668 | goto out2; |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 3669 | } |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 3670 | #ifdef CONFIG_XFRM |
| 3671 | pkt_dev->ipsmode = XFRM_MODE_TRANSPORT; |
| 3672 | pkt_dev->ipsproto = IPPROTO_ESP; |
| 3673 | #endif |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 3674 | |
| 3675 | return add_dev_to_thread(t, pkt_dev); |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 3676 | out2: |
| 3677 | dev_put(pkt_dev->odev); |
| 3678 | out1: |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 3679 | #ifdef CONFIG_XFRM |
| 3680 | free_SAs(pkt_dev); |
| 3681 | #endif |
Figo.zhang | 1d0ebfe | 2009-06-08 00:40:35 -0700 | [diff] [blame] | 3682 | vfree(pkt_dev->flows); |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 3683 | kfree(pkt_dev); |
| 3684 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3685 | } |
| 3686 | |
David S. Miller | ee74baa | 2007-01-01 20:51:53 -0800 | [diff] [blame] | 3687 | static int __init pktgen_create_thread(int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3688 | { |
Luiz Capitulino | cdcdbe0 | 2006-03-20 22:16:40 -0800 | [diff] [blame] | 3689 | struct pktgen_thread *t; |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 3690 | struct proc_dir_entry *pe; |
David S. Miller | ee74baa | 2007-01-01 20:51:53 -0800 | [diff] [blame] | 3691 | struct task_struct *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3692 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3693 | t = kzalloc(sizeof(struct pktgen_thread), GFP_KERNEL); |
| 3694 | if (!t) { |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 3695 | printk(KERN_ERR "pktgen: ERROR: out of memory, can't " |
| 3696 | "create new thread.\n"); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3697 | return -ENOMEM; |
| 3698 | } |
| 3699 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3700 | spin_lock_init(&t->if_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3701 | t->cpu = cpu; |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3702 | |
David S. Miller | ee74baa | 2007-01-01 20:51:53 -0800 | [diff] [blame] | 3703 | INIT_LIST_HEAD(&t->if_list); |
| 3704 | |
| 3705 | list_add_tail(&t->th_list, &pktgen_threads); |
Denis V. Lunev | d3ede32 | 2008-05-20 15:12:44 -0700 | [diff] [blame] | 3706 | init_completion(&t->start_done); |
David S. Miller | ee74baa | 2007-01-01 20:51:53 -0800 | [diff] [blame] | 3707 | |
| 3708 | p = kthread_create(pktgen_thread_worker, t, "kpktgend_%d", cpu); |
| 3709 | if (IS_ERR(p)) { |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 3710 | printk(KERN_ERR "pktgen: kernel_thread() failed " |
| 3711 | "for cpu %d\n", t->cpu); |
David S. Miller | ee74baa | 2007-01-01 20:51:53 -0800 | [diff] [blame] | 3712 | list_del(&t->th_list); |
| 3713 | kfree(t); |
| 3714 | return PTR_ERR(p); |
| 3715 | } |
| 3716 | kthread_bind(p, cpu); |
| 3717 | t->tsk = p; |
| 3718 | |
Denis V. Lunev | 5efdccb | 2008-05-02 02:46:22 -0700 | [diff] [blame] | 3719 | pe = proc_create_data(t->tsk->comm, 0600, pg_proc_dir, |
| 3720 | &pktgen_thread_fops, t); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3721 | if (!pe) { |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 3722 | printk(KERN_ERR "pktgen: cannot create %s/%s procfs entry.\n", |
David S. Miller | ee74baa | 2007-01-01 20:51:53 -0800 | [diff] [blame] | 3723 | PG_PROC_DIR, t->tsk->comm); |
| 3724 | kthread_stop(p); |
| 3725 | list_del(&t->th_list); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3726 | kfree(t); |
| 3727 | return -EINVAL; |
| 3728 | } |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 3729 | |
David S. Miller | ee74baa | 2007-01-01 20:51:53 -0800 | [diff] [blame] | 3730 | wake_up_process(p); |
Denis V. Lunev | d3ede32 | 2008-05-20 15:12:44 -0700 | [diff] [blame] | 3731 | wait_for_completion(&t->start_done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3732 | |
| 3733 | return 0; |
| 3734 | } |
| 3735 | |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 3736 | /* |
| 3737 | * Removes a device from the thread if_list. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3738 | */ |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3739 | static void _rem_dev_from_if_list(struct pktgen_thread *t, |
| 3740 | struct pktgen_dev *pkt_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3741 | { |
Luiz Capitulino | c26a801 | 2006-03-20 22:18:16 -0800 | [diff] [blame] | 3742 | struct list_head *q, *n; |
| 3743 | struct pktgen_dev *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3744 | |
Luiz Capitulino | c26a801 | 2006-03-20 22:18:16 -0800 | [diff] [blame] | 3745 | list_for_each_safe(q, n, &t->if_list) { |
| 3746 | p = list_entry(q, struct pktgen_dev, list); |
| 3747 | if (p == pkt_dev) |
| 3748 | list_del(&p->list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3749 | } |
| 3750 | } |
| 3751 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3752 | static int pktgen_remove_device(struct pktgen_thread *t, |
| 3753 | struct pktgen_dev *pkt_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3754 | { |
| 3755 | |
Stephen Hemminger | 25c4e53 | 2007-03-04 16:06:47 -0800 | [diff] [blame] | 3756 | pr_debug("pktgen: remove_device pkt_dev=%p\n", pkt_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3757 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3758 | if (pkt_dev->running) { |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 3759 | printk(KERN_WARNING "pktgen: WARNING: trying to remove a " |
| 3760 | "running interface, stopping it now.\n"); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3761 | pktgen_stop_device(pkt_dev); |
| 3762 | } |
| 3763 | |
| 3764 | /* Dis-associate from the interface */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3765 | |
| 3766 | if (pkt_dev->odev) { |
| 3767 | dev_put(pkt_dev->odev); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3768 | pkt_dev->odev = NULL; |
| 3769 | } |
| 3770 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3771 | /* And update the thread if_list */ |
| 3772 | |
| 3773 | _rem_dev_from_if_list(t, pkt_dev); |
| 3774 | |
Stephen Hemminger | 39df232 | 2007-03-04 16:11:51 -0800 | [diff] [blame] | 3775 | if (pkt_dev->entry) |
| 3776 | remove_proc_entry(pkt_dev->entry->name, pg_proc_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3777 | |
Jamal Hadi Salim | a553e4a | 2007-07-02 22:41:59 -0700 | [diff] [blame] | 3778 | #ifdef CONFIG_XFRM |
| 3779 | free_SAs(pkt_dev); |
| 3780 | #endif |
Figo.zhang | 1d0ebfe | 2009-06-08 00:40:35 -0700 | [diff] [blame] | 3781 | vfree(pkt_dev->flows); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3782 | kfree(pkt_dev); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3783 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3784 | } |
| 3785 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3786 | static int __init pg_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3787 | { |
| 3788 | int cpu; |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 3789 | struct proc_dir_entry *pe; |
| 3790 | |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 3791 | printk(KERN_INFO "%s", version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3792 | |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 3793 | pg_proc_dir = proc_mkdir(PG_PROC_DIR, init_net.proc_net); |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 3794 | if (!pg_proc_dir) |
| 3795 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3796 | |
Wang Chen | 25296d5 | 2008-02-28 14:11:49 -0800 | [diff] [blame] | 3797 | pe = proc_create(PGCTRL, 0600, pg_proc_dir, &pktgen_fops); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3798 | if (pe == NULL) { |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 3799 | printk(KERN_ERR "pktgen: ERROR: cannot create %s " |
| 3800 | "procfs entry.\n", PGCTRL); |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 3801 | proc_net_remove(&init_net, PG_PROC_DIR); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3802 | return -EINVAL; |
| 3803 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3805 | /* Register us to receive netdevice events */ |
| 3806 | register_netdevice_notifier(&pktgen_notifier_block); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3807 | |
John Hawkes | 670c02c | 2005-10-13 09:30:31 -0700 | [diff] [blame] | 3808 | for_each_online_cpu(cpu) { |
Luiz Capitulino | 8024bb2 | 2006-03-20 22:17:55 -0800 | [diff] [blame] | 3809 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3810 | |
David S. Miller | ee74baa | 2007-01-01 20:51:53 -0800 | [diff] [blame] | 3811 | err = pktgen_create_thread(cpu); |
Luiz Capitulino | 8024bb2 | 2006-03-20 22:17:55 -0800 | [diff] [blame] | 3812 | if (err) |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 3813 | printk(KERN_WARNING "pktgen: WARNING: Cannot create " |
| 3814 | "thread for cpu %d (%d)\n", cpu, err); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3815 | } |
Luiz Capitulino | 8024bb2 | 2006-03-20 22:17:55 -0800 | [diff] [blame] | 3816 | |
| 3817 | if (list_empty(&pktgen_threads)) { |
David S. Miller | 25a8b25 | 2007-07-30 16:11:48 -0700 | [diff] [blame] | 3818 | printk(KERN_ERR "pktgen: ERROR: Initialization failed for " |
| 3819 | "all threads\n"); |
Luiz Capitulino | 8024bb2 | 2006-03-20 22:17:55 -0800 | [diff] [blame] | 3820 | unregister_netdevice_notifier(&pktgen_notifier_block); |
| 3821 | remove_proc_entry(PGCTRL, pg_proc_dir); |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 3822 | proc_net_remove(&init_net, PG_PROC_DIR); |
Luiz Capitulino | 8024bb2 | 2006-03-20 22:17:55 -0800 | [diff] [blame] | 3823 | return -ENODEV; |
| 3824 | } |
| 3825 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3826 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3827 | } |
| 3828 | |
| 3829 | static void __exit pg_cleanup(void) |
| 3830 | { |
Luiz Capitulino | cdcdbe0 | 2006-03-20 22:16:40 -0800 | [diff] [blame] | 3831 | struct pktgen_thread *t; |
| 3832 | struct list_head *q, *n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3833 | wait_queue_head_t queue; |
| 3834 | init_waitqueue_head(&queue); |
| 3835 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3836 | /* Stop all interfaces & threads */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3837 | |
Luiz Capitulino | cdcdbe0 | 2006-03-20 22:16:40 -0800 | [diff] [blame] | 3838 | list_for_each_safe(q, n, &pktgen_threads) { |
| 3839 | t = list_entry(q, struct pktgen_thread, th_list); |
David S. Miller | ee74baa | 2007-01-01 20:51:53 -0800 | [diff] [blame] | 3840 | kthread_stop(t->tsk); |
| 3841 | kfree(t); |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3842 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3843 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3844 | /* Un-register us from receiving netdevice events */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3845 | unregister_netdevice_notifier(&pktgen_notifier_block); |
| 3846 | |
Luiz Capitulino | 222f180 | 2006-03-20 22:16:13 -0800 | [diff] [blame] | 3847 | /* Clean up proc file system */ |
Stephen Hemminger | d50a6b5 | 2005-10-14 15:42:33 -0700 | [diff] [blame] | 3848 | remove_proc_entry(PGCTRL, pg_proc_dir); |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 3849 | proc_net_remove(&init_net, PG_PROC_DIR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3850 | } |
| 3851 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3852 | module_init(pg_init); |
| 3853 | module_exit(pg_cleanup); |
| 3854 | |
Stephen Hemminger | c3d2f52 | 2009-08-27 13:55:20 +0000 | [diff] [blame] | 3855 | MODULE_AUTHOR("Robert Olsson <robert.olsson@its.uu.se>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3856 | MODULE_DESCRIPTION("Packet Generator tool"); |
| 3857 | MODULE_LICENSE("GPL"); |
Stephen Hemminger | c3d2f52 | 2009-08-27 13:55:20 +0000 | [diff] [blame] | 3858 | MODULE_VERSION(VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3859 | module_param(pg_count_d, int, 0); |
Stephen Hemminger | c3d2f52 | 2009-08-27 13:55:20 +0000 | [diff] [blame] | 3860 | MODULE_PARM_DESC(pg_count_d, "Default number of packets to inject"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3861 | module_param(pg_delay_d, int, 0); |
Stephen Hemminger | c3d2f52 | 2009-08-27 13:55:20 +0000 | [diff] [blame] | 3862 | MODULE_PARM_DESC(pg_delay_d, "Default delay between packets (nanoseconds)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3863 | module_param(pg_clone_skb_d, int, 0); |
Stephen Hemminger | c3d2f52 | 2009-08-27 13:55:20 +0000 | [diff] [blame] | 3864 | MODULE_PARM_DESC(pg_clone_skb_d, "Default number of copies of the same packet"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3865 | module_param(debug, int, 0); |
Stephen Hemminger | c3d2f52 | 2009-08-27 13:55:20 +0000 | [diff] [blame] | 3866 | MODULE_PARM_DESC(debug, "Enable debugging of pktgen module"); |