use of #ifdef INET and #ifdef INET6 in the kernel sources

Bjoern A. Zeeb bz at FreeBSD.org
Thu Feb 28 01:39:56 UTC 2019


On 28 Feb 2019, at 1:11, Rick Macklem wrote:

> I thought (can't remember when/how I was told) that it was no longer
> recommended to add
> #ifdef INET
> or
> #ifdef INET6
> to the kernel sources.

Not sure who said this.

> I'll admit I think #ifdef'ng code when it isn't necessary to get it to 
> build makes the
> code less readable and, as such, I prefer not to do this.

We all agree on this.


> So, is this still recommended for blocks of code that only execute for 
> the version
> of IP, but will build for kernels that do not have the particular 
> "options INET{6}"
> in the kernel config?

Yes.


> If it is still recommended, I will do it, but I'll admit I don't 
> understand why it should
> be done? (All it does is reduce the size of the executable by a small 
> amount and
> that doesn't seem significant to me.)

That small amount is still relevant on some devices where people go to 
great lengths to fit our constantly growing base into a tiny small 
thingy.

And it allows you to lose code from your kernel that you don’t 
need/want, such as if you’d want to rip out all INET sources from a 
tree.

I know both of these groups still do exist.

Also every code not compiled in is not an attack surface, where you 
think it’s executed or not.

/bz


More information about the freebsd-net mailing list