November 13, 2022

BSD TCP/IP for Kyu - tcp_usrreq.c

The code to handle various aspects of the system calls like socket, bind, accept, are handled by routines in this file.

The story is this -- at one time the BSD code supported a variety of protocols, not just AF_INET. BSD was a testbed for a lot of network protocol research back in the 1990's. So things like socket and bind were protocol independent. A call to one of these (socket or bind) would do a lookup on the protocol and find a protosw structure. This structure has various function pointers for the routines to handle different things (and those routines are what we find in tcp_usrreq.c). Typically a call is made to tcp_usrreq(). The second argument is a request type (like PRU_CONTROL, PRU_BIND) and the routine is a big switch/case on "req".

Since I am only interested in the AF_INET protocol family and even only the TCP protocol in that family, I could (and do) do some significant simplification and streamlining.

For whatever reason, most arguments of any size or complexity are passed in "mbuf" structures. This is certainly done for BIND where the sockaddr_in structure is copied into an mbuf. This is the kind of thing that I could entirely do away with in my code simplification.


Have any comments? Questions? Drop me a line!

Kyu / [email protected]