Пример #1
0
void config_vifs_from_file(void)
{
    FILE *f;
    char linebuf[LINE_BUFSIZ];
    char *w, *s;
    struct ifconf ifc;
    int option;
    char ifbuf[BUFSIZ];
    u_int8 *data_ptr;
    int error_flag;

    error_flag = FALSE;
    lineno = 0;

    if ((f = fopen(config_file, "r")) == NULL) {
	if (errno != ENOENT)
	    logit(LOG_WARNING, errno, "Cannot open %s", config_file);
	return;
    }

    /* TODO: HARDCODING!!! */
    cand_rp_adv_message.buffer = calloc(1, 4 + sizeof(pim_encod_uni_addr_t) +
					255 * sizeof(pim_encod_grp_addr_t));
    if (!cand_rp_adv_message.buffer)
	logit(LOG_ERR, errno, "Ran out of memory in config_vifs_from_file()");

    cand_rp_adv_message.prefix_cnt_ptr  = cand_rp_adv_message.buffer;
    /* By default, if no group_prefix configured, then prefix_cnt == 0
     * implies group_prefix = 224.0.0.0 and masklen = 4.
     */
    *cand_rp_adv_message.prefix_cnt_ptr = 0;
    cand_rp_adv_message.insert_data_ptr = cand_rp_adv_message.buffer;
    /* TODO: XXX: HARDCODING!!! */
    cand_rp_adv_message.insert_data_ptr += (4 + 6);

    ifc.ifc_buf = ifbuf;
    ifc.ifc_len = sizeof(ifbuf);
    if (ioctl(udp_socket, SIOCGIFCONF, (char *)&ifc) < 0)
	logit(LOG_ERR, errno, "Failed querying kernel network interfaces");

    while (fgets(linebuf, sizeof(linebuf), f) != NULL) {
	if (strlen(linebuf) >= (LINE_BUFSIZ - 1)) {
	    WARN("Line length must be shorter than %d", LINE_BUFSIZ);
	    error_flag = TRUE;
	}
	lineno++;

	s = linebuf;
	w = next_word(&s);
	option = parse_option(w);

	switch (option) {
	    case CONF_EMPTY:
		continue;
		break;

	    case CONF_PHYINT:
		parse_phyint(s);
		break;

	    case CONF_CANDIDATE_RP:
		parse_candidateRP(s);
		break;

	    case CONF_RP_ADDRESS:
		parse_rp_address(s);
		break;

	    case CONF_GROUP_PREFIX:
		parse_group_prefix(s);
		break;

	    case CONF_BOOTSTRAP_RP:
		parseBSR(s);
		break;

	    case CONF_COMPAT_THRESHOLD:
		parse_compat_threshold(s);
		break;

	    case CONF_SPT_THRESHOLD:
		parse_spt_threshold(s);
		break;

	    case CONF_DEFAULT_SOURCE_METRIC:
		parse_default_source_metric(s);
		break;

	    case CONF_DEFAULT_SOURCE_PREFERENCE:
		parse_default_source_preference(s);
		break;

	    case CONF_DEFAULT_IGMP_QUERY_INTERVAL:
		parse_default_igmp_query_interval(s);
		break;

	    case CONF_DEFAULT_IGMP_QUERIER_TIMEOUT:
		parse_default_igmp_querier_timeout(s);
		break;

	    default:
		logit(LOG_WARNING, 0, "%s:%u - Unknown command '%s'", config_file, lineno, w);
		error_flag = TRUE;
	}
    }

    if (error_flag)
	logit(LOG_ERR, 0, "%s:%u - Syntax error", config_file, lineno);

    cand_rp_adv_message.message_size = cand_rp_adv_message.insert_data_ptr - cand_rp_adv_message.buffer;
    if (cand_rp_flag != FALSE) {
	/* Prepare the RP info */
	my_cand_rp_holdtime = 2.5 * my_cand_rp_adv_period;

	/* TODO: HARDCODING! */
	data_ptr = cand_rp_adv_message.buffer + 1;
	PUT_BYTE(my_cand_rp_priority, data_ptr);
	PUT_HOSTSHORT(my_cand_rp_holdtime, data_ptr);
	PUT_EUADDR(my_cand_rp_address, data_ptr);
    }

    /* If no IGMP querier timeout was set, calculate from query interval */
    if (!default_igmp_querier_timeout)
	default_igmp_querier_timeout = QUERIER_TIMEOUT(default_igmp_query_interval);

    IF_DEBUG(DEBUG_IGMP) {
	logit(LOG_INFO, 0, "IGMP query interval  : %u sec", default_igmp_query_interval);
	logit(LOG_INFO, 0, "IGMP querier timeout : %u sec", default_igmp_querier_timeout);
    }

    fclose(f);
}
Пример #2
0
void config_vifs_from_file(void)
{
    FILE *f;
    char linebuf[LINE_BUFSIZ];
    char *w, *s;
    struct ifconf ifc;
    int option;
    char ifbuf[BUFSIZ];
    u_int8 *data_ptr;
    int error_flag;
    int line_num;

    error_flag = FALSE;
    line_num = 0;

    if ((f = fopen(configfilename, "r")) == NULL) {
        if (errno != ENOENT) logit(LOG_WARNING, errno, "can't open %s",
                                       configfilename);
        return;
    }

    /* TODO: HARDCODING!!! */
    cand_rp_adv_message.buffer =
        (u_int8 *)malloc(4 + sizeof(pim_encod_uni_addr_t)
                         + 255*sizeof(pim_encod_grp_addr_t));
    cand_rp_adv_message.prefix_cnt_ptr  = cand_rp_adv_message.buffer;
    /* By default, if no group_prefix configured, then prefix_cnt == 0
     * implies group_prefix = 224.0.0.0 and masklen = 4.
     */
    *cand_rp_adv_message.prefix_cnt_ptr = 0;
    cand_rp_adv_message.insert_data_ptr = cand_rp_adv_message.buffer;
    /* TODO: XXX: HARDCODING!!! */
    cand_rp_adv_message.insert_data_ptr += (4 + 6);

    ifc.ifc_buf = ifbuf;
    ifc.ifc_len = sizeof(ifbuf);
    if (ioctl(udp_socket, SIOCGIFCONF, (char *)&ifc) < 0)
        logit(LOG_ERR, errno, "ioctl SIOCGIFCONF");

    while (fgets(linebuf, sizeof(linebuf), f) != NULL) {
        if (strlen(linebuf) >= (LINE_BUFSIZ - 1)) {
            logit(LOG_WARNING, 0,
                  "line length must be shorter than %d in %s:%d",
                  LINE_BUFSIZ, configfilename, line_num);
            error_flag = TRUE;
        } else {
            line_num++;
        }

        s = linebuf;
        w = next_word(&s);
        option = wordToOption(w);

        switch(option) {
        case EMPTY:
            continue;
            break;
        case PHYINT:
            parse_phyint(s);
            break;
        case CANDIDATE_RP:
            parse_candidateRP(s);
            break;
        case RP_ADDRESS:
            parse_rp_address(s);
            break;
        case GROUP_PREFIX:
            parse_group_prefix(s);
            break;
        case BOOTSTRAP_RP:
            parseBSR(s);
            break;
        case REG_THRESHOLD:
            parse_reg_threshold(s);
            break;
        case DATA_THRESHOLD:
            parse_data_threshold(s);
            break;
        case DEFAULT_SOURCE_METRIC:
            parse_default_source_metric(s);
            break;
        case DEFAULT_SOURCE_PREFERENCE:
            parse_default_source_preference(s);
            break;
        default:
            logit(LOG_WARNING, 0, "unknown command '%s' in %s:%d",
                  w, configfilename, line_num);
            error_flag = TRUE;
        }
    }
    if (error_flag) {
        /*
         * XXX: let's be pedantic even about warnings. If this is a problem,
         * comment out this logit(LOG_ERR).
         */
        logit(LOG_ERR, 0, "Syntax Error in %s", configfilename);
    }

    cand_rp_adv_message.message_size = cand_rp_adv_message.insert_data_ptr
                                       - cand_rp_adv_message.buffer;
    if (cand_rp_flag != FALSE) {
        /* Prepare the RP info */
        my_cand_rp_holdtime = 2.5 * my_cand_rp_adv_period;
        /* TODO: HARDCODING! */
        data_ptr = cand_rp_adv_message.buffer + 1;
        PUT_BYTE(my_cand_rp_priority, data_ptr);
        PUT_HOSTSHORT(my_cand_rp_holdtime, data_ptr);
        PUT_EUADDR(my_cand_rp_address, data_ptr);
    }

    fclose(f);
}