Netdev Archive on
help / color / mirror / Atom feed
* How to find out name or id of newly created interface
@ 2021-07-31 20:30 Pali Rohár
  2021-08-01 14:31 ` Andrew Lunn
  2021-08-02 10:02 ` Guillaume Nault
  0 siblings, 2 replies; 9+ messages in thread
From: Pali Rohár @ 2021-07-31 20:30 UTC (permalink / raw)
  To: netdev, linux-kernel


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

And now I would like to know, how to race-free find out interface name
(or id) of this newly created interface?

Response to RTM_NEWLINK/NLM_F_CREATE packet from kernel contains only
buffer with struct nlmsgerr where is just error number (zero for
success) without any additional information.

I can send another rtnetlink packet to request list of all existing
network interfaces and expect that the interface with the highest id was
that one which was created. But it is racy as another process may
meanwhile create another network interface or it may delete this my
newly created one, prior I send this followup packet.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-08-02 17:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-31 20:30 How to find out name or id of newly created interface Pali Rohár
2021-08-01 14:31 ` Andrew Lunn
2021-08-01 14:38   ` Pali Rohár
2021-08-02 14:21     ` Andrew Lunn
2021-08-02 17:25       ` Pali Rohár
2021-08-02 10:02 ` Guillaume Nault
2021-08-02 10:58   ` Pali Rohár
2021-08-02 13:43     ` Guillaume Nault
2021-08-02 17:23       ` Pali Rohár

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).