Import dhcpcd-8.0.4 to vendor branch.
[dragonfly.git] / contrib / dhcpcd / src / arp.h
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * dhcpcd - DHCP client daemon
4  * Copyright (c) 2006-2019 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         unsigned char sha[HWADDR_LEN];
58         struct in_addr sip;
59         unsigned char tha[HWADDR_LEN];
60         struct in_addr tip;
61 };
62
63 struct arp_state {
64         TAILQ_ENTRY(arp_state) next;
65         struct interface *iface;
66
67         void (*found_cb)(struct arp_state *, const struct arp_msg *);
68         void (*not_found_cb)(struct arp_state *);
69         void (*announced_cb)(struct arp_state *);
70         void (*defend_failed_cb)(struct arp_state *);
71         void (*free_cb)(struct arp_state *);
72
73         struct in_addr addr;
74         int probes;
75         int claims;
76         struct timespec defend;
77 };
78 TAILQ_HEAD(arp_statehead, arp_state);
79
80 struct iarp_state {
81         int bpf_fd;
82         unsigned int bpf_flags;
83         struct arp_statehead arp_states;
84 };
85
86 #define ARP_STATE(ifp)                                                         \
87         ((struct iarp_state *)(ifp)->if_data[IF_DATA_ARP])
88 #define ARP_CSTATE(ifp)                                                        \
89         ((const struct iarp_state *)(ifp)->if_data[IF_DATA_ARP])
90
91 #ifdef ARP
92 struct arp_state *arp_new(struct interface *, const struct in_addr *);
93 void arp_probe(struct arp_state *);
94 void arp_announce(struct arp_state *);
95 void arp_announceaddr(struct dhcpcd_ctx *, const struct in_addr *);
96 void arp_ifannounceaddr(struct interface *, const struct in_addr *);
97 void arp_cancel(struct arp_state *);
98 void arp_free(struct arp_state *);
99 void arp_freeaddr(struct interface *, const struct in_addr *);
100 void arp_drop(struct interface *);
101 #endif /* ARP */
102 #endif /* ARP_H */