1*aca3beaaSApple OSS Distributions /* 2*aca3beaaSApple OSS Distributions * Copyright (c) 2009-2013 Apple Inc. All rights reserved. 3*aca3beaaSApple OSS Distributions * 4*aca3beaaSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*aca3beaaSApple OSS Distributions * 6*aca3beaaSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*aca3beaaSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*aca3beaaSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*aca3beaaSApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*aca3beaaSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*aca3beaaSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*aca3beaaSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*aca3beaaSApple OSS Distributions * terms of an Apple operating system software license agreement. 14*aca3beaaSApple OSS Distributions * 15*aca3beaaSApple OSS Distributions * Please obtain a copy of the License at 16*aca3beaaSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*aca3beaaSApple OSS Distributions * 18*aca3beaaSApple OSS Distributions * The Original Code and all software distributed under the License are 19*aca3beaaSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*aca3beaaSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*aca3beaaSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*aca3beaaSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*aca3beaaSApple OSS Distributions * Please see the License for the specific language governing rights and 24*aca3beaaSApple OSS Distributions * limitations under the License. 25*aca3beaaSApple OSS Distributions * 26*aca3beaaSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*aca3beaaSApple OSS Distributions */ 28*aca3beaaSApple OSS Distributions 29*aca3beaaSApple OSS Distributions #ifndef _NETINET_IN_ARP_H_ 30*aca3beaaSApple OSS Distributions #define _NETINET_IN_ARP_H_ 31*aca3beaaSApple OSS Distributions #ifdef KERNEL 32*aca3beaaSApple OSS Distributions #include <sys/kernel_types.h> 33*aca3beaaSApple OSS Distributions 34*aca3beaaSApple OSS Distributions struct sockaddr; 35*aca3beaaSApple OSS Distributions struct sockaddr_dl; 36*aca3beaaSApple OSS Distributions struct sockaddr_in; 37*aca3beaaSApple OSS Distributions 38*aca3beaaSApple OSS Distributions /*! 39*aca3beaaSApple OSS Distributions * @function inet_arp_lookup 40*aca3beaaSApple OSS Distributions * @discussion This function will check the routing table for a cached 41*aca3beaaSApple OSS Distributions * arp entry or trigger an arp query to resolve the ip address to a 42*aca3beaaSApple OSS Distributions * link-layer address. 43*aca3beaaSApple OSS Distributions * 44*aca3beaaSApple OSS Distributions * Arp entries are stored in the routing table. This function will 45*aca3beaaSApple OSS Distributions * lookup the ip destination in the routing table. If the 46*aca3beaaSApple OSS Distributions * destination requires forwarding to a gateway, the route of the 47*aca3beaaSApple OSS Distributions * gateway will be looked up. The route entry is inspected to 48*aca3beaaSApple OSS Distributions * determine if the link layer destination address is known. If 49*aca3beaaSApple OSS Distributions * unknown, the arp generation function for IP attached to the 50*aca3beaaSApple OSS Distributions * interface is called to create an arp request packet. 51*aca3beaaSApple OSS Distributions * @param interface The interface the packet is being sent on. 52*aca3beaaSApple OSS Distributions * @param ip_dest The ip destination of the packet. 53*aca3beaaSApple OSS Distributions * @param ll_dest On output, the link-layer destination. 54*aca3beaaSApple OSS Distributions * @param ll_dest_len The length of the buffer for ll_dest. 55*aca3beaaSApple OSS Distributions * @param hint Any routing hint passed down from the protocol. 56*aca3beaaSApple OSS Distributions * @param packet The packet being transmitted. 57*aca3beaaSApple OSS Distributions * @result May return an error such as EHOSTDOWN or ENETUNREACH. If 58*aca3beaaSApple OSS Distributions * this function returns EJUSTRETURN, the packet has been queued 59*aca3beaaSApple OSS Distributions * and will be sent when an arp response is received. If any other 60*aca3beaaSApple OSS Distributions * value is returned, the caller is responsible for disposing of 61*aca3beaaSApple OSS Distributions * the packet. 62*aca3beaaSApple OSS Distributions */ 63*aca3beaaSApple OSS Distributions #ifdef BSD_KERNEL_PRIVATE 64*aca3beaaSApple OSS Distributions extern boolean_t arp_is_entry_probing(route_t p_route); 65*aca3beaaSApple OSS Distributions extern errno_t arp_lookup_ip(ifnet_t interface, 66*aca3beaaSApple OSS Distributions const struct sockaddr_in *ip_dest, struct sockaddr_dl *ll_dest, 67*aca3beaaSApple OSS Distributions size_t ll_dest_len, route_t hint, mbuf_t packet); 68*aca3beaaSApple OSS Distributions #define inet_arp_lookup arp_lookup_ip 69*aca3beaaSApple OSS Distributions #else 70*aca3beaaSApple OSS Distributions extern errno_t inet_arp_lookup(ifnet_t interface, 71*aca3beaaSApple OSS Distributions const struct sockaddr_in *ip_dest, struct sockaddr_dl *ll_dest, 72*aca3beaaSApple OSS Distributions size_t ll_dest_len, route_t hint, mbuf_t packet); 73*aca3beaaSApple OSS Distributions #endif /* !BSD_KERNEL_PRIVATE */ 74*aca3beaaSApple OSS Distributions 75*aca3beaaSApple OSS Distributions /*! 76*aca3beaaSApple OSS Distributions * @function inet_arp_handle_input 77*aca3beaaSApple OSS Distributions * @discussion This function should be called by code that handles 78*aca3beaaSApple OSS Distributions * inbound arp packets. The caller should parse the ARP packet to 79*aca3beaaSApple OSS Distributions * pull out the operation and the relevant addresses. If a response 80*aca3beaaSApple OSS Distributions * is required, the proto_media_send_arp function will be called. 81*aca3beaaSApple OSS Distributions * 82*aca3beaaSApple OSS Distributions * This function will lookup the sender in the routing table and 83*aca3beaaSApple OSS Distributions * add an arp entry if necessary. Any queued packets waiting for 84*aca3beaaSApple OSS Distributions * the arp resolution will also be transmitted. 85*aca3beaaSApple OSS Distributions * @param interface The interface the packet was received on. 86*aca3beaaSApple OSS Distributions * @param arp_op The arp operation, ARPOP_REQUEST or ARPOP_REPLY 87*aca3beaaSApple OSS Distributions * @param sender_hw The sender hardware address from the arp payload. 88*aca3beaaSApple OSS Distributions * @param sender_ip The sender IP address from the arp payload. 89*aca3beaaSApple OSS Distributions * @param target_ip The target IP address from the arp payload. 90*aca3beaaSApple OSS Distributions * @result 0 on success or an errno error value on failure. 91*aca3beaaSApple OSS Distributions */ 92*aca3beaaSApple OSS Distributions #ifdef BSD_KERNEL_PRIVATE 93*aca3beaaSApple OSS Distributions extern errno_t arp_ip_handle_input(ifnet_t ifp, u_int16_t arpop, 94*aca3beaaSApple OSS Distributions const struct sockaddr_dl *sender_hw, const struct sockaddr_in *sender_ip, 95*aca3beaaSApple OSS Distributions const struct sockaddr_in *target_ip); 96*aca3beaaSApple OSS Distributions #define inet_arp_handle_input arp_ip_handle_input 97*aca3beaaSApple OSS Distributions #else 98*aca3beaaSApple OSS Distributions extern errno_t inet_arp_handle_input(ifnet_t ifp, u_int16_t arpop, 99*aca3beaaSApple OSS Distributions const struct sockaddr_dl *sender_hw, const struct sockaddr_in *sender_ip, 100*aca3beaaSApple OSS Distributions const struct sockaddr_in *target_ip); 101*aca3beaaSApple OSS Distributions #endif /* !BSD_KERNEL_PRIVATE */ 102*aca3beaaSApple OSS Distributions 103*aca3beaaSApple OSS Distributions /*! 104*aca3beaaSApple OSS Distributions * @function inet_arp_init_ifaddr 105*aca3beaaSApple OSS Distributions * @discussion This function should be called in two places, when an IP 106*aca3beaaSApple OSS Distributions * address is added and when the hardware address changes. This 107*aca3beaaSApple OSS Distributions * function will setup the ifaddr_t for use with the IP ARP 108*aca3beaaSApple OSS Distributions * functions. This function will also trigger the transmission of a 109*aca3beaaSApple OSS Distributions * gratuitous ARP packet. 110*aca3beaaSApple OSS Distributions * 111*aca3beaaSApple OSS Distributions * When the SIOCSIFADDR ioctl is handled, the data parameter will 112*aca3beaaSApple OSS Distributions * be an ifaddr_t. If this is an IP address, inet_arp_init_ifaddr 113*aca3beaaSApple OSS Distributions * should be called. This is usually performed in the protocol 114*aca3beaaSApple OSS Distributions * attachment's ioctl handler. 115*aca3beaaSApple OSS Distributions * 116*aca3beaaSApple OSS Distributions * When the event handler for the protocol attachment receives a 117*aca3beaaSApple OSS Distributions * KEV_DL_LINK_ADDRESS_CHANGED event, the event handler should call 118*aca3beaaSApple OSS Distributions * inet_arp_init_ifaddr for each interface ip address. 119*aca3beaaSApple OSS Distributions * 120*aca3beaaSApple OSS Distributions * For an example, see bsd/net/ether_inet_pr_module.c in xnu. 121*aca3beaaSApple OSS Distributions * Search for inet_arp_init_ifaddr. 122*aca3beaaSApple OSS Distributions * @param interface The interface the packet was received on. 123*aca3beaaSApple OSS Distributions * @param ipaddr The ip interface address. 124*aca3beaaSApple OSS Distributions */ 125*aca3beaaSApple OSS Distributions #ifdef BSD_KERNEL_PRIVATE 126*aca3beaaSApple OSS Distributions /* inet_arp_init_ifaddr is aliased to arp_ifinit (if_ether.h) */ 127*aca3beaaSApple OSS Distributions #define inet_arp_init_ifaddr arp_ifinit 128*aca3beaaSApple OSS Distributions #else 129*aca3beaaSApple OSS Distributions extern void inet_arp_init_ifaddr(ifnet_t interface, ifaddr_t ipaddr); 130*aca3beaaSApple OSS Distributions #endif /* !BSD_KERNEL_PRIVATE */ 131*aca3beaaSApple OSS Distributions 132*aca3beaaSApple OSS Distributions #ifdef BSD_KERNEL_PRIVATE 133*aca3beaaSApple OSS Distributions extern void arp_init(void); 134*aca3beaaSApple OSS Distributions extern void in_arpdrain(void *); 135*aca3beaaSApple OSS Distributions extern void arp_llreach_set_reachable(struct ifnet *, void *, unsigned int); 136*aca3beaaSApple OSS Distributions #endif /* BSD_KERNEL_PRIVATE */ 137*aca3beaaSApple OSS Distributions #endif /* KERNEL */ 138*aca3beaaSApple OSS Distributions #endif /* _NETINET_IN_ARP_H_ */ 139