mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-05 04:08:01 +02:00
platform: add paramter to ip4_route_add to set src (RTA_PREFSRC)
Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
parent
ad73a7a1e9
commit
0b50940f43
8 changed files with 32 additions and 21 deletions
|
|
@ -256,6 +256,7 @@ _platform_route_sync_add (const VTableIP *vtable, NMDefaultRouteManager *self, g
|
|||
0,
|
||||
0,
|
||||
entry->route.r4.gateway,
|
||||
0,
|
||||
entry->effective_metric,
|
||||
entry->route.rx.mss);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1045,7 +1045,7 @@ ip6_route_get_all (NMPlatform *platform, int ifindex, NMPlatformGetRouteMode mod
|
|||
static gboolean
|
||||
ip4_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
|
||||
in_addr_t network, int plen, in_addr_t gateway,
|
||||
guint32 metric, guint32 mss)
|
||||
guint32 pref_src, guint32 metric, guint32 mss)
|
||||
{
|
||||
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
|
||||
NMPlatformIP4Route route;
|
||||
|
|
|
|||
|
|
@ -3735,6 +3735,7 @@ clear_host_address (int family, const void *network, int plen, void *dst)
|
|||
static struct nl_object *
|
||||
build_rtnl_route (int family, int ifindex, NMIPConfigSource source,
|
||||
gconstpointer network, int plen, gconstpointer gateway,
|
||||
gconstpointer pref_src,
|
||||
guint32 metric, guint32 mss)
|
||||
{
|
||||
guint32 network_clean[4];
|
||||
|
|
@ -3744,6 +3745,7 @@ build_rtnl_route (int family, int ifindex, NMIPConfigSource source,
|
|||
/* Workaround a libnl bug by using zero destination address length for default routes */
|
||||
auto_nl_addr struct nl_addr *dst = NULL;
|
||||
auto_nl_addr struct nl_addr *gw = gateway ? _nm_nl_addr_build (family, gateway, addrlen) : NULL;
|
||||
auto_nl_addr struct nl_addr *pref_src_nl = pref_src ? _nm_nl_addr_build (family, pref_src, addrlen) : NULL;
|
||||
|
||||
/* There seem to be problems adding a route with non-zero host identifier.
|
||||
* Adding IPv6 routes is simply ignored, without error message.
|
||||
|
|
@ -3765,6 +3767,8 @@ build_rtnl_route (int family, int ifindex, NMIPConfigSource source,
|
|||
rtnl_route_nh_set_ifindex (nexthop, ifindex);
|
||||
if (gw && !nl_addr_iszero (gw))
|
||||
rtnl_route_nh_set_gateway (nexthop, gw);
|
||||
if (pref_src_nl)
|
||||
rtnl_route_set_pref_src (rtnlroute, pref_src_nl);
|
||||
rtnl_route_add_nexthop (rtnlroute, nexthop);
|
||||
|
||||
if (mss > 0)
|
||||
|
|
@ -3776,9 +3780,9 @@ build_rtnl_route (int family, int ifindex, NMIPConfigSource source,
|
|||
static gboolean
|
||||
ip4_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
|
||||
in_addr_t network, int plen, in_addr_t gateway,
|
||||
guint32 metric, guint32 mss)
|
||||
guint32 pref_src, guint32 metric, guint32 mss)
|
||||
{
|
||||
return add_object (platform, build_rtnl_route (AF_INET, ifindex, source, &network, plen, &gateway, metric, mss));
|
||||
return add_object (platform, build_rtnl_route (AF_INET, ifindex, source, &network, plen, &gateway, pref_src ? &pref_src : NULL, metric, mss));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
@ -3786,7 +3790,7 @@ ip6_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
|
|||
struct in6_addr network, int plen, struct in6_addr gateway,
|
||||
guint32 metric, guint32 mss)
|
||||
{
|
||||
return add_object (platform, build_rtnl_route (AF_INET6, ifindex, source, &network, plen, &gateway, metric, mss));
|
||||
return add_object (platform, build_rtnl_route (AF_INET6, ifindex, source, &network, plen, &gateway, NULL, metric, mss));
|
||||
}
|
||||
|
||||
static struct rtnl_route *
|
||||
|
|
@ -3843,7 +3847,7 @@ ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, int plen
|
|||
{
|
||||
in_addr_t gateway = 0;
|
||||
struct rtnl_route *cached_object;
|
||||
struct nl_object *route = build_rtnl_route (AF_INET, ifindex, NM_IP_CONFIG_SOURCE_UNKNOWN, &network, plen, &gateway, metric, 0);
|
||||
struct nl_object *route = build_rtnl_route (AF_INET, ifindex, NM_IP_CONFIG_SOURCE_UNKNOWN, &network, plen, &gateway, NULL, metric, 0);
|
||||
uint8_t scope = RT_SCOPE_NOWHERE;
|
||||
struct nl_cache *cache;
|
||||
|
||||
|
|
@ -3903,7 +3907,7 @@ ip6_route_delete (NMPlatform *platform, int ifindex, struct in6_addr network, in
|
|||
{
|
||||
struct in6_addr gateway = IN6ADDR_ANY_INIT;
|
||||
|
||||
return delete_object (platform, build_rtnl_route (AF_INET6, ifindex, NM_IP_CONFIG_SOURCE_UNKNOWN ,&network, plen, &gateway, metric, 0), FALSE) &&
|
||||
return delete_object (platform, build_rtnl_route (AF_INET6, ifindex, NM_IP_CONFIG_SOURCE_UNKNOWN ,&network, plen, &gateway, NULL, metric, 0), FALSE) &&
|
||||
refresh_route (platform, AF_INET6, ifindex, &network, plen, metric);
|
||||
}
|
||||
|
||||
|
|
@ -3912,7 +3916,7 @@ ip_route_exists (NMPlatform *platform, int family, int ifindex, gpointer network
|
|||
{
|
||||
auto_nl_object struct nl_object *object = build_rtnl_route (family, ifindex,
|
||||
NM_IP_CONFIG_SOURCE_UNKNOWN,
|
||||
network, plen, NULL, metric, 0);
|
||||
network, plen, NULL, NULL, metric, 0);
|
||||
struct nl_cache *cache = choose_cache (platform, object);
|
||||
auto_nl_object struct nl_object *cached_object = nl_cache_search (cache, object);
|
||||
|
||||
|
|
|
|||
|
|
@ -1868,7 +1868,8 @@ nm_platform_ip6_route_get_all (int ifindex, NMPlatformGetRouteMode mode)
|
|||
gboolean
|
||||
nm_platform_ip4_route_add (int ifindex, NMIPConfigSource source,
|
||||
in_addr_t network, int plen,
|
||||
in_addr_t gateway, guint32 metric, guint32 mss)
|
||||
in_addr_t gateway, guint32 pref_src,
|
||||
guint32 metric, guint32 mss)
|
||||
{
|
||||
reset_error ();
|
||||
|
||||
|
|
@ -1878,6 +1879,7 @@ nm_platform_ip4_route_add (int ifindex, NMIPConfigSource source,
|
|||
|
||||
if (nm_logging_enabled (LOGL_DEBUG, LOGD_PLATFORM)) {
|
||||
NMPlatformIP4Route route = { 0 };
|
||||
char pref_src_buf[NM_UTILS_INET_ADDRSTRLEN];
|
||||
|
||||
route.ifindex = ifindex;
|
||||
route.source = source;
|
||||
|
|
@ -1887,9 +1889,12 @@ nm_platform_ip4_route_add (int ifindex, NMIPConfigSource source,
|
|||
route.metric = metric;
|
||||
route.mss = mss;
|
||||
|
||||
debug ("route: adding or updating IPv4 route: %s", nm_platform_ip4_route_to_string (&route));
|
||||
debug ("route: adding or updating IPv4 route: %s%s%s%s", nm_platform_ip4_route_to_string (&route),
|
||||
pref_src ? " (src: " : "",
|
||||
pref_src ? nm_utils_inet4_ntop (pref_src, pref_src_buf) : "",
|
||||
pref_src ? ")" : "");
|
||||
}
|
||||
return klass->ip4_route_add (platform, ifindex, source, network, plen, gateway, metric, mss);
|
||||
return klass->ip4_route_add (platform, ifindex, source, network, plen, gateway, pref_src, metric, mss);
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
|
@ -2066,6 +2071,7 @@ nm_platform_ip4_route_sync (int ifindex, const GArray *known_routes)
|
|||
known_route->network,
|
||||
known_route->plen,
|
||||
known_route->gateway,
|
||||
0,
|
||||
known_route->metric,
|
||||
known_route->mss);
|
||||
if (!success && known_route->source < NM_IP_CONFIG_SOURCE_USER) {
|
||||
|
|
|
|||
|
|
@ -417,7 +417,7 @@ typedef struct {
|
|||
GArray * (*ip6_route_get_all) (NMPlatform *, int ifindex, NMPlatformGetRouteMode mode);
|
||||
gboolean (*ip4_route_add) (NMPlatform *, int ifindex, NMIPConfigSource source,
|
||||
in_addr_t network, int plen, in_addr_t gateway,
|
||||
guint32 metric, guint32 mss);
|
||||
guint32 pref_src, guint32 metric, guint32 mss);
|
||||
gboolean (*ip6_route_add) (NMPlatform *, int ifindex, NMIPConfigSource source,
|
||||
struct in6_addr network, int plen, struct in6_addr gateway,
|
||||
guint32 metric, guint32 mss);
|
||||
|
|
@ -564,7 +564,7 @@ GArray *nm_platform_ip4_route_get_all (int ifindex, NMPlatformGetRouteMode mode)
|
|||
GArray *nm_platform_ip6_route_get_all (int ifindex, NMPlatformGetRouteMode mode);
|
||||
gboolean nm_platform_ip4_route_add (int ifindex, NMIPConfigSource source,
|
||||
in_addr_t network, int plen, in_addr_t gateway,
|
||||
guint32 metric, guint32 mss);
|
||||
guint32 pref_src, guint32 metric, guint32 mss);
|
||||
gboolean nm_platform_ip6_route_add (int ifindex, NMIPConfigSource source,
|
||||
struct in6_addr network, int plen, struct in6_addr gateway,
|
||||
guint32 metric, guint32 mss);
|
||||
|
|
|
|||
|
|
@ -684,7 +684,7 @@ do_ip4_route_add (char **argv)
|
|||
mss = strtol (*argv++, NULL, 10);
|
||||
|
||||
return nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER,
|
||||
network, plen, gateway,
|
||||
network, plen, gateway, 0,
|
||||
metric, mss);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,9 +45,9 @@ test_cleanup_internal (void)
|
|||
/* Add routes and addresses */
|
||||
g_assert (nm_platform_ip4_address_add (ifindex, addr4, 0, plen4, lifetime, preferred, NULL));
|
||||
g_assert (nm_platform_ip6_address_add (ifindex, addr6, in6addr_any, plen6, lifetime, preferred, flags));
|
||||
g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, gateway4, 32, INADDR_ANY, metric, mss));
|
||||
g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, network4, plen4, gateway4, metric, mss));
|
||||
g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, 0, 0, gateway4, metric, mss));
|
||||
g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, gateway4, 32, INADDR_ANY, 0, metric, mss));
|
||||
g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, network4, plen4, gateway4, 0, metric, mss));
|
||||
g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, 0, 0, gateway4, 0, metric, mss));
|
||||
g_assert (nm_platform_ip6_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, gateway6, 128, in6addr_any, metric, mss));
|
||||
g_assert (nm_platform_ip6_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, network6, plen6, gateway6, metric, mss));
|
||||
g_assert (nm_platform_ip6_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, in6addr_any, 0, gateway6, metric, mss));
|
||||
|
|
|
|||
|
|
@ -68,35 +68,35 @@ test_ip4_route (void)
|
|||
inet_pton (AF_INET, "198.51.100.1", &gateway);
|
||||
|
||||
/* Add route to gateway */
|
||||
g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, gateway, 32, INADDR_ANY, metric, mss));
|
||||
g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, gateway, 32, INADDR_ANY, 0, metric, mss));
|
||||
no_error ();
|
||||
accept_signal (route_added);
|
||||
|
||||
/* Add route */
|
||||
g_assert (!nm_platform_ip4_route_exists (ifindex, network, plen, metric));
|
||||
no_error ();
|
||||
g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, metric, mss));
|
||||
g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, 0, metric, mss));
|
||||
no_error ();
|
||||
g_assert (nm_platform_ip4_route_exists (ifindex, network, plen, metric));
|
||||
no_error ();
|
||||
accept_signal (route_added);
|
||||
|
||||
/* Add route again */
|
||||
g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, metric, mss));
|
||||
g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, 0, metric, mss));
|
||||
no_error ();
|
||||
accept_signal (route_changed);
|
||||
|
||||
/* Add default route */
|
||||
g_assert (!nm_platform_ip4_route_exists (ifindex, 0, 0, metric));
|
||||
no_error ();
|
||||
g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, 0, 0, gateway, metric, mss));
|
||||
g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, 0, 0, gateway, 0, metric, mss));
|
||||
no_error ();
|
||||
g_assert (nm_platform_ip4_route_exists (ifindex, 0, 0, metric));
|
||||
no_error ();
|
||||
accept_signal (route_added);
|
||||
|
||||
/* Add default route again */
|
||||
g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, 0, 0, gateway, metric, mss));
|
||||
g_assert (nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_USER, 0, 0, gateway, 0, metric, mss));
|
||||
no_error ();
|
||||
accept_signal (route_changed);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue