121989Sdist /* 234902Sbostic * Copyright (c) 1983, 1988 Regents of the University of California. 333451Skarels * All rights reserved. 433451Skarels * 542748Sbostic * %sccs.include.redist.c% 621989Sdist */ 721989Sdist 87908Ssam #ifndef lint 9*53698Ssklower static char sccsid[] = "@(#)mbuf.c 5.11 (Berkeley) 05/27/92"; 1034902Sbostic #endif /* not lint */ 117908Ssam 129568Ssam #include <sys/param.h> 13*53698Ssklower #include <sys/protosw.h> 14*53698Ssklower #include <sys/socket.h> 157908Ssam #include <sys/mbuf.h> 16*53698Ssklower 17*53698Ssklower #include <stdio.h> 18*53698Ssklower #include "netstat.h" 19*53698Ssklower 2018594Skupfer #define YES 1 2118594Skupfer typedef int bool; 227908Ssam 237908Ssam struct mbstat mbstat; 247908Ssam 259837Ssam static struct mbtypes { 269837Ssam int mt_type; 279837Ssam char *mt_name; 289837Ssam } mbtypes[] = { 299837Ssam { MT_DATA, "data" }, 3039217Skarels { MT_OOBDATA, "oob data" }, 3139217Skarels { MT_CONTROL, "ancillary data" }, 329837Ssam { MT_HEADER, "packet headers" }, 3339217Skarels { MT_SOCKET, "socket structures" }, /* XXX */ 3439217Skarels { MT_PCB, "protocol control blocks" }, /* XXX */ 3539217Skarels { MT_RTABLE, "routing table entries" }, /* XXX */ 3639217Skarels { MT_HTABLE, "IMP host table entries" }, /* XXX */ 379837Ssam { MT_ATABLE, "address resolution tables" }, 3839217Skarels { MT_FTABLE, "fragment reassembly queue headers" }, /* XXX */ 399837Ssam { MT_SONAME, "socket names and addresses" }, 409837Ssam { MT_SOOPTS, "socket options" }, 4117232Ssam { MT_RIGHTS, "access rights" }, 42*53698Ssklower { MT_IFADDR, "interface addresses" }, /* XXX */ 439837Ssam { 0, 0 } 449837Ssam }; 459837Ssam 4618594Skupfer int nmbtypes = sizeof(mbstat.m_mtypes) / sizeof(short); 4718594Skupfer bool seen[256]; /* "have we seen this type yet?" */ 4818594Skupfer 497908Ssam /* 507908Ssam * Print mbuf statistics. 517908Ssam */ 52*53698Ssklower void 537908Ssam mbpr(mbaddr) 547908Ssam off_t mbaddr; 557908Ssam { 569837Ssam register int totmem, totfree, totmbufs; 5718594Skupfer register int i; 589837Ssam register struct mbtypes *mp; 599568Ssam 6018594Skupfer if (nmbtypes != 256) { 61*53698Ssklower fprintf(stderr, 62*53698Ssklower "%s: unexpected change to mbstat; check source\n", prog); 6318594Skupfer return; 6418594Skupfer } 657908Ssam if (mbaddr == 0) { 66*53698Ssklower fprintf(stderr, "%s: mbstat: symbol not in namelist\n", prog); 677908Ssam return; 687908Ssam } 69*53698Ssklower if (kread(mbaddr, (char *)&mbstat, sizeof (mbstat))) 709568Ssam return; 719837Ssam totmbufs = 0; 729837Ssam for (mp = mbtypes; mp->mt_name; mp++) 7339217Skarels totmbufs += mbstat.m_mtypes[mp->mt_type]; 7439217Skarels printf("%u mbufs in use:\n", totmbufs); 7539217Skarels for (mp = mbtypes; mp->mt_name; mp++) 769837Ssam if (mbstat.m_mtypes[mp->mt_type]) { 7718594Skupfer seen[mp->mt_type] = YES; 7830451Skarels printf("\t%u mbufs allocated to %s\n", 7918594Skupfer mbstat.m_mtypes[mp->mt_type], mp->mt_name); 809837Ssam } 8118594Skupfer seen[MT_FREE] = YES; 8218594Skupfer for (i = 0; i < nmbtypes; i++) 8318594Skupfer if (!seen[i] && mbstat.m_mtypes[i]) { 8430451Skarels printf("\t%u mbufs allocated to <mbuf type %d>\n", 8518594Skupfer mbstat.m_mtypes[i], i); 8618594Skupfer } 8730451Skarels printf("%u/%u mapped pages in use\n", 889568Ssam mbstat.m_clusters - mbstat.m_clfree, mbstat.m_clusters); 8946165Skarels totmem = totmbufs * MSIZE + mbstat.m_clusters * MCLBYTES; 9046165Skarels totfree = mbstat.m_clfree * MCLBYTES; 9130451Skarels printf("%u Kbytes allocated to network (%d%% in use)\n", 929576Ssam totmem / 1024, (totmem - totfree) * 100 / totmem); 9330451Skarels printf("%u requests for memory denied\n", mbstat.m_drops); 9430451Skarels printf("%u requests for memory delayed\n", mbstat.m_wait); 9530451Skarels printf("%u calls to protocol drain routines\n", mbstat.m_drain); 967908Ssam } 97