aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuiz Capitulino <lcapitulino@mandriva.com.br>2006-03-21 01:16:13 -0500
committerDavid S. Miller <davem@davemloft.net>2006-03-21 01:16:13 -0500
commit222f18065868b04df92df476b19c99c28740e00f (patch)
tree71d1bc3bcb42928aebfcf1d02d9dcbea961fa732
parent6df9424a9ca35f9fab773d1a0a8919781a367125 (diff)
[PKTGEN]: Lindent run.
Lindet run, with some fixes made by hand. Signed-off-by: Luiz Capitulino <lcapitulino@mandriva.com.br> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/core/pktgen.c2630
1 files changed, 1379 insertions, 1251 deletions
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 6586321b0187..e49b006a7654 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -149,35 +149,34 @@
149#include <asm/io.h> 149#include <asm/io.h>
150#include <asm/dma.h> 150#include <asm/dma.h>
151#include <asm/uaccess.h> 151#include <asm/uaccess.h>
152#include <asm/div64.h> /* do_div */ 152#include <asm/div64.h> /* do_div */
153#include <asm/timex.h> 153#include <asm/timex.h>
154 154
155
156#define VERSION "pktgen v2.64: Packet Generator for packet performance testing.\n" 155#define VERSION "pktgen v2.64: Packet Generator for packet performance testing.\n"
157 156
158/* #define PG_DEBUG(a) a */ 157/* #define PG_DEBUG(a) a */
159#define PG_DEBUG(a) 158#define PG_DEBUG(a)
160 159
161/* The buckets are exponential in 'width' */ 160/* The buckets are exponential in 'width' */
162#define LAT_BUCKETS_MAX 32 161#define LAT_BUCKETS_MAX 32
163#define IP_NAME_SZ 32 162#define IP_NAME_SZ 32
164 163
165/* Device flag bits */ 164/* Device flag bits */
166#define F_IPSRC_RND (1<<0) /* IP-Src Random */ 165#define F_IPSRC_RND (1<<0) /* IP-Src Random */
167#define F_IPDST_RND (1<<1) /* IP-Dst Random */ 166#define F_IPDST_RND (1<<1) /* IP-Dst Random */
168#define F_UDPSRC_RND (1<<2) /* UDP-Src Random */ 167#define F_UDPSRC_RND (1<<2) /* UDP-Src Random */
169#define F_UDPDST_RND (1<<3) /* UDP-Dst Random */ 168#define F_UDPDST_RND (1<<3) /* UDP-Dst Random */
170#define F_MACSRC_RND (1<<4) /* MAC-Src Random */ 169#define F_MACSRC_RND (1<<4) /* MAC-Src Random */
171#define F_MACDST_RND (1<<5) /* MAC-Dst Random */ 170#define F_MACDST_RND (1<<5) /* MAC-Dst Random */
172#define F_TXSIZE_RND (1<<6) /* Transmit size is random */ 171#define F_TXSIZE_RND (1<<6) /* Transmit size is random */
173#define F_IPV6 (1<<7) /* Interface in IPV6 Mode */ 172#define F_IPV6 (1<<7) /* Interface in IPV6 Mode */
174 173
175/* Thread control flag bits */ 174/* Thread control flag bits */
176#define T_TERMINATE (1<<0) 175#define T_TERMINATE (1<<0)
177#define T_STOP (1<<1) /* Stop run */ 176#define T_STOP (1<<1) /* Stop run */
178#define T_RUN (1<<2) /* Start run */ 177#define T_RUN (1<<2) /* Start run */
179#define T_REMDEVALL (1<<3) /* Remove all devs */ 178#define T_REMDEVALL (1<<3) /* Remove all devs */
180#define T_REMDEV (1<<4) /* Remove one dev */ 179#define T_REMDEV (1<<4) /* Remove one dev */
181 180
182/* Locks */ 181/* Locks */
183#define thread_lock() down(&pktgen_sem) 182#define thread_lock() down(&pktgen_sem)
@@ -195,10 +194,9 @@ static struct proc_dir_entry *pg_proc_dir = NULL;
195 194
196#define MAX_CFLOWS 65536 195#define MAX_CFLOWS 65536
197 196
198struct flow_state 197struct flow_state {
199{ 198 __u32 cur_daddr;
200 __u32 cur_daddr; 199 int count;
201 int count;
202}; 200};
203 201
204struct pktgen_dev { 202struct pktgen_dev {
@@ -207,143 +205,143 @@ struct pktgen_dev {
207 * Try to keep frequent/infrequent used vars. separated. 205 * Try to keep frequent/infrequent used vars. separated.
208 */ 206 */
209 207
210 char ifname[IFNAMSIZ]; 208 char ifname[IFNAMSIZ];
211 char result[512]; 209 char result[512];
210
211 struct pktgen_thread *pg_thread; /* the owner */
212 struct pktgen_dev *next; /* Used for chaining in the thread's run-queue */
212 213
213 struct pktgen_thread* pg_thread; /* the owner */ 214 int running; /* if this changes to false, the test will stop */
214 struct pktgen_dev *next; /* Used for chaining in the thread's run-queue */
215 215
216 int running; /* if this changes to false, the test will stop */ 216 /* If min != max, then we will either do a linear iteration, or
217 217 * we will do a random selection from within the range.
218 /* If min != max, then we will either do a linear iteration, or 218 */
219 * we will do a random selection from within the range. 219 __u32 flags;
220 */
221 __u32 flags;
222 int removal_mark; /* non-zero => the device is marked for 220 int removal_mark; /* non-zero => the device is marked for
223 * removal by worker thread */ 221 * removal by worker thread */
224 222
225 int min_pkt_size; /* = ETH_ZLEN; */ 223 int min_pkt_size; /* = ETH_ZLEN; */
226 int max_pkt_size; /* = ETH_ZLEN; */ 224 int max_pkt_size; /* = ETH_ZLEN; */
227 int nfrags; 225 int nfrags;
228 __u32 delay_us; /* Default delay */ 226 __u32 delay_us; /* Default delay */
229 __u32 delay_ns; 227 __u32 delay_ns;
230 __u64 count; /* Default No packets to send */ 228 __u64 count; /* Default No packets to send */
231 __u64 sofar; /* How many pkts we've sent so far */ 229 __u64 sofar; /* How many pkts we've sent so far */
232 __u64 tx_bytes; /* How many bytes we've transmitted */ 230 __u64 tx_bytes; /* How many bytes we've transmitted */
233 __u64 errors; /* Errors when trying to transmit, pkts will be re-sent */ 231 __u64 errors; /* Errors when trying to transmit, pkts will be re-sent */
234 232
235 /* runtime counters relating to clone_skb */ 233 /* runtime counters relating to clone_skb */
236 __u64 next_tx_us; /* timestamp of when to tx next */ 234 __u64 next_tx_us; /* timestamp of when to tx next */
237 __u32 next_tx_ns; 235 __u32 next_tx_ns;
238 236
239 __u64 allocated_skbs; 237 __u64 allocated_skbs;
240 __u32 clone_count; 238 __u32 clone_count;
241 int last_ok; /* Was last skb sent? 239 int last_ok; /* Was last skb sent?
242 * Or a failed transmit of some sort? This will keep 240 * Or a failed transmit of some sort? This will keep
243 * sequence numbers in order, for example. 241 * sequence numbers in order, for example.
244 */ 242 */
245 __u64 started_at; /* micro-seconds */ 243 __u64 started_at; /* micro-seconds */
246 __u64 stopped_at; /* micro-seconds */ 244 __u64 stopped_at; /* micro-seconds */
247 __u64 idle_acc; /* micro-seconds */ 245 __u64 idle_acc; /* micro-seconds */
248 __u32 seq_num; 246 __u32 seq_num;
249 247
250 int clone_skb; /* Use multiple SKBs during packet gen. If this number 248 int clone_skb; /* Use multiple SKBs during packet gen. If this number
251 * is greater than 1, then that many copies of the same 249 * is greater than 1, then that many copies of the same
252 * packet will be sent before a new packet is allocated. 250 * packet will be sent before a new packet is allocated.
253 * For instance, if you want to send 1024 identical packets 251 * For instance, if you want to send 1024 identical packets
254 * before creating a new packet, set clone_skb to 1024. 252 * before creating a new packet, set clone_skb to 1024.
255 */ 253 */
256 254
257 char dst_min[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */ 255 char dst_min[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */
258 char dst_max[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */ 256 char dst_max[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */
259 char src_min[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */ 257 char src_min[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */
260 char src_max[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */ 258 char src_max[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */
261 259
262 struct in6_addr in6_saddr; 260 struct in6_addr in6_saddr;
263 struct in6_addr in6_daddr; 261 struct in6_addr in6_daddr;
264 struct in6_addr cur_in6_daddr; 262 struct in6_addr cur_in6_daddr;
265 struct in6_addr cur_in6_saddr; 263 struct in6_addr cur_in6_saddr;
266 /* For ranges */ 264 /* For ranges */
267 struct in6_addr min_in6_daddr; 265 struct in6_addr min_in6_daddr;
268 struct in6_addr max_in6_daddr; 266 struct in6_addr max_in6_daddr;
269 struct in6_addr min_in6_saddr; 267 struct in6_addr min_in6_saddr;
270 struct in6_addr max_in6_saddr; 268 struct in6_addr max_in6_saddr;
271 269
272 /* If we're doing ranges, random or incremental, then this 270 /* If we're doing ranges, random or incremental, then this
273 * defines the min/max for those ranges. 271 * defines the min/max for those ranges.
274 */ 272 */
275 __u32 saddr_min; /* inclusive, source IP address */ 273 __u32 saddr_min; /* inclusive, source IP address */
276 __u32 saddr_max; /* exclusive, source IP address */ 274 __u32 saddr_max; /* exclusive, source IP address */
277 __u32 daddr_min; /* inclusive, dest IP address */ 275 __u32 daddr_min; /* inclusive, dest IP address */
278 __u32 daddr_max; /* exclusive, dest IP address */ 276 __u32 daddr_max; /* exclusive, dest IP address */
279 277
280 __u16 udp_src_min; /* inclusive, source UDP port */ 278 __u16 udp_src_min; /* inclusive, source UDP port */
281 __u16 udp_src_max; /* exclusive, source UDP port */ 279 __u16 udp_src_max; /* exclusive, source UDP port */
282 __u16 udp_dst_min; /* inclusive, dest UDP port */ 280 __u16 udp_dst_min; /* inclusive, dest UDP port */
283 __u16 udp_dst_max; /* exclusive, dest UDP port */ 281 __u16 udp_dst_max; /* exclusive, dest UDP port */
284 282
285 __u32 src_mac_count; /* How many MACs to iterate through */ 283 __u32 src_mac_count; /* How many MACs to iterate through */
286 __u32 dst_mac_count; /* How many MACs to iterate through */ 284 __u32 dst_mac_count; /* How many MACs to iterate through */
287 285
288 unsigned char dst_mac[ETH_ALEN]; 286 unsigned char dst_mac[ETH_ALEN];
289 unsigned char src_mac[ETH_ALEN]; 287 unsigned char src_mac[ETH_ALEN];
290 288
291 __u32 cur_dst_mac_offset; 289 __u32 cur_dst_mac_offset;
292 __u32 cur_src_mac_offset; 290 __u32 cur_src_mac_offset;
293 __u32 cur_saddr; 291 __u32 cur_saddr;
294 __u32 cur_daddr; 292 __u32 cur_daddr;
295 __u16 cur_udp_dst; 293 __u16 cur_udp_dst;
296 __u16 cur_udp_src; 294 __u16 cur_udp_src;
297 __u32 cur_pkt_size; 295 __u32 cur_pkt_size;
298 296
299 __u8 hh[14]; 297 __u8 hh[14];
300 /* = { 298 /* = {
301 0x00, 0x80, 0xC8, 0x79, 0xB3, 0xCB, 299 0x00, 0x80, 0xC8, 0x79, 0xB3, 0xCB,
302 300
303 We fill in SRC address later 301 We fill in SRC address later
304 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 302 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
305 0x08, 0x00 303 0x08, 0x00
306 }; 304 };
307 */ 305 */
308 __u16 pad; /* pad out the hh struct to an even 16 bytes */ 306 __u16 pad; /* pad out the hh struct to an even 16 bytes */
309 307
310 struct sk_buff* skb; /* skb we are to transmit next, mainly used for when we 308 struct sk_buff *skb; /* skb we are to transmit next, mainly used for when we
311 * are transmitting the same one multiple times 309 * are transmitting the same one multiple times
312 */ 310 */
313 struct net_device* odev; /* The out-going device. Note that the device should 311 struct net_device *odev; /* The out-going device. Note that the device should
314 * have it's pg_info pointer pointing back to this 312 * have it's pg_info pointer pointing back to this
315 * device. This will be set when the user specifies 313 * device. This will be set when the user specifies
316 * the out-going device name (not when the inject is 314 * the out-going device name (not when the inject is
317 * started as it used to do.) 315 * started as it used to do.)
318 */ 316 */
319 struct flow_state *flows; 317 struct flow_state *flows;
320 unsigned cflows; /* Concurrent flows (config) */ 318 unsigned cflows; /* Concurrent flows (config) */
321 unsigned lflow; /* Flow length (config) */ 319 unsigned lflow; /* Flow length (config) */
322 unsigned nflows; /* accumulated flows (stats) */ 320 unsigned nflows; /* accumulated flows (stats) */
323}; 321};
324 322
325struct pktgen_hdr { 323struct pktgen_hdr {
326 __u32 pgh_magic; 324 __u32 pgh_magic;
327 __u32 seq_num; 325 __u32 seq_num;
328 __u32 tv_sec; 326 __u32 tv_sec;
329 __u32 tv_usec; 327 __u32 tv_usec;
330}; 328};
331 329
332struct pktgen_thread { 330struct pktgen_thread {
333 spinlock_t if_lock; 331 spinlock_t if_lock;
334 struct pktgen_dev *if_list; /* All device here */ 332 struct pktgen_dev *if_list; /* All device here */
335 struct pktgen_thread* next; 333 struct pktgen_thread *next;
336 char name[32]; 334 char name[32];
337 char result[512]; 335 char result[512];
338 u32 max_before_softirq; /* We'll call do_softirq to prevent starvation. */ 336 u32 max_before_softirq; /* We'll call do_softirq to prevent starvation. */
339 337
340 /* Field for thread to receive "posted" events terminate, stop ifs etc.*/ 338 /* Field for thread to receive "posted" events terminate, stop ifs etc. */
341 339
342 u32 control; 340 u32 control;
343 int pid; 341 int pid;
344 int cpu; 342 int cpu;
345 343
346 wait_queue_head_t queue; 344 wait_queue_head_t queue;
347}; 345};
348 346
349#define REMOVE 1 347#define REMOVE 1
@@ -367,77 +365,76 @@ struct pktgen_thread {
367 */ 365 */
368static inline s64 divremdi3(s64 x, s64 y, int type) 366static inline s64 divremdi3(s64 x, s64 y, int type)
369{ 367{
370 u64 a = (x < 0) ? -x : x; 368 u64 a = (x < 0) ? -x : x;
371 u64 b = (y < 0) ? -y : y; 369 u64 b = (y < 0) ? -y : y;
372 u64 res = 0, d = 1; 370 u64 res = 0, d = 1;
373 371
374 if (b > 0) { 372 if (b > 0) {
375 while (b < a) { 373 while (b < a) {
376 b <<= 1; 374 b <<= 1;
377 d <<= 1; 375 d <<= 1;
378 } 376 }
379 } 377 }
380 378
381 do { 379 do {
382 if ( a >= b ) { 380 if (a >= b) {
383 a -= b; 381 a -= b;
384 res += d; 382 res += d;
385 } 383 }
386 b >>= 1; 384 b >>= 1;
387 d >>= 1; 385 d >>= 1;
388 } 386 }
389 while (d); 387 while (d);
390 388
391 if (PG_DIV == type) { 389 if (PG_DIV == type) {
392 return (((x ^ y) & (1ll<<63)) == 0) ? res : -(s64)res; 390 return (((x ^ y) & (1ll << 63)) == 0) ? res : -(s64) res;
393 } 391 } else {
394 else { 392 return ((x & (1ll << 63)) == 0) ? a : -(s64) a;
395 return ((x & (1ll<<63)) == 0) ? a : -(s64)a; 393 }
396 }
397} 394}
398 395
399/* End of hacks to deal with 64-bit math on x86 */ 396/* End of hacks to deal with 64-bit math on x86 */
400 397
401/** Convert to milliseconds */ 398/** Convert to milliseconds */
402static inline __u64 tv_to_ms(const struct timeval* tv) 399static inline __u64 tv_to_ms(const struct timeval *tv)
403{ 400{
404 __u64 ms = tv->tv_usec / 1000; 401 __u64 ms = tv->tv_usec / 1000;
405 ms += (__u64)tv->tv_sec * (__u64)1000; 402 ms += (__u64) tv->tv_sec * (__u64) 1000;
406 return ms; 403 return ms;
407} 404}
408 405
409
410/** Convert to micro-seconds */ 406/** Convert to micro-seconds */
411static inline __u64 tv_to_us(const struct timeval* tv) 407static inline __u64 tv_to_us(const struct timeval *tv)
412{ 408{
413 __u64 us = tv->tv_usec; 409 __u64 us = tv->tv_usec;
414 us += (__u64)tv->tv_sec * (__u64)1000000; 410 us += (__u64) tv->tv_sec * (__u64) 1000000;
415 return us; 411 return us;
416} 412}
417 413
418static inline __u64 pg_div(__u64 n, __u32 base) { 414static inline __u64 pg_div(__u64 n, __u32 base)
419 __u64 tmp = n; 415{
420 do_div(tmp, base); 416 __u64 tmp = n;
421 /* printk("pktgen: pg_div, n: %llu base: %d rv: %llu\n", 417 do_div(tmp, base);
422 n, base, tmp); */ 418 /* printk("pktgen: pg_div, n: %llu base: %d rv: %llu\n",
423 return tmp; 419 n, base, tmp); */
420 return tmp;
424} 421}
425 422
426static inline __u64 pg_div64(__u64 n, __u64 base) 423static inline __u64 pg_div64(__u64 n, __u64 base)
427{ 424{
428 __u64 tmp = n; 425 __u64 tmp = n;
429/* 426/*
430 * How do we know if the architecture we are running on 427 * How do we know if the architecture we are running on
431 * supports division with 64 bit base? 428 * supports division with 64 bit base?
432 * 429 *
433 */ 430 */
434#if defined(__sparc_v9__) || defined(__powerpc64__) || defined(__alpha__) || defined(__x86_64__) || defined(__ia64__) 431#if defined(__sparc_v9__) || defined(__powerpc64__) || defined(__alpha__) || defined(__x86_64__) || defined(__ia64__)
435 432
436 do_div(tmp, base); 433 do_div(tmp, base);
437#else 434#else
438 tmp = divremdi3(n, base, PG_DIV); 435 tmp = divremdi3(n, base, PG_DIV);
439#endif 436#endif
440 return tmp; 437 return tmp;
441} 438}
442 439
443static inline u32 pktgen_random(void) 440static inline u32 pktgen_random(void)
@@ -451,45 +448,45 @@ static inline u32 pktgen_random(void)
451#endif 448#endif
452} 449}
453 450
454static inline __u64 getCurMs(void) 451static inline __u64 getCurMs(void)
455{ 452{
456 struct timeval tv; 453 struct timeval tv;
457 do_gettimeofday(&tv); 454 do_gettimeofday(&tv);
458 return tv_to_ms(&tv); 455 return tv_to_ms(&tv);
459} 456}
460 457
461static inline __u64 getCurUs(void) 458static inline __u64 getCurUs(void)
462{ 459{
463 struct timeval tv; 460 struct timeval tv;
464 do_gettimeofday(&tv); 461 do_gettimeofday(&tv);
465 return tv_to_us(&tv); 462 return tv_to_us(&tv);
466} 463}
467 464
468static inline __u64 tv_diff(const struct timeval* a, const struct timeval* b) 465static inline __u64 tv_diff(const struct timeval *a, const struct timeval *b)
469{ 466{
470 return tv_to_us(a) - tv_to_us(b); 467 return tv_to_us(a) - tv_to_us(b);
471} 468}
472 469
473
474/* old include end */ 470/* old include end */
475 471
476static char version[] __initdata = VERSION; 472static char version[] __initdata = VERSION;
477 473
478static int pktgen_remove_device(struct pktgen_thread* t, struct pktgen_dev *i); 474static int pktgen_remove_device(struct pktgen_thread *t, struct pktgen_dev *i);
479static int pktgen_add_device(struct pktgen_thread* t, const char* ifname); 475static int pktgen_add_device(struct pktgen_thread *t, const char *ifname);
480static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread* t, const char* ifname); 476static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t,
477 const char *ifname);
481static int pktgen_device_event(struct notifier_block *, unsigned long, void *); 478static int pktgen_device_event(struct notifier_block *, unsigned long, void *);
482static void pktgen_run_all_threads(void); 479static void pktgen_run_all_threads(void);
483static void pktgen_stop_all_threads_ifs(void); 480static void pktgen_stop_all_threads_ifs(void);
484static int pktgen_stop_device(struct pktgen_dev *pkt_dev); 481static int pktgen_stop_device(struct pktgen_dev *pkt_dev);
485static void pktgen_stop(struct pktgen_thread* t); 482static void pktgen_stop(struct pktgen_thread *t);
486static void pktgen_clear_counters(struct pktgen_dev *pkt_dev); 483static void pktgen_clear_counters(struct pktgen_dev *pkt_dev);
487static int pktgen_mark_device(const char* ifname); 484static int pktgen_mark_device(const char *ifname);
488static unsigned int scan_ip6(const char *s,char ip[16]); 485static unsigned int scan_ip6(const char *s, char ip[16]);
489static unsigned int fmt_ip6(char *s,const char ip[16]); 486static unsigned int fmt_ip6(char *s, const char ip[16]);
490 487
491/* Module parameters, defaults. */ 488/* Module parameters, defaults. */
492static int pg_count_d = 1000; /* 1000 pkts by default */ 489static int pg_count_d = 1000; /* 1000 pkts by default */
493static int pg_delay_d; 490static int pg_delay_d;
494static int pg_clone_skb_d; 491static int pg_clone_skb_d;
495static int debug; 492static int debug;
@@ -507,21 +504,21 @@ static struct notifier_block pktgen_notifier_block = {
507 */ 504 */
508 505
509static int pgctrl_show(struct seq_file *seq, void *v) 506static int pgctrl_show(struct seq_file *seq, void *v)
510{ 507{
511 seq_puts(seq, VERSION); 508 seq_puts(seq, VERSION);
512 return 0; 509 return 0;
513} 510}
514 511
515static ssize_t pgctrl_write(struct file* file,const char __user * buf, 512static ssize_t pgctrl_write(struct file *file, const char __user * buf,
516 size_t count, loff_t *ppos) 513 size_t count, loff_t * ppos)
517{ 514{
518 int err = 0; 515 int err = 0;
519 char data[128]; 516 char data[128];
520 517
521 if (!capable(CAP_NET_ADMIN)){ 518 if (!capable(CAP_NET_ADMIN)) {
522 err = -EPERM; 519 err = -EPERM;
523 goto out; 520 goto out;
524 } 521 }
525 522
526 if (count > sizeof(data)) 523 if (count > sizeof(data))
527 count = sizeof(data); 524 count = sizeof(data);
@@ -529,22 +526,22 @@ static ssize_t pgctrl_write(struct file* file,const char __user * buf,
529 if (copy_from_user(data, buf, count)) { 526 if (copy_from_user(data, buf, count)) {
530 err = -EFAULT; 527 err = -EFAULT;
531 goto out; 528 goto out;
532 } 529 }
533 data[count-1] = 0; /* Make string */ 530 data[count - 1] = 0; /* Make string */
534 531
535 if (!strcmp(data, "stop")) 532 if (!strcmp(data, "stop"))
536 pktgen_stop_all_threads_ifs(); 533 pktgen_stop_all_threads_ifs();
537 534
538 else if (!strcmp(data, "start")) 535 else if (!strcmp(data, "start"))
539 pktgen_run_all_threads(); 536 pktgen_run_all_threads();
540 537
541 else 538 else
542 printk("pktgen: Unknown command: %s\n", data); 539 printk("pktgen: Unknown command: %s\n", data);
543 540
544 err = count; 541 err = count;
545 542
546 out: 543out:
547 return err; 544 return err;
548} 545}
549 546
550static int pgctrl_open(struct inode *inode, struct file *file) 547static int pgctrl_open(struct inode *inode, struct file *file)
@@ -553,147 +550,158 @@ static int pgctrl_open(struct inode *inode, struct file *file)
553} 550}
554 551
555static struct file_operations pktgen_fops = { 552static struct file_operations pktgen_fops = {
556 .owner = THIS_MODULE, 553 .owner = THIS_MODULE,
557 .open = pgctrl_open, 554 .open = pgctrl_open,
558 .read = seq_read, 555 .read = seq_read,
559 .llseek = seq_lseek, 556 .llseek = seq_lseek,
560 .write = pgctrl_write, 557 .write = pgctrl_write,
561 .release = single_release, 558 .release = single_release,
562}; 559};
563 560
564static int pktgen_if_show(struct seq_file *seq, void *v) 561static int pktgen_if_show(struct seq_file *seq, void *v)
565{ 562{
566 int i; 563 int i;
567 struct pktgen_dev *pkt_dev = seq->private; 564 struct pktgen_dev *pkt_dev = seq->private;
568 __u64 sa; 565 __u64 sa;
569 __u64 stopped; 566 __u64 stopped;
570 __u64 now = getCurUs(); 567 __u64 now = getCurUs();
571 568
572 seq_printf(seq, "Params: count %llu min_pkt_size: %u max_pkt_size: %u\n", 569 seq_printf(seq,
573 (unsigned long long) pkt_dev->count, 570 "Params: count %llu min_pkt_size: %u max_pkt_size: %u\n",
574 pkt_dev->min_pkt_size, pkt_dev->max_pkt_size); 571 (unsigned long long)pkt_dev->count, pkt_dev->min_pkt_size,
572 pkt_dev->max_pkt_size);
573
574 seq_printf(seq,
575 " frags: %d delay: %u clone_skb: %d ifname: %s\n",
576 pkt_dev->nfrags,
577 1000 * pkt_dev->delay_us + pkt_dev->delay_ns,
578 pkt_dev->clone_skb, pkt_dev->ifname);
579
580 seq_printf(seq, " flows: %u flowlen: %u\n", pkt_dev->cflows,
581 pkt_dev->lflow);
582
583 if (pkt_dev->flags & F_IPV6) {
584 char b1[128], b2[128], b3[128];
585 fmt_ip6(b1, pkt_dev->in6_saddr.s6_addr);
586 fmt_ip6(b2, pkt_dev->min_in6_saddr.s6_addr);
587 fmt_ip6(b3, pkt_dev->max_in6_saddr.s6_addr);
588 seq_printf(seq,
589 " saddr: %s min_saddr: %s max_saddr: %s\n", b1,
590 b2, b3);
591
592 fmt_ip6(b1, pkt_dev->in6_daddr.s6_addr);
593 fmt_ip6(b2, pkt_dev->min_in6_daddr.s6_addr);
594 fmt_ip6(b3, pkt_dev->max_in6_daddr.s6_addr);
595 seq_printf(seq,
596 " daddr: %s min_daddr: %s max_daddr: %s\n", b1,
597 b2, b3);
598
599 } else
600 seq_printf(seq,
601 " dst_min: %s dst_max: %s\n src_min: %s src_max: %s\n",
602 pkt_dev->dst_min, pkt_dev->dst_max, pkt_dev->src_min,
603 pkt_dev->src_max);
575 604
576 seq_printf(seq, " frags: %d delay: %u clone_skb: %d ifname: %s\n", 605 seq_puts(seq, " src_mac: ");
577 pkt_dev->nfrags, 1000*pkt_dev->delay_us+pkt_dev->delay_ns, pkt_dev->clone_skb, pkt_dev->ifname);
578 606
579 seq_printf(seq, " flows: %u flowlen: %u\n", pkt_dev->cflows, pkt_dev->lflow); 607 if (is_zero_ether_addr(pkt_dev->src_mac))
608 for (i = 0; i < 6; i++)
609 seq_printf(seq, "%02X%s", pkt_dev->odev->dev_addr[i],
610 i == 5 ? " " : ":");
611 else
612 for (i = 0; i < 6; i++)
613 seq_printf(seq, "%02X%s", pkt_dev->src_mac[i],
614 i == 5 ? " " : ":");
615
616 seq_printf(seq, "dst_mac: ");
617 for (i = 0; i < 6; i++)
618 seq_printf(seq, "%02X%s", pkt_dev->dst_mac[i],
619 i == 5 ? "\n" : ":");
620
621 seq_printf(seq,
622 " udp_src_min: %d udp_src_max: %d udp_dst_min: %d udp_dst_max: %d\n",
623 pkt_dev->udp_src_min, pkt_dev->udp_src_max,
624 pkt_dev->udp_dst_min, pkt_dev->udp_dst_max);
625
626 seq_printf(seq,
627 " src_mac_count: %d dst_mac_count: %d \n Flags: ",
628 pkt_dev->src_mac_count, pkt_dev->dst_mac_count);
580 629
630 if (pkt_dev->flags & F_IPV6)
631 seq_printf(seq, "IPV6 ");
581 632
582 if(pkt_dev->flags & F_IPV6) { 633 if (pkt_dev->flags & F_IPSRC_RND)
583 char b1[128], b2[128], b3[128]; 634 seq_printf(seq, "IPSRC_RND ");
584 fmt_ip6(b1, pkt_dev->in6_saddr.s6_addr);
585 fmt_ip6(b2, pkt_dev->min_in6_saddr.s6_addr);
586 fmt_ip6(b3, pkt_dev->max_in6_saddr.s6_addr);
587 seq_printf(seq, " saddr: %s min_saddr: %s max_saddr: %s\n", b1, b2, b3);
588 635
589 fmt_ip6(b1, pkt_dev->in6_daddr.s6_addr); 636 if (pkt_dev->flags & F_IPDST_RND)
590 fmt_ip6(b2, pkt_dev->min_in6_daddr.s6_addr); 637 seq_printf(seq, "IPDST_RND ");
591 fmt_ip6(b3, pkt_dev->max_in6_daddr.s6_addr);
592 seq_printf(seq, " daddr: %s min_daddr: %s max_daddr: %s\n", b1, b2, b3);
593 638
594 } 639 if (pkt_dev->flags & F_TXSIZE_RND)
595 else 640 seq_printf(seq, "TXSIZE_RND ");
596 seq_printf(seq," dst_min: %s dst_max: %s\n src_min: %s src_max: %s\n",
597 pkt_dev->dst_min, pkt_dev->dst_max, pkt_dev->src_min, pkt_dev->src_max);
598 641
599 seq_puts(seq, " src_mac: "); 642 if (pkt_dev->flags & F_UDPSRC_RND)
643 seq_printf(seq, "UDPSRC_RND ");
600 644
601 if (is_zero_ether_addr(pkt_dev->src_mac)) 645 if (pkt_dev->flags & F_UDPDST_RND)
602 for (i = 0; i < 6; i++) 646 seq_printf(seq, "UDPDST_RND ");
603 seq_printf(seq, "%02X%s", pkt_dev->odev->dev_addr[i], i == 5 ? " " : ":");
604 else
605 for (i = 0; i < 6; i++)
606 seq_printf(seq, "%02X%s", pkt_dev->src_mac[i], i == 5 ? " " : ":");
607 647
608 seq_printf(seq, "dst_mac: "); 648 if (pkt_dev->flags & F_MACSRC_RND)
609 for (i = 0; i < 6; i++) 649 seq_printf(seq, "MACSRC_RND ");
610 seq_printf(seq, "%02X%s", pkt_dev->dst_mac[i], i == 5 ? "\n" : ":");
611 650
612 seq_printf(seq, " udp_src_min: %d udp_src_max: %d udp_dst_min: %d udp_dst_max: %d\n", 651 if (pkt_dev->flags & F_MACDST_RND)
613 pkt_dev->udp_src_min, pkt_dev->udp_src_max, pkt_dev->udp_dst_min, 652 seq_printf(seq, "MACDST_RND ");
614 pkt_dev->udp_dst_max);
615 653
616 seq_printf(seq, " src_mac_count: %d dst_mac_count: %d \n Flags: ", 654 seq_puts(seq, "\n");
617 pkt_dev->src_mac_count, pkt_dev->dst_mac_count); 655
656 sa = pkt_dev->started_at;
657 stopped = pkt_dev->stopped_at;
658 if (pkt_dev->running)
659 stopped = now; /* not really stopped, more like last-running-at */
618 660
661 seq_printf(seq,
662 "Current:\n pkts-sofar: %llu errors: %llu\n started: %lluus stopped: %lluus idle: %lluus\n",
663 (unsigned long long)pkt_dev->sofar,
664 (unsigned long long)pkt_dev->errors, (unsigned long long)sa,
665 (unsigned long long)stopped,
666 (unsigned long long)pkt_dev->idle_acc);
619 667
620 if (pkt_dev->flags & F_IPV6) 668 seq_printf(seq,
621 seq_printf(seq, "IPV6 "); 669 " seq_num: %d cur_dst_mac_offset: %d cur_src_mac_offset: %d\n",
622
623 if (pkt_dev->flags & F_IPSRC_RND)
624 seq_printf(seq, "IPSRC_RND ");
625
626 if (pkt_dev->flags & F_IPDST_RND)
627 seq_printf(seq, "IPDST_RND ");
628
629 if (pkt_dev->flags & F_TXSIZE_RND)
630 seq_printf(seq, "TXSIZE_RND ");
631
632 if (pkt_dev->flags & F_UDPSRC_RND)
633 seq_printf(seq, "UDPSRC_RND ");
634
635 if (pkt_dev->flags & F_UDPDST_RND)
636 seq_printf(seq, "UDPDST_RND ");
637
638 if (pkt_dev->flags & F_MACSRC_RND)
639 seq_printf(seq, "MACSRC_RND ");
640
641 if (pkt_dev->flags & F_MACDST_RND)
642 seq_printf(seq, "MACDST_RND ");
643
644
645 seq_puts(seq, "\n");
646
647 sa = pkt_dev->started_at;
648 stopped = pkt_dev->stopped_at;
649 if (pkt_dev->running)
650 stopped = now; /* not really stopped, more like last-running-at */
651
652 seq_printf(seq, "Current:\n pkts-sofar: %llu errors: %llu\n started: %lluus stopped: %lluus idle: %lluus\n",
653 (unsigned long long) pkt_dev->sofar,
654 (unsigned long long) pkt_dev->errors,
655 (unsigned long long) sa,
656 (unsigned long long) stopped,
657 (unsigned long long) pkt_dev->idle_acc);
658
659 seq_printf(seq, " seq_num: %d cur_dst_mac_offset: %d cur_src_mac_offset: %d\n",
660 pkt_dev->seq_num, pkt_dev->cur_dst_mac_offset, 670 pkt_dev->seq_num, pkt_dev->cur_dst_mac_offset,
661 pkt_dev->cur_src_mac_offset); 671 pkt_dev->cur_src_mac_offset);
662 672
663 if(pkt_dev->flags & F_IPV6) { 673 if (pkt_dev->flags & F_IPV6) {
664 char b1[128], b2[128]; 674 char b1[128], b2[128];
665 fmt_ip6(b1, pkt_dev->cur_in6_daddr.s6_addr); 675 fmt_ip6(b1, pkt_dev->cur_in6_daddr.s6_addr);
666 fmt_ip6(b2, pkt_dev->cur_in6_saddr.s6_addr); 676 fmt_ip6(b2, pkt_dev->cur_in6_saddr.s6_addr);
667 seq_printf(seq, " cur_saddr: %s cur_daddr: %s\n", b2, b1); 677 seq_printf(seq, " cur_saddr: %s cur_daddr: %s\n", b2, b1);
668 } 678 } else
669 else 679 seq_printf(seq, " cur_saddr: 0x%x cur_daddr: 0x%x\n",
670 seq_printf(seq, " cur_saddr: 0x%x cur_daddr: 0x%x\n",
671 pkt_dev->cur_saddr, pkt_dev->cur_daddr); 680 pkt_dev->cur_saddr, pkt_dev->cur_daddr);
672 681
673 682 seq_printf(seq, " cur_udp_dst: %d cur_udp_src: %d\n",
674 seq_printf(seq, " cur_udp_dst: %d cur_udp_src: %d\n",
675 pkt_dev->cur_udp_dst, pkt_dev->cur_udp_src); 683 pkt_dev->cur_udp_dst, pkt_dev->cur_udp_src);
676 684
677 seq_printf(seq, " flows: %u\n", pkt_dev->nflows); 685 seq_printf(seq, " flows: %u\n", pkt_dev->nflows);
678 686
679 if (pkt_dev->result[0]) 687 if (pkt_dev->result[0])
680 seq_printf(seq, "Result: %s\n", pkt_dev->result); 688 seq_printf(seq, "Result: %s\n", pkt_dev->result);
681 else 689 else
682 seq_printf(seq, "Result: Idle\n"); 690 seq_printf(seq, "Result: Idle\n");
683 691
684 return 0; 692 return 0;
685} 693}
686 694
687 695static int count_trail_chars(const char __user * user_buffer,
688static int count_trail_chars(const char __user *user_buffer, unsigned int maxlen) 696 unsigned int maxlen)
689{ 697{
690 int i; 698 int i;
691 699
692 for (i = 0; i < maxlen; i++) { 700 for (i = 0; i < maxlen; i++) {
693 char c; 701 char c;
694 if (get_user(c, &user_buffer[i])) 702 if (get_user(c, &user_buffer[i]))
695 return -EFAULT; 703 return -EFAULT;
696 switch (c) { 704 switch (c) {
697 case '\"': 705 case '\"':
698 case '\n': 706 case '\n':
699 case '\r': 707 case '\r':
@@ -709,34 +717,34 @@ done:
709 return i; 717 return i;
710} 718}
711 719
712static unsigned long num_arg(const char __user *user_buffer, unsigned long maxlen, 720static unsigned long num_arg(const char __user * user_buffer,
713 unsigned long *num) 721 unsigned long maxlen, unsigned long *num)
714{ 722{
715 int i = 0; 723 int i = 0;
716 *num = 0; 724 *num = 0;
717 725
718 for(; i < maxlen; i++) { 726 for (; i < maxlen; i++) {
719 char c; 727 char c;
720 if (get_user(c, &user_buffer[i])) 728 if (get_user(c, &user_buffer[i]))
721 return -EFAULT; 729 return -EFAULT;
722 if ((c >= '0') && (c <= '9')) { 730 if ((c >= '0') && (c <= '9')) {
723 *num *= 10; 731 *num *= 10;
724 *num += c -'0'; 732 *num += c - '0';
725 } else 733 } else
726 break; 734 break;
727 } 735 }
728 return i; 736 return i;
729} 737}
730 738
731static int strn_len(const char __user *user_buffer, unsigned int maxlen) 739static int strn_len(const char __user * user_buffer, unsigned int maxlen)
732{ 740{
733 int i = 0; 741 int i = 0;
734 742
735 for(; i < maxlen; i++) { 743 for (; i < maxlen; i++) {
736 char c; 744 char c;
737 if (get_user(c, &user_buffer[i])) 745 if (get_user(c, &user_buffer[i]))
738 return -EFAULT; 746 return -EFAULT;
739 switch (c) { 747 switch (c) {
740 case '\"': 748 case '\"':
741 case '\n': 749 case '\n':
742 case '\r': 750 case '\r':
@@ -749,119 +757,133 @@ static int strn_len(const char __user *user_buffer, unsigned int maxlen)
749 }; 757 };
750 } 758 }
751done_str: 759done_str:
752
753 return i; 760 return i;
754} 761}
755 762
756static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer, 763static ssize_t pktgen_if_write(struct file *file,
757 size_t count, loff_t *offset) 764 const char __user * user_buffer, size_t count,
765 loff_t * offset)
758{ 766{
759 struct seq_file *seq = (struct seq_file *) file->private_data; 767 struct seq_file *seq = (struct seq_file *)file->private_data;
760 struct pktgen_dev *pkt_dev = seq->private; 768 struct pktgen_dev *pkt_dev = seq->private;
761 int i = 0, max, len; 769 int i = 0, max, len;
762 char name[16], valstr[32]; 770 char name[16], valstr[32];
763 unsigned long value = 0; 771 unsigned long value = 0;
764 char* pg_result = NULL; 772 char *pg_result = NULL;
765 int tmp = 0; 773 int tmp = 0;
766 char buf[128]; 774 char buf[128];
767 775
768 pg_result = &(pkt_dev->result[0]); 776 pg_result = &(pkt_dev->result[0]);
769 777
770 if (count < 1) { 778 if (count < 1) {
771 printk("pktgen: wrong command format\n"); 779 printk("pktgen: wrong command format\n");
772 return -EINVAL; 780 return -EINVAL;
773 } 781 }
774 782
775 max = count - i; 783 max = count - i;
776 tmp = count_trail_chars(&user_buffer[i], max); 784 tmp = count_trail_chars(&user_buffer[i], max);
777 if (tmp < 0) { 785 if (tmp < 0) {
778 printk("pktgen: illegal format\n"); 786 printk("pktgen: illegal format\n");
779 return tmp; 787 return tmp;
780 } 788 }
781 i += tmp; 789 i += tmp;
782 790
783 /* Read variable name */ 791 /* Read variable name */
784 792
785 len = strn_len(&user_buffer[i], sizeof(name) - 1); 793 len = strn_len(&user_buffer[i], sizeof(name) - 1);
786 if (len < 0) { return len; } 794 if (len < 0) {
795 return len;
796 }
787 memset(name, 0, sizeof(name)); 797 memset(name, 0, sizeof(name));
788 if (copy_from_user(name, &user_buffer[i], len) ) 798 if (copy_from_user(name, &user_buffer[i], len))
789 return -EFAULT; 799 return -EFAULT;
790 i += len; 800 i += len;
791 801
792 max = count -i; 802 max = count - i;
793 len = count_trail_chars(&user_buffer[i], max); 803 len = count_trail_chars(&user_buffer[i], max);
794 if (len < 0) 804 if (len < 0)
795 return len; 805 return len;
796 806
797 i += len; 807 i += len;
798 808
799 if (debug) { 809 if (debug) {
800 char tb[count + 1]; 810 char tb[count + 1];
801 if (copy_from_user(tb, user_buffer, count)) 811 if (copy_from_user(tb, user_buffer, count))
802 return -EFAULT; 812 return -EFAULT;
803 tb[count] = 0; 813 tb[count] = 0;
804 printk("pktgen: %s,%lu buffer -:%s:-\n", name, 814 printk("pktgen: %s,%lu buffer -:%s:-\n", name,
805 (unsigned long) count, tb); 815 (unsigned long)count, tb);
806 } 816 }
807 817
808 if (!strcmp(name, "min_pkt_size")) { 818 if (!strcmp(name, "min_pkt_size")) {
809 len = num_arg(&user_buffer[i], 10, &value); 819 len = num_arg(&user_buffer[i], 10, &value);
810 if (len < 0) { return len; } 820 if (len < 0) {
821 return len;
822 }
811 i += len; 823 i += len;
812 if (value < 14+20+8) 824 if (value < 14 + 20 + 8)
813 value = 14+20+8; 825 value = 14 + 20 + 8;
814 if (value != pkt_dev->min_pkt_size) { 826 if (value != pkt_dev->min_pkt_size) {
815 pkt_dev->min_pkt_size = value; 827 pkt_dev->min_pkt_size = value;
816 pkt_dev->cur_pkt_size = value; 828 pkt_dev->cur_pkt_size = value;
817 } 829 }
818 sprintf(pg_result, "OK: min_pkt_size=%u", pkt_dev->min_pkt_size); 830 sprintf(pg_result, "OK: min_pkt_size=%u",
831 pkt_dev->min_pkt_size);
819 return count; 832 return count;
820 } 833 }
821 834
822 if (!strcmp(name, "max_pkt_size")) { 835 if (!strcmp(name, "max_pkt_size")) {
823 len = num_arg(&user_buffer[i], 10, &value); 836 len = num_arg(&user_buffer[i], 10, &value);
824 if (len < 0) { return len; } 837 if (len < 0) {
838 return len;
839 }
825 i += len; 840 i += len;
826 if (value < 14+20+8) 841 if (value < 14 + 20 + 8)
827 value = 14+20+8; 842 value = 14 + 20 + 8;
828 if (value != pkt_dev->max_pkt_size) { 843 if (value != pkt_dev->max_pkt_size) {
829 pkt_dev->max_pkt_size = value; 844 pkt_dev->max_pkt_size = value;
830 pkt_dev->cur_pkt_size = value; 845 pkt_dev->cur_pkt_size = value;
831 } 846 }
832 sprintf(pg_result, "OK: max_pkt_size=%u", pkt_dev->max_pkt_size); 847 sprintf(pg_result, "OK: max_pkt_size=%u",
848 pkt_dev->max_pkt_size);
833 return count; 849 return count;
834 } 850 }
835 851
836 /* Shortcut for min = max */ 852 /* Shortcut for min = max */
837 853
838 if (!strcmp(name, "pkt_size")) { 854 if (!strcmp(name, "pkt_size")) {
839 len = num_arg(&user_buffer[i], 10, &value); 855 len = num_arg(&user_buffer[i], 10, &value);
840 if (len < 0) { return len; } 856 if (len < 0) {
857 return len;
858 }
841 i += len; 859 i += len;
842 if (value < 14+20+8) 860 if (value < 14 + 20 + 8)
843 value = 14+20+8; 861 value = 14 + 20 + 8;
844 if (value != pkt_dev->min_pkt_size) { 862 if (value != pkt_dev->min_pkt_size) {
845 pkt_dev->min_pkt_size = value; 863 pkt_dev->min_pkt_size = value;
846 pkt_dev->max_pkt_size = value; 864 pkt_dev->max_pkt_size = value;
847 pkt_dev->cur_pkt_size = value; 865 pkt_dev->cur_pkt_size = value;
848 } 866 }
849 sprintf(pg_result, "OK: pkt_size=%u", pkt_dev->min_pkt_size); 867 sprintf(pg_result, "OK: pkt_size=%u", pkt_dev->min_pkt_size);
850 return count; 868 return count;
851 } 869 }
852 870
853 if (!strcmp(name, "debug")) { 871 if (!strcmp(name, "debug")) {
854 len = num_arg(&user_buffer[i], 10, &value); 872 len = num_arg(&user_buffer[i], 10, &value);
855 if (len < 0) { return len; } 873 if (len < 0) {
874 return len;
875 }
856 i += len; 876 i += len;
857 debug = value; 877 debug = value;
858 sprintf(pg_result, "OK: debug=%u", debug); 878 sprintf(pg_result, "OK: debug=%u", debug);
859 return count; 879 return count;
860 } 880 }
861 881
862 if (!strcmp(name, "frags")) { 882 if (!strcmp(name, "frags")) {
863 len = num_arg(&user_buffer[i], 10, &value); 883 len = num_arg(&user_buffer[i], 10, &value);
864 if (len < 0) { return len; } 884 if (len < 0) {
885 return len;
886 }
865 i += len; 887 i += len;
866 pkt_dev->nfrags = value; 888 pkt_dev->nfrags = value;
867 sprintf(pg_result, "OK: frags=%u", pkt_dev->nfrags); 889 sprintf(pg_result, "OK: frags=%u", pkt_dev->nfrags);
@@ -869,7 +891,9 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
869 } 891 }
870 if (!strcmp(name, "delay")) { 892 if (!strcmp(name, "delay")) {
871 len = num_arg(&user_buffer[i], 10, &value); 893 len = num_arg(&user_buffer[i], 10, &value);
872 if (len < 0) { return len; } 894 if (len < 0) {
895 return len;
896 }
873 i += len; 897 i += len;
874 if (value == 0x7FFFFFFF) { 898 if (value == 0x7FFFFFFF) {
875 pkt_dev->delay_us = 0x7FFFFFFF; 899 pkt_dev->delay_us = 0x7FFFFFFF;
@@ -878,308 +902,347 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
878 pkt_dev->delay_us = value / 1000; 902 pkt_dev->delay_us = value / 1000;
879 pkt_dev->delay_ns = value % 1000; 903 pkt_dev->delay_ns = value % 1000;
880 } 904 }
881 sprintf(pg_result, "OK: delay=%u", 1000*pkt_dev->delay_us+pkt_dev->delay_ns); 905 sprintf(pg_result, "OK: delay=%u",
906 1000 * pkt_dev->delay_us + pkt_dev->delay_ns);
882 return count; 907 return count;
883 } 908 }
884 if (!strcmp(name, "udp_src_min")) { 909 if (!strcmp(name, "udp_src_min")) {
885 len = num_arg(&user_buffer[i], 10, &value); 910 len = num_arg(&user_buffer[i], 10, &value);
886 if (len < 0) { return len; } 911 if (len < 0) {
912 return len;
913 }
887 i += len; 914 i += len;
888 if (value != pkt_dev->udp_src_min) { 915 if (value != pkt_dev->udp_src_min) {
889 pkt_dev->udp_src_min = value; 916 pkt_dev->udp_src_min = value;
890 pkt_dev->cur_udp_src = value; 917 pkt_dev->cur_udp_src = value;
891 } 918 }
892 sprintf(pg_result, "OK: udp_src_min=%u", pkt_dev->udp_src_min); 919 sprintf(pg_result, "OK: udp_src_min=%u", pkt_dev->udp_src_min);
893 return count; 920 return count;
894 } 921 }
895 if (!strcmp(name, "udp_dst_min")) { 922 if (!strcmp(name, "udp_dst_min")) {
896 len = num_arg(&user_buffer[i], 10, &value); 923 len = num_arg(&user_buffer[i], 10, &value);
897 if (len < 0) { return len; } 924 if (len < 0) {
925 return len;
926 }
898 i += len; 927 i += len;
899 if (value != pkt_dev->udp_dst_min) { 928 if (value != pkt_dev->udp_dst_min) {
900 pkt_dev->udp_dst_min = value; 929 pkt_dev->udp_dst_min = value;
901 pkt_dev->cur_udp_dst = value; 930 pkt_dev->cur_udp_dst = value;
902 } 931 }
903 sprintf(pg_result, "OK: udp_dst_min=%u", pkt_dev->udp_dst_min); 932 sprintf(pg_result, "OK: udp_dst_min=%u", pkt_dev->udp_dst_min);
904 return count; 933 return count;
905 } 934 }
906 if (!strcmp(name, "udp_src_max")) { 935 if (!strcmp(name, "udp_src_max")) {
907 len = num_arg(&user_buffer[i], 10, &value); 936 len = num_arg(&user_buffer[i], 10, &value);
908 if (len < 0) { return len; } 937 if (len < 0) {
938 return len;
939 }
909 i += len; 940 i += len;
910 if (value != pkt_dev->udp_src_max) { 941 if (value != pkt_dev->udp_src_max) {
911 pkt_dev->udp_src_max = value; 942 pkt_dev->udp_src_max = value;
912 pkt_dev->cur_udp_src = value; 943 pkt_dev->cur_udp_src = value;
913 } 944 }
914 sprintf(pg_result, "OK: udp_src_max=%u", pkt_dev->udp_src_max); 945 sprintf(pg_result, "OK: udp_src_max=%u", pkt_dev->udp_src_max);
915 return count; 946 return count;
916 } 947 }
917 if (!strcmp(name, "udp_dst_max")) { 948 if (!strcmp(name, "udp_dst_max")) {
918 len = num_arg(&user_buffer[i], 10, &value); 949 len = num_arg(&user_buffer[i], 10, &value);
919 if (len < 0) { return len; } 950 if (len < 0) {
951 return len;
952 }
920 i += len; 953 i += len;
921 if (value != pkt_dev->udp_dst_max) { 954 if (value != pkt_dev->udp_dst_max) {
922 pkt_dev->udp_dst_max = value; 955 pkt_dev->udp_dst_max = value;
923 pkt_dev->cur_udp_dst = value; 956 pkt_dev->cur_udp_dst = value;
924 } 957 }
925 sprintf(pg_result, "OK: udp_dst_max=%u", pkt_dev->udp_dst_max); 958 sprintf(pg_result, "OK: udp_dst_max=%u", pkt_dev->udp_dst_max);
926 return count; 959 return count;
927 } 960 }
928 if (!strcmp(name, "clone_skb")) { 961 if (!strcmp(name, "clone_skb")) {
929 len = num_arg(&user_buffer[i], 10, &value); 962 len = num_arg(&user_buffer[i], 10, &value);
930 if (len < 0) { return len; } 963 if (len < 0) {
964 return len;
965 }
931 i += len; 966 i += len;
932 pkt_dev->clone_skb = value; 967 pkt_dev->clone_skb = value;
933 968
934 sprintf(pg_result, "OK: clone_skb=%d", pkt_dev->clone_skb); 969 sprintf(pg_result, "OK: clone_skb=%d", pkt_dev->clone_skb);
935 return count; 970 return count;
936 } 971 }
937 if (!strcmp(name, "count")) { 972 if (!strcmp(name, "count")) {
938 len = num_arg(&user_buffer[i], 10, &value); 973 len = num_arg(&user_buffer[i], 10, &value);
939 if (len < 0) { return len; } 974 if (len < 0) {
975 return len;
976 }
940 i += len; 977 i += len;
941 pkt_dev->count = value; 978 pkt_dev->count = value;
942 sprintf(pg_result, "OK: count=%llu", 979 sprintf(pg_result, "OK: count=%llu",
943 (unsigned long long) pkt_dev->count); 980 (unsigned long long)pkt_dev->count);
944 return count; 981 return count;
945 } 982 }
946 if (!strcmp(name, "src_mac_count")) { 983 if (!strcmp(name, "src_mac_count")) {
947 len = num_arg(&user_buffer[i], 10, &value); 984 len = num_arg(&user_buffer[i], 10, &value);
948 if (len < 0) { return len; } 985 if (len < 0) {
986 return len;
987 }
949 i += len; 988 i += len;
950 if (pkt_dev->src_mac_count != value) { 989 if (pkt_dev->src_mac_count != value) {
951 pkt_dev->src_mac_count = value; 990 pkt_dev->src_mac_count = value;
952 pkt_dev->cur_src_mac_offset = 0; 991 pkt_dev->cur_src_mac_offset = 0;
953 } 992 }
954 sprintf(pg_result, "OK: src_mac_count=%d", pkt_dev->src_mac_count); 993 sprintf(pg_result, "OK: src_mac_count=%d",
994 pkt_dev->src_mac_count);
955 return count; 995 return count;
956 } 996 }
957 if (!strcmp(name, "dst_mac_count")) { 997 if (!strcmp(name, "dst_mac_count")) {
958 len = num_arg(&user_buffer[i], 10, &value); 998 len = num_arg(&user_buffer[i], 10, &value);
959 if (len < 0) { return len; } 999 if (len < 0) {
1000 return len;
1001 }
960 i += len; 1002 i += len;
961 if (pkt_dev->dst_mac_count != value) { 1003 if (pkt_dev->dst_mac_count != value) {
962 pkt_dev->dst_mac_count = value; 1004 pkt_dev->dst_mac_count = value;
963 pkt_dev->cur_dst_mac_offset = 0; 1005 pkt_dev->cur_dst_mac_offset = 0;
964 } 1006 }
965 sprintf(pg_result, "OK: dst_mac_count=%d", pkt_dev->dst_mac_count); 1007 sprintf(pg_result, "OK: dst_mac_count=%d",
1008 pkt_dev->dst_mac_count);
966 return count; 1009 return count;
967 } 1010 }
968 if (!strcmp(name, "flag")) { 1011 if (!strcmp(name, "flag")) {
969 char f[32]; 1012 char f[32];
970 memset(f, 0, 32); 1013 memset(f, 0, 32);
971 len = strn_len(&user_buffer[i], sizeof(f) - 1); 1014 len = strn_len(&user_buffer[i], sizeof(f) - 1);
972 if (len < 0) { return len; } 1015 if (len < 0) {
1016 return len;
1017 }
973 if (copy_from_user(f, &user_buffer[i], len)) 1018 if (copy_from_user(f, &user_buffer[i], len))
974 return -EFAULT; 1019 return -EFAULT;
975 i += len; 1020 i += len;
976 if (strcmp(f, "IPSRC_RND") == 0) 1021 if (strcmp(f, "IPSRC_RND") == 0)
977 pkt_dev->flags |= F_IPSRC_RND; 1022 pkt_dev->flags |= F_IPSRC_RND;
978 1023
979 else if (strcmp(f, "!IPSRC_RND") == 0) 1024 else if (strcmp(f, "!IPSRC_RND") == 0)
980 pkt_dev->flags &= ~F_IPSRC_RND; 1025 pkt_dev->flags &= ~F_IPSRC_RND;
981 1026
982 else if (strcmp(f, "TXSIZE_RND") == 0) 1027 else if (strcmp(f, "TXSIZE_RND") == 0)
983 pkt_dev->flags |= F_TXSIZE_RND; 1028 pkt_dev->flags |= F_TXSIZE_RND;
984 1029
985 else if (strcmp(f, "!TXSIZE_RND") == 0) 1030 else if (strcmp(f, "!TXSIZE_RND") == 0)
986 pkt_dev->flags &= ~F_TXSIZE_RND; 1031 pkt_dev->flags &= ~F_TXSIZE_RND;
987 1032
988 else if (strcmp(f, "IPDST_RND") == 0) 1033 else if (strcmp(f, "IPDST_RND") == 0)
989 pkt_dev->flags |= F_IPDST_RND; 1034 pkt_dev->flags |= F_IPDST_RND;
990 1035
991 else if (strcmp(f, "!IPDST_RND") == 0) 1036 else if (strcmp(f, "!IPDST_RND") == 0)
992 pkt_dev->flags &= ~F_IPDST_RND; 1037 pkt_dev->flags &= ~F_IPDST_RND;
993 1038
994 else if (strcmp(f, "UDPSRC_RND") == 0) 1039 else if (strcmp(f, "UDPSRC_RND") == 0)
995 pkt_dev->flags |= F_UDPSRC_RND; 1040 pkt_dev->flags |= F_UDPSRC_RND;
996 1041
997 else if (strcmp(f, "!UDPSRC_RND") == 0) 1042 else if (strcmp(f, "!UDPSRC_RND") == 0)
998 pkt_dev->flags &= ~F_UDPSRC_RND; 1043 pkt_dev->flags &= ~F_UDPSRC_RND;
999 1044
1000 else if (strcmp(f, "UDPDST_RND") == 0) 1045 else if (strcmp(f, "UDPDST_RND") == 0)
1001 pkt_dev->flags |= F_UDPDST_RND; 1046 pkt_dev->flags |= F_UDPDST_RND;
1002 1047
1003 else if (strcmp(f, "!UDPDST_RND") == 0) 1048 else if (strcmp(f, "!UDPDST_RND") == 0)
1004 pkt_dev->flags &= ~F_UDPDST_RND; 1049 pkt_dev->flags &= ~F_UDPDST_RND;
1005 1050
1006 else if (strcmp(f, "MACSRC_RND") == 0) 1051 else if (strcmp(f, "MACSRC_RND") == 0)
1007 pkt_dev->flags |= F_MACSRC_RND; 1052 pkt_dev->flags |= F_MACSRC_RND;
1008 1053
1009 else if (strcmp(f, "!MACSRC_RND") == 0) 1054 else if (strcmp(f, "!MACSRC_RND") == 0)
1010 pkt_dev->flags &= ~F_MACSRC_RND; 1055 pkt_dev->flags &= ~F_MACSRC_RND;
1011 1056
1012 else if (strcmp(f, "MACDST_RND") == 0) 1057 else if (strcmp(f, "MACDST_RND") == 0)
1013 pkt_dev->flags |= F_MACDST_RND; 1058 pkt_dev->flags |= F_MACDST_RND;
1014 1059
1015 else if (strcmp(f, "!MACDST_RND") == 0) 1060 else if (strcmp(f, "!MACDST_RND") == 0)
1016 pkt_dev->flags &= ~F_MACDST_RND; 1061 pkt_dev->flags &= ~F_MACDST_RND;
1017 1062
1018 else { 1063 else {
1019 sprintf(pg_result, "Flag -:%s:- unknown\nAvailable flags, (prepend ! to un-set flag):\n%s", 1064 sprintf(pg_result,
1020 f, 1065 "Flag -:%s:- unknown\nAvailable flags, (prepend ! to un-set flag):\n%s",
1021 "IPSRC_RND, IPDST_RND, TXSIZE_RND, UDPSRC_RND, UDPDST_RND, MACSRC_RND, MACDST_RND\n"); 1066 f,
1022 return count; 1067 "IPSRC_RND, IPDST_RND, TXSIZE_RND, UDPSRC_RND, UDPDST_RND, MACSRC_RND, MACDST_RND\n");
1023 } 1068 return count;
1069 }
1024 sprintf(pg_result, "OK: flags=0x%x", pkt_dev->flags); 1070 sprintf(pg_result, "OK: flags=0x%x", pkt_dev->flags);
1025 return count; 1071 return count;
1026 } 1072 }
1027 if (!strcmp(name, "dst_min") || !strcmp(name, "dst")) { 1073 if (!strcmp(name, "dst_min") || !strcmp(name, "dst")) {
1028 len = strn_len(&user_buffer[i], sizeof(pkt_dev->dst_min) - 1); 1074 len = strn_len(&user_buffer[i], sizeof(pkt_dev->dst_min) - 1);
1029 if (len < 0) { return len; } 1075 if (len < 0) {
1076 return len;
1077 }
1030 1078
1031 if (copy_from_user(buf, &user_buffer[i], len)) 1079 if (copy_from_user(buf, &user_buffer[i], len))
1032 return -EFAULT; 1080 return -EFAULT;
1033 buf[len] = 0; 1081 buf[len] = 0;
1034 if (strcmp(buf, pkt_dev->dst_min) != 0) { 1082 if (strcmp(buf, pkt_dev->dst_min) != 0) {
1035 memset(pkt_dev->dst_min, 0, sizeof(pkt_dev->dst_min)); 1083 memset(pkt_dev->dst_min, 0, sizeof(pkt_dev->dst_min));
1036 strncpy(pkt_dev->dst_min, buf, len); 1084 strncpy(pkt_dev->dst_min, buf, len);
1037 pkt_dev->daddr_min = in_aton(pkt_dev->dst_min); 1085 pkt_dev->daddr_min = in_aton(pkt_dev->dst_min);
1038 pkt_dev->cur_daddr = pkt_dev->daddr_min; 1086 pkt_dev->cur_daddr = pkt_dev->daddr_min;
1039 } 1087 }
1040 if(debug) 1088 if (debug)
1041 printk("pktgen: dst_min set to: %s\n", pkt_dev->dst_min); 1089 printk("pktgen: dst_min set to: %s\n",
1042 i += len; 1090 pkt_dev->dst_min);
1091 i += len;
1043 sprintf(pg_result, "OK: dst_min=%s", pkt_dev->dst_min); 1092 sprintf(pg_result, "OK: dst_min=%s", pkt_dev->dst_min);
1044 return count; 1093 return count;
1045 } 1094 }
1046 if (!strcmp(name, "dst_max")) { 1095 if (!strcmp(name, "dst_max")) {
1047 len = strn_len(&user_buffer[i], sizeof(pkt_dev->dst_max) - 1); 1096 len = strn_len(&user_buffer[i], sizeof(pkt_dev->dst_max) - 1);
1048 if (len < 0) { return len; } 1097 if (len < 0) {
1098 return len;
1099 }
1049 1100
1050 if (copy_from_user(buf, &user_buffer[i], len)) 1101 if (copy_from_user(buf, &user_buffer[i], len))
1051 return -EFAULT; 1102 return -EFAULT;
1052 1103
1053 buf[len] = 0; 1104 buf[len] = 0;
1054 if (strcmp(buf, pkt_dev->dst_max) != 0) { 1105 if (strcmp(buf, pkt_dev->dst_max) != 0) {
1055 memset(pkt_dev->dst_max, 0, sizeof(pkt_dev->dst_max)); 1106 memset(pkt_dev->dst_max, 0, sizeof(pkt_dev->dst_max));
1056 strncpy(pkt_dev->dst_max, buf, len); 1107 strncpy(pkt_dev->dst_max, buf, len);
1057 pkt_dev->daddr_max = in_aton(pkt_dev->dst_max); 1108 pkt_dev->daddr_max = in_aton(pkt_dev->dst_max);
1058 pkt_dev->cur_daddr = pkt_dev->daddr_max; 1109 pkt_dev->cur_daddr = pkt_dev->daddr_max;
1059 } 1110 }
1060 if(debug) 1111 if (debug)
1061 printk("pktgen: dst_max set to: %s\n", pkt_dev->dst_max); 1112 printk("pktgen: dst_max set to: %s\n",
1113 pkt_dev->dst_max);
1062 i += len; 1114 i += len;
1063 sprintf(pg_result, "OK: dst_max=%s", pkt_dev->dst_max); 1115 sprintf(pg_result, "OK: dst_max=%s", pkt_dev->dst_max);
1064 return count; 1116 return count;
1065 } 1117 }
1066 if (!strcmp(name, "dst6")) { 1118 if (!strcmp(name, "dst6")) {
1067 len = strn_len(&user_buffer[i], sizeof(buf) - 1); 1119 len = strn_len(&user_buffer[i], sizeof(buf) - 1);
1068 if (len < 0) return len; 1120 if (len < 0)
1121 return len;
1069 1122
1070 pkt_dev->flags |= F_IPV6; 1123 pkt_dev->flags |= F_IPV6;
1071 1124
1072 if (copy_from_user(buf, &user_buffer[i], len)) 1125 if (copy_from_user(buf, &user_buffer[i], len))
1073 return -EFAULT; 1126 return -EFAULT;
1074 buf[len] = 0; 1127 buf[len] = 0;
1075 1128
1076 scan_ip6(buf, pkt_dev->in6_daddr.s6_addr); 1129 scan_ip6(buf, pkt_dev->in6_daddr.s6_addr);
1077 fmt_ip6(buf, pkt_dev->in6_daddr.s6_addr); 1130 fmt_ip6(buf, pkt_dev->in6_daddr.s6_addr);
1078 1131
1079 ipv6_addr_copy(&pkt_dev->cur_in6_daddr, &pkt_dev->in6_daddr); 1132 ipv6_addr_copy(&pkt_dev->cur_in6_daddr, &pkt_dev->in6_daddr);
1080 1133
1081 if(debug) 1134 if (debug)
1082 printk("pktgen: dst6 set to: %s\n", buf); 1135 printk("pktgen: dst6 set to: %s\n", buf);
1083 1136
1084 i += len; 1137 i += len;
1085 sprintf(pg_result, "OK: dst6=%s", buf); 1138 sprintf(pg_result, "OK: dst6=%s", buf);
1086 return count; 1139 return count;
1087 } 1140 }
1088 if (!strcmp(name, "dst6_min")) { 1141 if (!strcmp(name, "dst6_min")) {
1089 len = strn_len(&user_buffer[i], sizeof(buf) - 1); 1142 len = strn_len(&user_buffer[i], sizeof(buf) - 1);
1090 if (len < 0) return len; 1143 if (len < 0)
1144 return len;
1091 1145
1092 pkt_dev->flags |= F_IPV6; 1146 pkt_dev->flags |= F_IPV6;
1093 1147
1094 if (copy_from_user(buf, &user_buffer[i], len)) 1148 if (copy_from_user(buf, &user_buffer[i], len))
1095 return -EFAULT; 1149 return -EFAULT;
1096 buf[len] = 0; 1150 buf[len] = 0;
1097 1151
1098 scan_ip6(buf, pkt_dev->min_in6_daddr.s6_addr); 1152 scan_ip6(buf, pkt_dev->min_in6_daddr.s6_addr);
1099 fmt_ip6(buf, pkt_dev->min_in6_daddr.s6_addr); 1153 fmt_ip6(buf, pkt_dev->min_in6_daddr.s6_addr);
1100 1154
1101 ipv6_addr_copy(&pkt_dev->cur_in6_daddr, &pkt_dev->min_in6_daddr); 1155 ipv6_addr_copy(&pkt_dev->cur_in6_daddr,
1102 if(debug) 1156 &pkt_dev->min_in6_daddr);
1157 if (debug)
1103 printk("pktgen: dst6_min set to: %s\n", buf); 1158 printk("pktgen: dst6_min set to: %s\n", buf);
1104 1159
1105 i += len; 1160 i += len;
1106 sprintf(pg_result, "OK: dst6_min=%s", buf); 1161 sprintf(pg_result, "OK: dst6_min=%s", buf);
1107 return count; 1162 return count;
1108 } 1163 }
1109 if (!strcmp(name, "dst6_max")) { 1164 if (!strcmp(name, "dst6_max")) {
1110 len = strn_len(&user_buffer[i], sizeof(buf) - 1); 1165 len = strn_len(&user_buffer[i], sizeof(buf) - 1);
1111 if (len < 0) return len; 1166 if (len < 0)
1167 return len;
1112 1168
1113 pkt_dev->flags |= F_IPV6; 1169 pkt_dev->flags |= F_IPV6;
1114 1170
1115 if (copy_from_user(buf, &user_buffer[i], len)) 1171 if (copy_from_user(buf, &user_buffer[i], len))
1116 return -EFAULT; 1172 return -EFAULT;
1117 buf[len] = 0; 1173 buf[len] = 0;
1118 1174
1119 scan_ip6(buf, pkt_dev->max_in6_daddr.s6_addr); 1175 scan_ip6(buf, pkt_dev->max_in6_daddr.s6_addr);
1120 fmt_ip6(buf, pkt_dev->max_in6_daddr.s6_addr); 1176 fmt_ip6(buf, pkt_dev->max_in6_daddr.s6_addr);
1121 1177
1122 if(debug) 1178 if (debug)
1123 printk("pktgen: dst6_max set to: %s\n", buf); 1179 printk("pktgen: dst6_max set to: %s\n", buf);
1124 1180
1125 i += len; 1181 i += len;
1126 sprintf(pg_result, "OK: dst6_max=%s", buf); 1182 sprintf(pg_result, "OK: dst6_max=%s", buf);
1127 return count; 1183 return count;
1128 } 1184 }
1129 if (!strcmp(name, "src6")) { 1185 if (!strcmp(name, "src6")) {
1130 len = strn_len(&user_buffer[i], sizeof(buf) - 1); 1186 len = strn_len(&user_buffer[i], sizeof(buf) - 1);
1131 if (len < 0) return len; 1187 if (len < 0)
1188 return len;
1132 1189
1133 pkt_dev->flags |= F_IPV6; 1190 pkt_dev->flags |= F_IPV6;
1134 1191
1135 if (copy_from_user(buf, &user_buffer[i], len)) 1192 if (copy_from_user(buf, &user_buffer[i], len))
1136 return -EFAULT; 1193 return -EFAULT;
1137 buf[len] = 0; 1194 buf[len] = 0;
1138 1195
1139 scan_ip6(buf, pkt_dev->in6_saddr.s6_addr); 1196 scan_ip6(buf, pkt_dev->in6_saddr.s6_addr);
1140 fmt_ip6(buf, pkt_dev->in6_saddr.s6_addr); 1197 fmt_ip6(buf, pkt_dev->in6_saddr.s6_addr);
1141 1198
1142 ipv6_addr_copy(&pkt_dev->cur_in6_saddr, &pkt_dev->in6_saddr); 1199 ipv6_addr_copy(&pkt_dev->cur_in6_saddr, &pkt_dev->in6_saddr);
1143 1200
1144 if(debug) 1201 if (debug)
1145 printk("pktgen: src6 set to: %s\n", buf); 1202 printk("pktgen: src6 set to: %s\n", buf);
1146 1203
1147 i += len; 1204 i += len;
1148 sprintf(pg_result, "OK: src6=%s", buf); 1205 sprintf(pg_result, "OK: src6=%s", buf);
1149 return count; 1206 return count;
1150 } 1207 }
1151 if (!strcmp(name, "src_min")) { 1208 if (!strcmp(name, "src_min")) {
1152 len = strn_len(&user_buffer[i], sizeof(pkt_dev->src_min) - 1); 1209 len = strn_len(&user_buffer[i], sizeof(pkt_dev->src_min) - 1);
1153 if (len < 0) { return len; } 1210 if (len < 0) {
1154 if (copy_from_user(buf, &user_buffer[i], len)) 1211 return len;
1212 }
1213 if (copy_from_user(buf, &user_buffer[i], len))
1155 return -EFAULT; 1214 return -EFAULT;
1156 buf[len] = 0; 1215 buf[len] = 0;
1157 if (strcmp(buf, pkt_dev->src_min) != 0) { 1216 if (strcmp(buf, pkt_dev->src_min) != 0) {
1158 memset(pkt_dev->src_min, 0, sizeof(pkt_dev->src_min)); 1217 memset(pkt_dev->src_min, 0, sizeof(pkt_dev->src_min));
1159 strncpy(pkt_dev->src_min, buf, len); 1218 strncpy(pkt_dev->src_min, buf, len);
1160 pkt_dev->saddr_min = in_aton(pkt_dev->src_min); 1219 pkt_dev->saddr_min = in_aton(pkt_dev->src_min);
1161 pkt_dev->cur_saddr = pkt_dev->saddr_min; 1220 pkt_dev->cur_saddr = pkt_dev->saddr_min;
1162 } 1221 }
1163 if(debug) 1222 if (debug)
1164 printk("pktgen: src_min set to: %s\n", pkt_dev->src_min); 1223 printk("pktgen: src_min set to: %s\n",
1224 pkt_dev->src_min);
1165 i += len; 1225 i += len;
1166 sprintf(pg_result, "OK: src_min=%s", pkt_dev->src_min); 1226 sprintf(pg_result, "OK: src_min=%s", pkt_dev->src_min);
1167 return count; 1227 return count;
1168 } 1228 }
1169 if (!strcmp(name, "src_max")) { 1229 if (!strcmp(name, "src_max")) {
1170 len = strn_len(&user_buffer[i], sizeof(pkt_dev->src_max) - 1); 1230 len = strn_len(&user_buffer[i], sizeof(pkt_dev->src_max) - 1);
1171 if (len < 0) { return len; } 1231 if (len < 0) {
1172 if (copy_from_user(buf, &user_buffer[i], len)) 1232 return len;
1233 }
1234 if (copy_from_user(buf, &user_buffer[i], len))
1173 return -EFAULT; 1235 return -EFAULT;
1174 buf[len] = 0; 1236 buf[len] = 0;
1175 if (strcmp(buf, pkt_dev->src_max) != 0) { 1237 if (strcmp(buf, pkt_dev->src_max) != 0) {
1176 memset(pkt_dev->src_max, 0, sizeof(pkt_dev->src_max)); 1238 memset(pkt_dev->src_max, 0, sizeof(pkt_dev->src_max));
1177 strncpy(pkt_dev->src_max, buf, len); 1239 strncpy(pkt_dev->src_max, buf, len);
1178 pkt_dev->saddr_max = in_aton(pkt_dev->src_max); 1240 pkt_dev->saddr_max = in_aton(pkt_dev->src_max);
1179 pkt_dev->cur_saddr = pkt_dev->saddr_max; 1241 pkt_dev->cur_saddr = pkt_dev->saddr_max;
1180 } 1242 }
1181 if(debug) 1243 if (debug)
1182 printk("pktgen: src_max set to: %s\n", pkt_dev->src_max); 1244 printk("pktgen: src_max set to: %s\n",
1245 pkt_dev->src_max);
1183 i += len; 1246 i += len;
1184 sprintf(pg_result, "OK: src_max=%s", pkt_dev->src_max); 1247 sprintf(pg_result, "OK: src_max=%s", pkt_dev->src_max);
1185 return count; 1248 return count;
@@ -1189,15 +1252,17 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
1189 unsigned char old_dmac[ETH_ALEN]; 1252 unsigned char old_dmac[ETH_ALEN];
1190 unsigned char *m = pkt_dev->dst_mac; 1253 unsigned char *m = pkt_dev->dst_mac;
1191 memcpy(old_dmac, pkt_dev->dst_mac, ETH_ALEN); 1254 memcpy(old_dmac, pkt_dev->dst_mac, ETH_ALEN);
1192 1255
1193 len = strn_len(&user_buffer[i], sizeof(valstr) - 1); 1256 len = strn_len(&user_buffer[i], sizeof(valstr) - 1);
1194 if (len < 0) { return len; } 1257 if (len < 0) {
1258 return len;
1259 }
1195 memset(valstr, 0, sizeof(valstr)); 1260 memset(valstr, 0, sizeof(valstr));
1196 if( copy_from_user(valstr, &user_buffer[i], len)) 1261 if (copy_from_user(valstr, &user_buffer[i], len))
1197 return -EFAULT; 1262 return -EFAULT;
1198 i += len; 1263 i += len;
1199 1264
1200 for(*m = 0;*v && m < pkt_dev->dst_mac + 6; v++) { 1265 for (*m = 0; *v && m < pkt_dev->dst_mac + 6; v++) {
1201 if (*v >= '0' && *v <= '9') { 1266 if (*v >= '0' && *v <= '9') {
1202 *m *= 16; 1267 *m *= 16;
1203 *m += *v - '0'; 1268 *m += *v - '0';
@@ -1219,7 +1284,7 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
1219 /* Set up Dest MAC */ 1284 /* Set up Dest MAC */
1220 if (compare_ether_addr(old_dmac, pkt_dev->dst_mac)) 1285 if (compare_ether_addr(old_dmac, pkt_dev->dst_mac))
1221 memcpy(&(pkt_dev->hh[0]), pkt_dev->dst_mac, ETH_ALEN); 1286 memcpy(&(pkt_dev->hh[0]), pkt_dev->dst_mac, ETH_ALEN);
1222 1287
1223 sprintf(pg_result, "OK: dstmac"); 1288 sprintf(pg_result, "OK: dstmac");
1224 return count; 1289 return count;
1225 } 1290 }
@@ -1228,13 +1293,15 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
1228 unsigned char *m = pkt_dev->src_mac; 1293 unsigned char *m = pkt_dev->src_mac;
1229 1294
1230 len = strn_len(&user_buffer[i], sizeof(valstr) - 1); 1295 len = strn_len(&user_buffer[i], sizeof(valstr) - 1);
1231 if (len < 0) { return len; } 1296 if (len < 0) {
1297 return len;
1298 }
1232 memset(valstr, 0, sizeof(valstr)); 1299 memset(valstr, 0, sizeof(valstr));
1233 if( copy_from_user(valstr, &user_buffer[i], len)) 1300 if (copy_from_user(valstr, &user_buffer[i], len))
1234 return -EFAULT; 1301 return -EFAULT;
1235 i += len; 1302 i += len;
1236 1303
1237 for(*m = 0;*v && m < pkt_dev->src_mac + 6; v++) { 1304 for (*m = 0; *v && m < pkt_dev->src_mac + 6; v++) {
1238 if (*v >= '0' && *v <= '9') { 1305 if (*v >= '0' && *v <= '9') {
1239 *m *= 16; 1306 *m *= 16;
1240 *m += *v - '0'; 1307 *m += *v - '0';
@@ -1251,21 +1318,23 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
1251 m++; 1318 m++;
1252 *m = 0; 1319 *m = 0;
1253 } 1320 }
1254 } 1321 }
1255 1322
1256 sprintf(pg_result, "OK: srcmac"); 1323 sprintf(pg_result, "OK: srcmac");
1257 return count; 1324 return count;
1258 } 1325 }
1259 1326
1260 if (!strcmp(name, "clear_counters")) { 1327 if (!strcmp(name, "clear_counters")) {
1261 pktgen_clear_counters(pkt_dev); 1328 pktgen_clear_counters(pkt_dev);
1262 sprintf(pg_result, "OK: Clearing counters.\n"); 1329 sprintf(pg_result, "OK: Clearing counters.\n");
1263 return count; 1330 return count;
1264 } 1331 }
1265 1332
1266 if (!strcmp(name, "flows")) { 1333 if (!strcmp(name, "flows")) {
1267 len = num_arg(&user_buffer[i], 10, &value); 1334 len = num_arg(&user_buffer[i], 10, &value);
1268 if (len < 0) { return len; } 1335 if (len < 0) {
1336 return len;
1337 }
1269 i += len; 1338 i += len;
1270 if (value > MAX_CFLOWS) 1339 if (value > MAX_CFLOWS)
1271 value = MAX_CFLOWS; 1340 value = MAX_CFLOWS;
@@ -1277,13 +1346,15 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
1277 1346
1278 if (!strcmp(name, "flowlen")) { 1347 if (!strcmp(name, "flowlen")) {
1279 len = num_arg(&user_buffer[i], 10, &value); 1348 len = num_arg(&user_buffer[i], 10, &value);
1280 if (len < 0) { return len; } 1349 if (len < 0) {
1350 return len;
1351 }
1281 i += len; 1352 i += len;
1282 pkt_dev->lflow = value; 1353 pkt_dev->lflow = value;
1283 sprintf(pg_result, "OK: flowlen=%u", pkt_dev->lflow); 1354 sprintf(pg_result, "OK: flowlen=%u", pkt_dev->lflow);
1284 return count; 1355 return count;
1285 } 1356 }
1286 1357
1287 sprintf(pkt_dev->result, "No such parameter \"%s\"", name); 1358 sprintf(pkt_dev->result, "No such parameter \"%s\"", name);
1288 return -EINVAL; 1359 return -EINVAL;
1289} 1360}
@@ -1294,35 +1365,35 @@ static int pktgen_if_open(struct inode *inode, struct file *file)
1294} 1365}
1295 1366
1296static struct file_operations pktgen_if_fops = { 1367static struct file_operations pktgen_if_fops = {
1297 .owner = THIS_MODULE, 1368 .owner = THIS_MODULE,
1298 .open = pktgen_if_open, 1369 .open = pktgen_if_open,
1299 .read = seq_read, 1370 .read = seq_read,
1300 .llseek = seq_lseek, 1371 .llseek = seq_lseek,
1301 .write = pktgen_if_write, 1372 .write = pktgen_if_write,
1302 .release = single_release, 1373 .release = single_release,
1303}; 1374};
1304 1375
1305static int pktgen_thread_show(struct seq_file *seq, void *v) 1376static int pktgen_thread_show(struct seq_file *seq, void *v)
1306{ 1377{
1307 struct pktgen_thread *t = seq->private; 1378 struct pktgen_thread *t = seq->private;
1308 struct pktgen_dev *pkt_dev = NULL; 1379 struct pktgen_dev *pkt_dev = NULL;
1309 1380
1310 BUG_ON(!t); 1381 BUG_ON(!t);
1311 1382
1312 seq_printf(seq, "Name: %s max_before_softirq: %d\n", 1383 seq_printf(seq, "Name: %s max_before_softirq: %d\n",
1313 t->name, t->max_before_softirq); 1384 t->name, t->max_before_softirq);
1385
1386 seq_printf(seq, "Running: ");
1314 1387
1315 seq_printf(seq, "Running: "); 1388 if_lock(t);
1316 1389 for (pkt_dev = t->if_list; pkt_dev; pkt_dev = pkt_dev->next)
1317 if_lock(t); 1390 if (pkt_dev->running)
1318 for(pkt_dev = t->if_list;pkt_dev; pkt_dev = pkt_dev->next)
1319 if(pkt_dev->running)
1320 seq_printf(seq, "%s ", pkt_dev->ifname); 1391 seq_printf(seq, "%s ", pkt_dev->ifname);
1321
1322 seq_printf(seq, "\nStopped: ");
1323 1392
1324 for(pkt_dev = t->if_list;pkt_dev; pkt_dev = pkt_dev->next) 1393 seq_printf(seq, "\nStopped: ");
1325 if(!pkt_dev->running) 1394
1395 for (pkt_dev = t->if_list; pkt_dev; pkt_dev = pkt_dev->next)
1396 if (!pkt_dev->running)
1326 seq_printf(seq, "%s ", pkt_dev->ifname); 1397 seq_printf(seq, "%s ", pkt_dev->ifname);
1327 1398
1328 if (t->result[0]) 1399 if (t->result[0])
@@ -1330,30 +1401,30 @@ static int pktgen_thread_show(struct seq_file *seq, void *v)
1330 else 1401 else
1331 seq_printf(seq, "\nResult: NA\n"); 1402 seq_printf(seq, "\nResult: NA\n");
1332 1403
1333 if_unlock(t); 1404 if_unlock(t);
1334 1405
1335 return 0; 1406 return 0;
1336} 1407}
1337 1408
1338static ssize_t pktgen_thread_write(struct file *file, 1409static ssize_t pktgen_thread_write(struct file *file,
1339 const char __user *user_buffer, 1410 const char __user * user_buffer,
1340 size_t count, loff_t *offset) 1411 size_t count, loff_t * offset)
1341{ 1412{
1342 struct seq_file *seq = (struct seq_file *) file->private_data; 1413 struct seq_file *seq = (struct seq_file *)file->private_data;
1343 struct pktgen_thread *t = seq->private; 1414 struct pktgen_thread *t = seq->private;
1344 int i = 0, max, len, ret; 1415 int i = 0, max, len, ret;
1345 char name[40]; 1416 char name[40];
1346 char *pg_result; 1417 char *pg_result;
1347 unsigned long value = 0; 1418 unsigned long value = 0;
1348 1419
1349 if (count < 1) { 1420 if (count < 1) {
1350 // sprintf(pg_result, "Wrong command format"); 1421 // sprintf(pg_result, "Wrong command format");
1351 return -EINVAL; 1422 return -EINVAL;
1352 } 1423 }
1353 1424
1354 max = count - i; 1425 max = count - i;
1355 len = count_trail_chars(&user_buffer[i], max); 1426 len = count_trail_chars(&user_buffer[i], max);
1356 if (len < 0) 1427 if (len < 0)
1357 return len; 1428 return len;
1358 1429
1359 i += len; 1430 i += len;
@@ -1361,26 +1432,25 @@ static ssize_t pktgen_thread_write(struct file *file,
1361 /* Read variable name */ 1432 /* Read variable name */
1362 1433
1363 len = strn_len(&user_buffer[i], sizeof(name) - 1); 1434 len = strn_len(&user_buffer[i], sizeof(name) - 1);
1364 if (len < 0) 1435 if (len < 0)
1365 return len; 1436 return len;
1366 1437
1367 memset(name, 0, sizeof(name)); 1438 memset(name, 0, sizeof(name));
1368 if (copy_from_user(name, &user_buffer[i], len)) 1439 if (copy_from_user(name, &user_buffer[i], len))
1369 return -EFAULT; 1440 return -EFAULT;
1370 i += len; 1441 i += len;
1371 1442
1372 max = count -i; 1443 max = count - i;
1373 len = count_trail_chars(&user_buffer[i], max); 1444 len = count_trail_chars(&user_buffer[i], max);
1374 if (len < 0) 1445 if (len < 0)
1375 return len; 1446 return len;
1376 1447
1377 i += len; 1448 i += len;
1378 1449
1379 if (debug) 1450 if (debug)
1380 printk("pktgen: t=%s, count=%lu\n", name, 1451 printk("pktgen: t=%s, count=%lu\n", name, (unsigned long)count);
1381 (unsigned long) count);
1382 1452
1383 if(!t) { 1453 if (!t) {
1384 printk("pktgen: ERROR: No thread\n"); 1454 printk("pktgen: ERROR: No thread\n");
1385 ret = -EINVAL; 1455 ret = -EINVAL;
1386 goto out; 1456 goto out;
@@ -1388,48 +1458,47 @@ static ssize_t pktgen_thread_write(struct file *file,
1388 1458
1389 pg_result = &(t->result[0]); 1459 pg_result = &(t->result[0]);
1390 1460
1391 if (!strcmp(name, "add_device")) { 1461 if (!strcmp(name, "add_device")) {
1392 char f[32]; 1462 char f[32];
1393 memset(f, 0, 32); 1463 memset(f, 0, 32);
1394 len = strn_len(&user_buffer[i], sizeof(f) - 1); 1464 len = strn_len(&user_buffer[i], sizeof(f) - 1);
1395 if (len < 0) { 1465 if (len < 0) {
1396 ret = len; 1466 ret = len;
1397 goto out; 1467 goto out;
1398 } 1468 }
1399 if( copy_from_user(f, &user_buffer[i], len) ) 1469 if (copy_from_user(f, &user_buffer[i], len))
1400 return -EFAULT; 1470 return -EFAULT;
1401 i += len; 1471 i += len;
1402 thread_lock(); 1472 thread_lock();
1403 pktgen_add_device(t, f); 1473 pktgen_add_device(t, f);
1404 thread_unlock(); 1474 thread_unlock();
1405 ret = count; 1475 ret = count;
1406 sprintf(pg_result, "OK: add_device=%s", f); 1476 sprintf(pg_result, "OK: add_device=%s", f);
1407 goto out; 1477 goto out;
1408 } 1478 }
1409 1479
1410 if (!strcmp(name, "rem_device_all")) { 1480 if (!strcmp(name, "rem_device_all")) {
1411 thread_lock(); 1481 thread_lock();
1412 t->control |= T_REMDEVALL; 1482 t->control |= T_REMDEVALL;
1413 thread_unlock(); 1483 thread_unlock();
1414 schedule_timeout_interruptible(msecs_to_jiffies(125)); /* Propagate thread->control */ 1484 schedule_timeout_interruptible(msecs_to_jiffies(125)); /* Propagate thread->control */
1415 ret = count; 1485 ret = count;
1416 sprintf(pg_result, "OK: rem_device_all"); 1486 sprintf(pg_result, "OK: rem_device_all");
1417 goto out; 1487 goto out;
1418 } 1488 }
1419 1489
1420 if (!strcmp(name, "max_before_softirq")) { 1490 if (!strcmp(name, "max_before_softirq")) {
1421 len = num_arg(&user_buffer[i], 10, &value); 1491 len = num_arg(&user_buffer[i], 10, &value);
1422 thread_lock(); 1492 thread_lock();
1423 t->max_before_softirq = value; 1493 t->max_before_softirq = value;
1424 thread_unlock(); 1494 thread_unlock();
1425 ret = count; 1495 ret = count;
1426 sprintf(pg_result, "OK: max_before_softirq=%lu", value); 1496 sprintf(pg_result, "OK: max_before_softirq=%lu", value);
1427 goto out; 1497 goto out;
1428 } 1498 }
1429 1499
1430 ret = -EINVAL; 1500 ret = -EINVAL;
1431 out: 1501out:
1432
1433 return ret; 1502 return ret;
1434} 1503}
1435 1504
@@ -1439,42 +1508,42 @@ static int pktgen_thread_open(struct inode *inode, struct file *file)
1439} 1508}
1440 1509
1441static struct file_operations pktgen_thread_fops = { 1510static struct file_operations pktgen_thread_fops = {
1442 .owner = THIS_MODULE, 1511 .owner = THIS_MODULE,
1443 .open = pktgen_thread_open, 1512 .open = pktgen_thread_open,
1444 .read = seq_read, 1513 .read = seq_read,
1445 .llseek = seq_lseek, 1514 .llseek = seq_lseek,
1446 .write = pktgen_thread_write, 1515 .write = pktgen_thread_write,
1447 .release = single_release, 1516 .release = single_release,
1448}; 1517};
1449 1518
1450/* Think find or remove for NN */ 1519/* Think find or remove for NN */
1451static struct pktgen_dev *__pktgen_NN_threads(const char* ifname, int remove) 1520static struct pktgen_dev *__pktgen_NN_threads(const char *ifname, int remove)
1452{ 1521{
1453 struct pktgen_thread *t; 1522 struct pktgen_thread *t;
1454 struct pktgen_dev *pkt_dev = NULL; 1523 struct pktgen_dev *pkt_dev = NULL;
1455 1524
1456 t = pktgen_threads; 1525 t = pktgen_threads;
1457 1526
1458 while (t) { 1527 while (t) {
1459 pkt_dev = pktgen_find_dev(t, ifname); 1528 pkt_dev = pktgen_find_dev(t, ifname);
1460 if (pkt_dev) { 1529 if (pkt_dev) {
1461 if(remove) { 1530 if (remove) {
1462 if_lock(t); 1531 if_lock(t);
1463 pkt_dev->removal_mark = 1; 1532 pkt_dev->removal_mark = 1;
1464 t->control |= T_REMDEV; 1533 t->control |= T_REMDEV;
1465 if_unlock(t); 1534 if_unlock(t);
1466 } 1535 }
1467 break; 1536 break;
1468 } 1537 }
1469 t = t->next; 1538 t = t->next;
1470 } 1539 }
1471 return pkt_dev; 1540 return pkt_dev;
1472} 1541}
1473 1542
1474/* 1543/*
1475 * mark a device for removal 1544 * mark a device for removal
1476 */ 1545 */
1477static int pktgen_mark_device(const char* ifname) 1546static int pktgen_mark_device(const char *ifname)
1478{ 1547{
1479 struct pktgen_dev *pkt_dev = NULL; 1548 struct pktgen_dev *pkt_dev = NULL;
1480 const int max_tries = 10, msec_per_try = 125; 1549 const int max_tries = 10, msec_per_try = 125;
@@ -1482,24 +1551,25 @@ static int pktgen_mark_device(const char* ifname)
1482 int ret = 0; 1551 int ret = 0;
1483 1552
1484 thread_lock(); 1553 thread_lock();
1485 PG_DEBUG(printk("pktgen: pktgen_mark_device marking %s for removal\n", 1554 PG_DEBUG(printk("pktgen: pktgen_mark_device marking %s for removal\n",
1486 ifname)); 1555 ifname));
1487 1556
1488 while(1) { 1557 while (1) {
1489 1558
1490 pkt_dev = __pktgen_NN_threads(ifname, REMOVE); 1559 pkt_dev = __pktgen_NN_threads(ifname, REMOVE);
1491 if (pkt_dev == NULL) break; /* success */ 1560 if (pkt_dev == NULL)
1561 break; /* success */
1492 1562
1493 thread_unlock(); 1563 thread_unlock();
1494 PG_DEBUG(printk("pktgen: pktgen_mark_device waiting for %s " 1564 PG_DEBUG(printk("pktgen: pktgen_mark_device waiting for %s "
1495 "to disappear....\n", ifname)); 1565 "to disappear....\n", ifname));
1496 schedule_timeout_interruptible(msecs_to_jiffies(msec_per_try)); 1566 schedule_timeout_interruptible(msecs_to_jiffies(msec_per_try));
1497 thread_lock(); 1567 thread_lock();
1498 1568
1499 if (++i >= max_tries) { 1569 if (++i >= max_tries) {
1500 printk("pktgen_mark_device: timed out after waiting " 1570 printk("pktgen_mark_device: timed out after waiting "
1501 "%d msec for device %s to be removed\n", 1571 "%d msec for device %s to be removed\n",
1502 msec_per_try*i, ifname); 1572 msec_per_try * i, ifname);
1503 ret = 1; 1573 ret = 1;
1504 break; 1574 break;
1505 } 1575 }
@@ -1511,7 +1581,8 @@ static int pktgen_mark_device(const char* ifname)
1511 return ret; 1581 return ret;
1512} 1582}
1513 1583
1514static int pktgen_device_event(struct notifier_block *unused, unsigned long event, void *ptr) 1584static int pktgen_device_event(struct notifier_block *unused,
1585 unsigned long event, void *ptr)
1515{ 1586{
1516 struct net_device *dev = (struct net_device *)(ptr); 1587 struct net_device *dev = (struct net_device *)(ptr);
1517 1588
@@ -1526,9 +1597,9 @@ static int pktgen_device_event(struct notifier_block *unused, unsigned long even
1526 case NETDEV_UP: 1597 case NETDEV_UP:
1527 /* Ignore for now */ 1598 /* Ignore for now */
1528 break; 1599 break;
1529 1600
1530 case NETDEV_UNREGISTER: 1601 case NETDEV_UNREGISTER:
1531 pktgen_mark_device(dev->name); 1602 pktgen_mark_device(dev->name);
1532 break; 1603 break;
1533 }; 1604 };
1534 1605
@@ -1537,15 +1608,16 @@ static int pktgen_device_event(struct notifier_block *unused, unsigned long even
1537 1608
1538/* Associate pktgen_dev with a device. */ 1609/* Associate pktgen_dev with a device. */
1539 1610
1540static struct net_device* pktgen_setup_dev(struct pktgen_dev *pkt_dev) { 1611static struct net_device *pktgen_setup_dev(struct pktgen_dev *pkt_dev)
1612{
1541 struct net_device *odev; 1613 struct net_device *odev;
1542 1614
1543 /* Clean old setups */ 1615 /* Clean old setups */
1544 1616
1545 if (pkt_dev->odev) { 1617 if (pkt_dev->odev) {
1546 dev_put(pkt_dev->odev); 1618 dev_put(pkt_dev->odev);
1547 pkt_dev->odev = NULL; 1619 pkt_dev->odev = NULL;
1548 } 1620 }
1549 1621
1550 odev = dev_get_by_name(pkt_dev->ifname); 1622 odev = dev_get_by_name(pkt_dev->ifname);
1551 1623
@@ -1554,7 +1626,8 @@ static struct net_device* pktgen_setup_dev(struct pktgen_dev *pkt_dev) {
1554 goto out; 1626 goto out;
1555 } 1627 }
1556 if (odev->type != ARPHRD_ETHER) { 1628 if (odev->type != ARPHRD_ETHER) {
1557 printk("pktgen: not an ethernet device: \"%s\"\n", pkt_dev->ifname); 1629 printk("pktgen: not an ethernet device: \"%s\"\n",
1630 pkt_dev->ifname);
1558 goto out_put; 1631 goto out_put;
1559 } 1632 }
1560 if (!netif_running(odev)) { 1633 if (!netif_running(odev)) {
@@ -1562,13 +1635,13 @@ static struct net_device* pktgen_setup_dev(struct pktgen_dev *pkt_dev) {
1562 goto out_put; 1635 goto out_put;
1563 } 1636 }
1564 pkt_dev->odev = odev; 1637 pkt_dev->odev = odev;
1565 1638
1566 return pkt_dev->odev; 1639 return pkt_dev->odev;
1567 1640
1568out_put: 1641out_put:
1569 dev_put(odev); 1642 dev_put(odev);
1570out: 1643out:
1571 return NULL; 1644 return NULL;
1572 1645
1573} 1646}
1574 1647
@@ -1578,59 +1651,64 @@ out:
1578static void pktgen_setup_inject(struct pktgen_dev *pkt_dev) 1651static void pktgen_setup_inject(struct pktgen_dev *pkt_dev)
1579{ 1652{
1580 /* Try once more, just in case it works now. */ 1653 /* Try once more, just in case it works now. */
1581 if (!pkt_dev->odev) 1654 if (!pkt_dev->odev)
1582 pktgen_setup_dev(pkt_dev); 1655 pktgen_setup_dev(pkt_dev);
1583 1656
1584 if (!pkt_dev->odev) { 1657 if (!pkt_dev->odev) {
1585 printk("pktgen: ERROR: pkt_dev->odev == NULL in setup_inject.\n"); 1658 printk("pktgen: ERROR: pkt_dev->odev == NULL in setup_inject.\n");
1586 sprintf(pkt_dev->result, "ERROR: pkt_dev->odev == NULL in setup_inject.\n"); 1659 sprintf(pkt_dev->result,
1587 return; 1660 "ERROR: pkt_dev->odev == NULL in setup_inject.\n");
1588 } 1661 return;
1589 1662 }
1590 /* Default to the interface's mac if not explicitly set. */ 1663
1664 /* Default to the interface's mac if not explicitly set. */
1591 1665
1592 if (is_zero_ether_addr(pkt_dev->src_mac)) 1666 if (is_zero_ether_addr(pkt_dev->src_mac))
1593 memcpy(&(pkt_dev->hh[6]), pkt_dev->odev->dev_addr, ETH_ALEN); 1667 memcpy(&(pkt_dev->hh[6]), pkt_dev->odev->dev_addr, ETH_ALEN);
1594 1668
1595 /* Set up Dest MAC */ 1669 /* Set up Dest MAC */
1596 memcpy(&(pkt_dev->hh[0]), pkt_dev->dst_mac, ETH_ALEN); 1670 memcpy(&(pkt_dev->hh[0]), pkt_dev->dst_mac, ETH_ALEN);
1597 1671
1598 /* Set up pkt size */ 1672 /* Set up pkt size */
1599 pkt_dev->cur_pkt_size = pkt_dev->min_pkt_size; 1673 pkt_dev->cur_pkt_size = pkt_dev->min_pkt_size;
1600 1674
1601 if(pkt_dev->flags & F_IPV6) { 1675 if (pkt_dev->flags & F_IPV6) {
1602 /* 1676 /*
1603 * Skip this automatic address setting until locks or functions 1677 * Skip this automatic address setting until locks or functions
1604 * gets exported 1678 * gets exported
1605 */ 1679 */
1606 1680
1607#ifdef NOTNOW 1681#ifdef NOTNOW
1608 int i, set = 0, err=1; 1682 int i, set = 0, err = 1;
1609 struct inet6_dev *idev; 1683 struct inet6_dev *idev;
1610 1684
1611 for(i=0; i< IN6_ADDR_HSIZE; i++) 1685 for (i = 0; i < IN6_ADDR_HSIZE; i++)
1612 if(pkt_dev->cur_in6_saddr.s6_addr[i]) { 1686 if (pkt_dev->cur_in6_saddr.s6_addr[i]) {
1613 set = 1; 1687 set = 1;
1614 break; 1688 break;
1615 } 1689 }
1616 1690
1617 if(!set) { 1691 if (!set) {
1618 1692
1619 /* 1693 /*
1620 * Use linklevel address if unconfigured. 1694 * Use linklevel address if unconfigured.
1621 * 1695 *
1622 * use ipv6_get_lladdr if/when it's get exported 1696 * use ipv6_get_lladdr if/when it's get exported
1623 */ 1697 */
1624 1698
1625
1626 read_lock(&addrconf_lock); 1699 read_lock(&addrconf_lock);
1627 if ((idev = __in6_dev_get(pkt_dev->odev)) != NULL) { 1700 if ((idev = __in6_dev_get(pkt_dev->odev)) != NULL) {
1628 struct inet6_ifaddr *ifp; 1701 struct inet6_ifaddr *ifp;
1629 1702
1630 read_lock_bh(&idev->lock); 1703 read_lock_bh(&idev->lock);
1631 for (ifp=idev->addr_list; ifp; ifp=ifp->if_next) { 1704 for (ifp = idev->addr_list; ifp;
1632 if (ifp->scope == IFA_LINK && !(ifp->flags&IFA_F_TENTATIVE)) { 1705 ifp = ifp->if_next) {
1633 ipv6_addr_copy(&pkt_dev->cur_in6_saddr, &ifp->addr); 1706 if (ifp->scope == IFA_LINK
1707 && !(ifp->
1708 flags & IFA_F_TENTATIVE)) {
1709 ipv6_addr_copy(&pkt_dev->
1710 cur_in6_saddr,
1711 &ifp->addr);
1634 err = 0; 1712 err = 0;
1635 break; 1713 break;
1636 } 1714 }
@@ -1638,28 +1716,28 @@ static void pktgen_setup_inject(struct pktgen_dev *pkt_dev)
1638 read_unlock_bh(&idev->lock); 1716 read_unlock_bh(&idev->lock);
1639 } 1717 }
1640 read_unlock(&addrconf_lock); 1718 read_unlock(&addrconf_lock);
1641 if(err) printk("pktgen: ERROR: IPv6 link address not availble.\n"); 1719 if (err)
1720 printk("pktgen: ERROR: IPv6 link address not availble.\n");
1642 } 1721 }
1643#endif 1722#endif
1644 } 1723 } else {
1645 else {
1646 pkt_dev->saddr_min = 0; 1724 pkt_dev->saddr_min = 0;
1647 pkt_dev->saddr_max = 0; 1725 pkt_dev->saddr_max = 0;
1648 if (strlen(pkt_dev->src_min) == 0) { 1726 if (strlen(pkt_dev->src_min) == 0) {
1649 1727
1650 struct in_device *in_dev; 1728 struct in_device *in_dev;
1651 1729
1652 rcu_read_lock(); 1730 rcu_read_lock();
1653 in_dev = __in_dev_get_rcu(pkt_dev->odev); 1731 in_dev = __in_dev_get_rcu(pkt_dev->odev);
1654 if (in_dev) { 1732 if (in_dev) {
1655 if (in_dev->ifa_list) { 1733 if (in_dev->ifa_list) {
1656 pkt_dev->saddr_min = in_dev->ifa_list->ifa_address; 1734 pkt_dev->saddr_min =
1735 in_dev->ifa_list->ifa_address;
1657 pkt_dev->saddr_max = pkt_dev->saddr_min; 1736 pkt_dev->saddr_max = pkt_dev->saddr_min;
1658 } 1737 }
1659 } 1738 }
1660 rcu_read_unlock(); 1739 rcu_read_unlock();
1661 } 1740 } else {
1662 else {
1663 pkt_dev->saddr_min = in_aton(pkt_dev->src_min); 1741 pkt_dev->saddr_min = in_aton(pkt_dev->src_min);
1664 pkt_dev->saddr_max = in_aton(pkt_dev->src_max); 1742 pkt_dev->saddr_max = in_aton(pkt_dev->src_max);
1665 } 1743 }
@@ -1667,13 +1745,13 @@ static void pktgen_setup_inject(struct pktgen_dev *pkt_dev)
1667 pkt_dev->daddr_min = in_aton(pkt_dev->dst_min); 1745 pkt_dev->daddr_min = in_aton(pkt_dev->dst_min);
1668 pkt_dev->daddr_max = in_aton(pkt_dev->dst_max); 1746 pkt_dev->daddr_max = in_aton(pkt_dev->dst_max);
1669 } 1747 }
1670 /* Initialize current values. */ 1748 /* Initialize current values. */
1671 pkt_dev->cur_dst_mac_offset = 0; 1749 pkt_dev->cur_dst_mac_offset = 0;
1672 pkt_dev->cur_src_mac_offset = 0; 1750 pkt_dev->cur_src_mac_offset = 0;
1673 pkt_dev->cur_saddr = pkt_dev->saddr_min; 1751 pkt_dev->cur_saddr = pkt_dev->saddr_min;
1674 pkt_dev->cur_daddr = pkt_dev->daddr_min; 1752 pkt_dev->cur_daddr = pkt_dev->daddr_min;
1675 pkt_dev->cur_udp_dst = pkt_dev->udp_dst_min; 1753 pkt_dev->cur_udp_dst = pkt_dev->udp_dst_min;
1676 pkt_dev->cur_udp_src = pkt_dev->udp_src_min; 1754 pkt_dev->cur_udp_src = pkt_dev->udp_src_min;
1677 pkt_dev->nflows = 0; 1755 pkt_dev->nflows = 0;
1678} 1756}
1679 1757
@@ -1686,7 +1764,7 @@ static void spin(struct pktgen_dev *pkt_dev, __u64 spin_until_us)
1686 printk(KERN_INFO "sleeping for %d\n", (int)(spin_until_us - now)); 1764 printk(KERN_INFO "sleeping for %d\n", (int)(spin_until_us - now));
1687 while (now < spin_until_us) { 1765 while (now < spin_until_us) {
1688 /* TODO: optimize sleeping behavior */ 1766 /* TODO: optimize sleeping behavior */
1689 if (spin_until_us - now > jiffies_to_usecs(1)+1) 1767 if (spin_until_us - now > jiffies_to_usecs(1) + 1)
1690 schedule_timeout_interruptible(1); 1768 schedule_timeout_interruptible(1);
1691 else if (spin_until_us - now > 100) { 1769 else if (spin_until_us - now > 100) {
1692 do_softirq(); 1770 do_softirq();
@@ -1702,102 +1780,110 @@ static void spin(struct pktgen_dev *pkt_dev, __u64 spin_until_us)
1702 pkt_dev->idle_acc += now - start; 1780 pkt_dev->idle_acc += now - start;
1703} 1781}
1704 1782
1705
1706/* Increment/randomize headers according to flags and current values 1783/* Increment/randomize headers according to flags and current values
1707 * for IP src/dest, UDP src/dst port, MAC-Addr src/dst 1784 * for IP src/dest, UDP src/dst port, MAC-Addr src/dst
1708 */ 1785 */
1709static void mod_cur_headers(struct pktgen_dev *pkt_dev) { 1786static void mod_cur_headers(struct pktgen_dev *pkt_dev)
1710 __u32 imn; 1787{
1711 __u32 imx; 1788 __u32 imn;
1712 int flow = 0; 1789 __u32 imx;
1790 int flow = 0;
1713 1791
1714 if(pkt_dev->cflows) { 1792 if (pkt_dev->cflows) {
1715 flow = pktgen_random() % pkt_dev->cflows; 1793 flow = pktgen_random() % pkt_dev->cflows;
1716 1794
1717 if (pkt_dev->flows[flow].count > pkt_dev->lflow) 1795 if (pkt_dev->flows[flow].count > pkt_dev->lflow)
1718 pkt_dev->flows[flow].count = 0; 1796 pkt_dev->flows[flow].count = 0;
1719 } 1797 }
1720
1721 1798
1722 /* Deal with source MAC */ 1799 /* Deal with source MAC */
1723 if (pkt_dev->src_mac_count > 1) { 1800 if (pkt_dev->src_mac_count > 1) {
1724 __u32 mc; 1801 __u32 mc;
1725 __u32 tmp; 1802 __u32 tmp;
1726 1803
1727 if (pkt_dev->flags & F_MACSRC_RND) 1804 if (pkt_dev->flags & F_MACSRC_RND)
1728 mc = pktgen_random() % (pkt_dev->src_mac_count); 1805 mc = pktgen_random() % (pkt_dev->src_mac_count);
1729 else { 1806 else {
1730 mc = pkt_dev->cur_src_mac_offset++; 1807 mc = pkt_dev->cur_src_mac_offset++;
1731 if (pkt_dev->cur_src_mac_offset > pkt_dev->src_mac_count) 1808 if (pkt_dev->cur_src_mac_offset >
1732 pkt_dev->cur_src_mac_offset = 0; 1809 pkt_dev->src_mac_count)
1733 } 1810 pkt_dev->cur_src_mac_offset = 0;
1734 1811 }
1735 tmp = pkt_dev->src_mac[5] + (mc & 0xFF); 1812
1736 pkt_dev->hh[11] = tmp; 1813 tmp = pkt_dev->src_mac[5] + (mc & 0xFF);
1737 tmp = (pkt_dev->src_mac[4] + ((mc >> 8) & 0xFF) + (tmp >> 8)); 1814 pkt_dev->hh[11] = tmp;
1738 pkt_dev->hh[10] = tmp; 1815 tmp = (pkt_dev->src_mac[4] + ((mc >> 8) & 0xFF) + (tmp >> 8));
1739 tmp = (pkt_dev->src_mac[3] + ((mc >> 16) & 0xFF) + (tmp >> 8)); 1816 pkt_dev->hh[10] = tmp;
1740 pkt_dev->hh[9] = tmp; 1817 tmp = (pkt_dev->src_mac[3] + ((mc >> 16) & 0xFF) + (tmp >> 8));
1741 tmp = (pkt_dev->src_mac[2] + ((mc >> 24) & 0xFF) + (tmp >> 8)); 1818 pkt_dev->hh[9] = tmp;
1742 pkt_dev->hh[8] = tmp; 1819 tmp = (pkt_dev->src_mac[2] + ((mc >> 24) & 0xFF) + (tmp >> 8));
1743 tmp = (pkt_dev->src_mac[1] + (tmp >> 8)); 1820 pkt_dev->hh[8] = tmp;
1744 pkt_dev->hh[7] = tmp; 1821 tmp = (pkt_dev->src_mac[1] + (tmp >> 8));
1745 } 1822 pkt_dev->hh[7] = tmp;
1746 1823 }
1747 /* Deal with Destination MAC */ 1824
1748 if (pkt_dev->dst_mac_count > 1) { 1825 /* Deal with Destination MAC */
1749 __u32 mc; 1826 if (pkt_dev->dst_mac_count > 1) {
1750 __u32 tmp; 1827 __u32 mc;
1751 1828 __u32 tmp;
1752 if (pkt_dev->flags & F_MACDST_RND) 1829
1753 mc = pktgen_random() % (pkt_dev->dst_mac_count); 1830 if (pkt_dev->flags & F_MACDST_RND)
1754 1831 mc = pktgen_random() % (pkt_dev->dst_mac_count);
1755 else { 1832
1756 mc = pkt_dev->cur_dst_mac_offset++; 1833 else {
1757 if (pkt_dev->cur_dst_mac_offset > pkt_dev->dst_mac_count) { 1834 mc = pkt_dev->cur_dst_mac_offset++;
1758 pkt_dev->cur_dst_mac_offset = 0; 1835 if (pkt_dev->cur_dst_mac_offset >
1759 } 1836 pkt_dev->dst_mac_count) {
1760 } 1837 pkt_dev->cur_dst_mac_offset = 0;
1761 1838 }
1762 tmp = pkt_dev->dst_mac[5] + (mc & 0xFF); 1839 }
1763 pkt_dev->hh[5] = tmp; 1840
1764 tmp = (pkt_dev->dst_mac[4] + ((mc >> 8) & 0xFF) + (tmp >> 8)); 1841 tmp = pkt_dev->dst_mac[5] + (mc & 0xFF);
1765 pkt_dev->hh[4] = tmp; 1842 pkt_dev->hh[5] = tmp;
1766 tmp = (pkt_dev->dst_mac[3] + ((mc >> 16) & 0xFF) + (tmp >> 8)); 1843 tmp = (pkt_dev->dst_mac[4] + ((mc >> 8) & 0xFF) + (tmp >> 8));
1767 pkt_dev->hh[3] = tmp; 1844 pkt_dev->hh[4] = tmp;
1768 tmp = (pkt_dev->dst_mac[2] + ((mc >> 24) & 0xFF) + (tmp >> 8)); 1845 tmp = (pkt_dev->dst_mac[3] + ((mc >> 16) & 0xFF) + (tmp >> 8));
1769 pkt_dev->hh[2] = tmp; 1846 pkt_dev->hh[3] = tmp;
1770 tmp = (pkt_dev->dst_mac[1] + (tmp >> 8)); 1847 tmp = (pkt_dev->dst_mac[2] + ((mc >> 24) & 0xFF) + (tmp >> 8));
1771 pkt_dev->hh[1] = tmp; 1848 pkt_dev->hh[2] = tmp;
1772 } 1849 tmp = (pkt_dev->dst_mac[1] + (tmp >> 8));
1773 1850 pkt_dev->hh[1] = tmp;
1774 if (pkt_dev->udp_src_min < pkt_dev->udp_src_max) { 1851 }
1775 if (pkt_dev->flags & F_UDPSRC_RND) 1852
1776 pkt_dev->cur_udp_src = ((pktgen_random() % (pkt_dev->udp_src_max - pkt_dev->udp_src_min)) + pkt_dev->udp_src_min); 1853 if (pkt_dev->udp_src_min < pkt_dev->udp_src_max) {
1777 1854 if (pkt_dev->flags & F_UDPSRC_RND)
1778 else { 1855 pkt_dev->cur_udp_src =
1856 ((pktgen_random() %
1857 (pkt_dev->udp_src_max - pkt_dev->udp_src_min)) +
1858 pkt_dev->udp_src_min);
1859
1860 else {
1779 pkt_dev->cur_udp_src++; 1861 pkt_dev->cur_udp_src++;
1780 if (pkt_dev->cur_udp_src >= pkt_dev->udp_src_max) 1862 if (pkt_dev->cur_udp_src >= pkt_dev->udp_src_max)
1781 pkt_dev->cur_udp_src = pkt_dev->udp_src_min; 1863 pkt_dev->cur_udp_src = pkt_dev->udp_src_min;
1782 } 1864 }
1783 } 1865 }
1784 1866
1785 if (pkt_dev->udp_dst_min < pkt_dev->udp_dst_max) { 1867 if (pkt_dev->udp_dst_min < pkt_dev->udp_dst_max) {
1786 if (pkt_dev->flags & F_UDPDST_RND) { 1868 if (pkt_dev->flags & F_UDPDST_RND) {
1787 pkt_dev->cur_udp_dst = ((pktgen_random() % (pkt_dev->udp_dst_max - pkt_dev->udp_dst_min)) + pkt_dev->udp_dst_min); 1869 pkt_dev->cur_udp_dst =
1788 } 1870 ((pktgen_random() %
1789 else { 1871 (pkt_dev->udp_dst_max - pkt_dev->udp_dst_min)) +
1872 pkt_dev->udp_dst_min);
1873 } else {
1790 pkt_dev->cur_udp_dst++; 1874 pkt_dev->cur_udp_dst++;
1791 if (pkt_dev->cur_udp_dst >= pkt_dev->udp_dst_max) 1875 if (pkt_dev->cur_udp_dst >= pkt_dev->udp_dst_max)
1792 pkt_dev->cur_udp_dst = pkt_dev->udp_dst_min; 1876 pkt_dev->cur_udp_dst = pkt_dev->udp_dst_min;
1793 } 1877 }
1794 } 1878 }
1795 1879
1796 if (!(pkt_dev->flags & F_IPV6)) { 1880 if (!(pkt_dev->flags & F_IPV6)) {
1797 1881
1798 if ((imn = ntohl(pkt_dev->saddr_min)) < (imx = ntohl(pkt_dev->saddr_max))) { 1882 if ((imn = ntohl(pkt_dev->saddr_min)) < (imx =
1883 ntohl(pkt_dev->
1884 saddr_max))) {
1799 __u32 t; 1885 __u32 t;
1800 if (pkt_dev->flags & F_IPSRC_RND) 1886 if (pkt_dev->flags & F_IPSRC_RND)
1801 t = ((pktgen_random() % (imx - imn)) + imn); 1887 t = ((pktgen_random() % (imx - imn)) + imn);
1802 else { 1888 else {
1803 t = ntohl(pkt_dev->cur_saddr); 1889 t = ntohl(pkt_dev->cur_saddr);
@@ -1808,25 +1894,32 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev) {
1808 } 1894 }
1809 pkt_dev->cur_saddr = htonl(t); 1895 pkt_dev->cur_saddr = htonl(t);
1810 } 1896 }
1811 1897
1812 if (pkt_dev->cflows && pkt_dev->flows[flow].count != 0) { 1898 if (pkt_dev->cflows && pkt_dev->flows[flow].count != 0) {
1813 pkt_dev->cur_daddr = pkt_dev->flows[flow].cur_daddr; 1899 pkt_dev->cur_daddr = pkt_dev->flows[flow].cur_daddr;
1814 } else { 1900 } else {
1815 1901
1816 if ((imn = ntohl(pkt_dev->daddr_min)) < (imx = ntohl(pkt_dev->daddr_max))) { 1902 if ((imn = ntohl(pkt_dev->daddr_min)) < (imx =
1903 ntohl(pkt_dev->
1904 daddr_max)))
1905 {
1817 __u32 t; 1906 __u32 t;
1818 if (pkt_dev->flags & F_IPDST_RND) { 1907 if (pkt_dev->flags & F_IPDST_RND) {
1819 1908
1820 t = ((pktgen_random() % (imx - imn)) + imn); 1909 t = ((pktgen_random() % (imx - imn)) +
1910 imn);
1821 t = htonl(t); 1911 t = htonl(t);
1822 1912
1823 while( LOOPBACK(t) || MULTICAST(t) || BADCLASS(t) || ZERONET(t) || LOCAL_MCAST(t) ) { 1913 while (LOOPBACK(t) || MULTICAST(t)
1824 t = ((pktgen_random() % (imx - imn)) + imn); 1914 || BADCLASS(t) || ZERONET(t)
1915 || LOCAL_MCAST(t)) {
1916 t = ((pktgen_random() %
1917 (imx - imn)) + imn);
1825 t = htonl(t); 1918 t = htonl(t);
1826 } 1919 }
1827 pkt_dev->cur_daddr = t; 1920 pkt_dev->cur_daddr = t;
1828 } 1921 }
1829 1922
1830 else { 1923 else {
1831 t = ntohl(pkt_dev->cur_daddr); 1924 t = ntohl(pkt_dev->cur_daddr);
1832 t++; 1925 t++;
@@ -1836,60 +1929,59 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev) {
1836 pkt_dev->cur_daddr = htonl(t); 1929 pkt_dev->cur_daddr = htonl(t);
1837 } 1930 }
1838 } 1931 }
1839 if(pkt_dev->cflows) { 1932 if (pkt_dev->cflows) {
1840 pkt_dev->flows[flow].cur_daddr = pkt_dev->cur_daddr; 1933 pkt_dev->flows[flow].cur_daddr =
1934 pkt_dev->cur_daddr;
1841 pkt_dev->nflows++; 1935 pkt_dev->nflows++;
1842 } 1936 }
1843 } 1937 }
1844 } 1938 } else { /* IPV6 * */
1845 else /* IPV6 * */ 1939
1846 { 1940 if (pkt_dev->min_in6_daddr.s6_addr32[0] == 0 &&
1847 if(pkt_dev->min_in6_daddr.s6_addr32[0] == 0 && 1941 pkt_dev->min_in6_daddr.s6_addr32[1] == 0 &&
1848 pkt_dev->min_in6_daddr.s6_addr32[1] == 0 && 1942 pkt_dev->min_in6_daddr.s6_addr32[2] == 0 &&
1849 pkt_dev->min_in6_daddr.s6_addr32[2] == 0 && 1943 pkt_dev->min_in6_daddr.s6_addr32[3] == 0) ;
1850 pkt_dev->min_in6_daddr.s6_addr32[3] == 0);
1851 else { 1944 else {
1852 int i; 1945 int i;
1853 1946
1854 /* Only random destinations yet */ 1947 /* Only random destinations yet */
1855 1948
1856 for(i=0; i < 4; i++) { 1949 for (i = 0; i < 4; i++) {
1857 pkt_dev->cur_in6_daddr.s6_addr32[i] = 1950 pkt_dev->cur_in6_daddr.s6_addr32[i] =
1858 ((pktgen_random() | 1951 ((pktgen_random() |
1859 pkt_dev->min_in6_daddr.s6_addr32[i]) & 1952 pkt_dev->min_in6_daddr.s6_addr32[i]) &
1860 pkt_dev->max_in6_daddr.s6_addr32[i]); 1953 pkt_dev->max_in6_daddr.s6_addr32[i]);
1861 } 1954 }
1862 } 1955 }
1863 } 1956 }
1864 1957
1865 if (pkt_dev->min_pkt_size < pkt_dev->max_pkt_size) { 1958 if (pkt_dev->min_pkt_size < pkt_dev->max_pkt_size) {
1866 __u32 t; 1959 __u32 t;
1867 if (pkt_dev->flags & F_TXSIZE_RND) { 1960 if (pkt_dev->flags & F_TXSIZE_RND) {
1868 t = ((pktgen_random() % (pkt_dev->max_pkt_size - pkt_dev->min_pkt_size)) 1961 t = ((pktgen_random() %
1869 + pkt_dev->min_pkt_size); 1962 (pkt_dev->max_pkt_size - pkt_dev->min_pkt_size))
1870 } 1963 + pkt_dev->min_pkt_size);
1871 else { 1964 } else {
1872 t = pkt_dev->cur_pkt_size + 1; 1965 t = pkt_dev->cur_pkt_size + 1;
1873 if (t > pkt_dev->max_pkt_size) 1966 if (t > pkt_dev->max_pkt_size)
1874 t = pkt_dev->min_pkt_size; 1967 t = pkt_dev->min_pkt_size;
1875 } 1968 }
1876 pkt_dev->cur_pkt_size = t; 1969 pkt_dev->cur_pkt_size = t;
1877 } 1970 }
1878 1971
1879 pkt_dev->flows[flow].count++; 1972 pkt_dev->flows[flow].count++;
1880} 1973}
1881 1974
1882 1975static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
1883static struct sk_buff *fill_packet_ipv4(struct net_device *odev, 1976 struct pktgen_dev *pkt_dev)
1884 struct pktgen_dev *pkt_dev)
1885{ 1977{
1886 struct sk_buff *skb = NULL; 1978 struct sk_buff *skb = NULL;
1887 __u8 *eth; 1979 __u8 *eth;
1888 struct udphdr *udph; 1980 struct udphdr *udph;
1889 int datalen, iplen; 1981 int datalen, iplen;
1890 struct iphdr *iph; 1982 struct iphdr *iph;
1891 struct pktgen_hdr *pgh = NULL; 1983 struct pktgen_hdr *pgh = NULL;
1892 1984
1893 /* Update any of the values, used when we're incrementing various 1985 /* Update any of the values, used when we're incrementing various
1894 * fields. 1986 * fields.
1895 */ 1987 */
@@ -1910,47 +2002,47 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
1910 udph = (struct udphdr *)skb_put(skb, sizeof(struct udphdr)); 2002 udph = (struct udphdr *)skb_put(skb, sizeof(struct udphdr));
1911 2003
1912 memcpy(eth, pkt_dev->hh, 12); 2004 memcpy(eth, pkt_dev->hh, 12);
1913 *(u16*)&eth[12] = __constant_htons(ETH_P_IP); 2005 *(u16 *) & eth[12] = __constant_htons(ETH_P_IP);
1914 2006
1915 datalen = pkt_dev->cur_pkt_size - 14 - 20 - 8; /* Eth + IPh + UDPh */ 2007 datalen = pkt_dev->cur_pkt_size - 14 - 20 - 8; /* Eth + IPh + UDPh */
1916 if (datalen < sizeof(struct pktgen_hdr)) 2008 if (datalen < sizeof(struct pktgen_hdr))
1917 datalen = sizeof(struct pktgen_hdr); 2009 datalen = sizeof(struct pktgen_hdr);
1918 2010
1919 udph->source = htons(pkt_dev->cur_udp_src); 2011 udph->source = htons(pkt_dev->cur_udp_src);
1920 udph->dest = htons(pkt_dev->cur_udp_dst); 2012 udph->dest = htons(pkt_dev->cur_udp_dst);
1921 udph->len = htons(datalen + 8); /* DATA + udphdr */ 2013 udph->len = htons(datalen + 8); /* DATA + udphdr */
1922 udph->check = 0; /* No checksum */ 2014 udph->check = 0; /* No checksum */
1923 2015
1924 iph->ihl = 5; 2016 iph->ihl = 5;
1925 iph->version = 4; 2017 iph->version = 4;
1926 iph->ttl = 32; 2018 iph->ttl = 32;
1927 iph->tos = 0; 2019 iph->tos = 0;
1928 iph->protocol = IPPROTO_UDP; /* UDP */ 2020 iph->protocol = IPPROTO_UDP; /* UDP */
1929 iph->saddr = pkt_dev->cur_saddr; 2021 iph->saddr = pkt_dev->cur_saddr;
1930 iph->daddr = pkt_dev->cur_daddr; 2022 iph->daddr = pkt_dev->cur_daddr;
1931 iph->frag_off = 0; 2023 iph->frag_off = 0;
1932 iplen = 20 + 8 + datalen; 2024 iplen = 20 + 8 + datalen;
1933 iph->tot_len = htons(iplen); 2025 iph->tot_len = htons(iplen);
1934 iph->check = 0; 2026 iph->check = 0;
1935 iph->check = ip_fast_csum((void *) iph, iph->ihl); 2027 iph->check = ip_fast_csum((void *)iph, iph->ihl);
1936 skb->protocol = __constant_htons(ETH_P_IP); 2028 skb->protocol = __constant_htons(ETH_P_IP);
1937 skb->mac.raw = ((u8 *)iph) - 14; 2029 skb->mac.raw = ((u8 *) iph) - 14;
1938 skb->dev = odev; 2030 skb->dev = odev;
1939 skb->pkt_type = PACKET_HOST; 2031 skb->pkt_type = PACKET_HOST;
1940 2032
1941 if (pkt_dev->nfrags <= 0) 2033 if (pkt_dev->nfrags <= 0)
1942 pgh = (struct pktgen_hdr *)skb_put(skb, datalen); 2034 pgh = (struct pktgen_hdr *)skb_put(skb, datalen);
1943 else { 2035 else {
1944 int frags = pkt_dev->nfrags; 2036 int frags = pkt_dev->nfrags;
1945 int i; 2037 int i;
1946 2038
1947 pgh = (struct pktgen_hdr*)(((char*)(udph)) + 8); 2039 pgh = (struct pktgen_hdr *)(((char *)(udph)) + 8);
1948 2040
1949 if (frags > MAX_SKB_FRAGS) 2041 if (frags > MAX_SKB_FRAGS)
1950 frags = MAX_SKB_FRAGS; 2042 frags = MAX_SKB_FRAGS;
1951 if (datalen > frags*PAGE_SIZE) { 2043 if (datalen > frags * PAGE_SIZE) {
1952 skb_put(skb, datalen-frags*PAGE_SIZE); 2044 skb_put(skb, datalen - frags * PAGE_SIZE);
1953 datalen = frags*PAGE_SIZE; 2045 datalen = frags * PAGE_SIZE;
1954 } 2046 }
1955 2047
1956 i = 0; 2048 i = 0;
@@ -1959,7 +2051,7 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
1959 skb_shinfo(skb)->frags[i].page = page; 2051 skb_shinfo(skb)->frags[i].page = page;
1960 skb_shinfo(skb)->frags[i].page_offset = 0; 2052 skb_shinfo(skb)->frags[i].page_offset = 0;
1961 skb_shinfo(skb)->frags[i].size = 2053 skb_shinfo(skb)->frags[i].size =
1962 (datalen < PAGE_SIZE ? datalen : PAGE_SIZE); 2054 (datalen < PAGE_SIZE ? datalen : PAGE_SIZE);
1963 datalen -= skb_shinfo(skb)->frags[i].size; 2055 datalen -= skb_shinfo(skb)->frags[i].size;
1964 skb->len += skb_shinfo(skb)->frags[i].size; 2056 skb->len += skb_shinfo(skb)->frags[i].size;
1965 skb->data_len += skb_shinfo(skb)->frags[i].size; 2057 skb->data_len += skb_shinfo(skb)->frags[i].size;
@@ -1979,30 +2071,33 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
1979 2071
1980 skb_shinfo(skb)->frags[i - 1].size -= rem; 2072 skb_shinfo(skb)->frags[i - 1].size -= rem;
1981 2073
1982 skb_shinfo(skb)->frags[i] = skb_shinfo(skb)->frags[i - 1]; 2074 skb_shinfo(skb)->frags[i] =
2075 skb_shinfo(skb)->frags[i - 1];
1983 get_page(skb_shinfo(skb)->frags[i].page); 2076 get_page(skb_shinfo(skb)->frags[i].page);
1984 skb_shinfo(skb)->frags[i].page = skb_shinfo(skb)->frags[i - 1].page; 2077 skb_shinfo(skb)->frags[i].page =
1985 skb_shinfo(skb)->frags[i].page_offset += skb_shinfo(skb)->frags[i - 1].size; 2078 skb_shinfo(skb)->frags[i - 1].page;
2079 skb_shinfo(skb)->frags[i].page_offset +=
2080 skb_shinfo(skb)->frags[i - 1].size;
1986 skb_shinfo(skb)->frags[i].size = rem; 2081 skb_shinfo(skb)->frags[i].size = rem;
1987 i++; 2082 i++;
1988 skb_shinfo(skb)->nr_frags = i; 2083 skb_shinfo(skb)->nr_frags = i;
1989 } 2084 }
1990 } 2085 }
1991 2086
1992 /* Stamp the time, and sequence number, convert them to network byte order */ 2087 /* Stamp the time, and sequence number, convert them to network byte order */
2088
2089 if (pgh) {
2090 struct timeval timestamp;
2091
2092 pgh->pgh_magic = htonl(PKTGEN_MAGIC);
2093 pgh->seq_num = htonl(pkt_dev->seq_num);
2094
2095 do_gettimeofday(&timestamp);
2096 pgh->tv_sec = htonl(timestamp.tv_sec);
2097 pgh->tv_usec = htonl(timestamp.tv_usec);
2098 }
2099 pkt_dev->seq_num++;
1993 2100
1994 if (pgh) {
1995 struct timeval timestamp;
1996
1997 pgh->pgh_magic = htonl(PKTGEN_MAGIC);
1998 pgh->seq_num = htonl(pkt_dev->seq_num);
1999
2000 do_gettimeofday(&timestamp);
2001 pgh->tv_sec = htonl(timestamp.tv_sec);
2002 pgh->tv_usec = htonl(timestamp.tv_usec);
2003 }
2004 pkt_dev->seq_num++;
2005
2006 return skb; 2101 return skb;
2007} 2102}
2008 2103
@@ -2015,23 +2110,24 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
2015 * --ro 2110 * --ro
2016 */ 2111 */
2017 2112
2018static unsigned int scan_ip6(const char *s,char ip[16]) 2113static unsigned int scan_ip6(const char *s, char ip[16])
2019{ 2114{
2020 unsigned int i; 2115 unsigned int i;
2021 unsigned int len=0; 2116 unsigned int len = 0;
2022 unsigned long u; 2117 unsigned long u;
2023 char suffix[16]; 2118 char suffix[16];
2024 unsigned int prefixlen=0; 2119 unsigned int prefixlen = 0;
2025 unsigned int suffixlen=0; 2120 unsigned int suffixlen = 0;
2026 __u32 tmp; 2121 __u32 tmp;
2027 2122
2028 for (i=0; i<16; i++) ip[i]=0; 2123 for (i = 0; i < 16; i++)
2124 ip[i] = 0;
2029 2125
2030 for (;;) { 2126 for (;;) {
2031 if (*s == ':') { 2127 if (*s == ':') {
2032 len++; 2128 len++;
2033 if (s[1] == ':') { /* Found "::", skip to part 2 */ 2129 if (s[1] == ':') { /* Found "::", skip to part 2 */
2034 s+=2; 2130 s += 2;
2035 len++; 2131 len++;
2036 break; 2132 break;
2037 } 2133 }
@@ -2039,129 +2135,149 @@ static unsigned int scan_ip6(const char *s,char ip[16])
2039 } 2135 }
2040 { 2136 {
2041 char *tmp; 2137 char *tmp;
2042 u=simple_strtoul(s,&tmp,16); 2138 u = simple_strtoul(s, &tmp, 16);
2043 i=tmp-s; 2139 i = tmp - s;
2044 } 2140 }
2045 2141
2046 if (!i) return 0; 2142 if (!i)
2047 if (prefixlen==12 && s[i]=='.') { 2143 return 0;
2144 if (prefixlen == 12 && s[i] == '.') {
2048 2145
2049 /* the last 4 bytes may be written as IPv4 address */ 2146 /* the last 4 bytes may be written as IPv4 address */
2050 2147
2051 tmp = in_aton(s); 2148 tmp = in_aton(s);
2052 memcpy((struct in_addr*)(ip+12), &tmp, sizeof(tmp)); 2149 memcpy((struct in_addr *)(ip + 12), &tmp, sizeof(tmp));
2053 return i+len; 2150 return i + len;
2054 } 2151 }
2055 ip[prefixlen++] = (u >> 8); 2152 ip[prefixlen++] = (u >> 8);
2056 ip[prefixlen++] = (u & 255); 2153 ip[prefixlen++] = (u & 255);
2057 s += i; len += i; 2154 s += i;
2058 if (prefixlen==16) 2155 len += i;
2156 if (prefixlen == 16)
2059 return len; 2157 return len;
2060 } 2158 }
2061 2159
2062/* part 2, after "::" */ 2160/* part 2, after "::" */
2063 for (;;) { 2161 for (;;) {
2064 if (*s == ':') { 2162 if (*s == ':') {
2065 if (suffixlen==0) 2163 if (suffixlen == 0)
2066 break; 2164 break;
2067 s++; 2165 s++;
2068 len++; 2166 len++;
2069 } else if (suffixlen!=0) 2167 } else if (suffixlen != 0)
2070 break; 2168 break;
2071 { 2169 {
2072 char *tmp; 2170 char *tmp;
2073 u=simple_strtol(s,&tmp,16); 2171 u = simple_strtol(s, &tmp, 16);
2074 i=tmp-s; 2172 i = tmp - s;
2075 } 2173 }
2076 if (!i) { 2174 if (!i) {
2077 if (*s) len--; 2175 if (*s)
2176 len--;
2078 break; 2177 break;
2079 } 2178 }
2080 if (suffixlen+prefixlen<=12 && s[i]=='.') { 2179 if (suffixlen + prefixlen <= 12 && s[i] == '.') {
2081 tmp = in_aton(s); 2180 tmp = in_aton(s);
2082 memcpy((struct in_addr*)(suffix+suffixlen), &tmp, sizeof(tmp)); 2181 memcpy((struct in_addr *)(suffix + suffixlen), &tmp,
2083 suffixlen+=4; 2182 sizeof(tmp));
2084 len+=strlen(s); 2183 suffixlen += 4;
2184 len += strlen(s);
2085 break; 2185 break;
2086 } 2186 }
2087 suffix[suffixlen++] = (u >> 8); 2187 suffix[suffixlen++] = (u >> 8);
2088 suffix[suffixlen++] = (u & 255); 2188 suffix[suffixlen++] = (u & 255);
2089 s += i; len += i; 2189 s += i;
2090 if (prefixlen+suffixlen==16) 2190 len += i;
2191 if (prefixlen + suffixlen == 16)
2091 break; 2192 break;
2092 } 2193 }
2093 for (i=0; i<suffixlen; i++) 2194 for (i = 0; i < suffixlen; i++)
2094 ip[16-suffixlen+i] = suffix[i]; 2195 ip[16 - suffixlen + i] = suffix[i];
2095 return len; 2196 return len;
2096} 2197}
2097 2198
2098static char tohex(char hexdigit) { 2199static char tohex(char hexdigit)
2099 return hexdigit>9?hexdigit+'a'-10:hexdigit+'0'; 2200{
2201 return hexdigit > 9 ? hexdigit + 'a' - 10 : hexdigit + '0';
2100} 2202}
2101 2203
2102static int fmt_xlong(char* s,unsigned int i) { 2204static int fmt_xlong(char *s, unsigned int i)
2103 char* bak=s; 2205{
2104 *s=tohex((i>>12)&0xf); if (s!=bak || *s!='0') ++s; 2206 char *bak = s;
2105 *s=tohex((i>>8)&0xf); if (s!=bak || *s!='0') ++s; 2207 *s = tohex((i >> 12) & 0xf);
2106 *s=tohex((i>>4)&0xf); if (s!=bak || *s!='0') ++s; 2208 if (s != bak || *s != '0')
2107 *s=tohex(i&0xf); 2209 ++s;
2108 return s-bak+1; 2210 *s = tohex((i >> 8) & 0xf);
2211 if (s != bak || *s != '0')
2212 ++s;
2213 *s = tohex((i >> 4) & 0xf);
2214 if (s != bak || *s != '0')
2215 ++s;
2216 *s = tohex(i & 0xf);
2217 return s - bak + 1;
2109} 2218}
2110 2219
2111static unsigned int fmt_ip6(char *s,const char ip[16]) { 2220static unsigned int fmt_ip6(char *s, const char ip[16])
2221{
2112 unsigned int len; 2222 unsigned int len;
2113 unsigned int i; 2223 unsigned int i;
2114 unsigned int temp; 2224 unsigned int temp;
2115 unsigned int compressing; 2225 unsigned int compressing;
2116 int j; 2226 int j;
2117 2227
2118 len = 0; compressing = 0; 2228 len = 0;
2119 for (j=0; j<16; j+=2) { 2229 compressing = 0;
2230 for (j = 0; j < 16; j += 2) {
2120 2231
2121#ifdef V4MAPPEDPREFIX 2232#ifdef V4MAPPEDPREFIX
2122 if (j==12 && !memcmp(ip,V4mappedprefix,12)) { 2233 if (j == 12 && !memcmp(ip, V4mappedprefix, 12)) {
2123 inet_ntoa_r(*(struct in_addr*)(ip+12),s); 2234 inet_ntoa_r(*(struct in_addr *)(ip + 12), s);
2124 temp=strlen(s); 2235 temp = strlen(s);
2125 return len+temp; 2236 return len + temp;
2126 } 2237 }
2127#endif 2238#endif
2128 temp = ((unsigned long) (unsigned char) ip[j] << 8) + 2239 temp = ((unsigned long)(unsigned char)ip[j] << 8) +
2129 (unsigned long) (unsigned char) ip[j+1]; 2240 (unsigned long)(unsigned char)ip[j + 1];
2130 if (temp == 0) { 2241 if (temp == 0) {
2131 if (!compressing) { 2242 if (!compressing) {
2132 compressing=1; 2243 compressing = 1;
2133 if (j==0) { 2244 if (j == 0) {
2134 *s++=':'; ++len; 2245 *s++ = ':';
2246 ++len;
2135 } 2247 }
2136 } 2248 }
2137 } else { 2249 } else {
2138 if (compressing) { 2250 if (compressing) {
2139 compressing=0; 2251 compressing = 0;
2140 *s++=':'; ++len; 2252 *s++ = ':';
2253 ++len;
2141 } 2254 }
2142 i = fmt_xlong(s,temp); len += i; s += i; 2255 i = fmt_xlong(s, temp);
2143 if (j<14) { 2256 len += i;
2257 s += i;
2258 if (j < 14) {
2144 *s++ = ':'; 2259 *s++ = ':';
2145 ++len; 2260 ++len;
2146 } 2261 }
2147 } 2262 }
2148 } 2263 }
2149 if (compressing) { 2264 if (compressing) {
2150 *s++=':'; ++len; 2265 *s++ = ':';
2266 ++len;
2151 } 2267 }
2152 *s=0; 2268 *s = 0;
2153 return len; 2269 return len;
2154} 2270}
2155 2271
2156static struct sk_buff *fill_packet_ipv6(struct net_device *odev, 2272static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
2157 struct pktgen_dev *pkt_dev) 2273 struct pktgen_dev *pkt_dev)
2158{ 2274{
2159 struct sk_buff *skb = NULL; 2275 struct sk_buff *skb = NULL;
2160 __u8 *eth; 2276 __u8 *eth;
2161 struct udphdr *udph; 2277 struct udphdr *udph;
2162 int datalen; 2278 int datalen;
2163 struct ipv6hdr *iph; 2279 struct ipv6hdr *iph;
2164 struct pktgen_hdr *pgh = NULL; 2280 struct pktgen_hdr *pgh = NULL;
2165 2281
2166 /* Update any of the values, used when we're incrementing various 2282 /* Update any of the values, used when we're incrementing various
2167 * fields. 2283 * fields.
@@ -2182,23 +2298,23 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
2182 udph = (struct udphdr *)skb_put(skb, sizeof(struct udphdr)); 2298 udph = (struct udphdr *)skb_put(skb, sizeof(struct udphdr));
2183 2299
2184 memcpy(eth, pkt_dev->hh, 12); 2300 memcpy(eth, pkt_dev->hh, 12);
2185 *(u16*)&eth[12] = __constant_htons(ETH_P_IPV6); 2301 *(u16 *) & eth[12] = __constant_htons(ETH_P_IPV6);
2186 2302
2187 datalen = pkt_dev->cur_pkt_size-14- 2303 datalen = pkt_dev->cur_pkt_size - 14 - sizeof(struct ipv6hdr) - sizeof(struct udphdr); /* Eth + IPh + UDPh */
2188 sizeof(struct ipv6hdr)-sizeof(struct udphdr); /* Eth + IPh + UDPh */
2189 2304
2190 if (datalen < sizeof(struct pktgen_hdr)) { 2305 if (datalen < sizeof(struct pktgen_hdr)) {
2191 datalen = sizeof(struct pktgen_hdr); 2306 datalen = sizeof(struct pktgen_hdr);
2192 if (net_ratelimit()) 2307 if (net_ratelimit())
2193 printk(KERN_INFO "pktgen: increased datalen to %d\n", datalen); 2308 printk(KERN_INFO "pktgen: increased datalen to %d\n",
2309 datalen);
2194 } 2310 }
2195 2311
2196 udph->source = htons(pkt_dev->cur_udp_src); 2312 udph->source = htons(pkt_dev->cur_udp_src);
2197 udph->dest = htons(pkt_dev->cur_udp_dst); 2313 udph->dest = htons(pkt_dev->cur_udp_dst);
2198 udph->len = htons(datalen + sizeof(struct udphdr)); 2314 udph->len = htons(datalen + sizeof(struct udphdr));
2199 udph->check = 0; /* No checksum */ 2315 udph->check = 0; /* No checksum */
2200 2316
2201 *(u32*)iph = __constant_htonl(0x60000000); /* Version + flow */ 2317 *(u32 *) iph = __constant_htonl(0x60000000); /* Version + flow */
2202 2318
2203 iph->hop_limit = 32; 2319 iph->hop_limit = 32;
2204 2320
@@ -2208,24 +2324,24 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
2208 ipv6_addr_copy(&iph->daddr, &pkt_dev->cur_in6_daddr); 2324 ipv6_addr_copy(&iph->daddr, &pkt_dev->cur_in6_daddr);
2209 ipv6_addr_copy(&iph->saddr, &pkt_dev->cur_in6_saddr); 2325 ipv6_addr_copy(&iph->saddr, &pkt_dev->cur_in6_saddr);
2210 2326
2211 skb->mac.raw = ((u8 *)iph) - 14; 2327 skb->mac.raw = ((u8 *) iph) - 14;
2212 skb->protocol = __constant_htons(ETH_P_IPV6); 2328 skb->protocol = __constant_htons(ETH_P_IPV6);
2213 skb->dev = odev; 2329 skb->dev = odev;
2214 skb->pkt_type = PACKET_HOST; 2330 skb->pkt_type = PACKET_HOST;
2215 2331
2216 if (pkt_dev->nfrags <= 0) 2332 if (pkt_dev->nfrags <= 0)
2217 pgh = (struct pktgen_hdr *)skb_put(skb, datalen); 2333 pgh = (struct pktgen_hdr *)skb_put(skb, datalen);
2218 else { 2334 else {
2219 int frags = pkt_dev->nfrags; 2335 int frags = pkt_dev->nfrags;
2220 int i; 2336 int i;
2221 2337
2222 pgh = (struct pktgen_hdr*)(((char*)(udph)) + 8); 2338 pgh = (struct pktgen_hdr *)(((char *)(udph)) + 8);
2223 2339
2224 if (frags > MAX_SKB_FRAGS) 2340 if (frags > MAX_SKB_FRAGS)
2225 frags = MAX_SKB_FRAGS; 2341 frags = MAX_SKB_FRAGS;
2226 if (datalen > frags*PAGE_SIZE) { 2342 if (datalen > frags * PAGE_SIZE) {
2227 skb_put(skb, datalen-frags*PAGE_SIZE); 2343 skb_put(skb, datalen - frags * PAGE_SIZE);
2228 datalen = frags*PAGE_SIZE; 2344 datalen = frags * PAGE_SIZE;
2229 } 2345 }
2230 2346
2231 i = 0; 2347 i = 0;
@@ -2234,7 +2350,7 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
2234 skb_shinfo(skb)->frags[i].page = page; 2350 skb_shinfo(skb)->frags[i].page = page;
2235 skb_shinfo(skb)->frags[i].page_offset = 0; 2351 skb_shinfo(skb)->frags[i].page_offset = 0;
2236 skb_shinfo(skb)->frags[i].size = 2352 skb_shinfo(skb)->frags[i].size =
2237 (datalen < PAGE_SIZE ? datalen : PAGE_SIZE); 2353 (datalen < PAGE_SIZE ? datalen : PAGE_SIZE);
2238 datalen -= skb_shinfo(skb)->frags[i].size; 2354 datalen -= skb_shinfo(skb)->frags[i].size;
2239 skb->len += skb_shinfo(skb)->frags[i].size; 2355 skb->len += skb_shinfo(skb)->frags[i].size;
2240 skb->data_len += skb_shinfo(skb)->frags[i].size; 2356 skb->data_len += skb_shinfo(skb)->frags[i].size;
@@ -2254,151 +2370,155 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
2254 2370
2255 skb_shinfo(skb)->frags[i - 1].size -= rem; 2371 skb_shinfo(skb)->frags[i - 1].size -= rem;
2256 2372
2257 skb_shinfo(skb)->frags[i] = skb_shinfo(skb)->frags[i - 1]; 2373 skb_shinfo(skb)->frags[i] =
2374 skb_shinfo(skb)->frags[i - 1];
2258 get_page(skb_shinfo(skb)->frags[i].page); 2375 get_page(skb_shinfo(skb)->frags[i].page);
2259 skb_shinfo(skb)->frags[i].page = skb_shinfo(skb)->frags[i - 1].page; 2376 skb_shinfo(skb)->frags[i].page =
2260 skb_shinfo(skb)->frags[i].page_offset += skb_shinfo(skb)->frags[i - 1].size; 2377 skb_shinfo(skb)->frags[i - 1].page;
2378 skb_shinfo(skb)->frags[i].page_offset +=
2379 skb_shinfo(skb)->frags[i - 1].size;
2261 skb_shinfo(skb)->frags[i].size = rem; 2380 skb_shinfo(skb)->frags[i].size = rem;
2262 i++; 2381 i++;
2263 skb_shinfo(skb)->nr_frags = i; 2382 skb_shinfo(skb)->nr_frags = i;
2264 } 2383 }
2265 } 2384 }
2266 2385
2267 /* Stamp the time, and sequence number, convert them to network byte order */ 2386 /* Stamp the time, and sequence number, convert them to network byte order */
2268 /* should we update cloned packets too ? */ 2387 /* should we update cloned packets too ? */
2269 if (pgh) { 2388 if (pgh) {
2270 struct timeval timestamp; 2389 struct timeval timestamp;
2271 2390
2272 pgh->pgh_magic = htonl(PKTGEN_MAGIC); 2391 pgh->pgh_magic = htonl(PKTGEN_MAGIC);
2273 pgh->seq_num = htonl(pkt_dev->seq_num); 2392 pgh->seq_num = htonl(pkt_dev->seq_num);
2274 2393
2275 do_gettimeofday(&timestamp); 2394 do_gettimeofday(&timestamp);
2276 pgh->tv_sec = htonl(timestamp.tv_sec); 2395 pgh->tv_sec = htonl(timestamp.tv_sec);
2277 pgh->tv_usec = htonl(timestamp.tv_usec); 2396 pgh->tv_usec = htonl(timestamp.tv_usec);
2278 } 2397 }
2279 pkt_dev->seq_num++; 2398 pkt_dev->seq_num++;
2280 2399
2281 return skb; 2400 return skb;
2282} 2401}
2283 2402
2284static inline struct sk_buff *fill_packet(struct net_device *odev, 2403static inline struct sk_buff *fill_packet(struct net_device *odev,
2285 struct pktgen_dev *pkt_dev) 2404 struct pktgen_dev *pkt_dev)
2286{ 2405{
2287 if(pkt_dev->flags & F_IPV6) 2406 if (pkt_dev->flags & F_IPV6)
2288 return fill_packet_ipv6(odev, pkt_dev); 2407 return fill_packet_ipv6(odev, pkt_dev);
2289 else 2408 else
2290 return fill_packet_ipv4(odev, pkt_dev); 2409 return fill_packet_ipv4(odev, pkt_dev);
2291} 2410}
2292 2411
2293static void pktgen_clear_counters(struct pktgen_dev *pkt_dev) 2412static void pktgen_clear_counters(struct pktgen_dev *pkt_dev)
2294{ 2413{
2295 pkt_dev->seq_num = 1; 2414 pkt_dev->seq_num = 1;
2296 pkt_dev->idle_acc = 0; 2415 pkt_dev->idle_acc = 0;
2297 pkt_dev->sofar = 0; 2416 pkt_dev->sofar = 0;
2298 pkt_dev->tx_bytes = 0; 2417 pkt_dev->tx_bytes = 0;
2299 pkt_dev->errors = 0; 2418 pkt_dev->errors = 0;
2300} 2419}
2301 2420
2302/* Set up structure for sending pkts, clear counters */ 2421/* Set up structure for sending pkts, clear counters */
2303 2422
2304static void pktgen_run(struct pktgen_thread *t) 2423static void pktgen_run(struct pktgen_thread *t)
2305{ 2424{
2306 struct pktgen_dev *pkt_dev = NULL; 2425 struct pktgen_dev *pkt_dev = NULL;
2307 int started = 0; 2426 int started = 0;
2308 2427
2309 PG_DEBUG(printk("pktgen: entering pktgen_run. %p\n", t)); 2428 PG_DEBUG(printk("pktgen: entering pktgen_run. %p\n", t));
2310 2429
2311 if_lock(t); 2430 if_lock(t);
2312 for (pkt_dev = t->if_list; pkt_dev; pkt_dev = pkt_dev->next ) { 2431 for (pkt_dev = t->if_list; pkt_dev; pkt_dev = pkt_dev->next) {
2313 2432
2314 /* 2433 /*
2315 * setup odev and create initial packet. 2434 * setup odev and create initial packet.
2316 */ 2435 */
2317 pktgen_setup_inject(pkt_dev); 2436 pktgen_setup_inject(pkt_dev);
2318 2437
2319 if(pkt_dev->odev) { 2438 if (pkt_dev->odev) {
2320 pktgen_clear_counters(pkt_dev); 2439 pktgen_clear_counters(pkt_dev);
2321 pkt_dev->running = 1; /* Cranke yeself! */ 2440 pkt_dev->running = 1; /* Cranke yeself! */
2322 pkt_dev->skb = NULL; 2441 pkt_dev->skb = NULL;
2323 pkt_dev->started_at = getCurUs(); 2442 pkt_dev->started_at = getCurUs();
2324 pkt_dev->next_tx_us = getCurUs(); /* Transmit immediately */ 2443 pkt_dev->next_tx_us = getCurUs(); /* Transmit immediately */
2325 pkt_dev->next_tx_ns = 0; 2444 pkt_dev->next_tx_ns = 0;
2326 2445
2327 strcpy(pkt_dev->result, "Starting"); 2446 strcpy(pkt_dev->result, "Starting");
2328 started++; 2447 started++;
2329 } 2448 } else
2330 else
2331 strcpy(pkt_dev->result, "Error starting"); 2449 strcpy(pkt_dev->result, "Error starting");
2332 } 2450 }
2333 if_unlock(t); 2451 if_unlock(t);
2334 if(started) t->control &= ~(T_STOP); 2452 if (started)
2453 t->control &= ~(T_STOP);
2335} 2454}
2336 2455
2337static void pktgen_stop_all_threads_ifs(void) 2456static void pktgen_stop_all_threads_ifs(void)
2338{ 2457{
2339 struct pktgen_thread *t = pktgen_threads; 2458 struct pktgen_thread *t = pktgen_threads;
2340 2459
2341 PG_DEBUG(printk("pktgen: entering pktgen_stop_all_threads_ifs.\n")); 2460 PG_DEBUG(printk("pktgen: entering pktgen_stop_all_threads_ifs.\n"));
2342 2461
2343 thread_lock(); 2462 thread_lock();
2344 while(t) { 2463 while (t) {
2345 t->control |= T_STOP; 2464 t->control |= T_STOP;
2346 t = t->next; 2465 t = t->next;
2347 } 2466 }
2348 thread_unlock(); 2467 thread_unlock();
2349} 2468}
2350 2469
2351static int thread_is_running(struct pktgen_thread *t ) 2470static int thread_is_running(struct pktgen_thread *t)
2352{ 2471{
2353 struct pktgen_dev *next; 2472 struct pktgen_dev *next;
2354 int res = 0; 2473 int res = 0;
2355 2474
2356 for(next=t->if_list; next; next=next->next) { 2475 for (next = t->if_list; next; next = next->next) {
2357 if(next->running) { 2476 if (next->running) {
2358 res = 1; 2477 res = 1;
2359 break; 2478 break;
2360 } 2479 }
2361 } 2480 }
2362 return res; 2481 return res;
2363} 2482}
2364 2483
2365static int pktgen_wait_thread_run(struct pktgen_thread *t ) 2484static int pktgen_wait_thread_run(struct pktgen_thread *t)
2366{ 2485{
2367 if_lock(t); 2486 if_lock(t);
2368 2487
2369 while(thread_is_running(t)) { 2488 while (thread_is_running(t)) {
2370 2489
2371 if_unlock(t); 2490 if_unlock(t);
2372 2491
2373 msleep_interruptible(100); 2492 msleep_interruptible(100);
2374 2493
2375 if (signal_pending(current)) 2494 if (signal_pending(current))
2376 goto signal; 2495 goto signal;
2377 if_lock(t); 2496 if_lock(t);
2378 } 2497 }
2379 if_unlock(t); 2498 if_unlock(t);
2380 return 1; 2499 return 1;
2381 signal: 2500signal:
2382 return 0; 2501 return 0;
2383} 2502}
2384 2503
2385static int pktgen_wait_all_threads_run(void) 2504static int pktgen_wait_all_threads_run(void)
2386{ 2505{
2387 struct pktgen_thread *t = pktgen_threads; 2506 struct pktgen_thread *t = pktgen_threads;
2388 int sig = 1; 2507 int sig = 1;
2389 2508
2390 while (t) { 2509 while (t) {
2391 sig = pktgen_wait_thread_run(t); 2510 sig = pktgen_wait_thread_run(t);
2392 if( sig == 0 ) break; 2511 if (sig == 0)
2512 break;
2393 thread_lock(); 2513 thread_lock();
2394 t=t->next; 2514 t = t->next;
2395 thread_unlock(); 2515 thread_unlock();
2396 } 2516 }
2397 if(sig == 0) { 2517 if (sig == 0) {
2398 thread_lock(); 2518 thread_lock();
2399 while (t) { 2519 while (t) {
2400 t->control |= (T_STOP); 2520 t->control |= (T_STOP);
2401 t=t->next; 2521 t = t->next;
2402 } 2522 }
2403 thread_unlock(); 2523 thread_unlock();
2404 } 2524 }
@@ -2407,113 +2527,114 @@ static int pktgen_wait_all_threads_run(void)
2407 2527
2408static void pktgen_run_all_threads(void) 2528static void pktgen_run_all_threads(void)
2409{ 2529{
2410 struct pktgen_thread *t = pktgen_threads; 2530 struct pktgen_thread *t = pktgen_threads;
2411 2531
2412 PG_DEBUG(printk("pktgen: entering pktgen_run_all_threads.\n")); 2532 PG_DEBUG(printk("pktgen: entering pktgen_run_all_threads.\n"));
2413 2533
2414 thread_lock(); 2534 thread_lock();
2415 2535
2416 while(t) { 2536 while (t) {
2417 t->control |= (T_RUN); 2537 t->control |= (T_RUN);
2418 t = t->next; 2538 t = t->next;
2419 } 2539 }
2420 thread_unlock(); 2540 thread_unlock();
2421 2541
2422 schedule_timeout_interruptible(msecs_to_jiffies(125)); /* Propagate thread->control */ 2542 schedule_timeout_interruptible(msecs_to_jiffies(125)); /* Propagate thread->control */
2423 2543
2424 pktgen_wait_all_threads_run(); 2544 pktgen_wait_all_threads_run();
2425} 2545}
2426 2546
2427
2428static void show_results(struct pktgen_dev *pkt_dev, int nr_frags) 2547static void show_results(struct pktgen_dev *pkt_dev, int nr_frags)
2429{ 2548{
2430 __u64 total_us, bps, mbps, pps, idle; 2549 __u64 total_us, bps, mbps, pps, idle;
2431 char *p = pkt_dev->result; 2550 char *p = pkt_dev->result;
2432 2551
2433 total_us = pkt_dev->stopped_at - pkt_dev->started_at; 2552 total_us = pkt_dev->stopped_at - pkt_dev->started_at;
2434 2553
2435 idle = pkt_dev->idle_acc; 2554 idle = pkt_dev->idle_acc;
2436 2555
2437 p += sprintf(p, "OK: %llu(c%llu+d%llu) usec, %llu (%dbyte,%dfrags)\n", 2556 p += sprintf(p, "OK: %llu(c%llu+d%llu) usec, %llu (%dbyte,%dfrags)\n",
2438 (unsigned long long) total_us, 2557 (unsigned long long)total_us,
2439 (unsigned long long)(total_us - idle), 2558 (unsigned long long)(total_us - idle),
2440 (unsigned long long) idle, 2559 (unsigned long long)idle,
2441 (unsigned long long) pkt_dev->sofar, 2560 (unsigned long long)pkt_dev->sofar,
2442 pkt_dev->cur_pkt_size, nr_frags); 2561 pkt_dev->cur_pkt_size, nr_frags);
2443 2562
2444 pps = pkt_dev->sofar * USEC_PER_SEC; 2563 pps = pkt_dev->sofar * USEC_PER_SEC;
2445 2564
2446 while ((total_us >> 32) != 0) { 2565 while ((total_us >> 32) != 0) {
2447 pps >>= 1; 2566 pps >>= 1;
2448 total_us >>= 1; 2567 total_us >>= 1;
2449 } 2568 }
2450 2569
2451 do_div(pps, total_us); 2570 do_div(pps, total_us);
2452 2571
2453 bps = pps * 8 * pkt_dev->cur_pkt_size; 2572 bps = pps * 8 * pkt_dev->cur_pkt_size;
2454 2573
2455 mbps = bps; 2574 mbps = bps;
2456 do_div(mbps, 1000000); 2575 do_div(mbps, 1000000);
2457 p += sprintf(p, " %llupps %lluMb/sec (%llubps) errors: %llu", 2576 p += sprintf(p, " %llupps %lluMb/sec (%llubps) errors: %llu",
2458 (unsigned long long) pps, 2577 (unsigned long long)pps,
2459 (unsigned long long) mbps, 2578 (unsigned long long)mbps,
2460 (unsigned long long) bps, 2579 (unsigned long long)bps,
2461 (unsigned long long) pkt_dev->errors); 2580 (unsigned long long)pkt_dev->errors);
2462} 2581}
2463
2464 2582
2465/* Set stopped-at timer, remove from running list, do counters & statistics */ 2583/* Set stopped-at timer, remove from running list, do counters & statistics */
2466 2584
2467static int pktgen_stop_device(struct pktgen_dev *pkt_dev) 2585static int pktgen_stop_device(struct pktgen_dev *pkt_dev)
2468{ 2586{
2469 int nr_frags = pkt_dev->skb ? 2587 int nr_frags = pkt_dev->skb ? skb_shinfo(pkt_dev->skb)->nr_frags : -1;
2470 skb_shinfo(pkt_dev->skb)->nr_frags: -1;
2471 2588
2472 if (!pkt_dev->running) { 2589 if (!pkt_dev->running) {
2473 printk("pktgen: interface: %s is already stopped\n", pkt_dev->ifname); 2590 printk("pktgen: interface: %s is already stopped\n",
2474 return -EINVAL; 2591 pkt_dev->ifname);
2475 } 2592 return -EINVAL;
2593 }
2476 2594
2477 pkt_dev->stopped_at = getCurUs(); 2595 pkt_dev->stopped_at = getCurUs();
2478 pkt_dev->running = 0; 2596 pkt_dev->running = 0;
2479 2597
2480 show_results(pkt_dev, nr_frags); 2598 show_results(pkt_dev, nr_frags);
2481 2599
2482 return 0; 2600 return 0;
2483} 2601}
2484 2602
2485static struct pktgen_dev *next_to_run(struct pktgen_thread *t ) 2603static struct pktgen_dev *next_to_run(struct pktgen_thread *t)
2486{ 2604{
2487 struct pktgen_dev *next, *best = NULL; 2605 struct pktgen_dev *next, *best = NULL;
2488 2606
2489 if_lock(t); 2607 if_lock(t);
2490 2608
2491 for(next=t->if_list; next ; next=next->next) { 2609 for (next = t->if_list; next; next = next->next) {
2492 if(!next->running) continue; 2610 if (!next->running)
2493 if(best == NULL) best=next; 2611 continue;
2494 else if ( next->next_tx_us < best->next_tx_us) 2612 if (best == NULL)
2495 best = next; 2613 best = next;
2614 else if (next->next_tx_us < best->next_tx_us)
2615 best = next;
2496 } 2616 }
2497 if_unlock(t); 2617 if_unlock(t);
2498 return best; 2618 return best;
2499} 2619}
2500 2620
2501static void pktgen_stop(struct pktgen_thread *t) { 2621static void pktgen_stop(struct pktgen_thread *t)
2502 struct pktgen_dev *next = NULL; 2622{
2623 struct pktgen_dev *next = NULL;
2503 2624
2504 PG_DEBUG(printk("pktgen: entering pktgen_stop\n")); 2625 PG_DEBUG(printk("pktgen: entering pktgen_stop\n"));
2505 2626
2506 if_lock(t); 2627 if_lock(t);
2507 2628
2508 for(next=t->if_list; next; next=next->next) { 2629 for (next = t->if_list; next; next = next->next) {
2509 pktgen_stop_device(next); 2630 pktgen_stop_device(next);
2510 if (next->skb) 2631 if (next->skb)
2511 kfree_skb(next->skb); 2632 kfree_skb(next->skb);
2512 2633
2513 next->skb = NULL; 2634 next->skb = NULL;
2514 } 2635 }
2515 2636
2516 if_unlock(t); 2637 if_unlock(t);
2517} 2638}
2518 2639
2519/* 2640/*
@@ -2528,10 +2649,11 @@ static void pktgen_rem_one_if(struct pktgen_thread *t)
2528 2649
2529 if_lock(t); 2650 if_lock(t);
2530 2651
2531 for(cur=t->if_list; cur; cur=next) { 2652 for (cur = t->if_list; cur; cur = next) {
2532 next = cur->next; 2653 next = cur->next;
2533 2654
2534 if (!cur->removal_mark) continue; 2655 if (!cur->removal_mark)
2656 continue;
2535 2657
2536 if (cur->skb) 2658 if (cur->skb)
2537 kfree_skb(cur->skb); 2659 kfree_skb(cur->skb);
@@ -2545,16 +2667,16 @@ static void pktgen_rem_one_if(struct pktgen_thread *t)
2545 if_unlock(t); 2667 if_unlock(t);
2546} 2668}
2547 2669
2548static void pktgen_rem_all_ifs(struct pktgen_thread *t) 2670static void pktgen_rem_all_ifs(struct pktgen_thread *t)
2549{ 2671{
2550 struct pktgen_dev *cur, *next = NULL; 2672 struct pktgen_dev *cur, *next = NULL;
2551 2673
2552 /* Remove all devices, free mem */ 2674 /* Remove all devices, free mem */
2553 2675
2554 PG_DEBUG(printk("pktgen: entering pktgen_rem_all_ifs\n")); 2676 PG_DEBUG(printk("pktgen: entering pktgen_rem_all_ifs\n"));
2555 if_lock(t); 2677 if_lock(t);
2556 2678
2557 for(cur=t->if_list; cur; cur=next) { 2679 for (cur = t->if_list; cur; cur = next) {
2558 next = cur->next; 2680 next = cur->next;
2559 2681
2560 if (cur->skb) 2682 if (cur->skb)
@@ -2564,12 +2686,12 @@ static void pktgen_rem_all_ifs(struct pktgen_thread *t)
2564 pktgen_remove_device(t, cur); 2686 pktgen_remove_device(t, cur);
2565 } 2687 }
2566 2688
2567 if_unlock(t); 2689 if_unlock(t);
2568} 2690}
2569 2691
2570static void pktgen_rem_thread(struct pktgen_thread *t) 2692static void pktgen_rem_thread(struct pktgen_thread *t)
2571{ 2693{
2572 /* Remove from the thread list */ 2694 /* Remove from the thread list */
2573 2695
2574 struct pktgen_thread *tmp = pktgen_threads; 2696 struct pktgen_thread *tmp = pktgen_threads;
2575 2697
@@ -2589,7 +2711,7 @@ static void pktgen_rem_thread(struct pktgen_thread *t)
2589 tmp = tmp->next; 2711 tmp = tmp->next;
2590 } 2712 }
2591 } 2713 }
2592 thread_unlock(); 2714 thread_unlock();
2593} 2715}
2594 2716
2595static __inline__ void pktgen_xmit(struct pktgen_dev *pkt_dev) 2717static __inline__ void pktgen_xmit(struct pktgen_dev *pkt_dev)
@@ -2599,7 +2721,7 @@ static __inline__ void pktgen_xmit(struct pktgen_dev *pkt_dev)
2599 int ret; 2721 int ret;
2600 2722
2601 odev = pkt_dev->odev; 2723 odev = pkt_dev->odev;
2602 2724
2603 if (pkt_dev->delay_us || pkt_dev->delay_ns) { 2725 if (pkt_dev->delay_us || pkt_dev->delay_ns) {
2604 u64 now; 2726 u64 now;
2605 2727
@@ -2616,10 +2738,10 @@ static __inline__ void pktgen_xmit(struct pktgen_dev *pkt_dev)
2616 goto out; 2738 goto out;
2617 } 2739 }
2618 } 2740 }
2619 2741
2620 if (netif_queue_stopped(odev) || need_resched()) { 2742 if (netif_queue_stopped(odev) || need_resched()) {
2621 idle_start = getCurUs(); 2743 idle_start = getCurUs();
2622 2744
2623 if (!netif_running(odev)) { 2745 if (!netif_running(odev)) {
2624 pktgen_stop_device(pkt_dev); 2746 pktgen_stop_device(pkt_dev);
2625 if (pkt_dev->skb) 2747 if (pkt_dev->skb)
@@ -2627,33 +2749,34 @@ static __inline__ void pktgen_xmit(struct pktgen_dev *pkt_dev)
2627 pkt_dev->skb = NULL; 2749 pkt_dev->skb = NULL;
2628 goto out; 2750 goto out;
2629 } 2751 }
2630 if (need_resched()) 2752 if (need_resched())
2631 schedule(); 2753 schedule();
2632 2754
2633 pkt_dev->idle_acc += getCurUs() - idle_start; 2755 pkt_dev->idle_acc += getCurUs() - idle_start;
2634 2756
2635 if (netif_queue_stopped(odev)) { 2757 if (netif_queue_stopped(odev)) {
2636 pkt_dev->next_tx_us = getCurUs(); /* TODO */ 2758 pkt_dev->next_tx_us = getCurUs(); /* TODO */
2637 pkt_dev->next_tx_ns = 0; 2759 pkt_dev->next_tx_ns = 0;
2638 goto out; /* Try the next interface */ 2760 goto out; /* Try the next interface */
2639 } 2761 }
2640 } 2762 }
2641 2763
2642 if (pkt_dev->last_ok || !pkt_dev->skb) { 2764 if (pkt_dev->last_ok || !pkt_dev->skb) {
2643 if ((++pkt_dev->clone_count >= pkt_dev->clone_skb ) || (!pkt_dev->skb)) { 2765 if ((++pkt_dev->clone_count >= pkt_dev->clone_skb)
2766 || (!pkt_dev->skb)) {
2644 /* build a new pkt */ 2767 /* build a new pkt */
2645 if (pkt_dev->skb) 2768 if (pkt_dev->skb)
2646 kfree_skb(pkt_dev->skb); 2769 kfree_skb(pkt_dev->skb);
2647 2770
2648 pkt_dev->skb = fill_packet(odev, pkt_dev); 2771 pkt_dev->skb = fill_packet(odev, pkt_dev);
2649 if (pkt_dev->skb == NULL) { 2772 if (pkt_dev->skb == NULL) {
2650 printk("pktgen: ERROR: couldn't allocate skb in fill_packet.\n"); 2773 printk("pktgen: ERROR: couldn't allocate skb in fill_packet.\n");
2651 schedule(); 2774 schedule();
2652 pkt_dev->clone_count--; /* back out increment, OOM */ 2775 pkt_dev->clone_count--; /* back out increment, OOM */
2653 goto out; 2776 goto out;
2654 } 2777 }
2655 pkt_dev->allocated_skbs++; 2778 pkt_dev->allocated_skbs++;
2656 pkt_dev->clone_count = 0; /* reset counter */ 2779 pkt_dev->clone_count = 0; /* reset counter */
2657 } 2780 }
2658 } 2781 }
2659 2782
@@ -2661,25 +2784,25 @@ static __inline__ void pktgen_xmit(struct pktgen_dev *pkt_dev)
2661 if (!netif_queue_stopped(odev)) { 2784 if (!netif_queue_stopped(odev)) {
2662 2785
2663 atomic_inc(&(pkt_dev->skb->users)); 2786 atomic_inc(&(pkt_dev->skb->users));
2664retry_now: 2787 retry_now:
2665 ret = odev->hard_start_xmit(pkt_dev->skb, odev); 2788 ret = odev->hard_start_xmit(pkt_dev->skb, odev);
2666 if (likely(ret == NETDEV_TX_OK)) { 2789 if (likely(ret == NETDEV_TX_OK)) {
2667 pkt_dev->last_ok = 1; 2790 pkt_dev->last_ok = 1;
2668 pkt_dev->sofar++; 2791 pkt_dev->sofar++;
2669 pkt_dev->seq_num++; 2792 pkt_dev->seq_num++;
2670 pkt_dev->tx_bytes += pkt_dev->cur_pkt_size; 2793 pkt_dev->tx_bytes += pkt_dev->cur_pkt_size;
2671 2794
2672 } else if (ret == NETDEV_TX_LOCKED 2795 } else if (ret == NETDEV_TX_LOCKED
2673 && (odev->features & NETIF_F_LLTX)) { 2796 && (odev->features & NETIF_F_LLTX)) {
2674 cpu_relax(); 2797 cpu_relax();
2675 goto retry_now; 2798 goto retry_now;
2676 } else { /* Retry it next time */ 2799 } else { /* Retry it next time */
2677 2800
2678 atomic_dec(&(pkt_dev->skb->users)); 2801 atomic_dec(&(pkt_dev->skb->users));
2679 2802
2680 if (debug && net_ratelimit()) 2803 if (debug && net_ratelimit())
2681 printk(KERN_INFO "pktgen: Hard xmit error\n"); 2804 printk(KERN_INFO "pktgen: Hard xmit error\n");
2682 2805
2683 pkt_dev->errors++; 2806 pkt_dev->errors++;
2684 pkt_dev->last_ok = 0; 2807 pkt_dev->last_ok = 0;
2685 } 2808 }
@@ -2694,16 +2817,16 @@ retry_now:
2694 pkt_dev->next_tx_us++; 2817 pkt_dev->next_tx_us++;
2695 pkt_dev->next_tx_ns -= 1000; 2818 pkt_dev->next_tx_ns -= 1000;
2696 } 2819 }
2697 } 2820 }
2698 2821
2699 else { /* Retry it next time */ 2822 else { /* Retry it next time */
2700 pkt_dev->last_ok = 0; 2823 pkt_dev->last_ok = 0;
2701 pkt_dev->next_tx_us = getCurUs(); /* TODO */ 2824 pkt_dev->next_tx_us = getCurUs(); /* TODO */
2702 pkt_dev->next_tx_ns = 0; 2825 pkt_dev->next_tx_ns = 0;
2703 } 2826 }
2704 2827
2705 spin_unlock_bh(&odev->xmit_lock); 2828 spin_unlock_bh(&odev->xmit_lock);
2706 2829
2707 /* If pkt_dev->count is zero, then run forever */ 2830 /* If pkt_dev->count is zero, then run forever */
2708 if ((pkt_dev->count != 0) && (pkt_dev->sofar >= pkt_dev->count)) { 2831 if ((pkt_dev->count != 0) && (pkt_dev->sofar >= pkt_dev->count)) {
2709 if (atomic_read(&(pkt_dev->skb->users)) != 1) { 2832 if (atomic_read(&(pkt_dev->skb->users)) != 1) {
@@ -2716,47 +2839,45 @@ retry_now:
2716 } 2839 }
2717 pkt_dev->idle_acc += getCurUs() - idle_start; 2840 pkt_dev->idle_acc += getCurUs() - idle_start;
2718 } 2841 }
2719 2842
2720 /* Done with this */ 2843 /* Done with this */
2721 pktgen_stop_device(pkt_dev); 2844 pktgen_stop_device(pkt_dev);
2722 if (pkt_dev->skb) 2845 if (pkt_dev->skb)
2723 kfree_skb(pkt_dev->skb); 2846 kfree_skb(pkt_dev->skb);
2724 pkt_dev->skb = NULL; 2847 pkt_dev->skb = NULL;
2725 } 2848 }
2726 out:; 2849out:;
2727 } 2850}
2728 2851
2729/* 2852/*
2730 * Main loop of the thread goes here 2853 * Main loop of the thread goes here
2731 */ 2854 */
2732 2855
2733static void pktgen_thread_worker(struct pktgen_thread *t) 2856static void pktgen_thread_worker(struct pktgen_thread *t)
2734{ 2857{
2735 DEFINE_WAIT(wait); 2858 DEFINE_WAIT(wait);
2736 struct pktgen_dev *pkt_dev = NULL; 2859 struct pktgen_dev *pkt_dev = NULL;
2737 int cpu = t->cpu; 2860 int cpu = t->cpu;
2738 sigset_t tmpsig; 2861 sigset_t tmpsig;
2739 u32 max_before_softirq; 2862 u32 max_before_softirq;
2740 u32 tx_since_softirq = 0; 2863 u32 tx_since_softirq = 0;
2741 2864
2742 daemonize("pktgen/%d", cpu); 2865 daemonize("pktgen/%d", cpu);
2743 2866
2744 /* Block all signals except SIGKILL, SIGSTOP and SIGTERM */ 2867 /* Block all signals except SIGKILL, SIGSTOP and SIGTERM */
2745 2868
2746 spin_lock_irq(&current->sighand->siglock); 2869 spin_lock_irq(&current->sighand->siglock);
2747 tmpsig = current->blocked; 2870 tmpsig = current->blocked;
2748 siginitsetinv(&current->blocked, 2871 siginitsetinv(&current->blocked,
2749 sigmask(SIGKILL) | 2872 sigmask(SIGKILL) | sigmask(SIGSTOP) | sigmask(SIGTERM));
2750 sigmask(SIGSTOP)|
2751 sigmask(SIGTERM));
2752 2873
2753 recalc_sigpending(); 2874 recalc_sigpending();
2754 spin_unlock_irq(&current->sighand->siglock); 2875 spin_unlock_irq(&current->sighand->siglock);
2755 2876
2756 /* Migrate to the right CPU */ 2877 /* Migrate to the right CPU */
2757 set_cpus_allowed(current, cpumask_of_cpu(cpu)); 2878 set_cpus_allowed(current, cpumask_of_cpu(cpu));
2758 if (smp_processor_id() != cpu) 2879 if (smp_processor_id() != cpu)
2759 BUG(); 2880 BUG();
2760 2881
2761 init_waitqueue_head(&t->queue); 2882 init_waitqueue_head(&t->queue);
2762 2883
@@ -2766,26 +2887,26 @@ static void pktgen_thread_worker(struct pktgen_thread *t)
2766 t->control &= ~(T_REMDEVALL); 2887 t->control &= ~(T_REMDEVALL);
2767 t->control &= ~(T_REMDEV); 2888 t->control &= ~(T_REMDEV);
2768 2889
2769 t->pid = current->pid; 2890 t->pid = current->pid;
2770 2891
2771 PG_DEBUG(printk("pktgen: starting pktgen/%d: pid=%d\n", cpu, current->pid)); 2892 PG_DEBUG(printk("pktgen: starting pktgen/%d: pid=%d\n", cpu, current->pid));
2772 2893
2773 max_before_softirq = t->max_before_softirq; 2894 max_before_softirq = t->max_before_softirq;
2774
2775 __set_current_state(TASK_INTERRUPTIBLE);
2776 mb();
2777 2895
2778 while (1) { 2896 __set_current_state(TASK_INTERRUPTIBLE);
2779 2897 mb();
2898
2899 while (1) {
2900
2780 __set_current_state(TASK_RUNNING); 2901 __set_current_state(TASK_RUNNING);
2781 2902
2782 /* 2903 /*
2783 * Get next dev to xmit -- if any. 2904 * Get next dev to xmit -- if any.
2784 */ 2905 */
2785 2906
2786 pkt_dev = next_to_run(t); 2907 pkt_dev = next_to_run(t);
2787 2908
2788 if (pkt_dev) { 2909 if (pkt_dev) {
2789 2910
2790 pktgen_xmit(pkt_dev); 2911 pktgen_xmit(pkt_dev);
2791 2912
@@ -2803,119 +2924,121 @@ static void pktgen_thread_worker(struct pktgen_thread *t)
2803 } 2924 }
2804 } else { 2925 } else {
2805 prepare_to_wait(&(t->queue), &wait, TASK_INTERRUPTIBLE); 2926 prepare_to_wait(&(t->queue), &wait, TASK_INTERRUPTIBLE);
2806 schedule_timeout(HZ/10); 2927 schedule_timeout(HZ / 10);
2807 finish_wait(&(t->queue), &wait); 2928 finish_wait(&(t->queue), &wait);
2808 } 2929 }
2809 2930
2810 /* 2931 /*
2811 * Back from sleep, either due to the timeout or signal. 2932 * Back from sleep, either due to the timeout or signal.
2812 * We check if we have any "posted" work for us. 2933 * We check if we have any "posted" work for us.
2813 */ 2934 */
2814 2935
2815 if (t->control & T_TERMINATE || signal_pending(current)) 2936 if (t->control & T_TERMINATE || signal_pending(current))
2816 /* we received a request to terminate ourself */ 2937 /* we received a request to terminate ourself */
2817 break; 2938 break;
2818
2819 2939
2820 if(t->control & T_STOP) { 2940 if (t->control & T_STOP) {
2821 pktgen_stop(t); 2941 pktgen_stop(t);
2822 t->control &= ~(T_STOP); 2942 t->control &= ~(T_STOP);
2823 } 2943 }
2824 2944
2825 if(t->control & T_RUN) { 2945 if (t->control & T_RUN) {
2826 pktgen_run(t); 2946 pktgen_run(t);
2827 t->control &= ~(T_RUN); 2947 t->control &= ~(T_RUN);
2828 } 2948 }
2829 2949
2830 if(t->control & T_REMDEVALL) { 2950 if (t->control & T_REMDEVALL) {
2831 pktgen_rem_all_ifs(t); 2951 pktgen_rem_all_ifs(t);
2832 t->control &= ~(T_REMDEVALL); 2952 t->control &= ~(T_REMDEVALL);
2833 } 2953 }
2834 2954
2835 if(t->control & T_REMDEV) { 2955 if (t->control & T_REMDEV) {
2836 pktgen_rem_one_if(t); 2956 pktgen_rem_one_if(t);
2837 t->control &= ~(T_REMDEV); 2957 t->control &= ~(T_REMDEV);
2838 } 2958 }
2839 2959
2840 if (need_resched()) 2960 if (need_resched())
2841 schedule(); 2961 schedule();
2842 } 2962 }
2843 2963
2844 PG_DEBUG(printk("pktgen: %s stopping all device\n", t->name)); 2964 PG_DEBUG(printk("pktgen: %s stopping all device\n", t->name));
2845 pktgen_stop(t); 2965 pktgen_stop(t);
2846 2966
2847 PG_DEBUG(printk("pktgen: %s removing all device\n", t->name)); 2967 PG_DEBUG(printk("pktgen: %s removing all device\n", t->name));
2848 pktgen_rem_all_ifs(t); 2968 pktgen_rem_all_ifs(t);
2849 2969
2850 PG_DEBUG(printk("pktgen: %s removing thread.\n", t->name)); 2970 PG_DEBUG(printk("pktgen: %s removing thread.\n", t->name));
2851 pktgen_rem_thread(t); 2971 pktgen_rem_thread(t);
2852} 2972}
2853 2973
2854static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t, const char* ifname) 2974static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t,
2975 const char *ifname)
2855{ 2976{
2856 struct pktgen_dev *pkt_dev = NULL; 2977 struct pktgen_dev *pkt_dev = NULL;
2857 if_lock(t); 2978 if_lock(t);
2858 2979
2859 for(pkt_dev=t->if_list; pkt_dev; pkt_dev = pkt_dev->next ) { 2980 for (pkt_dev = t->if_list; pkt_dev; pkt_dev = pkt_dev->next) {
2860 if (strncmp(pkt_dev->ifname, ifname, IFNAMSIZ) == 0) { 2981 if (strncmp(pkt_dev->ifname, ifname, IFNAMSIZ) == 0) {
2861 break; 2982 break;
2862 } 2983 }
2863 } 2984 }
2864 2985
2865 if_unlock(t); 2986 if_unlock(t);
2866 PG_DEBUG(printk("pktgen: find_dev(%s) returning %p\n", ifname,pkt_dev)); 2987 PG_DEBUG(printk("pktgen: find_dev(%s) returning %p\n", ifname, pkt_dev));
2867 return pkt_dev; 2988 return pkt_dev;
2868} 2989}
2869 2990
2870/* 2991/*
2871 * Adds a dev at front of if_list. 2992 * Adds a dev at front of if_list.
2872 */ 2993 */
2873 2994
2874static int add_dev_to_thread(struct pktgen_thread *t, struct pktgen_dev *pkt_dev) 2995static int add_dev_to_thread(struct pktgen_thread *t,
2996 struct pktgen_dev *pkt_dev)
2875{ 2997{
2876 int rv = 0; 2998 int rv = 0;
2877 2999
2878 if_lock(t); 3000 if_lock(t);
2879 3001
2880 if (pkt_dev->pg_thread) { 3002 if (pkt_dev->pg_thread) {
2881 printk("pktgen: ERROR: already assigned to a thread.\n"); 3003 printk("pktgen: ERROR: already assigned to a thread.\n");
2882 rv = -EBUSY; 3004 rv = -EBUSY;
2883 goto out; 3005 goto out;
2884 } 3006 }
2885 pkt_dev->next =t->if_list; t->if_list=pkt_dev; 3007 pkt_dev->next = t->if_list;
2886 pkt_dev->pg_thread = t; 3008 t->if_list = pkt_dev;
3009 pkt_dev->pg_thread = t;
2887 pkt_dev->running = 0; 3010 pkt_dev->running = 0;
2888 3011
2889 out: 3012out:
2890 if_unlock(t); 3013 if_unlock(t);
2891 return rv; 3014 return rv;
2892} 3015}
2893 3016
2894/* Called under thread lock */ 3017/* Called under thread lock */
2895 3018
2896static int pktgen_add_device(struct pktgen_thread *t, const char* ifname) 3019static int pktgen_add_device(struct pktgen_thread *t, const char *ifname)
2897{ 3020{
2898 struct pktgen_dev *pkt_dev; 3021 struct pktgen_dev *pkt_dev;
2899 struct proc_dir_entry *pe; 3022 struct proc_dir_entry *pe;
2900 3023
2901 /* We don't allow a device to be on several threads */ 3024 /* We don't allow a device to be on several threads */
2902 3025
2903 pkt_dev = __pktgen_NN_threads(ifname, FIND); 3026 pkt_dev = __pktgen_NN_threads(ifname, FIND);
2904 if (pkt_dev) { 3027 if (pkt_dev) {
2905 printk("pktgen: ERROR: interface already used.\n"); 3028 printk("pktgen: ERROR: interface already used.\n");
2906 return -EBUSY; 3029 return -EBUSY;
2907 } 3030 }
2908 3031
2909 pkt_dev = kzalloc(sizeof(struct pktgen_dev), GFP_KERNEL); 3032 pkt_dev = kzalloc(sizeof(struct pktgen_dev), GFP_KERNEL);
2910 if (!pkt_dev) 3033 if (!pkt_dev)
2911 return -ENOMEM; 3034 return -ENOMEM;
2912 3035
2913 pkt_dev->flows = vmalloc(MAX_CFLOWS*sizeof(struct flow_state)); 3036 pkt_dev->flows = vmalloc(MAX_CFLOWS * sizeof(struct flow_state));
2914 if (pkt_dev->flows == NULL) { 3037 if (pkt_dev->flows == NULL) {
2915 kfree(pkt_dev); 3038 kfree(pkt_dev);
2916 return -ENOMEM; 3039 return -ENOMEM;
2917 } 3040 }
2918 memset(pkt_dev->flows, 0, MAX_CFLOWS*sizeof(struct flow_state)); 3041 memset(pkt_dev->flows, 0, MAX_CFLOWS * sizeof(struct flow_state));
2919 3042
2920 pkt_dev->removal_mark = 0; 3043 pkt_dev->removal_mark = 0;
2921 pkt_dev->min_pkt_size = ETH_ZLEN; 3044 pkt_dev->min_pkt_size = ETH_ZLEN;
@@ -2926,14 +3049,14 @@ static int pktgen_add_device(struct pktgen_thread *t, const char* ifname)
2926 pkt_dev->delay_ns = pg_delay_d % 1000; 3049 pkt_dev->delay_ns = pg_delay_d % 1000;
2927 pkt_dev->count = pg_count_d; 3050 pkt_dev->count = pg_count_d;
2928 pkt_dev->sofar = 0; 3051 pkt_dev->sofar = 0;
2929 pkt_dev->udp_src_min = 9; /* sink port */ 3052 pkt_dev->udp_src_min = 9; /* sink port */
2930 pkt_dev->udp_src_max = 9; 3053 pkt_dev->udp_src_max = 9;
2931 pkt_dev->udp_dst_min = 9; 3054 pkt_dev->udp_dst_min = 9;
2932 pkt_dev->udp_dst_max = 9; 3055 pkt_dev->udp_dst_max = 9;
2933 3056
2934 strncpy(pkt_dev->ifname, ifname, IFNAMSIZ); 3057 strncpy(pkt_dev->ifname, ifname, IFNAMSIZ);
2935 3058
2936 if (! pktgen_setup_dev(pkt_dev)) { 3059 if (!pktgen_setup_dev(pkt_dev)) {
2937 printk("pktgen: ERROR: pktgen_setup_dev failed.\n"); 3060 printk("pktgen: ERROR: pktgen_setup_dev failed.\n");
2938 if (pkt_dev->flows) 3061 if (pkt_dev->flows)
2939 vfree(pkt_dev->flows); 3062 vfree(pkt_dev->flows);
@@ -2956,63 +3079,63 @@ static int pktgen_add_device(struct pktgen_thread *t, const char* ifname)
2956 return add_dev_to_thread(t, pkt_dev); 3079 return add_dev_to_thread(t, pkt_dev);
2957} 3080}
2958 3081
2959static struct pktgen_thread * __init pktgen_find_thread(const char* name) 3082static struct pktgen_thread *__init pktgen_find_thread(const char *name)
2960{ 3083{
2961 struct pktgen_thread *t = NULL; 3084 struct pktgen_thread *t = NULL;
2962 3085
2963 thread_lock(); 3086 thread_lock();
2964 3087
2965 t = pktgen_threads; 3088 t = pktgen_threads;
2966 while (t) { 3089 while (t) {
2967 if (strcmp(t->name, name) == 0) 3090 if (strcmp(t->name, name) == 0)
2968 break; 3091 break;
2969 3092
2970 t = t->next; 3093 t = t->next;
2971 } 3094 }
2972 thread_unlock(); 3095 thread_unlock();
2973 return t; 3096 return t;
2974} 3097}
2975 3098
2976static int __init pktgen_create_thread(const char* name, int cpu) 3099static int __init pktgen_create_thread(const char *name, int cpu)
2977{ 3100{
2978 struct pktgen_thread *t = NULL; 3101 struct pktgen_thread *t = NULL;
2979 struct proc_dir_entry *pe; 3102 struct proc_dir_entry *pe;
2980 3103
2981 if (strlen(name) > 31) { 3104 if (strlen(name) > 31) {
2982 printk("pktgen: ERROR: Thread name cannot be more than 31 characters.\n"); 3105 printk("pktgen: ERROR: Thread name cannot be more than 31 characters.\n");
2983 return -EINVAL; 3106 return -EINVAL;
2984 } 3107 }
2985 3108
2986 if (pktgen_find_thread(name)) { 3109 if (pktgen_find_thread(name)) {
2987 printk("pktgen: ERROR: thread: %s already exists\n", name); 3110 printk("pktgen: ERROR: thread: %s already exists\n", name);
2988 return -EINVAL; 3111 return -EINVAL;
2989 } 3112 }
2990 3113
2991 t = kzalloc(sizeof(struct pktgen_thread), GFP_KERNEL); 3114 t = kzalloc(sizeof(struct pktgen_thread), GFP_KERNEL);
2992 if (!t) { 3115 if (!t) {
2993 printk("pktgen: ERROR: out of memory, can't create new thread.\n"); 3116 printk("pktgen: ERROR: out of memory, can't create new thread.\n");
2994 return -ENOMEM; 3117 return -ENOMEM;
2995 } 3118 }
2996 3119
2997 strcpy(t->name, name); 3120 strcpy(t->name, name);
2998 spin_lock_init(&t->if_lock); 3121 spin_lock_init(&t->if_lock);
2999 t->cpu = cpu; 3122 t->cpu = cpu;
3000 3123
3001 pe = create_proc_entry(t->name, 0600, pg_proc_dir); 3124 pe = create_proc_entry(t->name, 0600, pg_proc_dir);
3002 if (!pe) { 3125 if (!pe) {
3003 printk("pktgen: cannot create %s/%s procfs entry.\n", 3126 printk("pktgen: cannot create %s/%s procfs entry.\n",
3004 PG_PROC_DIR, t->name); 3127 PG_PROC_DIR, t->name);
3005 kfree(t); 3128 kfree(t);
3006 return -EINVAL; 3129 return -EINVAL;
3007 } 3130 }
3008 3131
3009 pe->proc_fops = &pktgen_thread_fops; 3132 pe->proc_fops = &pktgen_thread_fops;
3010 pe->data = t; 3133 pe->data = t;
3011 3134
3012 t->next = pktgen_threads; 3135 t->next = pktgen_threads;
3013 pktgen_threads = t; 3136 pktgen_threads = t;
3014 3137
3015 if (kernel_thread((void *) pktgen_thread_worker, (void *) t, 3138 if (kernel_thread((void *)pktgen_thread_worker, (void *)t,
3016 CLONE_FS | CLONE_FILES | CLONE_SIGHAND) < 0) 3139 CLONE_FS | CLONE_FILES | CLONE_SIGHAND) < 0)
3017 printk("pktgen: kernel_thread() failed for cpu %d\n", t->cpu); 3140 printk("pktgen: kernel_thread() failed for cpu %d\n", t->cpu);
3018 3141
@@ -3022,55 +3145,59 @@ static int __init pktgen_create_thread(const char* name, int cpu)
3022/* 3145/*
3023 * Removes a device from the thread if_list. 3146 * Removes a device from the thread if_list.
3024 */ 3147 */
3025static void _rem_dev_from_if_list(struct pktgen_thread *t, struct pktgen_dev *pkt_dev) 3148static void _rem_dev_from_if_list(struct pktgen_thread *t,
3149 struct pktgen_dev *pkt_dev)
3026{ 3150{
3027 struct pktgen_dev *i, *prev = NULL; 3151 struct pktgen_dev *i, *prev = NULL;
3028 3152
3029 i = t->if_list; 3153 i = t->if_list;
3030 3154
3031 while(i) { 3155 while (i) {
3032 if(i == pkt_dev) { 3156 if (i == pkt_dev) {
3033 if(prev) prev->next = i->next; 3157 if (prev)
3034 else t->if_list = NULL; 3158 prev->next = i->next;
3159 else
3160 t->if_list = NULL;
3035 break; 3161 break;
3036 } 3162 }
3037 prev = i; 3163 prev = i;
3038 i=i->next; 3164 i = i->next;
3039 } 3165 }
3040} 3166}
3041 3167
3042static int pktgen_remove_device(struct pktgen_thread *t, struct pktgen_dev *pkt_dev) 3168static int pktgen_remove_device(struct pktgen_thread *t,
3169 struct pktgen_dev *pkt_dev)
3043{ 3170{
3044 3171
3045 PG_DEBUG(printk("pktgen: remove_device pkt_dev=%p\n", pkt_dev)); 3172 PG_DEBUG(printk("pktgen: remove_device pkt_dev=%p\n", pkt_dev));
3046 3173
3047 if (pkt_dev->running) { 3174 if (pkt_dev->running) {
3048 printk("pktgen:WARNING: trying to remove a running interface, stopping it now.\n"); 3175 printk("pktgen:WARNING: trying to remove a running interface, stopping it now.\n");
3049 pktgen_stop_device(pkt_dev); 3176 pktgen_stop_device(pkt_dev);
3050 } 3177 }
3051 3178
3052 /* Dis-associate from the interface */ 3179 /* Dis-associate from the interface */
3053 3180
3054 if (pkt_dev->odev) { 3181 if (pkt_dev->odev) {
3055 dev_put(pkt_dev->odev); 3182 dev_put(pkt_dev->odev);
3056 pkt_dev->odev = NULL; 3183 pkt_dev->odev = NULL;
3057 } 3184 }
3058 3185
3059 /* And update the thread if_list */ 3186 /* And update the thread if_list */
3060 3187
3061 _rem_dev_from_if_list(t, pkt_dev); 3188 _rem_dev_from_if_list(t, pkt_dev);
3062 3189
3063 /* Clean up proc file system */ 3190 /* Clean up proc file system */
3064 3191
3065 remove_proc_entry(pkt_dev->ifname, pg_proc_dir); 3192 remove_proc_entry(pkt_dev->ifname, pg_proc_dir);
3066 3193
3067 if (pkt_dev->flows) 3194 if (pkt_dev->flows)
3068 vfree(pkt_dev->flows); 3195 vfree(pkt_dev->flows);
3069 kfree(pkt_dev); 3196 kfree(pkt_dev);
3070 return 0; 3197 return 0;
3071} 3198}
3072 3199
3073static int __init pg_init(void) 3200static int __init pg_init(void)
3074{ 3201{
3075 int cpu; 3202 int cpu;
3076 struct proc_dir_entry *pe; 3203 struct proc_dir_entry *pe;
@@ -3083,25 +3210,26 @@ static int __init pg_init(void)
3083 pg_proc_dir->owner = THIS_MODULE; 3210 pg_proc_dir->owner = THIS_MODULE;
3084 3211
3085 pe = create_proc_entry(PGCTRL, 0600, pg_proc_dir); 3212 pe = create_proc_entry(PGCTRL, 0600, pg_proc_dir);
3086 if (pe == NULL) { 3213 if (pe == NULL) {
3087 printk("pktgen: ERROR: cannot create %s procfs entry.\n", PGCTRL); 3214 printk("pktgen: ERROR: cannot create %s procfs entry.\n",
3215 PGCTRL);
3088 proc_net_remove(PG_PROC_DIR); 3216 proc_net_remove(PG_PROC_DIR);
3089 return -EINVAL; 3217 return -EINVAL;
3090 } 3218 }
3091 3219
3092 pe->proc_fops = &pktgen_fops; 3220 pe->proc_fops = &pktgen_fops;
3093 pe->data = NULL; 3221 pe->data = NULL;
3094 3222
3095 /* Register us to receive netdevice events */ 3223 /* Register us to receive netdevice events */
3096 register_netdevice_notifier(&pktgen_notifier_block); 3224 register_netdevice_notifier(&pktgen_notifier_block);
3097 3225
3098 for_each_online_cpu(cpu) { 3226 for_each_online_cpu(cpu) {
3099 char buf[30]; 3227 char buf[30];
3100 3228
3101 sprintf(buf, "kpktgend_%i", cpu); 3229 sprintf(buf, "kpktgend_%i", cpu);
3102 pktgen_create_thread(buf, cpu); 3230 pktgen_create_thread(buf, cpu);
3103 } 3231 }
3104 return 0; 3232 return 0;
3105} 3233}
3106 3234
3107static void __exit pg_cleanup(void) 3235static void __exit pg_cleanup(void)
@@ -3109,24 +3237,24 @@ static void __exit pg_cleanup(void)
3109 wait_queue_head_t queue; 3237 wait_queue_head_t queue;
3110 init_waitqueue_head(&queue); 3238 init_waitqueue_head(&queue);
3111 3239
3112 /* Stop all interfaces & threads */ 3240 /* Stop all interfaces & threads */
3113 3241
3114 while (pktgen_threads) { 3242 while (pktgen_threads) {
3115 struct pktgen_thread *t = pktgen_threads; 3243 struct pktgen_thread *t = pktgen_threads;
3116 pktgen_threads->control |= (T_TERMINATE); 3244 pktgen_threads->control |= (T_TERMINATE);
3117 3245
3118 wait_event_interruptible_timeout(queue, (t != pktgen_threads), HZ); 3246 wait_event_interruptible_timeout(queue, (t != pktgen_threads),
3119 } 3247 HZ);
3248 }
3120 3249
3121 /* Un-register us from receiving netdevice events */ 3250 /* Un-register us from receiving netdevice events */
3122 unregister_netdevice_notifier(&pktgen_notifier_block); 3251 unregister_netdevice_notifier(&pktgen_notifier_block);
3123 3252
3124 /* Clean up proc file system */ 3253 /* Clean up proc file system */
3125 remove_proc_entry(PGCTRL, pg_proc_dir); 3254 remove_proc_entry(PGCTRL, pg_proc_dir);
3126 proc_net_remove(PG_PROC_DIR); 3255 proc_net_remove(PG_PROC_DIR);
3127} 3256}
3128 3257
3129
3130module_init(pg_init); 3258module_init(pg_init);
3131module_exit(pg_cleanup); 3259module_exit(pg_cleanup);
3132 3260