platform: support specifying the fwmark in ip_route_get()
Add an optional argument to specify the fwmark, which will be used in the next commits to return results that match a specific rule.
This commit is contained in:
@@ -574,6 +574,7 @@ test_ip4_route_get(void)
|
||||
result = nm_platform_ip_route_get(NM_PLATFORM_GET,
|
||||
AF_INET,
|
||||
&a,
|
||||
0,
|
||||
nmtst_get_rand_uint32() % 2 ? 0 : ifindex,
|
||||
&route);
|
||||
|
||||
@@ -766,6 +767,7 @@ test_ip6_route_get(void)
|
||||
result = nm_platform_ip_route_get(NM_PLATFORM_GET,
|
||||
AF_INET6,
|
||||
a,
|
||||
0,
|
||||
nmtst_get_rand_uint32() % 2 ? 0 : ifindex,
|
||||
&route);
|
||||
|
||||
|
@@ -1203,6 +1203,7 @@ _parent_device_l3cd_add_gateway_route(NML3ConfigData *l3cd,
|
||||
r = nm_platform_ip_route_get(platform,
|
||||
addr_family,
|
||||
vpn_gw,
|
||||
0,
|
||||
ifindex,
|
||||
(NMPObject **) &route_resolved);
|
||||
if (r >= 0) {
|
||||
|
@@ -10591,6 +10591,7 @@ static int
|
||||
ip_route_get(NMPlatform *platform,
|
||||
int addr_family,
|
||||
gconstpointer address,
|
||||
guint32 fwmark,
|
||||
int oif_ifindex,
|
||||
NMPObject **out_route)
|
||||
{
|
||||
@@ -10625,6 +10626,11 @@ ip_route_get(NMPlatform *platform,
|
||||
if (!_nl_addattr_l(&req.n, sizeof(req), RTA_DST, address, addr_len))
|
||||
nm_assert_not_reached();
|
||||
|
||||
if (fwmark != 0) {
|
||||
if (!_nl_addattr_l(&req.n, sizeof(req), RTA_MARK, &fwmark, sizeof(fwmark)))
|
||||
nm_assert_not_reached();
|
||||
}
|
||||
|
||||
if (oif_ifindex > 0) {
|
||||
gint32 ii = oif_ifindex;
|
||||
|
||||
|
@@ -5603,6 +5603,7 @@ int
|
||||
nm_platform_ip_route_get(NMPlatform *self,
|
||||
int addr_family,
|
||||
gconstpointer address /* in_addr_t or struct in6_addr */,
|
||||
guint32 fwmark,
|
||||
int oif_ifindex,
|
||||
NMPObject **out_route)
|
||||
{
|
||||
@@ -5611,21 +5612,23 @@ nm_platform_ip_route_get(NMPlatform *self,
|
||||
int result;
|
||||
char buf[NM_INET_ADDRSTRLEN];
|
||||
char buf_oif[64];
|
||||
char buf_fwmark[64];
|
||||
|
||||
_CHECK_SELF(self, klass, FALSE);
|
||||
|
||||
g_return_val_if_fail(address, -NME_BUG);
|
||||
g_return_val_if_fail(NM_IN_SET(addr_family, AF_INET, AF_INET6), -NME_BUG);
|
||||
|
||||
_LOGT("route: get IPv%c route for: %s%s",
|
||||
_LOGT("route: get IPv%c route for: %s%s%s",
|
||||
nm_utils_addr_family_to_char(addr_family),
|
||||
inet_ntop(addr_family, address, buf, sizeof(buf)),
|
||||
oif_ifindex > 0 ? nm_sprintf_buf(buf_oif, " oif %d", oif_ifindex) : "");
|
||||
oif_ifindex > 0 ? nm_sprintf_buf(buf_oif, " oif %d", oif_ifindex) : "",
|
||||
fwmark > 0 ? nm_sprintf_buf(buf_fwmark, " fwmark %u", fwmark) : "");
|
||||
|
||||
if (!klass->ip_route_get)
|
||||
result = -NME_PL_OPNOTSUPP;
|
||||
else {
|
||||
result = klass->ip_route_get(self, addr_family, address, oif_ifindex, &route);
|
||||
result = klass->ip_route_get(self, addr_family, address, fwmark, oif_ifindex, &route);
|
||||
}
|
||||
|
||||
if (result < 0) {
|
||||
|
@@ -1321,6 +1321,7 @@ typedef struct {
|
||||
int (*ip_route_get)(NMPlatform *self,
|
||||
int addr_family,
|
||||
gconstpointer address,
|
||||
guint32 fwmark,
|
||||
int oif_ifindex,
|
||||
NMPObject **out_route);
|
||||
|
||||
@@ -2432,6 +2433,7 @@ gboolean nm_platform_ip_route_flush(NMPlatform *self, int addr_family, int ifind
|
||||
int nm_platform_ip_route_get(NMPlatform *self,
|
||||
int addr_family,
|
||||
gconstpointer address,
|
||||
guint32 fwmark,
|
||||
int oif_ifindex,
|
||||
NMPObject **out_route);
|
||||
|
||||
|
Reference in New Issue
Block a user