Print this page
XXXX adding PID information to netstat output

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/os/streamio.c
          +++ new/usr/src/uts/common/os/streamio.c
↓ open down ↓ 69 lines elided ↑ open up ↑
  70   70  #include <sys/ptyvar.h>
  71   71  #include <sys/vuid_event.h>
  72   72  #include <sys/modctl.h>
  73   73  #include <sys/sunddi.h>
  74   74  #include <sys/sunldi_impl.h>
  75   75  #include <sys/autoconf.h>
  76   76  #include <sys/policy.h>
  77   77  #include <sys/dld.h>
  78   78  #include <sys/zone.h>
  79   79  #include <c2/audit.h>
       80 +#include <sys/fcntl.h>
  80   81  
  81   82  /*
  82   83   * This define helps improve the readability of streams code while
  83   84   * still maintaining a very old streams performance enhancement.  The
  84   85   * performance enhancement basically involved having all callers
  85   86   * of straccess() perform the first check that straccess() will do
  86   87   * locally before actually calling straccess().  (There by reducing
  87   88   * the number of unnecessary calls to straccess().)
  88   89   */
  89   90  #define i_straccess(x, y)       ((stp->sd_sidp == NULL) ? 0 : \
↓ open down ↓ 45 lines elided ↑ open up ↑
 135  136  
 136  137  /*
 137  138   * id value used to distinguish between different ioctl messages
 138  139   */
 139  140  static uint32_t ioc_id;
 140  141  
 141  142  static void putback(struct stdata *, queue_t *, mblk_t *, int);
 142  143  static void strcleanall(struct vnode *);
 143  144  static int strwsrv(queue_t *);
 144  145  static int strdocmd(struct stdata *, struct strcmd *, cred_t *);
      146 +static boolean_t is_xti_str(const struct stdata *);
 145  147  
 146  148  /*
 147  149   * qinit and module_info structures for stream head read and write queues
 148  150   */
 149  151  struct module_info strm_info = { 0, "strrhead", 0, INFPSZ, STRHIGH, STRLOW };
 150  152  struct module_info stwm_info = { 0, "strwhead", 0, 0, 0, 0 };
 151  153  struct qinit strdata = { strrput, NULL, NULL, NULL, NULL, &strm_info };
 152  154  struct qinit stwdata = { NULL, strwsrv, NULL, NULL, NULL, &stwm_info };
 153  155  struct module_info fiform_info = { 0, "fifostrrhead", 0, PIPE_BUF, FIFOHIWAT,
 154  156      FIFOLOWAT };
