Commit graph

554 commits

Author SHA1 Message Date
Robert Lubos 370dfe088f net: sockets: Fix socket ctx check in usermode
When `z_get_fd_obj_and_vtable()` function returns NULL (no valid entry
in the FD table for the socket), there is no need for further usermode
checks on the `ctx` pointer, as there is nothing to invalidate in that
case.

Fixes #25990
Fixes #25991

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-06-05 18:34:25 +02:00
Andrew Boie c951d71eba net: check permissions on net contexts
The original sockets system calls used file descriptors which
were actually net_context pointers. For all socket system calls,
any calls from user mode would check if the caller had permission
to use the net context.

This was later changed to not stuff net_context pointers into file
descriptors, but all the permission checking was unintentionally
lost, allowing all threads on the system to
read/write all socket file descriptors in the system at will, with
no way to isolate applications running on the same microcontroller
from each other's network activity.

This patch restores the permission checks on network context objects
for socket system calls that originated from user mode.

The call to z_object_recycle() was never removed from
zsock_socket_internal(); this is again leveraged to grant the
caller who opened the socket permission on the net_context
associated with the returned file descriptor.

To ensure that all socket calls do this checking, all uses of
z_get_fd_obj_and_vtable() have been routed through get_sock_vtable().

Objects have initialization state set and thread permissions
reset to just the caller in common zsock_socket() code.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-06-03 22:33:32 +02:00
Andrew Boie 8ea273b44a net: socketpair: fix user mode access
The socketpair file descriptor context objects are heap allocated
and not drawn from a static pool. Register these as kernel objects
when we create them if user mode is enabled.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-06-03 22:33:32 +02:00
Andrew Boie 9f63a0a0a0 net: lib: remove socket-specific recycle calls
This is just done in common code now.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-06-03 22:33:32 +02:00
Andrew Boie 04bba6772b net: sockets: add API to fetch an fd's ctx object
Zephyr running on MPU devices have a different memory model than
process-oriented OSes like Linux and require a method to set
kernel object permissions on a file descriptor's underlying
context object. Add this, and a test to show that it is working.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-06-03 22:33:32 +02:00
Andrew Boie fed960b94a net: tag net socket objects
Used for permission validation when accessing the associated file
descriptors from user mode.

There often get defined in implementation code, expand the search
to look in drivers/ and subsys/net/.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-06-03 22:33:32 +02:00
Jukka Rissanen a2f0a9effe net: sockets: Fix sendmsg() user mode param checks for aux data
If we are calling sendmsg() without any aux data, then msg_controllen
is 0 and msg_control is NULL. Check these allowed values properly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-06-03 18:33:59 +02:00
Jukka Rissanen d3dde1ad1c net: sockets: Fix sendmsg() user mode param checks for dst address
If we are calling sendmsg() for a connected socket, then msg_namelen
is 0 and msg_name is NULL. Check these allowed values properly.

Also modify unit tests so that we test this scenario.

Fixes #25925

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-06-03 18:33:59 +02:00
Christopher Friedt 2715357e63 net: socket: socketpair: initialize after NULL check
Fixes #25788
Coverity-CID: 210581

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2020-06-03 18:33:19 +02:00
Christopher Friedt 195a536073 net: socket: socketpair: remove dead code
In this, case is_nonblock is false and will_block is true.
Therefore, we *may* block, and furthermore we *expect* to
block. Checking is_nonblock is, in fact, redundant, and
passing K_FOREVER to k_sem_take() is justified.

Fixes #25727
Coverity-CID: 210611

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2020-06-03 18:33:19 +02:00
Jukka Rissanen 35f4ffb186 net: sockets: Add sendmsg() parameter verification
If run in usermode, the sendmsg() parameters were not verified.

Fixes #25702

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-06-02 15:22:47 +02:00
Christopher Friedt 6161ea2542 net: socket: socketpair: mitigate possible race condition
There was a possible race condition between sock_is_nonblock()
and k_sem_take() in spair_read() and spair_write() that was
mitigated.

Also clarified some of the conditional branching in those
functions.

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2020-05-20 10:34:07 +02:00
Christopher Friedt 3bfc765aad tests: socket: socketpair: tests for socketpair(2) syscall
Tests for issue #24366

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2020-05-10 17:46:43 +02:00
Christopher Friedt 09f957c47a net: socket: syscall for socketpair(2)
Working:

* non-blocking reads / writes
* blocking reads / writes
* send(2) / recv(2) / sendto(2) / recvfrom(2) / sendmsg(2)
* select(2)
* poll(2)

Fixes #24366

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2020-05-10 17:46:43 +02:00
Xavier Chapron e5aaf21a73 subsys: Replace printf by printk when applicable
Signed-off-by: Xavier Chapron <xavier.chapron@stimio.fr>
2020-05-09 21:25:33 +02:00
Jukka Rissanen 65a1bebe85 net: Replace NET_WAIT_FOREVER by SYS_FOREVER_MS
As we now have SYS_FOREVER_MS, use that instead of network
specific NET_WAIT_FOREVER.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-05-05 16:29:23 +03:00
Kumar Gala 43a7d26603 drivers: entropy: replace CONFIG_ENTROPY_NAME with DT macro
Replace CONFIG_ENTROPY_NAME with DT_CHOSEN_ZEPHYR_ENTROPY_LABEL.  We now
set zephyr,entropy in the chosen node of the device tree to the entropy
device.

This allows us to remove CONFIG_ENTROPY_NAME from dts_fixup.h.  Also
remove any other stale ENTROPY related defines in dts_fixup.h files.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-13 09:14:21 -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
Jukka Rissanen 9f17c33b60 net: sockets: Refactor because of timeout overhaul
Use k_timeout_t internally, no change to user API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 0a47dc5918 net: sockets: Release net_pkt if error during UDP recv()
If we are receiving UDP packet and if there is some error happening
inside zsock_recv_dgram(), then make sure that the net_pkt received
from recv_q is freed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-03-17 13:13:58 +02:00
Robert Lubos 56566ad497 net: sockets: tls: Fix net_context referencing
TLS sockets did not increase refcount of a net_context running TCP,
which could lead to a crash upon TCP disconnection.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-03-10 14:08:20 +02:00
Jukka Rissanen ba3c5deea9 net: stats: Add RX time statistics for packet sockets
If CONFIG_NET_PKT_RXTIME_STATS is set, then update the received
packet RX time for packet sockets (SOCK_RAW). This was already
working for normal sockets but the statistics update was missing
from SOCK_RAW.

Fixes #22489

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-02-12 17:33:54 +02:00
Inbar Anson Bratspiess 827f6f1714 net: socket: Release fd on failure in accept()
The zsock_accept_ctx() calls z_reserve_fd() on entry but fails
to call z_free_fd() on failure. This will leak the allocated
socket descriptor.

Fixes #22366

Signed-off-by: Inbar Anson Bratspiess <inbar.anson.bratspiess@330plus.net>
2020-02-10 12:33:22 +02:00
Vincent Wan 115949a97f sockets: tls: set TLS_CREDENTIALS when using non-native stack
When is NET_SOCKETS_SOCKOPT_TLS set, it should set TLS_CREDENTIALS
even when NET_NATIVE=n, so that platforms that use socket offloading
can continue to set TLS credentials.

We are now setting this via 'imply' instead of 'select', so that
prj.conf can opt out if necessary.

Fixes #22390

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2020-02-05 18:47:54 -05: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
Robert Lubos 561973060e net: sockets: Extend ioctl poll protocol with offloading feature
Allow to use offloaded `poll` implementation via the existing ioctl poll
control mechanism.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-01-31 11:36:02 -05:00
Robert Lubos 41cfe0b31a sockets: tls: Fix Kconfig mbedTLS dependencies
Sort out mbedTLS dependencies in sockets Kconfig. mbedTLS will now
be enabled when TLS sockets and native network stack are enabled.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-01-31 09:52:21 +02:00
Robert Lubos 9b2fa8a5a7 net: sockets: Rework ioctl poll helpers error handling
Make ioctl handlers of `ZFD_IOCTL_POLL_PREPARE` and
`ZFD_IOCTL_POLL_UPDATE` return an error code instead of setting errno
variable.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-01-22 22:43:54 -05:00
Jukka Rissanen 61249021c0 net: socket: poll() with POLLOUT can return immediately
If we can write to the socket in POLLOUT, then there is no need to
wait.

Note that this is not a full POLLOUT implementation but prevents
the code from waiting even if we could send data out.

Fixes #18867

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-01-03 11:26:46 -08:00
Ravi kumar Veeramally cf9ad748ba net: ipv4: Add IPv4 options length to net pkt
IPv4 header options length will be stored in ipv4_opts_len
in net_pkt structure. Now IPv4 header length will be in
net_pkt ip_hdr_len + ipv4_opts_len. So modified relevant
places of ip header length calculation for IPv4.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-12-16 11:35:24 +02:00
Jukka Rissanen b92a4c5cff net: sockets: tls: Mark accepted socket correctly in accept()
The TCP code expects that we know when the socket has called accept()
in order to continue connection attempt.

Fixes #21335

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-12-16 11:07:06 +02:00
Markus Fuchs 2f982b3bc2 net: tls: Add SSL/TLS secure renegotiation support
Allow enabling SSL/TLS secure renegotiation support when initiated by
peer.

