Commit graph

808 commits

Author SHA1 Message Date
Jukka Rissanen 48f9dccc32 net: tcp: Allow ACK timeout to be configured
The timeout value when waiting ACK in various TCP states can
be configured via Kconfig.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-18 15:08:12 +03:00
Jukka Rissanen 27b5540118 net: tcp: Set timer for last ACK
If we do not receive last ACK when the connection is tore down,
then do not wait forever as that would eat all the resources in
the network stack. So when we enter the LAST_ACK state, we setup
a timer that will unref the connection if the last ACK is not
received.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-18 10:56:39 +03:00
Paul Sokolovsky d6b93b311f net: tcp: When sending FIN, make sure it goes with ACK and proper seq
Without change to add ACK to FIN, invalid TCP packet is generated,
where ack sequence number is non-zero. Without adjusting sequence
number as done, ACK which we send in response to peer's FIN/ACK is
not recognized by peer, and peer keeps retransmitting its FIN/ACK.

Jira: ZEP-2104

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-05-18 10:56:11 +03:00
Jukka Rissanen 6f25eb097e net: conn: Remove unregistered connection from cache
When connection handler was unregistered, we did not remove
it from cache. This caused invalid connection to be passed to
net_context after connection unregister if connection caching
was enabled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-18 10:55:17 +03:00
Jukka Rissanen 69b25c0788 net: conn: Check UDP and TCP checksum before accepting packet
We did not check UDP or TCP checksum to be valid after receiving
the packet. Fix this so that the checksum is validated when
packet is received in connection handler. As the checksum validation
can be resource intensive, do it after we have verified that
there is a connection handler for this connection.

The checksum calculation can be turned OFF if needed, but it is
ON by default.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-18 10:53:39 +03:00
Jukka Rissanen 6c60603a9f net: context: Shorten too long line
The commit "net: tcp: Handle retransmitted packets from peer"
introduced over 80 character line that was missed in review.
Fixing it now.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-17 16:55:02 +03:00
Jukka Rissanen bddacf6a7f net: stats: IPv6 multicast listener daemon stats not printed
The MLD statistics were collected but never printed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-17 13:55:21 +03:00
Jukka Rissanen e5257ae790 net: stats: Activate RPL and MLD stats if needed
If user has enabled RPL and STATISTICS, then enable RPL
statistics by default as that is probably what user want.
Same thing for MLD statistics.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-17 13:55:21 +03:00
Jukka Rissanen 9f1c7ffa5d net: stats: Add UDP checksum stats update function
A function updating UDP checksum failure statistics was missing.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-17 13:55:21 +03:00
Jukka Rissanen e253dcbd3b net: tcp: Add TCP statistics support
We did not collect any TCP statistics before but this commit
changes that.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-17 13:55:21 +03:00
Paul Sokolovsky 7a1a9a7946 net: tcp: Handle retransmitted packets from peer.
When we receive a packet with the sequence we already seen (and
processed), the most likely cause of it is that our ACK was lost,
and peer has to retransmit that packet. Then, we should just ACK
it, because otherwise peer will retransmit it again and again,
falling into exponential backoff and hosing the entire TCP
connection.

This makes changes to send_ack(), adding a flag to force sending
an ACK regardless of its cached status, and remove inline modifier,
as the function is big and called from many places.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-05-17 10:34:11 +03:00
Jukka Rissanen c6fcda19a3 net: tcp: Always set ACK bit in RST packet
Set the ACK bit in every RST packet as that seems to be expected
by Linux for example.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-17 09:36:02 +03:00
Jukka Rissanen 00b4081da3 net: tcp: Handle case when RST is received in any state
We must check if we receive RST in any of the TCP states.
If we do not do this, then the net_context might leak as it
would never be released in some of the states. Receiving RST
in any TCP state is not described in TCP state diagram but is
described in RFC 793 which says in chapter "Reset Processing"
that system "...aborts the connection and advises the user and
goes to the CLOSED state."

We need to also validate the received RST and accept only those
TCP reset packets that contain valid sequence number.

The validate_state_transitions() function is also changed to
accept CLOSED state transition from various other states.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-17 09:34:51 +03:00
Paul Sokolovsky e4a5e35b28 net: if: net_if_get_default: Return NULL if no interfaces configured
net_if_get_default() was documented as returning "Default interface
or NULL if no interfaces are configured.", but actually didn't
return NULL in the latter case. Instead, it effectively returned
a pointer to random area of memory, shared with other system
structures, so calling functions like net_if_ipv4_set_netmask(),
etc. could trash unrelated memory.

Jira: ZEP-2105

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-05-16 14:32:58 +03:00
Paul Sokolovsky 72a30f3843 net: tcp: Add TCP sequence number comparison compliant with RFC793.
RFC793, "Transmission Control Protocol", defines sequence numbers
just as 32-bit numbers without a sign. It doesn't specify any adhoc
rules for comparing them, so standard modular arithmetic should be
used.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-05-16 14:29:17 +03:00
Jukka Rissanen 43b37cef31 net: conn: Check duplicate UDP/TCP connection handlers
When a new UDP or TCP connection handler is to be registered,
we need to check if identical handler has already been created.
If a duplicate is found, the registering call will return -EALREADY.

The earlier code did not check this but allowed two identical
handlers to be created. The latter handler was never called in
this case.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-13 14:30:58 -04:00
Jukka Rissanen c77460da53 net: pkt: Add function to linearize a network packet
This helper copies desired amount of data from network packet
buffer info a user provided linear buffer.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-13 14:30:58 -04:00
Andrew Boie 7a0782d8ee net: use k_thread_create()
Common code in include/misc/stack.h is now used for analysis.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-05-11 20:24:22 -04:00
xiaorui hu cffb79a4e1 net: context: set tcp app data len when sending packets
When we send TCP data segment, we need to set the length
of the application data by calling net_pkt_set_appdatalen().
This is done so that sequence number can be properly
advanced when we receive ACK to that pending packet.

Signed-off-by: xiaorui hu <xiaorui.hu@linaro.org>
2017-05-08 08:07:41 -04:00
David B. Kinder f930480e16 doc: misspellings in Kconfig files
fix misspelling in Kconfig files that would show up in configuration
documentation and screens.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-05-05 19:38:53 -04:00
Luiz Augusto von Dentz 08eb5fc428 net: bt: Fix not setting lladdr type
When adding link-local address to the cache the type needs to be
properly set as net_ipv6_addr_create_iid will attempt to use it
when generating the IPv6 address.

Jira: ZEP-2077
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-03 08:48:24 -04:00
Jukka Rissanen 6a52a30b7d net: tcp: Mark ACK timer as cancelled
This is related to commit "net: tcp: Make sure ACK timer is not
run if cancelled" which did not set the cancel flag when the timer
was cancelled from tcp.c.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-03 08:48:24 -04:00
Tomasz Bursztyka e0a643591d net/net_if: Do not start TX thread if there is no network interface
And print a warning if that happens.

This will also avoid to raise an ASSERT on net_if_tx_thread()'s k_poll
as this one will be called with no events to work with.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-05-03 08:41:57 -04:00
Paul Sokolovsky ff3b019054 net: shell: Make shell commands non-static to allow reuse.
Some applications may want to reuse implementations of these
commands for debugging/diagnostics purpose even if they don't
use net shell per se, or implement an alternative shell.

Jira: ZEP-2064

Change-Id: I48cb66ccc41bd41a75a4eb8eb3c366316ec5a096
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-04-28 15:01:12 +03:00
Ravi kumar Veeramally ead481a041 net: rpl: Fix invalid usage of router addition api
net_if_ipv6_router_add() will return router pointer on success.
This information must be cached in RPL instance, otherwise RPL
instance doesn't know about default route.

Change-Id: Ic6d80ebfa95c9a64df9adf2621ae2631d9bdb990
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-28 15:01:11 +03:00
Ravi kumar Veeramally 5edf55f771 net: rpl: Fix router when it's timer expires
When router or default router timer expired, interface will remove
router from the list. In this case RPL does not know about this.
When RPL node receives DIO messages it only verifies whether parent
exists or not. This extra checks will verify whether router really
in "used" state or not.

Jira: ZEP-2080

Change-Id: I4b36b3a2d495e76a38caddd058451daff08fab0c
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-28 15:01:11 +03:00
Ravi kumar Veeramally d9bde9a5ab net: ipv6: Use correct API to remove router
net_if_ipv6_router_rm() is the correct API to remove IPv6 router
from the interface as it also cancels the timer and raises a mgmt
event. The net_if_router_rm() only sets router as unused and
nothing else.

Change-Id: I55114288c9ae748520b67b206edcd4f5e420b1af
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-28 15:01:11 +03:00
Luiz Augusto von Dentz 86a72e1ed4 net: bt: Fix leaking TX packets
Bluetooth only cares about the actual payload so net_pkt can be unref
as soon as the data fragments are detached.

Jira: ZEP-2070
Change-Id: Id528d5440f42903378883f5e696b3f663bbfa313
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-28 15:01:10 +03:00
Paul Sokolovsky 25307d5331 net: net_pkt_append: Refactor to return length of data actually added
For stream-based protocols (TCP), adding less data than requested
("short write") is generally not a problem - the rest of data can
be sent in the next packet. So, make net_pkt_append() return length
of written data instead of just bool flag, which makes it closer
to the behavior of POSIX send()/write() calls.

There're many users of older net_pkt_append() in the codebase
however, so net_pkt_append_all() convenience function is added which
keeps returning a boolean flag. All current users were converted to
this function, except for two:

samples/net/http_server/src/ssl_utils.c
samples/net/mbedtls_sslclient/src/tcp.c

Both are related to TLS and implement mbedTLS "tx callback", which
follows POSIX short-write semantics. Both cases also had a code to
workaround previous boolean-only behavior of net_pkt_append() - after
calling it, they measured length of the actual data added (but only
in case of successful return of net_pkt_append(), so that didn't
really help). So, these 2 cases are already improved.

Jira: ZEP-1984

Change-Id: Ibaf7c029b15e91b516d73dab3612eed190ee982b
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-04-28 15:01:09 +03:00
Jukka Rissanen 3051fc2035 net: rpl: Do not crash if DIO message contains garbage
Instead of just plain assert, check that the packet we receive
is ok before passing it to processing function.

Jira: ZEP-2057

Change-Id: I5754c82d16e1522d8fcee561eea280eadeec31ee
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-28 15:01:09 +03:00
Jukka Rissanen 52d0589c1f net: tcp: Fix TCP trace value debug
The TCP trace values were not printed because of incorrect
config option used. Print also seq and ack values in decimal
in order to make it easier to correlate the values in other
prints in tcp.c.

Change-Id: I44d1535a84dcba8c6c937d348516ba801193ca23
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-28 15:01:09 +03:00
Andrei Emeltchenko 65c002b8ce net: security: Use sys_put_be32() relevantly
Use ready-made utility function which can take care of endianness

Change-Id: I1edd0b2ce1a086dd637e97308145f9b434e48a1f
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-04-28 15:01:09 +03:00
june li 3e4faffede net: l2: Clear arp cache when disable interface.
When connect to diffrent router with the same gateway ip address,
need to clear arp cache when disable interface,
or it will use the wrong gateway mac address.
Call net_arp_clear_cache function replace to set arp_table 0.

Change-Id: Ib403a0c0030832ba48824db4d2d3fcb8add63d16
Signed-off-by: june li <junelizh@foxmail.com>
2017-04-28 15:01:08 +03:00
David B. Kinder 61de8f892b spell: Kconfig help typos: /kernel /misc /subsys
Fix misspellings in Kconfig help text

Change-Id: I6eda081c7b6f38287ace8c0a741e65df92d6817b
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-04-22 01:04:56 +00:00
Kumar Gala a509441210 net: convert to using newly introduced integer sized types
Convert code to use u{8,16,32,64}_t and s{8,16,32,64}_t instead of C99
integer types.

Jira: ZEP-2051

Change-Id: I4ec03eb2183d59ef86ea2c20d956e5d272656837
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-21 09:30:38 -05:00
Jukka Rissanen af1e3b9d32 net: shell: Fix compiler error when printing conn handlers
There was compiler error if CONFIG_NET_DEBUG_CONN was set.

Change-Id: Ibb6721c55dd2c56cd0097359a53563c6221859ea
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-21 15:44:22 +03:00
Jukka Rissanen d8dd91d7bf net: context: Connect callback was set too late
We need to set the connect_cb for the context before sending SYN packet.
This is required if we have a loopback connection in which case everything
is happening more or less synchronously and the connect_cb would not be
called in this case because its value would still be null.
For remote network connections this patch makes no difference.

Change-Id: Id7f837cd9e81cd79c4666c98cae84f6cb1a77af0
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-21 15:44:22 +03:00
Jukka Rissanen 1bf14853aa net: tcp: Make sure ACK timer is not run if cancelled
We must not let ACK timer to run if we have already cancelled it.
So keep track that the timer is cancelled and refuse to run it
if it was indeed cancelled. The reason why the timer might be run
in this case is because the timer might be scheduled to be triggered
after which one cannot cancel it.

Change-Id: I1c8b8cee72bc7a644e02db154d9d009b8d98ade2
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-21 14:19:52 +03:00
Jukka Rissanen 137e4e7256 net: context: Set the local port correctly in accept
The local port was set to 0 for IPv6 when registering
the connection handler. For IPv4, the code was not setting
the port in local_addr struct.

