|
Packit |
7b22a4 |
#include <stdio.h>
|
|
Packit |
7b22a4 |
#include <xtables.h>
|
|
Packit |
7b22a4 |
#include <linux/netfilter/xt_helper.h>
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
enum {
|
|
Packit |
7b22a4 |
O_HELPER = 0,
|
|
Packit |
7b22a4 |
};
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
static void helper_help(void)
|
|
Packit |
7b22a4 |
{
|
|
Packit |
7b22a4 |
printf(
|
|
Packit |
7b22a4 |
"helper match options:\n"
|
|
Packit |
7b22a4 |
"[!] --helper string Match helper identified by string\n");
|
|
Packit |
7b22a4 |
}
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
static const struct xt_option_entry helper_opts[] = {
|
|
Packit |
7b22a4 |
{.name = "helper", .id = O_HELPER, .type = XTTYPE_STRING,
|
|
Packit |
7b22a4 |
.flags = XTOPT_MAND | XTOPT_INVERT | XTOPT_PUT,
|
|
Packit |
7b22a4 |
XTOPT_POINTER(struct xt_helper_info, name)},
|
|
Packit |
7b22a4 |
XTOPT_TABLEEND,
|
|
Packit |
7b22a4 |
};
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
static void helper_parse(struct xt_option_call *cb)
|
|
Packit |
7b22a4 |
{
|
|
Packit |
7b22a4 |
struct xt_helper_info *info = cb->data;
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
xtables_option_parse(cb);
|
|
Packit |
7b22a4 |
if (cb->invert)
|
|
Packit |
7b22a4 |
info->invert = 1;
|
|
Packit |
7b22a4 |
}
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
static void
|
|
Packit |
7b22a4 |
helper_print(const void *ip, const struct xt_entry_match *match, int numeric)
|
|
Packit |
7b22a4 |
{
|
|
Packit |
7b22a4 |
const struct xt_helper_info *info = (const void *)match->data;
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
printf(" helper match %s\"%s\"", info->invert ? "! " : "", info->name);
|
|
Packit |
7b22a4 |
}
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
static void helper_save(const void *ip, const struct xt_entry_match *match)
|
|
Packit |
7b22a4 |
{
|
|
Packit |
7b22a4 |
const struct xt_helper_info *info = (const void *)match->data;
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
printf("%s --helper", info->invert ? " !" : "");
|
|
Packit |
7b22a4 |
xtables_save_string(info->name);
|
|
Packit |
7b22a4 |
}
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
static int helper_xlate(struct xt_xlate *xl,
|
|
Packit |
7b22a4 |
const struct xt_xlate_mt_params *params)
|
|
Packit |
7b22a4 |
{
|
|
Packit |
7b22a4 |
const struct xt_helper_info *info = (const void *)params->match->data;
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
if (params->escape_quotes)
|
|
Packit |
7b22a4 |
xt_xlate_add(xl, "ct helper%s \\\"%s\\\"",
|
|
Packit |
7b22a4 |
info->invert ? " !=" : "", info->name);
|
|
Packit |
7b22a4 |
else
|
|
Packit |
7b22a4 |
xt_xlate_add(xl, "ct helper%s \"%s\"",
|
|
Packit |
7b22a4 |
info->invert ? " !=" : "", info->name);
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
return 1;
|
|
Packit |
7b22a4 |
}
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
static struct xtables_match helper_match = {
|
|
Packit |
7b22a4 |
.family = NFPROTO_UNSPEC,
|
|
Packit |
7b22a4 |
.name = "helper",
|
|
Packit |
7b22a4 |
.version = XTABLES_VERSION,
|
|
Packit |
7b22a4 |
.size = XT_ALIGN(sizeof(struct xt_helper_info)),
|
|
Packit |
7b22a4 |
.help = helper_help,
|
|
Packit |
7b22a4 |
.print = helper_print,
|
|
Packit |
7b22a4 |
.save = helper_save,
|
|
Packit |
7b22a4 |
.x6_parse = helper_parse,
|
|
Packit |
7b22a4 |
.x6_options = helper_opts,
|
|
Packit |
7b22a4 |
.xlate = helper_xlate,
|
|
Packit |
7b22a4 |
};
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
void _init(void)
|
|
Packit |
7b22a4 |
{
|
|
Packit |
7b22a4 |
xtables_register_match(&helper_match);
|
|
Packit |
7b22a4 |
}
|