Re: How to find out name or id of newly created interface

From: Guillaume Nault
Date: Mon Aug 02 2021 - 09:43:28 EST


On Mon, Aug 02, 2021 at 12:58:25PM +0200, Pali Rohár wrote:
> On Monday 02 August 2021 12:02:38 Guillaume Nault wrote:
> >
> > So the proper solution is to implement NLM_F_ECHO support for
> > RTM_NEWLINK messages (RTM_NEWROUTE is an example of netlink handler
> > that supports NLM_F_ECHO, see rtmsg_fib()).
>
> Do you know if there is some workaround / other solution which can be
> used by userspace applications now? And also with stable kernels (which
> obviously do not receive this new NLM_F_ECHO support for RTM_NEWLINK)?

I unfortunately can't think of any clean solution. It might be possible
to create the new interface with attributes very unlikely to be used by
external programs and retrieve the interface name and id by monitoring
link creation messages (like 'ip monitor' does). But at this point it's
probably easier to just set the interface name and retry with a
different name every time it conflicted with an existing device.

Maybe someone else could propose less hacky solutions, but I really
can't think of anything else apart from implementing NLM_F_ECHO.