blob: 0e94c39e11902dbdb8489f525912b0800ed5060a [file] [log] [blame]
Stephane Ouelletteed30c6b2003-04-27 13:07:18 +00001/* Shared library add-on to ip6tables for condition match */
Stephane Ouellettea2c70372003-02-25 11:54:56 +00002#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <getopt.h>
6#include <ip6tables.h>
7
8#include<linux/netfilter_ipv6/ip6_tables.h>
9#include<linux/netfilter_ipv6/ip6t_condition.h>
10
11
12static void
13help(void)
14{
15 printf("condition match v%s options:\n"
16 "--condition [!] filename "
17 "Match on boolean value stored in /proc file\n",
18 IPTABLES_VERSION);
19}
20
21
22static struct option opts[] = {
23 { .name = "condition", .has_arg = 1, .flag = 0, .val = 'X' },
24 { .name = 0 }
25};
26
Stephane Ouellettea2c70372003-02-25 11:54:56 +000027static int
28parse(int c, char **argv, int invert, unsigned int *flags,
29 const struct ip6t_entry *entry, unsigned int *nfcache,
30 struct ip6t_entry_match **match)
31{
32 struct condition6_info *info =
33 (struct condition6_info *) (*match)->data;
34
Stephane Ouellettea2c70372003-02-25 11:54:56 +000035 if (c == 'X') {
Stephane Ouellettefbe3abe2003-03-26 14:42:35 +000036 if (*flags)
37 exit_error(PARAMETER_PROBLEM,
38 "Can't specify multiple conditions");
39
Stephane Ouelletteed30c6b2003-04-27 13:07:18 +000040 check_inverse(optarg, &invert, &optind, 0);
41
Stephane Ouellettea2c70372003-02-25 11:54:56 +000042 if (strlen(argv[optind - 1]) < CONDITION6_NAME_LEN)
43 strcpy(info->name, argv[optind - 1]);
44 else
45 exit_error(PARAMETER_PROBLEM,
46 "File name too long");
47
48 info->invert = invert;
49 *flags = 1;
50 return 1;
51 }
52
53 return 0;
54}
55
56
57static void
58final_check(unsigned int flags)
59{
60 if (!flags)
61 exit_error(PARAMETER_PROBLEM,
62 "Condition match: must specify --condition");
63}
64
65
66static void
67print(const struct ip6t_ip6 *ip,
68 const struct ip6t_entry_match *match, int numeric)
69{
70 const struct condition6_info *info =
71 (const struct condition6_info *) match->data;
72
73 printf("condition %s%s ", (info->invert) ? "!" : "", info->name);
74}
75
76
77static void
78save(const struct ip6t_ip6 *ip,
79 const struct ip6t_entry_match *match)
80{
81 const struct condition6_info *info =
82 (const struct condition6_info *) match->data;
83
Stephane Ouelletteed30c6b2003-04-27 13:07:18 +000084 printf("--condition %s\"%s\" ", (info->invert) ? "! " : "", info->name);
Stephane Ouellettea2c70372003-02-25 11:54:56 +000085}
86
87
88static struct ip6tables_match condition = {
89 .name = "condition",
90 .version = IPTABLES_VERSION,
91 .size = IP6T_ALIGN(sizeof(struct condition6_info)),
92 .userspacesize = IP6T_ALIGN(sizeof(struct condition6_info)),
93 .help = &help,
Stephane Ouellettea2c70372003-02-25 11:54:56 +000094 .parse = &parse,
95 .final_check = &final_check,
96 .print = &print,
97 .save = &save,
98 .extra_opts = opts
99};
100
101
102void
103_init(void)
104{
105 register_match6(&condition);
106}