Beispiel #1
0
static int red_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
	struct rtattr *tb[TCA_RED_STAB+1];
	struct tc_red_qopt *qopt;
	SPRINT_BUF(b1);
	SPRINT_BUF(b2);
	SPRINT_BUF(b3);

	if (opt == NULL)
		return 0;

	parse_rtattr_nested(tb, TCA_RED_STAB, opt);

	if (tb[TCA_RED_PARMS] == NULL)
		return -1;
	qopt = RTA_DATA(tb[TCA_RED_PARMS]);
	if (RTA_PAYLOAD(tb[TCA_RED_PARMS])  < sizeof(*qopt))
		return -1;
	fprintf(f, "limit %s min %s max %s ",
		sprint_size(qopt->limit, b1),
		sprint_size(qopt->qth_min, b2),
		sprint_size(qopt->qth_max, b3));
#ifdef TC_RED_ECN
	if (qopt->flags & TC_RED_ECN)
		fprintf(f, "ecn ");
#endif
	if (show_details) {
		fprintf(f, "ewma %u Plog %u Scell_log %u",
			qopt->Wlog, qopt->Plog, qopt->Scell_log);
	}
	return 0;
}
Beispiel #2
0
static int gred_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
	struct rtattr *tb[TCA_GRED_STAB+1];
	struct tc_gred_qopt *qopt;
	int i;
	SPRINT_BUF(b1);
	SPRINT_BUF(b2);
	SPRINT_BUF(b3);
	SPRINT_BUF(b4);
	SPRINT_BUF(b5);

	if (opt == NULL)
		return 0;

	parse_rtattr_nested(tb, TCA_GRED_STAB, opt);

	if (tb[TCA_GRED_PARMS] == NULL)
		return -1;

	qopt = RTA_DATA(tb[TCA_GRED_PARMS]);
	if (RTA_PAYLOAD(tb[TCA_GRED_PARMS])  < sizeof(*qopt)*MAX_DPs) {
		fprintf(f,"\n GRED received message smaller than expected\n");
		return -1;
		}
         
