1 /* 2 * Copyright (c) 2019, The OpenThread Authors. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 3. Neither the name of the copyright holder nor the 13 * names of its contributors may be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndef OPENTHREAD_PLATFORM_CONFIG_H_ 30 #define OPENTHREAD_PLATFORM_CONFIG_H_ 31 32 #include "openthread-core-config.h" 33 34 /** 35 * @file 36 * @brief 37 * This file includes the POSIX platform-specific configurations. 38 */ 39 40 /** 41 * @def OPENTHREAD_POSIX_CONFIG_RCP_PTY_ENABLE 42 * 43 * Define as 1 to enable PTY RCP support. 44 * 45 */ 46 #ifndef OPENTHREAD_POSIX_CONFIG_RCP_PTY_ENABLE 47 #define OPENTHREAD_POSIX_CONFIG_RCP_PTY_ENABLE 1 48 #endif 49 50 /** 51 * @def OPENTHREAD_POSIX_CONFIG_DAEMON_SOCKET_BASENAME 52 * 53 * Define socket basename used by POSIX app daemon. 54 * 55 */ 56 #ifndef OPENTHREAD_POSIX_CONFIG_DAEMON_SOCKET_BASENAME 57 #ifdef __linux__ 58 #define OPENTHREAD_POSIX_CONFIG_DAEMON_SOCKET_BASENAME "/run/openthread-%s" 59 #else 60 #define OPENTHREAD_POSIX_CONFIG_DAEMON_SOCKET_BASENAME "/tmp/openthread-%s" 61 #endif 62 #endif 63 64 /** 65 * @def OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE 66 * 67 * Define to 1 to enable POSIX daemon. 68 * 69 */ 70 #ifndef OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE 71 #define OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE 0 72 #endif 73 74 /** 75 * RCP bus UART. 76 * 77 * @note This value is also for simulated UART bus. 78 * 79 */ 80 #define OT_POSIX_RCP_BUS_UART 1 81 82 /** 83 * RCP bus SPI. 84 * 85 */ 86 #define OT_POSIX_RCP_BUS_SPI 2 87 88 /** 89 * RCP bus defined by vendors. 90 * 91 */ 92 #define OT_POSIX_RCP_BUS_VENDOR 3 93 94 /** 95 * @def OPENTHREAD_POSIX_CONFIG_RCP_BUS 96 * 97 * This setting configures what type of RCP bus to use. 98 * 99 */ 100 #ifndef OPENTHREAD_POSIX_CONFIG_RCP_BUS 101 #define OPENTHREAD_POSIX_CONFIG_RCP_BUS OT_POSIX_RCP_BUS_UART 102 #endif 103 104 /** 105 * @def OPENTHREAD_POSIX_CONFIG_MAX_POWER_TABLE_ENABLE 106 * 107 * Define as 1 to enable max power table support. 108 * 109 */ 110 #ifndef OPENTHREAD_POSIX_CONFIG_MAX_POWER_TABLE_ENABLE 111 #define OPENTHREAD_POSIX_CONFIG_MAX_POWER_TABLE_ENABLE 0 112 #endif 113 114 /** 115 * @def OPENTHREAD_POSIX_CONFIG_MAX_MULTICAST_FORWARDING_CACHE_TABLE 116 * 117 * This setting configures the maximum number of Multicast Forwarding Cache table for POSIX native multicast routing. 118 * 119 */ 120 #ifndef OPENTHREAD_POSIX_CONFIG_MAX_MULTICAST_FORWARDING_CACHE_TABLE 121 #define OPENTHREAD_POSIX_CONFIG_MAX_MULTICAST_FORWARDING_CACHE_TABLE (OPENTHREAD_CONFIG_MAX_MULTICAST_LISTENERS * 10) 122 #endif 123 124 /** 125 * @def OPENTHREAD_POSIX_CONFIG_SECURE_SETTINGS_ENABLE 126 * 127 * Define as 1 to enable the secure settings. When defined to 1, the platform MUST implement the otPosixSecureSetting* 128 * APIs defined in 'src/posix/platform/include/openthread/platform/secure_settings.h'. 129 * 130 */ 131 #ifndef OPENTHREAD_POSIX_CONFIG_SECURE_SETTINGS_ENABLE 132 #define OPENTHREAD_POSIX_CONFIG_SECURE_SETTINGS_ENABLE 0 133 #endif 134 135 /** 136 * @def OPENTHREAD_POSIX_CONFIG_NETIF_PREFIX_ROUTE_METRIC 137 * 138 * This setting configures the prefix route metric on the Thread network interface. 139 * Define as 0 to use use the default prefix route metric. 140 * 141 * Note: The feature works on Linux kernel v4.18+. 142 * 143 */ 144 #ifndef OPENTHREAD_POSIX_CONFIG_NETIF_PREFIX_ROUTE_METRIC 145 #define OPENTHREAD_POSIX_CONFIG_NETIF_PREFIX_ROUTE_METRIC 0 146 #endif 147 148 /** 149 * @def OPENTHREAD_POSIX_CONFIG_INSTALL_OMR_ROUTES_ENABLE 150 * 151 * Define as 1 to add OMR routes to POSIX kernel when OMR prefixes are changed in netdata. 152 * 153 * Note: This feature can be used to add OMR routes with non-default priority. Unlike 154 * `OPENTHREAD_POSIX_CONFIG_NETIF_PREFIX_ROUTE_METRIC`, it works on Linux kernels before v4.18. 155 * However, `OPENTHREAD_POSIX_CONFIG_NETIF_PREFIX_ROUTE_METRIC` should be preferred on Linux kernel v4.18+. 156 * 157 */ 158 #ifndef OPENTHREAD_POSIX_CONFIG_INSTALL_OMR_ROUTES_ENABLE 159 #define OPENTHREAD_POSIX_CONFIG_INSTALL_OMR_ROUTES_ENABLE 0 160 #endif 161 162 /** 163 * @def OPENTHREAD_POSIX_CONFIG_OMR_ROUTES_PRIORITY 164 * 165 * This macro defines the priority of OMR routes added to kernel. The larger the number, the lower the priority. We 166 * need to assign a high priority to such routes so that kernel prefers the Thread link rather than infrastructure. 167 * Otherwise we may unnecessarily transmit packets via infrastructure, which potentially causes looping issue. 168 * 169 */ 170 #ifndef OPENTHREAD_POSIX_CONFIG_OMR_ROUTES_PRIORITY 171 #define OPENTHREAD_POSIX_CONFIG_OMR_ROUTES_PRIORITY 1 172 #endif 173 174 /** 175 * @def OPENTHREAD_POSIX_CONFIG_MAX_OMR_ROUTES_NUM 176 * 177 * This macro defines the max number of OMR routes that can be added to kernel. 178 * 179 */ 180 #ifndef OPENTHREAD_POSIX_CONFIG_MAX_OMR_ROUTES_NUM 181 #define OPENTHREAD_POSIX_CONFIG_MAX_OMR_ROUTES_NUM OPENTHREAD_CONFIG_IP6_SLAAC_NUM_ADDRESSES 182 #endif 183 184 /** 185 * @def OPENTHREAD_POSIX_CONFIG_INSTALL_EXTERNAL_ROUTES_ENABLE 186 * 187 * Define as 1 to add external routes to POSIX kernel when external routes are changed in netdata. 188 * 189 */ 190 #ifndef OPENTHREAD_POSIX_CONFIG_INSTALL_EXTERNAL_ROUTES_ENABLE 191 #define OPENTHREAD_POSIX_CONFIG_INSTALL_EXTERNAL_ROUTES_ENABLE 1 192 #endif 193 194 /** 195 * @def OPENTHREAD_POSIX_CONFIG_EXTERNAL_ROUTE_PRIORITY 196 * 197 * This macro defines the priority of external routes added to kernel. The larger the number, the lower the priority. We 198 * need to assign a low priority to such routes so that kernel prefers the infra link rather than thread. Otherwise we 199 * may unnecessarily transmit packets via thread, which potentially causes performance issue. In linux, normally infra 200 * link routes' metric value is not greater than 1024, hence 65535 should be big enough. 201 * 202 */ 203 #ifndef OPENTHREAD_POSIX_CONFIG_EXTERNAL_ROUTE_PRIORITY 204 #define OPENTHREAD_POSIX_CONFIG_EXTERNAL_ROUTE_PRIORITY 65535 205 #endif 206 207 /** 208 * @def OPENTHREAD_POSIX_CONFIG_MAX_EXTERNAL_ROUTE_NUM 209 * 210 * This macro defines the max number of external routes that can be added to kernel. 211 * 212 */ 213 #ifndef OPENTHREAD_POSIX_CONFIG_MAX_EXTERNAL_ROUTE_NUM 214 #define OPENTHREAD_POSIX_CONFIG_MAX_EXTERNAL_ROUTE_NUM 8 215 #endif 216 217 /** 218 * @def OPENTHREAD_POSIX_CONFIG_FIREWALL_ENABLE 219 * 220 * Define as 1 to enable firewall. 221 * 222 * The rules are implemented using ip6tables and ipset. The rules are as follows. 223 * 224 * ip6tables -A $OTBR_FORWARD_INGRESS_CHAIN -m pkttype --pkt-type unicast -i $THREAD_IF -p ip -j DROP 225 * ip6tables -A $OTBR_FORWARD_INGRESS_CHAIN -m set --match-set otbr-ingress-deny-src src -p ip -j DROP 226 * ip6tables -A $OTBR_FORWARD_INGRESS_CHAIN -m set --match-set otbr-ingress-allow-dst dst -p ip -j ACCEPT 227 * ip6tables -A $OTBR_FORWARD_INGRESS_CHAIN -m pkttype --pkt-type unicast -p ip -j DROP 228 * ip6tables -A $OTBR_FORWARD_INGRESS_CHAIN -p ip -j ACCEPT 229 * 230 */ 231 #ifndef OPENTHREAD_POSIX_CONFIG_FIREWALL_ENABLE 232 #define OPENTHREAD_POSIX_CONFIG_FIREWALL_ENABLE 0 233 #endif 234 235 #if OPENTHREAD_POSIX_CONFIG_FIREWALL_ENABLE 236 #ifndef OPENTHREAD_POSIX_CONFIG_IPSET_BINARY 237 #define OPENTHREAD_POSIX_CONFIG_IPSET_BINARY "ipset" 238 #endif 239 #endif 240 241 #ifdef __APPLE__ 242 243 /** 244 * Use built-in utun driver on mac OS 245 */ 246 #define OT_POSIX_CONFIG_MACOS_UTUN 1 247 248 /** 249 * Use open-source tun driver on mac OS 250 */ 251 #define OT_POSIX_CONFIG_MACOS_TUN 2 252 253 /** 254 * @def OPENTHREAD_POSIX_CONFIG_MACOS_TUN_OPTION 255 * 256 * This setting configures which tunnel driver to use. 257 * 258 */ 259 #ifndef OPENTHREAD_POSIX_CONFIG_MACOS_TUN_OPTION 260 #define OPENTHREAD_POSIX_CONFIG_MACOS_TUN_OPTION OT_POSIX_CONFIG_MACOS_UTUN 261 #endif 262 263 #endif // __APPLE__ 264 265 //--------------------------------------------------------------------------------------------------------------------- 266 // Removed or renamed POSIX specific configs. 267 268 #ifdef OPENTHREAD_CONFIG_POSIX_APP_TREL_INTERFACE_NAME 269 #error "OPENTHREAD_CONFIG_POSIX_APP_TREL_INTERFACE_NAME was removed (no longer applicable with TREL over DNS-SD)." 270 #endif 271 272 #ifdef OPENTHREAD_CONFIG_POSIX_TREL_USE_NETLINK_SOCKET 273 #error "OPENTHREAD_CONFIG_POSIX_TREL_USE_NETLINK_SOCKET was removed (no longer applicable with TREL over DNS-SD)." 274 #endif 275 276 /** 277 * @def OPENTHREAD_POSIX_CONFIG_TREL_UDP_PORT 278 * 279 * This setting configures the TREL UDP port number. 280 * Define as 0 to use an ephemeral port number. 281 * 282 */ 283 #ifndef OPENTHREAD_POSIX_CONFIG_TREL_UDP_PORT 284 #define OPENTHREAD_POSIX_CONFIG_TREL_UDP_PORT 0 285 #endif 286 287 #endif // OPENTHREAD_PLATFORM_CONFIG_H_ 288