blob: 6ba8606355daa10105b9adcab05fb7e13f6a3425 [file] [log] [blame]
Patrick McHardyff968302006-05-24 16:15:03 +00001/*
2 * Shared library add-on to iptables to add SECMARK target support.
3 *
4 * Based on the MARK target.
5 *
6 * Copyright (C) 2006 Red Hat, Inc., James Morris <jmorris@redhat.com>
7 */
8#include <stdio.h>
Yasuyuki KOZAKAIfa00a732007-07-24 07:27:02 +00009#include <xtables.h>
Patrick McHardyff968302006-05-24 16:15:03 +000010#include <linux/netfilter/xt_SECMARK.h>
11
12#define PFX "SECMARK target: "
13
Jan Engelhardt03fe3d22011-03-02 22:50:13 +010014enum {
15 O_SELCTX = 0,
16};
17
Jan Engelhardt932e6482007-10-04 16:27:30 +000018static void SECMARK_help(void)
Patrick McHardyff968302006-05-24 16:15:03 +000019{
20 printf(
Jan Engelhardt8b7c64d2008-04-15 11:48:25 +020021"SECMARK target options:\n"
22" --selctx value Set the SELinux security context\n");
Patrick McHardyff968302006-05-24 16:15:03 +000023}
24
Jan Engelhardt03fe3d22011-03-02 22:50:13 +010025static const struct xt_option_entry SECMARK_opts[] = {
26 {.name = "selctx", .id = O_SELCTX, .type = XTTYPE_STRING,
27 .flags = XTOPT_MAND | XTOPT_PUT,
28 XTOPT_POINTER(struct xt_secmark_target_info, secctx)},
29 XTOPT_TABLEEND,
Patrick McHardyff968302006-05-24 16:15:03 +000030};
31
Jan Engelhardt03fe3d22011-03-02 22:50:13 +010032static void SECMARK_parse(struct xt_option_call *cb)
Patrick McHardyff968302006-05-24 16:15:03 +000033{
Jan Engelhardt03fe3d22011-03-02 22:50:13 +010034 struct xt_secmark_target_info *info = cb->data;
Patrick McHardyff968302006-05-24 16:15:03 +000035
Jan Engelhardt03fe3d22011-03-02 22:50:13 +010036 xtables_option_parse(cb);
37 info->mode = SECMARK_MODE_SEL;
Patrick McHardyff968302006-05-24 16:15:03 +000038}
39
Jan Engelhardt69f564e2009-05-26 13:14:06 +020040static void print_secmark(const struct xt_secmark_target_info *info)
Patrick McHardyff968302006-05-24 16:15:03 +000041{
42 switch (info->mode) {
43 case SECMARK_MODE_SEL:
Jan Engelhardt73866352010-12-18 02:04:59 +010044 printf("selctx %s", info->secctx);
Patrick McHardyff968302006-05-24 16:15:03 +000045 break;
46
47 default:
Jan Engelhardt1829ed42009-02-21 03:29:44 +010048 xtables_error(OTHER_PROBLEM, PFX "invalid mode %hhu\n", info->mode);
Patrick McHardyff968302006-05-24 16:15:03 +000049 }
50}
51
Jan Engelhardt932e6482007-10-04 16:27:30 +000052static void SECMARK_print(const void *ip, const struct xt_entry_target *target,
53 int numeric)
Patrick McHardyff968302006-05-24 16:15:03 +000054{
Jan Engelhardt69f564e2009-05-26 13:14:06 +020055 const struct xt_secmark_target_info *info =
Patrick McHardyff968302006-05-24 16:15:03 +000056 (struct xt_secmark_target_info*)(target)->data;
57
Jan Engelhardt73866352010-12-18 02:04:59 +010058 printf(" SECMARK ");
Patrick McHardyff968302006-05-24 16:15:03 +000059 print_secmark(info);
60}
61
Jan Engelhardt932e6482007-10-04 16:27:30 +000062static void SECMARK_save(const void *ip, const struct xt_entry_target *target)
Patrick McHardyff968302006-05-24 16:15:03 +000063{
Jan Engelhardt69f564e2009-05-26 13:14:06 +020064 const struct xt_secmark_target_info *info =
Patrick McHardyff968302006-05-24 16:15:03 +000065 (struct xt_secmark_target_info*)target->data;
66
Jan Engelhardt73866352010-12-18 02:04:59 +010067 printf(" --");
Patrick McHardyff968302006-05-24 16:15:03 +000068 print_secmark(info);
69}
70
Jan Engelhardt932e6482007-10-04 16:27:30 +000071static struct xtables_target secmark_target = {
Jan Engelhardt42979362009-06-01 11:56:23 +020072 .family = NFPROTO_UNSPEC,
Yasuyuki KOZAKAIfa00a732007-07-24 07:27:02 +000073 .name = "SECMARK",
Jan Engelhardt8b7c64d2008-04-15 11:48:25 +020074 .version = XTABLES_VERSION,
Yasuyuki KOZAKAIfa00a732007-07-24 07:27:02 +000075 .revision = 0,
76 .size = XT_ALIGN(sizeof(struct xt_secmark_target_info)),
77 .userspacesize = XT_ALIGN(sizeof(struct xt_secmark_target_info)),
Jan Engelhardt932e6482007-10-04 16:27:30 +000078 .help = SECMARK_help,
Jan Engelhardt932e6482007-10-04 16:27:30 +000079 .print = SECMARK_print,
80 .save = SECMARK_save,
Jan Engelhardt03fe3d22011-03-02 22:50:13 +010081 .x6_parse = SECMARK_parse,
82 .x6_options = SECMARK_opts,
Patrick McHardyff968302006-05-24 16:15:03 +000083};
84
85void _init(void)
86{
Jan Engelhardt932e6482007-10-04 16:27:30 +000087 xtables_register_target(&secmark_target);
Patrick McHardyff968302006-05-24 16:15:03 +000088}