Signed-off-by: Markus Fuchs <markus.fuchs@de.sauter-bc.com>
2019-12-13 13:26:45 +02:00
Kumar Gala 24ae1b1aa7 include: Fix use of <misc/FOO.h> -> <sys/FOO.h>
Fix #include <misc/FOO.h> as misc/FOO.h has been deprecated and
should be #include <sys/FOO.h>.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-12-10 08:39:37 -05:00
Markus Fuchs 1f2727c5fa net: tls: Add sendmsg
Add an implementation for `sendmsg`, so secure sockets can be used
together with the WebSocket module to implement secure WebSockets
("wss").

Fixes #20431

Signed-off-by: Markus Fuchs <markus.fuchs@de.sauter-bc.com>
2019-11-27 12:16:07 -05:00
Ulf Magnusson bd6e04411e kconfig: Clean up header comments and make them consistent
Use this short header style in all Kconfig files:

    # <description>

    # <copyright>
    # <license>

    ...

Also change all <description>s from

    # Kconfig[.extension] - Foo-related options

to just

    # Foo-related options

It's clear enough that it's about Kconfig.

The <description> cleanup was done with this command, along with some
manual cleanup (big letter at the start, etc.)

    git ls-files '*Kconfig*' | \
        xargs sed -i -E '1 s/#\s*Kconfig[\w.-]*\s*-\s*/# /'

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-11-04 17:31:27 -05:00
Ulf Magnusson 975de21858 kconfig: Global whitespace/consistency cleanup
Clean up space errors and use a consistent style throughout the Kconfig
files. This makes reading the Kconfig files more distraction-free, helps
with grepping, and encourages the same style getting copied around
everywhere (meaning another pass hopefully won't be needed).

Go for the most common style:

 - Indent properties with a single tab, including for choices.

   Properties on choices work exactly the same syntactically as
   properties on symbols, so not sure how the no-indentation thing
   happened.

 - Indent help texts with a tab followed by two spaces

 - Put a space between 'config' and the symbol name, not a tab. This
   also helps when grepping for definitions.

 - Do '# A comment' instead of '#A comment'

I tweaked Kconfiglib a bit to find most of the stuff.

Some help texts were reflowed to 79 columns with 'gq' in Vim as well,
though not all, because I was afraid I'd accidentally mess up
formatting.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-11-01 15:53:23 +01:00
David B. Kinder 241044f178 doc: fix misspellings in Kconfig files
Fix misspellings in Kconfig files missed during regular reviews.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2019-10-30 10:24:30 +01:00
Jukka Rissanen d88f25bd76 net: tcp: Handle special case where accepted socket is closed
Handle this corner case with TCP connection closing:

1) Client A connects, it is accepted and can send data to us
2) Client B connects, the application needs to call accept()
   before we will receive any data from client A to the application.
   The app has not yet called accept() at this point (for
   whatever reason).
3) Client B then disconnects and we receive FIN. The connection
   cleanup is a bit tricky as the client is in half-connected state
   meaning that the connection is in established state but the
   accept_q in socket queue contains still data which needs to be
   cleared.
4) Client A then disconnects, all data is sent etc

The above was not working correctly as the system did not handle the
step 3) properly. The client B was accepted in the application even
if the connection was closing.

After this commit, the commit called "net: tcp: Accept connections
only in LISTENING state" and related other commits are no longer
needed and are reverted.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-28 13:58:59 +02:00
Jukka Rissanen c3f0c32304 Revert "net: tls: Set accepting socket to LISTENING state"
This reverts commit d70a854904.

The next commit fixes the original issue so this commit is no
longer needed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-28 13:58:59 +02:00
Jukka Rissanen e73d5a6479 Revert "net: tcp: Accept connections only in LISTENING state"
This reverts commit 1a6f4a6368.

Let's try to fix the backlog handling instead of this.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-28 13:58:59 +02:00
Jukka Rissanen f6f4467098 net: socks: Prefer setsockopt() API instead of legacy proxy api
Applications should use setsockopt() to setup the SOCKS5 proxy,
so the old API file, which is using net_context directly, is
moved SOCKS5 directory.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-25 13:56:01 +03:00
Jukka Rissanen d70a854904 net: tls: Set accepting socket to LISTENING state
This is related to commit 1a6f4a6368 ("net: tcp: Accept
connections only in LISTENING state") which made the system
to only accept new connections if the application had called
accept(). Unfortunately the TLS accept was not fixed by that
commit so we were in wrong state when accepting TLS sockets.
This commit fixes that issue.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-15 23:30:34 +03:00
Jukka Rissanen 8d3b74ab61 net: Add statistics how long packets have spent in RX path
Calculate how long on average net_pkt has spent on its way from
network device driver to the application. The data is only
calculated for UDP and TCP network packets.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-14 16:34:48 +03:00
Jukka Rissanen e98f5d37f5 net: sockets: Store socket private data into its own variable
Do not try to re-use net_context.user_data field as in many places
(like in accept) it is expected to contain pointer to net_context.
Storing the socket flags will corrupt the value. To simplify and
make things less error prone, use socket specific field in net_context
to store the socket flags.

Fixes #19191

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-09-18 23:47:36 +03:00
Jukka Rissanen c755be0ee7 net: socket: The socket flags need to use uintptr_t
The socket flags are stored in void* so we need to use uintptr_t
instead of u32_t when manipulating the flag variable.

Fixes #19181

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-09-16 14:41:18 -05:00
Jukka Rissanen 0b1034aee2 net: socket: Support non-blocking accept()
If socket is marked non-blocking, then accept() will return immediately
if there is no one connecting.

Fixes #19103

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-09-13 10:41:33 +03:00
Jukka Rissanen 2f8f5fdd33 net: socket: Set default protocol if proto == 0
If proto field in socket() call is set to 0, then we should have
a sane default for it that depends on the type of the socket.

Fixes #18873

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-09-12 11:22:45 +03:00
Andy Ross 643701aaf8 kernel: syscalls: Whitespace fixups
The semi-automated API changes weren't checkpatch aware.  Fix up
whitespace warnings that snuck into the previous patches.  Really this
should be squashed, but that's somewhat difficult given the structure
of the series.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-09-12 11:31:50 +08: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
Andy Ross 6564974bae userspace: Support for split 64 bit arguments
System call arguments, at the arch layer, are single words.  So
passing wider values requires splitting them into two registers at
call time.  This gets even more complicated for values (e.g
k_timeout_t) that may have different sizes depending on configuration.
This patch adds a feature to gen_syscalls.py to detect functions with
wide arguments and automatically generates code to split/unsplit them.

Unfortunately the current scheme of Z_SYSCALL_DECLARE_* macros won't
work with functions like this, because for N arguments (our current
maximum N is 10) there are 2^N possible configurations of argument
widths.  So this generates the complete functions for each handler and
wrapper, effectively doing in python what was originally done in the
preprocessor.

Another complexity is that traditional the z_hdlr_*() function for a
system call has taken the raw list of word arguments, which does not
work when some of those arguments must be 64 bit types.  So instead of
using a single Z_SYSCALL_HANDLER macro, this splits the job of
z_hdlr_*() into two steps: An automatically-generated unmarshalling
function, z_mrsh_*(), which then calls a user-supplied verification
function z_vrfy_*().  The verification function is typesafe, and is a
simple C function with exactly the same argument and return signature
as the syscall impl function.  It is also not responsible for
validating the pointers to the extra parameter array or a wide return
value, that code gets automatically generated.

This commit includes new vrfy/msrh handling for all syscalls invoked
during CI runs.  Future commits will port the less testable code.

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
Ravi kumar Veeramally 1a6f4a6368 net: tcp: Accept connections only in LISTENING state
Issue noticed with following scenario.

 1) TCP server is listening for connections but will handle
    only one connection at a time (e.g. echo-server sample)
 2) Client A connects, and the connection is accepted.
 3) Client B connects, instead of denying a connection,
    it is "auto" accepted (this is the actual bug) even
    if the application has not called accept().
 4) After the connection A is closed, the connection B
    gets accepted by application but now the closed
    connection A will cause confusion in the net-stack
 5) This confusion can cause memory leak or double free
    in the TCP core.

It is not easy to trigger this issue because it depends
on timing of the connections A & B.

Fixes: #18308

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-09-10 22:57:48 +03:00
Jukka Rissanen 2262c48d37 net: socket: Return 0 in recvfrom() if buffer size is 0
If user has buffer with size 0, then return 0.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-09-08 17:13:07 -04:00
Tomasz Bursztyka 9124bcccc8 net: socket_mgmt: Fix for coverity CID 203397
Let's use IS_ENABLED() instead of the #ifdef to get clearer code. ret
variable is used only at one place, no need for the ARG_UNUSED()

Coverity-CID: 203397
Fixes #18419

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-08-19 16:27:23 +02:00
Tomasz Bursztyka 7f527f616e net: socket_mgmt: Fix for coverity CID 203468
Let's use IS_ENABLED() instead of the #ifdef to get clearer code. ret
variable is used only at one place, no need for the ARG_UNUSED()

