Print this page
XXXX adding PID information to netstat output

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/sockfs/sockcommon_sops.c
          +++ new/usr/src/uts/common/fs/sockfs/sockcommon_sops.c
↓ open down ↓ 29 lines elided ↑ open up ↑
  30   30  #include <sys/types.h>
  31   31  #include <sys/param.h>
  32   32  #include <sys/systm.h>
  33   33  #include <sys/sysmacros.h>
  34   34  #include <sys/debug.h>
  35   35  #include <sys/cmn_err.h>
  36   36  
  37   37  #include <sys/stropts.h>
  38   38  #include <sys/socket.h>
  39   39  #include <sys/socketvar.h>
       40 +#include <sys/fcntl.h>
  40   41  
  41   42  #define _SUN_TPI_VERSION        2
  42   43  #include <sys/tihdr.h>
  43   44  #include <sys/sockio.h>
  44   45  #include <sys/kmem_impl.h>
  45   46  
  46   47  #include <sys/strsubr.h>
  47   48  #include <sys/strsun.h>
  48   49  #include <sys/ddi.h>
  49   50  #include <netinet/in.h>
↓ open down ↓ 300 lines elided ↑ open up ↑
 350  351  
 351  352                  /* finish the accept */
 352  353                  if ((so->so_filter_active > 0 &&
 353  354                      (error = sof_filter_accept(nso, cr)) > 0) ||
 354  355                      (error = (*so->so_downcalls->sd_accept)(so->so_proto_handle,
 355  356                      nso->so_proto_handle, (sock_upper_handle_t)nso, cr)) != 0) {
 356  357                          (void) socket_close(nso, 0, cr);
 357  358                          socket_destroy(nso);
 358  359                  } else {
 359  360                          *nsop = nso;
      361 +                        if (!(curproc->p_flag & SSYS))
      362 +                                sonode_insert_pid(nso, curproc->p_pidp->pid_id);
 360  363                  }
 361  364          }
 362  365  
 363  366          SO_UNBLOCK_FALLBACK(so);
 364  367          return (error);
 365  368  }
 366  369  
 367  370  int
 368  371  so_sendmsg(struct sonode *so, struct nmsghdr *msg, struct uio *uiop,
 369  372      struct cred *cr)
↓ open down ↓ 1176 lines elided ↑ open up ↑
1546 1549   * will drop the protocol's reference on the socket.
1547 1550   */
1548 1551  void
1549 1552  so_closed(sock_upper_handle_t sock_handle)
1550 1553  {
1551 1554          struct sonode *so = (struct sonode *)sock_handle;
1552 1555  
1553 1556          VN_RELE(SOTOV(so));
1554 1557  }
1555 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_magic = CONN_PID_INFO_MGC;
     1582 +        cpi->cpi_contents = CONN_PID_INFO_SOC;
     1583 +        cpi->cpi_pids_cnt = n;
     1584 +        cpi->cpi_tot_size = sz;
     1585 +        cpi->cpi_pids[0] = 0;
     1586 +
     1587 +        if (cpi->cpi_pids_cnt > 0) {
     1588 +                pids = cpi->cpi_pids;
     1589 +                for (pn = avl_first(&so->so_pid_tree); pn != NULL;
     1590 +                    pids++, pn = AVL_NEXT(&so->so_pid_tree, pn))
     1591 +                        *pids = pn->pn_pid;
     1592 +        }
     1593 +        mutex_exit(&so->so_pid_tree_lock);
     1594 +        return (mblk);
     1595 +}
     1596 +
1556 1597  void
1557 1598  so_zcopy_notify(sock_upper_handle_t sock_handle)
1558 1599  {
1559 1600          struct sonode *so = (struct sonode *)sock_handle;
1560 1601  
1561 1602          mutex_enter(&so->so_lock);
1562 1603          so->so_copyflag |= STZCNOTIFY;
1563 1604          cv_broadcast(&so->so_copy_cv);
1564 1605          mutex_exit(&so->so_lock);
1565 1606  }
↓ open down ↓ 380 lines elided ↑ open up ↑
1946 1987          so_newconn,
1947 1988          so_connected,
1948 1989          so_disconnected,
1949 1990          so_opctl,
1950 1991          so_queue_msg,
1951 1992          so_set_prop,
1952 1993          so_txq_full,
1953 1994          so_signal_oob,
1954 1995          so_zcopy_notify,
1955 1996          so_set_error,
1956      -        so_closed
     1997 +        so_closed,
     1998 +        so_get_sock_pid_mblk
1957 1999  };
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX