Skip to content

Commit 2d96142

Browse files
lucassdiassdceara
authored andcommitted
ic: Add tag rules to filter the routes learned from a TS.
The "ic-route-filter-tag" option of a Logical_Router_Port connected to a transit switch blocks the routes carrying a single route tag. There is no way to express a list of tags, nor the opposite rule - "learn only the routes tagged with one of these tags" - which is useful when a router port has to import the routes of a known set of VPCs and drop everything else. Add an "ic-route-learn-tag-rules" option that takes a comma-separated list of route tags prefixed by the rule to apply to them: - "allow:<tags>": only the routes whose "ic-route-tag" is one of <tags> are learned. Every other route, the untagged ones included, is not learned. - "block:<tags>": the routes whose "ic-route-tag" is one of <tags> are not learned. Every other route, the untagged ones included, is learned. As commas separate the tags, a route tag cannot contain a comma. The two forms are mutually exclusive, so only the leading prefix is honored and everything after it is a tag name. Values that use neither prefix, as well as values with an empty tag list, are logged and ignored. This new option supersedes "ic-route-filter-tag", which is now deprecated and scheduled for removal in 28.09. The deprecated option is still honored on its own, but it is ignored whenever a valid "ic-route-learn-tag-rules" value is configured on the same port. Assisted-by: Claude Opus 5, Claude Code Acked-by: Rosemarie O'Riorden <rosemarie@redhat.com> Signed-off-by: Lucas Vargas Dias <lucas.vdias@magalu.cloud> Signed-off-by: Dumitru Ceara <dceara@redhat.com>
1 parent 4cd8a06 commit 2d96142

5 files changed

Lines changed: 369 additions & 3 deletions

File tree

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ Post v26.03.0
9696
egress pipelines.
9797
- The support for co-hosting multiple controller instances is now
9898
considered stable. Its "experimental" tag has been removed.
99+
- Added the "ic-route-learn-tag-rules" option to Logical_Router_Port to
100+
filter the routes learned through the port by route tag. This supersedes
101+
"ic-route-filter-tag", which is now deprecated and is ignored when
102+
"ic-route-learn-tag-rules" is set.
99103

100104
OVN v26.03.0 - xxx xx xxxx
101105
--------------------------

TODO.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ when the feature/action will move from ``Deprecated`` to ``Removed``.
224224
* ``OVN_FEATURE_MAC_BINDING_TIMESTAMP`` feature, should be removed in 28.09.
225225
* ``OVN_FEATURE_FDB_TIMESTAMP`` feature, should be removed in 28.09.
226226
* ``OVN_FEATURE_LS_DPG_COLUMN`` feature, should be removed in 28.09.
227+
* ``ic-route-filter-tag`` Logical_Router_Port option, superseded by
228+
``ic-route-learn-tag-rules``, should be removed in 28.09.
227229

228230
* 26.03 Deprecated
229231

ic/ovn-ic.c

Lines changed: 120 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2526,6 +2526,91 @@ lrp_is_ts_port(struct ic_context *ctx, struct ic_router_info *ic_lr,
25262526
return false;
25272527
}
25282528

