Beispiel #1
0
TError TNlClass::Create(const TNl &nl) {
    struct rtnl_class *cls;
    TError error;
    int ret;

    cls = rtnl_class_alloc();
    if (!cls)
        return TError(EError::Unknown, "Cannot allocate rtnl_class object");

    rtnl_tc_set_ifindex(TC_CAST(cls), Index);
    rtnl_tc_set_parent(TC_CAST(cls), Parent);
    rtnl_tc_set_handle(TC_CAST(cls), Handle);

    ret = rtnl_tc_set_kind(TC_CAST(cls), Kind.c_str());
    if (ret < 0) {
        error = nl.Error(ret, "Cannot set class kind");
        goto free_class;
    }

    if (Kind == "htb") {
        /* must be <= INT32_MAX to prevent overflows in libnl */
        uint64_t maxRate = INT32_MAX;

        /*
         * HTB doesn't allow 0 rate
         * FIXME add support for 64-bit rates
         */
        rtnl_htb_set_rate(cls, std::min(Rate ?: 1, maxRate));
        rtnl_htb_set_ceil(cls, std::min(Ceil ?: maxRate, maxRate));
        rtnl_htb_set_prio(cls, Prio);

        if (MTU)
            rtnl_tc_set_mtu(TC_CAST(cls), MTU);

        if (Quantum)
            rtnl_htb_set_quantum(cls, Quantum);

        if (RateBurst)
            rtnl_htb_set_rbuffer(cls, RateBurst);

        if (CeilBurst)
            rtnl_htb_set_cbuffer(cls, CeilBurst);
    }
Beispiel #2
0
void nl_cli_tc_parse_mtu(struct rtnl_tc *tc, char *arg)
{
	rtnl_tc_set_mtu(tc, nl_cli_parse_u32(arg));
}