pktgen.c (5501972e0b5857bc8354770d900ceb9b40c7f6b7) pktgen.c (ca6549af77f0f28ac5d23b662fb8f72713eb16d3)
1/*
2 * Authors:
3 * Copyright 2001, 2002 by Robert Olsson <robert.olsson@its.uu.se>
4 * Uppsala University and
5 * Swedish University of Agricultural Sciences
6 *
7 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
8 * Ben Greear <greearb@candelatech.com>

--- 92 unchanged lines hidden (view full) ---

101 * Remove FCS from BW calculation. Lennert Buytenhek <buytenh@wantstofly.org>
102 * New time handling. Lennert Buytenhek <buytenh@wantstofly.org> 041213
103 *
104 * Corrections from Nikolai Malykh (nmalykh@bilim.com)
105 * Removed unused flags F_SET_SRCMAC & F_SET_SRCIP 041230
106 *
107 * interruptible_sleep_on_timeout() replaced Nishanth Aravamudan <nacc@us.ibm.com>
108 * 050103
1/*
2 * Authors:
3 * Copyright 2001, 2002 by Robert Olsson <robert.olsson@its.uu.se>
4 * Uppsala University and
5 * Swedish University of Agricultural Sciences
6 *
7 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
8 * Ben Greear <greearb@candelatech.com>

--- 92 unchanged lines hidden (view full) ---

101 * Remove FCS from BW calculation. Lennert Buytenhek <buytenh@wantstofly.org>
102 * New time handling. Lennert Buytenhek <buytenh@wantstofly.org> 041213
103 *
104 * Corrections from Nikolai Malykh (nmalykh@bilim.com)
105 * Removed unused flags F_SET_SRCMAC & F_SET_SRCIP 041230
106 *
107 * interruptible_sleep_on_timeout() replaced Nishanth Aravamudan <nacc@us.ibm.com>
108 * 050103
109 *
110 * MPLS support by Steven Whitehouse <steve@chygwyn.com>
111 *
109 */
110#include <linux/sys.h>
111#include <linux/types.h>
112#include <linux/module.h>
113#include <linux/moduleparam.h>
114#include <linux/kernel.h>
115#include <linux/smp_lock.h>
116#include <linux/mutex.h>

--- 32 unchanged lines hidden (view full) ---

149#include <linux/rcupdate.h>
150#include <asm/bitops.h>
151#include <asm/io.h>
152#include <asm/dma.h>
153#include <asm/uaccess.h>
154#include <asm/div64.h> /* do_div */
155#include <asm/timex.h>
156
112 */
113#include <linux/sys.h>
114#include <linux/types.h>
115#include <linux/module.h>
116#include <linux/moduleparam.h>
117#include <linux/kernel.h>
118#include <linux/smp_lock.h>
119#include <linux/mutex.h>

--- 32 unchanged lines hidden (view full) ---

152#include <linux/rcupdate.h>
153#include <asm/bitops.h>
154#include <asm/io.h>
155#include <asm/dma.h>
156#include <asm/uaccess.h>
157#include <asm/div64.h> /* do_div */
158#include <asm/timex.h>
159
157#define VERSION "pktgen v2.66: Packet Generator for packet performance testing.\n"
160#define VERSION "pktgen v2.67: Packet Generator for packet performance testing.\n"
158
159/* #define PG_DEBUG(a) a */
160#define PG_DEBUG(a)
161
162/* The buckets are exponential in 'width' */
163#define LAT_BUCKETS_MAX 32
164#define IP_NAME_SZ 32
161
162/* #define PG_DEBUG(a) a */
163#define PG_DEBUG(a)
164
165/* The buckets are exponential in 'width' */
166#define LAT_BUCKETS_MAX 32
167#define IP_NAME_SZ 32
168#define MAX_MPLS_LABELS 16 /* This is the max label stack depth */
169#define MPLS_STACK_BOTTOM __constant_htonl(0x00000100)
165
166/* Device flag bits */
167#define F_IPSRC_RND (1<<0) /* IP-Src Random */
168#define F_IPDST_RND (1<<1) /* IP-Dst Random */
169#define F_UDPSRC_RND (1<<2) /* UDP-Src Random */
170#define F_UDPDST_RND (1<<3) /* UDP-Dst Random */
171#define F_MACSRC_RND (1<<4) /* MAC-Src Random */
172#define F_MACDST_RND (1<<5) /* MAC-Dst Random */
173#define F_TXSIZE_RND (1<<6) /* Transmit size is random */
174#define F_IPV6 (1<<7) /* Interface in IPV6 Mode */
170
171/* Device flag bits */
172#define F_IPSRC_RND (1<<0) /* IP-Src Random */
173#define F_IPDST_RND (1<<1) /* IP-Dst Random */
174#define F_UDPSRC_RND (1<<2) /* UDP-Src Random */
175#define F_UDPDST_RND (1<<3) /* UDP-Dst Random */
176#define F_MACSRC_RND (1<<4) /* MAC-Src Random */
177#define F_MACDST_RND (1<<5) /* MAC-Dst Random */
178#define F_TXSIZE_RND (1<<6) /* Transmit size is random */
179#define F_IPV6 (1<<7) /* Interface in IPV6 Mode */
180#define F_MPLS_RND (1<<8) /* Random MPLS labels */
175
176/* Thread control flag bits */
177#define T_TERMINATE (1<<0)
178#define T_STOP (1<<1) /* Stop run */
179#define T_RUN (1<<2) /* Start run */
180#define T_REMDEVALL (1<<3) /* Remove all devs */
181#define T_REMDEV (1<<4) /* Remove one dev */
182

