Esempio n. 1
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;
}
Esempio n. 2
0
static void vlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{
	struct ifla_vlan_flags *flags;
	SPRINT_BUF(b1);

	if (!tb)
		return;

	if (tb[IFLA_VLAN_PROTOCOL] &&
	    RTA_PAYLOAD(tb[IFLA_VLAN_PROTOCOL]) < sizeof(__u16))
		return;
	if (!tb[IFLA_VLAN_ID] ||
	    RTA_PAYLOAD(tb[IFLA_VLAN_ID]) < sizeof(__u16))
		return;

	if (tb[IFLA_VLAN_PROTOCOL])
		fprintf(f, "protocol %s ",
			ll_proto_n2a(rta_getattr_u16(tb[IFLA_VLAN_PROTOCOL]),
				     b1, sizeof(b1)));
	else
		fprintf(f, "protocol 802.1q ");

	fprintf(f, "id %u ", rta_getattr_u16(tb[IFLA_VLAN_ID]));

	if (tb[IFLA_VLAN_FLAGS]) {
		if (RTA_PAYLOAD(tb[IFLA_VLAN_FLAGS]) < sizeof(*flags))
			return;
		flags = RTA_DATA(tb[IFLA_VLAN_FLAGS]);
		vlan_print_flags(f, flags->flags);
	}
	if (tb[IFLA_VLAN_INGRESS_QOS])
		vlan_print_map(f, "ingress-qos-map", tb[IFLA_VLAN_INGRESS_QOS]);
	if (tb[IFLA_VLAN_EGRESS_QOS])
		vlan_print_map(f, "egress-qos-map", tb[IFLA_VLAN_EGRESS_QOS]);
}
Esempio n. 3
0
static int basic_print_opt(struct filter_util *qu, FILE *f,
			   struct rtattr *opt, __u32 handle)
{
	struct rtattr *tb[TCA_BASIC_MAX+1];

	if (opt == NULL)
		return 0;

	parse_rtattr_nested(tb, TCA_BASIC_MAX, opt);

	if (handle)
		fprintf(f, "handle 0x%x ", handle);

	if (tb[TCA_BASIC_CLASSID]) {
		SPRINT_BUF(b1);
		fprintf(f, "flowid %s ",
			sprint_tc_classid(rta_getattr_u32(tb[TCA_BASIC_CLASSID]), b1));
	}

	if (tb[TCA_BASIC_EMATCHES])
		print_ematch(f, tb[TCA_BASIC_EMATCHES]);

	if (tb[TCA_BASIC_POLICE]) {
		fprintf(f, "\n");
		tc_print_police(f, tb[TCA_BASIC_POLICE]);
	}

	if (tb[TCA_BASIC_ACT]) {
		tc_print_action(f, tb[TCA_BASIC_ACT]);
	}

	return 0;
}
static void bond_slave_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{
	SPRINT_BUF(b1);
	if (!tb)
		return;

	if (tb[IFLA_BOND_SLAVE_STATE])
		print_slave_state(f, tb[IFLA_BOND_SLAVE_STATE]);

	if (tb[IFLA_BOND_SLAVE_MII_STATUS])
		print_slave_mii_status(f, tb[IFLA_BOND_SLAVE_MII_STATUS]);

	if (tb[IFLA_BOND_SLAVE_LINK_FAILURE_COUNT])
		fprintf(f, "link_failure_count %d ",
			rta_getattr_u32(tb[IFLA_BOND_SLAVE_LINK_FAILURE_COUNT]));

	if (tb[IFLA_BOND_SLAVE_PERM_HWADDR])
		fprintf(f, "perm_hwaddr %s ",
			ll_addr_n2a(RTA_DATA(tb[IFLA_BOND_SLAVE_PERM_HWADDR]),
				    RTA_PAYLOAD(tb[IFLA_BOND_SLAVE_PERM_HWADDR]),
				    0, b1, sizeof(b1)));

	if (tb[IFLA_BOND_SLAVE_QUEUE_ID])
		fprintf(f, "queue_id %d ",
			rta_getattr_u16(tb[IFLA_BOND_SLAVE_QUEUE_ID]));

	if (tb[IFLA_BOND_SLAVE_AD_AGGREGATOR_ID])
		fprintf(f, "ad_aggregator_id %d ",
			rta_getattr_u16(tb[IFLA_BOND_SLAVE_AD_AGGREGATOR_ID]));
}
Esempio n. 5
0
static int codel_print_xstats(struct qdisc_util *qu, FILE *f,
			      struct rtattr *xstats)
{
	struct tc_codel_xstats *st;
	SPRINT_BUF(b1);

