Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TCP connection locally isn't possible #3442

Closed
zephyrbot opened this issue Apr 5, 2017 · 8 comments
Closed

TCP connection locally isn't possible #3442

zephyrbot opened this issue Apr 5, 2017 · 8 comments
Assignees
Labels
area: Networking Enhancement Changes/Updates/Additions to existing features priority: low Low impact/importance bug

Comments

@zephyrbot
Copy link
Collaborator

zephyrbot commented Apr 5, 2017

Reported by Paul Sokolovsky:

Even with GH-3411 fixed and local UDP communication working OK, TCP connection from one local context to another is not possible. What happens is that connect() call seemingly succeeds, but listening socket never has accept callback called. Enabling debug logging, following can be seen:

[net/ctx] [DBG] net_context_bind: (0x0013e050): Context 0x00136ce0 binding to TCP 192.0.2.1:5555 iface 0x00136760
[net/tcp] [DBG] net_tcp_change_state: (0x0013e050): state@0x00136fa0 CLOSED (0) => LISTEN (1)
[net/conn] [DBG] net_conn_register: (0x0013e050): [0/2/6/0x11] remote 0x00000000/-/0 local 0x0013ee90/192.0.2.1/5555 cb 0x00109dba ud 0x00136ce0
=============== lsock: <socket 136ce0 type=2>
[net/conn] [DBG] net_conn_register: (0x0013e050): [1/65363/6/0x23] remote 0x0013eeb0/127.0.0.1/5555 local 0x00000000/-/48205 cb 0x0010945c ud 0x00136d38
[net/tcp] [DBG] net_tcp_change_state: (0x0013e050): state@0x00137038 CLOSED (0) => SYN_SENT (2)
[net/tcp] [DBG] net_tcp_trace: (0x0013e050): buf 0x0013d6c0 src 48205 dst 5555 seq 0x3db82d47 ack 0x0000 (0) flags uaprSf win 1280 chk 0x2ce0
src addr: 10200c0
net_send_data(13d6c0): 1
[net/conn] [DBG] net_conn_input: (0x0013e050): Check TCP listener for buf 0x0013d6c0 src port 48205 dst port 5555 family 2 chksum 0x2ce0
[net/conn] [DBG] net_conn_input: (0x0013e050): [0] match found cb 0x00109dba ud 0x00136ce0 rank 0x11
[net/ctx] [DBG] _tcp_syn_rcvd: (0x0013e050): SYN received from 127.0.0.1 port 48205
[net/tcp] [DBG] net_tcp_change_state: (0x0013e050): state@0x00136fa0 LISTEN (1) => SYN_RCVD (3)
[net/tcp] [DBG] net_tcp_trace: (0x0013e050): buf 0x0013d708 src 5555 dst 48205 seq 0x3d389dfa ack 0x3db82d48 (0) flags uAprSf win 1280 chk 0x519c
src addr: 10200c0
net_send_data(13d708): 1
[net/conn] [DBG] net_conn_input: (0x0013e050): Check TCP listener for buf 0x0013d708 src port 5555 dst port 48205 family 2 chksum 0x519c
[net/conn] [DBG] net_conn_input: (0x0013e050): [1] match found cb 0x0010945c ud 0x00136d38 rank 0x23
*** remove temp conn, replace w/establ
[net/conn] [DBG] net_conn_unregister: (0x0013e050): [0] connection handler 0x001373bc removed
[net/conn] [DBG] net_conn_register: (0x0013e050): [1/2/6/0x33] remote 0x0013eba0/127.0.0.1/5555 local 0x0013eba8/192.0.2.1/48205 cb 0x00109778 ud 0x00136d38
[net/tcp] [DBG] net_tcp_change_state: (0x0013e050): state@0x00137038 SYN_SENT (2) => ESTABLISHED (4)
[net/tcp] [DBG] prepare_segment: (0x0013e050): Protocol family 0 not supported
[net/ctx] [DBG] send_control_segment: (0x0013e050): SYN_ACK sent to 0.0.0.0 port 0
[net/ctx] [DBG] send_control_segment: (0x0013e050): SYN sent to 0.0.0.0 port 0
Setting recv cb after connect()
========== client <socket 136d38 type=2>
before accept
net_send_data(13d6c0): 0
[net/ctx] [DBG] ack_timeout: (0x0013f050): Did not receive ACK in 1000ms
[net/tcp] [DBG] net_tcp_trace: (0x0013f050): buf 0x0013d6c0 src 5555 dst 0 seq 0x0000 ack 0x3db82d48 (0) flags uApRsf win 0 chk 0x6d1c
[net/ctx] [DBG] send_reset: (0x0013f050): RST sent to 0.0.0.0 port 0
net_send_data(13d6c0): -125
[net/tcp] [DBG] net_tcp_change_state: (0x0013f050): state@0x00136fa0 SYN_RCVD (3) => LISTEN (1)
net_send_data(13d6c0): 0

