Commit Graph

2445 Commits

Author SHA1 Message Date
Jukka Rissanen
412a4f32ff net: Fix menuconfig for setting up samples IP addresses
We need to have a menuconfig for setting up networking
sample application IP address. This way we can properly
use strtol() which is only available if the
CONFIG_MINIMAL_LIBC_EXTENDED is selected.

Change-Id: I749ea444584b3e15d4a6fee9cd9065aba22a7278
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:15 +02:00
Leandro Pereira
697f4098f2 net: tcp: While disposing connection, properly check net_tcp pointer
The net_tcp_release() function was checking if the passed pointer to a
net_tcp struct was valid by checking if the pointer was within the
range of the tcp_context array.

However, the check was inverted, and the function was returning -EINVAL
every time a pointer to any element of the tcp_context array was
passed.

Because of this, TCP connections were never properly disposed, TCP
context were most likely left in either active or passive close states,
and new connections could never be established again.

Change-Id: I2ed368157349f0ca5641f7d15a555c0035e1a9e2
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:15 +02:00
Leandro Pereira
572e3a1607 net: tcp: Calculate ack# correctly when receiving data
Use the appdatalen value calculated by packet_received().  This avoids
recalculating the acknowledgement delta by reusing the same value that
is provided to the application.

In particular, sending a 30-byte packet to a Zephyr server would
produce an ACK# that, instead of being 30 higher than the sequence
number, was 40 below that number, because -NET_IPV6H_LEN was being
considered in the calculation.

Wireshark seems happy with this value, with no retransmissions from the
Linux end to the Zephyr end.

Change-Id: I35507fc2b880b4bae97277951d6d1b74a83a88c2
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:15 +02:00
Leandro Pereira
564d8cda53 net: tcp: Revisit implementation of passive close
This change moves the handling of passive close to a callback function
that handles the {CLOSE_WAIT, LAST_ACK} states.  This cleans up the
callback that handles the established estate, leaving only the handling
for that specific state in the tcp_established() callback.

Also, send the correct acknowledge number and send only an ACK rather
than a FIN+ACK packet while transitioning from ESTABLISHED to
CLOSE_WAIT.

These changes makes Wireshark happy when the connection is closed.

Change-Id: Ieeced5dff845f53a6b61af973dcf0fe3b7b8601f
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:15 +02:00
Leandro Pereira
bab94301ff net: tcp: Print pointer to state when transitioning
This aids in debugging logs to know which state structure transitioned
to which state.

Change-Id: I5bb1f34431e162f422513fcb40a2178e24e6fd84
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:15 +02:00
Leandro Pereira
4ed6ed06d8 net: tcp: Be more careful before dereferencing pointer in accept()
The function net_context_accept() was dereferencing context->tcp
without asserting it's not NULL, even if the protocol was not TCP.
There's a check prior to that to ensure it's a SOCK_STREAM, but that
wasn't sufficient to ensure that the pointer wouldn't be dereferenced
even if invalid.

Change-Id: Ie4f6b9792f6ebb90198ba3a845bb1b83ac450c38
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:15 +02:00
Leandro Pereira
777cd0727c net: tcp: Fix state transitions during handshake
During handshake, a new network context is created. But, before that,
the master TCP state is reset to the LISTEN state. Although correct by
the state machine definition, the TCP state of the master socket is
swapped with the newly-created context for the client socket.

This allows the client to keep the sequence numbers and other critical
flags. So, after swapping the TCP states, we were transitioning between
the LISTEN and ESTABLISHED states, which is wrong, and the new state
would be kept in the default, CLOSED state, which would make it
impossible to connect to a port a second time.

Change-Id: I3a30c632be0da29960c632d1ee62d1c4ec9d7348
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:15 +02:00
Leandro Pereira
e66a257b7e net: tcp: Print all the reasons a RST segment is sent
One case was not covered by a NET_DBG call, so add it.

Change-Id: Ie2b1f5cf6cdf62d39a3d12d0533e57e126266451
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:15 +02:00
Leandro Pereira
95d23577d2 net: tcp: Handshake ACK timeout should transition to LISTEN
The timeout was transitioning the master socket to the CLOSED state,
which made the port unconnectable if a handshake failed to finish in
one second.

Also cancel the ACK timeout when transitioning to ESTABLISHED;
otherwise, the connection would be closed after a second.

As a bonus, print the timeout in miliseconds.

Change-Id: I8e2d93cf0bbd706397909a2bb97b1821964d25da
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:15 +02:00
Leandro Pereira
483c8e780f net: Remove duplicated return statement
Change-Id: I7dc42165d94add6d24dfcbf427f1fee3f44f6f5b
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:15 +02:00
Jukka Rissanen
5165eb7e7e net: udp: Add util to create UDP packet
Create utility function that creates an UDP packet.
Use that function by net_udp_append().

