Update to dhcpcd-9.3.0 with the following changes:
[dragonfly.git] / contrib / dhcpcd / src / if-options.h
blob2c974f578521c19a6baccf08f2ceefaa681fd3be
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3 * dhcpcd - DHCP client daemon
4 * Copyright (c) 2006-2020 Roy Marples <roy@marples.name>
5 * All rights reserved
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.
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.
29 #ifndef IF_OPTIONS_H
30 #define IF_OPTIONS_H
32 #include <sys/param.h>
33 #include <sys/socket.h>
34 #include <net/if.h>
35 #include <netinet/in.h>
37 #include <getopt.h>
38 #include <limits.h>
39 #include <stdint.h>
41 #include "auth.h"
42 #include "route.h"
44 /* Don't set any optional arguments here so we retain POSIX
45 * compatibility with getopt */
46 #define IF_OPTS "146bc:de:f:gh:i:j:kl:m:no:pqr:s:t:u:v:wxy:z:" \
47 "ABC:DEF:GHI:JKLMNO:PQ:S:TUVW:X:Z:"
48 #define NOERR_IF_OPTS ":" IF_OPTS
50 #define DEFAULT_TIMEOUT 30
51 #define DEFAULT_REBOOT 5
53 #ifndef HOSTNAME_MAX_LEN
54 #define HOSTNAME_MAX_LEN 250 /* 255 - 3 (FQDN) - 2 (DNS enc) */
55 #endif
56 #define VENDORCLASSID_MAX_LEN 255
57 #define CLIENTID_MAX_LEN 48
58 #define USERCLASS_MAX_LEN 255
59 #define VENDOR_MAX_LEN 255
60 #define MUDURL_MAX_LEN 255
62 #define DHCPCD_ARP (1ULL << 0)
63 #define DHCPCD_RELEASE (1ULL << 1)
64 #define DHCPCD_RTBUILD (1ULL << 2)
65 #define DHCPCD_GATEWAY (1ULL << 3)
66 #define DHCPCD_STATIC (1ULL << 4)
67 #define DHCPCD_DEBUG (1ULL << 5)
68 #define DHCPCD_LASTLEASE (1ULL << 7)
69 #define DHCPCD_INFORM (1ULL << 8)
70 #define DHCPCD_REQUEST (1ULL << 9)
71 #define DHCPCD_IPV4LL (1ULL << 10)
72 #define DHCPCD_DUID (1ULL << 11)
73 #define DHCPCD_PERSISTENT (1ULL << 12)
74 #define DHCPCD_DAEMONISE (1ULL << 14)
75 #define DHCPCD_DAEMONISED (1ULL << 15)
76 #define DHCPCD_TEST (1ULL << 16)
77 #define DHCPCD_MASTER (1ULL << 17)
78 #define DHCPCD_HOSTNAME (1ULL << 18)
79 #define DHCPCD_CLIENTID (1ULL << 19)
80 #define DHCPCD_LINK (1ULL << 20)
81 #define DHCPCD_ANONYMOUS (1ULL << 21)
82 #define DHCPCD_BACKGROUND (1ULL << 22)
83 #define DHCPCD_VENDORRAW (1ULL << 23)
84 #define DHCPCD_NOWAITIP (1ULL << 24) /* To force daemonise */
85 #define DHCPCD_WAITIP (1ULL << 25)
86 #define DHCPCD_SLAACPRIVATE (1ULL << 26)
87 #define DHCPCD_CSR_WARNED (1ULL << 27)
88 #define DHCPCD_XID_HWADDR (1ULL << 28)
89 #define DHCPCD_BROADCAST (1ULL << 29)
90 #define DHCPCD_DUMPLEASE (1ULL << 30)
91 #define DHCPCD_IPV6RS (1ULL << 31)
92 #define DHCPCD_IPV6RA_REQRDNSS (1ULL << 32)
93 #define DHCPCD_PRIVSEP (1ULL << 33)
94 #define DHCPCD_UNPRIV (1ULL << 34)
95 #define DHCPCD_IPV4 (1ULL << 35)
96 #define DHCPCD_FORKED (1ULL << 36)
97 #define DHCPCD_IPV6 (1ULL << 37)
98 #define DHCPCD_STARTED (1ULL << 38)
99 #define DHCPCD_NOALIAS (1ULL << 39)
100 #define DHCPCD_IA_FORCED (1ULL << 40)
101 #define DHCPCD_STOPPING (1ULL << 41)
102 #define DHCPCD_DEPARTED (1ULL << 42)
103 #define DHCPCD_HOSTNAME_SHORT (1ULL << 43)
104 #define DHCPCD_EXITING (1ULL << 44)
105 #define DHCPCD_WAITIP4 (1ULL << 45)
106 #define DHCPCD_WAITIP6 (1ULL << 46)
107 #define DHCPCD_DEV (1ULL << 47)
108 #define DHCPCD_IAID (1ULL << 48)
109 #define DHCPCD_DHCP (1ULL << 49)
110 #define DHCPCD_DHCP6 (1ULL << 50)
111 #define DHCPCD_IF_UP (1ULL << 51)
112 #define DHCPCD_INFORM6 (1ULL << 52)
113 #define DHCPCD_WANTDHCP (1ULL << 53)
114 #define DHCPCD_IPV6RA_AUTOCONF (1ULL << 54)
115 #define DHCPCD_ROUTER_HOST_ROUTE_WARNED (1ULL << 55)
116 #define DHCPCD_LASTLEASE_EXTEND (1ULL << 56)
117 #define DHCPCD_BOOTP (1ULL << 57)
118 #define DHCPCD_INITIAL_DELAY (1ULL << 58)
119 #define DHCPCD_PRINT_PIDFILE (1ULL << 59)
120 #define DHCPCD_ONESHOT (1ULL << 60)
121 #define DHCPCD_INACTIVE (1ULL << 61)
122 #define DHCPCD_SLAACTEMP (1ULL << 62)
123 #define DHCPCD_PRIVSEPROOT (1ULL << 63)
125 #define DHCPCD_NODROP (DHCPCD_EXITING | DHCPCD_PERSISTENT)
127 #define DHCPCD_WAITOPTS (DHCPCD_WAITIP | DHCPCD_WAITIP4 | DHCPCD_WAITIP6)
129 #define DHCPCD_WARNINGS (DHCPCD_CSR_WARNED | \
130 DHCPCD_ROUTER_HOST_ROUTE_WARNED)
132 /* These options only make sense in the config file, so don't use any
133 valid short options for them */
134 #define O_BASE MAX('z', 'Z') + 1
135 #define O_ARPING O_BASE + 1
136 #define O_FALLBACK O_BASE + 2
137 #define O_DESTINATION O_BASE + 3
138 #define O_IPV6RS O_BASE + 4
139 #define O_NOIPV6RS O_BASE + 5
140 #define O_IPV6RA_FORK O_BASE + 6
141 #define O_LINK_RCVBUF O_BASE + 7
142 #define O_ANONYMOUS O_BASE + 8
143 #define O_NOALIAS O_BASE + 9
144 #define O_IA_NA O_BASE + 10
145 #define O_IA_TA O_BASE + 11
146 #define O_IA_PD O_BASE + 12
147 #define O_HOSTNAME_SHORT O_BASE + 13
148 #define O_DEV O_BASE + 14
149 #define O_NODEV O_BASE + 15
150 #define O_NOIPV4 O_BASE + 16
151 #define O_NOIPV6 O_BASE + 17
152 #define O_IAID O_BASE + 18
153 #define O_DEFINE O_BASE + 19
154 #define O_DEFINE6 O_BASE + 20
155 #define O_EMBED O_BASE + 21
156 #define O_ENCAP O_BASE + 22
157 #define O_VENDOPT O_BASE + 23
158 #define O_VENDCLASS O_BASE + 24
159 #define O_AUTHPROTOCOL O_BASE + 25
160 #define O_AUTHTOKEN O_BASE + 26
161 #define O_AUTHNOTREQUIRED O_BASE + 27
162 #define O_NODHCP O_BASE + 28
163 #define O_NODHCP6 O_BASE + 29
164 #define O_DHCP O_BASE + 30
165 #define O_DHCP6 O_BASE + 31
166 #define O_IPV4 O_BASE + 32
167 #define O_IPV6 O_BASE + 33
168 #define O_CONTROLGRP O_BASE + 34
169 #define O_SLAAC O_BASE + 35
170 #define O_GATEWAY O_BASE + 36
171 #define O_NOUP O_BASE + 37
172 #define O_IPV6RA_AUTOCONF O_BASE + 38
173 #define O_IPV6RA_NOAUTOCONF O_BASE + 39
174 #define O_REJECT O_BASE + 40
175 #define O_BOOTP O_BASE + 42
176 #define O_DEFINEND O_BASE + 43
177 #define O_NODELAY O_BASE + 44
178 #define O_INFORM6 O_BASE + 45
179 #define O_LASTLEASE_EXTEND O_BASE + 46
180 #define O_INACTIVE O_BASE + 47
181 #define O_MUDURL O_BASE + 48
182 #define O_MSUSERCLASS O_BASE + 49
184 extern const struct option cf_options[];
186 struct if_sla {
187 char ifname[IF_NAMESIZE];
188 uint32_t sla;
189 uint8_t prefix_len;
190 uint64_t suffix;
191 bool sla_set;
194 struct if_ia {
195 uint8_t iaid[4];
196 #ifdef INET6
197 uint16_t ia_type;
198 uint8_t iaid_set;
199 struct in6_addr addr;
200 uint8_t prefix_len;
201 #ifndef SMALL
202 uint32_t sla_max;
203 size_t sla_len;
204 struct if_sla *sla;
205 #endif
206 #endif
209 struct vivco {
210 size_t len;
211 uint8_t *data;
214 struct if_options {
215 time_t mtime;
216 uint8_t iaid[4];
217 int metric;
218 uint8_t requestmask[256 / NBBY];
219 uint8_t requiremask[256 / NBBY];
220 uint8_t nomask[256 / NBBY];
221 uint8_t rejectmask[256 / NBBY];
222 uint8_t dstmask[256 / NBBY];
223 uint8_t requestmasknd[(UINT16_MAX + 1) / NBBY];
224 uint8_t requiremasknd[(UINT16_MAX + 1) / NBBY];
225 uint8_t nomasknd[(UINT16_MAX + 1) / NBBY];
226 uint8_t rejectmasknd[(UINT16_MAX + 1) / NBBY];
227 uint8_t requestmask6[(UINT16_MAX + 1) / NBBY];
228 uint8_t requiremask6[(UINT16_MAX + 1) / NBBY];
229 uint8_t nomask6[(UINT16_MAX + 1) / NBBY];
230 uint8_t rejectmask6[(UINT16_MAX + 1) / NBBY];
231 uint32_t leasetime;
232 uint32_t timeout;
233 uint32_t reboot;
234 unsigned long long options;
236 struct in_addr req_addr;
237 struct in_addr req_mask;
238 struct in_addr req_brd;
239 rb_tree_t routes;
240 struct in6_addr req_addr6;
241 uint8_t req_prefix_len;
242 unsigned int mtu;
243 char **config;
245 char **environ;
247 char hostname[HOSTNAME_MAX_LEN + 1]; /* We don't store the length */
248 uint8_t fqdn;
249 uint8_t vendorclassid[VENDORCLASSID_MAX_LEN + 2];
250 uint8_t clientid[CLIENTID_MAX_LEN + 2];
251 uint8_t userclass[USERCLASS_MAX_LEN + 2];
252 uint8_t vendor[VENDOR_MAX_LEN + 2];
253 uint8_t mudurl[MUDURL_MAX_LEN + 2];
255 size_t blacklist_len;
256 in_addr_t *blacklist;
257 size_t whitelist_len;
258 in_addr_t *whitelist;
259 ssize_t arping_len;
260 in_addr_t *arping;
261 char *fallback;
263 struct if_ia *ia;
264 size_t ia_len;
266 struct dhcp_opt *dhcp_override;
267 size_t dhcp_override_len;
268 struct dhcp_opt *nd_override;
269 size_t nd_override_len;
270 struct dhcp_opt *dhcp6_override;
271 size_t dhcp6_override_len;
272 uint32_t vivco_en;
273 struct vivco *vivco;
274 size_t vivco_len;
275 struct dhcp_opt *vivso_override;
276 size_t vivso_override_len;
278 struct auth auth;
281 struct if_options *default_config(struct dhcpcd_ctx *);
282 struct if_options *read_config(struct dhcpcd_ctx *,
283 const char *, const char *, const char *);
284 int add_options(struct dhcpcd_ctx *, const char *,
285 struct if_options *, int, char **);
286 void free_dhcp_opt_embenc(struct dhcp_opt *);
287 void free_options(struct dhcpcd_ctx *, struct if_options *);
289 #endif