17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 59f1fc992Sss146032 * Common Development and Distribution License (the "License"). 69f1fc992Sss146032 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 219f1fc992Sss146032 227c478bd9Sstevel@tonic-gate /* 23*4a634bb8Sga159272 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/types.h> 307c478bd9Sstevel@tonic-gate #include <socket_impl.h> 317c478bd9Sstevel@tonic-gate #include <socket_inet.h> 327c478bd9Sstevel@tonic-gate #include <sys/param.h> 337c478bd9Sstevel@tonic-gate #include <sys/time.h> 347c478bd9Sstevel@tonic-gate #include <sys/socket.h> 357c478bd9Sstevel@tonic-gate #include <net/if.h> 367c478bd9Sstevel@tonic-gate #include <net/if_arp.h> 377c478bd9Sstevel@tonic-gate #include <net/if_types.h> 387c478bd9Sstevel@tonic-gate #include <netinet/in_systm.h> 397c478bd9Sstevel@tonic-gate #include <netinet/in.h> 407c478bd9Sstevel@tonic-gate #include <netinet/if_ether.h> 417c478bd9Sstevel@tonic-gate #include <sys/promif.h> 427c478bd9Sstevel@tonic-gate #include <sys/prom_plat.h> 437c478bd9Sstevel@tonic-gate #include <sys/salib.h> 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate #include "mac.h" 467c478bd9Sstevel@tonic-gate #include "mac_impl.h" 477c478bd9Sstevel@tonic-gate #include "atm_inet.h" 487c478bd9Sstevel@tonic-gate #include "ethernet_inet.h" 497c478bd9Sstevel@tonic-gate #include "fddi_inet.h" 507c478bd9Sstevel@tonic-gate #include "token_inet.h" 517c478bd9Sstevel@tonic-gate #include "ibd_inet.h" 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate /* 547c478bd9Sstevel@tonic-gate * MAC layer interface 557c478bd9Sstevel@tonic-gate */ 567c478bd9Sstevel@tonic-gate boolean_t initialized; /* Boolean state */ 577c478bd9Sstevel@tonic-gate struct mac_type mac_state; 587c478bd9Sstevel@tonic-gate int arp_index; /* current arp table index */ 597c478bd9Sstevel@tonic-gate static struct arptable atable[ARP_TABLE_SIZE]; 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate struct ofw_net_types { 627c478bd9Sstevel@tonic-gate char *n_name; /* OFW network media name */ 637c478bd9Sstevel@tonic-gate int n_type; /* IFT */ 647c478bd9Sstevel@tonic-gate } ofw_types[] = { 657c478bd9Sstevel@tonic-gate { "atm", IFT_ATM }, 667c478bd9Sstevel@tonic-gate { "ethernet", IFT_ETHER }, 677c478bd9Sstevel@tonic-gate { "fddi", IFT_FDDI }, 687c478bd9Sstevel@tonic-gate { "token-ring", IFT_ISO88025 }, 697c478bd9Sstevel@tonic-gate { "ipib", IFT_IB } 707c478bd9Sstevel@tonic-gate }; 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate /* 737c478bd9Sstevel@tonic-gate * given the mac type, initialize the mac interface state. 747c478bd9Sstevel@tonic-gate */ 757c478bd9Sstevel@tonic-gate void 767c478bd9Sstevel@tonic-gate mac_init(char *bootdevicename) 777c478bd9Sstevel@tonic-gate { 787c478bd9Sstevel@tonic-gate int type = 0; 797c478bd9Sstevel@tonic-gate static char *mtu_name = "max-frame-size"; 807c478bd9Sstevel@tonic-gate static char *chosen_net = "chosen-network-type"; 817c478bd9Sstevel@tonic-gate static char *supported_net = "supported-network-types"; 827c478bd9Sstevel@tonic-gate static char *netiftype = "network-interface-type"; 83fa9e4066Sahrens pnode_t node; 847c478bd9Sstevel@tonic-gate char *wp, *media_type; 857c478bd9Sstevel@tonic-gate int len = 0, i; 867c478bd9Sstevel@tonic-gate char tmpbuf[MAXNAMELEN]; 877c478bd9Sstevel@tonic-gate char devname[MAXNAMELEN]; 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate if (initialized) 907c478bd9Sstevel@tonic-gate return; 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate mac_state.mac_in_timeout = MAC_IN_TIMEOUT; 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate #ifdef DEBUG 957c478bd9Sstevel@tonic-gate printf("mac_init: device path: %s\n", bootdevicename); 967c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate if ((mac_state.mac_dev = prom_open(bootdevicename)) == 0) { 997c478bd9Sstevel@tonic-gate (void) snprintf(tmpbuf, sizeof (tmpbuf), 1007c478bd9Sstevel@tonic-gate "Cannot prom_open network device %s.", bootdevicename); 1017c478bd9Sstevel@tonic-gate prom_panic(tmpbuf); 1027c478bd9Sstevel@tonic-gate } 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate (void) prom_devname_from_pathname(bootdevicename, devname); 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate #ifdef DEBUG 1077c478bd9Sstevel@tonic-gate printf("mac_init: Network device name: %s\n", devname); 1087c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate /* 1117c478bd9Sstevel@tonic-gate * Ask the prom for our MTU and media type. "chosen-network-type" 1127c478bd9Sstevel@tonic-gate * is of the form of "<network type>,<speed (Mbps)>,<connector type>, 1137c478bd9Sstevel@tonic-gate * <duplex mode>: e.g.: "ethernet,100,rj45,full" 1147c478bd9Sstevel@tonic-gate */ 1157c478bd9Sstevel@tonic-gate node = prom_finddevice(devname); 1167c478bd9Sstevel@tonic-gate if (node != OBP_NONODE && node != OBP_BADNODE) { 1177c478bd9Sstevel@tonic-gate if (prom_getproplen(node, mtu_name) == sizeof (ihandle_t)) { 1187c478bd9Sstevel@tonic-gate (void) prom_getprop(node, mtu_name, 1197c478bd9Sstevel@tonic-gate (caddr_t)&mac_state.mac_mtu); 1207c478bd9Sstevel@tonic-gate } 1217c478bd9Sstevel@tonic-gate bzero(tmpbuf, sizeof (tmpbuf)); 1227c478bd9Sstevel@tonic-gate /* 1237c478bd9Sstevel@tonic-gate * The following order of looking for properties is 1247c478bd9Sstevel@tonic-gate * from FWARC 2002/345. 1257c478bd9Sstevel@tonic-gate */ 1267c478bd9Sstevel@tonic-gate if ((len = prom_getproplen(node, netiftype)) > 0 && 1277c478bd9Sstevel@tonic-gate len < sizeof (tmpbuf)) { 1287c478bd9Sstevel@tonic-gate (void) prom_getprop(node, netiftype, tmpbuf); 1297c478bd9Sstevel@tonic-gate } else if ((len = prom_getproplen(node, chosen_net)) > 0 && 1307c478bd9Sstevel@tonic-gate len < sizeof (tmpbuf)) { 1317c478bd9Sstevel@tonic-gate (void) prom_getprop(node, chosen_net, tmpbuf); 1327c478bd9Sstevel@tonic-gate } else if ((len = prom_getproplen(node, supported_net)) > 0 && 1337c478bd9Sstevel@tonic-gate len < sizeof (tmpbuf)) { 1347c478bd9Sstevel@tonic-gate (void) prom_getprop(node, supported_net, tmpbuf); 1357c478bd9Sstevel@tonic-gate } 1367c478bd9Sstevel@tonic-gate media_type = NULL; 1377c478bd9Sstevel@tonic-gate if (len > 0) { 1387c478bd9Sstevel@tonic-gate if ((wp = strstr(tmpbuf, ",")) != NULL) 1397c478bd9Sstevel@tonic-gate *wp = '\0'; 1407c478bd9Sstevel@tonic-gate media_type = tmpbuf; 1417c478bd9Sstevel@tonic-gate } 1427c478bd9Sstevel@tonic-gate if (media_type != NULL) { 1437c478bd9Sstevel@tonic-gate #ifdef DEBUG 1447c478bd9Sstevel@tonic-gate printf("mac_init: Media type: %s\n", media_type); 1457c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 1467c478bd9Sstevel@tonic-gate for (i = 0; i < sizeof (ofw_types) / 1477c478bd9Sstevel@tonic-gate sizeof (struct ofw_net_types); i++) { 1487c478bd9Sstevel@tonic-gate if (strcmp(ofw_types[i].n_name, 1497c478bd9Sstevel@tonic-gate media_type) == 0) { 1507c478bd9Sstevel@tonic-gate type = ofw_types[i].n_type; 1517c478bd9Sstevel@tonic-gate break; 1527c478bd9Sstevel@tonic-gate } 1537c478bd9Sstevel@tonic-gate } 1547c478bd9Sstevel@tonic-gate } 1557c478bd9Sstevel@tonic-gate } 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate switch (type) { 1587c478bd9Sstevel@tonic-gate case IFT_ATM: 1597c478bd9Sstevel@tonic-gate /* 1607c478bd9Sstevel@tonic-gate * ATM is currently treated mostly like ethernet, 1617c478bd9Sstevel@tonic-gate * with the exception that the MTU is most likely 1627c478bd9Sstevel@tonic-gate * different. 1637c478bd9Sstevel@tonic-gate */ 1647c478bd9Sstevel@tonic-gate mac_state.mac_type = IFT_ATM; 1657c478bd9Sstevel@tonic-gate mac_state.mac_arp_timeout = ATM_ARP_TIMEOUT; 1667c478bd9Sstevel@tonic-gate mac_state.mac_in_timeout = ATM_IN_TIMEOUT; 1677c478bd9Sstevel@tonic-gate if (mac_state.mac_mtu == 0) 1687c478bd9Sstevel@tonic-gate mac_state.mac_mtu = ATMSIZE; 1697c478bd9Sstevel@tonic-gate mac_state.mac_addr_len = sizeof (ether_addr_t); 1707c478bd9Sstevel@tonic-gate mac_state.mac_addr_buf = bkmem_alloc(mac_state.mac_addr_len); 1717c478bd9Sstevel@tonic-gate if (mac_state.mac_addr_buf == NULL) 1727c478bd9Sstevel@tonic-gate prom_panic("mac_init: Cannot allocate memory."); 1737c478bd9Sstevel@tonic-gate if (prom_getmacaddr(mac_state.mac_dev, 1747c478bd9Sstevel@tonic-gate (caddr_t)mac_state.mac_addr_buf) != 0) 1757c478bd9Sstevel@tonic-gate prom_panic("mac_init: Cannot obtain MAC address."); 1767c478bd9Sstevel@tonic-gate mac_state.mac_arp = ether_arp; 1777c478bd9Sstevel@tonic-gate mac_state.mac_rarp = ether_revarp; 1787c478bd9Sstevel@tonic-gate mac_state.mac_header_len = ether_header_len; 1797c478bd9Sstevel@tonic-gate mac_state.mac_input = ether_input; 1807c478bd9Sstevel@tonic-gate mac_state.mac_output = ether_output; 1817c478bd9Sstevel@tonic-gate break; 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate case IFT_FDDI: 1847c478bd9Sstevel@tonic-gate /* 1857c478bd9Sstevel@tonic-gate * FDDI is currently treated mostly like ethernet, 1867c478bd9Sstevel@tonic-gate * with the exception that the MTU is most likely 1877c478bd9Sstevel@tonic-gate * different. 1887c478bd9Sstevel@tonic-gate */ 1897c478bd9Sstevel@tonic-gate mac_state.mac_type = IFT_FDDI; 1907c478bd9Sstevel@tonic-gate mac_state.mac_arp_timeout = FDDI_ARP_TIMEOUT; 1917c478bd9Sstevel@tonic-gate mac_state.mac_in_timeout = FDDI_IN_TIMEOUT; 1927c478bd9Sstevel@tonic-gate if (mac_state.mac_mtu == 0) 1937c478bd9Sstevel@tonic-gate mac_state.mac_mtu = FDDISIZE; 1947c478bd9Sstevel@tonic-gate mac_state.mac_addr_len = sizeof (ether_addr_t); 1957c478bd9Sstevel@tonic-gate mac_state.mac_addr_buf = bkmem_alloc(mac_state.mac_addr_len); 1967c478bd9Sstevel@tonic-gate if (mac_state.mac_addr_buf == NULL) 1977c478bd9Sstevel@tonic-gate prom_panic("mac_init: Cannot allocate memory."); 1987c478bd9Sstevel@tonic-gate if (prom_getmacaddr(mac_state.mac_dev, 1997c478bd9Sstevel@tonic-gate (caddr_t)mac_state.mac_addr_buf) != 0) 2007c478bd9Sstevel@tonic-gate prom_panic("mac_init: Cannot obtain MAC address."); 2017c478bd9Sstevel@tonic-gate mac_state.mac_arp = ether_arp; 2027c478bd9Sstevel@tonic-gate mac_state.mac_rarp = ether_revarp; 2037c478bd9Sstevel@tonic-gate mac_state.mac_header_len = ether_header_len; 2047c478bd9Sstevel@tonic-gate mac_state.mac_input = ether_input; 2057c478bd9Sstevel@tonic-gate mac_state.mac_output = ether_output; 2067c478bd9Sstevel@tonic-gate break; 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate case IFT_ISO88025: 2097c478bd9Sstevel@tonic-gate /* 2107c478bd9Sstevel@tonic-gate * Token ring is currently treated mostly like ethernet, 2117c478bd9Sstevel@tonic-gate * with the exception that the MTU is most likely different. 2127c478bd9Sstevel@tonic-gate */ 2137c478bd9Sstevel@tonic-gate mac_state.mac_type = IFT_ISO88025; 2147c478bd9Sstevel@tonic-gate mac_state.mac_arp_timeout = TOKEN_ARP_TIMEOUT; 2157c478bd9Sstevel@tonic-gate mac_state.mac_in_timeout = TOKEN_IN_TIMEOUT; 2167c478bd9Sstevel@tonic-gate if (mac_state.mac_mtu == 0) 2177c478bd9Sstevel@tonic-gate mac_state.mac_mtu = TOKENSIZE; 2187c478bd9Sstevel@tonic-gate mac_state.mac_addr_len = sizeof (ether_addr_t); 2197c478bd9Sstevel@tonic-gate mac_state.mac_addr_buf = bkmem_alloc(mac_state.mac_addr_len); 2207c478bd9Sstevel@tonic-gate if (mac_state.mac_addr_buf == NULL) 2217c478bd9Sstevel@tonic-gate prom_panic("mac_init: Cannot allocate memory."); 2227c478bd9Sstevel@tonic-gate if (prom_getmacaddr(mac_state.mac_dev, 2237c478bd9Sstevel@tonic-gate (caddr_t)mac_state.mac_addr_buf) != 0) 2247c478bd9Sstevel@tonic-gate prom_panic("mac_init: Cannot obtain MAC address."); 2257c478bd9Sstevel@tonic-gate mac_state.mac_arp = ether_arp; 2267c478bd9Sstevel@tonic-gate mac_state.mac_rarp = ether_revarp; 2277c478bd9Sstevel@tonic-gate mac_state.mac_header_len = ether_header_len; 2287c478bd9Sstevel@tonic-gate mac_state.mac_input = ether_input; 2297c478bd9Sstevel@tonic-gate mac_state.mac_output = ether_output; 2307c478bd9Sstevel@tonic-gate break; 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate case IFT_IB: 2337c478bd9Sstevel@tonic-gate mac_state.mac_type = IFT_IB; 2347c478bd9Sstevel@tonic-gate ibd_init(); 2357c478bd9Sstevel@tonic-gate break; 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate case IFT_ETHER: 2387c478bd9Sstevel@tonic-gate /* FALLTHRU - default to ethernet */ 2397c478bd9Sstevel@tonic-gate default: 2407c478bd9Sstevel@tonic-gate mac_state.mac_type = IFT_ETHER; 2417c478bd9Sstevel@tonic-gate mac_state.mac_mtu = ETHERSIZE; 2427c478bd9Sstevel@tonic-gate mac_state.mac_arp_timeout = ETHER_ARP_TIMEOUT; 2437c478bd9Sstevel@tonic-gate mac_state.mac_in_timeout = ETHER_IN_TIMEOUT; 2447c478bd9Sstevel@tonic-gate if (mac_state.mac_mtu == 0) 2457c478bd9Sstevel@tonic-gate mac_state.mac_mtu = ETHERSIZE; 2467c478bd9Sstevel@tonic-gate mac_state.mac_addr_len = sizeof (ether_addr_t); 2477c478bd9Sstevel@tonic-gate mac_state.mac_addr_buf = bkmem_alloc(mac_state.mac_addr_len); 2487c478bd9Sstevel@tonic-gate if (mac_state.mac_addr_buf == NULL) 2497c478bd9Sstevel@tonic-gate prom_panic("mac_init: Cannot allocate memory."); 2507c478bd9Sstevel@tonic-gate if (prom_getmacaddr(mac_state.mac_dev, 2517c478bd9Sstevel@tonic-gate (caddr_t)mac_state.mac_addr_buf) != 0) 2527c478bd9Sstevel@tonic-gate prom_panic("mac_init: Cannot obtain MAC address."); 2537c478bd9Sstevel@tonic-gate mac_state.mac_arp = ether_arp; 2547c478bd9Sstevel@tonic-gate mac_state.mac_rarp = ether_revarp; 2557c478bd9Sstevel@tonic-gate mac_state.mac_header_len = ether_header_len; 2567c478bd9Sstevel@tonic-gate mac_state.mac_input = ether_input; 2577c478bd9Sstevel@tonic-gate mac_state.mac_output = ether_output; 2587c478bd9Sstevel@tonic-gate break; 2597c478bd9Sstevel@tonic-gate } 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate mac_state.mac_buf = bkmem_alloc(mac_state.mac_mtu); 2627c478bd9Sstevel@tonic-gate if (mac_state.mac_buf == NULL) 2637c478bd9Sstevel@tonic-gate prom_panic("mac_init: Cannot allocate netbuf memory."); 2647c478bd9Sstevel@tonic-gate else 2657c478bd9Sstevel@tonic-gate initialized = B_TRUE; 2667c478bd9Sstevel@tonic-gate } 2677c478bd9Sstevel@tonic-gate 2687c478bd9Sstevel@tonic-gate void 2697c478bd9Sstevel@tonic-gate mac_fini() 2707c478bd9Sstevel@tonic-gate { 2717c478bd9Sstevel@tonic-gate if (mac_state.mac_addr_buf != NULL) { 2727c478bd9Sstevel@tonic-gate bkmem_free((caddr_t)mac_state.mac_addr_buf, 2737c478bd9Sstevel@tonic-gate mac_state.mac_addr_len); 2747c478bd9Sstevel@tonic-gate mac_state.mac_addr_buf = NULL; 2757c478bd9Sstevel@tonic-gate } 2767c478bd9Sstevel@tonic-gate if (mac_state.mac_buf != NULL) { 2777c478bd9Sstevel@tonic-gate bkmem_free(mac_state.mac_buf, mac_state.mac_mtu); 2787c478bd9Sstevel@tonic-gate mac_state.mac_buf = NULL; 2797c478bd9Sstevel@tonic-gate } 2807c478bd9Sstevel@tonic-gate (void) prom_close(mac_state.mac_dev); 2817c478bd9Sstevel@tonic-gate initialized = B_FALSE; 2827c478bd9Sstevel@tonic-gate } 2837c478bd9Sstevel@tonic-gate 2847c478bd9Sstevel@tonic-gate /* MAC layer specific socket initialization */ 2857c478bd9Sstevel@tonic-gate void 2867c478bd9Sstevel@tonic-gate mac_socket_init(struct inetboot_socket *isp) 2877c478bd9Sstevel@tonic-gate { 2887c478bd9Sstevel@tonic-gate isp->input[MEDIA_LVL] = mac_state.mac_input; 2897c478bd9Sstevel@tonic-gate isp->output[MEDIA_LVL] = mac_state.mac_output; 2907c478bd9Sstevel@tonic-gate isp->close[MEDIA_LVL] = NULL; 2917c478bd9Sstevel@tonic-gate isp->headerlen[MEDIA_LVL] = mac_state.mac_header_len; 2927c478bd9Sstevel@tonic-gate isp->in_timeout = mac_state.mac_in_timeout; 2937c478bd9Sstevel@tonic-gate } 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate /* 2967c478bd9Sstevel@tonic-gate * Add an entry to the ARP table. All values in table are network order. 2977c478bd9Sstevel@tonic-gate * No checking is done to determine whether there's duplicates. 2987c478bd9Sstevel@tonic-gate */ 2997c478bd9Sstevel@tonic-gate void 3007c478bd9Sstevel@tonic-gate mac_set_arp(struct in_addr *ip, void *hp, int hl) 3017c478bd9Sstevel@tonic-gate { 3027c478bd9Sstevel@tonic-gate atable[arp_index].ia.s_addr = ip->s_addr; 3037c478bd9Sstevel@tonic-gate bcopy(hp, (char *)atable[arp_index].ha, hl); 3047c478bd9Sstevel@tonic-gate atable[arp_index].hl = hl; 3057c478bd9Sstevel@tonic-gate arp_index++; 3067c478bd9Sstevel@tonic-gate if (arp_index >= ARP_TABLE_SIZE) 3077c478bd9Sstevel@tonic-gate arp_index = 0; 3087c478bd9Sstevel@tonic-gate } 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate /* 3117c478bd9Sstevel@tonic-gate * Retrieve an entry from the ARP table using network-order IP address as 3127c478bd9Sstevel@tonic-gate * search criteria. HW address buffer is filled in up to hl in len. (make 3137c478bd9Sstevel@tonic-gate * sure the buffer is big enough given the mac type) 3147c478bd9Sstevel@tonic-gate * 3157c478bd9Sstevel@tonic-gate * Returns TRUE if successful, FALSE otherwise. Will wait timeout milliseconds 3167c478bd9Sstevel@tonic-gate * for a response. 3177c478bd9Sstevel@tonic-gate */ 3187c478bd9Sstevel@tonic-gate int 3197c478bd9Sstevel@tonic-gate mac_get_arp(struct in_addr *ip, void *hp, int hl, uint32_t timeout) 3207c478bd9Sstevel@tonic-gate { 3217c478bd9Sstevel@tonic-gate int i, result; 3227c478bd9Sstevel@tonic-gate 3237c478bd9Sstevel@tonic-gate for (i = 0; i < ARP_TABLE_SIZE; i++) { 3247c478bd9Sstevel@tonic-gate if (ip->s_addr == atable[i].ia.s_addr) { 3257c478bd9Sstevel@tonic-gate bcopy((char *)atable[i].ha, hp, hl); 3267c478bd9Sstevel@tonic-gate return (TRUE); 3277c478bd9Sstevel@tonic-gate } 3287c478bd9Sstevel@tonic-gate } 3297c478bd9Sstevel@tonic-gate 3307c478bd9Sstevel@tonic-gate /* Not found. ARP for it. */ 3317c478bd9Sstevel@tonic-gate bzero(hp, hl); 3327c478bd9Sstevel@tonic-gate result = mac_state.mac_arp(ip, hp, timeout); 3337c478bd9Sstevel@tonic-gate 3347c478bd9Sstevel@tonic-gate if (result) { 3357c478bd9Sstevel@tonic-gate /* Cool - add it to the arp table */ 3367c478bd9Sstevel@tonic-gate mac_set_arp(ip, hp, hl); 3377c478bd9Sstevel@tonic-gate } 3387c478bd9Sstevel@tonic-gate return (result); 3397c478bd9Sstevel@tonic-gate } 3407c478bd9Sstevel@tonic-gate 3417c478bd9Sstevel@tonic-gate int 3427c478bd9Sstevel@tonic-gate mac_get_mtu(void) 3437c478bd9Sstevel@tonic-gate { 3447c478bd9Sstevel@tonic-gate if (!initialized) 3457c478bd9Sstevel@tonic-gate return (-1); 3467c478bd9Sstevel@tonic-gate else 3477c478bd9Sstevel@tonic-gate return (mac_state.mac_mtu); 3487c478bd9Sstevel@tonic-gate } 3497c478bd9Sstevel@tonic-gate 3507c478bd9Sstevel@tonic-gate int 3517c478bd9Sstevel@tonic-gate mac_get_dev(void) 3527c478bd9Sstevel@tonic-gate { 3537c478bd9Sstevel@tonic-gate if (!initialized) 3547c478bd9Sstevel@tonic-gate return (-1); 3557c478bd9Sstevel@tonic-gate else 3567c478bd9Sstevel@tonic-gate return (mac_state.mac_dev); 3577c478bd9Sstevel@tonic-gate } 3587c478bd9Sstevel@tonic-gate 3597c478bd9Sstevel@tonic-gate uint8_t * 3607c478bd9Sstevel@tonic-gate mac_get_addr_buf(void) 3617c478bd9Sstevel@tonic-gate { 3627c478bd9Sstevel@tonic-gate if (!initialized) 3637c478bd9Sstevel@tonic-gate return (NULL); 3647c478bd9Sstevel@tonic-gate else 3657c478bd9Sstevel@tonic-gate return (mac_state.mac_addr_buf); 3667c478bd9Sstevel@tonic-gate } 3677c478bd9Sstevel@tonic-gate 3687c478bd9Sstevel@tonic-gate int 3697c478bd9Sstevel@tonic-gate mac_get_addr_len(void) 3707c478bd9Sstevel@tonic-gate { 3717c478bd9Sstevel@tonic-gate if (!initialized) 3727c478bd9Sstevel@tonic-gate return (-1); 3737c478bd9Sstevel@tonic-gate else 3747c478bd9Sstevel@tonic-gate return (mac_state.mac_addr_len); 3757c478bd9Sstevel@tonic-gate } 3767c478bd9Sstevel@tonic-gate 3777c478bd9Sstevel@tonic-gate int 3787c478bd9Sstevel@tonic-gate mac_get_type(void) 3797c478bd9Sstevel@tonic-gate { 3807c478bd9Sstevel@tonic-gate if (!initialized) 3817c478bd9Sstevel@tonic-gate return (-1); 3827c478bd9Sstevel@tonic-gate else 3837c478bd9Sstevel@tonic-gate return (mac_state.mac_type); 3847c478bd9Sstevel@tonic-gate } 3857c478bd9Sstevel@tonic-gate 3869f1fc992Sss146032 void 3879f1fc992Sss146032 mac_set_arp_timeout(unsigned int timeout) 3889f1fc992Sss146032 { 3899f1fc992Sss146032 mac_state.mac_arp_timeout = 3909f1fc992Sss146032 timeout; 3919f1fc992Sss146032 } 3929f1fc992Sss146032 3937c478bd9Sstevel@tonic-gate int 3947c478bd9Sstevel@tonic-gate mac_get_arp_timeout(void) 3957c478bd9Sstevel@tonic-gate { 3967c478bd9Sstevel@tonic-gate if (!initialized) 3977c478bd9Sstevel@tonic-gate return (-1); 3987c478bd9Sstevel@tonic-gate else 3997c478bd9Sstevel@tonic-gate return (mac_state.mac_arp_timeout); 4007c478bd9Sstevel@tonic-gate } 4017c478bd9Sstevel@tonic-gate 4027c478bd9Sstevel@tonic-gate int 4037c478bd9Sstevel@tonic-gate mac_get_hdr_len(void) 4047c478bd9Sstevel@tonic-gate { 4057c478bd9Sstevel@tonic-gate if (!initialized) 4067c478bd9Sstevel@tonic-gate return (-1); 4077c478bd9Sstevel@tonic-gate else 4087c478bd9Sstevel@tonic-gate return (mac_state.mac_header_len(NULL)); 4097c478bd9Sstevel@tonic-gate } 4107c478bd9Sstevel@tonic-gate 4117c478bd9Sstevel@tonic-gate int 4127c478bd9Sstevel@tonic-gate mac_call_arp(struct in_addr *addr, void *buf, uint32_t timeout) 4137c478bd9Sstevel@tonic-gate { 4147c478bd9Sstevel@tonic-gate return (mac_state.mac_arp(addr, buf, timeout)); 4157c478bd9Sstevel@tonic-gate } 4167c478bd9Sstevel@tonic-gate 4177c478bd9Sstevel@tonic-gate void 4187c478bd9Sstevel@tonic-gate mac_call_rarp(void) 4197c478bd9Sstevel@tonic-gate { 4207c478bd9Sstevel@tonic-gate mac_state.mac_rarp(); 4217c478bd9Sstevel@tonic-gate } 4227c478bd9Sstevel@tonic-gate 4237c478bd9Sstevel@tonic-gate /* 4247c478bd9Sstevel@tonic-gate * Map a IFT_ type to an RFC 1700 arp hwtype. 4257c478bd9Sstevel@tonic-gate */ 4267c478bd9Sstevel@tonic-gate uint8_t 4277c478bd9Sstevel@tonic-gate mac_arp_type(uint8_t ift_type) 4287c478bd9Sstevel@tonic-gate { 4297c478bd9Sstevel@tonic-gate uint8_t arptype; 4307c478bd9Sstevel@tonic-gate 4317c478bd9Sstevel@tonic-gate switch (ift_type) { 4327c478bd9Sstevel@tonic-gate case IFT_ISO88025: 4337c478bd9Sstevel@tonic-gate arptype = 4; /* token ring */ 4347c478bd9Sstevel@tonic-gate break; 4357c478bd9Sstevel@tonic-gate case IFT_ATM: 4367c478bd9Sstevel@tonic-gate arptype = 16; /* ATM */ 4377c478bd9Sstevel@tonic-gate break; 4387c478bd9Sstevel@tonic-gate case IFT_FDDI: 4397c478bd9Sstevel@tonic-gate arptype = 18; /* Fiber Channel */ 4407c478bd9Sstevel@tonic-gate break; 4417c478bd9Sstevel@tonic-gate case IFT_IB: 4427c478bd9Sstevel@tonic-gate arptype = 32; /* Infiniband */ 4437c478bd9Sstevel@tonic-gate break; 4447c478bd9Sstevel@tonic-gate case IFT_ETHER: 4457c478bd9Sstevel@tonic-gate /* FALLTHRU */ 4467c478bd9Sstevel@tonic-gate default: 4477c478bd9Sstevel@tonic-gate arptype = 1; /* default to ethernet */ 4487c478bd9Sstevel@tonic-gate break; 4497c478bd9Sstevel@tonic-gate } 4507c478bd9Sstevel@tonic-gate return (arptype); 4517c478bd9Sstevel@tonic-gate } 452