diff options
author | Simon Kelley <simon@thekelleys.org.uk> | 2022-01-01 23:33:39 +0000 |
---|---|---|
committer | Simon Kelley <simon@thekelleys.org.uk> | 2022-01-01 23:33:39 +0000 |
commit | 011f8cf1d011ade2f9e7231fca3cabfb1e8eaf06 (patch) | |
tree | 3447b7bae885e682852a53d936506251d5eb0912 | |
parent | 2748fb81e23b71e2c44956e99321816aca91905d (diff) | |
download | dnsmasq-011f8cf1d011ade2f9e7231fca3cabfb1e8eaf06.tar.gz |
Tidy code for --umbrella option.
-rw-r--r-- | man/dnsmasq.8 | 9 | ||||
-rw-r--r-- | src/edns0.c | 42 | ||||
-rw-r--r-- | src/option.c | 75 |
3 files changed, 68 insertions, 58 deletions
diff --git a/man/dnsmasq.8 b/man/dnsmasq.8 index 4de8969..0a83e9e 100644 --- a/man/dnsmasq.8 +++ b/man/dnsmasq.8 @@ -766,12 +766,13 @@ will add 1.2.3.0/24 for IPv4 requestors and ::/0 for IPv6 requestors. .B --add-subnet=1.2.3.4/24,1.2.3.4/24 will add 1.2.3.0/24 for both IPv4 and IPv6 requestors. .TP -.B --umbrella[=deviceid:<deviceid>[,orgid:<orgid>]] +.B --umbrella[=[deviceid:<deviceid>][,orgid:<orgid>][,assetid:<id>]] Embeds the requestor's IP address in DNS queries forwarded upstream. -If device id or organization id are specified, the information is +If device id or, asset id or organization id are specified, the information is included in the forwarded queries and may be able to be used in -filtering policies and reporting. The order of the deviceid and orgid -attributes is irrelevant, but must be separated by a comma. +filtering policies and reporting. The order of the id +attributes is irrelevant, but they must be separated by a comma. Deviceid is +a sixteen digit hexadecimal number, org and asset ids are decimal numbers. .TP .B \-c, --cache-size=<cachesize> Set the size of dnsmasq's cache. The default is 150 names. Setting the cache size to zero disables caching. Note: huge cache size impacts performance. diff --git a/src/edns0.c b/src/edns0.c index 9cf1d11..5de6cb2 100644 --- a/src/edns0.c +++ b/src/edns0.c @@ -460,31 +460,33 @@ static size_t add_umbrella_opt(struct dns_header *header, size_t plen, unsigned struct umbrella_opt opt = {{"ODNS"}, UMBRELLA_VERSION, 0, {}}; u8 *u = &opt.fields[0]; - - if (daemon->umbrella_org) { - PUTSHORT(UMBRELLA_ORG, u); - PUTLONG(daemon->umbrella_org, u); - } - int family = source->sa.sa_family; - PUTSHORT(family == AF_INET ? UMBRELLA_IPV4 : UMBRELLA_IPV6, u); int size = family == AF_INET ? INADDRSZ : IN6ADDRSZ; + + if (daemon->umbrella_org) + { + PUTSHORT(UMBRELLA_ORG, u); + PUTLONG(daemon->umbrella_org, u); + } + + PUTSHORT(family == AF_INET ? UMBRELLA_IPV4 : UMBRELLA_IPV6, u); memcpy(u, get_addrp(source, family), size); u += size; + + if (option_bool(OPT_UMBRELLA_DEVID)) + { + PUTSHORT(UMBRELLA_DEVICE, u); + memcpy(u, (char *)&daemon->umbrella_device, UMBRELLA_DEVICESZ); + u += UMBRELLA_DEVICESZ; + } - if (option_bool(OPT_UMBRELLA_DEVID)) { - PUTSHORT(UMBRELLA_DEVICE, u); - memcpy(u, (char *)&daemon->umbrella_device, UMBRELLA_DEVICESZ); - u += UMBRELLA_DEVICESZ; - } - - if (daemon->umbrella_asset) { - PUTSHORT(UMBRELLA_ASSET, u); - PUTLONG(daemon->umbrella_asset, u); - } - - int len = u - &opt.magic[0]; - return add_pseudoheader(header, plen, (unsigned char *)limit, PACKETSZ, EDNS0_OPTION_UMBRELLA, (unsigned char *)&opt, len, 0, 1); + if (daemon->umbrella_asset) + { + PUTSHORT(UMBRELLA_ASSET, u); + PUTLONG(daemon->umbrella_asset, u); + } + + return add_pseudoheader(header, plen, (unsigned char *)limit, PACKETSZ, EDNS0_OPTION_UMBRELLA, (unsigned char *)&opt, u - (u8 *)&opt, 0, 1); } /* Set *check_subnet if we add a client subnet option, which needs to checked diff --git a/src/option.c b/src/option.c index 6f56ce8..7134ee7 100644 --- a/src/option.c +++ b/src/option.c @@ -2519,41 +2519,48 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma case LOPT_UMBRELLA: /* --umbrella */ set_option_bool(OPT_UMBRELLA); - while (arg) { - comma = split(arg); - if (strstr(arg, "deviceid:")) { - arg += 9; - if (strlen(arg) != 16) - ret_err(gen_err); - char *p; - for (p = arg; *p; p++) { - if (!isxdigit((int)*p)) - ret_err(gen_err); - } - set_option_bool(OPT_UMBRELLA_DEVID); - - u8 *u = daemon->umbrella_device; - char word[3]; - u8 i; - for (i = 0; i < sizeof(daemon->umbrella_device); i++, arg+=2) { - memcpy(word, &(arg[0]), 2); - *u++ = strtoul(word, NULL, 16); - } - } - else if (strstr(arg, "orgid:")) { - if (!strtoul_check(arg+6, &daemon->umbrella_org)) { - ret_err(gen_err); - } - } - else if (strstr(arg, "assetid:")) { - if (!strtoul_check(arg+8, &daemon->umbrella_asset)) { - ret_err(gen_err); - } - } - arg = comma; - } + while (arg) + { + comma = split(arg); + if (strstr(arg, "deviceid:")) + { + char *p; + u8 *u = daemon->umbrella_device; + char word[3]; + + arg += 9; + if (strlen(arg) != 16) + ret_err(gen_err); + + for (p = arg; *p; p++) + if (!isxdigit((int)*p)) + ret_err(gen_err); + + set_option_bool(OPT_UMBRELLA_DEVID); + + for (i = 0; i < (int)sizeof(daemon->umbrella_device); i++, arg+=2) + { + memcpy(word, &(arg[0]), 2); + *u++ = strtoul(word, NULL, 16); + } + } + else if (strstr(arg, "orgid:")) + { + if (!strtoul_check(arg+6, &daemon->umbrella_org)) + ret_err(gen_err); + } + else if (strstr(arg, "assetid:")) + { + if (!strtoul_check(arg+8, &daemon->umbrella_asset)) + ret_err(gen_err); + } + else + ret_err(gen_err); + + arg = comma; + } break; - + case LOPT_ADD_MAC: /* --add-mac */ if (!arg) set_option_bool(OPT_ADD_MAC); |