Page MenuHomeFreeBSD

Bug 204438 - setsockopt() handling of kern.ipc.maxsockbuf limit
Needs ReviewPublic

Authored by cameronsparr_gmail.com on Nov 11 2015, 10:23 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Apr 16, 8:28 PM
Unknown Object (File)
Mar 14 2024, 8:36 AM
Unknown Object (File)
Mar 14 2024, 8:36 AM
Unknown Object (File)
Feb 11 2024, 6:01 PM
Unknown Object (File)
Feb 11 2024, 3:37 PM
Unknown Object (File)
Jan 9 2024, 6:52 PM
Unknown Object (File)
Dec 23 2023, 6:06 AM
Unknown Object (File)
Dec 19 2023, 11:47 PM

Details

Reviewers
None
Group Reviewers
network
Contributor Reviews (src)
Summary

changing the way that the setsockopt() function handles the max socket buffer setting.

Currently, it's a bit unintuitive that socket send and receive buffers (SO_RCVBUF & SO_SNDBUF) can not actually be set to the kern.ipc.maxsockbuf value, even though it is described as being possible in the man page: https://www.freebsd.org/cgi/man.cgi?query=setsockopt&sektion=2

This is because setsockopt() will error out if the value passed is over the _adjusted_ maximum, which on my system (amd64) turns out to be something like kern.ipc.maxsockbuf * 0.889 (kern.ipc.maxsockbuf * (1 << 11) / (256 + (1 << 11)) = kern.ipc.maxsockbuf * (2048) / (2304)).

see here:
https://github.com/freebsd/freebsd/blob/master/sys/kern/uipc_sockbuf.c#L420
and here:
https://github.com/freebsd/freebsd/blob/master/sys/kern/uipc_sockbuf.c#L63-L64

I believe that the behavior could be made more intuitive by checking if the value passed is under the _actual_ max before erroring out, and if it is under the actual max, then set it to the adjusted max and continue the function, this would be a simple change and would look something like this (apologies for the whitespace diffs): https://github.com/sparrc/freebsd/commit/157f90c55d1d54d33f41c6f7517de1a9c5f5e229

FWIW, the linux kernel takes it a step further by never failing if setting the buffer over the maximum. It just takes whatever value it's given and sets it to min(given_value, max_value). see here: https://github.com/torvalds/linux/blob/master/net/core/sock.c#L762-L768. Not saying this is a good option, just pointing out that there is a precedent for doing something like this.

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped