bool mld_interface::output_info(base_stream &ctx, const std::vector<std::string> &) const { ctx.xprintf("MLD, version %i", (int)mif_mld_version); if (owner()->linklocals().empty()) { ctx.writeline(", not running"); return true; } ctx.newl(); ctx.inc_level(); if (!mif_isquerier) { if (mif_querier_addr.is_any()) { ctx.writeline("Querier: None"); } else { ctx.xprintf("Querier: %{Addr} for %{duration}\n", mif_querier_addr, mif_other_querier_present_timer_id.time_left_d()); } } else { ctx.writeline("Querier: self"); } ctx.dec_level(); return true; }
void base_ptree::dump_internal_tree_graphviz(base_stream &os, const ptree_node *node, const char *color) const { if (!node) return; os.xprintf("\"%p\" ", (const void *)node); if (color) { os.write("[label=\""); if (node->_t_color == ptree_node::BLACK) write_prefix(os, node); else os.xprintf("white %i", (int)node->_t_bit); os.xprintf("\",color=%s];\n", color); dump_internal_tree_graphviz(os, node->_t_left, "red"); dump_internal_tree_graphviz(os, node->_t_right, "green"); } else { os.write("-- {"); if (node->_t_left) os.xprintf("\"%p\"", (const void *)node->_t_left); if (node->_t_right) os.xprintf(" \"%p\"", (const void *)node->_t_right); os.writeline("};"); dump_internal_tree_graphviz(os, node->_t_left, 0); dump_internal_tree_graphviz(os, node->_t_right, 0); } }
bool _static_sources_node::output_info(base_stream &os, const std::vector<std::string> &args) const { if (!args.empty()) return false; os.xprintf("Sources: %{addrset}\n", sources); return true; }
static void _draw_sep(base_stream &ctx, int n) { char buf[64]; buf[0] = '+'; memset(buf + 1, '-', n+2); buf[n+3] = 0; ctx.xprintf("%s+--------------+------------+----------+\n", buf); }
void aggr_source_discovery::dump_cache(base_stream &out, const cache &c) const { time_t now = time(0); for (cache::const_iterator i = c.begin(); i != c.end(); ++i) { out.xprintf("(%{Addr}, %{Addr}) for %{duration}\n", i->first.second, i->first.first, time_duration((now - i->second) * 1000)); } }
void base_ptree::dump_internal_tree(base_stream &os, const ptree_node *node, const char *desc) const { if (!node) return; os.xprintf("%s ", desc); if (node->_t_color == ptree_node::BLACK) write_prefix(os, node); else os.write("white"); os.xprintf(" at %i", (int)node->_t_bit); os.newl(); os.inc_level(); dump_internal_tree(os, node->_t_left, "left"); dump_internal_tree(os, node->_t_right, "right"); os.dec_level(); }
bool group::output_info(base_stream &_out, bool detailed) const { _out.xprintf("Group %{Addr}\n", id()); _out.inc_level(); node::output_info(_out, std::vector<std::string>()); _out.dec_level(); return true; }
bool linux_unicast_router::show_filter_routes(base_stream &out, const std::vector<std::string> &args) { if (!args.empty()) { out.writeline("This method accepts no arguments."); return true; } const std::map<int, std::string> pmap = parse_rt_protos(); for (std::set<int>::const_iterator i = filter_protos.begin(); i != filter_protos.end(); ++i) { std::map<int, std::string>::const_iterator j = pmap.find(*i); if (j == pmap.end()) out.xprintf("? (%i)\n", *i); else out.xprintf("%s (%i)\n", j->second.c_str(), *i); } return true; }
void us_mfa_group_source::output_info(base_stream &out, bool counters, bool noempty) const { if (counters) { if (noempty && !stat_packet_count60s) return; out.xprintf("%{addr}", m_addr); out.inc_level(); if (stat_packet_count60s) { out.write(" Activity statistics: "); const char *format = "%.2f %s"; double rate = 8 * stat_octet_count60s / 60000.; const char *unit = "Kb/s"; if (rate > 1000) { rate /= 1000.; unit = "Mb/s"; } out.printf(format, rate, unit); out.printf(" (%.2f pkt/s)", stat_packet_count60s / 60.f); out.newl(); out.printf("Last 60 secs: %llu bytes (%llu packets, %.2lf bytes/packet)", stat_octet_count60s, stat_packet_count60s, stat_octet_count60s / (double)stat_packet_count60s); out.newl(); } else { out.writeline(" No activity in the last 60 seconds"); } out.dec_level(); } else { out.xprintf("%{addr} from %s to ", m_addr, m_iif ? m_iif->name() : "(None)"); output(out, m_oifs); out.newl(); } }
bool node::call_method(int id, base_stream &out, const std::vector<std::string> &args) { switch (id) { case node_method_enable: case node_method_disable: return enable_several(args, id == node_method_enable); case node_method_no: return exec_negate(out, args); case node_method_show_properties: { std::string fname = m_parent ? full_name() : std::string(); for (properties::const_iterator i = m_properties.begin(); i != m_properties.end(); ++i) { if (!fname.empty()) out.write(fname.c_str()).write("."); out.write(i->first.c_str()).write(" = "); if (i->second.is_property()) { i->second.output_value(out); if (i->second.is_readonly()) out.write(" [readonly]"); } else if (i->second.is_child()) { out.xprintf("<node %s>", i->second.get_node()->name()); } else if (i->second.is_method()) { if (i->second.is_readonly()) out.write("<info-method "); else out.write("<method "); out.xprintf("%s>", i->second.get_method_info()->name); } out.newl(); } return true; } } return false; }
bool pim_interface::output_info(base_stream &ctx, bool extended) const { if (get_state() == NOT_READY) return false; ctx.writeline("PIM"); ctx.inc_level(); ctx.xprintf("DR Priority: %u\n", conf()->dr_priority()); ctx.xprintf("LAN Propagation Delay: %ums Override Interval: %ums\n", conf()->propagation_delay(), conf()->override_interval()); if (elected_dr) ctx.xprintf("DR: %{Addr}\n", elected_dr->localaddr()); else ctx.writeline("DR: self"); ctx.writeline("Neighbours:"); ctx.inc_level(); if (neighbours.empty()) { ctx.writeline("(None)"); } else { for (neighbours_def::const_iterator j = neighbours.begin(); j != neighbours.end(); j++) { (*j)->output_info(ctx, extended); } } ctx.dec_level(); ctx.dec_level(); return true; }
bool linux_unicast_router::filter_routes(base_stream &out, const std::vector<std::string> &args) { std::map<int, std::string> pmap = parse_rt_protos(); std::map<std::string, int> proto_map; for (std::map<int, std::string>::const_iterator i = pmap.begin(); i != pmap.end(); ++i) proto_map[i->second] = i->first; std::set<int> new_filter; for (std::vector<std::string>::const_iterator i = args.begin(); i != args.end(); ++i) { int value = -1; if (isdigit(*i->c_str())) { char *endp; value = strtol(i->c_str(), &endp, 10); if (*endp) value = -1; } else { std::map<std::string, int>::const_iterator j = proto_map.find(*i); if (j != proto_map.end()) value = j->second; } if (value < 0) { out.xprintf("Invalid argument `%s`.\n", i->c_str()); return true; } new_filter.insert(value); } filter_protos = new_filter; return true; }
bool console_module::output_info(base_stream &ctx, const std::vector<std::string> &args) const { if (!args.empty()) return false; ctx.writeline("Console"); ctx.inc_level(); ctx.writeline("Allowed:"); ctx.inc_level(); if (acl.empty()) { ctx.writeline("(None)"); } else { for (allow_local_def::const_iterator i = acl.begin(); i != acl.end(); i++) { for (std::list<auth_desc>::const_iterator j = i->second.begin(); j != i->second.end(); j++) { if (j->username.empty() || j->username == "*") ctx.write("Any"); else ctx.write(j->username.c_str()); if (j->password.empty() || j->password == "*") ctx.write(" with no password"); ctx.xprintf(" from %{Addr}\n", i->first); } } } ctx.dec_level(); ctx.dec_level(); return true; }
void group_interface::dump_filter(base_stream &os) const { os.xprintf("%s %{addrset}", (filter_mode() == include ? "Include" : "Exclude"), (filter_mode() == include ? include_set() : exclude_set())); }
bool pim_router::call_method(int id, base_stream &out, const std::vector<std::string> &args) { if (id == pim_router_method_rpf) { if (args.size() != 1) return false; inet6_addr addr; if (!addr.set(args[0].c_str())) return false; pim_neighbour *neigh = get_rpf_neighbour(addr); if (neigh) { neigh->output_info(out, false); } else { out.writeline("No RPF neighbor."); } return true; } else if (id == pim_router_method_group_rp) { if (args.size() != 1) return false; inet6_addr addr; if (!addr.set(args[0].c_str())) return false; pim_groupconf_node *pconf = 0; groupconf *conf = g_mrd->match_group_configuration(addr); while (conf && !pconf) { pconf = (pim_groupconf_node *)conf->get_child("pim"); conf = g_mrd->get_similar_groupconf_node(conf); } if (!pconf) { out.writeline("No available configuration."); return true; } in6_addr rpaddr; rp_source src; if (pconf->rp_for_group(addr, rpaddr, src)) { out.xprintf("RP: %{addr} [", rpaddr); if (src == rps_static) out.write("static"); else if (src == rps_embedded) out.write("embedded"); else if (src == rps_rp_set) out.write("rp_set"); else out.write("unknown"); out.writeline("]"); } else { out.writeline("No available RP"); } return true; } else if (id == pim_router_method_group_summary) { if (args.size() > 1) return false; inet6_addr mask; if (!args.empty()) { if (!mask.set(args[0].c_str())) return false; } mrd::group_list::const_iterator i = g_mrd->group_table().begin(); for (; i != g_mrd->group_table().end(); ++i) { if (!mask.matches(i->first)) continue; pim_group_node *grp = (pim_group_node *)i->second->node_owned_by(this); if (!grp) continue; out.xprintf("%{Addr}\n", i->first); out.inc_level(); if (grp->wildcard()) { out.xprintf("Wildcard present, RP is at %{addr}\n", grp->rpaddr()); } int count = grp->source_state_set().size(); out.xprintf("Has %i state%s.\n", count, count > 1 ? "s" : ""); int local = grp->local_source_state_set().size(); if (local > 0) { out.xprintf("Of which %i %s local.\n", local, local > 1 ? "are" : "is"); } out.dec_level(); } return true; } return router::call_method(id, out, args); }
void mld_group_interface::output_info(base_stream &ctx, bool detailed) const { ctx.xprintf("Group-Interface %s [MLD]\n", intf()->name()); ctx.inc_level(); int maxsources = 3; const address_set &srcs = active_set(); if (detailed) { maxsources = srcs.size(); } ctx.xprintf("Filter: %s ", filter_mode() == include ? "Include" : "Exclude"); if (srcs.empty()) { ctx.write("{}"); } else { ctx.write("{"); address_set::const_iterator i = srcs.begin(); ctx.xprintf("%{addr}", *i); ++i; for (int k = 1; k < maxsources && i != srcs.end(); ++i) { ctx.xprintf(", %{addr}", *i); k++; } if (i != srcs.end()) ctx.write(", ..."); ctx.write(" }"); } if (g_filter_timer.is_running()) { ctx.xprintf(" (Reset in %{duration})", g_filter_timer.time_left_d()); } ctx.newl(); if (detailed) { if (!g_sources_timers.empty()) { ctx.writeline("Sources:"); ctx.inc_level(); std::vector<source_timer>::const_iterator i; for (i = g_sources_timers.begin(); i != g_sources_timers.end(); ++i) { ctx.xprintf("%{addr} for %{duration}", i->argument(), i->time_left_d()); } ctx.dec_level(); } } output_inner_info(ctx, detailed); ctx.dec_level(); }
bool mld_router::call_method(int id, base_stream &out, const std::vector<std::string> &args) { if (id == mld_router_method_show_groups) { inet6_addr mask; if (args.size() == 1) { if (!mask.set(args[0].c_str())) return false; } else if (args.size() > 1) { return false; } mrd::group_list::const_iterator i = g_mrd->group_table().begin(); for (; i != g_mrd->group_table().end(); ++i) { if (!mask.matches(i->first)) continue; mld_group *grp = (mld_group *)i->second->node_owned_by(this); if (!grp) continue; group::group_intfs::const_iterator j; int count = 0; j = i->second->interface_table().begin(); for (; j != i->second->interface_table().end(); ++j) { if (j->second->owner_node() == grp) count++; } if (!count) continue; out.xprintf("%{Addr}\n", i->first); out.inc_level(); j = i->second->interface_table().begin(); for (; j != i->second->interface_table().end(); ++j) { if (j->second->owner_node() == grp) { mld_group_interface *mldintf = (mld_group_interface *)j->second; out.write(mldintf->intf()->name()).write(": "); mldintf->dump_filter(out); out.xprintf(", Uptime: %{duration}", time_duration(mldintf->uptime())); uint32_t val = mldintf->time_left_to_expiry(true); if (val > 0) { out.xprintf(", Time left: %{duration}", time_duration(val)); } out.xprintf(", Last reporter: %{Addr}\n", mldintf->last_reporter()); } } out.dec_level(); } return true; } return router::call_method(id, out, args); }