bool TNlHtb::Valid(const TNlLink &link, uint32_t defaultClass) { int ret; struct nl_cache *qdiscCache; bool valid = true; ret = rtnl_qdisc_alloc_cache(link.GetSock(), &qdiscCache); if (ret < 0) { L_ERR() << "can't alloc qdisc cache" << std::endl; return false; } struct rtnl_qdisc *qdisc = rtnl_qdisc_get(qdiscCache, link.GetIndex(), Handle); if (qdisc) { link.Dump("found", qdisc); if (rtnl_tc_get_ifindex(TC_CAST(qdisc)) != link.GetIndex()) valid = false; else if (rtnl_tc_get_parent(TC_CAST(qdisc)) != Parent) valid = false; else if (rtnl_tc_get_handle(TC_CAST(qdisc)) != Handle) valid = false; else if (rtnl_tc_get_kind(TC_CAST(qdisc)) != std::string("htb")) valid = false; else if (rtnl_htb_get_defcls(qdisc) != TC_H_MIN(defaultClass)) valid = false; } else { valid = false; } rtnl_qdisc_put(qdisc); nl_cache_free(qdiscCache); return valid; }
bool TNlHtb::Exists(const TNlLink &link) { int ret; struct nl_cache *qdiscCache; bool exists; ret = rtnl_qdisc_alloc_cache(link.GetSock(), &qdiscCache); if (ret < 0) return false; link.LogCache(qdiscCache); struct rtnl_qdisc *qdisc = rtnl_qdisc_get(qdiscCache, link.GetIndex(), Handle); exists = qdisc != nullptr; rtnl_qdisc_put(qdisc); nl_cache_free(qdiscCache); return exists; }
bool TNlQdisc::Check(const TNl &nl) { struct nl_cache *qdiscCache; bool result = false; int ret; ret = rtnl_qdisc_alloc_cache(nl.GetSock(), &qdiscCache); if (ret < 0) { L_ERR() << nl.Error(ret, "cannot alloc qdisc cache") << std::endl; return false; } struct rtnl_qdisc *qdisc = rtnl_qdisc_get(qdiscCache, Index, Handle); if (!qdisc) { result = Kind == ""; goto out; } nl.Dump("found", qdisc); if (rtnl_tc_get_ifindex(TC_CAST(qdisc)) != Index) goto out; if (rtnl_tc_get_parent(TC_CAST(qdisc)) != Parent) goto out; if (rtnl_tc_get_handle(TC_CAST(qdisc)) != Handle) goto out; if (rtnl_tc_get_kind(TC_CAST(qdisc)) != Kind) goto out; if (Kind == "htb") { if (rtnl_htb_get_defcls(qdisc) != Default) goto out; } result = true; out: rtnl_qdisc_put(qdisc); nl_cache_free(qdiscCache); return result; }