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