void alloc_track(list track_list, vector strvec) { interface *ifp = NULL; tracked_if *tip = NULL; int weight = 0; char *tracked = VECTOR_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(VECTOR_SLOT(strvec, 1), "weight")) { weight = atoi(VECTOR_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 *) MALLOC(sizeof (tracked_if)); tip->ifp = ifp; tip->weight = weight; list_add(track_list, tip); }
int _install_keyword(vector keywords, char *string, int (*handler) (struct config *, vector), int (*print) (struct config *, char *, int, void *), int unique) { int i = 0; struct keyword *keyword; /* fetch last keyword */ keyword = VECTOR_SLOT(keywords, VECTOR_SIZE(keywords) - 1); /* position to last sub level */ for (i = 0; i < sublevel; i++) keyword = VECTOR_SLOT(keyword->sub, VECTOR_SIZE(keyword->sub) - 1); /* First sub level allocation */ if (!keyword->sub) keyword->sub = vector_alloc(); if (!keyword->sub) return 1; /* add new sub keyword */ return keyword_alloc(keyword->sub, string, handler, print, unique); }
static void pgr_handler(vector strvec) { virtual_server *vs = LIST_TAIL_DATA(check_data->vs); if (vs->addr.ss_family == AF_INET6) vs->granularity_persistence = atoi(VECTOR_SLOT(strvec, 1)); else inet_ston(VECTOR_SLOT(strvec, 1), &vs->granularity_persistence); }
struct path * first_path (struct multipath * mpp) { struct pathgroup * pgp; if (!mpp->pg) return NULL; pgp = VECTOR_SLOT(mpp->pg, 0); return pgp?VECTOR_SLOT(pgp->paths, 0):NULL; }
vector read_value_block(void) { char *buf; int i; char *str = NULL; char *dup; vector vec = NULL; vector elements = vector_alloc(); if (!elements) return NULL; buf = (char *) MALLOC(MAXBUF); if (!buf) return NULL; while (read_line(buf, MAXBUF)) { vec = alloc_strvec(buf); if (vec) { str = VECTOR_SLOT(vec, 0); if (!strcmp(str, EOB)) { free_strvec(vec); break; } if (VECTOR_SIZE(vec)) for (i = 0; i < VECTOR_SIZE(vec); i++) { str = VECTOR_SLOT(vec, i); dup = (char *) MALLOC(strlen(str) + 1); if (!dup) goto out; memcpy(dup, str, strlen(str)); if (!vector_alloc_slot(elements)) { free_strvec(vec); goto out1; } vector_set_slot(elements, dup); } free_strvec(vec); } memset(buf, 0, MAXBUF); } FREE(buf); return elements; out1: FREE(dup); out: FREE(buf); return NULL; }
static void quorum_handler(vector strvec) { virtual_server *vs = LIST_TAIL_DATA(check_data->vs); long tmp = atol (VECTOR_SLOT(strvec, 1)); if (tmp < 1) { log_message(LOG_ERR, "Condition not met: Quorum >= 1"); log_message(LOG_ERR, "Ignoring requested value %s, using 1 instead", (char *) VECTOR_SLOT(strvec, 1)); tmp = 1; } vs->quorum = tmp; }
int process_stream(vector keywords) { int i; int r = 0; struct keyword *keyword; char *str; char *buf; vector strvec; buf = MALLOC(MAXBUF); if (!buf) return 1; while (read_line(buf, MAXBUF)) { strvec = alloc_strvec(buf); memset(buf,0, MAXBUF); if (!strvec) continue; str = VECTOR_SLOT(strvec, 0); if (!strcmp(str, EOB) && kw_level > 0) { free_strvec(strvec); break; } for (i = 0; i < VECTOR_SIZE(keywords); i++) { keyword = VECTOR_SLOT(keywords, i); if (!strcmp(keyword->string, str)) { if (keyword->handler) r += (*keyword->handler) (strvec); if (keyword->sub) { kw_level++; r += process_stream(keyword->sub); kw_level--; } break; } } free_strvec(strvec); } FREE(buf); return r; }
static void hysteresis_handler(vector strvec) { virtual_server *vs = LIST_TAIL_DATA(check_data->vs); long tmp = atol (VECTOR_SLOT(strvec, 1)); if (tmp < 0 || tmp >= vs->quorum) { log_message(LOG_ERR, "Condition not met: 0 <= Hysteresis <= Quorum - 1"); log_message(LOG_ERR, "Ignoring requested value %s, using 0 instead", (char *) VECTOR_SLOT(strvec, 1)); log_message(LOG_ERR, "Hint: try defining hysteresis after quorum"); tmp = 0; } vs->hysteresis = tmp; }
struct keyword * find_keyword(vector keywords, vector v, char * name) { struct keyword *keyword; int i; int len; if (!name || !keywords) return NULL; if (!v) v = keywords; len = strlen(name); for (i = 0; i < VECTOR_SIZE(v); i++) { keyword = VECTOR_SLOT(v, i); if ((strlen(keyword->string) == len) && !strcmp(keyword->string, name)) return keyword; if (keyword->sub) { keyword = find_keyword(keywords, keyword->sub, name); if (keyword) return keyword; } } return NULL; }
static void lthreshold_handler(vector strvec) { virtual_server *vs = LIST_TAIL_DATA(check_data->vs); real_server *rs = LIST_TAIL_DATA(vs->rs); rs->l_threshold = atoi(VECTOR_SLOT(strvec, 1)); }
int alloc_value_block(vector strvec, void (*alloc_func) (vector)) { char *buf; char *str = NULL; vector vec = NULL; buf = (char *) MALLOC(MAXBUF); if (!buf) return 1; while (read_line(buf, MAXBUF)) { vec = alloc_strvec(buf); if (vec) { str = VECTOR_SLOT(vec, 0); if (!strcmp(str, EOB)) { free_strvec(vec); break; } if (VECTOR_SIZE(vec)) (*alloc_func) (vec); free_strvec(vec); } memset(buf, 0, MAXBUF); } FREE(buf); return 0; }
/* Virtual Servers handlers */ static void vsg_handler(vector strvec) { /* Fetch queued vsg */ alloc_vsg(VECTOR_SLOT(strvec, 1)); alloc_value_block(strvec, alloc_vsg_entry); }
static void proto_handler(vector strvec) { virtual_server *vs = LIST_TAIL_DATA(check_data->vs); char *str = VECTOR_SLOT(strvec, 1); vs->service_type = (!strcmp(str, "TCP")) ? IPPROTO_TCP : IPPROTO_UDP; }
static void weight_handler(vector strvec) { virtual_server *vs = LIST_TAIL_DATA(check_data->vs); real_server *rs = LIST_TAIL_DATA(vs->rs); rs->weight = atoi(VECTOR_SLOT(strvec, 1)); }
static void vrrp_vscript_fall_handler(vector strvec) { vrrp_script *vscript = LIST_TAIL_DATA(vrrp_data->vrrp_script); vscript->fall = atoi(VECTOR_SLOT(strvec, 1)); if (vscript->fall < 1) vscript->fall = 1; }
static void vrrp_int_handler(vector strvec) { vrrp_rt *vrrp = LIST_TAIL_DATA(vrrp_data->vrrp); char *name = VECTOR_SLOT(strvec, 1); vrrp->ifp = if_get_by_ifname(name); vrrp->xmit_ifp = vrrp->ifp; if (vrrp->vmac && !(vrrp->vmac & 2)) netlink_link_add_vmac(vrrp); }
static int verbosity_handler(vector strvec) { char * buff; buff = VECTOR_SLOT(strvec, 1); conf->verbosity = atoi(buff); return 0; }
static void vrrp_auth_type_handler(vector strvec) { vrrp_rt *vrrp = LIST_TAIL_DATA(vrrp_data->vrrp); char *str = VECTOR_SLOT(strvec, 1); if (!strcmp(str, "AH") && vrrp->family == AF_INET) vrrp->auth_type = VRRP_AUTH_AH; else if (!strcmp(str, "PASS") && vrrp->family == AF_INET) vrrp->auth_type = VRRP_AUTH_PASS; }
/* dump vector slots */ void vector_dump(vector v) { int i; printf("Vector Size : %d\n", v->allocated); for (i = 0; i < v->allocated; i++) if (v->slot[i] != NULL) printf(" Slot [%d]: %p\n", i, VECTOR_SLOT(v, i)); }
/* * default block handlers */ static int polling_interval_handler(vector strvec) { char * buff; buff = VECTOR_SLOT(strvec, 1); conf->checkint = atoi(buff); conf->max_checkint = MAX_CHECKINT(conf->checkint); return 0; }
static int set_int(vector strvec, void *ptr) { int *int_ptr = (int *)ptr; char * buff; buff = VECTOR_SLOT(strvec, 1); *int_ptr = atoi(buff); return 0; }
static void vrrp_debug_handler(vector strvec) { vrrp_rt *vrrp = LIST_TAIL_DATA(vrrp_data->vrrp); vrrp->debug = atoi(VECTOR_SLOT(strvec, 1)); if (VRRP_IS_BAD_DEBUG_INT(vrrp->debug)) { log_message(LOG_INFO, "VRRP Error : Debug interval not valid !\n"); log_message(LOG_INFO, " must be between 0-4\n"); vrrp->debug = 0; } }
static void vrrp_vrid_handler(vector strvec) { vrrp_rt *vrrp = LIST_TAIL_DATA(vrrp_data->vrrp); vrrp->vrid = atoi(VECTOR_SLOT(strvec, 1)); if (VRRP_IS_BAD_VID(vrrp->vrid)) { log_message(LOG_INFO, "VRRP Error : VRID not valid !\n"); log_message(LOG_INFO, " must be between 1 & 255. reconfigure !\n"); } else alloc_vrrp_bucket(vrrp); }
static void lbalgo_handler(vector strvec) { virtual_server *vs = LIST_TAIL_DATA(check_data->vs); char *str = VECTOR_SLOT(strvec, 1); int size = sizeof (vs->sched); int str_len = strlen(str); if (size > str_len) size = str_len; memcpy(vs->sched, str, size); }
static void pto_handler(vector strvec) { virtual_server *vs = LIST_TAIL_DATA(check_data->vs); char *str = VECTOR_SLOT(strvec, 1); int size = sizeof (vs->timeout_persistence); int str_len = strlen(str); if (size > str_len) size = str_len; memcpy(vs->timeout_persistence, str, size); }
/* dump vector slots */ void vector_dump(vector v) { unsigned int i; if (!v) return; log_print("vector size : %d\n", v->allocated); for (i = 0; i < v->allocated; i++) if (v->slot[i] != NULL) log_print(" Slot [%d]: %p\n", i, VECTOR_SLOT(v, i)); }
static void vrrp_auth_pass_handler(vector strvec) { vrrp_rt *vrrp = LIST_TAIL_DATA(vrrp_data->vrrp); char *str = VECTOR_SLOT(strvec, 1); int max_size = sizeof (vrrp->auth_data); int str_len = strlen(str); if (str_len > max_size) str_len = max_size; memset(vrrp->auth_data, 0, max_size); memcpy(vrrp->auth_data, str, str_len); }
void free_strvec(vector strvec) { unsigned int i; char *str; if (!strvec) return; for (i = 0; i < VECTOR_SIZE(strvec); i++) if ((str = VECTOR_SLOT(strvec, i)) != NULL) FREE(str); vector_free(strvec); }
static void lbkind_handler(vector strvec) { virtual_server *vs = LIST_TAIL_DATA(check_data->vs); char *str = VECTOR_SLOT(strvec, 1); if (!strcmp(str, "NAT")) vs->loadbalancing_kind = IP_VS_CONN_F_MASQ; else if (!strcmp(str, "DR")) vs->loadbalancing_kind = IP_VS_CONN_F_DROUTE; else if (!strcmp(str, "TUN")) vs->loadbalancing_kind = IP_VS_CONN_F_TUNNEL; else log_message(LOG_INFO, "PARSER : unknown [%s] routing method.", str); }
void alloc_track_script(list track_list, vector strvec) { vrrp_script *vsc = NULL; tracked_sc *tsc = NULL; int weight = 0; char *tracked = VECTOR_SLOT(strvec, 0); vsc = find_script_by_name(tracked); /* Ignoring if no interface found */ if (!vsc) { log_message(LOG_INFO, " %s no match, ignoring...", tracked); return; } /* default weight */ weight = vsc->weight; if (VECTOR_SIZE(strvec) >= 3 && !strcmp(VECTOR_SLOT(strvec, 1), "weight")) { weight = atoi(VECTOR_SLOT(strvec, 2)); if (weight < -254 || weight > 254) { weight = vsc->weight; log_message(LOG_INFO, " %s: weight must be between [-254..254]" " inclusive, ignoring...", tracked); } } tsc = (tracked_sc *) MALLOC(sizeof (tracked_sc)); tsc->scr = vsc; tsc->weight = weight; vsc->inuse++; list_add(track_list, tsc); }