Martynas has asked for the wisdom of the Perl Monks concerning the following question:

Hello

How I can set scaled window size in packet using Net::RawIP?

I want set window greater than 65535, but window option by setting it to greater value makes window size 0 in packet.

I also tried setting up TCP option 3, but looks like I miss something about how to set it or there is other way how to make window size in a ACK packet greater.

This is my attempt with optset while trying to use different data options :

$packet->optset(tcp=> { type => [(3)], data => [(1)],});

Please advice how to make scaled window with a size of 262144 for example.

Thanks, Martynas

Replies are listed 'Best First'.
Re: Scaled TCP window with Net::RawIP
by Corion (Patriarch) on Mar 02, 2011 at 10:59 UTC

    Reading the documentation and searching for window seems to suggest the window key in the constructor to specify the window size. The "Window" field is only 16 bit, so it's highly unlikely that you will be able to set it greater than 65535, at least, that's what TCP Protocol tells me.

    Update: Reading TCP window scale option seems to indicate that you want to set the appropriate window scaling option to make the window go above 64k. I'm not sure how your supplied value of 1, affects the window size, but other than that, what you did should work, according to the documentation.

    How do you check that it doesn't work?

    As the option only sets a scale factor, you still need to set a window size.

      That is what I am trying to set - window to some value like for example 65535 and scaling factor via TCP option 3. However must be somthing still missing as scaling is usualy negotiated only in packets that have S flag. I do not catch how window size shgall be adjusted for specific scaling factor for ACK packet - like giving window size and telling that this is scaling factor to be used.

      When I play with TCP option 3 I tried various values as scaling factor, looks like there must be more fancy setup or something is not working as my window size remains as set in window with no scaling (according Wireshark).

      $packet = new Net::RawIP({tcp => {}}); $packet->set({ip=> {saddr=>$srcip, daddr=>$dstip, frag_off=>0, tos=>0 +, id=>int rand 50000}, tcp=> {source=>$sport, dest=>$dport, syn=>0, ack=>1, win +dow=> 65535, ack_seq=>++$his_seq, seq=>++$my_seq,}}); $packet->optset(tcp=> { type => [(3)], data => [(2)],});

      Updating with tcpdump output - win is 65535, wscale is 0, eol is set (?).

      13:53:56.892099 IP (tos 0x0, ttl 64, id 46408, offset 0, flags none, proto: TCP (6), length: 44) xx.yy.zz.yy.64570 > zz.yy.xx.ww.9876: ., cksum 0xce9f (correct), ack 1 win 65535 <wscale 0,eol>

      Martynas

Re: Scaled TCP window with Net::RawIP
by Illuminatus (Curate) on Mar 02, 2011 at 16:01 UTC
    You do understand that the wscale option is only valid on SYN, SYN/ACK packets, right? The tcpdump line you listed did not appear to have the SYN flag set. Also, I have not used Net::RawIP, but the documentation is not very clear to me on optset. For example, It says that the data has to be a string (which perl ought to convert for you, but who knows). Since it gives no examples of usage of this method, you may have to use a little trial-and-error to get it right. If you look here, there is an example involving optset that implies that it really wants a string containing the binary representation of the option value (ala pack())

    fnord

    Update: added reference to optset example.

      That is the point. I receive scaling factor in previous SYN/ACK. Now how I shall form packet flow after that to use scaled window with window size and scaling factor?

      Martynas

        Maybe you should read the rfc that defines window scaling (section 2). As long as both the SYN and SYN/ACK contain wscale opts, both sides will do scaling based on the values they sent/received. The option is never resent, but its shift-value is implied in the window value in the tcp header of each packet. The session info in the stack keeps track of the scale. This is a different question from "how can I get optset to work?" I guess I am a little confused about what you are trying to do. Are you really trying to manage a complete TCP session via RawIP? Unless the session is extremely trivial, this is not recommended.

        fnord