Change-Id: I65b911a41910f812f8754ac1c787790ba63c637d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:15 +02:00
Jukka Rissanen
9ee1f3f7d4 net: Add support for setting up sample apps IP addresses
User is able to setup sample net apps IP addresses
via config file.

Change-Id: I7fbbda30d474095da717ed300977761857f509b8
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:14 +02:00
Jukka Rissanen
06fd64d1a0 net: dhcpv4: Fix debug output
The xid was printed in network byte order when msg was received.
Added also expected xid vs received xid if the packet recv
failed.

Change-Id: I6311033600f8e61378a8a1fb126074e83f98f142
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:14 +02:00
Jukka Rissanen
59532902ff net: mgmt: Use macro to define the stack
This enables the management stack information to be shown
in the net shell.

Change-Id: I6cf1d8b9a0d2da1623ce99b7726ea72a9769f2d8
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:14 +02:00
Jukka Rissanen
b20279dbfd net: rpl: Increase the RX stack usage
RPL requires 300 bytes more stack in RX path.

Change-Id: I7ebe5ec6470f6766997f8b5eb199fc55b059513a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:14 +02:00
Jukka Rissanen
888e6b997d net: Move stack related Kconfig options to Kconfig.stack
This way we see all the stack related Kconfig options in
one place.

Change-Id: I01dd566525823c96ee8c000435e27619fc8699c4
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:14 +02:00
Jukka Rissanen
720be1a3b8 net: shell: Add command to print stack usage info
The "net stacks" command will print information about
stack usage in the networking sub-system.

Change-Id: I568445e99158972b13dc10a1bb720ba9650b7ab4
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:14 +02:00
Jukka Rissanen
8e84e36f14 net: Declare a macro to define stacks used by networking
The macro defines the stack as usual, but if user has
enabled net shell (CONFIG_NET_SHELL), then additional
information about the stack is stored in net_shell
linker section. The information in the net_shell linker
section is then used to print information about the
stacks in the networking sub-system.

Change-Id: Ic6e9f16a73a192b9a59d32a6d0070322382f98bd
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:14 +02:00
Luiz Augusto von Dentz
1997b24e88 net: bt: Remove comments about nbuf extra references
This no longer apply as there is no longer a extra reference needed.

Change-Id: I84f50da7e15f31722cd99b906f9dd987a10ce2dd
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-12-02 12:41:13 +02:00
Luiz Augusto von Dentz
d1588dccee net: bt: Print data length for both recv and send
Change-Id: Ibe5c0a17addaa0f7a839691f8eac6128fe95335f
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-12-02 12:41:13 +02:00
Mahavir Jain
fa43abc100 net: shell: Fix warning in case CONFIG_NET_IPv6 is not enabled
Change-Id: Ie10aa043c222871c9f9ec8f6f311949b39f7c904
Signed-off-by: Mahavir Jain <mjain@marvell.com>
2016-12-02 12:41:13 +02:00
Leandro Pereira
d45a5330ee net: tcp: Validate state transitions for debugging purposes
If NET_DEBUG is enabled within tcp.c, all state transitions are checked
against the TCP state machine specification.  If an invalid state
transition is found, a debugging message is printed.

Change-Id: I8fe521a74da6c57e8aeee32e99b25c3d350fd4b0
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:13 +02:00
Leandro Pereira
db3bee8bdd net: tcp: No need to #if defined(TCP) inside TCP callback
The whole function is only built if TCP is also built.

Change-Id: I0ed71273fa8db52b3e4c18d4b7b1766593f15f5a
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:13 +02:00
Leandro Pereira
7c0e3f9580 net: tcp: Send a FIN|ACK when transitioning from ESTABLISHED->LAST_ACK
This sends FIN|ACK in one single segment instead of two while closing
a connection.

Change-Id: I80ff3da74deab2caffb69777438a0d13f75b4b32
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:13 +02:00
Leandro Pereira
99e4aa5dd4 net: Fix compile warnings when building with UDP disabled
The sanity checker should check for these as well eventually.

Change-Id: Ia22c8d0e000ee315ee2f582caa5a6b0c721e8b5f
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:13 +02:00
Andy Ross
65e85f39a3 net: Wire up TCP receive callbacks
packet_received() does most of our work here already.  The appdata
needs to be filled in correctly for TCP packets, which needed the
header size computation to be abstracted out of the ACK code.

