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