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 * @(#) $Id: atm_show.c,v 1.1 1998/09/15 08:22:46 phk Exp $
31 * User configuration and display program
32 * --------------------------------------
34 * Routines for "show" subcommand
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <sys/socket.h>
42 #include <netinet/in.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_sys.h>
48 #include <netatm/atm_vc.h>
49 #include <netatm/atm_ioctl.h>
60 __RCSID("@(#) $Id: atm_show.c,v 1.1 1998/09/15 08:22:46 phk Exp $");
67 static int vcc_compare __P((const void *, const void *));
68 static int ip_vcc_compare __P((const void *, const void *));
69 static int arp_compare __P((const void *, const void *));
73 * Process show ARP command
76 * atm show ARP [<ip-addr>]
79 * argc number of remaining arguments to command
80 * argv pointer to remaining argument strings
81 * cmdp pointer to command description
88 show_arp(argc, argv, cmdp)
93 int buf_len, arp_info_len;
95 struct air_arp_rsp *arp_info, *arp_info_base;
96 struct sockaddr_in *sin;
98 struct sockaddr_in sin;
103 * Get IP address of specified host name
105 UM_ZERO(&host_addr, sizeof(host_addr));
106 host_addr.sa.sa_family = AF_INET;
108 sin = get_ip_addr(argv[0]);
110 fprintf(stderr, "%s: host \'%s\' not found\n",
114 host_addr.sin.sin_addr.s_addr = sin->sin_addr.s_addr;
116 host_addr.sin.sin_addr.s_addr = INADDR_ANY;
120 * Get ARP information from the kernel
122 UM_ZERO(&air, sizeof(air));
123 buf_len = sizeof(struct air_arp_rsp) * 10;
124 air.air_opcode = AIOCS_INF_ARP;
125 air.air_arp_addr = host_addr.sa;
126 arp_info_len = do_info_ioctl(&air, buf_len);
127 if (arp_info_len < 0) {
128 fprintf(stderr, "%s: ", prog);
132 perror("Internal error");
135 fprintf(stderr, "not an ATM device\n");
138 perror("ioctl (AIOCINFO)");
143 arp_info_base = arp_info =
144 (struct air_arp_rsp *) air.air_buf_addr;
149 qsort((void *) arp_info,
150 arp_info_len / sizeof(struct air_arp_rsp),
151 sizeof(struct air_arp_rsp),
155 * Print the relevant information
157 while (arp_info_len > 0) {
158 print_arp_info(arp_info);
160 arp_info_len -= sizeof(struct air_arp_rsp);
164 * Release the information from the kernel
166 UM_FREE(arp_info_base);
171 * Process show ATM ARP server command
174 * atm show arpserver [<interface-name>]
177 * argc number of remaining arguments to command
178 * argv pointer to remaining argument strings
179 * cmdp pointer to command description
186 show_arpserv(argc, argv, cmdp)
191 int asrv_info_len, buf_len = sizeof(struct air_asrv_rsp) * 3;
192 struct atminfreq air;
193 struct air_asrv_rsp *asrv_info, *asrv_info_base;
196 * Validate interface name
198 UM_ZERO(air.air_int_intf, sizeof(air.air_int_intf));
200 if (strlen(argv[0]) > IFNAMSIZ - 1) {
201 fprintf(stderr, "%s: Illegal interface name\n",
205 strcpy(air.air_int_intf, argv[0]);
210 * Get interface information from the kernel
212 air.air_opcode = AIOCS_INF_ASV;
213 buf_len = do_info_ioctl(&air, buf_len);
215 fprintf(stderr, "%s: ", prog);
219 perror("Internal error");
222 fprintf(stderr, "%s is not an ATM device\n",
226 perror("ioctl (AIOCINFO)");
233 * Print the interface information
235 asrv_info_base = asrv_info =
236 (struct air_asrv_rsp *) air.air_buf_addr;
237 for (; buf_len >= sizeof(struct air_asrv_rsp);
238 asrv_info = (struct air_asrv_rsp *)
239 ((u_long)asrv_info + asrv_info_len),
240 buf_len -= asrv_info_len) {
241 print_asrv_info(asrv_info);
242 asrv_info_len = sizeof(struct air_asrv_rsp) +
243 asrv_info->asp_nprefix *
244 sizeof(struct in_addr) * 2;
246 UM_FREE(asrv_info_base);
251 * Process show ATM adapter configuration command
254 * atm show config [<interface-name>]
257 * argc number of remaining arguments to command
258 * argv pointer to remaining argument strings
259 * cmdp pointer to command description
266 show_config(argc, argv, cmdp)
271 int buf_len = sizeof(struct air_asrv_rsp) * 3;
272 struct atminfreq air;
273 struct air_cfg_rsp *cfg_info, *cfg_info_base;
276 * Validate interface name
278 UM_ZERO(air.air_cfg_intf, sizeof(air.air_cfg_intf));
280 if (strlen(argv[0]) > IFNAMSIZ - 1) {
281 fprintf(stderr, "%s: Illegal interface name\n",
285 strcpy(air.air_cfg_intf, argv[0]);
290 * Get configuration information from the kernel
292 air.air_opcode = AIOCS_INF_CFG;
293 buf_len = do_info_ioctl(&air, buf_len);
295 fprintf(stderr, "%s: ", prog);
299 perror("Internal error");
302 fprintf(stderr, "%s is not an ATM device\n",
306 perror("ioctl (AIOCINFO)");
313 * Print the interface information
315 cfg_info_base = cfg_info =
316 (struct air_cfg_rsp *) air.air_buf_addr;
317 for (; buf_len >= sizeof(struct air_cfg_rsp); cfg_info++,
318 buf_len -= sizeof(struct air_cfg_rsp)) {
319 print_cfg_info(cfg_info);
321 UM_FREE(cfg_info_base);
326 * Process show interface command
329 * atm show interface [<interface-name>]
332 * argc number of remaining arguments to command
333 * argv pointer to remaining argument strings
334 * cmdp pointer to command description
341 show_intf(argc, argv, cmdp)
346 int buf_len = sizeof(struct air_int_rsp) * 3;
347 struct atminfreq air;
348 struct air_int_rsp *int_info, *int_info_base;
351 * Validate interface name
353 UM_ZERO(&air, sizeof(air));
355 if (strlen(argv[0]) > IFNAMSIZ - 1) {
356 fprintf(stderr, "%s: Illegal interface name\n",
360 strcpy(air.air_int_intf, argv[0]);
365 * Get interface information from the kernel
367 air.air_opcode = AIOCS_INF_INT;
368 buf_len = do_info_ioctl(&air, buf_len);
370 fprintf(stderr, "%s: ", prog);
374 perror("Internal error");
377 fprintf(stderr, "%s is not an ATM device\n",
381 perror("ioctl (AIOCINFO)");
388 * Print the interface information
390 int_info_base = int_info =
391 (struct air_int_rsp *) air.air_buf_addr;
392 for (; buf_len >= sizeof(struct air_int_rsp); int_info++,
393 buf_len -= sizeof(struct air_int_rsp)) {
394 print_intf_info(int_info);
396 UM_FREE(int_info_base);
401 * Process show IP VCCs command
404 * atm show ipvcc [<ip-addr>]
407 * argc number of remaining arguments to command
408 * argv pointer to remaining argument strings
409 * cmdp pointer to command description
416 show_ip_vcc(argc, argv, cmdp)
421 int buf_len, ip_info_len, rc;
422 char *if_name = (char *)0;
423 struct atminfreq air;
424 struct air_ip_vcc_rsp *ip_info, *ip_info_base;
425 struct sockaddr_in *sin;
427 struct sockaddr_in sin;
432 * First parameter can be a netif name, an IP host name, or
433 * an IP address. Figure out which it is.
435 UM_ZERO(&host_addr, sizeof(host_addr));
436 host_addr.sa.sa_family = AF_INET;
438 rc = verify_nif_name(argv[0]);
443 fprintf(stderr, "%s: ", prog);
447 perror("Internal error");
450 fprintf(stderr, "%s is not an ATM device\n",
454 perror("ioctl (AIOCINFO)");
460 * Parameter is a valid netif name
465 * Get IP address of specified host name
467 sin = get_ip_addr(argv[0]);
468 host_addr.sin.sin_addr.s_addr =
469 sin->sin_addr.s_addr;
472 host_addr.sin.sin_addr.s_addr = INADDR_ANY;
476 * Get IP map information from the kernel
478 buf_len = sizeof(struct air_ip_vcc_rsp) * 10;
479 air.air_opcode = AIOCS_INF_IPM;
480 air.air_ip_addr = host_addr.sa;
481 ip_info_len = do_info_ioctl(&air, buf_len);
482 if (ip_info_len < 0) {
483 fprintf(stderr, "%s: ", prog);
487 perror("Internal error");
490 fprintf(stderr, "not an ATM device\n");
493 perror("ioctl (AIOCINFO)");
498 ip_info_base = ip_info =
499 (struct air_ip_vcc_rsp *) air.air_buf_addr;
502 * Sort the information
504 qsort((void *) ip_info,
505 ip_info_len / sizeof(struct air_ip_vcc_rsp),
506 sizeof(struct air_ip_vcc_rsp),
510 * Print the relevant information
512 while (ip_info_len>0) {
513 if (!if_name || !strcmp(if_name, ip_info->aip_intf)) {
514 print_ip_vcc_info(ip_info);
517 ip_info_len -= sizeof(struct air_ip_vcc_rsp);
521 * Release the information from the kernel
523 UM_FREE(ip_info_base);
529 * Process show network interface command
532 * atm show netif [<netif>]
535 * argc number of remaining arguments to command
536 * argv pointer to remaining argument strings
537 * cmdp pointer to command description
544 show_netif(argc, argv, cmdp)
549 int buf_len = sizeof(struct air_netif_rsp) * 3;
550 struct atminfreq air;
551 struct air_netif_rsp *int_info, *int_info_base;
554 * Validate network interface name
556 UM_ZERO(air.air_int_intf, sizeof(air.air_int_intf));
558 if (strlen(argv[0]) > IFNAMSIZ - 1) {
559 fprintf(stderr, "%s: Illegal interface name\n", prog);
562 strcpy(air.air_int_intf, argv[0]);
567 * Get network interface information from the kernel
569 air.air_opcode = AIOCS_INF_NIF;
570 buf_len = do_info_ioctl(&air, buf_len);
572 fprintf(stderr, "%s: ", prog);
576 perror("Internal error");
579 fprintf(stderr, "%s is not an ATM device\n",
583 perror("ioctl (AIOCINFO)");
590 * Print the network interface information
592 int_info_base = int_info =
593 (struct air_netif_rsp *) air.air_buf_addr;
594 for (; buf_len >= sizeof(struct air_netif_rsp); int_info++,
595 buf_len -= sizeof(struct air_netif_rsp)) {
596 print_netif_info(int_info);
598 UM_FREE(int_info_base);
603 * Process interface statistics command
606 * atm show stats interface [<interface-name>]
609 * argc number of remaining arguments to command
610 * argv pointer to remaining argument strings
611 * cmdp pointer to command description
618 show_intf_stats(argc, argv, cmdp)
625 struct atminfreq air;
626 struct air_phy_stat_rsp *pstat_info, *pstat_info_base;
627 struct air_cfg_rsp *cfg_info;
630 * Validate interface name
632 UM_ZERO(intf, sizeof(intf));
634 if (strlen(argv[0]) > IFNAMSIZ - 1) {
635 fprintf(stderr, "%s: Illegal interface name\n",
639 strcpy(intf, argv[0]);
644 * If there are parameters remaining, the request is for
645 * vendor-specific adaptor statistics
649 * Get adapter configuration information
651 buf_len = sizeof(struct air_cfg_rsp);
652 air.air_opcode = AIOCS_INF_CFG;
653 strcpy(air.air_cfg_intf, intf);
654 buf_len = do_info_ioctl(&air, buf_len);
656 fprintf(stderr, "%s: ", prog);
660 perror("Internal error");
663 fprintf(stderr, "%s is not an ATM device\n",
667 perror("ioctl (AIOCINFO)");
672 cfg_info = (struct air_cfg_rsp *)air.air_buf_addr;
675 * Call the appropriate vendor-specific routine
677 switch(cfg_info->acp_vendor) {
679 show_fore200_stats(intf, argc, argv);
682 show_eni_stats(intf, argc, argv);
685 fprintf(stderr, "%s: Unknown adapter vendor\n",
693 * Get generic interface statistics
695 buf_len = sizeof(struct air_phy_stat_rsp) * 3;
696 air.air_opcode = AIOCS_INF_PIS;
697 strcpy(air.air_physt_intf, intf);
698 buf_len = do_info_ioctl(&air, buf_len);
700 fprintf(stderr, "%s: ", prog);
704 perror("Internal error");
707 fprintf(stderr, "%s is not an ATM device\n",
711 perror("ioctl (AIOCINFO)");
718 * Display the interface statistics
720 pstat_info_base = pstat_info =
721 (struct air_phy_stat_rsp *)air.air_buf_addr;
722 for (; buf_len >= sizeof(struct air_phy_stat_rsp);
724 buf_len-=sizeof(struct air_phy_stat_rsp)) {
725 print_intf_stats(pstat_info);
727 UM_FREE((caddr_t)pstat_info_base);
733 * Process VCC statistics command
736 * atm show stats VCC [<interface-name> [<vpi> [<vci>]]]
739 * argc number of remaining arguments to command
740 * argv pointer to remaining argument strings
741 * cmdp pointer to command description
748 show_vcc_stats(argc, argv, cmdp)
754 int vpi = -1, vci = -1;
755 char *cp, *intf = NULL;
756 struct air_vcc_rsp *vcc_info, *vcc_info_base;
759 * Validate interface name
762 if (strlen(argv[0]) > IFNAMSIZ - 1) {
763 fprintf(stderr, "%s: Illegal interface name\n",
775 vpi = strtol(argv[0], &cp, 0);
776 if ((*cp != '\0') || (vpi < 0) || (vpi >= 1 << 8)) {
777 fprintf(stderr, "%s: Invalid VPI value\n", prog);
787 vci = strtol(argv[0], &cp, 0);
788 if ((*cp != '\0') || (vci <= 0) || (vci >= 1 << 16)) {
789 fprintf(stderr, "%s: Invalid VCI value\n",
797 * Get VCC information
799 vcc_info_len = get_vcc_info(intf, &vcc_info);
800 if (vcc_info_len == 0)
802 else if (vcc_info_len < 0) {
803 fprintf(stderr, "%s: ", prog);
807 perror("Internal error");
810 fprintf(stderr, "Not an ATM device\n");
813 perror("ioctl (AIOCINFO)");
820 * Sort the VCC information
822 qsort((void *) vcc_info,
823 vcc_info_len / sizeof(struct air_vcc_rsp),
824 sizeof(struct air_vcc_rsp),
828 * Display the VCC statistics
830 vcc_info_base = vcc_info;
831 for (; vcc_info_len >= sizeof(struct air_vcc_rsp);
832 vcc_info_len-=sizeof(struct air_vcc_rsp),
834 if (vpi != -1 && vcc_info->avp_vpi != vpi)
836 if (vci != -1 && vcc_info->avp_vci != vci)
838 print_vcc_stats(vcc_info);
840 UM_FREE(vcc_info_base);
845 * Process VCC information command
848 * atm show VCC [<interface-name> [<vpi> [<vci>] | PVC | SVC]]
851 * argc number of remaining arguments to command
852 * argv pointer to remaining argument strings
853 * cmdp pointer to command description
860 show_vcc(argc, argv, cmdp)
866 int vpi = -1, vci = -1, show_pvc = 0, show_svc = 0;
867 char *cp, *intf = NULL;
868 struct air_vcc_rsp *vcc_info, *vcc_info_base;
871 * Validate interface name
874 if (strlen(argv[0]) > IFNAMSIZ - 1) {
875 fprintf(stderr, "%s: Illegal interface name\n",
887 if (strcasecmp(argv[0], "pvc"))
889 else if (strcasecmp(argv[0], "svc"))
892 vpi = strtol(argv[0], &cp, 0);
893 if ((*cp != '\0') || (vpi < 0) ||
895 fprintf(stderr, "%s: Invalid VPI value\n", prog);
906 vci = strtol(argv[0], &cp, 0);
907 if ((*cp != '\0') || (vci <= 0) || (vci >= 1 << 16)) {
908 fprintf(stderr, "%s: Invalid VCI value\n",
916 * Get VCC information
918 vcc_info_len = get_vcc_info(intf, &vcc_info);
919 if (vcc_info_len == 0)
921 else if (vcc_info_len < 0) {
922 fprintf(stderr, "%s: ", prog);
926 perror("Internal error");
929 fprintf(stderr, "Not an ATM device\n");
932 perror("ioctl (AIOCINFO)");
939 * Sort the VCC information
941 qsort((void *) vcc_info,
942 vcc_info_len/sizeof(struct air_vcc_rsp),
943 sizeof(struct air_vcc_rsp),
947 * Display the VCC information
949 vcc_info_base = vcc_info;
950 for (; vcc_info_len >= sizeof(struct air_vcc_rsp);
951 vcc_info_len-=sizeof(struct air_vcc_rsp),
953 if (vpi != -1 && vcc_info->avp_vpi != vpi)
955 if (vci != -1 && vcc_info->avp_vci != vci)
957 if (show_pvc && vcc_info->avp_type & VCC_PVC)
959 if (show_svc && vcc_info->avp_type & VCC_SVC)
961 print_vcc_info(vcc_info);
963 UM_FREE(vcc_info_base);
968 * Process version command
974 * argc number of remaining arguments to command
975 * argv pointer to remaining argument strings
976 * cmdp pointer to command description
983 show_version(argc, argv, cmdp)
988 int buf_len = sizeof(struct air_version_rsp);
989 struct atminfreq air;
990 struct air_version_rsp *ver_info, *ver_info_base;
993 * Get network interface information from the kernel
995 air.air_opcode = AIOCS_INF_VER;
996 buf_len = do_info_ioctl(&air, buf_len);
998 fprintf(stderr, "%s: ", prog);
1002 perror("Internal error");
1005 fprintf(stderr, "Not an ATM device\n");
1008 perror("ioctl (AIOCINFO)");
1015 * Print the network interface information
1017 ver_info_base = ver_info =
1018 (struct air_version_rsp *) air.air_buf_addr;
1019 for (; buf_len >= sizeof(struct air_version_rsp); ver_info++,
1020 buf_len -= sizeof(struct air_version_rsp)) {
1021 print_version_info(ver_info);
1023 UM_FREE(ver_info_base);
1028 * Comparison function for qsort
1031 * p1 pointer to the first VCC response
1032 * p2 pointer to the second VCC response
1035 * int a number less than, greater than, or equal to zero,
1036 * depending on whether *p1 is less than, greater than, or
1042 const void *p1, *p2;
1045 struct air_vcc_rsp *c1, *c2;
1047 c1 = (struct air_vcc_rsp *) p1;
1048 c2 = (struct air_vcc_rsp *) p2;
1051 * Compare the interface names
1053 rc = strcmp(c1->avp_intf, c2->avp_intf);
1058 * Compare the VPI values
1060 rc = c1->avp_vpi - c2->avp_vpi;
1065 * Compare the VCI values
1067 rc = c1->avp_vci - c2->avp_vci;
1074 rc = c1->avp_type - c2->avp_type;
1080 * Comparison function for qsort
1083 * p1 pointer to the first VCC response
1084 * p2 pointer to the second VCC response
1087 * int a number less than, greater than, or equal to zero,
1088 * depending on whether *p1 is less than, greater than, or
1093 ip_vcc_compare(p1, p2)
1094 const void *p1, *p2;
1097 struct air_ip_vcc_rsp *c1, *c2;
1099 c1 = (struct air_ip_vcc_rsp *) p1;
1100 c2 = (struct air_ip_vcc_rsp *) p2;
1103 * Compare the interface names
1105 rc = strcmp(c1->aip_intf, c2->aip_intf);
1110 * Compare the VPI values
1112 rc = c1->aip_vpi - c2->aip_vpi;
1117 * Compare the VCI values
1119 rc = c1->aip_vci - c2->aip_vci;
1125 * Comparison function for qsort
1128 * p1 pointer to the first ARP or IP map entry
1129 * p2 pointer to the second ARP or IP map entry
1132 * int a number less than, greater than, or equal to zero,
1133 * depending on whether *p1 is less than, greater than, or
1139 const void *p1, *p2;
1142 struct air_arp_rsp *c1, *c2;
1143 struct sockaddr_in *sin1, *sin2;
1145 c1 = (struct air_arp_rsp *) p1;
1146 c2 = (struct air_arp_rsp *) p2;
1147 sin1 = (struct sockaddr_in *) &c1->aap_arp_addr;
1148 sin2 = (struct sockaddr_in *) &c2->aap_arp_addr;
1151 * Compare the IP addresses
1153 if ((rc = sin1->sin_family - sin2->sin_family) != 0)
1155 if ((rc = sin1->sin_addr.s_addr - sin2->sin_addr.s_addr) != 0)
1159 * Compare the ATM addresses
1161 if ((rc = c1->aap_addr.address_format - c2->aap_addr.address_format) != 0)
1163 if ((rc = c1->aap_addr.address_length - c2->aap_addr.address_length) != 0)
1165 switch(c1->aap_addr.address_format) {
1169 case T_ATM_ENDSYS_ADDR:
1170 rc = bcmp((caddr_t)c1->aap_addr.address,
1171 (caddr_t)c2->aap_addr.address,
1172 sizeof(Atm_addr_nsap));
1174 case T_ATM_E164_ADDR:
1175 rc = bcmp((caddr_t)c1->aap_addr.address,
1176 (caddr_t)c2->aap_addr.address,
1177 sizeof(Atm_addr_e164));
1179 case T_ATM_SPANS_ADDR:
1180 rc = bcmp((caddr_t)c1->aap_addr.address,
1181 (caddr_t)c2->aap_addr.address,
1182 sizeof(Atm_addr_spans));