1 /* Shared library add-on to ip6tables to add NFMARK matching support. */
9 #include <linux/netfilter_ipv6/ip6t_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 ip6t_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 ip6t_entry *entry,
40 unsigned int *nfcache,
41 struct ip6t_entry_match **match)
43 struct ip6t_mark_info *markinfo = (struct ip6t_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 invert, int numeric)
73 if(mask != 0xffffffff)
74 printf("0x%lx/0x%lx ", mark, mask);
76 printf("0x%lx ", mark);
79 /* Final check; must have specified --mark. */
81 final_check(unsigned int flags)
84 exit_error(PARAMETER_PROBLEM,
85 "MARK match: You must specify `--mark'");
88 /* Prints out the matchinfo. */
90 print(const struct ip6t_ip6 *ip,
91 const struct ip6t_entry_match *match,
94 printf("MARK match ");
95 print_mark(((struct ip6t_mark_info *)match->data)->mark,
96 ((struct ip6t_mark_info *)match->data)->mask,
97 ((struct ip6t_mark_info *)match->data)->invert, numeric);
100 /* Saves the union ip6t_matchinfo in parsable form to stdout. */
102 save(const struct ip6t_ip6 *ip, const struct ip6t_entry_match *match)
105 print_mark(((struct ip6t_mark_info *)match->data)->mark,
106 ((struct ip6t_mark_info *)match->data)->mask,
107 ((struct ip6t_mark_info *)match->data)->invert, 0);
111 struct ip6tables_match mark
115 IP6T_ALIGN(sizeof(struct ip6t_mark_info)),
116 IP6T_ALIGN(sizeof(struct ip6t_mark_info)),
128 register_match6(&mark);