Skip to content

Commit 9a63fa0

Browse files
authored
Make some Nebula state programmatically available via control object (#1188)
1 parent e264a0f commit 9a63fa0

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

control.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,42 @@ func (c *Control) ListHostmapIndexes(pendingMap bool) []ControlHostInfo {
129129
}
130130
}
131131

132+
// GetCertByVpnIp returns the authenticated certificate of the given vpn IP, or nil if not found
133+
func (c *Control) GetCertByVpnIp(vpnIp netip.Addr) *cert.NebulaCertificate {
134+
if c.f.myVpnNet.Addr() == vpnIp {
135+
return c.f.pki.GetCertState().Certificate
136+
}
137+
hi := c.f.hostMap.QueryVpnIp(vpnIp)
138+
if hi == nil {
139+
return nil
140+
}
141+
return hi.GetCert()
142+
}
143+
144+
// CreateTunnel creates a new tunnel to the given vpn ip.
145+
func (c *Control) CreateTunnel(vpnIp netip.Addr) {
146+
c.f.handshakeManager.StartHandshake(vpnIp, nil)
147+
}
148+
149+
// PrintTunnel creates a new tunnel to the given vpn ip.
150+
func (c *Control) PrintTunnel(vpnIp netip.Addr) *ControlHostInfo {
151+
hi := c.f.hostMap.QueryVpnIp(vpnIp)
152+
if hi == nil {
153+
return nil
154+
}
155+
chi := copyHostInfo(hi, c.f.hostMap.GetPreferredRanges())
156+
return &chi
157+
}
158+
159+
// QueryLighthouse queries the lighthouse.
160+
func (c *Control) QueryLighthouse(vpnIp netip.Addr) *CacheMap {
161+
hi := c.f.lightHouse.Query(vpnIp)
162+
if hi == nil {
163+
return nil
164+
}
165+
return hi.CopyCache()
166+
}
167+
132168
// GetHostInfoByVpnIp returns a single tunnels hostInfo, or nil if not found
133169
// Caller should take care to Unmap() any 4in6 addresses prior to calling.
134170
func (c *Control) GetHostInfoByVpnIp(vpnIp netip.Addr, pending bool) *ControlHostInfo {

0 commit comments

Comments
 (0)