diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2013-10-01 19:13:06 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2013-10-01 19:13:06 -0600 |
commit | 2fcd0856d3acff82fe6946c2aa35e0a7a3e5158d (patch) | |
tree | 60a4e48bfa6a3853371f8e55f16f0c8f7d0bc39b | |
parent | b4e9e42b45494e19fd131ea02e2c01745de855a5 (diff) | |
download | px4-nuttx-2fcd0856d3acff82fe6946c2aa35e0a7a3e5158d.tar.gz px4-nuttx-2fcd0856d3acff82fe6946c2aa35e0a7a3e5158d.tar.bz2 px4-nuttx-2fcd0856d3acff82fe6946c2aa35e0a7a3e5158d.zip |
Simple routing table hooked into network build system
-rw-r--r-- | nuttx/net/Kconfig | 15 | ||||
-rw-r--r-- | nuttx/net/Makefile | 6 | ||||
-rw-r--r-- | nuttx/net/net_addroute.c | 3 | ||||
-rw-r--r-- | nuttx/net/net_delroute.c | 23 | ||||
-rw-r--r-- | nuttx/net/net_findroute.c | 25 | ||||
-rw-r--r-- | nuttx/net/net_foreachroute.c | 5 |
6 files changed, 50 insertions, 27 deletions
diff --git a/nuttx/net/Kconfig b/nuttx/net/Kconfig index c581e32a3..fbc34ec78 100644 --- a/nuttx/net/Kconfig +++ b/nuttx/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 diff --git a/nuttx/net/Makefile b/nuttx/net/Makefile index 234434496..0aced6343 100644 --- a/nuttx/net/Makefile +++ b/nuttx/net/Makefile @@ -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) diff --git a/nuttx/net/net_addroute.c b/nuttx/net/net_addroute.c index fd4e7de9a..6b7ac9f6e 100644 --- a/nuttx/net/net_addroute.c +++ b/nuttx/net/net_addroute.c @@ -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 */ diff --git a/nuttx/net/net_delroute.c b/nuttx/net/net_delroute.c index 08d9ad154..b203f0349 100644 --- a/nuttx/net/net_delroute.c +++ b/nuttx/net/net_delroute.c @@ -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 */ diff --git a/nuttx/net/net_findroute.c b/nuttx/net/net_findroute.c index 252f9a098..5dea9d9ac 100644 --- a/nuttx/net/net_findroute.c +++ b/nuttx/net/net_findroute.c @@ -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 */ diff --git a/nuttx/net/net_foreachroute.c b/nuttx/net/net_foreachroute.c index 4c82a688b..8eb844334 100644 --- a/nuttx/net/net_foreachroute.c +++ b/nuttx/net/net_foreachroute.c @@ -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 */ |