manpages: do not include v4-only modules in ip6tables manpage
[jleu-iptables.git] / extensions / libxt_SECMARK.c
blob0c09c88ec3f51cf5590e6027b7dbb1f004da2d84
1 /*
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>
7 */
8 #include <stdio.h>
9 #include <string.h>
10 #include <stdlib.h>
11 #include <getopt.h>
12 #include <xtables.h>
13 #include <linux/netfilter/xt_SECMARK.h>
15 #define PFX "SECMARK target: "
17 static void SECMARK_help(void)
19 printf(
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' },
26 { .name = NULL }
29 static int SECMARK_parse(int c, char **argv, int invert, unsigned int *flags,
30 const void *entry, struct xt_entry_target **target)
32 struct xt_secmark_target_info *info =
33 (struct xt_secmark_target_info*)(*target)->data;
35 switch (c) {
36 case '1':
37 if (*flags & SECMARK_MODE_SEL)
38 xtables_error(PARAMETER_PROBLEM, PFX
39 "Can't specify --selctx twice");
40 info->mode = SECMARK_MODE_SEL;
42 if (strlen(optarg) > SECMARK_SELCTX_MAX-1)
43 xtables_error(PARAMETER_PROBLEM, PFX
44 "Maximum length %u exceeded by --selctx"
45 " parameter (%zu)",
46 SECMARK_SELCTX_MAX-1, strlen(optarg));
48 strcpy(info->u.sel.selctx, optarg);
49 *flags |= SECMARK_MODE_SEL;
50 break;
51 default:
52 return 0;
55 return 1;
58 static void SECMARK_check(unsigned int flags)
60 if (!flags)
61 xtables_error(PARAMETER_PROBLEM, PFX "parameter required");
64 static void print_secmark(const struct xt_secmark_target_info *info)
66 switch (info->mode) {
67 case SECMARK_MODE_SEL:
68 printf("selctx %s ", info->u.sel.selctx);\
69 break;
71 default:
72 xtables_error(OTHER_PROBLEM, PFX "invalid mode %hhu\n", info->mode);
76 static void SECMARK_print(const void *ip, const struct xt_entry_target *target,
77 int numeric)
79 const struct xt_secmark_target_info *info =
80 (struct xt_secmark_target_info*)(target)->data;
82 printf("SECMARK ");
83 print_secmark(info);
86 static void SECMARK_save(const void *ip, const struct xt_entry_target *target)
88 const struct xt_secmark_target_info *info =
89 (struct xt_secmark_target_info*)target->data;
91 printf("--");
92 print_secmark(info);
95 static struct xtables_target secmark_target = {
96 .family = AF_UNSPEC,
97 .name = "SECMARK",
98 .version = XTABLES_VERSION,
99 .revision = 0,
100 .size = XT_ALIGN(sizeof(struct xt_secmark_target_info)),
101 .userspacesize = XT_ALIGN(sizeof(struct xt_secmark_target_info)),
102 .help = SECMARK_help,
103 .parse = SECMARK_parse,
104 .final_check = SECMARK_check,
105 .print = SECMARK_print,
106 .save = SECMARK_save,
107 .extra_opts = SECMARK_opts,
110 void _init(void)
112 xtables_register_target(&secmark_target);