Beispiel #1
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;
}
Beispiel #2
0
static int cgroup_print_opt(struct filter_util *qu, FILE *f,
			   struct rtattr *opt, __u32 handle)
{
	struct rtattr *tb[TCA_CGROUP_MAX+1];

	if (opt == NULL)
		return 0;

	parse_rtattr_nested(tb, TCA_CGROUP_MAX, opt);

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

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

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

	if (tb[TCA_CGROUP_ACT])
		tc_print_action(f, tb[TCA_CGROUP_ACT]);

	return 0;
}
Beispiel #3
0
static int flow_print_opt(struct filter_util *fu, FILE *f, struct rtattr *opt,
			  __u32 handle)
{
	struct rtattr *tb[TCA_FLOW_MAX+1];
	SPRINT_BUF(b1);
	unsigned int i;
	__u32 mask = ~0, val = 0;

	if (opt == NULL)
		return -EINVAL;

	parse_rtattr_nested(tb, TCA_FLOW_MAX, opt);

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

	if (tb[TCA_FLOW_MODE]) {
		__u32 mode = *(__u32 *)RTA_DATA(tb[TCA_FLOW_MODE]);

		switch (mode) {
		case FLOW_MODE_MAP:
			fprintf(f, "map ");
			break;
		case FLOW_MODE_HASH:
			fprintf(f, "hash ");
			break;
		}
	}

	if (tb[TCA_FLOW_KEYS]) {
		__u32 keymask = *(__u32 *)RTA_DATA(tb[TCA_FLOW_KEYS]);
		char *sep = "";

		fprintf(f, "keys ");
		for (i = 0; i <= FLOW_KEY_MAX; i++) {
			if (keymask & (1 << i)) {
				fprintf(f, "%s%s", sep, flow_keys[i]);
				sep = ",";
			}
		}
		fprintf(f, " ");
	}

	if (tb[TCA_FLOW_MASK])
		mask = *(__u32 *)RTA_DATA(tb[TCA_FLOW_MASK]);
	if (tb[TCA_FLOW_XOR])
		val = *(__u32 *)RTA_DATA(tb[TCA_FLOW_XOR]);

	if (mask != ~0 || val != 0) {
		__u32 or = (mask & val) ^ val;
		__u32 xor = mask & val;

		if (mask != ~0)
			fprintf(f, "and 0x%.8x ", mask);
		if (xor != 0)
			fprintf(f, "xor 0x%.8x ", xor);
		if (or != 0)
			fprintf(f, "or 0x%.8x ", or);
	}

	if (tb[TCA_FLOW_RSHIFT])
		fprintf(f, "rshift %u ",
			*(__u32 *)RTA_DATA(tb[TCA_FLOW_RSHIFT]));
	if (tb[TCA_FLOW_ADDEND])
		fprintf(f, "addend 0x%x ",
			*(__u32 *)RTA_DATA(tb[TCA_FLOW_ADDEND]));

	if (tb[TCA_FLOW_DIVISOR])
		fprintf(f, "divisor %u ",
			*(__u32 *)RTA_DATA(tb[TCA_FLOW_DIVISOR]));
	if (tb[TCA_FLOW_BASECLASS])
		fprintf(f, "baseclass %s ",
			sprint_tc_classid(*(__u32 *)RTA_DATA(tb[TCA_FLOW_BASECLASS]), b1));

	if (tb[TCA_FLOW_PERTURB])
		fprintf(f, "perturb %usec ",
			*(__u32 *)RTA_DATA(tb[TCA_FLOW_PERTURB]));

	if (tb[TCA_FLOW_EMATCHES])
		print_ematch(f, tb[TCA_FLOW_EMATCHES]);
	if (tb[TCA_FLOW_POLICE])
		tc_print_police(f, tb[TCA_FLOW_POLICE]);
	if (tb[TCA_FLOW_ACT]) {
		fprintf(f, "\n");
		tc_print_action(f, tb[TCA_FLOW_ACT]);
	}
	return 0;
}