/** * parse_group_prefix - Parse group_prefix configured information. * @s: String token * Syntax: * group_prefix <group-addr>[/<masklen>] * <group-addr> [masklen <masklen>] * * Returns: * %TRUE if the parsing was successful, o.w. %FALSE */ int parse_group_prefix(char *s) { char *w; uint32_t group_addr; uint32_t masklen = PIM_GROUP_PREFIX_DEFAULT_MASKLEN; w = next_word(&s); if (EQUAL(w, "")) { WARN("Missing group_prefix address"); return FALSE; } parse_prefix_len (w, &masklen); group_addr = inet_parse(w, 4); if (!IN_MULTICAST(ntohl(group_addr))) { WARN("Group address '%s' is not a valid multicast address", inet_fmt(group_addr, s1, sizeof(s1))); return FALSE; } /* Was if (!(~(*cand_rp_adv_message.prefix_cnt_ptr))) which Arm GCC 4.4.2 dislikes: * --> "config.c:693: warning: promoted ~unsigned is always non-zero" * The prefix_cnt_ptr is a u_int8 so it seems this check was to prevent overruns. * I've changed the check to see if we've already read 255 entries, if so the cnt * is maximized and we need to tell the user. --Joachim Nilsson 2010-01-16 */ if (*cand_rp_adv_message.prefix_cnt_ptr == 255) { WARN("Too many multicast groups configured!"); return FALSE; } if (EQUAL((w = next_word(&s)), "masklen")) { w = next_word(&s); if (!sscanf(w, "%u", &masklen)) masklen = PIM_GROUP_PREFIX_DEFAULT_MASKLEN; } validate_prefix_len(&masklen); PUT_EGADDR(group_addr, (u_int8)masklen, 0, cand_rp_adv_message.insert_data_ptr); (*cand_rp_adv_message.prefix_cnt_ptr)++; logit(LOG_INFO, 0, "Adding Cand-RP group prefix %s/%d", inet_fmt(group_addr, s1, sizeof(s1)), masklen); return TRUE; }
/** * parse_rp_address - Parse rp_address config option. * @s: String token. * * This is an extension to the original pimd to add pimd.conf support for static * Rendez-Vous Point addresses. * * The function has been extended by [email protected], of Lintrack, to allow specifying * multicast group addresses as well. * * Syntax: * rp_address <ADDRESS> [<GROUP>[</LENGTH> masklen <LENGTH>] * * Returns: * When parsing @s is successful this function returns %TRUE, otherwise %FALSE. */ int parse_rp_address(char *s) { char *w; uint32_t local = 0xffffff; uint32_t group_addr = htonl(INADDR_UNSPEC_GROUP); uint32_t masklen = PIM_GROUP_PREFIX_DEFAULT_MASKLEN; u_int dummy; struct rp_hold *rph; /* next is RP addr */ w = next_word(&s); if (EQUAL(w, "")) { logit(LOG_WARNING, 0, "Missing rp_address argument"); return FALSE; } local = inet_parse(w, 4); if (local == 0xffffff) { WARN("Invalid rp_address %s", w); return FALSE; } /* next is group addr if exist */ w = next_word(&s); if (!EQUAL(w, "")) { parse_prefix_len (w, &masklen); group_addr = inet_parse(w, 4); if (!IN_MULTICAST(ntohl(group_addr))) { WARN("%s is not a valid multicast address", inet_fmt(group_addr, s1, sizeof(s1))); return FALSE; } /* next is prefix or priority if exist */ while (!EQUAL((w = next_word(&s)), "")) { if (EQUAL(w, "masklen")) { w = next_word(&s); if (!sscanf(w, "%u", &masklen)) { WARN("Invalid masklen %s. Defaulting to %d)", w, PIM_GROUP_PREFIX_DEFAULT_MASKLEN); masklen = PIM_GROUP_PREFIX_DEFAULT_MASKLEN; } } /* Unused, but keeping for backwards compatibility for people who * may still have this option in their pimd.conf * The priority of a static RP is hardcoded to always be 1, see Juniper's * configuration or similar sources for reference. */ if (EQUAL(w, "priority")) { w = next_word(&s); sscanf(w, "%u", &dummy); WARN("The priority of static RP's is, as of pimd 2.2.0, always 1."); } } } else { group_addr = htonl(INADDR_UNSPEC_GROUP); masklen = PIM_GROUP_PREFIX_MIN_MASKLEN; } validate_prefix_len(&masklen); rph = calloc(1, sizeof(*rph)); if (!rph) { logit(LOG_WARNING, 0, "Out of memory when parsing rp-address %s", inet_fmt(local, s1, sizeof(s1))); return FALSE; } rph->address = local; rph->group = group_addr; VAL_TO_MASK(rph->mask, masklen); /* attach at the beginning */ rph->next = g_rp_hold; g_rp_hold = rph; logit(LOG_INFO, 0, "Local static RP: %s, group %s/%d", inet_fmt(local, s1, sizeof(s1)), inet_fmt(group_addr, s2, sizeof(s2)), masklen); return TRUE; }
/** * parse_rp_address - Parse rp_address config option. * @s: String token. * * This is an extension to the original pimd to add pimd.conf support for static * Rendez-Vous Point addresses. * * The function has been extended by [email protected], of Lintrack, to allow specifying * multicast group addresses as well. * * Syntax: * rp_address <rp-address> [<group-addr>[/masklen>] [priority <number>]] * [<group-addr> [masklen <masklen>] [priority <number>]] * * Returns: * When parsing @s is successful this function returns %TRUE, otherwise %FALSE. */ int parse_rp_address(char *s) { char *w; uint32_t local = 0xffffff; uint32_t group_addr = htonl(INADDR_UNSPEC_GROUP); uint32_t masklen = PIM_GROUP_PREFIX_DEFAULT_MASKLEN; u_int priority = PIM_DEFAULT_CAND_RP_PRIORITY; struct rp_hold *rph; /* next is RP addr */ w = next_word(&s); if (EQUAL(w, "")) { logit(LOG_WARNING, 0, "Missing rp_address argument"); return FALSE; } local = inet_parse(w, 4); if (local == 0xffffff) { WARN("Invalid rp_address %s", w); return FALSE; } /* next is group addr if exist */ w = next_word(&s); if (!EQUAL(w, "")) { parse_prefix_len (w, &masklen); group_addr = inet_parse(w, 4); if (!IN_MULTICAST(ntohl(group_addr))) { WARN("%s is not a valid multicast address", inet_fmt(group_addr, s1, sizeof(s1))); return FALSE; } /* next is prefix or priority if exist */ while (!EQUAL((w = next_word(&s)), "")) { if (EQUAL(w, "masklen")) { w = next_word(&s); if (!sscanf(w, "%u", &masklen)) { WARN("Invalid masklen %s. Defaulting to %d)", w, PIM_GROUP_PREFIX_DEFAULT_MASKLEN); masklen = PIM_GROUP_PREFIX_DEFAULT_MASKLEN; } } if (EQUAL(w, "priority")) { w = next_word(&s); if (sscanf(w, "%u", &priority) == 1) { if (priority > PIM_MAX_CAND_RP_PRIORITY) { WARN("Too large priority %s. Defaulting to %d", w, PIM_MAX_CAND_RP_PRIORITY); priority = PIM_MAX_CAND_RP_PRIORITY; } } else { WARN("Invalid priority %s. Defaulting to %d", w, PIM_DEFAULT_CAND_RP_PRIORITY); priority = PIM_DEFAULT_CAND_RP_PRIORITY; } } } } else { group_addr = htonl(INADDR_UNSPEC_GROUP); masklen = PIM_GROUP_PREFIX_MIN_MASKLEN; priority = 1; } validate_prefix_len (&masklen); rph = calloc(1, sizeof(*rph)); if (!rph) { logit(LOG_WARNING, 0, "Ran out of memory in parse_rp_address()"); return FALSE; } rph->address = local; rph->group = group_addr; VAL_TO_MASK(rph->mask, masklen); rph->priority = priority; /* attach at the beginning */ rph->next = g_rp_hold; g_rp_hold = rph; logit(LOG_INFO, 0, "Added static RP: %s, group %s/%d, priority %d", inet_fmt(local, s1, sizeof(s1)), inet_fmt(group_addr, s2, sizeof(s2)), masklen, priority); return TRUE; }