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_show.c,v 1.3.2.1 2000/07/01 06:02:14 ps Exp $
27 * @(#) $DragonFly: src/sbin/atm/atm/atm_show.c,v 1.3 2003/09/28 14:39:16 hmp Exp $
31 * User configuration and display program
32 * --------------------------------------
34 * Routines for "show" subcommand
38 #include <sys/param.h>
39 #include <sys/socket.h>
41 #include <netinet/in.h>
42 #include <netatm/port.h>
43 #include <netatm/atm.h>
44 #include <netatm/atm_if.h>
45 #include <netatm/atm_sap.h>
46 #include <netatm/atm_sys.h>
47 #include <netatm/atm_vc.h>
48 #include <netatm/atm_ioctl.h>
61 static int vcc_compare __P((const void *, const void *));
62 static int ip_vcc_compare __P((const void *, const void *));
63 static int arp_compare __P((const void *, const void *));
67 * Process show ARP command
70 * atm show ARP [<ip-addr>]
73 * argc number of remaining arguments to command
74 * argv pointer to remaining argument strings
75 * cmdp pointer to command description
82 show_arp(int argc, char **argv, struct cmd *cmdp)
84 int buf_len, arp_info_len;
86 struct air_arp_rsp *arp_info, *arp_info_base;
87 struct sockaddr_in *sin;
89 struct sockaddr_in sin;
94 * Get IP address of specified host name
96 UM_ZERO(&host_addr, sizeof(host_addr));
97 host_addr.sa.sa_family = AF_INET;
99 sin = get_ip_addr(argv[0]);
101 fprintf(stderr, "%s: host \'%s\' not found\n",
105 host_addr.sin.sin_addr.s_addr = sin->sin_addr.s_addr;
107 host_addr.sin.sin_addr.s_addr = INADDR_ANY;
111 * Get ARP information from the kernel
113 UM_ZERO(&air, sizeof(air));
114 buf_len = sizeof(struct air_arp_rsp) * 10;
115 air.air_opcode = AIOCS_INF_ARP;
116 air.air_arp_addr = host_addr.sa;
117 arp_info_len = do_info_ioctl(&air, buf_len);
118 if (arp_info_len < 0) {
119 fprintf(stderr, "%s: ", prog);
123 perror("Internal error");
126 fprintf(stderr, "not an ATM device\n");
129 perror("ioctl (AIOCINFO)");
134 arp_info_base = arp_info =
135 (struct air_arp_rsp *) air.air_buf_addr;
140 qsort((void *) arp_info,
141 arp_info_len / sizeof(struct air_arp_rsp),
142 sizeof(struct air_arp_rsp),
146 * Print the relevant information
148 while (arp_info_len > 0) {
149 print_arp_info(arp_info);
151 arp_info_len -= sizeof(struct air_arp_rsp);
155 * Release the information from the kernel
157 UM_FREE(arp_info_base);
162 * Process show ATM ARP server command
165 * atm show arpserver [<interface-name>]
168 * argc number of remaining arguments to command
169 * argv pointer to remaining argument strings
170 * cmdp pointer to command description
177 show_arpserv(int argc, char **argv, struct cmd *cmdp)
179 int asrv_info_len, buf_len = sizeof(struct air_asrv_rsp) * 3;
180 struct atminfreq air;
181 struct air_asrv_rsp *asrv_info, *asrv_info_base;
184 * Validate interface name
186 UM_ZERO(air.air_int_intf, sizeof(air.air_int_intf));
188 if (strlen(argv[0]) > IFNAMSIZ - 1) {
189 fprintf(stderr, "%s: Illegal interface name\n",
193 strcpy(air.air_int_intf, argv[0]);
198 * Get interface information from the kernel
200 air.air_opcode = AIOCS_INF_ASV;
201 buf_len = do_info_ioctl(&air, buf_len);
203 fprintf(stderr, "%s: ", prog);
207 perror("Internal error");
210 fprintf(stderr, "%s is not an ATM device\n",
214 perror("ioctl (AIOCINFO)");
221 * Print the interface information
223 asrv_info_base = asrv_info =
224 (struct air_asrv_rsp *) air.air_buf_addr;
225 for (; buf_len >= sizeof(struct air_asrv_rsp);
226 asrv_info = (struct air_asrv_rsp *)
227 ((u_long)asrv_info + asrv_info_len),
228 buf_len -= asrv_info_len) {
229 print_asrv_info(asrv_info);
230 asrv_info_len = sizeof(struct air_asrv_rsp) +
231 asrv_info->asp_nprefix *
232 sizeof(struct in_addr) * 2;
234 UM_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, struct cmd *cmdp)
256 int buf_len = sizeof(struct air_asrv_rsp) * 3;
257 struct atminfreq air;
258 struct air_cfg_rsp *cfg_info, *cfg_info_base;
261 * Validate interface name
263 UM_ZERO(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, buf_len);
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 *) 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);
306 UM_FREE(cfg_info_base);
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, struct cmd *cmdp)
328 int buf_len = sizeof(struct air_int_rsp) * 3;
329 struct atminfreq air;
330 struct air_int_rsp *int_info, *int_info_base;
333 * Validate interface name
335 UM_ZERO(&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, buf_len);
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 *) 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);
378 UM_FREE(int_info_base);
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, struct cmd *cmdp)
400 int buf_len, ip_info_len, rc;
401 char *if_name = (char *)0;
402 struct atminfreq air;
403 struct air_ip_vcc_rsp *ip_info, *ip_info_base;
404 struct sockaddr_in *sin;
406 struct sockaddr_in sin;
411 * First parameter can be a netif name, an IP host name, or
412 * an IP address. Figure out which it is.
414 UM_ZERO(&host_addr, sizeof(host_addr));
415 host_addr.sa.sa_family = AF_INET;
417 rc = verify_nif_name(argv[0]);
422 fprintf(stderr, "%s: ", prog);
426 perror("Internal error");
429 fprintf(stderr, "%s is not an ATM device\n",
433 perror("ioctl (AIOCINFO)");
439 * Parameter is a valid netif name
444 * Get IP address of specified host name
446 sin = get_ip_addr(argv[0]);
447 host_addr.sin.sin_addr.s_addr =
448 sin->sin_addr.s_addr;
451 host_addr.sin.sin_addr.s_addr = INADDR_ANY;
455 * Get IP map information from the kernel
457 buf_len = sizeof(struct air_ip_vcc_rsp) * 10;
458 air.air_opcode = AIOCS_INF_IPM;
459 air.air_ip_addr = host_addr.sa;
460 ip_info_len = do_info_ioctl(&air, buf_len);
461 if (ip_info_len < 0) {
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 *) 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>0) {
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
502 UM_FREE(ip_info_base);
508 * Process show network interface command
511 * atm show netif [<netif>]
514 * argc number of remaining arguments to command
515 * argv pointer to remaining argument strings
516 * cmdp pointer to command description
523 show_netif(int argc, char **argv, struct cmd *cmdp)
525 int buf_len = sizeof(struct air_netif_rsp) * 3;
526 struct atminfreq air;
527 struct air_netif_rsp *int_info, *int_info_base;
530 * Validate network interface name
532 UM_ZERO(air.air_int_intf, sizeof(air.air_int_intf));
534 if (strlen(argv[0]) > IFNAMSIZ - 1) {
535 fprintf(stderr, "%s: Illegal interface name\n", prog);
538 strcpy(air.air_int_intf, argv[0]);
543 * Get network interface information from the kernel
545 air.air_opcode = AIOCS_INF_NIF;
546 buf_len = do_info_ioctl(&air, buf_len);
548 fprintf(stderr, "%s: ", prog);
552 perror("Internal error");
555 fprintf(stderr, "%s is not an ATM device\n",
559 perror("ioctl (AIOCINFO)");
566 * Print the network interface information
568 int_info_base = int_info =
569 (struct air_netif_rsp *) air.air_buf_addr;
570 for (; buf_len >= sizeof(struct air_netif_rsp); int_info++,
571 buf_len -= sizeof(struct air_netif_rsp)) {
572 print_netif_info(int_info);
574 UM_FREE(int_info_base);
579 * Process interface statistics command
582 * atm show stats interface [<interface-name>]
585 * argc number of remaining arguments to command
586 * argv pointer to remaining argument strings
587 * cmdp pointer to command description
594 show_intf_stats(int argc, char **argv, struct cmd *cmdp)
598 struct atminfreq air;
599 struct air_phy_stat_rsp *pstat_info, *pstat_info_base;
600 struct air_cfg_rsp *cfg_info;
603 * Validate interface name
605 UM_ZERO(intf, sizeof(intf));
607 if (strlen(argv[0]) > IFNAMSIZ - 1) {
608 fprintf(stderr, "%s: Illegal interface name\n",
612 strcpy(intf, argv[0]);
617 * If there are parameters remaining, the request is for
618 * vendor-specific adaptor statistics
622 * Get adapter configuration information
624 buf_len = sizeof(struct air_cfg_rsp);
625 air.air_opcode = AIOCS_INF_CFG;
626 strcpy(air.air_cfg_intf, intf);
627 buf_len = do_info_ioctl(&air, buf_len);
629 fprintf(stderr, "%s: ", prog);
633 perror("Internal error");
636 fprintf(stderr, "%s is not an ATM device\n",
640 perror("ioctl (AIOCINFO)");
645 cfg_info = (struct air_cfg_rsp *)air.air_buf_addr;
648 * Call the appropriate vendor-specific routine
650 switch(cfg_info->acp_vendor) {
652 show_fore200_stats(intf, argc, argv);
655 show_eni_stats(intf, argc, argv);
658 fprintf(stderr, "%s: Unknown adapter vendor\n",
666 * Get generic interface statistics
668 buf_len = sizeof(struct air_phy_stat_rsp) * 3;
669 air.air_opcode = AIOCS_INF_PIS;
670 strcpy(air.air_physt_intf, intf);
671 buf_len = do_info_ioctl(&air, buf_len);
673 fprintf(stderr, "%s: ", prog);
677 perror("Internal error");
680 fprintf(stderr, "%s is not an ATM device\n",
684 perror("ioctl (AIOCINFO)");
691 * Display the interface statistics
693 pstat_info_base = pstat_info =
694 (struct air_phy_stat_rsp *)air.air_buf_addr;
695 for (; buf_len >= sizeof(struct air_phy_stat_rsp);
697 buf_len-=sizeof(struct air_phy_stat_rsp)) {
698 print_intf_stats(pstat_info);
700 UM_FREE((caddr_t)pstat_info_base);
706 * Process VCC statistics command
709 * atm show stats VCC [<interface-name> [<vpi> [<vci>]]]
712 * argc number of remaining arguments to command
713 * argv pointer to remaining argument strings
714 * cmdp pointer to command description
721 show_vcc_stats(int argc, char **argv, struct cmd *cmdp)
724 int vpi = -1, vci = -1;
725 char *cp, *intf = NULL;
726 struct air_vcc_rsp *vcc_info, *vcc_info_base;
729 * Validate interface name
732 if (strlen(argv[0]) > IFNAMSIZ - 1) {
733 fprintf(stderr, "%s: Illegal interface name\n",
745 vpi = strtol(argv[0], &cp, 0);
746 if ((*cp != '\0') || (vpi < 0) || (vpi >= 1 << 8)) {
747 fprintf(stderr, "%s: Invalid VPI value\n", prog);
757 vci = strtol(argv[0], &cp, 0);
758 if ((*cp != '\0') || (vci <= 0) || (vci >= 1 << 16)) {
759 fprintf(stderr, "%s: Invalid VCI value\n",
767 * Get VCC information
769 vcc_info_len = get_vcc_info(intf, &vcc_info);
770 if (vcc_info_len == 0)
772 else if (vcc_info_len < 0) {
773 fprintf(stderr, "%s: ", prog);
777 perror("Internal error");
780 fprintf(stderr, "Not an ATM device\n");
783 perror("ioctl (AIOCINFO)");
790 * Sort the VCC information
792 qsort((void *) vcc_info,
793 vcc_info_len / sizeof(struct air_vcc_rsp),
794 sizeof(struct air_vcc_rsp),
798 * Display the VCC statistics
800 vcc_info_base = vcc_info;
801 for (; vcc_info_len >= sizeof(struct air_vcc_rsp);
802 vcc_info_len-=sizeof(struct air_vcc_rsp),
804 if (vpi != -1 && vcc_info->avp_vpi != vpi)
806 if (vci != -1 && vcc_info->avp_vci != vci)
808 print_vcc_stats(vcc_info);
810 UM_FREE(vcc_info_base);
815 * Process VCC information command
818 * atm show VCC [<interface-name> [<vpi> [<vci>] | PVC | SVC]]
821 * argc number of remaining arguments to command
822 * argv pointer to remaining argument strings
823 * cmdp pointer to command description
830 show_vcc(int argc, char **argv, struct cmd *cmdp)
833 int vpi = -1, vci = -1, show_pvc = 0, show_svc = 0;
834 char *cp, *intf = NULL;
835 struct air_vcc_rsp *vcc_info, *vcc_info_base;
838 * Validate interface name
841 if (strlen(argv[0]) > IFNAMSIZ - 1) {
842 fprintf(stderr, "%s: Illegal interface name\n",
854 if (strcasecmp(argv[0], "pvc"))
856 else if (strcasecmp(argv[0], "svc"))
859 vpi = strtol(argv[0], &cp, 0);
860 if ((*cp != '\0') || (vpi < 0) ||
862 fprintf(stderr, "%s: Invalid VPI value\n", prog);
873 vci = strtol(argv[0], &cp, 0);
874 if ((*cp != '\0') || (vci <= 0) || (vci >= 1 << 16)) {
875 fprintf(stderr, "%s: Invalid VCI value\n",
883 * Get VCC information
885 vcc_info_len = get_vcc_info(intf, &vcc_info);
886 if (vcc_info_len == 0)
888 else if (vcc_info_len < 0) {
889 fprintf(stderr, "%s: ", prog);
893 perror("Internal error");
896 fprintf(stderr, "Not an ATM device\n");
899 perror("ioctl (AIOCINFO)");
906 * Sort the VCC information
908 qsort((void *) vcc_info,
909 vcc_info_len/sizeof(struct air_vcc_rsp),
910 sizeof(struct air_vcc_rsp),
914 * Display the VCC information
916 vcc_info_base = vcc_info;
917 for (; vcc_info_len >= sizeof(struct air_vcc_rsp);
918 vcc_info_len-=sizeof(struct air_vcc_rsp),
920 if (vpi != -1 && vcc_info->avp_vpi != vpi)
922 if (vci != -1 && vcc_info->avp_vci != vci)
924 if (show_pvc && vcc_info->avp_type & VCC_PVC)
926 if (show_svc && vcc_info->avp_type & VCC_SVC)
928 print_vcc_info(vcc_info);
930 UM_FREE(vcc_info_base);
935 * Process version command
941 * argc number of remaining arguments to command
942 * argv pointer to remaining argument strings
943 * cmdp pointer to command description
950 show_version(int argc, char **argv, struct cmd *cmdp)
952 int buf_len = sizeof(struct air_version_rsp);
953 struct atminfreq air;
954 struct air_version_rsp *ver_info, *ver_info_base;
957 * Get network interface information from the kernel
959 air.air_opcode = AIOCS_INF_VER;
960 buf_len = do_info_ioctl(&air, buf_len);
962 fprintf(stderr, "%s: ", prog);
966 perror("Internal error");
969 fprintf(stderr, "Not an ATM device\n");
972 perror("ioctl (AIOCINFO)");
979 * Print the network interface information
981 ver_info_base = ver_info =
982 (struct air_version_rsp *) air.air_buf_addr;
983 for (; buf_len >= sizeof(struct air_version_rsp); ver_info++,
984 buf_len -= sizeof(struct air_version_rsp)) {
985 print_version_info(ver_info);
987 UM_FREE(ver_info_base);
992 * Comparison function for qsort
995 * p1 pointer to the first VCC response
996 * p2 pointer to the second VCC response
999 * int a number less than, greater than, or equal to zero,
1000 * depending on whether *p1 is less than, greater than, or
1005 vcc_compare(const void *p1, const void *p2)
1008 struct air_vcc_rsp *c1, *c2;
1010 c1 = (struct air_vcc_rsp *) p1;
1011 c2 = (struct air_vcc_rsp *) p2;
1014 * Compare the interface names
1016 rc = strcmp(c1->avp_intf, c2->avp_intf);
1021 * Compare the VPI values
1023 rc = c1->avp_vpi - c2->avp_vpi;
1028 * Compare the VCI values
1030 rc = c1->avp_vci - c2->avp_vci;
1037 rc = c1->avp_type - c2->avp_type;
1043 * Comparison function for qsort
1046 * p1 pointer to the first VCC response
1047 * p2 pointer to the second VCC response
1050 * int a number less than, greater than, or equal to zero,
1051 * depending on whether *p1 is less than, greater than, or
1056 ip_vcc_compare(const void *p1, const void *p2)
1059 struct air_ip_vcc_rsp *c1, *c2;
1061 c1 = (struct air_ip_vcc_rsp *) p1;
1062 c2 = (struct air_ip_vcc_rsp *) p2;
1065 * Compare the interface names
1067 rc = strcmp(c1->aip_intf, c2->aip_intf);
1072 * Compare the VPI values
1074 rc = c1->aip_vpi - c2->aip_vpi;
1079 * Compare the VCI values
1081 rc = c1->aip_vci - c2->aip_vci;
1087 * Comparison function for qsort
1090 * p1 pointer to the first ARP or IP map entry
1091 * p2 pointer to the second ARP or IP map entry
1094 * int a number less than, greater than, or equal to zero,
1095 * depending on whether *p1 is less than, greater than, or
1100 arp_compare(const void *p1, const void *p2)
1103 struct air_arp_rsp *c1, *c2;
1104 struct sockaddr_in *sin1, *sin2;
1106 c1 = (struct air_arp_rsp *) p1;
1107 c2 = (struct air_arp_rsp *) p2;
1108 sin1 = (struct sockaddr_in *) &c1->aap_arp_addr;
1109 sin2 = (struct sockaddr_in *) &c2->aap_arp_addr;
1112 * Compare the IP addresses
1114 if ((rc = sin1->sin_family - sin2->sin_family) != 0)
1116 if ((rc = sin1->sin_addr.s_addr - sin2->sin_addr.s_addr) != 0)
1120 * Compare the ATM addresses
1122 if ((rc = c1->aap_addr.address_format - c2->aap_addr.address_format) != 0)
1124 if ((rc = c1->aap_addr.address_length - c2->aap_addr.address_length) != 0)
1126 switch(c1->aap_addr.address_format) {
1130 case T_ATM_ENDSYS_ADDR:
1131 rc = bcmp((caddr_t)c1->aap_addr.address,
1132 (caddr_t)c2->aap_addr.address,
1133 sizeof(Atm_addr_nsap));
1135 case T_ATM_E164_ADDR:
1136 rc = bcmp((caddr_t)c1->aap_addr.address,
1137 (caddr_t)c2->aap_addr.address,
1138 sizeof(Atm_addr_e164));
1140 case T_ATM_SPANS_ADDR:
1141 rc = bcmp((caddr_t)c1->aap_addr.address,
1142 (caddr_t)c2->aap_addr.address,
1143 sizeof(Atm_addr_spans));