20 */
21
22 /*
23 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 /*
27 * Copyright (c) 2014, Joyent, Inc. All rights reserved.
28 */
29
30 #include <sys/types.h>
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/sysmacros.h>
34 #include <sys/debug.h>
35 #include <sys/cmn_err.h>
36
37 #include <sys/stropts.h>
38 #include <sys/socket.h>
39 #include <sys/socketvar.h>
40
41 #define _SUN_TPI_VERSION 2
42 #include <sys/tihdr.h>
43 #include <sys/sockio.h>
44 #include <sys/kmem_impl.h>
45
46 #include <sys/strsubr.h>
47 #include <sys/strsun.h>
48 #include <sys/ddi.h>
49 #include <netinet/in.h>
50 #include <inet/ip.h>
51
52 #include <fs/sockfs/sockcommon.h>
53 #include <fs/sockfs/sockfilter_impl.h>
54
55 #include <sys/socket_proto.h>
56
57 #include <fs/sockfs/socktpi_impl.h>
58 #include <fs/sockfs/sodirect.h>
59 #include <sys/tihdr.h>
340 SO_BLOCK_FALLBACK(so, SOP_ACCEPT(so, fflag, cr, nsop));
341 if ((so->so_state & SS_ACCEPTCONN) == 0) {
342 SO_UNBLOCK_FALLBACK(so);
343 return ((so->so_type == SOCK_DGRAM || so->so_type == SOCK_RAW) ?
344 EOPNOTSUPP : EINVAL);
345 }
346
347 if ((error = so_acceptq_dequeue(so, (fflag & (FNONBLOCK|FNDELAY)),
348 &nso)) == 0) {
349 ASSERT(nso != NULL);
350
351 /* finish the accept */
352 if ((so->so_filter_active > 0 &&
353 (error = sof_filter_accept(nso, cr)) > 0) ||
354 (error = (*so->so_downcalls->sd_accept)(so->so_proto_handle,
355 nso->so_proto_handle, (sock_upper_handle_t)nso, cr)) != 0) {
356 (void) socket_close(nso, 0, cr);
357 socket_destroy(nso);
358 } else {
359 *nsop = nso;
360 }
361 }
362
363 SO_UNBLOCK_FALLBACK(so);
364 return (error);
365 }
366
367 int
368 so_sendmsg(struct sonode *so, struct nmsghdr *msg, struct uio *uiop,
369 struct cred *cr)
370 {
371 int error, flags;
372 boolean_t dontblock;
373 ssize_t orig_resid;
374 mblk_t *mp;
375
376 SO_BLOCK_FALLBACK(so, SOP_SENDMSG(so, msg, uiop, cr));
377
378 flags = msg->msg_flags;
379 error = 0;
1536 */
1537 error = 0;
1538 break;
1539 }
1540
1541 return (error);
1542 }
1543
1544 /*
1545 * Upcall made by the protocol when it's doing an asynchronous close. It
1546 * will drop the protocol's reference on the socket.
1547 */
1548 void
1549 so_closed(sock_upper_handle_t sock_handle)
1550 {
1551 struct sonode *so = (struct sonode *)sock_handle;
1552
1553 VN_RELE(SOTOV(so));
1554 }
1555
1556 void
1557 so_zcopy_notify(sock_upper_handle_t sock_handle)
1558 {
1559 struct sonode *so = (struct sonode *)sock_handle;
1560
1561 mutex_enter(&so->so_lock);
1562 so->so_copyflag |= STZCNOTIFY;
1563 cv_broadcast(&so->so_copy_cv);
1564 mutex_exit(&so->so_lock);
1565 }
1566
1567 void
1568 so_set_error(sock_upper_handle_t sock_handle, int error)
1569 {
1570 struct sonode *so = (struct sonode *)sock_handle;
1571
1572 mutex_enter(&so->so_lock);
1573
1574 soseterror(so, error);
1575
1936 so_getsockname, /* sop_getsockname */
1937 so_shutdown, /* sop_shutdown */
1938 so_getsockopt, /* sop_getsockopt */
1939 so_setsockopt, /* sop_setsockopt */
1940 so_ioctl, /* sop_ioctl */
1941 so_poll, /* sop_poll */
1942 so_close, /* sop_close */
1943 };
1944
1945 sock_upcalls_t so_upcalls = {
1946 so_newconn,
1947 so_connected,
1948 so_disconnected,
1949 so_opctl,
1950 so_queue_msg,
1951 so_set_prop,
1952 so_txq_full,
1953 so_signal_oob,
1954 so_zcopy_notify,
1955 so_set_error,
1956 so_closed
1957 };
|
20 */
21
22 /*
23 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 /*
27 * Copyright (c) 2014, Joyent, Inc. All rights reserved.
28 */
29
30 #include <sys/types.h>
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/sysmacros.h>
34 #include <sys/debug.h>
35 #include <sys/cmn_err.h>
36
37 #include <sys/stropts.h>
38 #include <sys/socket.h>
39 #include <sys/socketvar.h>
40 #include <sys/fcntl.h>
41
42 #define _SUN_TPI_VERSION 2
43 #include <sys/tihdr.h>
44 #include <sys/sockio.h>
45 #include <sys/kmem_impl.h>
46
47 #include <sys/strsubr.h>
48 #include <sys/strsun.h>
49 #include <sys/ddi.h>
50 #include <netinet/in.h>
51 #include <inet/ip.h>
52
53 #include <fs/sockfs/sockcommon.h>
54 #include <fs/sockfs/sockfilter_impl.h>
55
56 #include <sys/socket_proto.h>
57
58 #include <fs/sockfs/socktpi_impl.h>
59 #include <fs/sockfs/sodirect.h>
60 #include <sys/tihdr.h>
341 SO_BLOCK_FALLBACK(so, SOP_ACCEPT(so, fflag, cr, nsop));
342 if ((so->so_state & SS_ACCEPTCONN) == 0) {
343 SO_UNBLOCK_FALLBACK(so);
344 return ((so->so_type == SOCK_DGRAM || so->so_type == SOCK_RAW) ?
345 EOPNOTSUPP : EINVAL);
346 }
347
348 if ((error = so_acceptq_dequeue(so, (fflag & (FNONBLOCK|FNDELAY)),
349 &nso)) == 0) {
350 ASSERT(nso != NULL);
351
352 /* finish the accept */
353 if ((so->so_filter_active > 0 &&
354 (error = sof_filter_accept(nso, cr)) > 0) ||
355 (error = (*so->so_downcalls->sd_accept)(so->so_proto_handle,
356 nso->so_proto_handle, (sock_upper_handle_t)nso, cr)) != 0) {
357 (void) socket_close(nso, 0, cr);
358 socket_destroy(nso);
359 } else {
360 *nsop = nso;
361 if (!(curproc->p_flag & SSYS))
362 sonode_insert_pid(nso, curproc->p_pidp->pid_id);
363 }
364 }
365
366 SO_UNBLOCK_FALLBACK(so);
367 return (error);
368 }
369
370 int
371 so_sendmsg(struct sonode *so, struct nmsghdr *msg, struct uio *uiop,
372 struct cred *cr)
373 {
374 int error, flags;
375 boolean_t dontblock;
376 ssize_t orig_resid;
377 mblk_t *mp;
378
379 SO_BLOCK_FALLBACK(so, SOP_SENDMSG(so, msg, uiop, cr));
380
381 flags = msg->msg_flags;
382 error = 0;
1539 */
1540 error = 0;
1541 break;
1542 }
1543
1544 return (error);
1545 }
1546
1547 /*
1548 * Upcall made by the protocol when it's doing an asynchronous close. It
1549 * will drop the protocol's reference on the socket.
1550 */
1551 void
1552 so_closed(sock_upper_handle_t sock_handle)
1553 {
1554 struct sonode *so = (struct sonode *)sock_handle;
1555
1556 VN_RELE(SOTOV(so));
1557 }
1558
1559 mblk_t *
1560 so_get_sock_pid_mblk(sock_upper_handle_t sock_handle)
1561 {
1562 ulong_t sz, n;
1563 mblk_t *mblk;
1564 pid_node_t *pn;
1565 pid_t *pids;
1566 conn_pid_info_t *cpi;
1567 struct sonode *so = (struct sonode *)sock_handle;
1568
1569 mutex_enter(&so->so_pid_tree_lock);
1570
1571 n = avl_numnodes(&so->so_pid_tree);
1572 sz = sizeof (conn_pid_info_t);
1573 sz += (n > 1) ? ((n - 1) * sizeof (pid_t)) : 0;
1574 if ((mblk = allocb(sz, BPRI_HI)) == NULL) {
1575 mutex_exit(&so->so_pid_tree_lock);
1576 return (NULL);
1577 }
1578 mblk->b_wptr += sz;
1579 cpi = (conn_pid_info_t *)mblk->b_datap->db_base;
1580
1581 cpi->cpi_contents = CONN_PID_INFO_SOC;
1582 cpi->cpi_pids_cnt = n;
1583 cpi->cpi_tot_size = sz;
1584 cpi->cpi_pids[0] = 0;
1585
1586 if (cpi->cpi_pids_cnt > 0) {
1587 pids = cpi->cpi_pids;
1588 for (pn = avl_first(&so->so_pid_tree); pn != NULL;
1589 pids++, pn = AVL_NEXT(&so->so_pid_tree, pn))
1590 *pids = pn->pn_pid;
1591 }
1592 mutex_exit(&so->so_pid_tree_lock);
1593 return (mblk);
1594 }
1595
1596 void
1597 so_zcopy_notify(sock_upper_handle_t sock_handle)
1598 {
1599 struct sonode *so = (struct sonode *)sock_handle;
1600
1601 mutex_enter(&so->so_lock);
1602 so->so_copyflag |= STZCNOTIFY;
1603 cv_broadcast(&so->so_copy_cv);
1604 mutex_exit(&so->so_lock);
1605 }
1606
1607 void
1608 so_set_error(sock_upper_handle_t sock_handle, int error)
1609 {
1610 struct sonode *so = (struct sonode *)sock_handle;
1611
1612 mutex_enter(&so->so_lock);
1613
1614 soseterror(so, error);
1615
1976 so_getsockname, /* sop_getsockname */
1977 so_shutdown, /* sop_shutdown */
1978 so_getsockopt, /* sop_getsockopt */
1979 so_setsockopt, /* sop_setsockopt */
1980 so_ioctl, /* sop_ioctl */
1981 so_poll, /* sop_poll */
1982 so_close, /* sop_close */
1983 };
1984
1985 sock_upcalls_t so_upcalls = {
1986 so_newconn,
1987 so_connected,
1988 so_disconnected,
1989 so_opctl,
1990 so_queue_msg,
1991 so_set_prop,
1992 so_txq_full,
1993 so_signal_oob,
1994 so_zcopy_notify,
1995 so_set_error,
1996 so_closed,
1997 so_get_sock_pid_mblk
1998 };
|