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

From: Pali Rohár
Date: Sun Aug 01 2021 - 10:39:59 EST


On Sunday 01 August 2021 16:31:33 Andrew Lunn wrote:
> On Sat, Jul 31, 2021 at 10:30:54PM +0200, Pali Rohár wrote:
> > Hello!
> >
> > Via rtnetlink API (RTM_NEWLINK/NLM_F_CREATE) it is possible to create a
> > new network interface without specifying neither interface name nor id.
> > This will let kernel to choose some interface name which does not
> > conflicts with any already existing network interface. So seems like
> > ideal way if I do not care about interface names. But at some stage it
> > is needed to "configure" interface and for this action it is required to
> > know interface id or name (as some ioctls use interface name instead of
> > id).
>
> Hi Pali
>
> Looking at __rtnl_newlink() it looks like you can specify the
> dev->ifindex when you request the create. So you can leave the kernel
> to pick the name, but pick the if_index from user space.
>
> Andrew

Hello! This has additional issue that I have to choose some free ifindex
number and it introduce another race condition that other userspace
process may choose same ifindex number. So create request in this case
fails if other userspace process is faster... So it has same race
condition as specifying interface name.