net: http: Use random source port when connecting

If we re-connect to same peer server, then we should select a new
source port. Noticed that if the same source port as before is
used for the new connection, the peer might drop the packet. This
was seen when connecting to Linux peer.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2017-06-02 08:51:54 +03:00
commit c9e6ef5331

View file

@ -491,6 +491,17 @@ static int tcp_connect(struct http_client_ctx *ctx)
if (ctx->tcp.remote.family == AF_INET6) {
addrlen = sizeof(struct sockaddr_in6);
/* If we are reconnecting, then make sure the source port
* is re-calculated so that the peer will not get confused
* which connection the connection is related to.
* This was seen in Linux which dropped packets when the same
* source port was for a new connection after the old connection
* was terminated.
*/
net_sin6(&ctx->tcp.local)->sin6_port = 0;
} else {
net_sin(&ctx->tcp.local)->sin_port = 0;
}
ret = get_local_addr(ctx);