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