Page MenuHomeFreeBSD

D53873.diff
No OneTemporary

D53873.diff

diff --git a/share/man/man4/bpf.4 b/share/man/man4/bpf.4
--- a/share/man/man4/bpf.4
+++ b/share/man/man4/bpf.4
@@ -47,7 +47,7 @@
.\" This document is derived in part from the enet man page (enet.4)
.\" distributed with 4.3BSD Unix.
.\"
-.Dd October 13, 2021
+.Dd November 19, 2025
.Dt BPF 4
.Os
.Sh NAME
@@ -276,6 +276,31 @@
.Xr ioctl 2
should be a pointer to the type indicated.
.Bl -tag -width BIOCGETBUFMODE
+.It Dv BIOCGETIFLIST
+.Pq Li "struct bpf_iflist"
+Returns list of available tapping points, that can later be attached
+to with
+.Dv BIOCSETIF .
+On entry the
+.Vt bi_ubuf
+shall point to user supplied buffer.
+The
+.Vt bi_size
+shall specify length of the buffer, or 0 if the request is used
+to determine the required length.
+The
+.Vt bi_count
+can be used to limit the output to first
+.Va count
+entries, otherwise shall be 0.
+On return, if the buffer length was enough to accomodate all desired entries,
+then the supplied buffer is filled with NUL-terminated names of
+available tapping points and
+.Vt bi_count
+is set to the number of copied names.
+Otherwise
+.Er ENOSPC
+is returned.
.It Dv BIOCGBLEN
.Pq Li u_int
Returns the required buffer length for reads on
diff --git a/sys/net/bpf.h b/sys/net/bpf.h
--- a/sys/net/bpf.h
+++ b/sys/net/bpf.h
@@ -118,6 +118,15 @@
size_t bz_buflen; /* Size of zero-copy buffers. */
};
+/*
+ * Struct used by BIOCGETIFLIST.
+ */
+struct bpf_iflist {
+ u_int bi_size;
+ u_int bi_count;
+ void *bi_ubuf;
+};
+
#define BIOCGBLEN _IOR('B', 102, u_int)
#define BIOCSBLEN _IOWR('B', 102, u_int)
#define BIOCSETF _IOW('B', 103, struct bpf_program)
@@ -151,6 +160,7 @@
#define BIOCGTSTAMP _IOR('B', 131, u_int)
#define BIOCSTSTAMP _IOW('B', 132, u_int)
#define BIOCSETVLANPCP _IOW('B', 133, u_int)
+#define BIOCGETIFLIST _IOWR('B', 134, struct bpf_iflist)
/* Obsolete */
#define BIOCGSEESENT BIOCGDIRECTION
diff --git a/sys/net/bpf.c b/sys/net/bpf.c
--- a/sys/net/bpf.c
+++ b/sys/net/bpf.c
@@ -209,8 +209,7 @@
* structures registered by different layers in the stack (i.e., 802.11
* frames, ethernet frames, etc).
*/
-LIST_HEAD(bpf_iflist, bpf_if);
-static struct bpf_iflist bpf_iflist = LIST_HEAD_INITIALIZER();
+static LIST_HEAD(, bpf_if) bpf_iflist = LIST_HEAD_INITIALIZER();
static struct sx bpf_sx; /* bpf global lock */
static void bpfif_ref(struct bpf_if *);
@@ -228,6 +227,7 @@
void (*)(struct bpf_d *, caddr_t, u_int, void *, u_int),
struct bintime *);
static void reset_d(struct bpf_d *);
+static int bpf_getiflist(struct bpf_iflist *);
static int bpf_setf(struct bpf_d *, struct bpf_program *, u_long cmd);
static int bpf_getdltlist(struct bpf_d *, struct bpf_dltlist *);
static int bpf_setdlt(struct bpf_d *, u_int);
@@ -1089,6 +1089,7 @@
/*
* FIONREAD Check for read packet available.
+ * BIOCGETIFLIST Get list of all tap points.
* BIOCGBLEN Get buffer len [for read()].
* BIOCSETF Set read filter.
* BIOCSETFNR Set read filter without resetting descriptor.
@@ -1142,6 +1143,7 @@
if (d->bd_flags & BPFD_LOCKED) {
switch (cmd) {
+ case BIOCGETIFLIST:
case BIOCGBLEN:
case BIOCFLUSH:
case BIOCGDLT:
@@ -1219,6 +1221,12 @@
*(int *)addr = n;
break;
}
+ /*
+ * Get list of all tap points.
+ */
+ case BIOCGETIFLIST:
+ error = bpf_getiflist((struct bpf_iflist *)addr);
+ break;
/*
* Get buffer len [for read()].
@@ -1695,6 +1703,59 @@
return (error);
}
+/*
+ * Return list of available tapping points, or report how much space is
+ * required for a successful return.
+ */
+static int
+bpf_getiflist(struct bpf_iflist *bi)
+{
+ struct bpf_if *bp;
+ u_int allsize, size, cnt;
+ char *uaddr;
+
+ BPF_LOCK();
+
+ cnt = allsize = size = 0;
+ LIST_FOREACH(bp, &bpf_iflist, bif_next) {
+ allsize += strlen(bp->bif_name) + 1;
+ if (++cnt == bi->bi_count)
+ size = allsize;
+ }
+ if (size == 0)
+ size = allsize;
+
+ if (bi->bi_size == 0) {
+ BPF_UNLOCK();
+ bi->bi_size = size;
+ bi->bi_count = cnt;
+ return (0);
+ } else if (bi->bi_size < size) {
+ BPF_UNLOCK();
+ return (ENOSPC);
+ }
+
+ uaddr = bi->bi_ubuf;
+ cnt = 0;
+ LIST_FOREACH(bp, &bpf_iflist, bif_next) {
+ u_int len;
+ int error;
+
+ len = strlen(bp->bif_name) + 1;
+ if ((error = copyout(bp->bif_name, uaddr, len)) != 0) {
+ BPF_UNLOCK();
+ return (error);
+ }
+ if (++cnt == bi->bi_count)
+ break;
+ uaddr += len;
+ }
+ BPF_UNLOCK();
+ bi->bi_count = cnt;
+
+ return (0);
+}
+
/*
* Set d's packet filter program to fp. If this file already has a filter,
* free it and replace it. Returns EINVAL for bogus requests.
diff --git a/sys/sys/param.h b/sys/sys/param.h
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -74,7 +74,7 @@
* cannot include sys/param.h and should only be updated here.
*/
#undef __FreeBSD_version
-#define __FreeBSD_version 1600004
+#define __FreeBSD_version 1600005
/*
* __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 23, 12:47 AM (6 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
25998243
Default Alt Text
D53873.diff (4 KB)

Event Timeline