1 /* Shared library add-on to iptables to add MARK target support. */
8 #include <linux/netfilter_ipv4/ip_tables.h>
9 #include <linux/netfilter_ipv4/ipt_MARK.h>
12 struct ipt_entry_target t;
13 struct ipt_mark_target_info mark;
16 /* Function which prints out usage message. */
21 "MARK target v%s options:\n"
22 " --set-mark value Set nfmark value\n"
27 static struct option opts[] = {
28 { "set-mark", 1, 0, '1' },
32 /* Initialize the target. */
34 init(struct ipt_entry_target *t, unsigned int *nfcache)
38 /* Function which parses command options; returns true if it
41 parse(int c, char **argv, int invert, unsigned int *flags,
42 const struct ipt_entry *entry,
43 struct ipt_entry_target **target)
45 struct ipt_mark_target_info *markinfo
46 = (struct ipt_mark_target_info *)(*target)->data;
50 if (string_to_number(optarg, 0, 0xffffffff,
51 (unsigned int *)&markinfo->mark))
52 exit_error(PARAMETER_PROBLEM, "Bad MARK value `%s'", optarg);
54 exit_error(PARAMETER_PROBLEM,
55 "MARK target: Can't specify --set-mark twice");
67 final_check(unsigned int flags)
70 exit_error(PARAMETER_PROBLEM,
71 "MARK target: Parameter --set-mark is required");
75 print_mark(unsigned long mark, int numeric)
77 printf("0x%lx ", mark);
80 /* Prints out the targinfo. */
82 print(const struct ipt_ip *ip,
83 const struct ipt_entry_target *target,
86 const struct ipt_mark_target_info *markinfo =
87 (const struct ipt_mark_target_info *)target->data;
89 print_mark(markinfo->mark, numeric);
92 /* Saves the union ipt_targinfo in parsable form to stdout. */
94 save(const struct ipt_ip *ip, const struct ipt_entry_target *target)
96 const struct ipt_mark_target_info *markinfo =
97 (const struct ipt_mark_target_info *)target->data;
99 printf("--set-mark 0x%lx ", markinfo->mark);
103 struct iptables_target mark
107 IPT_ALIGN(sizeof(struct ipt_mark_target_info)),
108 IPT_ALIGN(sizeof(struct ipt_mark_target_info)),
120 register_target(&mark);