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_subr.c,v 1.3.2.1 2000/07/01 06:02:14 ps Exp $
27 * @(#) $DragonFly: src/sbin/atm/atm/atm_subr.c,v 1.2 2003/06/17 04:27:32 dillon Exp $
31 * User configuration and display program
32 * --------------------------------------
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_ioctl.h>
48 #include <arpa/inet.h>
59 * Table entry definition
68 * Table to translate vendor codes to ASCII
71 { VENDAPI_UNKNOWN, "Unknown" },
72 { VENDAPI_FORE_1, "Fore" },
73 { VENDAPI_ENI_1, "ENI" },
79 * Table to translate adapter codes to ASCII
81 tbl_ent adapter_types[] = {
82 { DEV_UNKNOWN, "Unknown" },
83 { DEV_FORE_SBA200E, "SBA-200E" },
84 { DEV_FORE_SBA200, "SBA-200" },
85 { DEV_FORE_PCA200E, "PCA-200E" },
86 { DEV_ENI_155P, "ENI-155p" },
91 * Table to translate medium types to ASCII
93 tbl_ent media_types[] = {
94 { MEDIA_UNKNOWN, "Unknown" },
95 { MEDIA_TAXI_100, "100 Mbps 4B/5B" },
96 { MEDIA_TAXI_140, "140 Mbps 4B/5B" },
97 { MEDIA_OC3C, "OC-3c" },
98 { MEDIA_OC12C, "OC-12c" },
99 { MEDIA_UTP155, "155 Mbps UTP" },
104 * Table to translate bus types to ASCII
106 tbl_ent bus_types[] = {
107 { BUS_UNKNOWN, "Unknown" },
108 { BUS_SBUS_B16, "SBus" },
109 { BUS_SBUS_B32, "SBus" },
116 * Get interface vendor name
118 * Return a character string with a vendor name, given a vendor code.
124 * char * pointer to a string with the vendor name
133 for(i=0; vendors[i].name; i++) {
134 if (vendors[i].type == vendor)
135 return(vendors[i].name);
149 * char * pointer to a string with the adapter type
158 for(i=0; adapter_types[i].name; i++) {
159 if (adapter_types[i].type == dev)
160 return(adapter_types[i].name);
168 * Get communication medium type
174 * char * pointer to a string with the name of the medium
178 get_media_type(media)
183 for(i=0; media_types[i].name; i++) {
184 if (media_types[i].type == media)
185 return(media_types[i].name);
199 * char * pointer to a string with the bus type
208 for(i=0; bus_types[i].name; i++) {
209 if (bus_types[i].type == bus)
210 return(bus_types[i].name);
220 * Get a string giving the adapter's vendor and type.
223 * intf interface name
226 * char * pointer to a string identifying the adapter
230 get_adapter_name(intf)
234 struct atminfreq air;
235 struct air_cfg_rsp *cfg;
236 static char name[256];
241 UM_ZERO(&air, sizeof(air));
242 UM_ZERO(name, sizeof(name));
245 * Get configuration information from the kernel
247 air.air_opcode = AIOCS_INF_CFG;
248 strcpy(air.air_cfg_intf, intf);
249 buf_len = do_info_ioctl(&air, sizeof(struct air_cfg_rsp));
250 if (buf_len < sizeof(struct air_cfg_rsp))
252 cfg = (struct air_cfg_rsp *) air.air_buf_addr;
255 * Build a string describing the adapter
257 strcpy(name, get_vendor(cfg->acp_vendor));
259 strcat(name, get_adapter(cfg->acp_device));
268 * Format a MAC address into a string
271 * addr pointer to a MAC address
274 * the address of a string representing the MAC address
278 format_mac_addr(addr)
281 static char str[256];
284 * Check for null pointer
290 * Clear the returned string
292 UM_ZERO(str, sizeof(str));
297 sprintf(str, "%02x:%02x:%02x:%02x:%02x:%02x",
310 * Parse an IP prefix designation in the form nnn.nnn.nnn.nnn/mm
313 * cp pointer to prefix designation string
314 * op pointer to a pair of in_addrs for the result
318 * -1 prefix was invalid
322 parse_ip_prefix(cp, op)
328 struct in_addr ip_addr;
330 static u_long masks[33] = {
367 * Find the slash that marks the start of the mask
369 mp = strchr(cp, '/');
376 * Convert the IP-address part of the prefix
378 ip_addr.s_addr = inet_addr(cp);
379 if (ip_addr.s_addr == -1)
383 * Set the default mask length
385 if (IN_CLASSA(ntohl(ip_addr.s_addr)))
387 else if (IN_CLASSB(ntohl(ip_addr.s_addr)))
389 else if (IN_CLASSC(ntohl(ip_addr.s_addr)))
395 * Get the mask length
399 if (len < 1 || len > 32)
404 * Select the mask and copy the IP address into the
405 * result buffer, ANDing it with the mask
407 op[1].s_addr = htonl(masks[len]);
408 op[0].s_addr = ip_addr.s_addr & op[1].s_addr;
415 * Compress a list of IP network prefixes
418 * ipp pointer to list of IP address/mask pairs
422 * length of compressed list
426 compress_prefix_list(ipp, ilen)
431 struct in_addr *ip1, *ip2, *m1, *m2;
434 * Figure out how many pairs there are
436 n = ilen / (sizeof(struct in_addr) * 2);
439 * Check each pair of address/mask pairs to make sure
440 * none contains the other
442 for (i = 0; i < n; i++) {
447 * If we've already eliminated this address,
450 if (ip1->s_addr == 0)
454 * Try all possible second members of the pair
456 for (j = i + 1; j < n; j++) {
461 * If we've already eliminated the second
462 * address, just skip the checks
464 if (ip2->s_addr == 0)
468 * Compare the address/mask pairs
470 if (m1->s_addr == m2->s_addr) {
474 if (ip1->s_addr == ip2->s_addr) {
478 } else if (ntohl(m1->s_addr) <
483 if ((ip2->s_addr & m1->s_addr) ==
492 if ((ip1->s_addr & m2->s_addr) ==
503 * Now pull up the list, eliminating zeroed entries
505 for (i = 0, j = 0; i < n; i++) {
510 if (ip1->s_addr != 0) {
519 return(j * sizeof(struct in_addr) * 2);
524 * Make sure a user-supplied parameter is a valid network interface
527 * When a socket call fails, print an error message and exit
530 * nif pointer to network interface name
533 * none exits if name is not valid
537 check_netif_name(nif)
543 * Look up the name in the kernel
545 rc = verify_nif_name(nif);
555 } else if (rc == 0) {
559 fprintf(stderr, "%s: Invalid network interface name %s\n",
563 * Error performing IOCTL
565 fprintf(stderr, "%s: ", prog);
569 perror("Internal error");
572 fprintf(stderr, "%s is not an ATM device\n",
576 perror("ioctl (AIOCINFO)");
586 * Socket error handler
588 * When a socket call fails, print an error message and exit
591 * err an errno describing the error
601 fprintf(stderr, "%s: ", prog);
605 case EPROTONOSUPPORT:
606 fprintf(stderr, "ATM protocol support not loaded\n");