mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-10-05 22:29:49 +00:00
Create netif_input function that decides according to netif flags where to pass an incoming packet.
Allow to pass a NULL pointer to netif_add() input function - if so, use the function mentioned above as input function.
This commit is contained in:
parent
5f9c944da4
commit
4b67c582f6
@ -172,6 +172,21 @@ netif_init(void)
|
||||
#endif /* LWIP_HAVE_LOOPIF */
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass a received packet for input processing with
|
||||
* ethernet_input or ip_input depending on netif flags.
|
||||
*/
|
||||
static err_t
|
||||
netif_input(struct pbuf *p, struct netif *inp)
|
||||
{
|
||||
#if LWIP_ETHERNET
|
||||
if (inp->flags & (NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET)) {
|
||||
return ethernet_input(p, inp);
|
||||
} else
|
||||
#endif /* LWIP_ETHERNET */
|
||||
return ip_input(p, inp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup netif
|
||||
* Add a network interface to the list of lwIP netifs.
|
||||
@ -183,7 +198,14 @@ netif_init(void)
|
||||
* @param state opaque data passed to the new netif
|
||||
* @param init callback function that initializes the interface
|
||||
* @param input callback function that is called to pass
|
||||
* ingress packets up in the protocol layer stack.
|
||||
* ingress packets up in the protocol layer stack. If a NULL
|
||||
* pointer is supplied, a default input function is used
|
||||
* that uses netif flags NETIF_FLAG_ETHARP and NETIF_FLAG_ETHERNET
|
||||
* to decide whether to pass to ethernet_input() or ip_input(). Since
|
||||
* the flags are usually managed by the one implementing the ethernet
|
||||
* driver, the end user does not have to worry about choosing the correct
|
||||
* one here. In other words, this only works when the netif driver is
|
||||
* implemented correctly!
|
||||
*
|
||||
* @return netif, or NULL if failed.
|
||||
*/
|
||||
@ -254,7 +276,11 @@ netif_add(struct netif *netif,
|
||||
/* remember netif specific state information data */
|
||||
netif->state = state;
|
||||
netif->num = netif_num++;
|
||||
netif->input = input;
|
||||
if(input != NULL) {
|
||||
netif->input = input;
|
||||
} else {
|
||||
netif->input = netif_input;
|
||||
}
|
||||
NETIF_SET_HWADDRHINT(netif, NULL);
|
||||
#if ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS
|
||||
netif->loop_cnt_current = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user