From 0887203c57e098c468b6ec28d8ba745edf685010 Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Wed, 6 May 2020 10:25:03 +0800 Subject: [PATCH] tcp/conn: request arp before the 3-way handshake Since the request address was not properly resolved before the handshake, every time of connection, the handshake data will be overwitten into arp packet and retransmitted until the next tcp timer. Request the arp address before the handshake to avoid the retransmission. Change-Id: I80118b9a8096c126c8e16cdf2f7b3d98fca92437 Signed-off-by: chao.an --- net/tcp/tcp_conn.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c index dfb6575bf9..1e86873f1c 100644 --- a/net/tcp/tcp_conn.c +++ b/net/tcp/tcp_conn.c @@ -63,6 +63,8 @@ #include "devif/devif.h" #include "inet/inet.h" #include "tcp/tcp.h" +#include "arp/arp.h" +#include "icmpv6/icmpv6.h" /**************************************************************************** * Pre-processor Definitions @@ -1229,6 +1231,38 @@ int tcp_connect(FAR struct tcp_conn_s *conn, FAR const struct sockaddr *addr) goto errout_with_lock; } +#if defined(CONFIG_NET_ARP_SEND) || defined(CONFIG_NET_ICMPv6_NEIGHBOR) +#ifdef CONFIG_NET_ARP_SEND +#ifdef CONFIG_NET_ICMPv6_NEIGHBOR + if (conn->domain == PF_INET) +#endif + { + /* Make sure that the IP address mapping is in the ARP table */ + + ret = arp_send(conn->u.ipv4.raddr); + } +#endif /* CONFIG_NET_ARP_SEND */ + +#ifdef CONFIG_NET_ICMPv6_NEIGHBOR +#ifdef CONFIG_NET_ARP_SEND + else +#endif + { + /* Make sure that the IP address mapping is in the Neighbor Table */ + + ret = icmpv6_neighbor(conn->u.ipv6.raddr); + } +#endif /* CONFIG_NET_ICMPv6_NEIGHBOR */ + + /* Did we successfully get the address mapping? */ + + if (ret < 0) + { + ret = -ENETUNREACH; + goto errout_with_lock; + } +#endif /* CONFIG_NET_ARP_SEND || CONFIG_NET_ICMPv6_NEIGHBOR */ + /* Initialize and return the connection structure, bind it to the port * number. At this point, we do not know the size of the initial MSS We * know the total size of the packet buffer, but we don't yet know the