Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert DNS search path to std::vector<SBuf> #1751

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

yadij
Copy link
Contributor

@yadij yadij commented Mar 21, 2024

No description provided.

src/dns_internal.cc Outdated Show resolved Hide resolved
Copy link
Contributor

@rousskov rousskov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this useful conversion.

src/dns_internal.cc Outdated Show resolved Hide resolved
src/dns_internal.cc Outdated Show resolved Hide resolved
src/dns_internal.cc Outdated Show resolved Hide resolved
src/dns_internal.cc Outdated Show resolved Hide resolved
src/dns_internal.cc Outdated Show resolved Hide resolved
src/dns_internal.cc Outdated Show resolved Hide resolved
src/dns_internal.cc Outdated Show resolved Hide resolved
@rousskov rousskov added the S-waiting-for-author author action is expected (and usually required) label Mar 21, 2024
@yadij yadij added S-waiting-for-reviewer ready for review: Set this when requesting a (re)review using GitHub PR Reviewers box and removed S-waiting-for-author author action is expected (and usually required) labels Mar 25, 2024
@yadij yadij requested a review from rousskov March 25, 2024 04:03
@rousskov rousskov changed the title Convert DNS search path to std::vector Convert DNS search path to std::vector<SBuf> Mar 25, 2024
Copy link
Contributor

@rousskov rousskov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent progress, thank you!

I added SBuf to PR title in order to emphasize that this PR contains to-SBuf conversion in addition to to-vector conversion. I do not insist on that title change.

@@ -1745,7 +1755,7 @@ idnsALookup(const char *name, IDNSCB * callback, void *data)
if (q->do_searchpath && nd < ndots) {
q->domain = 0;
strcat(q->name, ".");
strcat(q->name, Dns::SearchPath()[q->domain].domain);
strcat(q->name, Dns::SearchPath()[q->domain].c_str());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and elsewhere in this PR, please avoid SBuf::c_str() overheads by using strncat() instead of strcat(). I recommend encapsulating this duplicated code inside idns_query::useSearchPath() or similar method.

Dns::SearchPath().push_back(name);

buf.chop(pos+Separator.length());
auto pos = buf.find(Separator);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo?

Suggested change
auto pos = buf.find(Separator);
pos = buf.find(Separator);

Comment on lines +381 to +383
name.toLower();
debugs(78, DBG_IMPORTANT, "Adding domain " << name << " from hostname");
Dns::SearchPath().push_back(name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please encapsulated this widely duplicated code into Dns::AddSearchPath(name, source) or similar function. We do not want to chaise places that forgot to call toLower() and/or debugs() when adding new search path components a few years from now.

Suggested change
name.toLower();
debugs(78, DBG_IMPORTANT, "Adding domain " << name << " from hostname");
Dns::SearchPath().push_back(name);
Dns::AddSearchPath(name, "from hostname");

The official code has idnsAddPathComponent(). This PR removes that function. We should replace it with a better one instead of inlining and duplicating the replacement code.

@@ -419,6 +402,7 @@ idnsParseResolvConf(void)

char buf[RESOLV_BUFSZ];
const char *t = nullptr;
SBuf name;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please declare this new variable for each use case that needs it, reducing future refactoring work to eliminate unwanted reuse of loop-global variables like t.

@@ -404,6 +367,26 @@ idnsParseNameservers(void)
return result;
}

static void
AddSearchPathFromHostname()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend renaming this to MaybeAddSearchPathFromHostname() to avoid concerns that undocumented AddFoo() does not throw (or otherwise declare an error) when it does not actually add Foo. I do not insist on this change.

@rousskov rousskov added S-waiting-for-author author action is expected (and usually required) and removed S-waiting-for-reviewer ready for review: Set this when requesting a (re)review using GitHub PR Reviewers box labels Mar 25, 2024
@squid-anubis squid-anubis added M-failed-other https://github.com/measurement-factory/anubis#pull-request-labels and removed M-failed-other https://github.com/measurement-factory/anubis#pull-request-labels labels May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-for-author author action is expected (and usually required)
Projects
None yet
4 participants