December 16, 2014

Ack number generated by receiver

Hello everyone,

I'm trying to print out ACK numbers that are generated by the receiver, which are put in ACK packets. I have added "printk" inside the ip_queue_xmit() function, which resides inside the file /net/ipv4/ip_output.c. Here you can see part of code that I've added this print:

packet_routed:
if (inet_opt && inet_opt->opt.is_strictroute && rt->rt_uses_gateway)
goto no_route;

/* OK, we know where to send it, allocate and build IP header. */
skb_push(skb, sizeof(struct iphdr) + (inet_opt ? inet_opt->opt.optlen : 0));
skb_reset_network_header(skb);
iph = ip_hdr(skb);
*((__be16 *)iph) = htons((4 << 12) | (5 << 8) | (inet->tos & 0xff));
if (ip_dont_fragment(sk, &rt->dst) && !skb->ignore_df)
iph->frag_off = htons(IP_DF);
else
iph->frag_off = 0;
iph->ttl = ip_select_ttl(inet, &rt->dst);
iph->protocol = sk->sk_protocol;
ip_copy_addrs(iph, fl4);
printk( KERN_ALERT "[IpQueueXmit] src:%i.%i.%i.%i, dst:%i.%i.%i.%i, seq=%lu, ack=%lu, wnd=%d, sack=%d%d%d%d%d%d%d\n",
iph->saddr & 0xFF, (iph->saddr >> 8) & 0xFF, (iph->saddr >> 16) & 0xFF, (iph->saddr >> 24) & 0xFF,
iph->daddr & 0xFF, (iph->daddr >> 8) & 0xFF, (iph->daddr >> 16) & 0xFF, (iph->daddr >> 24) & 0xFF,
th->seq, th->ack_seq, th->window,
(tcb->sacked & TCPCB_SACKED_ACKED),
(tcb->sacked & TCPCB_SACKED_RETRANS),
(tcb->sacked & TCPCB_LOST),
(tcb->sacked & TCPCB_TAGBITS),
(tcb->sacked & TCPCB_REPAIRED),
(tcb->sacked & TCPCB_EVER_RETRANS),
(tcb->sacked & TCPCB_RETRANS) );

Noe I have a simple client-server application. I'm recording this printks on the client side. Here what I see out there:

Dec 16 17:59:12 debian kernel: [ 71.812741] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=598397731, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.812835] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=1408881443, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.813728] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=3690452003, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.813976] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=588567843, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.815431] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=3274364195, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.816066] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=2608846115, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.816668] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=2475742499, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.817291] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=1677120803, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.820520] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=3958691363, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.820633] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=1667290915, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.820754] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=2743981859, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.822583] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=730650659, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.822684] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=331339811, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.823166] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=1125046563, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.823767] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=1935530275, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.824592] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=2746013987, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.827362] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=732682787, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.827474] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=2736184099, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.827584] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=188209955, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.827672] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=2474695459, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.829383] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=727571491, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.830072] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=4090747939, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.831229] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=3142245667, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.831833] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=2210520355, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.834096] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=197189155, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.834240] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=3676692259, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.835094] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=1663361059, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.835204] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=864739363, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.837317] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=2335826211, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.838943] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=322495011, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.839068] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=999875107, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.839875] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=3281445667, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.840005] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=3958825763, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.841147] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=2611012643, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.843652] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=597681443, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.843788] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=4227065123, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.844600] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=2613044771, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.844720] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=4217235235, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.844825] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=2608129827, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.845212] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=2475026211, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.845930] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=2337007651, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.848464] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=323676451, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.848585] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=2343954723, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.848708] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=2077747491, wnd=60696, sack=0000000
Dec 16 17:59:12 debian kernel: [ 71.849299] [IpQueueXmit] src:172.16.33.128, dst:172.16.33.129, seq=910346536, ack=1939728931, wnd=60696, sack=0000000

I exactly don't know what is wrong with ACK number. It is not increasing constantly, and changes randomly.

Does anybody know what is the problem with this? Am I doing something wrong somwhere?

Thanks!

Click Here!