/* Bad hack! should really return a proper message as shown above*/

	for (i=0;i<MAX_DPs;i++, qopt++) {
		if (qopt->DP >= MAX_DPs) continue;
		fprintf(f, "\n DP:%d (prio %d) Average Queue %s Measured "
		    "Queue %s  ",
			qopt->DP,
			qopt->prio,
			sprint_size(qopt->qave, b4),
			sprint_size(qopt->backlog, b5));
		fprintf(f, "\n\t Packet drops: %d (forced %d early %d)  ",
			qopt->forced+qopt->early,
			qopt->forced,
			qopt->early);
		fprintf(f, "\n\t Packet totals: %u (bytes %u)  ",
			qopt->packets,
			qopt->bytesin);
		if (show_details)
			fprintf(f, "\n limit %s min %s max %s ",
				sprint_size(qopt->limit, b1),
				sprint_size(qopt->qth_min, b2),
				sprint_size(qopt->qth_max, b3));
				fprintf(f, "ewma %u Plog %u Scell_log %u",
				    qopt->Wlog, qopt->Plog, qopt->Scell_log);
	}
	return 0;
}
Beispiel #3
0
int
print_police(struct action_util *a, FILE *f, struct rtattr *arg)
{
	SPRINT_BUF(b1);
	SPRINT_BUF(b2);
	struct tc_police *p;
	struct rtattr *tb[TCA_POLICE_MAX+1];
	unsigned buffer;
	unsigned int linklayer;

	if (arg == NULL)
		return 0;

	parse_rtattr_nested(tb, TCA_POLICE_MAX, arg);

	if (tb[TCA_POLICE_TBF] == NULL) {
		fprintf(f, "[NULL police tbf]");
		return 0;
	}
#ifndef STOOPID_8BYTE
	if (RTA_PAYLOAD(tb[TCA_POLICE_TBF])  < sizeof(*p)) {
		fprintf(f, "[truncated police tbf]");
		return -1;
	}
#endif
	p = RTA_DATA(tb[TCA_POLICE_TBF]);

	fprintf(f, " police 0x%x ", p->index);
	fprintf(f, "rate %s ", sprint_rate(p->rate.rate, b1));
	buffer = tc_calc_xmitsize(p->rate.rate, p->burst);
	fprintf(f, "burst %s ", sprint_size(buffer, b1));
	fprintf(f, "mtu %s ", sprint_size(p->mtu, b1));
	if (show_raw)
		fprintf(f, "[%08x] ", p->burst);
	if (p->peakrate.rate)
		fprintf(f, "peakrate %s ", sprint_rate(p->peakrate.rate, b1));
	if (tb[TCA_POLICE_AVRATE])
		fprintf(f, "avrate %s ", sprint_rate(rta_getattr_u32(tb[TCA_POLICE_AVRATE]), b1));
	fprintf(f, "action %s", police_action_n2a(p->action, b1, sizeof(b1)));
	if (tb[TCA_POLICE_RESULT]) {
		fprintf(f, "/%s ", police_action_n2a(*(int*)RTA_DATA(tb[TCA_POLICE_RESULT]), b1, sizeof(b1)));
	} else
		fprintf(f, " ");
	fprintf(f, "overhead %ub ", p->rate.overhead);
	linklayer = (p->rate.linklayer & TC_LINKLAYER_MASK);
	if (linklayer > TC_LINKLAYER_ETHERNET || show_details)
		fprintf(f, "linklayer %s ", sprint_linklayer(linklayer, b2));
	fprintf(f, "\nref %d bind %d\n",p->refcnt, p->bindcnt);

	return 0;
}
Beispiel #4
0
static int sfq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
	struct tc_sfq_qopt *qopt;
	struct tc_sfq_qopt_v1 *qopt_ext = NULL;
	SPRINT_BUF(b1);
	SPRINT_BUF(b2);
	SPRINT_BUF(b3);
	if (opt == NULL)
		return 0;

	if (RTA_PAYLOAD(opt)  < sizeof(*qopt))
		return -1;
	if (RTA_PAYLOAD(opt) >= sizeof(*qopt_ext))
		qopt_ext = RTA_DATA(opt);
	qopt = RTA_DATA(opt);
	fprintf(f, "limit %up ", qopt->limit);
	fprintf(f, "quantum %s ", sprint_size(qopt->quantum, b1));
	if (qopt_ext && qopt_ext->depth)
		fprintf(f, "depth %u ", qopt_ext->depth);
	if (qopt_ext && qopt_ext->headdrop)
		fprintf(f, "headdrop ");

	if (show_details) {
		fprintf(f, "flows %u/%u ", qopt->flows, qopt->divisor);
	}
	fprintf(f, "divisor %u ", qopt->divisor);
	if (qopt->perturb_period)
		fprintf(f, "perturb %dsec ", qopt->perturb_period);
	if (qopt_ext && qopt_ext->qth_min) {
		fprintf(f, "\n ewma %u ", qopt_ext->Wlog);
		fprintf(f, "min %s max %s probability %g ",
			sprint_size(qopt_ext->qth_min, b2),
			sprint_size(qopt_ext->qth_max, b3),
			qopt_ext->max_P / pow(2, 32));
		if (qopt_ext->flags & TC_RED_ECN)
			fprintf(f, "ecn ");
		if (show_stats) {
			fprintf(f, "\n prob_mark %u prob_mark_head %u prob_drop %u",
				qopt_ext->stats.prob_mark,
				qopt_ext->stats.prob_mark_head,
				qopt_ext->stats.prob_drop);
			fprintf(f, "\n forced_mark %u forced_mark_head %u forced_drop %u",
				qopt_ext->stats.forced_mark,
				qopt_ext->stats.forced_mark_head,
				qopt_ext->stats.forced_drop);
		}
	}
	return 0;
}
Beispiel #5
0
static int myred_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
	struct rtattr *tb[TCA_MYRED_STAB+1];
	struct tc_myred_qopt *qopt;


	SPRINT_BUF(b1);

	if (opt == NULL)
		return 0;

	parse_rtattr_nested(tb, TCA_MYRED_STAB, opt);

	if (tb[TCA_MYRED_PARMS] == NULL)
		return -1;
	qopt = RTA_DATA(tb[TCA_MYRED_PARMS]);
	if (RTA_PAYLOAD(tb[TCA_MYRED_PARMS])  < sizeof(*qopt))
		return -1;
	fprintf(f, "limit %s",
		sprint_size(qopt->limit, b1));