Change-Id: I82f0c08641a94d75d255ac306eca7bec6c332fba
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-21 14:19:52 +03:00
Jukka Rissanen a1c4f3fbd5 net: Print debug info if packet is loopback back to us
Without this info it is a bit difficult to notice what is going
on in loopback case.

Change-Id: I8f61330c01d025e41f00d663bd26947b8cafb5c0
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-21 14:19:51 +03:00
Jukka Rissanen a71a9f9ad1 net: conn: Utility to print connection handlers
Add support to print connection handler information in net-shell.
There exists one connection handler for each UDP/TCP port that we
are listening. These prints are only available if CONFIG_NET_DEBUG_CONN
is enabled because the net_context has the same information. Thus the
connection handler info is only printed if debugging is active in order
to verify that handler information is proper.

Change-Id: I0be39a5adb89b2cdbd85524c5d943e4a562b0fde
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-21 14:19:51 +03:00
Jukka Rissanen f498a90b77 net: pkt: Make the debug print eye friendly
Print "pkt" instead of "Pkt" when printing network packet
pointer value.

Change-Id: Id4225be9c55807def3d892d372cdfc5c79c871fc
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-21 14:19:51 +03:00
Jukka Rissanen 52339cdf5a net: tcp: Avoid unused variable compiler warning
If TCP debugging is enabled but if the loglevel is set to lower
than 4, then compiler prints warning about unused flags variable
in net_tcp_trace().

Change-Id: I2e663644b50fe97b75088202e21b286aa010953e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-21 14:19:51 +03:00
Tomasz Bursztyka f3ff4f7bd3 net_pkt: Let's make all IPv6 related attributes prefixed with ipv6_
Only 2 attributes lacked this prefix, which makes sense to have, so
applying it accordingly and changing the helpers as well.

Change-Id: I095b2729f977f8fb1624eff8801a4a4e21416693
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-21 14:19:51 +03:00
Tomasz Bursztyka e5896906f6 net: Rename all *_BUF() macros to *_HDR()
Most of these macros are not exactly exposing a buffer, but a specific
header pointer (ipv6, ivp4, ethernet and so on), so it relevant to
rename them accordingly.

Change-Id: I66e32f7c3f2bc75994befb28d823e24299a53f5c
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-21 14:19:51 +03:00
Tomasz Bursztyka c18016b69b net_pkt: Externalize ext_bitmap handling
IPv6 next headers are processed in a way so it is not required to store
which header has been already seen in the net_pkt, as the processing loop
can store internally which one it has seen already.

Change-Id: I266ba8a3a0081a162318cdafb474a0fc44a3185e
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-21 14:19:50 +03:00
Tomasz Bursztyka 2e331de690 net_pkt: Removing legacy net_dir
This is actually useless as there is only 1 RX memory slab, and thus can
be removed to reduce net_pkt structure size.

Change-Id: I62d716515120e7356ee1e2d75bbe1ec32e22c35d
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-21 14:19:50 +03:00
Tomasz Bursztyka db11fcd174 net/net_pkt: Fully separate struct net_pkt from struct net_buf
- net_pkt becomes a stand-alone structure with network packet meta
  information.
- network packet data is still managed through net_buf, mostly named
  'frag'.
- net_pkt memory management is done through k_mem_slab
- function got introduced or relevantly renamed to target eithe net_pkt
  or net_buf fragments.
- net_buf's sent_list ends up in net_pkt now, and thus helps to save
  memory when TCP is enabled.

Change-Id: Ibd5c17df4f75891dec79db723a4c9fc704eb843d
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-21 14:19:50 +03:00
Tomasz Bursztyka bf964cdd4c net: Renaming net nbuf API to net pkt API
There have been long lasting confusion between net_buf and net_nbuf.
While the first is actually a buffer, the second one is not. It's a
network buffer descriptor. More precisely it provides meta data about a
network packet, and holds the chain of buffer fragments made of net_buf.

Thus renaming net_nbuf to net_pkt and all names around it as well
(function, Kconfig option, ..).

Though net_pkt if the new name, it still inherit its logic from net_buf.
'
This patch is the first of a serie that will separate completely net_pkt
from net_buf.

Change-Id: Iecb32d2a0d8f4647692e5328e54b5c35454194cd
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-21 14:19:50 +03:00
Andrei Emeltchenko 9bf3ea071a net: shell: Correct print format specifier
Fix warning using incorrect format specifier

Change-Id: Ib6800c40b2cd769612ae6f107e41a941926d8e66
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-04-21 14:19:50 +03:00
june li 504b273b85 net: tcp: Do buf ref when resending a segment
We need to check whether buf_sent was true when resending the TCP
segment, and do a buf ref if needed. If this is not done, the buf
will be unref after send, which will cause unpredictable results.

Change-Id: Ibd4490305de88ac6ffd04ec42bba196e57da5c10
Signed-off-by: june li <junelizh@foxmail.com>
2017-04-21 14:19:50 +03:00
Jukka Rissanen 7ce82fea82 net: ipv6: Make sure not to access null pointer
While very unlikely it might happen that fragment pointer is NULL
when going through fragment list.

Coverity-CID: 167148

Change-Id: Ic3dbed7ee29c7b864d4830d726f65d7f62dcea84
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-21 14:19:49 +03:00
Ravi kumar Veeramally 2f73c324aa net: rpl: Fix rpl header update
When net_ipv6_finalize_raw() inserts RPL(HBH) header after IPv6 header,
it updates IPv6 next header as HBH and HBH next header as original IPv6
next header.

Then net_ipv6_prepare_for_send() will update RPL HBH header if it exists.
But net_rpl_update_header() is comparing HBH option and IPv6 next header,
which is wrong. Wrong comparion does not update RPL instance id and
sender rank. Peer nodes drops all the packets due to invalid instance
ID and sender rank.

Change-Id: I91c1870a09c60f8e1ebc73e434dcc208caf6299a
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-21 14:19:49 +03:00
Mitul Shah d27ca378b6 net: context: Fixing bug in net context put flow
Following flow does not work:
net_context_get
net_context_bind
..
..
net_context_put
net_context_get
net_context_bind

At instance of call to net_context_bind, conn_handler
is not NULL and returns with EISCONN.

This patch sets conn_handler to NULL in net_context_unref

Change-Id: I56a50839101b22161644b3cd7c5f510fa1abae3e
Signed-off-by: Mitul Shah <mitul.a.shah@intel.com>
2017-04-21 14:19:49 +03:00
Paul Sokolovsky 52e3e5c68d net: shell: conn: Dump local/remote ports for contexts.
Without port numbers, information printed by net shell's "conn" command
is unclear and non-differentiating. Also, improve handling of unknown
address families - don't abort early, still pring context address, iface
address, etc.

Example of "conn" output with these changes from echo_server sample:

net> conn
     Context   	Iface         Flags Local           	Remote
[ 1] 0x001126e0	0x001121a0    6DU   [::]:4242	[::]:0
[ 2] 0x00112738	0x001121a0    4DU   0.0.0.0:4242	0.0.0.0:0
[ 3] 0x00112790	0x001121a0    6ST   [::]:4242	[::]:0
[ 4] 0x001127e8	0x001121a0    4ST   0.0.0.0:4242	0.0.0.0:0

TCP        Src port  Dst port   Send-Seq   Send-Ack  MSS    State
0x00112b00     4242         0  497073352          0  1280
0x00112b98     4242         0  497543793          0  1460

Change-Id: I2f03efd933979b5571f608c28a7a7a4bd7f5346a
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-04-21 14:19:49 +03:00
Kumar Gala 789081673f Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t.  This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.

We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.

We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.

Jira: ZEP-2051

Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-20 16:07:08 +00:00
David B. Kinder 0ffb648210 spell: fix doxygen comment typos: /subsys
Fix doxygen comment typos used to generate API docs

Change-Id: I3efff6f5fa26f87d1e658d6336fef01ce45f5bb0
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-04-19 18:44:06 +00:00
Bogdan Davidoaia 290e1d8451 net: use UNALIGNED_GET/PUT to access IP address
Use UNALIGNED_GET and UNALIGNED_PUT throughout the networking stack to
access fields from the IP address structure. These structures can be
mapped directly to buffers and the macros are required for correct
unaligned memory access.

Jira: ZEP-2012

Change-Id: I55f9da7b143a22fa869d5d215c661de988cd9b91
Signed-off-by: Bogdan Davidoaia <bogdan.davidoaia@linaro.org>
2017-04-13 15:21:46 +03:00
Tomasz Bursztyka 987df43ba5 net/ieee802154: Add ieee15_4 shell module functions to set/get tx power
Change-Id: I1245686118daa1c81691694b4b4c1512847beca0
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-13 15:21:46 +03:00
Tomasz Bursztyka 3a3636ff7f net/ieee802154/samples: Add a Kconfig option to tweak the TX power
This can be useful to override the default value, for testing.

Change-Id: I23b559152c71955ff5aa6fd3643f1f40f5594194
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-13 15:21:46 +03:00
Tomasz Bursztyka 26b5f94a79 net/ieee802154: Add a Kconfig option to set a default tx power
Change-Id: Ife2af22c13954286d8e44c3e0b1f60962c617c52
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-13 15:21:46 +03:00
Tomasz Bursztyka 951294f15e net/ieee802154: Expose TX power setting through net mgmt API
This permits to tweak the TX power in dbm.

Change-Id: Idadff397941a39010ce3c374d9ca74b777934626
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-13 15:21:46 +03:00
Tomasz Bursztyka 63619b503f net/ieee802154: Fixing a typo in net_mgmt settings accessor
s/SET/GET obviously

Change-Id: Ibaad65f846fef8b1b7839616b2022fad6548612a
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-13 15:21:45 +03:00
Jukka Rissanen f8c9439908 net: if: Reshuffle fields in net_if and related structs
This does not save any space but sets the fields in the
structs in more natural order. Move IPv6 related
fields in net_if into internal ipv6 struct so that all
IPv6 fields are located inside one struct. Same thing
is done for IPv4 fields which are now located inside
IPv4 internal struct in net_if.

There is no functionality changes by this commit.

Change-Id: I7d72ec0a28e2b88c79a4c294655d5ef6da6ccb25
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:45 +03:00
Tomasz Bursztyka 62b710384d net/ieee802154: aux sec header frame counter is in little endian
So manipulating it requires to be ready to swap it if the CPU is BE.

Change-Id: I8d657c31cecfc9f3fcd010efbb6d090bf021f5f5
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-13 15:21:45 +03:00
Jukka Rissanen 57e128654b net: mgmt: Add IPv6 DAD succeed/failed event
We need a way to know when IPv6 address is successfully set
into network interface.

If IPv6 DAD (Duplicate Address Detection) succeeds or fails,
we send a management event for that. This can be used by
other components to detect when the network interface is in
usable state.

Change-Id: Ifb22415fe21f31f5dba4f55455d6e0f89b414d32
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:45 +03:00
Jukka Rissanen 528a393470 net: ipv6: Fix the constness of function parameters
Some of the IPv6 utility functions were missing const in
one of the parameters that are not modified by the corresponding
function.

Change-Id: Ic9fe53daac288570c14423fd9410dcf15d1c5cfa
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:44 +03:00
Luiz Augusto von Dentz 076ddacca5 net: ipv6: Rework net_ipv6_nbr_add
This makes net_ipv6_nbr_add able to update entries so it can be reused
when receiving RA or NS requests, so it now performs a lookup before
creating a new entry (using nbr_new to reuse more code) and in case it
finds a match attempts to update the lladdr.

Change-Id: I305a67a955e037cbbb862fef947a5fcfe131507c
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-13 15:21:44 +03:00
Luiz Augusto von Dentz 8b23e3e984 net: ipv6: Fix not initializing delayed work
net_ipv6_nbr_add shall init the delayed work as nbr_new does, so this
unifies both codes into nbr_init which does take care of initializing
the fields properly.

Change-Id: I91746276d346a3dc3c36be20d49bcf1968245fc5
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-13 15:21:44 +03:00
Jukka Rissanen 07438ead0d net: shell: Fix printk format for multicast routes
Route lifetime was printed using wrong modifier.

Change-Id: Ib503d50b5817491984d51bbdaadf7457fdde178b
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:44 +03:00
Jukka Rissanen d1ac3d6914 net: rpl: Fix compilation if MRHOF is enabled
Make sure the RPL is compiled ok if CONFIG_NET_RPL_MRHOF is
enabled in the configuration.

Change-Id: I51fc0e20f854164c7e0374fa6a1ebf1d4e4dbc5b
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:44 +03:00
Jukka Rissanen 43847e751d net: rpl: Fix compilation if CONFIG_NET_RPL_MOP3 is enabled
If multicast routing is set meaning that MOP3 (Mode of Operation)
is enabled, then the code was not compiling properly.

Change-Id: Ice8a9f7b705c781536d3c2c5ca6cc2bb77a7acc1
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:44 +03:00
Jukka Rissanen c7102c77a2 net: route: Fix compilation error
Change-Id: Ib4ed6fffe637ac9cd67ce4685d540730c26c8339
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:44 +03:00
Jukka Rissanen 42bd36ec77 net: ipv6: Allow user to tweak packet hop limit value
The default hop limit is defined in struct net_if. It is possible
that user might want to tweak it for each network packet. For this
purpose, a net_nbuf_set_ipv6_hop_limit(buf) function is created.

