From: sashan Date: Mon, 21 Nov 2022 07:27:10 +0000 (+0000) Subject: Fix DIOCIGETIFACES ioctl so all network interfaces X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=edd74edc674adc995f726ebfa0b3a14395d91255;p=openbsd Fix DIOCIGETIFACES ioctl so all network interfaces and interface groups are reported. The bug allowed to enumerate the first 64 interfaces only. The issue has been noticed and bug kindly reported by Olivier Croquin. OK kn@ --- diff --git a/sbin/pfctl/pfctl_table.c b/sbin/pfctl/pfctl_table.c index 5c0c32e5961..a7ff5533964 100644 --- a/sbin/pfctl/pfctl_table.c +++ b/sbin/pfctl/pfctl_table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfctl_table.c,v 1.84 2020/01/15 22:38:31 kn Exp $ */ +/* $OpenBSD: pfctl_table.c,v 1.85 2022/11/21 07:27:10 sashan Exp $ */ /* * Copyright (c) 2002 Cedric Berger @@ -583,18 +583,16 @@ pfctl_show_ifaces(const char *filter, int opts) { struct pfr_buffer b; struct pfi_kif *p; - int i = 0; bzero(&b, sizeof(b)); b.pfrb_type = PFRB_IFACES; for (;;) { - pfr_buf_grow(&b, b.pfrb_size); + pfr_buf_grow(&b, 0); b.pfrb_size = b.pfrb_msize; if (pfi_get_ifaces(filter, b.pfrb_caddr, &b.pfrb_size)) errx(1, "%s", pf_strerror(errno)); - if (b.pfrb_size <= b.pfrb_msize) + if (b.pfrb_size < b.pfrb_msize) break; - i++; } if (opts & PF_OPT_SHOWALL) pfctl_print_title("INTERFACES:"); diff --git a/sys/net/pf_if.c b/sys/net/pf_if.c index e23c14e6769..0ed3edccb35 100644 --- a/sys/net/pf_if.c +++ b/sys/net/pf_if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pf_if.c,v 1.106 2022/06/26 11:37:08 mbuhl Exp $ */ +/* $OpenBSD: pf_if.c,v 1.107 2022/11/21 07:27:10 sashan Exp $ */ /* * Copyright 2005 Henning Brauer @@ -766,12 +766,12 @@ pfi_get_ifaces(const char *name, struct pfi_kif *buf, int *size) nextp = RB_NEXT(pfi_ifhead, &pfi_ifs, p); if (pfi_skip_if(name, p)) continue; - if (*size > n++) { - if (!p->pfik_tzero) - p->pfik_tzero = gettime(); - memcpy(buf++, p, sizeof(*buf)); - nextp = RB_NEXT(pfi_ifhead, &pfi_ifs, p); - } + if (*size <= ++n) + break; + if (!p->pfik_tzero) + p->pfik_tzero = gettime(); + memcpy(buf++, p, sizeof(*buf)); + nextp = RB_NEXT(pfi_ifhead, &pfi_ifs, p); } *size = n; }