#ifdef TC_MYRED_ECN
	if (qopt->flags & TC_MYRED_ECN)
		fprintf(f, "ecn ");
#endif
	/*qjl*/
	if (show_details) {
		fprintf(f, "p_init %lf p_min %lf p_max %lf q_min %d q_max %d sampl_period %d",
			qopt->p_init, qopt->p_min, qopt->p_max, qopt->q_min, qopt->q_max, qopt->sampl_period);
	}
	return 0;
}
static int red_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
    struct rtattr *tb[TCA_NRED_MAX + 1];
    struct tc_nred_qopt *qopt;
    __u32 max_P = 0;
    SPRINT_BUF(b1);
    SPRINT_BUF(b2);
    SPRINT_BUF(b3);
    //SPRINT_BUF(b4);

    if (opt == NULL)
        return 0;

    parse_rtattr_nested(tb, TCA_NRED_MAX, opt);

    if (tb[TCA_NRED_PARMS] == NULL)
        return -1;
    qopt = RTA_DATA(tb[TCA_NRED_PARMS]);
    if (RTA_PAYLOAD(tb[TCA_NRED_PARMS])  < sizeof(*qopt))
        return -1;

    if (tb[TCA_NRED_MAX_P] &&
        RTA_PAYLOAD(tb[TCA_NRED_MAX_P]) >= sizeof(__u32))
        max_P = rta_getattr_u32(tb[TCA_NRED_MAX_P]);

    fprintf(f, "limit %s min %s max %s ",
        sprint_size(qopt->limit, b1),
        sprint_size(qopt->qth_min, b2),
        sprint_size(qopt->qth_max, b3));
        //sprint_size(qopt->decrement, b4));
    if (qopt->flags & TC_RED_ECN)
        fprintf(f, "ecn ");
    if (qopt->flags & TC_RED_HARDDROP)
        fprintf(f, "harddrop ");
    if (qopt->flags & TC_RED_ADAPTATIVE)
        fprintf(f, "adaptive ");
    if (show_details) {
        fprintf(f, "ewma %u ", qopt->Wlog);
        if (max_P)
            fprintf(f, "probability %lg ", max_P / pow(2, 32));
        else
            fprintf(f, "Plog %u ", qopt->Plog);
        fprintf(f, "Scell_log %u", qopt->Scell_log);
    }
    return 0;
}
Beispiel #7
0
static int tbf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
	struct rtattr *tb[TCA_TBF_PTAB+1];
	struct tc_tbf_qopt *qopt;
	double buffer, mtu;
	double latency;
	SPRINT_BUF(b1);
	SPRINT_BUF(b2);

	if (opt == NULL)
		return 0;

	memset(tb, 0, sizeof(tb));
	parse_rtattr(tb, TCA_TBF_PTAB, RTA_DATA(opt), RTA_PAYLOAD(opt));

	if (tb[TCA_TBF_PARMS] == NULL)
		return -1;

	qopt = RTA_DATA(tb[TCA_TBF_PARMS]);
	if (RTA_PAYLOAD(tb[TCA_TBF_PARMS])  < sizeof(*qopt))
		return -1;
	fprintf(f, "rate %s ", sprint_rate(qopt->rate.rate, b1));
	buffer = ((double)qopt->rate.rate*tc_core_tick2usec(qopt->buffer))/1000000;
	if (show_details) {
		fprintf(f, "burst %s/%u mpu %s ", sprint_size(buffer, b1),
			1<<qopt->rate.cell_log, sprint_size(qopt->rate.mpu, b2));
	} else {
		fprintf(f, "burst %s ", sprint_size(buffer, b1));
	}
	if (show_raw)
		fprintf(f, "[%08x] ", qopt->buffer);
	if (qopt->peakrate.rate) {
		fprintf(f, "peakrate %s ", sprint_rate(qopt->peakrate.rate, b1));
		if (qopt->mtu || qopt->peakrate.mpu) {
			mtu = ((double)qopt->peakrate.rate*tc_core_tick2usec(qopt->mtu))/1000000;
			if (show_details) {
				fprintf(f, "mtu %s/%u mpu %s ", sprint_size(mtu, b1),
					1<<qopt->peakrate.cell_log, sprint_size(qopt->peakrate.mpu, b2));
			} else {
				fprintf(f, "minburst %s ", sprint_size(mtu, b1));
			}
			if (show_raw)
				fprintf(f, "[%08x] ", qopt->mtu);
		}
	}

	if (show_raw)
		fprintf(f, "limit %s ", sprint_size(qopt->limit, b1));

	latency = 1000000*(qopt->limit/(double)qopt->rate.rate) - tc_core_tick2usec(qopt->buffer);
	if (qopt->peakrate.rate) {
		double lat2 = 1000000*(qopt->limit/(double)qopt->peakrate.rate) - tc_core_tick2usec(qopt->mtu);
		if (lat2 > latency)
			latency = lat2;
	}
	fprintf(f, "lat %s ", sprint_usecs(tc_core_tick2usec(latency), b1));

	return 0;
}
Beispiel #8
0
static int tbf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
	struct rtattr *tb[TCA_TBF_PTAB+1];
	struct tc_tbf_qopt *qopt;
	double buffer, mtu;
	double latency;
	SPRINT_BUF(b1);
	SPRINT_BUF(b2);

	if (opt == NULL)
		return 0;

	parse_rtattr_nested(tb, TCA_TBF_PTAB, opt);

	if (tb[TCA_TBF_PARMS] == NULL)
		return -1;

	qopt = RTA_DATA(tb[TCA_TBF_PARMS]);
	if (RTA_PAYLOAD(tb[TCA_TBF_PARMS])  < sizeof(*qopt))
		return -1;
	fprintf(f, "rate %s ", sprint_rate(qopt->rate.rate, b1));
	buffer = tc_calc_xmitsize(qopt->rate.rate, qopt->buffer);
	if (show_details) {
		fprintf(f, "burst %s/%u mpu %s ", sprint_size(buffer, b1),
			1<<qopt->rate.cell_log, sprint_size(qopt->rate.mpu, b2));
	} else {
		fprintf(f, "burst %s ", sprint_size(buffer, b1));
	}
	if (show_raw)
		fprintf(f, "[%08x] ", qopt->buffer);
	if (qopt->peakrate.rate) {
		fprintf(f, "peakrate %s ", sprint_rate(qopt->peakrate.rate, b1));
		if (qopt->mtu || qopt->peakrate.mpu) {
			mtu = tc_calc_xmitsize(qopt->peakrate.rate, qopt->mtu);
			if (show_details) {
				fprintf(f, "mtu %s/%u mpu %s ", sprint_size(mtu, b1),
					1<<qopt->peakrate.cell_log, sprint_size(qopt->peakrate.mpu, b2));
			} else {
				fprintf(f, "minburst %s ", sprint_size(mtu, b1));
			}
			if (show_raw)
				fprintf(f, "[%08x] ", qopt->mtu);
		}
	}

	if (show_raw)
		fprintf(f, "limit %s ", sprint_size(qopt->limit, b1));

	latency = TIME_UNITS_PER_SEC*(qopt->limit/(double)qopt->rate.rate) - tc_core_tick2time(qopt->buffer);
	if (qopt->peakrate.rate) {
		double lat2 = TIME_UNITS_PER_SEC*(qopt->limit/(double)qopt->peakrate.rate) - tc_core_tick2time(qopt->mtu);
		if (lat2 > latency)
			latency = lat2;
	}
	fprintf(f, "lat %s ", sprint_time(latency, b1));

	return 0;
}
Beispiel #9
0
static int esfq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
	struct tc_esfq_qopt *qopt;
	SPRINT_BUF(b1);

	if (opt == NULL)
		return 0;

	if (RTA_PAYLOAD(opt)  < sizeof(*qopt))
		return -1;
	qopt = RTA_DATA(opt);
	fprintf(f, "quantum %s ", sprint_size(qopt->quantum, b1));
	if (show_details) {
		fprintf(f, "limit %up flows %u/%u ",
			qopt->limit, qopt->flows, qopt->divisor);
	}
	if (qopt->perturb_period)
		fprintf(f, "perturb %dsec ", qopt->perturb_period);

		fprintf(f,"hash: ");
	switch(qopt->hash_kind)
	{
	case TCA_SFQ_HASH_CLASSIC:
		fprintf(f,"classic");
		break;
	case TCA_SFQ_HASH_DST:
		fprintf(f,"dst");
		break;
	case TCA_SFQ_HASH_SRC:
		fprintf(f,"src");
		break;
	case TCA_SFQ_HASH_FWMARK:
		fprintf(f,"fwmark");
		break;
	case TCA_SFQ_HASH_CTORIGSRC:
		fprintf(f,"ctorigsrc");
		break;
	case TCA_SFQ_HASH_CTORIGDST:
		fprintf(f,"ctorigdst");
		break;
	case TCA_SFQ_HASH_CTREPLSRC:
		fprintf(f,"ctreplsrc");
		break;
	case TCA_SFQ_HASH_CTREPLDST:
		fprintf(f,"ctrepldst");
		break;
	case TCA_SFQ_HASH_CTNATCHG:
		fprintf(f,"ctnatchg");
		break;
	default:
		fprintf(f,"Unknown");
	}
	return 0;
}
Beispiel #10
0
static int drr_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
{
	struct tc_drr_stats *x;
	SPRINT_BUF(b1);

	if (xstats == NULL)
		return 0;
	if (RTA_PAYLOAD(xstats) < sizeof(*x))
		return -1;
	x = RTA_DATA(xstats);

	fprintf(f, " deficit %s ", sprint_size(x->deficit, b1));
	return 0;
}
Beispiel #11
0
static int drr_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
	struct rtattr *tb[TCA_DRR_MAX + 1];
	SPRINT_BUF(b1);

	if (opt == NULL)
		return 0;

	parse_rtattr_nested(tb, TCA_DRR_MAX, opt);

	if (tb[TCA_DRR_QUANTUM])
		fprintf(f, "quantum %s ",
			sprint_size(*(__u32 *)RTA_DATA(tb[TCA_DRR_QUANTUM]), b1));
	return 0;
}
Beispiel #12
0
static int fifo_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
	struct tc_fifo_qopt *qopt;

	if (opt == NULL)
		return 0;

	if (RTA_PAYLOAD(opt)  < sizeof(*qopt))
		return -1;
	qopt = RTA_DATA(opt);
	if (strcmp(qu->id, "bfifo") == 0) {
		SPRINT_BUF(b1);
		fprintf(f, "limit %s", sprint_size(qopt->limit, b1));
	} else
		fprintf(f, "limit %up", qopt->limit);
	return 0;
}
Beispiel #13
0
static int htb_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
	struct rtattr *tb[TCA_HTB_RTAB+1];
	struct tc_htb_opt *hopt;
	struct tc_htb_glob *gopt;
	double buffer,cbuffer;
	SPRINT_BUF(b1);
	SPRINT_BUF(b2);
	SPRINT_BUF(b3);

	if (opt == NULL)
		return 0;

	memset(tb, 0, sizeof(tb));
	parse_rtattr(tb, TCA_HTB_RTAB, RTA_DATA(opt), RTA_PAYLOAD(opt));

	if (tb[TCA_HTB_PARMS]) {

	    hopt = RTA_DATA(tb[TCA_HTB_PARMS]);
	    if (RTA_PAYLOAD(tb[TCA_HTB_PARMS])  < sizeof(*hopt)) return -1;

		if (!hopt->level) {
			fprintf(f, "prio %d ", (int)hopt->prio);
			if (show_details)
				fprintf(f, "quantum %d ", (int)hopt->quantum);
		}
	    fprintf(f, "rate %s ", sprint_rate(hopt->rate.rate, b1));
	    buffer = ((double)hopt->rate.rate*tc_core_tick2usec(hopt->buffer))/1000000;
	    fprintf(f, "ceil %s ", sprint_rate(hopt->ceil.rate, b1));
	    cbuffer = ((double)hopt->ceil.rate*tc_core_tick2usec(hopt->cbuffer))/1000000;
	    if (show_details) {
		fprintf(f, "burst %s/%u mpu %s overhead %s ",
			sprint_size(buffer, b1),
			1<<hopt->rate.cell_log,
			sprint_size(hopt->rate.mpu&0xFF, b2),
			sprint_size((hopt->rate.mpu>>8)&0xFF, b3));
		fprintf(f, "cburst %s/%u mpu %s overhead %s ",
			sprint_size(cbuffer, b1),
			1<<hopt->ceil.cell_log,
			sprint_size(hopt->ceil.mpu&0xFF, b2),
			sprint_size((hopt->ceil.mpu>>8)&0xFF, b3));
		fprintf(f, "level %d ", (int)hopt->level);
	    } else {
		fprintf(f, "burst %s ", sprint_size(buffer, b1));
		fprintf(f, "cburst %s ", sprint_size(cbuffer, b1));
	    }
	    if (show_raw)
		fprintf(f, "buffer [%08x] cbuffer [%08x] ", 
			hopt->buffer,hopt->cbuffer);
	}
