Skip to content

Commit

Permalink
northd: fix infinite loop in ovn_allocate_tnlid()
Browse files Browse the repository at this point in the history
In case if all tunnel ids are exhausted, ovn_allocate_tnlid() function
iterates over tnlids indefinitely when *hint < min.  This is because
when tnlid reaches max, next tnlid is min and for-loop never reaches exit
condition for tnlid != *hint.

This patch sets a starting hint value to OVN_MIN_DP_KEY_LOCAL (1).

The downside of this change is that first allocated tnlid becomes 2.
This shouldn't be a problem.

Signed-off-by: Vladislav Odintsov <odivlad@gmail.com>
  • Loading branch information
odivlad committed Mar 29, 2024
1 parent 8bad19c commit 82254c3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/ovn-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,11 +689,17 @@ next_tnlid(uint32_t tnlid, uint32_t min, uint32_t max)
return tnlid + 1 <= max ? tnlid + 1 : min;
}

static uint32_t
prev_tnlid(uint32_t tnlid, uint32_t min, uint32_t max)
{
return tnlid - 1 <= min ? tnlid - 1 : max;
}

uint32_t
ovn_allocate_tnlid(struct hmap *set, const char *name, uint32_t min,
uint32_t max, uint32_t *hint)
{
for (uint32_t tnlid = next_tnlid(*hint, min, max); tnlid != *hint;
for (uint32_t tnlid = *hint; tnlid != prev_tnlid(*hint, min, max);
tnlid = next_tnlid(tnlid, min, max)) {
if (ovn_add_tnlid(set, tnlid)) {
*hint = tnlid;
Expand Down
2 changes: 1 addition & 1 deletion northd/northd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ build_datapaths(struct ovsdb_idl_txn *ovnsb_txn,
}

/* Assign new tunnel ids where needed. */
uint32_t hint = 0;
uint32_t hint = OVN_MIN_DP_KEY_LOCAL;
LIST_FOR_EACH_SAFE (od, list, &both) {
ovn_datapath_allocate_key(sbrec_chassis_table,
datapaths, &dp_tnlids, od, &hint);
Expand Down
26 changes: 26 additions & 0 deletions tests/ovn-northd.at
Original file line number Diff line number Diff line change
Expand Up @@ -2822,6 +2822,32 @@ AT_CHECK([test $lsp02 = 3 && test $ls1 = 123])
AT_CLEANUP
])

OVN_FOR_EACH_NORTHD_NO_HV([
AT_SETUP([check tunnel ids exhaustion])
ovn_start

# Create a fake chassis with vxlan encap to lower MAX DP tunnel key to 2^12
ovn-sbctl \
--id=@e create encap chassis_name=hv1 ip="192.168.0.1" type="vxlan" \
-- --id=@c create chassis name=hv1 encaps=@e

cmd="ovn-nbctl --wait=sb"

for i in {1..4097..1}; do
cmd="${cmd} -- ls-add lsw-${i}"
done

eval $cmd

check_row_count nb:Logical_Switch 4097
wait_row_count sb:Datapath_Binding 4095

OVS_WAIT_UNTIL([grep "all datapath tunnel ids exhausted" northd/ovn-northd.log])

AT_CLEANUP
])


OVN_FOR_EACH_NORTHD_NO_HV([
AT_SETUP([Logical Flow Datapath Groups])
ovn_start
Expand Down

0 comments on commit 82254c3

Please sign in to comment.