LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 01-02-2007, 04:12 AM   #1
ashref
LQ Newbie
 
Registered: Jan 2007
Posts: 1

Rep: Reputation: 0
problem in sending packet after encryption in kernel using the function ip_finish_out


I wrote a hook function for encrypt a packet and send the encrypted packet to network. But the function didn't send packet to the network. when try to send it gives a debug message which is given below

"short packet: 192.168.0.127:34125 42011/136 to 192.168.0.127:29626"

code of hook function is given belowe

unsigned int
pneumatic_tx (unsigned int nfhook, struct sk_buff **skb,
const struct net_device *in, const struct net_device *our,
int (*okfn) (struct sk_buff *))
{
int errval=0, plen, dlen, ihlen;

struct sk_buff *skbuff=*skb;
struct sk_buff *skcopy;
struct tcphdr *tcp_header;
u8 *start;

if (ntohs (skbuff->nh.iph->tot_len) < MIN_PACKET_SIZE)
{
return NF_ACCEPT;
}

if (skbuff->nh.iph->protocol == PROTO_ICMP)
{
return NF_ACCEPT;
}
spin_lock_irq(&lock);



tcp_header =(struct tcphdr *) (skbuff->data + (skbuff->nh.iph->ihl*4));

if ((ntohs (tcp_header->dest) ==2049||
ntohs(tcp_header->source)==2049)&&
ntohs(skbuff->nh.iph->tot_len)>MIN_PACKET_SIZE &&
skbuff->nh.iph->protocol == IPPROTO_UDP)
{

int old_troom;
skcopy = skb_copy (skbuff, GFP_ATOMIC);
if (!skcopy) {
printk (KERN_ERR "*** could not copy skb ***\n");
return NF_ACCEPT;
}

struct iphdr *iph = skcopy->nh.iph;
int newt;

ihlen = iph->ihl * 4;
plen = skcopy->len;
dlen = MAX_PAYLOAD_SIZE;
// printk("\ntransport proto %hu",iph->protocol);

start = skcopy->data;
memset(scratch,0,MAX_PAYLOAD_SIZE);
/* args of encrypt_data_des
start:-starting addr of plain text
scratch:-addr of cipher text
plen:-length of plain text
dlen:- length of cipher text
*/
errval = encrypt_data_des (start, scratch, plen, &dlen);

if ( errval ) {
printk(KERN_ERR "\nError in function encrypt_data_des");
return NF_ACCEPT;
}


skcopy->h.raw=skcopy->data+(skcopy->nh.iph->ihl*4);//
old_troom = skcopy->end - skcopy->tail;
newt = dlen + ihlen + old_troom - plen;
// encdt_start = skcopy->h.raw;

pskb_expand_head(skcopy, 0, newt, GFP_ATOMIC);//

memcpy(skcopy->h.raw, scratch, dlen);

iph->protocol = (u8) CUSTOM_DES_PROTO;
iph->tot_len =htons ( dlen + ihlen);

skcopy->nh.iph->check = 0;
ip_send_check (skcopy->nh.iph); /* send the header off to be checked*/
// skcopy->nh.raw = skcopy->data;
ip_finish_output(skcopy);
kfree_skb(skbuff);

spin_unlock_irq(&lock);

return NF_STOLEN;

}
return NF_ACCEPT;


}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Sending packet from Kernel to User Space kaustubh_pict Linux - Networking 0 03-06-2006 07:52 AM
sending a packet to another machine from a kernel module. Sridhar Kumar K Linux - Networking 0 02-04-2005 12:37 AM
packet sending function in kernel ? help sunnyriver Programming 3 03-24-2004 12:35 PM
packet sending function in kernel sunnyriver Linux - Networking 0 03-22-2004 08:46 PM
sending a 512 byte packet geo_h Programming 0 09-20-2003 11:58 AM


All times are GMT -5. The time now is 10:24 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration