Networking: Modify event list handling: Now there are two event lists each device structure: (1) One is for ARP and ICMP data related evetns, the other is for device related events. Callback allocation/free routines no accept a device paramter as well as a list: If the device paramter is added, then the callback goes into both the connection-related liast AND the device event list. Thus each socket type can received both custom data-related events as well as common device related events.

This commit is contained in:
Gregory Nutt 2015-05-28 12:01:38 -06:00
parent d3351eec64
commit e81f279315
20 changed files with 250 additions and 77 deletions

View file

@ -196,12 +196,24 @@ struct net_driver_s
*
* Network device event handlers are retained in a 'list' and are called
* for events specified in the flags set within struct devif_callback_s.
* The following network event flags may be specified:
*
* NETDEV_DOWN - The network is down
* There are two lists associated with each device:
*
* 1) d_pktcb - For connection/port oriented events for certain
* socket-less packet transfers. There events include:
*
* ICMP data receipt: ICMP_NEWDATA, ICMPv6_NEWDATA
* ICMP ECHO replies: ICMP_ECHOREPLY, ICMPv6_ECHOREPLY
* Driver Tx poll events: ARP_POLL, ICMP_POLL. ICMPv6_POLL
*
* 2) d_devcb - For non-data, device related events that apply to all
* transfers or connections involving this device:
*
* NETDEV_DOWN - The network is down
*/
FAR struct devif_callback_s *d_callbacks;
FAR struct devif_callback_s *d_conncb;
FAR struct devif_callback_s *d_devcb;
/* Driver callbacks */

View file

@ -87,8 +87,10 @@
/* Allocate a new ARP data callback */
#define arp_callback_alloc(dev) devif_callback_alloc(&(dev)->d_callbacks)
#define arp_callback_free(dev,cb) devif_callback_free(cb, &(dev)->d_callbacks)
#define arp_callback_alloc(dev) \
devif_callback_alloc(dev, &(dev)->d_conncb)
#define arp_callback_free(dev,cb) \
devif_callback_free(dev, cb, &(dev)->d_conncb)
/****************************************************************************
* Public Types

View file

@ -83,7 +83,7 @@ int arp_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback)
/* Perform the ARP callbacks */
(void)devif_callback_execute(dev, NULL, ARP_POLL, dev->d_callbacks);
(void)devif_conn_event(dev, NULL, ARP_POLL, dev->d_conncb);
/* Call back into the driver */

View file

