From: Emmanuel Guiton <emmanuel@netlab.hut.fi>
To: linux-kernel <linux-kernel@vger.kernel.org>
Subject: Sending built-by-hand packet and kernel panic.
Date: Mon, 02 Feb 2004 16:46:27 +0200 [thread overview]
Message-ID: <401E62C3.60503@netlab.hut.fi> (raw)
Hi!
Can any experienced network programmer give a quick look at the
following? I try to send a TCP packet built by hand. It works, but it
also leads to a kernel panic if a second packet is to be sent. As I'm
not an experienced kernel programmer, I guess I'm doing some stupid
thing that can be easily solved.
Basically, my code just fills a sk_buff structure and sends it with NF_HOOK.
Thanks for any help,
Emmanuel
/* skb is allocated 56 bytes = TCP message with no data
(detailed hereafter)
* + 2 extra bytes before the ethernet header (see hereafter)
*/
skb = alloc_skb(56, GFP_ATOMIC);
skb_reserve(skb, 2); /* for 16-bit alignment*/
/* ethernet header is 14 byte long */
eth = (__u8 *) skb_put(skb, 14);
/* ip header is 20 byte long */
iph = (struct iphdr *)skb_put(skb, sizeof(struct iphdr));
/* tcp header (no options) is 20 byte long */
tcph = (struct tcphdr *)skb_put(skb, sizeof(struct tcphdr));
/* skb->dst AND skb->dev (the latter is set by the former) */
if (ip_route_output(&rt, ip_dst, 0, 0, 0) != 0)
{
printk("ip_route_output failed.\n");
return -1;
}
skb->dst = (struct rt_entry *) rt; /* A trick from ip_route_input.c */
skb->dev = skb->dst->dev;
/* Socket allocation. */
if (sock_create(PF_INET, SOCK_RAW, IPPROTO_RAW, &sending_socket) < 0)
{
printk("Error socket creation.\n");
sock_release(sending_socket);
return -1;
}
sk = kmalloc(sizeof(struct sock), GFP_KERNEL);
memcpy(&(sending_socket->sk), sk, sizeof(struct sock));
sock_release(sending_socket);
if (sk == NULL)
{
printk("Error: sk == NULL\n");
return -1;
}
/* Now, set the sock field. */
skb->sk = sk;
/* TRANSPORT HEADER: TCP */
/* here, TCP header data is filled in tcph. */
skb->h.th = tcph;
/* NETWORK HEADER: IP */
/* here, IP header data is filled in iph*/
skb->nh.iph = iph;
/* LINK HEADER: ETHERNET */
/* here, ethernet header data is filled in iph*/
skb->mac.ethernet = ((u8 *)iph) - 14;
/* Fix me:
* Scheduling priority put at max, choose more correct value.
*/
skb->priority = 15;
/* To choose right pkt_type when receiving a packet.
* We're not receivng anything, but I set the value like the guys
* in pktgen.c did, there should be a reason for that.
*/
skb->protocol = __constant_htons(ETH_P_IP);
/* TIMESTAMP */
/* last, so it's closest to sending time. */
do_gettimeofday(&skb->stamp);
printk("Going to send initialized skb! ...\n");
// if (NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, skb->dev,
output_maybe_reroute) < 0)
NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, skb->dev,
ip_finish_output) < 0
next reply other threads:[~2004-02-02 14:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-02-02 14:46 Emmanuel Guiton [this message]
[not found] ` <200402021602.56242.baldrick@free.fr>
2004-02-02 17:51 ` Freeing skbuff (was: Re: Sending built-by-hand packet and kernel panic.) Emmanuel Guiton
2004-02-03 9:49 ` Muli Ben-Yehuda
2004-02-06 6:58 ` Emmanuel Guiton
2004-02-04 10:27 ` Duncan Sands
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=401E62C3.60503@netlab.hut.fi \
--to=emmanuel@netlab.hut.fi \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox