Networking routing table: Cosmetic naming to make IPv4 and IPv6 routing table logic symmetry.

This commit is contained in:
Gregory Nutt 2017-08-10 09:14:31 -06:00
parent c5e5cd5c0f
commit f506a49295
8 changed files with 55 additions and 48 deletions

View File

@ -146,7 +146,7 @@ static int ioctl_add_ipv4route(FAR struct rtentry *rtentry)
router = 0; router = 0;
} }
return net_addroute(target, netmask, router); return net_addroute_ipv4(target, netmask, router);
} }
#endif /* CONFIG_NET_ROUTE && CONFIG_NET_IPv4 */ #endif /* CONFIG_NET_ROUTE && CONFIG_NET_IPv4 */
@ -212,7 +212,7 @@ static int ioctl_del_ipv4route(FAR struct rtentry *rtentry)
addr = (FAR struct sockaddr_in *)rtentry->rt_netmask; addr = (FAR struct sockaddr_in *)rtentry->rt_netmask;
netmask = (in_addr_t)addr->sin_addr.s_addr; netmask = (in_addr_t)addr->sin_addr.s_addr;
return net_delroute(target, netmask); return net_delroute_ipv4(target, netmask);
} }
#endif /* CONFIG_NET_ROUTE && CONFIG_NET_IPv4 */ #endif /* CONFIG_NET_ROUTE && CONFIG_NET_IPv4 */

View File

