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