Coverity-CID: 203468
Fixes #18420

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-08-19 16:27:23 +02:00
Alexander Wachter c8c5f3bbf3 net: canbus: Rename canbus to canbus_raw
Rename the socket_can implementation from CANBUS to CANBUS_RAW.
This is a preperation for 6LoCAN which is a CANBUS L2 for IPv6.

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
2019-08-08 13:25:01 +03:00
Jukka Rissanen abdd58ce3c net: sockets: Do not call NULL socket callback function
Before calling socket callback function, make sure the callback
function exists so that we do not get NULL pointer reference.

Fixes #18021

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-08-06 19:27:48 +03:00
Ravi kumar Veeramally 39ed77e438 net: socks: Make SOCKS5 implementation transparent
Current SOCKS5 implementation is above socket level and every
higher layer protocol or application level needs to have
SOCKS5 related changes. This solution is based on socket
setsockopt(). Application caller has to set proxy details
through setsockopt() and socket:connect() will take care
creating connection.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-08-05 13:26:11 +03:00
Ravi kumar Veeramally c8fa169294 net: Add support for SOCKS5 socket option
The SO_SOCKS5 socket option can be used by the application to
set the SOCKS5 proxy details. These details will be used when
connecting to peer.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-08-05 13:26:11 +03:00
Jukka Rissanen 0435dce697 net: Add support for TXTIME socket option
The SO_TXTIME socket option can be used by the application to
tell the network device driver the exact moment when the
network packet should be sent.

This feature is also implemented in Linux.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-24 10:17:16 +03:00
Jukka Rissanen ec2e2f43d8 net: sockets: Add sendmsg() API
Add BSD socket sendmsg() API that can be used to send data to peer
and also pass ancillary data to lower level of the network stack.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-24 10:17:16 +03:00
Jukka Rissanen 1a9e09c85c net: socket: userspace: Copy user specified value in getsockopt()
User could have set something to optval in getsockopt() and we
need to copy the data to kernel optval so that the socket family
code can use the value for something.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-23 22:31:14 +03:00
Nicolas Pitre d19a5f9119 net: socket: mgmt: use uintptr_t for the nm_pid field
This may contain a pointer so make sure it is sufficiently wide
on 64-bit targets.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-05 10:06:23 -04:00
Nicolas Pitre 66045b5db0 net/socket: use the iterable section object constructor/iterator
The handcrafted allocation falls victim of misaligned structures due to
toolchain padding which crashes the socket test code on 64-bit targets.
Let's move it to the iterable section utility where those issues are
already taken care of.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-04 11:36:52 +03:00
Jukka Rissanen 2f95f4afe7 net: sockets: Initialize IP socket addresses in getsockname()
Make sure the IPv4 and IPv6 socket addresses are initialized before
copying them. This avoids uninitialized memory access.

Coverity-CID: 199436
Fixes #17202

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-03 15:26:59 +03:00
Jukka Rissanen eef7625660 net: socket: Add SO_TIMESTAMPING socket option
This can be used to activate the network packet statistics
collection. Note that we do not have resources to calculate
each network packet transit times but we collect average times
instead.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-03 09:42:45 +03:00
Jukka Rissanen 7c65db4e31 net: socket: mgmt: Add setsockopt() and getsockopt() support
Currently only setting and getting of Ethernet Qav options are
supported via this interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 13:50:08 -07:00
Jukka Rissanen 6f32f17cda net: socket: Add userspace support to getsockopt()
Allow userspace application to call getsockopt() without crashing.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 13:50:08 -07:00
Jukka Rissanen ee849826e3 net: socket: Add userspace support to setsockopt()
Allow userspace application to call setsockopt() without crashing.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 13:50:08 -07:00
Jukka Rissanen c0d6831bc0 net: sockets: mgmt: Add AF_NET_MGMT address family support
Allow application to listen network management events using
BSD socket API. Application needs to create the socket using
AF_NET_MGMT address family. At this point we only support
receiving network management events that the network subsystem
is sending.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 13:50:08 -07:00
Ravi kumar Veeramally 84b191edd2 net: sockets: Add timeout to socket connect call
Current socket connect call implementation always takes
K_FOREVER timeout value, which blocks TCP connections
in case failure. TCP connections waits until it receives
SYN ACK. If there is no SYC ACK means, connect call is
blocked forever.

Added a Kconfig option to define timeout value. Default
value is 3000 milliseconds. User can modify it.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-07-01 10:34:15 +03:00
Anas Nashif a2fd7d70ec cleanup: include/: move misc/util.h to sys/util.h
move misc/util.h to sys/util.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 6ecadb03ab cleanup: include/: move misc/math_extras.h to sys/math_extras.h
move misc/math_extras.h to sys/math_extras.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 8be9f5de03 cleanup: include/: move misc/fdtable.h to sys/fdtable.h
move misc/fdtable.h to sys/fdtable.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 969f8f1c68 cleanup: include/: move entropy.h to drivers/entropy.h
move entropy.h to drivers/entropy.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04: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
Jukka Rissanen 06b500b6bd net: sockets: can: Close the socket cleanly
If the socket is closed, then do CAN detach if that is needed.
This way the CAN interrupts are not received if there are no
CAN sockets listening the data.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-18 17:58:00 +03:00
Jukka Rissanen 6621491014 net: sockets: can: Add dispatcher
We need to dispatch the received CAN frame if there are multiple
sockets interested in the same CAN-IDs.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-18 17:58:00 +03:00
Jukka Rissanen c3bb0a6af9 net: socket: Add SO_PRIORITY support to setsockopt
Allow user to set the socket priority using setsockopt() call.
The priority value is used to order the networking queues so
that packets with a higher priority may be processed first.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-09 12:54:05 +03:00
Paul Sokolovsky 0fb8a917e6 net: sockets: Make NET_SOCKETS_POSIX_NAMES depend on !POSIX_API
These options are mutually exclusive, or more specifically,
CONFIG_POSIX_API has wider scope and supersedes
CONFIG_NET_SOCKETS_POSIX_NAMES. Implementation-wise, the two
options should not be defined at the same time, as that may
lead to declaration conflicts.

Fixes: #16141

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-06-05 07:51:01 -04:00
Robert Lubos 87462df3ef net: sockets: Remove TI conditional from offloaded fcntl implementation
Offloaded `fcntl` implementation should be available for all offloaded
implementations, not specific for TI. `socket_offload.c` is already
conditionally compiled based on `CONFIG_NET_SOCKETS_OFFLOAD` option, so
there should not be conflicts for non-offloaded interfaces.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-05-30 18:41:31 -04: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
Tomasz Gorochowik c0b30355fb net: sockets: implement getsockname function
From POSIX.1-2017:

The getsockname() function shall retrieve the locally-bound name of the
specified socket, store this address in the sockaddr structure pointed
to by the address argument, and store the length of this address in the
object pointed to by the address_len argument.

The address_len argument points to a socklen_t object which on input
specifies the length of the supplied sockaddr structure, and on output
specifies the length of the stored address. If the actual length of the
address is greater than the length of the supplied sockaddr structure,
the stored address shall be truncated.

If the socket has not been bound to a local name, the value stored in
the object pointed to by address is unspecified.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2019-05-17 22:49:32 +03: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
Jakob Olesen c8708d9bf3 misc: Replace uses of __builtin_*_overflow() with <misc/math_extras.h>.
Use the new math_extras functions instead of calling builtins directly.

Change a few local variables to size_t after checking that all uses of
the variable actually expects a size_t.

Signed-off-by: Jakob Olesen <jolesen@fb.com>
2019-05-14 19:53:30 -05:00
Sebastian Bøe c2c8c849b6 cmake: Don't have users call zephyr_link_interface on mbedTLS
Libraries that use mbedTLS have been invoking
zephyr_link_interface(mbedTLS). It is not clear what the intent of
this code has been, but it is redundant with the mbedTLS build
scripts, so it can be safely removed.

In addition to being redundant, it causes problems as it introduces an
ordering dependency, with this code mbedTLS must be declared before
users of mbedTLS are declared. Since this code is redundant, this
ordering dependency is also unnecessary.

This code is believed to have been added early on by accident and
copied through cargo-cult programming since.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-05-11 08:35:26 -04:00
Jukka Rissanen e082d98911 net: sockets: can: Register handler for AF_CAN
Use the automatic registration of AF_CAN type sockets.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-10 22:43:27 +03:00
Jukka Rissanen b3cd478a5f net: sockets: packet: Register handler for AF_PACKET
Use the automatic registration of AF_PACKET type sockets.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-10 22:43:27 +03:00
Jukka Rissanen 61f4597d64 net: sockets: tls: Register handler for TLS sockets
Use the automatic registration of TLS socket.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-10 22:43:27 +03:00
Jukka Rissanen 89bf1578d9 net: sockets: Add a way to register a socket family handler
Allow automatic handling of registered socket families.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-10 22:43:27 +03:00
Jukka Rissanen 9a6bbbfb69 net: Check device driver API pointer
It is possible that the device driver API pointer is null.
For example if the device driver returns an error, the device
code will make the API pointer NULL so that the API would not
be used. This can cause errors in networking code where we
typically do not check the NULL value.

