2017-07-08 17:56:08 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* net/ipforward/ipfwd_poll.c
|
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2017-07-08 17:56:08 +02:00
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2017-07-08 17:56:08 +02:00
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2017-07-08 17:56:08 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2017-08-12 18:27:55 +02:00
|
|
|
#include <debug.h>
|
2017-07-08 17:56:08 +02:00
|
|
|
|
|
|
|
#include <nuttx/net/netdev.h>
|
2017-08-09 02:37:42 +02:00
|
|
|
#include <nuttx/net/net.h>
|
2017-07-08 17:56:08 +02:00
|
|
|
|
|
|
|
#include "devif/devif.h"
|
2017-08-12 18:27:55 +02:00
|
|
|
#include "sixlowpan/sixlowpan.h"
|
2017-07-08 17:56:08 +02:00
|
|
|
#include "ipforward/ipforward.h"
|
|
|
|
|
2017-08-08 22:24:12 +02:00
|
|
|
#ifdef CONFIG_NET_IPFORWARD
|
2017-07-08 17:56:08 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: ipfwd_packet_proto
|
|
|
|
*
|
|
|
|
* Description:
|
2017-07-29 21:42:26 +02:00
|
|
|
* Generic output conversion hook. Only needed for IEEE802.15.4 (and
|
2018-08-13 15:39:38 +02:00
|
|
|
* other, non-standard packet radios) for now but this is a point where
|
2017-07-29 21:42:26 +02:00
|
|
|
* support for other conversions may be provided.
|
2017-07-08 17:56:08 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
|
|
|
static int ipfwd_packet_proto(FAR struct net_driver_s *dev)
|
|
|
|
{
|
|
|
|
FAR struct ipv6_hdr_s *ipv6;
|
|
|
|
|
|
|
|
/* Make sure the there is something in buffer that is at least as large as
|
|
|
|
* the IPv6_HDR.
|
|
|
|
*/
|
|
|
|
|
2022-10-26 06:35:08 +02:00
|
|
|
if (dev->d_len > (IPv6_HDRLEN + NET_LL_HDRLEN(dev)))
|
2017-07-08 17:56:08 +02:00
|
|
|
{
|
2017-07-29 21:42:26 +02:00
|
|
|
if (dev->d_lltype == NET_LL_IEEE802154 ||
|
|
|
|
dev->d_lltype == NET_LL_PKTRADIO)
|
2017-07-08 17:56:08 +02:00
|
|
|
{
|
2017-07-29 21:42:26 +02:00
|
|
|
/* There should be an IPv6 packet at the beginning of the buffer */
|
2017-07-08 17:56:08 +02:00
|
|
|
|
2022-10-26 06:35:08 +02:00
|
|
|
ipv6 = IPv6BUF;
|
2017-07-08 17:56:08 +02:00
|
|
|
if ((ipv6->vtc & IP_VERSION_MASK) == IPv6_VERSION)
|
|
|
|
{
|
|
|
|
/* Yes.. return the L2 protocol of the packet */
|
|
|
|
|
|
|
|
return ipv6->proto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EPROTO;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NET_6LOWPAN */
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: ipfwd_packet_conversion
|
|
|
|
*
|
|
|
|
* Description:
|
2017-07-29 21:42:26 +02:00
|
|
|
* Generic output conversion hook. Only needed for IEEE802.15.4 (and
|
|
|
|
* other, non-standard packet radios) for now but this is a point where
|
|
|
|
* support for other conversions may be provided.
|
2017-07-08 17:56:08 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
|
|
|
static void ipfwd_packet_conversion(FAR struct net_driver_s *dev, int proto)
|
|
|
|
{
|
2017-07-29 21:42:26 +02:00
|
|
|
if (dev->d_len > 0)
|
|
|
|
{
|
2017-08-09 00:27:23 +02:00
|
|
|
/* Check if this is a device served by 6LoWPAN */
|
|
|
|
|
2017-07-29 21:42:26 +02:00
|
|
|
if (dev->d_lltype == NET_LL_IEEE802154 ||
|
|
|
|
dev->d_lltype == NET_LL_PKTRADIO)
|
2017-07-08 17:56:08 +02:00
|
|
|
{
|
2017-08-08 23:26:09 +02:00
|
|
|
FAR struct ipv6_hdr_s *ipv6 = (FAR struct ipv6_hdr_s *)dev->d_buf;
|
|
|
|
|
2017-07-29 21:42:26 +02:00
|
|
|
#ifdef CONFIG_NET_TCP
|
|
|
|
if (proto == IP_PROTO_TCP)
|
|
|
|
{
|
|
|
|
/* Let 6LoWPAN convert IPv6 TCP output into radio frames. */
|
2017-07-08 17:56:08 +02:00
|
|
|
|
2017-07-29 21:42:26 +02:00
|
|
|
sixlowpan_tcp_send(dev, dev, ipv6);
|
|
|
|
}
|
|
|
|
else
|
2017-07-08 17:56:08 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_UDP
|
2017-07-29 21:42:26 +02:00
|
|
|
if (proto == IP_PROTO_UDP)
|
|
|
|
{
|
|
|
|
/* Let 6LoWPAN convert IPv6 UDP output into radio frames. */
|
2017-07-08 17:56:08 +02:00
|
|
|
|
2017-07-29 21:42:26 +02:00
|
|
|
sixlowpan_udp_send(dev, dev, ipv6);
|
|
|
|
}
|
|
|
|
else
|
2017-07-08 17:56:08 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_ICMPv6
|
2017-07-29 21:42:26 +02:00
|
|
|
if (proto == IP_PROTO_ICMP6)
|
|
|
|
{
|
|
|
|
/* Let 6LoWPAN convert IPv6 UDP output into radio frames. */
|
2017-07-08 17:56:08 +02:00
|
|
|
|
2017-07-29 21:42:26 +02:00
|
|
|
sixlowpan_icmpv6_send(dev, dev, ipv6);
|
|
|
|
}
|
|
|
|
else
|
2017-07-08 17:56:08 +02:00
|
|
|
#endif
|
2017-07-29 21:42:26 +02:00
|
|
|
{
|
2017-08-09 00:27:23 +02:00
|
|
|
nwarn("WARNING: Unsupported protocol (%u). Packet dropped\n",
|
|
|
|
proto);
|
2017-07-29 21:42:26 +02:00
|
|
|
}
|
2017-07-08 17:56:08 +02:00
|
|
|
|
2017-07-29 21:42:26 +02:00
|
|
|
dev->d_len = 0;
|
|
|
|
}
|
2017-07-08 17:56:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NET_6LOWPAN */
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: ipfwd_poll
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Poll all pending transfer for ARP requests to send.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* This function is called from the MAC device driver indirectly through
|
2022-06-05 17:34:03 +02:00
|
|
|
* devif_poll().
|
2017-07-08 17:56:08 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void ipfwd_poll(FAR struct net_driver_s *dev)
|
|
|
|
{
|
|
|
|
uint16_t flags;
|
|
|
|
|
|
|
|
/* Setup for the callback (most of these do not apply) */
|
|
|
|
|
|
|
|
dev->d_appdata = NULL;
|
|
|
|
dev->d_len = 0;
|
|
|
|
dev->d_sndlen = 0;
|
|
|
|
|
|
|
|
/* Perform the forwarding callbacks. Returns the new set of flags. If
|
2020-02-23 09:50:23 +01:00
|
|
|
* the packet was forwarded, then the new set will be zero.
|
2017-07-08 17:56:08 +02:00
|
|
|
*/
|
|
|
|
|
2022-08-25 15:17:57 +02:00
|
|
|
flags = devif_conn_event(dev, IPFWD_POLL, dev->d_conncb);
|
2017-07-08 17:56:08 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
|
|
|
if ((flags & DEVPOLL_MASK) == 0)
|
|
|
|
{
|
|
|
|
/* Get the L2 protocol of packet in the device's d_buf */
|
|
|
|
|
|
|
|
int proto = ipfwd_packet_proto(dev);
|
|
|
|
if (proto >= 0)
|
|
|
|
{
|
|
|
|
/* Perform any necessary conversions on the forwarded packet */
|
|
|
|
|
|
|
|
ipfwd_packet_conversion(dev, proto);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
UNUSED(flags);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-08-08 22:24:12 +02:00
|
|
|
#endif /* CONFIG_NET_ARP_SEND */
|