Skip to content

linux: opt out of naming your tun device yourself - #1487

Open
JackDoan wants to merge 1 commit into
masterfrom
tun-name-template
Open

linux: opt out of naming your tun device yourself#1487
JackDoan wants to merge 1 commit into
masterfrom
tun-name-template

Conversation

@JackDoan

@JackDoan JackDoan commented Oct 2, 2025

Copy link
Copy Markdown
Collaborator

This allows you to end your tun.dev name setting with %d to tell Nebula "please find the lowest-numbered interface that matches this pattern and use it"

I'm honestly not sure what would be needed to bring this to other platforms. I think Mac OS mostly doesn't care. Windows seems like it will need different handling as well, but won't break with this change.

@jasikpark jasikpark left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks reasonable to me

Comment thread overlay/tun_linux.go Outdated
}
if good {
if len(candidateName) > 16 {
return "", errors.New("you have too many nebula networks")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to be a little bit more clear about exactly what's going on here in order to make this error actionable. It's actually OK to have this many nebula networks, but we can't fit the tun name.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also be a pre-flight check and should be included the example config comments/docs. Can't compute a name shorter than unix.IFNAMSIZ if the tunNameTemplate is longer than it to begin with.

@nbrownus nbrownus added this to the v1.10.0 milestone Nov 12, 2025
@JackDoan JackDoan modified the milestones: v1.10.0, backlog Nov 13, 2025
@JackDoan
JackDoan marked this pull request as draft November 13, 2025 17:13
@JackDoan
JackDoan force-pushed the tun-name-template branch from 3583a3f to 6020e46 Compare July 8, 2026 17:32
@JackDoan
JackDoan marked this pull request as ready for review July 8, 2026 17:33
johnmaguire
johnmaguire previously approved these changes Jul 8, 2026

@johnmaguire johnmaguire left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread examples/config.yml
# Name of the device. If not set, a default will be chosen by the OS.
# For Linux: a trailing `%d` is treated as a template and replaced with the
# lowest number that yields an unused device name (e.g. `nebula%d` becomes `nebula0`, then `nebula1`, and so on).
# Only on Linux: `nebula%d` is the default if tun.dev is unset.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you're already in For Linux:

Comment thread overlay/tun_linux.go
// IFNAMSIZ is already taken.
func nextTunName(tunName string, used map[string]struct{}) (string, error) {
tunNameTemplate := tunName[:len(tunName)-len("%d")]
for i := 0; ; i++ {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this loop looks scary with a device name like a%d but the number of links registered should not be anywhere close to the theoretical limit (10^14)

Image

Comment thread overlay/tun_linux.go
// skipping any name present in used. tunName is assumed to have already passed
// validateTunName. It errors only if every candidate that is shorter than
// IFNAMSIZ is already taken.
func nextTunName(tunName string, used map[string]struct{}) (string, error) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This scan method is susceptible to TOCTOU issues, but I don't expect them to occur in practice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants