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