2
* "TEE" target extension for iptables
3
* Copyright © Sebastian Claßen <sebastian.classen [at] freenet.ag>, 2007
4
* Jan Engelhardt <jengelh [at] medozas de>, 2007 - 2008
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License; either
8
* version 2 of the License, or any later version, as published by the
9
* Free Software Foundation.
11
#include <sys/socket.h>
18
#include <arpa/inet.h>
20
#include <netinet/in.h>
23
#include <linux/netfilter.h>
24
#include <linux/netfilter/x_tables.h>
28
FLAG_GATEWAY = 1 << 0,
31
static const struct option tee_tg_opts[] = {
32
{.name = "gateway", .has_arg = true, .val = 'g'},
36
static void tee_tg_help(void)
39
"TEE target options:\n"
40
" --gateway IPADDR Route packet via the gateway given by address\n"
44
static int tee_tg_parse(int c, char **argv, int invert, unsigned int *flags,
45
const void *entry, struct xt_entry_target **target)
47
struct xt_tee_tginfo *info = (void *)(*target)->data;
48
const struct in_addr *ia;
52
if (*flags & FLAG_GATEWAY)
53
exit_error(PARAMETER_PROBLEM,
54
"Cannot specify --gw more than once");
56
if (check_inverse(optarg, &invert, NULL, 0))
57
exit_error(PARAMETER_PROBLEM,
58
"Unexpected \"!\" after --gateway");
60
ia = numeric_to_ipaddr(optarg);
62
exit_error(PARAMETER_PROBLEM,
63
"Invalid IP address %s", optarg);
65
memcpy(&info->gw, ia, sizeof(*ia));
66
*flags |= FLAG_GATEWAY;
73
static void tee_tg_check(unsigned int flags)
76
exit_error(PARAMETER_PROBLEM, "TEE target: "
77
"--gateway parameter required");
80
static void tee_tg_print(const void *ip, const struct xt_entry_target *target,
83
const struct xt_tee_tginfo *info = (const void *)target->data;
86
printf("TEE gw:%s ", ipaddr_to_anyname(&info->gw.in));
88
printf("TEE gw:%s ", ipaddr_to_numeric(&info->gw.in));
91
static void tee_tg_save(const void *ip, const struct xt_entry_target *target)
93
const struct xt_tee_tginfo *info = (const void *)target->data;
95
printf("--gateway %s ", ipaddr_to_numeric(&info->gw.in));
98
static struct xtables_target tee_tg_reg = {
100
.version = XTABLES_VERSION,
101
.size = XT_ALIGN(sizeof(struct xt_tee_tginfo)),
102
.userspacesize = XT_ALIGN(sizeof(struct xt_tee_tginfo)),
104
.parse = tee_tg_parse,
105
.final_check = tee_tg_check,
106
.print = tee_tg_print,
108
.extra_opts = tee_tg_opts,
111
static void _init(void)
113
xtables_register_target(&tee_tg_reg);