2529+
#define IC_ROUTE_LEARN_TAG_RULES "ic-route-learn-tag-rules"
2530+
#define IC_ROUTE_LEARN_TAG_ALLOW "allow:"
2531+
#define IC_ROUTE_LEARN_TAG_BLOCK "block:"
2532+
#define IC_ROUTE_FILTER_TAG "ic-route-filter-tag"
2533+
2534+
/* Route tag rules of a TS LRP, as configured through its
2535+
* "ic-route-learn-tag-rules" option. */
2536+
struct route_learn_tag_rules {
2537+
const char *config; /* Option value, for logging purposes. */
2538+
bool configured; /* False if the option is unset or invalid, in
2539+
* which case no route is filtered. */
2540+
bool allow; /* True: only routes tagged with one of 'tags' are
2541+
* learned. False: routes tagged with one of
2542+
* 'tags' are not learned. */
2543+
struct sset tags;
2544+
};
2545+
2546+
/* Initializes 'rules' from the "ic-route-learn-tag-rules" option of 'lrp',
2547+
* which may be NULL. The option value must be either
2548+
* "allow:<comma-separated-tags>" or "block:<comma-separated-tags>"; any other
2549+
* value is logged and ignored. Route tags cannot contain commas. */
2550+
static void
2551+
route_learn_tag_rules_init(struct route_learn_tag_rules *rules,
2552+
const struct nbrec_logical_router_port *lrp)
2553+
{
2554+
static struct vlog_rate_limit bad_value_rl = VLOG_RATE_LIMIT_INIT(5, 1);
2555+
static struct vlog_rate_limit no_tag_rl = VLOG_RATE_LIMIT_INIT(5, 1);
2556+
const char *tags = "";
2557+
2558+
rules->config = lrp ? smap_get(&lrp->options, IC_ROUTE_LEARN_TAG_RULES)
2559+
: NULL;
2560+
rules->configured = false;
2561+
rules->allow = false;
2562+
2563+
if (rules->config) {
2564+
if (!strncmp(rules->config, IC_ROUTE_LEARN_TAG_ALLOW,
2565+
strlen(IC_ROUTE_LEARN_TAG_ALLOW))) {
2566+
tags = rules->config + strlen(IC_ROUTE_LEARN_TAG_ALLOW);
2567+
rules->allow = true;
2568+
rules->configured = true;
2569+
} else if (!strncmp(rules->config, IC_ROUTE_LEARN_TAG_BLOCK,
2570+
strlen(IC_ROUTE_LEARN_TAG_BLOCK))) {
2571+
tags = rules->config + strlen(IC_ROUTE_LEARN_TAG_BLOCK);
2572+
rules->configured = true;
2573+
} else {
2574+
VLOG_WARN_RL(&bad_value_rl,
2575+
"Ignoring invalid %s value [%s] of logical "
2576+
"router port %s: expected \"%s<tags>\" or "
2577+
"\"%s<tags>\".", IC_ROUTE_LEARN_TAG_RULES,
2578+
rules->config, lrp->name,
2579+
IC_ROUTE_LEARN_TAG_ALLOW, IC_ROUTE_LEARN_TAG_BLOCK);
2580+
}
2581+
}
2582+
2583+
sset_from_delimited_string(&rules->tags, tags, ",");
2584+
2585+
if (rules->configured && sset_is_empty(&rules->tags)) {
2586+
VLOG_WARN_RL(&no_tag_rl,
2587+
"Ignoring %s value [%s] of logical router port %s: "
2588+
"no route tag specified.", IC_ROUTE_LEARN_TAG_RULES,
2589+
rules->config, lrp->name);
2590+
rules->configured = false;
2591+
}
2592+
}
2593+
2594+
static void
2595+
route_learn_tag_rules_destroy(struct route_learn_tag_rules *rules)
2596+
{
2597+
sset_destroy(&rules->tags);
2598+
}
2599+
2600+
/* Returns true if a route tagged with 'route_tag' (NULL if the route
2601+
* carries no tag) can be learned according to 'rules'. */
2602+
static bool
2603+
route_learn_tag_rules_allow(const struct route_learn_tag_rules *rules,
2604+
const char *route_tag)
2605+
{
2606+
if (!rules->configured) {
2607+
return true;
2608+
}
2609+
2610+
bool listed = route_tag && sset_contains(&rules->tags, route_tag);
2611+
return rules->allow ? listed : !listed;
2612+
}
2613+
25292614
static void
25302615
sync_learned_routes(struct ic_context *ctx,
25312616
struct ic_router_info *ic_lr)
@@ -2549,12 +2634,30 @@ sync_learned_routes(struct ic_context *ctx,
25492634
if (lrp) {
25502635
ts_route_table = smap_get_def(&lrp->options, "route_table", "");
25512636
route_filter_tag = smap_get_def(&lrp->options,
2552-
"ic-route-filter-tag", "");
2637+
IC_ROUTE_FILTER_TAG, "");
25532638
} else {
25542639
ts_route_table = "";
25552640
route_filter_tag = "";
25562641
}
25572642

