Simon Kelley | c8e8f5c | 2021-01-24 21:59:37 +0000 | [diff] [blame] | 1 | /* dnsmasq is Copyright (c) 2000-2021 Simon Kelley |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 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 |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5 | the Free Software Foundation; version 2 dated June, 1991, or |
| 6 | (at your option) version 3 dated 29 June, 2007. |
| 7 | |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 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. |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 12 | |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 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/>. |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 17 | /* define this to get facilitynames */ |
| 18 | #define SYSLOG_NAMES |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 19 | #include "dnsmasq.h" |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 20 | #include <setjmp.h> |
| 21 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 22 | static volatile int mem_recover = 0; |
| 23 | static jmp_buf mem_jmp; |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 24 | static int one_file(char *file, int hard_opt); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 25 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 26 | /* Solaris headers don't have facility names. */ |
| 27 | #ifdef HAVE_SOLARIS_NETWORK |
| 28 | static const struct { |
| 29 | char *c_name; |
| 30 | unsigned int c_val; |
| 31 | } facilitynames[] = { |
| 32 | { "kern", LOG_KERN }, |
| 33 | { "user", LOG_USER }, |
| 34 | { "mail", LOG_MAIL }, |
| 35 | { "daemon", LOG_DAEMON }, |
| 36 | { "auth", LOG_AUTH }, |
| 37 | { "syslog", LOG_SYSLOG }, |
| 38 | { "lpr", LOG_LPR }, |
| 39 | { "news", LOG_NEWS }, |
| 40 | { "uucp", LOG_UUCP }, |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 41 | { "audit", LOG_AUDIT }, |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 42 | { "cron", LOG_CRON }, |
| 43 | { "local0", LOG_LOCAL0 }, |
| 44 | { "local1", LOG_LOCAL1 }, |
| 45 | { "local2", LOG_LOCAL2 }, |
| 46 | { "local3", LOG_LOCAL3 }, |
| 47 | { "local4", LOG_LOCAL4 }, |
| 48 | { "local5", LOG_LOCAL5 }, |
| 49 | { "local6", LOG_LOCAL6 }, |
| 50 | { "local7", LOG_LOCAL7 }, |
| 51 | { NULL, 0 } |
| 52 | }; |
| 53 | #endif |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 54 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 55 | #ifndef HAVE_GETOPT_LONG |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 56 | struct myoption { |
| 57 | const char *name; |
| 58 | int has_arg; |
| 59 | int *flag; |
| 60 | int val; |
| 61 | }; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 62 | #endif |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 63 | |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 64 | #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:" |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 65 | |
Simon Kelley | 1697269 | 2006-10-16 20:04:18 +0100 | [diff] [blame] | 66 | /* options which don't have a one-char version */ |
Simon Kelley | e98bd52 | 2014-03-28 20:41:23 +0000 | [diff] [blame] | 67 | #define LOPT_RELOAD 256 |
| 68 | #define LOPT_NO_NAMES 257 |
| 69 | #define LOPT_TFTP 258 |
| 70 | #define LOPT_SECURE 259 |
| 71 | #define LOPT_PREFIX 260 |
| 72 | #define LOPT_PTR 261 |
| 73 | #define LOPT_BRIDGE 262 |
| 74 | #define LOPT_TFTP_MAX 263 |
| 75 | #define LOPT_FORCE 264 |
| 76 | #define LOPT_NOBLOCK 265 |
| 77 | #define LOPT_LOG_OPTS 266 |
| 78 | #define LOPT_MAX_LOGS 267 |
| 79 | #define LOPT_CIRCUIT 268 |
| 80 | #define LOPT_REMOTE 269 |
| 81 | #define LOPT_SUBSCR 270 |
| 82 | #define LOPT_INTNAME 271 |
| 83 | #define LOPT_BANK 272 |
| 84 | #define LOPT_DHCP_HOST 273 |
| 85 | #define LOPT_APREF 274 |
| 86 | #define LOPT_OVERRIDE 275 |
| 87 | #define LOPT_TFTPPORTS 276 |
| 88 | #define LOPT_REBIND 277 |
| 89 | #define LOPT_NOLAST 278 |
| 90 | #define LOPT_OPTS 279 |
| 91 | #define LOPT_DHCP_OPTS 280 |
| 92 | #define LOPT_MATCH 281 |
| 93 | #define LOPT_BROADCAST 282 |
| 94 | #define LOPT_NEGTTL 283 |
| 95 | #define LOPT_ALTPORT 284 |
| 96 | #define LOPT_SCRIPTUSR 285 |
| 97 | #define LOPT_LOCAL 286 |
| 98 | #define LOPT_NAPTR 287 |
| 99 | #define LOPT_MINPORT 288 |
| 100 | #define LOPT_DHCP_FQDN 289 |
| 101 | #define LOPT_CNAME 290 |
| 102 | #define LOPT_PXE_PROMT 291 |
| 103 | #define LOPT_PXE_SERV 292 |
| 104 | #define LOPT_TEST 293 |
| 105 | #define LOPT_TAG_IF 294 |
| 106 | #define LOPT_PROXY 295 |
| 107 | #define LOPT_GEN_NAMES 296 |
| 108 | #define LOPT_MAXTTL 297 |
| 109 | #define LOPT_NO_REBIND 298 |
| 110 | #define LOPT_LOC_REBND 299 |
| 111 | #define LOPT_ADD_MAC 300 |
| 112 | #define LOPT_DNSSEC 301 |
| 113 | #define LOPT_INCR_ADDR 302 |
| 114 | #define LOPT_CONNTRACK 303 |
| 115 | #define LOPT_FQDN 304 |
| 116 | #define LOPT_LUASCRIPT 305 |
| 117 | #define LOPT_RA 306 |
| 118 | #define LOPT_DUID 307 |
| 119 | #define LOPT_HOST_REC 308 |
| 120 | #define LOPT_TFTP_LC 309 |
| 121 | #define LOPT_RR 310 |
| 122 | #define LOPT_CLVERBIND 311 |
| 123 | #define LOPT_MAXCTTL 312 |
| 124 | #define LOPT_AUTHZONE 313 |
| 125 | #define LOPT_AUTHSERV 314 |
| 126 | #define LOPT_AUTHTTL 315 |
| 127 | #define LOPT_AUTHSOA 316 |
| 128 | #define LOPT_AUTHSFS 317 |
| 129 | #define LOPT_AUTHPEER 318 |
| 130 | #define LOPT_IPSET 319 |
| 131 | #define LOPT_SYNTH 320 |
Simon Kelley | e98bd52 | 2014-03-28 20:41:23 +0000 | [diff] [blame] | 132 | #define LOPT_RELAY 323 |
| 133 | #define LOPT_RA_PARAM 324 |
| 134 | #define LOPT_ADD_SBNET 325 |
| 135 | #define LOPT_QUIET_DHCP 326 |
| 136 | #define LOPT_QUIET_DHCP6 327 |
| 137 | #define LOPT_QUIET_RA 328 |
| 138 | #define LOPT_SEC_VALID 329 |
| 139 | #define LOPT_TRUST_ANCHOR 330 |
| 140 | #define LOPT_DNSSEC_DEBUG 331 |
| 141 | #define LOPT_REV_SERV 332 |
| 142 | #define LOPT_SERVERS_FILE 333 |
| 143 | #define LOPT_DNSSEC_CHECK 334 |
Simon Kelley | c8a8048 | 2014-03-05 14:29:54 +0000 | [diff] [blame] | 144 | #define LOPT_LOCAL_SERVICE 335 |
Simon Kelley | e98bd52 | 2014-03-28 20:41:23 +0000 | [diff] [blame] | 145 | #define LOPT_DNSSEC_TIME 336 |
Simon Kelley | b5ea1cc | 2014-07-29 16:34:14 +0100 | [diff] [blame] | 146 | #define LOPT_LOOP_DETECT 337 |
Glen Huang | 32fc6db | 2014-12-27 15:28:12 +0000 | [diff] [blame] | 147 | #define LOPT_IGNORE_ADDR 338 |
RinSatsuki | 28de387 | 2015-01-10 15:22:21 +0000 | [diff] [blame] | 148 | #define LOPT_MINCTTL 339 |
Simon Kelley | 5f4dc5c | 2015-01-20 20:51:02 +0000 | [diff] [blame] | 149 | #define LOPT_DHCP_INOTIFY 340 |
Simon Kelley | 70d1873 | 2015-01-31 19:59:29 +0000 | [diff] [blame] | 150 | #define LOPT_DHOPT_INOTIFY 341 |
| 151 | #define LOPT_HOST_INOTIFY 342 |
Simon Kelley | f6e62e2 | 2015-03-01 18:17:54 +0000 | [diff] [blame] | 152 | #define LOPT_DNSSEC_STAMP 343 |
Stefan Tomanek | 30d0879 | 2015-03-31 22:32:11 +0100 | [diff] [blame] | 153 | #define LOPT_TFTP_NO_FAIL 344 |
Hans Dedecker | 926332a | 2016-01-23 10:48:12 +0000 | [diff] [blame] | 154 | #define LOPT_MAXPORT 345 |
Simon Kelley | 1e50512 | 2016-01-25 21:29:23 +0000 | [diff] [blame] | 155 | #define LOPT_CPE_ID 346 |
| 156 | #define LOPT_SCRIPT_ARP 347 |
Simon Kelley | 832e47b | 2016-02-24 21:24:45 +0000 | [diff] [blame] | 157 | #define LOPT_DHCPTTL 348 |
Simon Kelley | bec366b | 2016-02-24 22:03:26 +0000 | [diff] [blame] | 158 | #define LOPT_TFTP_MTU 349 |
Floris Bos | 503c609 | 2017-04-09 23:07:13 +0100 | [diff] [blame] | 159 | #define LOPT_REPLY_DELAY 350 |
Simon Kelley | 734d531 | 2018-03-23 23:09:53 +0000 | [diff] [blame] | 160 | #define LOPT_RAPID_COMMIT 351 |
Simon Kelley | 6b17335 | 2018-05-08 18:32:14 +0100 | [diff] [blame] | 161 | #define LOPT_DUMPFILE 352 |
| 162 | #define LOPT_DUMPMASK 353 |
Julian Kornberger | 8dcdb33 | 2018-07-21 22:11:08 +0100 | [diff] [blame] | 163 | #define LOPT_UBUS 354 |
Simon Kelley | c822620 | 2018-08-08 23:46:03 +0100 | [diff] [blame] | 164 | #define LOPT_NAME_MATCH 355 |
Simon Kelley | 974a6d0 | 2018-08-23 23:01:16 +0100 | [diff] [blame] | 165 | #define LOPT_CAA 356 |
Simon Kelley | ae5b7e0 | 2019-03-27 22:33:28 +0000 | [diff] [blame] | 166 | #define LOPT_SHARED_NET 357 |
Florent Fourcot | 13a58f9 | 2019-06-20 10:26:40 +0200 | [diff] [blame] | 167 | #define LOPT_IGNORE_CLID 358 |
Simon Kelley | 66f6265 | 2020-01-05 16:21:24 +0000 | [diff] [blame] | 168 | #define LOPT_SINGLE_PORT 359 |
Simon Kelley | ee64582 | 2020-02-27 16:34:14 +0000 | [diff] [blame] | 169 | #define LOPT_SCRIPT_TIME 360 |
Wang Shanker | 4ded962 | 2020-12-04 10:17:35 +0800 | [diff] [blame] | 170 | #define LOPT_PXE_VENDOR 361 |
Simon Kelley | b7cf754 | 2021-03-04 16:54:14 +0000 | [diff] [blame] | 171 | #define LOPT_DYNHOST 362 |
Simon Kelley | b260d22 | 2021-03-12 21:57:57 +0000 | [diff] [blame] | 172 | #define LOPT_LOG_DEBUG 363 |
Simon Kelley | bec366b | 2016-02-24 22:03:26 +0000 | [diff] [blame] | 173 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 174 | #ifdef HAVE_GETOPT_LONG |
| 175 | static const struct option opts[] = |
| 176 | #else |
| 177 | static const struct myoption opts[] = |
| 178 | #endif |
| 179 | { |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 180 | { "version", 0, 0, 'v' }, |
| 181 | { "no-hosts", 0, 0, 'h' }, |
| 182 | { "no-poll", 0, 0, 'n' }, |
| 183 | { "help", 0, 0, 'w' }, |
| 184 | { "no-daemon", 0, 0, 'd' }, |
Simon Kelley | 25cf5e3 | 2015-01-09 15:53:03 +0000 | [diff] [blame] | 185 | { "log-queries", 2, 0, 'q' }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 186 | { "user", 2, 0, 'u' }, |
| 187 | { "group", 2, 0, 'g' }, |
| 188 | { "resolv-file", 2, 0, 'r' }, |
Simon Kelley | 7b1eae4 | 2014-02-20 13:43:28 +0000 | [diff] [blame] | 189 | { "servers-file", 1, 0, LOPT_SERVERS_FILE }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 190 | { "mx-host", 1, 0, 'm' }, |
| 191 | { "mx-target", 1, 0, 't' }, |
| 192 | { "cache-size", 2, 0, 'c' }, |
| 193 | { "port", 1, 0, 'p' }, |
| 194 | { "dhcp-leasefile", 2, 0, 'l' }, |
| 195 | { "dhcp-lease", 1, 0, 'l' }, |
| 196 | { "dhcp-host", 1, 0, 'G' }, |
| 197 | { "dhcp-range", 1, 0, 'F' }, |
| 198 | { "dhcp-option", 1, 0, 'O' }, |
| 199 | { "dhcp-boot", 1, 0, 'M' }, |
| 200 | { "domain", 1, 0, 's' }, |
| 201 | { "domain-suffix", 1, 0, 's' }, |
| 202 | { "interface", 1, 0, 'i' }, |
| 203 | { "listen-address", 1, 0, 'a' }, |
Simon Kelley | c8a8048 | 2014-03-05 14:29:54 +0000 | [diff] [blame] | 204 | { "local-service", 0, 0, LOPT_LOCAL_SERVICE }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 205 | { "bogus-priv", 0, 0, 'b' }, |
| 206 | { "bogus-nxdomain", 1, 0, 'B' }, |
Glen Huang | 32fc6db | 2014-12-27 15:28:12 +0000 | [diff] [blame] | 207 | { "ignore-address", 1, 0, LOPT_IGNORE_ADDR }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 208 | { "selfmx", 0, 0, 'e' }, |
| 209 | { "filterwin2k", 0, 0, 'f' }, |
| 210 | { "pid-file", 2, 0, 'x' }, |
| 211 | { "strict-order", 0, 0, 'o' }, |
| 212 | { "server", 1, 0, 'S' }, |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 213 | { "rev-server", 1, 0, LOPT_REV_SERV }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 214 | { "local", 1, 0, LOPT_LOCAL }, |
| 215 | { "address", 1, 0, 'A' }, |
| 216 | { "conf-file", 2, 0, 'C' }, |
| 217 | { "no-resolv", 0, 0, 'R' }, |
| 218 | { "expand-hosts", 0, 0, 'E' }, |
| 219 | { "localmx", 0, 0, 'L' }, |
| 220 | { "local-ttl", 1, 0, 'T' }, |
| 221 | { "no-negcache", 0, 0, 'N' }, |
| 222 | { "addn-hosts", 1, 0, 'H' }, |
Simon Kelley | 70d1873 | 2015-01-31 19:59:29 +0000 | [diff] [blame] | 223 | { "hostsdir", 1, 0, LOPT_HOST_INOTIFY }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 224 | { "query-port", 1, 0, 'Q' }, |
| 225 | { "except-interface", 1, 0, 'I' }, |
| 226 | { "no-dhcp-interface", 1, 0, '2' }, |
| 227 | { "domain-needed", 0, 0, 'D' }, |
| 228 | { "dhcp-lease-max", 1, 0, 'X' }, |
| 229 | { "bind-interfaces", 0, 0, 'z' }, |
| 230 | { "read-ethers", 0, 0, 'Z' }, |
| 231 | { "alias", 1, 0, 'V' }, |
| 232 | { "dhcp-vendorclass", 1, 0, 'U' }, |
| 233 | { "dhcp-userclass", 1, 0, 'j' }, |
| 234 | { "dhcp-ignore", 1, 0, 'J' }, |
| 235 | { "edns-packet-max", 1, 0, 'P' }, |
| 236 | { "keep-in-foreground", 0, 0, 'k' }, |
| 237 | { "dhcp-authoritative", 0, 0, 'K' }, |
| 238 | { "srv-host", 1, 0, 'W' }, |
| 239 | { "localise-queries", 0, 0, 'y' }, |
| 240 | { "txt-record", 1, 0, 'Y' }, |
Simon Kelley | 974a6d0 | 2018-08-23 23:01:16 +0100 | [diff] [blame] | 241 | { "caa-record", 1, 0 , LOPT_CAA }, |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 242 | { "dns-rr", 1, 0, LOPT_RR }, |
Simon Kelley | ad09427 | 2012-08-10 17:10:54 +0100 | [diff] [blame] | 243 | { "enable-dbus", 2, 0, '1' }, |
Oldřich Jedlička | d162bee | 2020-03-20 22:18:57 +0100 | [diff] [blame] | 244 | { "enable-ubus", 2, 0, LOPT_UBUS }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 245 | { "bootp-dynamic", 2, 0, '3' }, |
| 246 | { "dhcp-mac", 1, 0, '4' }, |
| 247 | { "no-ping", 0, 0, '5' }, |
| 248 | { "dhcp-script", 1, 0, '6' }, |
| 249 | { "conf-dir", 1, 0, '7' }, |
| 250 | { "log-facility", 1, 0 ,'8' }, |
| 251 | { "leasefile-ro", 0, 0, '9' }, |
Simon Kelley | ee64582 | 2020-02-27 16:34:14 +0000 | [diff] [blame] | 252 | { "script-on-renewal", 0, 0, LOPT_SCRIPT_TIME}, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 253 | { "dns-forward-max", 1, 0, '0' }, |
| 254 | { "clear-on-reload", 0, 0, LOPT_RELOAD }, |
| 255 | { "dhcp-ignore-names", 2, 0, LOPT_NO_NAMES }, |
Simon Kelley | 2937f8a | 2013-07-29 19:49:07 +0100 | [diff] [blame] | 256 | { "enable-tftp", 2, 0, LOPT_TFTP }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 257 | { "tftp-secure", 0, 0, LOPT_SECURE }, |
Stefan Tomanek | 30d0879 | 2015-03-31 22:32:11 +0100 | [diff] [blame] | 258 | { "tftp-no-fail", 0, 0, LOPT_TFTP_NO_FAIL }, |
Floris Bos | 60704f5 | 2017-04-09 22:22:49 +0100 | [diff] [blame] | 259 | { "tftp-unique-root", 2, 0, LOPT_APREF }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 260 | { "tftp-root", 1, 0, LOPT_PREFIX }, |
| 261 | { "tftp-max", 1, 0, LOPT_TFTP_MAX }, |
Simon Kelley | bec366b | 2016-02-24 22:03:26 +0000 | [diff] [blame] | 262 | { "tftp-mtu", 1, 0, LOPT_TFTP_MTU }, |
Simon Kelley | 61ce600 | 2012-04-20 21:28:49 +0100 | [diff] [blame] | 263 | { "tftp-lowercase", 0, 0, LOPT_TFTP_LC }, |
Simon Kelley | 66f6265 | 2020-01-05 16:21:24 +0000 | [diff] [blame] | 264 | { "tftp-single-port", 0, 0, LOPT_SINGLE_PORT }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 265 | { "ptr-record", 1, 0, LOPT_PTR }, |
| 266 | { "naptr-record", 1, 0, LOPT_NAPTR }, |
| 267 | { "bridge-interface", 1, 0 , LOPT_BRIDGE }, |
Simon Kelley | ae5b7e0 | 2019-03-27 22:33:28 +0000 | [diff] [blame] | 268 | { "shared-network", 1, 0, LOPT_SHARED_NET }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 269 | { "dhcp-option-force", 1, 0, LOPT_FORCE }, |
| 270 | { "tftp-no-blocksize", 0, 0, LOPT_NOBLOCK }, |
| 271 | { "log-dhcp", 0, 0, LOPT_LOG_OPTS }, |
| 272 | { "log-async", 2, 0, LOPT_MAX_LOGS }, |
| 273 | { "dhcp-circuitid", 1, 0, LOPT_CIRCUIT }, |
| 274 | { "dhcp-remoteid", 1, 0, LOPT_REMOTE }, |
| 275 | { "dhcp-subscrid", 1, 0, LOPT_SUBSCR }, |
Wang Shanker | 4ded962 | 2020-12-04 10:17:35 +0800 | [diff] [blame] | 276 | { "dhcp-pxe-vendor", 1, 0, LOPT_PXE_VENDOR }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 277 | { "interface-name", 1, 0, LOPT_INTNAME }, |
| 278 | { "dhcp-hostsfile", 1, 0, LOPT_DHCP_HOST }, |
| 279 | { "dhcp-optsfile", 1, 0, LOPT_DHCP_OPTS }, |
Simon Kelley | 5f4dc5c | 2015-01-20 20:51:02 +0000 | [diff] [blame] | 280 | { "dhcp-hostsdir", 1, 0, LOPT_DHCP_INOTIFY }, |
Simon Kelley | 70d1873 | 2015-01-31 19:59:29 +0000 | [diff] [blame] | 281 | { "dhcp-optsdir", 1, 0, LOPT_DHOPT_INOTIFY }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 282 | { "dhcp-no-override", 0, 0, LOPT_OVERRIDE }, |
| 283 | { "tftp-port-range", 1, 0, LOPT_TFTPPORTS }, |
| 284 | { "stop-dns-rebind", 0, 0, LOPT_REBIND }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 285 | { "rebind-domain-ok", 1, 0, LOPT_NO_REBIND }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 286 | { "all-servers", 0, 0, LOPT_NOLAST }, |
Simon Kelley | c822620 | 2018-08-08 23:46:03 +0100 | [diff] [blame] | 287 | { "dhcp-match", 1, 0, LOPT_MATCH }, |
| 288 | { "dhcp-name-match", 1, 0, LOPT_NAME_MATCH }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 289 | { "dhcp-broadcast", 2, 0, LOPT_BROADCAST }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 290 | { "neg-ttl", 1, 0, LOPT_NEGTTL }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 291 | { "max-ttl", 1, 0, LOPT_MAXTTL }, |
RinSatsuki | 28de387 | 2015-01-10 15:22:21 +0000 | [diff] [blame] | 292 | { "min-cache-ttl", 1, 0, LOPT_MINCTTL }, |
Simon Kelley | 1d86041 | 2012-09-20 20:48:04 +0100 | [diff] [blame] | 293 | { "max-cache-ttl", 1, 0, LOPT_MAXCTTL }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 294 | { "dhcp-alternate-port", 2, 0, LOPT_ALTPORT }, |
| 295 | { "dhcp-scriptuser", 1, 0, LOPT_SCRIPTUSR }, |
| 296 | { "min-port", 1, 0, LOPT_MINPORT }, |
Hans Dedecker | 926332a | 2016-01-23 10:48:12 +0000 | [diff] [blame] | 297 | { "max-port", 1, 0, LOPT_MAXPORT }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 298 | { "dhcp-fqdn", 0, 0, LOPT_DHCP_FQDN }, |
| 299 | { "cname", 1, 0, LOPT_CNAME }, |
| 300 | { "pxe-prompt", 1, 0, LOPT_PXE_PROMT }, |
| 301 | { "pxe-service", 1, 0, LOPT_PXE_SERV }, |
| 302 | { "test", 0, 0, LOPT_TEST }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 303 | { "tag-if", 1, 0, LOPT_TAG_IF }, |
| 304 | { "dhcp-proxy", 2, 0, LOPT_PROXY }, |
| 305 | { "dhcp-generate-names", 2, 0, LOPT_GEN_NAMES }, |
| 306 | { "rebind-localhost-ok", 0, 0, LOPT_LOC_REBND }, |
Simon Kelley | 1e50512 | 2016-01-25 21:29:23 +0000 | [diff] [blame] | 307 | { "add-mac", 2, 0, LOPT_ADD_MAC }, |
Simon Kelley | ed4c076 | 2013-10-08 20:46:34 +0100 | [diff] [blame] | 308 | { "add-subnet", 2, 0, LOPT_ADD_SBNET }, |
Simon Kelley | 1e50512 | 2016-01-25 21:29:23 +0000 | [diff] [blame] | 309 | { "add-cpe-id", 1, 0 , LOPT_CPE_ID }, |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 310 | { "proxy-dnssec", 0, 0, LOPT_DNSSEC }, |
Simon Kelley | 7de060b | 2011-08-26 17:24:52 +0100 | [diff] [blame] | 311 | { "dhcp-sequential-ip", 0, 0, LOPT_INCR_ADDR }, |
| 312 | { "conntrack", 0, 0, LOPT_CONNTRACK }, |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 313 | { "dhcp-client-update", 0, 0, LOPT_FQDN }, |
| 314 | { "dhcp-luascript", 1, 0, LOPT_LUASCRIPT }, |
Simon Kelley | c5ad4e7 | 2012-02-24 16:06:20 +0000 | [diff] [blame] | 315 | { "enable-ra", 0, 0, LOPT_RA }, |
Simon Kelley | 8b37270 | 2012-03-09 17:45:10 +0000 | [diff] [blame] | 316 | { "dhcp-duid", 1, 0, LOPT_DUID }, |
Simon Kelley | e759d42 | 2012-03-16 13:18:57 +0000 | [diff] [blame] | 317 | { "host-record", 1, 0, LOPT_HOST_REC }, |
Simon Kelley | 54dd393 | 2012-06-20 11:23:38 +0100 | [diff] [blame] | 318 | { "bind-dynamic", 0, 0, LOPT_CLVERBIND }, |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 319 | { "auth-zone", 1, 0, LOPT_AUTHZONE }, |
| 320 | { "auth-server", 1, 0, LOPT_AUTHSERV }, |
| 321 | { "auth-ttl", 1, 0, LOPT_AUTHTTL }, |
| 322 | { "auth-soa", 1, 0, LOPT_AUTHSOA }, |
Simon Kelley | e1ff419 | 2012-12-09 17:08:47 +0000 | [diff] [blame] | 323 | { "auth-sec-servers", 1, 0, LOPT_AUTHSFS }, |
Simon Kelley | 4967876 | 2012-12-09 18:24:58 +0000 | [diff] [blame] | 324 | { "auth-peer", 1, 0, LOPT_AUTHPEER }, |
Jason A. Donenfeld | 13d86c7 | 2013-02-22 18:20:53 +0000 | [diff] [blame] | 325 | { "ipset", 1, 0, LOPT_IPSET }, |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 326 | { "synth-domain", 1, 0, LOPT_SYNTH }, |
Giovanni Bajo | 7dbe193 | 2012-04-05 02:50:13 +0200 | [diff] [blame] | 327 | { "dnssec", 0, 0, LOPT_SEC_VALID }, |
Simon Kelley | ee41586 | 2014-02-11 11:07:22 +0000 | [diff] [blame] | 328 | { "trust-anchor", 1, 0, LOPT_TRUST_ANCHOR }, |
Simon Kelley | 5b3bf92 | 2014-01-25 17:03:07 +0000 | [diff] [blame] | 329 | { "dnssec-debug", 0, 0, LOPT_DNSSEC_DEBUG }, |
Simon Kelley | a691853 | 2018-04-15 16:20:52 +0100 | [diff] [blame] | 330 | { "dnssec-check-unsigned", 2, 0, LOPT_DNSSEC_CHECK }, |
Simon Kelley | e98bd52 | 2014-03-28 20:41:23 +0000 | [diff] [blame] | 331 | { "dnssec-no-timecheck", 0, 0, LOPT_DNSSEC_TIME }, |
Simon Kelley | f6e62e2 | 2015-03-01 18:17:54 +0000 | [diff] [blame] | 332 | { "dnssec-timestamp", 1, 0, LOPT_DNSSEC_STAMP }, |
Simon Kelley | ff7eea2 | 2013-09-04 18:01:38 +0100 | [diff] [blame] | 333 | { "dhcp-relay", 1, 0, LOPT_RELAY }, |
Simon Kelley | c4cd95d | 2013-10-10 20:58:11 +0100 | [diff] [blame] | 334 | { "ra-param", 1, 0, LOPT_RA_PARAM }, |
Kevin Darbyshire-Bryant | 8c0b73d | 2013-10-11 11:56:33 +0100 | [diff] [blame] | 335 | { "quiet-dhcp", 0, 0, LOPT_QUIET_DHCP }, |
| 336 | { "quiet-dhcp6", 0, 0, LOPT_QUIET_DHCP6 }, |
| 337 | { "quiet-ra", 0, 0, LOPT_QUIET_RA }, |
Simon Kelley | b5ea1cc | 2014-07-29 16:34:14 +0100 | [diff] [blame] | 338 | { "dns-loop-detect", 0, 0, LOPT_LOOP_DETECT }, |
Simon Kelley | 1e50512 | 2016-01-25 21:29:23 +0000 | [diff] [blame] | 339 | { "script-arp", 0, 0, LOPT_SCRIPT_ARP }, |
Simon Kelley | 832e47b | 2016-02-24 21:24:45 +0000 | [diff] [blame] | 340 | { "dhcp-ttl", 1, 0 , LOPT_DHCPTTL }, |
Floris Bos | 503c609 | 2017-04-09 23:07:13 +0100 | [diff] [blame] | 341 | { "dhcp-reply-delay", 1, 0, LOPT_REPLY_DELAY }, |
Simon Kelley | 734d531 | 2018-03-23 23:09:53 +0000 | [diff] [blame] | 342 | { "dhcp-rapid-commit", 0, 0, LOPT_RAPID_COMMIT }, |
Simon Kelley | 6b17335 | 2018-05-08 18:32:14 +0100 | [diff] [blame] | 343 | { "dumpfile", 1, 0, LOPT_DUMPFILE }, |
| 344 | { "dumpmask", 1, 0, LOPT_DUMPMASK }, |
Florent Fourcot | 13a58f9 | 2019-06-20 10:26:40 +0200 | [diff] [blame] | 345 | { "dhcp-ignore-clid", 0, 0, LOPT_IGNORE_CLID }, |
Simon Kelley | b7cf754 | 2021-03-04 16:54:14 +0000 | [diff] [blame] | 346 | { "dynamic-host", 1, 0, LOPT_DYNHOST }, |
Simon Kelley | b260d22 | 2021-03-12 21:57:57 +0000 | [diff] [blame] | 347 | { "log-debug", 0, 0, LOPT_LOG_DEBUG }, |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 348 | { NULL, 0, 0, 0 } |
| 349 | }; |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 350 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 351 | |
| 352 | #define ARG_DUP OPT_LAST |
| 353 | #define ARG_ONE OPT_LAST + 1 |
| 354 | #define ARG_USED_CL OPT_LAST + 2 |
| 355 | #define ARG_USED_FILE OPT_LAST + 3 |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 356 | |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 357 | static struct { |
| 358 | int opt; |
| 359 | unsigned int rept; |
| 360 | char * const flagdesc; |
Simon Kelley | b8187c8 | 2005-11-26 21:46:27 +0000 | [diff] [blame] | 361 | char * const desc; |
| 362 | char * const arg; |
| 363 | } usage[] = { |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 364 | { 'a', ARG_DUP, "<ipaddr>", gettext_noop("Specify local address(es) to listen on."), NULL }, |
| 365 | { 'A', ARG_DUP, "/<domain>/<ipaddr>", gettext_noop("Return ipaddr for all hosts in specified domains."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 366 | { 'b', OPT_BOGUSPRIV, NULL, gettext_noop("Fake reverse lookups for RFC1918 private address ranges."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 367 | { 'B', ARG_DUP, "<ipaddr>", gettext_noop("Treat ipaddr as NXDOMAIN (defeats Verisign wildcard)."), NULL }, |
| 368 | { 'c', ARG_ONE, "<integer>", gettext_noop("Specify the size of the cache in entries (defaults to %s)."), "$" }, |
| 369 | { 'C', ARG_DUP, "<path>", gettext_noop("Specify configuration file (defaults to %s)."), CONFFILE }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 370 | { 'd', OPT_DEBUG, NULL, gettext_noop("Do NOT fork into the background: run in debug mode."), NULL }, |
| 371 | { 'D', OPT_NODOTS_LOCAL, NULL, gettext_noop("Do NOT forward queries with no domain part."), NULL }, |
| 372 | { 'e', OPT_SELFMX, NULL, gettext_noop("Return self-pointing MX records for local hosts."), NULL }, |
| 373 | { 'E', OPT_EXPAND, NULL, gettext_noop("Expand simple names in /etc/hosts with domain-suffix."), NULL }, |
| 374 | { 'f', OPT_FILTER, NULL, gettext_noop("Don't forward spurious DNS requests from Windows hosts."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 375 | { 'F', ARG_DUP, "<ipaddr>,...", gettext_noop("Enable DHCP in the range given with lease duration."), NULL }, |
| 376 | { 'g', ARG_ONE, "<groupname>", gettext_noop("Change to this group after startup (defaults to %s)."), CHGRP }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 377 | { 'G', ARG_DUP, "<hostspec>", gettext_noop("Set address or hostname for a specified machine."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 378 | { LOPT_DHCP_HOST, ARG_DUP, "<path>", gettext_noop("Read DHCP host specs from file."), NULL }, |
| 379 | { LOPT_DHCP_OPTS, ARG_DUP, "<path>", gettext_noop("Read DHCP option specs from file."), NULL }, |
Simon Kelley | 5f4dc5c | 2015-01-20 20:51:02 +0000 | [diff] [blame] | 380 | { LOPT_DHCP_INOTIFY, ARG_DUP, "<path>", gettext_noop("Read DHCP host specs from a directory."), NULL }, |
Simon Kelley | 70d1873 | 2015-01-31 19:59:29 +0000 | [diff] [blame] | 381 | { LOPT_DHOPT_INOTIFY, ARG_DUP, "<path>", gettext_noop("Read DHCP options from a directory."), NULL }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 382 | { LOPT_TAG_IF, ARG_DUP, "tag-expression", gettext_noop("Evaluate conditional tag expression."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 383 | { 'h', OPT_NO_HOSTS, NULL, gettext_noop("Do NOT load %s file."), HOSTSFILE }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 384 | { 'H', ARG_DUP, "<path>", gettext_noop("Specify a hosts file to be read in addition to %s."), HOSTSFILE }, |
Simon Kelley | 70d1873 | 2015-01-31 19:59:29 +0000 | [diff] [blame] | 385 | { LOPT_HOST_INOTIFY, ARG_DUP, "<path>", gettext_noop("Read hosts files from a directory."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 386 | { 'i', ARG_DUP, "<interface>", gettext_noop("Specify interface(s) to listen on."), NULL }, |
| 387 | { 'I', ARG_DUP, "<interface>", gettext_noop("Specify interface(s) NOT to listen on.") , NULL }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 388 | { 'j', ARG_DUP, "set:<tag>,<class>", gettext_noop("Map DHCP user class to tag."), NULL }, |
| 389 | { LOPT_CIRCUIT, ARG_DUP, "set:<tag>,<circuit>", gettext_noop("Map RFC3046 circuit-id to tag."), NULL }, |
| 390 | { LOPT_REMOTE, ARG_DUP, "set:<tag>,<remote>", gettext_noop("Map RFC3046 remote-id to tag."), NULL }, |
| 391 | { LOPT_SUBSCR, ARG_DUP, "set:<tag>,<remote>", gettext_noop("Map RFC3993 subscriber-id to tag."), NULL }, |
Wang Shanker | 4ded962 | 2020-12-04 10:17:35 +0800 | [diff] [blame] | 392 | { LOPT_PXE_VENDOR, ARG_DUP, "<vendor>[,...]", gettext_noop("Specify vendor class to match for PXE requests."), NULL }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 393 | { 'J', ARG_DUP, "tag:<tag>...", gettext_noop("Don't do DHCP for hosts with tag set."), NULL }, |
| 394 | { LOPT_BROADCAST, ARG_DUP, "[=tag:<tag>...]", gettext_noop("Force broadcast replies for hosts with tag set."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 395 | { 'k', OPT_NO_FORK, NULL, gettext_noop("Do NOT fork into the background, do NOT run in debug mode."), NULL }, |
| 396 | { 'K', OPT_AUTHORITATIVE, NULL, gettext_noop("Assume we are the only DHCP server on the local network."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 397 | { 'l', ARG_ONE, "<path>", gettext_noop("Specify where to store DHCP leases (defaults to %s)."), LEASEFILE }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 398 | { 'L', OPT_LOCALMX, NULL, gettext_noop("Return MX records for local hosts."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 399 | { 'm', ARG_DUP, "<host_name>,<target>,<pref>", gettext_noop("Specify an MX record."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 400 | { 'M', ARG_DUP, "<bootp opts>", gettext_noop("Specify BOOTP options to DHCP server."), NULL }, |
| 401 | { 'n', OPT_NO_POLL, NULL, gettext_noop("Do NOT poll %s file, reload only on SIGHUP."), RESOLVFILE }, |
| 402 | { 'N', OPT_NO_NEG, NULL, gettext_noop("Do NOT cache failed search results."), NULL }, |
| 403 | { 'o', OPT_ORDER, NULL, gettext_noop("Use nameservers strictly in the order given in %s."), RESOLVFILE }, |
| 404 | { 'O', ARG_DUP, "<optspec>", gettext_noop("Specify options to be sent to DHCP clients."), NULL }, |
| 405 | { LOPT_FORCE, ARG_DUP, "<optspec>", gettext_noop("DHCP option sent even if the client does not request it."), NULL}, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 406 | { 'p', ARG_ONE, "<integer>", gettext_noop("Specify port to listen for DNS requests on (defaults to 53)."), NULL }, |
| 407 | { 'P', ARG_ONE, "<integer>", gettext_noop("Maximum supported UDP packet size for EDNS.0 (defaults to %s)."), "*" }, |
Simon Kelley | 25cf5e3 | 2015-01-09 15:53:03 +0000 | [diff] [blame] | 408 | { 'q', ARG_DUP, NULL, gettext_noop("Log DNS queries."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 409 | { 'Q', ARG_ONE, "<integer>", gettext_noop("Force the originating port for upstream DNS queries."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 410 | { 'R', OPT_NO_RESOLV, NULL, gettext_noop("Do NOT read resolv.conf."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 411 | { 'r', ARG_DUP, "<path>", gettext_noop("Specify path to resolv.conf (defaults to %s)."), RESOLVFILE }, |
Simon Kelley | 7b1eae4 | 2014-02-20 13:43:28 +0000 | [diff] [blame] | 412 | { LOPT_SERVERS_FILE, ARG_ONE, "<path>", gettext_noop("Specify path to file with server= options"), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 413 | { 'S', ARG_DUP, "/<domain>/<ipaddr>", gettext_noop("Specify address(es) of upstream servers with optional domains."), NULL }, |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 414 | { LOPT_REV_SERV, ARG_DUP, "<addr>/<prefix>,<ipaddr>", gettext_noop("Specify address of upstream servers for reverse address queries"), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 415 | { LOPT_LOCAL, ARG_DUP, "/<domain>/", gettext_noop("Never forward queries to specified domains."), NULL }, |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 416 | { 's', ARG_DUP, "<domain>[,<range>]", gettext_noop("Specify the domain to be assigned in DHCP leases."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 417 | { 't', ARG_ONE, "<host_name>", gettext_noop("Specify default target in an MX record."), NULL }, |
| 418 | { 'T', ARG_ONE, "<integer>", gettext_noop("Specify time-to-live in seconds for replies from /etc/hosts."), NULL }, |
| 419 | { LOPT_NEGTTL, ARG_ONE, "<integer>", gettext_noop("Specify time-to-live in seconds for negative caching."), NULL }, |
| 420 | { LOPT_MAXTTL, ARG_ONE, "<integer>", gettext_noop("Specify time-to-live in seconds for maximum TTL to send to clients."), NULL }, |
RinSatsuki | 28de387 | 2015-01-10 15:22:21 +0000 | [diff] [blame] | 421 | { LOPT_MAXCTTL, ARG_ONE, "<integer>", gettext_noop("Specify time-to-live ceiling for cache."), NULL }, |
| 422 | { LOPT_MINCTTL, ARG_ONE, "<integer>", gettext_noop("Specify time-to-live floor for cache."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 423 | { 'u', ARG_ONE, "<username>", gettext_noop("Change to this user after startup. (defaults to %s)."), CHUSER }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 424 | { 'U', ARG_DUP, "set:<tag>,<class>", gettext_noop("Map DHCP vendor class to tag."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 425 | { 'v', 0, NULL, gettext_noop("Display dnsmasq version and copyright information."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 426 | { 'V', ARG_DUP, "<ipaddr>,<ipaddr>,<netmask>", gettext_noop("Translate IPv4 addresses from upstream servers."), NULL }, |
| 427 | { 'W', ARG_DUP, "<name>,<target>,...", gettext_noop("Specify a SRV record."), NULL }, |
Simon Kelley | 09217a1 | 2016-05-03 17:04:35 +0100 | [diff] [blame] | 428 | { 'w', 0, NULL, gettext_noop("Display this message. Use --help dhcp or --help dhcp6 for known DHCP options."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 429 | { 'x', ARG_ONE, "<path>", gettext_noop("Specify path of PID file (defaults to %s)."), RUNFILE }, |
| 430 | { 'X', ARG_ONE, "<integer>", gettext_noop("Specify maximum number of DHCP leases (defaults to %s)."), "&" }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 431 | { 'y', OPT_LOCALISE, NULL, gettext_noop("Answer DNS queries based on the interface a query was sent to."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 432 | { 'Y', ARG_DUP, "<name>,<txt>[,<txt]", gettext_noop("Specify TXT DNS record."), NULL }, |
| 433 | { LOPT_PTR, ARG_DUP, "<name>,<target>", gettext_noop("Specify PTR DNS record."), NULL }, |
| 434 | { LOPT_INTNAME, ARG_DUP, "<name>,<interface>", gettext_noop("Give DNS name to IPv4 address of interface."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 435 | { 'z', OPT_NOWILD, NULL, gettext_noop("Bind only to interfaces in use."), NULL }, |
| 436 | { 'Z', OPT_ETHERS, NULL, gettext_noop("Read DHCP static host information from %s."), ETHERSFILE }, |
Simon Kelley | ad09427 | 2012-08-10 17:10:54 +0100 | [diff] [blame] | 437 | { '1', ARG_ONE, "[=<busname>]", gettext_noop("Enable the DBus interface for setting upstream servers, etc."), NULL }, |
Oldřich Jedlička | d162bee | 2020-03-20 22:18:57 +0100 | [diff] [blame] | 438 | { LOPT_UBUS, ARG_ONE, "[=<busname>]", gettext_noop("Enable the UBus interface."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 439 | { '2', ARG_DUP, "<interface>", gettext_noop("Do not provide DHCP on this interface, only provide DNS."), NULL }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 440 | { '3', ARG_DUP, "[=tag:<tag>]...", gettext_noop("Enable dynamic address allocation for bootp."), NULL }, |
| 441 | { '4', ARG_DUP, "set:<tag>,<mac address>", gettext_noop("Map MAC address (with wildcards) to option set."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 442 | { LOPT_BRIDGE, ARG_DUP, "<iface>,<alias>..", gettext_noop("Treat DHCP requests on aliases as arriving from interface."), NULL }, |
Simon Kelley | ae5b7e0 | 2019-03-27 22:33:28 +0000 | [diff] [blame] | 443 | { LOPT_SHARED_NET, ARG_DUP, "<iface>|<addr>,<addr>", gettext_noop("Specify extra networks sharing a broadcast domain for DHCP"), NULL}, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 444 | { '5', OPT_NO_PING, NULL, gettext_noop("Disable ICMP echo address checking in the DHCP server."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 445 | { '6', ARG_ONE, "<path>", gettext_noop("Shell script to run on DHCP lease creation and destruction."), NULL }, |
| 446 | { LOPT_LUASCRIPT, ARG_DUP, "path", gettext_noop("Lua script to run on DHCP lease creation and destruction."), NULL }, |
| 447 | { LOPT_SCRIPTUSR, ARG_ONE, "<username>", gettext_noop("Run lease-change scripts as this user."), NULL }, |
Simon Kelley | 1e50512 | 2016-01-25 21:29:23 +0000 | [diff] [blame] | 448 | { LOPT_SCRIPT_ARP, OPT_SCRIPT_ARP, NULL, gettext_noop("Call dhcp-script with changes to local ARP table."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 449 | { '7', ARG_DUP, "<path>", gettext_noop("Read configuration from all the files in this directory."), NULL }, |
Josh Soref | 730c674 | 2017-02-06 16:14:04 +0000 | [diff] [blame] | 450 | { '8', ARG_ONE, "<facility>|<file>", gettext_noop("Log to this syslog facility or file. (defaults to DAEMON)"), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 451 | { '9', OPT_LEASE_RO, NULL, gettext_noop("Do not use leasefile."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 452 | { '0', ARG_ONE, "<integer>", gettext_noop("Maximum number of concurrent DNS queries. (defaults to %s)"), "!" }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 453 | { LOPT_RELOAD, OPT_RELOAD, NULL, gettext_noop("Clear DNS cache when reloading %s."), RESOLVFILE }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 454 | { LOPT_NO_NAMES, ARG_DUP, "[=tag:<tag>]...", gettext_noop("Ignore hostnames provided by DHCP clients."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 455 | { LOPT_OVERRIDE, OPT_NO_OVERRIDE, NULL, gettext_noop("Do NOT reuse filename and server fields for extra DHCP options."), NULL }, |
Simon Kelley | 2937f8a | 2013-07-29 19:49:07 +0100 | [diff] [blame] | 456 | { LOPT_TFTP, ARG_DUP, "[=<intr>[,<intr>]]", gettext_noop("Enable integrated read-only TFTP server."), NULL }, |
Simon Kelley | 8b3ae2f | 2012-06-13 13:43:49 +0100 | [diff] [blame] | 457 | { LOPT_PREFIX, ARG_DUP, "<dir>[,<iface>]", gettext_noop("Export files by TFTP only from the specified subtree."), NULL }, |
Floris Bos | 60704f5 | 2017-04-09 22:22:49 +0100 | [diff] [blame] | 458 | { LOPT_APREF, ARG_DUP, "[=ip|mac]", gettext_noop("Add client IP or hardware address to tftp-root."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 459 | { LOPT_SECURE, OPT_TFTP_SECURE, NULL, gettext_noop("Allow access only to files owned by the user running dnsmasq."), NULL }, |
Stefan Tomanek | 30d0879 | 2015-03-31 22:32:11 +0100 | [diff] [blame] | 460 | { LOPT_TFTP_NO_FAIL, OPT_TFTP_NO_FAIL, NULL, gettext_noop("Do not terminate the service if TFTP directories are inaccessible."), NULL }, |
Josh Soref | 730c674 | 2017-02-06 16:14:04 +0000 | [diff] [blame] | 461 | { LOPT_TFTP_MAX, ARG_ONE, "<integer>", gettext_noop("Maximum number of concurrent TFTP transfers (defaults to %s)."), "#" }, |
Simon Kelley | bec366b | 2016-02-24 22:03:26 +0000 | [diff] [blame] | 462 | { LOPT_TFTP_MTU, ARG_ONE, "<integer>", gettext_noop("Maximum MTU to use for TFTP transfers."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 463 | { LOPT_NOBLOCK, OPT_TFTP_NOBLOCK, NULL, gettext_noop("Disable the TFTP blocksize extension."), NULL }, |
Simon Kelley | 61ce600 | 2012-04-20 21:28:49 +0100 | [diff] [blame] | 464 | { LOPT_TFTP_LC, OPT_TFTP_LC, NULL, gettext_noop("Convert TFTP filenames to lowercase"), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 465 | { LOPT_TFTPPORTS, ARG_ONE, "<start>,<end>", gettext_noop("Ephemeral port range for use by TFTP transfers."), NULL }, |
Simon Kelley | 66f6265 | 2020-01-05 16:21:24 +0000 | [diff] [blame] | 466 | { LOPT_SINGLE_PORT, OPT_SINGLE_PORT, NULL, gettext_noop("Use only one port for TFTP server."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 467 | { LOPT_LOG_OPTS, OPT_LOG_OPTS, NULL, gettext_noop("Extra logging for DHCP."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 468 | { LOPT_MAX_LOGS, ARG_ONE, "[=<integer>]", gettext_noop("Enable async. logging; optionally set queue length."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 469 | { LOPT_REBIND, OPT_NO_REBIND, NULL, gettext_noop("Stop DNS rebinding. Filter private IP ranges when resolving."), NULL }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 470 | { LOPT_LOC_REBND, OPT_LOCAL_REBIND, NULL, gettext_noop("Allow rebinding of 127.0.0.0/8, for RBL servers."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 471 | { LOPT_NO_REBIND, ARG_DUP, "/<domain>/", gettext_noop("Inhibit DNS-rebind protection on this domain."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 472 | { LOPT_NOLAST, OPT_ALL_SERVERS, NULL, gettext_noop("Always perform DNS queries to all servers."), NULL }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 473 | { LOPT_MATCH, ARG_DUP, "set:<tag>,<optspec>", gettext_noop("Set tag if client includes matching option in request."), NULL }, |
Simon Kelley | c822620 | 2018-08-08 23:46:03 +0100 | [diff] [blame] | 474 | { LOPT_NAME_MATCH, ARG_DUP, "set:<tag>,<string>[*]", gettext_noop("Set tag if client provides given name."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 475 | { LOPT_ALTPORT, ARG_ONE, "[=<ports>]", gettext_noop("Use alternative ports for DHCP."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 476 | { LOPT_NAPTR, ARG_DUP, "<name>,<naptr>", gettext_noop("Specify NAPTR DNS record."), NULL }, |
| 477 | { LOPT_MINPORT, ARG_ONE, "<port>", gettext_noop("Specify lowest port available for DNS query transmission."), NULL }, |
Hans Dedecker | 926332a | 2016-01-23 10:48:12 +0000 | [diff] [blame] | 478 | { LOPT_MAXPORT, ARG_ONE, "<port>", gettext_noop("Specify highest port available for DNS query transmission."), NULL }, |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 479 | { LOPT_DHCP_FQDN, OPT_DHCP_FQDN, NULL, gettext_noop("Use only fully qualified domain names for DHCP clients."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 480 | { LOPT_GEN_NAMES, ARG_DUP, "[=tag:<tag>]", gettext_noop("Generate hostnames based on MAC address for nameless clients."), NULL}, |
| 481 | { LOPT_PROXY, ARG_DUP, "[=<ipaddr>]...", gettext_noop("Use these DHCP relays as full proxies."), NULL }, |
Peter Wu | 3c0c111 | 2016-08-28 20:53:09 +0100 | [diff] [blame] | 482 | { LOPT_RELAY, ARG_DUP, "<local-addr>,<server>[,<iface>]", gettext_noop("Relay DHCP requests to a remote server"), NULL}, |
Simon Kelley | df3d54f | 2016-02-24 21:03:38 +0000 | [diff] [blame] | 483 | { LOPT_CNAME, ARG_DUP, "<alias>,<target>[,<ttl>]", gettext_noop("Specify alias name for LOCAL DNS name."), NULL }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 484 | { LOPT_PXE_PROMT, ARG_DUP, "<prompt>,[<timeout>]", gettext_noop("Prompt to send to PXE clients."), NULL }, |
| 485 | { LOPT_PXE_SERV, ARG_DUP, "<service>", gettext_noop("Boot service for PXE menu."), NULL }, |
| 486 | { LOPT_TEST, 0, NULL, gettext_noop("Check configuration syntax."), NULL }, |
Simon Kelley | 22c0f4f | 2016-02-17 22:12:31 +0000 | [diff] [blame] | 487 | { LOPT_ADD_MAC, ARG_DUP, "[=base64|text]", gettext_noop("Add requestor's MAC address to forwarded DNS queries."), NULL }, |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 488 | { LOPT_ADD_SBNET, ARG_ONE, "<v4 pref>[,<v6 pref>]", gettext_noop("Add specified IP subnet to forwarded DNS queries."), NULL }, |
Simon Kelley | df3d54f | 2016-02-24 21:03:38 +0000 | [diff] [blame] | 489 | { LOPT_CPE_ID, ARG_ONE, "<text>", gettext_noop("Add client identification to forwarded DNS queries."), NULL }, |
Simon Kelley | 5a4120d | 2013-10-25 13:13:11 +0100 | [diff] [blame] | 490 | { LOPT_DNSSEC, OPT_DNSSEC_PROXY, NULL, gettext_noop("Proxy DNSSEC validation results from upstream nameservers."), NULL }, |
Simon Kelley | 7de060b | 2011-08-26 17:24:52 +0100 | [diff] [blame] | 491 | { LOPT_INCR_ADDR, OPT_CONSEC_ADDR, NULL, gettext_noop("Attempt to allocate sequential IP addresses to DHCP clients."), NULL }, |
Florent Fourcot | 13a58f9 | 2019-06-20 10:26:40 +0200 | [diff] [blame] | 492 | { LOPT_IGNORE_CLID, OPT_IGNORE_CLID, NULL, gettext_noop("Ignore client identifier option sent by DHCP clients."), NULL }, |
Simon Kelley | 7de060b | 2011-08-26 17:24:52 +0100 | [diff] [blame] | 493 | { LOPT_CONNTRACK, OPT_CONNTRACK, NULL, gettext_noop("Copy connection-track mark from queries to upstream connections."), NULL }, |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 494 | { LOPT_FQDN, OPT_FQDN_UPDATE, NULL, gettext_noop("Allow DHCP clients to do their own DDNS updates."), NULL }, |
Simon Kelley | c5ad4e7 | 2012-02-24 16:06:20 +0000 | [diff] [blame] | 495 | { LOPT_RA, OPT_RA, NULL, gettext_noop("Send router-advertisements for interfaces doing DHCPv6"), NULL }, |
Simon Kelley | 8b37270 | 2012-03-09 17:45:10 +0000 | [diff] [blame] | 496 | { LOPT_DUID, ARG_ONE, "<enterprise>,<duid>", gettext_noop("Specify DUID_EN-type DHCPv6 server DUID"), NULL }, |
Simon Kelley | df3d54f | 2016-02-24 21:03:38 +0000 | [diff] [blame] | 497 | { LOPT_HOST_REC, ARG_DUP, "<name>,<address>[,<ttl>]", gettext_noop("Specify host (A/AAAA and PTR) records"), NULL }, |
Simon Kelley | b7cf754 | 2021-03-04 16:54:14 +0000 | [diff] [blame] | 498 | { LOPT_DYNHOST, ARG_DUP, "<name>,[<IPv4>][,<IPv6>],<interface-name>", gettext_noop("Specify host record in interface subnet"), NULL }, |
Simon Kelley | 974a6d0 | 2018-08-23 23:01:16 +0100 | [diff] [blame] | 499 | { LOPT_CAA, ARG_DUP, "<name>,<flags>,<tag>,<value>", gettext_noop("Specify certification authority authorization record"), NULL }, |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 500 | { LOPT_RR, ARG_DUP, "<name>,<RR-number>,[<data>]", gettext_noop("Specify arbitrary DNS resource record"), NULL }, |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 501 | { LOPT_CLVERBIND, OPT_CLEVERBIND, NULL, gettext_noop("Bind to interfaces in use - check for new interfaces"), NULL }, |
Simon Kelley | 86e3b9a | 2012-11-30 13:46:48 +0000 | [diff] [blame] | 502 | { LOPT_AUTHSERV, ARG_ONE, "<NS>,<interface>", gettext_noop("Export local names to global DNS"), NULL }, |
Simon Kelley | 333b2ce | 2013-01-07 21:46:03 +0000 | [diff] [blame] | 503 | { LOPT_AUTHZONE, ARG_DUP, "<domain>,[<subnet>...]", gettext_noop("Domain to export to global DNS"), NULL }, |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 504 | { LOPT_AUTHTTL, ARG_ONE, "<integer>", gettext_noop("Set TTL for authoritative replies"), NULL }, |
Josh Soref | 730c674 | 2017-02-06 16:14:04 +0000 | [diff] [blame] | 505 | { LOPT_AUTHSOA, ARG_ONE, "<serial>[,...]", gettext_noop("Set authoritative zone information"), NULL }, |
Simon Kelley | 4967876 | 2012-12-09 18:24:58 +0000 | [diff] [blame] | 506 | { LOPT_AUTHSFS, ARG_DUP, "<NS>[,<NS>...]", gettext_noop("Secondary authoritative nameservers for forward domains"), NULL }, |
| 507 | { LOPT_AUTHPEER, ARG_DUP, "<ipaddr>[,<ipaddr>...]", gettext_noop("Peers which are allowed to do zone transfer"), NULL }, |
Peter Wu | 3c0c111 | 2016-08-28 20:53:09 +0100 | [diff] [blame] | 508 | { LOPT_IPSET, ARG_DUP, "/<domain>[/<domain>...]/<ipset>...", gettext_noop("Specify ipsets to which matching domains should be added"), NULL }, |
Gildas | a9bf81a | 2013-10-24 13:31:40 +0100 | [diff] [blame] | 509 | { LOPT_SYNTH, ARG_DUP, "<domain>,<range>,[<prefix>]", gettext_noop("Specify a domain and address range for synthesised names"), NULL }, |
Simon Kelley | 3a23715 | 2013-12-12 12:15:50 +0000 | [diff] [blame] | 510 | { LOPT_SEC_VALID, OPT_DNSSEC_VALID, NULL, gettext_noop("Activate DNSSEC validation"), NULL }, |
Simon Kelley | ee41586 | 2014-02-11 11:07:22 +0000 | [diff] [blame] | 511 | { LOPT_TRUST_ANCHOR, ARG_DUP, "<domain>,[<class>],...", gettext_noop("Specify trust anchor key digest."), NULL }, |
Simon Kelley | 5b3bf92 | 2014-01-25 17:03:07 +0000 | [diff] [blame] | 512 | { LOPT_DNSSEC_DEBUG, OPT_DNSSEC_DEBUG, NULL, gettext_noop("Disable upstream checking for DNSSEC debugging."), NULL }, |
Simon Kelley | a691853 | 2018-04-15 16:20:52 +0100 | [diff] [blame] | 513 | { LOPT_DNSSEC_CHECK, ARG_DUP, NULL, gettext_noop("Ensure answers without DNSSEC are in unsigned zones."), NULL }, |
Simon Kelley | e98bd52 | 2014-03-28 20:41:23 +0000 | [diff] [blame] | 514 | { LOPT_DNSSEC_TIME, OPT_DNSSEC_TIME, NULL, gettext_noop("Don't check DNSSEC signature timestamps until first cache-reload"), NULL }, |
Simon Kelley | f6e62e2 | 2015-03-01 18:17:54 +0000 | [diff] [blame] | 515 | { LOPT_DNSSEC_STAMP, ARG_ONE, "<path>", gettext_noop("Timestamp file to verify system clock for DNSSEC"), NULL }, |
Vladislav Grishenko | 6ec5f5c | 2017-04-24 22:34:45 +0100 | [diff] [blame] | 516 | { LOPT_RA_PARAM, ARG_DUP, "<iface>,[mtu:<value>|<interface>|off,][<prio>,]<intval>[,<lifetime>]", gettext_noop("Set MTU, priority, resend-interval and router-lifetime"), NULL }, |
Kevin Darbyshire-Bryant | 8c0b73d | 2013-10-11 11:56:33 +0100 | [diff] [blame] | 517 | { LOPT_QUIET_DHCP, OPT_QUIET_DHCP, NULL, gettext_noop("Do not log routine DHCP."), NULL }, |
| 518 | { LOPT_QUIET_DHCP6, OPT_QUIET_DHCP6, NULL, gettext_noop("Do not log routine DHCPv6."), NULL }, |
| 519 | { LOPT_QUIET_RA, OPT_QUIET_RA, NULL, gettext_noop("Do not log RA."), NULL }, |
Simon Kelley | b260d22 | 2021-03-12 21:57:57 +0000 | [diff] [blame] | 520 | { LOPT_LOG_DEBUG, OPT_LOG_DEBUG, NULL, gettext_noop("Log debugging information."), NULL }, |
Simon Kelley | 832e47b | 2016-02-24 21:24:45 +0000 | [diff] [blame] | 521 | { LOPT_LOCAL_SERVICE, OPT_LOCAL_SERVICE, NULL, gettext_noop("Accept queries only from directly-connected networks."), NULL }, |
| 522 | { LOPT_LOOP_DETECT, OPT_LOOP_DETECT, NULL, gettext_noop("Detect and remove DNS forwarding loops."), NULL }, |
Glen Huang | 32fc6db | 2014-12-27 15:28:12 +0000 | [diff] [blame] | 523 | { LOPT_IGNORE_ADDR, ARG_DUP, "<ipaddr>", gettext_noop("Ignore DNS responses containing ipaddr."), NULL }, |
Simon Kelley | 832e47b | 2016-02-24 21:24:45 +0000 | [diff] [blame] | 524 | { LOPT_DHCPTTL, ARG_ONE, "<ttl>", gettext_noop("Set TTL in DNS responses with DHCP-derived addresses."), NULL }, |
Floris Bos | 503c609 | 2017-04-09 23:07:13 +0100 | [diff] [blame] | 525 | { LOPT_REPLY_DELAY, ARG_ONE, "<integer>", gettext_noop("Delay DHCP replies for at least number of seconds."), NULL }, |
Simon Kelley | 734d531 | 2018-03-23 23:09:53 +0000 | [diff] [blame] | 526 | { LOPT_RAPID_COMMIT, OPT_RAPID_COMMIT, NULL, gettext_noop("Enables DHCPv4 Rapid Commit option."), NULL }, |
Simon Kelley | 6b17335 | 2018-05-08 18:32:14 +0100 | [diff] [blame] | 527 | { LOPT_DUMPFILE, ARG_ONE, "<path>", gettext_noop("Path to debug packet dump file"), NULL }, |
| 528 | { LOPT_DUMPMASK, ARG_ONE, "<hex>", gettext_noop("Mask which packets to dump"), NULL }, |
Simon Kelley | ee64582 | 2020-02-27 16:34:14 +0000 | [diff] [blame] | 529 | { LOPT_SCRIPT_TIME, OPT_LEASE_RENEW, NULL, gettext_noop("Call dhcp-script when lease expiry changes."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 530 | { 0, 0, NULL, NULL, NULL } |
Simon Kelley | b8187c8 | 2005-11-26 21:46:27 +0000 | [diff] [blame] | 531 | }; |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 532 | |
Josh Soref | 730c674 | 2017-02-06 16:14:04 +0000 | [diff] [blame] | 533 | /* We hide metacharacters in quoted strings by mapping them into the ASCII control |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 534 | character space. Note that the \0, \t \b \r \033 and \n characters are carefully placed in the |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 535 | following sequence so that they map to themselves: it is therefore possible to call |
| 536 | unhide_metas repeatedly on string without breaking things. |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 537 | The transformation gets undone by opt_canonicalise, atoi_check and opt_string_alloc, and a |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 538 | couple of other places. |
| 539 | Note that space is included here so that |
| 540 | --dhcp-option=3, string |
| 541 | has five characters, whilst |
| 542 | --dhcp-option=3," string" |
| 543 | has six. |
| 544 | */ |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 545 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 546 | static const char meta[] = "\000123456 \b\t\n78\r90abcdefABCDE\033F:,."; |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 547 | |
| 548 | static char hide_meta(char c) |
| 549 | { |
| 550 | unsigned int i; |
| 551 | |
| 552 | for (i = 0; i < (sizeof(meta) - 1); i++) |
| 553 | if (c == meta[i]) |
| 554 | return (char)i; |
| 555 | |
| 556 | return c; |
| 557 | } |
| 558 | |
| 559 | static char unhide_meta(char cr) |
| 560 | { |
| 561 | unsigned int c = cr; |
| 562 | |
| 563 | if (c < (sizeof(meta) - 1)) |
| 564 | cr = meta[c]; |
| 565 | |
| 566 | return cr; |
| 567 | } |
| 568 | |
| 569 | static void unhide_metas(char *cp) |
| 570 | { |
| 571 | if (cp) |
| 572 | for(; *cp; cp++) |
| 573 | *cp = unhide_meta(*cp); |
| 574 | } |
| 575 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 576 | static void *opt_malloc(size_t size) |
| 577 | { |
| 578 | void *ret; |
| 579 | |
| 580 | if (mem_recover) |
| 581 | { |
| 582 | ret = whine_malloc(size); |
| 583 | if (!ret) |
| 584 | longjmp(mem_jmp, 1); |
| 585 | } |
| 586 | else |
| 587 | ret = safe_malloc(size); |
| 588 | |
| 589 | return ret; |
| 590 | } |
| 591 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 592 | static char *opt_string_alloc(const char *cp) |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 593 | { |
| 594 | char *ret = NULL; |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 595 | size_t len; |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 596 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 597 | if (cp && (len = strlen(cp)) != 0) |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 598 | { |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 599 | ret = opt_malloc(len+1); |
| 600 | memcpy(ret, cp, len+1); |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 601 | |
| 602 | /* restore hidden metachars */ |
| 603 | unhide_metas(ret); |
| 604 | } |
| 605 | |
| 606 | return ret; |
| 607 | } |
| 608 | |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 609 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 610 | /* find next comma, split string with zero and eliminate spaces. |
| 611 | return start of string following comma */ |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 612 | |
| 613 | static char *split_chr(char *s, char c) |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 614 | { |
| 615 | char *comma, *p; |
| 616 | |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 617 | if (!s || !(comma = strchr(s, c))) |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 618 | return NULL; |
| 619 | |
| 620 | p = comma; |
| 621 | *comma = ' '; |
| 622 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 623 | for (; *comma == ' '; comma++); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 624 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 625 | for (; (p >= s) && *p == ' '; p--) |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 626 | *p = 0; |
| 627 | |
| 628 | return comma; |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 629 | } |
| 630 | |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 631 | static char *split(char *s) |
| 632 | { |
| 633 | return split_chr(s, ','); |
| 634 | } |
| 635 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 636 | static char *canonicalise_opt(char *s) |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 637 | { |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 638 | char *ret; |
| 639 | int nomem; |
| 640 | |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 641 | if (!s) |
| 642 | return 0; |
| 643 | |
| 644 | unhide_metas(s); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 645 | if (!(ret = canonicalise(s, &nomem)) && nomem) |
| 646 | { |
| 647 | if (mem_recover) |
| 648 | longjmp(mem_jmp, 1); |
| 649 | else |
| 650 | die(_("could not get memory"), NULL, EC_NOMEM); |
| 651 | } |
| 652 | |
| 653 | return ret; |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | static int atoi_check(char *a, int *res) |
| 657 | { |
| 658 | char *p; |
| 659 | |
| 660 | if (!a) |
| 661 | return 0; |
| 662 | |
| 663 | unhide_metas(a); |
| 664 | |
| 665 | for (p = a; *p; p++) |
| 666 | if (*p < '0' || *p > '9') |
| 667 | return 0; |
| 668 | |
| 669 | *res = atoi(a); |
| 670 | return 1; |
| 671 | } |
| 672 | |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 673 | static int atoi_check16(char *a, int *res) |
| 674 | { |
| 675 | if (!(atoi_check(a, res)) || |
| 676 | *res < 0 || |
| 677 | *res > 0xffff) |
| 678 | return 0; |
| 679 | |
| 680 | return 1; |
| 681 | } |
Simon Kelley | ee41586 | 2014-02-11 11:07:22 +0000 | [diff] [blame] | 682 | |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 683 | #ifdef HAVE_DNSSEC |
Simon Kelley | ee41586 | 2014-02-11 11:07:22 +0000 | [diff] [blame] | 684 | static int atoi_check8(char *a, int *res) |
| 685 | { |
| 686 | if (!(atoi_check(a, res)) || |
| 687 | *res < 0 || |
| 688 | *res > 0xff) |
| 689 | return 0; |
| 690 | |
| 691 | return 1; |
| 692 | } |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 693 | #endif |
Kevin Darbyshire-Bryant | 7ac9ae1 | 2016-09-09 20:52:08 +0100 | [diff] [blame] | 694 | |
| 695 | #ifndef NO_ID |
Simon Kelley | fec216d | 2014-03-27 20:54:34 +0000 | [diff] [blame] | 696 | static void add_txt(char *name, char *txt, int stat) |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 697 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 698 | struct txt_record *r = opt_malloc(sizeof(struct txt_record)); |
Simon Kelley | fec216d | 2014-03-27 20:54:34 +0000 | [diff] [blame] | 699 | |
| 700 | if (txt) |
| 701 | { |
| 702 | size_t len = strlen(txt); |
| 703 | r->txt = opt_malloc(len+1); |
| 704 | r->len = len+1; |
| 705 | *(r->txt) = len; |
| 706 | memcpy((r->txt)+1, txt, len); |
| 707 | } |
Kevin Darbyshire-Bryant | 7ac9ae1 | 2016-09-09 20:52:08 +0100 | [diff] [blame] | 708 | |
Simon Kelley | fec216d | 2014-03-27 20:54:34 +0000 | [diff] [blame] | 709 | r->stat = stat; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 710 | r->name = opt_string_alloc(name); |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 711 | r->next = daemon->txt; |
| 712 | daemon->txt = r; |
| 713 | r->class = C_CHAOS; |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 714 | } |
Kevin Darbyshire-Bryant | 7ac9ae1 | 2016-09-09 20:52:08 +0100 | [diff] [blame] | 715 | #endif |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 716 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 717 | static void do_usage(void) |
| 718 | { |
| 719 | char buff[100]; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 720 | int i, j; |
| 721 | |
| 722 | struct { |
| 723 | char handle; |
| 724 | int val; |
| 725 | } tab[] = { |
| 726 | { '$', CACHESIZ }, |
| 727 | { '*', EDNS_PKTSZ }, |
| 728 | { '&', MAXLEASES }, |
| 729 | { '!', FTABSIZ }, |
| 730 | { '#', TFTP_MAX_CONNECTIONS }, |
| 731 | { '\0', 0 } |
| 732 | }; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 733 | |
| 734 | printf(_("Usage: dnsmasq [options]\n\n")); |
| 735 | #ifndef HAVE_GETOPT_LONG |
| 736 | printf(_("Use short options only on the command line.\n")); |
| 737 | #endif |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 738 | printf(_("Valid options are:\n")); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 739 | |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 740 | for (i = 0; usage[i].opt != 0; i++) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 741 | { |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 742 | char *desc = usage[i].flagdesc; |
| 743 | char *eq = "="; |
| 744 | |
| 745 | if (!desc || *desc == '[') |
| 746 | eq = ""; |
| 747 | |
| 748 | if (!desc) |
| 749 | desc = ""; |
| 750 | |
| 751 | for ( j = 0; opts[j].name; j++) |
| 752 | if (opts[j].val == usage[i].opt) |
| 753 | break; |
| 754 | if (usage[i].opt < 256) |
| 755 | sprintf(buff, "-%c, ", usage[i].opt); |
| 756 | else |
| 757 | sprintf(buff, " "); |
| 758 | |
| 759 | sprintf(buff+4, "--%s%s%s", opts[j].name, eq, desc); |
Peter Wu | 3c0c111 | 2016-08-28 20:53:09 +0100 | [diff] [blame] | 760 | printf("%-55.55s", buff); |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 761 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 762 | if (usage[i].arg) |
| 763 | { |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 764 | strcpy(buff, usage[i].arg); |
| 765 | for (j = 0; tab[j].handle; j++) |
| 766 | if (tab[j].handle == *(usage[i].arg)) |
| 767 | sprintf(buff, "%d", tab[j].val); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 768 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 769 | printf(_(usage[i].desc), buff); |
| 770 | printf("\n"); |
| 771 | } |
| 772 | } |
| 773 | |
Simon Kelley | c740e4f | 2012-08-09 16:19:01 +0100 | [diff] [blame] | 774 | #define ret_err(x) do { strcpy(errstr, (x)); return 0; } while (0) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 775 | #define ret_err_free(x,m) do { strcpy(errstr, (x)); free((m)); return 0; } while (0) |
| 776 | #define goto_err(x) do { strcpy(errstr, (x)); goto on_error; } while (0) |
Simon Kelley | c740e4f | 2012-08-09 16:19:01 +0100 | [diff] [blame] | 777 | |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 778 | static char *parse_mysockaddr(char *arg, union mysockaddr *addr) |
| 779 | { |
| 780 | if (inet_pton(AF_INET, arg, &addr->in.sin_addr) > 0) |
| 781 | addr->sa.sa_family = AF_INET; |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 782 | else if (inet_pton(AF_INET6, arg, &addr->in6.sin6_addr) > 0) |
| 783 | addr->sa.sa_family = AF_INET6; |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 784 | else |
| 785 | return _("bad address"); |
| 786 | |
| 787 | return NULL; |
| 788 | } |
| 789 | |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 790 | char *parse_server(char *arg, union mysockaddr *addr, union mysockaddr *source_addr, char *interface, int *flags) |
| 791 | { |
| 792 | int source_port = 0, serv_port = NAMESERVER_PORT; |
| 793 | char *portno, *source; |
Kristian Evensen | 4e7694d | 2017-03-22 21:32:50 +0000 | [diff] [blame] | 794 | char *interface_opt = NULL; |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 795 | int scope_index = 0; |
| 796 | char *scope_id; |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 797 | |
Simon Kelley | d68c2ca | 2014-02-18 22:30:30 +0000 | [diff] [blame] | 798 | if (!arg || strlen(arg) == 0) |
| 799 | { |
| 800 | *flags |= SERV_NO_ADDR; |
| 801 | *interface = 0; |
| 802 | return NULL; |
| 803 | } |
| 804 | |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 805 | if ((source = split_chr(arg, '@')) && /* is there a source. */ |
| 806 | (portno = split_chr(source, '#')) && |
| 807 | !atoi_check16(portno, &source_port)) |
| 808 | return _("bad port"); |
| 809 | |
| 810 | if ((portno = split_chr(arg, '#')) && /* is there a port no. */ |
| 811 | !atoi_check16(portno, &serv_port)) |
| 812 | return _("bad port"); |
| 813 | |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 814 | scope_id = split_chr(arg, '%'); |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 815 | |
Kristian Evensen | 4e7694d | 2017-03-22 21:32:50 +0000 | [diff] [blame] | 816 | if (source) { |
| 817 | interface_opt = split_chr(source, '@'); |
| 818 | |
| 819 | if (interface_opt) |
| 820 | { |
| 821 | #if defined(SO_BINDTODEVICE) |
Petr Menšík | 47b45b2 | 2018-08-15 18:17:00 +0200 | [diff] [blame] | 822 | safe_strncpy(interface, interface_opt, IF_NAMESIZE); |
Kristian Evensen | 4e7694d | 2017-03-22 21:32:50 +0000 | [diff] [blame] | 823 | #else |
| 824 | return _("interface binding not supported"); |
| 825 | #endif |
| 826 | } |
| 827 | } |
| 828 | |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 829 | if (inet_pton(AF_INET, arg, &addr->in.sin_addr) > 0) |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 830 | { |
| 831 | addr->in.sin_port = htons(serv_port); |
| 832 | addr->sa.sa_family = source_addr->sa.sa_family = AF_INET; |
| 833 | #ifdef HAVE_SOCKADDR_SA_LEN |
| 834 | source_addr->in.sin_len = addr->in.sin_len = sizeof(struct sockaddr_in); |
| 835 | #endif |
| 836 | source_addr->in.sin_addr.s_addr = INADDR_ANY; |
| 837 | source_addr->in.sin_port = htons(daemon->query_port); |
| 838 | |
| 839 | if (source) |
| 840 | { |
| 841 | if (flags) |
| 842 | *flags |= SERV_HAS_SOURCE; |
| 843 | source_addr->in.sin_port = htons(source_port); |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 844 | if (!(inet_pton(AF_INET, source, &source_addr->in.sin_addr) > 0)) |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 845 | { |
| 846 | #if defined(SO_BINDTODEVICE) |
Kristian Evensen | 4e7694d | 2017-03-22 21:32:50 +0000 | [diff] [blame] | 847 | if (interface_opt) |
| 848 | return _("interface can only be specified once"); |
| 849 | |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 850 | source_addr->in.sin_addr.s_addr = INADDR_ANY; |
Petr Menšík | 47b45b2 | 2018-08-15 18:17:00 +0200 | [diff] [blame] | 851 | safe_strncpy(interface, source, IF_NAMESIZE); |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 852 | #else |
| 853 | return _("interface binding not supported"); |
| 854 | #endif |
| 855 | } |
| 856 | } |
| 857 | } |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 858 | else if (inet_pton(AF_INET6, arg, &addr->in6.sin6_addr) > 0) |
| 859 | { |
| 860 | if (scope_id && (scope_index = if_nametoindex(scope_id)) == 0) |
| 861 | return _("bad interface name"); |
| 862 | |
| 863 | addr->in6.sin6_port = htons(serv_port); |
| 864 | addr->in6.sin6_scope_id = scope_index; |
| 865 | source_addr->in6.sin6_addr = in6addr_any; |
| 866 | source_addr->in6.sin6_port = htons(daemon->query_port); |
| 867 | source_addr->in6.sin6_scope_id = 0; |
| 868 | addr->sa.sa_family = source_addr->sa.sa_family = AF_INET6; |
| 869 | addr->in6.sin6_flowinfo = source_addr->in6.sin6_flowinfo = 0; |
| 870 | #ifdef HAVE_SOCKADDR_SA_LEN |
| 871 | addr->in6.sin6_len = source_addr->in6.sin6_len = sizeof(addr->in6); |
| 872 | #endif |
| 873 | if (source) |
| 874 | { |
| 875 | if (flags) |
| 876 | *flags |= SERV_HAS_SOURCE; |
| 877 | source_addr->in6.sin6_port = htons(source_port); |
| 878 | if (inet_pton(AF_INET6, source, &source_addr->in6.sin6_addr) == 0) |
| 879 | { |
| 880 | #if defined(SO_BINDTODEVICE) |
Kristian Evensen | 4e7694d | 2017-03-22 21:32:50 +0000 | [diff] [blame] | 881 | if (interface_opt) |
| 882 | return _("interface can only be specified once"); |
| 883 | |
| 884 | source_addr->in6.sin6_addr = in6addr_any; |
Petr Menšík | 47b45b2 | 2018-08-15 18:17:00 +0200 | [diff] [blame] | 885 | safe_strncpy(interface, source, IF_NAMESIZE); |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 886 | #else |
| 887 | return _("interface binding not supported"); |
| 888 | #endif |
| 889 | } |
| 890 | } |
| 891 | } |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 892 | else |
| 893 | return _("bad address"); |
| 894 | |
| 895 | return NULL; |
| 896 | } |
| 897 | |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 898 | static struct server *add_rev4(struct in_addr addr, int msize) |
| 899 | { |
| 900 | struct server *serv = opt_malloc(sizeof(struct server)); |
Olivier Gayot | 916959c | 2017-03-06 22:14:50 +0000 | [diff] [blame] | 901 | in_addr_t a = ntohl(addr.s_addr); |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 902 | char *p; |
| 903 | |
| 904 | memset(serv, 0, sizeof(struct server)); |
Olivier Gayot | 916959c | 2017-03-06 22:14:50 +0000 | [diff] [blame] | 905 | p = serv->domain = opt_malloc(29); /* strlen("xxx.yyy.zzz.ttt.in-addr.arpa")+1 */ |
| 906 | |
| 907 | switch (msize) |
| 908 | { |
| 909 | case 32: |
Rosen Penev | cbd29e5 | 2017-06-27 22:29:51 +0100 | [diff] [blame] | 910 | p += sprintf(p, "%u.", a & 0xff); |
Olivier Gayot | 916959c | 2017-03-06 22:14:50 +0000 | [diff] [blame] | 911 | /* fall through */ |
| 912 | case 24: |
| 913 | p += sprintf(p, "%d.", (a >> 8) & 0xff); |
| 914 | /* fall through */ |
Olivier Gayot | 916959c | 2017-03-06 22:14:50 +0000 | [diff] [blame] | 915 | case 16: |
| 916 | p += sprintf(p, "%d.", (a >> 16) & 0xff); |
| 917 | /* fall through */ |
| 918 | case 8: |
| 919 | p += sprintf(p, "%d.", (a >> 24) & 0xff); |
| 920 | break; |
Olivier Gayot | dc99058 | 2017-03-06 22:17:21 +0000 | [diff] [blame] | 921 | default: |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 922 | free(serv->domain); |
| 923 | free(serv); |
Olivier Gayot | dc99058 | 2017-03-06 22:17:21 +0000 | [diff] [blame] | 924 | return NULL; |
Olivier Gayot | 916959c | 2017-03-06 22:14:50 +0000 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | p += sprintf(p, "in-addr.arpa"); |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 928 | |
| 929 | serv->flags = SERV_HAS_DOMAIN; |
| 930 | serv->next = daemon->servers; |
| 931 | daemon->servers = serv; |
| 932 | |
| 933 | return serv; |
| 934 | |
| 935 | } |
| 936 | |
| 937 | static struct server *add_rev6(struct in6_addr *addr, int msize) |
| 938 | { |
| 939 | struct server *serv = opt_malloc(sizeof(struct server)); |
| 940 | char *p; |
| 941 | int i; |
| 942 | |
| 943 | memset(serv, 0, sizeof(struct server)); |
| 944 | p = serv->domain = opt_malloc(73); /* strlen("32*<n.>ip6.arpa")+1 */ |
| 945 | |
| 946 | for (i = msize-1; i >= 0; i -= 4) |
| 947 | { |
| 948 | int dig = ((unsigned char *)addr)[i>>3]; |
| 949 | p += sprintf(p, "%.1x.", (i>>2) & 1 ? dig & 15 : dig >> 4); |
| 950 | } |
| 951 | p += sprintf(p, "ip6.arpa"); |
| 952 | |
| 953 | serv->flags = SERV_HAS_DOMAIN; |
| 954 | serv->next = daemon->servers; |
| 955 | daemon->servers = serv; |
| 956 | |
| 957 | return serv; |
| 958 | } |
| 959 | |
Simon Kelley | b5a8dd1 | 2012-12-10 11:37:25 +0000 | [diff] [blame] | 960 | #ifdef HAVE_DHCP |
| 961 | |
| 962 | static int is_tag_prefix(char *arg) |
| 963 | { |
| 964 | if (arg && (strstr(arg, "net:") == arg || strstr(arg, "tag:") == arg)) |
| 965 | return 1; |
| 966 | |
| 967 | return 0; |
| 968 | } |
| 969 | |
| 970 | static char *set_prefix(char *arg) |
| 971 | { |
| 972 | if (strstr(arg, "set:") == arg) |
| 973 | return arg+4; |
| 974 | |
| 975 | return arg; |
| 976 | } |
| 977 | |
Simon Kelley | 52ec783 | 2020-02-07 21:05:54 +0000 | [diff] [blame] | 978 | static struct dhcp_netid *dhcp_netid_create(const char *net, struct dhcp_netid *next) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 979 | { |
| 980 | struct dhcp_netid *tt; |
| 981 | tt = opt_malloc(sizeof (struct dhcp_netid)); |
| 982 | tt->net = opt_string_alloc(net); |
| 983 | tt->next = next; |
| 984 | return tt; |
| 985 | } |
| 986 | |
| 987 | static void dhcp_netid_free(struct dhcp_netid *nid) |
| 988 | { |
| 989 | while (nid) |
| 990 | { |
| 991 | struct dhcp_netid *tmp = nid; |
| 992 | nid = nid->next; |
| 993 | free(tmp->net); |
| 994 | free(tmp); |
| 995 | } |
| 996 | } |
| 997 | |
| 998 | /* Parse one or more tag:s before parameters. |
| 999 | * Moves arg to the end of tags. */ |
| 1000 | static struct dhcp_netid * dhcp_tags(char **arg) |
| 1001 | { |
| 1002 | struct dhcp_netid *id = NULL; |
| 1003 | |
| 1004 | while (is_tag_prefix(*arg)) |
| 1005 | { |
| 1006 | char *comma = split(*arg); |
| 1007 | id = dhcp_netid_create((*arg)+4, id); |
| 1008 | *arg = comma; |
| 1009 | }; |
| 1010 | if (!*arg) |
| 1011 | { |
| 1012 | dhcp_netid_free(id); |
| 1013 | id = NULL; |
| 1014 | } |
| 1015 | return id; |
| 1016 | } |
| 1017 | |
| 1018 | static void dhcp_netid_list_free(struct dhcp_netid_list *netid) |
| 1019 | { |
| 1020 | while (netid) |
| 1021 | { |
| 1022 | struct dhcp_netid_list *tmplist = netid; |
| 1023 | netid = netid->next; |
| 1024 | dhcp_netid_free(tmplist->list); |
| 1025 | free(tmplist); |
| 1026 | } |
| 1027 | } |
| 1028 | |
| 1029 | static void dhcp_config_free(struct dhcp_config *config) |
| 1030 | { |
| 1031 | if (config) |
| 1032 | { |
| 1033 | struct hwaddr_config *hwaddr = config->hwaddr; |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 1034 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1035 | while (hwaddr) |
| 1036 | { |
| 1037 | struct hwaddr_config *tmp = hwaddr; |
| 1038 | hwaddr = hwaddr->next; |
| 1039 | free(tmp); |
| 1040 | } |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 1041 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1042 | dhcp_netid_list_free(config->netid); |
Simon Kelley | 52ec783 | 2020-02-07 21:05:54 +0000 | [diff] [blame] | 1043 | dhcp_netid_free(config->filter); |
| 1044 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1045 | if (config->flags & CONFIG_CLID) |
| 1046 | free(config->clid); |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 1047 | |
Kevin Darbyshire-Bryant | 8d6d573 | 2020-03-02 10:00:21 +0000 | [diff] [blame] | 1048 | #ifdef HAVE_DHCP6 |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 1049 | if (config->flags & CONFIG_ADDR6) |
| 1050 | { |
| 1051 | struct addrlist *addr, *tmp; |
| 1052 | |
| 1053 | for (addr = config->addr6; addr; addr = tmp) |
| 1054 | { |
| 1055 | tmp = addr->next; |
| 1056 | free(addr); |
| 1057 | } |
| 1058 | } |
Kevin Darbyshire-Bryant | 8d6d573 | 2020-03-02 10:00:21 +0000 | [diff] [blame] | 1059 | #endif |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 1060 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1061 | free(config); |
| 1062 | } |
| 1063 | } |
| 1064 | |
| 1065 | static void dhcp_context_free(struct dhcp_context *ctx) |
| 1066 | { |
| 1067 | if (ctx) |
| 1068 | { |
| 1069 | dhcp_netid_free(ctx->filter); |
| 1070 | free(ctx->netid.net); |
Kevin Darbyshire-Bryant | b683cf3 | 2018-12-10 10:34:35 +0000 | [diff] [blame] | 1071 | #ifdef HAVE_DHCP6 |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1072 | free(ctx->template_interface); |
Kevin Darbyshire-Bryant | b683cf3 | 2018-12-10 10:34:35 +0000 | [diff] [blame] | 1073 | #endif |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1074 | free(ctx); |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | static void dhcp_opt_free(struct dhcp_opt *opt) |
| 1079 | { |
| 1080 | if (opt->flags & DHOPT_VENDOR) |
| 1081 | free(opt->u.vendor_class); |
| 1082 | dhcp_netid_free(opt->netid); |
| 1083 | free(opt->val); |
| 1084 | free(opt); |
| 1085 | } |
| 1086 | |
| 1087 | |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1088 | /* This is too insanely large to keep in-line in the switch */ |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1089 | static int parse_dhcp_opt(char *errstr, char *arg, int flags) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1090 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1091 | struct dhcp_opt *new = opt_malloc(sizeof(struct dhcp_opt)); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1092 | char lenchar = 0, *cp; |
Simon Kelley | 40ef23b | 2012-03-13 21:59:28 +0000 | [diff] [blame] | 1093 | int addrs, digs, is_addr, is_addr6, is_hex, is_dec, is_string, dots; |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1094 | char *comma = NULL; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1095 | u16 opt_len = 0; |
| 1096 | int is6 = 0; |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 1097 | int option_ok = 0; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1098 | |
| 1099 | new->len = 0; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1100 | new->flags = flags; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1101 | new->netid = NULL; |
| 1102 | new->val = NULL; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1103 | new->opt = 0; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1104 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1105 | while (arg) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1106 | { |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1107 | comma = split(arg); |
| 1108 | |
| 1109 | for (cp = arg; *cp; cp++) |
| 1110 | if (*cp < '0' || *cp > '9') |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1111 | break; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1112 | |
| 1113 | if (!*cp) |
| 1114 | { |
| 1115 | new->opt = atoi(arg); |
| 1116 | opt_len = 0; |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 1117 | option_ok = 1; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1118 | break; |
| 1119 | } |
| 1120 | |
| 1121 | if (strstr(arg, "option:") == arg) |
| 1122 | { |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 1123 | if ((new->opt = lookup_dhcp_opt(AF_INET, arg+7)) != -1) |
| 1124 | { |
| 1125 | opt_len = lookup_dhcp_len(AF_INET, new->opt); |
| 1126 | /* option:<optname> must follow tag and vendor string. */ |
| 1127 | if (!(opt_len & OT_INTERNAL) || flags == DHOPT_MATCH) |
| 1128 | option_ok = 1; |
| 1129 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1130 | break; |
| 1131 | } |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1132 | #ifdef HAVE_DHCP6 |
| 1133 | else if (strstr(arg, "option6:") == arg) |
| 1134 | { |
| 1135 | for (cp = arg+8; *cp; cp++) |
| 1136 | if (*cp < '0' || *cp > '9') |
| 1137 | break; |
| 1138 | |
| 1139 | if (!*cp) |
| 1140 | { |
| 1141 | new->opt = atoi(arg+8); |
| 1142 | opt_len = 0; |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 1143 | option_ok = 1; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1144 | } |
| 1145 | else |
Simon Kelley | 40ef23b | 2012-03-13 21:59:28 +0000 | [diff] [blame] | 1146 | { |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 1147 | if ((new->opt = lookup_dhcp_opt(AF_INET6, arg+8)) != -1) |
| 1148 | { |
| 1149 | opt_len = lookup_dhcp_len(AF_INET6, new->opt); |
| 1150 | if (!(opt_len & OT_INTERNAL) || flags == DHOPT_MATCH) |
| 1151 | option_ok = 1; |
| 1152 | } |
Simon Kelley | 40ef23b | 2012-03-13 21:59:28 +0000 | [diff] [blame] | 1153 | } |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1154 | /* option6:<opt>|<optname> must follow tag and vendor string. */ |
| 1155 | is6 = 1; |
| 1156 | break; |
| 1157 | } |
| 1158 | #endif |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1159 | else if (strstr(arg, "vendor:") == arg) |
| 1160 | { |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 1161 | new->u.vendor_class = (unsigned char *)opt_string_alloc(arg+7); |
| 1162 | new->flags |= DHOPT_VENDOR; |
| 1163 | } |
| 1164 | else if (strstr(arg, "encap:") == arg) |
| 1165 | { |
| 1166 | new->u.encap = atoi(arg+6); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1167 | new->flags |= DHOPT_ENCAPSULATE; |
| 1168 | } |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 1169 | else if (strstr(arg, "vi-encap:") == arg) |
| 1170 | { |
| 1171 | new->u.encap = atoi(arg+9); |
| 1172 | new->flags |= DHOPT_RFC3925; |
| 1173 | if (flags == DHOPT_MATCH) |
| 1174 | { |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 1175 | option_ok = 1; |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 1176 | break; |
| 1177 | } |
| 1178 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1179 | else |
| 1180 | { |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 1181 | /* allow optional "net:" or "tag:" for consistency */ |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1182 | const char *name = (is_tag_prefix(arg)) ? arg+4 : set_prefix(arg); |
| 1183 | new->netid = dhcp_netid_create(name, new->netid); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | arg = comma; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1187 | } |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1188 | |
| 1189 | #ifdef HAVE_DHCP6 |
| 1190 | if (is6) |
| 1191 | { |
| 1192 | if (new->flags & (DHOPT_VENDOR | DHOPT_ENCAPSULATE)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1193 | goto_err(_("unsupported encapsulation for IPv6 option")); |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1194 | |
| 1195 | if (opt_len == 0 && |
| 1196 | !(new->flags & DHOPT_RFC3925)) |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 1197 | opt_len = lookup_dhcp_len(AF_INET6, new->opt); |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1198 | } |
| 1199 | else |
| 1200 | #endif |
| 1201 | if (opt_len == 0 && |
| 1202 | !(new->flags & (DHOPT_VENDOR | DHOPT_ENCAPSULATE | DHOPT_RFC3925))) |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 1203 | opt_len = lookup_dhcp_len(AF_INET, new->opt); |
Simon Kelley | 40ef23b | 2012-03-13 21:59:28 +0000 | [diff] [blame] | 1204 | |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 1205 | /* option may be missing with rfc3925 match */ |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 1206 | if (!option_ok) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1207 | goto_err(_("bad dhcp-option")); |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1208 | |
| 1209 | if (comma) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1210 | { |
| 1211 | /* characterise the value */ |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1212 | char c; |
Simon Kelley | 6799320 | 2019-03-04 22:59:42 +0000 | [diff] [blame] | 1213 | int found_dig = 0, found_colon = 0; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1214 | is_addr = is_addr6 = is_hex = is_dec = is_string = 1; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1215 | addrs = digs = 1; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1216 | dots = 0; |
| 1217 | for (cp = comma; (c = *cp); cp++) |
| 1218 | if (c == ',') |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1219 | { |
| 1220 | addrs++; |
| 1221 | is_dec = is_hex = 0; |
| 1222 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1223 | else if (c == ':') |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1224 | { |
| 1225 | digs++; |
| 1226 | is_dec = is_addr = 0; |
Simon Kelley | 6799320 | 2019-03-04 22:59:42 +0000 | [diff] [blame] | 1227 | found_colon = 1; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1228 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1229 | else if (c == '/') |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1230 | { |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1231 | is_addr6 = is_dec = is_hex = 0; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1232 | if (cp == comma) /* leading / means a pathname */ |
| 1233 | is_addr = 0; |
| 1234 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1235 | else if (c == '.') |
| 1236 | { |
Simon Kelley | 8baf583 | 2020-04-23 23:14:45 +0100 | [diff] [blame] | 1237 | is_dec = is_hex = 0; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1238 | dots++; |
| 1239 | } |
| 1240 | else if (c == '-') |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1241 | is_hex = is_addr = is_addr6 = 0; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1242 | else if (c == ' ') |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1243 | is_dec = is_hex = 0; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1244 | else if (!(c >='0' && c <= '9')) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1245 | { |
| 1246 | is_addr = 0; |
| 1247 | if (cp[1] == 0 && is_dec && |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1248 | (c == 'b' || c == 's' || c == 'i')) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1249 | { |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1250 | lenchar = c; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1251 | *cp = 0; |
| 1252 | } |
| 1253 | else |
| 1254 | is_dec = 0; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1255 | if (!((c >='A' && c <= 'F') || |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 1256 | (c >='a' && c <= 'f') || |
| 1257 | (c == '*' && (flags & DHOPT_MATCH)))) |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1258 | { |
| 1259 | is_hex = 0; |
| 1260 | if (c != '[' && c != ']') |
| 1261 | is_addr6 = 0; |
| 1262 | } |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1263 | } |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1264 | else |
| 1265 | found_dig = 1; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1266 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1267 | if (!found_dig) |
| 1268 | is_dec = is_addr = 0; |
Simon Kelley | 6799320 | 2019-03-04 22:59:42 +0000 | [diff] [blame] | 1269 | |
| 1270 | if (!found_colon) |
| 1271 | is_addr6 = 0; |
Vladislav Grishenko | dded78b | 2020-03-08 15:34:34 +0000 | [diff] [blame] | 1272 | |
| 1273 | #ifdef HAVE_DHCP6 |
| 1274 | /* NTP server option takes hex, addresses or FQDN */ |
| 1275 | if (is6 && new->opt == OPTION6_NTP_SERVER && !is_hex) |
| 1276 | opt_len |= is_addr6 ? OT_ADDR_LIST : OT_RFC1035_NAME; |
| 1277 | #endif |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1278 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1279 | /* We know that some options take addresses */ |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1280 | if (opt_len & OT_ADDR_LIST) |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1281 | { |
| 1282 | is_string = is_dec = is_hex = 0; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1283 | |
| 1284 | if (!is6 && (!is_addr || dots == 0)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1285 | goto_err(_("bad IP address")); |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1286 | |
| 1287 | if (is6 && !is_addr6) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1288 | goto_err(_("bad IPv6 address")); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1289 | } |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1290 | /* or names */ |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1291 | else if (opt_len & (OT_NAME | OT_RFC1035_NAME | OT_CSTRING)) |
| 1292 | is_addr6 = is_addr = is_dec = is_hex = 0; |
Simon Kelley | 23245c0 | 2012-07-18 16:21:11 +0100 | [diff] [blame] | 1293 | |
| 1294 | if (found_dig && (opt_len & OT_TIME) && strlen(comma) > 0) |
| 1295 | { |
| 1296 | int val, fac = 1; |
| 1297 | |
| 1298 | switch (comma[strlen(comma) - 1]) |
| 1299 | { |
Simon Kelley | 4224321 | 2012-07-20 15:19:18 +0100 | [diff] [blame] | 1300 | case 'w': |
| 1301 | case 'W': |
| 1302 | fac *= 7; |
| 1303 | /* fall through */ |
Simon Kelley | 23245c0 | 2012-07-18 16:21:11 +0100 | [diff] [blame] | 1304 | case 'd': |
| 1305 | case 'D': |
| 1306 | fac *= 24; |
Simon Kelley | 87e00fe | 2018-02-16 21:27:35 +0000 | [diff] [blame] | 1307 | /* fall through */ |
Simon Kelley | 23245c0 | 2012-07-18 16:21:11 +0100 | [diff] [blame] | 1308 | case 'h': |
| 1309 | case 'H': |
| 1310 | fac *= 60; |
| 1311 | /* fall through */ |
| 1312 | case 'm': |
| 1313 | case 'M': |
| 1314 | fac *= 60; |
| 1315 | /* fall through */ |
| 1316 | case 's': |
| 1317 | case 'S': |
| 1318 | comma[strlen(comma) - 1] = 0; |
| 1319 | } |
| 1320 | |
| 1321 | new->len = 4; |
| 1322 | new->val = opt_malloc(4); |
| 1323 | val = atoi(comma); |
| 1324 | *((int *)new->val) = htonl(val * fac); |
| 1325 | } |
| 1326 | else if (is_hex && digs > 1) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1327 | { |
| 1328 | new->len = digs; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1329 | new->val = opt_malloc(new->len); |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 1330 | parse_hex(comma, new->val, digs, (flags & DHOPT_MATCH) ? &new->u.wildcard_mask : NULL, NULL); |
| 1331 | new->flags |= DHOPT_HEX; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1332 | } |
| 1333 | else if (is_dec) |
| 1334 | { |
| 1335 | int i, val = atoi(comma); |
| 1336 | /* assume numeric arg is 1 byte except for |
| 1337 | options where it is known otherwise. |
| 1338 | For vendor class option, we have to hack. */ |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1339 | if (opt_len != 0) |
| 1340 | new->len = opt_len; |
| 1341 | else if (val & 0xffff0000) |
| 1342 | new->len = 4; |
| 1343 | else if (val & 0xff00) |
| 1344 | new->len = 2; |
| 1345 | else |
| 1346 | new->len = 1; |
| 1347 | |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1348 | if (lenchar == 'b') |
| 1349 | new->len = 1; |
| 1350 | else if (lenchar == 's') |
| 1351 | new->len = 2; |
| 1352 | else if (lenchar == 'i') |
| 1353 | new->len = 4; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1354 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1355 | new->val = opt_malloc(new->len); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1356 | for (i=0; i<new->len; i++) |
| 1357 | new->val[i] = val>>((new->len - i - 1)*8); |
| 1358 | } |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1359 | else if (is_addr && !is6) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1360 | { |
| 1361 | struct in_addr in; |
| 1362 | unsigned char *op; |
| 1363 | char *slash; |
| 1364 | /* max length of address/subnet descriptor is five bytes, |
| 1365 | add one for the option 120 enc byte too */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1366 | new->val = op = opt_malloc((5 * addrs) + 1); |
Simon Kelley | 6b01084 | 2007-02-12 20:32:07 +0000 | [diff] [blame] | 1367 | new->flags |= DHOPT_ADDR; |
| 1368 | |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 1369 | if (!(new->flags & (DHOPT_ENCAPSULATE | DHOPT_VENDOR | DHOPT_RFC3925)) && |
| 1370 | new->opt == OPTION_SIP_SERVER) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1371 | { |
Simon Kelley | 6b01084 | 2007-02-12 20:32:07 +0000 | [diff] [blame] | 1372 | *(op++) = 1; /* RFC 3361 "enc byte" */ |
| 1373 | new->flags &= ~DHOPT_ADDR; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1374 | } |
| 1375 | while (addrs--) |
| 1376 | { |
| 1377 | cp = comma; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1378 | comma = split(cp); |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 1379 | slash = split_chr(cp, '/'); |
Simon Kelley | a2bc254 | 2016-04-21 22:34:22 +0100 | [diff] [blame] | 1380 | if (!inet_pton(AF_INET, cp, &in)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1381 | goto_err(_("bad IPv4 address")); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1382 | if (!slash) |
| 1383 | { |
| 1384 | memcpy(op, &in, INADDRSZ); |
| 1385 | op += INADDRSZ; |
| 1386 | } |
| 1387 | else |
| 1388 | { |
| 1389 | unsigned char *p = (unsigned char *)∈ |
| 1390 | int netsize = atoi(slash); |
| 1391 | *op++ = netsize; |
| 1392 | if (netsize > 0) |
| 1393 | *op++ = *p++; |
| 1394 | if (netsize > 8) |
| 1395 | *op++ = *p++; |
| 1396 | if (netsize > 16) |
| 1397 | *op++ = *p++; |
| 1398 | if (netsize > 24) |
| 1399 | *op++ = *p++; |
| 1400 | new->flags &= ~DHOPT_ADDR; /* cannot re-write descriptor format */ |
| 1401 | } |
| 1402 | } |
| 1403 | new->len = op - new->val; |
| 1404 | } |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1405 | else if (is_addr6 && is6) |
| 1406 | { |
| 1407 | unsigned char *op; |
| 1408 | new->val = op = opt_malloc(16 * addrs); |
| 1409 | new->flags |= DHOPT_ADDR6; |
| 1410 | while (addrs--) |
| 1411 | { |
| 1412 | cp = comma; |
| 1413 | comma = split(cp); |
| 1414 | |
| 1415 | /* check for [1234::7] */ |
| 1416 | if (*cp == '[') |
| 1417 | cp++; |
| 1418 | if (strlen(cp) > 1 && cp[strlen(cp)-1] == ']') |
| 1419 | cp[strlen(cp)-1] = 0; |
| 1420 | |
| 1421 | if (inet_pton(AF_INET6, cp, op)) |
| 1422 | { |
| 1423 | op += IN6ADDRSZ; |
| 1424 | continue; |
| 1425 | } |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1426 | |
| 1427 | goto_err(_("bad IPv6 address")); |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1428 | } |
| 1429 | new->len = op - new->val; |
| 1430 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1431 | else if (is_string) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1432 | { |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1433 | /* text arg */ |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 1434 | if ((new->opt == OPTION_DOMAIN_SEARCH || new->opt == OPTION_SIP_SERVER) && |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1435 | !is6 && !(new->flags & (DHOPT_ENCAPSULATE | DHOPT_VENDOR | DHOPT_RFC3925))) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1436 | { |
| 1437 | /* dns search, RFC 3397, or SIP, RFC 3361 */ |
| 1438 | unsigned char *q, *r, *tail; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1439 | unsigned char *p, *m = NULL, *newp; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1440 | size_t newlen, len = 0; |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 1441 | int header_size = (new->opt == OPTION_DOMAIN_SEARCH) ? 0 : 1; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1442 | |
| 1443 | arg = comma; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1444 | comma = split(arg); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1445 | |
| 1446 | while (arg && *arg) |
| 1447 | { |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1448 | char *in, *dom = NULL; |
| 1449 | size_t domlen = 1; |
| 1450 | /* Allow "." as an empty domain */ |
| 1451 | if (strcmp (arg, ".") != 0) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1452 | { |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1453 | if (!(dom = canonicalise_opt(arg))) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1454 | goto_err(_("bad domain in dhcp-option")); |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1455 | |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1456 | domlen = strlen(dom) + 2; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1457 | } |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1458 | |
| 1459 | newp = opt_malloc(len + domlen + header_size); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1460 | if (m) |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1461 | { |
| 1462 | memcpy(newp, m, header_size + len); |
| 1463 | free(m); |
| 1464 | } |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1465 | m = newp; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1466 | p = m + header_size; |
| 1467 | q = p + len; |
| 1468 | |
| 1469 | /* add string on the end in RFC1035 format */ |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1470 | for (in = dom; in && *in;) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1471 | { |
| 1472 | unsigned char *cp = q++; |
| 1473 | int j; |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1474 | for (j = 0; *in && (*in != '.'); in++, j++) |
| 1475 | *q++ = *in; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1476 | *cp = j; |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1477 | if (*in) |
| 1478 | in++; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1479 | } |
| 1480 | *q++ = 0; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1481 | free(dom); |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1482 | |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1483 | /* Now tail-compress using earlier names. */ |
| 1484 | newlen = q - p; |
| 1485 | for (tail = p + len; *tail; tail += (*tail) + 1) |
| 1486 | for (r = p; r - p < (int)len; r += (*r) + 1) |
| 1487 | if (strcmp((char *)r, (char *)tail) == 0) |
| 1488 | { |
| 1489 | PUTSHORT((r - p) | 0xc000, tail); |
| 1490 | newlen = tail - p; |
| 1491 | goto end; |
| 1492 | } |
| 1493 | end: |
| 1494 | len = newlen; |
| 1495 | |
| 1496 | arg = comma; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1497 | comma = split(arg); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | /* RFC 3361, enc byte is zero for names */ |
Simon Kelley | 9e73244 | 2019-12-12 20:56:08 +0000 | [diff] [blame] | 1501 | if (new->opt == OPTION_SIP_SERVER && m) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1502 | m[0] = 0; |
| 1503 | new->len = (int) len + header_size; |
| 1504 | new->val = m; |
| 1505 | } |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1506 | #ifdef HAVE_DHCP6 |
| 1507 | else if (comma && (opt_len & OT_CSTRING)) |
| 1508 | { |
| 1509 | /* length fields are two bytes so need 16 bits for each string */ |
Simon Kelley | 40ef23b | 2012-03-13 21:59:28 +0000 | [diff] [blame] | 1510 | int i, commas = 1; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1511 | unsigned char *p, *newp; |
| 1512 | |
Simon Kelley | 40ef23b | 2012-03-13 21:59:28 +0000 | [diff] [blame] | 1513 | for (i = 0; comma[i]; i++) |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1514 | if (comma[i] == ',') |
| 1515 | commas++; |
| 1516 | |
| 1517 | newp = opt_malloc(strlen(comma)+(2*commas)); |
| 1518 | p = newp; |
| 1519 | arg = comma; |
| 1520 | comma = split(arg); |
| 1521 | |
| 1522 | while (arg && *arg) |
| 1523 | { |
| 1524 | u16 len = strlen(arg); |
Simon Kelley | 18f0fb0 | 2012-03-31 21:18:55 +0100 | [diff] [blame] | 1525 | unhide_metas(arg); |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1526 | PUTSHORT(len, p); |
| 1527 | memcpy(p, arg, len); |
| 1528 | p += len; |
| 1529 | |
| 1530 | arg = comma; |
| 1531 | comma = split(arg); |
| 1532 | } |
| 1533 | |
| 1534 | new->val = newp; |
| 1535 | new->len = p - newp; |
| 1536 | } |
| 1537 | else if (comma && (opt_len & OT_RFC1035_NAME)) |
| 1538 | { |
Vladislav Grishenko | dded78b | 2020-03-08 15:34:34 +0000 | [diff] [blame] | 1539 | unsigned char *p = NULL, *q, *newp, *end; |
Simon Kelley | 18f0fb0 | 2012-03-31 21:18:55 +0100 | [diff] [blame] | 1540 | int len = 0; |
Vladislav Grishenko | dded78b | 2020-03-08 15:34:34 +0000 | [diff] [blame] | 1541 | int header_size = (is6 && new->opt == OPTION6_NTP_SERVER) ? 4 : 0; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1542 | arg = comma; |
| 1543 | comma = split(arg); |
| 1544 | |
| 1545 | while (arg && *arg) |
| 1546 | { |
Simon Kelley | 18f0fb0 | 2012-03-31 21:18:55 +0100 | [diff] [blame] | 1547 | char *dom = canonicalise_opt(arg); |
| 1548 | if (!dom) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1549 | goto_err(_("bad domain in dhcp-option")); |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1550 | |
Vladislav Grishenko | dded78b | 2020-03-08 15:34:34 +0000 | [diff] [blame] | 1551 | newp = opt_malloc(len + header_size + strlen(dom) + 2); |
Simon Kelley | 18f0fb0 | 2012-03-31 21:18:55 +0100 | [diff] [blame] | 1552 | |
| 1553 | if (p) |
| 1554 | { |
| 1555 | memcpy(newp, p, len); |
| 1556 | free(p); |
| 1557 | } |
| 1558 | |
| 1559 | p = newp; |
Vladislav Grishenko | dded78b | 2020-03-08 15:34:34 +0000 | [diff] [blame] | 1560 | q = p + len; |
| 1561 | end = do_rfc1035_name(q + header_size, dom, NULL); |
Simon Kelley | 18f0fb0 | 2012-03-31 21:18:55 +0100 | [diff] [blame] | 1562 | *end++ = 0; |
Vladislav Grishenko | dded78b | 2020-03-08 15:34:34 +0000 | [diff] [blame] | 1563 | if (is6 && new->opt == OPTION6_NTP_SERVER) |
| 1564 | { |
| 1565 | PUTSHORT(NTP_SUBOPTION_SRV_FQDN, q); |
| 1566 | PUTSHORT(end - q - 2, q); |
| 1567 | } |
Simon Kelley | 18f0fb0 | 2012-03-31 21:18:55 +0100 | [diff] [blame] | 1568 | len = end - p; |
| 1569 | free(dom); |
| 1570 | |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1571 | arg = comma; |
| 1572 | comma = split(arg); |
| 1573 | } |
| 1574 | |
Simon Kelley | 18f0fb0 | 2012-03-31 21:18:55 +0100 | [diff] [blame] | 1575 | new->val = p; |
| 1576 | new->len = len; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1577 | } |
| 1578 | #endif |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1579 | else |
| 1580 | { |
| 1581 | new->len = strlen(comma); |
| 1582 | /* keep terminating zero on string */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1583 | new->val = (unsigned char *)opt_string_alloc(comma); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1584 | new->flags |= DHOPT_STRING; |
| 1585 | } |
| 1586 | } |
| 1587 | } |
| 1588 | |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1589 | if (!is6 && |
| 1590 | ((new->len > 255) || |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 1591 | (new->len > 253 && (new->flags & (DHOPT_VENDOR | DHOPT_ENCAPSULATE))) || |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1592 | (new->len > 250 && (new->flags & DHOPT_RFC3925)))) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1593 | goto_err(_("dhcp-option too long")); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1594 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1595 | if (flags == DHOPT_MATCH) |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1596 | { |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1597 | if ((new->flags & (DHOPT_ENCAPSULATE | DHOPT_VENDOR)) || |
| 1598 | !new->netid || |
| 1599 | new->netid->next) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1600 | goto_err(_("illegal dhcp-match")); |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1601 | |
| 1602 | if (is6) |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 1603 | { |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1604 | new->next = daemon->dhcp_match6; |
| 1605 | daemon->dhcp_match6 = new; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1606 | } |
| 1607 | else |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 1608 | { |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1609 | new->next = daemon->dhcp_match; |
| 1610 | daemon->dhcp_match = new; |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 1611 | } |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1612 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1613 | else if (is6) |
| 1614 | { |
| 1615 | new->next = daemon->dhcp_opts6; |
| 1616 | daemon->dhcp_opts6 = new; |
| 1617 | } |
| 1618 | else |
| 1619 | { |
| 1620 | new->next = daemon->dhcp_opts; |
| 1621 | daemon->dhcp_opts = new; |
| 1622 | } |
| 1623 | |
| 1624 | return 1; |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1625 | on_error: |
| 1626 | dhcp_opt_free(new); |
| 1627 | return 0; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1630 | #endif |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1631 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1632 | void set_option_bool(unsigned int opt) |
| 1633 | { |
Petr Menšík | 24b8760 | 2018-10-24 22:30:18 +0100 | [diff] [blame] | 1634 | option_var(opt) |= option_val(opt); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1635 | } |
| 1636 | |
Simon Kelley | 2b5bae9 | 2012-06-26 16:55:23 +0100 | [diff] [blame] | 1637 | void reset_option_bool(unsigned int opt) |
| 1638 | { |
Petr Menšík | 24b8760 | 2018-10-24 22:30:18 +0100 | [diff] [blame] | 1639 | option_var(opt) &= ~(option_val(opt)); |
Simon Kelley | 2b5bae9 | 2012-06-26 16:55:23 +0100 | [diff] [blame] | 1640 | } |
| 1641 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1642 | static void server_list_free(struct server *list) |
| 1643 | { |
| 1644 | while (list) |
| 1645 | { |
| 1646 | struct server *tmp = list; |
| 1647 | list = list->next; |
| 1648 | free(tmp); |
| 1649 | } |
| 1650 | } |
| 1651 | |
Simon Kelley | 7b1eae4 | 2014-02-20 13:43:28 +0000 | [diff] [blame] | 1652 | static int one_opt(int option, char *arg, char *errstr, char *gen_err, int command_line, int servers_only) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1653 | { |
| 1654 | int i; |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1655 | char *comma; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1656 | |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1657 | if (option == '?') |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1658 | ret_err(gen_err); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1659 | |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 1660 | for (i=0; usage[i].opt != 0; i++) |
| 1661 | if (usage[i].opt == option) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1662 | { |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 1663 | int rept = usage[i].rept; |
| 1664 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1665 | if (command_line) |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 1666 | { |
| 1667 | /* command line */ |
| 1668 | if (rept == ARG_USED_CL) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1669 | ret_err(_("illegal repeated flag")); |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 1670 | if (rept == ARG_ONE) |
| 1671 | usage[i].rept = ARG_USED_CL; |
| 1672 | } |
| 1673 | else |
| 1674 | { |
| 1675 | /* allow file to override command line */ |
| 1676 | if (rept == ARG_USED_FILE) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1677 | ret_err(_("illegal repeated keyword")); |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 1678 | if (rept == ARG_USED_CL || rept == ARG_ONE) |
| 1679 | usage[i].rept = ARG_USED_FILE; |
| 1680 | } |
| 1681 | |
| 1682 | if (rept != ARG_DUP && rept != ARG_ONE && rept != ARG_USED_CL) |
| 1683 | { |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1684 | set_option_bool(rept); |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1685 | return 1; |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 1686 | } |
| 1687 | |
| 1688 | break; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1689 | } |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 1690 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1691 | switch (option) |
| 1692 | { |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1693 | case 'C': /* --conf-file */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1694 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1695 | char *file = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1696 | if (file) |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1697 | { |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1698 | one_file(file, 0); |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1699 | free(file); |
| 1700 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1701 | break; |
| 1702 | } |
| 1703 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1704 | case '7': /* --conf-dir */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1705 | { |
| 1706 | DIR *dir_stream; |
| 1707 | struct dirent *ent; |
| 1708 | char *directory, *path; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1709 | struct list { |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1710 | char *name; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1711 | struct list *next; |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1712 | } *ignore_suffix = NULL, *match_suffix = NULL, *files = NULL, *li; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1713 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1714 | comma = split(arg); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1715 | if (!(directory = opt_string_alloc(arg))) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1716 | break; |
| 1717 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1718 | for (arg = comma; arg; arg = comma) |
| 1719 | { |
| 1720 | comma = split(arg); |
Simon Kelley | 00cd9d5 | 2014-10-02 21:44:21 +0100 | [diff] [blame] | 1721 | if (strlen(arg) != 0) |
Simon Kelley | 3e1551a | 2014-09-09 21:46:07 +0100 | [diff] [blame] | 1722 | { |
Simon Kelley | 00cd9d5 | 2014-10-02 21:44:21 +0100 | [diff] [blame] | 1723 | li = opt_malloc(sizeof(struct list)); |
| 1724 | if (*arg == '*') |
| 1725 | { |
Simon Kelley | 0007ee9 | 2015-11-21 21:47:41 +0000 | [diff] [blame] | 1726 | /* "*" with no suffix is a no-op */ |
| 1727 | if (arg[1] == 0) |
| 1728 | free(li); |
| 1729 | else |
| 1730 | { |
| 1731 | li->next = match_suffix; |
| 1732 | match_suffix = li; |
| 1733 | /* Have to copy: buffer is overwritten */ |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1734 | li->name = opt_string_alloc(arg+1); |
Simon Kelley | 0007ee9 | 2015-11-21 21:47:41 +0000 | [diff] [blame] | 1735 | } |
Simon Kelley | 00cd9d5 | 2014-10-02 21:44:21 +0100 | [diff] [blame] | 1736 | } |
| 1737 | else |
| 1738 | { |
| 1739 | li->next = ignore_suffix; |
| 1740 | ignore_suffix = li; |
| 1741 | /* Have to copy: buffer is overwritten */ |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1742 | li->name = opt_string_alloc(arg); |
Simon Kelley | 00cd9d5 | 2014-10-02 21:44:21 +0100 | [diff] [blame] | 1743 | } |
Simon Kelley | 3e1551a | 2014-09-09 21:46:07 +0100 | [diff] [blame] | 1744 | } |
Simon Kelley | 00cd9d5 | 2014-10-02 21:44:21 +0100 | [diff] [blame] | 1745 | } |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1746 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1747 | if (!(dir_stream = opendir(directory))) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 1748 | die(_("cannot access directory %s: %s"), directory, EC_FILE); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1749 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1750 | while ((ent = readdir(dir_stream))) |
| 1751 | { |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1752 | size_t len = strlen(ent->d_name); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1753 | struct stat buf; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1754 | |
| 1755 | /* ignore emacs backups and dotfiles */ |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1756 | if (len == 0 || |
| 1757 | ent->d_name[len - 1] == '~' || |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1758 | (ent->d_name[0] == '#' && ent->d_name[len - 1] == '#') || |
| 1759 | ent->d_name[0] == '.') |
| 1760 | continue; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1761 | |
Simon Kelley | 3e1551a | 2014-09-09 21:46:07 +0100 | [diff] [blame] | 1762 | if (match_suffix) |
| 1763 | { |
| 1764 | for (li = match_suffix; li; li = li->next) |
| 1765 | { |
| 1766 | /* check for required suffices */ |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1767 | size_t ls = strlen(li->name); |
Simon Kelley | 3e1551a | 2014-09-09 21:46:07 +0100 | [diff] [blame] | 1768 | if (len > ls && |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1769 | strcmp(li->name, &ent->d_name[len - ls]) == 0) |
Simon Kelley | 3e1551a | 2014-09-09 21:46:07 +0100 | [diff] [blame] | 1770 | break; |
| 1771 | } |
| 1772 | if (!li) |
| 1773 | continue; |
| 1774 | } |
| 1775 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1776 | for (li = ignore_suffix; li; li = li->next) |
| 1777 | { |
| 1778 | /* check for proscribed suffices */ |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1779 | size_t ls = strlen(li->name); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1780 | if (len > ls && |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1781 | strcmp(li->name, &ent->d_name[len - ls]) == 0) |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1782 | break; |
| 1783 | } |
| 1784 | if (li) |
| 1785 | continue; |
| 1786 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1787 | path = opt_malloc(strlen(directory) + len + 2); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1788 | strcpy(path, directory); |
| 1789 | strcat(path, "/"); |
| 1790 | strcat(path, ent->d_name); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1791 | |
Simon Kelley | 39595cf | 2013-02-04 21:40:07 +0000 | [diff] [blame] | 1792 | /* files must be readable */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1793 | if (stat(path, &buf) == -1) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 1794 | die(_("cannot access %s: %s"), path, EC_FILE); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1795 | |
Simon Kelley | 39595cf | 2013-02-04 21:40:07 +0000 | [diff] [blame] | 1796 | /* only reg files allowed. */ |
| 1797 | if (S_ISREG(buf.st_mode)) |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1798 | { |
| 1799 | /* sort files into order. */ |
| 1800 | struct list **up, *new = opt_malloc(sizeof(struct list)); |
| 1801 | new->name = path; |
| 1802 | |
| 1803 | for (up = &files, li = files; li; up = &li->next, li = li->next) |
| 1804 | if (strcmp(li->name, path) >=0) |
| 1805 | break; |
| 1806 | |
| 1807 | new->next = li; |
| 1808 | *up = new; |
| 1809 | } |
| 1810 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1811 | } |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1812 | |
| 1813 | for (li = files; li; li = li->next) |
| 1814 | one_file(li->name, 0); |
| 1815 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1816 | closedir(dir_stream); |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1817 | free(directory); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1818 | for(; ignore_suffix; ignore_suffix = li) |
| 1819 | { |
| 1820 | li = ignore_suffix->next; |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1821 | free(ignore_suffix->name); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1822 | free(ignore_suffix); |
| 1823 | } |
Simon Kelley | 00cd9d5 | 2014-10-02 21:44:21 +0100 | [diff] [blame] | 1824 | for(; match_suffix; match_suffix = li) |
| 1825 | { |
| 1826 | li = match_suffix->next; |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1827 | free(match_suffix->name); |
Simon Kelley | 00cd9d5 | 2014-10-02 21:44:21 +0100 | [diff] [blame] | 1828 | free(match_suffix); |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 1829 | } |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1830 | for(; files; files = li) |
| 1831 | { |
| 1832 | li = files->next; |
| 1833 | free(files->name); |
| 1834 | free(files); |
| 1835 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1836 | break; |
| 1837 | } |
| 1838 | |
Simon Kelley | ed4c076 | 2013-10-08 20:46:34 +0100 | [diff] [blame] | 1839 | case LOPT_ADD_SBNET: /* --add-subnet */ |
| 1840 | set_option_bool(OPT_CLIENT_SUBNET); |
| 1841 | if (arg) |
| 1842 | { |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 1843 | char *err, *end; |
Simon Kelley | ed4c076 | 2013-10-08 20:46:34 +0100 | [diff] [blame] | 1844 | comma = split(arg); |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 1845 | |
| 1846 | struct mysubnet* new = opt_malloc(sizeof(struct mysubnet)); |
| 1847 | if ((end = split_chr(arg, '/'))) |
| 1848 | { |
| 1849 | /* has subnet+len */ |
| 1850 | err = parse_mysockaddr(arg, &new->addr); |
| 1851 | if (err) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1852 | ret_err_free(err, new); |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 1853 | if (!atoi_check(end, &new->mask)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1854 | ret_err_free(gen_err, new); |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 1855 | new->addr_used = 1; |
| 1856 | } |
| 1857 | else if (!atoi_check(arg, &new->mask)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1858 | ret_err_free(gen_err, new); |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 1859 | |
| 1860 | daemon->add_subnet4 = new; |
| 1861 | |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 1862 | if (comma) |
| 1863 | { |
Simon Kelley | 22fe2fd | 2016-02-28 17:07:10 +0000 | [diff] [blame] | 1864 | new = opt_malloc(sizeof(struct mysubnet)); |
| 1865 | if ((end = split_chr(comma, '/'))) |
| 1866 | { |
| 1867 | /* has subnet+len */ |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 1868 | err = parse_mysockaddr(comma, &new->addr); |
| 1869 | if (err) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1870 | ret_err_free(err, new); |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 1871 | if (!atoi_check(end, &new->mask)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1872 | ret_err_free(gen_err, new); |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 1873 | new->addr_used = 1; |
| 1874 | } |
| 1875 | else |
| 1876 | { |
| 1877 | if (!atoi_check(comma, &new->mask)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1878 | ret_err_free(gen_err, new); |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 1879 | } |
Simon Kelley | 22fe2fd | 2016-02-28 17:07:10 +0000 | [diff] [blame] | 1880 | |
| 1881 | daemon->add_subnet6 = new; |
| 1882 | } |
Simon Kelley | ed4c076 | 2013-10-08 20:46:34 +0100 | [diff] [blame] | 1883 | } |
| 1884 | break; |
| 1885 | |
Simon Kelley | ad09427 | 2012-08-10 17:10:54 +0100 | [diff] [blame] | 1886 | case '1': /* --enable-dbus */ |
| 1887 | set_option_bool(OPT_DBUS); |
| 1888 | if (arg) |
| 1889 | daemon->dbus_name = opt_string_alloc(arg); |
| 1890 | else |
| 1891 | daemon->dbus_name = DNSMASQ_SERVICE; |
| 1892 | break; |
Oldřich Jedlička | d162bee | 2020-03-20 22:18:57 +0100 | [diff] [blame] | 1893 | |
| 1894 | case LOPT_UBUS: /* --enable-ubus */ |
| 1895 | set_option_bool(OPT_UBUS); |
| 1896 | if (arg) |
| 1897 | daemon->ubus_name = opt_string_alloc(arg); |
| 1898 | else |
| 1899 | daemon->ubus_name = DNSMASQ_UBUS_NAME; |
| 1900 | break; |
| 1901 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1902 | case '8': /* --log-facility */ |
| 1903 | /* may be a filename */ |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 1904 | if (strchr(arg, '/') || strcmp (arg, "-") == 0) |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1905 | daemon->log_file = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1906 | else |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1907 | { |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 1908 | #ifdef __ANDROID__ |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1909 | ret_err(_("setting log facility is not possible under Android")); |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 1910 | #else |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1911 | for (i = 0; facilitynames[i].c_name; i++) |
| 1912 | if (hostname_isequal((char *)facilitynames[i].c_name, arg)) |
| 1913 | break; |
| 1914 | |
| 1915 | if (facilitynames[i].c_name) |
| 1916 | daemon->log_fac = facilitynames[i].c_val; |
| 1917 | else |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1918 | ret_err(_("bad log facility")); |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 1919 | #endif |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1920 | } |
| 1921 | break; |
Julian Kornberger | 8dcdb33 | 2018-07-21 22:11:08 +0100 | [diff] [blame] | 1922 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1923 | case 'x': /* --pid-file */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1924 | daemon->runfile = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1925 | break; |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 1926 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1927 | case 'r': /* --resolv-file */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1928 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1929 | char *name = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1930 | struct resolvc *new, *list = daemon->resolv_files; |
| 1931 | |
| 1932 | if (list && list->is_default) |
| 1933 | { |
| 1934 | /* replace default resolv file - possibly with nothing */ |
| 1935 | if (name) |
| 1936 | { |
| 1937 | list->is_default = 0; |
| 1938 | list->name = name; |
| 1939 | } |
| 1940 | else |
| 1941 | list = NULL; |
| 1942 | } |
| 1943 | else if (name) |
| 1944 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1945 | new = opt_malloc(sizeof(struct resolvc)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1946 | new->next = list; |
| 1947 | new->name = name; |
| 1948 | new->is_default = 0; |
| 1949 | new->mtime = 0; |
| 1950 | new->logged = 0; |
| 1951 | list = new; |
| 1952 | } |
| 1953 | daemon->resolv_files = list; |
| 1954 | break; |
| 1955 | } |
Simon Kelley | 7b1eae4 | 2014-02-20 13:43:28 +0000 | [diff] [blame] | 1956 | |
| 1957 | case LOPT_SERVERS_FILE: |
| 1958 | daemon->servers_file = opt_string_alloc(arg); |
| 1959 | break; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1960 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1961 | case 'm': /* --mx-host */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1962 | { |
| 1963 | int pref = 1; |
| 1964 | struct mx_srv_record *new; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1965 | char *name, *target = NULL; |
| 1966 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1967 | if ((comma = split(arg))) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1968 | { |
| 1969 | char *prefstr; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1970 | if ((prefstr = split(comma)) && !atoi_check16(prefstr, &pref)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1971 | ret_err(_("bad MX preference")); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1972 | } |
| 1973 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1974 | if (!(name = canonicalise_opt(arg)) || |
| 1975 | (comma && !(target = canonicalise_opt(comma)))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1976 | ret_err(_("bad MX name")); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1977 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1978 | new = opt_malloc(sizeof(struct mx_srv_record)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1979 | new->next = daemon->mxnames; |
| 1980 | daemon->mxnames = new; |
| 1981 | new->issrv = 0; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1982 | new->name = name; |
| 1983 | new->target = target; /* may be NULL */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1984 | new->weight = pref; |
| 1985 | break; |
| 1986 | } |
| 1987 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1988 | case 't': /* --mx-target */ |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1989 | if (!(daemon->mxtarget = canonicalise_opt(arg))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1990 | ret_err(_("bad MX target")); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1991 | break; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1992 | |
Simon Kelley | 6b17335 | 2018-05-08 18:32:14 +0100 | [diff] [blame] | 1993 | case LOPT_DUMPFILE: /* --dumpfile */ |
| 1994 | daemon->dump_file = opt_string_alloc(arg); |
| 1995 | break; |
| 1996 | |
| 1997 | case LOPT_DUMPMASK: /* --dumpmask */ |
| 1998 | daemon->dump_mask = strtol(arg, NULL, 0); |
| 1999 | break; |
| 2000 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2001 | #ifdef HAVE_DHCP |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2002 | case 'l': /* --dhcp-leasefile */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2003 | daemon->lease_file = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2004 | break; |
| 2005 | |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 2006 | /* Sorry about the gross pre-processor abuse */ |
| 2007 | case '6': /* --dhcp-script */ |
| 2008 | case LOPT_LUASCRIPT: /* --dhcp-luascript */ |
Simon Kelley | 48d12f1 | 2018-11-02 21:55:04 +0000 | [diff] [blame] | 2009 | # if !defined(HAVE_SCRIPT) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2010 | ret_err(_("recompile with HAVE_SCRIPT defined to enable lease-change scripts")); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2011 | # else |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 2012 | if (option == LOPT_LUASCRIPT) |
| 2013 | # if !defined(HAVE_LUASCRIPT) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2014 | ret_err(_("recompile with HAVE_LUASCRIPT defined to enable Lua scripts")); |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 2015 | # else |
| 2016 | daemon->luascript = opt_string_alloc(arg); |
| 2017 | # endif |
| 2018 | else |
| 2019 | daemon->lease_change_command = opt_string_alloc(arg); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2020 | # endif |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2021 | break; |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 2022 | #endif /* HAVE_DHCP */ |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2023 | |
Simon Kelley | 70d1873 | 2015-01-31 19:59:29 +0000 | [diff] [blame] | 2024 | case LOPT_DHCP_HOST: /* --dhcp-hostsfile */ |
| 2025 | case LOPT_DHCP_OPTS: /* --dhcp-optsfile */ |
| 2026 | case LOPT_DHCP_INOTIFY: /* --dhcp-hostsdir */ |
| 2027 | case LOPT_DHOPT_INOTIFY: /* --dhcp-optsdir */ |
| 2028 | case LOPT_HOST_INOTIFY: /* --hostsdir */ |
| 2029 | case 'H': /* --addn-hosts */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2030 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2031 | struct hostsfile *new = opt_malloc(sizeof(struct hostsfile)); |
Simon Kelley | 19c51cf | 2014-03-18 22:38:30 +0000 | [diff] [blame] | 2032 | static unsigned int hosts_index = SRC_AH; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2033 | new->fname = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2034 | new->index = hosts_index++; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2035 | new->flags = 0; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 2036 | if (option == 'H') |
| 2037 | { |
| 2038 | new->next = daemon->addn_hosts; |
| 2039 | daemon->addn_hosts = new; |
| 2040 | } |
| 2041 | else if (option == LOPT_DHCP_HOST) |
| 2042 | { |
| 2043 | new->next = daemon->dhcp_hosts_file; |
| 2044 | daemon->dhcp_hosts_file = new; |
| 2045 | } |
Simon Kelley | e1ff419 | 2012-12-09 17:08:47 +0000 | [diff] [blame] | 2046 | else if (option == LOPT_DHCP_OPTS) |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 2047 | { |
| 2048 | new->next = daemon->dhcp_opts_file; |
| 2049 | daemon->dhcp_opts_file = new; |
| 2050 | } |
Simon Kelley | 70d1873 | 2015-01-31 19:59:29 +0000 | [diff] [blame] | 2051 | else |
Simon Kelley | 5f4dc5c | 2015-01-20 20:51:02 +0000 | [diff] [blame] | 2052 | { |
Simon Kelley | 70d1873 | 2015-01-31 19:59:29 +0000 | [diff] [blame] | 2053 | new->next = daemon->dynamic_dirs; |
| 2054 | daemon->dynamic_dirs = new; |
| 2055 | if (option == LOPT_DHCP_INOTIFY) |
| 2056 | new->flags |= AH_DHCP_HST; |
| 2057 | else if (option == LOPT_DHOPT_INOTIFY) |
| 2058 | new->flags |= AH_DHCP_OPT; |
| 2059 | else if (option == LOPT_HOST_INOTIFY) |
| 2060 | new->flags |= AH_HOSTS; |
Simon Kelley | 5f4dc5c | 2015-01-20 20:51:02 +0000 | [diff] [blame] | 2061 | } |
| 2062 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2063 | break; |
| 2064 | } |
| 2065 | |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2066 | case LOPT_AUTHSERV: /* --auth-server */ |
Simon Kelley | 0893347 | 2018-10-05 16:34:35 +0100 | [diff] [blame] | 2067 | comma = split(arg); |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2068 | |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2069 | daemon->authserver = opt_string_alloc(arg); |
Simon Kelley | 0893347 | 2018-10-05 16:34:35 +0100 | [diff] [blame] | 2070 | |
| 2071 | while ((arg = comma)) |
| 2072 | { |
| 2073 | struct iname *new = opt_malloc(sizeof(struct iname)); |
| 2074 | comma = split(arg); |
| 2075 | new->name = NULL; |
| 2076 | unhide_metas(arg); |
| 2077 | if (inet_pton(AF_INET, arg, &new->addr.in.sin_addr) > 0) |
| 2078 | new->addr.sa.sa_family = AF_INET; |
Simon Kelley | 0893347 | 2018-10-05 16:34:35 +0100 | [diff] [blame] | 2079 | else if (inet_pton(AF_INET6, arg, &new->addr.in6.sin6_addr) > 0) |
| 2080 | new->addr.sa.sa_family = AF_INET6; |
Simon Kelley | 0893347 | 2018-10-05 16:34:35 +0100 | [diff] [blame] | 2081 | else |
| 2082 | { |
| 2083 | char *fam = split_chr(arg, '/'); |
| 2084 | new->name = opt_string_alloc(arg); |
| 2085 | new->addr.sa.sa_family = 0; |
| 2086 | if (fam) |
| 2087 | { |
| 2088 | if (strcmp(fam, "4") == 0) |
| 2089 | new->addr.sa.sa_family = AF_INET; |
Simon Kelley | 0893347 | 2018-10-05 16:34:35 +0100 | [diff] [blame] | 2090 | else if (strcmp(fam, "6") == 0) |
| 2091 | new->addr.sa.sa_family = AF_INET6; |
Simon Kelley | 0893347 | 2018-10-05 16:34:35 +0100 | [diff] [blame] | 2092 | else |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2093 | { |
| 2094 | free(new->name); |
| 2095 | ret_err_free(gen_err, new); |
| 2096 | } |
Simon Kelley | 0893347 | 2018-10-05 16:34:35 +0100 | [diff] [blame] | 2097 | } |
| 2098 | } |
| 2099 | new->next = daemon->authinterface; |
| 2100 | daemon->authinterface = new; |
| 2101 | }; |
Simon Kelley | 429798f | 2012-12-10 20:45:53 +0000 | [diff] [blame] | 2102 | |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2103 | break; |
Simon Kelley | e1ff419 | 2012-12-09 17:08:47 +0000 | [diff] [blame] | 2104 | |
| 2105 | case LOPT_AUTHSFS: /* --auth-sec-servers */ |
| 2106 | { |
| 2107 | struct name_list *new; |
| 2108 | |
| 2109 | do { |
| 2110 | comma = split(arg); |
Simon Kelley | 429798f | 2012-12-10 20:45:53 +0000 | [diff] [blame] | 2111 | new = opt_malloc(sizeof(struct name_list)); |
Simon Kelley | e1ff419 | 2012-12-09 17:08:47 +0000 | [diff] [blame] | 2112 | new->name = opt_string_alloc(arg); |
| 2113 | new->next = daemon->secondary_forward_server; |
| 2114 | daemon->secondary_forward_server = new; |
| 2115 | arg = comma; |
| 2116 | } while (arg); |
| 2117 | break; |
| 2118 | } |
| 2119 | |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2120 | case LOPT_AUTHZONE: /* --auth-zone */ |
| 2121 | { |
| 2122 | struct auth_zone *new; |
| 2123 | |
| 2124 | comma = split(arg); |
Simon Kelley | 1e14cc0 | 2012-12-29 17:27:59 +0000 | [diff] [blame] | 2125 | |
Simon Kelley | 429798f | 2012-12-10 20:45:53 +0000 | [diff] [blame] | 2126 | new = opt_malloc(sizeof(struct auth_zone)); |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2127 | new->domain = opt_string_alloc(arg); |
| 2128 | new->subnet = NULL; |
Mathias Kresin | 094bfae | 2016-07-24 14:15:22 +0100 | [diff] [blame] | 2129 | new->exclude = NULL; |
Simon Kelley | 376d48c | 2013-11-13 13:04:30 +0000 | [diff] [blame] | 2130 | new->interface_names = NULL; |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2131 | new->next = daemon->auth_zones; |
| 2132 | daemon->auth_zones = new; |
| 2133 | |
| 2134 | while ((arg = comma)) |
| 2135 | { |
| 2136 | int prefixlen = 0; |
Mathias Kresin | 094bfae | 2016-07-24 14:15:22 +0100 | [diff] [blame] | 2137 | int is_exclude = 0; |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2138 | char *prefix; |
Simon Kelley | 376d48c | 2013-11-13 13:04:30 +0000 | [diff] [blame] | 2139 | struct addrlist *subnet = NULL; |
Simon Kelley | cc921df | 2019-01-02 22:48:59 +0000 | [diff] [blame] | 2140 | union all_addr addr; |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2141 | |
| 2142 | comma = split(arg); |
| 2143 | prefix = split_chr(arg, '/'); |
| 2144 | |
| 2145 | if (prefix && !atoi_check(prefix, &prefixlen)) |
| 2146 | ret_err(gen_err); |
| 2147 | |
Mathias Kresin | 094bfae | 2016-07-24 14:15:22 +0100 | [diff] [blame] | 2148 | if (strstr(arg, "exclude:") == arg) |
| 2149 | { |
| 2150 | is_exclude = 1; |
| 2151 | arg = arg+8; |
| 2152 | } |
| 2153 | |
Simon Kelley | cc921df | 2019-01-02 22:48:59 +0000 | [diff] [blame] | 2154 | if (inet_pton(AF_INET, arg, &addr.addr4)) |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2155 | { |
Simon Kelley | 376d48c | 2013-11-13 13:04:30 +0000 | [diff] [blame] | 2156 | subnet = opt_malloc(sizeof(struct addrlist)); |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2157 | subnet->prefixlen = (prefixlen == 0) ? 24 : prefixlen; |
Simon Kelley | 376d48c | 2013-11-13 13:04:30 +0000 | [diff] [blame] | 2158 | subnet->flags = ADDRLIST_LITERAL; |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2159 | } |
Simon Kelley | cc921df | 2019-01-02 22:48:59 +0000 | [diff] [blame] | 2160 | else if (inet_pton(AF_INET6, arg, &addr.addr6)) |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2161 | { |
Simon Kelley | 376d48c | 2013-11-13 13:04:30 +0000 | [diff] [blame] | 2162 | subnet = opt_malloc(sizeof(struct addrlist)); |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2163 | subnet->prefixlen = (prefixlen == 0) ? 64 : prefixlen; |
Simon Kelley | 376d48c | 2013-11-13 13:04:30 +0000 | [diff] [blame] | 2164 | subnet->flags = ADDRLIST_LITERAL | ADDRLIST_IPV6; |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2165 | } |
Simon Kelley | 376d48c | 2013-11-13 13:04:30 +0000 | [diff] [blame] | 2166 | else |
| 2167 | { |
| 2168 | struct auth_name_list *name = opt_malloc(sizeof(struct auth_name_list)); |
| 2169 | name->name = opt_string_alloc(arg); |
| 2170 | name->flags = AUTH4 | AUTH6; |
| 2171 | name->next = new->interface_names; |
| 2172 | new->interface_names = name; |
| 2173 | if (prefix) |
| 2174 | { |
| 2175 | if (prefixlen == 4) |
| 2176 | name->flags &= ~AUTH6; |
Simon Kelley | 376d48c | 2013-11-13 13:04:30 +0000 | [diff] [blame] | 2177 | else if (prefixlen == 6) |
| 2178 | name->flags &= ~AUTH4; |
Simon Kelley | 376d48c | 2013-11-13 13:04:30 +0000 | [diff] [blame] | 2179 | else |
| 2180 | ret_err(gen_err); |
| 2181 | } |
| 2182 | } |
| 2183 | |
| 2184 | if (subnet) |
| 2185 | { |
| 2186 | subnet->addr = addr; |
Mathias Kresin | 094bfae | 2016-07-24 14:15:22 +0100 | [diff] [blame] | 2187 | |
| 2188 | if (is_exclude) |
| 2189 | { |
| 2190 | subnet->next = new->exclude; |
| 2191 | new->exclude = subnet; |
| 2192 | } |
| 2193 | else |
| 2194 | { |
| 2195 | subnet->next = new->subnet; |
| 2196 | new->subnet = subnet; |
| 2197 | } |
Simon Kelley | 376d48c | 2013-11-13 13:04:30 +0000 | [diff] [blame] | 2198 | } |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2199 | } |
| 2200 | break; |
| 2201 | } |
Simon Kelley | 376d48c | 2013-11-13 13:04:30 +0000 | [diff] [blame] | 2202 | |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2203 | case LOPT_AUTHSOA: /* --auth-soa */ |
| 2204 | comma = split(arg); |
Simon Kelley | 5c72bb9 | 2013-08-19 14:12:59 +0100 | [diff] [blame] | 2205 | daemon->soa_sn = (u32)atoi(arg); |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2206 | if (comma) |
| 2207 | { |
Simon Kelley | 86e3b9a | 2012-11-30 13:46:48 +0000 | [diff] [blame] | 2208 | char *cp; |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2209 | arg = comma; |
| 2210 | comma = split(arg); |
| 2211 | daemon->hostmaster = opt_string_alloc(arg); |
Simon Kelley | 86e3b9a | 2012-11-30 13:46:48 +0000 | [diff] [blame] | 2212 | for (cp = daemon->hostmaster; *cp; cp++) |
| 2213 | if (*cp == '@') |
| 2214 | *cp = '.'; |
| 2215 | |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2216 | if (comma) |
| 2217 | { |
| 2218 | arg = comma; |
| 2219 | comma = split(arg); |
Simon Kelley | 5c72bb9 | 2013-08-19 14:12:59 +0100 | [diff] [blame] | 2220 | daemon->soa_refresh = (u32)atoi(arg); |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2221 | if (comma) |
| 2222 | { |
| 2223 | arg = comma; |
| 2224 | comma = split(arg); |
Simon Kelley | 5c72bb9 | 2013-08-19 14:12:59 +0100 | [diff] [blame] | 2225 | daemon->soa_retry = (u32)atoi(arg); |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2226 | if (comma) |
Simon Kelley | 407a1f3 | 2016-03-01 17:06:07 +0000 | [diff] [blame] | 2227 | daemon->soa_expiry = (u32)atoi(comma); |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2228 | } |
| 2229 | } |
| 2230 | } |
| 2231 | |
| 2232 | break; |
| 2233 | |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 2234 | case 's': /* --domain */ |
| 2235 | case LOPT_SYNTH: /* --synth-domain */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2236 | if (strcmp (arg, "#") == 0) |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 2237 | set_option_bool(OPT_RESOLV_DOMAIN); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2238 | else |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2239 | { |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 2240 | char *d; |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2241 | comma = split(arg); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 2242 | if (!(d = canonicalise_opt(arg))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2243 | ret_err(gen_err); |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2244 | else |
| 2245 | { |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2246 | if (comma) |
| 2247 | { |
Simon Kelley | 429798f | 2012-12-10 20:45:53 +0000 | [diff] [blame] | 2248 | struct cond_domain *new = opt_malloc(sizeof(struct cond_domain)); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 2249 | char *netpart; |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 2250 | |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 2251 | new->prefix = NULL; |
Simon Kelley | 6b2b564 | 2018-03-10 18:12:04 +0000 | [diff] [blame] | 2252 | new->indexed = 0; |
| 2253 | |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2254 | unhide_metas(comma); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 2255 | if ((netpart = split_chr(comma, '/'))) |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2256 | { |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2257 | int msize; |
| 2258 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 2259 | arg = split(netpart); |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2260 | if (!atoi_check(netpart, &msize)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2261 | ret_err_free(gen_err, new); |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2262 | else if (inet_pton(AF_INET, comma, &new->start)) |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2263 | { |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2264 | int mask = (1 << (32 - msize)) - 1; |
| 2265 | new->is6 = 0; |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2266 | new->start.s_addr = ntohl(htonl(new->start.s_addr) & ~mask); |
| 2267 | new->end.s_addr = new->start.s_addr | htonl(mask); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 2268 | if (arg) |
| 2269 | { |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 2270 | if (option != 's') |
Simon Kelley | b5a7ff4 | 2013-04-25 11:03:47 +0100 | [diff] [blame] | 2271 | { |
| 2272 | if (!(new->prefix = canonicalise_opt(arg)) || |
| 2273 | strlen(new->prefix) > MAXLABEL - INET_ADDRSTRLEN) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2274 | ret_err_free(_("bad prefix"), new); |
Simon Kelley | b5a7ff4 | 2013-04-25 11:03:47 +0100 | [diff] [blame] | 2275 | } |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 2276 | else if (strcmp(arg, "local") != 0 || |
| 2277 | (msize != 8 && msize != 16 && msize != 24)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2278 | ret_err_free(gen_err, new); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 2279 | else |
| 2280 | { |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2281 | /* generate the equivalent of |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2282 | local=/xxx.yyy.zzz.in-addr.arpa/ */ |
| 2283 | struct server *serv = add_rev4(new->start, msize); |
Olivier Gayot | dc99058 | 2017-03-06 22:17:21 +0000 | [diff] [blame] | 2284 | if (!serv) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2285 | ret_err_free(_("bad prefix"), new); |
Olivier Gayot | dc99058 | 2017-03-06 22:17:21 +0000 | [diff] [blame] | 2286 | |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2287 | serv->flags |= SERV_NO_ADDR; |
Simon Kelley | 3ad3f3b | 2014-12-16 18:25:17 +0000 | [diff] [blame] | 2288 | |
| 2289 | /* local=/<domain>/ */ |
| 2290 | serv = opt_malloc(sizeof(struct server)); |
| 2291 | memset(serv, 0, sizeof(struct server)); |
| 2292 | serv->domain = d; |
| 2293 | serv->flags = SERV_HAS_DOMAIN | SERV_NO_ADDR; |
| 2294 | serv->next = daemon->servers; |
| 2295 | daemon->servers = serv; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 2296 | } |
| 2297 | } |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2298 | } |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2299 | else if (inet_pton(AF_INET6, comma, &new->start6)) |
| 2300 | { |
| 2301 | u64 mask = (1LLU << (128 - msize)) - 1LLU; |
| 2302 | u64 addrpart = addr6part(&new->start6); |
| 2303 | new->is6 = 1; |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 2304 | |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2305 | /* prefix==64 overflows the mask calculation above */ |
| 2306 | if (msize == 64) |
| 2307 | mask = (u64)-1LL; |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 2308 | |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2309 | new->end6 = new->start6; |
| 2310 | setaddr6part(&new->start6, addrpart & ~mask); |
| 2311 | setaddr6part(&new->end6, addrpart | mask); |
| 2312 | |
| 2313 | if (msize < 64) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2314 | ret_err_free(gen_err, new); |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2315 | else if (arg) |
| 2316 | { |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 2317 | if (option != 's') |
Simon Kelley | b5a7ff4 | 2013-04-25 11:03:47 +0100 | [diff] [blame] | 2318 | { |
| 2319 | if (!(new->prefix = canonicalise_opt(arg)) || |
| 2320 | strlen(new->prefix) > MAXLABEL - INET6_ADDRSTRLEN) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2321 | ret_err_free(_("bad prefix"), new); |
Simon Kelley | b5a7ff4 | 2013-04-25 11:03:47 +0100 | [diff] [blame] | 2322 | } |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 2323 | else if (strcmp(arg, "local") != 0 || ((msize & 4) != 0)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2324 | ret_err_free(gen_err, new); |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2325 | else |
| 2326 | { |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 2327 | /* generate the equivalent of |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 2328 | local=/xxx.yyy.zzz.ip6.arpa/ */ |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2329 | struct server *serv = add_rev6(&new->start6, msize); |
| 2330 | serv->flags |= SERV_NO_ADDR; |
Simon Kelley | 3ad3f3b | 2014-12-16 18:25:17 +0000 | [diff] [blame] | 2331 | |
| 2332 | /* local=/<domain>/ */ |
| 2333 | serv = opt_malloc(sizeof(struct server)); |
| 2334 | memset(serv, 0, sizeof(struct server)); |
| 2335 | serv->domain = d; |
| 2336 | serv->flags = SERV_HAS_DOMAIN | SERV_NO_ADDR; |
| 2337 | serv->next = daemon->servers; |
| 2338 | daemon->servers = serv; |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2339 | } |
| 2340 | } |
| 2341 | } |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2342 | else |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2343 | ret_err_free(gen_err, new); |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2344 | } |
Simon Kelley | eec5c1e | 2013-10-25 10:37:30 +0100 | [diff] [blame] | 2345 | else |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2346 | { |
Simon Kelley | eec5c1e | 2013-10-25 10:37:30 +0100 | [diff] [blame] | 2347 | char *prefstr; |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2348 | arg = split(comma); |
Simon Kelley | eec5c1e | 2013-10-25 10:37:30 +0100 | [diff] [blame] | 2349 | prefstr = split(arg); |
| 2350 | |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2351 | if (inet_pton(AF_INET, comma, &new->start)) |
| 2352 | { |
| 2353 | new->is6 = 0; |
| 2354 | if (!arg) |
| 2355 | new->end.s_addr = new->start.s_addr; |
| 2356 | else if (!inet_pton(AF_INET, arg, &new->end)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2357 | ret_err_free(gen_err, new); |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2358 | } |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2359 | else if (inet_pton(AF_INET6, comma, &new->start6)) |
| 2360 | { |
| 2361 | new->is6 = 1; |
| 2362 | if (!arg) |
| 2363 | memcpy(&new->end6, &new->start6, IN6ADDRSZ); |
| 2364 | else if (!inet_pton(AF_INET6, arg, &new->end6)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2365 | ret_err_free(gen_err, new); |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2366 | } |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2367 | else |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2368 | ret_err_free(gen_err, new); |
Simon Kelley | eec5c1e | 2013-10-25 10:37:30 +0100 | [diff] [blame] | 2369 | |
| 2370 | if (option != 's' && prefstr) |
| 2371 | { |
| 2372 | if (!(new->prefix = canonicalise_opt(prefstr)) || |
| 2373 | strlen(new->prefix) > MAXLABEL - INET_ADDRSTRLEN) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2374 | ret_err_free(_("bad prefix"), new); |
Simon Kelley | eec5c1e | 2013-10-25 10:37:30 +0100 | [diff] [blame] | 2375 | } |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2376 | } |
Simon Kelley | 2307eac | 2012-02-13 10:13:13 +0000 | [diff] [blame] | 2377 | |
| 2378 | new->domain = d; |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 2379 | if (option == 's') |
| 2380 | { |
| 2381 | new->next = daemon->cond_domain; |
| 2382 | daemon->cond_domain = new; |
| 2383 | } |
| 2384 | else |
| 2385 | { |
Simon Kelley | 6b2b564 | 2018-03-10 18:12:04 +0000 | [diff] [blame] | 2386 | char *star; |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 2387 | new->next = daemon->synth_domains; |
| 2388 | daemon->synth_domains = new; |
Simon Kelley | dd33e98 | 2018-07-30 14:55:39 +0100 | [diff] [blame] | 2389 | if (new->prefix && |
| 2390 | (star = strrchr(new->prefix, '*')) |
| 2391 | && *(star+1) == 0) |
Simon Kelley | 6b2b564 | 2018-03-10 18:12:04 +0000 | [diff] [blame] | 2392 | { |
| 2393 | *star = 0; |
| 2394 | new->indexed = 1; |
| 2395 | } |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 2396 | } |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2397 | } |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 2398 | else if (option == 's') |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2399 | daemon->domain_suffix = d; |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 2400 | else |
| 2401 | ret_err(gen_err); |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2402 | } |
| 2403 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2404 | break; |
| 2405 | |
Simon Kelley | 1e50512 | 2016-01-25 21:29:23 +0000 | [diff] [blame] | 2406 | case LOPT_CPE_ID: /* --add-dns-client */ |
| 2407 | if (arg) |
Simon Kelley | 33702ab | 2015-12-28 23:17:15 +0000 | [diff] [blame] | 2408 | daemon->dns_client_id = opt_string_alloc(arg); |
| 2409 | break; |
| 2410 | |
Simon Kelley | c7f3bd2 | 2016-02-28 21:48:34 +0000 | [diff] [blame] | 2411 | case LOPT_ADD_MAC: /* --add-mac */ |
Simon Kelley | 1e50512 | 2016-01-25 21:29:23 +0000 | [diff] [blame] | 2412 | if (!arg) |
| 2413 | set_option_bool(OPT_ADD_MAC); |
| 2414 | else |
| 2415 | { |
| 2416 | unhide_metas(arg); |
| 2417 | if (strcmp(arg, "base64") == 0) |
| 2418 | set_option_bool(OPT_MAC_B64); |
Simon Kelley | 9e4cf47 | 2016-02-17 20:26:32 +0000 | [diff] [blame] | 2419 | else if (strcmp(arg, "text") == 0) |
| 2420 | set_option_bool(OPT_MAC_HEX); |
Simon Kelley | 22c0f4f | 2016-02-17 22:12:31 +0000 | [diff] [blame] | 2421 | else |
| 2422 | ret_err(gen_err); |
Simon Kelley | 1e50512 | 2016-01-25 21:29:23 +0000 | [diff] [blame] | 2423 | } |
| 2424 | break; |
| 2425 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2426 | case 'u': /* --user */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2427 | daemon->username = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2428 | break; |
| 2429 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2430 | case 'g': /* --group */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2431 | daemon->groupname = opt_string_alloc(arg); |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 2432 | daemon->group_set = 1; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2433 | break; |
Simon Kelley | 9e03894 | 2008-05-30 20:06:34 +0100 | [diff] [blame] | 2434 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2435 | #ifdef HAVE_DHCP |
Simon Kelley | 9e03894 | 2008-05-30 20:06:34 +0100 | [diff] [blame] | 2436 | case LOPT_SCRIPTUSR: /* --scriptuser */ |
| 2437 | daemon->scriptuser = opt_string_alloc(arg); |
| 2438 | break; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2439 | #endif |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2440 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2441 | case 'i': /* --interface */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2442 | do { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2443 | struct iname *new = opt_malloc(sizeof(struct iname)); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2444 | comma = split(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2445 | new->next = daemon->if_names; |
| 2446 | daemon->if_names = new; |
| 2447 | /* new->name may be NULL if someone does |
| 2448 | "interface=" to disable all interfaces except loop. */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2449 | new->name = opt_string_alloc(arg); |
Simon Kelley | 4ce4f37 | 2012-06-14 11:50:45 +0100 | [diff] [blame] | 2450 | new->used = 0; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2451 | arg = comma; |
| 2452 | } while (arg); |
| 2453 | break; |
| 2454 | |
Simon Kelley | 2937f8a | 2013-07-29 19:49:07 +0100 | [diff] [blame] | 2455 | case LOPT_TFTP: /* --enable-tftp */ |
| 2456 | set_option_bool(OPT_TFTP); |
| 2457 | if (!arg) |
| 2458 | break; |
| 2459 | /* fall through */ |
| 2460 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2461 | case 'I': /* --except-interface */ |
| 2462 | case '2': /* --no-dhcp-interface */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2463 | do { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2464 | struct iname *new = opt_malloc(sizeof(struct iname)); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2465 | comma = split(arg); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2466 | new->name = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2467 | if (option == 'I') |
| 2468 | { |
| 2469 | new->next = daemon->if_except; |
| 2470 | daemon->if_except = new; |
| 2471 | } |
Simon Kelley | 2937f8a | 2013-07-29 19:49:07 +0100 | [diff] [blame] | 2472 | else if (option == LOPT_TFTP) |
| 2473 | { |
| 2474 | new->next = daemon->tftp_interfaces; |
| 2475 | daemon->tftp_interfaces = new; |
| 2476 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2477 | else |
| 2478 | { |
| 2479 | new->next = daemon->dhcp_except; |
| 2480 | daemon->dhcp_except = new; |
| 2481 | } |
| 2482 | arg = comma; |
| 2483 | } while (arg); |
| 2484 | break; |
| 2485 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2486 | case 'B': /* --bogus-nxdomain */ |
Glen Huang | 32fc6db | 2014-12-27 15:28:12 +0000 | [diff] [blame] | 2487 | case LOPT_IGNORE_ADDR: /* --ignore-address */ |
| 2488 | { |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2489 | struct in_addr addr; |
Simon Kelley | 9eaa91b | 2021-03-17 20:31:06 +0000 | [diff] [blame^] | 2490 | int prefix = 32; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2491 | unhide_metas(arg); |
Simon Kelley | 9eaa91b | 2021-03-17 20:31:06 +0000 | [diff] [blame^] | 2492 | |
| 2493 | if (!arg || |
| 2494 | ((comma = split_chr(arg, '/')) && !atoi_check(comma, &prefix)) || |
| 2495 | (inet_pton(AF_INET, arg, &addr) != 1)) |
| 2496 | ret_err(gen_err); /* error */ |
| 2497 | else |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2498 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2499 | struct bogus_addr *baddr = opt_malloc(sizeof(struct bogus_addr)); |
Glen Huang | 32fc6db | 2014-12-27 15:28:12 +0000 | [diff] [blame] | 2500 | if (option == 'B') |
| 2501 | { |
| 2502 | baddr->next = daemon->bogus_addr; |
| 2503 | daemon->bogus_addr = baddr; |
| 2504 | } |
| 2505 | else |
| 2506 | { |
| 2507 | baddr->next = daemon->ignore_addr; |
| 2508 | daemon->ignore_addr = baddr; |
| 2509 | } |
Simon Kelley | 9eaa91b | 2021-03-17 20:31:06 +0000 | [diff] [blame^] | 2510 | baddr->mask.s_addr = htonl(~((1 << (32 - prefix)) - 1)); |
| 2511 | baddr->addr.s_addr = addr.s_addr & baddr->mask.s_addr; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2512 | } |
Simon Kelley | 9eaa91b | 2021-03-17 20:31:06 +0000 | [diff] [blame^] | 2513 | break; |
| 2514 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2515 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2516 | case 'a': /* --listen-address */ |
Simon Kelley | 4967876 | 2012-12-09 18:24:58 +0000 | [diff] [blame] | 2517 | case LOPT_AUTHPEER: /* --auth-peer */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2518 | do { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2519 | struct iname *new = opt_malloc(sizeof(struct iname)); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2520 | comma = split(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2521 | unhide_metas(arg); |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 2522 | if (arg && (inet_pton(AF_INET, arg, &new->addr.in.sin_addr) > 0)) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2523 | { |
| 2524 | new->addr.sa.sa_family = AF_INET; |
Simon Kelley | 4967876 | 2012-12-09 18:24:58 +0000 | [diff] [blame] | 2525 | new->addr.in.sin_port = 0; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2526 | #ifdef HAVE_SOCKADDR_SA_LEN |
| 2527 | new->addr.in.sin_len = sizeof(new->addr.in); |
| 2528 | #endif |
| 2529 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2530 | else if (arg && inet_pton(AF_INET6, arg, &new->addr.in6.sin6_addr) > 0) |
| 2531 | { |
| 2532 | new->addr.sa.sa_family = AF_INET6; |
| 2533 | new->addr.in6.sin6_flowinfo = 0; |
| 2534 | new->addr.in6.sin6_scope_id = 0; |
Simon Kelley | 4967876 | 2012-12-09 18:24:58 +0000 | [diff] [blame] | 2535 | new->addr.in6.sin6_port = 0; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2536 | #ifdef HAVE_SOCKADDR_SA_LEN |
| 2537 | new->addr.in6.sin6_len = sizeof(new->addr.in6); |
| 2538 | #endif |
| 2539 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2540 | else |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2541 | ret_err_free(gen_err, new); |
Simon Kelley | 4ce4f37 | 2012-06-14 11:50:45 +0100 | [diff] [blame] | 2542 | |
| 2543 | new->used = 0; |
Simon Kelley | 4967876 | 2012-12-09 18:24:58 +0000 | [diff] [blame] | 2544 | if (option == 'a') |
| 2545 | { |
| 2546 | new->next = daemon->if_addrs; |
| 2547 | daemon->if_addrs = new; |
| 2548 | } |
| 2549 | else |
| 2550 | { |
| 2551 | new->next = daemon->auth_peers; |
| 2552 | daemon->auth_peers = new; |
| 2553 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2554 | arg = comma; |
| 2555 | } while (arg); |
| 2556 | break; |
| 2557 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2558 | case 'S': /* --server */ |
| 2559 | case LOPT_LOCAL: /* --local */ |
| 2560 | case 'A': /* --address */ |
| 2561 | case LOPT_NO_REBIND: /* --rebind-domain-ok */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2562 | { |
| 2563 | struct server *serv, *newlist = NULL; |
| 2564 | |
| 2565 | unhide_metas(arg); |
| 2566 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2567 | if (arg && (*arg == '/' || option == LOPT_NO_REBIND)) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2568 | { |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2569 | int rebind = !(*arg == '/'); |
| 2570 | char *end = NULL; |
| 2571 | if (!rebind) |
| 2572 | arg++; |
| 2573 | while (rebind || (end = split_chr(arg, '/'))) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2574 | { |
| 2575 | char *domain = NULL; |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2576 | /* elide leading dots - they are implied in the search algorithm */ |
| 2577 | while (*arg == '.') arg++; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2578 | /* # matches everything and becomes a zero length domain string */ |
| 2579 | if (strcmp(arg, "#") == 0) |
| 2580 | domain = ""; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 2581 | else if (strlen (arg) != 0 && !(domain = canonicalise_opt(arg))) |
Simon Kelley | a3bd7e7 | 2018-07-19 22:00:08 +0100 | [diff] [blame] | 2582 | ret_err(gen_err); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2583 | serv = opt_malloc(sizeof(struct server)); |
| 2584 | memset(serv, 0, sizeof(struct server)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2585 | serv->next = newlist; |
| 2586 | newlist = serv; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2587 | serv->domain = domain; |
| 2588 | serv->flags = domain ? SERV_HAS_DOMAIN : SERV_FOR_NODOTS; |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 2589 | arg = end; |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2590 | if (rebind) |
| 2591 | break; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2592 | } |
| 2593 | if (!newlist) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2594 | ret_err(gen_err); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2595 | } |
| 2596 | else |
| 2597 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2598 | newlist = opt_malloc(sizeof(struct server)); |
| 2599 | memset(newlist, 0, sizeof(struct server)); |
Simon Kelley | b5ea1cc | 2014-07-29 16:34:14 +0100 | [diff] [blame] | 2600 | #ifdef HAVE_LOOP |
| 2601 | newlist->uid = rand32(); |
| 2602 | #endif |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2603 | } |
| 2604 | |
Simon Kelley | 7b1eae4 | 2014-02-20 13:43:28 +0000 | [diff] [blame] | 2605 | if (servers_only && option == 'S') |
| 2606 | newlist->flags |= SERV_FROM_FILE; |
| 2607 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2608 | if (option == 'A') |
| 2609 | { |
| 2610 | newlist->flags |= SERV_LITERAL_ADDRESS; |
| 2611 | if (!(newlist->flags & SERV_TYPE)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2612 | { |
| 2613 | server_list_free(newlist); |
| 2614 | ret_err(gen_err); |
| 2615 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2616 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2617 | else if (option == LOPT_NO_REBIND) |
| 2618 | newlist->flags |= SERV_NO_REBIND; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2619 | |
| 2620 | if (!arg || !*arg) |
| 2621 | { |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2622 | if (!(newlist->flags & SERV_NO_REBIND)) |
| 2623 | newlist->flags |= SERV_NO_ADDR; /* no server */ |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2624 | } |
| 2625 | |
| 2626 | else if (strcmp(arg, "#") == 0) |
Simon Kelley | da8b651 | 2018-09-03 23:18:36 +0100 | [diff] [blame] | 2627 | newlist->flags |= SERV_USE_RESOLV; /* treat in ordinary way */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2628 | else |
| 2629 | { |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 2630 | char *err = parse_server(arg, &newlist->addr, &newlist->source_addr, newlist->interface, &newlist->flags); |
| 2631 | if (err) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2632 | { |
| 2633 | server_list_free(newlist); |
| 2634 | ret_err(err); |
| 2635 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2636 | } |
| 2637 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2638 | serv = newlist; |
| 2639 | while (serv->next) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2640 | { |
Simon Kelley | d9603ef | 2020-01-26 18:13:35 +0000 | [diff] [blame] | 2641 | serv->next->flags |= serv->flags & ~(SERV_HAS_DOMAIN | SERV_FOR_NODOTS); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2642 | serv->next->addr = serv->addr; |
| 2643 | serv->next->source_addr = serv->source_addr; |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 2644 | strcpy(serv->next->interface, serv->interface); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2645 | serv = serv->next; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2646 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2647 | serv->next = daemon->servers; |
| 2648 | daemon->servers = newlist; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2649 | break; |
| 2650 | } |
Jason A. Donenfeld | 13d86c7 | 2013-02-22 18:20:53 +0000 | [diff] [blame] | 2651 | |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2652 | case LOPT_REV_SERV: /* --rev-server */ |
| 2653 | { |
| 2654 | char *string; |
| 2655 | int size; |
| 2656 | struct server *serv; |
| 2657 | struct in_addr addr4; |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2658 | struct in6_addr addr6; |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2659 | |
| 2660 | unhide_metas(arg); |
Simon Kelley | a9b022a | 2020-02-11 21:58:59 +0000 | [diff] [blame] | 2661 | if (!arg) |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2662 | ret_err(gen_err); |
Simon Kelley | a9b022a | 2020-02-11 21:58:59 +0000 | [diff] [blame] | 2663 | |
| 2664 | comma=split(arg); |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2665 | |
Simon Kelley | a9b022a | 2020-02-11 21:58:59 +0000 | [diff] [blame] | 2666 | if (!(string = split_chr(arg, '/')) || !atoi_check(string, &size)) |
| 2667 | ret_err(gen_err); |
| 2668 | |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2669 | if (inet_pton(AF_INET, arg, &addr4)) |
Olivier Gayot | dc99058 | 2017-03-06 22:17:21 +0000 | [diff] [blame] | 2670 | { |
| 2671 | serv = add_rev4(addr4, size); |
| 2672 | if (!serv) |
| 2673 | ret_err(_("bad prefix")); |
| 2674 | } |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2675 | else if (inet_pton(AF_INET6, arg, &addr6)) |
| 2676 | serv = add_rev6(&addr6, size); |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2677 | else |
| 2678 | ret_err(gen_err); |
| 2679 | |
| 2680 | string = parse_server(comma, &serv->addr, &serv->source_addr, serv->interface, &serv->flags); |
| 2681 | |
| 2682 | if (string) |
| 2683 | ret_err(string); |
Simon Kelley | 7b1eae4 | 2014-02-20 13:43:28 +0000 | [diff] [blame] | 2684 | |
| 2685 | if (servers_only) |
| 2686 | serv->flags |= SERV_FROM_FILE; |
| 2687 | |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2688 | break; |
| 2689 | } |
| 2690 | |
Jason A. Donenfeld | 13d86c7 | 2013-02-22 18:20:53 +0000 | [diff] [blame] | 2691 | case LOPT_IPSET: /* --ipset */ |
| 2692 | #ifndef HAVE_IPSET |
| 2693 | ret_err(_("recompile with HAVE_IPSET defined to enable ipset directives")); |
| 2694 | break; |
| 2695 | #else |
| 2696 | { |
| 2697 | struct ipsets ipsets_head; |
| 2698 | struct ipsets *ipsets = &ipsets_head; |
| 2699 | int size; |
| 2700 | char *end; |
| 2701 | char **sets, **sets_pos; |
| 2702 | memset(ipsets, 0, sizeof(struct ipsets)); |
| 2703 | unhide_metas(arg); |
| 2704 | if (arg && *arg == '/') |
| 2705 | { |
| 2706 | arg++; |
| 2707 | while ((end = split_chr(arg, '/'))) |
| 2708 | { |
| 2709 | char *domain = NULL; |
| 2710 | /* elide leading dots - they are implied in the search algorithm */ |
| 2711 | while (*arg == '.') |
| 2712 | arg++; |
| 2713 | /* # matches everything and becomes a zero length domain string */ |
| 2714 | if (strcmp(arg, "#") == 0 || !*arg) |
| 2715 | domain = ""; |
| 2716 | else if (strlen(arg) != 0 && !(domain = canonicalise_opt(arg))) |
Simon Kelley | a3bd7e7 | 2018-07-19 22:00:08 +0100 | [diff] [blame] | 2717 | ret_err(gen_err); |
Jason A. Donenfeld | 13d86c7 | 2013-02-22 18:20:53 +0000 | [diff] [blame] | 2718 | ipsets->next = opt_malloc(sizeof(struct ipsets)); |
| 2719 | ipsets = ipsets->next; |
| 2720 | memset(ipsets, 0, sizeof(struct ipsets)); |
| 2721 | ipsets->domain = domain; |
| 2722 | arg = end; |
| 2723 | } |
| 2724 | } |
| 2725 | else |
| 2726 | { |
| 2727 | ipsets->next = opt_malloc(sizeof(struct ipsets)); |
| 2728 | ipsets = ipsets->next; |
| 2729 | memset(ipsets, 0, sizeof(struct ipsets)); |
| 2730 | ipsets->domain = ""; |
| 2731 | } |
Simon Kelley | a3bd7e7 | 2018-07-19 22:00:08 +0100 | [diff] [blame] | 2732 | |
Jason A. Donenfeld | 13d86c7 | 2013-02-22 18:20:53 +0000 | [diff] [blame] | 2733 | if (!arg || !*arg) |
Simon Kelley | a3bd7e7 | 2018-07-19 22:00:08 +0100 | [diff] [blame] | 2734 | ret_err(gen_err); |
| 2735 | |
| 2736 | for (size = 2, end = arg; *end; ++end) |
Jason A. Donenfeld | 13d86c7 | 2013-02-22 18:20:53 +0000 | [diff] [blame] | 2737 | if (*end == ',') |
| 2738 | ++size; |
| 2739 | |
| 2740 | sets = sets_pos = opt_malloc(sizeof(char *) * size); |
| 2741 | |
| 2742 | do { |
| 2743 | end = split(arg); |
| 2744 | *sets_pos++ = opt_string_alloc(arg); |
| 2745 | arg = end; |
| 2746 | } while (end); |
| 2747 | *sets_pos = 0; |
| 2748 | for (ipsets = &ipsets_head; ipsets->next; ipsets = ipsets->next) |
| 2749 | ipsets->next->sets = sets; |
| 2750 | ipsets->next = daemon->ipsets; |
| 2751 | daemon->ipsets = ipsets_head.next; |
| 2752 | |
| 2753 | break; |
| 2754 | } |
| 2755 | #endif |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2756 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2757 | case 'c': /* --cache-size */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2758 | { |
| 2759 | int size; |
| 2760 | |
| 2761 | if (!atoi_check(arg, &size)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2762 | ret_err(gen_err); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2763 | else |
| 2764 | { |
| 2765 | /* zero is OK, and means no caching. */ |
| 2766 | |
| 2767 | if (size < 0) |
| 2768 | size = 0; |
Simon Kelley | 248efe8 | 2019-08-20 23:36:49 +0100 | [diff] [blame] | 2769 | |
| 2770 | /* Note that for very large cache sizes, the malloc() |
| 2771 | will overflow. For the size of the cache record |
| 2772 | at the time this was noted, the value of "very large" |
| 2773 | was 46684428. Limit to an order of magnitude less than |
| 2774 | that to be safe from changes to the cache record. */ |
| 2775 | if (size > 5000000) |
| 2776 | size = 5000000; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2777 | |
| 2778 | daemon->cachesize = size; |
| 2779 | } |
| 2780 | break; |
| 2781 | } |
| 2782 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2783 | case 'p': /* --port */ |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 2784 | if (!atoi_check16(arg, &daemon->port)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2785 | ret_err(gen_err); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2786 | break; |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 2787 | |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 2788 | case LOPT_MINPORT: /* --min-port */ |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 2789 | if (!atoi_check16(arg, &daemon->min_port)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2790 | ret_err(gen_err); |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 2791 | break; |
| 2792 | |
Hans Dedecker | 926332a | 2016-01-23 10:48:12 +0000 | [diff] [blame] | 2793 | case LOPT_MAXPORT: /* --max-port */ |
| 2794 | if (!atoi_check16(arg, &daemon->max_port)) |
| 2795 | ret_err(gen_err); |
| 2796 | break; |
| 2797 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2798 | case '0': /* --dns-forward-max */ |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 2799 | if (!atoi_check(arg, &daemon->ftabsize)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2800 | ret_err(gen_err); |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 2801 | break; |
| 2802 | |
Simon Kelley | 25cf5e3 | 2015-01-09 15:53:03 +0000 | [diff] [blame] | 2803 | case 'q': /* --log-queries */ |
| 2804 | set_option_bool(OPT_LOG); |
| 2805 | if (arg && strcmp(arg, "extra") == 0) |
| 2806 | set_option_bool(OPT_EXTRALOG); |
| 2807 | break; |
| 2808 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2809 | case LOPT_MAX_LOGS: /* --log-async */ |
| 2810 | daemon->max_logs = LOG_MAX; /* default */ |
| 2811 | if (arg && !atoi_check(arg, &daemon->max_logs)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2812 | ret_err(gen_err); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2813 | else if (daemon->max_logs > 100) |
| 2814 | daemon->max_logs = 100; |
| 2815 | break; |
| 2816 | |
| 2817 | case 'P': /* --edns-packet-max */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2818 | { |
| 2819 | int i; |
| 2820 | if (!atoi_check(arg, &i)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2821 | ret_err(gen_err); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2822 | daemon->edns_pktsz = (unsigned short)i; |
| 2823 | break; |
| 2824 | } |
| 2825 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2826 | case 'Q': /* --query-port */ |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 2827 | if (!atoi_check16(arg, &daemon->query_port)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2828 | ret_err(gen_err); |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 2829 | /* if explicitly set to zero, use single OS ephemeral port |
| 2830 | and disable random ports */ |
| 2831 | if (daemon->query_port == 0) |
| 2832 | daemon->osport = 1; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2833 | break; |
| 2834 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2835 | case 'T': /* --local-ttl */ |
| 2836 | case LOPT_NEGTTL: /* --neg-ttl */ |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2837 | case LOPT_MAXTTL: /* --max-ttl */ |
RinSatsuki | 28de387 | 2015-01-10 15:22:21 +0000 | [diff] [blame] | 2838 | case LOPT_MINCTTL: /* --min-cache-ttl */ |
Simon Kelley | 1d86041 | 2012-09-20 20:48:04 +0100 | [diff] [blame] | 2839 | case LOPT_MAXCTTL: /* --max-cache-ttl */ |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2840 | case LOPT_AUTHTTL: /* --auth-ttl */ |
Simon Kelley | 832e47b | 2016-02-24 21:24:45 +0000 | [diff] [blame] | 2841 | case LOPT_DHCPTTL: /* --dhcp-ttl */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2842 | { |
| 2843 | int ttl; |
| 2844 | if (!atoi_check(arg, &ttl)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2845 | ret_err(gen_err); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2846 | else if (option == LOPT_NEGTTL) |
| 2847 | daemon->neg_ttl = (unsigned long)ttl; |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2848 | else if (option == LOPT_MAXTTL) |
| 2849 | daemon->max_ttl = (unsigned long)ttl; |
RinSatsuki | 28de387 | 2015-01-10 15:22:21 +0000 | [diff] [blame] | 2850 | else if (option == LOPT_MINCTTL) |
| 2851 | { |
| 2852 | if (ttl > TTL_FLOOR_LIMIT) |
| 2853 | ttl = TTL_FLOOR_LIMIT; |
| 2854 | daemon->min_cache_ttl = (unsigned long)ttl; |
| 2855 | } |
Simon Kelley | 1d86041 | 2012-09-20 20:48:04 +0100 | [diff] [blame] | 2856 | else if (option == LOPT_MAXCTTL) |
| 2857 | daemon->max_cache_ttl = (unsigned long)ttl; |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2858 | else if (option == LOPT_AUTHTTL) |
| 2859 | daemon->auth_ttl = (unsigned long)ttl; |
Simon Kelley | 832e47b | 2016-02-24 21:24:45 +0000 | [diff] [blame] | 2860 | else if (option == LOPT_DHCPTTL) |
| 2861 | { |
| 2862 | daemon->dhcp_ttl = (unsigned long)ttl; |
| 2863 | daemon->use_dhcp_ttl = 1; |
| 2864 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2865 | else |
| 2866 | daemon->local_ttl = (unsigned long)ttl; |
| 2867 | break; |
| 2868 | } |
| 2869 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2870 | #ifdef HAVE_DHCP |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2871 | case 'X': /* --dhcp-lease-max */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2872 | if (!atoi_check(arg, &daemon->dhcp_max)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2873 | ret_err(gen_err); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2874 | break; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2875 | #endif |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2876 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2877 | #ifdef HAVE_TFTP |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2878 | case LOPT_TFTP_MAX: /* --tftp-max */ |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2879 | if (!atoi_check(arg, &daemon->tftp_max)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2880 | ret_err(gen_err); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2881 | break; |
| 2882 | |
Simon Kelley | bec366b | 2016-02-24 22:03:26 +0000 | [diff] [blame] | 2883 | case LOPT_TFTP_MTU: /* --tftp-mtu */ |
| 2884 | if (!atoi_check(arg, &daemon->tftp_mtu)) |
| 2885 | ret_err(gen_err); |
| 2886 | break; |
| 2887 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2888 | case LOPT_PREFIX: /* --tftp-prefix */ |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2889 | comma = split(arg); |
| 2890 | if (comma) |
| 2891 | { |
| 2892 | struct tftp_prefix *new = opt_malloc(sizeof(struct tftp_prefix)); |
| 2893 | new->interface = opt_string_alloc(comma); |
| 2894 | new->prefix = opt_string_alloc(arg); |
| 2895 | new->next = daemon->if_prefix; |
| 2896 | daemon->if_prefix = new; |
| 2897 | } |
| 2898 | else |
| 2899 | daemon->tftp_prefix = opt_string_alloc(arg); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2900 | break; |
| 2901 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2902 | case LOPT_TFTPPORTS: /* --tftp-port-range */ |
| 2903 | if (!(comma = split(arg)) || |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 2904 | !atoi_check16(arg, &daemon->start_tftp_port) || |
| 2905 | !atoi_check16(comma, &daemon->end_tftp_port)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2906 | ret_err(_("bad port range")); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2907 | |
| 2908 | if (daemon->start_tftp_port > daemon->end_tftp_port) |
| 2909 | { |
| 2910 | int tmp = daemon->start_tftp_port; |
| 2911 | daemon->start_tftp_port = daemon->end_tftp_port; |
| 2912 | daemon->end_tftp_port = tmp; |
| 2913 | } |
| 2914 | |
| 2915 | break; |
Floris Bos | 60704f5 | 2017-04-09 22:22:49 +0100 | [diff] [blame] | 2916 | |
| 2917 | case LOPT_APREF: /* --tftp-unique-root */ |
| 2918 | if (!arg || strcasecmp(arg, "ip") == 0) |
| 2919 | set_option_bool(OPT_TFTP_APREF_IP); |
| 2920 | else if (strcasecmp(arg, "mac") == 0) |
| 2921 | set_option_bool(OPT_TFTP_APREF_MAC); |
| 2922 | else |
| 2923 | ret_err(gen_err); |
| 2924 | break; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2925 | #endif |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2926 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2927 | case LOPT_BRIDGE: /* --bridge-interface */ |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2928 | { |
Simon Kelley | 22cd860 | 2018-01-14 22:57:14 +0000 | [diff] [blame] | 2929 | struct dhcp_bridge *new; |
| 2930 | |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 2931 | if (!(comma = split(arg)) || strlen(arg) > IF_NAMESIZE - 1 ) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2932 | ret_err(_("bad bridge-interface")); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2933 | |
Simon Kelley | 22cd860 | 2018-01-14 22:57:14 +0000 | [diff] [blame] | 2934 | for (new = daemon->bridges; new; new = new->next) |
| 2935 | if (strcmp(new->iface, arg) == 0) |
| 2936 | break; |
| 2937 | |
| 2938 | if (!new) |
| 2939 | { |
| 2940 | new = opt_malloc(sizeof(struct dhcp_bridge)); |
| 2941 | strcpy(new->iface, arg); |
| 2942 | new->alias = NULL; |
| 2943 | new->next = daemon->bridges; |
| 2944 | daemon->bridges = new; |
| 2945 | } |
| 2946 | |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2947 | do { |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2948 | arg = comma; |
| 2949 | comma = split(arg); |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 2950 | if (strlen(arg) != 0 && strlen(arg) <= IF_NAMESIZE - 1) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2951 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2952 | struct dhcp_bridge *b = opt_malloc(sizeof(struct dhcp_bridge)); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2953 | b->next = new->alias; |
| 2954 | new->alias = b; |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 2955 | strcpy(b->iface, arg); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2956 | } |
| 2957 | } while (comma); |
| 2958 | |
| 2959 | break; |
| 2960 | } |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2961 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2962 | #ifdef HAVE_DHCP |
Simon Kelley | ae5b7e0 | 2019-03-27 22:33:28 +0000 | [diff] [blame] | 2963 | case LOPT_SHARED_NET: /* --shared-network */ |
| 2964 | { |
| 2965 | struct shared_network *new = opt_malloc(sizeof(struct shared_network)); |
| 2966 | |
| 2967 | #ifdef HAVE_DHCP6 |
| 2968 | new->shared_addr.s_addr = 0; |
| 2969 | #endif |
| 2970 | new->if_index = 0; |
| 2971 | |
| 2972 | if (!(comma = split(arg))) |
| 2973 | { |
| 2974 | snerr: |
| 2975 | free(new); |
| 2976 | ret_err(_("bad shared-network")); |
| 2977 | } |
| 2978 | |
| 2979 | if (inet_pton(AF_INET, comma, &new->shared_addr)) |
| 2980 | { |
| 2981 | if (!inet_pton(AF_INET, arg, &new->match_addr) && |
| 2982 | !(new->if_index = if_nametoindex(arg))) |
| 2983 | goto snerr; |
| 2984 | } |
| 2985 | #ifdef HAVE_DHCP6 |
| 2986 | else if (inet_pton(AF_INET6, comma, &new->shared_addr6)) |
| 2987 | { |
| 2988 | if (!inet_pton(AF_INET6, arg, &new->match_addr6) && |
| 2989 | !(new->if_index = if_nametoindex(arg))) |
| 2990 | goto snerr; |
| 2991 | } |
| 2992 | #endif |
| 2993 | else |
| 2994 | goto snerr; |
| 2995 | |
| 2996 | new->next = daemon->shared_networks; |
| 2997 | daemon->shared_networks = new; |
| 2998 | break; |
| 2999 | } |
| 3000 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3001 | case 'F': /* --dhcp-range */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3002 | { |
| 3003 | int k, leasepos = 2; |
Simon Kelley | 8445f5d | 2012-12-17 21:54:08 +0000 | [diff] [blame] | 3004 | char *cp, *a[8] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3005 | struct dhcp_context *new = opt_malloc(sizeof(struct dhcp_context)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3006 | |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3007 | memset (new, 0, sizeof(*new)); |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3008 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3009 | while(1) |
| 3010 | { |
| 3011 | for (cp = arg; *cp; cp++) |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3012 | if (!(*cp == ' ' || *cp == '.' || *cp == ':' || |
| 3013 | (*cp >= 'a' && *cp <= 'f') || (*cp >= 'A' && *cp <= 'F') || |
| 3014 | (*cp >='0' && *cp <= '9'))) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3015 | break; |
| 3016 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3017 | if (*cp != ',' && (comma = split(arg))) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3018 | { |
Simon Kelley | 8bc4cec | 2012-07-03 21:04:11 +0100 | [diff] [blame] | 3019 | if (is_tag_prefix(arg)) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3020 | { |
Simon Kelley | 0c38719 | 2013-09-05 10:21:12 +0100 | [diff] [blame] | 3021 | /* ignore empty tag */ |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3022 | if (arg[4]) |
| 3023 | new->filter = dhcp_netid_create(arg+4, new->filter); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3024 | } |
| 3025 | else |
| 3026 | { |
| 3027 | if (new->netid.net) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3028 | { |
| 3029 | dhcp_context_free(new); |
| 3030 | ret_err(_("only one tag allowed")); |
| 3031 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3032 | else |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3033 | new->netid.net = opt_string_alloc(set_prefix(arg)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3034 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3035 | arg = comma; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3036 | } |
| 3037 | else |
| 3038 | { |
| 3039 | a[0] = arg; |
| 3040 | break; |
| 3041 | } |
| 3042 | } |
| 3043 | |
Simon Kelley | 1f77693 | 2012-12-16 19:46:08 +0000 | [diff] [blame] | 3044 | for (k = 1; k < 8; k++) |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3045 | if (!(a[k] = split(a[k-1]))) |
| 3046 | break; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3047 | |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3048 | if (k < 2) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3049 | { |
| 3050 | dhcp_context_free(new); |
| 3051 | ret_err(_("bad dhcp-range")); |
| 3052 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3053 | |
| 3054 | if (inet_pton(AF_INET, a[0], &new->start)) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3055 | { |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3056 | new->next = daemon->dhcp; |
Simon Kelley | 4d85e40 | 2020-07-12 22:45:46 +0100 | [diff] [blame] | 3057 | new->lease_time = DEFLEASE; |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3058 | daemon->dhcp = new; |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3059 | new->end = new->start; |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3060 | if (strcmp(a[1], "static") == 0) |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3061 | new->flags |= CONTEXT_STATIC; |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3062 | else if (strcmp(a[1], "proxy") == 0) |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3063 | new->flags |= CONTEXT_PROXY; |
| 3064 | else if (!inet_pton(AF_INET, a[1], &new->end)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3065 | { |
| 3066 | dhcp_context_free(new); |
| 3067 | ret_err(_("bad dhcp-range")); |
| 3068 | } |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3069 | |
| 3070 | if (ntohl(new->start.s_addr) > ntohl(new->end.s_addr)) |
| 3071 | { |
| 3072 | struct in_addr tmp = new->start; |
| 3073 | new->start = new->end; |
| 3074 | new->end = tmp; |
| 3075 | } |
| 3076 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3077 | if (k >= 3 && strchr(a[2], '.') && |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 3078 | (inet_pton(AF_INET, a[2], &new->netmask) > 0)) |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3079 | { |
| 3080 | new->flags |= CONTEXT_NETMASK; |
| 3081 | leasepos = 3; |
| 3082 | if (!is_same_net(new->start, new->end, new->netmask)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3083 | { |
| 3084 | dhcp_context_free(new); |
| 3085 | ret_err(_("inconsistent DHCP range")); |
| 3086 | } |
Simon Kelley | fa79466 | 2016-03-03 20:33:54 +0000 | [diff] [blame] | 3087 | |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3088 | |
Simon Kelley | fa79466 | 2016-03-03 20:33:54 +0000 | [diff] [blame] | 3089 | if (k >= 4 && strchr(a[3], '.') && |
| 3090 | (inet_pton(AF_INET, a[3], &new->broadcast) > 0)) |
| 3091 | { |
| 3092 | new->flags |= CONTEXT_BRDCAST; |
| 3093 | leasepos = 4; |
| 3094 | } |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3095 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3096 | } |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3097 | #ifdef HAVE_DHCP6 |
| 3098 | else if (inet_pton(AF_INET6, a[0], &new->start6)) |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3099 | { |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3100 | const char *err = NULL; |
| 3101 | |
Simon Kelley | 89500e3 | 2013-09-20 16:29:20 +0100 | [diff] [blame] | 3102 | new->flags |= CONTEXT_V6; |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3103 | new->prefix = 64; /* default */ |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3104 | new->end6 = new->start6; |
Simon Kelley | 4d85e40 | 2020-07-12 22:45:46 +0100 | [diff] [blame] | 3105 | new->lease_time = DEFLEASE6; |
Simon Kelley | 6692a1a | 2013-08-20 14:41:31 +0100 | [diff] [blame] | 3106 | new->next = daemon->dhcp6; |
| 3107 | daemon->dhcp6 = new; |
| 3108 | |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3109 | for (leasepos = 1; leasepos < k; leasepos++) |
| 3110 | { |
| 3111 | if (strcmp(a[leasepos], "static") == 0) |
| 3112 | new->flags |= CONTEXT_STATIC | CONTEXT_DHCP; |
| 3113 | else if (strcmp(a[leasepos], "ra-only") == 0 || strcmp(a[leasepos], "slaac") == 0 ) |
Simon Kelley | 7ea3d3f | 2014-04-25 22:04:05 +0100 | [diff] [blame] | 3114 | new->flags |= CONTEXT_RA; |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3115 | else if (strcmp(a[leasepos], "ra-names") == 0) |
Simon Kelley | 1f77693 | 2012-12-16 19:46:08 +0000 | [diff] [blame] | 3116 | new->flags |= CONTEXT_RA_NAME | CONTEXT_RA; |
Simon Kelley | 7ea3d3f | 2014-04-25 22:04:05 +0100 | [diff] [blame] | 3117 | else if (strcmp(a[leasepos], "ra-advrouter") == 0) |
| 3118 | new->flags |= CONTEXT_RA_ROUTER | CONTEXT_RA; |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3119 | else if (strcmp(a[leasepos], "ra-stateless") == 0) |
Simon Kelley | 1f77693 | 2012-12-16 19:46:08 +0000 | [diff] [blame] | 3120 | new->flags |= CONTEXT_RA_STATELESS | CONTEXT_DHCP | CONTEXT_RA; |
Neil Jerram | 2fd5bc9 | 2015-06-10 22:13:06 +0100 | [diff] [blame] | 3121 | else if (strcmp(a[leasepos], "off-link") == 0) |
| 3122 | new->flags |= CONTEXT_RA_OFF_LINK; |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3123 | else if (leasepos == 1 && inet_pton(AF_INET6, a[leasepos], &new->end6)) |
| 3124 | new->flags |= CONTEXT_DHCP; |
Simon Kelley | 1f77693 | 2012-12-16 19:46:08 +0000 | [diff] [blame] | 3125 | else if (strstr(a[leasepos], "constructor:") == a[leasepos]) |
| 3126 | { |
| 3127 | new->template_interface = opt_string_alloc(a[leasepos] + 12); |
| 3128 | new->flags |= CONTEXT_TEMPLATE; |
| 3129 | } |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3130 | else |
| 3131 | break; |
| 3132 | } |
Simon Kelley | 6692a1a | 2013-08-20 14:41:31 +0100 | [diff] [blame] | 3133 | |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3134 | /* bare integer < 128 is prefix value */ |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3135 | if (leasepos < k) |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3136 | { |
| 3137 | int pref; |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3138 | for (cp = a[leasepos]; *cp; cp++) |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3139 | if (!(*cp >= '0' && *cp <= '9')) |
| 3140 | break; |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3141 | if (!*cp && (pref = atoi(a[leasepos])) <= 128) |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3142 | { |
| 3143 | new->prefix = pref; |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3144 | leasepos++; |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3145 | } |
| 3146 | } |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3147 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3148 | if (new->prefix > 64) |
Simon Kelley | 6692a1a | 2013-08-20 14:41:31 +0100 | [diff] [blame] | 3149 | { |
Simon Kelley | 7ea3d3f | 2014-04-25 22:04:05 +0100 | [diff] [blame] | 3150 | if (new->flags & CONTEXT_RA) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3151 | err=(_("prefix length must be exactly 64 for RA subnets")); |
Simon Kelley | 6692a1a | 2013-08-20 14:41:31 +0100 | [diff] [blame] | 3152 | else if (new->flags & CONTEXT_TEMPLATE) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3153 | err=(_("prefix length must be exactly 64 for subnet constructors")); |
Simon Kelley | 6692a1a | 2013-08-20 14:41:31 +0100 | [diff] [blame] | 3154 | } |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3155 | else if (new->prefix < 64) |
| 3156 | err=(_("prefix length must be at least 64")); |
Simon Kelley | 6692a1a | 2013-08-20 14:41:31 +0100 | [diff] [blame] | 3157 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3158 | if (!err && !is_same_net6(&new->start6, &new->end6, new->prefix)) |
| 3159 | err=(_("inconsistent DHCPv6 range")); |
| 3160 | |
| 3161 | if (err) |
| 3162 | { |
| 3163 | dhcp_context_free(new); |
| 3164 | ret_err(err); |
| 3165 | } |
Simon Kelley | 6692a1a | 2013-08-20 14:41:31 +0100 | [diff] [blame] | 3166 | |
| 3167 | /* dhcp-range=:: enables DHCP stateless on any interface */ |
| 3168 | if (IN6_IS_ADDR_UNSPECIFIED(&new->start6) && !(new->flags & CONTEXT_TEMPLATE)) |
| 3169 | new->prefix = 0; |
Simon Kelley | 6640919 | 2013-08-01 20:19:32 +0100 | [diff] [blame] | 3170 | |
| 3171 | if (new->flags & CONTEXT_TEMPLATE) |
| 3172 | { |
| 3173 | struct in6_addr zero; |
| 3174 | memset(&zero, 0, sizeof(zero)); |
| 3175 | if (!is_same_net6(&zero, &new->start6, new->prefix)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3176 | { |
| 3177 | dhcp_context_free(new); |
| 3178 | ret_err(_("prefix must be zero with \"constructor:\" argument")); |
| 3179 | } |
Simon Kelley | 6640919 | 2013-08-01 20:19:32 +0100 | [diff] [blame] | 3180 | } |
| 3181 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3182 | if (addr6part(&new->start6) > addr6part(&new->end6)) |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3183 | { |
| 3184 | struct in6_addr tmp = new->start6; |
| 3185 | new->start6 = new->end6; |
| 3186 | new->end6 = tmp; |
| 3187 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3188 | } |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3189 | #endif |
Simon Kelley | d9ee9c0 | 2013-04-12 11:17:55 +0100 | [diff] [blame] | 3190 | else |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3191 | { |
| 3192 | dhcp_context_free(new); |
| 3193 | ret_err(_("bad dhcp-range")); |
| 3194 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3195 | |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3196 | if (leasepos < k) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3197 | { |
Simon Kelley | fa79466 | 2016-03-03 20:33:54 +0000 | [diff] [blame] | 3198 | if (leasepos != k-1) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3199 | { |
| 3200 | dhcp_context_free(new); |
| 3201 | ret_err(_("bad dhcp-range")); |
| 3202 | } |
Simon Kelley | fa79466 | 2016-03-03 20:33:54 +0000 | [diff] [blame] | 3203 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3204 | if (strcmp(a[leasepos], "infinite") == 0) |
Simon Kelley | 4d85e40 | 2020-07-12 22:45:46 +0100 | [diff] [blame] | 3205 | { |
| 3206 | new->lease_time = 0xffffffff; |
| 3207 | new->flags |= CONTEXT_SETLEASE; |
| 3208 | } |
Simon Kelley | c825754 | 2012-03-28 21:15:41 +0100 | [diff] [blame] | 3209 | else if (strcmp(a[leasepos], "deprecated") == 0) |
| 3210 | new->flags |= CONTEXT_DEPRECATE; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3211 | else |
| 3212 | { |
| 3213 | int fac = 1; |
| 3214 | if (strlen(a[leasepos]) > 0) |
| 3215 | { |
| 3216 | switch (a[leasepos][strlen(a[leasepos]) - 1]) |
| 3217 | { |
Simon Kelley | 4224321 | 2012-07-20 15:19:18 +0100 | [diff] [blame] | 3218 | case 'w': |
| 3219 | case 'W': |
| 3220 | fac *= 7; |
| 3221 | /* fall through */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3222 | case 'd': |
| 3223 | case 'D': |
| 3224 | fac *= 24; |
Simon Kelley | 87e00fe | 2018-02-16 21:27:35 +0000 | [diff] [blame] | 3225 | /* fall through */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3226 | case 'h': |
| 3227 | case 'H': |
| 3228 | fac *= 60; |
| 3229 | /* fall through */ |
| 3230 | case 'm': |
| 3231 | case 'M': |
| 3232 | fac *= 60; |
| 3233 | /* fall through */ |
| 3234 | case 's': |
| 3235 | case 'S': |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3236 | a[leasepos][strlen(a[leasepos]) - 1] = 0; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3237 | } |
| 3238 | |
Simon Kelley | be37986 | 2012-12-23 12:01:39 +0000 | [diff] [blame] | 3239 | for (cp = a[leasepos]; *cp; cp++) |
| 3240 | if (!(*cp >= '0' && *cp <= '9')) |
| 3241 | break; |
| 3242 | |
Simon Kelley | 54dae55 | 2013-02-05 17:55:10 +0000 | [diff] [blame] | 3243 | if (*cp || (leasepos+1 < k)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3244 | ret_err_free(_("bad dhcp-range"), new); |
Simon Kelley | be37986 | 2012-12-23 12:01:39 +0000 | [diff] [blame] | 3245 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3246 | new->lease_time = atoi(a[leasepos]) * fac; |
Simon Kelley | 4d85e40 | 2020-07-12 22:45:46 +0100 | [diff] [blame] | 3247 | new->flags |= CONTEXT_SETLEASE; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3248 | /* Leases of a minute or less confuse |
| 3249 | some clients, notably Apple's */ |
| 3250 | if (new->lease_time < 120) |
| 3251 | new->lease_time = 120; |
| 3252 | } |
| 3253 | } |
| 3254 | } |
Simon Kelley | 4d85e40 | 2020-07-12 22:45:46 +0100 | [diff] [blame] | 3255 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3256 | break; |
| 3257 | } |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 3258 | |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 3259 | case LOPT_BANK: |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3260 | case 'G': /* --dhcp-host */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3261 | { |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 3262 | struct dhcp_config *new; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3263 | struct in_addr in; |
| 3264 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3265 | new = opt_malloc(sizeof(struct dhcp_config)); |
| 3266 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3267 | new->next = daemon->dhcp_conf; |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 3268 | new->flags = (option == LOPT_BANK) ? CONFIG_BANK : 0; |
| 3269 | new->hwaddr = NULL; |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3270 | new->netid = NULL; |
Simon Kelley | 52ec783 | 2020-02-07 21:05:54 +0000 | [diff] [blame] | 3271 | new->filter = NULL; |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3272 | new->clid = NULL; |
Kevin Darbyshire-Bryant | 8d6d573 | 2020-03-02 10:00:21 +0000 | [diff] [blame] | 3273 | #ifdef HAVE_DHCP6 |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 3274 | new->addr6 = NULL; |
Kevin Darbyshire-Bryant | 8d6d573 | 2020-03-02 10:00:21 +0000 | [diff] [blame] | 3275 | #endif |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3276 | |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 3277 | while (arg) |
| 3278 | { |
| 3279 | comma = split(arg); |
| 3280 | if (strchr(arg, ':')) /* ethernet address, netid or binary CLID */ |
| 3281 | { |
| 3282 | if ((arg[0] == 'i' || arg[0] == 'I') && |
| 3283 | (arg[1] == 'd' || arg[1] == 'D') && |
| 3284 | arg[2] == ':') |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3285 | { |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 3286 | if (arg[3] == '*') |
| 3287 | new->flags |= CONFIG_NOCLID; |
| 3288 | else |
| 3289 | { |
| 3290 | int len; |
| 3291 | arg += 3; /* dump id: */ |
| 3292 | if (strchr(arg, ':')) |
| 3293 | len = parse_hex(arg, (unsigned char *)arg, -1, NULL, NULL); |
| 3294 | else |
| 3295 | { |
| 3296 | unhide_metas(arg); |
| 3297 | len = (int) strlen(arg); |
| 3298 | } |
| 3299 | |
| 3300 | if (len == -1) |
| 3301 | { |
| 3302 | dhcp_config_free(new); |
| 3303 | ret_err(_("bad hex constant")); |
| 3304 | } |
| 3305 | else if ((new->clid = opt_malloc(len))) |
| 3306 | { |
| 3307 | new->flags |= CONFIG_CLID; |
| 3308 | new->clid_len = len; |
| 3309 | memcpy(new->clid, arg, len); |
| 3310 | } |
| 3311 | } |
| 3312 | } |
| 3313 | /* dhcp-host has strange backwards-compat needs. */ |
| 3314 | else if (strstr(arg, "net:") == arg || strstr(arg, "set:") == arg) |
| 3315 | { |
| 3316 | struct dhcp_netid_list *newlist = opt_malloc(sizeof(struct dhcp_netid_list)); |
| 3317 | newlist->next = new->netid; |
| 3318 | new->netid = newlist; |
| 3319 | newlist->list = dhcp_netid_create(arg+4, NULL); |
| 3320 | } |
| 3321 | else if (strstr(arg, "tag:") == arg) |
Simon Kelley | 52ec783 | 2020-02-07 21:05:54 +0000 | [diff] [blame] | 3322 | new->filter = dhcp_netid_create(arg+4, new->filter); |
| 3323 | |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 3324 | #ifdef HAVE_DHCP6 |
| 3325 | else if (arg[0] == '[' && arg[strlen(arg)-1] == ']') |
| 3326 | { |
| 3327 | char *pref; |
| 3328 | struct in6_addr in6; |
| 3329 | struct addrlist *new_addr; |
| 3330 | |
| 3331 | arg[strlen(arg)-1] = 0; |
| 3332 | arg++; |
| 3333 | pref = split_chr(arg, '/'); |
| 3334 | |
| 3335 | if (!inet_pton(AF_INET6, arg, &in6)) |
| 3336 | { |
| 3337 | dhcp_config_free(new); |
| 3338 | ret_err(_("bad IPv6 address")); |
| 3339 | } |
Simon Kelley | 76ff440 | 2013-12-17 16:29:14 +0000 | [diff] [blame] | 3340 | |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 3341 | new_addr = opt_malloc(sizeof(struct addrlist)); |
| 3342 | new_addr->next = new->addr6; |
| 3343 | new_addr->flags = 0; |
| 3344 | new_addr->addr.addr6 = in6; |
| 3345 | new->addr6 = new_addr; |
| 3346 | |
| 3347 | if (pref) |
| 3348 | { |
| 3349 | u64 addrpart = addr6part(&in6); |
| 3350 | |
| 3351 | if (!atoi_check(pref, &new_addr->prefixlen) || |
| 3352 | new_addr->prefixlen > 128 || |
Petr Menšík | 46bdfe6 | 2020-03-08 15:56:19 +0000 | [diff] [blame] | 3353 | ((((u64)1<<(128-new_addr->prefixlen))-1) & addrpart) != 0) |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 3354 | { |
| 3355 | dhcp_config_free(new); |
| 3356 | ret_err(_("bad IPv6 prefix")); |
| 3357 | } |
| 3358 | |
| 3359 | new_addr->flags |= ADDRLIST_PREFIX; |
| 3360 | } |
| 3361 | |
| 3362 | for (i= 0; i < 8; i++) |
| 3363 | if (in6.s6_addr[i] != 0) |
| 3364 | break; |
| 3365 | |
| 3366 | /* set WILDCARD if network part all zeros */ |
| 3367 | if (i == 8) |
| 3368 | new_addr->flags |= ADDRLIST_WILDCARD; |
| 3369 | |
| 3370 | new->flags |= CONFIG_ADDR6; |
| 3371 | } |
| 3372 | #endif |
| 3373 | else |
| 3374 | { |
| 3375 | struct hwaddr_config *newhw = opt_malloc(sizeof(struct hwaddr_config)); |
| 3376 | if ((newhw->hwaddr_len = parse_hex(arg, newhw->hwaddr, DHCP_CHADDR_MAX, |
| 3377 | &newhw->wildcard_mask, &newhw->hwaddr_type)) == -1) |
| 3378 | { |
| 3379 | free(newhw); |
| 3380 | dhcp_config_free(new); |
| 3381 | ret_err(_("bad hex constant")); |
| 3382 | } |
| 3383 | else |
| 3384 | { |
| 3385 | newhw->next = new->hwaddr; |
| 3386 | new->hwaddr = newhw; |
| 3387 | } |
| 3388 | } |
| 3389 | } |
| 3390 | else if (strchr(arg, '.') && (inet_pton(AF_INET, arg, &in) > 0)) |
| 3391 | { |
| 3392 | struct dhcp_config *configs; |
| 3393 | |
| 3394 | new->addr = in; |
| 3395 | new->flags |= CONFIG_ADDR; |
| 3396 | |
| 3397 | /* If the same IP appears in more than one host config, then DISCOVER |
| 3398 | for one of the hosts will get the address, but REQUEST will be NAKed, |
| 3399 | since the address is reserved by the other one -> protocol loop. */ |
| 3400 | for (configs = daemon->dhcp_conf; configs; configs = configs->next) |
| 3401 | if ((configs->flags & CONFIG_ADDR) && configs->addr.s_addr == in.s_addr) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3402 | { |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 3403 | sprintf(errstr, _("duplicate dhcp-host IP address %s"), inet_ntoa(in)); |
| 3404 | return 0; |
| 3405 | } |
| 3406 | } |
| 3407 | else |
| 3408 | { |
| 3409 | char *cp, *lastp = NULL, last = 0; |
| 3410 | int fac = 1, isdig = 0; |
| 3411 | |
| 3412 | if (strlen(arg) > 1) |
| 3413 | { |
| 3414 | lastp = arg + strlen(arg) - 1; |
| 3415 | last = *lastp; |
| 3416 | switch (last) |
| 3417 | { |
| 3418 | case 'w': |
| 3419 | case 'W': |
| 3420 | fac *= 7; |
| 3421 | /* fall through */ |
| 3422 | case 'd': |
| 3423 | case 'D': |
| 3424 | fac *= 24; |
| 3425 | /* fall through */ |
| 3426 | case 'h': |
| 3427 | case 'H': |
| 3428 | fac *= 60; |
| 3429 | /* fall through */ |
| 3430 | case 'm': |
| 3431 | case 'M': |
| 3432 | fac *= 60; |
| 3433 | /* fall through */ |
| 3434 | case 's': |
| 3435 | case 'S': |
| 3436 | *lastp = 0; |
| 3437 | } |
| 3438 | } |
| 3439 | |
| 3440 | for (cp = arg; *cp; cp++) |
| 3441 | if (isdigit((unsigned char)*cp)) |
| 3442 | isdig = 1; |
| 3443 | else if (*cp != ' ') |
| 3444 | break; |
| 3445 | |
| 3446 | if (*cp) |
| 3447 | { |
| 3448 | if (lastp) |
| 3449 | *lastp = last; |
| 3450 | if (strcmp(arg, "infinite") == 0) |
| 3451 | { |
| 3452 | new->lease_time = 0xffffffff; |
| 3453 | new->flags |= CONFIG_TIME; |
| 3454 | } |
| 3455 | else if (strcmp(arg, "ignore") == 0) |
| 3456 | new->flags |= CONFIG_DISABLE; |
| 3457 | else |
| 3458 | { |
| 3459 | if (!(new->hostname = canonicalise_opt(arg)) || |
| 3460 | !legal_hostname(new->hostname)) |
| 3461 | { |
| 3462 | dhcp_config_free(new); |
| 3463 | ret_err(_("bad DHCP host name")); |
| 3464 | } |
| 3465 | |
| 3466 | new->flags |= CONFIG_NAME; |
| 3467 | new->domain = strip_hostname(new->hostname); |
| 3468 | } |
| 3469 | } |
| 3470 | else if (isdig) |
| 3471 | { |
| 3472 | new->lease_time = atoi(arg) * fac; |
| 3473 | /* Leases of a minute or less confuse |
| 3474 | some clients, notably Apple's */ |
| 3475 | if (new->lease_time < 120) |
| 3476 | new->lease_time = 120; |
| 3477 | new->flags |= CONFIG_TIME; |
| 3478 | } |
| 3479 | } |
| 3480 | |
| 3481 | arg = comma; |
| 3482 | } |
| 3483 | |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 3484 | daemon->dhcp_conf = new; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3485 | break; |
| 3486 | } |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 3487 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3488 | case LOPT_TAG_IF: /* --tag-if */ |
| 3489 | { |
| 3490 | struct tag_if *new = opt_malloc(sizeof(struct tag_if)); |
| 3491 | |
| 3492 | new->tag = NULL; |
| 3493 | new->set = NULL; |
| 3494 | new->next = NULL; |
| 3495 | |
| 3496 | /* preserve order */ |
| 3497 | if (!daemon->tag_if) |
| 3498 | daemon->tag_if = new; |
| 3499 | else |
| 3500 | { |
| 3501 | struct tag_if *tmp; |
| 3502 | for (tmp = daemon->tag_if; tmp->next; tmp = tmp->next); |
| 3503 | tmp->next = new; |
| 3504 | } |
| 3505 | |
| 3506 | while (arg) |
| 3507 | { |
| 3508 | size_t len; |
| 3509 | |
| 3510 | comma = split(arg); |
| 3511 | len = strlen(arg); |
| 3512 | |
| 3513 | if (len < 5) |
| 3514 | { |
| 3515 | new->set = NULL; |
| 3516 | break; |
| 3517 | } |
| 3518 | else |
| 3519 | { |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3520 | struct dhcp_netid *newtag = dhcp_netid_create(arg+4, NULL); |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3521 | |
| 3522 | if (strstr(arg, "set:") == arg) |
| 3523 | { |
| 3524 | struct dhcp_netid_list *newlist = opt_malloc(sizeof(struct dhcp_netid_list)); |
| 3525 | newlist->next = new->set; |
| 3526 | new->set = newlist; |
| 3527 | newlist->list = newtag; |
| 3528 | } |
| 3529 | else if (strstr(arg, "tag:") == arg) |
| 3530 | { |
| 3531 | newtag->next = new->tag; |
| 3532 | new->tag = newtag; |
| 3533 | } |
| 3534 | else |
| 3535 | { |
| 3536 | new->set = NULL; |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3537 | dhcp_netid_free(newtag); |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3538 | break; |
| 3539 | } |
| 3540 | } |
| 3541 | |
| 3542 | arg = comma; |
| 3543 | } |
| 3544 | |
| 3545 | if (!new->set) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3546 | { |
| 3547 | dhcp_netid_free(new->tag); |
| 3548 | dhcp_netid_list_free(new->set); |
| 3549 | ret_err_free(_("bad tag-if"), new); |
| 3550 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3551 | |
| 3552 | break; |
| 3553 | } |
| 3554 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3555 | |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 3556 | case 'O': /* --dhcp-option */ |
| 3557 | case LOPT_FORCE: /* --dhcp-option-force */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3558 | case LOPT_OPTS: |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 3559 | case LOPT_MATCH: /* --dhcp-match */ |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3560 | return parse_dhcp_opt(errstr, arg, |
| 3561 | option == LOPT_FORCE ? DHOPT_FORCE : |
| 3562 | (option == LOPT_MATCH ? DHOPT_MATCH : |
| 3563 | (option == LOPT_OPTS ? DHOPT_BANK : 0))); |
Simon Kelley | c822620 | 2018-08-08 23:46:03 +0100 | [diff] [blame] | 3564 | |
| 3565 | case LOPT_NAME_MATCH: /* --dhcp-name-match */ |
| 3566 | { |
| 3567 | struct dhcp_match_name *new = opt_malloc(sizeof(struct dhcp_match_name)); |
| 3568 | struct dhcp_netid *id = opt_malloc(sizeof(struct dhcp_netid)); |
| 3569 | ssize_t len; |
| 3570 | |
| 3571 | if (!(comma = split(arg)) || (len = strlen(comma)) == 0) |
| 3572 | ret_err(gen_err); |
| 3573 | |
| 3574 | new->wildcard = 0; |
| 3575 | new->netid = id; |
| 3576 | id->net = opt_string_alloc(set_prefix(arg)); |
| 3577 | |
| 3578 | if (comma[len-1] == '*') |
| 3579 | { |
| 3580 | comma[len-1] = 0; |
| 3581 | new->wildcard = 1; |
| 3582 | } |
| 3583 | new->name = opt_string_alloc(comma); |
| 3584 | |
| 3585 | new->next = daemon->dhcp_name_match; |
| 3586 | daemon->dhcp_name_match = new; |
| 3587 | |
| 3588 | break; |
| 3589 | } |
| 3590 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3591 | case 'M': /* --dhcp-boot */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3592 | { |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3593 | struct dhcp_netid *id = dhcp_tags(&arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3594 | |
Petr Menšík | 137e9f8 | 2018-12-16 21:25:29 +0000 | [diff] [blame] | 3595 | if (!arg) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3596 | { |
| 3597 | ret_err(gen_err); |
| 3598 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3599 | else |
| 3600 | { |
Simon Kelley | 7de060b | 2011-08-26 17:24:52 +0100 | [diff] [blame] | 3601 | char *dhcp_file, *dhcp_sname = NULL, *tftp_sname = NULL; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3602 | struct in_addr dhcp_next_server; |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3603 | struct dhcp_boot *new; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3604 | comma = split(arg); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3605 | dhcp_file = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3606 | dhcp_next_server.s_addr = 0; |
| 3607 | if (comma) |
| 3608 | { |
| 3609 | arg = comma; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3610 | comma = split(arg); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3611 | dhcp_sname = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3612 | if (comma) |
| 3613 | { |
| 3614 | unhide_metas(comma); |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 3615 | if (!(inet_pton(AF_INET, comma, &dhcp_next_server) > 0)) |
| 3616 | { |
| 3617 | /* |
| 3618 | * The user may have specified the tftp hostname here. |
| 3619 | * save it so that it can be resolved/looked up during |
| 3620 | * actual dhcp_reply(). |
| 3621 | */ |
| 3622 | |
| 3623 | tftp_sname = opt_string_alloc(comma); |
| 3624 | dhcp_next_server.s_addr = 0; |
| 3625 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3626 | } |
| 3627 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3628 | |
| 3629 | new = opt_malloc(sizeof(struct dhcp_boot)); |
| 3630 | new->file = dhcp_file; |
| 3631 | new->sname = dhcp_sname; |
| 3632 | new->tftp_sname = tftp_sname; |
| 3633 | new->next_server = dhcp_next_server; |
| 3634 | new->netid = id; |
| 3635 | new->next = daemon->boot_config; |
| 3636 | daemon->boot_config = new; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3637 | } |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 3638 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3639 | break; |
| 3640 | } |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3641 | |
Floris Bos | 503c609 | 2017-04-09 23:07:13 +0100 | [diff] [blame] | 3642 | case LOPT_REPLY_DELAY: /* --dhcp-reply-delay */ |
| 3643 | { |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3644 | struct dhcp_netid *id = dhcp_tags(&arg); |
Floris Bos | 503c609 | 2017-04-09 23:07:13 +0100 | [diff] [blame] | 3645 | |
Petr Menšík | 137e9f8 | 2018-12-16 21:25:29 +0000 | [diff] [blame] | 3646 | if (!arg) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3647 | { |
| 3648 | ret_err(gen_err); |
| 3649 | } |
Floris Bos | 503c609 | 2017-04-09 23:07:13 +0100 | [diff] [blame] | 3650 | else |
| 3651 | { |
| 3652 | struct delay_config *new; |
| 3653 | int delay; |
| 3654 | if (!atoi_check(arg, &delay)) |
| 3655 | ret_err(gen_err); |
| 3656 | |
| 3657 | new = opt_malloc(sizeof(struct delay_config)); |
| 3658 | new->delay = delay; |
| 3659 | new->netid = id; |
| 3660 | new->next = daemon->delay_conf; |
| 3661 | daemon->delay_conf = new; |
| 3662 | } |
| 3663 | |
| 3664 | break; |
| 3665 | } |
| 3666 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3667 | case LOPT_PXE_PROMT: /* --pxe-prompt */ |
| 3668 | { |
| 3669 | struct dhcp_opt *new = opt_malloc(sizeof(struct dhcp_opt)); |
| 3670 | int timeout; |
Floris Bos | 503c609 | 2017-04-09 23:07:13 +0100 | [diff] [blame] | 3671 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3672 | new->netid = NULL; |
| 3673 | new->opt = 10; /* PXE_MENU_PROMPT */ |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3674 | new->netid = dhcp_tags(&arg); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3675 | |
Petr Menšík | 137e9f8 | 2018-12-16 21:25:29 +0000 | [diff] [blame] | 3676 | if (!arg) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3677 | { |
| 3678 | dhcp_opt_free(new); |
| 3679 | ret_err(gen_err); |
| 3680 | } |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3681 | else |
| 3682 | { |
| 3683 | comma = split(arg); |
| 3684 | unhide_metas(arg); |
| 3685 | new->len = strlen(arg) + 1; |
| 3686 | new->val = opt_malloc(new->len); |
| 3687 | memcpy(new->val + 1, arg, new->len - 1); |
| 3688 | |
Wang Shanker | 4ded962 | 2020-12-04 10:17:35 +0800 | [diff] [blame] | 3689 | new->u.vendor_class = NULL; |
| 3690 | new->flags = DHOPT_VENDOR | DHOPT_VENDOR_PXE; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3691 | |
| 3692 | if (comma && atoi_check(comma, &timeout)) |
| 3693 | *(new->val) = timeout; |
| 3694 | else |
| 3695 | *(new->val) = 255; |
| 3696 | |
| 3697 | new->next = daemon->dhcp_opts; |
| 3698 | daemon->dhcp_opts = new; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 3699 | daemon->enable_pxe = 1; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3700 | } |
| 3701 | |
| 3702 | break; |
| 3703 | } |
| 3704 | |
| 3705 | case LOPT_PXE_SERV: /* --pxe-service */ |
| 3706 | { |
| 3707 | struct pxe_service *new = opt_malloc(sizeof(struct pxe_service)); |
| 3708 | char *CSA[] = { "x86PC", "PC98", "IA64_EFI", "Alpha", "Arc_x86", "Intel_Lean_Client", |
Simon Kelley | 68bea10 | 2016-05-11 22:15:06 +0100 | [diff] [blame] | 3709 | "IA32_EFI", "x86-64_EFI", "Xscale_EFI", "BC_EFI", |
| 3710 | "ARM32_EFI", "ARM64_EFI", NULL }; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3711 | static int boottype = 32768; |
| 3712 | |
| 3713 | new->netid = NULL; |
Simon Kelley | 751d6f4 | 2012-02-10 15:24:51 +0000 | [diff] [blame] | 3714 | new->sname = NULL; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3715 | new->server.s_addr = 0; |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3716 | new->netid = dhcp_tags(&arg); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3717 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3718 | if (arg && (comma = split(arg))) |
| 3719 | { |
| 3720 | for (i = 0; CSA[i]; i++) |
| 3721 | if (strcasecmp(CSA[i], arg) == 0) |
| 3722 | break; |
| 3723 | |
| 3724 | if (CSA[i] || atoi_check(arg, &i)) |
| 3725 | { |
| 3726 | arg = comma; |
| 3727 | comma = split(arg); |
| 3728 | |
| 3729 | new->CSA = i; |
| 3730 | new->menu = opt_string_alloc(arg); |
| 3731 | |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 3732 | if (!comma) |
| 3733 | { |
| 3734 | new->type = 0; /* local boot */ |
| 3735 | new->basename = NULL; |
| 3736 | } |
| 3737 | else |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3738 | { |
| 3739 | arg = comma; |
| 3740 | comma = split(arg); |
| 3741 | if (atoi_check(arg, &i)) |
| 3742 | { |
| 3743 | new->type = i; |
| 3744 | new->basename = NULL; |
| 3745 | } |
| 3746 | else |
| 3747 | { |
| 3748 | new->type = boottype++; |
| 3749 | new->basename = opt_string_alloc(arg); |
| 3750 | } |
| 3751 | |
Simon Kelley | 751d6f4 | 2012-02-10 15:24:51 +0000 | [diff] [blame] | 3752 | if (comma) |
| 3753 | { |
| 3754 | if (!inet_pton(AF_INET, comma, &new->server)) |
| 3755 | { |
| 3756 | new->server.s_addr = 0; |
| 3757 | new->sname = opt_string_alloc(comma); |
| 3758 | } |
| 3759 | |
| 3760 | } |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3761 | } |
Simon Kelley | 751d6f4 | 2012-02-10 15:24:51 +0000 | [diff] [blame] | 3762 | |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 3763 | /* Order matters */ |
| 3764 | new->next = NULL; |
| 3765 | if (!daemon->pxe_services) |
| 3766 | daemon->pxe_services = new; |
| 3767 | else |
| 3768 | { |
| 3769 | struct pxe_service *s; |
| 3770 | for (s = daemon->pxe_services; s->next; s = s->next); |
| 3771 | s->next = new; |
| 3772 | } |
| 3773 | |
| 3774 | daemon->enable_pxe = 1; |
| 3775 | break; |
| 3776 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3777 | } |
| 3778 | } |
| 3779 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3780 | ret_err(gen_err); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3781 | } |
| 3782 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3783 | case '4': /* --dhcp-mac */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3784 | { |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3785 | if (!(comma = split(arg))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3786 | ret_err(gen_err); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3787 | else |
| 3788 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3789 | struct dhcp_mac *new = opt_malloc(sizeof(struct dhcp_mac)); |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3790 | new->netid.net = opt_string_alloc(set_prefix(arg)); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3791 | unhide_metas(comma); |
| 3792 | new->hwaddr_len = parse_hex(comma, new->hwaddr, DHCP_CHADDR_MAX, &new->mask, &new->hwaddr_type); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 3793 | if (new->hwaddr_len == -1) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3794 | { |
| 3795 | free(new->netid.net); |
| 3796 | ret_err_free(gen_err, new); |
| 3797 | } |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 3798 | else |
| 3799 | { |
| 3800 | new->next = daemon->dhcp_macs; |
| 3801 | daemon->dhcp_macs = new; |
| 3802 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3803 | } |
| 3804 | } |
| 3805 | break; |
Simon Kelley | c630924 | 2013-03-07 20:59:28 +0000 | [diff] [blame] | 3806 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3807 | case 'U': /* --dhcp-vendorclass */ |
| 3808 | case 'j': /* --dhcp-userclass */ |
| 3809 | case LOPT_CIRCUIT: /* --dhcp-circuitid */ |
| 3810 | case LOPT_REMOTE: /* --dhcp-remoteid */ |
| 3811 | case LOPT_SUBSCR: /* --dhcp-subscrid */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3812 | { |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3813 | unsigned char *p; |
| 3814 | int dig = 0; |
| 3815 | struct dhcp_vendor *new = opt_malloc(sizeof(struct dhcp_vendor)); |
| 3816 | |
| 3817 | if (!(comma = split(arg))) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3818 | ret_err_free(gen_err, new); |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3819 | |
| 3820 | new->netid.net = opt_string_alloc(set_prefix(arg)); |
| 3821 | /* check for hex string - must digits may include : must not have nothing else, |
| 3822 | only allowed for agent-options. */ |
| 3823 | |
| 3824 | arg = comma; |
| 3825 | if ((comma = split(arg))) |
| 3826 | { |
| 3827 | if (option != 'U' || strstr(arg, "enterprise:") != arg) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3828 | { |
| 3829 | free(new->netid.net); |
| 3830 | ret_err_free(gen_err, new); |
| 3831 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3832 | else |
| 3833 | new->enterprise = atoi(arg+11); |
| 3834 | } |
| 3835 | else |
| 3836 | comma = arg; |
| 3837 | |
| 3838 | for (p = (unsigned char *)comma; *p; p++) |
| 3839 | if (isxdigit(*p)) |
| 3840 | dig = 1; |
| 3841 | else if (*p != ':') |
| 3842 | break; |
| 3843 | unhide_metas(comma); |
| 3844 | if (option == 'U' || option == 'j' || *p || !dig) |
| 3845 | { |
| 3846 | new->len = strlen(comma); |
| 3847 | new->data = opt_malloc(new->len); |
| 3848 | memcpy(new->data, comma, new->len); |
| 3849 | } |
| 3850 | else |
| 3851 | { |
| 3852 | new->len = parse_hex(comma, (unsigned char *)comma, strlen(comma), NULL, NULL); |
| 3853 | new->data = opt_malloc(new->len); |
| 3854 | memcpy(new->data, comma, new->len); |
| 3855 | } |
| 3856 | |
| 3857 | switch (option) |
| 3858 | { |
| 3859 | case 'j': |
| 3860 | new->match_type = MATCH_USER; |
| 3861 | break; |
| 3862 | case 'U': |
| 3863 | new->match_type = MATCH_VENDOR; |
| 3864 | break; |
| 3865 | case LOPT_CIRCUIT: |
| 3866 | new->match_type = MATCH_CIRCUIT; |
| 3867 | break; |
| 3868 | case LOPT_REMOTE: |
| 3869 | new->match_type = MATCH_REMOTE; |
| 3870 | break; |
| 3871 | case LOPT_SUBSCR: |
| 3872 | new->match_type = MATCH_SUBSCRIBER; |
| 3873 | break; |
| 3874 | } |
| 3875 | new->next = daemon->dhcp_vendors; |
| 3876 | daemon->dhcp_vendors = new; |
Simon Kelley | a5c72ab | 2012-02-10 13:42:47 +0000 | [diff] [blame] | 3877 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3878 | break; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3879 | } |
| 3880 | |
Simon Kelley | 9e03894 | 2008-05-30 20:06:34 +0100 | [diff] [blame] | 3881 | case LOPT_ALTPORT: /* --dhcp-alternate-port */ |
| 3882 | if (!arg) |
| 3883 | { |
| 3884 | daemon->dhcp_server_port = DHCP_SERVER_ALTPORT; |
| 3885 | daemon->dhcp_client_port = DHCP_CLIENT_ALTPORT; |
| 3886 | } |
| 3887 | else |
| 3888 | { |
| 3889 | comma = split(arg); |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 3890 | if (!atoi_check16(arg, &daemon->dhcp_server_port) || |
| 3891 | (comma && !atoi_check16(comma, &daemon->dhcp_client_port))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3892 | ret_err(_("invalid port number")); |
Simon Kelley | 9e03894 | 2008-05-30 20:06:34 +0100 | [diff] [blame] | 3893 | if (!comma) |
| 3894 | daemon->dhcp_client_port = daemon->dhcp_server_port+1; |
| 3895 | } |
| 3896 | break; |
| 3897 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3898 | case 'J': /* --dhcp-ignore */ |
| 3899 | case LOPT_NO_NAMES: /* --dhcp-ignore-names */ |
| 3900 | case LOPT_BROADCAST: /* --dhcp-broadcast */ |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3901 | case '3': /* --bootp-dynamic */ |
| 3902 | case LOPT_GEN_NAMES: /* --dhcp-generate-names */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3903 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3904 | struct dhcp_netid_list *new = opt_malloc(sizeof(struct dhcp_netid_list)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3905 | struct dhcp_netid *list = NULL; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 3906 | if (option == 'J') |
| 3907 | { |
| 3908 | new->next = daemon->dhcp_ignore; |
| 3909 | daemon->dhcp_ignore = new; |
| 3910 | } |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3911 | else if (option == LOPT_BROADCAST) |
| 3912 | { |
| 3913 | new->next = daemon->force_broadcast; |
| 3914 | daemon->force_broadcast = new; |
| 3915 | } |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 3916 | else if (option == '3') |
| 3917 | { |
| 3918 | new->next = daemon->bootp_dynamic; |
| 3919 | daemon->bootp_dynamic = new; |
| 3920 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3921 | else if (option == LOPT_GEN_NAMES) |
| 3922 | { |
| 3923 | new->next = daemon->dhcp_gen_names; |
| 3924 | daemon->dhcp_gen_names = new; |
| 3925 | } |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 3926 | else |
| 3927 | { |
| 3928 | new->next = daemon->dhcp_ignore_names; |
| 3929 | daemon->dhcp_ignore_names = new; |
| 3930 | } |
| 3931 | |
| 3932 | while (arg) { |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3933 | comma = split(arg); |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3934 | list = dhcp_netid_create(is_tag_prefix(arg) ? arg+4 :arg, list); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3935 | arg = comma; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 3936 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3937 | |
| 3938 | new->list = list; |
| 3939 | break; |
| 3940 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3941 | |
| 3942 | case LOPT_PROXY: /* --dhcp-proxy */ |
| 3943 | daemon->override = 1; |
| 3944 | while (arg) { |
| 3945 | struct addr_list *new = opt_malloc(sizeof(struct addr_list)); |
| 3946 | comma = split(arg); |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 3947 | if (!(inet_pton(AF_INET, arg, &new->addr) > 0)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3948 | ret_err_free(_("bad dhcp-proxy address"), new); |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3949 | new->next = daemon->override_relays; |
| 3950 | daemon->override_relays = new; |
| 3951 | arg = comma; |
Wang Shanker | 4ded962 | 2020-12-04 10:17:35 +0800 | [diff] [blame] | 3952 | } |
| 3953 | break; |
| 3954 | |
| 3955 | case LOPT_PXE_VENDOR: /* --dhcp-pxe-vendor */ |
| 3956 | { |
| 3957 | while (arg) { |
| 3958 | struct dhcp_pxe_vendor *new = opt_malloc(sizeof(struct dhcp_pxe_vendor)); |
| 3959 | comma = split(arg); |
| 3960 | new->data = opt_string_alloc(arg); |
| 3961 | new->next = daemon->dhcp_pxe_vendors; |
| 3962 | daemon->dhcp_pxe_vendors = new; |
| 3963 | arg = comma; |
| 3964 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3965 | } |
| 3966 | break; |
Simon Kelley | ff7eea2 | 2013-09-04 18:01:38 +0100 | [diff] [blame] | 3967 | |
| 3968 | case LOPT_RELAY: /* --dhcp-relay */ |
| 3969 | { |
| 3970 | struct dhcp_relay *new = opt_malloc(sizeof(struct dhcp_relay)); |
| 3971 | comma = split(arg); |
| 3972 | new->interface = opt_string_alloc(split(comma)); |
| 3973 | new->iface_index = 0; |
| 3974 | if (inet_pton(AF_INET, arg, &new->local) && inet_pton(AF_INET, comma, &new->server)) |
| 3975 | { |
| 3976 | new->next = daemon->relay4; |
| 3977 | daemon->relay4 = new; |
| 3978 | } |
| 3979 | #ifdef HAVE_DHCP6 |
| 3980 | else if (inet_pton(AF_INET6, arg, &new->local) && inet_pton(AF_INET6, comma, &new->server)) |
| 3981 | { |
| 3982 | new->next = daemon->relay6; |
| 3983 | daemon->relay6 = new; |
| 3984 | } |
| 3985 | #endif |
| 3986 | else |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3987 | { |
| 3988 | free(new->interface); |
| 3989 | ret_err_free(_("Bad dhcp-relay"), new); |
| 3990 | } |
Simon Kelley | ff7eea2 | 2013-09-04 18:01:38 +0100 | [diff] [blame] | 3991 | |
| 3992 | break; |
| 3993 | } |
| 3994 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3995 | #endif |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3996 | |
Simon Kelley | 8b37270 | 2012-03-09 17:45:10 +0000 | [diff] [blame] | 3997 | #ifdef HAVE_DHCP6 |
Simon Kelley | c4cd95d | 2013-10-10 20:58:11 +0100 | [diff] [blame] | 3998 | case LOPT_RA_PARAM: /* --ra-param */ |
| 3999 | if ((comma = split(arg))) |
| 4000 | { |
| 4001 | struct ra_interface *new = opt_malloc(sizeof(struct ra_interface)); |
| 4002 | new->lifetime = -1; |
| 4003 | new->prio = 0; |
David Flamand | 005c46d | 2017-04-11 11:49:54 +0100 | [diff] [blame] | 4004 | new->mtu = 0; |
Vladislav Grishenko | 6ec5f5c | 2017-04-24 22:34:45 +0100 | [diff] [blame] | 4005 | new->mtu_name = NULL; |
Simon Kelley | c4cd95d | 2013-10-10 20:58:11 +0100 | [diff] [blame] | 4006 | new->name = opt_string_alloc(arg); |
David Flamand | 005c46d | 2017-04-11 11:49:54 +0100 | [diff] [blame] | 4007 | if (strcasestr(comma, "mtu:") == comma) |
| 4008 | { |
| 4009 | arg = comma + 4; |
| 4010 | if (!(comma = split(comma))) |
| 4011 | goto err; |
| 4012 | if (!strcasecmp(arg, "off")) |
| 4013 | new->mtu = -1; |
Vladislav Grishenko | 6ec5f5c | 2017-04-24 22:34:45 +0100 | [diff] [blame] | 4014 | else if (!atoi_check(arg, &new->mtu)) |
| 4015 | new->mtu_name = opt_string_alloc(arg); |
| 4016 | else if (new->mtu < 1280) |
David Flamand | 005c46d | 2017-04-11 11:49:54 +0100 | [diff] [blame] | 4017 | goto err; |
| 4018 | } |
Simon Kelley | c4cd95d | 2013-10-10 20:58:11 +0100 | [diff] [blame] | 4019 | if (strcasestr(comma, "high") == comma || strcasestr(comma, "low") == comma) |
| 4020 | { |
| 4021 | if (*comma == 'l' || *comma == 'L') |
| 4022 | new->prio = 0x18; |
| 4023 | else |
| 4024 | new->prio = 0x08; |
| 4025 | comma = split(comma); |
| 4026 | } |
| 4027 | arg = split(comma); |
| 4028 | if (!atoi_check(comma, &new->interval) || |
| 4029 | (arg && !atoi_check(arg, &new->lifetime))) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4030 | { |
David Flamand | 005c46d | 2017-04-11 11:49:54 +0100 | [diff] [blame] | 4031 | err: |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4032 | free(new->name); |
| 4033 | ret_err_free(_("bad RA-params"), new); |
| 4034 | } |
Simon Kelley | c4cd95d | 2013-10-10 20:58:11 +0100 | [diff] [blame] | 4035 | |
| 4036 | new->next = daemon->ra_interfaces; |
| 4037 | daemon->ra_interfaces = new; |
| 4038 | } |
| 4039 | break; |
| 4040 | |
Simon Kelley | 8b37270 | 2012-03-09 17:45:10 +0000 | [diff] [blame] | 4041 | case LOPT_DUID: /* --dhcp-duid */ |
| 4042 | if (!(comma = split(arg)) || !atoi_check(arg, (int *)&daemon->duid_enterprise)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4043 | ret_err(_("bad DUID")); |
Simon Kelley | 8b37270 | 2012-03-09 17:45:10 +0000 | [diff] [blame] | 4044 | else |
| 4045 | { |
| 4046 | daemon->duid_config_len = parse_hex(comma,(unsigned char *)comma, strlen(comma), NULL, NULL); |
| 4047 | daemon->duid_config = opt_malloc(daemon->duid_config_len); |
| 4048 | memcpy(daemon->duid_config, comma, daemon->duid_config_len); |
| 4049 | } |
| 4050 | break; |
| 4051 | #endif |
| 4052 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4053 | case 'V': /* --alias */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4054 | { |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 4055 | char *dash, *a[3] = { NULL, NULL, NULL }; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4056 | int k = 0; |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 4057 | struct doctor *new = opt_malloc(sizeof(struct doctor)); |
| 4058 | new->next = daemon->doctors; |
| 4059 | daemon->doctors = new; |
| 4060 | new->mask.s_addr = 0xffffffff; |
| 4061 | new->end.s_addr = 0; |
| 4062 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4063 | if ((a[0] = arg)) |
| 4064 | for (k = 1; k < 3; k++) |
| 4065 | { |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4066 | if (!(a[k] = split(a[k-1]))) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4067 | break; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4068 | unhide_metas(a[k]); |
| 4069 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4070 | |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 4071 | dash = split_chr(a[0], '-'); |
| 4072 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4073 | if ((k < 2) || |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 4074 | (!(inet_pton(AF_INET, a[0], &new->in) > 0)) || |
Simon Kelley | a3bd7e7 | 2018-07-19 22:00:08 +0100 | [diff] [blame] | 4075 | (!(inet_pton(AF_INET, a[1], &new->out) > 0)) || |
| 4076 | (k == 3 && !inet_pton(AF_INET, a[2], &new->mask))) |
| 4077 | ret_err(_("missing address in alias")); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4078 | |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 4079 | if (dash && |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 4080 | (!(inet_pton(AF_INET, dash, &new->end) > 0) || |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 4081 | !is_same_net(new->in, new->end, new->mask) || |
| 4082 | ntohl(new->in.s_addr) > ntohl(new->end.s_addr))) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4083 | ret_err_free(_("invalid alias range"), new); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4084 | |
| 4085 | break; |
| 4086 | } |
| 4087 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4088 | case LOPT_INTNAME: /* --interface-name */ |
Simon Kelley | b7cf754 | 2021-03-04 16:54:14 +0000 | [diff] [blame] | 4089 | case LOPT_DYNHOST: /* --dynamic-host */ |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4090 | { |
| 4091 | struct interface_name *new, **up; |
Simon Kelley | b7cf754 | 2021-03-04 16:54:14 +0000 | [diff] [blame] | 4092 | char *domain = arg; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4093 | |
Simon Kelley | b7cf754 | 2021-03-04 16:54:14 +0000 | [diff] [blame] | 4094 | arg = split(arg); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 4095 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4096 | new = opt_malloc(sizeof(struct interface_name)); |
Simon Kelley | b7cf754 | 2021-03-04 16:54:14 +0000 | [diff] [blame] | 4097 | memset(new, 0, sizeof(struct interface_name)); |
| 4098 | new->flags = IN4 | IN6; |
Simon Kelley | 376d48c | 2013-11-13 13:04:30 +0000 | [diff] [blame] | 4099 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4100 | /* Add to the end of the list, so that first name |
| 4101 | of an interface is used for PTR lookups. */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4102 | for (up = &daemon->int_names; *up; up = &((*up)->next)); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4103 | *up = new; |
Simon Kelley | b7cf754 | 2021-03-04 16:54:14 +0000 | [diff] [blame] | 4104 | |
| 4105 | while ((comma = split(arg))) |
Simon Kelley | f7029f5 | 2013-11-21 15:09:09 +0000 | [diff] [blame] | 4106 | { |
Simon Kelley | b7cf754 | 2021-03-04 16:54:14 +0000 | [diff] [blame] | 4107 | if (inet_pton(AF_INET, arg, &new->proto4)) |
| 4108 | new->flags |= INP4; |
| 4109 | else if (inet_pton(AF_INET6, arg, &new->proto6)) |
| 4110 | new->flags |= INP6; |
| 4111 | else |
| 4112 | break; |
| 4113 | |
| 4114 | arg = comma; |
| 4115 | } |
| 4116 | |
| 4117 | if ((comma = split_chr(arg, '/'))) |
| 4118 | { |
| 4119 | if (strcmp(comma, "4") == 0) |
| 4120 | new->flags &= ~IN6; |
| 4121 | else if (strcmp(comma, "6") == 0) |
| 4122 | new->flags &= ~IN4; |
Simon Kelley | f7029f5 | 2013-11-21 15:09:09 +0000 | [diff] [blame] | 4123 | else |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4124 | ret_err_free(gen_err, new); |
Simon Kelley | b7cf754 | 2021-03-04 16:54:14 +0000 | [diff] [blame] | 4125 | } |
| 4126 | |
| 4127 | new->intr = opt_string_alloc(arg); |
| 4128 | |
| 4129 | if (option == LOPT_DYNHOST) |
| 4130 | { |
| 4131 | if (!(new->flags & (INP4 | INP6))) |
| 4132 | ret_err(_("missing address in dynamic host")); |
| 4133 | |
| 4134 | if (!(new->flags & IN4) || !(new->flags & IN6)) |
| 4135 | arg = NULL; /* provoke error below */ |
| 4136 | |
| 4137 | new->flags &= ~(IN4 | IN6); |
| 4138 | } |
| 4139 | else |
| 4140 | { |
| 4141 | if (new->flags & (INP4 | INP6)) |
| 4142 | arg = NULL; /* provoke error below */ |
| 4143 | } |
| 4144 | |
| 4145 | if (!domain || !arg || !(new->name = canonicalise_opt(domain))) |
| 4146 | ret_err(option == LOPT_DYNHOST ? |
| 4147 | _("bad dynamic host") : _("bad interface name")); |
| 4148 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4149 | break; |
| 4150 | } |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 4151 | |
| 4152 | case LOPT_CNAME: /* --cname */ |
| 4153 | { |
| 4154 | struct cname *new; |
Simon Kelley | a1d973f | 2016-12-22 22:09:50 +0000 | [diff] [blame] | 4155 | char *alias, *target, *last, *pen; |
Simon Kelley | df3d54f | 2016-02-24 21:03:38 +0000 | [diff] [blame] | 4156 | int ttl = -1; |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4157 | |
Simon Kelley | a1d973f | 2016-12-22 22:09:50 +0000 | [diff] [blame] | 4158 | for (last = pen = NULL, comma = arg; comma; comma = split(comma)) |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 4159 | { |
Simon Kelley | a1d973f | 2016-12-22 22:09:50 +0000 | [diff] [blame] | 4160 | pen = last; |
| 4161 | last = comma; |
| 4162 | } |
| 4163 | |
| 4164 | if (!pen) |
| 4165 | ret_err(_("bad CNAME")); |
| 4166 | |
| 4167 | if (pen != arg && atoi_check(last, &ttl)) |
| 4168 | last = pen; |
| 4169 | |
| 4170 | target = canonicalise_opt(last); |
| 4171 | |
| 4172 | while (arg != last) |
| 4173 | { |
Petr Menšík | 56f0623 | 2018-03-06 23:13:32 +0000 | [diff] [blame] | 4174 | int arglen = strlen(arg); |
Simon Kelley | a1d973f | 2016-12-22 22:09:50 +0000 | [diff] [blame] | 4175 | alias = canonicalise_opt(arg); |
Simon Kelley | 5614413 | 2017-05-03 22:54:09 +0100 | [diff] [blame] | 4176 | |
| 4177 | if (!alias || !target) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4178 | { |
| 4179 | free(target); |
| 4180 | free(alias); |
| 4181 | ret_err(_("bad CNAME")); |
| 4182 | } |
Simon Kelley | a1d973f | 2016-12-22 22:09:50 +0000 | [diff] [blame] | 4183 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4184 | for (new = daemon->cnames; new; new = new->next) |
Simon Kelley | 5614413 | 2017-05-03 22:54:09 +0100 | [diff] [blame] | 4185 | if (hostname_isequal(new->alias, alias)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4186 | { |
| 4187 | free(target); |
| 4188 | free(alias); |
| 4189 | ret_err(_("duplicate CNAME")); |
| 4190 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4191 | new = opt_malloc(sizeof(struct cname)); |
| 4192 | new->next = daemon->cnames; |
| 4193 | daemon->cnames = new; |
| 4194 | new->alias = alias; |
| 4195 | new->target = target; |
Simon Kelley | df3d54f | 2016-02-24 21:03:38 +0000 | [diff] [blame] | 4196 | new->ttl = ttl; |
Simon Kelley | a1d973f | 2016-12-22 22:09:50 +0000 | [diff] [blame] | 4197 | |
Petr Menšík | 56f0623 | 2018-03-06 23:13:32 +0000 | [diff] [blame] | 4198 | for (arg += arglen+1; *arg && isspace(*arg); arg++); |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 4199 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4200 | |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 4201 | break; |
| 4202 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4203 | |
| 4204 | case LOPT_PTR: /* --ptr-record */ |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 4205 | { |
| 4206 | struct ptr_record *new; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 4207 | char *dom, *target = NULL; |
| 4208 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4209 | comma = split(arg); |
| 4210 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 4211 | if (!(dom = canonicalise_opt(arg)) || |
| 4212 | (comma && !(target = canonicalise_opt(comma)))) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4213 | { |
| 4214 | free(dom); |
| 4215 | free(target); |
| 4216 | ret_err(_("bad PTR record")); |
| 4217 | } |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 4218 | else |
| 4219 | { |
| 4220 | new = opt_malloc(sizeof(struct ptr_record)); |
| 4221 | new->next = daemon->ptr; |
| 4222 | daemon->ptr = new; |
| 4223 | new->name = dom; |
| 4224 | new->ptr = target; |
| 4225 | } |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 4226 | break; |
| 4227 | } |
| 4228 | |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 4229 | case LOPT_NAPTR: /* --naptr-record */ |
| 4230 | { |
| 4231 | char *a[7] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; |
| 4232 | int k = 0; |
| 4233 | struct naptr *new; |
| 4234 | int order, pref; |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4235 | char *name=NULL, *replace = NULL; |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 4236 | |
| 4237 | if ((a[0] = arg)) |
| 4238 | for (k = 1; k < 7; k++) |
| 4239 | if (!(a[k] = split(a[k-1]))) |
| 4240 | break; |
| 4241 | |
| 4242 | |
| 4243 | if (k < 6 || |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 4244 | !(name = canonicalise_opt(a[0])) || |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 4245 | !atoi_check16(a[1], &order) || |
| 4246 | !atoi_check16(a[2], &pref) || |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 4247 | (k == 7 && !(replace = canonicalise_opt(a[6])))) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4248 | { |
| 4249 | free(name); |
| 4250 | free(replace); |
| 4251 | ret_err(_("bad NAPTR record")); |
| 4252 | } |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 4253 | else |
| 4254 | { |
| 4255 | new = opt_malloc(sizeof(struct naptr)); |
| 4256 | new->next = daemon->naptr; |
| 4257 | daemon->naptr = new; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 4258 | new->name = name; |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 4259 | new->flags = opt_string_alloc(a[3]); |
| 4260 | new->services = opt_string_alloc(a[4]); |
| 4261 | new->regexp = opt_string_alloc(a[5]); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 4262 | new->replace = replace; |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 4263 | new->order = order; |
| 4264 | new->pref = pref; |
| 4265 | } |
| 4266 | break; |
| 4267 | } |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 4268 | |
| 4269 | case LOPT_RR: /* dns-rr */ |
| 4270 | { |
| 4271 | struct txt_record *new; |
Simon Kelley | 4caa86d | 2016-03-16 18:44:16 +0000 | [diff] [blame] | 4272 | size_t len = 0; |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 4273 | char *data; |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4274 | int class; |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 4275 | |
| 4276 | comma = split(arg); |
| 4277 | data = split(comma); |
| 4278 | |
| 4279 | new = opt_malloc(sizeof(struct txt_record)); |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4280 | new->name = NULL; |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 4281 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4282 | if (!atoi_check(comma, &class) || |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 4283 | !(new->name = canonicalise_opt(arg)) || |
Simon Kelley | 51931b8 | 2012-05-29 17:06:02 +0100 | [diff] [blame] | 4284 | (data && (len = parse_hex(data, (unsigned char *)data, -1, NULL, NULL)) == -1U)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4285 | { |
| 4286 | free(new->name); |
| 4287 | ret_err_free(_("bad RR record"), new); |
| 4288 | } |
| 4289 | |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 4290 | new->len = 0; |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4291 | new->class = class; |
| 4292 | new->next = daemon->rr; |
| 4293 | daemon->rr = new; |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 4294 | |
| 4295 | if (data) |
| 4296 | { |
Simon Kelley | 974a6d0 | 2018-08-23 23:01:16 +0100 | [diff] [blame] | 4297 | new->txt = opt_malloc(len); |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 4298 | new->len = len; |
| 4299 | memcpy(new->txt, data, len); |
| 4300 | } |
| 4301 | |
| 4302 | break; |
| 4303 | } |
| 4304 | |
Simon Kelley | 974a6d0 | 2018-08-23 23:01:16 +0100 | [diff] [blame] | 4305 | case LOPT_CAA: /* --caa-record */ |
| 4306 | { |
| 4307 | struct txt_record *new; |
| 4308 | char *tag, *value; |
| 4309 | int flags; |
| 4310 | |
| 4311 | comma = split(arg); |
| 4312 | tag = split(comma); |
| 4313 | value = split(tag); |
| 4314 | |
| 4315 | new = opt_malloc(sizeof(struct txt_record)); |
| 4316 | new->next = daemon->rr; |
| 4317 | daemon->rr = new; |
| 4318 | |
| 4319 | if (!atoi_check(comma, &flags) || !tag || !value || !(new->name = canonicalise_opt(arg))) |
| 4320 | ret_err(_("bad CAA record")); |
| 4321 | |
| 4322 | unhide_metas(tag); |
| 4323 | unhide_metas(value); |
| 4324 | |
| 4325 | new->len = strlen(tag) + strlen(value) + 2; |
| 4326 | new->txt = opt_malloc(new->len); |
| 4327 | new->txt[0] = flags; |
| 4328 | new->txt[1] = strlen(tag); |
| 4329 | memcpy(&new->txt[2], tag, strlen(tag)); |
| 4330 | memcpy(&new->txt[2 + strlen(tag)], value, strlen(value)); |
| 4331 | new->class = T_CAA; |
| 4332 | |
| 4333 | break; |
| 4334 | } |
| 4335 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4336 | case 'Y': /* --txt-record */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4337 | { |
| 4338 | struct txt_record *new; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4339 | unsigned char *p, *cnt; |
| 4340 | size_t len; |
| 4341 | |
| 4342 | comma = split(arg); |
| 4343 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4344 | new = opt_malloc(sizeof(struct txt_record)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4345 | new->class = C_IN; |
Simon Kelley | fec216d | 2014-03-27 20:54:34 +0000 | [diff] [blame] | 4346 | new->stat = 0; |
| 4347 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 4348 | if (!(new->name = canonicalise_opt(arg))) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4349 | ret_err_free(_("bad TXT record"), new); |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4350 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4351 | new->next = daemon->txt; |
| 4352 | daemon->txt = new; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4353 | len = comma ? strlen(comma) : 0; |
| 4354 | len += (len/255) + 1; /* room for extra counts */ |
| 4355 | new->txt = p = opt_malloc(len); |
| 4356 | |
| 4357 | cnt = p++; |
| 4358 | *cnt = 0; |
| 4359 | |
| 4360 | while (comma && *comma) |
| 4361 | { |
| 4362 | unsigned char c = (unsigned char)*comma++; |
| 4363 | |
| 4364 | if (c == ',' || *cnt == 255) |
| 4365 | { |
| 4366 | if (c != ',') |
| 4367 | comma--; |
| 4368 | cnt = p++; |
| 4369 | *cnt = 0; |
| 4370 | } |
| 4371 | else |
| 4372 | { |
| 4373 | *p++ = unhide_meta(c); |
| 4374 | (*cnt)++; |
| 4375 | } |
| 4376 | } |
| 4377 | |
| 4378 | new->len = p - new->txt; |
| 4379 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4380 | break; |
| 4381 | } |
| 4382 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4383 | case 'W': /* --srv-host */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4384 | { |
| 4385 | int port = 1, priority = 0, weight = 0; |
| 4386 | char *name, *target = NULL; |
| 4387 | struct mx_srv_record *new; |
| 4388 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4389 | comma = split(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4390 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 4391 | if (!(name = canonicalise_opt(arg))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4392 | ret_err(_("bad SRV record")); |
| 4393 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4394 | if (comma) |
| 4395 | { |
| 4396 | arg = comma; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4397 | comma = split(arg); |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4398 | if (!(target = canonicalise_opt(arg))) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4399 | ret_err_free(_("bad SRV target"), name); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4400 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4401 | if (comma) |
| 4402 | { |
| 4403 | arg = comma; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4404 | comma = split(arg); |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 4405 | if (!atoi_check16(arg, &port)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4406 | { |
| 4407 | free(name); |
| 4408 | ret_err_free(_("invalid port number"), target); |
| 4409 | } |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4410 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4411 | if (comma) |
| 4412 | { |
| 4413 | arg = comma; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4414 | comma = split(arg); |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 4415 | if (!atoi_check16(arg, &priority)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4416 | { |
| 4417 | free(name); |
| 4418 | ret_err_free(_("invalid priority"), target); |
| 4419 | } |
Simon Kelley | 407a1f3 | 2016-03-01 17:06:07 +0000 | [diff] [blame] | 4420 | if (comma && !atoi_check16(comma, &weight)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4421 | { |
| 4422 | free(name); |
| 4423 | ret_err_free(_("invalid weight"), target); |
| 4424 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4425 | } |
| 4426 | } |
| 4427 | } |
| 4428 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4429 | new = opt_malloc(sizeof(struct mx_srv_record)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4430 | new->next = daemon->mxnames; |
| 4431 | daemon->mxnames = new; |
| 4432 | new->issrv = 1; |
| 4433 | new->name = name; |
| 4434 | new->target = target; |
| 4435 | new->srvport = port; |
| 4436 | new->priority = priority; |
| 4437 | new->weight = weight; |
| 4438 | break; |
| 4439 | } |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 4440 | |
Simon Kelley | e759d42 | 2012-03-16 13:18:57 +0000 | [diff] [blame] | 4441 | case LOPT_HOST_REC: /* --host-record */ |
| 4442 | { |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4443 | struct host_record *new; |
Simon Kelley | df3d54f | 2016-02-24 21:03:38 +0000 | [diff] [blame] | 4444 | |
Simon Kelley | e759d42 | 2012-03-16 13:18:57 +0000 | [diff] [blame] | 4445 | if (!arg || !(comma = split(arg))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4446 | ret_err(_("Bad host-record")); |
| 4447 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4448 | new = opt_malloc(sizeof(struct host_record)); |
| 4449 | memset(new, 0, sizeof(struct host_record)); |
| 4450 | new->ttl = -1; |
Simon Kelley | 157d8cf | 2019-10-25 17:46:49 +0100 | [diff] [blame] | 4451 | new->flags = 0; |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4452 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4453 | while (arg) |
| 4454 | { |
Simon Kelley | cc921df | 2019-01-02 22:48:59 +0000 | [diff] [blame] | 4455 | union all_addr addr; |
Simon Kelley | df3d54f | 2016-02-24 21:03:38 +0000 | [diff] [blame] | 4456 | char *dig; |
| 4457 | |
| 4458 | for (dig = arg; *dig != 0; dig++) |
| 4459 | if (*dig < '0' || *dig > '9') |
| 4460 | break; |
| 4461 | if (*dig == 0) |
| 4462 | new->ttl = atoi(arg); |
Simon Kelley | cc921df | 2019-01-02 22:48:59 +0000 | [diff] [blame] | 4463 | else if (inet_pton(AF_INET, arg, &addr.addr4)) |
Simon Kelley | 157d8cf | 2019-10-25 17:46:49 +0100 | [diff] [blame] | 4464 | { |
| 4465 | new->addr = addr.addr4; |
| 4466 | new->flags |= HR_4; |
| 4467 | } |
Simon Kelley | cc921df | 2019-01-02 22:48:59 +0000 | [diff] [blame] | 4468 | else if (inet_pton(AF_INET6, arg, &addr.addr6)) |
Simon Kelley | 157d8cf | 2019-10-25 17:46:49 +0100 | [diff] [blame] | 4469 | { |
| 4470 | new->addr6 = addr.addr6; |
| 4471 | new->flags |= HR_6; |
| 4472 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4473 | else |
| 4474 | { |
| 4475 | int nomem; |
| 4476 | char *canon = canonicalise(arg, &nomem); |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4477 | struct name_list *nl; |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4478 | if (!canon) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4479 | { |
| 4480 | struct name_list *tmp = new->names, *next; |
| 4481 | for (tmp = new->names; tmp; tmp = next) |
| 4482 | { |
| 4483 | next = tmp->next; |
| 4484 | free(tmp); |
| 4485 | } |
| 4486 | ret_err_free(_("Bad name in host-record"), new); |
| 4487 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4488 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4489 | nl = opt_malloc(sizeof(struct name_list)); |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4490 | nl->name = canon; |
| 4491 | /* keep order, so that PTR record goes to first name */ |
| 4492 | nl->next = NULL; |
| 4493 | if (!new->names) |
| 4494 | new->names = nl; |
| 4495 | else |
| 4496 | { |
| 4497 | struct name_list *tmp; |
| 4498 | for (tmp = new->names; tmp->next; tmp = tmp->next); |
| 4499 | tmp->next = nl; |
| 4500 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4501 | } |
Simon Kelley | e4807d8 | 2012-09-27 21:52:26 +0100 | [diff] [blame] | 4502 | |
| 4503 | arg = comma; |
| 4504 | comma = split(arg); |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4505 | } |
Simon Kelley | e759d42 | 2012-03-16 13:18:57 +0000 | [diff] [blame] | 4506 | |
| 4507 | /* Keep list order */ |
| 4508 | if (!daemon->host_records_tail) |
| 4509 | daemon->host_records = new; |
| 4510 | else |
| 4511 | daemon->host_records_tail->next = new; |
| 4512 | new->next = NULL; |
| 4513 | daemon->host_records_tail = new; |
| 4514 | break; |
| 4515 | } |
Simon Kelley | 0fc2f31 | 2014-01-08 10:26:58 +0000 | [diff] [blame] | 4516 | |
| 4517 | #ifdef HAVE_DNSSEC |
Simon Kelley | f3e5787 | 2018-07-20 21:10:48 +0100 | [diff] [blame] | 4518 | case LOPT_DNSSEC_STAMP: /* --dnssec-timestamp */ |
Simon Kelley | f6e62e2 | 2015-03-01 18:17:54 +0000 | [diff] [blame] | 4519 | daemon->timestamp_file = opt_string_alloc(arg); |
| 4520 | break; |
| 4521 | |
Simon Kelley | f3e5787 | 2018-07-20 21:10:48 +0100 | [diff] [blame] | 4522 | case LOPT_DNSSEC_CHECK: /* --dnssec-check-unsigned */ |
Simon Kelley | a691853 | 2018-04-15 16:20:52 +0100 | [diff] [blame] | 4523 | if (arg) |
| 4524 | { |
| 4525 | if (strcmp(arg, "no") == 0) |
| 4526 | set_option_bool(OPT_DNSSEC_IGN_NS); |
| 4527 | else |
| 4528 | ret_err(_("bad value for dnssec-check-unsigned")); |
| 4529 | } |
| 4530 | break; |
| 4531 | |
Simon Kelley | f3e5787 | 2018-07-20 21:10:48 +0100 | [diff] [blame] | 4532 | case LOPT_TRUST_ANCHOR: /* --trust-anchor */ |
Simon Kelley | 0fc2f31 | 2014-01-08 10:26:58 +0000 | [diff] [blame] | 4533 | { |
Simon Kelley | ee41586 | 2014-02-11 11:07:22 +0000 | [diff] [blame] | 4534 | struct ds_config *new = opt_malloc(sizeof(struct ds_config)); |
| 4535 | char *cp, *cp1, *keyhex, *digest, *algo = NULL; |
| 4536 | int len; |
Simon Kelley | cbf13a2 | 2014-01-25 17:59:14 +0000 | [diff] [blame] | 4537 | |
| 4538 | new->class = C_IN; |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4539 | new->name = NULL; |
Simon Kelley | 0fc2f31 | 2014-01-08 10:26:58 +0000 | [diff] [blame] | 4540 | |
Simon Kelley | cbf13a2 | 2014-01-25 17:59:14 +0000 | [diff] [blame] | 4541 | if ((comma = split(arg)) && (algo = split(comma))) |
| 4542 | { |
| 4543 | int class = 0; |
| 4544 | if (strcmp(comma, "IN") == 0) |
| 4545 | class = C_IN; |
| 4546 | else if (strcmp(comma, "CH") == 0) |
| 4547 | class = C_CHAOS; |
| 4548 | else if (strcmp(comma, "HS") == 0) |
| 4549 | class = C_HESIOD; |
| 4550 | |
| 4551 | if (class != 0) |
| 4552 | { |
| 4553 | new->class = class; |
| 4554 | comma = algo; |
| 4555 | algo = split(comma); |
| 4556 | } |
| 4557 | } |
| 4558 | |
Simon Kelley | ee41586 | 2014-02-11 11:07:22 +0000 | [diff] [blame] | 4559 | if (!comma || !algo || !(digest = split(algo)) || !(keyhex = split(digest)) || |
| 4560 | !atoi_check16(comma, &new->keytag) || |
| 4561 | !atoi_check8(algo, &new->algo) || |
| 4562 | !atoi_check8(digest, &new->digest_type) || |
Simon Kelley | cbf13a2 | 2014-01-25 17:59:14 +0000 | [diff] [blame] | 4563 | !(new->name = canonicalise_opt(arg))) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4564 | ret_err_free(_("bad trust anchor"), new); |
Simon Kelley | cbf13a2 | 2014-01-25 17:59:14 +0000 | [diff] [blame] | 4565 | |
Simon Kelley | 0fc2f31 | 2014-01-08 10:26:58 +0000 | [diff] [blame] | 4566 | /* Upper bound on length */ |
Simon Kelley | ee41586 | 2014-02-11 11:07:22 +0000 | [diff] [blame] | 4567 | len = (2*strlen(keyhex))+1; |
| 4568 | new->digest = opt_malloc(len); |
| 4569 | unhide_metas(keyhex); |
| 4570 | /* 4034: "Whitespace is allowed within digits" */ |
| 4571 | for (cp = keyhex; *cp; ) |
| 4572 | if (isspace(*cp)) |
| 4573 | for (cp1 = cp; *cp1; cp1++) |
| 4574 | *cp1 = *(cp1+1); |
| 4575 | else |
| 4576 | cp++; |
| 4577 | if ((new->digestlen = parse_hex(keyhex, (unsigned char *)new->digest, len, NULL, NULL)) == -1) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4578 | { |
| 4579 | free(new->name); |
| 4580 | ret_err_free(_("bad HEX in trust anchor"), new); |
| 4581 | } |
Simon Kelley | 0fc2f31 | 2014-01-08 10:26:58 +0000 | [diff] [blame] | 4582 | |
Simon Kelley | ee41586 | 2014-02-11 11:07:22 +0000 | [diff] [blame] | 4583 | new->next = daemon->ds; |
| 4584 | daemon->ds = new; |
| 4585 | |
Simon Kelley | 0fc2f31 | 2014-01-08 10:26:58 +0000 | [diff] [blame] | 4586 | break; |
| 4587 | } |
| 4588 | #endif |
| 4589 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 4590 | default: |
Simon Kelley | 0fc2f31 | 2014-01-08 10:26:58 +0000 | [diff] [blame] | 4591 | ret_err(_("unsupported option (check that dnsmasq was compiled with DHCP/TFTP/DNSSEC/DBus support)")); |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4592 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4593 | } |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4594 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4595 | return 1; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4596 | } |
| 4597 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4598 | static void read_file(char *file, FILE *f, int hard_opt) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4599 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4600 | volatile int lineno = 0; |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4601 | char *buff = daemon->namebuff; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4602 | |
| 4603 | while (fgets(buff, MAXDNAME, f)) |
| 4604 | { |
Simon Kelley | 7b1eae4 | 2014-02-20 13:43:28 +0000 | [diff] [blame] | 4605 | int white, i; |
| 4606 | volatile int option = (hard_opt == LOPT_REV_SERV) ? 0 : hard_opt; |
Simon Kelley | 13dee6f | 2017-02-28 16:51:58 +0000 | [diff] [blame] | 4607 | char *errmess, *p, *arg, *start; |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4608 | size_t len; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 4609 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4610 | /* Memory allocation failure longjmps here if mem_recover == 1 */ |
Simon Kelley | 7b1eae4 | 2014-02-20 13:43:28 +0000 | [diff] [blame] | 4611 | if (option != 0 || hard_opt == LOPT_REV_SERV) |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4612 | { |
| 4613 | if (setjmp(mem_jmp)) |
| 4614 | continue; |
| 4615 | mem_recover = 1; |
| 4616 | } |
| 4617 | |
Simon Kelley | 13dee6f | 2017-02-28 16:51:58 +0000 | [diff] [blame] | 4618 | arg = NULL; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4619 | lineno++; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4620 | errmess = NULL; |
| 4621 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4622 | /* Implement quotes, inside quotes we allow \\ \" \n and \t |
| 4623 | metacharacters get hidden also strip comments */ |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4624 | for (white = 1, p = buff; *p; p++) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4625 | { |
| 4626 | if (*p == '"') |
| 4627 | { |
| 4628 | memmove(p, p+1, strlen(p+1)+1); |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4629 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4630 | for(; *p && *p != '"'; p++) |
| 4631 | { |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 4632 | if (*p == '\\' && strchr("\"tnebr\\", p[1])) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4633 | { |
| 4634 | if (p[1] == 't') |
| 4635 | p[1] = '\t'; |
| 4636 | else if (p[1] == 'n') |
| 4637 | p[1] = '\n'; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4638 | else if (p[1] == 'b') |
| 4639 | p[1] = '\b'; |
| 4640 | else if (p[1] == 'r') |
| 4641 | p[1] = '\r'; |
Simon Kelley | 6b01084 | 2007-02-12 20:32:07 +0000 | [diff] [blame] | 4642 | else if (p[1] == 'e') /* escape */ |
| 4643 | p[1] = '\033'; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4644 | memmove(p, p+1, strlen(p+1)+1); |
| 4645 | } |
| 4646 | *p = hide_meta(*p); |
| 4647 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4648 | |
| 4649 | if (*p == 0) |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4650 | { |
| 4651 | errmess = _("missing \""); |
| 4652 | goto oops; |
| 4653 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4654 | |
| 4655 | memmove(p, p+1, strlen(p+1)+1); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4656 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4657 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4658 | if (isspace(*p)) |
| 4659 | { |
| 4660 | *p = ' '; |
| 4661 | white = 1; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4662 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4663 | else |
| 4664 | { |
| 4665 | if (white && *p == '#') |
| 4666 | { |
| 4667 | *p = 0; |
| 4668 | break; |
| 4669 | } |
| 4670 | white = 0; |
| 4671 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4672 | } |
| 4673 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4674 | |
| 4675 | /* strip leading spaces */ |
| 4676 | for (start = buff; *start && *start == ' '; start++); |
| 4677 | |
| 4678 | /* strip trailing spaces */ |
| 4679 | for (len = strlen(start); (len != 0) && (start[len-1] == ' '); len--); |
| 4680 | |
| 4681 | if (len == 0) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4682 | continue; |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4683 | else |
| 4684 | start[len] = 0; |
| 4685 | |
Simon Kelley | 611ebc5 | 2012-07-16 16:23:46 +0100 | [diff] [blame] | 4686 | if (option != 0) |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4687 | arg = start; |
| 4688 | else if ((p=strchr(start, '='))) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4689 | { |
| 4690 | /* allow spaces around "=" */ |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4691 | for (arg = p+1; *arg == ' '; arg++); |
| 4692 | for (; p >= start && (*p == ' ' || *p == '='); p--) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4693 | *p = 0; |
| 4694 | } |
| 4695 | else |
| 4696 | arg = NULL; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 4697 | |
Simon Kelley | 611ebc5 | 2012-07-16 16:23:46 +0100 | [diff] [blame] | 4698 | if (option == 0) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 4699 | { |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 4700 | for (option = 0, i = 0; opts[i].name; i++) |
| 4701 | if (strcmp(opts[i].name, start) == 0) |
| 4702 | { |
| 4703 | option = opts[i].val; |
| 4704 | break; |
| 4705 | } |
| 4706 | |
| 4707 | if (!option) |
| 4708 | errmess = _("bad option"); |
| 4709 | else if (opts[i].has_arg == 0 && arg) |
| 4710 | errmess = _("extraneous parameter"); |
| 4711 | else if (opts[i].has_arg == 1 && !arg) |
| 4712 | errmess = _("missing parameter"); |
Simon Kelley | 7b1eae4 | 2014-02-20 13:43:28 +0000 | [diff] [blame] | 4713 | else if (hard_opt == LOPT_REV_SERV && option != 'S' && option != LOPT_REV_SERV) |
| 4714 | errmess = _("illegal option"); |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 4715 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4716 | |
| 4717 | oops: |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 4718 | if (errmess) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4719 | strcpy(daemon->namebuff, errmess); |
| 4720 | |
Simon Kelley | 9bafdc6 | 2018-08-21 22:53:38 +0100 | [diff] [blame] | 4721 | if (errmess || !one_opt(option, arg, daemon->namebuff, _("error"), 0, hard_opt == LOPT_REV_SERV)) |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4722 | { |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4723 | sprintf(daemon->namebuff + strlen(daemon->namebuff), _(" at line %d of %s"), lineno, file); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4724 | if (hard_opt != 0) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4725 | my_syslog(LOG_ERR, "%s", daemon->namebuff); |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 4726 | else |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4727 | die("%s", daemon->namebuff, EC_BADCONF); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4728 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4729 | } |
| 4730 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4731 | mem_recover = 0; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4732 | fclose(f); |
| 4733 | } |
| 4734 | |
Simon Kelley | 4f7bb57 | 2018-03-08 18:47:08 +0000 | [diff] [blame] | 4735 | #if defined(HAVE_DHCP) && defined(HAVE_INOTIFY) |
Simon Kelley | 70d1873 | 2015-01-31 19:59:29 +0000 | [diff] [blame] | 4736 | int option_read_dynfile(char *file, int flags) |
Simon Kelley | 5f4dc5c | 2015-01-20 20:51:02 +0000 | [diff] [blame] | 4737 | { |
Simon Kelley | f9c8637 | 2015-02-03 21:52:48 +0000 | [diff] [blame] | 4738 | my_syslog(MS_DHCP | LOG_INFO, _("read %s"), file); |
| 4739 | |
Simon Kelley | 70d1873 | 2015-01-31 19:59:29 +0000 | [diff] [blame] | 4740 | if (flags & AH_DHCP_HST) |
| 4741 | return one_file(file, LOPT_BANK); |
| 4742 | else if (flags & AH_DHCP_OPT) |
| 4743 | return one_file(file, LOPT_OPTS); |
Simon Kelley | f9c8637 | 2015-02-03 21:52:48 +0000 | [diff] [blame] | 4744 | |
Simon Kelley | 70d1873 | 2015-01-31 19:59:29 +0000 | [diff] [blame] | 4745 | return 0; |
Simon Kelley | 5f4dc5c | 2015-01-20 20:51:02 +0000 | [diff] [blame] | 4746 | } |
| 4747 | #endif |
| 4748 | |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 4749 | static int one_file(char *file, int hard_opt) |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4750 | { |
| 4751 | FILE *f; |
| 4752 | int nofile_ok = 0; |
| 4753 | static int read_stdin = 0; |
| 4754 | static struct fileread { |
| 4755 | dev_t dev; |
| 4756 | ino_t ino; |
| 4757 | struct fileread *next; |
| 4758 | } *filesread = NULL; |
| 4759 | |
| 4760 | if (hard_opt == '7') |
| 4761 | { |
| 4762 | /* default conf-file reading */ |
| 4763 | hard_opt = 0; |
| 4764 | nofile_ok = 1; |
| 4765 | } |
| 4766 | |
| 4767 | if (hard_opt == 0 && strcmp(file, "-") == 0) |
| 4768 | { |
| 4769 | if (read_stdin == 1) |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 4770 | return 1; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4771 | read_stdin = 1; |
| 4772 | file = "stdin"; |
| 4773 | f = stdin; |
| 4774 | } |
| 4775 | else |
| 4776 | { |
| 4777 | /* ignore repeated files. */ |
| 4778 | struct stat statbuf; |
| 4779 | |
| 4780 | if (hard_opt == 0 && stat(file, &statbuf) == 0) |
| 4781 | { |
| 4782 | struct fileread *r; |
| 4783 | |
| 4784 | for (r = filesread; r; r = r->next) |
| 4785 | if (r->dev == statbuf.st_dev && r->ino == statbuf.st_ino) |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 4786 | return 1; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4787 | |
| 4788 | r = safe_malloc(sizeof(struct fileread)); |
| 4789 | r->next = filesread; |
| 4790 | filesread = r; |
| 4791 | r->dev = statbuf.st_dev; |
| 4792 | r->ino = statbuf.st_ino; |
| 4793 | } |
| 4794 | |
| 4795 | if (!(f = fopen(file, "r"))) |
| 4796 | { |
| 4797 | if (errno == ENOENT && nofile_ok) |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 4798 | return 1; /* No conffile, all done. */ |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4799 | else |
| 4800 | { |
| 4801 | char *str = _("cannot read %s: %s"); |
| 4802 | if (hard_opt != 0) |
| 4803 | { |
| 4804 | my_syslog(LOG_ERR, str, file, strerror(errno)); |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 4805 | return 0; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4806 | } |
| 4807 | else |
| 4808 | die(str, file, EC_FILE); |
| 4809 | } |
| 4810 | } |
| 4811 | } |
| 4812 | |
| 4813 | read_file(file, f, hard_opt); |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 4814 | return 1; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4815 | } |
| 4816 | |
| 4817 | /* expand any name which is a directory */ |
| 4818 | struct hostsfile *expand_filelist(struct hostsfile *list) |
| 4819 | { |
Simon Kelley | 19c51cf | 2014-03-18 22:38:30 +0000 | [diff] [blame] | 4820 | unsigned int i; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4821 | struct hostsfile *ah; |
| 4822 | |
Simon Kelley | 19c51cf | 2014-03-18 22:38:30 +0000 | [diff] [blame] | 4823 | /* find largest used index */ |
| 4824 | for (i = SRC_AH, ah = list; ah; ah = ah->next) |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4825 | { |
| 4826 | if (i <= ah->index) |
| 4827 | i = ah->index + 1; |
| 4828 | |
| 4829 | if (ah->flags & AH_DIR) |
| 4830 | ah->flags |= AH_INACTIVE; |
| 4831 | else |
| 4832 | ah->flags &= ~AH_INACTIVE; |
| 4833 | } |
| 4834 | |
| 4835 | for (ah = list; ah; ah = ah->next) |
| 4836 | if (!(ah->flags & AH_INACTIVE)) |
| 4837 | { |
| 4838 | struct stat buf; |
| 4839 | if (stat(ah->fname, &buf) != -1 && S_ISDIR(buf.st_mode)) |
| 4840 | { |
| 4841 | DIR *dir_stream; |
| 4842 | struct dirent *ent; |
| 4843 | |
| 4844 | /* don't read this as a file */ |
| 4845 | ah->flags |= AH_INACTIVE; |
Simon Kelley | 5f4dc5c | 2015-01-20 20:51:02 +0000 | [diff] [blame] | 4846 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4847 | if (!(dir_stream = opendir(ah->fname))) |
| 4848 | my_syslog(LOG_ERR, _("cannot access directory %s: %s"), |
| 4849 | ah->fname, strerror(errno)); |
| 4850 | else |
| 4851 | { |
| 4852 | while ((ent = readdir(dir_stream))) |
| 4853 | { |
| 4854 | size_t lendir = strlen(ah->fname); |
| 4855 | size_t lenfile = strlen(ent->d_name); |
| 4856 | struct hostsfile *ah1; |
| 4857 | char *path; |
| 4858 | |
| 4859 | /* ignore emacs backups and dotfiles */ |
| 4860 | if (lenfile == 0 || |
| 4861 | ent->d_name[lenfile - 1] == '~' || |
| 4862 | (ent->d_name[0] == '#' && ent->d_name[lenfile - 1] == '#') || |
| 4863 | ent->d_name[0] == '.') |
| 4864 | continue; |
| 4865 | |
| 4866 | /* see if we have an existing record. |
| 4867 | dir is ah->fname |
| 4868 | file is ent->d_name |
| 4869 | path to match is ah1->fname */ |
| 4870 | |
| 4871 | for (ah1 = list; ah1; ah1 = ah1->next) |
| 4872 | { |
| 4873 | if (lendir < strlen(ah1->fname) && |
| 4874 | strstr(ah1->fname, ah->fname) == ah1->fname && |
| 4875 | ah1->fname[lendir] == '/' && |
| 4876 | strcmp(ah1->fname + lendir + 1, ent->d_name) == 0) |
| 4877 | { |
| 4878 | ah1->flags &= ~AH_INACTIVE; |
| 4879 | break; |
| 4880 | } |
| 4881 | } |
| 4882 | |
| 4883 | /* make new record */ |
| 4884 | if (!ah1) |
| 4885 | { |
| 4886 | if (!(ah1 = whine_malloc(sizeof(struct hostsfile)))) |
| 4887 | continue; |
| 4888 | |
| 4889 | if (!(path = whine_malloc(lendir + lenfile + 2))) |
| 4890 | { |
| 4891 | free(ah1); |
| 4892 | continue; |
| 4893 | } |
| 4894 | |
| 4895 | strcpy(path, ah->fname); |
| 4896 | strcat(path, "/"); |
| 4897 | strcat(path, ent->d_name); |
| 4898 | ah1->fname = path; |
| 4899 | ah1->index = i++; |
| 4900 | ah1->flags = AH_DIR; |
| 4901 | ah1->next = list; |
| 4902 | list = ah1; |
| 4903 | } |
| 4904 | |
| 4905 | /* inactivate record if not regular file */ |
| 4906 | if ((ah1->flags & AH_DIR) && stat(ah1->fname, &buf) != -1 && !S_ISREG(buf.st_mode)) |
| 4907 | ah1->flags |= AH_INACTIVE; |
| 4908 | |
| 4909 | } |
| 4910 | closedir(dir_stream); |
| 4911 | } |
| 4912 | } |
| 4913 | } |
| 4914 | |
| 4915 | return list; |
| 4916 | } |
| 4917 | |
Simon Kelley | 7b1eae4 | 2014-02-20 13:43:28 +0000 | [diff] [blame] | 4918 | void read_servers_file(void) |
| 4919 | { |
| 4920 | FILE *f; |
| 4921 | |
| 4922 | if (!(f = fopen(daemon->servers_file, "r"))) |
| 4923 | { |
| 4924 | my_syslog(LOG_ERR, _("cannot read %s: %s"), daemon->servers_file, strerror(errno)); |
| 4925 | return; |
| 4926 | } |
| 4927 | |
| 4928 | mark_servers(SERV_FROM_FILE); |
| 4929 | cleanup_servers(); |
| 4930 | |
| 4931 | read_file(daemon->servers_file, f, LOPT_REV_SERV); |
| 4932 | } |
| 4933 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4934 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 4935 | #ifdef HAVE_DHCP |
Simon Kelley | 4f7bb57 | 2018-03-08 18:47:08 +0000 | [diff] [blame] | 4936 | static void clear_dynamic_conf(void) |
| 4937 | { |
| 4938 | struct dhcp_config *configs, *cp, **up; |
| 4939 | |
| 4940 | /* remove existing... */ |
| 4941 | for (up = &daemon->dhcp_conf, configs = daemon->dhcp_conf; configs; configs = cp) |
| 4942 | { |
| 4943 | cp = configs->next; |
| 4944 | |
| 4945 | if (configs->flags & CONFIG_BANK) |
| 4946 | { |
| 4947 | struct hwaddr_config *mac, *tmp; |
| 4948 | struct dhcp_netid_list *list, *tmplist; |
| 4949 | |
| 4950 | for (mac = configs->hwaddr; mac; mac = tmp) |
| 4951 | { |
| 4952 | tmp = mac->next; |
| 4953 | free(mac); |
| 4954 | } |
| 4955 | |
| 4956 | if (configs->flags & CONFIG_CLID) |
| 4957 | free(configs->clid); |
| 4958 | |
| 4959 | for (list = configs->netid; list; list = tmplist) |
| 4960 | { |
| 4961 | free(list->list); |
| 4962 | tmplist = list->next; |
| 4963 | free(list); |
| 4964 | } |
| 4965 | |
| 4966 | if (configs->flags & CONFIG_NAME) |
| 4967 | free(configs->hostname); |
| 4968 | |
| 4969 | *up = configs->next; |
| 4970 | free(configs); |
| 4971 | } |
| 4972 | else |
| 4973 | up = &configs->next; |
| 4974 | } |
| 4975 | } |
| 4976 | |
| 4977 | static void clear_dynamic_opt(void) |
| 4978 | { |
| 4979 | struct dhcp_opt *opts, *cp, **up; |
| 4980 | struct dhcp_netid *id, *next; |
| 4981 | |
| 4982 | for (up = &daemon->dhcp_opts, opts = daemon->dhcp_opts; opts; opts = cp) |
| 4983 | { |
| 4984 | cp = opts->next; |
| 4985 | |
| 4986 | if (opts->flags & DHOPT_BANK) |
| 4987 | { |
| 4988 | if ((opts->flags & DHOPT_VENDOR)) |
| 4989 | free(opts->u.vendor_class); |
| 4990 | free(opts->val); |
| 4991 | for (id = opts->netid; id; id = next) |
| 4992 | { |
| 4993 | next = id->next; |
| 4994 | free(id->net); |
| 4995 | free(id); |
| 4996 | } |
| 4997 | *up = opts->next; |
| 4998 | free(opts); |
| 4999 | } |
| 5000 | else |
| 5001 | up = &opts->next; |
| 5002 | } |
| 5003 | } |
| 5004 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5005 | void reread_dhcp(void) |
| 5006 | { |
Simon Kelley | 4f7bb57 | 2018-03-08 18:47:08 +0000 | [diff] [blame] | 5007 | struct hostsfile *hf; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5008 | |
Simon Kelley | 4f7bb57 | 2018-03-08 18:47:08 +0000 | [diff] [blame] | 5009 | /* Do these even if there is no daemon->dhcp_hosts_file or |
| 5010 | daemon->dhcp_opts_file since entries may have been created by the |
| 5011 | inotify dynamic file reading system. */ |
| 5012 | |
| 5013 | clear_dynamic_conf(); |
| 5014 | clear_dynamic_opt(); |
| 5015 | |
| 5016 | if (daemon->dhcp_hosts_file) |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5017 | { |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5018 | daemon->dhcp_hosts_file = expand_filelist(daemon->dhcp_hosts_file); |
| 5019 | for (hf = daemon->dhcp_hosts_file; hf; hf = hf->next) |
Simon Kelley | 4f7bb57 | 2018-03-08 18:47:08 +0000 | [diff] [blame] | 5020 | if (!(hf->flags & AH_INACTIVE)) |
| 5021 | { |
| 5022 | if (one_file(hf->fname, LOPT_BANK)) |
| 5023 | my_syslog(MS_DHCP | LOG_INFO, _("read %s"), hf->fname); |
| 5024 | } |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5025 | } |
| 5026 | |
| 5027 | if (daemon->dhcp_opts_file) |
| 5028 | { |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5029 | daemon->dhcp_opts_file = expand_filelist(daemon->dhcp_opts_file); |
| 5030 | for (hf = daemon->dhcp_opts_file; hf; hf = hf->next) |
| 5031 | if (!(hf->flags & AH_INACTIVE)) |
| 5032 | { |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 5033 | if (one_file(hf->fname, LOPT_OPTS)) |
| 5034 | my_syslog(MS_DHCP | LOG_INFO, _("read %s"), hf->fname); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5035 | } |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5036 | } |
Simon Kelley | 4f7bb57 | 2018-03-08 18:47:08 +0000 | [diff] [blame] | 5037 | |
| 5038 | # ifdef HAVE_INOTIFY |
| 5039 | /* Setup notify and read pre-existing files. */ |
| 5040 | set_dynamic_inotify(AH_DHCP_HST | AH_DHCP_OPT, 0, NULL, 0); |
| 5041 | # endif |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5042 | } |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 5043 | #endif |
Simon Kelley | 4f7bb57 | 2018-03-08 18:47:08 +0000 | [diff] [blame] | 5044 | |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 5045 | void read_opts(int argc, char **argv, char *compile_opts) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5046 | { |
Neil Jerram | 3bd4c47 | 2018-01-18 22:49:38 +0000 | [diff] [blame] | 5047 | size_t argbuf_size = MAXDNAME; |
| 5048 | char *argbuf = opt_malloc(argbuf_size); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5049 | char *buff = opt_malloc(MAXDNAME); |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 5050 | int option, testmode = 0; |
| 5051 | char *arg, *conffile = NULL; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5052 | |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5053 | opterr = 0; |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 5054 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5055 | daemon = opt_malloc(sizeof(struct daemon)); |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5056 | memset(daemon, 0, sizeof(struct daemon)); |
| 5057 | daemon->namebuff = buff; |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5058 | |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5059 | /* Set defaults - everything else is zero or NULL */ |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5060 | daemon->cachesize = CACHESIZ; |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 5061 | daemon->ftabsize = FTABSIZ; |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5062 | daemon->port = NAMESERVER_PORT; |
Simon Kelley | 9e03894 | 2008-05-30 20:06:34 +0100 | [diff] [blame] | 5063 | daemon->dhcp_client_port = DHCP_CLIENT_PORT; |
| 5064 | daemon->dhcp_server_port = DHCP_SERVER_PORT; |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5065 | daemon->default_resolv.is_default = 1; |
| 5066 | daemon->default_resolv.name = RESOLVFILE; |
| 5067 | daemon->resolv_files = &daemon->default_resolv; |
| 5068 | daemon->username = CHUSER; |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5069 | daemon->runfile = RUNFILE; |
| 5070 | daemon->dhcp_max = MAXLEASES; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 5071 | daemon->tftp_max = TFTP_MAX_CONNECTIONS; |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5072 | daemon->edns_pktsz = EDNS_PKTSZ; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5073 | daemon->log_fac = -1; |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 5074 | daemon->auth_ttl = AUTH_TTL; |
| 5075 | daemon->soa_refresh = SOA_REFRESH; |
| 5076 | daemon->soa_retry = SOA_RETRY; |
| 5077 | daemon->soa_expiry = SOA_EXPIRY; |
Hans Dedecker | 926332a | 2016-01-23 10:48:12 +0000 | [diff] [blame] | 5078 | daemon->max_port = MAX_PORT; |
Simon Kelley | baf553d | 2018-01-29 22:49:27 +0000 | [diff] [blame] | 5079 | daemon->min_port = MIN_PORT; |
Simon Kelley | b5ea1cc | 2014-07-29 16:34:14 +0100 | [diff] [blame] | 5080 | |
Kevin Darbyshire-Bryant | 7ac9ae1 | 2016-09-09 20:52:08 +0100 | [diff] [blame] | 5081 | #ifndef NO_ID |
Simon Kelley | fec216d | 2014-03-27 20:54:34 +0000 | [diff] [blame] | 5082 | add_txt("version.bind", "dnsmasq-" VERSION, 0 ); |
| 5083 | add_txt("authors.bind", "Simon Kelley", 0); |
| 5084 | add_txt("copyright.bind", COPYRIGHT, 0); |
| 5085 | add_txt("cachesize.bind", NULL, TXT_STAT_CACHESIZE); |
| 5086 | add_txt("insertions.bind", NULL, TXT_STAT_INSERTS); |
| 5087 | add_txt("evictions.bind", NULL, TXT_STAT_EVICTIONS); |
| 5088 | add_txt("misses.bind", NULL, TXT_STAT_MISSES); |
| 5089 | add_txt("hits.bind", NULL, TXT_STAT_HITS); |
| 5090 | #ifdef HAVE_AUTH |
| 5091 | add_txt("auth.bind", NULL, TXT_STAT_AUTH); |
| 5092 | #endif |
| 5093 | add_txt("servers.bind", NULL, TXT_STAT_SERVERS); |
Kevin Darbyshire-Bryant | 7ac9ae1 | 2016-09-09 20:52:08 +0100 | [diff] [blame] | 5094 | #endif |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 5095 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5096 | while (1) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5097 | { |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5098 | #ifdef HAVE_GETOPT_LONG |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5099 | option = getopt_long(argc, argv, OPTSTRING, opts, NULL); |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5100 | #else |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5101 | option = getopt(argc, argv, OPTSTRING); |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5102 | #endif |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5103 | |
| 5104 | if (option == -1) |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5105 | { |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 5106 | for (; optind < argc; optind++) |
| 5107 | { |
| 5108 | unsigned char *c = (unsigned char *)argv[optind]; |
| 5109 | for (; *c != 0; c++) |
| 5110 | if (!isspace(*c)) |
| 5111 | die(_("junk found in command line"), NULL, EC_BADCONF); |
| 5112 | } |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5113 | break; |
| 5114 | } |
| 5115 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5116 | /* Copy optarg so that argv doesn't get changed */ |
| 5117 | if (optarg) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5118 | { |
Neil Jerram | 3bd4c47 | 2018-01-18 22:49:38 +0000 | [diff] [blame] | 5119 | if (strlen(optarg) >= argbuf_size) |
| 5120 | { |
| 5121 | free(argbuf); |
| 5122 | argbuf_size = strlen(optarg) + 1; |
| 5123 | argbuf = opt_malloc(argbuf_size); |
| 5124 | } |
Petr Menšík | 47b45b2 | 2018-08-15 18:17:00 +0200 | [diff] [blame] | 5125 | safe_strncpy(argbuf, optarg, argbuf_size); |
Neil Jerram | 3bd4c47 | 2018-01-18 22:49:38 +0000 | [diff] [blame] | 5126 | arg = argbuf; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5127 | } |
| 5128 | else |
| 5129 | arg = NULL; |
| 5130 | |
| 5131 | /* command-line only stuff */ |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 5132 | if (option == LOPT_TEST) |
| 5133 | testmode = 1; |
| 5134 | else if (option == 'w') |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5135 | { |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 5136 | #ifdef HAVE_DHCP |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 5137 | if (argc == 3 && strcmp(argv[2], "dhcp") == 0) |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 5138 | display_opts(); |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 5139 | #ifdef HAVE_DHCP6 |
| 5140 | else if (argc == 3 && strcmp(argv[2], "dhcp6") == 0) |
| 5141 | display_opts6(); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 5142 | #endif |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 5143 | else |
| 5144 | #endif |
| 5145 | do_usage(); |
| 5146 | |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5147 | exit(0); |
| 5148 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5149 | else if (option == 'v') |
| 5150 | { |
| 5151 | printf(_("Dnsmasq version %s %s\n"), VERSION, COPYRIGHT); |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 5152 | printf(_("Compile time options: %s\n\n"), compile_opts); |
Simon Kelley | b8187c8 | 2005-11-26 21:46:27 +0000 | [diff] [blame] | 5153 | printf(_("This software comes with ABSOLUTELY NO WARRANTY.\n")); |
| 5154 | printf(_("Dnsmasq is free software, and you are welcome to redistribute it\n")); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5155 | printf(_("under the terms of the GNU General Public License, version 2 or 3.\n")); |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5156 | exit(0); |
| 5157 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5158 | else if (option == 'C') |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5159 | { |
Simon Kelley | 5c464ef | 2019-03-29 23:11:05 +0000 | [diff] [blame] | 5160 | if (!conffile) |
| 5161 | conffile = opt_string_alloc(arg); |
| 5162 | else |
| 5163 | { |
| 5164 | char *extra = opt_string_alloc(arg); |
| 5165 | one_file(extra, 0); |
| 5166 | free(extra); |
| 5167 | } |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5168 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5169 | else |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5170 | { |
Simon Kelley | 26128d2 | 2004-11-14 16:43:54 +0000 | [diff] [blame] | 5171 | #ifdef HAVE_GETOPT_LONG |
Simon Kelley | 7b1eae4 | 2014-02-20 13:43:28 +0000 | [diff] [blame] | 5172 | if (!one_opt(option, arg, daemon->namebuff, _("try --help"), 1, 0)) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5173 | #else |
Simon Kelley | 7b1eae4 | 2014-02-20 13:43:28 +0000 | [diff] [blame] | 5174 | if (!one_opt(option, arg, daemon->namebuff, _("try -w"), 1, 0)) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5175 | #endif |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 5176 | die(_("bad command line options: %s"), daemon->namebuff, EC_BADCONF); |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5177 | } |
| 5178 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5179 | |
Neil Jerram | 3bd4c47 | 2018-01-18 22:49:38 +0000 | [diff] [blame] | 5180 | free(argbuf); |
| 5181 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5182 | if (conffile) |
Chen Wei | 28b879a | 2015-02-17 22:07:35 +0000 | [diff] [blame] | 5183 | { |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 5184 | one_file(conffile, 0); |
| 5185 | free(conffile); |
Chen Wei | 28b879a | 2015-02-17 22:07:35 +0000 | [diff] [blame] | 5186 | } |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 5187 | else |
| 5188 | one_file(CONFFILE, '7'); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5189 | |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 5190 | /* port might not be known when the address is parsed - fill in here */ |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5191 | if (daemon->servers) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5192 | { |
| 5193 | struct server *tmp; |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5194 | for (tmp = daemon->servers; tmp; tmp = tmp->next) |
Simon Kelley | 14ffa07 | 2016-04-25 16:36:44 +0100 | [diff] [blame] | 5195 | if (!(tmp->flags & SERV_HAS_SOURCE)) |
| 5196 | { |
| 5197 | if (tmp->source_addr.sa.sa_family == AF_INET) |
| 5198 | tmp->source_addr.in.sin_port = htons(daemon->query_port); |
Simon Kelley | 14ffa07 | 2016-04-25 16:36:44 +0100 | [diff] [blame] | 5199 | else if (tmp->source_addr.sa.sa_family == AF_INET6) |
| 5200 | tmp->source_addr.in6.sin6_port = htons(daemon->query_port); |
Simon Kelley | 14ffa07 | 2016-04-25 16:36:44 +0100 | [diff] [blame] | 5201 | } |
| 5202 | } |
| 5203 | |
Simon Kelley | df3d54f | 2016-02-24 21:03:38 +0000 | [diff] [blame] | 5204 | if (daemon->host_records) |
| 5205 | { |
| 5206 | struct host_record *hr; |
| 5207 | |
| 5208 | for (hr = daemon->host_records; hr; hr = hr->next) |
| 5209 | if (hr->ttl == -1) |
| 5210 | hr->ttl = daemon->local_ttl; |
| 5211 | } |
| 5212 | |
| 5213 | if (daemon->cnames) |
| 5214 | { |
Simon Kelley | 903df07 | 2017-01-19 17:22:00 +0000 | [diff] [blame] | 5215 | struct cname *cn, *cn2, *cn3; |
| 5216 | |
| 5217 | #define NOLOOP 1 |
| 5218 | #define TESTLOOP 2 |
| 5219 | |
Simon Kelley | 157d8cf | 2019-10-25 17:46:49 +0100 | [diff] [blame] | 5220 | /* Fill in TTL for CNAMES now we have local_ttl. |
Simon Kelley | 903df07 | 2017-01-19 17:22:00 +0000 | [diff] [blame] | 5221 | Also prepare to do loop detection. */ |
Simon Kelley | df3d54f | 2016-02-24 21:03:38 +0000 | [diff] [blame] | 5222 | for (cn = daemon->cnames; cn; cn = cn->next) |
Simon Kelley | 903df07 | 2017-01-19 17:22:00 +0000 | [diff] [blame] | 5223 | { |
| 5224 | if (cn->ttl == -1) |
| 5225 | cn->ttl = daemon->local_ttl; |
| 5226 | cn->flag = 0; |
| 5227 | cn->targetp = NULL; |
| 5228 | for (cn2 = daemon->cnames; cn2; cn2 = cn2->next) |
| 5229 | if (hostname_isequal(cn->target, cn2->alias)) |
| 5230 | { |
| 5231 | cn->targetp = cn2; |
| 5232 | break; |
| 5233 | } |
| 5234 | } |
| 5235 | |
| 5236 | /* Find any CNAME loops.*/ |
| 5237 | for (cn = daemon->cnames; cn; cn = cn->next) |
| 5238 | { |
| 5239 | for (cn2 = cn->targetp; cn2; cn2 = cn2->targetp) |
| 5240 | { |
| 5241 | if (cn2->flag == NOLOOP) |
| 5242 | break; |
| 5243 | |
| 5244 | if (cn2->flag == TESTLOOP) |
| 5245 | die(_("CNAME loop involving %s"), cn->alias, EC_BADCONF); |
| 5246 | |
| 5247 | cn2->flag = TESTLOOP; |
| 5248 | } |
| 5249 | |
| 5250 | for (cn3 = cn->targetp; cn3 != cn2; cn3 = cn3->targetp) |
| 5251 | cn3->flag = NOLOOP; |
| 5252 | } |
Simon Kelley | df3d54f | 2016-02-24 21:03:38 +0000 | [diff] [blame] | 5253 | } |
| 5254 | |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5255 | if (daemon->if_addrs) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5256 | { |
| 5257 | struct iname *tmp; |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5258 | for(tmp = daemon->if_addrs; tmp; tmp = tmp->next) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5259 | if (tmp->addr.sa.sa_family == AF_INET) |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5260 | tmp->addr.in.sin_port = htons(daemon->port); |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5261 | else if (tmp->addr.sa.sa_family == AF_INET6) |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5262 | tmp->addr.in6.sin6_port = htons(daemon->port); |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5263 | } |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 5264 | |
| 5265 | /* create default, if not specified */ |
| 5266 | if (daemon->authserver && !daemon->hostmaster) |
| 5267 | { |
| 5268 | strcpy(buff, "hostmaster."); |
| 5269 | strcat(buff, daemon->authserver); |
| 5270 | daemon->hostmaster = opt_string_alloc(buff); |
| 5271 | } |
Wang Shanker | 4ded962 | 2020-12-04 10:17:35 +0800 | [diff] [blame] | 5272 | |
| 5273 | if (!daemon->dhcp_pxe_vendors) |
| 5274 | { |
| 5275 | daemon->dhcp_pxe_vendors = opt_malloc(sizeof(struct dhcp_pxe_vendor)); |
| 5276 | daemon->dhcp_pxe_vendors->data = opt_string_alloc(DHCP_PXE_DEF_VENDOR); |
| 5277 | daemon->dhcp_pxe_vendors->next = NULL; |
| 5278 | } |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 5279 | |
Simon Kelley | f6b7dc4 | 2005-01-23 12:06:08 +0000 | [diff] [blame] | 5280 | /* only one of these need be specified: the other defaults to the host-name */ |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5281 | if (option_bool(OPT_LOCALMX) || daemon->mxnames || daemon->mxtarget) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5282 | { |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 5283 | struct mx_srv_record *mx; |
| 5284 | |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5285 | if (gethostname(buff, MAXDNAME) == -1) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 5286 | die(_("cannot get host-name: %s"), NULL, EC_MISC); |
Simon Kelley | f6b7dc4 | 2005-01-23 12:06:08 +0000 | [diff] [blame] | 5287 | |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 5288 | for (mx = daemon->mxnames; mx; mx = mx->next) |
| 5289 | if (!mx->issrv && hostname_isequal(mx->name, buff)) |
| 5290 | break; |
| 5291 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5292 | if ((daemon->mxtarget || option_bool(OPT_LOCALMX)) && !mx) |
Simon Kelley | de37951 | 2004-06-22 20:23:33 +0100 | [diff] [blame] | 5293 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5294 | mx = opt_malloc(sizeof(struct mx_srv_record)); |
Simon Kelley | 91dccd0 | 2005-03-31 17:48:32 +0100 | [diff] [blame] | 5295 | mx->next = daemon->mxnames; |
| 5296 | mx->issrv = 0; |
| 5297 | mx->target = NULL; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5298 | mx->name = opt_string_alloc(buff); |
Simon Kelley | 91dccd0 | 2005-03-31 17:48:32 +0100 | [diff] [blame] | 5299 | daemon->mxnames = mx; |
Simon Kelley | f6b7dc4 | 2005-01-23 12:06:08 +0000 | [diff] [blame] | 5300 | } |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5301 | |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5302 | if (!daemon->mxtarget) |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5303 | daemon->mxtarget = opt_string_alloc(buff); |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 5304 | |
| 5305 | for (mx = daemon->mxnames; mx; mx = mx->next) |
| 5306 | if (!mx->issrv && !mx->target) |
| 5307 | mx->target = daemon->mxtarget; |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5308 | } |
Simon Kelley | f6b7dc4 | 2005-01-23 12:06:08 +0000 | [diff] [blame] | 5309 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5310 | if (!option_bool(OPT_NO_RESOLV) && |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 5311 | daemon->resolv_files && |
| 5312 | daemon->resolv_files->next && |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5313 | option_bool(OPT_NO_POLL)) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 5314 | die(_("only one resolv.conf file allowed in no-poll mode."), NULL, EC_BADCONF); |
Simon Kelley | de37951 | 2004-06-22 20:23:33 +0100 | [diff] [blame] | 5315 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5316 | if (option_bool(OPT_RESOLV_DOMAIN)) |
Simon Kelley | de37951 | 2004-06-22 20:23:33 +0100 | [diff] [blame] | 5317 | { |
| 5318 | char *line; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5319 | FILE *f; |
| 5320 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5321 | if (option_bool(OPT_NO_RESOLV) || |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 5322 | !daemon->resolv_files || |
| 5323 | (daemon->resolv_files)->next) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 5324 | die(_("must have exactly one resolv.conf to read domain from."), NULL, EC_BADCONF); |
Simon Kelley | de37951 | 2004-06-22 20:23:33 +0100 | [diff] [blame] | 5325 | |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5326 | if (!(f = fopen((daemon->resolv_files)->name, "r"))) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 5327 | die(_("failed to read %s: %s"), (daemon->resolv_files)->name, EC_FILE); |
Simon Kelley | de37951 | 2004-06-22 20:23:33 +0100 | [diff] [blame] | 5328 | |
| 5329 | while ((line = fgets(buff, MAXDNAME, f))) |
| 5330 | { |
| 5331 | char *token = strtok(line, " \t\n\r"); |
| 5332 | |
| 5333 | if (!token || strcmp(token, "search") != 0) |
| 5334 | continue; |
| 5335 | |
| 5336 | if ((token = strtok(NULL, " \t\n\r")) && |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 5337 | (daemon->domain_suffix = canonicalise_opt(token))) |
Simon Kelley | de37951 | 2004-06-22 20:23:33 +0100 | [diff] [blame] | 5338 | break; |
| 5339 | } |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5340 | |
Simon Kelley | de37951 | 2004-06-22 20:23:33 +0100 | [diff] [blame] | 5341 | fclose(f); |
Simon Kelley | 8a911cc | 2004-03-16 18:35:52 +0000 | [diff] [blame] | 5342 | |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5343 | if (!daemon->domain_suffix) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 5344 | die(_("no search directive found in %s"), (daemon->resolv_files)->name, EC_MISC); |
Simon Kelley | de37951 | 2004-06-22 20:23:33 +0100 | [diff] [blame] | 5345 | } |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 5346 | |
| 5347 | if (daemon->domain_suffix) |
| 5348 | { |
| 5349 | /* add domain for any srv record without one. */ |
| 5350 | struct mx_srv_record *srv; |
Simon Kelley | de37951 | 2004-06-22 20:23:33 +0100 | [diff] [blame] | 5351 | |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 5352 | for (srv = daemon->mxnames; srv; srv = srv->next) |
| 5353 | if (srv->issrv && |
| 5354 | strchr(srv->name, '.') && |
| 5355 | strchr(srv->name, '.') == strrchr(srv->name, '.')) |
| 5356 | { |
| 5357 | strcpy(buff, srv->name); |
| 5358 | strcat(buff, "."); |
| 5359 | strcat(buff, daemon->domain_suffix); |
| 5360 | free(srv->name); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5361 | srv->name = opt_string_alloc(buff); |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 5362 | } |
| 5363 | } |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5364 | else if (option_bool(OPT_DHCP_FQDN)) |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 5365 | die(_("there must be a default domain when --dhcp-fqdn is set"), NULL, EC_BADCONF); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 5366 | |
Simon Kelley | c8a8048 | 2014-03-05 14:29:54 +0000 | [diff] [blame] | 5367 | /* If there's access-control config, then ignore --local-service, it's intended |
| 5368 | as a system default to keep otherwise unconfigured installations safe. */ |
| 5369 | if (daemon->if_names || daemon->if_except || daemon->if_addrs || daemon->authserver) |
| 5370 | reset_option_bool(OPT_LOCAL_SERVICE); |
| 5371 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 5372 | if (testmode) |
| 5373 | { |
| 5374 | fprintf(stderr, "dnsmasq: %s.\n", _("syntax check OK")); |
| 5375 | exit(0); |
| 5376 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5377 | } |