LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 06-28-2016, 06:57 AM   #1
gauravsuman007
LQ Newbie
 
Registered: Jun 2016
Posts: 9

Rep: Reputation: Disabled
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.
 
Old 06-28-2016, 07:28 AM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
The Oops is because you are trying to free a fixed string. I don't think your first C program should be kernel code.
 
Old 06-28-2016, 08:04 AM   #3
gauravsuman007
LQ Newbie
 
Registered: Jun 2016
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by smallpond View Post
The Oops is because you are trying to free a fixed string. I don't think your first C program should be kernel code.
This was just a dirty way of sending a recognizable packet to the other end. Later on, the string will be replaced with a struct. For now, I'm more focused on creating and sending off a a UDP packet.
Thanks for pointing it out though.
 
Old 06-28-2016, 08:17 AM   #4
gauravsuman007
LQ Newbie
 
Registered: Jun 2016
Posts: 9

Original Poster
Rep: Reputation: Disabled
Edit the code to remove the stub bug

I edited the original post to ensure that I'm using the memory properly
 
Old 06-28-2016, 10:38 AM   #5
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
Nope. Now you are copying 30 bytes out of a 24-byte string.
 
Old 06-29-2016, 03:32 AM   #6
gauravsuman007
LQ Newbie
 
Registered: Jun 2016
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by smallpond View Post
Nope. Now you are copying 30 bytes out of a 24-byte string.
I see. I'll remove that line for the moment then and just send an empty datagram as that's my real problem. Thank you
 
  


Reply

Tags
skbuff, udp



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to send/ receive MPLS packet from Kernel. Sekhar417 Linux - Kernel 2 03-13-2013 11:46 AM
Kernel crashed when the module tries to send IPv6 packet Jpradhan Linux - General 1 10-10-2010 08:06 AM
how to send udp packet to the DNS using netcat piyara Linux - Networking 7 06-16-2010 03:51 PM
Perl: UDP server receive / send packet to host superm@n Programming 2 04-02-2010 07:22 AM
Send a UDP Syslog packet with Source Port set to 514 fjkum Programming 1 01-26-2010 03:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 03:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration