Page MenuHomeFreeBSD

dhclient: remove the need to patch static values
ClosedPublic

Authored by franco_opnsense.org on Aug 11 2021, 7:40 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Mar 22, 9:59 PM
Unknown Object (File)
Fri, Mar 22, 9:59 PM
Unknown Object (File)
Fri, Mar 22, 9:59 PM
Unknown Object (File)
Fri, Mar 22, 9:59 PM
Unknown Object (File)
Mar 9 2024, 7:02 AM
Unknown Object (File)
Mar 8 2024, 12:04 AM
Unknown Object (File)
Feb 15 2024, 5:47 PM
Unknown Object (File)
Jan 29 2024, 5:23 PM

Details

Summary

Imported into FreeBSD from OpenBSD 3.7. Imported in 2004 from
ISC DHCP... Looks like the patching was part of templating for
different things, sort of see:

https://gitlab.isc.org/isc-projects/dhcp/-/blob/master/common/bpf.c

At least we know the BPF filter values should be given in host
order and apparently the whole thing keeps working.

While here enable the IP_MF bit during receiving which seems to be
more consistent.

Test Plan

Running in production in OPNsense 21.7 for two weeks. Requires
another dhclient(1) test on a CURRENT build.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Seems ok to me overall.

At least we know the BPF filter values should be given in host
order and apparently the whole thing keeps working.

Are you sure it worked before? I see that BPF_LD will unconditionally byte-swap the loaded value into A, so on little-endian systems will convert it to host order. Then a subsequent JMP will compare the immediate value with A. So passing in host order is correct, and on big-endian systems BPF filters look to be somewhat broken...

sbin/dhclient/bpf.c
108

Did you consider making these tables const? You would have to write:

p.bf_insns = __DECONST(struct bpf_insn *, dhcp_bpf_wfilter);

below, but that is worth it IMO.

constify filters and avoid static length variables

OpenBSD added the single htons() while adding write filter, but nowhere else. I suspect the fragmentation check is mostly correct so this doesn't matter in the real world.

From the ISC bpf.c I can see no htons() but two ntohs() calls for port definitions that are initialised as:

local_port = htons(67);

If there is an issue with bpf on big endian it should probably be fixed closer to bpf code, but it doesn't seem this way (port filters likely work on big endian as a fundamental assumption for lack of reports)?

sbin/dhclient/bpf.c
108

Agreed, went a little further by inlining the length vars.

OpenBSD added the single htons() while adding write filter, but nowhere else. I suspect the fragmentation check is mostly correct so this doesn't matter in the real world.

From the ISC bpf.c I can see no htons() but two ntohs() calls for port definitions that are initialised as:

local_port = htons(67);

If there is an issue with bpf on big endian it should probably be fixed closer to bpf code, but it doesn't seem this way (port filters likely work on big endian as a fundamental assumption for lack of reports)?

Indeed, BPF_LD doesn't byte-swap, I just misread.

This revision is now accepted and ready to land.Aug 18 2021, 8:30 PM