Commit graph

40 commits

Author SHA1 Message Date
Yong Cong Sin bbe5e1e6eb build: namespace the generated headers with zephyr/
Namespaced the generated headers with `zephyr` to prevent
potential conflict with other headers.

Introduce a temporary Kconfig `LEGACY_GENERATED_INCLUDE_PATH`
that is enabled by default. This allows the developers to
continue the use of the old include paths for the time being
until it is deprecated and eventually removed. The Kconfig will
generate a build-time warning message, similar to the
`CONFIG_TIMER_RANDOM_GENERATOR`.

Updated the includes path of in-tree sources accordingly.

Most of the changes here are scripted, check the PR for more
info.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-28 22:03:55 +02:00
Robert Lubos 53561e3766 net: dns: Fix timeout calculation with DNS retransmissions
With recently introduced DNS retransmission mechanism, a certain bug
could occur when calculating query timeout.

If the time until the final DNS timeout (as indicated by
CONFIG_NET_SOCKETS_DNS_TIMEOUT) was less than 1 millisecond, the actual
millisecond timeout value was rounded down, resulting in 0 ms timeout.
This in order was interpreted as invalid argument by dns_get_addr_info()
function, so in result, instead of reporting query timeout, the function
reported invalid argument error.

Fix this by rounding the millisecond timeout up, instead of down, so
that in any case, if the final timeout is not due, we always provide
non-zero timeout to dns_get_addr_info().

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-03-12 15:13:31 -05:00
Jukka Rissanen 5be84131d6 net: dns: Split long resolving to smaller pieces
If getaddrinfo() is called with a long DNS timeout, then split
the timeout to smaller pieces with exponential backoff. Reason
for this is that if a DNS query is lost, then we do not need
to wait for a long time to find it out.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-06 13:33:50 +01:00
Anas Nashif a08bfeb49c syscall: rename Z_OOPS -> K_OOPS
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 9c1aeb5fd3 syscall: rename z_user_ to k_usermode_
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 56fddd805a syscall: rename z_user_from_copy -> k_usermode_from_copy
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif df9428991a syscall: Z_SYSCALL_MEMORY_ARRAY -> K_SYSCALL_MEMORY_ARRAY
Rename macros and do not use Z_ for internal APIs.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 4e396174ce kernel: move syscall_handler.h to internal include directory
Move the syscall_handler.h header, used internally only to a dedicated
internal folder that should not be used outside of Zephyr.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Stig Bjørlykke 0f71a130ef net: sockets: getaddrinfo: Minor refactoring
Minor refactoring in getaddrinfo() to make the code easier to
read and to make handling IPv4 and IPv6 support more equal.

- Move common wait and error handling code to exec_query()
- Use the same check for CONFIG_NET_IPV4 and CONFIG_NET_IPV6
- Add extra sanity check for family before exec_query()
- Do not set errno when return DNS_EAI_ADDRFAMILY

Fix issue with setting port number for all DNS servers.

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2023-02-21 15:02:35 +01:00
Marco Argiolas d51182d57d net: lib: sockets: support IPv6-only use case with AF_UNSPEC
Setting `hints.ai_family` to `AF_UNSPEC` was causing
`net_getaddrinfo_addr_str()` and in turn `getaddrinfo()` to resolve the
literal SNTP SERVER first into IPv4 and then (if supported) IPv6 addresses.
 This was causing useless waste of time and memory in case IPv4 was not
supported. In addition, in case IPv4 addresses were not supported, other
system components (eg. SNTP) could fail due to the DNS returning IP
addresses with unsupported family type (ie. IPv4).
Now, if address family is not explicitly set to `AF_INET` (ie. IPv4), then
 no attempt is made to resolve SNTP server address into an IPv4 address.

Signed-off-by: Marco Argiolas <marco.argiolas@ftpsolutions.com.au>
2023-01-03 11:03:25 +01:00
Florian Grandel e9a433cd8f net: introduce NET_IP config to efficiently mark conditional code
The code contained several repeated composite IPv4/v6 and UDP/TCP
preprocessor statements that can be simplified by introducing a hidden
NET_IP preprocessor constant that captures what probably is actually
"meant" by this code.

While we were on it we also used the new constant to further isolate
IP-specific code from non-IP specific generics.

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2022-09-05 14:35:17 +00:00
Gerard Marull-Paretas 5113c1418d subsystems: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all subsystems code to
the new prefix <zephyr/...>. Note that the conversion has been scripted,
refer to zephyrproject-rtos#45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-09 12:07:35 +02:00
Robert Lubos 0755a7f057 net: sockets: getaddrinfo: Fix possible crash when callback is delayed
In case system workqueue processing is delayed for any reason, and
resolver callback is executed after getaddrinfo() call already timed
out, the system would crash as the callback makes use of the user data
allocated on the stack within getaddrinfo() function.