@ -40,6 +40,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <stdint.h> #include <stdint.h>
#include <string.h>
#include <queue.h> #include <queue.h>
#include <errno.h> #include <errno.h>
#include <debug.h> #include <debug.h>
@ -58,7 +59,7 @@
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: net_addroute * Name: net_addroute_ipv4 and net_addroute_ipv6
* *
* Description: * Description:
* Add a new route to the routing table * Add a new route to the routing table
@ -71,13 +72,13 @@
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv4
int net_addroute(in_addr_t target, in_addr_t netmask, in_addr_t router) int net_addroute_ipv4(in_addr_t target, in_addr_t netmask, in_addr_t router)
{ {
FAR struct net_route_s *route; FAR struct net_route_s *route;
/* Allocate a route entry */ /* Allocate a route entry */
route = net_allocroute(); route = net_allocroute_ipv4();
if (!route) if (!route)
{ {
nerr("ERROR: Failed to allocate a route\n"); nerr("ERROR: Failed to allocate a route\n");
@ -96,14 +97,15 @@ int net_addroute(in_addr_t target, in_addr_t netmask, in_addr_t router)
/* Then add the new entry to the table */ /* Then add the new entry to the table */
sq_addlast((FAR sq_entry_t *)route, (FAR sq_queue_t *)&g_routes); sq_addlast((FAR sq_entry_t *)route, (FAR sq_queue_t *)&g_ipv4_routes);
net_unlock(); net_unlock();
return OK; return OK;
} }
#endif #endif
#ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv6
int net_addroute_ipv6(net_ipv6addr_t target, net_ipv6addr_t netmask, net_ipv6addr_t router) int net_addroute_ipv6(net_ipv6addr_t target, net_ipv6addr_t netmask,
net_ipv6addr_t router)
{ {
FAR struct net_route_ipv6_s *route; FAR struct net_route_ipv6_s *route;
@ -128,7 +130,7 @@ int net_addroute_ipv6(net_ipv6addr_t target, net_ipv6addr_t netmask, net_ipv6add
/* Then add the new entry to the table */ /* Then add the new entry to the table */
sq_addlast((FAR sq_entry_t *)route, (FAR sq_queue_t *)&g_routes_ipv6); sq_addlast((FAR sq_entry_t *)route, (FAR sq_queue_t *)&g_ipv6_routes);
net_unlock(); net_unlock();
return OK; return OK;
} }

View File

@ -57,11 +57,11 @@
/* This is the routing table */ /* This is the routing table */
#ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv4
sq_queue_t g_routes; sq_queue_t g_ipv4_routes;
#endif #endif
#ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv6
sq_queue_t g_routes_ipv6; sq_queue_t g_ipv6_routes;
#endif #endif
/**************************************************************************** /****************************************************************************
@ -116,7 +116,7 @@ void net_initroute(void)
/* Initialize the routing table and the free list */ /* Initialize the routing table and the free list */
#ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv4
sq_init(&g_routes); sq_init(&g_ipv4_routes);
sq_init(&g_freeroutes); sq_init(&g_freeroutes);
/* All all of the pre-allocated routing table entries to a free list */ /* All all of the pre-allocated routing table entries to a free list */
@ -129,7 +129,7 @@ void net_initroute(void)
#endif #endif
#ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv6
sq_init(&g_routes_ipv6); sq_init(&g_ipv6_routes);
sq_init(&g_freeroutes_ipv6); sq_init(&g_freeroutes_ipv6);
/* All all of the pre-allocated routing table entries to a free list */ /* All all of the pre-allocated routing table entries to a free list */
@ -143,7 +143,7 @@ void net_initroute(void)
} }
/**************************************************************************** /****************************************************************************
* Name: net_allocroute * Name: net_allocroute_ipv4 and net_allocroute_ipv6
* *
* Description: * Description:
* Allocate one route by removing it from the free list * Allocate one route by removing it from the free list
@ -158,7 +158,7 @@ void net_initroute(void)
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv4
FAR struct net_route_s *net_allocroute(void) FAR struct net_route_s *net_allocroute_ipv4(void)
{ {
FAR struct net_route_s *route; FAR struct net_route_s *route;
@ -196,7 +196,7 @@ FAR struct net_route_ipv6_s *net_allocroute_ipv6(void)
#endif #endif
/**************************************************************************** /****************************************************************************
* Name: net_freeroute * Name: net_freeroute_ipv4 and net_freeroute_ipv6
* *
* Description: * Description:
* Free one route by adding it from the free list * Free one route by adding it from the free list
@ -210,7 +210,7 @@ FAR struct net_route_ipv6_s *net_allocroute_ipv6(void)
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv4
void net_freeroute(FAR struct net_route_s *route) void net_freeroute_ipv4(FAR struct net_route_s *route)
{ {
DEBUGASSERT(route); DEBUGASSERT(route);

View File

@ -107,16 +107,16 @@ static int net_match(FAR struct net_route_s *route, FAR void *arg)
if (match->prev) if (match->prev)
{ {
(void)sq_remafter((FAR sq_entry_t *)match->prev, (void)sq_remafter((FAR sq_entry_t *)match->prev,
(FAR sq_queue_t *)&g_routes); (FAR sq_queue_t *)&g_ipv4_routes);
} }
else else
{ {
(void)sq_remfirst((FAR sq_queue_t *)&g_routes); (void)sq_remfirst((FAR sq_queue_t *)&g_ipv4_routes);
} }
/* And free the routing table entry by adding it to the free list */ /* And free the routing table entry by adding it to the free list */
net_freeroute(route); net_freeroute_ipv4(route);
/* Return a non-zero value to terminate the traversal */ /* Return a non-zero value to terminate the traversal */
@ -147,11 +147,11 @@ static int net_match_ipv6(FAR struct net_route_ipv6_s *route, FAR void *arg)
if (match->prev) if (match->prev)
{ {
(void)sq_remafter((FAR sq_entry_t *)match->prev, (void)sq_remafter((FAR sq_entry_t *)match->prev,
(FAR sq_queue_t *)&g_routes_ipv6); (FAR sq_queue_t *)&g_ipv6_routes);
} }
else else
{ {
(void)sq_remfirst((FAR sq_queue_t *)&g_routes_ipv6); (void)sq_remfirst((FAR sq_queue_t *)&g_ipv6_routes);
} }
/* And free the routing table entry by adding it to the free list */ /* And free the routing table entry by adding it to the free list */
@ -175,7 +175,7 @@ static int net_match_ipv6(FAR struct net_route_ipv6_s *route, FAR void *arg)
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: net_delroute * Name: net_delroute_ipv4 and net_delroute_ipv6
* *
* Description: * Description:
* Remove an existing route from the routing table * Remove an existing route from the routing table
@ -188,7 +188,7 @@ static int net_match_ipv6(FAR struct net_route_ipv6_s *route, FAR void *arg)
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv4
int net_delroute(in_addr_t target, in_addr_t netmask) int net_delroute_ipv4(in_addr_t target, in_addr_t netmask)
{ {
struct route_match_s match; struct route_match_s match;
@ -200,7 +200,7 @@ int net_delroute(in_addr_t target, in_addr_t netmask)
/* 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_ipv4(net_match, &match) ? OK : -ENOENT;
} }
#endif #endif

View File

@ -55,7 +55,7 @@
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: net_foreachroute * Name: net_foreachroute_ipv4 and net_foreachroute_ipv6
* *
* Description: * Description:
* Traverse the routing table * Traverse the routing table
@ -70,7 +70,7 @@
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv4
int net_foreachroute(route_handler_t handler, FAR void *arg) int net_foreachroute_ipv4(route_handler_t handler, FAR void *arg)
{ {
FAR struct net_route_s *route; FAR struct net_route_s *route;
FAR struct net_route_s *next; FAR struct net_route_s *next;
@ -82,7 +82,9 @@ int net_foreachroute(route_handler_t handler, FAR void *arg)
/* Visit each entry in the routing table */ /* Visit each entry in the routing table */
for (route = (FAR struct net_route_s *)g_routes.head; route; route = next) for (route = (FAR struct net_route_s *)g_ipv4_routes.head;
route;
route = next)
{ {
/* Get the next entry in the to visit. We do this BEFORE calling the /* Get the next entry in the to visit. We do this BEFORE calling the
* handler because the hanlder may delete this entry. * handler because the hanlder may delete this entry.
@ -112,7 +114,9 @@ int net_foreachroute_ipv6(route_handler_ipv6_t handler, FAR void *arg)
/* Visit each entry in the routing table */ /* Visit each entry in the routing table */
for (route = (FAR struct net_route_s *)g_routes_ipv6.head; route; route = next) for (route = (FAR struct net_route_ipv6_s *)g_ipv6_routes.head;
route;
route = next)
{ {
/* Get the next entry in the to visit. We do this BEFORE calling the /* Get the next entry in the to visit. We do this BEFORE calling the
* handler because the hanlder may delete this entry. * handler because the hanlder may delete this entry.

View File

@ -193,7 +193,7 @@ int net_ipv4_router(in_addr_t target, FAR in_addr_t *router)
* address * address
*/ */
ret = net_foreachroute(net_ipv4_match, &match); ret = net_foreachroute_ipv4(net_ipv4_match, &match);
if (ret > 0) if (ret > 0)
{ {
/* We found a route. Return the router address. */ /* We found a route. Return the router address. */
@ -230,7 +230,7 @@ int net_ipv4_router(in_addr_t target, FAR in_addr_t *router)
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv6
int net_ipv6_router(net_ipv6addr_t target, net_ipv6addr_t router) int net_ipv6_router(const net_ipv6addr_t target, net_ipv6addr_t router)
{ {
struct route_ipv6_match_s match; struct route_ipv6_match_s match;
int ret; int ret;

View File

@ -201,7 +201,7 @@ void netdev_ipv4_router(FAR struct net_driver_s *dev, in_addr_t target,
* address using this device. * address using this device.
*/ */
ret = net_foreachroute(net_ipv4_devmatch, &match); ret = net_foreachroute_ipv4(net_ipv4_devmatch, &match);
if (ret > 0) if (ret > 0)
{ {
/* We found a route. Return the router address. */ /* We found a route. Return the router address. */

View File

@ -73,7 +73,7 @@ struct net_route_s
in_addr_t router; /* Route packets via this router */ in_addr_t router; /* Route packets via this router */
}; };
/* Type of the call out function pointer provided to net_foreachroute() */ /* Type of the call out function pointer provided to net_foreachroute_ipv4() */
typedef int (*route_handler_t)(FAR struct net_route_s *route, FAR void *arg); typedef int (*route_handler_t)(FAR struct net_route_s *route, FAR void *arg);
#endif #endif
@ -87,9 +87,10 @@ struct net_route_ipv6_s
net_ipv6addr_t router; /* Route packets via this router */ net_ipv6addr_t router; /* Route packets via this router */
}; };
/* Type of the call out function pointer provided to net_foreachroute() */ /* Type of the call out function pointer provided to net_foreachroute_ipv6() */
typedef int (*route_handler_ipv6_t)(FAR struct net_route_ipv6_s *route, FAR void *arg); typedef int (*route_handler_ipv6_t)(FAR struct net_route_ipv6_s *route,
FAR void *arg);
#endif #endif
/**************************************************************************** /****************************************************************************
@ -107,11 +108,11 @@ extern "C"
/* This is the routing table */ /* This is the routing table */
#ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv4
EXTERN sq_queue_t g_routes; EXTERN sq_queue_t g_ipv4_routes;
#endif #endif
#ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv6
EXTERN sq_queue_t g_routes_ipv6; EXTERN sq_queue_t g_ipv6_routes;
#endif #endif
/**************************************************************************** /****************************************************************************
@ -135,7 +136,7 @@ EXTERN sq_queue_t g_routes_ipv6;
void net_initroute(void); void net_initroute(void);
/**************************************************************************** /****************************************************************************
* Name: net_allocroute * Name: net_allocroute_ipv4 and net_allocroute_ipv6
* *
* Description: * Description:
* Allocate one route by removing it from the free list * Allocate one route by removing it from the free list
@ -150,7 +151,7 @@ void net_initroute(void);
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv4
FAR struct net_route_s *net_allocroute(void); FAR struct net_route_s *net_allocroute_ipv4(void);
#endif #endif
#ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv6
@ -158,7 +159,7 @@ FAR struct net_route_ipv6_s *net_allocroute_ipv6(void);
#endif #endif
/**************************************************************************** /****************************************************************************
* Name: net_allocroute * Name: net_freeroute_ipv4 and net_freeroute_ipv6
* *
* Description: * Description:
* Free one route by adding it from the free list * Free one route by adding it from the free list
@ -172,7 +173,7 @@ FAR struct net_route_ipv6_s *net_allocroute_ipv6(void);
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv4
void net_freeroute(FAR struct net_route_s *route); void net_freeroute_ipv4(FAR struct net_route_s *route);
#endif #endif
#ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv6
@ -180,7 +181,7 @@ void net_freeroute_ipv6(FAR struct net_route_ipv6_s *route);
#endif #endif
/**************************************************************************** /****************************************************************************
* Name: net_addroute * Name: net_addroute_ipv4 and net_addroute_ipv6
* *
* Description: * Description:
* Add a new route to the routing table * Add a new route to the routing table
@ -197,8 +198,8 @@ void net_freeroute_ipv6(FAR struct net_route_ipv6_s *route);
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv4
int net_addroute(in_addr_t target, in_addr_t netmask, int net_addroute_ipv4(in_addr_t target, in_addr_t netmask,
in_addr_t router); in_addr_t router);
#endif #endif
#ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv6
@ -207,7 +208,7 @@ int net_addroute_ipv6(net_ipv6addr_t target, net_ipv6addr_t netmask,
#endif #endif
/**************************************************************************** /****************************************************************************
* Name: net_delroute * Name: net_delroute_ipv4 and net_delroute_ipv6
* *
* Description: * Description:
* Remove an existing route from the routing table * Remove an existing route from the routing table
@ -220,7 +221,7 @@ int net_addroute_ipv6(net_ipv6addr_t target, net_ipv6addr_t netmask,
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv4
int net_delroute(in_addr_t target, in_addr_t netmask); int net_delroute_ipv4(in_addr_t target, in_addr_t netmask);
#endif #endif
#ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv6
@ -266,7 +267,7 @@ int net_ipv4_router(in_addr_t target, FAR in_addr_t *router);
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv6
int net_ipv6_router(net_ipv6addr_t target, net_ipv6addr_t router); int net_ipv6_router(const net_ipv6addr_t target, net_ipv6addr_t router);
#endif #endif
/**************************************************************************** /****************************************************************************
@ -325,7 +326,7 @@ void netdev_ipv6_router(FAR struct net_driver_s *dev,
#endif #endif
/**************************************************************************** /****************************************************************************
* Name: net_foreachroute * Name: net_foreachroute_ipv4
* *
* Description: * Description:
* Traverse the routing table * Traverse the routing table
@ -338,7 +339,7 @@ void netdev_ipv6_router(FAR struct net_driver_s *dev,
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv4
int net_foreachroute(route_handler_t handler, FAR void *arg); int net_foreachroute_ipv4(route_handler_t handler, FAR void *arg);
#endif #endif
#ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv6