2016-12-22 17:51:47 -06:00
|
|
|
/*
|
|
|
|
* Functions for MDNS resolving.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Christian Huitema <huitema@huitema.net>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MDNS_H
|
|
|
|
#define MDNS_H
|
|
|
|
|
2016-12-22 22:30:14 -06:00
|
|
|
#ifdef HAVE_MDNS_SUPPORT
|
2016-12-22 17:51:47 -06:00
|
|
|
#include "getdns/getdns.h"
|
|
|
|
#include "types-internal.h"
|
2017-10-04 11:31:33 -05:00
|
|
|
#include "util-internal.h"
|
2017-10-06 09:04:49 -05:00
|
|
|
#include "platform.h"
|
2017-03-09 07:36:20 -06:00
|
|
|
#include "util/lruhash.h"
|
|
|
|
#include "config.h"
|
|
|
|
|
2016-12-22 17:51:47 -06:00
|
|
|
getdns_return_t
|
|
|
|
_getdns_submit_mdns_request(getdns_network_req *netreq);
|
|
|
|
|
|
|
|
getdns_return_t
|
2016-12-22 22:07:31 -06:00
|
|
|
_getdns_mdns_namespace_check(getdns_dns_req *dnsreq);
|
2017-01-20 21:44:05 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* data structure for continuous queries
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct getdns_mdns_known_record
|
|
|
|
{
|
2017-02-06 22:23:35 -06:00
|
|
|
/* For storage in context->mdns_known_records_by_value */
|
|
|
|
_getdns_rbnode_t node;
|
|
|
|
uint64_t insertion_microsec;
|
2017-02-13 22:28:46 -06:00
|
|
|
uint16_t record_type;
|
|
|
|
uint16_t record_class;
|
2017-02-06 22:23:35 -06:00
|
|
|
uint32_t ttl;
|
|
|
|
int name_len;
|
2017-02-13 22:28:46 -06:00
|
|
|
int record_data_len;
|
2017-02-06 22:23:35 -06:00
|
|
|
uint8_t* name;
|
2017-01-20 21:44:05 -06:00
|
|
|
uint8_t * record_data;
|
|
|
|
} getdns_mdns_known_record;
|
|
|
|
|
2017-02-13 22:28:46 -06:00
|
|
|
/*
|
|
|
|
* Each entry in the hash table is keyed by type, class and name.
|
2017-02-23 19:55:31 -06:00
|
|
|
* The key structure also contains the LRU hash entry structure.
|
2017-02-13 22:28:46 -06:00
|
|
|
* 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.
|
2017-02-23 19:55:31 -06:00
|
|
|
* For economy, the names of all answers are encoded using header compression, pointing
|
|
|
|
* to the name in the query, i.e. offset 12 from beginning of message.
|
|
|
|
* For stability, the names included in the data part of records are not compressed.
|
2017-02-13 22:28:46 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct getdns_mdns_cached_key_header
|
|
|
|
{
|
2017-02-23 19:55:31 -06:00
|
|
|
/* embedded entry, for LRU hash */
|
|
|
|
struct lruhash_entry entry;
|
|
|
|
/* identification */
|
2017-02-13 22:28:46 -06:00
|
|
|
uint16_t record_type;
|
|
|
|
uint16_t record_class;
|
|
|
|
int name_len;
|
2017-02-23 19:55:31 -06:00
|
|
|
/* the octets following this structure contain the name */
|
2017-02-13 22:28:46 -06:00
|
|
|
} getdns_mdns_cached_key_header;
|
|
|
|
|
|
|
|
typedef struct getdns_mdns_cached_record_header
|
|
|
|
{
|
|
|
|
uint64_t insertion_microsec;
|
|
|
|
uint32_t content_len;
|
|
|
|
uint32_t allocated_length;
|
2017-02-14 15:30:29 -06:00
|
|
|
/* list of user queries */
|
|
|
|
getdns_network_req *netreq_first;
|
2017-02-13 22:28:46 -06:00
|
|
|
} getdns_mdns_cached_record_header;
|
|
|
|
|
2017-01-20 21:44:05 -06:00
|
|
|
typedef struct getdns_mdns_continuous_query
|
|
|
|
{
|
2017-02-06 22:23:35 -06:00
|
|
|
/* For storage in context->mdns_continuous_queries_by_name_rrtype */
|
|
|
|
_getdns_rbnode_t node;
|
2017-01-20 21:44:05 -06:00
|
|
|
uint8_t name[256]; /* binary representation of name being queried */
|
|
|
|
int name_len;
|
|
|
|
uint16_t request_class;
|
|
|
|
uint16_t request_type;
|
|
|
|
/* list of user queries */
|
2017-02-06 22:23:35 -06:00
|
|
|
getdns_network_req *netreq_first;
|
2017-01-20 21:44:05 -06:00
|
|
|
/* todo: do we need an expiration date, or a timer? */
|
|
|
|
/* todo: do we need an update mark for showing last results? */
|
|
|
|
} getdns_mdns_continuous_query;
|
|
|
|
|
2017-02-13 22:28:46 -06:00
|
|
|
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;
|
|
|
|
|
2017-01-20 21:44:05 -06:00
|
|
|
|
2017-02-06 22:23:35 -06:00
|
|
|
void _getdns_mdns_context_init(struct getdns_context *context);
|
|
|
|
void _getdns_mdns_context_destroy(struct getdns_context *context);
|
|
|
|
|
2016-12-22 22:30:14 -06:00
|
|
|
#endif /* HAVE_MDNS_SUPPORT */
|
2016-12-22 17:51:47 -06:00
|
|
|
|
2016-12-22 22:30:14 -06:00
|
|
|
#endif /* MDNS_H */
|