Prevent that, by cancelling the DNS request explicitly from the
getaddrinfo() context, therefore preventing the resolver callback
from being executed after the getaddrinfo() call ends.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-01 14:18:33 -06:00
Ievgen Glinchuk 1ce8d6fae4 net: dns: Fix multiple IP DNS resolution
Fixed mutli-IP DNS resolution as previously the same IP address was
used to populate all AI entries and added DNS_RESOLVER_AI_MAX_ENTRIES
config entry to define max number of IP addresses per DNS name to be
handled.

Signed-off-by: Ievgen Glinchuk <john.iceblink@gmail.com>
2021-06-07 23:54:55 -04:00
James Harris b10428163a kernel: sem: add K_SEM_MAX_LIMIT
Currently there is no way to distinguish between a caller
explicitly asking for a semaphore with a limit that
happens to be `UINT_MAX` and a semaphore that just
has a limit "as large as possible".

Add `K_SEM_MAX_LIMIT`, currently defined to `UINT_MAX`, and akin
to `K_FOREVER` versus just passing some very large wait time.

In addition, the `k_sem_*` APIs were type-confused, where
the internal data structure was `uint32_t`, but the APIs took
and returned `unsigned int`. This changes the underlying data
structure to also use `unsigned int`, as changing the APIs
would be a (potentially) breaking change.

These changes are backwards-compatible, but it is strongly suggested
to take a quick scan for `k_sem_init` and `K_SEM_DEFINE` calls with
`UINT_MAX` (or `UINT32_MAX`) and replace them with `K_SEM_MAX_LIMIT`
where appropriate.

Signed-off-by: James Harris <james.harris@intel.com>
2021-03-05 08:13:53 -06:00
Hubert Miś ade40136ea net: resolve literal IP addresses even when DNS is disabled
With this patch the resolver module can resolve literal IPv6
and IPv4 addresses even when DNS client is not presnet in
the system.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2020-12-22 15:44:00 +02:00
Seppo Takalo f684b7c6cd net: getaddrinfo: Fix getaddrinfo() to respect socket type hints
If getaddrinfo() was called with AI_PASSIVE flag in hints,
returned address defaulted to SOCK_STREAM and IPPROTO_TCP.
Fixed so that SOCK_DGRAM leads to correct address type
that can be fed to bind() directly.

Same hard coding was visible when numerical IPv4 address string
was converted to binary. That is also fixed to respect hints now.

Also, added functionality to get IPv6 address, when hints contained
AF_INET6.

Fixes #30686

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2020-12-15 19:22:50 +02:00
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Jukka Rissanen 66d394d97a net: getaddrinfo: Fix timeout data type
Convert to use k_timeout_t

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Robert Lubos bea1093e62 net: sockets: Remove socket offloading interface
Instead of using a custom offloading interface, users can use
`NET_SOCKET_REGISTER` macro to register custom socket API provider. This
solution removes a limitation, that only one offloaded interface can be
registered and that it cannot be used together with native IP stack.

The only exception remainig are DNS releated operations -
`getaddrinfo`/`freeaddrinfo`, which, when offloaded, have to be
registered specifically.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-01-31 11:36:02 -05:00
Andy Ross 346cce31d8 kernel: Port remaining buildable syscalls to new API
These calls are buildable on common sanitycheck platforms, but are not
invoked at runtime in any tests accessible to CI.  The changes are
mostly mechanical, so the risk is low, but this commit is separated
from the main API change to allow for more careful review.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-09-12 11:31:50 +08:00
Jukka Rissanen 06d101e4b1 net: dns: Check family before returning results
If we are returned IPv4 address but the hints says IPv6, then
return error as currently we do not support AI_V4MAPPED addresses.
Same check for IPv6 if we want only IPv4 address.

Fixes #18870

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-09-11 16:17:42 +03:00
Jukka Rissanen 19806a2c1b net: getaddrinfo: Query both IPv4 and IPv6 if family is AF_UNSPEC
We must query both IPv4 and IPv6 addresses if the hints parameter
is NULL i.e., user does not supply hints or if family is set to
AF_UNSPEC.

Fixes #16453

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-20 14:45:43 +03:00
Paul Sokolovsky 8b3db460aa net: getaddrinfo: Parse numeric IPv4 addresses
If a valid numeric IP address is provided as argument, it should
be resolved without contacting DNS server.

Also, implement handling of AI_NUMERICHOST.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-05-29 17:46:56 +08:00
Paul Sokolovsky a2fa8e9c1c net: getaddrinfo: Implement initial handling of host == NULL
If host is NULL and ai_flags are AI_PASSIVE in a call to
getaddrinfo(), need to return "any" address.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-05-16 16:11:10 +03:00
Jukka Rissanen 1897896e97 net: sockets: Make sure that getaddrinfo() cannot hang forever
If for some reason the DNS resolver callback is not called properly
then make sure that semaphore will not block forever.

