void alloc_track(list track_list, vector_t *strvec) { interface_t *ifp = NULL; tracked_if_t *tip = NULL; int weight = 0; char *tracked = strvec_slot(strvec, 0); ifp = if_get_by_ifname(tracked); /* Ignoring if no interface found */ if (!ifp) { log_message(LOG_INFO, " %s no match, ignoring...", tracked); return; } if (vector_size(strvec) >= 3 && !strcmp(strvec_slot(strvec, 1), "weight")) { weight = atoi(strvec_slot(strvec, 2)); if (weight < -254 || weight > 254) { log_message(LOG_INFO, " %s: weight must be between " "[-254..254] inclusive. Ignoring...", tracked); weight = 0; } } tip = (tracked_if_t *) MALLOC(sizeof(tracked_if_t)); tip->ifp = ifp; tip->weight = weight; list_add(track_list, tip); }
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 http_get_handler(vector_t *strvec) { http_checker_t *http_get_chk; char *str = strvec_slot(strvec, 0); /* queue new checker */ http_get_chk = alloc_http_get(str); queue_checker(free_http_get_check, dump_http_get_check, http_connect_thread, http_get_chk, CHECKER_NEW_CO()); }
unsigned long read_timer(vector_t *strvec) { unsigned long timer; timer = strtoul(strvec_slot(strvec, 1), NULL, 10); if (timer >= ULONG_MAX / TIMER_HZ) return ULONG_MAX; return timer * TIMER_HZ; }
void alloc_track_script(list track_list, vector_t *strvec, const char *vrrp_iname) { vrrp_script_t *vsc = NULL; tracked_sc_t *tsc = NULL; int weight = 0; char *tracked = strvec_slot(strvec, 0); vsc = find_script_by_name(tracked); /* Ignoring if no script found */ if (!vsc) { log_message(LOG_INFO, "(%s): track script %s not found, ignoring...", vrrp_iname, tracked); return; } /* default weight */ weight = vsc->weight; if (vector_size(strvec) >= 3 && !strcmp(strvec_slot(strvec, 1), "weight")) { weight = atoi(strvec_slot(strvec, 2)); if (weight < -254 || weight > 254) { weight = vsc->weight; log_message(LOG_INFO, "(%s): track script %s: weight must be between [-254..254]" " inclusive, ignoring...", vrrp_iname, tracked); } } tsc = (tracked_sc_t *) MALLOC(sizeof(tracked_sc_t)); tsc->scr = vsc; tsc->weight = weight; vsc->inuse++; list_add(track_list, tsc); }
static void dynamic_interfaces_handler(vector_t *strvec) { char *str; global_data->dynamic_interfaces = true; if (vector_size(strvec) >= 2) { str = strvec_slot(strvec, 1); if (!strcmp(str, "allow_if_changes")) global_data->allow_if_changes = true; else report_config_error(CONFIG_GENERAL_ERROR, "Unknown dynamic_interfaces option '%s'",str); } }
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; }