Change-Id: I7568330358f80f0f5007d6d3c411c120b043c04f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:43 +03:00
Jukka Rissanen 31d3406efa net: rpl: Fix the statistics collection
The Kconfig.rpl file was missing option to actually collect
RPL statistics. Unified the config option name to be
CONFIG_NET_STATISTICS_RPL as there was two conflicting settings
in the code and both of them were missing from Kconfig file.

Change-Id: I4ce4fcbaa317b36cac315ea3b3f710fa7a344b25
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:42 +03:00
Jukka Rissanen dc9f8629b2 net: rpl: Add checks for probing timer
The probing_timer is only available if CONFIG_NET_RPL_PROBING
is defined.

Change-Id: I2835d17e6c3d616f815f8beefd87d2571a5ad94c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:42 +03:00
june li 961d7fc8f4 net: tcp: Release buf after failing to send
After failing to send the buf we need to release it.
This is not done for Bluetooth or IEEE 802.15.4 links which
create a copy of the sent buf and the failure case is already
checked by net_tcp_send_buf().

Change-Id: Ia556376b58ad74f68accb64eb2221a78d59dc2ec
Signed-off-by: june li <junelizh@foxmail.com>
2017-04-13 15:21:42 +03:00
Bogdan Davidoaia 8f97651d23 net: use UNALIGNED_GET in net_addr_ntop
Use UNALIGNED_GET in net_addr_ntop as the uint16_t pointer used in this
function can point to an unalined address.

Jira: ZEP-2012

Change-Id: Idfbfa8da4c8d4e10299c4ae4d6431b10466cc988
Signed-off-by: Bogdan Davidoaia <bogdan.davidoaia@linaro.org>
2017-04-13 15:21:42 +03:00
Jukka Rissanen 70cdaba202 net: shell: Add IPv6 fragmentation info printing
If the IPv6 fragmentation support is enabled, then print current
status of the IPv6 packet reassembly in "net conn" command.

Change-Id: I384e35928b67dd39ac720c77683b1767e2a1ce88
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:42 +03:00
Jukka Rissanen d8feb0a0e4 net: ipv6: Add helper to get the last extension header
Figure out what is the last extension header in IPv6 packet
and return offset to it. This is needed by IPv6 fragmentation
when fragmentation header is added to the packet.

Change-Id: I925ab806a5de076a425ff354711730d4f4b3c52f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:41 +03:00
Jukka Rissanen ea17e9d321 net: ipv6: Support fragmented IPv6 packets
This commit adds support for IPv6 packet fragmentation when
receiving (IPv6 reassembly) and when sending larger than 1280 bytes
long IPv6 packet. See RFC 2460 chapter 4.5 for more details.

Jira: ZEP-1718

Change-Id: Ia31c147cce4d456ee48f39276cca99aa09ce81d6
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:41 +03:00
Jukka Rissanen 1b2c16a498 net: nbuf: Add function to split a data fragment
Add net_nbuf_split() function that can be used to split
an existing net_buf fragment into two arbitrary length pieces,
and return the two new fragments to the caller. The data from
the original fragment is copied into these two new fragments.

Existing fragment is not modified.

Change-Id: I463e675232c6e19c2a42929f480893a6d1265873
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:41 +03:00
Jukka Rissanen 7a07f23da7 net: tcp: Store MSS in tcp header correctly
Use UNALIGNED_PUT() to store the MSS value into network packet
because the memory location cannot be guaranteed to be properly
aligned.

Change-Id: I77fd7a70ef45eedb657cac29457b0239b0a1d4c2
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:41 +03:00
Anas Nashif c574dde9a5 kconfig: fixed name of Kconfig option in comment
Change-Id: Iae95d06e3a01bee62ea2160b9640722d2bfc3c41
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-04-10 16:07:22 +00:00
Jukka Rissanen 749b439863 net: icmpv6: Print received packet type as string
This helps debugging as printable string of the ICMPv6 type is
printed when packet is received if debugging is active.

Change-Id: I22b84bb6b28db7fba030699af3e561a0775b53d2
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-07 18:32:19 +03:00
Tomasz Bursztyka 8bbe03f35b net/core: Fix wrong parameter usage for check_unknown_option()
It requires a net_nbuf, so the actual buf, and not a frag here.

Change-Id: I4fd888c9a91f5e3f3dd664ae5e3bf93f90a2f597
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-07 18:32:19 +03:00
Jukka Rissanen 3e99c2ea0c net: Move IPv4 packet handling from net_core.c to ipv4.c
This will refactor net_core.c and move IPv4 specific code
into ipv4.c which is a more logical place for it.

Change-Id: Ia60c5bfec488d2d1a664f113dc3df88e7d5badd1
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-07 18:32:18 +03:00
Jukka Rissanen d43494d187 net: Move IPv6 packet handling from net_core.c to ipv6.c
This will refactor net_core.c and move IPv6 specific code
into ipv6.c which is a more logical place for it.

Change-Id: I5bbecbb760111326b9a6bbef5802c53d7f6efda9
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-07 18:32:18 +03:00
Tomasz Bursztyka 1ab40390c9 net/arp: Return relevant verdict if the ARP packet was consumed
DROP is only on error case, here it should return NET_OK if it was a
proper ARP packet and it got properly handled.

Change-Id: If347e80a76b3a56a9455b70d11b735c1fd910117
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-07 18:32:18 +03:00
Luiz Augusto von Dentz 4d1115ab35 net: Enable context buffer pool in case TCP and 6LO are enabled
The context buffer pool was introduced to deal with TCP holding buffers
when 6LO may modify them, therefore it makes sense to have it enabled
by default when TCP and 6LO are enabled given that the code can deal
with NULL pool in case the application don't implement one.

Change-Id: I600ca31ab40c96ee27937c2e885e332b0cee4995
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-07 18:32:18 +03:00
Luiz Augusto von Dentz c53b43e4d5 net: ip: Increase RX stack size
RX stack overflow when dealing with TCP over Bluetooth/6lo setup:

RX [rx_stack] stack size 1200/1264 bytes unused 0 usage 1200/1200 (100 %)

Change-Id: I8d5e43faf93f675960e59d9340b97d1ce9fc082a
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-07 13:33:55 +03:00
Ravi kumar Veeramally 8ce12d5fe8 net: shell: Fix crash when retrieving remaining reachable time
Shell crashes if you try to retrieve IPv6 nbr reachable time
when CONFIG_NET_IPV6_ND is disabled.

Change-Id: I3c5b3b5614abf80373b892943fa1ab936d235f3c
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-07 12:35:51 +03:00
Ravi kumar Veeramally 7a6f976725 net: rpl: Return valid verdict
Return proper verdict on handling of DIS messages. Otherwise debug
prints will be confusing that packet dropped.

Change-Id: Ia4e18d6238868e3aed4b17e2c9ea11aa432869be
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-07 12:35:51 +03:00
Ravi kumar Veeramally 7ff7f58771 net: rpl: Refactor few rpl functions
No functionality changes, just refactored few rpl functions to
to align nicely.

Change-Id: I05c0397de7a8392cc781de2747802b2dd1bb8146
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-07 12:35:51 +03:00
Paul Sokolovsky a745832dc4 net: Elaborate output of net_nbuf_print_frags() to be more useful.
Following changes are made:

1. Output using NET_INFO logging level. This function is not part of
automatic logging, and must be called explicitly by a user application.
But if it outputs using NET_DEBUG, then DEBUG level needs to be
enabled, and the output of this function will be drowned in logging
spam. So, let user to enable just INFO level.

2. Show entire structure of the fragment chain, *including* the head
net_buf which holds net_nbuf structure. It is numbered as -1 in the
output to preserve existing order (and not change existing size
calculations).

3. Show owning pool (and its properties, like buffer size/user_data
size) for each buffer.

4. Check for NULL pointer, e.g. for convenience of calling directly
from net_context receive callback (which will be called with NULL
on TCP peer closed connection event).

With these changes, a newcomer from one look at the output of this
function will be able to have a clear basic picture of network
buffer management in Zephyr, and recurring user will be able to
recall any details at once.

Change-Id: I8f9562748329d749f765cc6af7989a448256d7e0
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-04-07 12:35:50 +03:00
Ravi kumar Veeramally 2a00f418f0 net: rpl: Refactor net_rpl_update_header function
No functionality changes, just refactored net_rpl_update_header
function to align nicely.

Change-Id: I5b3e099593bb964245ca06c9fb2ec85859a0640c
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-07 12:35:50 +03:00
Ravi kumar Veeramally 3e78d38f01 net: event: Add events for ROUTE ADD and DEL
Change-Id: I1d8cb1aebe8a6eb224f6103db0679000bb57c187
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-07 12:35:50 +03:00
Ravi kumar Veeramally bcc53c6157 net: route: Update IPv6 packet routing mechanism
Search destination address in IPv6 neighbor table. If it doesn't
exist in IPv6 neighbor table then go for routing. Added sanitycheck
to verify destination ll address is not the source ll address of
original packet (that means we are re-routing back to original sender).

Change-Id: I24adace6a0d17fbd1d2a36a5d75c79320de0a883
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-07 12:35:50 +03:00
Ravi kumar Veeramally 6cec42d792 net: route: Fix retrieving route nexthop
net_ipv6_nbr_lookup_by_index() will always find first matching entry
in IPv6 nbr table with lladdr index. But there can be multiple neighbors
linked to same lladdr index. So find route nexthop with ipv6_nbr_data
from nbr(ipv6 nbr) data pointer.

Change-Id: I5081d40330f5bc1ef0d96def03f4add4808b2fe9
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-07 12:35:50 +03:00
Ravi kumar Veeramally 3ebe644dd5 net: if: Fix missing submission of router lifetime timer
Router lifetime timer initialized in router_init but not submitted.

Change-Id: If5a77f413832db52eff99e7191f82d2a8fc8f081
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-07 12:35:50 +03:00
Ravi kumar Veeramally d07ca1d518 net: nbr: Fix miss calculation of nbr size
Extra data size was not considered in nbr size calculation.

Change-Id: Idc572abf55c8f9fd19940edb719f58e02e7f8ecd
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-07 12:35:50 +03:00
Ravi kumar Veeramally e0bfa15f8d net: rpl: Move net_route_lookup to proper place
Route lookup is necessary only if life time is
NET_RPL_ZERO_LIFETIME, otherwise lookup not required.

Change-Id: I25fb85c53e2d43cfdce08411af385f3ae26384cc
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-07 12:35:50 +03:00
Ravi kumar Veeramally f6af085a4b net: rpl: Add support for DAO retransmissions
If DAO message is routed through different nodes or sent directly
to a parent and ACK lost somewhere in noicy network. Node can not
join RPL mesh network properly. So try re-sending DAO message for
max number of trials (Kconfigurable).

Change-Id: I7f6a065deacd1e3942c89118ce8da4fbaa34af51
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-07 12:35:50 +03:00
june li 86cc447f38 net: tcp: Start retry timer when queueing data
When sending TCP data, check if the retry timer needs
to be started.

Change-Id: Iea90716e918dec0b22e60bf32467b11c0d1a296f
Signed-off-by: june li <junelizh@foxmail.com>
2017-04-07 12:35:49 +03:00
Tomasz Bursztyka 8108a608ff net/mgmt: Mask vs event should be verified part by part
It needs to check if current event matches:

- cb's layer
- cb's layer code
- cb's command

If none match, it will not raise the event.

Fixing the unit test as layer must be always != 0.

Jira: ZEP-1940

Change-Id: Iadd63e751fa6e534a10e7da9cae0f5bb5a384461
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 12:15:29 +00:00
Tomasz Bursztyka dc7be7c54f net/ieee802154: Disable ACK reply handling by default
Most (if not all) 802.15.4 devices can handle ACK replies by
themselves.

Change-Id: I0319d59de767b20eb67c1592bacaa4a7b7015cad
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 11:24:28 +02:00
Tomasz Bursztyka e716b4dcb0 net/ieee802154: Use context instead of interface to reduce stack usage
Now that interface is not directly used in data and mac frame creation,
let's just pass context pointer.

Change-Id: If002e6790d044eeffc57cb5685ac9525fbd6e43c
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 11:24:28 +02:00
Tomasz Bursztyka 0948149b92 net/ieee802154: Use context's extended address when generating frame
Now that RFD is default, the extended address can be changed through net
mgmt API, and thus no longer be the same as device's generated mac address.

Change-Id: I07ee647615c2caa1994712147c6c8a2b4306900d
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 11:24:28 +02:00
Tomasz Bursztyka 0df2a2fdbe net/ieee802154: Simplify data FS settings function signature
There is no need of interface anymore.
After previous changes, it appears that net_if parameter is not used so
we can remove it.

Change-Id: Id3570f50865696818a9be2280172e2e25fc537f7
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 11:24:28 +02:00
Tomasz Bursztyka 5e3354dad5 net/ieee802154: We don't get the MFR from device drivers
commit id 7a11439020 changed this.
Hopefully that changed did not affect anything.

Reducing minimal frame length and applying the change everywhere where
relevant.

Change-Id: I5ae203751bfcf70cef833620106d2c2d0e33b7a5
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 11:24:28 +02:00
Tomasz Bursztyka d2f8a5a27f net/samples: Add 802.15.4 link-layer security settings for the samples
And use them accordingly in the common code part.

