linux: opt out of naming your tun device yourself - #1487
Conversation
jasikpark
left a comment
There was a problem hiding this comment.
looks reasonable to me
| } | ||
| if good { | ||
| if len(candidateName) > 16 { | ||
| return "", errors.New("you have too many nebula networks") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
e1e8fb8 to
36daea9
Compare
3583a3f to
6020e46
Compare
| # 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. |
There was a problem hiding this comment.
nit: you're already in For Linux:
| // IFNAMSIZ is already taken. | ||
| func nextTunName(tunName string, used map[string]struct{}) (string, error) { | ||
| tunNameTemplate := tunName[:len(tunName)-len("%d")] | ||
| for i := 0; ; i++ { |
| // 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) { |
There was a problem hiding this comment.
This scan method is susceptible to TOCTOU issues, but I don't expect them to occur in practice.
6020e46 to
57e1a9b
Compare

This allows you to end your
tun.devname setting with%dto 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.