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                         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;


1526                  */
1527                 error = 0;
1528                 break;
1529         }
1530 
1531         return (error);
1532 }
1533 
1534 /*
1535  * Upcall made by the protocol when it's doing an asynchronous close. It
1536  * will drop the protocol's reference on the socket.
1537  */
1538 void
1539 so_closed(sock_upper_handle_t sock_handle)
1540 {
1541         struct sonode *so = (struct sonode *)sock_handle;
1542 
1543         VN_RELE(SOTOV(so));
1544 }
1545 
1546 mblk_t *
1547 so_get_sock_pid_mblk(sock_upper_handle_t sock_handle)
1548 {
1549         int sz, n = 0;
1550         mblk_t *mblk;
1551         pid_node_t *pn;
1552         pid_t *pids;
1553         conn_pid_info_t *cpi;
1554         struct sonode *so = (struct sonode *)sock_handle;
1555 
1556         mutex_enter(&so->so_pid_list_lock);
1557 
1558         n = list_numnodes(&so->so_pid_list);
1559         sz = sizeof (conn_pid_info_t);
1560         sz += (n > 1) ? ((n - 1) * sizeof (pid_t)) : 0;
1561         if ((mblk = allocb(sz, BPRI_HI)) == NULL) {
1562                 mutex_exit(&so->so_pid_list_lock);
1563                 return (NULL);
1564         }
1565         mblk->b_wptr += sz;
1566         cpi = (conn_pid_info_t *)mblk->b_datap->db_base;
1567 
1568         cpi->cpi_magic = CONN_PID_INFO_MGC;
1569         cpi->cpi_contents = CONN_PID_INFO_SOC;
1570         cpi->cpi_pids_cnt = n;
1571         cpi->cpi_tot_size = sz;
1572         cpi->cpi_pids[0] = 0;
1573 
1574         if (cpi->cpi_pids_cnt > 0) {
1575                 pids = cpi->cpi_pids;
1576                 for (pn = list_head(&so->so_pid_list); pn != NULL;
1577                     pids++, pn = list_next(&so->so_pid_list, pn))
1578                         *pids = pn->pn_pid;
1579         }
1580         mutex_exit(&so->so_pid_list_lock);
1581         return (mblk);
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_mblk
1986 };