switch (o->type) {
/* See: RFC 4782 */
case IPV4_OPT_QS:
- if (p->IPV4_OPTS[p->IPV4_OPTS_CNT].len < IPV4_OPT_QS_MIN) {
+ if (o->len < IPV4_OPT_QS_MIN) {
ENGINE_SET_INVALID_EVENT(p, IPV4_OPT_INVALID_LEN);
return -1;
}
break;
/* See: RFC 1108 */
case IPV4_OPT_SEC:
- if (p->IPV4_OPTS[p->IPV4_OPTS_CNT].len != IPV4_OPT_SEC_LEN) {
+ if (o->len != IPV4_OPT_SEC_LEN) {
ENGINE_SET_INVALID_EVENT(p, IPV4_OPT_INVALID_LEN);
return -1;
}
break;
case IPV4_OPT_SID:
- if (p->IPV4_OPTS[p->IPV4_OPTS_CNT].len != IPV4_OPT_SID_LEN) {
+ if (o->len != IPV4_OPT_SID_LEN) {
ENGINE_SET_INVALID_EVENT(p, IPV4_OPT_INVALID_LEN);
return -1;
}
break;
/* See: RFC 2113 */
case IPV4_OPT_RTRALT:
- if (p->IPV4_OPTS[p->IPV4_OPTS_CNT].len != IPV4_OPT_RTRALT_LEN) {
+ if (o->len != IPV4_OPT_RTRALT_LEN) {
ENGINE_SET_INVALID_EVENT(p, IPV4_OPT_INVALID_LEN);
return -1;
}
return 0;
}
+typedef struct IPV4Options_ {
+ IPV4Opt o_rr;
+ IPV4Opt o_qs;
+ IPV4Opt o_ts;
+ IPV4Opt o_sec;
+ IPV4Opt o_lsrr;
+ IPV4Opt o_cipso;
+ IPV4Opt o_sid;
+ IPV4Opt o_ssrr;
+ IPV4Opt o_rtralt;
+} IPV4Options;
+
/**
* Decode/Validate IPv4 Options.
*/
-static int DecodeIPV4Options(Packet *p, uint8_t *pkt, uint16_t len)
+static int DecodeIPV4Options(Packet *p, uint8_t *pkt, uint16_t len, IPV4Options *opts)
{
uint16_t plen = len;
- p->IPV4_OPTS_CNT = 0;
-
#ifdef DEBUG
if (SCLogDebugEnabled()) {
uint16_t i;
while (plen)
{
+ p->ip4vars.opt_cnt++;
+
/* single byte options */
if (*pkt == IPV4_OPT_EOL) {
/** \todo What if more data exist after EOL (possible covert channel or data leakage)? */
SCLogDebug("IPV4OPT %" PRIu16 " len 1 @ %" PRIu16 "/%" PRIu16 "",
*pkt, (len - plen), (len - 1));
+ p->ip4vars.eol = TRUE;
break;
} else if (*pkt == IPV4_OPT_NOP) {
SCLogDebug("IPV4OPT %" PRIu16 " len 1 @ %" PRIu16 "/%" PRIu16 "",
pkt++;
plen--;
+ p->ip4vars.nop = TRUE;
+
/* multibyte options */
} else {
if (unlikely(plen < 2)) {
return -1;
}
- p->IPV4_OPTS[p->IPV4_OPTS_CNT].type = *pkt;
- p->IPV4_OPTS[p->IPV4_OPTS_CNT].len = *(pkt+1);
- if (plen > 2)
- p->IPV4_OPTS[p->IPV4_OPTS_CNT].data = (pkt+2);
- else
- p->IPV4_OPTS[p->IPV4_OPTS_CNT].data = NULL;
-
- SCLogDebug("IPV4OPT %" PRIu16 " len %" PRIu16 " @ %" PRIu16 "/%" PRIu16 "",
- p->IPV4_OPTS[p->IPV4_OPTS_CNT].type, p->IPV4_OPTS[p->IPV4_OPTS_CNT].len,
- (len - plen), (len - 1));
+ IPV4Opt opt = {*pkt, *(pkt+1), plen > 2 ? (pkt + 2) : NULL };
/* we already know that the total options len is valid,
* so here the len of the specific option must be bad.
* Also check for invalid lengths 0 and 1. */
- if (unlikely(p->IPV4_OPTS[p->IPV4_OPTS_CNT].len > plen ||
- p->IPV4_OPTS[p->IPV4_OPTS_CNT].len < 2)) {
+ if (unlikely(opt.len > plen || opt.len < 2)) {
ENGINE_SET_INVALID_EVENT(p, IPV4_OPT_INVALID_LEN);
return -1;
}
-
/* we are parsing the most commonly used opts to prevent
* us from having to walk the opts list for these all the
* time. */
/** \todo Figure out which IP options are more common and list them first */
- switch (p->IPV4_OPTS[p->IPV4_OPTS_CNT].type) {
+ switch (opt.type) {
case IPV4_OPT_TS:
- if (p->ip4vars.o_ts != NULL) {
+ if (opts->o_ts.type != 0) {
ENGINE_SET_EVENT(p,IPV4_OPT_DUPLICATE);
/* Warn - we can keep going */
break;
- } else if (IPV4OptValidateTimestamp(p,&p->IPV4_OPTS[p->IPV4_OPTS_CNT])) {
+ } else if (IPV4OptValidateTimestamp(p, &opt)) {
return -1;
}
- p->ip4vars.o_ts = &p->IPV4_OPTS[p->IPV4_OPTS_CNT];
+ opts->o_ts = opt;
+ p->ip4vars.ts = TRUE;
break;
case IPV4_OPT_RR:
- if (p->ip4vars.o_rr != NULL) {
+ if (opts->o_rr.type != 0) {
ENGINE_SET_EVENT(p,IPV4_OPT_DUPLICATE);
/* Warn - we can keep going */
break;
- } else if (IPV4OptValidateRoute(p,&p->IPV4_OPTS[p->IPV4_OPTS_CNT]) != 0) {
+ } else if (IPV4OptValidateRoute(p, &opt) != 0) {
return -1;
}
- p->ip4vars.o_rr = &p->IPV4_OPTS[p->IPV4_OPTS_CNT];
+ opts->o_rr = opt;
+ p->ip4vars.rr = TRUE;
break;
case IPV4_OPT_QS:
- if (p->ip4vars.o_qs != NULL) {
+ if (opts->o_qs.type != 0) {
ENGINE_SET_EVENT(p,IPV4_OPT_DUPLICATE);
/* Warn - we can keep going */
break;
- } else if (IPV4OptValidateGeneric(p, &p->IPV4_OPTS[p->IPV4_OPTS_CNT])) {
+ } else if (IPV4OptValidateGeneric(p, &opt)) {
return -1;
}
- p->ip4vars.o_qs = &p->IPV4_OPTS[p->IPV4_OPTS_CNT];
+ opts->o_qs = opt;
+ p->ip4vars.qs = TRUE;
break;
case IPV4_OPT_SEC:
- if (p->ip4vars.o_sec != NULL) {
+ if (opts->o_sec.type != 0) {
ENGINE_SET_EVENT(p,IPV4_OPT_DUPLICATE);
/* Warn - we can keep going */
break;
- } else if (IPV4OptValidateGeneric(p, &p->IPV4_OPTS[p->IPV4_OPTS_CNT])) {
+ } else if (IPV4OptValidateGeneric(p, &opt)) {
return -1;
}
- p->ip4vars.o_sec = &p->IPV4_OPTS[p->IPV4_OPTS_CNT];
+ opts->o_sec = opt;
+ p->ip4vars.sec = TRUE;
break;
case IPV4_OPT_LSRR:
- if (p->ip4vars.o_lsrr != NULL) {
+ if (opts->o_lsrr.type != 0) {
ENGINE_SET_EVENT(p,IPV4_OPT_DUPLICATE);
/* Warn - we can keep going */
break;
- } else if (IPV4OptValidateRoute(p,&p->IPV4_OPTS[p->IPV4_OPTS_CNT]) != 0) {
+ } else if (IPV4OptValidateRoute(p, &opt) != 0) {
return -1;
}
- p->ip4vars.o_lsrr = &p->IPV4_OPTS[p->IPV4_OPTS_CNT];
+ opts->o_lsrr = opt;
+ p->ip4vars.lsrr = TRUE;
break;
case IPV4_OPT_CIPSO:
- if (p->ip4vars.o_cipso != NULL) {
+ if (opts->o_cipso.type != 0) {
ENGINE_SET_EVENT(p,IPV4_OPT_DUPLICATE);
/* Warn - we can keep going */
break;
- } else if (IPV4OptValidateCIPSO(p,&p->IPV4_OPTS[p->IPV4_OPTS_CNT]) != 0) {
+ } else if (IPV4OptValidateCIPSO(p, &opt) != 0) {
return -1;
}
- p->ip4vars.o_cipso = &p->IPV4_OPTS[p->IPV4_OPTS_CNT];
+ opts->o_cipso = opt;
+ p->ip4vars.cipso = TRUE;
break;
case IPV4_OPT_SID:
- if (p->ip4vars.o_sid != NULL) {
+ if (opts->o_sid.type != 0) {
ENGINE_SET_EVENT(p,IPV4_OPT_DUPLICATE);
/* Warn - we can keep going */
break;
- } else if (IPV4OptValidateGeneric(p, &p->IPV4_OPTS[p->IPV4_OPTS_CNT])) {
+ } else if (IPV4OptValidateGeneric(p, &opt)) {
return -1;
}
- p->ip4vars.o_sid = &p->IPV4_OPTS[p->IPV4_OPTS_CNT];
+ opts->o_sid = opt;
+ p->ip4vars.sid = TRUE;
break;
case IPV4_OPT_SSRR:
- if (p->ip4vars.o_ssrr != NULL) {
+ if (opts->o_ssrr.type != 0) {
ENGINE_SET_EVENT(p,IPV4_OPT_DUPLICATE);
/* Warn - we can keep going */
break;
- } else if (IPV4OptValidateRoute(p,&p->IPV4_OPTS[p->IPV4_OPTS_CNT]) != 0) {
+ } else if (IPV4OptValidateRoute(p, &opt) != 0) {
return -1;
}
- p->ip4vars.o_ssrr = &p->IPV4_OPTS[p->IPV4_OPTS_CNT];
+ opts->o_ssrr = opt;
+ p->ip4vars.ssrr = TRUE;
break;
case IPV4_OPT_RTRALT:
- if (p->ip4vars.o_rtralt != NULL) {
+ if (opts->o_rtralt.type != 0) {
ENGINE_SET_EVENT(p,IPV4_OPT_DUPLICATE);
/* Warn - we can keep going */
break;
- } else if (IPV4OptValidateGeneric(p, &p->IPV4_OPTS[p->IPV4_OPTS_CNT])) {
+ } else if (IPV4OptValidateGeneric(p, &opt)) {
return -1;
}
- p->ip4vars.o_rtralt = &p->IPV4_OPTS[p->IPV4_OPTS_CNT];
+ opts->o_rtralt = opt;
+ p->ip4vars.rtralt = TRUE;
break;
default:
- SCLogDebug("IPV4OPT <unknown> (%" PRIu8 ") len %" PRIu8 "",
- p->IPV4_OPTS[p->IPV4_OPTS_CNT].type,
- p->IPV4_OPTS[p->IPV4_OPTS_CNT].len);
+ SCLogDebug("IPV4OPT <unknown> (%" PRIu8 ") len %" PRIu8,
+ opt.type, opt.len);
ENGINE_SET_EVENT(p,IPV4_OPT_INVALID);
/* Warn - we can keep going */
break;
}
- pkt += p->IPV4_OPTS[p->IPV4_OPTS_CNT].len;
- plen -= (p->IPV4_OPTS[p->IPV4_OPTS_CNT].len);
- p->IPV4_OPTS_CNT++;
+ pkt += opt.len;
+ plen -= opt.len;
}
}
/* save the options len */
uint8_t ip_opt_len = IPV4_GET_HLEN(p) - IPV4_HEADER_LEN;
if (ip_opt_len > 0) {
- DecodeIPV4Options(p, pkt + IPV4_HEADER_LEN, ip_opt_len);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ DecodeIPV4Options(p, pkt + IPV4_HEADER_LEN, ip_opt_len, &opts);
}
return 0;
/* UNITTESTS */
#ifdef UNITTESTS
-void DecodeIPV4OptionsPrint(Packet *p)
-{
- IPV4Vars *pv = &p->ip4vars;
-
- printf("DecodeIPV4Options: cnt=%" PRIu8
- ",rr={t=%" PRIu8 ",l=%" PRIu8 ",d=%p}"
- ",qs={t=%" PRIu8 ",l=%" PRIu8 ",d=%p}"
- ",ts={t=%" PRIu8 ",l=%" PRIu8 ",d=%p}"
- ",sec={t=%" PRIu8 ",l=%" PRIu8 ",d=%p}"
- ",lsrr={t=%" PRIu8 ",l=%" PRIu8 ",d=%p}"
- ",cipso={t=%" PRIu8 ",l=%" PRIu8 ",d=%p}"
- ",sid={t=%" PRIu8 ",l=%" PRIu8 ",d=%p}"
- ",ssrr={t=%" PRIu8 ",l=%" PRIu8 ",d=%p}"
- ",rtralt={t=%" PRIu8 ",l=%" PRIu8 ",d=%p}"
- "}\n",
- pv->ip_opt_cnt,
- (pv->o_rr ? pv->o_rr->type : 0), (pv->o_rr ? pv->o_rr->len : 0), (pv->o_rr ? pv->o_rr->data : 0),
- (pv->o_qs ? pv->o_qs->type : 0), (pv->o_qs ? pv->o_qs->len : 0), (pv->o_qs ? pv->o_qs->data : 0),
- (pv->o_ts ? pv->o_ts->type : 0), (pv->o_ts ? pv->o_ts->len : 0), (pv->o_ts ? pv->o_ts->data : 0),
- (pv->o_sec ? pv->o_sec->type : 0), (pv->o_sec ? pv->o_sec->len : 0), (pv->o_sec ? pv->o_sec->data : 0),
- (pv->o_lsrr ? pv->o_lsrr->type : 0), (pv->o_lsrr ? pv->o_lsrr->len : 0), (pv->o_lsrr ? pv->o_lsrr->data : 0),
- (pv->o_cipso ? pv->o_cipso->type : 0), (pv->o_cipso ? pv->o_cipso->len : 0), (pv->o_cipso ? pv->o_cipso->data : 0),
- (pv->o_sid ? pv->o_sid->type : 0), (pv->o_sid ? pv->o_sid->len : 0), (pv->o_sid ? pv->o_sid->data : 0),
- (pv->o_ssrr ? pv->o_ssrr->type : 0), (pv->o_ssrr ? pv->o_ssrr->len : 0), (pv->o_ssrr ? pv->o_ssrr->data : 0),
- (pv->o_rtralt ? pv->o_rtralt->type : 0), (pv->o_rtralt ? pv->o_rtralt->len : 0), (pv->o_rtralt ? pv->o_rtralt->data : 0));
-}
-
/** \test IPV4 with no options. */
int DecodeIPV4OptionsNONETest01(void)
{
uint8_t raw_opts[] = { };
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- uint8_t *data = (uint8_t *)p;
- uint16_t i;
- int rc;
-
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- if (rc != 0) {
- DecodeIPV4OptionsPrint(p);
- SCFree(p);
- return 0;
- }
+ FAIL_IF(unlikely(p == NULL));
- for (i = 0; i < (uint16_t)SIZE_OF_PACKET; i++) {
- if (*data) {
- /* Should not have modified packet data */
- //printf("Data modified at offset %" PRIu16 "\n", i);
- DecodeIPV4OptionsPrint(p);
- SCFree(p);
- return 0;
- }
- }
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc != 0);
SCFree(p);
- return 1;
+ PASS;
}
/** \test IPV4 with EOL option. */
IPV4_OPT_EOL, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- uint8_t *data = (uint8_t *)p;
- uint16_t i;
- int rc;
-
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- if (rc != 0) {
- DecodeIPV4OptionsPrint(p);
- SCFree(p);
- return 0;
- }
-
- for (i = 0; i < (uint16_t)SIZE_OF_PACKET; i++) {
- if (*data) {
- /* Should not have modified packet data */
- //printf("Data modified at offset %" PRIu16 "\n", i);
- DecodeIPV4OptionsPrint(p);
- SCFree(p);
- return 0;
- }
- }
-
+ FAIL_IF(unlikely(p == NULL));
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF (rc != 0);
SCFree(p);
- return 1;
+ PASS;
}
/** \test IPV4 with NOP option. */
IPV4_OPT_NOP, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- uint8_t *data = (uint8_t *)p;
- uint16_t i;
- int rc;
-
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- if (rc != 0) {
- DecodeIPV4OptionsPrint(p);
- SCFree(p);
- return 0;
- }
-
- for (i = 0; i < (uint16_t)SIZE_OF_PACKET; i++) {
- if (*data) {
- /* Should not have modified packet data */
- //printf("Data modified at offset %" PRIu16 "\n", i);
- DecodeIPV4OptionsPrint(p);
- SCFree(p);
- return 0;
- }
- }
-
+ FAIL_IF(unlikely(p == NULL));
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF (rc != 0);
SCFree(p);
- return 1;
+ PASS;
}
/** \test IPV4 with RR option. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
-
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",rr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_rr, (uintmax_t)&p.IPV4_OPTS[0]);
- if ( (rc == 0)
- && (p->IPV4_OPTS_CNT == 1)
- && (p->IPV4_OPTS[0].type == IPV4_OPT_RR)
- && (p->IPV4_OPTS[0].len == 0x27)
- && (p->ip4vars.o_rr == &p->IPV4_OPTS[0]))
- {
- SCFree(p);
- return 1;
- }
+ FAIL_IF(unlikely(p == NULL));
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc != 0);
+ FAIL_IF(opts.o_rr.type != IPV4_OPT_RR);
SCFree(p);
- return 0;
+ PASS;
}
/** \test IPV4 with RR option (len too large). */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
-
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",rr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_rr, (uintmax_t)&p.IPV4_OPTS[0]);
- if (rc != 0) {
- SCFree(p);
- return 1;
- }
+ FAIL_IF(unlikely(p == NULL));
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc == 0);
+ FAIL_IF(opts.o_rr.type != 0);
SCFree(p);
- return 0;
+ PASS;
}
/** \test IPV4 with RR option (ptr too large). */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
-
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",rr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_rr, (uintmax_t)&p.IPV4_OPTS[0]);
- if (rc != 0) {
- SCFree(p);
- return 1;
- }
+ FAIL_IF(unlikely(p == NULL));
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc == 0);
+ FAIL_IF(opts.o_rr.type != 0);
SCFree(p);
- return 0;
+ PASS;
}
/** \test IPV4 with RR option (ptr not in 4 byte increment). */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
-
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",rr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_rr, (uintmax_t)&p.IPV4_OPTS[0]);
- if (rc != 0) {
- SCFree(p);
- return 1;
- }
+ FAIL_IF(unlikely(p == NULL));
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc == 0);
+ FAIL_IF(opts.o_rr.type != 0);
SCFree(p);
- return 0;
+ PASS;
}
/** \test IPV4 with QS option. */
IPV4_OPT_QS, 0x08, 0x0d, 0x00, 0xbe, 0xef, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
-
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",qs=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_qs, (uintmax_t)&p.IPV4_OPTS[0]);
- if ( (rc == 0)
- && (p->IPV4_OPTS_CNT == 1)
- && (p->IPV4_OPTS[0].type == IPV4_OPT_QS)
- && (p->IPV4_OPTS[0].len == 0x08)
- && (p->ip4vars.o_qs == &p->IPV4_OPTS[0]))
- {
- SCFree(p);
- return 1;
- }
+ FAIL_IF(unlikely(p == NULL));
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc != 0);
+ FAIL_IF(opts.o_qs.type != IPV4_OPT_QS);
SCFree(p);
- return 0;
+ PASS;
}
/** \test IPV4 with QS option (len too small) */
IPV4_OPT_QS, 0x07, 0x0d, 0x00, 0xbe, 0xef, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
+ FAIL_IF(unlikely(p == NULL));
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",qs=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_qs, (uintmax_t)&p.IPV4_OPTS[0]);
- if (rc != 0) {
- SCFree(p);
- return 1;
- }
-
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc == 0);
+ FAIL_IF(opts.o_qs.type != 0);
SCFree(p);
- return 0;
+ PASS;
}
/** \test IPV4 with TS option. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
-
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",ts=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_ts, (uintmax_t)&p.IPV4_OPTS[0]);
- if ( (rc == 0)
- && (p->IPV4_OPTS_CNT == 1)
- && (p->IPV4_OPTS[0].type == IPV4_OPT_TS)
- && (p->IPV4_OPTS[0].len == 0x24)
- && (p->ip4vars.o_ts == &p->IPV4_OPTS[0]))
- {
- SCFree(p);
- return 1;
- }
+ FAIL_IF(unlikely(p == NULL));
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc != 0);
+ FAIL_IF(opts.o_ts.type != IPV4_OPT_TS);
SCFree(p);
- return 0;
+ PASS;
}
/** \test IPV4 with TS option (ptr too small). */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
+ FAIL_IF(unlikely(p == NULL));
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",ts=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_ts, (uintmax_t)&p.IPV4_OPTS[0]);
- if (rc != 0) {
- SCFree(p);
- return 1;
- }
-
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc == 0);
+ FAIL_IF(opts.o_ts.type != 0);
SCFree(p);
- return 0;
+ PASS;
}
/** \test IPV4 with TS option (ptr too large). */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
+ FAIL_IF(unlikely(p == NULL));
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",ts=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_ts, (uintmax_t)&p.IPV4_OPTS[0]);
- if (rc != 0) {
- SCFree(p);
- return 1;
- }
-
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc == 0);
+ FAIL_IF(opts.o_ts.type != 0);
SCFree(p);
- return 0;
+ PASS;
}
/** \test IPV4 with TS option (ptr not valid). */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
+ FAIL_IF(unlikely(p == NULL));
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",ts=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_ts, (uintmax_t)&p.IPV4_OPTS[0]);
- if (rc != 0) {
- SCFree(p);
- return 1;
- }
-
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc == 0);
+ FAIL_IF(opts.o_ts.type != 0);
SCFree(p);
- return 0;
+ PASS;
}
/** \test IPV4 with SEC option. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
-
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",sec=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_sec, (uintmax_t)&p.IPV4_OPTS[0]);
- if ( (rc == 0)
- && (p->IPV4_OPTS_CNT == 1)
- && (p->IPV4_OPTS[0].type == IPV4_OPT_SEC)
- && (p->IPV4_OPTS[0].len == 0x0b)
- && (p->ip4vars.o_sec == &p->IPV4_OPTS[0]))
- {
- SCFree(p);
- return 1;
- }
+ FAIL_IF(unlikely(p == NULL));
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc != 0);
+ FAIL_IF(opts.o_sec.type != IPV4_OPT_SEC);
SCFree(p);
- return 0;
+ PASS;
}
/** \test IPV4 with SEC option (invalid length). */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
+ FAIL_IF(unlikely(p == NULL));
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",sec=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_sec, (uintmax_t)&p.IPV4_OPTS[0]);
- if (rc != 0) {
- SCFree(p);
- return 1;
- }
-
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc == 0);
+ FAIL_IF(opts.o_sec.type != 0);
SCFree(p);
- return 0;
+ PASS;
}
/** \test IPV4 with LSRR option. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
-
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",lsrr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_lsrr, (uintmax_t)&p.IPV4_OPTS[0]);
- if ( (rc == 0)
- && (p->IPV4_OPTS_CNT == 1)
- && (p->IPV4_OPTS[0].type == IPV4_OPT_LSRR)
- && (p->IPV4_OPTS[0].len == 0x27)
- && (p->ip4vars.o_lsrr == &p->IPV4_OPTS[0]))
- {
- SCFree(p);
- return 1;
- }
+ FAIL_IF(unlikely(p == NULL));
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc != 0);
+ FAIL_IF(opts.o_lsrr.type != IPV4_OPT_LSRR);
SCFree(p);
- return 0;
+ PASS;
}
/** \test IPV4 with LSRR option (len too large). */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
+ FAIL_IF(unlikely(p == NULL));
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",lsrr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_lsrr, (uintmax_t)&p.IPV4_OPTS[0]);
- if (rc != 0) {
- SCFree(p);
- return 1;
- }
-
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc == 0);
+ FAIL_IF(opts.o_lsrr.type != 0);
SCFree(p);
- return 0;
+ PASS;
}
/** \test IPV4 with LSRR option (ptr too large). */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
+ FAIL_IF(unlikely(p == NULL));
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",lsrr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_lsrr, (uintmax_t)&p.IPV4_OPTS[0]);
- if (rc != 0) {
- SCFree(p);
- return 1;
- }
-
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc == 0);
+ FAIL_IF(opts.o_lsrr.type != 0);
SCFree(p);
- return 0;
+ PASS;
}
/** \test IPV4 with LSRR option (ptr not in 4 byte increment). */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
+ FAIL_IF(unlikely(p == NULL));
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",lsrr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_lsrr, (uintmax_t)&p.IPV4_OPTS[0]);
- if (rc != 0) {
- SCFree(p);
- return 1;
- }
-
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc == 0);
+ FAIL_IF(opts.o_lsrr.type != 0);
SCFree(p);
- return 0;
+ PASS;
}
/** \test IPV4 with CIPSO option. */
0x00, 0x04, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
-
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",rr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_cipso, (uintmax_t)&p.IPV4_OPTS[0]);
- if ( (rc == 0)
- && (p->IPV4_OPTS_CNT == 1)
- && (p->IPV4_OPTS[0].type == IPV4_OPT_CIPSO)
- && (p->IPV4_OPTS[0].len == 0x18)
- && (p->ip4vars.o_cipso == &p->IPV4_OPTS[0]))
- {
- SCFree(p);
- return 1;
- }
+ FAIL_IF(unlikely(p == NULL));
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc != 0);
+ FAIL_IF(opts.o_cipso.type != IPV4_OPT_CIPSO);
SCFree(p);
- return 0;
+ PASS;
}
/** \test IPV4 with SID option. */
IPV4_OPT_SID, 0x04, 0xbe, 0xef, 0x00, 0x00, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
-
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",sid=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_sid, (uintmax_t)&p.IPV4_OPTS[0]);
- if ( (rc == 0)
- && (p->IPV4_OPTS_CNT == 1)
- && (p->IPV4_OPTS[0].type == IPV4_OPT_SID)
- && (p->IPV4_OPTS[0].len == 0x04)
- && (p->ip4vars.o_sid == &p->IPV4_OPTS[0]))
- {
- SCFree(p);
- return 1;
- }
+ FAIL_IF(unlikely(p == NULL));
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc != 0);
+ FAIL_IF(opts.o_sid.type != IPV4_OPT_SID);
SCFree(p);
- return 0;
+ PASS;
}
/** \test IPV4 with SID option (len invalid. */
IPV4_OPT_SID, 0x05, 0xbe, 0xef, 0x00, 0x00, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
-
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",sid=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_sid, (uintmax_t)&p.IPV4_OPTS[0]);
- if (rc != 0) {
- SCFree(p);
- return 1;
- }
+ FAIL_IF(unlikely(p == NULL));
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc == 0);
+ FAIL_IF(opts.o_sid.type != 0);
SCFree(p);
- return 0;
+ PASS;
}
/** \test IPV4 with SSRR option. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
-
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",ssrr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_ssrr, (uintmax_t)&p.IPV4_OPTS[0]);
- if ( (rc == 0)
- && (p->IPV4_OPTS_CNT == 1)
- && (p->IPV4_OPTS[0].type == IPV4_OPT_SSRR)
- && (p->IPV4_OPTS[0].len == 0x27)
- && (p->ip4vars.o_ssrr == &p->IPV4_OPTS[0]))
- {
- SCFree(p);
- return 1;
- }
+ FAIL_IF(unlikely(p == NULL));
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc != 0);
+ FAIL_IF(opts.o_ssrr.type != IPV4_OPT_SSRR);
SCFree(p);
- return 0;
+ PASS;
}
/** \test IPV4 with SSRR option (len too large). */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
-
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",ssrr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_ssrr, (uintmax_t)&p.IPV4_OPTS[0]);
- if (rc != 0) {
- SCFree(p);
- return 1;
- }
+ FAIL_IF(unlikely(p == NULL));
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc == 0);
+ FAIL_IF(opts.o_ssrr.type != 0);
SCFree(p);
- return 0;
+ PASS;
}
/** \test IPV4 with SSRR option (ptr too large). */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
-
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",ssrr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_ssrr, (uintmax_t)&p.IPV4_OPTS[0]);
- if (rc != 0) {
- SCFree(p);
- return 1;
- }
+ FAIL_IF(unlikely(p == NULL));
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc == 0);
+ FAIL_IF(opts.o_ssrr.type != 0);
SCFree(p);
- return 0;
+ PASS;
}
/** \test IPV4 with SSRR option (ptr not in 4 byte increment). */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
-
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",ssrr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_ssrr, (uintmax_t)&p.IPV4_OPTS[0]);
- if (rc != 0) {
- SCFree(p);
- return 1;
- }
+ FAIL_IF(unlikely(p == NULL));
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc == 0);
+ FAIL_IF(opts.o_ssrr.type != 0);
SCFree(p);
- return 0;
+ PASS;
}
/** \test IPV4 with RTRALT option. */
IPV4_OPT_RTRALT, 0x04, 0xbe, 0xef, 0x00, 0x00, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
-
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",rtralt=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_rtralt, (uintmax_t)&p.IPV4_OPTS[0]);
- if ( (rc == 0)
- && (p->IPV4_OPTS_CNT == 1)
- && (p->IPV4_OPTS[0].type == IPV4_OPT_RTRALT)
- && (p->IPV4_OPTS[0].len == 0x04)
- && (p->ip4vars.o_rtralt == &p->IPV4_OPTS[0]))
- {
- SCFree(p);
- return 1;
- }
+ FAIL_IF(unlikely(p == NULL));
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc != 0);
+ FAIL_IF(opts.o_rtralt.type != IPV4_OPT_RTRALT);
SCFree(p);
- return 0;
+ PASS;
}
/** \test IPV4 with RTRALT option (len invalid. */
IPV4_OPT_RTRALT, 0x05, 0xbe, 0xef, 0x00, 0x00, 0x00, 0x00
};
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
- int rc;
-
- rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts));
- //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",rtralt=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_rtralt, (uintmax_t)&p.IPV4_OPTS[0]);
- if (rc != 0) {
- SCFree(p);
- return 1;
- }
+ FAIL_IF(unlikely(p == NULL));
- DecodeIPV4OptionsPrint(p);
+ IPV4Options opts;
+ memset(&opts, 0x00, sizeof(opts));
+ int rc = DecodeIPV4Options(p, raw_opts, sizeof(raw_opts), &opts);
+ FAIL_IF(rc == 0);
+ FAIL_IF(opts.o_rtralt.type != 0);
SCFree(p);
- return 0;
+ PASS;
}
static int IPV4CalculateValidChecksumtest01(void)