Project

General

Profile

Actions

Bug #1022

closed

1.4.6 : stream-tcp.c : StreamTcpPseudoPacketSetupHeader : port swap logic isn't consistent

Added by Mark Solaris about 11 years ago. Updated about 11 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Target version:
Affected Versions:
Effort:
Difficulty:
Label:

Description

In the stream-tcp.c code below, IPv4 and IPv6 are treated differently. They are setting up the headers for the opposite direction but &np->sp and &np->dp are changed between the two IP versions. Is that correct? If it is the real intention can a comment be added to explain it?

void StreamTcpPseudoPacketSetupHeader(Packet *np, Packet *p)
{
    /* Setup the IP header */
    if (PKT_IS_IPV4(p)) {
        np->ip4h = (IPV4Hdr *)((uint8_t *)GET_PKT_DATA(np) + (GET_PKT_LEN(np) - IPV4_GET_IPLEN(p)));
        PSEUDO_PKT_SET_IPV4HDR(np->ip4h, p->ip4h);
        /* Similarly setup the TCP header with ports in opposite direction */
        np->tcph = (TCPHdr *)((uint8_t *)np->ip4h + IPV4_GET_HLEN(np));
        PSEUDO_PKT_SET_TCPHDR(np->tcph, p->tcph);
        /* Setup the adress and port details */
        SET_IPV4_SRC_ADDR(p, &np->dst);
        SET_IPV4_DST_ADDR(p, &np->src);
        SET_TCP_SRC_PORT(p, &np->dp);        <----- here
        SET_TCP_DST_PORT(p, &np->sp);
    } else if (PKT_IS_IPV6(p)) {
        np->ip6h = (IPV6Hdr *)((uint8_t *)GET_PKT_DATA(np) + (GET_PKT_LEN(np) - IPV6_GET_PLEN(p) - IPV6_HEADER_LEN));
        PSEUDO_PKT_SET_IPV6HDR(np->ip6h, p->ip6h);
        /* Similarly setup the TCP header with ports in opposite direction */
        np->tcph = (TCPHdr *)((uint8_t *)np->ip6h + IPV6_HEADER_LEN);
        PSEUDO_PKT_SET_TCPHDR(np->tcph, p->tcph);
        /* Setup the adress and port details */
        SET_IPV6_SRC_ADDR(p, &np->src);
        SET_IPV6_DST_ADDR(p, &np->dst);
        SET_TCP_SRC_PORT(p, &np->sp);          <---- here
        SET_TCP_DST_PORT(p, &np->dp);
    }
    /* we don't need a payload (if any) */
    np->payload = NULL;
    np->payload_len = 0;
}

Actions

Also available in: Atom PDF