2643+
struct route_learn_tag_rules learn_tag_rules;
2644+
route_learn_tag_rules_init(&learn_tag_rules, lrp);
2645+
2646+
if (route_filter_tag[0]) {
2647+
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
2648+
if (learn_tag_rules.configured) {
2649+
VLOG_WARN_RL(&rl, "The deprecated %s option of logical router "
2650+
"port %s is ignored as %s is also configured.",
2651+
IC_ROUTE_FILTER_TAG, lrp->name,
2652+
IC_ROUTE_LEARN_TAG_RULES);
2653+
} else {
2654+
VLOG_WARN_RL(&rl, "The %s option of logical router port %s is "
2655+
"deprecated and will be removed in the 28.09 "
2656+
"release; use %s instead.", IC_ROUTE_FILTER_TAG,
2657+
lrp->name, IC_ROUTE_LEARN_TAG_RULES);
2658+
}
2659+
}
2660+
25582661
isb_route_key = icsbrec_route_index_init_row(ctx->icsbrec_route_by_ts);
25592662
icsbrec_route_index_set_transit_switch(isb_route_key,
25602663
isb_pb->transit_switch);
@@ -2578,14 +2681,27 @@ sync_learned_routes(struct ic_context *ctx,
25782681

25792682
const char *isb_route_tag = smap_get(&isb_route->external_ids,
25802683
"ic-route-tag");
2581-
if (isb_route_tag && !strcmp(isb_route_tag, route_filter_tag)) {
2684+
/* The deprecated filter tag is honored only when the route learn
2685+
* tag rules are not in effect. */
2686+
if (!learn_tag_rules.configured && isb_route_tag &&
2687+
!strcmp(isb_route_tag, route_filter_tag)) {
25822688
VLOG_DBG("Skip learning route %s -> %s as its route tag "
2583-
"[%s] is filtered by the filter tag [%s] of TS LRP ",
2689+
"[%s] is filtered by the filter tag [%s] of TS LRP",
25842690
isb_route->ip_prefix, isb_route->nexthop,
25852691
isb_route_tag, route_filter_tag);
25862692
continue;
25872693
}
25882694

2695+
if (!route_learn_tag_rules_allow(&learn_tag_rules,
2696+
isb_route_tag)) {
2697+
VLOG_DBG("Skip learning route %s -> %s as its route tag "
2698+
"[%s] is filtered by the %s [%s] of TS LRP",
2699+
isb_route->ip_prefix, isb_route->nexthop,
2700+
isb_route_tag ? isb_route_tag : "",
2701+
IC_ROUTE_LEARN_TAG_RULES, learn_tag_rules.config);
2702+
continue;
2703+
}
2704+
25892705
if (isb_route->route_table[0] &&
25902706
strcmp(isb_route->route_table, ts_route_table)) {
25912707
if (VLOG_IS_DBG_ENABLED()) {
@@ -2650,6 +2766,7 @@ sync_learned_routes(struct ic_context *ctx,
26502766
}
26512767
}
26522768
icsbrec_route_index_destroy_row(isb_route_key);
2769+
route_learn_tag_rules_destroy(&learn_tag_rules);
26532770
}
26542771

26552772
/* Delete extra learned routes. */

ovn-nb.xml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4697,6 +4697,67 @@ or
46974697
<ref db="OVN_IC_Southbound"/> database, will be filtered and not
46984698
learned by the <code>ovn-ic</code> daemon.
46994699
</p>
4700+
4701+
<p>
4702+
This option is deprecated and will be removed in the 28.09
4703+
release. Use
4704+
<ref column="options" key="ic-route-learn-tag-rules"/> instead,
4705+
which supports more than one route tag and which, when set, causes
4706+
this option to be ignored.
4707+
</p>
4708+
</column>
4709+
4710+
<column name="options" key="ic-route-learn-tag-rules"
4711+
type='{"type": "string"}'>
4712+
<p>
4713+
This option controls, based on route tags, which routes the
4714+
<code>ovn-ic</code> daemon learns through this Logical Router Port.
4715+
It expects a value in one of the following two forms, where
4716+
<code>tags</code> is a comma-separated list of route-tag names, for
4717+
example <code>allow:vpc1,vpc2</code>:
4718+
</p>
4719+
4720+
<ul>
4721+
<li>
4722+
<code>allow:tags</code> - only routes whose
4723+
<code>ic-route-tag</code> matches one of the listed tags are
4724+
learned. Every other route, including routes that carry no
4725+
<code>ic-route-tag</code> at all, is not learned.
4726+
</li>
4727+
4728+
<li>
4729+
<code>block:tags</code> - routes whose <code>ic-route-tag</code>
4730+
matches one of the listed tags are not learned. Every other
4731+
route, including routes that carry no <code>ic-route-tag</code> at
4732+
all, is learned.
4733+
</li>
4734+
</ul>
4735+
4736+
<p>
4737+
The <code>ic-route-tag</code> of a route is the one present in the
4738+
<code>external_ids</code> register of the advertised route entry in
4739+
the <ref table="Route" db="OVN_IC_Southbound"/> table of the
4740+
<ref db="OVN_IC_Southbound"/> database. As commas separate the
4741+
tags, a route tag cannot contain a comma. Values that use neither
4742+
the <code>allow:</code> nor the <code>block:</code> prefix, as well
4743+
as values with an empty tag list, are invalid and are ignored (no
4744+
route is filtered by this option).
4745+
</p>
4746+
4747+
<p>
4748+
The two forms are mutually exclusive: only the leading prefix is
4749+
honored and everything after it is a route tag name. In
4750+
<code>allow:vpc1,block:vpc2</code>, for example, the allowed tags
4751+
are <code>vpc1</code> and <code>block:vpc2</code>.
4752+
</p>
4753+
4754+
<p>
4755+
This option supersedes the deprecated
4756+
<ref column="options" key="ic-route-filter-tag"/> option: whenever a
4757+
valid value is set here, the route tags to learn are the ones
4758+
defined by this option only and
4759+
<ref column="options" key="ic-route-filter-tag"/> is ignored.
4760+
</p>
47004761
</column>
47014762

47024763
<column name="options" key="requested-chassis">

0 commit comments

Comments
 (0)