Fixes #15003

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-07 15:41:15 +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
Anas Nashif 3ae52624ff license: cleanup: add SPDX Apache-2.0 license identifier
Update the files which contain no license information with the
'Apache-2.0' SPDX license identifier.  Many source files in the tree are
missing licensing information, which makes it harder for compliance
tools to determine the correct license.

By default all files without license information are under the default
license of Zephyr, which is Apache version 2.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-07 08:45:22 -04:00
Andrew Boie ce6b80470d net: add missing syscall for gethostname()
We need all the socket APIs to work from user mode.
tests/net/socket/misc now runs in userspace.

Fixes: #15227

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-04-06 14:30:42 -04:00
Patrik Flykt 4aa48833d8 subsystems: Rename reserved function names
Rename reserved function names in the subsys/ subdirectory except
for static _mod_pub_set and _mod_unbind functions in bluetooth mesh
cfg_srv.c which clash with the similarly named global functions.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-03 17:31:00 -04:00
Patrik Flykt 24d71431e9 all: Add 'U' suffix when using unsigned variables
Add a 'U' suffix to values when computing and comparing against
unsigned variables.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Tedd Ho-Jeong An f5c4e369ea net: sockets: Update setsockopt to handle IPV6_V6ONLY
This patch adds a routine that handles IPV6_V6ONLY option in setsockopt
function.

Fixes #14657

Signed-off-by: Tedd Ho-Jeong An <tedd.an@intel.com>
2019-03-26 13:23:49 -04:00
Vincent Wan 3609e261bb net: sockets: move fcntl back to socket_offload.c
We are reverting the changes in commit
55b3f05932 given build errors are seen
when fcntl.h is included, as it declares fcntl() as a non-static
function. The same function cannot be declared as both static and
non-static.

Instead, we avoid redefining fcntl() in lib/os/fdtable.c specifically
for case of the SimpleLink family, til we have support for the new
socket_op_vtable.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2019-03-20 11:36:18 -05:00
Tomasz Bursztyka 03bfc5dd0f net/context: Remove token parameter from net_context_send/sendto
And also to the relevant callbacks.

That parameter is not used anywhere so it is useless.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka a25f054cbd net/pkt: Remove _new suffix to net_pkt_read functions
Suffix is now useless, as these functions are now the only ones.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka f8a091104e net/pkt: Remove _new suffix to net_pkt_get_data_new function
Now that legacy - and unrelated - function named net_pkt_get_data has
been removed, we can rename net_pkt_get_data_new relevantly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka 172fe5a87b net/context: Remove _new suffix on net_context_send/sendto functions
Now that legacy functions are removew, let's rename the new functions by
removing the _new suffix.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Paul Sokolovsky 4e097b4d54 net: sockets: recv_stream: Check that the underlying net_context active
It may be closed by the stack behind our back (something which needs
to be fixed).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-03-18 10:49:25 -05:00
Paul Sokolovsky 5499f38e7a net: socket: Increment TCP context refcount on socket(), accept()
TCP context is effectively owned by both application and the stack:
stack may detect that peer closed/aborted connection, but it must
not dispose of the context behind the application back. Likewise,
when application "closes" context, it's not disposed of immediately,
there's yet closing handshake for stack to perform.

This effectively means that TCP contexts have refcount of 2 when
they're created. Without this change, following situation is
possible: peer opens connection, an app get a context (or socket)
via accept, peer sends data, closes connection. An app still holds
a reference to connection, but stack may dispose of context, and
even reuse it for a new connection. Then application holds a reference
to either free, or completely different context.

This situation was very clearly and 100% reproducible when making
Zephyr port of open62541 library, which works in async manner using
select().

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-03-18 10:49:25 -05: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
Jukka Rissanen 5a9fa72ef2 net: socket: can: Convert between can_frame and zcan_frame
The socket-can code expects to have "struct can_frame" from
application when it calls send(). We then have to convert to
"struct zcan_frame" as that is what the driver expects.

Same thing when receiving data. We just convert to
"struct can_frame" and pass that to application.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-03-13 05:58:30 -05:00
Jukka Rissanen fc36d56aca drivers: can: socket: Use proper filter when setsockopt is called
Check that the received filter is can_filter type when setsockopt()
is called.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-03-13 05:58:30 -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
Anas Nashif 4fcbb6bdf2 Revert "net: sockets: recv_stream: Check that the underlying net_context active"
This reverts commit 8cb5d083cb53627964ed72fb9fa3fb7a5219739f.

This was breaking tests on master due to missing dependency that is
still being reviewed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-03-06 17:40:52 -05:00
Paul Sokolovsky 41864915c2 net: sockets: recv_stream: Check that the underlying net_context active
It may be closed by the stack behind our back (something which needs
to be fixed).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-03-06 15:56:57 -05:00
Vincent Wan 55b3f05932 include: net: Move fcntl implementation into socket_offload.h
This is done to conform with how the rest of the socket APIs are
implemented during socket offload. Otherwise link error would
result due to the symbol being redefined in lib/os/fdtable.c.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2019-03-05 11:37:10 -05:00
Paul Sokolovsky a3cffb8e63 net: sockets: Trace socket/accept/close operations for debug logging
This is required to debug almost any issue with sockets.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-03-05 08:28:25 -05:00
Paul Sokolovsky 5a44011e3b net: sockets: Add dummy impl for SO_REUSEADDR and TCP_NODELAY sockopts
These options are oftentimes used when implementing servers, and
thus required to port existing socket apps. These options are also
safe to just ignore, e.g. SO_REUSEADDR has effect only for repeated
recreation of server socket (not an expected usecase for a Zephyr
app), while TCP_NODELAY is effectively the default for Zephyr, as we
don't implement TCP buffering (aka Nagle algorithm).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-03-01 09:52:15 +01:00
Robert Lubos 10e43e12ed net: sockets: tls: Add missing poll descriptor increment
Poll descriptor was not incremented in poll update function in case it
was reported as not ready. In result, poll could end up processing the
same poll descriptor for every fd requested to monitor.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-02-26 02:07:11 +01:00
Robert Lubos 6175d1bd8e net: sockets: tls: Detect EOF in poll prepare
Rework detection of EOF on a socket, so that it can be detected in a
poll prepare that socket is in in a EOF state and poll can return
immediately.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-02-26 02:07:11 +01:00
Robert Lubos f1920fff46 net: sockets: tls: Block DTLS client in poll until handshake is complete
When DTLS client was added to `poll` before/during the handshake, it
could throw errors and in some circumstances (when polling thread was
cooperative and had higher or equal priority to the handshake thread)
could lead to a deadlock in the application.

Prevent that, by blocking on handshake semaphore instead of fifo. Poll
will start using fifo for data poll only after handshake is complete.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-02-23 07:42:38 -05:00
Robert Lubos 64ca76f327 net: sockets: tls: Use semaphore to notify that handshake is complete
Instead of simple bool value, use a semaphore to notify that TLS
handshake is complete. This way, we can monitor this value with k_poll.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-02-23 07:42:38 -05:00
Paul Sokolovsky 87b5eb9fce net: sockets: Implement getnameinfo()
This function is the opposite of getaddrinfo(), i.e. converts
struct sockaddr into a textual address. Normally (or more
specifically, based on the flags) it would perform reverse DNS
lookup, but current implementation implements only subset of
functionality, by converting to numeric textual address.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-02-19 17:34:57 -05:00
Paul Sokolovsky f7169ec216 net: sockets: Fix logging message
A debug message told "Set EOF flag on pkt %p", but actually printed
net_context instead of net_pkt.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-02-19 17:33:44 -05:00
Carlos Stuart 75f77db432 include: misc: util.h: Rename min/max to MIN/MAX
There are issues using lowercase min and max macros when compiling a C++
application with a third-party toolchain such as GNU ARM Embedded when
using some STL headers i.e. <chrono>.

This is because there are actual C++ functions called min and max
defined in some of the STL headers and these macros interfere with them.
By changing the macros to UPPERCASE, which is consistent with almost all
other pre-processor macros this naming conflict is avoided.

All files that use these macros have been updated.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-14 22:16:03 -05:00
Paul Sokolovsky 3b73511153 net: sockets: Add dummy shutdown() implementation.
shutdown() itself is described as just marking RX or TX path of a
socket as not available. For the first approximation, we implement
it just as a dummy function, to allow build existing POSIX
applications which use it.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-02-13 07:00:51 -06:00
Tomasz Bursztyka 34fe5545c9 net/socket: Use the new net_pkt API to read TCP payload
There is no need for appdata pointer: net_pkt's cursor is already at the
right position, i.e. the beginning of the payload right after all IP/TCP
headers.

Also, when reading the actual data, let's use net_pkt_read_new()
relevantly instead of going through the buffer by ourselves.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 6331f052b7 net/socket: Use the new net_pkt API to read UDP payload
There is no need for appdata pointer: net_pkt's cursor is already at the
right position, i.e. the beginning of the payload right after all IP/UDP
headers.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 024a7e0502 net/sockets: Adapt net_pkt_get_src_addr to new net_pkt API
This function is only used in sockets, thus making it a private function
of socket library and renaming it relevantly.

