mirror of
				https://github.com/juanfont/headscale.git
				synced 2025-10-28 10:51:44 +01:00 
			
		
		
		
	MagicDNS changes merged back
This commit is contained in:
		
							parent
							
								
									2eef535b4b
								
							
						
					
					
						commit
						a0fa652449
					
				
							
								
								
									
										4
									
								
								api.go
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								api.go
									
									
									
									
									
								
							| @ -225,7 +225,7 @@ func (h *Headscale) getMapResponse(mKey wgkey.Key, req tailcfg.MapRequest, m *Ma | ||||
| 		Str("func", "getMapResponse"). | ||||
| 		Str("machine", req.Hostinfo.Hostname). | ||||
| 		Msg("Creating Map response") | ||||
| 	node, err := m.toNode(true) | ||||
| 	node, err := m.toNode(h.cfg.BaseDomain, h.cfg.DNSConfig, true) | ||||
| 	if err != nil { | ||||
| 		log.Error(). | ||||
| 			Str("func", "getMapResponse"). | ||||
| @ -249,7 +249,7 @@ func (h *Headscale) getMapResponse(mKey wgkey.Key, req tailcfg.MapRequest, m *Ma | ||||
| 		DisplayName: m.Namespace.Name, | ||||
| 	} | ||||
| 
 | ||||
| 	nodePeers, err := peers.toNodes(true) | ||||
| 	nodePeers, err := peers.toNodes(h.cfg.BaseDomain, h.cfg.DNSConfig, true) | ||||
| 	if err != nil { | ||||
| 		log.Error(). | ||||
| 			Str("func", "getMapResponse"). | ||||
|  | ||||
							
								
								
									
										15
									
								
								machine.go
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								machine.go
									
									
									
									
									
								
							| @ -360,11 +360,11 @@ func (ms MachinesP) String() string { | ||||
| 	return fmt.Sprintf("[ %s ](%d)", strings.Join(temp, ", "), len(temp)) | ||||
| } | ||||
| 
 | ||||
| func (ms Machines) toNodes(includeRoutes bool) ([]*tailcfg.Node, error) { | ||||
| func (ms Machines) toNodes(baseDomain string, dnsConfig *tailcfg.DNSConfig, includeRoutes bool) ([]*tailcfg.Node, error) { | ||||
| 	nodes := make([]*tailcfg.Node, len(ms)) | ||||
| 
 | ||||
| 	for index, machine := range ms { | ||||
| 		node, err := machine.toNode(includeRoutes) | ||||
| 		node, err := machine.toNode(baseDomain, dnsConfig, includeRoutes) | ||||
| 		if err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
| @ -377,7 +377,7 @@ func (ms Machines) toNodes(includeRoutes bool) ([]*tailcfg.Node, error) { | ||||
| 
 | ||||
| // toNode converts a Machine into a Tailscale Node. includeRoutes is false for shared nodes
 | ||||
| // as per the expected behaviour in the official SaaS
 | ||||
| func (m Machine) toNode(includeRoutes bool) (*tailcfg.Node, error) { | ||||
| func (m Machine) toNode(baseDomain string, dnsConfig *tailcfg.DNSConfig, includeRoutes bool) (*tailcfg.Node, error) { | ||||
| 	nKey, err := wgkey.ParseHex(m.NodeKey) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| @ -472,10 +472,17 @@ func (m Machine) toNode(includeRoutes bool) (*tailcfg.Node, error) { | ||||
| 		keyExpiry = time.Time{} | ||||
| 	} | ||||
| 
 | ||||
| 	var hostname string | ||||
| 	if dnsConfig != nil && dnsConfig.Proxied { // MagicDNS
 | ||||
| 		hostname = fmt.Sprintf("%s.%s.%s", m.Name, m.Namespace.Name, baseDomain) | ||||
| 	} else { | ||||
| 		hostname = m.Name | ||||
| 	} | ||||
| 
 | ||||
| 	n := tailcfg.Node{ | ||||
| 		ID:         tailcfg.NodeID(m.ID),                               // this is the actual ID
 | ||||
| 		StableID:   tailcfg.StableNodeID(strconv.FormatUint(m.ID, 10)), // in headscale, unlike tailcontrol server, IDs are permanent
 | ||||
| 		Name:       hostinfo.Hostname, | ||||
| 		Name:       hostname, | ||||
| 		User:       tailcfg.UserID(m.NamespaceID), | ||||
| 		Key:        tailcfg.NodeKey(nKey), | ||||
| 		KeyExpiry:  keyExpiry, | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user