Fix sending unicast questions on cache expire Sending unicast questions requires passing IP address. Pass the one that was cached when caching DNS record. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Keep source sockaddr for every cached DNS record This will be required for sending questions on TTL timeouts. When that happens we want to send unicast question but it's currently broken as we don't know original IP address. This change stores whole sockaddr (using struct sockaddr_storage). In theory it'd be sufficient to store struct in_addr or struct in6_addr but 1) There isn't helper struct for storing IP version agnostic address 2) interface_send_packet already expects struct sockaddr It hopefully won't hurt memory usage that bad to store a bit more info. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Fix code freeing cached non-A(AAA) records too early Fixes: f89986b67dd5 ("Fix refreshing cached A(AAA) records that expire") Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Fix comment typo in cache_gc_timer Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Fix refreshing cached A(AAA) records that expire Old code was trying to refresh record after it has already expired. Now it tries after 50% of TTL has passed - we do the same for other records. Fixes: 80dd24602480 ("Refresh DNS records A and AAAA directly") Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin <john@phrozen.org>
Don't cache hosts as services This was kind of abuse of struct cache_service and the tree storing all cached entries. Host isn't really a service, treating it so required extra checks whenever dealing with cached entries. Now we converted all code to read DNS records A and AAAA directly we don't need to store these faked services. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Refresh DNS records A and AAAA directly So far records A and AAAA were being connected and stored as a single *service*. It's possible to handle these records directly without this service trick and it also provides better control over them (some corner cases like different TTL values). Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Access cached records (instead of services) to read list of hosts We don't need to access hosts stored as services. It's enough to look for cached A and AAAA DNS records. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Use A(AAA) when querying for domain on cache expire When cache entry is (halfly) expired we send query to get an update. So far we were sending all queries using PTR records but for cached domains it should be A(AAA) instead. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin <john@phrozen.org>
Rename cache scanning to updating What we were do is querying over all interfaces for all cached entries. This isn't real scanning but rather updating (the cache). Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin <john@phrozen.org>
Set TTL to the new value when updating cached service entry In the simplest case host may change TTL to some different value. It's the most important for the goodbye packets though. Consider situation when host (for which we have no no cached entries) restarts. First it sends goodbye with TTL 0 (we cache it), then seconds later it announces with standard TTL values (but we keep TTL 0). It results in wrong cache state and could cause dropping valid entries. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin <john@phrozen.org>
Change dns_send_question function arg from unicast to multicast This trivial patch just reverses argument logic to make it a bit more consistent with struct interface which contains "multicast" field. This hopefully will make typos less likely and code easier to follow. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin <john@phrozen.org>
cache: fix cache record refreshing Signed-off-by: Steven Barth <steven@midlink.org>
ubus: add ubus fetch call Signed-off-by: Steven Barth <steven@midlink.org>
cache: also cache PTR records Signed-off-by: Steven Barth <steven@midlink.org>
cache: cache rdata of SRV-records as well Signed-off-by: Steven Barth <steven@midlink.org>
Use monotonic clock for timeouts Signed-off-by: Steven Barth <steven@midlink.org>
add a basic cache refresh logic Signed-off-by: John Crispin <blogic@openwrt.org>
add a iface pointer to services and records Signed-off-by: John Crispin <blogic@openwrt.org>
entry->service Signed-off-by: John Crispin <blogic@openwrt.org>