Find the answer to your Linux question:
Results 1 to 10 of 10
Like Tree1Likes
  • 1 Post By gregm
Hello, I want to know which header file in Linux contains the structure of the TCP packets i.e. the data type definition of the tcp packet struct. What I want ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2014
    Posts
    16

    Question Data structure for TCP packet in linux


    Hello,

    I want to know which header file in Linux contains the structure of the TCP packets i.e. the data type definition of the tcp packet struct.

    What I want is to get access to the data members of the TCP packets which are being stored in one of the there following socket buffer queues:

    Out of order queue "out_of_order_queue".
    Write queue "sk_write_queue".
    Receive queue "sk_receive_queue".

    In-order to manipulate the timestamp of each packet. So where is the structure is located?

    Thanks a lot.

  2. #2
    Linux Engineer docbop's Avatar
    Join Date
    Nov 2009
    Location
    Woodshed, CA
    Posts
    943
    The structure is defined by RFC791 so its the same so all platforms can communicate with each other. Here's the RFC...
    http://www.ietf.org/rfc/rfc791.txt

    Here's the programmer POV.
    http://cs.baylor.edu/~donahoo/practi.../textcode.html
    A lion does not lose sleep, over the opinion of sheep.

  3. #3
    Just Joined!
    Join Date
    May 2014
    Posts
    16

    Question

    I think you misunderstood my question, what I want is to know the name of the struct used for constructing the TCP packets in the Linux Kernel and in which "C" header do they exist. By having this struct I can manipulate the packets being hold in the three different queues I have mentioned.

  4. #4
    Linux Engineer
    Join Date
    Dec 2013
    Posts
    1,310
    It's tcphdr in uapi/linux/tcp.h
    ha-as likes this.

  5. #5
    Linux Newbie
    Join Date
    Jun 2012
    Location
    SF Bay area
    Posts
    173
    I may regret asking this, but why do you want to "manipulate the timestamp of each packet"?

  6. #6
    Just Joined!
    Join Date
    May 2014
    Posts
    16

    Red face

    I wanted to manipulate the timestamp to control the RTO calculation, but I was mistaken and the timestamp is not saved inside the packet according to the tcphdr data structure.

  7. #7
    Linux Engineer
    Join Date
    Dec 2013
    Posts
    1,310
    Timestamp is one of the options. The options, if any, follow immediately after the tcp header. IIRC timestamp is option 6.

  8. #8
    Just Joined!
    Join Date
    May 2014
    Posts
    16

    Question

    I know that, but I mean when the packet is being saved in one of the five existing queues of the TCP in linux, their timestamps won't be saved inside the struct tcphdr, but there are other data members in the tcp_sock which handles the timestamp values, am I correct or not?

    Let me rephrase my main question again, when a TCP segment arrives to the machine, it will be saved in of the five queues to be processed, however when then segment is stored in these queues, does it contain its timestamp after the tcphdr structure or where is it saved?

    If someone,can illustrate how the TCP segment looks like inside the data part of the struct sk_buff.

  9. #9
    Linux Engineer
    Join Date
    Dec 2013
    Posts
    1,310
    It's there in the RFC for TCP - docbop posted the link. It isn't part of tcphdr - if the option exists it follows the header. To understand how it works read the RFC. This might help: How SKBs work

  10. #10
    Just Joined!
    Join Date
    May 2014
    Posts
    16

    Smile

    OK, thanks for the clarification. So now I have to do the offset by my self and check if the option in the TCP Segment matches the TimeStamp option and then I can have access to it.

    Do you recommend any examples or references in which they work with the TCP segments stored in various TCP queues?

    The link you provided to me is great but it deals with UDP case, and I am still beginner in the Linux Kernel Networking.

    Thanks a lot.

Posting Permissions

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