Print this page
XXXX adding PID information to netstat output

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/inet/tcp/tcp_stats.c
          +++ new/usr/src/uts/common/inet/tcp/tcp_stats.c
↓ open down ↓ 22 lines elided ↑ open up ↑
  23   23   * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  24   24   * Copyright (c) 2011, Joyent Inc. All rights reserved.
  25   25   */
  26   26  
  27   27  #include <sys/types.h>
  28   28  #include <sys/tihdr.h>
  29   29  #include <sys/policy.h>
  30   30  #include <sys/tsol/tnet.h>
  31   31  #include <sys/kstat.h>
  32   32  
       33 +#include <sys/strsun.h>
       34 +#include <sys/stropts.h>
       35 +#include <sys/strsubr.h>
       36 +#include <sys/socket.h>
       37 +#include <sys/socketvar.h>
       38 +#include <sys/uio.h>
       39 +
  33   40  #include <inet/common.h>
  34   41  #include <inet/ip.h>
  35   42  #include <inet/tcp.h>
  36   43  #include <inet/tcp_impl.h>
  37   44  #include <inet/tcp_stats.h>
  38   45  #include <inet/kstatcom.h>
  39   46  #include <inet/snmpcom.h>
  40   47  
  41   48  static int      tcp_kstat_update(kstat_t *, int);
  42   49  static int      tcp_kstat2_update(kstat_t *, int);
↓ open down ↓ 47 lines elided ↑ open up ↑
  90   97   * Return SNMP stuff in buffer in mpdata.
  91   98   */
  92   99  mblk_t *
  93  100  tcp_snmp_get(queue_t *q, mblk_t *mpctl, boolean_t legacy_req)
  94  101  {
  95  102          mblk_t                  *mpdata;
  96  103          mblk_t                  *mp_conn_ctl = NULL;
  97  104          mblk_t                  *mp_conn_tail;
  98  105          mblk_t                  *mp_attr_ctl = NULL;
  99  106          mblk_t                  *mp_attr_tail;
      107 +        mblk_t                  *mp_pidnode_ctl = NULL;
      108 +        mblk_t                  *mp_pidnode_tail;
 100  109          mblk_t                  *mp6_conn_ctl = NULL;
 101  110          mblk_t                  *mp6_conn_tail;
 102  111          mblk_t                  *mp6_attr_ctl = NULL;
 103  112          mblk_t                  *mp6_attr_tail;
      113 +        mblk_t                  *mp6_pidnode_ctl = NULL;
      114 +        mblk_t                  *mp6_pidnode_tail;
 104  115          struct opthdr           *optp;
 105  116          mib2_tcpConnEntry_t     tce;
 106  117          mib2_tcp6ConnEntry_t    tce6;
 107  118          mib2_transportMLPEntry_t mlp;
 108  119          connf_t                 *connfp;
 109  120          int                     i;
 110  121          boolean_t               ispriv;
 111  122          zoneid_t                zoneid;
 112  123          int                     v4_conn_idx;
 113  124          int                     v6_conn_idx;
↓ open down ↓ 6 lines elided ↑ open up ↑
 120  131  
 121  132          /*
 122  133           * make a copy of the original message
 123  134           */
 124  135          mp2ctl = copymsg(mpctl);
 125  136  
 126  137          if (mpctl == NULL ||
 127  138              (mpdata = mpctl->b_cont) == NULL ||
 128  139              (mp_conn_ctl = copymsg(mpctl)) == NULL ||
 129  140              (mp_attr_ctl = copymsg(mpctl)) == NULL ||
      141 +            (mp_pidnode_ctl = copymsg(mpctl)) == NULL ||
 130  142              (mp6_conn_ctl = copymsg(mpctl)) == NULL ||
 131      -            (mp6_attr_ctl = copymsg(mpctl)) == NULL) {
      143 +            (mp6_attr_ctl = copymsg(mpctl)) == NULL ||
      144 +            (mp6_pidnode_ctl = copymsg(mpctl)) == NULL) {
 132  145                  freemsg(mp_conn_ctl);
 133  146                  freemsg(mp_attr_ctl);
      147 +                freemsg(mp_pidnode_ctl);
 134  148                  freemsg(mp6_conn_ctl);
 135  149                  freemsg(mp6_attr_ctl);
      150 +                freemsg(mp6_pidnode_ctl);
 136  151                  freemsg(mpctl);
 137  152                  freemsg(mp2ctl);
 138  153                  return (NULL);
 139  154          }
 140  155  
 141  156          ipst = connp->conn_netstack->netstack_ip;
 142  157          tcps = connp->conn_netstack->netstack_tcp;
 143  158  
 144  159          if (legacy_req) {
 145  160                  tcp_mib_size = LEGACY_MIB_SIZE(&tcp_mib, mib2_tcp_t);
↓ open down ↓ 13 lines elided ↑ open up ↑
 159  174          SET_MIB(tcp_mib.tcpRtoMax, tcps->tcps_rexmit_interval_max);
 160  175          SET_MIB(tcp_mib.tcpMaxConn, -1);
 161  176          SET_MIB(tcp_mib.tcpCurrEstab, 0);
 162  177  
 163  178          ispriv =
 164  179              secpolicy_ip_config((Q_TO_CONN(q))->conn_cred, B_TRUE) == 0;
 165  180          zoneid = Q_TO_CONN(q)->conn_zoneid;
 166  181  
 167  182          v4_conn_idx = v6_conn_idx = 0;
 168  183          mp_conn_tail = mp_attr_tail = mp6_conn_tail = mp6_attr_tail = NULL;
      184 +        mp_pidnode_tail = mp6_pidnode_tail = NULL;
 169  185  
 170  186          for (i = 0; i < CONN_G_HASH_SIZE; i++) {
 171  187                  ipst = tcps->tcps_netstack->netstack_ip;
 172  188  
 173  189                  connfp = &ipst->ips_ipcl_globalhash_fanout[i];
 174  190  
 175  191                  connp = NULL;
 176  192  
 177  193                  while ((connp =
 178  194                      ipcl_get_next_conn(connfp, connp, IPCL_TCPCONN)) != NULL) {
↓ open down ↓ 95 lines elided ↑ open up ↑
 274  290                          tce6.tcp6ConnEntryInfo.ce_state = tcp->tcp_state;
 275  291  
 276  292                          tce6.tcp6ConnCreationProcess =
 277  293                              (connp->conn_cpid < 0) ? MIB2_UNKNOWN_PROCESS :
 278  294                              connp->conn_cpid;
 279  295                          tce6.tcp6ConnCreationTime = connp->conn_open_time;
 280  296  
 281  297                          (void) snmp_append_data2(mp6_conn_ctl->b_cont,
 282  298                              &mp6_conn_tail, (char *)&tce6, tce6_size);
 283  299  
      300 +                        (void) snmp_append_data2(mp6_pidnode_ctl->b_cont,
      301 +                            &mp6_pidnode_tail, (char *)&tce6, tce6_size);
      302 +
      303 +                        (void) snmp_append_mblk2(mp6_pidnode_ctl->b_cont,
      304 +                            &mp6_pidnode_tail, conn_get_pid_mblk(connp));
      305 +
 284  306                          mlp.tme_connidx = v6_conn_idx++;
 285  307                          if (needattr)
 286  308                                  (void) snmp_append_data2(mp6_attr_ctl->b_cont,
 287  309                                      &mp6_attr_tail, (char *)&mlp, sizeof (mlp));
 288  310                          }
 289  311                          /*
 290  312                           * Create an IPv4 table entry for IPv4 entries and also
 291  313                           * for IPv6 entries which are bound to in6addr_any
 292  314                           * but don't have IPV6_V6ONLY set.
 293  315                           * (i.e. anything an IPv4 peer could connect to)
↓ open down ↓ 47 lines elided ↑ open up ↑
 341  363  
 342  364                                  tce.tcpConnCreationProcess =
 343  365                                      (connp->conn_cpid < 0) ?
 344  366                                      MIB2_UNKNOWN_PROCESS :
 345  367                                      connp->conn_cpid;
 346  368                                  tce.tcpConnCreationTime = connp->conn_open_time;
 347  369  
 348  370                                  (void) snmp_append_data2(mp_conn_ctl->b_cont,
 349  371                                      &mp_conn_tail, (char *)&tce, tce_size);
 350  372  
      373 +                                (void) snmp_append_data2(mp_pidnode_ctl->b_cont,
      374 +                                    &mp_pidnode_tail, (char *)&tce, tce_size);
      375 +
      376 +                                (void) snmp_append_mblk2(mp_pidnode_ctl->b_cont,
      377 +                                    &mp_pidnode_tail, conn_get_pid_mblk(connp));
      378 +
 351  379                                  mlp.tme_connidx = v4_conn_idx++;
 352  380                                  if (needattr)
 353  381                                          (void) snmp_append_data2(
 354  382                                              mp_attr_ctl->b_cont,
 355  383                                              &mp_attr_tail, (char *)&mlp,
 356  384                                              sizeof (mlp));
 357  385                          }
 358  386                  }
 359  387          }
 360  388  
↓ open down ↓ 49 lines elided ↑ open up ↑
 410  438          /* table of IPv6 MLP attributes... */
 411  439          optp = (struct opthdr *)&mp6_attr_ctl->b_rptr[
 412  440              sizeof (struct T_optmgmt_ack)];
 413  441          optp->level = MIB2_TCP6;
 414  442          optp->name = EXPER_XPORT_MLP;
 415  443          optp->len = msgdsize(mp6_attr_ctl->b_cont);
 416  444          if (optp->len == 0)
 417  445                  freemsg(mp6_attr_ctl);
 418  446          else
 419  447                  qreply(q, mp6_attr_ctl);
      448 +
      449 +        /* table of EXPER_XPORT_PROC_INFO  ipv4 */
      450 +        optp = (struct opthdr *)&mp_pidnode_ctl->b_rptr[
      451 +            sizeof (struct T_optmgmt_ack)];
      452 +        optp->level = MIB2_TCP;
      453 +        optp->name = EXPER_XPORT_PROC_INFO;
      454 +        optp->len = msgdsize(mp_pidnode_ctl->b_cont);
      455 +        if (optp->len == 0)
      456 +                freemsg(mp_pidnode_ctl);
      457 +        else
      458 +                qreply(q, mp_pidnode_ctl);
      459 +
      460 +        /* table of EXPER_XPORT_PROC_INFO  ipv6 */
      461 +        optp = (struct opthdr *)&mp6_pidnode_ctl->b_rptr[
      462 +            sizeof (struct T_optmgmt_ack)];
      463 +        optp->level = MIB2_TCP6;
      464 +        optp->name = EXPER_XPORT_PROC_INFO;
      465 +        optp->len = msgdsize(mp6_pidnode_ctl->b_cont);
      466 +        if (optp->len == 0)
      467 +                freemsg(mp6_pidnode_ctl);
      468 +        else
      469 +                qreply(q, mp6_pidnode_ctl);
      470 +
 420  471          return (mp2ctl);
 421  472  }
 422  473  
 423  474  /* Return 0 if invalid set request, 1 otherwise, including non-tcp requests  */
 424  475  /* ARGSUSED */
 425  476  int
 426  477  tcp_snmp_set(queue_t *q, int level, int name, uchar_t *ptr, int len)
 427  478  {
 428  479          mib2_tcpConnEntry_t     *tce = (mib2_tcpConnEntry_t *)ptr;
 429  480  
↓ open down ↓ 628 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX