mirror of
http://thekelleys.org.uk/git/dnsmasq.git
synced 2026-11-30 21:28:34 +00:00
Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a42ee397f3 | ||
|
|
e58f8bb8c1 | ||
|
|
58cf958e41 | ||
|
|
06d01f7ae4 | ||
|
|
1a33eec0ba | ||
|
|
82de7a1e96 | ||
|
|
8e9bde57c5 | ||
|
|
1bb70e08be | ||
|
|
9afcb7ae61 | ||
|
|
545c4955e6 | ||
|
|
2f2d59b35c |
No files matched your search
@@ -86,6 +86,12 @@ version 2.86
|
|||||||
conntrack is configured. Thanks to Yick Xie for spotting
|
conntrack is configured. Thanks to Yick Xie for spotting
|
||||||
the lack of this.
|
the lack of this.
|
||||||
|
|
||||||
|
When --dhcp-hostsfile --dhcp-optsfile and --addn-hosts are
|
||||||
|
given a directory as argument, define the order in which
|
||||||
|
files within that directory are read (alphabetical order
|
||||||
|
of filename). Thanks to Ed Wildgoose for the initial patch
|
||||||
|
and motivation for this.
|
||||||
|
|
||||||
|
|
||||||
version 2.85
|
version 2.85
|
||||||
Fix problem with DNS retries in 2.83/2.84.
|
Fix problem with DNS retries in 2.83/2.84.
|
||||||
|
|||||||
+8
-6
@@ -1,4 +1,4 @@
|
|||||||
.TH DNSMASQ 8 2020-04-05
|
.TH DNSMASQ 8 2021-08-16
|
||||||
.SH NAME
|
.SH NAME
|
||||||
dnsmasq \- A lightweight DHCP and caching DNS server.
|
dnsmasq \- A lightweight DHCP and caching DNS server.
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
@@ -55,7 +55,8 @@ Don't read the hostnames in /etc/hosts.
|
|||||||
.B \-H, --addn-hosts=<file>
|
.B \-H, --addn-hosts=<file>
|
||||||
Additional hosts file. Read the specified file as well as /etc/hosts. If \fB--no-hosts\fP is given, read
|
Additional hosts file. Read the specified file as well as /etc/hosts. If \fB--no-hosts\fP is given, read
|
||||||
only the specified file. This option may be repeated for more than one
|
only the specified file. This option may be repeated for more than one
|
||||||
additional hosts file. If a directory is given, then read all the files contained in that directory.
|
additional hosts file. If a directory is given, then read all the files contained in that directory
|
||||||
|
in alphabetical order.
|
||||||
.TP
|
.TP
|
||||||
.B --hostsdir=<path>
|
.B --hostsdir=<path>
|
||||||
Read all the hosts files contained in the directory. New or changed files
|
Read all the hosts files contained in the directory. New or changed files
|
||||||
@@ -905,7 +906,7 @@ compiled in and the kernel must have conntrack support
|
|||||||
included and configured. This option cannot be combined with
|
included and configured. This option cannot be combined with
|
||||||
.B --query-port.
|
.B --query-port.
|
||||||
.TP
|
.TP
|
||||||
.B \-F, --dhcp-range=[tag:<tag>[,tag:<tag>],][set:<tag>,]<start-addr>[,<end-addr>|<mode>][,<netmask>[,<broadcast>]][,<lease time>]
|
.B \-F, --dhcp-range=[tag:<tag>[,tag:<tag>],][set:<tag>,]<start-addr>[,<end-addr>|<mode>[,<netmask>[,<broadcast>]]][,<lease time>]
|
||||||
.TP
|
.TP
|
||||||
.B \-F, --dhcp-range=[tag:<tag>[,tag:<tag>],][set:<tag>,]<start-IPv6addr>[,<end-IPv6addr>|constructor:<interface>][,<mode>][,<prefix-len>][,<lease time>]
|
.B \-F, --dhcp-range=[tag:<tag>[,tag:<tag>],][set:<tag>,]<start-IPv6addr>[,<end-IPv6addr>|constructor:<interface>][,<mode>][,<prefix-len>][,<lease time>]
|
||||||
|
|
||||||
@@ -1165,7 +1166,7 @@ has both wired and wireless interfaces.
|
|||||||
.TP
|
.TP
|
||||||
.B --dhcp-hostsfile=<path>
|
.B --dhcp-hostsfile=<path>
|
||||||
Read DHCP host information from the specified file. If a directory
|
Read DHCP host information from the specified file. If a directory
|
||||||
is given, then read all the files contained in that directory. The file contains
|
is given, then read all the files contained in that directory in alphabetical order. The file contains
|
||||||
information about one host per line. The format of a line is the same
|
information about one host per line. The format of a line is the same
|
||||||
as text to the right of '=' in \fB--dhcp-host\fP. The advantage of storing DHCP host information
|
as text to the right of '=' in \fB--dhcp-host\fP. The advantage of storing DHCP host information
|
||||||
in this file is that it can be changed without re-starting dnsmasq:
|
in this file is that it can be changed without re-starting dnsmasq:
|
||||||
@@ -1173,7 +1174,7 @@ the file will be re-read when dnsmasq receives SIGHUP.
|
|||||||
.TP
|
.TP
|
||||||
.B --dhcp-optsfile=<path>
|
.B --dhcp-optsfile=<path>
|
||||||
Read DHCP option information from the specified file. If a directory
|
Read DHCP option information from the specified file. If a directory
|
||||||
is given, then read all the files contained in that directory. The advantage of
|
is given, then read all the files contained in that directory in alphabetical order. The advantage of
|
||||||
using this option is the same as for \fB--dhcp-hostsfile\fP: the
|
using this option is the same as for \fB--dhcp-hostsfile\fP: the
|
||||||
\fB--dhcp-optsfile\fP will be re-read when dnsmasq receives SIGHUP. Note that
|
\fB--dhcp-optsfile\fP will be re-read when dnsmasq receives SIGHUP. Note that
|
||||||
it is possible to encode the information in a
|
it is possible to encode the information in a
|
||||||
@@ -1188,7 +1189,8 @@ directory, and not an individual file. Changed or new files within
|
|||||||
the directory are read automatically, without the need to send SIGHUP.
|
the directory are read automatically, without the need to send SIGHUP.
|
||||||
If a file is deleted or changed after it has been read by dnsmasq, then the
|
If a file is deleted or changed after it has been read by dnsmasq, then the
|
||||||
host record it contained will remain until dnsmasq receives a SIGHUP, or
|
host record it contained will remain until dnsmasq receives a SIGHUP, or
|
||||||
is restarted; ie host records are only added dynamically.
|
is restarted; ie host records are only added dynamically. The order in which the
|
||||||
|
files in a directory are read is not defined.
|
||||||
.TP
|
.TP
|
||||||
.B --dhcp-optsdir=<path>
|
.B --dhcp-optsdir=<path>
|
||||||
This is equivalent to \fB--dhcp-optsfile\fP, with the differences noted for \fB--dhcp-hostsdir\fP.
|
This is equivalent to \fB--dhcp-optsfile\fP, with the differences noted for \fB--dhcp-hostsdir\fP.
|
||||||
|
|||||||
+729
-577
File diff suppressed because it is too large.
Load diff
@@ -76,9 +76,9 @@ unsigned char *hash_questions(struct dns_header *header, size_t plen, char *name
|
|||||||
|
|
||||||
#else /* HAVE_DNSSEC || HAVE_CRYPTOHASH */
|
#else /* HAVE_DNSSEC || HAVE_CRYPTOHASH */
|
||||||
|
|
||||||
#define SHA256_BLOCK_SIZE 32 // SHA256 outputs a 32 byte digest
|
#define SHA256_BLOCK_SIZE 32 /* SHA256 outputs a 32 byte digest */
|
||||||
typedef unsigned char BYTE; // 8-bit byte
|
typedef unsigned char BYTE; /* 8-bit byte */
|
||||||
typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines
|
typedef unsigned int WORD; /* 32-bit word, change to "long" for 16-bit machines */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
BYTE data[64];
|
BYTE data[64];
|
||||||
@@ -238,7 +238,7 @@ static void sha256_final(SHA256_CTX *ctx, BYTE hash[])
|
|||||||
|
|
||||||
i = ctx->datalen;
|
i = ctx->datalen;
|
||||||
|
|
||||||
// Pad whatever data is left in the buffer.
|
/* Pad whatever data is left in the buffer. */
|
||||||
if (ctx->datalen < 56)
|
if (ctx->datalen < 56)
|
||||||
{
|
{
|
||||||
ctx->data[i++] = 0x80;
|
ctx->data[i++] = 0x80;
|
||||||
@@ -254,7 +254,7 @@ static void sha256_final(SHA256_CTX *ctx, BYTE hash[])
|
|||||||
memset(ctx->data, 0, 56);
|
memset(ctx->data, 0, 56);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append to the padding the total message's length in bits and transform.
|
/* Append to the padding the total message's length in bits and transform. */
|
||||||
ctx->bitlen += ctx->datalen * 8;
|
ctx->bitlen += ctx->datalen * 8;
|
||||||
ctx->data[63] = ctx->bitlen;
|
ctx->data[63] = ctx->bitlen;
|
||||||
ctx->data[62] = ctx->bitlen >> 8;
|
ctx->data[62] = ctx->bitlen >> 8;
|
||||||
@@ -266,8 +266,8 @@ static void sha256_final(SHA256_CTX *ctx, BYTE hash[])
|
|||||||
ctx->data[56] = ctx->bitlen >> 56;
|
ctx->data[56] = ctx->bitlen >> 56;
|
||||||
sha256_transform(ctx, ctx->data);
|
sha256_transform(ctx, ctx->data);
|
||||||
|
|
||||||
// Since this implementation uses little endian byte ordering and SHA uses big endian,
|
/* Since this implementation uses little endian byte ordering and SHA uses big endian,
|
||||||
// reverse all the bytes when copying the final state to the output hash.
|
reverse all the bytes when copying the final state to the output hash. */
|
||||||
for (i = 0; i < 4; ++i)
|
for (i = 0; i < 4; ++i)
|
||||||
{
|
{
|
||||||
hash[i] = (ctx->state[0] >> (24 - i * 8)) & 0x000000ff;
|
hash[i] = (ctx->state[0] >> (24 - i * 8)) & 0x000000ff;
|
||||||
|
|||||||
+45
-20
@@ -2700,11 +2700,6 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
|
|||||||
{
|
{
|
||||||
if ((err = parse_server(arg, &serv_addr, &source_addr, interface, &flags)))
|
if ((err = parse_server(arg, &serv_addr, &source_addr, interface, &flags)))
|
||||||
ret_err(err);
|
ret_err(err);
|
||||||
|
|
||||||
/* server=//1.2.3.4 is special. */
|
|
||||||
if (strlen(domain) == 0 && lastdomain)
|
|
||||||
flags |= SERV_FOR_NODOTS;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (servers_only && option == 'S')
|
if (servers_only && option == 'S')
|
||||||
@@ -2712,6 +2707,12 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
|
|||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
/* server=//1.2.3.4 is special. */
|
||||||
|
if (strlen(domain) == 0 && lastdomain)
|
||||||
|
flags |= SERV_FOR_NODOTS;
|
||||||
|
else
|
||||||
|
flags &= ~SERV_FOR_NODOTS;
|
||||||
|
|
||||||
if (!add_update_server(flags, &serv_addr, &source_addr, interface, domain, &addr))
|
if (!add_update_server(flags, &serv_addr, &source_addr, interface, domain, &addr))
|
||||||
ret_err(gen_err);
|
ret_err(gen_err);
|
||||||
|
|
||||||
@@ -5027,15 +5028,33 @@ static int one_file(char *file, int hard_opt)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int file_filter(const struct dirent *ent)
|
||||||
|
{
|
||||||
|
size_t lenfile = strlen(ent->d_name);
|
||||||
|
|
||||||
|
/* ignore emacs backups and dotfiles */
|
||||||
|
|
||||||
|
if (lenfile == 0 ||
|
||||||
|
ent->d_name[lenfile - 1] == '~' ||
|
||||||
|
(ent->d_name[0] == '#' && ent->d_name[lenfile - 1] == '#') ||
|
||||||
|
ent->d_name[0] == '.')
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
/* expand any name which is a directory */
|
/* expand any name which is a directory */
|
||||||
struct hostsfile *expand_filelist(struct hostsfile *list)
|
struct hostsfile *expand_filelist(struct hostsfile *list)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
struct hostsfile *ah;
|
int entcnt, n;
|
||||||
|
struct hostsfile *ah, *last, *next, **up;
|
||||||
|
struct dirent **namelist;
|
||||||
|
|
||||||
/* find largest used index */
|
/* find largest used index */
|
||||||
for (i = SRC_AH, ah = list; ah; ah = ah->next)
|
for (i = SRC_AH, ah = list; ah; ah = ah->next)
|
||||||
{
|
{
|
||||||
|
last = ah;
|
||||||
|
|
||||||
if (i <= ah->index)
|
if (i <= ah->index)
|
||||||
i = ah->index + 1;
|
i = ah->index + 1;
|
||||||
|
|
||||||
@@ -5051,46 +5070,48 @@ struct hostsfile *expand_filelist(struct hostsfile *list)
|
|||||||
struct stat buf;
|
struct stat buf;
|
||||||
if (stat(ah->fname, &buf) != -1 && S_ISDIR(buf.st_mode))
|
if (stat(ah->fname, &buf) != -1 && S_ISDIR(buf.st_mode))
|
||||||
{
|
{
|
||||||
DIR *dir_stream;
|
|
||||||
struct dirent *ent;
|
struct dirent *ent;
|
||||||
|
|
||||||
/* don't read this as a file */
|
/* don't read this as a file */
|
||||||
ah->flags |= AH_INACTIVE;
|
ah->flags |= AH_INACTIVE;
|
||||||
|
|
||||||
if (!(dir_stream = opendir(ah->fname)))
|
entcnt = scandir(ah->fname, &namelist, file_filter, alphasort);
|
||||||
|
if (entcnt < 0)
|
||||||
my_syslog(LOG_ERR, _("cannot access directory %s: %s"),
|
my_syslog(LOG_ERR, _("cannot access directory %s: %s"),
|
||||||
ah->fname, strerror(errno));
|
ah->fname, strerror(errno));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
while ((ent = readdir(dir_stream)))
|
for (n = 0; n < entcnt; n++)
|
||||||
{
|
{
|
||||||
|
ent = namelist[n];
|
||||||
size_t lendir = strlen(ah->fname);
|
size_t lendir = strlen(ah->fname);
|
||||||
size_t lenfile = strlen(ent->d_name);
|
size_t lenfile = strlen(ent->d_name);
|
||||||
struct hostsfile *ah1;
|
struct hostsfile *ah1;
|
||||||
char *path;
|
char *path;
|
||||||
|
|
||||||
/* ignore emacs backups and dotfiles */
|
|
||||||
if (lenfile == 0 ||
|
|
||||||
ent->d_name[lenfile - 1] == '~' ||
|
|
||||||
(ent->d_name[0] == '#' && ent->d_name[lenfile - 1] == '#') ||
|
|
||||||
ent->d_name[0] == '.')
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* see if we have an existing record.
|
/* see if we have an existing record.
|
||||||
dir is ah->fname
|
dir is ah->fname
|
||||||
file is ent->d_name
|
file is ent->d_name
|
||||||
path to match is ah1->fname */
|
path to match is ah1->fname */
|
||||||
|
|
||||||
for (ah1 = list; ah1; ah1 = ah1->next)
|
for (up = &list, ah1 = list; ah1; ah1 = next)
|
||||||
{
|
{
|
||||||
|
next = ah1->next;
|
||||||
|
|
||||||
if (lendir < strlen(ah1->fname) &&
|
if (lendir < strlen(ah1->fname) &&
|
||||||
strstr(ah1->fname, ah->fname) == ah1->fname &&
|
strstr(ah1->fname, ah->fname) == ah1->fname &&
|
||||||
ah1->fname[lendir] == '/' &&
|
ah1->fname[lendir] == '/' &&
|
||||||
strcmp(ah1->fname + lendir + 1, ent->d_name) == 0)
|
strcmp(ah1->fname + lendir + 1, ent->d_name) == 0)
|
||||||
{
|
{
|
||||||
ah1->flags &= ~AH_INACTIVE;
|
ah1->flags &= ~AH_INACTIVE;
|
||||||
|
/* If found, remove from list to re-insert at the end.
|
||||||
|
Unless it's already at the end. */
|
||||||
|
if (last != ah1)
|
||||||
|
*up = next;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
up = &ah1->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* make new record */
|
/* make new record */
|
||||||
@@ -5111,17 +5132,21 @@ struct hostsfile *expand_filelist(struct hostsfile *list)
|
|||||||
ah1->fname = path;
|
ah1->fname = path;
|
||||||
ah1->index = i++;
|
ah1->index = i++;
|
||||||
ah1->flags = AH_DIR;
|
ah1->flags = AH_DIR;
|
||||||
ah1->next = list;
|
|
||||||
list = ah1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Edge case, may be the last in the list anyway */
|
||||||
|
if (last != ah1)
|
||||||
|
last->next = ah1;
|
||||||
|
ah1->next = NULL;
|
||||||
|
last = ah1;
|
||||||
|
|
||||||
/* inactivate record if not regular file */
|
/* inactivate record if not regular file */
|
||||||
if ((ah1->flags & AH_DIR) && stat(ah1->fname, &buf) != -1 && !S_ISREG(buf.st_mode))
|
if ((ah1->flags & AH_DIR) && stat(ah1->fname, &buf) != -1 && !S_ISREG(buf.st_mode))
|
||||||
ah1->flags |= AH_INACTIVE;
|
ah1->flags |= AH_INACTIVE;
|
||||||
|
|
||||||
}
|
}
|
||||||
closedir(dir_stream);
|
|
||||||
}
|
}
|
||||||
|
free(namelist);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+26
-26
@@ -20,13 +20,13 @@
|
|||||||
|
|
||||||
#define LOG(...) \
|
#define LOG(...) \
|
||||||
do { \
|
do { \
|
||||||
my_syslog(LOG_WARNING, __VA_ARGS__); \
|
my_syslog(LOG_DEBUG, __VA_ARGS__); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define ASSERT(condition) \
|
#define ASSERT(condition) \
|
||||||
do { \
|
do { \
|
||||||
if (!(condition)) \
|
if (!(condition)) \
|
||||||
LOG("[pattern.c:%d] Assertion failure: %s", __LINE__, #condition); \
|
my_syslog(LOG_ERR, _("[pattern.c:%d] Assertion failure: %s"), __LINE__, #condition); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -66,8 +66,8 @@ static int is_string_matching_glob_pattern(
|
|||||||
pattern_character -= 'a' - 'A';
|
pattern_character -= 'a' - 'A';
|
||||||
if (pattern_character == '*')
|
if (pattern_character == '*')
|
||||||
{
|
{
|
||||||
// zero-or-more-character wildcard
|
/* zero-or-more-character wildcard */
|
||||||
// Try to match at value_index, otherwise restart at value_index + 1 next.
|
/* Try to match at value_index, otherwise restart at value_index + 1 next. */
|
||||||
next_pattern_index = pattern_index;
|
next_pattern_index = pattern_index;
|
||||||
pattern_index++;
|
pattern_index++;
|
||||||
if (value_index < num_value_bytes)
|
if (value_index < num_value_bytes)
|
||||||
@@ -78,7 +78,7 @@ static int is_string_matching_glob_pattern(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// ordinary character
|
/* ordinary character */
|
||||||
if (value_index < num_value_bytes)
|
if (value_index < num_value_bytes)
|
||||||
{
|
{
|
||||||
char value_character = value[value_index];
|
char value_character = value[value_index];
|
||||||
@@ -139,7 +139,7 @@ int is_valid_dns_name(const char *value)
|
|||||||
(*c < 'A' || *c > 'Z') &&
|
(*c < 'A' || *c > 'Z') &&
|
||||||
(*c < 'a' || *c > 'z'))
|
(*c < 'a' || *c > 'z'))
|
||||||
{
|
{
|
||||||
LOG("Invalid DNS name: Invalid character %c.", *c);
|
LOG(_("Invalid DNS name: Invalid character %c."), *c);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (*c)
|
if (*c)
|
||||||
@@ -148,12 +148,12 @@ int is_valid_dns_name(const char *value)
|
|||||||
{
|
{
|
||||||
if (!*c || *c == '.')
|
if (!*c || *c == '.')
|
||||||
{
|
{
|
||||||
LOG("Invalid DNS name: Empty label.");
|
LOG(_("Invalid DNS name: Empty label."));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (*c == '-')
|
if (*c == '-')
|
||||||
{
|
{
|
||||||
LOG("Invalid DNS name: Label starts with hyphen.");
|
LOG(_("Invalid DNS name: Label starts with hyphen."));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
label = c;
|
label = c;
|
||||||
@@ -167,13 +167,13 @@ int is_valid_dns_name(const char *value)
|
|||||||
{
|
{
|
||||||
if (c[-1] == '-')
|
if (c[-1] == '-')
|
||||||
{
|
{
|
||||||
LOG("Invalid DNS name: Label ends with hyphen.");
|
LOG(_("Invalid DNS name: Label ends with hyphen."));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
size_t num_label_bytes = (size_t) (c - label);
|
size_t num_label_bytes = (size_t) (c - label);
|
||||||
if (num_label_bytes > 63)
|
if (num_label_bytes > 63)
|
||||||
{
|
{
|
||||||
LOG("Invalid DNS name: Label is too long (%zu).", num_label_bytes);
|
LOG(_("Invalid DNS name: Label is too long (%zu)."), num_label_bytes);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
num_labels++;
|
num_labels++;
|
||||||
@@ -181,12 +181,12 @@ int is_valid_dns_name(const char *value)
|
|||||||
{
|
{
|
||||||
if (num_labels < 2)
|
if (num_labels < 2)
|
||||||
{
|
{
|
||||||
LOG("Invalid DNS name: Not enough labels (%zu).", num_labels);
|
LOG(_("Invalid DNS name: Not enough labels (%zu)."), num_labels);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (is_label_numeric)
|
if (is_label_numeric)
|
||||||
{
|
{
|
||||||
LOG("Invalid DNS name: Final label is fully numeric.");
|
LOG(_("Invalid DNS name: Final label is fully numeric."));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (num_label_bytes == 5 &&
|
if (num_label_bytes == 5 &&
|
||||||
@@ -196,12 +196,12 @@ int is_valid_dns_name(const char *value)
|
|||||||
(label[3] == 'a' || label[3] == 'A') &&
|
(label[3] == 'a' || label[3] == 'A') &&
|
||||||
(label[4] == 'l' || label[4] == 'L'))
|
(label[4] == 'l' || label[4] == 'L'))
|
||||||
{
|
{
|
||||||
LOG("Invalid DNS name: \"local\" pseudo-TLD.");
|
LOG(_("Invalid DNS name: \"local\" pseudo-TLD."));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (num_bytes < 1 || num_bytes > 253)
|
if (num_bytes < 1 || num_bytes > 253)
|
||||||
{
|
{
|
||||||
LOG("DNS name has invalid length (%zu).", num_bytes);
|
LOG(_("DNS name has invalid length (%zu)."), num_bytes);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
@@ -249,13 +249,13 @@ int is_valid_dns_name_pattern(const char *value)
|
|||||||
for (const char *c = value;; c++)
|
for (const char *c = value;; c++)
|
||||||
{
|
{
|
||||||
if (*c &&
|
if (*c &&
|
||||||
*c != '*' && // Wildcard.
|
*c != '*' && /* Wildcard. */
|
||||||
*c != '-' && *c != '.' &&
|
*c != '-' && *c != '.' &&
|
||||||
(*c < '0' || *c > '9') &&
|
(*c < '0' || *c > '9') &&
|
||||||
(*c < 'A' || *c > 'Z') &&
|
(*c < 'A' || *c > 'Z') &&
|
||||||
(*c < 'a' || *c > 'z'))
|
(*c < 'a' || *c > 'z'))
|
||||||
{
|
{
|
||||||
LOG("Invalid DNS name pattern: Invalid character %c.", *c);
|
LOG(_("Invalid DNS name pattern: Invalid character %c."), *c);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (*c && *c != '*')
|
if (*c && *c != '*')
|
||||||
@@ -264,12 +264,12 @@ int is_valid_dns_name_pattern(const char *value)
|
|||||||
{
|
{
|
||||||
if (!*c || *c == '.')
|
if (!*c || *c == '.')
|
||||||
{
|
{
|
||||||
LOG("Invalid DNS name pattern: Empty label.");
|
LOG(_("Invalid DNS name pattern: Empty label."));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (*c == '-')
|
if (*c == '-')
|
||||||
{
|
{
|
||||||
LOG("Invalid DNS name pattern: Label starts with hyphen.");
|
LOG(_("Invalid DNS name pattern: Label starts with hyphen."));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
label = c;
|
label = c;
|
||||||
@@ -282,7 +282,7 @@ int is_valid_dns_name_pattern(const char *value)
|
|||||||
{
|
{
|
||||||
if (num_wildcards >= 2)
|
if (num_wildcards >= 2)
|
||||||
{
|
{
|
||||||
LOG("Invalid DNS name pattern: Wildcard character used more than twice per label.");
|
LOG(_("Invalid DNS name pattern: Wildcard character used more than twice per label."));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
num_wildcards++;
|
num_wildcards++;
|
||||||
@@ -292,13 +292,13 @@ int is_valid_dns_name_pattern(const char *value)
|
|||||||
{
|
{
|
||||||
if (c[-1] == '-')
|
if (c[-1] == '-')
|
||||||
{
|
{
|
||||||
LOG("Invalid DNS name pattern: Label ends with hyphen.");
|
LOG(_("Invalid DNS name pattern: Label ends with hyphen."));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
size_t num_label_bytes = (size_t) (c - label) - num_wildcards;
|
size_t num_label_bytes = (size_t) (c - label) - num_wildcards;
|
||||||
if (num_label_bytes > 63)
|
if (num_label_bytes > 63)
|
||||||
{
|
{
|
||||||
LOG("Invalid DNS name pattern: Label is too long (%zu).", num_label_bytes);
|
LOG(_("Invalid DNS name pattern: Label is too long (%zu)."), num_label_bytes);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
num_labels++;
|
num_labels++;
|
||||||
@@ -306,17 +306,17 @@ int is_valid_dns_name_pattern(const char *value)
|
|||||||
{
|
{
|
||||||
if (num_labels < 2)
|
if (num_labels < 2)
|
||||||
{
|
{
|
||||||
LOG("Invalid DNS name pattern: Not enough labels (%zu).", num_labels);
|
LOG(_("Invalid DNS name pattern: Not enough labels (%zu)."), num_labels);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (num_wildcards != 0 || previous_label_has_wildcard)
|
if (num_wildcards != 0 || previous_label_has_wildcard)
|
||||||
{
|
{
|
||||||
LOG("Invalid DNS name pattern: Wildcard within final two labels.");
|
LOG(_("Invalid DNS name pattern: Wildcard within final two labels."));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (is_label_numeric)
|
if (is_label_numeric)
|
||||||
{
|
{
|
||||||
LOG("Invalid DNS name pattern: Final label is fully numeric.");
|
LOG(_("Invalid DNS name pattern: Final label is fully numeric."));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (num_label_bytes == 5 &&
|
if (num_label_bytes == 5 &&
|
||||||
@@ -326,12 +326,12 @@ int is_valid_dns_name_pattern(const char *value)
|
|||||||
(label[3] == 'a' || label[3] == 'A') &&
|
(label[3] == 'a' || label[3] == 'A') &&
|
||||||
(label[4] == 'l' || label[4] == 'L'))
|
(label[4] == 'l' || label[4] == 'L'))
|
||||||
{
|
{
|
||||||
LOG("Invalid DNS name pattern: \"local\" pseudo-TLD.");
|
LOG(_("Invalid DNS name pattern: \"local\" pseudo-TLD."));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (num_bytes < 1 || num_bytes > 253)
|
if (num_bytes < 1 || num_bytes > 253)
|
||||||
{
|
{
|
||||||
LOG("DNS name pattern has invalid length after removing wildcards (%zu).", num_bytes);
|
LOG(_("DNS name pattern has invalid length after removing wildcards (%zu)."), num_bytes);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
+45
-29
@@ -84,7 +84,7 @@ static void ubus_destroy(struct ubus_context *ubus)
|
|||||||
ubus_free(ubus);
|
ubus_free(ubus);
|
||||||
daemon->ubus = NULL;
|
daemon->ubus = NULL;
|
||||||
|
|
||||||
// Forces re-initialization when we're reusing the same definitions later on.
|
/* Forces re-initialization when we're reusing the same definitions later on. */
|
||||||
ubus_object.id = 0;
|
ubus_object.id = 0;
|
||||||
ubus_object_type.id = 0;
|
ubus_object_type.id = 0;
|
||||||
}
|
}
|
||||||
@@ -171,6 +171,16 @@ void check_ubus_listeners()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define CHECK(stmt) \
|
||||||
|
do { \
|
||||||
|
int e = (stmt); \
|
||||||
|
if (e) \
|
||||||
|
{ \
|
||||||
|
my_syslog(LOG_ERR, _("UBus command failed: %d (%s)"), e, #stmt); \
|
||||||
|
return (UBUS_STATUS_UNKNOWN_ERROR); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
static int ubus_handle_metrics(struct ubus_context *ctx, struct ubus_object *obj,
|
static int ubus_handle_metrics(struct ubus_context *ctx, struct ubus_object *obj,
|
||||||
struct ubus_request_data *req, const char *method,
|
struct ubus_request_data *req, const char *method,
|
||||||
struct blob_attr *msg)
|
struct blob_attr *msg)
|
||||||
@@ -181,12 +191,13 @@ static int ubus_handle_metrics(struct ubus_context *ctx, struct ubus_object *obj
|
|||||||
(void)method;
|
(void)method;
|
||||||
(void)msg;
|
(void)msg;
|
||||||
|
|
||||||
blob_buf_init(&b, BLOBMSG_TYPE_TABLE);
|
CHECK(blob_buf_init(&b, BLOBMSG_TYPE_TABLE));
|
||||||
|
|
||||||
for (i=0; i < __METRIC_MAX; i++)
|
for (i=0; i < __METRIC_MAX; i++)
|
||||||
blobmsg_add_u32(&b, get_metric_name(i), daemon->metrics[i]);
|
CHECK(blobmsg_add_u32(&b, get_metric_name(i), daemon->metrics[i]));
|
||||||
|
|
||||||
return ubus_send_reply(ctx, req, b.head);
|
CHECK(ubus_send_reply(ctx, req, b.head));
|
||||||
|
return UBUS_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_CONNTRACK
|
#ifdef HAVE_CONNTRACK
|
||||||
@@ -305,66 +316,71 @@ fail:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#undef CHECK
|
||||||
|
|
||||||
|
#define CHECK(stmt) \
|
||||||
|
do { \
|
||||||
|
int e = (stmt); \
|
||||||
|
if (e) \
|
||||||
|
{ \
|
||||||
|
my_syslog(LOG_ERR, _("UBus command failed: %d (%s)"), e, #stmt); \
|
||||||
|
return; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
void ubus_event_bcast(const char *type, const char *mac, const char *ip, const char *name, const char *interface)
|
void ubus_event_bcast(const char *type, const char *mac, const char *ip, const char *name, const char *interface)
|
||||||
{
|
{
|
||||||
struct ubus_context *ubus = (struct ubus_context *)daemon->ubus;
|
struct ubus_context *ubus = (struct ubus_context *)daemon->ubus;
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (!ubus || !ubus_object.has_subscribers)
|
if (!ubus || !ubus_object.has_subscribers)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
blob_buf_init(&b, BLOBMSG_TYPE_TABLE);
|
CHECK(blob_buf_init(&b, BLOBMSG_TYPE_TABLE));
|
||||||
if (mac)
|
if (mac)
|
||||||
blobmsg_add_string(&b, "mac", mac);
|
CHECK(blobmsg_add_string(&b, "mac", mac));
|
||||||
if (ip)
|
if (ip)
|
||||||
blobmsg_add_string(&b, "ip", ip);
|
CHECK(blobmsg_add_string(&b, "ip", ip));
|
||||||
if (name)
|
if (name)
|
||||||
blobmsg_add_string(&b, "name", name);
|
CHECK(blobmsg_add_string(&b, "name", name));
|
||||||
if (interface)
|
if (interface)
|
||||||
blobmsg_add_string(&b, "interface", interface);
|
CHECK(blobmsg_add_string(&b, "interface", interface));
|
||||||
|
|
||||||
ret = ubus_notify(ubus, &ubus_object, type, b.head, -1);
|
CHECK(ubus_notify(ubus, &ubus_object, type, b.head, -1));
|
||||||
if (ret)
|
|
||||||
my_syslog(LOG_ERR, _("Failed to send UBus event: %s"), ubus_strerror(ret));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_CONNTRACK
|
#ifdef HAVE_CONNTRACK
|
||||||
void ubus_event_bcast_connmark_allowlist_refused(u32 mark, const char *name)
|
void ubus_event_bcast_connmark_allowlist_refused(u32 mark, const char *name)
|
||||||
{
|
{
|
||||||
struct ubus_context *ubus = (struct ubus_context *)daemon->ubus;
|
struct ubus_context *ubus = (struct ubus_context *)daemon->ubus;
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (!ubus || !ubus_object.has_subscribers)
|
if (!ubus || !ubus_object.has_subscribers)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
blob_buf_init(&b, 0);
|
CHECK(blob_buf_init(&b, 0));
|
||||||
blobmsg_add_u32(&b, "mark", mark);
|
CHECK(blobmsg_add_u32(&b, "mark", mark));
|
||||||
blobmsg_add_string(&b, "name", name);
|
CHECK(blobmsg_add_string(&b, "name", name));
|
||||||
|
|
||||||
ret = ubus_notify(ubus, &ubus_object, "connmark-allowlist.refused", b.head, -1);
|
CHECK(ubus_notify(ubus, &ubus_object, "connmark-allowlist.refused", b.head, -1));
|
||||||
if (ret)
|
|
||||||
my_syslog(LOG_ERR, _("Failed to send UBus event: %s"), ubus_strerror(ret));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ubus_event_bcast_connmark_allowlist_resolved(u32 mark, const char *name, const char *value, u32 ttl)
|
void ubus_event_bcast_connmark_allowlist_resolved(u32 mark, const char *name, const char *value, u32 ttl)
|
||||||
{
|
{
|
||||||
struct ubus_context *ubus = (struct ubus_context *)daemon->ubus;
|
struct ubus_context *ubus = (struct ubus_context *)daemon->ubus;
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (!ubus || !ubus_object.has_subscribers)
|
if (!ubus || !ubus_object.has_subscribers)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
blob_buf_init(&b, 0);
|
CHECK(blob_buf_init(&b, 0));
|
||||||
blobmsg_add_u32(&b, "mark", mark);
|
CHECK(blobmsg_add_u32(&b, "mark", mark));
|
||||||
blobmsg_add_string(&b, "name", name);
|
CHECK(blobmsg_add_string(&b, "name", name));
|
||||||
blobmsg_add_string(&b, "value", value);
|
CHECK(blobmsg_add_string(&b, "value", value));
|
||||||
blobmsg_add_u32(&b, "ttl", ttl);
|
CHECK(blobmsg_add_u32(&b, "ttl", ttl));
|
||||||
|
|
||||||
ret = ubus_notify(ubus, &ubus_object, "connmark-allowlist.resolved", b.head, /* timeout: */ 1000);
|
/* Set timeout to allow UBus subscriber to configure firewall rules before returning. */
|
||||||
if (ret)
|
CHECK(ubus_notify(ubus, &ubus_object, "connmark-allowlist.resolved", b.head, /* timeout: */ 1000));
|
||||||
my_syslog(LOG_ERR, _("Failed to send UBus event: %s"), ubus_strerror(ret));
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#undef CHECK
|
||||||
|
|
||||||
#endif /* HAVE_UBUS */
|
#endif /* HAVE_UBUS */
|
||||||
Reference in new issue
Block a user