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;
}
return net_addroute(target, netmask, router);
return net_addroute_ipv4(target, netmask, router);
}
#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;
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 */

View file

@ -40,6 +40,7 @@
#include <nuttx/config.h>
#include <stdint.h>
#include <string.h>
#include <queue.h>
#include <errno.h>
#include <debug.h>
@ -58,7 +59,7 @@
****************************************************************************/
/****************************************************************************
* Name: net_addroute
* Name: net_addroute_ipv4 and net_addroute_ipv6
*
* Description:
* Add a new route to the routing table
@ -71,13 +72,13 @@
****************************************************************************/
#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;
/* Allocate a route entry */
route = net_allocroute();
route = net_allocroute_ipv4();
if (!route)
{
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 */
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();
return OK;
}
#endif
#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;
@ -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 */
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();
return OK;
}

View file

@ -57,11 +57,11 @@
/* This is the routing table */
#ifdef CONFIG_NET_IPv4
sq_queue_t g_routes;
sq_queue_t g_ipv4_routes;
#endif
#ifdef CONFIG_NET_IPv6
sq_queue_t g_routes_ipv6;
sq_queue_t g_ipv6_routes;
#endif
/****************************************************************************
@ -116,7 +116,7 @@ void net_initroute(void)
/* Initialize the routing table and the free list */
#ifdef CONFIG_NET_IPv4
sq_init(&g_routes);
sq_init(&g_ipv4_routes);
sq_init(&g_freeroutes);
/* All all of the pre-allocated routing table entries to a free list */
@ -129,7 +129,7 @@ void net_initroute(void)
#endif
#ifdef CONFIG_NET_IPv6
sq_init(&g_routes_ipv6);
sq_init(&g_ipv6_routes);
sq_init(&g_freeroutes_ipv6);
/* 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:
* Allocate one route by removing it from the free list
@ -158,7 +158,7 @@ void net_initroute(void)
****************************************************************************/
#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;
@ -196,7 +196,7 @@ FAR struct net_route_ipv6_s *net_allocroute_ipv6(void)
#endif
/****************************************************************************
* Name: net_freeroute
* Name: net_freeroute_ipv4 and net_freeroute_ipv6
*
* Description:
* 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
void net_freeroute(FAR struct net_route_s *route)
void net_freeroute_ipv4(FAR struct net_route_s *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)
{
(void)sq_remafter((FAR sq_entry_t *)match->prev,
(FAR sq_queue_t *)&g_routes);
(FAR sq_queue_t *)&g_ipv4_routes);
}
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 */
net_freeroute(route);
net_freeroute_ipv4(route);
/* 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)
{
(void)sq_remafter((FAR sq_entry_t *)match->prev,
(FAR sq_queue_t *)&g_routes_ipv6);
(FAR sq_queue_t *)&g_ipv6_routes);
}
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 */
@ -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:
* 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
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;
@ -200,7 +200,7 @@ int net_delroute(in_addr_t target, in_addr_t netmask)
/* 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

View file

@ -55,7 +55,7 @@
****************************************************************************/
/****************************************************************************
* Name: net_foreachroute
* Name: net_foreachroute_ipv4 and net_foreachroute_ipv6
*
* Description:
* Traverse the routing table
@ -70,7 +70,7 @@
****************************************************************************/
#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 *next;
@ -82,7 +82,9 @@ int net_foreachroute(route_handler_t handler, FAR void *arg)
/* 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
* 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 */
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
* 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
*/
ret = net_foreachroute(net_ipv4_match, &match);
ret = net_foreachroute_ipv4(net_ipv4_match, &match);
if (ret > 0)
{
/* 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
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;
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.
*/
ret = net_foreachroute(net_ipv4_devmatch, &match);
ret = net_foreachroute_ipv4(net_ipv4_devmatch, &match);
if (ret > 0)
{
/* 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 */
};
/* 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);
#endif
@ -87,9 +87,10 @@ struct net_route_ipv6_s
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
/****************************************************************************
@ -107,11 +108,11 @@ extern "C"
/* This is the routing table */
#ifdef CONFIG_NET_IPv4
EXTERN sq_queue_t g_routes;
EXTERN sq_queue_t g_ipv4_routes;
#endif
#ifdef CONFIG_NET_IPv6
EXTERN sq_queue_t g_routes_ipv6;
EXTERN sq_queue_t g_ipv6_routes;
#endif
/****************************************************************************
@ -135,7 +136,7 @@ EXTERN sq_queue_t g_routes_ipv6;
void net_initroute(void);
/****************************************************************************
* Name: net_allocroute
* Name: net_allocroute_ipv4 and net_allocroute_ipv6
*
* Description:
* Allocate one route by removing it from the free list
@ -150,7 +151,7 @@ void net_initroute(void);
****************************************************************************/
#ifdef CONFIG_NET_IPv4
FAR struct net_route_s *net_allocroute(void);
FAR struct net_route_s *net_allocroute_ipv4(void);
#endif
#ifdef CONFIG_NET_IPv6
@ -158,7 +159,7 @@ FAR struct net_route_ipv6_s *net_allocroute_ipv6(void);
#endif
/****************************************************************************
* Name: net_allocroute
* Name: net_freeroute_ipv4 and net_freeroute_ipv6
*
* Description:
* 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
void net_freeroute(FAR struct net_route_s *route);
void net_freeroute_ipv4(FAR struct net_route_s *route);
#endif
#ifdef CONFIG_NET_IPv6
@ -180,7 +181,7 @@ void net_freeroute_ipv6(FAR struct net_route_ipv6_s *route);
#endif
/****************************************************************************
* Name: net_addroute
* Name: net_addroute_ipv4 and net_addroute_ipv6
*
* Description:
* 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
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);
#endif
#ifdef CONFIG_NET_IPv6
@ -207,7 +208,7 @@ int net_addroute_ipv6(net_ipv6addr_t target, net_ipv6addr_t netmask,
#endif
/****************************************************************************
* Name: net_delroute
* Name: net_delroute_ipv4 and net_delroute_ipv6
*
* Description:
* 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
int net_delroute(in_addr_t target, in_addr_t netmask);
int net_delroute_ipv4(in_addr_t target, in_addr_t netmask);
#endif
#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
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
/****************************************************************************
@ -325,7 +326,7 @@ void netdev_ipv6_router(FAR struct net_driver_s *dev,
#endif
/****************************************************************************
* Name: net_foreachroute
* Name: net_foreachroute_ipv4
*
* Description:
* Traverse the routing table
@ -338,7 +339,7 @@ void netdev_ipv6_router(FAR struct net_driver_s *dev,
****************************************************************************/
#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
#ifdef CONFIG_NET_IPv6