1/*
2 * dhcpcd - DHCP client daemon
3 * Copyright (c) 2006-2019 Roy Marples <roy@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#include "if.h"
45
46#ifdef IN_IFF_DUPLICATED
47/* NetBSD gained RFC 5227 support in the kernel.
48 * This means dhcpcd doesn't need ARP except for ARPing support. */
49#if defined(__NetBSD_Version__) && __NetBSD_Version__ >= 799003900
50#define KERNEL_RFC5227
51#endif
52#endif
53
54struct arp_msg {
55 uint16_t op;
56 unsigned char sha[HWADDR_LEN];
57 struct in_addr sip;
58 unsigned char tha[HWADDR_LEN];
59 struct in_addr tip;
60};
61
62struct arp_state {
63 TAILQ_ENTRY(arp_state) next;
64 struct interface *iface;
65
66 void (*probed_cb)(struct arp_state *);
67 void (*announced_cb)(struct arp_state *);
68 void (*conflicted_cb)(struct arp_state *, const struct arp_msg *);
69 void (*free_cb)(struct arp_state *);
70
71 struct in_addr addr;
72 int probes;
73 int claims;
74 struct in_addr failed;
75};
76TAILQ_HEAD(arp_statehead, arp_state);
77
78struct iarp_state {
79 int bpf_fd;
80 unsigned int bpf_flags;
81 struct arp_statehead arp_states;
82};
83
84#define ARP_STATE(ifp) \
85 ((struct iarp_state *)(ifp)->if_data[IF_DATA_ARP])
86#define ARP_CSTATE(ifp) \
87 ((const struct iarp_state *)(ifp)->if_data[IF_DATA_ARP])
88
89#ifdef ARP
90int arp_open(struct interface *);
91ssize_t arp_request(const struct interface *, in_addr_t, in_addr_t);
92void arp_probe(struct arp_state *);
93void arp_report_conflicted(const struct arp_state *, const struct arp_msg *);
94struct arp_state *arp_new(struct interface *, const struct in_addr *);
95struct arp_state *arp_find(struct interface *, const struct in_addr *);
96void arp_announce(struct arp_state *);
97void arp_announceaddr(struct dhcpcd_ctx *, const struct in_addr *);
98void arp_ifannounceaddr(struct interface *, const struct in_addr *);
99void arp_cancel(struct arp_state *);
100void arp_free(struct arp_state *);
101void arp_free_but(struct arp_state *);
102void arp_drop(struct interface *);
103
104void arp_handleifa(int, struct ipv4_addr *);
105#endif /* ARP */
106#endif /* ARP_H */
107