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.
26 * @(#) $FreeBSD: src/sbin/atm/atm/atm_print.c,v 1.3.2.1 2000/07/01 06:02:14 ps Exp $
31 * User configuration and display program
32 * --------------------------------------
34 * Print routines for "show" subcommand
38 #include <sys/param.h>
39 #include <sys/socket.h>
41 #include <netinet/in.h>
42 #include <arpa/inet.h>
43 #include <netatm/port.h>
44 #include <netatm/atm.h>
45 #include <netatm/atm_if.h>
46 #include <netatm/atm_sap.h>
47 #include <netatm/atm_sigmgr.h>
48 #include <netatm/atm_sys.h>
49 #include <netatm/atm_vc.h>
50 #include <netatm/atm_ioctl.h>
51 #include <netatm/ipatm/ipatm_var.h>
52 #include <netatm/sigpvc/sigpvc_var.h>
53 #include <netatm/spans/spans_var.h>
54 #include <netatm/uni/uniip_var.h>
55 #include <netatm/uni/unisig_var.h>
66 __RCSID("@(#) $FreeBSD: src/sbin/atm/atm/atm_print.c,v 1.3.2.1 2000/07/01 06:02:14 ps Exp $");
71 "Net Intf Flags Age Origin\n"
74 "Net Intf State ATM Address\n"
77 "Intf Vendor Model Media Bus Serial No\n"
80 "Net Intf VPI VCI State Flags IP Address\n"
83 "Interface Sigmgr State\n"
86 "Net Intf Phy Intf IP Address\n"
89 "Interface VPI VCI AAL Type Dir State Encaps Owner\n"
91 #define VCC_STATS_HDR \
92 " Input Input Input Output Output Output\n\
93 Interface VPI VCI PDUs Bytes Errs PDUs Bytes Errs\n"
98 #define PHY_STATS_HDR \
99 " Input Input Input Output Output Output Cmd\n\
100 Interface PDUs Bytes Errs PDUs Bytes Errs Errs\n"
103 * External references
105 extern struct proto protos[];
106 extern struct aal aals[];
107 extern struct encaps encaps[];
112 static int arp_hdr = 0;
113 static int asrv_hdr = 0;
114 static int cfg_hdr = 0;
115 static int ip_vcc_hdr = 0;
116 static int netif_hdr = 0;
117 static int vcc_hdr = 0;
118 static int vcc_stats_hdr = 0;
119 static int phy_stats_hdr = 0;
120 static int version_hdr = 0;
123 * SIGPVC state definitions
125 struct state sigpvc_states[] = {
126 { "ACTIVE", SIGPVC_ACTIVE },
127 { "DETACH", SIGPVC_DETACH },
132 * SPANS state definitions
134 struct state spans_states[] = {
135 { "ACTIVE", SPANS_ACTIVE },
136 { "DETACH", SPANS_DETACH },
137 { "INIT", SPANS_INIT },
138 { "PROBE", SPANS_PROBE },
143 * UNISIG state definitions
145 struct state unisig_states[] = {
146 { "NULL", UNISIG_NULL },
147 { "ADR_WAIT", UNISIG_ADDR_WAIT },
148 { "INIT", UNISIG_INIT },
149 { "ACTIVE", UNISIG_ACTIVE },
150 { "DETACH", UNISIG_DETACH },
155 * SIGPVC VCC state definitions
157 struct state sigpvc_vcc_states[] = {
158 { "NULL", VCCS_NULL },
159 { "ACTIVE", VCCS_ACTIVE },
160 { "FREE", VCCS_FREE },
165 * SPANS VCC state definitions
167 struct state spans_vcc_states[] = {
168 { "NULL", SPANS_VC_NULL },
169 { "ACTIVE", SPANS_VC_ACTIVE },
170 { "ACT_DOWN", SPANS_VC_ACT_DOWN },
171 { "POPEN", SPANS_VC_POPEN },
172 { "R_POPEN", SPANS_VC_R_POPEN },
173 { "OPEN", SPANS_VC_OPEN },
174 { "CLOSE", SPANS_VC_CLOSE },
175 { "ABORT", SPANS_VC_ABORT },
176 { "FREE", SPANS_VC_FREE },
181 * UNISIG VCC state definitions
183 struct state unisig_vcc_states[] = {
184 { "NULL", UNI_NULL },
185 { "C_INIT", UNI_CALL_INITIATED },
186 { "C_OUT_PR", UNI_CALL_OUT_PROC },
187 { "C_DELIV", UNI_CALL_DELIVERED },
188 { "C_PRES", UNI_CALL_PRESENT },
189 { "C_REC", UNI_CALL_RECEIVED },
190 { "CONN_REQ", UNI_CONNECT_REQUEST },
191 { "C_IN_PR", UNI_CALL_IN_PROC },
192 { "ACTIVE", UNI_ACTIVE },
193 { "REL_REQ", UNI_RELEASE_REQUEST },
194 { "REL_IND", UNI_RELEASE_IND },
195 { "SSCF_REC", UNI_SSCF_RECOV },
196 { "FREE", UNI_FREE },
197 { "ACTIVE", UNI_PVC_ACTIVE },
198 { "ACT_DOWN", UNI_PVC_ACT_DOWN },
203 * IP VCC state definitions
205 struct state ip_vcc_states[] = {
206 { "FREE", IPVCC_FREE },
207 { "PMAP", IPVCC_PMAP },
208 { "POPEN", IPVCC_POPEN },
209 { "PACCEPT", IPVCC_PACCEPT },
210 { "ACTPENT", IPVCC_ACTPENT },
211 { "ACTIVE", IPVCC_ACTIVE },
212 { "CLOSED", IPVCC_CLOSED },
217 * ARP server state definitions
219 struct state arpserver_states[] = {
220 { "NOT_CONF", UIAS_NOTCONF },
221 { "SERVER", UIAS_SERVER_ACTIVE },
222 { "PEND_ADR", UIAS_CLIENT_PADDR },
223 { "POPEN", UIAS_CLIENT_POPEN },
224 { "REGISTER", UIAS_CLIENT_REGISTER },
225 { "ACTIVE", UIAS_CLIENT_ACTIVE },
230 * Supported signalling managers
232 struct proto_state proto_states[] = {
233 { "SIGPVC", sigpvc_states, sigpvc_vcc_states, ATM_SIG_PVC },
234 { "SPANS", spans_states, spans_vcc_states, ATM_SIG_SPANS },
235 { "UNI 3.0", unisig_states, unisig_vcc_states, ATM_SIG_UNI30 },
236 { "UNI 3.1", unisig_states, unisig_vcc_states, ATM_SIG_UNI31 },
237 { "UNI 4.0", unisig_states, unisig_vcc_states, ATM_SIG_UNI40 },
242 * ATMARP origin values
244 struct state arp_origins[] = {
245 { "LOCAL", UAO_LOCAL },
246 { "PERM", UAO_PERM },
247 { "REG", UAO_REGISTER },
248 { "SCSP", UAO_SCSP },
249 { "LOOKUP", UAO_LOOKUP },
250 { "PEER_RSP", UAO_PEER_RSP },
251 { "PEER_REQ", UAO_PEER_REQ },
257 * Print ARP table information
260 * ai pointer to a struct air_arp_rsp
268 struct air_arp_rsp *ai;
271 char *atm_addr, *ip_addr, *origin;
272 char age[8], flags[32];
273 struct sockaddr_in *sin;
276 * Print a header if it hasn't been done yet.
284 * Format the addresses
286 atm_addr = format_atm_addr(&ai->aap_addr);
287 sin = (struct sockaddr_in *)&ai->aap_arp_addr;
288 ip_addr = format_ip_addr(&sin->sin_addr);
293 UM_ZERO(flags, sizeof(flags));
294 if (ai->aap_flags & ARPF_VALID) {
297 if (ai->aap_flags & ARPF_REFRESH) {
304 for (i=0; arp_origins[i].s_name != NULL &&
305 ai->aap_origin != arp_origins[i].s_id;
307 if (arp_origins[i].s_name) {
308 origin = arp_origins[i].s_name;
316 UM_ZERO(age, sizeof(age));
317 if (!(ai->aap_flags & ARPF_VALID)) {
320 sprintf(age, "%d", ai->aap_age);
324 * Print the ARP information
326 printf("%-8s %-5s %3s %s\n ATM address = %s\n IP address = %s\n",
337 * Print ARP server information
340 * si pointer to a struct air_asrv_rsp
348 struct air_asrv_rsp *si;
351 char *atm_addr, *state;
352 struct in_addr *addr;
355 * Print a header if it hasn't been done yet.
363 * Format the ATM address of the ARP server
365 atm_addr = format_atm_addr(&si->asp_addr);
368 * Format the server state
370 for (i=0; arpserver_states[i].s_name != NULL &&
371 si->asp_state != arpserver_states[i].s_id;
373 if (arpserver_states[i].s_name) {
374 state = arpserver_states[i].s_name;
380 * Print the ARP server information
382 printf("%-8s %-8s %s\n",
388 * Format and print the LIS prefixes
390 if (si->asp_nprefix) {
391 addr = (struct in_addr *)((u_long)si +
392 sizeof(struct air_asrv_rsp));
394 for (i = 0; i < si->asp_nprefix; i++) {
395 printf("%s", inet_ntoa(*addr));
397 printf("/0x%0lx", ntohl(addr->s_addr));
399 if (i < si->asp_nprefix -1)
408 * Print adapter configuration information
411 * si pointer to a struct air_cfg_rsp
419 struct air_cfg_rsp *si;
421 char *adapter, *bus, *media, *vendor;
424 * Print a header if it hasn't been done yet.
432 * Format the vendor name and adapter type
434 vendor = get_vendor(si->acp_vendor);
435 adapter = get_adapter(si->acp_device);
438 * Format the communications medium
440 media = get_media_type(si->acp_media);
441 bus = get_bus_type(si->acp_bustype);
444 * Print the ARP server information
446 printf("%-8s %-8s %-8s %-14s %-4s %ld\n",
453 printf(" MAC address = %s\n",
454 format_mac_addr(&si->acp_macaddr));
455 printf(" Hardware version = %s\n", si->acp_hard_vers);
456 printf(" Firmware version = %s\n", si->acp_firm_vers);
461 * Print interface information
464 * ni pointer to a struct air_int_rsp
472 struct air_int_rsp *ni;
475 char nif_names[(IFNAMSIZ *2)+4];
477 char *sigmgr = "-", *state_name = "-";
486 * Translate signalling manager name
488 for (i=0; proto_states[i].p_state != NULL; i++)
489 if (ni->anp_sig_proto == proto_states[i].p_id)
491 if (proto_states[i].p_state != NULL)
492 sigmgr = proto_states[i].p_name;
495 * Get the signalling manager state
497 if (proto_states[i].p_state != NULL) {
498 s_t = proto_states[i].p_state;
499 for (i=0; s_t[i].s_name != NULL; i++)
500 if (ni->anp_sig_state == s_t[i].s_id)
502 if (s_t[i].s_name != NULL)
503 state_name = s_t[i].s_name;
507 * Format the ATM address
509 atm_addr = format_atm_addr(&ni->anp_addr);
512 * Get the range of NIFs on the physical interface
514 UM_ZERO(nif_names, sizeof(nif_names));
515 if (strlen(ni->anp_nif_pref) == 0) {
516 strcpy(nif_names, "-");
518 strcpy(nif_names, ni->anp_nif_pref);
519 strcat(nif_names, "0");
520 if (ni->anp_nif_cnt > 1) {
521 strcat(nif_names, " - ");
522 strcat(nif_names, ni->anp_nif_pref);
523 sprintf(&nif_names[strlen(nif_names)], "%d",
530 * Print the interface information
532 printf("%-9s %-7s %s\n",
536 printf(" ATM address = %s\n", atm_addr);
537 printf(" Network interfaces: %s\n", nif_names);
542 * Print IP address map information
545 * ai pointer to a struct air_arp_rsp
552 print_ip_vcc_info(ai)
553 struct air_ip_vcc_rsp *ai;
556 char *ip_addr, *state;
557 char flags[32], vpi_vci[16];
558 struct sockaddr_in *sin;
561 * Print a header if it hasn't been done yet.
569 * Format the IP address
571 sin = (struct sockaddr_in *)&ai->aip_dst_addr;
572 ip_addr = format_ip_addr(&sin->sin_addr);
577 if (ai->aip_vpi == 0 && ai->aip_vci == 0) {
578 strcpy(vpi_vci, " - -");
580 sprintf(vpi_vci, "%3d %5d", ai->aip_vpi, ai->aip_vci);
586 UM_ZERO(flags, sizeof(flags));
587 if (ai->aip_flags & IVF_PVC) {
590 if (ai->aip_flags & IVF_SVC) {
593 if (ai->aip_flags & IVF_LLC) {
596 if (ai->aip_flags & IVF_MAPOK) {
599 if (ai->aip_flags & IVF_NOIDLE) {
604 * Get the state of the VCC
606 for (i=0; ip_vcc_states[i].s_name != NULL &&
607 ai->aip_state != ip_vcc_states[i].s_id;
609 if (ip_vcc_states[i].s_name) {
610 state = ip_vcc_states[i].s_name;
616 * Print the IP VCC information
618 printf("%-8s %9s %-7s %-5s %s\n",
628 * Print network interface information
631 * ni pointer to a struct air_int_rsp
639 struct air_netif_rsp *ni;
642 struct sockaddr_in *sin;
653 * Format the protocol address
655 sin = (struct sockaddr_in *)&ni->anp_proto_addr;
656 ip_addr = format_ip_addr(&sin->sin_addr);
659 * Print the network interface information
661 printf("%-8s %-8s %s\n",
669 * Print physical interface statistics
672 * pi pointer to a struct air_phy_stat_rsp
680 struct air_phy_stat_rsp *pi;
683 * Print a header if it hasn't already been done
685 if (!phy_stats_hdr) {
686 printf(PHY_STATS_HDR);
691 * Print the interface statistics
693 printf("%-9s %7ld %8ld %5ld %7ld %8ld %5ld %5ld\n",
706 * Print VCC statistics
709 * vi pointer to VCC statistics to print
717 struct air_vcc_rsp *vi;
721 * Print a header if it hasn't already been done
723 if (!vcc_stats_hdr) {
724 printf(VCC_STATS_HDR);
729 * Print the VCC statistics
731 printf("%-9s %3d %4d",
735 if ( vi->avp_type & VCC_IN )
736 printf ( " %7ld %8ld %5ld",
743 if ( vi->avp_type & VCC_OUT )
744 printf ( " %7ld %8ld %5ld\n",
749 printf ( " - - -\n" );
754 * Print VCC information
757 * vi pointer to a struct air_vcc_rsp
765 struct air_vcc_rsp *vi;
768 char *aal_name = "-" , *encaps_name = "-", *owner_name = "-";
769 char *state_name = "-", *type_name = "-";
774 * Print a header if it hasn't already been done
784 for (i=0; aals[i].a_name != NULL; i++)
785 if (vi->avp_aal == aals[i].a_id)
788 aal_name = aals[i].a_name;
793 if (vi->avp_type & VCC_PVC)
795 else if (vi->avp_type & VCC_SVC)
798 * Translate VCC direction
800 UM_ZERO(dir_name, sizeof(dir_name));
801 if (vi->avp_type & VCC_IN)
802 strcat(dir_name, "In");
803 if (vi->avp_type & VCC_OUT)
804 strcat(dir_name, "Out");
805 if (strlen(dir_name) == 0)
806 strcpy(dir_name, "-");
811 for (i=0; proto_states[i].p_state != NULL; i++)
812 if (vi->avp_sig_proto == proto_states[i].p_id)
814 if (proto_states[i].p_state) {
815 s_t = proto_states[i].v_state;
816 for (i=0; s_t[i].s_name != NULL; i++)
817 if (vi->avp_state == s_t[i].s_id)
820 state_name = s_t[i].s_name;
824 * Translate encapsulation
826 for (i=0; encaps[i].e_name != NULL; i++)
827 if (vi->avp_encaps == encaps[i].e_id)
829 if (encaps[i].e_name)
830 encaps_name = encaps[i].e_name;
833 * Print the VCC information
835 printf("%-9s %3d %5d %-4s %-4s %-5s %-8s %-8s ",
846 * Print VCC owners' names
848 for (i = 0, owner_name = vi->avp_owners;
849 i < O_CNT - 1 && strlen(owner_name);
850 i++, owner_name += (T_ATM_APP_NAME_LEN + 1)) {
853 printf("%s", owner_name);
860 * Print destination address if it's an SVC
862 if (vi->avp_type & VCC_SVC) {
863 printf(" Dest = %s\n",
864 format_atm_addr(&vi->avp_daddr));
870 * Print network interface information
873 * ni pointer to a struct air_int_rsp
880 print_version_info(vi)
881 struct air_version_rsp *vi;
883 char version_str[80];
894 * Print the interface information
896 sprintf(version_str, "%d.%d",
897 ATM_VERS_MAJ(vi->avp_version),
898 ATM_VERS_MIN(vi->avp_version));
899 printf("%7s\n", version_str);