1 /* Shared library add-on to iptables for the XOR target
2 * (C) 2000 by Tim Vandermeersch <Tim.Vandermeersch@pandora.be>
3 * Based on libipt_TTL.c
7 * This program is distributed under the terms of GNU GPL
16 #include <linux/netfilter_ipv4/ip_tables.h>
17 #include <linux/netfilter_ipv4/ipt_XOR.h>
20 #define IPT_BLOCKSIZE_SET 2
22 static void init(struct ipt_entry_target *t, unsigned int *nfcache)
26 static void help(void)
29 "XOR target v%s options\n"
30 " --key string Set key to \"string\"\n"
31 " --block-size Set block size\n",
35 static int parse(int c, char **argv, int invert, unsigned int *flags,
36 const struct ipt_entry *entry,
37 struct ipt_entry_target **target)
39 struct ipt_XOR_info *info = (struct ipt_XOR_info *) (*target)->data;
42 exit_error(PARAMETER_PROBLEM, "XOR: too few arguments");
44 if (check_inverse(optarg, &invert, NULL, 0))
45 exit_error(PARAMETER_PROBLEM, "XOR: unexpected '!'");
49 strncpy(info->key, optarg, 30);
50 *flags |= IPT_KEY_SET;
53 info->block_size = atoi(optarg);
54 *flags |= IPT_BLOCKSIZE_SET;
63 static void final_check(unsigned int flags)
65 if (!(flags & IPT_KEY_SET))
66 exit_error(PARAMETER_PROBLEM, "XOR: You must specify a key");
67 if (!(flags & IPT_BLOCKSIZE_SET))
68 exit_error(PARAMETER_PROBLEM, "XOR: You must specify a block-size");
71 static void save (const struct ipt_ip *ip,
72 const struct ipt_entry_target *target)
74 const struct ipt_XOR_info *info = (struct ipt_XOR_info *) target->data;
76 printf("--key %s ", info->key);
77 printf("--block-size %u ", info->block_size);
80 static void print (const struct ipt_ip *ip,
81 const struct ipt_entry_target *target, int numeric)
83 const struct ipt_XOR_info *info = (struct ipt_XOR_info *) target->data;
85 printf("key: %s ", info->key);
86 printf("block-size: %u ", info->block_size);
89 static struct option opts[] = {
91 { "block-size", 1, 0, '2' },
95 static struct iptables_target XOR = { NULL,
98 IPT_ALIGN(sizeof(struct ipt_XOR_info)),
99 IPT_ALIGN(sizeof(struct ipt_XOR_info)),
111 register_target(&XOR);