Merge pull request #15161 from brummer-simon/gnrc_tcp-hide_global_variables
gnrc_tcp: Hide remaining global variables
This commit is contained in:
commit
bcd59f9789
@ -49,16 +49,6 @@
|
|||||||
*/
|
*/
|
||||||
static evtimer_t _tcp_mbox_timer;
|
static evtimer_t _tcp_mbox_timer;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Head of liked TCB list.
|
|
||||||
*/
|
|
||||||
gnrc_tcp_tcb_t *_list_tcb_head;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Mutex for TCB list synchronization.
|
|
||||||
*/
|
|
||||||
mutex_t _list_tcb_lock;
|
|
||||||
|
|
||||||
static void _sched_mbox(evtimer_mbox_event_t *event, uint32_t offset,
|
static void _sched_mbox(evtimer_mbox_event_t *event, uint32_t offset,
|
||||||
uint16_t type, mbox_t *mbox)
|
uint16_t type, mbox_t *mbox)
|
||||||
{
|
{
|
||||||
@ -352,11 +342,7 @@ int gnrc_tcp_ep_from_str(gnrc_tcp_ep_t *ep, const char *str)
|
|||||||
|
|
||||||
int gnrc_tcp_init(void)
|
int gnrc_tcp_init(void)
|
||||||
{
|
{
|
||||||
/* Initialize mutex for TCB list synchronization */
|
|
||||||
mutex_init(&(_list_tcb_lock));
|
|
||||||
|
|
||||||
/* Initialize TCB list */
|
/* Initialize TCB list */
|
||||||
_list_tcb_head = NULL;
|
|
||||||
_rcvbuf_init();
|
_rcvbuf_init();
|
||||||
|
|
||||||
/* Initialize timers */
|
/* Initialize timers */
|
||||||
|
|||||||
27
sys/net/gnrc/transport_layer/tcp/gnrc_tcp_common.c
Normal file
27
sys/net/gnrc/transport_layer/tcp/gnrc_tcp_common.c
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Simon Brummer
|
||||||
|
*
|
||||||
|
* This file is subject to the terms and conditions of the GNU Lesser
|
||||||
|
* General Public License v2.1. See the file LICENSE in the top level
|
||||||
|
* directory for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ingroup net_gnrc
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file
|
||||||
|
* @brief GNRC TCP common function implementation
|
||||||
|
*
|
||||||
|
* @author Simon Brummer <simon.brummer@posteo.de>
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "internal/common.h"
|
||||||
|
|
||||||
|
static tcb_list_t _list = {NULL, MUTEX_INIT};
|
||||||
|
|
||||||
|
tcb_list_t *_gnrc_tcp_common_get_tcb_list(void)
|
||||||
|
{
|
||||||
|
return &_list;
|
||||||
|
}
|
||||||
@ -216,8 +216,9 @@ static int _receive(gnrc_pktsnip_t *pkt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Find TCB to for this packet */
|
/* Find TCB to for this packet */
|
||||||
mutex_lock(&_list_tcb_lock);
|
tcb_list_t *list = _gnrc_tcp_common_get_tcb_list();
|
||||||
tcb = _list_tcb_head;
|
mutex_lock(&list->lock);
|
||||||
|
tcb = list->head;
|
||||||
while (tcb) {
|
while (tcb) {
|
||||||
#ifdef MODULE_GNRC_IPV6
|
#ifdef MODULE_GNRC_IPV6
|
||||||
/* Check if current TCB is fitting for the incoming packet */
|
/* Check if current TCB is fitting for the incoming packet */
|
||||||
@ -250,7 +251,7 @@ static int _receive(gnrc_pktsnip_t *pkt)
|
|||||||
#endif
|
#endif
|
||||||
tcb = tcb->next;
|
tcb = tcb->next;
|
||||||
}
|
}
|
||||||
mutex_unlock(&_list_tcb_lock);
|
mutex_unlock(&list->lock);
|
||||||
|
|
||||||
/* Call FSM with event RCVD_PKT if a fitting TCB was found */
|
/* Call FSM with event RCVD_PKT if a fitting TCB was found */
|
||||||
/* cppcheck-suppress knownConditionTrueFalse
|
/* cppcheck-suppress knownConditionTrueFalse
|
||||||
|
|||||||
@ -56,7 +56,8 @@
|
|||||||
static int _is_local_port_in_use(const uint16_t port_number)
|
static int _is_local_port_in_use(const uint16_t port_number)
|
||||||
{
|
{
|
||||||
gnrc_tcp_tcb_t *iter = NULL;
|
gnrc_tcp_tcb_t *iter = NULL;
|
||||||
LL_SEARCH_SCALAR(_list_tcb_head, iter, local_port, port_number);
|
tcb_list_t *list = _gnrc_tcp_common_get_tcb_list();
|
||||||
|
LL_SEARCH_SCALAR(list->head, iter, local_port, port_number);
|
||||||
return (iter != NULL);
|
return (iter != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,6 +125,7 @@ static int _transition_to(gnrc_tcp_tcb_t *tcb, fsm_state_t state)
|
|||||||
DEBUG("_transition_to: %d\n", state);
|
DEBUG("_transition_to: %d\n", state);
|
||||||
|
|
||||||
gnrc_tcp_tcb_t *iter = NULL;
|
gnrc_tcp_tcb_t *iter = NULL;
|
||||||
|
tcb_list_t *list = _gnrc_tcp_common_get_tcb_list();
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case FSM_STATE_CLOSED:
|
case FSM_STATE_CLOSED:
|
||||||
@ -131,9 +133,9 @@ static int _transition_to(gnrc_tcp_tcb_t *tcb, fsm_state_t state)
|
|||||||
_clear_retransmit(tcb);
|
_clear_retransmit(tcb);
|
||||||
|
|
||||||
/* Remove connection from active connections */
|
/* Remove connection from active connections */
|
||||||
mutex_lock(&_list_tcb_lock);
|
mutex_lock(&list->lock);
|
||||||
LL_DELETE(_list_tcb_head, tcb);
|
LL_DELETE(list->head, tcb);
|
||||||
mutex_unlock(&_list_tcb_lock);
|
mutex_unlock(&list->lock);
|
||||||
|
|
||||||
/* Free potentially allocated receive buffer */
|
/* Free potentially allocated receive buffer */
|
||||||
_rcvbuf_release_buffer(tcb);
|
_rcvbuf_release_buffer(tcb);
|
||||||
@ -153,25 +155,25 @@ static int _transition_to(gnrc_tcp_tcb_t *tcb, fsm_state_t state)
|
|||||||
tcb->peer_port = PORT_UNSPEC;
|
tcb->peer_port = PORT_UNSPEC;
|
||||||
|
|
||||||
/* Add connection to active connections (if not already active) */
|
/* Add connection to active connections (if not already active) */
|
||||||
mutex_lock(&_list_tcb_lock);
|
mutex_lock(&list->lock);
|
||||||
LL_SEARCH(_list_tcb_head, iter, tcb, TCB_EQUAL);
|
LL_SEARCH(list->head, iter, tcb, TCB_EQUAL);
|
||||||
if (iter == NULL) {
|
if (iter == NULL) {
|
||||||
LL_PREPEND(_list_tcb_head, tcb);
|
LL_PREPEND(list->head, tcb);
|
||||||
}
|
}
|
||||||
mutex_unlock(&_list_tcb_lock);
|
mutex_unlock(&list->lock);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FSM_STATE_SYN_SENT:
|
case FSM_STATE_SYN_SENT:
|
||||||
/* Add connection to active connections (if not already active) */
|
/* Add connection to active connections (if not already active) */
|
||||||
mutex_lock(&_list_tcb_lock);
|
mutex_lock(&list->lock);
|
||||||
LL_SEARCH(_list_tcb_head, iter, tcb, TCB_EQUAL);
|
LL_SEARCH(list->head, iter, tcb, TCB_EQUAL);
|
||||||
/* If connection is not already active: Check port number, append TCB */
|
/* If connection is not already active: Check port number, append TCB */
|
||||||
if (iter == NULL) {
|
if (iter == NULL) {
|
||||||
/* Check if port number was specified */
|
/* Check if port number was specified */
|
||||||
if (tcb->local_port != PORT_UNSPEC) {
|
if (tcb->local_port != PORT_UNSPEC) {
|
||||||
/* Check if given port number is in use: return error */
|
/* Check if given port number is in use: return error */
|
||||||
if (_is_local_port_in_use(tcb->local_port)) {
|
if (_is_local_port_in_use(tcb->local_port)) {
|
||||||
mutex_unlock(&_list_tcb_lock);
|
mutex_unlock(&list->lock);
|
||||||
return -EADDRINUSE;
|
return -EADDRINUSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -179,9 +181,9 @@ static int _transition_to(gnrc_tcp_tcb_t *tcb, fsm_state_t state)
|
|||||||
else {
|
else {
|
||||||
tcb->local_port = _get_random_local_port();
|
tcb->local_port = _get_random_local_port();
|
||||||
}
|
}
|
||||||
LL_PREPEND(_list_tcb_head, tcb);
|
LL_PREPEND(list->head, tcb);
|
||||||
}
|
}
|
||||||
mutex_unlock(&_list_tcb_lock);
|
mutex_unlock(&list->lock);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FSM_STATE_SYN_RCVD:
|
case FSM_STATE_SYN_RCVD:
|
||||||
@ -443,7 +445,7 @@ static int _fsm_rcvd_pkt(gnrc_tcp_tcb_t *tcb, gnrc_pktsnip_t *in_pkt)
|
|||||||
uint16_t dst = byteorder_ntohs(tcp_hdr->dst_port);
|
uint16_t dst = byteorder_ntohs(tcp_hdr->dst_port);
|
||||||
|
|
||||||
/* Check if SYN request is handled by another connection */
|
/* Check if SYN request is handled by another connection */
|
||||||
lst = _list_tcb_head;
|
lst = _gnrc_tcp_common_get_tcb_list()->head;
|
||||||
while (lst) {
|
while (lst) {
|
||||||
/* Compare port numbers and network layer addresses */
|
/* Compare port numbers and network layer addresses */
|
||||||
if (lst->local_port == dst && lst->peer_port == src) {
|
if (lst->local_port == dst && lst->peer_port == src) {
|
||||||
|
|||||||
@ -115,14 +115,19 @@ extern "C" {
|
|||||||
#define GET_OFFSET( x ) (((x) & MSK_OFFSET) >> 12)
|
#define GET_OFFSET( x ) (((x) & MSK_OFFSET) >> 12)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Head of linked TCB list.
|
* @brief TCB list type.
|
||||||
*/
|
*/
|
||||||
extern gnrc_tcp_tcb_t *_list_tcb_head;
|
typedef struct {
|
||||||
|
gnrc_tcp_tcb_t *head; /**< Head of TCB list */
|
||||||
|
mutex_t lock; /**< Lock of TCB list */
|
||||||
|
} tcb_list_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Mutex to protect TCB list.
|
* @brief Function to access to TCB list
|
||||||
|
*
|
||||||
|
* @returns Pointer to global TCB list.
|
||||||
*/
|
*/
|
||||||
extern mutex_t _list_tcb_lock;
|
tcb_list_t *_gnrc_tcp_common_get_tcb_list(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user