Deleted Added
full compact
ng_socket.c (89066) ng_socket.c (89306)
1
2/*
3 * ng_socket.c
4 *
5 * Copyright (c) 1996-1999 Whistle Communications, Inc.
6 * All rights reserved.
7 *
8 * Subject to the following obligations and disclaimer of warranty, use and

--- 22 unchanged lines hidden (view full) ---

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
35 * OF SUCH DAMAGE.
36 *
37 * Author: Julian Elischer <julian@freebsd.org>
38 *
1
2/*
3 * ng_socket.c
4 *
5 * Copyright (c) 1996-1999 Whistle Communications, Inc.
6 * All rights reserved.
7 *
8 * Subject to the following obligations and disclaimer of warranty, use and

--- 22 unchanged lines hidden (view full) ---

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
35 * OF SUCH DAMAGE.
36 *
37 * Author: Julian Elischer <julian@freebsd.org>
38 *
39 * $FreeBSD: head/sys/netgraph/ng_socket.c 89066 2002-01-08 10:30:34Z msmith $
39 * $FreeBSD: head/sys/netgraph/ng_socket.c 89306 2002-01-13 11:58:06Z alfred $
40 * $Whistle: ng_socket.c,v 1.28 1999/11/01 09:24:52 julian Exp $
41 */
42
43/*
44 * Netgraph socket nodes
45 *
46 * There are two types of netgraph sockets, control and data.
47 * Control sockets have a netgraph node, but data sockets are

--- 516 unchanged lines hidden (view full) ---

564 * Note, that file descriptors cannot be passed OUT.
565 * Only character device descriptors are accepted.
566 * Character devices are useful to connect a graph to a device,
567 * which after all is the purpose of this whole system.
568 */
569static int
570ng_internalize(struct mbuf *control, struct thread *td)
571{
40 * $Whistle: ng_socket.c,v 1.28 1999/11/01 09:24:52 julian Exp $
41 */
42
43/*
44 * Netgraph socket nodes
45 *
46 * There are two types of netgraph sockets, control and data.
47 * Control sockets have a netgraph node, but data sockets are

--- 516 unchanged lines hidden (view full) ---

564 * Note, that file descriptors cannot be passed OUT.
565 * Only character device descriptors are accepted.
566 * Character devices are useful to connect a graph to a device,
567 * which after all is the purpose of this whole system.
568 */
569static int
570ng_internalize(struct mbuf *control, struct thread *td)
571{
572 struct filedesc *fdp = td->td_proc->p_fd;
573 struct cmsghdr *cm = mtod(control, struct cmsghdr *);
574 struct file *fp;
575 struct vnode *vn;
576 int oldfds;
577 int fd;
578
579 if (cm->cmsg_type != SCM_RIGHTS || cm->cmsg_level != SOL_SOCKET ||
580 cm->cmsg_len != control->m_len) {

--- 6 unchanged lines hidden (view full) ---

587 if (oldfds != 1) {
588 TRAP_ERROR;
589 return (EINVAL);
590 }
591
592 /* Check that the FD given is legit. and change it to a pointer to a
593 * struct file. */
594 fd = CMSG_DATA(cm);
572 struct cmsghdr *cm = mtod(control, struct cmsghdr *);
573 struct file *fp;
574 struct vnode *vn;
575 int oldfds;
576 int fd;
577
578 if (cm->cmsg_type != SCM_RIGHTS || cm->cmsg_level != SOL_SOCKET ||
579 cm->cmsg_len != control->m_len) {

--- 6 unchanged lines hidden (view full) ---

586 if (oldfds != 1) {
587 TRAP_ERROR;
588 return (EINVAL);
589 }
590
591 /* Check that the FD given is legit. and change it to a pointer to a
592 * struct file. */
593 fd = CMSG_DATA(cm);
595 if ((unsigned) fd >= fdp->fd_nfiles
596 || (fp = fdp->fd_ofiles[fd]) == NULL) {
594 fp = ffind_hold(td, fd);
595 if (fp == NULL)
597 return (EBADF);
596 return (EBADF);
598 }
599
600 /* Depending on what kind of resource it is, act differently. For
601 * devices, we treat it as a file. For a AF_NETGRAPH socket,
602 * shortcut straight to the node. */
603 switch (fp->f_type) {
604 case DTYPE_VNODE:
605 vn = (struct vnode *) fp->f_data;
606 if (vn && (vn->v_type == VCHR)) {
607 /* for a VCHR, actually reference the FILE */
608 fp->f_count++;
609 /* XXX then what :) */
610 /* how to pass on to other modules? */
611 } else {
597
598 /* Depending on what kind of resource it is, act differently. For
599 * devices, we treat it as a file. For a AF_NETGRAPH socket,
600 * shortcut straight to the node. */
601 switch (fp->f_type) {
602 case DTYPE_VNODE:
603 vn = (struct vnode *) fp->f_data;
604 if (vn && (vn->v_type == VCHR)) {
605 /* for a VCHR, actually reference the FILE */
606 fp->f_count++;
607 /* XXX then what :) */
608 /* how to pass on to other modules? */
609 } else {
610 fdrop(fp, td);
612 TRAP_ERROR;
613 return (EINVAL);
614 }
615 break;
616 default:
611 TRAP_ERROR;
612 return (EINVAL);
613 }
614 break;
615 default:
616 fdrop(fp, td);
617 TRAP_ERROR;
618 return (EINVAL);
619 }
617 TRAP_ERROR;
618 return (EINVAL);
619 }
620 fdrop(fp, td);
620 return (0);
621}
622#endif /* NOTYET */
623
624/*
625 * Connect the data socket to a named control socket node.
626 */
627static int

--- 465 unchanged lines hidden ---
621 return (0);
622}
623#endif /* NOTYET */
624
625/*
626 * Connect the data socket to a named control socket node.
627 */
628static int

--- 465 unchanged lines hidden ---