From 98a94c67ff3921210f69553673c2b3e843b1318e Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 18 Feb 2023 07:29:24 -0600 Subject: [PATCH] ready to pull DNS records Signed-off-by: Jeff Carr --- Makefile | 3 +++ args.go | 1 + dns.go | 47 +++++++++++++++++++++++++++++++++++++++++++---- gui.go | 10 +--------- net.go | 14 +++++++++++++- netlink.go | 2 ++ 6 files changed, 63 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index cc0c867..2c91975 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,9 @@ run: build verbose: build ./control-panel-dns --verbose --verbose-net --gui-debug --toolkit-debug +dns: build + ./control-panel-dns --verbose-dns + build-release: reset go get -v -u -x . diff --git a/args.go b/args.go index 40cf039..9a9680b 100644 --- a/args.go +++ b/args.go @@ -9,6 +9,7 @@ type LogOptions struct { LogFile string `help:"write all output to a file"` Verbose bool VerboseNet bool `arg:"--verbose-net" help:"debug network settings"` + VerboseDNS bool `arg:"--verbose-dns" help:"debug dns settings"` // GuiDebug bool `help:"open up the wit/gui Debugging Window"` // GuiDemo bool `help:"open the wit/gui Demo Window"` User string `arg:"env:USER"` diff --git a/dns.go b/dns.go index 93ffc8a..14b6683 100644 --- a/dns.go +++ b/dns.go @@ -5,13 +5,11 @@ package main import ( -// "os" -// "os/exec" "net" -// "git.wit.org/wit/gui" -// "github.com/davecgh/go-spew/spew" ) +var dnsTTL int = 3600; // Recheck DNS is working every TTL (in seconds) + /* Check a bunch of things. If they don't work right, then things are not correctly configured They are things like: @@ -33,3 +31,44 @@ func (h *Host) updateIPs(host string) { log(host, ip) } } + +func (h *Host) setIPv4(ipv4s map[string]*IPtype) { + for ip, t := range ipv4s { + log("IPv4", ip, t) + } +} + +func (h *Host) checkDNS() { + var ip4 bool = false + var ip6 bool = false + + for s, t := range h.ipmap { + i := t.iface + ipt := "IPv4" + if (t.ipv6) { + ipt = "IPv6" + } + if (! t.IsReal()) { + log(args.VerboseDNS, "\tIP is not Real", ipt, i.Index, i.Name, s) + continue + } + + log(args.VerboseDNS, "\tIP is Real ", ipt, i.Index, i.Name, s) + if (t.ipv6) { + ip6 = true + } else { + ip4 = true + } + } + + if (ip4 == true) { + log(args.VerboseDNS, "IPv4 should work. Wow. You actually have a real IPv4 address") + } else { + log(args.VerboseDNS, "IPv4 is broken. (be nice and setup ipv4-only.wit.com)") + } + if (ip6 == true) { + log(args.VerboseDNS, "IPv6 should be working. Need to test it here.") + } else { + log(args.VerboseDNS, "IPv6 is broken. Need to fix it here.") + } +} diff --git a/gui.go b/gui.go index 5313100..46ccb2d 100644 --- a/gui.go +++ b/gui.go @@ -71,16 +71,8 @@ func addDNSTab(window *gui.Node, title string) { log("int =", i, "name =", t.name, t.iface) } }) - g2.NewButton("dump Host.ipmap", func () { - for s, t := range me.ipmap { - log("name =", s, "ipv4 =", t.ipv4) - log("name =", s, "ipv6 =", t.ipv6) - log("name =", s, "iface =", t.iface) - log("name =", s, "ip =", t.ip) - } - }) g2.NewButton("checkDNS()", func () { - checkDNS() + me.checkDNS() }) g2.NewButton("os.Hostname()", func () { name, err = os.Hostname() diff --git a/net.go b/net.go index 70ac155..b52d513 100644 --- a/net.go +++ b/net.go @@ -91,7 +91,13 @@ func checkInterface(i net.Interface) { } } -func checkDNS() { +func checkDNS() (map[string]*IPtype, map[string]*IPtype) { + var ipv4s map[string]*IPtype + var ipv6s map[string]*IPtype + + ipv4s = make(map[string]*IPtype) + ipv6s = make(map[string]*IPtype) + for s, t := range me.ipmap { i := t.iface ipt := "IPv4" @@ -100,10 +106,16 @@ func checkDNS() { } if (t.IsReal()) { log("\tIP is Real ", ipt, i.Index, i.Name, s) + if (t.ipv6) { + ipv6s[s] = t + } else { + ipv4s[s] = t + } } else { log("\tIP is not Real", ipt, i.Index, i.Name, s) } } + return ipv6s, ipv4s } // Will figure out if an IP address is new diff --git a/netlink.go b/netlink.go index 8b2e14f..7d3c3f5 100644 --- a/netlink.go +++ b/netlink.go @@ -6,6 +6,8 @@ package main // from that page, a link to watch for any ip event: // https://github.com/angt/ipevent/blob/master/ipevent.c +// https://github.com/mdlayher/talks : Linux, Netlink, and Go in 7 minutes or less! (GopherCon 2018, lightning talk) + /* c example from ipevent.c : int fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);