diff options
Diffstat (limited to 'stacks/lwip_stack/lwip_src')
-rw-r--r-- | stacks/lwip_stack/lwip_src/api/spl_api_msg.c | 105 | ||||
-rw-r--r-- | stacks/lwip_stack/lwip_src/common/stackx_spl_share.h | 12 | ||||
-rw-r--r-- | stacks/lwip_stack/lwip_src/core/spl_pbuf.c | 14 | ||||
-rw-r--r-- | stacks/lwip_stack/lwip_src/core/spl_timers.c | 1 | ||||
-rw-r--r-- | stacks/lwip_stack/lwip_src/include/stackx/spl_pbuf.h | 3 | ||||
-rw-r--r-- | stacks/lwip_stack/lwip_src/ip_module/configuration_reader.c | 6 | ||||
-rw-r--r-- | stacks/lwip_stack/lwip_src/socket/stackx_prot_com.c | 28 | ||||
-rw-r--r-- | stacks/lwip_stack/lwip_src/socket/stackx_prot_com.h | 3 | ||||
-rw-r--r-- | stacks/lwip_stack/lwip_src/socket/stackx_protocol_api.c | 19 | ||||
-rw-r--r-- | stacks/lwip_stack/lwip_src/socket/stackx_res_mgr.c | 33 | ||||
-rw-r--r-- | stacks/lwip_stack/lwip_src/socket/stackx_res_mgr.h | 1 | ||||
-rw-r--r-- | stacks/lwip_stack/lwip_src/socket/stackx_tcp.c | 2 | ||||
-rw-r--r-- | stacks/lwip_stack/lwip_src/socket/stackx_udp.c | 2 |
13 files changed, 200 insertions, 29 deletions
diff --git a/stacks/lwip_stack/lwip_src/api/spl_api_msg.c b/stacks/lwip_stack/lwip_src/api/spl_api_msg.c index 9ba1e92..1c9bf92 100644 --- a/stacks/lwip_stack/lwip_src/api/spl_api_msg.c +++ b/stacks/lwip_stack/lwip_src/api/spl_api_msg.c @@ -414,7 +414,7 @@ spl_recv_udp (void *arg, struct udp_pcb *pcb, struct pbuf *p, { struct spl_netbuf *buf; spl_netconn_t *conn = (spl_netconn_t *) arg; - struct spl_pbuf *spb = NULL; //?? + struct spl_pbuf *spl_pb = NULL; //?? if (NULL == pcb) { @@ -432,12 +432,28 @@ spl_recv_udp (void *arg, struct udp_pcb *pcb, struct pbuf *p, /* //@TODO: malloc and Copy splbuf */ struct common_pcb *cpcb = (struct common_pcb *) (conn->comm_pcb_data); - buf = (struct spl_netbuf *) ((char *) p + sizeof (struct spl_pbuf)); - buf->p = spb; + u16_t proc_id = spl_get_lcore_id (); + + spl_pb = spl_pbuf_alloc_hugepage (SPL_PBUF_TRANSPORT, + p->tot_len + + g_offSetArry[SPL_PBUF_TRANSPORT], + SPL_PBUF_HUGE, proc_id, conn); + + if (!spl_pb) + { + NSPOL_LOGINF (TCP_DEBUG, "spl_pbuf_alloc_hugepage Failed!!!"); + return; + } + + pbuf_to_splpbuf_copy (spl_pb, p); + pbuf_free (p); + + buf = (struct spl_netbuf *) ((char *) spl_pb + sizeof (struct spl_pbuf)); + buf->p = spl_pb; spl_ip_addr_set (&buf->addr, ipaddr); buf->port = port; - err_t ret = sp_enqueue (cpcb, (void *) p); + err_t ret = sp_enqueue (cpcb, (void *) spl_pb); if (ret != ERR_OK) { NSPOL_LOGDBG (UDP_DEBUG, "mbox post failed"); @@ -1808,6 +1824,56 @@ do_listen (struct common_pcb *cpcb, msg_listen * lmsg) } /** + * Send some data on UDP pcb contained in a netconn + * Called from do_send + * + * @param msg the api_msg_msg pointing to the connection + */ +void +spl_udp_send (struct common_pcb *cpcb, msg_send_buf * smsg) +{ + struct spl_pbuf *p_from = smsg->p; + spl_netconn_t *conn = cpcb->conn; + struct udp_pcb *upcb = (struct udp_pcb *) (cpcb->conn->private_data); + data_com_msg *m = MSG_ENTRY (smsg, data_com_msg, buffer); + struct pbuf *p_to = NULL; + err_t err = ERR_OK; + + //allocate pbuf and copy spl_pbuf, send , free pbuf and spl_pbuf + do + { + p_to = pbuf_alloc (PBUF_TRANSPORT, p_from->len, PBUF_RAM); + if (NULL == p_to) + { + NSPOL_LOGERR ("pbuf is NULL]conn=%p,pcb=%p", conn, upcb); + return; + } + + err = splpbuf_to_pbuf_transport_copy (p_to, p_from); + if (err != ERR_OK) + { + SET_MSG_ERR (m, conn->last_err); + return; + } + + if (ip_addr_isany (&smsg->addr)) + { + SET_MSG_ERR (m, udp_send (upcb, p_to)); + } + else + { + SET_MSG_ERR (m, + udp_sendto (upcb, p_to, (ip_addr_t *) & smsg->addr, + smsg->port)); + } + + p_from = (struct spl_pbuf *) ADDR_SHTOL (p_from->next_a); + } + while (p_from != NULL); + +} + +/** * Send some data on a RAW or UDP pcb contained in a netconn * Called from netconn_send * @@ -1825,8 +1891,8 @@ do_send (struct common_pcb *cpcb, msg_send_buf * smsg) if (SPL_ERR_IS_FATAL (conn->last_err)) { SET_MSG_ERR (m, conn->last_err); - spl_pbuf_free (p); - return; + NSPOL_LOGERR ("Invalid param]msg->conn=%p", conn); + goto err_return; } switch (SPL_NETCONNTYPE_GROUP (cpcb->type)) @@ -1840,20 +1906,8 @@ do_send (struct common_pcb *cpcb, msg_send_buf * smsg) ss_set_local_ip (conn, smsg->local_ip.addr); } - //spl_ip_addr_t *destIP = &smsg->addr; + spl_udp_send (cpcb, smsg); - //@TODO udp send need to update like TCP. copy pbuf here. Once testing done for TCP we'll update it here. - if (ip_addr_isany (&smsg->addr)) - { - //SET_MSG_ERR(m, udp_send(upcb, p)); - /* destIP.addr == IPADDR_ANY means it is from stackx_send - and the destination is stored in remote_ip and remote port */ - //destIP = &upcb->remote_ip; - } - else - { - //SET_MSG_ERR(m, udp_sendto(upcb, p, &smsg->addr, smsg->port)); - } break; } @@ -1862,6 +1916,10 @@ do_send (struct common_pcb *cpcb, msg_send_buf * smsg) break; } +err_return: + pbuf_free_safe (smsg->p); + ASYNC_MSG_FREE (m); + return; } @@ -3186,9 +3244,12 @@ update_tcp_state (spl_netconn_t * conn, enum tcp_state state) spl_state = SPL_CLOSED; break; } - conn->tcp_state = spl_state; - NSTCP_LOGINF ("conn=%p,private_data=%p,state=%d", conn, - conn->private_data, spl_state); + if (conn->tcp_state != spl_state) + { + conn->tcp_state = spl_state; + NSTCP_LOGINF ("conn=%p,private_data=%p,state=%d", conn, + conn->private_data, spl_state); + } } } diff --git a/stacks/lwip_stack/lwip_src/common/stackx_spl_share.h b/stacks/lwip_stack/lwip_src/common/stackx_spl_share.h index 3b0c9f9..2d35dd0 100644 --- a/stacks/lwip_stack/lwip_src/common/stackx_spl_share.h +++ b/stacks/lwip_stack/lwip_src/common/stackx_spl_share.h @@ -431,11 +431,23 @@ ss_set_is_listen_conn (spl_netconn_t * sh, i8 is_listen_conn) } static inline i32 +ss_inc_fork_ref (spl_netconn_t * sh) +{ + return __sync_add_and_fetch (&sh->recycle.fork_ref, 1); +} + +static inline i32 ss_dec_fork_ref (spl_netconn_t * sh) { return __sync_sub_and_fetch (&sh->recycle.fork_ref, 1); } +static inline i32 +ss_get_fork_ref (spl_netconn_t * sh) +{ + return sh->recycle.fork_ref; +} + static inline int ss_add_pid (spl_netconn_t * sh, pid_t pid) { diff --git a/stacks/lwip_stack/lwip_src/core/spl_pbuf.c b/stacks/lwip_stack/lwip_src/core/spl_pbuf.c index 03e30ed..54589e8 100644 --- a/stacks/lwip_stack/lwip_src/core/spl_pbuf.c +++ b/stacks/lwip_stack/lwip_src/core/spl_pbuf.c @@ -369,6 +369,20 @@ spl_pbuf_copy (struct spl_pbuf * p_to, struct spl_pbuf * p_from) } err_t +splpbuf_to_pbuf_transport_copy (struct pbuf * p_to, struct spl_pbuf * p_from) +{ + if (EOK != MEMMOVE_S ((u8_t *) p_to->payload, + p_to->len, (u8_t *) ADDR_SHTOL (p_from->payload_a), + p_from->len)) + { + NSPOL_LOGERR ("MEMMOVE_S failed"); + return ERR_MEM; + } + + return ERR_OK; +} + +err_t splpbuf_to_pbuf_copy (struct pbuf * p_to, struct spl_pbuf * p_from) { u32_t offset_to = 0; diff --git a/stacks/lwip_stack/lwip_src/core/spl_timers.c b/stacks/lwip_stack/lwip_src/core/spl_timers.c index 50582fc..cfa130b 100644 --- a/stacks/lwip_stack/lwip_src/core/spl_timers.c +++ b/stacks/lwip_stack/lwip_src/core/spl_timers.c @@ -283,7 +283,6 @@ deal_timeout_sig (void) int retval; if (ptimer.first == NULL) { - NSPOL_LOGERR ("ptimer.first=NULL!!"); return; } tmo = rb_entry (ptimer.first, struct ptimer_node, node); diff --git a/stacks/lwip_stack/lwip_src/include/stackx/spl_pbuf.h b/stacks/lwip_stack/lwip_src/include/stackx/spl_pbuf.h index 01fe242..79deace 100644 --- a/stacks/lwip_stack/lwip_src/include/stackx/spl_pbuf.h +++ b/stacks/lwip_stack/lwip_src/include/stackx/spl_pbuf.h @@ -48,6 +48,9 @@ struct spl_pbuf *spl_pbuf_alloc_hugepage (spl_pbuf_layer l, u16_t length, spl_pbuf_type type, u16_t thread_index, void *net_conn); struct pbuf *spl_convert_spl_pbuf_to_pbuf (struct spl_pbuf *p_from); +err_t +splpbuf_to_pbuf_transport_copy (struct pbuf *p_to, struct spl_pbuf *p_from); + err_t pbuf_to_splpbuf_copy (struct spl_pbuf *p_to, struct pbuf *p_from); err_t splpbuf_to_pbuf_copy (struct pbuf *p_to, struct spl_pbuf *p_from); spl_pbuf_layer get_pbuf_layer_from_pbuf_payload (struct pbuf *buf); diff --git a/stacks/lwip_stack/lwip_src/ip_module/configuration_reader.c b/stacks/lwip_stack/lwip_src/ip_module/configuration_reader.c index d5b228b..03b5998 100644 --- a/stacks/lwip_stack/lwip_src/ip_module/configuration_reader.c +++ b/stacks/lwip_stack/lwip_src/ip_module/configuration_reader.c @@ -823,13 +823,7 @@ read_fn (i32 fd) return; } - const char *old_hbt_cnt = "6"; - const char *new_hbt_cnt = "60"; - nsfw_set_soft_para (NSFW_PROC_MASTER, NSFW_HBT_COUNT_PARAM, - (void *) new_hbt_cnt, sizeof (u16)); (void) read_configuration (); // if it returns -1, the err desc info will be wrote to g_config_data, so no need to check return value. - nsfw_set_soft_para (NSFW_PROC_MASTER, NSFW_HBT_COUNT_PARAM, - (void *) old_hbt_cnt, sizeof (u16)); offset = 0; left = MAX_IP_MODULE_BUFF_SIZE; diff --git a/stacks/lwip_stack/lwip_src/socket/stackx_prot_com.c b/stacks/lwip_stack/lwip_src/socket/stackx_prot_com.c index 6af2a77..292c17a 100644 --- a/stacks/lwip_stack/lwip_src/socket/stackx_prot_com.c +++ b/stacks/lwip_stack/lwip_src/socket/stackx_prot_com.c @@ -522,6 +522,34 @@ sbr_com_lock_common (sbr_socket_t * sk) } +void +sbr_com_fork_parent (sbr_socket_t * sk, pid_t p) +{ + i32 ref = ss_inc_fork_ref (sbr_get_conn (sk)); + NSSBR_LOGINF ("inc fork ref] fd=%d, p=%d, ref=%d, conn=%p, private_data=%p", + sk->fd, p, ref, sbr_get_conn (sk), + sbr_get_conn (sk)->private_data); +} + +void +sbr_com_fork_child (sbr_socket_t * sk, pid_t p, pid_t c) +{ + if (ss_add_pid (sbr_get_conn (sk), c) != 0) + { + NSSBR_LOGERR + ("add pid failed] fd=%d, p=%d, c=%d, ref=%d, conn=%p, private_data=%p", + sk->fd, p, c, ss_get_fork_ref (sbr_get_conn (sk)), sbr_get_conn (sk), + sbr_get_conn (sk)->private_data); + } + else + { + NSSBR_LOGINF + ("add pid ok] fd=%d, p=%d, c=%d, ref=%d, conn=%p, private_data=%p", + sk->fd, p, c, ss_get_fork_ref (sbr_get_conn (sk)), sbr_get_conn (sk), + sbr_get_conn (sk)->private_data); + } +} + /***************************************************************************** * Prototype : sbr_com_unlock_common * Description : unlock common diff --git a/stacks/lwip_stack/lwip_src/socket/stackx_prot_com.h b/stacks/lwip_stack/lwip_src/socket/stackx_prot_com.h index 054393b..1be44cb 100644 --- a/stacks/lwip_stack/lwip_src/socket/stackx_prot_com.h +++ b/stacks/lwip_stack/lwip_src/socket/stackx_prot_com.h @@ -150,6 +150,9 @@ int sbr_get_sockaddr_and_len (u16 port, spl_ip_addr_t * ip_addr, struct sockaddr *addr, socklen_t * addrlen); void sbr_com_set_app_info (sbr_socket_t * sk, void *appinfo); +void sbr_com_fork_parent (sbr_socket_t * sk, pid_t p); +void sbr_com_fork_child (sbr_socket_t * sk, pid_t p, pid_t c); + #ifdef __cplusplus /* *INDENT-OFF* */ } diff --git a/stacks/lwip_stack/lwip_src/socket/stackx_protocol_api.c b/stacks/lwip_stack/lwip_src/socket/stackx_protocol_api.c index 94ef483..920d73d 100644 --- a/stacks/lwip_stack/lwip_src/socket/stackx_protocol_api.c +++ b/stacks/lwip_stack/lwip_src/socket/stackx_protocol_api.c @@ -44,6 +44,25 @@ sbr_init_protocol () } /***************************************************************************** +* Prototype : sbr_fork_protocol +* Description : init protocol +* Input : None +* Output : None +* Return Value : int +* Calls : +* Called By : +* +*****************************************************************************/ +int +sbr_fork_protocol () +{ + pid_t pid = updata_sys_pid (); + + NSSBR_LOGINF ("update pid in child]pid=%d", pid); + return sbr_fork_stackx (); +} + +/***************************************************************************** * Prototype : sbr_get_fdopt * Description : get fdopt by domain type protocol * Input : int domain diff --git a/stacks/lwip_stack/lwip_src/socket/stackx_res_mgr.c b/stacks/lwip_stack/lwip_src/socket/stackx_res_mgr.c index 331eee1..f3cb5b5 100644 --- a/stacks/lwip_stack/lwip_src/socket/stackx_res_mgr.c +++ b/stacks/lwip_stack/lwip_src/socket/stackx_res_mgr.c @@ -172,6 +172,39 @@ sbr_init_stackx () } /***************************************************************************** +* Prototype : sbr_fork_stackx +* Description : init stackx res +* Input : None +* Output : None +* Return Value : int +* Calls : +* Called By : +* +*****************************************************************************/ +int +sbr_fork_stackx () +{ + + if (sbr_attach_group_array () != 0) + { + NSSBR_LOGERR ("sbr_attach_group_array failed"); + return -1; + } + + NSSBR_LOGDBG ("sbr_attach_group_array ok"); + + if (sbr_init_tx_pool () != 0) + { + NSSBR_LOGERR ("init tx pool failed"); + return -1; + } + + NSSBR_LOGDBG ("init tx pool ok"); + NSSBR_LOGDBG ("sbr_fork_stackx ok"); + return 0; +} + +/***************************************************************************** * Prototype : sbr_malloc_conn_for_sk * Description : malloc netconn for sk,need add pid * Input : sbr_socket_t* sk diff --git a/stacks/lwip_stack/lwip_src/socket/stackx_res_mgr.h b/stacks/lwip_stack/lwip_src/socket/stackx_res_mgr.h index e139644..73cec7f 100644 --- a/stacks/lwip_stack/lwip_src/socket/stackx_res_mgr.h +++ b/stacks/lwip_stack/lwip_src/socket/stackx_res_mgr.h @@ -56,6 +56,7 @@ sbr_get_spl_msg_box (sbr_socket_t * sk, u8 tos) } int sbr_init_stackx (); +int sbr_fork_stackx (); int sbr_malloc_conn_for_sk (sbr_socket_t * sk, spl_netconn_type_t type); int sbr_init_conn_for_accept (sbr_socket_t * sk, spl_netconn_t * conn); void sbr_free_conn_from_sk (sbr_socket_t * sk); diff --git a/stacks/lwip_stack/lwip_src/socket/stackx_tcp.c b/stacks/lwip_stack/lwip_src/socket/stackx_tcp.c index c64dc7b..3225c2f 100644 --- a/stacks/lwip_stack/lwip_src/socket/stackx_tcp.c +++ b/stacks/lwip_stack/lwip_src/socket/stackx_tcp.c @@ -1690,6 +1690,8 @@ sbr_fdopt tcp_fdopt = { .peak = sbr_com_peak, .lock_common = sbr_com_lock_common, .unlock_common = sbr_com_unlock_common, + .fork_parent = sbr_com_fork_parent, + .fork_child = sbr_com_fork_child, .ep_getevt = stackx_eventpoll_getEvt, .ep_ctl = stackx_eventpoll_triggle, .set_close_stat = NULL, diff --git a/stacks/lwip_stack/lwip_src/socket/stackx_udp.c b/stacks/lwip_stack/lwip_src/socket/stackx_udp.c index cf08731..69b822b 100644 --- a/stacks/lwip_stack/lwip_src/socket/stackx_udp.c +++ b/stacks/lwip_stack/lwip_src/socket/stackx_udp.c @@ -1163,6 +1163,8 @@ sbr_fdopt udp_fdopt = { .peak = sbr_com_peak, .lock_common = sbr_com_lock_common, .unlock_common = sbr_com_unlock_common, + .fork_parent = sbr_com_fork_parent, + .fork_child = sbr_com_fork_child, .ep_getevt = stackx_eventpoll_getEvt, .ep_ctl = stackx_eventpoll_triggle, .set_close_stat = NULL, |