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