blob: 0daf6155fdc5c2321fe8ea4371a9a2a5696b6351 [file] [log] [blame]
Samuel Tand7ed8512015-08-13 16:11:35 -07001/*
2 * dhcpcd - DHCP client daemon
3 * Copyright (c) 2006-2015 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
45struct 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
53struct 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
Samuel Tan1c4088e2015-08-13 16:18:58 -070061 struct in_addr src_addr;
Samuel Tand7ed8512015-08-13 16:11:35 -070062 struct in_addr addr;
63 int probes;
64 int claims;
65 struct in_addr failed;
Samuel Tanf20514b2015-08-13 16:24:02 -070066 uint8_t dest_hwlen;
67 unsigned char dest_hwaddr[HWADDR_LEN];
Samuel Tand7ed8512015-08-13 16:11:35 -070068};
69TAILQ_HEAD(arp_statehead, arp_state);
70
71#ifdef INET
72void arp_report_conflicted(const struct arp_state *, const struct arp_msg *);
73void arp_announce(struct arp_state *);
74void arp_probe(struct arp_state *);
75struct arp_state *arp_new(struct interface *, const struct in_addr *);
76void arp_cancel(struct arp_state *);
77void arp_free(struct arp_state *);
78void arp_free_but(struct arp_state *);
79void arp_close(struct interface *);
80
81void arp_handleifa(int, struct interface *, const struct in_addr *, int);
82#else
83#define arp_close(a) {}
84#endif
85#endif