--- 90 unchanged lines hidden (view full) ---

273 __u32 daddr_min; /* inclusive, dest IP address */
274 __u32 daddr_max; /* exclusive, dest IP address */
275
276 __u16 udp_src_min; /* inclusive, source UDP port */
277 __u16 udp_src_max; /* exclusive, source UDP port */
278 __u16 udp_dst_min; /* inclusive, dest UDP port */
279 __u16 udp_dst_max; /* exclusive, dest UDP port */
280
181
182/* Thread control flag bits */
183#define T_TERMINATE (1<<0)
184#define T_STOP (1<<1) /* Stop run */
185#define T_RUN (1<<2) /* Start run */
186#define T_REMDEVALL (1<<3) /* Remove all devs */
187#define T_REMDEV (1<<4) /* Remove one dev */
188

--- 90 unchanged lines hidden (view full) ---

279 __u32 daddr_min; /* inclusive, dest IP address */
280 __u32 daddr_max; /* exclusive, dest IP address */
281
282 __u16 udp_src_min; /* inclusive, source UDP port */
283 __u16 udp_src_max; /* exclusive, source UDP port */
284 __u16 udp_dst_min; /* inclusive, dest UDP port */
285 __u16 udp_dst_max; /* exclusive, dest UDP port */
286
287 /* MPLS */
288 unsigned nr_labels; /* Depth of stack, 0 = no MPLS */
289 __be32 labels[MAX_MPLS_LABELS];
290
281 __u32 src_mac_count; /* How many MACs to iterate through */
282 __u32 dst_mac_count; /* How many MACs to iterate through */
283
284 unsigned char dst_mac[ETH_ALEN];
285 unsigned char src_mac[ETH_ALEN];
286
287 __u32 cur_dst_mac_offset;
288 __u32 cur_src_mac_offset;

--- 329 unchanged lines hidden (view full) ---