Note that sockets should be reviewed at some point to avoid using such
function: zsock_received_cb() already get the ip header and the protocol
header, so it could grab the src addr/port from there. It would be way
more optimized to do so, since net_pkt_get_src_addr is costly as it
parses all over again the ip/protocol headers.

utils unit test is updated and the test of the former
net_pkt_get_src_addr/net_pkt_get_dst_addr are removed.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Paul Sokolovsky a46aadeff2 net: sockets: Properly handle EOF condition for poll()
If a socket is in EOF, it's readable (so client can read() it, get 0
in return, figure it's in EOF, and close it). Without this change, we
had peer-closed sockets leaked (ignore) by poll() and select().

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-02-12 09:45:04 -05:00
Jukka Rissanen 7f784153c1 net: socket: Dispatch all AF_CAN handling to sockets_can.c
The code was unnecessarily checking protocol for AF_CAN.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-08 16:01:49 +02:00
Jukka Rissanen c1d5cc26c1 net: sockets: Remove extra "default n" setting from config
No need to say "default n" as that is the implicit default.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-08 16:01:49 +02:00
Andrei Gansari fea80ca5c1 net: subsys: fixed comments CONFIG_NET*
Fixed stranded comments:
CONFIG_NET_TLS_DEBUG removed
CONFIG_NET_LLDP_MSG_TX_INTERVAL -> CONFIG_NET_LLDP_TX_INTERVAL

Signed-off-by: Andrei Gansari <andrei.gansari@nxp.com>
2019-02-08 13:57:55 +02:00
Paul Sokolovsky 5bb2c7022e net: sockets: Add gethostname() call
Implemented via Zephyr's net_hostname_get(). As support for that call
is configurable and by default off, while many POSIX applications
assume that hostname is always available, we need a default value
in case CONFIG_NET_HOSTNAME_ENABLE is "n". Initial version of this
patch added that on the level of gethostname() call, but of was
suggested to move that down to net_hostname_get() instead.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-02-08 10:39:30 +02:00
Jukka Rissanen df7162331f net: socket: can: Add getsockopt() and setsockopt() support
It is possible to set the filter in user application and that
information is passed to the CANBUS device driver.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-07 18:08:27 +02:00
Jukka Rissanen f610db9453 net: l2: Add CANBUS L2 layer
This is basically a dummy layer that just passes data through.
It is needed so that we can create CANBUS type network interface
to the system.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-07 18:08:27 +02:00
Jukka Rissanen 49cea0a199 net: socket: can: Add socket CAN support
This allows user to create a CAN socket and to read/write data
from it. From the user point of view, the BSD socket CAN support
works same way as in Linux.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-07 18:08:27 +02:00
Ravi kumar Veeramally a9a2b3ea91 net: sockets: Add socket api to support AF_PACKET
This commit adds packet socket support to socket api.
This version supports basic packet socket features.
Protocol family is AF_PACKET, type of socket is
SOCK_RAW and proto type is ETH_P_ALL. The user will
receive every packet (with L2 header) on the wire.
For TX, the subsystem expects that the user has set
all the protocol headers (L2 and L3) properly.

Networking subsystem doesn't verify or alter the headers while
sending or receiving the packets. This version supports packet
socket over Etherent only. Also combination of other family
and protocols doesn't work (i.e. Application can not open
packet-socket and non packet-socket together).

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-02-07 14:43:30 +02:00
Tomasz Bursztyka 4b78a251d7 net/context: Make recv_cb providing the ip and protocol headers
If status is 0, both ip_hdr and proto_hdr will own a pointer to the
relevant IP and Protocol headers. In order to know which of ipv4/ipv6
and udp/tcp one will need to use respectively net_pkt_family(pkt) and
net_context_get_ip_proto(context).

Having access to those headers directly, many callbacks will not need
to parse the packet again no get the src/dst addresses or the src/dst
ports. This will be change after this commit.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 083470a14a net/sockets: Use the new send/sendto from net_context
It's now up to net_context to build the net_pkt and send it.
This will become the default.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Jukka Rissanen d1162600e9 net: app: Remove net-app API files
The net-app API is removed. Users should use the BSD socket API
for application development.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-01 12:29:21 +02:00
Paul Sokolovsky 3e6d7d382a net: sockets_select: Fix build without CONFIG_NET_SOCKETS_POSIX_NAMES
The implementation code itself should not rely on plain POSIX names
and use zsock_ and ZSOCK_ prefixed versions of symbols.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-01-29 09:19:54 +02:00
Paul Sokolovsky 9c91094ff7 net: sockets: select: Get rid of timeval in favor of zsock_timeval
struct timeval is per POSIX defined in sys/time.h, but that also
allowed to pull sys/select.h (and indeed, it does with native_posix),
which then starts to conflict with out select implementation (if
NET_SOCKETS_POSIX_NAMES is defined, and many samples/tests have it).

So, for now follow the existing route of duplicating all definitions
needed by our code in namespaced manner. Things like struct timeval
usage will need to be revisited later, when we'll want socket
subsystem to work with POSIX subsystem, but that's a separate deep
matter.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-01-24 17:14:43 +02:00
Paul Sokolovsky 3a0a9944c0 net: sockets: Implement select() call.
It's implemented on top of poll() anyway, and the current
implementation of fd_set uses array of fd's underlyingly, which
leads to O(n) complexity for FD_SET() and friends.

The purpose of select() implementation is to allow to perform
proof-of-concept port of 3rd-party code to Zephyr quickly. For
efficiency, poll() should be used instead.

Fixes: #11333

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-01-24 17:14:43 +02:00
Robert Lubos 0b93c68f79 net: sockets: Add fcntl to socket offloading API
Offload fcntl calls through socket offloading API.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-01-18 17:25:01 +02:00
Paul Sokolovsky c885cb533e net: buf: linearize: Get rid of useless memset()
net_buf_linearize() used to clear the contents of output buffer,
just to fill it with data as the next step. The only effect that
would have is if less data was written to the output buffer. But
it's not reliable for a caller to rely on net_buf_linearize() for
that, instead callers should take care to handle any conditions
like that themselves. For example, a caller which wants to process
the data as zero-terminated string, must reserve a byte for it
in the output buffer explicitly (and set it to zero).

The only in-tree user which relied on clearing output buffer was
wncm14a2a.c. But either had buffer sizes calculated very precisely
to always accommodate extra trailing zero byte (without providing
code comments about this), or arguably could suffer from buffer
overruns (at least if data received from a modem was invalid and
filled up all destination buffer, leaving no space for trailing
zero).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-01-12 15:24:29 -06:00
Robert Lubos e8620e2cca ext: mbedtls: Unify mbedTLS Kconfig prefixes
Currently there is a mixed approach in prefixes from mbedTLS
configuration (MBEDTLS_ and TLS_). The latter was used in generic config
file and could bring up confusion that it can only be used with TLS
subsystem. Hence unify the approach to MBEDTLS_ prefix to avoid such
confusion.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-12-17 11:27:02 +01:00
Paul Sokolovsky 8a65f68a48 net: sockets_tls: Typo fix in comment
s/DLTS/DTLS.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-12-14 13:21:31 +02:00
Paul Sokolovsky 13b38ed686 lib: fdtable: Change ioctl vmethod signature to take va_list
As extend fdtable usage to more cases, there regularly arises a need
to forward ioctl/fcntl arguments to another ioctl vmethod, which is
complicated because it defined as taking variadic arguments. The only
portable solution is to convert variadic arguments to va_list at the
first point of entry from client code, and then pass va_list around.

To facilitate calling ioctl with variadic arguments from system code,
z_fdtable_call_ioctl() helper function is added.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-12-14 13:21:31 +02:00
Paul Sokolovsky 94007da116 net: sockets: Rework fcntl() dispatching to the underlying fd object
fcntl operations are implemented using ioctl vmethod.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-12-14 13:21:31 +02:00
Robert Lubos ee0b61fff8 net: sockets: Rework poll to support ioctl helper commands
This commit reworks socket poll implementation to support multiple
socket implementations.

To achieve that, two ioctl poll helper requests were added:
ZFD_IOCTL_POLL_PREPARE and ZFD_IOCTL_POLL_UPDATE. The poll
implementation calls ioctl with these requests for each socket
requested in the fds table.

The first request is responsible for preparing k_poll_event objects
for specific socket. It can request to skip waiting in k_poll by
returning EALREADY through errno.

The latter request is responsible for processing outcome of k_poll for
each socket. It can request to retry the k_poll by returning EAGAIN
through errno.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-12-10 11:38:13 +02:00
Robert Lubos 31ab8d061d net: sockets: tls: Implement vtable for TLS sockets
Implement extended socket vtable for TLS sockets, therefore allowing to
integrate the implementation with socket subsystem.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-12-10 11:38:13 +02:00
Robert Lubos df8693af64 net: sockets: Extend socket vtable
This commit extends socket vtable, allowing to redirect socket calls to
alternate implementations (e.g. TLS sockets).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-12-10 11:38:13 +02: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
Gil Pitney c51cf1e463 drivers: wifi: simplelink: Implement setsockopt() for TLS offload
Implements setsockopt() for the socket offload driver
to process the TLS tags sent in via the Zephyr setsockopt() API,
when CONFIG_NET_SOCKETS_SOCKOPT_TLS is chosen.
For each tag, the credential filenames are retrieved and
set via SimpleLink's sl_SetSockOpt() API.

