Pull misc into release branch
[cascardo/linux.git] / net / core / pktgen.c
index 9cd3a1c..36fdea7 100644 (file)
 #include <net/checksum.h>
 #include <net/ipv6.h>
 #include <net/addrconf.h>
+#ifdef CONFIG_XFRM
+#include <net/xfrm.h>
+#endif
 #include <asm/byteorder.h>
 #include <linux/rcupdate.h>
 #include <asm/bitops.h>
 #define F_MPLS_RND    (1<<8)   /* Random MPLS labels */
 #define F_VID_RND     (1<<9)   /* Random VLAN ID */
 #define F_SVID_RND    (1<<10)  /* Random SVLAN ID */
+#define F_FLOW_SEQ    (1<<11)  /* Sequential flows */
+#define F_IPSEC_ON    (1<<12)  /* ipsec on for flows */
 
 /* Thread control flag bits */
 #define T_TERMINATE   (1<<0)
@@ -207,8 +212,15 @@ static struct proc_dir_entry *pg_proc_dir = NULL;
 struct flow_state {
        __be32 cur_daddr;
        int count;
+#ifdef CONFIG_XFRM
+       struct xfrm_state *x;
+#endif
+       __u32 flags;
 };
 
+/* flow flag bits */
+#define F_INIT   (1<<0)                /* flow has been initialized */
+
 struct pktgen_dev {
        /*
         * Try to keep frequent/infrequent used vars. separated.
@@ -228,6 +240,7 @@ struct pktgen_dev {
 
        int min_pkt_size;       /* = ETH_ZLEN; */
        int max_pkt_size;       /* = ETH_ZLEN; */
+       int pkt_overhead;       /* overhead for MPLS, VLANs, IPSEC etc */
        int nfrags;
        __u32 delay_us;         /* Default delay */
        __u32 delay_ns;
@@ -341,7 +354,11 @@ struct pktgen_dev {
        unsigned cflows;        /* Concurrent flows (config) */
        unsigned lflow;         /* Flow length  (config) */
        unsigned nflows;        /* accumulated flows (stats) */
-
+       unsigned curfl;         /* current sequenced flow (state)*/
+#ifdef CONFIG_XFRM
+       __u8    ipsmode;                /* IPSEC mode (config) */
+       __u8    ipsproto;               /* IPSEC type (config) */
+#endif
        char result[512];
 };
 
@@ -363,7 +380,6 @@ struct pktgen_thread {
        /* Field for thread to receive "posted" events terminate, stop ifs etc. */
 
        u32 control;
-       int pid;
        int cpu;
 
        wait_queue_head_t queue;
@@ -550,7 +566,7 @@ static ssize_t pgctrl_write(struct file *file, const char __user * buf,
                pktgen_run_all_threads();
 
        else
-               printk("pktgen: Unknown command: %s\n", data);
+               printk(KERN_WARNING "pktgen: Unknown command: %s\n", data);
 
        err = count;
 
@@ -690,6 +706,18 @@ static int pktgen_if_show(struct seq_file *seq, void *v)
        if (pkt_dev->flags & F_MPLS_RND)
                seq_printf(seq,  "MPLS_RND  ");
 
+       if (pkt_dev->cflows) {
+               if (pkt_dev->flags & F_FLOW_SEQ)
+                       seq_printf(seq,  "FLOW_SEQ  "); /*in sequence flows*/
+               else
+                       seq_printf(seq,  "FLOW_RND  ");
+       }
+
+#ifdef CONFIG_XFRM
+       if (pkt_dev->flags & F_IPSEC_ON)
+               seq_printf(seq,  "IPSEC  ");
+#endif
+
        if (pkt_dev->flags & F_MACSRC_RND)
                seq_printf(seq, "MACSRC_RND  ");
 
@@ -879,14 +907,14 @@ static ssize_t pktgen_if_write(struct file *file,
        pg_result = &(pkt_dev->result[0]);
 
        if (count < 1) {
-               printk("pktgen: wrong command format\n");
+               printk(KERN_WARNING "pktgen: wrong command format\n");
                return -EINVAL;
        }
 
        max = count - i;
        tmp = count_trail_chars(&user_buffer[i], max);
        if (tmp < 0) {
-               printk("pktgen: illegal format\n");
+               printk(KERN_WARNING "pktgen: illegal format\n");
                return tmp;
        }
        i += tmp;
@@ -914,7 +942,7 @@ static ssize_t pktgen_if_write(struct file *file,
                if (copy_from_user(tb, user_buffer, count))
                        return -EFAULT;
                tb[count] = 0;
-               printk("pktgen: %s,%lu  buffer -:%s:-\n", name,
+               printk(KERN_DEBUG "pktgen: %s,%lu  buffer -:%s:-\n", name,
                       (unsigned long)count, tb);
        }
 
@@ -1181,6 +1209,14 @@ static ssize_t pktgen_if_write(struct file *file,
                else if (strcmp(f, "!SVID_RND") == 0)
                        pkt_dev->flags &= ~F_SVID_RND;
 
+               else if (strcmp(f, "FLOW_SEQ") == 0)
+                       pkt_dev->flags |= F_FLOW_SEQ;
+
+#ifdef CONFIG_XFRM
+               else if (strcmp(f, "IPSEC") == 0)
+                       pkt_dev->flags |= F_IPSEC_ON;
+#endif
+
                else if (strcmp(f, "!IPV6") == 0)
                        pkt_dev->flags &= ~F_IPV6;
 
@@ -1189,7 +1225,7 @@ static ssize_t pktgen_if_write(struct file *file,
                                "Flag -:%s:- unknown\nAvailable flags, (prepend ! to un-set flag):\n%s",
                                f,
                                "IPSRC_RND, IPDST_RND, UDPSRC_RND, UDPDST_RND, "
-                               "MACSRC_RND, MACDST_RND, TXSIZE_RND, IPV6, MPLS_RND, VID_RND, SVID_RND\n");
+                               "MACSRC_RND, MACDST_RND, TXSIZE_RND, IPV6, MPLS_RND, VID_RND, SVID_RND, FLOW_SEQ, IPSEC\n");
                        return count;
                }
                sprintf(pg_result, "OK: flags=0x%x", pkt_dev->flags);
@@ -1211,7 +1247,7 @@ static ssize_t pktgen_if_write(struct file *file,
                        pkt_dev->cur_daddr = pkt_dev->daddr_min;
                }
                if (debug)
-                       printk("pktgen: dst_min set to: %s\n",
+                       printk(KERN_DEBUG "pktgen: dst_min set to: %s\n",
                               pkt_dev->dst_min);
                i += len;
                sprintf(pg_result, "OK: dst_min=%s", pkt_dev->dst_min);
@@ -1234,7 +1270,7 @@ static ssize_t pktgen_if_write(struct file *file,
                        pkt_dev->cur_daddr = pkt_dev->daddr_max;
                }
                if (debug)
-                       printk("pktgen: dst_max set to: %s\n",
+                       printk(KERN_DEBUG "pktgen: dst_max set to: %s\n",
                               pkt_dev->dst_max);
                i += len;
                sprintf(pg_result, "OK: dst_max=%s", pkt_dev->dst_max);
@@ -1257,7 +1293,7 @@ static ssize_t pktgen_if_write(struct file *file,
                ipv6_addr_copy(&pkt_dev->cur_in6_daddr, &pkt_dev->in6_daddr);
 
                if (debug)
-                       printk("pktgen: dst6 set to: %s\n", buf);
+                       printk(KERN_DEBUG "pktgen: dst6 set to: %s\n", buf);
 
                i += len;
                sprintf(pg_result, "OK: dst6=%s", buf);
@@ -1280,7 +1316,7 @@ static ssize_t pktgen_if_write(struct file *file,
                ipv6_addr_copy(&pkt_dev->cur_in6_daddr,
                               &pkt_dev->min_in6_daddr);
                if (debug)
-                       printk("pktgen: dst6_min set to: %s\n", buf);
+                       printk(KERN_DEBUG "pktgen: dst6_min set to: %s\n", buf);
 
                i += len;
                sprintf(pg_result, "OK: dst6_min=%s", buf);
@@ -1301,7 +1337,7 @@ static ssize_t pktgen_if_write(struct file *file,
                fmt_ip6(buf, pkt_dev->max_in6_daddr.s6_addr);
 
                if (debug)
-                       printk("pktgen: dst6_max set to: %s\n", buf);
+                       printk(KERN_DEBUG "pktgen: dst6_max set to: %s\n", buf);
 
                i += len;
                sprintf(pg_result, "OK: dst6_max=%s", buf);
@@ -1324,7 +1360,7 @@ static ssize_t pktgen_if_write(struct file *file,
                ipv6_addr_copy(&pkt_dev->cur_in6_saddr, &pkt_dev->in6_saddr);
 
                if (debug)
-                       printk("pktgen: src6 set to: %s\n", buf);
+                       printk(KERN_DEBUG "pktgen: src6 set to: %s\n", buf);
 
                i += len;
                sprintf(pg_result, "OK: src6=%s", buf);
@@ -1345,7 +1381,7 @@ static ssize_t pktgen_if_write(struct file *file,
                        pkt_dev->cur_saddr = pkt_dev->saddr_min;
                }
                if (debug)
-                       printk("pktgen: src_min set to: %s\n",
+                       printk(KERN_DEBUG "pktgen: src_min set to: %s\n",
                               pkt_dev->src_min);
                i += len;
                sprintf(pg_result, "OK: src_min=%s", pkt_dev->src_min);
@@ -1366,7 +1402,7 @@ static ssize_t pktgen_if_write(struct file *file,
                        pkt_dev->cur_saddr = pkt_dev->saddr_max;
                }
                if (debug)
-                       printk("pktgen: src_max set to: %s\n",
+                       printk(KERN_DEBUG "pktgen: src_max set to: %s\n",
                               pkt_dev->src_max);
                i += len;
                sprintf(pg_result, "OK: src_max=%s", pkt_dev->src_max);
@@ -1496,7 +1532,7 @@ static ssize_t pktgen_if_write(struct file *file,
                        pkt_dev->svlan_id = 0xffff;
 
                        if (debug)
-                               printk("pktgen: VLAN/SVLAN auto turned off\n");
+                               printk(KERN_DEBUG "pktgen: VLAN/SVLAN auto turned off\n");
                }
                return count;
        }
@@ -1511,10 +1547,10 @@ static ssize_t pktgen_if_write(struct file *file,
                        pkt_dev->vlan_id = value;  /* turn on VLAN */
 
                        if (debug)
-                               printk("pktgen: VLAN turned on\n");
+                               printk(KERN_DEBUG "pktgen: VLAN turned on\n");
 
                        if (debug && pkt_dev->nr_labels)
-                               printk("pktgen: MPLS auto turned off\n");
+                               printk(KERN_DEBUG "pktgen: MPLS auto turned off\n");
 
                        pkt_dev->nr_labels = 0;    /* turn off MPLS */
                        sprintf(pg_result, "OK: vlan_id=%u", pkt_dev->vlan_id);
@@ -1523,7 +1559,7 @@ static ssize_t pktgen_if_write(struct file *file,
                        pkt_dev->svlan_id = 0xffff;
 
                        if (debug)
-                               printk("pktgen: VLAN/SVLAN turned off\n");
+                               printk(KERN_DEBUG "pktgen: VLAN/SVLAN turned off\n");
                }
                return count;
        }
@@ -1568,10 +1604,10 @@ static ssize_t pktgen_if_write(struct file *file,
                        pkt_dev->svlan_id = value;  /* turn on SVLAN */
 
                        if (debug)
-                               printk("pktgen: SVLAN turned on\n");
+                               printk(KERN_DEBUG "pktgen: SVLAN turned on\n");
 
                        if (debug && pkt_dev->nr_labels)
-                               printk("pktgen: MPLS auto turned off\n");
+                               printk(KERN_DEBUG "pktgen: MPLS auto turned off\n");
 
                        pkt_dev->nr_labels = 0;    /* turn off MPLS */
                        sprintf(pg_result, "OK: svlan_id=%u", pkt_dev->svlan_id);
@@ -1580,7 +1616,7 @@ static ssize_t pktgen_if_write(struct file *file,
                        pkt_dev->svlan_id = 0xffff;
 
                        if (debug)
-                               printk("pktgen: VLAN/SVLAN turned off\n");
+                               printk(KERN_DEBUG "pktgen: VLAN/SVLAN turned off\n");
                }
                return count;
        }
@@ -1740,10 +1776,11 @@ 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(KERN_DEBUG "pktgen: t=%s, count=%lu\n",
+                      name, (unsigned long)count);
 
        if (!t) {
-               printk("pktgen: ERROR: No thread\n");
+               printk(KERN_ERR "pktgen: ERROR: No thread\n");
                ret = -EINVAL;
                goto out;
        }
@@ -1854,8 +1891,8 @@ static void pktgen_mark_device(const char *ifname)
                mutex_lock(&pktgen_thread_lock);
 
                if (++i >= max_tries) {
-                       printk("pktgen_mark_device: timed out after waiting "
-                              "%d msec for device %s to be removed\n",
+                       printk(KERN_ERR "pktgen_mark_device: timed out after "
+                              "waiting %d msec for device %s to be removed\n",
                               msec_per_try * i, ifname);
                        break;
                }
@@ -1925,15 +1962,15 @@ static int pktgen_setup_dev(struct pktgen_dev *pkt_dev, const char *ifname)
 
        odev = dev_get_by_name(ifname);
        if (!odev) {
-               printk("pktgen: no such netdevice: \"%s\"\n", ifname);
+               printk(KERN_ERR "pktgen: no such netdevice: \"%s\"\n", ifname);
                return -ENODEV;
        }
 
        if (odev->type != ARPHRD_ETHER) {
-               printk("pktgen: not an ethernet device: \"%s\"\n", ifname);
+               printk(KERN_ERR "pktgen: not an ethernet device: \"%s\"\n", ifname);
                err = -EINVAL;
        } else if (!netif_running(odev)) {
-               printk("pktgen: device is down: \"%s\"\n", ifname);
+               printk(KERN_ERR "pktgen: device is down: \"%s\"\n", ifname);
                err = -ENETDOWN;
        } else {
                pkt_dev->odev = odev;
@@ -1950,7 +1987,8 @@ static int pktgen_setup_dev(struct pktgen_dev *pkt_dev, const char *ifname)
 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");
+               printk(KERN_ERR "pktgen: ERROR: pkt_dev->odev == NULL in "
+                      "setup_inject.\n");
                sprintf(pkt_dev->result,
                        "ERROR: pkt_dev->odev == NULL in setup_inject.\n");
                return;
@@ -2012,7 +2050,8 @@ static void pktgen_setup_inject(struct pktgen_dev *pkt_dev)
                        }
                        rcu_read_unlock();
                        if (err)
-                               printk("pktgen: ERROR: IPv6 link address not availble.\n");
+                               printk(KERN_ERR "pktgen: ERROR: IPv6 link "
+                                      "address not availble.\n");
                }
 #endif
        } else {
@@ -2075,6 +2114,69 @@ static void spin(struct pktgen_dev *pkt_dev, __u64 spin_until_us)
        pkt_dev->idle_acc += now - start;
 }
 
+static inline void set_pkt_overhead(struct pktgen_dev *pkt_dev)
+{
+       pkt_dev->pkt_overhead = 0;
+       pkt_dev->pkt_overhead += pkt_dev->nr_labels*sizeof(u32);
+       pkt_dev->pkt_overhead += VLAN_TAG_SIZE(pkt_dev);
+       pkt_dev->pkt_overhead += SVLAN_TAG_SIZE(pkt_dev);
+}
+
+static inline int f_seen(struct pktgen_dev *pkt_dev, int flow)
+{
+
+       if (pkt_dev->flows[flow].flags & F_INIT)
+               return 1;
+       else
+               return 0;
+}
+
+static inline int f_pick(struct pktgen_dev *pkt_dev)
+{
+       int flow = pkt_dev->curfl;
+
+       if (pkt_dev->flags & F_FLOW_SEQ) {
+               if (pkt_dev->flows[flow].count >= pkt_dev->lflow) {
+                       /* reset time */
+                       pkt_dev->flows[flow].count = 0;
+                       pkt_dev->curfl += 1;
+                       if (pkt_dev->curfl >= pkt_dev->cflows)
+                               pkt_dev->curfl = 0; /*reset */
+               }
+       } else {
+               flow = random32() % pkt_dev->cflows;
+
+               if (pkt_dev->flows[flow].count > pkt_dev->lflow)
+                       pkt_dev->flows[flow].count = 0;
+       }
+
+       return pkt_dev->curfl;
+}
+
+
+#ifdef CONFIG_XFRM
+/* If there was already an IPSEC SA, we keep it as is, else
+ * we go look for it ...
+*/
+static void get_ipsec_sa(struct pktgen_dev *pkt_dev, int flow)
+{
+       struct xfrm_state *x = pkt_dev->flows[flow].x;
+       if (!x) {
+               /*slow path: we dont already have xfrm_state*/
+               x = xfrm_stateonly_find((xfrm_address_t *)&pkt_dev->cur_daddr,
+                                       (xfrm_address_t *)&pkt_dev->cur_saddr,
+                                       AF_INET,
+                                       pkt_dev->ipsmode,
+                                       pkt_dev->ipsproto, 0);
+               if (x) {
+                       pkt_dev->flows[flow].x = x;
+                       set_pkt_overhead(pkt_dev);
+                       pkt_dev->pkt_overhead+=x->props.header_len;
+               }
+
+       }
+}
+#endif
 /* Increment/randomize headers according to flags and current values
  * for IP src/dest, UDP src/dst port, MAC-Addr src/dst
  */
@@ -2084,12 +2186,8 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev)
        __u32 imx;
        int flow = 0;
 
-       if (pkt_dev->cflows) {
-               flow = random32() % pkt_dev->cflows;
-
-               if (pkt_dev->flows[flow].count > pkt_dev->lflow)
-                       pkt_dev->flows[flow].count = 0;
-       }
+       if (pkt_dev->cflows)
+               flow = f_pick(pkt_dev);
 
        /*  Deal with source MAC */
        if (pkt_dev->src_mac_count > 1) {
@@ -2205,7 +2303,7 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev)
                        pkt_dev->cur_saddr = htonl(t);
                }
 
-               if (pkt_dev->cflows && pkt_dev->flows[flow].count != 0) {
+               if (pkt_dev->cflows && f_seen(pkt_dev, flow)) {
                        pkt_dev->cur_daddr = pkt_dev->flows[flow].cur_daddr;
                } else {
                        imn = ntohl(pkt_dev->daddr_min);
@@ -2235,8 +2333,13 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev)
                                }
                        }
                        if (pkt_dev->cflows) {
+                               pkt_dev->flows[flow].flags |= F_INIT;
                                pkt_dev->flows[flow].cur_daddr =
                                    pkt_dev->cur_daddr;
+#ifdef CONFIG_XFRM
+                               if (pkt_dev->flags & F_IPSEC_ON)
+                                       get_ipsec_sa(pkt_dev, flow);
+#endif
                                pkt_dev->nflows++;
                        }
                }
@@ -2277,6 +2380,93 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev)
        pkt_dev->flows[flow].count++;
 }
 
+
+#ifdef CONFIG_XFRM
+static int pktgen_output_ipsec(struct sk_buff *skb, struct pktgen_dev *pkt_dev)
+{
+       struct xfrm_state *x = pkt_dev->flows[pkt_dev->curfl].x;
+       int err = 0;
+       struct iphdr *iph;
+
+       if (!x)
+               return 0;
+       /* XXX: we dont support tunnel mode for now until
+        * we resolve the dst issue */
+       if (x->props.mode != XFRM_MODE_TRANSPORT)
+               return 0;
+
+       spin_lock(&x->lock);
+       iph = ip_hdr(skb);
+
+       err = x->mode->output(x, skb);
+       if (err)
+               goto error;
+       err = x->type->output(x, skb);
+       if (err)
+               goto error;
+
+       x->curlft.bytes +=skb->len;
+       x->curlft.packets++;
+       spin_unlock(&x->lock);
+
+error:
+       spin_unlock(&x->lock);
+       return err;
+}
+
+static inline void free_SAs(struct pktgen_dev *pkt_dev)
+{
+       if (pkt_dev->cflows) {
+               /* let go of the SAs if we have them */
+               int i = 0;
+               for (;  i < pkt_dev->nflows; i++){
+                       struct xfrm_state *x = pkt_dev->flows[i].x;
+                       if (x) {
+                               xfrm_state_put(x);
+                               pkt_dev->flows[i].x = NULL;
+                       }
+               }
+       }
+}
+
+static inline int process_ipsec(struct pktgen_dev *pkt_dev,
+                             struct sk_buff *skb, __be16 protocol)
+{
+       if (pkt_dev->flags & F_IPSEC_ON) {
+               struct xfrm_state *x = pkt_dev->flows[pkt_dev->curfl].x;
+               int nhead = 0;
+               if (x) {
+                       int ret;
+                       __u8 *eth;
+                       nhead = x->props.header_len - skb_headroom(skb);
+                       if (nhead >0) {
+                               ret = pskb_expand_head(skb, nhead, 0, GFP_ATOMIC);
+                               if (ret < 0) {
+                                       printk(KERN_ERR "Error expanding "
+                                              "ipsec packet %d\n",ret);
+                                       return 0;
+                               }
+                       }
+
+                       /* ipsec is not expecting ll header */
+                       skb_pull(skb, ETH_HLEN);
+                       ret = pktgen_output_ipsec(skb, pkt_dev);
+                       if (ret) {
+                               printk(KERN_ERR "Error creating ipsec "
+                                      "packet %d\n",ret);
+                               kfree_skb(skb);
+                               return 0;
+                       }
+                       /* restore ll */
+                       eth = (__u8 *) skb_push(skb, ETH_HLEN);
+                       memcpy(eth, pkt_dev->hh, 12);
+                       *(u16 *) & eth[12] = protocol;
+               }
+       }
+       return 1;
+}
+#endif
+
 static void mpls_push(__be32 *mpls, struct pktgen_dev *pkt_dev)
 {
        unsigned i;
@@ -2323,9 +2513,7 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
 
        datalen = (odev->hard_header_len + 16) & ~0xf;
        skb = alloc_skb(pkt_dev->cur_pkt_size + 64 + datalen +
-                       pkt_dev->nr_labels*sizeof(u32) +
-                       VLAN_TAG_SIZE(pkt_dev) + SVLAN_TAG_SIZE(pkt_dev),
-                       GFP_ATOMIC);
+                       pkt_dev->pkt_overhead, GFP_ATOMIC);
        if (!skb) {
                sprintf(pkt_dev->result, "No memory");
                return NULL;
@@ -2368,7 +2556,7 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
 
        /* Eth + IPh + UDPh + mpls */
        datalen = pkt_dev->cur_pkt_size - 14 - 20 - 8 -
-                 pkt_dev->nr_labels*sizeof(u32) - VLAN_TAG_SIZE(pkt_dev) - SVLAN_TAG_SIZE(pkt_dev);
+                 pkt_dev->pkt_overhead;
        if (datalen < sizeof(struct pktgen_hdr))
                datalen = sizeof(struct pktgen_hdr);
 
@@ -2391,8 +2579,7 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
        iph->check = ip_fast_csum((void *)iph, iph->ihl);
        skb->protocol = protocol;
        skb->mac_header = (skb->network_header - ETH_HLEN -
-                          pkt_dev->nr_labels * sizeof(u32) -
-                          VLAN_TAG_SIZE(pkt_dev) - SVLAN_TAG_SIZE(pkt_dev));
+                          pkt_dev->pkt_overhead);
        skb->dev = odev;
        skb->pkt_type = PACKET_HOST;
 
@@ -2463,6 +2650,11 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
                pgh->tv_usec = htonl(timestamp.tv_usec);
        }
 
+#ifdef CONFIG_XFRM
+       if (!process_ipsec(pkt_dev, skb, protocol))
+               return NULL;
+#endif
+
        return skb;
 }
 
@@ -2662,9 +2854,7 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
        mod_cur_headers(pkt_dev);
 
        skb = alloc_skb(pkt_dev->cur_pkt_size + 64 + 16 +
-                       pkt_dev->nr_labels*sizeof(u32) +
-                       VLAN_TAG_SIZE(pkt_dev) + SVLAN_TAG_SIZE(pkt_dev),
-                       GFP_ATOMIC);
+                       pkt_dev->pkt_overhead, GFP_ATOMIC);
        if (!skb) {
                sprintf(pkt_dev->result, "No memory");
                return NULL;
@@ -2708,7 +2898,7 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
        /* Eth + IPh + UDPh + mpls */
        datalen = pkt_dev->cur_pkt_size - 14 -
                  sizeof(struct ipv6hdr) - sizeof(struct udphdr) -
-                 pkt_dev->nr_labels*sizeof(u32) - VLAN_TAG_SIZE(pkt_dev) - SVLAN_TAG_SIZE(pkt_dev);
+                 pkt_dev->pkt_overhead;
 
        if (datalen < sizeof(struct pktgen_hdr)) {
                datalen = sizeof(struct pktgen_hdr);
@@ -2738,8 +2928,7 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
        ipv6_addr_copy(&iph->saddr, &pkt_dev->cur_in6_saddr);
 
        skb->mac_header = (skb->network_header - ETH_HLEN -
-                          pkt_dev->nr_labels * sizeof(u32) -
-                          VLAN_TAG_SIZE(pkt_dev) - SVLAN_TAG_SIZE(pkt_dev));
+                          pkt_dev->pkt_overhead);
        skb->protocol = protocol;
        skb->dev = odev;
        skb->pkt_type = PACKET_HOST;
@@ -2857,6 +3046,7 @@ static void pktgen_run(struct pktgen_thread *t)
                        pkt_dev->started_at = getCurUs();
                        pkt_dev->next_tx_us = getCurUs();       /* Transmit immediately */
                        pkt_dev->next_tx_ns = 0;
+                       set_pkt_overhead(pkt_dev);
 
                        strcpy(pkt_dev->result, "Starting");
                        started++;
@@ -2997,8 +3187,8 @@ static int pktgen_stop_device(struct pktgen_dev *pkt_dev)
        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->odev->name);
+               printk(KERN_WARNING "pktgen: interface: %s is already "
+                      "stopped\n", pkt_dev->odev->name);
                return -EINVAL;
        }
 
