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.16 2008/01/06 16:55:52 swildner 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>
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>
66 #include <sys/thread2.h>
68 #include <sys/vnode.h>
70 #include <netgraph/ng_message.h>
71 #include <netgraph/netgraph.h>
72 #include "ng_socketvar.h"
73 #include "ng_socket.h"
76 * It's Ascii-art time!
77 * +-------------+ +-------------+
78 * |socket (ctl)| |socket (data)|
79 * +-------------+ +-------------+
83 * +-----------+ +-----------+
84 * |pcb (ctl)| |pcb (data)|
85 * +-----------+ +-----------+
89 * +--------------------------+
90 * | Socket type private |
92 * +--------------------------+
101 /* Netgraph node methods */
102 static ng_constructor_t ngs_constructor
;
103 static ng_rcvmsg_t ngs_rcvmsg
;
104 static ng_shutdown_t ngs_rmnode
;
105 static ng_newhook_t ngs_newhook
;
106 static ng_rcvdata_t ngs_rcvdata
;
107 static ng_disconnect_t ngs_disconnect
;
109 /* Internal methods */
110 static int ng_attach_data(struct socket
*so
);
111 static int ng_attach_cntl(struct socket
*so
);
112 static int ng_attach_common(struct socket
*so
, int type
);
113 static void ng_detach_common(struct ngpcb
*pcbp
, int type
);
114 /*static int ng_internalize(struct mbuf *m, struct thread *td); */
116 static int ng_connect_data(struct sockaddr
*nam
, struct ngpcb
*pcbp
);
117 static int ng_connect_cntl(struct sockaddr
*nam
, struct ngpcb
*pcbp
);
118 static int ng_bind(struct sockaddr
*nam
, struct ngpcb
*pcbp
);
120 static int ngs_mod_event(module_t mod
, int event
, void *data
);
121 static int ship_msg(struct ngpcb
*pcbp
, struct ng_mesg
*msg
,
122 struct sockaddr_ng
*addr
);
124 /* Netgraph type descriptor */
125 static struct ng_type typestruct
= {
140 NETGRAPH_INIT(socket
, &typestruct
);
143 static u_long ngpdg_sendspace
= 20 * 1024; /* really max datagram size */
144 static u_long ngpdg_recvspace
= 20 * 1024;
146 /* List of all sockets */
147 LIST_HEAD(, ngpcb
) ngsocklist
;
149 #define sotongpcb(so) ((struct ngpcb *)(so)->so_pcb)
151 /* If getting unexplained errors returned, set this to "Debugger("X"); */
156 /***************************************************************
158 ***************************************************************/
161 ngc_attach(struct socket
*so
, int proto
, struct pru_attach_info
*ai
)
163 struct ngpcb
*const pcbp
= sotongpcb(so
);
165 if (suser_cred(ai
->p_ucred
, NULL_CRED_OKAY
) != 0)
169 return (ng_attach_cntl(so
));
173 ngc_detach(struct socket
*so
)
175 struct ngpcb
*const pcbp
= sotongpcb(so
);
179 ng_detach_common(pcbp
, NG_CONTROL
);
184 ngc_send(struct socket
*so
, int flags
, struct mbuf
*m
, struct sockaddr
*addr
,
185 struct mbuf
*control
, struct thread
*td
)
187 struct ngpcb
*const pcbp
= sotongpcb(so
);
188 struct sockaddr_ng
*const sap
= (struct sockaddr_ng
*) addr
;
189 struct ng_mesg
*resp
;
191 char *msg
, *path
= NULL
;
199 if (control
&& (error
= ng_internalize(control
, p
))) {
200 if (pcbp
->sockdata
== NULL
) {
212 /* Require destination as there may be >= 1 hooks on this node */
214 error
= EDESTADDRREQ
;
218 /* Allocate an expendable buffer for the path, chop off
219 * the sockaddr header, and make sure it's NUL terminated */
220 len
= sap
->sg_len
- 2;
221 MALLOC(path
, char *, len
+ 1, M_NETGRAPH
, M_WAITOK
);
222 bcopy(sap
->sg_data
, path
, len
);
225 /* Move the actual message out of mbufs into a linear buffer.
226 * Start by adding up the size of the data. (could use mh_len?) */
227 for (len
= 0, m0
= m
; m0
!= NULL
; m0
= m0
->m_next
)
230 /* Move the data into a linear buffer as well. Messages are not
231 * delivered in mbufs. */
232 MALLOC(msg
, char *, len
+ 1, M_NETGRAPH
, M_WAITOK
);
233 m_copydata(m
, 0, len
, msg
);
235 /* The callee will free the msg when done. The addr is our business. */
236 error
= ng_send_msg(pcbp
->sockdata
->node
,
237 (struct ng_mesg
*) msg
, path
, &resp
);
239 /* If the callee responded with a synchronous response, then put it
240 * back on the receive side of the socket; sap is source address. */
241 if (error
== 0 && resp
!= NULL
)
242 error
= ship_msg(pcbp
, resp
, sap
);
246 FREE(path
, M_NETGRAPH
);
255 ngc_bind(struct socket
*so
, struct sockaddr
*nam
, struct thread
*td
)
257 struct ngpcb
*const pcbp
= sotongpcb(so
);
261 return (ng_bind(nam
, pcbp
));
265 ngc_connect(struct socket
*so
, struct sockaddr
*nam
, struct thread
*td
)
267 struct ngpcb
*const pcbp
= sotongpcb(so
);
271 return (ng_connect_cntl(nam
, pcbp
));
274 /***************************************************************
276 ***************************************************************/
279 ngd_attach(struct socket
*so
, int proto
, struct pru_attach_info
*ai
)
281 struct ngpcb
*const pcbp
= sotongpcb(so
);
285 return (ng_attach_data(so
));
289 ngd_detach(struct socket
*so
)
291 struct ngpcb
*const pcbp
= sotongpcb(so
);
295 ng_detach_common(pcbp
, NG_DATA
);
300 ngd_send(struct socket
*so
, int flags
, struct mbuf
*m
, struct sockaddr
*addr
,
301 struct mbuf
*control
, struct thread
*td
)
303 struct ngpcb
*const pcbp
= sotongpcb(so
);
304 struct sockaddr_ng
*const sap
= (struct sockaddr_ng
*) addr
;
308 char hookname
[NG_HOOKSIZ
];
310 if ((pcbp
== NULL
) || (control
!= NULL
)) {
314 if (pcbp
->sockdata
== NULL
) {
319 * If the user used any of these ways to not specify an address
320 * then handle specially.
323 || ((len
= sap
->sg_len
- 2) <= 0)
324 || (*sap
->sg_data
== '\0')) {
325 if (pcbp
->sockdata
->node
->numhooks
!= 1) {
326 error
= EDESTADDRREQ
;
330 * if exactly one hook exists, just use it.
331 * Special case to allow write(2) to work on an ng_socket.
333 hook
= LIST_FIRST(&pcbp
->sockdata
->node
->hooks
);
335 if (len
>= NG_HOOKSIZ
) {
341 * chop off the sockaddr header, and make sure it's NUL
344 bcopy(sap
->sg_data
, hookname
, len
);
345 hookname
[len
] = '\0';
347 /* Find the correct hook from 'hookname' */
348 LIST_FOREACH(hook
, &pcbp
->sockdata
->node
->hooks
, hooks
) {
349 if (strcmp(hookname
, hook
->name
) == 0)
353 error
= EHOSTUNREACH
;
356 /* Send data (OK if hook is NULL) */
357 NG_SEND_DATA(error
, hook
, m
, mp
); /* makes m NULL */
368 ngd_connect(struct socket
*so
, struct sockaddr
*nam
, struct thread
*td
)
370 struct ngpcb
*const pcbp
= sotongpcb(so
);
374 return (ng_connect_data(nam
, pcbp
));
378 * Used for both data and control sockets
381 ng_setsockaddr(struct socket
*so
, struct sockaddr
**addr
)
384 struct sockaddr_ng
*sg
;
387 /* Why isn't sg_data a `char[1]' ? :-( */
388 sg_len
= sizeof(struct sockaddr_ng
) - sizeof(sg
->sg_data
) + 1;
391 pcbp
= sotongpcb(so
);
392 if ((pcbp
== 0) || (pcbp
->sockdata
== NULL
)) {
397 namelen
= 0; /* silence compiler ! */
399 if (pcbp
->sockdata
->node
->name
!= NULL
)
400 sg_len
+= namelen
= strlen(pcbp
->sockdata
->node
->name
);
402 MALLOC(sg
, struct sockaddr_ng
*, sg_len
, M_SONAME
, M_WAITOK
| M_ZERO
);
404 if (pcbp
->sockdata
->node
->name
!= NULL
)
405 bcopy(pcbp
->sockdata
->node
->name
, sg
->sg_data
, namelen
);
409 sg
->sg_family
= AF_NETGRAPH
;
410 *addr
= (struct sockaddr
*)sg
;
416 * Attach a socket to it's protocol specific partner.
417 * For a control socket, actually create a netgraph node and attach
422 ng_attach_cntl(struct socket
*so
)
424 struct ngsock
*privdata
;
428 /* Setup protocol control block */
429 if ((error
= ng_attach_common(so
, NG_CONTROL
)) != 0)
431 pcbp
= sotongpcb(so
);
433 /* Allocate node private info */
434 MALLOC(privdata
, struct ngsock
*,
435 sizeof(*privdata
), M_NETGRAPH
, M_WAITOK
| M_ZERO
);
437 /* Make the generic node components */
438 if ((error
= ng_make_node_common(&typestruct
, &privdata
->node
)) != 0) {
439 FREE(privdata
, M_NETGRAPH
);
440 ng_detach_common(pcbp
, NG_CONTROL
);
443 privdata
->node
->private = privdata
;
445 /* Link the pcb and the node private data */
446 privdata
->ctlsock
= pcbp
;
447 pcbp
->sockdata
= privdata
;
453 ng_attach_data(struct socket
*so
)
455 return(ng_attach_common(so
, NG_DATA
));
459 * Set up a socket protocol control block.
460 * This code is shared between control and data sockets.
463 ng_attach_common(struct socket
*so
, int type
)
468 /* Standard socket setup stuff */
469 error
= soreserve(so
, ngpdg_sendspace
, ngpdg_recvspace
, NULL
);
473 /* Allocate the pcb */
474 MALLOC(pcbp
, struct ngpcb
*, sizeof(*pcbp
), M_PCB
, M_WAITOK
| M_ZERO
);
477 /* Link the pcb and the socket */
478 so
->so_pcb
= (caddr_t
) pcbp
;
479 pcbp
->ng_socket
= so
;
481 /* Add the socket to linked list */
482 LIST_INSERT_HEAD(&ngsocklist
, pcbp
, socks
);
487 * Disassociate the socket from it's protocol specific
488 * partner. If it's attached to a node's private data structure,
489 * then unlink from that too. If we were the last socket attached to it,
490 * then shut down the entire node. Shared code for control and data sockets.
493 ng_detach_common(struct ngpcb
*pcbp
, int which
)
495 struct ngsock
*sockdata
;
497 if (pcbp
->sockdata
) {
498 sockdata
= pcbp
->sockdata
;
499 pcbp
->sockdata
= NULL
;
502 sockdata
->ctlsock
= NULL
;
505 sockdata
->datasock
= NULL
;
510 if ((--sockdata
->refs
== 0) && (sockdata
->node
!= NULL
))
511 ng_rmnode(sockdata
->node
);
513 pcbp
->ng_socket
->so_pcb
= NULL
;
514 pcbp
->ng_socket
= NULL
;
515 LIST_REMOVE(pcbp
, socks
);
521 * File descriptors can be passed into a AF_NETGRAPH socket.
522 * Note, that file descriptors cannot be passed OUT.
523 * Only character device descriptors are accepted.
524 * Character devices are useful to connect a graph to a device,
525 * which after all is the purpose of this whole system.
528 ng_internalize(struct mbuf
*control
, struct thread
*td
)
530 struct filedesc
*fdp
= p
->p_fd
;
531 const struct cmsghdr
*cm
= mtod(control
, const struct cmsghdr
*);
537 if (cm
->cmsg_type
!= SCM_RIGHTS
|| cm
->cmsg_level
!= SOL_SOCKET
||
538 cm
->cmsg_len
!= control
->m_len
) {
543 /* Check there is only one FD. XXX what would more than one signify? */
544 oldfds
= (cm
->cmsg_len
- sizeof(*cm
)) / sizeof(int);
550 /* Check that the FD given is legit. and change it to a pointer to a
552 fd
= *(int *) (cm
+ 1);
553 if ((unsigned) fd
>= fdp
->fd_nfiles
554 || (fp
= fdp
->fd_files
[fd
].fp
) == NULL
) {
558 /* Depending on what kind of resource it is, act differently. For
559 * devices, we treat it as a file. For a AF_NETGRAPH socket,
560 * shortcut straight to the node. */
561 switch (fp
->f_type
) {
563 vn
= (struct vnode
*) fp
->f_data
;
564 if (vn
&& (vn
->v_type
== VCHR
)) {
565 /* for a VCHR, actually reference the FILE */
567 /* XXX then what :) */
568 /* how to pass on to other modules? */
583 * Connect the data socket to a named control socket node.
586 ng_connect_data(struct sockaddr
*nam
, struct ngpcb
*pcbp
)
588 struct sockaddr_ng
*sap
;
590 struct ngsock
*sockdata
;
593 /* If we are already connected, don't do it again */
594 if (pcbp
->sockdata
!= NULL
)
597 /* Find the target (victim) and check it doesn't already have a data
598 * socket. Also check it is a 'socket' type node. */
599 sap
= (struct sockaddr_ng
*) nam
;
600 if ((error
= ng_path2node(NULL
, sap
->sg_data
, &farnode
, NULL
)))
603 if (strcmp(farnode
->type
->name
, NG_SOCKET_NODE_TYPE
) != 0)
605 sockdata
= farnode
->private;
606 if (sockdata
->datasock
!= NULL
)
609 /* Link the PCB and the private data struct. and note the extra
611 sockdata
->datasock
= pcbp
;
612 pcbp
->sockdata
= sockdata
;
618 * Connect the existing control socket node to a named node:hook.
619 * The hook we use on this end is the same name as the remote node name.
622 ng_connect_cntl(struct sockaddr
*nam
, struct ngpcb
*pcbp
)
624 struct ngsock
*const sockdata
= pcbp
->sockdata
;
625 struct sockaddr_ng
*sap
;
630 sap
= (struct sockaddr_ng
*) nam
;
631 rtn
= ng_path_parse(sap
->sg_data
, &node
, NULL
, &hook
);
632 if (rtn
< 0 || node
== NULL
|| hook
== NULL
) {
636 farnode
= ng_findname(sockdata
->node
, node
);
637 if (farnode
== NULL
) {
639 return (EADDRNOTAVAIL
);
642 /* Connect, using a hook name the same as the far node name. */
643 error
= ng_con_nodes(sockdata
->node
, node
, farnode
, hook
);
648 * Binding a socket means giving the corresponding node a name
651 ng_bind(struct sockaddr
*nam
, struct ngpcb
*pcbp
)
653 struct ngsock
*const sockdata
= pcbp
->sockdata
;
654 struct sockaddr_ng
*const sap
= (struct sockaddr_ng
*) nam
;
656 if (sockdata
== NULL
) {
660 if (sap
->sg_len
< 3 || sap
->sg_data
[sap
->sg_len
- 3] != '\0') {
664 return (ng_name_node(sockdata
->node
, sap
->sg_data
));
668 * Take a message and pass it up to the control socket associated
672 ship_msg(struct ngpcb
*pcbp
, struct ng_mesg
*msg
, struct sockaddr_ng
*addr
)
674 struct socket
*const so
= pcbp
->ng_socket
;
678 /* Copy the message itself into an mbuf chain */
679 msglen
= sizeof(struct ng_mesg
) + msg
->header
.arglen
;
680 mdata
= m_devget((caddr_t
) msg
, msglen
, 0, NULL
, NULL
);
682 /* Here we free the message, as we are the end of the line.
683 * We need to do that regardless of whether we got mbufs. */
684 FREE(msg
, M_NETGRAPH
);
691 /* Send it up to the socket */
692 if (ssb_appendaddr(&so
->so_rcv
,
693 (struct sockaddr
*) addr
, mdata
, NULL
) == 0) {
703 * You can only create new nodes from the socket end of things.
706 ngs_constructor(node_p
*nodep
)
712 * We allow any hook to be connected to the node.
713 * There is no per-hook private information though.
716 ngs_newhook(node_p node
, hook_p hook
, const char *name
)
718 hook
->private = node
->private;
723 * Incoming messages get passed up to the control socket.
724 * Unless they are for us specifically (socket_type)
727 ngs_rcvmsg(node_p node
, struct ng_mesg
*msg
, const char *retaddr
,
728 struct ng_mesg
**resp
)
730 struct ngsock
*const sockdata
= node
->private;
731 struct ngpcb
*const pcbp
= sockdata
->ctlsock
;
732 struct sockaddr_ng
*addr
;
736 /* Only allow mesgs to be passed if we have the control socket.
737 * Data sockets can only support the generic messages. */
743 if (msg
->header
.typecookie
== NGM_SOCKET_COOKIE
) {
744 switch (msg
->header
.cmd
) {
745 case NGM_SOCK_CMD_NOLINGER
:
746 sockdata
->flags
|= NGS_FLAG_NOLINGER
;
748 case NGM_SOCK_CMD_LINGER
:
749 sockdata
->flags
&= ~NGS_FLAG_NOLINGER
;
752 error
= EINVAL
; /* unknown command */
754 /* Free the message and return */
755 FREE(msg
, M_NETGRAPH
);
759 /* Get the return address into a sockaddr */
760 if ((retaddr
== NULL
) || (*retaddr
== '\0'))
762 addrlen
= strlen(retaddr
);
763 MALLOC(addr
, struct sockaddr_ng
*, addrlen
+ 4, M_NETGRAPH
, M_NOWAIT
);
768 addr
->sg_len
= addrlen
+ 3;
769 addr
->sg_family
= AF_NETGRAPH
;
770 bcopy(retaddr
, addr
->sg_data
, addrlen
);
771 addr
->sg_data
[addrlen
] = '\0';
774 error
= ship_msg(pcbp
, msg
, addr
);
775 FREE(addr
, M_NETGRAPH
);
780 * Receive data on a hook
783 ngs_rcvdata(hook_p hook
, struct mbuf
*m
, meta_p meta
)
785 struct ngsock
*const sockdata
= hook
->node
->private;
786 struct ngpcb
*const pcbp
= sockdata
->datasock
;
788 struct sockaddr_ng
*addr
;
789 char *addrbuf
[NG_HOOKSIZ
+ 4];
792 /* If there is no data socket, black-hole it */
794 NG_FREE_DATA(m
, meta
);
797 so
= pcbp
->ng_socket
;
799 /* Get the return address into a sockaddr. */
800 addrlen
= strlen(hook
->name
); /* <= NG_HOOKSIZ - 1 */
801 addr
= (struct sockaddr_ng
*) addrbuf
;
802 addr
->sg_len
= addrlen
+ 3;
803 addr
->sg_family
= AF_NETGRAPH
;
804 bcopy(hook
->name
, addr
->sg_data
, addrlen
);
805 addr
->sg_data
[addrlen
] = '\0';
807 /* We have no use for the meta data, free/clear it now. */
810 /* Try to tell the socket which hook it came in on */
811 if (ssb_appendaddr(&so
->so_rcv
, (struct sockaddr
*) addr
, m
, NULL
) == 0) {
823 * For this type, removal of the last link destroys the node
824 * if the NOLINGER flag is set.
827 ngs_disconnect(hook_p hook
)
829 struct ngsock
*const sockdata
= hook
->node
->private;
831 if ((sockdata
->flags
& NGS_FLAG_NOLINGER
)
832 && (hook
->node
->numhooks
== 0)) {
833 ng_rmnode(hook
->node
);
839 * Do local shutdown processing.
840 * In this case, that involves making sure the socket
841 * knows we should be shutting down.
844 ngs_rmnode(node_p node
)
846 struct ngsock
*const sockdata
= node
->private;
847 struct ngpcb
*const dpcbp
= sockdata
->datasock
;
848 struct ngpcb
*const pcbp
= sockdata
->ctlsock
;
854 soisdisconnected(dpcbp
->ng_socket
);
855 dpcbp
->sockdata
= NULL
;
856 sockdata
->datasock
= NULL
;
860 soisdisconnected(pcbp
->ng_socket
);
861 pcbp
->sockdata
= NULL
;
862 sockdata
->ctlsock
= NULL
;
865 node
->private = NULL
;
867 FREE(sockdata
, M_NETGRAPH
);
872 * Control and data socket type descriptors
875 static struct pr_usrreqs ngc_usrreqs
= {
877 .pru_accept
= pru_accept_notsupp
,
878 .pru_attach
= ngc_attach
,
879 .pru_bind
= ngc_bind
,
880 .pru_connect
= ngc_connect
,
881 .pru_connect2
= pru_connect2_notsupp
,
882 .pru_control
= pru_control_notsupp
,
883 .pru_detach
= ngc_detach
,
884 .pru_disconnect
= NULL
,
885 .pru_listen
= pru_listen_notsupp
,
886 .pru_peeraddr
= NULL
,
887 .pru_rcvd
= pru_rcvd_notsupp
,
888 .pru_rcvoob
= pru_rcvoob_notsupp
,
889 .pru_send
= ngc_send
,
890 .pru_sense
= pru_sense_null
,
891 .pru_shutdown
= NULL
,
892 .pru_sockaddr
= ng_setsockaddr
,
893 .pru_sosend
= sosend
,
894 .pru_soreceive
= soreceive
,
898 static struct pr_usrreqs ngd_usrreqs
= {
900 .pru_accept
= pru_accept_notsupp
,
901 .pru_attach
= ngd_attach
,
903 .pru_connect
= ngd_connect
,
904 .pru_connect2
= pru_connect2_notsupp
,
905 .pru_control
= pru_control_notsupp
,
906 .pru_detach
= ngd_detach
,
907 .pru_disconnect
= NULL
,
908 .pru_listen
= pru_listen_notsupp
,
909 .pru_peeraddr
= NULL
,
910 .pru_rcvd
= pru_rcvd_notsupp
,
911 .pru_rcvoob
= pru_rcvoob_notsupp
,
912 .pru_send
= ngd_send
,
913 .pru_sense
= pru_sense_null
,
914 .pru_shutdown
= NULL
,
915 .pru_sockaddr
= ng_setsockaddr
,
916 .pru_sosend
= sosend
,
917 .pru_soreceive
= soreceive
,
922 * Definitions of protocols supported in the NETGRAPH domain.
925 extern struct domain ngdomain
; /* stop compiler warnings */
927 static struct protosw ngsw
[] = {
932 PR_ATOMIC
| PR_ADDR
/* | PR_RIGHTS */,
950 struct domain ngdomain
= {
951 AF_NETGRAPH
, "netgraph", NULL
, NULL
, NULL
,
952 ngsw
, &ngsw
[sizeof(ngsw
) / sizeof(ngsw
[0])],
956 * Handle loading and unloading for this node type
957 * This is to handle auxiliary linkages (e.g protocol domain addition).
960 ngs_mod_event(module_t mod
, int event
, void *data
)
966 /* Register protocol domain */
967 net_add_domain(&ngdomain
);
970 /* Insure there are no open netgraph sockets */
971 if (!LIST_EMPTY(&ngsocklist
)) {
977 /* Unregister protocol domain XXX can't do this yet.. */
978 if ((error
= net_rm_domain(&ngdomain
)) != 0)
991 SYSCTL_INT(_net_graph
, OID_AUTO
, family
, CTLFLAG_RD
, 0, AF_NETGRAPH
, "");
992 SYSCTL_NODE(_net_graph
, OID_AUTO
, data
, CTLFLAG_RW
, 0, "DATA");
993 SYSCTL_INT(_net_graph_data
, OID_AUTO
, proto
, CTLFLAG_RD
, 0, NG_DATA
, "");
994 SYSCTL_NODE(_net_graph
, OID_AUTO
, control
, CTLFLAG_RW
, 0, "CONTROL");
995 SYSCTL_INT(_net_graph_control
, OID_AUTO
, proto
, CTLFLAG_RD
, 0, NG_CONTROL
, "");