decode: reduce PKT_IS_IPV4/PKT_IS_IPV6 use

Replace it with inline functions. Adds inline functions to
wrap PKT_IS_IPV4/PKT_IS_IPV6.

This is in preparation of removing the macro's, and cleaning up the
header pointers.

Ticket: #5517.
pull/10971/head
Victor Julien 3 years ago committed by Victor Julien
parent 813147755d
commit eb3ca643c1

@ -173,11 +173,11 @@ static TmEcode AlertDebugLogger(ThreadVars *tv, const Packet *p, void *thread_da
MemBufferWriteString(aft->buffer, "PKT SRC: %s\n", pkt_src_str);
char srcip[46], dstip[46];
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
PrintInet(AF_INET, (const void *)GET_IPV4_SRC_ADDR_PTR(p), srcip, sizeof(srcip));
PrintInet(AF_INET, (const void *)GET_IPV4_DST_ADDR_PTR(p), dstip, sizeof(dstip));
} else {
DEBUG_VALIDATE_BUG_ON(!(PKT_IS_IPV6(p)));
DEBUG_VALIDATE_BUG_ON(!(PacketIsIPv6(p)));
PrintInet(AF_INET6, (const void *)GET_IPV6_SRC_ADDR(p), srcip, sizeof(srcip));
PrintInet(AF_INET6, (const void *)GET_IPV6_DST_ADDR(p), dstip, sizeof(dstip));
}
@ -473,7 +473,7 @@ static bool AlertDebugLogCondition(ThreadVars *tv, void *thread_data, const Pack
static int AlertDebugLogLogger(ThreadVars *tv, void *thread_data, const Packet *p)
{
if (PKT_IS_IPV4(p) || PKT_IS_IPV6(p)) {
if (PacketIsIPv4(p) || PacketIsIPv6(p)) {
return AlertDebugLogger(tv, p, thread_data);
} else if (p->events.cnt > 0) {
return AlertDebugLogDecoderEvent(tv, p, thread_data);

@ -109,10 +109,10 @@ int AlertFastLogger(ThreadVars *tv, void *data, const Packet *p)
CreateTimeString(p->ts, timebuf, sizeof(timebuf));
char srcip[46], dstip[46];
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
PrintInet(AF_INET, (const void *)GET_IPV4_SRC_ADDR_PTR(p), srcip, sizeof(srcip));
PrintInet(AF_INET, (const void *)GET_IPV4_DST_ADDR_PTR(p), dstip, sizeof(dstip));
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
PrintInet(AF_INET6, (const void *)GET_IPV6_SRC_ADDR(p), srcip, sizeof(srcip));
PrintInet(AF_INET6, (const void *)GET_IPV6_DST_ADDR(p), dstip, sizeof(dstip));
} else {

@ -364,9 +364,9 @@ static bool AlertSyslogCondition(ThreadVars *tv, void *thread_data, const Packet
static int AlertSyslogLogger(ThreadVars *tv, void *thread_data, const Packet *p)
{
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
return AlertSyslogIPv4(tv, p, thread_data);
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
return AlertSyslogIPv6(tv, p, thread_data);
} else if (p->events.cnt > 0) {
return AlertSyslogDecoderEvent(tv, p, thread_data);

@ -88,7 +88,7 @@ static int DecodeCHDLCTest01 (void)
DecodeCHDLC(&tv, &dtv, p, raw, sizeof(raw));
FAIL_IF_NOT(PKT_IS_IPV4(p));
FAIL_IF_NOT(PacketIsIPv4(p));
FAIL_IF_NOT(PKT_IS_TCP(p));
FAIL_IF_NOT(p->dp == 80);

@ -113,12 +113,7 @@ static int DecodeRawTest01 (void)
FlowInitConfig(FLOW_QUIET);
DecodeRaw(&tv, &dtv, p, raw_ip, GET_PKT_LEN(p));
if (p->ip6h == NULL) {
printf("expected a valid ipv6 header but it was NULL: ");
FlowShutdown();
SCFree(p);
return 0;
}
FAIL_IF_NOT(PacketIsIPv6(p));
PacketRecycle(p);
FlowShutdown();
@ -159,13 +154,7 @@ static int DecodeRawTest02 (void)
FlowInitConfig(FLOW_QUIET);
DecodeRaw(&tv, &dtv, p, raw_ip, GET_PKT_LEN(p));
if (p->ip4h == NULL) {
printf("expected a valid ipv4 header but it was NULL: ");
PacketRecycle(p);
FlowShutdown();
SCFree(p);
return 0;
}
FAIL_IF_NOT(PacketIsIPv4(p));
PacketRecycle(p);
FlowShutdown();

@ -690,6 +690,16 @@ static inline uint8_t PacketGetIPProto(const Packet *p)
}
}
static inline bool PacketIsIPv4(const Packet *p)
{
return PKT_IS_IPV4(p);
}
static inline bool PacketIsIPv6(const Packet *p)
{
return PKT_IS_IPV6(p);
}
/** \brief Structure to hold thread specific data for all decode modules */
typedef struct DecodeThreadVars_
{

@ -93,9 +93,9 @@ int DefragPolicyGetHostTimeout(Packet *p)
{
int timeout = 0;
if (PKT_IS_IPV4(p))
if (PacketIsIPv4(p))
timeout = DefragPolicyGetIPv4HostTimeout((uint8_t *)GET_IPV4_DST_ADDR_PTR(p));
else if (PKT_IS_IPV6(p))
else if (PacketIsIPv6(p))
timeout = DefragPolicyGetIPv6HostTimeout((uint8_t *)GET_IPV6_DST_ADDR(p));
if (timeout <= 0)

@ -127,7 +127,7 @@ static void DefragTrackerInit(DefragTracker *dt, Packet *p)
COPY_ADDRESS(&p->src, &dt->src_addr);
COPY_ADDRESS(&p->dst, &dt->dst_addr);
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
dt->id = (int32_t)IPV4_GET_IPID(p);
dt->af = AF_INET;
} else {
@ -450,7 +450,7 @@ static inline uint32_t DefragHashGetKey(Packet *p)
static inline int DefragTrackerCompare(DefragTracker *t, Packet *p)
{
uint32_t id;
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
id = (uint32_t)IPV4_GET_IPID(p);
} else {
id = IPV6_EXTHDR_GET_FH_ID(p);

@ -971,10 +971,9 @@ DefragGetOsPolicy(Packet *p)
{
int policy = -1;
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
policy = SCHInfoGetIPv4HostOSFlavour((uint8_t *)GET_IPV4_DST_ADDR_PTR(p));
}
else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
policy = SCHInfoGetIPv6HostOSFlavour((uint8_t *)GET_IPV6_DST_ADDR(p));
}
@ -1053,17 +1052,15 @@ Defrag(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p)
DefragTracker *tracker;
int af;
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
af = AF_INET;
more_frags = IPV4_GET_MF(p);
frag_offset = IPV4_GET_IPOFFSET(p);
}
else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
af = AF_INET6;
frag_offset = IPV6_EXTHDR_GET_FH_OFFSET(p);
more_frags = IPV6_EXTHDR_GET_FH_FLAG(p);
}
else {
} else {
return NULL;
}

@ -417,7 +417,7 @@ static int DetectTCPV6CsumMatch(DetectEngineThreadCtx *det_ctx,
{
const DetectCsumData *cd = (const DetectCsumData *)ctx;
if (p->ip6h == NULL || p->tcph == NULL || p->proto != IPPROTO_TCP || PKT_IS_PSEUDOPKT(p))
if (!PacketIsIPv6(p) || p->tcph == NULL || p->proto != IPPROTO_TCP || PKT_IS_PSEUDOPKT(p))
return 0;
if (p->flags & PKT_IGNORE_CHECKSUM) {
@ -597,7 +597,7 @@ static int DetectUDPV6CsumMatch(DetectEngineThreadCtx *det_ctx,
{
const DetectCsumData *cd = (const DetectCsumData *)ctx;
if (p->ip6h == NULL || p->udph == NULL || p->proto != IPPROTO_UDP || PKT_IS_PSEUDOPKT(p))
if (!PacketIsIPv6(p) || p->udph == NULL || p->proto != IPPROTO_UDP || PKT_IS_PSEUDOPKT(p))
return 0;
if (p->flags & PKT_IGNORE_CHECKSUM) {
@ -775,8 +775,9 @@ static int DetectICMPV6CsumMatch(DetectEngineThreadCtx *det_ctx,
{
const DetectCsumData *cd = (const DetectCsumData *)ctx;
if (p->ip6h == NULL || p->icmpv6h == NULL || p->proto != IPPROTO_ICMPV6 || PKT_IS_PSEUDOPKT(p) ||
(GET_PKT_LEN(p) - ((uint8_t *)p->icmpv6h - GET_PKT_DATA(p))) <= 0) {
if (!PacketIsIPv6(p) || p->icmpv6h == NULL || p->proto != IPPROTO_ICMPV6 ||
PKT_IS_PSEUDOPKT(p) ||
(GET_PKT_LEN(p) - ((uint8_t *)p->icmpv6h - GET_PKT_DATA(p))) <= 0) {
return 0;
}

@ -77,7 +77,7 @@ static int PacketAlertHandle(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det
const DetectThresholdData *td = NULL;
const SigMatchData *smd;
if (!(PKT_IS_IPV4(p) || PKT_IS_IPV6(p))) {
if (!(PacketIsIPv4(p) || PacketIsIPv6(p))) {
SCReturnInt(1);
}

@ -1049,11 +1049,11 @@ void IPOnlyMatchPacket(ThreadVars *tv, const DetectEngineCtx *de_ctx,
if (bitarray & 0x01) {
const Signature *s = de_ctx->sig_array[io_ctx->sig_mapping[u * 8 + i]];
if ((s->proto.flags & DETECT_PROTO_IPV4) && !PKT_IS_IPV4(p)) {
if ((s->proto.flags & DETECT_PROTO_IPV4) && !PacketIsIPv4(p)) {
SCLogDebug("ip version didn't match");
continue;
}
if ((s->proto.flags & DETECT_PROTO_IPV6) && !PKT_IS_IPV6(p)) {
if ((s->proto.flags & DETECT_PROTO_IPV6) && !PacketIsIPv6(p)) {
SCLogDebug("ip version didn't match");
continue;
}

@ -142,7 +142,7 @@ FragBitsMatch(const uint8_t pbits, const uint8_t modifier,
static int DetectFragBitsMatch (DetectEngineThreadCtx *det_ctx,
Packet *p, const Signature *s, const SigMatchCtx *ctx)
{
if (!ctx || !PKT_IS_IPV4(p) || PKT_IS_PSEUDOPKT(p))
if (!ctx || !PacketIsIPv4(p) || PKT_IS_PSEUDOPKT(p))
return 0;
uint8_t fragbits = 0;
@ -321,7 +321,7 @@ PrefilterPacketFragBitsMatch(DetectEngineThreadCtx *det_ctx, Packet *p, const vo
{
const PrefilterPacketHeaderCtx *ctx = pectx;
if (!PKT_IS_IPV4(p) || PKT_IS_PSEUDOPKT(p))
if (!PacketIsIPv4(p) || PKT_IS_PSEUDOPKT(p))
return;
uint8_t fragbits = 0;

@ -114,9 +114,9 @@ static int DetectFragOffsetMatch (DetectEngineThreadCtx *det_ctx,
if (PKT_IS_PSEUDOPKT(p))
return 0;
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
frag = IPV4_GET_IPOFFSET(p);
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
if (IPV6_EXTHDR_ISSET_FH(p)) {
frag = IPV6_EXTHDR_GET_FH_OFFSET(p);
} else {
@ -268,9 +268,9 @@ PrefilterPacketFragOffsetMatch(DetectEngineThreadCtx *det_ctx, Packet *p, const
uint16_t frag;
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
frag = IPV4_GET_IPOFFSET(p);
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
if (IPV6_EXTHDR_ISSET_FH(p)) {
frag = IPV6_EXTHDR_GET_FH_OFFSET(p);
} else {

@ -253,8 +253,7 @@ static int DetectGeoipMatch(DetectEngineThreadCtx *det_ctx,
if (PKT_IS_PSEUDOPKT(p))
return 0;
if (PKT_IS_IPV4(p))
{
if (PacketIsIPv4(p)) {
if (geoipdata->flags & ( GEOIP_MATCH_SRC_FLAG | GEOIP_MATCH_BOTH_FLAG ))
{
if (CheckGeoMatchIPv4(geoipdata, GET_IPV4_SRC_ADDR_U32(p)))

@ -98,7 +98,7 @@ static int DetectIdMatch (DetectEngineThreadCtx *det_ctx, Packet *p,
/**
* To match a ipv4 packet with a "id" rule
*/
if (!PKT_IS_IPV4(p) || PKT_IS_PSEUDOPKT(p)) {
if (!PacketIsIPv4(p) || PKT_IS_PSEUDOPKT(p)) {
return 0;
}
@ -225,7 +225,7 @@ PrefilterPacketIdMatch(DetectEngineThreadCtx *det_ctx, Packet *p, const void *pe
{
const PrefilterPacketHeaderCtx *ctx = pectx;
if (!PKT_IS_IPV4(p) || PKT_IS_PSEUDOPKT(p)) {
if (!PacketIsIPv4(p) || PKT_IS_PSEUDOPKT(p)) {
return;
}

@ -120,10 +120,10 @@ static InspectionBuffer *GetDataSrc(DetectEngineThreadCtx *det_ctx,
{
InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
if (buffer->inspect == NULL) {
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
/* Suricata stores the IPv4 at the beginning of the field */
InspectionBufferSetup(det_ctx, list_id, buffer, p->src.address.address_un_data8, 4);
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
InspectionBufferSetup(det_ctx, list_id, buffer, p->src.address.address_un_data8, 16);
} else {
return NULL;
@ -144,10 +144,10 @@ static InspectionBuffer *GetDataDst(DetectEngineThreadCtx *det_ctx,
{
InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
if (buffer->inspect == NULL) {
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
/* Suricata stores the IPv4 at the beginning of the field */
InspectionBufferSetup(det_ctx, list_id, buffer, p->dst.address.address_un_data8, 4);
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
InspectionBufferSetup(det_ctx, list_id, buffer, p->dst.address.address_un_data8, 16);
} else {
return NULL;

@ -159,7 +159,7 @@ static int DetectIpOptsMatch (DetectEngineThreadCtx *det_ctx, Packet *p,
{
const DetectIpOptsData *de = (const DetectIpOptsData *)ctx;
if (!de || !PKT_IS_IPV4(p) || PKT_IS_PSEUDOPKT(p))
if (!de || !PacketIsIPv4(p) || PKT_IS_PSEUDOPKT(p))
return 0;
return (p->ip4vars.opts_set & de->ipopt) == de->ipopt;

@ -100,8 +100,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,
InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
if (buffer->inspect == NULL) {
if (p->ip6h == NULL) {
// DETECT_PROTO_IPV6 does not prefilter
if (!PacketIsIPv6(p)) {
return NULL;
}
uint32_t hlen = IPV6_HEADER_LEN + IPV6_GET_EXTHDRS_LEN(p);

@ -96,9 +96,9 @@ static int DetectTemplateMatch (DetectEngineThreadCtx *det_ctx, Packet *p,
/* fake pkt */
}
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
/* ipv4 pkt */
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
/* ipv6 pkt */
} else {
SCLogDebug("packet is of not IPv4 or IPv6");

@ -83,9 +83,9 @@ static int DetectTemplate2Match (DetectEngineThreadCtx *det_ctx, Packet *p,
/* TODO replace this */
uint8_t ptemplate2;
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
ptemplate2 = IPV4_GET_IPTTL(p);
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
ptemplate2 = IPV6_GET_HLIM(p);
} else {
SCLogDebug("Packet is of not IPv4 or IPv6");
@ -143,9 +143,9 @@ PrefilterPacketTemplate2Match(DetectEngineThreadCtx *det_ctx, Packet *p, const v
uint8_t ptemplate2;
/* TODO update */
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
ptemplate2 = IPV4_GET_IPTTL(p);
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
ptemplate2 = IPV6_GET_HLIM(p);
} else {
SCLogDebug("Packet is of not IPv4 or IPv6");

@ -96,7 +96,7 @@ static int DetectTosMatch(DetectEngineThreadCtx *det_ctx, Packet *p,
const DetectTosData *tosd = (const DetectTosData *)ctx;
int result = 0;
if (!PKT_IS_IPV4(p) || PKT_IS_PSEUDOPKT(p)) {
if (!PacketIsIPv4(p) || PKT_IS_PSEUDOPKT(p)) {
return 0;
}

@ -87,9 +87,9 @@ static int DetectTtlMatch (DetectEngineThreadCtx *det_ctx, Packet *p,
return 0;
uint8_t pttl;
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
pttl = IPV4_GET_IPTTL(p);
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
pttl = IPV6_GET_HLIM(p);
} else {
SCLogDebug("Packet is not IPv4 or IPv6");
@ -145,9 +145,9 @@ PrefilterPacketTtlMatch(DetectEngineThreadCtx *det_ctx, Packet *p, const void *p
}
uint8_t pttl;
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
pttl = IPV4_GET_IPTTL(p);
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
pttl = IPV6_GET_HLIM(p);
} else {
SCLogDebug("Packet is not IPv4 or IPv6");

@ -223,7 +223,7 @@ const SigGroupHead *SigMatchSignaturesGetSgh(const DetectEngineCtx *de_ctx,
if (p->proto == 0 && p->events.cnt > 0) {
SCReturnPtr(de_ctx->decoder_event_sgh, "SigGroupHead");
} else if (p->proto == 0) {
if (!(PKT_IS_IPV4(p) || PKT_IS_IPV6(p))) {
if (!(PacketIsIPv4(p) || PacketIsIPv6(p))) {
/* not IP, so nothing to do */
SCReturnPtr(NULL, "SigGroupHead");
}
@ -608,11 +608,11 @@ static inline bool DetectRunInspectRuleHeader(const Packet *p, const Flow *f, co
}
}
if ((s_proto_flags & DETECT_PROTO_IPV4) && !PKT_IS_IPV4(p)) {
if ((s_proto_flags & DETECT_PROTO_IPV4) && !PacketIsIPv4(p)) {
SCLogDebug("ip version didn't match");
return false;
}
if ((s_proto_flags & DETECT_PROTO_IPV6) && !PKT_IS_IPV6(p)) {
if ((s_proto_flags & DETECT_PROTO_IPV6) && !PacketIsIPv6(p)) {
SCLogDebug("ip version didn't match");
return false;
}
@ -649,20 +649,20 @@ static inline bool DetectRunInspectRuleHeader(const Packet *p, const Flow *f, co
/* check the destination address */
if (!(sflags & SIG_FLAG_DST_ANY)) {
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
if (DetectAddressMatchIPv4(s->addr_dst_match4, s->addr_dst_match4_cnt, &p->dst) == 0)
return false;
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
if (DetectAddressMatchIPv6(s->addr_dst_match6, s->addr_dst_match6_cnt, &p->dst) == 0)
return false;
}
}
/* check the source address */
if (!(sflags & SIG_FLAG_SRC_ANY)) {
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
if (DetectAddressMatchIPv4(s->addr_src_match4, s->addr_src_match4_cnt, &p->src) == 0)
return false;
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
if (DetectAddressMatchIPv6(s->addr_src_match6, s->addr_src_match6_cnt, &p->src) == 0)
return false;
}

@ -153,12 +153,12 @@ void FlowInit(Flow *f, const Packet *p)
f->vlan_idx = p->vlan_idx;
f->livedev = p->livedev;
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
FLOW_SET_IPV4_SRC_ADDR_FROM_PACKET(p, &f->src);
FLOW_SET_IPV4_DST_ADDR_FROM_PACKET(p, &f->dst);
f->min_ttl_toserver = f->max_ttl_toserver = IPV4_GET_IPTTL((p));
f->flags |= FLOW_IPV4;
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
FLOW_SET_IPV6_SRC_ADDR_FROM_PACKET(p, &f->src);
FLOW_SET_IPV6_DST_ADDR_FROM_PACKET(p, &f->dst);
f->min_ttl_toserver = f->max_ttl_toserver = IPV6_GET_HLIM((p));

@ -437,9 +437,9 @@ void FlowHandlePacketUpdate(Flow *f, Packet *p, ThreadVars *tv, DecodeThreadVars
}
FlowUpdateEthernet(tv, dtv, f, p->ethh, true);
/* update flow's ttl fields if needed */
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
FlowUpdateTtlTS(f, p, IPV4_GET_IPTTL(p));
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
FlowUpdateTtlTS(f, p, IPV6_GET_HLIM(p));
}
} else {
@ -459,9 +459,9 @@ void FlowHandlePacketUpdate(Flow *f, Packet *p, ThreadVars *tv, DecodeThreadVars
}
FlowUpdateEthernet(tv, dtv, f, p->ethh, false);
/* update flow's ttl fields if needed */
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
FlowUpdateTtlTC(f, p, IPV4_GET_IPTTL(p));
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
FlowUpdateTtlTC(f, p, IPV6_GET_HLIM(p));
}
}

@ -492,9 +492,9 @@ int LogHttpLogger(ThreadVars *tv, void *thread_data, const Packet *p, Flow *f, v
}
int r = 0;
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
r = LogHttpLogIPWrapper(tv, thread_data, p, f, (HtpState *)state, (htp_tx_t *)tx, tx_id, AF_INET);
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
r = LogHttpLogIPWrapper(tv, thread_data, p, f, (HtpState *)state, (htp_tx_t *)tx, tx_id, AF_INET6);
}

@ -478,7 +478,7 @@ static int LogTlsLogger(ThreadVars *tv, void *thread_data, const Packet *p,
{
LogTlsLogThread *aft = (LogTlsLogThread *)thread_data;
LogTlsFileCtx *hlog = aft->tlslog_ctx;
int ipproto = (PKT_IS_IPV4(p)) ? AF_INET : AF_INET6;
int ipproto = (PacketIsIPv4(p)) ? AF_INET : AF_INET6;
SSLState *ssl_state = (SSLState *)state;
if (unlikely(ssl_state == NULL)) {

@ -259,7 +259,7 @@ static int LogTlsStoreLogger(ThreadVars *tv, void *thread_data, const Packet *p,
Flow *f, void *state, void *tx, uint64_t tx_id)
{
LogTlsStoreLogThread *aft = (LogTlsStoreLogThread *)thread_data;
int ipproto = (PKT_IS_IPV4(p)) ? AF_INET : AF_INET6;
int ipproto = (PacketIsIPv4(p)) ? AF_INET : AF_INET6;
SSLState *ssl_state = (SSLState *)state;
if (unlikely(ssl_state == NULL)) {

@ -321,12 +321,12 @@ static int EveStreamLogger(ThreadVars *tv, void *thread_data, const Packet *p)
jb_open_object(js, "stream_tcp");
jb_open_object(js, "packet");
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
jb_set_uint(js, "len", IPV4_GET_IPLEN(p));
jb_set_uint(js, "tos", IPV4_GET_IPTOS(p));
jb_set_uint(js, "ttl", IPV4_GET_IPTTL(p));
jb_set_uint(js, "ipid", IPV4_GET_IPID(p));
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
jb_set_uint(js, "len", IPV6_GET_PLEN(p));
jb_set_uint(js, "tc", IPV6_GET_CLASS(p));
jb_set_uint(js, "hoplimit", IPV6_GET_HLIM(p));

@ -764,7 +764,7 @@ static int JsonAlertLogger(ThreadVars *tv, void *thread_data, const Packet *p)
{
JsonAlertLogThread *aft = thread_data;
if (PKT_IS_IPV4(p) || PKT_IS_IPV6(p)) {
if (PacketIsIPv4(p) || PacketIsIPv6(p)) {
return AlertJson(tv, aft, p);
} else if (p->alerts.cnt > 0) {
return AlertJsonDecoderEvent(tv, aft, p);

@ -107,13 +107,13 @@ static int DropLogJSON (JsonDropLogThread *aft, const Packet *p)
jb_open_object(js, "drop");
uint16_t proto = 0;
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
jb_set_uint(js, "len", IPV4_GET_IPLEN(p));
jb_set_uint(js, "tos", IPV4_GET_IPTOS(p));
jb_set_uint(js, "ttl", IPV4_GET_IPTTL(p));
jb_set_uint(js, "ipid", IPV4_GET_IPID(p));
proto = IPV4_GET_IPPROTO(p);
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
jb_set_uint(js, "len", IPV6_GET_PLEN(p));
jb_set_uint(js, "tc", IPV6_GET_CLASS(p));
jb_set_uint(js, "hoplimit", IPV6_GET_HLIM(p));

@ -472,12 +472,12 @@ void JsonAddrInfoInit(const Packet *p, enum OutputJsonLogDirection dir, JsonAddr
switch (dir) {
case LOG_DIR_PACKET:
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
PrintInet(AF_INET, (const void *)GET_IPV4_SRC_ADDR_PTR(p),
srcip, sizeof(srcip));
PrintInet(AF_INET, (const void *)GET_IPV4_DST_ADDR_PTR(p),
dstip, sizeof(dstip));
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
PrintInet(AF_INET6, (const void *)GET_IPV6_SRC_ADDR(p),
srcip, sizeof(srcip));
PrintInet(AF_INET6, (const void *)GET_IPV6_DST_ADDR(p),
@ -492,12 +492,12 @@ void JsonAddrInfoInit(const Packet *p, enum OutputJsonLogDirection dir, JsonAddr
case LOG_DIR_FLOW:
case LOG_DIR_FLOW_TOSERVER:
if ((PKT_IS_TOSERVER(p))) {
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
PrintInet(AF_INET, (const void *)GET_IPV4_SRC_ADDR_PTR(p),
srcip, sizeof(srcip));
PrintInet(AF_INET, (const void *)GET_IPV4_DST_ADDR_PTR(p),
dstip, sizeof(dstip));
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
PrintInet(AF_INET6, (const void *)GET_IPV6_SRC_ADDR(p),
srcip, sizeof(srcip));
PrintInet(AF_INET6, (const void *)GET_IPV6_DST_ADDR(p),
@ -506,12 +506,12 @@ void JsonAddrInfoInit(const Packet *p, enum OutputJsonLogDirection dir, JsonAddr
sp = p->sp;
dp = p->dp;
} else {
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
PrintInet(AF_INET, (const void *)GET_IPV4_DST_ADDR_PTR(p),
srcip, sizeof(srcip));
PrintInet(AF_INET, (const void *)GET_IPV4_SRC_ADDR_PTR(p),
dstip, sizeof(dstip));
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
PrintInet(AF_INET6, (const void *)GET_IPV6_DST_ADDR(p),
srcip, sizeof(srcip));
PrintInet(AF_INET6, (const void *)GET_IPV6_SRC_ADDR(p),
@ -523,12 +523,12 @@ void JsonAddrInfoInit(const Packet *p, enum OutputJsonLogDirection dir, JsonAddr
break;
case LOG_DIR_FLOW_TOCLIENT:
if ((PKT_IS_TOCLIENT(p))) {
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
PrintInet(AF_INET, (const void *)GET_IPV4_SRC_ADDR_PTR(p),
srcip, sizeof(srcip));
PrintInet(AF_INET, (const void *)GET_IPV4_DST_ADDR_PTR(p),
dstip, sizeof(dstip));
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
PrintInet(AF_INET6, (const void *)GET_IPV6_SRC_ADDR(p),
srcip, sizeof(srcip));
PrintInet(AF_INET6, (const void *)GET_IPV6_DST_ADDR(p),
@ -537,12 +537,12 @@ void JsonAddrInfoInit(const Packet *p, enum OutputJsonLogDirection dir, JsonAddr
sp = p->sp;
dp = p->dp;
} else {
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
PrintInet(AF_INET, (const void *)GET_IPV4_DST_ADDR_PTR(p),
srcip, sizeof(srcip));
PrintInet(AF_INET, (const void *)GET_IPV4_SRC_ADDR_PTR(p),
dstip, sizeof(dstip));
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
PrintInet(AF_INET6, (const void *)GET_IPV6_DST_ADDR(p),
srcip, sizeof(srcip));
PrintInet(AF_INET6, (const void *)GET_IPV6_SRC_ADDR(p),

@ -175,7 +175,7 @@ static int LuaPacketLoggerAlerts(ThreadVars *tv, void *thread_data, const Packet
char timebuf[64];
CreateTimeString(p->ts, timebuf, sizeof(timebuf));
if (!(PKT_IS_IPV4(p)) && !(PKT_IS_IPV6(p))) {
if (!(PacketIsIPv4(p)) && !(PacketIsIPv6(p))) {
/* decoder event */
goto not_supported;
}
@ -237,7 +237,7 @@ static int LuaPacketLogger(ThreadVars *tv, void *thread_data, const Packet *p)
char timebuf[64];
if ((!(PKT_IS_IPV4(p))) && (!(PKT_IS_IPV6(p)))) {
if ((!(PacketIsIPv4(p))) && (!(PacketIsIPv6(p)))) {
goto not_supported;
}
@ -281,7 +281,7 @@ static int LuaFileLogger(ThreadVars *tv, void *thread_data, const Packet *p, con
SCEnter();
LogLuaThreadCtx *td = (LogLuaThreadCtx *)thread_data;
if ((!(PKT_IS_IPV4(p))) && (!(PKT_IS_IPV6(p))))
if ((!(PacketIsIPv4(p))) && (!(PacketIsIPv6(p))))
return 0;
BUG_ON(ff->flags & FILE_LOGGED);

@ -149,9 +149,9 @@ uint8_t SRepCIDRGetIPRepSrc(SRepCIDRTree *cidr_ctx, Packet *p, uint8_t cat, uint
{
uint8_t rep = 0;
if (PKT_IS_IPV4(p))
if (PacketIsIPv4(p))
rep = SRepCIDRGetIPv4IPRep(cidr_ctx, (uint8_t *)GET_IPV4_SRC_ADDR_PTR(p), cat);
else if (PKT_IS_IPV6(p))
else if (PacketIsIPv6(p))
rep = SRepCIDRGetIPv6IPRep(cidr_ctx, (uint8_t *)GET_IPV6_SRC_ADDR(p), cat);
return rep;
@ -161,9 +161,9 @@ uint8_t SRepCIDRGetIPRepDst(SRepCIDRTree *cidr_ctx, Packet *p, uint8_t cat, uint
{
uint8_t rep = 0;
if (PKT_IS_IPV4(p))
if (PacketIsIPv4(p))
rep = SRepCIDRGetIPv4IPRep(cidr_ctx, (uint8_t *)GET_IPV4_DST_ADDR_PTR(p), cat);
else if (PKT_IS_IPV6(p))
else if (PacketIsIPv6(p))
rep = SRepCIDRGetIPv6IPRep(cidr_ctx, (uint8_t *)GET_IPV6_DST_ADDR(p), cat);
return rep;

@ -73,13 +73,13 @@ static TmEcode RespondRejectFunc(ThreadVars *tv, Packet *p, void *data)
return TM_ECODE_OK;
}
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
if (PKT_IS_TCP(p)) {
(void)RejectSendIPv4TCP(tv, p, data);
} else {
(void)RejectSendIPv4ICMP(tv, p, data);
}
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
if (PKT_IS_TCP(p)) {
(void)RejectSendIPv6TCP(tv, p, data);
} else {

@ -2197,7 +2197,7 @@ static int AFPBypassCallback(Packet *p)
if (PacketIsTunnel(p)) {
return 0;
}
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
SCLogDebug("add an IPv4");
if (p->afp_v.v4_map_fd == -1) {
return 0;
@ -2254,8 +2254,7 @@ static int AFPBypassCallback(Packet *p)
return AFPSetFlowStorage(p, p->afp_v.v4_map_fd, keys[0], keys[1], AF_INET);
}
/* For IPv6 case we don't handle extended header in eBPF */
if (PKT_IS_IPV6(p) &&
((IPV6_GET_NH(p) == IPPROTO_TCP) || (IPV6_GET_NH(p) == IPPROTO_UDP))) {
if (PacketIsIPv6(p) && ((IPV6_GET_NH(p) == IPPROTO_TCP) || (IPV6_GET_NH(p) == IPPROTO_UDP))) {
int i;
if (p->afp_v.v6_map_fd == -1) {
return 0;
@ -2352,7 +2351,7 @@ static int AFPXDPBypassCallback(Packet *p)
if (PacketIsTunnel(p)) {
return 0;
}
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
struct flowv4_keys *keys[2];
keys[0]= SCCalloc(1, sizeof(struct flowv4_keys));
if (keys[0] == NULL) {
@ -2409,8 +2408,7 @@ static int AFPXDPBypassCallback(Packet *p)
return AFPSetFlowStorage(p, p->afp_v.v4_map_fd, keys[0], keys[1], AF_INET);
}
/* For IPv6 case we don't handle extended header in eBPF */
if (PKT_IS_IPV6(p) &&
((IPV6_GET_NH(p) == IPPROTO_TCP) || (IPV6_GET_NH(p) == IPPROTO_UDP))) {
if (PacketIsIPv6(p) && ((IPV6_GET_NH(p) == IPPROTO_TCP) || (IPV6_GET_NH(p) == IPPROTO_UDP))) {
SCLogDebug("add an IPv6");
if (p->afp_v.v6_map_fd == -1) {
return 0;

@ -940,7 +940,7 @@ static void StreamTcpPacketSetState(Packet *p, TcpSession *ssn,
*/
void StreamTcpSetOSPolicy(TcpStream *stream, Packet *p)
{
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
/* Get the OS policy based on destination IP address, as destination
OS will decide how to react on the anomalies of newly received
packets */
@ -950,7 +950,7 @@ void StreamTcpSetOSPolicy(TcpStream *stream, Packet *p)
else
stream->os_policy = OS_POLICY_DEFAULT;
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
/* Get the OS policy based on destination IP address, as destination
OS will decide how to react on the anomalies of newly received
packets */
@ -5679,13 +5679,13 @@ static inline int StreamTcpValidateChecksum(Packet *p)
return ret;
if (p->level4_comp_csum == -1) {
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
p->level4_comp_csum = TCPChecksum(p->ip4h->s_ip_addrs,
(uint16_t *)p->tcph,
(p->payload_len +
TCP_GET_HLEN(p)),
p->tcph->th_sum);
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
p->level4_comp_csum = TCPV6Checksum(p->ip6h->s_ip6_addrs,
(uint16_t *)p->tcph,
(p->payload_len +

@ -28,7 +28,7 @@
int ReCalculateChecksum(Packet *p)
{
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
if (PKT_IS_TCP(p)) {
/* TCP */
p->tcph->th_sum = 0;
@ -43,7 +43,7 @@ int ReCalculateChecksum(Packet *p)
p->ip4h->ip_csum = 0;
p->ip4h->ip_csum = IPV4Checksum((uint16_t *)p->ip4h,
IPV4_GET_RAW_HLEN(p->ip4h), 0);
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
/* just TCP for IPV6 */
if (PKT_IS_TCP(p)) {
p->tcph->th_sum = 0;

@ -328,9 +328,9 @@ static int LuaCallbackFlowHasAlerts(lua_State *luastate)
static int LuaCallbackTuplePushToStackFromPacket(lua_State *luastate, const Packet *p)
{
int ipver = 0;
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
ipver = 4;
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
ipver = 6;
}
lua_pushinteger(luastate, ipver);
@ -338,10 +338,10 @@ static int LuaCallbackTuplePushToStackFromPacket(lua_State *luastate, const Pack
return 1;
char srcip[46] = "", dstip[46] = "";
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
PrintInet(AF_INET, (const void *)GET_IPV4_SRC_ADDR_PTR(p), srcip, sizeof(srcip));
PrintInet(AF_INET, (const void *)GET_IPV4_DST_ADDR_PTR(p), dstip, sizeof(dstip));
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
PrintInet(AF_INET6, (const void *)GET_IPV6_SRC_ADDR(p), srcip, sizeof(srcip));
PrintInet(AF_INET6, (const void *)GET_IPV6_DST_ADDR(p), dstip, sizeof(dstip));
}

@ -893,7 +893,7 @@ static void SCProfilingUpdatePacketDetectRecords(Packet *p)
PktProfilingDetectData *pdt = &p->profile->detect[i];
if (pdt->ticks_spent > 0) {
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
SCProfilingUpdatePacketDetectRecord(i, p->proto, pdt, 4);
} else {
SCProfilingUpdatePacketDetectRecord(i, p->proto, pdt, 6);
@ -951,7 +951,7 @@ static void SCProfilingUpdatePacketAppRecords(Packet *p)
PktProfilingAppData *pdt = &p->profile->app[i];
if (pdt->ticks_spent > 0) {
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
SCProfilingUpdatePacketAppRecord(i, p->proto, pdt, 4);
} else {
SCProfilingUpdatePacketAppRecord(i, p->proto, pdt, 6);
@ -960,7 +960,7 @@ static void SCProfilingUpdatePacketAppRecords(Packet *p)
}
if (p->profile->proto_detect > 0) {
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
SCProfilingUpdatePacketAppPdRecord(p->proto, p->profile->proto_detect, 4);
} else {
SCProfilingUpdatePacketAppPdRecord(p->proto, p->profile->proto_detect, 6);
@ -1011,7 +1011,7 @@ static void SCProfilingUpdatePacketTmmRecords(Packet *p)
continue;
}
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
SCProfilingUpdatePacketTmmRecord(i, p->proto, pdt, 4);
} else {
SCProfilingUpdatePacketTmmRecord(i, p->proto, pdt, 6);
@ -1052,7 +1052,7 @@ static void SCProfilingUpdatePacketGenericRecords(Packet *p, PktProfilingData *p
struct ProfileProtoRecords *r = &records[i];
SCProfilePacketData *store = NULL;
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
store = &(r->records4[p->proto]);
} else {
store = &(r->records6[p->proto]);
@ -1092,7 +1092,7 @@ static void SCProfilingUpdatePacketLogRecords(Packet *p)
PktProfilingLoggerData *pdt = &p->profile->logger[i];
if (pdt->ticks_spent > 0) {
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
SCProfilingUpdatePacketLogRecord(i, p->proto, pdt, 4);
} else {
SCProfilingUpdatePacketLogRecord(i, p->proto, pdt, 6);
@ -1111,7 +1111,7 @@ void SCProfilingAddPacket(Packet *p)
pthread_mutex_lock(&packet_profile_lock);
{
if (PKT_IS_IPV4(p)) {
if (PacketIsIPv4(p)) {
SCProfilePacketData *pd = &packet_profile_data4[p->proto];
uint64_t delta = p->profile->ticks_end - p->profile->ticks_start;
@ -1147,7 +1147,7 @@ void SCProfilingAddPacket(Packet *p)
SCProfilingUpdatePacketDetectRecords(p);
SCProfilingUpdatePacketLogRecords(p);
} else if (PKT_IS_IPV6(p)) {
} else if (PacketIsIPv6(p)) {
SCProfilePacketData *pd = &packet_profile_data6[p->proto];
uint64_t delta = p->profile->ticks_end - p->profile->ticks_start;

Loading…
Cancel
Save