Patrick McHardy | ff96830 | 2006-05-24 16:15:03 +0000 | [diff] [blame] | 1 | /* |
| 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 KOZAKAI | fa00a73 | 2007-07-24 07:27:02 +0000 | [diff] [blame] | 9 | #include <xtables.h> |
Patrick McHardy | ff96830 | 2006-05-24 16:15:03 +0000 | [diff] [blame] | 10 | #include <linux/netfilter/xt_SECMARK.h> |
| 11 | |
| 12 | #define PFX "SECMARK target: " |
| 13 | |
Jan Engelhardt | 03fe3d2 | 2011-03-02 22:50:13 +0100 | [diff] [blame] | 14 | enum { |
| 15 | O_SELCTX = 0, |
| 16 | }; |
| 17 | |
Jan Engelhardt | 932e648 | 2007-10-04 16:27:30 +0000 | [diff] [blame] | 18 | static void SECMARK_help(void) |
Patrick McHardy | ff96830 | 2006-05-24 16:15:03 +0000 | [diff] [blame] | 19 | { |
| 20 | printf( |
Jan Engelhardt | 8b7c64d | 2008-04-15 11:48:25 +0200 | [diff] [blame] | 21 | "SECMARK target options:\n" |
| 22 | " --selctx value Set the SELinux security context\n"); |
Patrick McHardy | ff96830 | 2006-05-24 16:15:03 +0000 | [diff] [blame] | 23 | } |
| 24 | |
Jan Engelhardt | 03fe3d2 | 2011-03-02 22:50:13 +0100 | [diff] [blame] | 25 | static 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 McHardy | ff96830 | 2006-05-24 16:15:03 +0000 | [diff] [blame] | 30 | }; |
| 31 | |
Jan Engelhardt | 03fe3d2 | 2011-03-02 22:50:13 +0100 | [diff] [blame] | 32 | static void SECMARK_parse(struct xt_option_call *cb) |
Patrick McHardy | ff96830 | 2006-05-24 16:15:03 +0000 | [diff] [blame] | 33 | { |
Jan Engelhardt | 03fe3d2 | 2011-03-02 22:50:13 +0100 | [diff] [blame] | 34 | struct xt_secmark_target_info *info = cb->data; |
Patrick McHardy | ff96830 | 2006-05-24 16:15:03 +0000 | [diff] [blame] | 35 | |
Jan Engelhardt | 03fe3d2 | 2011-03-02 22:50:13 +0100 | [diff] [blame] | 36 | xtables_option_parse(cb); |
| 37 | info->mode = SECMARK_MODE_SEL; |
Patrick McHardy | ff96830 | 2006-05-24 16:15:03 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Jan Engelhardt | 69f564e | 2009-05-26 13:14:06 +0200 | [diff] [blame] | 40 | static void print_secmark(const struct xt_secmark_target_info *info) |
Patrick McHardy | ff96830 | 2006-05-24 16:15:03 +0000 | [diff] [blame] | 41 | { |
| 42 | switch (info->mode) { |
| 43 | case SECMARK_MODE_SEL: |
Jan Engelhardt | 7386635 | 2010-12-18 02:04:59 +0100 | [diff] [blame] | 44 | printf("selctx %s", info->secctx); |
Patrick McHardy | ff96830 | 2006-05-24 16:15:03 +0000 | [diff] [blame] | 45 | break; |
| 46 | |
| 47 | default: |
Jan Engelhardt | 1829ed4 | 2009-02-21 03:29:44 +0100 | [diff] [blame] | 48 | xtables_error(OTHER_PROBLEM, PFX "invalid mode %hhu\n", info->mode); |
Patrick McHardy | ff96830 | 2006-05-24 16:15:03 +0000 | [diff] [blame] | 49 | } |
| 50 | } |
| 51 | |
Jan Engelhardt | 932e648 | 2007-10-04 16:27:30 +0000 | [diff] [blame] | 52 | static void SECMARK_print(const void *ip, const struct xt_entry_target *target, |
| 53 | int numeric) |
Patrick McHardy | ff96830 | 2006-05-24 16:15:03 +0000 | [diff] [blame] | 54 | { |
Jan Engelhardt | 69f564e | 2009-05-26 13:14:06 +0200 | [diff] [blame] | 55 | const struct xt_secmark_target_info *info = |
Patrick McHardy | ff96830 | 2006-05-24 16:15:03 +0000 | [diff] [blame] | 56 | (struct xt_secmark_target_info*)(target)->data; |
| 57 | |
Jan Engelhardt | 7386635 | 2010-12-18 02:04:59 +0100 | [diff] [blame] | 58 | printf(" SECMARK "); |
Patrick McHardy | ff96830 | 2006-05-24 16:15:03 +0000 | [diff] [blame] | 59 | print_secmark(info); |
| 60 | } |
| 61 | |
Jan Engelhardt | 932e648 | 2007-10-04 16:27:30 +0000 | [diff] [blame] | 62 | static void SECMARK_save(const void *ip, const struct xt_entry_target *target) |
Patrick McHardy | ff96830 | 2006-05-24 16:15:03 +0000 | [diff] [blame] | 63 | { |
Jan Engelhardt | 69f564e | 2009-05-26 13:14:06 +0200 | [diff] [blame] | 64 | const struct xt_secmark_target_info *info = |
Patrick McHardy | ff96830 | 2006-05-24 16:15:03 +0000 | [diff] [blame] | 65 | (struct xt_secmark_target_info*)target->data; |
| 66 | |
Jan Engelhardt | 7386635 | 2010-12-18 02:04:59 +0100 | [diff] [blame] | 67 | printf(" --"); |
Patrick McHardy | ff96830 | 2006-05-24 16:15:03 +0000 | [diff] [blame] | 68 | print_secmark(info); |
| 69 | } |
| 70 | |
Jan Engelhardt | 932e648 | 2007-10-04 16:27:30 +0000 | [diff] [blame] | 71 | static struct xtables_target secmark_target = { |
Jan Engelhardt | 4297936 | 2009-06-01 11:56:23 +0200 | [diff] [blame] | 72 | .family = NFPROTO_UNSPEC, |
Yasuyuki KOZAKAI | fa00a73 | 2007-07-24 07:27:02 +0000 | [diff] [blame] | 73 | .name = "SECMARK", |
Jan Engelhardt | 8b7c64d | 2008-04-15 11:48:25 +0200 | [diff] [blame] | 74 | .version = XTABLES_VERSION, |
Yasuyuki KOZAKAI | fa00a73 | 2007-07-24 07:27:02 +0000 | [diff] [blame] | 75 | .revision = 0, |
| 76 | .size = XT_ALIGN(sizeof(struct xt_secmark_target_info)), |
| 77 | .userspacesize = XT_ALIGN(sizeof(struct xt_secmark_target_info)), |
Jan Engelhardt | 932e648 | 2007-10-04 16:27:30 +0000 | [diff] [blame] | 78 | .help = SECMARK_help, |
Jan Engelhardt | 932e648 | 2007-10-04 16:27:30 +0000 | [diff] [blame] | 79 | .print = SECMARK_print, |
| 80 | .save = SECMARK_save, |
Jan Engelhardt | 03fe3d2 | 2011-03-02 22:50:13 +0100 | [diff] [blame] | 81 | .x6_parse = SECMARK_parse, |
| 82 | .x6_options = SECMARK_opts, |
Patrick McHardy | ff96830 | 2006-05-24 16:15:03 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | void _init(void) |
| 86 | { |
Jan Engelhardt | 932e648 | 2007-10-04 16:27:30 +0000 | [diff] [blame] | 87 | xtables_register_target(&secmark_target); |
Patrick McHardy | ff96830 | 2006-05-24 16:15:03 +0000 | [diff] [blame] | 88 | } |