[GH-ISSUE #142] Don't resolve record directly #383

Open
opened 2026-03-13 14:49:54 +03:00 by kerem · 3 comments
Owner

Originally created by @ghost on GitHub (May 3, 2024).
Original GitHub issue: https://github.com/abh/geodns/issues/142

Hello there,

I wanted to know is there any way with this library to prevent direct lookup results for de.example.com, europe.example.com, ... and only allow resolves for example.com ?

Thanks in advance.

Originally created by @ghost on GitHub (May 3, 2024). Original GitHub issue: https://github.com/abh/geodns/issues/142 Hello there, I wanted to know is there any way with this library to prevent direct lookup results for de.example.com, europe.example.com, ... and only allow resolves for example.com ? Thanks in advance.
Author
Owner

@ghost commented on GitHub (May 3, 2024):

@abh

I can add this code to the serve.go and it will resolve the issue, do you think this is the right way? Should I open pull request?

if len(labelMatches) == 1 {
  var countryCode, continentCode string
  
  if len(targets) == 3 {
	  countryCode, continentCode = targets[1], targets[2]
  } else if len(targets) == 2 {
	  if countries.CountryContinent[targets[1]] != "" {
		  countryCode = targets[1]
	  } else {
		  continentCode = targets[1]
	  }
  }
  
  cc := strings.SplitN(labelMatches[0].Label.Label, ".", 2)
  
  if len(cc) == 2 && (countries.CountryContinent[cc[1]] != "" || len(countries.ContinentCountries[cc[1]]) > 0) {
	  newTargets := targets
  
	  if cc[1] != countryCode && cc[1] != continentCode {
		  newTargets = append(newTargets, cc[1])
	  }
  
	  parentLabelMatches := z.FindLabels(cc[0], newTargets, []uint16{dns.TypeMF, dns.TypeCNAME, qtype})
  
	  if len(parentLabelMatches) > 1 {
		  // empty labelMatches
		  labelMatches = []zones.LabelMatch{}
	  }
  }
}

Also this must be added to imports on top:

"github.com/abh/geodns/v3/countries"
<!-- gh-comment-id:2093211491 --> @ghost commented on GitHub (May 3, 2024): @abh I can add this code to the serve.go and it will resolve the issue, do you think this is the right way? Should I open pull request? ``` if len(labelMatches) == 1 { var countryCode, continentCode string if len(targets) == 3 { countryCode, continentCode = targets[1], targets[2] } else if len(targets) == 2 { if countries.CountryContinent[targets[1]] != "" { countryCode = targets[1] } else { continentCode = targets[1] } } cc := strings.SplitN(labelMatches[0].Label.Label, ".", 2) if len(cc) == 2 && (countries.CountryContinent[cc[1]] != "" || len(countries.ContinentCountries[cc[1]]) > 0) { newTargets := targets if cc[1] != countryCode && cc[1] != continentCode { newTargets = append(newTargets, cc[1]) } parentLabelMatches := z.FindLabels(cc[0], newTargets, []uint16{dns.TypeMF, dns.TypeCNAME, qtype}) if len(parentLabelMatches) > 1 { // empty labelMatches labelMatches = []zones.LabelMatch{} } } } ``` Also this must be added to imports on top: ``` "github.com/abh/geodns/v3/countries" ```
Author
Owner

@abh commented on GitHub (May 4, 2024):

Something like that could work with an option to enable the feature.

Though I think it'd make more sense to "hide" the targeting rules in some way in a separate part of the data structure (and then if the data comes that way then they can't be queried directly).

Many years ago @miekg suggested having the zone format be a regular "RFC 1035 zone" with extra metadata for the targeting information; that might be worth revisiting again.

<!-- gh-comment-id:2093907922 --> @abh commented on GitHub (May 4, 2024): Something like that could work with an option to enable the feature. Though I think it'd make more sense to "hide" the targeting rules in some way in a separate part of the data structure (and then if the data comes that way then they can't be queried directly). Many years ago @miekg suggested having the zone format be a regular "RFC 1035 zone" with extra metadata for the targeting information; that might be worth revisiting again.
Author
Owner

@ghost commented on GitHub (May 4, 2024):

@abh I have managed to code it somehow, but I don't know where to put for configuration or if its the right decision, take a look:

github.com/abh/geodns@6047cb9567

<!-- gh-comment-id:2093910948 --> @ghost commented on GitHub (May 4, 2024): @abh I have managed to code it somehow, but I don't know where to put for configuration or if its the right decision, take a look: https://github.com/abh/geodns/commit/6047cb9567c651e41e1d1cbe1e3ac2ff0bc736f3
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/geodns#383
No description provided.