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