1 /* Shared library add-on to iptables to add customized REJECT support.
3 * (C) 2000 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5 * ported to IPv6 by Harald Welte <laforge@gnumonks.org>
12 #include <ip6tables.h>
13 #include <linux/netfilter_ipv6/ip6_tables.h>
14 #include <linux/netfilter_ipv6/ip6t_REJECT.h>
19 enum ip6t_reject_with with;
23 static const struct reject_names reject_table[] = {
24 {"icmp6-no-route", "no-route",
25 IP6T_ICMP6_NO_ROUTE, "ICMPv6 no route"},
26 {"icmp6-adm-prohibited", "adm-prohibited",
27 IP6T_ICMP6_ADM_PROHIBITED, "ICMPv6 administratively prohibited"},
29 {"icmp6-not-neighbor", "not-neighbor"},
30 IP6T_ICMP6_NOT_NEIGHBOR, "ICMPv6 not a neighbor"},
32 {"icmp6-addr-unreachable", "addr-unreach",
33 IP6T_ICMP6_ADDR_UNREACH, "ICMPv6 address unreachable"},
34 {"icmp6-port-unreachable", "port-unreach",
35 IP6T_ICMP6_PORT_UNREACH, "ICMPv6 port unreachable"},
36 {"tcp-reset", "tcp-reset",
37 IP6T_TCP_RESET, "TCP RST packet"}
41 print_reject_types(void)
45 printf("Valid reject types:\n");
47 for (i = 0; i < sizeof(reject_table)/sizeof(struct reject_names); i++) {
48 printf(" %-25s\t%s\n", reject_table[i].name, reject_table[i].desc);
49 printf(" %-25s\talias\n", reject_table[i].alias);
54 /* Saves the union ipt_targinfo in parsable form to stdout. */
56 /* Function which prints out usage message. */
57 static void REJECT_help(void)
60 "REJECT target options:\n"
61 "--reject-with type drop input packet and send back\n"
62 " a reply packet according to type:\n");
67 static const struct option REJECT_opts[] = {
68 { "reject-with", 1, NULL, '1' },
72 /* Allocate and initialize the target. */
73 static void REJECT_init(struct xt_entry_target *t)
75 struct ip6t_reject_info *reject = (struct ip6t_reject_info *)t->data;
78 reject->with = IP6T_ICMP6_PORT_UNREACH;
82 /* Function which parses command options; returns true if it
84 static int REJECT_parse(int c, char **argv, int invert, unsigned int *flags,
85 const void *entry, struct xt_entry_target **target)
87 struct ip6t_reject_info *reject =
88 (struct ip6t_reject_info *)(*target)->data;
89 unsigned int limit = sizeof(reject_table)/sizeof(struct reject_names);
94 if (check_inverse(optarg, &invert, NULL, 0))
95 exit_error(PARAMETER_PROBLEM,
96 "Unexpected `!' after --reject-with");
97 for (i = 0; i < limit; i++) {
98 if ((strncasecmp(reject_table[i].name, optarg, strlen(optarg)) == 0)
99 || (strncasecmp(reject_table[i].alias, optarg, strlen(optarg)) == 0)) {
100 reject->with = reject_table[i].with;
104 exit_error(PARAMETER_PROBLEM, "unknown reject type `%s'",optarg);
112 /* Prints out ipt_reject_info. */
113 static void REJECT_print(const void *ip, const struct xt_entry_target *target,
116 const struct ip6t_reject_info *reject
117 = (const struct ip6t_reject_info *)target->data;
120 for (i = 0; i < sizeof(reject_table)/sizeof(struct reject_names); i++) {
121 if (reject_table[i].with == reject->with)
124 printf("reject-with %s ", reject_table[i].name);
127 /* Saves ipt_reject in parsable form to stdout. */
128 static void REJECT_save(const void *ip, const struct xt_entry_target *target)
130 const struct ip6t_reject_info *reject
131 = (const struct ip6t_reject_info *)target->data;
134 for (i = 0; i < sizeof(reject_table)/sizeof(struct reject_names); i++)
135 if (reject_table[i].with == reject->with)
138 printf("--reject-with %s ", reject_table[i].name);
141 static struct xtables_target reject_tg6_reg = {
143 .version = XTABLES_VERSION,
145 .size = XT_ALIGN(sizeof(struct ip6t_reject_info)),
146 .userspacesize = XT_ALIGN(sizeof(struct ip6t_reject_info)),
149 .parse = REJECT_parse,
150 .print = REJECT_print,
152 .extra_opts = REJECT_opts,
157 xtables_register_target(&reject_tg6_reg);