Find the answer to your Linux question:
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.
  1. #1
    Just 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.

  2. #2
    Linux User fernape's Avatar
    Join Date
    Dec 2005
    Location
    Holland
    Posts
    301
    Quote Originally Posted by jituk
    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).
    Quote Originally Posted by jituk
    But I am not sure weather this is the right way to timestamp IP packets.
    I strongly recommnd that u use the Linux Trace Toolkit facility or netfilter hooks to do this.

    Best Regards

  3. #3
    Just Joined!
    Join Date
    Nov 2006
    Posts
    5
    Thank's for your comments..
    Quote Originally Posted by fernape
    I strongly recommnd that u use the Linux Trace Toolkit facility.
    Are you refering to use gdb or something like that..

    Regards,
    Jituk

  4. #4
    Linux User fernape's Avatar
    Join Date
    Dec 2005
    Location
    Holland
    Posts
    301
    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

  5. #5
    Just Joined!
    Join Date
    Nov 2006
    Posts
    5
    Thanks for replying.

    Quote Originally Posted by fernape
    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.
    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.

    Quote Originally Posted by fernape
    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.
    Okey, I will chk on this one.

  6. #6
    Linux User fernape's Avatar
    Join Date
    Dec 2005
    Location
    Holland
    Posts
    301
    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

  7. #7
    Just Joined!
    Join Date
    Nov 2006
    Posts
    5
    Quote Originally Posted by fernape
    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
    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. ) ..

    thanks

  8. #8
    Linux User fernape's Avatar
    Join Date
    Dec 2005
    Location
    Holland
    Posts
    301
    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

  9. #9
    Just Joined!
    Join Date
    Nov 2006
    Posts
    5
    Quote Originally Posted by fernape
    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
    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 (
    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 ************************************************/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •