Proposal: Allow plugins to skip nslookup
fdcastel opened this issue · 2 comments
When implementing #454 I found another problem which I left to solve later.
It is related to this code in cache.c
:
/* XXX: Possibly move this exception to each plugin */
const char *except[] = {
"ipv6tb@he.net",
"default@tunnelbroker.net"
};
const char *name = info->system->name;
size_t i, j;
int nonslookup = 0;
/* Exceptions -- no name to lookup */
for (i = 0; i < NELEMS(except); i++) {
if (!strncmp(name, except[i], strlen(name))) {
nonslookup = 1;
break;
}
}
// XXX: TODO better plugin identifiction here
for (j = 0; j < info->alias_count; j++)
read_one(&info->alias[j], name, nonslookup);
My current implementation for Cloudflare round-robin suffers from this problem, too. When passing a cloudflare ID this code tries to nslookup
it giving the error:
Failed resolving hostname MY_CLOUDFLARE_ID: Temporary failure in name resolution
and always forcing the update.
It is a small problem, it won't stop the update, but I would like to fix it anyways.
To the best of my understanding there are currently 2 workarounds in the code for this:
- the above code, already cited; and
- inside the
read_one()
function (a special handling forall.dnsomatic.com
):/* Exception for dnsomatic's special global hostname */ if (nonslookup || !strncmp(alias->name, "all.dnsomatic.com", sizeof(alias->name))) return; /* Try a DNS lookup of our last known IP#. */ nslookup(alias);
My first question would be:
I'm missing something or this special handling for all.dnsomatic.com
is totally unneeded? Couldn't it just be added to this array?
Second: What about to add an optional function pointer in ddns_system_t
:
const int *skip_nslookup;
which would
- receive the
hostname
as an input argument; and - return a boolean telling if the
nslookup
should be skipped.
Of course, if the function pointer is null
the default would be false
.
This would allow us to remove the special handling and also to solve my problem with Cloudflare round-robin entries.
All that said, I understand this is a very specific hook for a very specific situation being added to an entire plugin system. This is just my first idea. Any other suggestions to solve this problem are welcome.
You're right, this looks like a mess currently. I'm not so sure about the collapsing all.dnsomatic.com into that array though. The first is per provider and the latter is an exception for when a user selects updating all their dns entries for the given provider. (But then again, I'm still a bit off due to this flu I'm dragging along, and I've just woken up :)
Anyway, I think your proposal is a good one. The code needs a bit of refactoring, so please go ahead!