3 * ===================================
4 * HARP | Host ATM Research Platform
5 * ===================================
8 * This Host ATM Research Platform ("HARP") file (the "Software") is
9 * made available by Network Computing Services, Inc. ("NetworkCS")
10 * "AS IS". NetworkCS does not provide maintenance, improvements or
11 * support of any kind.
13 * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15 * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16 * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17 * In no event shall NetworkCS be responsible for any damages, including
18 * but not limited to consequential damages, arising from or relating to
19 * any use of the Software or related support.
21 * Copyright 1994-1998 Network Computing Services, Inc.
23 * Copies of this Software may be made, however, the above copyright
24 * notice must be reproduced on all copies.
28 * User configuration and display program
29 * --------------------------------------
31 * Print routines for "show" subcommand
35 #include <sys/param.h>
36 #include <sys/socket.h>
38 #include <netinet/in.h>
39 #include <arpa/inet.h>
40 #include <netatm/port.h>
41 #include <netatm/atm.h>
42 #include <netatm/atm_if.h>
43 #include <netatm/atm_sap.h>
44 #include <netatm/atm_sigmgr.h>
45 #include <netatm/atm_sys.h>
46 #include <netatm/atm_vc.h>
47 #include <netatm/atm_ioctl.h>
48 #include <netatm/ipatm/ipatm_var.h>
49 #include <netatm/sigpvc/sigpvc_var.h>
50 #include <netatm/spans/spans_var.h>
51 #include <netatm/uni/uniip_var.h>
52 #include <netatm/uni/unisig_var.h>
63 __RCSID("@(#) $FreeBSD$");
68 "Net Intf Flags Age Origin\n"
71 "Net Intf State ATM Address\n"
74 "Intf Vendor Model Media Bus Serial No\n"
77 "Net Intf VPI VCI State Flags IP Address\n"
80 "Interface Sigmgr State\n"
83 "Net Intf Phy Intf IP Address\n"
86 "Interface VPI VCI AAL Type Dir State Encaps Owner\n"
88 #define VCC_STATS_HDR \
89 " Input Input Input Output Output Output\n\
90 Interface VPI VCI PDUs Bytes Errs PDUs Bytes Errs\n"
95 #define PHY_STATS_HDR \
96 " Input Input Input Output Output Output Cmd\n\
97 Interface PDUs Bytes Errs PDUs Bytes Errs Errs\n"
102 static int arp_hdr = 0;
103 static int asrv_hdr = 0;
104 static int cfg_hdr = 0;
105 static int ip_vcc_hdr = 0;
106 static int netif_hdr = 0;
107 static int vcc_hdr = 0;
108 static int vcc_stats_hdr = 0;
109 static int phy_stats_hdr = 0;
110 static int version_hdr = 0;
113 * SIGPVC state definitions
115 static const struct state sigpvc_states[] = {
116 { "ACTIVE", SIGPVC_ACTIVE },
117 { "DETACH", SIGPVC_DETACH },
122 * SPANS state definitions
124 static const struct state spans_states[] = {
125 { "ACTIVE", SPANS_ACTIVE },
126 { "DETACH", SPANS_DETACH },
127 { "INIT", SPANS_INIT },
128 { "PROBE", SPANS_PROBE },
133 * UNISIG state definitions
135 static const struct state unisig_states[] = {
136 { "NULL", UNISIG_NULL },
137 { "ADR_WAIT", UNISIG_ADDR_WAIT },
138 { "INIT", UNISIG_INIT },
139 { "ACTIVE", UNISIG_ACTIVE },
140 { "DETACH", UNISIG_DETACH },
145 * SIGPVC VCC state definitions
147 static const struct state sigpvc_vcc_states[] = {
148 { "NULL", VCCS_NULL },
149 { "ACTIVE", VCCS_ACTIVE },
150 { "FREE", VCCS_FREE },
155 * SPANS VCC state definitions
157 static const struct state spans_vcc_states[] = {
158 { "NULL", SPANS_VC_NULL },
159 { "ACTIVE", SPANS_VC_ACTIVE },
160 { "ACT_DOWN", SPANS_VC_ACT_DOWN },
161 { "POPEN", SPANS_VC_POPEN },
162 { "R_POPEN", SPANS_VC_R_POPEN },
163 { "OPEN", SPANS_VC_OPEN },
164 { "CLOSE", SPANS_VC_CLOSE },
165 { "ABORT", SPANS_VC_ABORT },
166 { "FREE", SPANS_VC_FREE },
171 * UNISIG VCC state definitions
173 static const struct state unisig_vcc_states[] = {
174 { "NULL", UNI_NULL },
175 { "C_INIT", UNI_CALL_INITIATED },
176 { "C_OUT_PR", UNI_CALL_OUT_PROC },
177 { "C_DELIV", UNI_CALL_DELIVERED },
178 { "C_PRES", UNI_CALL_PRESENT },
179 { "C_REC", UNI_CALL_RECEIVED },
180 { "CONN_REQ", UNI_CONNECT_REQUEST },
181 { "C_IN_PR", UNI_CALL_IN_PROC },
182 { "ACTIVE", UNI_ACTIVE },
183 { "REL_REQ", UNI_RELEASE_REQUEST },
184 { "REL_IND", UNI_RELEASE_IND },
185 { "SSCF_REC", UNI_SSCF_RECOV },
186 { "FREE", UNI_FREE },
187 { "ACTIVE", UNI_PVC_ACTIVE },
188 { "ACT_DOWN", UNI_PVC_ACT_DOWN },
193 * IP VCC state definitions
195 static const struct state ip_vcc_states[] = {
196 { "FREE", IPVCC_FREE },
197 { "PMAP", IPVCC_PMAP },
198 { "POPEN", IPVCC_POPEN },
199 { "PACCEPT", IPVCC_PACCEPT },
200 { "ACTPENT", IPVCC_ACTPENT },
201 { "ACTIVE", IPVCC_ACTIVE },
202 { "CLOSED", IPVCC_CLOSED },
207 * ARP server state definitions
209 static const struct state arpserver_states[] = {
210 { "NOT_CONF", UIAS_NOTCONF },
211 { "SERVER", UIAS_SERVER_ACTIVE },
212 { "PEND_ADR", UIAS_CLIENT_PADDR },
213 { "POPEN", UIAS_CLIENT_POPEN },
214 { "REGISTER", UIAS_CLIENT_REGISTER },
215 { "ACTIVE", UIAS_CLIENT_ACTIVE },
220 * Supported signalling managers
222 static const struct proto_state proto_states[] = {
223 { "SIGPVC", sigpvc_states, sigpvc_vcc_states, ATM_SIG_PVC },
224 { "SPANS", spans_states, spans_vcc_states, ATM_SIG_SPANS },
225 { "UNI 3.0", unisig_states, unisig_vcc_states, ATM_SIG_UNI30 },
226 { "UNI 3.1", unisig_states, unisig_vcc_states, ATM_SIG_UNI31 },
227 { "UNI 4.0", unisig_states, unisig_vcc_states, ATM_SIG_UNI40 },
232 * ATMARP origin values
234 static const struct state arp_origins[] = {
235 { "LOCAL", UAO_LOCAL },
236 { "PERM", UAO_PERM },
237 { "REG", UAO_REGISTER },
238 { "SCSP", UAO_SCSP },
239 { "LOOKUP", UAO_LOOKUP },
240 { "PEER_RSP", UAO_PEER_RSP },
241 { "PEER_REQ", UAO_PEER_REQ },
247 * Print ARP table information
250 * ai pointer to a struct air_arp_rsp
258 struct air_arp_rsp *ai;
261 const char *atm_addr, *ip_addr, *origin;
262 char age[8], flags[32];
263 struct sockaddr_in *sain;
266 * Print a header if it hasn't been done yet.
274 * Format the addresses
276 atm_addr = format_atm_addr(&ai->aap_addr);
277 sain = (struct sockaddr_in *)(void *)&ai->aap_arp_addr;
278 ip_addr = format_ip_addr(&sain->sin_addr);
283 bzero(flags, sizeof(flags));
284 if (ai->aap_flags & ARPF_VALID) {
287 if (ai->aap_flags & ARPF_REFRESH) {
294 for (i=0; arp_origins[i].s_name != NULL &&
295 ai->aap_origin != arp_origins[i].s_id;
297 if (arp_origins[i].s_name) {
298 origin = arp_origins[i].s_name;
306 bzero(age, sizeof(age));
307 if (!(ai->aap_flags & ARPF_VALID)) {
310 sprintf(age, "%d", ai->aap_age);
314 * Print the ARP information
316 printf("%-8s %-5s %3s %s\n ATM address = %s\n IP address = %s\n",
327 * Print ARP server information
330 * si pointer to a struct air_asrv_rsp
338 struct air_asrv_rsp *si;
341 const char *atm_addr, *state;
342 struct in_addr *addr;
345 * Print a header if it hasn't been done yet.
353 * Format the ATM address of the ARP server
355 atm_addr = format_atm_addr(&si->asp_addr);
358 * Format the server state
360 for (i=0; arpserver_states[i].s_name != NULL &&
361 si->asp_state != arpserver_states[i].s_id;
363 if (arpserver_states[i].s_name) {
364 state = arpserver_states[i].s_name;
370 * Print the ARP server information
372 printf("%-8s %-8s %s\n",
378 * Format and print the LIS prefixes
380 if (si->asp_nprefix) {
381 addr = (struct in_addr *)((u_long)si +
382 sizeof(struct air_asrv_rsp));
384 for (i = 0; i < si->asp_nprefix; i++) {
385 printf("%s", inet_ntoa(*addr));
387 printf("/0x%0lx", (u_long)ntohl(addr->s_addr));
389 if (i < si->asp_nprefix -1)
398 * Print adapter configuration information
401 * si pointer to a struct air_cfg_rsp
409 struct air_cfg_rsp *si;
411 const char *adapter, *bus, *media, *vendor;
414 * Print a header if it hasn't been done yet.
422 * Format the vendor name and adapter type
424 vendor = get_vendor(si->acp_vendor);
425 adapter = get_adapter(si->acp_device);
428 * Format the communications medium
430 media = get_media_type(si->acp_media);
431 bus = get_bus_type(si->acp_bustype);
434 * Print the ARP server information
436 printf("%-8s %-8s %-8s %-14s %-4s %ld\n",
443 printf(" MAC address = %s\n",
444 format_mac_addr(&si->acp_macaddr));
445 printf(" Hardware version = %s\n", si->acp_hard_vers);
446 printf(" Firmware version = %s\n", si->acp_firm_vers);
451 * Print interface information
454 * ni pointer to a struct air_int_rsp
462 struct air_int_rsp *ni;
465 char nif_names[(IFNAMSIZ *2)+4];
467 const char *sigmgr = "-";
468 const char *state_name = "-";
469 const struct state *s_t;
477 * Translate signalling manager name
479 for (i=0; proto_states[i].p_state != NULL; i++)
480 if (ni->anp_sig_proto == proto_states[i].p_id)
482 if (proto_states[i].p_state != NULL)
483 sigmgr = proto_states[i].p_name;
486 * Get the signalling manager state
488 if (proto_states[i].p_state != NULL) {
489 s_t = proto_states[i].p_state;
490 for (i=0; s_t[i].s_name != NULL; i++)
491 if (ni->anp_sig_state == s_t[i].s_id)
493 if (s_t[i].s_name != NULL)
494 state_name = s_t[i].s_name;
498 * Format the ATM address
500 atm_addr = format_atm_addr(&ni->anp_addr);
503 * Get the range of NIFs on the physical interface
505 bzero(nif_names, sizeof(nif_names));
506 if (strlen(ni->anp_nif_pref) == 0) {
507 strcpy(nif_names, "-");
509 strcpy(nif_names, ni->anp_nif_pref);
510 strcat(nif_names, "0");
511 if (ni->anp_nif_cnt > 1) {
512 strcat(nif_names, " - ");
513 strcat(nif_names, ni->anp_nif_pref);
514 sprintf(&nif_names[strlen(nif_names)], "%d",
521 * Print the interface information
523 printf("%-9s %-7s %s\n",
527 printf(" ATM address = %s\n", atm_addr);
528 printf(" Network interfaces: %s\n", nif_names);
533 * Print IP address map information
536 * ai pointer to a struct air_arp_rsp
543 print_ip_vcc_info(ai)
544 struct air_ip_vcc_rsp *ai;
547 const char *ip_addr, *state;
548 char flags[32], vpi_vci[16];
549 struct sockaddr_in *sain;
552 * Print a header if it hasn't been done yet.
560 * Format the IP address
562 sain = (struct sockaddr_in *)(void *)&ai->aip_dst_addr;
563 ip_addr = format_ip_addr(&sain->sin_addr);
568 if (ai->aip_vpi == 0 && ai->aip_vci == 0) {
569 strcpy(vpi_vci, " - -");
571 sprintf(vpi_vci, "%3d %5d", ai->aip_vpi, ai->aip_vci);
577 bzero(flags, sizeof(flags));
578 if (ai->aip_flags & IVF_PVC) {
581 if (ai->aip_flags & IVF_SVC) {
584 if (ai->aip_flags & IVF_LLC) {
587 if (ai->aip_flags & IVF_MAPOK) {
590 if (ai->aip_flags & IVF_NOIDLE) {
595 * Get the state of the VCC
597 for (i=0; ip_vcc_states[i].s_name != NULL &&
598 ai->aip_state != ip_vcc_states[i].s_id;
600 if (ip_vcc_states[i].s_name) {
601 state = ip_vcc_states[i].s_name;
607 * Print the IP VCC information
609 printf("%-8s %9s %-7s %-5s %s\n",
619 * Print network interface information
622 * ni pointer to a struct air_int_rsp
630 struct air_netif_rsp *ni;
633 struct sockaddr_in *sain;
644 * Format the protocol address
646 sain = (struct sockaddr_in *)(void *)&ni->anp_proto_addr;
647 ip_addr = format_ip_addr(&sain->sin_addr);
650 * Print the network interface information
652 printf("%-8s %-8s %s\n",
660 * Print physical interface statistics
663 * pi pointer to a struct air_phy_stat_rsp
671 struct air_phy_stat_rsp *pi;
674 * Print a header if it hasn't already been done
676 if (!phy_stats_hdr) {
677 printf(PHY_STATS_HDR);
682 * Print the interface statistics
684 printf("%-9s %7lld %8lld %5lld %7lld %8lld %5lld %5lld\n",
686 (unsigned long long)pi->app_ipdus,
687 (unsigned long long)pi->app_ibytes,
688 (unsigned long long)pi->app_ierrors,
689 (unsigned long long)pi->app_opdus,
690 (unsigned long long)pi->app_obytes,
691 (unsigned long long)pi->app_oerrors,
692 (unsigned long long)pi->app_cmderrors);
697 * Print VCC statistics
700 * vi pointer to VCC statistics to print
708 struct air_vcc_rsp *vi;
712 * Print a header if it hasn't already been done
714 if (!vcc_stats_hdr) {
715 printf(VCC_STATS_HDR);
720 * Print the VCC statistics
722 printf("%-9s %3d %4d",
726 if ( vi->avp_type & VCC_IN )
727 printf ( " %7ld %8ld %5ld",
734 if ( vi->avp_type & VCC_OUT )
735 printf ( " %7ld %8ld %5ld\n",
740 printf ( " - - -\n" );
745 * Print VCC information
748 * vi pointer to a struct air_vcc_rsp
756 struct air_vcc_rsp *vi;
759 const char *aal_name = "-" , *encaps_name = "-", *owner_name = "-";
760 const char *state_name = "-", *type_name = "-";
762 const struct state *s_t;
765 * Print a header if it hasn't already been done
775 for (i=0; aals[i].a_name != NULL; i++)
776 if (vi->avp_aal == aals[i].a_id)
779 aal_name = aals[i].a_name;
784 if (vi->avp_type & VCC_PVC)
786 else if (vi->avp_type & VCC_SVC)
789 * Translate VCC direction
791 bzero(dir_name, sizeof(dir_name));
792 if (vi->avp_type & VCC_IN)
793 strcat(dir_name, "In");
794 if (vi->avp_type & VCC_OUT)
795 strcat(dir_name, "Out");
796 if (strlen(dir_name) == 0)
797 strcpy(dir_name, "-");
802 for (i=0; proto_states[i].p_state != NULL; i++)
803 if (vi->avp_sig_proto == proto_states[i].p_id)
805 if (proto_states[i].p_state) {
806 s_t = proto_states[i].v_state;
807 for (i=0; s_t[i].s_name != NULL; i++)
808 if (vi->avp_state == s_t[i].s_id)
811 state_name = s_t[i].s_name;
815 * Translate encapsulation
817 for (i=0; encaps[i].e_name != NULL; i++)
818 if (vi->avp_encaps == encaps[i].e_id)
820 if (encaps[i].e_name)
821 encaps_name = encaps[i].e_name;
824 * Print the VCC information
826 printf("%-9s %3d %5d %-4s %-4s %-5s %-8s %-8s ",
837 * Print VCC owners' names
839 for (i = 0, owner_name = vi->avp_owners;
840 i < O_CNT - 1 && strlen(owner_name);
841 i++, owner_name += (T_ATM_APP_NAME_LEN + 1)) {
844 printf("%s", owner_name);
851 * Print destination address if it's an SVC
853 if (vi->avp_type & VCC_SVC) {
854 printf(" Dest = %s\n",
855 format_atm_addr(&vi->avp_daddr));
861 * Print network interface information
864 * ni pointer to a struct air_int_rsp
871 print_version_info(vi)
872 struct air_version_rsp *vi;
874 char version_str[80];
885 * Print the interface information
887 sprintf(version_str, "%d.%d",
888 ATM_VERS_MAJ(vi->avp_version),
889 ATM_VERS_MIN(vi->avp_version));
890 printf("%7s\n", version_str);