net: revert tcpip_poll_tcp() to not require a data_buf

tcpip_poll_tcp() was changed with commit 61edc68c to take on a
data_buf parameter, which was then processed as the primary
buffer. That change led to incorrect behaviour where the handling
of the first data buffer on a connection got mixed with the SYN buf.
It is no longer clear why tcpip_poll_tcp() was modified with the
change 61edc68c originally. Reverting the modification to
tcpip_poll_tcp() leads to much better handling of TCP data; and
also obviates another pull-request submitted recently:
https://gerrit.zephyrproject.org/r/#/c/4226.

Change-Id: I947c0991495c538c41e6581c8d360526b1bb89ad
Signed-off-by: Rohit Grover <rohit.grover@arm.com>
diff --git a/net/ip/contiki/ip/tcpip.c b/net/ip/contiki/ip/tcpip.c
index bea4177..d3a8c44 100644
--- a/net/ip/contiki/ip/tcpip.c
+++ b/net/ip/contiki/ip/tcpip.c
@@ -224,7 +224,7 @@
 #if UIP_ACTIVE_OPEN
 struct uip_conn *
 tcp_connect(const uip_ipaddr_t *ripaddr, uint16_t port, void *appstate,
-	    struct process *process, struct net_buf *buf)
+	    struct process *process)
 {
   struct uip_conn *c;
   
@@ -236,7 +236,7 @@
   c->appstate.p = process;
   c->appstate.state = appstate;
   
-  tcpip_poll_tcp(c, buf);
+  tcpip_poll_tcp(c);
   
   return c;
 }
@@ -422,7 +422,7 @@
       {
         if(!buf)
           break;
-        /* Check the clock so see if we should call the periodic uIP
+        /* Check the clock to see if we should call the periodic uIP
            processing. */
         if(data == &periodic &&
            !etimer_is_triggered(&periodic)) {
@@ -840,18 +840,12 @@
 /*---------------------------------------------------------------------------*/
 #if UIP_TCP
 void
-tcpip_poll_tcp(struct uip_conn *conn, struct net_buf *data_buf)
+tcpip_poll_tcp(struct uip_conn *conn)
 {
   /* We are sending here the initial SYN */
   struct net_buf *buf = ip_buf_get_tx(conn->appstate.state);
-  uip_set_conn(data_buf) = conn;
-
-  /* The conn->buf will be freed after we have established the connection,
-   * sent the message and received an ack to it. This will happen in
-   * net_core.c:net_send().
-   */
-  conn->buf = ip_buf_ref(data_buf);
-
+  uip_set_conn(buf) = conn;
+  conn->buf = ip_buf_ref(buf);
   process_post_synch(&tcpip_process, TCP_POLL, conn, buf);
 }
 
diff --git a/net/ip/contiki/ip/tcpip.h b/net/ip/contiki/ip/tcpip.h
index 253a02d..7967c13 100644
--- a/net/ip/contiki/ip/tcpip.h
+++ b/net/ip/contiki/ip/tcpip.h
@@ -167,8 +167,7 @@
  *
  */
 CCIF struct uip_conn *tcp_connect(const uip_ipaddr_t *ripaddr, uint16_t port,
-				  void *appstate, struct process *process,
-				  struct net_buf *buf);
+				  void *appstate, struct process *process);
 
 /**
  * Cause a specified TCP connection to be polled.
@@ -181,7 +180,7 @@
  * \param conn A pointer to the TCP connection that should be polled.
  *
  */
-void tcpip_poll_tcp(struct uip_conn *conn, struct net_buf *data_buf);
+void tcpip_poll_tcp(struct uip_conn *conn);
 
 void tcpip_resend_syn(struct uip_conn *conn, struct net_buf *buf);
 
diff --git a/net/ip/net_context.c b/net/ip/net_context.c
index e4ae147..3cfcc39 100644
--- a/net/ip/net_context.c
+++ b/net/ip/net_context.c
@@ -442,7 +442,7 @@
 	PROCESS_END();
 }
 
-int net_context_tcp_init(struct net_context *context, struct net_buf *buf,
+int net_context_tcp_init(struct net_context *context,
 			 enum net_tcp_type tcp_type)
 {
 	if (!context || context->tuple.ip_proto != IPPROTO_TCP) {
@@ -491,7 +491,7 @@
 		tcp_connect((uip_ipaddr_t *)
 			    &context->tuple.remote_addr->in6_addr,
 			    UIP_HTONS(context->tuple.remote_port),
-			    context, &context->tcp, buf);
+			    context, &context->tcp);
 #else /* CONFIG_NETWORKING_WITH_IPV6 */
 		NET_DBG("Connecting to ");
 		PRINT6ADDR((const uip_ipaddr_t *)&context->tuple.remote_addr->in_addr);
@@ -500,7 +500,7 @@
 		tcp_connect((uip_ipaddr_t *)
 			    &context->tuple.remote_addr->in_addr,
 			    UIP_HTONS(context->tuple.remote_port),
-			    context, &context->tcp, buf);
+			    context, &context->tcp);
 #endif /* CONFIG_NETWORKING_WITH_IPV6 */
 #endif /* UIP_ACTIVE_OPEN */
 	}
diff --git a/net/ip/net_core.c b/net/ip/net_core.c
index df58e4a..22844d6 100644
--- a/net/ip/net_core.c
+++ b/net/ip/net_core.c
@@ -69,8 +69,7 @@
 	net_context_get_udp_connection(struct net_context *context);
 int net_context_get_receiver_registered(struct net_context *context);
 void net_context_set_receiver_registered(struct net_context *context);
-int net_context_tcp_init(struct net_context *context, struct net_buf *buf,
-			 enum net_tcp_type);
+int net_context_tcp_init(struct net_context *context, enum net_tcp_type);
 int net_context_tcp_send(struct net_buf *buf);
 void *net_context_get_internal_connection(struct net_context *context);
 struct net_buf *net_context_tcp_get_pending(struct net_context *context);
@@ -149,8 +148,7 @@
 		int status;
 		uint8_t retry_count;
 
-		net_context_tcp_init(ip_buf_context(buf), buf,
-				     NET_TCP_TYPE_CLIENT);
+		net_context_tcp_init(ip_buf_context(buf), NET_TCP_TYPE_CLIENT);
 
 		status = net_context_get_connection_status(
 							ip_buf_context(buf));
@@ -671,7 +669,7 @@
 		break;
 	case IPPROTO_TCP:
 #ifdef CONFIG_NETWORKING_WITH_TCP
-		ret = net_context_tcp_init(context, NULL, NET_TCP_TYPE_SERVER);
+		ret = net_context_tcp_init(context, NET_TCP_TYPE_SERVER);
 		if (ret) {
 			NET_DBG("TCP connection init failed\n");
 			ret = -ENOENT;