ENGINEERING NOTE / LINUX NETWORKING

Debugging Linux policy routing

A route can exist without being selected for the flow you are debugging. Start with a kernel lookup for that flow, then inspect the rules and routing tables around the result.

ROUTE LOOKUP

Start with the flow.

ip route get asks the running kernel to resolve a route. Run it in the affected network namespace and supply the selectors that matter: source address, packet mark, interfaces, TOS, VRF, protocol or ports. A destination-only lookup can answer a different question from the one the application’s traffic poses.

These commands use illustrative addresses. Replace them with the actual destination, source and mark from the flow you are investigating.

ip -4 route get 192.0.2.20
ip -4 route get 192.0.2.20 from 192.0.2.10 mark 0x42
ip -4 route get fibmatch 192.0.2.20 from 192.0.2.10 mark 0x42

The normal lookup returns the resolved route; fibmatch returns the matching FIB route, which helps identify the selected prefix. The commands send no test packet. Their options and semantics are defined in the iproute2 route manual.

RULES AND TABLES

Read the rules before comparing prefixes.

ip -4 rule show
ip -4 route show table all

The routing policy database (RPDB) processes rules in priority order; lower numbers come first. A rule can direct a lookup to a particular table. Only then do the routes in that table become relevant. A more specific route in table 52 cannot override a default route in main merely by existing in another table.

A matching rule selector also does not guarantee that the rule supplied the final route. Its table may have no usable result, a throw route may end that table lookup, or a suppressor may reject the result. Processing can then continue. The rule manual describes these actions and selectors.

This is where a route dump helps: it provides context for the kernel’s answer. Reconstructing the entire decision from the dump would require reproducing the kernel’s routing behaviour, including every relevant selector and exception.

PACKET MARKS

Check how the mark was obtained.

A lookup with mark 0x42 establishes the result for that supplied mark. It does not establish that a real packet carried it. To explain a marked flow, keep the source of the mark alongside the routing result.

Existing nftables trace events can provide an observed mark or input interface. A second lookup using those values can show whether they change the selected route. In route-explain, trace --correlate performs that comparison when matching trace events are available; it does not install tracing rules.

The second lookup describes the kernel’s answer when the probe runs. It does not prove that the original packet was rerouted at the nftables hook where the selector was observed. Establishing that requires further packet-path evidence. The trace documentation sets out the supported observations and limitations.

DIAGNOSTIC OUTPUT

Keep the lookup result with its inputs.

A useful report records the destination and selectors, the namespace, the kernel-selected route and the time of collection. Matching rule selectors and alternative routes belong alongside that result, with their role made clear.

route-explain labels direct lookup results KERNEL, derived context INFO, and unresolved questions CHECK. If a required selector was not supplied, the report should say which information is missing. This keeps an operator from mistaking a plausible explanation for a recorded routing decision.