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