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);
51 *flags
|= IPT_KEY_SET
;
54 info
->block_size
= atoi(optarg
);
55 *flags
|= IPT_BLOCKSIZE_SET
;
64 static void final_check(unsigned int flags
)
66 if (!(flags
& IPT_KEY_SET
))
67 exit_error(PARAMETER_PROBLEM
, "XOR: You must specify a key");
68 if (!(flags
& IPT_BLOCKSIZE_SET
))
69 exit_error(PARAMETER_PROBLEM
, "XOR: You must specify a block-size");
72 static void save (const struct ipt_ip
*ip
,
73 const struct ipt_entry_target
*target
)
75 const struct ipt_XOR_info
*info
= (struct ipt_XOR_info
*) target
->data
;
77 printf("--key %s ", info
->key
);
78 printf("--block-size %u ", info
->block_size
);
81 static void print (const struct ipt_ip
*ip
,
82 const struct ipt_entry_target
*target
, int numeric
)
84 const struct ipt_XOR_info
*info
= (struct ipt_XOR_info
*) target
->data
;
86 printf("key: %s ", info
->key
);
87 printf("block-size: %u ", info
->block_size
);
90 static struct option opts
[] = {
92 { "block-size", 1, 0, '2' },
96 static struct iptables_target XOR
= {
99 .version
= IPTABLES_VERSION
,
100 .size
= IPT_ALIGN(sizeof(struct ipt_XOR_info
)),
101 .userspacesize
= IPT_ALIGN(sizeof(struct ipt_XOR_info
)),
105 .final_check
= &final_check
,
113 register_target(&XOR
);