@ -214,22 +214,26 @@
* Public Type Definitions
****************************************************************************/
/* Describes a device interface callback
/* Describes a connection/device event callback interface
*
* flink - Supports a singly linked list
* nxtconn - Supports a singly linked list that supports connection
* specific event handlers.
* nxtdev - Supports a singly linked list that supports device specific
* event handlers
* event - Provides the address of the callback function entry point.
* pvconn is a pointer to one of struct tcp_conn_s or struct
* udp_conn_s.
* pvconn is a pointer to a connection-specific datat structure
* such as struct tcp_conn_s or struct udp_conn_s.
* priv - Holds a reference to socket layer specific data that will
* provided
* flags - Set by the socket layer to inform the lower layer which flags
* were and were not handled by the callback.
* are and are not handled by the callback.
*/
struct net_driver_s; /* Forward reference */
struct devif_callback_s
{
FAR struct devif_callback_s *flink;
FAR struct devif_callback_s *nxtconn;
FAR struct devif_callback_s *nxtdev;
uint16_t (*event)(FAR struct net_driver_s *dev, FAR void *pvconn,
FAR void *pvpriv, uint16_t flags);
FAR void *priv;
@ -282,8 +286,6 @@ void devif_initialize(void);
*
* Description:
* Configure the pre-allocated callback structures into a free list.
* This is called internally as part of uIP initialization and should not
* be accessed from the application or socket layer.
*
* Assumptions:
* This function is called with interrupts disabled.
@ -297,39 +299,36 @@ void devif_callback_init(void);
*
* Description:
* Allocate a callback container from the free list.
* This is called internally as part of uIP initialization and should not
* be accessed from the application or socket layer.
*
* Assumptions:
* This function is called with interrupts disabled.
*
****************************************************************************/
FAR struct devif_callback_s *devif_callback_alloc(FAR struct devif_callback_s **list);
FAR struct devif_callback_s *
devif_callback_alloc(FAR struct net_driver_s *dev,
FAR struct devif_callback_s **list);
/****************************************************************************
* Function: devif_callback_free
*
* Description:
* Return a callback container to the free list.
* This is called internally as part of uIP initialization and should not
* be accessed from the application or socket layer.
*
* Assumptions:
* This function is called with interrupts disabled.
*
****************************************************************************/
void devif_callback_free(FAR struct devif_callback_s *cb,
void devif_callback_free(FAR struct net_driver_s *dev,
FAR struct devif_callback_s *cb,
FAR struct devif_callback_s **list);
/****************************************************************************
* Function: devif_callback_execute
* Function: devif_conn_event
*
* Description:
* Execute a list of callbacks.
* This is called internally as part of uIP initialization and should not
* be accessed from the application or socket layer.
*
* Input parameters:
* dev - The network device state structure associated with the network
@ -337,6 +336,8 @@ void devif_callback_free(FAR struct devif_callback_s *cb,
* pvconn - Holds a reference to the TCP connection structure or the UDP
* port structure. May be NULL if the even is not related to a TCP
* connection or UDP port.
* flags - The bit set of events to be notified.
* list - The list to traverse in performing the notifications
*
* Returned value:
* The updated flags as modified by the callback functions.
@ -346,8 +347,33 @@ void devif_callback_free(FAR struct devif_callback_s *cb,
*
****************************************************************************/
uint16_t devif_callback_execute(FAR struct net_driver_s *dev, FAR void *pvconn,
uint16_t flags, FAR struct devif_callback_s *list);
uint16_t devif_conn_event(FAR struct net_driver_s *dev, FAR void *pvconn,
uint16_t flags, FAR struct devif_callback_s *list);
/****************************************************************************
* Function: devif_dev_event
*
* Description:
* Execute a list of callbacks using the device event chain.
*
* Input parameters:
* dev - The network device state structure associated with the network
* device that initiated the callback event.
* pvconn - Holds a reference to the TCP connection structure or the UDP
* port structure. May be NULL if the even is not related to a TCP
* connection or UDP port.
* flags - The bit set of events to be notified.
*
* Returned value:
* The updated flags as modified by the callback functions.
*
* Assumptions:
* This function is called with the network locked.
*
****************************************************************************/
uint16_t devif_dev_event(FAR struct net_driver_s *dev, void *pvconn,
uint16_t flags);
/****************************************************************************
* Send data on the current connection.
@ -375,12 +401,45 @@ uint16_t devif_callback_execute(FAR struct net_driver_s *dev, FAR void *pvconn,
void devif_send(FAR struct net_driver_s *dev, FAR const void *buf, int len);
/****************************************************************************
* Name: devif_iob_send
*
* Description:
* Called from socket logic in response to a xmit or poll request from the
* the network interface driver.
*
* This is identical to calling devif_send() except that the data is
* in an I/O buffer chain, rather than a flat buffer.
*
* Assumptions:
* Called from the interrupt level or, at a minimum, with interrupts
* disabled.
*
****************************************************************************/
#ifdef CONFIG_NET_IOB
struct iob_s;
void devif_iob_send(FAR struct net_driver_s *dev, FAR struct iob_s *buf,
unsigned int len, unsigned int offset);
#endif
/****************************************************************************
* Name: devif_pkt_send
*
* Description:
* Called from socket logic in order to send a raw packet in response to
* an xmit or poll request from the the network interface driver.
*
* This is almost identical to calling devif_send() except that the data to
* be sent is copied into dev->d_buf (vs. dev->d_appdata), since there is
* no header on the data.
*
* Assumptions:
* Called from the interrupt level or, at a minimum, with interrupts
* disabled.
*
****************************************************************************/
#ifdef CONFIG_NET_PKT
void devif_pkt_send(FAR struct net_driver_s *dev, FAR const void *buf,
unsigned int len);

View file

@ -1,7 +1,7 @@
/****************************************************************************
* net/devif/devif_callback.c
*
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2008-2009, 2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -82,10 +82,11 @@ static FAR struct devif_callback_s *g_cbfreelist = NULL;
void devif_callback_init(void)
{
int i;
for (i = 0; i < CONFIG_NET_NACTIVESOCKETS; i++)
{
g_cbprealloc[i].flink = g_cbfreelist;
g_cbfreelist = &g_cbprealloc[i];
g_cbprealloc[i].nxtconn = g_cbfreelist;
g_cbfreelist = &g_cbprealloc[i];
}
}
@ -94,15 +95,15 @@ void devif_callback_init(void)
*
* Description:
* Allocate a callback container from the free list.
* This is called internally as part of uIP initialization and should not
* be accessed from the application or socket layer.
*
* Assumptions:
* This function is called with interrupts disabled.
*
****************************************************************************/
FAR struct devif_callback_s *devif_callback_alloc(FAR struct devif_callback_s **list)
FAR struct devif_callback_s *
devif_callback_alloc(FAR struct net_driver_s *dev,
FAR struct devif_callback_s **list)
{
FAR struct devif_callback_s *ret;
net_lock_t save;
@ -115,19 +116,25 @@ FAR struct devif_callback_s *devif_callback_alloc(FAR struct devif_callback_s **
{
/* Remove the next instance from the head of the free list */
g_cbfreelist = ret->flink;
g_cbfreelist = ret->nxtconn;
memset(ret, 0, sizeof(struct devif_callback_s));
/* Add the newly allocated instance to the head of the device event
* list.
*/
if (dev)
{
ret->nxtdev = dev->d_devcb;
dev->d_devcb = ret;
}
/* Add the newly allocated instance to the head of the specified list */
if (list)
{
ret->flink = *list;
*list = ret;
}
else
{
ret->flink = NULL;
ret->nxtconn = *list;
*list = ret;
}
}
#ifdef CONFIG_DEBUG
@ -146,15 +153,14 @@ FAR struct devif_callback_s *devif_callback_alloc(FAR struct devif_callback_s **
*
* Description:
* Return a callback container to the free list.
* This is called internally as part of uIP initialization and should not
* be accessed from the application or socket layer.
*
* Assumptions:
* This function is called with interrupts disabled.
*
****************************************************************************/
void devif_callback_free(FAR struct devif_callback_s *cb,
void devif_callback_free(FAR struct net_driver_s *dev,
FAR struct devif_callback_s *cb,
FAR struct devif_callback_s **list)
{
FAR struct devif_callback_s *prev;
@ -173,48 +179,71 @@ void devif_callback_free(FAR struct devif_callback_s *cb,
while (curr != NULL)
{
DEBUGASSERT(cb != curr);
curr = curr->flink;
curr = curr->nxtconn;
}
#endif
/* Find the callback structure in the connection's list */
/* Find the callback structure in the device event list */
if (dev)
{
for (prev = NULL, curr = dev->d_devcb;
curr && curr != cb;
prev = curr, curr = curr->nxtdev);
/* Remove the structure from the device event list */
DEBUGASSERT(curr);
if (curr)
{
if (prev)
{
prev->nxtdev = cb->nxtdev;
}
else
{
dev->d_devcb = cb->nxtdev;
}
}
}
/* Find the callback structure in the connection event list */
if (list)
{
for (prev = NULL, curr = *list;
curr && curr != cb;
prev = curr, curr = curr->flink);
prev = curr, curr = curr->nxtconn);
/* Remove the structure from the connection's list */
/* Remove the structure from the connection event list */
DEBUGASSERT(curr);
if (curr)
{
if (prev)
{
prev->flink = cb->flink;
prev->nxtconn = cb->nxtconn;
}
else
{
*list = cb->flink;
*list = cb->nxtconn;
}
}
}
/* Put the structure into the free list */
cb->flink = g_cbfreelist;
cb->nxtconn = g_cbfreelist;
g_cbfreelist = cb;
net_unlock(save);
}
}
/****************************************************************************
* Function: devif_callback_execute
* Function: devif_conn_event
*
* Description:
* Execute a list of callbacks.
* This is called internally as part of uIP initialization and should not
* be accessed from the application or socket layer.
* Execute a list of callbacks using the packet event chain.
*
* Input parameters:
* dev - The network device state structure associated with the network
@ -222,6 +251,8 @@ void devif_callback_free(FAR struct devif_callback_s *cb,
* pvconn - Holds a reference to the TCP connection structure or the UDP
* port structure. May be NULL if the even is not related to a TCP
* connection or UDP port.
* flags - The bit set of events to be notified.
* list - The list to traverse in performing the notifications
*
* Returned value:
* The updated flags as modified by the callback functions.
@ -231,8 +262,8 @@ void devif_callback_free(FAR struct devif_callback_s *cb,
*
****************************************************************************/
uint16_t devif_callback_execute(FAR struct net_driver_s *dev, void *pvconn,
uint16_t flags, FAR struct devif_callback_s *list)
uint16_t devif_conn_event(FAR struct net_driver_s *dev, void *pvconn,
uint16_t flags, FAR struct devif_callback_s *list)
{
FAR struct devif_callback_s *next;
net_lock_t save;
@ -249,7 +280,7 @@ uint16_t devif_callback_execute(FAR struct net_driver_s *dev, void *pvconn,
* list.
*/
next = list->flink;
next = list->nxtconn;
/* Check if this callback handles any of the events in the flag set */
@ -273,4 +304,69 @@ uint16_t devif_callback_execute(FAR struct net_driver_s *dev, void *pvconn,
return flags;
}
/****************************************************************************
* Function: devif_dev_event
*
* Description:
* Execute a list of callbacks using the device event chain.
*
* Input parameters:
* dev - The network device state structure associated with the network
* device that initiated the callback event.
* pvconn - Holds a reference to the TCP connection structure or the UDP
* port structure. May be NULL if the even is not related to a TCP
* connection or UDP port.
* flags - The bit set of events to be notified.
*
* Returned value:
* The updated flags as modified by the callback functions.
*
* Assumptions:
* This function is called with the network locked.
*
****************************************************************************/
uint16_t devif_dev_event(FAR struct net_driver_s *dev, void *pvconn,
uint16_t flags)
{
FAR struct devif_callback_s *cb;
FAR struct devif_callback_s *next;
net_lock_t save;
/* Loop for each callback in the list and while there are still events
* set in the flags set.
*/
save = net_lock();
for (cb = dev->d_devcb; cb != NULL && flags != 0; cb = next)
{
/* Save the pointer to the next callback in the lists. This is done
* because the callback action might delete the entry pointed to by
* list.
*/
next = cb->nxtdev;
/* Check if this callback handles any of the events in the flag set */
if (cb->event && (flags & cb->flags) != 0)
{
/* Yes.. perform the callback. Actions perform by the callback
* may delete the current list entry or add a new list entry to
* beginning of the list (which will be ignored on this pass)
*/
nllvdbg("Call event=%p with flags=%04x\n", cb->event, flags);
flags = cb->event(dev, pvconn, cb->priv, flags);
}
/* Set up for the next time through the loop */
cb = next;
}
net_unlock(save);
return flags;
}
#endif /* CONFIG_NET */

View file

@ -178,9 +178,9 @@ void icmp_input(FAR struct net_driver_s *dev)
*/
#ifdef CONFIG_NET_ICMP_PING
else if (picmp->type == ICMP_ECHO_REPLY && dev->d_callbacks)
else if (picmp->type == ICMP_ECHO_REPLY && dev->d_conncb)
{
(void)devif_callback_execute(dev, picmp, ICMP_ECHOREPLY, dev->d_callbacks);
(void)devif_conn_event(dev, picmp, ICMP_ECHOREPLY, dev->d_conncb);
}
#endif

View file

@ -70,8 +70,10 @@
/* Allocate a new ICMP data callback */
#define icmp_callback_alloc(dev) devif_callback_alloc(&(dev)->d_callbacks)
#define icmp_callback_free(dev,cb) devif_callback_free(cb, &(dev)->d_callbacks)
#define icmp_callback_alloc(dev) \
devif_callback_alloc(dev, &(dev)->d_conncb)
#define icmp_callback_free(dev,cb) \
devif_callback_free(dev, cb, &(dev)->d_conncb)
/****************************************************************************
* Private Types

View file

@ -96,7 +96,7 @@ void icmp_poll(FAR struct net_driver_s *dev)
/* Perform the application callback */
(void)devif_callback_execute(dev, NULL, ICMP_POLL, dev->d_callbacks);
(void)devif_conn_event(dev, NULL, ICMP_POLL, dev->d_conncb);
}
#endif /* CONFIG_NET && CONFIG_NET_ICMP && CONFIG_NET_ICMP_PING */

View file

@ -55,8 +55,10 @@
/* Allocate a new ICMPv6 data callback */
#define icmpv6_callback_alloc(dev) devif_callback_alloc(&(dev)->d_callbacks)
#define icmpv6_callback_free(dev,cb) devif_callback_free(cb, &(dev)->d_callbacks)
#define icmpv6_callback_alloc(dev) \
devif_callback_alloc(dev, &(dev)->d_conncb)
#define icmpv6_callback_free(dev,cb) \
devif_callback_free(dev, cb, &(dev)->d_conncb)
/****************************************************************************
* Public Type Definitions

View file

@ -291,7 +291,7 @@ void icmpv6_input(FAR struct net_driver_s *dev)
/* Dispatch the ECHO reply to the waiting thread */
flags = devif_callback_execute(dev, icmp, flags, dev->d_callbacks);
flags = devif_conn_event(dev, icmp, flags, dev->d_conncb);
/* If the ECHO reply was not handled, then drop the packet */

View file

@ -97,7 +97,7 @@ void icmpv6_poll(FAR struct net_driver_s *dev)
/* Perform the application callback */
(void)devif_callback_execute(dev, NULL, ICMPv6_POLL, dev->d_callbacks);
(void)devif_conn_event(dev, NULL, ICMPv6_POLL, dev->d_conncb);
}
#endif /* CONFIG_NET_ICMPv6_PING || CONFIG_NET_ICMPv6_NEIGHBOR */

View file

@ -1045,8 +1045,7 @@ void netdev_ifdown(FAR struct net_driver_s *dev)
/* Notify clients that the network has been taken down */
(void)devif_callback_execute(dev, NULL, NETDEV_DOWN,
dev->d_callbacks);
(void)devif_dev_event(dev, NULL, NETDEV_DOWN);
}
}

View file

@ -249,7 +249,8 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype)
/* There are no clients of the device yet */
dev->d_callbacks = NULL;
dev->d_conncb = NULL;
dev->d_devcb = NULL;
/* Get the next available device number and sssign a device name to
* the interface

View file

@ -52,8 +52,8 @@
/* Allocate a new packet socket data callback */
#define pkt_callback_alloc(conn) devif_callback_alloc(&conn->list)
#define pkt_callback_free(conn,cb) devif_callback_free(cb, &conn->list)
#define pkt_callback_alloc(conn) devif_callback_alloc(NULL, &conn->list)
#define pkt_callback_free(conn,cb) devif_callback_free(NULL, cb, &conn->list)
/****************************************************************************
* Public Type Definitions

View file

@ -86,7 +86,7 @@ uint16_t pkt_callback(FAR struct net_driver_s *dev,
{
/* Perform the callback */
flags = devif_callback_execute(dev, conn, flags, conn->list);
flags = devif_conn_event(dev, conn, flags, conn->list);
}
return flags;

View file

@ -62,8 +62,8 @@
/* Allocate a new TCP data callback */
#define tcp_callback_alloc(conn) devif_callback_alloc(&conn->list)
#define tcp_callback_free(conn,cb) devif_callback_free(cb, &conn->list)
#define tcp_callback_alloc(conn) devif_callback_alloc(NULL, &conn->list)
#define tcp_callback_free(conn,cb) devif_callback_free(NULL, cb, &conn->list)
/* Get the current maximum segment size that can be sent on the current
* TCP connection.

View file

@ -177,7 +177,7 @@ uint16_t tcp_callback(FAR struct net_driver_s *dev,
* dev->d_len should also be cleared).
*/
flags = devif_callback_execute(dev, conn, flags, conn->list);
flags = devif_conn_event(dev, conn, flags, conn->list);
/* There may be no new data handler in place at them moment that the new
* incoming data is received. If the new incoming data was not handled, then

View file

@ -790,7 +790,7 @@ void tcp_free(FAR struct tcp_conn_s *conn)
for (cb = conn->list; cb; cb = next)
{
next = cb->flink;
next = cb->nxtconn;
tcp_callback_free(conn, cb);
}

View file

@ -65,8 +65,8 @@
/* Allocate a new UDP data callback */
#define udp_callback_alloc(conn) devif_callback_alloc(&conn->list)
#define udp_callback_free(conn,cb) devif_callback_free(cb, &conn->list)
#define udp_callback_alloc(conn) devif_callback_alloc(NULL, &conn->list)
#define udp_callback_free(conn,cb) devif_callback_free(NULL, cb, &conn->list)
/****************************************************************************
* Public Type Definitions

View file

@ -316,7 +316,7 @@ uint16_t udp_callback(FAR struct net_driver_s *dev,
{
/* Perform the callback */
flags = devif_callback_execute(dev, conn, flags, conn->list);
flags = devif_conn_event(dev, conn, flags, conn->list);
if ((flags & UDP_NEWDATA) != 0)
{