Blame extensions/libxt_physdev.c

Packit Service d1fe03
#include <stdio.h>
Packit Service d1fe03
#include <xtables.h>
Packit Service d1fe03
#include <linux/netfilter/xt_physdev.h>
Packit Service d1fe03
Packit Service d1fe03
enum {
Packit Service d1fe03
	O_PHYSDEV_IN = 0,
Packit Service d1fe03
	O_PHYSDEV_OUT,
Packit Service d1fe03
	O_PHYSDEV_IS_IN,
Packit Service d1fe03
	O_PHYSDEV_IS_OUT,
Packit Service d1fe03
	O_PHYSDEV_IS_BRIDGED,
Packit Service d1fe03
};
Packit Service d1fe03
Packit Service d1fe03
static void physdev_help(void)
Packit Service d1fe03
{
Packit Service d1fe03
	printf(
Packit Service d1fe03
"physdev match options:\n"
Packit Service d1fe03
" [!] --physdev-in inputname[+]		bridge port name ([+] for wildcard)\n"
Packit Service d1fe03
" [!] --physdev-out outputname[+]	bridge port name ([+] for wildcard)\n"
Packit Service d1fe03
" [!] --physdev-is-in			arrived on a bridge device\n"
Packit Service d1fe03
" [!] --physdev-is-out			will leave on a bridge device\n"
Packit Service d1fe03
" [!] --physdev-is-bridged		it's a bridged packet\n");
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
#define s struct xt_physdev_info
Packit Service d1fe03
static const struct xt_option_entry physdev_opts[] = {
Packit Service d1fe03
	{.name = "physdev-in", .id = O_PHYSDEV_IN, .type = XTTYPE_STRING,
Packit Service d1fe03
	 .flags = XTOPT_INVERT | XTOPT_PUT, XTOPT_POINTER(s, physindev)},
Packit Service d1fe03
	{.name = "physdev-out", .id = O_PHYSDEV_OUT, .type = XTTYPE_STRING,
Packit Service d1fe03
	 .flags = XTOPT_INVERT | XTOPT_PUT, XTOPT_POINTER(s, physoutdev)},
Packit Service d1fe03
	{.name = "physdev-is-in", .id = O_PHYSDEV_IS_IN, .type = XTTYPE_NONE,
Packit Service d1fe03
	 .flags = XTOPT_INVERT},
Packit Service d1fe03
	{.name = "physdev-is-out", .id = O_PHYSDEV_IS_OUT,
Packit Service d1fe03
	 .type = XTTYPE_NONE, .flags = XTOPT_INVERT},
Packit Service d1fe03
	{.name = "physdev-is-bridged", .id = O_PHYSDEV_IS_BRIDGED,
Packit Service d1fe03
	 .type = XTTYPE_NONE, .flags = XTOPT_INVERT},
Packit Service d1fe03
	XTOPT_TABLEEND,
Packit Service d1fe03
};
Packit Service d1fe03
#undef s
Packit Service d1fe03
Packit Service d1fe03
static void physdev_parse(struct xt_option_call *cb)
Packit Service d1fe03
{
Packit Service d1fe03
	struct xt_physdev_info *info = cb->data;
Packit Service d1fe03
Packit Service d1fe03
	xtables_option_parse(cb);
Packit Service d1fe03
	switch (cb->entry->id) {
Packit Service d1fe03
	case O_PHYSDEV_IN:
Packit Service d1fe03
		xtables_parse_interface(cb->arg, info->physindev,
Packit Service d1fe03
				(unsigned char *)info->in_mask);
Packit Service d1fe03
		if (cb->invert)
Packit Service d1fe03
			info->invert |= XT_PHYSDEV_OP_IN;
Packit Service d1fe03
		info->bitmask |= XT_PHYSDEV_OP_IN;
Packit Service d1fe03
		break;
Packit Service d1fe03
	case O_PHYSDEV_OUT:
Packit Service d1fe03
		xtables_parse_interface(cb->arg, info->physoutdev,
Packit Service d1fe03
				(unsigned char *)info->out_mask);
Packit Service d1fe03
		if (cb->invert)
Packit Service d1fe03
			info->invert |= XT_PHYSDEV_OP_OUT;
Packit Service d1fe03
		info->bitmask |= XT_PHYSDEV_OP_OUT;
Packit Service d1fe03
		break;
Packit Service d1fe03
	case O_PHYSDEV_IS_IN:
Packit Service d1fe03
		info->bitmask |= XT_PHYSDEV_OP_ISIN;
Packit Service d1fe03
		if (cb->invert)
Packit Service d1fe03
			info->invert |= XT_PHYSDEV_OP_ISIN;
Packit Service d1fe03
		break;
Packit Service d1fe03
	case O_PHYSDEV_IS_OUT:
Packit Service d1fe03
		info->bitmask |= XT_PHYSDEV_OP_ISOUT;
Packit Service d1fe03
		if (cb->invert)
Packit Service d1fe03
			info->invert |= XT_PHYSDEV_OP_ISOUT;
Packit Service d1fe03
		break;
Packit Service d1fe03
	case O_PHYSDEV_IS_BRIDGED:
Packit Service d1fe03
		if (cb->invert)
Packit Service d1fe03
			info->invert |= XT_PHYSDEV_OP_BRIDGED;
Packit Service d1fe03
		info->bitmask |= XT_PHYSDEV_OP_BRIDGED;
Packit Service d1fe03
		break;
Packit Service d1fe03
	}
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static void physdev_check(struct xt_fcheck_call *cb)
Packit Service d1fe03
{
Packit Service d1fe03
	if (cb->xflags == 0)
Packit Service d1fe03
		xtables_error(PARAMETER_PROBLEM, "PHYSDEV: no physdev option specified");
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static void
Packit Service d1fe03
physdev_print(const void *ip, const struct xt_entry_match *match, int numeric)
Packit Service d1fe03
{
Packit Service d1fe03
	const struct xt_physdev_info *info = (const void *)match->data;
Packit Service d1fe03
Packit Service d1fe03
	printf(" PHYSDEV match");
Packit Service d1fe03
	if (info->bitmask & XT_PHYSDEV_OP_ISIN)
Packit Service d1fe03
		printf("%s --physdev-is-in",
Packit Service d1fe03
		       info->invert & XT_PHYSDEV_OP_ISIN ? " !":"");
Packit Service d1fe03
	if (info->bitmask & XT_PHYSDEV_OP_IN)
Packit Service d1fe03
		printf("%s --physdev-in %s",
Packit Service d1fe03
		(info->invert & XT_PHYSDEV_OP_IN) ? " !":"", info->physindev);
Packit Service d1fe03
Packit Service d1fe03
	if (info->bitmask & XT_PHYSDEV_OP_ISOUT)
Packit Service d1fe03
		printf("%s --physdev-is-out",
Packit Service d1fe03
		       info->invert & XT_PHYSDEV_OP_ISOUT ? " !":"");
Packit Service d1fe03
	if (info->bitmask & XT_PHYSDEV_OP_OUT)
Packit Service d1fe03
		printf("%s --physdev-out %s",
Packit Service d1fe03
		(info->invert & XT_PHYSDEV_OP_OUT) ? " !":"", info->physoutdev);
Packit Service d1fe03
	if (info->bitmask & XT_PHYSDEV_OP_BRIDGED)
Packit Service d1fe03
		printf("%s --physdev-is-bridged",
Packit Service d1fe03
		       info->invert & XT_PHYSDEV_OP_BRIDGED ? " !":"");
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static void physdev_save(const void *ip, const struct xt_entry_match *match)
Packit Service d1fe03
{
Packit Service d1fe03
	const struct xt_physdev_info *info = (const void *)match->data;
Packit Service d1fe03
Packit Service d1fe03
	if (info->bitmask & XT_PHYSDEV_OP_ISIN)
Packit Service d1fe03
		printf("%s --physdev-is-in",
Packit Service d1fe03
		       (info->invert & XT_PHYSDEV_OP_ISIN) ? " !" : "");
Packit Service d1fe03
	if (info->bitmask & XT_PHYSDEV_OP_IN)
Packit Service d1fe03
		printf("%s --physdev-in %s",
Packit Service d1fe03
		       (info->invert & XT_PHYSDEV_OP_IN) ? " !" : "",
Packit Service d1fe03
		       info->physindev);
Packit Service d1fe03
Packit Service d1fe03
	if (info->bitmask & XT_PHYSDEV_OP_ISOUT)
Packit Service d1fe03
		printf("%s --physdev-is-out",
Packit Service d1fe03
		       (info->invert & XT_PHYSDEV_OP_ISOUT) ? " !" : "");
Packit Service d1fe03
	if (info->bitmask & XT_PHYSDEV_OP_OUT)
Packit Service d1fe03
		printf("%s --physdev-out %s",
Packit Service d1fe03
		       (info->invert & XT_PHYSDEV_OP_OUT) ? " !" : "",
Packit Service d1fe03
		       info->physoutdev);
Packit Service d1fe03
	if (info->bitmask & XT_PHYSDEV_OP_BRIDGED)
Packit Service d1fe03
		printf("%s --physdev-is-bridged",
Packit Service d1fe03
		       (info->invert & XT_PHYSDEV_OP_BRIDGED) ? " !" : "");
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static struct xtables_match physdev_match = {
Packit Service d1fe03
	.family		= NFPROTO_UNSPEC,
Packit Service d1fe03
	.name		= "physdev",
Packit Service d1fe03
	.version	= XTABLES_VERSION,
Packit Service d1fe03
	.size		= XT_ALIGN(sizeof(struct xt_physdev_info)),
Packit Service d1fe03
	.userspacesize	= XT_ALIGN(sizeof(struct xt_physdev_info)),
Packit Service d1fe03
	.help		= physdev_help,
Packit Service d1fe03
	.print		= physdev_print,
Packit Service d1fe03
	.save		= physdev_save,
Packit Service d1fe03
	.x6_parse	= physdev_parse,
Packit Service d1fe03
	.x6_fcheck	= physdev_check,
Packit Service d1fe03
	.x6_options	= physdev_opts,
Packit Service d1fe03
};
Packit Service d1fe03
Packit Service d1fe03
void _init(void)
Packit Service d1fe03
{
Packit Service d1fe03
	xtables_register_match(&physdev_match);
Packit Service d1fe03
}