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