This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

NDK hang on IP address change with active UDP connections

Hi,

we found a problem with NDK when changing IP address if there's an open UDP socket. In particular the stack hangs in a call to SockCleanPcb(SOCKPROT_UDP…), in SPIpNet() inside netsrv.c

To change IP address we follow this procedure:

/* get the current static IP entry */
CfgGetEntry(0, CFGTAG_IPNET, PHY_MAC_INTERFACE_INDEX, 1, &hCfgIpAddr);

 /* remove the current static IP entry */
CfgRemoveEntry(0, hCfgIpAddr);

 // Add the address to interface 1
CfgAddEntry(0, CFGTAG_IPNET, PHY_MAC_INTERFACE_INDEX, 0, sizeof(CI_IPNET), (UINT8 *) &NA, 0);

We fixed the problem adding the changes below in red to SPIpNet():

// Else if this is a "remove", remove the entry
else if( Op == CFGOP_REMOVE )
  {

        // If no network, return "pass"
        if( !pi->hBind )
            return(0);

        // Remove the network      MOVED AFTER the calls to SockCleanPcb()
        //NtRemoveNetwork( pi->hBind );
        //pi->hBind = 0;

        /* BUG FIX SDSCM00014560
          *  When an IP address is modified we need to close the sockets of all existing
          *  applications. */

        {

            SockCleanPcb (SOCKPROT_TCP, pi->IPAddr);
            SockCleanPcb (SOCKPROT_UDP, pi->IPAddr);
            SockCleanPcb (SOCKPROT_RAW, pi->IPAddr);
        }

        NtRemoveNetwork( pi->hBind );
        pi->hBind = 0;                           

        // Notify NetCtrl
        NC_IPUpdate( pi->IPAddr, Item, 0 );

    }

QUESTION: does it make sense to you? Can you please confirm that this fix is correct?

Best regards
Massimo

  • Hi Massimo,

    A colleague (NDK developer) and I reviewed your code and did not find any immediate problem with the fix.  As always; testing is recommend to ensure there are no unexpected side-effects on the customers application.  

    What version of the NDK is the customer developing on?  I would like to file a CQ for this issue.

    Thanks,

    --Emmanuel

  • Emmanuel,


    I apologize for the slow answer.

    The fix was tested on a dm643x, with an old NDK version. 2.03 if I'm right.  But if you compare the source, this function is identical in NDK 2.23. Unfortunately I couldn't find the time to generate a test case on 2.23, to verify it.

    Best regards

    Massimo

  • Hi Massimo,

    The described bug still happens with ndk_2_24_03_35. It seems to me, the bugfix did not go into your official sources, or it has not really been fixed. NtRemoveNetwork() is still called before SockCleanPcb(SOCKPROT_UDP, pi->IPAddr) in netsrv.c and this makes SockClose() loop infinitely in the while()-loop because IGMPLeave returns with error before getting a chance for removing from the multicast list.

    The bug does not happen if the multicast list ps->pMcastList in sock.c is empty.


    P.S.: I don't know if it's a good idea to reopen this issue.

  • I just took a look at this. Massimo is not on the NDK team so he wouldn't have been able to add this fix into the actual product.

    I'm not sure a bug was ever file (couldn't find one) so I filed one just now to track this:

    SDOCM00121144 changing IP address while open sockets exist causes hang

    Steve