-
Notifications
You must be signed in to change notification settings - Fork 45
Tracing OpenBSD's `bind`
The [regression test] (https://github.com/openbsd/src/blob/5271000b44abe23907b73bbb3aa38ddf4a0bce08/regress/sys/kern/bind/bind.c) creates a socket that will use the UNIX internal domain (AF_INET
) and a datagram communication protocol. The test enables port reuse on this socket with the SO_REUSEPORT
option passed to setsockopt
(see man socket
and man setsockopt
for details).
We call bind
on the socket's file descriptor. In order to trace this call, we go to our syscalls function assignment, which links 104 (bind
) to sys_bind
. sys_bind
, found in uipc_syscalls.c, parses the syscall arguments (standard for all syscalls), calls pledge_socket
, and eventually calls sobind
on the pointer to our socket, the mbuf carrying address information, and the metadata about the process that called this.
sobind
delegates out to the pr_usrreq
function attached to the passed-in socket's protocol. Before we go directly to the appropriate pr_usrreq
function, it's important we trace how that gets assigned in the first place. This will turn into quite the detour...
When we call socreate, which eventually gets called in sys_socket, we call one of two methods, pffindproto or pffindtype. Both of these methods return a protosw pointer which includes the pr_usrreq
function for whatever protocol gets returned.
- Link unlinked formatted functions to code.
- Explain how
pr_usrreq
functions get linked toprotosw
instances. - Cover the interface to
pr_usrreq
. - Add details to descriptions.
-
socreate
-
pffindproto
-
pffindtype
-
- Consider reformatting this into an outline or Q&A format.
- Add an actual trace of function calls with sample arguments.
- Add code blocks for important structs or pieces of code.
- What does
sw
inprotosw
stand for? Protocol switch table. - What does it mean when a function starts with "/*ARGSUSED*/"? Obsolete hint for lint, looks like.
- Why is the only implementation of
bind
found inuipc_syscalls.c
? What does "uipc" stand for? Is it "inter-process communication"? - What does the
...
mean at the end of a C function signature? http://man.openbsd.org/OpenBSD-5.8/varargs.3