↓ open down ↓ 234 lines elided ↑ open up ↑
 389  391          stp->sd_iocblk = NULL;
 390  392          stp->sd_cmdblk = NULL;
 391  393          stp->sd_pushcnt = 0;
 392  394          stp->sd_qn_minpsz = 0;
 393  395          stp->sd_qn_maxpsz = INFPSZ - 1; /* used to check for initialization */
 394  396          stp->sd_maxblk = INFPSZ;
 395  397          qp->q_ptr = _WR(qp)->q_ptr = stp;
 396  398          STREAM(qp) = STREAM(_WR(qp)) = stp;
 397  399          vp->v_stream = stp;
 398  400          mutex_exit(&vp->v_lock);
      401 +
      402 +        /*
      403 +         * If this is not a system process, then add it to
      404 +         * the list associated with the stream head.
      405 +         */
      406 +        if (!(curproc->p_flag & SSYS) && is_xti_str(stp))
      407 +                sh_insert_pid(stp, curproc->p_pidp->pid_id);
      408 +
 399  409          if (vp->v_type == VFIFO) {
 400  410                  stp->sd_flag |= OLDNDELAY;
 401  411                  /*
 402  412                   * This means, both for pipes and fifos
 403  413                   * strwrite will send SIGPIPE if the other
 404  414                   * end is closed. For putmsg it depends
 405  415                   * on whether it is a XPG4_2 application
 406  416                   * or not
 407  417                   */
 408  418                  stp->sd_wput_opt = SW_SIGPIPE;
↓ open down ↓ 5266 lines elided ↑ open up ↑
5675 5685          {
5676 5686                  /* freectty() always assumes curproc. */
5677 5687                  if (freectty(B_FALSE) != 0)
5678 5688                          return (0);
5679 5689                  return (ENOTTY);
5680 5690          }
5681 5691  
5682 5692          case FIONBIO:
5683 5693          case FIOASYNC:
5684 5694                  return (0);     /* handled by the upper layer */
     5695 +        case F_ASSOCI_PID:
     5696 +        {
     5697 +                if (crp != kcred)
     5698 +                        return (EPERM);
     5699 +                if (is_xti_str(stp))
     5700 +                        sh_insert_pid(stp, (pid_t)arg);
     5701 +                return (0);
     5702 +        }
     5703 +        case F_DASSOC_PID:
     5704 +        {
     5705 +                if (crp != kcred)
     5706 +                        return (EPERM);
     5707 +                if (is_xti_str(stp))
     5708 +                        sh_remove_pid(stp, (pid_t)arg);
     5709 +                return (0);
     5710 +        }
5685 5711          }
5686 5712  }
5687 5713  
5688 5714  /*
5689 5715   * Custom free routine used for M_PASSFP messages.
5690 5716   */
5691 5717  static void
5692 5718  free_passfp(struct k_strrecvfd *srf)
5693 5719  {
5694 5720          (void) closef(srf->fp);
↓ open down ↓ 2910 lines elided ↑ open up ↑
8605 8631   */
8606 8632  static boolean_t
8607 8633  msghasdata(mblk_t *bp)
8608 8634  {
8609 8635          for (; bp; bp = bp->b_cont)
8610 8636                  if (bp->b_datap->db_type == M_DATA) {
8611 8637                          ASSERT(bp->b_wptr >= bp->b_rptr);
8612 8638                          if (bp->b_wptr > bp->b_rptr)
8613 8639                                  return (B_TRUE);
8614 8640                  }
     8641 +        return (B_FALSE);
     8642 +}
     8643 +
     8644 +/*
     8645 + * Check whether a stream is an XTI stream or not.
     8646 + */
     8647 +static boolean_t
     8648 +is_xti_str(const struct stdata *stp)
     8649 +{
     8650 +        struct devnames *dnp;
     8651 +        vnode_t *vn;
     8652 +        major_t major;
     8653 +        if ((vn = stp->sd_vnode) != NULL && vn->v_type == VCHR &&
     8654 +            vn->v_rdev != 0) {
     8655 +                major = getmajor(vn->v_rdev);
     8656 +                dnp = (major != DDI_MAJOR_T_NONE && major >= 0 &&
     8657 +                    major < devcnt) ? &devnamesp[major] : NULL;
     8658 +                if (dnp != NULL && dnp->dn_name != NULL &&
     8659 +                    (strcmp(dnp->dn_name, "ip") == 0 ||
     8660 +                    strcmp(dnp->dn_name, "tcp") == 0 ||
     8661 +                    strcmp(dnp->dn_name, "udp") == 0 ||
     8662 +                    strcmp(dnp->dn_name, "icmp") == 0 ||
     8663 +                    strcmp(dnp->dn_name, "tl") == 0 ||
     8664 +                    strcmp(dnp->dn_name, "ip6") == 0 ||
     8665 +                    strcmp(dnp->dn_name, "tcp6") == 0 ||
     8666 +                    strcmp(dnp->dn_name, "udp6") == 0 ||
     8667 +                    strcmp(dnp->dn_name, "icmp6") == 0)) {
     8668 +                        return (B_TRUE);
     8669 +                }
     8670 +        }
8615 8671          return (B_FALSE);
8616 8672  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX