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