1 /** 2 * @file 3 * MDNS responder - output related functionalities 4 */ 5 6 /* 7 * Copyright (c) 2015 Verisure Innovation AB 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without modification, 11 * are permitted provided that the following conditions are met: 12 * 13 * 1. Redistributions of source code must retain the above copyright notice, 14 * this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright notice, 16 * this list of conditions and the following disclaimer in the documentation 17 * and/or other materials provided with the distribution. 18 * 3. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 24 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 30 * OF SUCH DAMAGE. 31 * 32 * This file is part of the lwIP TCP/IP stack. 33 * 34 * Author: Erik Ekman <erik@kryo.se> 35 * Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> 36 * 37 */ 38 39 #ifndef LWIP_HDR_APPS_MDNS_OUT_H 40 #define LWIP_HDR_APPS_MDNS_OUT_H 41 42 #include "lwip/apps/mdns_opts.h" 43 #include "lwip/apps/mdns_priv.h" 44 #include "lwip/netif.h" 45 #include "lwip/timeouts.h" 46 47 #ifdef __cplusplus 48 extern "C" { 49 #endif 50 51 #if LWIP_MDNS_RESPONDER 52 53 /** Bitmasks outmsg generation */ 54 /* Probe for ALL types with hostname */ 55 #define QUESTION_PROBE_HOST_ANY 0x10 56 /* Probe for ALL types with service instance name */ 57 #define QUESTION_PROBE_SERVICE_NAME_ANY 0x10 58 59 /* Lookup from hostname -> IPv4 */ 60 #define REPLY_HOST_A 0x01 61 /* Lookup from IPv4/v6 -> hostname */ 62 #define REPLY_HOST_PTR_V4 0x02 63 /* Lookup from hostname -> IPv6 */ 64 #define REPLY_HOST_AAAA 0x04 65 /* Lookup from hostname -> IPv6 */ 66 #define REPLY_HOST_PTR_V6 0x08 67 68 /* Lookup for service types */ 69 #define REPLY_SERVICE_TYPE_PTR 0x10 70 /* Lookup for instances of service */ 71 #define REPLY_SERVICE_NAME_PTR 0x20 72 /* Lookup for location of service instance */ 73 #define REPLY_SERVICE_SRV 0x40 74 /* Lookup for text info on service instance */ 75 #define REPLY_SERVICE_TXT 0x80 76 77 /* RFC6762 section 6: 78 * To protect the network against excessive packet flooding due to software bugs 79 * or malicious attack, a Multicast DNS responder MUST NOT (except in the one 80 * special case of answering probe queries) multicast a record on a given 81 * interface until at least one second has elapsed since the last time that 82 * record was multicast on that particular interface. 83 */ 84 #define MDNS_MULTICAST_TIMEOUT 1000 85 86 /* RFC6762 section 6: 87 * In this special case only, when responding via multicast to a probe, a 88 * Multicast DNS responder is only required to delay its transmission as 89 * necessary to ensure an interval of at least 250 ms since the last time the 90 * record was multicast on that interface. 91 */ 92 #define MDNS_MULTICAST_PROBE_TIMEOUT 250 93 94 /* RFC6762 section 5.4: 95 * When receiving a question with the unicast-response bit set, a responder 96 * SHOULD usually respond with a unicast packet directed back to the querier. 97 * However, if the responder has not multicast that record recently (within one 98 * quarter of its TTL), then the responder SHOULD instead multicast the response 99 * so as to keep all the peer caches up to date, and to permit passive conflict 100 * detection. 101 * -> we implement a stripped down version. Depending on a timeout of 30s 102 * (25% of 120s) all QU questions are send via multicast or unicast. 103 */ 104 #define MDNS_MULTICAST_TIMEOUT_25TTL 30000 105 106 err_t mdns_create_outpacket(struct netif *netif, struct mdns_outmsg *msg, 107 struct mdns_outpacket *outpkt); 108 err_t mdns_send_outpacket(struct mdns_outmsg *msg, struct netif *netif); 109 void mdns_set_timeout(struct netif *netif, u32_t msecs, 110 sys_timeout_handler handler, u8_t *busy_flag); 111 #if LWIP_IPV4 112 void mdns_multicast_timeout_reset_ipv4(void *arg); 113 void mdns_multicast_probe_timeout_reset_ipv4(void *arg); 114 void mdns_multicast_timeout_25ttl_reset_ipv4(void *arg); 115 void mdns_send_multicast_msg_delayed_ipv4(void *arg); 116 void mdns_send_unicast_msg_delayed_ipv4(void *arg); 117 void mdns_start_multicast_timeouts_ipv4(struct netif *netif); 118 #endif 119 #if LWIP_IPV6 120 void mdns_multicast_timeout_reset_ipv6(void *arg); 121 void mdns_multicast_probe_timeout_reset_ipv6(void *arg); 122 void mdns_multicast_timeout_25ttl_reset_ipv6(void *arg); 123 void mdns_send_multicast_msg_delayed_ipv6(void *arg); 124 void mdns_send_unicast_msg_delayed_ipv6(void *arg); 125 void mdns_start_multicast_timeouts_ipv6(struct netif *netif); 126 #endif 127 void mdns_prepare_txtdata(struct mdns_service *service); 128 #ifdef LWIP_MDNS_SEARCH 129 err_t mdns_send_request(struct mdns_request *req, struct netif *netif, const ip_addr_t *destination); 130 #endif 131 132 #endif /* LWIP_MDNS_RESPONDER */ 133 134 #ifdef __cplusplus 135 } 136 #endif 137 138 #endif /* LWIP_HDR_APPS_MDNS_OUT_H */ 139