618 i == 5 ? "\n" : ":");
619
620 seq_printf(seq,
621 " udp_src_min: %d udp_src_max: %d udp_dst_min: %d udp_dst_max: %d\n",
622 pkt_dev->udp_src_min, pkt_dev->udp_src_max,
623 pkt_dev->udp_dst_min, pkt_dev->udp_dst_max);
624
625 seq_printf(seq,
291 __u32 src_mac_count; /* How many MACs to iterate through */
292 __u32 dst_mac_count; /* How many MACs to iterate through */
293
294 unsigned char dst_mac[ETH_ALEN];
295 unsigned char src_mac[ETH_ALEN];
296
297 __u32 cur_dst_mac_offset;
298 __u32 cur_src_mac_offset;

--- 329 unchanged lines hidden (view full) ---

628 i == 5 ? "\n" : ":");
629
630 seq_printf(seq,
631 " udp_src_min: %d udp_src_max: %d udp_dst_min: %d udp_dst_max: %d\n",
632 pkt_dev->udp_src_min, pkt_dev->udp_src_max,
633 pkt_dev->udp_dst_min, pkt_dev->udp_dst_max);
634
635 seq_printf(seq,
626 " src_mac_count: %d dst_mac_count: %d \n Flags: ",
636 " src_mac_count: %d dst_mac_count: %d\n",
627 pkt_dev->src_mac_count, pkt_dev->dst_mac_count);
628
637 pkt_dev->src_mac_count, pkt_dev->dst_mac_count);
638
639 if (pkt_dev->nr_labels) {
640 unsigned i;
641 seq_printf(seq, " mpls: ");
642 for(i = 0; i < pkt_dev->nr_labels; i++)
643 seq_printf(seq, "%08x%s", ntohl(pkt_dev->labels[i]),
644 i == pkt_dev->nr_labels-1 ? "\n" : ", ");
645 }
646
647 seq_printf(seq, " Flags: ");
648
629 if (pkt_dev->flags & F_IPV6)
630 seq_printf(seq, "IPV6 ");
631
632 if (pkt_dev->flags & F_IPSRC_RND)
633 seq_printf(seq, "IPSRC_RND ");
634
635 if (pkt_dev->flags & F_IPDST_RND)
636 seq_printf(seq, "IPDST_RND ");
637
638 if (pkt_dev->flags & F_TXSIZE_RND)
639 seq_printf(seq, "TXSIZE_RND ");
640
641 if (pkt_dev->flags & F_UDPSRC_RND)
642 seq_printf(seq, "UDPSRC_RND ");
643
644 if (pkt_dev->flags & F_UDPDST_RND)
645 seq_printf(seq, "UDPDST_RND ");
646
649 if (pkt_dev->flags & F_IPV6)
650 seq_printf(seq, "IPV6 ");
651
652 if (pkt_dev->flags & F_IPSRC_RND)
653 seq_printf(seq, "IPSRC_RND ");
654
655 if (pkt_dev->flags & F_IPDST_RND)
656 seq_printf(seq, "IPDST_RND ");
657
658 if (pkt_dev->flags & F_TXSIZE_RND)
659 seq_printf(seq, "TXSIZE_RND ");
660
661 if (pkt_dev->flags & F_UDPSRC_RND)
662 seq_printf(seq, "UDPSRC_RND ");
663
664 if (pkt_dev->flags & F_UDPDST_RND)
665 seq_printf(seq, "UDPDST_RND ");
666
667 if (pkt_dev->flags & F_MPLS_RND)
668 seq_printf(seq, "MPLS_RND ");
669
647 if (pkt_dev->flags & F_MACSRC_RND)
648 seq_printf(seq, "MACSRC_RND ");
649
650 if (pkt_dev->flags & F_MACDST_RND)
651 seq_printf(seq, "MACDST_RND ");
652
653 seq_puts(seq, "\n");
654

--- 31 unchanged lines hidden (view full) ---

686 if (pkt_dev->result[0])
687 seq_printf(seq, "Result: %s\n", pkt_dev->result);
688 else
689 seq_printf(seq, "Result: Idle\n");
690
691 return 0;
692}
693
670 if (pkt_dev->flags & F_MACSRC_RND)
671 seq_printf(seq, "MACSRC_RND ");
672
673 if (pkt_dev->flags & F_MACDST_RND)
674 seq_printf(seq, "MACDST_RND ");
675
676 seq_puts(seq, "\n");
677

--- 31 unchanged lines hidden (view full) ---

