Download raw body.
let bpf pick the first bpf_if, not the bpf_if with the lowest dlt
let bpf pick the first bpf_if, not the bpf_if with the lowest dlt
On Wed, Nov 20, 2024 at 10:18:35AM +1000, David Gwynne wrote:
> this lets bpf_setif pick the first found dlt in the bpf_if list when
> attaching a bpf descriptor to an interface. back in bpf.c r1.52
> claudio changed bpf_setif so it would prefer lower numbered DLTs
> when attaching a bpf descriptor to an interface. before that it would
> pick the last bpf_if that was added because of how the bpf_if list was
> ordered.
>
> claudio made the change so things would show the "most common" DLT
> by default, and the example given was an atw(4) wifi interface.
> wifi interfaces provide at least two and often more DLTs,
>
> wifi interfaces attach a DLT_EN10MB interface first, which is what
> people expect when they tcpdump on an interface, so this doesn't break
> the change in 1.52.
>
> however, i want to attach multiple DLTs to some other interfaces, but
> control which one is the default regardless of the number used for the
> DLT identifier. letting bpf pick the first attached dlt on an interface
> is the simplest fix for this, and doesn't seem to break existing use
> cases.
>
> ok?
OK claudio@
The behaviour remains the same but the logic is a bit simpler. If there is
a driver that attaches the wrong way it can be fixed easily.
> Index: bpf.c
> ===================================================================
> RCS file: /cvs/src/sys/net/bpf.c,v
> diff -u -p -r1.227 bpf.c
> --- bpf.c 19 Nov 2024 23:26:35 -0000 1.227
> +++ bpf.c 19 Nov 2024 23:29:03 -0000
> @@ -1180,22 +1180,19 @@ bpf_setf(struct bpf_d *d, struct bpf_pro
> 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
> 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:
>
--
:wq Claudio
let bpf pick the first bpf_if, not the bpf_if with the lowest dlt
let bpf pick the first bpf_if, not the bpf_if with the lowest dlt