summaryrefslogtreecommitdiffstats
path: root/sys/kern/uipc_socket2.c
diff options
context:
space:
mode:
authorwollman <wollman@FreeBSD.org>1996-07-09 19:12:53 +0000
committerwollman <wollman@FreeBSD.org>1996-07-09 19:12:53 +0000
commitf53b019e3b9c566c1558586c1ccda33019257a28 (patch)
tree9c22bb256c7ddccd3022df002ff86c9b5678643b /sys/kern/uipc_socket2.c
parentba8d9388bd19ffc402d860c2376f96c7e618e193 (diff)
downloadFreeBSD-src-f53b019e3b9c566c1558586c1ccda33019257a28.zip
FreeBSD-src-f53b019e3b9c566c1558586c1ccda33019257a28.tar.gz
This is a proposal-in-code for a substantial modification of the way
the high kernel calls into a protocol stack to perform requests on the user's behalf. We replace the pr_usrreq() entry in struct protosw with a pointer to a structure containing pointers to functions which implement the various reuqests; each function is declared with the correct type and number of arguments. (This is unlike the current scheme in which a quarter of the requests take arguments of type other than (struct mbuf *) and the difference is papered over with casts.) There are a few benefits to this new scheme: 1) Arguments are passed with their correct types, and null-pointer dummies are no longer necessary. 2) There should be slightly better caching effects from eliminating the prximity to extraneous code and th switch in pr_usrreq(). 3) It becomes much easier to change the types of the arguments to something other than `struct mbuf *' (e.g.,pushing the work of sosend() into the protocol as advocated by Van Jacobson). There is one principal drawback: existing protocol stacks need to be modified. This is alleviated by compatibility code in uipc_socket2.c and uipc_domain.c which emulates the new interface in terms of the old and vice versa. This idea is not original to me. I read about what Jacobson did in one of his papers and have tried to implement the first steps towards something like that here. Much work remains to be done.
Diffstat (limited to 'sys/kern/uipc_socket2.c')
-rw-r--r--sys/kern/uipc_socket2.c220
1 files changed, 219 insertions, 1 deletions
diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c
index b3bdc44..4a8227d 100644
--- a/sys/kern/uipc_socket2.c
+++ b/sys/kern/uipc_socket2.c
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)uipc_socket2.c 8.1 (Berkeley) 6/10/93
- * $Id: uipc_socket2.c,v 1.9 1996/03/11 15:37:32 davidg Exp $
+ * $Id: uipc_socket2.c,v 1.10 1996/06/12 05:07:35 gpalmer Exp $
*/
#include <sys/param.h>
@@ -754,3 +754,221 @@ sbdroprecord(sb)
} while (m);
}
}
+
+#ifdef PRU_OLDSTYLE
+/*
+ * The following routines mediate between the old-style `pr_usrreq'
+ * protocol implementations and the new-style `struct pr_usrreqs'
+ * calling convention.
+ */
+
+/* syntactic sugar */
+#define nomb (struct mbuf *)0
+
+static int
+old_abort(struct socket *so)
+{
+ return so->so_proto->pr_usrreq(so, PRU_ABORT, nomb, nomb, nomb);
+}
+
+static int
+old_accept(struct socket *so, struct mbuf *nam)
+{
+ return so->so_proto->pr_usrreq(so, PRU_ACCEPT, nomb, nam, nomb);
+}
+
+static int
+old_attach(struct socket *so, int proto)
+{
+ return so->so_proto->pr_usrreq(so, PRU_ATTACH, nomb,
+ (struct mbuf *)proto, /* XXX */
+ nomb);
+}
+
+static int
+old_bind(struct socket *so, struct mbuf *nam)
+{
+ return so->so_proto->pr_usrreq(so, PRU_BIND, nomb, nam, nomb);
+}
+
+static int
+old_connect(struct socket *so, struct mbuf *nam)
+{
+ return so->so_proto->pr_usrreq(so, PRU_CONNECT, nomb, nam, nomb);
+}
+
+static int
+old_connect2(struct socket *so1, struct socket *so2)
+{
+ return so1->so_proto->pr_usrreq(so1, PRU_CONNECT2, nomb,
+ (struct mbuf *)so2, nomb);
+}
+
+static int
+old_control(struct socket *so, int cmd, caddr_t data)
+{
+ return so->so_proto->pr_usrreq(so, PRU_CONTROL, (struct mbuf *)cmd,
+ (struct mbuf *)data, nomb);
+}
+
+static int
+old_detach(struct socket *so)
+{
+ return so->so_proto->pr_usrreq(so, PRU_DETACH, nomb, nomb, nomb);
+}
+
+static int
+old_disconnect(struct socket *so)
+{
+ return so->so_proto->pr_usrreq(so, PRU_DISCONNECT, nomb, nomb, nomb);
+}
+
+static int
+old_listen(struct socket *so)
+{
+ return so->so_proto->pr_usrreq(so, PRU_LISTEN, nomb, nomb, nomb);
+}
+
+static int
+old_peeraddr(struct socket *so, struct mbuf *nam)
+{
+ return so->so_proto->pr_usrreq(so, PRU_PEERADDR, nomb, nam, nomb);
+}
+
+static int
+old_rcvd(struct socket *so, int flags)
+{
+ return so->so_proto->pr_usrreq(so, PRU_RCVD, nomb,
+ (struct mbuf *)flags, /* XXX */
+ nomb);
+}
+
+static int
+old_rcvoob(struct socket *so, struct mbuf *m, int flags)
+{
+ return so->so_proto->pr_usrreq(so, PRU_RCVOOB, m,
+ (struct mbuf *)flags, /* XXX */
+ nomb);
+}
+
+static int
+old_send(struct socket *so, int flags, struct mbuf *m, struct mbuf *addr,
+ struct mbuf *control)
+{
+ int req;
+
+ if (flags & PRUS_OOB) {
+ req = PRU_SENDOOB;
+ } else if(flags & PRUS_EOF) {
+ req = PRU_SEND_EOF;
+ } else {
+ req = PRU_SEND;
+ }
+ return so->so_proto->pr_usrreq(so, req, m, addr, control);
+}
+
+static int
+old_sense(struct socket *so, struct stat *sb)
+{
+ return so->so_proto->pr_usrreq(so, PRU_SENSE, (struct mbuf *)sb,
+ nomb, nomb);
+}
+
+static int
+old_shutdown(struct socket *so)
+{
+ return so->so_proto->pr_usrreq(so, PRU_SHUTDOWN, nomb, nomb, nomb);
+}
+
+static int
+old_sockaddr(struct socket *so, struct mbuf *nam)
+{
+ return so->so_proto->pr_usrreq(so, PRU_SOCKADDR, nomb, nam, nomb);
+}
+
+struct pr_usrreqs pru_oldstyle = {
+ old_abort, old_accept, old_attach, old_bind, old_connect,
+ old_connect2, old_control, old_detach, old_disconnect,
+ old_listen, old_peeraddr, old_rcvd, old_rcvoob, old_send,
+ old_sense, old_shutdown, old_sockaddr
+};
+
+/*
+ * This function is glue going the other way. It is present to allow
+ * for this interface to be actively developed from both directions
+ * (i.e., work on the kernel and protocol stacks proceeds simultaneously).
+ * It is expected that this function will probably cease to exist much
+ * sooner than the pru_oldstyle interface, above, will, because once the
+ * all of the high-kernel use of pr_usrreq() is removed the function is
+ * no longer needed.
+ */
+int
+pr_newstyle_usrreq(struct socket *so, int req, struct mbuf *m,
+ struct mbuf *nam, struct mbuf *control)
+{
+ struct pr_usrreqs *pru = so->so_proto->pr_usrreqs;
+
+ switch(req) {
+ case PRU_ABORT:
+ return pru->pru_abort(so);
+
+ case PRU_ACCEPT:
+ return pru->pru_accept(so, nam);
+
+ case PRU_ATTACH:
+ return pru->pru_attach(so, (int)nam);
+
+ case PRU_BIND:
+ return pru->pru_bind(so, nam);
+
+ case PRU_CONNECT:
+ return pru->pru_connect(so, nam);
+
+ case PRU_CONNECT2:
+ return pru->pru_connect2(so, (struct socket *)nam);
+
+ case PRU_CONTROL:
+ return pru->pru_control(so, (int)m, (caddr_t)nam);
+
+ case PRU_DETACH:
+ return pru->pru_detach(so);
+
+ case PRU_DISCONNECT:
+ return pru->pru_disconnect(so);
+
+ case PRU_LISTEN:
+ return pru->pru_listen(so);
+
+ case PRU_PEERADDR:
+ return pru->pru_peeraddr(so, nam);
+
+ case PRU_RCVD:
+ return pru->pru_rcvd(so, (int)nam);
+
+ case PRU_RCVOOB:
+ return pru->pru_rcvoob(so, m, (int)nam);
+
+ case PRU_SEND:
+ return pru->pru_send(so, 0, m, nam, control);
+
+ case PRU_SENDOOB:
+ return pru->pru_send(so, PRUS_OOB, m, nam, control);
+
+ case PRU_SEND_EOF:
+ return pru->pru_send(so, PRUS_EOF, m, nam, control);
+
+ case PRU_SENSE:
+ return pru->pru_sense(so, (struct stat *)m);
+
+ case PRU_SHUTDOWN:
+ return pru->pru_shutdown(so);
+
+ case PRU_SOCKADDR:
+ return pru->pru_sockaddr(so, nam);
+
+ }
+
+ panic("pru_newstyle_usrreq: unhandled request %d", req);
+}
+
+#endif /* PRU_OLDSTYLE */
OpenPOWER on IntegriCloud