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