Exemplo n.º 1
0
static int
print_gact(struct action_util *au, FILE * f, struct rtattr *arg)
{
#ifdef CONFIG_GACT_PROB
	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 ");
	print_action_control(f, "action ", p->action, "");
#ifdef CONFIG_GACT_PROB
	if (tb[TCA_GACT_PROB] != NULL) {
		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", prob_n2a(pp->ptype));
	print_action_control(f, " ", pp->paction, " ");
	fprintf(f, "val %d", pp->pval);
#endif
	fprintf(f, "\n\t index %u 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;
}
Exemplo n.º 2
0
static int
print_mirred(struct action_util *au, FILE *f, struct rtattr *arg)
{
	struct tc_mirred *p;
	struct rtattr *tb[TCA_MIRRED_MAX + 1];
	const char *dev;

	if (arg == NULL)
		return -1;

	parse_rtattr_nested(tb, TCA_MIRRED_MAX, arg);

	if (tb[TCA_MIRRED_PARMS] == NULL) {
		print_string(PRINT_FP, NULL, "%s", "[NULL mirred parameters]");
		return -1;
	}
	p = RTA_DATA(tb[TCA_MIRRED_PARMS]);

	dev = ll_index_to_name(p->ifindex);
	if (dev == 0) {
		fprintf(stderr, "Cannot find device %d\n", p->ifindex);
		return -1;
	}

	print_string(PRINT_ANY, "kind", "%s ", "mirred");
	print_string(PRINT_FP, NULL, "(%s", mirred_n2a(p->eaction));
	print_string(PRINT_JSON, "mirred_action", NULL,
		     mirred_action(p->eaction));
	print_string(PRINT_JSON, "direction", NULL,
		     mirred_direction(p->eaction));
	print_string(PRINT_ANY, "to_dev", " to device %s)", dev);
	print_action_control(f, " ", p->action, "");

	print_uint(PRINT_ANY, "index", "\n \tindex %u", p->index);
	print_int(PRINT_ANY, "ref", " ref %d", p->refcnt);
	print_int(PRINT_ANY, "bind", " bind %d", p->bindcnt);

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

			print_tm(f, tm);
		}
	}
	print_string(PRINT_FP, NULL, "%s", "\n ");
	return 0;
}
Exemplo n.º 3
0
static int print_connmark(struct action_util *au, FILE *f, struct rtattr *arg)
{
	struct rtattr *tb[TCA_CONNMARK_MAX + 1];
	struct tc_connmark *ci;

	if (arg == NULL)
		return -1;

	parse_rtattr_nested(tb, TCA_CONNMARK_MAX, arg);
	if (tb[TCA_CONNMARK_PARMS] == NULL) {
		print_string(PRINT_FP, NULL, "%s", "[NULL connmark parameters]");
		return -1;
	}

	ci = RTA_DATA(tb[TCA_CONNMARK_PARMS]);

	print_string(PRINT_ANY, "kind", "%s ", "connmark");
	print_uint(PRINT_ANY, "zone", "zone %u", ci->zone);
	print_action_control(f, " ", ci->action, "");

	print_string(PRINT_FP, NULL, "%s", _SL_);
	print_uint(PRINT_ANY, "index", "\t index %u", ci->index);
	print_int(PRINT_ANY, "ref", " ref %d", ci->refcnt);
	print_int(PRINT_ANY, "bind", " bind %d", ci->bindcnt);

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

			print_tm(f, tm);
		}
	}
	print_string(PRINT_FP, NULL, "%s", _SL_);

	return 0;
}
Exemplo n.º 4
0
static int print_pedit(struct action_util *au, FILE *f, struct rtattr *arg)
{
	struct tc_pedit_sel *sel;
	struct rtattr *tb[TCA_PEDIT_MAX + 1];
	struct m_pedit_key_ex *keys_ex = NULL;

	if (arg == NULL)
		return -1;

	parse_rtattr_nested(tb, TCA_PEDIT_MAX, arg);

	if (!tb[TCA_PEDIT_PARMS] && !tb[TCA_PEDIT_PARMS_EX]) {
		fprintf(f, "[NULL pedit parameters]");
		return -1;
	}

	if (tb[TCA_PEDIT_PARMS]) {
		sel = RTA_DATA(tb[TCA_PEDIT_PARMS]);
	} else {
		int err;

		sel = RTA_DATA(tb[TCA_PEDIT_PARMS_EX]);

		if (!tb[TCA_PEDIT_KEYS_EX]) {
			fprintf(f, "Netlink error\n");
			return -1;
		}

		keys_ex = calloc(sel->nkeys, sizeof(*keys_ex));
		if (!keys_ex) {
			fprintf(f, "Out of memory\n");
			return -1;
		}

		err = pedit_keys_ex_getattr(tb[TCA_PEDIT_KEYS_EX], keys_ex,
					    sel->nkeys);
		if (err) {
			fprintf(f, "Netlink error\n");

			free(keys_ex);
			return -1;
		}
	}

	fprintf(f, " pedit ");
	print_action_control(f, "action ", sel->action, " ");
	fprintf(f,"keys %d\n ", sel->nkeys);
	fprintf(f, "\t index %u 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;
		struct m_pedit_key_ex *key_ex = keys_ex;

		for (i = 0; i < sel->nkeys; i++, key++) {
			enum pedit_header_type htype =
				TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK;
			enum pedit_cmd cmd = TCA_PEDIT_KEY_EX_CMD_SET;

			if (keys_ex) {
				htype = key_ex->htype;
				cmd = key_ex->cmd;

				key_ex++;
			}

			fprintf(f, "\n\t key #%d", i);

			fprintf(f, "  at ");

			print_pedit_location(f, htype, key->off);

			fprintf(f, ": %s %08x mask %08x",
				cmd ? "add" : "val",
				(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 ");

	free(keys_ex);
	return 0;
}
Exemplo n.º 5
0
static int print_skbedit(struct action_util *au, FILE *f, struct rtattr *arg)
{
	struct rtattr *tb[TCA_SKBEDIT_MAX + 1];

	SPRINT_BUF(b1);
	__u32 *priority;
	__u32 *mark;
	__u16 *queue_mapping, *ptype;
	struct tc_skbedit *p = NULL;

	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;
	}
	p = 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 (tb[TCA_SKBEDIT_PTYPE] != NULL) {
		ptype = RTA_DATA(tb[TCA_SKBEDIT_PTYPE]);
		if (*ptype == PACKET_HOST)
			fprintf(f, " ptype host");
		else if (*ptype == PACKET_BROADCAST)
			fprintf(f, " ptype broadcast");
		else if (*ptype == PACKET_MULTICAST)
			fprintf(f, " ptype multicast");
		else if (*ptype == PACKET_OTHERHOST)
			fprintf(f, " ptype otherhost");
		else
			fprintf(f, " ptype %d", *ptype);
	}

	print_action_control(f, " ", p->action, "");

	fprintf(f, "\n\t index %u ref %d bind %d",
		p->index, p->refcnt, p->bindcnt);

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

			print_tm(f, tm);
		}
	}

	fprintf(f, "\n ");

	return 0;
}
Exemplo n.º 6
0
static int print_ife(struct action_util *au, FILE *f, struct rtattr *arg)
{
	struct tc_ife *p = NULL;
	struct rtattr *tb[TCA_IFE_MAX + 1];
	__u16 ife_type = 0;
	__u32 mmark = 0;
	__u16 mtcindex = 0;
	__u32 mprio = 0;
	int has_optional = 0;
	SPRINT_BUF(b2);

	if (arg == NULL)
		return -1;

	parse_rtattr_nested(tb, TCA_IFE_MAX, arg);

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

	fprintf(f, "ife %s ", p->flags & IFE_ENCODE ? "encode" : "decode");
	print_action_control(f, "action ", p->action, " ");

	if (tb[TCA_IFE_TYPE]) {
		ife_type = rta_getattr_u16(tb[TCA_IFE_TYPE]);
		has_optional = 1;
		fprintf(f, "type 0x%X ", ife_type);
	}

	if (has_optional)
		fprintf(f, "\n\t ");

	if (tb[TCA_IFE_METALST]) {
		struct rtattr *metalist[IFE_META_MAX + 1];
		int len = 0;

		parse_rtattr_nested(metalist, IFE_META_MAX,
				    tb[TCA_IFE_METALST]);

		if (metalist[IFE_META_SKBMARK]) {
			len = RTA_PAYLOAD(metalist[IFE_META_SKBMARK]);
			if (len) {
				mmark = rta_getattr_u32(metalist[IFE_META_SKBMARK]);
				fprintf(f, "use mark %u ", mmark);
			} else
				fprintf(f, "allow mark ");
		}

		if (metalist[IFE_META_TCINDEX]) {
			len = RTA_PAYLOAD(metalist[IFE_META_TCINDEX]);
			if (len) {
				mtcindex =
					rta_getattr_u16(metalist[IFE_META_TCINDEX]);
				fprintf(f, "use tcindex %d ", mtcindex);
			} else
				fprintf(f, "allow tcindex ");
		}

		if (metalist[IFE_META_PRIO]) {
			len = RTA_PAYLOAD(metalist[IFE_META_PRIO]);
			if (len) {
				mprio = rta_getattr_u32(metalist[IFE_META_PRIO]);
				fprintf(f, "use prio %u ", mprio);
			} else
				fprintf(f, "allow prio ");
		}

	}

	if (tb[TCA_IFE_DMAC]) {
		has_optional = 1;
		fprintf(f, "dst %s ",
			ll_addr_n2a(RTA_DATA(tb[TCA_IFE_DMAC]),
				    RTA_PAYLOAD(tb[TCA_IFE_DMAC]), 0, b2,
				    sizeof(b2)));

	}

	if (tb[TCA_IFE_SMAC]) {
		has_optional = 1;
		fprintf(f, "src %s ",
			ll_addr_n2a(RTA_DATA(tb[TCA_IFE_SMAC]),
				    RTA_PAYLOAD(tb[TCA_IFE_SMAC]), 0, b2,
				    sizeof(b2)));
	}

	fprintf(f, "\n\t index %u ref %d bind %d", p->index, p->refcnt,
		p->bindcnt);
	if (show_stats) {
		if (tb[TCA_IFE_TM]) {
			struct tcf_t *tm = RTA_DATA(tb[TCA_IFE_TM]);

			print_tm(f, tm);
		}
	}

	fprintf(f, "\n");

	return 0;
}