1 /* $NetBSD: arp.h,v 1.11 2015/07/09 10:15:34 roy Exp $ */ 2 3 /* 4 * dhcpcd - DHCP client daemon 5 * Copyright (c) 2006-2015 Roy Marples <roy@marples.name> 6 * All rights reserved 7 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30 #ifndef ARP_H 31 #define ARP_H 32 33 /* ARP timings from RFC5227 */ 34 #define PROBE_WAIT 1 35 #define PROBE_NUM 3 36 #define PROBE_MIN 1 37 #define PROBE_MAX 2 38 #define ANNOUNCE_WAIT 2 39 #define ANNOUNCE_NUM 2 40 #define ANNOUNCE_INTERVAL 2 41 #define MAX_CONFLICTS 10 42 #define RATE_LIMIT_INTERVAL 60 43 #define DEFEND_INTERVAL 10 44 45 #include "dhcpcd.h" 46 47 struct arp_msg { 48 uint16_t op; 49 unsigned char sha[HWADDR_LEN]; 50 struct in_addr sip; 51 unsigned char tha[HWADDR_LEN]; 52 struct in_addr tip; 53 }; 54 55 struct arp_state { 56 TAILQ_ENTRY(arp_state) next; 57 struct interface *iface; 58 59 void (*probed_cb)(struct arp_state *); 60 void (*announced_cb)(struct arp_state *); 61 void (*conflicted_cb)(struct arp_state *, const struct arp_msg *); 62 void (*free_cb)(struct arp_state *); 63 64 struct in_addr addr; 65 int probes; 66 int claims; 67 struct in_addr failed; 68 }; 69 TAILQ_HEAD(arp_statehead, arp_state); 70 71 struct iarp_state { 72 int fd; 73 struct arp_statehead arp_states; 74 }; 75 76 #define ARP_STATE(ifp) \ 77 ((struct iarp_state *)(ifp)->if_data[IF_DATA_ARP]) 78 #define ARP_CSTATE(ifp) \ 79 ((const struct iarp_state *)(ifp)->if_data[IF_DATA_ARP]) 80 81 #ifdef INET 82 void arp_report_conflicted(const struct arp_state *, const struct arp_msg *); 83 void arp_announce(struct arp_state *); 84 void arp_probe(struct arp_state *); 85 struct arp_state *arp_new(struct interface *, const struct in_addr *); 86 void arp_cancel(struct arp_state *); 87 void arp_free(struct arp_state *); 88 void arp_free_but(struct arp_state *); 89 struct arp_state *arp_find(struct interface *, const struct in_addr *); 90 void arp_close(struct interface *); 91 92 void arp_handleifa(int, struct interface *, const struct in_addr *, int); 93 #else 94 #define arp_close(a) {} 95 #endif 96 #endif 97