mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-21 21:09:07 +02:00
Merge remote-tracking branch 'origin/main' into components-impl-drop-indexes-use-xids
Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>
This commit is contained in:
@@ -292,18 +292,16 @@ func (s *serviceViaListener) generateFreePort() (uint16, error) {
|
|||||||
return customPort, nil
|
return customPort, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
udpAddr := net.UDPAddrFromAddrPort(netip.MustParseAddrPort("0.0.0.0:0"))
|
probeListener, err := net.ListenUDP("udp4", &net.UDPAddr{})
|
||||||
probeListener, err := net.ListenUDP("udp", udpAddr)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("failed to bind random port for DNS: %s", err)
|
log.Debugf("failed to bind random port for DNS: %s", err)
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
addrPort := netip.MustParseAddrPort(probeListener.LocalAddr().String()) // might panic if address is incorrect
|
port := uint16(probeListener.LocalAddr().(*net.UDPAddr).Port)
|
||||||
err = probeListener.Close()
|
if err = probeListener.Close(); err != nil {
|
||||||
if err != nil {
|
|
||||||
log.Debugf("failed to free up DNS port: %s", err)
|
log.Debugf("failed to free up DNS port: %s", err)
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
return addrPort.Port(), nil
|
return port, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,10 +44,25 @@ type Auth struct {
|
|||||||
// NewAuth instantiate Auth struct and validate the management URL
|
// NewAuth instantiate Auth struct and validate the management URL
|
||||||
func NewAuth(cfgPath string, mgmURL string) (*Auth, error) {
|
func NewAuth(cfgPath string, mgmURL string) (*Auth, error) {
|
||||||
inputCfg := profilemanager.ConfigInput{
|
inputCfg := profilemanager.ConfigInput{
|
||||||
|
ConfigPath: cfgPath,
|
||||||
ManagementURL: mgmURL,
|
ManagementURL: mgmURL,
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, err := profilemanager.CreateInMemoryConfig(inputCfg)
|
// Load the existing config when a config file is already present so an
|
||||||
|
// interactive re-login reuses the peer's persisted WireGuard private key
|
||||||
|
// (and thus its identity) instead of generating a fresh one. Generating a
|
||||||
|
// new key registers a brand-new peer on the management server on every
|
||||||
|
// re-auth (named after the fallback hostname). Only fall back to a fresh
|
||||||
|
// in-memory config for the first-time login when no config file exists yet.
|
||||||
|
// DirectUpdateOrCreateConfig uses non-atomic writes so it also works inside
|
||||||
|
// the tvOS App Group sandbox where atomic temp-file+rename is blocked.
|
||||||
|
var cfg *profilemanager.Config
|
||||||
|
var err error
|
||||||
|
if cfgPath != "" {
|
||||||
|
cfg, err = profilemanager.DirectUpdateOrCreateConfig(inputCfg)
|
||||||
|
} else {
|
||||||
|
cfg, err = profilemanager.CreateInMemoryConfig(inputCfg)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/client/ssh/auth"
|
"github.com/netbirdio/netbird/client/ssh/auth"
|
||||||
@@ -43,20 +44,28 @@ type NetworkMapComponents struct {
|
|||||||
|
|
||||||
RouterPeers map[string]*nbpeer.Peer
|
RouterPeers map[string]*nbpeer.Peer
|
||||||
|
|
||||||
// NetworkXIDToPublicID maps Network.ID (xid) → AccountSeqID. Populated by the
|
// NetworkXIDToPublicID maps Network.ID (xid) → PublicID.
|
||||||
// account-side component builder; consumed by the envelope encoder to
|
// Consumed by the envelope encoder to
|
||||||
// translate RoutersMap keys and NetworkResource.NetworkID references
|
// translate RoutersMap keys and NetworkResource.NetworkID references
|
||||||
// to compact uint32 ids. Legacy Calculate() doesn't consult it.
|
// to compact uint32 ids. Legacy Calculate() doesn't consult it.
|
||||||
NetworkXIDToPublicID map[string]string
|
NetworkXIDToPublicID map[string]string
|
||||||
|
|
||||||
// PostureCheckXIDToPublicID maps posture.Checks.ID (xid) → AccountSeqID.
|
// PostureCheckXIDToPublicID maps posture.Checks.ID (xid) → PublicID.
|
||||||
// Same role as NetworkXIDToSeq, used for PostureFailedPeers keys and
|
// Same role as NetworkXIDToPublicID, used for PostureFailedPeers keys and
|
||||||
// policy SourcePostureChecks references.
|
// policy SourcePostureChecks references.
|
||||||
PostureCheckXIDToPublicID map[string]string
|
PostureCheckXIDToPublicID map[string]string
|
||||||
|
routesByPeerOnce sync.Once
|
||||||
|
routesByPeerIdx map[string][]routeIndexEntry
|
||||||
|
|
||||||
// true when returning an empty-like map (returned instead of nil)
|
// true when returning an empty-like map (returned instead of nil)
|
||||||
empty bool
|
empty bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type routeIndexEntry struct {
|
||||||
|
route *route.Route
|
||||||
|
viaGroup bool
|
||||||
|
}
|
||||||
|
|
||||||
type AccountSettingsInfo struct {
|
type AccountSettingsInfo struct {
|
||||||
PeerLoginExpirationEnabled bool
|
PeerLoginExpirationEnabled bool
|
||||||
PeerLoginExpiration time.Duration
|
PeerLoginExpiration time.Duration
|
||||||
@@ -552,33 +561,43 @@ func (c *NetworkMapComponents) getRoutingPeerRoutes(peerID string) (enabledRoute
|
|||||||
disabledRoutes = append(disabledRoutes, r)
|
disabledRoutes = append(disabledRoutes, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, r := range c.Routes {
|
for _, entry := range c.routesByPeer()[peerID] {
|
||||||
for _, groupID := range r.PeerGroups {
|
if entry.viaGroup {
|
||||||
group := c.GetGroupInfo(groupID)
|
newPeerRoute := entry.route.Copy()
|
||||||
if group == nil {
|
newPeerRoute.PeerGroups = nil
|
||||||
continue
|
newPeerRoute.ID = route.ID(string(entry.route.ID) + ":" + peerID)
|
||||||
}
|
takeRoute(newPeerRoute)
|
||||||
for _, id := range group.Peers {
|
continue
|
||||||
if id != peerID {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
newPeerRoute := r.Copy()
|
|
||||||
newPeerRoute.Peer = id
|
|
||||||
newPeerRoute.PeerGroups = nil
|
|
||||||
newPeerRoute.ID = route.ID(string(r.ID) + ":" + id)
|
|
||||||
takeRoute(newPeerRoute)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if r.Peer == peerID {
|
|
||||||
takeRoute(r.Copy())
|
|
||||||
}
|
}
|
||||||
|
takeRoute(entry.route.Copy())
|
||||||
}
|
}
|
||||||
|
|
||||||
return enabledRoutes, disabledRoutes
|
return enabledRoutes, disabledRoutes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *NetworkMapComponents) routesByPeer() map[string][]routeIndexEntry {
|
||||||
|
c.routesByPeerOnce.Do(func() {
|
||||||
|
idx := make(map[string][]routeIndexEntry)
|
||||||
|
for _, r := range c.Routes {
|
||||||
|
for _, groupID := range r.PeerGroups {
|
||||||
|
group := c.GetGroupInfo(groupID)
|
||||||
|
if group == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, id := range group.Peers {
|
||||||
|
idx[id] = append(idx[id], routeIndexEntry{route: r, viaGroup: true})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if r.Peer != "" {
|
||||||
|
idx[r.Peer] = append(idx[r.Peer], routeIndexEntry{route: r})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.routesByPeerIdx = idx
|
||||||
|
})
|
||||||
|
|
||||||
|
return c.routesByPeerIdx
|
||||||
|
}
|
||||||
|
|
||||||
func (c *NetworkMapComponents) filterRoutesByGroups(routes []*route.Route, groupListMap LookupMap) []*route.Route {
|
func (c *NetworkMapComponents) filterRoutesByGroups(routes []*route.Route, groupListMap LookupMap) []*route.Route {
|
||||||
var filteredRoutes []*route.Route
|
var filteredRoutes []*route.Route
|
||||||
for _, r := range routes {
|
for _, r := range routes {
|
||||||
|
|||||||
Reference in New Issue
Block a user