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