Skip to content

net/dns: set WSL resolv.conf - #2252

Merged
crawshaw merged 2 commits into
mainfrom
crawshaw/dns
Jun 28, 2021
Merged

crawshaw merged 2 commits into
mainfrom
crawshaw/dns

Conversation

@crawshaw

@crawshaw crawshaw commented Jun 25, 2021 •

Copy link
Copy Markdown
Contributor

Tested on WSL2, should also work on WSL1.

Fixes #775

@crawshaw
crawshaw requested a review from danderson June 25, 2021 18:20
@crawshaw
crawshaw force-pushed the crawshaw/dns branch 4 times, most recently from ff6ee7d to 4d1ae05 Compare June 26, 2021 14:47
@crawshaw crawshaw changed the title net/dns: factor directManager out over an FS interface net/dns: set WSL resolv.conf Jun 26, 2021
@crawshaw
crawshaw requested a review from sailorfrag June 26, 2021 14:48
Comment thread net/dns/ini.go Resolved
Comment thread net/dns/manager_windows.go Resolved
Comment thread net/dns/direct.go Outdated
return fs.Rename(tmpName, filename)
}

// pinholeFS is a high-level file system abstraction designed just for use

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't get the name. What's pinhole?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I couldn't think of a name for this. It's an FS, but not a standard open/read/write/close Unix API. It felt like looking through a pinhole. Any better names?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

minimalFS?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Took another attempt at the name, wholeFileFS, as you can only work with whole files.

@bradfitz bradfitz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you clarify in the commit message whether this is WSL1, WSL2, or both?

Comment thread net/dns/direct.go Resolved
Comment thread net/dns/wsl_windows.go Resolved
Comment thread net/dns/direct.go Outdated
return fs.Rename(tmpName, filename)
}

// pinholeFS is a high-level file system abstraction designed just for use

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

minimalFS?

Comment thread net/dns/direct.go Resolved
Comment thread net/dns/ini_test.go Resolved
Comment thread net/dns/ini.go Resolved
Comment thread net/dns/ini.go Resolved
Comment thread net/dns/wsl_windows.go
}

const wslConf = "/etc/wsl.conf"
const wslConfSection = `# added by tailscale

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hmm, it would probably be good to delete this on uninstall, although that might be tricky if it's edited after; deleting the generateResolvConf line while leaving the section name is probably required

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It would, but it's very problematic. To touch this file, you need to call wsl.exe --shutdown and restart it. On my brand-new machine, that's a multiple second operation that could be disruptive. I'd like to do it zero times.

Open to ideas here, but doing this regularly doesn't seem like a great move.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If tagged with a special comment, maybe the generateResolvConf line could be deleted by the NSIS uninstaller? That should be sufficiently infrequent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That would be infrequent enough for me, though it's a bit of work to make that happen. Would you be fine if I file a bug and do that later?

I suspect it isn't super important because it appears the nature of the generated resolv.conf has shifted over time at MS. The resolv.conf they generate points at a stub resolver on a fixed IP. Nothing I do to my computer's DNS settings change its contents. So I suspect the current behavior of this commit, restoring the backup file, will be adequate.

(That said, we should try and restore the backup on uninstall too.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That sounds like a plan

Comment thread net/dns/wsl_windows.go Resolved
crawshaw added 2 commits June 28, 2021 13:45
This is preliminary work for using the directManager as
part of a wslManager on windows, where in addition to configuring
windows we'll use wsl.exe to edit the linux file system and modify the
system resolv.conf.

The pinholeFS is a little funky, but it's designed to work through
simple unix tools via wsl.exe without invoking bash. I would not have
thought it would stand on its own like this, but it turns out it's
useful for writing a test for the directManager.

Signed-off-by: David Crawshaw <[email protected]>
We also have to make a one-off change to /etc/wsl.conf to stop every
invocation of wsl.exe clobbering the /etc/resolv.conf. This appears to
be a safe change to make permanently, as even though the resolv.conf is
constantly clobbered, it is always the same stable internal IP that is
set as a nameserver. (I believe the resolv.conf clobbering predates the
MS stub resolver.)

Tested on WSL2, should work for WSL1 too.

Fixes #775

Signed-off-by: David Crawshaw <[email protected]>
@crawshaw

Copy link
Copy Markdown
Contributor Author

PTAL

@crawshaw
crawshaw merged commit 1147c7f into main Jun 28, 2021
@crawshaw
crawshaw deleted the crawshaw/dns branch June 28, 2021 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MagicDNS domains don't get registered as expected in WSL /etc/resolv.conf

3 participants