Also, creates a new KConfig option for TLS_CREDENTIAL_FILENAMES.
This new option is used by apps/protocols to add TLS credentials
via filenames referring to the actual content stored on a secure
file system or flash.

Handles the IPPROTO_TLS_* socket protocol families in the
socket() offloaded API.

This was validated on the cc3220sf_launchxl with the http_get sockets
sample, with the globalsign_r2.der file loaded to secure flash via
the TI Uniflash tool, and using the TI Catalog of known good
root CA's.

Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2018-11-23 09:16:21 -05:00
Paul Sokolovsky 2e21a95fd4 net: sockets: zsock_close: Be sure to free file descriptor
File descriptor I freed automagically when using POSIX subsystem's
close() function, but any subsys-adhoc functions like zsock_close()
should do that explicitly.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-20 11:25:17 +01:00
Robert Lubos 824d0bd854 sockets: tls: Use FD table to reach net_context
With FD table introduction, net_context can no longer be reached by
typecasting socket descriptor. Instead, file descriptor API have to be
used.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-11-15 17:54:40 -05:00
Robert Lubos 72958f2e1c sockets: tls: Fix getsockopt/setsockop return value
ztls_setsockopt and ztls_getsockopt returned error codes instead of
setting errno in particular cases. This commit fixes it.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-11-15 17:54:40 -05:00
Paul Sokolovsky 8f690e291b lib: fdtable: FD method tables should be const.
FD method tables contain function pointers, and thus should be
const and reside in ROM. This patch fixes all cases of FD vtable
definitions: for POSIX FS API and for sockets.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-08 09:47:46 -08:00
Paul Sokolovsky f750ce56ce net: lib: sockets: Switch to use fdtable
Previously the "socket file descriptors" were just net_context
pointers cast to int. For full POSIX compatibility and support
of generic operations line read/write/close/fcntl/ioctl, the
real file descriptors should be supported, as implemented by
fdtable mini-subsys.

Socket implementation already has userspace vs flatspace dichotomy,
and adding to that ptr-fds vs real-fds dichotomy (4 possible cases)
is just too cumbersome. So, switch sockets to real fd's regardless
if full POSIX subsystem is enabled or not.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-04 22:04:11 +01:00
Robert Lubos 683628ab73 net: tls: Do not assume PSK id is NULL terminated
Current TLS socket implementation assumed that PSK ID stored in
credential manager is NULL terminated. It's actually better to store
only the string content, as the string length is stored as well. This
approach is less confusing, when a user is not operating on C strings
but on a non-NULL terminated byte array.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-10-22 10:32:07 +03:00
Gil Pitney c2cdbbafd7 net: sockets: Get socket offload to build after net logging overhaul.
Also, defines one LOG_MODULE_NAME for the simplelink WiFi driver, and
uses the same name for all files in this driver (module).

Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2018-10-11 15:51:57 +03:00
Paul Sokolovsky 8e1d78c357 libc: minimal: Make fcntl.h be at top level, not sys/fcntl.h
Placing it at sys/fcntl.h was due to mimicking internal newlib's
layout, but what we need is this file at the standard location,
for reuse.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-10-09 15:44:59 -04:00
Léonard Bise 9975f7b854 net: sockets: Unblock threads waiting on recv on socket close
This commit fixes the issue that if a thread is waiting on recv for
data and the user closes the socket, the waiting thread is not
unblocked.

Signed-off-by: Léonard Bise <leonard.bise@gmail.com>
2018-10-09 18:35:22 +02:00
Jukka Rissanen 009e4dafa7 net: Make Kconfig template variables prettier
Adding spaces around "=" when definining Kconfig template so
that is more consistent with overall style of these template
variables.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-05 09:01:37 -04:00
Jukka Rissanen 57a8db7789 net: Use log_strdup() when printing debug strings
As the debugging print calls are async, all the strings that might
be overwritten must use log_strdup() which will create a copy
of the printable string.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03: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
Robert Lubos 349e14d63c net: tls: Fix mbedtls hostname erros when certificates are not used
When no certificate-based ciphersuites are used, mbedTLS compiles out
hostname field and associated functions from its SSL context. This
resulted in compilation error when only PSK-based ciphersuites were
configured.

This commit resolves the issue by compiling-out hostname-related code
from secure sockets implementation on the same basis as mbedTLS does.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-09-17 09:48:11 +03:00
Flavio Ceolin da49f2e440 coccicnelle: Ignore return of memset
The return of memset is never checked. This patch explicitly ignore
the return to avoid MISRA-C violations.

