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> |
Kyle Swenson | 545712c | 2021-11-17 12:25:04 -0700 | [diff] [blame] | 21 | /* CRADLEPOINT */ |
| 22 | #include "unescape_c_string.h" |
| 23 | #include "opendns.h" |
| 24 | /* CRADLEPOINT */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 25 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 26 | static volatile int mem_recover = 0; |
| 27 | static jmp_buf mem_jmp; |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 28 | static int one_file(char *file, int hard_opt); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 29 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 30 | /* Solaris headers don't have facility names. */ |
| 31 | #ifdef HAVE_SOLARIS_NETWORK |
| 32 | static const struct { |
| 33 | char *c_name; |
| 34 | unsigned int c_val; |
| 35 | } facilitynames[] = { |
| 36 | { "kern", LOG_KERN }, |
| 37 | { "user", LOG_USER }, |
| 38 | { "mail", LOG_MAIL }, |
| 39 | { "daemon", LOG_DAEMON }, |
| 40 | { "auth", LOG_AUTH }, |
| 41 | { "syslog", LOG_SYSLOG }, |
| 42 | { "lpr", LOG_LPR }, |
| 43 | { "news", LOG_NEWS }, |
| 44 | { "uucp", LOG_UUCP }, |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 45 | { "audit", LOG_AUDIT }, |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 46 | { "cron", LOG_CRON }, |
| 47 | { "local0", LOG_LOCAL0 }, |
| 48 | { "local1", LOG_LOCAL1 }, |
| 49 | { "local2", LOG_LOCAL2 }, |
| 50 | { "local3", LOG_LOCAL3 }, |
| 51 | { "local4", LOG_LOCAL4 }, |
| 52 | { "local5", LOG_LOCAL5 }, |
| 53 | { "local6", LOG_LOCAL6 }, |
| 54 | { "local7", LOG_LOCAL7 }, |
| 55 | { NULL, 0 } |
| 56 | }; |
| 57 | #endif |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 58 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 59 | #ifndef HAVE_GETOPT_LONG |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 60 | struct myoption { |
| 61 | const char *name; |
| 62 | int has_arg; |
| 63 | int *flag; |
| 64 | int val; |
| 65 | }; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 66 | #endif |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 67 | |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 68 | #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] | 69 | |
Simon Kelley | 1697269 | 2006-10-16 20:04:18 +0100 | [diff] [blame] | 70 | /* options which don't have a one-char version */ |
Simon Kelley | e98bd52 | 2014-03-28 20:41:23 +0000 | [diff] [blame] | 71 | #define LOPT_RELOAD 256 |
| 72 | #define LOPT_NO_NAMES 257 |
| 73 | #define LOPT_TFTP 258 |
| 74 | #define LOPT_SECURE 259 |
| 75 | #define LOPT_PREFIX 260 |
| 76 | #define LOPT_PTR 261 |
| 77 | #define LOPT_BRIDGE 262 |
| 78 | #define LOPT_TFTP_MAX 263 |
| 79 | #define LOPT_FORCE 264 |
| 80 | #define LOPT_NOBLOCK 265 |
| 81 | #define LOPT_LOG_OPTS 266 |
| 82 | #define LOPT_MAX_LOGS 267 |
| 83 | #define LOPT_CIRCUIT 268 |
| 84 | #define LOPT_REMOTE 269 |
| 85 | #define LOPT_SUBSCR 270 |
| 86 | #define LOPT_INTNAME 271 |
| 87 | #define LOPT_BANK 272 |
| 88 | #define LOPT_DHCP_HOST 273 |
| 89 | #define LOPT_APREF 274 |
| 90 | #define LOPT_OVERRIDE 275 |
| 91 | #define LOPT_TFTPPORTS 276 |
| 92 | #define LOPT_REBIND 277 |
| 93 | #define LOPT_NOLAST 278 |
| 94 | #define LOPT_OPTS 279 |
| 95 | #define LOPT_DHCP_OPTS 280 |
| 96 | #define LOPT_MATCH 281 |
| 97 | #define LOPT_BROADCAST 282 |
| 98 | #define LOPT_NEGTTL 283 |
| 99 | #define LOPT_ALTPORT 284 |
| 100 | #define LOPT_SCRIPTUSR 285 |
| 101 | #define LOPT_LOCAL 286 |
| 102 | #define LOPT_NAPTR 287 |
| 103 | #define LOPT_MINPORT 288 |
| 104 | #define LOPT_DHCP_FQDN 289 |
| 105 | #define LOPT_CNAME 290 |
| 106 | #define LOPT_PXE_PROMT 291 |
| 107 | #define LOPT_PXE_SERV 292 |
| 108 | #define LOPT_TEST 293 |
| 109 | #define LOPT_TAG_IF 294 |
| 110 | #define LOPT_PROXY 295 |
| 111 | #define LOPT_GEN_NAMES 296 |
| 112 | #define LOPT_MAXTTL 297 |
| 113 | #define LOPT_NO_REBIND 298 |
| 114 | #define LOPT_LOC_REBND 299 |
| 115 | #define LOPT_ADD_MAC 300 |
| 116 | #define LOPT_DNSSEC 301 |
| 117 | #define LOPT_INCR_ADDR 302 |
| 118 | #define LOPT_CONNTRACK 303 |
| 119 | #define LOPT_FQDN 304 |
| 120 | #define LOPT_LUASCRIPT 305 |
| 121 | #define LOPT_RA 306 |
| 122 | #define LOPT_DUID 307 |
| 123 | #define LOPT_HOST_REC 308 |
| 124 | #define LOPT_TFTP_LC 309 |
| 125 | #define LOPT_RR 310 |
| 126 | #define LOPT_CLVERBIND 311 |
| 127 | #define LOPT_MAXCTTL 312 |
| 128 | #define LOPT_AUTHZONE 313 |
| 129 | #define LOPT_AUTHSERV 314 |
| 130 | #define LOPT_AUTHTTL 315 |
| 131 | #define LOPT_AUTHSOA 316 |
| 132 | #define LOPT_AUTHSFS 317 |
| 133 | #define LOPT_AUTHPEER 318 |
| 134 | #define LOPT_IPSET 319 |
| 135 | #define LOPT_SYNTH 320 |
Simon Kelley | e98bd52 | 2014-03-28 20:41:23 +0000 | [diff] [blame] | 136 | #define LOPT_RELAY 323 |
| 137 | #define LOPT_RA_PARAM 324 |
| 138 | #define LOPT_ADD_SBNET 325 |
| 139 | #define LOPT_QUIET_DHCP 326 |
| 140 | #define LOPT_QUIET_DHCP6 327 |
| 141 | #define LOPT_QUIET_RA 328 |
| 142 | #define LOPT_SEC_VALID 329 |
| 143 | #define LOPT_TRUST_ANCHOR 330 |
| 144 | #define LOPT_DNSSEC_DEBUG 331 |
| 145 | #define LOPT_REV_SERV 332 |
| 146 | #define LOPT_SERVERS_FILE 333 |
| 147 | #define LOPT_DNSSEC_CHECK 334 |
Simon Kelley | c8a8048 | 2014-03-05 14:29:54 +0000 | [diff] [blame] | 148 | #define LOPT_LOCAL_SERVICE 335 |
Simon Kelley | e98bd52 | 2014-03-28 20:41:23 +0000 | [diff] [blame] | 149 | #define LOPT_DNSSEC_TIME 336 |
Simon Kelley | b5ea1cc | 2014-07-29 16:34:14 +0100 | [diff] [blame] | 150 | #define LOPT_LOOP_DETECT 337 |
Glen Huang | 32fc6db | 2014-12-27 15:28:12 +0000 | [diff] [blame] | 151 | #define LOPT_IGNORE_ADDR 338 |
RinSatsuki | 28de387 | 2015-01-10 15:22:21 +0000 | [diff] [blame] | 152 | #define LOPT_MINCTTL 339 |
Simon Kelley | 5f4dc5c | 2015-01-20 20:51:02 +0000 | [diff] [blame] | 153 | #define LOPT_DHCP_INOTIFY 340 |
Simon Kelley | 70d1873 | 2015-01-31 19:59:29 +0000 | [diff] [blame] | 154 | #define LOPT_DHOPT_INOTIFY 341 |
| 155 | #define LOPT_HOST_INOTIFY 342 |
Simon Kelley | f6e62e2 | 2015-03-01 18:17:54 +0000 | [diff] [blame] | 156 | #define LOPT_DNSSEC_STAMP 343 |
Stefan Tomanek | 30d0879 | 2015-03-31 22:32:11 +0100 | [diff] [blame] | 157 | #define LOPT_TFTP_NO_FAIL 344 |
Hans Dedecker | 926332a | 2016-01-23 10:48:12 +0000 | [diff] [blame] | 158 | #define LOPT_MAXPORT 345 |
Simon Kelley | 1e50512 | 2016-01-25 21:29:23 +0000 | [diff] [blame] | 159 | #define LOPT_CPE_ID 346 |
| 160 | #define LOPT_SCRIPT_ARP 347 |
Simon Kelley | 832e47b | 2016-02-24 21:24:45 +0000 | [diff] [blame] | 161 | #define LOPT_DHCPTTL 348 |
Simon Kelley | bec366b | 2016-02-24 22:03:26 +0000 | [diff] [blame] | 162 | #define LOPT_TFTP_MTU 349 |
Floris Bos | 503c609 | 2017-04-09 23:07:13 +0100 | [diff] [blame] | 163 | #define LOPT_REPLY_DELAY 350 |
Simon Kelley | 734d531 | 2018-03-23 23:09:53 +0000 | [diff] [blame] | 164 | #define LOPT_RAPID_COMMIT 351 |
Simon Kelley | 6b17335 | 2018-05-08 18:32:14 +0100 | [diff] [blame] | 165 | #define LOPT_DUMPFILE 352 |
| 166 | #define LOPT_DUMPMASK 353 |
Julian Kornberger | 8dcdb33 | 2018-07-21 22:11:08 +0100 | [diff] [blame] | 167 | #define LOPT_UBUS 354 |
Simon Kelley | c822620 | 2018-08-08 23:46:03 +0100 | [diff] [blame] | 168 | #define LOPT_NAME_MATCH 355 |
Simon Kelley | 974a6d0 | 2018-08-23 23:01:16 +0100 | [diff] [blame] | 169 | #define LOPT_CAA 356 |
Simon Kelley | ae5b7e0 | 2019-03-27 22:33:28 +0000 | [diff] [blame] | 170 | #define LOPT_SHARED_NET 357 |
Florent Fourcot | 13a58f9 | 2019-06-20 10:26:40 +0200 | [diff] [blame] | 171 | #define LOPT_IGNORE_CLID 358 |
Simon Kelley | 66f6265 | 2020-01-05 16:21:24 +0000 | [diff] [blame] | 172 | #define LOPT_SINGLE_PORT 359 |
Simon Kelley | ee64582 | 2020-02-27 16:34:14 +0000 | [diff] [blame] | 173 | #define LOPT_SCRIPT_TIME 360 |
Wang Shanker | 4ded962 | 2020-12-04 10:17:35 +0800 | [diff] [blame] | 174 | #define LOPT_PXE_VENDOR 361 |
Simon Kelley | b7cf754 | 2021-03-04 16:54:14 +0000 | [diff] [blame] | 175 | #define LOPT_DYNHOST 362 |
Simon Kelley | b260d22 | 2021-03-12 21:57:57 +0000 | [diff] [blame] | 176 | #define LOPT_LOG_DEBUG 363 |
Kyle Swenson | 545712c | 2021-11-17 12:25:04 -0700 | [diff] [blame] | 177 | /* CRADLEPOINT */ |
| 178 | #define LOPT_EDNS_OPTION 364 |
| 179 | #define LOPT_SSID_MAP 365 |
Kyle Swenson | ba77fe8 | 2021-11-19 09:33:46 -0700 | [diff] [blame] | 180 | #define LOPT_EDNS_RESTRICT 366 |
Kyle Swenson | 545712c | 2021-11-17 12:25:04 -0700 | [diff] [blame] | 181 | /* CRADLEPOINT */ |
Tarun Kundu | 024baf1 | 2022-06-28 10:56:47 -0700 | [diff] [blame] | 182 | #define LOPT_RA_ADV_DISABLE 367 |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 183 | #ifdef HAVE_GETOPT_LONG |
| 184 | static const struct option opts[] = |
| 185 | #else |
| 186 | static const struct myoption opts[] = |
| 187 | #endif |
| 188 | { |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 189 | { "version", 0, 0, 'v' }, |
| 190 | { "no-hosts", 0, 0, 'h' }, |
| 191 | { "no-poll", 0, 0, 'n' }, |
| 192 | { "help", 0, 0, 'w' }, |
| 193 | { "no-daemon", 0, 0, 'd' }, |
Simon Kelley | 25cf5e3 | 2015-01-09 15:53:03 +0000 | [diff] [blame] | 194 | { "log-queries", 2, 0, 'q' }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 195 | { "user", 2, 0, 'u' }, |
| 196 | { "group", 2, 0, 'g' }, |
| 197 | { "resolv-file", 2, 0, 'r' }, |
Simon Kelley | 7b1eae4 | 2014-02-20 13:43:28 +0000 | [diff] [blame] | 198 | { "servers-file", 1, 0, LOPT_SERVERS_FILE }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 199 | { "mx-host", 1, 0, 'm' }, |
| 200 | { "mx-target", 1, 0, 't' }, |
| 201 | { "cache-size", 2, 0, 'c' }, |
| 202 | { "port", 1, 0, 'p' }, |
| 203 | { "dhcp-leasefile", 2, 0, 'l' }, |
| 204 | { "dhcp-lease", 1, 0, 'l' }, |
| 205 | { "dhcp-host", 1, 0, 'G' }, |
| 206 | { "dhcp-range", 1, 0, 'F' }, |
| 207 | { "dhcp-option", 1, 0, 'O' }, |
| 208 | { "dhcp-boot", 1, 0, 'M' }, |
| 209 | { "domain", 1, 0, 's' }, |
| 210 | { "domain-suffix", 1, 0, 's' }, |
| 211 | { "interface", 1, 0, 'i' }, |
| 212 | { "listen-address", 1, 0, 'a' }, |
Simon Kelley | c8a8048 | 2014-03-05 14:29:54 +0000 | [diff] [blame] | 213 | { "local-service", 0, 0, LOPT_LOCAL_SERVICE }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 214 | { "bogus-priv", 0, 0, 'b' }, |
| 215 | { "bogus-nxdomain", 1, 0, 'B' }, |
Glen Huang | 32fc6db | 2014-12-27 15:28:12 +0000 | [diff] [blame] | 216 | { "ignore-address", 1, 0, LOPT_IGNORE_ADDR }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 217 | { "selfmx", 0, 0, 'e' }, |
| 218 | { "filterwin2k", 0, 0, 'f' }, |
| 219 | { "pid-file", 2, 0, 'x' }, |
| 220 | { "strict-order", 0, 0, 'o' }, |
| 221 | { "server", 1, 0, 'S' }, |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 222 | { "rev-server", 1, 0, LOPT_REV_SERV }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 223 | { "local", 1, 0, LOPT_LOCAL }, |
| 224 | { "address", 1, 0, 'A' }, |
| 225 | { "conf-file", 2, 0, 'C' }, |
| 226 | { "no-resolv", 0, 0, 'R' }, |
| 227 | { "expand-hosts", 0, 0, 'E' }, |
| 228 | { "localmx", 0, 0, 'L' }, |
| 229 | { "local-ttl", 1, 0, 'T' }, |
| 230 | { "no-negcache", 0, 0, 'N' }, |
| 231 | { "addn-hosts", 1, 0, 'H' }, |
Simon Kelley | 70d1873 | 2015-01-31 19:59:29 +0000 | [diff] [blame] | 232 | { "hostsdir", 1, 0, LOPT_HOST_INOTIFY }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 233 | { "query-port", 1, 0, 'Q' }, |
| 234 | { "except-interface", 1, 0, 'I' }, |
| 235 | { "no-dhcp-interface", 1, 0, '2' }, |
| 236 | { "domain-needed", 0, 0, 'D' }, |
| 237 | { "dhcp-lease-max", 1, 0, 'X' }, |
| 238 | { "bind-interfaces", 0, 0, 'z' }, |
| 239 | { "read-ethers", 0, 0, 'Z' }, |
| 240 | { "alias", 1, 0, 'V' }, |
| 241 | { "dhcp-vendorclass", 1, 0, 'U' }, |
| 242 | { "dhcp-userclass", 1, 0, 'j' }, |
| 243 | { "dhcp-ignore", 1, 0, 'J' }, |
| 244 | { "edns-packet-max", 1, 0, 'P' }, |
| 245 | { "keep-in-foreground", 0, 0, 'k' }, |
| 246 | { "dhcp-authoritative", 0, 0, 'K' }, |
| 247 | { "srv-host", 1, 0, 'W' }, |
| 248 | { "localise-queries", 0, 0, 'y' }, |
| 249 | { "txt-record", 1, 0, 'Y' }, |
Simon Kelley | 974a6d0 | 2018-08-23 23:01:16 +0100 | [diff] [blame] | 250 | { "caa-record", 1, 0 , LOPT_CAA }, |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 251 | { "dns-rr", 1, 0, LOPT_RR }, |
Simon Kelley | ad09427 | 2012-08-10 17:10:54 +0100 | [diff] [blame] | 252 | { "enable-dbus", 2, 0, '1' }, |
Oldřich Jedlička | d162bee | 2020-03-20 22:18:57 +0100 | [diff] [blame] | 253 | { "enable-ubus", 2, 0, LOPT_UBUS }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 254 | { "bootp-dynamic", 2, 0, '3' }, |
| 255 | { "dhcp-mac", 1, 0, '4' }, |
| 256 | { "no-ping", 0, 0, '5' }, |
| 257 | { "dhcp-script", 1, 0, '6' }, |
| 258 | { "conf-dir", 1, 0, '7' }, |
| 259 | { "log-facility", 1, 0 ,'8' }, |
| 260 | { "leasefile-ro", 0, 0, '9' }, |
Simon Kelley | ee64582 | 2020-02-27 16:34:14 +0000 | [diff] [blame] | 261 | { "script-on-renewal", 0, 0, LOPT_SCRIPT_TIME}, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 262 | { "dns-forward-max", 1, 0, '0' }, |
| 263 | { "clear-on-reload", 0, 0, LOPT_RELOAD }, |
| 264 | { "dhcp-ignore-names", 2, 0, LOPT_NO_NAMES }, |
Simon Kelley | 2937f8a | 2013-07-29 19:49:07 +0100 | [diff] [blame] | 265 | { "enable-tftp", 2, 0, LOPT_TFTP }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 266 | { "tftp-secure", 0, 0, LOPT_SECURE }, |
Stefan Tomanek | 30d0879 | 2015-03-31 22:32:11 +0100 | [diff] [blame] | 267 | { "tftp-no-fail", 0, 0, LOPT_TFTP_NO_FAIL }, |
Floris Bos | 60704f5 | 2017-04-09 22:22:49 +0100 | [diff] [blame] | 268 | { "tftp-unique-root", 2, 0, LOPT_APREF }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 269 | { "tftp-root", 1, 0, LOPT_PREFIX }, |
| 270 | { "tftp-max", 1, 0, LOPT_TFTP_MAX }, |
Simon Kelley | bec366b | 2016-02-24 22:03:26 +0000 | [diff] [blame] | 271 | { "tftp-mtu", 1, 0, LOPT_TFTP_MTU }, |
Simon Kelley | 61ce600 | 2012-04-20 21:28:49 +0100 | [diff] [blame] | 272 | { "tftp-lowercase", 0, 0, LOPT_TFTP_LC }, |
Simon Kelley | 66f6265 | 2020-01-05 16:21:24 +0000 | [diff] [blame] | 273 | { "tftp-single-port", 0, 0, LOPT_SINGLE_PORT }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 274 | { "ptr-record", 1, 0, LOPT_PTR }, |
| 275 | { "naptr-record", 1, 0, LOPT_NAPTR }, |
| 276 | { "bridge-interface", 1, 0 , LOPT_BRIDGE }, |
Simon Kelley | ae5b7e0 | 2019-03-27 22:33:28 +0000 | [diff] [blame] | 277 | { "shared-network", 1, 0, LOPT_SHARED_NET }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 278 | { "dhcp-option-force", 1, 0, LOPT_FORCE }, |
| 279 | { "tftp-no-blocksize", 0, 0, LOPT_NOBLOCK }, |
| 280 | { "log-dhcp", 0, 0, LOPT_LOG_OPTS }, |
| 281 | { "log-async", 2, 0, LOPT_MAX_LOGS }, |
| 282 | { "dhcp-circuitid", 1, 0, LOPT_CIRCUIT }, |
| 283 | { "dhcp-remoteid", 1, 0, LOPT_REMOTE }, |
| 284 | { "dhcp-subscrid", 1, 0, LOPT_SUBSCR }, |
Wang Shanker | 4ded962 | 2020-12-04 10:17:35 +0800 | [diff] [blame] | 285 | { "dhcp-pxe-vendor", 1, 0, LOPT_PXE_VENDOR }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 286 | { "interface-name", 1, 0, LOPT_INTNAME }, |
| 287 | { "dhcp-hostsfile", 1, 0, LOPT_DHCP_HOST }, |
| 288 | { "dhcp-optsfile", 1, 0, LOPT_DHCP_OPTS }, |
Simon Kelley | 5f4dc5c | 2015-01-20 20:51:02 +0000 | [diff] [blame] | 289 | { "dhcp-hostsdir", 1, 0, LOPT_DHCP_INOTIFY }, |
Simon Kelley | 70d1873 | 2015-01-31 19:59:29 +0000 | [diff] [blame] | 290 | { "dhcp-optsdir", 1, 0, LOPT_DHOPT_INOTIFY }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 291 | { "dhcp-no-override", 0, 0, LOPT_OVERRIDE }, |
| 292 | { "tftp-port-range", 1, 0, LOPT_TFTPPORTS }, |
| 293 | { "stop-dns-rebind", 0, 0, LOPT_REBIND }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 294 | { "rebind-domain-ok", 1, 0, LOPT_NO_REBIND }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 295 | { "all-servers", 0, 0, LOPT_NOLAST }, |
Simon Kelley | c822620 | 2018-08-08 23:46:03 +0100 | [diff] [blame] | 296 | { "dhcp-match", 1, 0, LOPT_MATCH }, |
| 297 | { "dhcp-name-match", 1, 0, LOPT_NAME_MATCH }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 298 | { "dhcp-broadcast", 2, 0, LOPT_BROADCAST }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 299 | { "neg-ttl", 1, 0, LOPT_NEGTTL }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 300 | { "max-ttl", 1, 0, LOPT_MAXTTL }, |
RinSatsuki | 28de387 | 2015-01-10 15:22:21 +0000 | [diff] [blame] | 301 | { "min-cache-ttl", 1, 0, LOPT_MINCTTL }, |
Simon Kelley | 1d86041 | 2012-09-20 20:48:04 +0100 | [diff] [blame] | 302 | { "max-cache-ttl", 1, 0, LOPT_MAXCTTL }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 303 | { "dhcp-alternate-port", 2, 0, LOPT_ALTPORT }, |
| 304 | { "dhcp-scriptuser", 1, 0, LOPT_SCRIPTUSR }, |
| 305 | { "min-port", 1, 0, LOPT_MINPORT }, |
Hans Dedecker | 926332a | 2016-01-23 10:48:12 +0000 | [diff] [blame] | 306 | { "max-port", 1, 0, LOPT_MAXPORT }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 307 | { "dhcp-fqdn", 0, 0, LOPT_DHCP_FQDN }, |
| 308 | { "cname", 1, 0, LOPT_CNAME }, |
| 309 | { "pxe-prompt", 1, 0, LOPT_PXE_PROMT }, |
| 310 | { "pxe-service", 1, 0, LOPT_PXE_SERV }, |
| 311 | { "test", 0, 0, LOPT_TEST }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 312 | { "tag-if", 1, 0, LOPT_TAG_IF }, |
| 313 | { "dhcp-proxy", 2, 0, LOPT_PROXY }, |
| 314 | { "dhcp-generate-names", 2, 0, LOPT_GEN_NAMES }, |
| 315 | { "rebind-localhost-ok", 0, 0, LOPT_LOC_REBND }, |
Simon Kelley | 1e50512 | 2016-01-25 21:29:23 +0000 | [diff] [blame] | 316 | { "add-mac", 2, 0, LOPT_ADD_MAC }, |
Simon Kelley | ed4c076 | 2013-10-08 20:46:34 +0100 | [diff] [blame] | 317 | { "add-subnet", 2, 0, LOPT_ADD_SBNET }, |
Simon Kelley | 1e50512 | 2016-01-25 21:29:23 +0000 | [diff] [blame] | 318 | { "add-cpe-id", 1, 0 , LOPT_CPE_ID }, |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 319 | { "proxy-dnssec", 0, 0, LOPT_DNSSEC }, |
Simon Kelley | 7de060b | 2011-08-26 17:24:52 +0100 | [diff] [blame] | 320 | { "dhcp-sequential-ip", 0, 0, LOPT_INCR_ADDR }, |
| 321 | { "conntrack", 0, 0, LOPT_CONNTRACK }, |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 322 | { "dhcp-client-update", 0, 0, LOPT_FQDN }, |
| 323 | { "dhcp-luascript", 1, 0, LOPT_LUASCRIPT }, |
Simon Kelley | c5ad4e7 | 2012-02-24 16:06:20 +0000 | [diff] [blame] | 324 | { "enable-ra", 0, 0, LOPT_RA }, |
Simon Kelley | 8b37270 | 2012-03-09 17:45:10 +0000 | [diff] [blame] | 325 | { "dhcp-duid", 1, 0, LOPT_DUID }, |
Simon Kelley | e759d42 | 2012-03-16 13:18:57 +0000 | [diff] [blame] | 326 | { "host-record", 1, 0, LOPT_HOST_REC }, |
Simon Kelley | 54dd393 | 2012-06-20 11:23:38 +0100 | [diff] [blame] | 327 | { "bind-dynamic", 0, 0, LOPT_CLVERBIND }, |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 328 | { "auth-zone", 1, 0, LOPT_AUTHZONE }, |
| 329 | { "auth-server", 1, 0, LOPT_AUTHSERV }, |
| 330 | { "auth-ttl", 1, 0, LOPT_AUTHTTL }, |
| 331 | { "auth-soa", 1, 0, LOPT_AUTHSOA }, |
Simon Kelley | e1ff419 | 2012-12-09 17:08:47 +0000 | [diff] [blame] | 332 | { "auth-sec-servers", 1, 0, LOPT_AUTHSFS }, |
Simon Kelley | 4967876 | 2012-12-09 18:24:58 +0000 | [diff] [blame] | 333 | { "auth-peer", 1, 0, LOPT_AUTHPEER }, |
Jason A. Donenfeld | 13d86c7 | 2013-02-22 18:20:53 +0000 | [diff] [blame] | 334 | { "ipset", 1, 0, LOPT_IPSET }, |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 335 | { "synth-domain", 1, 0, LOPT_SYNTH }, |
Giovanni Bajo | 7dbe193 | 2012-04-05 02:50:13 +0200 | [diff] [blame] | 336 | { "dnssec", 0, 0, LOPT_SEC_VALID }, |
Simon Kelley | ee41586 | 2014-02-11 11:07:22 +0000 | [diff] [blame] | 337 | { "trust-anchor", 1, 0, LOPT_TRUST_ANCHOR }, |
Simon Kelley | 5b3bf92 | 2014-01-25 17:03:07 +0000 | [diff] [blame] | 338 | { "dnssec-debug", 0, 0, LOPT_DNSSEC_DEBUG }, |
Simon Kelley | a691853 | 2018-04-15 16:20:52 +0100 | [diff] [blame] | 339 | { "dnssec-check-unsigned", 2, 0, LOPT_DNSSEC_CHECK }, |
Simon Kelley | e98bd52 | 2014-03-28 20:41:23 +0000 | [diff] [blame] | 340 | { "dnssec-no-timecheck", 0, 0, LOPT_DNSSEC_TIME }, |
Simon Kelley | f6e62e2 | 2015-03-01 18:17:54 +0000 | [diff] [blame] | 341 | { "dnssec-timestamp", 1, 0, LOPT_DNSSEC_STAMP }, |
Simon Kelley | ff7eea2 | 2013-09-04 18:01:38 +0100 | [diff] [blame] | 342 | { "dhcp-relay", 1, 0, LOPT_RELAY }, |
Simon Kelley | c4cd95d | 2013-10-10 20:58:11 +0100 | [diff] [blame] | 343 | { "ra-param", 1, 0, LOPT_RA_PARAM }, |
Kevin Darbyshire-Bryant | 8c0b73d | 2013-10-11 11:56:33 +0100 | [diff] [blame] | 344 | { "quiet-dhcp", 0, 0, LOPT_QUIET_DHCP }, |
| 345 | { "quiet-dhcp6", 0, 0, LOPT_QUIET_DHCP6 }, |
| 346 | { "quiet-ra", 0, 0, LOPT_QUIET_RA }, |
Simon Kelley | b5ea1cc | 2014-07-29 16:34:14 +0100 | [diff] [blame] | 347 | { "dns-loop-detect", 0, 0, LOPT_LOOP_DETECT }, |
Simon Kelley | 1e50512 | 2016-01-25 21:29:23 +0000 | [diff] [blame] | 348 | { "script-arp", 0, 0, LOPT_SCRIPT_ARP }, |
Simon Kelley | 832e47b | 2016-02-24 21:24:45 +0000 | [diff] [blame] | 349 | { "dhcp-ttl", 1, 0 , LOPT_DHCPTTL }, |
Floris Bos | 503c609 | 2017-04-09 23:07:13 +0100 | [diff] [blame] | 350 | { "dhcp-reply-delay", 1, 0, LOPT_REPLY_DELAY }, |
Simon Kelley | 734d531 | 2018-03-23 23:09:53 +0000 | [diff] [blame] | 351 | { "dhcp-rapid-commit", 0, 0, LOPT_RAPID_COMMIT }, |
Simon Kelley | 6b17335 | 2018-05-08 18:32:14 +0100 | [diff] [blame] | 352 | { "dumpfile", 1, 0, LOPT_DUMPFILE }, |
| 353 | { "dumpmask", 1, 0, LOPT_DUMPMASK }, |
Florent Fourcot | 13a58f9 | 2019-06-20 10:26:40 +0200 | [diff] [blame] | 354 | { "dhcp-ignore-clid", 0, 0, LOPT_IGNORE_CLID }, |
Simon Kelley | b7cf754 | 2021-03-04 16:54:14 +0000 | [diff] [blame] | 355 | { "dynamic-host", 1, 0, LOPT_DYNHOST }, |
Simon Kelley | b260d22 | 2021-03-12 21:57:57 +0000 | [diff] [blame] | 356 | { "log-debug", 0, 0, LOPT_LOG_DEBUG }, |
Kyle Swenson | 545712c | 2021-11-17 12:25:04 -0700 | [diff] [blame] | 357 | /* CRADLEPOINT */ |
| 358 | { "edns-option", 1, 0, LOPT_EDNS_OPTION }, |
| 359 | { "ssid-map", 1, 0, LOPT_SSID_MAP }, |
Kyle Swenson | ba77fe8 | 2021-11-19 09:33:46 -0700 | [diff] [blame] | 360 | { "edns-restrict", 0, 0, LOPT_EDNS_RESTRICT }, |
Tarun Kundu | 024baf1 | 2022-06-28 10:56:47 -0700 | [diff] [blame] | 361 | { "ra-adv-disable", 1, 0, LOPT_RA_ADV_DISABLE }, |
| 362 | /* CRADLEPOINT */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 363 | { NULL, 0, 0, 0 } |
| 364 | }; |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 365 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 366 | |
| 367 | #define ARG_DUP OPT_LAST |
| 368 | #define ARG_ONE OPT_LAST + 1 |
| 369 | #define ARG_USED_CL OPT_LAST + 2 |
| 370 | #define ARG_USED_FILE OPT_LAST + 3 |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 371 | |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 372 | static struct { |
| 373 | int opt; |
| 374 | unsigned int rept; |
| 375 | char * const flagdesc; |
Simon Kelley | b8187c8 | 2005-11-26 21:46:27 +0000 | [diff] [blame] | 376 | char * const desc; |
| 377 | char * const arg; |
| 378 | } usage[] = { |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 379 | { 'a', ARG_DUP, "<ipaddr>", gettext_noop("Specify local address(es) to listen on."), NULL }, |
| 380 | { '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] | 381 | { '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] | 382 | { 'B', ARG_DUP, "<ipaddr>", gettext_noop("Treat ipaddr as NXDOMAIN (defeats Verisign wildcard)."), NULL }, |
| 383 | { 'c', ARG_ONE, "<integer>", gettext_noop("Specify the size of the cache in entries (defaults to %s)."), "$" }, |
| 384 | { '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] | 385 | { 'd', OPT_DEBUG, NULL, gettext_noop("Do NOT fork into the background: run in debug mode."), NULL }, |
| 386 | { 'D', OPT_NODOTS_LOCAL, NULL, gettext_noop("Do NOT forward queries with no domain part."), NULL }, |
| 387 | { 'e', OPT_SELFMX, NULL, gettext_noop("Return self-pointing MX records for local hosts."), NULL }, |
| 388 | { 'E', OPT_EXPAND, NULL, gettext_noop("Expand simple names in /etc/hosts with domain-suffix."), NULL }, |
| 389 | { '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] | 390 | { 'F', ARG_DUP, "<ipaddr>,...", gettext_noop("Enable DHCP in the range given with lease duration."), NULL }, |
| 391 | { '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] | 392 | { '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] | 393 | { LOPT_DHCP_HOST, ARG_DUP, "<path>", gettext_noop("Read DHCP host specs from file."), NULL }, |
| 394 | { 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] | 395 | { 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] | 396 | { 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] | 397 | { 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] | 398 | { '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] | 399 | { '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] | 400 | { 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] | 401 | { 'i', ARG_DUP, "<interface>", gettext_noop("Specify interface(s) to listen on."), NULL }, |
| 402 | { '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] | 403 | { 'j', ARG_DUP, "set:<tag>,<class>", gettext_noop("Map DHCP user class to tag."), NULL }, |
| 404 | { LOPT_CIRCUIT, ARG_DUP, "set:<tag>,<circuit>", gettext_noop("Map RFC3046 circuit-id to tag."), NULL }, |
| 405 | { LOPT_REMOTE, ARG_DUP, "set:<tag>,<remote>", gettext_noop("Map RFC3046 remote-id to tag."), NULL }, |
| 406 | { 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] | 407 | { 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] | 408 | { 'J', ARG_DUP, "tag:<tag>...", gettext_noop("Don't do DHCP for hosts with tag set."), NULL }, |
| 409 | { 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] | 410 | { 'k', OPT_NO_FORK, NULL, gettext_noop("Do NOT fork into the background, do NOT run in debug mode."), NULL }, |
| 411 | { '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] | 412 | { '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] | 413 | { '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] | 414 | { '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] | 415 | { 'M', ARG_DUP, "<bootp opts>", gettext_noop("Specify BOOTP options to DHCP server."), NULL }, |
| 416 | { 'n', OPT_NO_POLL, NULL, gettext_noop("Do NOT poll %s file, reload only on SIGHUP."), RESOLVFILE }, |
| 417 | { 'N', OPT_NO_NEG, NULL, gettext_noop("Do NOT cache failed search results."), NULL }, |
| 418 | { 'o', OPT_ORDER, NULL, gettext_noop("Use nameservers strictly in the order given in %s."), RESOLVFILE }, |
| 419 | { 'O', ARG_DUP, "<optspec>", gettext_noop("Specify options to be sent to DHCP clients."), NULL }, |
| 420 | { 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] | 421 | { 'p', ARG_ONE, "<integer>", gettext_noop("Specify port to listen for DNS requests on (defaults to 53)."), NULL }, |
| 422 | { '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] | 423 | { 'q', ARG_DUP, NULL, gettext_noop("Log DNS queries."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 424 | { '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] | 425 | { '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] | 426 | { '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] | 427 | { 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] | 428 | { '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] | 429 | { 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] | 430 | { 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] | 431 | { '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] | 432 | { 't', ARG_ONE, "<host_name>", gettext_noop("Specify default target in an MX record."), NULL }, |
| 433 | { 'T', ARG_ONE, "<integer>", gettext_noop("Specify time-to-live in seconds for replies from /etc/hosts."), NULL }, |
| 434 | { LOPT_NEGTTL, ARG_ONE, "<integer>", gettext_noop("Specify time-to-live in seconds for negative caching."), NULL }, |
| 435 | { 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] | 436 | { LOPT_MAXCTTL, ARG_ONE, "<integer>", gettext_noop("Specify time-to-live ceiling for cache."), NULL }, |
| 437 | { 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] | 438 | { '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] | 439 | { '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] | 440 | { 'v', 0, NULL, gettext_noop("Display dnsmasq version and copyright information."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 441 | { 'V', ARG_DUP, "<ipaddr>,<ipaddr>,<netmask>", gettext_noop("Translate IPv4 addresses from upstream servers."), NULL }, |
| 442 | { 'W', ARG_DUP, "<name>,<target>,...", gettext_noop("Specify a SRV record."), NULL }, |
Simon Kelley | 09217a1 | 2016-05-03 17:04:35 +0100 | [diff] [blame] | 443 | { '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] | 444 | { 'x', ARG_ONE, "<path>", gettext_noop("Specify path of PID file (defaults to %s)."), RUNFILE }, |
| 445 | { '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] | 446 | { '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] | 447 | { 'Y', ARG_DUP, "<name>,<txt>[,<txt]", gettext_noop("Specify TXT DNS record."), NULL }, |
| 448 | { LOPT_PTR, ARG_DUP, "<name>,<target>", gettext_noop("Specify PTR DNS record."), NULL }, |
| 449 | { 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] | 450 | { 'z', OPT_NOWILD, NULL, gettext_noop("Bind only to interfaces in use."), NULL }, |
| 451 | { '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] | 452 | { '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] | 453 | { LOPT_UBUS, ARG_ONE, "[=<busname>]", gettext_noop("Enable the UBus interface."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 454 | { '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] | 455 | { '3', ARG_DUP, "[=tag:<tag>]...", gettext_noop("Enable dynamic address allocation for bootp."), NULL }, |
| 456 | { '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] | 457 | { 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] | 458 | { 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] | 459 | { '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] | 460 | { '6', ARG_ONE, "<path>", gettext_noop("Shell script to run on DHCP lease creation and destruction."), NULL }, |
| 461 | { LOPT_LUASCRIPT, ARG_DUP, "path", gettext_noop("Lua script to run on DHCP lease creation and destruction."), NULL }, |
| 462 | { 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] | 463 | { 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] | 464 | { '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] | 465 | { '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] | 466 | { '9', OPT_LEASE_RO, NULL, gettext_noop("Do not use leasefile."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 467 | { '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] | 468 | { 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] | 469 | { 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] | 470 | { 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] | 471 | { 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] | 472 | { 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] | 473 | { 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] | 474 | { 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] | 475 | { 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] | 476 | { 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] | 477 | { 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] | 478 | { 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] | 479 | { 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] | 480 | { 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] | 481 | { 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] | 482 | { 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] | 483 | { 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] | 484 | { 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] | 485 | { 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] | 486 | { 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] | 487 | { 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] | 488 | { 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] | 489 | { 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] | 490 | { 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] | 491 | { LOPT_NAPTR, ARG_DUP, "<name>,<naptr>", gettext_noop("Specify NAPTR DNS record."), NULL }, |
| 492 | { 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] | 493 | { 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] | 494 | { 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] | 495 | { LOPT_GEN_NAMES, ARG_DUP, "[=tag:<tag>]", gettext_noop("Generate hostnames based on MAC address for nameless clients."), NULL}, |
| 496 | { 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] | 497 | { 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] | 498 | { 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] | 499 | { LOPT_PXE_PROMT, ARG_DUP, "<prompt>,[<timeout>]", gettext_noop("Prompt to send to PXE clients."), NULL }, |
| 500 | { LOPT_PXE_SERV, ARG_DUP, "<service>", gettext_noop("Boot service for PXE menu."), NULL }, |
| 501 | { LOPT_TEST, 0, NULL, gettext_noop("Check configuration syntax."), NULL }, |
Simon Kelley | 22c0f4f | 2016-02-17 22:12:31 +0000 | [diff] [blame] | 502 | { 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] | 503 | { 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] | 504 | { 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] | 505 | { 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] | 506 | { 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] | 507 | { 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] | 508 | { 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] | 509 | { 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] | 510 | { 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] | 511 | { 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] | 512 | { 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] | 513 | { 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] | 514 | { 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] | 515 | { 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] | 516 | { 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] | 517 | { 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] | 518 | { 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] | 519 | { 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] | 520 | { LOPT_AUTHSOA, ARG_ONE, "<serial>[,...]", gettext_noop("Set authoritative zone information"), NULL }, |
Simon Kelley | 4967876 | 2012-12-09 18:24:58 +0000 | [diff] [blame] | 521 | { LOPT_AUTHSFS, ARG_DUP, "<NS>[,<NS>...]", gettext_noop("Secondary authoritative nameservers for forward domains"), NULL }, |
| 522 | { 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] | 523 | { 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] | 524 | { 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] | 525 | { 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] | 526 | { 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] | 527 | { 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] | 528 | { 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] | 529 | { 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] | 530 | { LOPT_DNSSEC_STAMP, ARG_ONE, "<path>", gettext_noop("Timestamp file to verify system clock for DNSSEC"), NULL }, |
Tarun Kundu | 41aa488 | 2022-07-05 10:44:13 -0700 | [diff] [blame] | 531 | { LOPT_RA_PARAM, ARG_DUP, "<iface>,[mtu:<value>|<interface>|off,][<prio>,]<intval>[,<lifetime>][,<reachable_time>][,<hop_limit>][,<retrans_time>]", gettext_noop("Set MTU, priority, resend-interval, router-lifetime, reachable_time, hop_limit and retrans_time"), NULL }, |
Kevin Darbyshire-Bryant | 8c0b73d | 2013-10-11 11:56:33 +0100 | [diff] [blame] | 532 | { LOPT_QUIET_DHCP, OPT_QUIET_DHCP, NULL, gettext_noop("Do not log routine DHCP."), NULL }, |
| 533 | { LOPT_QUIET_DHCP6, OPT_QUIET_DHCP6, NULL, gettext_noop("Do not log routine DHCPv6."), NULL }, |
| 534 | { 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] | 535 | { 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] | 536 | { LOPT_LOCAL_SERVICE, OPT_LOCAL_SERVICE, NULL, gettext_noop("Accept queries only from directly-connected networks."), NULL }, |
| 537 | { 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] | 538 | { 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] | 539 | { 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] | 540 | { 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] | 541 | { 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] | 542 | { LOPT_DUMPFILE, ARG_ONE, "<path>", gettext_noop("Path to debug packet dump file"), NULL }, |
| 543 | { 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] | 544 | { LOPT_SCRIPT_TIME, OPT_LEASE_RENEW, NULL, gettext_noop("Call dhcp-script when lease expiry changes."), NULL }, |
Tarun Kundu | 024baf1 | 2022-06-28 10:56:47 -0700 | [diff] [blame] | 545 | { LOPT_RA_ADV_DISABLE, ARG_DUP, "<interface>", gettext_noop("Specify interface(s) to disable RA. This parameter should be subset of interfaces and should be provided after interfaces option"), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 546 | { 0, 0, NULL, NULL, NULL } |
Simon Kelley | b8187c8 | 2005-11-26 21:46:27 +0000 | [diff] [blame] | 547 | }; |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 548 | |
Josh Soref | 730c674 | 2017-02-06 16:14:04 +0000 | [diff] [blame] | 549 | /* 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] | 550 | 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] | 551 | following sequence so that they map to themselves: it is therefore possible to call |
| 552 | unhide_metas repeatedly on string without breaking things. |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 553 | 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] | 554 | couple of other places. |
| 555 | Note that space is included here so that |
| 556 | --dhcp-option=3, string |
| 557 | has five characters, whilst |
| 558 | --dhcp-option=3," string" |
| 559 | has six. |
| 560 | */ |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 561 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 562 | static const char meta[] = "\000123456 \b\t\n78\r90abcdefABCDE\033F:,."; |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 563 | |
| 564 | static char hide_meta(char c) |
| 565 | { |
| 566 | unsigned int i; |
| 567 | |
| 568 | for (i = 0; i < (sizeof(meta) - 1); i++) |
| 569 | if (c == meta[i]) |
| 570 | return (char)i; |
| 571 | |
| 572 | return c; |
| 573 | } |
| 574 | |
| 575 | static char unhide_meta(char cr) |
| 576 | { |
| 577 | unsigned int c = cr; |
| 578 | |
| 579 | if (c < (sizeof(meta) - 1)) |
| 580 | cr = meta[c]; |
| 581 | |
| 582 | return cr; |
| 583 | } |
| 584 | |
| 585 | static void unhide_metas(char *cp) |
| 586 | { |
| 587 | if (cp) |
| 588 | for(; *cp; cp++) |
| 589 | *cp = unhide_meta(*cp); |
| 590 | } |
| 591 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 592 | static void *opt_malloc(size_t size) |
| 593 | { |
| 594 | void *ret; |
| 595 | |
| 596 | if (mem_recover) |
| 597 | { |
| 598 | ret = whine_malloc(size); |
| 599 | if (!ret) |
| 600 | longjmp(mem_jmp, 1); |
| 601 | } |
| 602 | else |
| 603 | ret = safe_malloc(size); |
| 604 | |
| 605 | return ret; |
| 606 | } |
| 607 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 608 | static char *opt_string_alloc(const char *cp) |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 609 | { |
| 610 | char *ret = NULL; |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 611 | size_t len; |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 612 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 613 | if (cp && (len = strlen(cp)) != 0) |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 614 | { |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 615 | ret = opt_malloc(len+1); |
| 616 | memcpy(ret, cp, len+1); |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 617 | |
| 618 | /* restore hidden metachars */ |
| 619 | unhide_metas(ret); |
| 620 | } |
| 621 | |
| 622 | return ret; |
| 623 | } |
| 624 | |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 625 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 626 | /* find next comma, split string with zero and eliminate spaces. |
| 627 | return start of string following comma */ |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 628 | |
| 629 | static char *split_chr(char *s, char c) |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 630 | { |
| 631 | char *comma, *p; |
| 632 | |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 633 | if (!s || !(comma = strchr(s, c))) |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 634 | return NULL; |
| 635 | |
| 636 | p = comma; |
| 637 | *comma = ' '; |
| 638 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 639 | for (; *comma == ' '; comma++); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 640 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 641 | for (; (p >= s) && *p == ' '; p--) |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 642 | *p = 0; |
| 643 | |
| 644 | return comma; |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 645 | } |
| 646 | |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 647 | static char *split(char *s) |
| 648 | { |
| 649 | return split_chr(s, ','); |
| 650 | } |
| 651 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 652 | static char *canonicalise_opt(char *s) |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 653 | { |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 654 | char *ret; |
| 655 | int nomem; |
| 656 | |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 657 | if (!s) |
| 658 | return 0; |
| 659 | |
| 660 | unhide_metas(s); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 661 | if (!(ret = canonicalise(s, &nomem)) && nomem) |
| 662 | { |
| 663 | if (mem_recover) |
| 664 | longjmp(mem_jmp, 1); |
| 665 | else |
| 666 | die(_("could not get memory"), NULL, EC_NOMEM); |
| 667 | } |
| 668 | |
| 669 | return ret; |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | static int atoi_check(char *a, int *res) |
| 673 | { |
| 674 | char *p; |
| 675 | |
| 676 | if (!a) |
| 677 | return 0; |
| 678 | |
| 679 | unhide_metas(a); |
| 680 | |
| 681 | for (p = a; *p; p++) |
| 682 | if (*p < '0' || *p > '9') |
| 683 | return 0; |
| 684 | |
| 685 | *res = atoi(a); |
| 686 | return 1; |
| 687 | } |
| 688 | |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 689 | static int atoi_check16(char *a, int *res) |
| 690 | { |
| 691 | if (!(atoi_check(a, res)) || |
| 692 | *res < 0 || |
| 693 | *res > 0xffff) |
| 694 | return 0; |
| 695 | |
| 696 | return 1; |
| 697 | } |
Simon Kelley | ee41586 | 2014-02-11 11:07:22 +0000 | [diff] [blame] | 698 | |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 699 | #ifdef HAVE_DNSSEC |
Simon Kelley | ee41586 | 2014-02-11 11:07:22 +0000 | [diff] [blame] | 700 | static int atoi_check8(char *a, int *res) |
| 701 | { |
| 702 | if (!(atoi_check(a, res)) || |
| 703 | *res < 0 || |
| 704 | *res > 0xff) |
| 705 | return 0; |
| 706 | |
| 707 | return 1; |
| 708 | } |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 709 | #endif |
Kevin Darbyshire-Bryant | 7ac9ae1 | 2016-09-09 20:52:08 +0100 | [diff] [blame] | 710 | |
| 711 | #ifndef NO_ID |
Simon Kelley | fec216d | 2014-03-27 20:54:34 +0000 | [diff] [blame] | 712 | static void add_txt(char *name, char *txt, int stat) |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 713 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 714 | struct txt_record *r = opt_malloc(sizeof(struct txt_record)); |
Simon Kelley | fec216d | 2014-03-27 20:54:34 +0000 | [diff] [blame] | 715 | |
| 716 | if (txt) |
| 717 | { |
| 718 | size_t len = strlen(txt); |
| 719 | r->txt = opt_malloc(len+1); |
| 720 | r->len = len+1; |
| 721 | *(r->txt) = len; |
| 722 | memcpy((r->txt)+1, txt, len); |
| 723 | } |
Kevin Darbyshire-Bryant | 7ac9ae1 | 2016-09-09 20:52:08 +0100 | [diff] [blame] | 724 | |
Simon Kelley | fec216d | 2014-03-27 20:54:34 +0000 | [diff] [blame] | 725 | r->stat = stat; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 726 | r->name = opt_string_alloc(name); |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 727 | r->next = daemon->txt; |
| 728 | daemon->txt = r; |
| 729 | r->class = C_CHAOS; |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 730 | } |
Kevin Darbyshire-Bryant | 7ac9ae1 | 2016-09-09 20:52:08 +0100 | [diff] [blame] | 731 | #endif |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 732 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 733 | static void do_usage(void) |
| 734 | { |
| 735 | char buff[100]; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 736 | int i, j; |
| 737 | |
| 738 | struct { |
| 739 | char handle; |
| 740 | int val; |
| 741 | } tab[] = { |
| 742 | { '$', CACHESIZ }, |
| 743 | { '*', EDNS_PKTSZ }, |
| 744 | { '&', MAXLEASES }, |
| 745 | { '!', FTABSIZ }, |
| 746 | { '#', TFTP_MAX_CONNECTIONS }, |
| 747 | { '\0', 0 } |
| 748 | }; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 749 | |
| 750 | printf(_("Usage: dnsmasq [options]\n\n")); |
| 751 | #ifndef HAVE_GETOPT_LONG |
| 752 | printf(_("Use short options only on the command line.\n")); |
| 753 | #endif |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 754 | printf(_("Valid options are:\n")); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 755 | |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 756 | for (i = 0; usage[i].opt != 0; i++) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 757 | { |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 758 | char *desc = usage[i].flagdesc; |
| 759 | char *eq = "="; |
| 760 | |
| 761 | if (!desc || *desc == '[') |
| 762 | eq = ""; |
| 763 | |
| 764 | if (!desc) |
| 765 | desc = ""; |
| 766 | |
| 767 | for ( j = 0; opts[j].name; j++) |
| 768 | if (opts[j].val == usage[i].opt) |
| 769 | break; |
| 770 | if (usage[i].opt < 256) |
| 771 | sprintf(buff, "-%c, ", usage[i].opt); |
| 772 | else |
| 773 | sprintf(buff, " "); |
| 774 | |
| 775 | sprintf(buff+4, "--%s%s%s", opts[j].name, eq, desc); |
Peter Wu | 3c0c111 | 2016-08-28 20:53:09 +0100 | [diff] [blame] | 776 | printf("%-55.55s", buff); |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 777 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 778 | if (usage[i].arg) |
| 779 | { |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 780 | strcpy(buff, usage[i].arg); |
| 781 | for (j = 0; tab[j].handle; j++) |
| 782 | if (tab[j].handle == *(usage[i].arg)) |
| 783 | sprintf(buff, "%d", tab[j].val); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 784 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 785 | printf(_(usage[i].desc), buff); |
| 786 | printf("\n"); |
| 787 | } |
| 788 | } |
| 789 | |
Simon Kelley | c740e4f | 2012-08-09 16:19:01 +0100 | [diff] [blame] | 790 | #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] | 791 | #define ret_err_free(x,m) do { strcpy(errstr, (x)); free((m)); return 0; } while (0) |
| 792 | #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] | 793 | |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 794 | static char *parse_mysockaddr(char *arg, union mysockaddr *addr) |
| 795 | { |
| 796 | if (inet_pton(AF_INET, arg, &addr->in.sin_addr) > 0) |
| 797 | addr->sa.sa_family = AF_INET; |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 798 | else if (inet_pton(AF_INET6, arg, &addr->in6.sin6_addr) > 0) |
| 799 | addr->sa.sa_family = AF_INET6; |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 800 | else |
| 801 | return _("bad address"); |
| 802 | |
| 803 | return NULL; |
| 804 | } |
| 805 | |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 806 | char *parse_server(char *arg, union mysockaddr *addr, union mysockaddr *source_addr, char *interface, int *flags) |
| 807 | { |
| 808 | int source_port = 0, serv_port = NAMESERVER_PORT; |
| 809 | char *portno, *source; |
Kristian Evensen | 4e7694d | 2017-03-22 21:32:50 +0000 | [diff] [blame] | 810 | char *interface_opt = NULL; |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 811 | int scope_index = 0; |
| 812 | char *scope_id; |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 813 | |
Simon Kelley | d68c2ca | 2014-02-18 22:30:30 +0000 | [diff] [blame] | 814 | if (!arg || strlen(arg) == 0) |
| 815 | { |
| 816 | *flags |= SERV_NO_ADDR; |
| 817 | *interface = 0; |
| 818 | return NULL; |
| 819 | } |
| 820 | |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 821 | if ((source = split_chr(arg, '@')) && /* is there a source. */ |
| 822 | (portno = split_chr(source, '#')) && |
| 823 | !atoi_check16(portno, &source_port)) |
| 824 | return _("bad port"); |
| 825 | |
| 826 | if ((portno = split_chr(arg, '#')) && /* is there a port no. */ |
| 827 | !atoi_check16(portno, &serv_port)) |
| 828 | return _("bad port"); |
| 829 | |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 830 | scope_id = split_chr(arg, '%'); |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 831 | |
Kristian Evensen | 4e7694d | 2017-03-22 21:32:50 +0000 | [diff] [blame] | 832 | if (source) { |
| 833 | interface_opt = split_chr(source, '@'); |
| 834 | |
| 835 | if (interface_opt) |
| 836 | { |
| 837 | #if defined(SO_BINDTODEVICE) |
Simon Kelley | 74d4fcd | 2021-03-15 21:59:51 +0000 | [diff] [blame] | 838 | safe_strncpy(interface, source, IF_NAMESIZE); |
| 839 | source = interface_opt; |
Kristian Evensen | 4e7694d | 2017-03-22 21:32:50 +0000 | [diff] [blame] | 840 | #else |
| 841 | return _("interface binding not supported"); |
| 842 | #endif |
| 843 | } |
| 844 | } |
| 845 | |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 846 | if (inet_pton(AF_INET, arg, &addr->in.sin_addr) > 0) |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 847 | { |
| 848 | addr->in.sin_port = htons(serv_port); |
| 849 | addr->sa.sa_family = source_addr->sa.sa_family = AF_INET; |
| 850 | #ifdef HAVE_SOCKADDR_SA_LEN |
| 851 | source_addr->in.sin_len = addr->in.sin_len = sizeof(struct sockaddr_in); |
| 852 | #endif |
| 853 | source_addr->in.sin_addr.s_addr = INADDR_ANY; |
| 854 | source_addr->in.sin_port = htons(daemon->query_port); |
| 855 | |
| 856 | if (source) |
| 857 | { |
| 858 | if (flags) |
| 859 | *flags |= SERV_HAS_SOURCE; |
| 860 | source_addr->in.sin_port = htons(source_port); |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 861 | if (!(inet_pton(AF_INET, source, &source_addr->in.sin_addr) > 0)) |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 862 | { |
| 863 | #if defined(SO_BINDTODEVICE) |
Kristian Evensen | 4e7694d | 2017-03-22 21:32:50 +0000 | [diff] [blame] | 864 | if (interface_opt) |
| 865 | return _("interface can only be specified once"); |
| 866 | |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 867 | source_addr->in.sin_addr.s_addr = INADDR_ANY; |
Petr Menšík | 47b45b2 | 2018-08-15 18:17:00 +0200 | [diff] [blame] | 868 | safe_strncpy(interface, source, IF_NAMESIZE); |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 869 | #else |
| 870 | return _("interface binding not supported"); |
| 871 | #endif |
| 872 | } |
| 873 | } |
| 874 | } |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 875 | else if (inet_pton(AF_INET6, arg, &addr->in6.sin6_addr) > 0) |
| 876 | { |
| 877 | if (scope_id && (scope_index = if_nametoindex(scope_id)) == 0) |
| 878 | return _("bad interface name"); |
| 879 | |
| 880 | addr->in6.sin6_port = htons(serv_port); |
| 881 | addr->in6.sin6_scope_id = scope_index; |
| 882 | source_addr->in6.sin6_addr = in6addr_any; |
| 883 | source_addr->in6.sin6_port = htons(daemon->query_port); |
| 884 | source_addr->in6.sin6_scope_id = 0; |
| 885 | addr->sa.sa_family = source_addr->sa.sa_family = AF_INET6; |
| 886 | addr->in6.sin6_flowinfo = source_addr->in6.sin6_flowinfo = 0; |
| 887 | #ifdef HAVE_SOCKADDR_SA_LEN |
| 888 | addr->in6.sin6_len = source_addr->in6.sin6_len = sizeof(addr->in6); |
| 889 | #endif |
| 890 | if (source) |
| 891 | { |
| 892 | if (flags) |
| 893 | *flags |= SERV_HAS_SOURCE; |
| 894 | source_addr->in6.sin6_port = htons(source_port); |
| 895 | if (inet_pton(AF_INET6, source, &source_addr->in6.sin6_addr) == 0) |
| 896 | { |
| 897 | #if defined(SO_BINDTODEVICE) |
Kristian Evensen | 4e7694d | 2017-03-22 21:32:50 +0000 | [diff] [blame] | 898 | if (interface_opt) |
| 899 | return _("interface can only be specified once"); |
| 900 | |
| 901 | source_addr->in6.sin6_addr = in6addr_any; |
Petr Menšík | 47b45b2 | 2018-08-15 18:17:00 +0200 | [diff] [blame] | 902 | safe_strncpy(interface, source, IF_NAMESIZE); |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 903 | #else |
| 904 | return _("interface binding not supported"); |
| 905 | #endif |
| 906 | } |
| 907 | } |
| 908 | } |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 909 | else |
| 910 | return _("bad address"); |
| 911 | |
| 912 | return NULL; |
| 913 | } |
| 914 | |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 915 | static struct server *add_rev4(struct in_addr addr, int msize) |
| 916 | { |
| 917 | struct server *serv = opt_malloc(sizeof(struct server)); |
Olivier Gayot | 916959c | 2017-03-06 22:14:50 +0000 | [diff] [blame] | 918 | in_addr_t a = ntohl(addr.s_addr); |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 919 | char *p; |
| 920 | |
| 921 | memset(serv, 0, sizeof(struct server)); |
Olivier Gayot | 916959c | 2017-03-06 22:14:50 +0000 | [diff] [blame] | 922 | p = serv->domain = opt_malloc(29); /* strlen("xxx.yyy.zzz.ttt.in-addr.arpa")+1 */ |
| 923 | |
| 924 | switch (msize) |
| 925 | { |
| 926 | case 32: |
Rosen Penev | cbd29e5 | 2017-06-27 22:29:51 +0100 | [diff] [blame] | 927 | p += sprintf(p, "%u.", a & 0xff); |
Olivier Gayot | 916959c | 2017-03-06 22:14:50 +0000 | [diff] [blame] | 928 | /* fall through */ |
| 929 | case 24: |
| 930 | p += sprintf(p, "%d.", (a >> 8) & 0xff); |
| 931 | /* fall through */ |
Olivier Gayot | 916959c | 2017-03-06 22:14:50 +0000 | [diff] [blame] | 932 | case 16: |
| 933 | p += sprintf(p, "%d.", (a >> 16) & 0xff); |
| 934 | /* fall through */ |
| 935 | case 8: |
| 936 | p += sprintf(p, "%d.", (a >> 24) & 0xff); |
| 937 | break; |
Olivier Gayot | dc99058 | 2017-03-06 22:17:21 +0000 | [diff] [blame] | 938 | default: |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 939 | free(serv->domain); |
| 940 | free(serv); |
Olivier Gayot | dc99058 | 2017-03-06 22:17:21 +0000 | [diff] [blame] | 941 | return NULL; |
Olivier Gayot | 916959c | 2017-03-06 22:14:50 +0000 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | p += sprintf(p, "in-addr.arpa"); |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 945 | |
| 946 | serv->flags = SERV_HAS_DOMAIN; |
| 947 | serv->next = daemon->servers; |
| 948 | daemon->servers = serv; |
| 949 | |
| 950 | return serv; |
| 951 | |
| 952 | } |
| 953 | |
| 954 | static struct server *add_rev6(struct in6_addr *addr, int msize) |
| 955 | { |
| 956 | struct server *serv = opt_malloc(sizeof(struct server)); |
| 957 | char *p; |
| 958 | int i; |
| 959 | |
| 960 | memset(serv, 0, sizeof(struct server)); |
| 961 | p = serv->domain = opt_malloc(73); /* strlen("32*<n.>ip6.arpa")+1 */ |
| 962 | |
| 963 | for (i = msize-1; i >= 0; i -= 4) |
| 964 | { |
| 965 | int dig = ((unsigned char *)addr)[i>>3]; |
| 966 | p += sprintf(p, "%.1x.", (i>>2) & 1 ? dig & 15 : dig >> 4); |
| 967 | } |
| 968 | p += sprintf(p, "ip6.arpa"); |
| 969 | |
| 970 | serv->flags = SERV_HAS_DOMAIN; |
| 971 | serv->next = daemon->servers; |
| 972 | daemon->servers = serv; |
| 973 | |
| 974 | return serv; |
| 975 | } |
| 976 | |
Simon Kelley | b5a8dd1 | 2012-12-10 11:37:25 +0000 | [diff] [blame] | 977 | #ifdef HAVE_DHCP |
| 978 | |
| 979 | static int is_tag_prefix(char *arg) |
| 980 | { |
| 981 | if (arg && (strstr(arg, "net:") == arg || strstr(arg, "tag:") == arg)) |
| 982 | return 1; |
| 983 | |
| 984 | return 0; |
| 985 | } |
| 986 | |
| 987 | static char *set_prefix(char *arg) |
| 988 | { |
| 989 | if (strstr(arg, "set:") == arg) |
| 990 | return arg+4; |
| 991 | |
| 992 | return arg; |
| 993 | } |
| 994 | |
Simon Kelley | 52ec783 | 2020-02-07 21:05:54 +0000 | [diff] [blame] | 995 | 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] | 996 | { |
| 997 | struct dhcp_netid *tt; |
| 998 | tt = opt_malloc(sizeof (struct dhcp_netid)); |
| 999 | tt->net = opt_string_alloc(net); |
| 1000 | tt->next = next; |
| 1001 | return tt; |
| 1002 | } |
| 1003 | |
| 1004 | static void dhcp_netid_free(struct dhcp_netid *nid) |
| 1005 | { |
| 1006 | while (nid) |
| 1007 | { |
| 1008 | struct dhcp_netid *tmp = nid; |
| 1009 | nid = nid->next; |
| 1010 | free(tmp->net); |
| 1011 | free(tmp); |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | /* Parse one or more tag:s before parameters. |
| 1016 | * Moves arg to the end of tags. */ |
| 1017 | static struct dhcp_netid * dhcp_tags(char **arg) |
| 1018 | { |
| 1019 | struct dhcp_netid *id = NULL; |
| 1020 | |
| 1021 | while (is_tag_prefix(*arg)) |
| 1022 | { |
| 1023 | char *comma = split(*arg); |
| 1024 | id = dhcp_netid_create((*arg)+4, id); |
| 1025 | *arg = comma; |
| 1026 | }; |
| 1027 | if (!*arg) |
| 1028 | { |
| 1029 | dhcp_netid_free(id); |
| 1030 | id = NULL; |
| 1031 | } |
| 1032 | return id; |
| 1033 | } |
| 1034 | |
| 1035 | static void dhcp_netid_list_free(struct dhcp_netid_list *netid) |
| 1036 | { |
| 1037 | while (netid) |
| 1038 | { |
| 1039 | struct dhcp_netid_list *tmplist = netid; |
| 1040 | netid = netid->next; |
| 1041 | dhcp_netid_free(tmplist->list); |
| 1042 | free(tmplist); |
| 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | static void dhcp_config_free(struct dhcp_config *config) |
| 1047 | { |
| 1048 | if (config) |
| 1049 | { |
| 1050 | struct hwaddr_config *hwaddr = config->hwaddr; |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 1051 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1052 | while (hwaddr) |
| 1053 | { |
| 1054 | struct hwaddr_config *tmp = hwaddr; |
| 1055 | hwaddr = hwaddr->next; |
| 1056 | free(tmp); |
| 1057 | } |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 1058 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1059 | dhcp_netid_list_free(config->netid); |
Simon Kelley | 52ec783 | 2020-02-07 21:05:54 +0000 | [diff] [blame] | 1060 | dhcp_netid_free(config->filter); |
| 1061 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1062 | if (config->flags & CONFIG_CLID) |
| 1063 | free(config->clid); |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 1064 | |
Kevin Darbyshire-Bryant | 8d6d573 | 2020-03-02 10:00:21 +0000 | [diff] [blame] | 1065 | #ifdef HAVE_DHCP6 |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 1066 | if (config->flags & CONFIG_ADDR6) |
| 1067 | { |
| 1068 | struct addrlist *addr, *tmp; |
| 1069 | |
| 1070 | for (addr = config->addr6; addr; addr = tmp) |
| 1071 | { |
| 1072 | tmp = addr->next; |
| 1073 | free(addr); |
| 1074 | } |
| 1075 | } |
Kevin Darbyshire-Bryant | 8d6d573 | 2020-03-02 10:00:21 +0000 | [diff] [blame] | 1076 | #endif |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 1077 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1078 | free(config); |
| 1079 | } |
| 1080 | } |
| 1081 | |
| 1082 | static void dhcp_context_free(struct dhcp_context *ctx) |
| 1083 | { |
| 1084 | if (ctx) |
| 1085 | { |
| 1086 | dhcp_netid_free(ctx->filter); |
| 1087 | free(ctx->netid.net); |
Kevin Darbyshire-Bryant | b683cf3 | 2018-12-10 10:34:35 +0000 | [diff] [blame] | 1088 | #ifdef HAVE_DHCP6 |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1089 | free(ctx->template_interface); |
Kevin Darbyshire-Bryant | b683cf3 | 2018-12-10 10:34:35 +0000 | [diff] [blame] | 1090 | #endif |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1091 | free(ctx); |
| 1092 | } |
| 1093 | } |
| 1094 | |
| 1095 | static void dhcp_opt_free(struct dhcp_opt *opt) |
| 1096 | { |
| 1097 | if (opt->flags & DHOPT_VENDOR) |
| 1098 | free(opt->u.vendor_class); |
| 1099 | dhcp_netid_free(opt->netid); |
| 1100 | free(opt->val); |
| 1101 | free(opt); |
| 1102 | } |
| 1103 | |
| 1104 | |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1105 | /* This is too insanely large to keep in-line in the switch */ |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1106 | static int parse_dhcp_opt(char *errstr, char *arg, int flags) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1107 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1108 | struct dhcp_opt *new = opt_malloc(sizeof(struct dhcp_opt)); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1109 | char lenchar = 0, *cp; |
Simon Kelley | 40ef23b | 2012-03-13 21:59:28 +0000 | [diff] [blame] | 1110 | 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] | 1111 | char *comma = NULL; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1112 | u16 opt_len = 0; |
| 1113 | int is6 = 0; |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 1114 | int option_ok = 0; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1115 | |
| 1116 | new->len = 0; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1117 | new->flags = flags; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1118 | new->netid = NULL; |
| 1119 | new->val = NULL; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1120 | new->opt = 0; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1121 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1122 | while (arg) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1123 | { |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1124 | comma = split(arg); |
| 1125 | |
| 1126 | for (cp = arg; *cp; cp++) |
| 1127 | if (*cp < '0' || *cp > '9') |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1128 | break; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1129 | |
| 1130 | if (!*cp) |
| 1131 | { |
| 1132 | new->opt = atoi(arg); |
| 1133 | opt_len = 0; |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 1134 | option_ok = 1; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1135 | break; |
| 1136 | } |
| 1137 | |
| 1138 | if (strstr(arg, "option:") == arg) |
| 1139 | { |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 1140 | if ((new->opt = lookup_dhcp_opt(AF_INET, arg+7)) != -1) |
| 1141 | { |
| 1142 | opt_len = lookup_dhcp_len(AF_INET, new->opt); |
| 1143 | /* option:<optname> must follow tag and vendor string. */ |
| 1144 | if (!(opt_len & OT_INTERNAL) || flags == DHOPT_MATCH) |
| 1145 | option_ok = 1; |
| 1146 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1147 | break; |
| 1148 | } |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1149 | #ifdef HAVE_DHCP6 |
| 1150 | else if (strstr(arg, "option6:") == arg) |
| 1151 | { |
| 1152 | for (cp = arg+8; *cp; cp++) |
| 1153 | if (*cp < '0' || *cp > '9') |
| 1154 | break; |
| 1155 | |
| 1156 | if (!*cp) |
| 1157 | { |
| 1158 | new->opt = atoi(arg+8); |
| 1159 | opt_len = 0; |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 1160 | option_ok = 1; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1161 | } |
| 1162 | else |
Simon Kelley | 40ef23b | 2012-03-13 21:59:28 +0000 | [diff] [blame] | 1163 | { |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 1164 | if ((new->opt = lookup_dhcp_opt(AF_INET6, arg+8)) != -1) |
| 1165 | { |
| 1166 | opt_len = lookup_dhcp_len(AF_INET6, new->opt); |
| 1167 | if (!(opt_len & OT_INTERNAL) || flags == DHOPT_MATCH) |
| 1168 | option_ok = 1; |
| 1169 | } |
Simon Kelley | 40ef23b | 2012-03-13 21:59:28 +0000 | [diff] [blame] | 1170 | } |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1171 | /* option6:<opt>|<optname> must follow tag and vendor string. */ |
| 1172 | is6 = 1; |
| 1173 | break; |
| 1174 | } |
| 1175 | #endif |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1176 | else if (strstr(arg, "vendor:") == arg) |
| 1177 | { |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 1178 | new->u.vendor_class = (unsigned char *)opt_string_alloc(arg+7); |
| 1179 | new->flags |= DHOPT_VENDOR; |
| 1180 | } |
| 1181 | else if (strstr(arg, "encap:") == arg) |
| 1182 | { |
| 1183 | new->u.encap = atoi(arg+6); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1184 | new->flags |= DHOPT_ENCAPSULATE; |
| 1185 | } |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 1186 | else if (strstr(arg, "vi-encap:") == arg) |
| 1187 | { |
| 1188 | new->u.encap = atoi(arg+9); |
| 1189 | new->flags |= DHOPT_RFC3925; |
| 1190 | if (flags == DHOPT_MATCH) |
| 1191 | { |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 1192 | option_ok = 1; |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 1193 | break; |
| 1194 | } |
| 1195 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1196 | else |
| 1197 | { |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 1198 | /* allow optional "net:" or "tag:" for consistency */ |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1199 | const char *name = (is_tag_prefix(arg)) ? arg+4 : set_prefix(arg); |
| 1200 | new->netid = dhcp_netid_create(name, new->netid); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | arg = comma; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1204 | } |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1205 | |
| 1206 | #ifdef HAVE_DHCP6 |
| 1207 | if (is6) |
| 1208 | { |
| 1209 | if (new->flags & (DHOPT_VENDOR | DHOPT_ENCAPSULATE)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1210 | goto_err(_("unsupported encapsulation for IPv6 option")); |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1211 | |
| 1212 | if (opt_len == 0 && |
| 1213 | !(new->flags & DHOPT_RFC3925)) |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 1214 | opt_len = lookup_dhcp_len(AF_INET6, new->opt); |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1215 | } |
| 1216 | else |
| 1217 | #endif |
| 1218 | if (opt_len == 0 && |
| 1219 | !(new->flags & (DHOPT_VENDOR | DHOPT_ENCAPSULATE | DHOPT_RFC3925))) |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 1220 | opt_len = lookup_dhcp_len(AF_INET, new->opt); |
Simon Kelley | 40ef23b | 2012-03-13 21:59:28 +0000 | [diff] [blame] | 1221 | |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 1222 | /* option may be missing with rfc3925 match */ |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 1223 | if (!option_ok) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1224 | goto_err(_("bad dhcp-option")); |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1225 | |
| 1226 | if (comma) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1227 | { |
| 1228 | /* characterise the value */ |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1229 | char c; |
Simon Kelley | 6799320 | 2019-03-04 22:59:42 +0000 | [diff] [blame] | 1230 | int found_dig = 0, found_colon = 0; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1231 | is_addr = is_addr6 = is_hex = is_dec = is_string = 1; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1232 | addrs = digs = 1; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1233 | dots = 0; |
| 1234 | for (cp = comma; (c = *cp); cp++) |
| 1235 | if (c == ',') |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1236 | { |
| 1237 | addrs++; |
| 1238 | is_dec = is_hex = 0; |
| 1239 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1240 | else if (c == ':') |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1241 | { |
| 1242 | digs++; |
| 1243 | is_dec = is_addr = 0; |
Simon Kelley | 6799320 | 2019-03-04 22:59:42 +0000 | [diff] [blame] | 1244 | found_colon = 1; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1245 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1246 | else if (c == '/') |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1247 | { |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1248 | is_addr6 = is_dec = is_hex = 0; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1249 | if (cp == comma) /* leading / means a pathname */ |
| 1250 | is_addr = 0; |
| 1251 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1252 | else if (c == '.') |
| 1253 | { |
Simon Kelley | 8baf583 | 2020-04-23 23:14:45 +0100 | [diff] [blame] | 1254 | is_dec = is_hex = 0; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1255 | dots++; |
| 1256 | } |
| 1257 | else if (c == '-') |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1258 | is_hex = is_addr = is_addr6 = 0; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1259 | else if (c == ' ') |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1260 | is_dec = is_hex = 0; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1261 | else if (!(c >='0' && c <= '9')) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1262 | { |
| 1263 | is_addr = 0; |
| 1264 | if (cp[1] == 0 && is_dec && |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1265 | (c == 'b' || c == 's' || c == 'i')) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1266 | { |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1267 | lenchar = c; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1268 | *cp = 0; |
| 1269 | } |
| 1270 | else |
| 1271 | is_dec = 0; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1272 | if (!((c >='A' && c <= 'F') || |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 1273 | (c >='a' && c <= 'f') || |
| 1274 | (c == '*' && (flags & DHOPT_MATCH)))) |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1275 | { |
| 1276 | is_hex = 0; |
| 1277 | if (c != '[' && c != ']') |
| 1278 | is_addr6 = 0; |
| 1279 | } |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1280 | } |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1281 | else |
| 1282 | found_dig = 1; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1283 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1284 | if (!found_dig) |
| 1285 | is_dec = is_addr = 0; |
Simon Kelley | 6799320 | 2019-03-04 22:59:42 +0000 | [diff] [blame] | 1286 | |
| 1287 | if (!found_colon) |
| 1288 | is_addr6 = 0; |
Vladislav Grishenko | dded78b | 2020-03-08 15:34:34 +0000 | [diff] [blame] | 1289 | |
| 1290 | #ifdef HAVE_DHCP6 |
| 1291 | /* NTP server option takes hex, addresses or FQDN */ |
| 1292 | if (is6 && new->opt == OPTION6_NTP_SERVER && !is_hex) |
| 1293 | opt_len |= is_addr6 ? OT_ADDR_LIST : OT_RFC1035_NAME; |
| 1294 | #endif |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1295 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1296 | /* We know that some options take addresses */ |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1297 | if (opt_len & OT_ADDR_LIST) |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1298 | { |
| 1299 | is_string = is_dec = is_hex = 0; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1300 | |
| 1301 | if (!is6 && (!is_addr || dots == 0)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1302 | goto_err(_("bad IP address")); |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1303 | |
| 1304 | if (is6 && !is_addr6) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1305 | goto_err(_("bad IPv6 address")); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1306 | } |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1307 | /* or names */ |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1308 | else if (opt_len & (OT_NAME | OT_RFC1035_NAME | OT_CSTRING)) |
| 1309 | is_addr6 = is_addr = is_dec = is_hex = 0; |
Simon Kelley | 23245c0 | 2012-07-18 16:21:11 +0100 | [diff] [blame] | 1310 | |
| 1311 | if (found_dig && (opt_len & OT_TIME) && strlen(comma) > 0) |
| 1312 | { |
| 1313 | int val, fac = 1; |
| 1314 | |
| 1315 | switch (comma[strlen(comma) - 1]) |
| 1316 | { |
Simon Kelley | 4224321 | 2012-07-20 15:19:18 +0100 | [diff] [blame] | 1317 | case 'w': |
| 1318 | case 'W': |
| 1319 | fac *= 7; |
| 1320 | /* fall through */ |
Simon Kelley | 23245c0 | 2012-07-18 16:21:11 +0100 | [diff] [blame] | 1321 | case 'd': |
| 1322 | case 'D': |
| 1323 | fac *= 24; |
Simon Kelley | 87e00fe | 2018-02-16 21:27:35 +0000 | [diff] [blame] | 1324 | /* fall through */ |
Simon Kelley | 23245c0 | 2012-07-18 16:21:11 +0100 | [diff] [blame] | 1325 | case 'h': |
| 1326 | case 'H': |
| 1327 | fac *= 60; |
| 1328 | /* fall through */ |
| 1329 | case 'm': |
| 1330 | case 'M': |
| 1331 | fac *= 60; |
| 1332 | /* fall through */ |
| 1333 | case 's': |
| 1334 | case 'S': |
| 1335 | comma[strlen(comma) - 1] = 0; |
| 1336 | } |
| 1337 | |
| 1338 | new->len = 4; |
| 1339 | new->val = opt_malloc(4); |
| 1340 | val = atoi(comma); |
| 1341 | *((int *)new->val) = htonl(val * fac); |
| 1342 | } |
| 1343 | else if (is_hex && digs > 1) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1344 | { |
| 1345 | new->len = digs; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1346 | new->val = opt_malloc(new->len); |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 1347 | parse_hex(comma, new->val, digs, (flags & DHOPT_MATCH) ? &new->u.wildcard_mask : NULL, NULL); |
| 1348 | new->flags |= DHOPT_HEX; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1349 | } |
| 1350 | else if (is_dec) |
| 1351 | { |
| 1352 | int i, val = atoi(comma); |
| 1353 | /* assume numeric arg is 1 byte except for |
| 1354 | options where it is known otherwise. |
| 1355 | For vendor class option, we have to hack. */ |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1356 | if (opt_len != 0) |
| 1357 | new->len = opt_len; |
| 1358 | else if (val & 0xffff0000) |
| 1359 | new->len = 4; |
| 1360 | else if (val & 0xff00) |
| 1361 | new->len = 2; |
| 1362 | else |
| 1363 | new->len = 1; |
| 1364 | |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1365 | if (lenchar == 'b') |
| 1366 | new->len = 1; |
| 1367 | else if (lenchar == 's') |
| 1368 | new->len = 2; |
| 1369 | else if (lenchar == 'i') |
| 1370 | new->len = 4; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1371 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1372 | new->val = opt_malloc(new->len); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1373 | for (i=0; i<new->len; i++) |
| 1374 | new->val[i] = val>>((new->len - i - 1)*8); |
| 1375 | } |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1376 | else if (is_addr && !is6) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1377 | { |
| 1378 | struct in_addr in; |
| 1379 | unsigned char *op; |
| 1380 | char *slash; |
| 1381 | /* max length of address/subnet descriptor is five bytes, |
| 1382 | add one for the option 120 enc byte too */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1383 | new->val = op = opt_malloc((5 * addrs) + 1); |
Simon Kelley | 6b01084 | 2007-02-12 20:32:07 +0000 | [diff] [blame] | 1384 | new->flags |= DHOPT_ADDR; |
| 1385 | |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 1386 | if (!(new->flags & (DHOPT_ENCAPSULATE | DHOPT_VENDOR | DHOPT_RFC3925)) && |
| 1387 | new->opt == OPTION_SIP_SERVER) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1388 | { |
Simon Kelley | 6b01084 | 2007-02-12 20:32:07 +0000 | [diff] [blame] | 1389 | *(op++) = 1; /* RFC 3361 "enc byte" */ |
| 1390 | new->flags &= ~DHOPT_ADDR; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1391 | } |
| 1392 | while (addrs--) |
| 1393 | { |
| 1394 | cp = comma; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1395 | comma = split(cp); |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 1396 | slash = split_chr(cp, '/'); |
Simon Kelley | a2bc254 | 2016-04-21 22:34:22 +0100 | [diff] [blame] | 1397 | if (!inet_pton(AF_INET, cp, &in)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1398 | goto_err(_("bad IPv4 address")); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1399 | if (!slash) |
| 1400 | { |
| 1401 | memcpy(op, &in, INADDRSZ); |
| 1402 | op += INADDRSZ; |
| 1403 | } |
| 1404 | else |
| 1405 | { |
| 1406 | unsigned char *p = (unsigned char *)∈ |
| 1407 | int netsize = atoi(slash); |
| 1408 | *op++ = netsize; |
| 1409 | if (netsize > 0) |
| 1410 | *op++ = *p++; |
| 1411 | if (netsize > 8) |
| 1412 | *op++ = *p++; |
| 1413 | if (netsize > 16) |
| 1414 | *op++ = *p++; |
| 1415 | if (netsize > 24) |
| 1416 | *op++ = *p++; |
| 1417 | new->flags &= ~DHOPT_ADDR; /* cannot re-write descriptor format */ |
| 1418 | } |
| 1419 | } |
| 1420 | new->len = op - new->val; |
| 1421 | } |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1422 | else if (is_addr6 && is6) |
| 1423 | { |
| 1424 | unsigned char *op; |
| 1425 | new->val = op = opt_malloc(16 * addrs); |
| 1426 | new->flags |= DHOPT_ADDR6; |
| 1427 | while (addrs--) |
| 1428 | { |
| 1429 | cp = comma; |
| 1430 | comma = split(cp); |
| 1431 | |
| 1432 | /* check for [1234::7] */ |
| 1433 | if (*cp == '[') |
| 1434 | cp++; |
| 1435 | if (strlen(cp) > 1 && cp[strlen(cp)-1] == ']') |
| 1436 | cp[strlen(cp)-1] = 0; |
| 1437 | |
| 1438 | if (inet_pton(AF_INET6, cp, op)) |
| 1439 | { |
| 1440 | op += IN6ADDRSZ; |
| 1441 | continue; |
| 1442 | } |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1443 | |
| 1444 | goto_err(_("bad IPv6 address")); |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1445 | } |
| 1446 | new->len = op - new->val; |
| 1447 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1448 | else if (is_string) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1449 | { |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1450 | /* text arg */ |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 1451 | if ((new->opt == OPTION_DOMAIN_SEARCH || new->opt == OPTION_SIP_SERVER) && |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1452 | !is6 && !(new->flags & (DHOPT_ENCAPSULATE | DHOPT_VENDOR | DHOPT_RFC3925))) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1453 | { |
| 1454 | /* dns search, RFC 3397, or SIP, RFC 3361 */ |
| 1455 | unsigned char *q, *r, *tail; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1456 | unsigned char *p, *m = NULL, *newp; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1457 | size_t newlen, len = 0; |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 1458 | int header_size = (new->opt == OPTION_DOMAIN_SEARCH) ? 0 : 1; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1459 | |
| 1460 | arg = comma; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1461 | comma = split(arg); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1462 | |
| 1463 | while (arg && *arg) |
| 1464 | { |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1465 | char *in, *dom = NULL; |
| 1466 | size_t domlen = 1; |
| 1467 | /* Allow "." as an empty domain */ |
| 1468 | if (strcmp (arg, ".") != 0) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1469 | { |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1470 | if (!(dom = canonicalise_opt(arg))) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1471 | goto_err(_("bad domain in dhcp-option")); |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1472 | |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1473 | domlen = strlen(dom) + 2; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1474 | } |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1475 | |
| 1476 | newp = opt_malloc(len + domlen + header_size); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1477 | if (m) |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1478 | { |
| 1479 | memcpy(newp, m, header_size + len); |
| 1480 | free(m); |
| 1481 | } |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1482 | m = newp; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1483 | p = m + header_size; |
| 1484 | q = p + len; |
| 1485 | |
| 1486 | /* add string on the end in RFC1035 format */ |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1487 | for (in = dom; in && *in;) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1488 | { |
| 1489 | unsigned char *cp = q++; |
| 1490 | int j; |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1491 | for (j = 0; *in && (*in != '.'); in++, j++) |
| 1492 | *q++ = *in; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1493 | *cp = j; |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1494 | if (*in) |
| 1495 | in++; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1496 | } |
| 1497 | *q++ = 0; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1498 | free(dom); |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1499 | |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1500 | /* Now tail-compress using earlier names. */ |
| 1501 | newlen = q - p; |
| 1502 | for (tail = p + len; *tail; tail += (*tail) + 1) |
| 1503 | for (r = p; r - p < (int)len; r += (*r) + 1) |
| 1504 | if (strcmp((char *)r, (char *)tail) == 0) |
| 1505 | { |
| 1506 | PUTSHORT((r - p) | 0xc000, tail); |
| 1507 | newlen = tail - p; |
| 1508 | goto end; |
| 1509 | } |
| 1510 | end: |
| 1511 | len = newlen; |
| 1512 | |
| 1513 | arg = comma; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1514 | comma = split(arg); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1515 | } |
| 1516 | |
| 1517 | /* RFC 3361, enc byte is zero for names */ |
Simon Kelley | 9e73244 | 2019-12-12 20:56:08 +0000 | [diff] [blame] | 1518 | if (new->opt == OPTION_SIP_SERVER && m) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1519 | m[0] = 0; |
| 1520 | new->len = (int) len + header_size; |
| 1521 | new->val = m; |
| 1522 | } |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1523 | #ifdef HAVE_DHCP6 |
| 1524 | else if (comma && (opt_len & OT_CSTRING)) |
| 1525 | { |
| 1526 | /* length fields are two bytes so need 16 bits for each string */ |
Simon Kelley | 40ef23b | 2012-03-13 21:59:28 +0000 | [diff] [blame] | 1527 | int i, commas = 1; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1528 | unsigned char *p, *newp; |
| 1529 | |
Simon Kelley | 40ef23b | 2012-03-13 21:59:28 +0000 | [diff] [blame] | 1530 | for (i = 0; comma[i]; i++) |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1531 | if (comma[i] == ',') |
| 1532 | commas++; |
| 1533 | |
| 1534 | newp = opt_malloc(strlen(comma)+(2*commas)); |
| 1535 | p = newp; |
| 1536 | arg = comma; |
| 1537 | comma = split(arg); |
| 1538 | |
| 1539 | while (arg && *arg) |
| 1540 | { |
| 1541 | u16 len = strlen(arg); |
Simon Kelley | 18f0fb0 | 2012-03-31 21:18:55 +0100 | [diff] [blame] | 1542 | unhide_metas(arg); |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1543 | PUTSHORT(len, p); |
| 1544 | memcpy(p, arg, len); |
| 1545 | p += len; |
| 1546 | |
| 1547 | arg = comma; |
| 1548 | comma = split(arg); |
| 1549 | } |
| 1550 | |
| 1551 | new->val = newp; |
| 1552 | new->len = p - newp; |
| 1553 | } |
| 1554 | else if (comma && (opt_len & OT_RFC1035_NAME)) |
| 1555 | { |
Vladislav Grishenko | dded78b | 2020-03-08 15:34:34 +0000 | [diff] [blame] | 1556 | unsigned char *p = NULL, *q, *newp, *end; |
Simon Kelley | 18f0fb0 | 2012-03-31 21:18:55 +0100 | [diff] [blame] | 1557 | int len = 0; |
Vladislav Grishenko | dded78b | 2020-03-08 15:34:34 +0000 | [diff] [blame] | 1558 | int header_size = (is6 && new->opt == OPTION6_NTP_SERVER) ? 4 : 0; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1559 | arg = comma; |
| 1560 | comma = split(arg); |
| 1561 | |
| 1562 | while (arg && *arg) |
| 1563 | { |
Simon Kelley | 18f0fb0 | 2012-03-31 21:18:55 +0100 | [diff] [blame] | 1564 | char *dom = canonicalise_opt(arg); |
| 1565 | if (!dom) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1566 | goto_err(_("bad domain in dhcp-option")); |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1567 | |
Vladislav Grishenko | dded78b | 2020-03-08 15:34:34 +0000 | [diff] [blame] | 1568 | newp = opt_malloc(len + header_size + strlen(dom) + 2); |
Simon Kelley | 18f0fb0 | 2012-03-31 21:18:55 +0100 | [diff] [blame] | 1569 | |
| 1570 | if (p) |
| 1571 | { |
| 1572 | memcpy(newp, p, len); |
| 1573 | free(p); |
| 1574 | } |
| 1575 | |
| 1576 | p = newp; |
Vladislav Grishenko | dded78b | 2020-03-08 15:34:34 +0000 | [diff] [blame] | 1577 | q = p + len; |
| 1578 | end = do_rfc1035_name(q + header_size, dom, NULL); |
Simon Kelley | 18f0fb0 | 2012-03-31 21:18:55 +0100 | [diff] [blame] | 1579 | *end++ = 0; |
Vladislav Grishenko | dded78b | 2020-03-08 15:34:34 +0000 | [diff] [blame] | 1580 | if (is6 && new->opt == OPTION6_NTP_SERVER) |
| 1581 | { |
| 1582 | PUTSHORT(NTP_SUBOPTION_SRV_FQDN, q); |
| 1583 | PUTSHORT(end - q - 2, q); |
| 1584 | } |
Simon Kelley | 18f0fb0 | 2012-03-31 21:18:55 +0100 | [diff] [blame] | 1585 | len = end - p; |
| 1586 | free(dom); |
| 1587 | |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1588 | arg = comma; |
| 1589 | comma = split(arg); |
| 1590 | } |
| 1591 | |
Simon Kelley | 18f0fb0 | 2012-03-31 21:18:55 +0100 | [diff] [blame] | 1592 | new->val = p; |
| 1593 | new->len = len; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1594 | } |
| 1595 | #endif |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1596 | else |
| 1597 | { |
| 1598 | new->len = strlen(comma); |
| 1599 | /* keep terminating zero on string */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1600 | new->val = (unsigned char *)opt_string_alloc(comma); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1601 | new->flags |= DHOPT_STRING; |
| 1602 | } |
| 1603 | } |
| 1604 | } |
| 1605 | |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1606 | if (!is6 && |
| 1607 | ((new->len > 255) || |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 1608 | (new->len > 253 && (new->flags & (DHOPT_VENDOR | DHOPT_ENCAPSULATE))) || |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1609 | (new->len > 250 && (new->flags & DHOPT_RFC3925)))) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1610 | goto_err(_("dhcp-option too long")); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1611 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1612 | if (flags == DHOPT_MATCH) |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1613 | { |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1614 | if ((new->flags & (DHOPT_ENCAPSULATE | DHOPT_VENDOR)) || |
| 1615 | !new->netid || |
| 1616 | new->netid->next) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1617 | goto_err(_("illegal dhcp-match")); |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1618 | |
| 1619 | if (is6) |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 1620 | { |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1621 | new->next = daemon->dhcp_match6; |
| 1622 | daemon->dhcp_match6 = new; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1623 | } |
| 1624 | else |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 1625 | { |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1626 | new->next = daemon->dhcp_match; |
| 1627 | daemon->dhcp_match = new; |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 1628 | } |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1629 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1630 | else if (is6) |
| 1631 | { |
| 1632 | new->next = daemon->dhcp_opts6; |
| 1633 | daemon->dhcp_opts6 = new; |
| 1634 | } |
| 1635 | else |
| 1636 | { |
| 1637 | new->next = daemon->dhcp_opts; |
| 1638 | daemon->dhcp_opts = new; |
| 1639 | } |
| 1640 | |
| 1641 | return 1; |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1642 | on_error: |
| 1643 | dhcp_opt_free(new); |
| 1644 | return 0; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1645 | } |
| 1646 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1647 | #endif |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1648 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1649 | void set_option_bool(unsigned int opt) |
| 1650 | { |
Petr Menšík | 24b8760 | 2018-10-24 22:30:18 +0100 | [diff] [blame] | 1651 | option_var(opt) |= option_val(opt); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1652 | } |
| 1653 | |
Simon Kelley | 2b5bae9 | 2012-06-26 16:55:23 +0100 | [diff] [blame] | 1654 | void reset_option_bool(unsigned int opt) |
| 1655 | { |
Petr Menšík | 24b8760 | 2018-10-24 22:30:18 +0100 | [diff] [blame] | 1656 | option_var(opt) &= ~(option_val(opt)); |
Simon Kelley | 2b5bae9 | 2012-06-26 16:55:23 +0100 | [diff] [blame] | 1657 | } |
| 1658 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1659 | static void server_list_free(struct server *list) |
| 1660 | { |
| 1661 | while (list) |
| 1662 | { |
| 1663 | struct server *tmp = list; |
| 1664 | list = list->next; |
| 1665 | free(tmp); |
| 1666 | } |
| 1667 | } |
| 1668 | |
Simon Kelley | 7b1eae4 | 2014-02-20 13:43:28 +0000 | [diff] [blame] | 1669 | 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] | 1670 | { |
| 1671 | int i; |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1672 | char *comma; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1673 | |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1674 | if (option == '?') |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1675 | ret_err(gen_err); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1676 | |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 1677 | for (i=0; usage[i].opt != 0; i++) |
| 1678 | if (usage[i].opt == option) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1679 | { |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 1680 | int rept = usage[i].rept; |
| 1681 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1682 | if (command_line) |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 1683 | { |
| 1684 | /* command line */ |
| 1685 | if (rept == ARG_USED_CL) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1686 | ret_err(_("illegal repeated flag")); |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 1687 | if (rept == ARG_ONE) |
| 1688 | usage[i].rept = ARG_USED_CL; |
| 1689 | } |
| 1690 | else |
| 1691 | { |
| 1692 | /* allow file to override command line */ |
| 1693 | if (rept == ARG_USED_FILE) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1694 | ret_err(_("illegal repeated keyword")); |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 1695 | if (rept == ARG_USED_CL || rept == ARG_ONE) |
| 1696 | usage[i].rept = ARG_USED_FILE; |
| 1697 | } |
| 1698 | |
| 1699 | if (rept != ARG_DUP && rept != ARG_ONE && rept != ARG_USED_CL) |
| 1700 | { |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1701 | set_option_bool(rept); |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1702 | return 1; |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | break; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1706 | } |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 1707 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1708 | switch (option) |
| 1709 | { |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1710 | case 'C': /* --conf-file */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1711 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1712 | char *file = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1713 | if (file) |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1714 | { |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1715 | one_file(file, 0); |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1716 | free(file); |
| 1717 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1718 | break; |
| 1719 | } |
| 1720 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1721 | case '7': /* --conf-dir */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1722 | { |
| 1723 | DIR *dir_stream; |
| 1724 | struct dirent *ent; |
| 1725 | char *directory, *path; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1726 | struct list { |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1727 | char *name; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1728 | struct list *next; |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1729 | } *ignore_suffix = NULL, *match_suffix = NULL, *files = NULL, *li; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1730 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1731 | comma = split(arg); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1732 | if (!(directory = opt_string_alloc(arg))) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1733 | break; |
| 1734 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1735 | for (arg = comma; arg; arg = comma) |
| 1736 | { |
| 1737 | comma = split(arg); |
Simon Kelley | 00cd9d5 | 2014-10-02 21:44:21 +0100 | [diff] [blame] | 1738 | if (strlen(arg) != 0) |
Simon Kelley | 3e1551a | 2014-09-09 21:46:07 +0100 | [diff] [blame] | 1739 | { |
Simon Kelley | 00cd9d5 | 2014-10-02 21:44:21 +0100 | [diff] [blame] | 1740 | li = opt_malloc(sizeof(struct list)); |
| 1741 | if (*arg == '*') |
| 1742 | { |
Simon Kelley | 0007ee9 | 2015-11-21 21:47:41 +0000 | [diff] [blame] | 1743 | /* "*" with no suffix is a no-op */ |
| 1744 | if (arg[1] == 0) |
| 1745 | free(li); |
| 1746 | else |
| 1747 | { |
| 1748 | li->next = match_suffix; |
| 1749 | match_suffix = li; |
| 1750 | /* Have to copy: buffer is overwritten */ |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1751 | li->name = opt_string_alloc(arg+1); |
Simon Kelley | 0007ee9 | 2015-11-21 21:47:41 +0000 | [diff] [blame] | 1752 | } |
Simon Kelley | 00cd9d5 | 2014-10-02 21:44:21 +0100 | [diff] [blame] | 1753 | } |
| 1754 | else |
| 1755 | { |
| 1756 | li->next = ignore_suffix; |
| 1757 | ignore_suffix = li; |
| 1758 | /* Have to copy: buffer is overwritten */ |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1759 | li->name = opt_string_alloc(arg); |
Simon Kelley | 00cd9d5 | 2014-10-02 21:44:21 +0100 | [diff] [blame] | 1760 | } |
Simon Kelley | 3e1551a | 2014-09-09 21:46:07 +0100 | [diff] [blame] | 1761 | } |
Simon Kelley | 00cd9d5 | 2014-10-02 21:44:21 +0100 | [diff] [blame] | 1762 | } |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1763 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1764 | if (!(dir_stream = opendir(directory))) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 1765 | die(_("cannot access directory %s: %s"), directory, EC_FILE); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1766 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1767 | while ((ent = readdir(dir_stream))) |
| 1768 | { |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1769 | size_t len = strlen(ent->d_name); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1770 | struct stat buf; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1771 | |
| 1772 | /* ignore emacs backups and dotfiles */ |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1773 | if (len == 0 || |
| 1774 | ent->d_name[len - 1] == '~' || |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1775 | (ent->d_name[0] == '#' && ent->d_name[len - 1] == '#') || |
| 1776 | ent->d_name[0] == '.') |
| 1777 | continue; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1778 | |
Simon Kelley | 3e1551a | 2014-09-09 21:46:07 +0100 | [diff] [blame] | 1779 | if (match_suffix) |
| 1780 | { |
| 1781 | for (li = match_suffix; li; li = li->next) |
| 1782 | { |
| 1783 | /* check for required suffices */ |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1784 | size_t ls = strlen(li->name); |
Simon Kelley | 3e1551a | 2014-09-09 21:46:07 +0100 | [diff] [blame] | 1785 | if (len > ls && |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1786 | strcmp(li->name, &ent->d_name[len - ls]) == 0) |
Simon Kelley | 3e1551a | 2014-09-09 21:46:07 +0100 | [diff] [blame] | 1787 | break; |
| 1788 | } |
| 1789 | if (!li) |
| 1790 | continue; |
| 1791 | } |
| 1792 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1793 | for (li = ignore_suffix; li; li = li->next) |
| 1794 | { |
| 1795 | /* check for proscribed suffices */ |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1796 | size_t ls = strlen(li->name); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1797 | if (len > ls && |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1798 | strcmp(li->name, &ent->d_name[len - ls]) == 0) |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1799 | break; |
| 1800 | } |
| 1801 | if (li) |
| 1802 | continue; |
| 1803 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1804 | path = opt_malloc(strlen(directory) + len + 2); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1805 | strcpy(path, directory); |
| 1806 | strcat(path, "/"); |
| 1807 | strcat(path, ent->d_name); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1808 | |
Simon Kelley | 39595cf | 2013-02-04 21:40:07 +0000 | [diff] [blame] | 1809 | /* files must be readable */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1810 | if (stat(path, &buf) == -1) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 1811 | die(_("cannot access %s: %s"), path, EC_FILE); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1812 | |
Simon Kelley | 39595cf | 2013-02-04 21:40:07 +0000 | [diff] [blame] | 1813 | /* only reg files allowed. */ |
| 1814 | if (S_ISREG(buf.st_mode)) |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1815 | { |
| 1816 | /* sort files into order. */ |
| 1817 | struct list **up, *new = opt_malloc(sizeof(struct list)); |
| 1818 | new->name = path; |
| 1819 | |
| 1820 | for (up = &files, li = files; li; up = &li->next, li = li->next) |
| 1821 | if (strcmp(li->name, path) >=0) |
| 1822 | break; |
| 1823 | |
| 1824 | new->next = li; |
| 1825 | *up = new; |
| 1826 | } |
| 1827 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1828 | } |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1829 | |
| 1830 | for (li = files; li; li = li->next) |
| 1831 | one_file(li->name, 0); |
| 1832 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1833 | closedir(dir_stream); |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1834 | free(directory); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1835 | for(; ignore_suffix; ignore_suffix = li) |
| 1836 | { |
| 1837 | li = ignore_suffix->next; |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1838 | free(ignore_suffix->name); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1839 | free(ignore_suffix); |
| 1840 | } |
Simon Kelley | 00cd9d5 | 2014-10-02 21:44:21 +0100 | [diff] [blame] | 1841 | for(; match_suffix; match_suffix = li) |
| 1842 | { |
| 1843 | li = match_suffix->next; |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1844 | free(match_suffix->name); |
Simon Kelley | 00cd9d5 | 2014-10-02 21:44:21 +0100 | [diff] [blame] | 1845 | free(match_suffix); |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 1846 | } |
Simon Kelley | ab53883 | 2020-01-10 20:44:48 +0000 | [diff] [blame] | 1847 | for(; files; files = li) |
| 1848 | { |
| 1849 | li = files->next; |
| 1850 | free(files->name); |
| 1851 | free(files); |
| 1852 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1853 | break; |
| 1854 | } |
| 1855 | |
Simon Kelley | ed4c076 | 2013-10-08 20:46:34 +0100 | [diff] [blame] | 1856 | case LOPT_ADD_SBNET: /* --add-subnet */ |
| 1857 | set_option_bool(OPT_CLIENT_SUBNET); |
| 1858 | if (arg) |
| 1859 | { |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 1860 | char *err, *end; |
Simon Kelley | ed4c076 | 2013-10-08 20:46:34 +0100 | [diff] [blame] | 1861 | comma = split(arg); |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 1862 | |
| 1863 | struct mysubnet* new = opt_malloc(sizeof(struct mysubnet)); |
| 1864 | if ((end = split_chr(arg, '/'))) |
| 1865 | { |
| 1866 | /* has subnet+len */ |
| 1867 | err = parse_mysockaddr(arg, &new->addr); |
| 1868 | if (err) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1869 | ret_err_free(err, new); |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 1870 | if (!atoi_check(end, &new->mask)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1871 | ret_err_free(gen_err, new); |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 1872 | new->addr_used = 1; |
| 1873 | } |
| 1874 | else if (!atoi_check(arg, &new->mask)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1875 | ret_err_free(gen_err, new); |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 1876 | |
| 1877 | daemon->add_subnet4 = new; |
| 1878 | |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 1879 | if (comma) |
| 1880 | { |
Simon Kelley | 22fe2fd | 2016-02-28 17:07:10 +0000 | [diff] [blame] | 1881 | new = opt_malloc(sizeof(struct mysubnet)); |
| 1882 | if ((end = split_chr(comma, '/'))) |
| 1883 | { |
| 1884 | /* has subnet+len */ |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 1885 | err = parse_mysockaddr(comma, &new->addr); |
| 1886 | if (err) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1887 | ret_err_free(err, new); |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 1888 | if (!atoi_check(end, &new->mask)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1889 | ret_err_free(gen_err, new); |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 1890 | new->addr_used = 1; |
| 1891 | } |
| 1892 | else |
| 1893 | { |
| 1894 | if (!atoi_check(comma, &new->mask)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 1895 | ret_err_free(gen_err, new); |
Ed Bardsley | a7369be | 2015-08-05 21:17:18 +0100 | [diff] [blame] | 1896 | } |
Simon Kelley | 22fe2fd | 2016-02-28 17:07:10 +0000 | [diff] [blame] | 1897 | |
| 1898 | daemon->add_subnet6 = new; |
| 1899 | } |
Simon Kelley | ed4c076 | 2013-10-08 20:46:34 +0100 | [diff] [blame] | 1900 | } |
| 1901 | break; |
| 1902 | |
Simon Kelley | ad09427 | 2012-08-10 17:10:54 +0100 | [diff] [blame] | 1903 | case '1': /* --enable-dbus */ |
| 1904 | set_option_bool(OPT_DBUS); |
| 1905 | if (arg) |
| 1906 | daemon->dbus_name = opt_string_alloc(arg); |
| 1907 | else |
| 1908 | daemon->dbus_name = DNSMASQ_SERVICE; |
| 1909 | break; |
Oldřich Jedlička | d162bee | 2020-03-20 22:18:57 +0100 | [diff] [blame] | 1910 | |
| 1911 | case LOPT_UBUS: /* --enable-ubus */ |
| 1912 | set_option_bool(OPT_UBUS); |
| 1913 | if (arg) |
| 1914 | daemon->ubus_name = opt_string_alloc(arg); |
| 1915 | else |
| 1916 | daemon->ubus_name = DNSMASQ_UBUS_NAME; |
| 1917 | break; |
| 1918 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1919 | case '8': /* --log-facility */ |
| 1920 | /* may be a filename */ |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 1921 | if (strchr(arg, '/') || strcmp (arg, "-") == 0) |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1922 | daemon->log_file = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1923 | else |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1924 | { |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 1925 | #ifdef __ANDROID__ |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1926 | ret_err(_("setting log facility is not possible under Android")); |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 1927 | #else |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1928 | for (i = 0; facilitynames[i].c_name; i++) |
| 1929 | if (hostname_isequal((char *)facilitynames[i].c_name, arg)) |
| 1930 | break; |
| 1931 | |
| 1932 | if (facilitynames[i].c_name) |
| 1933 | daemon->log_fac = facilitynames[i].c_val; |
| 1934 | else |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1935 | ret_err(_("bad log facility")); |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 1936 | #endif |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1937 | } |
| 1938 | break; |
Julian Kornberger | 8dcdb33 | 2018-07-21 22:11:08 +0100 | [diff] [blame] | 1939 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1940 | case 'x': /* --pid-file */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1941 | daemon->runfile = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1942 | break; |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 1943 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1944 | case 'r': /* --resolv-file */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1945 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1946 | char *name = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1947 | struct resolvc *new, *list = daemon->resolv_files; |
| 1948 | |
| 1949 | if (list && list->is_default) |
| 1950 | { |
| 1951 | /* replace default resolv file - possibly with nothing */ |
| 1952 | if (name) |
| 1953 | { |
| 1954 | list->is_default = 0; |
| 1955 | list->name = name; |
| 1956 | } |
| 1957 | else |
| 1958 | list = NULL; |
| 1959 | } |
| 1960 | else if (name) |
| 1961 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1962 | new = opt_malloc(sizeof(struct resolvc)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1963 | new->next = list; |
| 1964 | new->name = name; |
| 1965 | new->is_default = 0; |
| 1966 | new->mtime = 0; |
| 1967 | new->logged = 0; |
| 1968 | list = new; |
| 1969 | } |
| 1970 | daemon->resolv_files = list; |
| 1971 | break; |
| 1972 | } |
Simon Kelley | 7b1eae4 | 2014-02-20 13:43:28 +0000 | [diff] [blame] | 1973 | |
| 1974 | case LOPT_SERVERS_FILE: |
| 1975 | daemon->servers_file = opt_string_alloc(arg); |
| 1976 | break; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1977 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1978 | case 'm': /* --mx-host */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1979 | { |
| 1980 | int pref = 1; |
| 1981 | struct mx_srv_record *new; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1982 | char *name, *target = NULL; |
| 1983 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1984 | if ((comma = split(arg))) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1985 | { |
| 1986 | char *prefstr; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1987 | if ((prefstr = split(comma)) && !atoi_check16(prefstr, &pref)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1988 | ret_err(_("bad MX preference")); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1989 | } |
| 1990 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1991 | if (!(name = canonicalise_opt(arg)) || |
| 1992 | (comma && !(target = canonicalise_opt(comma)))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1993 | ret_err(_("bad MX name")); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1994 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1995 | new = opt_malloc(sizeof(struct mx_srv_record)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1996 | new->next = daemon->mxnames; |
| 1997 | daemon->mxnames = new; |
| 1998 | new->issrv = 0; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1999 | new->name = name; |
| 2000 | new->target = target; /* may be NULL */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2001 | new->weight = pref; |
| 2002 | break; |
| 2003 | } |
| 2004 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2005 | case 't': /* --mx-target */ |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 2006 | if (!(daemon->mxtarget = canonicalise_opt(arg))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2007 | ret_err(_("bad MX target")); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2008 | break; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2009 | |
Simon Kelley | 6b17335 | 2018-05-08 18:32:14 +0100 | [diff] [blame] | 2010 | case LOPT_DUMPFILE: /* --dumpfile */ |
| 2011 | daemon->dump_file = opt_string_alloc(arg); |
| 2012 | break; |
| 2013 | |
| 2014 | case LOPT_DUMPMASK: /* --dumpmask */ |
| 2015 | daemon->dump_mask = strtol(arg, NULL, 0); |
| 2016 | break; |
| 2017 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2018 | #ifdef HAVE_DHCP |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2019 | case 'l': /* --dhcp-leasefile */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2020 | daemon->lease_file = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2021 | break; |
| 2022 | |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 2023 | /* Sorry about the gross pre-processor abuse */ |
| 2024 | case '6': /* --dhcp-script */ |
| 2025 | case LOPT_LUASCRIPT: /* --dhcp-luascript */ |
Simon Kelley | 48d12f1 | 2018-11-02 21:55:04 +0000 | [diff] [blame] | 2026 | # if !defined(HAVE_SCRIPT) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2027 | ret_err(_("recompile with HAVE_SCRIPT defined to enable lease-change scripts")); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2028 | # else |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 2029 | if (option == LOPT_LUASCRIPT) |
| 2030 | # if !defined(HAVE_LUASCRIPT) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2031 | ret_err(_("recompile with HAVE_LUASCRIPT defined to enable Lua scripts")); |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 2032 | # else |
| 2033 | daemon->luascript = opt_string_alloc(arg); |
| 2034 | # endif |
| 2035 | else |
| 2036 | daemon->lease_change_command = opt_string_alloc(arg); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2037 | # endif |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2038 | break; |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 2039 | #endif /* HAVE_DHCP */ |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2040 | |
Simon Kelley | 70d1873 | 2015-01-31 19:59:29 +0000 | [diff] [blame] | 2041 | case LOPT_DHCP_HOST: /* --dhcp-hostsfile */ |
| 2042 | case LOPT_DHCP_OPTS: /* --dhcp-optsfile */ |
| 2043 | case LOPT_DHCP_INOTIFY: /* --dhcp-hostsdir */ |
| 2044 | case LOPT_DHOPT_INOTIFY: /* --dhcp-optsdir */ |
| 2045 | case LOPT_HOST_INOTIFY: /* --hostsdir */ |
| 2046 | case 'H': /* --addn-hosts */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2047 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2048 | struct hostsfile *new = opt_malloc(sizeof(struct hostsfile)); |
Simon Kelley | 19c51cf | 2014-03-18 22:38:30 +0000 | [diff] [blame] | 2049 | static unsigned int hosts_index = SRC_AH; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2050 | new->fname = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2051 | new->index = hosts_index++; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2052 | new->flags = 0; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 2053 | if (option == 'H') |
| 2054 | { |
| 2055 | new->next = daemon->addn_hosts; |
| 2056 | daemon->addn_hosts = new; |
| 2057 | } |
| 2058 | else if (option == LOPT_DHCP_HOST) |
| 2059 | { |
| 2060 | new->next = daemon->dhcp_hosts_file; |
| 2061 | daemon->dhcp_hosts_file = new; |
| 2062 | } |
Simon Kelley | e1ff419 | 2012-12-09 17:08:47 +0000 | [diff] [blame] | 2063 | else if (option == LOPT_DHCP_OPTS) |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 2064 | { |
| 2065 | new->next = daemon->dhcp_opts_file; |
| 2066 | daemon->dhcp_opts_file = new; |
| 2067 | } |
Simon Kelley | 70d1873 | 2015-01-31 19:59:29 +0000 | [diff] [blame] | 2068 | else |
Simon Kelley | 5f4dc5c | 2015-01-20 20:51:02 +0000 | [diff] [blame] | 2069 | { |
Simon Kelley | 70d1873 | 2015-01-31 19:59:29 +0000 | [diff] [blame] | 2070 | new->next = daemon->dynamic_dirs; |
| 2071 | daemon->dynamic_dirs = new; |
| 2072 | if (option == LOPT_DHCP_INOTIFY) |
| 2073 | new->flags |= AH_DHCP_HST; |
| 2074 | else if (option == LOPT_DHOPT_INOTIFY) |
| 2075 | new->flags |= AH_DHCP_OPT; |
| 2076 | else if (option == LOPT_HOST_INOTIFY) |
| 2077 | new->flags |= AH_HOSTS; |
Simon Kelley | 5f4dc5c | 2015-01-20 20:51:02 +0000 | [diff] [blame] | 2078 | } |
| 2079 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2080 | break; |
| 2081 | } |
| 2082 | |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2083 | case LOPT_AUTHSERV: /* --auth-server */ |
Simon Kelley | 0893347 | 2018-10-05 16:34:35 +0100 | [diff] [blame] | 2084 | comma = split(arg); |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2085 | |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2086 | daemon->authserver = opt_string_alloc(arg); |
Simon Kelley | 0893347 | 2018-10-05 16:34:35 +0100 | [diff] [blame] | 2087 | |
| 2088 | while ((arg = comma)) |
| 2089 | { |
| 2090 | struct iname *new = opt_malloc(sizeof(struct iname)); |
| 2091 | comma = split(arg); |
| 2092 | new->name = NULL; |
| 2093 | unhide_metas(arg); |
| 2094 | if (inet_pton(AF_INET, arg, &new->addr.in.sin_addr) > 0) |
| 2095 | new->addr.sa.sa_family = AF_INET; |
Simon Kelley | 0893347 | 2018-10-05 16:34:35 +0100 | [diff] [blame] | 2096 | else if (inet_pton(AF_INET6, arg, &new->addr.in6.sin6_addr) > 0) |
| 2097 | new->addr.sa.sa_family = AF_INET6; |
Simon Kelley | 0893347 | 2018-10-05 16:34:35 +0100 | [diff] [blame] | 2098 | else |
| 2099 | { |
| 2100 | char *fam = split_chr(arg, '/'); |
| 2101 | new->name = opt_string_alloc(arg); |
| 2102 | new->addr.sa.sa_family = 0; |
| 2103 | if (fam) |
| 2104 | { |
| 2105 | if (strcmp(fam, "4") == 0) |
| 2106 | new->addr.sa.sa_family = AF_INET; |
Simon Kelley | 0893347 | 2018-10-05 16:34:35 +0100 | [diff] [blame] | 2107 | else if (strcmp(fam, "6") == 0) |
| 2108 | new->addr.sa.sa_family = AF_INET6; |
Simon Kelley | 0893347 | 2018-10-05 16:34:35 +0100 | [diff] [blame] | 2109 | else |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2110 | { |
| 2111 | free(new->name); |
| 2112 | ret_err_free(gen_err, new); |
| 2113 | } |
Simon Kelley | 0893347 | 2018-10-05 16:34:35 +0100 | [diff] [blame] | 2114 | } |
| 2115 | } |
| 2116 | new->next = daemon->authinterface; |
| 2117 | daemon->authinterface = new; |
| 2118 | }; |
Simon Kelley | 429798f | 2012-12-10 20:45:53 +0000 | [diff] [blame] | 2119 | |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2120 | break; |
Simon Kelley | e1ff419 | 2012-12-09 17:08:47 +0000 | [diff] [blame] | 2121 | |
| 2122 | case LOPT_AUTHSFS: /* --auth-sec-servers */ |
| 2123 | { |
| 2124 | struct name_list *new; |
| 2125 | |
| 2126 | do { |
| 2127 | comma = split(arg); |
Simon Kelley | 429798f | 2012-12-10 20:45:53 +0000 | [diff] [blame] | 2128 | new = opt_malloc(sizeof(struct name_list)); |
Simon Kelley | e1ff419 | 2012-12-09 17:08:47 +0000 | [diff] [blame] | 2129 | new->name = opt_string_alloc(arg); |
| 2130 | new->next = daemon->secondary_forward_server; |
| 2131 | daemon->secondary_forward_server = new; |
| 2132 | arg = comma; |
| 2133 | } while (arg); |
| 2134 | break; |
| 2135 | } |
| 2136 | |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2137 | case LOPT_AUTHZONE: /* --auth-zone */ |
| 2138 | { |
| 2139 | struct auth_zone *new; |
| 2140 | |
| 2141 | comma = split(arg); |
Simon Kelley | 1e14cc0 | 2012-12-29 17:27:59 +0000 | [diff] [blame] | 2142 | |
Simon Kelley | 429798f | 2012-12-10 20:45:53 +0000 | [diff] [blame] | 2143 | new = opt_malloc(sizeof(struct auth_zone)); |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2144 | new->domain = opt_string_alloc(arg); |
| 2145 | new->subnet = NULL; |
Mathias Kresin | 094bfae | 2016-07-24 14:15:22 +0100 | [diff] [blame] | 2146 | new->exclude = NULL; |
Simon Kelley | 376d48c | 2013-11-13 13:04:30 +0000 | [diff] [blame] | 2147 | new->interface_names = NULL; |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2148 | new->next = daemon->auth_zones; |
| 2149 | daemon->auth_zones = new; |
| 2150 | |
| 2151 | while ((arg = comma)) |
| 2152 | { |
| 2153 | int prefixlen = 0; |
Mathias Kresin | 094bfae | 2016-07-24 14:15:22 +0100 | [diff] [blame] | 2154 | int is_exclude = 0; |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2155 | char *prefix; |
Simon Kelley | 376d48c | 2013-11-13 13:04:30 +0000 | [diff] [blame] | 2156 | struct addrlist *subnet = NULL; |
Simon Kelley | cc921df | 2019-01-02 22:48:59 +0000 | [diff] [blame] | 2157 | union all_addr addr; |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2158 | |
| 2159 | comma = split(arg); |
| 2160 | prefix = split_chr(arg, '/'); |
| 2161 | |
| 2162 | if (prefix && !atoi_check(prefix, &prefixlen)) |
| 2163 | ret_err(gen_err); |
| 2164 | |
Mathias Kresin | 094bfae | 2016-07-24 14:15:22 +0100 | [diff] [blame] | 2165 | if (strstr(arg, "exclude:") == arg) |
| 2166 | { |
| 2167 | is_exclude = 1; |
| 2168 | arg = arg+8; |
| 2169 | } |
| 2170 | |
Simon Kelley | cc921df | 2019-01-02 22:48:59 +0000 | [diff] [blame] | 2171 | if (inet_pton(AF_INET, arg, &addr.addr4)) |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2172 | { |
Simon Kelley | 376d48c | 2013-11-13 13:04:30 +0000 | [diff] [blame] | 2173 | subnet = opt_malloc(sizeof(struct addrlist)); |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2174 | subnet->prefixlen = (prefixlen == 0) ? 24 : prefixlen; |
Simon Kelley | 376d48c | 2013-11-13 13:04:30 +0000 | [diff] [blame] | 2175 | subnet->flags = ADDRLIST_LITERAL; |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2176 | } |
Simon Kelley | cc921df | 2019-01-02 22:48:59 +0000 | [diff] [blame] | 2177 | else if (inet_pton(AF_INET6, arg, &addr.addr6)) |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2178 | { |
Simon Kelley | 376d48c | 2013-11-13 13:04:30 +0000 | [diff] [blame] | 2179 | subnet = opt_malloc(sizeof(struct addrlist)); |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2180 | subnet->prefixlen = (prefixlen == 0) ? 64 : prefixlen; |
Simon Kelley | 376d48c | 2013-11-13 13:04:30 +0000 | [diff] [blame] | 2181 | subnet->flags = ADDRLIST_LITERAL | ADDRLIST_IPV6; |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2182 | } |
Simon Kelley | 376d48c | 2013-11-13 13:04:30 +0000 | [diff] [blame] | 2183 | else |
| 2184 | { |
| 2185 | struct auth_name_list *name = opt_malloc(sizeof(struct auth_name_list)); |
| 2186 | name->name = opt_string_alloc(arg); |
| 2187 | name->flags = AUTH4 | AUTH6; |
| 2188 | name->next = new->interface_names; |
| 2189 | new->interface_names = name; |
| 2190 | if (prefix) |
| 2191 | { |
| 2192 | if (prefixlen == 4) |
| 2193 | name->flags &= ~AUTH6; |
Simon Kelley | 376d48c | 2013-11-13 13:04:30 +0000 | [diff] [blame] | 2194 | else if (prefixlen == 6) |
| 2195 | name->flags &= ~AUTH4; |
Simon Kelley | 376d48c | 2013-11-13 13:04:30 +0000 | [diff] [blame] | 2196 | else |
| 2197 | ret_err(gen_err); |
| 2198 | } |
| 2199 | } |
| 2200 | |
| 2201 | if (subnet) |
| 2202 | { |
| 2203 | subnet->addr = addr; |
Mathias Kresin | 094bfae | 2016-07-24 14:15:22 +0100 | [diff] [blame] | 2204 | |
| 2205 | if (is_exclude) |
| 2206 | { |
| 2207 | subnet->next = new->exclude; |
| 2208 | new->exclude = subnet; |
| 2209 | } |
| 2210 | else |
| 2211 | { |
| 2212 | subnet->next = new->subnet; |
| 2213 | new->subnet = subnet; |
| 2214 | } |
Simon Kelley | 376d48c | 2013-11-13 13:04:30 +0000 | [diff] [blame] | 2215 | } |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2216 | } |
| 2217 | break; |
| 2218 | } |
Simon Kelley | 376d48c | 2013-11-13 13:04:30 +0000 | [diff] [blame] | 2219 | |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2220 | case LOPT_AUTHSOA: /* --auth-soa */ |
| 2221 | comma = split(arg); |
Simon Kelley | 5c72bb9 | 2013-08-19 14:12:59 +0100 | [diff] [blame] | 2222 | daemon->soa_sn = (u32)atoi(arg); |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2223 | if (comma) |
| 2224 | { |
Simon Kelley | 86e3b9a | 2012-11-30 13:46:48 +0000 | [diff] [blame] | 2225 | char *cp; |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2226 | arg = comma; |
| 2227 | comma = split(arg); |
| 2228 | daemon->hostmaster = opt_string_alloc(arg); |
Simon Kelley | 86e3b9a | 2012-11-30 13:46:48 +0000 | [diff] [blame] | 2229 | for (cp = daemon->hostmaster; *cp; cp++) |
| 2230 | if (*cp == '@') |
| 2231 | *cp = '.'; |
| 2232 | |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2233 | if (comma) |
| 2234 | { |
| 2235 | arg = comma; |
| 2236 | comma = split(arg); |
Simon Kelley | 5c72bb9 | 2013-08-19 14:12:59 +0100 | [diff] [blame] | 2237 | daemon->soa_refresh = (u32)atoi(arg); |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2238 | if (comma) |
| 2239 | { |
| 2240 | arg = comma; |
| 2241 | comma = split(arg); |
Simon Kelley | 5c72bb9 | 2013-08-19 14:12:59 +0100 | [diff] [blame] | 2242 | daemon->soa_retry = (u32)atoi(arg); |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2243 | if (comma) |
Simon Kelley | 407a1f3 | 2016-03-01 17:06:07 +0000 | [diff] [blame] | 2244 | daemon->soa_expiry = (u32)atoi(comma); |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2245 | } |
| 2246 | } |
| 2247 | } |
| 2248 | |
| 2249 | break; |
| 2250 | |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 2251 | case 's': /* --domain */ |
| 2252 | case LOPT_SYNTH: /* --synth-domain */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2253 | if (strcmp (arg, "#") == 0) |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 2254 | set_option_bool(OPT_RESOLV_DOMAIN); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2255 | else |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2256 | { |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 2257 | char *d; |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2258 | comma = split(arg); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 2259 | if (!(d = canonicalise_opt(arg))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2260 | ret_err(gen_err); |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2261 | else |
| 2262 | { |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2263 | if (comma) |
| 2264 | { |
Simon Kelley | 429798f | 2012-12-10 20:45:53 +0000 | [diff] [blame] | 2265 | struct cond_domain *new = opt_malloc(sizeof(struct cond_domain)); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 2266 | char *netpart; |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 2267 | |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 2268 | new->prefix = NULL; |
Simon Kelley | 6b2b564 | 2018-03-10 18:12:04 +0000 | [diff] [blame] | 2269 | new->indexed = 0; |
| 2270 | |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2271 | unhide_metas(comma); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 2272 | if ((netpart = split_chr(comma, '/'))) |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2273 | { |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2274 | int msize; |
| 2275 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 2276 | arg = split(netpart); |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2277 | if (!atoi_check(netpart, &msize)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2278 | ret_err_free(gen_err, new); |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2279 | else if (inet_pton(AF_INET, comma, &new->start)) |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2280 | { |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2281 | int mask = (1 << (32 - msize)) - 1; |
| 2282 | new->is6 = 0; |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2283 | new->start.s_addr = ntohl(htonl(new->start.s_addr) & ~mask); |
| 2284 | new->end.s_addr = new->start.s_addr | htonl(mask); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 2285 | if (arg) |
| 2286 | { |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 2287 | if (option != 's') |
Simon Kelley | b5a7ff4 | 2013-04-25 11:03:47 +0100 | [diff] [blame] | 2288 | { |
| 2289 | if (!(new->prefix = canonicalise_opt(arg)) || |
| 2290 | strlen(new->prefix) > MAXLABEL - INET_ADDRSTRLEN) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2291 | ret_err_free(_("bad prefix"), new); |
Simon Kelley | b5a7ff4 | 2013-04-25 11:03:47 +0100 | [diff] [blame] | 2292 | } |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 2293 | else if (strcmp(arg, "local") != 0 || |
| 2294 | (msize != 8 && msize != 16 && msize != 24)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2295 | ret_err_free(gen_err, new); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 2296 | else |
| 2297 | { |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2298 | /* generate the equivalent of |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2299 | local=/xxx.yyy.zzz.in-addr.arpa/ */ |
| 2300 | struct server *serv = add_rev4(new->start, msize); |
Olivier Gayot | dc99058 | 2017-03-06 22:17:21 +0000 | [diff] [blame] | 2301 | if (!serv) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2302 | ret_err_free(_("bad prefix"), new); |
Olivier Gayot | dc99058 | 2017-03-06 22:17:21 +0000 | [diff] [blame] | 2303 | |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2304 | serv->flags |= SERV_NO_ADDR; |
Simon Kelley | 3ad3f3b | 2014-12-16 18:25:17 +0000 | [diff] [blame] | 2305 | |
| 2306 | /* local=/<domain>/ */ |
| 2307 | serv = opt_malloc(sizeof(struct server)); |
| 2308 | memset(serv, 0, sizeof(struct server)); |
| 2309 | serv->domain = d; |
| 2310 | serv->flags = SERV_HAS_DOMAIN | SERV_NO_ADDR; |
| 2311 | serv->next = daemon->servers; |
| 2312 | daemon->servers = serv; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 2313 | } |
| 2314 | } |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2315 | } |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2316 | else if (inet_pton(AF_INET6, comma, &new->start6)) |
| 2317 | { |
| 2318 | u64 mask = (1LLU << (128 - msize)) - 1LLU; |
| 2319 | u64 addrpart = addr6part(&new->start6); |
| 2320 | new->is6 = 1; |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 2321 | |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2322 | /* prefix==64 overflows the mask calculation above */ |
| 2323 | if (msize == 64) |
| 2324 | mask = (u64)-1LL; |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 2325 | |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2326 | new->end6 = new->start6; |
| 2327 | setaddr6part(&new->start6, addrpart & ~mask); |
| 2328 | setaddr6part(&new->end6, addrpart | mask); |
| 2329 | |
| 2330 | if (msize < 64) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2331 | ret_err_free(gen_err, new); |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2332 | else if (arg) |
| 2333 | { |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 2334 | if (option != 's') |
Simon Kelley | b5a7ff4 | 2013-04-25 11:03:47 +0100 | [diff] [blame] | 2335 | { |
| 2336 | if (!(new->prefix = canonicalise_opt(arg)) || |
| 2337 | strlen(new->prefix) > MAXLABEL - INET6_ADDRSTRLEN) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2338 | ret_err_free(_("bad prefix"), new); |
Simon Kelley | b5a7ff4 | 2013-04-25 11:03:47 +0100 | [diff] [blame] | 2339 | } |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 2340 | else if (strcmp(arg, "local") != 0 || ((msize & 4) != 0)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2341 | ret_err_free(gen_err, new); |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2342 | else |
| 2343 | { |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 2344 | /* generate the equivalent of |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 2345 | local=/xxx.yyy.zzz.ip6.arpa/ */ |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2346 | struct server *serv = add_rev6(&new->start6, msize); |
| 2347 | serv->flags |= SERV_NO_ADDR; |
Simon Kelley | 3ad3f3b | 2014-12-16 18:25:17 +0000 | [diff] [blame] | 2348 | |
| 2349 | /* local=/<domain>/ */ |
| 2350 | serv = opt_malloc(sizeof(struct server)); |
| 2351 | memset(serv, 0, sizeof(struct server)); |
| 2352 | serv->domain = d; |
| 2353 | serv->flags = SERV_HAS_DOMAIN | SERV_NO_ADDR; |
| 2354 | serv->next = daemon->servers; |
| 2355 | daemon->servers = serv; |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2356 | } |
| 2357 | } |
| 2358 | } |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2359 | else |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2360 | ret_err_free(gen_err, new); |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2361 | } |
Simon Kelley | eec5c1e | 2013-10-25 10:37:30 +0100 | [diff] [blame] | 2362 | else |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2363 | { |
Simon Kelley | eec5c1e | 2013-10-25 10:37:30 +0100 | [diff] [blame] | 2364 | char *prefstr; |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2365 | arg = split(comma); |
Simon Kelley | eec5c1e | 2013-10-25 10:37:30 +0100 | [diff] [blame] | 2366 | prefstr = split(arg); |
| 2367 | |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2368 | if (inet_pton(AF_INET, comma, &new->start)) |
| 2369 | { |
| 2370 | new->is6 = 0; |
| 2371 | if (!arg) |
| 2372 | new->end.s_addr = new->start.s_addr; |
| 2373 | else if (!inet_pton(AF_INET, arg, &new->end)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2374 | ret_err_free(gen_err, new); |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2375 | } |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2376 | else if (inet_pton(AF_INET6, comma, &new->start6)) |
| 2377 | { |
| 2378 | new->is6 = 1; |
| 2379 | if (!arg) |
| 2380 | memcpy(&new->end6, &new->start6, IN6ADDRSZ); |
| 2381 | else if (!inet_pton(AF_INET6, arg, &new->end6)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2382 | ret_err_free(gen_err, new); |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2383 | } |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2384 | else |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2385 | ret_err_free(gen_err, new); |
Simon Kelley | eec5c1e | 2013-10-25 10:37:30 +0100 | [diff] [blame] | 2386 | |
| 2387 | if (option != 's' && prefstr) |
| 2388 | { |
| 2389 | if (!(new->prefix = canonicalise_opt(prefstr)) || |
| 2390 | strlen(new->prefix) > MAXLABEL - INET_ADDRSTRLEN) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2391 | ret_err_free(_("bad prefix"), new); |
Simon Kelley | eec5c1e | 2013-10-25 10:37:30 +0100 | [diff] [blame] | 2392 | } |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 2393 | } |
Simon Kelley | 2307eac | 2012-02-13 10:13:13 +0000 | [diff] [blame] | 2394 | |
| 2395 | new->domain = d; |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 2396 | if (option == 's') |
| 2397 | { |
| 2398 | new->next = daemon->cond_domain; |
| 2399 | daemon->cond_domain = new; |
| 2400 | } |
| 2401 | else |
| 2402 | { |
Simon Kelley | 6b2b564 | 2018-03-10 18:12:04 +0000 | [diff] [blame] | 2403 | char *star; |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 2404 | new->next = daemon->synth_domains; |
| 2405 | daemon->synth_domains = new; |
Simon Kelley | dd33e98 | 2018-07-30 14:55:39 +0100 | [diff] [blame] | 2406 | if (new->prefix && |
| 2407 | (star = strrchr(new->prefix, '*')) |
| 2408 | && *(star+1) == 0) |
Simon Kelley | 6b2b564 | 2018-03-10 18:12:04 +0000 | [diff] [blame] | 2409 | { |
| 2410 | *star = 0; |
| 2411 | new->indexed = 1; |
| 2412 | } |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 2413 | } |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2414 | } |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 2415 | else if (option == 's') |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2416 | daemon->domain_suffix = d; |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 2417 | else |
| 2418 | ret_err(gen_err); |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2419 | } |
| 2420 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2421 | break; |
| 2422 | |
Simon Kelley | 1e50512 | 2016-01-25 21:29:23 +0000 | [diff] [blame] | 2423 | case LOPT_CPE_ID: /* --add-dns-client */ |
| 2424 | if (arg) |
Simon Kelley | 33702ab | 2015-12-28 23:17:15 +0000 | [diff] [blame] | 2425 | daemon->dns_client_id = opt_string_alloc(arg); |
| 2426 | break; |
| 2427 | |
Simon Kelley | c7f3bd2 | 2016-02-28 21:48:34 +0000 | [diff] [blame] | 2428 | case LOPT_ADD_MAC: /* --add-mac */ |
Simon Kelley | 1e50512 | 2016-01-25 21:29:23 +0000 | [diff] [blame] | 2429 | if (!arg) |
| 2430 | set_option_bool(OPT_ADD_MAC); |
| 2431 | else |
| 2432 | { |
| 2433 | unhide_metas(arg); |
| 2434 | if (strcmp(arg, "base64") == 0) |
| 2435 | set_option_bool(OPT_MAC_B64); |
Simon Kelley | 9e4cf47 | 2016-02-17 20:26:32 +0000 | [diff] [blame] | 2436 | else if (strcmp(arg, "text") == 0) |
| 2437 | set_option_bool(OPT_MAC_HEX); |
Simon Kelley | 22c0f4f | 2016-02-17 22:12:31 +0000 | [diff] [blame] | 2438 | else |
| 2439 | ret_err(gen_err); |
Simon Kelley | 1e50512 | 2016-01-25 21:29:23 +0000 | [diff] [blame] | 2440 | } |
| 2441 | break; |
| 2442 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2443 | case 'u': /* --user */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2444 | daemon->username = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2445 | break; |
| 2446 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2447 | case 'g': /* --group */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2448 | daemon->groupname = opt_string_alloc(arg); |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 2449 | daemon->group_set = 1; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2450 | break; |
Simon Kelley | 9e03894 | 2008-05-30 20:06:34 +0100 | [diff] [blame] | 2451 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2452 | #ifdef HAVE_DHCP |
Simon Kelley | 9e03894 | 2008-05-30 20:06:34 +0100 | [diff] [blame] | 2453 | case LOPT_SCRIPTUSR: /* --scriptuser */ |
| 2454 | daemon->scriptuser = opt_string_alloc(arg); |
| 2455 | break; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2456 | #endif |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2457 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2458 | case 'i': /* --interface */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2459 | do { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2460 | struct iname *new = opt_malloc(sizeof(struct iname)); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2461 | comma = split(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2462 | new->next = daemon->if_names; |
| 2463 | daemon->if_names = new; |
| 2464 | /* new->name may be NULL if someone does |
| 2465 | "interface=" to disable all interfaces except loop. */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2466 | new->name = opt_string_alloc(arg); |
Simon Kelley | 4ce4f37 | 2012-06-14 11:50:45 +0100 | [diff] [blame] | 2467 | new->used = 0; |
Tarun Kundu | 024baf1 | 2022-06-28 10:56:47 -0700 | [diff] [blame] | 2468 | new->is_ra_adv_dis = false; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2469 | arg = comma; |
| 2470 | } while (arg); |
| 2471 | break; |
Tarun Kundu | 024baf1 | 2022-06-28 10:56:47 -0700 | [diff] [blame] | 2472 | |
| 2473 | case LOPT_RA_ADV_DISABLE: ; /* --ra-adv-disable */ |
| 2474 | struct iname *tmp; |
| 2475 | do { |
| 2476 | comma = split(arg); |
| 2477 | for (tmp = daemon->if_names; tmp; tmp = tmp->next) |
| 2478 | { |
| 2479 | if (strcmp(tmp->name, arg) == 0) { |
| 2480 | tmp->is_ra_adv_dis = true; |
| 2481 | } |
| 2482 | } |
| 2483 | arg = comma; |
| 2484 | } while (arg); |
| 2485 | break; |
| 2486 | |
Simon Kelley | 2937f8a | 2013-07-29 19:49:07 +0100 | [diff] [blame] | 2487 | case LOPT_TFTP: /* --enable-tftp */ |
| 2488 | set_option_bool(OPT_TFTP); |
| 2489 | if (!arg) |
| 2490 | break; |
| 2491 | /* fall through */ |
| 2492 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2493 | case 'I': /* --except-interface */ |
| 2494 | case '2': /* --no-dhcp-interface */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2495 | do { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2496 | struct iname *new = opt_malloc(sizeof(struct iname)); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2497 | comma = split(arg); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2498 | new->name = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2499 | if (option == 'I') |
| 2500 | { |
| 2501 | new->next = daemon->if_except; |
| 2502 | daemon->if_except = new; |
| 2503 | } |
Simon Kelley | 2937f8a | 2013-07-29 19:49:07 +0100 | [diff] [blame] | 2504 | else if (option == LOPT_TFTP) |
| 2505 | { |
| 2506 | new->next = daemon->tftp_interfaces; |
| 2507 | daemon->tftp_interfaces = new; |
| 2508 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2509 | else |
| 2510 | { |
| 2511 | new->next = daemon->dhcp_except; |
| 2512 | daemon->dhcp_except = new; |
| 2513 | } |
| 2514 | arg = comma; |
| 2515 | } while (arg); |
| 2516 | break; |
| 2517 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2518 | case 'B': /* --bogus-nxdomain */ |
Glen Huang | 32fc6db | 2014-12-27 15:28:12 +0000 | [diff] [blame] | 2519 | case LOPT_IGNORE_ADDR: /* --ignore-address */ |
| 2520 | { |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2521 | struct in_addr addr; |
Simon Kelley | 9eaa91b | 2021-03-17 20:31:06 +0000 | [diff] [blame] | 2522 | int prefix = 32; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2523 | unhide_metas(arg); |
Simon Kelley | 9eaa91b | 2021-03-17 20:31:06 +0000 | [diff] [blame] | 2524 | |
| 2525 | if (!arg || |
| 2526 | ((comma = split_chr(arg, '/')) && !atoi_check(comma, &prefix)) || |
| 2527 | (inet_pton(AF_INET, arg, &addr) != 1)) |
| 2528 | ret_err(gen_err); /* error */ |
| 2529 | else |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2530 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2531 | struct bogus_addr *baddr = opt_malloc(sizeof(struct bogus_addr)); |
Glen Huang | 32fc6db | 2014-12-27 15:28:12 +0000 | [diff] [blame] | 2532 | if (option == 'B') |
| 2533 | { |
| 2534 | baddr->next = daemon->bogus_addr; |
| 2535 | daemon->bogus_addr = baddr; |
| 2536 | } |
| 2537 | else |
| 2538 | { |
| 2539 | baddr->next = daemon->ignore_addr; |
| 2540 | daemon->ignore_addr = baddr; |
| 2541 | } |
Simon Kelley | 9eaa91b | 2021-03-17 20:31:06 +0000 | [diff] [blame] | 2542 | baddr->mask.s_addr = htonl(~((1 << (32 - prefix)) - 1)); |
| 2543 | baddr->addr.s_addr = addr.s_addr & baddr->mask.s_addr; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2544 | } |
Simon Kelley | 9eaa91b | 2021-03-17 20:31:06 +0000 | [diff] [blame] | 2545 | break; |
| 2546 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2547 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2548 | case 'a': /* --listen-address */ |
Simon Kelley | 4967876 | 2012-12-09 18:24:58 +0000 | [diff] [blame] | 2549 | case LOPT_AUTHPEER: /* --auth-peer */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2550 | do { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2551 | struct iname *new = opt_malloc(sizeof(struct iname)); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2552 | comma = split(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2553 | unhide_metas(arg); |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 2554 | 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] | 2555 | { |
| 2556 | new->addr.sa.sa_family = AF_INET; |
Simon Kelley | 4967876 | 2012-12-09 18:24:58 +0000 | [diff] [blame] | 2557 | new->addr.in.sin_port = 0; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2558 | #ifdef HAVE_SOCKADDR_SA_LEN |
| 2559 | new->addr.in.sin_len = sizeof(new->addr.in); |
| 2560 | #endif |
| 2561 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2562 | else if (arg && inet_pton(AF_INET6, arg, &new->addr.in6.sin6_addr) > 0) |
| 2563 | { |
| 2564 | new->addr.sa.sa_family = AF_INET6; |
| 2565 | new->addr.in6.sin6_flowinfo = 0; |
| 2566 | new->addr.in6.sin6_scope_id = 0; |
Simon Kelley | 4967876 | 2012-12-09 18:24:58 +0000 | [diff] [blame] | 2567 | new->addr.in6.sin6_port = 0; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2568 | #ifdef HAVE_SOCKADDR_SA_LEN |
| 2569 | new->addr.in6.sin6_len = sizeof(new->addr.in6); |
| 2570 | #endif |
| 2571 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2572 | else |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2573 | ret_err_free(gen_err, new); |
Simon Kelley | 4ce4f37 | 2012-06-14 11:50:45 +0100 | [diff] [blame] | 2574 | |
| 2575 | new->used = 0; |
Simon Kelley | 4967876 | 2012-12-09 18:24:58 +0000 | [diff] [blame] | 2576 | if (option == 'a') |
| 2577 | { |
| 2578 | new->next = daemon->if_addrs; |
| 2579 | daemon->if_addrs = new; |
| 2580 | } |
| 2581 | else |
| 2582 | { |
| 2583 | new->next = daemon->auth_peers; |
| 2584 | daemon->auth_peers = new; |
| 2585 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2586 | arg = comma; |
| 2587 | } while (arg); |
| 2588 | break; |
| 2589 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2590 | case 'S': /* --server */ |
| 2591 | case LOPT_LOCAL: /* --local */ |
| 2592 | case 'A': /* --address */ |
| 2593 | case LOPT_NO_REBIND: /* --rebind-domain-ok */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2594 | { |
| 2595 | struct server *serv, *newlist = NULL; |
| 2596 | |
| 2597 | unhide_metas(arg); |
| 2598 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2599 | if (arg && (*arg == '/' || option == LOPT_NO_REBIND)) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2600 | { |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2601 | int rebind = !(*arg == '/'); |
| 2602 | char *end = NULL; |
| 2603 | if (!rebind) |
| 2604 | arg++; |
| 2605 | while (rebind || (end = split_chr(arg, '/'))) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2606 | { |
| 2607 | char *domain = NULL; |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2608 | /* elide leading dots - they are implied in the search algorithm */ |
| 2609 | while (*arg == '.') arg++; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2610 | /* # matches everything and becomes a zero length domain string */ |
| 2611 | if (strcmp(arg, "#") == 0) |
| 2612 | domain = ""; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 2613 | else if (strlen (arg) != 0 && !(domain = canonicalise_opt(arg))) |
Simon Kelley | a3bd7e7 | 2018-07-19 22:00:08 +0100 | [diff] [blame] | 2614 | ret_err(gen_err); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2615 | serv = opt_malloc(sizeof(struct server)); |
| 2616 | memset(serv, 0, sizeof(struct server)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2617 | serv->next = newlist; |
| 2618 | newlist = serv; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2619 | serv->domain = domain; |
| 2620 | serv->flags = domain ? SERV_HAS_DOMAIN : SERV_FOR_NODOTS; |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 2621 | arg = end; |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2622 | if (rebind) |
| 2623 | break; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2624 | } |
| 2625 | if (!newlist) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2626 | ret_err(gen_err); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2627 | } |
| 2628 | else |
| 2629 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2630 | newlist = opt_malloc(sizeof(struct server)); |
| 2631 | memset(newlist, 0, sizeof(struct server)); |
Simon Kelley | b5ea1cc | 2014-07-29 16:34:14 +0100 | [diff] [blame] | 2632 | #ifdef HAVE_LOOP |
| 2633 | newlist->uid = rand32(); |
| 2634 | #endif |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2635 | } |
| 2636 | |
Simon Kelley | 7b1eae4 | 2014-02-20 13:43:28 +0000 | [diff] [blame] | 2637 | if (servers_only && option == 'S') |
| 2638 | newlist->flags |= SERV_FROM_FILE; |
| 2639 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2640 | if (option == 'A') |
| 2641 | { |
| 2642 | newlist->flags |= SERV_LITERAL_ADDRESS; |
| 2643 | if (!(newlist->flags & SERV_TYPE)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2644 | { |
| 2645 | server_list_free(newlist); |
| 2646 | ret_err(gen_err); |
| 2647 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2648 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2649 | else if (option == LOPT_NO_REBIND) |
| 2650 | newlist->flags |= SERV_NO_REBIND; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2651 | |
| 2652 | if (!arg || !*arg) |
| 2653 | { |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2654 | if (!(newlist->flags & SERV_NO_REBIND)) |
| 2655 | newlist->flags |= SERV_NO_ADDR; /* no server */ |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2656 | } |
| 2657 | |
| 2658 | else if (strcmp(arg, "#") == 0) |
Simon Kelley | da8b651 | 2018-09-03 23:18:36 +0100 | [diff] [blame] | 2659 | newlist->flags |= SERV_USE_RESOLV; /* treat in ordinary way */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2660 | else |
| 2661 | { |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 2662 | char *err = parse_server(arg, &newlist->addr, &newlist->source_addr, newlist->interface, &newlist->flags); |
| 2663 | if (err) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 2664 | { |
| 2665 | server_list_free(newlist); |
| 2666 | ret_err(err); |
| 2667 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2668 | } |
| 2669 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2670 | serv = newlist; |
| 2671 | while (serv->next) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2672 | { |
Simon Kelley | d9603ef | 2020-01-26 18:13:35 +0000 | [diff] [blame] | 2673 | serv->next->flags |= serv->flags & ~(SERV_HAS_DOMAIN | SERV_FOR_NODOTS); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2674 | serv->next->addr = serv->addr; |
| 2675 | serv->next->source_addr = serv->source_addr; |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 2676 | strcpy(serv->next->interface, serv->interface); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2677 | serv = serv->next; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2678 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2679 | serv->next = daemon->servers; |
| 2680 | daemon->servers = newlist; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2681 | break; |
| 2682 | } |
Jason A. Donenfeld | 13d86c7 | 2013-02-22 18:20:53 +0000 | [diff] [blame] | 2683 | |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2684 | case LOPT_REV_SERV: /* --rev-server */ |
| 2685 | { |
| 2686 | char *string; |
| 2687 | int size; |
| 2688 | struct server *serv; |
| 2689 | struct in_addr addr4; |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2690 | struct in6_addr addr6; |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2691 | |
| 2692 | unhide_metas(arg); |
Simon Kelley | a9b022a | 2020-02-11 21:58:59 +0000 | [diff] [blame] | 2693 | if (!arg) |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2694 | ret_err(gen_err); |
Simon Kelley | a9b022a | 2020-02-11 21:58:59 +0000 | [diff] [blame] | 2695 | |
| 2696 | comma=split(arg); |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2697 | |
Simon Kelley | a9b022a | 2020-02-11 21:58:59 +0000 | [diff] [blame] | 2698 | if (!(string = split_chr(arg, '/')) || !atoi_check(string, &size)) |
| 2699 | ret_err(gen_err); |
| 2700 | |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2701 | if (inet_pton(AF_INET, arg, &addr4)) |
Olivier Gayot | dc99058 | 2017-03-06 22:17:21 +0000 | [diff] [blame] | 2702 | { |
| 2703 | serv = add_rev4(addr4, size); |
| 2704 | if (!serv) |
| 2705 | ret_err(_("bad prefix")); |
| 2706 | } |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2707 | else if (inet_pton(AF_INET6, arg, &addr6)) |
| 2708 | serv = add_rev6(&addr6, size); |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2709 | else |
| 2710 | ret_err(gen_err); |
| 2711 | |
| 2712 | string = parse_server(comma, &serv->addr, &serv->source_addr, serv->interface, &serv->flags); |
| 2713 | |
| 2714 | if (string) |
| 2715 | ret_err(string); |
Simon Kelley | 7b1eae4 | 2014-02-20 13:43:28 +0000 | [diff] [blame] | 2716 | |
| 2717 | if (servers_only) |
| 2718 | serv->flags |= SERV_FROM_FILE; |
| 2719 | |
Simon Kelley | de73a49 | 2014-02-17 21:43:27 +0000 | [diff] [blame] | 2720 | break; |
| 2721 | } |
| 2722 | |
Jason A. Donenfeld | 13d86c7 | 2013-02-22 18:20:53 +0000 | [diff] [blame] | 2723 | case LOPT_IPSET: /* --ipset */ |
| 2724 | #ifndef HAVE_IPSET |
| 2725 | ret_err(_("recompile with HAVE_IPSET defined to enable ipset directives")); |
| 2726 | break; |
| 2727 | #else |
| 2728 | { |
| 2729 | struct ipsets ipsets_head; |
| 2730 | struct ipsets *ipsets = &ipsets_head; |
| 2731 | int size; |
| 2732 | char *end; |
| 2733 | char **sets, **sets_pos; |
| 2734 | memset(ipsets, 0, sizeof(struct ipsets)); |
| 2735 | unhide_metas(arg); |
| 2736 | if (arg && *arg == '/') |
| 2737 | { |
| 2738 | arg++; |
| 2739 | while ((end = split_chr(arg, '/'))) |
| 2740 | { |
| 2741 | char *domain = NULL; |
| 2742 | /* elide leading dots - they are implied in the search algorithm */ |
| 2743 | while (*arg == '.') |
| 2744 | arg++; |
| 2745 | /* # matches everything and becomes a zero length domain string */ |
| 2746 | if (strcmp(arg, "#") == 0 || !*arg) |
| 2747 | domain = ""; |
| 2748 | else if (strlen(arg) != 0 && !(domain = canonicalise_opt(arg))) |
Simon Kelley | a3bd7e7 | 2018-07-19 22:00:08 +0100 | [diff] [blame] | 2749 | ret_err(gen_err); |
Jason A. Donenfeld | 13d86c7 | 2013-02-22 18:20:53 +0000 | [diff] [blame] | 2750 | ipsets->next = opt_malloc(sizeof(struct ipsets)); |
| 2751 | ipsets = ipsets->next; |
| 2752 | memset(ipsets, 0, sizeof(struct ipsets)); |
| 2753 | ipsets->domain = domain; |
| 2754 | arg = end; |
| 2755 | } |
| 2756 | } |
| 2757 | else |
| 2758 | { |
| 2759 | ipsets->next = opt_malloc(sizeof(struct ipsets)); |
| 2760 | ipsets = ipsets->next; |
| 2761 | memset(ipsets, 0, sizeof(struct ipsets)); |
| 2762 | ipsets->domain = ""; |
| 2763 | } |
Simon Kelley | a3bd7e7 | 2018-07-19 22:00:08 +0100 | [diff] [blame] | 2764 | |
Jason A. Donenfeld | 13d86c7 | 2013-02-22 18:20:53 +0000 | [diff] [blame] | 2765 | if (!arg || !*arg) |
Simon Kelley | a3bd7e7 | 2018-07-19 22:00:08 +0100 | [diff] [blame] | 2766 | ret_err(gen_err); |
| 2767 | |
| 2768 | for (size = 2, end = arg; *end; ++end) |
Jason A. Donenfeld | 13d86c7 | 2013-02-22 18:20:53 +0000 | [diff] [blame] | 2769 | if (*end == ',') |
| 2770 | ++size; |
| 2771 | |
| 2772 | sets = sets_pos = opt_malloc(sizeof(char *) * size); |
| 2773 | |
| 2774 | do { |
| 2775 | end = split(arg); |
| 2776 | *sets_pos++ = opt_string_alloc(arg); |
| 2777 | arg = end; |
| 2778 | } while (end); |
| 2779 | *sets_pos = 0; |
| 2780 | for (ipsets = &ipsets_head; ipsets->next; ipsets = ipsets->next) |
| 2781 | ipsets->next->sets = sets; |
| 2782 | ipsets->next = daemon->ipsets; |
| 2783 | daemon->ipsets = ipsets_head.next; |
| 2784 | |
| 2785 | break; |
| 2786 | } |
| 2787 | #endif |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2788 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2789 | case 'c': /* --cache-size */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2790 | { |
| 2791 | int size; |
| 2792 | |
| 2793 | if (!atoi_check(arg, &size)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2794 | ret_err(gen_err); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2795 | else |
| 2796 | { |
| 2797 | /* zero is OK, and means no caching. */ |
| 2798 | |
| 2799 | if (size < 0) |
| 2800 | size = 0; |
Simon Kelley | 248efe8 | 2019-08-20 23:36:49 +0100 | [diff] [blame] | 2801 | |
| 2802 | /* Note that for very large cache sizes, the malloc() |
| 2803 | will overflow. For the size of the cache record |
| 2804 | at the time this was noted, the value of "very large" |
| 2805 | was 46684428. Limit to an order of magnitude less than |
| 2806 | that to be safe from changes to the cache record. */ |
| 2807 | if (size > 5000000) |
| 2808 | size = 5000000; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2809 | |
| 2810 | daemon->cachesize = size; |
| 2811 | } |
| 2812 | break; |
| 2813 | } |
| 2814 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2815 | case 'p': /* --port */ |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 2816 | if (!atoi_check16(arg, &daemon->port)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2817 | ret_err(gen_err); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2818 | break; |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 2819 | |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 2820 | case LOPT_MINPORT: /* --min-port */ |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 2821 | if (!atoi_check16(arg, &daemon->min_port)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2822 | ret_err(gen_err); |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 2823 | break; |
| 2824 | |
Hans Dedecker | 926332a | 2016-01-23 10:48:12 +0000 | [diff] [blame] | 2825 | case LOPT_MAXPORT: /* --max-port */ |
| 2826 | if (!atoi_check16(arg, &daemon->max_port)) |
| 2827 | ret_err(gen_err); |
| 2828 | break; |
| 2829 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2830 | case '0': /* --dns-forward-max */ |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 2831 | if (!atoi_check(arg, &daemon->ftabsize)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2832 | ret_err(gen_err); |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 2833 | break; |
| 2834 | |
Simon Kelley | 25cf5e3 | 2015-01-09 15:53:03 +0000 | [diff] [blame] | 2835 | case 'q': /* --log-queries */ |
| 2836 | set_option_bool(OPT_LOG); |
| 2837 | if (arg && strcmp(arg, "extra") == 0) |
| 2838 | set_option_bool(OPT_EXTRALOG); |
| 2839 | break; |
| 2840 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2841 | case LOPT_MAX_LOGS: /* --log-async */ |
| 2842 | daemon->max_logs = LOG_MAX; /* default */ |
| 2843 | if (arg && !atoi_check(arg, &daemon->max_logs)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2844 | ret_err(gen_err); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2845 | else if (daemon->max_logs > 100) |
| 2846 | daemon->max_logs = 100; |
| 2847 | break; |
| 2848 | |
| 2849 | case 'P': /* --edns-packet-max */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2850 | { |
| 2851 | int i; |
| 2852 | if (!atoi_check(arg, &i)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2853 | ret_err(gen_err); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2854 | daemon->edns_pktsz = (unsigned short)i; |
| 2855 | break; |
| 2856 | } |
| 2857 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2858 | case 'Q': /* --query-port */ |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 2859 | if (!atoi_check16(arg, &daemon->query_port)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2860 | ret_err(gen_err); |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 2861 | /* if explicitly set to zero, use single OS ephemeral port |
| 2862 | and disable random ports */ |
| 2863 | if (daemon->query_port == 0) |
| 2864 | daemon->osport = 1; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2865 | break; |
| 2866 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2867 | case 'T': /* --local-ttl */ |
| 2868 | case LOPT_NEGTTL: /* --neg-ttl */ |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2869 | case LOPT_MAXTTL: /* --max-ttl */ |
RinSatsuki | 28de387 | 2015-01-10 15:22:21 +0000 | [diff] [blame] | 2870 | case LOPT_MINCTTL: /* --min-cache-ttl */ |
Simon Kelley | 1d86041 | 2012-09-20 20:48:04 +0100 | [diff] [blame] | 2871 | case LOPT_MAXCTTL: /* --max-cache-ttl */ |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2872 | case LOPT_AUTHTTL: /* --auth-ttl */ |
Simon Kelley | 832e47b | 2016-02-24 21:24:45 +0000 | [diff] [blame] | 2873 | case LOPT_DHCPTTL: /* --dhcp-ttl */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2874 | { |
| 2875 | int ttl; |
| 2876 | if (!atoi_check(arg, &ttl)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2877 | ret_err(gen_err); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2878 | else if (option == LOPT_NEGTTL) |
| 2879 | daemon->neg_ttl = (unsigned long)ttl; |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2880 | else if (option == LOPT_MAXTTL) |
| 2881 | daemon->max_ttl = (unsigned long)ttl; |
RinSatsuki | 28de387 | 2015-01-10 15:22:21 +0000 | [diff] [blame] | 2882 | else if (option == LOPT_MINCTTL) |
| 2883 | { |
| 2884 | if (ttl > TTL_FLOOR_LIMIT) |
| 2885 | ttl = TTL_FLOOR_LIMIT; |
| 2886 | daemon->min_cache_ttl = (unsigned long)ttl; |
| 2887 | } |
Simon Kelley | 1d86041 | 2012-09-20 20:48:04 +0100 | [diff] [blame] | 2888 | else if (option == LOPT_MAXCTTL) |
| 2889 | daemon->max_cache_ttl = (unsigned long)ttl; |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2890 | else if (option == LOPT_AUTHTTL) |
| 2891 | daemon->auth_ttl = (unsigned long)ttl; |
Simon Kelley | 832e47b | 2016-02-24 21:24:45 +0000 | [diff] [blame] | 2892 | else if (option == LOPT_DHCPTTL) |
| 2893 | { |
| 2894 | daemon->dhcp_ttl = (unsigned long)ttl; |
| 2895 | daemon->use_dhcp_ttl = 1; |
| 2896 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2897 | else |
| 2898 | daemon->local_ttl = (unsigned long)ttl; |
| 2899 | break; |
| 2900 | } |
| 2901 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2902 | #ifdef HAVE_DHCP |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2903 | case 'X': /* --dhcp-lease-max */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2904 | if (!atoi_check(arg, &daemon->dhcp_max)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2905 | ret_err(gen_err); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2906 | break; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2907 | #endif |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2908 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2909 | #ifdef HAVE_TFTP |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2910 | case LOPT_TFTP_MAX: /* --tftp-max */ |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2911 | if (!atoi_check(arg, &daemon->tftp_max)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2912 | ret_err(gen_err); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2913 | break; |
| 2914 | |
Simon Kelley | bec366b | 2016-02-24 22:03:26 +0000 | [diff] [blame] | 2915 | case LOPT_TFTP_MTU: /* --tftp-mtu */ |
| 2916 | if (!atoi_check(arg, &daemon->tftp_mtu)) |
| 2917 | ret_err(gen_err); |
| 2918 | break; |
| 2919 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2920 | case LOPT_PREFIX: /* --tftp-prefix */ |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2921 | comma = split(arg); |
| 2922 | if (comma) |
| 2923 | { |
| 2924 | struct tftp_prefix *new = opt_malloc(sizeof(struct tftp_prefix)); |
| 2925 | new->interface = opt_string_alloc(comma); |
| 2926 | new->prefix = opt_string_alloc(arg); |
| 2927 | new->next = daemon->if_prefix; |
| 2928 | daemon->if_prefix = new; |
| 2929 | } |
| 2930 | else |
| 2931 | daemon->tftp_prefix = opt_string_alloc(arg); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2932 | break; |
| 2933 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2934 | case LOPT_TFTPPORTS: /* --tftp-port-range */ |
| 2935 | if (!(comma = split(arg)) || |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 2936 | !atoi_check16(arg, &daemon->start_tftp_port) || |
| 2937 | !atoi_check16(comma, &daemon->end_tftp_port)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2938 | ret_err(_("bad port range")); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2939 | |
| 2940 | if (daemon->start_tftp_port > daemon->end_tftp_port) |
| 2941 | { |
| 2942 | int tmp = daemon->start_tftp_port; |
| 2943 | daemon->start_tftp_port = daemon->end_tftp_port; |
| 2944 | daemon->end_tftp_port = tmp; |
| 2945 | } |
| 2946 | |
| 2947 | break; |
Floris Bos | 60704f5 | 2017-04-09 22:22:49 +0100 | [diff] [blame] | 2948 | |
| 2949 | case LOPT_APREF: /* --tftp-unique-root */ |
| 2950 | if (!arg || strcasecmp(arg, "ip") == 0) |
| 2951 | set_option_bool(OPT_TFTP_APREF_IP); |
| 2952 | else if (strcasecmp(arg, "mac") == 0) |
| 2953 | set_option_bool(OPT_TFTP_APREF_MAC); |
| 2954 | else |
| 2955 | ret_err(gen_err); |
| 2956 | break; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2957 | #endif |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2958 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2959 | case LOPT_BRIDGE: /* --bridge-interface */ |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2960 | { |
Simon Kelley | 22cd860 | 2018-01-14 22:57:14 +0000 | [diff] [blame] | 2961 | struct dhcp_bridge *new; |
| 2962 | |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 2963 | if (!(comma = split(arg)) || strlen(arg) > IF_NAMESIZE - 1 ) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2964 | ret_err(_("bad bridge-interface")); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2965 | |
Simon Kelley | 22cd860 | 2018-01-14 22:57:14 +0000 | [diff] [blame] | 2966 | for (new = daemon->bridges; new; new = new->next) |
| 2967 | if (strcmp(new->iface, arg) == 0) |
| 2968 | break; |
| 2969 | |
| 2970 | if (!new) |
| 2971 | { |
| 2972 | new = opt_malloc(sizeof(struct dhcp_bridge)); |
| 2973 | strcpy(new->iface, arg); |
| 2974 | new->alias = NULL; |
| 2975 | new->next = daemon->bridges; |
| 2976 | daemon->bridges = new; |
| 2977 | } |
| 2978 | |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2979 | do { |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2980 | arg = comma; |
| 2981 | comma = split(arg); |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 2982 | if (strlen(arg) != 0 && strlen(arg) <= IF_NAMESIZE - 1) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2983 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2984 | struct dhcp_bridge *b = opt_malloc(sizeof(struct dhcp_bridge)); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2985 | b->next = new->alias; |
| 2986 | new->alias = b; |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 2987 | strcpy(b->iface, arg); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2988 | } |
| 2989 | } while (comma); |
| 2990 | |
| 2991 | break; |
| 2992 | } |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2993 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2994 | #ifdef HAVE_DHCP |
Simon Kelley | ae5b7e0 | 2019-03-27 22:33:28 +0000 | [diff] [blame] | 2995 | case LOPT_SHARED_NET: /* --shared-network */ |
| 2996 | { |
| 2997 | struct shared_network *new = opt_malloc(sizeof(struct shared_network)); |
| 2998 | |
| 2999 | #ifdef HAVE_DHCP6 |
| 3000 | new->shared_addr.s_addr = 0; |
| 3001 | #endif |
| 3002 | new->if_index = 0; |
| 3003 | |
| 3004 | if (!(comma = split(arg))) |
| 3005 | { |
| 3006 | snerr: |
| 3007 | free(new); |
| 3008 | ret_err(_("bad shared-network")); |
| 3009 | } |
| 3010 | |
| 3011 | if (inet_pton(AF_INET, comma, &new->shared_addr)) |
| 3012 | { |
| 3013 | if (!inet_pton(AF_INET, arg, &new->match_addr) && |
| 3014 | !(new->if_index = if_nametoindex(arg))) |
| 3015 | goto snerr; |
| 3016 | } |
| 3017 | #ifdef HAVE_DHCP6 |
| 3018 | else if (inet_pton(AF_INET6, comma, &new->shared_addr6)) |
| 3019 | { |
| 3020 | if (!inet_pton(AF_INET6, arg, &new->match_addr6) && |
| 3021 | !(new->if_index = if_nametoindex(arg))) |
| 3022 | goto snerr; |
| 3023 | } |
| 3024 | #endif |
| 3025 | else |
| 3026 | goto snerr; |
| 3027 | |
| 3028 | new->next = daemon->shared_networks; |
| 3029 | daemon->shared_networks = new; |
| 3030 | break; |
| 3031 | } |
| 3032 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3033 | case 'F': /* --dhcp-range */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3034 | { |
| 3035 | int k, leasepos = 2; |
Kyle Swenson | 9d23807 | 2021-12-01 08:13:17 -0700 | [diff] [blame] | 3036 | char *cp, *a[9] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3037 | struct dhcp_context *new = opt_malloc(sizeof(struct dhcp_context)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3038 | |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3039 | memset (new, 0, sizeof(*new)); |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3040 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3041 | while(1) |
| 3042 | { |
| 3043 | for (cp = arg; *cp; cp++) |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3044 | if (!(*cp == ' ' || *cp == '.' || *cp == ':' || |
| 3045 | (*cp >= 'a' && *cp <= 'f') || (*cp >= 'A' && *cp <= 'F') || |
| 3046 | (*cp >='0' && *cp <= '9'))) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3047 | break; |
| 3048 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3049 | if (*cp != ',' && (comma = split(arg))) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3050 | { |
Kyle Swenson | 545712c | 2021-11-17 12:25:04 -0700 | [diff] [blame] | 3051 | /* CRADLEPOINT */ |
| 3052 | if (strstr(arg, "forcedinterface:") == arg) |
| 3053 | new->forcedinterface = opt_string_alloc(arg+16); |
| 3054 | else if (strstr(arg, "forcedaddress:") == arg) |
| 3055 | new->forcedaddress.s_addr = inet_addr(arg+14); |
| 3056 | else if (is_tag_prefix(arg)) |
| 3057 | /* CRADLEPOINT */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3058 | { |
Simon Kelley | 0c38719 | 2013-09-05 10:21:12 +0100 | [diff] [blame] | 3059 | /* ignore empty tag */ |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3060 | if (arg[4]) |
| 3061 | new->filter = dhcp_netid_create(arg+4, new->filter); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3062 | } |
| 3063 | else |
| 3064 | { |
| 3065 | if (new->netid.net) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3066 | { |
| 3067 | dhcp_context_free(new); |
| 3068 | ret_err(_("only one tag allowed")); |
| 3069 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3070 | else |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3071 | new->netid.net = opt_string_alloc(set_prefix(arg)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3072 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3073 | arg = comma; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3074 | } |
| 3075 | else |
| 3076 | { |
| 3077 | a[0] = arg; |
| 3078 | break; |
| 3079 | } |
| 3080 | } |
| 3081 | |
Kyle Swenson | 9d23807 | 2021-12-01 08:13:17 -0700 | [diff] [blame] | 3082 | for (k = 1; k < 9; k++) |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3083 | if (!(a[k] = split(a[k-1]))) |
| 3084 | break; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3085 | |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3086 | if (k < 2) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3087 | { |
| 3088 | dhcp_context_free(new); |
| 3089 | ret_err(_("bad dhcp-range")); |
| 3090 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3091 | |
| 3092 | if (inet_pton(AF_INET, a[0], &new->start)) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3093 | { |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3094 | new->next = daemon->dhcp; |
Simon Kelley | 4d85e40 | 2020-07-12 22:45:46 +0100 | [diff] [blame] | 3095 | new->lease_time = DEFLEASE; |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3096 | daemon->dhcp = new; |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3097 | new->end = new->start; |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3098 | if (strcmp(a[1], "static") == 0) |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3099 | new->flags |= CONTEXT_STATIC; |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3100 | else if (strcmp(a[1], "proxy") == 0) |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3101 | new->flags |= CONTEXT_PROXY; |
| 3102 | else if (!inet_pton(AF_INET, a[1], &new->end)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3103 | { |
| 3104 | dhcp_context_free(new); |
| 3105 | ret_err(_("bad dhcp-range")); |
| 3106 | } |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3107 | |
| 3108 | if (ntohl(new->start.s_addr) > ntohl(new->end.s_addr)) |
| 3109 | { |
| 3110 | struct in_addr tmp = new->start; |
| 3111 | new->start = new->end; |
| 3112 | new->end = tmp; |
| 3113 | } |
| 3114 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3115 | if (k >= 3 && strchr(a[2], '.') && |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 3116 | (inet_pton(AF_INET, a[2], &new->netmask) > 0)) |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3117 | { |
| 3118 | new->flags |= CONTEXT_NETMASK; |
| 3119 | leasepos = 3; |
| 3120 | if (!is_same_net(new->start, new->end, new->netmask)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3121 | { |
| 3122 | dhcp_context_free(new); |
| 3123 | ret_err(_("inconsistent DHCP range")); |
| 3124 | } |
Simon Kelley | fa79466 | 2016-03-03 20:33:54 +0000 | [diff] [blame] | 3125 | |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3126 | |
Simon Kelley | fa79466 | 2016-03-03 20:33:54 +0000 | [diff] [blame] | 3127 | if (k >= 4 && strchr(a[3], '.') && |
| 3128 | (inet_pton(AF_INET, a[3], &new->broadcast) > 0)) |
| 3129 | { |
| 3130 | new->flags |= CONTEXT_BRDCAST; |
| 3131 | leasepos = 4; |
| 3132 | } |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3133 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3134 | } |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3135 | #ifdef HAVE_DHCP6 |
| 3136 | else if (inet_pton(AF_INET6, a[0], &new->start6)) |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3137 | { |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3138 | const char *err = NULL; |
| 3139 | |
Simon Kelley | 89500e3 | 2013-09-20 16:29:20 +0100 | [diff] [blame] | 3140 | new->flags |= CONTEXT_V6; |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3141 | new->prefix = 64; /* default */ |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3142 | new->end6 = new->start6; |
Simon Kelley | 4d85e40 | 2020-07-12 22:45:46 +0100 | [diff] [blame] | 3143 | new->lease_time = DEFLEASE6; |
Kyle Swenson | 9d23807 | 2021-12-01 08:13:17 -0700 | [diff] [blame] | 3144 | new->valid_lifetime = DEFLEASE6; |
Simon Kelley | 6692a1a | 2013-08-20 14:41:31 +0100 | [diff] [blame] | 3145 | new->next = daemon->dhcp6; |
| 3146 | daemon->dhcp6 = new; |
| 3147 | |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3148 | for (leasepos = 1; leasepos < k; leasepos++) |
| 3149 | { |
| 3150 | if (strcmp(a[leasepos], "static") == 0) |
| 3151 | new->flags |= CONTEXT_STATIC | CONTEXT_DHCP; |
| 3152 | 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] | 3153 | new->flags |= CONTEXT_RA; |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3154 | else if (strcmp(a[leasepos], "ra-names") == 0) |
Simon Kelley | 1f77693 | 2012-12-16 19:46:08 +0000 | [diff] [blame] | 3155 | new->flags |= CONTEXT_RA_NAME | CONTEXT_RA; |
Simon Kelley | 7ea3d3f | 2014-04-25 22:04:05 +0100 | [diff] [blame] | 3156 | else if (strcmp(a[leasepos], "ra-advrouter") == 0) |
| 3157 | new->flags |= CONTEXT_RA_ROUTER | CONTEXT_RA; |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3158 | else if (strcmp(a[leasepos], "ra-stateless") == 0) |
Simon Kelley | 1f77693 | 2012-12-16 19:46:08 +0000 | [diff] [blame] | 3159 | new->flags |= CONTEXT_RA_STATELESS | CONTEXT_DHCP | CONTEXT_RA; |
Neil Jerram | 2fd5bc9 | 2015-06-10 22:13:06 +0100 | [diff] [blame] | 3160 | else if (strcmp(a[leasepos], "off-link") == 0) |
| 3161 | new->flags |= CONTEXT_RA_OFF_LINK; |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3162 | else if (leasepos == 1 && inet_pton(AF_INET6, a[leasepos], &new->end6)) |
| 3163 | new->flags |= CONTEXT_DHCP; |
Simon Kelley | 1f77693 | 2012-12-16 19:46:08 +0000 | [diff] [blame] | 3164 | else if (strstr(a[leasepos], "constructor:") == a[leasepos]) |
| 3165 | { |
| 3166 | new->template_interface = opt_string_alloc(a[leasepos] + 12); |
| 3167 | new->flags |= CONTEXT_TEMPLATE; |
| 3168 | } |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3169 | else |
| 3170 | break; |
| 3171 | } |
Simon Kelley | 6692a1a | 2013-08-20 14:41:31 +0100 | [diff] [blame] | 3172 | |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3173 | /* bare integer < 128 is prefix value */ |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3174 | if (leasepos < k) |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3175 | { |
| 3176 | int pref; |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3177 | for (cp = a[leasepos]; *cp; cp++) |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3178 | if (!(*cp >= '0' && *cp <= '9')) |
| 3179 | break; |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3180 | if (!*cp && (pref = atoi(a[leasepos])) <= 128) |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3181 | { |
| 3182 | new->prefix = pref; |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3183 | leasepos++; |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3184 | } |
| 3185 | } |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3186 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3187 | if (new->prefix > 64) |
Simon Kelley | 6692a1a | 2013-08-20 14:41:31 +0100 | [diff] [blame] | 3188 | { |
Simon Kelley | 7ea3d3f | 2014-04-25 22:04:05 +0100 | [diff] [blame] | 3189 | if (new->flags & CONTEXT_RA) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3190 | err=(_("prefix length must be exactly 64 for RA subnets")); |
Simon Kelley | 6692a1a | 2013-08-20 14:41:31 +0100 | [diff] [blame] | 3191 | else if (new->flags & CONTEXT_TEMPLATE) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3192 | err=(_("prefix length must be exactly 64 for subnet constructors")); |
Simon Kelley | 6692a1a | 2013-08-20 14:41:31 +0100 | [diff] [blame] | 3193 | } |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3194 | else if (new->prefix < 64) |
| 3195 | err=(_("prefix length must be at least 64")); |
Simon Kelley | 6692a1a | 2013-08-20 14:41:31 +0100 | [diff] [blame] | 3196 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3197 | if (!err && !is_same_net6(&new->start6, &new->end6, new->prefix)) |
| 3198 | err=(_("inconsistent DHCPv6 range")); |
| 3199 | |
| 3200 | if (err) |
| 3201 | { |
| 3202 | dhcp_context_free(new); |
| 3203 | ret_err(err); |
| 3204 | } |
Simon Kelley | 6692a1a | 2013-08-20 14:41:31 +0100 | [diff] [blame] | 3205 | |
| 3206 | /* dhcp-range=:: enables DHCP stateless on any interface */ |
| 3207 | if (IN6_IS_ADDR_UNSPECIFIED(&new->start6) && !(new->flags & CONTEXT_TEMPLATE)) |
| 3208 | new->prefix = 0; |
Simon Kelley | 6640919 | 2013-08-01 20:19:32 +0100 | [diff] [blame] | 3209 | |
| 3210 | if (new->flags & CONTEXT_TEMPLATE) |
| 3211 | { |
| 3212 | struct in6_addr zero; |
| 3213 | memset(&zero, 0, sizeof(zero)); |
| 3214 | if (!is_same_net6(&zero, &new->start6, new->prefix)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3215 | { |
| 3216 | dhcp_context_free(new); |
| 3217 | ret_err(_("prefix must be zero with \"constructor:\" argument")); |
| 3218 | } |
Simon Kelley | 6640919 | 2013-08-01 20:19:32 +0100 | [diff] [blame] | 3219 | } |
| 3220 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3221 | if (addr6part(&new->start6) > addr6part(&new->end6)) |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3222 | { |
| 3223 | struct in6_addr tmp = new->start6; |
| 3224 | new->start6 = new->end6; |
| 3225 | new->end6 = tmp; |
| 3226 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3227 | } |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 3228 | #endif |
Simon Kelley | d9ee9c0 | 2013-04-12 11:17:55 +0100 | [diff] [blame] | 3229 | else |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3230 | { |
| 3231 | dhcp_context_free(new); |
| 3232 | ret_err(_("bad dhcp-range")); |
| 3233 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3234 | |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 3235 | if (leasepos < k) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3236 | { |
Kyle Swenson | 9d23807 | 2021-12-01 08:13:17 -0700 | [diff] [blame] | 3237 | |
| 3238 | #ifndef HAVE_DHCP6 |
Simon Kelley | fa79466 | 2016-03-03 20:33:54 +0000 | [diff] [blame] | 3239 | if (leasepos != k-1) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3240 | { |
| 3241 | dhcp_context_free(new); |
| 3242 | ret_err(_("bad dhcp-range")); |
| 3243 | } |
Kyle Swenson | 9d23807 | 2021-12-01 08:13:17 -0700 | [diff] [blame] | 3244 | #endif |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3245 | if (strcmp(a[leasepos], "infinite") == 0) |
Simon Kelley | 4d85e40 | 2020-07-12 22:45:46 +0100 | [diff] [blame] | 3246 | { |
| 3247 | new->lease_time = 0xffffffff; |
| 3248 | new->flags |= CONTEXT_SETLEASE; |
| 3249 | } |
Simon Kelley | c825754 | 2012-03-28 21:15:41 +0100 | [diff] [blame] | 3250 | else if (strcmp(a[leasepos], "deprecated") == 0) |
| 3251 | new->flags |= CONTEXT_DEPRECATE; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3252 | else |
| 3253 | { |
| 3254 | int fac = 1; |
| 3255 | if (strlen(a[leasepos]) > 0) |
| 3256 | { |
| 3257 | switch (a[leasepos][strlen(a[leasepos]) - 1]) |
| 3258 | { |
Simon Kelley | 4224321 | 2012-07-20 15:19:18 +0100 | [diff] [blame] | 3259 | case 'w': |
| 3260 | case 'W': |
| 3261 | fac *= 7; |
| 3262 | /* fall through */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3263 | case 'd': |
| 3264 | case 'D': |
| 3265 | fac *= 24; |
Simon Kelley | 87e00fe | 2018-02-16 21:27:35 +0000 | [diff] [blame] | 3266 | /* fall through */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3267 | case 'h': |
| 3268 | case 'H': |
| 3269 | fac *= 60; |
| 3270 | /* fall through */ |
| 3271 | case 'm': |
| 3272 | case 'M': |
| 3273 | fac *= 60; |
| 3274 | /* fall through */ |
| 3275 | case 's': |
| 3276 | case 'S': |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3277 | a[leasepos][strlen(a[leasepos]) - 1] = 0; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3278 | } |
| 3279 | |
Simon Kelley | be37986 | 2012-12-23 12:01:39 +0000 | [diff] [blame] | 3280 | for (cp = a[leasepos]; *cp; cp++) |
| 3281 | if (!(*cp >= '0' && *cp <= '9')) |
| 3282 | break; |
| 3283 | |
Kyle Swenson | 9d23807 | 2021-12-01 08:13:17 -0700 | [diff] [blame] | 3284 | if (*cp) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3285 | ret_err_free(_("bad dhcp-range"), new); |
Simon Kelley | be37986 | 2012-12-23 12:01:39 +0000 | [diff] [blame] | 3286 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3287 | new->lease_time = atoi(a[leasepos]) * fac; |
Simon Kelley | 4d85e40 | 2020-07-12 22:45:46 +0100 | [diff] [blame] | 3288 | new->flags |= CONTEXT_SETLEASE; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3289 | /* Leases of a minute or less confuse |
| 3290 | some clients, notably Apple's */ |
| 3291 | if (new->lease_time < 120) |
| 3292 | new->lease_time = 120; |
| 3293 | } |
| 3294 | } |
Kyle Swenson | 9d23807 | 2021-12-01 08:13:17 -0700 | [diff] [blame] | 3295 | leasepos++; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3296 | } |
Kyle Swenson | 9d23807 | 2021-12-01 08:13:17 -0700 | [diff] [blame] | 3297 | #ifdef HAVE_DHCP6 |
| 3298 | if (leasepos < k) |
| 3299 | { |
| 3300 | if (leasepos != k-1) |
| 3301 | { |
| 3302 | dhcp_context_free(new); |
| 3303 | ret_err(_("bad dhcp-range")); |
| 3304 | } |
| 3305 | if (strcmp(a[leasepos], "infinite") == 0) |
| 3306 | { |
| 3307 | new->valid_lifetime = 0xffffffff; |
| 3308 | new->flags |= CONTEXT_SETVALID; |
| 3309 | } |
| 3310 | else |
| 3311 | { |
| 3312 | int fac = 1; |
| 3313 | if (strlen(a[leasepos]) > 0) |
| 3314 | { |
| 3315 | switch (a[leasepos][strlen(a[leasepos]) - 1]) |
| 3316 | { |
| 3317 | case 'w': |
| 3318 | case 'W': |
| 3319 | fac *= 7; |
| 3320 | /* fall through */ |
| 3321 | case 'd': |
| 3322 | case 'D': |
| 3323 | fac *= 24; |
| 3324 | /* fall through */ |
| 3325 | case 'h': |
| 3326 | case 'H': |
| 3327 | fac *= 60; |
| 3328 | /* fall through */ |
| 3329 | case 'm': |
| 3330 | case 'M': |
| 3331 | fac *= 60; |
| 3332 | /* fall through */ |
| 3333 | case 's': |
| 3334 | case 'S': |
| 3335 | a[leasepos][strlen(a[leasepos]) - 1] = 0; |
| 3336 | } |
| 3337 | |
| 3338 | for (cp = a[leasepos]; *cp; cp++) |
| 3339 | if (!(*cp >= '0' && *cp <= '9')) |
| 3340 | break; |
Simon Kelley | 4d85e40 | 2020-07-12 22:45:46 +0100 | [diff] [blame] | 3341 | |
Kyle Swenson | 9d23807 | 2021-12-01 08:13:17 -0700 | [diff] [blame] | 3342 | if (*cp || (leasepos+1 < k)) |
| 3343 | ret_err_free(_("bad dhcp-range"), new); |
| 3344 | |
| 3345 | new->valid_lifetime = atoi(a[leasepos]) * fac; |
| 3346 | new->flags |= CONTEXT_SETVALID; |
| 3347 | } |
| 3348 | } |
| 3349 | leasepos++; |
| 3350 | } |
| 3351 | #endif |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3352 | break; |
| 3353 | } |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 3354 | |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 3355 | case LOPT_BANK: |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3356 | case 'G': /* --dhcp-host */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3357 | { |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 3358 | struct dhcp_config *new; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3359 | struct in_addr in; |
| 3360 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3361 | new = opt_malloc(sizeof(struct dhcp_config)); |
| 3362 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3363 | new->next = daemon->dhcp_conf; |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 3364 | new->flags = (option == LOPT_BANK) ? CONFIG_BANK : 0; |
| 3365 | new->hwaddr = NULL; |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3366 | new->netid = NULL; |
Simon Kelley | 52ec783 | 2020-02-07 21:05:54 +0000 | [diff] [blame] | 3367 | new->filter = NULL; |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3368 | new->clid = NULL; |
Kevin Darbyshire-Bryant | 8d6d573 | 2020-03-02 10:00:21 +0000 | [diff] [blame] | 3369 | #ifdef HAVE_DHCP6 |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 3370 | new->addr6 = NULL; |
Kevin Darbyshire-Bryant | 8d6d573 | 2020-03-02 10:00:21 +0000 | [diff] [blame] | 3371 | #endif |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3372 | |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 3373 | while (arg) |
| 3374 | { |
| 3375 | comma = split(arg); |
| 3376 | if (strchr(arg, ':')) /* ethernet address, netid or binary CLID */ |
| 3377 | { |
| 3378 | if ((arg[0] == 'i' || arg[0] == 'I') && |
| 3379 | (arg[1] == 'd' || arg[1] == 'D') && |
| 3380 | arg[2] == ':') |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3381 | { |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 3382 | if (arg[3] == '*') |
| 3383 | new->flags |= CONFIG_NOCLID; |
| 3384 | else |
| 3385 | { |
| 3386 | int len; |
| 3387 | arg += 3; /* dump id: */ |
| 3388 | if (strchr(arg, ':')) |
| 3389 | len = parse_hex(arg, (unsigned char *)arg, -1, NULL, NULL); |
| 3390 | else |
| 3391 | { |
| 3392 | unhide_metas(arg); |
| 3393 | len = (int) strlen(arg); |
| 3394 | } |
| 3395 | |
| 3396 | if (len == -1) |
| 3397 | { |
| 3398 | dhcp_config_free(new); |
| 3399 | ret_err(_("bad hex constant")); |
| 3400 | } |
| 3401 | else if ((new->clid = opt_malloc(len))) |
| 3402 | { |
| 3403 | new->flags |= CONFIG_CLID; |
| 3404 | new->clid_len = len; |
| 3405 | memcpy(new->clid, arg, len); |
| 3406 | } |
| 3407 | } |
| 3408 | } |
| 3409 | /* dhcp-host has strange backwards-compat needs. */ |
| 3410 | else if (strstr(arg, "net:") == arg || strstr(arg, "set:") == arg) |
| 3411 | { |
| 3412 | struct dhcp_netid_list *newlist = opt_malloc(sizeof(struct dhcp_netid_list)); |
| 3413 | newlist->next = new->netid; |
| 3414 | new->netid = newlist; |
| 3415 | newlist->list = dhcp_netid_create(arg+4, NULL); |
| 3416 | } |
| 3417 | else if (strstr(arg, "tag:") == arg) |
Simon Kelley | 52ec783 | 2020-02-07 21:05:54 +0000 | [diff] [blame] | 3418 | new->filter = dhcp_netid_create(arg+4, new->filter); |
| 3419 | |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 3420 | #ifdef HAVE_DHCP6 |
| 3421 | else if (arg[0] == '[' && arg[strlen(arg)-1] == ']') |
| 3422 | { |
| 3423 | char *pref; |
| 3424 | struct in6_addr in6; |
| 3425 | struct addrlist *new_addr; |
| 3426 | |
| 3427 | arg[strlen(arg)-1] = 0; |
| 3428 | arg++; |
| 3429 | pref = split_chr(arg, '/'); |
| 3430 | |
| 3431 | if (!inet_pton(AF_INET6, arg, &in6)) |
| 3432 | { |
| 3433 | dhcp_config_free(new); |
| 3434 | ret_err(_("bad IPv6 address")); |
| 3435 | } |
Simon Kelley | 76ff440 | 2013-12-17 16:29:14 +0000 | [diff] [blame] | 3436 | |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 3437 | new_addr = opt_malloc(sizeof(struct addrlist)); |
| 3438 | new_addr->next = new->addr6; |
| 3439 | new_addr->flags = 0; |
| 3440 | new_addr->addr.addr6 = in6; |
| 3441 | new->addr6 = new_addr; |
| 3442 | |
| 3443 | if (pref) |
| 3444 | { |
| 3445 | u64 addrpart = addr6part(&in6); |
| 3446 | |
| 3447 | if (!atoi_check(pref, &new_addr->prefixlen) || |
| 3448 | new_addr->prefixlen > 128 || |
Petr Menšík | 46bdfe6 | 2020-03-08 15:56:19 +0000 | [diff] [blame] | 3449 | ((((u64)1<<(128-new_addr->prefixlen))-1) & addrpart) != 0) |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 3450 | { |
| 3451 | dhcp_config_free(new); |
| 3452 | ret_err(_("bad IPv6 prefix")); |
| 3453 | } |
| 3454 | |
| 3455 | new_addr->flags |= ADDRLIST_PREFIX; |
| 3456 | } |
| 3457 | |
| 3458 | for (i= 0; i < 8; i++) |
| 3459 | if (in6.s6_addr[i] != 0) |
| 3460 | break; |
| 3461 | |
| 3462 | /* set WILDCARD if network part all zeros */ |
| 3463 | if (i == 8) |
| 3464 | new_addr->flags |= ADDRLIST_WILDCARD; |
| 3465 | |
| 3466 | new->flags |= CONFIG_ADDR6; |
| 3467 | } |
| 3468 | #endif |
| 3469 | else |
| 3470 | { |
| 3471 | struct hwaddr_config *newhw = opt_malloc(sizeof(struct hwaddr_config)); |
| 3472 | if ((newhw->hwaddr_len = parse_hex(arg, newhw->hwaddr, DHCP_CHADDR_MAX, |
| 3473 | &newhw->wildcard_mask, &newhw->hwaddr_type)) == -1) |
| 3474 | { |
| 3475 | free(newhw); |
| 3476 | dhcp_config_free(new); |
| 3477 | ret_err(_("bad hex constant")); |
| 3478 | } |
| 3479 | else |
| 3480 | { |
| 3481 | newhw->next = new->hwaddr; |
| 3482 | new->hwaddr = newhw; |
| 3483 | } |
| 3484 | } |
| 3485 | } |
| 3486 | else if (strchr(arg, '.') && (inet_pton(AF_INET, arg, &in) > 0)) |
| 3487 | { |
| 3488 | struct dhcp_config *configs; |
| 3489 | |
| 3490 | new->addr = in; |
| 3491 | new->flags |= CONFIG_ADDR; |
| 3492 | |
| 3493 | /* If the same IP appears in more than one host config, then DISCOVER |
| 3494 | for one of the hosts will get the address, but REQUEST will be NAKed, |
| 3495 | since the address is reserved by the other one -> protocol loop. */ |
| 3496 | for (configs = daemon->dhcp_conf; configs; configs = configs->next) |
| 3497 | if ((configs->flags & CONFIG_ADDR) && configs->addr.s_addr == in.s_addr) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3498 | { |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 3499 | sprintf(errstr, _("duplicate dhcp-host IP address %s"), inet_ntoa(in)); |
| 3500 | return 0; |
| 3501 | } |
| 3502 | } |
| 3503 | else |
| 3504 | { |
| 3505 | char *cp, *lastp = NULL, last = 0; |
| 3506 | int fac = 1, isdig = 0; |
| 3507 | |
| 3508 | if (strlen(arg) > 1) |
| 3509 | { |
| 3510 | lastp = arg + strlen(arg) - 1; |
| 3511 | last = *lastp; |
| 3512 | switch (last) |
| 3513 | { |
| 3514 | case 'w': |
| 3515 | case 'W': |
| 3516 | fac *= 7; |
| 3517 | /* fall through */ |
| 3518 | case 'd': |
| 3519 | case 'D': |
| 3520 | fac *= 24; |
| 3521 | /* fall through */ |
| 3522 | case 'h': |
| 3523 | case 'H': |
| 3524 | fac *= 60; |
| 3525 | /* fall through */ |
| 3526 | case 'm': |
| 3527 | case 'M': |
| 3528 | fac *= 60; |
| 3529 | /* fall through */ |
| 3530 | case 's': |
| 3531 | case 'S': |
| 3532 | *lastp = 0; |
| 3533 | } |
| 3534 | } |
| 3535 | |
| 3536 | for (cp = arg; *cp; cp++) |
| 3537 | if (isdigit((unsigned char)*cp)) |
| 3538 | isdig = 1; |
| 3539 | else if (*cp != ' ') |
| 3540 | break; |
| 3541 | |
| 3542 | if (*cp) |
| 3543 | { |
| 3544 | if (lastp) |
| 3545 | *lastp = last; |
| 3546 | if (strcmp(arg, "infinite") == 0) |
| 3547 | { |
| 3548 | new->lease_time = 0xffffffff; |
| 3549 | new->flags |= CONFIG_TIME; |
| 3550 | } |
| 3551 | else if (strcmp(arg, "ignore") == 0) |
| 3552 | new->flags |= CONFIG_DISABLE; |
| 3553 | else |
| 3554 | { |
| 3555 | if (!(new->hostname = canonicalise_opt(arg)) || |
| 3556 | !legal_hostname(new->hostname)) |
| 3557 | { |
| 3558 | dhcp_config_free(new); |
| 3559 | ret_err(_("bad DHCP host name")); |
| 3560 | } |
| 3561 | |
| 3562 | new->flags |= CONFIG_NAME; |
| 3563 | new->domain = strip_hostname(new->hostname); |
| 3564 | } |
| 3565 | } |
| 3566 | else if (isdig) |
| 3567 | { |
| 3568 | new->lease_time = atoi(arg) * fac; |
| 3569 | /* Leases of a minute or less confuse |
| 3570 | some clients, notably Apple's */ |
| 3571 | if (new->lease_time < 120) |
| 3572 | new->lease_time = 120; |
| 3573 | new->flags |= CONFIG_TIME; |
| 3574 | } |
| 3575 | } |
| 3576 | |
| 3577 | arg = comma; |
| 3578 | } |
| 3579 | |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 3580 | daemon->dhcp_conf = new; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3581 | break; |
| 3582 | } |
Simon Kelley | 137286e | 2020-02-06 22:09:30 +0000 | [diff] [blame] | 3583 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3584 | case LOPT_TAG_IF: /* --tag-if */ |
| 3585 | { |
| 3586 | struct tag_if *new = opt_malloc(sizeof(struct tag_if)); |
| 3587 | |
| 3588 | new->tag = NULL; |
| 3589 | new->set = NULL; |
| 3590 | new->next = NULL; |
| 3591 | |
| 3592 | /* preserve order */ |
| 3593 | if (!daemon->tag_if) |
| 3594 | daemon->tag_if = new; |
| 3595 | else |
| 3596 | { |
| 3597 | struct tag_if *tmp; |
| 3598 | for (tmp = daemon->tag_if; tmp->next; tmp = tmp->next); |
| 3599 | tmp->next = new; |
| 3600 | } |
| 3601 | |
| 3602 | while (arg) |
| 3603 | { |
| 3604 | size_t len; |
| 3605 | |
| 3606 | comma = split(arg); |
| 3607 | len = strlen(arg); |
| 3608 | |
| 3609 | if (len < 5) |
| 3610 | { |
| 3611 | new->set = NULL; |
| 3612 | break; |
| 3613 | } |
| 3614 | else |
| 3615 | { |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3616 | struct dhcp_netid *newtag = dhcp_netid_create(arg+4, NULL); |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3617 | |
| 3618 | if (strstr(arg, "set:") == arg) |
| 3619 | { |
| 3620 | struct dhcp_netid_list *newlist = opt_malloc(sizeof(struct dhcp_netid_list)); |
| 3621 | newlist->next = new->set; |
| 3622 | new->set = newlist; |
| 3623 | newlist->list = newtag; |
| 3624 | } |
| 3625 | else if (strstr(arg, "tag:") == arg) |
| 3626 | { |
| 3627 | newtag->next = new->tag; |
| 3628 | new->tag = newtag; |
| 3629 | } |
| 3630 | else |
| 3631 | { |
| 3632 | new->set = NULL; |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3633 | dhcp_netid_free(newtag); |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3634 | break; |
| 3635 | } |
| 3636 | } |
| 3637 | |
| 3638 | arg = comma; |
| 3639 | } |
| 3640 | |
| 3641 | if (!new->set) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3642 | { |
| 3643 | dhcp_netid_free(new->tag); |
| 3644 | dhcp_netid_list_free(new->set); |
| 3645 | ret_err_free(_("bad tag-if"), new); |
| 3646 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3647 | |
| 3648 | break; |
| 3649 | } |
| 3650 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3651 | |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 3652 | case 'O': /* --dhcp-option */ |
| 3653 | case LOPT_FORCE: /* --dhcp-option-force */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3654 | case LOPT_OPTS: |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 3655 | case LOPT_MATCH: /* --dhcp-match */ |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3656 | return parse_dhcp_opt(errstr, arg, |
| 3657 | option == LOPT_FORCE ? DHOPT_FORCE : |
| 3658 | (option == LOPT_MATCH ? DHOPT_MATCH : |
| 3659 | (option == LOPT_OPTS ? DHOPT_BANK : 0))); |
Simon Kelley | c822620 | 2018-08-08 23:46:03 +0100 | [diff] [blame] | 3660 | |
| 3661 | case LOPT_NAME_MATCH: /* --dhcp-name-match */ |
| 3662 | { |
| 3663 | struct dhcp_match_name *new = opt_malloc(sizeof(struct dhcp_match_name)); |
| 3664 | struct dhcp_netid *id = opt_malloc(sizeof(struct dhcp_netid)); |
| 3665 | ssize_t len; |
| 3666 | |
| 3667 | if (!(comma = split(arg)) || (len = strlen(comma)) == 0) |
| 3668 | ret_err(gen_err); |
| 3669 | |
| 3670 | new->wildcard = 0; |
| 3671 | new->netid = id; |
| 3672 | id->net = opt_string_alloc(set_prefix(arg)); |
| 3673 | |
| 3674 | if (comma[len-1] == '*') |
| 3675 | { |
| 3676 | comma[len-1] = 0; |
| 3677 | new->wildcard = 1; |
| 3678 | } |
| 3679 | new->name = opt_string_alloc(comma); |
| 3680 | |
| 3681 | new->next = daemon->dhcp_name_match; |
| 3682 | daemon->dhcp_name_match = new; |
| 3683 | |
| 3684 | break; |
| 3685 | } |
| 3686 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3687 | case 'M': /* --dhcp-boot */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3688 | { |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3689 | struct dhcp_netid *id = dhcp_tags(&arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3690 | |
Petr Menšík | 137e9f8 | 2018-12-16 21:25:29 +0000 | [diff] [blame] | 3691 | if (!arg) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3692 | { |
| 3693 | ret_err(gen_err); |
| 3694 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3695 | else |
| 3696 | { |
Simon Kelley | 7de060b | 2011-08-26 17:24:52 +0100 | [diff] [blame] | 3697 | char *dhcp_file, *dhcp_sname = NULL, *tftp_sname = NULL; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3698 | struct in_addr dhcp_next_server; |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3699 | struct dhcp_boot *new; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3700 | comma = split(arg); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3701 | dhcp_file = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3702 | dhcp_next_server.s_addr = 0; |
| 3703 | if (comma) |
| 3704 | { |
| 3705 | arg = comma; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3706 | comma = split(arg); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3707 | dhcp_sname = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3708 | if (comma) |
| 3709 | { |
| 3710 | unhide_metas(comma); |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 3711 | if (!(inet_pton(AF_INET, comma, &dhcp_next_server) > 0)) |
| 3712 | { |
| 3713 | /* |
| 3714 | * The user may have specified the tftp hostname here. |
| 3715 | * save it so that it can be resolved/looked up during |
| 3716 | * actual dhcp_reply(). |
| 3717 | */ |
| 3718 | |
| 3719 | tftp_sname = opt_string_alloc(comma); |
| 3720 | dhcp_next_server.s_addr = 0; |
| 3721 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3722 | } |
| 3723 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3724 | |
| 3725 | new = opt_malloc(sizeof(struct dhcp_boot)); |
| 3726 | new->file = dhcp_file; |
| 3727 | new->sname = dhcp_sname; |
| 3728 | new->tftp_sname = tftp_sname; |
| 3729 | new->next_server = dhcp_next_server; |
| 3730 | new->netid = id; |
| 3731 | new->next = daemon->boot_config; |
| 3732 | daemon->boot_config = new; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3733 | } |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 3734 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3735 | break; |
| 3736 | } |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3737 | |
Floris Bos | 503c609 | 2017-04-09 23:07:13 +0100 | [diff] [blame] | 3738 | case LOPT_REPLY_DELAY: /* --dhcp-reply-delay */ |
| 3739 | { |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3740 | struct dhcp_netid *id = dhcp_tags(&arg); |
Floris Bos | 503c609 | 2017-04-09 23:07:13 +0100 | [diff] [blame] | 3741 | |
Petr Menšík | 137e9f8 | 2018-12-16 21:25:29 +0000 | [diff] [blame] | 3742 | if (!arg) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3743 | { |
| 3744 | ret_err(gen_err); |
| 3745 | } |
Floris Bos | 503c609 | 2017-04-09 23:07:13 +0100 | [diff] [blame] | 3746 | else |
| 3747 | { |
| 3748 | struct delay_config *new; |
| 3749 | int delay; |
| 3750 | if (!atoi_check(arg, &delay)) |
| 3751 | ret_err(gen_err); |
| 3752 | |
| 3753 | new = opt_malloc(sizeof(struct delay_config)); |
| 3754 | new->delay = delay; |
| 3755 | new->netid = id; |
| 3756 | new->next = daemon->delay_conf; |
| 3757 | daemon->delay_conf = new; |
| 3758 | } |
| 3759 | |
| 3760 | break; |
| 3761 | } |
| 3762 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3763 | case LOPT_PXE_PROMT: /* --pxe-prompt */ |
| 3764 | { |
| 3765 | struct dhcp_opt *new = opt_malloc(sizeof(struct dhcp_opt)); |
| 3766 | int timeout; |
Floris Bos | 503c609 | 2017-04-09 23:07:13 +0100 | [diff] [blame] | 3767 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3768 | new->netid = NULL; |
| 3769 | new->opt = 10; /* PXE_MENU_PROMPT */ |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3770 | new->netid = dhcp_tags(&arg); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3771 | |
Petr Menšík | 137e9f8 | 2018-12-16 21:25:29 +0000 | [diff] [blame] | 3772 | if (!arg) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3773 | { |
| 3774 | dhcp_opt_free(new); |
| 3775 | ret_err(gen_err); |
| 3776 | } |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3777 | else |
| 3778 | { |
| 3779 | comma = split(arg); |
| 3780 | unhide_metas(arg); |
| 3781 | new->len = strlen(arg) + 1; |
| 3782 | new->val = opt_malloc(new->len); |
| 3783 | memcpy(new->val + 1, arg, new->len - 1); |
| 3784 | |
Wang Shanker | 4ded962 | 2020-12-04 10:17:35 +0800 | [diff] [blame] | 3785 | new->u.vendor_class = NULL; |
| 3786 | new->flags = DHOPT_VENDOR | DHOPT_VENDOR_PXE; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3787 | |
| 3788 | if (comma && atoi_check(comma, &timeout)) |
| 3789 | *(new->val) = timeout; |
| 3790 | else |
| 3791 | *(new->val) = 255; |
| 3792 | |
| 3793 | new->next = daemon->dhcp_opts; |
| 3794 | daemon->dhcp_opts = new; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 3795 | daemon->enable_pxe = 1; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3796 | } |
| 3797 | |
| 3798 | break; |
| 3799 | } |
| 3800 | |
| 3801 | case LOPT_PXE_SERV: /* --pxe-service */ |
| 3802 | { |
| 3803 | struct pxe_service *new = opt_malloc(sizeof(struct pxe_service)); |
| 3804 | char *CSA[] = { "x86PC", "PC98", "IA64_EFI", "Alpha", "Arc_x86", "Intel_Lean_Client", |
Simon Kelley | 68bea10 | 2016-05-11 22:15:06 +0100 | [diff] [blame] | 3805 | "IA32_EFI", "x86-64_EFI", "Xscale_EFI", "BC_EFI", |
| 3806 | "ARM32_EFI", "ARM64_EFI", NULL }; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3807 | static int boottype = 32768; |
| 3808 | |
| 3809 | new->netid = NULL; |
Simon Kelley | 751d6f4 | 2012-02-10 15:24:51 +0000 | [diff] [blame] | 3810 | new->sname = NULL; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3811 | new->server.s_addr = 0; |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3812 | new->netid = dhcp_tags(&arg); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3813 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3814 | if (arg && (comma = split(arg))) |
| 3815 | { |
| 3816 | for (i = 0; CSA[i]; i++) |
| 3817 | if (strcasecmp(CSA[i], arg) == 0) |
| 3818 | break; |
| 3819 | |
| 3820 | if (CSA[i] || atoi_check(arg, &i)) |
| 3821 | { |
| 3822 | arg = comma; |
| 3823 | comma = split(arg); |
| 3824 | |
| 3825 | new->CSA = i; |
| 3826 | new->menu = opt_string_alloc(arg); |
| 3827 | |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 3828 | if (!comma) |
| 3829 | { |
| 3830 | new->type = 0; /* local boot */ |
| 3831 | new->basename = NULL; |
| 3832 | } |
| 3833 | else |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3834 | { |
| 3835 | arg = comma; |
| 3836 | comma = split(arg); |
| 3837 | if (atoi_check(arg, &i)) |
| 3838 | { |
| 3839 | new->type = i; |
| 3840 | new->basename = NULL; |
| 3841 | } |
| 3842 | else |
| 3843 | { |
| 3844 | new->type = boottype++; |
| 3845 | new->basename = opt_string_alloc(arg); |
| 3846 | } |
| 3847 | |
Simon Kelley | 751d6f4 | 2012-02-10 15:24:51 +0000 | [diff] [blame] | 3848 | if (comma) |
| 3849 | { |
| 3850 | if (!inet_pton(AF_INET, comma, &new->server)) |
| 3851 | { |
| 3852 | new->server.s_addr = 0; |
| 3853 | new->sname = opt_string_alloc(comma); |
| 3854 | } |
| 3855 | |
| 3856 | } |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3857 | } |
Simon Kelley | 751d6f4 | 2012-02-10 15:24:51 +0000 | [diff] [blame] | 3858 | |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 3859 | /* Order matters */ |
| 3860 | new->next = NULL; |
| 3861 | if (!daemon->pxe_services) |
| 3862 | daemon->pxe_services = new; |
| 3863 | else |
| 3864 | { |
| 3865 | struct pxe_service *s; |
| 3866 | for (s = daemon->pxe_services; s->next; s = s->next); |
| 3867 | s->next = new; |
| 3868 | } |
| 3869 | |
| 3870 | daemon->enable_pxe = 1; |
| 3871 | break; |
| 3872 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3873 | } |
| 3874 | } |
| 3875 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3876 | ret_err(gen_err); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3877 | } |
| 3878 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3879 | case '4': /* --dhcp-mac */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3880 | { |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3881 | if (!(comma = split(arg))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3882 | ret_err(gen_err); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3883 | else |
| 3884 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3885 | struct dhcp_mac *new = opt_malloc(sizeof(struct dhcp_mac)); |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3886 | new->netid.net = opt_string_alloc(set_prefix(arg)); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3887 | unhide_metas(comma); |
| 3888 | 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] | 3889 | if (new->hwaddr_len == -1) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3890 | { |
| 3891 | free(new->netid.net); |
| 3892 | ret_err_free(gen_err, new); |
| 3893 | } |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 3894 | else |
| 3895 | { |
| 3896 | new->next = daemon->dhcp_macs; |
| 3897 | daemon->dhcp_macs = new; |
| 3898 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3899 | } |
| 3900 | } |
| 3901 | break; |
Simon Kelley | c630924 | 2013-03-07 20:59:28 +0000 | [diff] [blame] | 3902 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3903 | case 'U': /* --dhcp-vendorclass */ |
| 3904 | case 'j': /* --dhcp-userclass */ |
| 3905 | case LOPT_CIRCUIT: /* --dhcp-circuitid */ |
| 3906 | case LOPT_REMOTE: /* --dhcp-remoteid */ |
| 3907 | case LOPT_SUBSCR: /* --dhcp-subscrid */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3908 | { |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3909 | unsigned char *p; |
| 3910 | int dig = 0; |
| 3911 | struct dhcp_vendor *new = opt_malloc(sizeof(struct dhcp_vendor)); |
| 3912 | |
| 3913 | if (!(comma = split(arg))) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3914 | ret_err_free(gen_err, new); |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3915 | |
| 3916 | new->netid.net = opt_string_alloc(set_prefix(arg)); |
| 3917 | /* check for hex string - must digits may include : must not have nothing else, |
| 3918 | only allowed for agent-options. */ |
| 3919 | |
| 3920 | arg = comma; |
| 3921 | if ((comma = split(arg))) |
| 3922 | { |
| 3923 | if (option != 'U' || strstr(arg, "enterprise:") != arg) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 3924 | { |
| 3925 | free(new->netid.net); |
| 3926 | ret_err_free(gen_err, new); |
| 3927 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3928 | else |
| 3929 | new->enterprise = atoi(arg+11); |
| 3930 | } |
| 3931 | else |
| 3932 | comma = arg; |
| 3933 | |
| 3934 | for (p = (unsigned char *)comma; *p; p++) |
| 3935 | if (isxdigit(*p)) |
| 3936 | dig = 1; |
| 3937 | else if (*p != ':') |
| 3938 | break; |
| 3939 | unhide_metas(comma); |
| 3940 | if (option == 'U' || option == 'j' || *p || !dig) |
| 3941 | { |
| 3942 | new->len = strlen(comma); |
| 3943 | new->data = opt_malloc(new->len); |
| 3944 | memcpy(new->data, comma, new->len); |
| 3945 | } |
| 3946 | else |
| 3947 | { |
| 3948 | new->len = parse_hex(comma, (unsigned char *)comma, strlen(comma), NULL, NULL); |
| 3949 | new->data = opt_malloc(new->len); |
| 3950 | memcpy(new->data, comma, new->len); |
| 3951 | } |
| 3952 | |
| 3953 | switch (option) |
| 3954 | { |
| 3955 | case 'j': |
| 3956 | new->match_type = MATCH_USER; |
| 3957 | break; |
| 3958 | case 'U': |
| 3959 | new->match_type = MATCH_VENDOR; |
| 3960 | break; |
| 3961 | case LOPT_CIRCUIT: |
| 3962 | new->match_type = MATCH_CIRCUIT; |
| 3963 | break; |
| 3964 | case LOPT_REMOTE: |
| 3965 | new->match_type = MATCH_REMOTE; |
| 3966 | break; |
| 3967 | case LOPT_SUBSCR: |
| 3968 | new->match_type = MATCH_SUBSCRIBER; |
| 3969 | break; |
| 3970 | } |
| 3971 | new->next = daemon->dhcp_vendors; |
| 3972 | daemon->dhcp_vendors = new; |
Simon Kelley | a5c72ab | 2012-02-10 13:42:47 +0000 | [diff] [blame] | 3973 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3974 | break; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3975 | } |
| 3976 | |
Simon Kelley | 9e03894 | 2008-05-30 20:06:34 +0100 | [diff] [blame] | 3977 | case LOPT_ALTPORT: /* --dhcp-alternate-port */ |
| 3978 | if (!arg) |
| 3979 | { |
| 3980 | daemon->dhcp_server_port = DHCP_SERVER_ALTPORT; |
| 3981 | daemon->dhcp_client_port = DHCP_CLIENT_ALTPORT; |
| 3982 | } |
| 3983 | else |
| 3984 | { |
| 3985 | comma = split(arg); |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 3986 | if (!atoi_check16(arg, &daemon->dhcp_server_port) || |
| 3987 | (comma && !atoi_check16(comma, &daemon->dhcp_client_port))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3988 | ret_err(_("invalid port number")); |
Simon Kelley | 9e03894 | 2008-05-30 20:06:34 +0100 | [diff] [blame] | 3989 | if (!comma) |
| 3990 | daemon->dhcp_client_port = daemon->dhcp_server_port+1; |
| 3991 | } |
| 3992 | break; |
| 3993 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3994 | case 'J': /* --dhcp-ignore */ |
| 3995 | case LOPT_NO_NAMES: /* --dhcp-ignore-names */ |
| 3996 | case LOPT_BROADCAST: /* --dhcp-broadcast */ |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3997 | case '3': /* --bootp-dynamic */ |
| 3998 | case LOPT_GEN_NAMES: /* --dhcp-generate-names */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3999 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4000 | struct dhcp_netid_list *new = opt_malloc(sizeof(struct dhcp_netid_list)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4001 | struct dhcp_netid *list = NULL; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 4002 | if (option == 'J') |
| 4003 | { |
| 4004 | new->next = daemon->dhcp_ignore; |
| 4005 | daemon->dhcp_ignore = new; |
| 4006 | } |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4007 | else if (option == LOPT_BROADCAST) |
| 4008 | { |
| 4009 | new->next = daemon->force_broadcast; |
| 4010 | daemon->force_broadcast = new; |
| 4011 | } |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 4012 | else if (option == '3') |
| 4013 | { |
| 4014 | new->next = daemon->bootp_dynamic; |
| 4015 | daemon->bootp_dynamic = new; |
| 4016 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4017 | else if (option == LOPT_GEN_NAMES) |
| 4018 | { |
| 4019 | new->next = daemon->dhcp_gen_names; |
| 4020 | daemon->dhcp_gen_names = new; |
| 4021 | } |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 4022 | else |
| 4023 | { |
| 4024 | new->next = daemon->dhcp_ignore_names; |
| 4025 | daemon->dhcp_ignore_names = new; |
| 4026 | } |
| 4027 | |
| 4028 | while (arg) { |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4029 | comma = split(arg); |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4030 | list = dhcp_netid_create(is_tag_prefix(arg) ? arg+4 :arg, list); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4031 | arg = comma; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 4032 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4033 | |
| 4034 | new->list = list; |
| 4035 | break; |
| 4036 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4037 | |
| 4038 | case LOPT_PROXY: /* --dhcp-proxy */ |
| 4039 | daemon->override = 1; |
| 4040 | while (arg) { |
| 4041 | struct addr_list *new = opt_malloc(sizeof(struct addr_list)); |
| 4042 | comma = split(arg); |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 4043 | if (!(inet_pton(AF_INET, arg, &new->addr) > 0)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4044 | ret_err_free(_("bad dhcp-proxy address"), new); |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4045 | new->next = daemon->override_relays; |
| 4046 | daemon->override_relays = new; |
| 4047 | arg = comma; |
Wang Shanker | 4ded962 | 2020-12-04 10:17:35 +0800 | [diff] [blame] | 4048 | } |
| 4049 | break; |
| 4050 | |
| 4051 | case LOPT_PXE_VENDOR: /* --dhcp-pxe-vendor */ |
| 4052 | { |
| 4053 | while (arg) { |
| 4054 | struct dhcp_pxe_vendor *new = opt_malloc(sizeof(struct dhcp_pxe_vendor)); |
| 4055 | comma = split(arg); |
| 4056 | new->data = opt_string_alloc(arg); |
| 4057 | new->next = daemon->dhcp_pxe_vendors; |
| 4058 | daemon->dhcp_pxe_vendors = new; |
| 4059 | arg = comma; |
| 4060 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4061 | } |
| 4062 | break; |
Simon Kelley | ff7eea2 | 2013-09-04 18:01:38 +0100 | [diff] [blame] | 4063 | |
| 4064 | case LOPT_RELAY: /* --dhcp-relay */ |
| 4065 | { |
| 4066 | struct dhcp_relay *new = opt_malloc(sizeof(struct dhcp_relay)); |
| 4067 | comma = split(arg); |
| 4068 | new->interface = opt_string_alloc(split(comma)); |
| 4069 | new->iface_index = 0; |
| 4070 | if (inet_pton(AF_INET, arg, &new->local) && inet_pton(AF_INET, comma, &new->server)) |
| 4071 | { |
| 4072 | new->next = daemon->relay4; |
| 4073 | daemon->relay4 = new; |
| 4074 | } |
| 4075 | #ifdef HAVE_DHCP6 |
| 4076 | else if (inet_pton(AF_INET6, arg, &new->local) && inet_pton(AF_INET6, comma, &new->server)) |
| 4077 | { |
| 4078 | new->next = daemon->relay6; |
| 4079 | daemon->relay6 = new; |
| 4080 | } |
| 4081 | #endif |
| 4082 | else |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4083 | { |
| 4084 | free(new->interface); |
| 4085 | ret_err_free(_("Bad dhcp-relay"), new); |
| 4086 | } |
Simon Kelley | ff7eea2 | 2013-09-04 18:01:38 +0100 | [diff] [blame] | 4087 | |
| 4088 | break; |
| 4089 | } |
| 4090 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 4091 | #endif |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4092 | |
Simon Kelley | 8b37270 | 2012-03-09 17:45:10 +0000 | [diff] [blame] | 4093 | #ifdef HAVE_DHCP6 |
Simon Kelley | c4cd95d | 2013-10-10 20:58:11 +0100 | [diff] [blame] | 4094 | case LOPT_RA_PARAM: /* --ra-param */ |
| 4095 | if ((comma = split(arg))) |
Tarun Kundu | 024baf1 | 2022-06-28 10:56:47 -0700 | [diff] [blame] | 4096 | { |
| 4097 | struct ra_interface *new = opt_malloc(sizeof(struct ra_interface)); |
| 4098 | new->lifetime = -1; |
| 4099 | new->prio = 0; |
| 4100 | new->mtu = 0; |
| 4101 | new->mtu_name = NULL; |
| 4102 | new->name = opt_string_alloc(arg); |
| 4103 | new->reachable_time = 0; |
| 4104 | new->hop_limit = 0; |
Tarun Kundu | 41aa488 | 2022-07-05 10:44:13 -0700 | [diff] [blame] | 4105 | new->retrans_time = 0; |
Tarun Kundu | 024baf1 | 2022-06-28 10:56:47 -0700 | [diff] [blame] | 4106 | if (strcasestr(comma, "mtu:") == comma) |
| 4107 | { |
| 4108 | arg = comma + 4; |
| 4109 | if (!(comma = split(comma))) |
| 4110 | goto err; |
| 4111 | if (!strcasecmp(arg, "off")) |
| 4112 | new->mtu = -1; |
| 4113 | else if (!atoi_check(arg, &new->mtu)) |
| 4114 | new->mtu_name = opt_string_alloc(arg); |
| 4115 | else if (new->mtu < 1280) |
| 4116 | goto err; |
| 4117 | } |
| 4118 | if (strcasestr(comma, "high") == comma || strcasestr(comma, "low") == comma) |
| 4119 | { |
| 4120 | if (*comma == 'l' || *comma == 'L') |
| 4121 | new->prio = 0x18; |
| 4122 | else |
| 4123 | new->prio = 0x08; |
| 4124 | comma = split(comma); |
| 4125 | } |
| 4126 | arg = split(comma); |
| 4127 | if (comma && !atoi_check(comma, &new->interval)) |
| 4128 | goto err; |
| 4129 | comma = split(arg); |
| 4130 | if (arg && !atoi_check(arg, &new->lifetime)) |
| 4131 | goto err; |
| 4132 | arg = split(comma); |
Tarun Kundu | 41aa488 | 2022-07-05 10:44:13 -0700 | [diff] [blame] | 4133 | if (comma && !atoi_check(comma, (int *)&new->reachable_time)) |
| 4134 | goto err; |
| 4135 | comma = split(arg); |
| 4136 | if ((arg && !atoi_check(arg, (int *)&new->hop_limit)) || |
| 4137 | (comma && (!atoi_check(comma, (int *)&new->retrans_time)))) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4138 | { |
David Flamand | 005c46d | 2017-04-11 11:49:54 +0100 | [diff] [blame] | 4139 | err: |
Tarun Kundu | 024baf1 | 2022-06-28 10:56:47 -0700 | [diff] [blame] | 4140 | free(new->name); |
| 4141 | ret_err_free(_("bad RA-params"), new); |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4142 | } |
Tarun Kundu | 024baf1 | 2022-06-28 10:56:47 -0700 | [diff] [blame] | 4143 | if (new->hop_limit != 0) |
| 4144 | { |
| 4145 | setsockopt(daemon->icmp6fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, |
| 4146 | &new->hop_limit, sizeof(new->hop_limit)); |
| 4147 | } |
| 4148 | |
| 4149 | new->next = daemon->ra_interfaces; |
| 4150 | daemon->ra_interfaces = new; |
| 4151 | } |
Simon Kelley | c4cd95d | 2013-10-10 20:58:11 +0100 | [diff] [blame] | 4152 | break; |
| 4153 | |
Simon Kelley | 8b37270 | 2012-03-09 17:45:10 +0000 | [diff] [blame] | 4154 | case LOPT_DUID: /* --dhcp-duid */ |
| 4155 | if (!(comma = split(arg)) || !atoi_check(arg, (int *)&daemon->duid_enterprise)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4156 | ret_err(_("bad DUID")); |
Simon Kelley | 8b37270 | 2012-03-09 17:45:10 +0000 | [diff] [blame] | 4157 | else |
| 4158 | { |
| 4159 | daemon->duid_config_len = parse_hex(comma,(unsigned char *)comma, strlen(comma), NULL, NULL); |
| 4160 | daemon->duid_config = opt_malloc(daemon->duid_config_len); |
| 4161 | memcpy(daemon->duid_config, comma, daemon->duid_config_len); |
| 4162 | } |
| 4163 | break; |
| 4164 | #endif |
| 4165 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4166 | case 'V': /* --alias */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4167 | { |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 4168 | char *dash, *a[3] = { NULL, NULL, NULL }; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4169 | int k = 0; |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 4170 | struct doctor *new = opt_malloc(sizeof(struct doctor)); |
| 4171 | new->next = daemon->doctors; |
| 4172 | daemon->doctors = new; |
| 4173 | new->mask.s_addr = 0xffffffff; |
| 4174 | new->end.s_addr = 0; |
| 4175 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4176 | if ((a[0] = arg)) |
| 4177 | for (k = 1; k < 3; k++) |
| 4178 | { |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4179 | if (!(a[k] = split(a[k-1]))) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4180 | break; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4181 | unhide_metas(a[k]); |
| 4182 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4183 | |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 4184 | dash = split_chr(a[0], '-'); |
| 4185 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4186 | if ((k < 2) || |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 4187 | (!(inet_pton(AF_INET, a[0], &new->in) > 0)) || |
Simon Kelley | a3bd7e7 | 2018-07-19 22:00:08 +0100 | [diff] [blame] | 4188 | (!(inet_pton(AF_INET, a[1], &new->out) > 0)) || |
| 4189 | (k == 3 && !inet_pton(AF_INET, a[2], &new->mask))) |
| 4190 | ret_err(_("missing address in alias")); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4191 | |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 4192 | if (dash && |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 4193 | (!(inet_pton(AF_INET, dash, &new->end) > 0) || |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 4194 | !is_same_net(new->in, new->end, new->mask) || |
| 4195 | ntohl(new->in.s_addr) > ntohl(new->end.s_addr))) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4196 | ret_err_free(_("invalid alias range"), new); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4197 | |
| 4198 | break; |
| 4199 | } |
| 4200 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4201 | case LOPT_INTNAME: /* --interface-name */ |
Simon Kelley | b7cf754 | 2021-03-04 16:54:14 +0000 | [diff] [blame] | 4202 | case LOPT_DYNHOST: /* --dynamic-host */ |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4203 | { |
| 4204 | struct interface_name *new, **up; |
Simon Kelley | b7cf754 | 2021-03-04 16:54:14 +0000 | [diff] [blame] | 4205 | char *domain = arg; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4206 | |
Simon Kelley | b7cf754 | 2021-03-04 16:54:14 +0000 | [diff] [blame] | 4207 | arg = split(arg); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 4208 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4209 | new = opt_malloc(sizeof(struct interface_name)); |
Simon Kelley | b7cf754 | 2021-03-04 16:54:14 +0000 | [diff] [blame] | 4210 | memset(new, 0, sizeof(struct interface_name)); |
| 4211 | new->flags = IN4 | IN6; |
Simon Kelley | 376d48c | 2013-11-13 13:04:30 +0000 | [diff] [blame] | 4212 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4213 | /* Add to the end of the list, so that first name |
| 4214 | of an interface is used for PTR lookups. */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4215 | for (up = &daemon->int_names; *up; up = &((*up)->next)); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4216 | *up = new; |
Simon Kelley | b7cf754 | 2021-03-04 16:54:14 +0000 | [diff] [blame] | 4217 | |
| 4218 | while ((comma = split(arg))) |
Simon Kelley | f7029f5 | 2013-11-21 15:09:09 +0000 | [diff] [blame] | 4219 | { |
Simon Kelley | b7cf754 | 2021-03-04 16:54:14 +0000 | [diff] [blame] | 4220 | if (inet_pton(AF_INET, arg, &new->proto4)) |
| 4221 | new->flags |= INP4; |
| 4222 | else if (inet_pton(AF_INET6, arg, &new->proto6)) |
| 4223 | new->flags |= INP6; |
| 4224 | else |
| 4225 | break; |
| 4226 | |
| 4227 | arg = comma; |
| 4228 | } |
| 4229 | |
| 4230 | if ((comma = split_chr(arg, '/'))) |
| 4231 | { |
| 4232 | if (strcmp(comma, "4") == 0) |
| 4233 | new->flags &= ~IN6; |
| 4234 | else if (strcmp(comma, "6") == 0) |
| 4235 | new->flags &= ~IN4; |
Simon Kelley | f7029f5 | 2013-11-21 15:09:09 +0000 | [diff] [blame] | 4236 | else |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4237 | ret_err_free(gen_err, new); |
Simon Kelley | b7cf754 | 2021-03-04 16:54:14 +0000 | [diff] [blame] | 4238 | } |
| 4239 | |
| 4240 | new->intr = opt_string_alloc(arg); |
| 4241 | |
| 4242 | if (option == LOPT_DYNHOST) |
| 4243 | { |
| 4244 | if (!(new->flags & (INP4 | INP6))) |
| 4245 | ret_err(_("missing address in dynamic host")); |
| 4246 | |
| 4247 | if (!(new->flags & IN4) || !(new->flags & IN6)) |
| 4248 | arg = NULL; /* provoke error below */ |
| 4249 | |
| 4250 | new->flags &= ~(IN4 | IN6); |
| 4251 | } |
| 4252 | else |
| 4253 | { |
| 4254 | if (new->flags & (INP4 | INP6)) |
| 4255 | arg = NULL; /* provoke error below */ |
| 4256 | } |
| 4257 | |
| 4258 | if (!domain || !arg || !(new->name = canonicalise_opt(domain))) |
| 4259 | ret_err(option == LOPT_DYNHOST ? |
| 4260 | _("bad dynamic host") : _("bad interface name")); |
| 4261 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4262 | break; |
| 4263 | } |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 4264 | |
| 4265 | case LOPT_CNAME: /* --cname */ |
| 4266 | { |
| 4267 | struct cname *new; |
Simon Kelley | a1d973f | 2016-12-22 22:09:50 +0000 | [diff] [blame] | 4268 | char *alias, *target, *last, *pen; |
Simon Kelley | df3d54f | 2016-02-24 21:03:38 +0000 | [diff] [blame] | 4269 | int ttl = -1; |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4270 | |
Simon Kelley | a1d973f | 2016-12-22 22:09:50 +0000 | [diff] [blame] | 4271 | for (last = pen = NULL, comma = arg; comma; comma = split(comma)) |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 4272 | { |
Simon Kelley | a1d973f | 2016-12-22 22:09:50 +0000 | [diff] [blame] | 4273 | pen = last; |
| 4274 | last = comma; |
| 4275 | } |
| 4276 | |
| 4277 | if (!pen) |
| 4278 | ret_err(_("bad CNAME")); |
| 4279 | |
| 4280 | if (pen != arg && atoi_check(last, &ttl)) |
| 4281 | last = pen; |
| 4282 | |
| 4283 | target = canonicalise_opt(last); |
| 4284 | |
| 4285 | while (arg != last) |
| 4286 | { |
Petr Menšík | 56f0623 | 2018-03-06 23:13:32 +0000 | [diff] [blame] | 4287 | int arglen = strlen(arg); |
Simon Kelley | a1d973f | 2016-12-22 22:09:50 +0000 | [diff] [blame] | 4288 | alias = canonicalise_opt(arg); |
Simon Kelley | 5614413 | 2017-05-03 22:54:09 +0100 | [diff] [blame] | 4289 | |
| 4290 | if (!alias || !target) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4291 | { |
| 4292 | free(target); |
| 4293 | free(alias); |
| 4294 | ret_err(_("bad CNAME")); |
| 4295 | } |
Simon Kelley | a1d973f | 2016-12-22 22:09:50 +0000 | [diff] [blame] | 4296 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4297 | for (new = daemon->cnames; new; new = new->next) |
Simon Kelley | 5614413 | 2017-05-03 22:54:09 +0100 | [diff] [blame] | 4298 | if (hostname_isequal(new->alias, alias)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4299 | { |
| 4300 | free(target); |
| 4301 | free(alias); |
| 4302 | ret_err(_("duplicate CNAME")); |
| 4303 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4304 | new = opt_malloc(sizeof(struct cname)); |
| 4305 | new->next = daemon->cnames; |
| 4306 | daemon->cnames = new; |
| 4307 | new->alias = alias; |
| 4308 | new->target = target; |
Simon Kelley | df3d54f | 2016-02-24 21:03:38 +0000 | [diff] [blame] | 4309 | new->ttl = ttl; |
Simon Kelley | a1d973f | 2016-12-22 22:09:50 +0000 | [diff] [blame] | 4310 | |
Petr Menšík | 56f0623 | 2018-03-06 23:13:32 +0000 | [diff] [blame] | 4311 | for (arg += arglen+1; *arg && isspace(*arg); arg++); |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 4312 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4313 | |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 4314 | break; |
| 4315 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4316 | |
| 4317 | case LOPT_PTR: /* --ptr-record */ |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 4318 | { |
| 4319 | struct ptr_record *new; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 4320 | char *dom, *target = NULL; |
| 4321 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4322 | comma = split(arg); |
| 4323 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 4324 | if (!(dom = canonicalise_opt(arg)) || |
| 4325 | (comma && !(target = canonicalise_opt(comma)))) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4326 | { |
| 4327 | free(dom); |
| 4328 | free(target); |
| 4329 | ret_err(_("bad PTR record")); |
| 4330 | } |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 4331 | else |
| 4332 | { |
| 4333 | new = opt_malloc(sizeof(struct ptr_record)); |
| 4334 | new->next = daemon->ptr; |
| 4335 | daemon->ptr = new; |
| 4336 | new->name = dom; |
| 4337 | new->ptr = target; |
| 4338 | } |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 4339 | break; |
| 4340 | } |
| 4341 | |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 4342 | case LOPT_NAPTR: /* --naptr-record */ |
| 4343 | { |
| 4344 | char *a[7] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; |
| 4345 | int k = 0; |
| 4346 | struct naptr *new; |
| 4347 | int order, pref; |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4348 | char *name=NULL, *replace = NULL; |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 4349 | |
| 4350 | if ((a[0] = arg)) |
| 4351 | for (k = 1; k < 7; k++) |
| 4352 | if (!(a[k] = split(a[k-1]))) |
| 4353 | break; |
| 4354 | |
| 4355 | |
| 4356 | if (k < 6 || |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 4357 | !(name = canonicalise_opt(a[0])) || |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 4358 | !atoi_check16(a[1], &order) || |
| 4359 | !atoi_check16(a[2], &pref) || |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 4360 | (k == 7 && !(replace = canonicalise_opt(a[6])))) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4361 | { |
| 4362 | free(name); |
| 4363 | free(replace); |
| 4364 | ret_err(_("bad NAPTR record")); |
| 4365 | } |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 4366 | else |
| 4367 | { |
| 4368 | new = opt_malloc(sizeof(struct naptr)); |
| 4369 | new->next = daemon->naptr; |
| 4370 | daemon->naptr = new; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 4371 | new->name = name; |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 4372 | new->flags = opt_string_alloc(a[3]); |
| 4373 | new->services = opt_string_alloc(a[4]); |
| 4374 | new->regexp = opt_string_alloc(a[5]); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 4375 | new->replace = replace; |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 4376 | new->order = order; |
| 4377 | new->pref = pref; |
| 4378 | } |
| 4379 | break; |
| 4380 | } |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 4381 | |
| 4382 | case LOPT_RR: /* dns-rr */ |
| 4383 | { |
| 4384 | struct txt_record *new; |
Simon Kelley | 4caa86d | 2016-03-16 18:44:16 +0000 | [diff] [blame] | 4385 | size_t len = 0; |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 4386 | char *data; |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4387 | int class; |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 4388 | |
| 4389 | comma = split(arg); |
| 4390 | data = split(comma); |
| 4391 | |
| 4392 | new = opt_malloc(sizeof(struct txt_record)); |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4393 | new->name = NULL; |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 4394 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4395 | if (!atoi_check(comma, &class) || |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 4396 | !(new->name = canonicalise_opt(arg)) || |
Simon Kelley | 51931b8 | 2012-05-29 17:06:02 +0100 | [diff] [blame] | 4397 | (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] | 4398 | { |
| 4399 | free(new->name); |
| 4400 | ret_err_free(_("bad RR record"), new); |
| 4401 | } |
| 4402 | |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 4403 | new->len = 0; |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4404 | new->class = class; |
| 4405 | new->next = daemon->rr; |
| 4406 | daemon->rr = new; |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 4407 | |
| 4408 | if (data) |
| 4409 | { |
Simon Kelley | 974a6d0 | 2018-08-23 23:01:16 +0100 | [diff] [blame] | 4410 | new->txt = opt_malloc(len); |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 4411 | new->len = len; |
| 4412 | memcpy(new->txt, data, len); |
| 4413 | } |
| 4414 | |
| 4415 | break; |
| 4416 | } |
| 4417 | |
Simon Kelley | 974a6d0 | 2018-08-23 23:01:16 +0100 | [diff] [blame] | 4418 | case LOPT_CAA: /* --caa-record */ |
| 4419 | { |
| 4420 | struct txt_record *new; |
| 4421 | char *tag, *value; |
| 4422 | int flags; |
| 4423 | |
| 4424 | comma = split(arg); |
| 4425 | tag = split(comma); |
| 4426 | value = split(tag); |
| 4427 | |
| 4428 | new = opt_malloc(sizeof(struct txt_record)); |
| 4429 | new->next = daemon->rr; |
| 4430 | daemon->rr = new; |
| 4431 | |
| 4432 | if (!atoi_check(comma, &flags) || !tag || !value || !(new->name = canonicalise_opt(arg))) |
| 4433 | ret_err(_("bad CAA record")); |
| 4434 | |
| 4435 | unhide_metas(tag); |
| 4436 | unhide_metas(value); |
| 4437 | |
| 4438 | new->len = strlen(tag) + strlen(value) + 2; |
| 4439 | new->txt = opt_malloc(new->len); |
| 4440 | new->txt[0] = flags; |
| 4441 | new->txt[1] = strlen(tag); |
| 4442 | memcpy(&new->txt[2], tag, strlen(tag)); |
| 4443 | memcpy(&new->txt[2 + strlen(tag)], value, strlen(value)); |
| 4444 | new->class = T_CAA; |
| 4445 | |
| 4446 | break; |
| 4447 | } |
| 4448 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4449 | case 'Y': /* --txt-record */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4450 | { |
| 4451 | struct txt_record *new; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4452 | unsigned char *p, *cnt; |
| 4453 | size_t len; |
| 4454 | |
| 4455 | comma = split(arg); |
| 4456 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4457 | new = opt_malloc(sizeof(struct txt_record)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4458 | new->class = C_IN; |
Simon Kelley | fec216d | 2014-03-27 20:54:34 +0000 | [diff] [blame] | 4459 | new->stat = 0; |
| 4460 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 4461 | if (!(new->name = canonicalise_opt(arg))) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4462 | ret_err_free(_("bad TXT record"), new); |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4463 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4464 | new->next = daemon->txt; |
| 4465 | daemon->txt = new; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4466 | len = comma ? strlen(comma) : 0; |
| 4467 | len += (len/255) + 1; /* room for extra counts */ |
| 4468 | new->txt = p = opt_malloc(len); |
| 4469 | |
| 4470 | cnt = p++; |
| 4471 | *cnt = 0; |
| 4472 | |
| 4473 | while (comma && *comma) |
| 4474 | { |
| 4475 | unsigned char c = (unsigned char)*comma++; |
| 4476 | |
| 4477 | if (c == ',' || *cnt == 255) |
| 4478 | { |
| 4479 | if (c != ',') |
| 4480 | comma--; |
| 4481 | cnt = p++; |
| 4482 | *cnt = 0; |
| 4483 | } |
| 4484 | else |
| 4485 | { |
| 4486 | *p++ = unhide_meta(c); |
| 4487 | (*cnt)++; |
| 4488 | } |
| 4489 | } |
| 4490 | |
| 4491 | new->len = p - new->txt; |
| 4492 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4493 | break; |
| 4494 | } |
| 4495 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4496 | case 'W': /* --srv-host */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4497 | { |
| 4498 | int port = 1, priority = 0, weight = 0; |
| 4499 | char *name, *target = NULL; |
| 4500 | struct mx_srv_record *new; |
| 4501 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4502 | comma = split(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4503 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 4504 | if (!(name = canonicalise_opt(arg))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4505 | ret_err(_("bad SRV record")); |
| 4506 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4507 | if (comma) |
| 4508 | { |
| 4509 | arg = comma; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4510 | comma = split(arg); |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4511 | if (!(target = canonicalise_opt(arg))) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4512 | ret_err_free(_("bad SRV target"), name); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4513 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4514 | if (comma) |
| 4515 | { |
| 4516 | arg = comma; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4517 | comma = split(arg); |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 4518 | if (!atoi_check16(arg, &port)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4519 | { |
| 4520 | free(name); |
| 4521 | ret_err_free(_("invalid port number"), target); |
| 4522 | } |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4523 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4524 | if (comma) |
| 4525 | { |
| 4526 | arg = comma; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4527 | comma = split(arg); |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 4528 | if (!atoi_check16(arg, &priority)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4529 | { |
| 4530 | free(name); |
| 4531 | ret_err_free(_("invalid priority"), target); |
| 4532 | } |
Simon Kelley | 407a1f3 | 2016-03-01 17:06:07 +0000 | [diff] [blame] | 4533 | if (comma && !atoi_check16(comma, &weight)) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4534 | { |
| 4535 | free(name); |
| 4536 | ret_err_free(_("invalid weight"), target); |
| 4537 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4538 | } |
| 4539 | } |
| 4540 | } |
| 4541 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4542 | new = opt_malloc(sizeof(struct mx_srv_record)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4543 | new->next = daemon->mxnames; |
| 4544 | daemon->mxnames = new; |
| 4545 | new->issrv = 1; |
| 4546 | new->name = name; |
| 4547 | new->target = target; |
| 4548 | new->srvport = port; |
| 4549 | new->priority = priority; |
| 4550 | new->weight = weight; |
| 4551 | break; |
| 4552 | } |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 4553 | |
Simon Kelley | e759d42 | 2012-03-16 13:18:57 +0000 | [diff] [blame] | 4554 | case LOPT_HOST_REC: /* --host-record */ |
| 4555 | { |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4556 | struct host_record *new; |
Simon Kelley | df3d54f | 2016-02-24 21:03:38 +0000 | [diff] [blame] | 4557 | |
Simon Kelley | e759d42 | 2012-03-16 13:18:57 +0000 | [diff] [blame] | 4558 | if (!arg || !(comma = split(arg))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4559 | ret_err(_("Bad host-record")); |
| 4560 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4561 | new = opt_malloc(sizeof(struct host_record)); |
| 4562 | memset(new, 0, sizeof(struct host_record)); |
| 4563 | new->ttl = -1; |
Simon Kelley | 157d8cf | 2019-10-25 17:46:49 +0100 | [diff] [blame] | 4564 | new->flags = 0; |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4565 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4566 | while (arg) |
| 4567 | { |
Simon Kelley | cc921df | 2019-01-02 22:48:59 +0000 | [diff] [blame] | 4568 | union all_addr addr; |
Simon Kelley | df3d54f | 2016-02-24 21:03:38 +0000 | [diff] [blame] | 4569 | char *dig; |
| 4570 | |
| 4571 | for (dig = arg; *dig != 0; dig++) |
| 4572 | if (*dig < '0' || *dig > '9') |
| 4573 | break; |
| 4574 | if (*dig == 0) |
| 4575 | new->ttl = atoi(arg); |
Simon Kelley | cc921df | 2019-01-02 22:48:59 +0000 | [diff] [blame] | 4576 | else if (inet_pton(AF_INET, arg, &addr.addr4)) |
Simon Kelley | 157d8cf | 2019-10-25 17:46:49 +0100 | [diff] [blame] | 4577 | { |
| 4578 | new->addr = addr.addr4; |
| 4579 | new->flags |= HR_4; |
| 4580 | } |
Simon Kelley | cc921df | 2019-01-02 22:48:59 +0000 | [diff] [blame] | 4581 | else if (inet_pton(AF_INET6, arg, &addr.addr6)) |
Simon Kelley | 157d8cf | 2019-10-25 17:46:49 +0100 | [diff] [blame] | 4582 | { |
| 4583 | new->addr6 = addr.addr6; |
| 4584 | new->flags |= HR_6; |
| 4585 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4586 | else |
| 4587 | { |
| 4588 | int nomem; |
| 4589 | char *canon = canonicalise(arg, &nomem); |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4590 | struct name_list *nl; |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4591 | if (!canon) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4592 | { |
| 4593 | struct name_list *tmp = new->names, *next; |
| 4594 | for (tmp = new->names; tmp; tmp = next) |
| 4595 | { |
| 4596 | next = tmp->next; |
| 4597 | free(tmp); |
| 4598 | } |
| 4599 | ret_err_free(_("Bad name in host-record"), new); |
| 4600 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4601 | |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4602 | nl = opt_malloc(sizeof(struct name_list)); |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4603 | nl->name = canon; |
| 4604 | /* keep order, so that PTR record goes to first name */ |
| 4605 | nl->next = NULL; |
| 4606 | if (!new->names) |
| 4607 | new->names = nl; |
| 4608 | else |
| 4609 | { |
| 4610 | struct name_list *tmp; |
| 4611 | for (tmp = new->names; tmp->next; tmp = tmp->next); |
| 4612 | tmp->next = nl; |
| 4613 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4614 | } |
Simon Kelley | e4807d8 | 2012-09-27 21:52:26 +0100 | [diff] [blame] | 4615 | |
| 4616 | arg = comma; |
| 4617 | comma = split(arg); |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4618 | } |
Simon Kelley | e759d42 | 2012-03-16 13:18:57 +0000 | [diff] [blame] | 4619 | |
| 4620 | /* Keep list order */ |
| 4621 | if (!daemon->host_records_tail) |
| 4622 | daemon->host_records = new; |
| 4623 | else |
| 4624 | daemon->host_records_tail->next = new; |
| 4625 | new->next = NULL; |
| 4626 | daemon->host_records_tail = new; |
| 4627 | break; |
| 4628 | } |
Simon Kelley | 0fc2f31 | 2014-01-08 10:26:58 +0000 | [diff] [blame] | 4629 | |
| 4630 | #ifdef HAVE_DNSSEC |
Simon Kelley | f3e5787 | 2018-07-20 21:10:48 +0100 | [diff] [blame] | 4631 | case LOPT_DNSSEC_STAMP: /* --dnssec-timestamp */ |
Simon Kelley | f6e62e2 | 2015-03-01 18:17:54 +0000 | [diff] [blame] | 4632 | daemon->timestamp_file = opt_string_alloc(arg); |
| 4633 | break; |
| 4634 | |
Simon Kelley | f3e5787 | 2018-07-20 21:10:48 +0100 | [diff] [blame] | 4635 | case LOPT_DNSSEC_CHECK: /* --dnssec-check-unsigned */ |
Simon Kelley | a691853 | 2018-04-15 16:20:52 +0100 | [diff] [blame] | 4636 | if (arg) |
| 4637 | { |
| 4638 | if (strcmp(arg, "no") == 0) |
| 4639 | set_option_bool(OPT_DNSSEC_IGN_NS); |
| 4640 | else |
| 4641 | ret_err(_("bad value for dnssec-check-unsigned")); |
| 4642 | } |
| 4643 | break; |
| 4644 | |
Simon Kelley | f3e5787 | 2018-07-20 21:10:48 +0100 | [diff] [blame] | 4645 | case LOPT_TRUST_ANCHOR: /* --trust-anchor */ |
Simon Kelley | 0fc2f31 | 2014-01-08 10:26:58 +0000 | [diff] [blame] | 4646 | { |
Simon Kelley | ee41586 | 2014-02-11 11:07:22 +0000 | [diff] [blame] | 4647 | struct ds_config *new = opt_malloc(sizeof(struct ds_config)); |
| 4648 | char *cp, *cp1, *keyhex, *digest, *algo = NULL; |
| 4649 | int len; |
Simon Kelley | cbf13a2 | 2014-01-25 17:59:14 +0000 | [diff] [blame] | 4650 | |
| 4651 | new->class = C_IN; |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4652 | new->name = NULL; |
Simon Kelley | 0fc2f31 | 2014-01-08 10:26:58 +0000 | [diff] [blame] | 4653 | |
Simon Kelley | cbf13a2 | 2014-01-25 17:59:14 +0000 | [diff] [blame] | 4654 | if ((comma = split(arg)) && (algo = split(comma))) |
| 4655 | { |
| 4656 | int class = 0; |
| 4657 | if (strcmp(comma, "IN") == 0) |
| 4658 | class = C_IN; |
| 4659 | else if (strcmp(comma, "CH") == 0) |
| 4660 | class = C_CHAOS; |
| 4661 | else if (strcmp(comma, "HS") == 0) |
| 4662 | class = C_HESIOD; |
| 4663 | |
| 4664 | if (class != 0) |
| 4665 | { |
| 4666 | new->class = class; |
| 4667 | comma = algo; |
| 4668 | algo = split(comma); |
| 4669 | } |
| 4670 | } |
| 4671 | |
Simon Kelley | ee41586 | 2014-02-11 11:07:22 +0000 | [diff] [blame] | 4672 | if (!comma || !algo || !(digest = split(algo)) || !(keyhex = split(digest)) || |
| 4673 | !atoi_check16(comma, &new->keytag) || |
| 4674 | !atoi_check8(algo, &new->algo) || |
| 4675 | !atoi_check8(digest, &new->digest_type) || |
Simon Kelley | cbf13a2 | 2014-01-25 17:59:14 +0000 | [diff] [blame] | 4676 | !(new->name = canonicalise_opt(arg))) |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 4677 | ret_err_free(_("bad trust anchor"), new); |
Simon Kelley | cbf13a2 | 2014-01-25 17:59:14 +0000 | [diff] [blame] | 4678 | |
Simon Kelley | 0fc2f31 | 2014-01-08 10:26:58 +0000 | [diff] [blame] | 4679 | /* Upper bound on length */ |
Simon Kelley | ee41586 | 2014-02-11 11:07:22 +0000 | [diff] [blame] | 4680 | len = (2*strlen(keyhex))+1; |
| 4681 | new->digest = opt_malloc(len); |
| 4682 | unhide_metas(keyhex); |
| 4683 | /* 4034: "Whitespace is allowed within digits" */ |
| 4684 | for (cp = keyhex; *cp; ) |
| 4685 | if (isspace(*cp)) |
| 4686 | for (cp1 = cp; *cp1; cp1++) |
| 4687 | *cp1 = *(cp1+1); |
| 4688 | else |
| 4689 | cp++; |
| 4690 | 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] | 4691 | { |
| 4692 | free(new->name); |
| 4693 | ret_err_free(_("bad HEX in trust anchor"), new); |
| 4694 | } |
Simon Kelley | 0fc2f31 | 2014-01-08 10:26:58 +0000 | [diff] [blame] | 4695 | |
Simon Kelley | ee41586 | 2014-02-11 11:07:22 +0000 | [diff] [blame] | 4696 | new->next = daemon->ds; |
| 4697 | daemon->ds = new; |
| 4698 | |
Simon Kelley | 0fc2f31 | 2014-01-08 10:26:58 +0000 | [diff] [blame] | 4699 | break; |
| 4700 | } |
| 4701 | #endif |
Kyle Swenson | 545712c | 2021-11-17 12:25:04 -0700 | [diff] [blame] | 4702 | /* CRADLEPOINT */ |
| 4703 | /* This option (OPT_EDNS_OPTION) is required to tack a(n) owner record onto a DNS request: |
| 4704 | * Option Code: Owner (reserved) 4 (0x00 0x04) |
| 4705 | * Option Length: 19 ("Cradlepoint" + device_id (obtained from OpenDNS)) (0x00 0x13) |
| 4706 | * Option Data: "Cradlepoint" + device_id (an 4 byte identifier) |
| 4707 | * |
| 4708 | * The EDNS option is passed in like this: |
| 4709 | * --edns-option=4,CradlepointAABBCCDD |
| 4710 | */ |
| 4711 | case LOPT_EDNS_OPTION: |
| 4712 | { |
| 4713 | unsigned char *tmp; |
| 4714 | int option_code, option_len = 0; |
| 4715 | |
| 4716 | comma = split(arg); |
| 4717 | |
| 4718 | if (*arg == 0 || !atoi_check16(arg, &option_code)) |
| 4719 | { |
| 4720 | option = '?'; |
| 4721 | ret_err(_("invalid EDNS option code")); |
| 4722 | break; |
| 4723 | } |
| 4724 | |
| 4725 | if (comma && |
| 4726 | (option_len = str_unescape_c_string(comma, comma)) <= 0) |
| 4727 | { |
| 4728 | option = '?'; |
| 4729 | ret_err(_("invalid EDNS option data")); |
| 4730 | break; |
| 4731 | } |
| 4732 | tmp = opt_malloc(daemon->edns_options_len + 4 + option_len); |
| 4733 | |
| 4734 | if (daemon->edns_options_len > 0) |
| 4735 | { |
| 4736 | memcpy(tmp, daemon->edns_options, daemon->edns_options_len); |
| 4737 | free(daemon->edns_options); |
| 4738 | } |
| 4739 | daemon->edns_options = tmp; |
| 4740 | tmp += daemon->edns_options_len; |
| 4741 | PUTSHORT(option_code, tmp); |
| 4742 | PUTSHORT(option_len, tmp); |
| 4743 | memcpy(tmp, comma, option_len); |
| 4744 | daemon->edns_options_len += 4 + option_len; |
| 4745 | my_syslog(LOG_DEBUG, _("EDNS Option %d added length %d"), option_code, |
| 4746 | daemon->edns_options_len); |
| 4747 | |
| 4748 | break; |
| 4749 | } |
| 4750 | |
| 4751 | case LOPT_SSID_MAP: |
| 4752 | { |
| 4753 | char *err; |
| 4754 | |
| 4755 | unhide_metas(arg); |
| 4756 | |
| 4757 | if ((err = opendns_parse_device_id_opt(arg)) != NULL) { |
| 4758 | /* int vs pointer warning return err; */ |
| 4759 | ret_err(_("opendns parse device id failed")); |
| 4760 | } |
| 4761 | |
| 4762 | break; |
| 4763 | } |
Kyle Swenson | ba77fe8 | 2021-11-19 09:33:46 -0700 | [diff] [blame] | 4764 | case LOPT_EDNS_RESTRICT: |
| 4765 | { |
| 4766 | set_option_bool(OPT_EDNS_RESTRICT); |
| 4767 | break; |
| 4768 | } |
Kyle Swenson | 545712c | 2021-11-17 12:25:04 -0700 | [diff] [blame] | 4769 | /* CRADLEPOINT */ |
| 4770 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 4771 | default: |
Simon Kelley | 0fc2f31 | 2014-01-08 10:26:58 +0000 | [diff] [blame] | 4772 | 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] | 4773 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4774 | } |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4775 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4776 | return 1; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4777 | } |
| 4778 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4779 | static void read_file(char *file, FILE *f, int hard_opt) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4780 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4781 | volatile int lineno = 0; |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4782 | char *buff = daemon->namebuff; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4783 | |
| 4784 | while (fgets(buff, MAXDNAME, f)) |
| 4785 | { |
Simon Kelley | 7b1eae4 | 2014-02-20 13:43:28 +0000 | [diff] [blame] | 4786 | int white, i; |
| 4787 | volatile int option = (hard_opt == LOPT_REV_SERV) ? 0 : hard_opt; |
Simon Kelley | 13dee6f | 2017-02-28 16:51:58 +0000 | [diff] [blame] | 4788 | char *errmess, *p, *arg, *start; |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4789 | size_t len; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 4790 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4791 | /* Memory allocation failure longjmps here if mem_recover == 1 */ |
Simon Kelley | 7b1eae4 | 2014-02-20 13:43:28 +0000 | [diff] [blame] | 4792 | if (option != 0 || hard_opt == LOPT_REV_SERV) |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4793 | { |
| 4794 | if (setjmp(mem_jmp)) |
| 4795 | continue; |
| 4796 | mem_recover = 1; |
| 4797 | } |
| 4798 | |
Simon Kelley | 13dee6f | 2017-02-28 16:51:58 +0000 | [diff] [blame] | 4799 | arg = NULL; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4800 | lineno++; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4801 | errmess = NULL; |
| 4802 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4803 | /* Implement quotes, inside quotes we allow \\ \" \n and \t |
| 4804 | metacharacters get hidden also strip comments */ |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4805 | for (white = 1, p = buff; *p; p++) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4806 | { |
| 4807 | if (*p == '"') |
| 4808 | { |
| 4809 | memmove(p, p+1, strlen(p+1)+1); |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4810 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4811 | for(; *p && *p != '"'; p++) |
| 4812 | { |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 4813 | if (*p == '\\' && strchr("\"tnebr\\", p[1])) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4814 | { |
| 4815 | if (p[1] == 't') |
| 4816 | p[1] = '\t'; |
| 4817 | else if (p[1] == 'n') |
| 4818 | p[1] = '\n'; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4819 | else if (p[1] == 'b') |
| 4820 | p[1] = '\b'; |
| 4821 | else if (p[1] == 'r') |
| 4822 | p[1] = '\r'; |
Simon Kelley | 6b01084 | 2007-02-12 20:32:07 +0000 | [diff] [blame] | 4823 | else if (p[1] == 'e') /* escape */ |
| 4824 | p[1] = '\033'; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4825 | memmove(p, p+1, strlen(p+1)+1); |
| 4826 | } |
| 4827 | *p = hide_meta(*p); |
| 4828 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4829 | |
| 4830 | if (*p == 0) |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4831 | { |
| 4832 | errmess = _("missing \""); |
| 4833 | goto oops; |
| 4834 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4835 | |
| 4836 | memmove(p, p+1, strlen(p+1)+1); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4837 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4838 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4839 | if (isspace(*p)) |
| 4840 | { |
| 4841 | *p = ' '; |
| 4842 | white = 1; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4843 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4844 | else |
| 4845 | { |
| 4846 | if (white && *p == '#') |
| 4847 | { |
| 4848 | *p = 0; |
| 4849 | break; |
| 4850 | } |
| 4851 | white = 0; |
| 4852 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4853 | } |
| 4854 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4855 | |
| 4856 | /* strip leading spaces */ |
| 4857 | for (start = buff; *start && *start == ' '; start++); |
| 4858 | |
| 4859 | /* strip trailing spaces */ |
| 4860 | for (len = strlen(start); (len != 0) && (start[len-1] == ' '); len--); |
| 4861 | |
| 4862 | if (len == 0) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4863 | continue; |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4864 | else |
| 4865 | start[len] = 0; |
| 4866 | |
Simon Kelley | 611ebc5 | 2012-07-16 16:23:46 +0100 | [diff] [blame] | 4867 | if (option != 0) |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4868 | arg = start; |
| 4869 | else if ((p=strchr(start, '='))) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4870 | { |
| 4871 | /* allow spaces around "=" */ |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4872 | for (arg = p+1; *arg == ' '; arg++); |
| 4873 | for (; p >= start && (*p == ' ' || *p == '='); p--) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4874 | *p = 0; |
| 4875 | } |
| 4876 | else |
| 4877 | arg = NULL; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 4878 | |
Simon Kelley | 611ebc5 | 2012-07-16 16:23:46 +0100 | [diff] [blame] | 4879 | if (option == 0) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 4880 | { |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 4881 | for (option = 0, i = 0; opts[i].name; i++) |
| 4882 | if (strcmp(opts[i].name, start) == 0) |
| 4883 | { |
| 4884 | option = opts[i].val; |
| 4885 | break; |
| 4886 | } |
| 4887 | |
| 4888 | if (!option) |
| 4889 | errmess = _("bad option"); |
| 4890 | else if (opts[i].has_arg == 0 && arg) |
| 4891 | errmess = _("extraneous parameter"); |
| 4892 | else if (opts[i].has_arg == 1 && !arg) |
| 4893 | errmess = _("missing parameter"); |
Simon Kelley | 7b1eae4 | 2014-02-20 13:43:28 +0000 | [diff] [blame] | 4894 | else if (hard_opt == LOPT_REV_SERV && option != 'S' && option != LOPT_REV_SERV) |
| 4895 | errmess = _("illegal option"); |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 4896 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4897 | |
| 4898 | oops: |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 4899 | if (errmess) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4900 | strcpy(daemon->namebuff, errmess); |
| 4901 | |
Simon Kelley | 9bafdc6 | 2018-08-21 22:53:38 +0100 | [diff] [blame] | 4902 | 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] | 4903 | { |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4904 | 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] | 4905 | if (hard_opt != 0) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4906 | my_syslog(LOG_ERR, "%s", daemon->namebuff); |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 4907 | else |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4908 | die("%s", daemon->namebuff, EC_BADCONF); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 4909 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4910 | } |
| 4911 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 4912 | mem_recover = 0; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4913 | fclose(f); |
| 4914 | } |
| 4915 | |
Simon Kelley | 4f7bb57 | 2018-03-08 18:47:08 +0000 | [diff] [blame] | 4916 | #if defined(HAVE_DHCP) && defined(HAVE_INOTIFY) |
Simon Kelley | 70d1873 | 2015-01-31 19:59:29 +0000 | [diff] [blame] | 4917 | int option_read_dynfile(char *file, int flags) |
Simon Kelley | 5f4dc5c | 2015-01-20 20:51:02 +0000 | [diff] [blame] | 4918 | { |
Simon Kelley | f9c8637 | 2015-02-03 21:52:48 +0000 | [diff] [blame] | 4919 | my_syslog(MS_DHCP | LOG_INFO, _("read %s"), file); |
| 4920 | |
Simon Kelley | 70d1873 | 2015-01-31 19:59:29 +0000 | [diff] [blame] | 4921 | if (flags & AH_DHCP_HST) |
| 4922 | return one_file(file, LOPT_BANK); |
| 4923 | else if (flags & AH_DHCP_OPT) |
| 4924 | return one_file(file, LOPT_OPTS); |
Simon Kelley | f9c8637 | 2015-02-03 21:52:48 +0000 | [diff] [blame] | 4925 | |
Simon Kelley | 70d1873 | 2015-01-31 19:59:29 +0000 | [diff] [blame] | 4926 | return 0; |
Simon Kelley | 5f4dc5c | 2015-01-20 20:51:02 +0000 | [diff] [blame] | 4927 | } |
| 4928 | #endif |
| 4929 | |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 4930 | static int one_file(char *file, int hard_opt) |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4931 | { |
| 4932 | FILE *f; |
| 4933 | int nofile_ok = 0; |
| 4934 | static int read_stdin = 0; |
| 4935 | static struct fileread { |
| 4936 | dev_t dev; |
| 4937 | ino_t ino; |
| 4938 | struct fileread *next; |
| 4939 | } *filesread = NULL; |
| 4940 | |
| 4941 | if (hard_opt == '7') |
| 4942 | { |
| 4943 | /* default conf-file reading */ |
| 4944 | hard_opt = 0; |
| 4945 | nofile_ok = 1; |
| 4946 | } |
| 4947 | |
| 4948 | if (hard_opt == 0 && strcmp(file, "-") == 0) |
| 4949 | { |
| 4950 | if (read_stdin == 1) |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 4951 | return 1; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4952 | read_stdin = 1; |
| 4953 | file = "stdin"; |
| 4954 | f = stdin; |
| 4955 | } |
| 4956 | else |
| 4957 | { |
| 4958 | /* ignore repeated files. */ |
| 4959 | struct stat statbuf; |
| 4960 | |
| 4961 | if (hard_opt == 0 && stat(file, &statbuf) == 0) |
| 4962 | { |
| 4963 | struct fileread *r; |
| 4964 | |
| 4965 | for (r = filesread; r; r = r->next) |
| 4966 | if (r->dev == statbuf.st_dev && r->ino == statbuf.st_ino) |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 4967 | return 1; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4968 | |
| 4969 | r = safe_malloc(sizeof(struct fileread)); |
| 4970 | r->next = filesread; |
| 4971 | filesread = r; |
| 4972 | r->dev = statbuf.st_dev; |
| 4973 | r->ino = statbuf.st_ino; |
| 4974 | } |
| 4975 | |
| 4976 | if (!(f = fopen(file, "r"))) |
| 4977 | { |
| 4978 | if (errno == ENOENT && nofile_ok) |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 4979 | return 1; /* No conffile, all done. */ |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4980 | else |
| 4981 | { |
| 4982 | char *str = _("cannot read %s: %s"); |
| 4983 | if (hard_opt != 0) |
| 4984 | { |
| 4985 | my_syslog(LOG_ERR, str, file, strerror(errno)); |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 4986 | return 0; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4987 | } |
| 4988 | else |
| 4989 | die(str, file, EC_FILE); |
| 4990 | } |
| 4991 | } |
| 4992 | } |
| 4993 | |
| 4994 | read_file(file, f, hard_opt); |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 4995 | return 1; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4996 | } |
| 4997 | |
| 4998 | /* expand any name which is a directory */ |
| 4999 | struct hostsfile *expand_filelist(struct hostsfile *list) |
| 5000 | { |
Simon Kelley | 19c51cf | 2014-03-18 22:38:30 +0000 | [diff] [blame] | 5001 | unsigned int i; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5002 | struct hostsfile *ah; |
| 5003 | |
Simon Kelley | 19c51cf | 2014-03-18 22:38:30 +0000 | [diff] [blame] | 5004 | /* find largest used index */ |
| 5005 | for (i = SRC_AH, ah = list; ah; ah = ah->next) |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5006 | { |
| 5007 | if (i <= ah->index) |
| 5008 | i = ah->index + 1; |
| 5009 | |
| 5010 | if (ah->flags & AH_DIR) |
| 5011 | ah->flags |= AH_INACTIVE; |
| 5012 | else |
| 5013 | ah->flags &= ~AH_INACTIVE; |
| 5014 | } |
| 5015 | |
| 5016 | for (ah = list; ah; ah = ah->next) |
| 5017 | if (!(ah->flags & AH_INACTIVE)) |
| 5018 | { |
| 5019 | struct stat buf; |
| 5020 | if (stat(ah->fname, &buf) != -1 && S_ISDIR(buf.st_mode)) |
| 5021 | { |
| 5022 | DIR *dir_stream; |
| 5023 | struct dirent *ent; |
| 5024 | |
| 5025 | /* don't read this as a file */ |
| 5026 | ah->flags |= AH_INACTIVE; |
Simon Kelley | 5f4dc5c | 2015-01-20 20:51:02 +0000 | [diff] [blame] | 5027 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5028 | if (!(dir_stream = opendir(ah->fname))) |
| 5029 | my_syslog(LOG_ERR, _("cannot access directory %s: %s"), |
| 5030 | ah->fname, strerror(errno)); |
| 5031 | else |
| 5032 | { |
| 5033 | while ((ent = readdir(dir_stream))) |
| 5034 | { |
| 5035 | size_t lendir = strlen(ah->fname); |
| 5036 | size_t lenfile = strlen(ent->d_name); |
| 5037 | struct hostsfile *ah1; |
| 5038 | char *path; |
| 5039 | |
| 5040 | /* ignore emacs backups and dotfiles */ |
| 5041 | if (lenfile == 0 || |
| 5042 | ent->d_name[lenfile - 1] == '~' || |
| 5043 | (ent->d_name[0] == '#' && ent->d_name[lenfile - 1] == '#') || |
| 5044 | ent->d_name[0] == '.') |
| 5045 | continue; |
| 5046 | |
| 5047 | /* see if we have an existing record. |
| 5048 | dir is ah->fname |
| 5049 | file is ent->d_name |
| 5050 | path to match is ah1->fname */ |
| 5051 | |
| 5052 | for (ah1 = list; ah1; ah1 = ah1->next) |
| 5053 | { |
| 5054 | if (lendir < strlen(ah1->fname) && |
| 5055 | strstr(ah1->fname, ah->fname) == ah1->fname && |
| 5056 | ah1->fname[lendir] == '/' && |
| 5057 | strcmp(ah1->fname + lendir + 1, ent->d_name) == 0) |
| 5058 | { |
| 5059 | ah1->flags &= ~AH_INACTIVE; |
| 5060 | break; |
| 5061 | } |
| 5062 | } |
| 5063 | |
| 5064 | /* make new record */ |
| 5065 | if (!ah1) |
| 5066 | { |
| 5067 | if (!(ah1 = whine_malloc(sizeof(struct hostsfile)))) |
| 5068 | continue; |
| 5069 | |
| 5070 | if (!(path = whine_malloc(lendir + lenfile + 2))) |
| 5071 | { |
| 5072 | free(ah1); |
| 5073 | continue; |
| 5074 | } |
| 5075 | |
| 5076 | strcpy(path, ah->fname); |
| 5077 | strcat(path, "/"); |
| 5078 | strcat(path, ent->d_name); |
| 5079 | ah1->fname = path; |
| 5080 | ah1->index = i++; |
| 5081 | ah1->flags = AH_DIR; |
| 5082 | ah1->next = list; |
| 5083 | list = ah1; |
| 5084 | } |
| 5085 | |
| 5086 | /* inactivate record if not regular file */ |
| 5087 | if ((ah1->flags & AH_DIR) && stat(ah1->fname, &buf) != -1 && !S_ISREG(buf.st_mode)) |
| 5088 | ah1->flags |= AH_INACTIVE; |
| 5089 | |
| 5090 | } |
| 5091 | closedir(dir_stream); |
| 5092 | } |
| 5093 | } |
| 5094 | } |
| 5095 | |
| 5096 | return list; |
| 5097 | } |
| 5098 | |
Simon Kelley | 7b1eae4 | 2014-02-20 13:43:28 +0000 | [diff] [blame] | 5099 | void read_servers_file(void) |
| 5100 | { |
| 5101 | FILE *f; |
| 5102 | |
| 5103 | if (!(f = fopen(daemon->servers_file, "r"))) |
| 5104 | { |
| 5105 | my_syslog(LOG_ERR, _("cannot read %s: %s"), daemon->servers_file, strerror(errno)); |
| 5106 | return; |
| 5107 | } |
| 5108 | |
| 5109 | mark_servers(SERV_FROM_FILE); |
| 5110 | cleanup_servers(); |
| 5111 | |
| 5112 | read_file(daemon->servers_file, f, LOPT_REV_SERV); |
| 5113 | } |
| 5114 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5115 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 5116 | #ifdef HAVE_DHCP |
Simon Kelley | 4f7bb57 | 2018-03-08 18:47:08 +0000 | [diff] [blame] | 5117 | static void clear_dynamic_conf(void) |
| 5118 | { |
| 5119 | struct dhcp_config *configs, *cp, **up; |
| 5120 | |
| 5121 | /* remove existing... */ |
| 5122 | for (up = &daemon->dhcp_conf, configs = daemon->dhcp_conf; configs; configs = cp) |
| 5123 | { |
| 5124 | cp = configs->next; |
| 5125 | |
| 5126 | if (configs->flags & CONFIG_BANK) |
| 5127 | { |
| 5128 | struct hwaddr_config *mac, *tmp; |
| 5129 | struct dhcp_netid_list *list, *tmplist; |
| 5130 | |
| 5131 | for (mac = configs->hwaddr; mac; mac = tmp) |
| 5132 | { |
| 5133 | tmp = mac->next; |
| 5134 | free(mac); |
| 5135 | } |
| 5136 | |
| 5137 | if (configs->flags & CONFIG_CLID) |
| 5138 | free(configs->clid); |
| 5139 | |
| 5140 | for (list = configs->netid; list; list = tmplist) |
| 5141 | { |
| 5142 | free(list->list); |
| 5143 | tmplist = list->next; |
| 5144 | free(list); |
| 5145 | } |
| 5146 | |
| 5147 | if (configs->flags & CONFIG_NAME) |
| 5148 | free(configs->hostname); |
| 5149 | |
| 5150 | *up = configs->next; |
| 5151 | free(configs); |
| 5152 | } |
| 5153 | else |
| 5154 | up = &configs->next; |
| 5155 | } |
| 5156 | } |
| 5157 | |
| 5158 | static void clear_dynamic_opt(void) |
| 5159 | { |
| 5160 | struct dhcp_opt *opts, *cp, **up; |
| 5161 | struct dhcp_netid *id, *next; |
| 5162 | |
| 5163 | for (up = &daemon->dhcp_opts, opts = daemon->dhcp_opts; opts; opts = cp) |
| 5164 | { |
| 5165 | cp = opts->next; |
| 5166 | |
| 5167 | if (opts->flags & DHOPT_BANK) |
| 5168 | { |
| 5169 | if ((opts->flags & DHOPT_VENDOR)) |
| 5170 | free(opts->u.vendor_class); |
| 5171 | free(opts->val); |
| 5172 | for (id = opts->netid; id; id = next) |
| 5173 | { |
| 5174 | next = id->next; |
| 5175 | free(id->net); |
| 5176 | free(id); |
| 5177 | } |
| 5178 | *up = opts->next; |
| 5179 | free(opts); |
| 5180 | } |
| 5181 | else |
| 5182 | up = &opts->next; |
| 5183 | } |
| 5184 | } |
| 5185 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5186 | void reread_dhcp(void) |
| 5187 | { |
Simon Kelley | 4f7bb57 | 2018-03-08 18:47:08 +0000 | [diff] [blame] | 5188 | struct hostsfile *hf; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5189 | |
Simon Kelley | 4f7bb57 | 2018-03-08 18:47:08 +0000 | [diff] [blame] | 5190 | /* Do these even if there is no daemon->dhcp_hosts_file or |
| 5191 | daemon->dhcp_opts_file since entries may have been created by the |
| 5192 | inotify dynamic file reading system. */ |
| 5193 | |
| 5194 | clear_dynamic_conf(); |
| 5195 | clear_dynamic_opt(); |
| 5196 | |
| 5197 | if (daemon->dhcp_hosts_file) |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5198 | { |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5199 | daemon->dhcp_hosts_file = expand_filelist(daemon->dhcp_hosts_file); |
| 5200 | for (hf = daemon->dhcp_hosts_file; hf; hf = hf->next) |
Simon Kelley | 4f7bb57 | 2018-03-08 18:47:08 +0000 | [diff] [blame] | 5201 | if (!(hf->flags & AH_INACTIVE)) |
| 5202 | { |
| 5203 | if (one_file(hf->fname, LOPT_BANK)) |
| 5204 | my_syslog(MS_DHCP | LOG_INFO, _("read %s"), hf->fname); |
| 5205 | } |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5206 | } |
| 5207 | |
| 5208 | if (daemon->dhcp_opts_file) |
| 5209 | { |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5210 | daemon->dhcp_opts_file = expand_filelist(daemon->dhcp_opts_file); |
| 5211 | for (hf = daemon->dhcp_opts_file; hf; hf = hf->next) |
| 5212 | if (!(hf->flags & AH_INACTIVE)) |
| 5213 | { |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 5214 | if (one_file(hf->fname, LOPT_OPTS)) |
| 5215 | my_syslog(MS_DHCP | LOG_INFO, _("read %s"), hf->fname); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5216 | } |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5217 | } |
Simon Kelley | 4f7bb57 | 2018-03-08 18:47:08 +0000 | [diff] [blame] | 5218 | |
| 5219 | # ifdef HAVE_INOTIFY |
| 5220 | /* Setup notify and read pre-existing files. */ |
| 5221 | set_dynamic_inotify(AH_DHCP_HST | AH_DHCP_OPT, 0, NULL, 0); |
| 5222 | # endif |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5223 | } |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 5224 | #endif |
Simon Kelley | 4f7bb57 | 2018-03-08 18:47:08 +0000 | [diff] [blame] | 5225 | |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 5226 | void read_opts(int argc, char **argv, char *compile_opts) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5227 | { |
Neil Jerram | 3bd4c47 | 2018-01-18 22:49:38 +0000 | [diff] [blame] | 5228 | size_t argbuf_size = MAXDNAME; |
| 5229 | char *argbuf = opt_malloc(argbuf_size); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5230 | char *buff = opt_malloc(MAXDNAME); |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 5231 | int option, testmode = 0; |
| 5232 | char *arg, *conffile = NULL; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5233 | |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5234 | opterr = 0; |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 5235 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5236 | daemon = opt_malloc(sizeof(struct daemon)); |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5237 | memset(daemon, 0, sizeof(struct daemon)); |
| 5238 | daemon->namebuff = buff; |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5239 | |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5240 | /* Set defaults - everything else is zero or NULL */ |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5241 | daemon->cachesize = CACHESIZ; |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 5242 | daemon->ftabsize = FTABSIZ; |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5243 | daemon->port = NAMESERVER_PORT; |
Simon Kelley | 9e03894 | 2008-05-30 20:06:34 +0100 | [diff] [blame] | 5244 | daemon->dhcp_client_port = DHCP_CLIENT_PORT; |
| 5245 | daemon->dhcp_server_port = DHCP_SERVER_PORT; |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5246 | daemon->default_resolv.is_default = 1; |
| 5247 | daemon->default_resolv.name = RESOLVFILE; |
| 5248 | daemon->resolv_files = &daemon->default_resolv; |
| 5249 | daemon->username = CHUSER; |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5250 | daemon->runfile = RUNFILE; |
| 5251 | daemon->dhcp_max = MAXLEASES; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 5252 | daemon->tftp_max = TFTP_MAX_CONNECTIONS; |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5253 | daemon->edns_pktsz = EDNS_PKTSZ; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5254 | daemon->log_fac = -1; |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 5255 | daemon->auth_ttl = AUTH_TTL; |
| 5256 | daemon->soa_refresh = SOA_REFRESH; |
| 5257 | daemon->soa_retry = SOA_RETRY; |
| 5258 | daemon->soa_expiry = SOA_EXPIRY; |
Simon Kelley | 4a8c098 | 2021-03-26 21:19:39 +0000 | [diff] [blame] | 5259 | |
Kevin Darbyshire-Bryant | 7ac9ae1 | 2016-09-09 20:52:08 +0100 | [diff] [blame] | 5260 | #ifndef NO_ID |
Simon Kelley | fec216d | 2014-03-27 20:54:34 +0000 | [diff] [blame] | 5261 | add_txt("version.bind", "dnsmasq-" VERSION, 0 ); |
| 5262 | add_txt("authors.bind", "Simon Kelley", 0); |
| 5263 | add_txt("copyright.bind", COPYRIGHT, 0); |
| 5264 | add_txt("cachesize.bind", NULL, TXT_STAT_CACHESIZE); |
| 5265 | add_txt("insertions.bind", NULL, TXT_STAT_INSERTS); |
| 5266 | add_txt("evictions.bind", NULL, TXT_STAT_EVICTIONS); |
| 5267 | add_txt("misses.bind", NULL, TXT_STAT_MISSES); |
| 5268 | add_txt("hits.bind", NULL, TXT_STAT_HITS); |
| 5269 | #ifdef HAVE_AUTH |
| 5270 | add_txt("auth.bind", NULL, TXT_STAT_AUTH); |
| 5271 | #endif |
| 5272 | add_txt("servers.bind", NULL, TXT_STAT_SERVERS); |
Kevin Darbyshire-Bryant | 7ac9ae1 | 2016-09-09 20:52:08 +0100 | [diff] [blame] | 5273 | #endif |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 5274 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5275 | while (1) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5276 | { |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5277 | #ifdef HAVE_GETOPT_LONG |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5278 | option = getopt_long(argc, argv, OPTSTRING, opts, NULL); |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5279 | #else |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5280 | option = getopt(argc, argv, OPTSTRING); |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5281 | #endif |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5282 | |
| 5283 | if (option == -1) |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5284 | { |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 5285 | for (; optind < argc; optind++) |
| 5286 | { |
| 5287 | unsigned char *c = (unsigned char *)argv[optind]; |
| 5288 | for (; *c != 0; c++) |
| 5289 | if (!isspace(*c)) |
| 5290 | die(_("junk found in command line"), NULL, EC_BADCONF); |
| 5291 | } |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5292 | break; |
| 5293 | } |
| 5294 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5295 | /* Copy optarg so that argv doesn't get changed */ |
| 5296 | if (optarg) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5297 | { |
Neil Jerram | 3bd4c47 | 2018-01-18 22:49:38 +0000 | [diff] [blame] | 5298 | if (strlen(optarg) >= argbuf_size) |
| 5299 | { |
| 5300 | free(argbuf); |
| 5301 | argbuf_size = strlen(optarg) + 1; |
| 5302 | argbuf = opt_malloc(argbuf_size); |
| 5303 | } |
Petr Menšík | 47b45b2 | 2018-08-15 18:17:00 +0200 | [diff] [blame] | 5304 | safe_strncpy(argbuf, optarg, argbuf_size); |
Neil Jerram | 3bd4c47 | 2018-01-18 22:49:38 +0000 | [diff] [blame] | 5305 | arg = argbuf; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5306 | } |
| 5307 | else |
| 5308 | arg = NULL; |
| 5309 | |
| 5310 | /* command-line only stuff */ |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 5311 | if (option == LOPT_TEST) |
| 5312 | testmode = 1; |
| 5313 | else if (option == 'w') |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5314 | { |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 5315 | #ifdef HAVE_DHCP |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 5316 | if (argc == 3 && strcmp(argv[2], "dhcp") == 0) |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 5317 | display_opts(); |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 5318 | #ifdef HAVE_DHCP6 |
| 5319 | else if (argc == 3 && strcmp(argv[2], "dhcp6") == 0) |
| 5320 | display_opts6(); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 5321 | #endif |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 5322 | else |
| 5323 | #endif |
| 5324 | do_usage(); |
| 5325 | |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5326 | exit(0); |
| 5327 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5328 | else if (option == 'v') |
| 5329 | { |
| 5330 | printf(_("Dnsmasq version %s %s\n"), VERSION, COPYRIGHT); |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 5331 | printf(_("Compile time options: %s\n\n"), compile_opts); |
Simon Kelley | b8187c8 | 2005-11-26 21:46:27 +0000 | [diff] [blame] | 5332 | printf(_("This software comes with ABSOLUTELY NO WARRANTY.\n")); |
| 5333 | 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] | 5334 | 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] | 5335 | exit(0); |
| 5336 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5337 | else if (option == 'C') |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5338 | { |
Simon Kelley | 5c464ef | 2019-03-29 23:11:05 +0000 | [diff] [blame] | 5339 | if (!conffile) |
| 5340 | conffile = opt_string_alloc(arg); |
| 5341 | else |
| 5342 | { |
| 5343 | char *extra = opt_string_alloc(arg); |
| 5344 | one_file(extra, 0); |
| 5345 | free(extra); |
| 5346 | } |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5347 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5348 | else |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5349 | { |
Simon Kelley | 26128d2 | 2004-11-14 16:43:54 +0000 | [diff] [blame] | 5350 | #ifdef HAVE_GETOPT_LONG |
Simon Kelley | 7b1eae4 | 2014-02-20 13:43:28 +0000 | [diff] [blame] | 5351 | if (!one_opt(option, arg, daemon->namebuff, _("try --help"), 1, 0)) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5352 | #else |
Simon Kelley | 7b1eae4 | 2014-02-20 13:43:28 +0000 | [diff] [blame] | 5353 | if (!one_opt(option, arg, daemon->namebuff, _("try -w"), 1, 0)) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5354 | #endif |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 5355 | die(_("bad command line options: %s"), daemon->namebuff, EC_BADCONF); |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5356 | } |
| 5357 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5358 | |
Neil Jerram | 3bd4c47 | 2018-01-18 22:49:38 +0000 | [diff] [blame] | 5359 | free(argbuf); |
| 5360 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5361 | if (conffile) |
Chen Wei | 28b879a | 2015-02-17 22:07:35 +0000 | [diff] [blame] | 5362 | { |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 5363 | one_file(conffile, 0); |
| 5364 | free(conffile); |
Chen Wei | 28b879a | 2015-02-17 22:07:35 +0000 | [diff] [blame] | 5365 | } |
Petr Menšík | 59e4703 | 2018-11-02 22:39:39 +0000 | [diff] [blame] | 5366 | else |
| 5367 | one_file(CONFFILE, '7'); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5368 | |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 5369 | /* 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] | 5370 | if (daemon->servers) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5371 | { |
| 5372 | struct server *tmp; |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5373 | for (tmp = daemon->servers; tmp; tmp = tmp->next) |
Simon Kelley | 14ffa07 | 2016-04-25 16:36:44 +0100 | [diff] [blame] | 5374 | if (!(tmp->flags & SERV_HAS_SOURCE)) |
| 5375 | { |
| 5376 | if (tmp->source_addr.sa.sa_family == AF_INET) |
| 5377 | tmp->source_addr.in.sin_port = htons(daemon->query_port); |
Simon Kelley | 14ffa07 | 2016-04-25 16:36:44 +0100 | [diff] [blame] | 5378 | else if (tmp->source_addr.sa.sa_family == AF_INET6) |
| 5379 | tmp->source_addr.in6.sin6_port = htons(daemon->query_port); |
Simon Kelley | 14ffa07 | 2016-04-25 16:36:44 +0100 | [diff] [blame] | 5380 | } |
| 5381 | } |
| 5382 | |
Simon Kelley | df3d54f | 2016-02-24 21:03:38 +0000 | [diff] [blame] | 5383 | if (daemon->host_records) |
| 5384 | { |
| 5385 | struct host_record *hr; |
| 5386 | |
| 5387 | for (hr = daemon->host_records; hr; hr = hr->next) |
| 5388 | if (hr->ttl == -1) |
| 5389 | hr->ttl = daemon->local_ttl; |
| 5390 | } |
| 5391 | |
| 5392 | if (daemon->cnames) |
| 5393 | { |
Simon Kelley | 903df07 | 2017-01-19 17:22:00 +0000 | [diff] [blame] | 5394 | struct cname *cn, *cn2, *cn3; |
| 5395 | |
| 5396 | #define NOLOOP 1 |
| 5397 | #define TESTLOOP 2 |
| 5398 | |
Simon Kelley | 157d8cf | 2019-10-25 17:46:49 +0100 | [diff] [blame] | 5399 | /* Fill in TTL for CNAMES now we have local_ttl. |
Simon Kelley | 903df07 | 2017-01-19 17:22:00 +0000 | [diff] [blame] | 5400 | Also prepare to do loop detection. */ |
Simon Kelley | df3d54f | 2016-02-24 21:03:38 +0000 | [diff] [blame] | 5401 | for (cn = daemon->cnames; cn; cn = cn->next) |
Simon Kelley | 903df07 | 2017-01-19 17:22:00 +0000 | [diff] [blame] | 5402 | { |
| 5403 | if (cn->ttl == -1) |
| 5404 | cn->ttl = daemon->local_ttl; |
| 5405 | cn->flag = 0; |
| 5406 | cn->targetp = NULL; |
| 5407 | for (cn2 = daemon->cnames; cn2; cn2 = cn2->next) |
| 5408 | if (hostname_isequal(cn->target, cn2->alias)) |
| 5409 | { |
| 5410 | cn->targetp = cn2; |
| 5411 | break; |
| 5412 | } |
| 5413 | } |
| 5414 | |
| 5415 | /* Find any CNAME loops.*/ |
| 5416 | for (cn = daemon->cnames; cn; cn = cn->next) |
| 5417 | { |
| 5418 | for (cn2 = cn->targetp; cn2; cn2 = cn2->targetp) |
| 5419 | { |
| 5420 | if (cn2->flag == NOLOOP) |
| 5421 | break; |
| 5422 | |
| 5423 | if (cn2->flag == TESTLOOP) |
| 5424 | die(_("CNAME loop involving %s"), cn->alias, EC_BADCONF); |
| 5425 | |
| 5426 | cn2->flag = TESTLOOP; |
| 5427 | } |
| 5428 | |
| 5429 | for (cn3 = cn->targetp; cn3 != cn2; cn3 = cn3->targetp) |
| 5430 | cn3->flag = NOLOOP; |
| 5431 | } |
Simon Kelley | df3d54f | 2016-02-24 21:03:38 +0000 | [diff] [blame] | 5432 | } |
| 5433 | |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5434 | if (daemon->if_addrs) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5435 | { |
| 5436 | struct iname *tmp; |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5437 | for(tmp = daemon->if_addrs; tmp; tmp = tmp->next) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5438 | if (tmp->addr.sa.sa_family == AF_INET) |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5439 | tmp->addr.in.sin_port = htons(daemon->port); |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5440 | else if (tmp->addr.sa.sa_family == AF_INET6) |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5441 | tmp->addr.in6.sin6_port = htons(daemon->port); |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5442 | } |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 5443 | |
| 5444 | /* create default, if not specified */ |
| 5445 | if (daemon->authserver && !daemon->hostmaster) |
| 5446 | { |
| 5447 | strcpy(buff, "hostmaster."); |
| 5448 | strcat(buff, daemon->authserver); |
| 5449 | daemon->hostmaster = opt_string_alloc(buff); |
| 5450 | } |
Wang Shanker | 4ded962 | 2020-12-04 10:17:35 +0800 | [diff] [blame] | 5451 | |
| 5452 | if (!daemon->dhcp_pxe_vendors) |
| 5453 | { |
| 5454 | daemon->dhcp_pxe_vendors = opt_malloc(sizeof(struct dhcp_pxe_vendor)); |
| 5455 | daemon->dhcp_pxe_vendors->data = opt_string_alloc(DHCP_PXE_DEF_VENDOR); |
| 5456 | daemon->dhcp_pxe_vendors->next = NULL; |
| 5457 | } |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 5458 | |
Simon Kelley | f6b7dc4 | 2005-01-23 12:06:08 +0000 | [diff] [blame] | 5459 | /* 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] | 5460 | if (option_bool(OPT_LOCALMX) || daemon->mxnames || daemon->mxtarget) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5461 | { |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 5462 | struct mx_srv_record *mx; |
| 5463 | |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5464 | if (gethostname(buff, MAXDNAME) == -1) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 5465 | die(_("cannot get host-name: %s"), NULL, EC_MISC); |
Simon Kelley | f6b7dc4 | 2005-01-23 12:06:08 +0000 | [diff] [blame] | 5466 | |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 5467 | for (mx = daemon->mxnames; mx; mx = mx->next) |
| 5468 | if (!mx->issrv && hostname_isequal(mx->name, buff)) |
| 5469 | break; |
| 5470 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5471 | if ((daemon->mxtarget || option_bool(OPT_LOCALMX)) && !mx) |
Simon Kelley | de37951 | 2004-06-22 20:23:33 +0100 | [diff] [blame] | 5472 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5473 | mx = opt_malloc(sizeof(struct mx_srv_record)); |
Simon Kelley | 91dccd0 | 2005-03-31 17:48:32 +0100 | [diff] [blame] | 5474 | mx->next = daemon->mxnames; |
| 5475 | mx->issrv = 0; |
| 5476 | mx->target = NULL; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5477 | mx->name = opt_string_alloc(buff); |
Simon Kelley | 91dccd0 | 2005-03-31 17:48:32 +0100 | [diff] [blame] | 5478 | daemon->mxnames = mx; |
Simon Kelley | f6b7dc4 | 2005-01-23 12:06:08 +0000 | [diff] [blame] | 5479 | } |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5480 | |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5481 | if (!daemon->mxtarget) |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5482 | daemon->mxtarget = opt_string_alloc(buff); |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 5483 | |
| 5484 | for (mx = daemon->mxnames; mx; mx = mx->next) |
| 5485 | if (!mx->issrv && !mx->target) |
| 5486 | mx->target = daemon->mxtarget; |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 5487 | } |
Simon Kelley | f6b7dc4 | 2005-01-23 12:06:08 +0000 | [diff] [blame] | 5488 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5489 | if (!option_bool(OPT_NO_RESOLV) && |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 5490 | daemon->resolv_files && |
| 5491 | daemon->resolv_files->next && |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5492 | option_bool(OPT_NO_POLL)) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 5493 | 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] | 5494 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5495 | if (option_bool(OPT_RESOLV_DOMAIN)) |
Simon Kelley | de37951 | 2004-06-22 20:23:33 +0100 | [diff] [blame] | 5496 | { |
| 5497 | char *line; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5498 | FILE *f; |
| 5499 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5500 | if (option_bool(OPT_NO_RESOLV) || |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 5501 | !daemon->resolv_files || |
| 5502 | (daemon->resolv_files)->next) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 5503 | 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] | 5504 | |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5505 | if (!(f = fopen((daemon->resolv_files)->name, "r"))) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 5506 | die(_("failed to read %s: %s"), (daemon->resolv_files)->name, EC_FILE); |
Simon Kelley | de37951 | 2004-06-22 20:23:33 +0100 | [diff] [blame] | 5507 | |
| 5508 | while ((line = fgets(buff, MAXDNAME, f))) |
| 5509 | { |
| 5510 | char *token = strtok(line, " \t\n\r"); |
| 5511 | |
| 5512 | if (!token || strcmp(token, "search") != 0) |
| 5513 | continue; |
| 5514 | |
| 5515 | if ((token = strtok(NULL, " \t\n\r")) && |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 5516 | (daemon->domain_suffix = canonicalise_opt(token))) |
Simon Kelley | de37951 | 2004-06-22 20:23:33 +0100 | [diff] [blame] | 5517 | break; |
| 5518 | } |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5519 | |
Simon Kelley | de37951 | 2004-06-22 20:23:33 +0100 | [diff] [blame] | 5520 | fclose(f); |
Simon Kelley | 8a911cc | 2004-03-16 18:35:52 +0000 | [diff] [blame] | 5521 | |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 5522 | if (!daemon->domain_suffix) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 5523 | 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] | 5524 | } |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 5525 | |
| 5526 | if (daemon->domain_suffix) |
| 5527 | { |
| 5528 | /* add domain for any srv record without one. */ |
| 5529 | struct mx_srv_record *srv; |
Simon Kelley | de37951 | 2004-06-22 20:23:33 +0100 | [diff] [blame] | 5530 | |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 5531 | for (srv = daemon->mxnames; srv; srv = srv->next) |
| 5532 | if (srv->issrv && |
| 5533 | strchr(srv->name, '.') && |
| 5534 | strchr(srv->name, '.') == strrchr(srv->name, '.')) |
| 5535 | { |
| 5536 | strcpy(buff, srv->name); |
| 5537 | strcat(buff, "."); |
| 5538 | strcat(buff, daemon->domain_suffix); |
| 5539 | free(srv->name); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5540 | srv->name = opt_string_alloc(buff); |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 5541 | } |
| 5542 | } |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 5543 | else if (option_bool(OPT_DHCP_FQDN)) |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 5544 | 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] | 5545 | |
Simon Kelley | c8a8048 | 2014-03-05 14:29:54 +0000 | [diff] [blame] | 5546 | /* If there's access-control config, then ignore --local-service, it's intended |
| 5547 | as a system default to keep otherwise unconfigured installations safe. */ |
| 5548 | if (daemon->if_names || daemon->if_except || daemon->if_addrs || daemon->authserver) |
| 5549 | reset_option_bool(OPT_LOCAL_SERVICE); |
| 5550 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 5551 | if (testmode) |
| 5552 | { |
| 5553 | fprintf(stderr, "dnsmasq: %s.\n", _("syntax check OK")); |
| 5554 | exit(0); |
| 5555 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 5556 | } |