I wanted to ask something,
When an application running on our browser doesn't want its data packet to get fragmented, it uses Do Not Fragment bit, to signify that this packet must not be fragmented, which could be in cases like while sharing tokens or passwords or key etc, i.e in case of security.
But since Do Not Fragment is a field in Ip header which works on network layer and there is Transport layer in between application layer and network layer, so how does transport layer shares this information from application layer to network layer that the incoming datagram must not be fragmented? Is there a similar field on transport layer? Or when is it decided if a packet should be fragmented or not?
I am a little confused about it, can someone explain? Thanks in advance.
You're right, the Transport Layer is "mediating" between the Application Layer which chooses to "not fragment" the data, and the IP Layer which actually sets the DF information on the packet. This "mediation" is done by the socket - the application sets the socket options or flags in the transport layer to request the DF behavior. For example, in C++ you do it with the setsockopt() call using the IP_DONTFRAG option:
int val = 1;
setsockopt(sd, IPPROTO_IP, IP_DONTFRAG, &val, sizeof(val));
You can read more about this flag here.
The IP layer examines the socket options or flags that were set by the application through the transport layer. Based on the information received from the transport layer, the IP layer then sets the DF bit in the IP header of the outgoing packet to 1 (indicating "Do Not Fragment") if the DF behavior is requested. If the application did not request the DF bit to be set, the IP layer leaves the DF bit as 0.