Hey.

I study the network. I do not understand the moment about the size of the pieces (segment, packet, frame), which are created to transmit the frame over the network. For example, a tcp segment using ethernet2 transfer technology can be as much as 1500 bytes. that is, the data with the http header came from the application layer (for example, the web server sent the html document), this data was broken into pieces — 1500 byte segments each. then [header tcp + segment] from the transport layer is transmitted to the ip level. It is written that the maximum packet size level ip = 65535 bytes. I do not understand - there is splitting into pieces of 1500 bytes at the transport level, why is the size of 65535 bytes indicated, if the transmitted chunks are 1500 bytes in size ?

    3 answers 3

    The reference model is an ideal data transfer model. OSI helps to illustrate the dependence of some protocols on others, and who drives whom, but it cannot dictate how they function.

    MTU and OSI model

    The transport layer protocols (TCP or UDP protocols), which use the network layer to send packets, consider that the maximum size of the data field of an IP packet is 65535 , and therefore can send it a message of such length for transport. The functions of the IP layer include splitting a message that is too long for a specific type of network component into shorter packets with the creation of corresponding service fields needed for the subsequent assembly of fragments into the original message.

    In most types of local and global networks, such a concept is defined as the maximum size of a frame or packet data field into which the IP protocol should encapsulate. This value is usually called the maximum transfer unit - Maximum Transfer Unit, MTU. Ethernet networks have an MTU of 1500 bytes, FDDI networks have 4096 bytes, and X.25 networks most often work with a 128 byte MTU.

    MTU is a data link layer characteristic of the OSI model. If the IP wants to send a datagram that is larger than the link level MTU, fragmentation is performed (fragmentation), and the datagram is split into smaller parts (fragments). Each fragment must be less than MTU.

    The top level always knows about the bottom . When the IP layer receives an IP datagram that needs to be sent, it determines to which local interface the datagram is sent (or routed), and requests the interface to tell the size of its MTU. IP compares the MTU with the size of the datagram and, if necessary, performs fragmentation. Fragmentation can be performed both on the sending host and on the intermediate router.

    Theoretically, the maximum size of an IP datagram is 65,535 bytes, due to the 16-bit full-length field in the IP header.

    The user @Smithson gave you the correct answer, because IP works not only on Ethernet, it has its own size on each network.

    Why do I need MTU?

    When two computers communicate on the same network, the MTU for this network is important. However, when two computers communicate on different networks, each intermediate channel may have a different MTU. In this case, the important thing is not the MTU of the two networks to which the computers are connected, but the smallest MTU of any data channel between two computers. It is called a transport MTU (path MTU).

    The transport MTU between any two hosts may not be permanent. MTU depends on the current channel load. It also depends on the route. The route may be asymmetric (the route from A to B may not be at all the fact that the route is from B to A), so the MTU may not be the same for these two directions.

    TCP has MSS

    There is such a thing as the maximum TCP Segment Size (MSS), which defines the maximum amount of data that a host wants to receive in a single TCP / IP datagram.

    Moreover, this TCP / IP datagram may be fragmented at the IP level.

    The MSS value is sent as an option to the TCP header only in the TCP SYN segment. Each side on a TCP connection reports its MSS value to the other side. The host sender is required to limit the size of the data in a single TCP segment to a value less than or equal to the MSS reported by the recipient host.

    The mechanism of the MSS is as follows: when creating a TCP connection, the machine determines the size of the outgoing interface buffer and the MTU of this interface. Then these two numbers are compared and the smallest is selected. Here it should be noted that the MTU is chosen by the number according to the formula MTU minus 40 bytes, to account for TCP and IP headers. Then the selected number is compared with the size of the MSS transmitted by the receiving party, and the smallest value is again selected. MSS operation example:

    1. Machine A compares the size of its interface buffer (16 Kbytes) with the MTU value of this interface (1500–40 = 1460 bytes) and uses the smallest number as MSS when sending it to machine B.
    2. Machine B takes the MSS value of Machine A (1460) and compares it with the MTU value of its outgoing interface (4462 - 40 = 4422 bytes).
    3. Machine B chooses the smallest of the resulting values ​​(1460) as the MSS value when sending TCP segments to machine A.
    4. Machine B compares the size of its interface buffer (8 KB) with the MTU value of this interface (4462-40 = 4422 bytes) and uses the smallest number as the MSS when sent to machine A.
    5. Machine A takes the MSS value of Machine B (4422) and compares it with the MTU value of its outgoing interface (1500 - 40 = 1460 bytes).
    6. Machine A chooses the smallest of the resulting values ​​(1460) as the MSS value when sending TCP segments to machine B.

    Thus, the MSS on both sides is set to 1460 bytes, this is the most common situation.

      Then, that on ip works not only tcp, but also udp, and icmp. Each protocol has its own limit.

      And networks are not just ethernet.

        For example, a tcp segment using ethernet2 transmission technology can be as much as 1500 bytes

        Problems start around here. 1,500 is a completely standard packet size (any network-level protocol, not necessarily ip), which fits into an e-net frame . The length of the TiSiPi segment is even smaller, the quite usual value is 1,460, just so that the final packet (with TiSiPi and IP) headers can fit into 1,500 octets . The standard size, unless otherwise agreed, is altogether 536 (as indicated in section 4.2.2.6 of the RFC 1122 , it is a pity that there is no translation of the RFC 6691 (English) ).

        In principle, the size of the segment is chosen by the OS network stack, just taking into account the maximum transmission parameters, because, as in Ethernet, it can prolapit 9,000 octets, and not only Ethernet is in this world.

        There is a partition into 1500 bytes at the transport level, why is the size of 65535 bytes specified, if the transmitted pieces are 1500 bytes in size?

        This is the maximum size. The maximum size of the TiCiPi segment is equal to the same value , by the way, since in both cases, 16-bit fields are used. And if you look very strictly, then the maximum size TiSiP segment cannot be sent using the IP protocol at all! How did that happen? Yes, just decided that 16 bits will be enough here and there. Which is typical, not mistaken, enough with a margin.

        It is important to understand that the whole matryoshka layers of the network stack was originally conceived for the rigid separation of issues solved in different layers and fundamentally implies the independence of protocols of different levels. And when such questions arise, the first thing that makes sense is to think about what it will be if, instead of Protocol A, an unknown protocol B is used at some level. Therefore, the theoretical constraints at each level are different and the agreement of real parameters is proceeding from real conditions For example, for IP on top of Infiniband, a typical limitation on the packet size is 2,044 octets (I propose to calculate the size of the TiCiP segment independently).

        But even more interesting is the fact that the seemingly unattainable maxima on the wire sometimes find unexpected use. For example, even despite the fact that in Ethernet more than 9,000 will not prolazit, it is quite realistic to receive a packet of about 64K in length, containing a TiCiPi segment inside with a value just as close to 64K! Everything is due to hardware (sometimes driver) data acquisition acceleration (for a ten-gigabit network the phenomenon is ubiquitous) - the card removes a set of “normal” length packets for one connection from the wire and repacks them into one such mega-packet. As a result, the OS doesn’t see the original “pea” at all, one 64K long packet came for it, it will continue to work with it. Maybe send the same mega-packet to the outside, and the network card will perform the actual segmentation to the desired length.

        An example of the practically natural use of MTU in 64K is the loopback interface, by default in Linux it is just such a MTU (and you can increase it to 2GB! Only this is already useless for common upper-level protocols), and it will be in such pieces that vishyushny stream, packing on the way in aypishny bags (plus or minus an overhead charge for headings).