1 | /* |
---|
2 | * dhcpcd - DHCP client daemon |
---|
3 | * Copyright (c) 2006-2014 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/socket.h> |
---|
32 | #include <net/if.h> |
---|
33 | #include <netinet/in.h> |
---|
34 | |
---|
35 | #include <getopt.h> |
---|
36 | #include <limits.h> |
---|
37 | #include <stdint.h> |
---|
38 | |
---|
39 | #include "auth.h" |
---|
40 | |
---|
41 | /* Don't set any optional arguments here so we retain POSIX |
---|
42 | * compatibility with getopt */ |
---|
43 | #define IF_OPTS "46bc:de:f:gh:i:kl:m:no:pqr:s:t:u:v:wxy:z:ABC:DEF:GHI:JKLO:Q:S:TUVW:X:Z:" |
---|
44 | |
---|
45 | #define DEFAULT_TIMEOUT 30 |
---|
46 | #define DEFAULT_REBOOT 5 |
---|
47 | |
---|
48 | #ifndef HOSTNAME_MAX_LEN |
---|
49 | #define HOSTNAME_MAX_LEN 250 /* 255 - 3 (FQDN) - 2 (DNS enc) */ |
---|
50 | #endif |
---|
51 | #define VENDORCLASSID_MAX_LEN 255 |
---|
52 | #define CLIENTID_MAX_LEN 48 |
---|
53 | #define USERCLASS_MAX_LEN 255 |
---|
54 | #define VENDOR_MAX_LEN 255 |
---|
55 | |
---|
56 | #define DHCPCD_ARP (1ULL << 0) |
---|
57 | #define DHCPCD_RELEASE (1ULL << 1) |
---|
58 | #define DHCPCD_DOMAIN (1ULL << 2) |
---|
59 | #define DHCPCD_GATEWAY (1ULL << 3) |
---|
60 | #define DHCPCD_STATIC (1ULL << 4) |
---|
61 | #define DHCPCD_DEBUG (1ULL << 5) |
---|
62 | #define DHCPCD_LASTLEASE (1ULL << 7) |
---|
63 | #define DHCPCD_INFORM (1ULL << 8) |
---|
64 | #define DHCPCD_REQUEST (1ULL << 9) |
---|
65 | #define DHCPCD_IPV4LL (1ULL << 10) |
---|
66 | #define DHCPCD_DUID (1ULL << 11) |
---|
67 | #define DHCPCD_PERSISTENT (1ULL << 12) |
---|
68 | #define DHCPCD_DAEMONISE (1ULL << 14) |
---|
69 | #define DHCPCD_DAEMONISED (1ULL << 15) |
---|
70 | #define DHCPCD_TEST (1ULL << 16) |
---|
71 | #define DHCPCD_MASTER (1ULL << 17) |
---|
72 | #define DHCPCD_HOSTNAME (1ULL << 18) |
---|
73 | #define DHCPCD_CLIENTID (1ULL << 19) |
---|
74 | #define DHCPCD_LINK (1ULL << 20) |
---|
75 | #define DHCPCD_QUIET (1ULL << 21) |
---|
76 | #define DHCPCD_BACKGROUND (1ULL << 22) |
---|
77 | #define DHCPCD_VENDORRAW (1ULL << 23) |
---|
78 | #define DHCPCD_TIMEOUT_IPV4LL (1ULL << 24) |
---|
79 | #define DHCPCD_WAITIP (1ULL << 25) |
---|
80 | #define DHCPCD_WAITUP (1ULL << 26) |
---|
81 | #define DHCPCD_CSR_WARNED (1ULL << 27) |
---|
82 | #define DHCPCD_XID_HWADDR (1ULL << 28) |
---|
83 | #define DHCPCD_BROADCAST (1ULL << 29) |
---|
84 | #define DHCPCD_DUMPLEASE (1ULL << 30) |
---|
85 | #define DHCPCD_IPV6RS (1ULL << 31) |
---|
86 | #define DHCPCD_IPV6RA_REQRDNSS (1ULL << 32) |
---|
87 | #define DHCPCD_IPV6RA_OWN (1ULL << 33) |
---|
88 | #define DHCPCD_IPV6RA_OWN_DEFAULT (1ULL << 34) |
---|
89 | #define DHCPCD_IPV4 (1ULL << 35) |
---|
90 | #define DHCPCD_FORKED (1ULL << 36) |
---|
91 | #define DHCPCD_IPV6 (1ULL << 37) |
---|
92 | #define DHCPCD_STARTED (1ULL << 38) |
---|
93 | #define DHCPCD_NOALIAS (1ULL << 39) |
---|
94 | #define DHCPCD_IA_FORCED (1ULL << 40) |
---|
95 | #define DHCPCD_STOPPING (1ULL << 41) |
---|
96 | #define DHCPCD_DEPARTED (1ULL << 42) |
---|
97 | #define DHCPCD_HOSTNAME_SHORT (1ULL << 43) |
---|
98 | #define DHCPCD_EXITING (1ULL << 44) |
---|
99 | #define DHCPCD_WAITIP4 (1ULL << 45) |
---|
100 | #define DHCPCD_WAITIP6 (1ULL << 46) |
---|
101 | #define DHCPCD_DEV (1ULL << 47) |
---|
102 | #define DHCPCD_IAID (1ULL << 48) |
---|
103 | #define DHCPCD_DHCP (1ULL << 49) |
---|
104 | #define DHCPCD_DHCP6 (1ULL << 50) |
---|
105 | |
---|
106 | extern const struct option cf_options[]; |
---|
107 | |
---|
108 | struct if_sla { |
---|
109 | char ifname[IF_NAMESIZE]; |
---|
110 | uint32_t sla; |
---|
111 | short prefix_len; |
---|
112 | int8_t sla_set; |
---|
113 | }; |
---|
114 | |
---|
115 | struct if_ia { |
---|
116 | uint8_t iaid[4]; |
---|
117 | #ifdef INET6 |
---|
118 | size_t sla_len; |
---|
119 | struct if_sla *sla; |
---|
120 | #endif |
---|
121 | }; |
---|
122 | |
---|
123 | struct vivco { |
---|
124 | uint16_t len; |
---|
125 | uint8_t *data; |
---|
126 | }; |
---|
127 | |
---|
128 | struct if_options { |
---|
129 | uint8_t iaid[4]; |
---|
130 | int metric; |
---|
131 | uint8_t requestmask[256 / 8]; |
---|
132 | uint8_t requiremask[256 / 8]; |
---|
133 | uint8_t nomask[256 / 8]; |
---|
134 | uint8_t requestmask6[(UINT16_MAX + 1) / 8]; |
---|
135 | uint8_t requiremask6[(UINT16_MAX + 1) / 8]; |
---|
136 | uint8_t nomask6[(UINT16_MAX + 1) / 8]; |
---|
137 | uint8_t dstmask[256 / 8]; |
---|
138 | uint32_t leasetime; |
---|
139 | time_t timeout; |
---|
140 | time_t reboot; |
---|
141 | unsigned long long options; |
---|
142 | |
---|
143 | struct in_addr req_addr; |
---|
144 | struct in_addr req_mask; |
---|
145 | struct rt_head *routes; |
---|
146 | char **config; |
---|
147 | |
---|
148 | char **environ; |
---|
149 | char script[PATH_MAX]; |
---|
150 | |
---|
151 | char hostname[HOSTNAME_MAX_LEN + 1]; /* We don't store the length */ |
---|
152 | int fqdn; |
---|
153 | uint8_t vendorclassid[VENDORCLASSID_MAX_LEN + 2]; |
---|
154 | char clientid[CLIENTID_MAX_LEN + 2]; |
---|
155 | uint8_t userclass[USERCLASS_MAX_LEN + 2]; |
---|
156 | uint8_t vendor[VENDOR_MAX_LEN + 2]; |
---|
157 | |
---|
158 | size_t blacklist_len; |
---|
159 | in_addr_t *blacklist; |
---|
160 | size_t whitelist_len; |
---|
161 | in_addr_t *whitelist; |
---|
162 | size_t arping_len; |
---|
163 | in_addr_t *arping; |
---|
164 | char *fallback; |
---|
165 | |
---|
166 | uint16_t ia_type; |
---|
167 | struct if_ia *ia; |
---|
168 | size_t ia_len; |
---|
169 | #ifdef INET6 |
---|
170 | int dadtransmits; |
---|
171 | #endif |
---|
172 | |
---|
173 | struct dhcp_opt *dhcp_override; |
---|
174 | size_t dhcp_override_len; |
---|
175 | struct dhcp_opt *dhcp6_override; |
---|
176 | size_t dhcp6_override_len; |
---|
177 | uint32_t vivco_en; |
---|
178 | struct vivco *vivco; |
---|
179 | size_t vivco_len; |
---|
180 | struct dhcp_opt *vivso_override; |
---|
181 | size_t vivso_override_len; |
---|
182 | |
---|
183 | struct auth auth; |
---|
184 | }; |
---|
185 | |
---|
186 | extern unsigned long long options; |
---|
187 | extern char *dev_load; |
---|
188 | |
---|
189 | struct if_options *read_config(const char *, |
---|
190 | const char *, const char *, const char *); |
---|
191 | int add_options(const char *, struct if_options *, int, char **); |
---|
192 | void free_dhcp_opt_embenc(struct dhcp_opt *); |
---|
193 | void free_options(struct if_options *); |
---|
194 | |
---|
195 | #endif |
---|