2 * Shared library add-on to iptables to add CONNSECMARK target support.
4 * Based on the MARK and CONNMARK targets.
6 * Copyright (C) 2006 Red Hat, Inc., James Morris <jmorris@redhat.com>
13 #include <linux/netfilter/xt_CONNSECMARK.h>
15 #define PFX "CONNSECMARK target: "
17 static void CONNSECMARK_help(void)
20 "CONNSECMARK target options:\n"
21 " --save Copy security mark from packet to conntrack\n"
22 " --restore Copy security mark from connection to packet\n");
25 static const struct option CONNSECMARK_opts[] = {
26 { "save", 0, NULL, '1' },
27 { "restore", 0, NULL, '2' },
32 CONNSECMARK_parse(int c, char **argv, int invert, unsigned int *flags,
33 const void *entry, struct xt_entry_target **target)
35 struct xt_connsecmark_target_info *info =
36 (struct xt_connsecmark_target_info*)(*target)->data;
40 if (*flags & CONNSECMARK_SAVE)
41 xtables_error(PARAMETER_PROBLEM, PFX
42 "Can't specify --save twice");
43 info->mode = CONNSECMARK_SAVE;
44 *flags |= CONNSECMARK_SAVE;
48 if (*flags & CONNSECMARK_RESTORE)
49 xtables_error(PARAMETER_PROBLEM, PFX
50 "Can't specify --restore twice");
51 info->mode = CONNSECMARK_RESTORE;
52 *flags |= CONNSECMARK_RESTORE;
62 static void CONNSECMARK_check(unsigned int flags)
65 xtables_error(PARAMETER_PROBLEM, PFX "parameter required");
67 if (flags == (CONNSECMARK_SAVE|CONNSECMARK_RESTORE))
68 xtables_error(PARAMETER_PROBLEM, PFX "only one flag of --save "
69 "or --restore is allowed");
72 static void print_connsecmark(const struct xt_connsecmark_target_info *info)
75 case CONNSECMARK_SAVE:
79 case CONNSECMARK_RESTORE:
84 xtables_error(OTHER_PROBLEM, PFX "invalid mode %hhu\n", info->mode);
89 CONNSECMARK_print(const void *ip, const struct xt_entry_target *target,
92 const struct xt_connsecmark_target_info *info =
93 (struct xt_connsecmark_target_info*)(target)->data;
95 printf("CONNSECMARK ");
96 print_connsecmark(info);
100 CONNSECMARK_save(const void *ip, const struct xt_entry_target *target)
102 const struct xt_connsecmark_target_info *info =
103 (struct xt_connsecmark_target_info*)target->data;
106 print_connsecmark(info);
109 static struct xtables_target connsecmark_target = {
110 .family = NFPROTO_UNSPEC,
111 .name = "CONNSECMARK",
112 .version = XTABLES_VERSION,
114 .size = XT_ALIGN(sizeof(struct xt_connsecmark_target_info)),
115 .userspacesize = XT_ALIGN(sizeof(struct xt_connsecmark_target_info)),
116 .parse = CONNSECMARK_parse,
117 .help = CONNSECMARK_help,
118 .final_check = CONNSECMARK_check,
119 .print = CONNSECMARK_print,
120 .save = CONNSECMARK_save,
121 .extra_opts = CONNSECMARK_opts,
126 xtables_register_target(&connsecmark_target);