-
Notifications
You must be signed in to change notification settings - Fork 43
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
Mdns minimal mode #89
Open
pemensik
wants to merge
3
commits into
avahi:master
Choose a base branch
from
pemensik:mdns-minimal-mode
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,13 @@ | |
#include "util.h" | ||
#include "nss.h" | ||
|
||
#ifdef MDNS_MINIMAL | ||
#ifdef MDNS_ALLOW_FILE | ||
# undef MDNS_ALLOW_FILE | ||
#endif | ||
#define MDNS_ALLOW_FILE NULL | ||
#endif | ||
|
||
static avahi_resolve_result_t do_avahi_resolve_name(int af, const char* name, | ||
userdata_t* userdata) { | ||
bool ipv4_found = false; | ||
|
@@ -84,8 +91,6 @@ static avahi_resolve_result_t do_avahi_resolve_name(int af, const char* name, | |
enum nss_status _nss_mdns_gethostbyname_impl(const char* name, int af, | ||
userdata_t* u, int* errnop, | ||
int* h_errnop) { | ||
|
||
FILE* mdns_allow_file = NULL; | ||
use_name_result_t result; | ||
|
||
#ifdef NSS_IPV4_ONLY | ||
|
@@ -115,16 +120,8 @@ enum nss_status _nss_mdns_gethostbyname_impl(const char* name, int af, | |
|
||
u->count = 0; | ||
|
||
#ifndef MDNS_MINIMAL | ||
mdns_allow_file = fopen(MDNS_ALLOW_FILE, "r"); | ||
#endif | ||
result = verify_name_allowed_with_soa(name, mdns_allow_file, | ||
result = verify_name_allowed_with_soa(name, MDNS_ALLOW_FILE, | ||
TEST_LOCAL_SOA_AUTO); | ||
#ifndef MDNS_MINIMAL | ||
if (mdns_allow_file) | ||
fclose(mdns_allow_file); | ||
#endif | ||
|
||
if (result == USE_NAME_RESULT_SKIP) { | ||
*errnop = EINVAL; | ||
*h_errnop = NO_RECOVERY; | ||
|
@@ -224,6 +221,23 @@ enum nss_status _nss_mdns_gethostbyname_r(const char* name, | |
errnop, h_errnop); | ||
} | ||
|
||
/* Reverse addresses are not supported in config file. | ||
* They just check if config is missing to enable minimal mode | ||
* from non-minimal plugins. */ | ||
static int avahi_is_file_present(const char *path) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about rather call it |
||
if (!path) | ||
return 0; | ||
return (access(path, R_OK) == 0); | ||
} | ||
|
||
static int avahi_is_not_link_local(const void *addr, int af) { | ||
return | ||
((af == AF_INET && | ||
((ntohl(*(const uint32_t*)addr) & 0xFFFF0000UL) != 0xA9FE0000UL)) || | ||
(af == AF_INET6 && !(((const uint8_t*)addr)[0] == 0xFE && | ||
(((const uint8_t*)addr)[1] >> 6) == 2))); | ||
} | ||
|
||
enum nss_status _nss_mdns_gethostbyaddr_r(const void* addr, int len, int af, | ||
struct hostent* result, char* buffer, | ||
size_t buflen, int* errnop, | ||
|
@@ -250,17 +264,14 @@ enum nss_status _nss_mdns_gethostbyaddr_r(const void* addr, int len, int af, | |
return NSS_STATUS_UNAVAIL; | ||
} | ||
|
||
#ifdef MDNS_MINIMAL | ||
/* Only query for 169.254.0.0/16 IPv4 in minimal mode */ | ||
if ((af == AF_INET && | ||
((ntohl(*(const uint32_t*)addr) & 0xFFFF0000UL) != 0xA9FE0000UL)) || | ||
(af == AF_INET6 && !(((const uint8_t*)addr)[0] == 0xFE && | ||
(((const uint8_t*)addr)[1] >> 6) == 2))) { | ||
/* Only query for 169.254.0.0/16 IPv4 in minimal mode. | ||
* Assume minimal mode if the config file is missing. */ | ||
if (!avahi_is_file_present(MDNS_ALLOW_FILE) && | ||
avahi_is_not_link_local(addr, af)) { | ||
*errnop = EINVAL; | ||
*h_errnop = NO_RECOVERY; | ||
return NSS_STATUS_UNAVAIL; | ||
} | ||
#endif | ||
|
||
/* Lookup using Avahi */ | ||
buffer_t buf; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mention the downside of having mdns.allow as well.