Skip to content

Commit

Permalink
fix(init): use /proc/net/pnp as resolv.conf (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrynhard authored May 18, 2018
1 parent 325ae5c commit 2aed515
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 33 deletions.
33 changes: 4 additions & 29 deletions initramfs/cmd/init/pkg/etc/etc.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"strings"
"text/template"

"github.com/autonomy/dianemo/initramfs/pkg/userdata"
"github.com/autonomy/dianemo/initramfs/pkg/version"
)

Expand All @@ -24,12 +23,6 @@ ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
`

const resolvConfTemplate = `
{{- range $_, $ip := . -}}
nameserver {{ $ip }}
{{- end -}}
`

const osReleaseTemplate = `
NAME="{{ .Name }}"
ID={{ .ID }}
Expand Down Expand Up @@ -67,30 +60,12 @@ func Hosts(s, hostname, ip string) (err error) {
return nil
}

// ResolvConf renders a valid /etc/resolv.conf file and writes it to disk.
func ResolvConf(s string, userdata userdata.UserData) (err error) {
tmpl, err := template.New("").Parse(resolvConfTemplate)
if err != nil {
return
}
var buf []byte
writer := bytes.NewBuffer(buf)
ip, err := DefaultGateway()
if err != nil {
// ResolvConf symlinks /proc/net/pnp to /etc/resolv.conf. See
// https://www.kernel.org/doc/Documentation/filesystems/nfs/nfsroot.txt.
func ResolvConf(s string) (err error) {
if err = os.Symlink("/proc/net/pnp", path.Join(s, "/etc/resolv.conf")); 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
}
Expand Down
2 changes: 1 addition & 1 deletion initramfs/cmd/init/pkg/rootfs/rootfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func Prepare(s string, userdata userdata.UserData) (err error) {
return
}
// Create /etc/resolv.conf.
if err = etc.ResolvConf(s, userdata); err != nil {
if err = etc.ResolvConf(s); err != nil {
return
}
// Create /etc/os-release.
Expand Down
4 changes: 1 addition & 3 deletions initramfs/pkg/userdata/userdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ type OS struct {

// Network represents the operating system networking specific configuration
// options.
type Network struct {
Nameservers []string `yaml:"nameservers,omitempty"`
}
type Network struct{}

// Security represents the operating system security specific configuration
// options.
Expand Down

0 comments on commit 2aed515

Please sign in to comment.