From nobody Mon Dec 27 09:17:07 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id F316B1919B5B; Mon, 27 Dec 2021 09:17:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JMsW733jBz4mgP; Mon, 27 Dec 2021 09:17:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3ED231B34A; Mon, 27 Dec 2021 09:17:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1BR9H7qd037341; Mon, 27 Dec 2021 09:17:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BR9H7Lv037340; Mon, 27 Dec 2021 09:17:07 GMT (envelope-from git) Date: Mon, 27 Dec 2021 09:17:07 GMT Message-Id: <202112270917.1BR9H7Lv037340@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Cy Schubert Subject: git: d740faa30a4a - main - ipfilter userland: Revert the ipmon part of a6fb9bbea731 List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: cy X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d740faa30a4a2b300da0b2f2af4680a2cb260828 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1640596627; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Kc4SwZ8ZRhXXqAuReZr7MhJSsWxNz7CYYaKKCbGRFM0=; b=xc3qtT4vJ7wH//IB19AOFPLQq06f9py8vMXWQhLco+zwzNmtEBgyGtipiSsq0pCefwpxKb 20bnPh1dRN368/lh5fwyZT7OyMVk8TavjC+ig8vbzhS5a/MHMcPk+7fJcroiHPRDQO1oDd za2k7tmQ1REXkOY80SUCPFY6+LuMrBbk76YQEc1vKs3zWKeFlVRsiL9lYWExoFip/BCrxo 8k2sm8N5LOl4vpv9U5b4v/M13GCNRxpMOGLssn4jC6WO26YAjr6egiiSrHb/Yq+Yd4QhCV 7EGF4kWXO0HEhfbdfZpMUjRGAu+VbT0YeZi+KXbex0oadvnpUuzkFsSpnofEBg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1640596627; a=rsa-sha256; cv=none; b=fh3OQddAIt+plpmZjdUZh/WkDwNIR/u1ZCIvzvUBQXhAUW4wKY9RfB1GvdHi3Ud17EanyR Qi13vfnb0beM7JQVc2je93eihYt5FXrtH+/0r51jOJtaX7IAAwLVuWv2VThIdi7IDKBv+5 2wX35opmrOmbZAdVPssSiQohvwhVlhZIJUypsLGIjVPMtQmpzD9+S84D58AKORsiv8FtTb jOAWKPqu5GMvp+uLyCzOsSr4vKGOnJbrd+JiewkXAF3ltyq61c91tAWE0q9OQuvMRkNeIx p7EuPyoU2A0OhBu3fZCsdLubH1NCdmMzV1u0IFG7J5NU5IXqCsoibZdcEgG1fg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=d740faa30a4a2b300da0b2f2af4680a2cb260828 commit d740faa30a4a2b300da0b2f2af4680a2cb260828 Author: Cy Schubert AuthorDate: 2021-12-27 09:10:52 +0000 Commit: Cy Schubert CommitDate: 2021-12-27 09:10:52 +0000 ipfilter userland: Revert the ipmon part of a6fb9bbea731 a6fb9bbea731 caused incorrect formatting of ipmon log output. Fixes: a6fb9bbea7318e993dfe0f8a7f00821f79850b26 MFC after: immediately --- sbin/ipf/ipmon/ipmon.c | 124 +++++++++++++++++++++++------------------------ sbin/ipf/ipmon/ipmon_y.y | 2 +- 2 files changed, 61 insertions(+), 65 deletions(-) diff --git a/sbin/ipf/ipmon/ipmon.c b/sbin/ipf/ipmon/ipmon.c index 28586537da5b..9022f12b6149 100644 --- a/sbin/ipf/ipmon/ipmon.c +++ b/sbin/ipf/ipmon/ipmon.c @@ -447,7 +447,7 @@ static char *getlocalproto(p) p &= 0xff; s = protocols ? protocols[p] : NULL; if (s == NULL) { - snprintf(pnum, sizeof(pnum), "%u", p); + sprintf(pnum, "%u", p); s = pnum; } return s; @@ -483,7 +483,7 @@ char *portlocalname(res, proto, port) port = ntohs(port); port &= 0xffff; - snprintf(pname, sizeof(pname), "%u", port); + sprintf(pname, "%u", port); if (!res || (ipmonopts & IPMON_PORTNUM)) return pname; s = NULL; @@ -512,9 +512,9 @@ static char *icmpname(type, code) s = it->it_name; if (s == NULL) - snprintf(name, sizeof(name), "icmptype(%d)/", type); + sprintf(name, "icmptype(%d)/", type); else - snprintf(name, sizeof(name), "%s/", s); + sprintf(name, "%s/", s); ist = NULL; if (it != NULL && it->it_subtable != NULL) @@ -522,10 +522,8 @@ static char *icmpname(type, code) if (ist != NULL && ist->ist_name != NULL) strcat(name, ist->ist_name); - else { - int strlen_name = strlen(name); - snprintf(name + strlen_name, sizeof(name) - strlen_name, "%d", code); - } + else + sprintf(name + strlen(name), "%d", code); return name; } @@ -545,9 +543,9 @@ static char *icmpname6(type, code) s = it->it_name; if (s == NULL) - snprintf(name, sizeof(name), "icmpv6type(%d)/", type); + sprintf(name, "icmpv6type(%d)/", type); else - snprintf(name, sizeof(name), "%s/", s); + sprintf(name, "%s/", s); ist = NULL; if (it != NULL && it->it_subtable != NULL) @@ -555,10 +553,8 @@ static char *icmpname6(type, code) if (ist != NULL && ist->ist_name != NULL) strcat(name, ist->ist_name); - else { - int strlen_name = strlen(name); - snprintf(name + strlen_name, sizeof(name) - strlen_name, "%d", code); - } + else + sprintf(name + strlen(name), "%d", code); return name; } @@ -684,7 +680,7 @@ static void print_natlog(conf, buf, blen) } (void) strftime(t, len, "%T", tm); t += strlen(t); - snprintf(t, sizeof(t), ".%-.6ld @%hd ", (long)ipl->ipl_usec, nl->nl_rule + 1); + sprintf(t, ".%-.6ld @%hd ", (long)ipl->ipl_usec, nl->nl_rule + 1); t += strlen(t); switch (nl->nl_action) @@ -714,7 +710,7 @@ static void print_natlog(conf, buf, blen) break; default : - snprintf(t, sizeof(t), "NAT:Action(%d)", nl->nl_action); + sprintf(t, "NAT:Action(%d)", nl->nl_action); break; } t += strlen(t); @@ -767,7 +763,7 @@ static void print_natlog(conf, buf, blen) break; default : - snprintf(t, sizeof(t), "-Type(%d) ", nl->nl_type); + sprintf(t, "-Type(%d) ", nl->nl_type); break; } t += strlen(t); @@ -777,25 +773,25 @@ static void print_natlog(conf, buf, blen) family = vtof(nl->nl_v[0]); if (simple == 1) { - snprintf(t, sizeof(t), "%s,%s <- -> ", hostname(family, nl->nl_osrcip.i6), + sprintf(t, "%s,%s <- -> ", hostname(family, nl->nl_osrcip.i6), portlocalname(res, proto, (u_int)nl->nl_osrcport)); t += strlen(t); - snprintf(t, sizeof(t), "%s,%s ", hostname(family, nl->nl_nsrcip.i6), + sprintf(t, "%s,%s ", hostname(family, nl->nl_nsrcip.i6), portlocalname(res, proto, (u_int)nl->nl_nsrcport)); t += strlen(t); - snprintf(t, sizeof(t), "[%s,%s] ", hostname(family, nl->nl_odstip.i6), + sprintf(t, "[%s,%s] ", hostname(family, nl->nl_odstip.i6), portlocalname(res, proto, (u_int)nl->nl_odstport)); } else { - snprintf(t, sizeof(t), "%s,%s ", hostname(family, nl->nl_osrcip.i6), + sprintf(t, "%s,%s ", hostname(family, nl->nl_osrcip.i6), portlocalname(res, proto, (u_int)nl->nl_osrcport)); t += strlen(t); - snprintf(t, sizeof(t), "%s,%s <- -> ", hostname(family, nl->nl_odstip.i6), + sprintf(t, "%s,%s <- -> ", hostname(family, nl->nl_odstip.i6), portlocalname(res, proto, (u_int)nl->nl_odstport)); t += strlen(t); - snprintf(t, sizeof(t), "%s,%s ", hostname(family, nl->nl_nsrcip.i6), + sprintf(t, "%s,%s ", hostname(family, nl->nl_nsrcip.i6), portlocalname(res, proto, (u_int)nl->nl_nsrcport)); t += strlen(t); - snprintf(t, sizeof(t), "%s,%s ", hostname(family, nl->nl_ndstip.i6), + sprintf(t, "%s,%s ", hostname(family, nl->nl_ndstip.i6), portlocalname(res, proto, (u_int)nl->nl_ndstport)); } t += strlen(t); @@ -806,13 +802,13 @@ static void print_natlog(conf, buf, blen) if (nl->nl_action == NL_EXPIRE || nl->nl_action == NL_FLUSH) { #ifdef USE_QUAD_T # ifdef PRId64 - snprintf(t, sizeof(t), " Pkts %" PRId64 "/%" PRId64 " Bytes %" PRId64 "/%" + sprintf(t, " Pkts %" PRId64 "/%" PRId64 " Bytes %" PRId64 "/%" PRId64, # else - snprintf(t, sizeof(t), " Pkts %qd/%qd Bytes %qd/%qd", + sprintf(t, " Pkts %qd/%qd Bytes %qd/%qd", # endif #else - snprintf(t, sizeof(t), " Pkts %ld/%ld Bytes %ld/%ld", + sprintf(t, " Pkts %ld/%ld Bytes %ld/%ld", #endif nl->nl_pkts[0], nl->nl_pkts[1], nl->nl_bytes[0], nl->nl_bytes[1]); @@ -869,7 +865,7 @@ static void print_statelog(conf, buf, blen) } (void) strftime(t, len, "%T", tm); t += strlen(t); - snprintf(t, sizeof(t), ".%-.6ld ", (long)ipl->ipl_usec); + sprintf(t, ".%-.6ld ", (long)ipl->ipl_usec); t += strlen(t); family = vtof(sl->isl_v); @@ -914,7 +910,7 @@ static void print_statelog(conf, buf, blen) break; default : - snprintf(t, sizeof(t), "Type: %d ", sl->isl_type); + sprintf(t, "Type: %d ", sl->isl_type); break; } t += strlen(t); @@ -922,38 +918,38 @@ static void print_statelog(conf, buf, blen) proto = getlocalproto(sl->isl_p); if (sl->isl_p == IPPROTO_TCP || sl->isl_p == IPPROTO_UDP) { - snprintf(t, sizeof(t), "%s,%s -> ", + sprintf(t, "%s,%s -> ", hostname(family, (u_32_t *)&sl->isl_src), portlocalname(res, proto, (u_int)sl->isl_sport)); t += strlen(t); - snprintf(t, sizeof(t), "%s,%s PR %s", + sprintf(t, "%s,%s PR %s", hostname(family, (u_32_t *)&sl->isl_dst), portlocalname(res, proto, (u_int)sl->isl_dport), proto); } else if (sl->isl_p == IPPROTO_ICMP) { - snprintf(t, sizeof(t), "%s -> ", hostname(family, (u_32_t *)&sl->isl_src)); + sprintf(t, "%s -> ", hostname(family, (u_32_t *)&sl->isl_src)); t += strlen(t); - snprintf(t, sizeof(t), "%s PR icmp %d", + sprintf(t, "%s PR icmp %d", hostname(family, (u_32_t *)&sl->isl_dst), sl->isl_itype); } else if (sl->isl_p == IPPROTO_ICMPV6) { - snprintf(t, sizeof(t), "%s -> ", hostname(family, (u_32_t *)&sl->isl_src)); + sprintf(t, "%s -> ", hostname(family, (u_32_t *)&sl->isl_src)); t += strlen(t); - snprintf(t, sizeof(t), "%s PR icmpv6 %d", + sprintf(t, "%s PR icmpv6 %d", hostname(family, (u_32_t *)&sl->isl_dst), sl->isl_itype); } else { - snprintf(t, sizeof(t), "%s -> ", hostname(family, (u_32_t *)&sl->isl_src)); + sprintf(t, "%s -> ", hostname(family, (u_32_t *)&sl->isl_src)); t += strlen(t); - snprintf(t, sizeof(t), "%s PR %s", + sprintf(t, "%s PR %s", hostname(family, (u_32_t *)&sl->isl_dst), proto); } t += strlen(t); if (sl->isl_tag != FR_NOLOGTAG) { - snprintf(t, sizeof(t), " tag %u", sl->isl_tag); + sprintf(t, " tag %u", sl->isl_tag); t += strlen(t); } if (sl->isl_type != ISL_NEW) { - snprintf(t, sizeof(t), + sprintf(t, #ifdef USE_QUAD_T #ifdef PRId64 " Forward: Pkts in %" PRId64 " Bytes in %" PRId64 @@ -1099,10 +1095,10 @@ static void print_ipflog(conf, buf, blen) } (void) strftime(t, len, "%T", tm); t += strlen(t); - snprintf(t, sizeof(t), ".%-.6ld ", (long)ipl->ipl_usec); + sprintf(t, ".%-.6ld ", (long)ipl->ipl_usec); t += strlen(t); if (ipl->ipl_count > 1) { - snprintf(t, sizeof(t), "%dx ", ipl->ipl_count); + sprintf(t, "%dx ", ipl->ipl_count); t += strlen(t); } { @@ -1110,11 +1106,11 @@ static void print_ipflog(conf, buf, blen) strncpy(ifname, ipf->fl_ifname, sizeof(ipf->fl_ifname)); ifname[sizeof(ipf->fl_ifname)] = '\0'; - snprintf(t, sizeof(t), "%s", ifname); + sprintf(t, "%s", ifname); t += strlen(t); # if SOLARIS if (ISALPHA(*(t - 1))) { - snprintf(t, sizeof(t), "%d", ipf->fl_unit); + sprintf(t, "%d", ipf->fl_unit); t += strlen(t); } # endif @@ -1124,12 +1120,12 @@ static void print_ipflog(conf, buf, blen) else if (ipf->fl_group[0] == '\0') (void) strcpy(t, " @0:"); else - snprintf(t, sizeof(t), " @%s:", ipf->fl_group); + sprintf(t, " @%s:", ipf->fl_group); t += strlen(t); if (ipf->fl_rule == 0xffffffff) strcat(t, "-1 "); else - snprintf(t, sizeof(t), "%u ", ipf->fl_rule + 1); + sprintf(t, "%u ", ipf->fl_rule + 1); t += strlen(t); lvl = LOG_NOTICE; @@ -1216,10 +1212,10 @@ static void print_ipflog(conf, buf, blen) if ((p == IPPROTO_TCP || p == IPPROTO_UDP) && !off) { tp = (tcphdr_t *)((char *)ip + hl); if (!(ipf->fl_lflags & FI_SHORT)) { - snprintf(t, sizeof(t), "%s,%s -> ", hostname(f, s), + sprintf(t, "%s,%s -> ", hostname(f, s), portlocalname(res, proto, (u_int)tp->th_sport)); t += strlen(t); - snprintf(t, sizeof(t), "%s,%s PR %s len %hu %hu", + sprintf(t, "%s,%s PR %s len %hu %hu", hostname(f, d), portlocalname(res, proto, (u_int)tp->th_dport), proto, hl, plen); @@ -1232,7 +1228,7 @@ static void print_ipflog(conf, buf, blen) if (tp->th_flags & tcpfl[i].value) *t++ = tcpfl[i].flag; if (ipmonopts & IPMON_VERBOSE) { - snprintf(t, sizeof(t), " %lu %lu %hu", + sprintf(t, " %lu %lu %hu", (u_long)(ntohl(tp->th_seq)), (u_long)(ntohl(tp->th_ack)), ntohs(tp->th_win)); @@ -1241,7 +1237,7 @@ static void print_ipflog(conf, buf, blen) } *t = '\0'; } else { - snprintf(t, sizeof(t), "%s -> ", hostname(f, s)); + sprintf(t, "%s -> ", hostname(f, s)); t += strlen(t); sprintf(t, "%s PR %s len %hu %hu", hostname(f, d), proto, hl, plen); @@ -1249,17 +1245,17 @@ static void print_ipflog(conf, buf, blen) #if defined(AF_INET6) && defined(IPPROTO_ICMPV6) } else if ((p == IPPROTO_ICMPV6) && !off && (f == AF_INET6)) { ic = (struct icmp *)((char *)ip + hl); - snprintf(t, sizeof(t), "%s -> ", hostname(f, s)); + sprintf(t, "%s -> ", hostname(f, s)); t += strlen(t); - snprintf(t, sizeof(t), "%s PR icmpv6 len %hu %hu icmpv6 %s", + sprintf(t, "%s PR icmpv6 len %hu %hu icmpv6 %s", hostname(f, d), hl, plen, icmpname6(ic->icmp_type, ic->icmp_code)); #endif } else if ((p == IPPROTO_ICMP) && !off && (f == AF_INET)) { ic = (struct icmp *)((char *)ip + hl); - snprintf(t, sizeof(t), "%s -> ", hostname(f, s)); + sprintf(t, "%s -> ", hostname(f, s)); t += strlen(t); - snprintf(t, sizeof(t), "%s PR icmp len %hu %hu icmp %s", + sprintf(t, "%s PR icmp len %hu %hu icmp %s", hostname(f, d), hl, plen, icmpname(ic->icmp_type, ic->icmp_code)); if (ic->icmp_type == ICMP_UNREACH || @@ -1283,12 +1279,12 @@ static void print_ipflog(conf, buf, blen) (ipc->ip_p == IPPROTO_UDP))) { tp = (tcphdr_t *)((char *)ipc + hl); t += strlen(t); - snprintf(t, sizeof(t), " for %s,%s -", + sprintf(t, " for %s,%s -", HOSTNAMEV4(ipc->ip_src), portlocalname(res, proto, (u_int)tp->th_sport)); t += strlen(t); - snprintf(t, sizeof(t), " %s,%s PR %s len %hu %hu", + sprintf(t, " %s,%s PR %s len %hu %hu", HOSTNAMEV4(ipc->ip_dst), portlocalname(res, proto, (u_int)tp->th_dport), @@ -1298,25 +1294,25 @@ static void print_ipflog(conf, buf, blen) icmp = (icmphdr_t *)((char *)ipc + hl); t += strlen(t); - snprintf(t, sizeof(t), " for %s -", + sprintf(t, " for %s -", HOSTNAMEV4(ipc->ip_src)); t += strlen(t); - snprintf(t, sizeof(t), + sprintf(t, " %s PR icmp len %hu %hu icmp %d/%d", HOSTNAMEV4(ipc->ip_dst), IP_HL(ipc) << 2, i, icmp->icmp_type, icmp->icmp_code); } else { t += strlen(t); - snprintf(t, sizeof(t), " for %s -", + sprintf(t, " for %s -", HOSTNAMEV4(ipc->ip_src)); t += strlen(t); - snprintf(t, sizeof(t), " %s PR %s len %hu (%hu)", + sprintf(t, " %s PR %s len %hu (%hu)", HOSTNAMEV4(ipc->ip_dst), proto, IP_HL(ipc) << 2, i); t += strlen(t); if (ipoff & IP_OFFMASK) { - snprintf(t, sizeof(t), "(frag %d:%hu@%hu%s%s)", + sprintf(t, "(frag %d:%hu@%hu%s%s)", ntohs(ipc->ip_id), i - (IP_HL(ipc) << 2), (ipoff & IP_OFFMASK) << 3, @@ -1327,13 +1323,13 @@ static void print_ipflog(conf, buf, blen) } } else { - snprintf(t, sizeof(t), "%s -> ", hostname(f, s)); + sprintf(t, "%s -> ", hostname(f, s)); t += strlen(t); - snprintf(t, sizeof(t), "%s PR %s len %hu (%hu)", + sprintf(t, "%s PR %s len %hu (%hu)", hostname(f, d), proto, hl, plen); t += strlen(t); if (off & IP_OFFMASK) - snprintf(t, sizeof(t), " (frag %d:%hu@%hu%s%s)", + sprintf(t, " (frag %d:%hu@%hu%s%s)", ntohs(ip->ip_id), plen - hl, (off & IP_OFFMASK) << 3, ipoff & IP_MF ? "+" : "", @@ -1358,7 +1354,7 @@ printipflog: strcpy(t, " OUT"); t += strlen(t); if (ipf->fl_logtag != 0) { - snprintf(t, sizeof(t), " log-tag %d", ipf->fl_logtag); + sprintf(t, " log-tag %d", ipf->fl_logtag); t += strlen(t); } if (ipf->fl_nattag.ipt_num[0] != 0) { diff --git a/sbin/ipf/ipmon/ipmon_y.y b/sbin/ipf/ipmon/ipmon_y.y index e734c1c8c1f1..0aeb20a32519 100644 --- a/sbin/ipf/ipmon/ipmon_y.y +++ b/sbin/ipf/ipmon/ipmon_y.y @@ -368,7 +368,7 @@ build_action(olist, todo) if (o->o_str != NULL) strncpy(a->ac_group, o->o_str, FR_GROUPLEN); else - snprintf(a->ac_group, FR_GROUPLEN, "%d", o->o_num); + sprintf(a->ac_group, "%d", o->o_num); break; case IPM_LOGTAG : a->ac_logtag = o->o_num;