platform: add oif argument to nm_platform_ip_route_get()
Analog to `ip route get $DST oif $IFACE`.
This commit is contained in:
@@ -6033,6 +6033,7 @@ static NMPlatformError
|
||||
ip_route_get (NMPlatform *platform,
|
||||
int addr_family,
|
||||
gconstpointer address,
|
||||
int oif_ifindex,
|
||||
NMPObject **out_route)
|
||||
{
|
||||
const gboolean is_v4 = (addr_family == AF_INET);
|
||||
@@ -6066,6 +6067,13 @@ ip_route_get (NMPlatform *platform,
|
||||
if (!_nl_addattr_l (&req.n, sizeof (req), RTA_DST, address, addr_len))
|
||||
nm_assert_not_reached ();
|
||||
|
||||
if (oif_ifindex > 0) {
|
||||
gint32 ii = oif_ifindex;
|
||||
|
||||
if (!_nl_addattr_l (&req.n, sizeof (req), RTA_OIF, &ii, sizeof (ii)))
|
||||
nm_assert_not_reached ();
|
||||
}
|
||||
|
||||
seq_result = WAIT_FOR_NL_RESPONSE_RESULT_UNKNOWN;
|
||||
nle = _nl_send_nlmsghdr (platform, &req.n, &seq_result, DELAYED_ACTION_RESPONSE_TYPE_ROUTE_GET, &route);
|
||||
if (nle < 0) {
|
||||
|
@@ -3888,12 +3888,14 @@ NMPlatformError
|
||||
nm_platform_ip_route_get (NMPlatform *self,
|
||||
int addr_family,
|
||||
gconstpointer address /* in_addr_t or struct in6_addr */,
|
||||
int oif_ifindex,
|
||||
NMPObject **out_route)
|
||||
{
|
||||
nm_auto_nmpobj NMPObject *route = NULL;
|
||||
NMPlatformError result;
|
||||
char buf[NM_UTILS_INET_ADDRSTRLEN];
|
||||
char buf_err[200];
|
||||
char buf_oif[64];
|
||||
|
||||
_CHECK_SELF (self, klass, FALSE);
|
||||
|
||||
@@ -3901,9 +3903,10 @@ nm_platform_ip_route_get (NMPlatform *self,
|
||||
g_return_val_if_fail (NM_IN_SET (addr_family, AF_INET,
|
||||
AF_INET6), NM_PLATFORM_ERROR_BUG);
|
||||
|
||||
_LOGT ("route: get IPv%c route for: %s",
|
||||
_LOGT ("route: get IPv%c route for: %s%s",
|
||||
addr_family == AF_INET ? '4' : '6',
|
||||
inet_ntop (addr_family, address, buf, sizeof (buf)));
|
||||
inet_ntop (addr_family, address, buf, sizeof (buf)),
|
||||
oif_ifindex > 0 ? nm_sprintf_buf (buf_oif, " oif %d", oif_ifindex) : "");
|
||||
|
||||
if (!klass->ip_route_get)
|
||||
result = NM_PLATFORM_ERROR_OPNOTSUPP;
|
||||
@@ -3911,6 +3914,7 @@ nm_platform_ip_route_get (NMPlatform *self,
|
||||
result = klass->ip_route_get (self,
|
||||
addr_family,
|
||||
address,
|
||||
oif_ifindex,
|
||||
&route);
|
||||
}
|
||||
|
||||
|
@@ -823,6 +823,7 @@ typedef struct {
|
||||
NMPlatformError (*ip_route_get) (NMPlatform *self,
|
||||
int addr_family,
|
||||
gconstpointer address,
|
||||
int oif_ifindex,
|
||||
NMPObject **out_route);
|
||||
|
||||
gboolean (*check_support_kernel_extended_ifa_flags) (NMPlatform *);
|
||||
@@ -1186,6 +1187,7 @@ gboolean nm_platform_ip_route_flush (NMPlatform *self,
|
||||
NMPlatformError nm_platform_ip_route_get (NMPlatform *self,
|
||||
int addr_family,
|
||||
gconstpointer address,
|
||||
int oif_ifindex,
|
||||
NMPObject **out_route);
|
||||
|
||||
const char *nm_platform_link_to_string (const NMPlatformLink *link, char *buf, gsize len);
|
||||
|
@@ -409,6 +409,7 @@ test_ip_route_get (void)
|
||||
result = nm_platform_ip_route_get (NM_PLATFORM_GET,
|
||||
AF_INET,
|
||||
&a,
|
||||
nmtst_get_rand_int () % 2 ? 0 : ifindex,
|
||||
&route);
|
||||
|
||||
g_assert (result == NM_PLATFORM_ERROR_SUCCESS);
|
||||
@@ -417,6 +418,7 @@ test_ip_route_get (void)
|
||||
g_assert (route->parent._ref_count == 1);
|
||||
r = NMP_OBJECT_CAST_IP4_ROUTE (route);
|
||||
g_assert (r->rt_cloned);
|
||||
g_assert (r->ifindex == ifindex);
|
||||
g_assert (r->network == a);
|
||||
g_assert (r->plen == 32);
|
||||
|
||||
|
@@ -741,6 +741,7 @@ add_ip4_vpn_gateway_route (NMIP4Config *config,
|
||||
if (nm_platform_ip_route_get (platform,
|
||||
AF_INET,
|
||||
&vpn_gw,
|
||||
0,
|
||||
(NMPObject **) &route_resolved) == NM_PLATFORM_ERROR_SUCCESS) {
|
||||
const NMPlatformIP4Route *r = NMP_OBJECT_CAST_IP4_ROUTE (route_resolved);
|
||||
|
||||
@@ -811,6 +812,7 @@ add_ip6_vpn_gateway_route (NMIP6Config *config,
|
||||
if (nm_platform_ip_route_get (platform,
|
||||
AF_INET6,
|
||||
vpn_gw,
|
||||
0,
|
||||
(NMPObject **) &route_resolved) == NM_PLATFORM_ERROR_SUCCESS) {
|
||||
const NMPlatformIP6Route *r = NMP_OBJECT_CAST_IP6_ROUTE (route_resolved);
|
||||
|
||||
|
Reference in New Issue
Block a user