Skip to content

Commit

Permalink
Adjust Linux+FreeBSD DCO device name handling to 'non DCO linux style'
Browse files Browse the repository at this point in the history
On Linux, tun devices are created according to the following algorithm
  --dev tun    -> try tun0, tun1, ... tun255, use first free
  --dev anything -> create a TUN device named "anything"
(as long as "anything" is not "null" or "tap[N]")

DCO was following the "other platform convention", where everything
not having a digit was iterated ("--dev tun-home" -> "tun-home0") -
which does not work for classic tun/tap devices on the BSDs anyway,
so is not the best model.

Adjust open_tun_dco_generic() to document expected behaviour and
do the thing.

Signed-off-by: Gert Doering <[email protected]>
Acked-by: Kristof Provost <[email protected]>
Acked-by: Antonio Quartulli <[email protected]>
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg25134.html
Signed-off-by: Gert Doering <[email protected]>
  • Loading branch information
cron2 committed Aug 30, 2022
1 parent 26d6192 commit a5cf4cf
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/openvpn/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -1943,12 +1943,14 @@ open_tun_dco_generic(const char *dev, const char *dev_type,
}

/*
* dynamic open is indicated by --dev specified without
* explicit unit number. Try opening DCO device named "[dev]n"
* where n = [0, 255].
* unlike "open_tun_generic()", DCO on Linux and FreeBSD follows
* the device naming model of "non-DCO linux", that is:
* --dev tun -> try tun0, tun1, ... tun255, use first free
* --dev <anything> -> (try to) create a tun device named "anything"
* ("--dev tap" and "--dev null" are caught earlier and not handled here)
*/

if (!tun_name_is_fixed(dev))
if (strcmp(dev, "tun") == 0)
{
for (int i = 0; i < 256; ++i)
{
Expand Down

0 comments on commit a5cf4cf

Please sign in to comment.