Commit graph

19237 commits

Author SHA1 Message Date
Michael Scott
a96fbc8167 net: tcp: fix NET_TCP_CLOSED state propagatation
In net_tcp_release() when a TCP connection is being closed, we
should call net_tcp_change_state instead of net_tcp_set_state.

net_tcp_change_state() will call into net_tcp_set_state() but
also contains logic specific to NET_TCP_CLOSED which unregisters
the context's conn_handler and sends an accept callback (if
present) with -ENETRESET error for user code to handle.

This fixes an EISCONN error returned by net_context_bind() when
a TCP-based net_context was reused.  Due to the conn_handler
not being cleaned up in the TCP code.

Change-Id: I8439a028a1c7ae5fd2a50d11caa9947a0ac6c7d4
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-03-09 20:33:47 +02:00
Vinicius Costa Gomes
43ae27fd9b samples/coaps_server: Don't error if the packet doesn't have payload
GET and DEL requests may not have payloads, so it's not correct to
return with an error in those cases.

This was only noticed now that zoap_packet_get_payload() returns the
correct value for all situations.

Jira: ZEP-1754

Change-Id: Ie533041aa7a66855582ff4c5c937d943304bad84
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
2017-03-09 20:33:47 +02:00
Jithu Joseph
bf5263a552 net: ip: Address type mismatch warnings
These were flagged by icx compiler.

Jira: ZEP-1811 , ZEP-1809

Change-Id: I0dff800ce2bb440b39dceb08b145e085be4c8caf
Signed-off-by: Jithu Joseph <jithu.joseph@intel.com>
2017-03-09 20:33:46 +02:00
Jukka Rissanen
673da2fbc8 net: core: Fix IPv6 extension parsing
The parsing of IPv6 extension headers was skipping bytes
in certain cases.

Change-Id: I80612144aed55aa2dcf9eaab1f4408e10ef9ca31
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:46 +02:00
Ravi kumar Veeramally
2e3e93dccb net: 6lo: Fix compress bit calculation
Compress bit calculation was wrong. It should be moved
to 4 bits left to cache it properly.

Change-Id: Ib011874881a69032795c2ecfd9a615b6cf559c69
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:46 +02:00
Ravi kumar Veeramally
dbec3b5838 net: 6lo: Fix invalid check on context id
Max 6lowpan contexts are 16 as per RFC 6775 4.2 6LoWPAN Context Option.
Range is 0 - F. So context id '0' is valid.

Change-Id: I8468a805e0145b64921139a587cdaeeb9d6871b8
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:46 +02:00
Ravi kumar Veeramally
eb6379dd94 net: 6lo: Fix tiny style and comments issues
Change-Id: I449473dbcc2cc0baa52607a94432c5c18befece5
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:46 +02:00
Ravi kumar Veeramally
9b9198562b net: 6lo: Fix invalid hoplimit uncompression
If hoplimit bit is unset then values are inlined as
per RFC 6282 3.1.1 HLIM: Hop Limit.

Change-Id: I5821fdf1a4a65b252362277cc604ae913203f80e
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:46 +02:00
Ravi kumar Veeramally
2b3a12be70 net: 6lo: Fix incorrect order of HLIM and NH compression
Hop limit compression should be after next header compression as
per RFC 6282 3.1.1.

Change-Id: I0eaf3428bf835fe73831a7fe6fb708b73c8f5d12
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:46 +02:00
Juan Manuel Cruz
26b014800b drivers: enc28j60: buffer reception waits timeout
The enc28j60's reception routine requires a timeout
for a buffer assignation. The timeout is configurable
to allow a per application fine tuning.

The effect that K_NO_WAIT currently has is that there are frames
lost everytime that a buffer is required and there are none
available.

Jira: ZEP-1169

Change-Id: Ia18736fd85daee51fe1c2304977209cc7f0038b5
Signed-off-by: Juan Manuel Cruz <juan.m.cruz.alcaraz@intel.com>
2017-03-09 20:33:46 +02:00
Luiz Augusto von Dentz
79ea89624e net: bt: Place ll address type together with other assignments
Change-Id: I15867c9457daf7857ef8dfccbd38419ab8292e8d
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-09 20:33:46 +02:00
Luiz Augusto von Dentz
d7ed8d62d6 net: bt: Fix setting ll addresses to possible invalid pointers
net_nbuf_ll_src(buf)->addr and net_nbuf_ll_dst(buf)->addr should be
pointing to ctxt area not actual net_nbuf_ll region since the payload
over Bluetooth does not carry any ll addresses.

Change-Id: I87828d74abf2402fdf2a5e34aa8db93aa7c50d08
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-09 20:33:46 +02:00
Luiz Augusto von Dentz
4db2c941be net: samples: Enable CONFIG_NET_CONTEXT_NBUF_POOL in prj_bt.conf
Bluetooth consumes buffer when transmitting them therefore any protocol
that need to retain them, like TCP, needs to have its own pool to copy
the buffers as they may need to be resent in case they are not acked.

Change-Id: I483c5a3eb4d54fae6b5b2902c69b67e8c2e0be5e
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-09 20:33:46 +02:00
Ravi kumar Veeramally
a6bc5cbb19 net: core: Fix IPv6 extra header options handling
If the packet contains IPv6 header + Extra header + ICMPv6 headers,
last header does not contain 'next header and length' fields. So
while parsing header we should first check next header and continue
parsing. Otherwise we parse 2 bytes extra and set invalid ext hdr len
and handover to other layers. So everything goes wrong after that.

Also simplified next header parsing to minimal.

Change-Id: I5d8235c5a57c8b77adf6a07eb8eb74350a3e4dc6
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:46 +02:00
Ravi kumar Veeramally
89b7bbfcfd net: core: Remove duplicate calls
If the buffer contains IPv6 header, set header length only once.
Need not to set it in different scenarios.

Change-Id: I54ab9a4259851c9230db240f6091e3190d25b6cb
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:46 +02:00
Ravi kumar Veeramally
3fd8305d6a net: core: Do not handle RPL options if RPL not enabled
If RPL is not enabled do not handle RPL options in IPv6 extra header.
Issues will arise if we skip reading those bytes and continue further.

E.g. Upper layer protocol like ICMPv6 echo request does not prepare
proper echo reply if we skip like this. It doesn't know what options
need to be updated in reply header.

Change-Id: I250672a54d4c7f60727313f6e7f8fe902685d0c5
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:45 +02:00
Ravi kumar Veeramally
4c58593b79 net: core: Fix missing verdict assignment
Verdict not assgined to its proper value and return NULL in case
of read error. Also simplified error handling.

Change-Id: Idf4c5e242066dfd03e1519271dc1ba38ec43e6ce
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:45 +02:00
Ravi kumar Veeramally
5a26d8dacd net: icmpv6: Return valid verdict in case of success
Verdict NET_DROP returned even though it handled properly.

Change-Id: I61e04b12f971b39585e983aa9a1007c63acd8b4e
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:45 +02:00
Ravi kumar Veeramally
e17fe10673 net: icmpv6: Simplify debug calls
Debugging code snippet inside handle_echo_reply() does not look nice,
just provided inline functions and simplified it.

Change-Id: Idc3a9284153aaa04d0431a9dd705c4f1c51b817d
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:45 +02:00
Ravi kumar Veeramally
992549ab40 net: icmpv6: Remove unnecessary cache pointers for src and dst
Earlier net_nbuf_copy_all() mangled the original buffer. So cacheing
src and dst address and other values was necessary. Now original
buffer does not get affected by net_nbuf_copy_all() call. Cacheing
is not required.

Change-Id: I8a8534f7ec299853b9b296d85e8aacecd3768c8e
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:45 +02:00
Ravi kumar Veeramally
476f46f61b net: icmpv6: Remove unused variable 'len' from input calls
Variable len is not used in net_icmpv6_input() and if required
it can be obtained from 'buf'.

Change-Id: I4b0710e1cf16cff9837173ad9d6908ec54ebafae
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:45 +02:00
Jesus Sanchez-Palencia
08f6f5507b net: todo: Remove TCP from TODO
TCP support is already implemented so it can be removed from
TODO file.

Change-Id: I27690120959ffa1e15891e3210bbcc38a3898359
Signed-off-by: Jesus Sanchez-Palencia <jesus.sanchez-palencia@intel.com>
2017-03-09 20:33:45 +02:00
Paul Sokolovsky
46eaa94ec5 net: context: Check if conn_handler exists when binding
If a UDP context had net_context_recv() called before
net_context_bind(), then it will have a stale connection handle
associated with initial (random) port number, while will be "bound"
to a new port as specified in net_context_bind(). So, it silently
won't behave as a user expects. net_context_bind() should really
update (or destroy/recreate) conn_handle in this case, but until
it's implemented, apply stopgap measure of at lease reporting error
back to user in this case.

Jira: ZEP-1644

Change-Id: I22ad55f94eaac487a4d5091ccbb24f973ec71553
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-03-09 20:33:45 +02:00
Leandro Pereira
141c0a5f1a samples: net: NATS protocol sample
NATS is a publisher/subscriber protocol implemented on top of TCP. It
is specified in [1], and this is a sample implementation for Zephyr
using the new IP stack.  The API is loosely based off of [2].

With this sample, it's possible to subscribe/unsubscribe to a given
subject, and be notified of changes asynchronously.  In order to
conserve resources, the implementation does not keep its own track of
subscribed subjects; that must be performed by the application itself,
so it ignore unknown/undesired subjects.

TLS is not supported yet, although basic auth is.  The client will
indicate if it supports username/password if a certain callback is set
in the struct nats.  This callback will then be called, and the user
must copy the username/password to the supplied user/pass buffers.

Content might be also published for a given subject.

The sample application lets one observe the subject "led0", and turn it
"on", "off", or "toggle" its value.  Changing the value will, if
supported, act on a status LED on the development board.  The new
status will be published.

Also worth noting is that most of the networking and GPIO boilerplate
has been shamelessly copied from the IRC bot example.  (Curiously, both
protocols are similar.)

[1] http://nats.io/documentation/internals/nats-protocol/
[2] https://github.com/nats-io/go-nats

Jira: ZEP-1012

Change-Id: I204adc61c4c533661eacfb8c28c1c08870debd91
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-03-09 20:33:45 +02:00
Leandro Pereira
fb192c5da0 lib: Add minimal JSON library
This is a minimal JSON parser (and string encoder helper).  This has
been originally written for the NATS client sample project, but since
it's a generic bit of code, it's also being provided as a library
outside the NATS application source.

It's limited (no support for arrays, nested objects, only integer
numbers, etc), but it is sufficient for the NATS protocol to work.

Jira: ZEP-1012

Change-Id: Ibfe64aa1884e8763576ec5862f77e81b4fd54b69
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-03-09 20:33:45 +02:00
Flavio Santes
760c1f1214 samples/net: Fix error handling issues in IRC bot
Fix the following error:

Calling "transmit(irc->conn, pong, ret)" without checking return value.
It wraps a library function that may fail and return an error code.

Coverity-CID: 163115

Change-Id: I525e1059e6a2ae3896f68760f1a8a6c68ecfc074
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-03-09 20:33:45 +02:00
Flavio Santes
c406be6360 samples/net: Fix uninitialized variable error
Fix "Uninitialized variables (UNINIT)" error found at the
HTTP client sample app.

Coverity-CID: 163117

Change-Id: I3d350fdc0e49a7bb7bea9d7af04494f6e918d603
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-03-09 20:33:45 +02:00
Jukka Rissanen
58d6e20493 net: nbuf: Print more info when trying double free net_buf
Print information who freed the net_buf last time if this
can be figured out. This info is not fully accurate if there
is lot of allocations going on but could give some indicatation
who was using the net_buf previously.

Change-Id: I3d4463c54a9b944847a532d951fb6d2303fc06cf
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:45 +02:00
Jukka Rissanen
aeb08874af net: samples: echo-client: Allow UDP and TCP run at the same time
Run both TCP and UDP to run at the same time. This requires two
extra threads in echo-client sample application.

Change-Id: I450a26d7ab1472150ea8f1309a43897a30bd4d90
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen
a616aa1f58 net: 6lo: ieee802154: Memory leak when unfragmenting received data
If we could not allocate a buffer while unfragmenting, make sure
that all the created temporary net_buf artifacts are freed and
we do not have a memory leak.

Change-Id: Ib98ae32eb4a0f9b5f92c51e9713fd8e6d78b10da
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen
ac7a05bbba net: 6lo: ieee802154: Do no try to unref NULL net_buf
It is possible that the cached buf is NULL so avoid nasty
error print by not trying to free NULL pointer.

Change-Id: Iec53164f6ffab4b830aba63a1f351ca2349a43ff
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen
f8ae384dae net: nbuf: Print adjust value if we fail in read or write
If net_nbuf_read() or net_nbuf_write() offset adjustment fails,
print the offset value in order to make debugging easier.

Change-Id: I899998bdcbc91a25ed7d71a599a5052a6fa4ee36
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen
f031c2be37 net: nbuf: Do not delete the fragments in net_nbuf_unref()
Show only what would be freed when debugging the allocations.
Let the net_buf_unref() to delete the individual fragments.

Change-Id: I1a39a553f12d73b78c4ba08be0e8e8252b666c8e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen
93f7f9f3e6 net: shell: Show also ISR and main stack usage
The "net stacks" command will also print main and interrupt
handler stack sizes.

Change-Id: I1b867be81ac8b4f6d9446f484ebb8b1d852b98b0
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen
f8c60de061 net: nbuf: Create net_nbuf_frag_del() for tracking allocations
Create net_nbuf_frag_del() so that we can track net_buf frees.
If CONFIG_NET_DEBUG_NET_BUF is not defined, then this new function
will call net_buf_frag_del() directly, and if not, then it will
track memory usage.

Change-Id: I5f382436cebc71fdaf12baf7bf964fb63bee7aca
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen
99097e53cb net: shell: Add cmd to see net_buf allocations
This commit adds "net allocs" command that can be used to
track net_buf allocations that are done by net_nbuf_get*()
and net_nbuf_unref().

Change-Id: If3dc2ecf5552f8008138ee9733458a19f9764c13
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen
38d26d07e9 net: nbuf: Track memory allocations
User can track memory allocations and deallocations.
This is enabled by CONFIG_NET_DEBUG_NET_BUF option.

Change-Id: I9d83b9b63fb2b141c9a283887f1770bb4232f61c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen
573eea0884 net: nbuf: Remove unnecessary buf init
No need to set the buf to NULL as it will get its value
from net_buf_alloc() call anyway.

Change-Id: Ib3a32b6e4cb4b446761b6a97a88c20fc52d3d683
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen
038664ac6f net: if: Clarify the documentation in net_if_send_data()
Add description what happens if NET_DROP is returned from
L2 send function.

Change-Id: I371de725b710041bb26a141f9860c0062fb1ef5d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen
57150538bd net: nbuf: Remove obsolete reserve variable from net_nbuf
There is no user for the reserve variable inside struct net_nbuf
so remove it.

Change-Id: I45750215cefa2227002eb2de57f080823e7013ce
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen
5032bdc46d net: nbuf: Pass ll_reserve when creating TX buffer
Instead of always calling net_nbuf_get_reserve_tx() with zero
ll_reserve (first parameter) and then setting the link layer
reserve separately, pass the reserve to that function which can
then set the ll_reserve in buf itself.

Change-Id: I21c14cb7e2e6c36d170c09998bca0207ecf65c75
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen
189ec2b6ad net: Remove link layer reserve param from IP packet creator
The ll_reserve parameter is useless in net_ipv{4|6}_create_raw()
function as the reserve information is already stored in buf.

Change-Id: I7815a78c001e3da532478c04b3dac9b37bbc723c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen
5197266768 net: nbuf: Use net_nbuf_get_frag() to allocate a fragment
The code used net_nbuf_get_reserve_{rx|tx}_data() function to
allocate a fragment. Instead of that low level function, use
net_nbuf_get_frag() instead. There are few places this is not
possible or is too big change like in few test programs.

Change-Id: Ied7e2b7db352de998b200ffa6ff82471bfa5ebe3
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen
0fdee2ef5d net: nbuf: Print pool name instead of address in debug prints
The net_buf pool address is not very useful so print the
user friendly name of the pool instead.

Change-Id: I1c64621c816832d2459819490ec5609f5c39f9f1
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen
4111b994b7 net: shell: Fix the info prints for net_buf pools
The columns were not aligned properly.

Change-Id: I551d04182c2877a29bb02a9da5400d74a080a1c9
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen
d32503f57e net: nbuf: Split one global DATA pool to RX and TX DATA pools
If we receive lot of packets, it might happen that we exhaust
all the DATA buffers in the system. This would prevent from
us sending anything to the network.
Change this by splitting the DATA buffer pool into RX and TX
parts. This way RX flooding cannot consume all DATA buffers
that needs to be sent.

Change-Id: I8e8934c6d5fdd47b579ffa6268721b5eb3d64b6d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen
2478dd250b net: context: TCP packets must be send via net_tcp_send_data()
Do not shortcut the sending side for TCP as we need to use
net_tcp_send_data() to send TCP data in order not to have
double unref in Bluetooth or IEEE 802.15.4 technologies which
has a special TCP packet sending logic.

Change-Id: I077db336c6335ccdbbafa4600f98388ecf33955f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen
93533b37d8 net: tcp: Fix the issues with 6lo
When sending TCP data using 802.15.4 or Bluetooth technologies,
the 6lo code modified the original IPv6 header. This caused
issue when acknowledgment was waited to the sent packet as
the code could never match the sequence and ack numbers in
TCP header.

This commit changes this and the packet is cloned when sending
it so the 6lo code will modify a copy of the data and will not
touch the original packet.

JIRA: ZEP-1719

Change-Id: Iae51f35d5b5ada0d2543b58a29abbf10f146777e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen
e18f76ce60 net: conn: Print UDP and TCP checksum after receiving pkt
Enhance the connection debugging and print the UDP and TCP
checksum when the packet is received.

Change-Id: I1ccf58a299178277fab0667b01d54ad7bac38663
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen
30a3f5ce88 net: 6lo: Change how net_buf is allocated in RX side
If there is lot of network traffic, it is possible that all the
network packets are allocated by network driver. The device driver
places the received packets into RX queue. Then that queue is read
by 6lo code. During the uncompression, the 6lo code tries allocate
net_buf in order to place proper IPv6 header into it.
If all the data fragments are in use at this point, then 6lo cannot
continue and it blocks while waiting available net_buf. This leads
to deadlock in the stack.
The solution is to change the 6lo to allocate the net_buf using a
timeout which will cause the received packet to be dropped if it
cannot be uncompressed because of out-of-buf situation.

Change-Id: I137f02b05193e16c45da8804974d357c920c861d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00