Fixes #15197

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-04-11 18:01:08 -04:00
Paul Sokolovsky 193d6c60df net: sockets: Implement gai_strerror()
To save binary size, currently just returns textual name of error
code, e.g. EAI_FAIL -> "EAI_FAIL". Based on real usecases, can be
replaced with user-friendly message later. (Current usecase is to
allow/help to elaborate sockets API by proof-of-concept porting
existing socket apps).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-03-15 07:13:15 -05:00
Patrik Flykt 4344e27c26 all: Update reserved function names
Update reserved function names starting with one underscore, replacing
them as follows:
   '_k_' with 'z_'
   '_K_' with 'Z_'
   '_handler_' with 'z_handl_'
   '_Cstart' with 'z_cstart'
   '_Swap' with 'z_swap'

This renaming is done on both global and those static function names
in kernel/include and include/. Other static function names in kernel/
are renamed by removing the leading underscore. Other function names
not starting with any prefix listed above are renamed starting with
a 'z_' or 'Z_' prefix.

Function names starting with two or three leading underscores are not
automatcally renamed since these names will collide with the variants
with two or three leading underscores.

Various generator scripts have also been updated as well as perf,
linker and usb files. These are
   drivers/serial/uart_handlers.c
   include/linker/kobject-text.ld
   kernel/include/syscall_handler.h
   scripts/gen_kobject_list.py
   scripts/gen_syscall_header.py

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-11 13:48:42 -04:00
Jukka Rissanen 86689030e8 net: Clarify logging in networking code
Remove network specific default and max log level setting
and start to use the zephyr logging values for those.

Remove LOG_MODULE_REGISTER() from net_core.h and place the
calls into .c files. This is done in order to avoid weird
compiler errors in some cases and to make the code look similar
as other subsystems.

Fixes #11343
Fixes #11659

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-07 12:00:04 +02:00
Patrik Flykt b97db52de7 misra-c: Add 'U' to unsigned variable assignments in subsys/
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Jukka Rissanen dc29ed0bd9 net: lib: Convert socket library to use log level
Use network log level in BSD socket library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Andrew Boie 18cec245ba net: introduce system calls for zsock socket APIs
Add system calls for the zsock implementations of socket,
close, bind, connect, listen, accept, sendto, recvfrom,
fcntl, poll, inet_pton, and getaddrinfo.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-08-13 07:19:39 -07:00
Paul Sokolovsky 58cc75327b net: getaddrinfo: Make availability depend on CONFIG_DNS_RESOLVER
CONFIG_DNS_RESOLVER is the master switch for DNS resolution support,
for both native and socket APIs. Avoid confusing link errors by
compiling out both dns_resolve_name() and getaddrinfo() if that
option is not enabled.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-07-23 10:04:39 -07:00
Andrew Boie a74137f665 net: getaddrinfo: use memory allocation for res
We no longer use a global array for what is supposed to be
a memory allocation.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-07-19 08:56:21 -07:00
Andrew Boie 1b37602859 net: getaddrinfo: ai_state no longer global
Move this onto the call stack of the getaddrinfo() function,
there's no need for it to be global.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-07-19 08:56:21 -07:00
Stig Bjørlykke 97b83ffc2c net: sockets: Check for errors from dns_get_addr_info
When dns_get_addr_info() returns an error it does not call the
resolve callback, and thus the semaphore will not be given.

This fix will avoid a deadlock situation for various errors.

Added some small tests for getaddrinfo().

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2018-04-03 14:15:43 +03:00
Stig Bjørlykke e652b74860 net: sockets: Do not lookup DNS AAAA entries if IPv6 is disabled
Do not lookup DNS AAAA entries if IPv6 is disabled. The result can not
be used anyway because "struct sockaddr" does not have enough space for
IPv6 address in that case.

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2018-04-03 10:23:06 +03:00
Stig Bjørlykke 5f42a26488 net: sockets: Allow empty service in getaddrinfo()
Make the service parameter optional in getaddrinfo().

The application should be able to use NULL as service when only
interested in the host lookup.

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2018-03-21 10:00:17 +02:00
Paul Sokolovsky ede25c12a3 net: sockets: getaddrinfo() buffer overflow, etc. fixes
The existing implementation assumed DNS resolv callback will be
called just once, but that's not always the case (apparently,
for multi-homes hosts or something). So, apply array bounds
checking (and do pointer arithmetic only after it, as the C
standard otherwise warns of "undefined behavior"). In such a case,
the port number wasn't set in each entry too, so rework how it's
done.

The issues discovered while resolving archive.ubuntu.com.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-02-12 20:17:26 -05:00
Paul Sokolovsky d3c7152528 net: sockets: Implement getaddrinfo()
POSIX-compatible getaddrinfo() call, implemented on top of native
Zephyr DNS resolver.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-09-19 17:39:44 +03:00