return false;
}
- /* Teach newbies what subnets are... */
-
- if(((subnet.type == SUBNET_IPV4)
- && !maskcheck(&subnet.net.ipv4.address, subnet.net.ipv4.prefixlength, sizeof(subnet.net.ipv4.address)))
- || ((subnet.type == SUBNET_IPV6)
- && !maskcheck(&subnet.net.ipv6.address, subnet.net.ipv6.prefixlength, sizeof(subnet.net.ipv6.address)))) {
- logger(DEBUG_ALWAYS, LOG_ERR, "Network address and prefix length do not match for configuration variable %s in %s line %d",
- cfg->variable, cfg->file, cfg->line);
- return false;
+ if (subnetcheck(subnet)) {
+ *(*result = new_subnet()) = subnet;
+ return true;
}
- *(*result = new_subnet()) = subnet;
-
- return true;
+ logger(DEBUG_ALWAYS, LOG_ERR, "Network address and prefix length do not match for configuration variable %s in %s line %d",
+ cfg->variable, cfg->file, cfg->line);
+ return false;
}
/*
while(cfg) {
subnet_t *subnet, *s2;
- if(!get_config_subnet(cfg, &subnet)) {
- cfg = lookup_config_next(config_tree, cfg);
- continue;
- }
+ if(get_config_subnet(cfg, &subnet)) {
+ if((s2 = lookup_subnet(myself, subnet))) {
+ if(s2->expires == 1) {
+ s2->expires = 0;
+ }
- if((s2 = lookup_subnet(myself, subnet))) {
- if(s2->expires == 1) {
- s2->expires = 0;
+ free_subnet(subnet);
+ } else {
+ subnet_add(myself, subnet);
+ send_add_subnet(everyone, subnet);
+ subnet_update(myself, subnet, true);
}
-
- free_subnet(subnet);
- } else {
- subnet_add(myself, subnet);
- send_add_subnet(everyone, subnet);
- subnet_update(myself, subnet, true);
}
cfg = lookup_config_next(config_tree, cfg);
extern int maskcmp(const void *a, const void *b, int masklen);
extern void maskcpy(void *dest, const void *src, int masklen, int len);
extern void mask(void *mask, int masklen, int len);
+extern bool subnetcheck(const subnet_t subnet);
extern bool maskcheck(const void *mask, int masklen, int len);
extern bool net2str(char *netstr, int len, const subnet_t *subnet);
extern bool str2net(subnet_t *subnet, const char *netstr);
}
}
+bool subnetcheck(const subnet_t subnet) {
+ if(((subnet.type == SUBNET_IPV4)
+ && !maskcheck(&subnet.net.ipv4.address, subnet.net.ipv4.prefixlength, sizeof(subnet.net.ipv4.address)))
+ || ((subnet.type == SUBNET_IPV6)
+ && !maskcheck(&subnet.net.ipv6.address, subnet.net.ipv6.prefixlength, sizeof(subnet.net.ipv6.address)))) {
+ return false;
+ }
+
+ return true;
+}
+
bool maskcheck(const void *va, int masklen, int len) {
int i;
const char *a = va;
#include "tincctl.h"
#include "top.h"
#include "version.h"
+#include "subnet.h"
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
found = true;
variable = (char *)variables[i].name;
+ if (!strcasecmp(variable, "Subnet")) {
+ subnet_t s = {0};
+
+ if(!str2net(&s, value)) {
+ fprintf(stderr, "Malformed subnet definition %s\n", value);
+ }
+
+ if(!subnetcheck(s)) {
+ fprintf(stderr, "Network address and prefix length do not match: %s\n", value);
+ return 1;
+ }
+ }
+
/* Discourage use of obsolete variables. */
if(variables[i].type & VAR_OBSOLETE && action >= 0) {