Note that there are some explanatory texts on larger screens.

plurals
  1. PObuilding an sk_buff for egress device linux kernel
    primarykey
    data
    text
    <p>Long story short, I am trying to build a very bare bones UDP SKB just to get something onto the wire. The scenario is as follows:</p> <p>I have a kernel module loading that (among other things) overrides the memory location of the standard udp_sendmsg function in /net/ipv4/udp.c. From here I would like to construct an skb to the point where I can simply put it onto the wire. Normally, udp_sendmsg simply does a little UDP bookkeeping, tacks on a UDP header and sends it down to the IP layer for routing, L3/L2 headers etc. Basically I am bringing some of that functionality up into the sendmsg function. At this time, I am just allocating an skb:</p> <pre><code> skb = alloc_skb(1500, GFP_KERNEL); //skb has 1500 bytes of tail room only skb_reserve(skb, 500); //now has head and tail but no data space data = skb_put(skb, 500); //now we have an skb with 500 head, 500 data sec, 500 tail </code></pre> <p>And then (after some route table seteup) I am trying to add a udp_hdr:</p> <pre><code> struct udphdr *uh; skb-&gt;transport_header = skb_push(skb, sizeof(struct udphdr)); uh = udp_hdr(skb); uh-&gt;source = 5555; uh-&gt;dest = dport; uh-&gt;len = 18; uh-&gt;check = 0; </code></pre> <p>and an ip_hdr (only the basics filled):</p> <pre><code> struct iphdr *iph; skb-&gt;network_header = skb_push(skb, sizeof(struct iphdr)); iph = ip_hdr(skb); iph-&gt;version = 4; iph-&gt;ihl = 5; iph-&gt;tos = inet-&gt;tos; iph-&gt;tot_len = htons(skb-&gt;len); iph-&gt;protocol = IPPROTO_UDP; iph-&gt;saddr = saddr; iph-&gt;daddr = daddr; skb-&gt;dst = dst_clone(&amp;rt-&gt;u.dst); </code></pre> <p>Note: I got most of this stuff from <a href="http://vger.kernel.org/~davem/skb_data.html" rel="nofollow noreferrer">this page</a> but they are using an older kernel (pre 2.6.24) where the network and transport headers were unions and called nh and h respectively. The new way involves using skb->transport_header / skb->network_header and using these helper functions but apparently I am doing something wrong because I get a kernel oops when I try to invoke the udp_sendmsg</p> <p>Note: this ran without an oops and dumped junk to the wire when instead of:</p> <pre><code> skb-&gt;transport_header = skb_push(skb, sizeof(struct udphdr)); </code></pre> <p>I used:</p> <pre><code>skb_reset_transport_header(skb); </code></pre> <p>(and equivalent for network_header. But after reading the link above and looking at the source for the reset function in linux/sk_buff.h, it didn't seem like it was doing what I wanted. </p> <p>Please also note that any assignment statement above with (in this context) undefined variables is simply because I didn't include the entire function. </p> <p>I realize this question might fall into a very specific domain but any guidance on correct usage of the newer skb construction would be greatly helpful. My buddy google is coming up pretty dry.</p> <p>The Oops Call Trace:</p> <blockquote> <pre><code> [&lt;ffffffff813dbf98&gt;] oops_end+0xb9/0xc1 [&lt;ffffffff81030e21&gt;] no_context+0x1f6/0x205 [&lt;ffffffff81030fd3&gt;] __bad_area_nosemaphore+0x1a3/0x1c9 [&lt;ffffffff8101184e&gt;] ? apic_timer_interrupt+0xe/0x20 [&lt;ffffffff8103100c&gt;] bad_area_nosemaphore+0x13/0x15 [&lt;ffffffff813dd30a&gt;] do_page_fault+0x125/0x222 [&lt;ffffffff813db485&gt;] page_fault+0x25/0x30 [&lt;ffffffffa010924f&gt;] ? udp_sendmsg_offload+0x1e3/0x250 [testmodule] [&lt;ffffffffa010922e&gt;] ? udp_sendmsg_offload+0x1c2/0x250 [testmodule] [&lt;ffffffff81390a00&gt;] inet_sendmsg+0x54/0x5d [&lt;ffffffff8132f142&gt;] __sock_sendmsg+0x61/0x6c [&lt;ffffffff8132f8b9&gt;] sock_sendmsg+0xcc/0xe5 </code></pre> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload