2 * Shared library add-on to iptables to add SECMARK target support.
4 * Based on the MARK target.
8 * Copyright (C) 2006 Red Hat, Inc., James Morris <jmorris@redhat.com>
14 #include <ip6tables.h>
15 #include <linux/netfilter/xt_SECMARK.h>
17 #define PFX "SECMARK target: "
19 static void help(void)
22 "SECMARK target v%s options:\n"
23 " --selctx value Set the SELinux security context\n"
28 static struct option opts
[] = {
29 { "selctx", 1, 0, '1' },
33 /* Initialize the target. */
34 static void init(struct ip6t_entry_target
*t
, unsigned int *nfcache
)
38 * Function which parses command options; returns true if it
41 static int parse(int c
, char **argv
, int invert
, unsigned int *flags
,
42 const struct ip6t_entry
*entry
, struct ip6t_entry_target
**target
)
44 struct xt_secmark_target_info
*info
=
45 (struct xt_secmark_target_info
*)(*target
)->data
;
49 if (*flags
& SECMARK_MODE_SEL
)
50 exit_error(PARAMETER_PROBLEM
, PFX
51 "Can't specify --selctx twice");
52 info
->mode
= SECMARK_MODE_SEL
;
54 if (strlen(optarg
) > SECMARK_SELCTX_MAX
-1)
55 exit_error(PARAMETER_PROBLEM
, PFX
56 "Maximum length %u exceeded by --selctx"
58 SECMARK_SELCTX_MAX
-1, strlen(optarg
));
60 strcpy(info
->u
.sel
.selctx
, optarg
);
61 *flags
|= SECMARK_MODE_SEL
;
70 static void final_check(unsigned int flags
)
73 exit_error(PARAMETER_PROBLEM
, PFX
"parameter required");
76 static void print_secmark(struct xt_secmark_target_info
*info
)
79 case SECMARK_MODE_SEL
:
80 printf("selctx %s ", info
->u
.sel
.selctx
);\
84 exit_error(OTHER_PROBLEM
, PFX
"invalid mode %hhu\n", info
->mode
);
88 static void print(const struct ip6t_ip6
*ip
,
89 const struct ip6t_entry_target
*target
, int numeric
)
91 struct xt_secmark_target_info
*info
=
92 (struct xt_secmark_target_info
*)(target
)->data
;
98 /* Saves the target info in parsable form to stdout. */
99 static void save(const struct ip6t_ip6
*ip
, const struct ip6t_entry_target
*target
)
101 struct xt_secmark_target_info
*info
=
102 (struct xt_secmark_target_info
*)target
->data
;
108 static struct ip6tables_target secmark
= {
110 .version
= IPTABLES_VERSION
,
111 .size
= IP6T_ALIGN(sizeof(struct xt_secmark_target_info
)),
112 .userspacesize
= IP6T_ALIGN(sizeof(struct xt_secmark_target_info
)),
116 .final_check
= &final_check
,
124 register_target6(&secmark
);