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