176 static void stat_report(mib_item_t *item);
177 static void mrt_stat_report(mib_item_t *item);
178 static void arp_report(mib_item_t *item);
179 static void ndp_report(mib_item_t *item);
180 static void mrt_report(mib_item_t *item);
181 static void if_stat_total(struct ifstat *oldstats,
182 struct ifstat *newstats, struct ifstat *sumstats);
183 static void if_report(mib_item_t *item, char *ifname,
184 int Iflag_only, boolean_t once_only);
185 static void if_report_ip4(mib2_ipAddrEntry_t *ap,
186 char ifname[], char logintname[],
187 struct ifstat *statptr, boolean_t ksp_not_null);
188 static void if_report_ip6(mib2_ipv6AddrEntry_t *ap6,
189 char ifname[], char logintname[],
190 struct ifstat *statptr, boolean_t ksp_not_null);
191 static void ire_report(const mib_item_t *item);
192 static void tcp_report(const mib_item_t *item);
193 static void udp_report(const mib_item_t *item);
194 static void group_report(mib_item_t *item);
195 static void dce_report(mib_item_t *item);
196 static void print_ip_stats(mib2_ip_t *ip);
197 static void print_icmp_stats(mib2_icmp_t *icmp);
198 static void print_ip6_stats(mib2_ipv6IfStatsEntry_t *ip6);
199 static void print_icmp6_stats(mib2_ipv6IfIcmpEntry_t *icmp6);
200 static void print_sctp_stats(mib2_sctp_t *tcp);
201 static void print_tcp_stats(mib2_tcp_t *tcp);
202 static void print_udp_stats(mib2_udp_t *udp);
203 static void print_rawip_stats(mib2_rawip_t *rawip);
204 static void print_igmp_stats(struct igmpstat *igps);
205 static void print_mrt_stats(struct mrtstat *mrts);
206 static void sctp_report(const mib_item_t *item);
207 static void sum_ip6_stats(mib2_ipv6IfStatsEntry_t *ip6,
208 mib2_ipv6IfStatsEntry_t *sum6);
209 static void sum_icmp6_stats(mib2_ipv6IfIcmpEntry_t *icmp6,
210 mib2_ipv6IfIcmpEntry_t *sum6);
211 static void m_report(void);
212 static void dhcp_report(char *);
213
214 static uint64_t kstat_named_value(kstat_t *, char *);
215 static kid_t safe_kstat_read(kstat_ctl_t *, kstat_t *, void *);
216 static int isnum(char *);
217 static char *plural(int n);
218 static char *pluraly(int n);
219 static char *plurales(int n);
220 static void process_filter(char *arg);
221 static char *ifindex2str(uint_t, char *);
222 static boolean_t family_selected(int family);
223
224 static void usage(char *);
225 static void fatal(int errcode, char *str1, ...);
226
267 static int mfcctlSize;
268
269 static int ipv6IfStatsEntrySize;
270 static int ipv6IfIcmpEntrySize;
271 static int ipv6AddrEntrySize;
272 static int ipv6RouteEntrySize;
273 static int ipv6NetToMediaEntrySize;
274 static int ipv6MemberEntrySize;
275 static int ipv6GroupSourceEntrySize;
276
277 static int ipDestEntrySize;
278
279 static int transportMLPSize;
280 static int tcpConnEntrySize;
281 static int tcp6ConnEntrySize;
282 static int udpEntrySize;
283 static int udp6EntrySize;
284 static int sctpEntrySize;
285 static int sctpLocalEntrySize;
286 static int sctpRemoteEntrySize;
287
288 #define protocol_selected(p) (proto == IPPROTO_MAX || proto == (p))
289
290 /* Machinery used for -f (filter) option */
291 enum { FK_AF = 0, FK_OUTIF, FK_DST, FK_FLAGS, NFILTERKEYS };
292
293 static const char *filter_keys[NFILTERKEYS] = {
294 "af", "outif", "dst", "flags"
295 };
296
297 static m_label_t *zone_security_label = NULL;
298
299 /* Flags on routes */
300 #define FLF_A 0x00000001
301 #define FLF_b 0x00000002
302 #define FLF_D 0x00000004
303 #define FLF_G 0x00000008
304 #define FLF_H 0x00000010
305 #define FLF_L 0x00000020
306 #define FLF_U 0x00000040
460 strcmp(optarg, "ip6") == 0) {
461 v4compat = 0; /* Overridden */
462 proto = IPPROTO_IPV6;
463 } else if (strcmp(optarg, "icmp") == 0) {
464 proto = IPPROTO_ICMP;
465 } else if (strcmp(optarg, "icmpv6") == 0 ||
466 strcmp(optarg, "icmp6") == 0) {
467 v4compat = 0; /* Overridden */
468 proto = IPPROTO_ICMPV6;
469 } else if (strcmp(optarg, "igmp") == 0) {
470 proto = IPPROTO_IGMP;
471 } else if (strcmp(optarg, "udp") == 0) {
472 proto = IPPROTO_UDP;
473 } else if (strcmp(optarg, "tcp") == 0) {
474 proto = IPPROTO_TCP;
475 } else if (strcmp(optarg, "sctp") == 0) {
476 proto = IPPROTO_SCTP;
477 } else if (strcmp(optarg, "raw") == 0 ||
478 strcmp(optarg, "rawip") == 0) {
479 proto = IPPROTO_RAW;
480 } else {
481 fatal(1, "%s: unknown protocol.\n", optarg);
482 }
483 break;
484
485 case 'I':
486 ifname = optarg;
487 Iflag = B_TRUE;
488 IFLAGMOD(Iflag_only, -1, 1); /* see macro def'n */
489 break;
490
491 case 'D':
492 DHCPflag = B_TRUE;
493 Iflag_only = 0;
494 break;
495
496 case 'T':
497 if (optarg) {
498 if (*optarg == 'u')
499 timestamp_fmt = UDATE;
605 print_timestamp(timestamp_fmt);
606
607 /* netstat: AF_INET[6] behaviour */
608 if (family_selected(AF_INET) || family_selected(AF_INET6)) {
609 if (Sflag) {
610 curritem = mib_item_diff(previtem, item);
611 if (curritem == NULL)
612 fatal(1, "can't process mib data, "
613 "out of memory\n");
614 mib_item_destroy(&previtem);
615 }
616
617 if (!(Dflag || Iflag || Rflag || Sflag || Mflag ||
618 MMflag || Pflag || Gflag || DHCPflag)) {
619 if (protocol_selected(IPPROTO_UDP))
620 udp_report(item);
621 if (protocol_selected(IPPROTO_TCP))
622 tcp_report(item);
623 if (protocol_selected(IPPROTO_SCTP))
624 sctp_report(item);
625 }
626 if (Iflag)
627 if_report(item, ifname, Iflag_only, once_only);
628 if (Mflag)
629 m_report();
630 if (Rflag)
631 ire_report(item);
632 if (Sflag && MMflag) {
633 mrt_stat_report(curritem);
634 } else {
635 if (Sflag)
636 stat_report(curritem);
637 if (MMflag)
638 mrt_report(item);
639 }
640 if (Gflag)
641 group_report(item);
642 if (Pflag) {
643 if (family_selected(AF_INET))
644 arp_report(item);
989 tempp2;
990 tempp2 = tempp2->next_item) {
991 if (tempp2->mib_id == 0)
992 switch (tempp2->group) {
993 /*
994 * upon adding a case here, the same
995 * must also be added in the next
996 * switch statement, alongwith
997 * appropriate code
998 */
999 case MIB2_IP:
1000 case MIB2_IP6:
1001 case EXPER_DVMRP:
1002 case EXPER_IGMP:
1003 case MIB2_ICMP:
1004 case MIB2_ICMP6:
1005 case MIB2_TCP:
1006 case MIB2_UDP:
1007 case MIB2_SCTP:
1008 case EXPER_RAWIP:
1009 nitems++;
1010 }
1011 }
1012 tempp2 = NULL;
1013 if (nitems == 0) {
1014 diffp = mib_item_dup(item2);
1015 return (diffp);
1016 }
1017
1018 diffp = (mib_item_t *)calloc(nitems, sizeof (mib_item_t));
1019 if (diffp == NULL)
1020 return (NULL);
1021 diffptr = diffp;
1022 /* 'for' loop 1: */
1023 for (tempp2 = item2; tempp2 != NULL; tempp2 = tempp2->next_item) {
1024 if (tempp2->mib_id != 0)
1025 continue; /* 'for' loop 1 */
1026 /* 'for' loop 2: */
1027 for (tempp1 = item1; tempp1 != NULL;
1028 tempp1 = tempp1->next_item) {
1435 MDIFF(d, s2, s1, sctpInCtrlChunks);
1436 MDIFF(d, s2, s1, sctpInOrderChunks);
1437 MDIFF(d, s2, s1, sctpInUnorderChunks);
1438 MDIFF(d, s2, s1, sctpInAck);
1439 MDIFF(d, s2, s1, sctpInDupAck);
1440 MDIFF(d, s2, s1, sctpInAckUnsent);
1441 MDIFF(d, s2, s1, sctpFragUsrMsgs);
1442 MDIFF(d, s2, s1, sctpReasmUsrMsgs);
1443 MDIFF(d, s2, s1, sctpOutSCTPPkts);
1444 MDIFF(d, s2, s1, sctpInSCTPPkts);
1445 MDIFF(d, s2, s1, sctpInInvalidCookie);
1446 MDIFF(d, s2, s1, sctpTimRetrans);
1447 MDIFF(d, s2, s1, sctpTimRetransDrop);
1448 MDIFF(d, s2, s1, sctpTimHeartBeatProbe);
1449 MDIFF(d, s2, s1, sctpTimHeartBeatDrop);
1450 MDIFF(d, s2, s1, sctpListenDrop);
1451 MDIFF(d, s2, s1, sctpInClosed);
1452 prevp = diffptr++;
1453 break;
1454 }
1455 case EXPER_RAWIP: {
1456 mib2_rawip_t *r2;
1457 mib2_rawip_t *r1;
1458 mib2_rawip_t *d;
1459
1460 r2 = (mib2_rawip_t *)tempp2->valp;
1461 r1 = (mib2_rawip_t *)tempp1->valp;
1462 diffptr->group = tempp2->group;
1463 diffptr->mib_id = tempp2->mib_id;
1464 diffptr->length = tempp2->length;
1465 d = (mib2_rawip_t *)calloc(tempp2->length, 1);
1466 if (d == NULL)
1467 goto mibdiff_out_of_memory;
1468 diffptr->valp = d;
1469 MDIFF(d, r2, r1, rawipInDatagrams);
1470 MDIFF(d, r2, r1, rawipInErrors);
1471 MDIFF(d, r2, r1, rawipInCksumErrs);
1472 MDIFF(d, r2, r1, rawipOutDatagrams);
1473 MDIFF(d, r2, r1, rawipOutErrors);
1474 prevp = diffptr++;
1844 }
1845 case MIB2_UDP: {
1846 mib2_udp_t *udp = (mib2_udp_t *)item->valp;
1847
1848 udpEntrySize = udp->udpEntrySize;
1849 udp6EntrySize = udp->udp6EntrySize;
1850 assert(IS_P2ALIGNED(udpEntrySize,
1851 sizeof (mib2_udpEntry_t *)));
1852 assert(IS_P2ALIGNED(udp6EntrySize,
1853 sizeof (mib2_udp6Entry_t *)));
1854 break;
1855 }
1856 case MIB2_SCTP: {
1857 mib2_sctp_t *sctp = (mib2_sctp_t *)item->valp;
1858
1859 sctpEntrySize = sctp->sctpEntrySize;
1860 sctpLocalEntrySize = sctp->sctpLocalEntrySize;
1861 sctpRemoteEntrySize = sctp->sctpRemoteEntrySize;
1862 break;
1863 }
1864 }
1865 } /* 'for' loop 1 ends */
1866
1867 if (Xflag) {
1868 (void) puts("mib_get_constants:");
1869 (void) printf("\tipv6IfStatsEntrySize %d\n",
1870 ipv6IfStatsEntrySize);
1871 (void) printf("\tipAddrEntrySize %d\n", ipAddrEntrySize);
1872 (void) printf("\tipRouteEntrySize %d\n", ipRouteEntrySize);
1873 (void) printf("\tipNetToMediaEntrySize %d\n",
1874 ipNetToMediaEntrySize);
1875 (void) printf("\tipMemberEntrySize %d\n", ipMemberEntrySize);
1876 (void) printf("\tipRouteAttributeSize %d\n",
1877 ipRouteAttributeSize);
1878 (void) printf("\tvifctlSize %d\n", vifctlSize);
1879 (void) printf("\tmfcctlSize %d\n", mfcctlSize);
1880
1881 (void) printf("\tipv6AddrEntrySize %d\n", ipv6AddrEntrySize);
1882 (void) printf("\tipv6RouteEntrySize %d\n", ipv6RouteEntrySize);
1883 (void) printf("\tipv6NetToMediaEntrySize %d\n",
1884 ipv6NetToMediaEntrySize);
1885 (void) printf("\tipv6MemberEntrySize %d\n",
1886 ipv6MemberEntrySize);
1887 (void) printf("\tipv6IfIcmpEntrySize %d\n",
1888 ipv6IfIcmpEntrySize);
1889 (void) printf("\tipDestEntrySize %d\n", ipDestEntrySize);
1890 (void) printf("\ttransportMLPSize %d\n", transportMLPSize);
1891 (void) printf("\ttcpConnEntrySize %d\n", tcpConnEntrySize);
1892 (void) printf("\ttcp6ConnEntrySize %d\n", tcp6ConnEntrySize);
1893 (void) printf("\tudpEntrySize %d\n", udpEntrySize);
1894 (void) printf("\tudp6EntrySize %d\n", udp6EntrySize);
1895 (void) printf("\tsctpEntrySize %d\n", sctpEntrySize);
1896 (void) printf("\tsctpLocalEntrySize %d\n", sctpLocalEntrySize);
1897 (void) printf("\tsctpRemoteEntrySize %d\n",
1898 sctpRemoteEntrySize);
1899 }
1900 }
1901
1902
1903 /* ----------------------------- STAT_REPORT ------------------------------- */
1904
1905 static void
1906 stat_report(mib_item_t *item)
1907 {
1908 int jtemp = 0;
1909 char ifname[LIFNAMSIZ + 1];
1910
1911 /* 'for' loop 1: */
1912 for (; item; item = item->next_item) {
1913 if (Xflag) {
1914 (void) printf("\n--- Entry %d ---\n", ++jtemp);
1915 (void) printf("Group = %d, mib_id = %d, "
1916 "length = %d, valp = 0x%p\n",
1917 item->group, item->mib_id,
1918 item->length, item->valp);
5414 for (sp = item->valp;
5415 (char *)sp < (char *)item->valp + item->length;
5416 /* LINTED: (note 1) */
5417 sp = (mib2_sctpConnEntry_t *)((char *)sp + sctpEntrySize)) {
5418 attr = aptr == NULL ? NULL : *aptr++;
5419 if (Aflag ||
5420 sp->sctpAssocState >= MIB2_SCTP_established) {
5421 if (first == B_TRUE) {
5422 (void) puts(sctp_hdr);
5423 (void) puts(sctp_hdr_normal);
5424 first = B_FALSE;
5425 }
5426 sctp_conn_report_item(head, sp, attr);
5427 }
5428 }
5429 }
5430 if (attrs != NULL)
5431 free(attrs);
5432 }
5433
5434 static char *
5435 plural(int n)
5436 {
5437 return (n != 1 ? "s" : "");
5438 }
5439
5440 static char *
5441 pluraly(int n)
5442 {
5443 return (n != 1 ? "ies" : "y");
5444 }
5445
5446 static char *
5447 plurales(int n)
5448 {
5449 return (n != 1 ? "es" : "");
5450 }
5451
5452 static char *
5453 pktscale(n)
|
176 static void stat_report(mib_item_t *item);
177 static void mrt_stat_report(mib_item_t *item);
178 static void arp_report(mib_item_t *item);
179 static void ndp_report(mib_item_t *item);
180 static void mrt_report(mib_item_t *item);
181 static void if_stat_total(struct ifstat *oldstats,
182 struct ifstat *newstats, struct ifstat *sumstats);
183 static void if_report(mib_item_t *item, char *ifname,
184 int Iflag_only, boolean_t once_only);
185 static void if_report_ip4(mib2_ipAddrEntry_t *ap,
186 char ifname[], char logintname[],
187 struct ifstat *statptr, boolean_t ksp_not_null);
188 static void if_report_ip6(mib2_ipv6AddrEntry_t *ap6,
189 char ifname[], char logintname[],
190 struct ifstat *statptr, boolean_t ksp_not_null);
191 static void ire_report(const mib_item_t *item);
192 static void tcp_report(const mib_item_t *item);
193 static void udp_report(const mib_item_t *item);
194 static void group_report(mib_item_t *item);
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);
198 static void print_ip_stats(mib2_ip_t *ip);
199 static void print_icmp_stats(mib2_icmp_t *icmp);
200 static void print_ip6_stats(mib2_ipv6IfStatsEntry_t *ip6);
201 static void print_icmp6_stats(mib2_ipv6IfIcmpEntry_t *icmp6);
202 static void print_sctp_stats(mib2_sctp_t *tcp);
203 static void print_tcp_stats(mib2_tcp_t *tcp);
204 static void print_udp_stats(mib2_udp_t *udp);
205 static void print_rawip_stats(mib2_rawip_t *rawip);
206 static void print_igmp_stats(struct igmpstat *igps);
207 static void print_mrt_stats(struct mrtstat *mrts);
208 static void print_dccp_stats(mib2_dccp_t *dccp);
209 static void sum_ip6_stats(mib2_ipv6IfStatsEntry_t *ip6,
210 mib2_ipv6IfStatsEntry_t *sum6);
211 static void sum_icmp6_stats(mib2_ipv6IfIcmpEntry_t *icmp6,
212 mib2_ipv6IfIcmpEntry_t *sum6);
213 static void m_report(void);
214 static void dhcp_report(char *);
215
216 static uint64_t kstat_named_value(kstat_t *, char *);
217 static kid_t safe_kstat_read(kstat_ctl_t *, kstat_t *, void *);
218 static int isnum(char *);
219 static char *plural(int n);
220 static char *pluraly(int n);
221 static char *plurales(int n);
222 static void process_filter(char *arg);
223 static char *ifindex2str(uint_t, char *);
224 static boolean_t family_selected(int family);
225
226 static void usage(char *);
227 static void fatal(int errcode, char *str1, ...);
228
269 static int mfcctlSize;
270
271 static int ipv6IfStatsEntrySize;
272 static int ipv6IfIcmpEntrySize;
273 static int ipv6AddrEntrySize;
274 static int ipv6RouteEntrySize;
275 static int ipv6NetToMediaEntrySize;
276 static int ipv6MemberEntrySize;
277 static int ipv6GroupSourceEntrySize;
278
279 static int ipDestEntrySize;
280
281 static int transportMLPSize;
282 static int tcpConnEntrySize;
283 static int tcp6ConnEntrySize;
284 static int udpEntrySize;
285 static int udp6EntrySize;
286 static int sctpEntrySize;
287 static int sctpLocalEntrySize;
288 static int sctpRemoteEntrySize;
289 static int dccpEntrySize;
290 static int dccp6EntrySize;
291
292 #define protocol_selected(p) (proto == IPPROTO_MAX || proto == (p))
293
294 /* Machinery used for -f (filter) option */
295 enum { FK_AF = 0, FK_OUTIF, FK_DST, FK_FLAGS, NFILTERKEYS };
296
297 static const char *filter_keys[NFILTERKEYS] = {
298 "af", "outif", "dst", "flags"
299 };
300
301 static m_label_t *zone_security_label = NULL;
302
303 /* Flags on routes */
304 #define FLF_A 0x00000001
305 #define FLF_b 0x00000002
306 #define FLF_D 0x00000004
307 #define FLF_G 0x00000008
308 #define FLF_H 0x00000010
309 #define FLF_L 0x00000020
310 #define FLF_U 0x00000040
464 strcmp(optarg, "ip6") == 0) {
465 v4compat = 0; /* Overridden */
466 proto = IPPROTO_IPV6;
467 } else if (strcmp(optarg, "icmp") == 0) {
468 proto = IPPROTO_ICMP;
469 } else if (strcmp(optarg, "icmpv6") == 0 ||
470 strcmp(optarg, "icmp6") == 0) {
471 v4compat = 0; /* Overridden */
472 proto = IPPROTO_ICMPV6;
473 } else if (strcmp(optarg, "igmp") == 0) {
474 proto = IPPROTO_IGMP;
475 } else if (strcmp(optarg, "udp") == 0) {
476 proto = IPPROTO_UDP;
477 } else if (strcmp(optarg, "tcp") == 0) {
478 proto = IPPROTO_TCP;
479 } else if (strcmp(optarg, "sctp") == 0) {
480 proto = IPPROTO_SCTP;
481 } else if (strcmp(optarg, "raw") == 0 ||
482 strcmp(optarg, "rawip") == 0) {
483 proto = IPPROTO_RAW;
484 } else if (strcmp(optarg, "dccp") == 0) {
485 proto = IPPROTO_DCCP;
486 } else {
487 fatal(1, "%s: unknown protocol.\n", optarg);
488 }
489 break;
490
491 case 'I':
492 ifname = optarg;
493 Iflag = B_TRUE;
494 IFLAGMOD(Iflag_only, -1, 1); /* see macro def'n */
495 break;
496
497 case 'D':
498 DHCPflag = B_TRUE;
499 Iflag_only = 0;
500 break;
501
502 case 'T':
503 if (optarg) {
504 if (*optarg == 'u')
505 timestamp_fmt = UDATE;
611 print_timestamp(timestamp_fmt);
612
613 /* netstat: AF_INET[6] behaviour */
614 if (family_selected(AF_INET) || family_selected(AF_INET6)) {
615 if (Sflag) {
616 curritem = mib_item_diff(previtem, item);
617 if (curritem == NULL)
618 fatal(1, "can't process mib data, "
619 "out of memory\n");
620 mib_item_destroy(&previtem);
621 }
622
623 if (!(Dflag || Iflag || Rflag || Sflag || Mflag ||
624 MMflag || Pflag || Gflag || DHCPflag)) {
625 if (protocol_selected(IPPROTO_UDP))
626 udp_report(item);
627 if (protocol_selected(IPPROTO_TCP))
628 tcp_report(item);
629 if (protocol_selected(IPPROTO_SCTP))
630 sctp_report(item);
631 if (protocol_selected(IPPROTO_DCCP))
632 dccp_report(item);
633 }
634 if (Iflag)
635 if_report(item, ifname, Iflag_only, once_only);
636 if (Mflag)
637 m_report();
638 if (Rflag)
639 ire_report(item);
640 if (Sflag && MMflag) {
641 mrt_stat_report(curritem);
642 } else {
643 if (Sflag)
644 stat_report(curritem);
645 if (MMflag)
646 mrt_report(item);
647 }
648 if (Gflag)
649 group_report(item);
650 if (Pflag) {
651 if (family_selected(AF_INET))
652 arp_report(item);
997 tempp2;
998 tempp2 = tempp2->next_item) {
999 if (tempp2->mib_id == 0)
1000 switch (tempp2->group) {
1001 /*
1002 * upon adding a case here, the same
1003 * must also be added in the next
1004 * switch statement, alongwith
1005 * appropriate code
1006 */
1007 case MIB2_IP:
1008 case MIB2_IP6:
1009 case EXPER_DVMRP:
1010 case EXPER_IGMP:
1011 case MIB2_ICMP:
1012 case MIB2_ICMP6:
1013 case MIB2_TCP:
1014 case MIB2_UDP:
1015 case MIB2_SCTP:
1016 case EXPER_RAWIP:
1017 case MIB2_DCCP:
1018 nitems++;
1019 }
1020 }
1021 tempp2 = NULL;
1022 if (nitems == 0) {
1023 diffp = mib_item_dup(item2);
1024 return (diffp);
1025 }
1026
1027 diffp = (mib_item_t *)calloc(nitems, sizeof (mib_item_t));
1028 if (diffp == NULL)
1029 return (NULL);
1030 diffptr = diffp;
1031 /* 'for' loop 1: */
1032 for (tempp2 = item2; tempp2 != NULL; tempp2 = tempp2->next_item) {
1033 if (tempp2->mib_id != 0)
1034 continue; /* 'for' loop 1 */
1035 /* 'for' loop 2: */
1036 for (tempp1 = item1; tempp1 != NULL;
1037 tempp1 = tempp1->next_item) {
1444 MDIFF(d, s2, s1, sctpInCtrlChunks);
1445 MDIFF(d, s2, s1, sctpInOrderChunks);
1446 MDIFF(d, s2, s1, sctpInUnorderChunks);
1447 MDIFF(d, s2, s1, sctpInAck);
1448 MDIFF(d, s2, s1, sctpInDupAck);
1449 MDIFF(d, s2, s1, sctpInAckUnsent);
1450 MDIFF(d, s2, s1, sctpFragUsrMsgs);
1451 MDIFF(d, s2, s1, sctpReasmUsrMsgs);
1452 MDIFF(d, s2, s1, sctpOutSCTPPkts);
1453 MDIFF(d, s2, s1, sctpInSCTPPkts);
1454 MDIFF(d, s2, s1, sctpInInvalidCookie);
1455 MDIFF(d, s2, s1, sctpTimRetrans);
1456 MDIFF(d, s2, s1, sctpTimRetransDrop);
1457 MDIFF(d, s2, s1, sctpTimHeartBeatProbe);
1458 MDIFF(d, s2, s1, sctpTimHeartBeatDrop);
1459 MDIFF(d, s2, s1, sctpListenDrop);
1460 MDIFF(d, s2, s1, sctpInClosed);
1461 prevp = diffptr++;
1462 break;
1463 }
1464 case MIB2_DCCP: {
1465 /* XXX:DCCP */
1466 break;
1467 }
1468 case EXPER_RAWIP: {
1469 mib2_rawip_t *r2;
1470 mib2_rawip_t *r1;
1471 mib2_rawip_t *d;
1472
1473 r2 = (mib2_rawip_t *)tempp2->valp;
1474 r1 = (mib2_rawip_t *)tempp1->valp;
1475 diffptr->group = tempp2->group;
1476 diffptr->mib_id = tempp2->mib_id;
1477 diffptr->length = tempp2->length;
1478 d = (mib2_rawip_t *)calloc(tempp2->length, 1);
1479 if (d == NULL)
1480 goto mibdiff_out_of_memory;
1481 diffptr->valp = d;
1482 MDIFF(d, r2, r1, rawipInDatagrams);
1483 MDIFF(d, r2, r1, rawipInErrors);
1484 MDIFF(d, r2, r1, rawipInCksumErrs);
1485 MDIFF(d, r2, r1, rawipOutDatagrams);
1486 MDIFF(d, r2, r1, rawipOutErrors);
1487 prevp = diffptr++;
1857 }
1858 case MIB2_UDP: {
1859 mib2_udp_t *udp = (mib2_udp_t *)item->valp;
1860
1861 udpEntrySize = udp->udpEntrySize;
1862 udp6EntrySize = udp->udp6EntrySize;
1863 assert(IS_P2ALIGNED(udpEntrySize,
1864 sizeof (mib2_udpEntry_t *)));
1865 assert(IS_P2ALIGNED(udp6EntrySize,
1866 sizeof (mib2_udp6Entry_t *)));
1867 break;
1868 }
1869 case MIB2_SCTP: {
1870 mib2_sctp_t *sctp = (mib2_sctp_t *)item->valp;
1871
1872 sctpEntrySize = sctp->sctpEntrySize;
1873 sctpLocalEntrySize = sctp->sctpLocalEntrySize;
1874 sctpRemoteEntrySize = sctp->sctpRemoteEntrySize;
1875 break;
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 }
1888 }
1889 } /* 'for' loop 1 ends */
1890
1891 if (Xflag) {
1892 (void) puts("mib_get_constants:");
1893 (void) printf("\tipv6IfStatsEntrySize %d\n",
1894 ipv6IfStatsEntrySize);
1895 (void) printf("\tipAddrEntrySize %d\n", ipAddrEntrySize);
1896 (void) printf("\tipRouteEntrySize %d\n", ipRouteEntrySize);
1897 (void) printf("\tipNetToMediaEntrySize %d\n",
1898 ipNetToMediaEntrySize);
1899 (void) printf("\tipMemberEntrySize %d\n", ipMemberEntrySize);
1900 (void) printf("\tipRouteAttributeSize %d\n",
1901 ipRouteAttributeSize);
1902 (void) printf("\tvifctlSize %d\n", vifctlSize);
1903 (void) printf("\tmfcctlSize %d\n", mfcctlSize);
1904
1905 (void) printf("\tipv6AddrEntrySize %d\n", ipv6AddrEntrySize);
1906 (void) printf("\tipv6RouteEntrySize %d\n", ipv6RouteEntrySize);
1907 (void) printf("\tipv6NetToMediaEntrySize %d\n",
1908 ipv6NetToMediaEntrySize);
1909 (void) printf("\tipv6MemberEntrySize %d\n",
1910 ipv6MemberEntrySize);
1911 (void) printf("\tipv6IfIcmpEntrySize %d\n",
1912 ipv6IfIcmpEntrySize);
1913 (void) printf("\tipDestEntrySize %d\n", ipDestEntrySize);
1914 (void) printf("\ttransportMLPSize %d\n", transportMLPSize);
1915 (void) printf("\ttcpConnEntrySize %d\n", tcpConnEntrySize);
1916 (void) printf("\ttcp6ConnEntrySize %d\n", tcp6ConnEntrySize);
1917 (void) printf("\tudpEntrySize %d\n", udpEntrySize);
1918 (void) printf("\tudp6EntrySize %d\n", udp6EntrySize);
1919 (void) printf("\tsctpEntrySize %d\n", sctpEntrySize);
1920 (void) printf("\tsctpLocalEntrySize %d\n", sctpLocalEntrySize);
1921 (void) printf("\tsctpRemoteEntrySize %d\n",
1922 sctpRemoteEntrySize);
1923 (void) printf("\tdccpEntrySize %d\n", dccpEntrySize);
1924 (void) printf("\ttcp6EntrySize %d\n", dccp6EntrySize);
1925 }
1926 }
1927
1928
1929 /* ----------------------------- STAT_REPORT ------------------------------- */
1930
1931 static void
1932 stat_report(mib_item_t *item)
1933 {
1934 int jtemp = 0;
1935 char ifname[LIFNAMSIZ + 1];
1936
1937 /* 'for' loop 1: */
1938 for (; item; item = item->next_item) {
1939 if (Xflag) {
1940 (void) printf("\n--- Entry %d ---\n", ++jtemp);
1941 (void) printf("Group = %d, mib_id = %d, "
1942 "length = %d, valp = 0x%p\n",
1943 item->group, item->mib_id,
1944 item->length, item->valp);
5440 for (sp = item->valp;
5441 (char *)sp < (char *)item->valp + item->length;
5442 /* LINTED: (note 1) */
5443 sp = (mib2_sctpConnEntry_t *)((char *)sp + sctpEntrySize)) {
5444 attr = aptr == NULL ? NULL : *aptr++;
5445 if (Aflag ||
5446 sp->sctpAssocState >= MIB2_SCTP_established) {
5447 if (first == B_TRUE) {
5448 (void) puts(sctp_hdr);
5449 (void) puts(sctp_hdr_normal);
5450 first = B_FALSE;
5451 }
5452 sctp_conn_report_item(head, sp, attr);
5453 }
5454 }
5455 }
5456 if (attrs != NULL)
5457 free(attrs);
5458 }
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
5587 static char *
5588 plural(int n)
5589 {
5590 return (n != 1 ? "s" : "");
5591 }
5592
5593 static char *
5594 pluraly(int n)
5595 {
5596 return (n != 1 ? "ies" : "y");
5597 }
5598
5599 static char *
5600 plurales(int n)
5601 {
5602 return (n != 1 ? "es" : "");
5603 }
5604
5605 static char *
5606 pktscale(n)
|