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