0

I was trying out the effects of setting different IP_MTU_DISCOVER values using setsockopt() on udp packet fragmentation and found out (from man page of ip(7)) that i need to set it's value to IP_PMTUDISC_WANT or IP_PMTUDISC_DONT to turn off "don't fragment" flag. However, i get socket.error: [Errno 90] Message too long when i try to send the packet.

import IN, socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

hostname = 'localhost'
s.connect((hostname, 1060))

s.setsockopt(socket.IPPROTO_IP, IN.IP_MTU_DISCOVER, IN.IP_PMTUDISC_DONT)
mtu = s.getsockopt(socket.IPPROTO_IP, IN.IP_MTU)

print 'MTU:', mtu
s.send('.' * (mtu + 1))
print 'Big packet sent'

Thank you

1 Answer 1

3

Let's first do a recap of how PMTU works for UDP.

  1. An IP endpoint starts with a given MTU, usually the MTU of it's directly connected link.
  2. When sending packets the endpoint always sets the DF bit.
  3. If a transit router decides it cannot send out the packet without fragmentating the packet, it will return an ICMP Destination Unreachable packet with error code 4 and the next-hop MTU.
  4. The IP endpoint receives the ICMP unreachable and adapts its PMTU.
  5. The IP endpoint decides what to do with the original packet (retransmit, signal app layer, ...).

Very important to note here is that PMTU does not happen automatically. There is no built-in probe packet that will find out the MTU before you (the application) starts sending actual data.

So Linux controls this (for datagrams) using the following flags:

  • IP_PMTUDISC_WANT Performs PMTU as described above. If the application sends a packet that is too large for the known MTU, the socket layer will fragment it. Outgoing packets (including fragments) will have the DF bit set.
  • IP_PMTUDISC_DONT Don't do PMTU discovery.
  • IP_PMTUDISC_DO Do PMTU discovery. If the application sends a packet that is too large for the known MTU, send an error to the application.
  • IP_PMTUDISC_PROBE Sets the DF bit to do PMTU discovery but ignores the currently learned MTU. So if the application sends a too large packet, it will try to send it out anyway. This is useful to send a probe from time to time to see if the PMTU hasn't increased.

Now one part of notice is that IP_PMTUDISC_DONT does not specify what to do if the packet is actually larger than your current MTU, i.e. the one of your direct link. So most likely it leaves this choice up to the interface that actually has to send out the packet. Most interfaces should actually fragment the packet as the DF bit is not sent. However, you use the link-local interface which is a usually a software interface with a bit less capabilities. It is possible that on your distribution this does not support fragmentation and therefore sends the error. This makes sense, take this output from my machine:

In [6]: s.getsockopt(socket.IPPROTO_IP, 14) #14 = IP_MTU, just wasn't in my python lib.
Out[6]: 16436

This shows that the MTU for the link-local interface is quite huge in network terms, so why should it bother supporting fragmentation to begin with. That being said, on my system this actually worked fine.

2
  • I get the same error when I replace IP_PMTUDISC_DONT with IP_PMTUDISC_WANT, why is that ? It should fragment the packet right ?
    – Apoorv
    Oct 23, 2014 at 9:42
  • Have you read my whole answer? At the end I specify what could go wrong with fragmentation independently of that setting.
    – KillianDS
    Oct 23, 2014 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.