Re: Sending sk_buffs without being tied to a struct sock

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Patrick McHardy wrote:

I don't think this is of much interest to lkml so i changed back cc to linux-net.

this is the basic outline i use to generate tcp packets (unimportant parts cut):

struct rt_key key = { .dst ctuple->dst.ip,
.src 0,
.oif 0,
.tos RT_TOS(IPTOS_LOWDELAY) | RTO_CONN,
#ifdef CONFIG_IP_ROUTE_FWMARK
.fwmark 0
#endif
};

if ((ip_route_output_key(&rt, &key) != 0))
sorry mistake here .. it should be return -1
patrick


return 1;

dev = rt->u.dst.dev;
skb = alloc_skb(dev->hard_header_len + sizeof(struct iphdr) +
tcp_hdr_len, GFP_ATOMIC);
if (!skb) {
ip_rt_put(rt);
return -1;
}

skb->dev = dev;
skb->dst = &rt->u.dst;
skb->protocol = __constant_htons(ETH_P_IP);

skb_reserve(skb, dev->hard_header_len);
skb->nh.raw = skb->data;
iph = (struct iphdr*) skb_put(skb, sizeof(struct iphdr));
tcph = (struct tcphdr*)skb_put(skb, tcp_hdr_len);

... fill in ip & tcp header ...

tcph->check = iph->check = 0;
tcph->check = tcp_v4_check(tcph, tcp_hdr_len, iph->saddr, iph->daddr,
csum_partial((char *)tcph, tcp_hdr_len, 0));
iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
skb->ip_summed = CHECKSUM_UNNECESSARY;

return skb->dst->output(skb);
}

this works fine, except when you turn on memory allocation debugging a
BUG_ON somewhere is triggered, i haven't looked into this yet.
While looking over it right now i noticed another thing, i think usually dev->hard_header_len
is padded to 16-byte boundaries, you might want to change this.
I hope it helps ..

Patrick


-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux