Commit graph

41120 commits

Author SHA1 Message Date
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
Jukka Rissanen
10979d8326 net: 6lo: Use dedicated buf pool if enabled
When doing 6lo compression or 802.15.4 fragmentation,
use the API that uses dedicated net_buf pool if that
support is enabled by the user.

Change-Id: Ic6651c393832c759eebb66a41db31c9067ebb4a9
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen
eb35c8dcae net: nbuf: Add helper function to copy buf user_data
The function copies the net_buf user data (struct net_nbuf).

Change-Id: I2ea42823d58aea77ea7b710f6ce5fd5d1e3641b4
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen
4bcc2a47d0 net: nbuf: Fix net_nbuf_copy() so that original nbuf is not modified
It makes no sense to modify the original net_buf so change the
copy function not to touch the original buffer.

Change-Id: I5d22445ce50cee62994c36567f0e995a500cb89d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:42 +02:00
Jukka Rissanen
6a4372b0df net: nbuf: Fix the net_nbuf_copy() buf parameter
The first parameter of net_nbuf_copy() must be the head
of the buffer chain i.e., it must contain the user_data
part. If a fragment is given, then we do not know enough
information to allocate the data fragments.

Change-Id: I052b183d8c63d7326b320254f36f00b2fc48b0a0
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:42 +02:00
Jukka Rissanen
a5dbf31b3a net: shell: Print network buffer pool information
Print information about various network buffer pools in the
system. This is useful in debugging the buffer allocations.

Change-Id: I31123c6f1f6647f77503f32e268c174330762128
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:42 +02:00
Jukka Rissanen
230de764a9 net: buf: Store name of the buffer pool
This is used to show the name of the pool during debugging.

Change-Id: I3a3c3c853e5fe13fd11f6ffd9e1feea4abf0c248
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:42 +02:00
Jukka Rissanen
ee0cff9ac7 samples: net: Use context specific net_buf pools in echo_*
Use context specific net_buf pool in echo-server and echo-client.
This will prevent application from allocating all available network
buffers in the system and thus preventing the core IP stack
functionality.

Change-Id: I3dbc64dd81c8a1165241426287a3530d00cbc7bf
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:42 +02:00
Jukka Rissanen
7719cee113 net: Add net_buf pool support to each context
User can configure its own pools for data that needs to
be transmitted out (TX). This helps to avoid deadlocking
the system if user space application uses all the buffers
in the system, and the core IP stack tries to get buffer
that needs to be sent out.

By default the net_buf pool support in net_context is turned
off as application developer needs to create the pools and
tie them to desired contexts.

Change-Id: Ida4a1771d34d6c250974e56fba4f0e0b2592cb29
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:42 +02:00
Jukka Rissanen
9fce1626d7 net: nbuf: Remove unnecessary debugging code
As the pool contains now more accounting information, there is
no need to keep track of this data in nbuf.c.

Change-Id: I7fd44f9feda8fd9816356556d1e788ad56e6eedd
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:42 +02:00
Jukka Rissanen
7218d0d64b net: buf: Add more accounting info to net_buf pool
Adding this information to the pool:
* number of available (free) buffers in pool
* total size of the pool in bytes

This can be used when debugging net_buf pool allocations.

Change-Id: I4212fcddb1affdf53e0827c88473d3380e2a4929
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:42 +02:00
Marcus Shawcroft
e82818c59b eth/eth_mcux: Make promiscous mode configurable.
Provide a configuration option for promiscuous mode.

Promiscuous mode provides a convenient workaround for ZEP-1673 however
it generates significant demand for RX buffers on a loaded network.
Add a configuration option to conveniently enable / disable.

The Kconfig defaults promiscuous on to workaroudn 1673, once that
issue is resolved the default logic on NET_IPV6 will be dropped.

Change-Id: I6929aca70d7bd88ce88c65d6654d664ea6653b66
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:42 +02:00
Marcus Shawcroft
7c193b7f9f net/dhcpv4: Support REBINDING
Change-Id: I1e3809b3cde1dec29a001e750cb191cfac046dab
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:42 +02:00
Marcus Shawcroft
f8cc065d13 net/dhcpv4: Refactor t1 handler.
Rewrite the dhcpv4_t1_timeout() handler to explicitly handle all
states.

Change-Id: I6f9d6c8cfacd945e24eb66c6440bf305d528c521
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:42 +02:00
Marcus Shawcroft
b42a6b3192 net/dhcpv4: Remove !iface checks from timeout handlers.
The iface handle checks in the both timeout handlers are unnecessary.
Drop them.

Change-Id: Ie7c884b2ea648f700fbefa8382341036a4db063f
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:42 +02:00
Marcus Shawcroft
b0df4bf260 net/dhcpv4: Fix the behaviour of ciaddr.
Correct the logic that determines when CIADDR is set and when it is
left as all zeros. RFC2131 requires that CIADDR is only set when the
client is in specific states.

Change-Id: I93a45e355fbef8d11dba5ac194570b87c594656e
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft
045d317b9b net/dhcpv4: Use BROADCAST and UNICAST appropriately.
RFC2131 places explict requirements on a client w.r.t which messages
are broadcast and which are unicast directly to a server.  Notable
rules as they apply to the current dhcpv4 implementation are that
DISCOVER and a REQUEST in response to an OFFER are broadcast.  A
REQUEST in state RENEWAL is unicast.  There are further rules relevant
to the REBINDING state which is not yet implementated.

Adjust the current implementation that always uses broadcast to use
unicast as required by RFC2131

Change-Id: I6edef4241bcd74623a804a73415888cd679888d0
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft
4b24c18f5f net/dhcpv4: Use server identifier appropriately.
RFC2131 requries that a client MUST NOT include server identifier in
DHCPREQUEST from state RENEWING.

Change-Id: I0fba703f3a3b218af1ac03f4f1f0daa290bd428f
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00