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 * $DragonFly: src/sys/netgraph/socket/ng_socket.c,v 1.17 2008/11/01 04:22:15 sephe Exp $
41 * $Whistle: ng_socket.c,v 1.28 1999/11/01 09:24:52 julian Exp $
45 * Netgraph socket nodes
47 * There are two types of netgraph sockets, control and data.
48 * Control sockets have a netgraph node, but data sockets are
49 * parasitic on control sockets, and have no node of their own.
52 #include <sys/param.h>
53 #include <sys/systm.h>
56 #include <sys/domain.h>
57 #include <sys/errno.h>
58 #include <sys/kernel.h>
59 #include <sys/filedesc.h>
60 #include <sys/malloc.h>
61 #include <sys/queue.h>
63 #include <sys/protosw.h>
64 #include <sys/socket.h>
65 #include <sys/socketvar.h>
66 #include <sys/sysctl.h>
68 #include <sys/vnode.h>
71 #include <sys/thread2.h>
72 #include <sys/socketvar2.h>
73 #include <sys/msgport2.h>
75 #include <netgraph/ng_message.h>
76 #include <netgraph/netgraph.h>
77 #include "ng_socketvar.h"
78 #include "ng_socket.h"
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_rmnode;
110 static ng_newhook_t ngs_newhook;
111 static ng_rcvdata_t ngs_rcvdata;
112 static ng_disconnect_t ngs_disconnect;
114 /* Internal methods */
115 static int ng_attach_data(struct socket *so);
116 static int ng_attach_cntl(struct socket *so);
117 static int ng_attach_common(struct socket *so, int type);
118 static void ng_detach_common(struct ngpcb *pcbp, int type);
119 /*static int ng_internalize(struct mbuf *m, struct thread *td); */
121 static int ng_connect_data(struct sockaddr *nam, struct ngpcb *pcbp);
122 static int ng_connect_cntl(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 = {
145 NETGRAPH_INIT(socket, &typestruct);
148 static u_long ngpdg_sendspace = 20 * 1024; /* really max datagram size */
149 static u_long ngpdg_recvspace = 20 * 1024;
151 /* List of all sockets */
152 LIST_HEAD(, ngpcb) ngsocklist;
154 #define sotongpcb(so) ((struct ngpcb *)(so)->so_pcb)
156 /* If getting unexplained errors returned, set this to "Debugger("X"); */
161 /***************************************************************
163 ***************************************************************/
166 ngc_attach(netmsg_t msg)
168 struct socket *so = msg->attach.base.nm_so;
169 struct pru_attach_info *ai = msg->attach.nm_ai;
170 struct ngpcb *const pcbp = sotongpcb(so);
173 if (priv_check_cred(ai->p_ucred, PRIV_ROOT, NULL_CRED_OKAY) != 0)
175 else if (pcbp != NULL)
178 error = ng_attach_cntl(so);
179 lwkt_replymsg(&msg->attach.base.lmsg, error);
183 ngc_detach(netmsg_t msg)
185 struct socket *so = msg->detach.base.nm_so;
186 struct ngpcb *const pcbp = sotongpcb(so);
190 ng_detach_common(pcbp, NG_CONTROL);
195 lwkt_replymsg(&msg->detach.base.lmsg, error);
199 ngc_send(netmsg_t msg)
201 struct socket *so = msg->send.base.nm_so;
202 struct mbuf *m = msg->send.nm_m;
203 struct sockaddr *addr = msg->send.nm_addr;
204 struct mbuf *control = msg->send.nm_control;
205 struct ngpcb *const pcbp = sotongpcb(so);
206 struct sockaddr_ng *const sap = (struct sockaddr_ng *) addr;
207 struct ng_mesg *resp;
209 char *xmsg, *path = NULL;
218 if (control && (error = ng_internalize(control, p))) {
219 if (pcbp->sockdata == NULL) {
231 /* Require destination as there may be >= 1 hooks on this node */
233 error = EDESTADDRREQ;
237 /* Allocate an expendable buffer for the path, chop off
238 * the sockaddr header, and make sure it's NUL terminated */
239 len = sap->sg_len - 2;
240 MALLOC(path, char *, len + 1, M_NETGRAPH, M_WAITOK);
241 bcopy(sap->sg_data, path, len);
244 /* Move the actual message out of mbufs into a linear buffer.
245 * Start by adding up the size of the data. (could use mh_len?) */
246 for (len = 0, m0 = m; m0 != NULL; m0 = m0->m_next)
249 /* Move the data into a linear buffer as well. Messages are not
250 * delivered in mbufs. */
251 MALLOC(xmsg, char *, len + 1, M_NETGRAPH, M_WAITOK);
252 m_copydata(m, 0, len, xmsg);
254 /* The callee will free the xmsg when done. The addr is our business. */
255 error = ng_send_msg(pcbp->sockdata->node,
256 (struct ng_mesg *) xmsg, path, &resp);
258 /* If the callee responded with a synchronous response, then put it
259 * back on the receive side of the socket; sap is source address. */
260 if (error == 0 && resp != NULL)
261 error = ship_msg(pcbp, resp, sap);
265 FREE(path, M_NETGRAPH);
270 lwkt_replymsg(&msg->send.base.lmsg, error);
274 ngc_bind(netmsg_t msg)
276 struct socket *so = msg->bind.base.nm_so;
277 struct sockaddr *nam = msg->bind.nm_nam;
278 struct ngpcb *const pcbp = sotongpcb(so);
282 error = ng_bind(nam, pcbp);
285 lwkt_replymsg(&msg->bind.base.lmsg, error);
289 ngc_connect(netmsg_t msg)
291 struct socket *so = msg->connect.base.nm_so;
292 struct sockaddr *nam = msg->connect.nm_nam;
293 struct ngpcb *const pcbp = sotongpcb(so);
297 error = ng_connect_cntl(nam, pcbp);
300 lwkt_replymsg(&msg->connect.base.lmsg, error);
303 /***************************************************************
305 ***************************************************************/
308 ngd_attach(netmsg_t msg)
310 struct socket *so = msg->attach.base.nm_so;
311 struct ngpcb *const pcbp = sotongpcb(so);
317 error = ng_attach_data(so);
318 lwkt_replymsg(&msg->connect.base.lmsg, error);
322 ngd_detach(netmsg_t msg)
324 struct socket *so = msg->detach.base.nm_so;
325 struct ngpcb *const pcbp = sotongpcb(so);
329 ng_detach_common(pcbp, NG_DATA);
334 lwkt_replymsg(&msg->detach.base.lmsg, error);
338 ngd_send(netmsg_t msg)
340 struct socket *so = msg->send.base.nm_so;
341 struct mbuf *m = msg->send.nm_m;
342 struct sockaddr *addr = msg->send.nm_addr;
343 struct mbuf *control = msg->send.nm_control;
344 struct ngpcb *const pcbp = sotongpcb(so);
345 struct sockaddr_ng *const sap = (struct sockaddr_ng *) addr;
349 char hookname[NG_HOOKSIZ];
351 if ((pcbp == NULL) || (control != NULL)) {
355 if (pcbp->sockdata == NULL) {
360 * If the user used any of these ways to not specify an address
361 * then handle specially.
364 || ((len = sap->sg_len - 2) <= 0)
365 || (*sap->sg_data == '\0')) {
366 if (pcbp->sockdata->node->numhooks != 1) {
367 error = EDESTADDRREQ;
371 * if exactly one hook exists, just use it.
372 * Special case to allow write(2) to work on an ng_socket.
374 hook = LIST_FIRST(&pcbp->sockdata->node->hooks);
376 if (len >= NG_HOOKSIZ) {
382 * chop off the sockaddr header, and make sure it's NUL
385 bcopy(sap->sg_data, hookname, len);
386 hookname[len] = '\0';
388 /* Find the correct hook from 'hookname' */
389 LIST_FOREACH(hook, &pcbp->sockdata->node->hooks, hooks) {
390 if (strcmp(hookname, hook->name) == 0)
394 error = EHOSTUNREACH;
397 /* Send data (OK if hook is NULL) */
398 NG_SEND_DATA(error, hook, m, mp); /* makes m NULL */
405 lwkt_replymsg(&msg->send.base.lmsg, error);
409 ngd_connect(netmsg_t msg)
411 struct socket *so = msg->connect.base.nm_so;
412 struct sockaddr *nam = msg->connect.nm_nam;
413 struct ngpcb *const pcbp = sotongpcb(so);
417 error = ng_connect_data(nam, pcbp);
421 lwkt_replymsg(&msg->connect.base.lmsg, error);
425 * Used for both data and control sockets
428 ng_setsockaddr(netmsg_t msg)
430 struct socket *so = msg->sockaddr.base.nm_so;
431 struct sockaddr **addr = msg->sockaddr.nm_nam;
433 struct sockaddr_ng *sg;
437 /* Why isn't sg_data a `char[1]' ? :-( */
438 sg_len = sizeof(struct sockaddr_ng) - sizeof(sg->sg_data) + 1;
441 pcbp = sotongpcb(so);
442 if ((pcbp == 0) || (pcbp->sockdata == NULL)) {
448 namelen = 0; /* silence compiler ! */
450 if (pcbp->sockdata->node->name != NULL)
451 sg_len += namelen = strlen(pcbp->sockdata->node->name);
453 MALLOC(sg, struct sockaddr_ng *, sg_len, M_SONAME, M_WAITOK | M_ZERO);
455 if (pcbp->sockdata->node->name != NULL)
456 bcopy(pcbp->sockdata->node->name, sg->sg_data, namelen);
460 sg->sg_family = AF_NETGRAPH;
461 *addr = (struct sockaddr *)sg;
464 lwkt_replymsg(&msg->sockaddr.base.lmsg, error);
468 * Attach a socket to it's protocol specific partner.
469 * For a control socket, actually create a netgraph node and attach
474 ng_attach_cntl(struct socket *so)
476 struct ngsock *privdata;
480 /* Setup protocol control block */
481 if ((error = ng_attach_common(so, NG_CONTROL)) != 0)
483 pcbp = sotongpcb(so);
485 /* Allocate node private info */
486 MALLOC(privdata, struct ngsock *,
487 sizeof(*privdata), M_NETGRAPH, M_WAITOK | M_ZERO);
489 /* Make the generic node components */
490 if ((error = ng_make_node_common(&typestruct, &privdata->node)) != 0) {
491 FREE(privdata, M_NETGRAPH);
492 ng_detach_common(pcbp, NG_CONTROL);
495 privdata->node->private = privdata;
497 /* Link the pcb and the node private data */
498 privdata->ctlsock = pcbp;
499 pcbp->sockdata = privdata;
505 ng_attach_data(struct socket *so)
507 return(ng_attach_common(so, NG_DATA));
511 * Set up a socket protocol control block.
512 * This code is shared between control and data sockets.
515 ng_attach_common(struct socket *so, int type)
520 /* Standard socket setup stuff */
521 error = soreserve(so, ngpdg_sendspace, ngpdg_recvspace, NULL);
525 /* Allocate the pcb */
526 MALLOC(pcbp, struct ngpcb *, sizeof(*pcbp), M_PCB, M_WAITOK | M_ZERO);
529 /* Link the pcb and the socket */
531 so->so_pcb = (caddr_t) pcbp;
532 pcbp->ng_socket = so;
534 /* Add the socket to linked list */
535 LIST_INSERT_HEAD(&ngsocklist, pcbp, socks);
540 * Disassociate the socket from it's protocol specific
541 * partner. If it's attached to a node's private data structure,
542 * then unlink from that too. If we were the last socket attached to it,
543 * then shut down the entire node. Shared code for control and data sockets.
546 ng_detach_common(struct ngpcb *pcbp, int which)
548 struct ngsock *sockdata;
551 if (pcbp->sockdata) {
552 sockdata = pcbp->sockdata;
553 pcbp->sockdata = NULL;
556 sockdata->ctlsock = NULL;
559 sockdata->datasock = NULL;
564 if ((--sockdata->refs == 0) && (sockdata->node != NULL))
565 ng_rmnode(sockdata->node);
567 so = pcbp->ng_socket;
569 pcbp->ng_socket = NULL;
570 sofree(so); /* remove pcb ref */
572 LIST_REMOVE(pcbp, socks);
578 * File descriptors can be passed into a AF_NETGRAPH socket.
579 * Note, that file descriptors cannot be passed OUT.
580 * Only character device descriptors are accepted.
581 * Character devices are useful to connect a graph to a device,
582 * which after all is the purpose of this whole system.
585 ng_internalize(struct mbuf *control, struct thread *td)
587 struct filedesc *fdp = p->p_fd;
588 const struct cmsghdr *cm = mtod(control, const struct cmsghdr *);
594 if (cm->cmsg_type != SCM_RIGHTS || cm->cmsg_level != SOL_SOCKET ||
595 cm->cmsg_len != control->m_len) {
600 /* Check there is only one FD. XXX what would more than one signify? */
601 oldfds = (cm->cmsg_len - sizeof(*cm)) / sizeof(int);
607 /* Check that the FD given is legit. and change it to a pointer to a
609 fd = *(int *) (cm + 1);
610 if ((unsigned) fd >= fdp->fd_nfiles
611 || (fp = fdp->fd_files[fd].fp) == NULL) {
615 /* Depending on what kind of resource it is, act differently. For
616 * devices, we treat it as a file. For a AF_NETGRAPH socket,
617 * shortcut straight to the node. */
618 switch (fp->f_type) {
620 vn = (struct vnode *) fp->f_data;
621 if (vn && (vn->v_type == VCHR)) {
622 /* for a VCHR, actually reference the FILE */
624 /* XXX then what :) */
625 /* how to pass on to other modules? */
640 * Connect the data socket to a named control socket node.
643 ng_connect_data(struct sockaddr *nam, struct ngpcb *pcbp)
645 struct sockaddr_ng *sap;
647 struct ngsock *sockdata;
650 /* If we are already connected, don't do it again */
651 if (pcbp->sockdata != NULL)
654 /* Find the target (victim) and check it doesn't already have a data
655 * socket. Also check it is a 'socket' type node. */
656 sap = (struct sockaddr_ng *) nam;
657 if ((error = ng_path2node(NULL, sap->sg_data, &farnode, NULL)))
660 if (strcmp(farnode->type->name, NG_SOCKET_NODE_TYPE) != 0)
662 sockdata = farnode->private;
663 if (sockdata->datasock != NULL)
666 /* Link the PCB and the private data struct. and note the extra
668 sockdata->datasock = pcbp;
669 pcbp->sockdata = sockdata;
675 * Connect the existing control socket node to a named node:hook.
676 * The hook we use on this end is the same name as the remote node name.
679 ng_connect_cntl(struct sockaddr *nam, struct ngpcb *pcbp)
681 struct ngsock *const sockdata = pcbp->sockdata;
682 struct sockaddr_ng *sap;
687 sap = (struct sockaddr_ng *) nam;
688 rtn = ng_path_parse(sap->sg_data, &node, NULL, &hook);
689 if (rtn < 0 || node == NULL || hook == NULL) {
693 farnode = ng_findname(sockdata->node, node);
694 if (farnode == NULL) {
696 return (EADDRNOTAVAIL);
699 /* Connect, using a hook name the same as the far node name. */
700 error = ng_con_nodes(sockdata->node, node, farnode, hook);
705 * Binding a socket means giving the corresponding node a name
708 ng_bind(struct sockaddr *nam, struct ngpcb *pcbp)
710 struct ngsock *const sockdata = pcbp->sockdata;
711 struct sockaddr_ng *const sap = (struct sockaddr_ng *) nam;
713 if (sockdata == NULL) {
717 if (sap->sg_len < 3 || sap->sg_data[sap->sg_len - 3] != '\0') {
721 return (ng_name_node(sockdata->node, sap->sg_data));
725 * Take a message and pass it up to the control socket associated
729 ship_msg(struct ngpcb *pcbp, struct ng_mesg *msg, struct sockaddr_ng *addr)
731 struct socket *const so = pcbp->ng_socket;
735 /* Copy the message itself into an mbuf chain */
736 msglen = sizeof(struct ng_mesg) + msg->header.arglen;
737 mdata = m_devget((caddr_t) msg, msglen, 0, NULL, NULL);
739 /* Here we free the message, as we are the end of the line.
740 * We need to do that regardless of whether we got mbufs. */
741 FREE(msg, M_NETGRAPH);
748 /* Send it up to the socket */
749 if (ssb_appendaddr(&so->so_rcv,
750 (struct sockaddr *) addr, mdata, NULL) == 0) {
760 * You can only create new nodes from the socket end of things.
763 ngs_constructor(node_p *nodep)
769 * We allow any hook to be connected to the node.
770 * There is no per-hook private information though.
773 ngs_newhook(node_p node, hook_p hook, const char *name)
775 hook->private = node->private;
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, struct ng_mesg *msg, const char *retaddr,
785 struct ng_mesg **resp)
787 struct ngsock *const sockdata = node->private;
788 struct ngpcb *const pcbp = sockdata->ctlsock;
789 struct sockaddr_ng *addr;
793 /* Only allow mesgs to be passed if we have the control socket.
794 * Data sockets can only support the generic messages. */
800 if (msg->header.typecookie == NGM_SOCKET_COOKIE) {
801 switch (msg->header.cmd) {
802 case NGM_SOCK_CMD_NOLINGER:
803 sockdata->flags |= NGS_FLAG_NOLINGER;
805 case NGM_SOCK_CMD_LINGER:
806 sockdata->flags &= ~NGS_FLAG_NOLINGER;
809 error = EINVAL; /* unknown command */
811 /* Free the message and return */
812 FREE(msg, M_NETGRAPH);
816 /* Get the return address into a sockaddr */
817 if ((retaddr == NULL) || (*retaddr == '\0'))
819 addrlen = strlen(retaddr);
820 MALLOC(addr, struct sockaddr_ng *, addrlen + 4, M_NETGRAPH, M_NOWAIT);
825 addr->sg_len = addrlen + 3;
826 addr->sg_family = AF_NETGRAPH;
827 bcopy(retaddr, addr->sg_data, addrlen);
828 addr->sg_data[addrlen] = '\0';
831 error = ship_msg(pcbp, msg, addr);
832 FREE(addr, M_NETGRAPH);
837 * Receive data on a hook
840 ngs_rcvdata(hook_p hook, struct mbuf *m, meta_p meta)
842 struct ngsock *const sockdata = hook->node->private;
843 struct ngpcb *const pcbp = sockdata->datasock;
845 struct sockaddr_ng *addr;
846 char *addrbuf[NG_HOOKSIZ + 4];
849 /* If there is no data socket, black-hole it */
851 NG_FREE_DATA(m, meta);
854 so = pcbp->ng_socket;
856 /* Get the return address into a sockaddr. */
857 addrlen = strlen(hook->name); /* <= NG_HOOKSIZ - 1 */
858 addr = (struct sockaddr_ng *) addrbuf;
859 addr->sg_len = addrlen + 3;
860 addr->sg_family = AF_NETGRAPH;
861 bcopy(hook->name, addr->sg_data, addrlen);
862 addr->sg_data[addrlen] = '\0';
864 /* We have no use for the meta data, free/clear it now. */
867 /* Try to tell the socket which hook it came in on */
868 if (ssb_appendaddr(&so->so_rcv, (struct sockaddr *) addr, m, NULL) == 0) {
880 * For this type, removal of the last link destroys the node
881 * if the NOLINGER flag is set.
884 ngs_disconnect(hook_p hook)
886 struct ngsock *const sockdata = hook->node->private;
888 if ((sockdata->flags & NGS_FLAG_NOLINGER )
889 && (hook->node->numhooks == 0)) {
890 ng_rmnode(hook->node);
896 * Do local shutdown processing.
897 * In this case, that involves making sure the socket
898 * knows we should be shutting down.
901 ngs_rmnode(node_p node)
903 struct ngsock *const sockdata = node->private;
904 struct ngpcb *const dpcbp = sockdata->datasock;
905 struct ngpcb *const pcbp = sockdata->ctlsock;
911 soisdisconnected(dpcbp->ng_socket);
912 dpcbp->sockdata = NULL;
913 sockdata->datasock = NULL;
917 soisdisconnected(pcbp->ng_socket);
918 pcbp->sockdata = NULL;
919 sockdata->ctlsock = NULL;
922 node->private = NULL;
924 FREE(sockdata, M_NETGRAPH);
929 * Control and data socket type descriptors
932 static struct pr_usrreqs ngc_usrreqs = {
934 .pru_accept = pr_generic_notsupp,
935 .pru_attach = ngc_attach,
936 .pru_bind = ngc_bind,
937 .pru_connect = ngc_connect,
938 .pru_connect2 = pr_generic_notsupp,
939 .pru_control = pr_generic_notsupp,
940 .pru_detach = ngc_detach,
941 .pru_disconnect = NULL,
942 .pru_listen = pr_generic_notsupp,
943 .pru_peeraddr = NULL,
944 .pru_rcvd = pr_generic_notsupp,
945 .pru_rcvoob = pr_generic_notsupp,
946 .pru_send = ngc_send,
947 .pru_sense = pru_sense_null,
948 .pru_shutdown = NULL,
949 .pru_sockaddr = ng_setsockaddr,
950 .pru_sosend = sosend,
951 .pru_soreceive = soreceive
954 static struct pr_usrreqs ngd_usrreqs = {
956 .pru_accept = pr_generic_notsupp,
957 .pru_attach = ngd_attach,
959 .pru_connect = ngd_connect,
960 .pru_connect2 = pr_generic_notsupp,
961 .pru_control = pr_generic_notsupp,
962 .pru_detach = ngd_detach,
963 .pru_disconnect = NULL,
964 .pru_listen = pr_generic_notsupp,
965 .pru_peeraddr = NULL,
966 .pru_rcvd = pr_generic_notsupp,
967 .pru_rcvoob = pr_generic_notsupp,
968 .pru_send = ngd_send,
969 .pru_sense = pru_sense_null,
970 .pru_shutdown = NULL,
971 .pru_sockaddr = ng_setsockaddr,
972 .pru_sosend = sosend,
973 .pru_soreceive = soreceive
977 * Definitions of protocols supported in the NETGRAPH domain.
980 extern struct domain ngdomain; /* stop compiler warnings */
982 static struct protosw ngsw[] = {
984 .pr_type = SOCK_DGRAM,
985 .pr_domain = &ngdomain,
986 .pr_protocol = NG_CONTROL,
987 .pr_flags = PR_ATOMIC | PR_ADDR /* | PR_RIGHTS */,
988 .pr_usrreqs = &ngc_usrreqs
991 .pr_type = SOCK_DGRAM,
992 .pr_domain = &ngdomain,
993 .pr_protocol = NG_DATA,
994 .pr_flags = PR_ATOMIC | PR_ADDR,
995 .pr_usrreqs = &ngd_usrreqs
999 struct domain ngdomain = {
1000 AF_NETGRAPH, "netgraph", NULL, NULL, NULL,
1001 ngsw, &ngsw[sizeof(ngsw) / sizeof(ngsw[0])],
1005 * Handle loading and unloading for this node type
1006 * This is to handle auxiliary linkages (e.g protocol domain addition).
1009 ngs_mod_event(module_t mod, int event, void *data)
1015 /* Register protocol domain */
1016 net_add_domain(&ngdomain);
1019 /* Insure there are no open netgraph sockets */
1020 if (!LIST_EMPTY(&ngsocklist)) {
1026 /* Unregister protocol domain XXX can't do this yet.. */
1027 if ((error = net_rm_domain(&ngdomain)) != 0)
1040 SYSCTL_INT(_net_graph, OID_AUTO, family, CTLFLAG_RD, 0, AF_NETGRAPH, "");
1041 SYSCTL_NODE(_net_graph, OID_AUTO, data, CTLFLAG_RW, 0, "DATA");
1042 SYSCTL_INT(_net_graph_data, OID_AUTO, proto, CTLFLAG_RD, 0, NG_DATA, "");
1043 SYSCTL_NODE(_net_graph, OID_AUTO, control, CTLFLAG_RW, 0, "CONTROL");
1044 SYSCTL_INT(_net_graph_control, OID_AUTO, proto, CTLFLAG_RD, 0, NG_CONTROL, "");