Ejemplo n.º 1
0
/* ------------------------------------------------------------ */
int ipvsfuncs_fprintf_ipvs(FILE *f) {
	int i, j;

	struct ip_vs_service_entry *se;
	struct ip_vs_dest_entry *de;
	struct ip_vs_get_services *vs = ipvs_get_services();
	
	for (i = 0; i < vs->num_services; i++) {
		se = &vs->entrytable[i];
		struct ip_vs_get_dests *vd = ipvs_get_dests(se);
        if (!vd)
            continue;
		fprintf(f, " svc dest [%d], ip=%x, port=%d, fwmark=%d, proto=%d\n", 
				i, ntohl(se->addr.ip), ntohs(se->port), se->fwmark, se->protocol);
		for (j = 0; j < se->num_dests; j++) {
			de = &vd->entrytable[j];
			fprintf(f, "  dest [%d], ip=%x, port=%d, weight=%d\n", 
					j, ntohl(de->addr.ip), ntohs(de->port), de->weight);
		}
		free(vd);		
	}
	free(vs);

	return 0;
}
Ejemplo n.º 2
0
/* ------------------------------------------------------------ */
int ipvsfuncs_fprintf_services(FILE *f) {
	int i;

	struct ip_vs_service_entry *se;
	struct ip_vs_get_services *vs = ipvs_get_services();
	for (i = 0; i < vs->num_services; i++) {
		se = &vs->entrytable[i];
		fprintf(f, "service [%d], ip=%x, port=%d\n", 
				i, ntohl(se->addr.ip), ntohs(se->port));
	}
	free(vs);
	
	return 0;
}
Ejemplo n.º 3
0
/* args:
   - managed_svc - pointer to svc table
   - is_in_ipvs  - function stores status is a virtual defined in ipvs 
                   (status is saved here only if (is_in_ipvs != NULL)
*/
int ipvsfuncs_del_unmanaged_services(ipvs_service_t **managed_svc, gint *is_in_ipvs) {
	int i, idx, found;

	ipvs_service_t **m;
	struct ip_vs_service_entry *se;
	struct ip_vs_get_services *vs;

    ipvsfuncs_reinitialize(); //if someone clears IPVS ipvs_get_services returns vs table which contains crap inside
    vs = ipvs_get_services();
    if (!vs) 
        return -1;

    LOGDETAIL("vs = %x, vs->num_services = %d", vs, vs->num_services);

	for (i = 0; i < vs->num_services; i++) {
		se = &vs->entrytable[i];
        LOGDETAIL("del_umanaged_services check: [%d], ip=%x, port=%d, protocol=%d, fwmark=%d", 
				i, ntohl(se->addr.ip), ntohs(se->port), se->protocol, se->fwmark);
		m = managed_svc;
		found = 0;
		idx = 0;
		while (*m) {
            LOGDETAIL(" * compare to [%x:%d proto=%d fwmark=%d]",
                      ntohl((*m)->addr.ip), ntohs((*m)->port), 
                      (*m)->protocol, (*m)->fwmark);
			if ((*m)->addr.ip == se->addr.ip && 
				(*m)->port == se->port &&
				(*m)->protocol == se->protocol &&
				(*m)->fwmark == se->fwmark) {
				found = 1;
				if (is_in_ipvs)
					is_in_ipvs[idx] = 1;
				break;
			}
			m++;
			idx++;
		}

		if (!found) {
            LOGDEBUG("Delete unmanaged virtual: ip=%s, port=%d, protocol=%d, fwmark=%d", 
                      INETTXTADDR(se->addr.ip), ntohs(se->port), se->protocol, se->fwmark);
			ipvsfuncs_del_service_entry((struct ip_vs_service_entry *)se);
        }
	}
	free(vs);

//    ipvsfuncs_fprintf_ipvs(stderr);

	return 0;
}
Ejemplo n.º 4
0
static int cipvs_read (void)
{
	struct ip_vs_get_services *services = NULL;
	size_t i;

	if (sockfd < 0)
		return (-1);

	if (NULL == (services = ipvs_get_services ()))
		return -1;

	for (i = 0; i < services->num_services; ++i)
		cipvs_submit_service (&services->entrytable[i]);

	free (services);
	return 0;
} /* cipvs_read */