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