platform: introduce function to globally track local route rule

The new function tracks local route rule in the GlobalTracker properly.
It also allow the developer to specify the untrack user tag.
This commit is contained in:
Fernando Fernandez Mancera 2023-02-20 17:39:29 +01:00
parent 3a3ac89b53
commit 79611e4fcc
2 changed files with 47 additions and 22 deletions

View file

@ -1155,17 +1155,7 @@ nmp_global_tracker_track_rule_default(NMPGlobalTracker *self,
/* track the default rules. See also `man ip-rule`. */
if (NM_IN_SET(addr_family, AF_UNSPEC, AF_INET)) {
nmp_global_tracker_track_rule(self,
&((NMPlatformRoutingRule){
.addr_family = AF_INET,
.priority = 0,
.table = RT_TABLE_LOCAL,
.action = FR_ACT_TO_TBL,
.protocol = RTPROT_KERNEL,
}),
track_priority,
user_tag,
NULL);
nmp_global_tracker_track_local_rule(self, addr_family, track_priority, user_tag, NULL);
nmp_global_tracker_track_rule(self,
&((NMPlatformRoutingRule){
.addr_family = AF_INET,
@ -1190,17 +1180,7 @@ nmp_global_tracker_track_rule_default(NMPGlobalTracker *self,
NULL);
}
if (NM_IN_SET(addr_family, AF_UNSPEC, AF_INET6)) {
nmp_global_tracker_track_rule(self,
&((NMPlatformRoutingRule){
.addr_family = AF_INET6,
.priority = 0,
.table = RT_TABLE_LOCAL,
.action = FR_ACT_TO_TBL,
.protocol = RTPROT_KERNEL,
}),
track_priority,
user_tag,
NULL);
nmp_global_tracker_track_local_rule(self, addr_family, track_priority, user_tag, NULL);
nmp_global_tracker_track_rule(self,
&((NMPlatformRoutingRule){
.addr_family = AF_INET6,
@ -1215,6 +1195,45 @@ nmp_global_tracker_track_rule_default(NMPGlobalTracker *self,
}
}
void
nmp_global_tracker_track_local_rule(NMPGlobalTracker *self,
int addr_family,
gint32 track_priority,
gconstpointer user_tag,
gconstpointer user_tag_untrack)
{
g_return_if_fail(NMP_IS_GLOBAL_TRACKER(self));
nm_assert(NM_IN_SET(addr_family, AF_UNSPEC, AF_INET, AF_INET6));
if (NM_IN_SET(addr_family, AF_UNSPEC, AF_INET)) {
nmp_global_tracker_track_rule(self,
&((NMPlatformRoutingRule){
.addr_family = AF_INET,
.priority = 0,
.table = RT_TABLE_LOCAL,
.action = FR_ACT_TO_TBL,
.protocol = RTPROT_KERNEL,
}),
track_priority,
user_tag,
user_tag_untrack);
}
if (NM_IN_SET(addr_family, AF_UNSPEC, AF_INET6)) {
nmp_global_tracker_track_rule(self,
&((NMPlatformRoutingRule){
.addr_family = AF_INET6,
.priority = 0,
.table = RT_TABLE_LOCAL,
.action = FR_ACT_TO_TBL,
.protocol = RTPROT_KERNEL,
}),
track_priority,
user_tag,
user_tag_untrack);
}
}
/*****************************************************************************/
NMPGlobalTracker *

View file

@ -46,6 +46,12 @@ void nmp_global_tracker_track_rule_default(NMPGlobalTracker *self,
gint32 track_priority,
gconstpointer user_tag);
void nmp_global_tracker_track_local_rule(NMPGlobalTracker *self,
int addr_family,
gint32 track_priority,
gconstpointer user_tag,
gconstpointer user_tag_untrack);
void nmp_global_tracker_track_rule_from_platform(NMPGlobalTracker *self,
NMPlatform *platform,
int addr_family,