| 1 |
/* dnsmasq is Copyright (c) 2000-2026 Simon Kelley |
| 2 |
|
| 3 |
This program is free software; you can redistribute it and/or modify |
| 4 |
it under the terms of the GNU General Public License as published by |
| 5 |
the Free Software Foundation; version 2 dated June, 1991, or |
| 6 |
(at your option) version 3 dated 29 June, 2007. |
| 7 |
|
| 8 |
This program is distributed in the hope that it will be useful, |
| 9 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
GNU General Public License for more details. |
| 12 |
|
| 13 |
You should have received a copy of the GNU General Public License |
| 14 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
/* define this to get facilitynames */ |
| 18 |
#define SYSLOG_NAMES |
| 19 |
#include "dnsmasq.h" |
| 20 |
#include <setjmp.h> |
| 21 |
|
| 22 |
static volatile int mem_recover = 0; |
| 23 |
static jmp_buf mem_jmp; |
| 24 |
static int one_file(char *file, int hard_opt); |
| 25 |
|
| 26 |
static void *opt_malloc_real(const char *func, unsigned int line, size_t size); |
| 27 |
#define opt_malloc(x) opt_malloc_real(__func__, __LINE__, (x)) |
| 28 |
|
| 29 |
/* Solaris headers don't have facility names. */ |
| 30 |
#ifdef HAVE_SOLARIS_NETWORK |
| 31 |
static const struct { |
| 32 |
char *c_name; |
| 33 |
unsigned int c_val; |
| 34 |
} facilitynames[] = { |
| 35 |
{ "kern", LOG_KERN }, |
| 36 |
{ "user", LOG_USER }, |
| 37 |
{ "mail", LOG_MAIL }, |
| 38 |
{ "daemon", LOG_DAEMON }, |
| 39 |
{ "auth", LOG_AUTH }, |
| 40 |
{ "syslog", LOG_SYSLOG }, |
| 41 |
{ "lpr", LOG_LPR }, |
| 42 |
{ "news", LOG_NEWS }, |
| 43 |
{ "uucp", LOG_UUCP }, |
| 44 |
{ "audit", LOG_AUDIT }, |
| 45 |
{ "cron", LOG_CRON }, |
| 46 |
{ "local0", LOG_LOCAL0 }, |
| 47 |
{ "local1", LOG_LOCAL1 }, |
| 48 |
{ "local2", LOG_LOCAL2 }, |
| 49 |
{ "local3", LOG_LOCAL3 }, |
| 50 |
{ "local4", LOG_LOCAL4 }, |
| 51 |
{ "local5", LOG_LOCAL5 }, |
| 52 |
{ "local6", LOG_LOCAL6 }, |
| 53 |
{ "local7", LOG_LOCAL7 }, |
| 54 |
{ NULL, 0 } |
| 55 |
}; |
| 56 |
#endif |
| 57 |
|
| 58 |
#ifndef HAVE_GETOPT_LONG |
| 59 |
struct myoption { |
| 60 |
const char *name; |
| 61 |
int has_arg; |
| 62 |
int *flag; |
| 63 |
int val; |
| 64 |
}; |
| 65 |
#endif |
| 66 |
|
| 67 |
#define OPTSTRING "951yZDNLERKzowefnbvhdkqr:m:p:c:l:s:i:t:u:g:a:x:S:C:A:T:H:Q:I:B:F:G:O:M:X:V:U:j:P:J:W:Y:2:4:6:7:8:0:3:" |
| 68 |
|
| 69 |
/* options which don't have a one-char version */ |
| 70 |
#define LOPT_RELOAD 256 |
| 71 |
#define LOPT_NO_NAMES 257 |
| 72 |
#define LOPT_TFTP 258 |
| 73 |
#define LOPT_SECURE 259 |
| 74 |
#define LOPT_PREFIX 260 |
| 75 |
#define LOPT_PTR 261 |
| 76 |
#define LOPT_BRIDGE 262 |
| 77 |
#define LOPT_TFTP_MAX 263 |
| 78 |
#define LOPT_FORCE 264 |
| 79 |
#define LOPT_NOBLOCK 265 |
| 80 |
#define LOPT_LOG_OPTS 266 |
| 81 |
#define LOPT_MAX_LOGS 267 |
| 82 |
#define LOPT_CIRCUIT 268 |
| 83 |
#define LOPT_REMOTE 269 |
| 84 |
#define LOPT_SUBSCR 270 |
| 85 |
#define LOPT_INTNAME 271 |
| 86 |
#define LOPT_BANK 272 |
| 87 |
#define LOPT_DHCP_HOST 273 |
| 88 |
#define LOPT_APREF 274 |
| 89 |
#define LOPT_OVERRIDE 275 |
| 90 |
#define LOPT_TFTPPORTS 276 |
| 91 |
#define LOPT_REBIND 277 |
| 92 |
#define LOPT_NOLAST 278 |
| 93 |
#define LOPT_OPTS 279 |
| 94 |
#define LOPT_DHCP_OPTS 280 |
| 95 |
#define LOPT_MATCH 281 |
| 96 |
#define LOPT_BROADCAST 282 |
| 97 |
#define LOPT_NEGTTL 283 |
| 98 |
#define LOPT_ALTPORT 284 |
| 99 |
#define LOPT_SCRIPTUSR 285 |
| 100 |
#define LOPT_LOCAL 286 |
| 101 |
#define LOPT_NAPTR 287 |
| 102 |
#define LOPT_MINPORT 288 |
| 103 |
#define LOPT_DHCP_FQDN 289 |
| 104 |
#define LOPT_CNAME 290 |
| 105 |
#define LOPT_PXE_PROMT 291 |
| 106 |
#define LOPT_PXE_SERV 292 |
| 107 |
#define LOPT_TEST 293 |
| 108 |
#define LOPT_TAG_IF 294 |
| 109 |
#define LOPT_PROXY 295 |
| 110 |
#define LOPT_GEN_NAMES 296 |
| 111 |
#define LOPT_MAXTTL 297 |
| 112 |
#define LOPT_NO_REBIND 298 |
| 113 |
#define LOPT_LOC_REBND 299 |
| 114 |
#define LOPT_ADD_MAC 300 |
| 115 |
#define LOPT_DNSSEC 301 |
| 116 |
#define LOPT_INCR_ADDR 302 |
| 117 |
#define LOPT_CONNTRACK 303 |
| 118 |
#define LOPT_FQDN 304 |
| 119 |
#define LOPT_LUASCRIPT 305 |
| 120 |
#define LOPT_RA 306 |
| 121 |
#define LOPT_DUID 307 |
| 122 |
#define LOPT_HOST_REC 308 |
| 123 |
#define LOPT_TFTP_LC 309 |
| 124 |
#define LOPT_RR 310 |
| 125 |
#define LOPT_CLVERBIND 311 |
| 126 |
#define LOPT_MAXCTTL 312 |
| 127 |
#define LOPT_AUTHZONE 313 |
| 128 |
#define LOPT_AUTHSERV 314 |
| 129 |
#define LOPT_AUTHTTL 315 |
| 130 |
#define LOPT_AUTHSOA 316 |
| 131 |
#define LOPT_AUTHSFS 317 |
| 132 |
#define LOPT_AUTHPEER 318 |
| 133 |
#define LOPT_IPSET 319 |
| 134 |
#define LOPT_SYNTH 320 |
| 135 |
#define LOPT_RELAY 323 |
| 136 |
#define LOPT_RA_PARAM 324 |
| 137 |
#define LOPT_ADD_SBNET 325 |
| 138 |
#define LOPT_QUIET_DHCP 326 |
| 139 |
#define LOPT_QUIET_DHCP6 327 |
| 140 |
#define LOPT_QUIET_RA 328 |
| 141 |
#define LOPT_SEC_VALID 329 |
| 142 |
#define LOPT_TRUST_ANCHOR 330 |
| 143 |
#define LOPT_DNSSEC_DEBUG 331 |
| 144 |
#define LOPT_REV_SERV 332 |
| 145 |
#define LOPT_SERVERS_FILE 333 |
| 146 |
#define LOPT_DNSSEC_CHECK 334 |
| 147 |
#define LOPT_LOCAL_SERVICE 335 |
| 148 |
#define LOPT_DNSSEC_TIME 336 |
| 149 |
#define LOPT_LOOP_DETECT 337 |
| 150 |
#define LOPT_IGNORE_ADDR 338 |
| 151 |
#define LOPT_MINCTTL 339 |
| 152 |
#define LOPT_DHCP_INOTIFY 340 |
| 153 |
#define LOPT_DHOPT_INOTIFY 341 |
| 154 |
#define LOPT_HOST_INOTIFY 342 |
| 155 |
#define LOPT_DNSSEC_STAMP 343 |
| 156 |
#define LOPT_TFTP_NO_FAIL 344 |
| 157 |
#define LOPT_MAXPORT 345 |
| 158 |
#define LOPT_CPE_ID 346 |
| 159 |
#define LOPT_SCRIPT_ARP 347 |
| 160 |
#define LOPT_DHCPTTL 348 |
| 161 |
#define LOPT_TFTP_MTU 349 |
| 162 |
#define LOPT_REPLY_DELAY 350 |
| 163 |
#define LOPT_RAPID_COMMIT 351 |
| 164 |
#define LOPT_DUMPFILE 352 |
| 165 |
#define LOPT_DUMPMASK 353 |
| 166 |
#define LOPT_UBUS 354 |
| 167 |
#define LOPT_NAME_MATCH 355 |
| 168 |
#define LOPT_CAA 356 |
| 169 |
#define LOPT_SHARED_NET 357 |
| 170 |
#define LOPT_IGNORE_CLID 358 |
| 171 |
#define LOPT_SINGLE_PORT 359 |
| 172 |
#define LOPT_SCRIPT_TIME 360 |
| 173 |
#define LOPT_PXE_VENDOR 361 |
| 174 |
#define LOPT_DYNHOST 362 |
| 175 |
#define LOPT_LOG_DEBUG 363 |
| 176 |
#define LOPT_UMBRELLA 364 |
| 177 |
#define LOPT_CMARK_ALST_EN 365 |
| 178 |
#define LOPT_CMARK_ALST 366 |
| 179 |
#define LOPT_QUIET_TFTP 367 |
| 180 |
#define LOPT_NFTSET 368 |
| 181 |
#define LOPT_FILTER_A 369 |
| 182 |
#define LOPT_FILTER_AAAA 370 |
| 183 |
#define LOPT_STRIP_SBNET 371 |
| 184 |
#define LOPT_STRIP_MAC 372 |
| 185 |
#define LOPT_CONF_OPT 373 |
| 186 |
#define LOPT_CONF_SCRIPT 374 |
| 187 |
#define LOPT_RANDPORT_LIM 375 |
| 188 |
#define LOPT_FAST_RETRY 376 |
| 189 |
#define LOPT_STALE_CACHE 377 |
| 190 |
#define LOPT_NORR 378 |
| 191 |
#define LOPT_NO_IDENT 379 |
| 192 |
#define LOPT_CACHE_RR 380 |
| 193 |
#define LOPT_FILTER_RR 381 |
| 194 |
#define LOPT_NO_DHCP6 382 |
| 195 |
#define LOPT_NO_DHCP4 383 |
| 196 |
#define LOPT_MAX_PROCS 384 |
| 197 |
#define LOPT_DNSSEC_LIMITS 385 |
| 198 |
#define LOPT_PXE_OPT 386 |
| 199 |
#define LOPT_NO_ENCODE 387 |
| 200 |
#define LOPT_DO_ENCODE 388 |
| 201 |
#define LOPT_LEASEQUERY 389 |
| 202 |
#define LOPT_SPLIT_RELAY 390 |
| 203 |
#define LOPT_LOG_MALLOC 391 |
| 204 |
|
| 205 |
#ifdef HAVE_GETOPT_LONG |
| 206 |
static const struct option opts[] = |
| 207 |
#else |
| 208 |
static const struct myoption opts[] = |
| 209 |
#endif |
| 210 |
{ |
| 211 |
{ "version", 0, 0, 'v' }, |
| 212 |
{ "no-hosts", 0, 0, 'h' }, |
| 213 |
{ "no-poll", 0, 0, 'n' }, |
| 214 |
{ "help", 0, 0, 'w' }, |
| 215 |
{ "no-daemon", 0, 0, 'd' }, |
| 216 |
{ "log-queries", 2, 0, 'q' }, |
| 217 |
{ "user", 2, 0, 'u' }, |
| 218 |
{ "group", 2, 0, 'g' }, |
| 219 |
{ "resolv-file", 2, 0, 'r' }, |
| 220 |
{ "servers-file", 1, 0, LOPT_SERVERS_FILE }, |
| 221 |
{ "mx-host", 1, 0, 'm' }, |
| 222 |
{ "mx-target", 1, 0, 't' }, |
| 223 |
{ "cache-size", 2, 0, 'c' }, |
| 224 |
{ "port", 1, 0, 'p' }, |
| 225 |
{ "dhcp-leasefile", 2, 0, 'l' }, |
| 226 |
{ "dhcp-lease", 1, 0, 'l' }, |
| 227 |
{ "dhcp-host", 1, 0, 'G' }, |
| 228 |
{ "dhcp-range", 1, 0, 'F' }, |
| 229 |
{ "dhcp-option", 1, 0, 'O' }, |
| 230 |
{ "dhcp-boot", 1, 0, 'M' }, |
| 231 |
{ "domain", 1, 0, 's' }, |
| 232 |
{ "domain-suffix", 1, 0, 's' }, |
| 233 |
{ "interface", 1, 0, 'i' }, |
| 234 |
{ "listen-address", 1, 0, 'a' }, |
| 235 |
{ "local-service", 2, 0, LOPT_LOCAL_SERVICE }, |
| 236 |
{ "bogus-priv", 0, 0, 'b' }, |
| 237 |
{ "bogus-nxdomain", 1, 0, 'B' }, |
| 238 |
{ "ignore-address", 1, 0, LOPT_IGNORE_ADDR }, |
| 239 |
{ "selfmx", 0, 0, 'e' }, |
| 240 |
{ "filterwin2k", 0, 0, 'f' }, |
| 241 |
{ "filter-A", 0, 0, LOPT_FILTER_A }, |
| 242 |
{ "filter-AAAA", 0, 0, LOPT_FILTER_AAAA }, |
| 243 |
{ "filter-rr", 1, 0, LOPT_FILTER_RR }, |
| 244 |
{ "pid-file", 2, 0, 'x' }, |
| 245 |
{ "strict-order", 0, 0, 'o' }, |
| 246 |
{ "server", 1, 0, 'S' }, |
| 247 |
{ "rev-server", 1, 0, LOPT_REV_SERV }, |
| 248 |
{ "local", 1, 0, LOPT_LOCAL }, |
| 249 |
{ "address", 1, 0, 'A' }, |
| 250 |
{ "conf-file", 2, 0, 'C' }, |
| 251 |
{ "conf-script", 1, 0, LOPT_CONF_SCRIPT }, |
| 252 |
{ "no-resolv", 0, 0, 'R' }, |
| 253 |
{ "expand-hosts", 0, 0, 'E' }, |
| 254 |
{ "localmx", 0, 0, 'L' }, |
| 255 |
{ "local-ttl", 1, 0, 'T' }, |
| 256 |
{ "no-negcache", 0, 0, 'N' }, |
| 257 |
{ "no-round-robin", 0, 0, LOPT_NORR }, |
| 258 |
{ "no-0x20-encode", 0, 0, LOPT_NO_ENCODE }, |
| 259 |
{ "do-0x20-encode", 0, 0, LOPT_DO_ENCODE }, |
| 260 |
{ "cache-rr", 1, 0, LOPT_CACHE_RR }, |
| 261 |
{ "addn-hosts", 1, 0, 'H' }, |
| 262 |
{ "hostsdir", 1, 0, LOPT_HOST_INOTIFY }, |
| 263 |
{ "query-port", 1, 0, 'Q' }, |
| 264 |
{ "except-interface", 1, 0, 'I' }, |
| 265 |
{ "no-dhcp-interface", 1, 0, '2' }, |
| 266 |
{ "no-dhcpv4-interface", 1, 0, LOPT_NO_DHCP4 }, |
| 267 |
{ "no-dhcpv6-interface", 1, 0, LOPT_NO_DHCP6 }, |
| 268 |
{ "domain-needed", 0, 0, 'D' }, |
| 269 |
{ "dhcp-lease-max", 1, 0, 'X' }, |
| 270 |
{ "bind-interfaces", 0, 0, 'z' }, |
| 271 |
{ "read-ethers", 0, 0, 'Z' }, |
| 272 |
{ "alias", 1, 0, 'V' }, |
| 273 |
{ "dhcp-vendorclass", 1, 0, 'U' }, |
| 274 |
{ "dhcp-userclass", 1, 0, 'j' }, |
| 275 |
{ "dhcp-ignore", 1, 0, 'J' }, |
| 276 |
{ "edns-packet-max", 1, 0, 'P' }, |
| 277 |
{ "keep-in-foreground", 0, 0, 'k' }, |
| 278 |
{ "dhcp-authoritative", 0, 0, 'K' }, |
| 279 |
{ "srv-host", 1, 0, 'W' }, |
| 280 |
{ "localise-queries", 0, 0, 'y' }, |
| 281 |
{ "txt-record", 1, 0, 'Y' }, |
| 282 |
{ "caa-record", 1, 0 , LOPT_CAA }, |
| 283 |
{ "dns-rr", 1, 0, LOPT_RR }, |
| 284 |
{ "enable-dbus", 2, 0, '1' }, |
| 285 |
{ "enable-ubus", 2, 0, LOPT_UBUS }, |
| 286 |
{ "bootp-dynamic", 2, 0, '3' }, |
| 287 |
{ "dhcp-mac", 1, 0, '4' }, |
| 288 |
{ "no-ping", 0, 0, '5' }, |
| 289 |
{ "dhcp-script", 1, 0, '6' }, |
| 290 |
{ "conf-dir", 1, 0, '7' }, |
| 291 |
{ "log-facility", 1, 0 ,'8' }, |
| 292 |
{ "leasefile-ro", 0, 0, '9' }, |
| 293 |
{ "script-on-renewal", 0, 0, LOPT_SCRIPT_TIME}, |
| 294 |
{ "dns-forward-max", 1, 0, '0' }, |
| 295 |
{ "clear-on-reload", 0, 0, LOPT_RELOAD }, |
| 296 |
{ "dhcp-ignore-names", 2, 0, LOPT_NO_NAMES }, |
| 297 |
{ "enable-tftp", 2, 0, LOPT_TFTP }, |
| 298 |
{ "tftp-secure", 0, 0, LOPT_SECURE }, |
| 299 |
{ "tftp-no-fail", 0, 0, LOPT_TFTP_NO_FAIL }, |
| 300 |
{ "tftp-unique-root", 2, 0, LOPT_APREF }, |
| 301 |
{ "tftp-root", 1, 0, LOPT_PREFIX }, |
| 302 |
{ "tftp-max", 1, 0, LOPT_TFTP_MAX }, |
| 303 |
{ "tftp-mtu", 1, 0, LOPT_TFTP_MTU }, |
| 304 |
{ "tftp-lowercase", 0, 0, LOPT_TFTP_LC }, |
| 305 |
{ "tftp-single-port", 0, 0, LOPT_SINGLE_PORT }, |
| 306 |
{ "ptr-record", 1, 0, LOPT_PTR }, |
| 307 |
{ "naptr-record", 1, 0, LOPT_NAPTR }, |
| 308 |
{ "bridge-interface", 1, 0 , LOPT_BRIDGE }, |
| 309 |
{ "shared-network", 1, 0, LOPT_SHARED_NET }, |
| 310 |
{ "dhcp-option-force", 1, 0, LOPT_FORCE }, |
| 311 |
{ "dhcp-option-pxe", 1, 0, LOPT_PXE_OPT }, |
| 312 |
{ "tftp-no-blocksize", 0, 0, LOPT_NOBLOCK }, |
| 313 |
{ "log-dhcp", 0, 0, LOPT_LOG_OPTS }, |
| 314 |
{ "log-async", 2, 0, LOPT_MAX_LOGS }, |
| 315 |
{ "dhcp-circuitid", 1, 0, LOPT_CIRCUIT }, |
| 316 |
{ "dhcp-remoteid", 1, 0, LOPT_REMOTE }, |
| 317 |
{ "dhcp-subscrid", 1, 0, LOPT_SUBSCR }, |
| 318 |
{ "dhcp-pxe-vendor", 1, 0, LOPT_PXE_VENDOR }, |
| 319 |
{ "interface-name", 1, 0, LOPT_INTNAME }, |
| 320 |
{ "dhcp-hostsfile", 1, 0, LOPT_DHCP_HOST }, |
| 321 |
{ "dhcp-optsfile", 1, 0, LOPT_DHCP_OPTS }, |
| 322 |
{ "dhcp-hostsdir", 1, 0, LOPT_DHCP_INOTIFY }, |
| 323 |
{ "dhcp-optsdir", 1, 0, LOPT_DHOPT_INOTIFY }, |
| 324 |
{ "dhcp-no-override", 0, 0, LOPT_OVERRIDE }, |
| 325 |
{ "tftp-port-range", 1, 0, LOPT_TFTPPORTS }, |
| 326 |
{ "stop-dns-rebind", 0, 0, LOPT_REBIND }, |
| 327 |
{ "rebind-domain-ok", 1, 0, LOPT_NO_REBIND }, |
| 328 |
{ "all-servers", 0, 0, LOPT_NOLAST }, |
| 329 |
{ "dhcp-match", 1, 0, LOPT_MATCH }, |
| 330 |
{ "dhcp-name-match", 1, 0, LOPT_NAME_MATCH }, |
| 331 |
{ "dhcp-broadcast", 2, 0, LOPT_BROADCAST }, |
| 332 |
{ "neg-ttl", 1, 0, LOPT_NEGTTL }, |
| 333 |
{ "max-ttl", 1, 0, LOPT_MAXTTL }, |
| 334 |
{ "min-cache-ttl", 1, 0, LOPT_MINCTTL }, |
| 335 |
{ "max-cache-ttl", 1, 0, LOPT_MAXCTTL }, |
| 336 |
{ "dhcp-alternate-port", 2, 0, LOPT_ALTPORT }, |
| 337 |
{ "dhcp-scriptuser", 1, 0, LOPT_SCRIPTUSR }, |
| 338 |
{ "min-port", 1, 0, LOPT_MINPORT }, |
| 339 |
{ "max-port", 1, 0, LOPT_MAXPORT }, |
| 340 |
{ "dhcp-fqdn", 0, 0, LOPT_DHCP_FQDN }, |
| 341 |
{ "cname", 1, 0, LOPT_CNAME }, |
| 342 |
{ "pxe-prompt", 1, 0, LOPT_PXE_PROMT }, |
| 343 |
{ "pxe-service", 1, 0, LOPT_PXE_SERV }, |
| 344 |
{ "test", 0, 0, LOPT_TEST }, |
| 345 |
{ "tag-if", 1, 0, LOPT_TAG_IF }, |
| 346 |
{ "dhcp-proxy", 2, 0, LOPT_PROXY }, |
| 347 |
{ "dhcp-generate-names", 2, 0, LOPT_GEN_NAMES }, |
| 348 |
{ "rebind-localhost-ok", 0, 0, LOPT_LOC_REBND }, |
| 349 |
{ "add-mac", 2, 0, LOPT_ADD_MAC }, |
| 350 |
{ "strip-mac", 0, 0, LOPT_STRIP_MAC }, |
| 351 |
{ "add-subnet", 2, 0, LOPT_ADD_SBNET }, |
| 352 |
{ "strip-subnet", 0, 0, LOPT_STRIP_SBNET }, |
| 353 |
{ "add-cpe-id", 1, 0 , LOPT_CPE_ID }, |
| 354 |
{ "proxy-dnssec", 0, 0, LOPT_DNSSEC }, |
| 355 |
{ "dhcp-sequential-ip", 0, 0, LOPT_INCR_ADDR }, |
| 356 |
{ "conntrack", 0, 0, LOPT_CONNTRACK }, |
| 357 |
{ "dhcp-client-update", 0, 0, LOPT_FQDN }, |
| 358 |
{ "dhcp-luascript", 1, 0, LOPT_LUASCRIPT }, |
| 359 |
{ "enable-ra", 0, 0, LOPT_RA }, |
| 360 |
{ "dhcp-duid", 1, 0, LOPT_DUID }, |
| 361 |
{ "host-record", 1, 0, LOPT_HOST_REC }, |
| 362 |
{ "bind-dynamic", 0, 0, LOPT_CLVERBIND }, |
| 363 |
{ "auth-zone", 1, 0, LOPT_AUTHZONE }, |
| 364 |
{ "auth-server", 1, 0, LOPT_AUTHSERV }, |
| 365 |
{ "auth-ttl", 1, 0, LOPT_AUTHTTL }, |
| 366 |
{ "auth-soa", 1, 0, LOPT_AUTHSOA }, |
| 367 |
{ "auth-sec-servers", 1, 0, LOPT_AUTHSFS }, |
| 368 |
{ "auth-peer", 1, 0, LOPT_AUTHPEER }, |
| 369 |
{ "ipset", 1, 0, LOPT_IPSET }, |
| 370 |
{ "nftset", 1, 0, LOPT_NFTSET }, |
| 371 |
{ "connmark-allowlist-enable", 2, 0, LOPT_CMARK_ALST_EN }, |
| 372 |
{ "connmark-allowlist", 1, 0, LOPT_CMARK_ALST }, |
| 373 |
{ "synth-domain", 1, 0, LOPT_SYNTH }, |
| 374 |
{ "dnssec", 0, 0, LOPT_SEC_VALID }, |
| 375 |
{ "trust-anchor", 1, 0, LOPT_TRUST_ANCHOR }, |
| 376 |
{ "dnssec-debug", 0, 0, LOPT_DNSSEC_DEBUG }, |
| 377 |
{ "dnssec-check-unsigned", 2, 0, LOPT_DNSSEC_CHECK }, |
| 378 |
{ "dnssec-no-timecheck", 0, 0, LOPT_DNSSEC_TIME }, |
| 379 |
{ "dnssec-timestamp", 1, 0, LOPT_DNSSEC_STAMP }, |
| 380 |
{ "dnssec-limits", 1, 0, LOPT_DNSSEC_LIMITS }, |
| 381 |
{ "dhcp-relay", 1, 0, LOPT_RELAY }, |
| 382 |
{ "dhcp-split-relay", 1, 0, LOPT_SPLIT_RELAY }, |
| 383 |
{ "ra-param", 1, 0, LOPT_RA_PARAM }, |
| 384 |
{ "quiet-dhcp", 0, 0, LOPT_QUIET_DHCP }, |
| 385 |
{ "quiet-dhcp6", 0, 0, LOPT_QUIET_DHCP6 }, |
| 386 |
{ "quiet-ra", 0, 0, LOPT_QUIET_RA }, |
| 387 |
{ "dns-loop-detect", 0, 0, LOPT_LOOP_DETECT }, |
| 388 |
{ "script-arp", 0, 0, LOPT_SCRIPT_ARP }, |
| 389 |
{ "dhcp-ttl", 1, 0 , LOPT_DHCPTTL }, |
| 390 |
{ "dhcp-reply-delay", 1, 0, LOPT_REPLY_DELAY }, |
| 391 |
{ "dhcp-rapid-commit", 0, 0, LOPT_RAPID_COMMIT }, |
| 392 |
{ "dumpfile", 1, 0, LOPT_DUMPFILE }, |
| 393 |
{ "dumpmask", 1, 0, LOPT_DUMPMASK }, |
| 394 |
{ "dhcp-ignore-clid", 0, 0, LOPT_IGNORE_CLID }, |
| 395 |
{ "dynamic-host", 1, 0, LOPT_DYNHOST }, |
| 396 |
{ "log-debug", 0, 0, LOPT_LOG_DEBUG }, |
| 397 |
{ "umbrella", 2, 0, LOPT_UMBRELLA }, |
| 398 |
{ "quiet-tftp", 0, 0, LOPT_QUIET_TFTP }, |
| 399 |
{ "port-limit", 1, 0, LOPT_RANDPORT_LIM }, |
| 400 |
{ "fast-dns-retry", 2, 0, LOPT_FAST_RETRY }, |
| 401 |
{ "use-stale-cache", 2, 0 , LOPT_STALE_CACHE }, |
| 402 |
{ "no-ident", 0, 0, LOPT_NO_IDENT }, |
| 403 |
{ "max-tcp-connections", 1, 0, LOPT_MAX_PROCS }, |
| 404 |
{ "leasequery", 2, 0, LOPT_LEASEQUERY }, |
| 405 |
{ "log-malloc", 0, 0, LOPT_LOG_MALLOC }, |
| 406 |
{ NULL, 0, 0, 0 } |
| 407 |
}; |
| 408 |
|
| 409 |
|
| 410 |
#define ARG_DUP OPT_LAST |
| 411 |
#define ARG_ONE OPT_LAST + 1 |
| 412 |
#define ARG_USED_CL OPT_LAST + 2 |
| 413 |
#define ARG_USED_FILE OPT_LAST + 3 |
| 414 |
|
| 415 |
static struct { |
| 416 |
int opt; |
| 417 |
unsigned int rept; |
| 418 |
char * const flagdesc; |
| 419 |
char * const desc; |
| 420 |
char * const arg; |
| 421 |
} usage[] = { |
| 422 |
{ 'a', ARG_DUP, "<ipaddr>", gettext_noop("Specify local address(es) to listen on."), NULL }, |
| 423 |
{ 'A', ARG_DUP, "/<domain>/<ipaddr>", gettext_noop("Return ipaddr for all hosts in specified domains."), NULL }, |
| 424 |
{ 'b', OPT_BOGUSPRIV, NULL, gettext_noop("Fake reverse lookups for RFC1918 private address ranges."), NULL }, |
| 425 |
{ 'B', ARG_DUP, "<ipaddr>", gettext_noop("Treat ipaddr as NXDOMAIN (defeats Verisign wildcard)."), NULL }, |
| 426 |
{ 'c', ARG_ONE, "<integer>", gettext_noop("Specify the size of the cache in entries (defaults to %s)."), "$" }, |
| 427 |
{ 'C', ARG_DUP, "<path>", gettext_noop("Specify configuration file (defaults to %s)."), CONFFILE }, |
| 428 |
{ 'd', OPT_DEBUG, NULL, gettext_noop("Do NOT fork into the background: run in debug mode."), NULL }, |
| 429 |
{ 'D', OPT_NODOTS_LOCAL, NULL, gettext_noop("Do NOT forward queries with no domain part."), NULL }, |
| 430 |
{ 'e', OPT_SELFMX, NULL, gettext_noop("Return self-pointing MX records for local hosts."), NULL }, |
| 431 |
{ 'E', OPT_EXPAND, NULL, gettext_noop("Expand simple names in /etc/hosts with domain-suffix."), NULL }, |
| 432 |
{ 'f', OPT_FILTER, NULL, gettext_noop("Don't forward spurious DNS requests from Windows hosts."), NULL }, |
| 433 |
{ LOPT_FILTER_A, ARG_DUP, NULL, gettext_noop("Don't include IPv4 addresses in DNS answers."), NULL }, |
| 434 |
{ LOPT_FILTER_AAAA, ARG_DUP, NULL, gettext_noop("Don't include IPv6 addresses in DNS answers."), NULL }, |
| 435 |
{ LOPT_FILTER_RR, ARG_DUP, "<RR-type>", gettext_noop("Don't include resource records of the given type in DNS answers."), NULL }, |
| 436 |
{ 'F', ARG_DUP, "<ipaddr>,...", gettext_noop("Enable DHCP in the range given with lease duration."), NULL }, |
| 437 |
{ 'g', ARG_ONE, "<groupname>", gettext_noop("Change to this group after startup (defaults to %s)."), CHGRP }, |
| 438 |
{ 'G', ARG_DUP, "<hostspec>", gettext_noop("Set address or hostname for a specified machine."), NULL }, |
| 439 |
{ LOPT_DHCP_HOST, ARG_DUP, "<path>", gettext_noop("Read DHCP host specs from file."), NULL }, |
| 440 |
{ LOPT_DHCP_OPTS, ARG_DUP, "<path>", gettext_noop("Read DHCP option specs from file."), NULL }, |
| 441 |
{ LOPT_DHCP_INOTIFY, ARG_DUP, "<path>", gettext_noop("Read DHCP host specs from a directory."), NULL }, |
| 442 |
{ LOPT_DHOPT_INOTIFY, ARG_DUP, "<path>", gettext_noop("Read DHCP options from a directory."), NULL }, |
| 443 |
{ LOPT_TAG_IF, ARG_DUP, "tag-expression", gettext_noop("Evaluate conditional tag expression."), NULL }, |
| 444 |
{ 'h', OPT_NO_HOSTS, NULL, gettext_noop("Do NOT load %s file."), HOSTSFILE }, |
| 445 |
{ 'H', ARG_DUP, "<path>", gettext_noop("Specify a hosts file to be read in addition to %s."), HOSTSFILE }, |
| 446 |
{ LOPT_HOST_INOTIFY, ARG_DUP, "<path>", gettext_noop("Read hosts files from a directory."), NULL }, |
| 447 |
{ 'i', ARG_DUP, "<interface>", gettext_noop("Specify interface(s) to listen on."), NULL }, |
| 448 |
{ 'I', ARG_DUP, "<interface>", gettext_noop("Specify interface(s) NOT to listen on.") , NULL }, |
| 449 |
{ 'j', ARG_DUP, "set:<tag>,<class>", gettext_noop("Map DHCP user class to tag."), NULL }, |
| 450 |
{ LOPT_CIRCUIT, ARG_DUP, "set:<tag>,<circuit>", gettext_noop("Map RFC3046 circuit-id to tag."), NULL }, |
| 451 |
{ LOPT_REMOTE, ARG_DUP, "set:<tag>,<remote>", gettext_noop("Map RFC3046 remote-id to tag."), NULL }, |
| 452 |
{ LOPT_SUBSCR, ARG_DUP, "set:<tag>,<remote>", gettext_noop("Map RFC3993 subscriber-id to tag."), NULL }, |
| 453 |
{ LOPT_PXE_VENDOR, ARG_DUP, "<vendor>[,...]", gettext_noop("Specify vendor class to match for PXE requests."), NULL }, |
| 454 |
{ 'J', ARG_DUP, "tag:<tag>...", gettext_noop("Don't do DHCP for hosts with tag set."), NULL }, |
| 455 |
{ LOPT_BROADCAST, ARG_DUP, "[=tag:<tag>...]", gettext_noop("Force broadcast replies for hosts with tag set."), NULL }, |
| 456 |
{ 'k', OPT_NO_FORK, NULL, gettext_noop("Do NOT fork into the background, do NOT run in debug mode."), NULL }, |
| 457 |
{ 'K', OPT_AUTHORITATIVE, NULL, gettext_noop("Assume we are the only DHCP server on the local network."), NULL }, |
| 458 |
{ 'l', ARG_ONE, "<path>", gettext_noop("Specify where to store DHCP leases (defaults to %s)."), LEASEFILE }, |
| 459 |
{ 'L', OPT_LOCALMX, NULL, gettext_noop("Return MX records for local hosts."), NULL }, |
| 460 |
{ 'm', ARG_DUP, "<host_name>,<target>,<pref>", gettext_noop("Specify an MX record."), NULL }, |
| 461 |
{ 'M', ARG_DUP, "<bootp opts>", gettext_noop("Specify BOOTP options to DHCP server."), NULL }, |
| 462 |
{ 'n', OPT_NO_POLL, NULL, gettext_noop("Do NOT poll %s file, reload only on SIGHUP."), RESOLVFILE }, |
| 463 |
{ 'N', OPT_NO_NEG, NULL, gettext_noop("Do NOT cache failed search results."), NULL }, |
| 464 |
{ LOPT_STALE_CACHE, ARG_ONE, "[=<max_expired>]", gettext_noop("Use expired cache data for faster reply."), NULL }, |
| 465 |
{ 'o', OPT_ORDER, NULL, gettext_noop("Use nameservers strictly in the order given in %s."), RESOLVFILE }, |
| 466 |
{ 'O', ARG_DUP, "<optspec>", gettext_noop("Specify options to be sent to DHCP clients."), NULL }, |
| 467 |
{ LOPT_FORCE, ARG_DUP, "<optspec>", gettext_noop("DHCP option sent even if the client does not request it."), NULL}, |
| 468 |
{ LOPT_PXE_OPT, ARG_DUP, "<optspec>", gettext_noop("DHCP option sent only to PXE clients."), NULL}, |
| 469 |
{ 'p', ARG_ONE, "<integer>", gettext_noop("Specify port to listen for DNS requests on (defaults to 53)."), NULL }, |
| 470 |
{ 'P', ARG_ONE, "<integer>", gettext_noop("Maximum supported UDP packet size for EDNS.0 (defaults to %s)."), "*" }, |
| 471 |
{ 'q', ARG_DUP, NULL, gettext_noop("Log DNS queries."), NULL }, |
| 472 |
{ 'Q', ARG_ONE, "<integer>", gettext_noop("Force the originating port for upstream DNS queries."), NULL }, |
| 473 |
{ LOPT_RANDPORT_LIM, ARG_ONE, "#ports", gettext_noop("Set maximum number of random originating ports for a query."), NULL }, |
| 474 |
{ 'R', OPT_NO_RESOLV, NULL, gettext_noop("Do NOT read resolv.conf."), NULL }, |
| 475 |
{ 'r', ARG_DUP, "<path>", gettext_noop("Specify path to resolv.conf (defaults to %s)."), RESOLVFILE }, |
| 476 |
{ LOPT_SERVERS_FILE, ARG_ONE, "<path>", gettext_noop("Specify path to file with server= options"), NULL }, |
| 477 |
{ 'S', ARG_DUP, "/<domain>/<ipaddr>", gettext_noop("Specify address(es) of upstream servers with optional domains."), NULL }, |
| 478 |
{ LOPT_REV_SERV, ARG_DUP, "<addr>/<prefix>,<ipaddr>", gettext_noop("Specify address of upstream servers for reverse address queries"), NULL }, |
| 479 |
{ LOPT_LOCAL, ARG_DUP, "/<domain>/", gettext_noop("Never forward queries to specified domains."), NULL }, |
| 480 |
{ 's', ARG_DUP, "<domain>[,<range>]", gettext_noop("Specify the domain to be assigned in DHCP leases."), NULL }, |
| 481 |
{ 't', ARG_ONE, "<host_name>", gettext_noop("Specify default target in an MX record."), NULL }, |
| 482 |
{ 'T', ARG_ONE, "<integer>", gettext_noop("Specify time-to-live in seconds for replies from /etc/hosts."), NULL }, |
| 483 |
{ LOPT_NEGTTL, ARG_ONE, "<integer>", gettext_noop("Specify time-to-live in seconds for negative caching."), NULL }, |
| 484 |
{ LOPT_MAXTTL, ARG_ONE, "<integer>", gettext_noop("Specify time-to-live in seconds for maximum TTL to send to clients."), NULL }, |
| 485 |
{ LOPT_MAXCTTL, ARG_ONE, "<integer>", gettext_noop("Specify time-to-live ceiling for cache."), NULL }, |
| 486 |
{ LOPT_MINCTTL, ARG_ONE, "<integer>", gettext_noop("Specify time-to-live floor for cache."), NULL }, |
| 487 |
{ LOPT_FAST_RETRY, ARG_ONE, "<milliseconds>", gettext_noop("Retry DNS queries after this many milliseconds."), NULL}, |
| 488 |
{ 'u', ARG_ONE, "<username>", gettext_noop("Change to this user after startup. (defaults to %s)."), CHUSER }, |
| 489 |
{ 'U', ARG_DUP, "set:<tag>,<class>", gettext_noop("Map DHCP vendor class to tag."), NULL }, |
| 490 |
{ 'v', 0, NULL, gettext_noop("Display dnsmasq version and copyright information."), NULL }, |
| 491 |
{ 'V', ARG_DUP, "<ipaddr>,<ipaddr>,<netmask>", gettext_noop("Translate IPv4 addresses from upstream servers."), NULL }, |
| 492 |
{ 'W', ARG_DUP, "<name>,<target>,...", gettext_noop("Specify a SRV record."), NULL }, |
| 493 |
{ 'w', 0, NULL, gettext_noop("Display this message. Use --help dhcp or --help dhcp6 for known DHCP options."), NULL }, |
| 494 |
{ 'x', ARG_ONE, "<path>", gettext_noop("Specify path of PID file (defaults to %s)."), RUNFILE }, |
| 495 |
{ 'X', ARG_ONE, "<integer>", gettext_noop("Specify maximum number of DHCP leases (defaults to %s)."), "&" }, |
| 496 |
{ 'y', OPT_LOCALISE, NULL, gettext_noop("Answer DNS queries based on the interface a query was sent to."), NULL }, |
| 497 |
{ 'Y', ARG_DUP, "<name>,<txt>[,<txt]", gettext_noop("Specify TXT DNS record."), NULL }, |
| 498 |
{ LOPT_PTR, ARG_DUP, "<name>,<target>", gettext_noop("Specify PTR DNS record."), NULL }, |
| 499 |
{ LOPT_INTNAME, ARG_DUP, "<name>,<interface>", gettext_noop("Give DNS name to IPv4 address of interface."), NULL }, |
| 500 |
{ 'z', OPT_NOWILD, NULL, gettext_noop("Bind only to interfaces in use."), NULL }, |
| 501 |
{ 'Z', OPT_ETHERS, NULL, gettext_noop("Read DHCP static host information from %s."), ETHERSFILE }, |
| 502 |
{ '1', ARG_ONE, "[=<busname>]", gettext_noop("Enable the DBus interface for setting upstream servers, etc."), NULL }, |
| 503 |
{ LOPT_UBUS, ARG_ONE, "[=<busname>]", gettext_noop("Enable the UBus interface."), NULL }, |
| 504 |
{ '2', ARG_DUP, "<interface>", gettext_noop("Do not provide DHCP on this interface, only provide DNS."), NULL }, |
| 505 |
{ LOPT_NO_DHCP6, ARG_DUP, "<interface>", gettext_noop("Do not provide DHCPv6 on this interface."), NULL }, |
| 506 |
{ LOPT_NO_DHCP4, ARG_DUP, "<interface>", gettext_noop("Do not provide DHCPv4 on this interface."), NULL }, |
| 507 |
{ '3', ARG_DUP, "[=tag:<tag>]...", gettext_noop("Enable dynamic address allocation for bootp."), NULL }, |
| 508 |
{ '4', ARG_DUP, "set:<tag>,<mac address>", gettext_noop("Map MAC address (with wildcards) to option set."), NULL }, |
| 509 |
{ LOPT_BRIDGE, ARG_DUP, "<iface>,<alias>..", gettext_noop("Treat DHCP requests on aliases as arriving from interface."), NULL }, |
| 510 |
{ LOPT_SHARED_NET, ARG_DUP, "<iface>|<addr>,<addr>", gettext_noop("Specify extra networks sharing a broadcast domain for DHCP"), NULL}, |
| 511 |
{ LOPT_LEASEQUERY, ARG_DUP, "[<addr>[/prefix>]]", gettext_noop("Enable RFC 4388 leasequery functions for DHCPv4"), NULL }, |
| 512 |
{ '5', OPT_NO_PING, NULL, gettext_noop("Disable ICMP echo address checking in the DHCP server."), NULL }, |
| 513 |
{ '6', ARG_ONE, "<path>", gettext_noop("Shell script to run on DHCP lease creation and destruction."), NULL }, |
| 514 |
{ LOPT_LUASCRIPT, ARG_DUP, "path", gettext_noop("Lua script to run on DHCP lease creation and destruction."), NULL }, |
| 515 |
{ LOPT_SCRIPTUSR, ARG_ONE, "<username>", gettext_noop("Run lease-change scripts as this user."), NULL }, |
| 516 |
{ LOPT_SCRIPT_ARP, OPT_SCRIPT_ARP, NULL, gettext_noop("Call dhcp-script with changes to local ARP table."), NULL }, |
| 517 |
{ '7', ARG_DUP, "<path>", gettext_noop("Read configuration from all the files in this directory."), NULL }, |
| 518 |
{ LOPT_CONF_SCRIPT, ARG_DUP, "<path>", gettext_noop("Execute file and read configuration from stdin."), NULL }, |
| 519 |
{ '8', ARG_ONE, "<facility>|<file>", gettext_noop("Log to this syslog facility or file. (defaults to DAEMON)"), NULL }, |
| 520 |
{ '9', OPT_LEASE_RO, NULL, gettext_noop("Do not use leasefile."), NULL }, |
| 521 |
{ '0', ARG_ONE, "<integer>", gettext_noop("Maximum number of concurrent DNS queries. (defaults to %s)"), "!" }, |
| 522 |
{ LOPT_RELOAD, OPT_RELOAD, NULL, gettext_noop("Clear DNS cache when reloading %s."), RESOLVFILE }, |
| 523 |
{ LOPT_NO_NAMES, ARG_DUP, "[=tag:<tag>]...", gettext_noop("Ignore hostnames provided by DHCP clients."), NULL }, |
| 524 |
{ LOPT_OVERRIDE, OPT_NO_OVERRIDE, NULL, gettext_noop("Do NOT reuse filename and server fields for extra DHCP options."), NULL }, |
| 525 |
{ LOPT_TFTP, ARG_DUP, "[=<intr>[,<intr>]]", gettext_noop("Enable integrated read-only TFTP server."), NULL }, |
| 526 |
{ LOPT_PREFIX, ARG_DUP, "<dir>[,<iface>]", gettext_noop("Export files by TFTP only from the specified subtree."), NULL }, |
| 527 |
{ LOPT_APREF, ARG_DUP, "[=ip|mac]", gettext_noop("Add client IP or hardware address to tftp-root."), NULL }, |
| 528 |
{ LOPT_SECURE, OPT_TFTP_SECURE, NULL, gettext_noop("Allow access only to files owned by the user running dnsmasq."), NULL }, |
| 529 |
{ LOPT_TFTP_NO_FAIL, OPT_TFTP_NO_FAIL, NULL, gettext_noop("Do not terminate the service if TFTP directories are inaccessible."), NULL }, |
| 530 |
{ LOPT_TFTP_MAX, ARG_ONE, "<integer>", gettext_noop("Maximum number of concurrent TFTP transfers (defaults to %s)."), "#" }, |
| 531 |
{ LOPT_TFTP_MTU, ARG_ONE, "<integer>", gettext_noop("Maximum MTU to use for TFTP transfers."), NULL }, |
| 532 |
{ LOPT_NOBLOCK, OPT_TFTP_NOBLOCK, NULL, gettext_noop("Disable the TFTP blocksize extension."), NULL }, |
| 533 |
{ LOPT_TFTP_LC, OPT_TFTP_LC, NULL, gettext_noop("Convert TFTP filenames to lowercase"), NULL }, |
| 534 |
{ LOPT_TFTPPORTS, ARG_ONE, "<start>,<end>", gettext_noop("Ephemeral port range for use by TFTP transfers."), NULL }, |
| 535 |
{ LOPT_SINGLE_PORT, OPT_SINGLE_PORT, NULL, gettext_noop("Use only one port for TFTP server."), NULL }, |
| 536 |
{ LOPT_LOG_OPTS, OPT_LOG_OPTS, NULL, gettext_noop("Extra logging for DHCP."), NULL }, |
| 537 |
{ LOPT_MAX_LOGS, ARG_ONE, "[=<integer>]", gettext_noop("Enable async. logging; optionally set queue length."), NULL }, |
| 538 |
{ LOPT_REBIND, OPT_NO_REBIND, NULL, gettext_noop("Stop DNS rebinding. Filter private IP ranges when resolving."), NULL }, |
| 539 |
{ LOPT_LOC_REBND, OPT_LOCAL_REBIND, NULL, gettext_noop("Allow rebinding of 127.0.0.0/8, for RBL servers."), NULL }, |
| 540 |
{ LOPT_NO_REBIND, ARG_DUP, "/<domain>/", gettext_noop("Inhibit DNS-rebind protection on this domain."), NULL }, |
| 541 |
{ LOPT_NOLAST, OPT_ALL_SERVERS, NULL, gettext_noop("Always perform DNS queries to all servers."), NULL }, |
| 542 |
{ LOPT_MATCH, ARG_DUP, "set:<tag>,<optspec>", gettext_noop("Set tag if client includes matching option in request."), NULL }, |
| 543 |
{ LOPT_NAME_MATCH, ARG_DUP, "set:<tag>,<string>[*]", gettext_noop("Set tag if client provides given name."), NULL }, |
| 544 |
{ LOPT_ALTPORT, ARG_ONE, "[=<ports>]", gettext_noop("Use alternative ports for DHCP."), NULL }, |
| 545 |
{ LOPT_NAPTR, ARG_DUP, "<name>,<naptr>", gettext_noop("Specify NAPTR DNS record."), NULL }, |
| 546 |
{ LOPT_MINPORT, ARG_ONE, "<port>", gettext_noop("Specify lowest port available for DNS query transmission."), NULL }, |
| 547 |
{ LOPT_MAXPORT, ARG_ONE, "<port>", gettext_noop("Specify highest port available for DNS query transmission."), NULL }, |
| 548 |
{ LOPT_DHCP_FQDN, OPT_DHCP_FQDN, NULL, gettext_noop("Use only fully qualified domain names for DHCP clients."), NULL }, |
| 549 |
{ LOPT_GEN_NAMES, ARG_DUP, "[=tag:<tag>]", gettext_noop("Generate hostnames based on MAC address for nameless clients."), NULL}, |
| 550 |
{ LOPT_PROXY, ARG_DUP, "[=<ipaddr>]...", gettext_noop("Use these DHCP relays as full proxies."), NULL }, |
| 551 |
{ LOPT_RELAY, ARG_DUP, "<local-addr>,<server>[,<iface>]", gettext_noop("Relay DHCP requests to a remote server"), NULL}, |
| 552 |
{ LOPT_SPLIT_RELAY, ARG_DUP, "<local-addr>,<server>,<iface>", gettext_noop("Relay DHCP requests to a remote server"), NULL}, |
| 553 |
{ LOPT_CNAME, ARG_DUP, "<alias>,<target>[,<ttl>]", gettext_noop("Specify alias name for LOCAL DNS name."), NULL }, |
| 554 |
{ LOPT_PXE_PROMT, ARG_DUP, "<prompt>,[<timeout>]", gettext_noop("Prompt to send to PXE clients."), NULL }, |
| 555 |
{ LOPT_PXE_SERV, ARG_DUP, "<service>", gettext_noop("Boot service for PXE menu."), NULL }, |
| 556 |
{ LOPT_TEST, 0, NULL, gettext_noop("Check configuration syntax."), NULL }, |
| 557 |
{ LOPT_ADD_MAC, ARG_DUP, "[=base64|text]", gettext_noop("Add requestor's MAC address to forwarded DNS queries."), NULL }, |
| 558 |
{ LOPT_STRIP_MAC, OPT_STRIP_MAC, NULL, gettext_noop("Strip MAC information from queries."), NULL }, |
| 559 |
{ LOPT_ADD_SBNET, ARG_ONE, "<v4 pref>[,<v6 pref>]", gettext_noop("Add specified IP subnet to forwarded DNS queries."), NULL }, |
| 560 |
{ LOPT_STRIP_SBNET, OPT_STRIP_ECS, NULL, gettext_noop("Strip ECS information from queries."), NULL }, |
| 561 |
{ LOPT_CPE_ID, ARG_ONE, "<text>", gettext_noop("Add client identification to forwarded DNS queries."), NULL }, |
| 562 |
{ LOPT_DNSSEC, OPT_DNSSEC_PROXY, NULL, gettext_noop("Proxy DNSSEC validation results from upstream nameservers."), NULL }, |
| 563 |
{ LOPT_INCR_ADDR, OPT_CONSEC_ADDR, NULL, gettext_noop("Attempt to allocate sequential IP addresses to DHCP clients."), NULL }, |
| 564 |
{ LOPT_IGNORE_CLID, OPT_IGNORE_CLID, NULL, gettext_noop("Ignore client identifier option sent by DHCP clients."), NULL }, |
| 565 |
{ LOPT_CONNTRACK, OPT_CONNTRACK, NULL, gettext_noop("Copy connection-track mark from queries to upstream connections."), NULL }, |
| 566 |
{ LOPT_FQDN, OPT_FQDN_UPDATE, NULL, gettext_noop("Allow DHCP clients to do their own DDNS updates."), NULL }, |
| 567 |
{ LOPT_RA, OPT_RA, NULL, gettext_noop("Send router-advertisements for interfaces doing DHCPv6"), NULL }, |
| 568 |
{ LOPT_DUID, ARG_ONE, "<enterprise>,<duid>", gettext_noop("Specify DUID_EN-type DHCPv6 server DUID"), NULL }, |
| 569 |
{ LOPT_HOST_REC, ARG_DUP, "<name>,<address>[,<ttl>]", gettext_noop("Specify host (A/AAAA and PTR) records"), NULL }, |
| 570 |
{ LOPT_DYNHOST, ARG_DUP, "<name>,[<IPv4>][,<IPv6>],<interface-name>", gettext_noop("Specify host record in interface subnet"), NULL }, |
| 571 |
{ LOPT_CAA, ARG_DUP, "<name>,<flags>,<tag>,<value>", gettext_noop("Specify certification authority authorization record"), NULL }, |
| 572 |
{ LOPT_RR, ARG_DUP, "<name>,<RR-number>,[<data>]", gettext_noop("Specify arbitrary DNS resource record"), NULL }, |
| 573 |
{ LOPT_CLVERBIND, OPT_CLEVERBIND, NULL, gettext_noop("Bind to interfaces in use - check for new interfaces"), NULL }, |
| 574 |
{ LOPT_AUTHSERV, ARG_ONE, "<NS>,<interface>", gettext_noop("Export local names to global DNS"), NULL }, |
| 575 |
{ LOPT_AUTHZONE, ARG_DUP, "<domain>,[<subnet>...]", gettext_noop("Domain to export to global DNS"), NULL }, |
| 576 |
{ LOPT_AUTHTTL, ARG_ONE, "<integer>", gettext_noop("Set TTL for authoritative replies"), NULL }, |
| 577 |
{ LOPT_AUTHSOA, ARG_ONE, "<serial>[,...]", gettext_noop("Set authoritative zone information"), NULL }, |
| 578 |
{ LOPT_AUTHSFS, ARG_DUP, "<NS>[,<NS>...]", gettext_noop("Secondary authoritative nameservers for forward domains"), NULL }, |
| 579 |
{ LOPT_AUTHPEER, ARG_DUP, "<ipaddr>[,<ipaddr>...]", gettext_noop("Peers which are allowed to do zone transfer"), NULL }, |
| 580 |
{ LOPT_IPSET, ARG_DUP, "/<domain>[/<domain>...]/<ipset>...", gettext_noop("Specify ipsets to which matching domains should be added"), NULL }, |
| 581 |
{ LOPT_NFTSET, ARG_DUP, "/<domain>[/<domain>...]/<nftset>...", gettext_noop("Specify nftables sets to which matching domains should be added"), NULL }, |
| 582 |
{ LOPT_CMARK_ALST_EN, ARG_ONE, "[=<mask>]", gettext_noop("Enable filtering of DNS queries with connection-track marks."), NULL }, |
| 583 |
{ LOPT_CMARK_ALST, ARG_DUP, "<connmark>[/<mask>][,<pattern>[/<pattern>...]]", gettext_noop("Set allowed DNS patterns for a connection-track mark."), NULL }, |
| 584 |
{ LOPT_SYNTH, ARG_DUP, "<domain>,<range>,[<prefix>]", gettext_noop("Specify a domain and address range for synthesised names"), NULL }, |
| 585 |
{ LOPT_SEC_VALID, OPT_DNSSEC_VALID, NULL, gettext_noop("Activate DNSSEC validation"), NULL }, |
| 586 |
{ LOPT_TRUST_ANCHOR, ARG_DUP, "<domain>,[<class>,]...", gettext_noop("Specify trust anchor key digest."), NULL }, |
| 587 |
{ LOPT_DNSSEC_DEBUG, OPT_DNSSEC_DEBUG, NULL, gettext_noop("Disable upstream checking for DNSSEC debugging."), NULL }, |
| 588 |
{ LOPT_DNSSEC_CHECK, ARG_DUP, NULL, gettext_noop("Ensure answers without DNSSEC are in unsigned zones."), NULL }, |
| 589 |
{ LOPT_DNSSEC_TIME, OPT_DNSSEC_TIME, NULL, gettext_noop("Don't check DNSSEC signature timestamps until first cache-reload"), NULL }, |
| 590 |
{ LOPT_DNSSEC_STAMP, ARG_ONE, "<path>", gettext_noop("Timestamp file to verify system clock for DNSSEC"), NULL }, |
| 591 |
{ LOPT_DNSSEC_LIMITS, ARG_ONE, "<limit>,..", gettext_noop("Set resource limits for DNSSEC validation"), NULL }, |
| 592 |
{ LOPT_RA_PARAM, ARG_DUP, "<iface>,[mtu:<value>|<interface>|off,][<prio>,]<intval>[,<lifetime>]", gettext_noop("Set MTU, priority, resend-interval and router-lifetime"), NULL }, |
| 593 |
{ LOPT_QUIET_DHCP, OPT_QUIET_DHCP, NULL, gettext_noop("Do not log routine DHCP."), NULL }, |
| 594 |
{ LOPT_QUIET_DHCP6, OPT_QUIET_DHCP6, NULL, gettext_noop("Do not log routine DHCPv6."), NULL }, |
| 595 |
{ LOPT_QUIET_RA, OPT_QUIET_RA, NULL, gettext_noop("Do not log RA."), NULL }, |
| 596 |
{ LOPT_LOG_DEBUG, OPT_LOG_DEBUG, NULL, gettext_noop("Log debugging information."), NULL }, |
| 597 |
{ LOPT_LOCAL_SERVICE, ARG_ONE, NULL, gettext_noop("Accept queries only from directly-connected networks."), NULL }, |
| 598 |
{ LOPT_LOOP_DETECT, OPT_LOOP_DETECT, NULL, gettext_noop("Detect and remove DNS forwarding loops."), NULL }, |
| 599 |
{ LOPT_IGNORE_ADDR, ARG_DUP, "<ipaddr>", gettext_noop("Ignore DNS responses containing ipaddr."), NULL }, |
| 600 |
{ LOPT_DHCPTTL, ARG_ONE, "<ttl>", gettext_noop("Set TTL in DNS responses with DHCP-derived addresses."), NULL }, |
| 601 |
{ LOPT_REPLY_DELAY, ARG_ONE, "<integer>", gettext_noop("Delay DHCP replies for at least number of seconds."), NULL }, |
| 602 |
{ LOPT_RAPID_COMMIT, OPT_RAPID_COMMIT, NULL, gettext_noop("Enables DHCPv4 Rapid Commit option."), NULL }, |
| 603 |
{ LOPT_DUMPFILE, ARG_ONE, "<path>", gettext_noop("Path to debug packet dump file."), NULL }, |
| 604 |
{ LOPT_DUMPMASK, ARG_ONE, "<hex>", gettext_noop("Mask which packets to dump."), NULL }, |
| 605 |
{ LOPT_SCRIPT_TIME, OPT_LEASE_RENEW, NULL, gettext_noop("Call dhcp-script when lease expiry changes."), NULL }, |
| 606 |
{ LOPT_UMBRELLA, ARG_ONE, "[=<optspec>]", gettext_noop("Send Cisco Umbrella identifiers including remote IP."), NULL }, |
| 607 |
{ LOPT_QUIET_TFTP, OPT_QUIET_TFTP, NULL, gettext_noop("Do not log routine TFTP."), NULL }, |
| 608 |
{ LOPT_NORR, OPT_NORR, NULL, gettext_noop("Suppress round-robin ordering of DNS records."), NULL }, |
| 609 |
{ LOPT_NO_ENCODE, OPT_NO_0x20, NULL, gettext_noop("Suppress DNS bit 0x20 encoding."), NULL }, |
| 610 |
{ LOPT_DO_ENCODE, OPT_DO_0x20, NULL, gettext_noop("Enable DNS bit 0x20 encoding."), NULL }, |
| 611 |
{ LOPT_NO_IDENT, OPT_NO_IDENT, NULL, gettext_noop("Do not add CHAOS TXT records."), NULL }, |
| 612 |
{ LOPT_CACHE_RR, ARG_DUP, "<RR-type>", gettext_noop("Cache this DNS resource record type."), NULL }, |
| 613 |
{ LOPT_MAX_PROCS, ARG_ONE, "<integer>", gettext_noop("Maximum number of concurrent tcp connections."), NULL }, |
| 614 |
{ LOPT_LOG_MALLOC, OPT_LOG_MALLOC, NULL, gettext_noop("Log memory allocation for debugging."), NULL }, |
| 615 |
{ 0, 0, NULL, NULL, NULL } |
| 616 |
}; |
| 617 |
|
| 618 |
/* We hide metacharacters in quoted strings by mapping them into the ASCII control |
| 619 |
character space. Note that the \0, \t \b \r \033 and \n characters are carefully placed in the |
| 620 |
following sequence so that they map to themselves: it is therefore possible to call |
| 621 |
unhide_metas repeatedly on string without breaking things. |
| 622 |
The transformation gets undone by opt_canonicalise, atoi_check and opt_string_alloc, and a |
| 623 |
couple of other places. |
| 624 |
Note that space is included here so that |
| 625 |
--dhcp-option=3, string |
| 626 |
has five characters, whilst |
| 627 |
--dhcp-option=3," string" |
| 628 |
has six. |
| 629 |
*/ |
| 630 |
|
| 631 |
static const char meta[] = "\000123456 \b\t\n78\r90abcdefABCDE\033F:,."; |
| 632 |
|
| 633 |
static char hide_meta(char c) |
| 634 |
{ |
| 635 |
unsigned int i; |
| 636 |
|
| 637 |
for (i = 0; i < (sizeof(meta) - 1); i++) |
| 638 |
if (c == meta[i]) |
| 639 |
return (char)i; |
| 640 |
|
| 641 |
return c; |
| 642 |
} |
| 643 |
|
| 644 |
static char unhide_meta(char cr) |
| 645 |
{ |
| 646 |
unsigned int c = cr; |
| 647 |
|
| 648 |
if (c < (sizeof(meta) - 1)) |
| 649 |
cr = meta[c]; |
| 650 |
|
| 651 |
return cr; |
| 652 |
} |
| 653 |
|
| 654 |
static void unhide_metas(char *cp) |
| 655 |
{ |
| 656 |
if (cp) |
| 657 |
for(; *cp; cp++) |
| 658 |
*cp = unhide_meta(*cp); |
| 659 |
} |
| 660 |
|
| 661 |
static void *opt_malloc_real(const char *func, unsigned int line, size_t size) |
| 662 |
{ |
| 663 |
void *ret; |
| 664 |
|
| 665 |
if (mem_recover) |
| 666 |
{ |
| 667 |
ret = whine_malloc_real(func, line, size); |
| 668 |
if (!ret) |
| 669 |
longjmp(mem_jmp, 1); |
| 670 |
} |
| 671 |
else |
| 672 |
ret = safe_malloc(size); |
| 673 |
|
| 674 |
return ret; |
| 675 |
} |
| 676 |
|
| 677 |
static char *opt_string_alloc(const char *cp) |
| 678 |
{ |
| 679 |
char *ret = NULL; |
| 680 |
size_t len; |
| 681 |
|
| 682 |
if (cp && (len = strlen(cp)) != 0) |
| 683 |
{ |
| 684 |
ret = opt_malloc(len+1); |
| 685 |
memcpy(ret, cp, len+1); |
| 686 |
|
| 687 |
/* restore hidden metachars */ |
| 688 |
unhide_metas(ret); |
| 689 |
} |
| 690 |
|
| 691 |
return ret; |
| 692 |
} |
| 693 |
|
| 694 |
|
| 695 |
/* find next comma, split string with zero and eliminate spaces. |
| 696 |
return start of string following comma */ |
| 697 |
|
| 698 |
static char *split_chr(char *s, char c) |
| 699 |
{ |
| 700 |
char *comma, *p; |
| 701 |
|
| 702 |
if (!s || !(comma = strchr(s, c))) |
| 703 |
return NULL; |
| 704 |
|
| 705 |
p = comma; |
| 706 |
*comma = ' '; |
| 707 |
|
| 708 |
for (; *comma == ' '; comma++); |
| 709 |
|
| 710 |
for (; (p >= s) && *p == ' '; p--) |
| 711 |
*p = 0; |
| 712 |
|
| 713 |
return comma; |
| 714 |
} |
| 715 |
|
| 716 |
static char *split(char *s) |
| 717 |
{ |
| 718 |
return split_chr(s, ','); |
| 719 |
} |
| 720 |
|
| 721 |
static char *canonicalise_opt(char *s) |
| 722 |
{ |
| 723 |
char *ret; |
| 724 |
int nomem; |
| 725 |
|
| 726 |
if (!s) |
| 727 |
return 0; |
| 728 |
|
| 729 |
if (strlen(s) == 0) |
| 730 |
return opt_malloc(1); /* Heap-allocated empty string */ |
| 731 |
|
| 732 |
unhide_metas(s); |
| 733 |
if (!(ret = canonicalise(s, &nomem)) && nomem) |
| 734 |
{ |
| 735 |
if (mem_recover) |
| 736 |
longjmp(mem_jmp, 1); |
| 737 |
else |
| 738 |
die(_("could not get memory"), NULL, EC_NOMEM); |
| 739 |
} |
| 740 |
|
| 741 |
return ret; |
| 742 |
} |
| 743 |
|
| 744 |
static int numeric_check(char *a) |
| 745 |
{ |
| 746 |
char *p; |
| 747 |
|
| 748 |
if (!a) |
| 749 |
return 0; |
| 750 |
|
| 751 |
unhide_metas(a); |
| 752 |
|
| 753 |
for (p = a; *p; p++) |
| 754 |
if (*p < '0' || *p > '9') |
| 755 |
return 0; |
| 756 |
|
| 757 |
return 1; |
| 758 |
} |
| 759 |
|
| 760 |
static int atoi_check(char *a, int *res) |
| 761 |
{ |
| 762 |
if (!numeric_check(a)) |
| 763 |
return 0; |
| 764 |
*res = atoi(a); |
| 765 |
return 1; |
| 766 |
} |
| 767 |
|
| 768 |
static int strtoul_check(char *a, u32 *res) |
| 769 |
{ |
| 770 |
unsigned long x; |
| 771 |
|
| 772 |
if (!numeric_check(a)) |
| 773 |
return 0; |
| 774 |
x = strtoul(a, NULL, 10); |
| 775 |
if (errno || x > UINT32_MAX) { |
| 776 |
errno = 0; |
| 777 |
return 0; |
| 778 |
} |
| 779 |
*res = (u32)x; |
| 780 |
return 1; |
| 781 |
} |
| 782 |
|
| 783 |
static int atoi_check16(char *a, int *res) |
| 784 |
{ |
| 785 |
if (!(atoi_check(a, res)) || |
| 786 |
*res < 0 || |
| 787 |
*res > 0xffff) |
| 788 |
return 0; |
| 789 |
|
| 790 |
return 1; |
| 791 |
} |
| 792 |
|
| 793 |
#ifdef HAVE_DNSSEC |
| 794 |
static int atoi_check8(char *a, int *res) |
| 795 |
{ |
| 796 |
if (!(atoi_check(a, res)) || |
| 797 |
*res < 0 || |
| 798 |
*res > 0xff) |
| 799 |
return 0; |
| 800 |
|
| 801 |
return 1; |
| 802 |
} |
| 803 |
#endif |
| 804 |
|
| 805 |
#ifndef NO_ID |
| 806 |
static void add_txt(char *name, char *txt, int stat) |
| 807 |
{ |
| 808 |
struct txt_record *r = opt_malloc(sizeof(struct txt_record)); |
| 809 |
|
| 810 |
if (txt) |
| 811 |
{ |
| 812 |
size_t len = strlen(txt); |
| 813 |
r->txt = opt_malloc(len+1); |
| 814 |
r->len = len+1; |
| 815 |
*(r->txt) = len; |
| 816 |
memcpy((r->txt)+1, txt, len); |
| 817 |
} |
| 818 |
|
| 819 |
r->stat = stat; |
| 820 |
r->name = opt_string_alloc(name); |
| 821 |
r->next = daemon->txt; |
| 822 |
daemon->txt = r; |
| 823 |
r->class = C_CHAOS; |
| 824 |
} |
| 825 |
#endif |
| 826 |
|
| 827 |
static void do_usage(void) |
| 828 |
{ |
| 829 |
char buff[100]; |
| 830 |
int i, j; |
| 831 |
|
| 832 |
struct { |
| 833 |
char handle; |
| 834 |
int val; |
| 835 |
} tab[] = { |
| 836 |
{ '$', CACHESIZ }, |
| 837 |
{ '*', EDNS_PKTSZ }, |
| 838 |
{ '&', MAXLEASES }, |
| 839 |
{ '!', FTABSIZ }, |
| 840 |
{ '#', TFTP_MAX_CONNECTIONS }, |
| 841 |
{ '\0', 0 } |
| 842 |
}; |
| 843 |
|
| 844 |
printf(_("Usage: dnsmasq [options]\n\n")); |
| 845 |
#ifndef HAVE_GETOPT_LONG |
| 846 |
printf(_("Use short options only on the command line.\n")); |
| 847 |
#endif |
| 848 |
printf(_("Valid options are:\n")); |
| 849 |
|
| 850 |
for (i = 0; usage[i].opt != 0; i++) |
| 851 |
{ |
| 852 |
char *desc = usage[i].flagdesc; |
| 853 |
char *eq = "="; |
| 854 |
|
| 855 |
if (!desc || *desc == '[') |
| 856 |
eq = ""; |
| 857 |
|
| 858 |
if (!desc) |
| 859 |
desc = ""; |
| 860 |
|
| 861 |
for ( j = 0; opts[j].name; j++) |
| 862 |
if (opts[j].val == usage[i].opt) |
| 863 |
break; |
| 864 |
if (usage[i].opt < 256) |
| 865 |
sprintf(buff, "-%c, ", usage[i].opt); |
| 866 |
else |
| 867 |
sprintf(buff, " "); |
| 868 |
|
| 869 |
sprintf(buff+4, "--%s%s%s", opts[j].name, eq, desc); |
| 870 |
printf("%-55.55s", buff); |
| 871 |
|
| 872 |
if (usage[i].arg) |
| 873 |
{ |
| 874 |
safe_strncpy(buff, usage[i].arg, sizeof(buff)); |
| 875 |
for (j = 0; tab[j].handle; j++) |
| 876 |
if (tab[j].handle == *(usage[i].arg)) |
| 877 |
sprintf(buff, "%d", tab[j].val); |
| 878 |
} |
| 879 |
printf(_(usage[i].desc), buff); |
| 880 |
printf("\n"); |
| 881 |
} |
| 882 |
} |
| 883 |
|
| 884 |
#define ret_err(x) do { strcpy(errstr, (x)); return 0; } while (0) |
| 885 |
#define ret_err_free(x,m) do { strcpy(errstr, (x)); free((m)); return 0; } while (0) |
| 886 |
#define goto_err(x) do { strcpy(errstr, (x)); goto on_error; } while (0) |
| 887 |
|
| 888 |
static char *parse_mysockaddr(char *arg, union mysockaddr *addr) |
| 889 |
{ |
| 890 |
if (inet_pton(AF_INET, arg, &addr->in.sin_addr) > 0) |
| 891 |
addr->sa.sa_family = AF_INET; |
| 892 |
else if (inet_pton(AF_INET6, arg, &addr->in6.sin6_addr) > 0) |
| 893 |
addr->sa.sa_family = AF_INET6; |
| 894 |
else |
| 895 |
return _("bad address"); |
| 896 |
|
| 897 |
return NULL; |
| 898 |
} |
| 899 |
|
| 900 |
char *parse_server(char *arg, struct server_details *sdetails) |
| 901 |
{ |
| 902 |
sdetails->serv_port = NAMESERVER_PORT; |
| 903 |
char *portno; |
| 904 |
int ecode = 0; |
| 905 |
struct addrinfo hints; |
| 906 |
|
| 907 |
memset(&hints, 0, sizeof(struct addrinfo)); |
| 908 |
|
| 909 |
*sdetails->interface = 0; |
| 910 |
sdetails->addr_type = AF_UNSPEC; |
| 911 |
|
| 912 |
if (strcmp(arg, "#") == 0) |
| 913 |
{ |
| 914 |
if (sdetails->flags) |
| 915 |
*sdetails->flags |= SERV_USE_RESOLV; |
| 916 |
sdetails->addr_type = AF_LOCAL; |
| 917 |
sdetails->valid = 1; |
| 918 |
return NULL; |
| 919 |
} |
| 920 |
|
| 921 |
if ((sdetails->source = split_chr(arg, '@')) && /* is there a source. */ |
| 922 |
(portno = split_chr(sdetails->source, '#')) && |
| 923 |
!atoi_check16(portno, &sdetails->source_port)) |
| 924 |
return _("bad port"); |
| 925 |
|
| 926 |
if ((portno = split_chr(arg, '#')) && /* is there a port no. */ |
| 927 |
!atoi_check16(portno, &sdetails->serv_port)) |
| 928 |
return _("bad port"); |
| 929 |
|
| 930 |
sdetails->scope_id = split_chr(arg, '%'); |
| 931 |
|
| 932 |
if (sdetails->source) { |
| 933 |
sdetails->interface_opt = split_chr(sdetails->source, '@'); |
| 934 |
|
| 935 |
if (sdetails->interface_opt) |
| 936 |
{ |
| 937 |
#if defined(SO_BINDTODEVICE) |
| 938 |
safe_strncpy(sdetails->interface, sdetails->source, IF_NAMESIZE); |
| 939 |
sdetails->source = sdetails->interface_opt; |
| 940 |
#else |
| 941 |
return _("interface binding not supported"); |
| 942 |
#endif |
| 943 |
} |
| 944 |
} |
| 945 |
|
| 946 |
if (inet_pton(AF_INET, arg, &sdetails->addr->in.sin_addr) > 0) |
| 947 |
sdetails->addr_type = AF_INET; |
| 948 |
else if (inet_pton(AF_INET6, arg, &sdetails->addr->in6.sin6_addr) > 0) |
| 949 |
sdetails->addr_type = AF_INET6; |
| 950 |
else |
| 951 |
{ |
| 952 |
/* if the argument is neither an IPv4 not an IPv6 address, it might be a |
| 953 |
hostname and we should try to resolve it to a suitable address. */ |
| 954 |
memset(&hints, 0, sizeof(hints)); |
| 955 |
/* The AI_ADDRCONFIG flag ensures that then IPv4 addresses are returned in |
| 956 |
the result only if the local system has at least one IPv4 address |
| 957 |
configured, and IPv6 addresses are returned only if the local system |
| 958 |
has at least one IPv6 address configured. The loopback address is not |
| 959 |
considered for this case as valid as a configured address. This flag is |
| 960 |
useful on, for example, IPv4-only systems, to ensure that getaddrinfo() |
| 961 |
does not return IPv6 socket addresses that would always fail in |
| 962 |
subsequent connect() or bind() attempts. */ |
| 963 |
hints.ai_flags = AI_ADDRCONFIG; |
| 964 |
#if defined(HAVE_IDN) && defined(AI_IDN) |
| 965 |
/* If the AI_IDN flag is specified and we have glibc 2.3.4 or newer, then |
| 966 |
the node name given in node is converted to IDN format if necessary. |
| 967 |
The source encoding is that of the current locale. */ |
| 968 |
hints.ai_flags |= AI_IDN; |
| 969 |
#endif |
| 970 |
/* The value AF_UNSPEC indicates that getaddrinfo() should return socket |
| 971 |
addresses for any address family (either IPv4 or IPv6, for example) |
| 972 |
that can be used with node <arg> and service "domain". */ |
| 973 |
hints.ai_family = AF_UNSPEC; |
| 974 |
|
| 975 |
/* Get addresses suitable for sending datagrams. We assume that we can use the |
| 976 |
same addresses for TCP connections. Setting this to zero gets each address |
| 977 |
threes times, for SOCK_STREAM, SOCK_RAW and SOCK_DGRAM, which is not useful. */ |
| 978 |
hints.ai_socktype = SOCK_DGRAM; |
| 979 |
|
| 980 |
/* Get address associated with this hostname */ |
| 981 |
ecode = getaddrinfo(arg, NULL, &hints, &sdetails->hostinfo); |
| 982 |
if (ecode == 0) |
| 983 |
{ |
| 984 |
/* The getaddrinfo() function allocated and initialized a linked list of |
| 985 |
addrinfo structures, one for each network address that matches node |
| 986 |
and service, subject to the restrictions imposed by our <hints> |
| 987 |
above, and returns a pointer to the start of the list in <hostinfo>. |
| 988 |
The items in the linked list are linked by the <ai_next> field. */ |
| 989 |
sdetails->valid = 1; |
| 990 |
sdetails->orig_hostinfo = sdetails->hostinfo; |
| 991 |
return NULL; |
| 992 |
} |
| 993 |
else |
| 994 |
{ |
| 995 |
/* Lookup failed, return human readable error string */ |
| 996 |
if (ecode == EAI_AGAIN) |
| 997 |
return _("Cannot resolve server name"); |
| 998 |
else |
| 999 |
return _((char*)gai_strerror(ecode)); |
| 1000 |
} |
| 1001 |
} |
| 1002 |
|
| 1003 |
sdetails->valid = 1; |
| 1004 |
return NULL; |
| 1005 |
} |
| 1006 |
|
| 1007 |
char *parse_server_addr(struct server_details *sdetails) |
| 1008 |
{ |
| 1009 |
if (sdetails->addr_type == AF_INET) |
| 1010 |
{ |
| 1011 |
sdetails->addr->in.sin_port = htons(sdetails->serv_port); |
| 1012 |
sdetails->addr->sa.sa_family = sdetails->source_addr->sa.sa_family = AF_INET; |
| 1013 |
#ifdef HAVE_SOCKADDR_SA_LEN |
| 1014 |
sdetails->source_addr->in.sin_len = sdetails->addr->in.sin_len = sizeof(struct sockaddr_in); |
| 1015 |
#endif |
| 1016 |
sdetails->source_addr->in.sin_addr.s_addr = INADDR_ANY; |
| 1017 |
sdetails->source_addr->in.sin_port = htons(daemon->query_port); |
| 1018 |
|
| 1019 |
if (sdetails->source) |
| 1020 |
{ |
| 1021 |
if (sdetails->flags) |
| 1022 |
*sdetails->flags |= SERV_HAS_SOURCE; |
| 1023 |
sdetails->source_addr->in.sin_port = htons(sdetails->source_port); |
| 1024 |
if (inet_pton(AF_INET, sdetails->source, &sdetails->source_addr->in.sin_addr) == 0) |
| 1025 |
{ |
| 1026 |
if (inet_pton(AF_INET6, sdetails->source, &sdetails->source_addr->in6.sin6_addr) == 1) |
| 1027 |
{ |
| 1028 |
sdetails->source_addr->sa.sa_family = AF_INET6; |
| 1029 |
/* When resolving a server IP by hostname, we can simply skip mismatching |
| 1030 |
server / source IP pairs. Otherwise, when an IP address is given directly, |
| 1031 |
this is a fatal error. */ |
| 1032 |
if (!sdetails->orig_hostinfo) |
| 1033 |
return _("cannot use IPv4 server address with IPv6 source address"); |
| 1034 |
} |
| 1035 |
else |
| 1036 |
{ |
| 1037 |
#if defined(SO_BINDTODEVICE) |
| 1038 |
if (sdetails->interface_opt) |
| 1039 |
return _("interface can only be specified once"); |
| 1040 |
|
| 1041 |
sdetails->source_addr->in.sin_addr.s_addr = INADDR_ANY; |
| 1042 |
safe_strncpy(sdetails->interface, sdetails->source, IF_NAMESIZE); |
| 1043 |
#else |
| 1044 |
return _("interface binding not supported"); |
| 1045 |
#endif |
| 1046 |
} |
| 1047 |
} |
| 1048 |
} |
| 1049 |
} |
| 1050 |
else if (sdetails->addr_type == AF_INET6) |
| 1051 |
{ |
| 1052 |
if (sdetails->scope_id && (sdetails->scope_index = if_nametoindex(sdetails->scope_id)) == 0) |
| 1053 |
return _("bad interface name"); |
| 1054 |
|
| 1055 |
sdetails->addr->in6.sin6_port = htons(sdetails->serv_port); |
| 1056 |
sdetails->addr->in6.sin6_scope_id = sdetails->scope_index; |
| 1057 |
sdetails->source_addr->in6.sin6_addr = in6addr_any; |
| 1058 |
sdetails->source_addr->in6.sin6_port = htons(daemon->query_port); |
| 1059 |
sdetails->source_addr->in6.sin6_scope_id = 0; |
| 1060 |
sdetails->addr->sa.sa_family = sdetails->source_addr->sa.sa_family = AF_INET6; |
| 1061 |
sdetails->addr->in6.sin6_flowinfo = sdetails->source_addr->in6.sin6_flowinfo = 0; |
| 1062 |
#ifdef HAVE_SOCKADDR_SA_LEN |
| 1063 |
sdetails->addr->in6.sin6_len = sdetails->source_addr->in6.sin6_len = sizeof(sdetails->addr->in6); |
| 1064 |
#endif |
| 1065 |
if (sdetails->source) |
| 1066 |
{ |
| 1067 |
if (sdetails->flags) |
| 1068 |
*sdetails->flags |= SERV_HAS_SOURCE; |
| 1069 |
sdetails->source_addr->in6.sin6_port = htons(sdetails->source_port); |
| 1070 |
if (inet_pton(AF_INET6, sdetails->source, &sdetails->source_addr->in6.sin6_addr) == 0) |
| 1071 |
{ |
| 1072 |
if (inet_pton(AF_INET, sdetails->source, &sdetails->source_addr->in.sin_addr) == 1) |
| 1073 |
{ |
| 1074 |
sdetails->source_addr->sa.sa_family = AF_INET; |
| 1075 |
/* When resolving a server IP by hostname, we can simply skip mismatching |
| 1076 |
server / source IP pairs. Otherwise, when an IP address is given directly, |
| 1077 |
this is a fatal error. */ |
| 1078 |
if(!sdetails->orig_hostinfo) |
| 1079 |
return _("cannot use IPv6 server address with IPv4 source address"); |
| 1080 |
} |
| 1081 |
else |
| 1082 |
{ |
| 1083 |
#if defined(SO_BINDTODEVICE) |
| 1084 |
if (sdetails->interface_opt) |
| 1085 |
return _("interface can only be specified once"); |
| 1086 |
|
| 1087 |
sdetails->source_addr->in6.sin6_addr = in6addr_any; |
| 1088 |
safe_strncpy(sdetails->interface, sdetails->source, IF_NAMESIZE); |
| 1089 |
#else |
| 1090 |
return _("interface binding not supported"); |
| 1091 |
#endif |
| 1092 |
} |
| 1093 |
} |
| 1094 |
} |
| 1095 |
} |
| 1096 |
else if (sdetails->addr_type != AF_LOCAL) |
| 1097 |
return _("bad address"); |
| 1098 |
|
| 1099 |
return NULL; |
| 1100 |
} |
| 1101 |
|
| 1102 |
int parse_server_next(struct server_details *sdetails) |
| 1103 |
{ |
| 1104 |
/* Looping over resolved addresses? */ |
| 1105 |
if (sdetails->hostinfo) |
| 1106 |
{ |
| 1107 |
/* Get address type */ |
| 1108 |
sdetails->addr_type = sdetails->hostinfo->ai_family; |
| 1109 |
|
| 1110 |
/* Get address */ |
| 1111 |
if (sdetails->addr_type == AF_INET) |
| 1112 |
memcpy(&sdetails->addr->in.sin_addr, |
| 1113 |
&((struct sockaddr_in *) sdetails->hostinfo->ai_addr)->sin_addr, |
| 1114 |
sizeof(sdetails->addr->in.sin_addr)); |
| 1115 |
else if (sdetails->addr_type == AF_INET6) |
| 1116 |
memcpy(&sdetails->addr->in6.sin6_addr, |
| 1117 |
&((struct sockaddr_in6 *) sdetails->hostinfo->ai_addr)->sin6_addr, |
| 1118 |
sizeof(sdetails->addr->in6.sin6_addr)); |
| 1119 |
|
| 1120 |
/* Iterate to the next available address */ |
| 1121 |
sdetails->valid = sdetails->hostinfo->ai_next != NULL; |
| 1122 |
sdetails->hostinfo = sdetails->hostinfo->ai_next; |
| 1123 |
return 1; |
| 1124 |
} |
| 1125 |
else if (sdetails->valid) |
| 1126 |
{ |
| 1127 |
/* When using an IP address, we return the address only once */ |
| 1128 |
sdetails->valid = 0; |
| 1129 |
return 1; |
| 1130 |
} |
| 1131 |
/* Stop iterating here, we used all available addresses */ |
| 1132 |
return 0; |
| 1133 |
} |
| 1134 |
|
| 1135 |
static char *domain_rev4(int from_file, char *server, struct in_addr *addr4, int size) |
| 1136 |
{ |
| 1137 |
int i, j; |
| 1138 |
char *string; |
| 1139 |
int msize; |
| 1140 |
u16 flags = 0; |
| 1141 |
char domain[29]; /* strlen("xxx.yyy.zzz.ttt.in-addr.arpa")+1 */ |
| 1142 |
union mysockaddr serv_addr, source_addr; |
| 1143 |
char interface[IF_NAMESIZE+1]; |
| 1144 |
int count = 1, rem, addrbytes, addrbits; |
| 1145 |
struct server_details sdetails; |
| 1146 |
|
| 1147 |
memset(&sdetails, 0, sizeof(struct server_details)); |
| 1148 |
sdetails.addr = &serv_addr; |
| 1149 |
sdetails.source_addr = &source_addr; |
| 1150 |
sdetails.interface = interface; |
| 1151 |
sdetails.flags = &flags; |
| 1152 |
|
| 1153 |
if (!server) |
| 1154 |
flags = SERV_LITERAL_ADDRESS; |
| 1155 |
else if ((string = parse_server(server, &sdetails))) |
| 1156 |
return string; |
| 1157 |
|
| 1158 |
if (from_file) |
| 1159 |
flags |= SERV_FROM_FILE; |
| 1160 |
|
| 1161 |
rem = size & 0x7; |
| 1162 |
addrbytes = (32 - size) >> 3; |
| 1163 |
addrbits = (32 - size) & 7; |
| 1164 |
|
| 1165 |
if (size > 32 || size < 1) |
| 1166 |
return _("bad IPv4 prefix length"); |
| 1167 |
|
| 1168 |
/* Zero out last address bits according to CIDR mask */ |
| 1169 |
((u8 *)addr4)[3-addrbytes] &= ~((1 << addrbits)-1); |
| 1170 |
|
| 1171 |
size = size & ~0x7; |
| 1172 |
|
| 1173 |
if (rem != 0) |
| 1174 |
count = 1 << (8 - rem); |
| 1175 |
|
| 1176 |
for (i = 0; i < count; i++) |
| 1177 |
{ |
| 1178 |
*domain = 0; |
| 1179 |
string = domain; |
| 1180 |
msize = size/8; |
| 1181 |
|
| 1182 |
for (j = (rem == 0) ? msize-1 : msize; j >= 0; j--) |
| 1183 |
{ |
| 1184 |
int dig = ((unsigned char *)addr4)[j]; |
| 1185 |
|
| 1186 |
if (j == msize) |
| 1187 |
dig += i; |
| 1188 |
|
| 1189 |
string += sprintf(string, "%d.", dig); |
| 1190 |
} |
| 1191 |
|
| 1192 |
sprintf(string, "in-addr.arpa"); |
| 1193 |
|
| 1194 |
if (flags & SERV_LITERAL_ADDRESS) |
| 1195 |
{ |
| 1196 |
if (!add_update_server(flags, &serv_addr, &source_addr, interface, domain, NULL)) |
| 1197 |
return _("error"); |
| 1198 |
} |
| 1199 |
else |
| 1200 |
{ |
| 1201 |
/* Always reset server as valid here, so we can add the same upstream |
| 1202 |
server address multiple times for each x.y.z.in-addr.arpa */ |
| 1203 |
sdetails.valid = 1; |
| 1204 |
while (parse_server_next(&sdetails)) |
| 1205 |
{ |
| 1206 |
if ((string = parse_server_addr(&sdetails))) |
| 1207 |
return string; |
| 1208 |
|
| 1209 |
if (!add_update_server(flags, &serv_addr, &source_addr, interface, domain, NULL)) |
| 1210 |
return _("error"); |
| 1211 |
} |
| 1212 |
|
| 1213 |
if (sdetails.orig_hostinfo) |
| 1214 |
freeaddrinfo(sdetails.orig_hostinfo); |
| 1215 |
} |
| 1216 |
} |
| 1217 |
|
| 1218 |
return NULL; |
| 1219 |
} |
| 1220 |
|
| 1221 |
static char *domain_rev6(int from_file, char *server, struct in6_addr *addr6, int size) |
| 1222 |
{ |
| 1223 |
int i, j; |
| 1224 |
char *string; |
| 1225 |
int msize; |
| 1226 |
u16 flags = 0; |
| 1227 |
char domain[73]; /* strlen("32*<n.>ip6.arpa")+1 */ |
| 1228 |
union mysockaddr serv_addr, source_addr; |
| 1229 |
char interface[IF_NAMESIZE+1]; |
| 1230 |
int count = 1, rem, addrbytes, addrbits; |
| 1231 |
struct server_details sdetails; |
| 1232 |
|
| 1233 |
memset(&sdetails, 0, sizeof(struct server_details)); |
| 1234 |
sdetails.addr = &serv_addr; |
| 1235 |
sdetails.source_addr = &source_addr; |
| 1236 |
sdetails.interface = interface; |
| 1237 |
sdetails.flags = &flags; |
| 1238 |
|
| 1239 |
if (!server) |
| 1240 |
flags = SERV_LITERAL_ADDRESS; |
| 1241 |
else if ((string = parse_server(server, &sdetails))) |
| 1242 |
return string; |
| 1243 |
|
| 1244 |
if (from_file) |
| 1245 |
flags |= SERV_FROM_FILE; |
| 1246 |
|
| 1247 |
rem = size & 0x3; |
| 1248 |
addrbytes = (128 - size) >> 3; |
| 1249 |
addrbits = (128 - size) & 7; |
| 1250 |
|
| 1251 |
if (size > 128 || size < 1) |
| 1252 |
return _("bad IPv6 prefix length"); |
| 1253 |
|
| 1254 |
/* Zero out last address bits according to CIDR mask */ |
| 1255 |
addr6->s6_addr[15-addrbytes] &= ~((1 << addrbits) - 1); |
| 1256 |
|
| 1257 |
size = size & ~0x3; |
| 1258 |
|
| 1259 |
if (rem != 0) |
| 1260 |
count = 1 << (4 - rem); |
| 1261 |
|
| 1262 |
for (i = 0; i < count; i++) |
| 1263 |
{ |
| 1264 |
*domain = 0; |
| 1265 |
string = domain; |
| 1266 |
msize = size/4; |
| 1267 |
|
| 1268 |
for (j = (rem == 0) ? msize-1 : msize; j >= 0; j--) |
| 1269 |
{ |
| 1270 |
int dig = ((unsigned char *)addr6)[j>>1]; |
| 1271 |
|
| 1272 |
dig = j & 1 ? dig & 15 : dig >> 4; |
| 1273 |
|
| 1274 |
if (j == msize) |
| 1275 |
dig += i; |
| 1276 |
|
| 1277 |
string += sprintf(string, "%.1x.", dig); |
| 1278 |
} |
| 1279 |
|
| 1280 |
sprintf(string, "ip6.arpa"); |
| 1281 |
|
| 1282 |
if (flags & SERV_LITERAL_ADDRESS) |
| 1283 |
{ |
| 1284 |
if (!add_update_server(flags, &serv_addr, &source_addr, interface, domain, NULL)) |
| 1285 |
return _("error"); |
| 1286 |
} |
| 1287 |
else |
| 1288 |
{ |
| 1289 |
/* Always reset server as valid here, so we can add the same upstream |
| 1290 |
server address multiple times for each x.y.z.ip6.arpa */ |
| 1291 |
sdetails.valid = 1; |
| 1292 |
while (parse_server_next(&sdetails)) |
| 1293 |
{ |
| 1294 |
if ((string = parse_server_addr(&sdetails))) |
| 1295 |
return string; |
| 1296 |
|
| 1297 |
if (!add_update_server(flags, &serv_addr, &source_addr, interface, domain, NULL)) |
| 1298 |
return _("error"); |
| 1299 |
} |
| 1300 |
|
| 1301 |
if (sdetails.orig_hostinfo) |
| 1302 |
freeaddrinfo(sdetails.orig_hostinfo); |
| 1303 |
} |
| 1304 |
} |
| 1305 |
|
| 1306 |
return NULL; |
| 1307 |
} |
| 1308 |
|
| 1309 |
static void if_names_add(const char *ifname) |
| 1310 |
{ |
| 1311 |
struct iname *new = opt_malloc(sizeof(struct iname)); |
| 1312 |
new->next = daemon->if_names; |
| 1313 |
daemon->if_names = new; |
| 1314 |
/* new->name may be NULL if someone does |
| 1315 |
"interface=" to disable all interfaces except loop. */ |
| 1316 |
new->name = opt_string_alloc(ifname); |
| 1317 |
new->flags = 0; |
| 1318 |
} |
| 1319 |
|
| 1320 |
#ifdef HAVE_DHCP |
| 1321 |
|
| 1322 |
static int is_tag_prefix(char *arg) |
| 1323 |
{ |
| 1324 |
if (arg && (strstr(arg, "net:") == arg || strstr(arg, "tag:") == arg)) |
| 1325 |
return 1; |
| 1326 |
|
| 1327 |
return 0; |
| 1328 |
} |
| 1329 |
|
| 1330 |
static char *set_prefix(char *arg) |
| 1331 |
{ |
| 1332 |
if (strstr(arg, "set:") == arg) |
| 1333 |
return arg+4; |
| 1334 |
|
| 1335 |
return arg; |
| 1336 |
} |
| 1337 |
|
| 1338 |
static struct dhcp_netid *dhcp_netid_create(const char *net, struct dhcp_netid *next) |
| 1339 |
{ |
| 1340 |
struct dhcp_netid *tt; |
| 1341 |
tt = opt_malloc(sizeof (struct dhcp_netid)); |
| 1342 |
tt->net = opt_string_alloc(net); |
| 1343 |
tt->next = next; |
| 1344 |
return tt; |
| 1345 |
} |
| 1346 |
|
| 1347 |
static void dhcp_netid_free(struct dhcp_netid *nid) |
| 1348 |
{ |
| 1349 |
while (nid) |
| 1350 |
{ |
| 1351 |
struct dhcp_netid *tmp = nid; |
| 1352 |
nid = nid->next; |
| 1353 |
free(tmp->net); |
| 1354 |
free(tmp); |
| 1355 |
} |
| 1356 |
} |
| 1357 |
|
| 1358 |
/* Parse one or more tag:s before parameters. |
| 1359 |
* Moves arg to the end of tags. */ |
| 1360 |
static struct dhcp_netid *dhcp_tags(char **arg) |
| 1361 |
{ |
| 1362 |
struct dhcp_netid *id = NULL; |
| 1363 |
|
| 1364 |
while (is_tag_prefix(*arg)) |
| 1365 |
{ |
| 1366 |
char *comma = split(*arg); |
| 1367 |
id = dhcp_netid_create((*arg)+4, id); |
| 1368 |
*arg = comma; |
| 1369 |
}; |
| 1370 |
if (!*arg) |
| 1371 |
{ |
| 1372 |
dhcp_netid_free(id); |
| 1373 |
id = NULL; |
| 1374 |
} |
| 1375 |
return id; |
| 1376 |
} |
| 1377 |
|
| 1378 |
static void dhcp_netid_list_free(struct dhcp_netid_list *netid) |
| 1379 |
{ |
| 1380 |
while (netid) |
| 1381 |
{ |
| 1382 |
struct dhcp_netid_list *tmplist = netid; |
| 1383 |
netid = netid->next; |
| 1384 |
/* Note: don't use dhcp_netid_free() here, since that |
| 1385 |
frees a list linked on netid->next. Where a netid_list |
| 1386 |
is used that's because the the ->next pointers in the |
| 1387 |
netids are being used to temporarily construct |
| 1388 |
a list of valid tags. */ |
| 1389 |
free(tmplist->list->net); |
| 1390 |
free(tmplist->list); |
| 1391 |
free(tmplist); |
| 1392 |
} |
| 1393 |
} |
| 1394 |
|
| 1395 |
static void dhcp_config_free(struct dhcp_config *config) |
| 1396 |
{ |
| 1397 |
if (config) |
| 1398 |
{ |
| 1399 |
struct hwaddr_config *hwaddr = config->hwaddr; |
| 1400 |
|
| 1401 |
while (hwaddr) |
| 1402 |
{ |
| 1403 |
struct hwaddr_config *tmp = hwaddr; |
| 1404 |
hwaddr = hwaddr->next; |
| 1405 |
free(tmp); |
| 1406 |
} |
| 1407 |
|
| 1408 |
dhcp_netid_list_free(config->netid); |
| 1409 |
dhcp_netid_free(config->filter); |
| 1410 |
|
| 1411 |
if (config->flags & CONFIG_CLID) |
| 1412 |
free(config->clid); |
| 1413 |
if (config->flags & CONFIG_NAME) |
| 1414 |
free(config->hostname); |
| 1415 |
|
| 1416 |
#ifdef HAVE_DHCP6 |
| 1417 |
if (config->flags & CONFIG_ADDR6) |
| 1418 |
{ |
| 1419 |
struct addrlist *addr, *tmp; |
| 1420 |
|
| 1421 |
for (addr = config->addr6; addr; addr = tmp) |
| 1422 |
{ |
| 1423 |
tmp = addr->next; |
| 1424 |
free(addr); |
| 1425 |
} |
| 1426 |
} |
| 1427 |
#endif |
| 1428 |
|
| 1429 |
free(config); |
| 1430 |
} |
| 1431 |
} |
| 1432 |
|
| 1433 |
static void dhcp_context_free(struct dhcp_context *ctx) |
| 1434 |
{ |
| 1435 |
if (ctx) |
| 1436 |
{ |
| 1437 |
dhcp_netid_free(ctx->filter); |
| 1438 |
free(ctx->netid.net); |
| 1439 |
#ifdef HAVE_DHCP6 |
| 1440 |
free(ctx->template_interface); |
| 1441 |
#endif |
| 1442 |
free(ctx); |
| 1443 |
} |
| 1444 |
} |
| 1445 |
|
| 1446 |
static void dhcp_opt_free(struct dhcp_opt *opt) |
| 1447 |
{ |
| 1448 |
if (opt->flags & DHOPT_VENDOR) |
| 1449 |
free(opt->u.vendor_class); |
| 1450 |
dhcp_netid_free(opt->netid); |
| 1451 |
free(opt->val); |
| 1452 |
free(opt); |
| 1453 |
} |
| 1454 |
|
| 1455 |
/* This is too insanely large to keep in-line in the switch */ |
| 1456 |
static int parse_dhcp_opt(char *errstr, char *arg, int flags) |
| 1457 |
{ |
| 1458 |
struct dhcp_opt *new = opt_malloc(sizeof(struct dhcp_opt)); |
| 1459 |
char lenchar = 0, *cp; |
| 1460 |
int addrs, digs, is_addr, is_addr6, is_hex, is_dec, is_string, dots; |
| 1461 |
char *comma = NULL; |
| 1462 |
u16 opt_len = 0; |
| 1463 |
int is6 = 0; |
| 1464 |
int option_ok = 0; |
| 1465 |
|
| 1466 |
new->len = 0; |
| 1467 |
new->flags = flags; |
| 1468 |
new->netid = NULL; |
| 1469 |
new->val = NULL; |
| 1470 |
new->opt = 0; |
| 1471 |
|
| 1472 |
while (arg) |
| 1473 |
{ |
| 1474 |
comma = split(arg); |
| 1475 |
|
| 1476 |
for (cp = arg; *cp; cp++) |
| 1477 |
if (*cp < '0' || *cp > '9') |
| 1478 |
break; |
| 1479 |
|
| 1480 |
if (!*cp) |
| 1481 |
{ |
| 1482 |
new->opt = atoi(arg); |
| 1483 |
opt_len = 0; |
| 1484 |
option_ok = 1; |
| 1485 |
break; |
| 1486 |
} |
| 1487 |
|
| 1488 |
if (strstr(arg, "option:") == arg) |
| 1489 |
{ |
| 1490 |
if ((new->opt = lookup_dhcp_opt(AF_INET, arg+7)) != -1) |
| 1491 |
{ |
| 1492 |
opt_len = lookup_dhcp_len(AF_INET, new->opt); |
| 1493 |
/* option:<optname> must follow tag and vendor string. */ |
| 1494 |
if (!(opt_len & OT_INTERNAL) || flags == DHOPT_MATCH) |
| 1495 |
option_ok = 1; |
| 1496 |
} |
| 1497 |
break; |
| 1498 |
} |
| 1499 |
#ifdef HAVE_DHCP6 |
| 1500 |
else if (strstr(arg, "option6:") == arg) |
| 1501 |
{ |
| 1502 |
for (cp = arg+8; *cp; cp++) |
| 1503 |
if (*cp < '0' || *cp > '9') |
| 1504 |
break; |
| 1505 |
|
| 1506 |
if (!*cp) |
| 1507 |
{ |
| 1508 |
new->opt = atoi(arg+8); |
| 1509 |
opt_len = 0; |
| 1510 |
option_ok = 1; |
| 1511 |
} |
| 1512 |
else |
| 1513 |
{ |
| 1514 |
if ((new->opt = lookup_dhcp_opt(AF_INET6, arg+8)) != -1) |
| 1515 |
{ |
| 1516 |
opt_len = lookup_dhcp_len(AF_INET6, new->opt); |
| 1517 |
if (!(opt_len & OT_INTERNAL) || flags == DHOPT_MATCH) |
| 1518 |
option_ok = 1; |
| 1519 |
} |
| 1520 |
} |
| 1521 |
/* option6:<opt>|<optname> must follow tag and vendor string. */ |
| 1522 |
is6 = 1; |
| 1523 |
break; |
| 1524 |
} |
| 1525 |
#endif |
| 1526 |
else if (strstr(arg, "vendor:") == arg) |
| 1527 |
{ |
| 1528 |
new->u.vendor_class = (unsigned char *)opt_string_alloc(arg+7); |
| 1529 |
new->flags |= DHOPT_VENDOR; |
| 1530 |
if ((new->flags & DHOPT_ENCAPSULATE) || flags == DHOPT_MATCH) |
| 1531 |
goto_err(_("inappropriate vendor:")); |
| 1532 |
} |
| 1533 |
else if (strstr(arg, "encap:") == arg) |
| 1534 |
{ |
| 1535 |
new->u.encap = atoi(arg+6); |
| 1536 |
new->flags |= DHOPT_ENCAPSULATE; |
| 1537 |
if ((new->flags & DHOPT_VENDOR) || flags == DHOPT_MATCH) |
| 1538 |
goto_err(_("inappropriate encap:")); |
| 1539 |
} |
| 1540 |
else if (strstr(arg, "vi-encap:") == arg) |
| 1541 |
{ |
| 1542 |
new->u.encap = atoi(arg+9); |
| 1543 |
new->flags |= DHOPT_RFC3925; |
| 1544 |
if (flags == DHOPT_MATCH) |
| 1545 |
{ |
| 1546 |
option_ok = 1; |
| 1547 |
break; |
| 1548 |
} |
| 1549 |
} |
| 1550 |
else |
| 1551 |
{ |
| 1552 |
/* allow optional "net:" or "tag:" for consistency */ |
| 1553 |
const char *name = (is_tag_prefix(arg)) ? arg+4 : set_prefix(arg); |
| 1554 |
new->netid = dhcp_netid_create(name, new->netid); |
| 1555 |
} |
| 1556 |
|
| 1557 |
arg = comma; |
| 1558 |
} |
| 1559 |
|
| 1560 |
#ifdef HAVE_DHCP6 |
| 1561 |
if (is6) |
| 1562 |
{ |
| 1563 |
if (new->flags & (DHOPT_VENDOR | DHOPT_ENCAPSULATE)) |
| 1564 |
goto_err(_("unsupported encapsulation for IPv6 option")); |
| 1565 |
|
| 1566 |
if (opt_len == 0 && |
| 1567 |
!(new->flags & DHOPT_RFC3925)) |
| 1568 |
opt_len = lookup_dhcp_len(AF_INET6, new->opt); |
| 1569 |
} |
| 1570 |
else |
| 1571 |
#endif |
| 1572 |
if (opt_len == 0 && |
| 1573 |
!(new->flags & (DHOPT_VENDOR | DHOPT_ENCAPSULATE | DHOPT_RFC3925))) |
| 1574 |
opt_len = lookup_dhcp_len(AF_INET, new->opt); |
| 1575 |
|
| 1576 |
/* option may be missing with rfc3925 match */ |
| 1577 |
if (!option_ok) |
| 1578 |
goto_err(_("bad dhcp-option")); |
| 1579 |
|
| 1580 |
if (comma) |
| 1581 |
{ |
| 1582 |
/* characterise the value */ |
| 1583 |
char c; |
| 1584 |
int found_dig = 0, found_colon = 0; |
| 1585 |
is_addr = is_addr6 = is_hex = is_dec = is_string = 1; |
| 1586 |
addrs = digs = 1; |
| 1587 |
dots = 0; |
| 1588 |
for (cp = comma; (c = *cp); cp++) |
| 1589 |
if (c == ',') |
| 1590 |
{ |
| 1591 |
addrs++; |
| 1592 |
is_dec = is_hex = 0; |
| 1593 |
} |
| 1594 |
else if (c == ':') |
| 1595 |
{ |
| 1596 |
digs++; |
| 1597 |
is_dec = is_addr = 0; |
| 1598 |
found_colon = 1; |
| 1599 |
} |
| 1600 |
else if (c == '/') |
| 1601 |
{ |
| 1602 |
is_addr6 = is_dec = is_hex = 0; |
| 1603 |
if (cp == comma) /* leading / means a pathname */ |
| 1604 |
is_addr = 0; |
| 1605 |
} |
| 1606 |
else if (c == '.') |
| 1607 |
{ |
| 1608 |
is_dec = is_hex = 0; |
| 1609 |
dots++; |
| 1610 |
} |
| 1611 |
else if (c == '-') |
| 1612 |
is_hex = is_addr = is_addr6 = 0; |
| 1613 |
else if (c == ' ') |
| 1614 |
is_dec = is_hex = 0; |
| 1615 |
else if (!(c >='0' && c <= '9')) |
| 1616 |
{ |
| 1617 |
is_addr = 0; |
| 1618 |
if (cp[1] == 0 && is_dec && |
| 1619 |
(c == 'b' || c == 's' || c == 'i')) |
| 1620 |
{ |
| 1621 |
lenchar = c; |
| 1622 |
*cp = 0; |
| 1623 |
} |
| 1624 |
else |
| 1625 |
is_dec = 0; |
| 1626 |
if (!((c >='A' && c <= 'F') || |
| 1627 |
(c >='a' && c <= 'f') || |
| 1628 |
(c == '*' && (flags & DHOPT_MATCH)))) |
| 1629 |
{ |
| 1630 |
is_hex = 0; |
| 1631 |
if (c != '[' && c != ']') |
| 1632 |
is_addr6 = 0; |
| 1633 |
} |
| 1634 |
} |
| 1635 |
else |
| 1636 |
found_dig = 1; |
| 1637 |
|
| 1638 |
if (!found_dig) |
| 1639 |
is_dec = is_addr = 0; |
| 1640 |
|
| 1641 |
if (!found_colon) |
| 1642 |
is_addr6 = 0; |
| 1643 |
|
| 1644 |
#ifdef HAVE_DHCP6 |
| 1645 |
/* NTP server option takes hex, addresses or FQDN */ |
| 1646 |
if (is6 && new->opt == OPTION6_NTP_SERVER && !is_hex) |
| 1647 |
opt_len |= is_addr6 ? OT_ADDR_LIST : OT_RFC1035_NAME; |
| 1648 |
#endif |
| 1649 |
|
| 1650 |
/* We know that some options take addresses */ |
| 1651 |
if (opt_len & OT_ADDR_LIST) |
| 1652 |
{ |
| 1653 |
is_string = is_dec = is_hex = 0; |
| 1654 |
|
| 1655 |
if (!is6 && (!is_addr || dots == 0)) |
| 1656 |
goto_err(_("bad IP address")); |
| 1657 |
|
| 1658 |
if (is6 && !is_addr6) |
| 1659 |
goto_err(_("bad IPv6 address")); |
| 1660 |
} |
| 1661 |
/* or names */ |
| 1662 |
else if (opt_len & (OT_NAME | OT_RFC1035_NAME | OT_CSTRING)) |
| 1663 |
is_addr6 = is_addr = is_dec = is_hex = 0; |
| 1664 |
|
| 1665 |
if (found_dig && (opt_len & OT_TIME) && strlen(comma) > 0) |
| 1666 |
{ |
| 1667 |
int val, fac = 1; |
| 1668 |
|
| 1669 |
switch (comma[strlen(comma) - 1]) |
| 1670 |
{ |
| 1671 |
case 'w': |
| 1672 |
case 'W': |
| 1673 |
fac *= 7; |
| 1674 |
/* fall through */ |
| 1675 |
case 'd': |
| 1676 |
case 'D': |
| 1677 |
fac *= 24; |
| 1678 |
/* fall through */ |
| 1679 |
case 'h': |
| 1680 |
case 'H': |
| 1681 |
fac *= 60; |
| 1682 |
/* fall through */ |
| 1683 |
case 'm': |
| 1684 |
case 'M': |
| 1685 |
fac *= 60; |
| 1686 |
/* fall through */ |
| 1687 |
case 's': |
| 1688 |
case 'S': |
| 1689 |
comma[strlen(comma) - 1] = 0; |
| 1690 |
} |
| 1691 |
|
| 1692 |
new->len = 4; |
| 1693 |
new->val = opt_malloc(4); |
| 1694 |
val = atoi(comma); |
| 1695 |
*((int *)new->val) = htonl(val * fac); |
| 1696 |
} |
| 1697 |
else if (is_hex && digs > 1) |
| 1698 |
{ |
| 1699 |
new->len = digs; |
| 1700 |
new->val = opt_malloc(new->len); |
| 1701 |
parse_hex(comma, new->val, digs, (flags & DHOPT_MATCH) ? &new->u.wildcard_mask : NULL, NULL); |
| 1702 |
new->flags |= DHOPT_HEX; |
| 1703 |
} |
| 1704 |
else if (is_dec) |
| 1705 |
{ |
| 1706 |
int i, val = atoi(comma); |
| 1707 |
/* assume numeric arg is 1 byte except for |
| 1708 |
options where it is known otherwise. |
| 1709 |
For vendor class option, we have to hack. */ |
| 1710 |
if (opt_len != 0) |
| 1711 |
new->len = opt_len; |
| 1712 |
else if (val & 0xffff0000) |
| 1713 |
new->len = 4; |
| 1714 |
else if (val & 0xff00) |
| 1715 |
new->len = 2; |
| 1716 |
else |
| 1717 |
new->len = 1; |
| 1718 |
|
| 1719 |
if (lenchar == 'b') |
| 1720 |
new->len = 1; |
| 1721 |
else if (lenchar == 's') |
| 1722 |
new->len = 2; |
| 1723 |
else if (lenchar == 'i') |
| 1724 |
new->len = 4; |
| 1725 |
|
| 1726 |
new->val = opt_malloc(new->len); |
| 1727 |
for (i=0; i<new->len; i++) |
| 1728 |
new->val[i] = val>>((new->len - i - 1)*8); |
| 1729 |
} |
| 1730 |
else if (is_addr && !is6) |
| 1731 |
{ |
| 1732 |
struct in_addr in; |
| 1733 |
unsigned char *op; |
| 1734 |
char *slash; |
| 1735 |
/* max length of address/subnet descriptor is five bytes, |
| 1736 |
add one for the option 120 enc byte too */ |
| 1737 |
new->val = op = opt_malloc((5 * addrs) + 1); |
| 1738 |
new->flags |= DHOPT_ADDR; |
| 1739 |
|
| 1740 |
if (!(new->flags & (DHOPT_ENCAPSULATE | DHOPT_VENDOR | DHOPT_RFC3925)) && |
| 1741 |
new->opt == OPTION_SIP_SERVER) |
| 1742 |
{ |
| 1743 |
*(op++) = 1; /* RFC 3361 "enc byte" */ |
| 1744 |
new->flags &= ~DHOPT_ADDR; |
| 1745 |
} |
| 1746 |
while (addrs--) |
| 1747 |
{ |
| 1748 |
cp = comma; |
| 1749 |
comma = split(cp); |
| 1750 |
slash = split_chr(cp, '/'); |
| 1751 |
if (!inet_pton(AF_INET, cp, &in)) |
| 1752 |
goto_err(_("bad IPv4 address")); |
| 1753 |
if (!slash) |
| 1754 |
{ |
| 1755 |
memcpy(op, &in, INADDRSZ); |
| 1756 |
op += INADDRSZ; |
| 1757 |
} |
| 1758 |
else |
| 1759 |
{ |
| 1760 |
unsigned char *p = (unsigned char *)∈ |
| 1761 |
int netsize = atoi(slash); |
| 1762 |
*op++ = netsize; |
| 1763 |
if (netsize > 0) |
| 1764 |
*op++ = *p++; |
| 1765 |
if (netsize > 8) |
| 1766 |
*op++ = *p++; |
| 1767 |
if (netsize > 16) |
| 1768 |
*op++ = *p++; |
| 1769 |
if (netsize > 24) |
| 1770 |
*op++ = *p++; |
| 1771 |
new->flags &= ~DHOPT_ADDR; /* cannot re-write descriptor format */ |
| 1772 |
} |
| 1773 |
} |
| 1774 |
new->len = op - new->val; |
| 1775 |
} |
| 1776 |
else if (is_addr6 && is6) |
| 1777 |
{ |
| 1778 |
unsigned char *op; |
| 1779 |
new->val = op = opt_malloc(16 * addrs); |
| 1780 |
new->flags |= DHOPT_ADDR6; |
| 1781 |
while (addrs--) |
| 1782 |
{ |
| 1783 |
cp = comma; |
| 1784 |
comma = split(cp); |
| 1785 |
|
| 1786 |
/* check for [1234::7] */ |
| 1787 |
if (*cp == '[') |
| 1788 |
cp++; |
| 1789 |
if (strlen(cp) > 1 && cp[strlen(cp)-1] == ']') |
| 1790 |
cp[strlen(cp)-1] = 0; |
| 1791 |
|
| 1792 |
if (inet_pton(AF_INET6, cp, op)) |
| 1793 |
{ |
| 1794 |
op += IN6ADDRSZ; |
| 1795 |
continue; |
| 1796 |
} |
| 1797 |
|
| 1798 |
goto_err(_("bad IPv6 address")); |
| 1799 |
} |
| 1800 |
new->len = op - new->val; |
| 1801 |
} |
| 1802 |
else if (is_string) |
| 1803 |
{ |
| 1804 |
/* text arg */ |
| 1805 |
if ((new->opt == OPTION_DOMAIN_SEARCH || new->opt == OPTION_SIP_SERVER) && |
| 1806 |
!is6 && !(new->flags & (DHOPT_ENCAPSULATE | DHOPT_VENDOR | DHOPT_RFC3925))) |
| 1807 |
{ |
| 1808 |
/* dns search, RFC 3397, or SIP, RFC 3361 */ |
| 1809 |
unsigned char *q, *r, *tail; |
| 1810 |
unsigned char *p, *m = NULL, *newp; |
| 1811 |
size_t newlen, len = 0; |
| 1812 |
int header_size = (new->opt == OPTION_DOMAIN_SEARCH) ? 0 : 1; |
| 1813 |
|
| 1814 |
arg = comma; |
| 1815 |
comma = split(arg); |
| 1816 |
|
| 1817 |
while (arg && *arg) |
| 1818 |
{ |
| 1819 |
char *in, *dom = NULL; |
| 1820 |
size_t domlen = 1; |
| 1821 |
/* Allow "." as an empty domain */ |
| 1822 |
if (strcmp (arg, ".") != 0) |
| 1823 |
{ |
| 1824 |
if (!(dom = canonicalise_opt(arg))) |
| 1825 |
goto_err(_("bad domain in dhcp-option")); |
| 1826 |
|
| 1827 |
domlen = strlen(dom) + 2; |
| 1828 |
} |
| 1829 |
|
| 1830 |
newp = opt_malloc(len + domlen + header_size); |
| 1831 |
if (m) |
| 1832 |
{ |
| 1833 |
memcpy(newp, m, header_size + len); |
| 1834 |
free(m); |
| 1835 |
} |
| 1836 |
m = newp; |
| 1837 |
p = m + header_size; |
| 1838 |
q = p + len; |
| 1839 |
|
| 1840 |
/* add string on the end in RFC1035 format */ |
| 1841 |
for (in = dom; in && *in;) |
| 1842 |
{ |
| 1843 |
unsigned char *cp = q++; |
| 1844 |
int j; |
| 1845 |
for (j = 0; *in && (*in != '.'); in++, j++) |
| 1846 |
*q++ = *in; |
| 1847 |
*cp = j; |
| 1848 |
if (*in) |
| 1849 |
in++; |
| 1850 |
} |
| 1851 |
*q++ = 0; |
| 1852 |
free(dom); |
| 1853 |
|
| 1854 |
/* Now tail-compress using earlier names. */ |
| 1855 |
newlen = q - p; |
| 1856 |
for (tail = p + len; *tail; tail += (*tail) + 1) |
| 1857 |
for (r = p; r - p < (int)len; r += (*r) + 1) |
| 1858 |
if (strcmp((char *)r, (char *)tail) == 0) |
| 1859 |
{ |
| 1860 |
PUTSHORT((r - p) | 0xc000, tail); |
| 1861 |
newlen = tail - p; |
| 1862 |
goto end; |
| 1863 |
} |
| 1864 |
end: |
| 1865 |
len = newlen; |
| 1866 |
|
| 1867 |
arg = comma; |
| 1868 |
comma = split(arg); |
| 1869 |
} |
| 1870 |
|
| 1871 |
/* RFC 3361, enc byte is zero for names */ |
| 1872 |
if (new->opt == OPTION_SIP_SERVER && m) |
| 1873 |
m[0] = 0; |
| 1874 |
new->len = (int) len + header_size; |
| 1875 |
new->val = m; |
| 1876 |
} |
| 1877 |
#ifdef HAVE_DHCP6 |
| 1878 |
else if (comma && (opt_len & OT_CSTRING)) |
| 1879 |
{ |
| 1880 |
/* length fields are two bytes so need 16 bits for each string */ |
| 1881 |
int i, commas = 1; |
| 1882 |
unsigned char *p, *newp; |
| 1883 |
|
| 1884 |
for (i = 0; comma[i]; i++) |
| 1885 |
if (comma[i] == ',') |
| 1886 |
commas++; |
| 1887 |
|
| 1888 |
newp = opt_malloc(strlen(comma)+(2*commas)); |
| 1889 |
p = newp; |
| 1890 |
arg = comma; |
| 1891 |
comma = split(arg); |
| 1892 |
|
| 1893 |
while (arg && *arg) |
| 1894 |
{ |
| 1895 |
u16 len = strlen(arg); |
| 1896 |
unhide_metas(arg); |
| 1897 |
PUTSHORT(len, p); |
| 1898 |
memcpy(p, arg, len); |
| 1899 |
p += len; |
| 1900 |
|
| 1901 |
arg = comma; |
| 1902 |
comma = split(arg); |
| 1903 |
} |
| 1904 |
|
| 1905 |
new->val = newp; |
| 1906 |
new->len = p - newp; |
| 1907 |
} |
| 1908 |
else if (comma && (opt_len & OT_RFC1035_NAME)) |
| 1909 |
{ |
| 1910 |
unsigned char *p = NULL, *q, *newp, *end; |
| 1911 |
int len = 0; |
| 1912 |
int header_size = (is6 && new->opt == OPTION6_NTP_SERVER) ? 4 : 0; |
| 1913 |
arg = comma; |
| 1914 |
comma = split(arg); |
| 1915 |
|
| 1916 |
while (arg && *arg) |
| 1917 |
{ |
| 1918 |
char *dom = canonicalise_opt(arg); |
| 1919 |
if (!dom) |
| 1920 |
goto_err(_("bad domain in dhcp-option")); |
| 1921 |
|
| 1922 |
newp = opt_malloc(len + header_size + strlen(dom) + 2); |
| 1923 |
|
| 1924 |
if (p) |
| 1925 |
{ |
| 1926 |
memcpy(newp, p, len); |
| 1927 |
free(p); |
| 1928 |
} |
| 1929 |
|
| 1930 |
p = newp; |
| 1931 |
q = p + len; |
| 1932 |
end = do_rfc1035_name(q + header_size, dom, NULL); |
| 1933 |
*end++ = 0; |
| 1934 |
if (is6 && new->opt == OPTION6_NTP_SERVER) |
| 1935 |
{ |
| 1936 |
PUTSHORT(NTP_SUBOPTION_SRV_FQDN, q); |
| 1937 |
PUTSHORT(end - q - 2, q); |
| 1938 |
} |
| 1939 |
len = end - p; |
| 1940 |
free(dom); |
| 1941 |
|
| 1942 |
arg = comma; |
| 1943 |
comma = split(arg); |
| 1944 |
} |
| 1945 |
|
| 1946 |
new->val = p; |
| 1947 |
new->len = len; |
| 1948 |
} |
| 1949 |
#endif |
| 1950 |
else |
| 1951 |
{ |
| 1952 |
new->len = strlen(comma); |
| 1953 |
/* keep terminating zero on string */ |
| 1954 |
new->val = (unsigned char *)opt_string_alloc(comma); |
| 1955 |
new->flags |= DHOPT_STRING; |
| 1956 |
} |
| 1957 |
} |
| 1958 |
} |
| 1959 |
|
| 1960 |
if (!is6 && |
| 1961 |
((new->len > 255) || |
| 1962 |
(new->len > 253 && (new->flags & (DHOPT_VENDOR | DHOPT_ENCAPSULATE))) || |
| 1963 |
(new->len > 250 && (new->flags & DHOPT_RFC3925)))) |
| 1964 |
goto_err(_("dhcp-option too long")); |
| 1965 |
|
| 1966 |
if (flags == DHOPT_PXE_OPT && (new->flags & DHOPT_VENDOR)) |
| 1967 |
goto_err(_("No vendor-encap options allowed in dhcp-option-pxe")); |
| 1968 |
|
| 1969 |
if (flags == DHOPT_MATCH) |
| 1970 |
{ |
| 1971 |
if ((new->flags & (DHOPT_ENCAPSULATE | DHOPT_VENDOR)) || |
| 1972 |
!new->netid || |
| 1973 |
new->netid->next) |
| 1974 |
goto_err(_("illegal dhcp-match")); |
| 1975 |
|
| 1976 |
if (is6) |
| 1977 |
{ |
| 1978 |
new->next = daemon->dhcp_match6; |
| 1979 |
daemon->dhcp_match6 = new; |
| 1980 |
} |
| 1981 |
else |
| 1982 |
{ |
| 1983 |
new->next = daemon->dhcp_match; |
| 1984 |
daemon->dhcp_match = new; |
| 1985 |
} |
| 1986 |
} |
| 1987 |
else if (is6) |
| 1988 |
{ |
| 1989 |
new->next = daemon->dhcp_opts6; |
| 1990 |
daemon->dhcp_opts6 = new; |
| 1991 |
} |
| 1992 |
else |
| 1993 |
{ |
| 1994 |
new->next = daemon->dhcp_opts; |
| 1995 |
daemon->dhcp_opts = new; |
| 1996 |
} |
| 1997 |
|
| 1998 |
return 1; |
| 1999 |
on_error: |
| 2000 |
dhcp_opt_free(new); |
| 2001 |
return 0; |
| 2002 |
} |
| 2003 |
|
| 2004 |
#endif |
| 2005 |
|
| 2006 |
void set_option_bool(unsigned int opt) |
| 2007 |
{ |
| 2008 |
option_var(opt) |= option_val(opt); |
| 2009 |
} |
| 2010 |
|
| 2011 |
void reset_option_bool(unsigned int opt) |
| 2012 |
{ |
| 2013 |
option_var(opt) &= ~(option_val(opt)); |
| 2014 |
} |
| 2015 |
|
| 2016 |
static int one_opt(int option, char *arg, char *errstr, char *gen_err, int command_line, int servers_only) |
| 2017 |
{ |
| 2018 |
int i; |
| 2019 |
char *comma; |
| 2020 |
|
| 2021 |
if (option == '?') |
| 2022 |
ret_err(gen_err); |
| 2023 |
|
| 2024 |
for (i=0; usage[i].opt != 0; i++) |
| 2025 |
if (usage[i].opt == option) |
| 2026 |
{ |
| 2027 |
int rept = usage[i].rept; |
| 2028 |
|
| 2029 |
if (command_line) |
| 2030 |
{ |
| 2031 |
/* command line */ |
| 2032 |
if (rept == ARG_USED_CL) |
| 2033 |
ret_err(_("illegal repeated flag")); |
| 2034 |
if (rept == ARG_ONE) |
| 2035 |
usage[i].rept = ARG_USED_CL; |
| 2036 |
} |
| 2037 |
else |
| 2038 |
{ |
| 2039 |
/* allow file to override command line */ |
| 2040 |
if (rept == ARG_USED_FILE) |
| 2041 |
ret_err(_("illegal repeated keyword")); |
| 2042 |
if (rept == ARG_USED_CL || rept == ARG_ONE) |
| 2043 |
usage[i].rept = ARG_USED_FILE; |
| 2044 |
} |
| 2045 |
|
| 2046 |
if (rept != ARG_DUP && rept != ARG_ONE && rept != ARG_USED_CL) |
| 2047 |
{ |
| 2048 |
set_option_bool(rept); |
| 2049 |
return 1; |
| 2050 |
} |
| 2051 |
|
| 2052 |
break; |
| 2053 |
} |
| 2054 |
|
| 2055 |
switch (option) |
| 2056 |
{ |
| 2057 |
case 'C': /* --conf-file */ |
| 2058 |
{ |
| 2059 |
char *file = opt_string_alloc(arg); |
| 2060 |
if (file) |
| 2061 |
{ |
| 2062 |
one_file(file, 0); |
| 2063 |
free(file); |
| 2064 |
} |
| 2065 |
break; |
| 2066 |
} |
| 2067 |
|
| 2068 |
case LOPT_CONF_SCRIPT: /* --conf-script */ |
| 2069 |
{ |
| 2070 |
char *file = opt_string_alloc(arg); |
| 2071 |
if (file) |
| 2072 |
{ |
| 2073 |
one_file(file, LOPT_CONF_SCRIPT); |
| 2074 |
free(file); |
| 2075 |
} |
| 2076 |
break; |
| 2077 |
} |
| 2078 |
|
| 2079 |
case '7': /* --conf-dir */ |
| 2080 |
{ |
| 2081 |
DIR *dir_stream; |
| 2082 |
struct dirent *ent; |
| 2083 |
char *directory, *path; |
| 2084 |
struct list { |
| 2085 |
char *name; |
| 2086 |
struct list *next; |
| 2087 |
} *ignore_suffix = NULL, *match_suffix = NULL, *files = NULL, *li; |
| 2088 |
|
| 2089 |
comma = split(arg); |
| 2090 |
if (!(directory = opt_string_alloc(arg))) |
| 2091 |
break; |
| 2092 |
|
| 2093 |
for (arg = comma; arg; arg = comma) |
| 2094 |
{ |
| 2095 |
comma = split(arg); |
| 2096 |
if (strlen(arg) != 0) |
| 2097 |
{ |
| 2098 |
li = opt_malloc(sizeof(struct list)); |
| 2099 |
if (*arg == '*') |
| 2100 |
{ |
| 2101 |
/* "*" with no suffix is a no-op */ |
| 2102 |
if (arg[1] == 0) |
| 2103 |
free(li); |
| 2104 |
else |
| 2105 |
{ |
| 2106 |
li->next = match_suffix; |
| 2107 |
match_suffix = li; |
| 2108 |
/* Have to copy: buffer is overwritten */ |
| 2109 |
li->name = opt_string_alloc(arg+1); |
| 2110 |
} |
| 2111 |
} |
| 2112 |
else |
| 2113 |
{ |
| 2114 |
li->next = ignore_suffix; |
| 2115 |
ignore_suffix = li; |
| 2116 |
/* Have to copy: buffer is overwritten */ |
| 2117 |
li->name = opt_string_alloc(arg); |
| 2118 |
} |
| 2119 |
} |
| 2120 |
} |
| 2121 |
|
| 2122 |
if (!(dir_stream = opendir(directory))) |
| 2123 |
die(_("cannot access directory %s: %s"), directory, EC_FILE); |
| 2124 |
|
| 2125 |
while ((ent = readdir(dir_stream))) |
| 2126 |
{ |
| 2127 |
size_t len = strlen(ent->d_name); |
| 2128 |
struct stat buf; |
| 2129 |
|
| 2130 |
/* ignore emacs backups and dotfiles */ |
| 2131 |
if (len == 0 || |
| 2132 |
ent->d_name[len - 1] == '~' || |
| 2133 |
(ent->d_name[0] == '#' && ent->d_name[len - 1] == '#') || |
| 2134 |
ent->d_name[0] == '.') |
| 2135 |
continue; |
| 2136 |
|
| 2137 |
if (match_suffix) |
| 2138 |
{ |
| 2139 |
for (li = match_suffix; li; li = li->next) |
| 2140 |
{ |
| 2141 |
/* check for required suffices */ |
| 2142 |
size_t ls = strlen(li->name); |
| 2143 |
if (len > ls && |
| 2144 |
strcmp(li->name, &ent->d_name[len - ls]) == 0) |
| 2145 |
break; |
| 2146 |
} |
| 2147 |
if (!li) |
| 2148 |
continue; |
| 2149 |
} |
| 2150 |
|
| 2151 |
for (li = ignore_suffix; li; li = li->next) |
| 2152 |
{ |
| 2153 |
/* check for proscribed suffices */ |
| 2154 |
size_t ls = strlen(li->name); |
| 2155 |
if (len > ls && |
| 2156 |
strcmp(li->name, &ent->d_name[len - ls]) == 0) |
| 2157 |
break; |
| 2158 |
} |
| 2159 |
if (li) |
| 2160 |
continue; |
| 2161 |
|
| 2162 |
path = opt_malloc(strlen(directory) + len + 2); |
| 2163 |
strcpy(path, directory); |
| 2164 |
strcat(path, "/"); |
| 2165 |
strcat(path, ent->d_name); |
| 2166 |
|
| 2167 |
/* files must be readable */ |
| 2168 |
if (stat(path, &buf) == -1) |
| 2169 |
die(_("cannot access %s: %s"), path, EC_FILE); |
| 2170 |
|
| 2171 |
/* only reg files allowed. */ |
| 2172 |
if (S_ISREG(buf.st_mode)) |
| 2173 |
{ |
| 2174 |
/* sort files into order. */ |
| 2175 |
struct list **up, *new = opt_malloc(sizeof(struct list)); |
| 2176 |
new->name = path; |
| 2177 |
|
| 2178 |
for (up = &files, li = files; li; up = &li->next, li = li->next) |
| 2179 |
if (strcmp(li->name, path) >=0) |
| 2180 |
break; |
| 2181 |
|
| 2182 |
new->next = li; |
| 2183 |
*up = new; |
| 2184 |
} |
| 2185 |
else |
| 2186 |
free(path); |
| 2187 |
|
| 2188 |
} |
| 2189 |
|
| 2190 |
for (li = files; li; li = li->next) |
| 2191 |
one_file(li->name, 0); |
| 2192 |
|
| 2193 |
closedir(dir_stream); |
| 2194 |
free(directory); |
| 2195 |
for(; ignore_suffix; ignore_suffix = li) |
| 2196 |
{ |
| 2197 |
li = ignore_suffix->next; |
| 2198 |
free(ignore_suffix->name); |
| 2199 |
free(ignore_suffix); |
| 2200 |
} |
| 2201 |
for(; match_suffix; match_suffix = li) |
| 2202 |
{ |
| 2203 |
li = match_suffix->next; |
| 2204 |
free(match_suffix->name); |
| 2205 |
free(match_suffix); |
| 2206 |
} |
| 2207 |
for(; files; files = li) |
| 2208 |
{ |
| 2209 |
li = files->next; |
| 2210 |
free(files->name); |
| 2211 |
free(files); |
| 2212 |
} |
| 2213 |
break; |
| 2214 |
} |
| 2215 |
|
| 2216 |
case LOPT_ADD_SBNET: /* --add-subnet */ |
| 2217 |
set_option_bool(OPT_CLIENT_SUBNET); |
| 2218 |
if (arg) |
| 2219 |
{ |
| 2220 |
char *err, *end; |
| 2221 |
comma = split(arg); |
| 2222 |
|
| 2223 |
struct mysubnet* new = opt_malloc(sizeof(struct mysubnet)); |
| 2224 |
if ((end = split_chr(arg, '/'))) |
| 2225 |
{ |
| 2226 |
/* has subnet+len */ |
| 2227 |
err = parse_mysockaddr(arg, &new->addr); |
| 2228 |
if (err) |
| 2229 |
ret_err_free(err, new); |
| 2230 |
if (!atoi_check(end, &new->mask)) |
| 2231 |
ret_err_free(gen_err, new); |
| 2232 |
new->addr_used = 1; |
| 2233 |
} |
| 2234 |
else if (!atoi_check(arg, &new->mask)) |
| 2235 |
ret_err_free(gen_err, new); |
| 2236 |
|
| 2237 |
daemon->add_subnet4 = new; |
| 2238 |
|
| 2239 |
if (comma) |
| 2240 |
{ |
| 2241 |
new = opt_malloc(sizeof(struct mysubnet)); |
| 2242 |
if ((end = split_chr(comma, '/'))) |
| 2243 |
{ |
| 2244 |
/* has subnet+len */ |
| 2245 |
err = parse_mysockaddr(comma, &new->addr); |
| 2246 |
if (err) |
| 2247 |
ret_err_free(err, new); |
| 2248 |
if (!atoi_check(end, &new->mask)) |
| 2249 |
ret_err_free(gen_err, new); |
| 2250 |
new->addr_used = 1; |
| 2251 |
} |
| 2252 |
else |
| 2253 |
{ |
| 2254 |
if (!atoi_check(comma, &new->mask)) |
| 2255 |
ret_err_free(gen_err, new); |
| 2256 |
} |
| 2257 |
|
| 2258 |
daemon->add_subnet6 = new; |
| 2259 |
} |
| 2260 |
} |
| 2261 |
break; |
| 2262 |
|
| 2263 |
case '1': /* --enable-dbus */ |
| 2264 |
set_option_bool(OPT_DBUS); |
| 2265 |
if (arg) |
| 2266 |
daemon->dbus_name = opt_string_alloc(arg); |
| 2267 |
else |
| 2268 |
daemon->dbus_name = DNSMASQ_SERVICE; |
| 2269 |
break; |
| 2270 |
|
| 2271 |
case LOPT_UBUS: /* --enable-ubus */ |
| 2272 |
set_option_bool(OPT_UBUS); |
| 2273 |
if (arg) |
| 2274 |
daemon->ubus_name = opt_string_alloc(arg); |
| 2275 |
else |
| 2276 |
daemon->ubus_name = DNSMASQ_UBUS_NAME; |
| 2277 |
break; |
| 2278 |
|
| 2279 |
case '8': /* --log-facility */ |
| 2280 |
/* may be a filename */ |
| 2281 |
if (strchr(arg, '/') || strcmp (arg, "-") == 0) |
| 2282 |
daemon->log_file = opt_string_alloc(arg); |
| 2283 |
else |
| 2284 |
{ |
| 2285 |
#ifdef __ANDROID__ |
| 2286 |
ret_err(_("setting log facility is not possible under Android")); |
| 2287 |
#else |
| 2288 |
for (i = 0; facilitynames[i].c_name; i++) |
| 2289 |
if (hostname_isequal((char *)facilitynames[i].c_name, arg)) |
| 2290 |
break; |
| 2291 |
|
| 2292 |
if (facilitynames[i].c_name) |
| 2293 |
daemon->log_fac = facilitynames[i].c_val; |
| 2294 |
else |
| 2295 |
ret_err(_("bad log facility")); |
| 2296 |
#endif |
| 2297 |
} |
| 2298 |
break; |
| 2299 |
|
| 2300 |
case 'x': /* --pid-file */ |
| 2301 |
daemon->runfile = opt_string_alloc(arg); |
| 2302 |
break; |
| 2303 |
|
| 2304 |
case 'r': /* --resolv-file */ |
| 2305 |
{ |
| 2306 |
char *name = opt_string_alloc(arg); |
| 2307 |
struct resolvc *new, *list = daemon->resolv_files; |
| 2308 |
|
| 2309 |
if (list && list->is_default) |
| 2310 |
{ |
| 2311 |
/* replace default resolv file - possibly with nothing */ |
| 2312 |
if (name) |
| 2313 |
{ |
| 2314 |
list->is_default = 0; |
| 2315 |
list->name = name; |
| 2316 |
} |
| 2317 |
else |
| 2318 |
list = NULL; |
| 2319 |
} |
| 2320 |
else if (name) |
| 2321 |
{ |
| 2322 |
new = opt_malloc(sizeof(struct resolvc)); |
| 2323 |
new->next = list; |
| 2324 |
new->name = name; |
| 2325 |
new->is_default = 0; |
| 2326 |
new->mtime = 0; |
| 2327 |
new->logged = 0; |
| 2328 |
list = new; |
| 2329 |
} |
| 2330 |
daemon->resolv_files = list; |
| 2331 |
break; |
| 2332 |
} |
| 2333 |
|
| 2334 |
case LOPT_SERVERS_FILE: |
| 2335 |
daemon->servers_file = opt_string_alloc(arg); |
| 2336 |
break; |
| 2337 |
|
| 2338 |
case 'm': /* --mx-host */ |
| 2339 |
{ |
| 2340 |
int pref = 1; |
| 2341 |
struct mx_srv_record *new; |
| 2342 |
char *name, *target = NULL; |
| 2343 |
|
| 2344 |
if ((comma = split(arg))) |
| 2345 |
{ |
| 2346 |
char *prefstr; |
| 2347 |
if ((prefstr = split(comma)) && !atoi_check16(prefstr, &pref)) |
| 2348 |
ret_err(_("bad MX preference")); |
| 2349 |
} |
| 2350 |
|
| 2351 |
if (!(name = canonicalise_opt(arg)) || |
| 2352 |
(comma && !(target = canonicalise_opt(comma)))) |
| 2353 |
{ |
| 2354 |
free(name); |
| 2355 |
free(target); |
| 2356 |
ret_err(_("bad MX name")); |
| 2357 |
} |
| 2358 |
|
| 2359 |
new = opt_malloc(sizeof(struct mx_srv_record)); |
| 2360 |
new->next = daemon->mxnames; |
| 2361 |
daemon->mxnames = new; |
| 2362 |
new->issrv = 0; |
| 2363 |
new->name = name; |
| 2364 |
new->target = target; /* may be NULL */ |
| 2365 |
new->weight = pref; |
| 2366 |
break; |
| 2367 |
} |
| 2368 |
|
| 2369 |
case 't': /* --mx-target */ |
| 2370 |
if (!(daemon->mxtarget = canonicalise_opt(arg))) |
| 2371 |
ret_err(_("bad MX target")); |
| 2372 |
break; |
| 2373 |
|
| 2374 |
case LOPT_DUMPFILE: /* --dumpfile */ |
| 2375 |
daemon->dump_file = opt_string_alloc(arg); |
| 2376 |
break; |
| 2377 |
|
| 2378 |
case LOPT_DUMPMASK: /* --dumpmask */ |
| 2379 |
daemon->dump_mask = strtol(arg, NULL, 0); |
| 2380 |
break; |
| 2381 |
|
| 2382 |
#ifdef HAVE_DHCP |
| 2383 |
case 'l': /* --dhcp-leasefile */ |
| 2384 |
daemon->lease_file = opt_string_alloc(arg); |
| 2385 |
break; |
| 2386 |
|
| 2387 |
/* Sorry about the gross pre-processor abuse */ |
| 2388 |
case '6': /* --dhcp-script */ |
| 2389 |
case LOPT_LUASCRIPT: /* --dhcp-luascript */ |
| 2390 |
# if !defined(HAVE_SCRIPT) |
| 2391 |
ret_err(_("recompile with HAVE_SCRIPT defined to enable lease-change scripts")); |
| 2392 |
# else |
| 2393 |
if (option == LOPT_LUASCRIPT) |
| 2394 |
# if !defined(HAVE_LUASCRIPT) |
| 2395 |
ret_err(_("recompile with HAVE_LUASCRIPT defined to enable Lua scripts")); |
| 2396 |
# else |
| 2397 |
daemon->luascript = opt_string_alloc(arg); |
| 2398 |
# endif |
| 2399 |
else |
| 2400 |
daemon->lease_change_command = opt_string_alloc(arg); |
| 2401 |
# endif |
| 2402 |
break; |
| 2403 |
#endif /* HAVE_DHCP */ |
| 2404 |
|
| 2405 |
case LOPT_DHCP_HOST: /* --dhcp-hostsfile */ |
| 2406 |
case LOPT_DHCP_OPTS: /* --dhcp-optsfile */ |
| 2407 |
case 'H': /* --addn-hosts */ |
| 2408 |
{ |
| 2409 |
struct hostsfile *new = opt_malloc(sizeof(struct hostsfile)); |
| 2410 |
new->fname = opt_string_alloc(arg); |
| 2411 |
new->index = daemon->host_index++; |
| 2412 |
new->flags = 0; |
| 2413 |
if (option == 'H') |
| 2414 |
{ |
| 2415 |
new->next = daemon->addn_hosts; |
| 2416 |
daemon->addn_hosts = new; |
| 2417 |
} |
| 2418 |
else if (option == LOPT_DHCP_HOST) |
| 2419 |
{ |
| 2420 |
new->next = daemon->dhcp_hosts_file; |
| 2421 |
daemon->dhcp_hosts_file = new; |
| 2422 |
} |
| 2423 |
else if (option == LOPT_DHCP_OPTS) |
| 2424 |
{ |
| 2425 |
new->next = daemon->dhcp_opts_file; |
| 2426 |
daemon->dhcp_opts_file = new; |
| 2427 |
} |
| 2428 |
|
| 2429 |
break; |
| 2430 |
} |
| 2431 |
|
| 2432 |
case LOPT_DHCP_INOTIFY: /* --dhcp-hostsdir */ |
| 2433 |
case LOPT_DHOPT_INOTIFY: /* --dhcp-optsdir */ |
| 2434 |
case LOPT_HOST_INOTIFY: /* --hostsdir */ |
| 2435 |
{ |
| 2436 |
struct dyndir *new = opt_malloc(sizeof(struct dyndir)); |
| 2437 |
new->dname = opt_string_alloc(arg); |
| 2438 |
new->flags = 0; |
| 2439 |
new->next = daemon->dynamic_dirs; |
| 2440 |
daemon->dynamic_dirs = new; |
| 2441 |
if (option == LOPT_DHCP_INOTIFY) |
| 2442 |
new->flags |= AH_DHCP_HST; |
| 2443 |
else if (option == LOPT_DHOPT_INOTIFY) |
| 2444 |
new->flags |= AH_DHCP_OPT; |
| 2445 |
else if (option == LOPT_HOST_INOTIFY) |
| 2446 |
new->flags |= AH_HOSTS; |
| 2447 |
|
| 2448 |
break; |
| 2449 |
} |
| 2450 |
|
| 2451 |
case LOPT_AUTHSERV: /* --auth-server */ |
| 2452 |
comma = split(arg); |
| 2453 |
|
| 2454 |
daemon->authserver = opt_string_alloc(arg); |
| 2455 |
|
| 2456 |
while ((arg = comma)) |
| 2457 |
{ |
| 2458 |
struct iname *new = opt_malloc(sizeof(struct iname)); |
| 2459 |
comma = split(arg); |
| 2460 |
new->name = NULL; |
| 2461 |
unhide_metas(arg); |
| 2462 |
if (inet_pton(AF_INET, arg, &new->addr.in.sin_addr) > 0) |
| 2463 |
new->addr.sa.sa_family = AF_INET; |
| 2464 |
else if (inet_pton(AF_INET6, arg, &new->addr.in6.sin6_addr) > 0) |
| 2465 |
new->addr.sa.sa_family = AF_INET6; |
| 2466 |
else |
| 2467 |
{ |
| 2468 |
char *fam = split_chr(arg, '/'); |
| 2469 |
new->name = opt_string_alloc(arg); |
| 2470 |
new->addr.sa.sa_family = 0; |
| 2471 |
if (fam) |
| 2472 |
{ |
| 2473 |
if (strcmp(fam, "4") == 0) |
| 2474 |
new->addr.sa.sa_family = AF_INET; |
| 2475 |
else if (strcmp(fam, "6") == 0) |
| 2476 |
new->addr.sa.sa_family = AF_INET6; |
| 2477 |
else |
| 2478 |
{ |
| 2479 |
free(new->name); |
| 2480 |
ret_err_free(gen_err, new); |
| 2481 |
} |
| 2482 |
} |
| 2483 |
} |
| 2484 |
new->next = daemon->authinterface; |
| 2485 |
daemon->authinterface = new; |
| 2486 |
}; |
| 2487 |
|
| 2488 |
break; |
| 2489 |
|
| 2490 |
case LOPT_AUTHSFS: /* --auth-sec-servers */ |
| 2491 |
{ |
| 2492 |
struct name_list *new; |
| 2493 |
|
| 2494 |
do { |
| 2495 |
comma = split(arg); |
| 2496 |
new = opt_malloc(sizeof(struct name_list)); |
| 2497 |
new->name = opt_string_alloc(arg); |
| 2498 |
new->next = daemon->secondary_forward_server; |
| 2499 |
daemon->secondary_forward_server = new; |
| 2500 |
arg = comma; |
| 2501 |
} while (arg); |
| 2502 |
break; |
| 2503 |
} |
| 2504 |
|
| 2505 |
case LOPT_AUTHZONE: /* --auth-zone */ |
| 2506 |
{ |
| 2507 |
struct auth_zone *new; |
| 2508 |
|
| 2509 |
comma = split(arg); |
| 2510 |
|
| 2511 |
new = opt_malloc(sizeof(struct auth_zone)); |
| 2512 |
new->domain = canonicalise_opt(arg); |
| 2513 |
if (!new->domain) |
| 2514 |
ret_err_free(_("invalid auth-zone"), new); |
| 2515 |
new->subnet = NULL; |
| 2516 |
new->exclude = NULL; |
| 2517 |
new->interface_names = NULL; |
| 2518 |
new->next = daemon->auth_zones; |
| 2519 |
daemon->auth_zones = new; |
| 2520 |
|
| 2521 |
while ((arg = comma)) |
| 2522 |
{ |
| 2523 |
int prefixlen = 0; |
| 2524 |
int is_exclude = 0; |
| 2525 |
char *prefix; |
| 2526 |
struct addrlist *subnet = NULL; |
| 2527 |
union all_addr addr; |
| 2528 |
|
| 2529 |
comma = split(arg); |
| 2530 |
prefix = split_chr(arg, '/'); |
| 2531 |
|
| 2532 |
if (prefix && !atoi_check(prefix, &prefixlen)) |
| 2533 |
ret_err(gen_err); |
| 2534 |
|
| 2535 |
if (strstr(arg, "exclude:") == arg) |
| 2536 |
{ |
| 2537 |
is_exclude = 1; |
| 2538 |
arg = arg+8; |
| 2539 |
} |
| 2540 |
|
| 2541 |
if (inet_pton(AF_INET, arg, &addr.addr4)) |
| 2542 |
{ |
| 2543 |
subnet = opt_malloc(sizeof(struct addrlist)); |
| 2544 |
subnet->prefixlen = (prefixlen == 0) ? 24 : prefixlen; |
| 2545 |
subnet->flags = ADDRLIST_LITERAL; |
| 2546 |
} |
| 2547 |
else if (inet_pton(AF_INET6, arg, &addr.addr6)) |
| 2548 |
{ |
| 2549 |
subnet = opt_malloc(sizeof(struct addrlist)); |
| 2550 |
subnet->prefixlen = (prefixlen == 0) ? 64 : prefixlen; |
| 2551 |
subnet->flags = ADDRLIST_LITERAL | ADDRLIST_IPV6; |
| 2552 |
} |
| 2553 |
else |
| 2554 |
{ |
| 2555 |
struct auth_name_list *name = opt_malloc(sizeof(struct auth_name_list)); |
| 2556 |
name->name = opt_string_alloc(arg); |
| 2557 |
name->flags = AUTH4 | AUTH6; |
| 2558 |
name->next = new->interface_names; |
| 2559 |
new->interface_names = name; |
| 2560 |
if (prefix) |
| 2561 |
{ |
| 2562 |
if (prefixlen == 4) |
| 2563 |
name->flags &= ~AUTH6; |
| 2564 |
else if (prefixlen == 6) |
| 2565 |
name->flags &= ~AUTH4; |
| 2566 |
else |
| 2567 |
ret_err(gen_err); |
| 2568 |
} |
| 2569 |
} |
| 2570 |
|
| 2571 |
if (subnet) |
| 2572 |
{ |
| 2573 |
subnet->addr = addr; |
| 2574 |
|
| 2575 |
if (is_exclude) |
| 2576 |
{ |
| 2577 |
subnet->next = new->exclude; |
| 2578 |
new->exclude = subnet; |
| 2579 |
} |
| 2580 |
else |
| 2581 |
{ |
| 2582 |
subnet->next = new->subnet; |
| 2583 |
new->subnet = subnet; |
| 2584 |
} |
| 2585 |
} |
| 2586 |
} |
| 2587 |
break; |
| 2588 |
} |
| 2589 |
|
| 2590 |
case LOPT_AUTHSOA: /* --auth-soa */ |
| 2591 |
comma = split(arg); |
| 2592 |
daemon->soa_sn = (u32)atoi(arg); |
| 2593 |
if (comma) |
| 2594 |
{ |
| 2595 |
char *cp; |
| 2596 |
arg = comma; |
| 2597 |
comma = split(arg); |
| 2598 |
daemon->hostmaster = opt_string_alloc(arg); |
| 2599 |
for (cp = daemon->hostmaster; cp && *cp; cp++) |
| 2600 |
if (*cp == '@') |
| 2601 |
*cp = '.'; |
| 2602 |
|
| 2603 |
if (comma) |
| 2604 |
{ |
| 2605 |
arg = comma; |
| 2606 |
comma = split(arg); |
| 2607 |
daemon->soa_refresh = (u32)atoi(arg); |
| 2608 |
if (comma) |
| 2609 |
{ |
| 2610 |
arg = comma; |
| 2611 |
comma = split(arg); |
| 2612 |
daemon->soa_retry = (u32)atoi(arg); |
| 2613 |
if (comma) |
| 2614 |
daemon->soa_expiry = (u32)atoi(comma); |
| 2615 |
} |
| 2616 |
} |
| 2617 |
} |
| 2618 |
|
| 2619 |
break; |
| 2620 |
|
| 2621 |
case 's': /* --domain */ |
| 2622 |
case LOPT_SYNTH: /* --synth-domain */ |
| 2623 |
{ |
| 2624 |
char *d, *d_raw = arg; |
| 2625 |
comma = split(arg); |
| 2626 |
if (!(d = canonicalise_opt(d_raw))) |
| 2627 |
ret_err(gen_err); |
| 2628 |
else |
| 2629 |
{ |
| 2630 |
free(d); /* allocate this again below. */ |
| 2631 |
if (comma) |
| 2632 |
{ |
| 2633 |
struct cond_domain *new = opt_malloc(sizeof(struct cond_domain)); |
| 2634 |
char *netpart; |
| 2635 |
|
| 2636 |
new->prefix = NULL; |
| 2637 |
new->indexed = 0; |
| 2638 |
new->prefixlen = 0; |
| 2639 |
|
| 2640 |
unhide_metas(comma); |
| 2641 |
if ((netpart = split_chr(comma, '/'))) |
| 2642 |
{ |
| 2643 |
int msize; |
| 2644 |
|
| 2645 |
arg = split(netpart); |
| 2646 |
if (!atoi_check(netpart, &msize)) |
| 2647 |
ret_err_free(gen_err, new); |
| 2648 |
else if (inet_pton(AF_INET, comma, &new->start)) |
| 2649 |
{ |
| 2650 |
int mask; |
| 2651 |
|
| 2652 |
if (msize > 32) |
| 2653 |
ret_err_free(_("bad prefix length"), new); |
| 2654 |
|
| 2655 |
mask = (1 << (32 - msize)) - 1; |
| 2656 |
new->is6 = 0; |
| 2657 |
new->start.s_addr = ntohl(htonl(new->start.s_addr) & ~mask); |
| 2658 |
new->end.s_addr = new->start.s_addr | htonl(mask); |
| 2659 |
if (arg) |
| 2660 |
{ |
| 2661 |
if (option != 's') |
| 2662 |
{ |
| 2663 |
/* IPv6 address is longest and represented as |
| 2664 |
xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx |
| 2665 |
which is 39 chars */ |
| 2666 |
if (!(new->prefix = canonicalise_opt(arg)) || |
| 2667 |
strlen(new->prefix) > (MAXLABEL - 39)) |
| 2668 |
ret_err_free(_("bad prefix"), new); |
| 2669 |
} |
| 2670 |
else if (strcmp(arg, "local") != 0) |
| 2671 |
ret_err_free(gen_err, new); |
| 2672 |
else |
| 2673 |
{ |
| 2674 |
/* local=/xxx.yyy.zzz.in-addr.arpa/ */ |
| 2675 |
domain_rev4(0, NULL, &new->start, msize); |
| 2676 |
|
| 2677 |
/* local=/<domain>/ */ |
| 2678 |
/* d_raw can't failed to canonicalise here, checked above. */ |
| 2679 |
add_update_server(SERV_LITERAL_ADDRESS, NULL, NULL, NULL, d_raw, NULL); |
| 2680 |
} |
| 2681 |
} |
| 2682 |
} |
| 2683 |
else if (inet_pton(AF_INET6, comma, &new->start6)) |
| 2684 |
{ |
| 2685 |
u64 mask, addrpart = addr6part(&new->start6); |
| 2686 |
|
| 2687 |
if (msize > 128) |
| 2688 |
ret_err_free(_("bad prefix length"), new); |
| 2689 |
|
| 2690 |
/* prefix==64 overflows the mask calculation */ |
| 2691 |
if (msize <= 64) |
| 2692 |
mask = (u64)-1LL; |
| 2693 |
else |
| 2694 |
mask = (1LLU << (128 - msize)) - 1LLU; |
| 2695 |
|
| 2696 |
new->is6 = 1; |
| 2697 |
new->prefixlen = msize; |
| 2698 |
|
| 2699 |
new->end6 = new->start6; |
| 2700 |
setaddr6part(&new->start6, addrpart & ~mask); |
| 2701 |
setaddr6part(&new->end6, addrpart | mask); |
| 2702 |
|
| 2703 |
if (arg) |
| 2704 |
{ |
| 2705 |
if (option != 's') |
| 2706 |
{ |
| 2707 |
if (!(new->prefix = canonicalise_opt(arg)) || |
| 2708 |
strlen(new->prefix) > MAXLABEL - INET6_ADDRSTRLEN) |
| 2709 |
ret_err_free(_("bad prefix"), new); |
| 2710 |
} |
| 2711 |
else if (strcmp(arg, "local") != 0) |
| 2712 |
ret_err_free(gen_err, new); |
| 2713 |
else |
| 2714 |
{ |
| 2715 |
/* generate the equivalent of |
| 2716 |
local=/xxx.yyy.zzz.ip6.arpa/ */ |
| 2717 |
domain_rev6(0, NULL, &new->start6, msize); |
| 2718 |
|
| 2719 |
/* local=/<domain>/ */ |
| 2720 |
/* d_raw can't failed to canonicalise here, checked above. */ |
| 2721 |
add_update_server(SERV_LITERAL_ADDRESS, NULL, NULL, NULL, d_raw, NULL); |
| 2722 |
} |
| 2723 |
} |
| 2724 |
} |
| 2725 |
else |
| 2726 |
ret_err_free(gen_err, new); |
| 2727 |
} |
| 2728 |
else |
| 2729 |
{ |
| 2730 |
char *prefstr; |
| 2731 |
arg = split(comma); |
| 2732 |
prefstr = split(arg); |
| 2733 |
|
| 2734 |
if (inet_pton(AF_INET, comma, &new->start)) |
| 2735 |
{ |
| 2736 |
new->is6 = 0; |
| 2737 |
if (!arg) |
| 2738 |
new->end.s_addr = new->start.s_addr; |
| 2739 |
else if (!inet_pton(AF_INET, arg, &new->end)) |
| 2740 |
ret_err_free(gen_err, new); |
| 2741 |
} |
| 2742 |
else if (inet_pton(AF_INET6, comma, &new->start6)) |
| 2743 |
{ |
| 2744 |
new->is6 = 1; |
| 2745 |
if (!arg) |
| 2746 |
memcpy(&new->end6, &new->start6, IN6ADDRSZ); |
| 2747 |
else if (!inet_pton(AF_INET6, arg, &new->end6)) |
| 2748 |
ret_err_free(gen_err, new); |
| 2749 |
} |
| 2750 |
else if (option == 's') |
| 2751 |
{ |
| 2752 |
/* subnet from interface. */ |
| 2753 |
new->interface = opt_string_alloc(comma); |
| 2754 |
new->al = NULL; |
| 2755 |
} |
| 2756 |
else |
| 2757 |
ret_err_free(gen_err, new); |
| 2758 |
|
| 2759 |
if (option != 's' && prefstr) |
| 2760 |
{ |
| 2761 |
if (!(new->prefix = canonicalise_opt(prefstr)) || |
| 2762 |
strlen(new->prefix) > MAXLABEL - INET_ADDRSTRLEN) |
| 2763 |
ret_err_free(_("bad prefix"), new); |
| 2764 |
} |
| 2765 |
} |
| 2766 |
|
| 2767 |
new->domain = canonicalise_opt(d_raw); |
| 2768 |
if (option == 's') |
| 2769 |
{ |
| 2770 |
new->next = daemon->cond_domain; |
| 2771 |
daemon->cond_domain = new; |
| 2772 |
} |
| 2773 |
else |
| 2774 |
{ |
| 2775 |
char *star; |
| 2776 |
if (new->prefix && |
| 2777 |
(star = strrchr(new->prefix, '*')) |
| 2778 |
&& *(star+1) == 0) |
| 2779 |
{ |
| 2780 |
*star = 0; |
| 2781 |
new->indexed = 1; |
| 2782 |
if (new->is6 && new->prefixlen < 64) |
| 2783 |
ret_err_free(_("prefix length too small"), new); |
| 2784 |
} |
| 2785 |
new->next = daemon->synth_domains; |
| 2786 |
daemon->synth_domains = new; |
| 2787 |
} |
| 2788 |
} |
| 2789 |
else if (option == 's') |
| 2790 |
{ |
| 2791 |
if (strcmp (arg, "#") == 0) |
| 2792 |
set_option_bool(OPT_RESOLV_DOMAIN); |
| 2793 |
else |
| 2794 |
daemon->domain_suffix = canonicalise_opt(d_raw); |
| 2795 |
} |
| 2796 |
else |
| 2797 |
ret_err(gen_err); |
| 2798 |
} |
| 2799 |
|
| 2800 |
break; |
| 2801 |
} |
| 2802 |
|
| 2803 |
case LOPT_CPE_ID: /* --add-dns-client */ |
| 2804 |
if (arg) |
| 2805 |
daemon->dns_client_id = opt_string_alloc(arg); |
| 2806 |
break; |
| 2807 |
|
| 2808 |
case LOPT_UMBRELLA: /* --umbrella */ |
| 2809 |
set_option_bool(OPT_UMBRELLA); |
| 2810 |
while (arg) |
| 2811 |
{ |
| 2812 |
comma = split(arg); |
| 2813 |
if (strstr(arg, "deviceid:")) |
| 2814 |
{ |
| 2815 |
char *p; |
| 2816 |
u8 *u = daemon->umbrella_device; |
| 2817 |
char word[3]; |
| 2818 |
|
| 2819 |
arg += 9; |
| 2820 |
if (strlen(arg) != 16) |
| 2821 |
ret_err(gen_err); |
| 2822 |
|
| 2823 |
for (p = arg; *p; p++) |
| 2824 |
if (!isxdigit((unsigned char)*p)) |
| 2825 |
ret_err(gen_err); |
| 2826 |
|
| 2827 |
set_option_bool(OPT_UMBRELLA_DEVID); |
| 2828 |
|
| 2829 |
for (i = 0; i < (int)sizeof(daemon->umbrella_device); i++, arg+=2) |
| 2830 |
{ |
| 2831 |
memcpy(word, &(arg[0]), 2); |
| 2832 |
*u++ = strtoul(word, NULL, 16); |
| 2833 |
} |
| 2834 |
} |
| 2835 |
else if (strstr(arg, "orgid:")) |
| 2836 |
{ |
| 2837 |
if (!strtoul_check(arg+6, &daemon->umbrella_org)) |
| 2838 |
ret_err(gen_err); |
| 2839 |
} |
| 2840 |
else if (strstr(arg, "assetid:")) |
| 2841 |
{ |
| 2842 |
if (!strtoul_check(arg+8, &daemon->umbrella_asset)) |
| 2843 |
ret_err(gen_err); |
| 2844 |
} |
| 2845 |
else |
| 2846 |
ret_err(gen_err); |
| 2847 |
|
| 2848 |
arg = comma; |
| 2849 |
} |
| 2850 |
break; |
| 2851 |
|
| 2852 |
case LOPT_ADD_MAC: /* --add-mac */ |
| 2853 |
if (!arg) |
| 2854 |
set_option_bool(OPT_ADD_MAC); |
| 2855 |
else |
| 2856 |
{ |
| 2857 |
unhide_metas(arg); |
| 2858 |
if (strcmp(arg, "base64") == 0) |
| 2859 |
set_option_bool(OPT_MAC_B64); |
| 2860 |
else if (strcmp(arg, "text") == 0) |
| 2861 |
set_option_bool(OPT_MAC_HEX); |
| 2862 |
else |
| 2863 |
ret_err(gen_err); |
| 2864 |
} |
| 2865 |
break; |
| 2866 |
|
| 2867 |
case 'u': /* --user */ |
| 2868 |
daemon->username = opt_string_alloc(arg); |
| 2869 |
break; |
| 2870 |
|
| 2871 |
case 'g': /* --group */ |
| 2872 |
daemon->groupname = opt_string_alloc(arg); |
| 2873 |
daemon->group_set = 1; |
| 2874 |
break; |
| 2875 |
|
| 2876 |
#ifdef HAVE_DHCP |
| 2877 |
case LOPT_SCRIPTUSR: /* --scriptuser */ |
| 2878 |
daemon->scriptuser = opt_string_alloc(arg); |
| 2879 |
break; |
| 2880 |
#endif |
| 2881 |
|
| 2882 |
case 'i': /* --interface */ |
| 2883 |
do { |
| 2884 |
comma = split(arg); |
| 2885 |
if_names_add(arg); |
| 2886 |
arg = comma; |
| 2887 |
} while (arg); |
| 2888 |
break; |
| 2889 |
|
| 2890 |
case LOPT_TFTP: /* --enable-tftp */ |
| 2891 |
set_option_bool(OPT_TFTP); |
| 2892 |
if (!arg) |
| 2893 |
break; |
| 2894 |
/* fall through */ |
| 2895 |
|
| 2896 |
case 'I': /* --except-interface */ |
| 2897 |
case '2': /* --no-dhcp-interface */ |
| 2898 |
case LOPT_NO_DHCP6: /* --no-dhcpv6-interface */ |
| 2899 |
case LOPT_NO_DHCP4: /* --no-dhcpv4-interface */ |
| 2900 |
do { |
| 2901 |
struct iname *new = opt_malloc(sizeof(struct iname)); |
| 2902 |
comma = split(arg); |
| 2903 |
new->name = opt_string_alloc(arg); |
| 2904 |
new->flags = INAME_4 | INAME_6; |
| 2905 |
if (option == 'I') |
| 2906 |
{ |
| 2907 |
new->next = daemon->if_except; |
| 2908 |
daemon->if_except = new; |
| 2909 |
} |
| 2910 |
else if (option == LOPT_TFTP) |
| 2911 |
{ |
| 2912 |
new->next = daemon->tftp_interfaces; |
| 2913 |
daemon->tftp_interfaces = new; |
| 2914 |
} |
| 2915 |
else |
| 2916 |
{ |
| 2917 |
if (option == LOPT_NO_DHCP6) |
| 2918 |
new->flags &= ~INAME_4; |
| 2919 |
if (option == LOPT_NO_DHCP4) |
| 2920 |
new->flags &= ~INAME_6; |
| 2921 |
new->next = daemon->dhcp_except; |
| 2922 |
daemon->dhcp_except = new; |
| 2923 |
} |
| 2924 |
arg = comma; |
| 2925 |
} while (arg); |
| 2926 |
break; |
| 2927 |
|
| 2928 |
#ifdef HAVE_DHCP |
| 2929 |
# if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) |
| 2930 |
# pragma GCC diagnostic push |
| 2931 |
# pragma GCC diagnostic ignored "-Wimplicit-fallthrough" |
| 2932 |
# endif |
| 2933 |
case LOPT_LEASEQUERY: |
| 2934 |
set_option_bool(OPT_LEASEQUERY); |
| 2935 |
if (!arg) |
| 2936 |
break; |
| 2937 |
# if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) |
| 2938 |
# pragma GCC diagnostic pop |
| 2939 |
# endif |
| 2940 |
#endif |
| 2941 |
case 'B': /* --bogus-nxdomain */ |
| 2942 |
case LOPT_IGNORE_ADDR: /* --ignore-address */ |
| 2943 |
{ |
| 2944 |
union all_addr addr; |
| 2945 |
int prefix, is6 = 0; |
| 2946 |
struct bogus_addr *baddr; |
| 2947 |
|
| 2948 |
unhide_metas(arg); |
| 2949 |
|
| 2950 |
if (!arg || |
| 2951 |
((comma = split_chr(arg, '/')) && !atoi_check(comma, &prefix))) |
| 2952 |
ret_err(gen_err); |
| 2953 |
|
| 2954 |
if (inet_pton(AF_INET6, arg, &addr.addr6) == 1) |
| 2955 |
is6 = 1; |
| 2956 |
else if (inet_pton(AF_INET, arg, &addr.addr4) != 1) |
| 2957 |
ret_err(gen_err); |
| 2958 |
|
| 2959 |
if (!comma) |
| 2960 |
{ |
| 2961 |
if (is6) |
| 2962 |
prefix = 128; |
| 2963 |
else |
| 2964 |
prefix = 32; |
| 2965 |
} |
| 2966 |
|
| 2967 |
if (prefix > 128 || (!is6 && prefix > 32)) |
| 2968 |
ret_err(gen_err); |
| 2969 |
|
| 2970 |
baddr = opt_malloc(sizeof(struct bogus_addr)); |
| 2971 |
if (option == 'B') |
| 2972 |
{ |
| 2973 |
baddr->next = daemon->bogus_addr; |
| 2974 |
daemon->bogus_addr = baddr; |
| 2975 |
} |
| 2976 |
#ifdef HAVE_DHCP |
| 2977 |
else if (option == LOPT_LEASEQUERY) |
| 2978 |
{ |
| 2979 |
baddr->next = daemon->leasequery_addr; |
| 2980 |
daemon->leasequery_addr = baddr; |
| 2981 |
} |
| 2982 |
#endif |
| 2983 |
else |
| 2984 |
{ |
| 2985 |
baddr->next = daemon->ignore_addr; |
| 2986 |
daemon->ignore_addr = baddr; |
| 2987 |
} |
| 2988 |
|
| 2989 |
baddr->prefix = prefix; |
| 2990 |
baddr->is6 = is6; |
| 2991 |
baddr->addr = addr; |
| 2992 |
break; |
| 2993 |
} |
| 2994 |
|
| 2995 |
case 'a': /* --listen-address */ |
| 2996 |
case LOPT_AUTHPEER: /* --auth-peer */ |
| 2997 |
do { |
| 2998 |
struct iname *new = opt_malloc(sizeof(struct iname)); |
| 2999 |
comma = split(arg); |
| 3000 |
unhide_metas(arg); |
| 3001 |
if (arg && (inet_pton(AF_INET, arg, &new->addr.in.sin_addr) > 0)) |
| 3002 |
{ |
| 3003 |
new->addr.sa.sa_family = AF_INET; |
| 3004 |
new->addr.in.sin_port = 0; |
| 3005 |
#ifdef HAVE_SOCKADDR_SA_LEN |
| 3006 |
new->addr.in.sin_len = sizeof(new->addr.in); |
| 3007 |
#endif |
| 3008 |
} |
| 3009 |
else if (arg && inet_pton(AF_INET6, arg, &new->addr.in6.sin6_addr) > 0) |
| 3010 |
{ |
| 3011 |
new->addr.sa.sa_family = AF_INET6; |
| 3012 |
new->addr.in6.sin6_flowinfo = 0; |
| 3013 |
new->addr.in6.sin6_scope_id = 0; |
| 3014 |
new->addr.in6.sin6_port = 0; |
| 3015 |
#ifdef HAVE_SOCKADDR_SA_LEN |
| 3016 |
new->addr.in6.sin6_len = sizeof(new->addr.in6); |
| 3017 |
#endif |
| 3018 |
} |
| 3019 |
else |
| 3020 |
ret_err_free(gen_err, new); |
| 3021 |
|
| 3022 |
new->flags = 0; |
| 3023 |
if (option == 'a') |
| 3024 |
{ |
| 3025 |
new->next = daemon->if_addrs; |
| 3026 |
daemon->if_addrs = new; |
| 3027 |
} |
| 3028 |
else |
| 3029 |
{ |
| 3030 |
new->next = daemon->auth_peers; |
| 3031 |
daemon->auth_peers = new; |
| 3032 |
} |
| 3033 |
arg = comma; |
| 3034 |
} while (arg); |
| 3035 |
break; |
| 3036 |
|
| 3037 |
case LOPT_NO_REBIND: /* --rebind-domain-ok */ |
| 3038 |
{ |
| 3039 |
struct rebind_domain *new; |
| 3040 |
|
| 3041 |
unhide_metas(arg); |
| 3042 |
|
| 3043 |
if (*arg == '/') |
| 3044 |
arg++; |
| 3045 |
|
| 3046 |
do { |
| 3047 |
comma = split_chr(arg, '/'); |
| 3048 |
new = opt_malloc(sizeof(struct rebind_domain)); |
| 3049 |
new->domain = canonicalise_opt(arg); |
| 3050 |
new->next = daemon->no_rebind; |
| 3051 |
daemon->no_rebind = new; |
| 3052 |
arg = comma; |
| 3053 |
} while (arg && *arg); |
| 3054 |
|
| 3055 |
break; |
| 3056 |
} |
| 3057 |
|
| 3058 |
case 'S': /* --server */ |
| 3059 |
case LOPT_LOCAL: /* --local */ |
| 3060 |
case 'A': /* --address */ |
| 3061 |
{ |
| 3062 |
char *lastdomain = NULL, *domain = "", *cur_domain; |
| 3063 |
u16 flags = 0; |
| 3064 |
char *err; |
| 3065 |
union all_addr addr; |
| 3066 |
union mysockaddr serv_addr, source_addr; |
| 3067 |
char interface[IF_NAMESIZE+1]; |
| 3068 |
struct server_details sdetails; |
| 3069 |
|
| 3070 |
memset(&sdetails, 0, sizeof(struct server_details)); |
| 3071 |
sdetails.addr = &serv_addr; |
| 3072 |
sdetails.source_addr = &source_addr; |
| 3073 |
sdetails.interface = interface; |
| 3074 |
sdetails.flags = &flags; |
| 3075 |
|
| 3076 |
unhide_metas(arg); |
| 3077 |
|
| 3078 |
/* split the domain args, if any and skip to the end of them. */ |
| 3079 |
if (arg && *arg == '/') |
| 3080 |
{ |
| 3081 |
char *last; |
| 3082 |
|
| 3083 |
domain = lastdomain = ++arg; |
| 3084 |
|
| 3085 |
while ((last = split_chr(arg, '/'))) |
| 3086 |
{ |
| 3087 |
lastdomain = arg; |
| 3088 |
arg = last; |
| 3089 |
} |
| 3090 |
} |
| 3091 |
|
| 3092 |
if (!arg || !*arg) |
| 3093 |
flags = SERV_LITERAL_ADDRESS; |
| 3094 |
else if (option == 'A') |
| 3095 |
{ |
| 3096 |
/* # as literal address means return zero address for 4 and 6 */ |
| 3097 |
if (strcmp(arg, "#") == 0) |
| 3098 |
flags = SERV_ALL_ZEROS | SERV_LITERAL_ADDRESS; |
| 3099 |
else if (inet_pton(AF_INET, arg, &addr.addr4) > 0) |
| 3100 |
flags = SERV_4ADDR | SERV_LITERAL_ADDRESS; |
| 3101 |
else if (inet_pton(AF_INET6, arg, &addr.addr6) > 0) |
| 3102 |
flags = SERV_6ADDR | SERV_LITERAL_ADDRESS; |
| 3103 |
else |
| 3104 |
ret_err(_("Bad address in --address")); |
| 3105 |
} |
| 3106 |
else |
| 3107 |
{ |
| 3108 |
if ((err = parse_server(arg, &sdetails))) |
| 3109 |
ret_err(err); |
| 3110 |
} |
| 3111 |
|
| 3112 |
if (servers_only && option == 'S') |
| 3113 |
flags |= SERV_FROM_FILE; |
| 3114 |
|
| 3115 |
cur_domain = domain; |
| 3116 |
while ((flags & SERV_LITERAL_ADDRESS) || parse_server_next(&sdetails)) |
| 3117 |
{ |
| 3118 |
cur_domain = domain; |
| 3119 |
|
| 3120 |
if (!(flags & SERV_LITERAL_ADDRESS) && (err = parse_server_addr(&sdetails))) |
| 3121 |
ret_err(err); |
| 3122 |
|
| 3123 |
/* When source is set only use DNS records of the same type and skip all others */ |
| 3124 |
if (flags & SERV_HAS_SOURCE && sdetails.addr_type != sdetails.source_addr->sa.sa_family) |
| 3125 |
continue; |
| 3126 |
|
| 3127 |
while (1) |
| 3128 |
{ |
| 3129 |
/* server=//1.2.3.4 is special. */ |
| 3130 |
if (lastdomain) |
| 3131 |
{ |
| 3132 |
if (strlen(cur_domain) == 0) |
| 3133 |
flags |= SERV_FOR_NODOTS; |
| 3134 |
else |
| 3135 |
flags &= ~SERV_FOR_NODOTS; |
| 3136 |
|
| 3137 |
/* address=/#/ matches the same as without domain, as does server=/#/.... for consistency. */ |
| 3138 |
if (cur_domain[0] == '#' && cur_domain[1] == 0) |
| 3139 |
cur_domain[0] = 0; |
| 3140 |
} |
| 3141 |
|
| 3142 |
if (!add_update_server(flags, sdetails.addr, sdetails.source_addr, sdetails.interface, cur_domain, &addr)) |
| 3143 |
ret_err(gen_err); |
| 3144 |
|
| 3145 |
if (!lastdomain || cur_domain == lastdomain) |
| 3146 |
break; |
| 3147 |
|
| 3148 |
cur_domain += strlen(cur_domain) + 1; |
| 3149 |
} |
| 3150 |
|
| 3151 |
if (flags & SERV_LITERAL_ADDRESS) |
| 3152 |
break; |
| 3153 |
} |
| 3154 |
|
| 3155 |
if (sdetails.orig_hostinfo) |
| 3156 |
freeaddrinfo(sdetails.orig_hostinfo); |
| 3157 |
|
| 3158 |
break; |
| 3159 |
} |
| 3160 |
|
| 3161 |
case LOPT_REV_SERV: /* --rev-server */ |
| 3162 |
{ |
| 3163 |
char *string; |
| 3164 |
int size; |
| 3165 |
struct in_addr addr4; |
| 3166 |
struct in6_addr addr6; |
| 3167 |
|
| 3168 |
unhide_metas(arg); |
| 3169 |
if (!arg) |
| 3170 |
ret_err(gen_err); |
| 3171 |
|
| 3172 |
comma=split(arg); |
| 3173 |
|
| 3174 |
if (!(string = split_chr(arg, '/')) || !atoi_check(string, &size)) |
| 3175 |
size = -1; |
| 3176 |
|
| 3177 |
if (inet_pton(AF_INET, arg, &addr4)) |
| 3178 |
{ |
| 3179 |
if (size == -1) |
| 3180 |
size = 32; |
| 3181 |
|
| 3182 |
if ((string = domain_rev4(servers_only, comma, &addr4, size))) |
| 3183 |
ret_err(string); |
| 3184 |
} |
| 3185 |
else if (inet_pton(AF_INET6, arg, &addr6)) |
| 3186 |
{ |
| 3187 |
if (size == -1) |
| 3188 |
size = 128; |
| 3189 |
|
| 3190 |
if ((string = domain_rev6(servers_only, comma, &addr6, size))) |
| 3191 |
ret_err(string); |
| 3192 |
} |
| 3193 |
else |
| 3194 |
ret_err(gen_err); |
| 3195 |
|
| 3196 |
break; |
| 3197 |
} |
| 3198 |
|
| 3199 |
case LOPT_IPSET: /* --ipset */ |
| 3200 |
case LOPT_NFTSET: /* --nftset */ |
| 3201 |
#ifndef HAVE_IPSET |
| 3202 |
if (option == LOPT_IPSET) |
| 3203 |
{ |
| 3204 |
ret_err(_("recompile with HAVE_IPSET defined to enable ipset directives")); |
| 3205 |
break; |
| 3206 |
} |
| 3207 |
#endif |
| 3208 |
#ifndef HAVE_NFTSET |
| 3209 |
if (option == LOPT_NFTSET) |
| 3210 |
{ |
| 3211 |
ret_err(_("recompile with HAVE_NFTSET defined to enable nftset directives")); |
| 3212 |
break; |
| 3213 |
} |
| 3214 |
#endif |
| 3215 |
|
| 3216 |
{ |
| 3217 |
struct ipsets ipsets_head; |
| 3218 |
struct ipsets *ipsets = &ipsets_head; |
| 3219 |
struct ipsets **daemon_sets = |
| 3220 |
(option == LOPT_IPSET) ? &daemon->ipsets : &daemon->nftsets; |
| 3221 |
int size; |
| 3222 |
char *end; |
| 3223 |
char **sets, **sets_pos; |
| 3224 |
memset(ipsets, 0, sizeof(struct ipsets)); |
| 3225 |
unhide_metas(arg); |
| 3226 |
if (arg && *arg == '/') |
| 3227 |
{ |
| 3228 |
arg++; |
| 3229 |
while ((end = split_chr(arg, '/'))) |
| 3230 |
{ |
| 3231 |
char *domain = NULL; |
| 3232 |
/* elide leading dots - they are implied in the search algorithm */ |
| 3233 |
while (*arg == '.') |
| 3234 |
arg++; |
| 3235 |
/* # matches everything and becomes a zero length domain string */ |
| 3236 |
if (strcmp(arg, "#") == 0 || !*arg) |
| 3237 |
domain = ""; |
| 3238 |
else if (strlen(arg) != 0 && !(domain = canonicalise_opt(arg))) |
| 3239 |
ret_err(gen_err); |
| 3240 |
ipsets->next = opt_malloc(sizeof(struct ipsets)); |
| 3241 |
ipsets = ipsets->next; |
| 3242 |
memset(ipsets, 0, sizeof(struct ipsets)); |
| 3243 |
ipsets->domain = domain; |
| 3244 |
arg = end; |
| 3245 |
} |
| 3246 |
} |
| 3247 |
else |
| 3248 |
{ |
| 3249 |
ipsets->next = opt_malloc(sizeof(struct ipsets)); |
| 3250 |
ipsets = ipsets->next; |
| 3251 |
memset(ipsets, 0, sizeof(struct ipsets)); |
| 3252 |
ipsets->domain = ""; |
| 3253 |
} |
| 3254 |
|
| 3255 |
if (!arg || !*arg) |
| 3256 |
ret_err(gen_err); |
| 3257 |
|
| 3258 |
for (size = 2, end = arg; *end; ++end) |
| 3259 |
if (*end == ',') |
| 3260 |
++size; |
| 3261 |
|
| 3262 |
sets = sets_pos = opt_malloc(sizeof(char *) * size); |
| 3263 |
|
| 3264 |
do { |
| 3265 |
char *p; |
| 3266 |
end = split(arg); |
| 3267 |
*sets_pos = opt_string_alloc(arg); |
| 3268 |
/* Use '#' to delimit table and set */ |
| 3269 |
if (option == LOPT_NFTSET) |
| 3270 |
while ((p = strchr(*sets_pos, '#'))) |
| 3271 |
*p = ' '; |
| 3272 |
sets_pos++; |
| 3273 |
arg = end; |
| 3274 |
} while (end); |
| 3275 |
*sets_pos = 0; |
| 3276 |
for (ipsets = &ipsets_head; ipsets->next; ipsets = ipsets->next) |
| 3277 |
ipsets->next->sets = sets; |
| 3278 |
ipsets->next = *daemon_sets; |
| 3279 |
*daemon_sets = ipsets_head.next; |
| 3280 |
|
| 3281 |
break; |
| 3282 |
} |
| 3283 |
|
| 3284 |
case LOPT_CMARK_ALST_EN: /* --connmark-allowlist-enable */ |
| 3285 |
#ifndef HAVE_CONNTRACK |
| 3286 |
ret_err(_("recompile with HAVE_CONNTRACK defined to enable connmark-allowlist directives")); |
| 3287 |
break; |
| 3288 |
#else |
| 3289 |
{ |
| 3290 |
u32 mask = UINT32_MAX; |
| 3291 |
|
| 3292 |
if (arg) |
| 3293 |
if (!strtoul_check(arg, &mask) || mask < 1) |
| 3294 |
ret_err(gen_err); |
| 3295 |
|
| 3296 |
set_option_bool(OPT_CMARK_ALST_EN); |
| 3297 |
daemon->allowlist_mask = mask; |
| 3298 |
break; |
| 3299 |
} |
| 3300 |
#endif |
| 3301 |
|
| 3302 |
case LOPT_CMARK_ALST: /* --connmark-allowlist */ |
| 3303 |
#ifndef HAVE_CONNTRACK |
| 3304 |
ret_err(_("recompile with HAVE_CONNTRACK defined to enable connmark-allowlist directives")); |
| 3305 |
break; |
| 3306 |
#else |
| 3307 |
{ |
| 3308 |
struct allowlist *allowlists; |
| 3309 |
char **patterns, **patterns_pos; |
| 3310 |
u32 mark, mask = UINT32_MAX; |
| 3311 |
size_t num_patterns = 0; |
| 3312 |
|
| 3313 |
char *c, *m = NULL; |
| 3314 |
char *separator; |
| 3315 |
unhide_metas(arg); |
| 3316 |
if (!arg) |
| 3317 |
ret_err(gen_err); |
| 3318 |
c = arg; |
| 3319 |
if (*c < '0' || *c > '9') |
| 3320 |
ret_err(gen_err); |
| 3321 |
while (*c && *c != ',') |
| 3322 |
{ |
| 3323 |
if (*c == '/') |
| 3324 |
{ |
| 3325 |
if (m) |
| 3326 |
ret_err(gen_err); |
| 3327 |
*c = '\0'; |
| 3328 |
m = ++c; |
| 3329 |
} |
| 3330 |
if (*c < '0' || *c > '9') |
| 3331 |
ret_err(gen_err); |
| 3332 |
c++; |
| 3333 |
} |
| 3334 |
separator = c; |
| 3335 |
if (!*separator) |
| 3336 |
break; |
| 3337 |
while (c && *c) |
| 3338 |
{ |
| 3339 |
char *end = strchr(++c, '/'); |
| 3340 |
if (end) |
| 3341 |
*end = '\0'; |
| 3342 |
if (strcmp(c, "*") && !is_valid_dns_name_pattern(c)) |
| 3343 |
ret_err(gen_err); |
| 3344 |
if (end) |
| 3345 |
*end = '/'; |
| 3346 |
if (num_patterns >= UINT16_MAX - 1) |
| 3347 |
ret_err(gen_err); |
| 3348 |
num_patterns++; |
| 3349 |
c = end; |
| 3350 |
} |
| 3351 |
|
| 3352 |
*separator = '\0'; |
| 3353 |
if (!strtoul_check(arg, &mark) || mark < 1 || mark > UINT32_MAX) |
| 3354 |
ret_err(gen_err); |
| 3355 |
if (m) |
| 3356 |
if (!strtoul_check(m, &mask) || mask < 1 || mask > UINT32_MAX || (mark & ~mask)) |
| 3357 |
ret_err(gen_err); |
| 3358 |
if (num_patterns) |
| 3359 |
*separator = ','; |
| 3360 |
for (allowlists = daemon->allowlists; allowlists; allowlists = allowlists->next) |
| 3361 |
if (allowlists->mark == mark && allowlists->mask == mask) |
| 3362 |
ret_err(gen_err); |
| 3363 |
|
| 3364 |
patterns = opt_malloc((num_patterns + 1) * sizeof(char *)); |
| 3365 |
if (!patterns) |
| 3366 |
goto fail_cmark_allowlist; |
| 3367 |
patterns_pos = patterns; |
| 3368 |
c = separator; |
| 3369 |
while (c && *c) |
| 3370 |
{ |
| 3371 |
char *end = strchr(++c, '/'); |
| 3372 |
if (end) |
| 3373 |
*end = '\0'; |
| 3374 |
if (!(*patterns_pos++ = opt_string_alloc(c))) |
| 3375 |
goto fail_cmark_allowlist; |
| 3376 |
if (end) |
| 3377 |
*end = '/'; |
| 3378 |
c = end; |
| 3379 |
} |
| 3380 |
*patterns_pos++ = NULL; |
| 3381 |
|
| 3382 |
allowlists = opt_malloc(sizeof(struct allowlist)); |
| 3383 |
if (!allowlists) |
| 3384 |
goto fail_cmark_allowlist; |
| 3385 |
memset(allowlists, 0, sizeof(struct allowlist)); |
| 3386 |
allowlists->mark = mark; |
| 3387 |
allowlists->mask = mask; |
| 3388 |
allowlists->patterns = patterns; |
| 3389 |
allowlists->next = daemon->allowlists; |
| 3390 |
daemon->allowlists = allowlists; |
| 3391 |
break; |
| 3392 |
|
| 3393 |
fail_cmark_allowlist: |
| 3394 |
if (patterns) |
| 3395 |
{ |
| 3396 |
for (patterns_pos = patterns; *patterns_pos; patterns_pos++) |
| 3397 |
{ |
| 3398 |
free(*patterns_pos); |
| 3399 |
*patterns_pos = NULL; |
| 3400 |
} |
| 3401 |
free(patterns); |
| 3402 |
patterns = NULL; |
| 3403 |
} |
| 3404 |
if (allowlists) |
| 3405 |
{ |
| 3406 |
free(allowlists); |
| 3407 |
allowlists = NULL; |
| 3408 |
} |
| 3409 |
ret_err(gen_err); |
| 3410 |
} |
| 3411 |
#endif |
| 3412 |
|
| 3413 |
case 'c': /* --cache-size */ |
| 3414 |
{ |
| 3415 |
int size; |
| 3416 |
|
| 3417 |
if (!atoi_check(arg, &size)) |
| 3418 |
ret_err(gen_err); |
| 3419 |
else |
| 3420 |
{ |
| 3421 |
/* zero is OK, and means no caching. */ |
| 3422 |
|
| 3423 |
if (size < 0) |
| 3424 |
size = 0; |
| 3425 |
|
| 3426 |
/* Note that for very large cache sizes, the malloc() |
| 3427 |
will overflow. For the size of the cache record |
| 3428 |
at the time this was noted, the value of "very large" |
| 3429 |
was 46684428. Limit to an order of magnitude less than |
| 3430 |
that to be safe from changes to the cache record. */ |
| 3431 |
if (size > 5000000) |
| 3432 |
size = 5000000; |
| 3433 |
|
| 3434 |
daemon->cachesize = size; |
| 3435 |
} |
| 3436 |
break; |
| 3437 |
} |
| 3438 |
|
| 3439 |
case 'p': /* --port */ |
| 3440 |
if (!atoi_check16(arg, &daemon->port)) |
| 3441 |
ret_err(gen_err); |
| 3442 |
break; |
| 3443 |
|
| 3444 |
case LOPT_MINPORT: /* --min-port */ |
| 3445 |
if (!atoi_check16(arg, &daemon->min_port)) |
| 3446 |
ret_err(gen_err); |
| 3447 |
break; |
| 3448 |
|
| 3449 |
case LOPT_MAXPORT: /* --max-port */ |
| 3450 |
if (!atoi_check16(arg, &daemon->max_port)) |
| 3451 |
ret_err(gen_err); |
| 3452 |
break; |
| 3453 |
|
| 3454 |
case '0': /* --dns-forward-max */ |
| 3455 |
if (!atoi_check(arg, &daemon->ftabsize)) |
| 3456 |
ret_err(gen_err); |
| 3457 |
break; |
| 3458 |
|
| 3459 |
case 'q': /* --log-queries */ |
| 3460 |
set_option_bool(OPT_LOG); |
| 3461 |
if (arg) |
| 3462 |
{ |
| 3463 |
if (strcmp(arg, "extra") == 0) |
| 3464 |
set_option_bool(OPT_EXTRALOG); |
| 3465 |
else if (strcmp(arg, "proto") == 0) |
| 3466 |
{ |
| 3467 |
set_option_bool(OPT_EXTRALOG); |
| 3468 |
set_option_bool(OPT_LOG_PROTO); |
| 3469 |
} |
| 3470 |
else if (strcmp(arg, "auth") == 0) |
| 3471 |
set_option_bool(OPT_AUTH_LOG); |
| 3472 |
else if (strcmp(arg, "only_failed") == 0) |
| 3473 |
set_option_bool(OPT_LOG_ONLY_FAILED); |
| 3474 |
} |
| 3475 |
break; |
| 3476 |
|
| 3477 |
case LOPT_MAX_LOGS: /* --log-async */ |
| 3478 |
daemon->max_logs = LOG_MAX; /* default */ |
| 3479 |
if (arg && !atoi_check(arg, &daemon->max_logs)) |
| 3480 |
ret_err(gen_err); |
| 3481 |
else if (daemon->max_logs > 100) |
| 3482 |
daemon->max_logs = 100; |
| 3483 |
break; |
| 3484 |
|
| 3485 |
case LOPT_LOCAL_SERVICE: /* --local-service */ |
| 3486 |
if (!arg || !strcmp(arg, "net")) |
| 3487 |
set_option_bool(OPT_LOCAL_SERVICE); |
| 3488 |
else if (!strcmp(arg, "host")) |
| 3489 |
set_option_bool(OPT_LOCALHOST_SERVICE); |
| 3490 |
else |
| 3491 |
ret_err(gen_err); |
| 3492 |
break; |
| 3493 |
|
| 3494 |
case 'P': /* --edns-packet-max */ |
| 3495 |
{ |
| 3496 |
int i; |
| 3497 |
if (!atoi_check(arg, &i)) |
| 3498 |
ret_err(gen_err); |
| 3499 |
daemon->edns_pktsz = (unsigned short)i; |
| 3500 |
break; |
| 3501 |
} |
| 3502 |
|
| 3503 |
case 'Q': /* --query-port */ |
| 3504 |
if (!atoi_check16(arg, &daemon->query_port)) |
| 3505 |
ret_err(gen_err); |
| 3506 |
/* if explicitly set to zero, use single OS ephemeral port |
| 3507 |
and disable random ports */ |
| 3508 |
if (daemon->query_port == 0) |
| 3509 |
daemon->osport = 1; |
| 3510 |
break; |
| 3511 |
|
| 3512 |
case LOPT_RANDPORT_LIM: /* --port-limit */ |
| 3513 |
if (!atoi_check(arg, &daemon->randport_limit) || (daemon->randport_limit < 1)) |
| 3514 |
ret_err(gen_err); |
| 3515 |
break; |
| 3516 |
|
| 3517 |
case 'T': /* --local-ttl */ |
| 3518 |
case LOPT_NEGTTL: /* --neg-ttl */ |
| 3519 |
case LOPT_MAXTTL: /* --max-ttl */ |
| 3520 |
case LOPT_MINCTTL: /* --min-cache-ttl */ |
| 3521 |
case LOPT_MAXCTTL: /* --max-cache-ttl */ |
| 3522 |
case LOPT_AUTHTTL: /* --auth-ttl */ |
| 3523 |
case LOPT_DHCPTTL: /* --dhcp-ttl */ |
| 3524 |
{ |
| 3525 |
int ttl; |
| 3526 |
if (!atoi_check(arg, &ttl)) |
| 3527 |
ret_err(gen_err); |
| 3528 |
else if (option == LOPT_NEGTTL) |
| 3529 |
daemon->neg_ttl = (unsigned long)ttl; |
| 3530 |
else if (option == LOPT_MAXTTL) |
| 3531 |
daemon->max_ttl = (unsigned long)ttl; |
| 3532 |
else if (option == LOPT_MINCTTL) |
| 3533 |
{ |
| 3534 |
if (ttl > TTL_FLOOR_LIMIT) |
| 3535 |
ttl = TTL_FLOOR_LIMIT; |
| 3536 |
daemon->min_cache_ttl = (unsigned long)ttl; |
| 3537 |
} |
| 3538 |
else if (option == LOPT_MAXCTTL) |
| 3539 |
daemon->max_cache_ttl = (unsigned long)ttl; |
| 3540 |
else if (option == LOPT_AUTHTTL) |
| 3541 |
daemon->auth_ttl = (unsigned long)ttl; |
| 3542 |
else if (option == LOPT_DHCPTTL) |
| 3543 |
{ |
| 3544 |
daemon->dhcp_ttl = (unsigned long)ttl; |
| 3545 |
daemon->use_dhcp_ttl = 1; |
| 3546 |
} |
| 3547 |
else |
| 3548 |
daemon->local_ttl = (unsigned long)ttl; |
| 3549 |
break; |
| 3550 |
} |
| 3551 |
|
| 3552 |
case LOPT_FAST_RETRY: /* --fast-dns-retry */ |
| 3553 |
daemon->fast_retry_timeout = TIMEOUT; |
| 3554 |
|
| 3555 |
if (!arg) |
| 3556 |
daemon->fast_retry_time = DEFAULT_FAST_RETRY; |
| 3557 |
else |
| 3558 |
{ |
| 3559 |
int retry; |
| 3560 |
|
| 3561 |
comma = split(arg); |
| 3562 |
if (!atoi_check(arg, &retry) || retry < 50) |
| 3563 |
ret_err(gen_err); |
| 3564 |
daemon->fast_retry_time = retry; |
| 3565 |
|
| 3566 |
if (comma) |
| 3567 |
{ |
| 3568 |
if (!atoi_check(comma, &retry)) |
| 3569 |
ret_err(gen_err); |
| 3570 |
daemon->fast_retry_timeout = retry/1000; |
| 3571 |
} |
| 3572 |
} |
| 3573 |
break; |
| 3574 |
|
| 3575 |
case LOPT_CACHE_RR: /* --cache-rr */ |
| 3576 |
case LOPT_FILTER_RR: /* --filter-rr */ |
| 3577 |
case LOPT_FILTER_A: /* --filter-A */ |
| 3578 |
case LOPT_FILTER_AAAA: /* --filter-AAAA */ |
| 3579 |
while (1) { |
| 3580 |
int type; |
| 3581 |
struct rrlist *new; |
| 3582 |
|
| 3583 |
comma = NULL; |
| 3584 |
|
| 3585 |
if (option == LOPT_FILTER_A) |
| 3586 |
type = T_A; |
| 3587 |
else if (option == LOPT_FILTER_AAAA) |
| 3588 |
type = T_AAAA; |
| 3589 |
else |
| 3590 |
{ |
| 3591 |
comma = split(arg); |
| 3592 |
if (!atoi_check(arg, &type) && (type = rrtype(arg)) == 0) |
| 3593 |
ret_err(_("bad RR type")); |
| 3594 |
} |
| 3595 |
|
| 3596 |
new = opt_malloc(sizeof(struct rrlist)); |
| 3597 |
new->rr = type; |
| 3598 |
|
| 3599 |
if (option == LOPT_CACHE_RR) |
| 3600 |
{ |
| 3601 |
new->next = daemon->cache_rr; |
| 3602 |
daemon->cache_rr = new; |
| 3603 |
} |
| 3604 |
else |
| 3605 |
{ |
| 3606 |
new->next = daemon->filter_rr; |
| 3607 |
daemon->filter_rr = new; |
| 3608 |
} |
| 3609 |
|
| 3610 |
if (!comma) break; |
| 3611 |
arg = comma; |
| 3612 |
} |
| 3613 |
break; |
| 3614 |
|
| 3615 |
|
| 3616 |
#ifdef HAVE_DHCP |
| 3617 |
case 'X': /* --dhcp-lease-max */ |
| 3618 |
if (!atoi_check(arg, &daemon->dhcp_max)) |
| 3619 |
ret_err(gen_err); |
| 3620 |
break; |
| 3621 |
#endif |
| 3622 |
|
| 3623 |
#ifdef HAVE_TFTP |
| 3624 |
case LOPT_TFTP_MAX: /* --tftp-max */ |
| 3625 |
if (!atoi_check(arg, &daemon->tftp_max)) |
| 3626 |
ret_err(gen_err); |
| 3627 |
break; |
| 3628 |
|
| 3629 |
case LOPT_TFTP_MTU: /* --tftp-mtu */ |
| 3630 |
if (!atoi_check(arg, &daemon->tftp_mtu)) |
| 3631 |
ret_err(gen_err); |
| 3632 |
break; |
| 3633 |
|
| 3634 |
case LOPT_PREFIX: /* --tftp-prefix */ |
| 3635 |
comma = split(arg); |
| 3636 |
if (comma) |
| 3637 |
{ |
| 3638 |
struct tftp_prefix *new = opt_malloc(sizeof(struct tftp_prefix)); |
| 3639 |
new->interface = opt_string_alloc(comma); |
| 3640 |
new->prefix = opt_string_alloc(arg); |
| 3641 |
new->next = daemon->if_prefix; |
| 3642 |
daemon->if_prefix = new; |
| 3643 |
} |
| 3644 |
else |
| 3645 |
daemon->tftp_prefix = opt_string_alloc(arg); |
| 3646 |
break; |
| 3647 |
|
| 3648 |
case LOPT_TFTPPORTS: /* --tftp-port-range */ |
| 3649 |
if (!(comma = split(arg)) || |
| 3650 |
!atoi_check16(arg, &daemon->start_tftp_port) || |
| 3651 |
!atoi_check16(comma, &daemon->end_tftp_port)) |
| 3652 |
ret_err(_("bad port range")); |
| 3653 |
|
| 3654 |
if (daemon->start_tftp_port > daemon->end_tftp_port) |
| 3655 |
{ |
| 3656 |
int tmp = daemon->start_tftp_port; |
| 3657 |
daemon->start_tftp_port = daemon->end_tftp_port; |
| 3658 |
daemon->end_tftp_port = tmp; |
| 3659 |
} |
| 3660 |
|
| 3661 |
break; |
| 3662 |
|
| 3663 |
case LOPT_APREF: /* --tftp-unique-root */ |
| 3664 |
if (!arg || strcasecmp(arg, "ip") == 0) |
| 3665 |
set_option_bool(OPT_TFTP_APREF_IP); |
| 3666 |
else if (strcasecmp(arg, "mac") == 0) |
| 3667 |
set_option_bool(OPT_TFTP_APREF_MAC); |
| 3668 |
else |
| 3669 |
ret_err(gen_err); |
| 3670 |
break; |
| 3671 |
#endif |
| 3672 |
|
| 3673 |
case LOPT_BRIDGE: /* --bridge-interface */ |
| 3674 |
{ |
| 3675 |
struct dhcp_bridge *new; |
| 3676 |
|
| 3677 |
if (!(comma = split(arg)) || strlen(arg) > IF_NAMESIZE - 1 ) |
| 3678 |
ret_err(_("bad bridge-interface")); |
| 3679 |
|
| 3680 |
for (new = daemon->bridges; new; new = new->next) |
| 3681 |
if (strcmp(new->iface, arg) == 0) |
| 3682 |
break; |
| 3683 |
|
| 3684 |
if (!new) |
| 3685 |
{ |
| 3686 |
new = opt_malloc(sizeof(struct dhcp_bridge)); |
| 3687 |
strcpy(new->iface, arg); |
| 3688 |
new->alias = NULL; |
| 3689 |
new->next = daemon->bridges; |
| 3690 |
daemon->bridges = new; |
| 3691 |
} |
| 3692 |
|
| 3693 |
do { |
| 3694 |
arg = comma; |
| 3695 |
comma = split(arg); |
| 3696 |
if (strlen(arg) != 0 && strlen(arg) <= IF_NAMESIZE - 1) |
| 3697 |
{ |
| 3698 |
struct dhcp_bridge *b = opt_malloc(sizeof(struct dhcp_bridge)); |
| 3699 |
b->next = new->alias; |
| 3700 |
new->alias = b; |
| 3701 |
strcpy(b->iface, arg); |
| 3702 |
} |
| 3703 |
} while (comma); |
| 3704 |
|
| 3705 |
break; |
| 3706 |
} |
| 3707 |
|
| 3708 |
#ifdef HAVE_DHCP |
| 3709 |
case LOPT_SHARED_NET: /* --shared-network */ |
| 3710 |
{ |
| 3711 |
struct shared_network *new = opt_malloc(sizeof(struct shared_network)); |
| 3712 |
|
| 3713 |
#ifdef HAVE_DHCP6 |
| 3714 |
new->shared_addr.s_addr = 0; |
| 3715 |
#endif |
| 3716 |
new->if_index = 0; |
| 3717 |
|
| 3718 |
if (!(comma = split(arg))) |
| 3719 |
{ |
| 3720 |
snerr: |
| 3721 |
free(new); |
| 3722 |
ret_err(_("bad shared-network")); |
| 3723 |
} |
| 3724 |
|
| 3725 |
if (inet_pton(AF_INET, comma, &new->shared_addr)) |
| 3726 |
{ |
| 3727 |
if (!inet_pton(AF_INET, arg, &new->match_addr) && |
| 3728 |
!(new->if_index = if_nametoindex(arg))) |
| 3729 |
goto snerr; |
| 3730 |
} |
| 3731 |
#ifdef HAVE_DHCP6 |
| 3732 |
else if (inet_pton(AF_INET6, comma, &new->shared_addr6)) |
| 3733 |
{ |
| 3734 |
if (!inet_pton(AF_INET6, arg, &new->match_addr6) && |
| 3735 |
!(new->if_index = if_nametoindex(arg))) |
| 3736 |
goto snerr; |
| 3737 |
} |
| 3738 |
#endif |
| 3739 |
else |
| 3740 |
goto snerr; |
| 3741 |
|
| 3742 |
new->next = daemon->shared_networks; |
| 3743 |
daemon->shared_networks = new; |
| 3744 |
break; |
| 3745 |
} |
| 3746 |
|
| 3747 |
case 'F': /* --dhcp-range */ |
| 3748 |
{ |
| 3749 |
int k, leasepos = 2; |
| 3750 |
char *cp, *a[8] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; |
| 3751 |
struct dhcp_context *new = opt_malloc(sizeof(struct dhcp_context)); |
| 3752 |
|
| 3753 |
memset (new, 0, sizeof(*new)); |
| 3754 |
|
| 3755 |
while(1) |
| 3756 |
{ |
| 3757 |
for (cp = arg; *cp; cp++) |
| 3758 |
if (!(*cp == ' ' || *cp == '.' || *cp == ':' || |
| 3759 |
(*cp >= 'a' && *cp <= 'f') || (*cp >= 'A' && *cp <= 'F') || |
| 3760 |
(*cp >='0' && *cp <= '9'))) |
| 3761 |
break; |
| 3762 |
|
| 3763 |
if (*cp != ',' && (comma = split(arg))) |
| 3764 |
{ |
| 3765 |
if (is_tag_prefix(arg)) |
| 3766 |
{ |
| 3767 |
/* ignore empty tag */ |
| 3768 |
if (arg[4]) |
| 3769 |
new->filter = dhcp_netid_create(arg+4, new->filter); |
| 3770 |
} |
| 3771 |
else |
| 3772 |
{ |
| 3773 |
if (new->netid.net) |
| 3774 |
{ |
| 3775 |
dhcp_context_free(new); |
| 3776 |
ret_err(_("only one tag allowed")); |
| 3777 |
} |
| 3778 |
else |
| 3779 |
new->netid.net = opt_string_alloc(set_prefix(arg)); |
| 3780 |
} |
| 3781 |
arg = comma; |
| 3782 |
} |
| 3783 |
else |
| 3784 |
{ |
| 3785 |
a[0] = arg; |
| 3786 |
break; |
| 3787 |
} |
| 3788 |
} |
| 3789 |
|
| 3790 |
for (k = 1; k < 8; k++) |
| 3791 |
if (!(a[k] = split(a[k-1]))) |
| 3792 |
break; |
| 3793 |
|
| 3794 |
if (k < 2) |
| 3795 |
{ |
| 3796 |
dhcp_context_free(new); |
| 3797 |
ret_err(_("bad dhcp-range")); |
| 3798 |
} |
| 3799 |
|
| 3800 |
if (inet_pton(AF_INET, a[0], &new->start)) |
| 3801 |
{ |
| 3802 |
new->next = daemon->dhcp; |
| 3803 |
new->lease_time = DEFLEASE; |
| 3804 |
daemon->dhcp = new; |
| 3805 |
new->end = new->start; |
| 3806 |
if (strcmp(a[1], "static") == 0) |
| 3807 |
new->flags |= CONTEXT_STATIC; |
| 3808 |
else if (strcmp(a[1], "proxy") == 0) |
| 3809 |
new->flags |= CONTEXT_PROXY; |
| 3810 |
else if (!inet_pton(AF_INET, a[1], &new->end)) |
| 3811 |
{ |
| 3812 |
dhcp_context_free(new); |
| 3813 |
ret_err(_("bad dhcp-range")); |
| 3814 |
} |
| 3815 |
|
| 3816 |
if (ntohl(new->start.s_addr) > ntohl(new->end.s_addr)) |
| 3817 |
{ |
| 3818 |
struct in_addr tmp = new->start; |
| 3819 |
new->start = new->end; |
| 3820 |
new->end = tmp; |
| 3821 |
} |
| 3822 |
|
| 3823 |
if (k >= 3 && strchr(a[2], '.') && |
| 3824 |
(inet_pton(AF_INET, a[2], &new->netmask) > 0)) |
| 3825 |
{ |
| 3826 |
new->flags |= CONTEXT_NETMASK; |
| 3827 |
leasepos = 3; |
| 3828 |
if (!is_same_net(new->start, new->end, new->netmask)) |
| 3829 |
{ |
| 3830 |
dhcp_context_free(new); |
| 3831 |
ret_err(_("inconsistent DHCP range")); |
| 3832 |
} |
| 3833 |
|
| 3834 |
|
| 3835 |
if (k >= 4 && strchr(a[3], '.') && |
| 3836 |
(inet_pton(AF_INET, a[3], &new->broadcast) > 0)) |
| 3837 |
{ |
| 3838 |
new->flags |= CONTEXT_BRDCAST; |
| 3839 |
leasepos = 4; |
| 3840 |
} |
| 3841 |
} |
| 3842 |
} |
| 3843 |
#ifdef HAVE_DHCP6 |
| 3844 |
else if (inet_pton(AF_INET6, a[0], &new->start6)) |
| 3845 |
{ |
| 3846 |
const char *err = NULL; |
| 3847 |
|
| 3848 |
new->flags |= CONTEXT_V6; |
| 3849 |
new->prefix = 64; /* default */ |
| 3850 |
new->end6 = new->start6; |
| 3851 |
new->lease_time = DEFLEASE6; |
| 3852 |
new->next = daemon->dhcp6; |
| 3853 |
daemon->dhcp6 = new; |
| 3854 |
|
| 3855 |
for (leasepos = 1; leasepos < k; leasepos++) |
| 3856 |
{ |
| 3857 |
if (strcmp(a[leasepos], "static") == 0) |
| 3858 |
new->flags |= CONTEXT_STATIC | CONTEXT_DHCP; |
| 3859 |
else if (strcmp(a[leasepos], "ra-only") == 0 || strcmp(a[leasepos], "slaac") == 0 ) |
| 3860 |
new->flags |= CONTEXT_RA; |
| 3861 |
else if (strcmp(a[leasepos], "ra-names") == 0) |
| 3862 |
new->flags |= CONTEXT_RA_NAME | CONTEXT_RA; |
| 3863 |
else if (strcmp(a[leasepos], "ra-advrouter") == 0) |
| 3864 |
new->flags |= CONTEXT_RA_ROUTER | CONTEXT_RA; |
| 3865 |
else if (strcmp(a[leasepos], "ra-stateless") == 0) |
| 3866 |
new->flags |= CONTEXT_RA_STATELESS | CONTEXT_DHCP | CONTEXT_RA; |
| 3867 |
else if (strcmp(a[leasepos], "off-link") == 0) |
| 3868 |
new->flags |= CONTEXT_RA_OFF_LINK; |
| 3869 |
else if (leasepos == 1 && inet_pton(AF_INET6, a[leasepos], &new->end6)) |
| 3870 |
new->flags |= CONTEXT_DHCP; |
| 3871 |
else if (strstr(a[leasepos], "constructor:") == a[leasepos]) |
| 3872 |
{ |
| 3873 |
new->template_interface = opt_string_alloc(a[leasepos] + 12); |
| 3874 |
new->flags |= CONTEXT_TEMPLATE; |
| 3875 |
} |
| 3876 |
else |
| 3877 |
break; |
| 3878 |
} |
| 3879 |
|
| 3880 |
/* bare integer < 128 is prefix value */ |
| 3881 |
if (leasepos < k) |
| 3882 |
{ |
| 3883 |
int pref; |
| 3884 |
for (cp = a[leasepos]; *cp; cp++) |
| 3885 |
if (!(*cp >= '0' && *cp <= '9')) |
| 3886 |
break; |
| 3887 |
if (!*cp && (pref = atoi(a[leasepos])) <= 128) |
| 3888 |
{ |
| 3889 |
new->prefix = pref; |
| 3890 |
leasepos++; |
| 3891 |
} |
| 3892 |
} |
| 3893 |
|
| 3894 |
if (new->prefix > 64) |
| 3895 |
{ |
| 3896 |
if (new->flags & CONTEXT_RA) |
| 3897 |
err=(_("prefix length must be exactly 64 for RA subnets")); |
| 3898 |
else if (new->flags & CONTEXT_TEMPLATE) |
| 3899 |
err=(_("prefix length must be exactly 64 for subnet constructors")); |
| 3900 |
} |
| 3901 |
else if (new->prefix < 64) |
| 3902 |
err=(_("prefix length must be at least 64")); |
| 3903 |
|
| 3904 |
if (!err && !is_same_net6(&new->start6, &new->end6, new->prefix)) |
| 3905 |
err=(_("inconsistent DHCPv6 range")); |
| 3906 |
|
| 3907 |
if (err) |
| 3908 |
{ |
| 3909 |
dhcp_context_free(new); |
| 3910 |
ret_err(err); |
| 3911 |
} |
| 3912 |
|
| 3913 |
/* dhcp-range=:: enables DHCP stateless on any interface */ |
| 3914 |
if (IN6_IS_ADDR_UNSPECIFIED(&new->start6) && !(new->flags & CONTEXT_TEMPLATE)) |
| 3915 |
new->prefix = 0; |
| 3916 |
|
| 3917 |
if (new->flags & CONTEXT_TEMPLATE) |
| 3918 |
{ |
| 3919 |
struct in6_addr zero; |
| 3920 |
memset(&zero, 0, sizeof(zero)); |
| 3921 |
if (!is_same_net6(&zero, &new->start6, new->prefix)) |
| 3922 |
{ |
| 3923 |
dhcp_context_free(new); |
| 3924 |
ret_err(_("prefix must be zero with \"constructor:\" argument")); |
| 3925 |
} |
| 3926 |
} |
| 3927 |
|
| 3928 |
if (addr6part(&new->start6) > addr6part(&new->end6)) |
| 3929 |
{ |
| 3930 |
struct in6_addr tmp = new->start6; |
| 3931 |
new->start6 = new->end6; |
| 3932 |
new->end6 = tmp; |
| 3933 |
} |
| 3934 |
} |
| 3935 |
#endif |
| 3936 |
else |
| 3937 |
{ |
| 3938 |
dhcp_context_free(new); |
| 3939 |
ret_err(_("bad dhcp-range")); |
| 3940 |
} |
| 3941 |
|
| 3942 |
if (leasepos < k) |
| 3943 |
{ |
| 3944 |
if (leasepos != k-1) |
| 3945 |
{ |
| 3946 |
dhcp_context_free(new); |
| 3947 |
ret_err(_("bad dhcp-range")); |
| 3948 |
} |
| 3949 |
|
| 3950 |
if (strcmp(a[leasepos], "infinite") == 0) |
| 3951 |
{ |
| 3952 |
new->lease_time = 0xffffffff; |
| 3953 |
new->flags |= CONTEXT_SETLEASE; |
| 3954 |
} |
| 3955 |
else if (strcmp(a[leasepos], "deprecated") == 0) |
| 3956 |
new->flags |= CONTEXT_DEPRECATE; |
| 3957 |
else |
| 3958 |
{ |
| 3959 |
int fac = 1; |
| 3960 |
if (strlen(a[leasepos]) > 0) |
| 3961 |
{ |
| 3962 |
switch (a[leasepos][strlen(a[leasepos]) - 1]) |
| 3963 |
{ |
| 3964 |
case 'w': |
| 3965 |
case 'W': |
| 3966 |
fac *= 7; |
| 3967 |
/* fall through */ |
| 3968 |
case 'd': |
| 3969 |
case 'D': |
| 3970 |
fac *= 24; |
| 3971 |
/* fall through */ |
| 3972 |
case 'h': |
| 3973 |
case 'H': |
| 3974 |
fac *= 60; |
| 3975 |
/* fall through */ |
| 3976 |
case 'm': |
| 3977 |
case 'M': |
| 3978 |
fac *= 60; |
| 3979 |
/* fall through */ |
| 3980 |
case 's': |
| 3981 |
case 'S': |
| 3982 |
a[leasepos][strlen(a[leasepos]) - 1] = 0; |
| 3983 |
} |
| 3984 |
|
| 3985 |
for (cp = a[leasepos]; *cp; cp++) |
| 3986 |
if (!(*cp >= '0' && *cp <= '9')) |
| 3987 |
break; |
| 3988 |
|
| 3989 |
if (*cp || (leasepos+1 < k)) |
| 3990 |
ret_err_free(_("bad dhcp-range"), new); |
| 3991 |
|
| 3992 |
new->lease_time = atoi(a[leasepos]) * fac; |
| 3993 |
new->flags |= CONTEXT_SETLEASE; |
| 3994 |
/* Leases of a minute or less confuse |
| 3995 |
some clients, notably Apple's */ |
| 3996 |
if (new->lease_time < 120) |
| 3997 |
new->lease_time = 120; |
| 3998 |
} |
| 3999 |
} |
| 4000 |
} |
| 4001 |
|
| 4002 |
break; |
| 4003 |
} |
| 4004 |
|
| 4005 |
case LOPT_BANK: |
| 4006 |
case 'G': /* --dhcp-host */ |
| 4007 |
{ |
| 4008 |
struct dhcp_config *new; |
| 4009 |
struct in_addr in; |
| 4010 |
|
| 4011 |
new = opt_malloc(sizeof(struct dhcp_config)); |
| 4012 |
|
| 4013 |
new->next = daemon->dhcp_conf; |
| 4014 |
new->flags = (option == LOPT_BANK) ? CONFIG_BANK : 0; |
| 4015 |
new->hwaddr = NULL; |
| 4016 |
new->netid = NULL; |
| 4017 |
new->filter = NULL; |
| 4018 |
new->clid = NULL; |
| 4019 |
#ifdef HAVE_DHCP6 |
| 4020 |
new->addr6 = NULL; |
| 4021 |
#endif |
| 4022 |
|
| 4023 |
while (arg) |
| 4024 |
{ |
| 4025 |
comma = split(arg); |
| 4026 |
if (strchr(arg, ':')) /* Ethernet address, netid or binary CLID */ |
| 4027 |
{ |
| 4028 |
if ((arg[0] == 'i' || arg[0] == 'I') && |
| 4029 |
(arg[1] == 'd' || arg[1] == 'D') && |
| 4030 |
arg[2] == ':') |
| 4031 |
{ |
| 4032 |
if (arg[3] == '*') |
| 4033 |
new->flags |= CONFIG_NOCLID; |
| 4034 |
else |
| 4035 |
{ |
| 4036 |
int len; |
| 4037 |
arg += 3; /* dump id: */ |
| 4038 |
if (strchr(arg, ':')) |
| 4039 |
len = parse_hex(arg, (unsigned char *)arg, -1, NULL, NULL); |
| 4040 |
else |
| 4041 |
{ |
| 4042 |
unhide_metas(arg); |
| 4043 |
len = (int) strlen(arg); |
| 4044 |
} |
| 4045 |
|
| 4046 |
if (len == -1) |
| 4047 |
{ |
| 4048 |
dhcp_config_free(new); |
| 4049 |
ret_err(_("bad hex constant")); |
| 4050 |
} |
| 4051 |
else if ((new->clid = opt_malloc(len))) |
| 4052 |
{ |
| 4053 |
new->flags |= CONFIG_CLID; |
| 4054 |
new->clid_len = len; |
| 4055 |
memcpy(new->clid, arg, len); |
| 4056 |
} |
| 4057 |
} |
| 4058 |
} |
| 4059 |
/* dhcp-host has strange backwards-compat needs. */ |
| 4060 |
else if (strstr(arg, "net:") == arg || strstr(arg, "set:") == arg) |
| 4061 |
{ |
| 4062 |
struct dhcp_netid_list *newlist = opt_malloc(sizeof(struct dhcp_netid_list)); |
| 4063 |
newlist->next = new->netid; |
| 4064 |
new->netid = newlist; |
| 4065 |
newlist->list = dhcp_netid_create(arg+4, NULL); |
| 4066 |
} |
| 4067 |
else if (strstr(arg, "tag:") == arg) |
| 4068 |
new->filter = dhcp_netid_create(arg+4, new->filter); |
| 4069 |
|
| 4070 |
#ifdef HAVE_DHCP6 |
| 4071 |
else if (arg[0] == '[' && arg[strlen(arg)-1] == ']') |
| 4072 |
{ |
| 4073 |
char *pref; |
| 4074 |
struct in6_addr in6; |
| 4075 |
struct addrlist *new_addr; |
| 4076 |
|
| 4077 |
arg[strlen(arg)-1] = 0; |
| 4078 |
arg++; |
| 4079 |
pref = split_chr(arg, '/'); |
| 4080 |
|
| 4081 |
if (!inet_pton(AF_INET6, arg, &in6)) |
| 4082 |
{ |
| 4083 |
dhcp_config_free(new); |
| 4084 |
ret_err(_("bad IPv6 address")); |
| 4085 |
} |
| 4086 |
|
| 4087 |
new_addr = opt_malloc(sizeof(struct addrlist)); |
| 4088 |
new_addr->flags = 0; |
| 4089 |
new_addr->addr.addr6 = in6; |
| 4090 |
|
| 4091 |
if (pref) |
| 4092 |
{ |
| 4093 |
u64 addrpart = addr6part(&in6); |
| 4094 |
|
| 4095 |
if (!atoi_check(pref, &new_addr->prefixlen) || |
| 4096 |
new_addr->prefixlen > 128 || |
| 4097 |
((((u64)1<<(128-new_addr->prefixlen))-1) & addrpart) != 0) |
| 4098 |
{ |
| 4099 |
dhcp_config_free(new); |
| 4100 |
ret_err_free(_("bad IPv6 prefix"), new_addr); |
| 4101 |
} |
| 4102 |
|
| 4103 |
new_addr->flags |= ADDRLIST_PREFIX; |
| 4104 |
} |
| 4105 |
|
| 4106 |
for (i= 0; i < 8; i++) |
| 4107 |
if (in6.s6_addr[i] != 0) |
| 4108 |
break; |
| 4109 |
|
| 4110 |
/* set WILDCARD if network part all zeros */ |
| 4111 |
if (i == 8) |
| 4112 |
new_addr->flags |= ADDRLIST_WILDCARD; |
| 4113 |
|
| 4114 |
new_addr->next = new->addr6; |
| 4115 |
new->addr6 = new_addr; |
| 4116 |
new->flags |= CONFIG_ADDR6; |
| 4117 |
} |
| 4118 |
#endif |
| 4119 |
else |
| 4120 |
{ |
| 4121 |
struct hwaddr_config *newhw = opt_malloc(sizeof(struct hwaddr_config)); |
| 4122 |
if ((newhw->hwaddr_len = parse_hex(arg, newhw->hwaddr, DHCP_CHADDR_MAX, |
| 4123 |
&newhw->wildcard_mask, &newhw->hwaddr_type)) == -1) |
| 4124 |
{ |
| 4125 |
free(newhw); |
| 4126 |
dhcp_config_free(new); |
| 4127 |
ret_err(_("bad hex constant")); |
| 4128 |
} |
| 4129 |
else |
| 4130 |
{ |
| 4131 |
newhw->next = new->hwaddr; |
| 4132 |
new->hwaddr = newhw; |
| 4133 |
} |
| 4134 |
} |
| 4135 |
} |
| 4136 |
else if (strchr(arg, '.') && (inet_pton(AF_INET, arg, &in) > 0)) |
| 4137 |
{ |
| 4138 |
struct dhcp_config *configs; |
| 4139 |
|
| 4140 |
new->addr = in; |
| 4141 |
new->flags |= CONFIG_ADDR; |
| 4142 |
|
| 4143 |
/* If the same IP appears in more than one host config, then DISCOVER |
| 4144 |
for one of the hosts will get the address, but REQUEST will be NAKed, |
| 4145 |
since the address is reserved by the other one -> protocol loop. */ |
| 4146 |
for (configs = daemon->dhcp_conf; configs; configs = configs->next) |
| 4147 |
if ((configs->flags & CONFIG_ADDR) && configs->addr.s_addr == in.s_addr) |
| 4148 |
{ |
| 4149 |
inet_ntop(AF_INET, &in, daemon->addrbuff, ADDRSTRLEN); |
| 4150 |
sprintf(errstr, _("duplicate dhcp-host IP address %s"), |
| 4151 |
daemon->addrbuff); |
| 4152 |
dhcp_config_free(new); |
| 4153 |
return 0; |
| 4154 |
} |
| 4155 |
} |
| 4156 |
else |
| 4157 |
{ |
| 4158 |
char *cp, *lastp = NULL, last = 0; |
| 4159 |
int fac = 1, isdig = 0; |
| 4160 |
|
| 4161 |
if (strlen(arg) > 1) |
| 4162 |
{ |
| 4163 |
lastp = arg + strlen(arg) - 1; |
| 4164 |
last = *lastp; |
| 4165 |
switch (last) |
| 4166 |
{ |
| 4167 |
case 'w': |
| 4168 |
case 'W': |
| 4169 |
fac *= 7; |
| 4170 |
/* fall through */ |
| 4171 |
case 'd': |
| 4172 |
case 'D': |
| 4173 |
fac *= 24; |
| 4174 |
/* fall through */ |
| 4175 |
case 'h': |
| 4176 |
case 'H': |
| 4177 |
fac *= 60; |
| 4178 |
/* fall through */ |
| 4179 |
case 'm': |
| 4180 |
case 'M': |
| 4181 |
fac *= 60; |
| 4182 |
/* fall through */ |
| 4183 |
case 's': |
| 4184 |
case 'S': |
| 4185 |
*lastp = 0; |
| 4186 |
} |
| 4187 |
} |
| 4188 |
|
| 4189 |
for (cp = arg; *cp; cp++) |
| 4190 |
if (isdigit((unsigned char)*cp)) |
| 4191 |
isdig = 1; |
| 4192 |
else if (*cp != ' ') |
| 4193 |
break; |
| 4194 |
|
| 4195 |
if (*cp) |
| 4196 |
{ |
| 4197 |
if (lastp) |
| 4198 |
*lastp = last; |
| 4199 |
if (strcmp(arg, "infinite") == 0) |
| 4200 |
{ |
| 4201 |
new->lease_time = 0xffffffff; |
| 4202 |
new->flags |= CONFIG_TIME; |
| 4203 |
} |
| 4204 |
else if (strcmp(arg, "ignore") == 0) |
| 4205 |
new->flags |= CONFIG_DISABLE; |
| 4206 |
else if (new->hostname) |
| 4207 |
{ |
| 4208 |
dhcp_config_free(new); |
| 4209 |
ret_err(_("DHCP host has multiple names")); |
| 4210 |
} |
| 4211 |
else |
| 4212 |
{ |
| 4213 |
if (!(new->hostname = canonicalise_opt(arg)) || |
| 4214 |
!legal_hostname(new->hostname)) |
| 4215 |
{ |
| 4216 |
dhcp_config_free(new); |
| 4217 |
ret_err(_("bad DHCP host name")); |
| 4218 |
} |
| 4219 |
|
| 4220 |
new->flags |= CONFIG_NAME; |
| 4221 |
new->domain = strip_hostname(new->hostname); |
| 4222 |
} |
| 4223 |
} |
| 4224 |
else if (isdig) |
| 4225 |
{ |
| 4226 |
new->lease_time = atoi(arg) * fac; |
| 4227 |
/* Leases of a minute or less confuse |
| 4228 |
some clients, notably Apple's */ |
| 4229 |
if (new->lease_time < 120) |
| 4230 |
new->lease_time = 120; |
| 4231 |
new->flags |= CONFIG_TIME; |
| 4232 |
} |
| 4233 |
} |
| 4234 |
|
| 4235 |
arg = comma; |
| 4236 |
} |
| 4237 |
|
| 4238 |
daemon->dhcp_conf = new; |
| 4239 |
break; |
| 4240 |
} |
| 4241 |
|
| 4242 |
case LOPT_TAG_IF: /* --tag-if */ |
| 4243 |
{ |
| 4244 |
struct tag_if *new = opt_malloc(sizeof(struct tag_if)); |
| 4245 |
|
| 4246 |
new->tag = NULL; |
| 4247 |
new->set = NULL; |
| 4248 |
new->next = NULL; |
| 4249 |
|
| 4250 |
/* preserve order */ |
| 4251 |
if (!daemon->tag_if) |
| 4252 |
daemon->tag_if = new; |
| 4253 |
else |
| 4254 |
{ |
| 4255 |
struct tag_if *tmp; |
| 4256 |
for (tmp = daemon->tag_if; tmp->next; tmp = tmp->next); |
| 4257 |
tmp->next = new; |
| 4258 |
} |
| 4259 |
|
| 4260 |
while (arg) |
| 4261 |
{ |
| 4262 |
size_t len; |
| 4263 |
|
| 4264 |
comma = split(arg); |
| 4265 |
len = strlen(arg); |
| 4266 |
|
| 4267 |
if (len < 5) |
| 4268 |
{ |
| 4269 |
new->set = NULL; |
| 4270 |
break; |
| 4271 |
} |
| 4272 |
else |
| 4273 |
{ |
| 4274 |
struct dhcp_netid *newtag = dhcp_netid_create(arg+4, NULL); |
| 4275 |
|
| 4276 |
if (strstr(arg, "set:") == arg) |
| 4277 |
{ |
| 4278 |
struct dhcp_netid_list *newlist = opt_malloc(sizeof(struct dhcp_netid_list)); |
| 4279 |
newlist->next = new->set; |
| 4280 |
new->set = newlist; |
| 4281 |
newlist->list = newtag; |
| 4282 |
} |
| 4283 |
else if (strstr(arg, "tag:") == arg) |
| 4284 |
{ |
| 4285 |
newtag->next = new->tag; |
| 4286 |
new->tag = newtag; |
| 4287 |
} |
| 4288 |
else |
| 4289 |
{ |
| 4290 |
new->set = NULL; |
| 4291 |
dhcp_netid_free(newtag); |
| 4292 |
break; |
| 4293 |
} |
| 4294 |
} |
| 4295 |
|
| 4296 |
arg = comma; |
| 4297 |
} |
| 4298 |
|
| 4299 |
if (!new->set) |
| 4300 |
{ |
| 4301 |
dhcp_netid_free(new->tag); |
| 4302 |
dhcp_netid_list_free(new->set); |
| 4303 |
ret_err_free(_("bad tag-if"), new); |
| 4304 |
} |
| 4305 |
|
| 4306 |
break; |
| 4307 |
} |
| 4308 |
|
| 4309 |
|
| 4310 |
case 'O': /* --dhcp-option */ |
| 4311 |
case LOPT_FORCE: /* --dhcp-option-force */ |
| 4312 |
case LOPT_PXE_OPT: /* --dhcp-option-pxe */ |
| 4313 |
case LOPT_OPTS: |
| 4314 |
case LOPT_MATCH: /* --dhcp-match */ |
| 4315 |
return parse_dhcp_opt(errstr, arg, |
| 4316 |
option == LOPT_FORCE ? DHOPT_FORCE : |
| 4317 |
(option == LOPT_MATCH ? DHOPT_MATCH : |
| 4318 |
(option == LOPT_OPTS ? DHOPT_BANK : |
| 4319 |
(option == LOPT_PXE_OPT ? DHOPT_PXE_OPT : 0)))); |
| 4320 |
|
| 4321 |
case LOPT_NAME_MATCH: /* --dhcp-name-match */ |
| 4322 |
{ |
| 4323 |
struct dhcp_match_name *new; |
| 4324 |
ssize_t len; |
| 4325 |
|
| 4326 |
if (!(comma = split(arg)) || (len = strlen(comma)) == 0) |
| 4327 |
ret_err(gen_err); |
| 4328 |
|
| 4329 |
new = opt_malloc(sizeof(struct dhcp_match_name)); |
| 4330 |
new->wildcard = 0; |
| 4331 |
new->netid = opt_malloc(sizeof(struct dhcp_netid)); |
| 4332 |
new->netid->net = opt_string_alloc(set_prefix(arg)); |
| 4333 |
|
| 4334 |
if (comma[len-1] == '*') |
| 4335 |
{ |
| 4336 |
comma[len-1] = 0; |
| 4337 |
new->wildcard = 1; |
| 4338 |
} |
| 4339 |
new->name = opt_string_alloc(comma); |
| 4340 |
|
| 4341 |
new->next = daemon->dhcp_name_match; |
| 4342 |
daemon->dhcp_name_match = new; |
| 4343 |
|
| 4344 |
break; |
| 4345 |
} |
| 4346 |
|
| 4347 |
case 'M': /* --dhcp-boot */ |
| 4348 |
{ |
| 4349 |
struct dhcp_netid *id = dhcp_tags(&arg); |
| 4350 |
|
| 4351 |
if (!arg) |
| 4352 |
{ |
| 4353 |
ret_err(gen_err); |
| 4354 |
} |
| 4355 |
else |
| 4356 |
{ |
| 4357 |
char *dhcp_file, *dhcp_sname = NULL, *tftp_sname = NULL; |
| 4358 |
struct in_addr dhcp_next_server; |
| 4359 |
struct dhcp_boot *new; |
| 4360 |
comma = split(arg); |
| 4361 |
dhcp_file = opt_string_alloc(arg); |
| 4362 |
dhcp_next_server.s_addr = 0; |
| 4363 |
if (comma) |
| 4364 |
{ |
| 4365 |
arg = comma; |
| 4366 |
comma = split(arg); |
| 4367 |
dhcp_sname = opt_string_alloc(arg); |
| 4368 |
if (comma) |
| 4369 |
{ |
| 4370 |
unhide_metas(comma); |
| 4371 |
if (!(inet_pton(AF_INET, comma, &dhcp_next_server) > 0)) |
| 4372 |
{ |
| 4373 |
/* |
| 4374 |
* The user may have specified the tftp hostname here. |
| 4375 |
* save it so that it can be resolved/looked up during |
| 4376 |
* actual dhcp_reply(). |
| 4377 |
*/ |
| 4378 |
|
| 4379 |
tftp_sname = opt_string_alloc(comma); |
| 4380 |
dhcp_next_server.s_addr = 0; |
| 4381 |
} |
| 4382 |
} |
| 4383 |
} |
| 4384 |
|
| 4385 |
new = opt_malloc(sizeof(struct dhcp_boot)); |
| 4386 |
new->file = dhcp_file; |
| 4387 |
new->sname = dhcp_sname; |
| 4388 |
new->tftp_sname = tftp_sname; |
| 4389 |
new->next_server = dhcp_next_server; |
| 4390 |
new->netid = id; |
| 4391 |
new->next = daemon->boot_config; |
| 4392 |
daemon->boot_config = new; |
| 4393 |
} |
| 4394 |
|
| 4395 |
break; |
| 4396 |
} |
| 4397 |
|
| 4398 |
case LOPT_REPLY_DELAY: /* --dhcp-reply-delay */ |
| 4399 |
{ |
| 4400 |
struct dhcp_netid *id = dhcp_tags(&arg); |
| 4401 |
|
| 4402 |
if (!arg) |
| 4403 |
{ |
| 4404 |
ret_err(gen_err); |
| 4405 |
} |
| 4406 |
else |
| 4407 |
{ |
| 4408 |
struct delay_config *new; |
| 4409 |
int delay; |
| 4410 |
if (!atoi_check(arg, &delay)) |
| 4411 |
ret_err(gen_err); |
| 4412 |
|
| 4413 |
new = opt_malloc(sizeof(struct delay_config)); |
| 4414 |
new->delay = delay; |
| 4415 |
new->netid = id; |
| 4416 |
new->next = daemon->delay_conf; |
| 4417 |
daemon->delay_conf = new; |
| 4418 |
} |
| 4419 |
|
| 4420 |
break; |
| 4421 |
} |
| 4422 |
|
| 4423 |
case LOPT_PXE_PROMT: /* --pxe-prompt */ |
| 4424 |
{ |
| 4425 |
struct dhcp_opt *new = opt_malloc(sizeof(struct dhcp_opt)); |
| 4426 |
int timeout; |
| 4427 |
|
| 4428 |
new->netid = NULL; |
| 4429 |
new->opt = 10; /* PXE_MENU_PROMPT */ |
| 4430 |
new->netid = dhcp_tags(&arg); |
| 4431 |
|
| 4432 |
if (!arg) |
| 4433 |
{ |
| 4434 |
dhcp_opt_free(new); |
| 4435 |
ret_err(gen_err); |
| 4436 |
} |
| 4437 |
else |
| 4438 |
{ |
| 4439 |
comma = split(arg); |
| 4440 |
unhide_metas(arg); |
| 4441 |
new->len = strlen(arg) + 1; |
| 4442 |
new->val = opt_malloc(new->len); |
| 4443 |
memcpy(new->val + 1, arg, new->len - 1); |
| 4444 |
|
| 4445 |
new->u.vendor_class = NULL; |
| 4446 |
new->flags = DHOPT_VENDOR | DHOPT_VENDOR_PXE; |
| 4447 |
|
| 4448 |
if (comma && atoi_check(comma, &timeout)) |
| 4449 |
*(new->val) = timeout; |
| 4450 |
else |
| 4451 |
*(new->val) = 255; |
| 4452 |
|
| 4453 |
new->next = daemon->dhcp_opts; |
| 4454 |
daemon->dhcp_opts = new; |
| 4455 |
daemon->enable_pxe = 1; |
| 4456 |
} |
| 4457 |
|
| 4458 |
break; |
| 4459 |
} |
| 4460 |
|
| 4461 |
case LOPT_PXE_SERV: /* --pxe-service */ |
| 4462 |
{ |
| 4463 |
struct pxe_service *new = opt_malloc(sizeof(struct pxe_service)); |
| 4464 |
char *CSA[] = { "x86PC", "PC98", "IA64_EFI", "Alpha", "Arc_x86", "Intel_Lean_Client", |
| 4465 |
"IA32_EFI", "x86-64_EFI", "Xscale_EFI", "BC_EFI", |
| 4466 |
"ARM32_EFI", "ARM64_EFI", NULL }; |
| 4467 |
static int boottype = 32768; |
| 4468 |
|
| 4469 |
new->netid = NULL; |
| 4470 |
new->sname = NULL; |
| 4471 |
new->server.s_addr = 0; |
| 4472 |
new->netid = dhcp_tags(&arg); |
| 4473 |
|
| 4474 |
if (arg && (comma = split(arg))) |
| 4475 |
{ |
| 4476 |
for (i = 0; CSA[i]; i++) |
| 4477 |
if (strcasecmp(CSA[i], arg) == 0) |
| 4478 |
break; |
| 4479 |
|
| 4480 |
if (CSA[i] || atoi_check(arg, &i)) |
| 4481 |
{ |
| 4482 |
arg = comma; |
| 4483 |
comma = split(arg); |
| 4484 |
|
| 4485 |
new->CSA = i; |
| 4486 |
new->menu = opt_string_alloc(arg); |
| 4487 |
|
| 4488 |
if (!comma) |
| 4489 |
{ |
| 4490 |
new->type = 0; /* local boot */ |
| 4491 |
new->basename = NULL; |
| 4492 |
} |
| 4493 |
else |
| 4494 |
{ |
| 4495 |
arg = comma; |
| 4496 |
comma = split(arg); |
| 4497 |
if (atoi_check(arg, &i)) |
| 4498 |
{ |
| 4499 |
new->type = i; |
| 4500 |
new->basename = NULL; |
| 4501 |
} |
| 4502 |
else |
| 4503 |
{ |
| 4504 |
new->type = boottype++; |
| 4505 |
new->basename = opt_string_alloc(arg); |
| 4506 |
} |
| 4507 |
|
| 4508 |
if (comma) |
| 4509 |
{ |
| 4510 |
if (!inet_pton(AF_INET, comma, &new->server)) |
| 4511 |
{ |
| 4512 |
new->server.s_addr = 0; |
| 4513 |
new->sname = opt_string_alloc(comma); |
| 4514 |
} |
| 4515 |
|
| 4516 |
} |
| 4517 |
} |
| 4518 |
|
| 4519 |
/* Order matters */ |
| 4520 |
new->next = NULL; |
| 4521 |
if (!daemon->pxe_services) |
| 4522 |
daemon->pxe_services = new; |
| 4523 |
else |
| 4524 |
{ |
| 4525 |
struct pxe_service *s; |
| 4526 |
for (s = daemon->pxe_services; s->next; s = s->next); |
| 4527 |
s->next = new; |
| 4528 |
} |
| 4529 |
|
| 4530 |
daemon->enable_pxe = 1; |
| 4531 |
break; |
| 4532 |
|
| 4533 |
} |
| 4534 |
} |
| 4535 |
|
| 4536 |
dhcp_netid_free(new->netid); |
| 4537 |
free(new); |
| 4538 |
ret_err(gen_err); |
| 4539 |
} |
| 4540 |
|
| 4541 |
case '4': /* --dhcp-mac */ |
| 4542 |
{ |
| 4543 |
if (!(comma = split(arg))) |
| 4544 |
ret_err(gen_err); |
| 4545 |
else |
| 4546 |
{ |
| 4547 |
struct dhcp_mac *new = opt_malloc(sizeof(struct dhcp_mac)); |
| 4548 |
new->netid.net = opt_string_alloc(set_prefix(arg)); |
| 4549 |
unhide_metas(comma); |
| 4550 |
new->hwaddr_len = parse_hex(comma, new->hwaddr, DHCP_CHADDR_MAX, &new->mask, &new->hwaddr_type); |
| 4551 |
if (new->hwaddr_len == -1) |
| 4552 |
{ |
| 4553 |
free(new->netid.net); |
| 4554 |
ret_err_free(gen_err, new); |
| 4555 |
} |
| 4556 |
else |
| 4557 |
{ |
| 4558 |
new->next = daemon->dhcp_macs; |
| 4559 |
daemon->dhcp_macs = new; |
| 4560 |
} |
| 4561 |
} |
| 4562 |
} |
| 4563 |
break; |
| 4564 |
|
| 4565 |
case 'U': /* --dhcp-vendorclass */ |
| 4566 |
case 'j': /* --dhcp-userclass */ |
| 4567 |
case LOPT_CIRCUIT: /* --dhcp-circuitid */ |
| 4568 |
case LOPT_REMOTE: /* --dhcp-remoteid */ |
| 4569 |
case LOPT_SUBSCR: /* --dhcp-subscrid */ |
| 4570 |
{ |
| 4571 |
unsigned char *p; |
| 4572 |
int dig, colon; |
| 4573 |
struct dhcp_vendor *new = opt_malloc(sizeof(struct dhcp_vendor)); |
| 4574 |
|
| 4575 |
if (!(comma = split(arg))) |
| 4576 |
ret_err_free(gen_err, new); |
| 4577 |
|
| 4578 |
new->netid.net = opt_string_alloc(set_prefix(arg)); |
| 4579 |
/* check for hex string - must digits may include : must not have nothing else, |
| 4580 |
only allowed for agent-options. */ |
| 4581 |
|
| 4582 |
arg = comma; |
| 4583 |
if (option == 'U' && strstr(arg, "enterprise:") == arg) |
| 4584 |
{ |
| 4585 |
comma = split(arg); |
| 4586 |
new->enterprise = atoi(arg+11); |
| 4587 |
arg = comma; |
| 4588 |
} |
| 4589 |
|
| 4590 |
if (arg) |
| 4591 |
{ |
| 4592 |
for (dig = 0, colon = 0, p = (unsigned char *)arg; *p; p++) |
| 4593 |
if (isxdigit(*p)) |
| 4594 |
dig = 1; |
| 4595 |
else if (*p == ':') |
| 4596 |
colon = 1; |
| 4597 |
else |
| 4598 |
break; |
| 4599 |
|
| 4600 |
unhide_metas(arg); |
| 4601 |
if (option == 'U' || option == 'j' || *p || !dig || !colon) |
| 4602 |
{ |
| 4603 |
new->len = strlen(arg); |
| 4604 |
new->data = opt_malloc(new->len); |
| 4605 |
memcpy(new->data, arg, new->len); |
| 4606 |
} |
| 4607 |
else |
| 4608 |
{ |
| 4609 |
new->len = parse_hex(comma, (unsigned char *)arg, strlen(arg), NULL, NULL); |
| 4610 |
new->data = opt_malloc(new->len); |
| 4611 |
memcpy(new->data, arg, new->len); |
| 4612 |
} |
| 4613 |
} |
| 4614 |
else if (option != 'U' || new->enterprise == 0) |
| 4615 |
{ |
| 4616 |
free(new->netid.net); |
| 4617 |
ret_err_free(gen_err, new); |
| 4618 |
} |
| 4619 |
|
| 4620 |
switch (option) |
| 4621 |
{ |
| 4622 |
case 'j': |
| 4623 |
new->match_type = MATCH_USER; |
| 4624 |
break; |
| 4625 |
case 'U': |
| 4626 |
new->match_type = MATCH_VENDOR; |
| 4627 |
break; |
| 4628 |
case LOPT_CIRCUIT: |
| 4629 |
new->match_type = MATCH_CIRCUIT; |
| 4630 |
break; |
| 4631 |
case LOPT_REMOTE: |
| 4632 |
new->match_type = MATCH_REMOTE; |
| 4633 |
break; |
| 4634 |
case LOPT_SUBSCR: |
| 4635 |
new->match_type = MATCH_SUBSCRIBER; |
| 4636 |
break; |
| 4637 |
} |
| 4638 |
new->next = daemon->dhcp_vendors; |
| 4639 |
daemon->dhcp_vendors = new; |
| 4640 |
|
| 4641 |
break; |
| 4642 |
} |
| 4643 |
|
| 4644 |
case LOPT_ALTPORT: /* --dhcp-alternate-port */ |
| 4645 |
if (!arg) |
| 4646 |
{ |
| 4647 |
daemon->dhcp_server_port = DHCP_SERVER_ALTPORT; |
| 4648 |
daemon->dhcp_client_port = DHCP_CLIENT_ALTPORT; |
| 4649 |
} |
| 4650 |
else |
| 4651 |
{ |
| 4652 |
comma = split(arg); |
| 4653 |
if (!atoi_check16(arg, &daemon->dhcp_server_port) || |
| 4654 |
(comma && !atoi_check16(comma, &daemon->dhcp_client_port))) |
| 4655 |
ret_err(_("invalid port number")); |
| 4656 |
if (!comma) |
| 4657 |
daemon->dhcp_client_port = daemon->dhcp_server_port+1; |
| 4658 |
} |
| 4659 |
break; |
| 4660 |
|
| 4661 |
case 'J': /* --dhcp-ignore */ |
| 4662 |
case LOPT_NO_NAMES: /* --dhcp-ignore-names */ |
| 4663 |
case LOPT_BROADCAST: /* --dhcp-broadcast */ |
| 4664 |
case '3': /* --bootp-dynamic */ |
| 4665 |
case LOPT_GEN_NAMES: /* --dhcp-generate-names */ |
| 4666 |
{ |
| 4667 |
struct dhcp_netid_list *new = opt_malloc(sizeof(struct dhcp_netid_list)); |
| 4668 |
struct dhcp_netid *list = NULL; |
| 4669 |
if (option == 'J') |
| 4670 |
{ |
| 4671 |
new->next = daemon->dhcp_ignore; |
| 4672 |
daemon->dhcp_ignore = new; |
| 4673 |
} |
| 4674 |
else if (option == LOPT_BROADCAST) |
| 4675 |
{ |
| 4676 |
new->next = daemon->force_broadcast; |
| 4677 |
daemon->force_broadcast = new; |
| 4678 |
} |
| 4679 |
else if (option == '3') |
| 4680 |
{ |
| 4681 |
new->next = daemon->bootp_dynamic; |
| 4682 |
daemon->bootp_dynamic = new; |
| 4683 |
} |
| 4684 |
else if (option == LOPT_GEN_NAMES) |
| 4685 |
{ |
| 4686 |
new->next = daemon->dhcp_gen_names; |
| 4687 |
daemon->dhcp_gen_names = new; |
| 4688 |
} |
| 4689 |
else |
| 4690 |
{ |
| 4691 |
new->next = daemon->dhcp_ignore_names; |
| 4692 |
daemon->dhcp_ignore_names = new; |
| 4693 |
} |
| 4694 |
|
| 4695 |
while (arg) { |
| 4696 |
comma = split(arg); |
| 4697 |
list = dhcp_netid_create(is_tag_prefix(arg) ? arg+4 :arg, list); |
| 4698 |
arg = comma; |
| 4699 |
} |
| 4700 |
|
| 4701 |
new->list = list; |
| 4702 |
break; |
| 4703 |
} |
| 4704 |
|
| 4705 |
case LOPT_PROXY: /* --dhcp-proxy */ |
| 4706 |
daemon->override = 1; |
| 4707 |
while (arg) { |
| 4708 |
struct addr_list *new = opt_malloc(sizeof(struct addr_list)); |
| 4709 |
comma = split(arg); |
| 4710 |
if (!(inet_pton(AF_INET, arg, &new->addr) > 0)) |
| 4711 |
ret_err_free(_("bad dhcp-proxy address"), new); |
| 4712 |
new->next = daemon->override_relays; |
| 4713 |
daemon->override_relays = new; |
| 4714 |
arg = comma; |
| 4715 |
} |
| 4716 |
break; |
| 4717 |
|
| 4718 |
case LOPT_PXE_VENDOR: /* --dhcp-pxe-vendor */ |
| 4719 |
{ |
| 4720 |
while (arg) { |
| 4721 |
struct dhcp_pxe_vendor *new = opt_malloc(sizeof(struct dhcp_pxe_vendor)); |
| 4722 |
comma = split(arg); |
| 4723 |
new->data = opt_string_alloc(arg); |
| 4724 |
new->next = daemon->dhcp_pxe_vendors; |
| 4725 |
daemon->dhcp_pxe_vendors = new; |
| 4726 |
arg = comma; |
| 4727 |
} |
| 4728 |
} |
| 4729 |
break; |
| 4730 |
|
| 4731 |
case LOPT_RELAY: /* --dhcp-relay */ |
| 4732 |
case LOPT_SPLIT_RELAY: /* --dhcp-splt-relay */ |
| 4733 |
{ |
| 4734 |
struct dhcp_relay *new = opt_malloc(sizeof(struct dhcp_relay)); |
| 4735 |
char *two = split(arg); |
| 4736 |
char *three = split(two); |
| 4737 |
|
| 4738 |
if (option == LOPT_SPLIT_RELAY) |
| 4739 |
{ |
| 4740 |
new->split_mode = 1; |
| 4741 |
|
| 4742 |
/* split mode must have two addresses and a non-wildcard interface name. */ |
| 4743 |
if (!three || strchr(three, '*')) |
| 4744 |
two = NULL; |
| 4745 |
} |
| 4746 |
|
| 4747 |
new->iface_index = 0; |
| 4748 |
|
| 4749 |
if (two) |
| 4750 |
{ |
| 4751 |
if (inet_pton(AF_INET, arg, &new->local)) |
| 4752 |
{ |
| 4753 |
char *hash = split_chr(two, '#'); |
| 4754 |
|
| 4755 |
if (!hash || !atoi_check16(hash, &new->port)) |
| 4756 |
new->port = DHCP_SERVER_PORT; |
| 4757 |
|
| 4758 |
if (!inet_pton(AF_INET, two, &new->server)) |
| 4759 |
{ |
| 4760 |
new->server.addr4.s_addr = 0; |
| 4761 |
|
| 4762 |
/* Fail for three arg version where there are not two addresses. |
| 4763 |
Also fail when broadcasting to wildcard address. */ |
| 4764 |
if (three || strchr(two, '*')) |
| 4765 |
two = NULL; |
| 4766 |
else |
| 4767 |
three = two; |
| 4768 |
} |
| 4769 |
else if (new->split_mode && inet_pton(AF_INET, three, &new->uplink)) |
| 4770 |
/* Third arg in split mode can be an address. */ |
| 4771 |
three = NULL; |
| 4772 |
|
| 4773 |
new->next = daemon->relay4; |
| 4774 |
daemon->relay4 = new; |
| 4775 |
} |
| 4776 |
#ifdef HAVE_DHCP6 |
| 4777 |
else if (inet_pton(AF_INET6, arg, &new->local) && !new->split_mode) |
| 4778 |
{ |
| 4779 |
char *hash = split_chr(two, '#'); |
| 4780 |
|
| 4781 |
if (!hash || !atoi_check16(hash, &new->port)) |
| 4782 |
new->port = DHCPV6_SERVER_PORT; |
| 4783 |
|
| 4784 |
if (!inet_pton(AF_INET6, two, &new->server)) |
| 4785 |
{ |
| 4786 |
inet_pton(AF_INET6, ALL_SERVERS, &new->server.addr6); |
| 4787 |
/* Fail for three arg version where there are not two addresses. |
| 4788 |
Also fail when multicasting to wildcard address. */ |
| 4789 |
if (three || strchr(two, '*')) |
| 4790 |
two = NULL; |
| 4791 |
else |
| 4792 |
three = two; |
| 4793 |
} |
| 4794 |
new->next = daemon->relay6; |
| 4795 |
daemon->relay6 = new; |
| 4796 |
} |
| 4797 |
#endif |
| 4798 |
else |
| 4799 |
two = NULL; |
| 4800 |
|
| 4801 |
new->interface = opt_string_alloc(three); |
| 4802 |
} |
| 4803 |
|
| 4804 |
if (!two) |
| 4805 |
{ |
| 4806 |
free(new->interface); |
| 4807 |
ret_err_free(_("Bad dhcp-relay"), new); |
| 4808 |
} |
| 4809 |
|
| 4810 |
break; |
| 4811 |
} |
| 4812 |
|
| 4813 |
#endif |
| 4814 |
|
| 4815 |
#ifdef HAVE_DHCP6 |
| 4816 |
case LOPT_RA_PARAM: /* --ra-param */ |
| 4817 |
if ((comma = split(arg))) |
| 4818 |
{ |
| 4819 |
struct ra_interface *new = opt_malloc(sizeof(struct ra_interface)); |
| 4820 |
new->lifetime = -1; |
| 4821 |
new->prio = 0; |
| 4822 |
new->mtu = 0; |
| 4823 |
new->mtu_name = NULL; |
| 4824 |
new->name = opt_string_alloc(arg); |
| 4825 |
if (strcasestr(comma, "mtu:") == comma) |
| 4826 |
{ |
| 4827 |
arg = comma + 4; |
| 4828 |
if (!(comma = split(comma))) |
| 4829 |
goto err; |
| 4830 |
if (!strcasecmp(arg, "off")) |
| 4831 |
new->mtu = -1; |
| 4832 |
else if (!atoi_check(arg, &new->mtu)) |
| 4833 |
new->mtu_name = opt_string_alloc(arg); |
| 4834 |
else if (new->mtu < 1280) |
| 4835 |
goto err; |
| 4836 |
} |
| 4837 |
if (strcasestr(comma, "high") == comma || strcasestr(comma, "low") == comma) |
| 4838 |
{ |
| 4839 |
if (*comma == 'l' || *comma == 'L') |
| 4840 |
new->prio = 0x18; |
| 4841 |
else |
| 4842 |
new->prio = 0x08; |
| 4843 |
comma = split(comma); |
| 4844 |
} |
| 4845 |
arg = split(comma); |
| 4846 |
if (!atoi_check(comma, &new->interval) || |
| 4847 |
(arg && !atoi_check(arg, &new->lifetime))) |
| 4848 |
{ |
| 4849 |
err: |
| 4850 |
free(new->name); |
| 4851 |
ret_err_free(_("bad RA-params"), new); |
| 4852 |
} |
| 4853 |
|
| 4854 |
new->next = daemon->ra_interfaces; |
| 4855 |
daemon->ra_interfaces = new; |
| 4856 |
} |
| 4857 |
break; |
| 4858 |
|
| 4859 |
case LOPT_DUID: /* --dhcp-duid */ |
| 4860 |
if (!(comma = split(arg)) || !atoi_check(arg, (int *)&daemon->duid_enterprise)) |
| 4861 |
ret_err(_("bad DUID")); |
| 4862 |
else |
| 4863 |
{ |
| 4864 |
daemon->duid_config_len = parse_hex(comma,(unsigned char *)comma, strlen(comma), NULL, NULL); |
| 4865 |
daemon->duid_config = opt_malloc(daemon->duid_config_len); |
| 4866 |
memcpy(daemon->duid_config, comma, daemon->duid_config_len); |
| 4867 |
} |
| 4868 |
break; |
| 4869 |
#endif |
| 4870 |
|
| 4871 |
case 'V': /* --alias */ |
| 4872 |
{ |
| 4873 |
char *dash, *a[3] = { NULL, NULL, NULL }; |
| 4874 |
int k = 0; |
| 4875 |
struct doctor *new = opt_malloc(sizeof(struct doctor)); |
| 4876 |
new->next = daemon->doctors; |
| 4877 |
daemon->doctors = new; |
| 4878 |
new->mask.s_addr = 0xffffffff; |
| 4879 |
new->end.s_addr = 0; |
| 4880 |
|
| 4881 |
if ((a[0] = arg)) |
| 4882 |
for (k = 1; k < 3; k++) |
| 4883 |
{ |
| 4884 |
if (!(a[k] = split(a[k-1]))) |
| 4885 |
break; |
| 4886 |
unhide_metas(a[k]); |
| 4887 |
} |
| 4888 |
|
| 4889 |
dash = split_chr(a[0], '-'); |
| 4890 |
|
| 4891 |
if ((k < 2) || |
| 4892 |
(!(inet_pton(AF_INET, a[0], &new->in) > 0)) || |
| 4893 |
(!(inet_pton(AF_INET, a[1], &new->out) > 0)) || |
| 4894 |
(k == 3 && !inet_pton(AF_INET, a[2], &new->mask))) |
| 4895 |
ret_err(_("missing address in alias")); |
| 4896 |
|
| 4897 |
if (dash && |
| 4898 |
(!(inet_pton(AF_INET, dash, &new->end) > 0) || |
| 4899 |
!is_same_net(new->in, new->end, new->mask) || |
| 4900 |
ntohl(new->in.s_addr) > ntohl(new->end.s_addr))) |
| 4901 |
ret_err_free(_("invalid alias range"), new); |
| 4902 |
|
| 4903 |
break; |
| 4904 |
} |
| 4905 |
|
| 4906 |
case LOPT_INTNAME: /* --interface-name */ |
| 4907 |
case LOPT_DYNHOST: /* --dynamic-host */ |
| 4908 |
{ |
| 4909 |
struct interface_name *new, **up; |
| 4910 |
char *domain = arg; |
| 4911 |
|
| 4912 |
arg = split(arg); |
| 4913 |
|
| 4914 |
new = opt_malloc(sizeof(struct interface_name)); |
| 4915 |
memset(new, 0, sizeof(struct interface_name)); |
| 4916 |
new->flags = IN4 | IN6; |
| 4917 |
|
| 4918 |
/* Add to the end of the list, so that first name |
| 4919 |
of an interface is used for PTR lookups. */ |
| 4920 |
for (up = &daemon->int_names; *up; up = &((*up)->next)); |
| 4921 |
*up = new; |
| 4922 |
|
| 4923 |
while ((comma = split(arg))) |
| 4924 |
{ |
| 4925 |
if (inet_pton(AF_INET, arg, &new->proto4)) |
| 4926 |
new->flags |= INP4; |
| 4927 |
else if (inet_pton(AF_INET6, arg, &new->proto6)) |
| 4928 |
new->flags |= INP6; |
| 4929 |
else |
| 4930 |
break; |
| 4931 |
|
| 4932 |
arg = comma; |
| 4933 |
} |
| 4934 |
|
| 4935 |
if ((comma = split_chr(arg, '/'))) |
| 4936 |
{ |
| 4937 |
if (strcmp(comma, "4") == 0) |
| 4938 |
new->flags &= ~IN6; |
| 4939 |
else if (strcmp(comma, "6") == 0) |
| 4940 |
new->flags &= ~IN4; |
| 4941 |
else |
| 4942 |
ret_err_free(gen_err, new); |
| 4943 |
} |
| 4944 |
|
| 4945 |
new->intr = opt_string_alloc(arg); |
| 4946 |
|
| 4947 |
if (option == LOPT_DYNHOST) |
| 4948 |
{ |
| 4949 |
if (!(new->flags & (INP4 | INP6))) |
| 4950 |
ret_err(_("missing address in dynamic host")); |
| 4951 |
|
| 4952 |
if (!(new->flags & IN4) || !(new->flags & IN6)) |
| 4953 |
arg = NULL; /* provoke error below */ |
| 4954 |
|
| 4955 |
new->flags &= ~(IN4 | IN6); |
| 4956 |
} |
| 4957 |
else |
| 4958 |
{ |
| 4959 |
if (new->flags & (INP4 | INP6)) |
| 4960 |
arg = NULL; /* provoke error below */ |
| 4961 |
} |
| 4962 |
|
| 4963 |
if (!domain || !arg || !new->intr || |
| 4964 |
!(new->name = canonicalise_opt(domain))) |
| 4965 |
ret_err(option == LOPT_DYNHOST ? |
| 4966 |
_("bad dynamic host") : _("bad interface name")); |
| 4967 |
|
| 4968 |
break; |
| 4969 |
} |
| 4970 |
|
| 4971 |
case LOPT_CNAME: /* --cname */ |
| 4972 |
{ |
| 4973 |
struct cname *new; |
| 4974 |
char *alias, *target=NULL, *last, *pen; |
| 4975 |
int ttl = -1; |
| 4976 |
|
| 4977 |
for (last = pen = NULL, comma = arg; comma; comma = split(comma)) |
| 4978 |
{ |
| 4979 |
pen = last; |
| 4980 |
last = comma; |
| 4981 |
} |
| 4982 |
|
| 4983 |
if (!pen) |
| 4984 |
ret_err(_("bad CNAME")); |
| 4985 |
|
| 4986 |
if (pen != arg && atoi_check(last, &ttl)) |
| 4987 |
last = pen; |
| 4988 |
|
| 4989 |
while (arg != last) |
| 4990 |
{ |
| 4991 |
int arglen = strlen(arg); |
| 4992 |
alias = canonicalise_opt(arg); |
| 4993 |
|
| 4994 |
if (!target) |
| 4995 |
target = canonicalise_opt(last); |
| 4996 |
if (!alias || !target) |
| 4997 |
{ |
| 4998 |
free(target); |
| 4999 |
free(alias); |
| 5000 |
ret_err(_("bad CNAME")); |
| 5001 |
} |
| 5002 |
|
| 5003 |
for (new = daemon->cnames; new; new = new->next) |
| 5004 |
if (hostname_isequal(new->alias, alias)) |
| 5005 |
{ |
| 5006 |
free(target); |
| 5007 |
free(alias); |
| 5008 |
ret_err(_("duplicate CNAME")); |
| 5009 |
} |
| 5010 |
new = opt_malloc(sizeof(struct cname)); |
| 5011 |
new->next = daemon->cnames; |
| 5012 |
daemon->cnames = new; |
| 5013 |
new->alias = alias; |
| 5014 |
new->target = target; |
| 5015 |
new->ttl = ttl; |
| 5016 |
|
| 5017 |
for (arg += arglen+1; *arg && isspace((unsigned char)*arg); arg++); |
| 5018 |
} |
| 5019 |
|
| 5020 |
break; |
| 5021 |
} |
| 5022 |
|
| 5023 |
case LOPT_PTR: /* --ptr-record */ |
| 5024 |
{ |
| 5025 |
struct ptr_record *new; |
| 5026 |
char *dom, *target = NULL; |
| 5027 |
|
| 5028 |
comma = split(arg); |
| 5029 |
|
| 5030 |
if (!(dom = canonicalise_opt(arg)) || |
| 5031 |
(comma && !(target = canonicalise_opt(comma)))) |
| 5032 |
{ |
| 5033 |
free(dom); |
| 5034 |
free(target); |
| 5035 |
ret_err(_("bad PTR record")); |
| 5036 |
} |
| 5037 |
else |
| 5038 |
{ |
| 5039 |
new = opt_malloc(sizeof(struct ptr_record)); |
| 5040 |
new->next = daemon->ptr; |
| 5041 |
daemon->ptr = new; |
| 5042 |
new->name = dom; |
| 5043 |
new->ptr = target; |
| 5044 |
} |
| 5045 |
break; |
| 5046 |
} |
| 5047 |
|
| 5048 |
case LOPT_NAPTR: /* --naptr-record */ |
| 5049 |
{ |
| 5050 |
char *a[7] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; |
| 5051 |
int k = 0; |
| 5052 |
struct naptr *new; |
| 5053 |
int order, pref; |
| 5054 |
char *name=NULL, *replace = NULL; |
| 5055 |
|
| 5056 |
if ((a[0] = arg)) |
| 5057 |
for (k = 1; k < 7; k++) |
| 5058 |
if (!(a[k] = split(a[k-1]))) |
| 5059 |
break; |
| 5060 |
|
| 5061 |
|
| 5062 |
if (k < 6 || |
| 5063 |
!(name = canonicalise_opt(a[0])) || |
| 5064 |
!atoi_check16(a[1], &order) || |
| 5065 |
!atoi_check16(a[2], &pref) || |
| 5066 |
(k == 7 && !(replace = canonicalise_opt(a[6])))) |
| 5067 |
{ |
| 5068 |
free(name); |
| 5069 |
free(replace); |
| 5070 |
ret_err(_("bad NAPTR record")); |
| 5071 |
} |
| 5072 |
else |
| 5073 |
{ |
| 5074 |
new = opt_malloc(sizeof(struct naptr)); |
| 5075 |
new->next = daemon->naptr; |
| 5076 |
daemon->naptr = new; |
| 5077 |
new->name = name; |
| 5078 |
new->flags = opt_string_alloc(a[3]); |
| 5079 |
new->services = opt_string_alloc(a[4]); |
| 5080 |
new->regexp = opt_string_alloc(a[5]); |
| 5081 |
new->replace = replace; |
| 5082 |
new->order = order; |
| 5083 |
new->pref = pref; |
| 5084 |
} |
| 5085 |
break; |
| 5086 |
} |
| 5087 |
|
| 5088 |
case LOPT_RR: /* dns-rr */ |
| 5089 |
{ |
| 5090 |
struct txt_record *new; |
| 5091 |
size_t len = 0; |
| 5092 |
char *data; |
| 5093 |
int class; |
| 5094 |
|
| 5095 |
comma = split(arg); |
| 5096 |
data = split(comma); |
| 5097 |
|
| 5098 |
new = opt_malloc(sizeof(struct txt_record)); |
| 5099 |
new->name = NULL; |
| 5100 |
|
| 5101 |
if (!atoi_check(comma, &class) || |
| 5102 |
!(new->name = canonicalise_opt(arg)) || |
| 5103 |
(data && (len = parse_hex(data, (unsigned char *)data, -1, NULL, NULL)) == -1U)) |
| 5104 |
{ |
| 5105 |
free(new->name); |
| 5106 |
ret_err_free(_("bad RR record"), new); |
| 5107 |
} |
| 5108 |
|
| 5109 |
new->len = 0; |
| 5110 |
new->class = class; |
| 5111 |
new->next = daemon->rr; |
| 5112 |
daemon->rr = new; |
| 5113 |
|
| 5114 |
if (data) |
| 5115 |
{ |
| 5116 |
new->txt = opt_malloc(len); |
| 5117 |
new->len = len; |
| 5118 |
memcpy(new->txt, data, len); |
| 5119 |
} |
| 5120 |
|
| 5121 |
break; |
| 5122 |
} |
| 5123 |
|
| 5124 |
case LOPT_CAA: /* --caa-record */ |
| 5125 |
{ |
| 5126 |
struct txt_record *new; |
| 5127 |
char *tag, *value; |
| 5128 |
int flags; |
| 5129 |
|
| 5130 |
comma = split(arg); |
| 5131 |
tag = split(comma); |
| 5132 |
value = split(tag); |
| 5133 |
|
| 5134 |
new = opt_malloc(sizeof(struct txt_record)); |
| 5135 |
new->next = daemon->rr; |
| 5136 |
daemon->rr = new; |
| 5137 |
|
| 5138 |
if (!atoi_check(comma, &flags) || !tag || !value || !(new->name = canonicalise_opt(arg))) |
| 5139 |
ret_err(_("bad CAA record")); |
| 5140 |
|
| 5141 |
unhide_metas(tag); |
| 5142 |
unhide_metas(value); |
| 5143 |
|
| 5144 |
new->len = strlen(tag) + strlen(value) + 2; |
| 5145 |
new->txt = opt_malloc(new->len); |
| 5146 |
new->txt[0] = flags; |
| 5147 |
new->txt[1] = strlen(tag); |
| 5148 |
memcpy(&new->txt[2], tag, strlen(tag)); |
| 5149 |
memcpy(&new->txt[2 + strlen(tag)], value, strlen(value)); |
| 5150 |
new->class = T_CAA; |
| 5151 |
|
| 5152 |
break; |
| 5153 |
} |
| 5154 |
|
| 5155 |
case 'Y': /* --txt-record */ |
| 5156 |
{ |
| 5157 |
struct txt_record *new; |
| 5158 |
unsigned char *p, *cnt; |
| 5159 |
size_t len; |
| 5160 |
|
| 5161 |
comma = split(arg); |
| 5162 |
|
| 5163 |
new = opt_malloc(sizeof(struct txt_record)); |
| 5164 |
new->class = C_IN; |
| 5165 |
new->stat = 0; |
| 5166 |
|
| 5167 |
if (!(new->name = canonicalise_opt(arg))) |
| 5168 |
ret_err_free(_("bad TXT record"), new); |
| 5169 |
|
| 5170 |
new->next = daemon->txt; |
| 5171 |
daemon->txt = new; |
| 5172 |
len = comma ? strlen(comma) : 0; |
| 5173 |
len += (len/255) + 1; /* room for extra counts */ |
| 5174 |
new->txt = p = opt_malloc(len); |
| 5175 |
|
| 5176 |
cnt = p++; |
| 5177 |
*cnt = 0; |
| 5178 |
|
| 5179 |
while (comma && *comma) |
| 5180 |
{ |
| 5181 |
unsigned char c = (unsigned char)*comma++; |
| 5182 |
|
| 5183 |
if (c == ',' || *cnt == 255) |
| 5184 |
{ |
| 5185 |
if (c != ',') |
| 5186 |
comma--; |
| 5187 |
cnt = p++; |
| 5188 |
*cnt = 0; |
| 5189 |
} |
| 5190 |
else |
| 5191 |
{ |
| 5192 |
*p++ = unhide_meta(c); |
| 5193 |
(*cnt)++; |
| 5194 |
} |
| 5195 |
} |
| 5196 |
|
| 5197 |
new->len = p - new->txt; |
| 5198 |
|
| 5199 |
break; |
| 5200 |
} |
| 5201 |
|
| 5202 |
case 'W': /* --srv-host */ |
| 5203 |
{ |
| 5204 |
int port = 1, priority = 0, weight = 0; |
| 5205 |
char *name, *target = NULL; |
| 5206 |
struct mx_srv_record *new; |
| 5207 |
|
| 5208 |
comma = split(arg); |
| 5209 |
|
| 5210 |
if (!(name = canonicalise_opt(arg))) |
| 5211 |
ret_err(_("bad SRV record")); |
| 5212 |
|
| 5213 |
if (comma) |
| 5214 |
{ |
| 5215 |
arg = comma; |
| 5216 |
comma = split(arg); |
| 5217 |
if (!(target = canonicalise_opt(arg))) |
| 5218 |
ret_err_free(_("bad SRV target"), name); |
| 5219 |
|
| 5220 |
if (comma) |
| 5221 |
{ |
| 5222 |
arg = comma; |
| 5223 |
comma = split(arg); |
| 5224 |
if (!atoi_check16(arg, &port)) |
| 5225 |
{ |
| 5226 |
free(name); |
| 5227 |
ret_err_free(_("invalid port number"), target); |
| 5228 |
} |
| 5229 |
|
| 5230 |
if (comma) |
| 5231 |
{ |
| 5232 |
arg = comma; |
| 5233 |
comma = split(arg); |
| 5234 |
if (!atoi_check16(arg, &priority)) |
| 5235 |
{ |
| 5236 |
free(name); |
| 5237 |
ret_err_free(_("invalid priority"), target); |
| 5238 |
} |
| 5239 |
if (comma && !atoi_check16(comma, &weight)) |
| 5240 |
{ |
| 5241 |
free(name); |
| 5242 |
ret_err_free(_("invalid weight"), target); |
| 5243 |
} |
| 5244 |
} |
| 5245 |
} |
| 5246 |
} |
| 5247 |
|
| 5248 |
new = opt_malloc(sizeof(struct mx_srv_record)); |
| 5249 |
new->next = daemon->mxnames; |
| 5250 |
daemon->mxnames = new; |
| 5251 |
new->issrv = 1; |
| 5252 |
new->name = name; |
| 5253 |
new->target = target; |
| 5254 |
new->srvport = port; |
| 5255 |
new->priority = priority; |
| 5256 |
new->weight = weight; |
| 5257 |
break; |
| 5258 |
} |
| 5259 |
|
| 5260 |
case LOPT_HOST_REC: /* --host-record */ |
| 5261 |
{ |
| 5262 |
struct host_record *new; |
| 5263 |
|
| 5264 |
if (!arg || !(comma = split(arg))) |
| 5265 |
ret_err(_("Bad host-record")); |
| 5266 |
|
| 5267 |
new = opt_malloc(sizeof(struct host_record)); |
| 5268 |
memset(new, 0, sizeof(struct host_record)); |
| 5269 |
new->ttl = -1; |
| 5270 |
new->flags = 0; |
| 5271 |
|
| 5272 |
while (arg) |
| 5273 |
{ |
| 5274 |
union all_addr addr; |
| 5275 |
char *dig; |
| 5276 |
|
| 5277 |
for (dig = arg; *dig != 0; dig++) |
| 5278 |
if (*dig < '0' || *dig > '9') |
| 5279 |
break; |
| 5280 |
if (*dig == 0) |
| 5281 |
new->ttl = atoi(arg); |
| 5282 |
else if (inet_pton(AF_INET, arg, &addr.addr4)) |
| 5283 |
{ |
| 5284 |
new->addr = addr.addr4; |
| 5285 |
new->flags |= HR_4; |
| 5286 |
} |
| 5287 |
else if (inet_pton(AF_INET6, arg, &addr.addr6)) |
| 5288 |
{ |
| 5289 |
new->addr6 = addr.addr6; |
| 5290 |
new->flags |= HR_6; |
| 5291 |
} |
| 5292 |
else |
| 5293 |
{ |
| 5294 |
char *canon = canonicalise_opt(arg); |
| 5295 |
struct name_list *nl; |
| 5296 |
if (!canon) |
| 5297 |
{ |
| 5298 |
struct name_list *tmp, *next; |
| 5299 |
for (tmp = new->names; tmp; tmp = next) |
| 5300 |
{ |
| 5301 |
next = tmp->next; |
| 5302 |
free(tmp); |
| 5303 |
} |
| 5304 |
ret_err_free(_("Bad name in host-record"), new); |
| 5305 |
} |
| 5306 |
|
| 5307 |
nl = opt_malloc(sizeof(struct name_list)); |
| 5308 |
nl->name = canon; |
| 5309 |
/* keep order, so that PTR record goes to first name */ |
| 5310 |
nl->next = NULL; |
| 5311 |
if (!new->names) |
| 5312 |
new->names = nl; |
| 5313 |
else |
| 5314 |
{ |
| 5315 |
struct name_list *tmp; |
| 5316 |
for (tmp = new->names; tmp->next; tmp = tmp->next); |
| 5317 |
tmp->next = nl; |
| 5318 |
} |
| 5319 |
} |
| 5320 |
|
| 5321 |
arg = comma; |
| 5322 |
comma = split(arg); |
| 5323 |
} |
| 5324 |
|
| 5325 |
/* Keep list order */ |
| 5326 |
if (!daemon->host_records_tail) |
| 5327 |
daemon->host_records = new; |
| 5328 |
else |
| 5329 |
daemon->host_records_tail->next = new; |
| 5330 |
new->next = NULL; |
| 5331 |
daemon->host_records_tail = new; |
| 5332 |
break; |
| 5333 |
} |
| 5334 |
|
| 5335 |
case LOPT_STALE_CACHE: /* --use-stale-cache */ |
| 5336 |
{ |
| 5337 |
int max_expiry = STALE_CACHE_EXPIRY; |
| 5338 |
if (arg) |
| 5339 |
{ |
| 5340 |
/* Don't accept negative TTLs here, they'd have the counter-intuitive |
| 5341 |
side-effect of evicting cache records before they expire */ |
| 5342 |
if (!atoi_check(arg, &max_expiry) || max_expiry < 0) |
| 5343 |
ret_err(gen_err); |
| 5344 |
/* Store "serve expired forever" as -1 internally, the option isn't |
| 5345 |
active for daemon->cache_max_expiry == 0 */ |
| 5346 |
if (max_expiry == 0) |
| 5347 |
max_expiry = -1; |
| 5348 |
} |
| 5349 |
daemon->cache_max_expiry = max_expiry; |
| 5350 |
break; |
| 5351 |
} |
| 5352 |
|
| 5353 |
#ifdef HAVE_DNSSEC |
| 5354 |
case LOPT_DNSSEC_LIMITS: |
| 5355 |
{ |
| 5356 |
int lim, val; |
| 5357 |
|
| 5358 |
for (lim = LIMIT_SIG_FAIL; arg && lim < LIMIT_MAX ; lim++, arg = comma) |
| 5359 |
{ |
| 5360 |
comma = split(arg); |
| 5361 |
|
| 5362 |
if (!atoi_check(arg, &val)) |
| 5363 |
ret_err(gen_err); |
| 5364 |
|
| 5365 |
if (val != 0) |
| 5366 |
daemon->limit[lim] = val; |
| 5367 |
} |
| 5368 |
|
| 5369 |
break; |
| 5370 |
} |
| 5371 |
|
| 5372 |
case LOPT_DNSSEC_STAMP: /* --dnssec-timestamp */ |
| 5373 |
daemon->timestamp_file = opt_string_alloc(arg); |
| 5374 |
break; |
| 5375 |
|
| 5376 |
case LOPT_DNSSEC_CHECK: /* --dnssec-check-unsigned */ |
| 5377 |
if (arg) |
| 5378 |
{ |
| 5379 |
if (strcmp(arg, "no") == 0) |
| 5380 |
set_option_bool(OPT_DNSSEC_IGN_NS); |
| 5381 |
else |
| 5382 |
ret_err(_("bad value for dnssec-check-unsigned")); |
| 5383 |
} |
| 5384 |
break; |
| 5385 |
|
| 5386 |
case LOPT_TRUST_ANCHOR: /* --trust-anchor */ |
| 5387 |
{ |
| 5388 |
struct ds_config *new = opt_malloc(sizeof(struct ds_config)); |
| 5389 |
char *cp, *cp1, *keyhex, *digest, *algo = NULL; |
| 5390 |
int len; |
| 5391 |
|
| 5392 |
new->class = C_IN; |
| 5393 |
new->name = NULL; |
| 5394 |
new->digestlen = 0; |
| 5395 |
|
| 5396 |
if ((comma = split(arg)) && (algo = split(comma))) |
| 5397 |
{ |
| 5398 |
int class = 0; |
| 5399 |
if (strcmp(comma, "IN") == 0) |
| 5400 |
class = C_IN; |
| 5401 |
else if (strcmp(comma, "CH") == 0) |
| 5402 |
class = C_CHAOS; |
| 5403 |
else if (strcmp(comma, "HS") == 0) |
| 5404 |
class = C_HESIOD; |
| 5405 |
|
| 5406 |
if (class != 0) |
| 5407 |
{ |
| 5408 |
new->class = class; |
| 5409 |
comma = algo; |
| 5410 |
algo = split(comma); |
| 5411 |
} |
| 5412 |
} |
| 5413 |
|
| 5414 |
if (!(new->name = canonicalise_opt(arg))) |
| 5415 |
ret_err_free(_("bad trust anchor"), new); |
| 5416 |
|
| 5417 |
if (comma) |
| 5418 |
{ |
| 5419 |
if (!algo || !(digest = split(algo)) || !(keyhex = split(digest)) || |
| 5420 |
!atoi_check16(comma, &new->keytag) || |
| 5421 |
!atoi_check8(algo, &new->algo) || |
| 5422 |
!atoi_check8(digest, &new->digest_type)) |
| 5423 |
{ |
| 5424 |
free(new->name); |
| 5425 |
ret_err_free(_("bad trust anchor"), new); |
| 5426 |
} |
| 5427 |
|
| 5428 |
/* Upper bound on length */ |
| 5429 |
len = (2*strlen(keyhex))+1; |
| 5430 |
new->digest = opt_malloc(len); |
| 5431 |
unhide_metas(keyhex); |
| 5432 |
/* 4034: "Whitespace is allowed within digits" */ |
| 5433 |
for (cp = keyhex; *cp; ) |
| 5434 |
if (isspace((unsigned char)*cp)) |
| 5435 |
for (cp1 = cp; *cp1; cp1++) |
| 5436 |
*cp1 = *(cp1+1); |
| 5437 |
else |
| 5438 |
cp++; |
| 5439 |
if ((new->digestlen = parse_hex(keyhex, (unsigned char *)new->digest, len, NULL, NULL)) == -1) |
| 5440 |
{ |
| 5441 |
free(new->name); |
| 5442 |
ret_err_free(_("bad HEX in trust anchor"), new); |
| 5443 |
} |
| 5444 |
} |
| 5445 |
|
| 5446 |
new->next = daemon->ds; |
| 5447 |
daemon->ds = new; |
| 5448 |
|
| 5449 |
break; |
| 5450 |
} |
| 5451 |
#endif |
| 5452 |
|
| 5453 |
case LOPT_MAX_PROCS: /* --max-tcp-connections */ |
| 5454 |
{ |
| 5455 |
int max_procs; |
| 5456 |
/* Don't accept numbers less than 1. */ |
| 5457 |
if (!atoi_check(arg, &max_procs) || max_procs < 1) |
| 5458 |
ret_err(gen_err); |
| 5459 |
daemon->max_procs = max_procs; |
| 5460 |
break; |
| 5461 |
} |
| 5462 |
|
| 5463 |
default: |
| 5464 |
ret_err(_("unsupported option (check that dnsmasq was compiled with DHCP/TFTP/DNSSEC/DBus support)")); |
| 5465 |
|
| 5466 |
} |
| 5467 |
|
| 5468 |
return 1; |
| 5469 |
} |
| 5470 |
|
| 5471 |
static void read_file(char *file, FILE *f, int hard_opt, int from_script) |
| 5472 |
{ |
| 5473 |
volatile int lineno = 0; |
| 5474 |
char *buff; |
| 5475 |
size_t buffsz; |
| 5476 |
|
| 5477 |
/* Memory allocation failure longjmps here if mem_recover == 1 */ |
| 5478 |
if (hard_opt != 0) |
| 5479 |
{ |
| 5480 |
setjmp(mem_jmp); |
| 5481 |
mem_recover = 1; |
| 5482 |
} |
| 5483 |
|
| 5484 |
buff = NULL; |
| 5485 |
buffsz = 0; |
| 5486 |
|
| 5487 |
while (get_line_alloc(f, &buff, &buffsz)) |
| 5488 |
{ |
| 5489 |
int white, i; |
| 5490 |
volatile int option; |
| 5491 |
char *errmess, *p, *arg, *start; |
| 5492 |
size_t len; |
| 5493 |
|
| 5494 |
option = (hard_opt == LOPT_REV_SERV) ? 0 : hard_opt; |
| 5495 |
|
| 5496 |
arg = NULL; |
| 5497 |
lineno++; |
| 5498 |
errmess = NULL; |
| 5499 |
|
| 5500 |
/* Implement quotes, inside quotes we allow \\ \" \n and \t |
| 5501 |
metacharacters get hidden also strip comments */ |
| 5502 |
for (white = 1, p = buff; *p; p++) |
| 5503 |
{ |
| 5504 |
if (*p == '"') |
| 5505 |
{ |
| 5506 |
memmove(p, p+1, strlen(p+1)+1); |
| 5507 |
|
| 5508 |
for(; *p && *p != '"'; p++) |
| 5509 |
{ |
| 5510 |
if (*p == '\\' && strchr("\"tnebr\\", p[1])) |
| 5511 |
{ |
| 5512 |
if (p[1] == 't') |
| 5513 |
p[1] = '\t'; |
| 5514 |
else if (p[1] == 'n') |
| 5515 |
p[1] = '\n'; |
| 5516 |
else if (p[1] == 'b') |
| 5517 |
p[1] = '\b'; |
| 5518 |
else if (p[1] == 'r') |
| 5519 |
p[1] = '\r'; |
| 5520 |
else if (p[1] == 'e') /* escape */ |
| 5521 |
p[1] = '\033'; |
| 5522 |
memmove(p, p+1, strlen(p+1)+1); |
| 5523 |
} |
| 5524 |
*p = hide_meta(*p); |
| 5525 |
} |
| 5526 |
|
| 5527 |
if (*p == 0) |
| 5528 |
{ |
| 5529 |
errmess = _("missing \""); |
| 5530 |
goto oops; |
| 5531 |
} |
| 5532 |
|
| 5533 |
memmove(p, p+1, strlen(p+1)+1); |
| 5534 |
} |
| 5535 |
|
| 5536 |
if (isspace((unsigned char)*p)) |
| 5537 |
{ |
| 5538 |
*p = ' '; |
| 5539 |
white = 1; |
| 5540 |
} |
| 5541 |
else |
| 5542 |
{ |
| 5543 |
if (white && *p == '#') |
| 5544 |
{ |
| 5545 |
*p = 0; |
| 5546 |
break; |
| 5547 |
} |
| 5548 |
white = 0; |
| 5549 |
} |
| 5550 |
} |
| 5551 |
|
| 5552 |
|
| 5553 |
/* strip leading spaces */ |
| 5554 |
for (start = buff; *start && *start == ' '; start++); |
| 5555 |
|
| 5556 |
/* strip trailing spaces */ |
| 5557 |
for (len = strlen(start); (len != 0) && (start[len-1] == ' '); len--); |
| 5558 |
|
| 5559 |
if (len == 0) |
| 5560 |
continue; |
| 5561 |
else |
| 5562 |
start[len] = 0; |
| 5563 |
|
| 5564 |
if (option != 0) |
| 5565 |
arg = start; |
| 5566 |
else if ((p=strchr(start, '='))) |
| 5567 |
{ |
| 5568 |
/* allow spaces around "=" */ |
| 5569 |
for (arg = p+1; *arg == ' '; arg++); |
| 5570 |
for (; p >= start && (*p == ' ' || *p == '='); p--) |
| 5571 |
*p = 0; |
| 5572 |
} |
| 5573 |
else |
| 5574 |
arg = NULL; |
| 5575 |
|
| 5576 |
if (option == 0) |
| 5577 |
{ |
| 5578 |
for (option = 0, i = 0; opts[i].name; i++) |
| 5579 |
if (strcmp(opts[i].name, start) == 0) |
| 5580 |
{ |
| 5581 |
option = opts[i].val; |
| 5582 |
break; |
| 5583 |
} |
| 5584 |
|
| 5585 |
if (!option) |
| 5586 |
errmess = _("bad option"); |
| 5587 |
else if (opts[i].has_arg == 0 && arg) |
| 5588 |
errmess = _("extraneous parameter"); |
| 5589 |
else if (opts[i].has_arg == 1 && !arg) |
| 5590 |
errmess = _("missing parameter"); |
| 5591 |
else if (hard_opt == LOPT_REV_SERV && option != 'S' && option != LOPT_REV_SERV) |
| 5592 |
errmess = _("illegal option"); |
| 5593 |
} |
| 5594 |
|
| 5595 |
oops: |
| 5596 |
if (errmess) |
| 5597 |
strcpy(daemon->namebuff, errmess); |
| 5598 |
|
| 5599 |
if (errmess || !one_opt(option, arg, daemon->namebuff, _("error"), 0, hard_opt == LOPT_REV_SERV)) |
| 5600 |
{ |
| 5601 |
if (from_script) |
| 5602 |
sprintf(daemon->namebuff + strlen(daemon->namebuff), _(" in output from %s"), file); |
| 5603 |
else |
| 5604 |
sprintf(daemon->namebuff + strlen(daemon->namebuff), _(" at line %d of %s"), lineno, file); |
| 5605 |
|
| 5606 |
if (hard_opt != 0) |
| 5607 |
my_syslog(LOG_ERR, "%s", daemon->namebuff); |
| 5608 |
else |
| 5609 |
die("%s", daemon->namebuff, EC_BADCONF); |
| 5610 |
} |
| 5611 |
} |
| 5612 |
|
| 5613 |
mem_recover = 0; |
| 5614 |
} |
| 5615 |
|
| 5616 |
#if defined(HAVE_DHCP) && defined(HAVE_INOTIFY) |
| 5617 |
int option_read_dynfile(char *file, int flags) |
| 5618 |
{ |
| 5619 |
my_syslog(MS_DHCP | LOG_INFO, _("read %s"), file); |
| 5620 |
|
| 5621 |
if (flags & AH_DHCP_HST) |
| 5622 |
return one_file(file, LOPT_BANK); |
| 5623 |
else if (flags & AH_DHCP_OPT) |
| 5624 |
return one_file(file, LOPT_OPTS); |
| 5625 |
|
| 5626 |
return 0; |
| 5627 |
} |
| 5628 |
#endif |
| 5629 |
|
| 5630 |
static int one_file(char *file, int hard_opt) |
| 5631 |
{ |
| 5632 |
FILE *f; |
| 5633 |
int nofile_ok = 0, do_popen = 0; |
| 5634 |
static int read_stdin = 0; |
| 5635 |
static struct fileread { |
| 5636 |
dev_t dev; |
| 5637 |
ino_t ino; |
| 5638 |
struct fileread *next; |
| 5639 |
} *filesread = NULL; |
| 5640 |
|
| 5641 |
if (hard_opt == LOPT_CONF_OPT) |
| 5642 |
{ |
| 5643 |
/* default conf-file reading */ |
| 5644 |
hard_opt = 0; |
| 5645 |
nofile_ok = 1; |
| 5646 |
} |
| 5647 |
|
| 5648 |
if (hard_opt == LOPT_CONF_SCRIPT) |
| 5649 |
{ |
| 5650 |
hard_opt = 0; |
| 5651 |
do_popen = 1; |
| 5652 |
} |
| 5653 |
|
| 5654 |
if (hard_opt == 0 && !do_popen && strcmp(file, "-") == 0) |
| 5655 |
{ |
| 5656 |
if (read_stdin == 1) |
| 5657 |
return 1; |
| 5658 |
read_stdin = 1; |
| 5659 |
file = "stdin"; |
| 5660 |
f = stdin; |
| 5661 |
} |
| 5662 |
else |
| 5663 |
{ |
| 5664 |
/* ignore repeated files. */ |
| 5665 |
struct stat statbuf; |
| 5666 |
|
| 5667 |
if (hard_opt == 0 && stat(file, &statbuf) == 0) |
| 5668 |
{ |
| 5669 |
struct fileread *r; |
| 5670 |
|
| 5671 |
for (r = filesread; r; r = r->next) |
| 5672 |
if (r->dev == statbuf.st_dev && r->ino == statbuf.st_ino) |
| 5673 |
return 1; |
| 5674 |
|
| 5675 |
r = safe_malloc(sizeof(struct fileread)); |
| 5676 |
r->next = filesread; |
| 5677 |
filesread = r; |
| 5678 |
r->dev = statbuf.st_dev; |
| 5679 |
r->ino = statbuf.st_ino; |
| 5680 |
} |
| 5681 |
|
| 5682 |
if (do_popen) |
| 5683 |
{ |
| 5684 |
if (!(f = popen(file, "r"))) |
| 5685 |
die(_("cannot execute %s: %s"), file, EC_FILE); |
| 5686 |
} |
| 5687 |
else if (!(f = fopen(file, "r"))) |
| 5688 |
{ |
| 5689 |
if (errno == ENOENT && nofile_ok) |
| 5690 |
return 1; /* No conffile, all done. */ |
| 5691 |
else |
| 5692 |
{ |
| 5693 |
char *str = _("cannot read %s: %s"); |
| 5694 |
if (hard_opt != 0) |
| 5695 |
{ |
| 5696 |
my_syslog(LOG_ERR, str, file, strerror(errno)); |
| 5697 |
return 0; |
| 5698 |
} |
| 5699 |
else |
| 5700 |
die(str, file, EC_FILE); |
| 5701 |
} |
| 5702 |
} |
| 5703 |
} |
| 5704 |
|
| 5705 |
read_file(file, f, hard_opt, do_popen); |
| 5706 |
|
| 5707 |
if (do_popen) |
| 5708 |
{ |
| 5709 |
int rc; |
| 5710 |
|
| 5711 |
if ((rc = pclose(f)) == -1) |
| 5712 |
die(_("error executing %s: %s"), file, EC_MISC); |
| 5713 |
|
| 5714 |
if (rc != 0) |
| 5715 |
die(_("%s returns non-zero error code"), file, rc+10); |
| 5716 |
} |
| 5717 |
else |
| 5718 |
fclose(f); |
| 5719 |
|
| 5720 |
return 1; |
| 5721 |
} |
| 5722 |
|
| 5723 |
static int file_filter(const struct dirent *ent) |
| 5724 |
{ |
| 5725 |
size_t lenfile = strlen(ent->d_name); |
| 5726 |
|
| 5727 |
/* ignore emacs backups and dotfiles */ |
| 5728 |
|
| 5729 |
if (lenfile == 0 || |
| 5730 |
ent->d_name[lenfile - 1] == '~' || |
| 5731 |
(ent->d_name[0] == '#' && ent->d_name[lenfile - 1] == '#') || |
| 5732 |
ent->d_name[0] == '.') |
| 5733 |
return 0; |
| 5734 |
|
| 5735 |
return 1; |
| 5736 |
} |
| 5737 |
/* expand any name which is a directory */ |
| 5738 |
struct hostsfile *expand_filelist(struct hostsfile *list) |
| 5739 |
{ |
| 5740 |
unsigned int i; |
| 5741 |
int entcnt, n; |
| 5742 |
struct hostsfile *ah, *last, *next, **up; |
| 5743 |
struct dirent **namelist; |
| 5744 |
|
| 5745 |
/* find largest used index */ |
| 5746 |
for (last = NULL, i = SRC_AH, ah = list; ah; ah = ah->next) |
| 5747 |
{ |
| 5748 |
last = ah; |
| 5749 |
|
| 5750 |
if (i <= ah->index) |
| 5751 |
i = ah->index + 1; |
| 5752 |
|
| 5753 |
if (ah->flags & AH_DIR) |
| 5754 |
ah->flags |= AH_INACTIVE; |
| 5755 |
else |
| 5756 |
ah->flags &= ~AH_INACTIVE; |
| 5757 |
} |
| 5758 |
|
| 5759 |
for (ah = list; ah; ah = ah->next) |
| 5760 |
if (!(ah->flags & AH_INACTIVE)) |
| 5761 |
{ |
| 5762 |
struct stat buf; |
| 5763 |
if (stat(ah->fname, &buf) != -1 && S_ISDIR(buf.st_mode)) |
| 5764 |
{ |
| 5765 |
struct dirent *ent; |
| 5766 |
|
| 5767 |
/* don't read this as a file */ |
| 5768 |
ah->flags |= AH_INACTIVE; |
| 5769 |
|
| 5770 |
entcnt = scandir(ah->fname, &namelist, file_filter, alphasort); |
| 5771 |
if (entcnt < 0) |
| 5772 |
my_syslog(LOG_ERR, _("cannot access directory %s: %s"), |
| 5773 |
ah->fname, strerror(errno)); |
| 5774 |
else |
| 5775 |
{ |
| 5776 |
for (n = 0; n < entcnt; n++) |
| 5777 |
{ |
| 5778 |
ent = namelist[n]; |
| 5779 |
size_t lendir = strlen(ah->fname); |
| 5780 |
size_t lenfile = strlen(ent->d_name); |
| 5781 |
struct hostsfile *ah1; |
| 5782 |
char *path; |
| 5783 |
|
| 5784 |
/* see if we have an existing record. |
| 5785 |
dir is ah->fname |
| 5786 |
file is ent->d_name |
| 5787 |
path to match is ah1->fname */ |
| 5788 |
|
| 5789 |
for (up = &list, ah1 = list; ah1; ah1 = next) |
| 5790 |
{ |
| 5791 |
next = ah1->next; |
| 5792 |
|
| 5793 |
if (lendir < strlen(ah1->fname) && |
| 5794 |
strstr(ah1->fname, ah->fname) == ah1->fname && |
| 5795 |
ah1->fname[lendir] == '/' && |
| 5796 |
strcmp(ah1->fname + lendir + 1, ent->d_name) == 0) |
| 5797 |
{ |
| 5798 |
ah1->flags &= ~AH_INACTIVE; |
| 5799 |
/* If found, remove from list to re-insert at the end. |
| 5800 |
Unless it's already at the end. */ |
| 5801 |
if (last != ah1) |
| 5802 |
*up = next; |
| 5803 |
break; |
| 5804 |
} |
| 5805 |
|
| 5806 |
up = &ah1->next; |
| 5807 |
} |
| 5808 |
|
| 5809 |
/* make new record */ |
| 5810 |
if (!ah1) |
| 5811 |
{ |
| 5812 |
if (!(ah1 = whine_malloc(sizeof(struct hostsfile)))) |
| 5813 |
continue; |
| 5814 |
|
| 5815 |
if (!(path = whine_malloc(lendir + lenfile + 2))) |
| 5816 |
{ |
| 5817 |
free(ah1); |
| 5818 |
continue; |
| 5819 |
} |
| 5820 |
|
| 5821 |
strcpy(path, ah->fname); |
| 5822 |
strcat(path, "/"); |
| 5823 |
strcat(path, ent->d_name); |
| 5824 |
ah1->fname = path; |
| 5825 |
ah1->index = i++; |
| 5826 |
ah1->flags = AH_DIR; |
| 5827 |
} |
| 5828 |
|
| 5829 |
/* Edge case, may be the last in the list anyway */ |
| 5830 |
if (last != ah1) |
| 5831 |
last->next = ah1; |
| 5832 |
ah1->next = NULL; |
| 5833 |
last = ah1; |
| 5834 |
|
| 5835 |
/* inactivate record if not regular file */ |
| 5836 |
if ((ah1->flags & AH_DIR) && stat(ah1->fname, &buf) != -1 && !S_ISREG(buf.st_mode)) |
| 5837 |
ah1->flags |= AH_INACTIVE; |
| 5838 |
|
| 5839 |
} |
| 5840 |
} |
| 5841 |
free(namelist); |
| 5842 |
} |
| 5843 |
} |
| 5844 |
|
| 5845 |
return list; |
| 5846 |
} |
| 5847 |
|
| 5848 |
void read_servers_file(void) |
| 5849 |
{ |
| 5850 |
FILE *f; |
| 5851 |
|
| 5852 |
if (!(f = fopen(daemon->servers_file, "r"))) |
| 5853 |
{ |
| 5854 |
my_syslog(LOG_ERR, _("cannot read %s: %s"), daemon->servers_file, strerror(errno)); |
| 5855 |
return; |
| 5856 |
} |
| 5857 |
|
| 5858 |
mark_servers(SERV_FROM_FILE); |
| 5859 |
read_file(daemon->servers_file, f, LOPT_REV_SERV, 0); |
| 5860 |
fclose(f); |
| 5861 |
cleanup_servers(); |
| 5862 |
check_servers(0); |
| 5863 |
} |
| 5864 |
|
| 5865 |
|
| 5866 |
#ifdef HAVE_DHCP |
| 5867 |
static void clear_dynamic_conf(void) |
| 5868 |
{ |
| 5869 |
struct dhcp_config *configs, *cp, **up; |
| 5870 |
|
| 5871 |
/* remove existing... */ |
| 5872 |
for (up = &daemon->dhcp_conf, configs = daemon->dhcp_conf; configs; configs = cp) |
| 5873 |
{ |
| 5874 |
cp = configs->next; |
| 5875 |
|
| 5876 |
if (configs->flags & CONFIG_BANK) |
| 5877 |
{ |
| 5878 |
*up = cp; |
| 5879 |
dhcp_config_free(configs); |
| 5880 |
} |
| 5881 |
else |
| 5882 |
up = &configs->next; |
| 5883 |
} |
| 5884 |
} |
| 5885 |
|
| 5886 |
static void clear_dhcp_opt(struct dhcp_opt **dhcp_opts) |
| 5887 |
{ |
| 5888 |
struct dhcp_opt *opts, *cp, **up; |
| 5889 |
|
| 5890 |
for (up = dhcp_opts, opts = *dhcp_opts; opts; opts = cp) |
| 5891 |
{ |
| 5892 |
cp = opts->next; |
| 5893 |
|
| 5894 |
if (opts->flags & DHOPT_BANK) |
| 5895 |
{ |
| 5896 |
*up = cp; |
| 5897 |
dhcp_opt_free(opts); |
| 5898 |
} |
| 5899 |
else |
| 5900 |
up = &opts->next; |
| 5901 |
} |
| 5902 |
} |
| 5903 |
|
| 5904 |
static void clear_dynamic_opt(void) |
| 5905 |
{ |
| 5906 |
clear_dhcp_opt(&daemon->dhcp_opts); |
| 5907 |
#ifdef HAVE_DHCP6 |
| 5908 |
clear_dhcp_opt(&daemon->dhcp_opts6); |
| 5909 |
#endif |
| 5910 |
} |
| 5911 |
|
| 5912 |
void reread_dhcp(void) |
| 5913 |
{ |
| 5914 |
struct hostsfile *hf; |
| 5915 |
|
| 5916 |
/* Do these even if there is no daemon->dhcp_hosts_file or |
| 5917 |
daemon->dhcp_opts_file since entries may have been created by the |
| 5918 |
inotify dynamic file reading system. */ |
| 5919 |
|
| 5920 |
clear_dynamic_conf(); |
| 5921 |
clear_dynamic_opt(); |
| 5922 |
|
| 5923 |
if (daemon->dhcp_hosts_file) |
| 5924 |
{ |
| 5925 |
daemon->dhcp_hosts_file = expand_filelist(daemon->dhcp_hosts_file); |
| 5926 |
for (hf = daemon->dhcp_hosts_file; hf; hf = hf->next) |
| 5927 |
if (!(hf->flags & AH_INACTIVE)) |
| 5928 |
{ |
| 5929 |
if (one_file(hf->fname, LOPT_BANK)) |
| 5930 |
my_syslog(MS_DHCP | LOG_INFO, _("read %s"), hf->fname); |
| 5931 |
} |
| 5932 |
} |
| 5933 |
|
| 5934 |
if (daemon->dhcp_opts_file) |
| 5935 |
{ |
| 5936 |
daemon->dhcp_opts_file = expand_filelist(daemon->dhcp_opts_file); |
| 5937 |
for (hf = daemon->dhcp_opts_file; hf; hf = hf->next) |
| 5938 |
if (!(hf->flags & AH_INACTIVE)) |
| 5939 |
{ |
| 5940 |
if (one_file(hf->fname, LOPT_OPTS)) |
| 5941 |
my_syslog(MS_DHCP | LOG_INFO, _("read %s"), hf->fname); |
| 5942 |
} |
| 5943 |
} |
| 5944 |
|
| 5945 |
# ifdef HAVE_INOTIFY |
| 5946 |
/* Setup notify and read pre-existing files. */ |
| 5947 |
set_dynamic_inotify(AH_DHCP_HST | AH_DHCP_OPT, 0, NULL, 0); |
| 5948 |
# endif |
| 5949 |
} |
| 5950 |
#endif |
| 5951 |
|
| 5952 |
void read_opts(int argc, char **argv, char *compile_opts) |
| 5953 |
{ |
| 5954 |
size_t argbuf_size = 300; |
| 5955 |
char *argbuf = safe_malloc(argbuf_size); |
| 5956 |
int option, testmode = 0; |
| 5957 |
char *arg, *conffile = NULL; |
| 5958 |
|
| 5959 |
opterr = 0; |
| 5960 |
|
| 5961 |
daemon = opt_malloc(sizeof(struct daemon)); |
| 5962 |
memset(daemon, 0, sizeof(struct daemon)); |
| 5963 |
daemon->namebuff = safe_malloc(MAXDNAMESTR+1); |
| 5964 |
daemon->workspacename = safe_malloc(MAXDNAMESTR+1); |
| 5965 |
daemon->addrbuff = safe_malloc(ADDRSTRLEN); |
| 5966 |
|
| 5967 |
/* Set defaults - everything else is zero or NULL */ |
| 5968 |
daemon->cachesize = CACHESIZ; |
| 5969 |
daemon->ftabsize = FTABSIZ; |
| 5970 |
daemon->port = NAMESERVER_PORT; |
| 5971 |
daemon->dhcp_client_port = DHCP_CLIENT_PORT; |
| 5972 |
daemon->dhcp_server_port = DHCP_SERVER_PORT; |
| 5973 |
daemon->default_resolv.is_default = 1; |
| 5974 |
daemon->default_resolv.name = RESOLVFILE; |
| 5975 |
daemon->resolv_files = &daemon->default_resolv; |
| 5976 |
daemon->username = CHUSER; |
| 5977 |
daemon->runfile = RUNFILE; |
| 5978 |
daemon->dhcp_max = MAXLEASES; |
| 5979 |
daemon->tftp_max = TFTP_MAX_CONNECTIONS; |
| 5980 |
daemon->edns_pktsz = EDNS_PKTSZ; |
| 5981 |
daemon->log_fac = -1; |
| 5982 |
daemon->auth_ttl = AUTH_TTL; |
| 5983 |
daemon->soa_refresh = SOA_REFRESH; |
| 5984 |
daemon->soa_retry = SOA_RETRY; |
| 5985 |
daemon->soa_expiry = SOA_EXPIRY; |
| 5986 |
daemon->randport_limit = 1; |
| 5987 |
daemon->host_index = SRC_AH; |
| 5988 |
daemon->max_procs = MAX_PROCS; |
| 5989 |
#ifdef HAVE_DUMPFILE |
| 5990 |
daemon->dump_mask = 0xffffffff; |
| 5991 |
#endif |
| 5992 |
#ifdef HAVE_DNSSEC |
| 5993 |
daemon->limit[LIMIT_SIG_FAIL] = DNSSEC_LIMIT_SIG_FAIL; |
| 5994 |
daemon->limit[LIMIT_CRYPTO] = DNSSEC_LIMIT_CRYPTO; |
| 5995 |
daemon->limit[LIMIT_WORK] = DNSSEC_LIMIT_WORK; |
| 5996 |
daemon->limit[LIMIT_NSEC3_ITERS] = DNSSEC_LIMIT_NSEC3_ITERS; |
| 5997 |
#endif |
| 5998 |
|
| 5999 |
/* See comment above make_servers(). Optimises server-read code. */ |
| 6000 |
mark_servers(0); |
| 6001 |
|
| 6002 |
while (1) |
| 6003 |
{ |
| 6004 |
#ifdef HAVE_GETOPT_LONG |
| 6005 |
option = getopt_long(argc, argv, OPTSTRING, opts, NULL); |
| 6006 |
#else |
| 6007 |
option = getopt(argc, argv, OPTSTRING); |
| 6008 |
#endif |
| 6009 |
|
| 6010 |
if (option == -1) |
| 6011 |
{ |
| 6012 |
for (; optind < argc; optind++) |
| 6013 |
{ |
| 6014 |
unsigned char *c = (unsigned char *)argv[optind]; |
| 6015 |
for (; *c != 0; c++) |
| 6016 |
if (!isspace(*c)) |
| 6017 |
die(_("junk found in command line"), NULL, EC_BADCONF); |
| 6018 |
} |
| 6019 |
break; |
| 6020 |
} |
| 6021 |
|
| 6022 |
/* Copy optarg so that argv doesn't get changed */ |
| 6023 |
if (optarg) |
| 6024 |
{ |
| 6025 |
if (strlen(optarg) >= argbuf_size) |
| 6026 |
{ |
| 6027 |
free(argbuf); |
| 6028 |
argbuf_size = strlen(optarg) + 1; |
| 6029 |
argbuf = opt_malloc(argbuf_size); |
| 6030 |
} |
| 6031 |
safe_strncpy(argbuf, optarg, argbuf_size); |
| 6032 |
arg = argbuf; |
| 6033 |
} |
| 6034 |
else |
| 6035 |
arg = NULL; |
| 6036 |
|
| 6037 |
/* command-line only stuff */ |
| 6038 |
if (option == LOPT_TEST) |
| 6039 |
testmode = 1; |
| 6040 |
else if (option == 'w') |
| 6041 |
{ |
| 6042 |
#ifdef HAVE_DHCP |
| 6043 |
if (argc == 3 && strcmp(argv[2], "dhcp") == 0) |
| 6044 |
display_opts(); |
| 6045 |
#ifdef HAVE_DHCP6 |
| 6046 |
else if (argc == 3 && strcmp(argv[2], "dhcp6") == 0) |
| 6047 |
display_opts6(); |
| 6048 |
#endif |
| 6049 |
else |
| 6050 |
#endif |
| 6051 |
do_usage(); |
| 6052 |
|
| 6053 |
exit(0); |
| 6054 |
} |
| 6055 |
else if (option == 'v') |
| 6056 |
{ |
| 6057 |
printf(_("Dnsmasq version %s %s\n"), VERSION, COPYRIGHT); |
| 6058 |
printf(_("Compile time options: %s\n\n"), compile_opts); |
| 6059 |
printf(_("This software comes with ABSOLUTELY NO WARRANTY.\n")); |
| 6060 |
printf(_("Dnsmasq is free software, and you are welcome to redistribute it\n")); |
| 6061 |
printf(_("under the terms of the GNU General Public License, version 2 or 3.\n")); |
| 6062 |
exit(0); |
| 6063 |
} |
| 6064 |
else if (option == 'C') |
| 6065 |
{ |
| 6066 |
if (!conffile) |
| 6067 |
conffile = opt_string_alloc(arg); |
| 6068 |
else |
| 6069 |
{ |
| 6070 |
char *extra = opt_string_alloc(arg); |
| 6071 |
one_file(extra, 0); |
| 6072 |
free(extra); |
| 6073 |
} |
| 6074 |
} |
| 6075 |
else |
| 6076 |
{ |
| 6077 |
#ifdef HAVE_GETOPT_LONG |
| 6078 |
if (!one_opt(option, arg, daemon->namebuff, _("try --help"), 1, 0)) |
| 6079 |
#else |
| 6080 |
if (!one_opt(option, arg, daemon->namebuff, _("try -w"), 1, 0)) |
| 6081 |
#endif |
| 6082 |
die(_("bad command line options: %s"), daemon->namebuff, EC_BADCONF); |
| 6083 |
} |
| 6084 |
} |
| 6085 |
|
| 6086 |
free(argbuf); |
| 6087 |
|
| 6088 |
if (conffile) |
| 6089 |
{ |
| 6090 |
one_file(conffile, 0); |
| 6091 |
free(conffile); |
| 6092 |
} |
| 6093 |
else |
| 6094 |
one_file(CONFFILE, LOPT_CONF_OPT); |
| 6095 |
|
| 6096 |
/* Add TXT records if wanted */ |
| 6097 |
#ifndef NO_ID |
| 6098 |
if (!option_bool(OPT_NO_IDENT)) |
| 6099 |
{ |
| 6100 |
add_txt("version.bind", "dnsmasq-" VERSION, 0 ); |
| 6101 |
add_txt("authors.bind", "Simon Kelley", 0); |
| 6102 |
add_txt("copyright.bind", COPYRIGHT, 0); |
| 6103 |
add_txt("cachesize.bind", NULL, TXT_STAT_CACHESIZE); |
| 6104 |
add_txt("insertions.bind", NULL, TXT_STAT_INSERTS); |
| 6105 |
add_txt("evictions.bind", NULL, TXT_STAT_EVICTIONS); |
| 6106 |
add_txt("misses.bind", NULL, TXT_STAT_MISSES); |
| 6107 |
add_txt("hits.bind", NULL, TXT_STAT_HITS); |
| 6108 |
#ifdef HAVE_AUTH |
| 6109 |
add_txt("auth.bind", NULL, TXT_STAT_AUTH); |
| 6110 |
#endif |
| 6111 |
add_txt("servers.bind", NULL, TXT_STAT_SERVERS); |
| 6112 |
} |
| 6113 |
#endif |
| 6114 |
|
| 6115 |
#ifdef HAVE_DNSSEC |
| 6116 |
/* Default fast retry on when doing DNSSEC */ |
| 6117 |
if (option_bool(OPT_DNSSEC_VALID) && daemon->fast_retry_time == 0) |
| 6118 |
{ |
| 6119 |
daemon->fast_retry_timeout = TIMEOUT; |
| 6120 |
daemon->fast_retry_time = DEFAULT_FAST_RETRY; |
| 6121 |
} |
| 6122 |
#endif |
| 6123 |
|
| 6124 |
/* port might not be known when the address is parsed - fill in here */ |
| 6125 |
if (daemon->servers) |
| 6126 |
{ |
| 6127 |
struct server *tmp; |
| 6128 |
for (tmp = daemon->servers; tmp; tmp = tmp->next) |
| 6129 |
if (!(tmp->flags & SERV_HAS_SOURCE)) |
| 6130 |
{ |
| 6131 |
if (tmp->source_addr.sa.sa_family == AF_INET) |
| 6132 |
tmp->source_addr.in.sin_port = htons(daemon->query_port); |
| 6133 |
else if (tmp->source_addr.sa.sa_family == AF_INET6) |
| 6134 |
tmp->source_addr.in6.sin6_port = htons(daemon->query_port); |
| 6135 |
} |
| 6136 |
} |
| 6137 |
|
| 6138 |
if (daemon->host_records) |
| 6139 |
{ |
| 6140 |
struct host_record *hr; |
| 6141 |
|
| 6142 |
for (hr = daemon->host_records; hr; hr = hr->next) |
| 6143 |
if (hr->ttl == -1) |
| 6144 |
hr->ttl = daemon->local_ttl; |
| 6145 |
} |
| 6146 |
|
| 6147 |
if (daemon->cnames) |
| 6148 |
{ |
| 6149 |
struct cname *cn, *cn2, *cn3; |
| 6150 |
|
| 6151 |
#define NOLOOP 1 |
| 6152 |
#define TESTLOOP 2 |
| 6153 |
|
| 6154 |
/* Fill in TTL for CNAMES now we have local_ttl. |
| 6155 |
Also prepare to do loop detection. */ |
| 6156 |
for (cn = daemon->cnames; cn; cn = cn->next) |
| 6157 |
{ |
| 6158 |
if (cn->ttl == -1) |
| 6159 |
cn->ttl = daemon->local_ttl; |
| 6160 |
cn->flag = 0; |
| 6161 |
cn->targetp = NULL; |
| 6162 |
for (cn2 = daemon->cnames; cn2; cn2 = cn2->next) |
| 6163 |
if (hostname_isequal(cn->target, cn2->alias)) |
| 6164 |
{ |
| 6165 |
cn->targetp = cn2; |
| 6166 |
break; |
| 6167 |
} |
| 6168 |
} |
| 6169 |
|
| 6170 |
/* Find any CNAME loops.*/ |
| 6171 |
for (cn = daemon->cnames; cn; cn = cn->next) |
| 6172 |
{ |
| 6173 |
for (cn2 = cn->targetp; cn2; cn2 = cn2->targetp) |
| 6174 |
{ |
| 6175 |
if (cn2->flag == NOLOOP) |
| 6176 |
break; |
| 6177 |
|
| 6178 |
if (cn2->flag == TESTLOOP) |
| 6179 |
die(_("CNAME loop involving %s"), cn->alias, EC_BADCONF); |
| 6180 |
|
| 6181 |
cn2->flag = TESTLOOP; |
| 6182 |
} |
| 6183 |
|
| 6184 |
for (cn3 = cn->targetp; cn3 != cn2; cn3 = cn3->targetp) |
| 6185 |
cn3->flag = NOLOOP; |
| 6186 |
} |
| 6187 |
} |
| 6188 |
|
| 6189 |
if (daemon->if_addrs) |
| 6190 |
{ |
| 6191 |
struct iname *tmp; |
| 6192 |
for(tmp = daemon->if_addrs; tmp; tmp = tmp->next) |
| 6193 |
if (tmp->addr.sa.sa_family == AF_INET) |
| 6194 |
tmp->addr.in.sin_port = htons(daemon->port); |
| 6195 |
else if (tmp->addr.sa.sa_family == AF_INET6) |
| 6196 |
tmp->addr.in6.sin6_port = htons(daemon->port); |
| 6197 |
} |
| 6198 |
|
| 6199 |
/* create default, if not specified */ |
| 6200 |
if (daemon->authserver && !daemon->hostmaster) |
| 6201 |
{ |
| 6202 |
strcpy(daemon->namebuff, "hostmaster."); |
| 6203 |
strncat(daemon->namebuff, daemon->authserver, MAXDNAMESTR - strlen(daemon->namebuff)); |
| 6204 |
daemon->hostmaster = opt_string_alloc(daemon->namebuff); |
| 6205 |
} |
| 6206 |
|
| 6207 |
if (!daemon->dhcp_pxe_vendors) |
| 6208 |
{ |
| 6209 |
daemon->dhcp_pxe_vendors = opt_malloc(sizeof(struct dhcp_pxe_vendor)); |
| 6210 |
daemon->dhcp_pxe_vendors->data = opt_string_alloc(DHCP_PXE_DEF_VENDOR); |
| 6211 |
daemon->dhcp_pxe_vendors->next = NULL; |
| 6212 |
} |
| 6213 |
|
| 6214 |
/* only one of these need be specified: the other defaults to the host-name */ |
| 6215 |
if (option_bool(OPT_LOCALMX) || daemon->mxnames || daemon->mxtarget) |
| 6216 |
{ |
| 6217 |
struct mx_srv_record *mx; |
| 6218 |
|
| 6219 |
if (gethostname(daemon->namebuff, MAXDNAMESTR) == -1) |
| 6220 |
die(_("cannot get host-name: %s"), NULL, EC_MISC); |
| 6221 |
|
| 6222 |
for (mx = daemon->mxnames; mx; mx = mx->next) |
| 6223 |
if (!mx->issrv && hostname_isequal(mx->name, daemon->namebuff)) |
| 6224 |
break; |
| 6225 |
|
| 6226 |
if ((daemon->mxtarget || option_bool(OPT_LOCALMX)) && !mx) |
| 6227 |
{ |
| 6228 |
mx = opt_malloc(sizeof(struct mx_srv_record)); |
| 6229 |
mx->next = daemon->mxnames; |
| 6230 |
mx->issrv = 0; |
| 6231 |
mx->target = NULL; |
| 6232 |
mx->name = opt_string_alloc(daemon->namebuff); |
| 6233 |
daemon->mxnames = mx; |
| 6234 |
} |
| 6235 |
|
| 6236 |
if (!daemon->mxtarget) |
| 6237 |
daemon->mxtarget = opt_string_alloc(daemon->namebuff); |
| 6238 |
|
| 6239 |
for (mx = daemon->mxnames; mx; mx = mx->next) |
| 6240 |
if (!mx->issrv && !mx->target) |
| 6241 |
mx->target = daemon->mxtarget; |
| 6242 |
} |
| 6243 |
|
| 6244 |
if (!option_bool(OPT_NO_RESOLV) && |
| 6245 |
daemon->resolv_files && |
| 6246 |
daemon->resolv_files->next && |
| 6247 |
option_bool(OPT_NO_POLL)) |
| 6248 |
die(_("only one resolv.conf file allowed in no-poll mode."), NULL, EC_BADCONF); |
| 6249 |
|
| 6250 |
if (option_bool(OPT_RESOLV_DOMAIN)) |
| 6251 |
{ |
| 6252 |
char *line = NULL; |
| 6253 |
size_t linesz = 0; |
| 6254 |
FILE *f; |
| 6255 |
|
| 6256 |
if (option_bool(OPT_NO_RESOLV) || |
| 6257 |
!daemon->resolv_files || |
| 6258 |
(daemon->resolv_files)->next) |
| 6259 |
die(_("must have exactly one resolv.conf to read domain from."), NULL, EC_BADCONF); |
| 6260 |
|
| 6261 |
if (!(f = fopen((daemon->resolv_files)->name, "r"))) |
| 6262 |
die(_("failed to read %s: %s"), (daemon->resolv_files)->name, EC_FILE); |
| 6263 |
|
| 6264 |
while (get_line_alloc(f, &line, &linesz)) |
| 6265 |
{ |
| 6266 |
char *token = strtok(line, " \t\n\r"); |
| 6267 |
|
| 6268 |
if (!token || strcmp(token, "search") != 0) |
| 6269 |
continue; |
| 6270 |
|
| 6271 |
if ((token = strtok(NULL, " \t\n\r")) && |
| 6272 |
(daemon->domain_suffix = canonicalise_opt(token))) |
| 6273 |
{ |
| 6274 |
/* We don't call get_line_alloc() until it returns false and frees the automatically */ |
| 6275 |
get_line_alloc(NULL, &line, &linesz); |
| 6276 |
break; |
| 6277 |
} |
| 6278 |
} |
| 6279 |
|
| 6280 |
fclose(f); |
| 6281 |
|
| 6282 |
if (!daemon->domain_suffix) |
| 6283 |
die(_("no search directive found in %s"), (daemon->resolv_files)->name, EC_MISC); |
| 6284 |
} |
| 6285 |
|
| 6286 |
if (daemon->domain_suffix) |
| 6287 |
{ |
| 6288 |
/* add domain for any srv record without one. */ |
| 6289 |
struct mx_srv_record *srv; |
| 6290 |
|
| 6291 |
for (srv = daemon->mxnames; srv; srv = srv->next) |
| 6292 |
if (srv->issrv && |
| 6293 |
strchr(srv->name, '.') && |
| 6294 |
strchr(srv->name, '.') == strrchr(srv->name, '.')) |
| 6295 |
{ |
| 6296 |
if (strlen(srv->name) + 1 + strlen(daemon->domain_suffix) > MAXDNAMESTR) |
| 6297 |
die(_("srv-host name %s too long after domain appended"), srv->name, EC_MISC); |
| 6298 |
strcpy(daemon->namebuff, srv->name); |
| 6299 |
strcat(daemon->namebuff, "."); |
| 6300 |
strcat(daemon->namebuff, daemon->domain_suffix); |
| 6301 |
free(srv->name); |
| 6302 |
if (!(srv->name = canonicalise_opt(daemon->namebuff))) |
| 6303 |
die(_("bad srv-host name %s after domain appended"), srv->name, EC_MISC); |
| 6304 |
} |
| 6305 |
} |
| 6306 |
else if (option_bool(OPT_DHCP_FQDN)) |
| 6307 |
die(_("there must be a default domain when --dhcp-fqdn is set"), NULL, EC_BADCONF); |
| 6308 |
|
| 6309 |
/* If there's access-control config, then ignore --local-service, it's intended |
| 6310 |
as a system default to keep otherwise unconfigured installations safe. */ |
| 6311 |
if (daemon->if_names || daemon->if_except || daemon->if_addrs || daemon->authserver) |
| 6312 |
{ |
| 6313 |
reset_option_bool(OPT_LOCAL_SERVICE); |
| 6314 |
reset_option_bool(OPT_LOCALHOST_SERVICE); |
| 6315 |
} |
| 6316 |
else if (option_bool(OPT_LOCALHOST_SERVICE) && !option_bool(OPT_LOCAL_SERVICE)) |
| 6317 |
{ |
| 6318 |
/* listen only on localhost, emulate --interface=lo --bind-interfaces */ |
| 6319 |
if_names_add(NULL); |
| 6320 |
set_option_bool(OPT_NOWILD); |
| 6321 |
} |
| 6322 |
|
| 6323 |
if (testmode) |
| 6324 |
{ |
| 6325 |
fprintf(stderr, "dnsmasq: %s.\n", _("syntax check OK")); |
| 6326 |
exit(0); |
| 6327 |
} |
| 6328 |
} |