Changed local domain handling

1. The local domain is now ".weave.local", which is safer from TLD
 pollution
 2. If the name given for an IP isn't a subdomain of the local domain,
 ignore it
This commit is contained in:
Michael Bridgen committed 2014-10-20 18:11:14 +01:00
1 parent bce06d2e9b
commit d3d07deec6
2 files changed
+13 -8

No files matched your search

+11 -6
View File
@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"log"
"github.com/miekg/dns"
"net"
"net/http"
"strings"
@@ -18,7 +19,7 @@ func parseUrl(url string) (identifier string, ipaddr string, err error) {
return parts[2], parts[3], nil
}
func ListenHttp(db Zone, port int) {
func ListenHttp(domain string, db Zone, port int) {
http.HandleFunc("/name/", func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "PUT":
@@ -44,11 +45,15 @@ func ListenHttp(db Zone, port int) {
http.Error(w, fmt.Sprintf("Invalid CIDR: %s", weave_cidr), http.StatusBadRequest)
return
}
log.Printf("Adding %s (%s) -> %s", name, local_ip, weave_cidr)
err = db.AddRecord(identifier, name, ip, weave_ip, subnet)
if err != nil {
http.Error(w, err.Error(), http.StatusConflict)
return
if dns.IsSubDomain(domain, name) {
log.Printf("Adding %s (%s) -> %s", name, local_ip, weave_cidr)
err = db.AddRecord(identifier, name, ip, weave_ip, subnet)
if err != nil {
http.Error(w, err.Error(), http.StatusConflict)
return
}
} else {
log.Printf("Ignoring name %s, not in %s", name, domain)
}
case "DELETE":
identifier, weave_ipstr, err := parseUrl(r.URL.Path)
+2 -2
View File
@@ -8,7 +8,7 @@ import (
)
const (
LOCAL_DOMAIN = "weave"
LOCAL_DOMAIN = "weave.local."
)
func makeDNSFailResponse(r *dns.Msg) *dns.Msg {
@@ -70,7 +70,7 @@ func notUsHandler() dns.HandlerFunc {
}
func StartServer(zone Zone, iface *net.Interface, dnsPort int, httpPort int, wait int) error {
go ListenHttp(zone, httpPort)
go ListenHttp(LOCAL_DOMAIN, zone, httpPort)
mdnsClient, err := NewMDNSClient()
if err != nil {