mirror of
https://github.com/pi-hole/dnsmasq.git
synced 2025-12-19 18:28:25 +00:00
Tidy code for --umbrella option.
This commit is contained in:
@@ -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
|
.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.
|
will add 1.2.3.0/24 for both IPv4 and IPv6 requestors.
|
||||||
.TP
|
.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.
|
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
|
included in the forwarded queries and may be able to be used in
|
||||||
filtering policies and reporting. The order of the deviceid and orgid
|
filtering policies and reporting. The order of the id
|
||||||
attributes is irrelevant, but must be separated by a comma.
|
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
|
.TP
|
||||||
.B \-c, --cache-size=<cachesize>
|
.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.
|
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.
|
||||||
|
|||||||
42
src/edns0.c
42
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, {}};
|
struct umbrella_opt opt = {{"ODNS"}, UMBRELLA_VERSION, 0, {}};
|
||||||
u8 *u = &opt.fields[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;
|
int family = source->sa.sa_family;
|
||||||
PUTSHORT(family == AF_INET ? UMBRELLA_IPV4 : UMBRELLA_IPV6, u);
|
|
||||||
int size = family == AF_INET ? INADDRSZ : IN6ADDRSZ;
|
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);
|
memcpy(u, get_addrp(source, family), size);
|
||||||
u += 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)) {
|
if (daemon->umbrella_asset)
|
||||||
PUTSHORT(UMBRELLA_DEVICE, u);
|
{
|
||||||
memcpy(u, (char *)&daemon->umbrella_device, UMBRELLA_DEVICESZ);
|
PUTSHORT(UMBRELLA_ASSET, u);
|
||||||
u += UMBRELLA_DEVICESZ;
|
PUTLONG(daemon->umbrella_asset, u);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (daemon->umbrella_asset) {
|
return add_pseudoheader(header, plen, (unsigned char *)limit, PACKETSZ, EDNS0_OPTION_UMBRELLA, (unsigned char *)&opt, u - (u8 *)&opt, 0, 1);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set *check_subnet if we add a client subnet option, which needs to checked
|
/* Set *check_subnet if we add a client subnet option, which needs to checked
|
||||||
|
|||||||
75
src/option.c
75
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 */
|
case LOPT_UMBRELLA: /* --umbrella */
|
||||||
set_option_bool(OPT_UMBRELLA);
|
set_option_bool(OPT_UMBRELLA);
|
||||||
while (arg) {
|
while (arg)
|
||||||
comma = split(arg);
|
{
|
||||||
if (strstr(arg, "deviceid:")) {
|
comma = split(arg);
|
||||||
arg += 9;
|
if (strstr(arg, "deviceid:"))
|
||||||
if (strlen(arg) != 16)
|
{
|
||||||
ret_err(gen_err);
|
char *p;
|
||||||
char *p;
|
u8 *u = daemon->umbrella_device;
|
||||||
for (p = arg; *p; p++) {
|
char word[3];
|
||||||
if (!isxdigit((int)*p))
|
|
||||||
ret_err(gen_err);
|
arg += 9;
|
||||||
}
|
if (strlen(arg) != 16)
|
||||||
set_option_bool(OPT_UMBRELLA_DEVID);
|
ret_err(gen_err);
|
||||||
|
|
||||||
u8 *u = daemon->umbrella_device;
|
for (p = arg; *p; p++)
|
||||||
char word[3];
|
if (!isxdigit((int)*p))
|
||||||
u8 i;
|
ret_err(gen_err);
|
||||||
for (i = 0; i < sizeof(daemon->umbrella_device); i++, arg+=2) {
|
|
||||||
memcpy(word, &(arg[0]), 2);
|
set_option_bool(OPT_UMBRELLA_DEVID);
|
||||||
*u++ = strtoul(word, NULL, 16);
|
|
||||||
}
|
for (i = 0; i < (int)sizeof(daemon->umbrella_device); i++, arg+=2)
|
||||||
}
|
{
|
||||||
else if (strstr(arg, "orgid:")) {
|
memcpy(word, &(arg[0]), 2);
|
||||||
if (!strtoul_check(arg+6, &daemon->umbrella_org)) {
|
*u++ = strtoul(word, NULL, 16);
|
||||||
ret_err(gen_err);
|
}
|
||||||
}
|
}
|
||||||
}
|
else if (strstr(arg, "orgid:"))
|
||||||
else if (strstr(arg, "assetid:")) {
|
{
|
||||||
if (!strtoul_check(arg+8, &daemon->umbrella_asset)) {
|
if (!strtoul_check(arg+6, &daemon->umbrella_org))
|
||||||
ret_err(gen_err);
|
ret_err(gen_err);
|
||||||
}
|
}
|
||||||
}
|
else if (strstr(arg, "assetid:"))
|
||||||
arg = comma;
|
{
|
||||||
}
|
if (!strtoul_check(arg+8, &daemon->umbrella_asset))
|
||||||
|
ret_err(gen_err);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ret_err(gen_err);
|
||||||
|
|
||||||
|
arg = comma;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LOPT_ADD_MAC: /* --add-mac */
|
case LOPT_ADD_MAC: /* --add-mac */
|
||||||
if (!arg)
|
if (!arg)
|
||||||
set_option_bool(OPT_ADD_MAC);
|
set_option_bool(OPT_ADD_MAC);
|
||||||
|
|||||||
Reference in New Issue
Block a user