xref: /dragonfly/contrib/dhcpcd/src/ipv4ll.h (revision 7d84b73d)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * dhcpcd - DHCP client daemon
4  * Copyright (c) 2006-2023 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 IPV4LL_H
30 #define IPV4LL_H
31 
32 #define	LINKLOCAL_ADDR		0xa9fe0000
33 #define	LINKLOCAL_MASK		IN_CLASSB_NET
34 #define	LINKLOCAL_BCAST		(LINKLOCAL_ADDR | ~LINKLOCAL_MASK)
35 
36 #ifndef IN_LINKLOCAL
37 # define IN_LINKLOCAL(addr) ((addr & IN_CLASSB_NET) == LINKLOCAL_ADDR)
38 #endif
39 
40 #ifdef IPV4LL
41 #include "arp.h"
42 
43 struct ipv4ll_state {
44 	struct in_addr pickedaddr;
45 	struct ipv4_addr *addr;
46 	char randomstate[128];
47 	bool running;
48 	bool seeded;
49 	bool down;
50 	size_t conflicts;
51 #ifndef KERNEL_RFC5227
52 	struct arp_state *arp;
53 #endif
54 };
55 
56 #define	IPV4LL_STATE(ifp)						       \
57 	((struct ipv4ll_state *)(ifp)->if_data[IF_DATA_IPV4LL])
58 #define	IPV4LL_CSTATE(ifp)						       \
59 	((const struct ipv4ll_state *)(ifp)->if_data[IF_DATA_IPV4LL])
60 #define	IPV4LL_STATE_RUNNING(ifp)					       \
61 	(IPV4LL_CSTATE((ifp)) && !IPV4LL_CSTATE((ifp))->down &&		       \
62 	(IPV4LL_CSTATE((ifp))->addr != NULL))
63 
64 int ipv4ll_subnetroute(rb_tree_t *, struct interface *);
65 int ipv4ll_defaultroute(rb_tree_t *,struct interface *);
66 ssize_t ipv4ll_env(FILE *, const char *, const struct interface *);
67 void ipv4ll_start(void *);
68 void ipv4ll_claimed(void *);
69 void ipv4ll_handle_failure(void *);
70 struct ipv4_addr *ipv4ll_handleifa(int, struct ipv4_addr *, pid_t pid);
71 #ifdef HAVE_ROUTE_METRIC
72 int ipv4ll_recvrt(int, const struct rt *);
73 #endif
74 
75 void ipv4ll_reset(struct interface *);
76 void ipv4ll_drop(struct interface *);
77 void ipv4ll_free(struct interface *);
78 #endif
79 
80 #endif
81