@@ -26,6 +26,11 @@ import (
26
26
27
27
var ErrHostNotKnown = errors .New ("host not known" )
28
28
29
+ type netIpAndPort struct {
30
+ ip net.IP
31
+ port uint16
32
+ }
33
+
29
34
type LightHouse struct {
30
35
//TODO: We need a timer wheel to kick out vpnIps that haven't reported in a long time
31
36
sync.RWMutex //Because we concurrently read and write to our maps
@@ -64,6 +69,8 @@ type LightHouse struct {
64
69
updateUdp udp.EncWriter
65
70
nebulaPort uint32 // 32 bits because protobuf does not have a uint16
66
71
72
+ atomicAdvertiseAddrs []netIpAndPort
73
+
67
74
metrics * MessageMetrics
68
75
metricHolepunchTx metrics.Counter
69
76
l * logrus.Logger
@@ -143,11 +150,45 @@ func (lh *LightHouse) GetLocalAllowList() *LocalAllowList {
143
150
return (* LocalAllowList )(atomic .LoadPointer ((* unsafe .Pointer )(unsafe .Pointer (& lh .atomicLocalAllowList ))))
144
151
}
145
152
153
+ func (lh * LightHouse ) GetAdvertiseAddrs () []netIpAndPort {
154
+ return * (* []netIpAndPort )(atomic .LoadPointer ((* unsafe .Pointer )(unsafe .Pointer (& lh .atomicAdvertiseAddrs ))))
155
+ }
156
+
146
157
func (lh * LightHouse ) GetUpdateInterval () int64 {
147
158
return atomic .LoadInt64 (& lh .atomicInterval )
148
159
}
149
160
150
161
func (lh * LightHouse ) reload (c * config.C , initial bool ) error {
162
+ if initial || c .HasChanged ("lighthouse.advertise_addrs" ) {
163
+ rawAdvAddrs := c .GetStringSlice ("lighthouse.advertise_addrs" , []string {})
164
+ advAddrs := make ([]netIpAndPort , 0 )
165
+
166
+ for i , rawAddr := range rawAdvAddrs {
167
+ fIp , fPort , err := udp .ParseIPAndPort (rawAddr )
168
+ if err != nil {
169
+ return util .NewContextualError ("Unable to parse lighthouse.advertise_addrs entry" , m {"addr" : rawAddr , "entry" : i + 1 }, err )
170
+ }
171
+
172
+ if fPort == 0 {
173
+ fPort = uint16 (lh .nebulaPort )
174
+ }
175
+
176
+ if ip4 := fIp .To4 (); ip4 != nil && lh .myVpnNet .Contains (fIp ) {
177
+ lh .l .WithField ("addr" , rawAddr ).WithField ("entry" , i + 1 ).
178
+ Warn ("Ignoring lighthouse.advertise_addrs report because it is within the nebula network range" )
179
+ continue
180
+ }
181
+
182
+ advAddrs = append (advAddrs , netIpAndPort {ip : fIp , port : fPort })
183
+ }
184
+
185
+ atomic .StorePointer ((* unsafe .Pointer )(unsafe .Pointer (& lh .atomicAdvertiseAddrs )), unsafe .Pointer (& advAddrs ))
186
+
187
+ if ! initial {
188
+ lh .l .Info ("lighthouse.advertise_addrs has changed" )
189
+ }
190
+ }
191
+
151
192
if initial || c .HasChanged ("lighthouse.interval" ) {
152
193
atomic .StoreInt64 (& lh .atomicInterval , int64 (c .GetInt ("lighthouse.interval" , 10 )))
153
194
@@ -535,6 +576,14 @@ func (lh *LightHouse) SendUpdate(f udp.EncWriter) {
535
576
var v4 []* Ip4AndPort
536
577
var v6 []* Ip6AndPort
537
578
579
+ for _ , e := range lh .GetAdvertiseAddrs () {
580
+ if ip := e .ip .To4 (); ip != nil {
581
+ v4 = append (v4 , NewIp4AndPort (e .ip , uint32 (e .port )))
582
+ } else {
583
+ v6 = append (v6 , NewIp6AndPort (e .ip , uint32 (e .port )))
584
+ }
585
+ }
586
+
538
587
lal := lh .GetLocalAllowList ()
539
588
for _ , e := range * localIps (lh .l , lal ) {
540
589
if ip4 := e .To4 (); ip4 != nil && ipMaskContains (lh .myVpnIp , lh .myVpnZeros , iputil .Ip2VpnIp (ip4 )) {
@@ -548,6 +597,7 @@ func (lh *LightHouse) SendUpdate(f udp.EncWriter) {
548
597
v6 = append (v6 , NewIp6AndPort (e , lh .nebulaPort ))
549
598
}
550
599
}
600
+
551
601
m := & NebulaMeta {
552
602
Type : NebulaMeta_HostUpdateNotification ,
553
603
Details : & NebulaMetaDetails {
0 commit comments