Commit graph

1227 commits

Author SHA1 Message Date
Ruslan Mstoi
b7ef393bfe net: ipv6: Drop ICMPv6 packet if NA header is NULL
This commit fixes the crash of echo_server from malformed
ICMPv6 NA packet.

Fixes #6315

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-02-23 09:13:10 +02:00
Paul Sokolovsky
ec207f4250 net: app: Move mbedTLS debug log level config to mbedTLS Kconfig
mbedTLS log level is obviously a mbedTLS config setting. It makes
sense to have it defined in mbedTLS Kconfig, and different parts
of Zephyr to reuse as needed (e.g. net-app vs upcoming TLS wrapper
for sockets).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-02-22 18:44:55 -05:00
Jukka Rissanen
7fc5ffa92b net: shell: Fix net mem command output
Pool size is no longer available so it is no use trying to print
its value. This change was introduced in commit dd09cbc1c4
("net: buf: Redesigned API with split data and meta-data")

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-02-21 11:05:19 +02:00
Ruslan Mstoi
76b262cae2 net: pkt: Fix comment typo in word fragment
Fix comment typo in word fragment

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-02-20 09:58:23 -05:00
Ruslan Mstoi
9f376407c0 net: ipv6: Drop NS packet if LL address is too long
This commit fixes the crash of echo_server from overflow in ICMPv6 NS
source link-layer address option.

Fixes #6235

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-02-20 16:54:47 +02:00
Ravi kumar Veeramally
5490d28d8c net: app: Fix issue while configuring local context
When IPv6 and IPv4 both are enabled and net_app acting as a client,
configuring local context has one glitch.

After selection of IPv6 context as a default context  function
should return immediately, otherwise it continue to select IPv4
context as default context.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-20 14:50:39 +02:00
Ravi kumar Veeramally
88e8119078 net: app: Fix connection closure issues with net_app_ctx
In case of TCP and node acting as a APP_SERVER it can have multiple
concurrent connections. Calling close callback when there are still
active connections exists, causing an issue.

e.g. When a node acting as a HTTP server and can support multiple
TCP connections. Let's say one of the connection is in closing
state and the rest are still in active state. net_app_ctx is
calling close (http_closed) callback of registered upper layers.
HTTP assumes all the connections are closed and unref all the
connection related stuff.

Call the close callback only when there are no active connections.
Patch has also moved TCP stuff under one #ifdef.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-20 14:50:39 +02:00
Jukka Rissanen
023628f3d7 net: Set net_buf alloc timeout for IPv4 ARP and IPv6 ND
Instead of having K_FOREVER when allocating a packet in IPv4 ARP
and IPv6 ND, set a timeout so that we do not have a case where we
would wait net_buf forever.

Fixes #5484

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-02-20 14:31:39 +02:00
Luiz Augusto von Dentz
ec6188bc06 net: bt: Call net_if_carrier_down when disconnected
If IPSP channel is disconnected call net_if_carrier_down instead of
net_if_down since the later may still attempt to send packets while the
former just discard them immediatelly.

Fixes #5317

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-02-19 14:46:33 +02:00
Luiz Augusto von Dentz
656bab0361 net: Introduce net_if_carrier_down
This introduces net_if_carrier_down so the L2 driver can inform when it
has lost connectivity so all packets shall be flushed and the interface
should be put down.

Fixes #5317

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-02-19 14:46:33 +02:00
Leandro Pereira
517df4d73c subsys: net: http: Send "Internal Server Error" on unknown error code
Avoid using an uninitialized pointer when adding headers to the HTTP
context.

Coverity-CID: 178792
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-02-19 10:37:57 +02:00
Ruslan Mstoi
d35cc75d2d net: icmpv6: Drop ICMPv6 packet if NS header is NULL
This commit fixes the crash of echo_server from malformed
ICMPv6 NS packet.

Fixes #6217

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-02-16 09:22:38 +02:00
Anas Nashif
8949233390 kconfig: fix more help spacing issues
Fix Kconfig help sections and add spacing to be consistent across all
Kconfig file. In a previous run we missed a few.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-02-15 23:20:55 -05:00
Ruslan Mstoi
c78a1227ff net: icmpv6: Drop ICMPv6 packet if ICMP header is NULL
This commit fixes the crash of echo_server from malformed
ICMPv6 packet.

