Blame extensions/libxt_nfacct.c

Packit Service d1fe03
/*
Packit Service d1fe03
 * (C) 2011 by Pablo Neira Ayuso <pablo@netfilter.org>
Packit Service d1fe03
 * (C) 2011 by Intra2Net AG <http://www.intra2net.com>
Packit Service d1fe03
 *
Packit Service d1fe03
 * This program is free software; you can redistribute it and/or modify
Packit Service d1fe03
 * it under the terms of the GNU General Public License version 2 (or
Packit Service d1fe03
 * any later at your option) as published by the Free Software Foundation.
Packit Service d1fe03
 */
Packit Service d1fe03
#include <stdbool.h>
Packit Service d1fe03
#include <stdlib.h>
Packit Service d1fe03
#include <stdio.h>
Packit Service d1fe03
#include <string.h>
Packit Service d1fe03
#include <getopt.h>
Packit Service d1fe03
#include <xtables.h>
Packit Service d1fe03
Packit Service d1fe03
#include <linux/netfilter/x_tables.h>
Packit Service d1fe03
#include <linux/netfilter/xt_nfacct.h>
Packit Service d1fe03
Packit Service d1fe03
enum {
Packit Service d1fe03
	O_NAME = 0,
Packit Service d1fe03
};
Packit Service d1fe03
Packit Service d1fe03
#define s struct xt_nfacct_match_info
Packit Service d1fe03
static const struct xt_option_entry nfacct_opts[] = {
Packit Service d1fe03
	{.name = "nfacct-name", .id = O_NAME, .type = XTTYPE_STRING,
Packit Service d1fe03
	 .min = 1, .flags = XTOPT_MAND|XTOPT_PUT, XTOPT_POINTER(s, name)},
Packit Service d1fe03
	XTOPT_TABLEEND,
Packit Service d1fe03
};
Packit Service d1fe03
#undef s
Packit Service d1fe03
Packit Service d1fe03
static void nfacct_help(void)
Packit Service d1fe03
{
Packit Service d1fe03
	printf("nfacct match options:\n"
Packit Service d1fe03
	       " --nfacct-name STRING		Name of accouting area\n");
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static void nfacct_parse(struct xt_option_call *cb)
Packit Service d1fe03
{
Packit Service d1fe03
	xtables_option_parse(cb);
Packit Service d1fe03
	switch (cb->entry->id) {
Packit Service d1fe03
	case O_NAME:
Packit Service d1fe03
		if (strchr(cb->arg, '\n') != NULL)
Packit Service d1fe03
			xtables_error(PARAMETER_PROBLEM,
Packit Service d1fe03
				   "Newlines not allowed in --nfacct-name");
Packit Service d1fe03
		break;
Packit Service d1fe03
	}
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static void
Packit Service d1fe03
nfacct_print_name(const struct xt_nfacct_match_info *info, char *name)
Packit Service d1fe03
{
Packit Service d1fe03
	printf(" %snfacct-name ", name);
Packit Service d1fe03
	xtables_save_string(info->name);
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static void nfacct_print(const void *ip, const struct xt_entry_match *match,
Packit Service d1fe03
                        int numeric)
Packit Service d1fe03
{
Packit Service d1fe03
	const struct xt_nfacct_match_info *info =
Packit Service d1fe03
		(struct xt_nfacct_match_info *)match->data;
Packit Service d1fe03
Packit Service d1fe03
	nfacct_print_name(info, "");
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static void nfacct_save(const void *ip, const struct xt_entry_match *match)
Packit Service d1fe03
{
Packit Service d1fe03
	const struct xt_nfacct_match_info *info =
Packit Service d1fe03
		(struct xt_nfacct_match_info *)match->data;
Packit Service d1fe03
Packit Service d1fe03
	nfacct_print_name(info, "--");
Packit Service d1fe03
}
Packit Service d1fe03
Packit Service d1fe03
static struct xtables_match nfacct_matches[] = {
Packit Service d1fe03
	{
Packit Service d1fe03
		.family		= NFPROTO_UNSPEC,
Packit Service d1fe03
		.revision	= 0,
Packit Service d1fe03
		.name		= "nfacct",
Packit Service d1fe03
		.version	= XTABLES_VERSION,
Packit Service d1fe03
		.size		= XT_ALIGN(sizeof(struct xt_nfacct_match_info)),
Packit Service d1fe03
		.userspacesize	= offsetof(struct xt_nfacct_match_info, nfacct),
Packit Service d1fe03
		.help		= nfacct_help,
Packit Service d1fe03
		.x6_parse	= nfacct_parse,
Packit Service d1fe03
		.print		= nfacct_print,
Packit Service d1fe03
		.save		= nfacct_save,
Packit Service d1fe03
		.x6_options	= nfacct_opts,
Packit Service d1fe03
	},
Packit Service d1fe03
	{
Packit Service d1fe03
		.family		= NFPROTO_UNSPEC,
Packit Service d1fe03
		.revision	= 1,
Packit Service d1fe03
		.name		= "nfacct",
Packit Service d1fe03
		.version	= XTABLES_VERSION,
Packit Service d1fe03
		.size		= XT_ALIGN(sizeof(struct xt_nfacct_match_info_v1)),
Packit Service d1fe03
		.userspacesize	= offsetof(struct xt_nfacct_match_info_v1, nfacct),
Packit Service d1fe03
		.help		= nfacct_help,
Packit Service d1fe03
		.x6_parse	= nfacct_parse,
Packit Service d1fe03
		.print		= nfacct_print,
Packit Service d1fe03
		.save		= nfacct_save,
Packit Service d1fe03
		.x6_options	= nfacct_opts,
Packit Service d1fe03
	},
Packit Service d1fe03
};
Packit Service d1fe03
Packit Service d1fe03
void _init(void)
Packit Service d1fe03
{
Packit Service d1fe03
	xtables_register_matches(nfacct_matches, ARRAY_SIZE(nfacct_matches));
Packit Service d1fe03
}