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