Clean and tiddy-up files.
[tomato.git] / release / src / router / iptables / extensions / libipt_XOR.c
blob23979164cb21740120a12112345918a74e1bfba7
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
5 * Version 1.0
7 * This program is distributed under the terms of GNU GPL
8 */
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdlib.h>
13 #include <getopt.h>
14 #include <iptables.h>
16 #include <linux/netfilter_ipv4/ip_tables.h>
17 #include <linux/netfilter_ipv4/ipt_XOR.h>
19 #define IPT_KEY_SET 1
20 #define IPT_BLOCKSIZE_SET 2
22 static void init(struct ipt_entry_target *t, unsigned int *nfcache)
26 static void help(void)
28 printf(
29 "XOR target v%s options\n"
30 " --key string Set key to \"string\"\n"
31 " --block-size Set block size\n",
32 IPTABLES_VERSION);
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;
41 if (!optarg)
42 exit_error(PARAMETER_PROBLEM, "XOR: too few arguments");
44 if (check_inverse(optarg, &invert, NULL, 0))
45 exit_error(PARAMETER_PROBLEM, "XOR: unexpected '!'");
47 switch (c) {
48 case '1':
49 strncpy(info->key, optarg, 30);
50 info->key[29] = '\0';
51 *flags |= IPT_KEY_SET;
52 break;
53 case '2':
54 info->block_size = atoi(optarg);
55 *flags |= IPT_BLOCKSIZE_SET;
56 break;
57 default:
58 return 0;
61 return 1;
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[] = {
91 { "key", 1, 0, '1' },
92 { "block-size", 1, 0, '2' },
93 { 0 }
96 static struct iptables_target XOR = {
97 .next = NULL,
98 .name = "XOR",
99 .version = IPTABLES_VERSION,
100 .size = IPT_ALIGN(sizeof(struct ipt_XOR_info)),
101 .userspacesize = IPT_ALIGN(sizeof(struct ipt_XOR_info)),
102 .help = &help,
103 .init = &init,
104 .parse = &parse,
105 .final_check = &final_check,
106 .print = &print,
107 .save = &save,
108 .extra_opts = opts
111 void _init(void)
113 register_target(&XOR);