Hi,

I just added a second network interface. The problem that I found was that unless the network interfaces were on different sub-nets then lwIP would send the response to the first interface. This behaviour may be OK for some applications but in my IEEE15888 application this was a problem. I solved it by keeping a copy of the IP addresses received on each network interface. Then searching the list for the destination IP address on the way out:

/******************************************************************************
* Function Name: ipGetNetIf
* Description : Function to get a pointer to an lwIP network interface based
*                on the destination IP address
* Arguments    : IN  dest - Pointer to the destination IP address
* Return Value : Pointer to the interface or NULL if not found
******************************************************************************/
struct netif * ipGetNetIf(struct ip_addr *dest)
{
    struct netif *pResult = NULL;
    PRTEIP  pEtherCList = gpEtherC;
#ifdef _HARDWIRE_BROADCAST_PORT_
    /* Hardwire broadcast messages to port0 for PTP testing purposes */
    if (*((PIPADR)dest) == INADDR_BROADCAST)
    {
        PRTEIP pEtherC0 = ipFindNetIf(&gpEtherC, "\\\\.\\ieee15888:0");
        if (pEtherC0)
        {
            return &pEtherC0->ipNetIf;
        }
    }
#endif
    /* For each network interface */
    while (pEtherCList)
    {
        /* Make sure that the cache is enabled */
        if (pEtherCList->bfIpCacheEnabled)
        {
            /* Look for the entry */
            if (icSearch(pEtherCList->pIpCache, (PIPADR)dest))
            {
                pResult = &pEtherCList->ipNetIf;
                break;
            }
        }
        pEtherCList = pEtherCList->pNext;
    }
    return pResult;
}
/******************************************************************************
End of function ipGetNetIf
******************************************************************************/

I hope this helps.

Cheers,

Adam.

On 09/01/2014 02:30, Vadim Vaynerman wrote:
Hello All,

I was wondering if there is any information about using 2 MACs concurrently for TCP/IP work within the LwIP framework. My architecture is ARM Cortex A9 - Xilinx Zynq, and I've got it working nicely with one MAC and a single IP address... Need to add a second, separate, link. Has anything like this been done, or are there any suggestions on how to go about this from experienced users?

Thanks,
Vadim


_______________________________________________
lwip-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/lwip-users

/******************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only 
* intended for use with Renesas products. No other uses are authorized. 
* This software is owned by Renesas Electronics Corporation and is protected 
* under all applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
* THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
* LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 
* AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS 
* ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE 
* FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
* ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software
* and to discontinue the availability of this software. By using this software,
* you agree to the additional terms and conditions found by accessing the 
* following link:
* http://www.renesas.com/disclaimer
*******************************************************************************
* Copyright (C) 2011 Renesas Electronics Corporation. All rights reserved.
*******************************************************************************
* File Name    : ipCache.c
* Version      : 1.00
* Description  : IPV4 address cache functions
******************************************************************************
* History : DD.MM.YYYY Version Description
*         : 01.02.2011 1.00    First Release
******************************************************************************/

/******************************************************************************
Includes   <System Includes> , "Project Includes"
******************************************************************************/

#include <stdlib.h>
#include <string.h>
#include "ipCache.h"
#include "malloc.h"

/******************************************************************************
Typedefs
******************************************************************************/

typedef struct _IPLST
{
    /* The Count for Least Recently Used replacemet */
    uint32_t    uiLRU;
    /* The IP address, 0 for invalid */
    IPADR       ipAddress;
} IPLST,
*PIPLST;

typedef struct _IPCACHE
{
    /* The total number of entries */
    uint32_t    uiCacheSize;
    /* The array of Ip entries */
    IPLST       ipList;
} IPCACHE;

/******************************************************************************
Private Function Prototypes
******************************************************************************/

static PIPLST ipFind(PIPCACHE pIpCache, PIPADR pIP);
static PIPLST ipGetEntry(PIPCACHE pIpCache);

/******************************************************************************
Public Functions
******************************************************************************/

/******************************************************************************
* Function Name: icCreate
* Description  : Function to create an IP address cache
* Arguments    : IN  uiCacheSize - The number of entries to keep in the cache
* Return Value : Pointer to the cache or NULL on error
******************************************************************************/
PIPCACHE icCreate(uint32_t uiCacheSize)
{
    size_t      stSize = (uiCacheSize * sizeof(IPLST)) + sizeof(IPCACHE);
    PIPCACHE    pIpCache = exMalloc(HEAP_INTERNAL_FAST, stSize);
    if (pIpCache)
    {
        memset(pIpCache, 0U, stSize);
        pIpCache->uiCacheSize = uiCacheSize;
    }
    return pIpCache;
}
/******************************************************************************
End of function icCreate
******************************************************************************/

