#include <linux/etherdevice.h>
#include <linux/skbuff.h>
#include <net/sock.h>
+#include <net/checksum.h>
#include <linux/if_ether.h> /* For the statistics structure. */
#include <linux/if_arp.h> /* For ARPHRD_ETHER */
+#include <linux/ip.h>
+#include <linux/tcp.h>
#define LOOPBACK_OVERHEAD (128 + MAX_HEADER + 16 + 16)
+/* KISS: just allocate small chunks and copy bits.
+ *
+ * So, in fact, this is documentation, explaining what we expect
+ * of largesending device modulo TCP checksum, which is ignored for loopback.
+ */
+
+static void emulate_large_send_offload(struct sk_buff *skb)
+{
+ struct iphdr *iph = skb->nh.iph;
+ struct tcphdr *th = (struct tcphdr*)(skb->nh.raw + (iph->ihl * 4));
+ unsigned int doffset = (iph->ihl + th->doff) * 4;
+ unsigned int mtu = skb_shinfo(skb)->tso_size + doffset;
+ unsigned int offset = 0;
+ u32 seq = ntohl(th->seq);
+ u16 id = ntohs(iph->id);
+
+ while (offset + doffset < skb->len) {
+ unsigned int frag_size = min(mtu, skb->len - offset) - doffset;
+ struct sk_buff *nskb = alloc_skb(mtu + 32, GFP_ATOMIC);
+
+ if (!nskb)
+ break;
+ skb_reserve(nskb, 32);
+ nskb->mac.raw = nskb->data - 14;
+ nskb->nh.raw = nskb->data;
+ iph = nskb->nh.iph;
+ memcpy(nskb->data, skb->nh.raw, doffset);
+ if (skb_copy_bits(skb,
+ doffset + offset,
+ nskb->data + doffset,
+ frag_size))
+ BUG();
+ skb_put(nskb, doffset + frag_size);
+ nskb->ip_summed = CHECKSUM_UNNECESSARY;
+ nskb->dev = skb->dev;
+ nskb->priority = skb->priority;
+ nskb->protocol = skb->protocol;
+ nskb->dst = dst_clone(skb->dst);
+ memcpy(nskb->cb, skb->cb, sizeof(skb->cb));
+ nskb->pkt_type = skb->pkt_type;
+
+ th = (struct tcphdr*)(nskb->nh.raw + iph->ihl*4);
+ iph->tot_len = htons(frag_size + doffset);
+ iph->id = htons(id);
+ iph->check = 0;
+ iph->check = ip_fast_csum((unsigned char *) iph, iph->ihl);
+ th->seq = htonl(seq);
+ if (offset + doffset + frag_size < skb->len)
+ th->fin = th->psh = 0;
+ netif_rx(nskb);
+ offset += frag_size;
+ seq += frag_size;
+ id++;
+ }
+
+ dev_kfree_skb(skb);
+}
+
/*
* The higher levels take care of making this non-reentrant (it's
* called with bh's disabled).
skb->ip_summed = CHECKSUM_UNNECESSARY;
#endif
+ if (skb_shinfo(skb)->tso_size) {
+ struct iphdr *iph = skb->nh.iph;
+
+ if (skb->protocol != htons(ETH_P_IP))
+ BUG();
+ if (iph->protocol != IPPROTO_TCP)
+ BUG();
+
+ emulate_large_send_offload(skb);
+ return 0;
+ }
+
dev->last_rx = jiffies;
stats->rx_bytes+=skb->len;
stats->tx_bytes+=skb->len;
dev->rebuild_header = eth_rebuild_header;
dev->flags = IFF_LOOPBACK;
dev->features = NETIF_F_SG|NETIF_F_FRAGLIST|NETIF_F_NO_CSUM|NETIF_F_HIGHDMA;
+
+ /* Current netfilter will die with oom linearizing large skbs,
+ * however this will be cured before 2.5.x is done.
+ */
+ dev->features |= NETIF_F_TSO;
+
dev->priv = kmalloc(sizeof(struct net_device_stats), GFP_KERNEL);
if (dev->priv == NULL)
return -ENOMEM;
atomic_set(&skb->users, 1);
atomic_set(&(skb_shinfo(skb)->dataref), 1);
skb_shinfo(skb)->nr_frags = 0;
+ skb_shinfo(skb)->tso_size = 0;
+ skb_shinfo(skb)->tso_segs = 0;
skb_shinfo(skb)->frag_list = NULL;
out:
return skb;
unsigned int size;
u8 *data;
long offset;
+ struct skb_shared_info *ninfo;
int headerlen = skb->data - skb->head;
int expand = (skb->tail + skb->data_len) - skb->end;
if (skb_copy_bits(skb, -headerlen, data, headerlen + skb->len))
BUG();
+ /* Set up shinfo */
+ ninfo = (struct skb_shared_info*)(data + size);
+ atomic_set(&ninfo->dataref, 1);
+ ninfo->tso_size = skb_shinfo(skb)->tso_size;
+ ninfo->tso_segs = skb_shinfo(skb)->tso_segs;
+ ninfo->nr_frags = 0;
+ ninfo->frag_list = NULL;
+
/* Offset between the two in bytes */
offset = data - skb->head;
skb->tail += offset;
skb->data += offset;
- /* Set up shinfo */
- atomic_set(&(skb_shinfo(skb)->dataref), 1);
- skb_shinfo(skb)->nr_frags = 0;
- skb_shinfo(skb)->frag_list = NULL;
-
/* We are no longer a clone, even if we were. */
skb->cloned = 0;
}
skb_shinfo(n)->nr_frags = i;
}
+ skb_shinfo(n)->tso_size = skb_shinfo(skb)->tso_size;
+ skb_shinfo(n)->tso_segs = skb_shinfo(skb)->tso_segs;
if (skb_shinfo(skb)->frag_list) {
skb_shinfo(n)->frag_list = skb_shinfo(skb)->frag_list;
*
* You must pass %GFP_ATOMIC as the allocation priority if this function
* is called from an interrupt.
+ *
+ * BUG ALERT: ip_summed is not copied. Why does this work? Is it used
+ * only by netfilter in the cases when checksum is recalculated? --ANK
*/
struct sk_buff *skb_copy_expand(const struct sk_buff *skb,
int newheadroom, int newtailroom, int gfp_mask)
BUG();
copy_skb_header(n, skb);
+ skb_shinfo(n)->tso_size = skb_shinfo(skb)->tso_size;
+ skb_shinfo(n)->tso_segs = skb_shinfo(skb)->tso_segs;
return n;
}