Change-Id: Ifeb87c8ddcaa6f4b116214a3b3fb737ab03286f1
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:12 +02:00
Andy Ross
9211918c56 net: Refactor net_context_recv() to separate UDP and sync handling
More protocols are incoming.  Put the UDP specific stuff (address
wrangling and connection creation) in a separate function, leaving the
synchronous handling in place for other protocols to use.

No behavior changes.

Change-Id: I67fd9f683314ca9b2e671b84c46b9392db9496b2
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:12 +02:00
Leandro Pereira
120468a858 net: udp: Remove protocol check in (private) net_udp_append()
I believe the original intention was to have code similar to:

	buf = net_ipv6_create(...)
	buf = net_udp_append(...)
	buf = net_tcp_append(...)
	buf = net_ipv6_finalize(...)

However, each protocol has different ways of creating packets and
checking invariants.  Thus, the code now does something similar to:

	if (proto == UDP) {
		// original UDP code
	} else if (proto == TCP) {
		// TCP code, which creates the IP header as well
	} else {
		// unknown protocol
	}

Which negates the need of such check in net_udp_append().

Change-Id: I7f05b7d556462b0db35aaecdf060539f8c246e8c
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:12 +02:00
Leandro Pereira
c4937e85ed net: tcp: Disallow sending messages to unconnected contexts
The call would eventually return -EDESTADDRREQ, however -ENOTCONN is
the sane error value in this case.

Change-Id: I6c24bf9bf2ecc4bff6a615567547390e6f5b7d77
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:12 +02:00
Leandro Pereira
6a8dcce179 net: tcp: Allow sending packets using send() and sendto()
Adds support to send TCP packets using net_context_send() and
net_context_sendto() functions.

There's one behavior change: net_udp_append() will only append UDP
headers+payload if the context protocol matches.  This would allow
sending only IP packets from Zephyr.  Proper support for raw packets
should be added later if required, so the new behavior is to return
-EPROTONOSUPPORT if trying to send a packet through an
-unknown/unsupported protocol.

Note that sending packets outbound from Zephyr is still WIP; this is
just a step in the general direction of making it work.

Change-Id: Idcf26ad3820e85f1495e7029aed94f3b7abf25ed
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:12 +02:00
Leandro Pereira
287111d236 net: Implement net_context_send() in function of net_context_sendto()
Both functions perform the same logic, except that the sendto() variant
expects two more parameters to specify the destination address.

Just obtain that from the context in the send() case and forward the
information to the sendto() variant.

Reduces code slightly, while also making it easier to add more
protocols later.

Change-Id: I48da621d8788d5ba2cddaf2982324d3e896c13c3
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:12 +02:00
Vinicius Costa Gomes
f1822a0252 net: Fix compilation when DEBUG is enabled
When debugging is enabled, compilation fails with an error, similar to
this:

... net/yaip/net_mgmt.c:155:35:
error: 'struct k_sem' has no member named 'sem'
     k_sem_count_get(&network_event.sem));
                                   ^

As 'network_event' is a k_sem, there is no '.sem' field.

Change-Id: I09fb46ec02b62c30b9a12972abcaea8a36b84610
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
2016-12-02 12:41:12 +02:00
Ravi kumar Veeramally
72c71e8310 net: ieee802154: Add offset based reassembly feature
Current reassembly of 802.15.4 packets works only if fragments are
in correct order. But as per RFC 6282 reassembly should be based on
offset parameter in fragmentation header.

Change-Id: Icdcb10b9aa8f5837063b0201a64f8eb050c75681
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2016-12-02 12:41:11 +02:00
Tomasz Bursztyka
3ac3fb1f1e net: ieee802154: Add debug output to 6lo fragmentation
Change-Id: I429398b31a4ebf55658376bdc294faae5774edbf
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:41:11 +02:00
Tomasz Bursztyka
aa556f828e net: ieee802154: Fix wrong ifdef statement
Fragments reassembly was never used in l2.

Change-Id: Ia06ccbcd591ff79c43915e81c0b273533c607aa6
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:41:11 +02:00
Tomasz Bursztyka
3312663011 net: Raise TX stack size to 1200 bytes by default
Current value is not enough anymore it seems. (depends however, if some
debug output is enabled or not).

Would be much better if the build system could automatically compute
such size.

Change-Id: I9052616a7923e484664e4f5c7760e6a6e1152c63
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:41:11 +02:00
Jukka Rissanen
28255628f8 net: rpl: Add RPL option to IPv6 HBHO extension header
See RFC 6553 for details.

Change-Id: I2448f6fa03819e797c4825238ff3e125d2f92bbf
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:11 +02:00
Jukka Rissanen
314068d924 net: Avoid compiler warning when compiled for Arduino 101 ARC
There is something wrong with Arduino 101 ARC compiler.

