/net/core/pktgen.c

http://github.com/mirrors/linux · C · 3896 lines · 2946 code · 619 blank · 331 comment · 595 complexity · c59dadde243d10df992a44b07ef85506 MD5 · raw file

Large files are truncated click here to view the full file

  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Authors:
  4. * Copyright 2001, 2002 by Robert Olsson <robert.olsson@its.uu.se>
  5. * Uppsala University and
  6. * Swedish University of Agricultural Sciences
  7. *
  8. * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
  9. * Ben Greear <greearb@candelatech.com>
  10. * Jens Låås <jens.laas@data.slu.se>
  11. *
  12. * A tool for loading the network with preconfigurated packets.
  13. * The tool is implemented as a linux module. Parameters are output
  14. * device, delay (to hard_xmit), number of packets, and whether
  15. * to use multiple SKBs or just the same one.
  16. * pktgen uses the installed interface's output routine.
  17. *
  18. * Additional hacking by:
  19. *
  20. * Jens.Laas@data.slu.se
  21. * Improved by ANK. 010120.
  22. * Improved by ANK even more. 010212.
  23. * MAC address typo fixed. 010417 --ro
  24. * Integrated. 020301 --DaveM
  25. * Added multiskb option 020301 --DaveM
  26. * Scaling of results. 020417--sigurdur@linpro.no
  27. * Significant re-work of the module:
  28. * * Convert to threaded model to more efficiently be able to transmit
  29. * and receive on multiple interfaces at once.
  30. * * Converted many counters to __u64 to allow longer runs.
  31. * * Allow configuration of ranges, like min/max IP address, MACs,
  32. * and UDP-ports, for both source and destination, and can
  33. * set to use a random distribution or sequentially walk the range.
  34. * * Can now change most values after starting.
  35. * * Place 12-byte packet in UDP payload with magic number,
  36. * sequence number, and timestamp.
  37. * * Add receiver code that detects dropped pkts, re-ordered pkts, and
  38. * latencies (with micro-second) precision.
  39. * * Add IOCTL interface to easily get counters & configuration.
  40. * --Ben Greear <greearb@candelatech.com>
  41. *
  42. * Renamed multiskb to clone_skb and cleaned up sending core for two distinct
  43. * skb modes. A clone_skb=0 mode for Ben "ranges" work and a clone_skb != 0
  44. * as a "fastpath" with a configurable number of clones after alloc's.
  45. * clone_skb=0 means all packets are allocated this also means ranges time
  46. * stamps etc can be used. clone_skb=100 means 1 malloc is followed by 100
  47. * clones.
  48. *
  49. * Also moved to /proc/net/pktgen/
  50. * --ro
  51. *
  52. * Sept 10: Fixed threading/locking. Lots of bone-headed and more clever
  53. * mistakes. Also merged in DaveM's patch in the -pre6 patch.
  54. * --Ben Greear <greearb@candelatech.com>
  55. *
  56. * Integrated to 2.5.x 021029 --Lucio Maciel (luciomaciel@zipmail.com.br)
  57. *
  58. * 021124 Finished major redesign and rewrite for new functionality.
  59. * See Documentation/networking/pktgen.txt for how to use this.
  60. *
  61. * The new operation:
  62. * For each CPU one thread/process is created at start. This process checks
  63. * for running devices in the if_list and sends packets until count is 0 it
  64. * also the thread checks the thread->control which is used for inter-process
  65. * communication. controlling process "posts" operations to the threads this
  66. * way.
  67. * The if_list is RCU protected, and the if_lock remains to protect updating
  68. * of if_list, from "add_device" as it invoked from userspace (via proc write).
  69. *
  70. * By design there should only be *one* "controlling" process. In practice
  71. * multiple write accesses gives unpredictable result. Understood by "write"
  72. * to /proc gives result code thats should be read be the "writer".
  73. * For practical use this should be no problem.
  74. *
  75. * Note when adding devices to a specific CPU there good idea to also assign
  76. * /proc/irq/XX/smp_affinity so TX-interrupts gets bound to the same CPU.
  77. * --ro
  78. *
  79. * Fix refcount off by one if first packet fails, potential null deref,
  80. * memleak 030710- KJP
  81. *
  82. * First "ranges" functionality for ipv6 030726 --ro
  83. *
  84. * Included flow support. 030802 ANK.
  85. *
  86. * Fixed unaligned access on IA-64 Grant Grundler <grundler@parisc-linux.org>
  87. *
  88. * Remove if fix from added Harald Welte <laforge@netfilter.org> 040419
  89. * ia64 compilation fix from Aron Griffis <aron@hp.com> 040604
  90. *
  91. * New xmit() return, do_div and misc clean up by Stephen Hemminger
  92. * <shemminger@osdl.org> 040923
  93. *
  94. * Randy Dunlap fixed u64 printk compiler warning
  95. *
  96. * Remove FCS from BW calculation. Lennert Buytenhek <buytenh@wantstofly.org>
  97. * New time handling. Lennert Buytenhek <buytenh@wantstofly.org> 041213
  98. *
  99. * Corrections from Nikolai Malykh (nmalykh@bilim.com)
  100. * Removed unused flags F_SET_SRCMAC & F_SET_SRCIP 041230
  101. *
  102. * interruptible_sleep_on_timeout() replaced Nishanth Aravamudan <nacc@us.ibm.com>
  103. * 050103
  104. *
  105. * MPLS support by Steven Whitehouse <steve@chygwyn.com>
  106. *
  107. * 802.1Q/Q-in-Q support by Francesco Fondelli (FF) <francesco.fondelli@gmail.com>
  108. *
  109. * Fixed src_mac command to set source mac of packet to value specified in
  110. * command by Adit Ranadive <adit.262@gmail.com>
  111. */
  112. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  113. #include <linux/sys.h>
  114. #include <linux/types.h>
  115. #include <linux/module.h>
  116. #include <linux/moduleparam.h>
  117. #include <linux/kernel.h>
  118. #include <linux/mutex.h>
  119. #include <linux/sched.h>
  120. #include <linux/slab.h>
  121. #include <linux/vmalloc.h>
  122. #include <linux/unistd.h>
  123. #include <linux/string.h>
  124. #include <linux/ptrace.h>
  125. #include <linux/errno.h>
  126. #include <linux/ioport.h>
  127. #include <linux/interrupt.h>
  128. #include <linux/capability.h>
  129. #include <linux/hrtimer.h>
  130. #include <linux/freezer.h>
  131. #include <linux/delay.h>
  132. #include <linux/timer.h>
  133. #include <linux/list.h>
  134. #include <linux/init.h>
  135. #include <linux/skbuff.h>
  136. #include <linux/netdevice.h>
  137. #include <linux/inet.h>
  138. #include <linux/inetdevice.h>
  139. #include <linux/rtnetlink.h>
  140. #include <linux/if_arp.h>
  141. #include <linux/if_vlan.h>
  142. #include <linux/in.h>
  143. #include <linux/ip.h>
  144. #include <linux/ipv6.h>
  145. #include <linux/udp.h>
  146. #include <linux/proc_fs.h>
  147. #include <linux/seq_file.h>
  148. #include <linux/wait.h>
  149. #include <linux/etherdevice.h>
  150. #include <linux/kthread.h>
  151. #include <linux/prefetch.h>
  152. #include <linux/mmzone.h>
  153. #include <net/net_namespace.h>
  154. #include <net/checksum.h>
  155. #include <net/ipv6.h>
  156. #include <net/udp.h>
  157. #include <net/ip6_checksum.h>
  158. #include <net/addrconf.h>
  159. #ifdef CONFIG_XFRM
  160. #include <net/xfrm.h>
  161. #endif
  162. #include <net/netns/generic.h>
  163. #include <asm/byteorder.h>
  164. #include <linux/rcupdate.h>
  165. #include <linux/bitops.h>
  166. #include <linux/io.h>
  167. #include <linux/timex.h>
  168. #include <linux/uaccess.h>
  169. #include <asm/dma.h>
  170. #include <asm/div64.h> /* do_div */
  171. #define VERSION "2.75"
  172. #define IP_NAME_SZ 32
  173. #define MAX_MPLS_LABELS 16 /* This is the max label stack depth */
  174. #define MPLS_STACK_BOTTOM htonl(0x00000100)
  175. #define func_enter() pr_debug("entering %s\n", __func__);
  176. #define PKT_FLAGS \
  177. pf(IPV6) /* Interface in IPV6 Mode */ \
  178. pf(IPSRC_RND) /* IP-Src Random */ \
  179. pf(IPDST_RND) /* IP-Dst Random */ \
  180. pf(TXSIZE_RND) /* Transmit size is random */ \
  181. pf(UDPSRC_RND) /* UDP-Src Random */ \
  182. pf(UDPDST_RND) /* UDP-Dst Random */ \
  183. pf(UDPCSUM) /* Include UDP checksum */ \
  184. pf(NO_TIMESTAMP) /* Don't timestamp packets (default TS) */ \
  185. pf(MPLS_RND) /* Random MPLS labels */ \
  186. pf(QUEUE_MAP_RND) /* queue map Random */ \
  187. pf(QUEUE_MAP_CPU) /* queue map mirrors smp_processor_id() */ \
  188. pf(FLOW_SEQ) /* Sequential flows */ \
  189. pf(IPSEC) /* ipsec on for flows */ \
  190. pf(MACSRC_RND) /* MAC-Src Random */ \
  191. pf(MACDST_RND) /* MAC-Dst Random */ \
  192. pf(VID_RND) /* Random VLAN ID */ \
  193. pf(SVID_RND) /* Random SVLAN ID */ \
  194. pf(NODE) /* Node memory alloc*/ \
  195. #define pf(flag) flag##_SHIFT,
  196. enum pkt_flags {
  197. PKT_FLAGS
  198. };
  199. #undef pf
  200. /* Device flag bits */
  201. #define pf(flag) static const __u32 F_##flag = (1<<flag##_SHIFT);
  202. PKT_FLAGS
  203. #undef pf
  204. #define pf(flag) __stringify(flag),
  205. static char *pkt_flag_names[] = {
  206. PKT_FLAGS
  207. };
  208. #undef pf
  209. #define NR_PKT_FLAGS ARRAY_SIZE(pkt_flag_names)
  210. /* Thread control flag bits */
  211. #define T_STOP (1<<0) /* Stop run */
  212. #define T_RUN (1<<1) /* Start run */
  213. #define T_REMDEVALL (1<<2) /* Remove all devs */
  214. #define T_REMDEV (1<<3) /* Remove one dev */
  215. /* Xmit modes */
  216. #define M_START_XMIT 0 /* Default normal TX */
  217. #define M_NETIF_RECEIVE 1 /* Inject packets into stack */
  218. #define M_QUEUE_XMIT 2 /* Inject packet into qdisc */
  219. /* If lock -- protects updating of if_list */
  220. #define if_lock(t) mutex_lock(&(t->if_lock));
  221. #define if_unlock(t) mutex_unlock(&(t->if_lock));
  222. /* Used to help with determining the pkts on receive */
  223. #define PKTGEN_MAGIC 0xbe9be955
  224. #define PG_PROC_DIR "pktgen"
  225. #define PGCTRL "pgctrl"
  226. #define MAX_CFLOWS 65536
  227. #define VLAN_TAG_SIZE(x) ((x)->vlan_id == 0xffff ? 0 : 4)
  228. #define SVLAN_TAG_SIZE(x) ((x)->svlan_id == 0xffff ? 0 : 4)
  229. struct flow_state {
  230. __be32 cur_daddr;
  231. int count;
  232. #ifdef CONFIG_XFRM
  233. struct xfrm_state *x;
  234. #endif
  235. __u32 flags;
  236. };
  237. /* flow flag bits */
  238. #define F_INIT (1<<0) /* flow has been initialized */
  239. struct pktgen_dev {
  240. /*
  241. * Try to keep frequent/infrequent used vars. separated.
  242. */
  243. struct proc_dir_entry *entry; /* proc file */
  244. struct pktgen_thread *pg_thread;/* the owner */
  245. struct list_head list; /* chaining in the thread's run-queue */
  246. struct rcu_head rcu; /* freed by RCU */
  247. int running; /* if false, the test will stop */
  248. /* If min != max, then we will either do a linear iteration, or
  249. * we will do a random selection from within the range.
  250. */
  251. __u32 flags;
  252. int xmit_mode;
  253. int min_pkt_size;
  254. int max_pkt_size;
  255. int pkt_overhead; /* overhead for MPLS, VLANs, IPSEC etc */
  256. int nfrags;
  257. int removal_mark; /* non-zero => the device is marked for
  258. * removal by worker thread */
  259. struct page *page;
  260. u64 delay; /* nano-seconds */
  261. __u64 count; /* Default No packets to send */
  262. __u64 sofar; /* How many pkts we've sent so far */
  263. __u64 tx_bytes; /* How many bytes we've transmitted */
  264. __u64 errors; /* Errors when trying to transmit, */
  265. /* runtime counters relating to clone_skb */
  266. __u32 clone_count;
  267. int last_ok; /* Was last skb sent?
  268. * Or a failed transmit of some sort?
  269. * This will keep sequence numbers in order
  270. */
  271. ktime_t next_tx;
  272. ktime_t started_at;
  273. ktime_t stopped_at;
  274. u64 idle_acc; /* nano-seconds */
  275. __u32 seq_num;
  276. int clone_skb; /*
  277. * Use multiple SKBs during packet gen.
  278. * If this number is greater than 1, then
  279. * that many copies of the same packet will be
  280. * sent before a new packet is allocated.
  281. * If you want to send 1024 identical packets
  282. * before creating a new packet,
  283. * set clone_skb to 1024.
  284. */
  285. char dst_min[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */
  286. char dst_max[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */
  287. char src_min[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */
  288. char src_max[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */
  289. struct in6_addr in6_saddr;
  290. struct in6_addr in6_daddr;
  291. struct in6_addr cur_in6_daddr;
  292. struct in6_addr cur_in6_saddr;
  293. /* For ranges */
  294. struct in6_addr min_in6_daddr;
  295. struct in6_addr max_in6_daddr;
  296. struct in6_addr min_in6_saddr;
  297. struct in6_addr max_in6_saddr;
  298. /* If we're doing ranges, random or incremental, then this
  299. * defines the min/max for those ranges.
  300. */
  301. __be32 saddr_min; /* inclusive, source IP address */
  302. __be32 saddr_max; /* exclusive, source IP address */
  303. __be32 daddr_min; /* inclusive, dest IP address */
  304. __be32 daddr_max; /* exclusive, dest IP address */
  305. __u16 udp_src_min; /* inclusive, source UDP port */
  306. __u16 udp_src_max; /* exclusive, source UDP port */
  307. __u16 udp_dst_min; /* inclusive, dest UDP port */
  308. __u16 udp_dst_max; /* exclusive, dest UDP port */
  309. /* DSCP + ECN */
  310. __u8 tos; /* six MSB of (former) IPv4 TOS
  311. are for dscp codepoint */
  312. __u8 traffic_class; /* ditto for the (former) Traffic Class in IPv6
  313. (see RFC 3260, sec. 4) */
  314. /* MPLS */
  315. unsigned int nr_labels; /* Depth of stack, 0 = no MPLS */
  316. __be32 labels[MAX_MPLS_LABELS];
  317. /* VLAN/SVLAN (802.1Q/Q-in-Q) */
  318. __u8 vlan_p;
  319. __u8 vlan_cfi;
  320. __u16 vlan_id; /* 0xffff means no vlan tag */
  321. __u8 svlan_p;
  322. __u8 svlan_cfi;
  323. __u16 svlan_id; /* 0xffff means no svlan tag */
  324. __u32 src_mac_count; /* How many MACs to iterate through */
  325. __u32 dst_mac_count; /* How many MACs to iterate through */
  326. unsigned char dst_mac[ETH_ALEN];
  327. unsigned char src_mac[ETH_ALEN];
  328. __u32 cur_dst_mac_offset;
  329. __u32 cur_src_mac_offset;
  330. __be32 cur_saddr;
  331. __be32 cur_daddr;
  332. __u16 ip_id;
  333. __u16 cur_udp_dst;
  334. __u16 cur_udp_src;
  335. __u16 cur_queue_map;
  336. __u32 cur_pkt_size;
  337. __u32 last_pkt_size;
  338. __u8 hh[14];
  339. /* = {
  340. 0x00, 0x80, 0xC8, 0x79, 0xB3, 0xCB,
  341. We fill in SRC address later
  342. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  343. 0x08, 0x00
  344. };
  345. */
  346. __u16 pad; /* pad out the hh struct to an even 16 bytes */
  347. struct sk_buff *skb; /* skb we are to transmit next, used for when we
  348. * are transmitting the same one multiple times
  349. */
  350. struct net_device *odev; /* The out-going device.
  351. * Note that the device should have it's
  352. * pg_info pointer pointing back to this
  353. * device.
  354. * Set when the user specifies the out-going
  355. * device name (not when the inject is
  356. * started as it used to do.)
  357. */
  358. char odevname[32];
  359. struct flow_state *flows;
  360. unsigned int cflows; /* Concurrent flows (config) */
  361. unsigned int lflow; /* Flow length (config) */
  362. unsigned int nflows; /* accumulated flows (stats) */
  363. unsigned int curfl; /* current sequenced flow (state)*/
  364. u16 queue_map_min;
  365. u16 queue_map_max;
  366. __u32 skb_priority; /* skb priority field */
  367. unsigned int burst; /* number of duplicated packets to burst */
  368. int node; /* Memory node */
  369. #ifdef CONFIG_XFRM
  370. __u8 ipsmode; /* IPSEC mode (config) */
  371. __u8 ipsproto; /* IPSEC type (config) */
  372. __u32 spi;
  373. struct xfrm_dst xdst;
  374. struct dst_ops dstops;
  375. #endif
  376. char result[512];
  377. };
  378. struct pktgen_hdr {
  379. __be32 pgh_magic;
  380. __be32 seq_num;
  381. __be32 tv_sec;
  382. __be32 tv_usec;
  383. };
  384. static unsigned int pg_net_id __read_mostly;
  385. struct pktgen_net {
  386. struct net *net;
  387. struct proc_dir_entry *proc_dir;
  388. struct list_head pktgen_threads;
  389. bool pktgen_exiting;
  390. };
  391. struct pktgen_thread {
  392. struct mutex if_lock; /* for list of devices */
  393. struct list_head if_list; /* All device here */
  394. struct list_head th_list;
  395. struct task_struct *tsk;
  396. char result[512];
  397. /* Field for thread to receive "posted" events terminate,
  398. stop ifs etc. */
  399. u32 control;
  400. int cpu;
  401. wait_queue_head_t queue;
  402. struct completion start_done;
  403. struct pktgen_net *net;
  404. };
  405. #define REMOVE 1
  406. #define FIND 0
  407. static const char version[] =
  408. "Packet Generator for packet performance testing. "
  409. "Version: " VERSION "\n";
  410. static int pktgen_remove_device(struct pktgen_thread *t, struct pktgen_dev *i);
  411. static int pktgen_add_device(struct pktgen_thread *t, const char *ifname);
  412. static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t,
  413. const char *ifname, bool exact);
  414. static int pktgen_device_event(struct notifier_block *, unsigned long, void *);
  415. static void pktgen_run_all_threads(struct pktgen_net *pn);
  416. static void pktgen_reset_all_threads(struct pktgen_net *pn);
  417. static void pktgen_stop_all_threads_ifs(struct pktgen_net *pn);
  418. static void pktgen_stop(struct pktgen_thread *t);
  419. static void pktgen_clear_counters(struct pktgen_dev *pkt_dev);
  420. /* Module parameters, defaults. */
  421. static int pg_count_d __read_mostly = 1000;
  422. static int pg_delay_d __read_mostly;
  423. static int pg_clone_skb_d __read_mostly;
  424. static int debug __read_mostly;
  425. static DEFINE_MUTEX(pktgen_thread_lock);
  426. static struct notifier_block pktgen_notifier_block = {
  427. .notifier_call = pktgen_device_event,
  428. };
  429. /*
  430. * /proc handling functions
  431. *
  432. */
  433. static int pgctrl_show(struct seq_file *seq, void *v)
  434. {
  435. seq_puts(seq, version);
  436. return 0;
  437. }
  438. static ssize_t pgctrl_write(struct file *file, const char __user *buf,
  439. size_t count, loff_t *ppos)
  440. {
  441. char data[128];
  442. struct pktgen_net *pn = net_generic(current->nsproxy->net_ns, pg_net_id);
  443. if (!capable(CAP_NET_ADMIN))
  444. return -EPERM;
  445. if (count == 0)
  446. return -EINVAL;
  447. if (count > sizeof(data))
  448. count = sizeof(data);
  449. if (copy_from_user(data, buf, count))
  450. return -EFAULT;
  451. data[count - 1] = 0; /* Strip trailing '\n' and terminate string */
  452. if (!strcmp(data, "stop"))
  453. pktgen_stop_all_threads_ifs(pn);
  454. else if (!strcmp(data, "start"))
  455. pktgen_run_all_threads(pn);
  456. else if (!strcmp(data, "reset"))
  457. pktgen_reset_all_threads(pn);
  458. else
  459. return -EINVAL;
  460. return count;
  461. }
  462. static int pgctrl_open(struct inode *inode, struct file *file)
  463. {
  464. return single_open(file, pgctrl_show, PDE_DATA(inode));
  465. }
  466. static const struct proc_ops pktgen_proc_ops = {
  467. .proc_open = pgctrl_open,
  468. .proc_read = seq_read,
  469. .proc_lseek = seq_lseek,
  470. .proc_write = pgctrl_write,
  471. .proc_release = single_release,
  472. };
  473. static int pktgen_if_show(struct seq_file *seq, void *v)
  474. {
  475. const struct pktgen_dev *pkt_dev = seq->private;
  476. ktime_t stopped;
  477. unsigned int i;
  478. u64 idle;
  479. seq_printf(seq,
  480. "Params: count %llu min_pkt_size: %u max_pkt_size: %u\n",
  481. (unsigned long long)pkt_dev->count, pkt_dev->min_pkt_size,
  482. pkt_dev->max_pkt_size);
  483. seq_printf(seq,
  484. " frags: %d delay: %llu clone_skb: %d ifname: %s\n",
  485. pkt_dev->nfrags, (unsigned long long) pkt_dev->delay,
  486. pkt_dev->clone_skb, pkt_dev->odevname);
  487. seq_printf(seq, " flows: %u flowlen: %u\n", pkt_dev->cflows,
  488. pkt_dev->lflow);
  489. seq_printf(seq,
  490. " queue_map_min: %u queue_map_max: %u\n",
  491. pkt_dev->queue_map_min,
  492. pkt_dev->queue_map_max);
  493. if (pkt_dev->skb_priority)
  494. seq_printf(seq, " skb_priority: %u\n",
  495. pkt_dev->skb_priority);
  496. if (pkt_dev->flags & F_IPV6) {
  497. seq_printf(seq,
  498. " saddr: %pI6c min_saddr: %pI6c max_saddr: %pI6c\n"
  499. " daddr: %pI6c min_daddr: %pI6c max_daddr: %pI6c\n",
  500. &pkt_dev->in6_saddr,
  501. &pkt_dev->min_in6_saddr, &pkt_dev->max_in6_saddr,
  502. &pkt_dev->in6_daddr,
  503. &pkt_dev->min_in6_daddr, &pkt_dev->max_in6_daddr);
  504. } else {
  505. seq_printf(seq,
  506. " dst_min: %s dst_max: %s\n",
  507. pkt_dev->dst_min, pkt_dev->dst_max);
  508. seq_printf(seq,
  509. " src_min: %s src_max: %s\n",
  510. pkt_dev->src_min, pkt_dev->src_max);
  511. }
  512. seq_puts(seq, " src_mac: ");
  513. seq_printf(seq, "%pM ",
  514. is_zero_ether_addr(pkt_dev->src_mac) ?
  515. pkt_dev->odev->dev_addr : pkt_dev->src_mac);
  516. seq_puts(seq, "dst_mac: ");
  517. seq_printf(seq, "%pM\n", pkt_dev->dst_mac);
  518. seq_printf(seq,
  519. " udp_src_min: %d udp_src_max: %d"
  520. " udp_dst_min: %d udp_dst_max: %d\n",
  521. pkt_dev->udp_src_min, pkt_dev->udp_src_max,
  522. pkt_dev->udp_dst_min, pkt_dev->udp_dst_max);
  523. seq_printf(seq,
  524. " src_mac_count: %d dst_mac_count: %d\n",
  525. pkt_dev->src_mac_count, pkt_dev->dst_mac_count);
  526. if (pkt_dev->nr_labels) {
  527. seq_puts(seq, " mpls: ");
  528. for (i = 0; i < pkt_dev->nr_labels; i++)
  529. seq_printf(seq, "%08x%s", ntohl(pkt_dev->labels[i]),
  530. i == pkt_dev->nr_labels-1 ? "\n" : ", ");
  531. }
  532. if (pkt_dev->vlan_id != 0xffff)
  533. seq_printf(seq, " vlan_id: %u vlan_p: %u vlan_cfi: %u\n",
  534. pkt_dev->vlan_id, pkt_dev->vlan_p,
  535. pkt_dev->vlan_cfi);
  536. if (pkt_dev->svlan_id != 0xffff)
  537. seq_printf(seq, " svlan_id: %u vlan_p: %u vlan_cfi: %u\n",
  538. pkt_dev->svlan_id, pkt_dev->svlan_p,
  539. pkt_dev->svlan_cfi);
  540. if (pkt_dev->tos)
  541. seq_printf(seq, " tos: 0x%02x\n", pkt_dev->tos);
  542. if (pkt_dev->traffic_class)
  543. seq_printf(seq, " traffic_class: 0x%02x\n", pkt_dev->traffic_class);
  544. if (pkt_dev->burst > 1)
  545. seq_printf(seq, " burst: %d\n", pkt_dev->burst);
  546. if (pkt_dev->node >= 0)
  547. seq_printf(seq, " node: %d\n", pkt_dev->node);
  548. if (pkt_dev->xmit_mode == M_NETIF_RECEIVE)
  549. seq_puts(seq, " xmit_mode: netif_receive\n");
  550. else if (pkt_dev->xmit_mode == M_QUEUE_XMIT)
  551. seq_puts(seq, " xmit_mode: xmit_queue\n");
  552. seq_puts(seq, " Flags: ");
  553. for (i = 0; i < NR_PKT_FLAGS; i++) {
  554. if (i == F_FLOW_SEQ)
  555. if (!pkt_dev->cflows)
  556. continue;
  557. if (pkt_dev->flags & (1 << i))
  558. seq_printf(seq, "%s ", pkt_flag_names[i]);
  559. else if (i == F_FLOW_SEQ)
  560. seq_puts(seq, "FLOW_RND ");
  561. #ifdef CONFIG_XFRM
  562. if (i == F_IPSEC && pkt_dev->spi)
  563. seq_printf(seq, "spi:%u", pkt_dev->spi);
  564. #endif
  565. }
  566. seq_puts(seq, "\n");
  567. /* not really stopped, more like last-running-at */
  568. stopped = pkt_dev->running ? ktime_get() : pkt_dev->stopped_at;
  569. idle = pkt_dev->idle_acc;
  570. do_div(idle, NSEC_PER_USEC);
  571. seq_printf(seq,
  572. "Current:\n pkts-sofar: %llu errors: %llu\n",
  573. (unsigned long long)pkt_dev->sofar,
  574. (unsigned long long)pkt_dev->errors);
  575. seq_printf(seq,
  576. " started: %lluus stopped: %lluus idle: %lluus\n",
  577. (unsigned long long) ktime_to_us(pkt_dev->started_at),
  578. (unsigned long long) ktime_to_us(stopped),
  579. (unsigned long long) idle);
  580. seq_printf(seq,
  581. " seq_num: %d cur_dst_mac_offset: %d cur_src_mac_offset: %d\n",
  582. pkt_dev->seq_num, pkt_dev->cur_dst_mac_offset,
  583. pkt_dev->cur_src_mac_offset);
  584. if (pkt_dev->flags & F_IPV6) {
  585. seq_printf(seq, " cur_saddr: %pI6c cur_daddr: %pI6c\n",
  586. &pkt_dev->cur_in6_saddr,
  587. &pkt_dev->cur_in6_daddr);
  588. } else
  589. seq_printf(seq, " cur_saddr: %pI4 cur_daddr: %pI4\n",
  590. &pkt_dev->cur_saddr, &pkt_dev->cur_daddr);
  591. seq_printf(seq, " cur_udp_dst: %d cur_udp_src: %d\n",
  592. pkt_dev->cur_udp_dst, pkt_dev->cur_udp_src);
  593. seq_printf(seq, " cur_queue_map: %u\n", pkt_dev->cur_queue_map);
  594. seq_printf(seq, " flows: %u\n", pkt_dev->nflows);
  595. if (pkt_dev->result[0])
  596. seq_printf(seq, "Result: %s\n", pkt_dev->result);
  597. else
  598. seq_puts(seq, "Result: Idle\n");
  599. return 0;
  600. }
  601. static int hex32_arg(const char __user *user_buffer, unsigned long maxlen,
  602. __u32 *num)
  603. {
  604. int i = 0;
  605. *num = 0;
  606. for (; i < maxlen; i++) {
  607. int value;
  608. char c;
  609. *num <<= 4;
  610. if (get_user(c, &user_buffer[i]))
  611. return -EFAULT;
  612. value = hex_to_bin(c);
  613. if (value >= 0)
  614. *num |= value;
  615. else
  616. break;
  617. }
  618. return i;
  619. }
  620. static int count_trail_chars(const char __user * user_buffer,
  621. unsigned int maxlen)
  622. {
  623. int i;
  624. for (i = 0; i < maxlen; i++) {
  625. char c;
  626. if (get_user(c, &user_buffer[i]))
  627. return -EFAULT;
  628. switch (c) {
  629. case '\"':
  630. case '\n':
  631. case '\r':
  632. case '\t':
  633. case ' ':
  634. case '=':
  635. break;
  636. default:
  637. goto done;
  638. }
  639. }
  640. done:
  641. return i;
  642. }
  643. static long num_arg(const char __user *user_buffer, unsigned long maxlen,
  644. unsigned long *num)
  645. {
  646. int i;
  647. *num = 0;
  648. for (i = 0; i < maxlen; i++) {
  649. char c;
  650. if (get_user(c, &user_buffer[i]))
  651. return -EFAULT;
  652. if ((c >= '0') && (c <= '9')) {
  653. *num *= 10;
  654. *num += c - '0';
  655. } else
  656. break;
  657. }
  658. return i;
  659. }
  660. static int strn_len(const char __user * user_buffer, unsigned int maxlen)
  661. {
  662. int i;
  663. for (i = 0; i < maxlen; i++) {
  664. char c;
  665. if (get_user(c, &user_buffer[i]))
  666. return -EFAULT;
  667. switch (c) {
  668. case '\"':
  669. case '\n':
  670. case '\r':
  671. case '\t':
  672. case ' ':
  673. goto done_str;
  674. default:
  675. break;
  676. }
  677. }
  678. done_str:
  679. return i;
  680. }
  681. static ssize_t get_labels(const char __user *buffer, struct pktgen_dev *pkt_dev)
  682. {
  683. unsigned int n = 0;
  684. char c;
  685. ssize_t i = 0;
  686. int len;
  687. pkt_dev->nr_labels = 0;
  688. do {
  689. __u32 tmp;
  690. len = hex32_arg(&buffer[i], 8, &tmp);
  691. if (len <= 0)
  692. return len;
  693. pkt_dev->labels[n] = htonl(tmp);
  694. if (pkt_dev->labels[n] & MPLS_STACK_BOTTOM)
  695. pkt_dev->flags |= F_MPLS_RND;
  696. i += len;
  697. if (get_user(c, &buffer[i]))
  698. return -EFAULT;
  699. i++;
  700. n++;
  701. if (n >= MAX_MPLS_LABELS)
  702. return -E2BIG;
  703. } while (c == ',');
  704. pkt_dev->nr_labels = n;
  705. return i;
  706. }
  707. static __u32 pktgen_read_flag(const char *f, bool *disable)
  708. {
  709. __u32 i;
  710. if (f[0] == '!') {
  711. *disable = true;
  712. f++;
  713. }
  714. for (i = 0; i < NR_PKT_FLAGS; i++) {
  715. if (!IS_ENABLED(CONFIG_XFRM) && i == IPSEC_SHIFT)
  716. continue;
  717. /* allow only disabling ipv6 flag */
  718. if (!*disable && i == IPV6_SHIFT)
  719. continue;
  720. if (strcmp(f, pkt_flag_names[i]) == 0)
  721. return 1 << i;
  722. }
  723. if (strcmp(f, "FLOW_RND") == 0) {
  724. *disable = !*disable;
  725. return F_FLOW_SEQ;
  726. }
  727. return 0;
  728. }
  729. static ssize_t pktgen_if_write(struct file *file,
  730. const char __user * user_buffer, size_t count,
  731. loff_t * offset)
  732. {
  733. struct seq_file *seq = file->private_data;
  734. struct pktgen_dev *pkt_dev = seq->private;
  735. int i, max, len;
  736. char name[16], valstr[32];
  737. unsigned long value = 0;
  738. char *pg_result = NULL;
  739. int tmp = 0;
  740. char buf[128];
  741. pg_result = &(pkt_dev->result[0]);
  742. if (count < 1) {
  743. pr_warn("wrong command format\n");
  744. return -EINVAL;
  745. }
  746. max = count;
  747. tmp = count_trail_chars(user_buffer, max);
  748. if (tmp < 0) {
  749. pr_warn("illegal format\n");
  750. return tmp;
  751. }
  752. i = tmp;
  753. /* Read variable name */
  754. len = strn_len(&user_buffer[i], sizeof(name) - 1);
  755. if (len < 0)
  756. return len;
  757. memset(name, 0, sizeof(name));
  758. if (copy_from_user(name, &user_buffer[i], len))
  759. return -EFAULT;
  760. i += len;
  761. max = count - i;
  762. len = count_trail_chars(&user_buffer[i], max);
  763. if (len < 0)
  764. return len;
  765. i += len;
  766. if (debug) {
  767. size_t copy = min_t(size_t, count + 1, 1024);
  768. char *tp = strndup_user(user_buffer, copy);
  769. if (IS_ERR(tp))
  770. return PTR_ERR(tp);
  771. pr_debug("%s,%zu buffer -:%s:-\n", name, count, tp);
  772. kfree(tp);
  773. }
  774. if (!strcmp(name, "min_pkt_size")) {
  775. len = num_arg(&user_buffer[i], 10, &value);
  776. if (len < 0)
  777. return len;
  778. i += len;
  779. if (value < 14 + 20 + 8)
  780. value = 14 + 20 + 8;
  781. if (value != pkt_dev->min_pkt_size) {
  782. pkt_dev->min_pkt_size = value;
  783. pkt_dev->cur_pkt_size = value;
  784. }
  785. sprintf(pg_result, "OK: min_pkt_size=%u",
  786. pkt_dev->min_pkt_size);
  787. return count;
  788. }
  789. if (!strcmp(name, "max_pkt_size")) {
  790. len = num_arg(&user_buffer[i], 10, &value);
  791. if (len < 0)
  792. return len;
  793. i += len;
  794. if (value < 14 + 20 + 8)
  795. value = 14 + 20 + 8;
  796. if (value != pkt_dev->max_pkt_size) {
  797. pkt_dev->max_pkt_size = value;
  798. pkt_dev->cur_pkt_size = value;
  799. }
  800. sprintf(pg_result, "OK: max_pkt_size=%u",
  801. pkt_dev->max_pkt_size);
  802. return count;
  803. }
  804. /* Shortcut for min = max */
  805. if (!strcmp(name, "pkt_size")) {
  806. len = num_arg(&user_buffer[i], 10, &value);
  807. if (len < 0)
  808. return len;
  809. i += len;
  810. if (value < 14 + 20 + 8)
  811. value = 14 + 20 + 8;
  812. if (value != pkt_dev->min_pkt_size) {
  813. pkt_dev->min_pkt_size = value;
  814. pkt_dev->max_pkt_size = value;
  815. pkt_dev->cur_pkt_size = value;
  816. }
  817. sprintf(pg_result, "OK: pkt_size=%u", pkt_dev->min_pkt_size);
  818. return count;
  819. }
  820. if (!strcmp(name, "debug")) {
  821. len = num_arg(&user_buffer[i], 10, &value);
  822. if (len < 0)
  823. return len;
  824. i += len;
  825. debug = value;
  826. sprintf(pg_result, "OK: debug=%u", debug);
  827. return count;
  828. }
  829. if (!strcmp(name, "frags")) {
  830. len = num_arg(&user_buffer[i], 10, &value);
  831. if (len < 0)
  832. return len;
  833. i += len;
  834. pkt_dev->nfrags = value;
  835. sprintf(pg_result, "OK: frags=%u", pkt_dev->nfrags);
  836. return count;
  837. }
  838. if (!strcmp(name, "delay")) {
  839. len = num_arg(&user_buffer[i], 10, &value);
  840. if (len < 0)
  841. return len;
  842. i += len;
  843. if (value == 0x7FFFFFFF)
  844. pkt_dev->delay = ULLONG_MAX;
  845. else
  846. pkt_dev->delay = (u64)value;
  847. sprintf(pg_result, "OK: delay=%llu",
  848. (unsigned long long) pkt_dev->delay);
  849. return count;
  850. }
  851. if (!strcmp(name, "rate")) {
  852. len = num_arg(&user_buffer[i], 10, &value);
  853. if (len < 0)
  854. return len;
  855. i += len;
  856. if (!value)
  857. return len;
  858. pkt_dev->delay = pkt_dev->min_pkt_size*8*NSEC_PER_USEC/value;
  859. if (debug)
  860. pr_info("Delay set at: %llu ns\n", pkt_dev->delay);
  861. sprintf(pg_result, "OK: rate=%lu", value);
  862. return count;
  863. }
  864. if (!strcmp(name, "ratep")) {
  865. len = num_arg(&user_buffer[i], 10, &value);
  866. if (len < 0)
  867. return len;
  868. i += len;
  869. if (!value)
  870. return len;
  871. pkt_dev->delay = NSEC_PER_SEC/value;
  872. if (debug)
  873. pr_info("Delay set at: %llu ns\n", pkt_dev->delay);
  874. sprintf(pg_result, "OK: rate=%lu", value);
  875. return count;
  876. }
  877. if (!strcmp(name, "udp_src_min")) {
  878. len = num_arg(&user_buffer[i], 10, &value);
  879. if (len < 0)
  880. return len;
  881. i += len;
  882. if (value != pkt_dev->udp_src_min) {
  883. pkt_dev->udp_src_min = value;
  884. pkt_dev->cur_udp_src = value;
  885. }
  886. sprintf(pg_result, "OK: udp_src_min=%u", pkt_dev->udp_src_min);
  887. return count;
  888. }
  889. if (!strcmp(name, "udp_dst_min")) {
  890. len = num_arg(&user_buffer[i], 10, &value);
  891. if (len < 0)
  892. return len;
  893. i += len;
  894. if (value != pkt_dev->udp_dst_min) {
  895. pkt_dev->udp_dst_min = value;
  896. pkt_dev->cur_udp_dst = value;
  897. }
  898. sprintf(pg_result, "OK: udp_dst_min=%u", pkt_dev->udp_dst_min);
  899. return count;
  900. }
  901. if (!strcmp(name, "udp_src_max")) {
  902. len = num_arg(&user_buffer[i], 10, &value);
  903. if (len < 0)
  904. return len;
  905. i += len;
  906. if (value != pkt_dev->udp_src_max) {
  907. pkt_dev->udp_src_max = value;
  908. pkt_dev->cur_udp_src = value;
  909. }
  910. sprintf(pg_result, "OK: udp_src_max=%u", pkt_dev->udp_src_max);
  911. return count;
  912. }
  913. if (!strcmp(name, "udp_dst_max")) {
  914. len = num_arg(&user_buffer[i], 10, &value);
  915. if (len < 0)
  916. return len;
  917. i += len;
  918. if (value != pkt_dev->udp_dst_max) {
  919. pkt_dev->udp_dst_max = value;
  920. pkt_dev->cur_udp_dst = value;
  921. }
  922. sprintf(pg_result, "OK: udp_dst_max=%u", pkt_dev->udp_dst_max);
  923. return count;
  924. }
  925. if (!strcmp(name, "clone_skb")) {
  926. len = num_arg(&user_buffer[i], 10, &value);
  927. if (len < 0)
  928. return len;
  929. if ((value > 0) &&
  930. ((pkt_dev->xmit_mode == M_NETIF_RECEIVE) ||
  931. !(pkt_dev->odev->priv_flags & IFF_TX_SKB_SHARING)))
  932. return -ENOTSUPP;
  933. i += len;
  934. pkt_dev->clone_skb = value;
  935. sprintf(pg_result, "OK: clone_skb=%d", pkt_dev->clone_skb);
  936. return count;
  937. }
  938. if (!strcmp(name, "count")) {
  939. len = num_arg(&user_buffer[i], 10, &value);
  940. if (len < 0)
  941. return len;
  942. i += len;
  943. pkt_dev->count = value;
  944. sprintf(pg_result, "OK: count=%llu",
  945. (unsigned long long)pkt_dev->count);
  946. return count;
  947. }
  948. if (!strcmp(name, "src_mac_count")) {
  949. len = num_arg(&user_buffer[i], 10, &value);
  950. if (len < 0)
  951. return len;
  952. i += len;
  953. if (pkt_dev->src_mac_count != value) {
  954. pkt_dev->src_mac_count = value;
  955. pkt_dev->cur_src_mac_offset = 0;
  956. }
  957. sprintf(pg_result, "OK: src_mac_count=%d",
  958. pkt_dev->src_mac_count);
  959. return count;
  960. }
  961. if (!strcmp(name, "dst_mac_count")) {
  962. len = num_arg(&user_buffer[i], 10, &value);
  963. if (len < 0)
  964. return len;
  965. i += len;
  966. if (pkt_dev->dst_mac_count != value) {
  967. pkt_dev->dst_mac_count = value;
  968. pkt_dev->cur_dst_mac_offset = 0;
  969. }
  970. sprintf(pg_result, "OK: dst_mac_count=%d",
  971. pkt_dev->dst_mac_count);
  972. return count;
  973. }
  974. if (!strcmp(name, "burst")) {
  975. len = num_arg(&user_buffer[i], 10, &value);
  976. if (len < 0)
  977. return len;
  978. i += len;
  979. if ((value > 1) &&
  980. ((pkt_dev->xmit_mode == M_QUEUE_XMIT) ||
  981. ((pkt_dev->xmit_mode == M_START_XMIT) &&
  982. (!(pkt_dev->odev->priv_flags & IFF_TX_SKB_SHARING)))))
  983. return -ENOTSUPP;
  984. pkt_dev->burst = value < 1 ? 1 : value;
  985. sprintf(pg_result, "OK: burst=%d", pkt_dev->burst);
  986. return count;
  987. }
  988. if (!strcmp(name, "node")) {
  989. len = num_arg(&user_buffer[i], 10, &value);
  990. if (len < 0)
  991. return len;
  992. i += len;
  993. if (node_possible(value)) {
  994. pkt_dev->node = value;
  995. sprintf(pg_result, "OK: node=%d", pkt_dev->node);
  996. if (pkt_dev->page) {
  997. put_page(pkt_dev->page);
  998. pkt_dev->page = NULL;
  999. }
  1000. }
  1001. else
  1002. sprintf(pg_result, "ERROR: node not possible");
  1003. return count;
  1004. }
  1005. if (!strcmp(name, "xmit_mode")) {
  1006. char f[32];
  1007. memset(f, 0, 32);
  1008. len = strn_len(&user_buffer[i], sizeof(f) - 1);
  1009. if (len < 0)
  1010. return len;
  1011. if (copy_from_user(f, &user_buffer[i], len))
  1012. return -EFAULT;
  1013. i += len;
  1014. if (strcmp(f, "start_xmit") == 0) {
  1015. pkt_dev->xmit_mode = M_START_XMIT;
  1016. } else if (strcmp(f, "netif_receive") == 0) {
  1017. /* clone_skb set earlier, not supported in this mode */
  1018. if (pkt_dev->clone_skb > 0)
  1019. return -ENOTSUPP;
  1020. pkt_dev->xmit_mode = M_NETIF_RECEIVE;
  1021. /* make sure new packet is allocated every time
  1022. * pktgen_xmit() is called
  1023. */
  1024. pkt_dev->last_ok = 1;
  1025. /* override clone_skb if user passed default value
  1026. * at module loading time
  1027. */
  1028. pkt_dev->clone_skb = 0;
  1029. } else if (strcmp(f, "queue_xmit") == 0) {
  1030. pkt_dev->xmit_mode = M_QUEUE_XMIT;
  1031. pkt_dev->last_ok = 1;
  1032. } else {
  1033. sprintf(pg_result,
  1034. "xmit_mode -:%s:- unknown\nAvailable modes: %s",
  1035. f, "start_xmit, netif_receive\n");
  1036. return count;
  1037. }
  1038. sprintf(pg_result, "OK: xmit_mode=%s", f);
  1039. return count;
  1040. }
  1041. if (!strcmp(name, "flag")) {
  1042. __u32 flag;
  1043. char f[32];
  1044. bool disable = false;
  1045. memset(f, 0, 32);
  1046. len = strn_len(&user_buffer[i], sizeof(f) - 1);
  1047. if (len < 0)
  1048. return len;
  1049. if (copy_from_user(f, &user_buffer[i], len))
  1050. return -EFAULT;
  1051. i += len;
  1052. flag = pktgen_read_flag(f, &disable);
  1053. if (flag) {
  1054. if (disable)
  1055. pkt_dev->flags &= ~flag;
  1056. else
  1057. pkt_dev->flags |= flag;
  1058. } else {
  1059. sprintf(pg_result,
  1060. "Flag -:%s:- unknown\nAvailable flags, (prepend ! to un-set flag):\n%s",
  1061. f,
  1062. "IPSRC_RND, IPDST_RND, UDPSRC_RND, UDPDST_RND, "
  1063. "MACSRC_RND, MACDST_RND, TXSIZE_RND, IPV6, "
  1064. "MPLS_RND, VID_RND, SVID_RND, FLOW_SEQ, "
  1065. "QUEUE_MAP_RND, QUEUE_MAP_CPU, UDPCSUM, "
  1066. "NO_TIMESTAMP, "
  1067. #ifdef CONFIG_XFRM
  1068. "IPSEC, "
  1069. #endif
  1070. "NODE_ALLOC\n");
  1071. return count;
  1072. }
  1073. sprintf(pg_result, "OK: flags=0x%x", pkt_dev->flags);
  1074. return count;
  1075. }
  1076. if (!strcmp(name, "dst_min") || !strcmp(name, "dst")) {
  1077. len = strn_len(&user_buffer[i], sizeof(pkt_dev->dst_min) - 1);
  1078. if (len < 0)
  1079. return len;
  1080. if (copy_from_user(buf, &user_buffer[i], len))
  1081. return -EFAULT;
  1082. buf[len] = 0;
  1083. if (strcmp(buf, pkt_dev->dst_min) != 0) {
  1084. memset(pkt_dev->dst_min, 0, sizeof(pkt_dev->dst_min));
  1085. strcpy(pkt_dev->dst_min, buf);
  1086. pkt_dev->daddr_min = in_aton(pkt_dev->dst_min);
  1087. pkt_dev->cur_daddr = pkt_dev->daddr_min;
  1088. }
  1089. if (debug)
  1090. pr_debug("dst_min set to: %s\n", pkt_dev->dst_min);
  1091. i += len;
  1092. sprintf(pg_result, "OK: dst_min=%s", pkt_dev->dst_min);
  1093. return count;
  1094. }
  1095. if (!strcmp(name, "dst_max")) {
  1096. len = strn_len(&user_buffer[i], sizeof(pkt_dev->dst_max) - 1);
  1097. if (len < 0)
  1098. return len;
  1099. if (copy_from_user(buf, &user_buffer[i], len))
  1100. return -EFAULT;
  1101. buf[len] = 0;
  1102. if (strcmp(buf, pkt_dev->dst_max) != 0) {
  1103. memset(pkt_dev->dst_max, 0, sizeof(pkt_dev->dst_max));
  1104. strcpy(pkt_dev->dst_max, buf);
  1105. pkt_dev->daddr_max = in_aton(pkt_dev->dst_max);
  1106. pkt_dev->cur_daddr = pkt_dev->daddr_max;
  1107. }
  1108. if (debug)
  1109. pr_debug("dst_max set to: %s\n", pkt_dev->dst_max);
  1110. i += len;
  1111. sprintf(pg_result, "OK: dst_max=%s", pkt_dev->dst_max);
  1112. return count;
  1113. }
  1114. if (!strcmp(name, "dst6")) {
  1115. len = strn_len(&user_buffer[i], sizeof(buf) - 1);
  1116. if (len < 0)
  1117. return len;
  1118. pkt_dev->flags |= F_IPV6;
  1119. if (copy_from_user(buf, &user_buffer[i], len))
  1120. return -EFAULT;
  1121. buf[len] = 0;
  1122. in6_pton(buf, -1, pkt_dev->in6_daddr.s6_addr, -1, NULL);
  1123. snprintf(buf, sizeof(buf), "%pI6c", &pkt_dev->in6_daddr);
  1124. pkt_dev->cur_in6_daddr = pkt_dev->in6_daddr;
  1125. if (debug)
  1126. pr_debug("dst6 set to: %s\n", buf);
  1127. i += len;
  1128. sprintf(pg_result, "OK: dst6=%s", buf);
  1129. return count;
  1130. }
  1131. if (!strcmp(name, "dst6_min")) {
  1132. len = strn_len(&user_buffer[i], sizeof(buf) - 1);
  1133. if (len < 0)
  1134. return len;
  1135. pkt_dev->flags |= F_IPV6;
  1136. if (copy_from_user(buf, &user_buffer[i], len))
  1137. return -EFAULT;
  1138. buf[len] = 0;
  1139. in6_pton(buf, -1, pkt_dev->min_in6_daddr.s6_addr, -1, NULL);
  1140. snprintf(buf, sizeof(buf), "%pI6c", &pkt_dev->min_in6_daddr);
  1141. pkt_dev->cur_in6_daddr = pkt_dev->min_in6_daddr;
  1142. if (debug)
  1143. pr_debug("dst6_min set to: %s\n", buf);
  1144. i += len;
  1145. sprintf(pg_result, "OK: dst6_min=%s", buf);
  1146. return count;
  1147. }
  1148. if (!strcmp(name, "dst6_max")) {
  1149. len = strn_len(&user_buffer[i], sizeof(buf) - 1);
  1150. if (len < 0)
  1151. return len;
  1152. pkt_dev->flags |= F_IPV6;
  1153. if (copy_from_user(buf, &user_buffer[i], len))
  1154. return -EFAULT;
  1155. buf[len] = 0;
  1156. in6_pton(buf, -1, pkt_dev->max_in6_daddr.s6_addr, -1, NULL);
  1157. snprintf(buf, sizeof(buf), "%pI6c", &pkt_dev->max_in6_daddr);
  1158. if (debug)
  1159. pr_debug("dst6_max set to: %s\n", buf);
  1160. i += len;
  1161. sprintf(pg_result, "OK: dst6_max=%s", buf);
  1162. return count;
  1163. }
  1164. if (!strcmp(name, "src6")) {
  1165. len = strn_len(&user_buffer[i], sizeof(buf) - 1);
  1166. if (len < 0)
  1167. return len;
  1168. pkt_dev->flags |= F_IPV6;
  1169. if (copy_from_user(buf, &user_buffer[i], len))
  1170. return -EFAULT;
  1171. buf[len] = 0;
  1172. in6_pton(buf, -1, pkt_dev->in6_saddr.s6_addr, -1, NULL);
  1173. snprintf(buf, sizeof(buf), "%pI6c", &pkt_dev->in6_saddr);
  1174. pkt_dev->cur_in6_saddr = pkt_dev->in6_saddr;
  1175. if (debug)
  1176. pr_debug("src6 set to: %s\n", buf);
  1177. i += len;
  1178. sprintf(pg_result, "OK: src6=%s", buf);
  1179. return count;
  1180. }
  1181. if (!strcmp(name, "src_min")) {
  1182. len = strn_len(&user_buffer[i], sizeof(pkt_dev->src_min) - 1);
  1183. if (len < 0)
  1184. return len;
  1185. if (copy_from_user(buf, &user_buffer[i], len))
  1186. return -EFAULT;
  1187. buf[len] = 0;
  1188. if (strcmp(buf, pkt_dev->src_min) != 0) {
  1189. memset(pkt_dev->src_min, 0, sizeof(pkt_dev->src_min));
  1190. strcpy(pkt_dev->src_min, buf);
  1191. pkt_dev->saddr_min = in_aton(pkt_dev->src_min);
  1192. pkt_dev->cur_saddr = pkt_dev->saddr_min;
  1193. }
  1194. if (debug)
  1195. pr_debug("src_min set to: %s\n", pkt_dev->src_min);
  1196. i += len;
  1197. sprintf(pg_result, "OK: src_min=%s", pkt_dev->src_min);
  1198. return count;
  1199. }
  1200. if (!strcmp(name, "src_max")) {
  1201. len = strn_len(&user_buffer[i], sizeof(pkt_dev->src_max) - 1);
  1202. if (len < 0)
  1203. return len;
  1204. if (copy_from_user(buf, &user_buffer[i], len))
  1205. return -EFAULT;
  1206. buf[len] = 0;
  1207. if (strcmp(buf, pkt_dev->src_max) != 0) {
  1208. memset(pkt_dev->src_max, 0, sizeof(pkt_dev->src_max));
  1209. strcpy(pkt_dev->src_max, buf);
  1210. pkt_dev->saddr_max = in_aton(pkt_dev->src_max);
  1211. pkt_dev->cur_saddr = pkt_dev->saddr_max;
  1212. }
  1213. if (debug)
  1214. pr_debug("src_max set to: %s\n", pkt_dev->src_max);
  1215. i += len;
  1216. sprintf(pg_result, "OK: src_max=%s", pkt_dev->src_max);
  1217. return count;
  1218. }
  1219. if (!strcmp(name, "dst_mac")) {
  1220. len = strn_len(&user_buffer[i], sizeof(valstr) - 1);
  1221. if (len < 0)
  1222. return len;
  1223. memset(valstr, 0, sizeof(valstr));
  1224. if (copy_from_user(valstr, &user_buffer[i], len))
  1225. return -EFAULT;
  1226. if (!mac_pton(valstr, pkt_dev->dst_mac))
  1227. return -EINVAL;
  1228. /* Set up Dest MAC */
  1229. ether_addr_copy(&pkt_dev->hh[0], pkt_dev->dst_mac);
  1230. sprintf(pg_result, "OK: dstmac %pM", pkt_dev->dst_mac);
  1231. return count;
  1232. }
  1233. if (!strcmp(name, "src_mac")) {
  1234. len = strn_len(&user_buffer[i], sizeof(valstr) - 1);
  1235. if (len < 0)
  1236. return len;
  1237. memset(valstr, 0, sizeof(valstr));
  1238. if (copy_from_user(valstr, &user_buffer[i], len))
  1239. return -EFAULT;
  1240. if (!mac_pton(valstr, pkt_dev->src_mac))
  1241. return -EINVAL;
  1242. /* Set up Src MAC */
  1243. ether_addr_copy(&pkt_dev->hh[6], pkt_dev->src_mac);
  1244. sprintf(pg_result, "OK: srcmac %pM", pkt_dev->src_mac);
  1245. return count;
  1246. }
  1247. if (!strcmp(name, "clear_counters")) {
  1248. pktgen_clear_counters(pkt_dev);
  1249. sprintf(pg_result, "OK: Clearing counters.\n");
  1250. return count;
  1251. }
  1252. if (!strcmp(name, "flows")) {
  1253. len = num_arg(&user_buffer[i], 10, &value);
  1254. if (len < 0)
  1255. return len;
  1256. i += len;
  1257. if (value > MAX_CFLOWS)
  1258. value = MAX_CFLOWS;
  1259. pkt_dev->cflows = value;
  1260. sprintf(pg_result, "OK: flows=%u", pkt_dev->cflows);
  1261. return count;
  1262. }
  1263. #ifdef CONFIG_XFRM
  1264. if (!strcmp(name, "spi")) {
  1265. len = num_arg(&user_buffer[i], 10, &value);
  1266. if (len < 0)
  1267. return len;
  1268. i += len;
  1269. pkt_dev->spi = value;
  1270. sprintf(pg_result, "OK: spi=%u", pkt_dev->spi);
  1271. return count;
  1272. }
  1273. #endif
  1274. if (!strcmp(name, "flowlen")) {
  1275. len = num_arg(&user_buffer[i], 10, &value);
  1276. if (len < 0)
  1277. return len;
  1278. i += len;
  1279. pkt_dev->lflow = value;
  1280. sprintf(pg_result, "OK: flowlen=%u", pkt_dev->lflow);
  1281. return count;
  1282. }
  1283. if (!strcmp(name, "queue_map_min")) {
  1284. len = num_arg(&user_buffer[i], 5, &value);
  1285. if (len < 0)
  1286. return len;
  1287. i += len;
  1288. pkt_dev->queue_map_min = value;
  1289. sprintf(pg_result, "OK: queue_map_min=%u", pkt_dev->queue_map_min);
  1290. return count;
  1291. }
  1292. if (!strcmp(name, "queue_map_max")) {
  1293. len = num_arg(&user_buffer[i], 5, &value);
  1294. if (len < 0)
  1295. return len;
  1296. i += len;
  1297. pkt_dev->queue_map_max = value;
  1298. sprintf(pg_result, "OK: queue_map_max=%u", pkt_dev->queue_map_max);
  1299. return count;
  1300. }
  1301. if (!strcmp(name, "mpls")) {
  1302. unsigned int n, cnt;
  1303. len = get_labels(&user_buffer[i], pkt_dev);
  1304. if (len < 0)
  1305. return len;
  1306. i += len;
  1307. cnt = sprintf(pg_result, "OK: mpls=");
  1308. for (n = 0; n < pkt_dev->nr_labels; n++)
  1309. cnt += sprintf(pg_result + cnt,
  1310. "%08x%s", ntohl(pkt_dev->labels[n]),
  1311. n == pkt_dev->nr_labels-1 ? "" : ",");
  1312. if (pkt_dev->nr_labels && pkt_dev->vlan_id != 0xffff) {
  1313. pkt_dev->vlan_id = 0xffff; /* turn off VLAN/SVLAN */
  1314. pkt_dev->svlan_id = 0xffff;
  1315. if (debug)
  1316. pr_debug("VLAN/SVLAN auto turned off\n");
  1317. }
  1318. return count;
  1319. }
  1320. if (!strcmp(name, "vlan_id")) {
  1321. len = num_arg(&user_buffer[i], 4, &value);
  1322. if (len < 0)
  1323. return len;
  1324. i += len;
  1325. if (value <= 4095) {
  1326. pkt_dev->vlan_id = value; /* turn on VLAN */
  1327. if (debug)
  1328. pr_debug("VLAN turned on\n");
  1329. if (debug && pkt_dev->nr_labels)
  1330. pr_debug("MPLS auto turned off\n");
  1331. pkt_dev->nr_labels = 0; /* turn off MPLS */
  1332. sprintf(pg_result, "OK: vlan_id=%u", pkt_dev->vlan_id);
  1333. } else {
  1334. pkt_dev->vlan_id = 0xffff; /* turn off VLAN/SVLAN */
  1335. pkt_dev->svlan_id = 0xffff;
  1336. if (debug)
  1337. pr_debug("VLAN/SVLAN turned off\n");
  1338. }
  1339. return count;
  1340. }
  1341. if (!strcmp(name, "vlan_p")) {
  1342. len = num_arg(&user_buffer[i], 1, &value);
  1343. if (len < 0)
  1344. return len;
  1345. i += len;
  1346. if ((value <= 7) && (pkt_dev->vlan_id != 0xffff)) {
  1347. pkt_dev->vlan_p = value;
  1348. sprintf(pg_result, "OK: vlan_p=%u", pkt_dev->vlan_p);
  1349. } else {
  1350. sprintf(pg_result, "ERROR: vlan_p must be 0-7");
  1351. }
  1352. return count;
  1353. }
  1354. if (!strcmp(name, "vlan_cfi")) {
  1355. len = num_arg(&user_buffer[i], 1, &value);
  1356. if (len < 0)
  1357. return len;
  1358. i += len;
  1359. if ((value <= 1) && (pkt_dev->vlan_id != 0xffff)) {
  1360. pkt_dev->vlan_cfi = value;
  1361. sprintf(pg_result, "OK: vlan_cfi=%u", pkt_dev->vlan_cfi);
  1362. } else {
  1363. sprintf(pg_result, "ERROR: vlan_cfi must be 0-1");
  1364. }
  1365. return count;
  1366. }
  1367. if (!strcmp(name, "svlan_id")) {
  1368. len = num_arg(&user_buffer[i], 4, &value);
  1369. if (len < 0)
  1370. return len;
  1371. i += len;
  1372. if ((value <= 4095) && ((pkt_dev->vlan_id != 0xffff))) {
  1373. pkt_dev->svlan_id = value; /* turn on SVLAN */
  1374. if (debug)
  1375. pr_debug("SVLAN turned on\n");
  1376. if (debug && pkt_dev->nr_labels)
  1377. pr_debug("MPLS auto turned off\n");
  1378. pkt_dev->nr_labels = 0; /* turn off MPLS */
  1379. sprintf(pg_result, "OK: svlan_id=%u", pkt_dev->svlan_id);
  1380. } else {
  1381. pkt_dev->vlan_id = 0xffff; /* turn off VLAN/SVLAN */
  1382. pkt_dev->svlan_id = 0xffff;
  1383. if (debug)
  1384. pr_debug("VLAN/SVLAN turned off\n");
  1385. }
  1386. return count;
  1387. }
  1388. if (!strcmp(name, "svlan_p")) {
  1389. len = num_arg(&user_buffer[i], 1, &value);
  1390. if (len < 0)
  1391. return len;
  1392. i += len;
  1393. if ((value <= 7) && (pkt_dev->svlan_id != 0xffff)) {
  1394. pkt_dev->svlan_p = value;
  1395. sprintf(pg_result, "OK: svlan_p=%u", pkt_dev->svlan_p);
  1396. } else {
  1397. sprintf(pg_result, "ERROR: svlan_p must be 0-7");
  1398. }
  1399. return count;
  1400. }
  1401. if (!strcmp(name, "svlan_cfi")) {
  1402. len = num_arg(&user_buffer[i], 1, &value);
  1403. if (len < 0)
  1404. return len;
  1405. i += len;
  1406. if ((value <= 1) && (pkt_dev->svlan_id != 0xffff)) {
  1407. pkt_dev->svlan_cfi = value;
  1408. sprintf(pg_result, "OK: svlan_cfi=%u", pkt_dev->svlan_cfi);
  1409. } else {
  1410. sprintf(pg_result, "ERROR: svlan_cfi must be 0-1");
  1411. }
  1412. return count;
  1413. }
  1414. if (!strcmp(name, "tos")) {
  1415. __u32 tmp_value = 0;
  1416. len = hex32_arg(&user_buffer[i], 2, &tmp_value);
  1417. if (len < 0)
  1418. return len;
  1419. i += len;
  1420. if (len == 2) {
  1421. pkt_dev->tos = tmp_value;
  1422. sprintf(pg_result, "OK: tos=0x%02x", pkt_dev->tos);
  1423. } else {
  1424. sprintf(pg_result, "ERROR: tos must be 00-ff");
  1425. }
  1426. return count;
  1427. }
  1428. if (!strcmp(name, "traffic_class")) {
  1429. __u32 tmp_value = 0;
  1430. len = hex32_arg(&user_buffer[i], 2, &tmp_value);
  1431. if (len < 0)
  1432. return len;
  1433. i += len;
  1434. if (len == 2) {
  1435. pkt_dev->traffic_class = tmp_value;
  1436. sprintf(pg_result, "OK: traffic_class=0x%02x", pkt_dev->traffic_class);
  1437. } else {
  1438. sprintf(pg_result, "ERROR: traffic_class must be 00-ff");
  1439. }
  1440. return count;
  1441. }
  1442. if (!strcmp(name, "skb_priority")) {
  1443. len = num_arg(&user_buffer[i], 9, &value);
  1444. if (len < 0)
  1445. return len;
  1446. i += len;
  1447. pkt_dev->skb_priority = value;
  1448. sprintf(pg_result, "OK: skb_priority=%i",
  1449. pkt_dev->skb_priority);
  1450. return count;
  1451. }
  1452. sprintf(pkt_dev->result, "No such parameter \"%s\"", name);
  1453. return -EINVAL;
  1454. }
  1455. static int pktgen_if_open(struct inode *inode, struct file *file)
  1456. {
  1457. return single_open(file, pktgen_if_show, PDE_DATA(inode));
  1458. }
  1459. static const struct proc_ops pktgen_if_proc_ops = {
  1460. .proc_open = pktgen_if_open,
  1461. .proc_read = seq_read,
  1462. .proc_lseek = seq_lseek,
  1463. .proc_write = pktgen_if_write,
  1464. .proc_release = single_release,
  1465. };
  1466. static int pktgen_thread_show(struct seq_file *seq, void *v)
  1467. {
  1468. struct pktgen_thread *t = seq->private;
  1469. const struct pktgen_dev *pkt_dev;
  1470. BUG_ON(!t);
  1471. seq_puts(seq, "Running: ");
  1472. rcu_read_lock();
  1473. list_for_each_entry_rcu(pkt_dev, &t->if_list, list)
  1474. if (pkt_dev->running)
  1475. seq_printf(seq, "%s ", pkt_dev->odevname);
  1476. seq_puts(seq, "\nStopped: ");
  1477. list_for_each_entry_rcu(pkt_dev, &t->if_list, list)
  1478. if (!pkt_dev->running)
  1479. seq_printf(seq, "%s ", pkt_dev->odevname);
  1480. if (t->result[0])
  1481. seq_printf(seq, "\nResult: %s\n", t->result);
  1482. else
  1483. seq_puts(seq, "\nResult: NA\n");
  1484. rcu_read_unlock();
  1485. return 0;
  1486. }
  1487. static ssize_t pktgen_thread_write(struct file *file,
  1488. const char __user * user_buffer,
  1489. size_t count, loff_t * offset)
  1490. {
  1491. struct seq_file *seq = file->private_data;
  1492. struct pktgen_thread *t = seq->private;
  1493. int i, max, len, ret;
  1494. char name[40];
  1495. char *pg_result;
  1496. if (count < 1) {
  1497. // sprintf(pg_result, "Wrong command format");
  1498. return -EINVAL;
  1499. }
  1500. max = count;
  1501. len = count_trail_chars(user_buffer, max);
  1502. if (len < 0)
  1503. return len;
  1504. i = len;
  1505. /* Read variable name */
  1506. len = strn_len(&user_buffer[i], sizeof(name) - 1);
  1507. if (len < 0)
  1508. return len;
  1509. memset(name, 0, sizeof(name));
  1510. if (copy_from_user(name, &user_buffer[i], len))
  1511. return -EFAULT;
  1512. i += len;
  1513. max = count - i;
  1514. len = count_trail_chars(&user_buffer[i], max);
  1515. if (len < 0)
  1516. return len;
  1517. i += len;
  1518. if (debug)
  1519. pr_debug("t=%s, count=%lu\n", name, (unsigned long)count);
  1520. if (!t) {
  1521. pr_err("ERROR: No thread\n");
  1522. ret = -EINVAL;
  1523. goto out;
  1524. }
  1525. pg_result = &(t->result[0]);
  1526. if (!strcmp(name, "add_device")) {
  1527. char f[32];
  1528. memset(f, 0, 32);
  1529. len = strn_len(&user_buffer[i], sizeof(f) - 1);
  1530. if (len < 0) {
  1531. ret = len;
  1532. goto out;
  1533. }
  1534. if (copy_from_user(f, &user_buffer[i], len))
  1535. return -EFAULT;
  1536. i += len;
  1537. mutex_lock(&pktgen_thread_lock);
  1538. ret = pktgen_add_device(t, f);
  1539. mutex_unlock(&pktgen_thread_lock);
  1540. if (!ret) {
  1541. ret = count;
  1542. sprintf(pg_result, "OK: add_device=%s", f);
  1543. } else
  1544. sprintf(pg_result, "ERROR: can not add device %s", f);
  1545. goto out;
  1546. }
  1547. if (!strcmp(name, "rem_device_all")) {
  1548. mutex_lock(&pktgen_thread_lock);
  1549. t->control |= T_REMDEVALL;
  1550. mutex_unlock(&pktgen_thread_lock);
  1551. schedule_timeout_interruptible(msecs_to_jiffies(125)); /* Propagate thread->control */
  1552. ret = count;
  1553. sprintf(pg_result, "OK: rem_device_all");
  1554. goto out;
  1555. }
  1556. if (!strcmp(name, "max_before_softirq")) {
  1557. sprintf(pg_result, "OK: Note! max_before_softirq is obsoleted -- Do not use");
  1558. ret = count;
  1559. goto out;
  1560. }
  1561. ret = -EINVAL;
  1562. out:
  1563. return ret;
  1564. }
  1565. static int pktgen_thread_open(struct inode *inode, struct file *file)
  1566. {
  1567. return single_open(file, pktgen_thread_show, PDE_DATA(inode));
  1568. }
  1569. static const struct proc_ops pktgen_thread_proc_ops = {
  1570. .proc_open = pktgen_thread_open,
  1571. .proc_read = seq_read,
  1572. .proc_lseek = seq_lseek,
  1573. .proc_write = pktgen_thread_write,
  1574. .proc_release = single_release,
  1575. };
  1576. /* Think find or remove for NN */
  1577. static struct pktgen_dev *__pktgen_NN_threads(const struct pktgen_net *pn,
  1578. const char *ifname, int remove)
  1579. {
  1580. struct pktgen_thread *t;
  1581. struct pktgen_dev *pkt_dev = NULL;
  1582. bool exact = (remove == FIND);
  1583. list_for_each_entry(t, &pn->pktgen_threads, th_list) {
  1584. pkt_dev = pktgen_find_dev(t, ifname, exact);
  1585. if (pkt_dev) {
  1586. if (remove) {
  1587. pkt_dev->removal_mark = 1;
  1588. t->control |= T_REMDEV;
  1589. }
  1590. break;
  1591. }
  1592. }
  1593. return pkt_dev;
  1594. }
  1595. /*
  1596. * mark a device for removal
  1597. */
  1598. static void pktgen_mark_device(const struct pktgen_net *pn, const char *ifname)
  1599. {
  1600. struct pktgen_dev *pkt_dev = NULL;
  1601. const int max_tries = 10, msec_per_try = 125;
  1602. int i = 0;
  1603. mutex_lock(&pktgen_thread_lock);
  1604. pr_debug("%s: marking %s for removal\n", __func__, ifname);
  1605. while (1) {
  1606. pkt_dev = __pktgen_NN_threads(pn, ifname, REMOVE);
  1607. if (pkt_dev == NULL)
  1608. break; /* success */
  1609. mutex_unlock(&pktgen_thread_lock);
  1610. pr_debug("%s: waiting for %s to disappear....\n",
  1611. __func__, ifname);
  1612. schedule_timeout_interruptible(msecs_to_jiffies(msec_per_try));
  1613. mutex_lock(&pktgen_thread_lock);
  1614. if (++i >= max_tries) {
  1615. pr_err("%s: timed out after waiting %d msec for device %s to be removed\n",
  1616. __func__, msec_per_try * i, ifname);
  1617. break;
  1618. }
  1619. }
  1620. mutex_unlock(&pktgen_thread_lock);
  1621. }
  1622. static void pktgen_change_name(const struct pktgen_net *pn, struct net_device *dev)
  1623. {
  1624. struct pktgen_thread *t;
  1625. mutex_lock(&pktgen_thread_lock);
  1626. list_for_each_entry(t, &pn->pktgen_threads, th_list) {
  1627. struct pktgen_dev *pkt_dev;
  1628. if_lock(t);
  1629. list_for_each_entry(pkt_dev, &t->if_list, list) {
  1630. if (pkt_dev->odev != dev)
  1631. continue;
  1632. proc_remove(pkt_dev->entry);
  1633. pkt_dev->entry = proc_create_data(dev->name, 0600,
  1634. pn->proc_dir,
  1635. &pktgen_if_proc_ops,
  1636. pkt_dev);
  1637. if (!pkt_dev->entry)
  1638. pr_err("can't move proc entry for '%s'\n",
  1639. dev->name);
  1640. break;
  1641. }
  1642. if_unlock(t);
  1643. }
  1644. mutex_unlock(&pktgen_thread_lock);
  1645. }
  1646. static int pktgen_device_event(struct notifier_block *unused,
  1647. unsigned long event, void *ptr)
  1648. {
  1649. struct net_device *dev = netdev_notifier_info_to_dev(ptr);
  1650. struct pktgen_net *pn = net_generic(dev_net(dev), pg_net_id);
  1651. if (pn->pktgen_exiting)
  1652. return NOTIFY_DONE;
  1653. /* It is OK that we do not hold the group lock right now,
  1654. * as we run under the RTNL lock.
  1655. */
  1656. switch (event) {
  1657. case NETDEV_CHANGENAME:
  1658. pktgen_change_name(pn, dev);
  1659. break;
  1660. case NETDEV_UNREGISTER:
  1661. pktgen_mark_device(pn, dev->name);
  1662. break;
  1663. }
  1664. return NOTIFY_DONE;
  1665. }
  1666. static struct net_device *pktgen_dev_get_by_name(const struct pktgen_net *pn,
  1667. struct pktgen_dev *pkt_dev,
  1668. const char *ifname)
  1669. {
  1670. char b[IFNAMSIZ+5];
  1671. int i;
  1672. for (i = 0; ifname[i] != '@'; i++