git: 88268bb664a9 - stable/12 - ipfilter userland: Revert the ipmon part of a6fb9bbea731
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 27 Dec 2021 09:26:24 UTC
The branch stable/12 has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=88268bb664a9486c8ca48f4af1fc3d95d00fdb73 commit 88268bb664a9486c8ca48f4af1fc3d95d00fdb73 Author: Cy Schubert <cy@FreeBSD.org> AuthorDate: 2021-12-27 09:10:52 +0000 Commit: Cy Schubert <cy@FreeBSD.org> CommitDate: 2021-12-27 09:22:03 +0000 ipfilter userland: Revert the ipmon part of a6fb9bbea731 a6fb9bbea731 caused incorrect formatting of ipmon log output. Fixes: a6fb9bbea7318e993dfe0f8a7f00821f79850b26 (cherry picked from commit d740faa30a4a2b300da0b2f2af4680a2cb260828) --- contrib/ipfilter/tools/ipmon.c | 124 +++++++++++++++++++-------------------- contrib/ipfilter/tools/ipmon_y.y | 2 +- 2 files changed, 61 insertions(+), 65 deletions(-) diff --git a/contrib/ipfilter/tools/ipmon.c b/contrib/ipfilter/tools/ipmon.c index 28586537da5b..9022f12b6149 100644 --- a/contrib/ipfilter/tools/ipmon.c +++ b/contrib/ipfilter/tools/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/contrib/ipfilter/tools/ipmon_y.y b/contrib/ipfilter/tools/ipmon_y.y index e734c1c8c1f1..0aeb20a32519 100644 --- a/contrib/ipfilter/tools/ipmon_y.y +++ b/contrib/ipfilter/tools/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;