2 * Shared library add-on to iptables to add SECMARK target support.
4 * Based on the MARK target.
6 * Copyright (C) 2006 Red Hat, Inc., James Morris <jmorris@redhat.com>
13 #include <linux/netfilter/xt_SECMARK.h>
15 #define PFX "SECMARK target: "
17 static void SECMARK_help(void)
20 "SECMARK target options:\n"
21 " --selctx value Set the SELinux security context\n");
24 static const struct option SECMARK_opts[] = {
25 { "selctx", 1, NULL, '1' },
30 * Function which parses command options; returns true if it
33 static int SECMARK_parse(int c, char **argv, int invert, unsigned int *flags,
34 const void *entry, struct xt_entry_target **target)
36 struct xt_secmark_target_info *info =
37 (struct xt_secmark_target_info*)(*target)->data;
41 if (*flags & SECMARK_MODE_SEL)
42 exit_error(PARAMETER_PROBLEM, PFX
43 "Can't specify --selctx twice");
44 info->mode = SECMARK_MODE_SEL;
46 if (strlen(optarg) > SECMARK_SELCTX_MAX-1)
47 exit_error(PARAMETER_PROBLEM, PFX
48 "Maximum length %u exceeded by --selctx"
50 SECMARK_SELCTX_MAX-1, strlen(optarg));
52 strcpy(info->u.sel.selctx, optarg);
53 *flags |= SECMARK_MODE_SEL;
62 static void SECMARK_check(unsigned int flags)
65 exit_error(PARAMETER_PROBLEM, PFX "parameter required");
68 static void print_secmark(struct xt_secmark_target_info *info)
71 case SECMARK_MODE_SEL:
72 printf("selctx %s ", info->u.sel.selctx);\
76 exit_error(OTHER_PROBLEM, PFX "invalid mode %hhu\n", info->mode);
80 static void SECMARK_print(const void *ip, const struct xt_entry_target *target,
83 struct xt_secmark_target_info *info =
84 (struct xt_secmark_target_info*)(target)->data;
90 /* Saves the target info in parsable form to stdout. */
91 static void SECMARK_save(const void *ip, const struct xt_entry_target *target)
93 struct xt_secmark_target_info *info =
94 (struct xt_secmark_target_info*)target->data;
100 static struct xtables_target secmark_target = {
103 .version = XTABLES_VERSION,
105 .size = XT_ALIGN(sizeof(struct xt_secmark_target_info)),
106 .userspacesize = XT_ALIGN(sizeof(struct xt_secmark_target_info)),
107 .help = SECMARK_help,
108 .parse = SECMARK_parse,
109 .final_check = SECMARK_check,
110 .print = SECMARK_print,
111 .save = SECMARK_save,
112 .extra_opts = SECMARK_opts,
117 xtables_register_target(&secmark_target);