From 166705fc60c23db84ae3c38b218f97e45cd1c9fa Mon Sep 17 00:00:00 2001 From: George Date: Sun, 31 Oct 2021 18:37:11 +0000 Subject: [PATCH] Remove DNS records storage, use dnsmasq or PopuraDNS instead --- USAGE.md | 51 ++++++++------------------ cmd/meshnamed/main.go | 35 ++---------------- contrib/gentoo/meshnamed-0.1.0.ebuild | 3 -- contrib/meshnamed.initd | 2 +- meshnamed.service | 2 +- pkg/meshname/config.go | 52 --------------------------- pkg/meshname/server.go | 20 +---------- 7 files changed, 21 insertions(+), 144 deletions(-) delete mode 100644 pkg/meshname/config.go diff --git a/USAGE.md b/USAGE.md index 0105055..3c3b236 100644 --- a/USAGE.md +++ b/USAGE.md @@ -8,46 +8,33 @@ git clone https://github.com/zhoreeq/meshname.git cd meshname make ``` -2) Generate the default config for your host +2) Run the daemon ``` -./meshnamed -genconf 200:6fc8:9220:f400:5cc2:305a:4ac6:967e -subdomain meshname | tee /tmp/meshnamed.conf +./meshnamed ``` -3) Run the daemon +3) Optionally, set configuration flags ``` -./meshnamed -useconffile /tmp/meshnamed.conf +./meshnamed -listenaddr [::1]:53535 -debug ``` -4) Optionally, set configuration flags -``` -./meshnamed -listenaddr [::1]:53535 -debug -useconffile /tmp/meshnamed.conf -``` -5) See the list of all configuration flags +4) See the list of all available flags ``` ./meshnamed -help ``` -Add custom DNS records to the configuration file and restart the daemon to apply settings. -A DNS record can be of any valid string form parsed by [miekg/dns#NewRR](https://godoc.org/github.com/miekg/dns#NewRR) function (see example configuration file below). + +## Get meshname subdomain from an IPv6 address + +``` +./meshnamed -getname 200:f8b1:f974:967f:dd32:145d:1cc0:3679 +aiaprmpzoslh7xjscrorzqbwpe +``` + +Use this subdomain with a .meshname TLD to configure DNS records +on your authoritative server, (i.e. dnsmasq, bind or PopuraDNS). ## systemd unit Look for `meshnamed.service` in the source directory for a systemd unit file. -## Example configuration file - -In this example, meshnamed is configured as authoritative server for two domain zones: - - { - "aiag7sesed2aaxgcgbnevruwpy": [ - "aiag7sesed2aaxgcgbnevruwpy.meshname. AAAA 200:6fc8:9220:f400:5cc2:305a:4ac6:967e", - "_xmpp-client._tcp.aiag7sesed2aaxgcgbnevruwpy.meshname. SRV 5 0 5222 xmpp.aiag7sesed2aaxgcgbnevruwpy.meshname", - "_xmpp-server._tcp.aiag7sesed2aaxgcgbnevruwpy.meshname. SRV 5 0 5269 xmpp.aiag7sesed2aaxgcgbnevruwpy.meshname", - "xmpp.aiag7sesed2aaxgcgbnevruwpy.meshname. AAAA 300:6fc8:9220:f400::1", - "forum.aiag7sesed2aaxgcgbnevruwpy.meshname. CNAME amag7sesed2aaaaaaaaaaaaaau.meshname." - ], - "amag7sesed2aaaaaaaaaaaaaau": [ - "amag7sesed2aaaaaaaaaaaaaau.meshname. AAAA 300:6fc8:9220:f400::5" - ] - } - ## Configure dnsmasq as a primary DNS resolver with "meshname." support `/etc/dnsmasq.conf` @@ -58,14 +45,6 @@ In this example, meshnamed is configured as authoritative server for two domain server=/meshname/::1#53535 server=8.8.8.8 -## Using meshnamed as a standalone DNS server - -Set the flag to listen on all interfaces and a standard DNS server port - - ./meshnamed -listenaddr [::]:53 -useconffile /tmp/meshnamed.conf - -Run as root and allow incoming connections to port 53/UDP in firewall settings. - ## Custom top level domains (TLD) and subnet filtering meshnamed can be configured to resolve custom TLDs. diff --git a/cmd/meshnamed/main.go b/cmd/meshnamed/main.go index e0067f2..1aaaf3d 100644 --- a/cmd/meshnamed/main.go +++ b/cmd/meshnamed/main.go @@ -28,24 +28,13 @@ func parseNetworks(networksconf string) (map[string]*net.IPNet, error) { return networks, nil } -func loadConfig(s *meshname.MeshnameServer, confPath string) error { - dnsRecords, err := meshname.ParseConfigFile(confPath) - if err == nil { - s.ConfigureDNSRecords(dnsRecords) - } - return err -} - var ( - genconf, subdomain, useconffile, listenAddr, networksconf string - getName, getIP string - debug, noMeshIP, allowRemote bool + listenAddr, networksconf string + getName, getIP string + debug, noMeshIP, allowRemote bool ) func init() { - flag.StringVar(&genconf, "genconf", "", "generate a new config for IP address") - flag.StringVar(&subdomain, "subdomain", "meshname.", "subdomain used to generate config") - flag.StringVar(&useconffile, "useconffile", "", "run daemon with a config file") flag.StringVar(&listenAddr, "listenaddr", "[::1]:53535", "address to listen on") flag.StringVar(&networksconf, "networks", "ygg=200::/7,cjd=fc00::/8,meshname=::/0,popura=::/0", "TLD=subnet list separated by comma") flag.BoolVar(&noMeshIP, "nomeship", false, "disable .meship resolver") @@ -82,13 +71,6 @@ func main() { } fmt.Println(ip) return - } else if genconf != "" { - if conf, err := meshname.GenConf(genconf, subdomain); err == nil { - fmt.Println(conf) - } else { - logger.Errorln(err) - } - return } networks, err := parseNetworks(networksconf) @@ -97,11 +79,6 @@ func main() { } s := meshname.New(logger, listenAddr, networks, !noMeshIP, allowRemote) - if useconffile != "" { - if err := loadConfig(s, useconffile); err != nil { - logger.Fatalln(err) - } - } if err := s.Start(); err != nil { logger.Fatal(err) @@ -117,12 +94,6 @@ func main() { select { case <-c: return - case <-r: - if useconffile != "" { - if err := loadConfig(s, useconffile); err != nil { - logger.Errorln(err) - } - } } } } diff --git a/contrib/gentoo/meshnamed-0.1.0.ebuild b/contrib/gentoo/meshnamed-0.1.0.ebuild index 9d35ca8..65ff233 100644 --- a/contrib/gentoo/meshnamed-0.1.0.ebuild +++ b/contrib/gentoo/meshnamed-0.1.0.ebuild @@ -60,9 +60,6 @@ src_install() { } pkg_postinst() { - elog "The meshname config file must be generated before use:" - elog " # meshnamed -genconf -subdomain meshname | tee /etc/meshnamed.conf" - elog elog "The meshname daemon will have to be started before use:" if use systemd ; then elog " # systemctl start meshnamed" diff --git a/contrib/meshnamed.initd b/contrib/meshnamed.initd index 046bf5b..356ee91 100644 --- a/contrib/meshnamed.initd +++ b/contrib/meshnamed.initd @@ -6,7 +6,7 @@ command="/usr/bin/meshnamed" description="Distributed naming system for IPv6 mesh networks" pidfile="/run/meshnamed.pid" logfile="/var/run/meshnamed.log" -start_stop_daemon_args="--user nobody --group nobody -listenaddr '[::1]:53535' -useconffile /etc/meshnamed.conf" +start_stop_daemon_args="--user nobody --group nobody -listenaddr '[::1]:53535'" start() { ebegin "Starting Distributed naming system for IPv6 mesh networks" diff --git a/meshnamed.service b/meshnamed.service index f1bf916..fb2b60f 100644 --- a/meshnamed.service +++ b/meshnamed.service @@ -9,7 +9,7 @@ Group=nogroup ProtectHome=true ProtectSystem=true SyslogIdentifier=meshnamed -ExecStart=/usr/local/bin/meshnamed -listenaddr [::1]:53535 -useconffile /etc/meshnamed.conf +ExecStart=/usr/local/bin/meshnamed -listenaddr [::1]:53535 Restart=always TimeoutStopSec=5 diff --git a/pkg/meshname/config.go b/pkg/meshname/config.go deleted file mode 100644 index dce0494..0000000 --- a/pkg/meshname/config.go +++ /dev/null @@ -1,52 +0,0 @@ -package meshname - -import ( - "encoding/json" - "errors" - "fmt" - "io/ioutil" - "net" - - "github.com/miekg/dns" -) - -func GenConf(target, zone string) (string, error) { - ip := net.ParseIP(target) - if ip == nil { - return "", errors.New("Invalid IP address") - } - subDomain := DomainFromIP(&ip) - selfRecord := fmt.Sprintf("\t\t\"%s.%s AAAA %s\"\n", subDomain, zone, target) - confString := fmt.Sprintf("{\n\t\"%s\":[\n%s\t]\n}", subDomain, selfRecord) - - return confString, nil -} - -// Load dnsRecords from a JSON file -func ParseConfigFile(configPath string) (map[string][]dns.RR, error) { - conf, err := ioutil.ReadFile(configPath) - if err != nil { - return nil, err - } - var dat map[string][]string - if err := json.Unmarshal(conf, &dat); err == nil { - return ParseDNSRecordsMap(dat) - } else { - return nil, err - } -} - -// ParseDNSRecordsMap takes a string map and returns a resource record map -func ParseDNSRecordsMap(dnsRecordsMap map[string][]string) (map[string][]dns.RR, error) { - var dnsRecords = make(map[string][]dns.RR) - for subDomain, records := range dnsRecordsMap { - for _, r := range records { - if rr, err := dns.NewRR(r); err == nil { - dnsRecords[subDomain] = append(dnsRecords[subDomain], rr) - } else { - return nil, err - } - } - } - return dnsRecords, nil -} diff --git a/pkg/meshname/server.go b/pkg/meshname/server.go index 4439dc1..17d8c53 100644 --- a/pkg/meshname/server.go +++ b/pkg/meshname/server.go @@ -19,9 +19,6 @@ type MeshnameServer struct { enableMeshIP bool allowRemote bool - dnsRecordsLock sync.RWMutex - dnsRecords map[string][]dns.RR - startedLock sync.RWMutex started bool } @@ -34,7 +31,6 @@ func New(log *log.Logger, listenAddr string, networks map[string]*net.IPNet, ena return &MeshnameServer{ log: log, listenAddr: listenAddr, - dnsRecords: make(map[string][]dns.RR), networks: networks, dnsClient: dnsClient, enableMeshIP: enableMeshIP, @@ -89,19 +85,12 @@ func (s *MeshnameServer) Start() error { } } -func (s *MeshnameServer) ConfigureDNSRecords(dnsRecords map[string][]dns.RR) { - s.dnsRecordsLock.Lock() - s.dnsRecords = dnsRecords - s.dnsRecordsLock.Unlock() -} - func (s *MeshnameServer) handleMeshnameRequest(w dns.ResponseWriter, r *dns.Msg) { var remoteLookups = make(map[string][]dns.Question) m := new(dns.Msg) m.SetReply(r) s.log.Debugln(r.String()) - s.dnsRecordsLock.RLock() for _, q := range r.Question { labels := dns.SplitDomainName(q.Name) if len(labels) < 2 { @@ -110,13 +99,7 @@ func (s *MeshnameServer) handleMeshnameRequest(w dns.ResponseWriter, r *dns.Msg) } subDomain := labels[len(labels)-2] - if records, ok := s.dnsRecords[subDomain]; ok { - for _, rec := range records { - if h := rec.Header(); h.Name == q.Name && h.Rrtype == q.Qtype && h.Class == q.Qclass { - m.Answer = append(m.Answer, rec) - } - } - } else if s.isRemoteLookupAllowed(w.RemoteAddr()) { + if s.isRemoteLookupAllowed(w.RemoteAddr()) { // do remote lookups only for local clients resolvedAddr, err := IPFromDomain(&subDomain) if err != nil { @@ -133,7 +116,6 @@ func (s *MeshnameServer) handleMeshnameRequest(w dns.ResponseWriter, r *dns.Msg) } } } - s.dnsRecordsLock.RUnlock() for remoteServer, questions := range remoteLookups { rm := new(dns.Msg)