There're at least 2 problem spots:

  • The fact that "net_conn_unregister: (0x0013e050): [0]" called, this doesn't happen when connecting from outside
  • SYN ACK, instead of being sent back to local connecting socket, is sent via an empty TCP segment: "send_control_segment: (0x0013e050): SYN_ACK sent to 0.0.0.0 port 0"

I thought 1 is the route cause of 2, but even commenting out net_conn_unregister, "SYN_ACK sent to 0.0.0.0 port 0" still happens.

Overall, I spent an hour trying different hacks and workarounds, and can't get thru to what's wrong exactly. Connection handling is definitely not good, but there's a big problem beyond.

I guess this is not high priority, but it shows that some things in the stack work not general enough, so it would be nice to get to the root cause of this.

(Imported from Jira ZEP-2001)

@zephyrbot
Copy link
Collaborator Author

by Jukka Rissanen:

There are two patches applied already to net that should help with loopback TCP connections:

net: context: Set the local port correctly in accept
net: context: Connect callback was set too late

I also created a test application (echo-loopback) that tests the UDP and TCP loopback connectivity. It is currently still in DRAFT as there is a memory leak somewhere and I have not yet found it. https://gerrit.zephyrproject.org/r/#/c/13077/

@zephyrbot
Copy link
Collaborator Author

zephyrbot commented Sep 12, 2017

by Vakul Garg:

@zephyrbot
Copy link
Collaborator Author

by Vakul Garg:

Attached a test case. It creates a TCP server socket listening on loopback address in a thread.
From main function, a client socket connected to TCP server socket and starts sending data.

For each data sent, following errors appear:

[net/tcp] [ERR] net_tcp_get_hdr: {assert: 'frag' failed}
[net/tcp] [ERR] net_tcp_ack_received: pkt 0x0040d524 has no TCP header

To compile the test case, unpack the attached tarball in zephyr/samples/net.

@zephyrbot zephyrbot added priority: low Low impact/importance bug area: Networking bug The issue is a bug, or the PR is fixing a bug labels Sep 23, 2017
@zephyrbot zephyrbot added this to the Future milestone Sep 23, 2017
@nashif nashif removed this from the Future milestone Jun 1, 2018
@nashif
Copy link
Member

nashif commented Nov 5, 2018

@pfalcon @jukkar is this still an issue, please update status.

@pfalcon
Copy link
Contributor

pfalcon commented Nov 5, 2018

Will need to recheck, yeah.

@pfalcon
Copy link
Contributor

pfalcon commented Dec 6, 2018

Didn't have chance to retest, would target for 1.14 re-release testing.

@jukkar
Copy link
Member

jukkar commented Feb 21, 2019

TCP should work if CONFIG_NET_LOOPBACK is enabled. Probably does not work if that is missing.

@laperie laperie modified the milestone: v1.15.0 Feb 26, 2019
@rljordan-zz rljordan-zz added Enhancement Changes/Updates/Additions to existing features and removed bug The issue is a bug, or the PR is fixing a bug labels Mar 11, 2019
@jukkar
Copy link
Member

jukkar commented May 22, 2019

This is old one and should work if CONFIG_NET_LOOPBACK is enabled -> closing for now.

@jukkar jukkar closed this as completed May 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Networking Enhancement Changes/Updates/Additions to existing features priority: low Low impact/importance bug
Projects
None yet
Development

No branches or pull requests

6 participants