@@ -3139,7 +3329,10 @@ static __inline__ void pktgen_xmit(struct pktgen_dev *pkt_dev)
                }
        }
 
-       if (netif_queue_stopped(odev) || need_resched()) {
+       if ((netif_queue_stopped(odev) ||
+            (pkt_dev->skb &&
+             netif_subqueue_stopped(odev, pkt_dev->skb->queue_mapping))) ||
+           need_resched()) {
                idle_start = getCurUs();
 
                if (!netif_running(odev)) {
@@ -3154,7 +3347,8 @@ static __inline__ void pktgen_xmit(struct pktgen_dev *pkt_dev)
 
                pkt_dev->idle_acc += getCurUs() - idle_start;
 
-               if (netif_queue_stopped(odev)) {
+               if (netif_queue_stopped(odev) ||
+                   netif_subqueue_stopped(odev, pkt_dev->skb->queue_mapping)) {
                        pkt_dev->next_tx_us = getCurUs();       /* TODO */
                        pkt_dev->next_tx_ns = 0;
                        goto out;       /* Try the next interface */
@@ -3170,7 +3364,8 @@ static __inline__ void pktgen_xmit(struct pktgen_dev *pkt_dev)
 
                        pkt_dev->skb = fill_packet(odev, pkt_dev);
                        if (pkt_dev->skb == NULL) {
-                               printk("pktgen: ERROR: couldn't allocate skb in fill_packet.\n");
+                               printk(KERN_ERR "pktgen: ERROR: couldn't "
+                                      "allocate skb in fill_packet.\n");
                                schedule();
                                pkt_dev->clone_count--; /* back out increment, OOM */
                                goto out;
@@ -3181,7 +3376,8 @@ static __inline__ void pktgen_xmit(struct pktgen_dev *pkt_dev)
        }
 
        netif_tx_lock_bh(odev);
-       if (!netif_queue_stopped(odev)) {
+       if (!netif_queue_stopped(odev) &&
+           !netif_subqueue_stopped(odev, pkt_dev->skb->queue_mapping)) {
 
                atomic_inc(&(pkt_dev->skb->users));
              retry_now:
@@ -3266,14 +3462,14 @@ static int pktgen_thread_worker(void *arg)
 
        init_waitqueue_head(&t->queue);
 
-       t->pid = current->pid;
-
        pr_debug("pktgen: starting pktgen/%d:  pid=%d\n", cpu, current->pid);
 
        max_before_softirq = t->max_before_softirq;
 
        set_current_state(TASK_INTERRUPTIBLE);
 
+       set_freezable();
+
        while (!kthread_should_stop()) {
                pkt_dev = next_to_run(t);
 
@@ -3372,7 +3568,8 @@ static int add_dev_to_thread(struct pktgen_thread *t,
        if_lock(t);
 
        if (pkt_dev->pg_thread) {
-               printk("pktgen: ERROR:  already assigned to a thread.\n");
+               printk(KERN_ERR "pktgen: ERROR: already assigned "
+                      "to a thread.\n");
                rv = -EBUSY;
                goto out;
        }
@@ -3397,7 +3594,7 @@ static int pktgen_add_device(struct pktgen_thread *t, const char *ifname)
 
        pkt_dev = __pktgen_NN_threads(ifname, FIND);
        if (pkt_dev) {
-               printk("pktgen: ERROR: interface already used.\n");
+               printk(KERN_ERR "pktgen: ERROR: interface already used.\n");
                return -EBUSY;
        }
 
@@ -3439,18 +3636,25 @@ static int pktgen_add_device(struct pktgen_thread *t, const char *ifname)
 
        pkt_dev->entry = create_proc_entry(ifname, 0600, pg_proc_dir);
        if (!pkt_dev->entry) {
-               printk("pktgen: cannot create %s/%s procfs entry.\n",
+               printk(KERN_ERR "pktgen: cannot create %s/%s procfs entry.\n",
                       PG_PROC_DIR, ifname);
                err = -EINVAL;
                goto out2;
        }
        pkt_dev->entry->proc_fops = &pktgen_if_fops;
        pkt_dev->entry->data = pkt_dev;
+#ifdef CONFIG_XFRM
+       pkt_dev->ipsmode = XFRM_MODE_TRANSPORT;
+       pkt_dev->ipsproto = IPPROTO_ESP;
+#endif
 
        return add_dev_to_thread(t, pkt_dev);
 out2:
        dev_put(pkt_dev->odev);
 out1:
+#ifdef CONFIG_XFRM
+       free_SAs(pkt_dev);
+#endif
        if (pkt_dev->flows)
                vfree(pkt_dev->flows);
        kfree(pkt_dev);
@@ -3465,7 +3669,8 @@ static int __init pktgen_create_thread(int cpu)
 
        t = kzalloc(sizeof(struct pktgen_thread), GFP_KERNEL);
        if (!t) {
-               printk("pktgen: ERROR: out of memory, can't create new thread.\n");
+               printk(KERN_ERR "pktgen: ERROR: out of memory, can't "
+                      "create new thread.\n");
                return -ENOMEM;
        }
 
@@ -3478,7 +3683,8 @@ static int __init pktgen_create_thread(int cpu)
 
        p = kthread_create(pktgen_thread_worker, t, "kpktgend_%d", cpu);
        if (IS_ERR(p)) {
-               printk("pktgen: kernel_thread() failed for cpu %d\n", t->cpu);
+               printk(KERN_ERR "pktgen: kernel_thread() failed "
+                      "for cpu %d\n", t->cpu);
                list_del(&t->th_list);
                kfree(t);
                return PTR_ERR(p);
@@ -3488,7 +3694,7 @@ static int __init pktgen_create_thread(int cpu)
 
        pe = create_proc_entry(t->tsk->comm, 0600, pg_proc_dir);
        if (!pe) {
-               printk("pktgen: cannot create %s/%s procfs entry.\n",
+               printk(KERN_ERR "pktgen: cannot create %s/%s procfs entry.\n",
                       PG_PROC_DIR, t->tsk->comm);
                kthread_stop(p);
                list_del(&t->th_list);
@@ -3527,7 +3733,8 @@ static int pktgen_remove_device(struct pktgen_thread *t,
        pr_debug("pktgen: remove_device pkt_dev=%p\n", pkt_dev);
 
        if (pkt_dev->running) {
-               printk("pktgen:WARNING: trying to remove a running interface, stopping it now.\n");
+               printk(KERN_WARNING "pktgen: WARNING: trying to remove a "
+                      "running interface, stopping it now.\n");
                pktgen_stop_device(pkt_dev);
        }
 
@@ -3545,6 +3752,9 @@ static int pktgen_remove_device(struct pktgen_thread *t,
        if (pkt_dev->entry)
                remove_proc_entry(pkt_dev->entry->name, pg_proc_dir);
 
+#ifdef CONFIG_XFRM
+       free_SAs(pkt_dev);
+#endif
        if (pkt_dev->flows)
                vfree(pkt_dev->flows);
        kfree(pkt_dev);
@@ -3556,7 +3766,7 @@ static int __init pg_init(void)
        int cpu;
        struct proc_dir_entry *pe;
 
-       printk(version);
+       printk(KERN_INFO "%s", version);
 
        pg_proc_dir = proc_mkdir(PG_PROC_DIR, proc_net);
        if (!pg_proc_dir)
@@ -3565,8 +3775,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(KERN_ERR "pktgen: ERROR: cannot create %s "
+                      "procfs entry.\n", PGCTRL);
                proc_net_remove(PG_PROC_DIR);
                return -EINVAL;
        }
@@ -3582,12 +3792,13 @@ static int __init pg_init(void)
 
                err = pktgen_create_thread(cpu);
                if (err)
-                       printk("pktgen: WARNING: Cannot create thread for cpu %d (%d)\n",
-                                       cpu, err);
+                       printk(KERN_WARNING "pktgen: WARNING: Cannot create "
+                              "thread for cpu %d (%d)\n", cpu, err);
        }
 
        if (list_empty(&pktgen_threads)) {
-               printk("pktgen: ERROR: Initialization failed for all threads\n");
+               printk(KERN_ERR "pktgen: ERROR: Initialization failed for "
+                      "all threads\n");
                unregister_netdevice_notifier(&pktgen_notifier_block);
                remove_proc_entry(PGCTRL, pg_proc_dir);
                proc_net_remove(PG_PROC_DIR);