LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: "Pali Rohár" <pali@kernel.org>
To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: How to find out name or id of newly created interface
Date: Sat, 31 Jul 2021 22:30:54 +0200	[thread overview]
Message-ID: <20210731203054.72mw3rbgcjuqbf4j@pali> (raw)

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).

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.

             reply	other threads:[~2021-07-31 20:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-31 20:30 Pali Rohár [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210731203054.72mw3rbgcjuqbf4j@pali \
    --to=pali@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --subject='Re: How to find out name or id of newly created interface' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).