1 /* 2 * FreeRTOS+TCP <DEVELOPMENT BRANCH> 3 * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 * 5 * SPDX-License-Identifier: MIT 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 * this software and associated documentation files (the "Software"), to deal in 9 * the Software without restriction, including without limitation the rights to 10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 * the Software, and to permit persons to whom the Software is furnished to do so, 12 * subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be included in all 15 * copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 * 24 * https://github.com/FreeRTOS 25 * https://www.FreeRTOS.org 26 */ 27 28 #ifndef FREERTOS_DNS_H 29 #define FREERTOS_DNS_H 30 31 #include "FreeRTOS.h" 32 33 /* Application level configuration options. */ 34 #include "FreeRTOS_DNS_Globals.h" 35 #include "FreeRTOS_DNS_Callback.h" 36 #include "FreeRTOS_DNS_Cache.h" 37 38 /* *INDENT-OFF* */ 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 /* *INDENT-ON* */ 43 44 /* 45 * LLMNR is very similar to DNS, so is handled by the DNS routines. 46 */ 47 uint32_t ulDNSHandlePacket( const NetworkBufferDescriptor_t * pxNetworkBuffer ); 48 49 #if ( ipconfigUSE_LLMNR == 1 ) 50 /* The LLMNR MAC address is 01:00:5e:00:00:fc */ 51 extern const MACAddress_t xLLMNR_MacAdress; 52 #endif /* ipconfigUSE_LLMNR */ 53 54 #if ( ipconfigUSE_LLMNR == 1 ) && ( ipconfigUSE_IPv6 != 0 ) 55 56 /* The LLMNR IPv6 address is ff02::1:3 */ 57 extern const IPv6_Address_t ipLLMNR_IP_ADDR_IPv6; 58 59 /* The LLMNR IPv6 MAC address is 33:33:00:01:00:03 */ 60 extern const MACAddress_t xLLMNR_MacAdressIPv6; 61 #endif /* ipconfigUSE_LLMNR */ 62 63 #if ( ipconfigUSE_MDNS == 1 ) 64 /* The MDNS MAC address is 01:00:5e:00:00:fc */ 65 extern const MACAddress_t xMDNS_MacAdress; 66 #endif /* ipconfigUSE_MDNS */ 67 68 #if ( ipconfigUSE_MDNS == 1 ) && ( ipconfigUSE_IPv6 != 0 ) 69 70 /* The MDNS IPv6 address is ff02::1:3 */ 71 extern const IPv6_Address_t ipMDNS_IP_ADDR_IPv6; 72 73 /* The MDNS IPv6 MAC address is 33:33:00:01:00:03 */ 74 extern const MACAddress_t xMDNS_MACAdressIPv6; 75 #endif /* ipconfigUSE_MDNS */ 76 77 /** @brief While doing integration tests, it is necessary to influence the choice 78 * between DNS/IPv4 and DNS/IPv4. Depending on this, a DNS server will be 79 * addressed via IPv4 or IPv6 messages. */ 80 typedef enum xIPPreference 81 { 82 xPreferenceNone, 83 xPreferenceIPv4, 84 #if ( ipconfigUSE_IPv6 != 0 ) 85 xPreferenceIPv6, 86 #endif 87 } IPPreference_t; 88 89 /** @brief This variable determines he choice of DNS server, either IPv4 or IPv6. */ 90 extern IPPreference_t xDNS_IP_Preference; 91 92 #if ( ipconfigUSE_NBNS != 0 ) 93 94 /* 95 * Inspect a NetBIOS Names-Service message. If the name matches with ours 96 * (xApplicationDNSQueryHook returns true) an answer will be sent back. 97 * Note that LLMNR is a better protocol for name services on a LAN as it is 98 * less polluted 99 */ 100 uint32_t ulNBNSHandlePacket( NetworkBufferDescriptor_t * pxNetworkBuffer ); 101 102 #endif /* ipconfigUSE_NBNS */ 103 104 #if ( ipconfigDNS_USE_CALLBACKS != 0 ) 105 106 /* 107 * Asynchronous version of gethostbyname() 108 * xTimeout is in units of ms. 109 */ 110 uint32_t FreeRTOS_gethostbyname_a( const char * pcHostName, 111 FOnDNSEvent pCallback, 112 void * pvSearchID, 113 TickType_t uxTimeout ); 114 void FreeRTOS_gethostbyname_cancel( void * pvSearchID ); 115 116 /* The asynchronous versions of FreeRTOS_getaddrinfo(). */ 117 BaseType_t FreeRTOS_getaddrinfo_a( const char * pcName, /* The name of the node or device */ 118 const char * pcService, /* Ignored for now. */ 119 const struct freertos_addrinfo * pxHints, /* If not NULL: preferences. */ 120 struct freertos_addrinfo ** ppxResult, /* An allocated struct, containing the results. */ 121 FOnDNSEvent pCallback, 122 void * pvSearchID, 123 TickType_t uxTimeout ); 124 125 #endif /* if ( ipconfigDNS_USE_CALLBACKS != 0 ) */ 126 127 /* 128 * Lookup a IPv4 node in a blocking-way. 129 * It returns a 32-bit IP-address, 0 when not found. 130 * gethostbyname() is already deprecated. 131 */ 132 uint32_t FreeRTOS_gethostbyname( const char * pcHostName ); 133 134 /* _HT_ Although this function is private to the library, it needs a global declaration. */ 135 struct freertos_addrinfo * pxNew_AddrInfo( const char * pcName, 136 BaseType_t xFamily, 137 const uint8_t * pucAddress ); 138 139 /* 140 * FreeRTOS_getaddrinfo() replaces FreeRTOS_gethostbyname(). 141 * When 'ipconfigUSE_IPv6' is defined, it can also retrieve IPv6 addresses, 142 * in case pxHints->ai_family equals FREERTOS_AF_INET6. 143 * Otherwise, or when pxHints is NULL, only IPv4 addresses will be returned. 144 */ 145 BaseType_t FreeRTOS_getaddrinfo( const char * pcName, /* The name of the node or device */ 146 const char * pcService, /* Ignored for now. */ 147 const struct freertos_addrinfo * pxHints, /* If not NULL: preferences. */ 148 struct freertos_addrinfo ** ppxResult ); /* An allocated struct, containing the results. */ 149 150 /* When FreeRTOS_getaddrinfo() is successful, ppxResult will point to an 151 * allocated structure. This pointer must be released by the user by calling 152 * FreeRTOS_freeaddrinfo(). 153 */ 154 void FreeRTOS_freeaddrinfo( struct freertos_addrinfo * pxInfo ); 155 156 #if ( ipconfigDNS_USE_CALLBACKS == 1 ) 157 158 /* 159 * The function vDNSInitialise() initialises the DNS module. 160 * It will be called "internally", by the IP-task. 161 */ 162 void vDNSInitialise( void ); 163 #endif /* ( ipconfigDNS_USE_CALLBACKS == 1 ) */ 164 165 /* *INDENT-OFF* */ 166 #ifdef __cplusplus 167 } /* extern "C" */ 168 #endif 169 /* *INDENT-ON* */ 170 171 #endif /* FREERTOS_DNS_H */ 172