Change-Id: Id91b76e5baea607c0d68eebcde6f84e4e35ca44c
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 11:24:27 +02:00
Tomasz Bursztyka e3c0310d98 net/ieee802154: Remove ORFD choice altogether.
ORFD was a hack, from the beginning of the IEEE 802.15.4 Soft MAC stack,
but is now useless and can therefore be removed.

Change-Id: I74d5e1995993f4a0749b6d9d553406d5ae162bda
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 11:24:27 +02:00
Tomasz Bursztyka 26a4df620f samples/net: Uses CONFIG_NET_APP_IEEE802154_* options relevantly
In order to simplify when 802.15.4 is selected on these samples, let's
setup the device through a common code.

For this to work, RFD is now the default.

Change-Id: I46590864442f77d83f681cc0e854c94344648856
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 11:24:27 +02:00
Tomasz Bursztyka 35dd54d1d7 net/ieee802154: Rename <SET/GET>_CHAN to <SET/GET>_CHANNEL
It's more readable and along with other part of the system.

Change-Id: Ib4be787d74310d838f38b1f1d5624e7357da8969
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 11:24:27 +02:00
Tomasz Bursztyka 1a647613a4 net: Add 802.15.4 useful Kconfig application settings
These should be used by samples to fix basic 15.4 settings.

Change-Id: I31ad1540008ac760b7aef720e520bf8e72d3a805
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 11:24:27 +02:00
Tomasz Bursztyka 0f18ce44f9 net: Rename Kconfig.samples and its main option for future changes
s/SAMPLES/APP for name shortening. Applying the change where relevant.

Not only IP addresse will be available as samples settings there but
also IEEE 802.15.4 channel, pan_id, and more for instance.

Change-Id: I05dd24989bd0c804d9588092d67044a3e063bc88
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 11:24:26 +02:00
Tomasz Bursztyka 98cace4a96 net/ieee802154: Expose auxiliary security header validation function
This will be needed for Thread/MLE.

Change-Id: Ib421da66cfc4da8111ff131f08cac74a11674928
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 10:39:33 +02:00
Tomasz Bursztyka e771f174e5 net/ieee802154: Add net mgmt requests to set/get security settings
These requests are used to set/get the key, the mode and the level of
the IEEE 802.15.4 link layer security.

Only implicit key mode is supported for now.

Change-Id: Ifbc9a5d08f9fbf0d51d6c3e4b650cfdce3d263db
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 10:39:33 +02:00
Tomasz Bursztyka 165f8b4d29 net/ieee802154: Integrate link-layer security relevantly
Initialize the ciphers.

Once the header is parsed and validated, we get all the necessary info
to decrypt the frame properly.

Change-Id: I3142fa572c7566b40efe18cf9d4e3f2b4bce0612
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 10:39:32 +02:00
Tomasz Bursztyka aa24613347 net/ieee802154: Provide the means to decipher data frames
It's not only about decrypting and authentifying but also setting the
right frag's length after that.

Change-Id: Ifc766b212b37d4e3593c210f6646ee85dff2ab6d
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 10:39:32 +02:00
Tomasz Bursztyka 5e115ba935 net/ieee802154: Provide the means to create secured data frames
Take into account the current security context to compute the header
size.

Provide the function to fill-in the aux security header in a frame.

Finally, call the generic encryption function which will process the
frame relevantly according to the given security context.

For now, only implicit key mode is supported.

Change-Id: I5412c32179e70217c0946b1b54d9a752375d522f
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 10:39:32 +02:00
Tomasz Bursztyka 9d78dba0a1 net/ieee802154: Add generic support for link layer cipher operations
This provides the means to authentify with/without encryption or
decryption of a frame following a generic 15.4 security context.

Change-Id: Ia5dbb7f43936a8131112fe4b16c9780e30f904c1
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 10:39:32 +02:00
Tomasz Bursztyka fb55449882 net/ieee802154: Normalize one parameter to make it clearer
Some call use a boolean for it, and since it's supposed to be 1 or 0
let's ask for a boolean always.

Change-Id: If4fbe5d58d5c25fb2a86719435c59af53ea02445
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 10:39:32 +02:00
Tomasz Bursztyka fb0e2d44ee net/ieee802154: Change function signature for future change
When applying security, there will be needs for accessing payload as
well, thus providing the whole frag directly instead of a data pointer
on the ll part.

Change-Id: Ia97a1f07f2a12fc5cdf085c3cc6350d50b419cae
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 10:39:32 +02:00
Tomasz Bursztyka 1ee5f3b578 net/ieee802154: Parse and validate auxiliary security header
This will ensure basic auxiliary security header fields are relevantly
filled-in as well as moving the parsing buffer pointer to the right
position for further parsing.

Change-Id: Ib09e312add783b13bf8b59a81a2ffe64eb6f8dc2
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 10:39:32 +02:00
Tomasz Bursztyka e089f14427 net/ieee802154: Add Auxiliary Security Header definitions
These will be used to parse and create 802.15.4 frames with security
enabled.

Change-Id: Icad214c8d7aa658b8483bf601b091b266e1b8d77
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 10:39:32 +02:00
Jukka Rissanen d593914b17 net: Check if sent packet is meant for us
If the destination IP address is one of our own address,
then reroute it back to us.

Jira: ZEP-1966

Change-Id: I8b93fc5425f3f18b0b9e85ca9a57cb122129c47f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-31 10:58:17 +03:00
Jukka Rissanen 039e215233 net: shell: Fix the connection status output
The fields in "net conn" output were unaligned and looked
generally very ugly.

Change-Id: I56b29982d4f6b984405944d155bbb6c682383318
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-31 10:58:17 +03:00
Jukka Rissanen 11305ec928 net: nbuf: Do not crash if context pools are not in use
It is possible that CONFIG_NET_CONTEXT_NBUF_POOL is set but
application has not defined any pools. In this case the tx and
data pool pointers will be NULL in net_context struct and we
must use the default pools instead.

Change-Id: I286f34c87d9182aace71e0a61f038945810e4916
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-31 10:58:17 +03:00
Jukka Rissanen 6df4ee9691 net: tcp: Allow tweaking of 2MSL timeout
The default timeout (4 min) is very long. Allow tweaking the
value via Kconfig option.

Change-Id: Iddfd48b96f3612b9bba7caa4d64357505df9644d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-31 10:58:17 +03:00
Ravi kumar Veeramally e5183fcf97 net: rpl: Fix invalid nbr lookup
Match neighbour with link layer address. And get RPL parent with
matching ll address. DAG id different which is prefix based address
from the parent.

Change-Id: I75ecdfa7aa63da210676a3f44b8510d24c38d1d5
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-31 10:58:17 +03:00
Ravi kumar Veeramally e6fd75c507 net: rpl: Fix DAO ACK reply
Let intermediate node reply DAO ACK only if it can not forward original
DAO messages to it's parent. If DAO forwarding is success let the final
parent sends DAO ACK.

Change-Id: I14ff9b5b110a639cad6415741dde71c2cdd222ef
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-31 10:58:17 +03:00
Ravi kumar Veeramally 8b6166e5c9 net: rpl: Fix invalid parsing of DIO message
DIO message suboptions can contain PAD1, PADN, Metric container,
Routing information, DODAG configuration and Prefix information.
Right now we are not skipping PADN and unknown options payload.

Change-Id: I43557962784f68a223ea209eae5ca0367a3d5410
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-31 10:58:17 +03:00
Ravi kumar Veeramally ea7d1e138c net: rpl: Fix invalid parsing of DAO message
DAO message suboptions can contain PAD1, PADN, Target, Transit
and Target descriptor. Right now we are not skipping PADN and
Target descriptor payload.

Change-Id: I89a9c3cb59de5397d1430f0fa5de95beee193880
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-31 10:58:16 +03:00
Ravi kumar Veeramally b77ad7dd6c net: rpl: Add support for handling of DAO ACK
Parse DAO ACK from parent and analyze it.

Change-Id: I2394bd5e339ff00c87b9b4835dd5a21e2bafb2e5
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-31 10:58:16 +03:00
Ravi kumar Veeramally bfb781dd14 net: rpl: Align Kconfig options properly
Indentation is wrong for few options. And few options does not
properly aligned.

Change-Id: Ib4a8a90a17fd20ddd16ec6f29558eb937f035bb9
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-31 10:58:16 +03:00
Ravi kumar Veeramally 6280abe372 net: icmpv6: Remove unnecessary cache ptrs for src and dst
Earlier net_nbuf_copy() mangled the original buffer. So cacheing
src and dst address was necessary. Now original buffer does not
get affected by net_nbuf_copy() call. Cacheing is not required.

Change-Id: I25f60bc6db2a75612e562e56024d4459478d80b4
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-31 10:58:16 +03:00
Ravi kumar Veeramally 29fb336ccd net: if: Fix triggering interface link call back
Do not call callback if destination ll address is not set. This
happens when dst is multicast or broadcast.

Change-Id: I34dda92799a987d9cff031dc97f4a01b94437561
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-31 10:58:16 +03:00
Tomasz Bursztyka 178589fc31 net/net_if: When IPv6 DAD is disabled, added address gets final state
There is no transition from tentative state etc... It should directly go
to preferred.

This is fixing ND processing when DAD is disabled: source address was
never set, as tentative state is not a valid in
is_proper_ipv6_address().

Change-Id: I6f0a0fdd99dd13d28849f9749f89ec21fdd370d8
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-24 17:31:42 +02:00
Tomasz Bursztyka 53b9c45f11 net/ipv6: Fix a NULL dereferencing issue when debug is enabled
Change-Id: If62aa12acfc07d32ae29068537127d245f8af87e
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-24 17:31:42 +02:00
Jukka Rissanen aa11cef227 net: shell: Add DNS query support
Add "net dns <hostname> [A | AAAA]" command support that can be
used to query IPv4 or IPv6 address for a given host name.

Change-Id: I86b2258efa994a67163f9b3b340f44d65767f11b
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:42 +02:00
Jukka Rissanen 8dc01261ea net: dns: Initialize DNS resolver if DNS servers are set
If the config file contains DNS server addresses, then
configure the DNS resolver to use them.

Change-Id: Ie7f2bdcf7ac4bb7ee0ecf7fb5b7bd2df3379cdc3
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:42 +02:00
Tomasz Bursztyka 850efc270c net/icmpv4: Normalize input function signature with ipv6 counter-part
Length parameter was always useless, only used in debugging, so that can
be removed.

Change-Id: If597f424840f37955202fa5fe827dd992e4cf776
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-24 17:31:42 +02:00
Tomasz Bursztyka e98f2e0b6a net/shell: Add ping reply handlers and a timeout
Thus the ping command is more user-friendly: at least user knows the
ping got a reply or not.

Change-Id: I740a2f77d288f6287ac04c908f3d517a49df57d2
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-24 17:31:42 +02:00
Tomasz Bursztyka 19af4eee4f net/icpmv4: Add dynamically registered ICMPv4 handlers
As it is done for ICMPv6. This will prove to be useful for implementing
an echo reply handler in a ping for instance.

Change-Id: I969a1da60f2a4ea59eee5c9983eb6e340923e2ef
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-24 17:31:41 +02:00
Tomasz Bursztyka 1d361b0507 net/shell: Simplify ping logic
net_addr_pton always returns -EINVAL in case of error, so let's play with
it to factorize the code.

net_icmpv<4/6>_send_echo_request always returns -EIO in case of error.

Change-Id: I89e5ccd4b936701f7dad194089dda845fab5d738
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-24 17:31:41 +02:00
Tomasz Bursztyka 1e3dc0cbb4 net/ipv6: Renaming IPv6 neighbor state related macros and function
Refining the names around IPv6's neighbor states to differentiate them
easily from any net_nbr related names (which are not tighten to IPv6).

Change-Id: Ibc24df2a9485477a53fe5fe1c8f993f0fcd91635
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-24 17:31:41 +02:00
Tomasz Bursztyka 4991499cab net/ipv6: Regroup debugging routines relevantly
Probably some refactoring left-over.

Change-Id: I9715441a54b2e675135ce4072651dcead3216d3b
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-24 17:31:41 +02:00
Jukka Rissanen b3e5de641d net: tcp: Invalid transition from FIN_WAIT_1 to CLOSE_WAIT
We incorrectly changed the state from FIN_WAIT_1 to CLOSE_WAIT.
This caused ACK be sent in CLOSE_WAIT state when the connection
was closed by peer. Sending ACK in this state is not allowed
according to RFC. The connection was still closed but slightly
wrong way.

Jira: ZEP-1961

Change-Id: Ie4aa6818128d4190230b679e26ac9630c7d45d69
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:41 +02:00
Jukka Rissanen 4de6340fe9 net: shell: Add command for testing TCP connection
User can open a TCP connection (just one at a time) by
using "tcp connect <ip> port" command.
Data can be sent by "tcp send <data>" command.
Connection can be closed by "tcp close" command.

Change-Id: I75aedd873a30575a6f742926b716afb7dbbfb92b
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:41 +02:00
Jukka Rissanen 4d0c27209b net: tcp: Refactor net_tcp_trace()
No functionality changes, use separate variable so that we do
not need to do big-endian conversion multiple times.

Change-Id: I8874b427bd39dfa2d952034a2623c47544a644fc
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:41 +02:00
Jukka Rissanen 2149ec599e net: ipv6: Adding router mgmt add/del events
If IPv6 router is added, then NET_EVENT_IPV6_ROUTER_ADD event
is generated. When router is removed, NET_EVENT_IPV6_ROUTER_DEL
is then generated. This is useful info if we want to have a generic
connectivity to outside of our local network.