Beispiel #14
0
static int ccnsfq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
	struct tc_ccnsfq_qopt *qopt;
	SPRINT_BUF(b1);

	if (opt == NULL)
		return 0;

	if (RTA_PAYLOAD(opt)  < sizeof(*qopt))
		return -1;
	qopt = RTA_DATA(opt);
	fprintf(f, "limit %up ", qopt->limit);
	fprintf(f, "quantum %s ", sprint_size(qopt->quantum, b1));
	if (show_details) {
		fprintf(f, "flows %u/%u ", qopt->flows, qopt->divisor);
	}
	if (qopt->perturb_period)
		fprintf(f, "perturb %dsec ", qopt->perturb_period);
	return 0;
}
static int wrr_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
	long *qm;
	SPRINT_BUF(b1);

	if (opt == NULL)
		return 0;

	if (RTA_PAYLOAD(opt)  < sizeof(qm))
		return -1;
	qm = RTA_DATA(opt);
	fprintf(f, "quantum %s ", sprint_size(*qm, b1));
/*	if (show_details) {
		fprintf(f, "limit %up flows %u/%u ",
			qopt->limit, qopt->flows, qopt->divisor);
	}
	if (qopt->perturb_period)
		fprintf(f, "perturb %dsec ", qopt->perturb_period);
		*/
	return 0;
}
Beispiel #16
0
void print_tcstats(FILE *fp, struct tc_stats *st)
{
	SPRINT_BUF(b1);

	fprintf(fp, " Sent %llu bytes %u pkts (dropped %u, overlimits %u) ",
		(unsigned long long)st->bytes, st->packets, st->drops, st->overlimits);
	if (st->bps || st->pps || st->qlen || st->backlog) {
		fprintf(fp, "\n ");
		if (st->bps || st->pps) {
			fprintf(fp, "rate ");
			if (st->bps)
				fprintf(fp, "%s ", sprint_rate(st->bps, b1));
			if (st->pps)
				fprintf(fp, "%upps ", st->pps);
		}
		if (st->qlen || st->backlog) {
			fprintf(fp, "backlog ");
			if (st->backlog)
				fprintf(fp, "%s ", sprint_size(st->backlog, b1));
			if (st->qlen)
				fprintf(fp, "%up ", st->qlen);
		}
	}
}
Beispiel #17
0
static int fq_codel_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
	struct rtattr *tb[TCA_FQ_CODEL_MAX + 1];
	unsigned int limit;
	unsigned int flows;
	unsigned int interval;
	unsigned int target;
	unsigned int ecn;
	unsigned int quantum;
	unsigned int ce_threshold;
	unsigned int memory_limit;

	SPRINT_BUF(b1);

	if (opt == NULL)
		return 0;

	parse_rtattr_nested(tb, TCA_FQ_CODEL_MAX, opt);

	if (tb[TCA_FQ_CODEL_LIMIT] &&
	    RTA_PAYLOAD(tb[TCA_FQ_CODEL_LIMIT]) >= sizeof(__u32)) {
		limit = rta_getattr_u32(tb[TCA_FQ_CODEL_LIMIT]);
		print_uint(PRINT_ANY, "limit", "limit %up ", limit);
	}
	if (tb[TCA_FQ_CODEL_FLOWS] &&
	    RTA_PAYLOAD(tb[TCA_FQ_CODEL_FLOWS]) >= sizeof(__u32)) {
		flows = rta_getattr_u32(tb[TCA_FQ_CODEL_FLOWS]);
		print_uint(PRINT_ANY, "flows", "flows %u ", flows);
	}
	if (tb[TCA_FQ_CODEL_QUANTUM] &&
	    RTA_PAYLOAD(tb[TCA_FQ_CODEL_QUANTUM]) >= sizeof(__u32)) {
		quantum = rta_getattr_u32(tb[TCA_FQ_CODEL_QUANTUM]);
		print_uint(PRINT_ANY, "quantum", "quantum %u ", quantum);
	}
	if (tb[TCA_FQ_CODEL_TARGET] &&
	    RTA_PAYLOAD(tb[TCA_FQ_CODEL_TARGET]) >= sizeof(__u32)) {
		target = rta_getattr_u32(tb[TCA_FQ_CODEL_TARGET]);
		print_uint(PRINT_JSON, "target", NULL, target);
		print_string(PRINT_FP, NULL, "target %s ",
			     sprint_time(target, b1));
	}
	if (tb[TCA_FQ_CODEL_CE_THRESHOLD] &&
	    RTA_PAYLOAD(tb[TCA_FQ_CODEL_CE_THRESHOLD]) >= sizeof(__u32)) {
		ce_threshold = rta_getattr_u32(tb[TCA_FQ_CODEL_CE_THRESHOLD]);
		print_uint(PRINT_JSON, "ce_threshold", NULL, ce_threshold);
		print_string(PRINT_FP, NULL, "ce_threshold %s ",
			     sprint_time(ce_threshold, b1));
	}
	if (tb[TCA_FQ_CODEL_INTERVAL] &&
	    RTA_PAYLOAD(tb[TCA_FQ_CODEL_INTERVAL]) >= sizeof(__u32)) {
		interval = rta_getattr_u32(tb[TCA_FQ_CODEL_INTERVAL]);
		print_uint(PRINT_JSON, "interval", NULL, interval);
		print_string(PRINT_FP, NULL, "interval %s ",
			     sprint_time(interval, b1));
	}
	if (tb[TCA_FQ_CODEL_MEMORY_LIMIT] &&
	    RTA_PAYLOAD(tb[TCA_FQ_CODEL_MEMORY_LIMIT]) >= sizeof(__u32)) {
		memory_limit = rta_getattr_u32(tb[TCA_FQ_CODEL_MEMORY_LIMIT]);
		print_uint(PRINT_JSON, "memory_limit", NULL, memory_limit);
		print_string(PRINT_FP, NULL, "memory_limit %s ",
			     sprint_size(memory_limit, b1));
	}
	if (tb[TCA_FQ_CODEL_ECN] &&
	    RTA_PAYLOAD(tb[TCA_FQ_CODEL_ECN]) >= sizeof(__u32)) {
		ecn = rta_getattr_u32(tb[TCA_FQ_CODEL_ECN]);
		if (ecn)
			print_bool(PRINT_ANY, "ecn", "ecn ", true);
	}

	return 0;
}
Beispiel #18
0
static int gred_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
	struct rtattr *tb[TCA_GRED_MAX + 1];
	struct tc_gred_sopt *sopt;
	struct tc_gred_qopt *qopt;
	__u32 *max_p = NULL;
	__u32 *limit = NULL;
	unsigned int i;

	SPRINT_BUF(b1);
	SPRINT_BUF(b2);
	SPRINT_BUF(b3);

	if (opt == NULL)
		return 0;

	parse_rtattr_nested(tb, TCA_GRED_MAX, opt);

	if (tb[TCA_GRED_PARMS] == NULL)
		return -1;

	if (tb[TCA_GRED_MAX_P] &&
	    RTA_PAYLOAD(tb[TCA_GRED_MAX_P]) >= sizeof(__u32) * MAX_DPs)
		max_p = RTA_DATA(tb[TCA_GRED_MAX_P]);

	if (tb[TCA_GRED_LIMIT] &&
	    RTA_PAYLOAD(tb[TCA_GRED_LIMIT]) == sizeof(__u32))
		limit = RTA_DATA(tb[TCA_GRED_LIMIT]);

	sopt = RTA_DATA(tb[TCA_GRED_DPS]);
	qopt = RTA_DATA(tb[TCA_GRED_PARMS]);
	if (RTA_PAYLOAD(tb[TCA_GRED_DPS]) < sizeof(*sopt) ||
	    RTA_PAYLOAD(tb[TCA_GRED_PARMS]) < sizeof(*qopt)*MAX_DPs) {
		fprintf(f, "\n GRED received message smaller than expected\n");
		return -1;
	}

