Simple routing table hooked into network build system
This commit is contained in:
parent
ca8ec81688
commit
255a9dcfc2
15
net/Kconfig
15
net/Kconfig
@ -295,7 +295,7 @@ config NET_ARPTAB_SIZE
|
|||||||
int "ARP table size"
|
int "ARP table size"
|
||||||
default 16
|
default 16
|
||||||
---help---
|
---help---
|
||||||
The size of the ARP table
|
The size of the ARP table (in entries).
|
||||||
|
|
||||||
config NET_ARP_IPIN
|
config NET_ARP_IPIN
|
||||||
bool "ARP address harvesting"
|
bool "ARP address harvesting"
|
||||||
@ -304,6 +304,19 @@ config NET_ARP_IPIN
|
|||||||
Harvest IP/MAC address mappings from the ARP table
|
Harvest IP/MAC address mappings from the ARP table
|
||||||
from incoming IP packets.
|
from incoming IP packets.
|
||||||
|
|
||||||
|
config NET_ROUTE
|
||||||
|
bool "Routing table suport"
|
||||||
|
default n
|
||||||
|
---help---
|
||||||
|
Build in support for a routing table. See include/nuttx/net/route.h
|
||||||
|
|
||||||
|
config NET_MAXROUTES
|
||||||
|
int "Routing table size"
|
||||||
|
default 4
|
||||||
|
depends on NET_ROUTE
|
||||||
|
---help---
|
||||||
|
The size of the routing table (in entries).
|
||||||
|
|
||||||
config NET_MULTICAST
|
config NET_MULTICAST
|
||||||
bool "Multi-cast Tx support"
|
bool "Multi-cast Tx support"
|
||||||
default n
|
default n
|
||||||
|
@ -62,6 +62,12 @@ endif
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# Routing table support
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_NET_ROUTE),y)
|
||||||
|
SOCK_CSRCS += net_addroute.c net_delroute.c net_findroute.c net_foreachroute.c
|
||||||
|
endif
|
||||||
|
|
||||||
# Support for network access using streams
|
# Support for network access using streams
|
||||||
|
|
||||||
ifneq ($(CONFIG_NFILE_STREAMS),0)
|
ifneq ($(CONFIG_NFILE_STREAMS),0)
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <nuttx/net/route.h>
|
#include <nuttx/net/route.h>
|
||||||
@ -117,4 +118,4 @@ int net_addroute(uip_ipaddr_t target, uip_ipaddr_t netmask,
|
|||||||
return net_foreachroute(net_available, &route) ? OK : -EAGAIN;
|
return net_foreachroute(net_available, &route) ? OK : -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_NET && CONFIG_NET_SOCKOPTS && !CONFIG_DISABLE_CLOCK */
|
#endif /* CONFIG_NET && CONFIG_NET_ROUTE */
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <nuttx/net/route.h>
|
#include <nuttx/net/route.h>
|
||||||
@ -54,8 +55,8 @@
|
|||||||
|
|
||||||
struct route_match_s
|
struct route_match_s
|
||||||
{
|
{
|
||||||
uip_ipaddr_t target; /* The target IP address to match */
|
uip_ipaddr_t target; /* The target IP address to match */
|
||||||
FAR struct net_route_s *route; /* The location to return the route */
|
uip_ipaddr_t netmask; /* The network mask to match */
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -81,17 +82,17 @@ static int net_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_match_s *match = ( FAR struct route_match_s *)arg;
|
||||||
|
|
||||||
/* To match, the entry has to be in use, the masked target addresses must
|
/* To match, the entry has to be in use, the masked target address must
|
||||||
* be the same. In the event of multiple matches, only the first is
|
* be the same, and the masks must be the same.
|
||||||
* returned.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (route->inuse &&
|
if (route->inuse &&
|
||||||
uip_ipaddr_maskcmp(route->target, match->target, route>netmask))
|
uip_ipaddr_maskcmp(route->target, match->target, match->netmask) &&
|
||||||
|
uip_ipaddr_cmp(route->target, match->netmask))
|
||||||
{
|
{
|
||||||
/* They match.. clear the route table entry */
|
/* They match.. clear the route table entry */
|
||||||
|
|
||||||
memcpy(match->route, route, sizeof(struct net_route_s));
|
memset(route, 0, sizeof(struct net_route_s));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,10 +104,10 @@ static int net_match(FAR struct net_route_s *route, FAR void *arg)
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Function: net_findroute
|
* Function: net_delroute
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Given an IP address, return a copy of the routing table contents
|
* Remove an existing route from the routing table
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
*
|
*
|
||||||
@ -115,7 +116,7 @@ static int net_match(FAR struct net_route_s *route, FAR void *arg)
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int net_findroute(uip_ipaddr_t target, FAR struct net_route_s *route);
|
int net_delroute(uip_ipaddr_t target, uip_ipaddr_t netmask)
|
||||||
{
|
{
|
||||||
struct route_match_s match;
|
struct route_match_s match;
|
||||||
|
|
||||||
@ -129,4 +130,4 @@ int net_findroute(uip_ipaddr_t target, FAR struct net_route_s *route);
|
|||||||
return net_foreachroute(net_match, &match) ? OK : -ENOENT;
|
return net_foreachroute(net_match, &match) ? OK : -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_NET && CONFIG_NET_ROUTE */
|
#endif /* CONFIG_NET && CONFIG_NET_SOCKOPTS && !CONFIG_DISABLE_CLOCK */
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <nuttx/net/route.h>
|
#include <nuttx/net/route.h>
|
||||||
@ -54,8 +55,8 @@
|
|||||||
|
|
||||||
struct route_match_s
|
struct route_match_s
|
||||||
{
|
{
|
||||||
uip_ipaddr_t target; /* The target IP address to match */
|
uip_ipaddr_t target; /* The target IP address to match */
|
||||||
uip_ipaddr_t netmask; /* The network mask to match */
|
FAR struct net_route_s *route; /* The location to return the route */
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -81,17 +82,17 @@ static int net_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_match_s *match = ( FAR struct route_match_s *)arg;
|
||||||
|
|
||||||
/* To match, the entry has to be in use, the masked target address must
|
/* To match, the entry has to be in use, the masked target addresses must
|
||||||
* be the same, and the masks must be the same.
|
* be the same. In the event of multiple matches, only the first is
|
||||||
|
* returned.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (route->inuse &&
|
if (route->inuse &&
|
||||||
uip_ipaddr_maskcmp(route->target, match->target, match->netmask) &&
|
uip_ipaddr_maskcmp(route->target, match->target, route->netmask))
|
||||||
uip_ipaddr_cmp(route->target, match->netmask))
|
|
||||||
{
|
{
|
||||||
/* They match.. clear the route table entry */
|
/* They match.. clear the route table entry */
|
||||||
|
|
||||||
memset(route, 0, sizeof(struct net_route_s));
|
memcpy(match->route, route, sizeof(struct net_route_s));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,10 +104,10 @@ static int net_match(FAR struct net_route_s *route, FAR void *arg)
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Function: net_delroute
|
* Function: net_findroute
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Remove an existing route from the routing table
|
* Given an IP address, return a copy of the routing table contents
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
*
|
*
|
||||||
@ -115,18 +116,18 @@ static int net_match(FAR struct net_route_s *route, FAR void *arg)
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int net_delroute(uip_ipaddr_t target, uip_ipaddr_t netmask);
|
int net_findroute(uip_ipaddr_t target, FAR struct net_route_s *route)
|
||||||
{
|
{
|
||||||
struct route_match_s match;
|
struct route_match_s match;
|
||||||
|
|
||||||
/* Set up the comparison structure */
|
/* Set up the comparison structure */
|
||||||
|
|
||||||
uip_ipaddr_copy(match.target, target);
|
uip_ipaddr_copy(match.target, target);
|
||||||
uip_ipaddr_copy(match.netmask, netmask);
|
match.route = route;
|
||||||
|
|
||||||
/* Then remove the entry from the routing table */
|
/* Then remove the entry from the routing table */
|
||||||
|
|
||||||
return net_foreachroute(net_match, &match) ? OK : -ENOENT;
|
return net_foreachroute(net_match, &match) ? OK : -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_NET && CONFIG_NET_SOCKOPTS && !CONFIG_DISABLE_CLOCK */
|
#endif /* CONFIG_NET && CONFIG_NET_ROUTE */
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <arch/irq.h>
|
||||||
#include <nuttx/net/route.h>
|
#include <nuttx/net/route.h>
|
||||||
|
|
||||||
#include "net_internal.h"
|
#include "net_internal.h"
|
||||||
@ -85,7 +86,7 @@ int net_foreachroute(route_handler_t handler, FAR void *arg)
|
|||||||
|
|
||||||
for (i = 0; i < CONFIG_NET_MAXROUTES && ret == 0; i++)
|
for (i = 0; i < CONFIG_NET_MAXROUTES && ret == 0; i++)
|
||||||
{
|
{
|
||||||
ret = handler(&g_route[i], arg);
|
ret = handler(&g_routes[i], arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unlock uIP */
|
/* Unlock uIP */
|
||||||
@ -94,4 +95,4 @@ int net_foreachroute(route_handler_t handler, FAR void *arg)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_NET && CONFIG_NET_SOCKOPTS && !CONFIG_DISABLE_CLOCK */
|
#endif /* CONFIG_NET && CONFIG_NET_ROUTE */
|
||||||
|
Loading…
Reference in New Issue
Block a user