The only directory excluded directory was ext/* since it contains
only imported code.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Robert Lubos 5286524a5c net: tls: Add missing entropy header
sockets_tls subsystem uses entropy driver, yet it does not include
entropy header. This commit fixes this.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-09-14 15:01:57 +03:00
Gil Pitney c21b0fb357 net: sockets: Add a socket offload module
This patch enables BSD socket offload to a dedicated
TCP/IP offload engine.

This provides a simpler, more direct mechanism than going
through NET_OFFLOAD (zsock -> net_context -> socket conversions)
for those devices which provide complete TCP/IP offload at the
BSD socket level, and whose use cases do not require
IP routing between multiple network interfaces.

To use, configure CONFIG_NET_SOCKETS_OFFLOAD=y, and register
socket_offload_ops with this module.

Fixes #3706

Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2018-09-11 18:42:34 +03:00
Paul Sokolovsky a2d12527f6 net: sockets: poll: Handle EINTR return from k_poll
This is similar to change which was done in 21f31e90ec, unfortunately
this case was missed.

Fixes: #9032

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-30 09:28:29 -04:00
Paul Sokolovsky 2af8dc9630 net: sockets: close: Call net_context_accept only for listening socket
The previous code "optimized" and called both net_context_accept()
and net_context_recv() blindly to reset the corresponding callbacks.
But this leads to "wrong state" logging if debugging is enabled, so
clean that up.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-25 07:18:31 -07:00
Robert Lubos d529aef9f2 net: tls: Apply DTLS review fixes
This commit contains several fixes for DTLS implementation, proposed in
a post-merge review of #9338.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-17 15:10:00 +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
Robert Lubos 7c487ba04a net: tls: Use EINVAL for NULL pointer error in option setters
Originally EFAULT was used to indicate NULL pointer error in TLS option
set/get functions. EINVAL was suggested to be more apropriate error code
for this case, hence replace it.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 800392e128 net: tls: Enable non-blocking DTLS handshake
Introduce non-blocking DTLS handshake, used during recv function call.
This prevents from blocking while waiting for initial handshake packet
on non-blocking sockets during receive.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos ae41ec1f35 net: tls: Make TLS poll implementation check mbedTLS data
Make TLS poll function verify if decrypted data is available after
socket has notified activity with POLLIN flag. This prevents from giving
false notifications in case data was received on socket but was consumed
by mbedTLS.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 8697cc946f net: tls: Add timeout for mbetTLS read
Specify timeout value for mbedtls_ssl_read function for DTLS servers.
Adding this can prevent TLS context lockup in case blocking recv is used
and peer has shut down DTLS connection without closing it gracefully.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos b1d8271152 net: tls: Support DTLS recv and handshake
Add support for DTLS recv/recvfrom function.

For DTLS client, recv function requires to have an already established
DTLS connection.

For DTLS servers, this function will try to establish DTLS connection
before receiving data. In case that DTLS handshake fails, recv function
will silently retry.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos bdc56cfe89 net: tls: Support DTLS send and handshake
Add support for DTLS send/sendto function.

For DTLS clients, send function will try to establish DTLS connection
before sending data. If DTLS handshake fails, it will return an error.

For DTLS servers, send function requires to have DTLS connection already
established.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos d021b8c60f net: tls: Adapt connect for DTLS
Extend connect function with DTLS functionality.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 6c5aaa070c net: tls: Handle HELLO_VERIFY_REQUIRED during DTLS handshake
DTLS handshake can return MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED, which
indicate that TLS session context should be reset.

Also, store information whether TLS connection has beed established.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 4c235dea73 net: tls: Add DTLS bio functions
Add binary IO functions for DTLS connections.

dtls_rx function is more complex than it's TLS counterpart due to fact,
that DTLS does not allow blocking operation for this function. A simple
timeout mechanism was implmented basing on the zsock_poll function.

This function also verifies peer address. As currently only a single
DTLS connection is supported on a socket, if a DTLS connection is
established, and we receive datagram from different peer, it is silently
dropped.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 8719f9a802 net: socket: Extract flag related functions to internal header file
Functions for checking flags set on sockets are needed by TLS sockets as
well, therefore extract them to a separate header file to avoid code
duplication.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 4aaffaff8a net: tls: Add DTLS peer address helpers
Add helper functions to handle stored DTLS peer address.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 3ad2bbceda net: tls: Add cookie for DTLS
Add DTLS cookie to TLS context, required by DTLS servers.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 011b4f4265 net: tls: Add timer handling for DTLS
Add timer functions required by DTLS.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos b03a388d73 net: tls: Add socket option to set DTLS role
Add write-only socket option to set role for DTLS connection. This
option is irrelevant for TLS connections.

This options accepts and integer with a TLS role, compatible with
mbedTLS values:
0 - client,
1 - server.

By default, DTLS will assume client role.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 85db974ec3 net: tls: Add DTLS protocol types
Define DTLS protocol types and and Kconfig option to enable DTLS
support.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos b7e686648b net: sockets: Fix setsockopt coverity issues
Minor refactoring to satisfy Coverity.

Fixes #9291 (CID 187324)
Fixes #9296 (CID 187319)

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-06 12:40:40 +03:00
Ulf Magnusson d1684a83a4 Kconfig: Clean up some symbol definitions
- Remove redundant 'n' defaults. 'n' is the default value for bool
  symbols.

  This makes the auto-generated documentation clearer as well: You get
  "implicitly defaults to n" instead of
  "- n if <propagated dependencies>".

- Shorten

      <type>
      prompt "foo"

  to

      <type> "foo"

  This works for all types, not just bool.

- Various formatting nits.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-01 12:47:17 -04:00
Robert Lubos 7826228def net: tls: Add socket option to set peer verification level
Add write only TLS secure option to set peer verification level for
TLS connection.

This option accepts an integer with a peer verification
level, compatible with mbedtls values (0 - none, 1 - optional, 2 -
required.

By default, socket mimics mebdTLS behavior - (none for server, required
for client).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos 3d560e14ac net: tls: Add socket option to read chosen ciphersuite
Add TLS secure socket option to read a ciphersuite chosen during TLS
handshake. Might be useful during development.

This is a read-only option that returns an integer containing an
IANA assigned ciphersuite identifier of chosen ciphersuite.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos 11c24c855d net: tls: Add socket option to select ciphersuites
Add TLS secure socket option that enables to narrow list of ciphersuites
available for TLS connection.

This option accepts an array of integers with IANA assigned ciphersuite
identifiers and returns such.

By default, every statically configured ciphersuite is available for a
socket and getsockopt returns an array of these.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos 915317724c net: tls: Add socket option to set TLS hostname
Add write-only TLS secure socket option to set hostname.

This option accepts a string containing the hostname. May be NULL, to
disable hostname verification.

By default, an empty string is set as a hostname for TLS clients,
to enforce hostname verification in mbedTLS.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos a3edfc2563 net: tls: Set TLS credentials in mbedTLS
Configure selected credentials in mbedTLS before the handshake.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos 48e055577b net: tls: Add socket option to select TLS credentials
Add TLS secure socket option to select TLS credentials to use.

This option accepts and returns an array of sec_tag_t that indicate
which TLS credentials should be used with specific socket.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos f959b5c164 net: tls: Add TLS socket options placeholder
Add TLS secure sockets wrapper for getsockopt/setsockopt functions.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos 11f7abcefd net: socket: Define getsockopt() and setsockopt()
Define socket option functions and make them return ENOPROTOOPT.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos d09cbcaf6f net: tls: Add credential management subsystem
Add TLS credential management subsystem that enables to register TLS
credentials in the system. Once specific credentials are registered in
the system, they will be available for TLS secure sockets to use.

To use a TLS credential with a socket, the following steps have to be
taken:
1. TLS credential has to be registered in a system-wide pool, using the
API provided in "net/tls_credentials.h" header file.
2. TLS credential (and other TLS parameters) should be set on a socket
using setsockopt().

Note, that there is no need to repeat step 1 for different sockets using
the same credentials. Once TLS credential is registered in the system,
it can be used with mulitple sockets, as long as it's not deleted.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04: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
Paul Sokolovsky eedb8a7bd8 net: sockets: Make poll() call threadsafe by avoiding global array
Initial implementation of poll() was more of a proof of concept, so
was coded with a single-thread application in mind. As we move to
sockets as the main networking API, make it possible to use poll()
from different threads.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-07-17 13:02:16 +03:00
Robert Lubos 47f908872d net: tls: Implement poll with support for mbedTLS pending data
Implement socket poll function for TLS socket. In addition to regular
poll checks, we have to check if there is some decrypted data pending on
mbedTLS.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-13 15:03:45 -04:00
Robert Lubos 07f1a1fe2c net: tls: Handle TLS socket send and recv
Implement socket recv/recvfrom and send/sendto functions.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-13 15:03:45 -04:00
Robert Lubos d08fd07f60 net: tls: Handle TLS handshake
Implement TLS handshake handling in socket connect/accept functions.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-13 15:03:45 -04:00
Robert Lubos 2d4815dd15 net: tls: Add mbedTLS logging
Add mbedTLS logging function to enable logs from mbedTLS.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-13 15:03:45 -04:00
Robert Lubos ccdc6a6bdf net: tls: Add mbedTLS entropy source
Add entropy source for mbedTLS. If no entropy driver is available, use
non-secure, software entropy source.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-13 15:03:45 -04:00
Robert Lubos a7c698d936 net: tls: Add TLS context allocation/deallocation
Add tls_context structure that stored data required by TLS socket
implementation. This structure is allocated from global pool during
socket creation and freed during socket closure.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-13 15:03:45 -04:00
Robert Lubos 00a69bf9bb net: socket: Add switch to enable TLS socket option support
Add switch to a socket layer that will enable switching socket API to
TLS secure sockets. At this point there is no secure sockets
implementation, so secure socket calls redirect to regular socket calls.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-13 15:03:45 -04:00
Ulf Magnusson 1073882998 subsys: kconfig: Remove 'default n' properties and clean up a bit
Bool symbols implicitly default to 'n'.

A 'default n' can make sense e.g. in a Kconfig.defconfig file, if you
want to override a 'default y' on the base definition of the symbol. It
isn't used like that on any of these symbols though.

Remove some 'default ""' properties on string symbols too.

Also make definitions more consistent by converting some

  config FOO
  	<type>
  	prompt "foo"

definitions to a shorter form:

  config FOO
  	<type> "foo"

This shorthand works for int/hex/string symbols too, not just for bool
symbols.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-07-12 23:13:22 -04: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
Stig Bjørlykke 57e7ea8793 net: sockets: Support MSG_DONTWAIT flag in zsock_sendto
Add support for MSG_DONTWAIT flag in send() and sendto(). This
aligns with the same flag used in recv() and recvfrom().

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2018-03-21 09:59:49 +02:00
Stig Bjørlykke 7c9c825138 net: sockets: Support MSG_PEEK flag in zsock_recvfrom
Add support for MSG_PEEK flag in recv and recvfrom.

This flag is needed when using non-zephyr embedded applications with
Zephyr's socket API.

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2018-03-20 15:55:04 +02:00
Stig Bjørlykke 158adc684f net: sockets: Support MSG_DONTWAIT flag in zsock_recvfrom
Add support for MSG_DONTWAIT flag in recv and recvfrom.

This flag is needed when using non-zephyr embedded applications with
Zephyr's socket API.

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2018-03-18 17:06:38 -04:00
Stig Bjørlykke b0c8cd8048 net: sockets: Refactoring zsock_recvfrom
Refactor recvfrom code for handling SOCK_DGRAM into zsock_recv_dgram
to align with SOCK_STREAM. Add flags parameter, will be used later.

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2018-03-15 15:10:04 +02:00
Paul Sokolovsky 5925112ee6 net: sockets: Preserve user_data for any net_context send() or recv()
We use ctx->user_data to hold socket flags. As each call to
net_context_recv() and net_context_send() overwrites its previous
value, we explicitly must pass the current ctx value there.

Without this, non-blocking socket was turned into blocking after
e.g. switching from receiving to sending.

Fixes: #6309

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-03-05 12:54:42 +01:00
Paul Sokolovsky 934195cc43 net: sockets: zsock_accepted_cb: Init child socket on success only
If accept callback is called with error, don't treat the context
passed to the callback as a new accepted context.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-03-05 12:54:42 +01:00
Paul Sokolovsky 9e02f7b644 net: sockets: Fix mask application in sock_set_flag()
We pass normal 1-based mask, and mask invert it before logically
AND'ing with the value. This apparently a mix-up between how the
mask was intended to be passed initially and how it was in the end.
This issue actually didn't have an effect, because currently defined
flags have mutually exclusive lifetime (when "eof" flag is set,
"non-blocking" flag value is no longer import). Anyway, that's a
bug and needs fixing.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-03-05 12:54:42 +01:00
Leandro Pereira 816c709ef2 net: sockets: Do not reference NULL pointer with empty frags on start
Assertions should only be used to check invariants.  Things that may
change value in runtime are better left to proper checks.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-03-02 07:11:46 +01: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
Anas Nashif 429c2a4d9d kconfig: fix help syntax and add spaces
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-13 17:43:28 -06:00
Paul Sokolovsky 21f31e90ec net: sockets: Handle EINTR return from k_poll()
In 90b471fe4, there was a change to make k_poll() return EINTR error
if it was cancelled with k_fifo_cancel_wait(). Handle this change, or
otherwise sockets EOF handling was broken.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-11-21 07:01:49 -05:00
Aska Wu 7e58c5609a net: sockets: Fix net pkt leak
If net_context_recv() returns a error, net pkt will not be released. For
example, net_context_recv() returns -EBADF because the TCP connection is
closed by the peer.

Handle the return value instead of using SET_ERRNO().

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-11-17 12:58:32 +02:00
Paul Sokolovsky 91e810f87a net: sockets: sendto: Remove adhoc handling of max pkt payload size
Now the check happens on the level of the core IP stack, in
net_pkt_append().

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-11-10 16:30:42 +02:00
Sebastian Bøe 0829ddfe9a kbuild: Removed KBuild
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Sebastian Bøe 12f8f76165 Introduce cmake-based rewrite of KBuild
Introducing CMake is an important step in a larger effort to make
Zephyr easy to use for application developers working on different
platforms with different development environment needs.

Simplified, this change retains Kconfig as-is, and replaces all
Makefiles with CMakeLists.txt. The DSL-like Make language that KBuild
offers is replaced by a set of CMake extentions. These extentions have
either provided simple one-to-one translations of KBuild features or
introduced new concepts that replace KBuild concepts.

This is a breaking change for existing test infrastructure and build
scripts that are maintained out-of-tree. But for FW itself, no porting
should be necessary.

For users that just want to continue their work with minimal
disruption the following should suffice:

Install CMake 3.8.2+

Port any out-of-tree Makefiles to CMake.

Learn the absolute minimum about the new command line interface:

$ cd samples/hello_world
$ mkdir build && cd build
$ cmake -DBOARD=nrf52_pca10040 ..

$ cd build
$ make

PR: zephyrproject-rtos#4692
docs: http://docs.zephyrproject.org/getting_started/getting_started.html

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Aska Wu 62e5f8d7a1 net: socket: Handle the value-result argument
The addrlen of accept() and recvfrom() is a value-result argument. It
should be updated to the actual size of the source address after
calling accept() and recvfrom().

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-11-06 20:59:05 +02:00
Paul Sokolovsky 6f76a19f77 net: sockets: Fix Coverity false positive
Due to parameters used, net_context_recv() call cannot fail (it just
installs a callback, no I/O performed).

Coverity-CID: 178247
Fixes: #4581

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-11-01 09:47:40 +02:00
Aska Wu 632904117c net: sockets: Fix the error zsock_send() failed on the datagram socket
net_context_sendto() returns an error if dest address is NULL.

If dest address is available, net_conext_sendto() should be used.
Otherwise, net_context_send() should be used.

Fixes #4347

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-10-17 08:10:14 -04:00
Paul Sokolovsky 82a03936a4 net: sockets: Simplify if logic in sendto(), fix warning
send()/sendto() aren't "front facing" functions, so when user calls
them, context type hopefully should be already validated by other
functions. They are also on critical path of app/network performance,
so getting rid of extra check helps a little bit too. This also
fixes a warning of "err" possibly being used non-initialized.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-10-03 16:18:11 -04:00
Aska Wu 9ec60774f8 net: sockets: Implement sendto() and recvfrom()
sendto() and recvfrom() are often used with datagram socket.

sendto() is based on net_context_sendto() and recvfrom() is based on
zsock_recv() with parsing source address from the packet header.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-10-03 14:40:05 +03: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
Paul Sokolovsky c7da45f9e2 net: Enable logging in more modules if CONFIG_NET_LOG_GLOBAL defined
This is useful to enable error/warning logging across the net
codebase (less useful for debug level logging, but that's true
for CONFIG_NET_LOG_GLOBAL already).

Implementation-wise, instead of keeping adding to long list of
"select"'s in CONFIG_NET_LOG_GLOBAL and thus introduce component
inter-dependencies, add "default y if NET_LOG_GLOBAL" to
individual components' logging options.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-09-18 08:19:27 -04:00
Paul Sokolovsky 958ff51da8 net: sock: zsock_close: Explicitly cast few calls to (void).
To make Coverity happy.

Coverity-CID: 173646
Jira: ZEP-2465

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-09-01 09:31:19 -04:00
Paul Sokolovsky eb5d6fcef5 net: sockets: Be sure to initialize socket's queue on accept
When new socket context is created on accepting connection to a
listening socket, its recv_q FIFO should be initialized. Without
initialization, this worked by a chance when FIFO structure was
simple, but recent change to add dlist to it (which now needs
proper initialization) exposed this issue.

Jira: ZEP-2576

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-31 15:07:33 -04:00
Paul Sokolovsky d9af77bfd6 net: sockets: Consistently use "BSD Sockets compatible API" moniker
This is how it's called in the main docs, so use this same phrase in
Kconfig and samples too.

Also, added some articles to docs.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-17 12:02:55 -05:00
David B. Kinder 81f7c82625 doc: fix misspellings and missing EOF newlines
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-08-16 17:38:41 -05:00
Paul Sokolovsky c1a5573c85 net: sockets: Check return value of k_poll()
Mostly to make Coverity happy.

Coverity-CID: 173641

Jira: ZEP-2465

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-14 23:46:44 +03:00
Aska Wu eb8fd4aacf net: sockets: inet_pton() should return 1 on success
Add zsock_inet_pton() to convert the return value of net_addr_pton()
which returns 0 on success.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-08-10 17:41:47 +03:00
Paul Sokolovsky f80b2ac865 net: sockets: Fix race condition with accept() call
For an accepted socket, we should set our receive callback and start
to queue packets ASAP (in the accept callback itself). Otherwise,
(if done in accept() call like before) we may miss to queue some
packets.

This issue wasn't exposed with slow SLIP and with emulated QEMU, but
easily exposed with Ethernet on a real hardware.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-08 12:44:28 +03:00
Jukka Rissanen 238c51f6d0 net: sockets: Comment Coverity warning about unchecked values
Coverity complains about non-checked return values here. This is false
positive as the return values do not need checking in this special
case because we are closing the socket.

Coverity-CID: 173646

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-07 21:32:03 -04:00
Paul Sokolovsky b7e3739043 net: sockets: Manage TCP receive window
As we buffer incoming packets in receive callbacks, we must decrease
receive window to avoid situation that incoming stream for one socket
uses up all buffers in the system and causes deadlock. Once user app
consumes queued data using recv() call, we increase window again.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-05 11:40:50 +03:00
Paul Sokolovsky 8088e14c74 net: sockets: poll: Use prefixed POLL* constants.
Default examples build with native POSIX aliases enabled, so
unprefixed refs got thru.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-04 17:24:22 +03:00
David B. Kinder 62a0cd246d doc: fix uses of back quotes in documentation
ReST defines interpreted text roles where text enclosed by single quotes
can be "intrepreted", for example :ref:`some name` becomes a link to
a label anywhere in the doc set named "some name", :c:func:`funcname()`
becomes a link to the API documentation for "funcname", and
:option:`CONFIG_NAME` becomes a link to, in our case, the documentation
for the generated Kconfig option.

This patch fixes uses of `some name` (without a role) by either adding
an explicit role, or changing to ``some name``, which indicates inline
code block formatting (most likely what was intended).

This is a precursor to changing the default behavior of interpreted
text to treat `some name` as :any:`some name` (as configured in
doc/conf.py), which would attempt to create a link to any available
definition of "some name".

We may not change this default role behavior, but it becomes an option
after the fixes in this patch.  In any case, this patch fixes incorrect
uses of single-quoted text (possibly introduced because GitHub's
markdown language uses single-quoted text for inline code formatting).

Jira: ZEP-2414

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-08-03 11:08:23 -04:00
Paul Sokolovsky 2c2e8b26b4 net: sockets: Implement poll() operation.
poll() allows to (efficiently) wait for available data on sockets,
and is essential operation for working with non-blocking sockets.

This is initial, very basic implementation, effectively supporting
just POLLIN operation. (POLLOUT implementation is dummy - it's
assumed that socket is always writable, as there's currently no
reasonable way to test that.)

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-07-18 21:46:06 +03:00
Paul Sokolovsky 1abb89f640 net: sockets: Implement non-blocking mode.
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-07-11 14:00:27 +03:00
Paul Sokolovsky 49eaa2b722 net: sockets: Explicitly flush conn/pkt queue on close()
If a socket is closed without reading all data from peer or accepting
all pending connection, they will be leaked. So, flush queues
explicitly.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-28 16:07:55 +03:00
Paul Sokolovsky 6055b6cd6b net: sockets: Implement recv() for DGRAM sockets
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-28 16:07:55 +03:00
Paul Sokolovsky 2b4a240859 net: sockets: Implement recv() for STREAM sockets
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-28 16:07:55 +03:00
Paul Sokolovsky 41e88ea40c net: sockets: Implement send()
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-28 16:07:55 +03:00
Paul Sokolovsky 7567962f3a net: sockets: Implement bind(), connect(), listen(), accept()
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-28 16:07:55 +03:00
Paul Sokolovsky 386c5bacd1 net: sockets: Add configurable option to provide raw POSIX API names
With CONFIG_NET_SOCKETS_POSIX_NAMES=y, "raw" POSIX names like
socket(), recv(), close() will be exposed (using macro defines).
The close() is the biggest culprit here, because in POSIX it
applies to any file descriptor, but in this implementation -
only to sockets.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-28 16:07:55 +03:00
Paul Sokolovsky 3432ff4fca net: sockets: Bootstrap Sockets API implementation
This adds Kconfig and build infrastructure and implements
zsock_socket() and zsock_close() functions.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-28 16:07:55 +03:00