Change-Id: Ia03958a071ceb998127894025c99ab72a8b648d5
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:41 +02:00
Jukka Rissanen 8130208839 net: context: Set the bind port
If the bind port is set to 0, then return the real bind port and
show it in the debug print.

Change-Id: If75b52bdacfc916329222d0d9e8aa4669e7a7160
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:40 +02:00
Gil Pitney 657ad14234 net: offload: More decoupling of net_offload from l2 naming
This is part of a patch series to decouple TCP/IP offload, which
currently occurs at the transport layer (L4), from the data link
layer (L2).

- Rename struct net_l2_offload_ip to struct net_offload
- Rename struct field offload_ip to just offload
- Rename include/net/offload_ip.h -> include/net/net_offload.h

Change-Id: I3cd891c2b13e0e8f3ad1c66264f90b5031ae17c2
Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2017-03-24 17:31:40 +02:00
Gil Pitney adb2e7ea2e net: offload: Rename Kconfig NET_L2_OFFLOAD_IP to NET_OFFLOAD
This is part of a patch series to decouple TCP/IP offload, which
currently occurs at the transport layer (L4), from the data link
layer (L2).

This patch simply renames the NET_L2_OFFLOAD_IP Kconfig variable
to NET_OFFLOAD.

Change-Id: Ic8b1d004cbac09b7c636475aaed75b0a31e4be1c
Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2017-03-24 17:31:40 +02:00
Ravi kumar Veeramally 1fb8b4aa74 net: route: Fix when route not found with dst address
When route not found try with default router if it exists. Consider
default router as nexthop. If default router also does not exist
then drop the packet.

Change-Id: I56cc9e4a1432fc25687cbaea600bfe9cf5b1d51e
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-24 17:31:40 +02:00
Ravi kumar Veeramally 192ca6c95e net: rpl: Fix verdict for handle_dao_ack
No memory leak but debug prints shows buffer dropped due to
NET_DROP verdict. Added TODO comments to support DAO ACK.

Change-Id: I32deb2e1d2eea98f19ef26ad429ba8d03ae13751
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-24 17:31:40 +02:00
Ravi kumar Veeramally 42994f37b2 net: rpl: Cache src and dst addresses for DAO ACK reply
When an intermediate node received DAO message, it should forward it
to its parent (if exists) and it ack to orignal DAO sender. But
dao_forward() function steals frag chain from original buffer. Src
and dst address pointers to original buffer are not valid to
continue in dao_ack_send. So cache them for DAO ACK.

Change-Id: I3a4df4837a133afe4e2badb183f729c37d267f63
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-24 17:31:40 +02:00
Ravi kumar Veeramally 97f4f69aee net: rpl: Fix setting metadata of forwarding buffer
When DAO message is required to be forwarding to a parent addr,
only frag chain and iface is considered. But for newly created Tx buf
other metadata also required. In this particular case setting
inet type, ip header length. Also update checksum as dst address
is changed.

Change-Id: If0e0a52e943db66be4aeecb6d0e3b9d7c3f04f58
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-24 17:31:39 +02:00
Ravi kumar Veeramally 948ec357c7 net: rpl: Fix invalid reading of RPL Transmit information
Path lifetime exists at 6 byte in RPL Transit information. So after
type and option length 3 bytes should be skipped to read lifetime.

Change-Id: Ic90c3bd75e3c7c63ffe9be27c0d206fc8fd58604
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-24 17:31:39 +02:00
Ravi kumar Veeramally 62116a9b72 net: rpl: Add missing Kconfig option
NET_RPL_DAO_ACK Kconfig option was missed. subsys/net/ip/rpl.c has
functionality of this option. By default it is disabled. Enable it
if you want to know the status of DAO message.

Change-Id: If5ed86c9c8c6c62991fc92d2f1e2a35331811356
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-24 17:31:39 +02:00
Ravi kumar Veeramally 3bf7eb5cde net: rpl: Handle verdict properly for forwarding_dao
If DAO message is not inteded to destination node then
intermediate node will forward original message with final
destination address. But verdict not passed properly.

Change-Id: If61c7b683b55b24b68f5235d0eee5ed60b611aef
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-24 17:31:39 +02:00
Jukka Rissanen 7ef7d305ce net: rpl: Fix printf modifiers for size_t variables
Two size_t variables were printed using %d which gave warning
if RPL debugging was enabled.

Change-Id: I6bc135c76a31da304e94af34ecd571163ddf2a0e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:39 +02:00
Jukka Rissanen c4751a7c6b net: Select IPv6 neighbor cache when RPL is enabled
Selecting RPL will need to enable NBR cache support,
it is not enough just to select IPv6.

Change-Id: I8162497111354d0fa9e44564fa5cc5ee46110b96
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:39 +02:00
Jukka Rissanen 1061ce302a net: route: Try to route IPv6 packet if we are not the recipient
Instead of simply dropping the packet if the destination IPv6
address is not ours, try to figure out if there is a route
to real destination and then re-route the IPv6 packet there.

Change-Id: I6b2a0d7096b3d7877b82b04f38e3a6e588587c11
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:39 +02:00
Luiz Augusto von Dentz 7aa5ae1feb net: rpl: Make sure k_delayed_work_init is only called once
k_delayed_work_init shall only be called once per work and not every
time before as that can trash the workqueue list if the work is pending.

Change-Id: Ib04b6689c59d03328687b0b579e80012dbd2f853
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-17 11:37:48 +02:00
Luiz Augusto von Dentz 64ccc1d5df net: ipv6: Make sure k_delayed_work_init is only called once
k_delayed_work_init shall only be called once per work and not every
time before as that can trash the workqueue list if the work is pending.

Change-Id: I454f40b63133bb7d6239dbe902858932bacfc454
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-17 11:37:48 +02:00
Jukka Rissanen 9337dd8c22 net: tcp: Print TCP trace in one line
Print TCP header information in one line as there is really no
need to use multiple lines. Also use debug level when printing
the header info so that it is only seen if debugging is activated.

Change-Id: I27f314ca060239545769dec07148897da3426436
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:45 +02:00
Luiz Augusto von Dentz 1b19e16d40 net: if: Make sure k_delayed_work_init is only called once
k_delayed_work_init shall only be called once per work and not every
time before as that can trash the workqueue list if the work is pending.

Change-Id: Ib6398a6a843dd4d820529487ad76a9dc9d9e152e
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-17 10:34:45 +02:00
Luiz Augusto von Dentz 9f8d1c17d9 net: bt: Fix warnings when debug is enabled
This fixes warnings when using %u to print the result of sizeof.

Change-Id: I5391456c855ec2785af22467d9d0f355bbb1e577
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-17 10:34:44 +02:00
Jukka Rissanen 430e271751 net: icmp: Fix return values of ICMP error send function
The return code from net_icmpv{4|6}_send_error() was not correct
if the error message could be sent. Now 0 is returned if sending
succeed, and <0 otherwise.

Change-Id: Iff67f097a9d9519c9f11d4cbc9cf428a7c74ec1b
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:44 +02:00
Jukka Rissanen 8ae7bb257f net: icmp: Update ICMP statistics for every ICMP packet
Update statistics for every sent, received and dropped
ICMPv{4|6} packet.

Change-Id: Ibe6f02e8222adb3db1f1dbd0cde1ed251710eb43
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:44 +02:00
Jukka Rissanen d233f91388 net: icmp: Gracefully timeout net_buf get in RX path
If we are replying ICMPv{4|6} message, then do not wait forever
for a free buffer. In a busy system, this might lead to non-progress
in RX path if we receive lot of packet from the network and never get
a free buffer.

Change-Id: Iaef92541b8745f872a07bc6e2052d0393d4d1e8b
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:44 +02:00
Michael Scott d48ef44d25 net: 6lo: Fix typo in compress bit calculation
commit 2e3e93dccb ("net: 6lo: Fix compress bit calculation") adds
a bit shift to the compress bit calculation, however it's typo'd as
a greater than comparison causing get_6co_compress() to return a
boolean value rather than the shifted version of the calculation.

Change-Id: Idacac2c032a03f1f75a78c94bed4c70428b8c77a
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-03-17 10:34:44 +02:00
Jukka Rissanen 0a259d6bd0 net: ipv6: Prefix length was incorrectly set
The IPv6 prefix address length was incorrectly set in net_if
after RA was received from the network. The incorrect "len"
variable was used instead of correct "prefix_len" in the prefix
info struct.

Change-Id: Ifeaf150b9960414d2ad200053a3bd5290dc8d365
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:44 +02:00
Jukka Rissanen 51dea40f80 net: ipv6: Cancel the prefix timer before setting it again
If the earlier prefix timeout is not cancelled before setting
it again, the system will hang.

Change-Id: I6e271294c8e5d43e3ceae4780b5d1c26bab2b296
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:44 +02:00
Tomasz Bursztyka 82545373ee net/mgmt: Remove the list node before unlocking the semaphore
The caller semaphore was released too early, this can cause the caller
to re-use the data and possibly corrupt the memory, if caller yields
and is run before this management thread. Solution is to first remove
the node from the list and then unlock the semaphore.

Change-Id: I02cef53559d776f32a5959380e6b7122cd5198c5
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-17 10:34:44 +02:00
Jukka Rissanen 157c383260 net: ipv6: Make config options more fine grained
Add CONFIG_NET_IPV6_NBR_CACHE option that is the base for both
neighbor discovery (ND) and duplicate address detection (DAD).

Both ND and DAD can be disabled if needed. If NBR cache is
disabled, then ND and DAD are disabled too.

Note that it makes not much sense to disable DAD or NBR cache
as IPv6 will not work properly without them. It is possible
to disable ND but then the neighbor information needs to come
via other sources like RPL.

Change-Id: I57c8668ad828b3a153dfc58eea78bf5f7ac3938a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:43 +02:00
Jukka Rissanen a623209f62 net: Print error if buf or interface are NULL when receiving pkt
Although very unlikely, I saw crashes at startup that could
be because of the buf or iface were null.

Change-Id: I8649eeb4f24fcd7d9f2acaeefaba4e6593388e91
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:43 +02:00
Jukka Rissanen 312a9cbb32 net: ipv6: Enhance debug print when handling pending packet
The fragment pointer is good to print here.

Change-Id: If09e684bbe0f9f5d3f961c4af8f86fb3ff364671
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:43 +02:00
Jukka Rissanen b18dd41b2d net: ipv6: Clear pending buf if NS cannot be sent
If for some reason the neighbor solicitation cannot be sent,
then we need to unref the pending packet as that would never
be freed otherwise.

Change-Id: Ied12a9b3a027a2aad3fafd0b5b36c56b5f042c28
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:43 +02:00
Jukka Rissanen ff6365c928 net: ipv6: Make sure there is data to be sent
If we are trying to send a IPv6 network packet and there
is no data, then print error.

Change-Id: Ia0e7bebae513f1bcf984e189566ae7e10a90bbfc
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:43 +02:00
Jukka Rissanen 13c1037885 net: ipv6: Use net_nbuf_unref() to get better debug prints
When going through fragments in update_ll_reserve(), use
net_nbuf_unref() in order to get better memory allocation
debug prints.

Change-Id: Ia7ee15b32800acdebeb28125465515132c55e179
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:43 +02:00
Jukka Rissanen 185f36034f net: Ignore everything in RX if interface is not up
No need to receive anything if network interface is down.

Change-Id: I22d62aeaf4fbef54608818bf6c8073ec2e9a7c09
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:43 +02:00
Jukka Rissanen 318afc4519 net: Synchronize TX and RX threads startup
Make sure that both the TX and RX threads are running before
we turn the network interface up.

Change-Id: Ie7e5938403e90e1ae76047c221cf9fd2f5a1167b
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:43 +02:00
Tomasz Bursztyka 1dfd399d77 net/mgmt: Remove a useless k_sem_init() and use K_SEM_DEFINE instead
Change-Id: I95ec89ad67f9d40df6773056d5af6a9df1332ca3
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-17 10:34:43 +02:00
Tomasz Bursztyka d6d1b3a748 net/mgmt: Add a network interface based synchronous event listener
In case of callback based event listener, it is easy for the callback to
filter on the given interface. But in case of the synchronous call it's
not: it would need, after a failed comparison on the interface pointer
to loop by itself on the net_mgmt_event_wait() which is a little bit
heavy (reinstalling the event listener, with the semaphore and all) and
a bit of a burden for the caller itself.

Instead, net_mgmt provides a dedicated call
net_mgmt_event_wait_on_iface() which does it the right way, so the
callback and the related semaphore are destroyed if only the iface
matches the one given as parameter (besides the timeout obviously).

Change-Id: Iab05c3249586f4f4d0447eea42fdac72b8428f2e
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-17 10:34:42 +02:00
Tomasz Bursztyka 35e5aa8865 net/mgmt: Add a function to wait on a event synchronously
Instead of creating a handler and a related callback structure on an
event_mask: net_mgmt_event_wait() can be used to wait synchronously on
such event_mask. The core mgmt part will seamlessly reuse the struct
net_mgmt_event_callback so the whole internal notification mechanism is
using the same code.