	if (xstats == NULL)
		return 0;

	if (RTA_PAYLOAD(xstats) < sizeof(*st))
		return -1;

	st = RTA_DATA(xstats);
	fprintf(f, "  count %u lastcount %u ldelay %s",
		st->count, st->lastcount, sprint_time(st->ldelay, b1));
	if (st->dropping)
		fprintf(f, " dropping");
	if (st->drop_next < 0)
		fprintf(f, " drop_next -%s", sprint_time(-st->drop_next, b1));
	else
		fprintf(f, " drop_next %s", sprint_time(st->drop_next, b1));
	fprintf(f, "\n  maxpacket %u ecn_mark %u drop_overlimit %u",
		st->maxpacket, st->ecn_mark, st->drop_overlimit);
	return 0;

}
Esempio n. 6
0
static void print_maddr(FILE *fp, struct ma_info *list)
{
	fprintf(fp, "\t");

	if (list->addr.family == AF_PACKET) {
		SPRINT_BUF(b1);
		fprintf(fp, "link  %s", ll_addr_n2a((unsigned char*)list->addr.data,
						    list->addr.bytelen, 0,
						    b1, sizeof(b1)));
	} else {
		char abuf[256];
		switch(list->addr.family) {
		case AF_INET:
			fprintf(fp, "inet  ");
			break;
		case AF_INET6:
			fprintf(fp, "inet6 ");
			break;
		default:
			fprintf(fp, "family %d ", list->addr.family);
			break;
		}
		fprintf(fp, "%s", 
			format_host(list->addr.family,
				    -1,
				    list->addr.data,
				    abuf, sizeof(abuf)));
	}
	if (list->users != 1)
		fprintf(fp, " users %d", list->users);
	if (list->features)
		fprintf(fp, " %s", list->features);
	fprintf(fp, "\n");
}
static void print_vfinfo(FILE *fp, struct rtattr *vfinfo)
{
	struct ifla_vf_mac *vf_mac;
	struct ifla_vf_vlan *vf_vlan;
	struct ifla_vf_tx_rate *vf_tx_rate;
	struct rtattr *vf[IFLA_VF_MAX+1];
	SPRINT_BUF(b1);

	if (vfinfo->rta_type != IFLA_VF_INFO) {
		fprintf(stderr, "BUG: rta type is %d\n", vfinfo->rta_type);
		return;
	}

	parse_rtattr_nested(vf, IFLA_VF_MAX, vfinfo);

	vf_mac = RTA_DATA(vf[IFLA_VF_MAC]);
	vf_vlan = RTA_DATA(vf[IFLA_VF_VLAN]);
	vf_tx_rate = RTA_DATA(vf[IFLA_VF_TX_RATE]);

	fprintf(fp, "\n    vf %d MAC %s", vf_mac->vf,
		ll_addr_n2a((unsigned char *)&vf_mac->mac,
		ETH_ALEN, 0, b1, sizeof(b1)));
	if (vf_vlan->vlan)
		fprintf(fp, ", vlan %d", vf_vlan->vlan);
	if (vf_vlan->qos)
		fprintf(fp, ", qos %d", vf_vlan->qos);
	if (vf_tx_rate->rate)
		fprintf(fp, ", tx rate %d (Mbps)", vf_tx_rate->rate);
}
Esempio n. 8
0
static int tcindex_print_opt(struct filter_util *qu, FILE *f,
     struct rtattr *opt, __u32 handle)
{
	struct rtattr *tb[TCA_TCINDEX_MAX+1];

	if (opt == NULL)
		return 0;

	parse_rtattr_nested(tb, TCA_TCINDEX_MAX, opt);

