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 IPV4LL_H
29#define IPV4LL_H
30
31#define LINKLOCAL_ADDR 0xa9fe0000
32#define LINKLOCAL_MASK IN_CLASSB_NET
33#define LINKLOCAL_BCAST (LINKLOCAL_ADDR | ~LINKLOCAL_MASK)
34
35#ifndef IN_LINKLOCAL
36# define IN_LINKLOCAL(addr) ((addr & IN_CLASSB_NET) == LINKLOCAL_ADDR)
37#endif
38
39#ifdef IPV4LL
40#include "arp.h"
41
42struct ipv4ll_state {
43 struct in_addr pickedaddr;
44 struct ipv4_addr *addr;
45 struct arp_state *arp;
46 unsigned int conflicts;
47 struct timespec defend;
48 char randomstate[128];
49 bool seeded;
50 uint8_t down;
51};
52
53#define IPV4LL_STATE(ifp) \
54 ((struct ipv4ll_state *)(ifp)->if_data[IF_DATA_IPV4LL])
55#define IPV4LL_CSTATE(ifp) \
56 ((const struct ipv4ll_state *)(ifp)->if_data[IF_DATA_IPV4LL])
57#define IPV4LL_STATE_RUNNING(ifp) \
58 (IPV4LL_CSTATE((ifp)) && !IPV4LL_CSTATE((ifp))->down && \
59 (IPV4LL_CSTATE((ifp))->addr != NULL))
60
61int ipv4ll_subnetroute(struct rt_head *, struct interface *);
62int ipv4ll_defaultroute(struct rt_head *,struct interface *);
63ssize_t ipv4ll_env(char **, const char *, const struct interface *);
64void ipv4ll_start(void *);
65void ipv4ll_claimed(void *);
66void ipv4ll_handle_failure(void *);
67#ifdef HAVE_ROUTE_METRIC
68int ipv4ll_recvrt(int, const struct rt *);
69#endif
70
71void ipv4ll_reset(struct interface *);
72void ipv4ll_drop(struct interface *);
73void ipv4ll_free(struct interface *);
74#endif
75
76#endif
77