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 * Routines for "show" subcommand
35 #include <sys/param.h>
36 #include <sys/socket.h>
38 #include <netinet/in.h>
39 #include <netatm/port.h>
40 #include <netatm/atm.h>
41 #include <netatm/atm_if.h>
42 #include <netatm/atm_sap.h>
43 #include <netatm/atm_sys.h>
44 #include <netatm/atm_vc.h>
45 #include <netatm/atm_ioctl.h>
56 __RCSID("@(#) $FreeBSD$");
63 static int vcc_compare(const void *, const void *);
64 static int ip_vcc_compare(const void *, const void *);
65 static int arp_compare(const void *, const void *);
69 * Process show ARP command
72 * atm show ARP [<ip-addr>]
75 * argc number of remaining arguments to command
76 * argv pointer to remaining argument strings
77 * cmdp pointer to command description
84 show_arp(int argc, char **argv, const struct cmd *cmdp __unused)
88 struct air_arp_rsp *arp_info, *arp_info_base;
89 struct sockaddr_in *sain;
91 struct sockaddr_in sain;
96 * Get IP address of specified host name
98 bzero(&host_addr, sizeof(host_addr));
99 host_addr.sa.sa_family = AF_INET;
101 sain = get_ip_addr(argv[0]);
103 fprintf(stderr, "%s: host \'%s\' not found\n",
107 host_addr.sain.sin_addr.s_addr = sain->sin_addr.s_addr;
109 host_addr.sain.sin_addr.s_addr = INADDR_ANY;
113 * Get ARP information from the kernel
115 bzero(&air, sizeof(air));
116 air.air_opcode = AIOCS_INF_ARP;
117 air.air_arp_addr = host_addr.sa;
118 arp_info_len = do_info_ioctl(&air, sizeof(struct air_arp_rsp) * 10);
119 if ((ssize_t)arp_info_len == -1) {
120 fprintf(stderr, "%s: ", prog);
124 perror("Internal error");
127 fprintf(stderr, "not an ATM device\n");
130 perror("ioctl (AIOCINFO)");
135 arp_info_base = arp_info =
136 (struct air_arp_rsp *) air.air_buf_addr;
141 qsort((void *) arp_info,
142 arp_info_len / sizeof(struct air_arp_rsp),
143 sizeof(struct air_arp_rsp),
147 * Print the relevant information
149 while (arp_info_len >= sizeof(struct air_arp_rsp)) {
150 print_arp_info(arp_info);
152 arp_info_len -= sizeof(struct air_arp_rsp);
156 * Release the information from the kernel
163 * Process show ATM ARP server command
166 * atm show arpserver [<interface-name>]
169 * argc number of remaining arguments to command
170 * argv pointer to remaining argument strings
171 * cmdp pointer to command description
178 show_arpserv(int argc, char **argv, const struct cmd *cmdp __unused)
180 size_t buf_len, asrv_info_len;
181 struct atminfreq air;
182 struct air_asrv_rsp *asrv_info, *asrv_info_base;
185 * Validate interface name
187 bzero(air.air_int_intf, sizeof(air.air_int_intf));
189 if (strlen(argv[0]) > IFNAMSIZ - 1) {
190 fprintf(stderr, "%s: Illegal interface name\n",
194 strcpy(air.air_int_intf, argv[0]);
199 * Get interface information from the kernel
201 air.air_opcode = AIOCS_INF_ASV;
202 buf_len = do_info_ioctl(&air, sizeof(struct air_asrv_rsp) * 3);
203 if ((ssize_t)buf_len == -1) {
204 fprintf(stderr, "%s: ", prog);
208 perror("Internal error");
211 fprintf(stderr, "%s is not an ATM device\n",
215 perror("ioctl (AIOCINFO)");
222 * Print the interface information
224 asrv_info_base = asrv_info =
225 (struct air_asrv_rsp *)(void *)air.air_buf_addr;
226 while (buf_len >= sizeof(struct air_asrv_rsp)) {
227 print_asrv_info(asrv_info);
228 asrv_info_len = sizeof(struct air_asrv_rsp) +
229 asrv_info->asp_nprefix * sizeof(struct in_addr) * 2;
230 asrv_info = (struct air_asrv_rsp *)(void *)
231 ((char *)asrv_info + asrv_info_len);
232 buf_len -= asrv_info_len;
234 free(asrv_info_base);
239 * Process show ATM adapter configuration command
242 * atm show config [<interface-name>]
245 * argc number of remaining arguments to command
246 * argv pointer to remaining argument strings
247 * cmdp pointer to command description
254 show_config(int argc, char **argv, const struct cmd *cmdp __unused)
257 struct atminfreq air;
258 struct air_cfg_rsp *cfg_info, *cfg_info_base;
261 * Validate interface name
263 bzero(air.air_cfg_intf, sizeof(air.air_cfg_intf));
265 if (strlen(argv[0]) > IFNAMSIZ - 1) {
266 fprintf(stderr, "%s: Illegal interface name\n",
270 strcpy(air.air_cfg_intf, argv[0]);
275 * Get configuration information from the kernel
277 air.air_opcode = AIOCS_INF_CFG;
278 buf_len = do_info_ioctl(&air, sizeof(struct air_asrv_rsp) * 3);
279 if ((ssize_t)buf_len == -1) {
280 fprintf(stderr, "%s: ", prog);
284 perror("Internal error");
287 fprintf(stderr, "%s is not an ATM device\n",
291 perror("ioctl (AIOCINFO)");
298 * Print the interface information
300 cfg_info_base = cfg_info =
301 (struct air_cfg_rsp *)(void *)air.air_buf_addr;
302 for (; buf_len >= sizeof(struct air_cfg_rsp); cfg_info++,
303 buf_len -= sizeof(struct air_cfg_rsp)) {
304 print_cfg_info(cfg_info);
311 * Process show interface command
314 * atm show interface [<interface-name>]
317 * argc number of remaining arguments to command
318 * argv pointer to remaining argument strings
319 * cmdp pointer to command description
326 show_intf(int argc, char **argv, const struct cmd *cmdp __unused)
329 struct atminfreq air;
330 struct air_int_rsp *int_info, *int_info_base;
333 * Validate interface name
335 bzero(&air, sizeof(air));
337 if (strlen(argv[0]) > IFNAMSIZ - 1) {
338 fprintf(stderr, "%s: Illegal interface name\n",
342 strcpy(air.air_int_intf, argv[0]);
347 * Get interface information from the kernel
349 air.air_opcode = AIOCS_INF_INT;
350 buf_len = do_info_ioctl(&air, sizeof(struct air_int_rsp) * 3);
351 if ((ssize_t)buf_len == -1) {
352 fprintf(stderr, "%s: ", prog);
356 perror("Internal error");
359 fprintf(stderr, "%s is not an ATM device\n",
363 perror("ioctl (AIOCINFO)");
370 * Print the interface information
372 int_info_base = int_info =
373 (struct air_int_rsp *)(void *)air.air_buf_addr;
374 for (; buf_len >= sizeof(struct air_int_rsp); int_info++,
375 buf_len -= sizeof(struct air_int_rsp)) {
376 print_intf_info(int_info);
383 * Process show IP VCCs command
386 * atm show ipvcc [<ip-addr>]
389 * argc number of remaining arguments to command
390 * argv pointer to remaining argument strings
391 * cmdp pointer to command description
398 show_ip_vcc(int argc, char **argv, const struct cmd *cmdp __unused)
402 char *if_name = (char *)0;
403 struct atminfreq air;
404 struct air_ip_vcc_rsp *ip_info, *ip_info_base;
405 struct sockaddr_in *sain;
407 struct sockaddr_in sain;
412 * First parameter can be a netif name, an IP host name, or
413 * an IP address. Figure out which it is.
415 bzero(&host_addr, sizeof(host_addr));
416 host_addr.sa.sa_family = AF_INET;
418 rc = verify_nif_name(argv[0]);
423 fprintf(stderr, "%s: ", prog);
427 perror("Internal error");
430 fprintf(stderr, "%s is not an ATM device\n",
434 perror("ioctl (AIOCINFO)");
440 * Parameter is a valid netif name
445 * Get IP address of specified host name
447 sain = get_ip_addr(argv[0]);
448 host_addr.sain.sin_addr.s_addr =
449 sain->sin_addr.s_addr;
452 host_addr.sain.sin_addr.s_addr = INADDR_ANY;
456 * Get IP map information from the kernel
458 air.air_opcode = AIOCS_INF_IPM;
459 air.air_ip_addr = host_addr.sa;
460 ip_info_len = do_info_ioctl(&air, sizeof(struct air_ip_vcc_rsp) * 10);
461 if ((ssize_t)ip_info_len == -1) {
462 fprintf(stderr, "%s: ", prog);
466 perror("Internal error");
469 fprintf(stderr, "not an ATM device\n");
472 perror("ioctl (AIOCINFO)");
477 ip_info_base = ip_info =
478 (struct air_ip_vcc_rsp *)(void *)air.air_buf_addr;
481 * Sort the information
483 qsort((void *) ip_info,
484 ip_info_len / sizeof(struct air_ip_vcc_rsp),
485 sizeof(struct air_ip_vcc_rsp),
489 * Print the relevant information
491 while (ip_info_len >= sizeof(struct air_ip_vcc_rsp)) {
492 if (!if_name || !strcmp(if_name, ip_info->aip_intf)) {
493 print_ip_vcc_info(ip_info);
496 ip_info_len -= sizeof(struct air_ip_vcc_rsp);
500 * Release the information from the kernel
507 * Process show network interface command
510 * atm show netif [<netif>]
513 * argc number of remaining arguments to command
514 * argv pointer to remaining argument strings
515 * cmdp pointer to command description
522 show_netif(int argc, char **argv, const struct cmd *cmdp __unused)
525 struct atminfreq air;
526 struct air_netif_rsp *int_info, *int_info_base;
529 * Validate network interface name
531 bzero(air.air_int_intf, sizeof(air.air_int_intf));
533 if (strlen(argv[0]) > IFNAMSIZ - 1) {
534 fprintf(stderr, "%s: Illegal interface name\n", prog);
537 strcpy(air.air_int_intf, argv[0]);
542 * Get network interface information from the kernel
544 air.air_opcode = AIOCS_INF_NIF;
545 buf_len = do_info_ioctl(&air, sizeof(struct air_netif_rsp) * 3);
546 if ((ssize_t)buf_len == -1) {
547 fprintf(stderr, "%s: ", prog);
551 perror("Internal error");
554 fprintf(stderr, "%s is not an ATM device\n",
558 perror("ioctl (AIOCINFO)");
565 * Print the network interface information
567 int_info_base = int_info =
568 (struct air_netif_rsp *) air.air_buf_addr;
569 for (; buf_len >= sizeof(struct air_netif_rsp); int_info++,
570 buf_len -= sizeof(struct air_netif_rsp)) {
571 print_netif_info(int_info);
578 * Process interface statistics command
581 * atm show stats interface [<interface-name>]
584 * argc number of remaining arguments to command
585 * argv pointer to remaining argument strings
586 * cmdp pointer to command description
593 show_intf_stats(int argc, char **argv, const struct cmd *cmdp __unused)
597 struct atminfreq air;
598 struct air_phy_stat_rsp *pstat_info, *pstat_info_base;
599 struct air_cfg_rsp *cfg_info;
602 * Validate interface name
604 bzero(intf, sizeof(intf));
606 if (strlen(argv[0]) > IFNAMSIZ - 1) {
607 fprintf(stderr, "%s: Illegal interface name\n",
611 strcpy(intf, argv[0]);
616 * If there are parameters remaining, the request is for
617 * vendor-specific adaptor statistics
621 * Get adapter configuration information
623 air.air_opcode = AIOCS_INF_CFG;
624 strcpy(air.air_cfg_intf, intf);
625 buf_len = do_info_ioctl(&air, sizeof(struct air_cfg_rsp));
626 if ((ssize_t)buf_len == -1) {
627 fprintf(stderr, "%s: ", prog);
631 perror("Internal error");
634 fprintf(stderr, "%s is not an ATM device\n",
638 perror("ioctl (AIOCINFO)");
643 cfg_info = (struct air_cfg_rsp *)(void *)air.air_buf_addr;
646 * Call the appropriate vendor-specific routine
648 switch(cfg_info->acp_vendor) {
650 show_fore200_stats(intf, argc, argv);
653 fprintf(stderr, "%s: Unknown adapter vendor\n",
661 * Get generic interface statistics
663 air.air_opcode = AIOCS_INF_PIS;
664 strcpy(air.air_physt_intf, intf);
665 buf_len = do_info_ioctl(&air,
666 sizeof(struct air_phy_stat_rsp) * 3);
667 if ((ssize_t)buf_len == -1) {
668 fprintf(stderr, "%s: ", prog);
672 perror("Internal error");
675 fprintf(stderr, "%s is not an ATM device\n",
679 perror("ioctl (AIOCINFO)");
686 * Display the interface statistics
688 pstat_info_base = pstat_info = (struct air_phy_stat_rsp *)
689 (void *)air.air_buf_addr;
690 for (; buf_len >= sizeof(struct air_phy_stat_rsp);
692 buf_len-=sizeof(struct air_phy_stat_rsp)) {
693 print_intf_stats(pstat_info);
695 free((caddr_t)pstat_info_base);
701 * Process VCC statistics command
704 * atm show stats VCC [<interface-name> [<vpi> [<vci>]]]
707 * argc number of remaining arguments to command
708 * argv pointer to remaining argument strings
709 * cmdp pointer to command description
716 show_vcc_stats(int argc, char **argv, const struct cmd *cmdp __unused)
719 int vpi = -1, vci = -1;
720 char *cp, *intf = NULL;
721 struct air_vcc_rsp *vcc_info, *vcc_info_base;
724 * Validate interface name
727 if (strlen(argv[0]) > IFNAMSIZ - 1) {
728 fprintf(stderr, "%s: Illegal interface name\n",
740 vpi = strtol(argv[0], &cp, 0);
741 if ((*cp != '\0') || (vpi < 0) || (vpi >= 1 << 8)) {
742 fprintf(stderr, "%s: Invalid VPI value\n", prog);
752 vci = strtol(argv[0], &cp, 0);
753 if ((*cp != '\0') || (vci <= 0) || (vci >= 1 << 16)) {
754 fprintf(stderr, "%s: Invalid VCI value\n",
762 * Get VCC information
764 vcc_info_len = get_vcc_info(intf, &vcc_info);
765 if (vcc_info_len == 0)
767 else if ((ssize_t)vcc_info_len == -1) {
768 fprintf(stderr, "%s: ", prog);
772 perror("Internal error");
775 fprintf(stderr, "Not an ATM device\n");
778 perror("ioctl (AIOCINFO)");
785 * Sort the VCC information
787 qsort((void *) vcc_info,
788 vcc_info_len / sizeof(struct air_vcc_rsp),
789 sizeof(struct air_vcc_rsp),
793 * Display the VCC statistics
795 vcc_info_base = vcc_info;
796 for (; vcc_info_len >= sizeof(struct air_vcc_rsp);
797 vcc_info_len-=sizeof(struct air_vcc_rsp),
799 if (vpi != -1 && vcc_info->avp_vpi != vpi)
801 if (vci != -1 && vcc_info->avp_vci != vci)
803 print_vcc_stats(vcc_info);
810 * Process VCC information command
813 * atm show VCC [<interface-name> [<vpi> [<vci>] | PVC | SVC]]
816 * argc number of remaining arguments to command
817 * argv pointer to remaining argument strings
818 * cmdp pointer to command description
825 show_vcc(int argc, char **argv, const struct cmd *cmdp __unused)
828 int vpi = -1, vci = -1, show_pvc = 0, show_svc = 0;
829 char *cp, *intf = NULL;
830 struct air_vcc_rsp *vcc_info, *vcc_info_base;
833 * Validate interface name
836 if (strlen(argv[0]) > IFNAMSIZ - 1) {
837 fprintf(stderr, "%s: Illegal interface name\n",
849 if (strcasecmp(argv[0], "pvc"))
851 else if (strcasecmp(argv[0], "svc"))
854 vpi = strtol(argv[0], &cp, 0);
855 if ((*cp != '\0') || (vpi < 0) ||
857 fprintf(stderr, "%s: Invalid VPI value\n", prog);
868 vci = strtol(argv[0], &cp, 0);
869 if ((*cp != '\0') || (vci <= 0) || (vci >= 1 << 16)) {
870 fprintf(stderr, "%s: Invalid VCI value\n",
878 * Get VCC information
880 vcc_info_len = get_vcc_info(intf, &vcc_info);
881 if (vcc_info_len == 0)
883 else if ((ssize_t)vcc_info_len == -1) {
884 fprintf(stderr, "%s: ", prog);
888 perror("Internal error");
891 fprintf(stderr, "Not an ATM device\n");
894 perror("ioctl (AIOCINFO)");
901 * Sort the VCC information
903 qsort((void *) vcc_info,
904 vcc_info_len/sizeof(struct air_vcc_rsp),
905 sizeof(struct air_vcc_rsp),
909 * Display the VCC information
911 vcc_info_base = vcc_info;
912 for (; vcc_info_len >= sizeof(struct air_vcc_rsp);
913 vcc_info_len-=sizeof(struct air_vcc_rsp),
915 if (vpi != -1 && vcc_info->avp_vpi != vpi)
917 if (vci != -1 && vcc_info->avp_vci != vci)
919 if (show_pvc && vcc_info->avp_type & VCC_PVC)
921 if (show_svc && vcc_info->avp_type & VCC_SVC)
923 print_vcc_info(vcc_info);
930 * Process version command
936 * argc number of remaining arguments to command
937 * argv pointer to remaining argument strings
938 * cmdp pointer to command description
945 show_version(int argc __unused, char **argv __unused,
946 const struct cmd *cmdp __unused)
949 struct atminfreq air;
950 struct air_version_rsp *ver_info, *ver_info_base;
953 * Get network interface information from the kernel
955 air.air_opcode = AIOCS_INF_VER;
956 buf_len = do_info_ioctl(&air, sizeof(struct air_version_rsp));
957 if ((ssize_t)buf_len == -1) {
958 fprintf(stderr, "%s: ", prog);
962 perror("Internal error");
965 fprintf(stderr, "Not an ATM device\n");
968 perror("ioctl (AIOCINFO)");
975 * Print the network interface information
977 ver_info_base = ver_info =
978 (struct air_version_rsp *)(void *)air.air_buf_addr;
979 for (; buf_len >= sizeof(struct air_version_rsp); ver_info++,
980 buf_len -= sizeof(struct air_version_rsp)) {
981 print_version_info(ver_info);
988 * Comparison function for qsort
991 * p1 pointer to the first VCC response
992 * p2 pointer to the second VCC response
995 * int a number less than, greater than, or equal to zero,
996 * depending on whether *p1 is less than, greater than, or
1002 const void *p1, *p2;
1005 const struct air_vcc_rsp *c1, *c2;
1007 c1 = (const struct air_vcc_rsp *) p1;
1008 c2 = (const struct air_vcc_rsp *) p2;
1011 * Compare the interface names
1013 rc = strcmp(c1->avp_intf, c2->avp_intf);
1018 * Compare the VPI values
1020 rc = c1->avp_vpi - c2->avp_vpi;
1025 * Compare the VCI values
1027 rc = c1->avp_vci - c2->avp_vci;
1034 rc = c1->avp_type - c2->avp_type;
1040 * Comparison function for qsort
1043 * p1 pointer to the first VCC response
1044 * p2 pointer to the second VCC response
1047 * int a number less than, greater than, or equal to zero,
1048 * depending on whether *p1 is less than, greater than, or
1053 ip_vcc_compare(p1, p2)
1054 const void *p1, *p2;
1057 const struct air_ip_vcc_rsp *c1, *c2;
1059 c1 = (const struct air_ip_vcc_rsp *) p1;
1060 c2 = (const struct air_ip_vcc_rsp *) p2;
1063 * Compare the interface names
1065 rc = strcmp(c1->aip_intf, c2->aip_intf);
1070 * Compare the VPI values
1072 rc = c1->aip_vpi - c2->aip_vpi;
1077 * Compare the VCI values
1079 rc = c1->aip_vci - c2->aip_vci;
1085 * Comparison function for qsort
1088 * p1 pointer to the first ARP or IP map entry
1089 * p2 pointer to the second ARP or IP map entry
1092 * int a number less than, greater than, or equal to zero,
1093 * depending on whether *p1 is less than, greater than, or
1099 const void *p1, *p2;
1102 const struct air_arp_rsp *c1, *c2;
1103 const struct sockaddr_in *sin1, *sin2;
1105 c1 = (const struct air_arp_rsp *)p1;
1106 c2 = (const struct air_arp_rsp *)p2;
1107 sin1 = (const struct sockaddr_in *)(const void *)&c1->aap_arp_addr;
1108 sin2 = (const struct sockaddr_in *)(const void *)&c2->aap_arp_addr;
1111 * Compare the IP addresses
1113 if ((rc = sin1->sin_family - sin2->sin_family) != 0)
1115 if ((rc = sin1->sin_addr.s_addr - sin2->sin_addr.s_addr) != 0)
1119 * Compare the ATM addresses
1121 if ((rc = c1->aap_addr.address_format - c2->aap_addr.address_format) != 0)
1123 if ((rc = c1->aap_addr.address_length - c2->aap_addr.address_length) != 0)
1125 switch(c1->aap_addr.address_format) {
1129 case T_ATM_ENDSYS_ADDR:
1130 rc = bcmp(c1->aap_addr.address, c2->aap_addr.address,
1131 sizeof(Atm_addr_nsap));
1133 case T_ATM_E164_ADDR:
1134 rc = bcmp(c1->aap_addr.address, c2->aap_addr.address,
1135 sizeof(Atm_addr_e164));
1137 case T_ATM_SPANS_ADDR:
1138 rc = bcmp(c1->aap_addr.address, c2->aap_addr.address,
1139 sizeof(Atm_addr_spans));