From: Michael Altizer (mialtize) Date: Wed, 3 Mar 2021 22:20:58 +0000 (+0000) Subject: Merge pull request #2773 in SNORT/snort3 from ~MIALTIZE/snort3:textlog_format to... X-Git-Tag: 3.1.2.0~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d532840a13c6b59415e9443e812f212f889781f4;p=thirdparty%2Fsnort3.git Merge pull request #2773 in SNORT/snort3 from ~MIALTIZE/snort3:textlog_format to master Squashed commit of the following: commit cc15aa3048a4006dcede48ae2c74292f1185ef44 Author: Michael Altizer Date: Tue Mar 2 13:03:42 2021 -0500 log: Add printf format attribute to TextLog_Print() and clean up the fallout --- diff --git a/src/codecs/ip/cd_frag.cc b/src/codecs/ip/cd_frag.cc index 2c903f06a..4bfeb0b1c 100644 --- a/src/codecs/ip/cd_frag.cc +++ b/src/codecs/ip/cd_frag.cc @@ -137,7 +137,7 @@ void Ipv6FragCodec::log(TextLog* const text_log, const uint8_t* raw_pkt, const uint16_t offlg = fragh->off(); TextLog_Print(text_log, "Next:0x%02X Off:%u ID:%u", - fragh->ip6f_nxt, offlg, fragh->id()); + static_cast(fragh->ip6f_nxt), offlg, fragh->id()); if (fragh->mf()) TextLog_Puts(text_log, " MF"); diff --git a/src/codecs/ip/cd_gre.cc b/src/codecs/ip/cd_gre.cc index 9af9a1159..a6e24f22d 100644 --- a/src/codecs/ip/cd_gre.cc +++ b/src/codecs/ip/cd_gre.cc @@ -285,7 +285,7 @@ void GreCodec::log(TextLog* const text_log, const uint8_t* raw_pkt, TextLog_Print(text_log, "version:%u flags:0x%02X ethertype:(0x%04X)", greh->get_version(), greh->flags, - greh->proto()); + static_cast(greh->proto())); } //------------------------------------------------------------------------- diff --git a/src/codecs/ip/cd_icmp6.cc b/src/codecs/ip/cd_icmp6.cc index 27f2f37ef..9775f48f7 100644 --- a/src/codecs/ip/cd_icmp6.cc +++ b/src/codecs/ip/cd_icmp6.cc @@ -336,7 +336,7 @@ void Icmp6Codec::log(TextLog* const text_log, const uint8_t* raw_pkt, const uint16_t /*lyr_len*/) { const icmp::Icmp6Hdr* const icmph = reinterpret_cast(raw_pkt); - TextLog_Print(text_log, "sType:%d Code:%d ", icmph->type, icmph->code); + TextLog_Print(text_log, "sType:%d Code:%d ", icmph->type, static_cast(icmph->code)); } /****************************************************************** diff --git a/src/codecs/ip/cd_ipv4.cc b/src/codecs/ip/cd_ipv4.cc index 3d63e9ac4..2d69f470c 100644 --- a/src/codecs/ip/cd_ipv4.cc +++ b/src/codecs/ip/cd_ipv4.cc @@ -590,7 +590,7 @@ void Ipv4Codec::log(TextLog* const text_log, const uint8_t* raw_pkt, const uint1 bool mf_set = false; TextLog_Print(text_log, "Next:0x%02X TTL:%u TOS:0x%X ID:%u IpLen:%u DgmLen:%u", - ip4h->proto(), ip4h->ttl(), ip4h->tos(), + static_cast(ip4h->proto()), ip4h->ttl(), ip4h->tos(), ip4h->id(), hlen, len); /* print the reserved bit if it's set */ diff --git a/src/codecs/ip/cd_ipv6.cc b/src/codecs/ip/cd_ipv6.cc index 90950b0f6..4c4fc73f9 100644 --- a/src/codecs/ip/cd_ipv6.cc +++ b/src/codecs/ip/cd_ipv6.cc @@ -564,7 +564,7 @@ void Ipv6Codec::log(TextLog* const text_log, const uint8_t* raw_pkt, TextLog_Putc(text_log, '\t'); TextLog_Print(text_log, "Next:0x%02X TTL:%u TOS:0x%X DgmLen:%u", - ip6h->next(), ip6h->hop_lim(), ip6h->tos(), + static_cast(ip6h->next()), ip6h->hop_lim(), ip6h->tos(), ip6h->len()); } diff --git a/src/codecs/misc/cd_icmp4_ip.cc b/src/codecs/misc/cd_icmp4_ip.cc index e3c666dcc..eb585a3b2 100644 --- a/src/codecs/misc/cd_icmp4_ip.cc +++ b/src/codecs/misc/cd_icmp4_ip.cc @@ -177,7 +177,7 @@ void Icmp4IpCodec::log(TextLog* const text_log, const uint8_t* raw_pkt, TextLog_Print(text_log, "Next:%s(%02X) TTL:%u TOS:0x%X ID:%u IpLen:%u DgmLen:%u", PacketManager::get_proto_name(ip4h->proto()), - ip4h->proto(), ip4h->ttl(), ip4h->tos(), + static_cast(ip4h->proto()), ip4h->ttl(), ip4h->tos(), ip4h->id(), hlen, len); /* print the reserved bit if it's set */ @@ -295,7 +295,7 @@ void Icmp4IpCodec::log(TextLog* const text_log, const uint8_t* raw_pkt, { TextLog_Print(text_log, "Protocol:%s(%02X)", PacketManager::get_proto_name(ip4h->proto()), - ip4h->proto()); + static_cast(ip4h->proto())); break; } } diff --git a/src/codecs/misc/cd_llc.cc b/src/codecs/misc/cd_llc.cc index c83c22b4c..e4863271a 100644 --- a/src/codecs/misc/cd_llc.cc +++ b/src/codecs/misc/cd_llc.cc @@ -150,7 +150,7 @@ void LlcCodec::log(TextLog* const text_log, const uint8_t* raw_pkt, TextLog_Print(text_log, " ORG:0x%02X%02X%02X PROTO:0x%04X", other->org_code[0], other->org_code[1], other->org_code[2], - proto); + static_cast(proto)); } } diff --git a/src/codecs/root/cd_eth.cc b/src/codecs/root/cd_eth.cc index b85ac2203..b998654d8 100644 --- a/src/codecs/root/cd_eth.cc +++ b/src/codecs/root/cd_eth.cc @@ -138,9 +138,9 @@ void EthCodec::log(TextLog* const text_log, const uint8_t* raw_pkt, const ProtocolId prot_id = eh->ethertype(); if (to_utype(prot_id) <= to_utype(ProtocolId::ETHERTYPE_MINIMUM)) - TextLog_Print(text_log, " len:0x%04X", prot_id); + TextLog_Print(text_log, " len:0x%04X", static_cast(prot_id)); else - TextLog_Print(text_log, " type:0x%04X", prot_id); + TextLog_Print(text_log, " type:0x%04X", static_cast(prot_id)); } //------------------------------------------------------------------------- diff --git a/src/file_api/file_log.cc b/src/file_api/file_log.cc index 333931541..9fe5cf1df 100644 --- a/src/file_api/file_log.cc +++ b/src/file_api/file_log.cc @@ -190,7 +190,7 @@ void LogHandler::handle(DataEvent&, Flow* f) uint64_t fsize = file->get_file_size(); if ( fsize > 0) - TextLog_Print(tlog, "[Size: %lu] ", fsize); + TextLog_Print(tlog, "[Size: %" PRIu64 "] ", fsize); TextLog_Print(tlog, "\n"); diff --git a/src/log/log_text.cc b/src/log/log_text.cc index 546db57c1..f11659830 100644 --- a/src/log/log_text.cc +++ b/src/log/log_text.cc @@ -137,7 +137,7 @@ static void LogGREHeader(TextLog* log, Packet* p) return; TextLog_Print(log, "GRE version:%u flags:0x%02X ether-type:0x%04X\n", - greh->get_version(), greh->flags, greh->proto()); + greh->get_version(), greh->flags, static_cast(greh->proto())); } /*-------------------------------------------------------------------- @@ -225,7 +225,7 @@ static void LogIpOptions(TextLog* log, const ip::IpOptionIterator& options) default: // the only cases where op.len is invalid were handled aboved // op.len includes code and length bytes but data does not - TextLog_Print(log, "Type %u, Len %u", op.code, op.len); + TextLog_Print(log, "Type %u, Len %u", static_cast(op.code), op.len); if ( op.len <= 2 ) break; @@ -538,7 +538,7 @@ static void LogTcpOptions(TextLog* log, const tcp::TcpOptIterator& opt_iter) break; default: - TextLog_Print(log, " Kind %u, Len %u", opt.code, opt.len); + TextLog_Print(log, " Kind %u, Len %u", static_cast(opt.code), opt.len); if ( opt.len <= 2 ) break; @@ -756,7 +756,7 @@ static void LogICMPEmbeddedIP(TextLog* log, Packet* p) LogIPHeader(log, orig); TextLog_Print(log, "Protocol: 0x%X (unknown or " - "header truncated)", orig->ptrs.ip_api.proto()); + "header truncated)", static_cast(orig->ptrs.ip_api.proto())); break; } } /* switch */ diff --git a/src/log/text_log.h b/src/log/text_log.h index bcf867160..d18aad4e0 100644 --- a/src/log/text_log.h +++ b/src/log/text_log.h @@ -55,7 +55,7 @@ SO_PUBLIC void TextLog_Term(TextLog*); SO_PUBLIC bool TextLog_Putc(TextLog* const, char); SO_PUBLIC bool TextLog_Quote(TextLog* const, const char*); SO_PUBLIC bool TextLog_Write(TextLog* const, const char*, int len); -SO_PUBLIC bool TextLog_Print(TextLog* const, const char* format, ...); +SO_PUBLIC bool TextLog_Print(TextLog* const, const char* format, ...) __attribute__((format (printf, 2, 3))); SO_PUBLIC bool TextLog_Flush(TextLog* const); SO_PUBLIC int TextLog_Avail(TextLog* const); diff --git a/src/loggers/alert_csv.cc b/src/loggers/alert_csv.cc index 099d8d170..1fbd519a6 100644 --- a/src/loggers/alert_csv.cc +++ b/src/loggers/alert_csv.cc @@ -207,7 +207,7 @@ static void ff_eth_type(const Args& a) static void ff_flowstart_time(const Args& a) { if (a.pkt->flow) - TextLog_Print(csv_log, "%lu", a.pkt->flow->flowstats.start_time.tv_sec); + TextLog_Print(csv_log, "%ld", a.pkt->flow->flowstats.start_time.tv_sec); } static void ff_gid(const Args& a) @@ -318,7 +318,7 @@ static void ff_rule(const Args& a) static void ff_seconds(const Args& a) { - TextLog_Print(csv_log, "%lu", a.pkt->pkth->ts.tv_sec); + TextLog_Print(csv_log, "%ld", a.pkt->pkth->ts.tv_sec); } static void ff_server_bytes(const Args& a) diff --git a/src/loggers/alert_json.cc b/src/loggers/alert_json.cc index 53bed17dd..1f76b13b9 100644 --- a/src/loggers/alert_json.cc +++ b/src/loggers/alert_json.cc @@ -262,7 +262,7 @@ static bool ff_flowstart_time(const Args& a) if (a.pkt->flow) { print_label(a, "flowstart_time"); - TextLog_Print(json_log, "%lu", a.pkt->flow->flowstats.start_time.tv_sec); + TextLog_Print(json_log, "%ld", a.pkt->flow->flowstats.start_time.tv_sec); return true; } return false; @@ -433,7 +433,7 @@ static bool ff_rule(const Args& a) static bool ff_seconds(const Args& a) { print_label(a, "seconds"); - TextLog_Print(json_log, "%lu", a.pkt->pkth->ts.tv_sec); + TextLog_Print(json_log, "%ld", a.pkt->pkth->ts.tv_sec); return true; } diff --git a/src/loggers/log_hext.cc b/src/loggers/log_hext.cc index 051326177..abaa81fea 100644 --- a/src/loggers/log_hext.cc +++ b/src/loggers/log_hext.cc @@ -79,10 +79,32 @@ void DaqMessageEventHandler::handle(DataEvent& event, Flow*) src.ntop(shost, sizeof(shost)); dst.ntop(dhost, sizeof(dhost)); - int vlan_tag = fs->vlan_tag == 0xfff ? 0 : fs->vlan_tag; + uint16_t vlan_tag = (fs->vlan_tag == 0xfff) ? 0 : fs->vlan_tag; TextLog_Print(hext_log, - "\n$%s %hd %hd %d %d %s %d %s %d %u %lu %lu %lu %lu %lu %lu %d %lu %lu %d %hd %d\n", + "\n$%s " // type (sof or eof) + "%hd " // ingressGroup + "%hd " // egressGroup + "%d " // ingressIntf + "%d " // egressIntf + "%s " // initiatorIp (stringified) + "%d " // initiatorPort (host order) + "%s " // responderIp (stringified) + "%d " // responderPort (host order) + "%u " // opaque + "%" PRIu64 " " // initiatorPkts + "%" PRIu64 " " // responderPkts + "%" PRIu64 " " // initiatorPktsDropped + "%" PRIu64 " " // responderPktsDropped + "%" PRIu64 " " // initiatorBytesDropped + "%" PRIu64 " " // responderBytesDropped + "%hhu " // isQoSAppliedOnSrcIntf + "%ld " // sof_timestamp.tv_sec + "%ld " // eof_timestamp.tv_sec + "%hu " // vlan_tag + "%hu " // address_space_id + "%hhu" // protocol + "\n", cmd, fs->ingressGroup, fs->egressGroup,