mirror of
https://github.com/apache/nuttx.git
synced 2026-06-05 07:12:54 +08:00
IP forwarding: Two bugfixes (1) IPFWD poll event must be unique and different from other device poll events otherwise, some other waiting task might get the poll, (2) Add logic necessary to forward 6LoWPAN packets.
This commit is contained in:
+27
-9
@@ -148,6 +148,14 @@
|
||||
* is set differently
|
||||
* OUT: Not used
|
||||
*
|
||||
* IPFWD_POLL IN: Used for polling for forwarded packets layer. This
|
||||
* is provided periodically from the drivers to support
|
||||
* to check if there is a packet waiting to be forward
|
||||
* on the device. This is a device oriented event,
|
||||
* not associated with a socket. The appdata pointer
|
||||
* The appdata pointer is not used in this case.
|
||||
* OUT: Not used
|
||||
*
|
||||
* ICMP_ECHOREPLY IN: An ICMP Echo Reply has been received. Used to support
|
||||
* ICMP ping from the socket layer. (ICMPv4 only)
|
||||
* OUT: Cleared (only) by the socket layer logic to indicate
|
||||
@@ -164,7 +172,7 @@
|
||||
* OUT: Not used
|
||||
*/
|
||||
|
||||
/* Connection specific events */
|
||||
/* Bits 0-9: Connection specific event bits */
|
||||
|
||||
#define TCP_ACKDATA (1 << 0)
|
||||
#define TCP_NEWDATA (1 << 1)
|
||||
@@ -178,23 +186,33 @@
|
||||
#define UDP_POLL TCP_POLL
|
||||
#define PKT_POLL TCP_POLL
|
||||
#define WPAN_POLL TCP_POLL
|
||||
#define IPFWD_POLL TCP_POLL
|
||||
#define TCP_BACKLOG (1 << 5)
|
||||
#define TCP_CLOSE (1 << 6)
|
||||
#define TCP_ABORT (1 << 7)
|
||||
#define TCP_CONNECTED (1 << 8)
|
||||
#define TCP_TIMEDOUT (1 << 9)
|
||||
|
||||
/* Device specific events */
|
||||
/* Bits 10-12: Device specific event bits */
|
||||
|
||||
#define ICMP_NEWDATA TCP_NEWDATA
|
||||
#define ICMPv6_NEWDATA TCP_NEWDATA
|
||||
#define ARP_POLL (1 << 10)
|
||||
#define ICMP_POLL (1 << 11)
|
||||
#define ICMPv6_POLL (1 << 12)
|
||||
#define ICMP_ECHOREPLY (1 << 13)
|
||||
#define ICMPv6_ECHOREPLY (1 << 14)
|
||||
#define NETDEV_DOWN (1 << 15)
|
||||
#define ICMP_ECHOREPLY (1 << 10)
|
||||
#define ICMPv6_ECHOREPLY (1 << 11)
|
||||
#define NETDEV_DOWN (1 << 12)
|
||||
|
||||
/* Bits 13-15: Encoded device specific poll events. Unlike connection
|
||||
* oriented poll events, device related poll events must distinguish
|
||||
* between what is being polled for since the callbacks all reside in
|
||||
* the same list in the network device structure.
|
||||
*/
|
||||
|
||||
#define DEVPOLL_SHIFT (13)
|
||||
#define DEVPOLL_MASK (7 << DEVPOLL_SHIFT)
|
||||
# define DEVPOLL_NONE (0 << DEVPOLL_SHIFT)
|
||||
# define ARP_POLL (1 << DEVPOLL_SHIFT)
|
||||
# define ICMP_POLL (2 << DEVPOLL_SHIFT)
|
||||
# define ICMPv6_POLL (3 << DEVPOLL_SHIFT)
|
||||
# define IPFWD_POLL (4 << DEVPOLL_SHIFT)
|
||||
|
||||
/* The set of events that and implications to the TCP connection state */
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#if defined(CONFIG_NET)
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <debug.h>
|
||||
#include <assert.h>
|
||||
@@ -162,6 +163,45 @@ static void devif_callback_free(FAR struct net_driver_s *dev,
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: devif_event_trigger
|
||||
*
|
||||
* Description:
|
||||
* Return true if the current set of events should trigger a callback to
|
||||
* occur.
|
||||
*
|
||||
* Input paramters:
|
||||
* events - The set of events that has occurred.
|
||||
* triggers - The set of events that will trigger a callback.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static bool devif_event_trigger(uint16_t events, uint16_t triggers)
|
||||
{
|
||||
/* The events are divided into a set of individual bits that may be ORed
|
||||
* together PLUS a field that encodes a single poll event.
|
||||
*
|
||||
* First check if any of the individual event bits will trigger the
|
||||
* callback.
|
||||
*/
|
||||
|
||||
if ((events & triggers & ~DEVPOLL_MASK) != 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/* No... check the encoded device event. */
|
||||
|
||||
if ((events & DEVPOLL_MASK) == (triggers & DEVPOLL_MASK))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/* No.. this event set will not generate the callback */
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@@ -335,7 +375,7 @@ void devif_dev_callback_free(FAR struct net_driver_s *dev,
|
||||
* was allocated and the time when the callback was freed.
|
||||
*/
|
||||
|
||||
if (dev && netdev_verify(dev))
|
||||
if (dev != NULL && netdev_verify(dev))
|
||||
{
|
||||
/* The device reference is valid.. the use the list pointer in the
|
||||
* device structure as well.
|
||||
@@ -400,7 +440,7 @@ uint16_t devif_conn_event(FAR struct net_driver_s *dev, void *pvconn,
|
||||
|
||||
/* Check if this callback handles any of the events in the flag set */
|
||||
|
||||
if (list->event && (flags & list->flags) != 0)
|
||||
if (list->event != NULL && devif_event_trigger(flags, list->flags))
|
||||
{
|
||||
/* Yes.. perform the callback. Actions perform by the callback
|
||||
* may delete the current list entry or add a new list entry to
|
||||
@@ -464,7 +504,7 @@ uint16_t devif_dev_event(FAR struct net_driver_s *dev, void *pvconn,
|
||||
|
||||
/* Check if this callback handles any of the events in the flag set */
|
||||
|
||||
if (cb->event && (flags & cb->flags) != 0)
|
||||
if (cb->event != NULL && devif_event_trigger(flags, cb->flags))
|
||||
{
|
||||
/* Yes.. perform the callback. Actions perform by the callback
|
||||
* may delete the current list entry or add a new list entry to
|
||||
|
||||
+24
-18
@@ -56,6 +56,7 @@
|
||||
#include "icmp/icmp.h"
|
||||
#include "icmpv6/icmpv6.h"
|
||||
#include "igmp/igmp.h"
|
||||
#include "ipforward/ipforward.h"
|
||||
#include "sixlowpan/sixlowpan.h"
|
||||
|
||||
/****************************************************************************
|
||||
@@ -166,8 +167,8 @@ static void devif_packet_conversion(FAR struct net_driver_s *dev,
|
||||
* Poll all packet connections for available packets to send.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function is called from the MAC device driver and may be called
|
||||
* from the timer interrupt/watchdog handle level.
|
||||
* This function is called from the MAC device driver with the network
|
||||
* locked.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@@ -259,13 +260,18 @@ static inline int devif_poll_icmpv6(FAR struct net_driver_s *dev,
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_NET_IPFORWARD) || defined(CONFIG_NETDEV_MULTINIC)
|
||||
#if defined(CONFIG_NET_IPFORWARD) && defined(CONFIG_NETDEV_MULTINIC)
|
||||
static inline int devif_poll_forward(FAR struct net_driver_s *dev,
|
||||
devif_poll_callback_t callback)
|
||||
{
|
||||
/* Perform the ICMPv6 poll */
|
||||
/* Perform the forwarding poll */
|
||||
|
||||
devif_dev_event(dev, NULL, IPFWD_POLL);
|
||||
ipfwd_poll(dev);
|
||||
|
||||
/* NOTE: that 6LoWPAN packet conversions are handled differently for
|
||||
* forwarded packets. That is because we don't know what the packet
|
||||
* type is at this point; not within peeking into the device's d_buf.
|
||||
*/
|
||||
|
||||
/* Call back into the driver */
|
||||
|
||||
@@ -280,8 +286,8 @@ static inline int devif_poll_forward(FAR struct net_driver_s *dev,
|
||||
* Poll all IGMP connections for available packets to send.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function is called from the MAC device driver and may be called
|
||||
* from the timer interrupt/watchdog handle level.
|
||||
* This function is called from the MAC device driver with the network
|
||||
* locked.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@@ -310,8 +316,8 @@ static inline int devif_poll_igmp(FAR struct net_driver_s *dev,
|
||||
* Poll all UDP connections for available packets to send.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function is called from the MAC device driver and may be called
|
||||
* from the timer interrupt/watchdog handle level.
|
||||
* This function is called from the MAC device driver with the network
|
||||
* locked.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@@ -350,8 +356,8 @@ static int devif_poll_udp_connections(FAR struct net_driver_s *dev,
|
||||
* Poll all UDP connections for available packets to send.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function is called from the MAC device driver and may be called
|
||||
* from the timer interrupt/watchdog handle level.
|
||||
* This function is called from the MAC device driver with the network
|
||||
* locked.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@@ -393,8 +399,8 @@ static inline int devif_poll_tcp_connections(FAR struct net_driver_s *dev,
|
||||
* TCP connection.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function is called from the MAC device driver and may be called
|
||||
* from the timer interrupt/watchdog handle level.
|
||||
* This function is called from the MAC device driver with the network
|
||||
* locked.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@@ -453,8 +459,8 @@ static inline int devif_poll_tcp_timer(FAR struct net_driver_s *dev,
|
||||
* out the packet.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function is called from the MAC device driver and may be called
|
||||
* from the timer interrupt/watchdog handle level.
|
||||
* This function is called from the MAC device driver with the network
|
||||
* locked.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@@ -530,7 +536,7 @@ int devif_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback)
|
||||
|
||||
if (!bstop)
|
||||
#endif
|
||||
#if defined(CONFIG_NET_IPFORWARD) || defined(CONFIG_NETDEV_MULTINIC)
|
||||
#if defined(CONFIG_NET_IPFORWARD) && defined(CONFIG_NETDEV_MULTINIC)
|
||||
{
|
||||
/* Traverse all of the tasks waiting to forward a packet to this device. */
|
||||
|
||||
@@ -565,8 +571,8 @@ int devif_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback)
|
||||
* out the packet.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function is called from the MAC device driver and may be called from
|
||||
* the timer interrupt/watchdog handle level.
|
||||
* This function is called from the MAC device driver with the network
|
||||
* locked.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user