Code to manage the MDNS cache using LRUHASH

This commit is contained in:
Christian Huitema 2017-02-13 18:28:46 -10:00
parent 93d6f2b18f
commit 1587e2f8f5
5 changed files with 1198 additions and 44 deletions

View File

@ -348,10 +348,10 @@ struct getdns_context {
* by name, RR type and data value.
*/
int mdns_extended_support; /* 0 = no support, 1 = supported, 2 = initialization needed */
int mdns_fdv4;
int mdns_fdv6;
int mdns_connection_nb; /* typically 0 or 2 for IPv4 and IPv6 */
struct mdns_network_connection * mdns_connection;
struct lruhash * mdns_cache;
_getdns_rbtree_t mdns_continuous_queries_by_name_rrtype;
_getdns_rbtree_t mdns_known_records_by_value;
#endif /* HAVE_MDNS_SUPPORT */
}; /* getdns_context */

View File

@ -139,5 +139,9 @@
#define DEBUG_MDNS(...) DEBUG_OFF(__VA_ARGS__)
#endif
#ifndef log_info
#define log_info(...) fprintf(stderr, __VA_ARGS__)
#endif
#endif
/* debug.h */

1187
src/mdns.c

File diff suppressed because it is too large Load Diff

View File

@ -40,15 +40,40 @@ typedef struct getdns_mdns_known_record
/* For storage in context->mdns_known_records_by_value */
_getdns_rbnode_t node;
uint64_t insertion_microsec;
uint16_t request_type;
uint16_t request_class;
uint16_t record_type;
uint16_t record_class;
uint32_t ttl;
int name_len;
int record_len;
int record_data_len;
uint8_t* name;
uint8_t * record_data;
} getdns_mdns_known_record;
/*
* Each entry in the hash table is keyed by type, class and name.
* The data part contains:
* - 64 bit time stamp
* - 32 bit word describing the record size
* - 32 bit word describing teh allocated memory size
* - valid DNS response, including 1 query and N answers, 0 AUTH, 0 AD.
* For economy, all answers are encoded using header compression, pointing
* to the name in the query, i.e. offset 12 from beginning of message
*/
typedef struct getdns_mdns_cached_key_header
{
uint16_t record_type;
uint16_t record_class;
int name_len;
} getdns_mdns_cached_key_header;
typedef struct getdns_mdns_cached_record_header
{
uint64_t insertion_microsec;
uint32_t content_len;
uint32_t allocated_length;
} getdns_mdns_cached_record_header;
typedef struct getdns_mdns_continuous_query
{
/* For storage in context->mdns_continuous_queries_by_name_rrtype */
@ -63,6 +88,16 @@ typedef struct getdns_mdns_continuous_query
/* todo: do we need an update mark for showing last results? */
} getdns_mdns_continuous_query;
typedef struct mdns_network_connection
{
struct getdns_context* context;
int fd;
int addr_mcast_len;
SOCKADDR_STORAGE addr_mcast;
getdns_eventloop_event event;
uint8_t response[1500];
} mdns_network_connection;
void _getdns_mdns_context_init(struct getdns_context *context);
void _getdns_mdns_context_destroy(struct getdns_context *context);

View File

@ -708,7 +708,11 @@ static void remove_listeners(listen_set *set)
continue;
loop->vmt->clear(loop, &l->event);
#ifdef USE_WINSOCK
closesocket(l->fd);
#else
close(l->fd);
#endif
l->fd = -1;
if (l->transport != GETDNS_TRANSPORT_TCP)