Change-Id: I426d782c770e75e5222aa3c5b703172b1f1f2e5e
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-17 10:34:42 +02:00
Paul Sokolovsky c1ecd8c890 net: context: For bind debug logging, include context protocol.
It's not enough to know just network address and port number to
disambiguate an endpoint, protocol (TCP vs UDP, etc.) should be
known too. Without this patch, there is a confusing output from
e.g. echo_server if both TCP and UDP is enabled.

Jira: ZEP-1086

Change-Id: I247a2dfc87df634ceac3b8733d7349b1d6aca80c
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-03-17 10:34:42 +02:00
Paul Sokolovsky 80c2946c42 net: connection: Move proto2str() to utils.c, rename to net_proto2str()
This function is useful for logging in other parts of network stack,
so allow to reuse it. (Will be used for net_context logging in a
follow-up patch).

Change-Id: I8238874584f8f039c94e5d827265944d97d13f6b
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-03-17 10:34:42 +02:00
Luiz Augusto von Dentz e46c8f27ed net: if: Don't check NET_IF_UP in net_if_prepare_events
NET_IF_UP may change during the lifetime of k_pool which means we would
have to reconfigure everytime the flag changes but NET_IF_UP is already
checked during net_if_send_data thus it should never reach the queue in
the first place making this check unnecessary.

Jira: ZEP-1888

Change-Id: Iaa8471bee886a6f7e701a1dd243fb199def26589
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-17 10:34:42 +02:00
Ravi kumar Veeramally 8cb97ae47d net: Modify IPv4/6 packet finalize API's
Current finalize api's takes buf as input parameter and returns
the finalized buf. But if there are any issue while finalizing,
it failed to throw an error.

Change-Id: I6db54b7453eec41a8051fab50d5c0dc937debd54
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-17 10:34:42 +02:00
Ravi kumar Veeramally 84a1c87d7f net: rpl: Add API to access default rpl instance
Change-Id: I1b0a3a9065f62d1fa757d93bd752c0f7c47fe821
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-17 10:34:42 +02:00
Ravi kumar Veeramally 12c98493b8 net: rpl: Fix compilation warnings about format specifier
Change-Id: I1887042586aa77cbb2642a64fba54a36e0bd7a20
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-17 10:34:42 +02:00
Ravi kumar Veeramally eaa31ec530 net: context: Fix setting of appdata ptr and length
When IPv6 header contains extra header (e.g. HBH), extra header length
was not part of app data length calculation. Result applications get
invalid total length. Also simplified set_appdata_values().

Change-Id: I07438d62dfd0f9abc1452484deb8b5eacdc37cf1
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-17 10:34:42 +02:00
Ravi kumar Veeramally 593e73615b net: icmpv6: Add support for HBH and RPL option handling
Add support for adding IPv6 extra header (HBH) with RPL options
in ICMPv6 echo reply.

Change-Id: Ibd0b96362a7d5a5f668a18d6a33e6917d37dc51c
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-17 10:34:41 +02:00
Ravi kumar Veeramally ad855fc31d net: ipv6: Fix handling of RA 6CO options
As per RFC 6775 4.2, context length holds number of leading bits
in the Context Prefix field that are valid. Rest are not valid
for compression.

Change-Id: Id21cc2d7a5d42980cf9295f85e75c4869ff6cb99
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-17 10:34:41 +02:00
Ravi kumar Veeramally 137aeb2809 net: rpl: Add RPL header revert utility
When a nodes receive a packet with RPL option in IPv6 HBH, it's need
to be reverted with node flags, instance id and sender rank.

Change-Id: Ic49c8e84c7846dc02728c120078506f6d7411e52
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-17 10:34:41 +02:00
Ravi kumar Veeramally 643d545cb3 net: core: Fix IPv6 RPL extension parsing
RPL extension header verify function takes input parameter as
metadata 'buf' and start reading from it. Instead it should start
reading from fragment (buf->frags). Also API should return
fragment and offset where caller can continue reading it.

Change-Id: I80612144aed55aa2dcf9eaab1f4408e10efdda31
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-17 10:34:41 +02:00
Jukka Rissanen a7133282ce net: shell: Pretty print the neighbor cache info
Make sure the neighbor cache is printed nicely in table
format with columns aligned.

Change-Id: I5323fdc644317ea08fd4694215f8cd44f8d7ff74
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:41 +02:00
Jukka Rissanen 995ff35a93 net: shell: Add cmd to remove IPv6 neighbor from cache
Add "net nbr rm <ipv6 address>" command. This is useful when
debugging IPv6 neighbor discovery procedure.

Change-Id: Idf1d5628bcf01489ca28a77e9a2f84a8ed041c9a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:41 +02:00
Jukka Rissanen f55e545376 net: utils: Byte to hex converter had wrong prototype
The net_byte_to_hex() prototype first parameter was uint8_t *,
but it should have been char *.

Jira: ZEP-1885

Change-Id: I6132a67bb9e8199de88451fb4e446081f401e8f6
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:41 +02:00
Jukka Rissanen d9528ac7fa net: ipv6: Properly enter DELAY state in NUD
We did not handle NUD (Neighbor Unreachability Detection)
properly and did not go to DELAY state when neighbor
reachability was checked.

Change-Id: I127d25124aa806c44ff37c1355cc3db7fb25b2d2
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:40 +02:00
Jukka Rissanen cd85a5e924 net: ipv6: Add more debugging to reachability timer
Print timer information when creating and expiring the
reachability timer.

Change-Id: I5c8fee91de85fe7c9ea7c467f45dbb105250d5b1
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:40 +02:00
Jukka Rissanen 7848d6e0ff net: ipv6: Wrong timer was used when reachability timer expired
The send_ns timer was used instead of reachable timer when
the reachability timer was expired. This meant that the
reachability timer was never restarted after it expired once.

Change-Id: Iccbd6d019d1106adca60f7319bc4c547cdb1d924
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:40 +02:00
Jukka Rissanen 49c0444f5c net: shell: Print more detailed neighbor information
Print the neighbor pointer address and remaining time when
viewing the neighbor cache in "net nbr" command.

Change-Id: I13840ccc16c31c99a803ec1b7afe69879bd639f2
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:40 +02:00
Jukka Rissanen ac74637e54 net: ipv6: Return the prefix lifetime in seconds
Use the proper API to get the remaining time in prefix timer
and return the value in seconds as expected.

Change-Id: I055ce0ba6092c23ad60d6775ce75a0a67ad91d26
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:40 +02:00
Jukka Rissanen 465ce5bac5 net: ipv6: Send NS when neighbor is added
In order to verify that the neighbor is reachable, send
neighbor solicitation message to neighbor which should then
send neighbor advertisement to us so that we can then mark
it reachable.

Change-Id: I2c45ee4a6982c698ef6c8fa1acccb995aadf8ee6
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:40 +02:00
Jukka Rissanen 2f5ee81c28 net: ipv6: Print IPv6 neighbor state changes
In order to be able to debug IPv6 neighbor state changes,
pretty print the state names when setting the new state.

Change-Id: I64e0b4173eaa63c9715c17420a008602759aa4fa
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:40 +02:00
Jukka Rissanen 91e99ea7da net: ipv6: Add debug function to convert nbr state to string
To be used by net-shell and other files for debugging neighbor
state.

Change-Id: Ie9b09a54a05dcb066906a3697dfe38aeffc886e6
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:40 +02:00
Tomasz Bursztyka f6987169d8 net/ieee802154: Fix net mgmt request to get core settings
Obviously s/SET/GET

Change-Id: Iab4fa82ee6c53cb53806bf131655605a21125c3b
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-17 10:34:40 +02:00
Tomasz Bursztyka 00a3b880f6 net/ieee802154: Add missing line breaks in the shell module
Change-Id: Ib05922bd2799732107bea1bef218e558dd94f264
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-17 10:34:40 +02:00
Jukka Rissanen a060553666 net: if: Skip error print for already joined mcast group
No need to print error if we have already joined a pre-defined
multicast group.

Change-Id: I1237d5fbf0b63267ccb00432522513358c48d31d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:51 +02:00
Jukka Rissanen 011392dafd net: if: Fix compiler warning when printing TX stack size
Wrong type modifier %zu in debug print, should be %d.

Change-Id: I82feca91d9e083a03263477569c552acc7c9767f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:50 +02:00
Luiz Augusto von Dentz 50ec0864c6 net: bt: Fix memory corruption
Patch 235118245864491a592245f57e5244bf61711943 did not set the ll
addresses in the right buffer which causes 6lo to unref buffers
causing a double unref latter.

Jira: ZEP-1890

Change-Id: Id7591ef3c20c7ab62dcb04576406d70602baa129
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-09 20:33:50 +02:00
Tomasz Bursztyka b1d73aaa98 net/ieee802154: Use pre-filled link address as ll target
IPv6 fills in lladdr_dst properly according to nexthop. Thus it's
useless to lookup again for nbr when creating data frame etc... Let's
use this directly. It both optimizes the code path as well as implements
proper nexthop frame sending.

Jira: ZEP-1863

Change-Id: Ic17a1b14a0db0692d31419ea2f45a5f288a09fb5
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-09 20:33:50 +02:00
Tomasz Bursztyka fac10f9b9a net/ieee802154: Display which channel is being scanned
Change-Id: I1917db4ac0ce5e65aff98a290401fa3caa896520
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-09 20:33:50 +02:00
Tomasz Bursztyka e38a9e8b9c net: Switch from per-iface tx thread to a unique k_poll triggered one
Now that k_poll landed in the kernel, it's worth using it to save
memory and reduce the number of threads at runtime.

Such switch has been first done in bluetooth (see hci_core.c and conn.c
in subsys/bluetooth/host). Since network interfaces kind of follows the
same design for sending data, it was then easy to copy the same change as
in bluetooth.

Change-Id: I7f9734b88ac818284bbabaedc946b4765b905ebb
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-09 20:33:49 +02:00
Michael Scott 0453629078 net: ip: Fix 6lo buffer leak when sending ACK
Due to recent TCP fixes for 6lo, we are making a copy of buffers
sent to net_tcp_send_buf() so that TCP retransmit can send the original
(unmodified) buffer.  This original buffer is freed via the TCP
sent_list when the related ACK packet is received.

However, there are users of the net_tcp_send_buf() function which
will never get a corresponding ACK (and do not add the buffer to the
TCP sent_list).  An example is send_ack() in net_context.c.  In this
case, we leak the original buffer.

To fix this leak in the 6lo specific block of net_tcp_send_buf(),
let's check to see if the original buffer was added to the TCP sent_list
and if not, then avoid the buffer copy process entirely.

Change-Id: If99e0e5bf266d33dd3466dc5d74443eaa39d10a8
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-03-09 20:33:49 +02:00
Jukka Rissanen 6ff97e40c4 net: core: Use K_NO_WAIT when spawning RX and TX threads
Instead of magic constant (0) use the K_NO_WAIT when spawning
a thread.

Change-Id: Ib3a181fdfa246843d9c708592ccc754e54bc6005
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:49 +02:00
Jukka Rissanen 2e552b2b59 net: core: Mark RX and TX threads essential
As the networking cannot work without RX or TX threads, mark
them as essential.

Change-Id: Icb52c77fcdcef35d77c36e5ec855fed438a38407
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:49 +02:00
Jukka Rissanen aa95a93f38 net: iface: Print error if we cannot join mcast groups
If we cannot join pre-defined allnodes or solicit node multicast
groups, then print error. Typically this will happen if the number
of multicast IPv6 address records is too small in net_if struct.

Change-Id: I12211cff90ef4edc856f1432cab0c37aae9a1bd5
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen 29a6cc0add net: icmpv6: Add function to unregister ICMPv6 handler
This is only needed when doing unit tests.

Change-Id: Ifd4e5e8ea98e3ab2344ed0c19d92f2be7d8008f8
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen 75b550e81d net: ipv6: Collect MLD statistics
Collect number of received, sent or dropped multicast listener
reports and queries.

Change-Id: Ia5c08203155475763f96df23f44eceffa7569873
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen 8d8e3772e6 net: ipv6: Respond to MLD query
If we receive MLDv2 (Multicast Listener Discover) query,
we send out information about the multicast groups that
we have joined.

Change-Id: If4ea9fa685319b2ad900e1949a5cbe12e7696b43
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen ef2ee88af1 net: ipv6: Add router alert option to MLD msg
As dictated by RFC 3810 ch 5, we need to add Hop-by-Hop option
with Router Alert sub-option to the sent multicast listener
message.

Change-Id: I8e3ed58fff4736e9708276a3185f94e7f2b453a3
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen c89270c670 net: if: Create support to flush the TX queue
If we are taking network interface down, then flush the TX for any
pending bufs that would be needed to be sent.

Change-Id: I229ecce8e07ec5847d4c6c6a1994de04bd9171e2
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen 82267e7bd4 net: ipv6: Allow joining to existing multicast address
If the multicast address already exists, then do not give
error but try to join it.

Change-Id: I32ffa6b3bf0798011d684a1a21e87e389f1f0380
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen f8467437e6 net: if: Leave all joined IPv6 multicast groups at net_if_down
When network interface is taken down, leave only those
IPv6 multicast groups that were joined.

Change-Id: I414556c093ba67be7c13e6c86e0451465c2203f3
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen c3c76f35cc net: ipv6: Notify others if we join/leave IPv6 mcast group
Send management event if we joined or leaved IPv6 multicast
group.

