From bc5b690c37af1b5be2e0be9893cc0869c8668c19 Mon Sep 17 00:00:00 2001 From: Claudio Jeker Date: Sun, 12 Sep 2004 09:35:51 +0000 Subject: Return the most common data link type instead of the first match for an interface. Where the most common DLT is the one with the smallest id. This fixes tcpdump for atw(4) that attaches multiple bpf hooks. Tested: millert@, Sigfred Haversen, otto@, mcbride@, sturm@, krw@, Steve Shockley OK millert@ deraadt@ --- sys/net/bpf.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'sys/net') diff --git a/sys/net/bpf.c b/sys/net/bpf.c index 82406c22ab6..d51e491f3ed 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bpf.c,v 1.51 2004/06/22 04:58:27 canacar Exp $ */ +/* $OpenBSD: bpf.c,v 1.52 2004/09/12 09:35:50 claudio Exp $ */ /* $NetBSD: bpf.c,v 1.33 1997/02/21 23:59:35 thorpej Exp $ */ /* @@ -945,7 +945,7 @@ bpf_setif(d, ifr) struct bpf_d *d; struct ifreq *ifr; { - struct bpf_if *bp; + struct bpf_if *bp, *candidate = NULL; int s, error; /* @@ -959,6 +959,13 @@ bpf_setif(d, ifr) continue; /* * We found the requested interface. + */ + if (candidate == NULL || candidate->bif_dlt > bp->bif_dlt) + candidate = bp; + } + + if (candidate != NULL) { + /* * Allocate the packet buffers if we need to. * If we're already attached to requested interface, * just flush the buffer. @@ -969,14 +976,14 @@ bpf_setif(d, ifr) return (error); } s = splimp(); - if (bp != d->bd_bif) { + if (candidate != d->bd_bif) { if (d->bd_bif) /* * Detach if attached to something else. */ bpf_detachd(d); - bpf_attachd(d, bp); + bpf_attachd(d, candidate); } bpf_reset_d(d); splx(s); -- cgit v1.2.3