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);
69 #ifdef KERNEL_64_USERSPACE_32
70 markinfo->mark = strtoull(optarg, &end, 0);
71 markinfo->mask = ~0ULL;
73 markinfo->mask = strtoull(end+1, &end, 0);
75 markinfo->mark = strtoul(optarg, &end, 0);
76 markinfo->mask = ~0UL;
78 markinfo->mask = strtoul(end+1, &end, 0);
80 if (*end != '\0' || end == optarg)
81 exit_error(PARAMETER_PROBLEM, "Bad MARK value `%s'", optarg);
93 #ifdef KERNEL_64_USERSPACE_32
95 print_mark(unsigned long long mark, unsigned long long mask, int numeric)
98 printf("0x%llx/0x%llx ", mark, mask);
100 printf("0x%llx ", mark);
104 print_mark(unsigned long mark, unsigned long mask, int numeric)
107 printf("0x%lx/0x%lx ", mark, mask);
109 printf("0x%lx ", mark);
113 /* Final check; must have specified --mark. */
115 final_check(unsigned int flags)
118 exit_error(PARAMETER_PROBLEM,
119 "MARK match: You must specify `--mark'");
122 /* Prints out the matchinfo. */
124 print(const struct ipt_ip *ip,
125 const struct ipt_entry_match *match,
128 struct ipt_connmark_info *info = (struct ipt_connmark_info *)match->data;
130 printf("CONNMARK match ");
133 print_mark(info->mark, info->mask, numeric);
136 /* Saves the matchinfo in parsable form to stdout. */
138 save(const struct ipt_ip *ip, const struct ipt_entry_match *match)
140 struct ipt_connmark_info *info = (struct ipt_connmark_info *)match->data;
146 print_mark(info->mark, info->mask, 0);
149 static struct iptables_match connmark_match = {
151 .version = IPTABLES_VERSION,
152 .size = IPT_ALIGN(sizeof(struct ipt_connmark_info)),
153 .userspacesize = IPT_ALIGN(sizeof(struct ipt_connmark_info)),
157 .final_check = &final_check,
165 register_match(&connmark_match);