/******************************************************************************
* Function Name: icDestroy
* Description  : Function to destroy an IP address cache
* Arguments    : IN  pIpCache - Pointer to the IP address cache
* Return Value : none
******************************************************************************/
void icDestroy(PIPCACHE pIpCache)
{
    exFree(HEAP_INTERNAL_FAST, pIpCache);
}
/******************************************************************************
End of function icDestroy
******************************************************************************/

/******************************************************************************
* Function Name: icAdd
* Description  : Function to add an address to the cache
* Arguments    : IN  pIpCache - Pointer to the IP address cache
*                IN  pIP - Pointer to the IP address to add
* Return Value : none
******************************************************************************/
void icAdd(PIPCACHE pIpCache, PIPADR pIP)
{
    if (pIpCache)
    {
        /* Look to see if it is in the list */
        PIPLST  pIpEntry = ipFind(pIpCache, pIP);
        if (!pIpEntry)
        {
            /* Get a new entry */
            pIpEntry = ipGetEntry(pIpCache);
            /* Add the IP address to the cache entry */
            pIpEntry->ipAddress = *pIP;
            pIpEntry->uiLRU = 0U;
        }
    }
}
/******************************************************************************
End of function icAdd
******************************************************************************/

/******************************************************************************
* Function Name: icRemove
* Description  : Function to remove an address from the cache
* Arguments    : IN  pIpCache - Pointer to the IP address cache
*                IN  pIP - Pointer to the IP address to remove
* Return Value : none
******************************************************************************/
void icRemove(PIPCACHE pIpCache, PIPADR pIP)
{
    if (pIpCache)
    {
        PIPLST  pIpEntry = &pIpCache->ipList;
        PIPLST  pIpEnd = pIpEntry + pIpCache->uiCacheSize;
        IPADR   ipAddress = *pIP;
        while (pIpEntry < pIpEnd)
        {
            if (pIpEntry->ipAddress == ipAddress)
            {
                pIpEntry->ipAddress = 0U;
                return;
            }
            pIpEntry++;
        }
    }
}
/******************************************************************************
End of function icRemove
******************************************************************************/

/******************************************************************************
* Function Name: icPurge
* Description  : Function to purge the cache
* Arguments    : IN  pIpCache - Pointer to the IP address cache
* Return Value : none
******************************************************************************/
void icPurge(PIPCACHE pIpCache)
{
    if (pIpCache)
    {
        PIPLST  pIpEntry = &pIpCache->ipList;
        PIPLST  pIpEnd = pIpEntry + pIpCache->uiCacheSize;
        while (pIpEntry < pIpEnd)
        {
            pIpEntry->ipAddress = 0U;
            pIpEntry++;
        }
    }
}
/******************************************************************************
End of function icPurge
******************************************************************************/

/******************************************************************************
* Function Name: icSearch
* Description  : Function to search the cache
* Arguments    : IN  pIpCache - Pointer to the IP address cache
*                IN  pIP - Pointer to the IP address to search
* Return Value : true if the entry is found
******************************************************************************/
_Bool icSearch(PIPCACHE pIpCache, PIPADR pIP)
{
    if (pIpCache)
    {
        PIPLST  pIpEntry = &pIpCache->ipList;
        PIPLST  pIpEnd = pIpEntry + pIpCache->uiCacheSize;
        IPADR   ipAddress = *pIP;
        while (pIpEntry < pIpEnd)
        {
            if (pIpEntry->ipAddress == ipAddress)
            {
                return true;
            }
            pIpEntry++;
        }
    }
    return false;
}
/******************************************************************************
End of function icSearch
******************************************************************************/

/******************************************************************************
Private Functions
******************************************************************************/

/******************************************************************************
* Function Name: ipFind
* Description  : Function to find an entry in the cache
* Arguments    : IN  pIpCache - Pointer to the IP address cache
*                IN  pIP - Pointer to the IP address to search
* Return Value : Pointer to the entry or NULL if not found
******************************************************************************/
static PIPLST ipFind(PIPCACHE pIpCache, PIPADR pIP)
{
    PIPLST  pIpEntry = &pIpCache->ipList;
    PIPLST  pIpEnd = pIpEntry + pIpCache->uiCacheSize;
    IPADR   ipAddress = *pIP;
    while (pIpEntry < pIpEnd)
    {
        if (pIpEntry->ipAddress == ipAddress)
        {
            pIpEntry->uiLRU = 0U;
            return pIpEntry;
        }
        pIpEntry->uiLRU++;
        pIpEntry++;
    }
    return NULL;
}
/******************************************************************************
End of function ipFind
******************************************************************************/