Sanitycheck runs ethernet tests for this board basically using
this command:

cd tests/drivers/build_all
make pristine && make CONF_FILE=ethernet.conf BOARD=arduino_101_sss

Which then gives following warning

warning: missing braces around initializer [-Wmissing-braces]

which is then converted to error in sanitycheck.

Change-Id: I822c599cb172825a79b5b8e4a71cb9252757a435
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:11 +02:00
Tomasz Bursztyka
7a11439020 net: ieee802154: Fix current stack to completely drop CRC handling
The 802.15.4 frame has a header and in the end after the payload a CRC.
Overall MTU is 127 bytes, but CRC is most likely going to be generated
by the device itself (offloading). Because the limitation of current
nbuf, it's not possible to keep this CRC in the buffer because it
require a user data size of 127 bytes but if we do so, IP stack will
fill in as much as it can as packet data, thus occupying the 2 last
bytes. This generates bugs. A perfect solution would be to generalize a
better handling of MTU and head or tail reserve data into nbuf, but
this will probably be solved in the future.

Change-Id: I1a0fee4d555e2717c1edd5afba399a1f17d9c7a9
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:41:11 +02:00
Jukka Rissanen
c4cec90f68 net: shell: Add IPv4 ping support
User is able to send ICMPv4 Echo Request to destination
address.

Change-Id: Ie32d5970e5f3e75e925c283947f97e096e509555
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:10 +02:00
Jukka Rissanen
137e34a795 net: Fix net_addr_pton() IPv4 address parsing
Change-Id: Ib84067b66e3e417561045a4746408cecb6c2c67a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:10 +02:00
Jukka Rissanen
23d32722e8 net: Check loopback and unspecified address in sending
If the destination IP address is loopback, then bypass
the L2 layer and directly feed the IP packet back to us.

If the destination IP address is unspecified, then
drop the packet.

All this is only done if CONFIG_NET_IP_ADDR_CHECK is
set as this extra processing can be unnecessary if
it is always known what addresses the device is going
to use. By default the address checking is enabled.

Change-Id: I323cce97a72533c75b0424870f08729479024ebf
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:10 +02:00
Jukka Rissanen
b9d2113f02 net: Add util to send IPv4 ICMP Echo Request packet
Change-Id: I879eec03bc93cbf8935d62be9bff3e6cb03a8d72
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:10 +02:00
Jukka Rissanen
5db9bc8895 net: ipv4: Add utils to create IPv4 network packet
Create utility functions to create IPv4 packet if the
network context is not known.

Change-Id: I982830d09f3b91e23b75e6b63a5d97bfea0e8d4e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:10 +02:00
Jukka Rissanen
9c99fbe601 net: shell: Fix hostname parsing for ping command
If the user uses set_module command, then the target host
name pointer will be wrong. This is fixed so user can
either say "net ping 2001:db8::2" or if set_module command
is used "ping 2001:db8::2"

Change-Id: I708c53e329a11a18fcb448b34213e4b2f19c6390
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:10 +02:00
Tomasz Bursztyka
7e8ebf4733 net: ieee802154: Fix and use pkt_hexdump relevantly
Use frag->data as a reference, not net_nbuf_ll or net_nbuf_ip_data.

Print out packet before compression/fragmentation, so it will help to
spot issues after such process.

Make sure as well no coloration is done if frag reserver is not set.

Change-Id: I7f1bdc9e5c39913b8d7f62b5ffacb9ba3e11ecc8
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:41:09 +02:00
Tomasz Bursztyka
fa678cfdb6 net: ieee802154: Fix some debug output
Do not color the packet hexdump if there is no reserve set.
Do not print the ll part after 6lo compression/fragmentation.
Print out the actual frag being sent in radio driver.

Change-Id: I43118203c37fc76f60673c046732c8655ab7067b
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:41:09 +02:00
Tomasz Bursztyka
094ef65130 net: 6lo: LL content is set after 6lo compression/fragmentation
Thus no need to copy anything from there.

Change-Id: I1090f42f7fa5429748c973a656f9d25333ff16af
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:41:09 +02:00
Jukka Rissanen
a9673d9f56 net: Replacing TICKS_UNLIMITED by K_FOREVER
Unified kernel uses K_FOREVER so use it instead.

Change-Id: I24ae75e99cf54d6959c014b8a848e22a33848657
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:09 +02:00
Leandro Pereira
2bfc42610d net: tcp: Reduce some of the boilerplate to send control segments
Move most of the code to send a control segment to a single function to
avoid copies of boilerplate code in a few functions.

Change-Id: Id2d4770b6bec3f10b4eb786af3eb2a25482d953d
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:09 +02:00