Exemplo n.º 1
0
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);
}
Exemplo n.º 2
0
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);
}
Exemplo n.º 3
0
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);
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
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;
}
Exemplo n.º 6
0
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;
}
Exemplo n.º 7
0
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;
}
Exemplo n.º 8
0
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;
}
Exemplo n.º 9
0
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;
}
Exemplo n.º 10
0
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));
}
Exemplo n.º 11
0
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;
}
Exemplo n.º 12
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);
}
Exemplo n.º 13
0
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;
}
Exemplo n.º 14
0
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));
}
Exemplo n.º 15
0
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;
}
Exemplo n.º 16
0
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);
}
Exemplo n.º 17
0
static int
verbosity_handler(vector strvec)
{
	char * buff;

	buff = VECTOR_SLOT(strvec, 1);
	conf->verbosity = atoi(buff);

	return 0;
}
Exemplo n.º 18
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;
}
Exemplo n.º 19
0
/* 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));
}
Exemplo n.º 20
0
/*
 * 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;
}
Exemplo n.º 21
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;
}
Exemplo n.º 22
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;
	}
}
Exemplo n.º 23
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);
}
Exemplo n.º 24
0
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);
}
Exemplo n.º 25
0
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);
}
Exemplo n.º 26
0
/* 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));
}
Exemplo n.º 27
0
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);
}
Exemplo n.º 28
0
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);
}
Exemplo n.º 29
0
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);
}
Exemplo n.º 30
0
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);
}