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