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"
|
||||
default 16
|
||||
---help---
|
||||
The size of the ARP table
|
||||
The size of the ARP table (in entries).
|
||||
|
||||
config NET_ARP_IPIN
|
||||
bool "ARP address harvesting"
|
||||
@ -304,6 +304,19 @@ config NET_ARP_IPIN
|
||||
Harvest IP/MAC address mappings from the ARP table
|
||||
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
|
||||
bool "Multi-cast Tx support"
|
||||
default n
|
||||
|
@ -62,6 +62,12 @@ 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
|
||||
|
||||
ifneq ($(CONFIG_NFILE_STREAMS),0)
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <errno.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;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET && CONFIG_NET_SOCKOPTS && !CONFIG_DISABLE_CLOCK */
|
||||
#endif /* CONFIG_NET && CONFIG_NET_ROUTE */
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/net/route.h>
|
||||
@ -54,8 +55,8 @@
|
||||
|
||||
struct route_match_s
|
||||
{
|
||||
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 target; /* The target IP address to match */
|
||||
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;
|
||||
|
||||
/* To match, the entry has to be in use, the masked target addresses must
|
||||
* be the same. In the event of multiple matches, only the first is
|
||||
* returned.
|
||||
/* To match, the entry has to be in use, the masked target address must
|
||||
* be the same, and the masks must be the same.
|
||||
*/
|
||||
|
||||
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 */
|
||||
|
||||
memcpy(match->route, route, sizeof(struct net_route_s));
|
||||
memset(route, 0, sizeof(struct net_route_s));
|
||||
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:
|
||||
* Given an IP address, return a copy of the routing table contents
|
||||
* Remove an existing route from the routing table
|
||||
*
|
||||
* 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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET && CONFIG_NET_ROUTE */
|
||||
#endif /* CONFIG_NET && CONFIG_NET_SOCKOPTS && !CONFIG_DISABLE_CLOCK */
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/net/route.h>
|
||||
@ -54,8 +55,8 @@
|
||||
|
||||
struct route_match_s
|
||||
{
|
||||
uip_ipaddr_t target; /* The target IP address to match */
|
||||
uip_ipaddr_t netmask; /* The network mask to match */
|
||||
uip_ipaddr_t target; /* The target IP address 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;
|
||||
|
||||
/* To match, the entry has to be in use, the masked target address must
|
||||
* be the same, and the masks must be the same.
|
||||
/* To match, the entry has to be in use, the masked target addresses must
|
||||
* be the same. In the event of multiple matches, only the first is
|
||||
* returned.
|
||||
*/
|
||||
|
||||
if (route->inuse &&
|
||||
uip_ipaddr_maskcmp(route->target, match->target, match->netmask) &&
|
||||
uip_ipaddr_cmp(route->target, match->netmask))
|
||||
uip_ipaddr_maskcmp(route->target, match->target, route->netmask))
|
||||
{
|
||||
/* 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;
|
||||
}
|
||||
|
||||
@ -103,10 +104,10 @@ static int net_match(FAR struct net_route_s *route, FAR void *arg)
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: net_delroute
|
||||
* Function: net_findroute
|
||||
*
|
||||
* Description:
|
||||
* Remove an existing route from the routing table
|
||||
* Given an IP address, return a copy of the routing table contents
|
||||
*
|
||||
* 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;
|
||||
|
||||
/* Set up the comparison structure */
|
||||
|
||||
uip_ipaddr_copy(match.target, target);
|
||||
uip_ipaddr_copy(match.netmask, netmask);
|
||||
match.route = route;
|
||||
|
||||
/* Then remove the entry from the routing table */
|
||||
|
||||
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 <errno.h>
|
||||
|
||||
#include <arch/irq.h>
|
||||
#include <nuttx/net/route.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++)
|
||||
{
|
||||
ret = handler(&g_route[i], arg);
|
||||
ret = handler(&g_routes[i], arg);
|
||||
}
|
||||
|
||||
/* Unlock uIP */
|
||||
@ -94,4 +95,4 @@ int net_foreachroute(route_handler_t handler, FAR void *arg)
|
||||
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