Commit graph

1260 commits

Author SHA1 Message Date
Michael Scott 407ceeee6d net: if: Make sure iface->if_dev is not null when accessing L2
commit 971ae59913 ("net: pkt: Make sure iface is not null when
accessing L2") fixed net_if_l2 where iface was NULL, however if
iface->if_dev is NULL, the check breaks and returns an offset of
NULL (0x82 or so).  This is incorrect.

Let's add a check for iface->if_dev as well.

Signed-off-by: Michael Scott <mike@foundries.io>
2020-01-24 23:30:10 +02:00
Jukka Rissanen f9c18dd962 net: dns: Support multiple simultaneous mDNS requests
As mDNS requests set DNS id to 0, we cannot use it to match
the DNS response packet. In order to allow this functionality,
create a hash from query name and type, and use that together
with DNS id to match request and response.

Fixes #21914

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-01-24 16:22:18 +02:00
Robert Lubos 665d195f3a net: sockets: tls: Add missing symbols for a few options
`TLS_PEER_VERIFY` and `TLS_DTLS_ROLE` options accept specific values,
yet no symbols were defined for them. In result, magic numbers were used
in several places, making the code less readable.

Fix this issue, by adding the missing symbols to the `socket.h` header,
and using them in places where related socket options are set.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-01-20 09:58:23 +02:00
Robert Lubos 20b1c695ab net: mqtt: Add keep alive timeout helper
Add function that returns remaining time until next keep alive message
shall be sent. Such function could be used for instance as a source
for `poll` timeout.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-01-18 12:25:33 +02:00
Oleg Zhurakivskyy 8a77b53053 net: core: Drop NET_ASSERT_INFO() macro
A single assert macro can serve a purpose here.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-08 14:10:21 +02:00
Joakim Andersson 8d2b9e6fef net: buf: Add push functions for supported bit-variants
Add push functions for bit-widths supported by add and pull functions.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-02 19:05:27 +01:00
Justin Brzozoski 0116729114 net: mqtt: Maintain count of PINGREQ awaiting response
Maintain a simple count of how many PINGREQ have been sent for the
current connection that have not had a corresponding PINGRESP.  Nothing
is done with this information internal to the MQTT driver, but it is
exposed to the application layer to monitor as desired.

Signed-off-by: Justin Brzozoski <justin.brzozoski@signal-fire.com>
2019-12-18 23:33:56 +02:00
Paul Sokolovsky 3e706833bd include: net: ethernet.h: Clarify checksum offloading options
Both ETHERNET_HW_TX_CHKSUM_OFFLOAD and ETHERNET_HW_RX_CHKSUM_OFFLOAD
apply to all of IPv4, UDP, and TCP heafers (there's no checksum in
IPv6 header). Consequently, these options should be enabled only for
hardware which supports offloading for all of these options. (And
hardware which has fine-grained control over individual protocol
headers, should enable them all).

Based on the handling in the current source code and discussion
in #21269.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-12-17 11:32:09 +02: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
Luiz Augusto von Dentz 8724f4a2ee net: buf: Add support for 64 bit data type
This enables pulling and pushing values in 64 bit format.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-12-10 09:55:30 +02:00
Luiz Augusto von Dentz e0a55796b2 net: buf: Add support for 48 bit data type
This enables pulling and pushing values in 48 bit format.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-12-10 09:55:30 +02:00
Luiz Augusto von Dentz 4c06a9f577 net: buf: Add support for 24 bit data type
This enables pulling and pushing values in 24 bit format.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-12-10 09:55:30 +02:00
Luiz Augusto von Dentz 53784479b3 net: buf: Add net_buf_simple_init_with_data
This adds net_bug_simple_init_with_data which can be used to initialize
a net_buf_simple pointer with an external data pointer.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-12-10 09:55:30 +02:00
Jukka Rissanen 6378ac4e38 net: Verify correctness of iface_api inside L2 driver API
Add build time check that guarantees that iface_api struct is the
first entry inside L2 driver data. This makes sure we do not miss
a case when the ordering of the fields in the struct is changed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-12-09 12:55:29 -05:00
Jukka Rissanen 971ae59913 net: pkt: Make sure iface is not null when accessing L2
It is possible that the network interface is not set when we
check the interface in net_pkt.c:pkt_buffer_length(). For example
in icmpv6 unit test the interface is left as NULL as the test does
not care about what network interface is used. For real hw like
mimxrt1050_evk, which supports Ethernet, we need to add additional
checks for the interface being non-null.

Fixes #20088

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-12-02 07:39:41 -06: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
Robert Lubos 83bb911a21 net: openthread: Update OpenThread version
Use the newest version of the OpenThread project, as updated in
https://github.com/zephyrproject-rtos/openthread/pull/2.

Introduce the following fixes along with the update (they're squashed to
retain bisectability of OT samples):

* Update configs and flags used
	Some OT configs were renamed, some new were introduced that Zephyr port
	needs to set.

* Add entropy platform driver
	OpenThreads `random` platform subsystem was replaced with `entropy`
	subsystem which is supposed to serve as an entropy source for the
	generic OpenThread's random generator.

* Halt OT thread when OT command is processed
	OpenThread can currently be processed from two threads - a
	genuine OpenThread thread and shell thread, which processes CLI
	commands. This could cause trouble, when context was switched
	during OT command processing (i.e. switched to process an incomming OT
	message, while still in unfinished command handler).

	In result, it was not possible to turn the commissioner role on via
	CLI, as the commissioner petition response was handled before the
	Commissioner::Start function finished its execution (if the
	petitioner is also the network leader, all messages are passed
	internally within the stack).

	Fix this by suspending the OT thread for the time of an OT command
	processing.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-10-28 13:00:56 +02:00
Oleg Zhurakivskyy 9666f2201e net: context: Add an opaque handle for TCP2
Add an opaque handle for TCP2.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2019-10-25 14:33:37 +03:00
Oleg Zhurakivskyy 9c3fc831b9 net: tcp2: Allow placing the packet into sys_slist_t
Allow placing the packet into sys_slist_t.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2019-10-25 14:33:37 +03: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
Robert Lubos 047969c0d0 net: if: Fix interface initialization with socket offloading
A socket-offloaded interface should bypass interface initialization in
the same way as net-offloaded interface does.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-10-15 11:06:40 +03:00
Jukka Rissanen d03cb7367c net: Add statistics how long packets have spent in TX path
Calculate how long on average net_pkt has spent on its way from
application to the network device driver. The data is calculated
for all network packets and not just for UDP or TCP ones like in
RX statistics.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-14 16:34:48 +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 23ca8899fa net: mqtt: Add support for running MQTT over Websocket
Initial support for running MQTT over Websocket.

Fixes #19539

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-04 18:48:10 -07:00
Benjamin Lindqvist 81ccbd96c9 net: coap: Add internal init function to seed message_id
Randomly generating ID the first time coap_next_id() is called is more
in accordance with CoAP recommendations (see
https://tools.ietf.org/html/draft-ietf-core-coap-18, section 4.4)

"It is strongly recommended that the initial value of the
variable (e.g., on startup) be randomized, in order to make successful
off-path attacks on the protocol less likely."

Doing this in a dedicated init function is the cleanest and most
idiomatic approach. This init function is not exposed publically which
means it will be called only once, by the network stack init procedure.

Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
2019-10-04 21:22:55 +03:00
Trond Einar Snekvik 3d201b45f9 net: buf: Add net_buf_simple_clone
Provides a way to clone a net_buf_simple without altering the state of
the original buffer. The primary usage scenario is for manipulating a
previously allocated PDU inside a buffer without altering the length and
offset of the buffer.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2019-10-04 20:56:25 +03:00
Jukka Rissanen 6af987646f net: websocket: client: Simple API for Websocket client
Implement simple API to do Websocket client requests.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-04 16:38:34 +03:00
Jukka Rissanen eb40499627 net: http: client: Initial version
Simple HTTP client API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-04 16:38:34 +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
Paul Sokolovsky a7bb2850f7 net: sntp: Allow to build for CONFIG_POSIX_API.
Use POSIX headers in this case.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-09-12 17:30:29 +03:00
Paul Sokolovsky 7c49ac6e0a include: net: socketutils: Allow to build for CONFIG_POSIX_API
Previously, they were tested only with CONFIG_NET_SOCKETS_POSIX_NAMES,
but should also work with POSIX subsys. Achieve this by including POSIX
headers in this case.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-09-12 17:30:29 +03:00
Jukka Rissanen e182f31b9e net: Add IPPROTO_RAW as it was missing
The IPPROTO_RAW is used as a default for SOCK_RAW when protocol
is not set in socket() call.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-09-12 11:22:45 +03:00
Jukka Rissanen 6cf1da486d net: Add CONFIG_NET_NATIVE option for selecting native IP
Allow user to disable native IP stack and use offloaded IP
stack instead. It is also possible to enable both at the same
time if needed.

Fixes #18105

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-09-10 12:45:38 +03:00
Stephanos Ioannidis bef377998a net: Explicitly include toolchain.h to check for endianness definitions.
This commit adds an explicit inclusion of toolchain.h from ptp_time.h.

The endianness preprocessor definitions (__BYTE_ORDER__,
__ORDER_LITTLE_ENDIAN__, __ORDER_BIG_ENDIAN__) are used by ptp_time.h;
these being not defined can easily go unnoticed and cause unexpected
behaviours, as detailed in PR #18922.

toolchain.h ensures that these preprocessor definitions are defined and
*must* be included in a file that uses these definitions.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2019-09-09 21:40:54 +02:00
Jun Qing Zou ca783d72a6 net: lwm2m: support client-initiated De-register
Add new RD Client API of lwm2m_rd_client_stop() for this
Fix issues of de-register and event reporting in RD Client

Signed-off-by: Jun Qing Zou <jun.qing.zou@nordicsemi.no>
2019-09-08 12:36:33 +02:00
Peter Bigot 6554a5e5b6 include: rearrange for standard use of extern "C" in various headers
Consistently place C++ use of extern "C" after all include directives,
within the negative branch of _ASMLANGUAGE if used.

The inclusion of the generated syscall files is placed outside the
extern "C" block as the generated file has its own extern "C" block.

Background from issue #17997:

Declarations that use C linkage should be placed within extern "C"
so the language linkage is correct when the header is included by
a C++ compiler.

Similarly #include directives should be outside the extern "C" to
ensure the language-specific default linkage is applied to any
declarations provided by the included header.

See: https://en.cppreference.com/w/cpp/language/language_linkage
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-08-13 18:00:31 +02:00
Peter Bigot 754d1274a7 include/net: additional cleanup for extern "C" use
The previous patch left some include directives hidden within the body
of the extern "C" block.  Lift them out to the top of the file where
they're more visible.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-08-13 18:00:31 +02:00
Alexander Wachter 95863a73da net: ip: net_pkt: Implement net_pkt_shallow_clone
This commit implements net_pkt_shallow_clone. A shallow clone clones
the net_pkt but not the buffers. The buffers are only referenced and
therefor only freed when both copies of the net_pkt are freed.

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
2019-08-08 13:25:01 +03:00
Alexander Wachter 35f01673ac net: l2: 6LoCAN implementation
This commit is an implementation of 6LoCAN, a 6Lo adaption layer for
Controller Area Networks. 6LoCAN is not yet standardised.

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
2019-08-08 13:25:01 +03: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 5c05ef5101 net: Move include files outside of extern "C" block
This is related to findings in #17997 and changes network related
header files to have include files outside of extern "C" { } block.

Declarations that use C linkage should be placed within extern "C"
so the language linkage is correct when the header is included by
a C++ compiler.

Similarly #include directives should be outside the extern "C" to
ensure the language-specific default linkage is applied to any
declarations provided by the included header.

See: https://en.cppreference.com/w/cpp/language/language_linkage

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-08-06 14:46:36 +03:00
Jukka Rissanen caa99b7fed net: context: Clarify net_context_send() API documentation
The net_context_send API documentation was missing the fact,
that the callback might be called after the net_context_send()
has returned. Also currently the timeout value is not used properly
anywhere in the code. This is left like this as there is not much
use for the timeout value atm. This might be fixed later if there
is proper use case for it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-08-06 10:14:57 +03:00
Ravi kumar Veeramally 8e70bd6f48 net: mqtt: Modify SOCKS5 based connections
Current SOCKS5 based connections in mqtt are only
TCP (nonsecure) based. To support TLS based SOCKS5
connections, new methods needs to be introduced.

Instead, removed CONFIG_MQTT_LIB_SOCKS based implementation.
And now mqtt provides an api to set proxy
(mqtt_client_set_proxy()) details. That's enough,
socket layer will take care of making connections through
proxy server.

Fixes: #17037

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-08-05 13:26:11 +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
Michael Scott 3d3af7114e net: lwm2m: add IPSO Accelerometer object support
This IPSO object can be used to represent a 1-3 axis accelerometer.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott ca61a238af net: lwm2m: add IPSO Push Button object support
This Object is used to report the state of a momentary action push
button control and to count the number of times the control has
been operated since the last observation.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott 2019d49bf0 net: lwm2m: add IPSO On/Off Switch object support
This object is used with an On/Off switch to report it's state.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott 4bf343d5d1 net: lwm2m: add IPSO Buzzer object support
The IPSO Buzzer object is used to represent a buzzer, beeper or
vibrating alarm.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott 8817d930a8 net: lwm2m: rework resource instance storage / access methods
LwM2M allows for multiple instance resources such the power source
resources in the device object.  These types of resources have
always been very hard to work with, and frankly were poorly
implemented.

This led to other issues where it was very hard to have
non-sequential resource instances, and each resource of this type
needed special getter / setter methods such as:
lwm2m_device_add_pwrsrc()
lwm2m_device_set_pwrsrc_voltage_mv()

Going forward, as more LwM2M objects are implemented this just
doesn't scale well.

To fix this:
- split the resource instance data out from the resource data.
  This includes the data pointer information and resource
  instance id.
- add resource id and resource instance id to the event callback
  functions so user's can see in more detail what resources and
  resource instances are being handled.
- allow generic functions like lwm2m_engine_get_*() and
  lwm2m_engine_set_*() to access resource instance data.
- adjust object resource initialization  macros to map resource
  instances to resources at the time of object instance
  creation.
- fix up the lwm2m_client as a reflection of all of these changes.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott ad01c035b8 net: lwm2m: update function prototypes and descriptions
- Several of the functions use "path" as the parameter name for the
  string-based LwM2M path.  Let's clarify by using "pathstr".
- Recent updates to the LwM2M engine now support resource instances
  when parsing the LwM2M path.  Let's update descriptions accordingly.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Jukka Rissanen c4a692a85f net: ppp: Add proper support to receive Echo-Reply message
Currently only net-shell calls net_ppp_ping() command, so make
it return the amount of time that it took to receive Echo-Reply
so the net-shell can print the round trip time value.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-29 10:24:46 +03:00
Jukka Rissanen 19a09bf553 net: pkt: Add net_pkt_read_le16() helper
We had a big endian helper but little endian one was missing.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-29 10:24:46 +03:00
Jukka Rissanen ddac835ea7 net: pkt: Add net_pkt_write_le16() helper
We had a big endian helper but little endian one was missing.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-29 10:24:46 +03:00
Jukka Rissanen 3e481f9d07 net: ppp: Allow delay of PPP protocol handshakes
By default PPP is started immediately when the network interface
goes up. This can be problematic especially when debugging the beast
so allow user to delay the startup.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-29 10:24:46 +03:00
Jukka Rissanen 4a5543db25 net: shell: Add ppp network interface support
Print point-to-point network information properly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-29 10:24:46 +03:00
Jukka Rissanen 02239a99a2 net: ppp: Add IPV6CP support
Initial version for PPP IPv6 Control Protocol.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-29 10:24:46 +03:00
Jukka Rissanen f95938da0f net: ppp: Initial support for point-to-point protocol
This implements ppp L2 component, LCP and IPCP modules.

Fixes #14034

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-29 10:24:46 +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 390a6cf617 net: context: Add support for net_context_sendmsg()
After this we can implement BSD sendmsg() API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-24 10:17:16 +03:00
Jukka Rissanen c1d03b24af net: ip: Add iovec and msghdr structs
These are needed in sendmsg implementation. See RFC 3542 for
details of the msghdr struct and the macros that are used
to manipulate it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-24 10:17:16 +03:00
Markus Fuchs a928b6dc61 net: sntp: add missing __cplusplus check
This patch adds an `extern "C"` linkage directive so sntp.h can be
included by C++ source files.

Signed-off-by: Markus Fuchs <markus.fuchs@de.sauter-bc.com>
2019-07-17 17:51:12 +03:00
Tomasz Bursztyka b2e71a2fa2 net: Add a connection manager preliminary logic
It currently only listens to relevant events about network interface to
decide whether raising connected or disconnected event.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-07-12 12:33:19 +03:00
Jukka Rissanen 3ebe60a3ba net: ip: Helper for getting used network address family as string
This helper can be used in debugging the used network address family.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-12 12:33:19 +03:00
Michael Scott e7155622a2 net: lwm2m: add custom TLS credential load function pointer
Current implementation of LwM2M engine doesn't allow users a way
of overriding TLS credential load with custom function.  This
would be needed by an offloaded TLS stack where we don't want
to use standard Zephyr functions.

Let's add a load_credential function pointer to the LwM2M client
context which will be called when it's available.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/17408

Signed-off-by: Michael Scott <mike@foundries.io>
2019-07-11 11:08:05 +03:00
Tomasz Bursztyka c8f7c329a2 net/lldp: Simplify Kconfig file
Let's remove depends on NET_LLDP from all the options. It avoids this:
 # CONFIG_NET_LLDP is not set
 # CONFIG_NET_LLDP_LOG_LEVEL_OFF is not set
 # CONFIG_NET_LLDP_LOG_LEVEL_ERR is not set
 # CONFIG_NET_LLDP_LOG_LEVEL_WRN is not set
 # CONFIG_NET_LLDP_LOG_LEVEL_INF is not set
 # CONFIG_NET_LLDP_LOG_LEVEL_DBG is not set
 CONFIG_NET_LLDP_LOG_LEVEL_DEFAULT=y
 CONFIG_NET_LLDP_LOG_LEVEL=3
 CONFIG_NET_LLDP_CHASSIS_ID="CHASSIS_ID_PLACEHOLDER"
 CONFIG_NET_LLDP_PORT_ID="PORT_ID_PLACEHOLDER"

And instead it will generate this:
 # CONFIG_NET_LLDP is not set

Make the menu as an enablement config option as well.

Adapting lldp header file relevantly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-07-10 15:24:32 +03:00
Jukka Rissanen 8f92dc4634 net: dns: Send net-mgmt event for DNS server add and del
If DNS server(s) are added or removed e.g., as part of DHCP
processing, send newly defined net-mgmt events so that
a user application may get this information.

Fixes #16924

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-09 17:04:55 +03:00
Jukka Rissanen 4b06ae323c net: mgmt: Add L4 layer and related events
These events are used by connection management patches following
this one.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-09 17:04:55 +03:00
Tomasz Bursztyka d80d181d04 net/iface: Add IPv4 route find and add
Removing an IPv4 router was missing, as well as finding the default
router for an IPv4 address.

Note howevere that IPv4 router features are not used anywhere yet. But
at least the API is there and is a 1:1 to IPv6, if that matters.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-07-09 14:54:23 +03:00
Tomasz Bursztyka eccc268d0a net/iface: Rework how routers are handled
- router lifetime is always a u16_t so fixing
net_if_ipv6_router_update_lifetime() signature.
- Coalescing router timers into one: this reduces the net_if_router
structure by 22 bytes
- refactor IPv6 and IPv4 router code so it's handled in generic
functions, to avoid duplicating 90% of the code for each family. This
also fixes the lifetime support for IPv4 which was missing.

Note however that IPv4 routing support seems to be missing as none of
the relevant functions are used anywhere yet.

Fixes #8728

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-07-09 14:54:23 +03:00
Tomasz Bursztyka b2d95840a5 net/ipv4: Add a net mgmt event for IPv4 router deletion
There will probably be at some point a way to remove IPv4 router, and
thus it will require such event.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-07-09 14:54:23 +03:00
Tomasz Bursztyka b5bcd25398 net/iface: Coalesce all RS timers through one
This reduces the size of struct net_if_ipv6 by 24 bytes by moving
the k_delayed_work attribute into net_if core code.
Then each net_if_ipv6 can be added to the timer handler via a slist.

This does not make much gain if the system has only 1 network interface
It starts to be interesting if it has 2+ network interfaces then.

Fixes #8728

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-07-09 14:54:23 +03:00
Tomasz Bursztyka 09e7262be8 net/iface: Coalesce all DAD timers through one
This reduces the size of struct net_if_addr by 24 bytes by moving
the k_delayed_work attribute into net_if core code.
Then each net_if_addr can be added to the timer handler via a slist.

This does not make much gain if the system has only 1 unicast IPv6
address. It's a nice memory improvment once it has 2+ unicast IPv6
address. Note that having IPv4 enabled along with IPv6 will also see
memory improvements since both IPv6 and IPv4 use the same struct
net_if_addr.

Fixes #8728

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-07-09 14:54:23 +03:00
Tomasz Bursztyka ca5d24d2cd net/iface: Remove useless attributes in net_if_ipv6 structure
DAD use dad_count attribute in struct net_if_addr, since DAD is ran on
each and every ipv6 unicast address.

Fixes #8728

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-07-09 14:54:23 +03:00
Tomasz Bursztyka 6a513e4394 net/iface: Reduce ifdef usage on various options
Offload, DAD, RS and IPv4 autoconf.

Fixes #8728

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-07-09 14:54:23 +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 a18bd3a2e7 net: mgmt: Remove L1 layer as that is useless
The network interface events should be in L2 layer so there
is no one that would emit L1 events so no need for it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-03 14:40:03 +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 e809b95c51 net: Collect network packet TX send time
Finalize the CONFIG_NET_CONTEXT_TIMESTAMP support that was started
earlier but never properly finished. We collect network statistics for
TX packet network stack throughput time from when the net_context_send
is called and when the net_pkt was sent out successfully by the network
device driver.

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 5d13df9c3b net: utils: Add userspace support to net_addr_ntop/pton()
Allow userspace application call net_addr_ntop() and
net_addr_pton() functions.

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
Jukka Rissanen 02b3826fa0 net: mgmt: Add info length to event wait API
The info parameter is difficult to use if the caller does not
get information how long the info struct is. So add info_length
parameter to net_mgmt_event_wait_on_iface() and
net_mgmt_event_wait() APIs.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 13:50:08 -07:00
Jukka Rissanen 766ad9f96c net: if: Make gateway address in net_if_ipv4_set_gw() const
As the function does not modify the parameter, we can make it const.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 15:34:11 +03:00
Jukka Rissanen 7063921e87 net: if: Add userspace support to IPv4 gateway set function
Allow application to call net_if_ipv4_set_gw_by_index()
and set the gateway if enabled by configuration.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 15:34:11 +03:00
Jukka Rissanen 813ae63f6b net: if: Add userspace support to IPv4 netmask set function
Allow application to call net_if_ipv4_set_netmask_by_index()
and set the netmask if enabled by configuration.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 15:34:11 +03:00
Jukka Rissanen 10189332cd net: if: Make IPv4 address const in removal function
As the function does not touch IPv4 address in removal, we
can mark it const.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 15:34:11 +03:00
Jukka Rissanen 041cd5f18f net: if: Add syscall interface to IP address add and rm
Make IPv4 and IPv6 address addition and removal possible from
userspace app. But allow this only if CONFIG_NET_IF_USERSPACE_ACCESS
By default these operations are not allowed from userspace app.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 15:34:11 +03:00
Justin Brzozoski ffe25df82a mqtt: Allow client to override keepalive
This change will allow an MQTT client to override the compile-time
keepalive if desired.  The change is structured such that the
compile-time default will still be setup by calling mqtt_client_init,
but can be changed by the application before calling mqtt_connect if
desired.

Signed-off-by: Justin Brzozoski <justin.brzozoski@signal-fire.com>
2019-06-28 09:54:16 -04:00
Anas Nashif efb8df5366 cleanup: include/: move misc/stack.h to debug/stack.h
move misc/stack.h to debug/stack.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 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 536dd5a71f cleanup: include/: move misc/slist.h to sys/slist.h
move misc/slist.h to sys/slist.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 0c9e280547 cleanup: include/: move misc/mutex.h to sys/mutex.h
move misc/mutex.h to sys/mutex.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 5d001f3e41 cleanup: include/: move misc/byteorder.h to sys/byteorder.h
move misc/byteorder.h to sys/byteorder.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 5eb90ec169 cleanup: include/: move misc/__assert.h to sys/__assert.h
move misc/__assert.h to sys/__assert.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 c0c9396d44 cleanup: include/: move can.h to drivers/can.h
move can.h to drivers/can.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