709 if (pkt_dev->result[0])
710 seq_printf(seq, "Result: %s\n", pkt_dev->result);
711 else
712 seq_printf(seq, "Result: Idle\n");
713
714 return 0;
715}
716
717
718static int hex32_arg(const char __user *user_buffer, __u32 *num)
719{
720 int i = 0;
721 *num = 0;
722
723 for(; i < 8; i++) {
724 char c;
725 *num <<= 4;
726 if (get_user(c, &user_buffer[i]))
727 return -EFAULT;
728 if ((c >= '0') && (c <= '9'))
729 *num |= c - '0';
730 else if ((c >= 'a') && (c <= 'f'))
731 *num |= c - 'a' + 10;
732 else if ((c >= 'A') && (c <= 'F'))
733 *num |= c - 'A' + 10;
734 else
735 break;
736 }
737 return i;
738}
739
694static int count_trail_chars(const char __user * user_buffer,
695 unsigned int maxlen)
696{
697 int i;
698
699 for (i = 0; i < maxlen; i++) {
700 char c;
701 if (get_user(c, &user_buffer[i]))

--- 52 unchanged lines hidden (view full) ---

754 default:
755 break;
756 };
757 }
758done_str:
759 return i;
760}
761
740static int count_trail_chars(const char __user * user_buffer,
741 unsigned int maxlen)
742{
743 int i;
744
745 for (i = 0; i < maxlen; i++) {
746 char c;
747 if (get_user(c, &user_buffer[i]))

--- 52 unchanged lines hidden (view full) ---

800 default:
801 break;
802 };
803 }
804done_str:
805 return i;
806}
807
808static ssize_t get_labels(const char __user *buffer, struct pktgen_dev *pkt_dev)
809{
810 unsigned n = 0;
811 char c;
812 ssize_t i = 0;
813 int len;
814
815 pkt_dev->nr_labels = 0;
816 do {
817 __u32 tmp;
818 len = hex32_arg(&buffer[i], &tmp);
819 if (len <= 0)
820 return len;
821 pkt_dev->labels[n] = htonl(tmp);
822 if (pkt_dev->labels[n] & MPLS_STACK_BOTTOM)
823 pkt_dev->flags |= F_MPLS_RND;
824 i += len;
825 if (get_user(c, &buffer[i]))
826 return -EFAULT;
827 i++;
828 n++;
829 if (n >= MAX_MPLS_LABELS)
830 return -E2BIG;
831 } while(c == ',');
832
833 pkt_dev->nr_labels = n;
834 return i;
835}
836
762static ssize_t pktgen_if_write(struct file *file,
763 const char __user * user_buffer, size_t count,
764 loff_t * offset)
765{
766 struct seq_file *seq = (struct seq_file *)file->private_data;
767 struct pktgen_dev *pkt_dev = seq->private;
768 int i = 0, max, len;
769 char name[16], valstr[32];

--- 284 unchanged lines hidden (view full) ---

1054 pkt_dev->flags &= ~F_MACSRC_RND;
1055
1056 else if (strcmp(f, "MACDST_RND") == 0)
1057 pkt_dev->flags |= F_MACDST_RND;
1058
1059 else if (strcmp(f, "!MACDST_RND") == 0)
1060 pkt_dev->flags &= ~F_MACDST_RND;
1061
837static ssize_t pktgen_if_write(struct file *file,
838 const char __user * user_buffer, size_t count,
839 loff_t * offset)
840{
841 struct seq_file *seq = (struct seq_file *)file->private_data;
842 struct pktgen_dev *pkt_dev = seq->private;
843 int i = 0, max, len;
844 char name[16], valstr[32];

--- 284 unchanged lines hidden (view full) ---

1129 pkt_dev->flags &= ~F_MACSRC_RND;
1130
1131 else if (strcmp(f, "MACDST_RND") == 0)
1132 pkt_dev->flags |= F_MACDST_RND;
1133
1134 else if (strcmp(f, "!MACDST_RND") == 0)
1135 pkt_dev->flags &= ~F_MACDST_RND;
1136
1137 else if (strcmp(f, "MPLS_RND") == 0)
1138 pkt_dev->flags |= F_MPLS_RND;
1139
1140 else if (strcmp(f, "!MPLS_RND") == 0)
1141 pkt_dev->flags &= ~F_MPLS_RND;
1142
1062 else {
1063 sprintf(pg_result,
1064 "Flag -:%s:- unknown\nAvailable flags, (prepend ! to un-set flag):\n%s",
1065 f,
1066 "IPSRC_RND, IPDST_RND, TXSIZE_RND, UDPSRC_RND, UDPDST_RND, MACSRC_RND, MACDST_RND\n");
1067 return count;
1068 }
1069 sprintf(pg_result, "OK: flags=0x%x", pkt_dev->flags);

--- 279 unchanged lines hidden (view full) ---

1349 return len;
1350 }
1351 i += len;
1352 pkt_dev->lflow = value;
1353 sprintf(pg_result, "OK: flowlen=%u", pkt_dev->lflow);
1354 return count;
1355 }
1356
1143 else {
1144 sprintf(pg_result,
1145 "Flag -:%s:- unknown\nAvailable flags, (prepend ! to un-set flag):\n%s",
1146 f,
1147 "IPSRC_RND, IPDST_RND, TXSIZE_RND, UDPSRC_RND, UDPDST_RND, MACSRC_RND, MACDST_RND\n");
1148 return count;
1149 }
1150 sprintf(pg_result, "OK: flags=0x%x", pkt_dev->flags);

