Print this page
XXXX adding PID information to netstat output


  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;


1523                  */
1524                 error = 0;
1525                 break;
1526         }
1527 
1528         return (error);
1529 }
1530 
1531 /*
1532  * Upcall made by the protocol when it's doing an asynchronous close. It
1533  * will drop the protocol's reference on the socket.
1534  */
1535 void
1536 so_closed(sock_upper_handle_t sock_handle)
1537 {
1538         struct sonode *so = (struct sonode *)sock_handle;
1539 
1540         VN_RELE(SOTOV(so));
1541 }
1542 







































1543 void
1544 so_zcopy_notify(sock_upper_handle_t sock_handle)
1545 {
1546         struct sonode *so = (struct sonode *)sock_handle;
1547 
1548         mutex_enter(&so->so_lock);
1549         so->so_copyflag |= STZCNOTIFY;
1550         cv_broadcast(&so->so_copy_cv);
1551         mutex_exit(&so->so_lock);
1552 }
1553 
1554 void
1555 so_set_error(sock_upper_handle_t sock_handle, int error)
1556 {
1557         struct sonode *so = (struct sonode *)sock_handle;
1558 
1559         mutex_enter(&so->so_lock);
1560 
1561         soseterror(so, error);
1562 


1923         so_getsockname,         /* sop_getsockname */
1924         so_shutdown,            /* sop_shutdown */
1925         so_getsockopt,          /* sop_getsockopt */
1926         so_setsockopt,          /* sop_setsockopt */
1927         so_ioctl,               /* sop_ioctl    */
1928         so_poll,                /* sop_poll     */
1929         so_close,               /* sop_close */
1930 };
1931 
1932 sock_upcalls_t so_upcalls = {
1933         so_newconn,
1934         so_connected,
1935         so_disconnected,
1936         so_opctl,
1937         so_queue_msg,
1938         so_set_prop,
1939         so_txq_full,
1940         so_signal_oob,
1941         so_zcopy_notify,
1942         so_set_error,
1943         so_closed

1944 };


  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                         sonode_insert_pid(nso, curproc);
 362                 }
 363         }
 364 
 365         SO_UNBLOCK_FALLBACK(so);
 366         return (error);
 367 }
 368 
 369 int
 370 so_sendmsg(struct sonode *so, struct nmsghdr *msg, struct uio *uiop,
 371     struct cred *cr)
 372 {
 373         int error, flags;
 374         boolean_t dontblock;
 375         ssize_t orig_resid;
 376         mblk_t  *mp;
 377 
 378         SO_BLOCK_FALLBACK(so, SOP_SENDMSG(so, msg, uiop, cr));
 379 
 380         flags = msg->msg_flags;
 381         error = 0;


1525                  */
1526                 error = 0;
1527                 break;
1528         }
1529 
1530         return (error);
1531 }
1532 
1533 /*
1534  * Upcall made by the protocol when it's doing an asynchronous close. It
1535  * will drop the protocol's reference on the socket.
1536  */
1537 void
1538 so_closed(sock_upper_handle_t sock_handle)
1539 {
1540         struct sonode *so = (struct sonode *)sock_handle;
1541 
1542         VN_RELE(SOTOV(so));
1543 }
1544 
1545 conn_pid_node_list_hdr_t *
1546 so_get_sock_pid_list(sock_upper_handle_t sock_handle)
1547 {
1548         int sz, n = 0;
1549         pid_node_t                      *pn;
1550         conn_pid_node_t                 *cpn;
1551         conn_pid_node_list_hdr_t        *cph;
1552         struct sonode                   *so = (struct sonode *)sock_handle;
1553 
1554         mutex_enter(&so->so_pid_list_lock);
1555 
1556         n = list_size(&so->so_pid_list);
1557         sz = sizeof (conn_pid_node_list_hdr_t);
1558         sz += (n > 1)?((n - 1) * sizeof (conn_pid_node_t)):0;
1559         cph = kmem_zalloc(sz, KM_SLEEP);
1560 
1561         cph->cph_magic = CONN_PID_NODE_LIST_HDR_MAGIC;
1562         cph->cph_contents = CONN_PID_NODE_LIST_HDR_SOC;
1563         cph->cph_pn_cnt = n;
1564         cph->cph_tot_size = sz;
1565         cph->cph_flags = 0;
1566         cph->cph_optional1 = 0;
1567         cph->cph_optional2 = 0;
1568 
1569         if (cph->cph_pn_cnt > 0) {
1570                 cpn = cph->cph_cpns;
1571                 pn = list_head(&so->so_pid_list);
1572                 while (pn != NULL) {
1573                         PIDNODE2CONNPIDNODE(pn, cpn);
1574                         pn = list_next(&so->so_pid_list, pn);
1575                         cpn++;
1576                 }
1577         }
1578 
1579         mutex_exit(&so->so_pid_list_lock);
1580 
1581         return (cph);
1582 }
1583 
1584 void
1585 so_zcopy_notify(sock_upper_handle_t sock_handle)
1586 {
1587         struct sonode *so = (struct sonode *)sock_handle;
1588 
1589         mutex_enter(&so->so_lock);
1590         so->so_copyflag |= STZCNOTIFY;
1591         cv_broadcast(&so->so_copy_cv);
1592         mutex_exit(&so->so_lock);
1593 }
1594 
1595 void
1596 so_set_error(sock_upper_handle_t sock_handle, int error)
1597 {
1598         struct sonode *so = (struct sonode *)sock_handle;
1599 
1600         mutex_enter(&so->so_lock);
1601 
1602         soseterror(so, error);
1603 


1964         so_getsockname,         /* sop_getsockname */
1965         so_shutdown,            /* sop_shutdown */
1966         so_getsockopt,          /* sop_getsockopt */
1967         so_setsockopt,          /* sop_setsockopt */
1968         so_ioctl,               /* sop_ioctl    */
1969         so_poll,                /* sop_poll     */
1970         so_close,               /* sop_close */
1971 };
1972 
1973 sock_upcalls_t so_upcalls = {
1974         so_newconn,
1975         so_connected,
1976         so_disconnected,
1977         so_opctl,
1978         so_queue_msg,
1979         so_set_prop,
1980         so_txq_full,
1981         so_signal_oob,
1982         so_zcopy_notify,
1983         so_set_error,
1984         so_closed,
1985         so_get_sock_pid_list
1986 };