Page MenuHomeFreeBSD

ipfw: use typed pointers to access network protocols headers where possible
ClosedPublic

Authored by glebius on Fri, Sep 4, 11:10 PM.
Tags
None
Referenced Files
F173757967: D59435.id187165.diff
Mon, Sep 28, 4:37 AM
F173754231: D59435.diff
Mon, Sep 28, 3:50 AM
F173718755: D59435.diff
Sun, Sep 27, 10:33 PM
Unknown Object (File)
Sun, Sep 27, 12:16 AM
Unknown Object (File)
Wed, Sep 16, 11:45 PM
Unknown Object (File)
Wed, Sep 16, 8:18 PM
Unknown Object (File)
Tue, Sep 15, 4:03 AM
Unknown Object (File)
Sat, Sep 12, 11:10 PM

Details

Summary

The 'void *ulp' is still in action, but where possible prefer a typed
pointer. Get rid of associated pre-processor macros.

Diff Detail

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

Event Timeline

Treat this as a suggestion. IMHO, this is more readable than the old version. If everybody disagrees with me, I'm fine with abandoning this.

The diff may not look great but I like the spelling out of types rather than hiding casts behind macros.

I was going to say I'd start the block under the case and not at the end of the line but it seems the more dominant style indeed is what you chose, so ignore this one.

sys/netpfil/ipfw/ip_fw2.c
1590

We have insntoc/insntod macros with similar goal, but for ipfw insn structure.

Not sure if we need a stack variables scattered across the code instead of something similar to ulptod(ulp, icmp6).

Yep, this sounds much like reformatting ICMP6(ulp) et al. into a flexible form.

sys/netpfil/ipfw/ip_fw2.c
1590

IMHO, all these macros that hide C basics are beneficial when you work with a single project for a long time and both your eyes and fingers have the muscle memory to immediately recognize them and type them. The downside is that the code is not very welcoming to a newcomer. The struct ip, struct tcp, struct icmp6_hdr and etc are well known to any network stack programmer and adoption is even wider than just FreeBSD. So, for a newcomer the suggested code is much more readable without jumping and checking wtf is ICMP6() or ulptod(). Even a returning co-author after years of working in different areas of the network stack will stumble upon this micro-obfuscations.

sys/netpfil/ipfw/ip_fw2.c
1590

A perfectly valid point indeed. But we're talking about hot path and on-stack variables may require an additional assignment in contrast to type casting.

sys/netpfil/ipfw/ip_fw2.c
1590

Compiler will produce same code for both variants. Maybe only with -O0 could be different.

This revision was not accepted when it landed; it landed in state Needs Review.Fri, Sep 18, 10:50 PM
This revision was automatically updated to reflect the committed changes.