--- 279 unchanged lines hidden (view full) ---

1430 return len;
1431 }
1432 i += len;
1433 pkt_dev->lflow = value;
1434 sprintf(pg_result, "OK: flowlen=%u", pkt_dev->lflow);
1435 return count;
1436 }
1437
1438 if (!strcmp(name, "mpls")) {
1439 unsigned n, offset;
1440 len = get_labels(&user_buffer[i], pkt_dev);
1441 if (len < 0) { return len; }
1442 i += len;
1443 offset = sprintf(pg_result, "OK: mpls=");
1444 for(n = 0; n < pkt_dev->nr_labels; n++)
1445 offset += sprintf(pg_result + offset,
1446 "%08x%s", ntohl(pkt_dev->labels[n]),
1447 n == pkt_dev->nr_labels-1 ? "" : ",");
1448 return count;
1449 }
1450
1357 sprintf(pkt_dev->result, "No such parameter \"%s\"", name);
1358 return -EINVAL;
1359}
1360
1361static int pktgen_if_open(struct inode *inode, struct file *file)
1362{
1363 return single_open(file, pktgen_if_show, PDE(inode)->data);
1364}

--- 476 unchanged lines hidden (view full) ---

1841 tmp = (pkt_dev->dst_mac[3] + ((mc >> 16) & 0xFF) + (tmp >> 8));
1842 pkt_dev->hh[3] = tmp;
1843 tmp = (pkt_dev->dst_mac[2] + ((mc >> 24) & 0xFF) + (tmp >> 8));
1844 pkt_dev->hh[2] = tmp;
1845 tmp = (pkt_dev->dst_mac[1] + (tmp >> 8));
1846 pkt_dev->hh[1] = tmp;
1847 }
1848
1451 sprintf(pkt_dev->result, "No such parameter \"%s\"", name);
1452 return -EINVAL;
1453}
1454
1455static int pktgen_if_open(struct inode *inode, struct file *file)
1456{
1457 return single_open(file, pktgen_if_show, PDE(inode)->data);
1458}

--- 476 unchanged lines hidden (view full) ---

