diff --git a/config.h b/config.h index 1a0e0c9a..556387f3 100644 --- a/config.h +++ b/config.h @@ -177,15 +177,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. typedef unsigned long debugflags_t; +#define PORT_DNA 4110 #define RHIZOME_HTTP_PORT 4110 typedef struct binarysid { unsigned char binary[SID_SIZE]; } sid_t; #define SID_NONE ((sid_t){0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}) #define SID_BROADCAST ((sid_t){0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}) +#define INTERFACE_NAME_STRLEN 40 struct pattern_list { unsigned patc; - char patv[16][41]; + char patv[16][INTERFACE_NAME_STRLEN + 1]; }; #define PATTERN_LIST_EMPTY ((struct pattern_list){.patc = 0}) diff --git a/config_schema.h b/config_schema.h index ce1d6edd..ee211bae 100644 --- a/config_schema.h +++ b/config_schema.h @@ -213,6 +213,14 @@ STRUCT(directory) ATOM(sid_t, service, SID_NONE, opt_sid,, "Subscriber ID of Serval Directory Service") END_STRUCT +STRUCT(host) +STRING(INTERFACE_NAME_STRLEN, interface, "", opt_str_nonempty, MANDATORY, "Interface name") +ATOM(struct in_addr, address, (struct in_addr){0}, opt_in_addr, MANDATORY, "Host IP address") +ATOM(uint16_t, port, PORT_DNA, opt_port,, "Port number") +END_STRUCT + +ARRAY_STRUCT(host_list, 32, SID_STRLEN, host, opt_str_hex_sid) + STRUCT(network_interface) ATOM(int, exclude, 0, opt_boolean,, "If true, do not use matching interfaces") ATOM(struct pattern_list, match, PATTERN_LIST_EMPTY, opt_pattern_list, MANDATORY, "Names that match network interface") @@ -232,4 +240,5 @@ SUB_STRUCT(dna, dna,) NODE(debugflags_t, debug, 0, opt_debugflags, USES_CHILDREN, "Debug flags") SUB_STRUCT(rhizome, rhizome,) SUB_STRUCT(directory, directory,) +SUB_STRUCT(host_list, hosts,) END_STRUCT diff --git a/config_test.c b/config_test.c index 6fa45a7e..8c6ed1c9 100644 --- a/config_test.c +++ b/config_test.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "str.h" #include "strbuf.h" @@ -412,7 +413,9 @@ int opt_str_nonempty(char *str, size_t len, const char *text); int opt_int(int *intp, const char *text); int opt_uint64_scaled(uint64_t *intp, const char *text); int opt_protocol(char *str, size_t len, const char *text); +int opt_in_addr(struct in_addr *addrp, const char *text); int opt_port(unsigned short *portp, const char *text); +int opt_str_hex_sid(char *sidhexp, size_t len, const char *text); int opt_sid(sid_t *sidp, const char *text); int opt_interface_type(short *typep, const char *text); int opt_pattern_list(struct pattern_list *listp, const char *text); @@ -630,7 +633,7 @@ int opt_uint64_scaled(uint64_t *intp, const char *text) return CFOK; } -int opt_argv_label(char *str, size_t len, const char *text) +int opt_argv_label(char *labelp, size_t len, const char *text) { const char *s = text; if (isdigit(*s) && *s != '0') { @@ -642,7 +645,7 @@ int opt_argv_label(char *str, size_t len, const char *text) return CFINVALID; if (s - text >= len) return CFSTRINGOVERFLOW; - strncpy(str, text, len - 1)[len - 1] = '\0'; + strncpy(labelp, text, len - 1)[len - 1] = '\0'; return CFOK; } @@ -672,6 +675,15 @@ int vld_argv(const struct cf_om_node *parent, struct config_argv *array, int res return result; } +int opt_in_addr(struct in_addr *addrp, const char *text) +{ + struct in_addr addr; + if (!inet_aton(text, &addr)) + return CFINVALID; + *addrp = addr; + return CFOK; +} + int opt_port(unsigned short *portp, const char *text) { unsigned short port = 0; @@ -690,6 +702,16 @@ int opt_port(unsigned short *portp, const char *text) return CFOK; } +int opt_str_hex_sid(char *sidhexp, size_t len, const char *text) +{ + if (!str_is_subscriber_id(text)) + return CFINVALID; + if (len <= SID_STRLEN) + return CFSTRINGOVERFLOW; + strncpy(sidhexp, text, SID_STRLEN)[SID_STRLEN] = '\0'; + return CFOK; +} + int opt_sid(sid_t *sidp, const char *text) { sid_t sid; @@ -1121,6 +1143,12 @@ int main(int argc, char **argv) DEBUGF(" .port = %u", config.interfaces.av[j].value.port); DEBUGF(" .speed = %llu", (unsigned long long) config.interfaces.av[j].value.speed); } + for (j = 0; j < config.hosts.ac; ++j) { + DEBUGF("config.hosts.%s", config.hosts.av[j].label); + DEBUGF(" .interface = %s", alloca_str(config.hosts.av[j].value.interface)); + DEBUGF(" .address = %s", inet_ntoa(config.hosts.av[j].value.address)); + DEBUGF(" .port = %u", config.hosts.av[j].value.port); + } } exit(0); }