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