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 $
27 * @(#) $DragonFly: src/sbin/atm/atm/atm_print.c,v 1.2 2003/06/17 04:27:32 dillon 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 "Net Intf Flags Age Origin\n"
69 "Net Intf State ATM Address\n"
72 "Intf Vendor Model Media Bus Serial No\n"
75 "Net Intf VPI VCI State Flags IP Address\n"
78 "Interface Sigmgr State\n"
81 "Net Intf Phy Intf IP Address\n"
84 "Interface VPI VCI AAL Type Dir State Encaps Owner\n"
86 #define VCC_STATS_HDR \
87 " Input Input Input Output Output Output\n\
88 Interface VPI VCI PDUs Bytes Errs PDUs Bytes Errs\n"
93 #define PHY_STATS_HDR \
94 " Input Input Input Output Output Output Cmd\n\
95 Interface PDUs Bytes Errs PDUs Bytes Errs Errs\n"
100 extern struct proto protos[];
101 extern struct aal aals[];
102 extern struct encaps encaps[];
107 static int arp_hdr = 0;
108 static int asrv_hdr = 0;
109 static int cfg_hdr = 0;
110 static int ip_vcc_hdr = 0;
111 static int netif_hdr = 0;
112 static int vcc_hdr = 0;
113 static int vcc_stats_hdr = 0;
114 static int phy_stats_hdr = 0;
115 static int version_hdr = 0;
118 * SIGPVC state definitions
120 struct state sigpvc_states[] = {
121 { "ACTIVE", SIGPVC_ACTIVE },
122 { "DETACH", SIGPVC_DETACH },
127 * SPANS state definitions
129 struct state spans_states[] = {
130 { "ACTIVE", SPANS_ACTIVE },
131 { "DETACH", SPANS_DETACH },
132 { "INIT", SPANS_INIT },
133 { "PROBE", SPANS_PROBE },
138 * UNISIG state definitions
140 struct state unisig_states[] = {
141 { "NULL", UNISIG_NULL },
142 { "ADR_WAIT", UNISIG_ADDR_WAIT },
143 { "INIT", UNISIG_INIT },
144 { "ACTIVE", UNISIG_ACTIVE },
145 { "DETACH", UNISIG_DETACH },
150 * SIGPVC VCC state definitions
152 struct state sigpvc_vcc_states[] = {
153 { "NULL", VCCS_NULL },
154 { "ACTIVE", VCCS_ACTIVE },
155 { "FREE", VCCS_FREE },
160 * SPANS VCC state definitions
162 struct state spans_vcc_states[] = {
163 { "NULL", SPANS_VC_NULL },
164 { "ACTIVE", SPANS_VC_ACTIVE },
165 { "ACT_DOWN", SPANS_VC_ACT_DOWN },
166 { "POPEN", SPANS_VC_POPEN },
167 { "R_POPEN", SPANS_VC_R_POPEN },
168 { "OPEN", SPANS_VC_OPEN },
169 { "CLOSE", SPANS_VC_CLOSE },
170 { "ABORT", SPANS_VC_ABORT },
171 { "FREE", SPANS_VC_FREE },
176 * UNISIG VCC state definitions
178 struct state unisig_vcc_states[] = {
179 { "NULL", UNI_NULL },
180 { "C_INIT", UNI_CALL_INITIATED },
181 { "C_OUT_PR", UNI_CALL_OUT_PROC },
182 { "C_DELIV", UNI_CALL_DELIVERED },
183 { "C_PRES", UNI_CALL_PRESENT },
184 { "C_REC", UNI_CALL_RECEIVED },
185 { "CONN_REQ", UNI_CONNECT_REQUEST },
186 { "C_IN_PR", UNI_CALL_IN_PROC },
187 { "ACTIVE", UNI_ACTIVE },
188 { "REL_REQ", UNI_RELEASE_REQUEST },
189 { "REL_IND", UNI_RELEASE_IND },
190 { "SSCF_REC", UNI_SSCF_RECOV },
191 { "FREE", UNI_FREE },
192 { "ACTIVE", UNI_PVC_ACTIVE },
193 { "ACT_DOWN", UNI_PVC_ACT_DOWN },
198 * IP VCC state definitions
200 struct state ip_vcc_states[] = {
201 { "FREE", IPVCC_FREE },
202 { "PMAP", IPVCC_PMAP },
203 { "POPEN", IPVCC_POPEN },
204 { "PACCEPT", IPVCC_PACCEPT },
205 { "ACTPENT", IPVCC_ACTPENT },
206 { "ACTIVE", IPVCC_ACTIVE },
207 { "CLOSED", IPVCC_CLOSED },
212 * ARP server state definitions
214 struct state arpserver_states[] = {
215 { "NOT_CONF", UIAS_NOTCONF },
216 { "SERVER", UIAS_SERVER_ACTIVE },
217 { "PEND_ADR", UIAS_CLIENT_PADDR },
218 { "POPEN", UIAS_CLIENT_POPEN },
219 { "REGISTER", UIAS_CLIENT_REGISTER },
220 { "ACTIVE", UIAS_CLIENT_ACTIVE },
225 * Supported signalling managers
227 struct proto_state proto_states[] = {
228 { "SIGPVC", sigpvc_states, sigpvc_vcc_states, ATM_SIG_PVC },
229 { "SPANS", spans_states, spans_vcc_states, ATM_SIG_SPANS },
230 { "UNI 3.0", unisig_states, unisig_vcc_states, ATM_SIG_UNI30 },
231 { "UNI 3.1", unisig_states, unisig_vcc_states, ATM_SIG_UNI31 },
232 { "UNI 4.0", unisig_states, unisig_vcc_states, ATM_SIG_UNI40 },
237 * ATMARP origin values
239 struct state arp_origins[] = {
240 { "LOCAL", UAO_LOCAL },
241 { "PERM", UAO_PERM },
242 { "REG", UAO_REGISTER },
243 { "SCSP", UAO_SCSP },
244 { "LOOKUP", UAO_LOOKUP },
245 { "PEER_RSP", UAO_PEER_RSP },
246 { "PEER_REQ", UAO_PEER_REQ },
252 * Print ARP table information
255 * ai pointer to a struct air_arp_rsp
263 struct air_arp_rsp *ai;
266 char *atm_addr, *ip_addr, *origin;
267 char age[8], flags[32];
268 struct sockaddr_in *sin;
271 * Print a header if it hasn't been done yet.
279 * Format the addresses
281 atm_addr = format_atm_addr(&ai->aap_addr);
282 sin = (struct sockaddr_in *)&ai->aap_arp_addr;
283 ip_addr = format_ip_addr(&sin->sin_addr);
288 UM_ZERO(flags, sizeof(flags));
289 if (ai->aap_flags & ARPF_VALID) {
292 if (ai->aap_flags & ARPF_REFRESH) {
299 for (i=0; arp_origins[i].s_name != NULL &&
300 ai->aap_origin != arp_origins[i].s_id;
302 if (arp_origins[i].s_name) {
303 origin = arp_origins[i].s_name;
311 UM_ZERO(age, sizeof(age));
312 if (!(ai->aap_flags & ARPF_VALID)) {
315 sprintf(age, "%d", ai->aap_age);
319 * Print the ARP information
321 printf("%-8s %-5s %3s %s\n ATM address = %s\n IP address = %s\n",
332 * Print ARP server information
335 * si pointer to a struct air_asrv_rsp
343 struct air_asrv_rsp *si;
346 char *atm_addr, *state;
347 struct in_addr *addr;
350 * Print a header if it hasn't been done yet.
358 * Format the ATM address of the ARP server
360 atm_addr = format_atm_addr(&si->asp_addr);
363 * Format the server state
365 for (i=0; arpserver_states[i].s_name != NULL &&
366 si->asp_state != arpserver_states[i].s_id;
368 if (arpserver_states[i].s_name) {
369 state = arpserver_states[i].s_name;
375 * Print the ARP server information
377 printf("%-8s %-8s %s\n",
383 * Format and print the LIS prefixes
385 if (si->asp_nprefix) {
386 addr = (struct in_addr *)((u_long)si +
387 sizeof(struct air_asrv_rsp));
389 for (i = 0; i < si->asp_nprefix; i++) {
390 printf("%s", inet_ntoa(*addr));
392 printf("/0x%0lx", ntohl(addr->s_addr));
394 if (i < si->asp_nprefix -1)
403 * Print adapter configuration information
406 * si pointer to a struct air_cfg_rsp
414 struct air_cfg_rsp *si;
416 char *adapter, *bus, *media, *vendor;
419 * Print a header if it hasn't been done yet.
427 * Format the vendor name and adapter type
429 vendor = get_vendor(si->acp_vendor);
430 adapter = get_adapter(si->acp_device);
433 * Format the communications medium
435 media = get_media_type(si->acp_media);
436 bus = get_bus_type(si->acp_bustype);
439 * Print the ARP server information
441 printf("%-8s %-8s %-8s %-14s %-4s %ld\n",
448 printf(" MAC address = %s\n",
449 format_mac_addr(&si->acp_macaddr));
450 printf(" Hardware version = %s\n", si->acp_hard_vers);
451 printf(" Firmware version = %s\n", si->acp_firm_vers);
456 * Print interface information
459 * ni pointer to a struct air_int_rsp
467 struct air_int_rsp *ni;
470 char nif_names[(IFNAMSIZ *2)+4];
472 char *sigmgr = "-", *state_name = "-";
481 * Translate signalling manager name
483 for (i=0; proto_states[i].p_state != NULL; i++)
484 if (ni->anp_sig_proto == proto_states[i].p_id)
486 if (proto_states[i].p_state != NULL)
487 sigmgr = proto_states[i].p_name;
490 * Get the signalling manager state
492 if (proto_states[i].p_state != NULL) {
493 s_t = proto_states[i].p_state;
494 for (i=0; s_t[i].s_name != NULL; i++)
495 if (ni->anp_sig_state == s_t[i].s_id)
497 if (s_t[i].s_name != NULL)
498 state_name = s_t[i].s_name;
502 * Format the ATM address
504 atm_addr = format_atm_addr(&ni->anp_addr);
507 * Get the range of NIFs on the physical interface
509 UM_ZERO(nif_names, sizeof(nif_names));
510 if (strlen(ni->anp_nif_pref) == 0) {
511 strcpy(nif_names, "-");
513 strcpy(nif_names, ni->anp_nif_pref);
514 strcat(nif_names, "0");
515 if (ni->anp_nif_cnt > 1) {
516 strcat(nif_names, " - ");
517 strcat(nif_names, ni->anp_nif_pref);
518 sprintf(&nif_names[strlen(nif_names)], "%d",
525 * Print the interface information
527 printf("%-9s %-7s %s\n",
531 printf(" ATM address = %s\n", atm_addr);
532 printf(" Network interfaces: %s\n", nif_names);
537 * Print IP address map information
540 * ai pointer to a struct air_arp_rsp
547 print_ip_vcc_info(ai)
548 struct air_ip_vcc_rsp *ai;
551 char *ip_addr, *state;
552 char flags[32], vpi_vci[16];
553 struct sockaddr_in *sin;
556 * Print a header if it hasn't been done yet.
564 * Format the IP address
566 sin = (struct sockaddr_in *)&ai->aip_dst_addr;
567 ip_addr = format_ip_addr(&sin->sin_addr);
572 if (ai->aip_vpi == 0 && ai->aip_vci == 0) {
573 strcpy(vpi_vci, " - -");
575 sprintf(vpi_vci, "%3d %5d", ai->aip_vpi, ai->aip_vci);
581 UM_ZERO(flags, sizeof(flags));
582 if (ai->aip_flags & IVF_PVC) {
585 if (ai->aip_flags & IVF_SVC) {
588 if (ai->aip_flags & IVF_LLC) {
591 if (ai->aip_flags & IVF_MAPOK) {
594 if (ai->aip_flags & IVF_NOIDLE) {
599 * Get the state of the VCC
601 for (i=0; ip_vcc_states[i].s_name != NULL &&
602 ai->aip_state != ip_vcc_states[i].s_id;
604 if (ip_vcc_states[i].s_name) {
605 state = ip_vcc_states[i].s_name;
611 * Print the IP VCC information
613 printf("%-8s %9s %-7s %-5s %s\n",
623 * Print network interface information
626 * ni pointer to a struct air_int_rsp
634 struct air_netif_rsp *ni;
637 struct sockaddr_in *sin;
648 * Format the protocol address
650 sin = (struct sockaddr_in *)&ni->anp_proto_addr;
651 ip_addr = format_ip_addr(&sin->sin_addr);
654 * Print the network interface information
656 printf("%-8s %-8s %s\n",
664 * Print physical interface statistics
667 * pi pointer to a struct air_phy_stat_rsp
675 struct air_phy_stat_rsp *pi;
678 * Print a header if it hasn't already been done
680 if (!phy_stats_hdr) {
681 printf(PHY_STATS_HDR);
686 * Print the interface statistics
688 printf("%-9s %7ld %8ld %5ld %7ld %8ld %5ld %5ld\n",
701 * Print VCC statistics
704 * vi pointer to VCC statistics to print
712 struct air_vcc_rsp *vi;
716 * Print a header if it hasn't already been done
718 if (!vcc_stats_hdr) {
719 printf(VCC_STATS_HDR);
724 * Print the VCC statistics
726 printf("%-9s %3d %4d",
730 if ( vi->avp_type & VCC_IN )
731 printf ( " %7ld %8ld %5ld",
738 if ( vi->avp_type & VCC_OUT )
739 printf ( " %7ld %8ld %5ld\n",
744 printf ( " - - -\n" );
749 * Print VCC information
752 * vi pointer to a struct air_vcc_rsp
760 struct air_vcc_rsp *vi;
763 char *aal_name = "-" , *encaps_name = "-", *owner_name = "-";
764 char *state_name = "-", *type_name = "-";
769 * Print a header if it hasn't already been done
779 for (i=0; aals[i].a_name != NULL; i++)
780 if (vi->avp_aal == aals[i].a_id)
783 aal_name = aals[i].a_name;
788 if (vi->avp_type & VCC_PVC)
790 else if (vi->avp_type & VCC_SVC)
793 * Translate VCC direction
795 UM_ZERO(dir_name, sizeof(dir_name));
796 if (vi->avp_type & VCC_IN)
797 strcat(dir_name, "In");
798 if (vi->avp_type & VCC_OUT)
799 strcat(dir_name, "Out");
800 if (strlen(dir_name) == 0)
801 strcpy(dir_name, "-");
806 for (i=0; proto_states[i].p_state != NULL; i++)
807 if (vi->avp_sig_proto == proto_states[i].p_id)
809 if (proto_states[i].p_state) {
810 s_t = proto_states[i].v_state;
811 for (i=0; s_t[i].s_name != NULL; i++)
812 if (vi->avp_state == s_t[i].s_id)
815 state_name = s_t[i].s_name;
819 * Translate encapsulation
821 for (i=0; encaps[i].e_name != NULL; i++)
822 if (vi->avp_encaps == encaps[i].e_id)
824 if (encaps[i].e_name)
825 encaps_name = encaps[i].e_name;
828 * Print the VCC information
830 printf("%-9s %3d %5d %-4s %-4s %-5s %-8s %-8s ",
841 * Print VCC owners' names
843 for (i = 0, owner_name = vi->avp_owners;
844 i < O_CNT - 1 && strlen(owner_name);
845 i++, owner_name += (T_ATM_APP_NAME_LEN + 1)) {
848 printf("%s", owner_name);
855 * Print destination address if it's an SVC
857 if (vi->avp_type & VCC_SVC) {
858 printf(" Dest = %s\n",
859 format_atm_addr(&vi->avp_daddr));
865 * Print network interface information
868 * ni pointer to a struct air_int_rsp
875 print_version_info(vi)
876 struct air_version_rsp *vi;
878 char version_str[80];
889 * Print the interface information
891 sprintf(version_str, "%d.%d",
892 ATM_VERS_MAJ(vi->avp_version),
893 ATM_VERS_MIN(vi->avp_version));
894 printf("%7s\n", version_str);