Commit 222f1806 authored by Luiz Capitulino's avatar Luiz Capitulino Committed by David S. Miller

[PKTGEN]: Lindent run.

Lindet run, with some fixes made by hand.
Signed-off-by: default avatarLuiz Capitulino <lcapitulino@mandriva.com.br>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6df9424a
......@@ -152,7 +152,6 @@
#include <asm/div64.h> /* do_div */
#include <asm/timex.h>
#define VERSION "pktgen v2.64: Packet Generator for packet performance testing.\n"
/* #define PG_DEBUG(a) a */
......@@ -195,8 +194,7 @@ static struct proc_dir_entry *pg_proc_dir = NULL;
#define MAX_CFLOWS 65536
struct flow_state
{
struct flow_state {
__u32 cur_daddr;
int count;
};
......@@ -210,7 +208,7 @@ struct pktgen_dev {
char ifname[IFNAMSIZ];
char result[512];
struct pktgen_thread* pg_thread; /* the owner */
struct pktgen_thread *pg_thread; /* the owner */
struct pktgen_dev *next; /* Used for chaining in the thread's run-queue */
int running; /* if this changes to false, the test will stop */
......@@ -307,10 +305,10 @@ struct pktgen_dev {
*/
__u16 pad; /* pad out the hh struct to an even 16 bytes */
struct sk_buff* skb; /* skb we are to transmit next, mainly used for when we
struct sk_buff *skb; /* skb we are to transmit next, mainly used for when we
* are transmitting the same one multiple times
*/
struct net_device* odev; /* The out-going device. Note that the device should
struct net_device *odev; /* The out-going device. Note that the device should
* have it's pg_info pointer pointing back to this
* device. This will be set when the user specifies
* the out-going device name (not when the inject is
......@@ -332,12 +330,12 @@ struct pktgen_hdr {
struct pktgen_thread {
spinlock_t if_lock;
struct pktgen_dev *if_list; /* All device here */
struct pktgen_thread* next;
struct pktgen_thread *next;
char name[32];
char result[512];
u32 max_before_softirq; /* We'll call do_softirq to prevent starvation. */
/* Field for thread to receive "posted" events terminate, stop ifs etc.*/
/* Field for thread to receive "posted" events terminate, stop ifs etc. */
u32 control;
int pid;
......@@ -379,7 +377,7 @@ static inline s64 divremdi3(s64 x, s64 y, int type)
}
do {
if ( a >= b ) {
if (a >= b) {
a -= b;
res += d;
}
......@@ -389,33 +387,32 @@ static inline s64 divremdi3(s64 x, s64 y, int type)
while (d);
if (PG_DIV == type) {
return (((x ^ y) & (1ll<<63)) == 0) ? res : -(s64)res;
}
else {
return ((x & (1ll<<63)) == 0) ? a : -(s64)a;
return (((x ^ y) & (1ll << 63)) == 0) ? res : -(s64) res;
} else {
return ((x & (1ll << 63)) == 0) ? a : -(s64) a;
}
}
/* End of hacks to deal with 64-bit math on x86 */
/** Convert to milliseconds */
static inline __u64 tv_to_ms(const struct timeval* tv)
static inline __u64 tv_to_ms(const struct timeval *tv)
{
__u64 ms = tv->tv_usec / 1000;
ms += (__u64)tv->tv_sec * (__u64)1000;
ms += (__u64) tv->tv_sec * (__u64) 1000;
return ms;
}
/** Convert to micro-seconds */
static inline __u64 tv_to_us(const struct timeval* tv)
static inline __u64 tv_to_us(const struct timeval *tv)
{
__u64 us = tv->tv_usec;
us += (__u64)tv->tv_sec * (__u64)1000000;
us += (__u64) tv->tv_sec * (__u64) 1000000;
return us;
}
static inline __u64 pg_div(__u64 n, __u32 base) {
static inline __u64 pg_div(__u64 n, __u32 base)
{
__u64 tmp = n;
do_div(tmp, base);
/* printk("pktgen: pg_div, n: %llu base: %d rv: %llu\n",
......@@ -465,28 +462,28 @@ static inline __u64 getCurUs(void)
return tv_to_us(&tv);
}
static inline __u64 tv_diff(const struct timeval* a, const struct timeval* b)
static inline __u64 tv_diff(const struct timeval *a, const struct timeval *b)
{
return tv_to_us(a) - tv_to_us(b);
}
/* old include end */
static char version[] __initdata = VERSION;
static int pktgen_remove_device(struct pktgen_thread* t, struct pktgen_dev *i);
static int pktgen_add_device(struct pktgen_thread* t, const char* ifname);
static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread* t, const char* ifname);
static int pktgen_remove_device(struct pktgen_thread *t, struct pktgen_dev *i);
static int pktgen_add_device(struct pktgen_thread *t, const char *ifname);
static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t,
const char *ifname);
static int pktgen_device_event(struct notifier_block *, unsigned long, void *);
static void pktgen_run_all_threads(void);
static void pktgen_stop_all_threads_ifs(void);
static int pktgen_stop_device(struct pktgen_dev *pkt_dev);
static void pktgen_stop(struct pktgen_thread* t);
static void pktgen_stop(struct pktgen_thread *t);
static void pktgen_clear_counters(struct pktgen_dev *pkt_dev);
static int pktgen_mark_device(const char* ifname);
static unsigned int scan_ip6(const char *s,char ip[16]);
static unsigned int fmt_ip6(char *s,const char ip[16]);
static int pktgen_mark_device(const char *ifname);
static unsigned int scan_ip6(const char *s, char ip[16]);
static unsigned int fmt_ip6(char *s, const char ip[16]);
/* Module parameters, defaults. */
static int pg_count_d = 1000; /* 1000 pkts by default */
......@@ -512,13 +509,13 @@ static int pgctrl_show(struct seq_file *seq, void *v)
return 0;
}
static ssize_t pgctrl_write(struct file* file,const char __user * buf,
size_t count, loff_t *ppos)
static ssize_t pgctrl_write(struct file *file, const char __user * buf,
size_t count, loff_t * ppos)
{
int err = 0;
char data[128];
if (!capable(CAP_NET_ADMIN)){
if (!capable(CAP_NET_ADMIN)) {
err = -EPERM;
goto out;
}
......@@ -530,7 +527,7 @@ static ssize_t pgctrl_write(struct file* file,const char __user * buf,
err = -EFAULT;
goto out;
}
data[count-1] = 0; /* Make string */
data[count - 1] = 0; /* Make string */
if (!strcmp(data, "stop"))
pktgen_stop_all_threads_ifs();
......@@ -543,7 +540,7 @@ static ssize_t pgctrl_write(struct file* file,const char __user * buf,
err = count;
out:
out:
return err;
}
......@@ -569,54 +566,67 @@ static int pktgen_if_show(struct seq_file *seq, void *v)
__u64 stopped;
__u64 now = getCurUs();
seq_printf(seq, "Params: count %llu min_pkt_size: %u max_pkt_size: %u\n",
(unsigned long long) pkt_dev->count,
pkt_dev->min_pkt_size, pkt_dev->max_pkt_size);
seq_printf(seq,
"Params: count %llu min_pkt_size: %u max_pkt_size: %u\n",
(unsigned long long)pkt_dev->count, pkt_dev->min_pkt_size,
pkt_dev->max_pkt_size);
seq_printf(seq, " frags: %d delay: %u clone_skb: %d ifname: %s\n",
pkt_dev->nfrags, 1000*pkt_dev->delay_us+pkt_dev->delay_ns, pkt_dev->clone_skb, pkt_dev->ifname);
seq_printf(seq,
" frags: %d delay: %u clone_skb: %d ifname: %s\n",
pkt_dev->nfrags,
1000 * pkt_dev->delay_us + pkt_dev->delay_ns,
pkt_dev->clone_skb, pkt_dev->ifname);
seq_printf(seq, " flows: %u flowlen: %u\n", pkt_dev->cflows, pkt_dev->lflow);
seq_printf(seq, " flows: %u flowlen: %u\n", pkt_dev->cflows,
pkt_dev->lflow);
if(pkt_dev->flags & F_IPV6) {
if (pkt_dev->flags & F_IPV6) {
char b1[128], b2[128], b3[128];
fmt_ip6(b1, pkt_dev->in6_saddr.s6_addr);
fmt_ip6(b2, pkt_dev->min_in6_saddr.s6_addr);
fmt_ip6(b3, pkt_dev->max_in6_saddr.s6_addr);
seq_printf(seq, " saddr: %s min_saddr: %s max_saddr: %s\n", b1, b2, b3);
seq_printf(seq,
" saddr: %s min_saddr: %s max_saddr: %s\n", b1,
b2, b3);
fmt_ip6(b1, pkt_dev->in6_daddr.s6_addr);
fmt_ip6(b2, pkt_dev->min_in6_daddr.s6_addr);
fmt_ip6(b3, pkt_dev->max_in6_daddr.s6_addr);
seq_printf(seq, " daddr: %s min_daddr: %s max_daddr: %s\n", b1, b2, b3);
seq_printf(seq,
" daddr: %s min_daddr: %s max_daddr: %s\n", b1,
b2, b3);
}
else
seq_printf(seq," dst_min: %s dst_max: %s\n src_min: %s src_max: %s\n",
pkt_dev->dst_min, pkt_dev->dst_max, pkt_dev->src_min, pkt_dev->src_max);
} else
seq_printf(seq,
" dst_min: %s dst_max: %s\n src_min: %s src_max: %s\n",
pkt_dev->dst_min, pkt_dev->dst_max, pkt_dev->src_min,
pkt_dev->src_max);
seq_puts(seq, " src_mac: ");
if (is_zero_ether_addr(pkt_dev->src_mac))
for (i = 0; i < 6; i++)
seq_printf(seq, "%02X%s", pkt_dev->odev->dev_addr[i], i == 5 ? " " : ":");
seq_printf(seq, "%02X%s", pkt_dev->odev->dev_addr[i],
i == 5 ? " " : ":");
else
for (i = 0; i < 6; i++)
seq_printf(seq, "%02X%s", pkt_dev->src_mac[i], i == 5 ? " " : ":");
seq_printf(seq, "%02X%s", pkt_dev->src_mac[i],
i == 5 ? " " : ":");
seq_printf(seq, "dst_mac: ");
for (i = 0; i < 6; i++)
seq_printf(seq, "%02X%s", pkt_dev->dst_mac[i], i == 5 ? "\n" : ":");
seq_printf(seq, "%02X%s", pkt_dev->dst_mac[i],
i == 5 ? "\n" : ":");
seq_printf(seq, " udp_src_min: %d udp_src_max: %d udp_dst_min: %d udp_dst_max: %d\n",
pkt_dev->udp_src_min, pkt_dev->udp_src_max, pkt_dev->udp_dst_min,
pkt_dev->udp_dst_max);
seq_printf(seq,
" udp_src_min: %d udp_src_max: %d udp_dst_min: %d udp_dst_max: %d\n",
pkt_dev->udp_src_min, pkt_dev->udp_src_max,
pkt_dev->udp_dst_min, pkt_dev->udp_dst_max);
seq_printf(seq, " src_mac_count: %d dst_mac_count: %d \n Flags: ",
seq_printf(seq,
" src_mac_count: %d dst_mac_count: %d \n Flags: ",
pkt_dev->src_mac_count, pkt_dev->dst_mac_count);
if (pkt_dev->flags & F_IPV6)
seq_printf(seq, "IPV6 ");
......@@ -641,7 +651,6 @@ static int pktgen_if_show(struct seq_file *seq, void *v)
if (pkt_dev->flags & F_MACDST_RND)
seq_printf(seq, "MACDST_RND ");
seq_puts(seq, "\n");
sa = pkt_dev->started_at;
......@@ -649,28 +658,27 @@ static int pktgen_if_show(struct seq_file *seq, void *v)
if (pkt_dev->running)
stopped = now; /* not really stopped, more like last-running-at */
seq_printf(seq, "Current:\n pkts-sofar: %llu errors: %llu\n started: %lluus stopped: %lluus idle: %lluus\n",
(unsigned long long) pkt_dev->sofar,
(unsigned long long) pkt_dev->errors,
(unsigned long long) sa,
(unsigned long long) stopped,
(unsigned long long) pkt_dev->idle_acc);
seq_printf(seq,
"Current:\n pkts-sofar: %llu errors: %llu\n started: %lluus stopped: %lluus idle: %lluus\n",
(unsigned long long)pkt_dev->sofar,
(unsigned long long)pkt_dev->errors, (unsigned long long)sa,
(unsigned long long)stopped,
(unsigned long long)pkt_dev->idle_acc);
seq_printf(seq, " seq_num: %d cur_dst_mac_offset: %d cur_src_mac_offset: %d\n",
seq_printf(seq,
" seq_num: %d cur_dst_mac_offset: %d cur_src_mac_offset: %d\n",
pkt_dev->seq_num, pkt_dev->cur_dst_mac_offset,
pkt_dev->cur_src_mac_offset);
if(pkt_dev->flags & F_IPV6) {
if (pkt_dev->flags & F_IPV6) {
char b1[128], b2[128];
fmt_ip6(b1, pkt_dev->cur_in6_daddr.s6_addr);
fmt_ip6(b2, pkt_dev->cur_in6_saddr.s6_addr);
seq_printf(seq, " cur_saddr: %s cur_daddr: %s\n", b2, b1);
}
else
} else
seq_printf(seq, " cur_saddr: 0x%x cur_daddr: 0x%x\n",
pkt_dev->cur_saddr, pkt_dev->cur_daddr);
seq_printf(seq, " cur_udp_dst: %d cur_udp_src: %d\n",
pkt_dev->cur_udp_dst, pkt_dev->cur_udp_src);
......@@ -684,8 +692,8 @@ static int pktgen_if_show(struct seq_file *seq, void *v)
return 0;
}
static int count_trail_chars(const char __user *user_buffer, unsigned int maxlen)
static int count_trail_chars(const char __user * user_buffer,
unsigned int maxlen)
{
int i;
......@@ -709,30 +717,30 @@ static int count_trail_chars(const char __user *user_buffer, unsigned int maxlen
return i;
}
static unsigned long num_arg(const char __user *user_buffer, unsigned long maxlen,
unsigned long *num)
static unsigned long num_arg(const char __user * user_buffer,
unsigned long maxlen, unsigned long *num)
{
int i = 0;
*num = 0;
for(; i < maxlen; i++) {
for (; i < maxlen; i++) {
char c;
if (get_user(c, &user_buffer[i]))
return -EFAULT;
if ((c >= '0') && (c <= '9')) {
*num *= 10;
*num += c -'0';
*num += c - '0';
} else
break;
}
return i;
}
static int strn_len(const char __user *user_buffer, unsigned int maxlen)
static int strn_len(const char __user * user_buffer, unsigned int maxlen)
{
int i = 0;
for(; i < maxlen; i++) {
for (; i < maxlen; i++) {
char c;
if (get_user(c, &user_buffer[i]))
return -EFAULT;
......@@ -749,19 +757,19 @@ static int strn_len(const char __user *user_buffer, unsigned int maxlen)
};
}
done_str:
return i;
}
static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer,
size_t count, loff_t *offset)
static ssize_t pktgen_if_write(struct file *file,
const char __user * user_buffer, size_t count,
loff_t * offset)
{
struct seq_file *seq = (struct seq_file *) file->private_data;
struct seq_file *seq = (struct seq_file *)file->private_data;
struct pktgen_dev *pkt_dev = seq->private;
int i = 0, max, len;
char name[16], valstr[32];
unsigned long value = 0;
char* pg_result = NULL;
char *pg_result = NULL;
int tmp = 0;
char buf[128];
......@@ -783,13 +791,15 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
/* Read variable name */
len = strn_len(&user_buffer[i], sizeof(name) - 1);
if (len < 0) { return len; }
if (len < 0) {
return len;
}
memset(name, 0, sizeof(name));
if (copy_from_user(name, &user_buffer[i], len) )
if (copy_from_user(name, &user_buffer[i], len))
return -EFAULT;
i += len;
max = count -i;
max = count - i;
len = count_trail_chars(&user_buffer[i], max);
if (len < 0)
return len;
......@@ -802,34 +812,40 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
return -EFAULT;
tb[count] = 0;
printk("pktgen: %s,%lu buffer -:%s:-\n", name,
(unsigned long) count, tb);
(unsigned long)count, tb);
}
if (!strcmp(name, "min_pkt_size")) {
len = num_arg(&user_buffer[i], 10, &value);
if (len < 0) { return len; }
if (len < 0) {
return len;
}
i += len;
if (value < 14+20+8)
value = 14+20+8;
if (value < 14 + 20 + 8)
value = 14 + 20 + 8;
if (value != pkt_dev->min_pkt_size) {
pkt_dev->min_pkt_size = value;
pkt_dev->cur_pkt_size = value;
}
sprintf(pg_result, "OK: min_pkt_size=%u", pkt_dev->min_pkt_size);
sprintf(pg_result, "OK: min_pkt_size=%u",
pkt_dev->min_pkt_size);
return count;
}
if (!strcmp(name, "max_pkt_size")) {
len = num_arg(&user_buffer[i], 10, &value);
if (len < 0) { return len; }
if (len < 0) {
return len;
}
i += len;
if (value < 14+20+8)
value = 14+20+8;
if (value < 14 + 20 + 8)
value = 14 + 20 + 8;
if (value != pkt_dev->max_pkt_size) {
pkt_dev->max_pkt_size = value;
pkt_dev->cur_pkt_size = value;
}
sprintf(pg_result, "OK: max_pkt_size=%u", pkt_dev->max_pkt_size);
sprintf(pg_result, "OK: max_pkt_size=%u",
pkt_dev->max_pkt_size);
return count;
}
......@@ -837,10 +853,12 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
if (!strcmp(name, "pkt_size")) {
len = num_arg(&user_buffer[i], 10, &value);
if (len < 0) { return len; }
if (len < 0) {
return len;
}
i += len;
if (value < 14+20+8)
value = 14+20+8;
if (value < 14 + 20 + 8)
value = 14 + 20 + 8;
if (value != pkt_dev->min_pkt_size) {
pkt_dev->min_pkt_size = value;
pkt_dev->max_pkt_size = value;
......@@ -852,7 +870,9 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
if (!strcmp(name, "debug")) {
len = num_arg(&user_buffer[i], 10, &value);
if (len < 0) { return len; }
if (len < 0) {
return len;
}
i += len;
debug = value;
sprintf(pg_result, "OK: debug=%u", debug);
......@@ -861,7 +881,9 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
if (!strcmp(name, "frags")) {
len = num_arg(&user_buffer[i], 10, &value);
if (len < 0) { return len; }
if (len < 0) {
return len;
}
i += len;
pkt_dev->nfrags = value;
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
}
if (!strcmp(name, "delay")) {
len = num_arg(&user_buffer[i], 10, &value);
if (len < 0) { return len; }
if (len < 0) {
return len;
}
i += len;
if (value == 0x7FFFFFFF) {
pkt_dev->delay_us = 0x7FFFFFFF;
......@@ -878,12 +902,15 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
pkt_dev->delay_us = value / 1000;
pkt_dev->delay_ns = value % 1000;
}
sprintf(pg_result, "OK: delay=%u", 1000*pkt_dev->delay_us+pkt_dev->delay_ns);
sprintf(pg_result, "OK: delay=%u",
1000 * pkt_dev->delay_us + pkt_dev->delay_ns);
return count;
}
if (!strcmp(name, "udp_src_min")) {
len = num_arg(&user_buffer[i], 10, &value);
if (len < 0) { return len; }
if (len < 0) {
return len;
}
i += len;
if (value != pkt_dev->udp_src_min) {
pkt_dev->udp_src_min = value;
......@@ -894,7 +921,9 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
}
if (!strcmp(name, "udp_dst_min")) {
len = num_arg(&user_buffer[i], 10, &value);
if (len < 0) { return len; }
if (len < 0) {
return len;
}
i += len;
if (value != pkt_dev->udp_dst_min) {
pkt_dev->udp_dst_min = value;
......@@ -905,7 +934,9 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
}
if (!strcmp(name, "udp_src_max")) {
len = num_arg(&user_buffer[i], 10, &value);
if (len < 0) { return len; }
if (len < 0) {
return len;
}
i += len;
if (value != pkt_dev->udp_src_max) {
pkt_dev->udp_src_max = value;
......@@ -916,7 +947,9 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
}
if (!strcmp(name, "udp_dst_max")) {
len = num_arg(&user_buffer[i], 10, &value);
if (len < 0) { return len; }
if (len < 0) {
return len;
}
i += len;
if (value != pkt_dev->udp_dst_max) {
pkt_dev->udp_dst_max = value;
......@@ -927,7 +960,9 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
}
if (!strcmp(name, "clone_skb")) {
len = num_arg(&user_buffer[i], 10, &value);
if (len < 0) { return len; }
if (len < 0) {
return len;
}
i += len;
pkt_dev->clone_skb = value;
......@@ -936,40 +971,50 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
}
if (!strcmp(name, "count")) {
len = num_arg(&user_buffer[i], 10, &value);
if (len < 0) { return len; }
if (len < 0) {
return len;
}
i += len;
pkt_dev->count = value;
sprintf(pg_result, "OK: count=%llu",
(unsigned long long) pkt_dev->count);
(unsigned long long)pkt_dev->count);
return count;
}
if (!strcmp(name, "src_mac_count")) {
len = num_arg(&user_buffer[i], 10, &value);
if (len < 0) { return len; }
if (len < 0) {
return len;
}
i += len;
if (pkt_dev->src_mac_count != value) {
pkt_dev->src_mac_count = value;
pkt_dev->cur_src_mac_offset = 0;
}
sprintf(pg_result, "OK: src_mac_count=%d", pkt_dev->src_mac_count);
sprintf(pg_result, "OK: src_mac_count=%d",
pkt_dev->src_mac_count);
return count;
}
if (!strcmp(name, "dst_mac_count")) {
len = num_arg(&user_buffer[i], 10, &value);
if (len < 0) { return len; }
if (len < 0) {
return len;
}
i += len;
if (pkt_dev->dst_mac_count != value) {
pkt_dev->dst_mac_count = value;
pkt_dev->cur_dst_mac_offset = 0;
}
sprintf(pg_result, "OK: dst_mac_count=%d", pkt_dev->dst_mac_count);
sprintf(pg_result, "OK: dst_mac_count=%d",
pkt_dev->dst_mac_count);
return count;
}
if (!strcmp(name, "flag")) {
char f[32];
memset(f, 0, 32);
len = strn_len(&user_buffer[i], sizeof(f) - 1);
if (len < 0) { return len; }
if (len < 0) {
return len;
}
if (copy_from_user(f, &user_buffer[i], len))
return -EFAULT;
i += len;
......@@ -1016,7 +1061,8 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
pkt_dev->flags &= ~F_MACDST_RND;
else {
sprintf(pg_result, "Flag -:%s:- unknown\nAvailable flags, (prepend ! to un-set flag):\n%s",
sprintf(pg_result,
"Flag -:%s:- unknown\nAvailable flags, (prepend ! to un-set flag):\n%s",
f,
"IPSRC_RND, IPDST_RND, TXSIZE_RND, UDPSRC_RND, UDPDST_RND, MACSRC_RND, MACDST_RND\n");
return count;
......@@ -1026,7 +1072,9 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
}
if (!strcmp(name, "dst_min") || !strcmp(name, "dst")) {
len = strn_len(&user_buffer[i], sizeof(pkt_dev->dst_min) - 1);
if (len < 0) { return len; }
if (len < 0) {
return len;
}
if (copy_from_user(buf, &user_buffer[i], len))
return -EFAULT;
......@@ -1037,15 +1085,18 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
pkt_dev->daddr_min = in_aton(pkt_dev->dst_min);
pkt_dev->cur_daddr = pkt_dev->daddr_min;
}
if(debug)
printk("pktgen: dst_min set to: %s\n", pkt_dev->dst_min);
if (debug)
printk("pktgen: dst_min set to: %s\n",
pkt_dev->dst_min);
i += len;
sprintf(pg_result, "OK: dst_min=%s", pkt_dev->dst_min);
return count;
}
if (!strcmp(name, "dst_max")) {
len = strn_len(&user_buffer[i], sizeof(pkt_dev->dst_max) - 1);
if (len < 0) { return len; }
if (len < 0) {
return len;
}
if (copy_from_user(buf, &user_buffer[i], len))
return -EFAULT;
......@@ -1057,15 +1108,17 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
pkt_dev->daddr_max = in_aton(pkt_dev->dst_max);
pkt_dev->cur_daddr = pkt_dev->daddr_max;
}
if(debug)
printk("pktgen: dst_max set to: %s\n", pkt_dev->dst_max);
if (debug)
printk("pktgen: dst_max set to: %s\n",
pkt_dev->dst_max);
i += len;
sprintf(pg_result, "OK: dst_max=%s", pkt_dev->dst_max);
return count;
}
if (!strcmp(name, "dst6")) {
len = strn_len(&user_buffer[i], sizeof(buf) - 1);
if (len < 0) return len;
if (len < 0)
return len;
pkt_dev->flags |= F_IPV6;
......@@ -1078,7 +1131,7 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
ipv6_addr_copy(&pkt_dev->cur_in6_daddr, &pkt_dev->in6_daddr);
if(debug)
if (debug)
printk("pktgen: dst6 set to: %s\n", buf);
i += len;
......@@ -1087,7 +1140,8 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
}
if (!strcmp(name, "dst6_min")) {
len = strn_len(&user_buffer[i], sizeof(buf) - 1);
if (len < 0) return len;
if (len < 0)
return len;
pkt_dev->flags |= F_IPV6;
......@@ -1098,8 +1152,9 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
scan_ip6(buf, pkt_dev->min_in6_daddr.s6_addr);
fmt_ip6(buf, pkt_dev->min_in6_daddr.s6_addr);
ipv6_addr_copy(&pkt_dev->cur_in6_daddr, &pkt_dev->min_in6_daddr);
if(debug)
ipv6_addr_copy(&pkt_dev->cur_in6_daddr,
&pkt_dev->min_in6_daddr);
if (debug)
printk("pktgen: dst6_min set to: %s\n", buf);
i += len;
......@@ -1108,7 +1163,8 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
}
if (!strcmp(name, "dst6_max")) {
len = strn_len(&user_buffer[i], sizeof(buf) - 1);
if (len < 0) return len;
if (len < 0)
return len;
pkt_dev->flags |= F_IPV6;
......@@ -1119,7 +1175,7 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
scan_ip6(buf, pkt_dev->max_in6_daddr.s6_addr);
fmt_ip6(buf, pkt_dev->max_in6_daddr.s6_addr);
if(debug)
if (debug)
printk("pktgen: dst6_max set to: %s\n", buf);
i += len;
......@@ -1128,7 +1184,8 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
}
if (!strcmp(name, "src6")) {
len = strn_len(&user_buffer[i], sizeof(buf) - 1);
if (len < 0) return len;
if (len < 0)
return len;
pkt_dev->flags |= F_IPV6;
......@@ -1141,7 +1198,7 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
ipv6_addr_copy(&pkt_dev->cur_in6_saddr, &pkt_dev->in6_saddr);
if(debug)
if (debug)
printk("pktgen: src6 set to: %s\n", buf);
i += len;
......@@ -1150,7 +1207,9 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
}
if (!strcmp(name, "src_min")) {
len = strn_len(&user_buffer[i], sizeof(pkt_dev->src_min) - 1);
if (len < 0) { return len; }
if (len < 0) {
return len;
}
if (copy_from_user(buf, &user_buffer[i], len))
return -EFAULT;
buf[len] = 0;
......@@ -1160,15 +1219,18 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
pkt_dev->saddr_min = in_aton(pkt_dev->src_min);
pkt_dev->cur_saddr = pkt_dev->saddr_min;
}
if(debug)
printk("pktgen: src_min set to: %s\n", pkt_dev->src_min);
if (debug)
printk("pktgen: src_min set to: %s\n",
pkt_dev->src_min);
i += len;
sprintf(pg_result, "OK: src_min=%s", pkt_dev->src_min);
return count;
}
if (!strcmp(name, "src_max")) {
len = strn_len(&user_buffer[i], sizeof(pkt_dev->src_max) - 1);
if (len < 0) { return len; }
if (len < 0) {
return len;
}
if (copy_from_user(buf, &user_buffer[i], len))
return -EFAULT;
buf[len] = 0;
......@@ -1178,8 +1240,9 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
pkt_dev->saddr_max = in_aton(pkt_dev->src_max);
pkt_dev->cur_saddr = pkt_dev->saddr_max;
}
if(debug)
printk("pktgen: src_max set to: %s\n", pkt_dev->src_max);
if (debug)
printk("pktgen: src_max set to: %s\n",
pkt_dev->src_max);
i += len;
sprintf(pg_result, "OK: src_max=%s", pkt_dev->src_max);
return count;
......@@ -1191,13 +1254,15 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
memcpy(old_dmac, pkt_dev->dst_mac, ETH_ALEN);
len = strn_len(&user_buffer[i], sizeof(valstr) - 1);
if (len < 0) { return len; }
if (len < 0) {
return len;
}
memset(valstr, 0, sizeof(valstr));
if( copy_from_user(valstr, &user_buffer[i], len))
if (copy_from_user(valstr, &user_buffer[i], len))
return -EFAULT;
i += len;
for(*m = 0;*v && m < pkt_dev->dst_mac + 6; v++) {
for (*m = 0; *v && m < pkt_dev->dst_mac + 6; v++) {
if (*v >= '0' && *v <= '9') {
*m *= 16;
*m += *v - '0';
......@@ -1228,13 +1293,15 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
unsigned char *m = pkt_dev->src_mac;
len = strn_len(&user_buffer[i], sizeof(valstr) - 1);
if (len < 0) { return len; }
if (len < 0) {
return len;
}
memset(valstr, 0, sizeof(valstr));
if( copy_from_user(valstr, &user_buffer[i], len))
if (copy_from_user(valstr, &user_buffer[i], len))
return -EFAULT;
i += len;
for(*m = 0;*v && m < pkt_dev->src_mac + 6; v++) {
for (*m = 0; *v && m < pkt_dev->src_mac + 6; v++) {
if (*v >= '0' && *v <= '9') {
*m *= 16;
*m += *v - '0';
......@@ -1265,7 +1332,9 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
if (!strcmp(name, "flows")) {
len = num_arg(&user_buffer[i], 10, &value);
if (len < 0) { return len; }
if (len < 0) {
return len;
}
i += len;
if (value > MAX_CFLOWS)
value = MAX_CFLOWS;
......@@ -1277,7 +1346,9 @@ static ssize_t pktgen_if_write(struct file *file, const char __user *user_buffer
if (!strcmp(name, "flowlen")) {
len = num_arg(&user_buffer[i], 10, &value);
if (len < 0) { return len; }
if (len < 0) {
return len;
}
i += len;
pkt_dev->lflow = value;
sprintf(pg_result, "OK: flowlen=%u", pkt_dev->lflow);
......@@ -1315,14 +1386,14 @@ static int pktgen_thread_show(struct seq_file *seq, void *v)
seq_printf(seq, "Running: ");
if_lock(t);
for(pkt_dev = t->if_list;pkt_dev; pkt_dev = pkt_dev->next)
if(pkt_dev->running)
for (pkt_dev = t->if_list; pkt_dev; pkt_dev = pkt_dev->next)
if (pkt_dev->running)
seq_printf(seq, "%s ", pkt_dev->ifname);
seq_printf(seq, "\nStopped: ");
for(pkt_dev = t->if_list;pkt_dev; pkt_dev = pkt_dev->next)
if(!pkt_dev->running)
for (pkt_dev = t->if_list; pkt_dev; pkt_dev = pkt_dev->next)
if (!pkt_dev->running)
seq_printf(seq, "%s ", pkt_dev->ifname);
if (t->result[0])
......@@ -1336,10 +1407,10 @@ static int pktgen_thread_show(struct seq_file *seq, void *v)
}
static ssize_t pktgen_thread_write(struct file *file,
const char __user *user_buffer,
size_t count, loff_t *offset)
const char __user * user_buffer,
size_t count, loff_t * offset)
{
struct seq_file *seq = (struct seq_file *) file->private_data;
struct seq_file *seq = (struct seq_file *)file->private_data;
struct pktgen_thread *t = seq->private;
int i = 0, max, len, ret;
char name[40];
......@@ -1369,7 +1440,7 @@ static ssize_t pktgen_thread_write(struct file *file,
return -EFAULT;
i += len;
max = count -i;
max = count - i;
len = count_trail_chars(&user_buffer[i], max);
if (len < 0)
return len;
......@@ -1377,10 +1448,9 @@ static ssize_t pktgen_thread_write(struct file *file,
i += len;
if (debug)
printk("pktgen: t=%s, count=%lu\n", name,
(unsigned long) count);
printk("pktgen: t=%s, count=%lu\n", name, (unsigned long)count);
if(!t) {
if (!t) {
printk("pktgen: ERROR: No thread\n");
ret = -EINVAL;
goto out;
......@@ -1396,7 +1466,7 @@ static ssize_t pktgen_thread_write(struct file *file,
ret = len;
goto out;
}
if( copy_from_user(f, &user_buffer[i], len) )
if (copy_from_user(f, &user_buffer[i], len))
return -EFAULT;
i += len;
thread_lock();
......@@ -1428,8 +1498,7 @@ static ssize_t pktgen_thread_write(struct file *file,
}
ret = -EINVAL;
out:
out:
return ret;
}
......@@ -1448,7 +1517,7 @@ static struct file_operations pktgen_thread_fops = {
};
/* Think find or remove for NN */
static struct pktgen_dev *__pktgen_NN_threads(const char* ifname, int remove)
static struct pktgen_dev *__pktgen_NN_threads(const char *ifname, int remove)
{
struct pktgen_thread *t;
struct pktgen_dev *pkt_dev = NULL;
......@@ -1458,7 +1527,7 @@ static struct pktgen_dev *__pktgen_NN_threads(const char* ifname, int remove)
while (t) {
pkt_dev = pktgen_find_dev(t, ifname);
if (pkt_dev) {
if(remove) {
if (remove) {
if_lock(t);
pkt_dev->removal_mark = 1;
t->control |= T_REMDEV;
......@@ -1474,7 +1543,7 @@ static struct pktgen_dev *__pktgen_NN_threads(const char* ifname, int remove)
/*
* mark a device for removal
*/
static int pktgen_mark_device(const char* ifname)
static int pktgen_mark_device(const char *ifname)
{
struct pktgen_dev *pkt_dev = NULL;
const int max_tries = 10, msec_per_try = 125;
......@@ -1485,10 +1554,11 @@ static int pktgen_mark_device(const char* ifname)
PG_DEBUG(printk("pktgen: pktgen_mark_device marking %s for removal\n",
ifname));
while(1) {
while (1) {
pkt_dev = __pktgen_NN_threads(ifname, REMOVE);
if (pkt_dev == NULL) break; /* success */
if (pkt_dev == NULL)
break; /* success */
thread_unlock();
PG_DEBUG(printk("pktgen: pktgen_mark_device waiting for %s "
......@@ -1499,7 +1569,7 @@ static int pktgen_mark_device(const char* ifname)
if (++i >= max_tries) {
printk("pktgen_mark_device: timed out after waiting "
"%d msec for device %s to be removed\n",
msec_per_try*i, ifname);
msec_per_try * i, ifname);
ret = 1;
break;
}
......@@ -1511,7 +1581,8 @@ static int pktgen_mark_device(const char* ifname)
return ret;
}
static int pktgen_device_event(struct notifier_block *unused, unsigned long event, void *ptr)
static int pktgen_device_event(struct notifier_block *unused,
unsigned long event, void *ptr)
{
struct net_device *dev = (struct net_device *)(ptr);
......@@ -1537,7 +1608,8 @@ static int pktgen_device_event(struct notifier_block *unused, unsigned long even
/* Associate pktgen_dev with a device. */
static struct net_device* pktgen_setup_dev(struct pktgen_dev *pkt_dev) {
static struct net_device *pktgen_setup_dev(struct pktgen_dev *pkt_dev)
{
struct net_device *odev;
/* Clean old setups */
......@@ -1554,7 +1626,8 @@ static struct net_device* pktgen_setup_dev(struct pktgen_dev *pkt_dev) {
goto out;
}
if (odev->type != ARPHRD_ETHER) {
printk("pktgen: not an ethernet device: \"%s\"\n", pkt_dev->ifname);
printk("pktgen: not an ethernet device: \"%s\"\n",
pkt_dev->ifname);
goto out_put;
}
if (!netif_running(odev)) {
......@@ -1583,7 +1656,8 @@ static void pktgen_setup_inject(struct pktgen_dev *pkt_dev)
if (!pkt_dev->odev) {
printk("pktgen: ERROR: pkt_dev->odev == NULL in setup_inject.\n");
sprintf(pkt_dev->result, "ERROR: pkt_dev->odev == NULL in setup_inject.\n");
sprintf(pkt_dev->result,
"ERROR: pkt_dev->odev == NULL in setup_inject.\n");
return;
}
......@@ -1598,23 +1672,23 @@ static void pktgen_setup_inject(struct pktgen_dev *pkt_dev)
/* Set up pkt size */
pkt_dev->cur_pkt_size = pkt_dev->min_pkt_size;
if(pkt_dev->flags & F_IPV6) {
if (pkt_dev->flags & F_IPV6) {
/*
* Skip this automatic address setting until locks or functions
* gets exported
*/
#ifdef NOTNOW
int i, set = 0, err=1;
int i, set = 0, err = 1;
struct inet6_dev *idev;
for(i=0; i< IN6_ADDR_HSIZE; i++)
if(pkt_dev->cur_in6_saddr.s6_addr[i]) {
for (i = 0; i < IN6_ADDR_HSIZE; i++)
if (pkt_dev->cur_in6_saddr.s6_addr[i]) {
set = 1;
break;
}
if(!set) {
if (!set) {
/*
* Use linklevel address if unconfigured.
......@@ -1622,15 +1696,19 @@ static void pktgen_setup_inject(struct pktgen_dev *pkt_dev)
* use ipv6_get_lladdr if/when it's get exported
*/
read_lock(&addrconf_lock);
if ((idev = __in6_dev_get(pkt_dev->odev)) != NULL) {
struct inet6_ifaddr *ifp;
read_lock_bh(&idev->lock);
for (ifp=idev->addr_list; ifp; ifp=ifp->if_next) {
if (ifp->scope == IFA_LINK && !(ifp->flags&IFA_F_TENTATIVE)) {
ipv6_addr_copy(&pkt_dev->cur_in6_saddr, &ifp->addr);
for (ifp = idev->addr_list; ifp;
ifp = ifp->if_next) {
if (ifp->scope == IFA_LINK
&& !(ifp->
flags & IFA_F_TENTATIVE)) {
ipv6_addr_copy(&pkt_dev->
cur_in6_saddr,
&ifp->addr);
err = 0;
break;
}
......@@ -1638,11 +1716,11 @@ static void pktgen_setup_inject(struct pktgen_dev *pkt_dev)
read_unlock_bh(&idev->lock);
}
read_unlock(&addrconf_lock);
if(err) printk("pktgen: ERROR: IPv6 link address not availble.\n");
if (err)
printk("pktgen: ERROR: IPv6 link address not availble.\n");
}
#endif
}
else {
} else {
pkt_dev->saddr_min = 0;
pkt_dev->saddr_max = 0;
if (strlen(pkt_dev->src_min) == 0) {
......@@ -1653,13 +1731,13 @@ static void pktgen_setup_inject(struct pktgen_dev *pkt_dev)
in_dev = __in_dev_get_rcu(pkt_dev->odev);
if (in_dev) {
if (in_dev->ifa_list) {
pkt_dev->saddr_min = in_dev->ifa_list->ifa_address;
pkt_dev->saddr_min =
in_dev->ifa_list->ifa_address;
pkt_dev->saddr_max = pkt_dev->saddr_min;
}
}
rcu_read_unlock();
}
else {
} else {
pkt_dev->saddr_min = in_aton(pkt_dev->src_min);
pkt_dev->saddr_max = in_aton(pkt_dev->src_max);
}
......@@ -1686,7 +1764,7 @@ static void spin(struct pktgen_dev *pkt_dev, __u64 spin_until_us)
printk(KERN_INFO "sleeping for %d\n", (int)(spin_until_us - now));
while (now < spin_until_us) {
/* TODO: optimize sleeping behavior */
if (spin_until_us - now > jiffies_to_usecs(1)+1)
if (spin_until_us - now > jiffies_to_usecs(1) + 1)
schedule_timeout_interruptible(1);
else if (spin_until_us - now > 100) {
do_softirq();
......@@ -1702,23 +1780,22 @@ static void spin(struct pktgen_dev *pkt_dev, __u64 spin_until_us)
pkt_dev->idle_acc += now - start;
}
/* Increment/randomize headers according to flags and current values
* for IP src/dest, UDP src/dst port, MAC-Addr src/dst
*/
static void mod_cur_headers(struct pktgen_dev *pkt_dev) {
static void mod_cur_headers(struct pktgen_dev *pkt_dev)
{
__u32 imn;
__u32 imx;
int flow = 0;
if(pkt_dev->cflows) {
if (pkt_dev->cflows) {
flow = pktgen_random() % pkt_dev->cflows;
if (pkt_dev->flows[flow].count > pkt_dev->lflow)
pkt_dev->flows[flow].count = 0;
}
/* Deal with source MAC */
if (pkt_dev->src_mac_count > 1) {
__u32 mc;
......@@ -1728,7 +1805,8 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev) {
mc = pktgen_random() % (pkt_dev->src_mac_count);
else {
mc = pkt_dev->cur_src_mac_offset++;
if (pkt_dev->cur_src_mac_offset > pkt_dev->src_mac_count)
if (pkt_dev->cur_src_mac_offset >
pkt_dev->src_mac_count)
pkt_dev->cur_src_mac_offset = 0;
}
......@@ -1754,7 +1832,8 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev) {
else {
mc = pkt_dev->cur_dst_mac_offset++;
if (pkt_dev->cur_dst_mac_offset > pkt_dev->dst_mac_count) {
if (pkt_dev->cur_dst_mac_offset >
pkt_dev->dst_mac_count) {
pkt_dev->cur_dst_mac_offset = 0;
}
}
......@@ -1773,7 +1852,10 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev) {
if (pkt_dev->udp_src_min < pkt_dev->udp_src_max) {
if (pkt_dev->flags & F_UDPSRC_RND)
pkt_dev->cur_udp_src = ((pktgen_random() % (pkt_dev->udp_src_max - pkt_dev->udp_src_min)) + pkt_dev->udp_src_min);
pkt_dev->cur_udp_src =
((pktgen_random() %
(pkt_dev->udp_src_max - pkt_dev->udp_src_min)) +
pkt_dev->udp_src_min);
else {
pkt_dev->cur_udp_src++;
......@@ -1784,9 +1866,11 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev) {
if (pkt_dev->udp_dst_min < pkt_dev->udp_dst_max) {
if (pkt_dev->flags & F_UDPDST_RND) {
pkt_dev->cur_udp_dst = ((pktgen_random() % (pkt_dev->udp_dst_max - pkt_dev->udp_dst_min)) + pkt_dev->udp_dst_min);
}
else {
pkt_dev->cur_udp_dst =
((pktgen_random() %
(pkt_dev->udp_dst_max - pkt_dev->udp_dst_min)) +
pkt_dev->udp_dst_min);
} else {
pkt_dev->cur_udp_dst++;
if (pkt_dev->cur_udp_dst >= pkt_dev->udp_dst_max)
pkt_dev->cur_udp_dst = pkt_dev->udp_dst_min;
......@@ -1795,7 +1879,9 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev) {
if (!(pkt_dev->flags & F_IPV6)) {
if ((imn = ntohl(pkt_dev->saddr_min)) < (imx = ntohl(pkt_dev->saddr_max))) {
if ((imn = ntohl(pkt_dev->saddr_min)) < (imx =
ntohl(pkt_dev->
saddr_max))) {
__u32 t;
if (pkt_dev->flags & F_IPSRC_RND)
t = ((pktgen_random() % (imx - imn)) + imn);
......@@ -1813,15 +1899,22 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev) {
pkt_dev->cur_daddr = pkt_dev->flows[flow].cur_daddr;
} else {
if ((imn = ntohl(pkt_dev->daddr_min)) < (imx = ntohl(pkt_dev->daddr_max))) {
if ((imn = ntohl(pkt_dev->daddr_min)) < (imx =
ntohl(pkt_dev->
daddr_max)))
{
__u32 t;
if (pkt_dev->flags & F_IPDST_RND) {
t = ((pktgen_random() % (imx - imn)) + imn);
t = ((pktgen_random() % (imx - imn)) +
imn);
t = htonl(t);
while( LOOPBACK(t) || MULTICAST(t) || BADCLASS(t) || ZERONET(t) || LOCAL_MCAST(t) ) {
t = ((pktgen_random() % (imx - imn)) + imn);
while (LOOPBACK(t) || MULTICAST(t)
|| BADCLASS(t) || ZERONET(t)
|| LOCAL_MCAST(t)) {
t = ((pktgen_random() %
(imx - imn)) + imn);
t = htonl(t);
}
pkt_dev->cur_daddr = t;
......@@ -1836,24 +1929,24 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev) {
pkt_dev->cur_daddr = htonl(t);
}
}
if(pkt_dev->cflows) {
pkt_dev->flows[flow].cur_daddr = pkt_dev->cur_daddr;
if (pkt_dev->cflows) {
pkt_dev->flows[flow].cur_daddr =
pkt_dev->cur_daddr;
pkt_dev->nflows++;
}
}
}
else /* IPV6 * */
{
if(pkt_dev->min_in6_daddr.s6_addr32[0] == 0 &&
} else { /* IPV6 * */
if (pkt_dev->min_in6_daddr.s6_addr32[0] == 0 &&
pkt_dev->min_in6_daddr.s6_addr32[1] == 0 &&
pkt_dev->min_in6_daddr.s6_addr32[2] == 0 &&
pkt_dev->min_in6_daddr.s6_addr32[3] == 0);
pkt_dev->min_in6_daddr.s6_addr32[3] == 0) ;
else {
int i;
/* Only random destinations yet */
for(i=0; i < 4; i++) {
for (i = 0; i < 4; i++) {
pkt_dev->cur_in6_daddr.s6_addr32[i] =
((pktgen_random() |
pkt_dev->min_in6_daddr.s6_addr32[i]) &
......@@ -1865,10 +1958,10 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev) {
if (pkt_dev->min_pkt_size < pkt_dev->max_pkt_size) {
__u32 t;
if (pkt_dev->flags & F_TXSIZE_RND) {
t = ((pktgen_random() % (pkt_dev->max_pkt_size - pkt_dev->min_pkt_size))
t = ((pktgen_random() %
(pkt_dev->max_pkt_size - pkt_dev->min_pkt_size))
+ pkt_dev->min_pkt_size);
}
else {
} else {
t = pkt_dev->cur_pkt_size + 1;
if (t > pkt_dev->max_pkt_size)
t = pkt_dev->min_pkt_size;
......@@ -1879,7 +1972,6 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev) {
pkt_dev->flows[flow].count++;
}
static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
struct pktgen_dev *pkt_dev)
{
......@@ -1910,7 +2002,7 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
udph = (struct udphdr *)skb_put(skb, sizeof(struct udphdr));
memcpy(eth, pkt_dev->hh, 12);
*(u16*)&eth[12] = __constant_htons(ETH_P_IP);
*(u16 *) & eth[12] = __constant_htons(ETH_P_IP);
datalen = pkt_dev->cur_pkt_size - 14 - 20 - 8; /* Eth + IPh + UDPh */
if (datalen < sizeof(struct pktgen_hdr))
......@@ -1932,9 +2024,9 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
iplen = 20 + 8 + datalen;
iph->tot_len = htons(iplen);
iph->check = 0;
iph->check = ip_fast_csum((void *) iph, iph->ihl);
iph->check = ip_fast_csum((void *)iph, iph->ihl);
skb->protocol = __constant_htons(ETH_P_IP);
skb->mac.raw = ((u8 *)iph) - 14;
skb->mac.raw = ((u8 *) iph) - 14;
skb->dev = odev;
skb->pkt_type = PACKET_HOST;
......@@ -1944,13 +2036,13 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
int frags = pkt_dev->nfrags;
int i;
pgh = (struct pktgen_hdr*)(((char*)(udph)) + 8);
pgh = (struct pktgen_hdr *)(((char *)(udph)) + 8);
if (frags > MAX_SKB_FRAGS)
frags = MAX_SKB_FRAGS;
if (datalen > frags*PAGE_SIZE) {
skb_put(skb, datalen-frags*PAGE_SIZE);
datalen = frags*PAGE_SIZE;
if (datalen > frags * PAGE_SIZE) {
skb_put(skb, datalen - frags * PAGE_SIZE);
datalen = frags * PAGE_SIZE;
}
i = 0;
......@@ -1979,10 +2071,13 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
skb_shinfo(skb)->frags[i - 1].size -= rem;
skb_shinfo(skb)->frags[i] = skb_shinfo(skb)->frags[i - 1];
skb_shinfo(skb)->frags[i] =
skb_shinfo(skb)->frags[i - 1];
get_page(skb_shinfo(skb)->frags[i].page);
skb_shinfo(skb)->frags[i].page = skb_shinfo(skb)->frags[i - 1].page;
skb_shinfo(skb)->frags[i].page_offset += skb_shinfo(skb)->frags[i - 1].size;
skb_shinfo(skb)->frags[i].page =
skb_shinfo(skb)->frags[i - 1].page;
skb_shinfo(skb)->frags[i].page_offset +=
skb_shinfo(skb)->frags[i - 1].size;
skb_shinfo(skb)->frags[i].size = rem;
i++;
skb_shinfo(skb)->nr_frags = i;
......@@ -2015,23 +2110,24 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
* --ro
*/
static unsigned int scan_ip6(const char *s,char ip[16])
static unsigned int scan_ip6(const char *s, char ip[16])
{
unsigned int i;
unsigned int len=0;
unsigned int len = 0;
unsigned long u;
char suffix[16];
unsigned int prefixlen=0;
unsigned int suffixlen=0;
unsigned int prefixlen = 0;
unsigned int suffixlen = 0;
__u32 tmp;
for (i=0; i<16; i++) ip[i]=0;
for (i = 0; i < 16; i++)
ip[i] = 0;
for (;;) {
if (*s == ':') {
len++;
if (s[1] == ':') { /* Found "::", skip to part 2 */
s+=2;
s += 2;
len++;
break;
}
......@@ -2039,117 +2135,137 @@ static unsigned int scan_ip6(const char *s,char ip[16])
}
{
char *tmp;
u=simple_strtoul(s,&tmp,16);
i=tmp-s;
u = simple_strtoul(s, &tmp, 16);
i = tmp - s;
}
if (!i) return 0;
if (prefixlen==12 && s[i]=='.') {
if (!i)
return 0;
if (prefixlen == 12 && s[i] == '.') {
/* the last 4 bytes may be written as IPv4 address */
tmp = in_aton(s);
memcpy((struct in_addr*)(ip+12), &tmp, sizeof(tmp));
return i+len;
memcpy((struct in_addr *)(ip + 12), &tmp, sizeof(tmp));
return i + len;
}
ip[prefixlen++] = (u >> 8);
ip[prefixlen++] = (u & 255);
s += i; len += i;
if (prefixlen==16)
s += i;
len += i;
if (prefixlen == 16)
return len;
}
/* part 2, after "::" */
for (;;) {
if (*s == ':') {
if (suffixlen==0)
if (suffixlen == 0)
break;
s++;
len++;
} else if (suffixlen!=0)
} else if (suffixlen != 0)
break;
{
char *tmp;
u=simple_strtol(s,&tmp,16);
i=tmp-s;
u = simple_strtol(s, &tmp, 16);
i = tmp - s;
}
if (!i) {
if (*s) len--;
if (*s)
len--;
break;
}
if (suffixlen+prefixlen<=12 && s[i]=='.') {
if (suffixlen + prefixlen <= 12 && s[i] == '.') {
tmp = in_aton(s);
memcpy((struct in_addr*)(suffix+suffixlen), &tmp, sizeof(tmp));
suffixlen+=4;
len+=strlen(s);
memcpy((struct in_addr *)(suffix + suffixlen), &tmp,
sizeof(tmp));
suffixlen += 4;
len += strlen(s);
break;
}
suffix[suffixlen++] = (u >> 8);
suffix[suffixlen++] = (u & 255);
s += i; len += i;
if (prefixlen+suffixlen==16)
s += i;
len += i;
if (prefixlen + suffixlen == 16)
break;
}
for (i=0; i<suffixlen; i++)
ip[16-suffixlen+i] = suffix[i];
for (i = 0; i < suffixlen; i++)
ip[16 - suffixlen + i] = suffix[i];
return len;
}
static char tohex(char hexdigit) {
return hexdigit>9?hexdigit+'a'-10:hexdigit+'0';
static char tohex(char hexdigit)
{
return hexdigit > 9 ? hexdigit + 'a' - 10 : hexdigit + '0';
}
static int fmt_xlong(char* s,unsigned int i) {
char* bak=s;
*s=tohex((i>>12)&0xf); if (s!=bak || *s!='0') ++s;
*s=tohex((i>>8)&0xf); if (s!=bak || *s!='0') ++s;
*s=tohex((i>>4)&0xf); if (s!=bak || *s!='0') ++s;
*s=tohex(i&0xf);
return s-bak+1;
static int fmt_xlong(char *s, unsigned int i)
{
char *bak = s;
*s = tohex((i >> 12) & 0xf);
if (s != bak || *s != '0')
++s;
*s = tohex((i >> 8) & 0xf);
if (s != bak || *s != '0')
++s;
*s = tohex((i >> 4) & 0xf);
if (s != bak || *s != '0')
++s;
*s = tohex(i & 0xf);
return s - bak + 1;
}
static unsigned int fmt_ip6(char *s,const char ip[16]) {
static unsigned int fmt_ip6(char *s, const char ip[16])
{
unsigned int len;
unsigned int i;
unsigned int temp;
unsigned int compressing;
int j;
len = 0; compressing = 0;
for (j=0; j<16; j+=2) {
len = 0;
compressing = 0;
for (j = 0; j < 16; j += 2) {
#ifdef V4MAPPEDPREFIX
if (j==12 && !memcmp(ip,V4mappedprefix,12)) {
inet_ntoa_r(*(struct in_addr*)(ip+12),s);
temp=strlen(s);
return len+temp;
if (j == 12 && !memcmp(ip, V4mappedprefix, 12)) {
inet_ntoa_r(*(struct in_addr *)(ip + 12), s);
temp = strlen(s);
return len + temp;
}
#endif
temp = ((unsigned long) (unsigned char) ip[j] << 8) +
(unsigned long) (unsigned char) ip[j+1];
temp = ((unsigned long)(unsigned char)ip[j] << 8) +
(unsigned long)(unsigned char)ip[j + 1];
if (temp == 0) {
if (!compressing) {
compressing=1;
if (j==0) {
*s++=':'; ++len;
compressing = 1;
if (j == 0) {
*s++ = ':';
++len;
}
}
} else {
if (compressing) {
compressing=0;
*s++=':'; ++len;
compressing = 0;
*s++ = ':';
++len;
}
i = fmt_xlong(s,temp); len += i; s += i;
if (j<14) {
i = fmt_xlong(s, temp);
len += i;
s += i;
if (j < 14) {
*s++ = ':';
++len;
}
}
}
if (compressing) {
*s++=':'; ++len;
*s++ = ':';
++len;
}
*s=0;
*s = 0;
return len;
}
......@@ -2182,15 +2298,15 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
udph = (struct udphdr *)skb_put(skb, sizeof(struct udphdr));
memcpy(eth, pkt_dev->hh, 12);
*(u16*)&eth[12] = __constant_htons(ETH_P_IPV6);
*(u16 *) & eth[12] = __constant_htons(ETH_P_IPV6);
datalen = pkt_dev->cur_pkt_size-14-
sizeof(struct ipv6hdr)-sizeof(struct udphdr); /* Eth + IPh + UDPh */
datalen = pkt_dev->cur_pkt_size - 14 - sizeof(struct ipv6hdr) - sizeof(struct udphdr); /* Eth + IPh + UDPh */
if (datalen < sizeof(struct pktgen_hdr)) {
datalen = sizeof(struct pktgen_hdr);
if (net_ratelimit())
printk(KERN_INFO "pktgen: increased datalen to %d\n", datalen);
printk(KERN_INFO "pktgen: increased datalen to %d\n",
datalen);
}
udph->source = htons(pkt_dev->cur_udp_src);
......@@ -2198,7 +2314,7 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
udph->len = htons(datalen + sizeof(struct udphdr));
udph->check = 0; /* No checksum */
*(u32*)iph = __constant_htonl(0x60000000); /* Version + flow */
*(u32 *) iph = __constant_htonl(0x60000000); /* Version + flow */
iph->hop_limit = 32;
......@@ -2208,7 +2324,7 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
ipv6_addr_copy(&iph->daddr, &pkt_dev->cur_in6_daddr);
ipv6_addr_copy(&iph->saddr, &pkt_dev->cur_in6_saddr);
skb->mac.raw = ((u8 *)iph) - 14;
skb->mac.raw = ((u8 *) iph) - 14;
skb->protocol = __constant_htons(ETH_P_IPV6);
skb->dev = odev;
skb->pkt_type = PACKET_HOST;
......@@ -2219,13 +2335,13 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
int frags = pkt_dev->nfrags;
int i;
pgh = (struct pktgen_hdr*)(((char*)(udph)) + 8);
pgh = (struct pktgen_hdr *)(((char *)(udph)) + 8);
if (frags > MAX_SKB_FRAGS)
frags = MAX_SKB_FRAGS;
if (datalen > frags*PAGE_SIZE) {
skb_put(skb, datalen-frags*PAGE_SIZE);
datalen = frags*PAGE_SIZE;
if (datalen > frags * PAGE_SIZE) {
skb_put(skb, datalen - frags * PAGE_SIZE);
datalen = frags * PAGE_SIZE;
}
i = 0;
......@@ -2254,10 +2370,13 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
skb_shinfo(skb)->frags[i - 1].size -= rem;
skb_shinfo(skb)->frags[i] = skb_shinfo(skb)->frags[i - 1];
skb_shinfo(skb)->frags[i] =
skb_shinfo(skb)->frags[i - 1];
get_page(skb_shinfo(skb)->frags[i].page);
skb_shinfo(skb)->frags[i].page = skb_shinfo(skb)->frags[i - 1].page;
skb_shinfo(skb)->frags[i].page_offset += skb_shinfo(skb)->frags[i - 1].size;
skb_shinfo(skb)->frags[i].page =
skb_shinfo(skb)->frags[i - 1].page;
skb_shinfo(skb)->frags[i].page_offset +=
skb_shinfo(skb)->frags[i - 1].size;
skb_shinfo(skb)->frags[i].size = rem;
i++;
skb_shinfo(skb)->nr_frags = i;
......@@ -2284,7 +2403,7 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
static inline struct sk_buff *fill_packet(struct net_device *odev,
struct pktgen_dev *pkt_dev)
{
if(pkt_dev->flags & F_IPV6)
if (pkt_dev->flags & F_IPV6)
return fill_packet_ipv6(odev, pkt_dev);
else
return fill_packet_ipv4(odev, pkt_dev);
......@@ -2309,14 +2428,14 @@ static void pktgen_run(struct pktgen_thread *t)
PG_DEBUG(printk("pktgen: entering pktgen_run. %p\n", t));
if_lock(t);
for (pkt_dev = t->if_list; pkt_dev; pkt_dev = pkt_dev->next ) {
for (pkt_dev = t->if_list; pkt_dev; pkt_dev = pkt_dev->next) {
/*
* setup odev and create initial packet.
*/
pktgen_setup_inject(pkt_dev);
if(pkt_dev->odev) {
if (pkt_dev->odev) {
pktgen_clear_counters(pkt_dev);
pkt_dev->running = 1; /* Cranke yeself! */
pkt_dev->skb = NULL;
......@@ -2326,12 +2445,12 @@ static void pktgen_run(struct pktgen_thread *t)
strcpy(pkt_dev->result, "Starting");
started++;
}
else
} else
strcpy(pkt_dev->result, "Error starting");
}
if_unlock(t);
if(started) t->control &= ~(T_STOP);
if (started)
t->control &= ~(T_STOP);
}
static void pktgen_stop_all_threads_ifs(void)
......@@ -2341,20 +2460,20 @@ static void pktgen_stop_all_threads_ifs(void)
PG_DEBUG(printk("pktgen: entering pktgen_stop_all_threads_ifs.\n"));
thread_lock();
while(t) {
while (t) {
t->control |= T_STOP;
t = t->next;
}
thread_unlock();
}
static int thread_is_running(struct pktgen_thread *t )
static int thread_is_running(struct pktgen_thread *t)
{
struct pktgen_dev *next;
int res = 0;
for(next=t->if_list; next; next=next->next) {
if(next->running) {
for (next = t->if_list; next; next = next->next) {
if (next->running) {
res = 1;
break;
}
......@@ -2362,11 +2481,11 @@ static int thread_is_running(struct pktgen_thread *t )
return res;
}
static int pktgen_wait_thread_run(struct pktgen_thread *t )
static int pktgen_wait_thread_run(struct pktgen_thread *t)
{
if_lock(t);
while(thread_is_running(t)) {
while (thread_is_running(t)) {
if_unlock(t);
......@@ -2378,7 +2497,7 @@ static int pktgen_wait_thread_run(struct pktgen_thread *t )
}
if_unlock(t);
return 1;
signal:
signal:
return 0;
}
......@@ -2389,16 +2508,17 @@ static int pktgen_wait_all_threads_run(void)
while (t) {
sig = pktgen_wait_thread_run(t);
if( sig == 0 ) break;
if (sig == 0)
break;
thread_lock();
t=t->next;
t = t->next;
thread_unlock();
}
if(sig == 0) {
if (sig == 0) {
thread_lock();
while (t) {
t->control |= (T_STOP);
t=t->next;
t = t->next;
}
thread_unlock();
}
......@@ -2413,7 +2533,7 @@ static void pktgen_run_all_threads(void)
thread_lock();
while(t) {
while (t) {
t->control |= (T_RUN);
t = t->next;
}
......@@ -2424,7 +2544,6 @@ static void pktgen_run_all_threads(void)
pktgen_wait_all_threads_run();
}
static void show_results(struct pktgen_dev *pkt_dev, int nr_frags)
{
__u64 total_us, bps, mbps, pps, idle;
......@@ -2435,10 +2554,10 @@ static void show_results(struct pktgen_dev *pkt_dev, int nr_frags)
idle = pkt_dev->idle_acc;
p += sprintf(p, "OK: %llu(c%llu+d%llu) usec, %llu (%dbyte,%dfrags)\n",
(unsigned long long) total_us,
(unsigned long long)total_us,
(unsigned long long)(total_us - idle),
(unsigned long long) idle,
(unsigned long long) pkt_dev->sofar,
(unsigned long long)idle,
(unsigned long long)pkt_dev->sofar,
pkt_dev->cur_pkt_size, nr_frags);
pps = pkt_dev->sofar * USEC_PER_SEC;
......@@ -2455,22 +2574,21 @@ static void show_results(struct pktgen_dev *pkt_dev, int nr_frags)
mbps = bps;
do_div(mbps, 1000000);
p += sprintf(p, " %llupps %lluMb/sec (%llubps) errors: %llu",
(unsigned long long) pps,
(unsigned long long) mbps,
(unsigned long long) bps,
(unsigned long long) pkt_dev->errors);
(unsigned long long)pps,
(unsigned long long)mbps,
(unsigned long long)bps,
(unsigned long long)pkt_dev->errors);
}
/* Set stopped-at timer, remove from running list, do counters & statistics */
static int pktgen_stop_device(struct pktgen_dev *pkt_dev)
{
int nr_frags = pkt_dev->skb ?
skb_shinfo(pkt_dev->skb)->nr_frags: -1;
int nr_frags = pkt_dev->skb ? skb_shinfo(pkt_dev->skb)->nr_frags : -1;
if (!pkt_dev->running) {
printk("pktgen: interface: %s is already stopped\n", pkt_dev->ifname);
printk("pktgen: interface: %s is already stopped\n",
pkt_dev->ifname);
return -EINVAL;
}
......@@ -2482,30 +2600,33 @@ static int pktgen_stop_device(struct pktgen_dev *pkt_dev)
return 0;
}
static struct pktgen_dev *next_to_run(struct pktgen_thread *t )
static struct pktgen_dev *next_to_run(struct pktgen_thread *t)
{
struct pktgen_dev *next, *best = NULL;
if_lock(t);
for(next=t->if_list; next ; next=next->next) {
if(!next->running) continue;
if(best == NULL) best=next;
else if ( next->next_tx_us < best->next_tx_us)
for (next = t->if_list; next; next = next->next) {
if (!next->running)
continue;
if (best == NULL)
best = next;
else if (next->next_tx_us < best->next_tx_us)
best = next;
}
if_unlock(t);
return best;
}
static void pktgen_stop(struct pktgen_thread *t) {
static void pktgen_stop(struct pktgen_thread *t)
{
struct pktgen_dev *next = NULL;
PG_DEBUG(printk("pktgen: entering pktgen_stop\n"));
if_lock(t);
for(next=t->if_list; next; next=next->next) {
for (next = t->if_list; next; next = next->next) {
pktgen_stop_device(next);
if (next->skb)
kfree_skb(next->skb);
......@@ -2528,10 +2649,11 @@ static void pktgen_rem_one_if(struct pktgen_thread *t)
if_lock(t);
for(cur=t->if_list; cur; cur=next) {
for (cur = t->if_list; cur; cur = next) {
next = cur->next;
if (!cur->removal_mark) continue;
if (!cur->removal_mark)
continue;
if (cur->skb)
kfree_skb(cur->skb);
......@@ -2554,7 +2676,7 @@ static void pktgen_rem_all_ifs(struct pktgen_thread *t)
PG_DEBUG(printk("pktgen: entering pktgen_rem_all_ifs\n"));
if_lock(t);
for(cur=t->if_list; cur; cur=next) {
for (cur = t->if_list; cur; cur = next) {
next = cur->next;
if (cur->skb)
......@@ -2640,7 +2762,8 @@ static __inline__ void pktgen_xmit(struct pktgen_dev *pkt_dev)
}
if (pkt_dev->last_ok || !pkt_dev->skb) {
if ((++pkt_dev->clone_count >= pkt_dev->clone_skb ) || (!pkt_dev->skb)) {
if ((++pkt_dev->clone_count >= pkt_dev->clone_skb)
|| (!pkt_dev->skb)) {
/* build a new pkt */
if (pkt_dev->skb)
kfree_skb(pkt_dev->skb);
......@@ -2661,7 +2784,7 @@ static __inline__ void pktgen_xmit(struct pktgen_dev *pkt_dev)
if (!netif_queue_stopped(odev)) {
atomic_inc(&(pkt_dev->skb->users));
retry_now:
retry_now:
ret = odev->hard_start_xmit(pkt_dev->skb, odev);
if (likely(ret == NETDEV_TX_OK)) {
pkt_dev->last_ok = 1;
......@@ -2723,8 +2846,8 @@ static __inline__ void pktgen_xmit(struct pktgen_dev *pkt_dev)
kfree_skb(pkt_dev->skb);
pkt_dev->skb = NULL;
}
out:;
}
out:;
}
/*
* Main loop of the thread goes here
......@@ -2746,9 +2869,7 @@ static void pktgen_thread_worker(struct pktgen_thread *t)
spin_lock_irq(&current->sighand->siglock);
tmpsig = current->blocked;
siginitsetinv(&current->blocked,
sigmask(SIGKILL) |
sigmask(SIGSTOP)|
sigmask(SIGTERM));
sigmask(SIGKILL) | sigmask(SIGSTOP) | sigmask(SIGTERM));
recalc_sigpending();
spin_unlock_irq(&current->sighand->siglock);
......@@ -2803,7 +2924,7 @@ static void pktgen_thread_worker(struct pktgen_thread *t)
}
} else {
prepare_to_wait(&(t->queue), &wait, TASK_INTERRUPTIBLE);
schedule_timeout(HZ/10);
schedule_timeout(HZ / 10);
finish_wait(&(t->queue), &wait);
}
......@@ -2816,23 +2937,22 @@ static void pktgen_thread_worker(struct pktgen_thread *t)
/* we received a request to terminate ourself */
break;
if(t->control & T_STOP) {
if (t->control & T_STOP) {
pktgen_stop(t);
t->control &= ~(T_STOP);
}
if(t->control & T_RUN) {
if (t->control & T_RUN) {
pktgen_run(t);
t->control &= ~(T_RUN);
}
if(t->control & T_REMDEVALL) {
if (t->control & T_REMDEVALL) {
pktgen_rem_all_ifs(t);
t->control &= ~(T_REMDEVALL);
}
if(t->control & T_REMDEV) {
if (t->control & T_REMDEV) {
pktgen_rem_one_if(t);
t->control &= ~(T_REMDEV);
}
......@@ -2851,19 +2971,20 @@ static void pktgen_thread_worker(struct pktgen_thread *t)
pktgen_rem_thread(t);
}
static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t, const char* ifname)
static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t,
const char *ifname)
{
struct pktgen_dev *pkt_dev = NULL;
if_lock(t);
for(pkt_dev=t->if_list; pkt_dev; pkt_dev = pkt_dev->next ) {
for (pkt_dev = t->if_list; pkt_dev; pkt_dev = pkt_dev->next) {
if (strncmp(pkt_dev->ifname, ifname, IFNAMSIZ) == 0) {
break;
}
}
if_unlock(t);
PG_DEBUG(printk("pktgen: find_dev(%s) returning %p\n", ifname,pkt_dev));
PG_DEBUG(printk("pktgen: find_dev(%s) returning %p\n", ifname, pkt_dev));
return pkt_dev;
}
......@@ -2871,7 +2992,8 @@ static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t, const char* i
* Adds a dev at front of if_list.
*/
static int add_dev_to_thread(struct pktgen_thread *t, struct pktgen_dev *pkt_dev)
static int add_dev_to_thread(struct pktgen_thread *t,
struct pktgen_dev *pkt_dev)
{
int rv = 0;
......@@ -2882,18 +3004,19 @@ static int add_dev_to_thread(struct pktgen_thread *t, struct pktgen_dev *pkt_dev
rv = -EBUSY;
goto out;
}
pkt_dev->next =t->if_list; t->if_list=pkt_dev;
pkt_dev->next = t->if_list;
t->if_list = pkt_dev;
pkt_dev->pg_thread = t;
pkt_dev->running = 0;
out:
out:
if_unlock(t);
return rv;
}
/* Called under thread lock */
static int pktgen_add_device(struct pktgen_thread *t, const char* ifname)
static int pktgen_add_device(struct pktgen_thread *t, const char *ifname)
{
struct pktgen_dev *pkt_dev;
struct proc_dir_entry *pe;
......@@ -2910,12 +3033,12 @@ static int pktgen_add_device(struct pktgen_thread *t, const char* ifname)
if (!pkt_dev)
return -ENOMEM;
pkt_dev->flows = vmalloc(MAX_CFLOWS*sizeof(struct flow_state));
pkt_dev->flows = vmalloc(MAX_CFLOWS * sizeof(struct flow_state));
if (pkt_dev->flows == NULL) {
kfree(pkt_dev);
return -ENOMEM;
}
memset(pkt_dev->flows, 0, MAX_CFLOWS*sizeof(struct flow_state));
memset(pkt_dev->flows, 0, MAX_CFLOWS * sizeof(struct flow_state));
pkt_dev->removal_mark = 0;
pkt_dev->min_pkt_size = ETH_ZLEN;
......@@ -2933,7 +3056,7 @@ static int pktgen_add_device(struct pktgen_thread *t, const char* ifname)
strncpy(pkt_dev->ifname, ifname, IFNAMSIZ);
if (! pktgen_setup_dev(pkt_dev)) {
if (!pktgen_setup_dev(pkt_dev)) {
printk("pktgen: ERROR: pktgen_setup_dev failed.\n");
if (pkt_dev->flows)
vfree(pkt_dev->flows);
......@@ -2956,7 +3079,7 @@ static int pktgen_add_device(struct pktgen_thread *t, const char* ifname)
return add_dev_to_thread(t, pkt_dev);
}
static struct pktgen_thread * __init pktgen_find_thread(const char* name)
static struct pktgen_thread *__init pktgen_find_thread(const char *name)
{
struct pktgen_thread *t = NULL;
......@@ -2973,7 +3096,7 @@ static struct pktgen_thread * __init pktgen_find_thread(const char* name)
return t;
}
static int __init pktgen_create_thread(const char* name, int cpu)
static int __init pktgen_create_thread(const char *name, int cpu)
{
struct pktgen_thread *t = NULL;
struct proc_dir_entry *pe;
......@@ -3012,7 +3135,7 @@ static int __init pktgen_create_thread(const char* name, int cpu)
t->next = pktgen_threads;
pktgen_threads = t;
if (kernel_thread((void *) pktgen_thread_worker, (void *) t,
if (kernel_thread((void *)pktgen_thread_worker, (void *)t,
CLONE_FS | CLONE_FILES | CLONE_SIGHAND) < 0)
printk("pktgen: kernel_thread() failed for cpu %d\n", t->cpu);
......@@ -3022,24 +3145,28 @@ static int __init pktgen_create_thread(const char* name, int cpu)
/*
* Removes a device from the thread if_list.
*/
static void _rem_dev_from_if_list(struct pktgen_thread *t, struct pktgen_dev *pkt_dev)
static void _rem_dev_from_if_list(struct pktgen_thread *t,
struct pktgen_dev *pkt_dev)
{
struct pktgen_dev *i, *prev = NULL;
i = t->if_list;
while(i) {
if(i == pkt_dev) {
if(prev) prev->next = i->next;
else t->if_list = NULL;
while (i) {
if (i == pkt_dev) {
if (prev)
prev->next = i->next;
else
t->if_list = NULL;
break;
}
prev = i;
i=i->next;
i = i->next;
}
}
static int pktgen_remove_device(struct pktgen_thread *t, struct pktgen_dev *pkt_dev)
static int pktgen_remove_device(struct pktgen_thread *t,
struct pktgen_dev *pkt_dev)
{
PG_DEBUG(printk("pktgen: remove_device pkt_dev=%p\n", pkt_dev));
......@@ -3084,7 +3211,8 @@ static int __init pg_init(void)
pe = create_proc_entry(PGCTRL, 0600, pg_proc_dir);
if (pe == NULL) {
printk("pktgen: ERROR: cannot create %s procfs entry.\n", PGCTRL);
printk("pktgen: ERROR: cannot create %s procfs entry.\n",
PGCTRL);
proc_net_remove(PG_PROC_DIR);
return -EINVAL;
}
......@@ -3115,7 +3243,8 @@ static void __exit pg_cleanup(void)
struct pktgen_thread *t = pktgen_threads;
pktgen_threads->control |= (T_TERMINATE);
wait_event_interruptible_timeout(queue, (t != pktgen_threads), HZ);
wait_event_interruptible_timeout(queue, (t != pktgen_threads),
HZ);
}
/* Un-register us from receiving netdevice events */
......@@ -3126,7 +3255,6 @@ static void __exit pg_cleanup(void)
proc_net_remove(PG_PROC_DIR);
}
module_init(pg_init);
module_exit(pg_cleanup);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment