summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorDavid Gwynne <dlg@cvs.openbsd.org>2024-11-26 10:42:59 +0000
committerDavid Gwynne <dlg@cvs.openbsd.org>2024-11-26 10:42:59 +0000
commitf2e47d4004943f3f50662aa805fc155c34d9b90d (patch)
tree723caff5b8373948e3a3ba83521bc8a21f880c0b /sys
parent01b8ed6aa673709aaaa6fa4820957bd172cc8e1e (diff)
let bpf pick the first attached dlt when attaching to an interface.
this is instead of picking the lowest numbered dlt, which was done to make bpf more predictable with interfaces that attached multiple DLTs. i think the real problem was that bpf would keep the list in the reverse order of attachment and would prefer the last dlt. interfaces that attach multiple DLTs attach ethernet first, which is what you want the majority of the time anyway. but letting bpf pick the first one means drivers can control which dlt they want to default to, regardless of the numeric id behind a dlt. ok claudio@
Diffstat (limited to 'sys')
-rw-r--r--sys/net/bpf.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/sys/net/bpf.c b/sys/net/bpf.c
index 1496b2a8d4f..d3015e70118 100644
--- a/sys/net/bpf.c
+++ b/sys/net/bpf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bpf.c,v 1.227 2024/11/19 23:26:35 dlg Exp $ */
+/* $OpenBSD: bpf.c,v 1.228 2024/11/26 10:42:58 dlg Exp $ */
/* $NetBSD: bpf.c,v 1.33 1997/02/21 23:59:35 thorpej Exp $ */
/*
@@ -1180,22 +1180,19 @@ bpf_setf(struct bpf_d *d, struct bpf_program *fp, u_long cmd)
int
bpf_setif(struct bpf_d *d, struct ifreq *ifr)
{
- struct bpf_if *bp, *candidate = NULL;
+ struct bpf_if *bp;
int error = 0;
/*
* Look through attached interfaces for the named one.
*/
TAILQ_FOREACH(bp, &bpf_iflist, bif_next) {
- if (strcmp(bp->bif_name, ifr->ifr_name) != 0)
- continue;
-
- if (candidate == NULL || candidate->bif_dlt > bp->bif_dlt)
- candidate = bp;
+ if (strcmp(bp->bif_name, ifr->ifr_name) == 0)
+ break;
}
/* Not found. */
- if (candidate == NULL)
+ if (bp == NULL)
return (ENXIO);
/*
@@ -1208,12 +1205,12 @@ bpf_setif(struct bpf_d *d, struct ifreq *ifr)
if ((error = bpf_allocbufs(d)))
goto out;
}
- if (candidate != d->bd_bif) {
+ if (bp != d->bd_bif) {
/*
* Detach if attached to something else.
*/
bpf_detachd(d);
- bpf_attachd(d, candidate);
+ bpf_attachd(d, bp);
}
bpf_resetd(d);
out: