1 /* Shared library add-on to iptables to add connmark matching support.
3 * (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
4 * by Henrik Nordstrom <hno@marasystems.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "../include/linux/netfilter_ipv4/ipt_connmark.h"
31 /* Function which prints out usage message. */
36 "CONNMARK match v%s options:\n"
37 "[!] --mark value[/mask] Match nfmark value with optional mask\n"
42 static struct option opts[] = {
43 { "mark", 1, 0, '1' },
47 /* Initialize the match. */
49 init(struct ipt_entry_match *m, unsigned int *nfcache)
51 /* Can't cache this. */
52 *nfcache |= NFC_UNKNOWN;
55 /* Function which parses command options; returns true if it
58 parse(int c, char **argv, int invert, unsigned int *flags,
59 const struct ipt_entry *entry,
60 unsigned int *nfcache,
61 struct ipt_entry_match **match)
63 struct ipt_connmark_info *markinfo = (struct ipt_connmark_info *)(*match)->data;
68 check_inverse(optarg, &invert, &optind, 0);
70 markinfo->mark = strtoul(optarg, &end, 0);
71 markinfo->mask = 0xffffffffUL;
74 markinfo->mask = strtoul(end+1, &end, 0);
76 if (*end != '\0' || end == optarg)
77 exit_error(PARAMETER_PROBLEM, "Bad MARK value `%s'", optarg);
90 print_mark(unsigned long mark, unsigned long mask, int numeric)
92 if(mask != 0xffffffffUL)
93 printf("0x%lx/0x%lx ", mark, mask);
95 printf("0x%lx ", mark);
98 /* Final check; must have specified --mark. */
100 final_check(unsigned int flags)
103 exit_error(PARAMETER_PROBLEM,
104 "MARK match: You must specify `--mark'");
107 /* Prints out the matchinfo. */
109 print(const struct ipt_ip *ip,
110 const struct ipt_entry_match *match,
113 struct ipt_connmark_info *info = (struct ipt_connmark_info *)match->data;
115 printf("CONNMARK match ");
118 print_mark(info->mark, info->mask, numeric);
121 /* Saves the matchinfo in parsable form to stdout. */
123 save(const struct ipt_ip *ip, const struct ipt_entry_match *match)
125 struct ipt_connmark_info *info = (struct ipt_connmark_info *)match->data;
131 print_mark(info->mark, info->mask, 0);
134 static struct iptables_match connmark_match = {
136 .version = IPTABLES_VERSION,
137 .size = IPT_ALIGN(sizeof(struct ipt_connmark_info)),
138 .userspacesize = IPT_ALIGN(sizeof(struct ipt_connmark_info)),
142 .final_check = &final_check,
150 register_match(&connmark_match);