5 * Copyright (c) 1996-1999 Whistle Communications, Inc.
8 * Subject to the following obligations and disclaimer of warranty, use and
9 * redistribution of this software, in source or object code forms, with or
10 * without modifications are expressly permitted by Whistle Communications;
11 * provided, however, that:
12 * 1. Any and all reproductions of the source or object code must include the
13 * copyright notice above and the following disclaimer of warranties; and
14 * 2. No rights are granted, in any manner or form, to use Whistle
15 * Communications, Inc. trademarks, including the mark "WHISTLE
16 * COMMUNICATIONS" on advertising, endorsements, or otherwise except as
17 * such appears in the above copyright notice or in the software.
19 * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
20 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
21 * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
22 * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
24 * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
25 * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
26 * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
27 * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
28 * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
29 * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
30 * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
37 * Author: Julian Elischer <julian@freebsd.org>
40 * $Whistle: ng_socket.c,v 1.28 1999/11/01 09:24:52 julian Exp $
44 * Netgraph socket nodes
46 * There are two types of netgraph sockets, control and data.
47 * Control sockets have a netgraph node, but data sockets are
48 * parasitic on control sockets, and have no node of their own.
51 #include <sys/param.h>
52 #include <sys/systm.h>
53 #include <sys/domain.h>
54 #include <sys/errno.h>
55 #include <sys/kernel.h>
56 #include <sys/filedesc.h>
57 #include <sys/malloc.h>
58 #include <sys/queue.h>
60 #include <sys/protosw.h>
61 #include <sys/socket.h>
62 #include <sys/socketvar.h>
63 #include <sys/sysctl.h>
65 #include <sys/vnode.h>
67 #include <netgraph/ng_message.h>
68 #include <netgraph/netgraph.h>
69 #include <netgraph/ng_socketvar.h>
70 #include <netgraph/ng_socket.h>
72 #ifdef NG_SEPARATE_MALLOC
73 MALLOC_DEFINE(M_NETGRAPH_PATH, "netgraph_path", "netgraph path info ");
74 MALLOC_DEFINE(M_NETGRAPH_SOCK, "netgraph_sock", "netgraph socket info ");
76 #define M_NETGRAPH_PATH M_NETGRAPH
77 #define M_NETGRAPH_SOCK M_NETGRAPH
81 * It's Ascii-art time!
82 * +-------------+ +-------------+
83 * |socket (ctl)| |socket (data)|
84 * +-------------+ +-------------+
88 * +-----------+ +-----------+
89 * |pcb (ctl)| |pcb (data)|
90 * +-----------+ +-----------+
94 * +--------------------------+
95 * | Socket type private |
97 * +--------------------------+
106 /* Netgraph node methods */
107 static ng_constructor_t ngs_constructor;
108 static ng_rcvmsg_t ngs_rcvmsg;
109 static ng_shutdown_t ngs_shutdown;
110 static ng_newhook_t ngs_newhook;
111 static ng_connect_t ngs_connect;
112 static ng_rcvdata_t ngs_rcvdata;
113 static ng_disconnect_t ngs_disconnect;
115 /* Internal methods */
116 static int ng_attach_data(struct socket *so);
117 static int ng_attach_cntl(struct socket *so);
118 static int ng_attach_common(struct socket *so, int type);
119 static void ng_detach_common(struct ngpcb *pcbp, int type);
120 /*static int ng_internalize(struct mbuf *m, struct thread *p); */
122 static int ng_connect_data(struct sockaddr *nam, struct ngpcb *pcbp);
123 static int ng_bind(struct sockaddr *nam, struct ngpcb *pcbp);
125 static int ngs_mod_event(module_t mod, int event, void *data);
126 static int ship_msg(struct ngpcb *pcbp, struct ng_mesg *msg,
127 struct sockaddr_ng *addr);
129 /* Netgraph type descriptor */
130 static struct ng_type typestruct = {
144 NETGRAPH_INIT(socket, &typestruct);
147 static u_long ngpdg_sendspace = 20 * 1024; /* really max datagram size */
148 static u_long ngpdg_recvspace = 20 * 1024;
150 /* List of all sockets */
151 static LIST_HEAD(, ngpcb) ngsocklist;
153 #define sotongpcb(so) ((struct ngpcb *)(so)->so_pcb)
155 /* If getting unexplained errors returned, set this to "Debugger("X"); */
160 /***************************************************************
162 ***************************************************************/
165 ngc_attach(struct socket *so, int proto, struct thread *td)
167 struct ngpcb *const pcbp = sotongpcb(so);
173 return (ng_attach_cntl(so));
177 ngc_detach(struct socket *so)
179 struct ngpcb *const pcbp = sotongpcb(so);
183 ng_detach_common(pcbp, NG_CONTROL);
188 ngc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
189 struct mbuf *control, struct thread *td)
191 struct ngpcb *const pcbp = sotongpcb(so);
192 struct sockaddr_ng *const sap = (struct sockaddr_ng *) addr;
203 if (control && (error = ng_internalize(control, td))) {
204 if (pcbp->sockdata == NULL) {
216 /* Require destination as there may be >= 1 hooks on this node */
218 error = EDESTADDRREQ;
222 /* Allocate an expendable buffer for the path, chop off
223 * the sockaddr header, and make sure it's NUL terminated */
224 len = sap->sg_len - 2;
225 MALLOC(path, char *, len + 1, M_NETGRAPH_PATH, M_WAITOK);
230 bcopy(sap->sg_data, path, len);
233 /* Move the actual message out of mbufs into a linear buffer.
234 * Start by adding up the size of the data. (could use mh_len?) */
235 for (len = 0, m0 = m; m0 != NULL; m0 = m0->m_next)
238 /* Move the data into a linear buffer as well. Messages are not
239 * delivered in mbufs. */
240 MALLOC(msg, struct ng_mesg *, len + 1, M_NETGRAPH_MSG, M_WAITOK);
245 m_copydata(m, 0, len, (char *)msg);
247 #ifdef TRACE_MESSAGES
250 if ((item = ng_package_msg(msg)) == NULL) {
253 printf("err=%d\n",error);
256 if (((error) = ng_address_path((pcbp->sockdata->node), (item),
257 (path), (NULL))) == 0) {
258 printf("[%x]:<---------[socket]: c=<%d>cmd=%x(%s) f=%x #%d (%s)\n",
259 item->el_dest->nd_ID,
260 msg->header.typecookie,
265 item->el_dest->nd_type->name);
267 (error) = ng_snd_item((item), 0);
270 printf("errx=%d\n",error);
276 /* The callee will free the msg when done. The path is our business. */
277 NG_SEND_MSG_PATH(error, pcbp->sockdata->node, msg, path, NULL);
281 FREE(path, M_NETGRAPH_PATH);
290 ngc_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
292 struct ngpcb *const pcbp = sotongpcb(so);
296 return (ng_bind(nam, pcbp));
300 ngc_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
302 printf(" program tried to connect control socket to remote node\n ");
304 * At this time refuse to do this.. it used to
305 * do something but it was undocumented and not used.
310 /***************************************************************
312 ***************************************************************/
315 ngd_attach(struct socket *so, int proto, struct thread *td)
317 struct ngpcb *const pcbp = sotongpcb(so);
321 return (ng_attach_data(so));
325 ngd_detach(struct socket *so)
327 struct ngpcb *const pcbp = sotongpcb(so);
331 ng_detach_common(pcbp, NG_DATA);
336 ngd_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
337 struct mbuf *control, struct thread *td)
339 struct ngpcb *const pcbp = sotongpcb(so);
340 struct sockaddr_ng *const sap = (struct sockaddr_ng *) addr;
343 char hookname[NG_HOOKLEN + 1];
345 if ((pcbp == NULL) || (control != NULL)) {
349 if (pcbp->sockdata == NULL) {
354 * If the user used any of these ways to not specify an address
355 * then handle specially.
358 || ((len = sap->sg_len - 2) <= 0)
359 || (*sap->sg_data == '\0')) {
360 if (NG_NODE_NUMHOOKS(pcbp->sockdata->node) != 1) {
361 error = EDESTADDRREQ;
365 * if exactly one hook exists, just use it.
366 * Special case to allow write(2) to work on an ng_socket.
368 hook = LIST_FIRST(&pcbp->sockdata->node->nd_hooks);
370 if (len > NG_HOOKLEN) {
376 * chop off the sockaddr header, and make sure it's NUL
379 bcopy(sap->sg_data, hookname, len);
380 hookname[len] = '\0';
382 /* Find the correct hook from 'hookname' */
383 LIST_FOREACH(hook, &pcbp->sockdata->node->nd_hooks, hk_hooks) {
384 if (strcmp(hookname, NG_HOOK_NAME(hook)) == 0) {
389 error = EHOSTUNREACH;
393 /* Send data (OK if hook is NULL) */
394 NG_SEND_DATA_ONLY(error, hook, m); /* makes m NULL */
405 ngd_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
407 struct ngpcb *const pcbp = sotongpcb(so);
411 return (ng_connect_data(nam, pcbp));
415 * Used for both data and control sockets
418 ng_setsockaddr(struct socket *so, struct sockaddr **addr)
421 struct sockaddr_ng *sg;
422 int sg_len, namelen, s;
424 /* Why isn't sg_data a `char[1]' ? :-( */
425 sg_len = sizeof(struct sockaddr_ng) - sizeof(sg->sg_data) + 1;
428 pcbp = sotongpcb(so);
429 if ((pcbp == NULL) || (pcbp->sockdata == NULL)) {
434 namelen = 0; /* silence compiler ! */
435 if ( NG_NODE_HAS_NAME(pcbp->sockdata->node))
436 sg_len += namelen = strlen(NG_NODE_NAME(pcbp->sockdata->node));
438 MALLOC(sg, struct sockaddr_ng *, sg_len, M_SONAME, M_WAITOK | M_ZERO);
440 if (NG_NODE_HAS_NAME(pcbp->sockdata->node))
441 bcopy(NG_NODE_NAME(pcbp->sockdata->node), sg->sg_data, namelen);
445 sg->sg_family = AF_NETGRAPH;
446 *addr = (struct sockaddr *)sg;
452 * Attach a socket to it's protocol specific partner.
453 * For a control socket, actually create a netgraph node and attach
458 ng_attach_cntl(struct socket *so)
460 struct ngsock *privdata;
464 /* Setup protocol control block */
465 if ((error = ng_attach_common(so, NG_CONTROL)) != 0)
467 pcbp = sotongpcb(so);
469 /* Allocate node private info */
470 MALLOC(privdata, struct ngsock *,
471 sizeof(*privdata), M_NETGRAPH_SOCK, M_WAITOK | M_ZERO);
472 if (privdata == NULL) {
473 ng_detach_common(pcbp, NG_CONTROL);
477 /* Make the generic node components */
478 if ((error = ng_make_node_common(&typestruct, &privdata->node)) != 0) {
479 FREE(privdata, M_NETGRAPH_SOCK);
480 ng_detach_common(pcbp, NG_CONTROL);
483 NG_NODE_SET_PRIVATE(privdata->node, privdata);
485 /* Link the pcb and the node private data */
486 privdata->ctlsock = pcbp;
487 pcbp->sockdata = privdata;
493 ng_attach_data(struct socket *so)
495 return(ng_attach_common(so, NG_DATA));
499 * Set up a socket protocol control block.
500 * This code is shared between control and data sockets.
503 ng_attach_common(struct socket *so, int type)
508 /* Standard socket setup stuff */
509 error = soreserve(so, ngpdg_sendspace, ngpdg_recvspace);
513 /* Allocate the pcb */
514 MALLOC(pcbp, struct ngpcb *, sizeof(*pcbp), M_PCB, M_WAITOK | M_ZERO);
519 /* Link the pcb and the socket */
520 so->so_pcb = (caddr_t) pcbp;
521 pcbp->ng_socket = so;
523 /* Add the socket to linked list */
524 LIST_INSERT_HEAD(&ngsocklist, pcbp, socks);
529 * Disassociate the socket from it's protocol specific
530 * partner. If it's attached to a node's private data structure,
531 * then unlink from that too. If we were the last socket attached to it,
532 * then shut down the entire node. Shared code for control and data sockets.
535 ng_detach_common(struct ngpcb *pcbp, int which)
539 if (pcbp->sockdata) {
540 priv = pcbp->sockdata;
541 pcbp->sockdata = NULL;
544 priv->ctlsock = NULL;
547 priv->datasock = NULL;
552 if ((--priv->refs == 0) && (priv->node != NULL))
553 ng_rmnode_self(priv->node);
555 pcbp->ng_socket->so_pcb = NULL;
556 pcbp->ng_socket = NULL;
557 LIST_REMOVE(pcbp, socks);
563 * File descriptors can be passed into a AF_NETGRAPH socket.
564 * Note, that file descriptors cannot be passed OUT.
565 * Only character device descriptors are accepted.
566 * Character devices are useful to connect a graph to a device,
567 * which after all is the purpose of this whole system.
570 ng_internalize(struct mbuf *control, struct thread *td)
572 struct cmsghdr *cm = mtod(control, struct cmsghdr *);
578 if (cm->cmsg_type != SCM_RIGHTS || cm->cmsg_level != SOL_SOCKET ||
579 cm->cmsg_len != control->m_len) {
584 /* Check there is only one FD. XXX what would more than one signify? */
585 oldfds = ((caddr_t)cm + cm->cmsg_len - (caddr_t)data) / sizeof (int);
591 /* Check that the FD given is legit. and change it to a pointer to a
594 if ((error = fget(td, fd, &fp)) != 0)
597 /* Depending on what kind of resource it is, act differently. For
598 * devices, we treat it as a file. For a AF_NETGRAPH socket,
599 * shortcut straight to the node. */
600 switch (fp->f_type) {
602 vn = (struct vnode *) fp->f_data;
603 if (vn && (vn->v_type == VCHR)) {
604 /* for a VCHR, actually reference the FILE */
606 /* XXX then what :) */
607 /* how to pass on to other modules? */
625 * Connect the data socket to a named control socket node.
628 ng_connect_data(struct sockaddr *nam, struct ngpcb *pcbp)
630 struct sockaddr_ng *sap;
636 /* If we are already connected, don't do it again */
637 if (pcbp->sockdata != NULL)
640 /* Find the target (victim) and check it doesn't already have a data
641 * socket. Also check it is a 'socket' type node.
642 * Use ng_package_data() and address_path() to do this.
645 sap = (struct sockaddr_ng *) nam;
646 /* The item will hold the node reference */
647 item = ng_package_data(NULL, NULL);
651 if ((error = ng_address_path(NULL, item, sap->sg_data, NULL)))
652 return (error); /* item is freed on failure */
655 * Extract node from item and free item. Remember we now have
656 * a reference on the node. The item holds it for us.
657 * when we free the item we release the reference.
659 farnode = item->el_dest; /* shortcut */
660 if (strcmp(farnode->nd_type->name, NG_SOCKET_NODE_TYPE) != 0) {
661 NG_FREE_ITEM(item); /* drop the reference to the node */
664 priv = NG_NODE_PRIVATE(farnode);
665 if (priv->datasock != NULL) {
666 NG_FREE_ITEM(item); /* drop the reference to the node */
671 * Link the PCB and the private data struct. and note the extra
672 * reference. Drop the extra reference on the node.
674 priv->datasock = pcbp;
675 pcbp->sockdata = priv;
676 priv->refs++; /* XXX possible race if it's being freed */
677 NG_FREE_ITEM(item); /* drop the reference to the node */
682 * Binding a socket means giving the corresponding node a name
685 ng_bind(struct sockaddr *nam, struct ngpcb *pcbp)
687 struct ngsock *const priv = pcbp->sockdata;
688 struct sockaddr_ng *const sap = (struct sockaddr_ng *) nam;
694 if ((sap->sg_len < 4)
695 || (sap->sg_len > (NG_NODELEN + 3))
696 || (sap->sg_data[0] == '\0')
697 || (sap->sg_data[sap->sg_len - 3] != '\0')) {
701 return (ng_name_node(priv->node, sap->sg_data));
705 * Take a message and pass it up to the control socket associated
709 ship_msg(struct ngpcb *pcbp, struct ng_mesg *msg, struct sockaddr_ng *addr)
711 struct socket *const so = pcbp->ng_socket;
715 /* Copy the message itself into an mbuf chain */
716 msglen = sizeof(struct ng_mesg) + msg->header.arglen;
717 mdata = m_devget((caddr_t) msg, msglen, 0, NULL, NULL);
719 /* Here we free the message, as we are the end of the line.
720 * We need to do that regardless of whether we got mbufs. */
728 /* Send it up to the socket */
729 if (sbappendaddr(&so->so_rcv,
730 (struct sockaddr *) addr, mdata, NULL) == 0) {
740 * You can only create new nodes from the socket end of things.
743 ngs_constructor(node_p nodep)
749 * We allow any hook to be connected to the node.
750 * There is no per-hook private information though.
753 ngs_newhook(node_p node, hook_p hook, const char *name)
755 NG_HOOK_SET_PRIVATE(hook, NG_NODE_PRIVATE(node));
760 * if only one hook, allow read(2) and write(2) to work.
763 ngs_connect(hook_p hook)
765 node_p node = NG_HOOK_NODE(hook);
766 struct ngsock *priv = NG_NODE_PRIVATE(node);
769 && (priv->datasock->ng_socket)) {
770 if (NG_NODE_NUMHOOKS(node) == 1) {
771 priv->datasock->ng_socket->so_state |= SS_ISCONNECTED;
773 priv->datasock->ng_socket->so_state &= ~SS_ISCONNECTED;
780 * Incoming messages get passed up to the control socket.
781 * Unless they are for us specifically (socket_type)
784 ngs_rcvmsg(node_p node, item_p item, hook_p lasthook)
786 struct ngsock *const priv = NG_NODE_PRIVATE(node);
787 struct ngpcb *const pcbp = priv->ctlsock;
788 struct sockaddr_ng *addr;
792 ng_ID_t retaddr = NGI_RETADDR(item);
795 NGI_GET_MSG(item, msg);
796 NG_FREE_ITEM(item); /* we have all we need */
798 /* Only allow mesgs to be passed if we have the control socket.
799 * Data sockets can only support the generic messages. */
804 #ifdef TRACE_MESSAGES
805 printf("[%x]:---------->[socket]: c=<%d>cmd=%x(%s) f=%x #%d\n",
807 msg->header.typecookie,
815 if (msg->header.typecookie == NGM_SOCKET_COOKIE) {
816 switch (msg->header.cmd) {
817 case NGM_SOCK_CMD_NOLINGER:
818 priv->flags |= NGS_FLAG_NOLINGER;
820 case NGM_SOCK_CMD_LINGER:
821 priv->flags &= ~NGS_FLAG_NOLINGER;
824 error = EINVAL; /* unknown command */
826 /* Free the message and return */
831 /* Get the return address into a sockaddr */
832 sprintf(retabuf,"[%x]:", retaddr);
833 addrlen = strlen(retabuf);
834 MALLOC(addr, struct sockaddr_ng *, addrlen + 4, M_NETGRAPH_PATH, M_NOWAIT);
839 addr->sg_len = addrlen + 3;
840 addr->sg_family = AF_NETGRAPH;
841 bcopy(retabuf, addr->sg_data, addrlen);
842 addr->sg_data[addrlen] = '\0';
845 error = ship_msg(pcbp, msg, addr);
846 FREE(addr, M_NETGRAPH_PATH);
851 * Receive data on a hook
854 ngs_rcvdata(hook_p hook, item_p item)
856 struct ngsock *const priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
857 struct ngpcb *const pcbp = priv->datasock;
859 struct sockaddr_ng *addr;
860 char *addrbuf[NG_HOOKLEN + 1 + 4];
866 /* If there is no data socket, black-hole it */
871 so = pcbp->ng_socket;
873 /* Get the return address into a sockaddr. */
874 addrlen = strlen(NG_HOOK_NAME(hook)); /* <= NG_HOOKLEN */
875 addr = (struct sockaddr_ng *) addrbuf;
876 addr->sg_len = addrlen + 3;
877 addr->sg_family = AF_NETGRAPH;
878 bcopy(NG_HOOK_NAME(hook), addr->sg_data, addrlen);
879 addr->sg_data[addrlen] = '\0';
881 /* Try to tell the socket which hook it came in on */
882 if (sbappendaddr(&so->so_rcv, (struct sockaddr *) addr, m, NULL) == 0) {
894 * For this type, removal of the last link destroys the node
895 * if the NOLINGER flag is set.
898 ngs_disconnect(hook_p hook)
900 node_p node = NG_HOOK_NODE(hook);
901 struct ngsock *const priv = NG_NODE_PRIVATE(node);
904 && (priv->datasock->ng_socket)) {
905 if (NG_NODE_NUMHOOKS(node) == 1) {
906 priv->datasock->ng_socket->so_state |= SS_ISCONNECTED;
908 priv->datasock->ng_socket->so_state &= ~SS_ISCONNECTED;
912 if ((priv->flags & NGS_FLAG_NOLINGER )
913 && (NG_NODE_NUMHOOKS(node) == 0)
914 && (NG_NODE_IS_VALID(node))) {
915 ng_rmnode_self(node);
921 * Do local shutdown processing.
922 * In this case, that involves making sure the socket
923 * knows we should be shutting down.
926 ngs_shutdown(node_p node)
928 struct ngsock *const priv = NG_NODE_PRIVATE(node);
929 struct ngpcb *const dpcbp = priv->datasock;
930 struct ngpcb *const pcbp = priv->ctlsock;
933 soisdisconnected(dpcbp->ng_socket);
934 dpcbp->sockdata = NULL;
935 priv->datasock = NULL;
939 soisdisconnected(pcbp->ng_socket);
940 pcbp->sockdata = NULL;
941 priv->ctlsock = NULL;
944 NG_NODE_SET_PRIVATE(node, NULL);
946 FREE(priv, M_NETGRAPH_SOCK);
951 dummy_disconnect(struct socket *so)
956 * Control and data socket type descriptors
959 static struct pr_usrreqs ngc_usrreqs = {
965 pru_connect2_notsupp,
968 dummy_disconnect, /* disconnect */
970 NULL, /* setpeeraddr */
982 static struct pr_usrreqs ngd_usrreqs = {
988 pru_connect2_notsupp,
991 dummy_disconnect, /* disconnect */
993 NULL, /* setpeeraddr */
1006 * Definitions of protocols supported in the NETGRAPH domain.
1009 extern struct domain ngdomain; /* stop compiler warnings */
1011 static struct protosw ngsw[] = {
1013 SOCK_DGRAM, /* protocol type */
1014 &ngdomain, /* backpointer to domain */
1016 PR_ATOMIC | PR_ADDR /* | PR_RIGHTS */, /* flags */
1017 0, 0, 0, 0, /* input, output, ctlinput, ctloutput */
1019 0, 0, 0, 0, /* init, fasttimeo, slowtimo, drain */
1020 &ngc_usrreqs, /* usrreq table (above) */
1021 /*{NULL}*/ /* pffh (protocol filter head?) */
1024 SOCK_DGRAM, /* protocol type */
1025 &ngdomain, /* backpointer to domain */
1027 PR_ATOMIC | PR_ADDR, /* flags */
1028 0, 0, 0, 0, /* input, output, ctlinput, ctloutput */
1029 NULL, /* ousrreq() */
1030 0, 0, 0, 0, /* init, fasttimeo, slowtimo, drain */
1031 &ngd_usrreqs, /* usrreq table (above) */
1032 /*{NULL}*/ /* pffh (protocol filter head?) */
1036 struct domain ngdomain = {
1040 NULL, /* externalise() */
1041 NULL, /* dispose() */
1042 ngsw, /* protosw entry */
1043 &ngsw[sizeof(ngsw) / sizeof(ngsw[0])], /* Number of protosw entries */
1044 NULL, /* next domain in list */
1045 NULL, /* rtattach() */
1046 0, /* arg to rtattach in bits */
1051 * Handle loading and unloading for this node type
1052 * This is to handle auxiliary linkages (e.g protocol domain addition).
1055 ngs_mod_event(module_t mod, int event, void *data)
1061 /* Register protocol domain */
1062 net_add_domain(&ngdomain);
1065 /* Insure there are no open netgraph sockets */
1066 if (!LIST_EMPTY(&ngsocklist)) {
1072 if ((LIST_EMPTY(&ngsocklist)) && (typestruct.refs == 0)) {
1073 /* Unregister protocol domain XXX can't do this yet.. */
1074 if ((error = net_rm_domain(&ngdomain)) != 0)
1087 SYSCTL_INT(_net_graph, OID_AUTO, family, CTLFLAG_RD, 0, AF_NETGRAPH, "");
1088 SYSCTL_NODE(_net_graph, OID_AUTO, data, CTLFLAG_RW, 0, "DATA");
1089 SYSCTL_INT(_net_graph_data, OID_AUTO, proto, CTLFLAG_RD, 0, NG_DATA, "");
1090 SYSCTL_NODE(_net_graph, OID_AUTO, control, CTLFLAG_RW, 0, "CONTROL");
1091 SYSCTL_INT(_net_graph_control, OID_AUTO, proto, CTLFLAG_RD, 0, NG_CONTROL, "");