Fixes #6197

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-02-14 17:44:29 +02:00
Michael Scott
086893fc55 net: app: client: set remote port after DNS lookup
In net_app_init_client(), the remote port is set after an initial
set of checks based on the remote_addr's assigned family.

However, if the peer_addr_str is a host name which needs to be
resolved via DNS, the family won't be set yet, and the port is
left as 0.

To fix this behavior let's move the port assignment after the
DNS lookup section to be sure that the remote sa_family is set.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-02-14 09:40:01 +02:00
Tomasz Bursztyka
47e45c52a1 net: buf: Support allocation of a net_buf pointing to external buffer
Difference being that the data is not, then, allocated from the pool.
Only the net_buf is.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-02-13 16:46:32 +02:00
Ruslan Mstoi
b743f98896 net: icmpv4: Drop ICMPv4 packet if ICMP header is NULL
This commit fixes the crash of echo_server from malformed
ICMPv4 packet.

Fixes #6081

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-02-13 16:05:25 +02:00
Ravi kumar Veeramally
18422de8da net: tcp: Provide local address in TCP reset message preparation
If context is bound to IPv6 unspecified addresss and some port
number, then unspecified address is passed in TCP reset packet
message preparation. Eventually packet dropped at the peer.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-13 13:37:20 +02:00
Ravi kumar Veeramally
1f20111ef3 net: tcp: Do not handle packet re-transmission in TCP ACK
Zephyr doesn't have luxury to create re-transmit timer per packet. So
it has different methods to handle packets in queue. But re-sending
packets on valid ack messages causing issues.

E.g. A TCP node sent two packets (packet-1, packet-2). Peer replied
two ACKs (ACK-1 and ACK-2), and these two ACK's are at rx_thread
queue. Now ACK-1 is handled and reference of packet-1 is freed
from sent list. Then if condiftion (valid ACK and connection
state is ESTABLISHED) notices that, sent list is not empty.
Restart the timer, modify sent flag and resend packets in a
list. Here packet-2 is sent again, even though ACK-2 is already
received. Situation is worse if there are more packets in the
list.

So only start the re-transmit timer in-case queue is not empty. It
allows rx_thread to handle all incoming packets (in this e.g ACKs).
When the re-trasmit timer expires, it sends the packets which
are left in queue.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-13 13:37:20 +02:00
Ravi kumar Veeramally
e059e8b379 net: context: Handle failure case of tcp backlog entry
In case of failed to get source address from the net packet,
release the assgined tcp backlog entry. Otherwise it will
never be freed.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-13 13:37:20 +02:00
Ravi kumar Veeramally
7dc72c3ca6 net: context: Remove duplicate call
k_delayed_work_cancel(&context->tcp->fin_timer) called twice
immediately one after other.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-13 13:37:20 +02:00
Luiz Augusto von Dentz
800bfaf9a7 Bluetooth: UUID: Remove macros defining 16 bit values
Application should normally declare a bt_uuid with proper type and then
use bt_uuid_cmp.

