diff --git a/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_eventloop.c b/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_eventloop.c index cbe37b57b4..45fa2f33e2 100644 --- a/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_eventloop.c +++ b/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_eventloop.c @@ -85,13 +85,10 @@ static int _send(gnrc_pktsnip_t *pkt) assert(pkt != NULL); /* NOTE: In sending direction: pkt = nw, nw->next = tcp, tcp->next = payload */ - gnrc_pktsnip_t *tcp = NULL; + /* Search for TCP header */ + gnrc_pktsnip_t *tcp = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_TCP); gnrc_pktsnip_t *nw = NULL; - /* Search for TCP header */ - LL_SEARCH_SCALAR(pkt, tcp, type, GNRC_NETTYPE_TCP); - /* cppcheck-suppress knownConditionTrueFalse - * (reason: tcp *can* be != NULL after LL_SEARCH_SCALAR) */ if (tcp == NULL) { DEBUG("gnrc_tcp_eventloop : _send() : tcp header missing.\n"); gnrc_pktbuf_release(pkt); @@ -101,7 +98,7 @@ static int _send(gnrc_pktsnip_t *pkt) /* Search for network layer */ #ifdef MODULE_GNRC_IPV6 /* Get IPv6 header, discard packet if doesn't contain an ipv6 header */ - LL_SEARCH_SCALAR(pkt, nw, type, GNRC_NETTYPE_IPV6); + nw = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_IPV6); if (nw == NULL) { DEBUG("gnrc_tcp_eventloop.c : _send() : pkt contains no ipv6 layer header\n"); gnrc_pktbuf_release(pkt); @@ -155,7 +152,7 @@ static int _receive(gnrc_pktsnip_t *pkt) #ifdef MODULE_GNRC_IPV6 /* Get IPv6 header, discard packet if doesn't contain an ip header */ - LL_SEARCH_SCALAR(pkt, ip, type, GNRC_NETTYPE_IPV6); + ip = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_IPV6); if (ip == NULL) { DEBUG("gnrc_tcp_eventloop.c : _receive() : pkt contains no IP Header\n"); gnrc_pktbuf_release(pkt); @@ -164,7 +161,7 @@ static int _receive(gnrc_pktsnip_t *pkt) #endif /* Get TCP header */ - LL_SEARCH_SCALAR(pkt, tcp, type, GNRC_NETTYPE_TCP); + tcp = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_TCP); if (tcp == NULL) { DEBUG("gnrc_tcp_eventloop.c : _receive() : pkt contains no TCP Header\n"); gnrc_pktbuf_release(pkt); diff --git a/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_fsm.c b/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_fsm.c index 3cb2f29bce..14afea8949 100644 --- a/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_fsm.c +++ b/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_fsm.c @@ -394,7 +394,7 @@ static int _fsm_rcvd_pkt(gnrc_tcp_tcb_t *tcb, gnrc_pktsnip_t *in_pkt) { gnrc_pktsnip_t *out_pkt = NULL; /* Outgoing packet */ uint16_t seq_con = 0; /* Sequence number consumption of outgoing packet */ - gnrc_pktsnip_t *snp = NULL; /* Temporary packet snip */ + gnrc_pktsnip_t *snp; /* Temporary packet snip */ gnrc_tcp_tcb_t *lst = NULL; /* Temporary pointer to TCB */ uint16_t ctl = 0; /* Control bits of the incoming packet */ uint32_t seg_seq = 0; /* Sequence number of the incoming packet*/ @@ -403,7 +403,7 @@ static int _fsm_rcvd_pkt(gnrc_tcp_tcb_t *tcb, gnrc_pktsnip_t *in_pkt) DEBUG("gnrc_tcp_fsm.c : _fsm_rcvd_pkt()\n"); /* Search for TCP header. */ - LL_SEARCH_SCALAR(in_pkt, snp, type, GNRC_NETTYPE_TCP); + snp = gnrc_pktsnip_search_type(in_pkt, GNRC_NETTYPE_TCP); tcp_hdr_t *tcp_hdr = (tcp_hdr_t *) snp->data; /* Parse packet options, return if they are malformed */ @@ -419,7 +419,7 @@ static int _fsm_rcvd_pkt(gnrc_tcp_tcb_t *tcb, gnrc_pktsnip_t *in_pkt) /* Extract network layer header */ #ifdef MODULE_GNRC_IPV6 - LL_SEARCH_SCALAR(in_pkt, snp, type, GNRC_NETTYPE_IPV6); + snp = gnrc_pktsnip_search_type(in_pkt, GNRC_NETTYPE_IPV6); if (snp == NULL) { DEBUG("gnrc_tcp_fsm.c : _fsm_rcvd_pkt() : incoming packet had no IPv6 header\n"); return 0; @@ -480,10 +480,7 @@ static int _fsm_rcvd_pkt(gnrc_tcp_tcb_t *tcb, gnrc_pktsnip_t *in_pkt) /* In case peer_addr is link local: Store interface Id in tcb */ if (ipv6_addr_is_link_local((ipv6_addr_t *) tcb->peer_addr)) { - gnrc_pktsnip_t *tmp = NULL; - LL_SEARCH_SCALAR(in_pkt, tmp, type, GNRC_NETTYPE_NETIF); - /* cppcheck-suppress knownConditionTrueFalse - * (reason: tmp *can* be != NULL after LL_SEARCH_SCALAR) */ + gnrc_pktsnip_t *tmp = gnrc_pktsnip_search_type(in_pkt, GNRC_NETTYPE_NETIF); if (tmp == NULL) { DEBUG("gnrc_tcp_fsm.c : _fsm_rcvd_pkt() :\ incoming packet had no netif header\n"); @@ -687,7 +684,7 @@ static int _fsm_rcvd_pkt(gnrc_tcp_tcb_t *tcb, gnrc_pktsnip_t *in_pkt) if (tcb->state == FSM_STATE_ESTABLISHED || tcb->state == FSM_STATE_FIN_WAIT_1 || tcb->state == FSM_STATE_FIN_WAIT_2) { /* Search for begin of payload */ - LL_SEARCH_SCALAR(in_pkt, snp, type, GNRC_NETTYPE_UNDEF); + snp = gnrc_pktsnip_search_type(in_pkt, GNRC_NETTYPE_UNDEF); /* Accept only data that is expected, to be received */ if (tcb->rcv_nxt == seg_seq) { diff --git a/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_pkt.c b/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_pkt.c index 4c98094b50..4d3c682dfe 100644 --- a/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_pkt.c +++ b/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_pkt.c @@ -54,12 +54,12 @@ int _pkt_build_reset_from_pkt(gnrc_pktsnip_t **out_pkt, gnrc_pktsnip_t *in_pkt) tcp_hdr_t tcp_hdr_out; /* Extract headers */ - gnrc_pktsnip_t *tcp_snp; - LL_SEARCH_SCALAR(in_pkt, tcp_snp, type, GNRC_NETTYPE_TCP); + gnrc_pktsnip_t *tcp_snp = gnrc_pktsnip_search_type(in_pkt, + GNRC_NETTYPE_TCP); tcp_hdr_t *tcp_hdr_in = (tcp_hdr_t *)tcp_snp->data; #ifdef MODULE_GNRC_IPV6 - gnrc_pktsnip_t *ip6_snp; - LL_SEARCH_SCALAR(in_pkt, ip6_snp, type, GNRC_NETTYPE_IPV6); + gnrc_pktsnip_t *ip6_snp = gnrc_pktsnip_search_type(in_pkt, + GNRC_NETTYPE_IPV6); ipv6_hdr_t *ip6_hdr = (ipv6_hdr_t *)ip6_snp->data; #endif @@ -117,8 +117,8 @@ int _pkt_build_reset_from_pkt(gnrc_pktsnip_t **out_pkt, gnrc_pktsnip_t *in_pkt) if (ipv6_addr_is_link_local(&ip6_hdr->src)) { /* Search for netif header in received packet */ - gnrc_pktsnip_t *net_snp; - LL_SEARCH_SCALAR(in_pkt, net_snp, type, GNRC_NETTYPE_NETIF); + gnrc_pktsnip_t *net_snp = gnrc_pktsnip_search_type(in_pkt, + GNRC_NETTYPE_NETIF); gnrc_netif_hdr_t *net_hdr = (gnrc_netif_hdr_t *)net_snp->data; /* Allocate new header and set interface id */ @@ -325,9 +325,7 @@ uint32_t _pkt_get_seg_len(gnrc_pktsnip_t *pkt) { uint32_t seq = 0; uint16_t ctl = 0; - gnrc_pktsnip_t *snp = NULL; - - LL_SEARCH_SCALAR(pkt, snp, type, GNRC_NETTYPE_TCP); + gnrc_pktsnip_t *snp = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_TCP); tcp_hdr_t *hdr = (tcp_hdr_t *) snp->data; ctl = byteorder_ntohs(hdr->off_ctl); seq = _pkt_get_pay_len(pkt); @@ -343,9 +341,7 @@ uint32_t _pkt_get_seg_len(gnrc_pktsnip_t *pkt) uint32_t _pkt_get_pay_len(gnrc_pktsnip_t *pkt) { uint32_t seg_len = 0; - gnrc_pktsnip_t *snp = NULL; - - LL_SEARCH_SCALAR(pkt, snp, type, GNRC_NETTYPE_UNDEF); + gnrc_pktsnip_t *snp = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_UNDEF); while (snp && snp->type == GNRC_NETTYPE_UNDEF) { seg_len += snp->size; snp = snp->next; @@ -372,7 +368,7 @@ int _pkt_setup_retransmit(gnrc_tcp_tcb_t *tcb, gnrc_pktsnip_t *pkt, const bool r } /* Extract control bits and segment length */ - LL_SEARCH_SCALAR(pkt, snp, type, GNRC_NETTYPE_TCP); + snp = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_TCP); ctl = byteorder_ntohs(((tcp_hdr_t *) snp->data)->off_ctl); len = _pkt_get_pay_len(pkt); @@ -434,7 +430,7 @@ int _pkt_acknowledge(gnrc_tcp_tcb_t *tcb, const uint32_t ack) return -ENODATA; } - LL_SEARCH_SCALAR(tcb->pkt_retransmit, snp, type, GNRC_NETTYPE_TCP); + snp = gnrc_pktsnip_search_type(tcb->pkt_retransmit, GNRC_NETTYPE_TCP); hdr = (tcp_hdr_t *) snp->data; /* There must be a packet, waiting to be acknowledged. */