Change-Id: Ieeb407ef88fb3bf4cd92d4fb4b69f03b260474e7
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen ba5bb5a9df net: if: Join/leave pre-defined IPv6 multicast groups
When we setup the network interface, add predefined IPv6 multicast
groups into the network interface. When interface is taken down,
then leave all the multicast groups that joined.
See RFC 4291 ch 2.8 for details.

Change-Id: If17d3e8c75157a02aa93c92e2fb499619c1484cf
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:47 +02:00
Jukka Rissanen 74e747a27f net: ipv6: Add support to join/leave multicast group
This and subsequent commits adds API to join or leave
an IPv6 multicast group.

Jira: ZEP-1673

Change-Id: I26dcfe16a4527dbf7886a30827a5d4ebfdeaac01
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:47 +02:00
Marcus Shawcroft 0547f51408 net: shell: Fix missing return when IPv6 disabled
Change-Id: Ic7b94841da0966ae9022f26cf71db7912aa79880
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:47 +02:00
june li 07b8e4cb01 net: tcp: Add tcp options length
The tcphdr->offset was not set when tcp options were added.

Change-Id: I19fe97983ce81948a9a84893183e5c9000f12767
Signed-off-by: june li <junelizh@foxmail.com>
2017-03-09 20:33:47 +02:00
Michael Scott eddd598323 net: tcp: remove net_tcp_set_state() function
There are no users of net_tcp_set_state() left outside of
subsys/net/ip/tcp.c.

And the naming of this function is confusing -- it could easily
be mistaken for net_tcp_change_state() which contains additional
logic for certain tcp states.

Let's remove it entirely and fix the remaining uses to set
tcp->state directly.

Change-Id: I92855ad180e8682780fcff11e50af06adcbc177c
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-03-09 20:33:47 +02:00
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
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
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
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
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
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 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 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 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 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
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
Marcus Shawcroft 53f0823113 net/dhcpv4: Call net_if_ipv4_addr_rm
The DHCPv4 client obtains resources from the server on a lease.  Once
a lease expires those resources must be relinquished.

Update the DHCPv4 client to explicitly remove leased resources from
the network stack once a lease has expired.

Change-Id: I5d3b7a02e463041cfdee1d104f5962498bdd6a30
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 3726bb98bd net/dhcpv4: Introduce start/stop API and disabled state.
Change-Id: Iae3b96dd91325ecf51b33b8c58f65aa5ec2b40c9
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft c4f4cb17db net/dhcpv4: Rework initialization.
The existing dhcpv4 initialization code places all initialization in
the per iface dhcpv4_start() code.  The net_udp_register() setup needs
to happen once for the dhcpv4 instance rather than once per iface.
Subsequent patches in this series also need a place to perform one
time initialization, independent of iface.

Factor the one time setup code out of the existing net_dhcpv4_start()
into a dhcpv4_init() function.  Rather than use SYS_INIT() to run
dhcpv_init() we hook directly into net_init().

The prototype of dhcpv4_init() is shared within the net subsystem with
a new private header file deliberately to avoid exposing the function
via the public API in include/net/dhcpv4.h

Change-Id: I3502a53cc3bfe4db4e4cd22c02ae133c266fdf10
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 010102ae02 net/dhcpv4: Refactor REQUESTING state entry.
Factor out common code associated with entering the REQUESTING state.

Change-Id: I0fc038a49309625c24b874dfda0355794cd41da9
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 653d614e1e net/dhcpv4: Refactor SELECTING state entry.
Factor out common code associated with entering the SELECTING state.

Change-Id: If34929e5f13dff7650388a2b491a01cbbf5dc100
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 5cfc917617 net/dhcpv4: Refactor send_discover
Refactor send_discover() to provide a clean separation between state
machine and action.

Change-Id: I96510cc6a7ab16216821fe65ea4289a78f6443aa
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 33bb4c0f21 net/dhcpv4: Refactor send_request state handling.
Refactor send_request() to provide a clean separation between state
machine and action.

Change-Id: If4c61c5789c919ab3ce6c1f914afc243176760d8
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 9dd39e1553 net/dhcpv4: Implement NAK support.
Handle the NAK message.

Change-Id: Ia3686564b083b16bd409bbe39acc500404f90fe0
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 57b24721b2 net/dhcpv4: Refactor handle_reply()
Split handle_reply into distinct state machine and actions.

Change-Id: Ib177c7a4007662f941f156acfa5791e1d27e3d73
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft b840664c11 net/dhcpv4: Adjust state names to reflect rfc2131
The dhcpv4 state machine implementation names differ from the names
used by the relevant rfc.  There is no good reason for them to be
different, so rename them.

Change-Id: I837f1bc4788c0ed4d2949b12eb6f5bfeef9a0be8
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:40 +02:00
Marcus Shawcroft 1f279e13b3 net/dhcpv4: Unify dhcpv4 state name printers
There are two implementations of dhcpv4 state name numbers to human
readable strings, unify the two.

Change-Id: I1d654918bb919108a0d8c5514b309b193c9c3f96
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:40 +02:00
Marcus Shawcroft 8df38dc55f net/dhcpv4: Move timers inside the net_if dhcpv4 context
The dhcpv4 state machine has a dedicated context within each net_if
structure.  For reasons unknown the timers used by the dhcpv4 state
machine have been placed in net_if outside of the dhcpv4 context area.
Relocate them into the dhcpv4 context.

Change-Id: I0531f493610dffda9ca9208993597a5665bde997
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:40 +02:00
Marcus Shawcroft 5dcc56ebed net/dhcpv4: Refactor dhcpv4 message type representation.
Change the message type representation from integer to enum, this will
help prevent re-occurrence of recent issues where states and events
are interchanged by making it more likely the compiler will see a type
mismatch.

Change-Id: Ia235afda428a9e5dfbd933e02beeae468b4c84a2
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:40 +02:00
Marcus Shawcroft 0d0cdc23a6 net/dhcpv4: Refactor packet construction
Refactor and simplify packet construction.  This resulting code is
simplier, easier to read and compiles a lot smaller.

Change-Id: I43c67d79fbb77f85af54355eca41f516054cbba3
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:40 +02:00
Marcus Shawcroft 1559a3b3e8 net/dhcpv4: Add missing const
Change-Id: I213b35936eb862d5abc4356a1a920cc2fef02f3f
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:40 +02:00
Jesus Sanchez-Palencia b21cfc2404 net: context: Make packet_received() static
This function is used only within net_context.c, make the symbol static
then.

Change-Id: Ib2c00a21c25e8c6a1404d6345d4b8ae05b779525
Signed-off-by: Jesus Sanchez-Palencia <jesus.sanchez-palencia@intel.com>
2017-03-09 20:33:40 +02:00
Leandro Pereira 4a0e008e8d net: tcp: ACK packet should not be forwarded to application
Since we try to match with POSIX behavior as much as possible, let's
not bother the user unless they need to be bothered.  The recv(2) POSIX
syscall won't return 0 on stream sockets unless the connection has been
closed by the peer; however, that was happening with the callback set
by net_context_recv().

Change it so that the callback is never called if operating on a stream
socket and appdatalen is set to 0.

This is similar to a previous patch sent by Michael Scott in [1], but
not relying on the actual TCP flags: only on the appdatalen and the
socket type.

[1] https://gerrit.zephyrproject.org/r/#/c/9949/

Jira: ZEP-1632

Change-Id: Ib0c214fc9269d305a03e8d85eb606f106c45b038
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-03-09 20:33:40 +02:00
Marcus Shawcroft 5028503d61 net/l2/ieeee802154: Fix typo in ieee802154_reserve name
Change-Id: I64112dfc04872d07b5dc4394d98b0ebd04222f53
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-27 08:30:02 +00:00
Jukka Rissanen 4852d6859b net: ipv6: Do not try to unref null pointer
If the DAD timeouts, then the pending pointer will be null
when we remove the neighbor. Fortunately this only prints
this error message and does not cause any issues in the code.

[net/nbuf] [DBG] net_nbuf_unref_debug: (0x00118350): *** ERROR *** \
  buf 0x00000000 (nbr_clear_ns_pending():175)

Change-Id: I3e11d4aa1d90f205df591b5d5cdcf2ee7bde6c01
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-27 10:28:55 +02:00
Jukka Rissanen c27aced5bf net: if: Remove local address from IPv6 neighbor cache
When we do DAD (Duplicate Address Detection), the local IPv6
address gets added to the neighbor cache. This is useless so
remove it after DAD has finished.

Change-Id: I9625d367e96d8108a7d3d1d8b2e95f3c4ea11c45
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-27 10:28:54 +02:00
Jukka Rissanen f5477582bd net: ipv6: Add util to remove neighbor from cache
Add net_ipv6_nbr_rm() utility function that can be used to
remove an IPv6 neighbor from the cache.

Change-Id: I9794856a4f65c5e943656970648e5c5762b0338c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-27 10:28:54 +02:00
Jukka Rissanen ab740c00c7 net: shell: Print IPv6 neighbor information
Add "net nbr" command which prints IPv6 neighbor cache
contents.

Change-Id: I7c26ecb117e8b77e64e3be3c0164a94f0d1775bf
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-27 10:28:54 +02:00
Jukka Rissanen d29e073c62 net: ipv6: Add util to traverse neighbor cache entries
Add utility function to go through all the stored neighbors
in the IPv6 neighbor cache.

Change-Id: I42fe0ec48c000215403aef63629d0763189ebdbb
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-27 10:28:54 +02:00
Jukka Rissanen c13753587f net: icmpv6: Echo-Reply seq and id fix
The sequence and identifier fields are 16-bit instead of 32-bit
long. This did not cause any issue in Echo-Reply but those two
fields should be set properly.

Change-Id: I5e4878f53d6bb37660d46d173159d27bbe0e94dc
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-27 10:28:53 +02:00
Jukka Rissanen 02a06f6489 net: icmpv6: Add TCP header when sending ICMPv6 error
TCP header was not sent back to originator when ICMPv6
error message was prepared to be sent.

Change-Id: I171bd724c4260b83d7d1c37e0894f9ed8cddd2c9
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-27 10:28:53 +02:00
Ravi kumar Veeramally 05d5dcf007 net: tcp: Retransmit buffers are not freed on tcp_release
TCP maintains 'sent_list' for retransmission if it doesn't get ACK for it.
Same list is not freed on net_tcp_release() call. This causes memory leak.

Change-Id: I2b2def1ea19487cc48ea4fbb6343ef0c773f288f
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-22 17:28:25 +02:00
Michael Scott f30a9e51c1 net: context: let tcp_established() handle more TCP states
Due to commit fece856959 ("net: tcp: Clean up FIN handling") the
tcp_established() callback now handles TCP connections which are
in various ending/closing states other than TCP_ESTABLISHED.

Currently, these states are generating the following error and not
being processed:
Context 0x123456778 in wrong state 6.
(Shown when TCP is in LAST_ACK state).

This commit also fixes a memory leak issue discribed in
Jira: ZEP-1658

Analysis of the memory leak issue is here:
When TCP connection is established, tcp context is in
NET_TCP_ESTABLISHED state. Once it receives FIN message from client
it goes to NET_TCP_CLOSE_WAIT and then it turns to NET_TCP_LAST_ACK
after connection closing request from server. Now server gets final
ack from client, but tcp_established() will reject it because current
state is not in NET_TCP_ESTABLISHED. Even if server receives proper
ack, it is not handled by server. Hence 'sent_list' is not freed.

Change-Id: I41c8af2e6851809f87a02c271a4290cf3d823ebb
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-02-22 17:28:25 +02:00
Ravi kumar Veeramally 4da61f7fc7 net: context: Fix invalid order of statements
NET_ASSERT(net_nbuf_iface(buf)) should be called before setting
it on context [net_context_set_iface(context, net_nbuf_iface(buf))].

Change-Id: I9a1da1214857e96e03784bc98a9aae5cf59ef0fc
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-22 17:28:25 +02:00
Tomasz Bursztyka 46298d5a45 net/utils: Fix parameters type
Using char or uint8_t relevantly.

Jira: ZEP-1723

Change-Id: I512cb6ff4800cd23f6539e7a47c7f3c72dc94183
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-02-22 17:28:25 +02:00
Jukka Rissanen 4eb2020055 net: Set the network link address type when setting link address
The interface L2 address type is set at the same time as the
L2 address is set to the network interface. This is most
convinient place to set the address type.

Change-Id: I712d7357d075959eb79df3463141cfbc6d163a74
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-22 17:28:25 +02:00
Marcus Shawcroft 0296cdd728 net/dhcpv4: Ensure udp header checksum is computed correctly
The dhcpv4 client code builds ip and udp packets from scratch rather
than using the network stack to do the heavy lifting (why ?).

When it computes the udp checksum of each packet it builds it neglects
to clear any preexisting detritus from the checksum field.  The result
of this is that some packets will be built with correct checksums and
some will be built with incorrect checksums.

This is the underlying reason that the dhcp client often taken many
retransmissions and elapsed time before in order to acquire an IP
address.

Change-Id: Iebd1ed34e06f7f2e53d45f6d1555e22f48490287
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-14 08:30:34 +02:00
Marcus Shawcroft ccd6d8c79f net/dhcpv4: Remove unused dhcpv4 offer state
The offer state is unused, remove it.