Fixes #5162

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-02-13 13:33:48 +02:00
Robert Chou
6f466cd7e5 net: coap: retransmission for four times
RFC 7252, sec 4.8 [https://tools.ietf.org/html/rfc7252#section-4.8]
The default MAX_RETRANSMIT is 4, current implementation only
retry 3 times. Update next_timeout() to return one more retry.

Also, add a TODO for random generated initial ACK timeout

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

The issues discovered while resolving archive.ubuntu.com.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-02-12 20:17:26 -05:00
Johan Hedberg
c14c2692e2 net: buf: Set default user data size to 4
Since all in-tree users are good with 4 bytes of user data, reduce the
default to 4. Also fix the default and rage values where apparently
'0' and '8' had been swapped.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-12 09:48:32 +02:00
Johan Hedberg
7aeb1fa136 net: buf: Remove incorrect dependency for NET_BUF_POOL_USAGE
NET_BUF_POOL_USAGE was never supposed to depend on NET_BUF_LOG.

Fixes #6127

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-11 13:37:09 +02:00
Johan Hedberg
5008ec7a06 net: buf: Introduce variable data length allocators
Introduce two new "standard" data allocators to net_buf. There are now
three in total:

NET_BUF_POOL_FIXED_DEFINE: This is the closes to the old
implementation, i.e. fixed size chunks.  It's also what the old
NET_BUF_POOL_DEFINE macro maps to.

NET_BUF_POOL_HEAP_DEFINE: uses the OS heap

NET_BUF_POOL_VAR_DEFINE: defines a variable sized allocator using
k_mem_pool (this is all that there was in my first draft of this
feature)

Currently the variable length allocators (HEAP & VAR) support
reference counted data payloads, i.e. cheap cloning. The FIXED
allocator does not currentlty support this to allow for the simplest
possible implementation, but the support can be added later if
desired.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-10 09:20:42 +02:00
Johan Hedberg
dd09cbc1c4 net: buf: Redesigned API with split data and meta-data
Redesign of the net_buf_simple and net_buf structs, where the data
payload portion is split to a separately allocated chunk of memory. In
practice this means that buf->__buf becomes a pointer from having just
been a marker (empty array) for where the payload begins right after
the meta-data.

Fixes #3283

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-10 09:20:42 +02:00
Ravi kumar Veeramally
b22ab26b10 net: app: Add a new API to get net pkt based on dst
Added a new API to get net pkt based on dst address. Destination
address will be used to find correct net_context.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-09 14:45:53 +02:00
Ravi kumar Veeramally
09b361deed net: app: Fix get_server_ctx helper function
When net_app_ctx has multiple net_contexts, selecting net_context
based on dst address has some glitches.

E.g. One net_app_ctx and two net_contexts (net_ctx1, net_ctx2).
     Both net_contexts are mapped to net_app_ctx.
     When a caller looking for net_ctx (e.g. net_ctx2) with
     matching dst address. Loop goes through net_ctx1 and dst
     doesn't match. But another if condition checks does this
     net_context mapped to net_app_ctx, yes it matches.
     So return net_ctx1, which is wrong.

So first go through all elements in array of net_contexts for
matching dst address, if it fails to find then go for matching
net_app_ctx.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-09 14:45:53 +02:00
Ravi kumar Veeramally
0055e007d0 net: if: Provide a Kconfig to select default network interface
Default network interface is the first interface if there are multiple
interfaces exist. But this creates an issue when different parts of
the network subsystem wants to choose particular default interface.
At-least with this Kconfig option user can select default network
interface.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-09 14:44:15 +02:00
Michael Scott
83978e6264 net: lwm2m: add max device power source config option
The code in the LwM2M "Device" object was checking for this max
power source config value, except that it was never added as a
Kconfig option.  Let's go ahead and add it so apps can set the
value appropriately.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-02-08 09:49:01 +02:00
Michael Scott
c1e180b6ee net: lwm2m: return NOT_FOUND for unused multi-value resources
When attempting to read an unused multi-value resource such as
"Available Power Sources", lwm2m client return a successful coap packet
w/o any values.  This looks like a timeout to any lwm2m servers which
make sure a valid response is returned.

Let's fix this by returning the correct NOT_FOUND error code instead.

NOTE: To test this I commented out the portion of the lwm2m client
sample which initializes the LWM2M_DEVICE_PWR_SRC_TYPE_BAT_INT and
LWM2M_DEVICE_PWR_SRC_TYPE_USB values.  By default, the sample will
setup dummy values to be returned by the client.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-02-08 09:48:45 +02:00
Robert Chou
228bf05af6 net: lwm2m: update internal API select_writer() and select_reader()
As per review of PR #5893, this is a follow up patch to update
select_writer() API to match the behavior of select_reader() API.

Quote from OMA-TS-LightweightM2M-V1_0_1-20170704-A. 8.2.5
"An Object Instance or Resource is Read by sending a CoAP GET to the
 corresponding path. The response includes the value in the
 corresponding Plain Text, Opaque, TLV or JSON format according to
 the specified Content-Format (see section 6.4).The request MAY
 specify an Accept option containing the preferred Content-Format
 to receive. When the specified Content-Format is not supported by
 the LwM2M Client, the request MUST be rejected."

Therefore, we do not attempt to assign a content-format when the
requested one is not supported. Instead, we return an error code.

0 is returned when reader or writer has been successfully selected by
select_reader() or select_writer()

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2018-02-07 22:12:48 -05:00
Robert Chou
54d7207e09 net: lwm2m: check content-format and respond with error if not support
Currently, we always set the content-format as "plain/text" when
it is unrecognized. This is wrong for it's possible that payload
is actually something else.

For example, we don't support JSON as incoming format right now.
But if I send a PUT request to /1/0/1 (server objectinstance/lifetime
resource) with value 3200 in JSON format: {"e":[{"n":"","v":3200}]}.
The client will still handle the request and respond with changed (2.04)
except the lifetime resource is updated incorrectly due to parsing
error.

Correct the behavior by not setting a default format and respond with
content-format-not-support error code (4.15)

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2018-02-05 09:05:00 +02:00
Ravi kumar Veeramally
9489fa54cc net: http: Fix http_prepare_and_send
net_pkt_append() has been changed. If payload reached max value
of 'data_len' in net packet, net_pkt_append will not append.
So the caller has to create new packet and append remaining payload.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally
d6ca4decea net: Unlink the neighbor after unref
Unlinking of neighbor also needed after nbr_unref. Otherwise
neighbor id is still in use and can not be linked further.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally
82f23bc276 net: rpl: Fix handling of DAO message
When a node receives DIO message from peer then node adds peer as
a neighbor (nbr with linklayer address). But when a node receives
DAO message from different peer (chances are peer selected
different route to reach this node), remove peer with previous
link layer address and add as a neighbor with new link layer address
with new route information. Now node can properly route packets to
peer from neighbor table or based on nexthop information from
routing table.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally
6245dd68d9 net: rpl: Ignore parents with lower rank
When a node joins in DAG network, it chooses neighbor (node or border
router) as its parent. But if it receives DIO message from another
peer, it can only act as a neighbor, not as a parent. If peer rank
is better than current preferred parent rank then node will select
new peer as it's best parent.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally
cfc8749133 net: rpl: Fix debug information and alignment issues
RPL prints lot of debug information which is difficult to track.
Minimized debugs in timer specific information and parsing of
DIO and DAO options. Also fixed alignment issues (no changes in
functionality)

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally
ebf56ed1a6 net: mgmt: Fix mgmt push event
Do not even consider the push event if CONFIG_NET_MGMT_EVENT_INFO
enabled and info length is more than NET_EVENT_INFO_MAX_SIZE.
Print error message and ignore the event.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally
ed2fcaeb8a net: rpl: Change default value for NET_RPL_INIT_LINK_METRIC
Current default value for NET_RPL_INIT_LINK_METRIC is 2, changing it
to 1.

e.g. NET_RPL_MIN_HOP_RANK_INC is 256 and NET_RPL_MC_ETX_DIVISOR is 256.
     Rank calculation for nodes is
     rank_increase = CONFIG_NET_RPL_INIT_LINK_METRIC *
                             NET_RPL_MC_ETX_DIVISOR;

     Which gives 768 for first set of child nodes. It would be good if
     CONFIG_NET_RPL_INIT_LINK_METRIC value is 1 and nodes ranks will be
     245, 512, 768 based on the path they choose.

User can absolutely change their configuration to maintain proper ranks.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally
e567ca4f44 net: rpl: Do not run IPv6 DAD for global addresses
When CONFIG_NET_RPL enabled, do not run DAD (duplicate address
detection) for global addresses. In RPL mesh network global addresses
for nodes are determined by prefix from Border Router. DAD is not
necessary in this case.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally
83bda0f037 net: Add IPv6 route add and delete event with info
If CONFIG_NET_MGMT_EVENT_INFO is enabled then provide mgmt info
about the route, which is added or deleted.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally
9010def93e net: Add IPv6 neighbor add and delete event with info
If CONFIG_NET_MGMT_EVENT_INFO is enabled then provide mgmt info
about the neighbor, which is added or deleted.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally
5e65444d04 net: ipv6: Remove route information before deleting neighbor
Remove any routes with neighbor as a nexthop first and then remove
neighbor from neighbor table.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally
49894b98e4 net: Improve net management event information
Provided separate event information structs based on events. This way
user will know what kind of information will be received to that
particular event.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally
ef36088608 net: Fix RPL header update
When net_ipv6_prepare_for_send() needs to route packets, it missed
updating of RPL header.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Jukka Rissanen
182b054a9f net: rpl: Setup DAG prefix into network interface
This is needed in routing if we are acting as border router.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-02-02 16:50:07 +02:00
Jukka Rissanen
6167f0f70c net: rpl: Do not do neighbor discovery for RPL network
Doing neighbor discovery in RPL network is not necessary and
that can be disabled in RPL nodes. Unfortunately the border
router needs to have ND enabled as it has also non-RPL network
interfaces in use. So in this case, mark RPL node as always
reachable.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-02-02 16:50:07 +02:00