veth: fix detection of existing interfaces in create_and_realize()

Merged Beniamino Galvani requested to merge bg/veth-detect-existing into main

The current implementation only checks that a device with name equal to veth.peer exists and it has a parent device; it doesn't check that its parent is actually the device we want to create. So for example, if the profile specifies interface-name A and peer B, while in platform we have a veth pair {B,C}, we'll skip the interface creation and the device will remain without a ifindex, leading to a crash later. Fix this by adding the missing check.

While at it, don't implement the check by inspecting NMDevices but look directly at the platform cache; that seems more robust because devices are often updated from platform events via idle handlers and so the information there could be outdated.

Fixes: 07e0ab48 ('veth: drop iface peer check during create_and_realize()')

Merge request reports