1 /* Shared library add-on to iptables to add NFMARK matching support. */
9 #include <linux/netfilter_ipv4/ipt_mark.h>
11 /* Function which prints out usage message. */
16 "MARK match v%s options:\n"
17 "[!] --mark value[/mask] Match nfmark value with optional mask\n"
22 static struct option opts[] = {
23 { "mark", 1, 0, '1' },
27 /* Initialize the match. */
29 init(struct ipt_entry_match *m, unsigned int *nfcache)
31 /* Can't cache this. */
32 *nfcache |= NFC_UNKNOWN;
35 /* Function which parses command options; returns true if it
38 parse(int c, char **argv, int invert, unsigned int *flags,
39 const struct ipt_entry *entry,
40 unsigned int *nfcache,
41 struct ipt_entry_match **match)
43 struct ipt_mark_info *markinfo = (struct ipt_mark_info *)(*match)->data;
48 check_inverse(optarg, &invert, &optind, 0);
49 markinfo->mark = strtoul(optarg, &end, 0);
51 markinfo->mask = strtoul(end+1, &end, 0);
53 markinfo->mask = 0xffffffff;
54 if (*end != '\0' || end == optarg)
55 exit_error(PARAMETER_PROBLEM, "Bad MARK value `%s'", optarg);
68 print_mark(unsigned long mark, unsigned long mask, int numeric)
70 if(mask != 0xffffffff)
71 printf("0x%lx/0x%lx ", mark, mask);
73 printf("0x%lx ", mark);
76 /* Final check; must have specified --mark. */
78 final_check(unsigned int flags)
81 exit_error(PARAMETER_PROBLEM,
82 "MARK match: You must specify `--mark'");
85 /* Prints out the matchinfo. */
87 print(const struct ipt_ip *ip,
88 const struct ipt_entry_match *match,
91 struct ipt_mark_info *info = (struct ipt_mark_info *)match->data;
93 printf("MARK match ");
98 print_mark(info->mark, info->mask, numeric);
101 /* Saves the union ipt_matchinfo in parsable form to stdout. */
103 save(const struct ipt_ip *ip, const struct ipt_entry_match *match)
105 struct ipt_mark_info *info = (struct ipt_mark_info *)match->data;
111 print_mark(info->mark, info->mask, 0);
115 struct iptables_match mark
119 IPT_ALIGN(sizeof(struct ipt_mark_info)),
120 IPT_ALIGN(sizeof(struct ipt_mark_info)),
132 register_match(&mark);