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