title: Sending don't fragment UDP packets at the server and receiving fragmented packets at the client
body: <p>I've created a program in C that sends data with UDP packets.</p>
  
  <p>Socket is made don't fragment using</p>
  
  <pre><code>int optval = IP_PMTUDISC_DO;
  if(setsockopt(sd,IPPROTO_IP,IP_MTU_DISCOVER,&amp;optval,sizeof(int))!=0)
  {
      perror("setsocketopt()");
      return 0;
  }
  </code></pre>
  
  <p>Checking with TSHARK at the server (debian 8 KVM virtualizied), for all packets don't fragment has been set:</p>
  
  <p><a href="https://i.stack.imgur.com/qsgZu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qsgZu.png" alt="server sniffier"></a></p>
  
  <p>But at the client, large packets receiving fragmented!!</p>
  
  <p><a href="https://i.stack.imgur.com/1zQNA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1zQNA.png" alt="client side wireshark"></a></p>
  
  <p>Then I figured something more wired. The IPv4 ID field has been set to 0!</p>
  
  <p>I thought it might be because of the don't fragment effect (because no packet is going to be fragmented).</p>
  
  <p>Then I started Openvpn program and sniffed its packets at the server but the packets had IPv4 ID != 0 while don't fragment was set.</p>
  
  <p>Do you guys have any idea that why is this happening to me?!</p>
  
  <p>Edit: Here is another sample of a large packet at server copy and pasted from tshark result. </p>
  
  <pre><code>Frame 1049: 1514 bytes on wire (12112 bits), 1514 bytes captured (12112 bits) on interface 0
  Ethernet II, Src: server_mac, Dst: gateway_mac
  Internet Protocol Version 4, Src: server_ip, Dst: client_ip
  Version: 4
  Header Length: 20 bytes
  Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00: Not-ECT (Not ECN-Capable Transport))
      0000 00.. = Differentiated Services Codepoint: Default (0x00)
      .... ..00 = Explicit Congestion Notification: Not-ECT (Not ECN-Capable Transport) (0x00)
  Total Length: 1500
  Identification: 0x0000 (0)
  Flags: 0x02 (Don't Fragment)
      0... .... = Reserved bit: Not set
      .1.. .... = Don't fragment: Set
      ..0. .... = More fragments: Not set
  Fragment offset: 0
  Time to live: 64
  Protocol: UDP (17)
  Header checksum: 0xa52d [validation disabled]
      [Good: False]
      [Bad: False]
  Source: server_ip
  Destination: client_ip
  [Source GeoIP: Unknown]
  [Destination GeoIP: Unknown]
  User Datagram Protocol, Src Port: 7554 (7554), Dst Port: 45376 (45376)
  Data (1472 bytes)   
  </code></pre>
  
  <p>Like you see, don't fragment has been set, while all packets larger than PMTU are receiving fragmented to client side.</p>
  
  <p>This is a packet trace example of openvpn on the same server. like you see it at least has IPv4 ID calculated!</p>
  
  <pre><code>Frame 3749: 1455 bytes on wire (11640 bits), 1455 bytes captured (11640 bits) on interface 0
  Ethernet II, Src: SERVER_MAC, Dst: GATEWAY_MAC
  Internet Protocol Version 4, Src: SERVER_IP, Dst: CLIENT_IP
  Version: 4
  Header Length: 20 bytes
  Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00: Not-ECT (Not ECN-Capable Transport))
      0000 00.. = Differentiated Services Codepoint: Default (0x00)
      .... ..00 = Explicit Congestion Notification: Not-ECT (Not ECN-Capable Transport) (0x00)
  Total Length: 1441
  Identification: 0xcc96 (52374)
  Flags: 0x02 (Don't Fragment)
      0... .... = Reserved bit: Not set
      .1.. .... = Don't fragment: Set
      ..0. .... = More fragments: Not set
  Fragment offset: 0
  Time to live: 64
  Protocol: UDP (17)
  Header checksum: 0xe252 [validation disabled]
      [Good: False]
      [Bad: False]
  Source: SERVER_IP
  Destination: CLIENT_IP
  [Source GeoIP: Unknown]
  [Destination GeoIP: Unknown]
  User Datagram Protocol, Src Port: 19234 (19234), Dst Port: 46921 (46921)
  Data (1413 bytes)
  </code></pre>