/******************************************************************************
* Function Name: ipGetEntry
* Description  : Function to find an entry in the cache
* Arguments    : IN  pIpCache - Pointer to the IP address cache
* Return Value : Pointer to the entry
******************************************************************************/
static PIPLST ipGetEntry(PIPCACHE pIpCache)
{
    PIPLST      pIpEntry = &pIpCache->ipList;
    PIPLST      pResult = pIpEntry;
    PIPLST      pIpEnd = pIpEntry + pIpCache->uiCacheSize;
    uint32_t    uiUsedCount = 0U;
    while (pIpEntry < pIpEnd)
    {
        /* Use the first invalid entry found */
        if (!pIpEntry->ipAddress)
        {
            pResult = pIpEntry;
            break;
        }
        /* Select from the least recently used */
        if (pIpEntry->uiLRU > uiUsedCount)
        {
            pIpEntry->uiLRU = uiUsedCount;
            pResult = pIpEntry;
        }
        pIpEntry++;
    }
    return pResult;
}
/******************************************************************************
End of function ipGetEntry
******************************************************************************/

/******************************************************************************
End of File
******************************************************************************/
/******************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only 
* intended for use with Renesas products. No other uses are authorized. 
* This software is owned by Renesas Electronics Corporation and is protected 
* under all applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
* THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
* LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 
* AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS 
* ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE 
* FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
* ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software
* and to discontinue the availability of this software. By using this software,
* you agree to the additional terms and conditions found by accessing the 
* following link:
* http://www.renesas.com/disclaimer
*******************************************************************************
* Copyright (C) 2011 Renesas Electronics Corporation. All rights reserved.
*******************************************************************************
* File Name    : ipCache.h
* Version      : 1.00
* Description  : IPV4 address cache functions
******************************************************************************
* History : DD.MM.YYYY Version Description
*         : 01.02.2011 1.00    First Release
******************************************************************************/

#ifndef IPCACHE_FILE_H
#define IPCACHE_FILE_H

#ifdef __cplusplus
extern "C" {
#endif

/******************************************************************************
Includes   <System Includes> , "Project Includes"
******************************************************************************/

#include "r_typedefs.h"

/******************************************************************************
Typedef definitions
******************************************************************************/

typedef uint32_t IPADR, *PIPADR;
typedef struct _IPCACHE *PIPCACHE;

/******************************************************************************
Functions Prototypes
******************************************************************************/

/******************************************************************************
* Function Name: icCreate
* Description  : Function to create an IP address cache
* Arguments    : IN  uiCacheSize - The number of entries to keep in the cache
* Return Value : Pointer to the cache or NULL on error
******************************************************************************/

extern  PIPCACHE icCreate(uint32_t uiCacheSize);

/******************************************************************************
* Function Name: icDestroy
* Description  : Function to destroy an IP address cache
* Arguments    : IN  pIpCache - Pointer to the IP address cache
* Return Value : none
******************************************************************************/

extern  void icDestroy(PIPCACHE pIpCache);

/******************************************************************************
* Function Name: icAdd
* Description  : Function to add an address to the cache
* Arguments    : IN  pIpCache - Pointer to the IP address cache
*                IN  pIP - Pointer to the IP address to add
* Return Value : none
******************************************************************************/

extern  void icAdd(PIPCACHE pIpCache, PIPADR pIP);

/******************************************************************************
* Function Name: icRemove
* Description  : Function to remove an address from the cache
* Arguments    : IN  pIpCache - Pointer to the IP address cache
*                IN  pIP - Pointer to the IP address to remove
* Return Value : none
******************************************************************************/

extern  void icRemove(PIPCACHE pIpCache, PIPADR pIP);

/******************************************************************************
* Function Name: icPurge
* Description  : Function to purge the cache
* Arguments    : IN  pIpCache - Pointer to the IP address cache
* Return Value : none
******************************************************************************/

extern  void icPurge(PIPCACHE pIpCache);

/******************************************************************************
* Function Name: icSearch
* Description  : Function to search the cache
* Arguments    : IN  pIpCache - Pointer to the IP address cache
*                IN  pIP - Pointer to the IP address to search
* Return Value : true if the entry is found
******************************************************************************/

extern _Bool icSearch(PIPCACHE pIpCache, PIPADR pIP);

#ifdef __cplusplus
}
#endif

#endif /* IPCACHE_FILE_H */

/******************************************************************************
End of file
******************************************************************************/
_______________________________________________
lwip-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to