Skip to content
Snippets Groups Projects
Commit be2fc144 authored by Marek Vavrusa's avatar Marek Vavrusa
Browse files

Fixed logfiles, config support for IPv6.

Commit refs #461, #12, #463.
parent 23fc8610
No related branches found
No related tags found
No related merge requests found
......@@ -86,12 +86,21 @@ error { cf_lval.i = LOG_MASK(LOG_ERR); return LOG_LEVEL; }
}
({HEXA}*::|({HEXA}*:){3,})({HEXA}*|{DIGIT}+\.{DIGIT}+\.{DIGIT}+\.{DIGIT}+) {
#ifdef DISABLE_IPV6
unsigned char buf[sizeof(struct in6_addr)];
if (inet_pton(AF_INET6, yytext, buf)) {
cf_lval.t = strdup(yytext);
return IPA6;
}
cf_error("Invalid IPv6 address.");
#else
unsigned char buf[sizeof(struct in6_addr)];
if (inet_pton(AF_INET6, yytext, buf)) {
cf_lval.t = strdup(yytext);
return IPA;
return IPA6;
}
cf_error("Invalid IPv6 address.");
#endif
}
gss-tsig { cf_lval.alg = GSS_TSIG; return TSIG_ALGO_NAME; }
......
......@@ -39,6 +39,7 @@ static conf_log_map_t *this_logmap = 0;
%token INTERFACES ADDRESS PORT
%token <t> IPA
%token <t> IPA6
%token LOG
%token <i> LOG_DEST
......@@ -67,12 +68,25 @@ interface_start: TEXT {
interface:
interface_start '{'
| interface ADDRESS IPA ';' { this_iface->address = $3; }
| interface PORT NUM ';' { this_iface->port = $3; }
| interface ADDRESS IPA ';' {
this_iface->address = $3;
this_iface->family = AF_INET;
}
| interface ADDRESS IPA '@' NUM ';' {
this_iface->address = $3;
this_iface->family = AF_INET;
this_iface->port = $5;
}
| interface ADDRESS IPA6 ';' {
this_iface->address = $3;
this_iface->family = AF_INET6;
}
| interface ADDRESS IPA6 '@' NUM ';' {
this_iface->address = $3;
this_iface->family = AF_INET6;
this_iface->port = $5;
}
;
interfaces:
......@@ -191,7 +205,7 @@ log_file: FILENAME TEXT {
if (!this_log) {
this_log = malloc(sizeof(conf_log_t));
this_log->type = LOGT_FILE;
this_log->file = $2;
this_log->file = strcpath($2);
init_list(&this_log->map);
add_tail(&new_config->logs, &this_log->n);
++new_config->logs_count;
......
......@@ -21,37 +21,6 @@ static char* strcdup(const char *s1, const char *s2)
return dst;
}
static char* strcpath(char *path)
{
// Remote trailing slash
size_t plen = strlen(path);
if (path[plen - 1] == '/') {
path[--plen] = '\0';
}
// Expand '~'
char* tild_p = strchr(path,'~');
if (tild_p != 0) {
// Get full path
char *tild_exp = getenv("HOME");
size_t tild_len = strlen(tild_exp);
if (tild_exp[tild_len - 1] == '/') {
tild_exp[--tild_len] = '\0';
}
// Expand
char *npath = malloc(plen + tild_len + 1);
npath[0] = '\0';
strncpy(npath, path, (size_t)(tild_p - path));
strcat(npath, tild_exp);
strcat(npath, tild_p + 1);
free(path);
path = npath;
}
return path;
}
static int rmkdir(char *path, int mode)
{
char *p = path;
......@@ -501,3 +470,35 @@ int conf_open(const char* path)
return 0;
}
char* strcpath(char *path)
{
// Remote trailing slash
size_t plen = strlen(path);
if (path[plen - 1] == '/') {
path[--plen] = '\0';
}
// Expand '~'
char* tild_p = strchr(path,'~');
if (tild_p != 0) {
// Get full path
char *tild_exp = getenv("HOME");
size_t tild_len = strlen(tild_exp);
if (tild_exp[tild_len - 1] == '/') {
tild_exp[--tild_len] = '\0';
}
// Expand
char *npath = malloc(plen + tild_len + 1);
npath[0] = '\0';
strncpy(npath, path, (size_t)(tild_p - path));
strcat(npath, tild_exp);
strcat(npath, tild_p + 1);
free(path);
path = npath;
}
return path;
}
......@@ -34,6 +34,7 @@ typedef struct {
char *name; /*!< Internal name for the interface. */
char *address; /*!< IP (IPv4/v6) address for this interface */
int port; /*!< Port number for this interface */
int family; /*!< Address family. */
} conf_iface_t;
/*!
......@@ -267,6 +268,19 @@ static inline conf_t* conf() {
return s_config; // Inline for performance reasons.
}
/*
* Utilities.
*/
/*!
* \brief Return normalized path.
*
* \note Old pointer may be freed.
*
* \retval Pointer to normalized path.
*/
char* strcpath(char *path);
#endif /* _CUTEDNS_CONF_H_ */
/*! \} */
......@@ -11,12 +11,21 @@
int log_conf_hook(const struct conf_t *conf)
{
// Find maximum log facility id
node *n = 0; size_t files = 0;
WALK_LIST(n, conf->logs) {
conf_log_t* log = (conf_log_t*)n;
if (log->type == LOGT_FILE) {
++files;
}
}
// Initialize logsystem
log_truncate();
log_setup(conf->logs_count);
log_setup(files);
// Setup logs
node *n = 0;
n = 0;
WALK_LIST(n, conf->logs) {
// Calculate offset
......@@ -24,6 +33,11 @@ int log_conf_hook(const struct conf_t *conf)
int facility = log->type;
if (facility == LOGT_FILE) {
facility = log_open_file(log->file);
if (facility < 0) {
log_error("Failed to open logfile '%s'.\n",
log->file);
continue;
}
}
// Setup sources mapping
......
......@@ -12,38 +12,42 @@
static uint8_t *LOG_FCL = 0;
static volatile size_t LOG_FCL_SIZE = 0;
static FILE** LOG_FDS = 0;
static size_t LOG_FDS_OPEN = 0;
static ssize_t LOG_FDS_OPEN = 0;
#define facility_at(i) (LOG_FCL + ((i) << LOG_SRC_BITS))
#define facility_next(f) (f) += (1 << LOG_SRC_BITS)
#define facility_levels(f, i) *((f) + (i))
int log_setup(int facilities)
int log_setup(int logfiles)
{
/* Check facilities count. */
if (facilities <= 0) {
if (logfiles < 0) {
return -1;
}
/* Ensure minimum facilities count. */
int facilities = LOGT_FILE + logfiles;
/* Reserve space for facilities. */
size_t new_size = facilities << LOG_SRC_BITS;
LOG_FDS = 0;
LOG_FDS_OPEN = 0;
LOG_FCL = 0;
LOG_FCL_SIZE = 0;
LOG_FCL = malloc(new_size);
if (!LOG_FCL) {
return -1;
}
/* Reserve space for logfiles. */
int files = (facilities - LOGT_FILE);
if (files > 0) {
LOG_FDS = malloc(sizeof(FILE*) * files);
if (logfiles > 0) {
LOG_FDS = malloc(sizeof(FILE*) * logfiles);
if (!LOG_FDS) {
free(LOG_FCL);
LOG_FCL = 0;
return -1;
}
memset(LOG_FDS, 0, sizeof(FILE*) * files);
memset(LOG_FDS, 0, sizeof(FILE*) * logfiles);
}
memset(LOG_FCL, 0, new_size);
......@@ -62,7 +66,7 @@ int log_init()
LOG_FDS_OPEN = 0;
/* Setup initial state. */
log_setup(LOGT_FILE);
log_setup(0);
log_levels_set(LOGT_SYSLOG, LOG_ANY, LOG_MASK(LOG_ERR));
log_levels_set(LOGT_STDERR, LOG_ANY, LOG_MASK(LOG_ERR));
......
......@@ -52,12 +52,12 @@ typedef enum {
* Facilities ordering: Syslog, Stderr, Stdout, File0...
* \see logtype_t
*
* \param facilities Number of requested facilities.
* \param logfiles Number of extra logfiles.
*
* \retval 0 On success.
* \retval <0 If an error occured.
*/
int log_setup(int facilities);
int log_setup(int logfiles);
/*!
* \brief Setup logging subsystem.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment