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>
67 #include <sys/thread2.h>
69 #include <sys/vnode.h>
71 #include <netgraph/ng_message.h>
72 #include <netgraph/netgraph.h>
73 #include "ng_socketvar.h"
74 #include "ng_socket.h"
77 * It's Ascii-art time!
78 * +-------------+ +-------------+
79 * |socket (ctl)| |socket (data)|
80 * +-------------+ +-------------+
84 * +-----------+ +-----------+
85 * |pcb (ctl)| |pcb (data)|
86 * +-----------+ +-----------+
90 * +--------------------------+
91 * | Socket type private |
93 * +--------------------------+
102 /* Netgraph node methods */
103 static ng_constructor_t ngs_constructor
;
104 static ng_rcvmsg_t ngs_rcvmsg
;
105 static ng_shutdown_t ngs_rmnode
;
106 static ng_newhook_t ngs_newhook
;
107 static ng_rcvdata_t ngs_rcvdata
;
108 static ng_disconnect_t ngs_disconnect
;
110 /* Internal methods */
111 static int ng_attach_data(struct socket
*so
);
112 static int ng_attach_cntl(struct socket
*so
);
113 static int ng_attach_common(struct socket
*so
, int type
);
114 static void ng_detach_common(struct ngpcb
*pcbp
, int type
);
115 /*static int ng_internalize(struct mbuf *m, struct thread *td); */
117 static int ng_connect_data(struct sockaddr
*nam
, struct ngpcb
*pcbp
);
118 static int ng_connect_cntl(struct sockaddr
*nam
, struct ngpcb
*pcbp
);
119 static int ng_bind(struct sockaddr
*nam
, struct ngpcb
*pcbp
);
121 static int ngs_mod_event(module_t mod
, int event
, void *data
);
122 static int ship_msg(struct ngpcb
*pcbp
, struct ng_mesg
*msg
,
123 struct sockaddr_ng
*addr
);
125 /* Netgraph type descriptor */
126 static struct ng_type typestruct
= {
141 NETGRAPH_INIT(socket
, &typestruct
);
144 static u_long ngpdg_sendspace
= 20 * 1024; /* really max datagram size */
145 static u_long ngpdg_recvspace
= 20 * 1024;
147 /* List of all sockets */
148 LIST_HEAD(, ngpcb
) ngsocklist
;
150 #define sotongpcb(so) ((struct ngpcb *)(so)->so_pcb)
152 /* If getting unexplained errors returned, set this to "Debugger("X"); */
157 /***************************************************************
159 ***************************************************************/
162 ngc_attach(struct socket
*so
, int proto
, struct pru_attach_info
*ai
)
164 struct ngpcb
*const pcbp
= sotongpcb(so
);
166 if (priv_check_cred(ai
->p_ucred
, PRIV_ROOT
, NULL_CRED_OKAY
) != 0)
170 return (ng_attach_cntl(so
));
174 ngc_detach(struct socket
*so
)
176 struct ngpcb
*const pcbp
= sotongpcb(so
);
180 ng_detach_common(pcbp
, NG_CONTROL
);
185 ngc_send(struct socket
*so
, int flags
, struct mbuf
*m
, struct sockaddr
*addr
,
186 struct mbuf
*control
, struct thread
*td
)
188 struct ngpcb
*const pcbp
= sotongpcb(so
);
189 struct sockaddr_ng
*const sap
= (struct sockaddr_ng
*) addr
;
190 struct ng_mesg
*resp
;
192 char *msg
, *path
= NULL
;
200 if (control
&& (error
= ng_internalize(control
, p
))) {
201 if (pcbp
->sockdata
== NULL
) {
213 /* Require destination as there may be >= 1 hooks on this node */
215 error
= EDESTADDRREQ
;
219 /* Allocate an expendable buffer for the path, chop off
220 * the sockaddr header, and make sure it's NUL terminated */
221 len
= sap
->sg_len
- 2;
222 MALLOC(path
, char *, len
+ 1, M_NETGRAPH
, M_WAITOK
);
223 bcopy(sap
->sg_data
, path
, len
);
226 /* Move the actual message out of mbufs into a linear buffer.
227 * Start by adding up the size of the data. (could use mh_len?) */
228 for (len
= 0, m0
= m
; m0
!= NULL
; m0
= m0
->m_next
)
231 /* Move the data into a linear buffer as well. Messages are not
232 * delivered in mbufs. */
233 MALLOC(msg
, char *, len
+ 1, M_NETGRAPH
, M_WAITOK
);
234 m_copydata(m
, 0, len
, msg
);
236 /* The callee will free the msg when done. The addr is our business. */
237 error
= ng_send_msg(pcbp
->sockdata
->node
,
238 (struct ng_mesg
*) msg
, path
, &resp
);
240 /* If the callee responded with a synchronous response, then put it
241 * back on the receive side of the socket; sap is source address. */
242 if (error
== 0 && resp
!= NULL
)
243 error
= ship_msg(pcbp
, resp
, sap
);
247 FREE(path
, M_NETGRAPH
);
256 ngc_bind(struct socket
*so
, struct sockaddr
*nam
, struct thread
*td
)
258 struct ngpcb
*const pcbp
= sotongpcb(so
);
262 return (ng_bind(nam
, pcbp
));
266 ngc_connect(struct socket
*so
, struct sockaddr
*nam
, struct thread
*td
)
268 struct ngpcb
*const pcbp
= sotongpcb(so
);
272 return (ng_connect_cntl(nam
, pcbp
));
275 /***************************************************************
277 ***************************************************************/
280 ngd_attach(struct socket
*so
, int proto
, struct pru_attach_info
*ai
)
282 struct ngpcb
*const pcbp
= sotongpcb(so
);
286 return (ng_attach_data(so
));
290 ngd_detach(struct socket
*so
)
292 struct ngpcb
*const pcbp
= sotongpcb(so
);
296 ng_detach_common(pcbp
, NG_DATA
);
301 ngd_send(struct socket
*so
, int flags
, struct mbuf
*m
, struct sockaddr
*addr
,
302 struct mbuf
*control
, struct thread
*td
)
304 struct ngpcb
*const pcbp
= sotongpcb(so
);
305 struct sockaddr_ng
*const sap
= (struct sockaddr_ng
*) addr
;
309 char hookname
[NG_HOOKSIZ
];
311 if ((pcbp
== NULL
) || (control
!= NULL
)) {
315 if (pcbp
->sockdata
== NULL
) {
320 * If the user used any of these ways to not specify an address
321 * then handle specially.
324 || ((len
= sap
->sg_len
- 2) <= 0)
325 || (*sap
->sg_data
== '\0')) {
326 if (pcbp
->sockdata
->node
->numhooks
!= 1) {
327 error
= EDESTADDRREQ
;
331 * if exactly one hook exists, just use it.
332 * Special case to allow write(2) to work on an ng_socket.
334 hook
= LIST_FIRST(&pcbp
->sockdata
->node
->hooks
);
336 if (len
>= NG_HOOKSIZ
) {
342 * chop off the sockaddr header, and make sure it's NUL
345 bcopy(sap
->sg_data
, hookname
, len
);
346 hookname
[len
] = '\0';
348 /* Find the correct hook from 'hookname' */
349 LIST_FOREACH(hook
, &pcbp
->sockdata
->node
->hooks
, hooks
) {
350 if (strcmp(hookname
, hook
->name
) == 0)
354 error
= EHOSTUNREACH
;
357 /* Send data (OK if hook is NULL) */
358 NG_SEND_DATA(error
, hook
, m
, mp
); /* makes m NULL */
369 ngd_connect(struct socket
*so
, struct sockaddr
*nam
, struct thread
*td
)
371 struct ngpcb
*const pcbp
= sotongpcb(so
);
375 return (ng_connect_data(nam
, pcbp
));
379 * Used for both data and control sockets
382 ng_setsockaddr(struct socket
*so
, struct sockaddr
**addr
)
385 struct sockaddr_ng
*sg
;
388 /* Why isn't sg_data a `char[1]' ? :-( */
389 sg_len
= sizeof(struct sockaddr_ng
) - sizeof(sg
->sg_data
) + 1;
392 pcbp
= sotongpcb(so
);
393 if ((pcbp
== 0) || (pcbp
->sockdata
== NULL
)) {
398 namelen
= 0; /* silence compiler ! */
400 if (pcbp
->sockdata
->node
->name
!= NULL
)
401 sg_len
+= namelen
= strlen(pcbp
->sockdata
->node
->name
);
403 MALLOC(sg
, struct sockaddr_ng
*, sg_len
, M_SONAME
, M_WAITOK
| M_ZERO
);
405 if (pcbp
->sockdata
->node
->name
!= NULL
)
406 bcopy(pcbp
->sockdata
->node
->name
, sg
->sg_data
, namelen
);
410 sg
->sg_family
= AF_NETGRAPH
;
411 *addr
= (struct sockaddr
*)sg
;
417 * Attach a socket to it's protocol specific partner.
418 * For a control socket, actually create a netgraph node and attach
423 ng_attach_cntl(struct socket
*so
)
425 struct ngsock
*privdata
;
429 /* Setup protocol control block */
430 if ((error
= ng_attach_common(so
, NG_CONTROL
)) != 0)
432 pcbp
= sotongpcb(so
);
434 /* Allocate node private info */
435 MALLOC(privdata
, struct ngsock
*,
436 sizeof(*privdata
), M_NETGRAPH
, M_WAITOK
| M_ZERO
);
438 /* Make the generic node components */
439 if ((error
= ng_make_node_common(&typestruct
, &privdata
->node
)) != 0) {
440 FREE(privdata
, M_NETGRAPH
);
441 ng_detach_common(pcbp
, NG_CONTROL
);
444 privdata
->node
->private = privdata
;
446 /* Link the pcb and the node private data */
447 privdata
->ctlsock
= pcbp
;
448 pcbp
->sockdata
= privdata
;
454 ng_attach_data(struct socket
*so
)
456 return(ng_attach_common(so
, NG_DATA
));
460 * Set up a socket protocol control block.
461 * This code is shared between control and data sockets.
464 ng_attach_common(struct socket
*so
, int type
)
469 /* Standard socket setup stuff */
470 error
= soreserve(so
, ngpdg_sendspace
, ngpdg_recvspace
, NULL
);
474 /* Allocate the pcb */
475 MALLOC(pcbp
, struct ngpcb
*, sizeof(*pcbp
), M_PCB
, M_WAITOK
| M_ZERO
);
478 /* Link the pcb and the socket */
479 so
->so_pcb
= (caddr_t
) pcbp
;
480 pcbp
->ng_socket
= so
;
482 /* Add the socket to linked list */
483 LIST_INSERT_HEAD(&ngsocklist
, pcbp
, socks
);
488 * Disassociate the socket from it's protocol specific
489 * partner. If it's attached to a node's private data structure,
490 * then unlink from that too. If we were the last socket attached to it,
491 * then shut down the entire node. Shared code for control and data sockets.
494 ng_detach_common(struct ngpcb
*pcbp
, int which
)
496 struct ngsock
*sockdata
;
498 if (pcbp
->sockdata
) {
499 sockdata
= pcbp
->sockdata
;
500 pcbp
->sockdata
= NULL
;
503 sockdata
->ctlsock
= NULL
;
506 sockdata
->datasock
= NULL
;
511 if ((--sockdata
->refs
== 0) && (sockdata
->node
!= NULL
))
512 ng_rmnode(sockdata
->node
);
514 pcbp
->ng_socket
->so_pcb
= NULL
;
515 pcbp
->ng_socket
= NULL
;
516 LIST_REMOVE(pcbp
, socks
);
522 * File descriptors can be passed into a AF_NETGRAPH socket.
523 * Note, that file descriptors cannot be passed OUT.
524 * Only character device descriptors are accepted.
525 * Character devices are useful to connect a graph to a device,
526 * which after all is the purpose of this whole system.
529 ng_internalize(struct mbuf
*control
, struct thread
*td
)
531 struct filedesc
*fdp
= p
->p_fd
;
532 const struct cmsghdr
*cm
= mtod(control
, const struct cmsghdr
*);
538 if (cm
->cmsg_type
!= SCM_RIGHTS
|| cm
->cmsg_level
!= SOL_SOCKET
||
539 cm
->cmsg_len
!= control
->m_len
) {
544 /* Check there is only one FD. XXX what would more than one signify? */
545 oldfds
= (cm
->cmsg_len
- sizeof(*cm
)) / sizeof(int);
551 /* Check that the FD given is legit. and change it to a pointer to a
553 fd
= *(int *) (cm
+ 1);
554 if ((unsigned) fd
>= fdp
->fd_nfiles
555 || (fp
= fdp
->fd_files
[fd
].fp
) == NULL
) {
559 /* Depending on what kind of resource it is, act differently. For
560 * devices, we treat it as a file. For a AF_NETGRAPH socket,
561 * shortcut straight to the node. */
562 switch (fp
->f_type
) {
564 vn
= (struct vnode
*) fp
->f_data
;
565 if (vn
&& (vn
->v_type
== VCHR
)) {
566 /* for a VCHR, actually reference the FILE */
568 /* XXX then what :) */
569 /* how to pass on to other modules? */
584 * Connect the data socket to a named control socket node.
587 ng_connect_data(struct sockaddr
*nam
, struct ngpcb
*pcbp
)
589 struct sockaddr_ng
*sap
;
591 struct ngsock
*sockdata
;
594 /* If we are already connected, don't do it again */
595 if (pcbp
->sockdata
!= NULL
)
598 /* Find the target (victim) and check it doesn't already have a data
599 * socket. Also check it is a 'socket' type node. */
600 sap
= (struct sockaddr_ng
*) nam
;
601 if ((error
= ng_path2node(NULL
, sap
->sg_data
, &farnode
, NULL
)))
604 if (strcmp(farnode
->type
->name
, NG_SOCKET_NODE_TYPE
) != 0)
606 sockdata
= farnode
->private;
607 if (sockdata
->datasock
!= NULL
)
610 /* Link the PCB and the private data struct. and note the extra
612 sockdata
->datasock
= pcbp
;
613 pcbp
->sockdata
= sockdata
;
619 * Connect the existing control socket node to a named node:hook.
620 * The hook we use on this end is the same name as the remote node name.
623 ng_connect_cntl(struct sockaddr
*nam
, struct ngpcb
*pcbp
)
625 struct ngsock
*const sockdata
= pcbp
->sockdata
;
626 struct sockaddr_ng
*sap
;
631 sap
= (struct sockaddr_ng
*) nam
;
632 rtn
= ng_path_parse(sap
->sg_data
, &node
, NULL
, &hook
);
633 if (rtn
< 0 || node
== NULL
|| hook
== NULL
) {
637 farnode
= ng_findname(sockdata
->node
, node
);
638 if (farnode
== NULL
) {
640 return (EADDRNOTAVAIL
);
643 /* Connect, using a hook name the same as the far node name. */
644 error
= ng_con_nodes(sockdata
->node
, node
, farnode
, hook
);
649 * Binding a socket means giving the corresponding node a name
652 ng_bind(struct sockaddr
*nam
, struct ngpcb
*pcbp
)
654 struct ngsock
*const sockdata
= pcbp
->sockdata
;
655 struct sockaddr_ng
*const sap
= (struct sockaddr_ng
*) nam
;
657 if (sockdata
== NULL
) {
661 if (sap
->sg_len
< 3 || sap
->sg_data
[sap
->sg_len
- 3] != '\0') {
665 return (ng_name_node(sockdata
->node
, sap
->sg_data
));
669 * Take a message and pass it up to the control socket associated
673 ship_msg(struct ngpcb
*pcbp
, struct ng_mesg
*msg
, struct sockaddr_ng
*addr
)
675 struct socket
*const so
= pcbp
->ng_socket
;
679 /* Copy the message itself into an mbuf chain */
680 msglen
= sizeof(struct ng_mesg
) + msg
->header
.arglen
;
681 mdata
= m_devget((caddr_t
) msg
, msglen
, 0, NULL
, NULL
);
683 /* Here we free the message, as we are the end of the line.
684 * We need to do that regardless of whether we got mbufs. */
685 FREE(msg
, M_NETGRAPH
);
692 /* Send it up to the socket */
693 if (ssb_appendaddr(&so
->so_rcv
,
694 (struct sockaddr
*) addr
, mdata
, NULL
) == 0) {
704 * You can only create new nodes from the socket end of things.
707 ngs_constructor(node_p
*nodep
)
713 * We allow any hook to be connected to the node.
714 * There is no per-hook private information though.
717 ngs_newhook(node_p node
, hook_p hook
, const char *name
)
719 hook
->private = node
->private;
724 * Incoming messages get passed up to the control socket.
725 * Unless they are for us specifically (socket_type)
728 ngs_rcvmsg(node_p node
, struct ng_mesg
*msg
, const char *retaddr
,
729 struct ng_mesg
**resp
)
731 struct ngsock
*const sockdata
= node
->private;
732 struct ngpcb
*const pcbp
= sockdata
->ctlsock
;
733 struct sockaddr_ng
*addr
;
737 /* Only allow mesgs to be passed if we have the control socket.
738 * Data sockets can only support the generic messages. */
744 if (msg
->header
.typecookie
== NGM_SOCKET_COOKIE
) {
745 switch (msg
->header
.cmd
) {
746 case NGM_SOCK_CMD_NOLINGER
:
747 sockdata
->flags
|= NGS_FLAG_NOLINGER
;
749 case NGM_SOCK_CMD_LINGER
:
750 sockdata
->flags
&= ~NGS_FLAG_NOLINGER
;
753 error
= EINVAL
; /* unknown command */
755 /* Free the message and return */
756 FREE(msg
, M_NETGRAPH
);
760 /* Get the return address into a sockaddr */
761 if ((retaddr
== NULL
) || (*retaddr
== '\0'))
763 addrlen
= strlen(retaddr
);
764 MALLOC(addr
, struct sockaddr_ng
*, addrlen
+ 4, M_NETGRAPH
, M_NOWAIT
);
769 addr
->sg_len
= addrlen
+ 3;
770 addr
->sg_family
= AF_NETGRAPH
;
771 bcopy(retaddr
, addr
->sg_data
, addrlen
);
772 addr
->sg_data
[addrlen
] = '\0';
775 error
= ship_msg(pcbp
, msg
, addr
);
776 FREE(addr
, M_NETGRAPH
);
781 * Receive data on a hook
784 ngs_rcvdata(hook_p hook
, struct mbuf
*m
, meta_p meta
)
786 struct ngsock
*const sockdata
= hook
->node
->private;
787 struct ngpcb
*const pcbp
= sockdata
->datasock
;
789 struct sockaddr_ng
*addr
;
790 char *addrbuf
[NG_HOOKSIZ
+ 4];
793 /* If there is no data socket, black-hole it */
795 NG_FREE_DATA(m
, meta
);
798 so
= pcbp
->ng_socket
;
800 /* Get the return address into a sockaddr. */
801 addrlen
= strlen(hook
->name
); /* <= NG_HOOKSIZ - 1 */
802 addr
= (struct sockaddr_ng
*) addrbuf
;
803 addr
->sg_len
= addrlen
+ 3;
804 addr
->sg_family
= AF_NETGRAPH
;
805 bcopy(hook
->name
, addr
->sg_data
, addrlen
);
806 addr
->sg_data
[addrlen
] = '\0';
808 /* We have no use for the meta data, free/clear it now. */
811 /* Try to tell the socket which hook it came in on */
812 if (ssb_appendaddr(&so
->so_rcv
, (struct sockaddr
*) addr
, m
, NULL
) == 0) {
824 * For this type, removal of the last link destroys the node
825 * if the NOLINGER flag is set.
828 ngs_disconnect(hook_p hook
)
830 struct ngsock
*const sockdata
= hook
->node
->private;
832 if ((sockdata
->flags
& NGS_FLAG_NOLINGER
)
833 && (hook
->node
->numhooks
== 0)) {
834 ng_rmnode(hook
->node
);
840 * Do local shutdown processing.
841 * In this case, that involves making sure the socket
842 * knows we should be shutting down.
845 ngs_rmnode(node_p node
)
847 struct ngsock
*const sockdata
= node
->private;
848 struct ngpcb
*const dpcbp
= sockdata
->datasock
;
849 struct ngpcb
*const pcbp
= sockdata
->ctlsock
;
855 soisdisconnected(dpcbp
->ng_socket
);
856 dpcbp
->sockdata
= NULL
;
857 sockdata
->datasock
= NULL
;
861 soisdisconnected(pcbp
->ng_socket
);
862 pcbp
->sockdata
= NULL
;
863 sockdata
->ctlsock
= NULL
;
866 node
->private = NULL
;
868 FREE(sockdata
, M_NETGRAPH
);
873 * Control and data socket type descriptors
876 static struct pr_usrreqs ngc_usrreqs
= {
878 .pru_accept
= pru_accept_notsupp
,
879 .pru_attach
= ngc_attach
,
880 .pru_bind
= ngc_bind
,
881 .pru_connect
= ngc_connect
,
882 .pru_connect2
= pru_connect2_notsupp
,
883 .pru_control
= pru_control_notsupp
,
884 .pru_detach
= ngc_detach
,
885 .pru_disconnect
= NULL
,
886 .pru_listen
= pru_listen_notsupp
,
887 .pru_peeraddr
= NULL
,
888 .pru_rcvd
= pru_rcvd_notsupp
,
889 .pru_rcvoob
= pru_rcvoob_notsupp
,
890 .pru_send
= ngc_send
,
891 .pru_sense
= pru_sense_null
,
892 .pru_shutdown
= NULL
,
893 .pru_sockaddr
= ng_setsockaddr
,
894 .pru_sosend
= sosend
,
895 .pru_soreceive
= soreceive
,
899 static struct pr_usrreqs ngd_usrreqs
= {
901 .pru_accept
= pru_accept_notsupp
,
902 .pru_attach
= ngd_attach
,
904 .pru_connect
= ngd_connect
,
905 .pru_connect2
= pru_connect2_notsupp
,
906 .pru_control
= pru_control_notsupp
,
907 .pru_detach
= ngd_detach
,
908 .pru_disconnect
= NULL
,
909 .pru_listen
= pru_listen_notsupp
,
910 .pru_peeraddr
= NULL
,
911 .pru_rcvd
= pru_rcvd_notsupp
,
912 .pru_rcvoob
= pru_rcvoob_notsupp
,
913 .pru_send
= ngd_send
,
914 .pru_sense
= pru_sense_null
,
915 .pru_shutdown
= NULL
,
916 .pru_sockaddr
= ng_setsockaddr
,
917 .pru_sosend
= sosend
,
918 .pru_soreceive
= soreceive
,
923 * Definitions of protocols supported in the NETGRAPH domain.
926 extern struct domain ngdomain
; /* stop compiler warnings */
928 static struct protosw ngsw
[] = {
933 PR_ATOMIC
| PR_ADDR
/* | PR_RIGHTS */,
951 struct domain ngdomain
= {
952 AF_NETGRAPH
, "netgraph", NULL
, NULL
, NULL
,
953 ngsw
, &ngsw
[sizeof(ngsw
) / sizeof(ngsw
[0])],
957 * Handle loading and unloading for this node type
958 * This is to handle auxiliary linkages (e.g protocol domain addition).
961 ngs_mod_event(module_t mod
, int event
, void *data
)
967 /* Register protocol domain */
968 net_add_domain(&ngdomain
);
971 /* Insure there are no open netgraph sockets */
972 if (!LIST_EMPTY(&ngsocklist
)) {
978 /* Unregister protocol domain XXX can't do this yet.. */
979 if ((error
= net_rm_domain(&ngdomain
)) != 0)
992 SYSCTL_INT(_net_graph
, OID_AUTO
, family
, CTLFLAG_RD
, 0, AF_NETGRAPH
, "");
993 SYSCTL_NODE(_net_graph
, OID_AUTO
, data
, CTLFLAG_RW
, 0, "DATA");
994 SYSCTL_INT(_net_graph_data
, OID_AUTO
, proto
, CTLFLAG_RD
, 0, NG_DATA
, "");
995 SYSCTL_NODE(_net_graph
, OID_AUTO
, control
, CTLFLAG_RW
, 0, "CONTROL");
996 SYSCTL_INT(_net_graph_control
, OID_AUTO
, proto
, CTLFLAG_RD
, 0, NG_CONTROL
, "");