]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #2773 in SNORT/snort3 from ~MIALTIZE/snort3:textlog_format to...
authorMichael Altizer (mialtize) <mialtize@cisco.com>
Wed, 3 Mar 2021 22:20:58 +0000 (22:20 +0000)
committerMichael Altizer (mialtize) <mialtize@cisco.com>
Wed, 3 Mar 2021 22:20:58 +0000 (22:20 +0000)
Squashed commit of the following:

commit cc15aa3048a4006dcede48ae2c74292f1185ef44
Author: Michael Altizer <mialtize@cisco.com>
Date:   Tue Mar 2 13:03:42 2021 -0500

    log: Add printf format attribute to TextLog_Print() and clean up the fallout

14 files changed:
src/codecs/ip/cd_frag.cc
src/codecs/ip/cd_gre.cc
src/codecs/ip/cd_icmp6.cc
src/codecs/ip/cd_ipv4.cc
src/codecs/ip/cd_ipv6.cc
src/codecs/misc/cd_icmp4_ip.cc
src/codecs/misc/cd_llc.cc
src/codecs/root/cd_eth.cc
src/file_api/file_log.cc
src/log/log_text.cc
src/log/text_log.h
src/loggers/alert_csv.cc
src/loggers/alert_json.cc
src/loggers/log_hext.cc

index 2c903f06a09e346bd14e083e93da3f4b1628ba9c..4bfeb0b1cc325e220e1a2b85410f15031c33290d 100644 (file)
@@ -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<uint8_t>(fragh->ip6f_nxt), offlg, fragh->id());
 
     if (fragh->mf())
         TextLog_Puts(text_log, " MF");
index 9af9a1159b4feb9690803448a4022c693f938a83..a6e24f22d07cbad9e43413907dcf88ebb667e0c4 100644 (file)
@@ -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<uint16_t>(greh->proto()));
 }
 
 //-------------------------------------------------------------------------
index 27f2f37ef1041fd76d49c675724a8bc754e3201b..9775f48f72d79b3dc991fbecb8df22bff5b3c0b5 100644 (file)
@@ -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<const icmp::Icmp6Hdr*>(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<uint8_t>(icmph->code));
 }
 
 /******************************************************************
index 3d63e9ac4627302ccf3cecac2e4d0f07e8a985a8..2d69f470cf446626708ac403a10e907817a67e7b 100644 (file)
@@ -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<uint8_t>(ip4h->proto()), ip4h->ttl(), ip4h->tos(),
         ip4h->id(), hlen, len);
 
     /* print the reserved bit if it's set */
index 90950b0f6dbb32964a6a16d5f17fc9d63e1dd8ae..4c4fc73f993bd501a6ba5c942f29f98679e92323 100644 (file)
@@ -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<uint8_t>(ip6h->next()), ip6h->hop_lim(), ip6h->tos(),
         ip6h->len());
 }
 
index e3c666dccd0951980aa128256554b292d173a6db..eb585a3b28345f658413167f795c76bc43962819 100644 (file)
@@ -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<uint8_t>(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<uint8_t>(ip4h->proto()));
         break;
     }
     }
index c83c22b4c12802c9331b15d656146424cfb83cc0..e4863271a06033000f50def158da4c5c9059f82c 100644 (file)
@@ -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<uint16_t>(proto));
     }
 }
 
index b85ac22036571d1c1a3af9f55e9cc0802e68e18e..b998654d880fed5c9dcc776f95ec882442aca28c 100644 (file)
@@ -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<uint16_t>(prot_id));
     else
-        TextLog_Print(text_log, "  type:0x%04X", prot_id);
+        TextLog_Print(text_log, "  type:0x%04X", static_cast<uint16_t>(prot_id));
 }
 
 //-------------------------------------------------------------------------
index 333931541e7393f183f9775c89cdf24e948674f2..9fe5cf1dfa26b2575ce017d276cd52753feb0564 100644 (file)
@@ -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");
 
index 546db57c1737ebb34f03eba9640eb37f3ec437d8..f11659830212cabea901b4150e9f58b4aa3bc4e4 100644 (file)
@@ -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<uint16_t>(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<uint8_t>(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<uint8_t>(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<uint8_t>(orig->ptrs.ip_api.proto()));
             break;
         }
         } /* switch */
index bcf867160d42de30abbc241f44530cebe5ce9919..d18aad4e0a7753ecd96b6ecaa436d9aea222c499 100644 (file)
@@ -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);
index 099d8d170cb692f6f802d83f4a4210c6db86008a..1fbd519a67a60d2f784f2049839ae90632e20c1b 100644 (file)
@@ -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)
index 53bed17dd8327e2c8da0a8ef70cecfd129e95c12..1f76b13b99abe76c01842375cf096ed17565b776 100644 (file)
@@ -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;
 }
 
index 0513261772de63fc7a04e105ac9a223879705d30..abaa81feae1dcc5c15dceb6ed7ebc713a98d86cf 100644 (file)
@@ -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,