Print this page
dccp: complete netstack

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/cmd-inet/usr.bin/netstat/netstat.c
          +++ new/usr/src/cmd/cmd-inet/usr.bin/netstat/netstat.c
↓ open down ↓ 185 lines elided ↑ open up ↑
 186  186                              char ifname[], char logintname[],
 187  187                              struct ifstat *statptr, boolean_t ksp_not_null);
 188  188  static void             if_report_ip6(mib2_ipv6AddrEntry_t *ap6,
 189  189                              char ifname[], char logintname[],
 190  190                              struct ifstat *statptr, boolean_t ksp_not_null);
 191  191  static void             ire_report(const mib_item_t *item);
 192  192  static void             tcp_report(const mib_item_t *item);
 193  193  static void             udp_report(const mib_item_t *item);
 194  194  static void             group_report(mib_item_t *item);
 195  195  static void             dce_report(mib_item_t *item);
      196 +static void             sctp_report(const mib_item_t *item);
      197 +static void             dccp_report(const mib_item_t *item);
 196  198  static void             print_ip_stats(mib2_ip_t *ip);
 197  199  static void             print_icmp_stats(mib2_icmp_t *icmp);
 198  200  static void             print_ip6_stats(mib2_ipv6IfStatsEntry_t *ip6);
 199  201  static void             print_icmp6_stats(mib2_ipv6IfIcmpEntry_t *icmp6);
 200  202  static void             print_sctp_stats(mib2_sctp_t *tcp);
 201  203  static void             print_tcp_stats(mib2_tcp_t *tcp);
 202  204  static void             print_udp_stats(mib2_udp_t *udp);
 203  205  static void             print_rawip_stats(mib2_rawip_t *rawip);
 204  206  static void             print_igmp_stats(struct igmpstat *igps);
 205  207  static void             print_mrt_stats(struct mrtstat *mrts);
 206      -static void             sctp_report(const mib_item_t *item);
      208 +static void             print_dccp_stats(mib2_dccp_t *dccp);
 207  209  static void             sum_ip6_stats(mib2_ipv6IfStatsEntry_t *ip6,
 208  210                              mib2_ipv6IfStatsEntry_t *sum6);
 209  211  static void             sum_icmp6_stats(mib2_ipv6IfIcmpEntry_t *icmp6,
 210  212                              mib2_ipv6IfIcmpEntry_t *sum6);
 211  213  static void             m_report(void);
 212  214  static void             dhcp_report(char *);
 213  215  
 214  216  static  uint64_t        kstat_named_value(kstat_t *, char *);
 215  217  static  kid_t           safe_kstat_read(kstat_ctl_t *, kstat_t *, void *);
 216  218  static int              isnum(char *);
↓ open down ↓ 60 lines elided ↑ open up ↑
 277  279  static int ipDestEntrySize;
 278  280  
 279  281  static int transportMLPSize;
 280  282  static int tcpConnEntrySize;
 281  283  static int tcp6ConnEntrySize;
 282  284  static int udpEntrySize;
 283  285  static int udp6EntrySize;
 284  286  static int sctpEntrySize;
 285  287  static int sctpLocalEntrySize;
 286  288  static int sctpRemoteEntrySize;
      289 +static int dccpEntrySize;
      290 +static int dccp6EntrySize;
 287  291  
 288  292  #define protocol_selected(p)    (proto == IPPROTO_MAX || proto == (p))
 289  293  
 290  294  /* Machinery used for -f (filter) option */
 291  295  enum { FK_AF = 0, FK_OUTIF, FK_DST, FK_FLAGS, NFILTERKEYS };
 292  296  
 293  297  static const char *filter_keys[NFILTERKEYS] = {
 294  298          "af", "outif", "dst", "flags"
 295  299  };
 296  300  
