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/domain.h>
53 #include <sys/errno.h>
54 #include <sys/kernel.h>
56 #include <sys/malloc.h>
58 #include <sys/protosw.h>
59 #include <sys/queue.h>
60 #include <sys/signalvar.h>
61 #include <sys/socket.h>
62 #include <sys/socketvar.h>
64 #include <sys/sysctl.h>
65 #include <sys/systm.h>
67 #include <sys/vnode.h>
69 #include <netgraph/ng_message.h>
70 #include <netgraph/netgraph.h>
71 #include <netgraph/ng_socketvar.h>
72 #include <netgraph/ng_socket.h>
74 #ifdef NG_SEPARATE_MALLOC
75 MALLOC_DEFINE(M_NETGRAPH_PATH, "netgraph_path", "netgraph path info ");
76 MALLOC_DEFINE(M_NETGRAPH_SOCK, "netgraph_sock", "netgraph socket info ");
78 #define M_NETGRAPH_PATH M_NETGRAPH
79 #define M_NETGRAPH_SOCK M_NETGRAPH
83 * It's Ascii-art time!
84 * +-------------+ +-------------+
85 * |socket (ctl)| |socket (data)|
86 * +-------------+ +-------------+
90 * +-----------+ +-----------+
91 * |pcb (ctl)| |pcb (data)|
92 * +-----------+ +-----------+
96 * +--------------------------+
97 * | Socket type private |
99 * +--------------------------+
108 /* Netgraph node methods */
109 static ng_constructor_t ngs_constructor;
110 static ng_rcvmsg_t ngs_rcvmsg;
111 static ng_shutdown_t ngs_shutdown;
112 static ng_newhook_t ngs_newhook;
113 static ng_connect_t ngs_connect;
114 static ng_rcvdata_t ngs_rcvdata;
115 static ng_disconnect_t ngs_disconnect;
117 /* Internal methods */
118 static int ng_attach_data(struct socket *so);
119 static int ng_attach_cntl(struct socket *so);
120 static int ng_attach_common(struct socket *so, int type);
121 static void ng_detach_common(struct ngpcb *pcbp, int type);
122 /*static int ng_internalize(struct mbuf *m, struct thread *p); */
124 static int ng_connect_data(struct sockaddr *nam, struct ngpcb *pcbp);
125 static int ng_bind(struct sockaddr *nam, struct ngpcb *pcbp);
127 static int ngs_mod_event(module_t mod, int event, void *data);
128 static int ship_msg(struct ngpcb *pcbp, struct ng_mesg *msg,
129 struct sockaddr_ng *addr);
131 /* Netgraph type descriptor */
132 static struct ng_type typestruct = {
146 NETGRAPH_INIT(socket, &typestruct);
149 static u_long ngpdg_sendspace = 20 * 1024; /* really max datagram size */
150 static u_long ngpdg_recvspace = 20 * 1024;
152 /* List of all sockets */
153 static LIST_HEAD(, ngpcb) ngsocklist;
155 #define sotongpcb(so) ((struct ngpcb *)(so)->so_pcb)
157 /* If getting unexplained errors returned, set this to "Debugger("X"); */
162 /***************************************************************
164 ***************************************************************/
167 ngc_attach(struct socket *so, int proto, struct thread *td)
169 struct ngpcb *const pcbp = sotongpcb(so);
175 return (ng_attach_cntl(so));
179 ngc_detach(struct socket *so)
181 struct ngpcb *const pcbp = sotongpcb(so);
185 ng_detach_common(pcbp, NG_CONTROL);
190 ngc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
191 struct mbuf *control, struct thread *td)
193 struct ngpcb *const pcbp = sotongpcb(so);
194 struct sockaddr_ng *const sap = (struct sockaddr_ng *) addr;
205 if (control && (error = ng_internalize(control, td))) {
206 if (pcbp->sockdata == NULL) {
218 /* Require destination as there may be >= 1 hooks on this node */
220 error = EDESTADDRREQ;
224 /* Allocate an expendable buffer for the path, chop off
225 * the sockaddr header, and make sure it's NUL terminated */
226 len = sap->sg_len - 2;
227 MALLOC(path, char *, len + 1, M_NETGRAPH_PATH, M_WAITOK);
232 bcopy(sap->sg_data, path, len);
235 /* Move the actual message out of mbufs into a linear buffer.
236 * Start by adding up the size of the data. (could use mh_len?) */
237 for (len = 0, m0 = m; m0 != NULL; m0 = m0->m_next)
240 /* Move the data into a linear buffer as well. Messages are not
241 * delivered in mbufs. */
242 MALLOC(msg, struct ng_mesg *, len + 1, M_NETGRAPH_MSG, M_WAITOK);
247 m_copydata(m, 0, len, (char *)msg);
249 #ifdef TRACE_MESSAGES
252 if ((item = ng_package_msg(msg)) == NULL) {
255 printf("err=%d\n",error);
258 if (((error) = ng_address_path((pcbp->sockdata->node), (item),
259 (path), (NULL))) == 0) {
260 printf("[%x]:<---------[socket]: c=<%d>cmd=%x(%s) f=%x #%d (%s)\n",
261 item->el_dest->nd_ID,
262 msg->header.typecookie,
267 item->el_dest->nd_type->name);
269 (error) = ng_snd_item((item), 0);
272 printf("errx=%d\n",error);
278 /* The callee will free the msg when done. The path is our business. */
279 NG_SEND_MSG_PATH(error, pcbp->sockdata->node, msg, path, NULL);
283 FREE(path, M_NETGRAPH_PATH);
292 ngc_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
294 struct ngpcb *const pcbp = sotongpcb(so);
298 return (ng_bind(nam, pcbp));
302 ngc_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
304 printf(" program tried to connect control socket to remote node\n ");
306 * At this time refuse to do this.. it used to
307 * do something but it was undocumented and not used.
312 /***************************************************************
314 ***************************************************************/
317 ngd_attach(struct socket *so, int proto, struct thread *td)
319 struct ngpcb *const pcbp = sotongpcb(so);
323 return (ng_attach_data(so));
327 ngd_detach(struct socket *so)
329 struct ngpcb *const pcbp = sotongpcb(so);
333 ng_detach_common(pcbp, NG_DATA);
338 ngd_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
339 struct mbuf *control, struct thread *td)
341 struct ngpcb *const pcbp = sotongpcb(so);
342 struct sockaddr_ng *const sap = (struct sockaddr_ng *) addr;
345 char hookname[NG_HOOKLEN + 1];
347 if ((pcbp == NULL) || (control != NULL)) {
351 if (pcbp->sockdata == NULL) {
356 * If the user used any of these ways to not specify an address
357 * then handle specially.
360 || ((len = sap->sg_len - 2) <= 0)
361 || (*sap->sg_data == '\0')) {
362 if (NG_NODE_NUMHOOKS(pcbp->sockdata->node) != 1) {
363 error = EDESTADDRREQ;
367 * if exactly one hook exists, just use it.
368 * Special case to allow write(2) to work on an ng_socket.
370 hook = LIST_FIRST(&pcbp->sockdata->node->nd_hooks);
372 if (len > NG_HOOKLEN) {
378 * chop off the sockaddr header, and make sure it's NUL
381 bcopy(sap->sg_data, hookname, len);
382 hookname[len] = '\0';
384 /* Find the correct hook from 'hookname' */
385 LIST_FOREACH(hook, &pcbp->sockdata->node->nd_hooks, hk_hooks) {
386 if (strcmp(hookname, NG_HOOK_NAME(hook)) == 0) {
391 error = EHOSTUNREACH;
395 /* Send data (OK if hook is NULL) */
396 NG_SEND_DATA_ONLY(error, hook, m); /* makes m NULL */
407 ngd_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
409 struct ngpcb *const pcbp = sotongpcb(so);
413 return (ng_connect_data(nam, pcbp));
417 * Used for both data and control sockets
420 ng_setsockaddr(struct socket *so, struct sockaddr **addr)
423 struct sockaddr_ng *sg;
424 int sg_len, namelen, s;
426 /* Why isn't sg_data a `char[1]' ? :-( */
427 sg_len = sizeof(struct sockaddr_ng) - sizeof(sg->sg_data) + 1;
430 pcbp = sotongpcb(so);
431 if ((pcbp == NULL) || (pcbp->sockdata == NULL)) {
436 namelen = 0; /* silence compiler ! */
437 if ( NG_NODE_HAS_NAME(pcbp->sockdata->node))
438 sg_len += namelen = strlen(NG_NODE_NAME(pcbp->sockdata->node));
440 MALLOC(sg, struct sockaddr_ng *, sg_len, M_SONAME, M_WAITOK | M_ZERO);
442 if (NG_NODE_HAS_NAME(pcbp->sockdata->node))
443 bcopy(NG_NODE_NAME(pcbp->sockdata->node), sg->sg_data, namelen);
447 sg->sg_family = AF_NETGRAPH;
448 *addr = (struct sockaddr *)sg;
454 * Attach a socket to it's protocol specific partner.
455 * For a control socket, actually create a netgraph node and attach
460 ng_attach_cntl(struct socket *so)
462 struct ngsock *privdata;
466 /* Setup protocol control block */
467 if ((error = ng_attach_common(so, NG_CONTROL)) != 0)
469 pcbp = sotongpcb(so);
471 /* Allocate node private info */
472 MALLOC(privdata, struct ngsock *,
473 sizeof(*privdata), M_NETGRAPH_SOCK, M_WAITOK | M_ZERO);
474 if (privdata == NULL) {
475 ng_detach_common(pcbp, NG_CONTROL);
479 /* Make the generic node components */
480 if ((error = ng_make_node_common(&typestruct, &privdata->node)) != 0) {
481 FREE(privdata, M_NETGRAPH_SOCK);
482 ng_detach_common(pcbp, NG_CONTROL);
485 NG_NODE_SET_PRIVATE(privdata->node, privdata);
487 /* Link the pcb and the node private data */
488 privdata->ctlsock = pcbp;
489 pcbp->sockdata = privdata;
495 ng_attach_data(struct socket *so)
497 return(ng_attach_common(so, NG_DATA));
501 * Set up a socket protocol control block.
502 * This code is shared between control and data sockets.
505 ng_attach_common(struct socket *so, int type)
510 /* Standard socket setup stuff */
511 error = soreserve(so, ngpdg_sendspace, ngpdg_recvspace);
515 /* Allocate the pcb */
516 MALLOC(pcbp, struct ngpcb *, sizeof(*pcbp), M_PCB, M_WAITOK | M_ZERO);
521 /* Link the pcb and the socket */
522 so->so_pcb = (caddr_t) pcbp;
523 pcbp->ng_socket = so;
525 /* Add the socket to linked list */
526 LIST_INSERT_HEAD(&ngsocklist, pcbp, socks);
531 * Disassociate the socket from it's protocol specific
532 * partner. If it's attached to a node's private data structure,
533 * then unlink from that too. If we were the last socket attached to it,
534 * then shut down the entire node. Shared code for control and data sockets.
537 ng_detach_common(struct ngpcb *pcbp, int which)
541 if (pcbp->sockdata) {
542 priv = pcbp->sockdata;
543 pcbp->sockdata = NULL;
546 priv->ctlsock = NULL;
549 priv->datasock = NULL;
554 if ((--priv->refs == 0) && (priv->node != NULL))
555 ng_rmnode_self(priv->node);
557 pcbp->ng_socket->so_pcb = NULL;
558 pcbp->ng_socket = NULL;
559 LIST_REMOVE(pcbp, socks);
565 * File descriptors can be passed into a AF_NETGRAPH socket.
566 * Note, that file descriptors cannot be passed OUT.
567 * Only character device descriptors are accepted.
568 * Character devices are useful to connect a graph to a device,
569 * which after all is the purpose of this whole system.
572 ng_internalize(struct mbuf *control, struct thread *td)
574 const struct cmsghdr *cm = mtod(control, const struct cmsghdr *);
580 if (cm->cmsg_type != SCM_RIGHTS || cm->cmsg_level != SOL_SOCKET ||
581 cm->cmsg_len != control->m_len) {
586 /* Check there is only one FD. XXX what would more than one signify? */
587 oldfds = ((caddr_t)cm + cm->cmsg_len - (caddr_t)data) / sizeof (int);
593 /* Check that the FD given is legit. and change it to a pointer to a
596 if ((error = fget(td, fd, &fp)) != 0)
599 /* Depending on what kind of resource it is, act differently. For
600 * devices, we treat it as a file. For a AF_NETGRAPH socket,
601 * shortcut straight to the node. */
602 switch (fp->f_type) {
604 vn = (struct vnode *) fp->f_data;
605 if (vn && (vn->v_type == VCHR)) {
606 /* for a VCHR, actually reference the FILE */
608 /* XXX then what :) */
609 /* how to pass on to other modules? */
627 * Connect the data socket to a named control socket node.
630 ng_connect_data(struct sockaddr *nam, struct ngpcb *pcbp)
632 struct sockaddr_ng *sap;
638 /* If we are already connected, don't do it again */
639 if (pcbp->sockdata != NULL)
642 /* Find the target (victim) and check it doesn't already have a data
643 * socket. Also check it is a 'socket' type node.
644 * Use ng_package_data() and address_path() to do this.
647 sap = (struct sockaddr_ng *) nam;
648 /* The item will hold the node reference */
649 item = ng_package_data(NULL, NULL);
653 if ((error = ng_address_path(NULL, item, sap->sg_data, NULL)))
654 return (error); /* item is freed on failure */
657 * Extract node from item and free item. Remember we now have
658 * a reference on the node. The item holds it for us.
659 * when we free the item we release the reference.
661 farnode = item->el_dest; /* shortcut */
662 if (strcmp(farnode->nd_type->name, NG_SOCKET_NODE_TYPE) != 0) {
663 NG_FREE_ITEM(item); /* drop the reference to the node */
666 priv = NG_NODE_PRIVATE(farnode);
667 if (priv->datasock != NULL) {
668 NG_FREE_ITEM(item); /* drop the reference to the node */
673 * Link the PCB and the private data struct. and note the extra
674 * reference. Drop the extra reference on the node.
676 priv->datasock = pcbp;
677 pcbp->sockdata = priv;
678 priv->refs++; /* XXX possible race if it's being freed */
679 NG_FREE_ITEM(item); /* drop the reference to the node */
684 * Binding a socket means giving the corresponding node a name
687 ng_bind(struct sockaddr *nam, struct ngpcb *pcbp)
689 struct ngsock *const priv = pcbp->sockdata;
690 struct sockaddr_ng *const sap = (struct sockaddr_ng *) nam;
696 if ((sap->sg_len < 4)
697 || (sap->sg_len > (NG_NODELEN + 3))
698 || (sap->sg_data[0] == '\0')
699 || (sap->sg_data[sap->sg_len - 3] != '\0')) {
703 return (ng_name_node(priv->node, sap->sg_data));
707 * Take a message and pass it up to the control socket associated
711 ship_msg(struct ngpcb *pcbp, struct ng_mesg *msg, struct sockaddr_ng *addr)
713 struct socket *const so = pcbp->ng_socket;
717 /* Copy the message itself into an mbuf chain */
718 msglen = sizeof(struct ng_mesg) + msg->header.arglen;
719 mdata = m_devget((caddr_t) msg, msglen, 0, NULL, NULL);
721 /* Here we free the message, as we are the end of the line.
722 * We need to do that regardless of whether we got mbufs. */
730 /* Send it up to the socket */
731 if (sbappendaddr(&so->so_rcv,
732 (struct sockaddr *) addr, mdata, NULL) == 0) {
742 * You can only create new nodes from the socket end of things.
745 ngs_constructor(node_p nodep)
751 * We allow any hook to be connected to the node.
752 * There is no per-hook private information though.
755 ngs_newhook(node_p node, hook_p hook, const char *name)
757 NG_HOOK_SET_PRIVATE(hook, NG_NODE_PRIVATE(node));
762 * if only one hook, allow read(2) and write(2) to work.
765 ngs_connect(hook_p hook)
767 node_p node = NG_HOOK_NODE(hook);
768 struct ngsock *priv = NG_NODE_PRIVATE(node);
771 && (priv->datasock->ng_socket)) {
772 if (NG_NODE_NUMHOOKS(node) == 1) {
773 priv->datasock->ng_socket->so_state |= SS_ISCONNECTED;
775 priv->datasock->ng_socket->so_state &= ~SS_ISCONNECTED;
782 * Incoming messages get passed up to the control socket.
783 * Unless they are for us specifically (socket_type)
786 ngs_rcvmsg(node_p node, item_p item, hook_p lasthook)
788 struct ngsock *const priv = NG_NODE_PRIVATE(node);
789 struct ngpcb *const pcbp = priv->ctlsock;
790 struct sockaddr_ng *addr;
794 ng_ID_t retaddr = NGI_RETADDR(item);
797 NGI_GET_MSG(item, msg);
798 NG_FREE_ITEM(item); /* we have all we need */
800 /* Only allow mesgs to be passed if we have the control socket.
801 * Data sockets can only support the generic messages. */
806 #ifdef TRACE_MESSAGES
807 printf("[%x]:---------->[socket]: c=<%d>cmd=%x(%s) f=%x #%d\n",
809 msg->header.typecookie,
817 if (msg->header.typecookie == NGM_SOCKET_COOKIE) {
818 switch (msg->header.cmd) {
819 case NGM_SOCK_CMD_NOLINGER:
820 priv->flags |= NGS_FLAG_NOLINGER;
822 case NGM_SOCK_CMD_LINGER:
823 priv->flags &= ~NGS_FLAG_NOLINGER;
826 error = EINVAL; /* unknown command */
828 /* Free the message and return */
833 /* Get the return address into a sockaddr */
834 sprintf(retabuf,"[%x]:", retaddr);
835 addrlen = strlen(retabuf);
836 MALLOC(addr, struct sockaddr_ng *, addrlen + 4, M_NETGRAPH_PATH, M_NOWAIT);
841 addr->sg_len = addrlen + 3;
842 addr->sg_family = AF_NETGRAPH;
843 bcopy(retabuf, addr->sg_data, addrlen);
844 addr->sg_data[addrlen] = '\0';
847 error = ship_msg(pcbp, msg, addr);
848 FREE(addr, M_NETGRAPH_PATH);
853 * Receive data on a hook
856 ngs_rcvdata(hook_p hook, item_p item)
858 struct ngsock *const priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
859 struct ngpcb *const pcbp = priv->datasock;
861 struct sockaddr_ng *addr;
862 char *addrbuf[NG_HOOKLEN + 1 + 4];
868 /* If there is no data socket, black-hole it */
873 so = pcbp->ng_socket;
875 /* Get the return address into a sockaddr. */
876 addrlen = strlen(NG_HOOK_NAME(hook)); /* <= NG_HOOKLEN */
877 addr = (struct sockaddr_ng *) addrbuf;
878 addr->sg_len = addrlen + 3;
879 addr->sg_family = AF_NETGRAPH;
880 bcopy(NG_HOOK_NAME(hook), addr->sg_data, addrlen);
881 addr->sg_data[addrlen] = '\0';
883 /* Try to tell the socket which hook it came in on */
884 if (sbappendaddr(&so->so_rcv, (struct sockaddr *) addr, m, NULL) == 0) {
896 * For this type, removal of the last link destroys the node
897 * if the NOLINGER flag is set.
900 ngs_disconnect(hook_p hook)
902 node_p node = NG_HOOK_NODE(hook);
903 struct ngsock *const priv = NG_NODE_PRIVATE(node);
906 && (priv->datasock->ng_socket)) {
907 if (NG_NODE_NUMHOOKS(node) == 1) {
908 priv->datasock->ng_socket->so_state |= SS_ISCONNECTED;
910 priv->datasock->ng_socket->so_state &= ~SS_ISCONNECTED;
914 if ((priv->flags & NGS_FLAG_NOLINGER )
915 && (NG_NODE_NUMHOOKS(node) == 0)
916 && (NG_NODE_IS_VALID(node))) {
917 ng_rmnode_self(node);
923 * Do local shutdown processing.
924 * In this case, that involves making sure the socket
925 * knows we should be shutting down.
928 ngs_shutdown(node_p node)
930 struct ngsock *const priv = NG_NODE_PRIVATE(node);
931 struct ngpcb *const dpcbp = priv->datasock;
932 struct ngpcb *const pcbp = priv->ctlsock;
935 soisdisconnected(dpcbp->ng_socket);
936 dpcbp->sockdata = NULL;
937 priv->datasock = NULL;
941 soisdisconnected(pcbp->ng_socket);
942 pcbp->sockdata = NULL;
943 priv->ctlsock = NULL;
946 NG_NODE_SET_PRIVATE(node, NULL);
948 FREE(priv, M_NETGRAPH_SOCK);
953 dummy_disconnect(struct socket *so)
958 * Control and data socket type descriptors
961 static struct pr_usrreqs ngc_usrreqs = {
967 pru_connect2_notsupp,
970 dummy_disconnect, /* disconnect */
972 NULL, /* setpeeraddr */
984 static struct pr_usrreqs ngd_usrreqs = {
990 pru_connect2_notsupp,
993 dummy_disconnect, /* disconnect */
995 NULL, /* setpeeraddr */
1000 NULL, /* shutdown */
1008 * Definitions of protocols supported in the NETGRAPH domain.
1011 extern struct domain ngdomain; /* stop compiler warnings */
1013 static struct protosw ngsw[] = {
1015 SOCK_DGRAM, /* protocol type */
1016 &ngdomain, /* backpointer to domain */
1018 PR_ATOMIC | PR_ADDR /* | PR_RIGHTS */, /* flags */
1019 0, 0, 0, 0, /* input, output, ctlinput, ctloutput */
1021 0, 0, 0, 0, /* init, fasttimeo, slowtimo, drain */
1022 &ngc_usrreqs, /* usrreq table (above) */
1023 /*{NULL}*/ /* pffh (protocol filter head?) */
1026 SOCK_DGRAM, /* protocol type */
1027 &ngdomain, /* backpointer to domain */
1029 PR_ATOMIC | PR_ADDR, /* flags */
1030 0, 0, 0, 0, /* input, output, ctlinput, ctloutput */
1031 NULL, /* ousrreq() */
1032 0, 0, 0, 0, /* init, fasttimeo, slowtimo, drain */
1033 &ngd_usrreqs, /* usrreq table (above) */
1034 /*{NULL}*/ /* pffh (protocol filter head?) */
1038 struct domain ngdomain = {
1042 NULL, /* externalise() */
1043 NULL, /* dispose() */
1044 ngsw, /* protosw entry */
1045 &ngsw[sizeof(ngsw) / sizeof(ngsw[0])], /* Number of protosw entries */
1046 NULL, /* next domain in list */
1047 NULL, /* rtattach() */
1048 0, /* arg to rtattach in bits */
1053 * Handle loading and unloading for this node type
1054 * This is to handle auxiliary linkages (e.g protocol domain addition).
1057 ngs_mod_event(module_t mod, int event, void *data)
1063 /* Register protocol domain */
1064 net_add_domain(&ngdomain);
1067 /* Insure there are no open netgraph sockets */
1068 if (!LIST_EMPTY(&ngsocklist)) {
1074 if ((LIST_EMPTY(&ngsocklist)) && (typestruct.refs == 0)) {
1075 /* Unregister protocol domain XXX can't do this yet.. */
1076 if ((error = net_rm_domain(&ngdomain)) != 0)
1089 SYSCTL_INT(_net_graph, OID_AUTO, family, CTLFLAG_RD, 0, AF_NETGRAPH, "");
1090 SYSCTL_NODE(_net_graph, OID_AUTO, data, CTLFLAG_RW, 0, "DATA");
1091 SYSCTL_INT(_net_graph_data, OID_AUTO, proto, CTLFLAG_RD, 0, NG_DATA, "");
1092 SYSCTL_NODE(_net_graph, OID_AUTO, control, CTLFLAG_RW, 0, "CONTROL");
1093 SYSCTL_INT(_net_graph_control, OID_AUTO, proto, CTLFLAG_RD, 0, NG_CONTROL, "");