1 /* SPDX-License-Identifier: BSD-2-Clause */
3 * dhcpcd - DHCP client daemon
4 * Copyright (c) 2006-2021 Roy Marples <roy@marples.name>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
32 /* ARP timings from RFC5227 */
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
48 #ifdef IN_IFF_DUPLICATED
49 /* NetBSD gained RFC 5227 support in the kernel.
50 * This means dhcpcd doesn't need ARP except for ARPing support
51 * and ARP announcing an address. */
52 #if defined(__NetBSD_Version__) && __NetBSD_Version__ >= 799003900
53 #define KERNEL_RFC5227
59 uint8_t sha[HWADDR_LEN];
61 uint8_t tha[HWADDR_LEN];
63 /* Frame header and sender to diagnose failures */
64 uint8_t fsha[HWADDR_LEN];
65 uint8_t ftha[HWADDR_LEN];
69 TAILQ_ENTRY(arp_state) next;
70 struct interface *iface;
76 struct timespec defend;
78 void (*found_cb)(struct arp_state *, const struct arp_msg *);
79 void (*not_found_cb)(struct arp_state *);
80 void (*announced_cb)(struct arp_state *);
81 void (*defend_failed_cb)(struct arp_state *);
82 void (*free_cb)(struct arp_state *);
84 TAILQ_HEAD(arp_statehead, arp_state);
87 struct arp_statehead arp_states;
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])
96 void arp_packet(struct interface *, uint8_t *, size_t, unsigned int);
97 struct arp_state *arp_new(struct interface *, const struct in_addr *);
98 void arp_probe(struct arp_state *);
99 struct arp_state *arp_announceaddr(struct dhcpcd_ctx *, const struct in_addr *);
100 struct arp_state *arp_ifannounceaddr(struct interface *, const struct in_addr *);
101 struct arp_state * arp_find(struct interface *, const struct in_addr *);
102 void arp_free(struct arp_state *);
103 void arp_freeaddr(struct interface *, const struct in_addr *);
104 void arp_drop(struct interface *);