1935 tmp = (pkt_dev->dst_mac[3] + ((mc >> 16) & 0xFF) + (tmp >> 8));
1936 pkt_dev->hh[3] = tmp;
1937 tmp = (pkt_dev->dst_mac[2] + ((mc >> 24) & 0xFF) + (tmp >> 8));
1938 pkt_dev->hh[2] = tmp;
1939 tmp = (pkt_dev->dst_mac[1] + (tmp >> 8));
1940 pkt_dev->hh[1] = tmp;
1941 }
1942
1943 if (pkt_dev->flags & F_MPLS_RND) {
1944 unsigned i;
1945 for(i = 0; i < pkt_dev->nr_labels; i++)
1946 if (pkt_dev->labels[i] & MPLS_STACK_BOTTOM)
1947 pkt_dev->labels[i] = MPLS_STACK_BOTTOM |
1948 (pktgen_random() &
1949 htonl(0x000fffff));
1950 }
1951
1849 if (pkt_dev->udp_src_min < pkt_dev->udp_src_max) {
1850 if (pkt_dev->flags & F_UDPSRC_RND)
1851 pkt_dev->cur_udp_src =
1852 ((pktgen_random() %
1853 (pkt_dev->udp_src_max - pkt_dev->udp_src_min)) +
1854 pkt_dev->udp_src_min);
1855
1856 else {

--- 106 unchanged lines hidden (view full) ---

1963 t = pkt_dev->min_pkt_size;
1964 }
1965 pkt_dev->cur_pkt_size = t;
1966 }
1967
1968 pkt_dev->flows[flow].count++;
1969}
1970
1952 if (pkt_dev->udp_src_min < pkt_dev->udp_src_max) {
1953 if (pkt_dev->flags & F_UDPSRC_RND)
1954 pkt_dev->cur_udp_src =
1955 ((pktgen_random() %
1956 (pkt_dev->udp_src_max - pkt_dev->udp_src_min)) +
1957 pkt_dev->udp_src_min);
1958
1959 else {

--- 106 unchanged lines hidden (view full) ---

2066 t = pkt_dev->min_pkt_size;
2067 }
2068 pkt_dev->cur_pkt_size = t;
2069 }
2070
2071 pkt_dev->flows[flow].count++;
2072}
2073
2074static void mpls_push(__be32 *mpls, struct pktgen_dev *pkt_dev)
2075{
2076 unsigned i;
2077 for(i = 0; i < pkt_dev->nr_labels; i++) {
2078 *mpls++ = pkt_dev->labels[i] & ~MPLS_STACK_BOTTOM;
2079 }
2080 mpls--;
2081 *mpls |= MPLS_STACK_BOTTOM;
2082}
2083
1971static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
1972 struct pktgen_dev *pkt_dev)
1973{
1974 struct sk_buff *skb = NULL;
1975 __u8 *eth;
1976 struct udphdr *udph;
1977 int datalen, iplen;
1978 struct iphdr *iph;
1979 struct pktgen_hdr *pgh = NULL;
2084static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
2085 struct pktgen_dev *pkt_dev)
2086{
2087 struct sk_buff *skb = NULL;
2088 __u8 *eth;
2089 struct udphdr *udph;
2090 int datalen, iplen;
2091 struct iphdr *iph;
2092 struct pktgen_hdr *pgh = NULL;
2093 __be16 protocol = __constant_htons(ETH_P_IP);
2094 __be32 *mpls;
1980
2095
2096 if (pkt_dev->nr_labels)
2097 protocol = __constant_htons(ETH_P_MPLS_UC);
2098
1981 /* Update any of the values, used when we're incrementing various
1982 * fields.
1983 */
1984 mod_cur_headers(pkt_dev);
1985
1986 datalen = (odev->hard_header_len + 16) & ~0xf;
2099 /* Update any of the values, used when we're incrementing various
2100 * fields.
2101 */
2102 mod_cur_headers(pkt_dev);
2103
2104 datalen = (odev->hard_header_len + 16) & ~0xf;
1987 skb = alloc_skb(pkt_dev->cur_pkt_size + 64 + datalen, GFP_ATOMIC);
2105 skb = alloc_skb(pkt_dev->cur_pkt_size + 64 + datalen +
2106 pkt_dev->nr_labels*sizeof(u32), GFP_ATOMIC);
1988 if (!skb) {
1989 sprintf(pkt_dev->result, "No memory");
1990 return NULL;
1991 }
1992
1993 skb_reserve(skb, datalen);
1994
1995 /* Reserve for ethernet and IP header */
1996 eth = (__u8 *) skb_push(skb, 14);
2107 if (!skb) {
2108 sprintf(pkt_dev->result, "No memory");
2109 return NULL;
2110 }
2111
2112 skb_reserve(skb, datalen);
2113
2114 /* Reserve for ethernet and IP header */
2115 eth = (__u8 *) skb_push(skb, 14);
2116 mpls = (__be32 *)skb_put(skb, pkt_dev->nr_labels*sizeof(__u32));
2117 if (pkt_dev->nr_labels)
2118 mpls_push(mpls, pkt_dev);
1997 iph = (struct iphdr *)skb_put(skb, sizeof(struct iphdr));
1998 udph = (struct udphdr *)skb_put(skb, sizeof(struct udphdr));
1999
2000 memcpy(eth, pkt_dev->hh, 12);
2119 iph = (struct iphdr *)skb_put(skb, sizeof(struct iphdr));
2120 udph = (struct udphdr *)skb_put(skb, sizeof(struct udphdr));
2121
2122 memcpy(eth, pkt_dev->hh, 12);
2001 *(u16 *) & eth[12] = __constant_htons(ETH_P_IP);
2123 *(u16 *) & eth[12] = protocol;
2002
2124
2003 datalen = pkt_dev->cur_pkt_size - 14 - 20 - 8; /* Eth + IPh + UDPh */
2125 /* Eth + IPh + UDPh + mpls */
2126 datalen = pkt_dev->cur_pkt_size - 14 - 20 - 8 -
2127 pkt_dev->nr_labels*sizeof(u32);
2004 if (datalen < sizeof(struct pktgen_hdr))
2005 datalen = sizeof(struct pktgen_hdr);
2006
2007 udph->source = htons(pkt_dev->cur_udp_src);
2008 udph->dest = htons(pkt_dev->cur_udp_dst);
2009 udph->len = htons(datalen + 8); /* DATA + udphdr */
2010 udph->check = 0; /* No checksum */
2011

--- 4 unchanged lines hidden (view full) ---

2016 iph->protocol = IPPROTO_UDP; /* UDP */
2017 iph->saddr = pkt_dev->cur_saddr;
2018 iph->daddr = pkt_dev->cur_daddr;
2019 iph->frag_off = 0;
2020 iplen = 20 + 8 + datalen;
2021 iph->tot_len = htons(iplen);
2022 iph->check = 0;
2023 iph->check = ip_fast_csum((void *)iph, iph->ihl);
2128 if (datalen < sizeof(struct pktgen_hdr))
2129 datalen = sizeof(struct pktgen_hdr);
2130
2131 udph->source = htons(pkt_dev->cur_udp_src);
2132 udph->dest = htons(pkt_dev->cur_udp_dst);
2133 udph->len = htons(datalen + 8); /* DATA + udphdr */
2134 udph->check = 0; /* No checksum */
2135

--- 4 unchanged lines hidden (view full) ---

2140 iph->protocol = IPPROTO_UDP; /* UDP */
2141 iph->saddr = pkt_dev->cur_saddr;
2142 iph->daddr = pkt_dev->cur_daddr;
2143 iph->frag_off = 0;
2144 iplen = 20 + 8 + datalen;
2145 iph->tot_len = htons(iplen);
2146 iph->check = 0;
2147 iph->check = ip_fast_csum((void *)iph, iph->ihl);
2024 skb->protocol = __constant_htons(ETH_P_IP);
2025 skb->mac.raw = ((u8 *) iph) - 14;
2148 skb->protocol = protocol;
2149 skb->mac.raw = ((u8 *) iph) - 14 - pkt_dev->nr_labels*sizeof(u32);
2026 skb->dev = odev;
2027 skb->pkt_type = PACKET_HOST;
2028
2029 if (pkt_dev->nfrags <= 0)
2030 pgh = (struct pktgen_hdr *)skb_put(skb, datalen);
2031 else {
2032 int frags = pkt_dev->nfrags;
2033 int i;

--- 235 unchanged lines hidden (view full) ---

2269 struct pktgen_dev *pkt_dev)
2270{
2271 struct sk_buff *skb = NULL;
2272 __u8 *eth;
2273 struct udphdr *udph;
2274 int datalen;
2275 struct ipv6hdr *iph;
2276 struct pktgen_hdr *pgh = NULL;
2150 skb->dev = odev;
2151 skb->pkt_type = PACKET_HOST;
2152
2153 if (pkt_dev->nfrags <= 0)
2154 pgh = (struct pktgen_hdr *)skb_put(skb, datalen);
2155 else {
2156 int frags = pkt_dev->nfrags;
2157 int i;

--- 235 unchanged lines hidden (view full) ---

2393 struct pktgen_dev *pkt_dev)
2394{
2395 struct sk_buff *skb = NULL;
2396 __u8 *eth;
2397 struct udphdr *udph;
2398 int datalen;
2399 struct ipv6hdr *iph;
2400 struct pktgen_hdr *pgh = NULL;
2401 __be16 protocol = __constant_htons(ETH_P_IPV6);
2402 __be32 *mpls;
2277
2403
2404 if (pkt_dev->nr_labels)
2405 protocol = __constant_htons(ETH_P_MPLS_UC);
2406
2278 /* Update any of the values, used when we're incrementing various
2279 * fields.
2280 */
2281 mod_cur_headers(pkt_dev);
2282
2407 /* Update any of the values, used when we're incrementing various
2408 * fields.
2409 */
2410 mod_cur_headers(pkt_dev);
2411
2283 skb = alloc_skb(pkt_dev->cur_pkt_size + 64 + 16, GFP_ATOMIC);
2412 skb = alloc_skb(pkt_dev->cur_pkt_size + 64 + 16 +
2413 pkt_dev->nr_labels*sizeof(u32), GFP_ATOMIC);
2284 if (!skb) {
2285 sprintf(pkt_dev->result, "No memory");
2286 return NULL;
2287 }
2288
2289 skb_reserve(skb, 16);
2290
2291 /* Reserve for ethernet and IP header */
2292 eth = (__u8 *) skb_push(skb, 14);
2414 if (!skb) {
2415 sprintf(pkt_dev->result, "No memory");
2416 return NULL;
2417 }
2418
2419 skb_reserve(skb, 16);
2420
2421 /* Reserve for ethernet and IP header */
2422 eth = (__u8 *) skb_push(skb, 14);
2423 mpls = (__be32 *)skb_put(skb, pkt_dev->nr_labels*sizeof(__u32));
2424 if (pkt_dev->nr_labels)
2425 mpls_push(mpls, pkt_dev);
2293 iph = (struct ipv6hdr *)skb_put(skb, sizeof(struct ipv6hdr));
2294 udph = (struct udphdr *)skb_put(skb, sizeof(struct udphdr));
2295
2296 memcpy(eth, pkt_dev->hh, 12);
2297 *(u16 *) & eth[12] = __constant_htons(ETH_P_IPV6);
2298
2426 iph = (struct ipv6hdr *)skb_put(skb, sizeof(struct ipv6hdr));
2427 udph = (struct udphdr *)skb_put(skb, sizeof(struct udphdr));
2428
2429 memcpy(eth, pkt_dev->hh, 12);
2430 *(u16 *) & eth[12] = __constant_htons(ETH_P_IPV6);
2431
2299 datalen = pkt_dev->cur_pkt_size - 14 - sizeof(struct ipv6hdr) - sizeof(struct udphdr); /* Eth + IPh + UDPh */
2432 /* Eth + IPh + UDPh + mpls */
2433 datalen = pkt_dev->cur_pkt_size - 14 -
2434 sizeof(struct ipv6hdr) - sizeof(struct udphdr) -
2435 pkt_dev->nr_labels*sizeof(u32);
2300
2301 if (datalen < sizeof(struct pktgen_hdr)) {
2302 datalen = sizeof(struct pktgen_hdr);
2303 if (net_ratelimit())
2304 printk(KERN_INFO "pktgen: increased datalen to %d\n",
2305 datalen);
2306 }
2307

--- 7 unchanged lines hidden (view full) ---

2315 iph->hop_limit = 32;
2316
2317 iph->payload_len = htons(sizeof(struct udphdr) + datalen);
2318 iph->nexthdr = IPPROTO_UDP;
2319
2320 ipv6_addr_copy(&iph->daddr, &pkt_dev->cur_in6_daddr);
2321 ipv6_addr_copy(&iph->saddr, &pkt_dev->cur_in6_saddr);
2322
2436
2437 if (datalen < sizeof(struct pktgen_hdr)) {
2438 datalen = sizeof(struct pktgen_hdr);
2439 if (net_ratelimit())
2440 printk(KERN_INFO "pktgen: increased datalen to %d\n",
2441 datalen);
2442 }
2443

--- 7 unchanged lines hidden (view full) ---

2451 iph->hop_limit = 32;
2452
2453 iph->payload_len = htons(sizeof(struct udphdr) + datalen);
2454 iph->nexthdr = IPPROTO_UDP;
2455
2456 ipv6_addr_copy(&iph->daddr, &pkt_dev->cur_in6_daddr);
2457 ipv6_addr_copy(&iph->saddr, &pkt_dev->cur_in6_saddr);
2458
2323 skb->mac.raw = ((u8 *) iph) - 14;
2324 skb->protocol = __constant_htons(ETH_P_IPV6);
2459 skb->mac.raw = ((u8 *) iph) - 14 - pkt_dev->nr_labels*sizeof(u32);
2460 skb->protocol = protocol;
2325 skb->dev = odev;
2326 skb->pkt_type = PACKET_HOST;
2327
2328 if (pkt_dev->nfrags <= 0)
2329 pgh = (struct pktgen_hdr *)skb_put(skb, datalen);
2330 else {
2331 int frags = pkt_dev->nfrags;
2332 int i;

--- 934 unchanged lines hidden ---
2461 skb->dev = odev;
2462 skb->pkt_type = PACKET_HOST;
2463
2464 if (pkt_dev->nfrags <= 0)
2465 pgh = (struct pktgen_hdr *)skb_put(skb, datalen);
2466 else {
2467 int frags = pkt_dev->nfrags;
2468 int i;

--- 934 unchanged lines hidden ---