1 /* Copyright (C) 2000-2002 Joakim Axelsson <gozem@linux.nu>
2 * Patrick Schaaf <bof@bof.de>
3 * Martin Josefsson <gandalf@wlug.westbo.se>
4 * Copyright (C) 2003-2004 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 /* Shared library add-on to iptables to add IP set matching. */
21 #include <linux/netfilter_ipv4/ipt_set.h>
22 #include "libipt_set.h"
24 static void set_help(void)
26 printf("set match options:\n"
27 " [!] --set name flags\n"
28 " 'name' is the set name from to match,\n"
29 " 'flags' are the comma separated list of\n"
30 " 'src' and 'dst'.\n");
33 static const struct option set_opts
[] = {
34 {"set", 1, NULL
, '1'},
38 static void set_init(struct xt_entry_match
*match
)
40 struct ipt_set_info_match
*info
=
41 (struct ipt_set_info_match
*) match
->data
;
44 memset(info
, 0, sizeof(struct ipt_set_info_match
));
48 static int set_parse(int c
, char **argv
, int invert
, unsigned int *flags
,
49 const void *entry
, struct xt_entry_match
**match
)
51 struct ipt_set_info_match
*myinfo
=
52 (struct ipt_set_info_match
*) (*match
)->data
;
53 struct ipt_set_info
*info
= &myinfo
->match_set
;
56 case '1': /* --set <set> <flag>[,<flag> */
58 xtables_error(PARAMETER_PROBLEM
,
59 "--set can be specified only once");
61 xtables_check_inverse(optarg
, &invert
, &optind
, 0);
63 info
->flags
[0] |= IPSET_MATCH_INV
;
66 || argv
[optind
][0] == '-'
67 || argv
[optind
][0] == '!')
68 xtables_error(PARAMETER_PROBLEM
,
69 "--set requires two args.");
71 if (strlen(argv
[optind
-1]) > IP_SET_MAXNAMELEN
- 1)
72 xtables_error(PARAMETER_PROBLEM
,
73 "setname `%s' too long, max %d characters.",
74 argv
[optind
-1], IP_SET_MAXNAMELEN
- 1);
76 get_set_byname(argv
[optind
- 1], info
);
77 parse_bindings(argv
[optind
], info
);
78 DEBUGP("parse: set index %u\n", info
->index
);
91 static void set_check(unsigned int flags
)
94 xtables_error(PARAMETER_PROBLEM
,
95 "You must specify `--set' with proper arguments");
96 DEBUGP("final check OK\n");
100 print_match(const char *prefix
, const struct ipt_set_info
*info
)
103 char setname
[IP_SET_MAXNAMELEN
];
105 get_set_byid(setname
, info
->index
);
107 (info
->flags
[0] & IPSET_MATCH_INV
) ? "! " : "",
110 for (i
= 0; i
< IP_SET_MAX_BINDINGS
; i
++) {
115 info
->flags
[i
] & IPSET_SRC
? "src" : "dst");
120 /* Prints out the matchinfo. */
121 static void set_print(const void *ip
, const struct xt_entry_match
*match
,
124 const struct ipt_set_info_match
*info
= (const void *)match
->data
;
126 print_match("set", &info
->match_set
);
129 static void set_save(const void *ip
, const struct xt_entry_match
*match
)
131 const struct ipt_set_info_match
*info
= (const void *)match
->data
;
133 print_match("--set", &info
->match_set
);
136 static struct xtables_match set_mt_reg
= {
138 .version
= XTABLES_VERSION
,
139 .family
= NFPROTO_IPV4
,
140 .size
= XT_ALIGN(sizeof(struct ipt_set_info_match
)),
141 .userspacesize
= XT_ALIGN(sizeof(struct ipt_set_info_match
)),
145 .final_check
= set_check
,
148 .extra_opts
= set_opts
,
153 xtables_register_match(&set_mt_reg
);