?? mld6igmp_vif.cc
字號:
// // Reset the primary address if it is not valid anymore. // if (Vif::find_address(primary_addr()) == NULL) { if (primary_addr() == querier_addr()) { // Reset the querier address set_querier_addr(IPvX::ZERO(family())); set_i_am_querier(false); i_was_querier = true; } set_primary_addr(IPvX::ZERO(family())); } list<VifAddr>::const_iterator iter; for (iter = addr_list().begin(); iter != addr_list().end(); ++iter) { const VifAddr& vif_addr = *iter; const IPvX& addr = vif_addr.addr(); if (! addr.is_unicast()) continue; if (addr.is_linklocal_unicast()) { if (primary_a.is_zero()) primary_a = addr; continue; } // // XXX: assume that everything else can be a domain-wide reachable // address. if (domain_wide_a.is_zero()) domain_wide_a = addr; } // // XXX: In case of IPv6 if there is no link-local address we may try // to use the the domain-wide address as a primary address, // but the MLD spec is clear that the MLD messages are to be originated // from a link-local address. // Hence, only in case of IPv4 we assign the domain-wide address // to the primary address. // if (is_ipv4()) { if (primary_a.is_zero()) primary_a = domain_wide_a; } // // Check that the interface has a primary address. // if (primary_addr().is_zero() && primary_a.is_zero()) { error_msg = "invalid primary address"; return (XORP_ERROR); } if (primary_addr().is_zero()) set_primary_addr(primary_a); if (i_was_querier) { // Assume again that I am the MLD6IGMP Querier set_querier_addr(primary_addr()); set_i_am_querier(true); } return (XORP_OK);}/** * Mld6igmpVif::add_protocol: * @module_id: The #xorp_module_id of the protocol to add. * @module_instance_name: The module instance name of the protocol to add. * * Add a protocol to the list of entries that would be notified if there * is membership change on this interface. * * Return value: %XORP_OK on success, otherwise %XORP_ERROR. **/intMld6igmpVif::add_protocol(xorp_module_id module_id, const string& module_instance_name){ if (find(_notify_routing_protocols.begin(), _notify_routing_protocols.end(), pair<xorp_module_id, string>(module_id, module_instance_name)) != _notify_routing_protocols.end()) { return (XORP_ERROR); // Already added } _notify_routing_protocols.push_back( pair<xorp_module_id, string>(module_id, module_instance_name)); return (XORP_OK);}/** * Mld6igmpVif::delete_protocol: * @module_id: The #xorp_module_id of the protocol to delete. * @module_instance_name: The module instance name of the protocol to delete. * * Delete a protocol from the list of entries that would be notified if there * is membership change on this interface. * * Return value: %XORP_OK on success, otherwise %XORP_ERROR. **/intMld6igmpVif::delete_protocol(xorp_module_id module_id, const string& module_instance_name){ vector<pair<xorp_module_id, string> >::iterator iter; iter = find(_notify_routing_protocols.begin(), _notify_routing_protocols.end(), pair<xorp_module_id, string>(module_id, module_instance_name)); if (iter == _notify_routing_protocols.end()) return (XORP_ERROR); // Not on the list _notify_routing_protocols.erase(iter); return (XORP_OK);}/** * Test if the interface is running in IGMPv1 mode. * * @return true if the interface is running in IGMPv1 mode, otherwise false. */boolMld6igmpVif::is_igmpv1_mode() const{ return (proto_is_igmp() && (proto_version() == IGMP_V1));}/** * Test if the interface is running in IGMPv2 mode. * * @return true if the interface is running in IGMPv2 mode, otherwise false. */boolMld6igmpVif::is_igmpv2_mode() const{ return (proto_is_igmp() && (proto_version() == IGMP_V2));}/** * Test if the interface is running in IGMPv3 mode. * * @return true if the interface is running in IGMPv3 mode, otherwise false. */boolMld6igmpVif::is_igmpv3_mode() const{ return (proto_is_igmp() && (proto_version() == IGMP_V3));}/** * Test if the interface is running in MLDv1 mode. * * @return true if the interface is running in MLDv1 mode, otherwise false. */boolMld6igmpVif::is_mldv1_mode() const{ return (proto_is_mld6() && (proto_version() == MLD_V1));}/** * Test if the interface is running in MLDv2 mode. * * @return true if the interface is running in MLDv2 mode, otherwise false. */boolMld6igmpVif::is_mldv2_mode() const{ return (proto_is_mld6() && (proto_version() == MLD_V2));}/** * Test if a group is running in IGMPv1 mode. * * Note that if @ref group_record is NULL, then we test whether the * interface itself is running in IGMPv1 mode. * @param group_record the group record to test. * @return true if the group is running in IGMPv1 mode, * otherwise false. */boolMld6igmpVif::is_igmpv1_mode(const Mld6igmpGroupRecord* group_record) const{ if (group_record != NULL) return (group_record->is_igmpv1_mode()); return (is_igmpv1_mode());}/** * Test if a group is running in IGMPv2 mode. * * Note that if @ref group_record is NULL, then we test whether the * interface itself is running in IGMPv2 mode. * @param group_record the group record to test. * @return true if the group is running in IGMPv2 mode, * otherwise false. */boolMld6igmpVif::is_igmpv2_mode(const Mld6igmpGroupRecord* group_record) const{ if (group_record != NULL) return (group_record->is_igmpv2_mode()); return (is_igmpv2_mode());}/** * Test if a group is running in IGMPv3 mode. * * Note that if @ref group_record is NULL, then we test whether the * interface itself is running in IGMPv3 mode. * @param group_record the group record to test. * @return true if the group is running in IGMPv3 mode, * otherwise false. */boolMld6igmpVif::is_igmpv3_mode(const Mld6igmpGroupRecord* group_record) const{ if (group_record != NULL) return (group_record->is_igmpv3_mode()); return (is_igmpv3_mode());}/** * Test if a group is running in MLDv1 mode. * * Note that if @ref group_record is NULL, then we test whether the * interface itself is running in MLDv1 mode. * @param group_record the group record to test. * @return true if the group is running in MLDv1 mode, * otherwise false. */boolMld6igmpVif::is_mldv1_mode(const Mld6igmpGroupRecord* group_record) const{ if (group_record != NULL) return (group_record->is_mldv1_mode()); return (is_mldv1_mode());}/** * Test if a group is running in MLDv2 mode. * * Note that if @ref group_record is NULL, then we test whether the * interface itself is running in MLDv2 mode. * @param group_record the group record to test. * @return true if the group is running in MLDv2 mode, * otherwise false. */boolMld6igmpVif::is_mldv2_mode(const Mld6igmpGroupRecord* group_record) const{ if (group_record != NULL) return (group_record->is_mldv2_mode()); return (is_mldv2_mode());}/** * Return the ASCII text description of the protocol message. * * @param message_type the protocol message type. * @return the ASCII text descrpition of the protocol message. */const char *Mld6igmpVif::proto_message_type2ascii(uint8_t message_type) const{ if (proto_is_igmp()) return (IGMPTYPE2ASCII(message_type)); if (proto_is_mld6()) return (MLDTYPE2ASCII(message_type)); return ("Unknown protocol message");}/** * Reset and prepare the buffer for sending data. * * @return the prepared buffer. */buffer_t *Mld6igmpVif::buffer_send_prepare(){ BUFFER_RESET(_buffer_send); return (_buffer_send);}/** * Calculate the checksum of an IPv6 "pseudo-header" as described * in RFC 2460. * * @param src the source address of the pseudo-header. * @param dst the destination address of the pseudo-header. * @param len the upper-layer packet length of the pseudo-header * (in host-order). * @param protocol the upper-layer protocol number. * @return the checksum of the IPv6 "pseudo-header". */uint16_tMld6igmpVif::calculate_ipv6_pseudo_header_checksum(const IPvX& src, const IPvX& dst, size_t len, uint8_t protocol){ struct ip6_pseudo_hdr { struct in6_addr ip6_src; // Source address struct in6_addr ip6_dst; // Destination address uint32_t ph_len; // Upper-layer packet length uint8_t ph_zero[3]; // Zero uint8_t ph_next; // Upper-layer protocol number } ip6_pseudo_header; // TODO: may need __attribute__((__packed__)) src.copy_out(ip6_pseudo_header.ip6_src); dst.copy_out(ip6_pseudo_header.ip6_dst); ip6_pseudo_header.ph_len = htonl(len); ip6_pseudo_header.ph_zero[0] = 0; ip6_pseudo_header.ph_zero[1] = 0; ip6_pseudo_header.ph_zero[2] = 0; ip6_pseudo_header.ph_next = protocol; uint16_t cksum = inet_checksum( reinterpret_cast<const uint8_t *>(&ip6_pseudo_header), sizeof(ip6_pseudo_header)); return (cksum);}/** * Notify the interested parties that there is membership change among * the local members. * * @param source the source address of the (S,G) entry that has changed. * In case of group-specific membership, it could be IPvX::ZERO(). * @param group the group address of the (S,G) entry that has changed. * @param action_jp the membership change: @ref ACTION_JOIN * or @ref ACTION_PRUNE. * @return XORP_OK on success, otherwise XORP_ERROR. */intMld6igmpVif::join_prune_notify_routing(const IPvX& source, const IPvX& group, action_jp_t action_jp) const{ XLOG_TRACE(mld6igmp_node().is_log_trace(), "Notify routing %s membership for (%s, %s) on vif %s", (action_jp == ACTION_JOIN)? "add" : "delete", cstring(source), cstring(group), name().c_str()); vector<pair<xorp_module_id, string> >::const_iterator iter; for (iter = _notify_routing_protocols.begin(); iter != _notify_routing_protocols.end(); ++iter) { pair<xorp_module_id, string> my_pair = *iter; xorp_module_id module_id = my_pair.first; string module_instance_name = my_pair.second; if (mld6igmp_node().join_prune_notify_routing(module_instance_name, module_id, vif_index(), source, group, action_jp) != XORP_OK) { // // TODO: remove <module_id, module_instance_name> ?? // } } return (XORP_OK);}boolMld6igmpVif::i_am_querier() const{ if (_proto_flags & MLD6IGMP_VIF_QUERIER) return (true); else return (false);}voidMld6igmpVif::set_i_am_querier(bool v){ if (v) { _proto_flags |= MLD6IGMP_VIF_QUERIER; // // XXX: Restore the variables that might have been adopted from // the Querier. // restore_effective_variables(); } else { _proto_flags &= ~MLD6IGMP_VIF_QUERIER; }}size_tMld6igmpVif::mld6igmp_constant_minlen() const{ if (proto_is_igmp()) return (IGMP_MINLEN); if (proto_is_mld6()) return (MLD_MINLEN); XLOG_UNREACHABLE(); return (0);}uint32_tMld6igmpVif::mld6igmp_constant_timer_scale() const{ if (proto_is_igmp()) return (IGMP_TIMER_SCALE); if (proto_is_mld6()) return (MLD_TIMER_SCALE); XLOG_UNREACHABLE(); return (0);}uint8_tMld6igmpVif::mld6igmp_constant_membership_query() const{ if (proto_is_igmp()) return (IGMP_MEMBERSHIP_QUERY); if (proto_is_mld6()) return (MLD_LISTENER_QUERY); XLOG_UNREACHABLE(); return (0);}// TODO: temporary here. Should go to the Vif class after the Vif// class starts using the Proto classstringMld6igmpVif::flags_string() const{ string flags; if (is_up()) flags += " UP"; if (is_down()) flags += " DOWN"; if (is_pending_up()) flags += " PENDING_UP"; if (is_pending_down()) flags += " PENDING_DOWN"; if (is_ipv4()) flags += " IPv4"; if (is_ipv6()) flags += " IPv6"; if (is_enabled()) flags += " ENABLED"; if (is_disabled()) flags += " DISABLED"; return (flags);}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -