Skip to content

Unhandled FileNotFoundError when /etc/iproute2/rt_tables does not exist in add_route_table() #163

@ddung1203

Description

@ddung1203

Describe the bug

In modern Linux distributions, the /etc/iproute2/rt_tables file may not exist by default (it has been moved or isn't created automatically).
When a secondary VNIC is attached, oci-utils (specifically ocid) attempts to configure policy-based routing but crashes abruptly without handling the exception.

Root Cause

In lib/oci_utils/network/... (or wherever add_route_table is defined), the code opens the file without a try-except block:

    with open(_ROUTE_TABLES) as f:
        for line in f.readlines():

If _ROUTE_TABLES (/etc/iproute2/rt_tables) does not exist, a FileNotFoundError is raised, causing the daemon to abort the routing configuration silently.

Additionally (Leaking stale route tables)
Also, when a VNIC is detached, oci-utils does not clean up the previously added ortX entries from rt_tables. When re-attached, it keeps incrementing the table number (ort4, ort5, etc.) by appending to the end of the file.

Expected behavior
The script should catch FileNotFoundError and either create the file gracefully or fall back to /usr/share/iproute2/rt_tables.

Clean up old ort entries when a VNIC is detached.

Workaround
Manually creating the file sudo touch /etc/iproute2/rt_tables with default values (local, main, default) resolves the issue, and ocid successfully completes the configuration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions