Why PacketTunnelProvider UDP readHandler truncate packet to 1472 bytes all times?

In my scenario, my server sending down 3004 packet. Because of MTU, the ip layer fragement my packet into 3 frame.


This is what I see on Wireshark:


Frame 1: payload: 0-1479 (1480 bytes)

Frame 2: payload: 1480-2959 (1480 bytes)

Frame 3: payload: 2960-3011 (52 bytes)


The frame 1 has 8 bytes UDP Header.


The issue happening on my read handler function. The packet that I receive only the first frame which is 1472 bytes (1480 bytes - 8 bytes udp header)


So whenever I send data bigger than 1500, my packet always get truncated to 1472.

Also I could not find the remaining of frame (Frame 2 and Frame 3) being received on read handler at all. Is there a set in Network Extension to prevent this from happening ?


I try to set MTU to 4000 (for example) on network settings but it still happening.


Thanks


EDIT:


I try to capture packet on iPhone as well. According to my pcap file, the data captured and assambled correctly. I received correct size of UDP packet on pcap file. But my read handler still only give me 1472 bytes size packet.


This is the frame that being assembled on iPhone


Frame 1: payload: 0-1471 (1472 bytes)

Frame 2: payload: 1472-1479 (8 bytes)

Frame 3: payload: 1480-2951 (1472 bytes)

Frame 4: payload: 2952-2959 (8 bytes)

Frame 5: payload: 2960-3011 (52 bytes)

Which read handler are you talking about it? Packet tunnel providers typically have two:

  • the handler that receives packets from the system that are to be put into the tunnel (that is, the block you pass to the

    -readPacketsWithCompletionHandler:
    method of the
    packetFlow
    property of the NEPacketTunnelProvider)
  • the handler that receives packets from the tunnel that are to be injected into the system (that is, the block you pass to the

    -setReadHandler:maxDatagrams:
    method of the NWUDPSession you created via NEProvider’s
    -createUDPSessionToEndpoint:fromEndpoint:
    method)

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

What does your read handler function look like?


Because it's a really, really common mistake for people to write those incorrectly assuming that you get the entire packet at once instead of possibly across multiple reads or callbacks.

Sorry for ambiguity.


The handler that I was talking about was setReadHandler from NWUDPSession.


Thanks

This is my basic handle code.


self.session?.setReadHandler({ (datagrams: [NSData]?, error: NSError?) -> Void in
           
            if let datagramArray = datagrams{
               
                var ipPacketArray = [NSData]()
                var protocolArray = [NSNumber]()
               
                for datagram in datagramArray{
                    ipPacketArray.append(datagram)
                    protocolArray.append(NSNumber(int: AF_INET))
                }
               
                self.packetFlow.writePackets(ipPacketArray, withProtocols:protocolArray);
            }
           
            }, maxDatagrams: NSIntegerMax)



I print every datagram, however I couldn't found the remain of packet that has been truncated.

The handler that I was talking about was setReadHandler from NWUDPSession.

NWUDPSession definitely has a ‘max payload size’ concept for received data. This is closely related to, but not exactly the same as, the

maximumDatagramLength
property for the send side. I’m a little hazy on the details and there’s no documentation about this at all )-: I’m going to recommend that you open a DTS tech support incident, which will give me the time to look into this in more depth.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Why PacketTunnelProvider UDP readHandler truncate packet to 1472 bytes all times?
 
 
Q