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 #1

Updated by Victor Julien about 11 years ago

  • Status changed from New to Assigned
  • Assignee set to Victor Julien
  • Target version set to 1.4.7
Actions #2

Updated by Victor Julien about 11 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

Fixed by:

commit 9bc7ab604569465ea919f6ee83558d609eeb4405
Author: Victor Julien <victor@inliniac.net>
Date:   Tue Nov 5 16:55:57 2013 +0100

    stream: fix IPv6 pseudo packet setup

    Bug #1022: IPv6 pseudo packet setup using reverse logic of IPv4.

commit 1f2cc13c6ae9b85d0b439b43d212e97b34a389fb
Author: Victor Julien <victor@inliniac.net>
Date:   Tue Nov 5 15:48:05 2013 +0100

    stream: reduce scope of StreamTcpPseudoPacketSetupHeader

Actions

Also available in: Atom PDF