	if (handle != ~0) fprintf(f, "handle 0x%04x ", handle);
	if (tb[TCA_TCINDEX_HASH]) {
		__u16 hash;

		if (RTA_PAYLOAD(tb[TCA_TCINDEX_HASH]) < sizeof(hash))
			return -1;
		hash = rta_getattr_u16(tb[TCA_TCINDEX_HASH]);
		fprintf(f, "hash %d ", hash);
	}
	if (tb[TCA_TCINDEX_MASK]) {
		__u16 mask;

		if (RTA_PAYLOAD(tb[TCA_TCINDEX_MASK]) < sizeof(mask))
			return -1;
		mask = rta_getattr_u16(tb[TCA_TCINDEX_MASK]);
		fprintf(f, "mask 0x%04x ", mask);
	}
	if (tb[TCA_TCINDEX_SHIFT]) {
		int shift;

		if (RTA_PAYLOAD(tb[TCA_TCINDEX_SHIFT]) < sizeof(shift))
			return -1;
		shift = *(int *) RTA_DATA(tb[TCA_TCINDEX_SHIFT]);
		fprintf(f, "shift %d ", shift);
	}
	if (tb[TCA_TCINDEX_FALL_THROUGH]) {
		int fall_through;

		if (RTA_PAYLOAD(tb[TCA_TCINDEX_FALL_THROUGH]) <
		    sizeof(fall_through))
			return -1;
		fall_through = *(int *) RTA_DATA(tb[TCA_TCINDEX_FALL_THROUGH]);
		fprintf(f, fall_through ? "fall_through " : "pass_on ");
	}
	if (tb[TCA_TCINDEX_CLASSID]) {
		SPRINT_BUF(b1);
		fprintf(f, "classid %s ", sprint_tc_classid(*(__u32 *)
		    RTA_DATA(tb[TCA_TCINDEX_CLASSID]), b1));
	}
	if (tb[TCA_TCINDEX_POLICE]) {
		fprintf(f, "\n");
		tc_print_police(f, tb[TCA_TCINDEX_POLICE]);
	}
	if (tb[TCA_TCINDEX_ACT]) {
		fprintf(f, "\n");
		tc_print_police(f, tb[TCA_TCINDEX_ACT]);
	}
	return 0;
}
Esempio n. 9
0
static void print_tunnel(struct ip_tunnel_parm *p)
{
	char s1[256];
	char s2[256];
	char s3[64];
	char s4[64];

	format_host(AF_INET, 4, &p->iph.daddr, s1, sizeof(s1));
	format_host(AF_INET, 4, &p->iph.saddr, s2, sizeof(s2));
	inet_ntop(AF_INET, &p->i_key, s3, sizeof(s3));
	inet_ntop(AF_INET, &p->o_key, s4, sizeof(s4));

	printf("%s: %s/ip  remote %s  local %s ",
	       p->name,
	       p->iph.protocol == IPPROTO_IPIP ? "ip" :
	       (p->iph.protocol == IPPROTO_GRE ? "gre" :
		(p->iph.protocol == IPPROTO_IPV6 ? "ipv6" : "unknown")),
	       p->iph.daddr ? s1 : "any", p->iph.saddr ? s2 : "any");
	if (p->link) {
		char *n = do_ioctl_get_ifname(p->link);
		if (n) {
			printf(" dev %s ", n);
			free(n);
		}
	}
	if (p->iph.ttl)
		printf(" ttl %d ", p->iph.ttl);
	else
		printf(" ttl inherit ");
	if (p->iph.tos) {
		SPRINT_BUF(b1);
		printf(" tos");
		if (p->iph.tos & 1)
			printf(" inherit");
		if (p->iph.tos & ~1)
			printf("%c%s ", p->iph.tos & 1 ? '/' : ' ',
			       rtnl_dsfield_n2a(p->iph.tos & ~1, b1, sizeof(b1)));
	}
	if (!(p->iph.frag_off & htons(IP_DF)))
		printf(" nopmtudisc");

	if ((p->i_flags & GRE_KEY) && (p->o_flags & GRE_KEY) && p->o_key == p->i_key)
		printf(" key %s", s3);
	else if ((p->i_flags | p->o_flags) & GRE_KEY) {
		if (p->i_flags & GRE_KEY)
			printf(" ikey %s ", s3);
		if (p->o_flags & GRE_KEY)
			printf(" okey %s ", s4);
	}

	if (p->i_flags & GRE_SEQ)
		printf("%c  Drop packets out of sequence.\n", _SL_);
	if (p->i_flags & GRE_CSUM)
		printf("%c  Checksum in received packet is required.", _SL_);
	if (p->o_flags & GRE_SEQ)
		printf("%c  Sequence packets on output.", _SL_);
	if (p->o_flags & GRE_CSUM)
		printf("%c  Checksum output packets.", _SL_);
}
Esempio n. 10
0
static void print_key(struct rtattr *key)
{
	SPRINT_BUF(keyid);

	print_string(PRINT_ANY, "key", " key %s\n",
		     hexstring_n2a(RTA_DATA(key), RTA_PAYLOAD(key),
				   keyid, sizeof(keyid)));
}
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;
}
Esempio n. 12
0
static int pie_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
	struct rtattr *tb[TCA_PIE_MAX + 1];
	unsigned int limit;
	unsigned int tupdate;
	unsigned int target;
	unsigned int alpha;
	unsigned int beta;
	unsigned ecn;
	unsigned bytemode;
	SPRINT_BUF(b1);

	if (opt == NULL)
		return 0;

	parse_rtattr_nested(tb, TCA_PIE_MAX, opt);

	if (tb[TCA_PIE_LIMIT] &&
	    RTA_PAYLOAD(tb[TCA_PIE_LIMIT]) >= sizeof(__u32)) {
		limit = rta_getattr_u32(tb[TCA_PIE_LIMIT]);
		fprintf(f, "limit %up ", limit);
	}
	if (tb[TCA_PIE_TARGET] &&
	    RTA_PAYLOAD(tb[TCA_PIE_TARGET]) >= sizeof(__u32)) {
		target = rta_getattr_u32(tb[TCA_PIE_TARGET]);
		fprintf(f, "target %s ", sprint_time(target, b1));
	}
	if (tb[TCA_PIE_TUPDATE] &&
	    RTA_PAYLOAD(tb[TCA_PIE_TUPDATE]) >= sizeof(__u32)) {
		tupdate = rta_getattr_u32(tb[TCA_PIE_TUPDATE]);
		fprintf(f, "tupdate %s ", sprint_time(tupdate, b1));
	}
	if (tb[TCA_PIE_ALPHA] &&
	    RTA_PAYLOAD(tb[TCA_PIE_ALPHA]) >= sizeof(__u32)) {
		alpha = rta_getattr_u32(tb[TCA_PIE_ALPHA]);
		fprintf(f, "alpha %u ", alpha);
	}
	if (tb[TCA_PIE_BETA] &&
	    RTA_PAYLOAD(tb[TCA_PIE_BETA]) >= sizeof(__u32)) {
		beta = rta_getattr_u32(tb[TCA_PIE_BETA]);
		fprintf(f, "beta %u ", beta);
	}

	if (tb[TCA_PIE_ECN] && RTA_PAYLOAD(tb[TCA_PIE_ECN]) >= sizeof(__u32)) {
		ecn = rta_getattr_u32(tb[TCA_PIE_ECN]);
		if (ecn)
			fprintf(f, "ecn ");
	}

	if (tb[TCA_PIE_BYTEMODE] &&
	    RTA_PAYLOAD(tb[TCA_PIE_BYTEMODE]) >= sizeof(__u32)) {
		bytemode = rta_getattr_u32(tb[TCA_PIE_BYTEMODE]);
		if (bytemode)
			fprintf(f, "bytemode ");
	}

	return 0;
}
Esempio n. 13
0
int
print_gact(struct action_util *au,FILE * f, struct rtattr *arg)
{
    SPRINT_BUF(b1);
#ifdef CONFIG_GACT_PROB
    SPRINT_BUF(b2);
    struct tc_gact_p *pp = NULL;
    struct tc_gact_p pp_dummy;
#endif
    struct tc_gact *p = NULL;
    struct rtattr *tb[TCA_GACT_MAX + 1];

    if (arg == NULL)
        return -1;

    parse_rtattr_nested(tb, TCA_GACT_MAX, arg);

    if (tb[TCA_GACT_PARMS] == NULL) {
        fprintf(f, "[NULL gact parameters]");
        return -1;
    }
    p = RTA_DATA(tb[TCA_GACT_PARMS]);

    fprintf(f, "gact action %s", action_n2a(p->action, b1, sizeof (b1)));
#ifdef CONFIG_GACT_PROB
    if (NULL != tb[TCA_GACT_PROB]) {
        pp = RTA_DATA(tb[TCA_GACT_PROB]);
    } else {
        /* need to keep consistent output */
        memset(&pp_dummy, 0, sizeof (pp_dummy));
        pp = &pp_dummy;
    }
    fprintf(f, "\n\t random type %s %s val %d",prob_n2a(pp->ptype), action_n2a(pp->paction, b2, sizeof (b2)), pp->pval);
#endif
    fprintf(f, "\n\t index %d ref %d bind %d",p->index, p->refcnt, p->bindcnt);
    if (show_stats) {
        if (tb[TCA_GACT_TM]) {
            struct tcf_t *tm = RTA_DATA(tb[TCA_GACT_TM]);
            print_tm(f,tm);
        }
    }
    fprintf(f, "\n ");
    return 0;
}
Esempio n. 14
0
static void
hfsc_print_sc(FILE *f, char *name, struct tc_service_curve *sc)
{
	SPRINT_BUF(b1);

	fprintf(f, "%s ", name);
	fprintf(f, "m1 %s ", sprint_rate(sc->m1, b1));
	fprintf(f, "d %s ", sprint_time(tc_core_ktime2time(sc->d), b1));
	fprintf(f, "m2 %s ", sprint_rate(sc->m2, b1));
}
Esempio n. 15
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;
}
Esempio n. 16
0
static void hsr_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{
	SPRINT_BUF(b1);

	if (!tb)
		return;

	if (tb[IFLA_HSR_SLAVE1] &&
	    RTA_PAYLOAD(tb[IFLA_HSR_SLAVE1]) < sizeof(__u32))
		return;
	if (tb[IFLA_HSR_SLAVE2] &&
	    RTA_PAYLOAD(tb[IFLA_HSR_SLAVE2]) < sizeof(__u32))
		return;
	if (tb[IFLA_HSR_SEQ_NR] &&
	    RTA_PAYLOAD(tb[IFLA_HSR_SEQ_NR]) < sizeof(__u16))
		return;
	if (tb[IFLA_HSR_SUPERVISION_ADDR] &&
	    RTA_PAYLOAD(tb[IFLA_HSR_SUPERVISION_ADDR]) < ETH_ALEN)
		return;

	if (tb[IFLA_HSR_SLAVE1])
		print_string(PRINT_ANY,
			     "slave1",
			     "slave1 %s ",
			     ll_index_to_name(rta_getattr_u32(tb[IFLA_HSR_SLAVE1])));
	else
		print_null(PRINT_ANY, "slave1", "slave1 %s ", "<none>");

	if (tb[IFLA_HSR_SLAVE2])
		print_string(PRINT_ANY,
			     "slave2",
			     "slave2 %s ",
			     ll_index_to_name(rta_getattr_u32(tb[IFLA_HSR_SLAVE2])));
	else
		print_null(PRINT_ANY, "slave2", "slave2 %s ", "<none>");

	if (tb[IFLA_HSR_SEQ_NR])
		print_int(PRINT_ANY,
			  "seq_nr",
			  "sequence %d ",
			  rta_getattr_u16(tb[IFLA_HSR_SEQ_NR]));

	if (tb[IFLA_HSR_SUPERVISION_ADDR])
		print_string(PRINT_ANY,
			     "supervision_addr",
			     "supervision %s ",
			     ll_addr_n2a(RTA_DATA(tb[IFLA_HSR_SUPERVISION_ADDR]),
					 RTA_PAYLOAD(tb[IFLA_HSR_SUPERVISION_ADDR]),
					 ARPHRD_VOID,
					 b1, sizeof(b1)));
}
Esempio n. 17
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;
}
Esempio n. 18
0
static void print_mdb_entry(FILE *f, int ifindex, struct br_mdb_entry *e)
{
	SPRINT_BUF(abuf);

	if (e->addr.proto == htons(ETH_P_IP))
		fprintf(f, "dev %s port %s grp %s %s\n", ll_index_to_name(ifindex),
			ll_index_to_name(e->ifindex),
			inet_ntop(AF_INET, &e->addr.u.ip4, abuf, sizeof(abuf)),
			(e->state & MDB_PERMANENT) ? "permanent" : "temp");
	else
		fprintf(f, "dev %s port %s grp %s %s\n", ll_index_to_name(ifindex),
			ll_index_to_name(e->ifindex),
			inet_ntop(AF_INET6, &e->addr.u.ip6, abuf, sizeof(abuf)),
			(e->state & MDB_PERMANENT) ? "permanent" : "temp");
}
Esempio n. 19
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;
}
Esempio n. 20
0
/*
 * In JSON context uses hardcode %#x format: 42 -> 0x2a
 */
