1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * dhcpcd - DHCP client daemon 4 * Copyright (c) 2006-2020 Roy Marples <roy@marples.name> 5 * All rights reserved 6 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #ifndef ARP_H 30 #define ARP_H 31 32 /* ARP timings from RFC5227 */ 33 #define PROBE_WAIT 1 34 #define PROBE_NUM 3 35 #define PROBE_MIN 1 36 #define PROBE_MAX 2 37 #define ANNOUNCE_WAIT 2 38 #define ANNOUNCE_NUM 2 39 #define ANNOUNCE_INTERVAL 2 40 #define MAX_CONFLICTS 10 41 #define RATE_LIMIT_INTERVAL 60 42 #define DEFEND_INTERVAL 10 43 44 #include "dhcpcd.h" 45 #include "if.h" 46 47 #ifdef IN_IFF_DUPLICATED 48 /* NetBSD gained RFC 5227 support in the kernel. 49 * This means dhcpcd doesn't need ARP except for ARPing support. */ 50 #if defined(__NetBSD_Version__) && __NetBSD_Version__ >= 799003900 51 #define KERNEL_RFC5227 52 #endif 53 #endif 54 55 struct arp_msg { 56 uint16_t op; 57 uint8_t sha[HWADDR_LEN]; 58 struct in_addr sip; 59 uint8_t tha[HWADDR_LEN]; 60 struct in_addr tip; 61 /* Frame header and sender to diagnose failures */ 62 uint8_t fsha[HWADDR_LEN]; 63 uint8_t ftha[HWADDR_LEN]; 64 }; 65 66 struct arp_state { 67 TAILQ_ENTRY(arp_state) next; 68 struct interface *iface; 69 70 void (*found_cb)(struct arp_state *, const struct arp_msg *); 71 void (*not_found_cb)(struct arp_state *); 72 void (*announced_cb)(struct arp_state *); 73 void (*defend_failed_cb)(struct arp_state *); 74 void (*free_cb)(struct arp_state *); 75 76 struct in_addr addr; 77 int probes; 78 int claims; 79 struct timespec defend; 80 }; 81 TAILQ_HEAD(arp_statehead, arp_state); 82 83 struct iarp_state { 84 struct interface *ifp; 85 int bpf_fd; 86 unsigned int bpf_flags; 87 struct arp_statehead arp_states; 88 }; 89 90 #define ARP_STATE(ifp) \ 91 ((struct iarp_state *)(ifp)->if_data[IF_DATA_ARP]) 92 #define ARP_CSTATE(ifp) \ 93 ((const struct iarp_state *)(ifp)->if_data[IF_DATA_ARP]) 94 95 #ifdef ARP 96 void arp_packet(struct interface *, uint8_t *, size_t); 97 struct arp_state *arp_new(struct interface *, const struct in_addr *); 98 void arp_change(struct arp_state *, const struct in_addr *); 99 void arp_probe(struct arp_state *); 100 void arp_announce(struct arp_state *); 101 void arp_announceaddr(struct dhcpcd_ctx *, const struct in_addr *); 102 void arp_ifannounceaddr(struct interface *, const struct in_addr *); 103 void arp_cancel(struct arp_state *); 104 struct arp_state * arp_find(struct interface *, const struct in_addr *); 105 void arp_free(struct arp_state *); 106 void arp_freeaddr(struct interface *, const struct in_addr *); 107 void arp_drop(struct interface *); 108 #endif /* ARP */ 109 #endif /* ARP_H */ 110