Merge pull request #41 from slackhq/lighthouse_static_map_error

Add an error (non fatal) when a lighthouse host has no static entry
This commit is contained in:
Ryan Huber 2019-11-23 18:24:22 -06:00 committed by GitHub
commit 94441789d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 0 deletions

View File

@ -53,6 +53,18 @@ func NewLightHouse(amLighthouse bool, myIp uint32, ips []string, interval int, n
return &h return &h
} }
func (lh *LightHouse) ValidateLHStaticEntries() error {
for lhIP, _ := range lh.lighthouses {
for ip, _ := range lh.staticList {
if lhIP == ip {
continue
}
return fmt.Errorf("Lighthouse %s does not have a static_host_map entry", IntIp(lhIP))
}
}
return nil
}
func (lh *LightHouse) Query(ip uint32, f EncWriter) ([]udpAddr, error) { func (lh *LightHouse) Query(ip uint32, f EncWriter) ([]udpAddr, error) {
if !lh.IsLighthouseIP(ip) { if !lh.IsLighthouseIP(ip) {
lh.QueryServer(ip, f) lh.QueryServer(ip, f)

View File

@ -46,6 +46,27 @@ func TestNewipandportsfromudpaddrs(t *testing.T) {
} }
func Test_lhStaticMapping(t *testing.T) {
lh1 := "10.128.0.2"
lh1IP := net.ParseIP(lh1)
udpServer, _ := NewListener("0.0.0.0", 0, true)
meh := NewLightHouse(true, 1, []string{lh1}, 10, 10003, udpServer, false)
meh.AddRemote(ip2int(lh1IP), NewUDPAddr(ip2int(lh1IP), uint16(4242)), true)
err := meh.ValidateLHStaticEntries()
assert.Nil(t, err)
lh2 := "10.128.0.3"
meh = NewLightHouse(true, 1, []string{lh1, lh2}, 10, 10003, udpServer, false)
meh.AddRemote(ip2int(lh1IP), NewUDPAddr(ip2int(lh1IP), uint16(4242)), true)
err = meh.ValidateLHStaticEntries()
assert.EqualError(t, err, "Lighthouse 10.128.0.3 does not have a static_host_map entry")
}
//func NewLightHouse(amLighthouse bool, myIp uint32, ips []string, interval int, nebulaPort int, pc *udpConn, punchBack bool) *LightHouse {
/* /*
func TestLHQuery(t *testing.T) { func TestLHQuery(t *testing.T) {
//n := NewLhQueryByIpString("10.128.0.3") //n := NewLhQueryByIpString("10.128.0.3")

View File

@ -205,6 +205,7 @@ func Main(configPath string, configTest bool, buildVersion string) {
go dnsMain(hostMap) go dnsMain(hostMap)
} }
//TODO: Move all of this inside functions in lighthouse.go
for k, v := range config.GetMap("static_host_map", map[interface{}]interface{}{}) { for k, v := range config.GetMap("static_host_map", map[interface{}]interface{}{}) {
vpnIp := net.ParseIP(fmt.Sprintf("%v", k)) vpnIp := net.ParseIP(fmt.Sprintf("%v", k))
vals, ok := v.([]interface{}) vals, ok := v.([]interface{})
@ -236,6 +237,11 @@ func Main(configPath string, configTest bool, buildVersion string) {
} }
} }
err = lightHouse.ValidateLHStaticEntries()
if err != nil {
l.WithError(err).Error("Lighthouse unreachable")
}
handshakeManager := NewHandshakeManager(tunCidr, preferredRanges, hostMap, lightHouse, udpServer) handshakeManager := NewHandshakeManager(tunCidr, preferredRanges, hostMap, lightHouse, udpServer)
//TODO: These will be reused for psk //TODO: These will be reused for psk