Skip to content

Commit

Permalink
dns forwarding
Browse files Browse the repository at this point in the history
  • Loading branch information
panumjp committed Jan 22, 2022
1 parent 41c9f66 commit 885f47e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions plugins/meta/dnsname/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const dnsMasqTemplate = `## WARNING: THIS IS AN AUTOGENERATED FILE
## LIKELY TO AUTOMATICALLY BE REPLACED.
strict-order
local=/{{.Domain}}/
{{- range $domain, $server := .Servers}}
server=/{{ $domain }}/{{ $server }}
{{- end }}
domain={{.Domain}}
expand-hosts
pid-file={{.PidFile}}
Expand All @@ -45,6 +48,7 @@ type DNSNameConf struct {
RuntimeConfig struct { // The capability arg
Aliases map[string][]string `json:"aliases"`
} `json:"runtimeConfig,omitempty"`
Servers map[string]string `json:"servers,omitempty"`
}

// dnsNameFile describes the plugin's attributes
Expand All @@ -55,6 +59,7 @@ type dnsNameFile struct {
Domain string
NetworkInterface string
PidFile string
Servers map[string]string
}

// dnsNameConfPath tells where we store the conf, pid, and hosts files
Expand Down
4 changes: 2 additions & 2 deletions plugins/meta/dnsname/dnsname_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ var _ = Describe("dnsname tests", func() {
}
Expect(reflect.DeepEqual(expectedFileNames, resultingFileNames)).To(BeTrue())

d, err := newDNSMasqFile("foobar.io", "dummy0", "test")
d, err := newDNSMasqFile("foobar.io", "dummy0", "test", map[string]string{})
Expect(err).To(BeNil())

// Check that the dns masq instance is running
Expand Down Expand Up @@ -166,7 +166,7 @@ var _ = Describe("dnsname tests", func() {
_, err = current.GetResult(r)
Expect(err).NotTo(HaveOccurred())

d, err := newDNSMasqFile("foobar.io", "dummy0", "test")
d, err := newDNSMasqFile("foobar.io", "dummy0", "test", map[string]string{})
Expect(err).To(BeNil())

pid, err := d.getProcess()
Expand Down
6 changes: 3 additions & 3 deletions plugins/meta/dnsname/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func cmdAdd(args *skel.CmdArgs) error {
if err != nil {
return err
}
dnsNameConf, err := newDNSMasqFile(netConf.DomainName, result.Interfaces[0].Name, netConf.Name)
dnsNameConf, err := newDNSMasqFile(netConf.DomainName, result.Interfaces[0].Name, netConf.Name, netConf.Servers)
if err != nil {
return err
}
Expand Down Expand Up @@ -118,7 +118,7 @@ func cmdDel(args *skel.CmdArgs) error {
} else if result == nil {
return nil
}
dnsNameConf, err := newDNSMasqFile(netConf.DomainName, result.Interfaces[0].Name, netConf.Name)
dnsNameConf, err := newDNSMasqFile(netConf.DomainName, result.Interfaces[0].Name, netConf.Name, netConf.Servers)
if err != nil {
logrus.Error(err)
return nil
Expand Down Expand Up @@ -187,7 +187,7 @@ func cmdCheck(args *skel.CmdArgs) error {
if result == nil {
return errors.Errorf("Required prevResult missing")
}
dnsNameConf, err := newDNSMasqFile(netConf.DomainName, result.Interfaces[0].Name, netConf.Name)
dnsNameConf, err := newDNSMasqFile(netConf.DomainName, result.Interfaces[0].Name, netConf.Name, netConf.Servers)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/meta/dnsname/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

// newDNSMasqFile creates a new instance of a dnsNameFile
func newDNSMasqFile(domainName, networkInterface, networkName string) (dnsNameFile, error) {
func newDNSMasqFile(domainName, networkInterface, networkName string, servers map[string]string) (dnsNameFile, error) {
dnsMasqBinary, err := exec.LookPath("dnsmasq")
if err != nil {
return dnsNameFile{}, errors.Errorf("the dnsmasq cni plugin requires the dnsmasq binary be in PATH")
Expand All @@ -27,6 +27,7 @@ func newDNSMasqFile(domainName, networkInterface, networkName string) (dnsNameFi
NetworkInterface: networkInterface,
AddOnHostsFile: makePath(networkName, hostsFileName),
Binary: dnsMasqBinary,
Servers: servers,
}
return masqConf, nil
}
Expand Down

0 comments on commit 885f47e

Please sign in to comment.