void print_color_0xhex(enum output_type type,
		       enum color_attr color,
		       const char *key,
		       const char *fmt,
		       unsigned int hex)
{
	if (_IS_JSON_CONTEXT(type)) {
		SPRINT_BUF(b1);

		snprintf(b1, sizeof(b1), "%#x", hex);
		print_string(PRINT_JSON, key, NULL, b1);
	} else if (_IS_FP_CONTEXT(type)) {
		color_fprintf(stdout, color, fmt, hex);
	}
}
Esempio n. 21
0
static int fw_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u32 handle)
{
	struct rtattr *tb[TCA_FW_MAX+1];

	if (opt == NULL)
		return 0;

	parse_rtattr_nested(tb, TCA_FW_MAX, opt);

	if (handle || tb[TCA_FW_MASK]) {
		__u32 mark = 0, mask = 0;
		if(handle)
			mark = handle;
		if(tb[TCA_FW_MASK] &&
		    (mask = *(__u32*)RTA_DATA(tb[TCA_FW_MASK])) != 0xFFFFFFFF)
			fprintf(f, "handle 0x%x/0x%x ", mark, mask);
		else
			fprintf(f, "handle 0x%x ", handle);
	}

	if (tb[TCA_FW_FMASK]) {
		__u32 mask = 0, shift = 0;
		mask = *(__u32*)RTA_DATA(tb[TCA_FW_FMASK]);
		if (tb[TCA_FW_FSHIFT] &&
		    (shift = *(__u32*)RTA_DATA(tb[TCA_FW_FSHIFT])) != 0x0)
			fprintf(f, "mask 0x%x/0x%x ", mask, shift);
		else
			fprintf(f, "mask 0x%x ", mask);
	}

	if (tb[TCA_FW_CLASSID]) {
		SPRINT_BUF(b1);
		fprintf(f, "classid %s ", sprint_tc_classid(*(__u32*)RTA_DATA(tb[TCA_FW_CLASSID]), b1));
	}

	if (tb[TCA_FW_POLICE])
		tc_print_police(f, tb[TCA_FW_POLICE]);
	if (tb[TCA_FW_INDEV]) {
		struct rtattr *idev = tb[TCA_FW_INDEV];
		fprintf(f, "input dev %s ",(char *)RTA_DATA(idev));
	}

	if (tb[TCA_FW_ACT]) {
		fprintf(f, "\n");
		tc_print_action(f, tb[TCA_FW_ACT]);
	}
	return 0;
}
Esempio n. 22
0
static void print_vfinfo(FILE *fp, struct rtattr *vfinfo)
{
	struct ifla_vf_mac *vf_mac;
	struct ifla_vf_vlan *vf_vlan;
	struct ifla_vf_tx_rate *vf_tx_rate;
	struct ifla_vf_spoofchk *vf_spoofchk;
	struct rtattr *vf[IFLA_VF_MAX+1];
	struct rtattr *tmp;
	SPRINT_BUF(b1);

	if (vfinfo->rta_type != IFLA_VF_INFO) {
		fprintf(stderr, "BUG: rta type is %d\n", vfinfo->rta_type);
		return;
	}

	parse_rtattr_nested(vf, IFLA_VF_MAX, vfinfo);

	vf_mac = RTA_DATA(vf[IFLA_VF_MAC]);
	vf_vlan = RTA_DATA(vf[IFLA_VF_VLAN]);
	vf_tx_rate = RTA_DATA(vf[IFLA_VF_TX_RATE]);

	/* Check if the spoof checking vf info type is supported by
	 * this kernel.
	 */
	tmp = (struct rtattr *)((char *)vf[IFLA_VF_TX_RATE] +
			vf[IFLA_VF_TX_RATE]->rta_len);

	if (tmp->rta_type != IFLA_VF_SPOOFCHK)
		vf_spoofchk = NULL;
	else
		vf_spoofchk = RTA_DATA(vf[IFLA_VF_SPOOFCHK]);

	fprintf(fp, "\n    vf %d MAC %s", vf_mac->vf,
		ll_addr_n2a((unsigned char *)&vf_mac->mac,
		ETH_ALEN, 0, b1, sizeof(b1)));
	if (vf_vlan->vlan)
		fprintf(fp, ", vlan %d", vf_vlan->vlan);
	if (vf_vlan->qos)
		fprintf(fp, ", qos %d", vf_vlan->qos);
	if (vf_tx_rate->rate)
		fprintf(fp, ", tx rate %d (Mbps)", vf_tx_rate->rate);
	if (vf_spoofchk && vf_spoofchk->setting != -1) {
		if (vf_spoofchk->setting)
			fprintf(fp, ", spoof checking on");
		else
			fprintf(fp, ", spoof checking off");
	}
}
Esempio n. 23
0
static int bpf_print_opt(struct action_util *au, FILE *f, struct rtattr *arg)
{
	struct rtattr *tb[TCA_ACT_BPF_MAX + 1];
	struct tc_act_bpf *parm;

	SPRINT_BUF(action_buf);

	if (arg == NULL)
		return -1;

	parse_rtattr_nested(tb, TCA_ACT_BPF_MAX, arg);

	if (!tb[TCA_ACT_BPF_PARMS]) {
		fprintf(f, "[NULL bpf parameters]");
		return -1;
	}

	parm = RTA_DATA(tb[TCA_ACT_BPF_PARMS]);
	fprintf(f, "bpf ");

	if (tb[TCA_ACT_BPF_NAME])
		fprintf(f, "%s ", rta_getattr_str(tb[TCA_ACT_BPF_NAME]));
	else if (tb[TCA_ACT_BPF_FD])
		fprintf(f, "pfd %u ", rta_getattr_u32(tb[TCA_ACT_BPF_FD]));

	if (tb[TCA_ACT_BPF_OPS] && tb[TCA_ACT_BPF_OPS_LEN]) {
		bpf_print_ops(f, tb[TCA_ACT_BPF_OPS],
			      rta_getattr_u16(tb[TCA_ACT_BPF_OPS_LEN]));
		fprintf(f, " ");
	}

	fprintf(f, "default-action %s\n", action_n2a(parm->action, action_buf,
		sizeof(action_buf)));
	fprintf(f, "\tindex %d ref %d bind %d", parm->index, parm->refcnt,
		parm->bindcnt);

	if (show_stats) {
		if (tb[TCA_ACT_BPF_TM]) {
			struct tcf_t *tm = RTA_DATA(tb[TCA_ACT_BPF_TM]);

			print_tm(f, tm);
		}
	}

	fprintf(f, "\n ");
	return 0;
}
Esempio n. 24
0
File: utils.c Progetto: dtaht/tc-adv
unsigned int print_name_and_link(const char *fmt,
				 const char *name, struct rtattr *tb[])
{
	const char *link = NULL;
	unsigned int m_flag = 0;
	SPRINT_BUF(b1);

	if (tb[IFLA_LINK]) {
		int iflink = rta_getattr_u32(tb[IFLA_LINK]);

		if (iflink) {
			if (tb[IFLA_LINK_NETNSID]) {
				if (is_json_context()) {
					print_int(PRINT_JSON,
						  "link_index", NULL, iflink);
				} else {
					link = ll_idx_n2a(iflink);
				}
			} else {
				link = ll_index_to_name(iflink);

				if (is_json_context()) {
					print_string(PRINT_JSON,
						     "link", NULL, link);
					link = NULL;
				}

				m_flag = ll_index_to_flags(iflink);
				m_flag = !(m_flag & IFF_UP);
			}
		} else {
			if (is_json_context())
				print_null(PRINT_JSON, "link", NULL, NULL);
			else
				link = "NONE";
		}

		if (link) {
			snprintf(b1, sizeof(b1), "%s@%s", name, link);
			name = b1;
		}
	}

	print_color_string(PRINT_ANY, COLOR_IFNAME, "ifname", fmt, name);

	return m_flag;
}
int
print_police(struct action_util *a, FILE *f, struct rtattr *arg)
{
	SPRINT_BUF(b1);
	struct tc_police *p;
	struct rtattr *tb[TCA_POLICE_MAX+1];
	unsigned buffer;

	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(*(__u32*)RTA_DATA(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);
	fprintf(f, "\nref %d bind %d\n",p->refcnt, p->bindcnt);

	return 0;
}
Esempio n. 26
0
int
print_pedit(struct action_util *au,FILE * f, struct rtattr *arg)
{
	struct tc_pedit_sel *sel;
	struct rtattr *tb[TCA_PEDIT_MAX + 1];
	SPRINT_BUF(b1);

	if (arg == NULL)
		return -1;

	parse_rtattr_nested(tb, TCA_PEDIT_MAX, arg);

	if (tb[TCA_PEDIT_PARMS] == NULL) {
		fprintf(f, "[NULL pedit parameters]");
		return -1;
	}
	sel = RTA_DATA(tb[TCA_PEDIT_PARMS]);

	fprintf(f, " pedit action %s keys %d\n ", action_n2a(sel->action, b1, sizeof (b1)),sel->nkeys);
	fprintf(f, "\t index %d ref %d bind %d", sel->index,sel->refcnt, sel->bindcnt);

	if (show_stats) {
		if (tb[TCA_PEDIT_TM]) {
			struct tcf_t *tm = RTA_DATA(tb[TCA_PEDIT_TM]);
			print_tm(f,tm);
		}
	}
	if (sel->nkeys) {
		int i;
		struct tc_pedit_key *key = sel->keys;

		for (i=0; i<sel->nkeys; i++, key++) {
			fprintf(f, "\n\t key #%d",i);
			fprintf(f, "  at %d: val %08x mask %08x",
			(unsigned int)key->off,
			(unsigned int)ntohl(key->val),
			(unsigned int)ntohl(key->mask));
		}
	} else {
		fprintf(f, "\npedit %x keys %d is not LEGIT", sel->index,sel->nkeys);
	}


	fprintf(f, "\n ");
	return 0;
}
Esempio n. 27
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;
}
Esempio n. 28
0
static int print_skbedit(struct action_util *au, FILE *f, struct rtattr *arg)
{
	struct tc_skbedit *sel;
	struct rtattr *tb[TCA_SKBEDIT_MAX + 1];
	SPRINT_BUF(b1);
	__u32 *priority;
	__u32 *mark;
	__u16 *queue_mapping;

	if (arg == NULL)
		return -1;

	parse_rtattr_nested(tb, TCA_SKBEDIT_MAX, arg);

	if (tb[TCA_SKBEDIT_PARMS] == NULL) {
		fprintf(f, "[NULL skbedit parameters]");
		return -1;
	}

	sel = RTA_DATA(tb[TCA_SKBEDIT_PARMS]);

	fprintf(f, " skbedit");

	if (tb[TCA_SKBEDIT_QUEUE_MAPPING] != NULL) {
		queue_mapping = RTA_DATA(tb[TCA_SKBEDIT_QUEUE_MAPPING]);
		fprintf(f, " queue_mapping %u", *queue_mapping);
	}
	if (tb[TCA_SKBEDIT_PRIORITY] != NULL) {
		priority = RTA_DATA(tb[TCA_SKBEDIT_PRIORITY]);
		fprintf(f, " priority %s", sprint_tc_classid(*priority, b1));
	}
	if (tb[TCA_SKBEDIT_MARK] != NULL) {
		mark = RTA_DATA(tb[TCA_SKBEDIT_MARK]);
		fprintf(f, " mark %d", *mark);
	}

	if (show_stats) {
		if (tb[TCA_SKBEDIT_TM]) {
			struct tcf_t *tm = RTA_DATA(tb[TCA_SKBEDIT_TM]);
			print_tm(f, tm);
		}
	}

	return 0;
}
Esempio n. 29
0
static int codel_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
	struct rtattr *tb[TCA_CODEL_MAX + 1];
	unsigned int limit;
	unsigned int interval;
	unsigned int target;
	unsigned int ecn;
	unsigned int ce_threshold;

	SPRINT_BUF(b1);

	if (opt == NULL)
		return 0;

	parse_rtattr_nested(tb, TCA_CODEL_MAX, opt);

	if (tb[TCA_CODEL_LIMIT] &&
	    RTA_PAYLOAD(tb[TCA_CODEL_LIMIT]) >= sizeof(__u32)) {
		limit = rta_getattr_u32(tb[TCA_CODEL_LIMIT]);
		fprintf(f, "limit %up ", limit);
	}
	if (tb[TCA_CODEL_TARGET] &&
	    RTA_PAYLOAD(tb[TCA_CODEL_TARGET]) >= sizeof(__u32)) {
		target = rta_getattr_u32(tb[TCA_CODEL_TARGET]);
		fprintf(f, "target %s ", sprint_time(target, b1));
	}
	if (tb[TCA_CODEL_CE_THRESHOLD] &&
	    RTA_PAYLOAD(tb[TCA_CODEL_CE_THRESHOLD]) >= sizeof(__u32)) {
		ce_threshold = rta_getattr_u32(tb[TCA_CODEL_CE_THRESHOLD]);
		fprintf(f, "ce_threshold %s ", sprint_time(ce_threshold, b1));
	}
	if (tb[TCA_CODEL_INTERVAL] &&
	    RTA_PAYLOAD(tb[TCA_CODEL_INTERVAL]) >= sizeof(__u32)) {
		interval = rta_getattr_u32(tb[TCA_CODEL_INTERVAL]);
		fprintf(f, "interval %s ", sprint_time(interval, b1));
	}
	if (tb[TCA_CODEL_ECN] &&
	    RTA_PAYLOAD(tb[TCA_CODEL_ECN]) >= sizeof(__u32)) {
		ecn = rta_getattr_u32(tb[TCA_CODEL_ECN]);
		if (ecn)
			fprintf(f, "ecn ");
	}

	return 0;
}
Esempio n. 30
0
void print_color_hex(enum output_type type,
		     enum color_attr color,
		     const char *key,
		     const char *fmt,
		     unsigned int hex)
{
	if (_IS_JSON_CONTEXT(type)) {
		SPRINT_BUF(b1);

		snprintf(b1, sizeof(b1), "%x", hex);
		if (key)
			jsonw_string_field(_jw, key, b1);
		else
			jsonw_string(_jw, b1);
	} else if (_IS_FP_CONTEXT(type)) {
		color_fprintf(stdout, color, fmt, hex);
	}
}