/** * 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; }
static int getmsg(struct rtmsg *rtm, int msglen, struct rpfctl *rpf) { mifi_t vifi; struct uvif *v; struct rtattr *rta[RTA_MAX + 1]; if (rtm->rtm_type == RTN_LOCAL) { /* tracef(TRF_NETLINK, "NETLINK: local address"); */ log_msg(LOG_DEBUG, 0, "NETLINK: local address"); if ((rpf->iif = local_address(&rpf->source)) != MAXMIFS) { rpf->rpfneighbor = rpf->source; return TRUE; } return FALSE; } memset(&rpf->rpfneighbor, 0, sizeof(rpf->rpfneighbor)); /* initialized */ if (rtm->rtm_type != RTN_UNICAST) { /* tracef(TRF_NETLINK, "NETLINK: route type is %d", rtm->rtm_type); */ log_msg(LOG_DEBUG, 0, "NETLINK: route type is %d", rtm->rtm_type); return FALSE; } memset(rta, 0, sizeof(rta)); parse_rtattr(rta, RTA_MAX, RTM_RTA(rtm), msglen - sizeof(*rtm)); if (rta[RTA_OIF]) { int ifindex = *(int *) RTA_DATA(rta[RTA_OIF]); for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) { if (v->uv_ifindex == ifindex) break; } if (vifi >= numvifs) { log_msg(LOG_WARNING, 0, "NETLINK: ifindex=%d, but no vif", ifindex); return FALSE; } /* tracef(TRF_NETLINK, "NETLINK: vif %d, ifindex=%d", vifi, ifindex);*/ log_msg(LOG_DEBUG, 0, "NETLINK: vif %d, ifindex=%d", vifi, ifindex); } else { log_msg(LOG_WARNING, 0, "NETLINK: no interface"); return FALSE; } if (rta[RTA_GATEWAY]) { struct in6_addr gw; memcpy(&gw,RTA_DATA(rta[RTA_GATEWAY]),sizeof(gw)); /* __u32 gw = *(__u32 *) RTA_DATA(rta[RTA_GATEWAY]); */ /* tracef(TRF_NETLINK, "NETLINK: gateway is %s", inet6_fmt(gw)); */ log_msg(LOG_DEBUG, 0, "NETLINK: gateway is %s", inet6_fmt(&gw)); init_sin6(&rpf->rpfneighbor); rpf->rpfneighbor.sin6_addr = gw; rpf->rpfneighbor.sin6_scope_id = v->uv_ifindex; } else rpf->rpfneighbor = rpf->source; rpf->iif = vifi; 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; }
BOOST_FIXTURE_TEST_CASE( addresses_reported_when_connection_established, link_layer_only_connect_callback ) { respond_to( 37, valid_connection_request_pdu ); add_connection_event_respond( { 0, 1 } ); run(); const auto reported_addresses = only_connect_callback.reported_addresses; BOOST_CHECK_EQUAL( reported_addresses.remote_address(), bluetoe::link_layer::address( { 0x3c, 0x1c, 0x62, 0x92, 0xf0, 0x48 } ) ); BOOST_CHECK_EQUAL( reported_addresses.local_address(), bluetoe::link_layer::address( { 0x47, 0x11, 0x08, 0x15, 0x0f, 0xc0 } ) ); }
void inqp_stat_mngr::init( std::string host, int portnum, sock::protocol proto) { if (proto == sock::UNKNOWN_PROTO) { LOG_FATAL("unknown protocol value"); } else { sock::socket_address local_address(host, portnum, proto); char ifs = '|'; char irs = '\n'; char quote = '"'; m_reader = new sock::socket_reader( local_address, ifs, irs, quote, m_cols); m_reader->add_consumer( this ); } }
/* If route not found or if a local source or if a directly connected source, * but is not PIM router, or if the first hop router is not a PIM router, * then return NULL. */ pim_nbr_entry_t *find_pim_nbr(u_int32 source) { struct rpfctl rpfc; pim_nbr_entry_t *pim_nbr; u_int32 next_hop_router_addr; if (local_address(source) != NO_VIF) return (pim_nbr_entry_t *)NULL; k_req_incoming(source, &rpfc); if ((rpfc.rpfneighbor.s_addr == INADDR_ANY_N) || (rpfc.iif == NO_VIF)) return (pim_nbr_entry_t *)NULL; next_hop_router_addr = rpfc.rpfneighbor.s_addr; for (pim_nbr = uvifs[rpfc.iif].uv_pim_neighbors; pim_nbr != (pim_nbr_entry_t *)NULL; pim_nbr = pim_nbr->next) if (pim_nbr->address == next_hop_router_addr) return(pim_nbr); return (pim_nbr_entry_t *)NULL; }
/* * Process an incoming host membership query */ void accept_membership_query(u_int32 src, u_int32 dst __attribute__((unused)), u_int32 group, int tmo) { vifi_t vifi; struct uvif *v; /* Ignore my own membership query */ if (local_address(src) != NO_VIF) return; /* TODO: modify for DVMRP?? */ if ((vifi = find_vif_direct(src)) == NO_VIF) { IF_DEBUG(DEBUG_IGMP) logit(LOG_INFO, 0, "ignoring group membership query from non-adjacent host %s", inet_fmt(src, s1, sizeof(s1))); return; } v = &uvifs[vifi]; if ((tmo == 0 && !(v->uv_flags & VIFF_IGMPV1)) || (tmo != 0 && (v->uv_flags & VIFF_IGMPV1))) { int i; /* * Exponentially back-off warning rate */ i = ++v->uv_igmpv1_warn; while (i && !(i & 1)) i >>= 1; if (i == 1) { logit(LOG_WARNING, 0, "%s %s on vif %d, %s", tmo == 0 ? "Received IGMPv1 report from" : "Received IGMPv2 report from", inet_fmt(src, s1, sizeof(s1)), vifi, tmo == 0 ? "please configure vif for IGMPv1" : "but I am configured for IGMPv1"); } }
BOOST_FIXTURE_TEST_CASE( addresses_reported_when_connection_established, link_layer_only_connect_callback ) { respond_to( 37, { 0x85, 0x22, // header 0x3c, 0x1c, 0x62, 0x92, 0xf0, 0x48, // InitA: 48:f0:92:62:1c:3c (public) 0x47, 0x11, 0x08, 0x15, 0x0f, 0xc0, // AdvA: c0:0f:15:08:11:47 (random) 0x5a, 0xb3, 0x9a, 0xaf, // Access Address 0x08, 0x81, 0xf6, // CRC Init 0x03, // transmit window size 0x0b, 0x00, // window offset 0x18, 0x00, // interval (30ms) 0x00, 0x00, // slave latency 0x48, 0x00, // connection timeout (720ms) 0xff, 0xff, 0xff, 0xff, 0x1f, // used channel map 0xaa // hop increment and sleep clock accuracy (10 and 50ppm) } ); add_connection_event_respond( { 0, 1 } ); run(); const auto reported_addresses = only_connect_callback.reported_addresses; BOOST_CHECK_EQUAL( reported_addresses.remote_address(), bluetoe::link_layer::public_device_address( { 0x3c, 0x1c, 0x62, 0x92, 0xf0, 0x48 } ) ); BOOST_CHECK_EQUAL( reported_addresses.local_address(), bluetoe::link_layer::random_device_address( { 0x47, 0x11, 0x08, 0x15, 0x0f, 0xc0 } ) ); }
Address local_tag_address_low (const Register reg) { GUARANTEE(TaggedJavaStack, "Should not call this"); return local_address(reg, -12); }
Address local_address_low (const Register reg) { return local_address(reg, -BytesPerStackElement); }
Address local_address_high (const Register reg) { return local_address(reg); }
Address local_tag_address_low (int n) { GUARANTEE(TaggedJavaStack, "Should not call this"); return local_address(n, -12); }
Address local_address_low (int n) { return local_address(n, -BytesPerStackElement); }
Address local_address_high (int n) { return local_address(n, -0); }
/* * Set the iif, upstream router, preference and metric for the route * toward the source. Return TRUE is the route was found, othewise FALSE. * If srctype==PIM_IIF_SOURCE and if the source is directly connected * then the "upstream" is set to NULL. If srcentry==PIM_IIF_RP, then * "upstream" in case of directly connected "source" will be that "source" * (if it is also PIM router)., */ int set_incoming(srcentry_t *srcentry_ptr, int srctype) { struct rpfctl rpfc; u_int32 source = srcentry_ptr->address; u_int32 neighbor_addr; struct uvif *v; pim_nbr_entry_t *n; /* Preference will be 0 if directly connected */ srcentry_ptr->metric = 0; srcentry_ptr->preference = 0; if ((srcentry_ptr->incoming = local_address(source)) != NO_VIF) { /* The source is a local address */ /* TODO: set the upstream to myself? */ srcentry_ptr->upstream = (pim_nbr_entry_t *)NULL; return (TRUE); } if ((srcentry_ptr->incoming = find_vif_direct(source)) != NO_VIF) { /* The source is directly connected. Check whether we are * looking for real source or RP */ if (srctype == PIM_IIF_SOURCE) { srcentry_ptr->upstream = (pim_nbr_entry_t *)NULL; return (TRUE); } else { /* PIM_IIF_RP */ neighbor_addr = source; } } else { /* TODO: probably need to check the case if the iif is disabled */ /* Use the lastest resource: the kernel unicast routing table */ k_req_incoming(source, &rpfc); if ((rpfc.iif == NO_VIF) || rpfc.rpfneighbor.s_addr == INADDR_ANY_N) { /* couldn't find a route */ IF_DEBUG(DEBUG_PIM_MRT | DEBUG_RPF) logit(LOG_DEBUG, 0, "NO ROUTE found for %s", inet_fmt(source, s1, sizeof(s1))); return FALSE; } srcentry_ptr->incoming = rpfc.iif; neighbor_addr = rpfc.rpfneighbor.s_addr; /* set the preference for sources that aren't directly connected. */ v = &uvifs[srcentry_ptr->incoming]; srcentry_ptr->preference = v->uv_local_pref; srcentry_ptr->metric = v->uv_local_metric; } /* * The upstream router must be a (PIM router) neighbor, otherwise we * are in big trouble ;-) */ v = &uvifs[srcentry_ptr->incoming]; for (n = v->uv_pim_neighbors; n != NULL; n = n->next) { if (ntohl(neighbor_addr) < ntohl(n->address)) continue; if (neighbor_addr == n->address) { /* *The upstream router is found in the list of neighbors. * We are safe! */ srcentry_ptr->upstream = n; IF_DEBUG(DEBUG_RPF) logit(LOG_DEBUG, 0, "For src %s, iif is %d, next hop router is %s", inet_fmt(source, s1, sizeof(s1)), srcentry_ptr->incoming, inet_fmt(neighbor_addr, s2, sizeof(s2))); return TRUE; } else break; } /* TODO: control the number of messages! */ logit(LOG_INFO, 0, "For src %s, iif is %d, next hop router is %s: NOT A PIM ROUTER", inet_fmt(source, s1, sizeof(s1)), srcentry_ptr->incoming, inet_fmt(neighbor_addr, s2, sizeof(s2))); srcentry_ptr->upstream = (pim_nbr_entry_t *)NULL; return FALSE; }
Socket_Info local_socket_info(void) const { return Socket_Info(local_address(), local_port()); }
/** * parse_candidateRP - Parse candidate Rendez-Vous Point information. * @s: String token * * Syntax: * cand_rp [address | ifname] [priority <0-255>] [time <10-16383>] * * Returns: * %TRUE if the parsing was successful, o.w. %FALSE */ int parse_candidateRP(char *s) { u_int time = PIM_DEFAULT_CAND_RP_ADV_PERIOD; u_int priority = PIM_DEFAULT_CAND_RP_PRIORITY; char *w; uint32_t local = INADDR_ANY_N; cand_rp_flag = FALSE; my_cand_rp_adv_period = PIM_DEFAULT_CAND_RP_ADV_PERIOD; while (!EQUAL((w = next_word(&s)), "")) { if (EQUAL(w, "priority")) { if (EQUAL((w = next_word(&s)), "")) { WARN("Missing priority, defaulting to %u", w, PIM_DEFAULT_CAND_RP_PRIORITY); priority = PIM_DEFAULT_CAND_RP_PRIORITY; continue; } if (sscanf(w, "%u", &priority) != 1) { WARN("Invalid priority %s, defaulting to %u", w, PIM_DEFAULT_CAND_RP_PRIORITY); priority = PIM_DEFAULT_CAND_RP_PRIORITY; } if (priority > PIM_MAX_CAND_RP_PRIORITY) { WARN("Too high Cand-RP priority %u, defaulting to %d", priority, PIM_MAX_CAND_RP_PRIORITY); priority = PIM_MAX_CAND_RP_PRIORITY; } continue; } if (EQUAL(w, "time")) { if (EQUAL((w = next_word(&s)), "")) { WARN("Missing Cand-RP announce interval, defaulting to %u", PIM_DEFAULT_CAND_RP_ADV_PERIOD); time = PIM_DEFAULT_CAND_RP_ADV_PERIOD; continue; } if (sscanf(w, "%u", &time) != 1) { WARN("Invalid Cand-RP announce interval, defaulting to %u", PIM_DEFAULT_CAND_RP_ADV_PERIOD); time = PIM_DEFAULT_CAND_RP_ADV_PERIOD; continue; } if (time < PIM_MIN_CAND_RP_ADV_PERIOD) time = PIM_MIN_CAND_RP_ADV_PERIOD; if (time > PIM_MAX_CAND_RP_ADV_PERIOD) time = PIM_MAX_CAND_RP_ADV_PERIOD; my_cand_rp_adv_period = time; continue; } /* Cand-RP 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-RP address '%s', defaulting to %s", w, inet_fmt(local, s1, sizeof(s1))); } else if (local_address(local) == NO_VIF) { local = max_local_address(); WARN("Cand-RP 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_cand_rp_address = local; my_cand_rp_priority = priority; my_cand_rp_adv_period = time; cand_rp_flag = TRUE; logit(LOG_INFO, 0, "Local Cand-RP address %s, priority %u, interval %u sec", inet_fmt(local, s1, sizeof(s1)), priority, time); return TRUE; }
std::string str_local_address(void) const { return local_address().to_string(); }
/* * function name: parse_candidateRP * input: char *s * output: int (TRUE if the parsing was successful, o.w. FALSE) * operation: parses the candidate RP information. * The general form is: * 'cand_rp <local-addr> [priority <number>] [time <number>]'. */ int parse_candidateRP(char *s) { u_int time = PIM_DEFAULT_CAND_RP_ADV_PERIOD; u_int priority = PIM_DEFAULT_CAND_RP_PRIORITY; char *w; u_int32 local = INADDR_ANY_N; cand_rp_flag = FALSE; my_cand_rp_adv_period = PIM_DEFAULT_CAND_RP_ADV_PERIOD; 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 highest)", PIM_DEFAULT_CAND_RP_PRIORITY); priority = PIM_DEFAULT_CAND_RP_PRIORITY; continue; } if (sscanf(w, "%u", &priority) != 1) { logit(LOG_WARNING, 0, "invalid priority %s; set to default %u (0 is highest)", PIM_DEFAULT_CAND_RP_PRIORITY); priority = PIM_DEFAULT_CAND_RP_PRIORITY; } continue; } if (EQUAL(w, "time")) { if (EQUAL((w = next_word(&s)), "")) { logit(LOG_WARNING, 0, "Missing cand_rp_adv_period value; set to default %u", PIM_DEFAULT_CAND_RP_ADV_PERIOD); time = PIM_DEFAULT_CAND_RP_ADV_PERIOD; continue; } if (sscanf(w, "%u", &time) != 1) { logit(LOG_WARNING, 0, "Invalid cand_rp_adv_period value; set to default %u", PIM_DEFAULT_CAND_RP_ADV_PERIOD); time = PIM_DEFAULT_CAND_RP_ADV_PERIOD; continue; } if (time > (my_cand_rp_adv_period = ~0)) time = my_cand_rp_adv_period; /* TODO: XXX: cannot be shorter than 10 seconds (not in the spec)*/ if (time < 10) time = 10; #if 0 if (time > PIM_DEFAULT_CAND_RP_ADV_PERIOD) time = PIM_DEFAULT_CAND_RP_ADV_PERIOD; #endif /* 0 */ my_cand_rp_adv_period = time; continue; } /* Cand-RP address */ local = inet_parse(w, 4); if (!inet_valid_host(local)) { local = max_local_address(); logit(LOG_WARNING, 0, "Invalid Cand-RP address provided '%s' in %s. Will use the largest enabled local address.", w, configfilename); } else if (local_address(local) == NO_VIF) { local = max_local_address(); logit(LOG_WARNING, 0, "Cand-RP 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_cand_rp_address = local; my_cand_rp_priority = priority; my_cand_rp_adv_period = time; cand_rp_flag = TRUE; logit(LOG_INFO, 0, "Local Cand-RP address is %s", inet_fmt(local, s1, sizeof(s1))); logit(LOG_INFO, 0, "Local Cand-RP priority is %u", priority); logit(LOG_INFO, 0, "Local Cand-RP advertisement period is %u sec.", time); return TRUE; }