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.5 2006/10/16 00:15:35 pavalos 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 static const struct state sigpvc_states[] = {
121 { "ACTIVE", SIGPVC_ACTIVE },
122 { "DETACH", SIGPVC_DETACH },
127 * SPANS state definitions
129 static const 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 static const 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 static const struct state sigpvc_vcc_states[] = {
153 { "NULL", VCCS_NULL },
154 { "ACTIVE", VCCS_ACTIVE },
155 { "FREE", VCCS_FREE },
160 * SPANS VCC state definitions
162 static const 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 static const 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 static const 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 static const 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 static const 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 static const 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
262 print_arp_info(struct air_arp_rsp *ai)
265 const char *atm_addr, *ip_addr, *origin;
266 char age[8], flags[32];
267 struct sockaddr_in *sin;
270 * Print a header if it hasn't been done yet.
278 * Format the addresses
280 atm_addr = format_atm_addr(&ai->aap_addr);
281 sin = (struct sockaddr_in *)&ai->aap_arp_addr;
282 ip_addr = format_ip_addr(&sin->sin_addr);
287 UM_ZERO(flags, sizeof(flags));
288 if (ai->aap_flags & ARPF_VALID) {
291 if (ai->aap_flags & ARPF_REFRESH) {
298 for (i=0; arp_origins[i].s_name != NULL &&
299 ai->aap_origin != arp_origins[i].s_id;
301 if (arp_origins[i].s_name) {
302 origin = arp_origins[i].s_name;
310 UM_ZERO(age, sizeof(age));
311 if (!(ai->aap_flags & ARPF_VALID)) {
314 sprintf(age, "%d", ai->aap_age);
318 * Print the ARP information
320 printf("%-8s %-5s %3s %s\n ATM address = %s\n IP address = %s\n",
331 * Print ARP server information
334 * si pointer to a struct air_asrv_rsp
341 print_asrv_info(struct air_asrv_rsp *si)
344 const char *atm_addr, *state;
345 struct in_addr *addr;
348 * Print a header if it hasn't been done yet.
356 * Format the ATM address of the ARP server
358 atm_addr = format_atm_addr(&si->asp_addr);
361 * Format the server state
363 for (i=0; arpserver_states[i].s_name != NULL &&
364 si->asp_state != arpserver_states[i].s_id;
366 if (arpserver_states[i].s_name) {
367 state = arpserver_states[i].s_name;
373 * Print the ARP server information
375 printf("%-8s %-8s %s\n",
381 * Format and print the LIS prefixes
383 if (si->asp_nprefix) {
384 addr = (struct in_addr *)((u_long)si +
385 sizeof(struct air_asrv_rsp));
387 for (i = 0; i < si->asp_nprefix; i++) {
388 printf("%s", inet_ntoa(*addr));
390 printf("/0x%0lx", (unsigned long)ntohl(addr->s_addr));
392 if (i < si->asp_nprefix -1)
401 * Print adapter configuration information
404 * si pointer to a struct air_cfg_rsp
411 print_cfg_info(struct air_cfg_rsp *si)
413 const char *adapter, *bus, *media, *vendor;
416 * Print a header if it hasn't been done yet.
424 * Format the vendor name and adapter type
426 vendor = get_vendor(si->acp_vendor);
427 adapter = get_adapter(si->acp_device);
430 * Format the communications medium
432 media = get_media_type(si->acp_media);
433 bus = get_bus_type(si->acp_bustype);
436 * Print the ARP server information
438 printf("%-8s %-8s %-8s %-14s %-4s %ld\n",
445 printf(" MAC address = %s\n",
446 format_mac_addr(&si->acp_macaddr));
447 printf(" Hardware version = %s\n", si->acp_hard_vers);
448 printf(" Firmware version = %s\n", si->acp_firm_vers);
453 * Print interface information
456 * ni pointer to a struct air_int_rsp
463 print_intf_info(struct air_int_rsp *ni)
466 char nif_names[(IFNAMSIZ *2)+4];
468 const char *sigmgr = "-", *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 UM_ZERO(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(struct air_ip_vcc_rsp *ai)
546 const char *ip_addr, *state;
547 char flags[32], vpi_vci[16];
548 struct sockaddr_in *sin;
551 * Print a header if it hasn't been done yet.
559 * Format the IP address
561 sin = (struct sockaddr_in *)&ai->aip_dst_addr;
562 ip_addr = format_ip_addr(&sin->sin_addr);
567 if (ai->aip_vpi == 0 && ai->aip_vci == 0) {
568 strcpy(vpi_vci, " - -");
570 sprintf(vpi_vci, "%3d %5d", ai->aip_vpi, ai->aip_vci);
576 UM_ZERO(flags, sizeof(flags));
577 if (ai->aip_flags & IVF_PVC) {
580 if (ai->aip_flags & IVF_SVC) {
583 if (ai->aip_flags & IVF_LLC) {
586 if (ai->aip_flags & IVF_MAPOK) {
589 if (ai->aip_flags & IVF_NOIDLE) {
594 * Get the state of the VCC
596 for (i=0; ip_vcc_states[i].s_name != NULL &&
597 ai->aip_state != ip_vcc_states[i].s_id;
599 if (ip_vcc_states[i].s_name) {
600 state = ip_vcc_states[i].s_name;
606 * Print the IP VCC information
608 printf("%-8s %9s %-7s %-5s %s\n",
618 * Print network interface information
621 * ni pointer to a struct air_int_rsp
628 print_netif_info(struct air_netif_rsp *ni)
631 struct sockaddr_in *sin;
642 * Format the protocol address
644 sin = (struct sockaddr_in *)&ni->anp_proto_addr;
645 ip_addr = format_ip_addr(&sin->sin_addr);
648 * Print the network interface information
650 printf("%-8s %-8s %s\n",
658 * Print physical interface statistics
661 * pi pointer to a struct air_phy_stat_rsp
668 print_intf_stats(struct air_phy_stat_rsp *pi)
671 * Print a header if it hasn't already been done
673 if (!phy_stats_hdr) {
674 printf(PHY_STATS_HDR);
679 * Print the interface statistics
681 printf("%-9s %7ld %8ld %5ld %7ld %8ld %5ld %5ld\n",
694 * Print VCC statistics
697 * vi pointer to VCC statistics to print
704 print_vcc_stats(struct air_vcc_rsp *vi)
708 * Print a header if it hasn't already been done
710 if (!vcc_stats_hdr) {
711 printf(VCC_STATS_HDR);
716 * Print the VCC statistics
718 printf("%-9s %3d %4d",
722 if ( vi->avp_type & VCC_IN )
723 printf ( " %7ld %8ld %5ld",
730 if ( vi->avp_type & VCC_OUT )
731 printf ( " %7ld %8ld %5ld\n",
736 printf ( " - - -\n" );
741 * Print VCC information
744 * vi pointer to a struct air_vcc_rsp
751 print_vcc_info(struct air_vcc_rsp *vi)
754 const char *aal_name = "-" , *encaps_name = "-", *owner_name = "-";
755 const char *state_name = "-", *type_name = "-";
757 const struct state *s_t;
760 * Print a header if it hasn't already been done
770 for (i=0; aals[i].a_name != NULL; i++)
771 if (vi->avp_aal == aals[i].a_id)
774 aal_name = aals[i].a_name;
779 if (vi->avp_type & VCC_PVC)
781 else if (vi->avp_type & VCC_SVC)
784 * Translate VCC direction
786 UM_ZERO(dir_name, sizeof(dir_name));
787 if (vi->avp_type & VCC_IN)
788 strcat(dir_name, "In");
789 if (vi->avp_type & VCC_OUT)
790 strcat(dir_name, "Out");
791 if (strlen(dir_name) == 0)
792 strcpy(dir_name, "-");
797 for (i=0; proto_states[i].p_state != NULL; i++)
798 if (vi->avp_sig_proto == proto_states[i].p_id)
800 if (proto_states[i].p_state) {
801 s_t = proto_states[i].v_state;
802 for (i=0; s_t[i].s_name != NULL; i++)
803 if (vi->avp_state == s_t[i].s_id)
806 state_name = s_t[i].s_name;
810 * Translate encapsulation
812 for (i=0; encaps[i].e_name != NULL; i++)
813 if (vi->avp_encaps == encaps[i].e_id)
815 if (encaps[i].e_name)
816 encaps_name = encaps[i].e_name;
819 * Print the VCC information
821 printf("%-9s %3d %5d %-4s %-4s %-5s %-8s %-8s ",
832 * Print VCC owners' names
834 for (i = 0, owner_name = vi->avp_owners;
835 i < O_CNT - 1 && strlen(owner_name);
836 i++, owner_name += (T_ATM_APP_NAME_LEN + 1)) {
839 printf("%s", owner_name);
846 * Print destination address if it's an SVC
848 if (vi->avp_type & VCC_SVC) {
849 printf(" Dest = %s\n",
850 format_atm_addr(&vi->avp_daddr));
856 * Print network interface information
859 * ni pointer to a struct air_int_rsp
866 print_version_info(struct air_version_rsp *vi)
868 char version_str[80];
879 * Print the interface information
881 sprintf(version_str, "%d.%d",
882 ATM_VERS_MAJ(vi->avp_version),
883 ATM_VERS_MIN(vi->avp_version));
884 printf("%7s\n", version_str);