Wednesday, March 23, 2005

TCP packet entry (Linux Kernel)

This post should have preceeded the earlier post about the SYN and SYN-ACK's. But this is what happens when I dont keep my papers in order =). Anyways here it is. Once again I am not mentioning a few details which I dont think are neccessary. So here goes the entry of a TCP packet into the TCP layer of the Linux Network Stack.

As it happens, tcp_v4_rcv() is the function that is the entry point for a TCP packet into the TCP layer. This fuction first pulls out the TCP header from the packet and populates the 'th' variable in sk_buff. It then checks if there is a socket associated with the flow. It can either be the server socket or the client socket. If it fails to find such a socket, the packet is dropped. Otherwise the function populates other bookkeeping vaiables for the flow and finally calls tcp_v4_do_rcv(). tcp_v4_do_rcv() first checks to see if the socket is in the established state. If so, tcp_rcv_established() is called. What this means is that there was a SYN packet earlier to this packet and that the flow has gone beyond the 3-way handshake. Any other state the flow is in is handled by tcp_rcv_state_process().

Some of the important functions in tcp_rcv_established() are listed below.

tcp_ack(): This function deals with incoming acks only.
tcp_data_snd_check(): This function deals with data packets.
tcp_event_data_recv(): This function schedules ack's. The rest of the function deals with the data.
tcp_ack_scheduled(): This function returns the value of tp->ack.pending
tcp_send_ack(): This function prepares an outgoing ACK packet.
tcp_send_delayed_ack(): This function deals with delayed ACK's. Eventually it calls tcp_send_ack() to send out the packet.
__tcp_ack_snd_check(): This function checks to see if the kernel needs to send an ACK.

Well this is what I have at the moment. I thought I had more stuff to write but it turns out I dont.

Tuesday, March 22, 2005

SYN to SYN-ACK (Linux Kernel)

This is technical note. I have skipped a lot of details here that I know and dont feel neccessary to mention.

Well it so happens that tcp_v4_rcv() is the enterance point into the TCP layer for all TCP packets. All packets go to tcp_v4_do_rcv() from here. If the packet is a valid one and since this is a SYN packet, tcp_rcv_state_process() is called next. This function tries to do the right thing depending on the state of the socket. Since we are considering a SYN packet and are reading the code at a server, we can assume that the socket is in the listen mode. The function makes use of a switch statement to go through all the possible states of the socket. In the TCP_LISTEN case, apart from other things, the kernel checks if the syn flag is set in the packet. If so, the kernel executes the following code: tp->af_specific->conn_request()

where tp: of type struct tcp_opt
af_specific: of type struct tcp_func
conn_request: is a function pointer

In the init function, af_specific was initialized to ipv4_specific and thats how all the function pointers get their values i.e. function addresse. Thats how I can conclude that conn_request points to tcp_v4_conn_request.

At the time I was looking through this flow, I was interested in finding the function that is called for sending the SYN-ACK. And that function is tcp_v4_send_synack() which is called from tcp_v4_conn_request().

This entire exercise was done so that I can set the __unused variable in the SYN-ACK packets belonging to split TCP. I changed the function definition and introduced a new char variable that I call flag. This flag variable reflects the value of the __unused variable in the incoming packet. So depending on the value of flag variable I either set __unused to L or R or '\0' for the SYN-ACK packet. I also changed the function calls.Icing on the cake: it worked =)

Monday, March 21, 2005

Frustration abundant

Been a really long time since I have been feeling like this. Mostly its frustration because of work. Not sure what the remedy is but trying to live it a day at a time. As each day passes by, my hope that things will get better becomes even more bleak.

Last summer when I was reading the Linux network stack code, I was frustrated because there were no documentations available. But now when I look back at it, I am quite happy with what I had done. Because now I know a lot about the code and most of it is self learned. But now when I started hacking the kernel, I realize there are many more things that I need to know about. Every time I write a piece of code thats not even more than 10 lines and one that should take only 20 mins of testing, takes me about 2 weeks of debugging and testing. And not because the logic is wrong, but because the way that I want to integrate it with the kernel is wrong. At times I wish I had the easy button like those advertised in the staples ad.

At this time when I look beyond my PhD, I find myself working in a university. This is something that I absolutely dont want, especially after graduation. I love teaching, but I want to get back to the university after working in a research lab. I would have much more knowledge than I would immediately after graduation and much more to offer. Most people look forward for their graduation because it signifies the start of a new chapter in life. At this moment I am dreading it because the prospects dont look good for me, something that I dont want. I had made a roadmap of my life after I had graduated from my bachelors. Till about 7 months ago it seemed as though my life was going right as I had planned. And then BOOOOOOM. And everything was scattered and I was left behind to pick up the pieces. Pieces so small that its hard to find them.

Ahh but as they say, thats life. When I was a kid, my school teachers use to try to make a better person out of us. One famous line that they would often tell to us was "There is no substitute for Hard Work". What they never told us was, even though you put in everything you got into something, did all the hard work, it might just not work out. I wish my teachers would have never made me believe in that. Life is not that kind while teaching us our lessons.

Friday, March 18, 2005

Be independent

My todays achievement was doing laundry :D What a big pain it is. Back in India when I was working, I use to make fun of a co-worker who had moved to bombay for the job. Every weekend he would turn down our plans because he had to do laundry. Now I feel his pain. Things were way different back home. Everything was given to us in a silver plate. But I dont know how many us really appreciated all that was simply handed over to us. In that respect I am quite happy that I came here to be on my own. There is a fitting saying for this situation in hindi "Akele rahoge tho atte daal ka bhaav pata chalega". What is means is that you will know the hardships of life when you start living alone. And this is one thing that is so true. I have learned so much after coming here that I am sure it would have taken me ages if I was still in India. I feel everyone should stay away from home for a few years. Be totally independent. I feel its a very important learning process.

Thursday, March 17, 2005

And the journey begins

Its 1.00 in the nite. After 2 hours of speculation and being lazy I have finally put myself together to write my first blog. Nothing much to write at the moment, but I guess a blog is supposed to be a means for you to just scribble out your heart and mind. Thts how I choose the name of my blog - dildimag. Dil meaning heart and Dimag meaning mind. The heart and the mind, such a strange combination. Hardly do I find my heart and mind at the same page. As one friend of mine had put it, thats what makes life interesting. True to a certain extent. There is this constant battle between the two, who is right, who is wrong. And we humans are supposed to make the decision. Well I for one hardly find myself making the right one. But here is the thing, what ever I choose, I have to live with it. There is no turning back after the moment passes. There is a song very much potraying this situation. Not completely though

Aane wala pal,
jaane wala hai
Ho sake tho ismye,
zindagi bitalo,
pal jo yeh ane wala hai

The lyrics are in hindi. They mean, the moment that is coming is gonna go away. Try and live it to the fullest before this moment that comes passes away. I guess that is what I should try to do. Everyone should do. But here is the catch - easy said than done. It just occured to me that for any situation one can find a saying that is the consoling types. Something to think about.

Ok that does it for me today. I am gonna try n write blog (personal or technical) each day. It will be good for me.