static void bfd_nbrip_handler(vector_t *strvec) { bfd_t *bfd; struct sockaddr_storage nbr_addr; assert(strvec); assert(bfd_data); bfd = LIST_TAIL_DATA(bfd_data->bfd); assert(bfd); if (!strcmp(vector_slot(strvec, 1), "neighbour_ip")) neighbor_str = "neighbour"; if (inet_stosockaddr(strvec_slot(strvec, 1), BFD_CONTROL_PORT, &nbr_addr)) { report_config_error(CONFIG_GENERAL_ERROR, "Configuration error: BFD instance %s has" " malformed %s address %s, ignoring instance", bfd->iname, neighbor_str, FMT_STR_VSLOT(strvec, 1)); list_del(bfd_data->bfd, bfd); skip_block(false); return; } else if (find_bfd_by_addr(&nbr_addr)) { report_config_error(CONFIG_GENERAL_ERROR, "Configuration error: BFD instance %s has" " duplicate %s address %s, ignoring instance", bfd->iname, neighbor_str, FMT_STR_VSLOT(strvec, 1)); list_del(bfd_data->bfd, bfd); skip_block(false); return; } else bfd->nbr_addr = nbr_addr; }
static void bfd_idletx_handler(vector_t *strvec) { bfd_t *bfd; unsigned value; assert(strvec); assert(bfd_data); bfd = LIST_TAIL_DATA(bfd_data->bfd); assert(bfd); if (!read_unsigned_strvec(strvec, 1, &value,BFD_IDLETX_MIN, BFD_IDLETX_MAX, false)) report_config_error(CONFIG_GENERAL_ERROR, "Configuration error: BFD instance %s" " idle_tx value %s is not valid (must be in range" " [%u-%u]), ignoring", bfd->iname, FMT_STR_VSLOT(strvec, 1), BFD_IDLETX_MIN, BFD_IDLETX_MAX); else bfd->local_idle_tx_intv = value * 1000U; if (value > BFD_IDLETX_MAX_SENSIBLE) log_message(LOG_INFO, "Configuration warning: BFD instance %s" " idle_tx value %u is larger than max sensible (%u)", bfd->iname, value, BFD_IDLETX_MAX_SENSIBLE); }
vector_t * read_value_block(vector_t *strvec) { char *buf; unsigned int word; char *str = NULL; char *dup; vector_t *vec = NULL; vector_t *elements = vector_alloc(); int first = 1; int need_bob = 1; int got_eob = 0; buf = (char *) MALLOC(MAXBUF); while (first || read_line(buf, MAXBUF)) { if (first && vector_size(strvec) > 1) { vec = strvec; word = 1; } else { vec = alloc_strvec(buf); word = 0; } if (vec) { str = vector_slot(vec, word); if (need_bob) { if (!strcmp(str, BOB)) word++; else log_message(LOG_INFO, "'{' missing at beginning of block %s", FMT_STR_VSLOT(strvec,0)); need_bob = 0; } for (; word < vector_size(vec); word++) { str = vector_slot(vec, word); if (!strcmp(str, EOB)) { if (word != vector_size(vec) - 1) log_message(LOG_INFO, "Extra characters after '}' - \"%s\"", buf); got_eob = 1; break; } dup = (char *) MALLOC(strlen(str) + 1); memcpy(dup, str, strlen(str)); vector_alloc_slot(elements); vector_set_slot(elements, dup); } if (vec != strvec) free_strvec(vec); if (got_eob) break; } memset(buf, 0, MAXBUF); first = 0; } FREE(buf); return elements; }
static void vrrp_srcip_handler(vector_t *strvec) { vrrp_t *vrrp = LIST_TAIL_DATA(vrrp_data->vrrp); struct sockaddr_storage *saddr = &vrrp->saddr; int ret; ret = inet_stosockaddr(vector_slot(strvec, 1), 0, saddr); if (ret < 0) { log_message(LOG_ERR, "Configuration error: VRRP instance[%s] malformed unicast" " src address[%s]. Skipping..." , vrrp->iname, FMT_STR_VSLOT(strvec, 1)); return; } if (saddr->ss_family != vrrp->family) { log_message(LOG_ERR, "Configuration error: VRRP instance[%s] and unicast src address" "[%s] MUST be of the same family !!! Skipping..." , vrrp->iname, FMT_STR_VSLOT(strvec, 1)); memset(saddr, 0, sizeof(struct sockaddr_storage)); } }
static void vrrp_strict_mode_handler(vector_t *strvec) { int res; vrrp_t *vrrp = LIST_TAIL_DATA(vrrp_data->vrrp); if (vector_size(strvec) >= 2) { res = check_true_false(vector_slot(strvec, 1)); if (res >= 0) vrrp->strict_mode = res; else log_message(LOG_INFO, "(%s): invalid strict_mode %s specified", vrrp->iname, FMT_STR_VSLOT(strvec, 1)); } else { /* Defaults to true */ vrrp->strict_mode = true; } }
static void bfd_multiplier_handler(vector_t *strvec) { bfd_t *bfd; unsigned value; assert(strvec); assert(bfd_data); bfd = LIST_TAIL_DATA(bfd_data->bfd); assert(bfd); if (!read_unsigned_strvec(strvec, 1, &value, BFD_MULTIPLIER_MIN, BFD_MULTIPLIER_MAX, false)) report_config_error(CONFIG_GENERAL_ERROR, "Configuration error: BFD instance %s" " multiplier value %s not valid (must be in range" " [%u-%u]), ignoring", bfd->iname, FMT_STR_VSLOT(strvec, 1), BFD_MULTIPLIER_MIN, BFD_MULTIPLIER_MAX); else bfd->local_detect_mult = value; }
static void bfd_srcip_handler(vector_t *strvec) { bfd_t *bfd; struct sockaddr_storage src_addr; assert(strvec); assert(bfd_data); bfd = LIST_TAIL_DATA(bfd_data->bfd); assert(bfd); if (inet_stosockaddr(strvec_slot(strvec, 1), NULL, &src_addr)) { report_config_error(CONFIG_GENERAL_ERROR, "Configuration error: BFD instance %s has" " malformed source address %s, ignoring", bfd->iname, FMT_STR_VSLOT(strvec, 1)); } else bfd->src_addr = src_addr; }
static void read_file(const char* file_name, list *l, uint32_t max) { FILE *fp; rt_entry_t *rte; vector_t *strvec = NULL; char buf[MAX_RT_BUF]; unsigned long id; char *number; char *endptr; fp = fopen(file_name, "r"); if (!fp) return; while (fgets(buf, MAX_RT_BUF, fp)) { strvec = alloc_strvec(buf); if (!strvec) continue; if (vector_size(strvec) != 2) { free_strvec(strvec); continue; } rte = MALLOC(sizeof(rt_entry_t)); if (!rte) { free_strvec(strvec); goto err; } number = strvec_slot(strvec, 0); number += strspn(number, " \t"); id = strtoul(number, &endptr, 0); if (*number == '-' || number == endptr || *endptr || id > max) { FREE(rte); free_strvec(strvec); continue; } rte->id = (unsigned)id; rte->name = MALLOC(strlen(FMT_STR_VSLOT(strvec, 1)) + 1); if (!rte->name) { FREE(rte); free_strvec(strvec); goto err; } strcpy(rte->name, FMT_STR_VSLOT(strvec, 1)); list_add(*l, rte); free_strvec(strvec); } fclose(fp); return; err: fclose(fp); if (strvec) free_strvec(strvec); free_list(l); return; }
static void smtpto_handler(vector_t *strvec) { unsigned timeout; /* The min value should be 1, but allow 0 to maintain backward compatibility * with pre v2.0.7 */ if (!read_unsigned_strvec(strvec, 1, &timeout, 0, UINT_MAX / TIMER_HZ, true)) { report_config_error(CONFIG_GENERAL_ERROR, "smtp_connect_timeout '%s' must be in [0, %d] - ignoring", FMT_STR_VSLOT(strvec, 1), UINT_MAX / TIMER_HZ); return; } if (timeout == 0) { report_config_error(CONFIG_GENERAL_ERROR, "smtp_conect_timeout must be greater than 0, setting to 1"); timeout = 1; } global_data->smtp_connection_to = timeout * TIMER_HZ; }
static bool read_rttables(void) { FILE *fp; rt_entry_t *rte; vector_t *strvec = NULL; char buf[MAX_RT_TABLES_BUF]; if (rt_list) return true; fp = fopen(RT_TABLES_FILE, "r"); if (!fp) { if (errno == EACCES || errno == EISDIR || errno == ENOENT) { /* This is a permanent error, so don't keep trying to reopen the file */ rt_list = alloc_list(NULL, NULL); return true; } return false; } rt_list = alloc_list(free_rt_entry, dump_rt_entry); if (!rt_list) goto err; while (fgets(buf, MAX_RT_TABLES_BUF, fp)) { strvec = alloc_strvec(buf); if (!strvec) continue; if (vector_size(strvec) != 2) { free_strvec(strvec); continue; } rte = MALLOC(sizeof(rt_entry_t)); if (!rte) goto err; rte->id = strtoul(FMT_STR_VSLOT(strvec, 0), NULL, 0); rte->name = MALLOC(strlen(FMT_STR_VSLOT(strvec, 1)) + 1); if (!rte->name) { FREE(rte); goto err; } strcpy(rte->name, FMT_STR_VSLOT(strvec, 1)); list_add(rt_list, rte); free_strvec(strvec); strvec = NULL; } fclose(fp); return true; err: fclose(fp); if (!strvec) free_strvec(strvec); free_list(&rt_list); return false; }