mirror of
https://github.com/apache/nuttx.git
synced 2026-05-26 10:46:28 +08:00
net/netlink: Add RTM route support
Signed-off-by: meijian <meijian@xiaomi.com>
This commit is contained in:
committed by
Alan Carvalho de Assis
parent
98d5e118c0
commit
34aeeb024c
@@ -33,6 +33,7 @@
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/net/ip.h>
|
||||
|
||||
#include "netlink/netlink.h"
|
||||
#include "route/fileroute.h"
|
||||
#include "route/route.h"
|
||||
|
||||
@@ -84,6 +85,8 @@ int net_addroute_ipv4(in_addr_t target, in_addr_t netmask, in_addr_t router)
|
||||
nwritten = net_writeroute_ipv4(&fshandle, &route);
|
||||
|
||||
net_closeroute_ipv4(&fshandle);
|
||||
|
||||
netlink_route_notify(&route, RTM_NEWROUTE, AF_INET);
|
||||
return nwritten >= 0 ? 0 : (int)nwritten;
|
||||
}
|
||||
#endif
|
||||
@@ -118,6 +121,8 @@ int net_addroute_ipv6(net_ipv6addr_t target, net_ipv6addr_t netmask,
|
||||
nwritten = net_writeroute_ipv6(&fshandle, &route);
|
||||
|
||||
net_closeroute_ipv6(&fshandle);
|
||||
|
||||
netlink_route_notify(&route, RTM_NEWROUTE, AF_INET6);
|
||||
return nwritten >= 0 ? 0 : (int)nwritten;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
|
||||
#include <arch/irq.h>
|
||||
|
||||
#include "netlink/netlink.h"
|
||||
#include "route/ramroute.h"
|
||||
#include "route/route.h"
|
||||
|
||||
@@ -86,6 +87,8 @@ int net_addroute_ipv4(in_addr_t target, in_addr_t netmask, in_addr_t router)
|
||||
ramroute_ipv4_addlast((FAR struct net_route_ipv4_entry_s *)route,
|
||||
&g_ipv4_routes);
|
||||
net_unlock();
|
||||
|
||||
netlink_route_notify(route, RTM_NEWROUTE, AF_INET);
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
@@ -121,6 +124,8 @@ int net_addroute_ipv6(net_ipv6addr_t target, net_ipv6addr_t netmask,
|
||||
ramroute_ipv6_addlast((FAR struct net_route_ipv6_entry_s *)route,
|
||||
&g_ipv6_routes);
|
||||
net_unlock();
|
||||
|
||||
netlink_route_notify(route, RTM_NEWROUTE, AF_INET6);
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/net/ip.h>
|
||||
|
||||
#include "netlink/netlink.h"
|
||||
#include "route/fileroute.h"
|
||||
#include "route/cacheroute.h"
|
||||
#include "route/route.h"
|
||||
@@ -313,6 +314,8 @@ int net_delroute_ipv4(in_addr_t target, in_addr_t netmask)
|
||||
filesize = (nentries - 1) * sizeof(struct net_route_ipv4_s);
|
||||
ret = file_truncate(&fshandle, filesize);
|
||||
|
||||
netlink_route_notify(&match, RTM_DELROUTE, AF_INET);
|
||||
|
||||
errout_with_fshandle:
|
||||
net_closeroute_ipv4(&fshandle);
|
||||
|
||||
@@ -464,6 +467,8 @@ int net_delroute_ipv6(net_ipv6addr_t target, net_ipv6addr_t netmask)
|
||||
filesize = (nentries - 1) * sizeof(struct net_route_ipv6_s);
|
||||
ret = file_truncate(&fshandle, filesize);
|
||||
|
||||
netlink_route_notify(&match, RTM_DELROUTE, AF_INET6);
|
||||
|
||||
errout_with_fshandle:
|
||||
net_closeroute_ipv6(&fshandle);
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <nuttx/net/ip.h>
|
||||
|
||||
#include "netlink/netlink.h"
|
||||
#include "route/ramroute.h"
|
||||
#include "route/route.h"
|
||||
|
||||
@@ -64,10 +65,10 @@ struct route_match_ipv6_s
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_match_ipv4
|
||||
* Name: net_del_ipv4route
|
||||
*
|
||||
* Description:
|
||||
* Return 1 if the route is available
|
||||
* Return 1 if the route is available, and delete the match route
|
||||
*
|
||||
* Input Parameters:
|
||||
* route - The next route to examine
|
||||
@@ -79,7 +80,8 @@ struct route_match_ipv6_s
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ROUTE_IPv4_RAMROUTE
|
||||
static int net_match_ipv4(FAR struct net_route_ipv4_s *route, FAR void *arg)
|
||||
static int net_del_ipv4route(FAR struct net_route_ipv4_s *route,
|
||||
FAR void *arg)
|
||||
{
|
||||
FAR struct route_match_ipv4_s *match =
|
||||
(FAR struct route_match_ipv4_s *)arg;
|
||||
@@ -109,6 +111,8 @@ static int net_match_ipv4(FAR struct net_route_ipv4_s *route, FAR void *arg)
|
||||
ramroute_ipv4_remfirst(&g_ipv4_routes);
|
||||
}
|
||||
|
||||
netlink_route_notify(route, RTM_DELROUTE, AF_INET);
|
||||
|
||||
/* And free the routing table entry by adding it to the free list */
|
||||
|
||||
net_freeroute_ipv4(route);
|
||||
@@ -126,8 +130,8 @@ static int net_match_ipv4(FAR struct net_route_ipv4_s *route, FAR void *arg)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ROUTE_IPv6_RAMROUTE
|
||||
static int net_match_ipv6(
|
||||
FAR struct net_route_ipv6_s *route, FAR void *arg)
|
||||
static int net_del_ipv6route(FAR struct net_route_ipv6_s *route,
|
||||
FAR void *arg)
|
||||
{
|
||||
FAR struct route_match_ipv6_s *match =
|
||||
(FAR struct route_match_ipv6_s *)arg;
|
||||
@@ -165,6 +169,8 @@ static int net_match_ipv6(
|
||||
ramroute_ipv6_remfirst(&g_ipv6_routes);
|
||||
}
|
||||
|
||||
netlink_route_notify(route, RTM_DELROUTE, AF_INET6);
|
||||
|
||||
/* And free the routing table entry by adding it to the free list */
|
||||
|
||||
net_freeroute_ipv6(route);
|
||||
@@ -211,7 +217,7 @@ int net_delroute_ipv4(in_addr_t target, in_addr_t netmask)
|
||||
|
||||
/* Then remove the entry from the routing table */
|
||||
|
||||
return net_foreachroute_ipv4(net_match_ipv4, &match) ? OK : -ENOENT;
|
||||
return net_foreachroute_ipv4(net_del_ipv4route, &match) ? OK : -ENOENT;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -228,7 +234,7 @@ int net_delroute_ipv6(net_ipv6addr_t target, net_ipv6addr_t netmask)
|
||||
|
||||
/* Then remove the entry from the routing table */
|
||||
|
||||
return net_foreachroute_ipv6(net_match_ipv6, &match) ? OK : -ENOENT;
|
||||
return net_foreachroute_ipv6(net_del_ipv6route, &match) ? OK : -ENOENT;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user