Skip to content

Commit 27cc274

Browse files
committed
northd: Use lower priority for all src routes.
The current implementation prefers dst routes over src routes only if they have the same prefix length. This is not very useful for real world use cases, because it doesn't make much sense to compare the prefix length between different fields of the IP header (dst IP v.s. src IP). The prefix length should make sense only when comparing for the same field, either dst or src. This patch changes the behavior by always prefering dst routes over src routes, regardless of the prefix length, and comparing prefix length only within the same type of routes. E.g., there are two routes: 10.0.0.0/8 nexthop A dst-ip 192.168.11.0/24 nexthop B src-ip For a packet 192.168.11.123 -> 10.1.2.3: Before: nexthop will be B After: nexthop will be A Reported-by: Girish Moodalbail <gmoodalbail@gmail.com> Reported-at: https://mail.openvswitch.org/pipermail/ovs-discuss/2020-May/050049.html Signed-off-by: Han Zhou <hzhou@ovn.org> Acked-by: Dumitru Ceara <dceara@redhat.com>
1 parent 93fc05d commit 27cc274

4 files changed

Lines changed: 129 additions & 122 deletions

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Post v25.03.0
3636
- Added a new ACL option "--all" to "acl-list" command. When set,
3737
"acl-list" command will also list port groups ACLs associated with
3838
each port of the target logical switch.
39+
- Adjusted priorities of src-ip based static routes to be lower than other
40+
types of routes regardless of prefix length.
3941

4042
OVN v25.03.0 - 07 Mar 2025
4143
--------------------------

northd/northd.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,12 @@ static const char *reg_ct_state[] = {
339339
* 1. (highest priority) connected routes
340340
* 2. static routes
341341
* 3. routes learned from the outside via ovn-controller (e.g. bgp)
342-
* 4. (lowest priority) src-ip routes */
343-
#define ROUTE_PRIO_OFFSET_MULTIPLIER 8
344-
#define ROUTE_PRIO_OFFSET_LEARNED 2
345-
#define ROUTE_PRIO_OFFSET_STATIC 4
346-
#define ROUTE_PRIO_OFFSET_CONNECTED 6
342+
* (src-ip routes have lower priority than all other routes regardless of
343+
* prefix length, so not included here.) */
344+
#define ROUTE_PRIO_OFFSET_MULTIPLIER 6
345+
#define ROUTE_PRIO_OFFSET_LEARNED 0
346+
#define ROUTE_PRIO_OFFSET_STATIC 2
347+
#define ROUTE_PRIO_OFFSET_CONNECTED 4
347348

348349
/* Returns the type of the datapath to which a flow with the given 'stage' may
349350
* be added. */
@@ -11832,6 +11833,7 @@ build_route_match(const struct ovn_port *op_inport, uint32_t rtb_id,
1183211833
{
1183311834
const char *dir;
1183411835
int ofs = route_source_to_offset(source);
11836+
int base = 0;
1183511837

1183611838
/* The priority here is calculated to implement longest-prefix-match
1183711839
* routing. */
@@ -11840,6 +11842,9 @@ build_route_match(const struct ovn_port *op_inport, uint32_t rtb_id,
1184011842
ofs = 0;
1184111843
} else {
1184211844
dir = "dst";
11845+
/* dst routes have higher priority than all src routes regardless of
11846+
* prefix length. */
11847+
base = (128 + 1) * ROUTE_PRIO_OFFSET_MULTIPLIER;
1184311848
}
1184411849

1184511850
if (op_inport) {
@@ -11853,7 +11858,7 @@ build_route_match(const struct ovn_port *op_inport, uint32_t rtb_id,
1185311858
if (has_protocol_match) {
1185411859
ofs += 1;
1185511860
}
11856-
*priority = (plen * ROUTE_PRIO_OFFSET_MULTIPLIER) + ofs;
11861+
*priority = base + (plen * ROUTE_PRIO_OFFSET_MULTIPLIER) + ofs;
1185711862

1185811863
ds_put_format(match, "ip%s.%s == %s/%d", is_ipv4 ? "4" : "6", dir,
1185911864
network_s, plen);

ovn-nb.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4325,9 +4325,9 @@ or
43254325
</p>
43264326

43274327
<p>
4328-
When multiple routes match a packet, the longest-prefix match is chosen.
4329-
For a given prefix length, a <code>dst-ip</code> route is preferred over
4330-
a <code>src-ip</code> route.
4328+
When multiple routes match a packet, a <code>dst-ip</code> route is
4329+
preferred over a <code>src-ip</code> route. Among the same type of
4330+
routes, the longest-prefix match is chosen.
43314331
</p>
43324332

43334333
<p>

0 commit comments

Comments
 (0)