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