↓ open down ↓ 173 lines elided ↑ open up ↑
 470  474                                  proto = IPPROTO_IGMP;
 471  475                          } else if (strcmp(optarg, "udp") == 0) {
 472  476                                  proto = IPPROTO_UDP;
 473  477                          } else if (strcmp(optarg, "tcp") == 0) {
 474  478                                  proto = IPPROTO_TCP;
 475  479                          } else if (strcmp(optarg, "sctp") == 0) {
 476  480                                  proto = IPPROTO_SCTP;
 477  481                          } else if (strcmp(optarg, "raw") == 0 ||
 478  482                              strcmp(optarg, "rawip") == 0) {
 479  483                                  proto = IPPROTO_RAW;
      484 +                        } else if (strcmp(optarg, "dccp") == 0) {
      485 +                                proto = IPPROTO_DCCP;
 480  486                          } else {
 481  487                                  fatal(1, "%s: unknown protocol.\n", optarg);
 482  488                          }
 483  489                          break;
 484  490  
 485  491                  case 'I':
 486  492                          ifname = optarg;
 487  493                          Iflag = B_TRUE;
 488  494                          IFLAGMOD(Iflag_only, -1, 1); /* see macro def'n */
 489  495                          break;
↓ open down ↓ 125 lines elided ↑ open up ↑
 615  621                          }
 616  622  
 617  623                          if (!(Dflag || Iflag || Rflag || Sflag || Mflag ||
 618  624                              MMflag || Pflag || Gflag || DHCPflag)) {
 619  625                                  if (protocol_selected(IPPROTO_UDP))
 620  626                                          udp_report(item);
 621  627                                  if (protocol_selected(IPPROTO_TCP))
 622  628                                          tcp_report(item);
 623  629                                  if (protocol_selected(IPPROTO_SCTP))
 624  630                                          sctp_report(item);
      631 +                                if (protocol_selected(IPPROTO_DCCP))
      632 +                                        dccp_report(item);
 625  633                          }
 626  634                          if (Iflag)
 627  635                                  if_report(item, ifname, Iflag_only, once_only);
 628  636                          if (Mflag)
 629  637                                  m_report();
 630  638                          if (Rflag)
 631  639                                  ire_report(item);
 632  640                          if (Sflag && MMflag) {
 633  641                                  mrt_stat_report(curritem);
 634  642                          } else {
↓ open down ↓ 364 lines elided ↑ open up ↑
 999 1007                          case MIB2_IP:
1000 1008                          case MIB2_IP6:
1001 1009                          case EXPER_DVMRP:
1002 1010                          case EXPER_IGMP:
1003 1011                          case MIB2_ICMP:
1004 1012                          case MIB2_ICMP6:
1005 1013                          case MIB2_TCP:
1006 1014                          case MIB2_UDP:
1007 1015                          case MIB2_SCTP:
1008 1016                          case EXPER_RAWIP:
     1017 +                        case MIB2_DCCP:
1009 1018                                  nitems++;
1010 1019                          }
1011 1020          }
1012 1021          tempp2 = NULL;
1013 1022          if (nitems == 0) {
1014 1023                  diffp = mib_item_dup(item2);
1015 1024                  return (diffp);
1016 1025          }
1017 1026  
1018 1027          diffp = (mib_item_t *)calloc(nitems, sizeof (mib_item_t));
↓ open down ↓ 426 lines elided ↑ open up ↑
1445 1454                                  MDIFF(d, s2, s1, sctpInInvalidCookie);
1446 1455                                  MDIFF(d, s2, s1, sctpTimRetrans);
1447 1456                                  MDIFF(d, s2, s1, sctpTimRetransDrop);
1448 1457                                  MDIFF(d, s2, s1, sctpTimHeartBeatProbe);
1449 1458                                  MDIFF(d, s2, s1, sctpTimHeartBeatDrop);
1450 1459                                  MDIFF(d, s2, s1, sctpListenDrop);
1451 1460                                  MDIFF(d, s2, s1, sctpInClosed);
1452 1461                                  prevp = diffptr++;
1453 1462                                  break;
1454 1463                          }
     1464 +                        case MIB2_DCCP: {
     1465 +                                /* XXX:DCCP */
     1466 +                                break;
     1467 +                        }
1455 1468                          case EXPER_RAWIP: {
1456 1469                                  mib2_rawip_t *r2;
1457 1470                                  mib2_rawip_t *r1;
1458 1471                                  mib2_rawip_t *d;
1459 1472  
1460 1473                                  r2 = (mib2_rawip_t *)tempp2->valp;
1461 1474                                  r1 = (mib2_rawip_t *)tempp1->valp;
1462 1475                                  diffptr->group = tempp2->group;
1463 1476                                  diffptr->mib_id = tempp2->mib_id;
1464 1477                                  diffptr->length = tempp2->length;
↓ open down ↓ 389 lines elided ↑ open up ↑
1854 1867                          break;
1855 1868                  }
1856 1869                  case MIB2_SCTP: {
1857 1870                          mib2_sctp_t     *sctp = (mib2_sctp_t *)item->valp;
1858 1871  
1859 1872                          sctpEntrySize = sctp->sctpEntrySize;
1860 1873                          sctpLocalEntrySize = sctp->sctpLocalEntrySize;
1861 1874                          sctpRemoteEntrySize = sctp->sctpRemoteEntrySize;
1862 1875                          break;
1863 1876                  }
     1877 +                case MIB2_DCCP: {
     1878 +                        mib2_dccp_t     *dccp = (mib2_dccp_t *)item->valp;
     1879 +
     1880 +                        dccpEntrySize = dccp->dccpConnTableSize;
     1881 +                        dccp6EntrySize = dccp->dccp6ConnTableSize;
     1882 +                        assert(IS_P2ALIGNED(dccpEntrySize,
     1883 +                            sizeof (mib2_dccpConnEntry_t *)));
     1884 +                        assert(IS_P2ALIGNED(dccp6EntrySize,
     1885 +                            sizeof (mib2_dccp6ConnEntry_t *)));
     1886 +                        break;
     1887 +                }
