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
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_KEY_EXCHANGE_RSA_ENABLED if !NET_L2_OPENTHREAD
120	imply MBEDTLS_CIPHER_AES_ENABLED if !NET_L2_OPENTHREAD
121	imply PSA_WANT_KEY_TYPE_AES if !NET_L2_OPENTHREAD && PSA_CRYPTO_CLIENT
122	imply PSA_WANT_ALG_CBC_NO_PADDING if !NET_L2_OPENTHREAD && PSA_CRYPTO_CLIENT
123	help
124	  Enable TLS socket option support which automatically establishes
125	  a TLS connection to the remote host.
126
127config NET_SOCKETS_TLS_PRIORITY
128	int "Default processing priority for TLS sockets"
129	default 45
130	help
131	  Processing priority for TLS sockets. Should be lower than
132	  NET_SOCKETS_PRIORITY_DEFAULT in order to be processed correctly.
133
134config NET_SOCKETS_TLS_SET_MAX_FRAGMENT_LENGTH
135	bool "Set Maximum Fragment Length (MFL)"
136	default y
137	help
138	  Call mbedtls_ssl_conf_max_frag_len() on created TLS context
139	  configuration, so that Maximum Fragment Length (MFL) will be sent to
140	  peer using RFC 6066 max_fragment_length extension.
141
142	  Maximum Fragment Length (MFL) value is automatically chosen based on
143	  MBEDTLS_SSL_OUT_CONTENT_LEN and MBEDTLS_SSL_IN_CONTENT_LEN mbed TLS
144	  macros (which are configured by CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN in
145	  case of default mbed TLS config). With DTLS, MFL value may be further
146	  limited with NET_SOCKETS_DTLS_MAX_FRAGMENT_LENGTH.
147
148	  This is mostly useful for TLS client side to tell TLS server what is
149	  the maximum supported receive record length.
150
151config NET_SOCKETS_ENABLE_DTLS
152	bool "DTLS socket support"
153	depends on NET_SOCKETS_SOCKOPT_TLS
154	select MBEDTLS_DTLS if NET_NATIVE
155	help
156	  Enable DTLS socket support. By default only TLS over TCP is supported.
157
158config NET_SOCKETS_DTLS_TIMEOUT
159	int "Timeout value in milliseconds for DTLS connection"
160	default 5000
161	depends on NET_SOCKETS_ENABLE_DTLS
162	help
163	  This variable specifies time in milliseconds after which DTLS
164	  connection is considered dead by TLS server and DTLS resources are
165	  freed. This is needed to prevent situation when DTLS client shuts down
166	  without closing connection gracefully, which can prevent other peers
167	  from connecting. Value of 0 indicates no timeout - resources will be
168	  freed only when connection is gracefully closed by peer sending TLS
169	  notification or socket is closed.
170
171config NET_SOCKETS_DTLS_MAX_FRAGMENT_LENGTH
172	int "Maximum DTLS fragment size in bytes"
173	default 1024
174	range 512 4096
175	depends on NET_SOCKETS_ENABLE_DTLS
176	depends on NET_SOCKETS_TLS_SET_MAX_FRAGMENT_LENGTH
177	help
178	  This variable specifies the Maximum Fragment Length (MFL) value to
179	  be used with DTLS connection when MBEDTLS_SSL_OUT_CONTENT_LEN and
180	  MBEDTLS_SSL_IN_CONTENT_LEN are set to larger values (for TLS).
181
182	  With DTLS the MFL should be kept under the network MTU, to avoid
183	  IP fragmentation.
184
185config NET_SOCKETS_DTLS_SENDMSG_BUF_SIZE
186	int "Intermediate buffer size for DTLS sendmsg()"
187	depends on NET_SOCKETS_ENABLE_DTLS
188	range 0 $(UINT16_MAX)
189	default 0
190	help
191	  Size of the intermediate buffer for DTLS sendmsg() function. The
192	  intermediate buffer is needed, as sendmsg() for DGRAM is expected to
193	  send all of the data in a single datagram, therefore all data provided
194	  in msghdr structure need to be linearized before passing to mbed TLS.
195	  The buffer size can be set to 0, in that case data linearizing for
196	  DTLS sockets is disabled. In result, sendmsg() will only accept msghdr
197	  with a single non-empty iov buffer.
198
199config NET_SOCKETS_TLS_MAX_CONTEXTS
200	int "Maximum number of TLS/DTLS contexts"
201	default 1
202	depends on NET_SOCKETS_SOCKOPT_TLS
203	help
204	  "This variable specifies maximum number of TLS/DTLS contexts that can
205	   be allocated at the same time."
206
207config NET_SOCKETS_TLS_MAX_CREDENTIALS
208	int "Maximum number of TLS/DTLS credentials per socket"
209	default 4
210	depends on NET_SOCKETS_SOCKOPT_TLS
211	help
212	  This variable sets maximum number of TLS/DTLS credentials that can be
213	  used with a specific socket.
214
215config NET_SOCKETS_TLS_MAX_CIPHERSUITES
216	int "Maximum number of TLS/DTLS ciphersuites per socket"
217	default 4
218	depends on NET_SOCKETS_SOCKOPT_TLS
219	help
220	  This variable sets maximum number of TLS/DTLS ciphersuites that can
221	  be used with specific socket, if set explicitly by socket option.
222	  By default, all ciphersuites that are available in the system are
223	  available to the socket.
224
225config NET_SOCKETS_TLS_MAX_APP_PROTOCOLS
226	int "Maximum number of supported application layer protocols"
227	default 2
228	depends on NET_SOCKETS_SOCKOPT_TLS && MBEDTLS_SSL_ALPN
229	help
230	  This variable sets maximum number of supported application layer
231	  protocols over TLS/DTLS that can be set explicitly by a socket option.
232	  By default, no supported application layer protocol is set.
233
234config NET_SOCKETS_TLS_MAX_CLIENT_SESSION_COUNT
235	  int "Maximum number of stored client TLS/DTLS sessions"
236	  default 1
237	  depends on NET_SOCKETS_SOCKOPT_TLS
238	  help
239	    This variable specifies maximum number of stored TLS/DTLS sessions,
240	    used for TLS/DTLS session resumption.
241
242config NET_SOCKETS_OFFLOAD
243	bool "Offload Socket APIs"
244	help
245	  Enables direct offloading of socket operations to dedicated TCP/IP
246	  hardware.
247	  This feature is intended to save resources by bypassing the Zephyr
248	  TCP/IP stack in the case where there is only one network interface
249	  required in the system, providing full BSD socket offload capability.
250	  As a result, it bypasses any potential IP routing that Zephyr might
251	  provide between multiple network interfaces.
252	  See NET_OFFLOAD for a more deeply integrated approach which offloads
253	  from the net_context() API within the Zephyr IP stack.
254
255config NET_SOCKETS_OFFLOAD_PRIORITY
256	int "Default processing priority for offloaded sockets"
257	default 40
258	help
259	  Processing priority for offloaded sockets.
260
261	  If native TLS is enabled, lower value than NET_SOCKETS_TLS_PRIORITY
262	  means that TLS will be offloaded as well (if supported by offloaded
263	  socket implementation). Higher value than NET_SOCKETS_TLS_PRIORITY
264	  means that native TLS will be used.
265
266config NET_SOCKETS_OFFLOAD_DISPATCHER
267	bool "Intermediate socket offloading layer"
268	depends on NET_SOCKETS_OFFLOAD
269	help
270	  If enabled, an intermediate socket offloading layer is included
271	  (called socket dispatcher), allowing to select an offloaded network
272	  interface and thus socket implementation with SO_BINDTODEVICE socket
273	  option. This can be useful, when multiple offloaded sockets
274	  implementations are available in the system, allowing to easily bind
275	  a socket to a particular implementation.
276
277config NET_SOCKETS_OFFLOAD_DISPATCHER_CONTEXT_MAX
278	int "Maximum number of dispatcher sockets created"
279	default 4
280	depends on NET_SOCKETS_OFFLOAD_DISPATCHER
281	help
282	  Maximum number of dispatcher sockets created at a time. Note, that
283	  only sockets that has not been dispatched yet count into the limit.
284	  After a proper socket has been created for a given file descriptor,
285	  the dispatcher context is released and can be reused.
286
287config NET_SOCKETS_PACKET
288	bool "Packet socket support"
289	select NET_CONNECTION_SOCKETS
290	help
291	  This is an initial version of packet socket support (special type
292	  raw socket). Packets are passed to and from the device driver
293	  without any changes in the packet headers. It's API caller
294	  responsibility to provide all the headers (e.g L2, L3 and so on)
295	  while sending. While receiving, packets (including all the headers)
296	  will be fed to sockets unchanged as provided by the driver.
297
298config NET_SOCKETS_PACKET_DGRAM
299	bool "Packet socket SOCK_DGRAM support"
300	depends on NET_SOCKETS_PACKET
301	default y
302	help
303	  For AF_PACKET sockets with SOCK_DGRAM type, the L2 header
304	  is removed before the packet is passed to the user.  Packets sent
305	  through a SOCK_DGRAM packet socket get a suitable L2 header based
306	  on the information in the sockaddr_ll destination address before
307	  they are queued.
308
309config NET_SOCKETS_CAN
310	bool "Socket CAN support [EXPERIMENTAL]"
311	select NET_L2_CANBUS_RAW
312	select NET_CONNECTION_SOCKETS
313	select EXPERIMENTAL
314	help
315	  The value depends on your network needs.
316
317config NET_SOCKETS_CAN_RECEIVERS
318	int "How many simultaneous SocketCAN receivers are allowed"
319	default 1
320	depends on NET_SOCKETS_CAN
321	help
322	  The value tells how many sockets can receive data from same
323	  Socket-CAN interface.
324
325config NET_SOCKETPAIR
326	bool "Support for socketpair"
327	select PIPES
328	help
329	  Communicate over a pair of connected, unnamed UNIX domain sockets.
330
331if NET_SOCKETPAIR
332
333config NET_SOCKETPAIR_BUFFER_SIZE
334	int "Size of the intermediate buffer, in bytes"
335	default 1024 if WIFI_NM_WPA_SUPPLICANT
336	default 64
337	range 1 4096
338	help
339	  Buffer size for socketpair(2)
340
341choice
342	prompt "Memory management for socketpair"
343	default NET_SOCKETPAIR_HEAP if KERNEL_MEM_POOL
344
345config NET_SOCKETPAIR_STATIC
346	bool "Pre-allocate memory statically"
347
348config NET_SOCKETPAIR_HEAP
349	bool "Use heap for allocating socketpairs"
350
351endchoice
352
353if NET_SOCKETPAIR_STATIC
354
355config NET_SOCKETPAIR_MAX
356	int "How many socketpairs to pre-allocate"
357	default 6 if WIFI_NM_WPA_SUPPLICANT
358	default 1
359
360endif # NET_SOCKETPAIR_STATIC
361
362if NET_SOCKETPAIR_HEAP
363
364config HEAP_MEM_POOL_ADD_SIZE_SOCKETPAIR
365	int
366	default 13696 if WIFI_NM_HOSTAPD_AP
367	default 9120 if WIFI_NM_WPA_SUPPLICANT
368	default 256
369
370endif # NET_SOCKETPAIR_HEAP
371
372endif # NET_SOCKETPAIR
373
374config NET_SOCKETS_NET_MGMT
375	bool "Network management socket support [EXPERIMENTAL]"
376	depends on NET_MGMT_EVENT
377	select NET_MGMT_EVENT_INFO
378	select EXPERIMENTAL
379	help
380	  Select this if you want to use socket API to get network
381	  managements events to your application.
382	  Note, that the thread using net_mgmt sockets should have at least
383	  the same priority as the thread processing network events (see
384	  CONFIG_NET_MGMT_EVENT_WORKER), otherwise in case of event bursts some
385	  events may be lost.
386
387config NET_SOCKETS_NET_MGMT_MAX_LISTENERS
388	int "Max number of sockets to listen"
389	default 1
390	depends on NET_SOCKETS_NET_MGMT
391	help
392	  This sets the maximum number of net_mgmt sockets that can
393	  be set by the socket interface. So if you have two separate
394	  sockets that are used for listening events, you need to set
395	  this to two.
396
397module = NET_SOCKETS
398module-dep = NET_LOG
399module-str = Log level for BSD sockets compatible API calls
400module-help = Enables logging for sockets code.
401source "subsys/net/Kconfig.template.log_config.net"
402
403config NET_SOCKETS_OBJ_CORE
404	bool "Object core socket support [EXPERIMENTAL]"
405	depends on OBJ_CORE
406	select OBJ_CORE_STATS
407	select EXPERIMENTAL
408	help
409	  Select this if you want to use object core with socket API to get
410	  network socket information and statistics via object core.
411	  The net-shell "net sockets" command will use this functionality
412	  to show the socket information.
413
414endif # NET_SOCKETS
415