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