1864 1888                  }
1865 1889          } /* 'for' loop 1 ends */
1866 1890  
1867 1891          if (Xflag) {
1868 1892                  (void) puts("mib_get_constants:");
1869 1893                  (void) printf("\tipv6IfStatsEntrySize %d\n",
1870 1894                      ipv6IfStatsEntrySize);
1871 1895                  (void) printf("\tipAddrEntrySize %d\n", ipAddrEntrySize);
1872 1896                  (void) printf("\tipRouteEntrySize %d\n", ipRouteEntrySize);
1873 1897                  (void) printf("\tipNetToMediaEntrySize %d\n",
↓ open down ↓ 15 lines elided ↑ open up ↑
1889 1913                  (void) printf("\tipDestEntrySize %d\n", ipDestEntrySize);
1890 1914                  (void) printf("\ttransportMLPSize %d\n", transportMLPSize);
1891 1915                  (void) printf("\ttcpConnEntrySize %d\n", tcpConnEntrySize);
1892 1916                  (void) printf("\ttcp6ConnEntrySize %d\n", tcp6ConnEntrySize);
1893 1917                  (void) printf("\tudpEntrySize %d\n", udpEntrySize);
1894 1918                  (void) printf("\tudp6EntrySize %d\n", udp6EntrySize);
1895 1919                  (void) printf("\tsctpEntrySize %d\n", sctpEntrySize);
1896 1920                  (void) printf("\tsctpLocalEntrySize %d\n", sctpLocalEntrySize);
1897 1921                  (void) printf("\tsctpRemoteEntrySize %d\n",
1898 1922                      sctpRemoteEntrySize);
     1923 +                (void) printf("\tdccpEntrySize %d\n", dccpEntrySize);
     1924 +                (void) printf("\ttcp6EntrySize %d\n", dccp6EntrySize);
1899 1925          }
1900 1926  }
1901 1927  
1902 1928  
1903 1929  /* ----------------------------- STAT_REPORT ------------------------------- */
1904 1930  
1905 1931  static void
1906 1932  stat_report(mib_item_t *item)
1907 1933  {
1908 1934          int     jtemp = 0;
↓ open down ↓ 3515 lines elided ↑ open up ↑
5424 5450                                          first = B_FALSE;
5425 5451                                  }
5426 5452                                  sctp_conn_report_item(head, sp, attr);
5427 5453                          }
5428 5454                  }
5429 5455          }
5430 5456          if (attrs != NULL)
5431 5457                  free(attrs);
5432 5458  }
5433 5459  
     5460 +/* ------------------------------ DCCP_REPORT------------------------------- */
     5461 +
     5462 +static const char dccp_hdr_v4[] =
     5463 +"\nDCCP: IPv4\n";
     5464 +static const char dccp_hdr_v4_compat[] =
     5465 +"\nDCCP\n";
     5466 +static const char dccp_hdr_v4_verbose[] =
     5467 +"Local/Remote Address Swind  Snext     Suna   Rwind  Rnext     Rack   "
     5468 +" Rto   Mss     State\n"
     5469 +"-------------------- ----- -------- -------- ----- -------- -------- "
     5470 +"----- ----- -----------\n";
     5471 +static const char dccp_hdr_v4_normal[] =
     5472 +"   Local Address        Remote Address    Swind Send-Q Rwind Recv-Q "
     5473 +"   State\n"
     5474 +"-------------------- -------------------- ----- ------ ----- ------ "
     5475 +"-----------\n";
     5476 +
     5477 +static const char dccp_hdr_v6[] =
     5478 +"\nDCCP: IPv6\n";
     5479 +static const char dccp_hdr_v6_verbose[] =
     5480 +"Local/Remote Address              Swind  Snext     Suna   Rwind  Rnext   "
     5481 +"  Rack    Rto   Mss    State      If\n"
     5482 +"--------------------------------- ----- -------- -------- ----- -------- "
     5483 +"-------- ----- ----- ----------- -----\n";
     5484 +static const char dccp_hdr_v6_normal[] =
     5485 +"   Local Address                     Remote Address                 "
     5486 +"Swind Send-Q Rwind Recv-Q   State      If\n"
     5487 +"--------------------------------- --------------------------------- "
     5488 +"----- ------ ----- ------ ----------- -----\n";
     5489 +
     5490 +static boolean_t dccp_report_item_v4(const mib2_dccpConnEntry_t *,
     5491 +    boolean_t, const mib2_transportMLPEntry_t *);
     5492 +static boolean_t dccp_report_item_v6(const mib2_dccp6ConnEntry_t *,
     5493 +    boolean_t, const mib2_transportMLPEntry_t *);
     5494 +
     5495 +static void
     5496 +dccp_report(const mib_item_t *item)
     5497 +{
     5498 +        mib2_dccpConnEntry_t            *dp;
     5499 +        mib2_transportMLPEntry_t        **v4_attrs;
     5500 +        mib2_transportMLPEntry_t        **v6_attrs;
     5501 +        mib2_transportMLPEntry_t        **v4a;
     5502 +        mib2_transportMLPEntry_t        **v6a;
     5503 +        mib2_transportMLPEntry_t        *aptr;
     5504 +        boolean_t                       print_hdr_once_v4 = B_TRUE;
     5505 +        boolean_t                       print_hdr_once_v6 = B_TRUE;
     5506 +        int                             jtemp = 0;
     5507 +
     5508 +        if (!protocol_selected(IPPROTO_DCCP)) {
     5509 +                return;
     5510 +        }
     5511 +
     5512 +        v4_attrs = family_selected(AF_INET) && RSECflag ?
     5513 +            gather_attrs(item, MIB2_DCCP, MIB2_DCCP_CONN, dccpEntrySize) :
     5514 +            NULL;
     5515 +        v6_attrs = family_selected(AF_INET6) && RSECflag ?
     5516 +            gather_attrs(item, MIB2_DCCP6, MIB2_DCCP6_CONN, dccp6EntrySize) :
     5517 +            NULL;
     5518 +
     5519 +        v4a = v4_attrs;
     5520 +        v6a = v6_attrs;
     5521 +        for (; item != NULL; item = item->next_item) {
     5522 +                if (Xflag) {
     5523 +                        (void) printf("\n--- Entry %d ---\n", ++jtemp);
     5524 +                        (void) printf("Group = %d, mib_id = %d, "
     5525 +                            "length = %d, valp = 0x%p\n",
     5526 +                            item->group, item->mib_id,
     5527 +                            item->length, item->valp);
     5528 +                }
     5529 +
     5530 +                if (item->group == MIB2_DCCP) {
     5531 +                        for (dp = (mib2_dccpConnEntry_t *)item->valp;
     5532 +                            (char *)dp < (char *)item->valp + item->length;
     5533 +                            dp = (mib2_dccpConnEntry_t *)((char *)dp +
     5534 +                            dccpEntrySize)) {
     5535 +                                aptr = v4a == NULL ? NULL : *v4a++;
     5536 +                                print_hdr_once_v4 = dccp_report_item_v4(dp,
     5537 +                                    print_hdr_once_v4, aptr);
     5538 +                        }
     5539 +                }
     5540 +        }
     5541 +
     5542 +        (void) fflush(stdout);
     5543 +
     5544 +        if (v4_attrs != NULL) {
     5545 +                free(v4_attrs);
     5546 +        }
     5547 +        if (v6_attrs != NULL) {
     5548 +                free(v6_attrs);
     5549 +        }
     5550 +}
     5551 +
     5552 +static boolean_t
     5553 +dccp_report_item_v4(const mib2_dccpConnEntry_t *dp, boolean_t first,
     5554 +    const mib2_transportMLPEntry_t *attr)
     5555 +{
     5556 +        char    lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
     5557 +        char    fname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
     5558 +
     5559 +        if (first) {
     5560 +                (void) printf(v4compat ? dccp_hdr_v4_compat : dccp_hdr_v4);
     5561 +                (void) printf(Vflag ? dccp_hdr_v4_verbose : dccp_hdr_v4_normal);
     5562 +        }
     5563 +
     5564 +        (void) printf("%-20s %-20s %5u %6d %5u %6d %s\n",
     5565 +            pr_ap(dp->dccpConnLocalAddress,
     5566 +            dp->dccpConnLocalPort, "dccp", lname, sizeof (lname)),
     5567 +            pr_ap(dp->dccpConnRemAddress,
     5568 +            dp->dccpConnRemPort, "dccp", fname, sizeof (fname)),
     5569 +            0,
     5570 +            0,
     5571 +            0,
     5572 +            0,
     5573 +            0);
     5574 +
     5575 +        print_transport_label(attr);
     5576 +
     5577 +        return (B_FALSE);
     5578 +}
     5579 +
     5580 +static boolean_t
     5581 +dccp_report_item_v6(const mib2_dccp6ConnEntry_t *dp, boolean_t first,
     5582 +    const mib2_transportMLPEntry_t *attr)
     5583 +{
     5584 +        return (B_FALSE);
     5585 +}
     5586 +
5434 5587  static char *
5435 5588  plural(int n)
5436 5589  {
5437 5590          return (n != 1 ? "s" : "");
5438 5591  }
5439 5592  
5440 5593  static char *
5441 5594  pluraly(int n)
5442 5595  {
5443 5596          return (n != 1 ? "ies" : "y");
↓ open down ↓ 1012 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX