/** * parseBSR - Parse the candidate BSR configured information. * @s: String token * * Syntax: * cand_bootstrap_router [address | ifname] [priority <0-255>] */ int parseBSR(char *s) { char *w; uint32_t local = INADDR_ANY_N; uint32_t priority = PIM_DEFAULT_BSR_PRIORITY; cand_bsr_flag = FALSE; while (!EQUAL((w = next_word(&s)), "")) { if (EQUAL(w, "priority")) { if (EQUAL((w = next_word(&s)), "")) { WARN("Missing Cand-BSR priority, defaulting to %u", PIM_DEFAULT_BSR_PRIORITY); priority = PIM_DEFAULT_BSR_PRIORITY; continue; } if (sscanf(w, "%u", &priority) != 1) { WARN("Invalid Cand-BSR priority %s, defaulting to %u", PIM_DEFAULT_BSR_PRIORITY); priority = PIM_DEFAULT_BSR_PRIORITY; continue; } if (priority > PIM_MAX_CAND_BSR_PRIORITY) { WARN("Too high Cand-BSR priority %u, defaulting to %d", priority, PIM_MAX_CAND_BSR_PRIORITY); priority = PIM_MAX_CAND_BSR_PRIORITY; } my_bsr_priority = (u_int8)priority; continue; } /* Cand-BSR interface or address */ local = ifname2addr(w); if (!local) local = inet_parse(w, 4); if (!inet_valid_host(local)) { local = max_local_address(); WARN("Invalid Cand-BSR address '%s', defaulting to %s", w, inet_fmt(local, s1, sizeof(s1))); continue; } if (local_address(local) == NO_VIF) { local = max_local_address(); WARN("Cand-BSR address '%s' is not local, defaulting to %s", w, inet_fmt(local, s1, sizeof(s1))); } } if (local == INADDR_ANY_N) { /* If address not provided, use the max. local */ local = max_local_address(); } my_bsr_address = local; my_bsr_priority = priority; MASKLEN_TO_MASK(RP_DEFAULT_IPV4_HASHMASKLEN, my_bsr_hash_mask); cand_bsr_flag = TRUE; logit(LOG_INFO, 0, "Local Cand-BSR address %s, priority %u", inet_fmt(local, s1, sizeof(s1)), priority); return TRUE; }
/* * function name: parseBSR * input: char *s * output: int * operation: parse the candidate BSR configured information. * General form: * 'cand_bootstrap_router <local-addr> [priority <number>]'. */ int parseBSR(char *s) { char *w; u_int32 local = INADDR_ANY_N; u_int32 priority = PIM_DEFAULT_BSR_PRIORITY; cand_bsr_flag = FALSE; while (!EQUAL((w = next_word(&s)), "")) { if (EQUAL(w, "priority")) { if (EQUAL((w = next_word(&s)), "")) { logit(LOG_WARNING, 0, "Missing priority; set to default %u (0 is lowest)\n", PIM_DEFAULT_BSR_PRIORITY); priority = PIM_DEFAULT_BSR_PRIORITY; continue; } if (sscanf(w, "%u", &priority) != 1) { logit(LOG_WARNING, 0, "invalid priority %s; set to default %u (0 is lowest)", PIM_DEFAULT_BSR_PRIORITY); priority = PIM_DEFAULT_BSR_PRIORITY; continue; } if (priority > (my_bsr_priority = ~0)) priority = my_bsr_priority; my_bsr_priority = (u_int8)priority; continue; } /* BSR address */ local = inet_parse(w, 4); if (!inet_valid_host(local)) { local = max_local_address(); logit(LOG_WARNING, 0, "Invalid BSR address provided '%s' in %s. Will use the largest enabled local address.", w, configfilename); continue; } if (local_address(local) == NO_VIF) { local = max_local_address(); logit(LOG_WARNING, 0, "Cand-BSR address is not local '%s' in %s. Will use the largest enabled local address.", w, configfilename); } } /* while not empty */ if (local == INADDR_ANY_N) /* If address not provided, use the max. local */ local = max_local_address(); my_bsr_address = local; my_bsr_priority = priority; MASKLEN_TO_MASK(RP_DEFAULT_IPV4_HASHMASKLEN, my_bsr_hash_mask); cand_bsr_flag = TRUE; logit(LOG_INFO, 0, "Local Cand-BSR address is %s", inet_fmt(local, s1, sizeof(s1))); logit(LOG_INFO, 0, "Local Cand-BSR priority is %u", priority); return TRUE; }