1# BSD Sockets compatible API 2 3# Copyright (c) 2017 Linaro Limited. 4# SPDX-License-Identifier: Apache-2.0 5 6menuconfig NET_SOCKETS 7 bool "BSD Sockets compatible API" 8 select FDTABLE 9 help 10 Provide BSD Sockets like API on top of native Zephyr networking API. 11 12if NET_SOCKETS 13 14config NET_SOCKETS_PRIORITY_DEFAULT 15 int "Default processing priority for sockets" 16 default 50 17 help 18 Default processing priority for socket implementations. This defines 19 the order of processing of particular socket implementations when 20 creating a new socket, lower value indicate earlier processing. This 21 allows to for instance prioritize offloaded socket processing during 22 socket creation over the native one, or vice versa. 23 24config NET_SOCKETS_POSIX_NAMES 25 bool "[DEPRECATED] POSIX names for Sockets API (without full POSIX API)" 26 depends on !POSIX_API 27 select DEPRECATED 28 help 29 This option is marked as deprecated in favor of using normal 30 POSIX socket API includes found under the include/zephyr/posix 31 directory. If you want to use BSD socket API calls, you need 32 to select POSIX_API and use the socket headers in POSIX subsystem. 33 34 With this option, Socket API functions are available under the 35 standard POSIX names like socket(), recv(), and close(), etc., 36 even if full POSIX API (CONFIG_POSIX_API) is not enabled. (Note 37 that close() may require a special attention, as in POSIX it 38 closes any file descriptor, while with this option enabled, it 39 will apply only to sockets.) 40 41 Various networking libraries require either 42 CONFIG_NET_SOCKETS_POSIX_NAMES or CONFIG_POSIX_API to be set. 43 If both are disabled, Zephyr's socket functions will be 44 available (only) with ``zsock_`` prefix, (e.g. `zsock_socket`). 45 This is useful only in peculiar cases, e.g. when integrating 46 with 3rd-party socket libraries. 47 48config NET_SOCKETS_POLL_MAX 49 int "Max number of supported poll() entries" 50 default 6 if WIFI_NM_WPA_SUPPLICANT 51 default 4 if SHELL_BACKEND_TELNET 52 default 3 53 help 54 Maximum number of entries supported for poll() call. 55 56config NET_SOCKETS_CONNECT_TIMEOUT 57 int "Timeout value in milliseconds to CONNECT" 58 default 3000 59 range 0 60000 60 help 61 This variable specifies time in milliseconds after connect() 62 API call will timeout if we have not received SYN-ACK from 63 peer. 64 65config NET_SOCKETS_DNS_TIMEOUT 66 int "Timeout value in milliseconds for DNS queries" 67 default 2000 68 range 1000 300000 69 depends on DNS_RESOLVER 70 help 71 This variable specifies time in milliseconds after which DNS 72 query is considered timeout. Minimum timeout is 1 second and 73 maximum timeout is 5 min. If the value is higher than 74 CONFIG_NET_SOCKETS_DNS_BACKOFF_INTERVAL, then we try multiple 75 times with exponential backoff until the timeout is reached. 76 77config NET_SOCKETS_DNS_BACKOFF_INTERVAL 78 int "Backoff interval for the DNS timeout" 79 default 5000 80 range 1000 300000 81 depends on DNS_RESOLVER 82 help 83 This variable is related to the DNS timeout. If the DNS timeout is 84 smaller than this value, then this value is ignored. If the timeout 85 is larger, then this variable specifies time in milliseconds after 86 which DNS query is re-tried. If there is no reply, the backoff 87 interval is doubled and query is retried. 88 Example: 89 The CONFIG_NET_SOCKETS_DNS_TIMEOUT is set to 17000 (17 secs). 90 This value is 5000 (5 sec). If there is no reply from DNS server 91 within 5 secs, a 2nd query is done with timeout set to 10 sec (5 * 2). 92 If no reply is received, a 3rd query is done after 15 sec (5 + 5 * 2), 93 and the timeout is set to 2 sec so that the total timeout is 17 seconds. 94 95config NET_SOCKET_MAX_SEND_WAIT 96 int "Max time in milliseconds waiting for a send command" 97 default 10000 98 help 99 The maximum time a socket is waiting for a blocked connection before 100 returning an ENOBUFS error. 101 102config NET_SOCKETS_SERVICE 103 bool "Socket service support [EXPERIMENTAL]" 104 select EXPERIMENTAL 105 select EVENTFD 106 help 107 The socket service can monitor multiple sockets and save memory 108 by only having one thread listening socket data. If data is received 109 in the monitored socket, a user supplied work is called. 110 Note that you need to set CONFIG_NET_SOCKETS_POLL_MAX high enough 111 so that enough sockets entries can be serviced. This depends on 112 system needs as multiple services can be activated at the same time 113 depending on network configuration. 114 115config NET_SOCKETS_SERVICE_THREAD_PRIO 116 int "Priority of the socket service dispatcher thread" 117 default NUM_PREEMPT_PRIORITIES 118 depends on NET_SOCKETS_SERVICE 119 help 120 Set the priority of the socket service dispatcher thread. This handler 121 polls the sockets and either places the triggered socket to work queue 122 for asynchronous handlers, or calls the user supplied callback directly 123 for synchronous handlers. 124 The value should be selected carefully because if this thread priority 125 is too high, the work queue handlers might not be able to run if using 126 asynchronous handlers that are called via a work queue. 127 128 Note that >= 0 value means preemptive thread priority, the lowest 129 value is NUM_PREEMPT_PRIORITIES. 130 Highest preemptive thread priority is 0. 131 Lowest cooperative thread priority is -1. 132 Highest cooperative thread priority is -NUM_COOP_PRIORITIES. 133 Make sure the priority is lower than workqueue priority so that 134 we never block the workqueue handler. 135 136config NET_SOCKETS_SERVICE_STACK_SIZE 137 int "Stack size for the thread handling socket services" 138 default 2400 if NET_DHCPV4_SERVER 139 default 1400 if MDNS_RESPONDER 140 default 1200 141 depends on NET_SOCKETS_SERVICE 142 help 143 Set the internal stack size for the thread that polls sockets. 144 145config NET_SOCKETS_SOCKOPT_TLS 146 bool "TCP TLS socket option support" 147 imply TLS_CREDENTIALS 148 select MBEDTLS if NET_NATIVE 149 imply MBEDTLS_TLS_VERSION_1_2 if !NET_L2_OPENTHREAD 150 imply MBEDTLS_KEY_EXCHANGE_RSA_ENABLED if !NET_L2_OPENTHREAD 151 imply MBEDTLS_CIPHER_AES_ENABLED if !NET_L2_OPENTHREAD 152 imply PSA_WANT_KEY_TYPE_AES if !NET_L2_OPENTHREAD && PSA_CRYPTO_CLIENT 153 imply PSA_WANT_ALG_CBC_NO_PADDING if !NET_L2_OPENTHREAD && PSA_CRYPTO_CLIENT 154 help 155 Enable TLS socket option support which automatically establishes 156 a TLS connection to the remote host. 157 158config NET_SOCKETS_TLS_PRIORITY 159 int "Default processing priority for TLS sockets" 160 default 45 161 help 162 Processing priority for TLS sockets. Should be lower than 163 NET_SOCKETS_PRIORITY_DEFAULT in order to be processed correctly. 164 165config NET_SOCKETS_TLS_SET_MAX_FRAGMENT_LENGTH 166 bool "Set Maximum Fragment Length (MFL)" 167 default y 168 help 169 Call mbedtls_ssl_conf_max_frag_len() on created TLS context 170 configuration, so that Maximum Fragment Length (MFL) will be sent to 171 peer using RFC 6066 max_fragment_length extension. 172 173 Maximum Fragment Length (MFL) value is automatically chosen based on 174 MBEDTLS_SSL_OUT_CONTENT_LEN and MBEDTLS_SSL_IN_CONTENT_LEN mbed TLS 175 macros (which are configured by CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN in 176 case of default mbed TLS config). With DTLS, MFL value may be further 177 limited with NET_SOCKETS_DTLS_MAX_FRAGMENT_LENGTH. 178 179 This is mostly useful for TLS client side to tell TLS server what is 180 the maximum supported receive record length. 181 182config NET_SOCKETS_ENABLE_DTLS 183 bool "DTLS socket support" 184 depends on NET_SOCKETS_SOCKOPT_TLS 185 select MBEDTLS_DTLS if NET_NATIVE 186 help 187 Enable DTLS socket support. By default only TLS over TCP is supported. 188 189config NET_SOCKETS_DTLS_TIMEOUT 190 int "Timeout value in milliseconds for DTLS connection" 191 default 5000 192 depends on NET_SOCKETS_ENABLE_DTLS 193 help 194 This variable specifies time in milliseconds after which DTLS 195 connection is considered dead by TLS server and DTLS resources are 196 freed. This is needed to prevent situation when DTLS client shuts down 197 without closing connection gracefully, which can prevent other peers 198 from connecting. Value of 0 indicates no timeout - resources will be 199 freed only when connection is gracefully closed by peer sending TLS 200 notification or socket is closed. 201 202config NET_SOCKETS_DTLS_MAX_FRAGMENT_LENGTH 203 int "Maximum DTLS fragment size in bytes" 204 default 1024 205 range 512 4096 206 depends on NET_SOCKETS_ENABLE_DTLS 207 depends on NET_SOCKETS_TLS_SET_MAX_FRAGMENT_LENGTH 208 help 209 This variable specifies the Maximum Fragment Length (MFL) value to 210 be used with DTLS connection when MBEDTLS_SSL_OUT_CONTENT_LEN and 211 MBEDTLS_SSL_IN_CONTENT_LEN are set to larger values (for TLS). 212 213 With DTLS the MFL should be kept under the network MTU, to avoid 214 IP fragmentation. 215 216config NET_SOCKETS_DTLS_SENDMSG_BUF_SIZE 217 int "Intermediate buffer size for DTLS sendmsg()" 218 depends on NET_SOCKETS_ENABLE_DTLS 219 range 0 $(UINT16_MAX) 220 default 0 221 help 222 Size of the intermediate buffer for DTLS sendmsg() function. The 223 intermediate buffer is needed, as sendmsg() for DGRAM is expected to 224 send all of the data in a single datagram, therefore all data provided 225 in msghdr structure need to be linearized before passing to mbed TLS. 226 The buffer size can be set to 0, in that case data linearizing for 227 DTLS sockets is disabled. In result, sendmsg() will only accept msghdr 228 with a single non-empty iov buffer. 229 230config NET_SOCKETS_TLS_MAX_CONTEXTS 231 int "Maximum number of TLS/DTLS contexts" 232 default 1 233 depends on NET_SOCKETS_SOCKOPT_TLS 234 help 235 "This variable specifies maximum number of TLS/DTLS contexts that can 236 be allocated at the same time." 237 238config NET_SOCKETS_TLS_MAX_CREDENTIALS 239 int "Maximum number of TLS/DTLS credentials per socket" 240 default 4 241 depends on NET_SOCKETS_SOCKOPT_TLS 242 help 243 This variable sets maximum number of TLS/DTLS credentials that can be 244 used with a specific socket. 245 246config NET_SOCKETS_TLS_MAX_CIPHERSUITES 247 int "Maximum number of TLS/DTLS ciphersuites per socket" 248 default 4 249 depends on NET_SOCKETS_SOCKOPT_TLS 250 help 251 This variable sets maximum number of TLS/DTLS ciphersuites that can 252 be used with specific socket, if set explicitly by socket option. 253 By default, all ciphersuites that are available in the system are 254 available to the socket. 255 256config NET_SOCKETS_TLS_MAX_APP_PROTOCOLS 257 int "Maximum number of supported application layer protocols" 258 default 2 259 depends on NET_SOCKETS_SOCKOPT_TLS && MBEDTLS_SSL_ALPN 260 help 261 This variable sets maximum number of supported application layer 262 protocols over TLS/DTLS that can be set explicitly by a socket option. 263 By default, no supported application layer protocol is set. 264 265config NET_SOCKETS_TLS_MAX_CLIENT_SESSION_COUNT 266 int "Maximum number of stored client TLS/DTLS sessions" 267 default 1 268 depends on NET_SOCKETS_SOCKOPT_TLS 269 help 270 This variable specifies maximum number of stored TLS/DTLS sessions, 271 used for TLS/DTLS session resumption. 272 273config NET_SOCKETS_OFFLOAD 274 bool "Offload Socket APIs" 275 help 276 Enables direct offloading of socket operations to dedicated TCP/IP 277 hardware. 278 This feature is intended to save resources by bypassing the Zephyr 279 TCP/IP stack in the case where there is only one network interface 280 required in the system, providing full BSD socket offload capability. 281 As a result, it bypasses any potential IP routing that Zephyr might 282 provide between multiple network interfaces. 283 See NET_OFFLOAD for a more deeply integrated approach which offloads 284 from the net_context() API within the Zephyr IP stack. 285 286config NET_SOCKETS_OFFLOAD_PRIORITY 287 int "Default processing priority for offloaded sockets" 288 default 40 289 help 290 Processing priority for offloaded sockets. 291 292 If native TLS is enabled, lower value than NET_SOCKETS_TLS_PRIORITY 293 means that TLS will be offloaded as well (if supported by offloaded 294 socket implementation). Higher value than NET_SOCKETS_TLS_PRIORITY 295 means that native TLS will be used. 296 297config NET_SOCKETS_OFFLOAD_DISPATCHER 298 bool "Intermediate socket offloading layer" 299 depends on NET_SOCKETS_OFFLOAD 300 help 301 If enabled, an intermediate socket offloading layer is included 302 (called socket dispatcher), allowing to select an offloaded network 303 interface and thus socket implementation with SO_BINDTODEVICE socket 304 option. This can be useful, when multiple offloaded sockets 305 implementations are available in the system, allowing to easily bind 306 a socket to a particular implementation. 307 308config NET_SOCKETS_OFFLOAD_DISPATCHER_CONTEXT_MAX 309 int "Maximum number of dispatcher sockets created" 310 default 4 311 depends on NET_SOCKETS_OFFLOAD_DISPATCHER 312 help 313 Maximum number of dispatcher sockets created at a time. Note, that 314 only sockets that has not been dispatched yet count into the limit. 315 After a proper socket has been created for a given file descriptor, 316 the dispatcher context is released and can be reused. 317 318config NET_SOCKETS_PACKET 319 bool "Packet socket support" 320 select NET_CONNECTION_SOCKETS 321 help 322 This is an initial version of packet socket support (special type 323 raw socket). Packets are passed to and from the device driver 324 without any changes in the packet headers. It's API caller 325 responsibility to provide all the headers (e.g L2, L3 and so on) 326 while sending. While receiving, packets (including all the headers) 327 will be fed to sockets unchanged as provided by the driver. 328 329config NET_SOCKETS_PACKET_DGRAM 330 bool "Packet socket SOCK_DGRAM support" 331 depends on NET_SOCKETS_PACKET 332 default y 333 help 334 For AF_PACKET sockets with SOCK_DGRAM type, the L2 header 335 is removed before the packet is passed to the user. Packets sent 336 through a SOCK_DGRAM packet socket get a suitable L2 header based 337 on the information in the sockaddr_ll destination address before 338 they are queued. 339 340config NET_SOCKETS_CAN 341 bool "Socket CAN support [EXPERIMENTAL]" 342 select NET_L2_CANBUS_RAW 343 select NET_CONNECTION_SOCKETS 344 select EXPERIMENTAL 345 help 346 The value depends on your network needs. 347 348config NET_SOCKETS_CAN_RECEIVERS 349 int "How many simultaneous SocketCAN receivers are allowed" 350 default 1 351 depends on NET_SOCKETS_CAN 352 help 353 The value tells how many sockets can receive data from same 354 Socket-CAN interface. 355 356config NET_SOCKETPAIR 357 bool "Support for socketpair" 358 select PIPES 359 help 360 Communicate over a pair of connected, unnamed UNIX domain sockets. 361 362if NET_SOCKETPAIR 363 364config NET_SOCKETPAIR_BUFFER_SIZE 365 int "Size of the intermediate buffer, in bytes" 366 default 4096 if WIFI_NM_WPA_SUPPLICANT 367 default 64 368 range 1 4096 369 help 370 Buffer size for socketpair(2) 371 372choice 373 prompt "Memory management for socketpair" 374 default NET_SOCKETPAIR_HEAP if HEAP_MEM_POOL_SIZE != 0 375 376config NET_SOCKETPAIR_STATIC 377 bool "Pre-allocate memory statically" 378 379config NET_SOCKETPAIR_HEAP 380 bool "Use heap for allocating socketpairs" 381 382endchoice 383 384if NET_SOCKETPAIR_STATIC 385 386config NET_SOCKETPAIR_MAX 387 int "How many socketpairs to pre-allocate" 388 default 6 if WIFI_NM_WPA_SUPPLICANT 389 default 1 390 391endif # NET_SOCKETPAIR_STATIC 392 393if NET_SOCKETPAIR_HEAP 394 395config HEAP_MEM_POOL_ADD_SIZE_SOCKETPAIR 396 int 397 default 32000 if WIFI_NM_WPA_SUPPLICANT 398 default 256 399 400endif # NET_SOCKETPAIR_HEAP 401 402endif # NET_SOCKETPAIR 403 404config NET_SOCKETS_NET_MGMT 405 bool "Network management socket support [EXPERIMENTAL]" 406 depends on NET_MGMT_EVENT 407 select NET_MGMT_EVENT_INFO 408 select EXPERIMENTAL 409 help 410 Select this if you want to use socket API to get network 411 managements events to your application. 412 Note, that the thread using net_mgmt sockets should have at least 413 the same priority as the thread processing network events (see 414 CONFIG_NET_MGMT_EVENT_WORKER), otherwise in case of event bursts some 415 events may be lost. 416 417config NET_SOCKETS_NET_MGMT_MAX_LISTENERS 418 int "Max number of sockets to listen" 419 default 1 420 depends on NET_SOCKETS_NET_MGMT 421 help 422 This sets the maximum number of net_mgmt sockets that can 423 be set by the socket interface. So if you have two separate 424 sockets that are used for listening events, you need to set 425 this to two. 426 427module = NET_SOCKETS 428module-dep = NET_LOG 429module-str = Log level for BSD sockets compatible API calls 430module-help = Enables logging for sockets code. 431source "subsys/net/Kconfig.template.log_config.net" 432 433config NET_SOCKETS_OBJ_CORE 434 bool "Object core socket support [EXPERIMENTAL]" 435 depends on OBJ_CORE 436 select OBJ_CORE_STATS 437 select EXPERIMENTAL 438 help 439 Select this if you want to use object core with socket API to get 440 network socket information and statistics via object core. 441 The net-shell "net sockets" command will use this functionality 442 to show the socket information. 443 444endif # NET_SOCKETS 445