3 * Copyright 2001, 2002 by Robert Olsson <robert.olsson@its.uu.se>
4 * Uppsala University and
5 * Swedish University of Agricultural Sciences
7 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
8 * Ben Greear <greearb@candelatech.com>
9 * Jens Låås <jens.laas@data.slu.se>
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.
17 * A tool for loading the network with preconfigurated packets.
18 * The tool is implemented as a linux module. Parameters are output
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.
23 * Additional hacking by:
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>
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
49 * as a "fastpath" with a configurable number of clones after alloc's.
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
54 * Also moved to /proc/net/pktgen/
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>
61 * Integrated to 2.5.x 021029 --Lucio Maciel (luciomaciel@zipmail.com.br)
64 * 021124 Finished major redesign and rewrite for new functionality.
65 * See Documentation/networking/pktgen.txt for how to use this.
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
72 * way. The if_lock should be possible to remove when add/rem_device is merged
75 * By design there should only be *one* "controlling" process. In practice
76 * multiple write accesses gives unpredictable result. Understood by "write"
77 * to /proc gives result code thats should be read be the "writer".
78 * For practical use this should be no problem.
80 * Note when adding devices to a specific CPU there good idea to also assign
81 * /proc/irq/XX/smp_affinity so TX-interrupts gets bound to the same CPU.
84 * Fix refcount off by one if first packet fails, potential null deref,
87 * First "ranges" functionality for ipv6 030726 --ro
89 * Included flow support. 030802 ANK.
91 * Fixed unaligned access on IA-64 Grant Grundler <grundler@parisc-linux.org>
93 * Remove if fix from added Harald Welte <laforge@netfilter.org> 040419
94 * ia64 compilation fix from Aron Griffis <aron@hp.com> 040604
96 * New xmit() return, do_div and misc clean up by Stephen Hemminger
97 * <shemminger@osdl.org> 040923
99 * Randy Dunlap fixed u64 printk compiler waring
101 * Remove FCS from BW calculation. Lennert Buytenhek <buytenh@wantstofly.org>
102 * New time handling. Lennert Buytenhek <buytenh@wantstofly.org> 041213
104 * Corrections from Nikolai Malykh (nmalykh@bilim.com)
105 * Removed unused flags F_SET_SRCMAC & F_SET_SRCIP 041230
107 * interruptible_sleep_on_timeout() replaced Nishanth Aravamudan <nacc@us.ibm.com>
110 * MPLS support by Steven Whitehouse <steve@chygwyn.com>
112 * 802.1Q/Q-in-Q support by Francesco Fondelli (FF) <francesco.fondelli@gmail.com>
114 * Fixed src_mac command to set source mac of packet to value specified in
115 * command by Adit Ranadive <adit.262@gmail.com>
118 #include <linux/sys.h>
119 #include <linux/types.h>
120 #include <linux/module.h>
121 #include <linux/moduleparam.h>
122 #include <linux/kernel.h>
123 #include <linux/mutex.h>
124 #include <linux/sched.h>
125 #include <linux/slab.h>
126 #include <linux/vmalloc.h>
127 #include <linux/unistd.h>
128 #include <linux/string.h>
129 #include <linux/ptrace.h>
130 #include <linux/errno.h>
131 #include <linux/ioport.h>
132 #include <linux/interrupt.h>
133 #include <linux/capability.h>
134 #include <linux/freezer.h>
135 #include <linux/delay.h>
136 #include <linux/timer.h>
137 #include <linux/list.h>
138 #include <linux/init.h>
139 #include <linux/skbuff.h>
140 #include <linux/netdevice.h>
141 #include <linux/inet.h>
142 #include <linux/inetdevice.h>
143 #include <linux/rtnetlink.h>
144 #include <linux/if_arp.h>
145 #include <linux/if_vlan.h>
146 #include <linux/in.h>
147 #include <linux/ip.h>
148 #include <linux/ipv6.h>
149 #include <linux/udp.h>
150 #include <linux/proc_fs.h>
151 #include <linux/seq_file.h>
152 #include <linux/wait.h>
153 #include <linux/etherdevice.h>
154 #include <linux/kthread.h>
155 #include <net/net_namespace.h>
156 #include <net/checksum.h>
157 #include <net/ipv6.h>
158 #include <net/addrconf.h>
160 #include <net/xfrm.h>
162 #include <asm/byteorder.h>
163 #include <linux/rcupdate.h>
164 #include <linux/bitops.h>
167 #include <asm/uaccess.h>
168 #include <asm/div64.h> /* do_div */
169 #include <asm/timex.h>
171 #define VERSION "pktgen v2.70: Packet Generator for packet performance testing.\n"
173 #define IP_NAME_SZ 32
174 #define MAX_MPLS_LABELS 16 /* This is the max label stack depth */
175 #define MPLS_STACK_BOTTOM htonl(0x00000100)
177 /* Device flag bits */
178 #define F_IPSRC_RND (1<<0) /* IP-Src Random */
179 #define F_IPDST_RND (1<<1) /* IP-Dst Random */
180 #define F_UDPSRC_RND (1<<2) /* UDP-Src Random */
181 #define F_UDPDST_RND (1<<3) /* UDP-Dst Random */
182 #define F_MACSRC_RND (1<<4) /* MAC-Src Random */
183 #define F_MACDST_RND (1<<5) /* MAC-Dst Random */
184 #define F_TXSIZE_RND (1<<6) /* Transmit size is random */
185 #define F_IPV6 (1<<7) /* Interface in IPV6 Mode */
186 #define F_MPLS_RND (1<<8) /* Random MPLS labels */
187 #define F_VID_RND (1<<9) /* Random VLAN ID */
188 #define F_SVID_RND (1<<10) /* Random SVLAN ID */
189 #define F_FLOW_SEQ (1<<11) /* Sequential flows */
190 #define F_IPSEC_ON (1<<12) /* ipsec on for flows */
191 #define F_QUEUE_MAP_RND (1<<13) /* queue map Random */
192 #define F_QUEUE_MAP_CPU (1<<14) /* queue map mirrors smp_processor_id() */
194 /* Thread control flag bits */
195 #define T_TERMINATE (1<<0)
196 #define T_STOP (1<<1) /* Stop run */
197 #define T_RUN (1<<2) /* Start run */
198 #define T_REMDEVALL (1<<3) /* Remove all devs */
199 #define T_REMDEV (1<<4) /* Remove one dev */
201 /* If lock -- can be removed after some work */
202 #define if_lock(t) spin_lock(&(t->if_lock));
203 #define if_unlock(t) spin_unlock(&(t->if_lock));
205 /* Used to help with determining the pkts on receive */
206 #define PKTGEN_MAGIC 0xbe9be955
207 #define PG_PROC_DIR "pktgen"
208 #define PGCTRL "pgctrl"
209 static struct proc_dir_entry
*pg_proc_dir
= NULL
;
211 #define MAX_CFLOWS 65536
213 #define VLAN_TAG_SIZE(x) ((x)->vlan_id == 0xffff ? 0 : 4)
214 #define SVLAN_TAG_SIZE(x) ((x)->svlan_id == 0xffff ? 0 : 4)
220 struct xfrm_state
*x
;
226 #define F_INIT (1<<0) /* flow has been initialized */
230 * Try to keep frequent/infrequent used vars. separated.
232 struct proc_dir_entry
*entry
; /* proc file */
233 struct pktgen_thread
*pg_thread
;/* the owner */
234 struct list_head list
; /* Used for chaining in the thread's run-queue */
236 int running
; /* if this changes to false, the test will stop */
238 /* If min != max, then we will either do a linear iteration, or
239 * we will do a random selection from within the range.
242 int removal_mark
; /* non-zero => the device is marked for
243 * removal by worker thread */
245 int min_pkt_size
; /* = ETH_ZLEN; */
246 int max_pkt_size
; /* = ETH_ZLEN; */
247 int pkt_overhead
; /* overhead for MPLS, VLANs, IPSEC etc */
249 __u32 delay_us
; /* Default delay */
251 __u64 count
; /* Default No packets to send */
252 __u64 sofar
; /* How many pkts we've sent so far */
253 __u64 tx_bytes
; /* How many bytes we've transmitted */
254 __u64 errors
; /* Errors when trying to transmit, pkts will be re-sent */
256 /* runtime counters relating to clone_skb */
257 __u64 next_tx_us
; /* timestamp of when to tx next */
260 __u64 allocated_skbs
;
262 int last_ok
; /* Was last skb sent?
263 * Or a failed transmit of some sort? This will keep
264 * sequence numbers in order, for example.
266 __u64 started_at
; /* micro-seconds */
267 __u64 stopped_at
; /* micro-seconds */
268 __u64 idle_acc
; /* micro-seconds */
271 int clone_skb
; /* Use multiple SKBs during packet gen. If this number
272 * is greater than 1, then that many copies of the same
273 * packet will be sent before a new packet is allocated.
274 * For instance, if you want to send 1024 identical packets
275 * before creating a new packet, set clone_skb to 1024.
278 char dst_min
[IP_NAME_SZ
]; /* IP, ie 1.2.3.4 */
279 char dst_max
[IP_NAME_SZ
]; /* IP, ie 1.2.3.4 */
280 char src_min
[IP_NAME_SZ
]; /* IP, ie 1.2.3.4 */
281 char src_max
[IP_NAME_SZ
]; /* IP, ie 1.2.3.4 */
283 struct in6_addr in6_saddr
;
284 struct in6_addr in6_daddr
;
285 struct in6_addr cur_in6_daddr
;
286 struct in6_addr cur_in6_saddr
;
288 struct in6_addr min_in6_daddr
;
289 struct in6_addr max_in6_daddr
;
290 struct in6_addr min_in6_saddr
;
291 struct in6_addr max_in6_saddr
;
293 /* If we're doing ranges, random or incremental, then this
294 * defines the min/max for those ranges.
296 __be32 saddr_min
; /* inclusive, source IP address */
297 __be32 saddr_max
; /* exclusive, source IP address */
298 __be32 daddr_min
; /* inclusive, dest IP address */
299 __be32 daddr_max
; /* exclusive, dest IP address */
301 __u16 udp_src_min
; /* inclusive, source UDP port */
302 __u16 udp_src_max
; /* exclusive, source UDP port */
303 __u16 udp_dst_min
; /* inclusive, dest UDP port */
304 __u16 udp_dst_max
; /* exclusive, dest UDP port */
307 __u8 tos
; /* six most significant bits of (former) IPv4 TOS are for dscp codepoint */
308 __u8 traffic_class
; /* ditto for the (former) Traffic Class in IPv6 (see RFC 3260, sec. 4) */
311 unsigned nr_labels
; /* Depth of stack, 0 = no MPLS */
312 __be32 labels
[MAX_MPLS_LABELS
];
314 /* VLAN/SVLAN (802.1Q/Q-in-Q) */
317 __u16 vlan_id
; /* 0xffff means no vlan tag */
321 __u16 svlan_id
; /* 0xffff means no svlan tag */
323 __u32 src_mac_count
; /* How many MACs to iterate through */
324 __u32 dst_mac_count
; /* How many MACs to iterate through */
326 unsigned char dst_mac
[ETH_ALEN
];
327 unsigned char src_mac
[ETH_ALEN
];
329 __u32 cur_dst_mac_offset
;
330 __u32 cur_src_mac_offset
;
340 0x00, 0x80, 0xC8, 0x79, 0xB3, 0xCB,
342 We fill in SRC address later
343 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
347 __u16 pad
; /* pad out the hh struct to an even 16 bytes */
349 struct sk_buff
*skb
; /* skb we are to transmit next, mainly used for when we
350 * are transmitting the same one multiple times
352 struct net_device
*odev
; /* The out-going device. Note that the device should
353 * have it's pg_info pointer pointing back to this
354 * device. This will be set when the user specifies
355 * the out-going device name (not when the inject is
356 * started as it used to do.)
358 struct flow_state
*flows
;
359 unsigned cflows
; /* Concurrent flows (config) */
360 unsigned lflow
; /* Flow length (config) */
361 unsigned nflows
; /* accumulated flows (stats) */
362 unsigned curfl
; /* current sequenced flow (state)*/
368 __u8 ipsmode
; /* IPSEC mode (config) */
369 __u8 ipsproto
; /* IPSEC type (config) */
381 struct pktgen_thread
{
383 struct list_head if_list
; /* All device here */
384 struct list_head th_list
;
385 struct task_struct
*tsk
;
388 /* Field for thread to receive "posted" events terminate, stop ifs etc. */
393 wait_queue_head_t queue
;
394 struct completion start_done
;
400 /** Convert to micro-seconds */
401 static inline __u64
tv_to_us(const struct timeval
*tv
)
403 __u64 us
= tv
->tv_usec
;
404 us
+= (__u64
) tv
->tv_sec
* (__u64
) 1000000;
408 static __u64
getCurUs(void)
411 do_gettimeofday(&tv
);
412 return tv_to_us(&tv
);
415 /* old include end */
417 static char version
[] __initdata
= VERSION
;
419 static int pktgen_remove_device(struct pktgen_thread
*t
, struct pktgen_dev
*i
);
420 static int pktgen_add_device(struct pktgen_thread
*t
, const char *ifname
);
421 static struct pktgen_dev
*pktgen_find_dev(struct pktgen_thread
*t
,
423 static int pktgen_device_event(struct notifier_block
*, unsigned long, void *);
424 static void pktgen_run_all_threads(void);
425 static void pktgen_reset_all_threads(void);
426 static void pktgen_stop_all_threads_ifs(void);
427 static int pktgen_stop_device(struct pktgen_dev
*pkt_dev
);
428 static void pktgen_stop(struct pktgen_thread
*t
);
429 static void pktgen_clear_counters(struct pktgen_dev
*pkt_dev
);
431 static unsigned int scan_ip6(const char *s
, char ip
[16]);
432 static unsigned int fmt_ip6(char *s
, const char ip
[16]);
434 /* Module parameters, defaults. */
435 static int pg_count_d
= 1000; /* 1000 pkts by default */
436 static int pg_delay_d
;
437 static int pg_clone_skb_d
;
440 static DEFINE_MUTEX(pktgen_thread_lock
);
441 static LIST_HEAD(pktgen_threads
);
443 static struct notifier_block pktgen_notifier_block
= {
444 .notifier_call
= pktgen_device_event
,
448 * /proc handling functions
452 static int pgctrl_show(struct seq_file
*seq
, void *v
)
454 seq_puts(seq
, VERSION
);
458 static ssize_t
pgctrl_write(struct file
*file
, const char __user
* buf
,
459 size_t count
, loff_t
* ppos
)
464 if (!capable(CAP_NET_ADMIN
)) {
469 if (count
> sizeof(data
))
470 count
= sizeof(data
);
472 if (copy_from_user(data
, buf
, count
)) {
476 data
[count
- 1] = 0; /* Make string */
478 if (!strcmp(data
, "stop"))
479 pktgen_stop_all_threads_ifs();
481 else if (!strcmp(data
, "start"))
482 pktgen_run_all_threads();
484 else if (!strcmp(data
, "reset"))
485 pktgen_reset_all_threads();
488 printk(KERN_WARNING
"pktgen: Unknown command: %s\n", data
);
496 static int pgctrl_open(struct inode
*inode
, struct file
*file
)
498 return single_open(file
, pgctrl_show
, PDE(inode
)->data
);
501 static const struct file_operations pktgen_fops
= {
502 .owner
= THIS_MODULE
,
506 .write
= pgctrl_write
,
507 .release
= single_release
,
510 static int pktgen_if_show(struct seq_file
*seq
, void *v
)
512 struct pktgen_dev
*pkt_dev
= seq
->private;
515 __u64 now
= getCurUs();
518 "Params: count %llu min_pkt_size: %u max_pkt_size: %u\n",
519 (unsigned long long)pkt_dev
->count
, pkt_dev
->min_pkt_size
,
520 pkt_dev
->max_pkt_size
);
523 " frags: %d delay: %u clone_skb: %d ifname: %s\n",
525 1000 * pkt_dev
->delay_us
+ pkt_dev
->delay_ns
,
526 pkt_dev
->clone_skb
, pkt_dev
->odev
->name
);
528 seq_printf(seq
, " flows: %u flowlen: %u\n", pkt_dev
->cflows
,
532 " queue_map_min: %u queue_map_max: %u\n",
533 pkt_dev
->queue_map_min
,
534 pkt_dev
->queue_map_max
);
536 if (pkt_dev
->flags
& F_IPV6
) {
537 char b1
[128], b2
[128], b3
[128];
538 fmt_ip6(b1
, pkt_dev
->in6_saddr
.s6_addr
);
539 fmt_ip6(b2
, pkt_dev
->min_in6_saddr
.s6_addr
);
540 fmt_ip6(b3
, pkt_dev
->max_in6_saddr
.s6_addr
);
542 " saddr: %s min_saddr: %s max_saddr: %s\n", b1
,
545 fmt_ip6(b1
, pkt_dev
->in6_daddr
.s6_addr
);
546 fmt_ip6(b2
, pkt_dev
->min_in6_daddr
.s6_addr
);
547 fmt_ip6(b3
, pkt_dev
->max_in6_daddr
.s6_addr
);
549 " daddr: %s min_daddr: %s max_daddr: %s\n", b1
,
554 " dst_min: %s dst_max: %s\n src_min: %s src_max: %s\n",
555 pkt_dev
->dst_min
, pkt_dev
->dst_max
, pkt_dev
->src_min
,
558 seq_puts(seq
, " src_mac: ");
560 seq_printf(seq
, "%pM ",
561 is_zero_ether_addr(pkt_dev
->src_mac
) ?
562 pkt_dev
->odev
->dev_addr
: pkt_dev
->src_mac
);
564 seq_printf(seq
, "dst_mac: ");
565 seq_printf(seq
, "%pM\n", pkt_dev
->dst_mac
);
568 " udp_src_min: %d udp_src_max: %d udp_dst_min: %d udp_dst_max: %d\n",
569 pkt_dev
->udp_src_min
, pkt_dev
->udp_src_max
,
570 pkt_dev
->udp_dst_min
, pkt_dev
->udp_dst_max
);
573 " src_mac_count: %d dst_mac_count: %d\n",
574 pkt_dev
->src_mac_count
, pkt_dev
->dst_mac_count
);
576 if (pkt_dev
->nr_labels
) {
578 seq_printf(seq
, " mpls: ");
579 for (i
= 0; i
< pkt_dev
->nr_labels
; i
++)
580 seq_printf(seq
, "%08x%s", ntohl(pkt_dev
->labels
[i
]),
581 i
== pkt_dev
->nr_labels
-1 ? "\n" : ", ");
584 if (pkt_dev
->vlan_id
!= 0xffff) {
585 seq_printf(seq
, " vlan_id: %u vlan_p: %u vlan_cfi: %u\n",
586 pkt_dev
->vlan_id
, pkt_dev
->vlan_p
, pkt_dev
->vlan_cfi
);
589 if (pkt_dev
->svlan_id
!= 0xffff) {
590 seq_printf(seq
, " svlan_id: %u vlan_p: %u vlan_cfi: %u\n",
591 pkt_dev
->svlan_id
, pkt_dev
->svlan_p
, pkt_dev
->svlan_cfi
);
595 seq_printf(seq
, " tos: 0x%02x\n", pkt_dev
->tos
);
598 if (pkt_dev
->traffic_class
) {
599 seq_printf(seq
, " traffic_class: 0x%02x\n", pkt_dev
->traffic_class
);
602 seq_printf(seq
, " Flags: ");
604 if (pkt_dev
->flags
& F_IPV6
)
605 seq_printf(seq
, "IPV6 ");
607 if (pkt_dev
->flags
& F_IPSRC_RND
)
608 seq_printf(seq
, "IPSRC_RND ");
610 if (pkt_dev
->flags
& F_IPDST_RND
)
611 seq_printf(seq
, "IPDST_RND ");
613 if (pkt_dev
->flags
& F_TXSIZE_RND
)
614 seq_printf(seq
, "TXSIZE_RND ");
616 if (pkt_dev
->flags
& F_UDPSRC_RND
)
617 seq_printf(seq
, "UDPSRC_RND ");
619 if (pkt_dev
->flags
& F_UDPDST_RND
)
620 seq_printf(seq
, "UDPDST_RND ");
622 if (pkt_dev
->flags
& F_MPLS_RND
)
623 seq_printf(seq
, "MPLS_RND ");
625 if (pkt_dev
->flags
& F_QUEUE_MAP_RND
)
626 seq_printf(seq
, "QUEUE_MAP_RND ");
628 if (pkt_dev
->flags
& F_QUEUE_MAP_CPU
)
629 seq_printf(seq
, "QUEUE_MAP_CPU ");
631 if (pkt_dev
->cflows
) {
632 if (pkt_dev
->flags
& F_FLOW_SEQ
)
633 seq_printf(seq
, "FLOW_SEQ "); /*in sequence flows*/
635 seq_printf(seq
, "FLOW_RND ");
639 if (pkt_dev
->flags
& F_IPSEC_ON
)
640 seq_printf(seq
, "IPSEC ");
643 if (pkt_dev
->flags
& F_MACSRC_RND
)
644 seq_printf(seq
, "MACSRC_RND ");
646 if (pkt_dev
->flags
& F_MACDST_RND
)
647 seq_printf(seq
, "MACDST_RND ");
649 if (pkt_dev
->flags
& F_VID_RND
)
650 seq_printf(seq
, "VID_RND ");
652 if (pkt_dev
->flags
& F_SVID_RND
)
653 seq_printf(seq
, "SVID_RND ");
657 sa
= pkt_dev
->started_at
;
658 stopped
= pkt_dev
->stopped_at
;
659 if (pkt_dev
->running
)
660 stopped
= now
; /* not really stopped, more like last-running-at */
663 "Current:\n pkts-sofar: %llu errors: %llu\n started: %lluus stopped: %lluus idle: %lluus\n",
664 (unsigned long long)pkt_dev
->sofar
,
665 (unsigned long long)pkt_dev
->errors
, (unsigned long long)sa
,
666 (unsigned long long)stopped
,
667 (unsigned long long)pkt_dev
->idle_acc
);
670 " seq_num: %d cur_dst_mac_offset: %d cur_src_mac_offset: %d\n",
671 pkt_dev
->seq_num
, pkt_dev
->cur_dst_mac_offset
,
672 pkt_dev
->cur_src_mac_offset
);
674 if (pkt_dev
->flags
& F_IPV6
) {
675 char b1
[128], b2
[128];
676 fmt_ip6(b1
, pkt_dev
->cur_in6_daddr
.s6_addr
);
677 fmt_ip6(b2
, pkt_dev
->cur_in6_saddr
.s6_addr
);
678 seq_printf(seq
, " cur_saddr: %s cur_daddr: %s\n", b2
, b1
);
680 seq_printf(seq
, " cur_saddr: 0x%x cur_daddr: 0x%x\n",
681 pkt_dev
->cur_saddr
, pkt_dev
->cur_daddr
);
683 seq_printf(seq
, " cur_udp_dst: %d cur_udp_src: %d\n",
684 pkt_dev
->cur_udp_dst
, pkt_dev
->cur_udp_src
);
686 seq_printf(seq
, " cur_queue_map: %u\n", pkt_dev
->cur_queue_map
);
688 seq_printf(seq
, " flows: %u\n", pkt_dev
->nflows
);
690 if (pkt_dev
->result
[0])
691 seq_printf(seq
, "Result: %s\n", pkt_dev
->result
);
693 seq_printf(seq
, "Result: Idle\n");
699 static int hex32_arg(const char __user
*user_buffer
, unsigned long maxlen
, __u32
*num
)
704 for (; i
< maxlen
; i
++) {
707 if (get_user(c
, &user_buffer
[i
]))
709 if ((c
>= '0') && (c
<= '9'))
711 else if ((c
>= 'a') && (c
<= 'f'))
712 *num
|= c
- 'a' + 10;
713 else if ((c
>= 'A') && (c
<= 'F'))
714 *num
|= c
- 'A' + 10;
721 static int count_trail_chars(const char __user
* user_buffer
,
726 for (i
= 0; i
< maxlen
; i
++) {
728 if (get_user(c
, &user_buffer
[i
]))
746 static unsigned long num_arg(const char __user
* user_buffer
,
747 unsigned long maxlen
, unsigned long *num
)
752 for (; i
< maxlen
; i
++) {
754 if (get_user(c
, &user_buffer
[i
]))
756 if ((c
>= '0') && (c
<= '9')) {
765 static int strn_len(const char __user
* user_buffer
, unsigned int maxlen
)
769 for (; i
< maxlen
; i
++) {
771 if (get_user(c
, &user_buffer
[i
]))
789 static ssize_t
get_labels(const char __user
*buffer
, struct pktgen_dev
*pkt_dev
)
796 pkt_dev
->nr_labels
= 0;
799 len
= hex32_arg(&buffer
[i
], 8, &tmp
);
802 pkt_dev
->labels
[n
] = htonl(tmp
);
803 if (pkt_dev
->labels
[n
] & MPLS_STACK_BOTTOM
)
804 pkt_dev
->flags
|= F_MPLS_RND
;
806 if (get_user(c
, &buffer
[i
]))
810 if (n
>= MAX_MPLS_LABELS
)
814 pkt_dev
->nr_labels
= n
;
818 static ssize_t
pktgen_if_write(struct file
*file
,
819 const char __user
* user_buffer
, size_t count
,
822 struct seq_file
*seq
= (struct seq_file
*)file
->private_data
;
823 struct pktgen_dev
*pkt_dev
= seq
->private;
825 char name
[16], valstr
[32];
826 unsigned long value
= 0;
827 char *pg_result
= NULL
;
831 pg_result
= &(pkt_dev
->result
[0]);
834 printk(KERN_WARNING
"pktgen: wrong command format\n");
839 tmp
= count_trail_chars(&user_buffer
[i
], max
);
841 printk(KERN_WARNING
"pktgen: illegal format\n");
846 /* Read variable name */
848 len
= strn_len(&user_buffer
[i
], sizeof(name
) - 1);
852 memset(name
, 0, sizeof(name
));
853 if (copy_from_user(name
, &user_buffer
[i
], len
))
858 len
= count_trail_chars(&user_buffer
[i
], max
);
866 if (copy_from_user(tb
, user_buffer
, count
))
869 printk(KERN_DEBUG
"pktgen: %s,%lu buffer -:%s:-\n", name
,
870 (unsigned long)count
, tb
);
873 if (!strcmp(name
, "min_pkt_size")) {
874 len
= num_arg(&user_buffer
[i
], 10, &value
);
879 if (value
< 14 + 20 + 8)
881 if (value
!= pkt_dev
->min_pkt_size
) {
882 pkt_dev
->min_pkt_size
= value
;
883 pkt_dev
->cur_pkt_size
= value
;
885 sprintf(pg_result
, "OK: min_pkt_size=%u",
886 pkt_dev
->min_pkt_size
);
890 if (!strcmp(name
, "max_pkt_size")) {
891 len
= num_arg(&user_buffer
[i
], 10, &value
);
896 if (value
< 14 + 20 + 8)
898 if (value
!= pkt_dev
->max_pkt_size
) {
899 pkt_dev
->max_pkt_size
= value
;
900 pkt_dev
->cur_pkt_size
= value
;
902 sprintf(pg_result
, "OK: max_pkt_size=%u",
903 pkt_dev
->max_pkt_size
);
907 /* Shortcut for min = max */
909 if (!strcmp(name
, "pkt_size")) {
910 len
= num_arg(&user_buffer
[i
], 10, &value
);
915 if (value
< 14 + 20 + 8)
917 if (value
!= pkt_dev
->min_pkt_size
) {
918 pkt_dev
->min_pkt_size
= value
;
919 pkt_dev
->max_pkt_size
= value
;
920 pkt_dev
->cur_pkt_size
= value
;
922 sprintf(pg_result
, "OK: pkt_size=%u", pkt_dev
->min_pkt_size
);
926 if (!strcmp(name
, "debug")) {
927 len
= num_arg(&user_buffer
[i
], 10, &value
);
933 sprintf(pg_result
, "OK: debug=%u", debug
);
937 if (!strcmp(name
, "frags")) {
938 len
= num_arg(&user_buffer
[i
], 10, &value
);
943 pkt_dev
->nfrags
= value
;
944 sprintf(pg_result
, "OK: frags=%u", pkt_dev
->nfrags
);
947 if (!strcmp(name
, "delay")) {
948 len
= num_arg(&user_buffer
[i
], 10, &value
);
953 if (value
== 0x7FFFFFFF) {
954 pkt_dev
->delay_us
= 0x7FFFFFFF;
955 pkt_dev
->delay_ns
= 0;
957 pkt_dev
->delay_us
= value
/ 1000;
958 pkt_dev
->delay_ns
= value
% 1000;
960 sprintf(pg_result
, "OK: delay=%u",
961 1000 * pkt_dev
->delay_us
+ pkt_dev
->delay_ns
);
964 if (!strcmp(name
, "udp_src_min")) {
965 len
= num_arg(&user_buffer
[i
], 10, &value
);
970 if (value
!= pkt_dev
->udp_src_min
) {
971 pkt_dev
->udp_src_min
= value
;
972 pkt_dev
->cur_udp_src
= value
;
974 sprintf(pg_result
, "OK: udp_src_min=%u", pkt_dev
->udp_src_min
);
977 if (!strcmp(name
, "udp_dst_min")) {
978 len
= num_arg(&user_buffer
[i
], 10, &value
);
983 if (value
!= pkt_dev
->udp_dst_min
) {
984 pkt_dev
->udp_dst_min
= value
;
985 pkt_dev
->cur_udp_dst
= value
;
987 sprintf(pg_result
, "OK: udp_dst_min=%u", pkt_dev
->udp_dst_min
);
990 if (!strcmp(name
, "udp_src_max")) {
991 len
= num_arg(&user_buffer
[i
], 10, &value
);
996 if (value
!= pkt_dev
->udp_src_max
) {
997 pkt_dev
->udp_src_max
= value
;
998 pkt_dev
->cur_udp_src
= value
;
1000 sprintf(pg_result
, "OK: udp_src_max=%u", pkt_dev
->udp_src_max
);
1003 if (!strcmp(name
, "udp_dst_max")) {
1004 len
= num_arg(&user_buffer
[i
], 10, &value
);
1009 if (value
!= pkt_dev
->udp_dst_max
) {
1010 pkt_dev
->udp_dst_max
= value
;
1011 pkt_dev
->cur_udp_dst
= value
;
1013 sprintf(pg_result
, "OK: udp_dst_max=%u", pkt_dev
->udp_dst_max
);
1016 if (!strcmp(name
, "clone_skb")) {
1017 len
= num_arg(&user_buffer
[i
], 10, &value
);
1022 pkt_dev
->clone_skb
= value
;
1024 sprintf(pg_result
, "OK: clone_skb=%d", pkt_dev
->clone_skb
);
1027 if (!strcmp(name
, "count")) {
1028 len
= num_arg(&user_buffer
[i
], 10, &value
);
1033 pkt_dev
->count
= value
;
1034 sprintf(pg_result
, "OK: count=%llu",
1035 (unsigned long long)pkt_dev
->count
);
1038 if (!strcmp(name
, "src_mac_count")) {
1039 len
= num_arg(&user_buffer
[i
], 10, &value
);
1044 if (pkt_dev
->src_mac_count
!= value
) {
1045 pkt_dev
->src_mac_count
= value
;
1046 pkt_dev
->cur_src_mac_offset
= 0;
1048 sprintf(pg_result
, "OK: src_mac_count=%d",
1049 pkt_dev
->src_mac_count
);
1052 if (!strcmp(name
, "dst_mac_count")) {
1053 len
= num_arg(&user_buffer
[i
], 10, &value
);
1058 if (pkt_dev
->dst_mac_count
!= value
) {
1059 pkt_dev
->dst_mac_count
= value
;
1060 pkt_dev
->cur_dst_mac_offset
= 0;
1062 sprintf(pg_result
, "OK: dst_mac_count=%d",
1063 pkt_dev
->dst_mac_count
);
1066 if (!strcmp(name
, "flag")) {
1069 len
= strn_len(&user_buffer
[i
], sizeof(f
) - 1);
1073 if (copy_from_user(f
, &user_buffer
[i
], len
))
1076 if (strcmp(f
, "IPSRC_RND") == 0)
1077 pkt_dev
->flags
|= F_IPSRC_RND
;
1079 else if (strcmp(f
, "!IPSRC_RND") == 0)
1080 pkt_dev
->flags
&= ~F_IPSRC_RND
;
1082 else if (strcmp(f
, "TXSIZE_RND") == 0)
1083 pkt_dev
->flags
|= F_TXSIZE_RND
;
1085 else if (strcmp(f
, "!TXSIZE_RND") == 0)
1086 pkt_dev
->flags
&= ~F_TXSIZE_RND
;
1088 else if (strcmp(f
, "IPDST_RND") == 0)
1089 pkt_dev
->flags
|= F_IPDST_RND
;
1091 else if (strcmp(f
, "!IPDST_RND") == 0)
1092 pkt_dev
->flags
&= ~F_IPDST_RND
;
1094 else if (strcmp(f
, "UDPSRC_RND") == 0)
1095 pkt_dev
->flags
|= F_UDPSRC_RND
;
1097 else if (strcmp(f
, "!UDPSRC_RND") == 0)
1098 pkt_dev
->flags
&= ~F_UDPSRC_RND
;
1100 else if (strcmp(f
, "UDPDST_RND") == 0)
1101 pkt_dev
->flags
|= F_UDPDST_RND
;
1103 else if (strcmp(f
, "!UDPDST_RND") == 0)
1104 pkt_dev
->flags
&= ~F_UDPDST_RND
;
1106 else if (strcmp(f
, "MACSRC_RND") == 0)
1107 pkt_dev
->flags
|= F_MACSRC_RND
;
1109 else if (strcmp(f
, "!MACSRC_RND") == 0)
1110 pkt_dev
->flags
&= ~F_MACSRC_RND
;
1112 else if (strcmp(f
, "MACDST_RND") == 0)
1113 pkt_dev
->flags
|= F_MACDST_RND
;
1115 else if (strcmp(f
, "!MACDST_RND") == 0)
1116 pkt_dev
->flags
&= ~F_MACDST_RND
;
1118 else if (strcmp(f
, "MPLS_RND") == 0)
1119 pkt_dev
->flags
|= F_MPLS_RND
;
1121 else if (strcmp(f
, "!MPLS_RND") == 0)
1122 pkt_dev
->flags
&= ~F_MPLS_RND
;
1124 else if (strcmp(f
, "VID_RND") == 0)
1125 pkt_dev
->flags
|= F_VID_RND
;
1127 else if (strcmp(f
, "!VID_RND") == 0)
1128 pkt_dev
->flags
&= ~F_VID_RND
;
1130 else if (strcmp(f
, "SVID_RND") == 0)
1131 pkt_dev
->flags
|= F_SVID_RND
;
1133 else if (strcmp(f
, "!SVID_RND") == 0)
1134 pkt_dev
->flags
&= ~F_SVID_RND
;
1136 else if (strcmp(f
, "FLOW_SEQ") == 0)
1137 pkt_dev
->flags
|= F_FLOW_SEQ
;
1139 else if (strcmp(f
, "QUEUE_MAP_RND") == 0)
1140 pkt_dev
->flags
|= F_QUEUE_MAP_RND
;
1142 else if (strcmp(f
, "!QUEUE_MAP_RND") == 0)
1143 pkt_dev
->flags
&= ~F_QUEUE_MAP_RND
;
1145 else if (strcmp(f
, "QUEUE_MAP_CPU") == 0)
1146 pkt_dev
->flags
|= F_QUEUE_MAP_CPU
;
1148 else if (strcmp(f
, "!QUEUE_MAP_CPU") == 0)
1149 pkt_dev
->flags
&= ~F_QUEUE_MAP_CPU
;
1151 else if (strcmp(f
, "IPSEC") == 0)
1152 pkt_dev
->flags
|= F_IPSEC_ON
;
1155 else if (strcmp(f
, "!IPV6") == 0)
1156 pkt_dev
->flags
&= ~F_IPV6
;
1160 "Flag -:%s:- unknown\nAvailable flags, (prepend ! to un-set flag):\n%s",
1162 "IPSRC_RND, IPDST_RND, UDPSRC_RND, UDPDST_RND, "
1163 "MACSRC_RND, MACDST_RND, TXSIZE_RND, IPV6, MPLS_RND, VID_RND, SVID_RND, FLOW_SEQ, IPSEC\n");
1166 sprintf(pg_result
, "OK: flags=0x%x", pkt_dev
->flags
);
1169 if (!strcmp(name
, "dst_min") || !strcmp(name
, "dst")) {
1170 len
= strn_len(&user_buffer
[i
], sizeof(pkt_dev
->dst_min
) - 1);
1175 if (copy_from_user(buf
, &user_buffer
[i
], len
))
1178 if (strcmp(buf
, pkt_dev
->dst_min
) != 0) {
1179 memset(pkt_dev
->dst_min
, 0, sizeof(pkt_dev
->dst_min
));
1180 strncpy(pkt_dev
->dst_min
, buf
, len
);
1181 pkt_dev
->daddr_min
= in_aton(pkt_dev
->dst_min
);
1182 pkt_dev
->cur_daddr
= pkt_dev
->daddr_min
;
1185 printk(KERN_DEBUG
"pktgen: dst_min set to: %s\n",
1188 sprintf(pg_result
, "OK: dst_min=%s", pkt_dev
->dst_min
);
1191 if (!strcmp(name
, "dst_max")) {
1192 len
= strn_len(&user_buffer
[i
], sizeof(pkt_dev
->dst_max
) - 1);
1197 if (copy_from_user(buf
, &user_buffer
[i
], len
))
1201 if (strcmp(buf
, pkt_dev
->dst_max
) != 0) {
1202 memset(pkt_dev
->dst_max
, 0, sizeof(pkt_dev
->dst_max
));
1203 strncpy(pkt_dev
->dst_max
, buf
, len
);
1204 pkt_dev
->daddr_max
= in_aton(pkt_dev
->dst_max
);
1205 pkt_dev
->cur_daddr
= pkt_dev
->daddr_max
;
1208 printk(KERN_DEBUG
"pktgen: dst_max set to: %s\n",
1211 sprintf(pg_result
, "OK: dst_max=%s", pkt_dev
->dst_max
);
1214 if (!strcmp(name
, "dst6")) {
1215 len
= strn_len(&user_buffer
[i
], sizeof(buf
) - 1);
1219 pkt_dev
->flags
|= F_IPV6
;
1221 if (copy_from_user(buf
, &user_buffer
[i
], len
))
1225 scan_ip6(buf
, pkt_dev
->in6_daddr
.s6_addr
);
1226 fmt_ip6(buf
, pkt_dev
->in6_daddr
.s6_addr
);
1228 ipv6_addr_copy(&pkt_dev
->cur_in6_daddr
, &pkt_dev
->in6_daddr
);
1231 printk(KERN_DEBUG
"pktgen: dst6 set to: %s\n", buf
);
1234 sprintf(pg_result
, "OK: dst6=%s", buf
);
1237 if (!strcmp(name
, "dst6_min")) {
1238 len
= strn_len(&user_buffer
[i
], sizeof(buf
) - 1);
1242 pkt_dev
->flags
|= F_IPV6
;
1244 if (copy_from_user(buf
, &user_buffer
[i
], len
))
1248 scan_ip6(buf
, pkt_dev
->min_in6_daddr
.s6_addr
);
1249 fmt_ip6(buf
, pkt_dev
->min_in6_daddr
.s6_addr
);
1251 ipv6_addr_copy(&pkt_dev
->cur_in6_daddr
,
1252 &pkt_dev
->min_in6_daddr
);
1254 printk(KERN_DEBUG
"pktgen: dst6_min set to: %s\n", buf
);
1257 sprintf(pg_result
, "OK: dst6_min=%s", buf
);
1260 if (!strcmp(name
, "dst6_max")) {
1261 len
= strn_len(&user_buffer
[i
], sizeof(buf
) - 1);
1265 pkt_dev
->flags
|= F_IPV6
;
1267 if (copy_from_user(buf
, &user_buffer
[i
], len
))
1271 scan_ip6(buf
, pkt_dev
->max_in6_daddr
.s6_addr
);
1272 fmt_ip6(buf
, pkt_dev
->max_in6_daddr
.s6_addr
);
1275 printk(KERN_DEBUG
"pktgen: dst6_max set to: %s\n", buf
);
1278 sprintf(pg_result
, "OK: dst6_max=%s", buf
);
1281 if (!strcmp(name
, "src6")) {
1282 len
= strn_len(&user_buffer
[i
], sizeof(buf
) - 1);
1286 pkt_dev
->flags
|= F_IPV6
;
1288 if (copy_from_user(buf
, &user_buffer
[i
], len
))
1292 scan_ip6(buf
, pkt_dev
->in6_saddr
.s6_addr
);
1293 fmt_ip6(buf
, pkt_dev
->in6_saddr
.s6_addr
);
1295 ipv6_addr_copy(&pkt_dev
->cur_in6_saddr
, &pkt_dev
->in6_saddr
);
1298 printk(KERN_DEBUG
"pktgen: src6 set to: %s\n", buf
);
1301 sprintf(pg_result
, "OK: src6=%s", buf
);
1304 if (!strcmp(name
, "src_min")) {
1305 len
= strn_len(&user_buffer
[i
], sizeof(pkt_dev
->src_min
) - 1);
1309 if (copy_from_user(buf
, &user_buffer
[i
], len
))
1312 if (strcmp(buf
, pkt_dev
->src_min
) != 0) {
1313 memset(pkt_dev
->src_min
, 0, sizeof(pkt_dev
->src_min
));
1314 strncpy(pkt_dev
->src_min
, buf
, len
);
1315 pkt_dev
->saddr_min
= in_aton(pkt_dev
->src_min
);
1316 pkt_dev
->cur_saddr
= pkt_dev
->saddr_min
;
1319 printk(KERN_DEBUG
"pktgen: src_min set to: %s\n",
1322 sprintf(pg_result
, "OK: src_min=%s", pkt_dev
->src_min
);
1325 if (!strcmp(name
, "src_max")) {
1326 len
= strn_len(&user_buffer
[i
], sizeof(pkt_dev
->src_max
) - 1);
1330 if (copy_from_user(buf
, &user_buffer
[i
], len
))
1333 if (strcmp(buf
, pkt_dev
->src_max
) != 0) {
1334 memset(pkt_dev
->src_max
, 0, sizeof(pkt_dev
->src_max
));
1335 strncpy(pkt_dev
->src_max
, buf
, len
);
1336 pkt_dev
->saddr_max
= in_aton(pkt_dev
->src_max
);
1337 pkt_dev
->cur_saddr
= pkt_dev
->saddr_max
;
1340 printk(KERN_DEBUG
"pktgen: src_max set to: %s\n",
1343 sprintf(pg_result
, "OK: src_max=%s", pkt_dev
->src_max
);
1346 if (!strcmp(name
, "dst_mac")) {
1348 unsigned char old_dmac
[ETH_ALEN
];
1349 unsigned char *m
= pkt_dev
->dst_mac
;
1350 memcpy(old_dmac
, pkt_dev
->dst_mac
, ETH_ALEN
);
1352 len
= strn_len(&user_buffer
[i
], sizeof(valstr
) - 1);
1356 memset(valstr
, 0, sizeof(valstr
));
1357 if (copy_from_user(valstr
, &user_buffer
[i
], len
))
1361 for (*m
= 0; *v
&& m
< pkt_dev
->dst_mac
+ 6; v
++) {
1362 if (*v
>= '0' && *v
<= '9') {
1366 if (*v
>= 'A' && *v
<= 'F') {
1368 *m
+= *v
- 'A' + 10;
1370 if (*v
>= 'a' && *v
<= 'f') {
1372 *m
+= *v
- 'a' + 10;
1380 /* Set up Dest MAC */
1381 if (compare_ether_addr(old_dmac
, pkt_dev
->dst_mac
))
1382 memcpy(&(pkt_dev
->hh
[0]), pkt_dev
->dst_mac
, ETH_ALEN
);
1384 sprintf(pg_result
, "OK: dstmac");
1387 if (!strcmp(name
, "src_mac")) {
1389 unsigned char old_smac
[ETH_ALEN
];
1390 unsigned char *m
= pkt_dev
->src_mac
;
1392 memcpy(old_smac
, pkt_dev
->src_mac
, ETH_ALEN
);
1394 len
= strn_len(&user_buffer
[i
], sizeof(valstr
) - 1);
1398 memset(valstr
, 0, sizeof(valstr
));
1399 if (copy_from_user(valstr
, &user_buffer
[i
], len
))
1403 for (*m
= 0; *v
&& m
< pkt_dev
->src_mac
+ 6; v
++) {
1404 if (*v
>= '0' && *v
<= '9') {
1408 if (*v
>= 'A' && *v
<= 'F') {
1410 *m
+= *v
- 'A' + 10;
1412 if (*v
>= 'a' && *v
<= 'f') {
1414 *m
+= *v
- 'a' + 10;
1422 /* Set up Src MAC */
1423 if (compare_ether_addr(old_smac
, pkt_dev
->src_mac
))
1424 memcpy(&(pkt_dev
->hh
[6]), pkt_dev
->src_mac
, ETH_ALEN
);
1426 sprintf(pg_result
, "OK: srcmac");
1430 if (!strcmp(name
, "clear_counters")) {
1431 pktgen_clear_counters(pkt_dev
);
1432 sprintf(pg_result
, "OK: Clearing counters.\n");
1436 if (!strcmp(name
, "flows")) {
1437 len
= num_arg(&user_buffer
[i
], 10, &value
);
1442 if (value
> MAX_CFLOWS
)
1445 pkt_dev
->cflows
= value
;
1446 sprintf(pg_result
, "OK: flows=%u", pkt_dev
->cflows
);
1450 if (!strcmp(name
, "flowlen")) {
1451 len
= num_arg(&user_buffer
[i
], 10, &value
);
1456 pkt_dev
->lflow
= value
;
1457 sprintf(pg_result
, "OK: flowlen=%u", pkt_dev
->lflow
);
1461 if (!strcmp(name
, "queue_map_min")) {
1462 len
= num_arg(&user_buffer
[i
], 5, &value
);
1467 pkt_dev
->queue_map_min
= value
;
1468 sprintf(pg_result
, "OK: queue_map_min=%u", pkt_dev
->queue_map_min
);
1472 if (!strcmp(name
, "queue_map_max")) {
1473 len
= num_arg(&user_buffer
[i
], 5, &value
);
1478 pkt_dev
->queue_map_max
= value
;
1479 sprintf(pg_result
, "OK: queue_map_max=%u", pkt_dev
->queue_map_max
);
1483 if (!strcmp(name
, "mpls")) {
1486 len
= get_labels(&user_buffer
[i
], pkt_dev
);
1490 cnt
= sprintf(pg_result
, "OK: mpls=");
1491 for (n
= 0; n
< pkt_dev
->nr_labels
; n
++)
1492 cnt
+= sprintf(pg_result
+ cnt
,
1493 "%08x%s", ntohl(pkt_dev
->labels
[n
]),
1494 n
== pkt_dev
->nr_labels
-1 ? "" : ",");
1496 if (pkt_dev
->nr_labels
&& pkt_dev
->vlan_id
!= 0xffff) {
1497 pkt_dev
->vlan_id
= 0xffff; /* turn off VLAN/SVLAN */
1498 pkt_dev
->svlan_id
= 0xffff;
1501 printk(KERN_DEBUG
"pktgen: VLAN/SVLAN auto turned off\n");
1506 if (!strcmp(name
, "vlan_id")) {
1507 len
= num_arg(&user_buffer
[i
], 4, &value
);
1512 if (value
<= 4095) {
1513 pkt_dev
->vlan_id
= value
; /* turn on VLAN */
1516 printk(KERN_DEBUG
"pktgen: VLAN turned on\n");
1518 if (debug
&& pkt_dev
->nr_labels
)
1519 printk(KERN_DEBUG
"pktgen: MPLS auto turned off\n");
1521 pkt_dev
->nr_labels
= 0; /* turn off MPLS */
1522 sprintf(pg_result
, "OK: vlan_id=%u", pkt_dev
->vlan_id
);
1524 pkt_dev
->vlan_id
= 0xffff; /* turn off VLAN/SVLAN */
1525 pkt_dev
->svlan_id
= 0xffff;
1528 printk(KERN_DEBUG
"pktgen: VLAN/SVLAN turned off\n");
1533 if (!strcmp(name
, "vlan_p")) {
1534 len
= num_arg(&user_buffer
[i
], 1, &value
);
1539 if ((value
<= 7) && (pkt_dev
->vlan_id
!= 0xffff)) {
1540 pkt_dev
->vlan_p
= value
;
1541 sprintf(pg_result
, "OK: vlan_p=%u", pkt_dev
->vlan_p
);
1543 sprintf(pg_result
, "ERROR: vlan_p must be 0-7");
1548 if (!strcmp(name
, "vlan_cfi")) {
1549 len
= num_arg(&user_buffer
[i
], 1, &value
);
1554 if ((value
<= 1) && (pkt_dev
->vlan_id
!= 0xffff)) {
1555 pkt_dev
->vlan_cfi
= value
;
1556 sprintf(pg_result
, "OK: vlan_cfi=%u", pkt_dev
->vlan_cfi
);
1558 sprintf(pg_result
, "ERROR: vlan_cfi must be 0-1");
1563 if (!strcmp(name
, "svlan_id")) {
1564 len
= num_arg(&user_buffer
[i
], 4, &value
);
1569 if ((value
<= 4095) && ((pkt_dev
->vlan_id
!= 0xffff))) {
1570 pkt_dev
->svlan_id
= value
; /* turn on SVLAN */
1573 printk(KERN_DEBUG
"pktgen: SVLAN turned on\n");
1575 if (debug
&& pkt_dev
->nr_labels
)
1576 printk(KERN_DEBUG
"pktgen: MPLS auto turned off\n");
1578 pkt_dev
->nr_labels
= 0; /* turn off MPLS */
1579 sprintf(pg_result
, "OK: svlan_id=%u", pkt_dev
->svlan_id
);
1581 pkt_dev
->vlan_id
= 0xffff; /* turn off VLAN/SVLAN */
1582 pkt_dev
->svlan_id
= 0xffff;
1585 printk(KERN_DEBUG
"pktgen: VLAN/SVLAN turned off\n");
1590 if (!strcmp(name
, "svlan_p")) {
1591 len
= num_arg(&user_buffer
[i
], 1, &value
);
1596 if ((value
<= 7) && (pkt_dev
->svlan_id
!= 0xffff)) {
1597 pkt_dev
->svlan_p
= value
;
1598 sprintf(pg_result
, "OK: svlan_p=%u", pkt_dev
->svlan_p
);
1600 sprintf(pg_result
, "ERROR: svlan_p must be 0-7");
1605 if (!strcmp(name
, "svlan_cfi")) {
1606 len
= num_arg(&user_buffer
[i
], 1, &value
);
1611 if ((value
<= 1) && (pkt_dev
->svlan_id
!= 0xffff)) {
1612 pkt_dev
->svlan_cfi
= value
;
1613 sprintf(pg_result
, "OK: svlan_cfi=%u", pkt_dev
->svlan_cfi
);
1615 sprintf(pg_result
, "ERROR: svlan_cfi must be 0-1");
1620 if (!strcmp(name
, "tos")) {
1621 __u32 tmp_value
= 0;
1622 len
= hex32_arg(&user_buffer
[i
], 2, &tmp_value
);
1628 pkt_dev
->tos
= tmp_value
;
1629 sprintf(pg_result
, "OK: tos=0x%02x", pkt_dev
->tos
);
1631 sprintf(pg_result
, "ERROR: tos must be 00-ff");
1636 if (!strcmp(name
, "traffic_class")) {
1637 __u32 tmp_value
= 0;
1638 len
= hex32_arg(&user_buffer
[i
], 2, &tmp_value
);
1644 pkt_dev
->traffic_class
= tmp_value
;
1645 sprintf(pg_result
, "OK: traffic_class=0x%02x", pkt_dev
->traffic_class
);
1647 sprintf(pg_result
, "ERROR: traffic_class must be 00-ff");
1652 sprintf(pkt_dev
->result
, "No such parameter \"%s\"", name
);
1656 static int pktgen_if_open(struct inode
*inode
, struct file
*file
)
1658 return single_open(file
, pktgen_if_show
, PDE(inode
)->data
);
1661 static const struct file_operations pktgen_if_fops
= {
1662 .owner
= THIS_MODULE
,
1663 .open
= pktgen_if_open
,
1665 .llseek
= seq_lseek
,
1666 .write
= pktgen_if_write
,
1667 .release
= single_release
,
1670 static int pktgen_thread_show(struct seq_file
*seq
, void *v
)
1672 struct pktgen_thread
*t
= seq
->private;
1673 struct pktgen_dev
*pkt_dev
;
1677 seq_printf(seq
, "Running: ");
1680 list_for_each_entry(pkt_dev
, &t
->if_list
, list
)
1681 if (pkt_dev
->running
)
1682 seq_printf(seq
, "%s ", pkt_dev
->odev
->name
);
1684 seq_printf(seq
, "\nStopped: ");
1686 list_for_each_entry(pkt_dev
, &t
->if_list
, list
)
1687 if (!pkt_dev
->running
)
1688 seq_printf(seq
, "%s ", pkt_dev
->odev
->name
);
1691 seq_printf(seq
, "\nResult: %s\n", t
->result
);
1693 seq_printf(seq
, "\nResult: NA\n");
1700 static ssize_t
pktgen_thread_write(struct file
*file
,
1701 const char __user
* user_buffer
,
1702 size_t count
, loff_t
* offset
)
1704 struct seq_file
*seq
= (struct seq_file
*)file
->private_data
;
1705 struct pktgen_thread
*t
= seq
->private;
1706 int i
= 0, max
, len
, ret
;
1711 // sprintf(pg_result, "Wrong command format");
1716 len
= count_trail_chars(&user_buffer
[i
], max
);
1722 /* Read variable name */
1724 len
= strn_len(&user_buffer
[i
], sizeof(name
) - 1);
1728 memset(name
, 0, sizeof(name
));
1729 if (copy_from_user(name
, &user_buffer
[i
], len
))
1734 len
= count_trail_chars(&user_buffer
[i
], max
);
1741 printk(KERN_DEBUG
"pktgen: t=%s, count=%lu\n",
1742 name
, (unsigned long)count
);
1745 printk(KERN_ERR
"pktgen: ERROR: No thread\n");
1750 pg_result
= &(t
->result
[0]);
1752 if (!strcmp(name
, "add_device")) {
1755 len
= strn_len(&user_buffer
[i
], sizeof(f
) - 1);
1760 if (copy_from_user(f
, &user_buffer
[i
], len
))
1763 mutex_lock(&pktgen_thread_lock
);
1764 pktgen_add_device(t
, f
);
1765 mutex_unlock(&pktgen_thread_lock
);
1767 sprintf(pg_result
, "OK: add_device=%s", f
);
1771 if (!strcmp(name
, "rem_device_all")) {
1772 mutex_lock(&pktgen_thread_lock
);
1773 t
->control
|= T_REMDEVALL
;
1774 mutex_unlock(&pktgen_thread_lock
);
1775 schedule_timeout_interruptible(msecs_to_jiffies(125)); /* Propagate thread->control */
1777 sprintf(pg_result
, "OK: rem_device_all");
1781 if (!strcmp(name
, "max_before_softirq")) {
1782 sprintf(pg_result
, "OK: Note! max_before_softirq is obsoleted -- Do not use");
1792 static int pktgen_thread_open(struct inode
*inode
, struct file
*file
)
1794 return single_open(file
, pktgen_thread_show
, PDE(inode
)->data
);
1797 static const struct file_operations pktgen_thread_fops
= {
1798 .owner
= THIS_MODULE
,
1799 .open
= pktgen_thread_open
,
1801 .llseek
= seq_lseek
,
1802 .write
= pktgen_thread_write
,
1803 .release
= single_release
,
1806 /* Think find or remove for NN */
1807 static struct pktgen_dev
*__pktgen_NN_threads(const char *ifname
, int remove
)
1809 struct pktgen_thread
*t
;
1810 struct pktgen_dev
*pkt_dev
= NULL
;
1812 list_for_each_entry(t
, &pktgen_threads
, th_list
) {
1813 pkt_dev
= pktgen_find_dev(t
, ifname
);
1817 pkt_dev
->removal_mark
= 1;
1818 t
->control
|= T_REMDEV
;
1828 * mark a device for removal
1830 static void pktgen_mark_device(const char *ifname
)
1832 struct pktgen_dev
*pkt_dev
= NULL
;
1833 const int max_tries
= 10, msec_per_try
= 125;
1836 mutex_lock(&pktgen_thread_lock
);
1837 pr_debug("pktgen: pktgen_mark_device marking %s for removal\n", ifname
);
1841 pkt_dev
= __pktgen_NN_threads(ifname
, REMOVE
);
1842 if (pkt_dev
== NULL
)
1843 break; /* success */
1845 mutex_unlock(&pktgen_thread_lock
);
1846 pr_debug("pktgen: pktgen_mark_device waiting for %s "
1847 "to disappear....\n", ifname
);
1848 schedule_timeout_interruptible(msecs_to_jiffies(msec_per_try
));
1849 mutex_lock(&pktgen_thread_lock
);
1851 if (++i
>= max_tries
) {
1852 printk(KERN_ERR
"pktgen_mark_device: timed out after "
1853 "waiting %d msec for device %s to be removed\n",
1854 msec_per_try
* i
, ifname
);
1860 mutex_unlock(&pktgen_thread_lock
);
1863 static void pktgen_change_name(struct net_device
*dev
)
1865 struct pktgen_thread
*t
;
1867 list_for_each_entry(t
, &pktgen_threads
, th_list
) {
1868 struct pktgen_dev
*pkt_dev
;
1870 list_for_each_entry(pkt_dev
, &t
->if_list
, list
) {
1871 if (pkt_dev
->odev
!= dev
)
1874 remove_proc_entry(pkt_dev
->entry
->name
, pg_proc_dir
);
1876 pkt_dev
->entry
= create_proc_entry(dev
->name
, 0600,
1878 if (!pkt_dev
->entry
)
1879 printk(KERN_ERR
"pktgen: can't move proc "
1880 " entry for '%s'\n", dev
->name
);
1886 static int pktgen_device_event(struct notifier_block
*unused
,
1887 unsigned long event
, void *ptr
)
1889 struct net_device
*dev
= ptr
;
1891 if (!net_eq(dev_net(dev
), &init_net
))
1894 /* It is OK that we do not hold the group lock right now,
1895 * as we run under the RTNL lock.
1899 case NETDEV_CHANGENAME
:
1900 pktgen_change_name(dev
);
1903 case NETDEV_UNREGISTER
:
1904 pktgen_mark_device(dev
->name
);
1911 static struct net_device
*pktgen_dev_get_by_name(struct pktgen_dev
*pkt_dev
, const char *ifname
)
1916 for(i
=0; ifname
[i
] != '@'; i
++) {
1924 return dev_get_by_name(&init_net
, b
);
1928 /* Associate pktgen_dev with a device. */
1930 static int pktgen_setup_dev(struct pktgen_dev
*pkt_dev
, const char *ifname
)
1932 struct net_device
*odev
;
1935 /* Clean old setups */
1936 if (pkt_dev
->odev
) {
1937 dev_put(pkt_dev
->odev
);
1938 pkt_dev
->odev
= NULL
;
1941 odev
= pktgen_dev_get_by_name(pkt_dev
, ifname
);
1943 printk(KERN_ERR
"pktgen: no such netdevice: \"%s\"\n", ifname
);
1947 if (odev
->type
!= ARPHRD_ETHER
) {
1948 printk(KERN_ERR
"pktgen: not an ethernet device: \"%s\"\n", ifname
);
1950 } else if (!netif_running(odev
)) {
1951 printk(KERN_ERR
"pktgen: device is down: \"%s\"\n", ifname
);
1954 pkt_dev
->odev
= odev
;
1962 /* Read pkt_dev from the interface and set up internal pktgen_dev
1963 * structure to have the right information to create/send packets
1965 static void pktgen_setup_inject(struct pktgen_dev
*pkt_dev
)
1969 if (!pkt_dev
->odev
) {
1970 printk(KERN_ERR
"pktgen: ERROR: pkt_dev->odev == NULL in "
1972 sprintf(pkt_dev
->result
,
1973 "ERROR: pkt_dev->odev == NULL in setup_inject.\n");
1977 /* make sure that we don't pick a non-existing transmit queue */
1978 ntxq
= pkt_dev
->odev
->real_num_tx_queues
;
1980 if (ntxq
<= pkt_dev
->queue_map_min
) {
1981 printk(KERN_WARNING
"pktgen: WARNING: Requested "
1982 "queue_map_min (zero-based) (%d) exceeds valid range "
1983 "[0 - %d] for (%d) queues on %s, resetting\n",
1984 pkt_dev
->queue_map_min
, (ntxq
?: 1)- 1, ntxq
,
1985 pkt_dev
->odev
->name
);
1986 pkt_dev
->queue_map_min
= ntxq
- 1;
1988 if (pkt_dev
->queue_map_max
>= ntxq
) {
1989 printk(KERN_WARNING
"pktgen: WARNING: Requested "
1990 "queue_map_max (zero-based) (%d) exceeds valid range "
1991 "[0 - %d] for (%d) queues on %s, resetting\n",
1992 pkt_dev
->queue_map_max
, (ntxq
?: 1)- 1, ntxq
,
1993 pkt_dev
->odev
->name
);
1994 pkt_dev
->queue_map_max
= ntxq
- 1;
1997 /* Default to the interface's mac if not explicitly set. */
1999 if (is_zero_ether_addr(pkt_dev
->src_mac
))
2000 memcpy(&(pkt_dev
->hh
[6]), pkt_dev
->odev
->dev_addr
, ETH_ALEN
);
2002 /* Set up Dest MAC */
2003 memcpy(&(pkt_dev
->hh
[0]), pkt_dev
->dst_mac
, ETH_ALEN
);
2005 /* Set up pkt size */
2006 pkt_dev
->cur_pkt_size
= pkt_dev
->min_pkt_size
;
2008 if (pkt_dev
->flags
& F_IPV6
) {
2010 * Skip this automatic address setting until locks or functions
2015 int i
, set
= 0, err
= 1;
2016 struct inet6_dev
*idev
;
2018 for (i
= 0; i
< IN6_ADDR_HSIZE
; i
++)
2019 if (pkt_dev
->cur_in6_saddr
.s6_addr
[i
]) {
2027 * Use linklevel address if unconfigured.
2029 * use ipv6_get_lladdr if/when it's get exported
2033 if ((idev
= __in6_dev_get(pkt_dev
->odev
)) != NULL
) {
2034 struct inet6_ifaddr
*ifp
;
2036 read_lock_bh(&idev
->lock
);
2037 for (ifp
= idev
->addr_list
; ifp
;
2038 ifp
= ifp
->if_next
) {
2039 if (ifp
->scope
== IFA_LINK
2041 flags
& IFA_F_TENTATIVE
)) {
2042 ipv6_addr_copy(&pkt_dev
->
2049 read_unlock_bh(&idev
->lock
);
2053 printk(KERN_ERR
"pktgen: ERROR: IPv6 link "
2054 "address not availble.\n");
2058 pkt_dev
->saddr_min
= 0;
2059 pkt_dev
->saddr_max
= 0;
2060 if (strlen(pkt_dev
->src_min
) == 0) {
2062 struct in_device
*in_dev
;
2065 in_dev
= __in_dev_get_rcu(pkt_dev
->odev
);
2067 if (in_dev
->ifa_list
) {
2068 pkt_dev
->saddr_min
=
2069 in_dev
->ifa_list
->ifa_address
;
2070 pkt_dev
->saddr_max
= pkt_dev
->saddr_min
;
2075 pkt_dev
->saddr_min
= in_aton(pkt_dev
->src_min
);
2076 pkt_dev
->saddr_max
= in_aton(pkt_dev
->src_max
);
2079 pkt_dev
->daddr_min
= in_aton(pkt_dev
->dst_min
);
2080 pkt_dev
->daddr_max
= in_aton(pkt_dev
->dst_max
);
2082 /* Initialize current values. */
2083 pkt_dev
->cur_dst_mac_offset
= 0;
2084 pkt_dev
->cur_src_mac_offset
= 0;
2085 pkt_dev
->cur_saddr
= pkt_dev
->saddr_min
;
2086 pkt_dev
->cur_daddr
= pkt_dev
->daddr_min
;
2087 pkt_dev
->cur_udp_dst
= pkt_dev
->udp_dst_min
;
2088 pkt_dev
->cur_udp_src
= pkt_dev
->udp_src_min
;
2089 pkt_dev
->nflows
= 0;
2092 static void spin(struct pktgen_dev
*pkt_dev
, __u64 spin_until_us
)
2097 start
= now
= getCurUs();
2098 while (now
< spin_until_us
) {
2099 /* TODO: optimize sleeping behavior */
2100 if (spin_until_us
- now
> jiffies_to_usecs(1) + 1)
2101 schedule_timeout_interruptible(1);
2102 else if (spin_until_us
- now
> 100) {
2103 if (!pkt_dev
->running
)
2112 pkt_dev
->idle_acc
+= now
- start
;
2115 static inline void set_pkt_overhead(struct pktgen_dev
*pkt_dev
)
2117 pkt_dev
->pkt_overhead
= 0;
2118 pkt_dev
->pkt_overhead
+= pkt_dev
->nr_labels
*sizeof(u32
);
2119 pkt_dev
->pkt_overhead
+= VLAN_TAG_SIZE(pkt_dev
);
2120 pkt_dev
->pkt_overhead
+= SVLAN_TAG_SIZE(pkt_dev
);
2123 static inline int f_seen(struct pktgen_dev
*pkt_dev
, int flow
)
2126 if (pkt_dev
->flows
[flow
].flags
& F_INIT
)
2132 static inline int f_pick(struct pktgen_dev
*pkt_dev
)
2134 int flow
= pkt_dev
->curfl
;
2136 if (pkt_dev
->flags
& F_FLOW_SEQ
) {
2137 if (pkt_dev
->flows
[flow
].count
>= pkt_dev
->lflow
) {
2139 pkt_dev
->flows
[flow
].count
= 0;
2140 pkt_dev
->flows
[flow
].flags
= 0;
2141 pkt_dev
->curfl
+= 1;
2142 if (pkt_dev
->curfl
>= pkt_dev
->cflows
)
2143 pkt_dev
->curfl
= 0; /*reset */
2146 flow
= random32() % pkt_dev
->cflows
;
2147 pkt_dev
->curfl
= flow
;
2149 if (pkt_dev
->flows
[flow
].count
> pkt_dev
->lflow
) {
2150 pkt_dev
->flows
[flow
].count
= 0;
2151 pkt_dev
->flows
[flow
].flags
= 0;
2155 return pkt_dev
->curfl
;
2160 /* If there was already an IPSEC SA, we keep it as is, else
2161 * we go look for it ...
2163 static void get_ipsec_sa(struct pktgen_dev
*pkt_dev
, int flow
)
2165 struct xfrm_state
*x
= pkt_dev
->flows
[flow
].x
;
2167 /*slow path: we dont already have xfrm_state*/
2168 x
= xfrm_stateonly_find((xfrm_address_t
*)&pkt_dev
->cur_daddr
,
2169 (xfrm_address_t
*)&pkt_dev
->cur_saddr
,
2172 pkt_dev
->ipsproto
, 0);
2174 pkt_dev
->flows
[flow
].x
= x
;
2175 set_pkt_overhead(pkt_dev
);
2176 pkt_dev
->pkt_overhead
+=x
->props
.header_len
;
2182 static void set_cur_queue_map(struct pktgen_dev
*pkt_dev
)
2185 if (pkt_dev
->flags
& F_QUEUE_MAP_CPU
)
2186 pkt_dev
->cur_queue_map
= smp_processor_id();
2188 else if (pkt_dev
->queue_map_min
< pkt_dev
->queue_map_max
) {
2190 if (pkt_dev
->flags
& F_QUEUE_MAP_RND
) {
2192 (pkt_dev
->queue_map_max
-
2193 pkt_dev
->queue_map_min
+ 1)
2194 + pkt_dev
->queue_map_min
;
2196 t
= pkt_dev
->cur_queue_map
+ 1;
2197 if (t
> pkt_dev
->queue_map_max
)
2198 t
= pkt_dev
->queue_map_min
;
2200 pkt_dev
->cur_queue_map
= t
;
2202 pkt_dev
->cur_queue_map
= pkt_dev
->cur_queue_map
% pkt_dev
->odev
->real_num_tx_queues
;
2205 /* Increment/randomize headers according to flags and current values
2206 * for IP src/dest, UDP src/dst port, MAC-Addr src/dst
2208 static void mod_cur_headers(struct pktgen_dev
*pkt_dev
)
2214 if (pkt_dev
->cflows
)
2215 flow
= f_pick(pkt_dev
);
2217 /* Deal with source MAC */
2218 if (pkt_dev
->src_mac_count
> 1) {
2222 if (pkt_dev
->flags
& F_MACSRC_RND
)
2223 mc
= random32() % pkt_dev
->src_mac_count
;
2225 mc
= pkt_dev
->cur_src_mac_offset
++;
2226 if (pkt_dev
->cur_src_mac_offset
>=
2227 pkt_dev
->src_mac_count
)
2228 pkt_dev
->cur_src_mac_offset
= 0;
2231 tmp
= pkt_dev
->src_mac
[5] + (mc
& 0xFF);
2232 pkt_dev
->hh
[11] = tmp
;
2233 tmp
= (pkt_dev
->src_mac
[4] + ((mc
>> 8) & 0xFF) + (tmp
>> 8));
2234 pkt_dev
->hh
[10] = tmp
;
2235 tmp
= (pkt_dev
->src_mac
[3] + ((mc
>> 16) & 0xFF) + (tmp
>> 8));
2236 pkt_dev
->hh
[9] = tmp
;
2237 tmp
= (pkt_dev
->src_mac
[2] + ((mc
>> 24) & 0xFF) + (tmp
>> 8));
2238 pkt_dev
->hh
[8] = tmp
;
2239 tmp
= (pkt_dev
->src_mac
[1] + (tmp
>> 8));
2240 pkt_dev
->hh
[7] = tmp
;
2243 /* Deal with Destination MAC */
2244 if (pkt_dev
->dst_mac_count
> 1) {
2248 if (pkt_dev
->flags
& F_MACDST_RND
)
2249 mc
= random32() % pkt_dev
->dst_mac_count
;
2252 mc
= pkt_dev
->cur_dst_mac_offset
++;
2253 if (pkt_dev
->cur_dst_mac_offset
>=
2254 pkt_dev
->dst_mac_count
) {
2255 pkt_dev
->cur_dst_mac_offset
= 0;
2259 tmp
= pkt_dev
->dst_mac
[5] + (mc
& 0xFF);
2260 pkt_dev
->hh
[5] = tmp
;
2261 tmp
= (pkt_dev
->dst_mac
[4] + ((mc
>> 8) & 0xFF) + (tmp
>> 8));
2262 pkt_dev
->hh
[4] = tmp
;
2263 tmp
= (pkt_dev
->dst_mac
[3] + ((mc
>> 16) & 0xFF) + (tmp
>> 8));
2264 pkt_dev
->hh
[3] = tmp
;
2265 tmp
= (pkt_dev
->dst_mac
[2] + ((mc
>> 24) & 0xFF) + (tmp
>> 8));
2266 pkt_dev
->hh
[2] = tmp
;
2267 tmp
= (pkt_dev
->dst_mac
[1] + (tmp
>> 8));
2268 pkt_dev
->hh
[1] = tmp
;
2271 if (pkt_dev
->flags
& F_MPLS_RND
) {
2273 for (i
= 0; i
< pkt_dev
->nr_labels
; i
++)
2274 if (pkt_dev
->labels
[i
] & MPLS_STACK_BOTTOM
)
2275 pkt_dev
->labels
[i
] = MPLS_STACK_BOTTOM
|
2276 ((__force __be32
)random32() &
2280 if ((pkt_dev
->flags
& F_VID_RND
) && (pkt_dev
->vlan_id
!= 0xffff)) {
2281 pkt_dev
->vlan_id
= random32() & (4096-1);
2284 if ((pkt_dev
->flags
& F_SVID_RND
) && (pkt_dev
->svlan_id
!= 0xffff)) {
2285 pkt_dev
->svlan_id
= random32() & (4096 - 1);
2288 if (pkt_dev
->udp_src_min
< pkt_dev
->udp_src_max
) {
2289 if (pkt_dev
->flags
& F_UDPSRC_RND
)
2290 pkt_dev
->cur_udp_src
= random32() %
2291 (pkt_dev
->udp_src_max
- pkt_dev
->udp_src_min
)
2292 + pkt_dev
->udp_src_min
;
2295 pkt_dev
->cur_udp_src
++;
2296 if (pkt_dev
->cur_udp_src
>= pkt_dev
->udp_src_max
)
2297 pkt_dev
->cur_udp_src
= pkt_dev
->udp_src_min
;
2301 if (pkt_dev
->udp_dst_min
< pkt_dev
->udp_dst_max
) {
2302 if (pkt_dev
->flags
& F_UDPDST_RND
) {
2303 pkt_dev
->cur_udp_dst
= random32() %
2304 (pkt_dev
->udp_dst_max
- pkt_dev
->udp_dst_min
)
2305 + pkt_dev
->udp_dst_min
;
2307 pkt_dev
->cur_udp_dst
++;
2308 if (pkt_dev
->cur_udp_dst
>= pkt_dev
->udp_dst_max
)
2309 pkt_dev
->cur_udp_dst
= pkt_dev
->udp_dst_min
;
2313 if (!(pkt_dev
->flags
& F_IPV6
)) {
2315 if ((imn
= ntohl(pkt_dev
->saddr_min
)) < (imx
=
2319 if (pkt_dev
->flags
& F_IPSRC_RND
)
2320 t
= random32() % (imx
- imn
) + imn
;
2322 t
= ntohl(pkt_dev
->cur_saddr
);
2328 pkt_dev
->cur_saddr
= htonl(t
);
2331 if (pkt_dev
->cflows
&& f_seen(pkt_dev
, flow
)) {
2332 pkt_dev
->cur_daddr
= pkt_dev
->flows
[flow
].cur_daddr
;
2334 imn
= ntohl(pkt_dev
->daddr_min
);
2335 imx
= ntohl(pkt_dev
->daddr_max
);
2339 if (pkt_dev
->flags
& F_IPDST_RND
) {
2341 t
= random32() % (imx
- imn
) + imn
;
2344 while (ipv4_is_loopback(s
) ||
2345 ipv4_is_multicast(s
) ||
2346 ipv4_is_lbcast(s
) ||
2347 ipv4_is_zeronet(s
) ||
2348 ipv4_is_local_multicast(s
)) {
2349 t
= random32() % (imx
- imn
) + imn
;
2352 pkt_dev
->cur_daddr
= s
;
2354 t
= ntohl(pkt_dev
->cur_daddr
);
2359 pkt_dev
->cur_daddr
= htonl(t
);
2362 if (pkt_dev
->cflows
) {
2363 pkt_dev
->flows
[flow
].flags
|= F_INIT
;
2364 pkt_dev
->flows
[flow
].cur_daddr
=
2367 if (pkt_dev
->flags
& F_IPSEC_ON
)
2368 get_ipsec_sa(pkt_dev
, flow
);
2373 } else { /* IPV6 * */
2375 if (pkt_dev
->min_in6_daddr
.s6_addr32
[0] == 0 &&
2376 pkt_dev
->min_in6_daddr
.s6_addr32
[1] == 0 &&
2377 pkt_dev
->min_in6_daddr
.s6_addr32
[2] == 0 &&
2378 pkt_dev
->min_in6_daddr
.s6_addr32
[3] == 0) ;
2382 /* Only random destinations yet */
2384 for (i
= 0; i
< 4; i
++) {
2385 pkt_dev
->cur_in6_daddr
.s6_addr32
[i
] =
2386 (((__force __be32
)random32() |
2387 pkt_dev
->min_in6_daddr
.s6_addr32
[i
]) &
2388 pkt_dev
->max_in6_daddr
.s6_addr32
[i
]);
2393 if (pkt_dev
->min_pkt_size
< pkt_dev
->max_pkt_size
) {
2395 if (pkt_dev
->flags
& F_TXSIZE_RND
) {
2397 (pkt_dev
->max_pkt_size
- pkt_dev
->min_pkt_size
)
2398 + pkt_dev
->min_pkt_size
;
2400 t
= pkt_dev
->cur_pkt_size
+ 1;
2401 if (t
> pkt_dev
->max_pkt_size
)
2402 t
= pkt_dev
->min_pkt_size
;
2404 pkt_dev
->cur_pkt_size
= t
;
2407 set_cur_queue_map(pkt_dev
);
2409 pkt_dev
->flows
[flow
].count
++;
2414 static int pktgen_output_ipsec(struct sk_buff
*skb
, struct pktgen_dev
*pkt_dev
)
2416 struct xfrm_state
*x
= pkt_dev
->flows
[pkt_dev
->curfl
].x
;
2422 /* XXX: we dont support tunnel mode for now until
2423 * we resolve the dst issue */
2424 if (x
->props
.mode
!= XFRM_MODE_TRANSPORT
)
2427 spin_lock(&x
->lock
);
2430 err
= x
->outer_mode
->output(x
, skb
);
2433 err
= x
->type
->output(x
, skb
);
2437 x
->curlft
.bytes
+=skb
->len
;
2438 x
->curlft
.packets
++;
2440 spin_unlock(&x
->lock
);
2444 static inline void free_SAs(struct pktgen_dev
*pkt_dev
)
2446 if (pkt_dev
->cflows
) {
2447 /* let go of the SAs if we have them */
2449 for (; i
< pkt_dev
->nflows
; i
++){
2450 struct xfrm_state
*x
= pkt_dev
->flows
[i
].x
;
2453 pkt_dev
->flows
[i
].x
= NULL
;
2459 static inline int process_ipsec(struct pktgen_dev
*pkt_dev
,
2460 struct sk_buff
*skb
, __be16 protocol
)
2462 if (pkt_dev
->flags
& F_IPSEC_ON
) {
2463 struct xfrm_state
*x
= pkt_dev
->flows
[pkt_dev
->curfl
].x
;
2468 nhead
= x
->props
.header_len
- skb_headroom(skb
);
2470 ret
= pskb_expand_head(skb
, nhead
, 0, GFP_ATOMIC
);
2472 printk(KERN_ERR
"Error expanding "
2473 "ipsec packet %d\n",ret
);
2478 /* ipsec is not expecting ll header */
2479 skb_pull(skb
, ETH_HLEN
);
2480 ret
= pktgen_output_ipsec(skb
, pkt_dev
);
2482 printk(KERN_ERR
"Error creating ipsec "
2487 eth
= (__u8
*) skb_push(skb
, ETH_HLEN
);
2488 memcpy(eth
, pkt_dev
->hh
, 12);
2489 *(u16
*) & eth
[12] = protocol
;
2499 static void mpls_push(__be32
*mpls
, struct pktgen_dev
*pkt_dev
)
2502 for (i
= 0; i
< pkt_dev
->nr_labels
; i
++) {
2503 *mpls
++ = pkt_dev
->labels
[i
] & ~MPLS_STACK_BOTTOM
;
2506 *mpls
|= MPLS_STACK_BOTTOM
;
2509 static inline __be16
build_tci(unsigned int id
, unsigned int cfi
,
2512 return htons(id
| (cfi
<< 12) | (prio
<< 13));
2515 static struct sk_buff
*fill_packet_ipv4(struct net_device
*odev
,
2516 struct pktgen_dev
*pkt_dev
)
2518 struct sk_buff
*skb
= NULL
;
2520 struct udphdr
*udph
;
2523 struct pktgen_hdr
*pgh
= NULL
;
2524 __be16 protocol
= htons(ETH_P_IP
);
2526 __be16
*vlan_tci
= NULL
; /* Encapsulates priority and VLAN ID */
2527 __be16
*vlan_encapsulated_proto
= NULL
; /* packet type ID field (or len) for VLAN tag */
2528 __be16
*svlan_tci
= NULL
; /* Encapsulates priority and SVLAN ID */
2529 __be16
*svlan_encapsulated_proto
= NULL
; /* packet type ID field (or len) for SVLAN tag */
2532 if (pkt_dev
->nr_labels
)
2533 protocol
= htons(ETH_P_MPLS_UC
);
2535 if (pkt_dev
->vlan_id
!= 0xffff)
2536 protocol
= htons(ETH_P_8021Q
);
2538 /* Update any of the values, used when we're incrementing various
2541 queue_map
= pkt_dev
->cur_queue_map
;
2542 mod_cur_headers(pkt_dev
);
2544 datalen
= (odev
->hard_header_len
+ 16) & ~0xf;
2545 skb
= alloc_skb(pkt_dev
->cur_pkt_size
+ 64 + datalen
+
2546 pkt_dev
->pkt_overhead
, GFP_ATOMIC
);
2548 sprintf(pkt_dev
->result
, "No memory");
2552 skb_reserve(skb
, datalen
);
2554 /* Reserve for ethernet and IP header */
2555 eth
= (__u8
*) skb_push(skb
, 14);
2556 mpls
= (__be32
*)skb_put(skb
, pkt_dev
->nr_labels
*sizeof(__u32
));
2557 if (pkt_dev
->nr_labels
)
2558 mpls_push(mpls
, pkt_dev
);
2560 if (pkt_dev
->vlan_id
!= 0xffff) {
2561 if (pkt_dev
->svlan_id
!= 0xffff) {
2562 svlan_tci
= (__be16
*)skb_put(skb
, sizeof(__be16
));
2563 *svlan_tci
= build_tci(pkt_dev
->svlan_id
,
2566 svlan_encapsulated_proto
= (__be16
*)skb_put(skb
, sizeof(__be16
));
2567 *svlan_encapsulated_proto
= htons(ETH_P_8021Q
);
2569 vlan_tci
= (__be16
*)skb_put(skb
, sizeof(__be16
));
2570 *vlan_tci
= build_tci(pkt_dev
->vlan_id
,
2573 vlan_encapsulated_proto
= (__be16
*)skb_put(skb
, sizeof(__be16
));
2574 *vlan_encapsulated_proto
= htons(ETH_P_IP
);
2577 skb
->network_header
= skb
->tail
;
2578 skb
->transport_header
= skb
->network_header
+ sizeof(struct iphdr
);
2579 skb_put(skb
, sizeof(struct iphdr
) + sizeof(struct udphdr
));
2580 skb_set_queue_mapping(skb
, queue_map
);
2582 udph
= udp_hdr(skb
);
2584 memcpy(eth
, pkt_dev
->hh
, 12);
2585 *(__be16
*) & eth
[12] = protocol
;
2587 /* Eth + IPh + UDPh + mpls */
2588 datalen
= pkt_dev
->cur_pkt_size
- 14 - 20 - 8 -
2589 pkt_dev
->pkt_overhead
;
2590 if (datalen
< sizeof(struct pktgen_hdr
))
2591 datalen
= sizeof(struct pktgen_hdr
);
2593 udph
->source
= htons(pkt_dev
->cur_udp_src
);
2594 udph
->dest
= htons(pkt_dev
->cur_udp_dst
);
2595 udph
->len
= htons(datalen
+ 8); /* DATA + udphdr */
2596 udph
->check
= 0; /* No checksum */
2601 iph
->tos
= pkt_dev
->tos
;
2602 iph
->protocol
= IPPROTO_UDP
; /* UDP */
2603 iph
->saddr
= pkt_dev
->cur_saddr
;
2604 iph
->daddr
= pkt_dev
->cur_daddr
;
2606 iplen
= 20 + 8 + datalen
;
2607 iph
->tot_len
= htons(iplen
);
2609 iph
->check
= ip_fast_csum((void *)iph
, iph
->ihl
);
2610 skb
->protocol
= protocol
;
2611 skb
->mac_header
= (skb
->network_header
- ETH_HLEN
-
2612 pkt_dev
->pkt_overhead
);
2614 skb
->pkt_type
= PACKET_HOST
;
2616 if (pkt_dev
->nfrags
<= 0)
2617 pgh
= (struct pktgen_hdr
*)skb_put(skb
, datalen
);
2619 int frags
= pkt_dev
->nfrags
;
2622 pgh
= (struct pktgen_hdr
*)(((char *)(udph
)) + 8);
2624 if (frags
> MAX_SKB_FRAGS
)
2625 frags
= MAX_SKB_FRAGS
;
2626 if (datalen
> frags
* PAGE_SIZE
) {
2627 skb_put(skb
, datalen
- frags
* PAGE_SIZE
);
2628 datalen
= frags
* PAGE_SIZE
;
2632 while (datalen
> 0) {
2633 struct page
*page
= alloc_pages(GFP_KERNEL
, 0);
2634 skb_shinfo(skb
)->frags
[i
].page
= page
;
2635 skb_shinfo(skb
)->frags
[i
].page_offset
= 0;
2636 skb_shinfo(skb
)->frags
[i
].size
=
2637 (datalen
< PAGE_SIZE
? datalen
: PAGE_SIZE
);
2638 datalen
-= skb_shinfo(skb
)->frags
[i
].size
;
2639 skb
->len
+= skb_shinfo(skb
)->frags
[i
].size
;
2640 skb
->data_len
+= skb_shinfo(skb
)->frags
[i
].size
;
2642 skb_shinfo(skb
)->nr_frags
= i
;
2651 rem
= skb_shinfo(skb
)->frags
[i
- 1].size
/ 2;
2655 skb_shinfo(skb
)->frags
[i
- 1].size
-= rem
;
2657 skb_shinfo(skb
)->frags
[i
] =
2658 skb_shinfo(skb
)->frags
[i
- 1];
2659 get_page(skb_shinfo(skb
)->frags
[i
].page
);
2660 skb_shinfo(skb
)->frags
[i
].page
=
2661 skb_shinfo(skb
)->frags
[i
- 1].page
;
2662 skb_shinfo(skb
)->frags
[i
].page_offset
+=
2663 skb_shinfo(skb
)->frags
[i
- 1].size
;
2664 skb_shinfo(skb
)->frags
[i
].size
= rem
;
2666 skb_shinfo(skb
)->nr_frags
= i
;
2670 /* Stamp the time, and sequence number, convert them to network byte order */
2673 struct timeval timestamp
;
2675 pgh
->pgh_magic
= htonl(PKTGEN_MAGIC
);
2676 pgh
->seq_num
= htonl(pkt_dev
->seq_num
);
2678 do_gettimeofday(×tamp
);
2679 pgh
->tv_sec
= htonl(timestamp
.tv_sec
);
2680 pgh
->tv_usec
= htonl(timestamp
.tv_usec
);
2684 if (!process_ipsec(pkt_dev
, skb
, protocol
))
2692 * scan_ip6, fmt_ip taken from dietlibc-0.21
2693 * Author Felix von Leitner <felix-dietlibc@fefe.de>
2695 * Slightly modified for kernel.
2696 * Should be candidate for net/ipv4/utils.c
2700 static unsigned int scan_ip6(const char *s
, char ip
[16])
2703 unsigned int len
= 0;
2706 unsigned int prefixlen
= 0;
2707 unsigned int suffixlen
= 0;
2711 for (i
= 0; i
< 16; i
++)
2717 if (s
[1] == ':') { /* Found "::", skip to part 2 */
2725 u
= simple_strtoul(s
, &pos
, 16);
2729 if (prefixlen
== 12 && s
[i
] == '.') {
2731 /* the last 4 bytes may be written as IPv4 address */
2734 memcpy((struct in_addr
*)(ip
+ 12), &tmp
, sizeof(tmp
));
2737 ip
[prefixlen
++] = (u
>> 8);
2738 ip
[prefixlen
++] = (u
& 255);
2741 if (prefixlen
== 16)
2745 /* part 2, after "::" */
2752 } else if (suffixlen
!= 0)
2755 u
= simple_strtol(s
, &pos
, 16);
2762 if (suffixlen
+ prefixlen
<= 12 && s
[i
] == '.') {
2764 memcpy((struct in_addr
*)(suffix
+ suffixlen
), &tmp
,
2770 suffix
[suffixlen
++] = (u
>> 8);
2771 suffix
[suffixlen
++] = (u
& 255);
2774 if (prefixlen
+ suffixlen
== 16)
2777 for (i
= 0; i
< suffixlen
; i
++)
2778 ip
[16 - suffixlen
+ i
] = suffix
[i
];
2782 static char tohex(char hexdigit
)
2784 return hexdigit
> 9 ? hexdigit
+ 'a' - 10 : hexdigit
+ '0';
2787 static int fmt_xlong(char *s
, unsigned int i
)
2790 *s
= tohex((i
>> 12) & 0xf);
2791 if (s
!= bak
|| *s
!= '0')
2793 *s
= tohex((i
>> 8) & 0xf);
2794 if (s
!= bak
|| *s
!= '0')
2796 *s
= tohex((i
>> 4) & 0xf);
2797 if (s
!= bak
|| *s
!= '0')
2799 *s
= tohex(i
& 0xf);
2803 static unsigned int fmt_ip6(char *s
, const char ip
[16])
2808 unsigned int compressing
;
2813 for (j
= 0; j
< 16; j
+= 2) {
2815 #ifdef V4MAPPEDPREFIX
2816 if (j
== 12 && !memcmp(ip
, V4mappedprefix
, 12)) {
2817 inet_ntoa_r(*(struct in_addr
*)(ip
+ 12), s
);
2822 temp
= ((unsigned long)(unsigned char)ip
[j
] << 8) +
2823 (unsigned long)(unsigned char)ip
[j
+ 1];
2838 i
= fmt_xlong(s
, temp
);
2855 static struct sk_buff
*fill_packet_ipv6(struct net_device
*odev
,
2856 struct pktgen_dev
*pkt_dev
)
2858 struct sk_buff
*skb
= NULL
;
2860 struct udphdr
*udph
;
2862 struct ipv6hdr
*iph
;
2863 struct pktgen_hdr
*pgh
= NULL
;
2864 __be16 protocol
= htons(ETH_P_IPV6
);
2866 __be16
*vlan_tci
= NULL
; /* Encapsulates priority and VLAN ID */
2867 __be16
*vlan_encapsulated_proto
= NULL
; /* packet type ID field (or len) for VLAN tag */
2868 __be16
*svlan_tci
= NULL
; /* Encapsulates priority and SVLAN ID */
2869 __be16
*svlan_encapsulated_proto
= NULL
; /* packet type ID field (or len) for SVLAN tag */
2872 if (pkt_dev
->nr_labels
)
2873 protocol
= htons(ETH_P_MPLS_UC
);
2875 if (pkt_dev
->vlan_id
!= 0xffff)
2876 protocol
= htons(ETH_P_8021Q
);
2878 /* Update any of the values, used when we're incrementing various
2881 queue_map
= pkt_dev
->cur_queue_map
;
2882 mod_cur_headers(pkt_dev
);
2884 skb
= alloc_skb(pkt_dev
->cur_pkt_size
+ 64 + 16 +
2885 pkt_dev
->pkt_overhead
, GFP_ATOMIC
);
2887 sprintf(pkt_dev
->result
, "No memory");
2891 skb_reserve(skb
, 16);
2893 /* Reserve for ethernet and IP header */
2894 eth
= (__u8
*) skb_push(skb
, 14);
2895 mpls
= (__be32
*)skb_put(skb
, pkt_dev
->nr_labels
*sizeof(__u32
));
2896 if (pkt_dev
->nr_labels
)
2897 mpls_push(mpls
, pkt_dev
);
2899 if (pkt_dev
->vlan_id
!= 0xffff) {
2900 if (pkt_dev
->svlan_id
!= 0xffff) {
2901 svlan_tci
= (__be16
*)skb_put(skb
, sizeof(__be16
));
2902 *svlan_tci
= build_tci(pkt_dev
->svlan_id
,
2905 svlan_encapsulated_proto
= (__be16
*)skb_put(skb
, sizeof(__be16
));
2906 *svlan_encapsulated_proto
= htons(ETH_P_8021Q
);
2908 vlan_tci
= (__be16
*)skb_put(skb
, sizeof(__be16
));
2909 *vlan_tci
= build_tci(pkt_dev
->vlan_id
,
2912 vlan_encapsulated_proto
= (__be16
*)skb_put(skb
, sizeof(__be16
));
2913 *vlan_encapsulated_proto
= htons(ETH_P_IPV6
);
2916 skb
->network_header
= skb
->tail
;
2917 skb
->transport_header
= skb
->network_header
+ sizeof(struct ipv6hdr
);
2918 skb_put(skb
, sizeof(struct ipv6hdr
) + sizeof(struct udphdr
));
2919 skb_set_queue_mapping(skb
, queue_map
);
2920 iph
= ipv6_hdr(skb
);
2921 udph
= udp_hdr(skb
);
2923 memcpy(eth
, pkt_dev
->hh
, 12);
2924 *(__be16
*) & eth
[12] = protocol
;
2926 /* Eth + IPh + UDPh + mpls */
2927 datalen
= pkt_dev
->cur_pkt_size
- 14 -
2928 sizeof(struct ipv6hdr
) - sizeof(struct udphdr
) -
2929 pkt_dev
->pkt_overhead
;
2931 if (datalen
< sizeof(struct pktgen_hdr
)) {
2932 datalen
= sizeof(struct pktgen_hdr
);
2933 if (net_ratelimit())
2934 printk(KERN_INFO
"pktgen: increased datalen to %d\n",
2938 udph
->source
= htons(pkt_dev
->cur_udp_src
);
2939 udph
->dest
= htons(pkt_dev
->cur_udp_dst
);
2940 udph
->len
= htons(datalen
+ sizeof(struct udphdr
));
2941 udph
->check
= 0; /* No checksum */
2943 *(__be32
*) iph
= htonl(0x60000000); /* Version + flow */
2945 if (pkt_dev
->traffic_class
) {
2946 /* Version + traffic class + flow (0) */
2947 *(__be32
*)iph
|= htonl(0x60000000 | (pkt_dev
->traffic_class
<< 20));
2950 iph
->hop_limit
= 32;
2952 iph
->payload_len
= htons(sizeof(struct udphdr
) + datalen
);
2953 iph
->nexthdr
= IPPROTO_UDP
;
2955 ipv6_addr_copy(&iph
->daddr
, &pkt_dev
->cur_in6_daddr
);
2956 ipv6_addr_copy(&iph
->saddr
, &pkt_dev
->cur_in6_saddr
);
2958 skb
->mac_header
= (skb
->network_header
- ETH_HLEN
-
2959 pkt_dev
->pkt_overhead
);
2960 skb
->protocol
= protocol
;
2962 skb
->pkt_type
= PACKET_HOST
;
2964 if (pkt_dev
->nfrags
<= 0)
2965 pgh
= (struct pktgen_hdr
*)skb_put(skb
, datalen
);
2967 int frags
= pkt_dev
->nfrags
;
2970 pgh
= (struct pktgen_hdr
*)(((char *)(udph
)) + 8);
2972 if (frags
> MAX_SKB_FRAGS
)
2973 frags
= MAX_SKB_FRAGS
;
2974 if (datalen
> frags
* PAGE_SIZE
) {
2975 skb_put(skb
, datalen
- frags
* PAGE_SIZE
);
2976 datalen
= frags
* PAGE_SIZE
;
2980 while (datalen
> 0) {
2981 struct page
*page
= alloc_pages(GFP_KERNEL
, 0);
2982 skb_shinfo(skb
)->frags
[i
].page
= page
;
2983 skb_shinfo(skb
)->frags
[i
].page_offset
= 0;
2984 skb_shinfo(skb
)->frags
[i
].size
=
2985 (datalen
< PAGE_SIZE
? datalen
: PAGE_SIZE
);
2986 datalen
-= skb_shinfo(skb
)->frags
[i
].size
;
2987 skb
->len
+= skb_shinfo(skb
)->frags
[i
].size
;
2988 skb
->data_len
+= skb_shinfo(skb
)->frags
[i
].size
;
2990 skb_shinfo(skb
)->nr_frags
= i
;
2999 rem
= skb_shinfo(skb
)->frags
[i
- 1].size
/ 2;
3003 skb_shinfo(skb
)->frags
[i
- 1].size
-= rem
;
3005 skb_shinfo(skb
)->frags
[i
] =
3006 skb_shinfo(skb
)->frags
[i
- 1];
3007 get_page(skb_shinfo(skb
)->frags
[i
].page
);
3008 skb_shinfo(skb
)->frags
[i
].page
=
3009 skb_shinfo(skb
)->frags
[i
- 1].page
;
3010 skb_shinfo(skb
)->frags
[i
].page_offset
+=
3011 skb_shinfo(skb
)->frags
[i
- 1].size
;
3012 skb_shinfo(skb
)->frags
[i
].size
= rem
;
3014 skb_shinfo(skb
)->nr_frags
= i
;
3018 /* Stamp the time, and sequence number, convert them to network byte order */
3019 /* should we update cloned packets too ? */
3021 struct timeval timestamp
;
3023 pgh
->pgh_magic
= htonl(PKTGEN_MAGIC
);
3024 pgh
->seq_num
= htonl(pkt_dev
->seq_num
);
3026 do_gettimeofday(×tamp
);
3027 pgh
->tv_sec
= htonl(timestamp
.tv_sec
);
3028 pgh
->tv_usec
= htonl(timestamp
.tv_usec
);
3030 /* pkt_dev->seq_num++; FF: you really mean this? */
3035 static inline struct sk_buff
*fill_packet(struct net_device
*odev
,
3036 struct pktgen_dev
*pkt_dev
)
3038 if (pkt_dev
->flags
& F_IPV6
)
3039 return fill_packet_ipv6(odev
, pkt_dev
);
3041 return fill_packet_ipv4(odev
, pkt_dev
);
3044 static void pktgen_clear_counters(struct pktgen_dev
*pkt_dev
)
3046 pkt_dev
->seq_num
= 1;
3047 pkt_dev
->idle_acc
= 0;
3049 pkt_dev
->tx_bytes
= 0;
3050 pkt_dev
->errors
= 0;
3053 /* Set up structure for sending pkts, clear counters */
3055 static void pktgen_run(struct pktgen_thread
*t
)
3057 struct pktgen_dev
*pkt_dev
;
3060 pr_debug("pktgen: entering pktgen_run. %p\n", t
);
3063 list_for_each_entry(pkt_dev
, &t
->if_list
, list
) {
3066 * setup odev and create initial packet.
3068 pktgen_setup_inject(pkt_dev
);
3070 if (pkt_dev
->odev
) {
3071 pktgen_clear_counters(pkt_dev
);
3072 pkt_dev
->running
= 1; /* Cranke yeself! */
3073 pkt_dev
->skb
= NULL
;
3074 pkt_dev
->started_at
= getCurUs();
3075 pkt_dev
->next_tx_us
= getCurUs(); /* Transmit immediately */
3076 pkt_dev
->next_tx_ns
= 0;
3077 set_pkt_overhead(pkt_dev
);
3079 strcpy(pkt_dev
->result
, "Starting");
3082 strcpy(pkt_dev
->result
, "Error starting");
3086 t
->control
&= ~(T_STOP
);
3089 static void pktgen_stop_all_threads_ifs(void)
3091 struct pktgen_thread
*t
;
3093 pr_debug("pktgen: entering pktgen_stop_all_threads_ifs.\n");
3095 mutex_lock(&pktgen_thread_lock
);
3097 list_for_each_entry(t
, &pktgen_threads
, th_list
)
3098 t
->control
|= T_STOP
;
3100 mutex_unlock(&pktgen_thread_lock
);
3103 static int thread_is_running(struct pktgen_thread
*t
)
3105 struct pktgen_dev
*pkt_dev
;
3108 list_for_each_entry(pkt_dev
, &t
->if_list
, list
)
3109 if (pkt_dev
->running
) {
3116 static int pktgen_wait_thread_run(struct pktgen_thread
*t
)
3120 while (thread_is_running(t
)) {
3124 msleep_interruptible(100);
3126 if (signal_pending(current
))
3136 static int pktgen_wait_all_threads_run(void)
3138 struct pktgen_thread
*t
;
3141 mutex_lock(&pktgen_thread_lock
);
3143 list_for_each_entry(t
, &pktgen_threads
, th_list
) {
3144 sig
= pktgen_wait_thread_run(t
);
3150 list_for_each_entry(t
, &pktgen_threads
, th_list
)
3151 t
->control
|= (T_STOP
);
3153 mutex_unlock(&pktgen_thread_lock
);
3157 static void pktgen_run_all_threads(void)
3159 struct pktgen_thread
*t
;
3161 pr_debug("pktgen: entering pktgen_run_all_threads.\n");
3163 mutex_lock(&pktgen_thread_lock
);
3165 list_for_each_entry(t
, &pktgen_threads
, th_list
)
3166 t
->control
|= (T_RUN
);
3168 mutex_unlock(&pktgen_thread_lock
);
3170 schedule_timeout_interruptible(msecs_to_jiffies(125)); /* Propagate thread->control */
3172 pktgen_wait_all_threads_run();
3175 static void pktgen_reset_all_threads(void)
3177 struct pktgen_thread
*t
;
3179 pr_debug("pktgen: entering pktgen_reset_all_threads.\n");
3181 mutex_lock(&pktgen_thread_lock
);
3183 list_for_each_entry(t
, &pktgen_threads
, th_list
)
3184 t
->control
|= (T_REMDEVALL
);
3186 mutex_unlock(&pktgen_thread_lock
);
3188 schedule_timeout_interruptible(msecs_to_jiffies(125)); /* Propagate thread->control */
3190 pktgen_wait_all_threads_run();
3193 static void show_results(struct pktgen_dev
*pkt_dev
, int nr_frags
)
3195 __u64 total_us
, bps
, mbps
, pps
, idle
;
3196 char *p
= pkt_dev
->result
;
3198 total_us
= pkt_dev
->stopped_at
- pkt_dev
->started_at
;
3200 idle
= pkt_dev
->idle_acc
;
3202 p
+= sprintf(p
, "OK: %llu(c%llu+d%llu) usec, %llu (%dbyte,%dfrags)\n",
3203 (unsigned long long)total_us
,
3204 (unsigned long long)(total_us
- idle
),
3205 (unsigned long long)idle
,
3206 (unsigned long long)pkt_dev
->sofar
,
3207 pkt_dev
->cur_pkt_size
, nr_frags
);
3209 pps
= pkt_dev
->sofar
* USEC_PER_SEC
;
3211 while ((total_us
>> 32) != 0) {
3216 do_div(pps
, total_us
);
3218 bps
= pps
* 8 * pkt_dev
->cur_pkt_size
;
3221 do_div(mbps
, 1000000);
3222 p
+= sprintf(p
, " %llupps %lluMb/sec (%llubps) errors: %llu",
3223 (unsigned long long)pps
,
3224 (unsigned long long)mbps
,
3225 (unsigned long long)bps
,
3226 (unsigned long long)pkt_dev
->errors
);
3229 /* Set stopped-at timer, remove from running list, do counters & statistics */
3231 static int pktgen_stop_device(struct pktgen_dev
*pkt_dev
)
3233 int nr_frags
= pkt_dev
->skb
? skb_shinfo(pkt_dev
->skb
)->nr_frags
: -1;
3235 if (!pkt_dev
->running
) {
3236 printk(KERN_WARNING
"pktgen: interface: %s is already "
3237 "stopped\n", pkt_dev
->odev
->name
);
3241 pkt_dev
->stopped_at
= getCurUs();
3242 pkt_dev
->running
= 0;
3244 show_results(pkt_dev
, nr_frags
);
3249 static struct pktgen_dev
*next_to_run(struct pktgen_thread
*t
)
3251 struct pktgen_dev
*pkt_dev
, *best
= NULL
;
3255 list_for_each_entry(pkt_dev
, &t
->if_list
, list
) {
3256 if (!pkt_dev
->running
)
3260 else if (pkt_dev
->next_tx_us
< best
->next_tx_us
)
3267 static void pktgen_stop(struct pktgen_thread
*t
)
3269 struct pktgen_dev
*pkt_dev
;
3271 pr_debug("pktgen: entering pktgen_stop\n");
3275 list_for_each_entry(pkt_dev
, &t
->if_list
, list
) {
3276 pktgen_stop_device(pkt_dev
);
3278 kfree_skb(pkt_dev
->skb
);
3280 pkt_dev
->skb
= NULL
;
3287 * one of our devices needs to be removed - find it
3290 static void pktgen_rem_one_if(struct pktgen_thread
*t
)
3292 struct list_head
*q
, *n
;
3293 struct pktgen_dev
*cur
;
3295 pr_debug("pktgen: entering pktgen_rem_one_if\n");
3299 list_for_each_safe(q
, n
, &t
->if_list
) {
3300 cur
= list_entry(q
, struct pktgen_dev
, list
);
3302 if (!cur
->removal_mark
)
3306 kfree_skb(cur
->skb
);
3309 pktgen_remove_device(t
, cur
);
3317 static void pktgen_rem_all_ifs(struct pktgen_thread
*t
)
3319 struct list_head
*q
, *n
;
3320 struct pktgen_dev
*cur
;
3322 /* Remove all devices, free mem */
3324 pr_debug("pktgen: entering pktgen_rem_all_ifs\n");
3327 list_for_each_safe(q
, n
, &t
->if_list
) {
3328 cur
= list_entry(q
, struct pktgen_dev
, list
);
3331 kfree_skb(cur
->skb
);
3334 pktgen_remove_device(t
, cur
);
3340 static void pktgen_rem_thread(struct pktgen_thread
*t
)
3342 /* Remove from the thread list */
3344 remove_proc_entry(t
->tsk
->comm
, pg_proc_dir
);
3346 mutex_lock(&pktgen_thread_lock
);
3348 list_del(&t
->th_list
);
3350 mutex_unlock(&pktgen_thread_lock
);
3353 static __inline__
void pktgen_xmit(struct pktgen_dev
*pkt_dev
)
3355 struct net_device
*odev
= pkt_dev
->odev
;
3356 int (*xmit
)(struct sk_buff
*, struct net_device
*)
3357 = odev
->netdev_ops
->ndo_start_xmit
;
3358 struct netdev_queue
*txq
;
3359 __u64 idle_start
= 0;
3363 if (pkt_dev
->delay_us
|| pkt_dev
->delay_ns
) {
3367 if (now
< pkt_dev
->next_tx_us
)
3368 spin(pkt_dev
, pkt_dev
->next_tx_us
);
3370 /* This is max DELAY, this has special meaning of
3373 if (pkt_dev
->delay_us
== 0x7FFFFFFF) {
3374 pkt_dev
->next_tx_us
= getCurUs() + pkt_dev
->delay_us
;
3375 pkt_dev
->next_tx_ns
= pkt_dev
->delay_ns
;
3380 if (!pkt_dev
->skb
) {
3381 set_cur_queue_map(pkt_dev
);
3382 queue_map
= pkt_dev
->cur_queue_map
;
3384 queue_map
= skb_get_queue_mapping(pkt_dev
->skb
);
3387 txq
= netdev_get_tx_queue(odev
, queue_map
);
3388 if (netif_tx_queue_stopped(txq
) ||
3389 netif_tx_queue_frozen(txq
) ||
3391 idle_start
= getCurUs();
3393 if (!netif_running(odev
)) {
3394 pktgen_stop_device(pkt_dev
);
3396 kfree_skb(pkt_dev
->skb
);
3397 pkt_dev
->skb
= NULL
;
3403 pkt_dev
->idle_acc
+= getCurUs() - idle_start
;
3405 if (netif_tx_queue_stopped(txq
) ||
3406 netif_tx_queue_frozen(txq
)) {
3407 pkt_dev
->next_tx_us
= getCurUs(); /* TODO */
3408 pkt_dev
->next_tx_ns
= 0;
3409 goto out
; /* Try the next interface */
3413 if (pkt_dev
->last_ok
|| !pkt_dev
->skb
) {
3414 if ((++pkt_dev
->clone_count
>= pkt_dev
->clone_skb
)
3415 || (!pkt_dev
->skb
)) {
3416 /* build a new pkt */
3418 kfree_skb(pkt_dev
->skb
);
3420 pkt_dev
->skb
= fill_packet(odev
, pkt_dev
);
3421 if (pkt_dev
->skb
== NULL
) {
3422 printk(KERN_ERR
"pktgen: ERROR: couldn't "
3423 "allocate skb in fill_packet.\n");
3425 pkt_dev
->clone_count
--; /* back out increment, OOM */
3428 pkt_dev
->allocated_skbs
++;
3429 pkt_dev
->clone_count
= 0; /* reset counter */
3433 /* fill_packet() might have changed the queue */
3434 queue_map
= skb_get_queue_mapping(pkt_dev
->skb
);
3435 txq
= netdev_get_tx_queue(odev
, queue_map
);
3437 __netif_tx_lock_bh(txq
);
3438 if (!netif_tx_queue_stopped(txq
) &&
3439 !netif_tx_queue_frozen(txq
)) {
3441 atomic_inc(&(pkt_dev
->skb
->users
));
3443 ret
= (*xmit
)(pkt_dev
->skb
, odev
);
3444 if (likely(ret
== NETDEV_TX_OK
)) {
3445 pkt_dev
->last_ok
= 1;
3448 pkt_dev
->tx_bytes
+= pkt_dev
->cur_pkt_size
;
3450 } else if (ret
== NETDEV_TX_LOCKED
3451 && (odev
->features
& NETIF_F_LLTX
)) {
3454 } else { /* Retry it next time */
3456 atomic_dec(&(pkt_dev
->skb
->users
));
3458 if (debug
&& net_ratelimit())
3459 printk(KERN_INFO
"pktgen: Hard xmit error\n");
3462 pkt_dev
->last_ok
= 0;
3465 pkt_dev
->next_tx_us
= getCurUs();
3466 pkt_dev
->next_tx_ns
= 0;
3468 pkt_dev
->next_tx_us
+= pkt_dev
->delay_us
;
3469 pkt_dev
->next_tx_ns
+= pkt_dev
->delay_ns
;
3471 if (pkt_dev
->next_tx_ns
> 1000) {
3472 pkt_dev
->next_tx_us
++;
3473 pkt_dev
->next_tx_ns
-= 1000;
3477 else { /* Retry it next time */
3478 pkt_dev
->last_ok
= 0;
3479 pkt_dev
->next_tx_us
= getCurUs(); /* TODO */
3480 pkt_dev
->next_tx_ns
= 0;
3483 __netif_tx_unlock_bh(txq
);
3485 /* If pkt_dev->count is zero, then run forever */
3486 if ((pkt_dev
->count
!= 0) && (pkt_dev
->sofar
>= pkt_dev
->count
)) {
3487 if (atomic_read(&(pkt_dev
->skb
->users
)) != 1) {
3488 idle_start
= getCurUs();
3489 while (atomic_read(&(pkt_dev
->skb
->users
)) != 1) {
3490 if (signal_pending(current
)) {
3495 pkt_dev
->idle_acc
+= getCurUs() - idle_start
;
3498 /* Done with this */
3499 pktgen_stop_device(pkt_dev
);
3501 kfree_skb(pkt_dev
->skb
);
3502 pkt_dev
->skb
= NULL
;
3508 * Main loop of the thread goes here
3511 static int pktgen_thread_worker(void *arg
)
3514 struct pktgen_thread
*t
= arg
;
3515 struct pktgen_dev
*pkt_dev
= NULL
;
3518 BUG_ON(smp_processor_id() != cpu
);
3520 init_waitqueue_head(&t
->queue
);
3521 complete(&t
->start_done
);
3523 pr_debug("pktgen: starting pktgen/%d: pid=%d\n", cpu
, task_pid_nr(current
));
3525 set_current_state(TASK_INTERRUPTIBLE
);
3529 while (!kthread_should_stop()) {
3530 pkt_dev
= next_to_run(t
);
3533 (t
->control
& (T_STOP
| T_RUN
| T_REMDEVALL
| T_REMDEV
))
3535 prepare_to_wait(&(t
->queue
), &wait
,
3536 TASK_INTERRUPTIBLE
);
3537 schedule_timeout(HZ
/ 10);
3538 finish_wait(&(t
->queue
), &wait
);
3541 __set_current_state(TASK_RUNNING
);
3544 pktgen_xmit(pkt_dev
);
3546 if (t
->control
& T_STOP
) {
3548 t
->control
&= ~(T_STOP
);
3551 if (t
->control
& T_RUN
) {
3553 t
->control
&= ~(T_RUN
);
3556 if (t
->control
& T_REMDEVALL
) {
3557 pktgen_rem_all_ifs(t
);
3558 t
->control
&= ~(T_REMDEVALL
);
3561 if (t
->control
& T_REMDEV
) {
3562 pktgen_rem_one_if(t
);
3563 t
->control
&= ~(T_REMDEV
);
3568 set_current_state(TASK_INTERRUPTIBLE
);
3571 pr_debug("pktgen: %s stopping all device\n", t
->tsk
->comm
);
3574 pr_debug("pktgen: %s removing all device\n", t
->tsk
->comm
);
3575 pktgen_rem_all_ifs(t
);
3577 pr_debug("pktgen: %s removing thread.\n", t
->tsk
->comm
);
3578 pktgen_rem_thread(t
);
3583 static struct pktgen_dev
*pktgen_find_dev(struct pktgen_thread
*t
,
3586 struct pktgen_dev
*p
, *pkt_dev
= NULL
;
3589 list_for_each_entry(p
, &t
->if_list
, list
)
3590 if (strncmp(p
->odev
->name
, ifname
, IFNAMSIZ
) == 0) {
3596 pr_debug("pktgen: find_dev(%s) returning %p\n", ifname
, pkt_dev
);
3601 * Adds a dev at front of if_list.
3604 static int add_dev_to_thread(struct pktgen_thread
*t
,
3605 struct pktgen_dev
*pkt_dev
)
3611 if (pkt_dev
->pg_thread
) {
3612 printk(KERN_ERR
"pktgen: ERROR: already assigned "
3618 list_add(&pkt_dev
->list
, &t
->if_list
);
3619 pkt_dev
->pg_thread
= t
;
3620 pkt_dev
->running
= 0;
3627 /* Called under thread lock */
3629 static int pktgen_add_device(struct pktgen_thread
*t
, const char *ifname
)
3631 struct pktgen_dev
*pkt_dev
;
3634 /* We don't allow a device to be on several threads */
3636 pkt_dev
= __pktgen_NN_threads(ifname
, FIND
);
3638 printk(KERN_ERR
"pktgen: ERROR: interface already used.\n");
3642 pkt_dev
= kzalloc(sizeof(struct pktgen_dev
), GFP_KERNEL
);
3646 pkt_dev
->flows
= vmalloc(MAX_CFLOWS
* sizeof(struct flow_state
));
3647 if (pkt_dev
->flows
== NULL
) {
3651 memset(pkt_dev
->flows
, 0, MAX_CFLOWS
* sizeof(struct flow_state
));
3653 pkt_dev
->removal_mark
= 0;
3654 pkt_dev
->min_pkt_size
= ETH_ZLEN
;
3655 pkt_dev
->max_pkt_size
= ETH_ZLEN
;
3656 pkt_dev
->nfrags
= 0;
3657 pkt_dev
->clone_skb
= pg_clone_skb_d
;
3658 pkt_dev
->delay_us
= pg_delay_d
/ 1000;
3659 pkt_dev
->delay_ns
= pg_delay_d
% 1000;
3660 pkt_dev
->count
= pg_count_d
;
3662 pkt_dev
->udp_src_min
= 9; /* sink port */
3663 pkt_dev
->udp_src_max
= 9;
3664 pkt_dev
->udp_dst_min
= 9;
3665 pkt_dev
->udp_dst_max
= 9;
3667 pkt_dev
->vlan_p
= 0;
3668 pkt_dev
->vlan_cfi
= 0;
3669 pkt_dev
->vlan_id
= 0xffff;
3670 pkt_dev
->svlan_p
= 0;
3671 pkt_dev
->svlan_cfi
= 0;
3672 pkt_dev
->svlan_id
= 0xffff;
3674 err
= pktgen_setup_dev(pkt_dev
, ifname
);
3678 pkt_dev
->entry
= proc_create_data(ifname
, 0600, pg_proc_dir
,
3679 &pktgen_if_fops
, pkt_dev
);
3680 if (!pkt_dev
->entry
) {
3681 printk(KERN_ERR
"pktgen: cannot create %s/%s procfs entry.\n",
3682 PG_PROC_DIR
, ifname
);
3687 pkt_dev
->ipsmode
= XFRM_MODE_TRANSPORT
;
3688 pkt_dev
->ipsproto
= IPPROTO_ESP
;
3691 return add_dev_to_thread(t
, pkt_dev
);
3693 dev_put(pkt_dev
->odev
);
3699 vfree(pkt_dev
->flows
);
3704 static int __init
pktgen_create_thread(int cpu
)
3706 struct pktgen_thread
*t
;
3707 struct proc_dir_entry
*pe
;
3708 struct task_struct
*p
;
3710 t
= kzalloc(sizeof(struct pktgen_thread
), GFP_KERNEL
);
3712 printk(KERN_ERR
"pktgen: ERROR: out of memory, can't "
3713 "create new thread.\n");
3717 spin_lock_init(&t
->if_lock
);
3720 INIT_LIST_HEAD(&t
->if_list
);
3722 list_add_tail(&t
->th_list
, &pktgen_threads
);
3723 init_completion(&t
->start_done
);
3725 p
= kthread_create(pktgen_thread_worker
, t
, "kpktgend_%d", cpu
);
3727 printk(KERN_ERR
"pktgen: kernel_thread() failed "
3728 "for cpu %d\n", t
->cpu
);
3729 list_del(&t
->th_list
);
3733 kthread_bind(p
, cpu
);
3736 pe
= proc_create_data(t
->tsk
->comm
, 0600, pg_proc_dir
,
3737 &pktgen_thread_fops
, t
);
3739 printk(KERN_ERR
"pktgen: cannot create %s/%s procfs entry.\n",
3740 PG_PROC_DIR
, t
->tsk
->comm
);
3742 list_del(&t
->th_list
);
3748 wait_for_completion(&t
->start_done
);
3754 * Removes a device from the thread if_list.
3756 static void _rem_dev_from_if_list(struct pktgen_thread
*t
,
3757 struct pktgen_dev
*pkt_dev
)
3759 struct list_head
*q
, *n
;
3760 struct pktgen_dev
*p
;
3762 list_for_each_safe(q
, n
, &t
->if_list
) {
3763 p
= list_entry(q
, struct pktgen_dev
, list
);
3769 static int pktgen_remove_device(struct pktgen_thread
*t
,
3770 struct pktgen_dev
*pkt_dev
)
3773 pr_debug("pktgen: remove_device pkt_dev=%p\n", pkt_dev
);
3775 if (pkt_dev
->running
) {
3776 printk(KERN_WARNING
"pktgen: WARNING: trying to remove a "
3777 "running interface, stopping it now.\n");
3778 pktgen_stop_device(pkt_dev
);
3781 /* Dis-associate from the interface */
3783 if (pkt_dev
->odev
) {
3784 dev_put(pkt_dev
->odev
);
3785 pkt_dev
->odev
= NULL
;
3788 /* And update the thread if_list */
3790 _rem_dev_from_if_list(t
, pkt_dev
);
3793 remove_proc_entry(pkt_dev
->entry
->name
, pg_proc_dir
);
3799 vfree(pkt_dev
->flows
);
3804 static int __init
pg_init(void)
3807 struct proc_dir_entry
*pe
;
3809 printk(KERN_INFO
"%s", version
);
3811 pg_proc_dir
= proc_mkdir(PG_PROC_DIR
, init_net
.proc_net
);
3814 pg_proc_dir
->owner
= THIS_MODULE
;
3816 pe
= proc_create(PGCTRL
, 0600, pg_proc_dir
, &pktgen_fops
);
3818 printk(KERN_ERR
"pktgen: ERROR: cannot create %s "
3819 "procfs entry.\n", PGCTRL
);
3820 proc_net_remove(&init_net
, PG_PROC_DIR
);
3824 /* Register us to receive netdevice events */
3825 register_netdevice_notifier(&pktgen_notifier_block
);
3827 for_each_online_cpu(cpu
) {
3830 err
= pktgen_create_thread(cpu
);
3832 printk(KERN_WARNING
"pktgen: WARNING: Cannot create "
3833 "thread for cpu %d (%d)\n", cpu
, err
);
3836 if (list_empty(&pktgen_threads
)) {
3837 printk(KERN_ERR
"pktgen: ERROR: Initialization failed for "
3839 unregister_netdevice_notifier(&pktgen_notifier_block
);
3840 remove_proc_entry(PGCTRL
, pg_proc_dir
);
3841 proc_net_remove(&init_net
, PG_PROC_DIR
);
3848 static void __exit
pg_cleanup(void)
3850 struct pktgen_thread
*t
;
3851 struct list_head
*q
, *n
;
3852 wait_queue_head_t queue
;
3853 init_waitqueue_head(&queue
);
3855 /* Stop all interfaces & threads */
3857 list_for_each_safe(q
, n
, &pktgen_threads
) {
3858 t
= list_entry(q
, struct pktgen_thread
, th_list
);
3859 kthread_stop(t
->tsk
);
3863 /* Un-register us from receiving netdevice events */
3864 unregister_netdevice_notifier(&pktgen_notifier_block
);
3866 /* Clean up proc file system */
3867 remove_proc_entry(PGCTRL
, pg_proc_dir
);
3868 proc_net_remove(&init_net
, PG_PROC_DIR
);
3871 module_init(pg_init
);
3872 module_exit(pg_cleanup
);
3874 MODULE_AUTHOR("Robert Olsson <robert.olsson@its.uu.se");
3875 MODULE_DESCRIPTION("Packet Generator tool");
3876 MODULE_LICENSE("GPL");
3877 module_param(pg_count_d
, int, 0);
3878 module_param(pg_delay_d
, int, 0);
3879 module_param(pg_clone_skb_d
, int, 0);
3880 module_param(debug
, int, 0);