#define TCP_GET_RAW_WINDOW(tcph) ntohs((tcph)->th_win)
#define TCP_GET_RAW_URG_POINTER(tcph) ntohs((tcph)->th_urp)
-/** macro for getting the first timestamp from the packet. Timestamp is in host
- * order and either returned from the cache or from the packet directly. */
-#define TCP_GET_TSVAL(p) \
- (uint32_t)ntohl((*(uint32_t *)(p)->tcpvars.ts.data))
+/** macro for getting the first timestamp from the packet in host order */
+#define TCP_GET_TSVAL(p) ((p)->tcpvars.ts_val)
-/** macro for getting the second timestamp from the packet. Timestamp is in
- * host order and either returned from the cache or from the packet directly. */
-#define TCP_GET_TSECR(p) \
- (uint32_t)ntohl((*(uint32_t *)((p)->tcpvars.ts.data+4)))
+/** macro for getting the second timestamp from the packet in host order. */
+#define TCP_GET_TSECR(p) ((p)->tcpvars.ts_ecr)
#define TCP_HAS_WSCALE(p) ((p)->tcpvars.ws.type == TCP_OPT_WS)
#define TCP_HAS_SACK(p) ((p)->tcpvars.sack.type == TCP_OPT_SACK)
#define TCP_HAS_SACKOK(p) ((p)->tcpvars.sackok.type == TCP_OPT_SACKOK)
-#define TCP_HAS_TS(p) ((p)->tcpvars.ts.type == TCP_OPT_TS)
+#define TCP_HAS_TS(p) ((p)->tcpvars.ts_set == TRUE)
#define TCP_HAS_MSS(p) ((p)->tcpvars.mss.type == TCP_OPT_MSS)
/** macro for getting the wscale from the packet. */
typedef struct TCPVars_
{
/* commonly used and needed opts */
- TCPOpt ts;
+ _Bool ts_set;
+ uint32_t ts_val; /* host-order */
+ uint32_t ts_ecr; /* host-order */
TCPOpt sack;
TCPOpt sackok;
TCPOpt ws;
#define CLEAR_TCP_PACKET(p) { \
(p)->tcph = NULL; \
(p)->level4_comp_csum = -1; \
- (p)->tcpvars.ts.type = 0; \
+ (p)->tcpvars.ts_set = FALSE; \
+ (p)->tcpvars.ts_val = 0; \
+ (p)->tcpvars.ts_ecr = 0; \
(p)->tcpvars.sack.type = 0; \
(p)->tcpvars.sackok.type = 0; \
(p)->tcpvars.ws.type = 0; \
static int StreamTcpTest07 (void)
{
Packet *p = SCMalloc(SIZE_OF_PACKET);
- if (unlikely(p == NULL))
- return 0;
+ FAIL_IF(unlikely(p == NULL));
Flow f;
ThreadVars tv;
StreamTcpThread stt;
TCPHdr tcph;
uint8_t payload[1] = {0x42};
- uint32_t data[2];
PacketQueue pq;
memset(p, 0, SIZE_OF_PACKET);
FLOW_INITIALIZE(&f);
p->flow = &f;
- int ret = 0;
StreamTcpInitConfig(TRUE);
stream_config.midstream = TRUE;
tcph.th_flags = TH_ACK|TH_PUSH;
p->tcph = &tcph;
- data[0] = htonl(10);
- data[1] = htonl(11);
-
- p->tcpvars.ts.type = TCP_OPT_TS;
- p->tcpvars.ts.len = 10;
- p->tcpvars.ts.data = (uint8_t *)data;
+ p->tcpvars.ts_set = TRUE;
+ p->tcpvars.ts_val = 10;
+ p->tcpvars.ts_ecr = 11;
p->payload = payload;
p->payload_len = 1;
SCMutexLock(&f.m);
- if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
- goto end;
+ FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) == -1);
p->tcph->th_seq = htonl(11);
p->tcph->th_ack = htonl(23);
p->tcph->th_flags = TH_ACK|TH_PUSH;
p->flowflags = FLOW_PKT_TOSERVER;
- data[0] = htonl(2);
- p->tcpvars.ts.data = (uint8_t *)data;
+ p->tcpvars.ts_val = 2;
- if (StreamTcpPacket(&tv, p, &stt, &pq) == -1) {
- if (((TcpSession *) (p->flow->protoctx))->client.next_seq != 11) {
- printf("the timestamp values are client %"PRIu32" server %" PRIu32""
- " seq %" PRIu32 "\n", TCP_GET_TSVAL(p), TCP_GET_TSECR(p),
- ((TcpSession *) (p->flow->protoctx))->client.next_seq);
- goto end;
- }
+ FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) != -1);
- StreamTcpSessionClear(p->flow->protoctx);
- ret = 1;
- }
-end:
+ FAIL_IF (((TcpSession *) (p->flow->protoctx))->client.next_seq != 11);
+
+ StreamTcpSessionClear(p->flow->protoctx);
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
FLOW_DESTROY(&f);
- return ret;
+ PASS;
}
/**
static int StreamTcpTest08 (void)
{
-
Packet *p = SCMalloc(SIZE_OF_PACKET);
- if (unlikely(p == NULL))
- return 0;
+ FAIL_IF(unlikely(p == NULL));
Flow f;
ThreadVars tv;
StreamTcpThread stt;
TCPHdr tcph;
uint8_t payload[1] = {0x42};
- uint32_t data[2];
memset(p, 0, SIZE_OF_PACKET);
PacketQueue pq;
FLOW_INITIALIZE(&f);
p->flow = &f;
- int ret = 0;
StreamTcpInitConfig(TRUE);
stream_config.midstream = TRUE;
tcph.th_flags = TH_ACK|TH_PUSH;
p->tcph = &tcph;
- data[0] = htonl(10);
- data[1] = htonl(11);
-
- p->tcpvars.ts.type = TCP_OPT_TS;
- p->tcpvars.ts.len = 10;
- p->tcpvars.ts.data = (uint8_t *)data;
+ p->tcpvars.ts_set = TRUE;
+ p->tcpvars.ts_val = 10;
+ p->tcpvars.ts_ecr = 11;
p->payload = payload;
p->payload_len = 1;
SCMutexLock(&f.m);
- if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
- goto end;
+ FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) == -1);
p->tcph->th_seq = htonl(11);
p->tcph->th_ack = htonl(20);
p->tcph->th_flags = TH_ACK|TH_PUSH;
p->flowflags = FLOW_PKT_TOSERVER;
- data[0] = htonl(12);
- p->tcpvars.ts.data = (uint8_t *)data;
+ p->tcpvars.ts_val = 12;
- if (StreamTcpPacket(&tv, p, &stt, &pq) == -1)
- goto end;
+ FAIL_IF(StreamTcpPacket(&tv, p, &stt, &pq) == -1);
- if (((TcpSession *) (p->flow->protoctx))->client.next_seq != 12) {
- printf("the timestamp values are client %"PRIu32" server %" PRIu32 " "
- "seq %" PRIu32 "\n", TCP_GET_TSVAL(p), TCP_GET_TSECR(p),
- ((TcpSession *) (p->flow->protoctx))->client.next_seq);
- goto end;
- }
+ FAIL_IF(((TcpSession *) (p->flow->protoctx))->client.next_seq != 12);
StreamTcpSessionClear(p->flow->protoctx);
- ret = 1;
-end:
StreamTcpFreeConfig(TRUE);
SCMutexUnlock(&f.m);
SCFree(p);
FLOW_DESTROY(&f);
- return ret;
+ PASS;
}
/**