mdns_out.h 5.4 KB

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