Results 1 to 9 of 9
Hi,
I am trying to timestamp all incomming IP packets. For this I am making changes to ip_rcv_finish() function, in Linux/net/ipv4/ip_input.c. Before ip header is checked (iph->ihl > 5).
If ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 11-01-2006 #1Just Joined!
- Join Date
- Nov 2006
- Posts
- 5
How to timestamp incomming IP packets in kernel
Hi,
I am trying to timestamp all incomming IP packets. For this I am making changes to ip_rcv_finish() function, in Linux/net/ipv4/ip_input.c. Before ip header is checked (iph->ihl > 5).
If the incomming IP packet header lenght is 5, i.e their is no option field available in IP header. How can I allocate memory in IP header to add timestamp infomation.
I have tried using sbk_push(), to allocate extra memory for timestamp. But I am not sure weather this is the right way to timestamp IP packets.
- 11-01-2006 #2
Originally Posted by jituk I strongly recommnd that u use the Linux Trace Toolkit facility or netfilter hooks to do this.
Originally Posted by jituk
Best Regards
- 11-02-2006 #3Just Joined!
- Join Date
- Nov 2006
- Posts
- 5
Thank's for your comments..
Are you refering to use gdb or something like that..
Originally Posted by fernape
Regards,
Jituk
- 11-02-2006 #4
No.
Netfilter allows you to hook some IP stack functions (maybe to do some pre and post processing). So with it, u should be able to take some timestamps.
On the ohter hand, Linux Trace Toolkit allows to define some "checkpoints" inside the linux kernel, so u can do some work "before" a certain function is executed.
Best Regards
- 11-02-2006 #5Just Joined!
- Join Date
- Nov 2006
- Posts
- 5
Thanks for replying.
I am new to netfilter, but as far as my understanding goes, with netfilter I will create a hook in linux kernel code, and while doing so I will be specifing a function that will add timestamp to ip packet.. So still my problem for allocating extra memory in IP header (skbuff) persist. Correct me if I am wrong.
Originally Posted by fernape
Okey, I will chk on this one.
Originally Posted by fernape
- 11-05-2006 #6
Maybe I didn't understand your problem... do you want to change the IP header allocating more memory? I mean, do you want to make it bigger?
Best Regards
- 11-06-2006 #7Just Joined!
- Join Date
- Nov 2006
- Posts
- 5
Yes, exactly I need to make incomming IP header bigger. Since all most all the incomming IP packets do not have IP option field in the header (IP header lenght field is 5 (i.e. 20 bytes)), I need to allocated extra memory so that I can incorporate timestamp option field in IP header (extra 8 bytes.. to make it 28 bytes. ) ..
Originally Posted by fernape
thanks
- 11-06-2006 #8
Did you try with kmalloc()? Didn't work for u?
I think you could allocate memory for your new IP packet and then copy the old into the new plus your custom field.
Best Regards
- 11-06-2006 #9Just Joined!
- Join Date
- Nov 2006
- Posts
- 5
Yea I tried tow ways to allocate memory one useng kmalloc and using skb_push... Here is my code that is written in ip_rcv_finish, just before ip header length is checked (
Originally Posted by fernape )if (iph->ihl > 5)
// Check it the "sysctl" variable is set or not
if (sysctl_ip_opt_timestamps == 1) {
struct iphdr *new_iph;
unsigned char *new_ip_opt;
if (iph->ihl == 5) {
// Allocate a new memory buffer of the IP header
// new_iph = kmalloc(sizeof(struct iphdr) +
, GFP_ATOMIC);
new_iph = (struct iphdr *)skb_push(skb,sizeof(struct iphdr) +
;
// Copy the contents of previous IP header to the new one.
memcpy(new_iph, iph, sizeof(struct iphdr));
// Now a assign the new IP header pointer to the local IP header pointer
// We are doing this so that we dont have to modify the code after **END**
iph = new_iph;
// We are allocation the new IP header to soket buffer, raw sub field.
// NOTE: we are not assigining the new pointer to "skb->nh.iph"
skb->nh.raw = iph;
// Modifing the lenght field to new IP header to 7 (5 for IP header + 2 for (8 byte option field)).
iph->ihl = 7;
// Creating a local pointer to point the IP option field
new_ip_opt = (unsigned char *)(new_iph + sizeof(struct iphdr));
// Adding data in the option field as per client requirment
*(new_ip_opt + 0) = 68; // Adding data to IP timestamp option type field (1st byte of option)
*(new_ip_opt + 1) = 8; // Adding data to IP timestamp option leng field (2nd byte of option)
*(new_ip_opt + 2) = 5; // Adding data to IP timestamp option pointer field (3rd byte of option)
*(new_ip_opt + 3) = 0; // Adding data to IP timestamp option overflow + flag field (4th byte of option)
// NOTE: Timestamp is not added at this point. But when the control goes to "ip_options_compile" function
// See 22 lines below this comment.
// We have just set the control for time stamp to be added.
}
}
#endif /*CONFIG_IP_PACKET_TIMESTAMP*/
/************************************* END ************************************************/


Reply With Quote
