Extract interface util functions to their own file
This commit is contained in:
1 parent
3af058481e
commit
b8a06521c0
2 files changed
+35
-28
No files matched your search
@@ -0,0 +1,35 @@
|
|||||||
|
package weavedns
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ensureInterface(ifaceName string, wait int) (iface *net.Interface, err error) {
|
||||||
|
iface, err = findInterface(ifaceName)
|
||||||
|
if err == nil || wait == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Println("Waiting for interface", ifaceName, "to come up")
|
||||||
|
for ; err != nil && wait > 0; wait -= 1 {
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
iface, err = findInterface(ifaceName)
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
log.Println("Interface", ifaceName, "is up")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func findInterface(ifaceName string) (iface *net.Interface, err error) {
|
||||||
|
iface, err = net.InterfaceByName(ifaceName)
|
||||||
|
if err != nil {
|
||||||
|
return iface, fmt.Errorf("Unable to find interface %s", ifaceName)
|
||||||
|
}
|
||||||
|
if 0 == (net.FlagUp & iface.Flags) {
|
||||||
|
return iface, fmt.Errorf("Interface %s is not up", ifaceName)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -5,40 +5,12 @@ import (
|
|||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LOCAL_DOMAIN = "weave"
|
LOCAL_DOMAIN = "weave"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ensureInterface(ifaceName string, wait int) (iface *net.Interface, err error) {
|
|
||||||
iface, err = findInterface(ifaceName)
|
|
||||||
if err == nil || wait == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Println("Waiting for interface", ifaceName, "to come up")
|
|
||||||
for ; err != nil && wait > 0; wait -= 1 {
|
|
||||||
time.Sleep(1 * time.Second)
|
|
||||||
iface, err = findInterface(ifaceName)
|
|
||||||
}
|
|
||||||
if err == nil {
|
|
||||||
log.Println("Interface", ifaceName, "is up")
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func findInterface(ifaceName string) (iface *net.Interface, err error) {
|
|
||||||
iface, err = net.InterfaceByName(ifaceName)
|
|
||||||
if err != nil {
|
|
||||||
return iface, fmt.Errorf("Unable to find interface %s", ifaceName)
|
|
||||||
}
|
|
||||||
if 0 == (net.FlagUp & iface.Flags) {
|
|
||||||
return iface, fmt.Errorf("Interface %s is not up", ifaceName)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeDNSFailResponse(r *dns.Msg) *dns.Msg {
|
func makeDNSFailResponse(r *dns.Msg) *dns.Msg {
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
m.SetReply(r)
|
m.SetReply(r)
|
||||||
|
|||||||
Reference in new issue
Block a user