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>
39 * $FreeBSD: src/sys/netgraph/ng_socket.c,v 1.11.2.6 2002/07/02 22:17:18 archie Exp $
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>
55 #include <sys/domain.h>
56 #include <sys/errno.h>
57 #include <sys/kernel.h>
58 #include <sys/filedesc.h>
59 #include <sys/malloc.h>
60 #include <sys/queue.h>
62 #include <sys/protosw.h>
63 #include <sys/socket.h>
64 #include <sys/socketvar.h>
65 #include <sys/sysctl.h>
67 #include <sys/vnode.h>
70 #include <sys/thread2.h>
71 #include <sys/socketvar2.h>
72 #include <sys/msgport2.h>
74 #include <netgraph/ng_message.h>
75 #include <netgraph/netgraph.h>
76 #include "ng_socketvar.h"
77 #include "ng_socket.h"
80 * It's Ascii-art time!
81 * +-------------+ +-------------+
82 * |socket (ctl)| |socket (data)|
83 * +-------------+ +-------------+
87 * +-----------+ +-----------+
88 * |pcb (ctl)| |pcb (data)|
89 * +-----------+ +-----------+
93 * +--------------------------+
94 * | Socket type private |
96 * +--------------------------+
105 /* Netgraph node methods */
106 static ng_constructor_t ngs_constructor;
107 static ng_rcvmsg_t ngs_rcvmsg;
108 static ng_shutdown_t ngs_rmnode;
109 static ng_newhook_t ngs_newhook;
110 static ng_rcvdata_t ngs_rcvdata;
111 static ng_disconnect_t ngs_disconnect;
113 /* Internal methods */
114 static int ng_attach_data(struct socket *so);
115 static int ng_attach_cntl(struct socket *so);
116 static int ng_attach_common(struct socket *so, int type);
117 static void ng_detach_common(struct ngpcb *pcbp, int type);
118 /*static int ng_internalize(struct mbuf *m, struct thread *td); */
120 static int ng_connect_data(struct sockaddr *nam, struct ngpcb *pcbp);
121 static int ng_connect_cntl(struct sockaddr *nam, struct ngpcb *pcbp);
122 static int ng_bind(struct sockaddr *nam, struct ngpcb *pcbp);
124 static int ngs_mod_event(module_t mod, int event, void *data);
125 static int ship_msg(struct ngpcb *pcbp, struct ng_mesg *msg,
126 struct sockaddr_ng *addr);
128 /* Netgraph type descriptor */
129 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 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(netmsg_t msg)
167 struct socket *so = msg->attach.base.nm_so;
168 struct pru_attach_info *ai = msg->attach.nm_ai;
169 struct ngpcb *const pcbp = sotongpcb(so);
172 if (priv_check_cred(ai->p_ucred, PRIV_ROOT, NULL_CRED_OKAY) != 0)
174 else if (pcbp != NULL)
177 error = ng_attach_cntl(so);
178 lwkt_replymsg(&msg->attach.base.lmsg, error);
182 ngc_detach(netmsg_t msg)
184 struct socket *so = msg->detach.base.nm_so;
185 struct ngpcb *const pcbp = sotongpcb(so);
189 ng_detach_common(pcbp, NG_CONTROL);
194 lwkt_replymsg(&msg->detach.base.lmsg, error);
198 ngc_send(netmsg_t msg)
200 struct socket *so = msg->send.base.nm_so;
201 struct mbuf *m = msg->send.nm_m;
202 struct sockaddr *addr = msg->send.nm_addr;
203 struct mbuf *control = msg->send.nm_control;
204 struct ngpcb *const pcbp = sotongpcb(so);
205 struct sockaddr_ng *const sap = (struct sockaddr_ng *) addr;
206 struct ng_mesg *resp;
208 char *xmsg, *path = NULL;
217 if (control && (error = ng_internalize(control, p))) {
218 if (pcbp->sockdata == NULL) {
230 /* Require destination as there may be >= 1 hooks on this node */
232 error = EDESTADDRREQ;
236 /* Allocate an expendable buffer for the path, chop off
237 * the sockaddr header, and make sure it's NUL terminated */
238 len = sap->sg_len - 2;
239 path = kmalloc(len + 1, M_NETGRAPH, M_WAITOK);
240 bcopy(sap->sg_data, path, len);
243 /* Move the actual message out of mbufs into a linear buffer.
244 * Start by adding up the size of the data. (could use mh_len?) */
245 for (len = 0, m0 = m; m0 != NULL; m0 = m0->m_next)
248 /* Move the data into a linear buffer as well. Messages are not
249 * delivered in mbufs. */
250 xmsg = kmalloc(len + 1, M_NETGRAPH, M_WAITOK);
251 m_copydata(m, 0, len, xmsg);
253 /* The callee will free the xmsg when done. The addr is our business. */
254 error = ng_send_msg(pcbp->sockdata->node,
255 (struct ng_mesg *) xmsg, path, &resp);
257 /* If the callee responded with a synchronous response, then put it
258 * back on the receive side of the socket; sap is source address. */
259 if (error == 0 && resp != NULL)
260 error = ship_msg(pcbp, resp, sap);
264 kfree(path, M_NETGRAPH);
269 lwkt_replymsg(&msg->send.base.lmsg, error);
273 ngc_bind(netmsg_t msg)
275 struct socket *so = msg->bind.base.nm_so;
276 struct sockaddr *nam = msg->bind.nm_nam;
277 struct ngpcb *const pcbp = sotongpcb(so);
281 error = ng_bind(nam, pcbp);
284 lwkt_replymsg(&msg->bind.base.lmsg, error);
288 ngc_connect(netmsg_t msg)
290 struct socket *so = msg->connect.base.nm_so;
291 struct sockaddr *nam = msg->connect.nm_nam;
292 struct ngpcb *const pcbp = sotongpcb(so);
296 error = ng_connect_cntl(nam, pcbp);
299 lwkt_replymsg(&msg->connect.base.lmsg, error);
302 /***************************************************************
304 ***************************************************************/
307 ngd_attach(netmsg_t msg)
309 struct socket *so = msg->attach.base.nm_so;
310 struct ngpcb *const pcbp = sotongpcb(so);
316 error = ng_attach_data(so);
317 lwkt_replymsg(&msg->connect.base.lmsg, error);
321 ngd_detach(netmsg_t msg)
323 struct socket *so = msg->detach.base.nm_so;
324 struct ngpcb *const pcbp = sotongpcb(so);
328 ng_detach_common(pcbp, NG_DATA);
333 lwkt_replymsg(&msg->detach.base.lmsg, error);
337 ngd_send(netmsg_t msg)
339 struct socket *so = msg->send.base.nm_so;
340 struct mbuf *m = msg->send.nm_m;
341 struct sockaddr *addr = msg->send.nm_addr;
342 struct mbuf *control = msg->send.nm_control;
343 struct ngpcb *const pcbp = sotongpcb(so);
344 struct sockaddr_ng *const sap = (struct sockaddr_ng *) addr;
348 char hookname[NG_HOOKSIZ];
350 if ((pcbp == NULL) || (control != NULL)) {
354 if (pcbp->sockdata == NULL) {
359 * If the user used any of these ways to not specify an address
360 * then handle specially.
363 || ((len = sap->sg_len - 2) <= 0)
364 || (*sap->sg_data == '\0')) {
365 if (pcbp->sockdata->node->numhooks != 1) {
366 error = EDESTADDRREQ;
370 * if exactly one hook exists, just use it.
371 * Special case to allow write(2) to work on an ng_socket.
373 hook = LIST_FIRST(&pcbp->sockdata->node->hooks);
375 if (len >= NG_HOOKSIZ) {
381 * chop off the sockaddr header, and make sure it's NUL
384 bcopy(sap->sg_data, hookname, len);
385 hookname[len] = '\0';
387 /* Find the correct hook from 'hookname' */
388 LIST_FOREACH(hook, &pcbp->sockdata->node->hooks, hooks) {
389 if (strcmp(hookname, hook->name) == 0)
393 error = EHOSTUNREACH;
396 /* Send data (OK if hook is NULL) */
397 NG_SEND_DATA(error, hook, m, mp); /* makes m NULL */
404 lwkt_replymsg(&msg->send.base.lmsg, error);
408 ngd_connect(netmsg_t msg)
410 struct socket *so = msg->connect.base.nm_so;
411 struct sockaddr *nam = msg->connect.nm_nam;
412 struct ngpcb *const pcbp = sotongpcb(so);
416 error = ng_connect_data(nam, pcbp);
420 lwkt_replymsg(&msg->connect.base.lmsg, error);
424 * Used for both data and control sockets
427 ng_setsockaddr(netmsg_t msg)
429 struct socket *so = msg->sockaddr.base.nm_so;
430 struct sockaddr **addr = msg->sockaddr.nm_nam;
432 struct sockaddr_ng *sg;
436 /* Why isn't sg_data a `char[1]' ? :-( */
437 sg_len = sizeof(struct sockaddr_ng) - sizeof(sg->sg_data) + 1;
440 pcbp = sotongpcb(so);
441 if ((pcbp == 0) || (pcbp->sockdata == NULL)) {
447 namelen = 0; /* silence compiler ! */
449 if (pcbp->sockdata->node->name != NULL)
450 sg_len += namelen = strlen(pcbp->sockdata->node->name);
452 sg = kmalloc(sg_len, M_SONAME, M_WAITOK | M_ZERO);
454 if (pcbp->sockdata->node->name != NULL)
455 bcopy(pcbp->sockdata->node->name, sg->sg_data, namelen);
459 sg->sg_family = AF_NETGRAPH;
460 *addr = (struct sockaddr *)sg;
463 lwkt_replymsg(&msg->sockaddr.base.lmsg, error);
467 * Attach a socket to it's protocol specific partner.
468 * For a control socket, actually create a netgraph node and attach
473 ng_attach_cntl(struct socket *so)
475 struct ngsock *privdata;
479 /* Setup protocol control block */
480 if ((error = ng_attach_common(so, NG_CONTROL)) != 0)
482 pcbp = sotongpcb(so);
484 /* Allocate node private info */
485 privdata = kmalloc(sizeof(*privdata), M_NETGRAPH, M_WAITOK | M_ZERO);
487 /* Make the generic node components */
488 if ((error = ng_make_node_common(&typestruct, &privdata->node)) != 0) {
489 kfree(privdata, M_NETGRAPH);
490 ng_detach_common(pcbp, NG_CONTROL);
493 privdata->node->private = privdata;
495 /* Link the pcb and the node private data */
496 privdata->ctlsock = pcbp;
497 pcbp->sockdata = privdata;
503 ng_attach_data(struct socket *so)
505 return(ng_attach_common(so, NG_DATA));
509 * Set up a socket protocol control block.
510 * This code is shared between control and data sockets.
513 ng_attach_common(struct socket *so, int type)
518 /* Standard socket setup stuff */
519 error = soreserve(so, ngpdg_sendspace, ngpdg_recvspace, NULL);
523 /* Allocate the pcb */
524 pcbp = kmalloc(sizeof(*pcbp), M_PCB, M_WAITOK | M_ZERO);
527 /* Link the pcb and the socket */
529 so->so_pcb = (caddr_t) pcbp;
530 pcbp->ng_socket = so;
532 /* Add the socket to linked list */
533 LIST_INSERT_HEAD(&ngsocklist, pcbp, socks);
538 * Disassociate the socket from it's protocol specific
539 * partner. If it's attached to a node's private data structure,
540 * then unlink from that too. If we were the last socket attached to it,
541 * then shut down the entire node. Shared code for control and data sockets.
544 ng_detach_common(struct ngpcb *pcbp, int which)
546 struct ngsock *sockdata;
549 if (pcbp->sockdata) {
550 sockdata = pcbp->sockdata;
551 pcbp->sockdata = NULL;
554 sockdata->ctlsock = NULL;
557 sockdata->datasock = NULL;
562 if ((--sockdata->refs == 0) && (sockdata->node != NULL))
563 ng_rmnode(sockdata->node);
565 so = pcbp->ng_socket;
567 pcbp->ng_socket = NULL;
568 sofree(so); /* remove pcb ref */
570 LIST_REMOVE(pcbp, socks);
576 * File descriptors can be passed into a AF_NETGRAPH socket.
577 * Note, that file descriptors cannot be passed OUT.
578 * Only character device descriptors are accepted.
579 * Character devices are useful to connect a graph to a device,
580 * which after all is the purpose of this whole system.
583 ng_internalize(struct mbuf *control, struct thread *td)
585 struct filedesc *fdp = p->p_fd;
586 const struct cmsghdr *cm = mtod(control, const struct cmsghdr *);
592 if (cm->cmsg_type != SCM_RIGHTS || cm->cmsg_level != SOL_SOCKET ||
593 cm->cmsg_len != control->m_len) {
598 /* Check there is only one FD. XXX what would more than one signify? */
599 oldfds = (cm->cmsg_len - sizeof(*cm)) / sizeof(int);
605 /* Check that the FD given is legit. and change it to a pointer to a
607 fd = *(int *) (cm + 1);
608 if ((unsigned) fd >= fdp->fd_nfiles
609 || (fp = fdp->fd_files[fd].fp) == NULL) {
613 /* Depending on what kind of resource it is, act differently. For
614 * devices, we treat it as a file. For a AF_NETGRAPH socket,
615 * shortcut straight to the node. */
616 switch (fp->f_type) {
618 vn = (struct vnode *) fp->f_data;
619 if (vn && (vn->v_type == VCHR)) {
620 /* for a VCHR, actually reference the FILE */
622 /* XXX then what :) */
623 /* how to pass on to other modules? */
638 * Connect the data socket to a named control socket node.
641 ng_connect_data(struct sockaddr *nam, struct ngpcb *pcbp)
643 struct sockaddr_ng *sap;
645 struct ngsock *sockdata;
648 /* If we are already connected, don't do it again */
649 if (pcbp->sockdata != NULL)
652 /* Find the target (victim) and check it doesn't already have a data
653 * socket. Also check it is a 'socket' type node. */
654 sap = (struct sockaddr_ng *) nam;
655 if ((error = ng_path2node(NULL, sap->sg_data, &farnode, NULL)))
658 if (strcmp(farnode->type->name, NG_SOCKET_NODE_TYPE) != 0)
660 sockdata = farnode->private;
661 if (sockdata->datasock != NULL)
664 /* Link the PCB and the private data struct. and note the extra
666 sockdata->datasock = pcbp;
667 pcbp->sockdata = sockdata;
673 * Connect the existing control socket node to a named node:hook.
674 * The hook we use on this end is the same name as the remote node name.
677 ng_connect_cntl(struct sockaddr *nam, struct ngpcb *pcbp)
679 struct ngsock *const sockdata = pcbp->sockdata;
680 struct sockaddr_ng *sap;
685 sap = (struct sockaddr_ng *) nam;
686 rtn = ng_path_parse(sap->sg_data, &node, NULL, &hook);
687 if (rtn < 0 || node == NULL || hook == NULL) {
691 farnode = ng_findname(sockdata->node, node);
692 if (farnode == NULL) {
694 return (EADDRNOTAVAIL);
697 /* Connect, using a hook name the same as the far node name. */
698 error = ng_con_nodes(sockdata->node, node, farnode, hook);
703 * Binding a socket means giving the corresponding node a name
706 ng_bind(struct sockaddr *nam, struct ngpcb *pcbp)
708 struct ngsock *const sockdata = pcbp->sockdata;
709 struct sockaddr_ng *const sap = (struct sockaddr_ng *) nam;
711 if (sockdata == NULL) {
715 if (sap->sg_len < 3 || sap->sg_data[sap->sg_len - 3] != '\0') {
719 return (ng_name_node(sockdata->node, sap->sg_data));
723 * Take a message and pass it up to the control socket associated
727 ship_msg(struct ngpcb *pcbp, struct ng_mesg *msg, struct sockaddr_ng *addr)
729 struct socket *const so = pcbp->ng_socket;
733 /* Copy the message itself into an mbuf chain */
734 msglen = sizeof(struct ng_mesg) + msg->header.arglen;
735 mdata = m_devget((caddr_t) msg, msglen, 0, NULL, NULL);
737 /* Here we free the message, as we are the end of the line.
738 * We need to do that regardless of whether we got mbufs. */
739 kfree(msg, M_NETGRAPH);
746 /* Send it up to the socket */
747 lwkt_gettoken(&so->so_rcv.ssb_token);
748 if (ssb_appendaddr(&so->so_rcv,
749 (struct sockaddr *) addr, mdata, NULL) == 0) {
750 lwkt_reltoken(&so->so_rcv.ssb_token);
756 lwkt_reltoken(&so->so_rcv.ssb_token);
761 * You can only create new nodes from the socket end of things.
764 ngs_constructor(node_p *nodep)
770 * We allow any hook to be connected to the node.
771 * There is no per-hook private information though.
774 ngs_newhook(node_p node, hook_p hook, const char *name)
776 hook->private = node->private;
781 * Incoming messages get passed up to the control socket.
782 * Unless they are for us specifically (socket_type)
785 ngs_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr,
786 struct ng_mesg **resp)
788 struct ngsock *const sockdata = node->private;
789 struct ngpcb *const pcbp = sockdata->ctlsock;
790 struct sockaddr_ng *addr;
794 /* Only allow mesgs to be passed if we have the control socket.
795 * Data sockets can only support the generic messages. */
801 if (msg->header.typecookie == NGM_SOCKET_COOKIE) {
802 switch (msg->header.cmd) {
803 case NGM_SOCK_CMD_NOLINGER:
804 sockdata->flags |= NGS_FLAG_NOLINGER;
806 case NGM_SOCK_CMD_LINGER:
807 sockdata->flags &= ~NGS_FLAG_NOLINGER;
810 error = EINVAL; /* unknown command */
812 /* Free the message and return */
813 kfree(msg, M_NETGRAPH);
817 /* Get the return address into a sockaddr */
818 if ((retaddr == NULL) || (*retaddr == '\0'))
820 addrlen = strlen(retaddr);
821 addr = kmalloc(addrlen + 4, M_NETGRAPH, M_NOWAIT);
826 addr->sg_len = addrlen + 3;
827 addr->sg_family = AF_NETGRAPH;
828 bcopy(retaddr, addr->sg_data, addrlen);
829 addr->sg_data[addrlen] = '\0';
832 error = ship_msg(pcbp, msg, addr);
833 kfree(addr, M_NETGRAPH);
838 * Receive data on a hook
841 ngs_rcvdata(hook_p hook, struct mbuf *m, meta_p meta)
843 struct ngsock *const sockdata = hook->node->private;
844 struct ngpcb *const pcbp = sockdata->datasock;
846 struct sockaddr_ng *addr;
847 char *addrbuf[NG_HOOKSIZ + 4];
850 /* If there is no data socket, black-hole it */
852 NG_FREE_DATA(m, meta);
855 so = pcbp->ng_socket;
857 /* Get the return address into a sockaddr. */
858 addrlen = strlen(hook->name); /* <= NG_HOOKSIZ - 1 */
859 addr = (struct sockaddr_ng *) addrbuf;
860 addr->sg_len = addrlen + 3;
861 addr->sg_family = AF_NETGRAPH;
862 bcopy(hook->name, addr->sg_data, addrlen);
863 addr->sg_data[addrlen] = '\0';
865 /* We have no use for the meta data, free/clear it now. */
868 /* Try to tell the socket which hook it came in on */
869 lwkt_gettoken(&so->so_rcv.ssb_token);
870 if (ssb_appendaddr(&so->so_rcv, (struct sockaddr *) addr, m, NULL) == 0) {
871 lwkt_reltoken(&so->so_rcv.ssb_token);
877 lwkt_reltoken(&so->so_rcv.ssb_token);
884 * For this type, removal of the last link destroys the node
885 * if the NOLINGER flag is set.
888 ngs_disconnect(hook_p hook)
890 struct ngsock *const sockdata = hook->node->private;
892 if ((sockdata->flags & NGS_FLAG_NOLINGER )
893 && (hook->node->numhooks == 0)) {
894 ng_rmnode(hook->node);
900 * Do local shutdown processing.
901 * In this case, that involves making sure the socket
902 * knows we should be shutting down.
905 ngs_rmnode(node_p node)
907 struct ngsock *const sockdata = node->private;
908 struct ngpcb *const dpcbp = sockdata->datasock;
909 struct ngpcb *const pcbp = sockdata->ctlsock;
915 soisdisconnected(dpcbp->ng_socket);
916 dpcbp->sockdata = NULL;
917 sockdata->datasock = NULL;
921 soisdisconnected(pcbp->ng_socket);
922 pcbp->sockdata = NULL;
923 sockdata->ctlsock = NULL;
926 node->private = NULL;
928 kfree(sockdata, M_NETGRAPH);
933 * Control and data socket type descriptors
936 static struct pr_usrreqs ngc_usrreqs = {
938 .pru_accept = pr_generic_notsupp,
939 .pru_attach = ngc_attach,
940 .pru_bind = ngc_bind,
941 .pru_connect = ngc_connect,
942 .pru_connect2 = pr_generic_notsupp,
943 .pru_control = pr_generic_notsupp,
944 .pru_detach = ngc_detach,
945 .pru_disconnect = NULL,
946 .pru_listen = pr_generic_notsupp,
947 .pru_peeraddr = NULL,
948 .pru_rcvd = pr_generic_notsupp,
949 .pru_rcvoob = pr_generic_notsupp,
950 .pru_send = ngc_send,
951 .pru_sense = pru_sense_null,
952 .pru_shutdown = NULL,
953 .pru_sockaddr = ng_setsockaddr,
954 .pru_sosend = sosend,
955 .pru_soreceive = soreceive
958 static struct pr_usrreqs ngd_usrreqs = {
960 .pru_accept = pr_generic_notsupp,
961 .pru_attach = ngd_attach,
963 .pru_connect = ngd_connect,
964 .pru_connect2 = pr_generic_notsupp,
965 .pru_control = pr_generic_notsupp,
966 .pru_detach = ngd_detach,
967 .pru_disconnect = NULL,
968 .pru_listen = pr_generic_notsupp,
969 .pru_peeraddr = NULL,
970 .pru_rcvd = pr_generic_notsupp,
971 .pru_rcvoob = pr_generic_notsupp,
972 .pru_send = ngd_send,
973 .pru_sense = pru_sense_null,
974 .pru_shutdown = NULL,
975 .pru_sockaddr = ng_setsockaddr,
976 .pru_sosend = sosend,
977 .pru_soreceive = soreceive
981 * Definitions of protocols supported in the NETGRAPH domain.
984 extern struct domain ngdomain; /* stop compiler warnings */
986 static struct protosw ngsw[] = {
988 .pr_type = SOCK_DGRAM,
989 .pr_domain = &ngdomain,
990 .pr_protocol = NG_CONTROL,
991 .pr_flags = PR_ATOMIC | PR_ADDR /* | PR_RIGHTS */,
992 .pr_usrreqs = &ngc_usrreqs
995 .pr_type = SOCK_DGRAM,
996 .pr_domain = &ngdomain,
997 .pr_protocol = NG_DATA,
998 .pr_flags = PR_ATOMIC | PR_ADDR,
999 .pr_usrreqs = &ngd_usrreqs
1003 struct domain ngdomain = {
1004 AF_NETGRAPH, "netgraph", NULL, NULL, NULL,
1005 ngsw, &ngsw[NELEM(ngsw)],
1009 * Handle loading and unloading for this node type
1010 * This is to handle auxiliary linkages (e.g protocol domain addition).
1013 ngs_mod_event(module_t mod, int event, void *data)
1019 /* Register protocol domain */
1020 net_add_domain(&ngdomain);
1023 /* Insure there are no open netgraph sockets */
1024 if (!LIST_EMPTY(&ngsocklist)) {
1030 /* Unregister protocol domain XXX can't do this yet.. */
1031 if ((error = net_rm_domain(&ngdomain)) != 0)
1044 SYSCTL_INT(_net_graph, OID_AUTO, family, CTLFLAG_RD, 0, AF_NETGRAPH, "");
1045 SYSCTL_NODE(_net_graph, OID_AUTO, data, CTLFLAG_RW, 0, "DATA");
1046 SYSCTL_INT(_net_graph_data, OID_AUTO, proto, CTLFLAG_RD, 0, NG_DATA, "");
1047 SYSCTL_NODE(_net_graph, OID_AUTO, control, CTLFLAG_RW, 0, "CONTROL");
1048 SYSCTL_INT(_net_graph_control, OID_AUTO, proto, CTLFLAG_RD, 0, NG_CONTROL, "");