/* Bad hack! should really return a proper message as shown above*/

	fprintf(f, "vqs %u default %u %s",
		sopt->DPs,
		sopt->def_DP,
		sopt->grio ? "grio " : "");

	if (limit)
		fprintf(f, "limit %s ",
			sprint_size(*limit, b1));

	for (i = 0; i < MAX_DPs; i++, qopt++) {
		if (qopt->DP >= MAX_DPs) continue;
		fprintf(f, "\n vq %u prio %hhu limit %s min %s max %s ",
			qopt->DP,
			qopt->prio,
			sprint_size(qopt->limit, b1),
			sprint_size(qopt->qth_min, b2),
			sprint_size(qopt->qth_max, b3));
		if (show_details) {
			fprintf(f, "ewma %u ", qopt->Wlog);
			if (max_p)
				fprintf(f, "probability %lg ", max_p[i] / pow(2, 32));
			else
				fprintf(f, "Plog %u ", qopt->Plog);
			fprintf(f, "Scell_log %u ", qopt->Scell_log);
		}
		if (show_stats) {
			fprintf(f, "\n  Queue size: average %s current %s ",
				sprint_size(qopt->qave, b1),
				sprint_size(qopt->backlog, b2));
			fprintf(f, "\n  Dropped packets: forced %u early %u pdrop %u other %u ",
				qopt->forced,
				qopt->early,
				qopt->pdrop,
				qopt->other);
			fprintf(f, "\n  Total packets: %u (%s) ",
				qopt->packets,
				sprint_size(qopt->bytesin, b1));
		}
	}
	return 0;
}
Beispiel #19
0
bool mf_write_tag_internal(const mf_tag_t* tag,
                           const mf_tag_t* keys,
                           mf_key_type_t key_type) {

  mifare_param mp;
  int error = 0;

  printf("Writing %s tag [", sprint_size(size)); fflush(stdout);

  // Process each sector in turn
  for (int header_block_it = sector_header_iterator(0);
       header_block_it != -1;
       header_block_it = sector_header_iterator(size)) {
    size_t header_block = (size_t)header_block_it;

    // Authenticate
    uint8_t* key = key_from_tag(keys, key_type, header_block);
    if (key_type != MF_KEY_UNLOCKED) {
      if (!mf_authenticate(header_block, key, key_type)) {
        // Progress indication and error report
        if (header_block != 0) printf(".");
        printf("0x%02zx", block_to_sector(header_block));
        fflush(stdout);

        error = 1;
        continue; // Skip the rest of the sector blocks
      }
    }

    // Write the sectors blocks
    for (size_t block = header_block, trailer = block_to_trailer(header_block);
         block < trailer; ++block) {

      // First block on tag is read only - skip it unless unlocked
      if (block == 0 && key_type != MF_KEY_UNLOCKED)
        continue;

      // Try to write the data block
      memcpy (mp.mpd.abtData, tag->amb[block].mbd.abtData, 0x10);

      // do not write a block 0 with incorrect BCC - card will be made invalid!
      if (block == 0) {
        if((mp.mpd.abtData[0] ^ mp.mpd.abtData[1] ^ mp.mpd.abtData[2] ^
            mp.mpd.abtData[3] ^ mp.mpd.abtData[4]) != 0x00) {
          printf ("\nError: incorrect BCC in MFD file!\n"); // ADD DATA
          return false;
        }
      }

      // Write the data block
      if (!nfc_initiator_mifare_cmd(device, MC_WRITE, (uint8_t)block, &mp)) {
        printf("\nUnable to write block: 0x%02zx.\n", block);
        return false;
      }
    }

    // Auth ok and sector read ok, finish up by reading trailer
    size_t trailer_block = block_to_trailer(header_block);
    memcpy (mp.mpd.abtData, tag->amb[trailer_block].mbt.abtKeyA, 6);
    memcpy (mp.mpd.abtData + 6, tag->amb[trailer_block].mbt.abtAccessBits, 4);
    memcpy (mp.mpd.abtData + 10, tag->amb[trailer_block].mbt.abtKeyB, 6);

    // Try to write the trailer
    if (!nfc_initiator_mifare_cmd(device, MC_WRITE, (uint8_t)trailer_block, &mp)) {
      printf("\nUnable to write block: 0x%02zx.\n", trailer_block);
      return false;
    }

    printf("."); fflush(stdout); // Progress indicator
  }

  // Terminate progress indicator
  if (error)
    printf("] Auth errors in indicated sectors.\n");
  else
    printf("] Success!\n");

  return true;
}