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 5*9f1fc992Sss * Common Development and Distribution License (the "License"). 6*9f1fc992Sss * 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 */ 21*9f1fc992Sss 227c478bd9Sstevel@tonic-gate /* 23*9f1fc992Sss * Copyright 2006 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 #if !defined(__i386) 627c478bd9Sstevel@tonic-gate struct ofw_net_types { 637c478bd9Sstevel@tonic-gate char *n_name; /* OFW network media name */ 647c478bd9Sstevel@tonic-gate int n_type; /* IFT */ 657c478bd9Sstevel@tonic-gate } ofw_types[] = { 667c478bd9Sstevel@tonic-gate { "atm", IFT_ATM }, 677c478bd9Sstevel@tonic-gate { "ethernet", IFT_ETHER }, 687c478bd9Sstevel@tonic-gate { "fddi", IFT_FDDI }, 697c478bd9Sstevel@tonic-gate { "token-ring", IFT_ISO88025 }, 707c478bd9Sstevel@tonic-gate { "ipib", IFT_IB } 717c478bd9Sstevel@tonic-gate }; 727c478bd9Sstevel@tonic-gate #endif /* !__i386 */ 737c478bd9Sstevel@tonic-gate 74*9f1fc992Sss void mac_set_arp_timeout(unsigned int); 75*9f1fc992Sss 767c478bd9Sstevel@tonic-gate /* 777c478bd9Sstevel@tonic-gate * given the mac type, initialize the mac interface state. 787c478bd9Sstevel@tonic-gate */ 797c478bd9Sstevel@tonic-gate void 807c478bd9Sstevel@tonic-gate mac_init(char *bootdevicename) 817c478bd9Sstevel@tonic-gate { 827c478bd9Sstevel@tonic-gate int type = 0; 837c478bd9Sstevel@tonic-gate #if !defined(__i386) 847c478bd9Sstevel@tonic-gate static char *mtu_name = "max-frame-size"; 857c478bd9Sstevel@tonic-gate static char *chosen_net = "chosen-network-type"; 867c478bd9Sstevel@tonic-gate static char *supported_net = "supported-network-types"; 877c478bd9Sstevel@tonic-gate static char *netiftype = "network-interface-type"; 88fa9e4066Sahrens pnode_t node; 897c478bd9Sstevel@tonic-gate char *wp, *media_type; 907c478bd9Sstevel@tonic-gate int len = 0, i; 917c478bd9Sstevel@tonic-gate #endif /* !__i386 */ 927c478bd9Sstevel@tonic-gate char tmpbuf[MAXNAMELEN]; 937c478bd9Sstevel@tonic-gate char devname[MAXNAMELEN]; 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate if (initialized) 967c478bd9Sstevel@tonic-gate return; 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate mac_state.mac_in_timeout = MAC_IN_TIMEOUT; 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate #ifdef DEBUG 1017c478bd9Sstevel@tonic-gate printf("mac_init: device path: %s\n", bootdevicename); 1027c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate if ((mac_state.mac_dev = prom_open(bootdevicename)) == 0) { 1057c478bd9Sstevel@tonic-gate (void) snprintf(tmpbuf, sizeof (tmpbuf), 1067c478bd9Sstevel@tonic-gate "Cannot prom_open network device %s.", bootdevicename); 1077c478bd9Sstevel@tonic-gate prom_panic(tmpbuf); 1087c478bd9Sstevel@tonic-gate } 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate #if !defined(__i386) 1117c478bd9Sstevel@tonic-gate (void) prom_devname_from_pathname(bootdevicename, devname); 1127c478bd9Sstevel@tonic-gate #else 1137c478bd9Sstevel@tonic-gate (void) strcpy(devname, bootdevicename); 1147c478bd9Sstevel@tonic-gate #endif /* !__i386 */ 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate #ifdef DEBUG 1177c478bd9Sstevel@tonic-gate printf("mac_init: Network device name: %s\n", devname); 1187c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate #if !defined(__i386) 1217c478bd9Sstevel@tonic-gate /* 1227c478bd9Sstevel@tonic-gate * Ask the prom for our MTU and media type. "chosen-network-type" 1237c478bd9Sstevel@tonic-gate * is of the form of "<network type>,<speed (Mbps)>,<connector type>, 1247c478bd9Sstevel@tonic-gate * <duplex mode>: e.g.: "ethernet,100,rj45,full" 1257c478bd9Sstevel@tonic-gate */ 1267c478bd9Sstevel@tonic-gate node = prom_finddevice(devname); 1277c478bd9Sstevel@tonic-gate if (node != OBP_NONODE && node != OBP_BADNODE) { 1287c478bd9Sstevel@tonic-gate if (prom_getproplen(node, mtu_name) == sizeof (ihandle_t)) { 1297c478bd9Sstevel@tonic-gate (void) prom_getprop(node, mtu_name, 1307c478bd9Sstevel@tonic-gate (caddr_t)&mac_state.mac_mtu); 1317c478bd9Sstevel@tonic-gate } 1327c478bd9Sstevel@tonic-gate bzero(tmpbuf, sizeof (tmpbuf)); 1337c478bd9Sstevel@tonic-gate /* 1347c478bd9Sstevel@tonic-gate * The following order of looking for properties is 1357c478bd9Sstevel@tonic-gate * from FWARC 2002/345. 1367c478bd9Sstevel@tonic-gate */ 1377c478bd9Sstevel@tonic-gate if ((len = prom_getproplen(node, netiftype)) > 0 && 1387c478bd9Sstevel@tonic-gate len < sizeof (tmpbuf)) { 1397c478bd9Sstevel@tonic-gate (void) prom_getprop(node, netiftype, tmpbuf); 1407c478bd9Sstevel@tonic-gate } else if ((len = prom_getproplen(node, chosen_net)) > 0 && 1417c478bd9Sstevel@tonic-gate len < sizeof (tmpbuf)) { 1427c478bd9Sstevel@tonic-gate (void) prom_getprop(node, chosen_net, tmpbuf); 1437c478bd9Sstevel@tonic-gate } else if ((len = prom_getproplen(node, supported_net)) > 0 && 1447c478bd9Sstevel@tonic-gate len < sizeof (tmpbuf)) { 1457c478bd9Sstevel@tonic-gate (void) prom_getprop(node, supported_net, tmpbuf); 1467c478bd9Sstevel@tonic-gate } 1477c478bd9Sstevel@tonic-gate media_type = NULL; 1487c478bd9Sstevel@tonic-gate if (len > 0) { 1497c478bd9Sstevel@tonic-gate if ((wp = strstr(tmpbuf, ",")) != NULL) 1507c478bd9Sstevel@tonic-gate *wp = '\0'; 1517c478bd9Sstevel@tonic-gate media_type = tmpbuf; 1527c478bd9Sstevel@tonic-gate } 1537c478bd9Sstevel@tonic-gate if (media_type != NULL) { 1547c478bd9Sstevel@tonic-gate #ifdef DEBUG 1557c478bd9Sstevel@tonic-gate printf("mac_init: Media type: %s\n", media_type); 1567c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 1577c478bd9Sstevel@tonic-gate for (i = 0; i < sizeof (ofw_types) / 1587c478bd9Sstevel@tonic-gate sizeof (struct ofw_net_types); i++) { 1597c478bd9Sstevel@tonic-gate if (strcmp(ofw_types[i].n_name, 1607c478bd9Sstevel@tonic-gate media_type) == 0) { 1617c478bd9Sstevel@tonic-gate type = ofw_types[i].n_type; 1627c478bd9Sstevel@tonic-gate break; 1637c478bd9Sstevel@tonic-gate } 1647c478bd9Sstevel@tonic-gate } 1657c478bd9Sstevel@tonic-gate } 1667c478bd9Sstevel@tonic-gate } 1677c478bd9Sstevel@tonic-gate #else 1687c478bd9Sstevel@tonic-gate type = IFT_ETHER; /* default to ethernet */ 1697c478bd9Sstevel@tonic-gate #endif /* !__i386 */ 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate switch (type) { 1727c478bd9Sstevel@tonic-gate case IFT_ATM: 1737c478bd9Sstevel@tonic-gate /* 1747c478bd9Sstevel@tonic-gate * ATM is currently treated mostly like ethernet, 1757c478bd9Sstevel@tonic-gate * with the exception that the MTU is most likely 1767c478bd9Sstevel@tonic-gate * different. 1777c478bd9Sstevel@tonic-gate */ 1787c478bd9Sstevel@tonic-gate mac_state.mac_type = IFT_ATM; 1797c478bd9Sstevel@tonic-gate mac_state.mac_arp_timeout = ATM_ARP_TIMEOUT; 1807c478bd9Sstevel@tonic-gate mac_state.mac_in_timeout = ATM_IN_TIMEOUT; 1817c478bd9Sstevel@tonic-gate if (mac_state.mac_mtu == 0) 1827c478bd9Sstevel@tonic-gate mac_state.mac_mtu = ATMSIZE; 1837c478bd9Sstevel@tonic-gate mac_state.mac_addr_len = sizeof (ether_addr_t); 1847c478bd9Sstevel@tonic-gate mac_state.mac_addr_buf = bkmem_alloc(mac_state.mac_addr_len); 1857c478bd9Sstevel@tonic-gate if (mac_state.mac_addr_buf == NULL) 1867c478bd9Sstevel@tonic-gate prom_panic("mac_init: Cannot allocate memory."); 1877c478bd9Sstevel@tonic-gate if (prom_getmacaddr(mac_state.mac_dev, 1887c478bd9Sstevel@tonic-gate (caddr_t)mac_state.mac_addr_buf) != 0) 1897c478bd9Sstevel@tonic-gate prom_panic("mac_init: Cannot obtain MAC address."); 1907c478bd9Sstevel@tonic-gate mac_state.mac_arp = ether_arp; 1917c478bd9Sstevel@tonic-gate mac_state.mac_rarp = ether_revarp; 1927c478bd9Sstevel@tonic-gate mac_state.mac_header_len = ether_header_len; 1937c478bd9Sstevel@tonic-gate mac_state.mac_input = ether_input; 1947c478bd9Sstevel@tonic-gate mac_state.mac_output = ether_output; 1957c478bd9Sstevel@tonic-gate break; 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate case IFT_FDDI: 1987c478bd9Sstevel@tonic-gate /* 1997c478bd9Sstevel@tonic-gate * FDDI is currently treated mostly like ethernet, 2007c478bd9Sstevel@tonic-gate * with the exception that the MTU is most likely 2017c478bd9Sstevel@tonic-gate * different. 2027c478bd9Sstevel@tonic-gate */ 2037c478bd9Sstevel@tonic-gate mac_state.mac_type = IFT_FDDI; 2047c478bd9Sstevel@tonic-gate mac_state.mac_arp_timeout = FDDI_ARP_TIMEOUT; 2057c478bd9Sstevel@tonic-gate mac_state.mac_in_timeout = FDDI_IN_TIMEOUT; 2067c478bd9Sstevel@tonic-gate if (mac_state.mac_mtu == 0) 2077c478bd9Sstevel@tonic-gate mac_state.mac_mtu = FDDISIZE; 2087c478bd9Sstevel@tonic-gate mac_state.mac_addr_len = sizeof (ether_addr_t); 2097c478bd9Sstevel@tonic-gate mac_state.mac_addr_buf = bkmem_alloc(mac_state.mac_addr_len); 2107c478bd9Sstevel@tonic-gate if (mac_state.mac_addr_buf == NULL) 2117c478bd9Sstevel@tonic-gate prom_panic("mac_init: Cannot allocate memory."); 2127c478bd9Sstevel@tonic-gate if (prom_getmacaddr(mac_state.mac_dev, 2137c478bd9Sstevel@tonic-gate (caddr_t)mac_state.mac_addr_buf) != 0) 2147c478bd9Sstevel@tonic-gate prom_panic("mac_init: Cannot obtain MAC address."); 2157c478bd9Sstevel@tonic-gate mac_state.mac_arp = ether_arp; 2167c478bd9Sstevel@tonic-gate mac_state.mac_rarp = ether_revarp; 2177c478bd9Sstevel@tonic-gate mac_state.mac_header_len = ether_header_len; 2187c478bd9Sstevel@tonic-gate mac_state.mac_input = ether_input; 2197c478bd9Sstevel@tonic-gate mac_state.mac_output = ether_output; 2207c478bd9Sstevel@tonic-gate break; 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate case IFT_ISO88025: 2237c478bd9Sstevel@tonic-gate /* 2247c478bd9Sstevel@tonic-gate * Token ring is currently treated mostly like ethernet, 2257c478bd9Sstevel@tonic-gate * with the exception that the MTU is most likely different. 2267c478bd9Sstevel@tonic-gate */ 2277c478bd9Sstevel@tonic-gate mac_state.mac_type = IFT_ISO88025; 2287c478bd9Sstevel@tonic-gate mac_state.mac_arp_timeout = TOKEN_ARP_TIMEOUT; 2297c478bd9Sstevel@tonic-gate mac_state.mac_in_timeout = TOKEN_IN_TIMEOUT; 2307c478bd9Sstevel@tonic-gate if (mac_state.mac_mtu == 0) 2317c478bd9Sstevel@tonic-gate mac_state.mac_mtu = TOKENSIZE; 2327c478bd9Sstevel@tonic-gate mac_state.mac_addr_len = sizeof (ether_addr_t); 2337c478bd9Sstevel@tonic-gate mac_state.mac_addr_buf = bkmem_alloc(mac_state.mac_addr_len); 2347c478bd9Sstevel@tonic-gate if (mac_state.mac_addr_buf == NULL) 2357c478bd9Sstevel@tonic-gate prom_panic("mac_init: Cannot allocate memory."); 2367c478bd9Sstevel@tonic-gate if (prom_getmacaddr(mac_state.mac_dev, 2377c478bd9Sstevel@tonic-gate (caddr_t)mac_state.mac_addr_buf) != 0) 2387c478bd9Sstevel@tonic-gate prom_panic("mac_init: Cannot obtain MAC address."); 2397c478bd9Sstevel@tonic-gate mac_state.mac_arp = ether_arp; 2407c478bd9Sstevel@tonic-gate mac_state.mac_rarp = ether_revarp; 2417c478bd9Sstevel@tonic-gate mac_state.mac_header_len = ether_header_len; 2427c478bd9Sstevel@tonic-gate mac_state.mac_input = ether_input; 2437c478bd9Sstevel@tonic-gate mac_state.mac_output = ether_output; 2447c478bd9Sstevel@tonic-gate break; 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate case IFT_IB: 2477c478bd9Sstevel@tonic-gate mac_state.mac_type = IFT_IB; 2487c478bd9Sstevel@tonic-gate ibd_init(); 2497c478bd9Sstevel@tonic-gate break; 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate case IFT_ETHER: 2527c478bd9Sstevel@tonic-gate /* FALLTHRU - default to ethernet */ 2537c478bd9Sstevel@tonic-gate default: 2547c478bd9Sstevel@tonic-gate mac_state.mac_type = IFT_ETHER; 2557c478bd9Sstevel@tonic-gate mac_state.mac_mtu = ETHERSIZE; 2567c478bd9Sstevel@tonic-gate mac_state.mac_arp_timeout = ETHER_ARP_TIMEOUT; 2577c478bd9Sstevel@tonic-gate mac_state.mac_in_timeout = ETHER_IN_TIMEOUT; 2587c478bd9Sstevel@tonic-gate if (mac_state.mac_mtu == 0) 2597c478bd9Sstevel@tonic-gate mac_state.mac_mtu = ETHERSIZE; 2607c478bd9Sstevel@tonic-gate mac_state.mac_addr_len = sizeof (ether_addr_t); 2617c478bd9Sstevel@tonic-gate mac_state.mac_addr_buf = bkmem_alloc(mac_state.mac_addr_len); 2627c478bd9Sstevel@tonic-gate if (mac_state.mac_addr_buf == NULL) 2637c478bd9Sstevel@tonic-gate prom_panic("mac_init: Cannot allocate memory."); 2647c478bd9Sstevel@tonic-gate if (prom_getmacaddr(mac_state.mac_dev, 2657c478bd9Sstevel@tonic-gate (caddr_t)mac_state.mac_addr_buf) != 0) 2667c478bd9Sstevel@tonic-gate prom_panic("mac_init: Cannot obtain MAC address."); 2677c478bd9Sstevel@tonic-gate mac_state.mac_arp = ether_arp; 2687c478bd9Sstevel@tonic-gate mac_state.mac_rarp = ether_revarp; 2697c478bd9Sstevel@tonic-gate mac_state.mac_header_len = ether_header_len; 2707c478bd9Sstevel@tonic-gate mac_state.mac_input = ether_input; 2717c478bd9Sstevel@tonic-gate mac_state.mac_output = ether_output; 2727c478bd9Sstevel@tonic-gate break; 2737c478bd9Sstevel@tonic-gate } 2747c478bd9Sstevel@tonic-gate 2757c478bd9Sstevel@tonic-gate mac_state.mac_buf = bkmem_alloc(mac_state.mac_mtu); 2767c478bd9Sstevel@tonic-gate if (mac_state.mac_buf == NULL) 2777c478bd9Sstevel@tonic-gate prom_panic("mac_init: Cannot allocate netbuf memory."); 2787c478bd9Sstevel@tonic-gate else 2797c478bd9Sstevel@tonic-gate initialized = B_TRUE; 2807c478bd9Sstevel@tonic-gate } 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate void 2837c478bd9Sstevel@tonic-gate mac_fini() 2847c478bd9Sstevel@tonic-gate { 2857c478bd9Sstevel@tonic-gate if (mac_state.mac_addr_buf != NULL) { 2867c478bd9Sstevel@tonic-gate bkmem_free((caddr_t)mac_state.mac_addr_buf, 2877c478bd9Sstevel@tonic-gate mac_state.mac_addr_len); 2887c478bd9Sstevel@tonic-gate mac_state.mac_addr_buf = NULL; 2897c478bd9Sstevel@tonic-gate } 2907c478bd9Sstevel@tonic-gate if (mac_state.mac_buf != NULL) { 2917c478bd9Sstevel@tonic-gate bkmem_free(mac_state.mac_buf, mac_state.mac_mtu); 2927c478bd9Sstevel@tonic-gate mac_state.mac_buf = NULL; 2937c478bd9Sstevel@tonic-gate } 2947c478bd9Sstevel@tonic-gate (void) prom_close(mac_state.mac_dev); 2957c478bd9Sstevel@tonic-gate initialized = B_FALSE; 2967c478bd9Sstevel@tonic-gate } 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate /* MAC layer specific socket initialization */ 2997c478bd9Sstevel@tonic-gate void 3007c478bd9Sstevel@tonic-gate mac_socket_init(struct inetboot_socket *isp) 3017c478bd9Sstevel@tonic-gate { 3027c478bd9Sstevel@tonic-gate isp->input[MEDIA_LVL] = mac_state.mac_input; 3037c478bd9Sstevel@tonic-gate isp->output[MEDIA_LVL] = mac_state.mac_output; 3047c478bd9Sstevel@tonic-gate isp->close[MEDIA_LVL] = NULL; 3057c478bd9Sstevel@tonic-gate isp->headerlen[MEDIA_LVL] = mac_state.mac_header_len; 3067c478bd9Sstevel@tonic-gate isp->in_timeout = mac_state.mac_in_timeout; 3077c478bd9Sstevel@tonic-gate } 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate /* 3107c478bd9Sstevel@tonic-gate * Add an entry to the ARP table. All values in table are network order. 3117c478bd9Sstevel@tonic-gate * No checking is done to determine whether there's duplicates. 3127c478bd9Sstevel@tonic-gate */ 3137c478bd9Sstevel@tonic-gate void 3147c478bd9Sstevel@tonic-gate mac_set_arp(struct in_addr *ip, void *hp, int hl) 3157c478bd9Sstevel@tonic-gate { 3167c478bd9Sstevel@tonic-gate atable[arp_index].ia.s_addr = ip->s_addr; 3177c478bd9Sstevel@tonic-gate bcopy(hp, (char *)atable[arp_index].ha, hl); 3187c478bd9Sstevel@tonic-gate atable[arp_index].hl = hl; 3197c478bd9Sstevel@tonic-gate arp_index++; 3207c478bd9Sstevel@tonic-gate if (arp_index >= ARP_TABLE_SIZE) 3217c478bd9Sstevel@tonic-gate arp_index = 0; 3227c478bd9Sstevel@tonic-gate } 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate /* 3257c478bd9Sstevel@tonic-gate * Retrieve an entry from the ARP table using network-order IP address as 3267c478bd9Sstevel@tonic-gate * search criteria. HW address buffer is filled in up to hl in len. (make 3277c478bd9Sstevel@tonic-gate * sure the buffer is big enough given the mac type) 3287c478bd9Sstevel@tonic-gate * 3297c478bd9Sstevel@tonic-gate * Returns TRUE if successful, FALSE otherwise. Will wait timeout milliseconds 3307c478bd9Sstevel@tonic-gate * for a response. 3317c478bd9Sstevel@tonic-gate */ 3327c478bd9Sstevel@tonic-gate int 3337c478bd9Sstevel@tonic-gate mac_get_arp(struct in_addr *ip, void *hp, int hl, uint32_t timeout) 3347c478bd9Sstevel@tonic-gate { 3357c478bd9Sstevel@tonic-gate int i, result; 3367c478bd9Sstevel@tonic-gate 3377c478bd9Sstevel@tonic-gate for (i = 0; i < ARP_TABLE_SIZE; i++) { 3387c478bd9Sstevel@tonic-gate if (ip->s_addr == atable[i].ia.s_addr) { 3397c478bd9Sstevel@tonic-gate bcopy((char *)atable[i].ha, hp, hl); 3407c478bd9Sstevel@tonic-gate return (TRUE); 3417c478bd9Sstevel@tonic-gate } 3427c478bd9Sstevel@tonic-gate } 3437c478bd9Sstevel@tonic-gate 3447c478bd9Sstevel@tonic-gate /* Not found. ARP for it. */ 3457c478bd9Sstevel@tonic-gate bzero(hp, hl); 3467c478bd9Sstevel@tonic-gate result = mac_state.mac_arp(ip, hp, timeout); 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate if (result) { 3497c478bd9Sstevel@tonic-gate /* Cool - add it to the arp table */ 3507c478bd9Sstevel@tonic-gate mac_set_arp(ip, hp, hl); 3517c478bd9Sstevel@tonic-gate } 3527c478bd9Sstevel@tonic-gate return (result); 3537c478bd9Sstevel@tonic-gate } 3547c478bd9Sstevel@tonic-gate 3557c478bd9Sstevel@tonic-gate int 3567c478bd9Sstevel@tonic-gate mac_get_mtu(void) 3577c478bd9Sstevel@tonic-gate { 3587c478bd9Sstevel@tonic-gate if (!initialized) 3597c478bd9Sstevel@tonic-gate return (-1); 3607c478bd9Sstevel@tonic-gate else 3617c478bd9Sstevel@tonic-gate return (mac_state.mac_mtu); 3627c478bd9Sstevel@tonic-gate } 3637c478bd9Sstevel@tonic-gate 3647c478bd9Sstevel@tonic-gate int 3657c478bd9Sstevel@tonic-gate mac_get_dev(void) 3667c478bd9Sstevel@tonic-gate { 3677c478bd9Sstevel@tonic-gate if (!initialized) 3687c478bd9Sstevel@tonic-gate return (-1); 3697c478bd9Sstevel@tonic-gate else 3707c478bd9Sstevel@tonic-gate return (mac_state.mac_dev); 3717c478bd9Sstevel@tonic-gate } 3727c478bd9Sstevel@tonic-gate 3737c478bd9Sstevel@tonic-gate uint8_t * 3747c478bd9Sstevel@tonic-gate mac_get_addr_buf(void) 3757c478bd9Sstevel@tonic-gate { 3767c478bd9Sstevel@tonic-gate if (!initialized) 3777c478bd9Sstevel@tonic-gate return (NULL); 3787c478bd9Sstevel@tonic-gate else 3797c478bd9Sstevel@tonic-gate return (mac_state.mac_addr_buf); 3807c478bd9Sstevel@tonic-gate } 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate int 3837c478bd9Sstevel@tonic-gate mac_get_addr_len(void) 3847c478bd9Sstevel@tonic-gate { 3857c478bd9Sstevel@tonic-gate if (!initialized) 3867c478bd9Sstevel@tonic-gate return (-1); 3877c478bd9Sstevel@tonic-gate else 3887c478bd9Sstevel@tonic-gate return (mac_state.mac_addr_len); 3897c478bd9Sstevel@tonic-gate } 3907c478bd9Sstevel@tonic-gate 3917c478bd9Sstevel@tonic-gate int 3927c478bd9Sstevel@tonic-gate mac_get_type(void) 3937c478bd9Sstevel@tonic-gate { 3947c478bd9Sstevel@tonic-gate if (!initialized) 3957c478bd9Sstevel@tonic-gate return (-1); 3967c478bd9Sstevel@tonic-gate else 3977c478bd9Sstevel@tonic-gate return (mac_state.mac_type); 3987c478bd9Sstevel@tonic-gate } 3997c478bd9Sstevel@tonic-gate 400*9f1fc992Sss void 401*9f1fc992Sss mac_set_arp_timeout(unsigned int timeout) 402*9f1fc992Sss { 403*9f1fc992Sss mac_state.mac_arp_timeout = 404*9f1fc992Sss timeout; 405*9f1fc992Sss } 406*9f1fc992Sss 4077c478bd9Sstevel@tonic-gate int 4087c478bd9Sstevel@tonic-gate mac_get_arp_timeout(void) 4097c478bd9Sstevel@tonic-gate { 4107c478bd9Sstevel@tonic-gate if (!initialized) 4117c478bd9Sstevel@tonic-gate return (-1); 4127c478bd9Sstevel@tonic-gate else 4137c478bd9Sstevel@tonic-gate return (mac_state.mac_arp_timeout); 4147c478bd9Sstevel@tonic-gate } 4157c478bd9Sstevel@tonic-gate 4167c478bd9Sstevel@tonic-gate int 4177c478bd9Sstevel@tonic-gate mac_get_hdr_len(void) 4187c478bd9Sstevel@tonic-gate { 4197c478bd9Sstevel@tonic-gate if (!initialized) 4207c478bd9Sstevel@tonic-gate return (-1); 4217c478bd9Sstevel@tonic-gate else 4227c478bd9Sstevel@tonic-gate return (mac_state.mac_header_len(NULL)); 4237c478bd9Sstevel@tonic-gate } 4247c478bd9Sstevel@tonic-gate 4257c478bd9Sstevel@tonic-gate int 4267c478bd9Sstevel@tonic-gate mac_call_arp(struct in_addr *addr, void *buf, uint32_t timeout) 4277c478bd9Sstevel@tonic-gate { 4287c478bd9Sstevel@tonic-gate return (mac_state.mac_arp(addr, buf, timeout)); 4297c478bd9Sstevel@tonic-gate } 4307c478bd9Sstevel@tonic-gate 4317c478bd9Sstevel@tonic-gate void 4327c478bd9Sstevel@tonic-gate mac_call_rarp(void) 4337c478bd9Sstevel@tonic-gate { 4347c478bd9Sstevel@tonic-gate mac_state.mac_rarp(); 4357c478bd9Sstevel@tonic-gate } 4367c478bd9Sstevel@tonic-gate 4377c478bd9Sstevel@tonic-gate /* 4387c478bd9Sstevel@tonic-gate * Map a IFT_ type to an RFC 1700 arp hwtype. 4397c478bd9Sstevel@tonic-gate */ 4407c478bd9Sstevel@tonic-gate uint8_t 4417c478bd9Sstevel@tonic-gate mac_arp_type(uint8_t ift_type) 4427c478bd9Sstevel@tonic-gate { 4437c478bd9Sstevel@tonic-gate uint8_t arptype; 4447c478bd9Sstevel@tonic-gate 4457c478bd9Sstevel@tonic-gate switch (ift_type) { 4467c478bd9Sstevel@tonic-gate case IFT_ISO88025: 4477c478bd9Sstevel@tonic-gate arptype = 4; /* token ring */ 4487c478bd9Sstevel@tonic-gate break; 4497c478bd9Sstevel@tonic-gate case IFT_ATM: 4507c478bd9Sstevel@tonic-gate arptype = 16; /* ATM */ 4517c478bd9Sstevel@tonic-gate break; 4527c478bd9Sstevel@tonic-gate case IFT_FDDI: 4537c478bd9Sstevel@tonic-gate arptype = 18; /* Fiber Channel */ 4547c478bd9Sstevel@tonic-gate break; 4557c478bd9Sstevel@tonic-gate case IFT_IB: 4567c478bd9Sstevel@tonic-gate arptype = 32; /* Infiniband */ 4577c478bd9Sstevel@tonic-gate break; 4587c478bd9Sstevel@tonic-gate case IFT_ETHER: 4597c478bd9Sstevel@tonic-gate /* FALLTHRU */ 4607c478bd9Sstevel@tonic-gate default: 4617c478bd9Sstevel@tonic-gate arptype = 1; /* default to ethernet */ 4627c478bd9Sstevel@tonic-gate break; 4637c478bd9Sstevel@tonic-gate } 4647c478bd9Sstevel@tonic-gate return (arptype); 4657c478bd9Sstevel@tonic-gate } 466