libxt_SECMARK.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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>
  9. #include <xtables.h>
  10. #include <linux/netfilter/xt_SECMARK.h>
  11. #define PFX "SECMARK target: "
  12. enum {
  13. O_SELCTX = 0,
  14. };
  15. static void SECMARK_help(void)
  16. {
  17. printf(
  18. "SECMARK target options:\n"
  19. " --selctx value Set the SELinux security context\n");
  20. }
  21. static const struct xt_option_entry SECMARK_opts[] = {
  22. {.name = "selctx", .id = O_SELCTX, .type = XTTYPE_STRING,
  23. .flags = XTOPT_MAND | XTOPT_PUT,
  24. XTOPT_POINTER(struct xt_secmark_target_info, secctx)},
  25. XTOPT_TABLEEND,
  26. };
  27. static void SECMARK_parse(struct xt_option_call *cb)
  28. {
  29. struct xt_secmark_target_info *info = cb->data;
  30. xtables_option_parse(cb);
  31. info->mode = SECMARK_MODE_SEL;
  32. }
  33. static void print_secmark(const struct xt_secmark_target_info *info)
  34. {
  35. switch (info->mode) {
  36. case SECMARK_MODE_SEL:
  37. printf("selctx %s", info->secctx);
  38. break;
  39. default:
  40. xtables_error(OTHER_PROBLEM, PFX "invalid mode %hhu\n", info->mode);
  41. }
  42. }
  43. static void SECMARK_print(const void *ip, const struct xt_entry_target *target,
  44. int numeric)
  45. {
  46. const struct xt_secmark_target_info *info =
  47. (struct xt_secmark_target_info*)(target)->data;
  48. printf(" SECMARK ");
  49. print_secmark(info);
  50. }
  51. static void SECMARK_save(const void *ip, const struct xt_entry_target *target)
  52. {
  53. const struct xt_secmark_target_info *info =
  54. (struct xt_secmark_target_info*)target->data;
  55. printf(" --");
  56. print_secmark(info);
  57. }
  58. static struct xtables_target secmark_target = {
  59. .family = NFPROTO_UNSPEC,
  60. .name = "SECMARK",
  61. .version = XTABLES_VERSION,
  62. .revision = 0,
  63. .size = XT_ALIGN(sizeof(struct xt_secmark_target_info)),
  64. .userspacesize = XT_ALIGN(sizeof(struct xt_secmark_target_info)),
  65. .help = SECMARK_help,
  66. .print = SECMARK_print,
  67. .save = SECMARK_save,
  68. .x6_parse = SECMARK_parse,
  69. .x6_options = SECMARK_opts,
  70. };
  71. void _init(void)
  72. {
  73. xtables_register_target(&secmark_target);
  74. }