Change-Id: I9d6217dae291bb90c57c77ce439809bf7e9a9177
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-14 08:30:34 +02:00
Marcus Shawcroft 45e199c812 net/dhcpv4: Fix event/state mismatch
Fix long standing issue where a dhcpv4 message type is compared
against a dhcpv4 state machine state name rather than a message type.
The issue probably arizes due to the similarity in names between
messages and states.  By accident, the relevant message types and
states happen to share the same numbers, hence the implementation
works, but is ill defined.

Change-Id: I5c028de4336ff42f6696e28b3492c932c58b5a05
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-14 08:30:34 +02:00
Luiz Augusto von Dentz 4ab09bdead net: Convert FOR_EACH macro instances to use CONTAINER
Change-Id: I2fbdc8128bef79eac74441c84fbb80e31f6bc261
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-02-10 16:16:15 +00:00
Marcus Shawcroft 4c08b15c63 net/dhcpv4: Ensure the retransmission attempts counter gets reset.
Change-Id: I4c7c478425ca6f602a397295c36573a4453346d3
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-10 11:25:26 +02:00
Jukka Rissanen c3b0f35f6f net: if: Change the iface param in net_if_ipv6_maddr_lookup
Change the handling of iface parameter in net_if_ipv6_maddr_lookup()
function:
  * If the *iface is set to NULL, then return the found
    interface to the caller.
  * If the *iface is not NULL, then use that interface
    when doing the lookup.

Change-Id: Ia1f0365170ea9f3e615d189231160614a80d241a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-10 11:25:26 +02:00
Jukka Rissanen 253030c654 net: context: Fix the multicast address lookup in bind
Because of the change in next commit "net: if: Change
the iface param in net_if_ipv6_maddr_lookup",
we must initialize the network interface to NULL.
Without this the multicast address lookup will fail.

Change-Id: I113b44ce23c5f2ecbbf1698972078f102995e891
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-10 11:25:25 +02:00
Jukka Rissanen c357349e44 net: if: Change the addr param type in net_if_ipv6_maddr_add/rm
Make the IP address parameter const because we are not
modifying the IP address in net_if_ipv6_maddr_add() or
net_if_ipv6_maddr_rm()

Change-Id: I98c19de132e58c386f661e8a76a349d562a82c71
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-10 11:25:25 +02:00
Jukka Rissanen c0f6a5ecd8 net: nbuf: Fix constness of data param in net_nbuf_append
As the function does not change the original data, make
the corresponding parameter const.

Change-Id: I1125a2f9205dc73de2f0aac0c30110591baace1e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-10 11:25:25 +02:00
Marcus Shawcroft 878aa5f15c net/dhcpv4: Correct backoff and retransmit behaviour
Implement RFC2131 4.1.1 requirement that at dhcp implementation wait
for a random delay of 1 to 10s before sending the initial DISCOVER.

Implement RF2131 4.1 requirement that at dhcp implementation set the
initial retransmit timeout at 4 seconds and exponentially backoff on
each retransmit.

Change-Id: Id7029f3ed16a5f886dbd555fed87320aeffe31aa
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-09 14:27:11 +00:00
Marcus Shawcroft d06ca47eb3 net/dhcpv4: Use unique XID on each request.
Rather than reuse XID's on retransmissions, always use a unique XID.

Either behaviour is permitted by rfc2131.  Debugging the dhcp client
in the presence of multiple dhcp servers with significant packet loss
in the network is much easier if we don't unnecessarily reuse request
identifiers.

Change-Id: I5c82cbdbf3dfc0ef88cae036aa863946844c144f
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-09 14:27:11 +00:00
Marcus Shawcroft 8cd2e089d6 net/dhcpv4: Add further diagnostics.
Change-Id: I13fed6b6102d7711082f16de3f782c606808b142
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-09 14:27:10 +00:00
Ravi kumar Veeramally b45c4c7353 net: tcp: Remove multiple times of nbuf_compact() call
finalize_segment() will call net_ipv4_finalize() or
net_ipv6_finalize(). Both the functions perform net_nbuf_compact().
But after finalize_segment(), net_nbuf_compact() called again, which
is unnecessary.

Change-Id: I9fab63bcc44eec87061a4b55edd5053cf6556a75
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-09 09:43:06 +02:00
Ravi kumar Veeramally d3ea2021f4 net: tcp: Remove multiple checks on nbuf protocol family
Protocol family is checked in prepare_segment() and in same function
it's again verified by finalize_segment(). So remove the double checking
in finalize_segment().

Change-Id: I17123ab8741d017d7e3ff1ef3fb07371b0d4aa66
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-09 09:43:06 +02:00
Ravi kumar Veeramally 369e906e31 net: Ref net_buf using net_nbuf_ref
Using net_buf_ref() technically works but debugging the network buffer
allocations is more difficult if done like that.

Change-Id: Iac81bd3ab95547741d49f32763baaa54e97b4877
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-09 09:43:06 +02:00
Michael Scott a2e9dd1361 net: context: fix net context / net conn leak
If a net context is not connected or listening, we can go ahead and
call net_context_unref() to free it up instead of waiting for
FIN_ACK which will never happen.

Change-Id: Ice06f572df64f2edb5918c10c92087ce0b7b254a
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-02-08 10:12:36 +02:00
Michael Scott 7acb7aceb3 net: ip: change some error messages to NET_ERR
Several error messages are currently being logged as NET_DBG which
requires the user to have CONFIG_SYS_LOG_NET_LEVEL=4.

Let's show these as errors so they are more visible.

Change-Id: I28c9a1aedb78787ef098a9bf565472a437373933
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-02-08 10:12:36 +02:00
Ravi kumar Veeramally 58ba1d834e net: nbuf: Fix net_nbuf_compact() API
Current API description of net_nbuf_compact() is not very clear.
The first parameter needs to be the first net_buf in the chain.

The changes to this API are needed in order to clarify following
use cases:
1) User provides fragment that is not first of the chain and compact is
successfully done. In this case there is no free space in fragment list
after the input fragment. But there might be empty space in previous
fragments. So fragment chain is not completely compacted.

2) What if input fragment has been deleted and api returns the same
buf?

So this commit simplifies the API behavior. Now net_nbuf_compact()
expects the first parameter to be either TX or RX net_buf and then it
compacts it. It fails only if the input fragment is a data fragment.

Change-Id: I9e02dfcb6f3f2e2998826522a25ec207850a8056
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-08 10:12:36 +02:00
Ravi kumar Veeramally 999338ea94 net: nbuf: Remove unused net_nbuf_push() API
The net_nbuf_push() API is not used by anyone. Semantics are not
clear and following patch requires changes to push api, so removing
this API for now. If needed this can be re-introduced later.

Change-Id: I1d669c861590aa9bc80cc1ccb08144bd6020dac5
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-08 10:12:36 +02:00
Jukka Rissanen 32415396d8 net: arp: Fix the ethernet header location
The ethernet header location was incorrectly calculated
and the result pointer had some random value.

Change-Id: I6b2deee787a78444f3ee3be805d4b82ebb6c3664
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-08 10:12:36 +02:00
Ravi kumar Veeramally d7e0531149 net: fragment: Fix the 802.15.4 fragmentation
Currently fragmentation introduces empty fragment in the
beginning of the list, and adds fragmentation header, and moves frags
data to previous fragments. This is done based on condition that max
data should be multiples of 8 bytes and offset is based on before
compression.

It will fail at scenario when current fragment has not enough space
to move from next fragment and next fragment has more than allowable
max bytes. This will cause memory overflow which is typically seen
as double-free error to the user.

This is solved more simple way by this commit. First detach frags list,
prepare new fragment and attach that to buffer. Then move data from
detached frag list and free the fragments in the old one.

Change-Id: I5e3693d47828ff3b92db4ba5f6c00c0b751daadc
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-08 10:12:35 +02:00
Jukka Rissanen dace99611a net: nbuf: Fix double free in net_nbuf_compact()
If we are in the end of the fragment chain, then we can just
bail out as there is nothing more to do. There will be a
double free if we continue as the last entry is already
removed at this point.

Change-Id: I0f9782b408244d283dc7e3e087359dd00bada7a9
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-08 10:12:35 +02:00
Jukka Rissanen d15c836f6c net: nbuf: Remove dead code in net_nbuf_compact()
Change-Id: I8898ca20dd9d1764f52cd039baaa144faa7326f7
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-08 10:12:35 +02:00
Jukka Rissanen 5294497dd5 net: nbuf: Add helper to print fragment chain
Change-Id: I33eb2cf88e1cdeb79034334331dd346fa31cec49
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-08 10:12:35 +02:00
Jukka Rissanen bd3908b2a9 net: nbuf: Add timeout to net_buf getters
This commit changes the net_buf getter functions in nbuf.h
by adding a timeout parameter. These function prototypes
are changed to accept a timeout parameter.
	net_nbuf_get_rx()
	net_nbuf_get_tx()
	net_nbuf_get_data()
	net_nbuf_get_reserve_rx()
	net_nbuf_get_reserve_tx()
	net_nbuf_get_reserve_data()
	net_nbuf_copy()
	net_nbuf_copy_all()
	net_nbuf_push()
	net_nbuf_append()
	net_nbuf_write()
	net_nbuf_insert()

Following convinience functions have not been changed
	net_nbuf_append_u8
	net_nbuf_append_be16
	net_nbuf_append_be32
	net_nbuf_insert_u8
	net_nbuf_insert_be16
	net_nbuf_insert_be32
	net_nbuf_write_u8
	net_nbuf_write_be16
	net_nbuf_write_be32
so they call the base function using K_FOREVER. Use the
base function if you want to have a timeout when net_buf
is allocated.

Change-Id: I20bb602ffb73069e5a02668fce60575141586c0f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-08 10:12:35 +02:00
Michael Scott 567cc4531f net: context: keep randomly assigned port for TCP bind() calls
Prior to commit df201a0e4b ("net: context: Assign a random port
number when context is created"), TCP clients were assigned a random
port number when the incoming sockaddr parameter's port value was 0.

After the above commit, this is now broken as it will bind to port 0.

If left this way, every TCP client would need to add a line of code
copying the context->local sockaddr_ptr's port value into the
src_sockaddr port prior to calling net_context_bin().

Instead, we can reinstate this behavior in net_context_bind(), by
making sure we only overwrite the randomly assigned port in the
context->local sockaddr if the incoming sockaddr parameter has a
port which is != 0.

Change-Id: I0f27f031f743d50c351ecf9ab55b5282a20ff292
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-02-08 10:12:35 +02:00
Jukka Rissanen 8db13f905b net: ipv6: Free received NA net_buf
If we receive a neighbor advertisement, we need to free its
net_buf because we are returning NET_OK to the caller. This
return code means that we consumed the net_buf but we did
not call net_nbuf_unref() in this case.

Change-Id: Ia6d8f1b440be87eff5d2b14a23336a37be6d6a04
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-08 10:12:35 +02:00
Jukka Rissanen f25d4768b2 net: ipv6: Fix pending buf leak when NA is received
The pending buf needs to be freed after it has been sent
to the network. We took the ref when pending buf was saved,
now we need to unref it when it is about to be sent.

Change-Id: I1e429969895700000a8aa124bd645db2d52d036c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-08 10:12:34 +02:00
Tomasz Bursztyka 93ed88a670 net/ipv6: Updating ll reserve should be done for all IPv6 packet.
Doing it only in net_context, prevented to do it once NS succesfully
finished. This generated an error in 15.4, where pending data had wrong
ll reserve size.

Change-Id: I0f917fb76171457e5dff2c29e44edb8f00662150
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-02-03 15:59:20 +02:00
Jukka Rissanen 1301d3f6d3 net: ipv6: Use the nexthop when sending the packet
We must use the nexthop instead of destination address
when sending the packet. The current code mixed destination
and nexthop addresses and ignored the nexthop when sending
neighbor solicitation message.

Change-Id: I53887c16ef6fcf8365f1f47ab5792cb208dd273e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-03 15:59:20 +02:00
Jukka Rissanen 6930f93fd3 net: stats: Collect bytes sent and received
Keep track of amount of bytes that are sent or received from
all network interfaces.

Change-Id: I706481aab1a7e0cf2bc78d032f2ef4ebbabe3184
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-03 15:59:20 +02:00
Ravi kumar Veeramally df201a0e4b net: context: Assign a random port number when context is created
Current behaviour has an issue when UDP context is created with local
port number 0, net_conn_input() happens to treat zero port as
a wildcard ("receive packets for all ports"). net_context_bind()
for a UDP context doesn't affect its existing connection in any way.

Proposed solution is, context should be created with a random free
port assigned and bind() updates connection information from context.

Jira: ZEP-1644

Change-Id: Idb3592b58c831d986763312077b0dcdd95850bc9
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-03 15:59:20 +02:00
Ravi kumar Veeramally f6c8b0b89a net: context: Skip reserved ports
The port numbers in the range from 0 to 1023 are the well-known ports
or system ports. Do not allocate them for users.

Change-Id: I4d7b4e1314759e4d8b260669946b9880282642c0
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-03 15:59:20 +02:00
Tomasz Bursztyka 3aa6b21c07 net/ieee802154: Fixing active scan buffer reference counting
Commit-ID 83ed3a29be changed the way
fragments are managed after being sent, and this brought a bug in the
active scan logic. Up to active scan to keep the buffer referenced
relevantly now, which is simpler than it used to be.

Reported-by: Johann Fischer <j.fischer@phytec.de>

Change-Id: I23db4bab878328b1ca3cb313e737de819177c281
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-02-03 15:59:20 +02:00