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 IF_OPTIONS_H
29#define IF_OPTIONS_H
30
31#include <sys/param.h>
32#include <sys/socket.h>
33#include <net/if.h>
34#include <netinet/in.h>
35
36#include <getopt.h>
37#include <limits.h>
38#include <stdint.h>
39
40#include "auth.h"
41#include "route.h"
42
43/* Don't set any optional arguments here so we retain POSIX
44 * compatibility with getopt */
45#define IF_OPTS "146bc:de:f:gh:i:j:kl:m:no:pqr:s:t:u:v:wxy:z:" \
46 "ABC:DEF:GHI:JKLMNO:PQ:S:TUVW:X:Z:"
47#define NOERR_IF_OPTS ":" IF_OPTS
48
49#define DEFAULT_TIMEOUT 30
50#define DEFAULT_REBOOT 5
51
52#ifndef HOSTNAME_MAX_LEN
53#define HOSTNAME_MAX_LEN 250 /* 255 - 3 (FQDN) - 2 (DNS enc) */
54#endif
55#define VENDORCLASSID_MAX_LEN 255
56#define CLIENTID_MAX_LEN 48
57#define USERCLASS_MAX_LEN 255
58#define VENDOR_MAX_LEN 255
59#define MUDURL_MAX_LEN 255
60
61#define DHCPCD_ARP (1ULL << 0)
62#define DHCPCD_RELEASE (1ULL << 1)
63// unused (1ULL << 2)
64#define DHCPCD_GATEWAY (1ULL << 3)
65#define DHCPCD_STATIC (1ULL << 4)
66#define DHCPCD_DEBUG (1ULL << 5)
67#define DHCPCD_LASTLEASE (1ULL << 7)
68#define DHCPCD_INFORM (1ULL << 8)
69#define DHCPCD_REQUEST (1ULL << 9)
70#define DHCPCD_IPV4LL (1ULL << 10)
71#define DHCPCD_DUID (1ULL << 11)
72#define DHCPCD_PERSISTENT (1ULL << 12)
73#define DHCPCD_DAEMONISE (1ULL << 14)
74#define DHCPCD_DAEMONISED (1ULL << 15)
75#define DHCPCD_TEST (1ULL << 16)
76#define DHCPCD_MASTER (1ULL << 17)
77#define DHCPCD_HOSTNAME (1ULL << 18)
78#define DHCPCD_CLIENTID (1ULL << 19)
79#define DHCPCD_LINK (1ULL << 20)
80// unused (1ULL << 21)
81#define DHCPCD_BACKGROUND (1ULL << 22)
82#define DHCPCD_VENDORRAW (1ULL << 23)
83#define DHCPCD_NOWAITIP (1ULL << 24) /* To force daemonise */
84#define DHCPCD_WAITIP (1ULL << 25)
85#define DHCPCD_SLAACPRIVATE (1ULL << 26)
86#define DHCPCD_CSR_WARNED (1ULL << 27)
87#define DHCPCD_XID_HWADDR (1ULL << 28)
88#define DHCPCD_BROADCAST (1ULL << 29)
89#define DHCPCD_DUMPLEASE (1ULL << 30)
90#define DHCPCD_IPV6RS (1ULL << 31)
91#define DHCPCD_IPV6RA_REQRDNSS (1ULL << 32)
92// unused (1ULL << 33)
93// unused (1ULL << 34)
94#define DHCPCD_IPV4 (1ULL << 35)
95#define DHCPCD_FORKED (1ULL << 36)
96#define DHCPCD_IPV6 (1ULL << 37)
97#define DHCPCD_STARTED (1ULL << 38)
98#define DHCPCD_NOALIAS (1ULL << 39)
99#define DHCPCD_IA_FORCED (1ULL << 40)
100#define DHCPCD_STOPPING (1ULL << 41)
101#define DHCPCD_DEPARTED (1ULL << 42)
102#define DHCPCD_HOSTNAME_SHORT (1ULL << 43)
103#define DHCPCD_EXITING (1ULL << 44)
104#define DHCPCD_WAITIP4 (1ULL << 45)
105#define DHCPCD_WAITIP6 (1ULL << 46)
106#define DHCPCD_DEV (1ULL << 47)
107#define DHCPCD_IAID (1ULL << 48)
108#define DHCPCD_DHCP (1ULL << 49)
109#define DHCPCD_DHCP6 (1ULL << 50)
110#define DHCPCD_IF_UP (1ULL << 51)
111#define DHCPCD_INFORM6 (1ULL << 52)
112// unused (1ULL << 53)
113#define DHCPCD_IPV6RA_AUTOCONF (1ULL << 54)
114#define DHCPCD_ROUTER_HOST_ROUTE_WARNED (1ULL << 55)
115#define DHCPCD_LASTLEASE_EXTEND (1ULL << 56)
116#define DHCPCD_BOOTP (1ULL << 57)
117#define DHCPCD_INITIAL_DELAY (1ULL << 58)
118#define DHCPCD_PRINT_PIDFILE (1ULL << 59)
119#define DHCPCD_ONESHOT (1ULL << 60)
120#define DHCPCD_INACTIVE (1ULL << 61)
121
122#define DHCPCD_NODROP (DHCPCD_EXITING | DHCPCD_PERSISTENT)
123
124#define DHCPCD_WAITOPTS (DHCPCD_WAITIP | DHCPCD_WAITIP4 | DHCPCD_WAITIP6)
125
126#define DHCPCD_WARNINGS (DHCPCD_CSR_WARNED | \
127 DHCPCD_ROUTER_HOST_ROUTE_WARNED)
128
129extern const struct option cf_options[];
130
131struct if_sla {
132 char ifname[IF_NAMESIZE];
133 uint32_t sla;
134 uint8_t prefix_len;
135 uint64_t suffix;
136 int8_t sla_set;
137};
138
139struct if_ia {
140 uint8_t iaid[4];
141#ifdef INET6
142 uint16_t ia_type;
143 uint8_t iaid_set;
144 struct in6_addr addr;
145 uint8_t prefix_len;
146#ifndef SMALL
147 uint32_t sla_max;
148 size_t sla_len;
149 struct if_sla *sla;
150#endif
151#endif
152};
153
154struct vivco {
155 size_t len;
156 uint8_t *data;
157};
158
159struct if_options {
160 time_t mtime;
161 uint8_t iaid[4];
162 int metric;
163 uint8_t requestmask[256 / NBBY];
164 uint8_t requiremask[256 / NBBY];
165 uint8_t nomask[256 / NBBY];
166 uint8_t rejectmask[256 / NBBY];
167 uint8_t dstmask[256 / NBBY];
168 uint8_t requestmasknd[(UINT16_MAX + 1) / NBBY];
169 uint8_t requiremasknd[(UINT16_MAX + 1) / NBBY];
170 uint8_t nomasknd[(UINT16_MAX + 1) / NBBY];
171 uint8_t rejectmasknd[(UINT16_MAX + 1) / NBBY];
172 uint8_t requestmask6[(UINT16_MAX + 1) / NBBY];
173 uint8_t requiremask6[(UINT16_MAX + 1) / NBBY];
174 uint8_t nomask6[(UINT16_MAX + 1) / NBBY];
175 uint8_t rejectmask6[(UINT16_MAX + 1) / NBBY];
176 uint32_t leasetime;
177 time_t timeout;
178 time_t reboot;
179 unsigned long long options;
180
181 struct in_addr req_addr;
182 struct in_addr req_mask;
183 struct in_addr req_brd;
184 struct rt_head routes;
185 struct in6_addr req_addr6;
186 uint8_t req_prefix_len;
187 unsigned int mtu;
188 char **config;
189
190 char **environ;
191 char *script;
192
193 char hostname[HOSTNAME_MAX_LEN + 1]; /* We don't store the length */
194 uint8_t fqdn;
195 uint8_t vendorclassid[VENDORCLASSID_MAX_LEN + 2];
196 uint8_t clientid[CLIENTID_MAX_LEN + 2];
197 uint8_t userclass[USERCLASS_MAX_LEN + 2];
198 uint8_t vendor[VENDOR_MAX_LEN + 2];
199 uint8_t mudurl[MUDURL_MAX_LEN + 2];
200
201 size_t blacklist_len;
202 in_addr_t *blacklist;
203 size_t whitelist_len;
204 in_addr_t *whitelist;
205 ssize_t arping_len;
206 in_addr_t *arping;
207 char *fallback;
208
209 struct if_ia *ia;
210 size_t ia_len;
211
212 struct dhcp_opt *dhcp_override;
213 size_t dhcp_override_len;
214 struct dhcp_opt *nd_override;
215 size_t nd_override_len;
216 struct dhcp_opt *dhcp6_override;
217 size_t dhcp6_override_len;
218 uint32_t vivco_en;
219 struct vivco *vivco;
220 size_t vivco_len;
221 struct dhcp_opt *vivso_override;
222 size_t vivso_override_len;
223
224 struct auth auth;
225};
226
227struct if_options *default_config(struct dhcpcd_ctx *);
228struct if_options *read_config(struct dhcpcd_ctx *,
229 const char *, const char *, const char *);
230int add_options(struct dhcpcd_ctx *, const char *,
231 struct if_options *, int, char **);
232void free_dhcp_opt_embenc(struct dhcp_opt *);
233void free_options(struct dhcpcd_ctx *, struct if_options *);
234
235#endif
236