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