Networking: Replace all references to net_ipaddr_t with either in_addr_t on net_ipv6addr_t. The goal is to support both IPv4 and IPv6 simultaneously. This requires that the two types be distinct and not conditionally typedef'ed to net_ipaddr_t.
This commit is contained in:
parent
75ce2c895e
commit
5e938941a6
@ -189,7 +189,7 @@ extern "C"
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int icmp_ping(net_ipaddr_t addr, uint16_t id, uint16_t seqno, uint16_t datalen,
|
||||
int icmp_ping(in_addr_t addr, uint16_t id, uint16_t seqno, uint16_t datalen,
|
||||
int dsecs);
|
||||
|
||||
#undef EXTERN
|
||||
|
@ -94,12 +94,6 @@
|
||||
|
||||
typedef uint16_t net_ipv6addr_t[8];
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
typedef net_ipv6addr_t net_ipaddr_t;
|
||||
#else
|
||||
typedef in_addr_t net_ipaddr_t;
|
||||
#endif
|
||||
|
||||
/* Describes and address in either the IPv4 or IPv6 domain */
|
||||
|
||||
union ip_addr_u
|
||||
@ -192,7 +186,7 @@ struct net_ipv6hdr_s
|
||||
*
|
||||
* This function constructs an IPv4 address in network byte order.
|
||||
*
|
||||
* addr A pointer to a net_ipaddr_t variable that will be
|
||||
* addr A pointer to a in_addr_t variable that will be
|
||||
* filled in with the IPv4 address.
|
||||
* addr0 The first octet of the IPv4 address.
|
||||
* addr1 The second octet of the IPv4 address.
|
||||
@ -255,7 +249,7 @@ struct net_ipv6hdr_s
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* net_ipaddr_t ipaddr1, ipaddr2;
|
||||
* in_addr_t ipaddr1, ipaddr2;
|
||||
*
|
||||
* net_ipaddr(&ipaddr1, 192,16,1,2);
|
||||
* net_ipaddr_copy(&ipaddr2, &ipaddr1);
|
||||
@ -289,7 +283,7 @@ struct net_ipv6hdr_s
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* net_ipaddr_t ipaddr1, ipaddr2;
|
||||
* in_addr_t ipaddr1, ipaddr2;
|
||||
*
|
||||
* net_ipaddr(&ipaddr1, 192,16,1,2);
|
||||
* if (net_ipaddr_cmp(ipaddr2, ipaddr1))
|
||||
@ -362,7 +356,7 @@ bool net_ipv6addr_maskcmp(const net_ipv6addr_t addr1,
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* net_ipaddr_t ipaddr1, ipaddr2, netmask;
|
||||
* in_addr_t ipaddr1, ipaddr2, netmask;
|
||||
*
|
||||
* net_ipaddr(&ipaddr1, 192,16,1,2);
|
||||
* net_ipaddr(&netmask, 255,255,255,0);
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* net/arp/arp_send.c
|
||||
*
|
||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2014-2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -223,7 +223,7 @@ int arp_send(in_addr_t ipaddr)
|
||||
/* Get the device that can route this request */
|
||||
|
||||
#ifdef CONFIG_NET_MULTILINK
|
||||
dev = netdev_findby_ipv4addr(g_allzeroaddr, ipaddr);
|
||||
dev = netdev_findby_ipv4addr(g_ipv4_allzeroaddr, ipaddr);
|
||||
#else
|
||||
dev = netdev_findby_ipv4addr(ipaddr);
|
||||
#endif
|
||||
@ -337,7 +337,7 @@ int arp_send(in_addr_t ipaddr)
|
||||
state.snd_cb->event = arp_send_interrupt;
|
||||
|
||||
/* Notify the device driver that new TX data is available.
|
||||
* NOTES: This is in essence what netdev_txnotify() does, which
|
||||
* NOTES: This is in essence what netdev_ipv4_txnotify() does, which
|
||||
* is not possible to call since it expects a in_addr_t as
|
||||
* its single argument to lookup the network interface.
|
||||
*/
|
||||
|
@ -165,8 +165,15 @@ struct devif_callback_s
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
extern const net_ipaddr_t g_alloneaddr;
|
||||
extern const net_ipaddr_t g_allzeroaddr;
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
extern const in_addr_t g_ipv4_alloneaddr;
|
||||
extern const in_addr_t g_ipv4_allzeroaddr;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
extern const net_ipv6addr_t g_ipv6_alloneaddr;
|
||||
extern const net_ipv6addr_t g_ipv6_allzeroaddr;
|
||||
#endif
|
||||
|
||||
/* Increasing number used for the IP ID field. */
|
||||
|
||||
|
@ -69,25 +69,23 @@ struct net_stats_s g_netstats;
|
||||
|
||||
uint16_t g_ipid;
|
||||
|
||||
const net_ipaddr_t g_alloneaddr =
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
{0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
|
||||
#else
|
||||
0xffffffff;
|
||||
#endif
|
||||
|
||||
const net_ipaddr_t g_allzeroaddr =
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
{0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000};
|
||||
#else
|
||||
0x00000000;
|
||||
#endif
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
const in_addr_t g_ipv4_alloneaddr = 0xffffffff;
|
||||
const in_addr_t g_ipv4_allzeroaddr = 0x00000000;
|
||||
|
||||
/* Reassembly timer (units: deci-seconds) */
|
||||
|
||||
#if defined(CONFIG_NET_TCP_REASSEMBLY) && !defined(CONFIG_NET_IPv6)
|
||||
#ifdef CONFIG_NET_TCP_REASSEMBLY
|
||||
uint8_t g_reassembly_timer;
|
||||
#endif
|
||||
#endif /* CONFIG_NET_IPv4 */
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
const net_ipv6addr_t g_ipv6_alloneaddr =
|
||||
{0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
|
||||
const net_ipv6addr_t g_ipv6_allzeroaddr =
|
||||
{0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000};
|
||||
#endif /* CONFIG_NET_IPv4 */
|
||||
|
||||
/****************************************************************************
|
||||
* Private Variables
|
||||
|
@ -381,7 +381,8 @@ int ipv4_input(FAR struct net_driver_s *dev)
|
||||
|
||||
#if defined(CONFIG_NET_BROADCAST) && defined(CONFIG_NET_UDP)
|
||||
if (pbuf->proto == IP_PROTO_UDP &&
|
||||
net_ipv4addr_cmp(net_ip4addr_conv32(pbuf->destipaddr), g_alloneaddr))
|
||||
net_ipv4addr_cmp(net_ip4addr_conv32(pbuf->destipaddr),
|
||||
g_ipv4_alloneaddr))
|
||||
{
|
||||
return udp_ipv4_input(dev);
|
||||
}
|
||||
@ -394,7 +395,7 @@ int ipv4_input(FAR struct net_driver_s *dev)
|
||||
else
|
||||
#endif
|
||||
#ifdef CONFIG_NET_ICMP
|
||||
if (net_ipv4addr_cmp(dev->d_ipaddr, g_allzeroaddr))
|
||||
if (net_ipv4addr_cmp(dev->d_ipaddr, g_ipv4_allzeroaddr))
|
||||
{
|
||||
/* If we are configured to use ping IP address configuration and
|
||||
* hasn't been assigned an IP address yet, we accept all ICMP
|
||||
|
@ -196,7 +196,7 @@ int ipv6_input(FAR struct net_driver_s *dev)
|
||||
|
||||
#if defined(CONFIG_NET_BROADCAST) && defined(CONFIG_NET_UDP)
|
||||
if (pbuf->proto == IP_PROTO_UDP &&
|
||||
net_ipv6addr_cmp(pbuf->destipaddr, g_alloneaddr))
|
||||
net_ipv6addr_cmp(pbuf->destipaddr, g_ipv6_alloneaddr))
|
||||
{
|
||||
return udp_ipv6_input(dev);
|
||||
}
|
||||
@ -209,7 +209,7 @@ int ipv6_input(FAR struct net_driver_s *dev)
|
||||
else
|
||||
#endif
|
||||
#ifdef CONFIG_NET_ICMPv6
|
||||
if (net_ipv6addr_cmp(dev->d_ipv6addr, g_allzeroaddr))
|
||||
if (net_ipv6addr_cmp(dev->d_ipv6addr, g_ipv6_allzeroaddr))
|
||||
{
|
||||
/* If we are configured to use ping IP address configuration and
|
||||
* hasn't been assigned an IP address yet, we accept all ICMP
|
||||
|
@ -369,9 +369,9 @@ int icmp_ping(in_addr_t addr, uint16_t id, uint16_t seqno, uint16_t datalen,
|
||||
/* Notify the device driver of the availability of TX data */
|
||||
|
||||
#ifdef CONFIG_NET_MULTILINK
|
||||
netdev_txnotify(g_allzeroaddr, state.png_addr);
|
||||
netdev_ipv4_txnotify(g_ipv4_allzeroaddr, state.png_addr);
|
||||
#else
|
||||
netdev_txnotify(state.png_addr);
|
||||
netdev_ipv4_txnotify(state.png_addr);
|
||||
#endif
|
||||
|
||||
/* Wait for either the full round trip transfer to complete or
|
||||
|
@ -368,9 +368,9 @@ int icmpv6_ping(net_ipv6addr_t addr, uint16_t id, uint16_t seqno,
|
||||
/* Notify the device driver of the availability of TX data */
|
||||
|
||||
#ifdef CONFIG_NET_MULTILINK
|
||||
netdev_txnotify(g_allzeroaddr, state.png_addr);
|
||||
netdev_ipv6_txnotify(g_ipv6_allzeroaddr, state.png_addr);
|
||||
#else
|
||||
netdev_txnotify(state.png_addr);
|
||||
netdev_ipv6_txnotify(state.png_addr);
|
||||
#endif
|
||||
|
||||
/* Wait for either the full round trip transfer to complete or
|
||||
|
@ -101,7 +101,7 @@ typedef FAR struct wdog_s *WDOG_ID;
|
||||
struct igmp_group_s
|
||||
{
|
||||
struct igmp_group_s *next; /* Implements a singly-linked list */
|
||||
net_ipaddr_t grpaddr; /* Group IP address */
|
||||
in_addr_t grpaddr; /* Group IPv4 address */
|
||||
WDOG_ID wdog; /* WDOG used to detect timeouts */
|
||||
sem_t sem; /* Used to wait for message transmission */
|
||||
volatile uint8_t flags; /* See IGMP_ flags definitions */
|
||||
@ -120,8 +120,8 @@ extern "C"
|
||||
# define EXTERN extern
|
||||
#endif
|
||||
|
||||
EXTERN net_ipaddr_t g_allsystems;
|
||||
EXTERN net_ipaddr_t g_allrouters;
|
||||
EXTERN in_addr_t g_ipv4_allsystems;
|
||||
EXTERN in_addr_t g_ipv4_allrouters;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
@ -188,7 +188,7 @@ void igmp_grpinit(void);
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct igmp_group_s *igmp_grpalloc(FAR struct net_driver_s *dev,
|
||||
FAR const net_ipaddr_t *addr);
|
||||
FAR const in_addr_t *addr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: igmp_grpfind
|
||||
@ -202,7 +202,7 @@ FAR struct igmp_group_s *igmp_grpalloc(FAR struct net_driver_s *dev,
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct igmp_group_s *igmp_grpfind(FAR struct net_driver_s *dev,
|
||||
FAR const net_ipaddr_t *addr);
|
||||
FAR const in_addr_t *addr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: igmp_grpallocfind
|
||||
@ -217,7 +217,7 @@ FAR struct igmp_group_s *igmp_grpfind(FAR struct net_driver_s *dev,
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct igmp_group_s *igmp_grpallocfind(FAR struct net_driver_s *dev,
|
||||
FAR const net_ipaddr_t *addr);
|
||||
FAR const in_addr_t *addr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: igmp_grpfree
|
||||
@ -304,7 +304,7 @@ void igmp_poll(FAR struct net_driver_s *dev);
|
||||
****************************************************************************/
|
||||
|
||||
void igmp_send(FAR struct net_driver_s *dev, FAR struct igmp_group_s *group,
|
||||
FAR net_ipaddr_t *dest);
|
||||
FAR in_addr_t *dest);
|
||||
|
||||
/* Defined in igmp_join.c ***************************************************/
|
||||
/****************************************************************************
|
||||
@ -405,7 +405,7 @@ bool igmp_cmptimer(FAR struct igmp_group_s *group, int maxticks);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void igmp_addmcastmac(FAR struct net_driver_s *dev, FAR net_ipaddr_t *ip);
|
||||
void igmp_addmcastmac(FAR struct net_driver_s *dev, FAR in_addr_t *ip);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: igmp_removemcastmac
|
||||
@ -415,7 +415,7 @@ void igmp_addmcastmac(FAR struct net_driver_s *dev, FAR net_ipaddr_t *ip);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void igmp_removemcastmac(FAR struct net_driver_s *dev, FAR net_ipaddr_t *ip);
|
||||
void igmp_removemcastmac(FAR struct net_driver_s *dev, FAR in_addr_t *ip);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
|
@ -221,7 +221,7 @@ void igmp_grpinit(void)
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct igmp_group_s *igmp_grpalloc(FAR struct net_driver_s *dev,
|
||||
FAR const net_ipaddr_t *addr)
|
||||
FAR const in_addr_t *addr)
|
||||
{
|
||||
FAR struct igmp_group_s *group;
|
||||
net_lock_t flags;
|
||||
@ -284,7 +284,7 @@ FAR struct igmp_group_s *igmp_grpalloc(FAR struct net_driver_s *dev,
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct igmp_group_s *igmp_grpfind(FAR struct net_driver_s *dev,
|
||||
FAR const net_ipaddr_t *addr)
|
||||
FAR const in_addr_t *addr)
|
||||
{
|
||||
FAR struct igmp_group_s *group;
|
||||
net_lock_t flags;
|
||||
@ -325,7 +325,7 @@ FAR struct igmp_group_s *igmp_grpfind(FAR struct net_driver_s *dev,
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct igmp_group_s *igmp_grpallocfind(FAR struct net_driver_s *dev,
|
||||
FAR const net_ipaddr_t *addr)
|
||||
FAR const in_addr_t *addr)
|
||||
{
|
||||
FAR struct igmp_group_s *group = igmp_grpfind(dev, addr);
|
||||
|
||||
|
@ -67,8 +67,8 @@
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
net_ipaddr_t g_allsystems;
|
||||
net_ipaddr_t g_allrouters;
|
||||
in_addr_t g_ipv4_allsystems;
|
||||
in_addr_t g_ipv4_allrouters;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
@ -86,8 +86,8 @@ void igmp_initialize(void)
|
||||
{
|
||||
nvdbg("IGMP initializing\n");
|
||||
|
||||
net_ipaddr(g_allrouters, 224, 0, 0, 2);
|
||||
net_ipaddr(g_allsystems, 224, 0, 0, 1);
|
||||
net_ipaddr(g_ipv4_allrouters, 224, 0, 0, 2);
|
||||
net_ipaddr(g_ipv4_allsystems, 224, 0, 0, 1);
|
||||
|
||||
/* Initialize the group allocation logic */
|
||||
|
||||
@ -110,12 +110,12 @@ void igmp_devinit(struct net_driver_s *dev)
|
||||
|
||||
/* Add the all systems address to the group */
|
||||
|
||||
(void)igmp_grpalloc(dev, &g_allsystems);
|
||||
(void)igmp_grpalloc(dev, &g_ipv4_allsystems);
|
||||
|
||||
/* Allow the IGMP messages at the MAC level */
|
||||
|
||||
igmp_addmcastmac(dev, &g_allrouters);
|
||||
igmp_addmcastmac(dev, &g_allsystems);
|
||||
igmp_addmcastmac(dev, &g_ipv4_allrouters);
|
||||
igmp_addmcastmac(dev, &g_ipv4_allsystems);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET_IGMP */
|
||||
|
@ -117,8 +117,8 @@
|
||||
void igmp_input(struct net_driver_s *dev)
|
||||
{
|
||||
FAR struct igmp_group_s *group;
|
||||
net_ipaddr_t destipaddr;
|
||||
net_ipaddr_t grpaddr;
|
||||
in_addr_t destipaddr;
|
||||
in_addr_t grpaddr;
|
||||
unsigned int ticks;
|
||||
|
||||
nllvdbg("IGMP message: %04x%04x\n", IGMPBUF->destipaddr[1], IGMPBUF->destipaddr[0]);
|
||||
@ -165,7 +165,7 @@ void igmp_input(struct net_driver_s *dev)
|
||||
|
||||
/* Check if the query was sent to all systems */
|
||||
|
||||
if (net_ipaddr_cmp(destipaddr, g_allsystems))
|
||||
if (net_ipaddr_cmp(destipaddr, g_ipv4_allsystems))
|
||||
{
|
||||
/* Yes... Now check the if this this is a general or a group
|
||||
* specific query.
|
||||
@ -206,7 +206,7 @@ void igmp_input(struct net_driver_s *dev)
|
||||
{
|
||||
/* Skip over the all systems group entry */
|
||||
|
||||
if (!net_ipaddr_cmp(member->grpaddr, g_allsystems))
|
||||
if (!net_ipaddr_cmp(member->grpaddr, g_ipv4_allsystems))
|
||||
{
|
||||
ticks = net_dsec2tick((int)IGMPBUF->maxresp);
|
||||
if (IS_IDLEMEMBER(member->flags) ||
|
||||
|
@ -152,7 +152,7 @@ int igmp_joingroup(struct net_driver_s *dev, FAR const struct in_addr *grpaddr)
|
||||
|
||||
/* Add the group (MAC) address to the ether drivers MAC filter list */
|
||||
|
||||
igmp_addmcastmac(dev, (FAR net_ipaddr_t *)&grpaddr->s_addr);
|
||||
igmp_addmcastmac(dev, (FAR in_addr_t *)&grpaddr->s_addr);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
@ -174,7 +174,7 @@ int igmp_leavegroup(struct net_driver_s *dev, FAR const struct in_addr *grpaddr)
|
||||
|
||||
/* And remove the group address from the ethernet drivers MAC filter set */
|
||||
|
||||
igmp_removemcastmac(dev, (FAR net_ipaddr_t *)&grpaddr->s_addr);
|
||||
igmp_removemcastmac(dev, (FAR in_addr_t *)&grpaddr->s_addr);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void igmp_mcastmac(net_ipaddr_t *ip, FAR uint8_t *mac)
|
||||
static void igmp_mcastmac(in_addr_t *ip, FAR uint8_t *mac)
|
||||
{
|
||||
/* This mapping is from the IETF IN RFC 1700 */
|
||||
|
||||
@ -99,7 +99,7 @@ static void igmp_mcastmac(net_ipaddr_t *ip, FAR uint8_t *mac)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void igmp_addmcastmac(FAR struct net_driver_s *dev, FAR net_ipaddr_t *ip)
|
||||
void igmp_addmcastmac(FAR struct net_driver_s *dev, FAR in_addr_t *ip)
|
||||
{
|
||||
uint8_t mcastmac[6];
|
||||
|
||||
@ -119,7 +119,7 @@ void igmp_addmcastmac(FAR struct net_driver_s *dev, FAR net_ipaddr_t *ip)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void igmp_removemcastmac(FAR struct net_driver_s *dev, FAR net_ipaddr_t *ip)
|
||||
void igmp_removemcastmac(FAR struct net_driver_s *dev, FAR in_addr_t *ip)
|
||||
{
|
||||
uint8_t mcastmac[6];
|
||||
|
||||
|
@ -82,7 +82,7 @@
|
||||
static inline void igmp_sched_send(FAR struct net_driver_s *dev,
|
||||
FAR struct igmp_group_s *group)
|
||||
{
|
||||
net_ipaddr_t *dest;
|
||||
in_addr_t *dest;
|
||||
|
||||
/* Check what kind of message we need to send. There are only two
|
||||
* possibilities:
|
||||
@ -99,7 +99,7 @@ static inline void igmp_sched_send(FAR struct net_driver_s *dev,
|
||||
else
|
||||
{
|
||||
DEBUGASSERT(group->msgid == IGMP_LEAVE_GROUP);
|
||||
dest = &g_allrouters;
|
||||
dest = &g_ipv4_allrouters;
|
||||
nllvdbg("Send IGMP_LEAVE_GROUP, dest=%08x flags=%02x\n",
|
||||
*dest, group->flags);
|
||||
IGMP_STATINCR(g_netstats.igmp.leave_sched);
|
||||
|
@ -122,7 +122,7 @@ static uint16_t igmp_chksum(FAR uint8_t *buffer, int buflen)
|
||||
****************************************************************************/
|
||||
|
||||
void igmp_send(FAR struct net_driver_s *dev, FAR struct igmp_group_s *group,
|
||||
FAR net_ipaddr_t *destipaddr)
|
||||
FAR in_addr_t *destipaddr)
|
||||
{
|
||||
nllvdbg("msgid: %02x destipaddr: %08x\n", group->msgid, (int)*destipaddr);
|
||||
|
||||
|
@ -122,27 +122,61 @@ FAR struct net_driver_s *netdev_default(void);
|
||||
/* netdev_txnotify.c *********************************************************/
|
||||
|
||||
#if CONFIG_NSOCKET_DESCRIPTORS > 0
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
# ifdef CONFIG_NET_MULTILINK
|
||||
void netdev_txnotify(const net_ipaddr_t lipaddr, const net_ipaddr_t ripaddr);
|
||||
void netdev_ipv4_txnotify(in_addr_t lipaddr, in_addr_t ripaddr);
|
||||
# else
|
||||
void netdev_txnotify(const net_ipaddr_t ripaddr);
|
||||
void netdev_ipv4_txnotify(in_addr_t ripaddr);
|
||||
# endif
|
||||
#endif
|
||||
#endif /* CONFIG_NET_IPv4 */
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
# ifdef CONFIG_NET_MULTILINK
|
||||
void netdev_ipv6_txnotify(FAR const net_ipv6addr_t lipaddr,
|
||||
FAR const net_ipv6addr_t ripaddr);
|
||||
# else
|
||||
void netdev_ipv6_txnotify(FAR const net_ipv6addr_t ripaddr);
|
||||
# endif
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
#endif /* CONFIG_NSOCKET_DESCRIPTORS > 0 */
|
||||
|
||||
/* netdev_rxnotify.c *********************************************************/
|
||||
|
||||
#if CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET_RXAVAIL)
|
||||
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
# ifdef CONFIG_NET_MULTILINK
|
||||
void netdev_rxnotify(const net_ipaddr_t lipaddr, const net_ipaddr_t ripaddr);
|
||||
void netdev_ipv4_rxnotify(in_addr_t lipaddr, in_addr_t ripaddr);
|
||||
# else
|
||||
void netdev_rxnotify(const net_ipaddr_t ripaddr);
|
||||
void netdev_ipv4_rxnotify(in_addr_t ripaddr);
|
||||
# endif
|
||||
#endif /* CONFIG_NET_IPv4 */
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
# ifdef CONFIG_NET_MULTILINK
|
||||
void netdev_ipv6_rxnotify(FAR const net_ipv6addr_t lipaddr,
|
||||
FAR const net_ipv6addr_t ripaddr);
|
||||
# else
|
||||
void netdev_ipv6_rxnotify(FAR const net_ipv6addr_t ripaddr);
|
||||
# endif
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
#else
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
# ifdef CONFIG_NET_MULTILINK
|
||||
# define netdev_rxnotify(lipaddr,ripaddr)
|
||||
# define netdev_ipv4_rxnotify(lipaddr,ripaddr)
|
||||
# else
|
||||
# define netdev_rxnotify(ripaddr)
|
||||
# define netdev_ipv4_rxnotify(ripaddr)
|
||||
# endif
|
||||
#endif /* CONFIG_NET_IPv4 */
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
# ifdef CONFIG_NET_MULTILINK
|
||||
# define netdev_ipv6_rxnotify(lipaddr,ripaddr)
|
||||
# else
|
||||
# define netdev_ipv6_rxnotify(ripaddr)
|
||||
# endif
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
#endif
|
||||
|
||||
/* netdev_count.c ************************************************************/
|
||||
|
@ -211,18 +211,18 @@ FAR struct net_driver_s *netdev_findby_ipv4addr(in_addr_t ripaddr)
|
||||
{
|
||||
struct net_driver_s *dev;
|
||||
#ifdef CONFIG_NET_ROUTE
|
||||
net_ipaddr_t router;
|
||||
in_addr_t router;
|
||||
int ret;
|
||||
#endif
|
||||
|
||||
/* First, check if this is the broadcast IP address */
|
||||
|
||||
if (net_ipv4addr_cmp(ripaddr, g_alloneaddr))
|
||||
if (net_ipv4addr_cmp(ripaddr, g_ipv4_alloneaddr))
|
||||
{
|
||||
#ifdef CONFIG_NET_MULTILINK
|
||||
/* Yes.. Check the local, bound address. Is it INADDR_ANY? */
|
||||
|
||||
if (net_ipv4addr_cmp(lipaddr, g_allzeroaddr))
|
||||
if (net_ipv4addr_cmp(lipaddr, g_ipv4_allzeroaddr))
|
||||
{
|
||||
/* Yes.. In this case, I think we are supposed to send the
|
||||
* broadcast packet out ALL local networks. I am not sure
|
||||
@ -262,7 +262,7 @@ FAR struct net_driver_s *netdev_findby_ipv4addr(in_addr_t ripaddr)
|
||||
* address of a router that can forward packets to the external network.
|
||||
*/
|
||||
|
||||
ret = net_router(ripaddr, &router);
|
||||
ret = net_ipv4_router(ripaddr, &router);
|
||||
if (ret >= 0)
|
||||
{
|
||||
/* Success... try to find the network device associated with the local
|
||||
@ -329,18 +329,18 @@ FAR struct net_driver_s *netdev_findby_ipv6addr(const net_ipv6addr_t ripaddr)
|
||||
{
|
||||
struct net_driver_s *dev;
|
||||
#ifdef CONFIG_NET_ROUTE
|
||||
net_ipaddr_t router;
|
||||
net_ipv6addr_t router;
|
||||
int ret;
|
||||
#endif
|
||||
|
||||
/* First, check if this is the broadcast IP address */
|
||||
|
||||
if (net_ipv6addr_cmp(ripaddr, g_alloneaddr))
|
||||
if (net_ipv6addr_cmp(ripaddr, g_ipv6_alloneaddr))
|
||||
{
|
||||
#ifdef CONFIG_NET_MULTILINK
|
||||
/* Yes.. Check the local, bound address. Is it INADDR_ANY? */
|
||||
|
||||
if (net_ipv6addr_cmp(lipaddr, g_allzeroaddr))
|
||||
if (net_ipv6addr_cmp(lipaddr, g_ipv6_allzeroaddr))
|
||||
{
|
||||
/* Yes.. In this case, I think we are supposed to send the
|
||||
* broadcast packet out ALL local networks. I am not sure
|
||||
@ -380,7 +380,7 @@ FAR struct net_driver_s *netdev_findby_ipv6addr(const net_ipv6addr_t ripaddr)
|
||||
* address of a router that can forward packets to the external network.
|
||||
*/
|
||||
|
||||
ret = net_router(ripaddr, router);
|
||||
ret = net_ipv6_router(ripaddr, router);
|
||||
if (ret >= 0)
|
||||
{
|
||||
/* Success... try to find the network device associated with the local
|
||||
|
@ -82,6 +82,144 @@
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ioctl_addipv4route
|
||||
*
|
||||
* Description:
|
||||
* Add an IPv4 route to the routing table.
|
||||
*
|
||||
* Input Parameters:
|
||||
* rentry - Describes the route to be added
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_NET_ROUTE) && defined(CONFIG_NET_IPv4)
|
||||
static int ioctl_addipv4route(FAR struct rtentry *rtentry)
|
||||
{
|
||||
FAR struct sockaddr_in *addr;
|
||||
in_addr_t target;
|
||||
in_addr_t netmask;
|
||||
in_addr_t router;
|
||||
|
||||
addr = (FAR struct sockaddr_in *)rtentry->rt_target;
|
||||
target = (in_addr_t)addr->sin_addr.s_addr;
|
||||
|
||||
addr = (FAR struct sockaddr_in *)rtentry->rt_netmask;
|
||||
netmask = (in_addr_t)addr->sin_addr.s_addr;
|
||||
|
||||
/* The router is an optional argument */
|
||||
|
||||
if (rtentry->rt_router)
|
||||
{
|
||||
addr = (FAR struct sockaddr_in *)rtentry->rt_router;
|
||||
router = (in_addr_t)addr->sin_addr.s_addr;
|
||||
}
|
||||
else
|
||||
{
|
||||
router = 0;
|
||||
}
|
||||
|
||||
return net_addroute(target, netmask, router);
|
||||
}
|
||||
#endif /* CONFIG_NET_ROUTE && CONFIG_NET_IPv4 */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ioctl_addipv6route
|
||||
*
|
||||
* Description:
|
||||
* Add an IPv6 route to the routing table.
|
||||
*
|
||||
* Input Parameters:
|
||||
* rentry - Describes the route to be added
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_NET_ROUTE) && defined(CONFIG_NET_IPv6)
|
||||
static int ioctl_addipv6route(FAR struct rtentry *rtentry)
|
||||
{
|
||||
FAR struct sockaddr_in6 *addr;
|
||||
net_ipv6addr_t target;
|
||||
net_ipv6addr_t netmask;
|
||||
net_ipv6addr_t router;
|
||||
|
||||
addr = (FAR struct sockaddr_in6 *)rtentry->rt_target;
|
||||
target = (net_ipv6addr_t)addr->sin6_addr.u6_addr16;
|
||||
|
||||
addr = (FAR struct sockaddr_in6 *)rtentry->rt_netmask;
|
||||
netmask = (net_ipv6addr_t)addr->sin6_addr.u6_addr16;
|
||||
|
||||
/* The router is an optional argument */
|
||||
|
||||
if (rtentry->rt_router)
|
||||
{
|
||||
addr = (FAR struct sockaddr_in6 *)rtentry->rt_router;
|
||||
router = (net_ipv6addr_t)addr->sin6_addr.u6_addr16;
|
||||
}
|
||||
else
|
||||
{
|
||||
router = NULL;
|
||||
}
|
||||
|
||||
return net_addroute(target, netmask, router);
|
||||
}
|
||||
#endif /* CONFIG_NET_ROUTE && CONFIG_NET_IPv6 */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ioctl_delipv4route
|
||||
*
|
||||
* Description:
|
||||
* Delete an IPv4 route to the routing table.
|
||||
*
|
||||
* Input Parameters:
|
||||
* rentry - Describes the route to be deleted
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_NET_ROUTE) && defined(CONFIG_NET_IPv4)
|
||||
static int ioctl_delipv4route(FAR struct rtentry *rtentry)
|
||||
{
|
||||
FAR struct sockaddr_in *addr;
|
||||
in_addr_t target;
|
||||
in_addr_t netmask;
|
||||
|
||||
addr = (FAR struct sockaddr_in *)rtentry->rt_target;
|
||||
target = (in_addr_t)addr->sin_addr.s_addr;
|
||||
|
||||
addr = (FAR struct sockaddr_in *)rtentry->rt_netmask;
|
||||
netmask = (in_addr_t)addr->sin_addr.s_addr;
|
||||
|
||||
return net_delroute(target, netmask);
|
||||
}
|
||||
#endif /* CONFIG_NET_ROUTE && CONFIG_NET_IPv4 */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ioctl_delipv6route
|
||||
*
|
||||
* Description:
|
||||
* Delete an IPv6 route to the routing table.
|
||||
*
|
||||
* Input Parameters:
|
||||
* rentry - Describes the route to be deleted
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_NET_ROUTE) && defined(CONFIG_NET_IPv6)
|
||||
static int ioctl_delipv6route(FAR struct rtentry *rtentry)
|
||||
{
|
||||
FAR struct sockaddr_in6 *addr;
|
||||
net_ipv6addr_t target;
|
||||
net_ipv6addr_t netmask;
|
||||
|
||||
addr = (FAR struct sockaddr_in6 *)rtentry->rt_target;
|
||||
target = (net_ipv6addr_t)addr->sin6_addr.u6_addr16;
|
||||
|
||||
addr = (FAR struct sockaddr_in6 *)rtentry->rt_netmask;
|
||||
netmask = (net_ipv6addr_t)addr->sin6_addr.u6_addr16;
|
||||
|
||||
return net_delroute(target, netmask);
|
||||
}
|
||||
#endif /* CONFIG_NET_ROUTE && CONFIG_NET_IPv6 */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ioctl_getipv4addr
|
||||
*
|
||||
@ -90,7 +228,7 @@
|
||||
*
|
||||
* Input Parameters:
|
||||
* outaddr - Pointer to the user-provided memory to receive the address.
|
||||
* inaddr - The source IP adress in the device structure.
|
||||
* inaddr - The source IP address in the device structure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@ -741,99 +879,67 @@ static int netdev_rtioctl(FAR struct socket *psock, int cmd,
|
||||
{
|
||||
case SIOCADDRT: /* Add an entry to the routing table */
|
||||
{
|
||||
if (rtentry)
|
||||
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
|
||||
FAR struct sockaddr_in *addr;
|
||||
#endif
|
||||
/* The target address and the netmask are required values */
|
||||
|
||||
if (!retentry || !rtentry->rt_target || !rtentry->rt_netmask)
|
||||
{
|
||||
net_ipaddr_t target;
|
||||
net_ipaddr_t netmask;
|
||||
net_ipaddr_t router;
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
FAR struct sockaddr_in6 *addr;
|
||||
#else
|
||||
FAR struct sockaddr_in *addr;
|
||||
#endif
|
||||
/* The target address and the netmask are required value */
|
||||
|
||||
if (!rtentry->rt_target || !rtentry->rt_netmask)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
addr = (FAR struct sockaddr_in6 *)rtentry->rt_target;
|
||||
target = (net_ipaddr_t)addr->sin6_addr.u6_addr16;
|
||||
|
||||
addr = (FAR struct sockaddr_in6 *)rtentry->rt_netmask;
|
||||
netmask = (net_ipaddr_t)addr->sin6_addr.u6_addr16;
|
||||
|
||||
/* The router is an optional argument */
|
||||
|
||||
if (rtentry->rt_router)
|
||||
{
|
||||
addr = (FAR struct sockaddr_in6 *)rtentry->rt_router;
|
||||
router = (net_ipaddr_t)addr->sin6_addr.u6_addr16;
|
||||
}
|
||||
else
|
||||
{
|
||||
router = NULL;
|
||||
}
|
||||
#else
|
||||
addr = (FAR struct sockaddr_in *)rtentry->rt_target;
|
||||
target = (net_ipaddr_t)addr->sin_addr.s_addr;
|
||||
|
||||
addr = (FAR struct sockaddr_in *)rtentry->rt_netmask;
|
||||
netmask = (net_ipaddr_t)addr->sin_addr.s_addr;
|
||||
|
||||
/* The router is an optional argument */
|
||||
|
||||
if (rtentry->rt_router)
|
||||
{
|
||||
addr = (FAR struct sockaddr_in *)rtentry->rt_router;
|
||||
router = (net_ipaddr_t)addr->sin_addr.s_addr;
|
||||
}
|
||||
else
|
||||
{
|
||||
router = 0;
|
||||
}
|
||||
#endif
|
||||
ret = net_addroute(target, netmask, router);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
|
||||
addr = (FAR struct sockaddr_in *)rtentry->rt_target;
|
||||
if (addr->sin_family == AF_INET)
|
||||
{
|
||||
ret = ioctl_addipv4route(rtentry);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = ioctl_addipv6route(rtentry);
|
||||
}
|
||||
|
||||
#elif defined(CONFIG_NET_IPv4)
|
||||
ret = ioctl_addipv4route(rtentry);
|
||||
#elif defined(CONFIG_NET_IPv6)
|
||||
ret = ioctl_addipv6route(rtentry);
|
||||
#else
|
||||
ret = -EAFNOSUPPORT;
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case SIOCDELRT: /* Delete an entry from the routing table */
|
||||
{
|
||||
if (rtentry)
|
||||
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
|
||||
FAR struct sockaddr_in *addr;
|
||||
#endif
|
||||
/* The target address and the netmask are required values */
|
||||
|
||||
if (!retentry || !rtentry->rt_target || !rtentry->rt_netmask)
|
||||
{
|
||||
net_ipaddr_t target;
|
||||
net_ipaddr_t netmask;
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
FAR struct sockaddr_in6 *addr;
|
||||
#else
|
||||
FAR struct sockaddr_in *addr;
|
||||
#endif
|
||||
|
||||
/* The target address and the netmask are required value */
|
||||
|
||||
if (!rtentry->rt_target || !rtentry->rt_netmask)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
addr = (FAR struct sockaddr_in6 *)rtentry->rt_target;
|
||||
target = (net_ipaddr_t)addr->sin6_addr.u6_addr16;
|
||||
|
||||
addr = (FAR struct sockaddr_in6 *)rtentry->rt_netmask;
|
||||
netmask = (net_ipaddr_t)addr->sin6_addr.u6_addr16;
|
||||
#else
|
||||
addr = (FAR struct sockaddr_in *)rtentry->rt_target;
|
||||
target = (net_ipaddr_t)addr->sin_addr.s_addr;
|
||||
|
||||
addr = (FAR struct sockaddr_in *)rtentry->rt_netmask;
|
||||
netmask = (net_ipaddr_t)addr->sin_addr.s_addr;
|
||||
#endif
|
||||
ret = net_delroute(target, netmask);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
|
||||
addr = (FAR struct sockaddr_in *)rtentry->rt_target;
|
||||
if (addr->sin_family == AF_INET)
|
||||
{
|
||||
ret = ioctl_delipv4route(rtentry);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = ioctl_delipv6route(rtentry);
|
||||
}
|
||||
|
||||
#elif defined(CONFIG_NET_IPv4)
|
||||
ret = ioctl_delipv4route(rtentry);
|
||||
#elif defined(CONFIG_NET_IPv6)
|
||||
ret = ioctl_delipv6route(rtentry);
|
||||
#else
|
||||
ret = -EAFNOSUPPORT;
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* net/netdev/netdev_rxnotify.c
|
||||
*
|
||||
* Copyright (C) 2013-2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2013-2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -75,13 +75,15 @@
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: netdev_rxnotify
|
||||
* Function: netdev_ipv4_rxnotify
|
||||
*
|
||||
* Description:
|
||||
* Notify the device driver that the application waits for RX data.
|
||||
* Notify the device driver that forwards the IPv4 address that the
|
||||
* application waits for RX data.
|
||||
*
|
||||
* Parameters:
|
||||
* ripaddr - The remote address to send the data
|
||||
* lipaddr - The local board IPv6 address of the socket
|
||||
* ripaddr - The remote IPv4 address to send the data
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
@ -91,10 +93,11 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
#ifdef CONFIG_NET_MULTILINK
|
||||
void netdev_rxnotify(const net_ipaddr_t lipaddr, const net_ipaddr_t ripaddr)
|
||||
void netdev_ipv4_rxnotify(in_addr_t lipaddr, in_addr_t ripaddr)
|
||||
#else
|
||||
void netdev_rxnotify(const net_ipaddr_t ripaddr)
|
||||
void netdev_ipv4_rxnotify(in_addr_t ripaddr)
|
||||
#endif
|
||||
{
|
||||
FAR struct net_driver_s *dev;
|
||||
@ -114,5 +117,52 @@ void netdev_rxnotify(const net_ipaddr_t ripaddr)
|
||||
(void)dev->d_rxavail(dev);
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_NET_IPv4 */
|
||||
|
||||
/****************************************************************************
|
||||
* Function: netdev_ipv6_rxnotify
|
||||
*
|
||||
* Description:
|
||||
* Notify the device driver that forwards the IPv6 address that the
|
||||
* application waits for RX data.
|
||||
*
|
||||
* Parameters:
|
||||
* lipaddr - The local board IPv6 address of the socket
|
||||
* ripaddr - The remote IPv6 address to send the data
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
* Assumptions:
|
||||
* Called from normal user mode
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
#ifdef CONFIG_NET_MULTILINK
|
||||
void netdev_ipv6_rxnotify(FAR const net_ipv6addr_t lipaddr,
|
||||
FAR const net_ipv6addr_t ripaddr)
|
||||
#else
|
||||
void netdev_ipv6_rxnotify(FAR const net_ipv6addr_t ripaddr)
|
||||
#endif
|
||||
{
|
||||
FAR struct net_driver_s *dev;
|
||||
|
||||
/* Find the device driver that serves the subnet of the remote address */
|
||||
|
||||
#ifdef CONFIG_NET_MULTILINK
|
||||
dev = netdev_findby_ipv6addr(lipaddr, ripaddr);
|
||||
#else
|
||||
dev = netdev_findby_ipv6addr(ripaddr);
|
||||
#endif
|
||||
|
||||
if (dev && dev->d_rxavail)
|
||||
{
|
||||
/* Notify the device driver that new RX data is available. */
|
||||
|
||||
(void)dev->d_rxavail(dev);
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS && CONFIG_NET_RXAVAIL */
|
||||
|
@ -75,12 +75,14 @@
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: netdev_txnotify
|
||||
* Function: netdev_ipv4_txnotify
|
||||
*
|
||||
* Description:
|
||||
* Notify the device driver that new TX data is available.
|
||||
* Notify the device driver that forwards the IPv4 address that new TX
|
||||
* data is available.
|
||||
*
|
||||
* Parameters:
|
||||
* lipaddr - The local address bound to the socket
|
||||
* ripaddr - The remote address to send the data
|
||||
*
|
||||
* Returned Value:
|
||||
@ -91,11 +93,12 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_MULTILINK
|
||||
void netdev_txnotify(const net_ipaddr_t lipaddr, const net_ipaddr_t ripaddr)
|
||||
#else
|
||||
void netdev_txnotify(const net_ipaddr_t ripaddr)
|
||||
#endif
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
# ifdef CONFIG_NET_MULTILINK
|
||||
void netdev_ipv4_txnotify(in_addr_t lipaddr, in_addr_t ripaddr)
|
||||
# else
|
||||
void netdev_ipv4_txnotify(in_addr_t ripaddr)
|
||||
# endif
|
||||
{
|
||||
FAR struct net_driver_s *dev;
|
||||
|
||||
@ -114,5 +117,53 @@ void netdev_txnotify(const net_ipaddr_t ripaddr)
|
||||
(void)dev->d_txavail(dev);
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_NET_IPv4 */
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Function: netdev_ipv6_txnotify
|
||||
*
|
||||
* Description:
|
||||
* Notify the device driver that forwards the IPv4 address that new TX
|
||||
* data is available.
|
||||
*
|
||||
* Parameters:
|
||||
* lipaddr - The local address bound to the socket
|
||||
* ripaddr - The remote address to send the data
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
* Assumptions:
|
||||
* Called from normal user mode
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
#ifdef CONFIG_NET_MULTILINK
|
||||
void netdev_ipv6_txnotify(FAR const net_ipv6addr_t lipaddr,
|
||||
FAR const net_ipv6addr_t ripaddr)
|
||||
#else
|
||||
void netdev_ipv6_txnotify(FAR const net_ipv6addr_t ripaddr)
|
||||
#endif
|
||||
{
|
||||
FAR struct net_driver_s *dev;
|
||||
|
||||
/* Find the device driver that serves the subnet of the remote address */
|
||||
|
||||
#ifdef CONFIG_NET_MULTILINK
|
||||
dev = netdev_findby_ipv6addr(lipaddr, ripaddr);
|
||||
#else
|
||||
dev = netdev_findby_ipv6addr(ripaddr);
|
||||
#endif
|
||||
|
||||
if (dev && dev->d_txavail)
|
||||
{
|
||||
/* Notify the device driver that new TX data is available. */
|
||||
|
||||
(void)dev->d_txavail(dev);
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */
|
||||
|
@ -267,14 +267,14 @@ ssize_t psock_pkt_send(FAR struct socket *psock, FAR const void *buf,
|
||||
dev = netdev_findbyname("eth0");
|
||||
|
||||
/* Notify the device driver that new TX data is available.
|
||||
* NOTES: This is in essence what netdev_txnotify() does, which
|
||||
* is not possible to call since it expects a net_ipaddr_t as
|
||||
* NOTES: This is in essence what netdev_ipv4_txnotify() does,
|
||||
* which is not possible to call since it expects a in_addr_t as
|
||||
* its single argument to lookup the network interface.
|
||||
*/
|
||||
|
||||
dev->d_txavail(dev);
|
||||
|
||||
/* Wait for the send to complete or an error to occure: NOTES: (1)
|
||||
/* Wait for the send to complete or an error to occur: NOTES: (1)
|
||||
* net_lockedwait will also terminate if a signal is received, (2)
|
||||
* interrupts may be disabled! They will be re-enabled while the
|
||||
* task sleeps and automatically re-enabled when the task restarts.
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* net/route/net_addroute.c
|
||||
*
|
||||
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2013, 2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -78,8 +78,7 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int net_addroute(net_ipaddr_t target, net_ipaddr_t netmask,
|
||||
net_ipaddr_t router)
|
||||
int net_addroute(in_addr_t target, in_addr_t netmask, in_addr_t router)
|
||||
{
|
||||
FAR struct net_route_s *route;
|
||||
net_lock_t save;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* net/route/net_delroute.c
|
||||
*
|
||||
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2013, 2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -56,8 +56,8 @@
|
||||
struct route_match_s
|
||||
{
|
||||
FAR struct net_route_s *prev; /* Predecessor in the list */
|
||||
net_ipaddr_t target; /* The target IP address to match */
|
||||
net_ipaddr_t netmask; /* The network mask to match */
|
||||
in_addr_t target; /* The target IP address to match */
|
||||
in_addr_t netmask; /* The network mask to match */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
@ -134,7 +134,7 @@ static int net_match(FAR struct net_route_s *route, FAR void *arg)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int net_delroute(net_ipaddr_t target, net_ipaddr_t netmask)
|
||||
int net_delroute(in_addr_t target, in_addr_t netmask)
|
||||
{
|
||||
struct route_match_s match;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* net/route/net_router.c
|
||||
*
|
||||
* Copyright (C) 2013-2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2013-2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -54,21 +54,31 @@
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
struct route_match_s
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
struct route_ipv4_match_s
|
||||
{
|
||||
net_ipaddr_t target; /* The target IP address on an external network to match */
|
||||
net_ipaddr_t router; /* The IP address of the router on one of our networks*/
|
||||
in_addr_t target; /* Target IPv4 address on an external network to match */
|
||||
in_addr_t router; /* IPv4 address of the router on one of our networks*/
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
struct route_ipv6_match_s
|
||||
{
|
||||
net_ipv6addr_t target; /* arget IPv6 address on an external network to match */
|
||||
net_ipv6addr_t router; /* IPv6 address of the router on one of our networks*/
|
||||
};
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: net_match
|
||||
* Function: net_ipv4_match
|
||||
*
|
||||
* Description:
|
||||
* Return 1 if the route is available
|
||||
* Return 1 if the IPv4 route is available
|
||||
*
|
||||
* Parameters:
|
||||
* route - The next route to examine
|
||||
@ -79,16 +89,17 @@ struct route_match_s
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int net_match(FAR struct net_route_s *route, FAR void *arg)
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
static int net_ipv4_match(FAR struct net_route_s *route, FAR void *arg)
|
||||
{
|
||||
FAR struct route_match_s *match = (FAR struct route_match_s *)arg;
|
||||
FAR struct route_ipv4_match_s *match = (FAR struct route_ipv4_match_s *)arg;
|
||||
|
||||
/* To match, the masked target addresses must be the same. In the event
|
||||
* of multiple matches, only the first is returned. There is not (yet) any
|
||||
* concept for the precedence of networks.
|
||||
*/
|
||||
|
||||
if (net_ipaddr_maskcmp(route->target, match->target, route->netmask))
|
||||
if (net_ipv4addr_maskcmp(route->target, match->target, route->netmask))
|
||||
{
|
||||
/* They match.. Copy the router address */
|
||||
|
||||
@ -98,66 +109,98 @@ static int net_match(FAR struct net_route_s *route, FAR void *arg)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_NET_IPv4 */
|
||||
|
||||
/****************************************************************************
|
||||
* Function: net_ipv6_match
|
||||
*
|
||||
* Description:
|
||||
* Return 1 if the IPv6 route is available
|
||||
*
|
||||
* Parameters:
|
||||
* route - The next route to examine
|
||||
* arg - The match values (cast to void*)
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 if the entry is not a match; 1 if the entry matched and was cleared.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
static int net_ipv6_match(FAR struct net_route_s *route, FAR void *arg)
|
||||
{
|
||||
#if 1
|
||||
# warning Missing logic
|
||||
#else
|
||||
FAR struct route_ipv4_match_s *match = (FAR struct route_ipv4_match_s *)arg;
|
||||
|
||||
/* To match, the masked target addresses must be the same. In the event
|
||||
* of multiple matches, only the first is returned. There is not (yet) any
|
||||
* concept for the precedence of networks.
|
||||
*/
|
||||
|
||||
if (net_ipv6ddr_maskcmp(route->target, match->target, route->netmask))
|
||||
{
|
||||
/* They match.. Copy the router address */
|
||||
|
||||
net_ipaddr_copy(match->router, route->router);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: net_router
|
||||
* Function: net_ipv4_router
|
||||
*
|
||||
* Description:
|
||||
* Given an IP address on a external network, return the address of the
|
||||
* Given an IPv4 address on a external network, return the address of the
|
||||
* router on a local network that can forward to the external network.
|
||||
*
|
||||
* Parameters:
|
||||
* target - An IP address on a remote network to use in the lookup.
|
||||
* target - An IPv4 address on a remote network to use in the lookup.
|
||||
* router - The address of router on a local network that can forward our
|
||||
* packets to the target.
|
||||
*
|
||||
* NOTE: For IPv6, router will be an array, for IPv4 it will be a scalar
|
||||
* value. Hence, the change in the function signature.
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; Negated errno on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
int net_router(net_ipaddr_t target, net_ipaddr_t router)
|
||||
#else
|
||||
int net_router(net_ipaddr_t target, FAR net_ipaddr_t *router)
|
||||
#endif
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
int net_ipv4_router(in_addr_t target, FAR in_addr_t *router)
|
||||
{
|
||||
struct route_match_s match;
|
||||
struct route_ipv4_match_s match;
|
||||
int ret;
|
||||
|
||||
/* Do not route the special broadcast IP address */
|
||||
|
||||
if (net_ipaddr_cmp(target, g_alloneaddr))
|
||||
if (net_ipaddr_cmp(target, g_ipv4_alloneaddr))
|
||||
{
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/* Set up the comparison structure */
|
||||
|
||||
memset(&match, 0, sizeof(struct route_match_s));
|
||||
memset(&match, 0, sizeof(struct route_ipv4_match_s));
|
||||
net_ipaddr_copy(match.target, target);
|
||||
|
||||
/* Find an router entry with the routing table that can forward to this
|
||||
* address
|
||||
*/
|
||||
|
||||
ret = net_foreachroute(net_match, &match);
|
||||
ret = net_foreachroute(net_ipv4_match, &match);
|
||||
if (ret > 0)
|
||||
{
|
||||
/* We found a route. Return the router address. */
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
net_ipaddr_copy(router, match.router);
|
||||
#else
|
||||
net_ipaddr_copy(*router, match.router);
|
||||
#endif
|
||||
net_ipv4addr_copy(*router, match.router);
|
||||
ret = OK;
|
||||
}
|
||||
else
|
||||
@ -169,5 +212,64 @@ int net_router(net_ipaddr_t target, FAR net_ipaddr_t *router)
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* CONFIG_NET_IPv4 */
|
||||
|
||||
/****************************************************************************
|
||||
* Function: net_ipv6_router
|
||||
*
|
||||
* Description:
|
||||
* Given an IPv6 address on a external network, return the address of the
|
||||
* router on a local network that can forward to the external network.
|
||||
*
|
||||
* Parameters:
|
||||
* target - An IPv6 address on a remote network to use in the lookup.
|
||||
* router - The address of router on a local network that can forward our
|
||||
* packets to the target.
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; Negated errno on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
int net_ipv6_router(net_ipv6addr_t target, net_ipv6addr_t router)
|
||||
{
|
||||
struct route_ipv6_match_s match;
|
||||
int ret;
|
||||
|
||||
/* Do not route the special broadcast IP address */
|
||||
|
||||
if (net_ipaddr_cmp(target, g_ipv6_alloneaddr))
|
||||
{
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/* Set up the comparison structure */
|
||||
|
||||
memset(&match, 0, sizeof(struct route_ipv6_match_s));
|
||||
net_ipaddr_copy(match.target, target);
|
||||
|
||||
/* Find an router entry with the routing table that can forward to this
|
||||
* address
|
||||
*/
|
||||
|
||||
ret = net_foreachroute(net_ipv6_match, &match);
|
||||
if (ret > 0)
|
||||
{
|
||||
/* We found a route. Return the router address. */
|
||||
|
||||
net_ipv6addr_copy(router, match.router);
|
||||
ret = OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* There is no route for this address */
|
||||
|
||||
ret = -ENOENT;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
#endif /* CONFIG_NET && CONFIG_NET_ROUTE */
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* net/route/netdev_router.c
|
||||
*
|
||||
* Copyright (C) 2013-2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2013-2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -55,22 +55,24 @@
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
struct route_devmatch_s
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
struct route_ipv4_devmatch_s
|
||||
{
|
||||
FAR struct net_driver_s *dev; /* The route must use this device */
|
||||
net_ipaddr_t target; /* The target IP address on an external network to match */
|
||||
net_ipaddr_t router; /* The IP address of the router on one of our networks*/
|
||||
in_addr_t target; /* Target IPv4 address on an external network to match */
|
||||
in_addr_t router; /* IPv6 address of the router on one of our networks*/
|
||||
};
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: net_devmatch
|
||||
* Function: net_ipv4_devmatch
|
||||
*
|
||||
* Description:
|
||||
* Return 1 if the route is available on the device's network.
|
||||
* Return 1 if the IPv4 route is available on the device's network.
|
||||
*
|
||||
* Parameters:
|
||||
* route - The next route to examine
|
||||
@ -81,9 +83,10 @@ struct route_devmatch_s
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int net_devmatch(FAR struct net_route_s *route, FAR void *arg)
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
static int net_ipv4_devmatch(FAR struct net_route_s *route, FAR void *arg)
|
||||
{
|
||||
FAR struct route_devmatch_s *match = (FAR struct route_devmatch_s *)arg;
|
||||
FAR struct route_ipv4_devmatch_s *match = (FAR struct route_ipv4_devmatch_s *)arg;
|
||||
FAR struct net_driver_s *dev = match->dev;
|
||||
|
||||
/* To match, (1) the masked target addresses must be the same, and (2) the
|
||||
@ -93,59 +96,99 @@ static int net_devmatch(FAR struct net_route_s *route, FAR void *arg)
|
||||
* not (yet) any concept for the precedence of networks.
|
||||
*/
|
||||
|
||||
if (net_ipaddr_maskcmp(route->target, match->target, route->netmask) &&
|
||||
net_ipaddr_maskcmp(route->router, dev->d_ipaddr, dev->d_netmask))
|
||||
if (net_ipv4addr_maskcmp(route->target, match->target, route->netmask) &&
|
||||
net_ipv4addr_maskcmp(route->router, dev->d_ipaddr, dev->d_netmask))
|
||||
{
|
||||
/* They match.. Copy the router address */
|
||||
|
||||
net_ipaddr_copy(match->router, route->router);
|
||||
net_ipv4addr_copy(match->router, route->router);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_NET_IPv4 */
|
||||
|
||||
/****************************************************************************
|
||||
* Function: net_ipv6_devmatch
|
||||
*
|
||||
* Description:
|
||||
* Return 1 if the IPv6 route is available on the device's network.
|
||||
*
|
||||
* Parameters:
|
||||
* route - The next route to examine
|
||||
* arg - The match values (cast to void*)
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 if the entry is not a match; 1 if the entry matched and was cleared.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
static int net_ipv6_devmatch(FAR struct net_route_s *route, FAR void *arg)
|
||||
{
|
||||
#if 1
|
||||
# warning Missing logic
|
||||
#else
|
||||
FAR struct route_ipv6_devmatch_s *match = (FAR struct route_ipv6_devmatch_s *)arg;
|
||||
FAR struct net_driver_s *dev = match->dev;
|
||||
|
||||
/* To match, (1) the masked target addresses must be the same, and (2) the
|
||||
* router address must like on the network provided by the device.
|
||||
*
|
||||
* In the event of multiple matches, only the first is returned. There
|
||||
* not (yet) any concept for the precedence of networks.
|
||||
*/
|
||||
|
||||
if (net_ipv6addr_maskcmp(route->target, match->target, route->netmask) &&
|
||||
net_ipv6addr_maskcmp(route->router, dev->d_ipaddr, dev->d_netmask))
|
||||
{
|
||||
/* They match.. Copy the router address */
|
||||
|
||||
net_ipv6addr_copy(match->router, route->router);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: netdev_router
|
||||
* Function: netdev_ipv4_router
|
||||
*
|
||||
* Description:
|
||||
* Given an IP address on a external network, return the address of the
|
||||
* Given an IPv4 address on a external network, return the address of the
|
||||
* router on a local network that can forward to the external network.
|
||||
* This is similar to net_router(). However, the set of routers is
|
||||
* This is similar to net_ipv4_router(). However, the set of routers is
|
||||
* constrained to those accessible by the specific device
|
||||
*
|
||||
* Parameters:
|
||||
* dev - We are committed to using this device.
|
||||
* target - An IP address on a remote network to use in the lookup.
|
||||
* target - An IPv4 address on a remote network to use in the lookup.
|
||||
* router - The address of router on a local network that can forward our
|
||||
* packets to the target.
|
||||
*
|
||||
* NOTE: For IPv6, router will be an array, for IPv4 it will be a scalar
|
||||
* value. Hence, the change in the function signature.
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
* A router address is always returned (which may just be, perhaps,
|
||||
* device's default router address)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
void netdev_router(FAR struct net_driver_s *dev, net_ipaddr_t target,
|
||||
net_ipaddr_t router)
|
||||
#else
|
||||
void netdev_router(FAR struct net_driver_s *dev, net_ipaddr_t target,
|
||||
FAR net_ipaddr_t *router)
|
||||
#endif
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
void netdev_ipv4_router(FAR struct net_driver_s *dev, in_addr_t target,
|
||||
FAR in_addr_t *router)
|
||||
{
|
||||
struct route_devmatch_s match;
|
||||
struct route_ipv4_devmatch_s match;
|
||||
int ret;
|
||||
|
||||
/* Set up the comparison structure */
|
||||
|
||||
memset(&match, 0, sizeof(struct route_devmatch_s));
|
||||
memset(&match, 0, sizeof(struct route_ipv4_devmatch_s));
|
||||
match.dev = dev;
|
||||
net_ipaddr_copy(match.target, target);
|
||||
|
||||
@ -153,16 +196,12 @@ void netdev_router(FAR struct net_driver_s *dev, net_ipaddr_t target,
|
||||
* address using this device.
|
||||
*/
|
||||
|
||||
ret = net_foreachroute(net_devmatch, &match);
|
||||
ret = net_foreachroute(net_ipv4_devmatch, &match);
|
||||
if (ret > 0)
|
||||
{
|
||||
/* We found a route. Return the router address. */
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
net_ipaddr_copy(router, match.target);
|
||||
#else
|
||||
net_ipaddr_copy(*router, match.target);
|
||||
#endif
|
||||
net_ipv4addr_copy(*router, match.target);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -170,12 +209,66 @@ void netdev_router(FAR struct net_driver_s *dev, net_ipaddr_t target,
|
||||
* of the device.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
net_ipaddr_copy(router, dev->d_draddr);
|
||||
#else
|
||||
net_ipaddr_copy(*router, dev->d_draddr);
|
||||
#endif
|
||||
net_ipv4addr_copy(*router, dev->d_draddr);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Function: netdev_ipv6_router
|
||||
*
|
||||
* Description:
|
||||
* Given an IPv6 address on a external network, return the address of the
|
||||
* router on a local network that can forward to the external network.
|
||||
* This is similar to net_ipv6_router(). However, the set of routers is
|
||||
* constrained to those accessible by the specific device
|
||||
*
|
||||
* Parameters:
|
||||
* dev - We are committed to using this device.
|
||||
* target - An IPv6 address on a remote network to use in the lookup.
|
||||
* router - The address of router on a local network that can forward our
|
||||
* packets to the target.
|
||||
*
|
||||
* Returned Value:
|
||||
* A router address is always returned (which may just be, perhaps,
|
||||
* device's default router address)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
void netdev_ipv6_router(FAR struct net_driver_s *dev,
|
||||
FAR const net_ipv6addr_t target,
|
||||
FAR net_ipv6addr_t router)
|
||||
{
|
||||
struct route_ipv6_devmatch_s match;
|
||||
int ret;
|
||||
|
||||
/* Set up the comparison structure */
|
||||
|
||||
memset(&match, 0, sizeof(struct route_ipv6_devmatch_s));
|
||||
match.dev = dev;
|
||||
net_ipaddr_copy(match.target, target);
|
||||
|
||||
/* Find an router entry with the routing table that can forward to this
|
||||
* address using this device.
|
||||
*/
|
||||
|
||||
ret = net_foreachroute(net_ipv6_devmatch, &match);
|
||||
if (ret > 0)
|
||||
{
|
||||
/* We found a route. Return the router address. */
|
||||
|
||||
net_ipv6addr_copy(router, match.target);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* There isn't a matching route.. fallback and use the default router
|
||||
* of the device.
|
||||
*/
|
||||
|
||||
net_ipv6addr_copy(router, dev->d_draddr);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_NET && CONFIG_NET_ROUTE */
|
||||
|
@ -67,9 +67,9 @@
|
||||
struct net_route_s
|
||||
{
|
||||
FAR struct net_route_s *flink; /* Supports a singly linked list */
|
||||
net_ipaddr_t target; /* The destination network */
|
||||
net_ipaddr_t netmask; /* The network address mask */
|
||||
net_ipaddr_t router; /* Route packets via this router */
|
||||
in_addr_t target; /* The destination network */
|
||||
in_addr_t netmask; /* The network address mask */
|
||||
in_addr_t router; /* Route packets via this router */
|
||||
};
|
||||
|
||||
/* Type of the call out function pointer provided to net_foreachroute() */
|
||||
@ -162,8 +162,8 @@ void net_freeroute(FAR struct net_route_s *route);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int net_addroute(net_ipaddr_t target, net_ipaddr_t netmask,
|
||||
net_ipaddr_t router);
|
||||
int net_addroute(in_addr_t target, in_addr_t netmask,
|
||||
in_addr_t router);
|
||||
|
||||
/****************************************************************************
|
||||
* Function: net_delroute
|
||||
@ -178,22 +178,40 @@ int net_addroute(net_ipaddr_t target, net_ipaddr_t netmask,
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int net_delroute(net_ipaddr_t target, net_ipaddr_t netmask);
|
||||
int net_delroute(in_addr_t target, in_addr_t netmask);
|
||||
|
||||
/****************************************************************************
|
||||
* Function: net_router
|
||||
* Function: net_ipv4_router
|
||||
*
|
||||
* Description:
|
||||
* Given an IP address on a external network, return the address of the
|
||||
* Given an IPv4 address on a external network, return the address of the
|
||||
* router on a local network that can forward to the external network.
|
||||
*
|
||||
* Parameters:
|
||||
* target - An IP address on a remote network to use in the lookup.
|
||||
* target - An IPv4 address on a remote network to use in the lookup.
|
||||
* router - The address of router on a local network that can forward our
|
||||
* packets to the target.
|
||||
*
|
||||
* NOTE: For IPv6, router will be an array, for IPv4 it will be a scalar
|
||||
* value. Hence, the change in the function signature.
|
||||
* Returned Value:
|
||||
* OK on success; Negated errno on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
int net_ipv4_router(in_addr_t target, FAR in_addr_t *router);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Function: net_ipv6_router
|
||||
*
|
||||
* Description:
|
||||
* Given an IPv6 address on a external network, return the address of the
|
||||
* router on a local network that can forward to the external network.
|
||||
*
|
||||
* Parameters:
|
||||
* target - An IPv6 address on a remote network to use in the lookup.
|
||||
* router - The address of router on a local network that can forward our
|
||||
* packets to the target.
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; Negated errno on failure.
|
||||
@ -201,43 +219,62 @@ int net_delroute(net_ipaddr_t target, net_ipaddr_t netmask);
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
int net_router(net_ipaddr_t target, net_ipaddr_t router);
|
||||
#else
|
||||
int net_router(net_ipaddr_t target, FAR net_ipaddr_t *router);
|
||||
int net_ipv6_router(net_ipv6addr_t target, net_ipv6addr_t router);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Function: netdev_router
|
||||
* Function: netdev_ipv4_router
|
||||
*
|
||||
* Description:
|
||||
* Given an IP address on a external network, return the address of the
|
||||
* Given an IPv4 address on a external network, return the address of the
|
||||
* router on a local network that can forward to the external network.
|
||||
* This is similar to net_router(). However, the set of routers is
|
||||
* This is similar to net_ipv4_router(). However, the set of routers is
|
||||
* constrained to those accessible by the specific device
|
||||
*
|
||||
* Parameters:
|
||||
* dev - We are committed to using this device.
|
||||
* target - An IP address on a remote network to use in the lookup.
|
||||
* target - An IPv4 address on a remote network to use in the lookup.
|
||||
* router - The address of router on a local network that can forward our
|
||||
* packets to the target.
|
||||
*
|
||||
* NOTE: For IPv6, router will be an array, for IPv4 it will be a scalar
|
||||
* value. Hence, the change in the function signature.
|
||||
*
|
||||
* Returned Value:
|
||||
* None, a router address is always returned (which may just be, perhaps,
|
||||
* A router address is always returned (which may just be, perhaps,
|
||||
* device's default router address)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
struct net_driver_s;
|
||||
void netdev_ipv4_router(FAR struct net_driver_s *dev, in_addr_t target,
|
||||
FAR in_addr_t *router);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Function: netdev_ipv6_router
|
||||
*
|
||||
* Description:
|
||||
* Given an IPv6 address on a external network, return the address of the
|
||||
* router on a local network that can forward to the external network.
|
||||
* This is similar to net_ipv6_router(). However, the set of routers is
|
||||
* constrained to those accessible by the specific device
|
||||
*
|
||||
* Parameters:
|
||||
* dev - We are committed to using this device.
|
||||
* target - An IPv6 address on a remote network to use in the lookup.
|
||||
* router - The address of router on a local network that can forward our
|
||||
* packets to the target.
|
||||
*
|
||||
* Returned Value:
|
||||
* A router address is always returned (which may just be, perhaps,
|
||||
* device's default router address)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
void netdev_router(FAR struct net_driver_s *dev, net_ipaddr_t target,
|
||||
net_ipaddr_t router);
|
||||
#else
|
||||
void netdev_router(FAR struct net_driver_s *dev, net_ipaddr_t target,
|
||||
FAR net_ipaddr_t *router);
|
||||
struct net_driver_s;
|
||||
void netdev_ipv6_router(FAR struct net_driver_s *dev,
|
||||
FAR const net_ipv6addr_t target,
|
||||
FAR net_ipv6addr_t router);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* net/socket/net_close.c
|
||||
*
|
||||
* Copyright (C) 2007-2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007-2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -358,9 +358,9 @@ static inline int netclose_disconnect(FAR struct socket *psock)
|
||||
/* Notify the device driver of the availability of TX data */
|
||||
|
||||
#ifdef CONFIG_NET_MULTILINK
|
||||
netdev_txnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
|
||||
netdev_ipv4_txnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
|
||||
#else
|
||||
netdev_txnotify(conn->u.ipv4.raddr);
|
||||
netdev_ipv4_txnotify(conn->u.ipv4.raddr);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_SOLINGER
|
||||
|
@ -565,9 +565,9 @@ ssize_t net_sendfile(int outfd, struct file *infile, off_t *offset,
|
||||
/* Notify the device driver of the availability of TX data */
|
||||
|
||||
#ifdef CONFIG_NET_MULTILINK
|
||||
netdev_txnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
|
||||
netdev_ipv4_txnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
|
||||
#else
|
||||
netdev_txnotify(conn->u.ipv4.raddr);
|
||||
netdev_ipv4_txnotify(conn->u.ipv4.raddr);
|
||||
#endif
|
||||
net_lockedwait(&state.snd_sem);
|
||||
}
|
||||
|
@ -1097,9 +1097,9 @@ static ssize_t pkt_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
||||
|
||||
#if 0 /* No */
|
||||
#ifdef CONFIG_NET_MULTILINK
|
||||
netdev_rxnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
|
||||
netdev_ipv4_rxnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
|
||||
#else
|
||||
netdev_rxnotify(conn->u.ipv4.raddr);
|
||||
netdev_ipv4_rxnotify(conn->u.ipv4.raddr);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -1196,9 +1196,9 @@ static ssize_t udp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
||||
/* Notify the device driver of the receive call */
|
||||
|
||||
#ifdef CONFIG_NET_MULTILINK
|
||||
netdev_rxnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
|
||||
netdev_ipv4_rxnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
|
||||
#else
|
||||
netdev_rxnotify(conn->u.ipv4.raddr);
|
||||
netdev_ipv4_rxnotify(conn->u.ipv4.raddr);
|
||||
#endif
|
||||
|
||||
/* Wait for either the receive to complete or for an error/timeout to occur.
|
||||
|
@ -420,9 +420,9 @@ ssize_t psock_sendto(FAR struct socket *psock, FAR const void *buf,
|
||||
/* Notify the device driver of the availability of TX data */
|
||||
|
||||
#ifdef CONFIG_NET_MULTILINK
|
||||
netdev_txnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
|
||||
netdev_ipv4_txnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
|
||||
#else
|
||||
netdev_txnotify(conn->u.ipv4.raddr);
|
||||
netdev_ipv4_txnotify(conn->u.ipv4.raddr);
|
||||
#endif
|
||||
|
||||
/* Wait for either the receive to complete or for an error/timeout to occur.
|
||||
|
@ -104,8 +104,7 @@ static uint16_t g_last_tcp_port;
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NETDEV_MULTINIC
|
||||
static FAR struct tcp_conn_s *tcp_listener(net_ipaddr_t ipaddr,
|
||||
uint16_t portno)
|
||||
static FAR struct tcp_conn_s *tcp_listener(in_addr_t ipaddr, uint16_t portno)
|
||||
#else
|
||||
static FAR struct tcp_conn_s *tcp_listener(uint16_t portno)
|
||||
#endif
|
||||
@ -132,11 +131,11 @@ static FAR struct tcp_conn_s *tcp_listener(uint16_t portno)
|
||||
* with INADDR_ANY.
|
||||
*/
|
||||
|
||||
if (net_ipaddr_cmp(conn->u.ipv4.laddr, ipaddr) ||
|
||||
if (net_ipv4addr_cmp(conn->u.ipv4.laddr, ipaddr) ||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
net_ipaddr_cmp(conn->u.ipv4.laddr, g_allzeroaddr))
|
||||
net_ipv4addr_cmp(conn->u.ipv4.laddr, g_ipv4_allzeroaddr))
|
||||
#else
|
||||
net_ipaddr_cmp(conn->u.ipv4.laddr, INADDR_ANY))
|
||||
net_ipv4addr_cmp(conn->u.ipv4.laddr, INADDR_ANY))
|
||||
#endif
|
||||
#endif
|
||||
{
|
||||
@ -176,7 +175,7 @@ static FAR struct tcp_conn_s *tcp_listener(uint16_t portno)
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NETDEV_MULTINIC
|
||||
static int tcp_selectport(net_ipaddr_t ipaddr, uint16_t portno)
|
||||
static int tcp_selectport(in_addr_t ipaddr, uint16_t portno)
|
||||
#else
|
||||
static int tcp_selectport(uint16_t portno)
|
||||
#endif
|
||||
@ -525,7 +524,7 @@ FAR struct tcp_conn_s *tcp_active(FAR struct net_driver_s *dev,
|
||||
tcp->destport == conn->lport &&
|
||||
tcp->srcport == conn->rport &&
|
||||
#ifdef CONFIG_NETDEV_MULTINIC
|
||||
(net_ipaddr_cmp(conn->u.ipv4.laddr, g_allzeroaddr) ||
|
||||
(net_ipaddr_cmp(conn->u.ipv4.laddr, g_ipv4_allzeroaddr) ||
|
||||
net_ipaddr_cmp(destipaddr, conn->u.ipv4.laddr)) &&
|
||||
#endif
|
||||
net_ipaddr_cmp(srcipaddr, conn->u.ipv4.raddr))
|
||||
@ -668,7 +667,7 @@ int tcp_bind(FAR struct tcp_conn_s *conn,
|
||||
net_lock_t flags;
|
||||
int port;
|
||||
#ifdef CONFIG_NETDEV_MULTINIC
|
||||
net_ipaddr_t ipaddr;
|
||||
in_addr_t ipaddr;
|
||||
#endif
|
||||
|
||||
/* Verify or select a local port and address */
|
||||
|
@ -829,9 +829,9 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf,
|
||||
/* Notify the device driver of the availability of TX data */
|
||||
|
||||
#ifdef CONFIG_NET_MULTILINK
|
||||
netdev_txnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
|
||||
netdev_ipv4_txnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
|
||||
#else
|
||||
netdev_txnotify(conn->u.ipv4.raddr);
|
||||
netdev_ipv4_txnotify(conn->u.ipv4.raddr);
|
||||
#endif
|
||||
result = len;
|
||||
}
|
||||
|
@ -597,9 +597,9 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
|
||||
/* Notify the device driver of the availability of TX data */
|
||||
|
||||
#ifdef CONFIG_NET_MULTILINK
|
||||
netdev_txnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
|
||||
netdev_ipv4_txnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
|
||||
#else
|
||||
netdev_txnotify(conn->u.ipv4.raddr);
|
||||
netdev_ipv4_txnotify(conn->u.ipv4.raddr);
|
||||
#endif
|
||||
|
||||
/* Wait for the send to complete or an error to occur: NOTES: (1)
|
||||
|
@ -127,8 +127,7 @@ static inline void _udp_semtake(FAR sem_t *sem)
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NETDEV_MULTINIC
|
||||
static FAR struct udp_conn_s *udp_find_conn(net_ipaddr_t ipaddr,
|
||||
uint16_t portno)
|
||||
static FAR struct udp_conn_s *udp_find_conn(in_addr_t ipaddr, uint16_t portno)
|
||||
#else
|
||||
static FAR struct udp_conn_s *udp_find_conn(uint16_t portno)
|
||||
#endif
|
||||
@ -150,11 +149,11 @@ static FAR struct udp_conn_s *udp_find_conn(uint16_t portno)
|
||||
*/
|
||||
|
||||
if (conn->lport == portno &&
|
||||
(net_ipaddr_cmp(conn->u.ipv4.laddr, ipaddr) ||
|
||||
(net_ipv4addr_cmp(conn->u.ipv4.laddr, ipaddr) ||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
net_ipaddr_cmp(conn->u.ipv4.laddr, g_allzeroaddr)))
|
||||
net_ipv4addr_cmp(conn->u.ipv4.laddr, g_ipv4_allzeroaddr)))
|
||||
#else
|
||||
net_ipaddr_cmp(conn->u.ipv4.laddr, INADDR_ANY)))
|
||||
net_ipv4addr_cmp(conn->u.ipv4.laddr, INADDR_ANY)))
|
||||
#endif
|
||||
{
|
||||
return conn;
|
||||
@ -195,7 +194,7 @@ static FAR struct udp_conn_s *udp_find_conn(uint16_t portno)
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NETDEV_MULTINIC
|
||||
static uint16_t udp_select_port(net_ipaddr_t ipaddr)
|
||||
static uint16_t udp_select_port(in_addr_t ipaddr)
|
||||
#else
|
||||
static uint16_t udp_select_port(void)
|
||||
#endif
|
||||
@ -381,13 +380,13 @@ FAR struct udp_conn_s *udp_active(FAR struct net_driver_s *dev,
|
||||
if (conn->lport != 0 && udp->destport == conn->lport &&
|
||||
(conn->rport == 0 || udp->srcport == conn->rport) &&
|
||||
#ifdef CONFIG_NETDEV_MULTINIC
|
||||
(net_ipaddr_cmp(conn->u.ipv4.laddr, g_allzeroaddr) ||
|
||||
net_ipaddr_cmp(conn->u.ipv4.laddr, g_alloneaddr) ||
|
||||
net_ipaddr_hdrcmp(ip->destipaddr, &conn->u.ipv4.laddr)) &&
|
||||
(net_ipv4addr_cmp(conn->u.ipv4.laddr, g_ipv4_allzeroaddr) ||
|
||||
net_ipv4addr_cmp(conn->u.ipv4.laddr, g_ipv4_alloneaddr) ||
|
||||
net_ipv4addr_hdrcmp(ip->destipaddr, &conn->u.ipv4.laddr)) &&
|
||||
#endif
|
||||
(net_ipaddr_cmp(conn->u.ipv4.raddr, g_allzeroaddr) ||
|
||||
net_ipaddr_cmp(conn->u.ipv4.raddr, g_alloneaddr) ||
|
||||
net_ipaddr_hdrcmp(ip->srcipaddr, &conn->u.ipv4.raddr)))
|
||||
(net_ipv4addr_cmp(conn->u.ipv4.raddr, g_ipv4_allzeroaddr) ||
|
||||
net_ipv4addr_cmp(conn->u.ipv4.raddr, g_ipv4_alloneaddr) ||
|
||||
net_ipv4addr_hdrcmp(ip->srcipaddr, &conn->u.ipv4.raddr)))
|
||||
{
|
||||
/* Matching connection found.. return a reference to it */
|
||||
|
||||
@ -448,7 +447,7 @@ int udp_bind(FAR struct udp_conn_s *conn, FAR const struct sockaddr_in *addr)
|
||||
int ret;
|
||||
|
||||
#ifdef CONFIG_NETDEV_MULTINIC
|
||||
net_ipaddr_t ipaddr;
|
||||
in_addr_t ipaddr;
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
/* Get the IPv6 address that we are binding to */
|
||||
@ -569,7 +568,7 @@ int udp_connect(FAR struct udp_conn_s *conn,
|
||||
else
|
||||
{
|
||||
conn->rport = 0;
|
||||
net_ipaddr_copy(conn->u.ipv4.raddr, g_allzeroaddr);
|
||||
net_ipv4addr_copy(conn->u.ipv4.raddr, g_ipv4_allzeroaddr);
|
||||
}
|
||||
|
||||
conn->ttl = IP_TTL;
|
||||
|
@ -143,7 +143,7 @@ static uint16_t upper_layer_chksum(FAR struct net_driver_s *dev,
|
||||
|
||||
/* Sum IP source and destination addresses. */
|
||||
|
||||
sum = chksum(sum, (uint8_t *)&pbuf->srcipaddr, 2 * sizeof(net_ipaddr_t));
|
||||
sum = chksum(sum, (uint8_t *)&pbuf->srcipaddr, 2 * sizeof(in_addr_t));
|
||||
|
||||
/* Sum TCP header and data. */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user