How to send a UDP packet from inside linux kernel
0
down vote
favorite
I'm modifying the UDP protocol such that when connect() is called on a UDP socket, in addition to finding the route, a "Hello" packet is also sent to the destination.
From the UDP proto structure, I figured out that the function ip4_datagram_connect does the job of finding the route to the destination. Now at the end of this function, I need to send the Hello packet.
I don't think I can use udp_sendmsg() as it's used for copying and sending data from the userspace.
I think udp_send_skb() should be used to sent the hello. My problem is I don't know how to create an appropriate skbuff to store the Hello message (it should be a proper udp datagram) to be passed on to udp_send_skb(). I've tried this
int quic_connect(struct sock *sk, struct flowi4 *fl4){
struct sk_buff *hbuff;
char *hello;
int err = 0;
hbuff = dev_alloc_skb(2000);
if (!hbuff){
printk("xxxxx skbuff not alloted for QUIC connect\n");
goto out;
}
skb_reserve(hbuff, sizeof(struct udphdr));
security_skb_owned_by(hbuff, sk);
skb_push(hbuff, sizeof(struct udphdr));
skb_reset_transport_header(hbuff);
hbuff->sk = sk;
err = udp_send_skb(hbuff, fl4);
However, this gives me errors in the kernel log
BUG: unable to handle kernel NULL pointer dereference at 0000000000000018
IP: [<ffffffff81686555>] __ip_local_out+0x45/0x80
PGD 4f4dd067 PUD 4f4df067 PMD 0
Oops: 0000 [#1] SMP
which was quite expected as I guessed that the new skbuff I created wasn't filled up properly.
So my question is, what else do I need to fill in my skbuff before it can be handled properly by udp_send_skb. Better yet, is there a function which can do this for me?
Last edited by gauravsuman007; 06-29-2016 at 03:33 AM.
|