fix(init): use /proc/net/pnp as resolv.conf (#87)

This commit is contained in:
Andrew Rynhard 2018-05-17 22:56:37 -07:00 committed by GitHub
parent 325ae5cbf7
commit 2aed5157fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 33 deletions

View File

@ -11,7 +11,6 @@ import (
"strings" "strings"
"text/template" "text/template"
"github.com/autonomy/dianemo/initramfs/pkg/userdata"
"github.com/autonomy/dianemo/initramfs/pkg/version" "github.com/autonomy/dianemo/initramfs/pkg/version"
) )
@ -24,12 +23,6 @@ ff02::1 ip6-allnodes
ff02::2 ip6-allrouters ff02::2 ip6-allrouters
` `
const resolvConfTemplate = `
{{- range $_, $ip := . -}}
nameserver {{ $ip }}
{{- end -}}
`
const osReleaseTemplate = ` const osReleaseTemplate = `
NAME="{{ .Name }}" NAME="{{ .Name }}"
ID={{ .ID }} ID={{ .ID }}
@ -67,30 +60,12 @@ func Hosts(s, hostname, ip string) (err error) {
return nil return nil
} }
// ResolvConf renders a valid /etc/resolv.conf file and writes it to disk. // ResolvConf symlinks /proc/net/pnp to /etc/resolv.conf. See
func ResolvConf(s string, userdata userdata.UserData) (err error) { // https://www.kernel.org/doc/Documentation/filesystems/nfs/nfsroot.txt.
tmpl, err := template.New("").Parse(resolvConfTemplate) func ResolvConf(s string) (err error) {
if err != nil { if err = os.Symlink("/proc/net/pnp", path.Join(s, "/etc/resolv.conf")); err != nil {
return return
} }
var buf []byte
writer := bytes.NewBuffer(buf)
ip, err := DefaultGateway()
if err != nil {
return
}
nameservers := []string{ip}
if userdata.OS.Network != nil {
nameservers = append(nameservers, userdata.OS.Network.Nameservers...)
}
err = tmpl.Execute(writer, nameservers)
if err != nil {
return
}
if err := ioutil.WriteFile(path.Join(s, "/etc/resolv.conf"), writer.Bytes(), 0644); err != nil {
return fmt.Errorf("write /etc/resolv.conf: %v", err)
}
return nil return nil
} }

View File

@ -40,7 +40,7 @@ func Prepare(s string, userdata userdata.UserData) (err error) {
return return
} }
// Create /etc/resolv.conf. // Create /etc/resolv.conf.
if err = etc.ResolvConf(s, userdata); err != nil { if err = etc.ResolvConf(s); err != nil {
return return
} }
// Create /etc/os-release. // Create /etc/os-release.

View File

@ -57,9 +57,7 @@ type OS struct {
// Network represents the operating system networking specific configuration // Network represents the operating system networking specific configuration
// options. // options.
type Network struct { type Network struct{}
Nameservers []string `yaml:"nameservers,omitempty"`
}
// Security represents the operating system security specific configuration // Security represents the operating system security specific configuration
// options. // options.